Skip to content

Commit 006760b

Browse files
committed
take the option names of 4.0 and point the deprecation hints to them
1 parent 07dcf8d commit 006760b

6 files changed

Lines changed: 194 additions & 28 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Changelog
22

3+
## 3.20.4
4+
5+
### Deprecated
6+
7+
The deprecation hints now lead to the names 4.0 uses, and 3.x takes those names already. 4.0 ignores an option it
8+
doesn't know, so code that followed the earlier hints (`cropCircle({ size: 'cover' })`) would have changed its output
9+
there without an error:
10+
11+
- **`cropCircle({ fit })`**: the `size` option is deprecated, `fit` is its name in 4.0. The hint of `cropCircle(max, feathering)` and of the `max` option now names `fit`.
12+
- **`Image.renderSVG(svg, { width })`, `{ height }` and `{ scale }`**: the `size` and `mode` options (and `SVGScaleMode`, `SVGScaleModes`) are deprecated, these are their names in 4.0. Only one of the three can be given. **`{ font }`** (one font or an array) is the 4.0 name of `fonts`, which is deprecated. `RenderSVGOptions` is the 4.0 name of `SVGOptions`.
13+
- **`new GainMap(image, { min, max })`** and **`map.min`**, **`map.max`**: the 4.0 names of `gainMapMin` and `gainMapMax`, which are deprecated.
14+
- **`ResizeModes`**, **`FrameDisposalModes`** and the constants `Image.RESIZE_*`, `Frame.DISPOSAL_*` and `Image.SVG_MODE_*` point to the names 4.0 uses (`'bicubic'`, `'background'`, `{ width }`): 4.0 removes the classes too. `FrameDisposalMode` is the 4.0 name of `FrameDisposalModeName`.
15+
316
## 3.20.3
417

518
### Deprecated

‎src/frame.ts‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@ import { Image, ResizeMode, ResizeOptions, ResizeToOptions, Color, TrimOptions,
22
import { isOptions, finite } from './util/options.ts';
33

44
/** Names of the frame disposal modes, see {@link Frame.disposalMode} */
5-
export type FrameDisposalModeName = 'any' | 'keep' | 'previous' | 'background';
5+
export type FrameDisposalMode = 'any' | 'keep' | 'previous' | 'background';
6+
/**
7+
* Names of the frame disposal modes, see {@link Frame.disposalMode}
8+
* @deprecated Use {@link FrameDisposalMode}, its name in 4.0
9+
*/
10+
export type FrameDisposalModeName = FrameDisposalMode;
611
/**
712
* Ids of the frame disposal modes, as GIFs store them (0 any, 1 keep, 2 previous, 3 background)
8-
* @deprecated Use the names ({@link FrameDisposalModeName}: `'any'`, `'keep'`, `'previous'`, `'background'`), the ids will
13+
* @deprecated Use the names ({@link FrameDisposalMode}: `'any'`, `'keep'`, `'previous'`, `'background'`), the ids will
914
* be removed in 4.0
1015
*/
1116
export type FrameDisposalModeId = 0 | 1 | 2 | 3;
@@ -15,7 +20,10 @@ type DisposalId = 0 | 1 | 2 | 3;
1520

1621
const DISPOSAL_MODES: readonly FrameDisposalModeName[] = ['any', 'keep', 'previous', 'background'];
1722

18-
/** What happens to a frame's area before the next frame is drawn, see {@link Frame.disposalMode} */
23+
/**
24+
* What happens to a frame's area before the next frame is drawn, see {@link Frame.disposalMode}
25+
* @deprecated Use the names, `'background'` for `FrameDisposalModes.BACKGROUND`: `FrameDisposalModes` is removed in 4.0
26+
*/
1927
export class FrameDisposalModes {
2028
/** The decoder decides (in practice like {@link FrameDisposalModes.KEEP}) */
2129
static readonly ANY = 'any';
@@ -65,25 +73,25 @@ export class Frame extends Image {
6573
private __disposalMode__: DisposalId = 1;
6674

6775
/**
68-
* @deprecated Use {@link FrameDisposalModes.ANY}, `Frame.DISPOSAL_*` will be removed in 4.0
76+
* @deprecated Use the name `'any'`: `Frame.DISPOSAL_*` and `FrameDisposalModes` are removed in 4.0
6977
* @group Deprecated
7078
*/
7179
static readonly DISPOSAL_ANY: typeof FrameDisposalModes.ANY = FrameDisposalModes.ANY;
7280

7381
/**
74-
* @deprecated Use {@link FrameDisposalModes.KEEP}, `Frame.DISPOSAL_*` will be removed in 4.0
82+
* @deprecated Use the name `'keep'`: `Frame.DISPOSAL_*` and `FrameDisposalModes` are removed in 4.0
7583
* @group Deprecated
7684
*/
7785
static readonly DISPOSAL_KEEP: typeof FrameDisposalModes.KEEP = FrameDisposalModes.KEEP;
7886

7987
/**
80-
* @deprecated Use {@link FrameDisposalModes.PREVIOUS}, `Frame.DISPOSAL_*` will be removed in 4.0
88+
* @deprecated Use the name `'previous'`: `Frame.DISPOSAL_*` and `FrameDisposalModes` are removed in 4.0
8189
* @group Deprecated
8290
*/
8391
static readonly DISPOSAL_PREVIOUS: typeof FrameDisposalModes.PREVIOUS = FrameDisposalModes.PREVIOUS;
8492

8593
/**
86-
* @deprecated Use {@link FrameDisposalModes.BACKGROUND}, `Frame.DISPOSAL_*` will be removed in 4.0
94+
* @deprecated Use the name `'background'`: `Frame.DISPOSAL_*` and `FrameDisposalModes` are removed in 4.0
8795
* @group Deprecated
8896
*/
8997
static readonly DISPOSAL_BACKGROUND: typeof FrameDisposalModes.BACKGROUND = FrameDisposalModes.BACKGROUND;

‎src/gainmap.ts‎

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,18 @@ export interface GainMapEncodeOptions {
1313
/** Options of the {@link GainMap} constructor: per channel values can be one number for all three or [r, g, b] */
1414
export interface GainMapOptions {
1515
/** log2 of the boost of the map's value 0 (`-1`: half as bright). Default: `0` */
16-
gainMapMin?: number | number[];
16+
min?: number | number[];
1717
/** log2 of the boost of the map's value 255 (`2`: 4 times as bright). Default: `2` */
18+
max?: number | number[];
19+
/**
20+
* Like {@link GainMapOptions.min}
21+
* @deprecated Use `min`, its name in 4.0, which ignores `gainMapMin`
22+
*/
23+
gainMapMin?: number | number[];
24+
/**
25+
* Like {@link GainMapOptions.max}
26+
* @deprecated Use `max`, its name in 4.0, which ignores `gainMapMax`
27+
*/
1828
gainMapMax?: number | number[];
1929
/** the gamma the map's values are stored with. Default: `1` */
2030
gamma?: number | number[];
@@ -47,9 +57,15 @@ const perChannel = (value: number | number[], name: string): number[] => {
4757
* light of the image by `2^(gainMapMin + (gainMapMax - gainMapMin) * (v / 255)^(1 / gamma))`
4858
*/
4959
export class GainMap {
50-
/** log2 of the boost of the map's value 0, per channel (red, green, blue) */
60+
/**
61+
* log2 of the boost of the map's value 0, per channel (red, green, blue)
62+
* @deprecated Use {@link GainMap.min}, its name in 4.0
63+
*/
5164
gainMapMin: number[];
52-
/** log2 of the boost of the map's value 255, per channel */
65+
/**
66+
* log2 of the boost of the map's value 255, per channel
67+
* @deprecated Use {@link GainMap.max}, its name in 4.0
68+
*/
5369
gainMapMax: number[];
5470
/** the gamma the map's values are stored with, per channel */
5571
gamma: number[];
@@ -73,9 +89,33 @@ export class GainMap {
7389
* ignored
7490
* @param options See {@link GainMapOptions}
7591
*/
92+
/** log2 of the boost of the map's value 0, per channel (red, green, blue): {@link GainMap.gainMapMin}, by its name in 4.0 */
93+
get min(): number[] {
94+
return this.gainMapMin;
95+
}
96+
97+
/** Sets {@link GainMap.gainMapMin} */
98+
set min(value: number[]) {
99+
this.gainMapMin = value;
100+
}
101+
102+
/** log2 of the boost of the map's value 255, per channel: {@link GainMap.gainMapMax}, by its name in 4.0 */
103+
get max(): number[] {
104+
return this.gainMapMax;
105+
}
106+
107+
/** Sets {@link GainMap.gainMapMax} */
108+
set max(value: number[]) {
109+
this.gainMapMax = value;
110+
}
111+
76112
constructor(image: Image, options: GainMapOptions = {}) {
77113
if (!(image instanceof Image)) throw new TypeError('The gain map has to be an Image');
78-
const { gainMapMin = 0, gainMapMax = 2, gamma = 1, offsetSDR = 1 / 64, offsetHDR = 1 / 64, hdrCapacityMin = 0, useBaseColorSpace = true } = options;
114+
if (options.min !== undefined && options.gainMapMin !== undefined) throw new TypeError('A gain map takes min, or the deprecated gainMapMin, not both');
115+
if (options.max !== undefined && options.gainMapMax !== undefined) throw new TypeError('A gain map takes max, or the deprecated gainMapMax, not both');
116+
const { gamma = 1, offsetSDR = 1 / 64, offsetHDR = 1 / 64, hdrCapacityMin = 0, useBaseColorSpace = true } = options;
117+
// (min and max are the names of 4.0)
118+
const gainMapMin = options.min ?? options.gainMapMin ?? 0, gainMapMax = options.max ?? options.gainMapMax ?? 2;
79119
this.gainMapMin = perChannel(gainMapMin, 'gainMapMin');
80120
this.gainMapMax = perChannel(gainMapMax, 'gainMapMax');
81121
this.gamma = perChannel(gamma, 'gamma');

‎src/image.ts‎

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
6263
export 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
*/
6870
export 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+
*/
101107
export 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} */
387396
export 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

Comments
 (0)