imagescript 3.10.0 → 3.12.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/README.md CHANGED
@@ -56,7 +56,7 @@ and encoded as GIF, APNG or WebP, all at once or
56
56
  P3, Adobe RGB, ...) are converted to sRGB when decoding, so images look the way browsers show them.
57
57
 
58
58
  - [Text rendering](https://imagescript.matmen.dev/classes/Image.html#rendertext) with TrueType and OpenType fonts:
59
- all scripts, color emoji
59
+ all scripts, color emoji, variable fonts
60
60
  - [SVG rendering](https://imagescript.matmen.dev/classes/Image.html#rendersvg), including text (with fonts you pass
61
61
  or fonts embedded in the SVG)
62
62
  - [Resizing](https://imagescript.matmen.dev/classes/Image.html#resize),
@@ -16,7 +16,7 @@ following projects, under their own licenses. Each derived file says so in its h
16
16
  | [dav1d](https://code.videolan.org/videolan/dav1d) by VideoLAN, the dav1d authors and Two Orioles | `src/codecs/av1/*` (the AV1 decoder, and the encoder's syntax, contexts and reconstruction mirrored from it: bitstream parsing, symbol decoding, prediction, inverse transforms, loop filters, film grain; the tables in `src/codecs/av1/data.ts`, generated from dav1d by `scripts/av1-tables.c`) | BSD-2-Clause |
17
17
  | [libaom](https://aomedia.googlesource.com/aom/) by the Alliance for Open Media | `src/codecs/av1/msac-enc.ts` (the symbol encoder), `src/codecs/av1/fdct.ts` (the forward Walsh-Hadamard transform), `src/codecs/av1/encode.ts` (the loop filter level from the quantizer), `src/codecs/avif-enc.ts` (the quantizer to qindex table) | BSD-2-Clause |
18
18
  | [libavif](https://github.com/AOMediaCodec/libavif) by Joe Drago | `src/codecs/avif.ts` (YUV to RGB conversion with bilinear chroma upsampling, alpha range expansion and unpremultiplication) | BSD-2-Clause |
19
- | [jxl-oxide](https://github.com/tirr-c/jxl-oxide) by Wonwoo Choi | `src/codecs/jxl/*` (the JPEG XL decoder: bit reader, header and frame header fields, entropy decoding, VarDCT, dequantization matrices, transforms, restoration filters, upsampling, the parsing of patches, splines and noise) | MIT (or Apache-2.0) |
19
+ | [jxl-oxide](https://github.com/tirr-c/jxl-oxide) by Wonwoo Choi | `src/codecs/jxl/*` (the JPEG XL decoder: bit reader, header and frame header fields, entropy decoding, VarDCT, dequantization matrices, transforms, restoration filters, upsampling, the parsing of patches, splines and noise, the ICC profile stream) | MIT (or Apache-2.0) |
20
20
  | [libjxl](https://github.com/libjxl/libjxl) by the JPEG XL Project Authors | `src/codecs/jxl/modular.ts` (Modular decoding: MA trees, predictors, the self-correcting predictor, transforms), `src/codecs/jxl/frame.ts` (the sections of frames, the order of the rendering stages, reference frames), `src/codecs/jxl/blend.ts`, `src/codecs/jxl/color.ts` (XYB to RGB), `src/codecs/jxl/features.ts` (rendering patches, splines and noise), `src/codecs/jxl/fast-lossless.ts` (the lossless encoder: palette detection, YCoCg, the gradient predictor, prefix codes, runs as LZ77, the headers), `src/codecs/jxl/patches-enc.ts` (finding text-like patches, packing them into a reference frame, quantizing it like Modular XYB, the patch dictionary) | BSD-3-Clause |
21
21
  | [JPEG XL conformance](https://github.com/libjxl/conformance) by the JPEG XL Project Authors | `tests/jxl/alpha-*.jxl`, `animation-spline.jxl`, `blendmodes.jxl`, `mul-no-extra-channels.jxl` (test files) | BSD-3-Clause |
22
22
  | [Various smartphones - Android, Blackberry, Windows Phone, and iOS.jpg](https://commons.wikimedia.org/wiki/File:Various_smartphones_-_Android,_Blackberry,_Windows_Phone,_and_iOS.jpg) by Carlos Varela | `tests/targets/external.png` and `external.jpg` (a square of it, scaled to 638x638), the test files made from them (`tests/avif`, `tests/jxl`, `tests/ico`, `tests/hdr`, `tests/qoi`, `tests/tiffs`) and the test targets showing them; `bench/inputs/photo.jpg` (unmodified) | [CC BY 2.0](https://creativecommons.org/licenses/by/2.0/) |
package/dist/animation.js CHANGED
@@ -218,16 +218,17 @@ export class Animation extends Array {
218
218
  }
219
219
  if (type === 'jxl') {
220
220
  const frames = [];
221
- let loopCount = -1;
221
+ let loopCount = -1, icc;
222
222
  for await (const decoded of jxl.frames(data, maxPixels, 'reinhard', threads)) {
223
223
  const frame = new Frame(decoded.width, decoded.height, decoded.duration, 0, 0, Frame.DISPOSAL_BACKGROUND);
224
224
  frame.bitmap = decoded.pixels;
225
225
  frames.push(frame.__orient__(decoded.orientation));
226
226
  loopCount = fromPlays(decoded.loopCount);
227
+ icc = decoded.icc;
227
228
  if (onlyExtractFirstFrame)
228
229
  break;
229
230
  }
230
- return new Animation(frames, frames.length > 1 ? loopCount : -1);
231
+ return new Animation(profile(frames, icc), frames.length > 1 ? loopCount : -1);
231
232
  }
232
233
  if (type)
233
234
  return new Animation([Frame.from(await Image.decode(data, { maxPixels, applyColorProfile }), 0)]);
@@ -540,7 +540,7 @@ async function decodeImage(d, it, items, idat, alphaItem, alphaOf, maxPixels, to
540
540
  else if (box.type === 'imir')
541
541
  pixels = mirror(pixels, width, height, d[box.start] & 1);
542
542
  }
543
- return { width, height, pixels, icc };
543
+ return { width, height, pixels, icc, cicp: icc ? undefined : [color.primaries, color.transfer] };
544
544
  }
545
545
  function iccOf(d, it) {
546
546
  for (const { box } of it.props) {
@@ -662,5 +662,5 @@ async function decodeSequence(d, moov, maxPixels, toneMapping) {
662
662
  return fromFrame(decodeAV1(data, 0, data.length, { maxPixels }));
663
663
  };
664
664
  const color = frame(colorTrack);
665
- return { width: color.width, height: color.height, pixels: await toRgba(color, alphaTrack ? frame(alphaTrack) : null, toneMapping) };
665
+ return { width: color.width, height: color.height, pixels: await toRgba(color, alphaTrack ? frame(alphaTrack) : null, toneMapping), cicp: [color.primaries, color.transfer] };
666
666
  }
@@ -184,13 +184,14 @@ export function imageHeader(r) {
184
184
  }
185
185
  return h;
186
186
  }
187
- export function skipICC(r) {
187
+ export function readICC(r) {
188
188
  const size = r.u64();
189
189
  if (size > 1 << 28)
190
190
  throw new Error('JPEG XL: ICC profile too large');
191
191
  const dec = new EntropyDecoder(r, 41);
192
192
  dec.begin(r);
193
193
  const kind = (b) => b >= 97 && b <= 122 || b >= 65 && b <= 90 ? 0 : b >= 48 && b <= 57 || b === 46 || b === 44 ? 1 : -1;
194
+ const out = new Uint8Array(size);
194
195
  let b1 = 0, b2 = 0;
195
196
  for (let i = 0; i < size; i++) {
196
197
  let ctx = 0;
@@ -203,10 +204,216 @@ export function skipICC(r) {
203
204
  const b = dec.read(r, ctx);
204
205
  if (b > 255)
205
206
  throw new Error('JPEG XL: invalid ICC profile');
207
+ out[i] = b;
206
208
  b2 = b1;
207
209
  b1 = b;
208
210
  }
209
211
  dec.finish();
212
+ return out;
213
+ }
214
+ const COMMON_TAGS = ['rTRC', 'rXYZ', 'cprt', 'wtpt', 'bkpt', 'rXYZ', 'gXYZ', 'bXYZ', 'kXYZ', 'rTRC', 'gTRC', 'bTRC', 'kTRC', 'chad', 'desc', 'chrm', 'dmnd', 'dmdd', 'lumi'];
215
+ const COMMON_DATA = ['XYZ ', 'desc', 'text', 'mluc', 'para', 'curv', 'sf32', 'gbd '];
216
+ export function decodeICC(stream) {
217
+ let at = 0;
218
+ const fail = () => {
219
+ throw new RangeError('invalid ICC stream');
220
+ };
221
+ const varint = (s, pos) => {
222
+ let value = 0;
223
+ for (let shift = 0; shift < 63; shift += 7) {
224
+ if (pos.at >= s.length)
225
+ fail();
226
+ const b = s[pos.at++];
227
+ value += (b & 127) * 2 ** shift;
228
+ if (!(b & 128))
229
+ break;
230
+ }
231
+ return value;
232
+ };
233
+ try {
234
+ const head = { at: 0 };
235
+ const outputSize = varint(stream, head), commandsSize = varint(stream, head);
236
+ at = head.at;
237
+ if (at + commandsSize > stream.length || outputSize > 1 << 28)
238
+ fail();
239
+ const commands = stream.subarray(at, at + commandsSize), cmd = { at: 0 };
240
+ let data = stream.subarray(at + commandsSize);
241
+ const headerSize = Math.min(outputSize, 128);
242
+ if (data.length < headerSize)
243
+ fail();
244
+ const out = new Uint8Array(outputSize);
245
+ let o = 0;
246
+ const push = (...bytes) => pushBytes(bytes);
247
+ const pushBytes = (bytes) => {
248
+ if (o + bytes.length > outputSize)
249
+ fail();
250
+ out.set(bytes, o);
251
+ o += bytes.length;
252
+ };
253
+ const pushText = (t) => pushBytes([...t].map(c => c.charCodeAt(0)));
254
+ const u32 = (v) => [v >>> 24 & 255, v >>> 16 & 255, v >>> 8 & 255, v & 255];
255
+ const take = (n) => {
256
+ if (n > data.length)
257
+ fail();
258
+ const bytes = data.subarray(0, n);
259
+ data = data.subarray(n);
260
+ return bytes;
261
+ };
262
+ const header = take(headerSize);
263
+ const predict = (i) => {
264
+ const h40 = String.fromCharCode(header[40]), h41 = String.fromCharCode(header[41]);
265
+ if (i <= 3)
266
+ return u32(outputSize)[i];
267
+ if (i === 8)
268
+ return 4;
269
+ if (i >= 12 && i <= 23)
270
+ return 'mntrRGB XYZ '.charCodeAt(i - 12);
271
+ if (i >= 36 && i <= 39)
272
+ return 'acsp'.charCodeAt(i - 36);
273
+ if (h40 === 'A' && i >= 41 && i <= 43)
274
+ return 'PPL'.charCodeAt(i - 41);
275
+ if (h40 === 'M' && i >= 41 && i <= 43)
276
+ return 'SFT'.charCodeAt(i - 41);
277
+ if (h40 === 'S' && h41 === 'G' && (i === 42 || i === 43))
278
+ return 'I '.charCodeAt(i - 42);
279
+ if (h40 === 'S' && h41 === 'U' && (i === 42 || i === 43))
280
+ return 'NW'.charCodeAt(i - 42);
281
+ if (i === 70)
282
+ return 246;
283
+ if (i === 71)
284
+ return 214;
285
+ if (i === 73)
286
+ return 1;
287
+ if (i === 78)
288
+ return 211;
289
+ if (i === 79)
290
+ return 45;
291
+ if (i >= 80 && i <= 83)
292
+ return header[4 + i - 80];
293
+ return 0;
294
+ };
295
+ for (let i = 0; i < headerSize; i++)
296
+ push(predict(i) + header[i] & 255);
297
+ if (outputSize <= 128)
298
+ return out;
299
+ const v = varint(commands, cmd);
300
+ if (v > 0) {
301
+ const numTags = v - 1;
302
+ if ((outputSize - 128) / 12 < numTags)
303
+ fail();
304
+ push(...u32(numTags));
305
+ let prevStart = numTags * 12 + 128, prevSize = 0;
306
+ for (;;) {
307
+ if (cmd.at >= commands.length)
308
+ return out.subarray(0, o);
309
+ const command = commands[cmd.at++], code = command & 63;
310
+ if (code === 0)
311
+ break;
312
+ let tag;
313
+ if (code === 1)
314
+ tag = String.fromCharCode(...take(4));
315
+ else if (code <= 20)
316
+ tag = COMMON_TAGS[code - 2];
317
+ else
318
+ return fail();
319
+ const start = command & 64 ? varint(commands, cmd) : prevStart + prevSize;
320
+ const size = command & 128 ? varint(commands, cmd) : ['rXYZ', 'gXYZ', 'bXYZ', 'kXYZ', 'wtpt', 'bkpt', 'lumi'].includes(tag) ? 20 : prevSize;
321
+ if (start + size > outputSize)
322
+ fail();
323
+ prevStart = start;
324
+ prevSize = size;
325
+ pushText(tag);
326
+ push(...u32(start), ...u32(size));
327
+ if (code === 2) {
328
+ pushText('gTRC');
329
+ push(...u32(start), ...u32(size));
330
+ pushText('bTRC');
331
+ push(...u32(start), ...u32(size));
332
+ }
333
+ else if (code === 3) {
334
+ pushText('gXYZ');
335
+ push(...u32(start + size), ...u32(size));
336
+ pushText('bXYZ');
337
+ push(...u32(start + 2 * size), ...u32(size));
338
+ }
339
+ }
340
+ }
341
+ const shuffle = (bytes, width) => {
342
+ const n = bytes.length, shuffled = new Uint8Array(n);
343
+ if (width === 2) {
344
+ const half = n >> 1, odd = n & 1;
345
+ let k = 0;
346
+ for (let i = 0; i < half; i++) {
347
+ shuffled[k++] = bytes[i];
348
+ shuffled[k++] = bytes[i + half + odd];
349
+ }
350
+ if (odd)
351
+ shuffled[k] = bytes[half];
352
+ }
353
+ else {
354
+ const step = n >> 2, wide = n & 3;
355
+ let k = 0;
356
+ for (let i = 0; i < step; i++) {
357
+ let base = i;
358
+ for (let j = 0; j < wide; j++, base += step + 1)
359
+ shuffled[k++] = bytes[base];
360
+ for (let j = wide; j < 4; j++, base += step)
361
+ shuffled[k++] = bytes[base];
362
+ }
363
+ for (let i = 1; i <= wide; i++)
364
+ shuffled[k++] = bytes[(step + 1) * i - 1];
365
+ }
366
+ return shuffled;
367
+ };
368
+ while (cmd.at < commands.length) {
369
+ const command = commands[cmd.at++];
370
+ if (command === 1)
371
+ pushBytes(take(varint(commands, cmd)));
372
+ else if (command === 2 || command === 3)
373
+ pushBytes(shuffle(take(varint(commands, cmd)), command === 2 ? 2 : 4));
374
+ else if (command === 4) {
375
+ if (cmd.at >= commands.length)
376
+ fail();
377
+ const flags = commands[cmd.at++], width = (flags & 3) + 1, order = flags >> 2 & 3;
378
+ if (width === 3 || order === 3)
379
+ fail();
380
+ const stride = flags & 16 ? varint(commands, cmd) : width;
381
+ if (stride < width || stride * 4 >= o)
382
+ fail();
383
+ const num = varint(commands, cmd), raw = take(num), bytes = width === 1 ? raw : shuffle(raw, width);
384
+ for (let i = 0; i < num; i += width) {
385
+ const prev = [0, 0, 0];
386
+ for (let j = 0; j <= order; j++) {
387
+ const from = o - stride * (j + 1);
388
+ let value = 0;
389
+ for (let k = 0; k < width; k++)
390
+ value = (value << 8 | out[from + k]) >>> 0;
391
+ prev[j] = value;
392
+ }
393
+ const p = order === 0 ? prev[0] : order === 1 ? 2 * prev[0] - prev[1] >>> 0 : 3 * (prev[0] - prev[1]) + prev[2] >>> 0;
394
+ for (let j = 0; j < Math.min(width, num - i); j++)
395
+ push(bytes[i + j] + (p >>> 8 * (width - 1 - j)) & 255);
396
+ }
397
+ }
398
+ else if (command === 10) {
399
+ pushText('XYZ ');
400
+ push(0, 0, 0, 0);
401
+ pushBytes(take(12));
402
+ }
403
+ else if (command >= 16 && command <= 23) {
404
+ pushText(COMMON_DATA[command - 16]);
405
+ push(0, 0, 0, 0);
406
+ }
407
+ else
408
+ fail();
409
+ }
410
+ return o === outputSize ? out : null;
411
+ }
412
+ catch (e) {
413
+ if (e instanceof RangeError)
414
+ return null;
415
+ throw e;
416
+ }
210
417
  }
211
418
  const UP2 = [
212
419
  -0.01716200, -0.03452303, -0.04022174, -0.02921014, -0.00624645, 0.14111091, 0.28896755, 0.00278718, -0.01610267,
@@ -1,7 +1,7 @@
1
1
  import { startThreads } from "../util/threads.js";
2
2
  import { MAX_PIXELS, checkPixels } from "../util/limits.js";
3
3
  import { BitReader } from "./jxl/bits.js";
4
- import { imageHeader, skipICC } from "./jxl/headers.js";
4
+ import { decodeICC, imageHeader, readICC } from "./jxl/headers.js";
5
5
  import { frameHeader, toc } from "./jxl/frame-header.js";
6
6
  import { decodeFrame } from "./jxl/frame.js";
7
7
  import { ColorOutput } from "./jxl/color.js";
@@ -64,8 +64,8 @@ export async function* frames(data, maxPixels = MAX_PIXELS, toneMapping = 'reinh
64
64
  const r = new BitReader(d);
65
65
  const image = imageHeader(r);
66
66
  checkPixels(image.width, image.height, maxPixels);
67
- if (image.colour.wantICC)
68
- skipICC(r);
67
+ const stream = image.colour.wantICC ? readICC(r) : null;
68
+ const icc = stream && !image.xybEncoded ? decodeICC(stream) ?? undefined : undefined;
69
69
  r.zeroPadToByte();
70
70
  let at = r.bytePosition;
71
71
  if (image.preview) {
@@ -94,7 +94,7 @@ export async function* frames(data, maxPixels = MAX_PIXELS, toneMapping = 'reinh
94
94
  shown++;
95
95
  yield {
96
96
  width: image.width, height: image.height, pixels: state.output.toRGBA(frame.canvas), duration: frame.header.duration * tick,
97
- orientation: image.orientation, loopCount: a ? a.numLoops : 1
97
+ orientation: image.orientation, loopCount: a ? a.numLoops : 1, icc
98
98
  };
99
99
  }
100
100
  if (frame.header.isLast)
package/dist/image.d.ts CHANGED
@@ -148,11 +148,11 @@ export interface DecodeOptions {
148
148
  /** Whether to rotate/mirror JPEGs, TIFFs, PNGs and WebPs as their orientation tag (Exif or XMP) says. Default: `true` */
149
149
  applyOrientation?: boolean;
150
150
  /**
151
- * Whether to convert the colors of images with an embedded ICC profile (PNG, JPEG, WebP, AVIF, TIFF) to sRGB, like
152
- * browsers show them: wide gamut photos (Display P3 from phones, Adobe RGB, ProPhoto) look as intended instead of
153
- * washed out. Matrix/TRC profiles (RGB and gray) are applied, relative colorimetric (colors outside sRGB are
154
- * clipped); profiles with only lookup tables, CMYK ones and ones that are sRGB anyway leave the pixels as they are.
155
- * Default: `true`
151
+ * Whether to convert the colors of images with an embedded ICC profile (PNG, JPEG, WebP, AVIF, JPEG XL, TIFF), and
152
+ * of AVIFs with other color primaries than sRGB's (Display P3, BT.2020), to sRGB, like browsers show them: wide
153
+ * gamut photos (Display P3 from phones, Adobe RGB, ProPhoto) look as intended instead of washed out. Matrix/TRC
154
+ * profiles (RGB and gray) are applied, relative colorimetric (colors outside sRGB are clipped); profiles with only
155
+ * lookup tables, CMYK ones and ones that are sRGB anyway leave the pixels as they are. Default: `true`
156
156
  */
157
157
  applyColorProfile?: boolean;
158
158
  /**
@@ -238,6 +238,15 @@ export interface TextStyle {
238
238
  * `kern`), a number picks an alternate (`salt: 2`). Fonts without a feature ignore it. Default: `{}`
239
239
  */
240
240
  features?: Record<string, boolean | number>;
241
+ /**
242
+ * The instance of variable fonts, by their axes: `weight` (1-1000, like CSS's `font-weight`: 400 regular, 700
243
+ * bold), `width` (percent of the normal width: 75 condensed, 125 expanded), `slant` (degrees, negative leans
244
+ * right), `italic` (`true`/`false`), `opticalSize` (the size the glyphs are designed for, in pixels; default: the
245
+ * font size, like browsers' `font-optical-sizing: auto`), and other axes by their 4-character tag (like Roboto
246
+ * Flex's `GRAD: 50`). Values outside an axis's range are clamped, axes a font doesn't have are ignored, fonts
247
+ * without axes aren't affected. Default: `{}` (the fonts' default instances)
248
+ */
249
+ variations?: Record<string, number | boolean>;
241
250
  }
242
251
  /** Options of {@link Image.cropCircle} */
243
252
  export interface CropCircleOptions {
package/dist/image.js CHANGED
@@ -22,7 +22,7 @@ import * as quantize from "./codecs/quantize.js";
22
22
  import * as textRenderer from "./render/text.js";
23
23
  import * as svgRenderer from "./render/svg.js";
24
24
  import { view } from "./util/mem.js";
25
- import { profileTransform } from "./util/icc.js";
25
+ import { cicpTransform, profileTransform } from "./util/icc.js";
26
26
  import { ImageType } from "./image-type.js";
27
27
  import { TextLayout } from "./text-layout.js";
28
28
  import { resolveMetadata, pngText, exifData } from "./metadata.js";
@@ -1114,8 +1114,8 @@ export class Image {
1114
1114
  return tga.decode(data, maxPixels);
1115
1115
  throw new Error('Unsupported image type');
1116
1116
  });
1117
- if (applyColorProfile && decoded.icc)
1118
- profileTransform(decoded.icc)?.(decoded.pixels);
1117
+ if (applyColorProfile)
1118
+ (decoded.icc ? profileTransform(decoded.icc) : decoded.cicp ? cicpTransform(...decoded.cicp) : null)?.(decoded.pixels);
1119
1119
  const image = new Image(decoded.width, decoded.height);
1120
1120
  image.bitmap = decoded.pixels;
1121
1121
  return applyOrientation && decoded.orientation ? image.__orient__(decoded.orientation) : image;
@@ -1208,7 +1208,8 @@ export class Image {
1208
1208
  }
1209
1209
  static async renderText(font, size, text, colorOrOptions = 0xffffffff, layoutArgument, styleArgument = {}) {
1210
1210
  const options = isOptions(colorOrOptions) ? colorOrOptions : { ...styleArgument, color: colorOrOptions, layout: layoutArgument };
1211
- const { color = 0xffffffff, layout = new TextLayout(), strokeWidth = 0, strokeColor = 0x000000ff, hinting = true, features = {} } = options;
1211
+ const { color = 0xffffffff, layout = new TextLayout(), strokeWidth = 0, strokeColor = 0x000000ff, hinting = true, features = {}, variations = {} } = options;
1212
+ const axes = textRenderer.axisValues(variations);
1212
1213
  size = finite(size, 'font size');
1213
1214
  if (finite(strokeWidth, 'stroke width') < 0)
1214
1215
  throw new RangeError('Invalid stroke width');
@@ -1216,7 +1217,7 @@ export class Image {
1216
1217
  if (!fonts.length)
1217
1218
  throw new RangeError('No font given');
1218
1219
  const [r, g, b, a] = Image.colorToRGBA(color);
1219
- const rendered = await textRenderer.render(fonts.map(view), size, text, layout, hinting, (r << 24 | g << 16 | b << 8 | 255) >>> 0, featureList(features));
1220
+ const rendered = await textRenderer.render(fonts.map(view), size, text, layout, hinting, (r << 24 | g << 16 | b << 8 | 255) >>> 0, featureList(features), axes);
1220
1221
  const pad = Math.ceil(strokeWidth);
1221
1222
  const width = rendered.width + 2 * pad, height = rendered.height + 2 * pad;
1222
1223
  const coverage = new Uint8Array(width * height);
@@ -1,3 +1,4 @@
1
+ import { Gvar, ItemVariationStore, cvarDeltas, deltaSetIndexMap, normalize, parseAvar, parseFvar } from "./variations.js";
1
2
  const MAX_COMMANDS = 100000;
2
3
  export class Font {
3
4
  data;
@@ -16,6 +17,10 @@ export class Font {
16
17
  outlineCache;
17
18
  kernTable;
18
19
  variation;
20
+ axes;
21
+ coords = [];
22
+ variationTables = null;
23
+ instances = null;
19
24
  constructor(data) {
20
25
  this.data = data;
21
26
  this.view = new DataView(data.buffer, data.byteOffset, data.byteLength);
@@ -63,6 +68,62 @@ export class Font {
63
68
  this.outlineCache = new Map();
64
69
  this.kernTable = this.tables.kern && parseKern(this, this.tables.kern.offset) || null;
65
70
  this.variation = parseVariations(this, this.tables.cmap.offset);
71
+ this.axes = this.tables.fvar ? parseFvar(this, this.tables.fvar.offset) : [];
72
+ }
73
+ get vary() {
74
+ if (this.variationTables)
75
+ return this.variationTables;
76
+ const t = this.tables, at = (tag) => t[tag].offset;
77
+ const hvar = t.HVAR ? (() => {
78
+ const o = at('HVAR'), map = this.u32(o + 8);
79
+ return { store: new ItemVariationStore(this, o + this.u32(o + 4)), advances: map ? deltaSetIndexMap(this, o + map) : null };
80
+ })() : null;
81
+ const mvar = t.MVAR && this.u16(at('MVAR') + 10) ? (() => {
82
+ const o = at('MVAR'), size = this.u16(o + 6), count = this.u16(o + 8), records = new Map();
83
+ for (let i = 0; i < count; i++) {
84
+ const r = o + 12 + i * size;
85
+ records.set(String.fromCharCode(...this.data.subarray(r, r + 4)), [this.u16(r + 4), this.u16(r + 6)]);
86
+ }
87
+ return { store: new ItemVariationStore(this, o + this.u16(o + 10)), records };
88
+ })() : null;
89
+ const gdef = t.GDEF && this.u16(at('GDEF') + 2) >= 3 && this.u32(at('GDEF') + 14) ? new ItemVariationStore(this, at('GDEF') + this.u32(at('GDEF') + 14)) : null;
90
+ const base = Object.getPrototypeOf(this) instanceof Font ? Object.getPrototypeOf(this) : this;
91
+ base.variationTables = {
92
+ avar: t.avar ? parseAvar(this, at('avar'), this.axes.length) : null,
93
+ gvar: t.gvar && this.outlines === 'glyf' ? new Gvar(this, at('gvar')) : null,
94
+ hvar, mvar, gdef,
95
+ };
96
+ return base.variationTables;
97
+ }
98
+ withVariations(values) {
99
+ if (!this.axes.length)
100
+ return this;
101
+ const coords = normalize(this.axes, this.vary.avar, values);
102
+ if (coords.every(c => c === 0))
103
+ return Object.getPrototypeOf(this) instanceof Font ? Object.getPrototypeOf(this) : this;
104
+ const base = Object.getPrototypeOf(this) instanceof Font ? Object.getPrototypeOf(this) : this;
105
+ const key = coords.join(',');
106
+ const cached = base.instances?.get(key);
107
+ if (cached)
108
+ return cached;
109
+ const instance = Object.create(base);
110
+ (base.instances ??= new Map()).set(key, instance);
111
+ instance.coords = coords;
112
+ instance.outlineCache = new Map();
113
+ const metric = (tag, value) => {
114
+ const item = this.vary.mvar?.records.get(tag);
115
+ return item ? value + this.vary.mvar.store.delta(coords, item[0], item[1]) : value;
116
+ };
117
+ instance.ascender = metric('hasc', base.ascender);
118
+ instance.descender = metric('hdsc', base.descender);
119
+ instance.lineGap = metric('hlgn', base.lineGap);
120
+ return instance;
121
+ }
122
+ variationDelta(outer, inner) {
123
+ return this.coords.length && this.vary.gdef ? this.vary.gdef.delta(this.coords, outer, inner) : 0;
124
+ }
125
+ cvtDeltas(count) {
126
+ return this.coords.length && this.tables.cvar ? cvarDeltas(this, this.tables.cvar.offset, this.axes.length, this.coords, count) : null;
66
127
  }
67
128
  u8(o) { return this.data[o]; }
68
129
  i8(o) { return this.view.getInt8(o); }
@@ -76,14 +137,45 @@ export class Font {
76
137
  advance(glyph) {
77
138
  const hmtx = this.tables.hmtx.offset;
78
139
  const index = Math.min(glyph, this.numberOfHMetrics - 1);
79
- return this.u16(hmtx + index * 4);
140
+ const advance = this.u16(hmtx + index * 4);
141
+ if (!this.coords.length)
142
+ return advance;
143
+ const hvar = this.vary.hvar;
144
+ if (hvar) {
145
+ const [outer, inner] = hvar.advances ? hvar.advances(glyph) : [0, glyph];
146
+ return advance + hvar.store.delta(this.coords, outer, inner);
147
+ }
148
+ const phantom = this.phantomDeltas(glyph);
149
+ return phantom ? advance + phantom[2] - phantom[0] : advance;
150
+ }
151
+ phantomDeltas(glyph) {
152
+ const varied = this.varied(glyph);
153
+ return varied && varied.deltas && varied.deltas.subarray(2 * varied.count);
154
+ }
155
+ varied(glyph) {
156
+ if (this.outlines !== 'glyf' || glyph >= this.numGlyphs)
157
+ return null;
158
+ const offset = this.glyfOffset(glyph);
159
+ const gvar = this.coords.length ? this.vary.gvar : null;
160
+ if (offset < 0)
161
+ return { count: 0, deltas: gvar ? gvar.deltas(glyph, this.coords, 4, null, [], []) : null, simple: null };
162
+ const contours = this.i16(offset);
163
+ if (contours < 0) {
164
+ const count = this.components(offset).components.length;
165
+ return { count, deltas: gvar ? gvar.deltas(glyph, this.coords, count + 4, null, [], []) : null, simple: null };
166
+ }
167
+ const simple = this.simplePoints(offset, contours);
168
+ if (!simple)
169
+ return null;
170
+ const count = simple.xs.length;
171
+ return { count, deltas: gvar ? gvar.deltas(glyph, this.coords, count + 4, simple.ends, simple.xs, simple.ys) : null, simple };
80
172
  }
81
173
  variationGlyph(codepoint, selector) {
82
174
  const glyph = this.variation ? this.variation(codepoint, selector) : 0;
83
175
  return glyph < 0 ? this.glyphIndex(codepoint) : glyph;
84
176
  }
85
177
  extents(glyph) {
86
- if (this.outlines === 'glyf' && glyph < this.numGlyphs) {
178
+ if (this.outlines === 'glyf' && glyph < this.numGlyphs && !this.coords.length) {
87
179
  const o = this.glyfOffset(glyph);
88
180
  if (o < 0)
89
181
  return { xMin: 0, yMin: 0, xMax: 0, yMax: 0 };
@@ -114,13 +206,16 @@ export class Font {
114
206
  return null;
115
207
  const contourCount = this.i16(offset);
116
208
  const xMin = this.i16(offset + 2);
209
+ const varied = this.coords.length ? this.varied(glyph) : null, d = varied?.deltas;
210
+ const at = (i, axis) => d ? Math.round(d[2 * i + axis]) : 0;
211
+ const origin = d && varied ? at(varied.count, 0) : 0;
117
212
  if (contourCount < 0) {
118
213
  const { components, end } = this.components(offset);
119
214
  const instructions = components[components.length - 1].flags & 0x100 ? this.data.subarray(end + 2, end + 2 + this.u16(end)) : new Uint8Array(0);
120
215
  return {
121
- xs: [], ys: [], on: [], ends: [], instructions, xMin,
122
- components: components.map(({ glyph, flags, arg1, arg2, matrix }) => ({
123
- glyph, dx: flags & 2 ? arg1 : 0, dy: flags & 2 ? arg2 : 0, matrix,
216
+ xs: [], ys: [], on: [], ends: [], instructions, xMin: xMin + origin,
217
+ components: components.map(({ glyph, flags, arg1, arg2, matrix }, i) => ({
218
+ glyph, dx: flags & 2 ? arg1 + at(i, 0) : 0, dy: flags & 2 ? arg2 + at(i, 1) : 0, matrix,
124
219
  round: (flags & 4) !== 0, match: flags & 2 ? null : [arg1, arg2], useMetrics: (flags & 0x200) !== 0,
125
220
  })),
126
221
  };
@@ -129,7 +224,10 @@ export class Font {
129
224
  if (!points)
130
225
  return null;
131
226
  const { xs, ys, flags, ends, instructions } = points;
132
- return { xs: Array.from(xs), ys: Array.from(ys), on: Array.from(flags, f => (f & 1) === 1), ends, instructions, xMin, components: null };
227
+ return {
228
+ xs: Array.from(xs, (x, i) => x + at(i, 0)), ys: Array.from(ys, (y, i) => y + at(i, 1)), on: Array.from(flags, f => (f & 1) === 1), ends,
229
+ instructions, xMin: xMin + origin, components: null,
230
+ };
133
231
  }
134
232
  glyfOffset(glyph) {
135
233
  const loca = this.tables.loca.offset;
@@ -231,31 +329,38 @@ export class Font {
231
329
  return [];
232
330
  const contours = this.i16(offset);
233
331
  if (contours >= 0) {
234
- const path = this.simpleGlyph(offset, contours);
332
+ const path = this.simpleGlyph(offset, contours, glyph);
235
333
  expanding.budget -= path.length;
236
334
  return expanding.budget >= 0 ? path : [];
237
335
  }
238
336
  expanding.expanding.add(glyph);
239
- const path = this.compositeGlyph(offset, expanding);
337
+ const path = this.compositeGlyph(offset, expanding, glyph);
240
338
  expanding.expanding.delete(glyph);
241
339
  return path;
242
340
  }
243
- simpleGlyph(offset, contourCount) {
341
+ simpleGlyph(offset, contourCount, glyph) {
244
342
  const points = this.simplePoints(offset, contourCount);
245
343
  if (!points)
246
344
  return [];
345
+ let xs = points.xs, ys = points.ys;
346
+ const d = this.coords.length ? this.varied(glyph)?.deltas : null;
347
+ if (d) {
348
+ xs = Float64Array.from(points.xs, (x, i) => x + d[2 * i]);
349
+ ys = Float64Array.from(points.ys, (y, i) => y + d[2 * i + 1]);
350
+ }
247
351
  const path = [];
248
352
  let first = 0;
249
353
  for (const last of points.ends) {
250
- contourToPath(path, points.xs, points.ys, points.flags, first, last);
354
+ contourToPath(path, xs, ys, points.flags, first, last);
251
355
  first = last + 1;
252
356
  }
253
357
  return path;
254
358
  }
255
- compositeGlyph(offset, expanding) {
359
+ compositeGlyph(offset, expanding, composite) {
256
360
  const path = [];
257
- for (const { glyph, flags, arg1, arg2, matrix: [a, b, c, d] } of this.components(offset).components) {
258
- const dx = flags & 2 ? arg1 : 0, dy = flags & 2 ? arg2 : 0;
361
+ const deltas = this.coords.length ? this.varied(composite)?.deltas : null;
362
+ for (const [k, { glyph, flags, arg1, arg2, matrix: [a, b, c, d] }] of this.components(offset).components.entries()) {
363
+ const dx = flags & 2 ? arg1 + (deltas ? deltas[2 * k] : 0) : 0, dy = flags & 2 ? arg2 + (deltas ? deltas[2 * k + 1] : 0) : 0;
259
364
  for (const command of this.glyfOutline(glyph, expanding)) {
260
365
  const transformed = [command[0]];
261
366
  for (let i = 1; i < command.length; i += 2) {
@@ -111,6 +111,10 @@ export class Hinter {
111
111
  this.cvt = new Int16Array(cvt.length >> 1);
112
112
  for (let i = 0; i < this.cvt.length; i++)
113
113
  this.cvt[i] = font.i16(font.tables['cvt '].offset + i * 2);
114
+ const deltas = font.cvtDeltas(this.cvt.length);
115
+ if (deltas)
116
+ for (let i = 0; i < this.cvt.length; i++)
117
+ this.cvt[i] = Math.round(this.cvt[i] + deltas[i]);
114
118
  const maxp = font.tables.maxp.offset;
115
119
  const version = font.u32(maxp);
116
120
  this.maxTwilight = version >= 0x10000 ? font.u16(maxp + 16) : 0;
@@ -496,8 +496,10 @@ export class LayoutTable {
496
496
  const condition = set + f.u32(set + 2 + j * 4);
497
497
  if (f.u16(condition) !== 1)
498
498
  matches = false;
499
- else
500
- matches = f.i16(condition + 4) <= 0 && 0 <= f.i16(condition + 6);
499
+ else {
500
+ const v = f.coords[f.u16(condition + 2)] ?? 0;
501
+ matches = f.i16(condition + 4) / 16384 <= v && v <= f.i16(condition + 6) / 16384;
502
+ }
501
503
  }
502
504
  }
503
505
  if (!matches)
@@ -886,7 +888,7 @@ export class LayoutTable {
886
888
  return { coverage: has, apply: c => {
887
889
  if (coverage(c.buffer.cur().codepoint) < 0)
888
890
  return false;
889
- applyValue(f, valueFormat, offset + 6, c.buffer.cur());
891
+ applyValue(f, valueFormat, offset + 6, c.buffer.cur(), offset);
890
892
  c.buffer.idx++;
891
893
  return true;
892
894
  } };
@@ -896,7 +898,7 @@ export class LayoutTable {
896
898
  const index = coverage(c.buffer.cur().codepoint);
897
899
  if (index < 0 || index >= f.u16(offset + 6))
898
900
  return false;
899
- applyValue(f, valueFormat, offset + 8 + index * size, c.buffer.cur());
901
+ applyValue(f, valueFormat, offset + 8 + index * size, c.buffer.cur(), offset);
900
902
  c.buffer.idx++;
901
903
  return true;
902
904
  } };
@@ -934,9 +936,9 @@ export class LayoutTable {
934
936
  if (record < 0)
935
937
  return false;
936
938
  if (len1)
937
- applyValue(f, format1, record + 2, buffer.cur());
939
+ applyValue(f, format1, record + 2, buffer.cur(), offset);
938
940
  if (len2)
939
- applyValue(f, format2, record + 2 + len1, buffer.info[pos]);
941
+ applyValue(f, format2, record + 2 + len1, buffer.info[pos], offset);
940
942
  buffer.idx = len2 ? pos + 1 : pos;
941
943
  return true;
942
944
  } };
@@ -960,9 +962,9 @@ export class LayoutTable {
960
962
  return false;
961
963
  const v = records + (k1 * class2Count + k2) * (len1 + len2);
962
964
  if (len1)
963
- applyValue(f, format1, v, buffer.cur());
965
+ applyValue(f, format1, v, buffer.cur(), offset);
964
966
  if (len2)
965
- applyValue(f, format2, v + len1, buffer.info[pos]);
967
+ applyValue(f, format2, v + len1, buffer.info[pos], offset);
966
968
  buffer.idx = len2 ? pos + 1 : pos;
967
969
  return true;
968
970
  } };
@@ -1156,20 +1158,40 @@ const valueSize = (format) => {
1156
1158
  n += v & 1;
1157
1159
  return n * 2;
1158
1160
  };
1159
- function applyValue(f, format, offset, info) {
1160
- if (format & 1) {
1161
- info.xOffset += f.i16(offset);
1162
- offset += 2;
1163
- }
1164
- if (format & 2) {
1165
- info.yOffset += f.i16(offset);
1166
- offset += 2;
1167
- }
1168
- if (format & 4)
1169
- info.xAdvance += f.i16(offset);
1161
+ function deviceDelta(f, device) {
1162
+ if (!f.coords.length || f.u16(device + 4) !== 0x8000)
1163
+ return 0;
1164
+ return f.variationDelta(f.u16(device), f.u16(device + 2));
1165
+ }
1166
+ function applyValue(f, format, offset, info, base) {
1167
+ const fields = [0, 0, 0, 0];
1168
+ for (let k = 0; k < 4; k++)
1169
+ if (format & 1 << k) {
1170
+ fields[k] = f.i16(offset);
1171
+ offset += 2;
1172
+ }
1173
+ if (format & 0xf0 && f.coords.length)
1174
+ for (let k = 0; k < 4; k++)
1175
+ if (format & 0x10 << k) {
1176
+ const device = f.u16(offset);
1177
+ offset += 2;
1178
+ if (device)
1179
+ fields[k] += deviceDelta(f, base + device);
1180
+ }
1181
+ info.xOffset += fields[0];
1182
+ info.yOffset += fields[1];
1183
+ info.xAdvance += fields[2];
1170
1184
  }
1171
1185
  function anchor(f, offset) {
1172
- return [f.i16(offset + 2), f.i16(offset + 4)];
1186
+ let x = f.i16(offset + 2), y = f.i16(offset + 4);
1187
+ if (f.u16(offset) === 3 && f.coords.length) {
1188
+ const dx = f.u16(offset + 6), dy = f.u16(offset + 8);
1189
+ if (dx)
1190
+ x += deviceDelta(f, offset + dx);
1191
+ if (dy)
1192
+ y += deviceDelta(f, offset + dy);
1193
+ }
1194
+ return [x, y];
1173
1195
  }
1174
1196
  function markAttach(f, c, markArray, markIndex, anchors, row, classCount, glyphPos) {
1175
1197
  const buffer = c.buffer, info = buffer.info;
@@ -83,8 +83,18 @@ export function fontFace(data, descriptors) {
83
83
  generic.add('serif');
84
84
  else if ((familyType === 2 && serifStyle >= 11 && serifStyle <= 15) || familyClass === 8)
85
85
  generic.add('sans-serif');
86
+ const axis = (tag) => font.axes.find(a => a.tag === tag);
87
+ const wght = axis('wght'), wdth = axis('wdth'), ital = axis('ital'), slnt = axis('slnt');
88
+ const classes = (min, max) => {
89
+ const lo = STRETCH_PERCENT.findIndex(p => p >= min), hi = STRETCH_PERCENT.filter(p => p <= max).length - 1;
90
+ return lo >= 0 && hi >= lo ? [lo + 1, hi + 1] : null;
91
+ };
92
+ const ranges = font.axes.length ? {
93
+ weight: wght ? [wght.min, wght.max] : null, stretch: wdth ? classes(wdth.min, wdth.max) : null,
94
+ italic: !!ital && ital.max >= 1, oblique: !!slnt && slnt.min < 0,
95
+ } : null;
86
96
  const face = {
87
- font, families: families.map(name => name.toLowerCase()), weight, style, stretch, generic,
97
+ font, families: families.map(name => name.toLowerCase()), weight, style, stretch, ranges, generic,
88
98
  ascent, descent, xHeight,
89
99
  underlinePosition: post >= 0 ? font.i16(post + 8) : -Math.trunc(units / 9),
90
100
  underlineThickness,
@@ -96,8 +106,15 @@ export function fontFace(data, descriptors) {
96
106
  faces.set(font, face);
97
107
  return face;
98
108
  }
109
+ const STRETCH_PERCENT = [50, 62.5, 75, 87.5, 100, 112.5, 125, 150, 200];
99
110
  const GENERIC = new Set(['serif', 'sans-serif', 'monospace', 'cursive', 'fantasy']);
100
- function bestMatch(candidates, query) {
111
+ function bestMatch(faces, query) {
112
+ const clamp = (v, range, own) => range ? Math.min(Math.max(v, range[0]), range[1]) : own;
113
+ const candidates = faces.map(f => !f.ranges ? f : {
114
+ ...f, face: f, weight: clamp(query.weight, f.ranges.weight, f.weight), stretch: clamp(query.stretch, f.ranges.stretch, f.stretch),
115
+ style: query.style === 'italic' && f.ranges.italic ? 'italic' : query.style === 'oblique' && f.ranges.oblique ? 'oblique' : f.style,
116
+ });
117
+ const original = (f) => f.face ?? f;
101
118
  const pick = (values, wanted, below) => {
102
119
  if (values.includes(wanted))
103
120
  return wanted;
@@ -119,7 +136,32 @@ function bestMatch(candidates, query) {
119
136
  }
120
137
  else
121
138
  weight = pick(weights, w, w < 400);
122
- return list.find(f => f.weight === weight);
139
+ return original(list.find(f => f.weight === weight));
140
+ }
141
+ const variedFaces = new WeakMap();
142
+ export function variedFace(face, query, fontSize) {
143
+ if (!face.font.axes.length)
144
+ return face;
145
+ const values = { wght: query.weight };
146
+ if (query.stretch !== 5)
147
+ values.wdth = STRETCH_PERCENT[query.stretch - 1];
148
+ if (query.style === 'italic')
149
+ values.ital = 1;
150
+ if (query.style === 'oblique')
151
+ values.slnt = -12;
152
+ if (query.opticalSizing)
153
+ values.opsz = fontSize;
154
+ const font = face.font.withVariations({ ...values, ...query.variations });
155
+ if (font === face.font)
156
+ return face;
157
+ let byCoords = variedFaces.get(face);
158
+ if (!byCoords)
159
+ variedFaces.set(face, byCoords = new Map());
160
+ const key = font.coords.join(',');
161
+ let varied = byCoords.get(key);
162
+ if (!varied)
163
+ byCoords.set(key, varied = { ...face, font, ascent: face.ascent + font.ascender - face.font.ascender, descent: face.descent + font.descender - face.font.descender });
164
+ return varied;
123
165
  }
124
166
  export function matchFont(fonts, query) {
125
167
  if (!fonts.length)
@@ -197,6 +239,17 @@ function colorKind(face, glyph, fontSize) {
197
239
  return 'bitmap';
198
240
  return null;
199
241
  }
242
+ export function parseVariationSettings(value) {
243
+ const out = {};
244
+ if (value.trim().toLowerCase() === 'normal')
245
+ return out;
246
+ for (const part of value.split(',')) {
247
+ const m = /^\s*(["'])(.{4})\1\s+([-+]?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?)\s*$/i.exec(part);
248
+ if (m)
249
+ out[m[2]] = Number(m[3]);
250
+ }
251
+ return out;
252
+ }
200
253
  export function parseFontFamilies(value) {
201
254
  const families = [];
202
255
  for (const part of value.split(',')) {
@@ -247,8 +300,10 @@ function shapeChunk(chunk, fonts, primary) {
247
300
  if (base) {
248
301
  const grapheme = cps.slice(start, end);
249
302
  let face = base;
250
- if (!grapheme.every(c => isDefaultIgnorableCodepoint(c) || base.font.glyphIndex(c)))
251
- face = fallbackFont(fonts, base, grapheme, new Set([base])) ?? base;
303
+ if (!grapheme.every(c => isDefaultIgnorableCodepoint(c) || base.font.glyphIndex(c))) {
304
+ const other = fallbackFont(fonts, base, grapheme, new Set([base]));
305
+ face = other && span ? variedFace(other, span.font, span.fontSize) : base;
306
+ }
252
307
  faceOf.fill(face, start, end);
253
308
  if (face !== base)
254
309
  fallback.fill(face, start, end);
@@ -748,7 +803,7 @@ export function layOutText(text, fonts) {
748
803
  for (const span of chunk.spans) {
749
804
  const face = matchFont(fonts, span.font);
750
805
  if (face)
751
- primary.set(span, face);
806
+ primary.set(span, variedFace(face, span.font, span.fontSize));
752
807
  }
753
808
  const spans = [];
754
809
  let box = null;
@@ -15,7 +15,7 @@ import { base64 } from "../util/bytes.js";
15
15
  import { gunzip } from "../codecs/zlib.js";
16
16
  import { applyFilter } from "./filter.js";
17
17
  import { BLEND_MODES, blendPixel } from "./blend.js";
18
- import { fontFace, layOutText, parseFontFamilies, pathLength, placeOutline, colorTablesOf } from "./svg-text.js";
18
+ import { fontFace, layOutText, parseFontFamilies, parseVariationSettings, pathLength, placeOutline, colorTablesOf } from "./svg-text.js";
19
19
  import { rasterizeGlyph } from "./text.js";
20
20
  import { renderPaintGlyph } from "./colr.js";
21
21
  import { decodeSync as decodePNG } from "../codecs/png.js";
@@ -26,7 +26,7 @@ const INHERITED = new Set(['fill', 'fill-opacity', 'fill-rule', 'stroke', 'strok
26
26
  'stroke-miterlimit', 'stroke-dasharray', 'stroke-dashoffset', 'color', 'visibility', 'clip-rule', 'font-size', 'marker-start', 'marker-mid',
27
27
  'marker-end', 'image-rendering', 'color-interpolation-filters', 'paint-order', 'shape-rendering',
28
28
  'font-family', 'font-weight', 'font-style', 'font-stretch', 'font-variant', 'text-anchor', 'letter-spacing', 'word-spacing', 'dominant-baseline',
29
- 'writing-mode', 'kerning', 'font-kerning', 'text-rendering']);
29
+ 'writing-mode', 'kerning', 'font-kerning', 'text-rendering', 'font-variation-settings', 'font-optical-sizing']);
30
30
  const CSS_ONLY = new Set(['font-kerning']);
31
31
  const SVG_ELEMENTS = new Set(['a', 'altGlyph', 'altGlyphDef', 'altGlyphItem', 'animate', 'animateColor', 'animateMotion', 'animateTransform', 'circle',
32
32
  'clipPath', 'color-profile', 'cursor', 'defs', 'desc', 'ellipse', 'feBlend', 'feColorMatrix', 'feComponentTransfer', 'feComposite', 'feConvolveMatrix',
@@ -45,6 +45,7 @@ const DEFAULTS = {
45
45
  'stop-color': 'black', 'stop-opacity': '1', 'marker-start': 'none', 'marker-mid': 'none', 'marker-end': 'none',
46
46
  'image-rendering': 'auto', 'filter': 'none', 'flood-color': 'black', 'flood-opacity': '1', 'color-interpolation-filters': 'linearRGB',
47
47
  'lighting-color': 'white', 'shape-rendering': 'auto', 'font-weight': '400', 'font-style': 'normal', 'font-stretch': 'normal',
48
+ 'font-variation-settings': 'normal', 'font-optical-sizing': 'auto',
48
49
  'font-variant': 'normal', 'text-anchor': 'start', 'letter-spacing': 'normal', 'word-spacing': 'normal', 'dominant-baseline': 'auto',
49
50
  'writing-mode': 'lr-tb', 'text-rendering': 'auto'
50
51
  };
@@ -1040,7 +1041,10 @@ class Document {
1040
1041
  const fontStyle = style['font-style'] === 'italic' || style['font-style'] === 'oblique' ? style['font-style'] : 'normal';
1041
1042
  return {
1042
1043
  start, end, paint: style, visible: style.visibility === 'visible',
1043
- font: { families: parseFontFamilies(style['font-family'] ?? ''), weight: Number(style['font-weight']), style: fontStyle, stretch },
1044
+ font: {
1045
+ families: parseFontFamilies(style['font-family'] ?? ''), weight: Number(style['font-weight']), style: fontStyle, stretch,
1046
+ variations: parseVariationSettings(style['font-variation-settings'] ?? ''), opticalSizing: style['font-optical-sizing'] !== 'none',
1047
+ },
1044
1048
  fontSize, smallCaps: style['font-variant'] === 'small-caps',
1045
1049
  kerning: !(style.kerning !== undefined && style.kerning !== 'auto' && parseLength(style.kerning, viewport, fontSize, 'x') === 0) && style['font-kerning'] !== 'none',
1046
1050
  letterSpacing: spacing(style['letter-spacing']), wordSpacing: spacing(style['word-spacing']),
@@ -30,8 +30,22 @@ export function loadFont(data) {
30
30
  regions.set(key, font = new Font(data));
31
31
  return font;
32
32
  }
33
- function sizedFont(data, size, hinting) {
34
- const font = loadFont(data);
33
+ const AXES = { weight: 'wght', width: 'wdth', slant: 'slnt', italic: 'ital', opticalSize: 'opsz' };
34
+ export function axisValues(variations) {
35
+ const values = {};
36
+ for (const [key, value] of Object.entries(variations)) {
37
+ const tag = AXES[key] ?? (key.length === 4 ? key : null);
38
+ if (!tag)
39
+ throw new RangeError(`Unknown font variation ${key}: use weight, width, slant, italic, opticalSize or an axis tag`);
40
+ const v = typeof value === 'boolean' ? +value : value;
41
+ if (typeof v !== 'number' || !Number.isFinite(v))
42
+ throw new RangeError(`Invalid font variation ${key}: ${String(value)}`);
43
+ values[tag] = v;
44
+ }
45
+ return values;
46
+ }
47
+ function sizedFont(data, size, hinting, variations) {
48
+ const font = loadFont(data).withVariations({ opsz: size, ...variations });
35
49
  let bySize = sizes.get(font);
36
50
  if (!bySize)
37
51
  sizes.set(font, bySize = new Map());
@@ -90,9 +104,9 @@ function glyphOf(f, index, size) {
90
104
  f.glyphs.set(index, g);
91
105
  return g;
92
106
  }
93
- export async function render(fonts, size, text, layout, hinting = false, foreground = 0xffffffff, features = []) {
107
+ export async function render(fonts, size, text, layout, hinting = false, foreground = 0xffffffff, features = [], variations = {}) {
94
108
  try {
95
- return await layOut(fonts, size, text, layout, hinting, foreground, features);
109
+ return await layOut(fonts, size, text, layout, hinting, foreground, features, variations);
96
110
  }
97
111
  catch (err) {
98
112
  if (err instanceof RangeError && !(err instanceof TooLarge))
@@ -103,9 +117,9 @@ export async function render(fonts, size, text, layout, hinting = false, foregro
103
117
  const MAX_PIXELS = 1 << 28;
104
118
  class TooLarge extends RangeError {
105
119
  }
106
- async function layOut(fonts, size, text, layout, hinting, foreground, features) {
120
+ async function layOut(fonts, size, text, layout, hinting, foreground, features, variations) {
107
121
  const sized = [];
108
- const font = (i) => sized[i] ??= sizedFont(fonts[i], size, hinting);
122
+ const font = (i) => sized[i] ??= sizedFont(fonts[i], size, hinting, variations);
109
123
  const primary = font(0);
110
124
  const ascent = Math.ceil(primary.font.ascender * primary.scale);
111
125
  const lineHeight = Math.max(1, Math.ceil((primary.font.ascender - primary.font.descender + primary.font.lineGap) * primary.scale));
@@ -0,0 +1,310 @@
1
+ const fixed = (r, o) => r.i32(o) / 65536;
2
+ const f2dot14 = (r, o) => r.i16(o) / 16384;
3
+ export function parseFvar(r, fvar) {
4
+ const axesOffset = r.u16(fvar + 4), count = r.u16(fvar + 8), size = r.u16(fvar + 10);
5
+ const axes = [];
6
+ for (let i = 0; i < count; i++) {
7
+ const o = fvar + axesOffset + i * size;
8
+ const tag = String.fromCharCode(r.u8(o), r.u8(o + 1), r.u8(o + 2), r.u8(o + 3));
9
+ const min = fixed(r, o + 4), def = fixed(r, o + 8), max = fixed(r, o + 12);
10
+ axes.push({ tag, min: Math.min(min, def), default: def, max: Math.max(max, def) });
11
+ }
12
+ return axes;
13
+ }
14
+ export function parseAvar(r, avar, axisCount) {
15
+ if (r.u16(avar) !== 1 || r.u16(avar + 6) !== axisCount)
16
+ return null;
17
+ const maps = [];
18
+ let o = avar + 8;
19
+ for (let a = 0; a < axisCount; a++) {
20
+ const count = r.u16(o), map = [];
21
+ for (let i = 0; i < count; i++)
22
+ map.push(f2dot14(r, o + 2 + i * 4), f2dot14(r, o + 4 + i * 4));
23
+ maps.push(map);
24
+ o += 2 + count * 4;
25
+ }
26
+ return maps;
27
+ }
28
+ export function normalize(axes, avar, values) {
29
+ return axes.map((axis, a) => {
30
+ const v = Math.min(Math.max(values[axis.tag] ?? axis.default, axis.min), axis.max);
31
+ let n = v < axis.default ? (v - axis.default) / (axis.default - axis.min) : v > axis.default ? (v - axis.default) / (axis.max - axis.default) : 0;
32
+ const map = avar?.[a];
33
+ if (map && map.length >= 6) {
34
+ for (let i = 2; i < map.length; i += 2) {
35
+ if (n > map[i])
36
+ continue;
37
+ const [x0, y0, x1, y1] = [map[i - 2], map[i - 1], map[i], map[i + 1]];
38
+ n = x1 === x0 ? y1 : y0 + (n - x0) * (y1 - y0) / (x1 - x0);
39
+ break;
40
+ }
41
+ }
42
+ return Math.round(n * 16384) / 16384;
43
+ });
44
+ }
45
+ export function scalar(coords, peak, start, end) {
46
+ let s = 1;
47
+ for (let a = 0; a < peak.length; a++) {
48
+ const p = peak[a];
49
+ if (p === 0)
50
+ continue;
51
+ const v = coords[a] ?? 0, lo = start ? start[a] : Math.min(p, 0), hi = end ? end[a] : Math.max(p, 0);
52
+ if (start && end && (lo > p || p > hi || lo < 0 && hi > 0))
53
+ continue;
54
+ if (v === p)
55
+ continue;
56
+ if (v <= lo || v >= hi)
57
+ return 0;
58
+ s *= v < p ? (v - lo) / (p - lo) : (hi - v) / (hi - p);
59
+ }
60
+ return s;
61
+ }
62
+ export class ItemVariationStore {
63
+ r;
64
+ regions = [];
65
+ data = [];
66
+ scalars = null;
67
+ scalarsFor = null;
68
+ constructor(r, store) {
69
+ this.r = r;
70
+ const regionList = store + r.u32(store + 2), count = r.u16(store + 6);
71
+ const axisCount = r.u16(regionList), regionCount = r.u16(regionList + 2);
72
+ for (let i = 0; i < regionCount; i++) {
73
+ const region = { peak: [], start: [], end: [] };
74
+ for (let a = 0; a < axisCount; a++) {
75
+ const o = regionList + 4 + (i * axisCount + a) * 6;
76
+ region.start.push(f2dot14(r, o));
77
+ region.peak.push(f2dot14(r, o + 2));
78
+ region.end.push(f2dot14(r, o + 4));
79
+ }
80
+ this.regions.push(region);
81
+ }
82
+ for (let i = 0; i < count; i++) {
83
+ const o = store + r.u32(store + 8 + i * 4);
84
+ const words = r.u16(o + 2), regionIndexCount = r.u16(o + 4), regions = [];
85
+ for (let k = 0; k < regionIndexCount; k++)
86
+ regions.push(r.u16(o + 6 + k * 2));
87
+ this.data.push({ itemCount: r.u16(o), wordCount: words & 0x7fff, long: (words & 0x8000) !== 0, regions, offset: o + 6 + regionIndexCount * 2 });
88
+ }
89
+ }
90
+ delta(coords, outer, inner) {
91
+ const d = this.data[outer];
92
+ if (!d || inner >= d.itemCount)
93
+ return 0;
94
+ if (this.scalarsFor !== coords) {
95
+ this.scalars = Float64Array.from(this.regions, region => scalar(coords, region.peak, region.start, region.end));
96
+ this.scalarsFor = coords;
97
+ }
98
+ const scalars = this.scalars, r = this.r;
99
+ const big = d.long ? 4 : 2, small = d.long ? 2 : 1;
100
+ let o = d.offset + inner * (d.wordCount * big + (d.regions.length - d.wordCount) * small), delta = 0;
101
+ for (let k = 0; k < d.regions.length; k++) {
102
+ const s = scalars[d.regions[k]] ?? 0;
103
+ let v;
104
+ if (k < d.wordCount) {
105
+ v = d.long ? r.i32(o) : r.i16(o);
106
+ o += big;
107
+ }
108
+ else {
109
+ v = d.long ? r.i16(o) : r.i8(o);
110
+ o += small;
111
+ }
112
+ if (s)
113
+ delta += s * v;
114
+ }
115
+ return delta;
116
+ }
117
+ }
118
+ export function deltaSetIndexMap(r, map) {
119
+ const format = r.u8(map), entryFormat = r.u8(map + 1);
120
+ const count = format === 0 ? r.u16(map + 2) : r.u32(map + 2), start = map + (format === 0 ? 4 : 6);
121
+ const size = (entryFormat >> 4 & 3) + 1, innerBits = (entryFormat & 15) + 1;
122
+ return index => {
123
+ if (!count)
124
+ return [0, index];
125
+ const i = Math.min(index, count - 1);
126
+ let v = 0;
127
+ for (let k = 0; k < size; k++)
128
+ v = v * 256 + r.u8(start + i * size + k);
129
+ return [Math.floor(v / 2 ** innerBits), v % 2 ** innerBits];
130
+ };
131
+ }
132
+ function readPoints(r, o) {
133
+ let count = r.u8(o++);
134
+ if (count & 0x80)
135
+ count = (count & 0x7f) << 8 | r.u8(o++);
136
+ if (!count)
137
+ return [null, o];
138
+ const points = [];
139
+ let point = 0;
140
+ while (points.length < count) {
141
+ const control = r.u8(o++), words = control & 0x80, run = (control & 0x7f) + 1;
142
+ for (let i = 0; i < run && points.length < count; i++) {
143
+ point += words ? r.u16(o) : r.u8(o);
144
+ o += words ? 2 : 1;
145
+ points.push(point);
146
+ }
147
+ }
148
+ return [points, o];
149
+ }
150
+ function readDeltas(r, o, n) {
151
+ const deltas = new Int32Array(n);
152
+ for (let i = 0; i < n;) {
153
+ const control = r.u8(o++), run = (control & 0x3f) + 1;
154
+ for (let k = 0; k < run && i < n; k++, i++) {
155
+ if (control & 0x80)
156
+ deltas[i] = 0;
157
+ else if (control & 0x40) {
158
+ deltas[i] = r.i16(o);
159
+ o += 2;
160
+ }
161
+ else
162
+ deltas[i] = r.i8(o++);
163
+ }
164
+ }
165
+ return [deltas, o];
166
+ }
167
+ function readTuples(r, base, header, axisCount, sharedTuples) {
168
+ const countField = r.u16(header), count = countField & 0xfff, dataOffset = r.u16(header + 2);
169
+ let h = header + 4, data = base + dataOffset;
170
+ let shared = null;
171
+ if (countField & 0x8000)
172
+ [shared, data] = readPoints(r, data);
173
+ const tuples = [];
174
+ for (let i = 0; i < count; i++) {
175
+ const size = r.u16(h), index = r.u16(h + 2);
176
+ h += 4;
177
+ let peak;
178
+ if (index & 0x8000) {
179
+ peak = Array.from({ length: axisCount }, (_, a) => f2dot14(r, h + a * 2));
180
+ h += axisCount * 2;
181
+ }
182
+ else
183
+ peak = sharedTuples[index & 0xfff] ?? new Array(axisCount).fill(0);
184
+ let start = null, end = null;
185
+ if (index & 0x4000) {
186
+ start = Array.from({ length: axisCount }, (_, a) => f2dot14(r, h + a * 2));
187
+ end = Array.from({ length: axisCount }, (_, a) => f2dot14(r, h + axisCount * 2 + a * 2));
188
+ h += axisCount * 4;
189
+ }
190
+ let points = shared, d = data;
191
+ if (index & 0x2000)
192
+ [points, d] = readPoints(r, data);
193
+ tuples.push({ peak, start, end, points, data: d, size: size - (d - data) });
194
+ data += size;
195
+ }
196
+ return tuples;
197
+ }
198
+ export class Gvar {
199
+ r;
200
+ axisCount;
201
+ sharedTuples = [];
202
+ glyphCount;
203
+ long;
204
+ offsets;
205
+ dataStart;
206
+ constructor(r, gvar) {
207
+ this.r = r;
208
+ this.axisCount = r.u16(gvar + 4);
209
+ const sharedCount = r.u16(gvar + 6), shared = gvar + r.u32(gvar + 8);
210
+ for (let i = 0; i < sharedCount; i++)
211
+ this.sharedTuples.push(Array.from({ length: this.axisCount }, (_, a) => f2dot14(r, shared + (i * this.axisCount + a) * 2)));
212
+ this.glyphCount = r.u16(gvar + 12);
213
+ this.long = (r.u16(gvar + 14) & 1) !== 0;
214
+ this.dataStart = gvar + r.u32(gvar + 16);
215
+ this.offsets = gvar + 20;
216
+ }
217
+ deltas(glyph, coords, n, ends, xs, ys) {
218
+ if (glyph >= this.glyphCount || coords.every(c => c === 0))
219
+ return null;
220
+ const r = this.r;
221
+ const offset = (i) => this.long ? r.u32(this.offsets + i * 4) : r.u16(this.offsets + i * 2) * 2;
222
+ const start = offset(glyph), end = offset(glyph + 1);
223
+ if (end <= start)
224
+ return null;
225
+ const base = this.dataStart + start;
226
+ const out = new Float64Array(2 * n);
227
+ let any = false;
228
+ for (const t of readTuples(r, base, base, this.axisCount, this.sharedTuples)) {
229
+ const s = scalar(coords, t.peak, t.start, t.end);
230
+ if (!s)
231
+ continue;
232
+ const count = t.points ? t.points.length : n;
233
+ const [dx, after] = readDeltas(r, t.data, count), [dy] = readDeltas(r, after, count);
234
+ any = true;
235
+ if (!t.points) {
236
+ for (let i = 0; i < n; i++) {
237
+ out[2 * i] += s * dx[i];
238
+ out[2 * i + 1] += s * dy[i];
239
+ }
240
+ continue;
241
+ }
242
+ const tx = new Float64Array(n), ty = new Float64Array(n), touched = new Uint8Array(n);
243
+ t.points.forEach((p, k) => {
244
+ if (p >= n)
245
+ return;
246
+ tx[p] = dx[k];
247
+ ty[p] = dy[k];
248
+ touched[p] = 1;
249
+ });
250
+ if (ends)
251
+ interpolateUntouched(tx, ty, touched, ends, xs, ys);
252
+ for (let i = 0; i < n; i++) {
253
+ out[2 * i] += s * tx[i];
254
+ out[2 * i + 1] += s * ty[i];
255
+ }
256
+ }
257
+ return any ? out : null;
258
+ }
259
+ }
260
+ function interpolateUntouched(dx, dy, touched, ends, xs, ys) {
261
+ let first = 0;
262
+ for (const last of ends) {
263
+ let firstTouched = -1;
264
+ for (let i = first; i <= last; i++)
265
+ if (touched[i]) {
266
+ firstTouched = i;
267
+ break;
268
+ }
269
+ if (firstTouched >= 0) {
270
+ for (const [d, c] of [[dx, xs], [dy, ys]]) {
271
+ let prev = firstTouched;
272
+ for (let k = 1; k <= last - first + 1; k++) {
273
+ const i = first + (firstTouched - first + k) % (last - first + 1);
274
+ if (!touched[i])
275
+ continue;
276
+ infer(d, c, prev, i, first, last);
277
+ prev = i;
278
+ }
279
+ }
280
+ }
281
+ first = last + 1;
282
+ }
283
+ }
284
+ function infer(d, c, a, b, first, last) {
285
+ const ca = c[a], cb = c[b], da = d[a], db = d[b];
286
+ const lo = Math.min(ca, cb), hi = Math.max(ca, cb), dlo = ca <= cb ? da : db, dhi = ca <= cb ? db : da;
287
+ for (let i = a === last ? first : a + 1; i !== b; i = i === last ? first : i + 1) {
288
+ const v = c[i];
289
+ d[i] = lo === hi ? (da === db ? da : 0) : v <= lo ? dlo : v >= hi ? dhi : dlo + (v - lo) * (dhi - dlo) / (hi - lo);
290
+ }
291
+ }
292
+ export function cvarDeltas(r, cvar, axisCount, coords, count) {
293
+ if (coords.every(c => c === 0))
294
+ return null;
295
+ const out = new Float64Array(count);
296
+ let any = false;
297
+ for (const t of readTuples(r, cvar, cvar + 4, axisCount, [])) {
298
+ const s = scalar(coords, t.peak, t.start, t.end);
299
+ if (!s)
300
+ continue;
301
+ const points = t.points ?? Array.from({ length: count }, (_, i) => i);
302
+ const [deltas] = readDeltas(r, t.data, points.length);
303
+ points.forEach((p, k) => {
304
+ if (p < count)
305
+ out[p] += s * deltas[k];
306
+ });
307
+ any = true;
308
+ }
309
+ return any ? out : null;
310
+ }
package/dist/util/icc.js CHANGED
@@ -109,7 +109,43 @@ export function profileTransform(icc) {
109
109
  catch {
110
110
  return null;
111
111
  }
112
- if (!p || isSRGB(p))
112
+ return p && transform(p);
113
+ }
114
+ const CICP_PRIMARIES = {
115
+ 1: [[0.64, 0.33], [0.30, 0.60], [0.15, 0.06], [0.3127, 0.3290]],
116
+ 4: [[0.67, 0.33], [0.21, 0.71], [0.14, 0.08], [0.310, 0.316]],
117
+ 5: [[0.64, 0.33], [0.29, 0.60], [0.15, 0.06], [0.3127, 0.3290]],
118
+ 6: [[0.630, 0.340], [0.310, 0.595], [0.155, 0.070], [0.3127, 0.3290]],
119
+ 7: [[0.630, 0.340], [0.310, 0.595], [0.155, 0.070], [0.3127, 0.3290]],
120
+ 8: [[0.681, 0.319], [0.243, 0.692], [0.145, 0.049], [0.310, 0.316]],
121
+ 9: [[0.708, 0.292], [0.170, 0.797], [0.131, 0.046], [0.3127, 0.3290]],
122
+ 11: [[0.680, 0.320], [0.265, 0.690], [0.150, 0.060], [0.314, 0.351]],
123
+ 12: [[0.680, 0.320], [0.265, 0.690], [0.150, 0.060], [0.3127, 0.3290]],
124
+ 22: [[0.630, 0.340], [0.295, 0.605], [0.155, 0.077], [0.3127, 0.3290]],
125
+ };
126
+ const D50 = [0.9642, 1, 0.8249];
127
+ const BRADFORD = [0.8951, 0.2664, -0.1614, -0.7502, 1.7135, 0.0367, 0.0389, -0.0685, 1.0296];
128
+ export function cicpTransform(primaries, transfer) {
129
+ const xy = CICP_PRIMARIES[primaries];
130
+ if (!xy || transfer === 16 || transfer === 18)
131
+ return null;
132
+ const xyz = ([x, y]) => [x / y, 1, (1 - x - y) / y];
133
+ const p = [0, 1, 2].map(i => xyz(xy[i])), white = xyz(xy[3]);
134
+ const columns = [p[0][0], p[1][0], p[2][0], p[0][1], p[1][1], p[2][1], p[0][2], p[1][2], p[2][2]];
135
+ const inverse = invert3(columns);
136
+ if (!inverse)
137
+ return null;
138
+ const scale = [0, 1, 2].map(r => inverse[r * 3] * white[0] + inverse[r * 3 + 1] * white[1] + inverse[r * 3 + 2] * white[2]);
139
+ const matrix = columns.map((v, i) => v * scale[i % 3]);
140
+ const cone = (v) => [0, 1, 2].map(r => BRADFORD[r * 3] * v[0] + BRADFORD[r * 3 + 1] * v[1] + BRADFORD[r * 3 + 2] * v[2]);
141
+ const from = cone(white), to = cone(D50);
142
+ const adapt = multiply3(invert3(BRADFORD), multiply3([to[0] / from[0], 0, 0, 0, to[1] / from[1], 0, 0, 0, to[2] / from[2]], BRADFORD));
143
+ const curve = transfer === 4 ? v => v ** 2.2 : transfer === 5 ? v => v ** 2.8 : transfer === 8 ? v => v
144
+ : v => v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
145
+ return transform({ gray: false, matrix: multiply3(adapt, matrix), curves: [curve, curve, curve] });
146
+ }
147
+ function transform(p) {
148
+ if (isSRGB(p))
113
149
  return null;
114
150
  const linear = p.curves.map(c => Float32Array.from({ length: 256 }, (_, i) => c(i / 255)));
115
151
  const N = 4096, encode = new Uint8Array(N + 1);
@@ -62,7 +62,8 @@ export function startThreads(n) {
62
62
  }
63
63
  else {
64
64
  const { Worker } = builtin('node:worker_threads');
65
- const w = new Worker(new URL(import.meta.url.endsWith('.ts') ? './worker.ts' : './worker.js', import.meta.url));
65
+ const url = import.meta.url;
66
+ const w = new Worker(new URL(url.endsWith('.ts') ? './worker.ts' : './worker.js', url));
66
67
  w.unref();
67
68
  threads.push(thread(m => w.postMessage(m), (message, error) => {
68
69
  w.on('message', m => message(m));
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = '3.10.0';
1
+ export const VERSION = '3.12.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imagescript",
3
- "version": "3.10.0",
3
+ "version": "3.12.0",
4
4
  "description": "zero-dependency javascript image manipulation",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",