imagescript 3.20.3 → 3.20.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/frame.d.ts CHANGED
@@ -1,13 +1,21 @@
1
1
  import { Image, ResizeMode, ResizeOptions, ResizeToOptions, Color, TrimOptions } from './image.js';
2
2
  /** Names of the frame disposal modes, see {@link Frame.disposalMode} */
3
- export type FrameDisposalModeName = 'any' | 'keep' | 'previous' | 'background';
3
+ export type FrameDisposalMode = 'any' | 'keep' | 'previous' | 'background';
4
+ /**
5
+ * Names of the frame disposal modes, see {@link Frame.disposalMode}
6
+ * @deprecated Use {@link FrameDisposalMode}, its name in 4.0
7
+ */
8
+ export type FrameDisposalModeName = FrameDisposalMode;
4
9
  /**
5
10
  * Ids of the frame disposal modes, as GIFs store them (0 any, 1 keep, 2 previous, 3 background)
6
- * @deprecated Use the names ({@link FrameDisposalModeName}: `'any'`, `'keep'`, `'previous'`, `'background'`), the ids will
11
+ * @deprecated Use the names ({@link FrameDisposalMode}: `'any'`, `'keep'`, `'previous'`, `'background'`), the ids will
7
12
  * be removed in 4.0
8
13
  */
9
14
  export type FrameDisposalModeId = 0 | 1 | 2 | 3;
10
- /** What happens to a frame's area before the next frame is drawn, see {@link Frame.disposalMode} */
15
+ /**
16
+ * What happens to a frame's area before the next frame is drawn, see {@link Frame.disposalMode}
17
+ * @deprecated Use the names, `'background'` for `FrameDisposalModes.BACKGROUND`: `FrameDisposalModes` is removed in 4.0
18
+ */
11
19
  export declare class FrameDisposalModes {
12
20
  /** The decoder decides (in practice like {@link FrameDisposalModes.KEEP}) */
13
21
  static readonly ANY = "any";
@@ -45,22 +53,22 @@ export declare class Frame extends Image {
45
53
  /** The frame's vertical offset in the animation */
46
54
  yOffset: number;
47
55
  /**
48
- * @deprecated Use {@link FrameDisposalModes.ANY}, `Frame.DISPOSAL_*` will be removed in 4.0
56
+ * @deprecated Use the name `'any'`: `Frame.DISPOSAL_*` and `FrameDisposalModes` are removed in 4.0
49
57
  * @group Deprecated
50
58
  */
51
59
  static readonly DISPOSAL_ANY: typeof FrameDisposalModes.ANY;
52
60
  /**
53
- * @deprecated Use {@link FrameDisposalModes.KEEP}, `Frame.DISPOSAL_*` will be removed in 4.0
61
+ * @deprecated Use the name `'keep'`: `Frame.DISPOSAL_*` and `FrameDisposalModes` are removed in 4.0
54
62
  * @group Deprecated
55
63
  */
56
64
  static readonly DISPOSAL_KEEP: typeof FrameDisposalModes.KEEP;
57
65
  /**
58
- * @deprecated Use {@link FrameDisposalModes.PREVIOUS}, `Frame.DISPOSAL_*` will be removed in 4.0
66
+ * @deprecated Use the name `'previous'`: `Frame.DISPOSAL_*` and `FrameDisposalModes` are removed in 4.0
59
67
  * @group Deprecated
60
68
  */
61
69
  static readonly DISPOSAL_PREVIOUS: typeof FrameDisposalModes.PREVIOUS;
62
70
  /**
63
- * @deprecated Use {@link FrameDisposalModes.BACKGROUND}, `Frame.DISPOSAL_*` will be removed in 4.0
71
+ * @deprecated Use the name `'background'`: `Frame.DISPOSAL_*` and `FrameDisposalModes` are removed in 4.0
64
72
  * @group Deprecated
65
73
  */
66
74
  static readonly DISPOSAL_BACKGROUND: typeof FrameDisposalModes.BACKGROUND;
package/dist/gainmap.d.ts CHANGED
@@ -8,8 +8,18 @@ export interface GainMapEncodeOptions {
8
8
  /** Options of the {@link GainMap} constructor: per channel values can be one number for all three or [r, g, b] */
9
9
  export interface GainMapOptions {
10
10
  /** log2 of the boost of the map's value 0 (`-1`: half as bright). Default: `0` */
11
- gainMapMin?: number | number[];
11
+ min?: number | number[];
12
12
  /** log2 of the boost of the map's value 255 (`2`: 4 times as bright). Default: `2` */
13
+ max?: number | number[];
14
+ /**
15
+ * Like {@link GainMapOptions.min}
16
+ * @deprecated Use `min`, its name in 4.0, which ignores `gainMapMin`
17
+ */
18
+ gainMapMin?: number | number[];
19
+ /**
20
+ * Like {@link GainMapOptions.max}
21
+ * @deprecated Use `max`, its name in 4.0, which ignores `gainMapMax`
22
+ */
13
23
  gainMapMax?: number | number[];
14
24
  /** the gamma the map's values are stored with. Default: `1` */
15
25
  gamma?: number | number[];
@@ -34,9 +44,15 @@ export interface GainMapOptions {
34
44
  * light of the image by `2^(gainMapMin + (gainMapMax - gainMapMin) * (v / 255)^(1 / gamma))`
35
45
  */
36
46
  export declare class GainMap {
37
- /** log2 of the boost of the map's value 0, per channel (red, green, blue) */
47
+ /**
48
+ * log2 of the boost of the map's value 0, per channel (red, green, blue)
49
+ * @deprecated Use {@link GainMap.min}, its name in 4.0
50
+ */
38
51
  gainMapMin: number[];
39
- /** log2 of the boost of the map's value 255, per channel */
52
+ /**
53
+ * log2 of the boost of the map's value 255, per channel
54
+ * @deprecated Use {@link GainMap.max}, its name in 4.0
55
+ */
40
56
  gainMapMax: number[];
41
57
  /** the gamma the map's values are stored with, per channel */
42
58
  gamma: number[];
@@ -58,6 +74,14 @@ export declare class GainMap {
58
74
  * ignored
59
75
  * @param options See {@link GainMapOptions}
60
76
  */
77
+ /** log2 of the boost of the map's value 0, per channel (red, green, blue): {@link GainMap.gainMapMin}, by its name in 4.0 */
78
+ get min(): number[];
79
+ /** Sets {@link GainMap.gainMapMin} */
80
+ set min(value: number[]);
81
+ /** log2 of the boost of the map's value 255, per channel: {@link GainMap.gainMapMax}, by its name in 4.0 */
82
+ get max(): number[];
83
+ /** Sets {@link GainMap.gainMapMax} */
84
+ set max(value: number[]);
61
85
  constructor(image: Image, options?: GainMapOptions);
62
86
  private __set_params__;
63
87
  private __check__;
package/dist/gainmap.js CHANGED
@@ -21,10 +21,27 @@ export class GainMap {
21
21
  hdrCapacityMax;
22
22
  useBaseColorSpace;
23
23
  __pixels__ = null;
24
+ get min() {
25
+ return this.gainMapMin;
26
+ }
27
+ set min(value) {
28
+ this.gainMapMin = value;
29
+ }
30
+ get max() {
31
+ return this.gainMapMax;
32
+ }
33
+ set max(value) {
34
+ this.gainMapMax = value;
35
+ }
24
36
  constructor(image, options = {}) {
25
37
  if (!(image instanceof Image))
26
38
  throw new TypeError('The gain map has to be an Image');
27
- const { gainMapMin = 0, gainMapMax = 2, gamma = 1, offsetSDR = 1 / 64, offsetHDR = 1 / 64, hdrCapacityMin = 0, useBaseColorSpace = true } = options;
39
+ if (options.min !== undefined && options.gainMapMin !== undefined)
40
+ throw new TypeError('A gain map takes min, or the deprecated gainMapMin, not both');
41
+ if (options.max !== undefined && options.gainMapMax !== undefined)
42
+ throw new TypeError('A gain map takes max, or the deprecated gainMapMax, not both');
43
+ const { gamma = 1, offsetSDR = 1 / 64, offsetHDR = 1 / 64, hdrCapacityMin = 0, useBaseColorSpace = true } = options;
44
+ const gainMapMin = options.min ?? options.gainMapMin ?? 0, gainMapMax = options.max ?? options.gainMapMax ?? 2;
28
45
  this.gainMapMin = perChannel(gainMapMin, 'gainMapMin');
29
46
  this.gainMapMax = perChannel(gainMapMax, 'gainMapMax');
30
47
  this.gamma = perChannel(gamma, 'gamma');
package/dist/image.d.ts CHANGED
@@ -16,11 +16,13 @@ export type ResizeMode = 'nearest-neighbor' | 'bilinear' | 'bicubic' | 'area' |
16
16
  /**
17
17
  * How {@link Image.renderSVG} scales, see {@link SVGScaleModes}. The numbers 1-3 (the values of the deprecated
18
18
  * `Image.SVG_MODE_*`) still work, they are removed in 4.0
19
+ * @deprecated Use `renderSVG(svg, { width })`, `{ height }` or `{ scale }`: the `mode` option is removed in 4.0
19
20
  */
20
21
  export type SVGScaleMode = 'scale' | 'width' | 'height' | 1 | 2 | 3;
21
22
  /**
22
23
  * The resampling filters of {@link Image.resize} and the other scaling functions:
23
24
  * `image.resize({ width: 256, mode: ResizeModes.BICUBIC })`
25
+ * @deprecated Use the names, `image.resize({ width: 256, mode: 'bicubic' })`: `ResizeModes` is removed in 4.0
24
26
  */
25
27
  export declare class ResizeModes {
26
28
  /**
@@ -48,7 +50,11 @@ export declare class ResizeModes {
48
50
  static readonly AUTO = -1;
49
51
  private constructor();
50
52
  }
51
- /** How {@link Image.renderSVG} scales the SVG to the given size */
53
+ /**
54
+ * How {@link Image.renderSVG} scales the SVG to the given size
55
+ * @deprecated Use `renderSVG(svg, { width })`, `{ height }` or `{ scale }`: `SVGScaleModes` and the `mode` option are
56
+ * removed in 4.0
57
+ */
52
58
  export declare class SVGScaleModes {
53
59
  /** The size is a factor of the SVG's own size */
54
60
  static readonly SCALE = "scale";
@@ -303,15 +309,33 @@ export interface FisheyeOptions {
303
309
  /** The distortion strength (exponent of the radial mapping), higher values bulge the center more. Default: `2` */
304
310
  strength?: number;
305
311
  }
312
+ /** Options of {@link Image.renderSVG}: {@link SVGOptions}, by its name in 4.0 */
313
+ export type RenderSVGOptions = SVGOptions;
306
314
  /** Options of {@link Image.renderSVG} */
307
315
  export interface SVGOptions {
308
- /** The scale, or the width or height in pixels, see `mode`. Default: `1` */
316
+ /** The width in pixels, the height follows the SVG's aspect ratio. Only one of `width`, `height` and `scale` */
317
+ width?: number;
318
+ /** The height in pixels, the width follows the SVG's aspect ratio. Only one of `width`, `height` and `scale` */
319
+ height?: number;
320
+ /** A factor of the SVG's own size. Only one of `width`, `height` and `scale`. Default: `1` */
321
+ scale?: number;
322
+ /**
323
+ * The scale, or the width or height in pixels, see `mode`. Default: `1`
324
+ * @deprecated Use `width`, `height` or `scale`, their names in 4.0, which ignores `size` and `mode`:
325
+ * `renderSVG(svg, { width: 512 })`
326
+ */
309
327
  size?: number;
310
328
  /**
311
329
  * What `size` is: one of {@link SVGScaleModes.SCALE}, {@link SVGScaleModes.WIDTH}, {@link SVGScaleModes.HEIGHT}.
312
330
  * Default: {@link SVGScaleModes.SCALE}
331
+ * @deprecated Use `width`, `height` or `scale`, their names in 4.0, which ignores `size` and `mode`:
332
+ * `renderSVG(svg, { width: 512 })`
313
333
  */
314
334
  mode?: SVGScaleMode;
335
+ /**
336
+ * Fonts for `<text>`, like {@link SVGOptions.fonts}: one font, or several
337
+ */
338
+ font?: BinaryData | BinaryData[];
315
339
  /**
316
340
  * Fonts for `<text>` (TrueType, OpenType): each text gets the face its `font-family`, `font-weight`, `font-style`
317
341
  * and `font-stretch` match best among them, by the names, weights and styles in the fonts (like browsers match
@@ -319,6 +343,7 @@ export interface SVGOptions {
319
343
  * other families and text without one get the first font's family; characters a face doesn't have come from the
320
344
  * other fonts (TrueType, OpenType or WOFF). Fonts the SVG embeds with `@font-face` (in data: URIs) are used too,
321
345
  * before these for their family names. Without any fonts text isn't rendered. Default: `[]`
346
+ * @deprecated Use `font`, its name in 4.0, which ignores `fonts` (one font, or several in an array)
322
347
  */
323
348
  fonts?: BinaryData[];
324
349
  /**
@@ -493,10 +518,15 @@ export interface CropCircleOptions {
493
518
  * `'cover'` covers the image (the larger dimension is its diameter, the corners of a rectangular image stay
494
519
  * transparent on the shorter side). Default: `'contain'`
495
520
  */
521
+ fit?: 'contain' | 'cover';
522
+ /**
523
+ * The circle's size, like {@link CropCircleOptions.fit}
524
+ * @deprecated Use `fit`, its name in 4.0, which ignores `size`: `cropCircle({ fit: 'cover' })`
525
+ */
496
526
  size?: 'contain' | 'cover';
497
527
  /**
498
528
  * Whether to use the larger dimension for the size. Default: `false`
499
- * @deprecated Use `size: 'cover'` (`true`) or `size: 'contain'` (`false`), `max` will be removed in 4.0
529
+ * @deprecated Use `fit: 'cover'` (`true`) or `fit: 'contain'` (`false`), `max` will be removed in 4.0
500
530
  */
501
531
  max?: boolean;
502
532
  /** Share of the radius (0..1) over which the edge fades out. Default: `0` */
@@ -734,22 +764,22 @@ export declare class Image {
734
764
  */
735
765
  clone(): Image;
736
766
  /**
737
- * @deprecated Use {@link ResizeModes.NEAREST_NEIGHBOR}, `Image.RESIZE_*` will be removed in 4.0
767
+ * @deprecated Use the name `'nearest-neighbor'`: `Image.RESIZE_*` and `ResizeModes` are removed in 4.0
738
768
  * @group Deprecated
739
769
  */
740
770
  static readonly RESIZE_NEAREST_NEIGHBOR = "RESIZE_NEAREST_NEIGHBOR";
741
771
  /**
742
- * @deprecated Use {@link ResizeModes.BILINEAR}, `Image.RESIZE_*` will be removed in 4.0
772
+ * @deprecated Use the name `'bilinear'`: `Image.RESIZE_*` and `ResizeModes` are removed in 4.0
743
773
  * @group Deprecated
744
774
  */
745
775
  static readonly RESIZE_BILINEAR = "RESIZE_BILINEAR";
746
776
  /**
747
- * @deprecated Use {@link ResizeModes.BICUBIC}, `Image.RESIZE_*` will be removed in 4.0
777
+ * @deprecated Use the name `'bicubic'`: `Image.RESIZE_*` and `ResizeModes` are removed in 4.0
748
778
  * @group Deprecated
749
779
  */
750
780
  static readonly RESIZE_BICUBIC = "RESIZE_BICUBIC";
751
781
  /**
752
- * @deprecated Use {@link ResizeModes.AREA}, `Image.RESIZE_*` will be removed in 4.0
782
+ * @deprecated Use the name `'area'`: `Image.RESIZE_*` and `ResizeModes` are removed in 4.0
753
783
  * @group Deprecated
754
784
  */
755
785
  static readonly RESIZE_AREA = "RESIZE_AREA";
@@ -916,7 +946,7 @@ export declare class Image {
916
946
  * Crops the image into a circle with an antialiased edge
917
947
  * @param max Whether to use the larger dimension for the size. Default: `false`
918
948
  * @param feathering Share of the radius (0..1) over which the edge fades out. Default: `0`
919
- * @deprecated Pass {@link CropCircleOptions} instead, `cropCircle({ size: 'cover' })`. The arguments will be
949
+ * @deprecated Pass {@link CropCircleOptions} instead, `cropCircle({ fit: 'cover' })`. The arguments will be
920
950
  * removed in 4.0
921
951
  */
922
952
  cropCircle(max?: boolean, feathering?: number): this;
@@ -1334,17 +1364,17 @@ export declare class Image {
1334
1364
  */
1335
1365
  static decode(input: BinaryData, options?: DecodeOptions): Promise<Image>;
1336
1366
  /**
1337
- * @deprecated Use {@link SVGScaleModes.SCALE}, `Image.SVG_MODE_*` will be removed in 4.0
1367
+ * @deprecated Use `renderSVG(svg, { scale })`: `Image.SVG_MODE_*` and `SVGScaleModes` are removed in 4.0
1338
1368
  * @group Deprecated
1339
1369
  */
1340
1370
  static readonly SVG_MODE_SCALE = 1;
1341
1371
  /**
1342
- * @deprecated Use {@link SVGScaleModes.WIDTH}, `Image.SVG_MODE_*` will be removed in 4.0
1372
+ * @deprecated Use `renderSVG(svg, { width })`: `Image.SVG_MODE_*` and `SVGScaleModes` are removed in 4.0
1343
1373
  * @group Deprecated
1344
1374
  */
1345
1375
  static readonly SVG_MODE_WIDTH = 2;
1346
1376
  /**
1347
- * @deprecated Use {@link SVGScaleModes.HEIGHT}, `Image.SVG_MODE_*` will be removed in 4.0
1377
+ * @deprecated Use `renderSVG(svg, { height })`: `Image.SVG_MODE_*` and `SVGScaleModes` are removed in 4.0
1348
1378
  * @group Deprecated
1349
1379
  */
1350
1380
  static readonly SVG_MODE_HEIGHT = 3;
@@ -1372,7 +1402,8 @@ export declare class Image {
1372
1402
  * @param size The size to use
1373
1403
  * @param mode The SVG resizing mode to use (one of {@link SVGScaleModes.SCALE}, {@link SVGScaleModes.WIDTH}, {@link SVGScaleModes.HEIGHT})
1374
1404
  * @return The rendered SVG graphic
1375
- * @deprecated Pass {@link SVGOptions} instead, the positional arguments will be removed in 4.0
1405
+ * @deprecated Pass {@link SVGOptions} instead, `renderSVG(svg, { width: 512 })` (or `height`, `scale`). The
1406
+ * positional arguments will be removed in 4.0
1376
1407
  */
1377
1408
  static renderSVG(svg: string | BinaryData, size?: number, mode?: SVGScaleMode): Promise<Image>;
1378
1409
  /**
package/dist/image.js CHANGED
@@ -517,8 +517,9 @@ export class Image {
517
517
  b[i + 3] = a * 255;
518
518
  }
519
519
  cropCircle(maxOrOptions = false, featheringArgument = 0) {
520
- const { max = false, size = max ? 'cover' : 'contain', feathering = 0 } = typeof maxOrOptions === 'object' && maxOrOptions !== null
520
+ const { max = false, fit, size: givenSize, feathering = 0 } = typeof maxOrOptions === 'object' && maxOrOptions !== null
521
521
  ? maxOrOptions : { max: maxOrOptions, feathering: featheringArgument };
522
+ const size = fit ?? givenSize ?? (max ? 'cover' : 'contain');
522
523
  finite(feathering, 'feathering');
523
524
  if (size !== 'contain' && size !== 'cover')
524
525
  throw new TypeError(`Invalid circle size: ${String(size)}`);
@@ -1626,7 +1627,19 @@ export class Image {
1626
1627
  static SVG_MODE_WIDTH = 2;
1627
1628
  static SVG_MODE_HEIGHT = 3;
1628
1629
  static async renderSVG(svg, sizeOrOptions = 1, modeArgument = SVGScaleModes.SCALE) {
1629
- const { size = 1, mode: givenMode = SVGScaleModes.SCALE, fonts = [], images: givenImages = {} } = isOptions(sizeOrOptions) ? sizeOrOptions : { size: sizeOrOptions, mode: modeArgument };
1630
+ const options = isOptions(sizeOrOptions) ? sizeOrOptions : { size: sizeOrOptions, mode: modeArgument };
1631
+ const sizes = [options.width, options.height, options.scale].filter(value => value !== undefined).length;
1632
+ if (sizes > 1)
1633
+ throw new TypeError('renderSVG() takes one of width, height and scale');
1634
+ if (sizes && (options.size !== undefined || options.mode !== undefined))
1635
+ throw new TypeError('renderSVG() takes width, height or scale, or the deprecated size and mode, not both');
1636
+ if (options.font !== undefined && options.fonts !== undefined)
1637
+ throw new TypeError('renderSVG() takes font, or the deprecated fonts, not both');
1638
+ const { size = 1, mode: givenMode = SVGScaleModes.SCALE } = options.width !== undefined ? { size: options.width, mode: SVGScaleModes.WIDTH }
1639
+ : options.height !== undefined ? { size: options.height, mode: SVGScaleModes.HEIGHT }
1640
+ : options.scale !== undefined ? { size: options.scale, mode: SVGScaleModes.SCALE } : options;
1641
+ const { images: givenImages = {} } = options;
1642
+ const fonts = options.font === undefined ? options.fonts ?? [] : Array.isArray(options.font) ? options.font : [options.font];
1630
1643
  const mode = LEGACY_SVG_MODES.get(givenMode) ?? givenMode;
1631
1644
  if (mode !== 'scale' && mode !== 'width' && mode !== 'height')
1632
1645
  throw new Error('Invalid SVG scaling mode');
package/dist/index.d.ts CHANGED
@@ -4,9 +4,9 @@ import { GIF } from './gif.js';
4
4
  import { Animation, AnimationDecodeOptions } from './animation.js';
5
5
  export { Image, ResizeModes, SVGScaleModes } from './image.js';
6
6
  export { Colors } from './colors.js';
7
- export type { Color, ColorFunction, ResizeMode, SVGScaleMode, PNGMetadata, TextStyle, DecodeOptions, CompositeOptions, BlendMode, CropCircleOptions, DominantColorOptions, RotateOptions, ColorToAlphaOptions, ResizeOptions, ResizeToOptions, AdjustOptions, SharpenOptions, PNGEncodeOptions, JPEGEncodeOptions, WebPEncodeOptions, AVIFEncodeOptions, JXLEncodeOptions, EncodeOptions, SVGOptions, TextOptions, RenderTextOptions, ShadowOptions, OutlineOptions, QuantizeOptions, TransformOptions, TransformMode, GradientOptions, LinearGradientOptions, RadialGradientOptions, RoundCornersOptions, FisheyeOptions, TrimOptions } from './image.js';
7
+ export type { Color, ColorFunction, ResizeMode, SVGScaleMode, PNGMetadata, TextStyle, DecodeOptions, CompositeOptions, BlendMode, CropCircleOptions, DominantColorOptions, RotateOptions, ColorToAlphaOptions, ResizeOptions, ResizeToOptions, AdjustOptions, SharpenOptions, PNGEncodeOptions, JPEGEncodeOptions, WebPEncodeOptions, AVIFEncodeOptions, JXLEncodeOptions, EncodeOptions, SVGOptions, RenderSVGOptions, TextOptions, RenderTextOptions, ShadowOptions, OutlineOptions, QuantizeOptions, TransformOptions, TransformMode, GradientOptions, LinearGradientOptions, RadialGradientOptions, RoundCornersOptions, FisheyeOptions, TrimOptions } from './image.js';
8
8
  export { Frame, FrameDisposalModes } from './frame.js';
9
- export type { FrameDisposalModeName, FrameDisposalModeId, FrameOptions } from './frame.js';
9
+ export type { FrameDisposalMode, FrameDisposalModeName, FrameDisposalModeId, FrameOptions } from './frame.js';
10
10
  export { GainMap } from './gainmap.js';
11
11
  export type { GainMapOptions, GainMapEncodeOptions } from './gainmap.js';
12
12
  export { GIF } from './gif.js';
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = '3.20.3';
1
+ export const VERSION = '3.20.4';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imagescript",
3
- "version": "3.20.3",
3
+ "version": "3.20.4",
4
4
  "description": "Pure TypeScript image processing that runs everywhere",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",