@@ -58,12 +58,14 @@ export type ResizeMode = 'nearest-neighbor' | 'bilinear' | 'bicubic' | 'area'
5858/**
5959 * How {@link Image.renderSVG} scales, see {@link SVGScaleModes}. The numbers 1-3 (the values of the deprecated
6060 * `Image.SVG_MODE_*`) still work, they are removed in 4.0
61+ * @deprecated Use `renderSVG(svg, { width })`, `{ height }` or `{ scale }`: the `mode` option is removed in 4.0
6162 */
6263export type SVGScaleMode = 'scale' | 'width' | 'height' | 1 | 2 | 3 ;
6364
6465/**
6566 * The resampling filters of {@link Image.resize} and the other scaling functions:
6667 * `image.resize({ width: 256, mode: ResizeModes.BICUBIC })`
68+ * @deprecated Use the names, `image.resize({ width: 256, mode: 'bicubic' })`: `ResizeModes` is removed in 4.0
6769 */
6870export class ResizeModes {
6971 /**
@@ -97,7 +99,11 @@ export class ResizeModes {
9799 private constructor ( ) { }
98100}
99101
100- /** How {@link Image.renderSVG} scales the SVG to the given size */
102+ /**
103+ * How {@link Image.renderSVG} scales the SVG to the given size
104+ * @deprecated Use `renderSVG(svg, { width })`, `{ height }` or `{ scale }`: `SVGScaleModes` and the `mode` option are
105+ * removed in 4.0
106+ */
101107export class SVGScaleModes {
102108 /** The size is a factor of the SVG's own size */
103109 static readonly SCALE = 'scale' ;
@@ -383,22 +389,42 @@ export interface FisheyeOptions {
383389 strength ?: number ;
384390}
385391
392+ /** Options of {@link Image.renderSVG}: {@link SVGOptions}, by its name in 4.0 */
393+ export type RenderSVGOptions = SVGOptions ;
394+
386395/** Options of {@link Image.renderSVG} */
387396export interface SVGOptions {
388- /** The scale, or the width or height in pixels, see `mode`. Default: `1` */
397+ /** The width in pixels, the height follows the SVG's aspect ratio. Only one of `width`, `height` and `scale` */
398+ width ?: number ;
399+ /** The height in pixels, the width follows the SVG's aspect ratio. Only one of `width`, `height` and `scale` */
400+ height ?: number ;
401+ /** A factor of the SVG's own size. Only one of `width`, `height` and `scale`. Default: `1` */
402+ scale ?: number ;
403+ /**
404+ * The scale, or the width or height in pixels, see `mode`. Default: `1`
405+ * @deprecated Use `width`, `height` or `scale`, their names in 4.0, which ignores `size` and `mode`:
406+ * `renderSVG(svg, { width: 512 })`
407+ */
389408 size ?: number ;
390409 /**
391410 * What `size` is: one of {@link SVGScaleModes.SCALE}, {@link SVGScaleModes.WIDTH}, {@link SVGScaleModes.HEIGHT}.
392411 * Default: {@link SVGScaleModes.SCALE}
412+ * @deprecated Use `width`, `height` or `scale`, their names in 4.0, which ignores `size` and `mode`:
413+ * `renderSVG(svg, { width: 512 })`
393414 */
394415 mode ?: SVGScaleMode ;
416+ /**
417+ * Fonts for `<text>`, like {@link SVGOptions.fonts}: one font, or several
418+ */
419+ font ?: BinaryData | BinaryData [ ] ;
395420 /**
396421 * Fonts for `<text>` (TrueType, OpenType): each text gets the face its `font-family`, `font-weight`, `font-style`
397422 * and `font-stretch` match best among them, by the names, weights and styles in the fonts (like browsers match
398423 * installed fonts). Generic families (`serif`, `sans-serif`, `monospace`, ...) are the first font that fits them,
399424 * other families and text without one get the first font's family; characters a face doesn't have come from the
400425 * other fonts (TrueType, OpenType or WOFF). Fonts the SVG embeds with `@font-face` (in data: URIs) are used too,
401426 * before these for their family names. Without any fonts text isn't rendered. Default: `[]`
427+ * @deprecated Use `font`, its name in 4.0, which ignores `fonts` (one font, or several in an array)
402428 */
403429 fonts ?: BinaryData [ ] ;
404430 /**
@@ -580,10 +606,15 @@ export interface CropCircleOptions {
580606 * `'cover'` covers the image (the larger dimension is its diameter, the corners of a rectangular image stay
581607 * transparent on the shorter side). Default: `'contain'`
582608 */
609+ fit ?: 'contain' | 'cover' ;
610+ /**
611+ * The circle's size, like {@link CropCircleOptions.fit}
612+ * @deprecated Use `fit`, its name in 4.0, which ignores `size`: `cropCircle({ fit: 'cover' })`
613+ */
583614 size ?: 'contain' | 'cover' ;
584615 /**
585616 * Whether to use the larger dimension for the size. Default: `false`
586- * @deprecated Use `size : 'cover'` (`true`) or `size : 'contain'` (`false`), `max` will be removed in 4.0
617+ * @deprecated Use `fit : 'cover'` (`true`) or `fit : 'contain'` (`false`), `max` will be removed in 4.0
587618 */
588619 max ?: boolean ;
589620 /** Share of the radius (0..1) over which the edge fades out. Default: `0` */
@@ -1077,25 +1108,25 @@ export class Image {
10771108 }
10781109
10791110 /**
1080- * @deprecated Use { @link ResizeModes.NEAREST_NEIGHBOR}, ` Image.RESIZE_*` will be removed in 4.0
1111+ * @deprecated Use the name `'nearest-neighbor'`: ` Image.RESIZE_*` and `ResizeModes` are removed in 4.0
10811112 * @group Deprecated
10821113 */
10831114 static readonly RESIZE_NEAREST_NEIGHBOR = 'RESIZE_NEAREST_NEIGHBOR' ;
10841115
10851116 /**
1086- * @deprecated Use { @link ResizeModes.BILINEAR}, ` Image.RESIZE_*` will be removed in 4.0
1117+ * @deprecated Use the name `'bilinear'`: ` Image.RESIZE_*` and `ResizeModes` are removed in 4.0
10871118 * @group Deprecated
10881119 */
10891120 static readonly RESIZE_BILINEAR = 'RESIZE_BILINEAR' ;
10901121
10911122 /**
1092- * @deprecated Use { @link ResizeModes.BICUBIC}, ` Image.RESIZE_*` will be removed in 4.0
1123+ * @deprecated Use the name `'bicubic'`: ` Image.RESIZE_*` and `ResizeModes` are removed in 4.0
10931124 * @group Deprecated
10941125 */
10951126 static readonly RESIZE_BICUBIC = 'RESIZE_BICUBIC' ;
10961127
10971128 /**
1098- * @deprecated Use { @link ResizeModes.AREA}, ` Image.RESIZE_*` will be removed in 4.0
1129+ * @deprecated Use the name `'area'`: ` Image.RESIZE_*` and `ResizeModes` are removed in 4.0
10991130 * @group Deprecated
11001131 */
11011132 static readonly RESIZE_AREA = 'RESIZE_AREA' ;
@@ -1580,13 +1611,14 @@ export class Image {
15801611 * Crops the image into a circle with an antialiased edge
15811612 * @param max Whether to use the larger dimension for the size. Default: `false`
15821613 * @param feathering Share of the radius (0..1) over which the edge fades out. Default: `0`
1583- * @deprecated Pass {@link CropCircleOptions} instead, `cropCircle({ size : 'cover' })`. The arguments will be
1614+ * @deprecated Pass {@link CropCircleOptions} instead, `cropCircle({ fit : 'cover' })`. The arguments will be
15841615 * removed in 4.0
15851616 */
15861617 cropCircle ( max ?: boolean , feathering ?: number ) : this;
15871618 cropCircle ( maxOrOptions : boolean | CropCircleOptions = false , featheringArgument = 0 ) : this {
1588- const { max = false , size = max ? 'cover' : 'contain' , feathering = 0 } = typeof maxOrOptions === 'object' && maxOrOptions !== null
1589- ? maxOrOptions : { max : maxOrOptions , feathering : featheringArgument } ;
1619+ const { max = false , fit, size : givenSize , feathering = 0 } = typeof maxOrOptions === 'object' && maxOrOptions !== null
1620+ ? maxOrOptions : { max : maxOrOptions , feathering : featheringArgument } as CropCircleOptions ;
1621+ const size = fit ?? givenSize ?? ( max ? 'cover' : 'contain' ) ;
15901622 finite ( feathering , 'feathering' ) ;
15911623 if ( size !== 'contain' && size !== 'cover' ) throw new TypeError ( `Invalid circle size: ${ String ( size ) } ` ) ;
15921624 const radius = ( size === 'cover' ? Math . max : Math . min ) ( this . width , this . height ) / 2 ;
@@ -3230,19 +3262,19 @@ export class Image {
32303262 }
32313263
32323264 /**
3233- * @deprecated Use { @link SVGScaleModes.SCALE}, `Image.SVG_MODE_*` will be removed in 4.0
3265+ * @deprecated Use `renderSVG(svg, { scale })`: `Image.SVG_MODE_*` and `SVGScaleModes` are removed in 4.0
32343266 * @group Deprecated
32353267 */
32363268 static readonly SVG_MODE_SCALE = 1 ;
32373269
32383270 /**
3239- * @deprecated Use { @link SVGScaleModes.WIDTH}, `Image.SVG_MODE_*` will be removed in 4.0
3271+ * @deprecated Use `renderSVG(svg, { width })`: `Image.SVG_MODE_*` and `SVGScaleModes` are removed in 4.0
32403272 * @group Deprecated
32413273 */
32423274 static readonly SVG_MODE_WIDTH = 2 ;
32433275
32443276 /**
3245- * @deprecated Use { @link SVGScaleModes.HEIGHT}, `Image.SVG_MODE_*` will be removed in 4.0
3277+ * @deprecated Use `renderSVG(svg, { height })`: `Image.SVG_MODE_*` and `SVGScaleModes` are removed in 4.0
32463278 * @group Deprecated
32473279 */
32483280 static readonly SVG_MODE_HEIGHT = 3 ;
@@ -3271,11 +3303,22 @@ export class Image {
32713303 * @param size The size to use
32723304 * @param mode The SVG resizing mode to use (one of {@link SVGScaleModes.SCALE}, {@link SVGScaleModes.WIDTH}, {@link SVGScaleModes.HEIGHT})
32733305 * @return The rendered SVG graphic
3274- * @deprecated Pass {@link SVGOptions} instead, the positional arguments will be removed in 4.0
3306+ * @deprecated Pass {@link SVGOptions} instead, `renderSVG(svg, { width: 512 })` (or `height`, `scale`). The
3307+ * positional arguments will be removed in 4.0
32753308 */
32763309 static renderSVG ( svg : string | BinaryData , size ?: number , mode ?: SVGScaleMode ) : Promise < Image > ;
32773310 static async renderSVG ( svg : string | BinaryData , sizeOrOptions : number | SVGOptions = 1 , modeArgument : SVGScaleMode = SVGScaleModes . SCALE ) : Promise < Image > {
3278- const { size = 1 , mode : givenMode = SVGScaleModes . SCALE , fonts = [ ] , images : givenImages = { } } = isOptions ( sizeOrOptions ) ? sizeOrOptions : { size : sizeOrOptions , mode : modeArgument } ;
3311+ const options : SVGOptions = isOptions ( sizeOrOptions ) ? sizeOrOptions : { size : sizeOrOptions , mode : modeArgument } ;
3312+ // (the 4.0 names: width, height or scale for size and mode, font for fonts)
3313+ const sizes = [ options . width , options . height , options . scale ] . filter ( value => value !== undefined ) . length ;
3314+ if ( sizes > 1 ) throw new TypeError ( 'renderSVG() takes one of width, height and scale' ) ;
3315+ if ( sizes && ( options . size !== undefined || options . mode !== undefined ) ) throw new TypeError ( 'renderSVG() takes width, height or scale, or the deprecated size and mode, not both' ) ;
3316+ if ( options . font !== undefined && options . fonts !== undefined ) throw new TypeError ( 'renderSVG() takes font, or the deprecated fonts, not both' ) ;
3317+ const { size = 1 , mode : givenMode = SVGScaleModes . SCALE } = options . width !== undefined ? { size : options . width , mode : SVGScaleModes . WIDTH }
3318+ : options . height !== undefined ? { size : options . height , mode : SVGScaleModes . HEIGHT }
3319+ : options . scale !== undefined ? { size : options . scale , mode : SVGScaleModes . SCALE } : options ;
3320+ const { images : givenImages = { } } = options ;
3321+ const fonts = options . font === undefined ? options . fonts ?? [ ] : Array . isArray ( options . font ) ? options . font : [ options . font ] ;
32793322 const mode = LEGACY_SVG_MODES . get ( givenMode ) ?? givenMode ;
32803323 if ( mode !== 'scale' && mode !== 'width' && mode !== 'height' )
32813324 throw new Error ( 'Invalid SVG scaling mode' ) ;
0 commit comments