@ingcreators/annot-annotator 0.5.0 → 0.6.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/index.js CHANGED
@@ -51,7 +51,7 @@ function h(e) {
51
51
  return r;
52
52
  }
53
53
  var g = (() => {
54
- let e = new Uint32Array(256);
54
+ let e = /* @__PURE__ */ new Uint32Array(256);
55
55
  for (let t = 0; t < 256; t++) {
56
56
  let n = t;
57
57
  for (let e = 0; e < 8; e++) n & 1 ? n = 3988292384 ^ n >>> 1 : n >>>= 1;
@@ -142,7 +142,7 @@ var D = new Uint8Array([
142
142
  26,
143
143
  10
144
144
  ]), O = (() => {
145
- let e = new Uint32Array(256);
145
+ let e = /* @__PURE__ */ new Uint32Array(256);
146
146
  for (let t = 0; t < 256; t++) {
147
147
  let n = t;
148
148
  for (let e = 0; e < 8; e++) n = n & 1 ? 3988292384 ^ n >>> 1 : n >>> 1;
@@ -169,7 +169,7 @@ function j(e, t, n, i, a = 9) {
169
169
  let o = e.length >>> 2;
170
170
  if (o < 1 || o > 256) throw Error(`encodePng8: palette must have 1–256 colors, got ${o}`);
171
171
  if (t.length !== n * i) throw Error(`encodePng8: indices length ${t.length} != width*height ${n * i}`);
172
- let s = new Uint8Array(13), c = new DataView(s.buffer);
172
+ let s = /* @__PURE__ */ new Uint8Array(13), c = new DataView(s.buffer);
173
173
  c.setUint32(0, n, !1), c.setUint32(4, i, !1), s[8] = 8, s[9] = 3, s[10] = 0, s[11] = 0, s[12] = 0;
174
174
  let l = new Uint8Array(o * 3), u = !1, d = -1;
175
175
  for (let t = 0; t < o; t++) l[t * 3] = e[t * 4], l[t * 3 + 1] = e[t * 4 + 1], l[t * 3 + 2] = e[t * 4 + 2], e[t * 4 + 3] < 255 && (u = !0, d = t);
@@ -192,7 +192,7 @@ function j(e, t, n, i, a = 9) {
192
192
  A("IHDR", s),
193
193
  A("PLTE", l)
194
194
  ];
195
- f && g.push(A("tRNS", f)), g.push(A("IDAT", h)), g.push(A("IEND", new Uint8Array()));
195
+ f && g.push(A("tRNS", f)), g.push(A("IDAT", h)), g.push(A("IEND", /* @__PURE__ */ new Uint8Array()));
196
196
  let _ = 0;
197
197
  for (let e of g) _ += e.length;
198
198
  let v = new Uint8Array(_), y = 0;
@@ -201,12 +201,12 @@ function j(e, t, n, i, a = 9) {
201
201
  }
202
202
  //#endregion
203
203
  //#region ../core/src/encode/quantize-median-cut.ts
204
- function M(e, t, n, r) {
204
+ function ee(e, t, n, r) {
205
205
  if (!Number.isInteger(t) || t <= 0) throw Error(`quantizeMedianCut: invalid width ${t}`);
206
206
  if (!Number.isInteger(n) || n <= 0) throw Error(`quantizeMedianCut: invalid height ${n}`);
207
207
  let i = t * n * 4;
208
208
  if (e.length !== i) throw Error(`quantizeMedianCut: rgba length ${e.length} != width*height*4 = ${i}`);
209
- let a = Math.max(1, Math.min(256, Math.floor(r))), { opaqueSamples: o, hasTransparent: s, transparentCount: c } = P(e), l = F(o, s ? Math.max(1, a - 1) : a), u = l.length, d = u + +!!s, f = new Uint8Array(d * 4), p = 0;
209
+ let a = Math.max(1, Math.min(256, Math.floor(r))), { opaqueSamples: o, hasTransparent: s, transparentCount: c } = te(e), l = ne(o, s ? Math.max(1, a - 1) : a), u = l.length, d = u + +!!s, f = new Uint8Array(d * 4), p = 0;
210
210
  s && (f[0] = 0, f[1] = 0, f[2] = 0, f[3] = 0, p = 1);
211
211
  let m = p * 4;
212
212
  for (let e = 0; e < u; e++) {
@@ -215,14 +215,14 @@ function M(e, t, n, r) {
215
215
  }
216
216
  return {
217
217
  palette: f,
218
- indices: te(e, t, n, f, m, s, c > 0)
218
+ indices: ie(e, t, n, f, m, s, c > 0)
219
219
  };
220
220
  }
221
- var N = 16;
222
- function P(e) {
221
+ var M = 16;
222
+ function te(e) {
223
223
  let t = /* @__PURE__ */ new Map(), n = 0, r = e.length;
224
224
  for (let i = 0; i < r; i += 4) {
225
- if (e[i + 3] < N) {
225
+ if (e[i + 3] < M) {
226
226
  n++;
227
227
  continue;
228
228
  }
@@ -242,10 +242,10 @@ function P(e) {
242
242
  transparentCount: n
243
243
  };
244
244
  }
245
- function F(e, t) {
245
+ function ne(e, t) {
246
246
  if (e.length === 0) return [];
247
- if (t <= 1) return [I(e, 0, e.length, 0)];
248
- let n = [I(e, 0, e.length, 0)], r = 1;
247
+ if (t <= 1) return [N(e, 0, e.length, 0)];
248
+ let n = [N(e, 0, e.length, 0)], r = 1;
249
249
  for (; n.length < t;) {
250
250
  let t = -1, i = -1, a = Infinity;
251
251
  for (let e = 0; e < n.length; e++) {
@@ -254,19 +254,19 @@ function F(e, t) {
254
254
  }
255
255
  if (t < 0) break;
256
256
  let o = n[t], s = o.rMax - o.rMin, c = o.gMax - o.gMin, l = o.bMax - o.bMin, u;
257
- u = s >= c && s >= l ? 0 : c >= l ? 1 : 2, ee(e, o.start, o.end, u);
257
+ u = s >= c && s >= l ? 0 : c >= l ? 1 : 2, re(e, o.start, o.end, u);
258
258
  let d = o.population >>> 1, f = 0, p = o.start + 1;
259
259
  for (let t = o.start; t < o.end; t++) if (f += e[t].count, f >= d) {
260
260
  p = t + 1;
261
261
  break;
262
262
  }
263
263
  p <= o.start && (p = o.start + 1), p >= o.end && (p = o.end - 1);
264
- let m = I(e, o.start, p, r++), h = I(e, p, o.end, r++);
264
+ let m = N(e, o.start, p, r++), h = N(e, p, o.end, r++);
265
265
  n[t] = m, n.push(h);
266
266
  }
267
267
  return n;
268
268
  }
269
- function I(e, t, n, r) {
269
+ function N(e, t, n, r) {
270
270
  let i = 255, a = 0, o = 255, s = 0, c = 255, l = 0, u = 0, d = 0, f = 0, p = 0;
271
271
  for (let r = t; r < n; r++) {
272
272
  let t = e[r];
@@ -290,12 +290,12 @@ function I(e, t, n, r) {
290
290
  insertOrder: r
291
291
  };
292
292
  }
293
- function ee(e, t, n, r) {
293
+ function re(e, t, n, r) {
294
294
  let i = e.slice(t, n);
295
295
  r === 0 ? i.sort((e, t) => e.r - t.r) : r === 1 ? i.sort((e, t) => e.g - t.g) : i.sort((e, t) => e.b - t.b);
296
296
  for (let n = 0; n < i.length; n++) e[t + n] = i[n];
297
297
  }
298
- function te(e, t, n, r, i, a, o) {
298
+ function ie(e, t, n, r, i, a, o) {
299
299
  let s = t * n, c = new Uint8Array(s), l = new Float32Array(t), u = new Float32Array(t), d = new Float32Array(t), f = new Float32Array(t), p = new Float32Array(t), m = new Float32Array(t), h = r.length - i >>> 2, g = new Int32Array(h), _ = new Int32Array(h), v = new Int32Array(h);
300
300
  for (let e = 0; e < h; e++) {
301
301
  let t = i + e * 4;
@@ -306,7 +306,7 @@ function te(e, t, n, r, i, a, o) {
306
306
  f.fill(0), p.fill(0), m.fill(0);
307
307
  for (let n = 0; n < t; n++) {
308
308
  let i = r * t + n, o = i * 4, s = e[o + 3];
309
- if (a && s < N) {
309
+ if (a && s < M) {
310
310
  c[i] = 0;
311
311
  continue;
312
312
  }
@@ -330,11 +330,11 @@ function te(e, t, n, r, i, a, o) {
330
330
  }
331
331
  //#endregion
332
332
  //#region src/encode/quantize.ts
333
- function ne(e, t, n) {
334
- let { palette: r, indices: i } = M(e, t, n, 256);
333
+ function ae(e, t, n) {
334
+ let { palette: r, indices: i } = ee(e, t, n, 256);
335
335
  return j(r, i, t, n, 9);
336
336
  }
337
- function L(e, t) {
337
+ function P(e, t) {
338
338
  let n = new Uint32Array(e.buffer, e.byteOffset, e.byteLength >>> 2), r = n.length;
339
339
  if (r === 0) return !1;
340
340
  let i = Math.max(1, Math.floor(r / 5e4)), a = /* @__PURE__ */ new Set();
@@ -343,64 +343,64 @@ function L(e, t) {
343
343
  }
344
344
  //#endregion
345
345
  //#region src/encode/encode.ts
346
- var re = 1e7;
347
- async function R(e, t, n, r = T) {
348
- let i = E(t, n, r.saveSizePreset ?? "original"), a = i.scaled ? ae(e, t, n, i.width, i.height) : e, o = i.width, s = i.height;
346
+ var oe = 1e7;
347
+ async function F(e, t, n, r = T) {
348
+ let i = E(t, n, r.saveSizePreset ?? "original"), a = i.scaled ? ce(e, t, n, i.width, i.height) : e, o = i.width, s = i.height;
349
349
  return r.format === "png" ? {
350
- bytes: z(a, o, s),
350
+ bytes: I(a, o, s),
351
351
  chosen: "png",
352
352
  width: o,
353
353
  height: s
354
354
  } : r.format === "jpeg" ? {
355
- bytes: B(a, o, s, r.jpegPercent / 100),
355
+ bytes: L(a, o, s, r.jpegPercent / 100),
356
356
  chosen: "jpeg",
357
357
  width: o,
358
358
  height: s
359
- } : o * s > re ? {
360
- bytes: z(a, o, s),
359
+ } : o * s > oe ? {
360
+ bytes: I(a, o, s),
361
361
  chosen: "png",
362
362
  reason: "too-large-for-png8",
363
363
  width: o,
364
364
  height: s
365
- } : L(a, r.smartColorThreshold) ? r.smartFallback === "jpeg" ? {
366
- bytes: B(a, o, s, r.jpegPercent / 100),
365
+ } : P(a, r.smartColorThreshold) ? r.smartFallback === "jpeg" ? {
366
+ bytes: L(a, o, s, r.jpegPercent / 100),
367
367
  chosen: "jpeg",
368
368
  reason: "photo-fallback-jpeg",
369
369
  width: o,
370
370
  height: s
371
371
  } : {
372
- bytes: z(a, o, s),
372
+ bytes: I(a, o, s),
373
373
  chosen: "png",
374
374
  reason: "photo-fallback-png",
375
375
  width: o,
376
376
  height: s
377
377
  } : {
378
- bytes: ne(a, o, s),
378
+ bytes: ae(a, o, s),
379
379
  chosen: "png",
380
380
  reason: "png-8",
381
381
  width: o,
382
382
  height: s
383
383
  };
384
384
  }
385
- async function ie(e, r = T) {
385
+ async function se(e, r = T) {
386
386
  let i = await n(Buffer.from(e)), a = t(i.width, i.height).getContext("2d");
387
387
  a.drawImage(i, 0, 0);
388
388
  let o = a.getImageData(0, 0, i.width, i.height).data;
389
- return R(new Uint8Array(o.buffer, o.byteOffset, o.byteLength), i.width, i.height, r);
389
+ return F(new Uint8Array(o.buffer, o.byteOffset, o.byteLength), i.width, i.height, r);
390
390
  }
391
- function z(e, n, r) {
391
+ function I(e, n, r) {
392
392
  let i = t(n, r), a = i.getContext("2d"), o = a.createImageData(n, r);
393
393
  o.data.set(e), a.putImageData(o, 0, 0);
394
394
  let s = i.toBuffer("image/png");
395
395
  return new Uint8Array(s.buffer, s.byteOffset, s.byteLength);
396
396
  }
397
- function B(e, n, r, i) {
397
+ function L(e, n, r, i) {
398
398
  let a = t(n, r), o = a.getContext("2d"), s = o.createImageData(n, r);
399
399
  s.data.set(e), o.putImageData(s, 0, 0);
400
400
  let c = a.toBuffer("image/jpeg", i);
401
401
  return new Uint8Array(c.buffer, c.byteOffset, c.byteLength);
402
402
  }
403
- function ae(e, n, r, i, a) {
403
+ function ce(e, n, r, i, a) {
404
404
  let o = t(n, r), s = o.getContext("2d"), c = s.createImageData(n, r);
405
405
  c.data.set(e), s.putImageData(c, 0, 0);
406
406
  let l = t(i, a).getContext("2d");
@@ -410,7 +410,7 @@ function ae(e, n, r, i, a) {
410
410
  }
411
411
  //#endregion
412
412
  //#region src/sanitise-svg.ts
413
- function oe(e) {
413
+ function le(e) {
414
414
  if (!e || e.trim().length === 0) return "";
415
415
  let t = new i(), n;
416
416
  try {
@@ -426,7 +426,7 @@ function oe(e) {
426
426
  if (!t || t.nodeType !== 1) continue;
427
427
  let n = t, i = n.localName ?? n.tagName ?? "";
428
428
  if (i === "defs") {
429
- let e = se(n);
429
+ let e = ue(n);
430
430
  e !== null && (s += o.serializeToString(e));
431
431
  continue;
432
432
  }
@@ -443,7 +443,7 @@ function oe(e) {
443
443
  }
444
444
  return s;
445
445
  }
446
- function se(e) {
446
+ function ue(e) {
447
447
  let t = e.cloneNode(!0);
448
448
  for (let e = t.childNodes.length - 1; e >= 0; e--) {
449
449
  let n = t.childNodes.item(e);
@@ -455,7 +455,7 @@ function se(e) {
455
455
  }
456
456
  //#endregion
457
457
  //#region src/annotator.ts
458
- function V(t = {}) {
458
+ function de(t = {}) {
459
459
  let n = {
460
460
  loadSystemFonts: t.loadSystemFonts ?? !1,
461
461
  ...t.fontFiles ? { fontFiles: t.fontFiles } : {},
@@ -463,7 +463,7 @@ function V(t = {}) {
463
463
  ...t.defaultFontFamily ? { defaultFontFamily: t.defaultFontFamily } : {}
464
464
  };
465
465
  function r(t) {
466
- let r = new e(H(t), {
466
+ let r = new e(R(t), {
467
467
  fitTo: {
468
468
  mode: "width",
469
469
  value: t.width
@@ -479,10 +479,10 @@ function V(t = {}) {
479
479
  }
480
480
  return {
481
481
  toSvg(e) {
482
- return H(e);
482
+ return R(e);
483
483
  },
484
484
  toPng(t) {
485
- return new e(H(t), {
485
+ return new e(R(t), {
486
486
  fitTo: {
487
487
  mode: "width",
488
488
  value: t.width
@@ -493,7 +493,7 @@ function V(t = {}) {
493
493
  },
494
494
  toEditablePng(t) {
495
495
  return S({
496
- renderedPng: new e(H(t), {
496
+ renderedPng: new e(R(t), {
497
497
  fitTo: {
498
498
  mode: "width",
499
499
  value: t.width
@@ -510,17 +510,203 @@ function V(t = {}) {
510
510
  },
511
511
  async toEncoded(e, t) {
512
512
  let { pixels: n, width: i, height: a } = r(e);
513
- return R(n, i, a, t);
513
+ return F(n, i, a, t);
514
514
  }
515
515
  };
516
516
  }
517
- function H(e) {
518
- let t = oe(e.annotationsSvg);
517
+ function R(e) {
518
+ let t = le(e.annotationsSvg);
519
519
  return `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ${o}="1" width="${e.width}" height="${e.height}" viewBox="0 0 ${e.width} ${e.height}"><image href="${e.originalDataUrl}" width="${e.width}" height="${e.height}"/>` + t + "</svg>";
520
520
  }
521
521
  //#endregion
522
+ //#region src/redact-burn.ts
523
+ var fe = "solid", pe = "#000000", z = 16, me = 12;
524
+ async function B(e, r) {
525
+ if (r.length === 0) return e;
526
+ let i = await n(Buffer.from(e)), a = t(i.width, i.height), o = a.getContext("2d");
527
+ o.drawImage(i, 0, 0);
528
+ for (let e of r) if (!(e.bbox.width <= 0 || e.bbox.height <= 0)) switch (e.style ?? fe) {
529
+ case "solid":
530
+ he(o, e.bbox, e.color ?? pe);
531
+ break;
532
+ case "mosaic":
533
+ ge(o, i, e.bbox);
534
+ break;
535
+ case "blur":
536
+ _e(o, i, e.bbox);
537
+ break;
538
+ }
539
+ let s = a.toBuffer("image/png");
540
+ return new Uint8Array(s.buffer, s.byteOffset, s.byteLength);
541
+ }
542
+ function he(e, t, n) {
543
+ e.save(), e.fillStyle = n, e.fillRect(t.x, t.y, t.width, t.height), e.restore();
544
+ }
545
+ function ge(e, n, r) {
546
+ let i = Math.max(1, Math.round(r.width / z)), a = Math.max(1, Math.round(r.height / z)), o = t(i, a), s = o.getContext("2d");
547
+ s.imageSmoothingEnabled = !1, s.drawImage(n, r.x, r.y, r.width, r.height, 0, 0, i, a), e.save(), e.imageSmoothingEnabled = !1, e.drawImage(o, 0, 0, i, a, r.x, r.y, r.width, r.height), e.restore();
548
+ }
549
+ function _e(e, t, n) {
550
+ e.save(), e.beginPath(), e.rect(n.x, n.y, n.width, n.height), e.clip(), e.filter = `blur(${me}px)`, e.drawImage(t, 0, 0), e.restore();
551
+ }
552
+ var ve = B;
553
+ //#endregion
554
+ //#region ../../node_modules/.pnpm/pixelmatch@7.2.0/node_modules/pixelmatch/index.js
555
+ function ye(e, t, n, r, i, a = {}) {
556
+ let { threshold: o = .1, alpha: s = .1, aaColor: c = [
557
+ 255,
558
+ 255,
559
+ 0
560
+ ], diffColor: l = [
561
+ 255,
562
+ 0,
563
+ 0
564
+ ], checkerboard: u = !0, includeAA: d, diffColorAlt: f, diffMask: p } = a;
565
+ if (!V(e) || !V(t) || n && !V(n)) throw Error("Image data: Uint8Array, Uint8ClampedArray or Buffer expected.");
566
+ if (e.length !== t.length || n && n.length !== e.length) throw Error(`Image sizes do not match. Image 1 size: ${e.length}, image 2 size: ${t.length}`);
567
+ if (e.length !== r * i * 4) throw Error(`Image data size does not match width/height. Expecting ${r * i * 4}. Got ${e.length}`);
568
+ let m = r * i, h = new Uint32Array(e.buffer, e.byteOffset, m), g = new Uint32Array(t.buffer, t.byteOffset, m), _ = !0;
569
+ for (let e = 0; e < m; e++) if (h[e] !== g[e]) {
570
+ _ = !1;
571
+ break;
572
+ }
573
+ if (_) {
574
+ if (n && !p) for (let t = 0, r = 0; t < m; t++, r += 4) G(e, r, s, n);
575
+ return 0;
576
+ }
577
+ let v = 35215 * o * o, [y, b, x] = c, [S, C, w] = l, [T, E, D] = f || l, O = 0;
578
+ for (let a = 0, o = 0; a < m; a++, o += 4) {
579
+ let c = h[a] === g[a] ? 0 : be(e, t, o, o, u);
580
+ if (Math.abs(c) > v) {
581
+ let s = a % r, l = a / r | 0;
582
+ !d && (H(e, s, l, r, i, h, g, u) || H(t, s, l, r, i, g, h, u)) ? n && !p && W(n, o, y, b, x) : (n && (c < 0 ? W(n, o, T, E, D) : W(n, o, S, C, w)), O++);
583
+ } else n && !p && G(e, o, s, n);
584
+ }
585
+ return O;
586
+ }
587
+ function V(e) {
588
+ return ArrayBuffer.isView(e) && e.BYTES_PER_ELEMENT === 1;
589
+ }
590
+ function H(e, t, n, r, i, a, o, s) {
591
+ let c = Math.max(t - 1, 0), l = Math.max(n - 1, 0), u = Math.min(t + 1, r - 1), d = Math.min(n + 1, i - 1), f = (n * r + t) * 4, p = e[f], m = e[f + 1], h = e[f + 2], g = e[f + 3], _ = +(t === c || t === u || n === l || n === d), v = 0, y = 0, b = 0, x = 0, S = 0, C = 0;
592
+ for (let i = c; i <= u; i++) for (let a = l; a <= d; a++) {
593
+ if (i === t && a === n) continue;
594
+ let o = xe(e, f, (a * r + i) * 4, p, m, h, g, s);
595
+ if (o === 0) {
596
+ if (_++, _ > 2) return !1;
597
+ } else o < v ? (v = o, b = i, x = a) : o > y && (y = o, S = i, C = a);
598
+ }
599
+ return v === 0 || y === 0 ? !1 : U(a, b, x, r, i) && U(o, b, x, r, i) || U(a, S, C, r, i) && U(o, S, C, r, i);
600
+ }
601
+ function U(e, t, n, r, i) {
602
+ let a = Math.max(t - 1, 0), o = Math.max(n - 1, 0), s = Math.min(t + 1, r - 1), c = Math.min(n + 1, i - 1), l = e[n * r + t], u = +(t === a || t === s || n === o || n === c);
603
+ for (let i = a; i <= s; i++) for (let a = o; a <= c; a++) if (!(i === t && a === n) && (u += +(l === e[a * r + i]), u > 2)) return !0;
604
+ return !1;
605
+ }
606
+ function be(e, t, n, r, i) {
607
+ let a = e[n], o = e[n + 1], s = e[n + 2], c = e[n + 3], l = t[r], u = t[r + 1], d = t[r + 2], f = t[r + 3], p = a - l, m = o - u, h = s - d, g = c - f;
608
+ if (c < 255 || f < 255) {
609
+ let e = 255, t = 255, r = 255;
610
+ i && (e = 48 + n % 2 * 159, t = 48 + 159 * ((n / 1.618033988749895 | 0) % 2), r = 48 + 159 * ((n / 2.618033988749895 | 0) % 2)), p = (a * c - l * f - e * g) / 255, m = (o * c - u * f - t * g) / 255, h = (s * c - d * f - r * g) / 255;
611
+ }
612
+ let _ = p * .29889531 + m * .58662247 + h * .11448223, v = p * .59597799 - m * .2741761 - h * .32180189, y = p * .21147017 - m * .52261711 + h * .31114694, b = .5053 * _ * _ + .299 * v * v + .1957 * y * y;
613
+ return _ > 0 ? -b : b;
614
+ }
615
+ function xe(e, t, n, r, i, a, o, s) {
616
+ let c = e[n], l = e[n + 1], u = e[n + 2], d = e[n + 3], f = r - c, p = i - l, m = a - u, h = o - d;
617
+ if (!f && !p && !m && !h) return 0;
618
+ if (o < 255 || d < 255) {
619
+ let e = 255, n = 255, g = 255;
620
+ s && (e = 48 + t % 2 * 159, n = 48 + 159 * ((t / 1.618033988749895 | 0) % 2), g = 48 + 159 * ((t / 2.618033988749895 | 0) % 2)), f = (r * o - c * d - e * h) / 255, p = (i * o - l * d - n * h) / 255, m = (a * o - u * d - g * h) / 255;
621
+ }
622
+ return f * .29889531 + p * .58662247 + m * .11448223;
623
+ }
624
+ function W(e, t, n, r, i) {
625
+ e[t] = n, e[t + 1] = r, e[t + 2] = i, e[t + 3] = 255;
626
+ }
627
+ function G(e, t, n, r) {
628
+ let i = 255 + (e[t] * .29889531 + e[t + 1] * .58662247 + e[t + 2] * .11448223 - 255) * n * e[t + 3] / 255;
629
+ W(r, t, i, i, i);
630
+ }
631
+ //#endregion
632
+ //#region src/diff-aggregate.ts
633
+ var Se = 4;
634
+ function K(e, t, n) {
635
+ let r = new Uint8Array(t * n), i = [];
636
+ for (let a = 0; a < n; a++) for (let o = 0; o < t; o++) {
637
+ let s = a * t + o;
638
+ if (r[s] || !Ce(e, s)) continue;
639
+ let c = we(e, r, o, a, t, n);
640
+ c.count >= Se && i.push({
641
+ x: c.minX,
642
+ y: c.minY,
643
+ width: c.maxX - c.minX + 1,
644
+ height: c.maxY - c.minY + 1
645
+ });
646
+ }
647
+ return i;
648
+ }
649
+ function Ce(e, t) {
650
+ return e[t * 4 + 3] > 0;
651
+ }
652
+ function we(e, t, n, r, i, a) {
653
+ let o = {
654
+ count: 0,
655
+ minX: n,
656
+ minY: r,
657
+ maxX: n,
658
+ maxY: r
659
+ }, s = [n, r];
660
+ for (; s.length > 0;) {
661
+ let n = s.pop(), r = s.pop();
662
+ if (r < 0 || r >= i || n < 0 || n >= a) continue;
663
+ let c = n * i + r;
664
+ t[c] || Ce(e, c) && (t[c] = 1, o.count += 1, r < o.minX && (o.minX = r), n < o.minY && (o.minY = n), r > o.maxX && (o.maxX = r), n > o.maxY && (o.maxY = n), s.push(r + 1, n), s.push(r - 1, n), s.push(r, n + 1), s.push(r, n - 1));
665
+ }
666
+ return o;
667
+ }
668
+ //#endregion
669
+ //#region src/diff.ts
670
+ var Te = class extends Error {
671
+ constructor(e, t) {
672
+ super(`Cannot compare screenshots of different dimensions: before is ${e.width}×${e.height}, after is ${t.width}×${t.height}.`), this.name = "DimensionMismatchError";
673
+ }
674
+ };
675
+ async function Ee(e, t, r = {}) {
676
+ let [i, a] = await Promise.all([n(Buffer.from(e)), n(Buffer.from(t))]);
677
+ if (i.width !== a.width || i.height !== a.height) throw new Te({
678
+ width: i.width,
679
+ height: i.height
680
+ }, {
681
+ width: a.width,
682
+ height: a.height
683
+ });
684
+ let { width: o, height: s } = i, c = De(i, o, s), l = De(a, o, s), u = new Uint8Array(o * s * 4);
685
+ return {
686
+ mismatchedPixels: ye(c, l, u, o, s, {
687
+ threshold: r.threshold ?? .1,
688
+ includeAA: !1,
689
+ diffMask: !0
690
+ }),
691
+ regions: K(u, o, s),
692
+ width: o,
693
+ height: s
694
+ };
695
+ }
696
+ function De(e, n, r) {
697
+ let i = t(n, r).getContext("2d");
698
+ i.drawImage(e, 0, 0);
699
+ let a = i.getImageData(0, 0, n, r).data;
700
+ return new Uint8Array(a.buffer, a.byteOffset, a.byteLength);
701
+ }
702
+ //#endregion
703
+ //#region src/flatten-editable-png.ts
704
+ function Oe(e) {
705
+ return b(e);
706
+ }
707
+ //#endregion
522
708
  //#region src/dsl/schema.ts
523
- var U = {
709
+ var ke = {
524
710
  BBox: {
525
711
  type: "object",
526
712
  required: [
@@ -576,7 +762,7 @@ var U = {
576
762
  color: { type: "string" }
577
763
  }
578
764
  }
579
- }, W = { oneOf: [
765
+ }, Ae = { oneOf: [
580
766
  {
581
767
  type: "object",
582
768
  required: ["type", "bbox"],
@@ -731,6 +917,57 @@ var U = {
731
917
  color: { type: "string" }
732
918
  }
733
919
  },
920
+ {
921
+ type: "object",
922
+ required: ["type", "path"],
923
+ additionalProperties: !1,
924
+ properties: {
925
+ type: { const: "freehand" },
926
+ path: {
927
+ type: "string",
928
+ minLength: 1
929
+ },
930
+ intent: { $ref: "#/$defs/Intent" },
931
+ stroke: { type: "string" },
932
+ strokeWidth: {
933
+ type: "number",
934
+ minimum: 0
935
+ },
936
+ fill: { type: "string" },
937
+ color: { type: "string" }
938
+ }
939
+ },
940
+ {
941
+ type: "object",
942
+ required: [
943
+ "type",
944
+ "cutout",
945
+ "imageWidth",
946
+ "imageHeight"
947
+ ],
948
+ additionalProperties: !1,
949
+ properties: {
950
+ type: { const: "focusMask" },
951
+ cutout: { $ref: "#/$defs/BBox" },
952
+ imageWidth: {
953
+ type: "number",
954
+ minimum: 0
955
+ },
956
+ imageHeight: {
957
+ type: "number",
958
+ minimum: 0
959
+ },
960
+ dimColor: { type: "string" },
961
+ intent: { $ref: "#/$defs/Intent" },
962
+ stroke: { type: "string" },
963
+ strokeWidth: {
964
+ type: "number",
965
+ minimum: 0
966
+ },
967
+ fill: { type: "string" },
968
+ color: { type: "string" }
969
+ }
970
+ },
734
971
  {
735
972
  type: "object",
736
973
  required: ["type", "svgFragment"],
@@ -740,7 +977,7 @@ var U = {
740
977
  svgFragment: { type: "string" }
741
978
  }
742
979
  }
743
- ] }, G = {
980
+ ] }, je = {
744
981
  type: "object",
745
982
  required: ["bbox"],
746
983
  additionalProperties: !1,
@@ -759,31 +996,31 @@ var U = {
759
996
  };
760
997
  //#endregion
761
998
  //#region src/dsl/svg-primitives.ts
762
- function K(e, t = {}) {
999
+ function q(e, t = {}) {
763
1000
  let n = t.stroke ?? "red", r = t.strokeWidth ?? 2, i = t.fill ?? "none";
764
- return `<rect x="${e.x}" y="${e.y}" width="${e.width}" height="${e.height}" fill="${X(i)}" stroke="${X(n)}" stroke-width="${r}"/>`;
765
- }
766
- function q(e, t, n = {}) {
767
- let r = n.color ?? "red", i = n.strokeWidth ?? 2, a = `annot-arrow-${ce()}`;
768
- return `<defs><marker id="${a}" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto" markerUnits="strokeWidth"><path d="M 0 0 L 10 5 L 0 10 z" fill="${X(r)}"/></marker></defs><line x1="${e.x}" y1="${e.y}" x2="${t.x}" y2="${t.y}" stroke="${X(r)}" stroke-width="${i}" marker-end="url(#${a})"/>`;
1001
+ return `<rect x="${e.x}" y="${e.y}" width="${e.width}" height="${e.height}" fill="${Z(i)}" stroke="${Z(n)}" stroke-width="${r}"/>`;
769
1002
  }
770
1003
  function J(e, t, n = {}) {
1004
+ let r = n.color ?? "red", i = n.strokeWidth ?? 2, a = `annot-arrow-${Me()}`;
1005
+ return `<defs><marker id="${a}" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto" markerUnits="strokeWidth"><path d="M 0 0 L 10 5 L 0 10 z" fill="${Z(r)}"/></marker></defs><line x1="${e.x}" y1="${e.y}" x2="${t.x}" y2="${t.y}" stroke="${Z(r)}" stroke-width="${i}" marker-end="url(#${a})"/>`;
1006
+ }
1007
+ function Y(e, t, n = {}) {
771
1008
  let r = n.color ?? "red", i = n.fontSize ?? 14, a = n.anchor ?? "start";
772
- return `<text x="${e.x}" y="${e.y}" fill="${X(r)}" font-size="${i}" text-anchor="${a}">` + le(t) + "</text>";
1009
+ return `<text x="${e.x}" y="${e.y}" fill="${Z(r)}" font-size="${i}" text-anchor="${a}">` + Ne(t) + "</text>";
773
1010
  }
774
- var Y = 0;
775
- function ce() {
776
- return Y = Y + 1 | 0, Y;
1011
+ var X = 0;
1012
+ function Me() {
1013
+ return X = X + 1 | 0, X;
777
1014
  }
778
- function X(e) {
1015
+ function Z(e) {
779
1016
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
780
1017
  }
781
- function le(e) {
1018
+ function Ne(e) {
782
1019
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
783
1020
  }
784
1021
  //#endregion
785
1022
  //#region src/dsl/to-svg.ts
786
- var ue = {
1023
+ var Pe = {
787
1024
  info: {
788
1025
  stroke: "#3b82f6",
789
1026
  fill: "rgba(59, 130, 246, 0.12)",
@@ -809,84 +1046,95 @@ var ue = {
809
1046
  fill: "rgba(107, 114, 128, 0.12)",
810
1047
  text: "#374151"
811
1048
  }
812
- }, de = "error";
813
- function Z(e) {
814
- let t = ue[e.intent ?? de];
1049
+ }, Fe = "error";
1050
+ function Q(e) {
1051
+ let t = Pe[e.intent ?? Fe];
815
1052
  return {
816
1053
  stroke: e.stroke ?? t.stroke,
817
1054
  fill: e.fill ?? "none",
818
1055
  text: e.color ?? t.text
819
1056
  };
820
1057
  }
821
- function fe(e) {
822
- return e.map(pe).join("");
1058
+ function Ie(e) {
1059
+ return e.map(Le).join("");
823
1060
  }
824
- function pe(e) {
1061
+ function Le(e) {
825
1062
  switch (e.type) {
826
- case "rect": return me(e);
827
- case "circle": return he(e);
828
- case "arrow": return ge(e);
829
- case "text": return _e(e);
830
- case "callout": return ve(e);
831
- case "numberedBadge": return xe(e);
832
- case "raw": return ye(e);
833
- }
834
- }
835
- function me(e) {
836
- let t = Z(e);
837
- return K(e.bbox, {
1063
+ case "rect": return Re(e);
1064
+ case "circle": return ze(e);
1065
+ case "arrow": return Be(e);
1066
+ case "text": return Ve(e);
1067
+ case "callout": return He(e);
1068
+ case "numberedBadge": return Je(e);
1069
+ case "freehand": return We(e);
1070
+ case "focusMask": return Ke(e);
1071
+ case "raw": return Ue(e);
1072
+ }
1073
+ }
1074
+ function Re(e) {
1075
+ let t = Q(e);
1076
+ return q(e.bbox, {
838
1077
  stroke: t.stroke,
839
1078
  strokeWidth: e.strokeWidth ?? 2,
840
1079
  fill: t.fill
841
1080
  });
842
1081
  }
843
- function he(e) {
844
- let t = Z(e), n = e.strokeWidth ?? 2;
1082
+ function ze(e) {
1083
+ let t = Q(e), n = e.strokeWidth ?? 2;
845
1084
  return `<circle cx="${e.center.x}" cy="${e.center.y}" r="${e.radius}" fill="${$(t.fill)}" stroke="${$(t.stroke)}" stroke-width="${n}"/>`;
846
1085
  }
847
- function ge(e) {
848
- let t = Z(e);
849
- return q(e.from, e.to, {
1086
+ function Be(e) {
1087
+ let t = Q(e);
1088
+ return J(e.from, e.to, {
850
1089
  color: t.stroke,
851
1090
  strokeWidth: e.strokeWidth ?? 2
852
1091
  });
853
1092
  }
854
- function _e(e) {
855
- let t = Z(e);
856
- return J(e.at, e.content, {
1093
+ function Ve(e) {
1094
+ let t = Q(e);
1095
+ return Y(e.at, e.content, {
857
1096
  color: t.text,
858
1097
  fontSize: e.fontSize ?? 14,
859
1098
  anchor: e.anchor ?? "start"
860
1099
  });
861
1100
  }
862
- function ve(e) {
863
- let t = Z(e), n = e.targetBbox, r = we(n, e.at);
864
- return K(n, {
1101
+ function He(e) {
1102
+ let t = Q(e), n = e.targetBbox, r = Ze(n, e.at);
1103
+ return q(n, {
865
1104
  stroke: t.stroke,
866
1105
  strokeWidth: e.strokeWidth ?? 2,
867
1106
  fill: t.fill
868
- }) + q(e.at, r, {
1107
+ }) + J(e.at, r, {
869
1108
  color: t.stroke,
870
1109
  strokeWidth: 2
871
- }) + J(e.at, e.content, {
1110
+ }) + Y(e.at, e.content, {
872
1111
  color: t.text,
873
1112
  fontSize: 14,
874
1113
  anchor: "start"
875
1114
  });
876
1115
  }
877
- function ye(e) {
1116
+ function Ue(e) {
878
1117
  return e.svgFragment;
879
1118
  }
880
- var be = 40;
881
- function xe(e) {
882
- let t = Z(e), n = e.badgeSize ?? be, r = Se(e, n), i = K(e.bbox, {
1119
+ function We(e) {
1120
+ let t = Q(e), n = e.fill ?? "none", r = e.strokeWidth ?? 2;
1121
+ return `<path d="${$(e.path)}" fill="${$(n)}" stroke="${$(t.stroke)}" stroke-width="${r}" stroke-linecap="round" stroke-linejoin="round"/>`;
1122
+ }
1123
+ var Ge = "rgba(0,0,0,0.5)";
1124
+ function Ke(e) {
1125
+ let { cutout: t, imageWidth: n, imageHeight: r } = e, i = e.dimColor ?? Ge;
1126
+ return `<path d="${$(`M0,0 H${n} V${r} H0 Z M${t.x},${t.y} H${t.x + t.width} V${t.y + t.height} H${t.x} Z`)}" fill="${$(i)}" fill-rule="evenodd" stroke="none"/>`;
1127
+ }
1128
+ var qe = 40;
1129
+ function Je(e) {
1130
+ let t = Q(e), n = e.badgeSize ?? qe, r = Ye(e, n), i = q(e.bbox, {
883
1131
  stroke: t.stroke,
884
1132
  strokeWidth: e.strokeWidth ?? 3,
885
1133
  fill: e.fill ?? "none"
886
- }), a = Ce(e.bbox, r), o = n / 2, s = `<circle cx="${a.x}" cy="${a.y}" r="${o}" fill="${t.stroke}" stroke="#ffffff" stroke-width="${Math.max(2, o * .12)}" />`, c = Math.round(o * 1.1), l = `<text x="${a.x}" y="${a.y}" font-family="-apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif" font-size="${c}" font-weight="700" fill="#ffffff" text-anchor="middle" dominant-baseline="central">${$(String(e.number))}</text>`;
1134
+ }), a = Xe(e.bbox, r), o = n / 2, s = `<circle cx="${a.x}" cy="${a.y}" r="${o}" fill="${t.stroke}" stroke="#ffffff" stroke-width="${Math.max(2, o * .12)}" />`, c = Math.round(o * 1.1), l = `<text x="${a.x}" y="${a.y}" font-family="-apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif" font-size="${c}" font-weight="700" fill="#ffffff" text-anchor="middle" dominant-baseline="central">${$(String(e.number))}</text>`;
887
1135
  return i + s + l;
888
1136
  }
889
- function Se(e, t) {
1137
+ function Ye(e, t) {
890
1138
  if (e.placement && e.placement !== "auto") return e.placement;
891
1139
  if (e.imageWidth === void 0 || e.imageHeight === void 0) return "topRight";
892
1140
  let n = t / 2, r = [
@@ -917,7 +1165,7 @@ function Se(e, t) {
917
1165
  }
918
1166
  return i.kind;
919
1167
  }
920
- function Ce(e, t) {
1168
+ function Xe(e, t) {
921
1169
  switch (t) {
922
1170
  case "topLeft": return {
923
1171
  x: e.x,
@@ -937,17 +1185,17 @@ function Ce(e, t) {
937
1185
  };
938
1186
  }
939
1187
  }
940
- function we(e, t) {
1188
+ function Ze(e, t) {
941
1189
  return {
942
- x: Q(t.x, e.x, e.x + e.width),
943
- y: Q(t.y, e.y, e.y + e.height)
1190
+ x: Qe(t.x, e.x, e.x + e.width),
1191
+ y: Qe(t.y, e.y, e.y + e.height)
944
1192
  };
945
1193
  }
946
- function Q(e, t, n) {
1194
+ function Qe(e, t, n) {
947
1195
  return Math.min(Math.max(e, t), n);
948
1196
  }
949
1197
  function $(e) {
950
1198
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
951
1199
  }
952
1200
  //#endregion
953
- export { W as BBOX_ANNOTATION_SCHEMA, G as BBOX_REDACT_REGION_SCHEMA, T as DEFAULT_ENCODE_OPTIONS, w as SAVE_SIZE_LABEL, C as SAVE_SIZE_MAX_WIDTH, U as SHARED_DEFS, q as arrowBetween, fe as bboxAnnotationsToSvg, E as computeResizeTarget, V as createAnnotator, ie as decodeAndEncodeImage, R as encodeRgba, L as isPhotoHeavy, K as rectForBoundingBox, J as textAt };
1201
+ export { Ae as BBOX_ANNOTATION_SCHEMA, je as BBOX_REDACT_REGION_SCHEMA, T as DEFAULT_ENCODE_OPTIONS, Te as DimensionMismatchError, w as SAVE_SIZE_LABEL, C as SAVE_SIZE_MAX_WIDTH, ke as SHARED_DEFS, K as aggregateDiffRegions, J as arrowBetween, Ie as bboxAnnotationsToSvg, B as burnRedactions, ve as burnRegions, E as computeResizeTarget, de as createAnnotator, se as decodeAndEncodeImage, Ee as diffScreenshots, F as encodeRgba, Oe as flattenEditablePng, P as isPhotoHeavy, q as rectForBoundingBox, Y as textAt };