@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.
@@ -13257,17 +13257,2708 @@ function getCompletePlatformConfig(userConfig) {
13257
13257
  // lib/shared/process-snapshot-file.ts
13258
13258
  import { renderGLTFToPNGBufferFromGLBBuffer } from "poppygl";
13259
13259
 
13260
+ // node_modules/@tscircuit/image-utils/dist/looks-same.js
13261
+ import { readFile, writeFile } from "fs/promises";
13262
+
13263
+ // node_modules/color-diff/lib/convert.js
13264
+ function rgbaToLab(c, bc) {
13265
+ bc = normalize(bc || { R: 255, G: 255, B: 255 });
13266
+ c = normalize(c);
13267
+ let newC = c;
13268
+ if (c.A !== undefined) {
13269
+ newC = {
13270
+ R: bc.R + (c.R - bc.R) * c.A,
13271
+ G: bc.G + (c.G - bc.G) * c.A,
13272
+ B: bc.B + (c.B - bc.B) * c.A
13273
+ };
13274
+ }
13275
+ return xyzToLab(rgbToXyz(newC));
13276
+ }
13277
+ function rgbToXyz(c) {
13278
+ let R = c.R / 255;
13279
+ let G = c.G / 255;
13280
+ let B = c.B / 255;
13281
+ if (R > 0.04045)
13282
+ R = Math.pow((R + 0.055) / 1.055, 2.4);
13283
+ else
13284
+ R = R / 12.92;
13285
+ if (G > 0.04045)
13286
+ G = Math.pow((G + 0.055) / 1.055, 2.4);
13287
+ else
13288
+ G = G / 12.92;
13289
+ if (B > 0.04045)
13290
+ B = Math.pow((B + 0.055) / 1.055, 2.4);
13291
+ else
13292
+ B = B / 12.92;
13293
+ R *= 100;
13294
+ G *= 100;
13295
+ B *= 100;
13296
+ const X = R * 0.4124 + G * 0.3576 + B * 0.1805;
13297
+ const Y = R * 0.2126 + G * 0.7152 + B * 0.0722;
13298
+ const Z = R * 0.0193 + G * 0.1192 + B * 0.9505;
13299
+ return { X, Y, Z };
13300
+ }
13301
+ function xyzToLab(c) {
13302
+ const refY = 100;
13303
+ const refZ = 108.883;
13304
+ const refX = 95.047;
13305
+ let Y = c.Y / refY;
13306
+ let Z = c.Z / refZ;
13307
+ let X = c.X / refX;
13308
+ if (X > 0.008856)
13309
+ X = Math.pow(X, 1 / 3);
13310
+ else
13311
+ X = 7.787 * X + 16 / 116;
13312
+ if (Y > 0.008856)
13313
+ Y = Math.pow(Y, 1 / 3);
13314
+ else
13315
+ Y = 7.787 * Y + 16 / 116;
13316
+ if (Z > 0.008856)
13317
+ Z = Math.pow(Z, 1 / 3);
13318
+ else
13319
+ Z = 7.787 * Z + 16 / 116;
13320
+ const L = 116 * Y - 16;
13321
+ const a = 500 * (X - Y);
13322
+ const b = 200 * (Y - Z);
13323
+ return { L, a, b };
13324
+ }
13325
+ function normalize(c) {
13326
+ let r, g, b, a;
13327
+ if ("R" in c) {
13328
+ r = c.R;
13329
+ g = c.G;
13330
+ b = c.B;
13331
+ a = c.A;
13332
+ } else {
13333
+ r = c.r;
13334
+ g = c.g;
13335
+ b = c.b;
13336
+ a = c.a;
13337
+ }
13338
+ const normalizedC = { R: r, G: g, B: b };
13339
+ if (a !== undefined)
13340
+ normalizedC.A = a;
13341
+ return normalizedC;
13342
+ }
13343
+
13344
+ // node_modules/color-diff/lib/diff.js
13345
+ function ciede2000(c1, c2, bc) {
13346
+ if ("R" in c1 || "r" in c1) {
13347
+ c1 = rgbaToLab(c1, bc);
13348
+ }
13349
+ if ("R" in c2 || "r" in c2) {
13350
+ c2 = rgbaToLab(c2, bc);
13351
+ }
13352
+ const L1 = c1.L;
13353
+ const a1 = c1.a;
13354
+ const b1 = c1.b;
13355
+ const L2 = c2.L;
13356
+ const a2 = c2.a;
13357
+ const b2 = c2.b;
13358
+ const kL = 1;
13359
+ const kC = 1;
13360
+ const kH = 1;
13361
+ const C1 = Math.sqrt(Math.pow(a1, 2) + Math.pow(b1, 2));
13362
+ const C2 = Math.sqrt(Math.pow(a2, 2) + Math.pow(b2, 2));
13363
+ const aC1C2 = (C1 + C2) / 2;
13364
+ const G = 0.5 * (1 - Math.sqrt(Math.pow(aC1C2, 7) / (Math.pow(aC1C2, 7) + Math.pow(25, 7))));
13365
+ const a1p = (1 + G) * a1;
13366
+ const a2p = (1 + G) * a2;
13367
+ const C1p = Math.sqrt(Math.pow(a1p, 2) + Math.pow(b1, 2));
13368
+ const C2p = Math.sqrt(Math.pow(a2p, 2) + Math.pow(b2, 2));
13369
+ const h1p = hpF(b1, a1p);
13370
+ const h2p = hpF(b2, a2p);
13371
+ const dLp = L2 - L1;
13372
+ const dCp = C2p - C1p;
13373
+ const dhp = dhpF(C1, C2, h1p, h2p);
13374
+ const dHp = 2 * Math.sqrt(C1p * C2p) * Math.sin(radians(dhp) / 2);
13375
+ const aL = (L1 + L2) / 2;
13376
+ const aCp = (C1p + C2p) / 2;
13377
+ const aHp = aHpF(C1, C2, h1p, h2p);
13378
+ const T = 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));
13379
+ const dRo = 30 * Math.exp(-Math.pow((aHp - 275) / 25, 2));
13380
+ const RC = Math.sqrt(Math.pow(aCp, 7) / (Math.pow(aCp, 7) + Math.pow(25, 7)));
13381
+ const SL = 1 + 0.015 * Math.pow(aL - 50, 2) / Math.sqrt(20 + Math.pow(aL - 50, 2));
13382
+ const SC = 1 + 0.045 * aCp;
13383
+ const SH = 1 + 0.015 * aCp * T;
13384
+ const RT = -2 * RC * Math.sin(radians(2 * dRo));
13385
+ 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)));
13386
+ return dE;
13387
+ }
13388
+ function degrees(n) {
13389
+ return n * (180 / Math.PI);
13390
+ }
13391
+ function radians(n) {
13392
+ return n * (Math.PI / 180);
13393
+ }
13394
+ function hpF(x, y) {
13395
+ if (x === 0 && y === 0)
13396
+ return 0;
13397
+ else {
13398
+ const tmphp = degrees(Math.atan2(x, y));
13399
+ if (tmphp >= 0)
13400
+ return tmphp;
13401
+ else
13402
+ return tmphp + 360;
13403
+ }
13404
+ }
13405
+ function dhpF(C1, C2, h1p, h2p) {
13406
+ if (C1 * C2 === 0)
13407
+ return 0;
13408
+ else if (Math.abs(h2p - h1p) <= 180)
13409
+ return h2p - h1p;
13410
+ else if (h2p - h1p > 180)
13411
+ return h2p - h1p - 360;
13412
+ else if (h2p - h1p < -180)
13413
+ return h2p - h1p + 360;
13414
+ else
13415
+ throw new Error;
13416
+ }
13417
+ function aHpF(C1, C2, h1p, h2p) {
13418
+ if (C1 * C2 === 0)
13419
+ return h1p + h2p;
13420
+ else if (Math.abs(h1p - h2p) <= 180)
13421
+ return (h1p + h2p) / 2;
13422
+ else if (Math.abs(h1p - h2p) > 180 && h1p + h2p < 360)
13423
+ return (h1p + h2p + 360) / 2;
13424
+ else if (Math.abs(h1p - h2p) > 180 && h1p + h2p >= 360)
13425
+ return (h1p + h2p - 360) / 2;
13426
+ else
13427
+ throw new Error;
13428
+ }
13429
+
13430
+ // node_modules/color-diff/index.js
13431
+ function rgb_to_lab(c) {
13432
+ return rgbaToLab(c);
13433
+ }
13434
+
13435
+ // node_modules/fflate/esm/index.mjs
13436
+ import { createRequire as createRequire3 } from "module";
13437
+ var require2 = createRequire3("/");
13438
+ var Worker;
13439
+ try {
13440
+ Worker = require2("worker_threads").Worker;
13441
+ } catch (e) {}
13442
+ var u8 = Uint8Array;
13443
+ var u16 = Uint16Array;
13444
+ var i32 = Int32Array;
13445
+ 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]);
13446
+ 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]);
13447
+ var clim = new u8([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
13448
+ var freb = function(eb, start) {
13449
+ var b = new u16(31);
13450
+ for (var i = 0;i < 31; ++i) {
13451
+ b[i] = start += 1 << eb[i - 1];
13452
+ }
13453
+ var r = new i32(b[30]);
13454
+ for (var i = 1;i < 30; ++i) {
13455
+ for (var j = b[i];j < b[i + 1]; ++j) {
13456
+ r[j] = j - b[i] << 5 | i;
13457
+ }
13458
+ }
13459
+ return { b, r };
13460
+ };
13461
+ var _a = freb(fleb, 2);
13462
+ var fl = _a.b;
13463
+ var revfl = _a.r;
13464
+ fl[28] = 258, revfl[258] = 28;
13465
+ var _b = freb(fdeb, 0);
13466
+ var fd = _b.b;
13467
+ var revfd = _b.r;
13468
+ var rev = new u16(32768);
13469
+ for (i = 0;i < 32768; ++i) {
13470
+ x = (i & 43690) >> 1 | (i & 21845) << 1;
13471
+ x = (x & 52428) >> 2 | (x & 13107) << 2;
13472
+ x = (x & 61680) >> 4 | (x & 3855) << 4;
13473
+ rev[i] = ((x & 65280) >> 8 | (x & 255) << 8) >> 1;
13474
+ }
13475
+ var x;
13476
+ var i;
13477
+ var hMap = function(cd, mb, r) {
13478
+ var s = cd.length;
13479
+ var i2 = 0;
13480
+ var l = new u16(mb);
13481
+ for (;i2 < s; ++i2) {
13482
+ if (cd[i2])
13483
+ ++l[cd[i2] - 1];
13484
+ }
13485
+ var le = new u16(mb);
13486
+ for (i2 = 1;i2 < mb; ++i2) {
13487
+ le[i2] = le[i2 - 1] + l[i2 - 1] << 1;
13488
+ }
13489
+ var co;
13490
+ if (r) {
13491
+ co = new u16(1 << mb);
13492
+ var rvb = 15 - mb;
13493
+ for (i2 = 0;i2 < s; ++i2) {
13494
+ if (cd[i2]) {
13495
+ var sv = i2 << 4 | cd[i2];
13496
+ var r_1 = mb - cd[i2];
13497
+ var v = le[cd[i2] - 1]++ << r_1;
13498
+ for (var m = v | (1 << r_1) - 1;v <= m; ++v) {
13499
+ co[rev[v] >> rvb] = sv;
13500
+ }
13501
+ }
13502
+ }
13503
+ } else {
13504
+ co = new u16(s);
13505
+ for (i2 = 0;i2 < s; ++i2) {
13506
+ if (cd[i2]) {
13507
+ co[i2] = rev[le[cd[i2] - 1]++] >> 15 - cd[i2];
13508
+ }
13509
+ }
13510
+ }
13511
+ return co;
13512
+ };
13513
+ var flt = new u8(288);
13514
+ for (i = 0;i < 144; ++i)
13515
+ flt[i] = 8;
13516
+ var i;
13517
+ for (i = 144;i < 256; ++i)
13518
+ flt[i] = 9;
13519
+ var i;
13520
+ for (i = 256;i < 280; ++i)
13521
+ flt[i] = 7;
13522
+ var i;
13523
+ for (i = 280;i < 288; ++i)
13524
+ flt[i] = 8;
13525
+ var i;
13526
+ var fdt = new u8(32);
13527
+ for (i = 0;i < 32; ++i)
13528
+ fdt[i] = 5;
13529
+ var i;
13530
+ var flm = /* @__PURE__ */ hMap(flt, 9, 0);
13531
+ var flrm = /* @__PURE__ */ hMap(flt, 9, 1);
13532
+ var fdm = /* @__PURE__ */ hMap(fdt, 5, 0);
13533
+ var fdrm = /* @__PURE__ */ hMap(fdt, 5, 1);
13534
+ var max = function(a) {
13535
+ var m = a[0];
13536
+ for (var i2 = 1;i2 < a.length; ++i2) {
13537
+ if (a[i2] > m)
13538
+ m = a[i2];
13539
+ }
13540
+ return m;
13541
+ };
13542
+ var bits = function(d, p, m) {
13543
+ var o = p / 8 | 0;
13544
+ return (d[o] | d[o + 1] << 8) >> (p & 7) & m;
13545
+ };
13546
+ var bits16 = function(d, p) {
13547
+ var o = p / 8 | 0;
13548
+ return (d[o] | d[o + 1] << 8 | d[o + 2] << 16) >> (p & 7);
13549
+ };
13550
+ var shft = function(p) {
13551
+ return (p + 7) / 8 | 0;
13552
+ };
13553
+ var slc = function(v, s, e) {
13554
+ if (s == null || s < 0)
13555
+ s = 0;
13556
+ if (e == null || e > v.length)
13557
+ e = v.length;
13558
+ return new u8(v.subarray(s, e));
13559
+ };
13560
+ var ec = [
13561
+ "unexpected EOF",
13562
+ "invalid block type",
13563
+ "invalid length/literal",
13564
+ "invalid distance",
13565
+ "stream finished",
13566
+ "no stream handler",
13567
+ ,
13568
+ "no callback",
13569
+ "invalid UTF-8 data",
13570
+ "extra field too long",
13571
+ "date not in range 1980-2099",
13572
+ "filename too long",
13573
+ "stream finishing",
13574
+ "invalid zip data"
13575
+ ];
13576
+ var err = function(ind, msg, nt) {
13577
+ var e = new Error(msg || ec[ind]);
13578
+ e.code = ind;
13579
+ if (Error.captureStackTrace)
13580
+ Error.captureStackTrace(e, err);
13581
+ if (!nt)
13582
+ throw e;
13583
+ return e;
13584
+ };
13585
+ var inflt = function(dat, st, buf, dict) {
13586
+ var sl = dat.length, dl = dict ? dict.length : 0;
13587
+ if (!sl || st.f && !st.l)
13588
+ return buf || new u8(0);
13589
+ var noBuf = !buf;
13590
+ var resize = noBuf || st.i != 2;
13591
+ var noSt = st.i;
13592
+ if (noBuf)
13593
+ buf = new u8(sl * 3);
13594
+ var cbuf = function(l2) {
13595
+ var bl = buf.length;
13596
+ if (l2 > bl) {
13597
+ var nbuf = new u8(Math.max(bl * 2, l2));
13598
+ nbuf.set(buf);
13599
+ buf = nbuf;
13600
+ }
13601
+ };
13602
+ var final = st.f || 0, pos = st.p || 0, bt = st.b || 0, lm = st.l, dm = st.d, lbt = st.m, dbt = st.n;
13603
+ var tbts = sl * 8;
13604
+ do {
13605
+ if (!lm) {
13606
+ final = bits(dat, pos, 1);
13607
+ var type = bits(dat, pos + 1, 3);
13608
+ pos += 3;
13609
+ if (!type) {
13610
+ var s = shft(pos) + 4, l = dat[s - 4] | dat[s - 3] << 8, t = s + l;
13611
+ if (t > sl) {
13612
+ if (noSt)
13613
+ err(0);
13614
+ break;
13615
+ }
13616
+ if (resize)
13617
+ cbuf(bt + l);
13618
+ buf.set(dat.subarray(s, t), bt);
13619
+ st.b = bt += l, st.p = pos = t * 8, st.f = final;
13620
+ continue;
13621
+ } else if (type == 1)
13622
+ lm = flrm, dm = fdrm, lbt = 9, dbt = 5;
13623
+ else if (type == 2) {
13624
+ var hLit = bits(dat, pos, 31) + 257, hcLen = bits(dat, pos + 10, 15) + 4;
13625
+ var tl = hLit + bits(dat, pos + 5, 31) + 1;
13626
+ pos += 14;
13627
+ var ldt = new u8(tl);
13628
+ var clt = new u8(19);
13629
+ for (var i2 = 0;i2 < hcLen; ++i2) {
13630
+ clt[clim[i2]] = bits(dat, pos + i2 * 3, 7);
13631
+ }
13632
+ pos += hcLen * 3;
13633
+ var clb = max(clt), clbmsk = (1 << clb) - 1;
13634
+ var clm = hMap(clt, clb, 1);
13635
+ for (var i2 = 0;i2 < tl; ) {
13636
+ var r = clm[bits(dat, pos, clbmsk)];
13637
+ pos += r & 15;
13638
+ var s = r >> 4;
13639
+ if (s < 16) {
13640
+ ldt[i2++] = s;
13641
+ } else {
13642
+ var c = 0, n = 0;
13643
+ if (s == 16)
13644
+ n = 3 + bits(dat, pos, 3), pos += 2, c = ldt[i2 - 1];
13645
+ else if (s == 17)
13646
+ n = 3 + bits(dat, pos, 7), pos += 3;
13647
+ else if (s == 18)
13648
+ n = 11 + bits(dat, pos, 127), pos += 7;
13649
+ while (n--)
13650
+ ldt[i2++] = c;
13651
+ }
13652
+ }
13653
+ var lt = ldt.subarray(0, hLit), dt = ldt.subarray(hLit);
13654
+ lbt = max(lt);
13655
+ dbt = max(dt);
13656
+ lm = hMap(lt, lbt, 1);
13657
+ dm = hMap(dt, dbt, 1);
13658
+ } else
13659
+ err(1);
13660
+ if (pos > tbts) {
13661
+ if (noSt)
13662
+ err(0);
13663
+ break;
13664
+ }
13665
+ }
13666
+ if (resize)
13667
+ cbuf(bt + 131072);
13668
+ var lms = (1 << lbt) - 1, dms = (1 << dbt) - 1;
13669
+ var lpos = pos;
13670
+ for (;; lpos = pos) {
13671
+ var c = lm[bits16(dat, pos) & lms], sym = c >> 4;
13672
+ pos += c & 15;
13673
+ if (pos > tbts) {
13674
+ if (noSt)
13675
+ err(0);
13676
+ break;
13677
+ }
13678
+ if (!c)
13679
+ err(2);
13680
+ if (sym < 256)
13681
+ buf[bt++] = sym;
13682
+ else if (sym == 256) {
13683
+ lpos = pos, lm = null;
13684
+ break;
13685
+ } else {
13686
+ var add = sym - 254;
13687
+ if (sym > 264) {
13688
+ var i2 = sym - 257, b = fleb[i2];
13689
+ add = bits(dat, pos, (1 << b) - 1) + fl[i2];
13690
+ pos += b;
13691
+ }
13692
+ var d = dm[bits16(dat, pos) & dms], dsym = d >> 4;
13693
+ if (!d)
13694
+ err(3);
13695
+ pos += d & 15;
13696
+ var dt = fd[dsym];
13697
+ if (dsym > 3) {
13698
+ var b = fdeb[dsym];
13699
+ dt += bits16(dat, pos) & (1 << b) - 1, pos += b;
13700
+ }
13701
+ if (pos > tbts) {
13702
+ if (noSt)
13703
+ err(0);
13704
+ break;
13705
+ }
13706
+ if (resize)
13707
+ cbuf(bt + 131072);
13708
+ var end = bt + add;
13709
+ if (bt < dt) {
13710
+ var shift = dl - dt, dend = Math.min(dt, end);
13711
+ if (shift + bt < 0)
13712
+ err(3);
13713
+ for (;bt < dend; ++bt)
13714
+ buf[bt] = dict[shift + bt];
13715
+ }
13716
+ for (;bt < end; ++bt)
13717
+ buf[bt] = buf[bt - dt];
13718
+ }
13719
+ }
13720
+ st.l = lm, st.p = lpos, st.b = bt, st.f = final;
13721
+ if (lm)
13722
+ final = 1, st.m = lbt, st.d = dm, st.n = dbt;
13723
+ } while (!final);
13724
+ return bt != buf.length && noBuf ? slc(buf, 0, bt) : buf.subarray(0, bt);
13725
+ };
13726
+ var wbits = function(d, p, v) {
13727
+ v <<= p & 7;
13728
+ var o = p / 8 | 0;
13729
+ d[o] |= v;
13730
+ d[o + 1] |= v >> 8;
13731
+ };
13732
+ var wbits16 = function(d, p, v) {
13733
+ v <<= p & 7;
13734
+ var o = p / 8 | 0;
13735
+ d[o] |= v;
13736
+ d[o + 1] |= v >> 8;
13737
+ d[o + 2] |= v >> 16;
13738
+ };
13739
+ var hTree = function(d, mb) {
13740
+ var t = [];
13741
+ for (var i2 = 0;i2 < d.length; ++i2) {
13742
+ if (d[i2])
13743
+ t.push({ s: i2, f: d[i2] });
13744
+ }
13745
+ var s = t.length;
13746
+ var t2 = t.slice();
13747
+ if (!s)
13748
+ return { t: et, l: 0 };
13749
+ if (s == 1) {
13750
+ var v = new u8(t[0].s + 1);
13751
+ v[t[0].s] = 1;
13752
+ return { t: v, l: 1 };
13753
+ }
13754
+ t.sort(function(a, b) {
13755
+ return a.f - b.f;
13756
+ });
13757
+ t.push({ s: -1, f: 25001 });
13758
+ var l = t[0], r = t[1], i0 = 0, i1 = 1, i22 = 2;
13759
+ t[0] = { s: -1, f: l.f + r.f, l, r };
13760
+ while (i1 != s - 1) {
13761
+ l = t[t[i0].f < t[i22].f ? i0++ : i22++];
13762
+ r = t[i0 != i1 && t[i0].f < t[i22].f ? i0++ : i22++];
13763
+ t[i1++] = { s: -1, f: l.f + r.f, l, r };
13764
+ }
13765
+ var maxSym = t2[0].s;
13766
+ for (var i2 = 1;i2 < s; ++i2) {
13767
+ if (t2[i2].s > maxSym)
13768
+ maxSym = t2[i2].s;
13769
+ }
13770
+ var tr = new u16(maxSym + 1);
13771
+ var mbt = ln(t[i1 - 1], tr, 0);
13772
+ if (mbt > mb) {
13773
+ var i2 = 0, dt = 0;
13774
+ var lft = mbt - mb, cst = 1 << lft;
13775
+ t2.sort(function(a, b) {
13776
+ return tr[b.s] - tr[a.s] || a.f - b.f;
13777
+ });
13778
+ for (;i2 < s; ++i2) {
13779
+ var i2_1 = t2[i2].s;
13780
+ if (tr[i2_1] > mb) {
13781
+ dt += cst - (1 << mbt - tr[i2_1]);
13782
+ tr[i2_1] = mb;
13783
+ } else
13784
+ break;
13785
+ }
13786
+ dt >>= lft;
13787
+ while (dt > 0) {
13788
+ var i2_2 = t2[i2].s;
13789
+ if (tr[i2_2] < mb)
13790
+ dt -= 1 << mb - tr[i2_2]++ - 1;
13791
+ else
13792
+ ++i2;
13793
+ }
13794
+ for (;i2 >= 0 && dt; --i2) {
13795
+ var i2_3 = t2[i2].s;
13796
+ if (tr[i2_3] == mb) {
13797
+ --tr[i2_3];
13798
+ ++dt;
13799
+ }
13800
+ }
13801
+ mbt = mb;
13802
+ }
13803
+ return { t: new u8(tr), l: mbt };
13804
+ };
13805
+ var ln = function(n, l, d) {
13806
+ return n.s == -1 ? Math.max(ln(n.l, l, d + 1), ln(n.r, l, d + 1)) : l[n.s] = d;
13807
+ };
13808
+ var lc = function(c) {
13809
+ var s = c.length;
13810
+ while (s && !c[--s])
13811
+ ;
13812
+ var cl = new u16(++s);
13813
+ var cli = 0, cln = c[0], cls = 1;
13814
+ var w = function(v) {
13815
+ cl[cli++] = v;
13816
+ };
13817
+ for (var i2 = 1;i2 <= s; ++i2) {
13818
+ if (c[i2] == cln && i2 != s)
13819
+ ++cls;
13820
+ else {
13821
+ if (!cln && cls > 2) {
13822
+ for (;cls > 138; cls -= 138)
13823
+ w(32754);
13824
+ if (cls > 2) {
13825
+ w(cls > 10 ? cls - 11 << 5 | 28690 : cls - 3 << 5 | 12305);
13826
+ cls = 0;
13827
+ }
13828
+ } else if (cls > 3) {
13829
+ w(cln), --cls;
13830
+ for (;cls > 6; cls -= 6)
13831
+ w(8304);
13832
+ if (cls > 2)
13833
+ w(cls - 3 << 5 | 8208), cls = 0;
13834
+ }
13835
+ while (cls--)
13836
+ w(cln);
13837
+ cls = 1;
13838
+ cln = c[i2];
13839
+ }
13840
+ }
13841
+ return { c: cl.subarray(0, cli), n: s };
13842
+ };
13843
+ var clen = function(cf, cl) {
13844
+ var l = 0;
13845
+ for (var i2 = 0;i2 < cl.length; ++i2)
13846
+ l += cf[i2] * cl[i2];
13847
+ return l;
13848
+ };
13849
+ var wfblk = function(out, pos, dat) {
13850
+ var s = dat.length;
13851
+ var o = shft(pos + 2);
13852
+ out[o] = s & 255;
13853
+ out[o + 1] = s >> 8;
13854
+ out[o + 2] = out[o] ^ 255;
13855
+ out[o + 3] = out[o + 1] ^ 255;
13856
+ for (var i2 = 0;i2 < s; ++i2)
13857
+ out[o + i2 + 4] = dat[i2];
13858
+ return (o + 4 + s) * 8;
13859
+ };
13860
+ var wblk = function(dat, out, final, syms, lf, df, eb, li, bs, bl, p) {
13861
+ wbits(out, p++, final);
13862
+ ++lf[256];
13863
+ var _a2 = hTree(lf, 15), dlt = _a2.t, mlb = _a2.l;
13864
+ var _b2 = hTree(df, 15), ddt = _b2.t, mdb = _b2.l;
13865
+ var _c = lc(dlt), lclt = _c.c, nlc = _c.n;
13866
+ var _d = lc(ddt), lcdt = _d.c, ndc = _d.n;
13867
+ var lcfreq = new u16(19);
13868
+ for (var i2 = 0;i2 < lclt.length; ++i2)
13869
+ ++lcfreq[lclt[i2] & 31];
13870
+ for (var i2 = 0;i2 < lcdt.length; ++i2)
13871
+ ++lcfreq[lcdt[i2] & 31];
13872
+ var _e = hTree(lcfreq, 7), lct = _e.t, mlcb = _e.l;
13873
+ var nlcc = 19;
13874
+ for (;nlcc > 4 && !lct[clim[nlcc - 1]]; --nlcc)
13875
+ ;
13876
+ var flen = bl + 5 << 3;
13877
+ var ftlen = clen(lf, flt) + clen(df, fdt) + eb;
13878
+ var dtlen = clen(lf, dlt) + clen(df, ddt) + eb + 14 + 3 * nlcc + clen(lcfreq, lct) + 2 * lcfreq[16] + 3 * lcfreq[17] + 7 * lcfreq[18];
13879
+ if (bs >= 0 && flen <= ftlen && flen <= dtlen)
13880
+ return wfblk(out, p, dat.subarray(bs, bs + bl));
13881
+ var lm, ll, dm, dl;
13882
+ wbits(out, p, 1 + (dtlen < ftlen)), p += 2;
13883
+ if (dtlen < ftlen) {
13884
+ lm = hMap(dlt, mlb, 0), ll = dlt, dm = hMap(ddt, mdb, 0), dl = ddt;
13885
+ var llm = hMap(lct, mlcb, 0);
13886
+ wbits(out, p, nlc - 257);
13887
+ wbits(out, p + 5, ndc - 1);
13888
+ wbits(out, p + 10, nlcc - 4);
13889
+ p += 14;
13890
+ for (var i2 = 0;i2 < nlcc; ++i2)
13891
+ wbits(out, p + 3 * i2, lct[clim[i2]]);
13892
+ p += 3 * nlcc;
13893
+ var lcts = [lclt, lcdt];
13894
+ for (var it = 0;it < 2; ++it) {
13895
+ var clct = lcts[it];
13896
+ for (var i2 = 0;i2 < clct.length; ++i2) {
13897
+ var len = clct[i2] & 31;
13898
+ wbits(out, p, llm[len]), p += lct[len];
13899
+ if (len > 15)
13900
+ wbits(out, p, clct[i2] >> 5 & 127), p += clct[i2] >> 12;
13901
+ }
13902
+ }
13903
+ } else {
13904
+ lm = flm, ll = flt, dm = fdm, dl = fdt;
13905
+ }
13906
+ for (var i2 = 0;i2 < li; ++i2) {
13907
+ var sym = syms[i2];
13908
+ if (sym > 255) {
13909
+ var len = sym >> 18 & 31;
13910
+ wbits16(out, p, lm[len + 257]), p += ll[len + 257];
13911
+ if (len > 7)
13912
+ wbits(out, p, sym >> 23 & 31), p += fleb[len];
13913
+ var dst = sym & 31;
13914
+ wbits16(out, p, dm[dst]), p += dl[dst];
13915
+ if (dst > 3)
13916
+ wbits16(out, p, sym >> 5 & 8191), p += fdeb[dst];
13917
+ } else {
13918
+ wbits16(out, p, lm[sym]), p += ll[sym];
13919
+ }
13920
+ }
13921
+ wbits16(out, p, lm[256]);
13922
+ return p + ll[256];
13923
+ };
13924
+ var deo = /* @__PURE__ */ new i32([65540, 131080, 131088, 131104, 262176, 1048704, 1048832, 2114560, 2117632]);
13925
+ var et = /* @__PURE__ */ new u8(0);
13926
+ var dflt = function(dat, lvl, plvl, pre, post, st) {
13927
+ var s = st.z || dat.length;
13928
+ var o = new u8(pre + s + 5 * (1 + Math.ceil(s / 7000)) + post);
13929
+ var w = o.subarray(pre, o.length - post);
13930
+ var lst = st.l;
13931
+ var pos = (st.r || 0) & 7;
13932
+ if (lvl) {
13933
+ if (pos)
13934
+ w[0] = st.r >> 3;
13935
+ var opt = deo[lvl - 1];
13936
+ var n = opt >> 13, c = opt & 8191;
13937
+ var msk_1 = (1 << plvl) - 1;
13938
+ var prev = st.p || new u16(32768), head = st.h || new u16(msk_1 + 1);
13939
+ var bs1_1 = Math.ceil(plvl / 3), bs2_1 = 2 * bs1_1;
13940
+ var hsh = function(i3) {
13941
+ return (dat[i3] ^ dat[i3 + 1] << bs1_1 ^ dat[i3 + 2] << bs2_1) & msk_1;
13942
+ };
13943
+ var syms = new i32(25000);
13944
+ var lf = new u16(288), df = new u16(32);
13945
+ var lc_1 = 0, eb = 0, i2 = st.i || 0, li = 0, wi = st.w || 0, bs = 0;
13946
+ for (;i2 + 2 < s; ++i2) {
13947
+ var hv = hsh(i2);
13948
+ var imod = i2 & 32767, pimod = head[hv];
13949
+ prev[imod] = pimod;
13950
+ head[hv] = imod;
13951
+ if (wi <= i2) {
13952
+ var rem = s - i2;
13953
+ if ((lc_1 > 7000 || li > 24576) && (rem > 423 || !lst)) {
13954
+ pos = wblk(dat, w, 0, syms, lf, df, eb, li, bs, i2 - bs, pos);
13955
+ li = lc_1 = eb = 0, bs = i2;
13956
+ for (var j = 0;j < 286; ++j)
13957
+ lf[j] = 0;
13958
+ for (var j = 0;j < 30; ++j)
13959
+ df[j] = 0;
13960
+ }
13961
+ var l = 2, d = 0, ch_1 = c, dif = imod - pimod & 32767;
13962
+ if (rem > 2 && hv == hsh(i2 - dif)) {
13963
+ var maxn = Math.min(n, rem) - 1;
13964
+ var maxd = Math.min(32767, i2);
13965
+ var ml = Math.min(258, rem);
13966
+ while (dif <= maxd && --ch_1 && imod != pimod) {
13967
+ if (dat[i2 + l] == dat[i2 + l - dif]) {
13968
+ var nl = 0;
13969
+ for (;nl < ml && dat[i2 + nl] == dat[i2 + nl - dif]; ++nl)
13970
+ ;
13971
+ if (nl > l) {
13972
+ l = nl, d = dif;
13973
+ if (nl > maxn)
13974
+ break;
13975
+ var mmd = Math.min(dif, nl - 2);
13976
+ var md = 0;
13977
+ for (var j = 0;j < mmd; ++j) {
13978
+ var ti = i2 - dif + j & 32767;
13979
+ var pti = prev[ti];
13980
+ var cd = ti - pti & 32767;
13981
+ if (cd > md)
13982
+ md = cd, pimod = ti;
13983
+ }
13984
+ }
13985
+ }
13986
+ imod = pimod, pimod = prev[imod];
13987
+ dif += imod - pimod & 32767;
13988
+ }
13989
+ }
13990
+ if (d) {
13991
+ syms[li++] = 268435456 | revfl[l] << 18 | revfd[d];
13992
+ var lin = revfl[l] & 31, din = revfd[d] & 31;
13993
+ eb += fleb[lin] + fdeb[din];
13994
+ ++lf[257 + lin];
13995
+ ++df[din];
13996
+ wi = i2 + l;
13997
+ ++lc_1;
13998
+ } else {
13999
+ syms[li++] = dat[i2];
14000
+ ++lf[dat[i2]];
14001
+ }
14002
+ }
14003
+ }
14004
+ for (i2 = Math.max(i2, wi);i2 < s; ++i2) {
14005
+ syms[li++] = dat[i2];
14006
+ ++lf[dat[i2]];
14007
+ }
14008
+ pos = wblk(dat, w, lst, syms, lf, df, eb, li, bs, i2 - bs, pos);
14009
+ if (!lst) {
14010
+ st.r = pos & 7 | w[pos / 8 | 0] << 3;
14011
+ pos -= 7;
14012
+ st.h = head, st.p = prev, st.i = i2, st.w = wi;
14013
+ }
14014
+ } else {
14015
+ for (var i2 = st.w || 0;i2 < s + lst; i2 += 65535) {
14016
+ var e = i2 + 65535;
14017
+ if (e >= s) {
14018
+ w[pos / 8 | 0] = lst;
14019
+ e = s;
14020
+ }
14021
+ pos = wfblk(w, pos + 1, dat.subarray(i2, e));
14022
+ }
14023
+ st.i = s;
14024
+ }
14025
+ return slc(o, 0, pre + shft(pos) + post);
14026
+ };
14027
+ var adler = function() {
14028
+ var a = 1, b = 0;
14029
+ return {
14030
+ p: function(d) {
14031
+ var n = a, m = b;
14032
+ var l = d.length | 0;
14033
+ for (var i2 = 0;i2 != l; ) {
14034
+ var e = Math.min(i2 + 2655, l);
14035
+ for (;i2 < e; ++i2)
14036
+ m += n += d[i2];
14037
+ n = (n & 65535) + 15 * (n >> 16), m = (m & 65535) + 15 * (m >> 16);
14038
+ }
14039
+ a = n, b = m;
14040
+ },
14041
+ d: function() {
14042
+ a %= 65521, b %= 65521;
14043
+ return (a & 255) << 24 | (a & 65280) << 8 | (b & 255) << 8 | b >> 8;
14044
+ }
14045
+ };
14046
+ };
14047
+ var dopt = function(dat, opt, pre, post, st) {
14048
+ if (!st) {
14049
+ st = { l: 1 };
14050
+ if (opt.dictionary) {
14051
+ var dict = opt.dictionary.subarray(-32768);
14052
+ var newDat = new u8(dict.length + dat.length);
14053
+ newDat.set(dict);
14054
+ newDat.set(dat, dict.length);
14055
+ dat = newDat;
14056
+ st.w = dict.length;
14057
+ }
14058
+ }
14059
+ return dflt(dat, opt.level == null ? 6 : opt.level, opt.mem == null ? st.l ? Math.ceil(Math.max(8, Math.min(13, Math.log(dat.length))) * 1.5) : 20 : 12 + opt.mem, pre, post, st);
14060
+ };
14061
+ var wbytes = function(d, b, v) {
14062
+ for (;v; ++b)
14063
+ d[b] = v, v >>>= 8;
14064
+ };
14065
+ var zlh = function(c, o) {
14066
+ var lv = o.level, fl2 = lv == 0 ? 0 : lv < 6 ? 1 : lv == 9 ? 3 : 2;
14067
+ c[0] = 120, c[1] = fl2 << 6 | (o.dictionary && 32);
14068
+ c[1] |= 31 - (c[0] << 8 | c[1]) % 31;
14069
+ if (o.dictionary) {
14070
+ var h = adler();
14071
+ h.p(o.dictionary);
14072
+ wbytes(c, 2, h.d());
14073
+ }
14074
+ };
14075
+ var zls = function(d, dict) {
14076
+ if ((d[0] & 15) != 8 || d[0] >> 4 > 7 || (d[0] << 8 | d[1]) % 31)
14077
+ err(6, "invalid zlib data");
14078
+ if ((d[1] >> 5 & 1) == +!dict)
14079
+ err(6, "invalid zlib data: " + (d[1] & 32 ? "need" : "unexpected") + " dictionary");
14080
+ return (d[1] >> 3 & 4) + 2;
14081
+ };
14082
+ var Inflate = /* @__PURE__ */ function() {
14083
+ function Inflate2(opts, cb) {
14084
+ if (typeof opts == "function")
14085
+ cb = opts, opts = {};
14086
+ this.ondata = cb;
14087
+ var dict = opts && opts.dictionary && opts.dictionary.subarray(-32768);
14088
+ this.s = { i: 0, b: dict ? dict.length : 0 };
14089
+ this.o = new u8(32768);
14090
+ this.p = new u8(0);
14091
+ if (dict)
14092
+ this.o.set(dict);
14093
+ }
14094
+ Inflate2.prototype.e = function(c) {
14095
+ if (!this.ondata)
14096
+ err(5);
14097
+ if (this.d)
14098
+ err(4);
14099
+ if (!this.p.length)
14100
+ this.p = c;
14101
+ else if (c.length) {
14102
+ var n = new u8(this.p.length + c.length);
14103
+ n.set(this.p), n.set(c, this.p.length), this.p = n;
14104
+ }
14105
+ };
14106
+ Inflate2.prototype.c = function(final) {
14107
+ this.s.i = +(this.d = final || false);
14108
+ var bts = this.s.b;
14109
+ var dt = inflt(this.p, this.s, this.o);
14110
+ this.ondata(slc(dt, bts, this.s.b), this.d);
14111
+ this.o = slc(dt, this.s.b - 32768), this.s.b = this.o.length;
14112
+ this.p = slc(this.p, this.s.p / 8 | 0), this.s.p &= 7;
14113
+ };
14114
+ Inflate2.prototype.push = function(chunk, final) {
14115
+ this.e(chunk), this.c(final);
14116
+ };
14117
+ return Inflate2;
14118
+ }();
14119
+ function zlibSync(data, opts) {
14120
+ if (!opts)
14121
+ opts = {};
14122
+ var a = adler();
14123
+ a.p(data);
14124
+ var d = dopt(data, opts, opts.dictionary ? 6 : 2, 4);
14125
+ return zlh(d, opts), wbytes(d, d.length - 4, a.d()), d;
14126
+ }
14127
+ var Unzlib = /* @__PURE__ */ function() {
14128
+ function Unzlib2(opts, cb) {
14129
+ Inflate.call(this, opts, cb);
14130
+ this.v = opts && opts.dictionary ? 2 : 1;
14131
+ }
14132
+ Unzlib2.prototype.push = function(chunk, final) {
14133
+ Inflate.prototype.e.call(this, chunk);
14134
+ if (this.v) {
14135
+ if (this.p.length < 6 && !final)
14136
+ return;
14137
+ this.p = this.p.subarray(zls(this.p, this.v - 1)), this.v = 0;
14138
+ }
14139
+ if (final) {
14140
+ if (this.p.length < 4)
14141
+ err(6, "invalid zlib data");
14142
+ this.p = this.p.subarray(0, -4);
14143
+ }
14144
+ Inflate.prototype.c.call(this, final);
14145
+ };
14146
+ return Unzlib2;
14147
+ }();
14148
+ function unzlibSync(data, opts) {
14149
+ return inflt(data.subarray(zls(data, opts && opts.dictionary), -4), { i: 2 }, opts && opts.out, opts && opts.dictionary);
14150
+ }
14151
+ var td = typeof TextDecoder != "undefined" && /* @__PURE__ */ new TextDecoder;
14152
+ var tds = 0;
14153
+ try {
14154
+ td.decode(et, { stream: true });
14155
+ tds = 1;
14156
+ } catch (e) {}
14157
+
14158
+ // node_modules/iobuffer/lib/text.js
14159
+ function decode(bytes, encoding = "utf8") {
14160
+ const decoder = new TextDecoder(encoding);
14161
+ return decoder.decode(bytes);
14162
+ }
14163
+ var encoder = new TextEncoder;
14164
+ function encode(str) {
14165
+ return encoder.encode(str);
14166
+ }
14167
+
14168
+ // node_modules/iobuffer/lib/iobuffer.js
14169
+ var defaultByteLength = 1024 * 8;
14170
+ var hostBigEndian = (() => {
14171
+ const array = new Uint8Array(4);
14172
+ const view = new Uint32Array(array.buffer);
14173
+ return !((view[0] = 1) & array[0]);
14174
+ })();
14175
+ var typedArrays = {
14176
+ int8: globalThis.Int8Array,
14177
+ uint8: globalThis.Uint8Array,
14178
+ int16: globalThis.Int16Array,
14179
+ uint16: globalThis.Uint16Array,
14180
+ int32: globalThis.Int32Array,
14181
+ uint32: globalThis.Uint32Array,
14182
+ uint64: globalThis.BigUint64Array,
14183
+ int64: globalThis.BigInt64Array,
14184
+ float32: globalThis.Float32Array,
14185
+ float64: globalThis.Float64Array
14186
+ };
14187
+
14188
+ class IOBuffer {
14189
+ buffer;
14190
+ byteLength;
14191
+ byteOffset;
14192
+ length;
14193
+ offset;
14194
+ lastWrittenByte;
14195
+ littleEndian;
14196
+ _data;
14197
+ _mark;
14198
+ _marks;
14199
+ constructor(data = defaultByteLength, options = {}) {
14200
+ let dataIsGiven = false;
14201
+ if (typeof data === "number") {
14202
+ data = new ArrayBuffer(data);
14203
+ } else {
14204
+ dataIsGiven = true;
14205
+ this.lastWrittenByte = data.byteLength;
14206
+ }
14207
+ const offset = options.offset ? options.offset >>> 0 : 0;
14208
+ const byteLength = data.byteLength - offset;
14209
+ let dvOffset = offset;
14210
+ if (ArrayBuffer.isView(data) || data instanceof IOBuffer) {
14211
+ if (data.byteLength !== data.buffer.byteLength) {
14212
+ dvOffset = data.byteOffset + offset;
14213
+ }
14214
+ data = data.buffer;
14215
+ }
14216
+ if (dataIsGiven) {
14217
+ this.lastWrittenByte = byteLength;
14218
+ } else {
14219
+ this.lastWrittenByte = 0;
14220
+ }
14221
+ this.buffer = data;
14222
+ this.length = byteLength;
14223
+ this.byteLength = byteLength;
14224
+ this.byteOffset = dvOffset;
14225
+ this.offset = 0;
14226
+ this.littleEndian = true;
14227
+ this._data = new DataView(this.buffer, dvOffset, byteLength);
14228
+ this._mark = 0;
14229
+ this._marks = [];
14230
+ }
14231
+ available(byteLength = 1) {
14232
+ return this.offset + byteLength <= this.length;
14233
+ }
14234
+ isLittleEndian() {
14235
+ return this.littleEndian;
14236
+ }
14237
+ setLittleEndian() {
14238
+ this.littleEndian = true;
14239
+ return this;
14240
+ }
14241
+ isBigEndian() {
14242
+ return !this.littleEndian;
14243
+ }
14244
+ setBigEndian() {
14245
+ this.littleEndian = false;
14246
+ return this;
14247
+ }
14248
+ skip(n = 1) {
14249
+ this.offset += n;
14250
+ return this;
14251
+ }
14252
+ back(n = 1) {
14253
+ this.offset -= n;
14254
+ return this;
14255
+ }
14256
+ seek(offset) {
14257
+ this.offset = offset;
14258
+ return this;
14259
+ }
14260
+ mark() {
14261
+ this._mark = this.offset;
14262
+ return this;
14263
+ }
14264
+ reset() {
14265
+ this.offset = this._mark;
14266
+ return this;
14267
+ }
14268
+ pushMark() {
14269
+ this._marks.push(this.offset);
14270
+ return this;
14271
+ }
14272
+ popMark() {
14273
+ const offset = this._marks.pop();
14274
+ if (offset === undefined) {
14275
+ throw new Error("Mark stack empty");
14276
+ }
14277
+ this.seek(offset);
14278
+ return this;
14279
+ }
14280
+ rewind() {
14281
+ this.offset = 0;
14282
+ return this;
14283
+ }
14284
+ ensureAvailable(byteLength = 1) {
14285
+ if (!this.available(byteLength)) {
14286
+ const lengthNeeded = this.offset + byteLength;
14287
+ const newLength = lengthNeeded * 2;
14288
+ const newArray = new Uint8Array(newLength);
14289
+ newArray.set(new Uint8Array(this.buffer));
14290
+ this.buffer = newArray.buffer;
14291
+ this.length = newLength;
14292
+ this.byteLength = newLength;
14293
+ this._data = new DataView(this.buffer);
14294
+ }
14295
+ return this;
14296
+ }
14297
+ readBoolean() {
14298
+ return this.readUint8() !== 0;
14299
+ }
14300
+ readInt8() {
14301
+ return this._data.getInt8(this.offset++);
14302
+ }
14303
+ readUint8() {
14304
+ return this._data.getUint8(this.offset++);
14305
+ }
14306
+ readByte() {
14307
+ return this.readUint8();
14308
+ }
14309
+ readBytes(n = 1) {
14310
+ return this.readArray(n, "uint8");
14311
+ }
14312
+ readArray(size, type) {
14313
+ const bytes = typedArrays[type].BYTES_PER_ELEMENT * size;
14314
+ const offset = this.byteOffset + this.offset;
14315
+ const slice = this.buffer.slice(offset, offset + bytes);
14316
+ if (this.littleEndian === hostBigEndian && type !== "uint8" && type !== "int8") {
14317
+ const slice2 = new Uint8Array(this.buffer.slice(offset, offset + bytes));
14318
+ slice2.reverse();
14319
+ const returnArray2 = new typedArrays[type](slice2.buffer);
14320
+ this.offset += bytes;
14321
+ returnArray2.reverse();
14322
+ return returnArray2;
14323
+ }
14324
+ const returnArray = new typedArrays[type](slice);
14325
+ this.offset += bytes;
14326
+ return returnArray;
14327
+ }
14328
+ readInt16() {
14329
+ const value = this._data.getInt16(this.offset, this.littleEndian);
14330
+ this.offset += 2;
14331
+ return value;
14332
+ }
14333
+ readUint16() {
14334
+ const value = this._data.getUint16(this.offset, this.littleEndian);
14335
+ this.offset += 2;
14336
+ return value;
14337
+ }
14338
+ readInt32() {
14339
+ const value = this._data.getInt32(this.offset, this.littleEndian);
14340
+ this.offset += 4;
14341
+ return value;
14342
+ }
14343
+ readUint32() {
14344
+ const value = this._data.getUint32(this.offset, this.littleEndian);
14345
+ this.offset += 4;
14346
+ return value;
14347
+ }
14348
+ readFloat32() {
14349
+ const value = this._data.getFloat32(this.offset, this.littleEndian);
14350
+ this.offset += 4;
14351
+ return value;
14352
+ }
14353
+ readFloat64() {
14354
+ const value = this._data.getFloat64(this.offset, this.littleEndian);
14355
+ this.offset += 8;
14356
+ return value;
14357
+ }
14358
+ readBigInt64() {
14359
+ const value = this._data.getBigInt64(this.offset, this.littleEndian);
14360
+ this.offset += 8;
14361
+ return value;
14362
+ }
14363
+ readBigUint64() {
14364
+ const value = this._data.getBigUint64(this.offset, this.littleEndian);
14365
+ this.offset += 8;
14366
+ return value;
14367
+ }
14368
+ readChar() {
14369
+ return String.fromCharCode(this.readInt8());
14370
+ }
14371
+ readChars(n = 1) {
14372
+ let result = "";
14373
+ for (let i2 = 0;i2 < n; i2++) {
14374
+ result += this.readChar();
14375
+ }
14376
+ return result;
14377
+ }
14378
+ readUtf8(n = 1) {
14379
+ return decode(this.readBytes(n));
14380
+ }
14381
+ decodeText(n = 1, encoding = "utf8") {
14382
+ return decode(this.readBytes(n), encoding);
14383
+ }
14384
+ writeBoolean(value) {
14385
+ this.writeUint8(value ? 255 : 0);
14386
+ return this;
14387
+ }
14388
+ writeInt8(value) {
14389
+ this.ensureAvailable(1);
14390
+ this._data.setInt8(this.offset++, value);
14391
+ this._updateLastWrittenByte();
14392
+ return this;
14393
+ }
14394
+ writeUint8(value) {
14395
+ this.ensureAvailable(1);
14396
+ this._data.setUint8(this.offset++, value);
14397
+ this._updateLastWrittenByte();
14398
+ return this;
14399
+ }
14400
+ writeByte(value) {
14401
+ return this.writeUint8(value);
14402
+ }
14403
+ writeBytes(bytes) {
14404
+ this.ensureAvailable(bytes.length);
14405
+ for (let i2 = 0;i2 < bytes.length; i2++) {
14406
+ this._data.setUint8(this.offset++, bytes[i2]);
14407
+ }
14408
+ this._updateLastWrittenByte();
14409
+ return this;
14410
+ }
14411
+ writeInt16(value) {
14412
+ this.ensureAvailable(2);
14413
+ this._data.setInt16(this.offset, value, this.littleEndian);
14414
+ this.offset += 2;
14415
+ this._updateLastWrittenByte();
14416
+ return this;
14417
+ }
14418
+ writeUint16(value) {
14419
+ this.ensureAvailable(2);
14420
+ this._data.setUint16(this.offset, value, this.littleEndian);
14421
+ this.offset += 2;
14422
+ this._updateLastWrittenByte();
14423
+ return this;
14424
+ }
14425
+ writeInt32(value) {
14426
+ this.ensureAvailable(4);
14427
+ this._data.setInt32(this.offset, value, this.littleEndian);
14428
+ this.offset += 4;
14429
+ this._updateLastWrittenByte();
14430
+ return this;
14431
+ }
14432
+ writeUint32(value) {
14433
+ this.ensureAvailable(4);
14434
+ this._data.setUint32(this.offset, value, this.littleEndian);
14435
+ this.offset += 4;
14436
+ this._updateLastWrittenByte();
14437
+ return this;
14438
+ }
14439
+ writeFloat32(value) {
14440
+ this.ensureAvailable(4);
14441
+ this._data.setFloat32(this.offset, value, this.littleEndian);
14442
+ this.offset += 4;
14443
+ this._updateLastWrittenByte();
14444
+ return this;
14445
+ }
14446
+ writeFloat64(value) {
14447
+ this.ensureAvailable(8);
14448
+ this._data.setFloat64(this.offset, value, this.littleEndian);
14449
+ this.offset += 8;
14450
+ this._updateLastWrittenByte();
14451
+ return this;
14452
+ }
14453
+ writeBigInt64(value) {
14454
+ this.ensureAvailable(8);
14455
+ this._data.setBigInt64(this.offset, value, this.littleEndian);
14456
+ this.offset += 8;
14457
+ this._updateLastWrittenByte();
14458
+ return this;
14459
+ }
14460
+ writeBigUint64(value) {
14461
+ this.ensureAvailable(8);
14462
+ this._data.setBigUint64(this.offset, value, this.littleEndian);
14463
+ this.offset += 8;
14464
+ this._updateLastWrittenByte();
14465
+ return this;
14466
+ }
14467
+ writeChar(str) {
14468
+ return this.writeUint8(str.charCodeAt(0));
14469
+ }
14470
+ writeChars(str) {
14471
+ for (let i2 = 0;i2 < str.length; i2++) {
14472
+ this.writeUint8(str.charCodeAt(i2));
14473
+ }
14474
+ return this;
14475
+ }
14476
+ writeUtf8(str) {
14477
+ return this.writeBytes(encode(str));
14478
+ }
14479
+ toArray() {
14480
+ return new Uint8Array(this.buffer, this.byteOffset, this.lastWrittenByte);
14481
+ }
14482
+ getWrittenByteLength() {
14483
+ return this.lastWrittenByte - this.byteOffset;
14484
+ }
14485
+ _updateLastWrittenByte() {
14486
+ if (this.offset > this.lastWrittenByte) {
14487
+ this.lastWrittenByte = this.offset;
14488
+ }
14489
+ }
14490
+ }
14491
+
14492
+ // node_modules/fast-png/lib/helpers/crc.js
14493
+ var crcTable = [];
14494
+ for (let n = 0;n < 256; n++) {
14495
+ let c = n;
14496
+ for (let k = 0;k < 8; k++) {
14497
+ if (c & 1) {
14498
+ c = 3988292384 ^ c >>> 1;
14499
+ } else {
14500
+ c = c >>> 1;
14501
+ }
14502
+ }
14503
+ crcTable[n] = c;
14504
+ }
14505
+ var initialCrc = 4294967295;
14506
+ function updateCrc(currentCrc, data, length) {
14507
+ let c = currentCrc;
14508
+ for (let n = 0;n < length; n++) {
14509
+ c = crcTable[(c ^ data[n]) & 255] ^ c >>> 8;
14510
+ }
14511
+ return c;
14512
+ }
14513
+ function crc(data, length) {
14514
+ return (updateCrc(initialCrc, data, length) ^ initialCrc) >>> 0;
14515
+ }
14516
+ function checkCrc(buffer, crcLength, chunkName) {
14517
+ const expectedCrc = buffer.readUint32();
14518
+ const actualCrc = crc(new Uint8Array(buffer.buffer, buffer.byteOffset + buffer.offset - crcLength - 4, crcLength), crcLength);
14519
+ if (actualCrc !== expectedCrc) {
14520
+ throw new Error(`CRC mismatch for chunk ${chunkName}. Expected ${expectedCrc}, found ${actualCrc}`);
14521
+ }
14522
+ }
14523
+ function writeCrc(buffer, length) {
14524
+ buffer.writeUint32(crc(new Uint8Array(buffer.buffer, buffer.byteOffset + buffer.offset - length, length), length));
14525
+ }
14526
+
14527
+ // node_modules/fast-png/lib/helpers/unfilter.js
14528
+ function unfilterNone(currentLine, newLine, bytesPerLine) {
14529
+ for (let i2 = 0;i2 < bytesPerLine; i2++) {
14530
+ newLine[i2] = currentLine[i2];
14531
+ }
14532
+ }
14533
+ function unfilterSub(currentLine, newLine, bytesPerLine, bytesPerPixel) {
14534
+ let i2 = 0;
14535
+ for (;i2 < bytesPerPixel; i2++) {
14536
+ newLine[i2] = currentLine[i2];
14537
+ }
14538
+ for (;i2 < bytesPerLine; i2++) {
14539
+ newLine[i2] = currentLine[i2] + newLine[i2 - bytesPerPixel] & 255;
14540
+ }
14541
+ }
14542
+ function unfilterUp(currentLine, newLine, prevLine, bytesPerLine) {
14543
+ let i2 = 0;
14544
+ if (prevLine.length === 0) {
14545
+ for (;i2 < bytesPerLine; i2++) {
14546
+ newLine[i2] = currentLine[i2];
14547
+ }
14548
+ } else {
14549
+ for (;i2 < bytesPerLine; i2++) {
14550
+ newLine[i2] = currentLine[i2] + prevLine[i2] & 255;
14551
+ }
14552
+ }
14553
+ }
14554
+ function unfilterAverage(currentLine, newLine, prevLine, bytesPerLine, bytesPerPixel) {
14555
+ let i2 = 0;
14556
+ if (prevLine.length === 0) {
14557
+ for (;i2 < bytesPerPixel; i2++) {
14558
+ newLine[i2] = currentLine[i2];
14559
+ }
14560
+ for (;i2 < bytesPerLine; i2++) {
14561
+ newLine[i2] = currentLine[i2] + (newLine[i2 - bytesPerPixel] >> 1) & 255;
14562
+ }
14563
+ } else {
14564
+ for (;i2 < bytesPerPixel; i2++) {
14565
+ newLine[i2] = currentLine[i2] + (prevLine[i2] >> 1) & 255;
14566
+ }
14567
+ for (;i2 < bytesPerLine; i2++) {
14568
+ newLine[i2] = currentLine[i2] + (newLine[i2 - bytesPerPixel] + prevLine[i2] >> 1) & 255;
14569
+ }
14570
+ }
14571
+ }
14572
+ function unfilterPaeth(currentLine, newLine, prevLine, bytesPerLine, bytesPerPixel) {
14573
+ let i2 = 0;
14574
+ if (prevLine.length === 0) {
14575
+ for (;i2 < bytesPerPixel; i2++) {
14576
+ newLine[i2] = currentLine[i2];
14577
+ }
14578
+ for (;i2 < bytesPerLine; i2++) {
14579
+ newLine[i2] = currentLine[i2] + newLine[i2 - bytesPerPixel] & 255;
14580
+ }
14581
+ } else {
14582
+ for (;i2 < bytesPerPixel; i2++) {
14583
+ newLine[i2] = currentLine[i2] + prevLine[i2] & 255;
14584
+ }
14585
+ for (;i2 < bytesPerLine; i2++) {
14586
+ newLine[i2] = currentLine[i2] + paethPredictor(newLine[i2 - bytesPerPixel], prevLine[i2], prevLine[i2 - bytesPerPixel]) & 255;
14587
+ }
14588
+ }
14589
+ }
14590
+ function paethPredictor(a, b, c) {
14591
+ const p = a + b - c;
14592
+ const pa = Math.abs(p - a);
14593
+ const pb = Math.abs(p - b);
14594
+ const pc = Math.abs(p - c);
14595
+ if (pa <= pb && pa <= pc)
14596
+ return a;
14597
+ else if (pb <= pc)
14598
+ return b;
14599
+ else
14600
+ return c;
14601
+ }
14602
+
14603
+ // node_modules/fast-png/lib/helpers/apply_unfilter.js
14604
+ function applyUnfilter(filterType, currentLine, newLine, prevLine, passLineBytes, bytesPerPixel) {
14605
+ switch (filterType) {
14606
+ case 0:
14607
+ unfilterNone(currentLine, newLine, passLineBytes);
14608
+ break;
14609
+ case 1:
14610
+ unfilterSub(currentLine, newLine, passLineBytes, bytesPerPixel);
14611
+ break;
14612
+ case 2:
14613
+ unfilterUp(currentLine, newLine, prevLine, passLineBytes);
14614
+ break;
14615
+ case 3:
14616
+ unfilterAverage(currentLine, newLine, prevLine, passLineBytes, bytesPerPixel);
14617
+ break;
14618
+ case 4:
14619
+ unfilterPaeth(currentLine, newLine, prevLine, passLineBytes, bytesPerPixel);
14620
+ break;
14621
+ default:
14622
+ throw new Error(`Unsupported filter: ${filterType}`);
14623
+ }
14624
+ }
14625
+
14626
+ // node_modules/fast-png/lib/helpers/decode_interlace_adam7.js
14627
+ var uint16 = new Uint16Array([255]);
14628
+ var uint8 = new Uint8Array(uint16.buffer);
14629
+ var osIsLittleEndian = uint8[0] === 255;
14630
+ function decodeInterlaceAdam7(params) {
14631
+ const { data, width, height, channels, depth } = params;
14632
+ const passes = [
14633
+ { x: 0, y: 0, xStep: 8, yStep: 8 },
14634
+ { x: 4, y: 0, xStep: 8, yStep: 8 },
14635
+ { x: 0, y: 4, xStep: 4, yStep: 8 },
14636
+ { x: 2, y: 0, xStep: 4, yStep: 4 },
14637
+ { x: 0, y: 2, xStep: 2, yStep: 4 },
14638
+ { x: 1, y: 0, xStep: 2, yStep: 2 },
14639
+ { x: 0, y: 1, xStep: 1, yStep: 2 }
14640
+ ];
14641
+ const bytesPerPixel = Math.ceil(depth / 8) * channels;
14642
+ const resultData = new Uint8Array(height * width * bytesPerPixel);
14643
+ let offset = 0;
14644
+ for (let passIndex = 0;passIndex < 7; passIndex++) {
14645
+ const pass = passes[passIndex];
14646
+ const passWidth = Math.ceil((width - pass.x) / pass.xStep);
14647
+ const passHeight = Math.ceil((height - pass.y) / pass.yStep);
14648
+ if (passWidth <= 0 || passHeight <= 0)
14649
+ continue;
14650
+ const passLineBytes = passWidth * bytesPerPixel;
14651
+ const prevLine = new Uint8Array(passLineBytes);
14652
+ for (let y = 0;y < passHeight; y++) {
14653
+ const filterType = data[offset++];
14654
+ const currentLine = data.subarray(offset, offset + passLineBytes);
14655
+ offset += passLineBytes;
14656
+ const newLine = new Uint8Array(passLineBytes);
14657
+ applyUnfilter(filterType, currentLine, newLine, prevLine, passLineBytes, bytesPerPixel);
14658
+ prevLine.set(newLine);
14659
+ for (let x2 = 0;x2 < passWidth; x2++) {
14660
+ const outputX = pass.x + x2 * pass.xStep;
14661
+ const outputY = pass.y + y * pass.yStep;
14662
+ if (outputX >= width || outputY >= height)
14663
+ continue;
14664
+ for (let i2 = 0;i2 < bytesPerPixel; i2++) {
14665
+ resultData[(outputY * width + outputX) * bytesPerPixel + i2] = newLine[x2 * bytesPerPixel + i2];
14666
+ }
14667
+ }
14668
+ }
14669
+ }
14670
+ if (depth === 16) {
14671
+ const uint16Data = new Uint16Array(resultData.buffer);
14672
+ if (osIsLittleEndian) {
14673
+ for (let k = 0;k < uint16Data.length; k++) {
14674
+ uint16Data[k] = swap16(uint16Data[k]);
14675
+ }
14676
+ }
14677
+ return uint16Data;
14678
+ } else {
14679
+ return resultData;
14680
+ }
14681
+ }
14682
+ function swap16(val) {
14683
+ return (val & 255) << 8 | val >> 8 & 255;
14684
+ }
14685
+
14686
+ // node_modules/fast-png/lib/helpers/decode_interlace_null.js
14687
+ var uint162 = new Uint16Array([255]);
14688
+ var uint82 = new Uint8Array(uint162.buffer);
14689
+ var osIsLittleEndian2 = uint82[0] === 255;
14690
+ var empty = new Uint8Array(0);
14691
+ function decodeInterlaceNull(params) {
14692
+ const { data, width, height, channels, depth } = params;
14693
+ const bytesPerPixel = Math.ceil(depth / 8) * channels;
14694
+ const bytesPerLine = Math.ceil(depth / 8 * channels * width);
14695
+ const newData = new Uint8Array(height * bytesPerLine);
14696
+ let prevLine = empty;
14697
+ let offset = 0;
14698
+ let currentLine;
14699
+ let newLine;
14700
+ for (let i2 = 0;i2 < height; i2++) {
14701
+ currentLine = data.subarray(offset + 1, offset + 1 + bytesPerLine);
14702
+ newLine = newData.subarray(i2 * bytesPerLine, (i2 + 1) * bytesPerLine);
14703
+ switch (data[offset]) {
14704
+ case 0:
14705
+ unfilterNone(currentLine, newLine, bytesPerLine);
14706
+ break;
14707
+ case 1:
14708
+ unfilterSub(currentLine, newLine, bytesPerLine, bytesPerPixel);
14709
+ break;
14710
+ case 2:
14711
+ unfilterUp(currentLine, newLine, prevLine, bytesPerLine);
14712
+ break;
14713
+ case 3:
14714
+ unfilterAverage(currentLine, newLine, prevLine, bytesPerLine, bytesPerPixel);
14715
+ break;
14716
+ case 4:
14717
+ unfilterPaeth(currentLine, newLine, prevLine, bytesPerLine, bytesPerPixel);
14718
+ break;
14719
+ default:
14720
+ throw new Error(`Unsupported filter: ${data[offset]}`);
14721
+ }
14722
+ prevLine = newLine;
14723
+ offset += bytesPerLine + 1;
14724
+ }
14725
+ if (depth === 16) {
14726
+ const uint16Data = new Uint16Array(newData.buffer);
14727
+ if (osIsLittleEndian2) {
14728
+ for (let k = 0;k < uint16Data.length; k++) {
14729
+ uint16Data[k] = swap162(uint16Data[k]);
14730
+ }
14731
+ }
14732
+ return uint16Data;
14733
+ } else {
14734
+ return newData;
14735
+ }
14736
+ }
14737
+ function swap162(val) {
14738
+ return (val & 255) << 8 | val >> 8 & 255;
14739
+ }
14740
+
14741
+ // node_modules/fast-png/lib/helpers/signature.js
14742
+ var pngSignature = Uint8Array.of(137, 80, 78, 71, 13, 10, 26, 10);
14743
+ function writeSignature(buffer) {
14744
+ buffer.writeBytes(pngSignature);
14745
+ }
14746
+ function checkSignature(buffer) {
14747
+ if (!hasPngSignature(buffer.readBytes(pngSignature.length))) {
14748
+ throw new Error("wrong PNG signature");
14749
+ }
14750
+ }
14751
+ function hasPngSignature(array) {
14752
+ if (array.length < pngSignature.length) {
14753
+ return false;
14754
+ }
14755
+ for (let i2 = 0;i2 < pngSignature.length; i2++) {
14756
+ if (array[i2] !== pngSignature[i2]) {
14757
+ return false;
14758
+ }
14759
+ }
14760
+ return true;
14761
+ }
14762
+
14763
+ // node_modules/fast-png/lib/helpers/text.js
14764
+ var textChunkName = "tEXt";
14765
+ var NULL = 0;
14766
+ var latin1Decoder = new TextDecoder("latin1");
14767
+ function validateKeyword(keyword) {
14768
+ validateLatin1(keyword);
14769
+ if (keyword.length === 0 || keyword.length > 79) {
14770
+ throw new Error("keyword length must be between 1 and 79");
14771
+ }
14772
+ }
14773
+ var latin1Regex = /^[\u0000-\u00FF]*$/;
14774
+ function validateLatin1(text) {
14775
+ if (!latin1Regex.test(text)) {
14776
+ throw new Error("invalid latin1 text");
14777
+ }
14778
+ }
14779
+ function decodetEXt(text, buffer, length) {
14780
+ const keyword = readKeyword(buffer);
14781
+ text[keyword] = readLatin1(buffer, length - keyword.length - 1);
14782
+ }
14783
+ function encodetEXt(buffer, keyword, text) {
14784
+ validateKeyword(keyword);
14785
+ validateLatin1(text);
14786
+ const length = keyword.length + 1 + text.length;
14787
+ buffer.writeUint32(length);
14788
+ buffer.writeChars(textChunkName);
14789
+ buffer.writeChars(keyword);
14790
+ buffer.writeByte(NULL);
14791
+ buffer.writeChars(text);
14792
+ writeCrc(buffer, length + 4);
14793
+ }
14794
+ function readKeyword(buffer) {
14795
+ buffer.mark();
14796
+ while (buffer.readByte() !== NULL) {}
14797
+ const end = buffer.offset;
14798
+ buffer.reset();
14799
+ const keyword = latin1Decoder.decode(buffer.readBytes(end - buffer.offset - 1));
14800
+ buffer.skip(1);
14801
+ validateKeyword(keyword);
14802
+ return keyword;
14803
+ }
14804
+ function readLatin1(buffer, length) {
14805
+ return latin1Decoder.decode(buffer.readBytes(length));
14806
+ }
14807
+
14808
+ // node_modules/fast-png/lib/internal_types.js
14809
+ var ColorType = {
14810
+ UNKNOWN: -1,
14811
+ GREYSCALE: 0,
14812
+ TRUECOLOUR: 2,
14813
+ INDEXED_COLOUR: 3,
14814
+ GREYSCALE_ALPHA: 4,
14815
+ TRUECOLOUR_ALPHA: 6
14816
+ };
14817
+ var CompressionMethod = {
14818
+ UNKNOWN: -1,
14819
+ DEFLATE: 0
14820
+ };
14821
+ var FilterMethod = {
14822
+ UNKNOWN: -1,
14823
+ ADAPTIVE: 0
14824
+ };
14825
+ var InterlaceMethod = {
14826
+ UNKNOWN: -1,
14827
+ NO_INTERLACE: 0,
14828
+ ADAM7: 1
14829
+ };
14830
+ var DisposeOpType = {
14831
+ NONE: 0,
14832
+ BACKGROUND: 1,
14833
+ PREVIOUS: 2
14834
+ };
14835
+ var BlendOpType = {
14836
+ SOURCE: 0,
14837
+ OVER: 1
14838
+ };
14839
+
14840
+ // node_modules/fast-png/lib/png_decoder.js
14841
+ class PngDecoder extends IOBuffer {
14842
+ _checkCrc;
14843
+ _inflator;
14844
+ _png;
14845
+ _apng;
14846
+ _end;
14847
+ _hasPalette;
14848
+ _palette;
14849
+ _hasTransparency;
14850
+ _transparency;
14851
+ _compressionMethod;
14852
+ _filterMethod;
14853
+ _interlaceMethod;
14854
+ _colorType;
14855
+ _isAnimated;
14856
+ _numberOfFrames;
14857
+ _numberOfPlays;
14858
+ _frames;
14859
+ _writingDataChunks;
14860
+ _chunks;
14861
+ _inflatorResult;
14862
+ constructor(data, options = {}) {
14863
+ super(data);
14864
+ const { checkCrc: checkCrc2 = false } = options;
14865
+ this._checkCrc = checkCrc2;
14866
+ this._inflator = new Unzlib((chunk, final) => {
14867
+ this._chunks.push(chunk);
14868
+ if (final) {
14869
+ const totalLength = this._chunks.reduce((sum, c) => sum + c.length, 0);
14870
+ this._inflatorResult = new Uint8Array(totalLength);
14871
+ let offset = 0;
14872
+ for (const chunk2 of this._chunks) {
14873
+ this._inflatorResult.set(chunk2, offset);
14874
+ offset += chunk2.length;
14875
+ }
14876
+ this._chunks = [];
14877
+ }
14878
+ });
14879
+ this._chunks = [];
14880
+ this._png = {
14881
+ width: -1,
14882
+ height: -1,
14883
+ channels: -1,
14884
+ data: new Uint8Array(0),
14885
+ depth: 1,
14886
+ text: {}
14887
+ };
14888
+ this._apng = {
14889
+ width: -1,
14890
+ height: -1,
14891
+ channels: -1,
14892
+ depth: 1,
14893
+ numberOfFrames: 1,
14894
+ numberOfPlays: 0,
14895
+ text: {},
14896
+ frames: []
14897
+ };
14898
+ this._end = false;
14899
+ this._hasPalette = false;
14900
+ this._palette = [];
14901
+ this._hasTransparency = false;
14902
+ this._transparency = new Uint16Array(0);
14903
+ this._compressionMethod = CompressionMethod.UNKNOWN;
14904
+ this._filterMethod = FilterMethod.UNKNOWN;
14905
+ this._interlaceMethod = InterlaceMethod.UNKNOWN;
14906
+ this._colorType = ColorType.UNKNOWN;
14907
+ this._isAnimated = false;
14908
+ this._numberOfFrames = 1;
14909
+ this._numberOfPlays = 0;
14910
+ this._frames = [];
14911
+ this._writingDataChunks = false;
14912
+ this._inflatorResult = new Uint8Array(0);
14913
+ this.setBigEndian();
14914
+ }
14915
+ decode() {
14916
+ checkSignature(this);
14917
+ while (!this._end) {
14918
+ const length = this.readUint32();
14919
+ const type = this.readChars(4);
14920
+ this.decodeChunk(length, type);
14921
+ }
14922
+ this._inflator.push(new Uint8Array(0), true);
14923
+ this.decodeImage();
14924
+ return this._png;
14925
+ }
14926
+ decodeApng() {
14927
+ checkSignature(this);
14928
+ while (!this._end) {
14929
+ const length = this.readUint32();
14930
+ const type = this.readChars(4);
14931
+ this.decodeApngChunk(length, type);
14932
+ }
14933
+ this.decodeApngImage();
14934
+ return this._apng;
14935
+ }
14936
+ decodeChunk(length, type) {
14937
+ const offset = this.offset;
14938
+ switch (type) {
14939
+ case "IHDR":
14940
+ this.decodeIHDR();
14941
+ break;
14942
+ case "PLTE":
14943
+ this.decodePLTE(length);
14944
+ break;
14945
+ case "IDAT":
14946
+ this.decodeIDAT(length);
14947
+ break;
14948
+ case "IEND":
14949
+ this._end = true;
14950
+ break;
14951
+ case "tRNS":
14952
+ this.decodetRNS(length);
14953
+ break;
14954
+ case "iCCP":
14955
+ this.decodeiCCP(length);
14956
+ break;
14957
+ case textChunkName:
14958
+ decodetEXt(this._png.text, this, length);
14959
+ break;
14960
+ case "pHYs":
14961
+ this.decodepHYs();
14962
+ break;
14963
+ default:
14964
+ this.skip(length);
14965
+ break;
14966
+ }
14967
+ if (this.offset - offset !== length) {
14968
+ throw new Error(`Length mismatch while decoding chunk ${type}`);
14969
+ }
14970
+ if (this._checkCrc) {
14971
+ checkCrc(this, length + 4, type);
14972
+ } else {
14973
+ this.skip(4);
14974
+ }
14975
+ }
14976
+ decodeApngChunk(length, type) {
14977
+ const offset = this.offset;
14978
+ if (type !== "fdAT" && type !== "IDAT" && this._writingDataChunks) {
14979
+ this.pushDataToFrame();
14980
+ }
14981
+ switch (type) {
14982
+ case "acTL":
14983
+ this.decodeACTL();
14984
+ break;
14985
+ case "fcTL":
14986
+ this.decodeFCTL();
14987
+ break;
14988
+ case "fdAT":
14989
+ this.decodeFDAT(length);
14990
+ break;
14991
+ default:
14992
+ this.decodeChunk(length, type);
14993
+ this.offset = offset + length;
14994
+ break;
14995
+ }
14996
+ if (this.offset - offset !== length) {
14997
+ throw new Error(`Length mismatch while decoding chunk ${type}`);
14998
+ }
14999
+ if (this._checkCrc) {
15000
+ checkCrc(this, length + 4, type);
15001
+ } else {
15002
+ this.skip(4);
15003
+ }
15004
+ }
15005
+ decodeIHDR() {
15006
+ const image = this._png;
15007
+ image.width = this.readUint32();
15008
+ image.height = this.readUint32();
15009
+ image.depth = checkBitDepth(this.readUint8());
15010
+ const colorType = this.readUint8();
15011
+ this._colorType = colorType;
15012
+ let channels;
15013
+ switch (colorType) {
15014
+ case ColorType.GREYSCALE:
15015
+ channels = 1;
15016
+ break;
15017
+ case ColorType.TRUECOLOUR:
15018
+ channels = 3;
15019
+ break;
15020
+ case ColorType.INDEXED_COLOUR:
15021
+ channels = 1;
15022
+ break;
15023
+ case ColorType.GREYSCALE_ALPHA:
15024
+ channels = 2;
15025
+ break;
15026
+ case ColorType.TRUECOLOUR_ALPHA:
15027
+ channels = 4;
15028
+ break;
15029
+ case ColorType.UNKNOWN:
15030
+ default:
15031
+ throw new Error(`Unknown color type: ${colorType}`);
15032
+ }
15033
+ this._png.channels = channels;
15034
+ this._compressionMethod = this.readUint8();
15035
+ if (this._compressionMethod !== CompressionMethod.DEFLATE) {
15036
+ throw new Error(`Unsupported compression method: ${this._compressionMethod}`);
15037
+ }
15038
+ this._filterMethod = this.readUint8();
15039
+ this._interlaceMethod = this.readUint8();
15040
+ }
15041
+ decodeACTL() {
15042
+ this._numberOfFrames = this.readUint32();
15043
+ this._numberOfPlays = this.readUint32();
15044
+ this._isAnimated = true;
15045
+ }
15046
+ decodeFCTL() {
15047
+ const image = {
15048
+ sequenceNumber: this.readUint32(),
15049
+ width: this.readUint32(),
15050
+ height: this.readUint32(),
15051
+ xOffset: this.readUint32(),
15052
+ yOffset: this.readUint32(),
15053
+ delayNumber: this.readUint16(),
15054
+ delayDenominator: this.readUint16(),
15055
+ disposeOp: this.readUint8(),
15056
+ blendOp: this.readUint8(),
15057
+ data: new Uint8Array(0)
15058
+ };
15059
+ this._frames.push(image);
15060
+ }
15061
+ decodePLTE(length) {
15062
+ if (length % 3 !== 0) {
15063
+ throw new RangeError(`PLTE field length must be a multiple of 3. Got ${length}`);
15064
+ }
15065
+ const l = length / 3;
15066
+ this._hasPalette = true;
15067
+ const palette = [];
15068
+ this._palette = palette;
15069
+ for (let i2 = 0;i2 < l; i2++) {
15070
+ palette.push([this.readUint8(), this.readUint8(), this.readUint8()]);
15071
+ }
15072
+ }
15073
+ decodeIDAT(length) {
15074
+ this._writingDataChunks = true;
15075
+ const dataLength = length;
15076
+ const dataOffset = this.offset + this.byteOffset;
15077
+ try {
15078
+ this._inflator.push(new Uint8Array(this.buffer, dataOffset, dataLength), false);
15079
+ } catch (error) {
15080
+ throw new Error("Error while decompressing the data:", { cause: error });
15081
+ }
15082
+ this.skip(length);
15083
+ }
15084
+ decodeFDAT(length) {
15085
+ this._writingDataChunks = true;
15086
+ let dataLength = length;
15087
+ let dataOffset = this.offset + this.byteOffset;
15088
+ dataOffset += 4;
15089
+ dataLength -= 4;
15090
+ try {
15091
+ this._inflator.push(new Uint8Array(this.buffer, dataOffset, dataLength), false);
15092
+ } catch (error) {
15093
+ throw new Error("Error while decompressing the data:", { cause: error });
15094
+ }
15095
+ this.skip(length);
15096
+ }
15097
+ decodetRNS(length) {
15098
+ switch (this._colorType) {
15099
+ case ColorType.GREYSCALE:
15100
+ case ColorType.TRUECOLOUR: {
15101
+ if (length % 2 !== 0) {
15102
+ throw new RangeError(`tRNS chunk length must be a multiple of 2. Got ${length}`);
15103
+ }
15104
+ if (length / 2 > this._png.width * this._png.height) {
15105
+ throw new Error(`tRNS chunk contains more alpha values than there are pixels (${length / 2} vs ${this._png.width * this._png.height})`);
15106
+ }
15107
+ this._hasTransparency = true;
15108
+ this._transparency = new Uint16Array(length / 2);
15109
+ for (let i2 = 0;i2 < length / 2; i2++) {
15110
+ this._transparency[i2] = this.readUint16();
15111
+ }
15112
+ break;
15113
+ }
15114
+ case ColorType.INDEXED_COLOUR: {
15115
+ if (length > this._palette.length) {
15116
+ throw new Error(`tRNS chunk contains more alpha values than there are palette colors (${length} vs ${this._palette.length})`);
15117
+ }
15118
+ let i2 = 0;
15119
+ for (;i2 < length; i2++) {
15120
+ const alpha = this.readByte();
15121
+ this._palette[i2].push(alpha);
15122
+ }
15123
+ for (;i2 < this._palette.length; i2++) {
15124
+ this._palette[i2].push(255);
15125
+ }
15126
+ break;
15127
+ }
15128
+ case ColorType.UNKNOWN:
15129
+ case ColorType.GREYSCALE_ALPHA:
15130
+ case ColorType.TRUECOLOUR_ALPHA:
15131
+ default: {
15132
+ throw new Error(`tRNS chunk is not supported for color type ${this._colorType}`);
15133
+ }
15134
+ }
15135
+ }
15136
+ decodeiCCP(length) {
15137
+ const name = readKeyword(this);
15138
+ const compressionMethod = this.readUint8();
15139
+ if (compressionMethod !== CompressionMethod.DEFLATE) {
15140
+ throw new Error(`Unsupported iCCP compression method: ${compressionMethod}`);
15141
+ }
15142
+ const compressedProfile = this.readBytes(length - name.length - 2);
15143
+ this._png.iccEmbeddedProfile = {
15144
+ name,
15145
+ profile: unzlibSync(compressedProfile)
15146
+ };
15147
+ }
15148
+ decodepHYs() {
15149
+ const ppuX = this.readUint32();
15150
+ const ppuY = this.readUint32();
15151
+ const unitSpecifier = this.readByte();
15152
+ this._png.resolution = {
15153
+ x: ppuX,
15154
+ y: ppuY,
15155
+ unit: unitSpecifier
15156
+ };
15157
+ }
15158
+ decodeApngImage() {
15159
+ this._apng.width = this._png.width;
15160
+ this._apng.height = this._png.height;
15161
+ this._apng.channels = this._png.channels;
15162
+ this._apng.depth = this._png.depth;
15163
+ this._apng.numberOfFrames = this._numberOfFrames;
15164
+ this._apng.numberOfPlays = this._numberOfPlays;
15165
+ this._apng.text = this._png.text;
15166
+ this._apng.resolution = this._png.resolution;
15167
+ for (let i2 = 0;i2 < this._numberOfFrames; i2++) {
15168
+ const newFrame = {
15169
+ sequenceNumber: this._frames[i2].sequenceNumber,
15170
+ delayNumber: this._frames[i2].delayNumber,
15171
+ delayDenominator: this._frames[i2].delayDenominator,
15172
+ 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)
15173
+ };
15174
+ const frame = this._frames.at(i2);
15175
+ if (frame) {
15176
+ frame.data = decodeInterlaceNull({
15177
+ data: frame.data,
15178
+ width: frame.width,
15179
+ height: frame.height,
15180
+ channels: this._apng.channels,
15181
+ depth: this._apng.depth
15182
+ });
15183
+ if (this._hasPalette) {
15184
+ this._apng.palette = this._palette;
15185
+ }
15186
+ if (this._hasTransparency) {
15187
+ this._apng.transparency = this._transparency;
15188
+ }
15189
+ if (i2 === 0 || frame.xOffset === 0 && frame.yOffset === 0 && frame.width === this._png.width && frame.height === this._png.height) {
15190
+ newFrame.data = frame.data;
15191
+ } else {
15192
+ const prevFrame = this._apng.frames.at(i2 - 1);
15193
+ this.disposeFrame(frame, prevFrame, newFrame);
15194
+ this.addFrameDataToCanvas(newFrame, frame);
15195
+ }
15196
+ this._apng.frames.push(newFrame);
15197
+ }
15198
+ }
15199
+ return this._apng;
15200
+ }
15201
+ disposeFrame(frame, prevFrame, imageFrame) {
15202
+ switch (frame.disposeOp) {
15203
+ case DisposeOpType.NONE:
15204
+ break;
15205
+ case DisposeOpType.BACKGROUND:
15206
+ for (let row = 0;row < this._png.height; row++) {
15207
+ for (let col = 0;col < this._png.width; col++) {
15208
+ const index = (row * frame.width + col) * this._png.channels;
15209
+ for (let channel = 0;channel < this._png.channels; channel++) {
15210
+ imageFrame.data[index + channel] = 0;
15211
+ }
15212
+ }
15213
+ }
15214
+ break;
15215
+ case DisposeOpType.PREVIOUS:
15216
+ imageFrame.data.set(prevFrame.data);
15217
+ break;
15218
+ default:
15219
+ throw new Error("Unknown disposeOp");
15220
+ }
15221
+ }
15222
+ addFrameDataToCanvas(imageFrame, frame) {
15223
+ const maxValue = 1 << this._png.depth;
15224
+ const calculatePixelIndices = (row, col) => {
15225
+ const index = ((row + frame.yOffset) * this._png.width + frame.xOffset + col) * this._png.channels;
15226
+ const frameIndex = (row * frame.width + col) * this._png.channels;
15227
+ return { index, frameIndex };
15228
+ };
15229
+ switch (frame.blendOp) {
15230
+ case BlendOpType.SOURCE:
15231
+ for (let row = 0;row < frame.height; row++) {
15232
+ for (let col = 0;col < frame.width; col++) {
15233
+ const { index, frameIndex } = calculatePixelIndices(row, col);
15234
+ for (let channel = 0;channel < this._png.channels; channel++) {
15235
+ imageFrame.data[index + channel] = frame.data[frameIndex + channel];
15236
+ }
15237
+ }
15238
+ }
15239
+ break;
15240
+ case BlendOpType.OVER:
15241
+ for (let row = 0;row < frame.height; row++) {
15242
+ for (let col = 0;col < frame.width; col++) {
15243
+ const { index, frameIndex } = calculatePixelIndices(row, col);
15244
+ for (let channel = 0;channel < this._png.channels; channel++) {
15245
+ const sourceAlpha = frame.data[frameIndex + this._png.channels - 1] / maxValue;
15246
+ const foregroundValue = channel % (this._png.channels - 1) === 0 ? 1 : frame.data[frameIndex + channel];
15247
+ const value = Math.floor(sourceAlpha * foregroundValue + (1 - sourceAlpha) * imageFrame.data[index + channel]);
15248
+ imageFrame.data[index + channel] += value;
15249
+ }
15250
+ }
15251
+ }
15252
+ break;
15253
+ default:
15254
+ throw new Error("Unknown blendOp");
15255
+ }
15256
+ }
15257
+ decodeImage() {
15258
+ const data = this._inflatorResult;
15259
+ if (this._filterMethod !== FilterMethod.ADAPTIVE) {
15260
+ throw new Error(`Filter method ${this._filterMethod} not supported`);
15261
+ }
15262
+ if (this._interlaceMethod === InterlaceMethod.NO_INTERLACE) {
15263
+ this._png.data = decodeInterlaceNull({
15264
+ data,
15265
+ width: this._png.width,
15266
+ height: this._png.height,
15267
+ channels: this._png.channels,
15268
+ depth: this._png.depth
15269
+ });
15270
+ } else if (this._interlaceMethod === InterlaceMethod.ADAM7) {
15271
+ this._png.data = decodeInterlaceAdam7({
15272
+ data,
15273
+ width: this._png.width,
15274
+ height: this._png.height,
15275
+ channels: this._png.channels,
15276
+ depth: this._png.depth
15277
+ });
15278
+ } else {
15279
+ throw new Error(`Interlace method ${this._interlaceMethod} not supported`);
15280
+ }
15281
+ if (this._hasPalette) {
15282
+ this._png.palette = this._palette;
15283
+ }
15284
+ if (this._hasTransparency) {
15285
+ this._png.transparency = this._transparency;
15286
+ }
15287
+ }
15288
+ pushDataToFrame() {
15289
+ this._inflator.push(new Uint8Array(0), true);
15290
+ const result = this._inflatorResult;
15291
+ const lastFrame = this._frames.at(-1);
15292
+ if (lastFrame) {
15293
+ lastFrame.data = result;
15294
+ } else {
15295
+ this._frames.push({
15296
+ sequenceNumber: 0,
15297
+ width: this._png.width,
15298
+ height: this._png.height,
15299
+ xOffset: 0,
15300
+ yOffset: 0,
15301
+ delayNumber: 0,
15302
+ delayDenominator: 0,
15303
+ disposeOp: DisposeOpType.NONE,
15304
+ blendOp: BlendOpType.SOURCE,
15305
+ data: result
15306
+ });
15307
+ }
15308
+ this._inflator = new Unzlib((chunk, final) => {
15309
+ this._chunks.push(chunk);
15310
+ if (final) {
15311
+ const totalLength = this._chunks.reduce((sum, c) => sum + c.length, 0);
15312
+ this._inflatorResult = new Uint8Array(totalLength);
15313
+ let offset = 0;
15314
+ for (const chunk2 of this._chunks) {
15315
+ this._inflatorResult.set(chunk2, offset);
15316
+ offset += chunk2.length;
15317
+ }
15318
+ this._chunks = [];
15319
+ }
15320
+ });
15321
+ this._chunks = [];
15322
+ this._writingDataChunks = false;
15323
+ }
15324
+ }
15325
+ function checkBitDepth(value) {
15326
+ if (value !== 1 && value !== 2 && value !== 4 && value !== 8 && value !== 16) {
15327
+ throw new Error(`invalid bit depth: ${value}`);
15328
+ }
15329
+ return value;
15330
+ }
15331
+
15332
+ // node_modules/fast-png/lib/png_encoder.js
15333
+ var defaultZlibOptions = {
15334
+ level: 3
15335
+ };
15336
+
15337
+ class PngEncoder extends IOBuffer {
15338
+ _png;
15339
+ _zlibOptions;
15340
+ _colorType;
15341
+ _interlaceMethod;
15342
+ constructor(data, options = {}) {
15343
+ super();
15344
+ this._colorType = ColorType.UNKNOWN;
15345
+ this._zlibOptions = { ...defaultZlibOptions, ...options.zlib };
15346
+ this._png = this._checkData(data);
15347
+ this._interlaceMethod = (options.interlace === "Adam7" ? InterlaceMethod.ADAM7 : InterlaceMethod.NO_INTERLACE) ?? InterlaceMethod.NO_INTERLACE;
15348
+ this.setBigEndian();
15349
+ }
15350
+ encode() {
15351
+ writeSignature(this);
15352
+ this.encodeIHDR();
15353
+ if (this._png.palette) {
15354
+ this.encodePLTE();
15355
+ if (this._png.palette[0].length === 4) {
15356
+ this.encodeTRNS();
15357
+ }
15358
+ }
15359
+ this.encodeData();
15360
+ if (this._png.text) {
15361
+ for (const [keyword, text] of Object.entries(this._png.text)) {
15362
+ encodetEXt(this, keyword, text);
15363
+ }
15364
+ }
15365
+ this.encodeIEND();
15366
+ return this.toArray();
15367
+ }
15368
+ encodeIHDR() {
15369
+ this.writeUint32(13);
15370
+ this.writeChars("IHDR");
15371
+ this.writeUint32(this._png.width);
15372
+ this.writeUint32(this._png.height);
15373
+ this.writeByte(this._png.depth);
15374
+ this.writeByte(this._colorType);
15375
+ this.writeByte(CompressionMethod.DEFLATE);
15376
+ this.writeByte(FilterMethod.ADAPTIVE);
15377
+ this.writeByte(this._interlaceMethod);
15378
+ writeCrc(this, 17);
15379
+ }
15380
+ encodeIEND() {
15381
+ this.writeUint32(0);
15382
+ this.writeChars("IEND");
15383
+ writeCrc(this, 4);
15384
+ }
15385
+ encodePLTE() {
15386
+ const paletteLength = this._png.palette?.length * 3;
15387
+ this.writeUint32(paletteLength);
15388
+ this.writeChars("PLTE");
15389
+ for (const color of this._png.palette) {
15390
+ this.writeByte(color[0]);
15391
+ this.writeByte(color[1]);
15392
+ this.writeByte(color[2]);
15393
+ }
15394
+ writeCrc(this, 4 + paletteLength);
15395
+ }
15396
+ encodeTRNS() {
15397
+ const alpha = this._png.palette.filter((color) => {
15398
+ return color.at(-1) !== 255;
15399
+ });
15400
+ this.writeUint32(alpha.length);
15401
+ this.writeChars("tRNS");
15402
+ for (const el of alpha) {
15403
+ this.writeByte(el.at(-1));
15404
+ }
15405
+ writeCrc(this, 4 + alpha.length);
15406
+ }
15407
+ encodeIDAT(data) {
15408
+ this.writeUint32(data.length);
15409
+ this.writeChars("IDAT");
15410
+ this.writeBytes(data);
15411
+ writeCrc(this, data.length + 4);
15412
+ }
15413
+ encodeData() {
15414
+ const { width, height, channels, depth, data } = this._png;
15415
+ const slotsPerLine = depth <= 8 ? Math.ceil(width * depth / 8) * channels : Math.ceil(width * depth / 8 * channels / 2);
15416
+ const newData = new IOBuffer().setBigEndian();
15417
+ let offset = 0;
15418
+ if (this._interlaceMethod === InterlaceMethod.NO_INTERLACE) {
15419
+ for (let i2 = 0;i2 < height; i2++) {
15420
+ newData.writeByte(0);
15421
+ if (depth === 16) {
15422
+ offset = writeDataUint16(data, newData, slotsPerLine, offset);
15423
+ } else {
15424
+ offset = writeDataBytes(data, newData, slotsPerLine, offset);
15425
+ }
15426
+ }
15427
+ } else if (this._interlaceMethod === InterlaceMethod.ADAM7) {
15428
+ offset = writeDataInterlaced(this._png, data, newData, offset);
15429
+ }
15430
+ const buffer = newData.toArray();
15431
+ const compressed = zlibSync(buffer, this._zlibOptions);
15432
+ this.encodeIDAT(compressed);
15433
+ }
15434
+ _checkData(data) {
15435
+ const { colorType, channels, depth } = getColorType(data, data.palette);
15436
+ const png = {
15437
+ width: checkInteger(data.width, "width"),
15438
+ height: checkInteger(data.height, "height"),
15439
+ channels,
15440
+ data: data.data,
15441
+ depth,
15442
+ text: data.text,
15443
+ palette: data.palette
15444
+ };
15445
+ this._colorType = colorType;
15446
+ const expectedSize = depth < 8 ? Math.ceil(png.width * depth / 8) * png.height * channels : png.width * png.height * channels;
15447
+ if (png.data.length !== expectedSize) {
15448
+ throw new RangeError(`wrong data size. Found ${png.data.length}, expected ${expectedSize}`);
15449
+ }
15450
+ return png;
15451
+ }
15452
+ }
15453
+ function checkInteger(value, name) {
15454
+ if (Number.isInteger(value) && value > 0) {
15455
+ return value;
15456
+ }
15457
+ throw new TypeError(`${name} must be a positive integer`);
15458
+ }
15459
+ function getColorType(data, palette) {
15460
+ const { channels = 4, depth = 8 } = data;
15461
+ if (channels !== 4 && channels !== 3 && channels !== 2 && channels !== 1) {
15462
+ throw new RangeError(`unsupported number of channels: ${channels}`);
15463
+ }
15464
+ const returnValue = {
15465
+ channels,
15466
+ depth,
15467
+ colorType: ColorType.UNKNOWN
15468
+ };
15469
+ switch (channels) {
15470
+ case 4:
15471
+ returnValue.colorType = ColorType.TRUECOLOUR_ALPHA;
15472
+ break;
15473
+ case 3:
15474
+ returnValue.colorType = ColorType.TRUECOLOUR;
15475
+ break;
15476
+ case 1:
15477
+ if (palette) {
15478
+ returnValue.colorType = ColorType.INDEXED_COLOUR;
15479
+ } else {
15480
+ returnValue.colorType = ColorType.GREYSCALE;
15481
+ }
15482
+ break;
15483
+ case 2:
15484
+ returnValue.colorType = ColorType.GREYSCALE_ALPHA;
15485
+ break;
15486
+ default:
15487
+ throw new Error("unsupported number of channels");
15488
+ }
15489
+ return returnValue;
15490
+ }
15491
+ function writeDataBytes(data, newData, slotsPerLine, offset) {
15492
+ for (let j = 0;j < slotsPerLine; j++) {
15493
+ newData.writeByte(data[offset++]);
15494
+ }
15495
+ return offset;
15496
+ }
15497
+ function writeDataInterlaced(imageData, data, newData, offset) {
15498
+ const passes = [
15499
+ { x: 0, y: 0, xStep: 8, yStep: 8 },
15500
+ { x: 4, y: 0, xStep: 8, yStep: 8 },
15501
+ { x: 0, y: 4, xStep: 4, yStep: 8 },
15502
+ { x: 2, y: 0, xStep: 4, yStep: 4 },
15503
+ { x: 0, y: 2, xStep: 2, yStep: 4 },
15504
+ { x: 1, y: 0, xStep: 2, yStep: 2 },
15505
+ { x: 0, y: 1, xStep: 1, yStep: 2 }
15506
+ ];
15507
+ const { width, height, channels, depth } = imageData;
15508
+ let pixelSize;
15509
+ if (depth === 16) {
15510
+ pixelSize = channels * depth / 8 / 2;
15511
+ } else {
15512
+ pixelSize = channels * depth / 8;
15513
+ }
15514
+ for (let passIndex = 0;passIndex < 7; passIndex++) {
15515
+ const pass = passes[passIndex];
15516
+ const passWidth = Math.floor((width - pass.x + pass.xStep - 1) / pass.xStep);
15517
+ const passHeight = Math.floor((height - pass.y + pass.yStep - 1) / pass.yStep);
15518
+ if (passWidth <= 0 || passHeight <= 0)
15519
+ continue;
15520
+ const passLineBytes = passWidth * pixelSize;
15521
+ for (let y = 0;y < passHeight; y++) {
15522
+ const imageY = pass.y + y * pass.yStep;
15523
+ const rawScanline = depth <= 8 ? new Uint8Array(passLineBytes) : new Uint16Array(passLineBytes);
15524
+ let rawOffset = 0;
15525
+ for (let x2 = 0;x2 < passWidth; x2++) {
15526
+ const imageX = pass.x + x2 * pass.xStep;
15527
+ if (imageX < width && imageY < height) {
15528
+ const srcPos = (imageY * width + imageX) * pixelSize;
15529
+ for (let i2 = 0;i2 < pixelSize; i2++) {
15530
+ rawScanline[rawOffset++] = data[srcPos + i2];
15531
+ }
15532
+ }
15533
+ }
15534
+ newData.writeByte(0);
15535
+ if (depth === 8) {
15536
+ newData.writeBytes(rawScanline);
15537
+ } else if (depth === 16) {
15538
+ for (const value of rawScanline) {
15539
+ newData.writeByte(value >> 8 & 255);
15540
+ newData.writeByte(value & 255);
15541
+ }
15542
+ }
15543
+ }
15544
+ }
15545
+ return offset;
15546
+ }
15547
+ function writeDataUint16(data, newData, slotsPerLine, offset) {
15548
+ for (let j = 0;j < slotsPerLine; j++) {
15549
+ newData.writeUint16(data[offset++]);
15550
+ }
15551
+ return offset;
15552
+ }
15553
+
15554
+ // node_modules/fast-png/lib/index.js
15555
+ function decodePng(data, options) {
15556
+ const decoder = new PngDecoder(data, options);
15557
+ return decoder.decode();
15558
+ }
15559
+ function encodePng(png, options) {
15560
+ const encoder2 = new PngEncoder(png, options);
15561
+ return encoder2.encode();
15562
+ }
15563
+
15564
+ // node_modules/@tscircuit/image-utils/dist/looks-same.js
15565
+ var DEFAULT_TOLERANCE = 2.3;
15566
+ var DEFAULT_HIGHLIGHT = { R: 255, G: 0, B: 255 };
15567
+ var areColorsSame = ({
15568
+ color1,
15569
+ color2
15570
+ }) => {
15571
+ return color1.R === color2.R && color1.G === color2.G && color1.B === color2.B;
15572
+ };
15573
+ var parsePng = (buffer) => {
15574
+ try {
15575
+ const png = decodePng(buffer);
15576
+ if (png.depth !== 8)
15577
+ return null;
15578
+ const channels = png.channels;
15579
+ const source = png.data;
15580
+ const rgba = new Uint8Array(png.width * png.height * 4);
15581
+ if (channels === 4) {
15582
+ rgba.set(source);
15583
+ } else if (channels === 3) {
15584
+ for (let i2 = 0, j = 0;i2 < source.length; i2 += 3, j += 4) {
15585
+ rgba[j] = source[i2];
15586
+ rgba[j + 1] = source[i2 + 1];
15587
+ rgba[j + 2] = source[i2 + 2];
15588
+ rgba[j + 3] = 255;
15589
+ }
15590
+ } else {
15591
+ return null;
15592
+ }
15593
+ return {
15594
+ width: png.width,
15595
+ height: png.height,
15596
+ data: rgba,
15597
+ getPixel: (x2, y) => {
15598
+ const index = (y * png.width + x2) * 4;
15599
+ return {
15600
+ R: rgba[index],
15601
+ G: rgba[index + 1],
15602
+ B: rgba[index + 2]
15603
+ };
15604
+ }
15605
+ };
15606
+ } catch {
15607
+ return null;
15608
+ }
15609
+ };
15610
+ var getBuffer = async (input) => {
15611
+ if (Buffer.isBuffer(input))
15612
+ return input;
15613
+ return readFile(input);
15614
+ };
15615
+ var parseHexColor = (color) => {
15616
+ if (!color)
15617
+ return DEFAULT_HIGHLIGHT;
15618
+ const match = /^#?([0-9a-fA-F]{6})$/.exec(color.trim());
15619
+ if (!match)
15620
+ return DEFAULT_HIGHLIGHT;
15621
+ const hex = match[1];
15622
+ return {
15623
+ R: Number.parseInt(hex.slice(0, 2), 16),
15624
+ G: Number.parseInt(hex.slice(2, 4), 16),
15625
+ B: Number.parseInt(hex.slice(4, 6), 16)
15626
+ };
15627
+ };
15628
+ var makeCIEDE2000Comparator = (tolerance) => {
15629
+ const upperBound = tolerance * 6.2;
15630
+ const lowerBound = tolerance * 0.695;
15631
+ let rgbColor1 = null;
15632
+ let rgbColor2 = null;
15633
+ let labColor1 = null;
15634
+ let labColor2 = null;
15635
+ return (data) => {
15636
+ if (areColorsSame(data)) {
15637
+ return true;
15638
+ }
15639
+ let lab1 = null;
15640
+ let lab2 = null;
15641
+ if (rgbColor1 && areColorsSame({ color1: data.color1, color2: rgbColor1 })) {
15642
+ lab1 = labColor1;
15643
+ } else if (rgbColor2 && areColorsSame({ color1: data.color1, color2: rgbColor2 })) {
15644
+ lab1 = labColor2;
15645
+ }
15646
+ if (rgbColor1 && areColorsSame({ color1: data.color2, color2: rgbColor1 })) {
15647
+ lab2 = labColor1;
15648
+ } else if (rgbColor2 && areColorsSame({ color1: data.color2, color2: rgbColor2 })) {
15649
+ lab2 = labColor2;
15650
+ }
15651
+ if (!lab1) {
15652
+ lab1 = rgb_to_lab(data.color1);
15653
+ rgbColor1 = data.color1;
15654
+ labColor1 = lab1;
15655
+ }
15656
+ if (!lab2) {
15657
+ lab2 = rgb_to_lab(data.color2);
15658
+ rgbColor2 = data.color2;
15659
+ labColor2 = lab2;
15660
+ }
15661
+ 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));
15662
+ if (cie76 >= upperBound)
15663
+ return false;
15664
+ if (cie76 <= lowerBound)
15665
+ return true;
15666
+ return ciede2000(lab1, lab2) < tolerance;
15667
+ };
15668
+ };
15669
+ var AntialiasingComparator = class {
15670
+ _baseComparator;
15671
+ _img1;
15672
+ _img2;
15673
+ _brightnessTolerance;
15674
+ constructor(baseComparator, img1, img2, { antialiasingTolerance = 0 }) {
15675
+ this._baseComparator = baseComparator;
15676
+ this._img1 = img1;
15677
+ this._img2 = img2;
15678
+ this._brightnessTolerance = antialiasingTolerance;
15679
+ }
15680
+ compare(data) {
15681
+ return this._baseComparator(data) || this._checkIsAntialiased(data);
15682
+ }
15683
+ _checkIsAntialiased(data) {
15684
+ return this._isAntialiased(this._img2, data.x, data.y, data, this._img1) || this._isAntialiased(this._img1, data.x, data.y, data, this._img2);
15685
+ }
15686
+ _isAntialiased(img1, x1, y1, data, img2) {
15687
+ const color1 = img1.getPixel(x1, y1);
15688
+ const x0 = Math.max(x1 - 1, 0);
15689
+ const y0 = Math.max(y1 - 1, 0);
15690
+ const x2 = Math.min(x1 + 1, data.width - 1);
15691
+ const y2 = Math.min(y1 + 1, data.height - 1);
15692
+ const checkExtremePixels = !img2;
15693
+ const brightnessTolerance = checkExtremePixels ? this._brightnessTolerance : 0;
15694
+ let zeroes = 0;
15695
+ let positives = 0;
15696
+ let negatives = 0;
15697
+ let min = 0;
15698
+ let max2 = 0;
15699
+ let minX = 0;
15700
+ let minY = 0;
15701
+ let maxX = 0;
15702
+ let maxY = 0;
15703
+ for (let y = y0;y <= y2; y += 1) {
15704
+ for (let x3 = x0;x3 <= x2; x3 += 1) {
15705
+ if (x3 === x1 && y === y1)
15706
+ continue;
15707
+ const delta = this._brightnessDelta(img1.getPixel(x3, y), color1);
15708
+ if (Math.abs(delta) <= brightnessTolerance) {
15709
+ zeroes += 1;
15710
+ } else if (delta > brightnessTolerance) {
15711
+ positives += 1;
15712
+ } else {
15713
+ negatives += 1;
15714
+ }
15715
+ if (zeroes > 2)
15716
+ return false;
15717
+ if (checkExtremePixels)
15718
+ continue;
15719
+ if (delta < min) {
15720
+ min = delta;
15721
+ minX = x3;
15722
+ minY = y;
15723
+ }
15724
+ if (delta > max2) {
15725
+ max2 = delta;
15726
+ maxX = x3;
15727
+ maxY = y;
15728
+ }
15729
+ }
15730
+ }
15731
+ if (checkExtremePixels)
15732
+ return true;
15733
+ if (negatives === 0 || positives === 0)
15734
+ return false;
15735
+ 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);
15736
+ }
15737
+ _brightnessDelta(color1, color2) {
15738
+ 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);
15739
+ }
15740
+ };
15741
+ var IgnoreCaretComparator = class {
15742
+ pixelRatio;
15743
+ caretTopLeft = null;
15744
+ caretBottomRight = null;
15745
+ _baseComparator;
15746
+ _state = "init";
15747
+ constructor(baseComparator, pixelRatio) {
15748
+ this.pixelRatio = pixelRatio ? Math.floor(pixelRatio) : 1;
15749
+ this._baseComparator = baseComparator;
15750
+ }
15751
+ compare(data) {
15752
+ return this._baseComparator(data) || this._checkIsCaret(data);
15753
+ }
15754
+ _checkIsCaret(data) {
15755
+ if (this._state === "caretDetected") {
15756
+ 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;
15757
+ }
15758
+ 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) {
15759
+ return true;
15760
+ }
15761
+ const lastCaretPoint = this._getLastCaretPoint(data);
15762
+ if (!this._looksLikeCaret({ x: data.x, y: data.y }, lastCaretPoint)) {
15763
+ return false;
15764
+ }
15765
+ this.caretTopLeft = { x: data.x, y: data.y };
15766
+ this.caretBottomRight = lastCaretPoint;
15767
+ this._state = "caretDetected";
15768
+ return true;
15769
+ }
15770
+ _getLastCaretPoint(data) {
15771
+ let currPoint = { x: data.x, y: data.y };
15772
+ while (true) {
15773
+ const nextPoint = this._getNextCaretPoint({ x: data.x, y: data.y }, currPoint);
15774
+ if (this._isPointOutsideImages(nextPoint, data) || this._areColorsSame(nextPoint, data)) {
15775
+ return currPoint;
15776
+ }
15777
+ currPoint = nextPoint;
15778
+ }
15779
+ }
15780
+ _isPointOutsideImages(point, data) {
15781
+ return point.x >= data.minWidth || point.y >= data.minHeight;
15782
+ }
15783
+ _areColorsSame(point, data) {
15784
+ const color1 = data.img1.getPixel(point.x, point.y);
15785
+ const color2 = data.img2.getPixel(point.x, point.y);
15786
+ return areColorsSame({ color1, color2 });
15787
+ }
15788
+ _getNextCaretPoint(firstCaretPoint, currPoint) {
15789
+ const nextX = currPoint.x + 1;
15790
+ return nextX < firstCaretPoint.x + this.pixelRatio ? { x: nextX, y: currPoint.y } : { x: firstCaretPoint.x, y: currPoint.y + 1 };
15791
+ }
15792
+ _looksLikeCaret(firstCaretPoint, lastCaretPoint) {
15793
+ return this._caretHeight(firstCaretPoint, lastCaretPoint) > 1 && this._caretWidth(firstCaretPoint, lastCaretPoint) === this.pixelRatio;
15794
+ }
15795
+ _caretHeight(firstCaretPoint, lastCaretPoint) {
15796
+ return lastCaretPoint.y - firstCaretPoint.y + 1;
15797
+ }
15798
+ _caretWidth(firstCaretPoint, lastCaretPoint) {
15799
+ return lastCaretPoint.x - firstCaretPoint.x + 1;
15800
+ }
15801
+ };
15802
+ var prepareOptions = (options = {}) => {
15803
+ if (options.strict && options.tolerance !== undefined) {
15804
+ throw new TypeError('Unable to use "strict" and "tolerance" options together');
15805
+ }
15806
+ if (options.percentThreshold !== undefined && (!Number.isFinite(options.percentThreshold) || options.percentThreshold < 0)) {
15807
+ throw new TypeError('Expected "percentThreshold" to be a non-negative number');
15808
+ }
15809
+ return {
15810
+ strict: Boolean(options.strict),
15811
+ tolerance: options.tolerance ?? DEFAULT_TOLERANCE,
15812
+ ignoreCaret: options.ignoreCaret ?? true,
15813
+ ignoreAntialiasing: options.ignoreAntialiasing ?? true,
15814
+ antialiasingTolerance: options.antialiasingTolerance ?? 0,
15815
+ pixelRatio: options.pixelRatio
15816
+ };
15817
+ };
15818
+ var createComparator = (img1, img2, options) => {
15819
+ let comparator = options.strict ? (data) => areColorsSame(data) : makeCIEDE2000Comparator(options.tolerance);
15820
+ if (options.ignoreAntialiasing) {
15821
+ const antialiasingComparator = new AntialiasingComparator(comparator, img1, img2, options);
15822
+ comparator = (data) => antialiasingComparator.compare(data);
15823
+ }
15824
+ if (options.ignoreCaret) {
15825
+ const caretComparator = new IgnoreCaretComparator(comparator, options.pixelRatio);
15826
+ comparator = (data) => caretComparator.compare(data);
15827
+ }
15828
+ return comparator;
15829
+ };
15830
+ var compare = async (buffer1, buffer2, options) => {
15831
+ const reference = parsePng(buffer1);
15832
+ const current = parsePng(buffer2);
15833
+ if (!reference || !current) {
15834
+ return { equal: buffer1.equals(buffer2) };
15835
+ }
15836
+ const comparator = createComparator(reference, current, options);
15837
+ const width = Math.max(reference.width, current.width);
15838
+ const height = Math.max(reference.height, current.height);
15839
+ const minWidth = Math.min(reference.width, current.width);
15840
+ const minHeight = Math.min(reference.height, current.height);
15841
+ const totalPixels = width * height;
15842
+ let differentPixels = 0;
15843
+ for (let y = 0;y < height; y += 1) {
15844
+ for (let x2 = 0;x2 < width; x2 += 1) {
15845
+ if (x2 >= minWidth || y >= minHeight) {
15846
+ differentPixels += 1;
15847
+ continue;
15848
+ }
15849
+ const color1 = reference.getPixel(x2, y);
15850
+ const color2 = current.getPixel(x2, y);
15851
+ const same = areColorsSame({ color1, color2 }) || comparator({
15852
+ color1,
15853
+ color2,
15854
+ img1: reference,
15855
+ img2: current,
15856
+ x: x2,
15857
+ y,
15858
+ width,
15859
+ height,
15860
+ minWidth,
15861
+ minHeight
15862
+ });
15863
+ if (!same) {
15864
+ differentPixels += 1;
15865
+ }
15866
+ }
15867
+ }
15868
+ return {
15869
+ equal: differentPixels === 0,
15870
+ differentPixels,
15871
+ totalPixels
15872
+ };
15873
+ };
15874
+ var looksSameImpl = async (reference, current, options = {}) => {
15875
+ const prepared = prepareOptions(options);
15876
+ const referenceBuffer = await getBuffer(reference);
15877
+ const currentBuffer = await getBuffer(current);
15878
+ return compare(referenceBuffer, currentBuffer, prepared);
15879
+ };
15880
+ var createDiff = async ({
15881
+ reference,
15882
+ current,
15883
+ diff: diff2,
15884
+ highlightColor,
15885
+ ...options
15886
+ }) => {
15887
+ const prepared = prepareOptions(options);
15888
+ const referenceBuffer = await getBuffer(reference);
15889
+ const currentBuffer = await getBuffer(current);
15890
+ const referencePng = parsePng(referenceBuffer);
15891
+ const currentPng = parsePng(currentBuffer);
15892
+ if (!(diff2.endsWith(".png") && referencePng && currentPng)) {
15893
+ await writeFile(diff2, currentBuffer);
15894
+ return;
15895
+ }
15896
+ const comparator = createComparator(referencePng, currentPng, prepared);
15897
+ const width = Math.max(referencePng.width, currentPng.width);
15898
+ const height = Math.max(referencePng.height, currentPng.height);
15899
+ const minWidth = Math.min(referencePng.width, currentPng.width);
15900
+ const minHeight = Math.min(referencePng.height, currentPng.height);
15901
+ const highlight = parseHexColor(highlightColor);
15902
+ const diffData = new Uint8Array(width * height * 4);
15903
+ for (let y = 0;y < height; y += 1) {
15904
+ for (let x2 = 0;x2 < width; x2 += 1) {
15905
+ const index = (y * width + x2) * 4;
15906
+ if (x2 >= minWidth || y >= minHeight) {
15907
+ diffData[index] = highlight.R;
15908
+ diffData[index + 1] = highlight.G;
15909
+ diffData[index + 2] = highlight.B;
15910
+ diffData[index + 3] = 255;
15911
+ continue;
15912
+ }
15913
+ const color1 = referencePng.getPixel(x2, y);
15914
+ const color2 = currentPng.getPixel(x2, y);
15915
+ const same = areColorsSame({ color1, color2 }) || comparator({
15916
+ color1,
15917
+ color2,
15918
+ img1: referencePng,
15919
+ img2: currentPng,
15920
+ x: x2,
15921
+ y,
15922
+ width,
15923
+ height,
15924
+ minWidth,
15925
+ minHeight
15926
+ });
15927
+ if (same) {
15928
+ diffData[index] = color1.R;
15929
+ diffData[index + 1] = color1.G;
15930
+ diffData[index + 2] = color1.B;
15931
+ diffData[index + 3] = 255;
15932
+ } else {
15933
+ diffData[index] = highlight.R;
15934
+ diffData[index + 1] = highlight.G;
15935
+ diffData[index + 2] = highlight.B;
15936
+ diffData[index + 3] = 255;
15937
+ }
15938
+ }
15939
+ }
15940
+ const encoded = encodePng({
15941
+ width,
15942
+ height,
15943
+ data: diffData,
15944
+ channels: 4,
15945
+ depth: 8
15946
+ });
15947
+ await writeFile(diff2, Buffer.from(encoded));
15948
+ };
15949
+ var looksSame = Object.assign(looksSameImpl, { createDiff });
15950
+ var looks_same_default = looksSame;
15951
+
13260
15952
  // lib/shared/compare-images.ts
13261
- import looksSame from "looks-same";
13262
15953
  import fs8 from "node:fs/promises";
13263
- var compareAndCreateDiff = async (buffer1, buffer2, diffPath, createDiff = true) => {
13264
- const { equal } = await looksSame(buffer1, buffer2, {
15954
+ var compareAndCreateDiff = async (buffer1, buffer2, diffPath, createDiff2 = true) => {
15955
+ const { equal } = await looks_same_default(buffer1, buffer2, {
13265
15956
  strict: false,
13266
15957
  tolerance: 2
13267
15958
  });
13268
- if (!equal && createDiff) {
15959
+ if (!equal && createDiff2) {
13269
15960
  if (diffPath.endsWith(".png")) {
13270
- await looksSame.createDiff({
15961
+ await looks_same_default.createDiff({
13271
15962
  reference: buffer1,
13272
15963
  current: buffer2,
13273
15964
  diff: diffPath,
@@ -13299,7 +15990,7 @@ var processSnapshotFile = async ({
13299
15990
  forceUpdate,
13300
15991
  platformConfig,
13301
15992
  pcbSnapshotSettings,
13302
- createDiff,
15993
+ createDiff: createDiff2,
13303
15994
  cameraPreset
13304
15995
  }) => {
13305
15996
  const relativeFilePath = path10.relative(projectDir, file);
@@ -13449,7 +16140,7 @@ var processSnapshotFile = async ({
13449
16140
  const oldContentBuffer = fs9.readFileSync(snapPath);
13450
16141
  let equal;
13451
16142
  let diffPath;
13452
- if (createDiff) {
16143
+ if (createDiff2) {
13453
16144
  diffPath = snapPath.replace(is3d ? ".snap.png" : ".snap.svg", is3d ? ".diff.png" : ".diff.svg");
13454
16145
  const comparison = await compareAndCreateDiff(oldContentBuffer, newContentBuffer, diffPath, true);
13455
16146
  equal = comparison.equal;