imagescript 3.17.0 → 3.19.0

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/image.js CHANGED
@@ -37,17 +37,17 @@ import { GainMap } from "./gainmap.js";
37
37
  import * as gain from "./util/gain.js";
38
38
  import * as gainMapCodec from "./codecs/gainmap.js";
39
39
  export class ResizeModes {
40
- static NEAREST_NEIGHBOR = 'RESIZE_NEAREST_NEIGHBOR';
41
- static BILINEAR = 'RESIZE_BILINEAR';
42
- static BICUBIC = 'RESIZE_BICUBIC';
43
- static AREA = 'RESIZE_AREA';
40
+ static NEAREST_NEIGHBOR = 'nearest-neighbor';
41
+ static BILINEAR = 'bilinear';
42
+ static BICUBIC = 'bicubic';
43
+ static AREA = 'area';
44
44
  static AUTO = -1;
45
45
  constructor() { }
46
46
  }
47
47
  export class SVGScaleModes {
48
- static SCALE = 1;
49
- static WIDTH = 2;
50
- static HEIGHT = 3;
48
+ static SCALE = 'scale';
49
+ static WIDTH = 'width';
50
+ static HEIGHT = 'height';
51
51
  constructor() { }
52
52
  }
53
53
  function featureList(features) {
@@ -115,18 +115,24 @@ export class Image {
115
115
  get height() {
116
116
  return this.__height__;
117
117
  }
118
- *[Symbol.iterator]() {
118
+ *coordinates() {
119
119
  for (let y = 0; y < this.height; y++)
120
120
  for (let x = 0; x < this.width; x++)
121
121
  yield [x, y];
122
122
  }
123
- *iterateWithColors() {
123
+ *pixels() {
124
124
  const view = new DataView(this.bitmap.buffer, this.bitmap.byteOffset, this.bitmap.byteLength);
125
125
  let offset = 0;
126
126
  for (let y = 0; y < this.height; y++)
127
127
  for (let x = 0; x < this.width; x++, offset += 4)
128
128
  yield [x, y, view.getUint32(offset, false)];
129
129
  }
130
+ *[Symbol.iterator]() {
131
+ yield* this.coordinates();
132
+ }
133
+ *iterateWithColors() {
134
+ yield* this.pixels();
135
+ }
130
136
  static rgbaToColor(r, g, b, a) {
131
137
  return Colors.fromRGBA(r, g, b, a);
132
138
  }
@@ -148,6 +154,34 @@ export class Image {
148
154
  static colorToRGB(color) {
149
155
  return Colors.toRGB(color);
150
156
  }
157
+ static linearGradient(width, height, options) {
158
+ const { stops, angle = 180 } = options;
159
+ const color = gradientFunction(stops);
160
+ finite(angle, 'angle');
161
+ const image = new Image(width, height);
162
+ const radians = angle * Math.PI / 180;
163
+ const dx = Math.sin(radians), dy = -Math.cos(radians);
164
+ const length = Math.abs(width * dx) + Math.abs(height * dy);
165
+ const cx = width / 2, cy = height / 2, bitmap = new DataView(image.bitmap.buffer, image.bitmap.byteOffset, image.bitmap.byteLength);
166
+ for (let y = 0, i = 0; y < height; y++)
167
+ for (let x = 0; x < width; x++, i += 4)
168
+ bitmap.setUint32(i, color(((x + 0.5 - cx) * dx + (y + 0.5 - cy) * dy) / length + 0.5), false);
169
+ return image;
170
+ }
171
+ static radialGradient(width, height, options) {
172
+ const { stops, x: cx = width / 2, y: cy = height / 2, radius = Math.hypot(Math.max(cx, width - cx), Math.max(cy, height - cy)) } = options;
173
+ const color = gradientFunction(stops);
174
+ finite(cx, 'x');
175
+ finite(cy, 'y');
176
+ if (!(finite(radius, 'radius') > 0))
177
+ throw new RangeError('Invalid radius');
178
+ const image = new Image(width, height);
179
+ const bitmap = new DataView(image.bitmap.buffer, image.bitmap.byteOffset, image.bitmap.byteLength);
180
+ for (let y = 0, i = 0; y < height; y++)
181
+ for (let x = 0; x < width; x++, i += 4)
182
+ bitmap.setUint32(i, color(Math.hypot(x + 0.5 - cx, y + 0.5 - cy) / radius), false);
183
+ return image;
184
+ }
151
185
  static gradient(colors) {
152
186
  return Colors.gradient(colors);
153
187
  }
@@ -220,10 +254,10 @@ export class Image {
220
254
  image.__gain_map__ = this.__gain_map__ ? this.__gain_map__.clone() : null;
221
255
  return image;
222
256
  }
223
- static RESIZE_NEAREST_NEIGHBOR = ResizeModes.NEAREST_NEIGHBOR;
224
- static RESIZE_BILINEAR = ResizeModes.BILINEAR;
225
- static RESIZE_BICUBIC = ResizeModes.BICUBIC;
226
- static RESIZE_AREA = ResizeModes.AREA;
257
+ static RESIZE_NEAREST_NEIGHBOR = 'RESIZE_NEAREST_NEIGHBOR';
258
+ static RESIZE_BILINEAR = 'RESIZE_BILINEAR';
259
+ static RESIZE_BICUBIC = 'RESIZE_BICUBIC';
260
+ static RESIZE_AREA = 'RESIZE_AREA';
227
261
  static RESIZE_AUTO = ResizeModes.AUTO;
228
262
  scale(factor, modeOrOptions) {
229
263
  const { mode, fast } = resizeOptions(modeOrOptions);
@@ -236,7 +270,8 @@ export class Image {
236
270
  return this;
237
271
  return this.__resize__(this.width * factor, this.height * factor, mode, fast);
238
272
  }
239
- resize(width, height, modeOrOptions) {
273
+ resize(widthOrOptions, heightArgument, modeArgument) {
274
+ const [width, height, modeOrOptions] = resizeArguments(widthOrOptions, heightArgument, modeArgument);
240
275
  const { mode, fast } = resizeOptions(modeOrOptions);
241
276
  const image = this.__resize__(width, height, mode, fast);
242
277
  this.__gain_map__?.__rescale__(this.width, this.height, image.width, image.height);
@@ -341,7 +376,8 @@ export class Image {
341
376
  throw new RangeError('Crop region does not overlap the image');
342
377
  return [left, top, right - left, bottom - top];
343
378
  }
344
- trim(color, options = {}) {
379
+ trim(colorOrOptions, optionsArgument = {}) {
380
+ const { color, ...options } = isOptions(colorOrOptions) ? colorOrOptions : { ...optionsArgument, color: colorOrOptions ?? optionsArgument.color };
345
381
  const bounds = this.__trim_bounds__(color, options);
346
382
  if (!bounds)
347
383
  return this;
@@ -477,10 +513,12 @@ export class Image {
477
513
  b[i + 3] = a * 255;
478
514
  }
479
515
  cropCircle(maxOrOptions = false, featheringArgument = 0) {
480
- const { max = false, feathering = 0 } = typeof maxOrOptions === 'object' && maxOrOptions !== null
516
+ const { max = false, size = max ? 'cover' : 'contain', feathering = 0 } = typeof maxOrOptions === 'object' && maxOrOptions !== null
481
517
  ? maxOrOptions : { max: maxOrOptions, feathering: featheringArgument };
482
518
  finite(feathering, 'feathering');
483
- const radius = (max ? Math.max : Math.min)(this.width, this.height) / 2;
519
+ if (size !== 'contain' && size !== 'cover')
520
+ throw new TypeError(`Invalid circle size: ${String(size)}`);
521
+ const radius = (size === 'cover' ? Math.max : Math.min)(this.width, this.height) / 2;
484
522
  const cx = this.width / 2, cy = this.height / 2;
485
523
  const band = Math.min(1, Math.max(0, feathering)) * radius;
486
524
  for (let y = 0; y < this.height; y++) {
@@ -498,10 +536,24 @@ export class Image {
498
536
  }
499
537
  return this;
500
538
  }
501
- recolor(color) {
539
+ recolor(colorOrImage) {
540
+ if (colorOrImage instanceof Image) {
541
+ const colors = colorOrImage;
542
+ if (colors.width !== this.width || colors.height !== this.height)
543
+ throw new RangeError(`The image to take the colors from has to be ${this.width}x${this.height}, not ${colors.width}x${colors.height}`);
544
+ if (this.__gain_map__)
545
+ return this.__recolor__(image => image.recolor(image.width === colors.width && image.height === colors.height ? colors : colors.clone().resize(image.width, image.height)));
546
+ const from = colors.bitmap, to = this.bitmap;
547
+ for (let i = 0; i < to.length; i += 4) {
548
+ to[i] = from[i];
549
+ to[i + 1] = from[i + 1];
550
+ to[i + 2] = from[i + 2];
551
+ }
552
+ return this;
553
+ }
554
+ const color = checkColor(colorOrImage);
502
555
  if (this.__gain_map__)
503
556
  return this.__recolor__(image => image.recolor(color));
504
- color = checkColor(color);
505
557
  const r = color >>> 24, g = color >> 16 & 0xff, b = color >> 8 & 0xff;
506
558
  for (let i = 0; i < this.bitmap.length; i += 4) {
507
559
  this.bitmap[i] = r;
@@ -783,6 +835,103 @@ export class Image {
783
835
  unpremultiply(pixels, this.bitmap);
784
836
  return this;
785
837
  }
838
+ dropShadow(options = {}) {
839
+ const { x = 0, y = 0, blur = 0, spread = 0, color = 0x00000080, expand = true } = options;
840
+ finite(x, 'x');
841
+ finite(y, 'y');
842
+ if (finite(blur, 'blur') < 0)
843
+ throw new RangeError('Invalid blur radius');
844
+ if (finite(spread, 'spread') < 0)
845
+ throw new RangeError('Invalid spread');
846
+ const [r, g, b, a] = Colors.toRGBA(checkColor(color));
847
+ const reach = spread + 3 * blur, margin = Math.ceil(reach) + 1;
848
+ const layer = this.__shape_layer__(margin);
849
+ const width = layer.width;
850
+ const coverage = new Uint8Array(width * layer.height);
851
+ for (let i = 0; i < coverage.length; i++)
852
+ coverage[i] = layer.bitmap[i * 4 + 3];
853
+ const grown = spread > 0 ? outline(coverage, width, layer.height, spread) : null;
854
+ const bitmap = layer.bitmap;
855
+ for (let i = 0; i < coverage.length; i++) {
856
+ bitmap[i * 4] = r;
857
+ bitmap[i * 4 + 1] = g;
858
+ bitmap[i * 4 + 2] = b;
859
+ bitmap[i * 4 + 3] = (grown ? grown[i] * 255 : coverage[i]) * a / 255;
860
+ }
861
+ if (blur > 0) {
862
+ layer.blur(blur);
863
+ for (let i = 0; i < coverage.length; i++) {
864
+ if (!bitmap[i * 4 + 3])
865
+ continue;
866
+ bitmap[i * 4] = r;
867
+ bitmap[i * 4 + 1] = g;
868
+ bitmap[i * 4 + 2] = b;
869
+ }
870
+ }
871
+ const room = this.__room__();
872
+ return this.__under__(layer, x - margin, y - margin, expand ? {
873
+ left: Math.min(room.left, Math.max(0, Math.ceil(reach - x))),
874
+ top: Math.min(room.top, Math.max(0, Math.ceil(reach - y))),
875
+ right: Math.max(0, Math.ceil(reach + x)),
876
+ bottom: Math.max(0, Math.ceil(reach + y))
877
+ } : { left: 0, top: 0, right: 0, bottom: 0 });
878
+ }
879
+ outline(options = {}) {
880
+ const { width = 1, color = 0x000000ff, expand = true } = options;
881
+ if (finite(width, 'outline width') < 0)
882
+ throw new RangeError('Invalid outline width');
883
+ const [r, g, b, a] = Colors.toRGBA(checkColor(color));
884
+ if (width === 0)
885
+ return this;
886
+ const margin = Math.ceil(width) + 1;
887
+ const layer = this.__shape_layer__(margin);
888
+ const coverage = new Uint8Array(layer.width * layer.height);
889
+ for (let i = 0; i < coverage.length; i++)
890
+ coverage[i] = layer.bitmap[i * 4 + 3];
891
+ const stroke = outline(coverage, layer.width, layer.height, width);
892
+ const bitmap = layer.bitmap;
893
+ for (let i = 0; i < coverage.length; i++) {
894
+ bitmap[i * 4] = r;
895
+ bitmap[i * 4 + 1] = g;
896
+ bitmap[i * 4 + 2] = b;
897
+ bitmap[i * 4 + 3] = stroke[i] * (1 - coverage[i] / 255) * a;
898
+ }
899
+ const room = this.__room__(), grow = Math.ceil(width);
900
+ return this.__under__(layer, -margin, -margin, expand
901
+ ? { left: Math.min(room.left, grow), top: Math.min(room.top, grow), right: grow, bottom: grow }
902
+ : { left: 0, top: 0, right: 0, bottom: 0 });
903
+ }
904
+ __shape_layer__(margin) {
905
+ const layer = new Image(this.width + 2 * margin, this.height + 2 * margin);
906
+ for (let y = 0; y < this.height; y++)
907
+ for (let x = 0; x < this.width; x++)
908
+ layer.bitmap[((y + margin) * layer.width + x + margin) * 4 + 3] = this.bitmap[(y * this.width + x) * 4 + 3];
909
+ return layer;
910
+ }
911
+ __under__(layer, layerX, layerY, grow) {
912
+ const { left, top, right, bottom } = grow;
913
+ const width = this.width + left + right, height = this.height + top + bottom;
914
+ const result = new Image(width, height);
915
+ result.composite(layer, { x: layerX + left, y: layerY + top });
916
+ const map = this.__gain_map__;
917
+ this.__gain_map__ = null;
918
+ try {
919
+ result.composite(this, { x: left, y: top });
920
+ }
921
+ finally {
922
+ this.__gain_map__ = map;
923
+ }
924
+ map?.__transform__(this.width, this.height, width, height, (X, Y) => [X - left, Y - top]);
925
+ this.__apply__(result);
926
+ if (left || top)
927
+ this.__grown__(left, top);
928
+ return this;
929
+ }
930
+ __room__() {
931
+ return { left: Infinity, top: Infinity };
932
+ }
933
+ __grown__(_left, _top) {
934
+ }
786
935
  sharpen(amountOrOptions = 1, radiusArgument = 1) {
787
936
  const { amount = 1, radius = 1 } = isOptions(amountOrOptions) ? amountOrOptions : { amount: amountOrOptions, radius: radiusArgument };
788
937
  if (!Number.isFinite(amount) || amount < 0)
@@ -847,8 +996,9 @@ export class Image {
847
996
  }
848
997
  return this;
849
998
  }
850
- colorToAlpha(color, options = {}) {
851
- const { transparencyThreshold = 0, opacityThreshold = 1 } = options;
999
+ colorToAlpha(colorOrOptions, optionsArgument = {}) {
1000
+ const { color: colorOption, transparencyThreshold = 0, opacityThreshold = 1 } = isOptions(colorOrOptions) ? colorOrOptions : { ...optionsArgument, color: colorOrOptions ?? optionsArgument.color };
1001
+ let color = colorOption;
852
1002
  if (!(transparencyThreshold >= 0 && opacityThreshold <= 1 && transparencyThreshold < opacityThreshold))
853
1003
  throw new RangeError('Invalid thresholds, they have to satisfy 0 <= transparencyThreshold < opacityThreshold <= 1');
854
1004
  const bitmap = this.bitmap;
@@ -1106,7 +1256,7 @@ export class Image {
1106
1256
  });
1107
1257
  return this.__apply__(r);
1108
1258
  }
1109
- async encode(compressionOrOptions = 4, metadataArgument = {}) {
1259
+ async encodePNG(compressionOrOptions = 4, metadataArgument = {}) {
1110
1260
  let compression = 4, metadata = metadataArgument;
1111
1261
  if (!isOptions(compressionOrOptions))
1112
1262
  compression = compressionOrOptions;
@@ -1116,8 +1266,8 @@ export class Image {
1116
1266
  metadata = compressionOrOptions;
1117
1267
  return png.encodeRGBA(this.__bytes__(), this.width, this.height, compressionLevel(compression), pngText(resolveMetadata(metadata)));
1118
1268
  }
1119
- encodePNG(compressionOrOptions, metadata) {
1120
- return this.encode(compressionOrOptions, metadata);
1269
+ encode(compressionOrOptions, metadata) {
1270
+ return this.encodePNG(compressionOrOptions, metadata);
1121
1271
  }
1122
1272
  async encodeJPEG(qualityOrOptions = 90) {
1123
1273
  const { quality = 90, metadata = {}, gainMap: gainMapOption = true } = isOptions(qualityOrOptions) ? qualityOrOptions : { quality: qualityOrOptions };
@@ -1326,12 +1476,13 @@ export class Image {
1326
1476
  }
1327
1477
  return this.__apply__(out);
1328
1478
  }
1329
- static SVG_MODE_SCALE = SVGScaleModes.SCALE;
1330
- static SVG_MODE_WIDTH = SVGScaleModes.WIDTH;
1331
- static SVG_MODE_HEIGHT = SVGScaleModes.HEIGHT;
1479
+ static SVG_MODE_SCALE = 1;
1480
+ static SVG_MODE_WIDTH = 2;
1481
+ static SVG_MODE_HEIGHT = 3;
1332
1482
  static async renderSVG(svg, sizeOrOptions = 1, modeArgument = SVGScaleModes.SCALE) {
1333
- const { size = 1, mode = SVGScaleModes.SCALE, fonts = [] } = isOptions(sizeOrOptions) ? sizeOrOptions : { size: sizeOrOptions, mode: modeArgument };
1334
- if (![1, 2, 3].includes(mode))
1483
+ const { size = 1, mode: givenMode = SVGScaleModes.SCALE, fonts = [] } = isOptions(sizeOrOptions) ? sizeOrOptions : { size: sizeOrOptions, mode: modeArgument };
1484
+ const mode = LEGACY_SVG_MODES.get(givenMode) ?? givenMode;
1485
+ if (mode !== 'scale' && mode !== 'width' && mode !== 'height')
1335
1486
  throw new Error('Invalid SVG scaling mode');
1336
1487
  finite(size, 'SVG size');
1337
1488
  if (mode === SVGScaleModes.SCALE && size <= 0)
@@ -1361,9 +1512,22 @@ export class Image {
1361
1512
  image.bitmap.set(pixels);
1362
1513
  return image;
1363
1514
  }
1364
- static async renderText(font, size, text, colorOrOptions = 0xffffffff, layoutArgument, styleArgument = {}) {
1365
- const options = isOptions(colorOrOptions) ? colorOrOptions : { ...styleArgument, color: colorOrOptions, layout: layoutArgument };
1366
- const { color = 0xffffffff, layout = new TextLayout(), strokeWidth = 0, strokeColor = 0x000000ff, hinting = true, features = {}, variations = {} } = options;
1515
+ static async renderText(fontOrText, sizeOrOptions, textArgument, colorOrOptions = 0xffffffff, layoutArgument, styleArgument = {}) {
1516
+ let font, size, text, options;
1517
+ if (typeof fontOrText === 'string') {
1518
+ if (!isOptions(sizeOrOptions) || sizeOrOptions.font === undefined)
1519
+ throw new TypeError('renderText(text, options) needs the font in the options');
1520
+ ({ font, size, ...options } = sizeOrOptions);
1521
+ text = fontOrText;
1522
+ }
1523
+ else {
1524
+ font = fontOrText;
1525
+ size = sizeOrOptions;
1526
+ text = textArgument;
1527
+ options = isOptions(colorOrOptions) ? colorOrOptions : { ...styleArgument, color: colorOrOptions, layout: layoutArgument };
1528
+ }
1529
+ const { color = 0xffffffff, strokeWidth = 0, strokeColor = 0x000000ff, hinting = true, features = {}, variations = {} } = options;
1530
+ const layout = options.layout instanceof TextLayout ? options.layout : new TextLayout(options.layout);
1367
1531
  const axes = textRenderer.axisValues(variations);
1368
1532
  size = finite(size, 'font size');
1369
1533
  if (size < 0)
@@ -1449,10 +1613,23 @@ function circleCoverage(px, py, cx, cy, radius) {
1449
1613
  return 0;
1450
1614
  return pixelCoverage(px, py, (x, y) => (x - cx) ** 2 + (y - cy) ** 2 <= radius * radius);
1451
1615
  }
1616
+ const LEGACY_RESIZE_MODES = new Map([
1617
+ ['RESIZE_NEAREST_NEIGHBOR', 'nearest-neighbor'], ['RESIZE_BILINEAR', 'bilinear'], ['RESIZE_BICUBIC', 'bicubic'], ['RESIZE_AREA', 'area']
1618
+ ]);
1619
+ export function resizeArguments(widthOrOptions, height, modeOrOptions) {
1620
+ if (!isOptions(widthOrOptions))
1621
+ return [widthOrOptions, height, modeOrOptions];
1622
+ const { width, height: optionsHeight, ...options } = widthOrOptions;
1623
+ if (width === undefined && optionsHeight === undefined)
1624
+ throw new TypeError('resize() needs a width, a height or both');
1625
+ return [width ?? ResizeModes.AUTO, optionsHeight ?? ResizeModes.AUTO, options];
1626
+ }
1452
1627
  function resizeOptions(modeOrOptions) {
1453
1628
  const options = isOptions(modeOrOptions) ? modeOrOptions : { mode: modeOrOptions };
1454
- return { mode: options.mode ?? ResizeModes.BILINEAR, fast: options.fast ?? true };
1629
+ const mode = options.mode ?? ResizeModes.BILINEAR;
1630
+ return { mode: LEGACY_RESIZE_MODES.get(mode) ?? mode, fast: options.fast ?? true };
1455
1631
  }
1632
+ const LEGACY_SVG_MODES = new Map([[1, 'scale'], [2, 'width'], [3, 'height']]);
1456
1633
  const hardLight = (b, s) => s <= 0.5 ? b * 2 * s : 1 - (1 - b) * (1 - (2 * s - 1));
1457
1634
  const BLEND_MODES = {
1458
1635
  'normal': (_b, s) => s,
@@ -1474,6 +1651,14 @@ const BLEND_MODES = {
1474
1651
  'exclusion': (b, s) => b + s - 2 * b * s,
1475
1652
  'add': (b, s) => Math.min(1, b + s)
1476
1653
  };
1654
+ function gradientFunction(stops) {
1655
+ if (!Array.isArray(stops))
1656
+ return Colors.gradient(stops);
1657
+ if (!stops.length)
1658
+ throw new RangeError('Invalid gradient point count');
1659
+ const colors = stops.length === 1 ? [stops[0], stops[0]] : stops;
1660
+ return Colors.gradient(Object.fromEntries(colors.map((color, i) => [i / (colors.length - 1), color])));
1661
+ }
1477
1662
  const OUTLINE_WINDOW = 1;
1478
1663
  function outline(coverage, width, height, radius) {
1479
1664
  const count = width * height;
package/dist/index.d.ts CHANGED
@@ -4,11 +4,11 @@ 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, AdjustOptions, SharpenOptions, PNGEncodeOptions, JPEGEncodeOptions, WebPEncodeOptions, AVIFEncodeOptions, JXLEncodeOptions, EncodeOptions, SVGOptions, TextOptions, 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, TextOptions, RenderTextOptions, ShadowOptions, OutlineOptions, GradientOptions, LinearGradientOptions, RadialGradientOptions, RoundCornersOptions, FisheyeOptions, TrimOptions } from './image.js';
8
8
  export { Frame, FrameDisposalModes } from './frame.js';
9
9
  export type { FrameDisposalModeName, FrameDisposalModeId, FrameOptions } from './frame.js';
10
10
  export { GainMap } from './gainmap.js';
11
- export type { GainMapOptions } from './gainmap.js';
11
+ export type { GainMapOptions, GainMapEncodeOptions } from './gainmap.js';
12
12
  export { GIF } from './gif.js';
13
13
  export { Animation } from './animation.js';
14
14
  export type { AnimationOptions, AnimationDecodeOptions, AnimationEncodeOptions, WebPAnimationEncodeOptions, GIFEncodeOptions, APNGEncodeOptions } from './animation.js';
@@ -63,11 +63,11 @@ export function render(source, mode, size, images = new Map(), fonts = []) {
63
63
  if (!(width > 0) || !(height > 0))
64
64
  throw new Error('SVG: invalid dimensions');
65
65
  let outWidth, outHeight;
66
- if (mode === 2) {
66
+ if (mode === 'width') {
67
67
  outWidth = Math.round(size);
68
68
  outHeight = Math.round(height * size / width);
69
69
  }
70
- else if (mode === 3) {
70
+ else if (mode === 'height') {
71
71
  outHeight = Math.round(size);
72
72
  outWidth = Math.round(width * size / height);
73
73
  }
@@ -14,12 +14,14 @@ export interface TextLayoutOptions {
14
14
  wrapStyle?: WrapStyle;
15
15
  /**
16
16
  * Alignment of the lines relative to the widest line. Default: `'left'`
17
- * (before 3.0 this was called verticalAlign, values are accepted under either name)
17
+ * (before 3.0 this was called verticalAlign, the values of the other axis (`'top'`, `'middle'`, `'bottom'`) are
18
+ * accepted for compatibility, which will be removed in 4.0)
18
19
  */
19
20
  horizontalAlign?: HorizontalAlign | VerticalAlign;
20
21
  /**
21
22
  * Which lines to keep when cutting off at `maxHeight`. Default: `'top'`
22
- * (before 3.0 this was called horizontalAlign, values are accepted under either name)
23
+ * (before 3.0 this was called horizontalAlign, the values of the other axis (`'left'`, `'center'`, `'right'`) are
24
+ * accepted for compatibility, which will be removed in 4.0)
23
25
  */
24
26
  verticalAlign?: VerticalAlign | HorizontalAlign;
25
27
  /** Whether to break lines at newline characters. Default: `true` */
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = '3.17.0';
1
+ export const VERSION = '3.19.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imagescript",
3
- "version": "3.17.0",
3
+ "version": "3.19.0",
4
4
  "description": "Pure TypeScript image processing that runs everywhere",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",