@tscircuit/cli 0.1.1142 → 0.1.1144

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/cli/main.js CHANGED
@@ -124180,7 +124180,7 @@ var import_perfect_cli = __toESM2(require_dist2(), 1);
124180
124180
  // lib/getVersion.ts
124181
124181
  import { createRequire as createRequire2 } from "node:module";
124182
124182
  // package.json
124183
- var version = "0.1.1141";
124183
+ var version = "0.1.1143";
124184
124184
  var package_default = {
124185
124185
  name: "@tscircuit/cli",
124186
124186
  version,
@@ -124196,6 +124196,7 @@ var package_default = {
124196
124196
  "@tscircuit/circuit-json-routing-analysis": "^0.0.1",
124197
124197
  "@tscircuit/fake-snippets": "^0.0.182",
124198
124198
  "@tscircuit/file-server": "^0.0.32",
124199
+ "@tscircuit/image-utils": "^0.0.3",
124199
124200
  "@tscircuit/math-utils": "0.0.36",
124200
124201
  "@tscircuit/props": "^0.0.496",
124201
124202
  "@tscircuit/runframe": "^0.0.1748",
@@ -124234,7 +124235,6 @@ var package_default = {
124234
124235
  kicadts: "^0.0.24",
124235
124236
  kleur: "^4.1.5",
124236
124237
  ky: "^1.7.4",
124237
- "looks-same": "^9.0.1",
124238
124238
  "make-vfs": "^1.0.15",
124239
124239
  md5: "^2.3.0",
124240
124240
  "perfect-cli": "^1.0.21",
@@ -124243,7 +124243,6 @@ var package_default = {
124243
124243
  prompts: "^2.4.2",
124244
124244
  redaxios: "^0.5.1",
124245
124245
  semver: "^7.6.3",
124246
- sharp: "0.32.6",
124247
124246
  tempy: "^3.1.0",
124248
124247
  tscircuit: "0.0.1519-libonly",
124249
124248
  tsx: "^4.7.1",
@@ -375417,17 +375416,2708 @@ import {
375417
375416
  } from "circuit-to-svg";
375418
375417
  import { renderGLTFToPNGBufferFromGLBBuffer as renderGLTFToPNGBufferFromGLBBuffer2 } from "poppygl";
375419
375418
 
375419
+ // node_modules/@tscircuit/image-utils/dist/looks-same.js
375420
+ import { readFile, writeFile } from "fs/promises";
375421
+
375422
+ // node_modules/color-diff/lib/convert.js
375423
+ function rgbaToLab(c4, bc3) {
375424
+ bc3 = normalize8(bc3 || { R: 255, G: 255, B: 255 });
375425
+ c4 = normalize8(c4);
375426
+ let newC = c4;
375427
+ if (c4.A !== undefined) {
375428
+ newC = {
375429
+ R: bc3.R + (c4.R - bc3.R) * c4.A,
375430
+ G: bc3.G + (c4.G - bc3.G) * c4.A,
375431
+ B: bc3.B + (c4.B - bc3.B) * c4.A
375432
+ };
375433
+ }
375434
+ return xyzToLab(rgbToXyz(newC));
375435
+ }
375436
+ function rgbToXyz(c4) {
375437
+ let R5 = c4.R / 255;
375438
+ let G4 = c4.G / 255;
375439
+ let B4 = c4.B / 255;
375440
+ if (R5 > 0.04045)
375441
+ R5 = Math.pow((R5 + 0.055) / 1.055, 2.4);
375442
+ else
375443
+ R5 = R5 / 12.92;
375444
+ if (G4 > 0.04045)
375445
+ G4 = Math.pow((G4 + 0.055) / 1.055, 2.4);
375446
+ else
375447
+ G4 = G4 / 12.92;
375448
+ if (B4 > 0.04045)
375449
+ B4 = Math.pow((B4 + 0.055) / 1.055, 2.4);
375450
+ else
375451
+ B4 = B4 / 12.92;
375452
+ R5 *= 100;
375453
+ G4 *= 100;
375454
+ B4 *= 100;
375455
+ const X4 = R5 * 0.4124 + G4 * 0.3576 + B4 * 0.1805;
375456
+ const Y4 = R5 * 0.2126 + G4 * 0.7152 + B4 * 0.0722;
375457
+ const Z7 = R5 * 0.0193 + G4 * 0.1192 + B4 * 0.9505;
375458
+ return { X: X4, Y: Y4, Z: Z7 };
375459
+ }
375460
+ function xyzToLab(c4) {
375461
+ const refY = 100;
375462
+ const refZ = 108.883;
375463
+ const refX = 95.047;
375464
+ let Y4 = c4.Y / refY;
375465
+ let Z7 = c4.Z / refZ;
375466
+ let X4 = c4.X / refX;
375467
+ if (X4 > 0.008856)
375468
+ X4 = Math.pow(X4, 1 / 3);
375469
+ else
375470
+ X4 = 7.787 * X4 + 16 / 116;
375471
+ if (Y4 > 0.008856)
375472
+ Y4 = Math.pow(Y4, 1 / 3);
375473
+ else
375474
+ Y4 = 7.787 * Y4 + 16 / 116;
375475
+ if (Z7 > 0.008856)
375476
+ Z7 = Math.pow(Z7, 1 / 3);
375477
+ else
375478
+ Z7 = 7.787 * Z7 + 16 / 116;
375479
+ const L5 = 116 * Y4 - 16;
375480
+ const a3 = 500 * (X4 - Y4);
375481
+ const b = 200 * (Y4 - Z7);
375482
+ return { L: L5, a: a3, b };
375483
+ }
375484
+ function normalize8(c4) {
375485
+ let r4, g8, b, a3;
375486
+ if ("R" in c4) {
375487
+ r4 = c4.R;
375488
+ g8 = c4.G;
375489
+ b = c4.B;
375490
+ a3 = c4.A;
375491
+ } else {
375492
+ r4 = c4.r;
375493
+ g8 = c4.g;
375494
+ b = c4.b;
375495
+ a3 = c4.a;
375496
+ }
375497
+ const normalizedC = { R: r4, G: g8, B: b };
375498
+ if (a3 !== undefined)
375499
+ normalizedC.A = a3;
375500
+ return normalizedC;
375501
+ }
375502
+
375503
+ // node_modules/color-diff/lib/diff.js
375504
+ function ciede2000(c13, c23, bc3) {
375505
+ if ("R" in c13 || "r" in c13) {
375506
+ c13 = rgbaToLab(c13, bc3);
375507
+ }
375508
+ if ("R" in c23 || "r" in c23) {
375509
+ c23 = rgbaToLab(c23, bc3);
375510
+ }
375511
+ const L13 = c13.L;
375512
+ const a13 = c13.a;
375513
+ const b13 = c13.b;
375514
+ const L24 = c23.L;
375515
+ const a22 = c23.a;
375516
+ const b23 = c23.b;
375517
+ const kL = 1;
375518
+ const kC = 1;
375519
+ const kH = 1;
375520
+ const C13 = Math.sqrt(Math.pow(a13, 2) + Math.pow(b13, 2));
375521
+ const C23 = Math.sqrt(Math.pow(a22, 2) + Math.pow(b23, 2));
375522
+ const aC1C2 = (C13 + C23) / 2;
375523
+ const G4 = 0.5 * (1 - Math.sqrt(Math.pow(aC1C2, 7) / (Math.pow(aC1C2, 7) + Math.pow(25, 7))));
375524
+ const a1p = (1 + G4) * a13;
375525
+ const a2p = (1 + G4) * a22;
375526
+ const C1p = Math.sqrt(Math.pow(a1p, 2) + Math.pow(b13, 2));
375527
+ const C2p = Math.sqrt(Math.pow(a2p, 2) + Math.pow(b23, 2));
375528
+ const h1p = hpF(b13, a1p);
375529
+ const h2p = hpF(b23, a2p);
375530
+ const dLp = L24 - L13;
375531
+ const dCp = C2p - C1p;
375532
+ const dhp = dhpF(C13, C23, h1p, h2p);
375533
+ const dHp = 2 * Math.sqrt(C1p * C2p) * Math.sin(radians(dhp) / 2);
375534
+ const aL = (L13 + L24) / 2;
375535
+ const aCp = (C1p + C2p) / 2;
375536
+ const aHp = aHpF(C13, C23, h1p, h2p);
375537
+ const T4 = 1 - 0.17 * Math.cos(radians(aHp - 30)) + 0.24 * Math.cos(radians(2 * aHp)) + 0.32 * Math.cos(radians(3 * aHp + 6)) - 0.2 * Math.cos(radians(4 * aHp - 63));
375538
+ const dRo = 30 * Math.exp(-Math.pow((aHp - 275) / 25, 2));
375539
+ const RC = Math.sqrt(Math.pow(aCp, 7) / (Math.pow(aCp, 7) + Math.pow(25, 7)));
375540
+ const SL = 1 + 0.015 * Math.pow(aL - 50, 2) / Math.sqrt(20 + Math.pow(aL - 50, 2));
375541
+ const SC = 1 + 0.045 * aCp;
375542
+ const SH = 1 + 0.015 * aCp * T4;
375543
+ const RT = -2 * RC * Math.sin(radians(2 * dRo));
375544
+ const dE = Math.sqrt(Math.pow(dLp / (SL * kL), 2) + Math.pow(dCp / (SC * kC), 2) + Math.pow(dHp / (SH * kH), 2) + RT * (dCp / (SC * kC)) * (dHp / (SH * kH)));
375545
+ return dE;
375546
+ }
375547
+ function degrees(n4) {
375548
+ return n4 * (180 / Math.PI);
375549
+ }
375550
+ function radians(n4) {
375551
+ return n4 * (Math.PI / 180);
375552
+ }
375553
+ function hpF(x4, y5) {
375554
+ if (x4 === 0 && y5 === 0)
375555
+ return 0;
375556
+ else {
375557
+ const tmphp = degrees(Math.atan2(x4, y5));
375558
+ if (tmphp >= 0)
375559
+ return tmphp;
375560
+ else
375561
+ return tmphp + 360;
375562
+ }
375563
+ }
375564
+ function dhpF(C13, C23, h1p, h2p) {
375565
+ if (C13 * C23 === 0)
375566
+ return 0;
375567
+ else if (Math.abs(h2p - h1p) <= 180)
375568
+ return h2p - h1p;
375569
+ else if (h2p - h1p > 180)
375570
+ return h2p - h1p - 360;
375571
+ else if (h2p - h1p < -180)
375572
+ return h2p - h1p + 360;
375573
+ else
375574
+ throw new Error;
375575
+ }
375576
+ function aHpF(C13, C23, h1p, h2p) {
375577
+ if (C13 * C23 === 0)
375578
+ return h1p + h2p;
375579
+ else if (Math.abs(h1p - h2p) <= 180)
375580
+ return (h1p + h2p) / 2;
375581
+ else if (Math.abs(h1p - h2p) > 180 && h1p + h2p < 360)
375582
+ return (h1p + h2p + 360) / 2;
375583
+ else if (Math.abs(h1p - h2p) > 180 && h1p + h2p >= 360)
375584
+ return (h1p + h2p - 360) / 2;
375585
+ else
375586
+ throw new Error;
375587
+ }
375588
+
375589
+ // node_modules/color-diff/index.js
375590
+ function rgb_to_lab(c4) {
375591
+ return rgbaToLab(c4);
375592
+ }
375593
+
375594
+ // node_modules/fflate/esm/index.mjs
375595
+ import { createRequire as createRequire4 } from "module";
375596
+ var require3 = createRequire4("/");
375597
+ var Worker2;
375598
+ try {
375599
+ Worker2 = require3("worker_threads").Worker;
375600
+ } catch (e5) {}
375601
+ var u8 = Uint8Array;
375602
+ var u16 = Uint16Array;
375603
+ var i32 = Int32Array;
375604
+ var fleb = new u8([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 0, 0]);
375605
+ var fdeb = new u8([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 0, 0]);
375606
+ var clim = new u8([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
375607
+ var freb = function(eb, start) {
375608
+ var b = new u16(31);
375609
+ for (var i3 = 0;i3 < 31; ++i3) {
375610
+ b[i3] = start += 1 << eb[i3 - 1];
375611
+ }
375612
+ var r4 = new i32(b[30]);
375613
+ for (var i3 = 1;i3 < 30; ++i3) {
375614
+ for (var j5 = b[i3];j5 < b[i3 + 1]; ++j5) {
375615
+ r4[j5] = j5 - b[i3] << 5 | i3;
375616
+ }
375617
+ }
375618
+ return { b, r: r4 };
375619
+ };
375620
+ var _a5 = freb(fleb, 2);
375621
+ var fl5 = _a5.b;
375622
+ var revfl = _a5.r;
375623
+ fl5[28] = 258, revfl[258] = 28;
375624
+ var _b3 = freb(fdeb, 0);
375625
+ var fd5 = _b3.b;
375626
+ var revfd = _b3.r;
375627
+ var rev = new u16(32768);
375628
+ for (i3 = 0;i3 < 32768; ++i3) {
375629
+ x5 = (i3 & 43690) >> 1 | (i3 & 21845) << 1;
375630
+ x5 = (x5 & 52428) >> 2 | (x5 & 13107) << 2;
375631
+ x5 = (x5 & 61680) >> 4 | (x5 & 3855) << 4;
375632
+ rev[i3] = ((x5 & 65280) >> 8 | (x5 & 255) << 8) >> 1;
375633
+ }
375634
+ var x5;
375635
+ var i3;
375636
+ var hMap = function(cd5, mb3, r4) {
375637
+ var s3 = cd5.length;
375638
+ var i4 = 0;
375639
+ var l4 = new u16(mb3);
375640
+ for (;i4 < s3; ++i4) {
375641
+ if (cd5[i4])
375642
+ ++l4[cd5[i4] - 1];
375643
+ }
375644
+ var le5 = new u16(mb3);
375645
+ for (i4 = 1;i4 < mb3; ++i4) {
375646
+ le5[i4] = le5[i4 - 1] + l4[i4 - 1] << 1;
375647
+ }
375648
+ var co5;
375649
+ if (r4) {
375650
+ co5 = new u16(1 << mb3);
375651
+ var rvb = 15 - mb3;
375652
+ for (i4 = 0;i4 < s3; ++i4) {
375653
+ if (cd5[i4]) {
375654
+ var sv = i4 << 4 | cd5[i4];
375655
+ var r_1 = mb3 - cd5[i4];
375656
+ var v4 = le5[cd5[i4] - 1]++ << r_1;
375657
+ for (var m4 = v4 | (1 << r_1) - 1;v4 <= m4; ++v4) {
375658
+ co5[rev[v4] >> rvb] = sv;
375659
+ }
375660
+ }
375661
+ }
375662
+ } else {
375663
+ co5 = new u16(s3);
375664
+ for (i4 = 0;i4 < s3; ++i4) {
375665
+ if (cd5[i4]) {
375666
+ co5[i4] = rev[le5[cd5[i4] - 1]++] >> 15 - cd5[i4];
375667
+ }
375668
+ }
375669
+ }
375670
+ return co5;
375671
+ };
375672
+ var flt = new u8(288);
375673
+ for (i3 = 0;i3 < 144; ++i3)
375674
+ flt[i3] = 8;
375675
+ var i3;
375676
+ for (i3 = 144;i3 < 256; ++i3)
375677
+ flt[i3] = 9;
375678
+ var i3;
375679
+ for (i3 = 256;i3 < 280; ++i3)
375680
+ flt[i3] = 7;
375681
+ var i3;
375682
+ for (i3 = 280;i3 < 288; ++i3)
375683
+ flt[i3] = 8;
375684
+ var i3;
375685
+ var fdt = new u8(32);
375686
+ for (i3 = 0;i3 < 32; ++i3)
375687
+ fdt[i3] = 5;
375688
+ var i3;
375689
+ var flm = /* @__PURE__ */ hMap(flt, 9, 0);
375690
+ var flrm = /* @__PURE__ */ hMap(flt, 9, 1);
375691
+ var fdm = /* @__PURE__ */ hMap(fdt, 5, 0);
375692
+ var fdrm = /* @__PURE__ */ hMap(fdt, 5, 1);
375693
+ var max = function(a3) {
375694
+ var m4 = a3[0];
375695
+ for (var i4 = 1;i4 < a3.length; ++i4) {
375696
+ if (a3[i4] > m4)
375697
+ m4 = a3[i4];
375698
+ }
375699
+ return m4;
375700
+ };
375701
+ var bits = function(d4, p4, m4) {
375702
+ var o4 = p4 / 8 | 0;
375703
+ return (d4[o4] | d4[o4 + 1] << 8) >> (p4 & 7) & m4;
375704
+ };
375705
+ var bits16 = function(d4, p4) {
375706
+ var o4 = p4 / 8 | 0;
375707
+ return (d4[o4] | d4[o4 + 1] << 8 | d4[o4 + 2] << 16) >> (p4 & 7);
375708
+ };
375709
+ var shft = function(p4) {
375710
+ return (p4 + 7) / 8 | 0;
375711
+ };
375712
+ var slc = function(v4, s3, e5) {
375713
+ if (s3 == null || s3 < 0)
375714
+ s3 = 0;
375715
+ if (e5 == null || e5 > v4.length)
375716
+ e5 = v4.length;
375717
+ return new u8(v4.subarray(s3, e5));
375718
+ };
375719
+ var ec3 = [
375720
+ "unexpected EOF",
375721
+ "invalid block type",
375722
+ "invalid length/literal",
375723
+ "invalid distance",
375724
+ "stream finished",
375725
+ "no stream handler",
375726
+ ,
375727
+ "no callback",
375728
+ "invalid UTF-8 data",
375729
+ "extra field too long",
375730
+ "date not in range 1980-2099",
375731
+ "filename too long",
375732
+ "stream finishing",
375733
+ "invalid zip data"
375734
+ ];
375735
+ var err = function(ind, msg, nt5) {
375736
+ var e5 = new Error(msg || ec3[ind]);
375737
+ e5.code = ind;
375738
+ if (Error.captureStackTrace)
375739
+ Error.captureStackTrace(e5, err);
375740
+ if (!nt5)
375741
+ throw e5;
375742
+ return e5;
375743
+ };
375744
+ var inflt = function(dat, st5, buf, dict) {
375745
+ var sl5 = dat.length, dl5 = dict ? dict.length : 0;
375746
+ if (!sl5 || st5.f && !st5.l)
375747
+ return buf || new u8(0);
375748
+ var noBuf = !buf;
375749
+ var resize = noBuf || st5.i != 2;
375750
+ var noSt = st5.i;
375751
+ if (noBuf)
375752
+ buf = new u8(sl5 * 3);
375753
+ var cbuf = function(l5) {
375754
+ var bl5 = buf.length;
375755
+ if (l5 > bl5) {
375756
+ var nbuf = new u8(Math.max(bl5 * 2, l5));
375757
+ nbuf.set(buf);
375758
+ buf = nbuf;
375759
+ }
375760
+ };
375761
+ var final = st5.f || 0, pos = st5.p || 0, bt4 = st5.b || 0, lm3 = st5.l, dm3 = st5.d, lbt = st5.m, dbt = st5.n;
375762
+ var tbts = sl5 * 8;
375763
+ do {
375764
+ if (!lm3) {
375765
+ final = bits(dat, pos, 1);
375766
+ var type = bits(dat, pos + 1, 3);
375767
+ pos += 3;
375768
+ if (!type) {
375769
+ var s3 = shft(pos) + 4, l4 = dat[s3 - 4] | dat[s3 - 3] << 8, t19 = s3 + l4;
375770
+ if (t19 > sl5) {
375771
+ if (noSt)
375772
+ err(0);
375773
+ break;
375774
+ }
375775
+ if (resize)
375776
+ cbuf(bt4 + l4);
375777
+ buf.set(dat.subarray(s3, t19), bt4);
375778
+ st5.b = bt4 += l4, st5.p = pos = t19 * 8, st5.f = final;
375779
+ continue;
375780
+ } else if (type == 1)
375781
+ lm3 = flrm, dm3 = fdrm, lbt = 9, dbt = 5;
375782
+ else if (type == 2) {
375783
+ var hLit = bits(dat, pos, 31) + 257, hcLen = bits(dat, pos + 10, 15) + 4;
375784
+ var tl5 = hLit + bits(dat, pos + 5, 31) + 1;
375785
+ pos += 14;
375786
+ var ldt = new u8(tl5);
375787
+ var clt = new u8(19);
375788
+ for (var i4 = 0;i4 < hcLen; ++i4) {
375789
+ clt[clim[i4]] = bits(dat, pos + i4 * 3, 7);
375790
+ }
375791
+ pos += hcLen * 3;
375792
+ var clb = max(clt), clbmsk = (1 << clb) - 1;
375793
+ var clm = hMap(clt, clb, 1);
375794
+ for (var i4 = 0;i4 < tl5; ) {
375795
+ var r4 = clm[bits(dat, pos, clbmsk)];
375796
+ pos += r4 & 15;
375797
+ var s3 = r4 >> 4;
375798
+ if (s3 < 16) {
375799
+ ldt[i4++] = s3;
375800
+ } else {
375801
+ var c4 = 0, n4 = 0;
375802
+ if (s3 == 16)
375803
+ n4 = 3 + bits(dat, pos, 3), pos += 2, c4 = ldt[i4 - 1];
375804
+ else if (s3 == 17)
375805
+ n4 = 3 + bits(dat, pos, 7), pos += 3;
375806
+ else if (s3 == 18)
375807
+ n4 = 11 + bits(dat, pos, 127), pos += 7;
375808
+ while (n4--)
375809
+ ldt[i4++] = c4;
375810
+ }
375811
+ }
375812
+ var lt5 = ldt.subarray(0, hLit), dt5 = ldt.subarray(hLit);
375813
+ lbt = max(lt5);
375814
+ dbt = max(dt5);
375815
+ lm3 = hMap(lt5, lbt, 1);
375816
+ dm3 = hMap(dt5, dbt, 1);
375817
+ } else
375818
+ err(1);
375819
+ if (pos > tbts) {
375820
+ if (noSt)
375821
+ err(0);
375822
+ break;
375823
+ }
375824
+ }
375825
+ if (resize)
375826
+ cbuf(bt4 + 131072);
375827
+ var lms = (1 << lbt) - 1, dms = (1 << dbt) - 1;
375828
+ var lpos = pos;
375829
+ for (;; lpos = pos) {
375830
+ var c4 = lm3[bits16(dat, pos) & lms], sym = c4 >> 4;
375831
+ pos += c4 & 15;
375832
+ if (pos > tbts) {
375833
+ if (noSt)
375834
+ err(0);
375835
+ break;
375836
+ }
375837
+ if (!c4)
375838
+ err(2);
375839
+ if (sym < 256)
375840
+ buf[bt4++] = sym;
375841
+ else if (sym == 256) {
375842
+ lpos = pos, lm3 = null;
375843
+ break;
375844
+ } else {
375845
+ var add = sym - 254;
375846
+ if (sym > 264) {
375847
+ var i4 = sym - 257, b = fleb[i4];
375848
+ add = bits(dat, pos, (1 << b) - 1) + fl5[i4];
375849
+ pos += b;
375850
+ }
375851
+ var d4 = dm3[bits16(dat, pos) & dms], dsym = d4 >> 4;
375852
+ if (!d4)
375853
+ err(3);
375854
+ pos += d4 & 15;
375855
+ var dt5 = fd5[dsym];
375856
+ if (dsym > 3) {
375857
+ var b = fdeb[dsym];
375858
+ dt5 += bits16(dat, pos) & (1 << b) - 1, pos += b;
375859
+ }
375860
+ if (pos > tbts) {
375861
+ if (noSt)
375862
+ err(0);
375863
+ break;
375864
+ }
375865
+ if (resize)
375866
+ cbuf(bt4 + 131072);
375867
+ var end = bt4 + add;
375868
+ if (bt4 < dt5) {
375869
+ var shift = dl5 - dt5, dend = Math.min(dt5, end);
375870
+ if (shift + bt4 < 0)
375871
+ err(3);
375872
+ for (;bt4 < dend; ++bt4)
375873
+ buf[bt4] = dict[shift + bt4];
375874
+ }
375875
+ for (;bt4 < end; ++bt4)
375876
+ buf[bt4] = buf[bt4 - dt5];
375877
+ }
375878
+ }
375879
+ st5.l = lm3, st5.p = lpos, st5.b = bt4, st5.f = final;
375880
+ if (lm3)
375881
+ final = 1, st5.m = lbt, st5.d = dm3, st5.n = dbt;
375882
+ } while (!final);
375883
+ return bt4 != buf.length && noBuf ? slc(buf, 0, bt4) : buf.subarray(0, bt4);
375884
+ };
375885
+ var wbits = function(d4, p4, v4) {
375886
+ v4 <<= p4 & 7;
375887
+ var o4 = p4 / 8 | 0;
375888
+ d4[o4] |= v4;
375889
+ d4[o4 + 1] |= v4 >> 8;
375890
+ };
375891
+ var wbits16 = function(d4, p4, v4) {
375892
+ v4 <<= p4 & 7;
375893
+ var o4 = p4 / 8 | 0;
375894
+ d4[o4] |= v4;
375895
+ d4[o4 + 1] |= v4 >> 8;
375896
+ d4[o4 + 2] |= v4 >> 16;
375897
+ };
375898
+ var hTree = function(d4, mb3) {
375899
+ var t19 = [];
375900
+ for (var i4 = 0;i4 < d4.length; ++i4) {
375901
+ if (d4[i4])
375902
+ t19.push({ s: i4, f: d4[i4] });
375903
+ }
375904
+ var s3 = t19.length;
375905
+ var t25 = t19.slice();
375906
+ if (!s3)
375907
+ return { t: et5, l: 0 };
375908
+ if (s3 == 1) {
375909
+ var v4 = new u8(t19[0].s + 1);
375910
+ v4[t19[0].s] = 1;
375911
+ return { t: v4, l: 1 };
375912
+ }
375913
+ t19.sort(function(a3, b) {
375914
+ return a3.f - b.f;
375915
+ });
375916
+ t19.push({ s: -1, f: 25001 });
375917
+ var l4 = t19[0], r4 = t19[1], i03 = 0, i13 = 1, i22 = 2;
375918
+ t19[0] = { s: -1, f: l4.f + r4.f, l: l4, r: r4 };
375919
+ while (i13 != s3 - 1) {
375920
+ l4 = t19[t19[i03].f < t19[i22].f ? i03++ : i22++];
375921
+ r4 = t19[i03 != i13 && t19[i03].f < t19[i22].f ? i03++ : i22++];
375922
+ t19[i13++] = { s: -1, f: l4.f + r4.f, l: l4, r: r4 };
375923
+ }
375924
+ var maxSym = t25[0].s;
375925
+ for (var i4 = 1;i4 < s3; ++i4) {
375926
+ if (t25[i4].s > maxSym)
375927
+ maxSym = t25[i4].s;
375928
+ }
375929
+ var tr5 = new u16(maxSym + 1);
375930
+ var mbt = ln5(t19[i13 - 1], tr5, 0);
375931
+ if (mbt > mb3) {
375932
+ var i4 = 0, dt5 = 0;
375933
+ var lft = mbt - mb3, cst = 1 << lft;
375934
+ t25.sort(function(a3, b) {
375935
+ return tr5[b.s] - tr5[a3.s] || a3.f - b.f;
375936
+ });
375937
+ for (;i4 < s3; ++i4) {
375938
+ var i2_1 = t25[i4].s;
375939
+ if (tr5[i2_1] > mb3) {
375940
+ dt5 += cst - (1 << mbt - tr5[i2_1]);
375941
+ tr5[i2_1] = mb3;
375942
+ } else
375943
+ break;
375944
+ }
375945
+ dt5 >>= lft;
375946
+ while (dt5 > 0) {
375947
+ var i2_2 = t25[i4].s;
375948
+ if (tr5[i2_2] < mb3)
375949
+ dt5 -= 1 << mb3 - tr5[i2_2]++ - 1;
375950
+ else
375951
+ ++i4;
375952
+ }
375953
+ for (;i4 >= 0 && dt5; --i4) {
375954
+ var i2_3 = t25[i4].s;
375955
+ if (tr5[i2_3] == mb3) {
375956
+ --tr5[i2_3];
375957
+ ++dt5;
375958
+ }
375959
+ }
375960
+ mbt = mb3;
375961
+ }
375962
+ return { t: new u8(tr5), l: mbt };
375963
+ };
375964
+ var ln5 = function(n4, l4, d4) {
375965
+ return n4.s == -1 ? Math.max(ln5(n4.l, l4, d4 + 1), ln5(n4.r, l4, d4 + 1)) : l4[n4.s] = d4;
375966
+ };
375967
+ var lc5 = function(c4) {
375968
+ var s3 = c4.length;
375969
+ while (s3 && !c4[--s3])
375970
+ ;
375971
+ var cl5 = new u16(++s3);
375972
+ var cli = 0, cln = c4[0], cls = 1;
375973
+ var w4 = function(v4) {
375974
+ cl5[cli++] = v4;
375975
+ };
375976
+ for (var i4 = 1;i4 <= s3; ++i4) {
375977
+ if (c4[i4] == cln && i4 != s3)
375978
+ ++cls;
375979
+ else {
375980
+ if (!cln && cls > 2) {
375981
+ for (;cls > 138; cls -= 138)
375982
+ w4(32754);
375983
+ if (cls > 2) {
375984
+ w4(cls > 10 ? cls - 11 << 5 | 28690 : cls - 3 << 5 | 12305);
375985
+ cls = 0;
375986
+ }
375987
+ } else if (cls > 3) {
375988
+ w4(cln), --cls;
375989
+ for (;cls > 6; cls -= 6)
375990
+ w4(8304);
375991
+ if (cls > 2)
375992
+ w4(cls - 3 << 5 | 8208), cls = 0;
375993
+ }
375994
+ while (cls--)
375995
+ w4(cln);
375996
+ cls = 1;
375997
+ cln = c4[i4];
375998
+ }
375999
+ }
376000
+ return { c: cl5.subarray(0, cli), n: s3 };
376001
+ };
376002
+ var clen = function(cf4, cl5) {
376003
+ var l4 = 0;
376004
+ for (var i4 = 0;i4 < cl5.length; ++i4)
376005
+ l4 += cf4[i4] * cl5[i4];
376006
+ return l4;
376007
+ };
376008
+ var wfblk = function(out, pos, dat) {
376009
+ var s3 = dat.length;
376010
+ var o4 = shft(pos + 2);
376011
+ out[o4] = s3 & 255;
376012
+ out[o4 + 1] = s3 >> 8;
376013
+ out[o4 + 2] = out[o4] ^ 255;
376014
+ out[o4 + 3] = out[o4 + 1] ^ 255;
376015
+ for (var i4 = 0;i4 < s3; ++i4)
376016
+ out[o4 + i4 + 4] = dat[i4];
376017
+ return (o4 + 4 + s3) * 8;
376018
+ };
376019
+ var wblk = function(dat, out, final, syms, lf4, df4, eb, li5, bs5, bl5, p4) {
376020
+ wbits(out, p4++, final);
376021
+ ++lf4[256];
376022
+ var _a6 = hTree(lf4, 15), dlt = _a6.t, mlb = _a6.l;
376023
+ var _b4 = hTree(df4, 15), ddt = _b4.t, mdb = _b4.l;
376024
+ var _c5 = lc5(dlt), lclt = _c5.c, nlc = _c5.n;
376025
+ var _d5 = lc5(ddt), lcdt = _d5.c, ndc = _d5.n;
376026
+ var lcfreq = new u16(19);
376027
+ for (var i4 = 0;i4 < lclt.length; ++i4)
376028
+ ++lcfreq[lclt[i4] & 31];
376029
+ for (var i4 = 0;i4 < lcdt.length; ++i4)
376030
+ ++lcfreq[lcdt[i4] & 31];
376031
+ var _e5 = hTree(lcfreq, 7), lct = _e5.t, mlcb = _e5.l;
376032
+ var nlcc = 19;
376033
+ for (;nlcc > 4 && !lct[clim[nlcc - 1]]; --nlcc)
376034
+ ;
376035
+ var flen = bl5 + 5 << 3;
376036
+ var ftlen = clen(lf4, flt) + clen(df4, fdt) + eb;
376037
+ var dtlen = clen(lf4, dlt) + clen(df4, ddt) + eb + 14 + 3 * nlcc + clen(lcfreq, lct) + 2 * lcfreq[16] + 3 * lcfreq[17] + 7 * lcfreq[18];
376038
+ if (bs5 >= 0 && flen <= ftlen && flen <= dtlen)
376039
+ return wfblk(out, p4, dat.subarray(bs5, bs5 + bl5));
376040
+ var lm3, ll5, dm3, dl5;
376041
+ wbits(out, p4, 1 + (dtlen < ftlen)), p4 += 2;
376042
+ if (dtlen < ftlen) {
376043
+ lm3 = hMap(dlt, mlb, 0), ll5 = dlt, dm3 = hMap(ddt, mdb, 0), dl5 = ddt;
376044
+ var llm = hMap(lct, mlcb, 0);
376045
+ wbits(out, p4, nlc - 257);
376046
+ wbits(out, p4 + 5, ndc - 1);
376047
+ wbits(out, p4 + 10, nlcc - 4);
376048
+ p4 += 14;
376049
+ for (var i4 = 0;i4 < nlcc; ++i4)
376050
+ wbits(out, p4 + 3 * i4, lct[clim[i4]]);
376051
+ p4 += 3 * nlcc;
376052
+ var lcts = [lclt, lcdt];
376053
+ for (var it5 = 0;it5 < 2; ++it5) {
376054
+ var clct = lcts[it5];
376055
+ for (var i4 = 0;i4 < clct.length; ++i4) {
376056
+ var len = clct[i4] & 31;
376057
+ wbits(out, p4, llm[len]), p4 += lct[len];
376058
+ if (len > 15)
376059
+ wbits(out, p4, clct[i4] >> 5 & 127), p4 += clct[i4] >> 12;
376060
+ }
376061
+ }
376062
+ } else {
376063
+ lm3 = flm, ll5 = flt, dm3 = fdm, dl5 = fdt;
376064
+ }
376065
+ for (var i4 = 0;i4 < li5; ++i4) {
376066
+ var sym = syms[i4];
376067
+ if (sym > 255) {
376068
+ var len = sym >> 18 & 31;
376069
+ wbits16(out, p4, lm3[len + 257]), p4 += ll5[len + 257];
376070
+ if (len > 7)
376071
+ wbits(out, p4, sym >> 23 & 31), p4 += fleb[len];
376072
+ var dst = sym & 31;
376073
+ wbits16(out, p4, dm3[dst]), p4 += dl5[dst];
376074
+ if (dst > 3)
376075
+ wbits16(out, p4, sym >> 5 & 8191), p4 += fdeb[dst];
376076
+ } else {
376077
+ wbits16(out, p4, lm3[sym]), p4 += ll5[sym];
376078
+ }
376079
+ }
376080
+ wbits16(out, p4, lm3[256]);
376081
+ return p4 + ll5[256];
376082
+ };
376083
+ var deo = /* @__PURE__ */ new i32([65540, 131080, 131088, 131104, 262176, 1048704, 1048832, 2114560, 2117632]);
376084
+ var et5 = /* @__PURE__ */ new u8(0);
376085
+ var dflt = function(dat, lvl, plvl, pre, post, st5) {
376086
+ var s3 = st5.z || dat.length;
376087
+ var o4 = new u8(pre + s3 + 5 * (1 + Math.ceil(s3 / 7000)) + post);
376088
+ var w4 = o4.subarray(pre, o4.length - post);
376089
+ var lst = st5.l;
376090
+ var pos = (st5.r || 0) & 7;
376091
+ if (lvl) {
376092
+ if (pos)
376093
+ w4[0] = st5.r >> 3;
376094
+ var opt = deo[lvl - 1];
376095
+ var n4 = opt >> 13, c4 = opt & 8191;
376096
+ var msk_1 = (1 << plvl) - 1;
376097
+ var prev = st5.p || new u16(32768), head = st5.h || new u16(msk_1 + 1);
376098
+ var bs1_1 = Math.ceil(plvl / 3), bs2_1 = 2 * bs1_1;
376099
+ var hsh = function(i5) {
376100
+ return (dat[i5] ^ dat[i5 + 1] << bs1_1 ^ dat[i5 + 2] << bs2_1) & msk_1;
376101
+ };
376102
+ var syms = new i32(25000);
376103
+ var lf4 = new u16(288), df4 = new u16(32);
376104
+ var lc_1 = 0, eb = 0, i4 = st5.i || 0, li5 = 0, wi5 = st5.w || 0, bs5 = 0;
376105
+ for (;i4 + 2 < s3; ++i4) {
376106
+ var hv = hsh(i4);
376107
+ var imod = i4 & 32767, pimod = head[hv];
376108
+ prev[imod] = pimod;
376109
+ head[hv] = imod;
376110
+ if (wi5 <= i4) {
376111
+ var rem = s3 - i4;
376112
+ if ((lc_1 > 7000 || li5 > 24576) && (rem > 423 || !lst)) {
376113
+ pos = wblk(dat, w4, 0, syms, lf4, df4, eb, li5, bs5, i4 - bs5, pos);
376114
+ li5 = lc_1 = eb = 0, bs5 = i4;
376115
+ for (var j5 = 0;j5 < 286; ++j5)
376116
+ lf4[j5] = 0;
376117
+ for (var j5 = 0;j5 < 30; ++j5)
376118
+ df4[j5] = 0;
376119
+ }
376120
+ var l4 = 2, d4 = 0, ch_1 = c4, dif = imod - pimod & 32767;
376121
+ if (rem > 2 && hv == hsh(i4 - dif)) {
376122
+ var maxn = Math.min(n4, rem) - 1;
376123
+ var maxd = Math.min(32767, i4);
376124
+ var ml5 = Math.min(258, rem);
376125
+ while (dif <= maxd && --ch_1 && imod != pimod) {
376126
+ if (dat[i4 + l4] == dat[i4 + l4 - dif]) {
376127
+ var nl5 = 0;
376128
+ for (;nl5 < ml5 && dat[i4 + nl5] == dat[i4 + nl5 - dif]; ++nl5)
376129
+ ;
376130
+ if (nl5 > l4) {
376131
+ l4 = nl5, d4 = dif;
376132
+ if (nl5 > maxn)
376133
+ break;
376134
+ var mmd = Math.min(dif, nl5 - 2);
376135
+ var md3 = 0;
376136
+ for (var j5 = 0;j5 < mmd; ++j5) {
376137
+ var ti5 = i4 - dif + j5 & 32767;
376138
+ var pti = prev[ti5];
376139
+ var cd5 = ti5 - pti & 32767;
376140
+ if (cd5 > md3)
376141
+ md3 = cd5, pimod = ti5;
376142
+ }
376143
+ }
376144
+ }
376145
+ imod = pimod, pimod = prev[imod];
376146
+ dif += imod - pimod & 32767;
376147
+ }
376148
+ }
376149
+ if (d4) {
376150
+ syms[li5++] = 268435456 | revfl[l4] << 18 | revfd[d4];
376151
+ var lin = revfl[l4] & 31, din = revfd[d4] & 31;
376152
+ eb += fleb[lin] + fdeb[din];
376153
+ ++lf4[257 + lin];
376154
+ ++df4[din];
376155
+ wi5 = i4 + l4;
376156
+ ++lc_1;
376157
+ } else {
376158
+ syms[li5++] = dat[i4];
376159
+ ++lf4[dat[i4]];
376160
+ }
376161
+ }
376162
+ }
376163
+ for (i4 = Math.max(i4, wi5);i4 < s3; ++i4) {
376164
+ syms[li5++] = dat[i4];
376165
+ ++lf4[dat[i4]];
376166
+ }
376167
+ pos = wblk(dat, w4, lst, syms, lf4, df4, eb, li5, bs5, i4 - bs5, pos);
376168
+ if (!lst) {
376169
+ st5.r = pos & 7 | w4[pos / 8 | 0] << 3;
376170
+ pos -= 7;
376171
+ st5.h = head, st5.p = prev, st5.i = i4, st5.w = wi5;
376172
+ }
376173
+ } else {
376174
+ for (var i4 = st5.w || 0;i4 < s3 + lst; i4 += 65535) {
376175
+ var e5 = i4 + 65535;
376176
+ if (e5 >= s3) {
376177
+ w4[pos / 8 | 0] = lst;
376178
+ e5 = s3;
376179
+ }
376180
+ pos = wfblk(w4, pos + 1, dat.subarray(i4, e5));
376181
+ }
376182
+ st5.i = s3;
376183
+ }
376184
+ return slc(o4, 0, pre + shft(pos) + post);
376185
+ };
376186
+ var adler = function() {
376187
+ var a3 = 1, b = 0;
376188
+ return {
376189
+ p: function(d4) {
376190
+ var n4 = a3, m4 = b;
376191
+ var l4 = d4.length | 0;
376192
+ for (var i4 = 0;i4 != l4; ) {
376193
+ var e5 = Math.min(i4 + 2655, l4);
376194
+ for (;i4 < e5; ++i4)
376195
+ m4 += n4 += d4[i4];
376196
+ n4 = (n4 & 65535) + 15 * (n4 >> 16), m4 = (m4 & 65535) + 15 * (m4 >> 16);
376197
+ }
376198
+ a3 = n4, b = m4;
376199
+ },
376200
+ d: function() {
376201
+ a3 %= 65521, b %= 65521;
376202
+ return (a3 & 255) << 24 | (a3 & 65280) << 8 | (b & 255) << 8 | b >> 8;
376203
+ }
376204
+ };
376205
+ };
376206
+ var dopt = function(dat, opt, pre, post, st5) {
376207
+ if (!st5) {
376208
+ st5 = { l: 1 };
376209
+ if (opt.dictionary) {
376210
+ var dict = opt.dictionary.subarray(-32768);
376211
+ var newDat = new u8(dict.length + dat.length);
376212
+ newDat.set(dict);
376213
+ newDat.set(dat, dict.length);
376214
+ dat = newDat;
376215
+ st5.w = dict.length;
376216
+ }
376217
+ }
376218
+ return dflt(dat, opt.level == null ? 6 : opt.level, opt.mem == null ? st5.l ? Math.ceil(Math.max(8, Math.min(13, Math.log(dat.length))) * 1.5) : 20 : 12 + opt.mem, pre, post, st5);
376219
+ };
376220
+ var wbytes = function(d4, b, v4) {
376221
+ for (;v4; ++b)
376222
+ d4[b] = v4, v4 >>>= 8;
376223
+ };
376224
+ var zlh = function(c4, o4) {
376225
+ var lv = o4.level, fl6 = lv == 0 ? 0 : lv < 6 ? 1 : lv == 9 ? 3 : 2;
376226
+ c4[0] = 120, c4[1] = fl6 << 6 | (o4.dictionary && 32);
376227
+ c4[1] |= 31 - (c4[0] << 8 | c4[1]) % 31;
376228
+ if (o4.dictionary) {
376229
+ var h6 = adler();
376230
+ h6.p(o4.dictionary);
376231
+ wbytes(c4, 2, h6.d());
376232
+ }
376233
+ };
376234
+ var zls = function(d4, dict) {
376235
+ if ((d4[0] & 15) != 8 || d4[0] >> 4 > 7 || (d4[0] << 8 | d4[1]) % 31)
376236
+ err(6, "invalid zlib data");
376237
+ if ((d4[1] >> 5 & 1) == +!dict)
376238
+ err(6, "invalid zlib data: " + (d4[1] & 32 ? "need" : "unexpected") + " dictionary");
376239
+ return (d4[1] >> 3 & 4) + 2;
376240
+ };
376241
+ var Inflate = /* @__PURE__ */ function() {
376242
+ function Inflate2(opts, cb3) {
376243
+ if (typeof opts == "function")
376244
+ cb3 = opts, opts = {};
376245
+ this.ondata = cb3;
376246
+ var dict = opts && opts.dictionary && opts.dictionary.subarray(-32768);
376247
+ this.s = { i: 0, b: dict ? dict.length : 0 };
376248
+ this.o = new u8(32768);
376249
+ this.p = new u8(0);
376250
+ if (dict)
376251
+ this.o.set(dict);
376252
+ }
376253
+ Inflate2.prototype.e = function(c4) {
376254
+ if (!this.ondata)
376255
+ err(5);
376256
+ if (this.d)
376257
+ err(4);
376258
+ if (!this.p.length)
376259
+ this.p = c4;
376260
+ else if (c4.length) {
376261
+ var n4 = new u8(this.p.length + c4.length);
376262
+ n4.set(this.p), n4.set(c4, this.p.length), this.p = n4;
376263
+ }
376264
+ };
376265
+ Inflate2.prototype.c = function(final) {
376266
+ this.s.i = +(this.d = final || false);
376267
+ var bts = this.s.b;
376268
+ var dt5 = inflt(this.p, this.s, this.o);
376269
+ this.ondata(slc(dt5, bts, this.s.b), this.d);
376270
+ this.o = slc(dt5, this.s.b - 32768), this.s.b = this.o.length;
376271
+ this.p = slc(this.p, this.s.p / 8 | 0), this.s.p &= 7;
376272
+ };
376273
+ Inflate2.prototype.push = function(chunk, final) {
376274
+ this.e(chunk), this.c(final);
376275
+ };
376276
+ return Inflate2;
376277
+ }();
376278
+ function zlibSync(data, opts) {
376279
+ if (!opts)
376280
+ opts = {};
376281
+ var a3 = adler();
376282
+ a3.p(data);
376283
+ var d4 = dopt(data, opts, opts.dictionary ? 6 : 2, 4);
376284
+ return zlh(d4, opts), wbytes(d4, d4.length - 4, a3.d()), d4;
376285
+ }
376286
+ var Unzlib = /* @__PURE__ */ function() {
376287
+ function Unzlib2(opts, cb3) {
376288
+ Inflate.call(this, opts, cb3);
376289
+ this.v = opts && opts.dictionary ? 2 : 1;
376290
+ }
376291
+ Unzlib2.prototype.push = function(chunk, final) {
376292
+ Inflate.prototype.e.call(this, chunk);
376293
+ if (this.v) {
376294
+ if (this.p.length < 6 && !final)
376295
+ return;
376296
+ this.p = this.p.subarray(zls(this.p, this.v - 1)), this.v = 0;
376297
+ }
376298
+ if (final) {
376299
+ if (this.p.length < 4)
376300
+ err(6, "invalid zlib data");
376301
+ this.p = this.p.subarray(0, -4);
376302
+ }
376303
+ Inflate.prototype.c.call(this, final);
376304
+ };
376305
+ return Unzlib2;
376306
+ }();
376307
+ function unzlibSync(data, opts) {
376308
+ return inflt(data.subarray(zls(data, opts && opts.dictionary), -4), { i: 2 }, opts && opts.out, opts && opts.dictionary);
376309
+ }
376310
+ var td5 = typeof TextDecoder != "undefined" && /* @__PURE__ */ new TextDecoder;
376311
+ var tds = 0;
376312
+ try {
376313
+ td5.decode(et5, { stream: true });
376314
+ tds = 1;
376315
+ } catch (e5) {}
376316
+
376317
+ // node_modules/iobuffer/lib/text.js
376318
+ function decode(bytes, encoding = "utf8") {
376319
+ const decoder = new TextDecoder(encoding);
376320
+ return decoder.decode(bytes);
376321
+ }
376322
+ var encoder = new TextEncoder;
376323
+ function encode(str) {
376324
+ return encoder.encode(str);
376325
+ }
376326
+
376327
+ // node_modules/iobuffer/lib/iobuffer.js
376328
+ var defaultByteLength = 1024 * 8;
376329
+ var hostBigEndian = (() => {
376330
+ const array = new Uint8Array(4);
376331
+ const view = new Uint32Array(array.buffer);
376332
+ return !((view[0] = 1) & array[0]);
376333
+ })();
376334
+ var typedArrays = {
376335
+ int8: globalThis.Int8Array,
376336
+ uint8: globalThis.Uint8Array,
376337
+ int16: globalThis.Int16Array,
376338
+ uint16: globalThis.Uint16Array,
376339
+ int32: globalThis.Int32Array,
376340
+ uint32: globalThis.Uint32Array,
376341
+ uint64: globalThis.BigUint64Array,
376342
+ int64: globalThis.BigInt64Array,
376343
+ float32: globalThis.Float32Array,
376344
+ float64: globalThis.Float64Array
376345
+ };
376346
+
376347
+ class IOBuffer {
376348
+ buffer;
376349
+ byteLength;
376350
+ byteOffset;
376351
+ length;
376352
+ offset;
376353
+ lastWrittenByte;
376354
+ littleEndian;
376355
+ _data;
376356
+ _mark;
376357
+ _marks;
376358
+ constructor(data = defaultByteLength, options = {}) {
376359
+ let dataIsGiven = false;
376360
+ if (typeof data === "number") {
376361
+ data = new ArrayBuffer(data);
376362
+ } else {
376363
+ dataIsGiven = true;
376364
+ this.lastWrittenByte = data.byteLength;
376365
+ }
376366
+ const offset = options.offset ? options.offset >>> 0 : 0;
376367
+ const byteLength = data.byteLength - offset;
376368
+ let dvOffset = offset;
376369
+ if (ArrayBuffer.isView(data) || data instanceof IOBuffer) {
376370
+ if (data.byteLength !== data.buffer.byteLength) {
376371
+ dvOffset = data.byteOffset + offset;
376372
+ }
376373
+ data = data.buffer;
376374
+ }
376375
+ if (dataIsGiven) {
376376
+ this.lastWrittenByte = byteLength;
376377
+ } else {
376378
+ this.lastWrittenByte = 0;
376379
+ }
376380
+ this.buffer = data;
376381
+ this.length = byteLength;
376382
+ this.byteLength = byteLength;
376383
+ this.byteOffset = dvOffset;
376384
+ this.offset = 0;
376385
+ this.littleEndian = true;
376386
+ this._data = new DataView(this.buffer, dvOffset, byteLength);
376387
+ this._mark = 0;
376388
+ this._marks = [];
376389
+ }
376390
+ available(byteLength = 1) {
376391
+ return this.offset + byteLength <= this.length;
376392
+ }
376393
+ isLittleEndian() {
376394
+ return this.littleEndian;
376395
+ }
376396
+ setLittleEndian() {
376397
+ this.littleEndian = true;
376398
+ return this;
376399
+ }
376400
+ isBigEndian() {
376401
+ return !this.littleEndian;
376402
+ }
376403
+ setBigEndian() {
376404
+ this.littleEndian = false;
376405
+ return this;
376406
+ }
376407
+ skip(n4 = 1) {
376408
+ this.offset += n4;
376409
+ return this;
376410
+ }
376411
+ back(n4 = 1) {
376412
+ this.offset -= n4;
376413
+ return this;
376414
+ }
376415
+ seek(offset) {
376416
+ this.offset = offset;
376417
+ return this;
376418
+ }
376419
+ mark() {
376420
+ this._mark = this.offset;
376421
+ return this;
376422
+ }
376423
+ reset() {
376424
+ this.offset = this._mark;
376425
+ return this;
376426
+ }
376427
+ pushMark() {
376428
+ this._marks.push(this.offset);
376429
+ return this;
376430
+ }
376431
+ popMark() {
376432
+ const offset = this._marks.pop();
376433
+ if (offset === undefined) {
376434
+ throw new Error("Mark stack empty");
376435
+ }
376436
+ this.seek(offset);
376437
+ return this;
376438
+ }
376439
+ rewind() {
376440
+ this.offset = 0;
376441
+ return this;
376442
+ }
376443
+ ensureAvailable(byteLength = 1) {
376444
+ if (!this.available(byteLength)) {
376445
+ const lengthNeeded = this.offset + byteLength;
376446
+ const newLength = lengthNeeded * 2;
376447
+ const newArray = new Uint8Array(newLength);
376448
+ newArray.set(new Uint8Array(this.buffer));
376449
+ this.buffer = newArray.buffer;
376450
+ this.length = newLength;
376451
+ this.byteLength = newLength;
376452
+ this._data = new DataView(this.buffer);
376453
+ }
376454
+ return this;
376455
+ }
376456
+ readBoolean() {
376457
+ return this.readUint8() !== 0;
376458
+ }
376459
+ readInt8() {
376460
+ return this._data.getInt8(this.offset++);
376461
+ }
376462
+ readUint8() {
376463
+ return this._data.getUint8(this.offset++);
376464
+ }
376465
+ readByte() {
376466
+ return this.readUint8();
376467
+ }
376468
+ readBytes(n4 = 1) {
376469
+ return this.readArray(n4, "uint8");
376470
+ }
376471
+ readArray(size3, type) {
376472
+ const bytes = typedArrays[type].BYTES_PER_ELEMENT * size3;
376473
+ const offset = this.byteOffset + this.offset;
376474
+ const slice = this.buffer.slice(offset, offset + bytes);
376475
+ if (this.littleEndian === hostBigEndian && type !== "uint8" && type !== "int8") {
376476
+ const slice2 = new Uint8Array(this.buffer.slice(offset, offset + bytes));
376477
+ slice2.reverse();
376478
+ const returnArray2 = new typedArrays[type](slice2.buffer);
376479
+ this.offset += bytes;
376480
+ returnArray2.reverse();
376481
+ return returnArray2;
376482
+ }
376483
+ const returnArray = new typedArrays[type](slice);
376484
+ this.offset += bytes;
376485
+ return returnArray;
376486
+ }
376487
+ readInt16() {
376488
+ const value = this._data.getInt16(this.offset, this.littleEndian);
376489
+ this.offset += 2;
376490
+ return value;
376491
+ }
376492
+ readUint16() {
376493
+ const value = this._data.getUint16(this.offset, this.littleEndian);
376494
+ this.offset += 2;
376495
+ return value;
376496
+ }
376497
+ readInt32() {
376498
+ const value = this._data.getInt32(this.offset, this.littleEndian);
376499
+ this.offset += 4;
376500
+ return value;
376501
+ }
376502
+ readUint32() {
376503
+ const value = this._data.getUint32(this.offset, this.littleEndian);
376504
+ this.offset += 4;
376505
+ return value;
376506
+ }
376507
+ readFloat32() {
376508
+ const value = this._data.getFloat32(this.offset, this.littleEndian);
376509
+ this.offset += 4;
376510
+ return value;
376511
+ }
376512
+ readFloat64() {
376513
+ const value = this._data.getFloat64(this.offset, this.littleEndian);
376514
+ this.offset += 8;
376515
+ return value;
376516
+ }
376517
+ readBigInt64() {
376518
+ const value = this._data.getBigInt64(this.offset, this.littleEndian);
376519
+ this.offset += 8;
376520
+ return value;
376521
+ }
376522
+ readBigUint64() {
376523
+ const value = this._data.getBigUint64(this.offset, this.littleEndian);
376524
+ this.offset += 8;
376525
+ return value;
376526
+ }
376527
+ readChar() {
376528
+ return String.fromCharCode(this.readInt8());
376529
+ }
376530
+ readChars(n4 = 1) {
376531
+ let result = "";
376532
+ for (let i4 = 0;i4 < n4; i4++) {
376533
+ result += this.readChar();
376534
+ }
376535
+ return result;
376536
+ }
376537
+ readUtf8(n4 = 1) {
376538
+ return decode(this.readBytes(n4));
376539
+ }
376540
+ decodeText(n4 = 1, encoding = "utf8") {
376541
+ return decode(this.readBytes(n4), encoding);
376542
+ }
376543
+ writeBoolean(value) {
376544
+ this.writeUint8(value ? 255 : 0);
376545
+ return this;
376546
+ }
376547
+ writeInt8(value) {
376548
+ this.ensureAvailable(1);
376549
+ this._data.setInt8(this.offset++, value);
376550
+ this._updateLastWrittenByte();
376551
+ return this;
376552
+ }
376553
+ writeUint8(value) {
376554
+ this.ensureAvailable(1);
376555
+ this._data.setUint8(this.offset++, value);
376556
+ this._updateLastWrittenByte();
376557
+ return this;
376558
+ }
376559
+ writeByte(value) {
376560
+ return this.writeUint8(value);
376561
+ }
376562
+ writeBytes(bytes) {
376563
+ this.ensureAvailable(bytes.length);
376564
+ for (let i4 = 0;i4 < bytes.length; i4++) {
376565
+ this._data.setUint8(this.offset++, bytes[i4]);
376566
+ }
376567
+ this._updateLastWrittenByte();
376568
+ return this;
376569
+ }
376570
+ writeInt16(value) {
376571
+ this.ensureAvailable(2);
376572
+ this._data.setInt16(this.offset, value, this.littleEndian);
376573
+ this.offset += 2;
376574
+ this._updateLastWrittenByte();
376575
+ return this;
376576
+ }
376577
+ writeUint16(value) {
376578
+ this.ensureAvailable(2);
376579
+ this._data.setUint16(this.offset, value, this.littleEndian);
376580
+ this.offset += 2;
376581
+ this._updateLastWrittenByte();
376582
+ return this;
376583
+ }
376584
+ writeInt32(value) {
376585
+ this.ensureAvailable(4);
376586
+ this._data.setInt32(this.offset, value, this.littleEndian);
376587
+ this.offset += 4;
376588
+ this._updateLastWrittenByte();
376589
+ return this;
376590
+ }
376591
+ writeUint32(value) {
376592
+ this.ensureAvailable(4);
376593
+ this._data.setUint32(this.offset, value, this.littleEndian);
376594
+ this.offset += 4;
376595
+ this._updateLastWrittenByte();
376596
+ return this;
376597
+ }
376598
+ writeFloat32(value) {
376599
+ this.ensureAvailable(4);
376600
+ this._data.setFloat32(this.offset, value, this.littleEndian);
376601
+ this.offset += 4;
376602
+ this._updateLastWrittenByte();
376603
+ return this;
376604
+ }
376605
+ writeFloat64(value) {
376606
+ this.ensureAvailable(8);
376607
+ this._data.setFloat64(this.offset, value, this.littleEndian);
376608
+ this.offset += 8;
376609
+ this._updateLastWrittenByte();
376610
+ return this;
376611
+ }
376612
+ writeBigInt64(value) {
376613
+ this.ensureAvailable(8);
376614
+ this._data.setBigInt64(this.offset, value, this.littleEndian);
376615
+ this.offset += 8;
376616
+ this._updateLastWrittenByte();
376617
+ return this;
376618
+ }
376619
+ writeBigUint64(value) {
376620
+ this.ensureAvailable(8);
376621
+ this._data.setBigUint64(this.offset, value, this.littleEndian);
376622
+ this.offset += 8;
376623
+ this._updateLastWrittenByte();
376624
+ return this;
376625
+ }
376626
+ writeChar(str) {
376627
+ return this.writeUint8(str.charCodeAt(0));
376628
+ }
376629
+ writeChars(str) {
376630
+ for (let i4 = 0;i4 < str.length; i4++) {
376631
+ this.writeUint8(str.charCodeAt(i4));
376632
+ }
376633
+ return this;
376634
+ }
376635
+ writeUtf8(str) {
376636
+ return this.writeBytes(encode(str));
376637
+ }
376638
+ toArray() {
376639
+ return new Uint8Array(this.buffer, this.byteOffset, this.lastWrittenByte);
376640
+ }
376641
+ getWrittenByteLength() {
376642
+ return this.lastWrittenByte - this.byteOffset;
376643
+ }
376644
+ _updateLastWrittenByte() {
376645
+ if (this.offset > this.lastWrittenByte) {
376646
+ this.lastWrittenByte = this.offset;
376647
+ }
376648
+ }
376649
+ }
376650
+
376651
+ // node_modules/fast-png/lib/helpers/crc.js
376652
+ var crcTable = [];
376653
+ for (let n4 = 0;n4 < 256; n4++) {
376654
+ let c4 = n4;
376655
+ for (let k4 = 0;k4 < 8; k4++) {
376656
+ if (c4 & 1) {
376657
+ c4 = 3988292384 ^ c4 >>> 1;
376658
+ } else {
376659
+ c4 = c4 >>> 1;
376660
+ }
376661
+ }
376662
+ crcTable[n4] = c4;
376663
+ }
376664
+ var initialCrc = 4294967295;
376665
+ function updateCrc(currentCrc, data, length3) {
376666
+ let c4 = currentCrc;
376667
+ for (let n4 = 0;n4 < length3; n4++) {
376668
+ c4 = crcTable[(c4 ^ data[n4]) & 255] ^ c4 >>> 8;
376669
+ }
376670
+ return c4;
376671
+ }
376672
+ function crc(data, length3) {
376673
+ return (updateCrc(initialCrc, data, length3) ^ initialCrc) >>> 0;
376674
+ }
376675
+ function checkCrc(buffer, crcLength, chunkName) {
376676
+ const expectedCrc = buffer.readUint32();
376677
+ const actualCrc = crc(new Uint8Array(buffer.buffer, buffer.byteOffset + buffer.offset - crcLength - 4, crcLength), crcLength);
376678
+ if (actualCrc !== expectedCrc) {
376679
+ throw new Error(`CRC mismatch for chunk ${chunkName}. Expected ${expectedCrc}, found ${actualCrc}`);
376680
+ }
376681
+ }
376682
+ function writeCrc(buffer, length3) {
376683
+ buffer.writeUint32(crc(new Uint8Array(buffer.buffer, buffer.byteOffset + buffer.offset - length3, length3), length3));
376684
+ }
376685
+
376686
+ // node_modules/fast-png/lib/helpers/unfilter.js
376687
+ function unfilterNone(currentLine, newLine, bytesPerLine) {
376688
+ for (let i4 = 0;i4 < bytesPerLine; i4++) {
376689
+ newLine[i4] = currentLine[i4];
376690
+ }
376691
+ }
376692
+ function unfilterSub(currentLine, newLine, bytesPerLine, bytesPerPixel) {
376693
+ let i4 = 0;
376694
+ for (;i4 < bytesPerPixel; i4++) {
376695
+ newLine[i4] = currentLine[i4];
376696
+ }
376697
+ for (;i4 < bytesPerLine; i4++) {
376698
+ newLine[i4] = currentLine[i4] + newLine[i4 - bytesPerPixel] & 255;
376699
+ }
376700
+ }
376701
+ function unfilterUp(currentLine, newLine, prevLine, bytesPerLine) {
376702
+ let i4 = 0;
376703
+ if (prevLine.length === 0) {
376704
+ for (;i4 < bytesPerLine; i4++) {
376705
+ newLine[i4] = currentLine[i4];
376706
+ }
376707
+ } else {
376708
+ for (;i4 < bytesPerLine; i4++) {
376709
+ newLine[i4] = currentLine[i4] + prevLine[i4] & 255;
376710
+ }
376711
+ }
376712
+ }
376713
+ function unfilterAverage(currentLine, newLine, prevLine, bytesPerLine, bytesPerPixel) {
376714
+ let i4 = 0;
376715
+ if (prevLine.length === 0) {
376716
+ for (;i4 < bytesPerPixel; i4++) {
376717
+ newLine[i4] = currentLine[i4];
376718
+ }
376719
+ for (;i4 < bytesPerLine; i4++) {
376720
+ newLine[i4] = currentLine[i4] + (newLine[i4 - bytesPerPixel] >> 1) & 255;
376721
+ }
376722
+ } else {
376723
+ for (;i4 < bytesPerPixel; i4++) {
376724
+ newLine[i4] = currentLine[i4] + (prevLine[i4] >> 1) & 255;
376725
+ }
376726
+ for (;i4 < bytesPerLine; i4++) {
376727
+ newLine[i4] = currentLine[i4] + (newLine[i4 - bytesPerPixel] + prevLine[i4] >> 1) & 255;
376728
+ }
376729
+ }
376730
+ }
376731
+ function unfilterPaeth(currentLine, newLine, prevLine, bytesPerLine, bytesPerPixel) {
376732
+ let i4 = 0;
376733
+ if (prevLine.length === 0) {
376734
+ for (;i4 < bytesPerPixel; i4++) {
376735
+ newLine[i4] = currentLine[i4];
376736
+ }
376737
+ for (;i4 < bytesPerLine; i4++) {
376738
+ newLine[i4] = currentLine[i4] + newLine[i4 - bytesPerPixel] & 255;
376739
+ }
376740
+ } else {
376741
+ for (;i4 < bytesPerPixel; i4++) {
376742
+ newLine[i4] = currentLine[i4] + prevLine[i4] & 255;
376743
+ }
376744
+ for (;i4 < bytesPerLine; i4++) {
376745
+ newLine[i4] = currentLine[i4] + paethPredictor(newLine[i4 - bytesPerPixel], prevLine[i4], prevLine[i4 - bytesPerPixel]) & 255;
376746
+ }
376747
+ }
376748
+ }
376749
+ function paethPredictor(a3, b, c4) {
376750
+ const p4 = a3 + b - c4;
376751
+ const pa5 = Math.abs(p4 - a3);
376752
+ const pb = Math.abs(p4 - b);
376753
+ const pc5 = Math.abs(p4 - c4);
376754
+ if (pa5 <= pb && pa5 <= pc5)
376755
+ return a3;
376756
+ else if (pb <= pc5)
376757
+ return b;
376758
+ else
376759
+ return c4;
376760
+ }
376761
+
376762
+ // node_modules/fast-png/lib/helpers/apply_unfilter.js
376763
+ function applyUnfilter(filterType, currentLine, newLine, prevLine, passLineBytes, bytesPerPixel) {
376764
+ switch (filterType) {
376765
+ case 0:
376766
+ unfilterNone(currentLine, newLine, passLineBytes);
376767
+ break;
376768
+ case 1:
376769
+ unfilterSub(currentLine, newLine, passLineBytes, bytesPerPixel);
376770
+ break;
376771
+ case 2:
376772
+ unfilterUp(currentLine, newLine, prevLine, passLineBytes);
376773
+ break;
376774
+ case 3:
376775
+ unfilterAverage(currentLine, newLine, prevLine, passLineBytes, bytesPerPixel);
376776
+ break;
376777
+ case 4:
376778
+ unfilterPaeth(currentLine, newLine, prevLine, passLineBytes, bytesPerPixel);
376779
+ break;
376780
+ default:
376781
+ throw new Error(`Unsupported filter: ${filterType}`);
376782
+ }
376783
+ }
376784
+
376785
+ // node_modules/fast-png/lib/helpers/decode_interlace_adam7.js
376786
+ var uint16 = new Uint16Array([255]);
376787
+ var uint8 = new Uint8Array(uint16.buffer);
376788
+ var osIsLittleEndian = uint8[0] === 255;
376789
+ function decodeInterlaceAdam7(params2) {
376790
+ const { data, width, height, channels, depth } = params2;
376791
+ const passes = [
376792
+ { x: 0, y: 0, xStep: 8, yStep: 8 },
376793
+ { x: 4, y: 0, xStep: 8, yStep: 8 },
376794
+ { x: 0, y: 4, xStep: 4, yStep: 8 },
376795
+ { x: 2, y: 0, xStep: 4, yStep: 4 },
376796
+ { x: 0, y: 2, xStep: 2, yStep: 4 },
376797
+ { x: 1, y: 0, xStep: 2, yStep: 2 },
376798
+ { x: 0, y: 1, xStep: 1, yStep: 2 }
376799
+ ];
376800
+ const bytesPerPixel = Math.ceil(depth / 8) * channels;
376801
+ const resultData = new Uint8Array(height * width * bytesPerPixel);
376802
+ let offset = 0;
376803
+ for (let passIndex = 0;passIndex < 7; passIndex++) {
376804
+ const pass = passes[passIndex];
376805
+ const passWidth = Math.ceil((width - pass.x) / pass.xStep);
376806
+ const passHeight = Math.ceil((height - pass.y) / pass.yStep);
376807
+ if (passWidth <= 0 || passHeight <= 0)
376808
+ continue;
376809
+ const passLineBytes = passWidth * bytesPerPixel;
376810
+ const prevLine = new Uint8Array(passLineBytes);
376811
+ for (let y5 = 0;y5 < passHeight; y5++) {
376812
+ const filterType = data[offset++];
376813
+ const currentLine = data.subarray(offset, offset + passLineBytes);
376814
+ offset += passLineBytes;
376815
+ const newLine = new Uint8Array(passLineBytes);
376816
+ applyUnfilter(filterType, currentLine, newLine, prevLine, passLineBytes, bytesPerPixel);
376817
+ prevLine.set(newLine);
376818
+ for (let x4 = 0;x4 < passWidth; x4++) {
376819
+ const outputX = pass.x + x4 * pass.xStep;
376820
+ const outputY = pass.y + y5 * pass.yStep;
376821
+ if (outputX >= width || outputY >= height)
376822
+ continue;
376823
+ for (let i4 = 0;i4 < bytesPerPixel; i4++) {
376824
+ resultData[(outputY * width + outputX) * bytesPerPixel + i4] = newLine[x4 * bytesPerPixel + i4];
376825
+ }
376826
+ }
376827
+ }
376828
+ }
376829
+ if (depth === 16) {
376830
+ const uint16Data = new Uint16Array(resultData.buffer);
376831
+ if (osIsLittleEndian) {
376832
+ for (let k4 = 0;k4 < uint16Data.length; k4++) {
376833
+ uint16Data[k4] = swap16(uint16Data[k4]);
376834
+ }
376835
+ }
376836
+ return uint16Data;
376837
+ } else {
376838
+ return resultData;
376839
+ }
376840
+ }
376841
+ function swap16(val) {
376842
+ return (val & 255) << 8 | val >> 8 & 255;
376843
+ }
376844
+
376845
+ // node_modules/fast-png/lib/helpers/decode_interlace_null.js
376846
+ var uint162 = new Uint16Array([255]);
376847
+ var uint82 = new Uint8Array(uint162.buffer);
376848
+ var osIsLittleEndian2 = uint82[0] === 255;
376849
+ var empty = new Uint8Array(0);
376850
+ function decodeInterlaceNull(params2) {
376851
+ const { data, width, height, channels, depth } = params2;
376852
+ const bytesPerPixel = Math.ceil(depth / 8) * channels;
376853
+ const bytesPerLine = Math.ceil(depth / 8 * channels * width);
376854
+ const newData = new Uint8Array(height * bytesPerLine);
376855
+ let prevLine = empty;
376856
+ let offset = 0;
376857
+ let currentLine;
376858
+ let newLine;
376859
+ for (let i4 = 0;i4 < height; i4++) {
376860
+ currentLine = data.subarray(offset + 1, offset + 1 + bytesPerLine);
376861
+ newLine = newData.subarray(i4 * bytesPerLine, (i4 + 1) * bytesPerLine);
376862
+ switch (data[offset]) {
376863
+ case 0:
376864
+ unfilterNone(currentLine, newLine, bytesPerLine);
376865
+ break;
376866
+ case 1:
376867
+ unfilterSub(currentLine, newLine, bytesPerLine, bytesPerPixel);
376868
+ break;
376869
+ case 2:
376870
+ unfilterUp(currentLine, newLine, prevLine, bytesPerLine);
376871
+ break;
376872
+ case 3:
376873
+ unfilterAverage(currentLine, newLine, prevLine, bytesPerLine, bytesPerPixel);
376874
+ break;
376875
+ case 4:
376876
+ unfilterPaeth(currentLine, newLine, prevLine, bytesPerLine, bytesPerPixel);
376877
+ break;
376878
+ default:
376879
+ throw new Error(`Unsupported filter: ${data[offset]}`);
376880
+ }
376881
+ prevLine = newLine;
376882
+ offset += bytesPerLine + 1;
376883
+ }
376884
+ if (depth === 16) {
376885
+ const uint16Data = new Uint16Array(newData.buffer);
376886
+ if (osIsLittleEndian2) {
376887
+ for (let k4 = 0;k4 < uint16Data.length; k4++) {
376888
+ uint16Data[k4] = swap162(uint16Data[k4]);
376889
+ }
376890
+ }
376891
+ return uint16Data;
376892
+ } else {
376893
+ return newData;
376894
+ }
376895
+ }
376896
+ function swap162(val) {
376897
+ return (val & 255) << 8 | val >> 8 & 255;
376898
+ }
376899
+
376900
+ // node_modules/fast-png/lib/helpers/signature.js
376901
+ var pngSignature = Uint8Array.of(137, 80, 78, 71, 13, 10, 26, 10);
376902
+ function writeSignature(buffer) {
376903
+ buffer.writeBytes(pngSignature);
376904
+ }
376905
+ function checkSignature(buffer) {
376906
+ if (!hasPngSignature(buffer.readBytes(pngSignature.length))) {
376907
+ throw new Error("wrong PNG signature");
376908
+ }
376909
+ }
376910
+ function hasPngSignature(array) {
376911
+ if (array.length < pngSignature.length) {
376912
+ return false;
376913
+ }
376914
+ for (let i4 = 0;i4 < pngSignature.length; i4++) {
376915
+ if (array[i4] !== pngSignature[i4]) {
376916
+ return false;
376917
+ }
376918
+ }
376919
+ return true;
376920
+ }
376921
+
376922
+ // node_modules/fast-png/lib/helpers/text.js
376923
+ var textChunkName = "tEXt";
376924
+ var NULL = 0;
376925
+ var latin1Decoder = new TextDecoder("latin1");
376926
+ function validateKeyword(keyword) {
376927
+ validateLatin1(keyword);
376928
+ if (keyword.length === 0 || keyword.length > 79) {
376929
+ throw new Error("keyword length must be between 1 and 79");
376930
+ }
376931
+ }
376932
+ var latin1Regex = /^[\u0000-\u00FF]*$/;
376933
+ function validateLatin1(text) {
376934
+ if (!latin1Regex.test(text)) {
376935
+ throw new Error("invalid latin1 text");
376936
+ }
376937
+ }
376938
+ function decodetEXt(text, buffer, length3) {
376939
+ const keyword = readKeyword(buffer);
376940
+ text[keyword] = readLatin1(buffer, length3 - keyword.length - 1);
376941
+ }
376942
+ function encodetEXt(buffer, keyword, text) {
376943
+ validateKeyword(keyword);
376944
+ validateLatin1(text);
376945
+ const length3 = keyword.length + 1 + text.length;
376946
+ buffer.writeUint32(length3);
376947
+ buffer.writeChars(textChunkName);
376948
+ buffer.writeChars(keyword);
376949
+ buffer.writeByte(NULL);
376950
+ buffer.writeChars(text);
376951
+ writeCrc(buffer, length3 + 4);
376952
+ }
376953
+ function readKeyword(buffer) {
376954
+ buffer.mark();
376955
+ while (buffer.readByte() !== NULL) {}
376956
+ const end = buffer.offset;
376957
+ buffer.reset();
376958
+ const keyword = latin1Decoder.decode(buffer.readBytes(end - buffer.offset - 1));
376959
+ buffer.skip(1);
376960
+ validateKeyword(keyword);
376961
+ return keyword;
376962
+ }
376963
+ function readLatin1(buffer, length3) {
376964
+ return latin1Decoder.decode(buffer.readBytes(length3));
376965
+ }
376966
+
376967
+ // node_modules/fast-png/lib/internal_types.js
376968
+ var ColorType = {
376969
+ UNKNOWN: -1,
376970
+ GREYSCALE: 0,
376971
+ TRUECOLOUR: 2,
376972
+ INDEXED_COLOUR: 3,
376973
+ GREYSCALE_ALPHA: 4,
376974
+ TRUECOLOUR_ALPHA: 6
376975
+ };
376976
+ var CompressionMethod = {
376977
+ UNKNOWN: -1,
376978
+ DEFLATE: 0
376979
+ };
376980
+ var FilterMethod = {
376981
+ UNKNOWN: -1,
376982
+ ADAPTIVE: 0
376983
+ };
376984
+ var InterlaceMethod = {
376985
+ UNKNOWN: -1,
376986
+ NO_INTERLACE: 0,
376987
+ ADAM7: 1
376988
+ };
376989
+ var DisposeOpType = {
376990
+ NONE: 0,
376991
+ BACKGROUND: 1,
376992
+ PREVIOUS: 2
376993
+ };
376994
+ var BlendOpType = {
376995
+ SOURCE: 0,
376996
+ OVER: 1
376997
+ };
376998
+
376999
+ // node_modules/fast-png/lib/png_decoder.js
377000
+ class PngDecoder extends IOBuffer {
377001
+ _checkCrc;
377002
+ _inflator;
377003
+ _png;
377004
+ _apng;
377005
+ _end;
377006
+ _hasPalette;
377007
+ _palette;
377008
+ _hasTransparency;
377009
+ _transparency;
377010
+ _compressionMethod;
377011
+ _filterMethod;
377012
+ _interlaceMethod;
377013
+ _colorType;
377014
+ _isAnimated;
377015
+ _numberOfFrames;
377016
+ _numberOfPlays;
377017
+ _frames;
377018
+ _writingDataChunks;
377019
+ _chunks;
377020
+ _inflatorResult;
377021
+ constructor(data, options = {}) {
377022
+ super(data);
377023
+ const { checkCrc: checkCrc2 = false } = options;
377024
+ this._checkCrc = checkCrc2;
377025
+ this._inflator = new Unzlib((chunk, final) => {
377026
+ this._chunks.push(chunk);
377027
+ if (final) {
377028
+ const totalLength = this._chunks.reduce((sum, c4) => sum + c4.length, 0);
377029
+ this._inflatorResult = new Uint8Array(totalLength);
377030
+ let offset = 0;
377031
+ for (const chunk2 of this._chunks) {
377032
+ this._inflatorResult.set(chunk2, offset);
377033
+ offset += chunk2.length;
377034
+ }
377035
+ this._chunks = [];
377036
+ }
377037
+ });
377038
+ this._chunks = [];
377039
+ this._png = {
377040
+ width: -1,
377041
+ height: -1,
377042
+ channels: -1,
377043
+ data: new Uint8Array(0),
377044
+ depth: 1,
377045
+ text: {}
377046
+ };
377047
+ this._apng = {
377048
+ width: -1,
377049
+ height: -1,
377050
+ channels: -1,
377051
+ depth: 1,
377052
+ numberOfFrames: 1,
377053
+ numberOfPlays: 0,
377054
+ text: {},
377055
+ frames: []
377056
+ };
377057
+ this._end = false;
377058
+ this._hasPalette = false;
377059
+ this._palette = [];
377060
+ this._hasTransparency = false;
377061
+ this._transparency = new Uint16Array(0);
377062
+ this._compressionMethod = CompressionMethod.UNKNOWN;
377063
+ this._filterMethod = FilterMethod.UNKNOWN;
377064
+ this._interlaceMethod = InterlaceMethod.UNKNOWN;
377065
+ this._colorType = ColorType.UNKNOWN;
377066
+ this._isAnimated = false;
377067
+ this._numberOfFrames = 1;
377068
+ this._numberOfPlays = 0;
377069
+ this._frames = [];
377070
+ this._writingDataChunks = false;
377071
+ this._inflatorResult = new Uint8Array(0);
377072
+ this.setBigEndian();
377073
+ }
377074
+ decode() {
377075
+ checkSignature(this);
377076
+ while (!this._end) {
377077
+ const length3 = this.readUint32();
377078
+ const type = this.readChars(4);
377079
+ this.decodeChunk(length3, type);
377080
+ }
377081
+ this._inflator.push(new Uint8Array(0), true);
377082
+ this.decodeImage();
377083
+ return this._png;
377084
+ }
377085
+ decodeApng() {
377086
+ checkSignature(this);
377087
+ while (!this._end) {
377088
+ const length3 = this.readUint32();
377089
+ const type = this.readChars(4);
377090
+ this.decodeApngChunk(length3, type);
377091
+ }
377092
+ this.decodeApngImage();
377093
+ return this._apng;
377094
+ }
377095
+ decodeChunk(length3, type) {
377096
+ const offset = this.offset;
377097
+ switch (type) {
377098
+ case "IHDR":
377099
+ this.decodeIHDR();
377100
+ break;
377101
+ case "PLTE":
377102
+ this.decodePLTE(length3);
377103
+ break;
377104
+ case "IDAT":
377105
+ this.decodeIDAT(length3);
377106
+ break;
377107
+ case "IEND":
377108
+ this._end = true;
377109
+ break;
377110
+ case "tRNS":
377111
+ this.decodetRNS(length3);
377112
+ break;
377113
+ case "iCCP":
377114
+ this.decodeiCCP(length3);
377115
+ break;
377116
+ case textChunkName:
377117
+ decodetEXt(this._png.text, this, length3);
377118
+ break;
377119
+ case "pHYs":
377120
+ this.decodepHYs();
377121
+ break;
377122
+ default:
377123
+ this.skip(length3);
377124
+ break;
377125
+ }
377126
+ if (this.offset - offset !== length3) {
377127
+ throw new Error(`Length mismatch while decoding chunk ${type}`);
377128
+ }
377129
+ if (this._checkCrc) {
377130
+ checkCrc(this, length3 + 4, type);
377131
+ } else {
377132
+ this.skip(4);
377133
+ }
377134
+ }
377135
+ decodeApngChunk(length3, type) {
377136
+ const offset = this.offset;
377137
+ if (type !== "fdAT" && type !== "IDAT" && this._writingDataChunks) {
377138
+ this.pushDataToFrame();
377139
+ }
377140
+ switch (type) {
377141
+ case "acTL":
377142
+ this.decodeACTL();
377143
+ break;
377144
+ case "fcTL":
377145
+ this.decodeFCTL();
377146
+ break;
377147
+ case "fdAT":
377148
+ this.decodeFDAT(length3);
377149
+ break;
377150
+ default:
377151
+ this.decodeChunk(length3, type);
377152
+ this.offset = offset + length3;
377153
+ break;
377154
+ }
377155
+ if (this.offset - offset !== length3) {
377156
+ throw new Error(`Length mismatch while decoding chunk ${type}`);
377157
+ }
377158
+ if (this._checkCrc) {
377159
+ checkCrc(this, length3 + 4, type);
377160
+ } else {
377161
+ this.skip(4);
377162
+ }
377163
+ }
377164
+ decodeIHDR() {
377165
+ const image = this._png;
377166
+ image.width = this.readUint32();
377167
+ image.height = this.readUint32();
377168
+ image.depth = checkBitDepth(this.readUint8());
377169
+ const colorType = this.readUint8();
377170
+ this._colorType = colorType;
377171
+ let channels;
377172
+ switch (colorType) {
377173
+ case ColorType.GREYSCALE:
377174
+ channels = 1;
377175
+ break;
377176
+ case ColorType.TRUECOLOUR:
377177
+ channels = 3;
377178
+ break;
377179
+ case ColorType.INDEXED_COLOUR:
377180
+ channels = 1;
377181
+ break;
377182
+ case ColorType.GREYSCALE_ALPHA:
377183
+ channels = 2;
377184
+ break;
377185
+ case ColorType.TRUECOLOUR_ALPHA:
377186
+ channels = 4;
377187
+ break;
377188
+ case ColorType.UNKNOWN:
377189
+ default:
377190
+ throw new Error(`Unknown color type: ${colorType}`);
377191
+ }
377192
+ this._png.channels = channels;
377193
+ this._compressionMethod = this.readUint8();
377194
+ if (this._compressionMethod !== CompressionMethod.DEFLATE) {
377195
+ throw new Error(`Unsupported compression method: ${this._compressionMethod}`);
377196
+ }
377197
+ this._filterMethod = this.readUint8();
377198
+ this._interlaceMethod = this.readUint8();
377199
+ }
377200
+ decodeACTL() {
377201
+ this._numberOfFrames = this.readUint32();
377202
+ this._numberOfPlays = this.readUint32();
377203
+ this._isAnimated = true;
377204
+ }
377205
+ decodeFCTL() {
377206
+ const image = {
377207
+ sequenceNumber: this.readUint32(),
377208
+ width: this.readUint32(),
377209
+ height: this.readUint32(),
377210
+ xOffset: this.readUint32(),
377211
+ yOffset: this.readUint32(),
377212
+ delayNumber: this.readUint16(),
377213
+ delayDenominator: this.readUint16(),
377214
+ disposeOp: this.readUint8(),
377215
+ blendOp: this.readUint8(),
377216
+ data: new Uint8Array(0)
377217
+ };
377218
+ this._frames.push(image);
377219
+ }
377220
+ decodePLTE(length3) {
377221
+ if (length3 % 3 !== 0) {
377222
+ throw new RangeError(`PLTE field length must be a multiple of 3. Got ${length3}`);
377223
+ }
377224
+ const l4 = length3 / 3;
377225
+ this._hasPalette = true;
377226
+ const palette = [];
377227
+ this._palette = palette;
377228
+ for (let i4 = 0;i4 < l4; i4++) {
377229
+ palette.push([this.readUint8(), this.readUint8(), this.readUint8()]);
377230
+ }
377231
+ }
377232
+ decodeIDAT(length3) {
377233
+ this._writingDataChunks = true;
377234
+ const dataLength = length3;
377235
+ const dataOffset = this.offset + this.byteOffset;
377236
+ try {
377237
+ this._inflator.push(new Uint8Array(this.buffer, dataOffset, dataLength), false);
377238
+ } catch (error) {
377239
+ throw new Error("Error while decompressing the data:", { cause: error });
377240
+ }
377241
+ this.skip(length3);
377242
+ }
377243
+ decodeFDAT(length3) {
377244
+ this._writingDataChunks = true;
377245
+ let dataLength = length3;
377246
+ let dataOffset = this.offset + this.byteOffset;
377247
+ dataOffset += 4;
377248
+ dataLength -= 4;
377249
+ try {
377250
+ this._inflator.push(new Uint8Array(this.buffer, dataOffset, dataLength), false);
377251
+ } catch (error) {
377252
+ throw new Error("Error while decompressing the data:", { cause: error });
377253
+ }
377254
+ this.skip(length3);
377255
+ }
377256
+ decodetRNS(length3) {
377257
+ switch (this._colorType) {
377258
+ case ColorType.GREYSCALE:
377259
+ case ColorType.TRUECOLOUR: {
377260
+ if (length3 % 2 !== 0) {
377261
+ throw new RangeError(`tRNS chunk length must be a multiple of 2. Got ${length3}`);
377262
+ }
377263
+ if (length3 / 2 > this._png.width * this._png.height) {
377264
+ throw new Error(`tRNS chunk contains more alpha values than there are pixels (${length3 / 2} vs ${this._png.width * this._png.height})`);
377265
+ }
377266
+ this._hasTransparency = true;
377267
+ this._transparency = new Uint16Array(length3 / 2);
377268
+ for (let i4 = 0;i4 < length3 / 2; i4++) {
377269
+ this._transparency[i4] = this.readUint16();
377270
+ }
377271
+ break;
377272
+ }
377273
+ case ColorType.INDEXED_COLOUR: {
377274
+ if (length3 > this._palette.length) {
377275
+ throw new Error(`tRNS chunk contains more alpha values than there are palette colors (${length3} vs ${this._palette.length})`);
377276
+ }
377277
+ let i4 = 0;
377278
+ for (;i4 < length3; i4++) {
377279
+ const alpha = this.readByte();
377280
+ this._palette[i4].push(alpha);
377281
+ }
377282
+ for (;i4 < this._palette.length; i4++) {
377283
+ this._palette[i4].push(255);
377284
+ }
377285
+ break;
377286
+ }
377287
+ case ColorType.UNKNOWN:
377288
+ case ColorType.GREYSCALE_ALPHA:
377289
+ case ColorType.TRUECOLOUR_ALPHA:
377290
+ default: {
377291
+ throw new Error(`tRNS chunk is not supported for color type ${this._colorType}`);
377292
+ }
377293
+ }
377294
+ }
377295
+ decodeiCCP(length3) {
377296
+ const name = readKeyword(this);
377297
+ const compressionMethod = this.readUint8();
377298
+ if (compressionMethod !== CompressionMethod.DEFLATE) {
377299
+ throw new Error(`Unsupported iCCP compression method: ${compressionMethod}`);
377300
+ }
377301
+ const compressedProfile = this.readBytes(length3 - name.length - 2);
377302
+ this._png.iccEmbeddedProfile = {
377303
+ name,
377304
+ profile: unzlibSync(compressedProfile)
377305
+ };
377306
+ }
377307
+ decodepHYs() {
377308
+ const ppuX = this.readUint32();
377309
+ const ppuY = this.readUint32();
377310
+ const unitSpecifier = this.readByte();
377311
+ this._png.resolution = {
377312
+ x: ppuX,
377313
+ y: ppuY,
377314
+ unit: unitSpecifier
377315
+ };
377316
+ }
377317
+ decodeApngImage() {
377318
+ this._apng.width = this._png.width;
377319
+ this._apng.height = this._png.height;
377320
+ this._apng.channels = this._png.channels;
377321
+ this._apng.depth = this._png.depth;
377322
+ this._apng.numberOfFrames = this._numberOfFrames;
377323
+ this._apng.numberOfPlays = this._numberOfPlays;
377324
+ this._apng.text = this._png.text;
377325
+ this._apng.resolution = this._png.resolution;
377326
+ for (let i4 = 0;i4 < this._numberOfFrames; i4++) {
377327
+ const newFrame = {
377328
+ sequenceNumber: this._frames[i4].sequenceNumber,
377329
+ delayNumber: this._frames[i4].delayNumber,
377330
+ delayDenominator: this._frames[i4].delayDenominator,
377331
+ data: this._apng.depth === 8 ? new Uint8Array(this._apng.width * this._apng.height * this._apng.channels) : new Uint16Array(this._apng.width * this._apng.height * this._apng.channels)
377332
+ };
377333
+ const frame = this._frames.at(i4);
377334
+ if (frame) {
377335
+ frame.data = decodeInterlaceNull({
377336
+ data: frame.data,
377337
+ width: frame.width,
377338
+ height: frame.height,
377339
+ channels: this._apng.channels,
377340
+ depth: this._apng.depth
377341
+ });
377342
+ if (this._hasPalette) {
377343
+ this._apng.palette = this._palette;
377344
+ }
377345
+ if (this._hasTransparency) {
377346
+ this._apng.transparency = this._transparency;
377347
+ }
377348
+ if (i4 === 0 || frame.xOffset === 0 && frame.yOffset === 0 && frame.width === this._png.width && frame.height === this._png.height) {
377349
+ newFrame.data = frame.data;
377350
+ } else {
377351
+ const prevFrame = this._apng.frames.at(i4 - 1);
377352
+ this.disposeFrame(frame, prevFrame, newFrame);
377353
+ this.addFrameDataToCanvas(newFrame, frame);
377354
+ }
377355
+ this._apng.frames.push(newFrame);
377356
+ }
377357
+ }
377358
+ return this._apng;
377359
+ }
377360
+ disposeFrame(frame, prevFrame, imageFrame) {
377361
+ switch (frame.disposeOp) {
377362
+ case DisposeOpType.NONE:
377363
+ break;
377364
+ case DisposeOpType.BACKGROUND:
377365
+ for (let row = 0;row < this._png.height; row++) {
377366
+ for (let col = 0;col < this._png.width; col++) {
377367
+ const index = (row * frame.width + col) * this._png.channels;
377368
+ for (let channel = 0;channel < this._png.channels; channel++) {
377369
+ imageFrame.data[index + channel] = 0;
377370
+ }
377371
+ }
377372
+ }
377373
+ break;
377374
+ case DisposeOpType.PREVIOUS:
377375
+ imageFrame.data.set(prevFrame.data);
377376
+ break;
377377
+ default:
377378
+ throw new Error("Unknown disposeOp");
377379
+ }
377380
+ }
377381
+ addFrameDataToCanvas(imageFrame, frame) {
377382
+ const maxValue = 1 << this._png.depth;
377383
+ const calculatePixelIndices = (row, col) => {
377384
+ const index = ((row + frame.yOffset) * this._png.width + frame.xOffset + col) * this._png.channels;
377385
+ const frameIndex = (row * frame.width + col) * this._png.channels;
377386
+ return { index, frameIndex };
377387
+ };
377388
+ switch (frame.blendOp) {
377389
+ case BlendOpType.SOURCE:
377390
+ for (let row = 0;row < frame.height; row++) {
377391
+ for (let col = 0;col < frame.width; col++) {
377392
+ const { index, frameIndex } = calculatePixelIndices(row, col);
377393
+ for (let channel = 0;channel < this._png.channels; channel++) {
377394
+ imageFrame.data[index + channel] = frame.data[frameIndex + channel];
377395
+ }
377396
+ }
377397
+ }
377398
+ break;
377399
+ case BlendOpType.OVER:
377400
+ for (let row = 0;row < frame.height; row++) {
377401
+ for (let col = 0;col < frame.width; col++) {
377402
+ const { index, frameIndex } = calculatePixelIndices(row, col);
377403
+ for (let channel = 0;channel < this._png.channels; channel++) {
377404
+ const sourceAlpha = frame.data[frameIndex + this._png.channels - 1] / maxValue;
377405
+ const foregroundValue = channel % (this._png.channels - 1) === 0 ? 1 : frame.data[frameIndex + channel];
377406
+ const value = Math.floor(sourceAlpha * foregroundValue + (1 - sourceAlpha) * imageFrame.data[index + channel]);
377407
+ imageFrame.data[index + channel] += value;
377408
+ }
377409
+ }
377410
+ }
377411
+ break;
377412
+ default:
377413
+ throw new Error("Unknown blendOp");
377414
+ }
377415
+ }
377416
+ decodeImage() {
377417
+ const data = this._inflatorResult;
377418
+ if (this._filterMethod !== FilterMethod.ADAPTIVE) {
377419
+ throw new Error(`Filter method ${this._filterMethod} not supported`);
377420
+ }
377421
+ if (this._interlaceMethod === InterlaceMethod.NO_INTERLACE) {
377422
+ this._png.data = decodeInterlaceNull({
377423
+ data,
377424
+ width: this._png.width,
377425
+ height: this._png.height,
377426
+ channels: this._png.channels,
377427
+ depth: this._png.depth
377428
+ });
377429
+ } else if (this._interlaceMethod === InterlaceMethod.ADAM7) {
377430
+ this._png.data = decodeInterlaceAdam7({
377431
+ data,
377432
+ width: this._png.width,
377433
+ height: this._png.height,
377434
+ channels: this._png.channels,
377435
+ depth: this._png.depth
377436
+ });
377437
+ } else {
377438
+ throw new Error(`Interlace method ${this._interlaceMethod} not supported`);
377439
+ }
377440
+ if (this._hasPalette) {
377441
+ this._png.palette = this._palette;
377442
+ }
377443
+ if (this._hasTransparency) {
377444
+ this._png.transparency = this._transparency;
377445
+ }
377446
+ }
377447
+ pushDataToFrame() {
377448
+ this._inflator.push(new Uint8Array(0), true);
377449
+ const result = this._inflatorResult;
377450
+ const lastFrame = this._frames.at(-1);
377451
+ if (lastFrame) {
377452
+ lastFrame.data = result;
377453
+ } else {
377454
+ this._frames.push({
377455
+ sequenceNumber: 0,
377456
+ width: this._png.width,
377457
+ height: this._png.height,
377458
+ xOffset: 0,
377459
+ yOffset: 0,
377460
+ delayNumber: 0,
377461
+ delayDenominator: 0,
377462
+ disposeOp: DisposeOpType.NONE,
377463
+ blendOp: BlendOpType.SOURCE,
377464
+ data: result
377465
+ });
377466
+ }
377467
+ this._inflator = new Unzlib((chunk, final) => {
377468
+ this._chunks.push(chunk);
377469
+ if (final) {
377470
+ const totalLength = this._chunks.reduce((sum, c4) => sum + c4.length, 0);
377471
+ this._inflatorResult = new Uint8Array(totalLength);
377472
+ let offset = 0;
377473
+ for (const chunk2 of this._chunks) {
377474
+ this._inflatorResult.set(chunk2, offset);
377475
+ offset += chunk2.length;
377476
+ }
377477
+ this._chunks = [];
377478
+ }
377479
+ });
377480
+ this._chunks = [];
377481
+ this._writingDataChunks = false;
377482
+ }
377483
+ }
377484
+ function checkBitDepth(value) {
377485
+ if (value !== 1 && value !== 2 && value !== 4 && value !== 8 && value !== 16) {
377486
+ throw new Error(`invalid bit depth: ${value}`);
377487
+ }
377488
+ return value;
377489
+ }
377490
+
377491
+ // node_modules/fast-png/lib/png_encoder.js
377492
+ var defaultZlibOptions = {
377493
+ level: 3
377494
+ };
377495
+
377496
+ class PngEncoder extends IOBuffer {
377497
+ _png;
377498
+ _zlibOptions;
377499
+ _colorType;
377500
+ _interlaceMethod;
377501
+ constructor(data, options = {}) {
377502
+ super();
377503
+ this._colorType = ColorType.UNKNOWN;
377504
+ this._zlibOptions = { ...defaultZlibOptions, ...options.zlib };
377505
+ this._png = this._checkData(data);
377506
+ this._interlaceMethod = (options.interlace === "Adam7" ? InterlaceMethod.ADAM7 : InterlaceMethod.NO_INTERLACE) ?? InterlaceMethod.NO_INTERLACE;
377507
+ this.setBigEndian();
377508
+ }
377509
+ encode() {
377510
+ writeSignature(this);
377511
+ this.encodeIHDR();
377512
+ if (this._png.palette) {
377513
+ this.encodePLTE();
377514
+ if (this._png.palette[0].length === 4) {
377515
+ this.encodeTRNS();
377516
+ }
377517
+ }
377518
+ this.encodeData();
377519
+ if (this._png.text) {
377520
+ for (const [keyword, text] of Object.entries(this._png.text)) {
377521
+ encodetEXt(this, keyword, text);
377522
+ }
377523
+ }
377524
+ this.encodeIEND();
377525
+ return this.toArray();
377526
+ }
377527
+ encodeIHDR() {
377528
+ this.writeUint32(13);
377529
+ this.writeChars("IHDR");
377530
+ this.writeUint32(this._png.width);
377531
+ this.writeUint32(this._png.height);
377532
+ this.writeByte(this._png.depth);
377533
+ this.writeByte(this._colorType);
377534
+ this.writeByte(CompressionMethod.DEFLATE);
377535
+ this.writeByte(FilterMethod.ADAPTIVE);
377536
+ this.writeByte(this._interlaceMethod);
377537
+ writeCrc(this, 17);
377538
+ }
377539
+ encodeIEND() {
377540
+ this.writeUint32(0);
377541
+ this.writeChars("IEND");
377542
+ writeCrc(this, 4);
377543
+ }
377544
+ encodePLTE() {
377545
+ const paletteLength = this._png.palette?.length * 3;
377546
+ this.writeUint32(paletteLength);
377547
+ this.writeChars("PLTE");
377548
+ for (const color of this._png.palette) {
377549
+ this.writeByte(color[0]);
377550
+ this.writeByte(color[1]);
377551
+ this.writeByte(color[2]);
377552
+ }
377553
+ writeCrc(this, 4 + paletteLength);
377554
+ }
377555
+ encodeTRNS() {
377556
+ const alpha = this._png.palette.filter((color) => {
377557
+ return color.at(-1) !== 255;
377558
+ });
377559
+ this.writeUint32(alpha.length);
377560
+ this.writeChars("tRNS");
377561
+ for (const el5 of alpha) {
377562
+ this.writeByte(el5.at(-1));
377563
+ }
377564
+ writeCrc(this, 4 + alpha.length);
377565
+ }
377566
+ encodeIDAT(data) {
377567
+ this.writeUint32(data.length);
377568
+ this.writeChars("IDAT");
377569
+ this.writeBytes(data);
377570
+ writeCrc(this, data.length + 4);
377571
+ }
377572
+ encodeData() {
377573
+ const { width, height, channels, depth, data } = this._png;
377574
+ const slotsPerLine = depth <= 8 ? Math.ceil(width * depth / 8) * channels : Math.ceil(width * depth / 8 * channels / 2);
377575
+ const newData = new IOBuffer().setBigEndian();
377576
+ let offset = 0;
377577
+ if (this._interlaceMethod === InterlaceMethod.NO_INTERLACE) {
377578
+ for (let i4 = 0;i4 < height; i4++) {
377579
+ newData.writeByte(0);
377580
+ if (depth === 16) {
377581
+ offset = writeDataUint16(data, newData, slotsPerLine, offset);
377582
+ } else {
377583
+ offset = writeDataBytes(data, newData, slotsPerLine, offset);
377584
+ }
377585
+ }
377586
+ } else if (this._interlaceMethod === InterlaceMethod.ADAM7) {
377587
+ offset = writeDataInterlaced(this._png, data, newData, offset);
377588
+ }
377589
+ const buffer = newData.toArray();
377590
+ const compressed = zlibSync(buffer, this._zlibOptions);
377591
+ this.encodeIDAT(compressed);
377592
+ }
377593
+ _checkData(data) {
377594
+ const { colorType, channels, depth } = getColorType(data, data.palette);
377595
+ const png = {
377596
+ width: checkInteger(data.width, "width"),
377597
+ height: checkInteger(data.height, "height"),
377598
+ channels,
377599
+ data: data.data,
377600
+ depth,
377601
+ text: data.text,
377602
+ palette: data.palette
377603
+ };
377604
+ this._colorType = colorType;
377605
+ const expectedSize = depth < 8 ? Math.ceil(png.width * depth / 8) * png.height * channels : png.width * png.height * channels;
377606
+ if (png.data.length !== expectedSize) {
377607
+ throw new RangeError(`wrong data size. Found ${png.data.length}, expected ${expectedSize}`);
377608
+ }
377609
+ return png;
377610
+ }
377611
+ }
377612
+ function checkInteger(value, name) {
377613
+ if (Number.isInteger(value) && value > 0) {
377614
+ return value;
377615
+ }
377616
+ throw new TypeError(`${name} must be a positive integer`);
377617
+ }
377618
+ function getColorType(data, palette) {
377619
+ const { channels = 4, depth = 8 } = data;
377620
+ if (channels !== 4 && channels !== 3 && channels !== 2 && channels !== 1) {
377621
+ throw new RangeError(`unsupported number of channels: ${channels}`);
377622
+ }
377623
+ const returnValue = {
377624
+ channels,
377625
+ depth,
377626
+ colorType: ColorType.UNKNOWN
377627
+ };
377628
+ switch (channels) {
377629
+ case 4:
377630
+ returnValue.colorType = ColorType.TRUECOLOUR_ALPHA;
377631
+ break;
377632
+ case 3:
377633
+ returnValue.colorType = ColorType.TRUECOLOUR;
377634
+ break;
377635
+ case 1:
377636
+ if (palette) {
377637
+ returnValue.colorType = ColorType.INDEXED_COLOUR;
377638
+ } else {
377639
+ returnValue.colorType = ColorType.GREYSCALE;
377640
+ }
377641
+ break;
377642
+ case 2:
377643
+ returnValue.colorType = ColorType.GREYSCALE_ALPHA;
377644
+ break;
377645
+ default:
377646
+ throw new Error("unsupported number of channels");
377647
+ }
377648
+ return returnValue;
377649
+ }
377650
+ function writeDataBytes(data, newData, slotsPerLine, offset) {
377651
+ for (let j5 = 0;j5 < slotsPerLine; j5++) {
377652
+ newData.writeByte(data[offset++]);
377653
+ }
377654
+ return offset;
377655
+ }
377656
+ function writeDataInterlaced(imageData, data, newData, offset) {
377657
+ const passes = [
377658
+ { x: 0, y: 0, xStep: 8, yStep: 8 },
377659
+ { x: 4, y: 0, xStep: 8, yStep: 8 },
377660
+ { x: 0, y: 4, xStep: 4, yStep: 8 },
377661
+ { x: 2, y: 0, xStep: 4, yStep: 4 },
377662
+ { x: 0, y: 2, xStep: 2, yStep: 4 },
377663
+ { x: 1, y: 0, xStep: 2, yStep: 2 },
377664
+ { x: 0, y: 1, xStep: 1, yStep: 2 }
377665
+ ];
377666
+ const { width, height, channels, depth } = imageData;
377667
+ let pixelSize;
377668
+ if (depth === 16) {
377669
+ pixelSize = channels * depth / 8 / 2;
377670
+ } else {
377671
+ pixelSize = channels * depth / 8;
377672
+ }
377673
+ for (let passIndex = 0;passIndex < 7; passIndex++) {
377674
+ const pass = passes[passIndex];
377675
+ const passWidth = Math.floor((width - pass.x + pass.xStep - 1) / pass.xStep);
377676
+ const passHeight = Math.floor((height - pass.y + pass.yStep - 1) / pass.yStep);
377677
+ if (passWidth <= 0 || passHeight <= 0)
377678
+ continue;
377679
+ const passLineBytes = passWidth * pixelSize;
377680
+ for (let y5 = 0;y5 < passHeight; y5++) {
377681
+ const imageY = pass.y + y5 * pass.yStep;
377682
+ const rawScanline = depth <= 8 ? new Uint8Array(passLineBytes) : new Uint16Array(passLineBytes);
377683
+ let rawOffset = 0;
377684
+ for (let x4 = 0;x4 < passWidth; x4++) {
377685
+ const imageX = pass.x + x4 * pass.xStep;
377686
+ if (imageX < width && imageY < height) {
377687
+ const srcPos = (imageY * width + imageX) * pixelSize;
377688
+ for (let i4 = 0;i4 < pixelSize; i4++) {
377689
+ rawScanline[rawOffset++] = data[srcPos + i4];
377690
+ }
377691
+ }
377692
+ }
377693
+ newData.writeByte(0);
377694
+ if (depth === 8) {
377695
+ newData.writeBytes(rawScanline);
377696
+ } else if (depth === 16) {
377697
+ for (const value of rawScanline) {
377698
+ newData.writeByte(value >> 8 & 255);
377699
+ newData.writeByte(value & 255);
377700
+ }
377701
+ }
377702
+ }
377703
+ }
377704
+ return offset;
377705
+ }
377706
+ function writeDataUint16(data, newData, slotsPerLine, offset) {
377707
+ for (let j5 = 0;j5 < slotsPerLine; j5++) {
377708
+ newData.writeUint16(data[offset++]);
377709
+ }
377710
+ return offset;
377711
+ }
377712
+
377713
+ // node_modules/fast-png/lib/index.js
377714
+ function decodePng(data, options) {
377715
+ const decoder = new PngDecoder(data, options);
377716
+ return decoder.decode();
377717
+ }
377718
+ function encodePng(png, options) {
377719
+ const encoder2 = new PngEncoder(png, options);
377720
+ return encoder2.encode();
377721
+ }
377722
+
377723
+ // node_modules/@tscircuit/image-utils/dist/looks-same.js
377724
+ var DEFAULT_TOLERANCE = 2.3;
377725
+ var DEFAULT_HIGHLIGHT = { R: 255, G: 0, B: 255 };
377726
+ var areColorsSame = ({
377727
+ color1,
377728
+ color2
377729
+ }) => {
377730
+ return color1.R === color2.R && color1.G === color2.G && color1.B === color2.B;
377731
+ };
377732
+ var parsePng = (buffer) => {
377733
+ try {
377734
+ const png = decodePng(buffer);
377735
+ if (png.depth !== 8)
377736
+ return null;
377737
+ const channels = png.channels;
377738
+ const source = png.data;
377739
+ const rgba = new Uint8Array(png.width * png.height * 4);
377740
+ if (channels === 4) {
377741
+ rgba.set(source);
377742
+ } else if (channels === 3) {
377743
+ for (let i4 = 0, j5 = 0;i4 < source.length; i4 += 3, j5 += 4) {
377744
+ rgba[j5] = source[i4];
377745
+ rgba[j5 + 1] = source[i4 + 1];
377746
+ rgba[j5 + 2] = source[i4 + 2];
377747
+ rgba[j5 + 3] = 255;
377748
+ }
377749
+ } else {
377750
+ return null;
377751
+ }
377752
+ return {
377753
+ width: png.width,
377754
+ height: png.height,
377755
+ data: rgba,
377756
+ getPixel: (x4, y5) => {
377757
+ const index = (y5 * png.width + x4) * 4;
377758
+ return {
377759
+ R: rgba[index],
377760
+ G: rgba[index + 1],
377761
+ B: rgba[index + 2]
377762
+ };
377763
+ }
377764
+ };
377765
+ } catch {
377766
+ return null;
377767
+ }
377768
+ };
377769
+ var getBuffer = async (input) => {
377770
+ if (Buffer.isBuffer(input))
377771
+ return input;
377772
+ return readFile(input);
377773
+ };
377774
+ var parseHexColor = (color) => {
377775
+ if (!color)
377776
+ return DEFAULT_HIGHLIGHT;
377777
+ const match = /^#?([0-9a-fA-F]{6})$/.exec(color.trim());
377778
+ if (!match)
377779
+ return DEFAULT_HIGHLIGHT;
377780
+ const hex = match[1];
377781
+ return {
377782
+ R: Number.parseInt(hex.slice(0, 2), 16),
377783
+ G: Number.parseInt(hex.slice(2, 4), 16),
377784
+ B: Number.parseInt(hex.slice(4, 6), 16)
377785
+ };
377786
+ };
377787
+ var makeCIEDE2000Comparator = (tolerance) => {
377788
+ const upperBound2 = tolerance * 6.2;
377789
+ const lowerBound = tolerance * 0.695;
377790
+ let rgbColor1 = null;
377791
+ let rgbColor2 = null;
377792
+ let labColor1 = null;
377793
+ let labColor2 = null;
377794
+ return (data) => {
377795
+ if (areColorsSame(data)) {
377796
+ return true;
377797
+ }
377798
+ let lab1 = null;
377799
+ let lab2 = null;
377800
+ if (rgbColor1 && areColorsSame({ color1: data.color1, color2: rgbColor1 })) {
377801
+ lab1 = labColor1;
377802
+ } else if (rgbColor2 && areColorsSame({ color1: data.color1, color2: rgbColor2 })) {
377803
+ lab1 = labColor2;
377804
+ }
377805
+ if (rgbColor1 && areColorsSame({ color1: data.color2, color2: rgbColor1 })) {
377806
+ lab2 = labColor1;
377807
+ } else if (rgbColor2 && areColorsSame({ color1: data.color2, color2: rgbColor2 })) {
377808
+ lab2 = labColor2;
377809
+ }
377810
+ if (!lab1) {
377811
+ lab1 = rgb_to_lab(data.color1);
377812
+ rgbColor1 = data.color1;
377813
+ labColor1 = lab1;
377814
+ }
377815
+ if (!lab2) {
377816
+ lab2 = rgb_to_lab(data.color2);
377817
+ rgbColor2 = data.color2;
377818
+ labColor2 = lab2;
377819
+ }
377820
+ const cie76 = Math.sqrt((lab1.L - lab2.L) * (lab1.L - lab2.L) + (lab1.a - lab2.a) * (lab1.a - lab2.a) + (lab1.b - lab2.b) * (lab1.b - lab2.b));
377821
+ if (cie76 >= upperBound2)
377822
+ return false;
377823
+ if (cie76 <= lowerBound)
377824
+ return true;
377825
+ return ciede2000(lab1, lab2) < tolerance;
377826
+ };
377827
+ };
377828
+ var AntialiasingComparator = class {
377829
+ _baseComparator;
377830
+ _img1;
377831
+ _img2;
377832
+ _brightnessTolerance;
377833
+ constructor(baseComparator, img1, img2, { antialiasingTolerance = 0 }) {
377834
+ this._baseComparator = baseComparator;
377835
+ this._img1 = img1;
377836
+ this._img2 = img2;
377837
+ this._brightnessTolerance = antialiasingTolerance;
377838
+ }
377839
+ compare(data) {
377840
+ return this._baseComparator(data) || this._checkIsAntialiased(data);
377841
+ }
377842
+ _checkIsAntialiased(data) {
377843
+ return this._isAntialiased(this._img2, data.x, data.y, data, this._img1) || this._isAntialiased(this._img1, data.x, data.y, data, this._img2);
377844
+ }
377845
+ _isAntialiased(img1, x13, y13, data, img2) {
377846
+ const color1 = img1.getPixel(x13, y13);
377847
+ const x03 = Math.max(x13 - 1, 0);
377848
+ const y03 = Math.max(y13 - 1, 0);
377849
+ const x25 = Math.min(x13 + 1, data.width - 1);
377850
+ const y25 = Math.min(y13 + 1, data.height - 1);
377851
+ const checkExtremePixels = !img2;
377852
+ const brightnessTolerance = checkExtremePixels ? this._brightnessTolerance : 0;
377853
+ let zeroes = 0;
377854
+ let positives = 0;
377855
+ let negatives = 0;
377856
+ let min = 0;
377857
+ let max2 = 0;
377858
+ let minX = 0;
377859
+ let minY = 0;
377860
+ let maxX = 0;
377861
+ let maxY = 0;
377862
+ for (let y5 = y03;y5 <= y25; y5 += 1) {
377863
+ for (let x4 = x03;x4 <= x25; x4 += 1) {
377864
+ if (x4 === x13 && y5 === y13)
377865
+ continue;
377866
+ const delta = this._brightnessDelta(img1.getPixel(x4, y5), color1);
377867
+ if (Math.abs(delta) <= brightnessTolerance) {
377868
+ zeroes += 1;
377869
+ } else if (delta > brightnessTolerance) {
377870
+ positives += 1;
377871
+ } else {
377872
+ negatives += 1;
377873
+ }
377874
+ if (zeroes > 2)
377875
+ return false;
377876
+ if (checkExtremePixels)
377877
+ continue;
377878
+ if (delta < min) {
377879
+ min = delta;
377880
+ minX = x4;
377881
+ minY = y5;
377882
+ }
377883
+ if (delta > max2) {
377884
+ max2 = delta;
377885
+ maxX = x4;
377886
+ maxY = y5;
377887
+ }
377888
+ }
377889
+ }
377890
+ if (checkExtremePixels)
377891
+ return true;
377892
+ if (negatives === 0 || positives === 0)
377893
+ return false;
377894
+ return !this._isAntialiased(img1, minX, minY, data) && !this._isAntialiased(img2, minX, minY, data) || !this._isAntialiased(img1, maxX, maxY, data) && !this._isAntialiased(img2, maxX, maxY, data);
377895
+ }
377896
+ _brightnessDelta(color1, color2) {
377897
+ return color1.R * 0.29889531 + color1.G * 0.58662247 + color1.B * 0.11448223 - (color2.R * 0.29889531 + color2.G * 0.58662247 + color2.B * 0.11448223);
377898
+ }
377899
+ };
377900
+ var IgnoreCaretComparator = class {
377901
+ pixelRatio;
377902
+ caretTopLeft = null;
377903
+ caretBottomRight = null;
377904
+ _baseComparator;
377905
+ _state = "init";
377906
+ constructor(baseComparator, pixelRatio) {
377907
+ this.pixelRatio = pixelRatio ? Math.floor(pixelRatio) : 1;
377908
+ this._baseComparator = baseComparator;
377909
+ }
377910
+ compare(data) {
377911
+ return this._baseComparator(data) || this._checkIsCaret(data);
377912
+ }
377913
+ _checkIsCaret(data) {
377914
+ if (this._state === "caretDetected") {
377915
+ return this.caretTopLeft !== null && this.caretBottomRight !== null && data.x >= this.caretTopLeft.x && data.x <= this.caretBottomRight.x && data.y >= this.caretTopLeft.y && data.y <= this.caretBottomRight.y;
377916
+ }
377917
+ if (this.caretTopLeft && this.caretBottomRight && data.x >= this.caretTopLeft.x && data.x <= this.caretBottomRight.x && data.y >= this.caretTopLeft.y && data.y <= this.caretBottomRight.y) {
377918
+ return true;
377919
+ }
377920
+ const lastCaretPoint = this._getLastCaretPoint(data);
377921
+ if (!this._looksLikeCaret({ x: data.x, y: data.y }, lastCaretPoint)) {
377922
+ return false;
377923
+ }
377924
+ this.caretTopLeft = { x: data.x, y: data.y };
377925
+ this.caretBottomRight = lastCaretPoint;
377926
+ this._state = "caretDetected";
377927
+ return true;
377928
+ }
377929
+ _getLastCaretPoint(data) {
377930
+ let currPoint = { x: data.x, y: data.y };
377931
+ while (true) {
377932
+ const nextPoint = this._getNextCaretPoint({ x: data.x, y: data.y }, currPoint);
377933
+ if (this._isPointOutsideImages(nextPoint, data) || this._areColorsSame(nextPoint, data)) {
377934
+ return currPoint;
377935
+ }
377936
+ currPoint = nextPoint;
377937
+ }
377938
+ }
377939
+ _isPointOutsideImages(point6, data) {
377940
+ return point6.x >= data.minWidth || point6.y >= data.minHeight;
377941
+ }
377942
+ _areColorsSame(point6, data) {
377943
+ const color1 = data.img1.getPixel(point6.x, point6.y);
377944
+ const color2 = data.img2.getPixel(point6.x, point6.y);
377945
+ return areColorsSame({ color1, color2 });
377946
+ }
377947
+ _getNextCaretPoint(firstCaretPoint, currPoint) {
377948
+ const nextX = currPoint.x + 1;
377949
+ return nextX < firstCaretPoint.x + this.pixelRatio ? { x: nextX, y: currPoint.y } : { x: firstCaretPoint.x, y: currPoint.y + 1 };
377950
+ }
377951
+ _looksLikeCaret(firstCaretPoint, lastCaretPoint) {
377952
+ return this._caretHeight(firstCaretPoint, lastCaretPoint) > 1 && this._caretWidth(firstCaretPoint, lastCaretPoint) === this.pixelRatio;
377953
+ }
377954
+ _caretHeight(firstCaretPoint, lastCaretPoint) {
377955
+ return lastCaretPoint.y - firstCaretPoint.y + 1;
377956
+ }
377957
+ _caretWidth(firstCaretPoint, lastCaretPoint) {
377958
+ return lastCaretPoint.x - firstCaretPoint.x + 1;
377959
+ }
377960
+ };
377961
+ var prepareOptions = (options = {}) => {
377962
+ if (options.strict && options.tolerance !== undefined) {
377963
+ throw new TypeError('Unable to use "strict" and "tolerance" options together');
377964
+ }
377965
+ if (options.percentThreshold !== undefined && (!Number.isFinite(options.percentThreshold) || options.percentThreshold < 0)) {
377966
+ throw new TypeError('Expected "percentThreshold" to be a non-negative number');
377967
+ }
377968
+ return {
377969
+ strict: Boolean(options.strict),
377970
+ tolerance: options.tolerance ?? DEFAULT_TOLERANCE,
377971
+ ignoreCaret: options.ignoreCaret ?? true,
377972
+ ignoreAntialiasing: options.ignoreAntialiasing ?? true,
377973
+ antialiasingTolerance: options.antialiasingTolerance ?? 0,
377974
+ pixelRatio: options.pixelRatio
377975
+ };
377976
+ };
377977
+ var createComparator = (img1, img2, options) => {
377978
+ let comparator = options.strict ? (data) => areColorsSame(data) : makeCIEDE2000Comparator(options.tolerance);
377979
+ if (options.ignoreAntialiasing) {
377980
+ const antialiasingComparator = new AntialiasingComparator(comparator, img1, img2, options);
377981
+ comparator = (data) => antialiasingComparator.compare(data);
377982
+ }
377983
+ if (options.ignoreCaret) {
377984
+ const caretComparator = new IgnoreCaretComparator(comparator, options.pixelRatio);
377985
+ comparator = (data) => caretComparator.compare(data);
377986
+ }
377987
+ return comparator;
377988
+ };
377989
+ var compare = async (buffer1, buffer2, options) => {
377990
+ const reference = parsePng(buffer1);
377991
+ const current3 = parsePng(buffer2);
377992
+ if (!reference || !current3) {
377993
+ return { equal: buffer1.equals(buffer2) };
377994
+ }
377995
+ const comparator = createComparator(reference, current3, options);
377996
+ const width = Math.max(reference.width, current3.width);
377997
+ const height = Math.max(reference.height, current3.height);
377998
+ const minWidth = Math.min(reference.width, current3.width);
377999
+ const minHeight = Math.min(reference.height, current3.height);
378000
+ const totalPixels = width * height;
378001
+ let differentPixels = 0;
378002
+ for (let y5 = 0;y5 < height; y5 += 1) {
378003
+ for (let x4 = 0;x4 < width; x4 += 1) {
378004
+ if (x4 >= minWidth || y5 >= minHeight) {
378005
+ differentPixels += 1;
378006
+ continue;
378007
+ }
378008
+ const color1 = reference.getPixel(x4, y5);
378009
+ const color2 = current3.getPixel(x4, y5);
378010
+ const same = areColorsSame({ color1, color2 }) || comparator({
378011
+ color1,
378012
+ color2,
378013
+ img1: reference,
378014
+ img2: current3,
378015
+ x: x4,
378016
+ y: y5,
378017
+ width,
378018
+ height,
378019
+ minWidth,
378020
+ minHeight
378021
+ });
378022
+ if (!same) {
378023
+ differentPixels += 1;
378024
+ }
378025
+ }
378026
+ }
378027
+ return {
378028
+ equal: differentPixels === 0,
378029
+ differentPixels,
378030
+ totalPixels
378031
+ };
378032
+ };
378033
+ var looksSameImpl = async (reference, current3, options = {}) => {
378034
+ const prepared = prepareOptions(options);
378035
+ const referenceBuffer = await getBuffer(reference);
378036
+ const currentBuffer = await getBuffer(current3);
378037
+ return compare(referenceBuffer, currentBuffer, prepared);
378038
+ };
378039
+ var createDiff = async ({
378040
+ reference,
378041
+ current: current3,
378042
+ diff: diff2,
378043
+ highlightColor,
378044
+ ...options
378045
+ }) => {
378046
+ const prepared = prepareOptions(options);
378047
+ const referenceBuffer = await getBuffer(reference);
378048
+ const currentBuffer = await getBuffer(current3);
378049
+ const referencePng = parsePng(referenceBuffer);
378050
+ const currentPng = parsePng(currentBuffer);
378051
+ if (!(diff2.endsWith(".png") && referencePng && currentPng)) {
378052
+ await writeFile(diff2, currentBuffer);
378053
+ return;
378054
+ }
378055
+ const comparator = createComparator(referencePng, currentPng, prepared);
378056
+ const width = Math.max(referencePng.width, currentPng.width);
378057
+ const height = Math.max(referencePng.height, currentPng.height);
378058
+ const minWidth = Math.min(referencePng.width, currentPng.width);
378059
+ const minHeight = Math.min(referencePng.height, currentPng.height);
378060
+ const highlight = parseHexColor(highlightColor);
378061
+ const diffData = new Uint8Array(width * height * 4);
378062
+ for (let y5 = 0;y5 < height; y5 += 1) {
378063
+ for (let x4 = 0;x4 < width; x4 += 1) {
378064
+ const index = (y5 * width + x4) * 4;
378065
+ if (x4 >= minWidth || y5 >= minHeight) {
378066
+ diffData[index] = highlight.R;
378067
+ diffData[index + 1] = highlight.G;
378068
+ diffData[index + 2] = highlight.B;
378069
+ diffData[index + 3] = 255;
378070
+ continue;
378071
+ }
378072
+ const color1 = referencePng.getPixel(x4, y5);
378073
+ const color2 = currentPng.getPixel(x4, y5);
378074
+ const same = areColorsSame({ color1, color2 }) || comparator({
378075
+ color1,
378076
+ color2,
378077
+ img1: referencePng,
378078
+ img2: currentPng,
378079
+ x: x4,
378080
+ y: y5,
378081
+ width,
378082
+ height,
378083
+ minWidth,
378084
+ minHeight
378085
+ });
378086
+ if (same) {
378087
+ diffData[index] = color1.R;
378088
+ diffData[index + 1] = color1.G;
378089
+ diffData[index + 2] = color1.B;
378090
+ diffData[index + 3] = 255;
378091
+ } else {
378092
+ diffData[index] = highlight.R;
378093
+ diffData[index + 1] = highlight.G;
378094
+ diffData[index + 2] = highlight.B;
378095
+ diffData[index + 3] = 255;
378096
+ }
378097
+ }
378098
+ }
378099
+ const encoded = encodePng({
378100
+ width,
378101
+ height,
378102
+ data: diffData,
378103
+ channels: 4,
378104
+ depth: 8
378105
+ });
378106
+ await writeFile(diff2, Buffer.from(encoded));
378107
+ };
378108
+ var looksSame = Object.assign(looksSameImpl, { createDiff });
378109
+ var looks_same_default = looksSame;
378110
+
375420
378111
  // lib/shared/compare-images.ts
375421
- import looksSame from "looks-same";
375422
378112
  import fs64 from "node:fs/promises";
375423
- var compareAndCreateDiff = async (buffer1, buffer2, diffPath, createDiff = true) => {
375424
- const { equal: equal3 } = await looksSame(buffer1, buffer2, {
378113
+ var compareAndCreateDiff = async (buffer1, buffer2, diffPath, createDiff2 = true) => {
378114
+ const { equal: equal3 } = await looks_same_default(buffer1, buffer2, {
375425
378115
  strict: false,
375426
378116
  tolerance: 2
375427
378117
  });
375428
- if (!equal3 && createDiff) {
378118
+ if (!equal3 && createDiff2) {
375429
378119
  if (diffPath.endsWith(".png")) {
375430
- await looksSame.createDiff({
378120
+ await looks_same_default.createDiff({
375431
378121
  reference: buffer1,
375432
378122
  current: buffer2,
375433
378123
  diff: diffPath,
@@ -375453,7 +378143,7 @@ var processSnapshotFile = async ({
375453
378143
  forceUpdate,
375454
378144
  platformConfig: platformConfig3,
375455
378145
  pcbSnapshotSettings,
375456
- createDiff,
378146
+ createDiff: createDiff2,
375457
378147
  cameraPreset
375458
378148
  }) => {
375459
378149
  const relativeFilePath = path65.relative(projectDir, file);
@@ -375603,7 +378293,7 @@ var processSnapshotFile = async ({
375603
378293
  const oldContentBuffer = fs65.readFileSync(snapPath);
375604
378294
  let equal3;
375605
378295
  let diffPath;
375606
- if (createDiff) {
378296
+ if (createDiff2) {
375607
378297
  diffPath = snapPath.replace(is3d ? ".snap.png" : ".snap.svg", is3d ? ".diff.png" : ".diff.svg");
375608
378298
  const comparison = await compareAndCreateDiff(oldContentBuffer, newContentBuffer, diffPath, true);
375609
378299
  equal3 = comparison.equal;
@@ -375651,7 +378341,7 @@ var snapshotProject = async ({
375651
378341
  onError = (msg) => console.error(msg),
375652
378342
  onSuccess = (msg) => console.log(msg),
375653
378343
  platformConfig: platformConfig3,
375654
- createDiff = false,
378344
+ createDiff: createDiff2 = false,
375655
378345
  cameraPreset,
375656
378346
  concurrency = 1
375657
378347
  } = {}) => {
@@ -375722,7 +378412,7 @@ var snapshotProject = async ({
375722
378412
  forceUpdate,
375723
378413
  platformConfig: platformConfig3,
375724
378414
  pcbSnapshotSettings: projectConfig3?.pcbSnapshotSettings,
375725
- createDiff,
378415
+ createDiff: createDiff2,
375726
378416
  cameraPreset
375727
378417
  },
375728
378418
  stopOnFailure: true,
@@ -375761,7 +378451,7 @@ var snapshotProject = async ({
375761
378451
  forceUpdate,
375762
378452
  platformConfig: platformConfig3,
375763
378453
  pcbSnapshotSettings: projectConfig3?.pcbSnapshotSettings,
375764
- createDiff,
378454
+ createDiff: createDiff2,
375765
378455
  cameraPreset
375766
378456
  });
375767
378457
  processResult(result);
@@ -375908,13 +378598,13 @@ program2.command("version").description("Print CLI version").option("--verbose",
375908
378598
  console.log(getVersion({ verbose: options.verbose }));
375909
378599
  });
375910
378600
  if (process.argv.length === 2) {
375911
- import_perfect_cli.perfectCli(program2, process.argv).catch((err) => {
375912
- if (err instanceof Error && err.name === "TypeError") {
378601
+ import_perfect_cli.perfectCli(program2, process.argv).catch((err2) => {
378602
+ if (err2 instanceof Error && err2.name === "TypeError") {
375913
378603
  console.error(`
375914
378604
  Aborted.`);
375915
378605
  process.exit(130);
375916
378606
  }
375917
- throw err;
378607
+ throw err2;
375918
378608
  });
375919
378609
  } else {
375920
378610
  program2.parse();