domflax 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/LICENSE +214 -0
  2. package/dist/chunk-4HHISSMR.js +2227 -0
  3. package/dist/chunk-4HHISSMR.js.map +1 -0
  4. package/dist/chunk-6WVVF6AD.js +55 -0
  5. package/dist/chunk-6WVVF6AD.js.map +1 -0
  6. package/dist/chunk-77SLHRN6.js +2047 -0
  7. package/dist/chunk-77SLHRN6.js.map +1 -0
  8. package/dist/chunk-ZJ2S36GY.js +175 -0
  9. package/dist/chunk-ZJ2S36GY.js.map +1 -0
  10. package/dist/cli.cjs +5207 -0
  11. package/dist/cli.cjs.map +1 -0
  12. package/dist/cli.d.cts +1 -0
  13. package/dist/cli.d.ts +1 -0
  14. package/dist/cli.js +1310 -0
  15. package/dist/cli.js.map +1 -0
  16. package/dist/index.cjs +4383 -0
  17. package/dist/index.cjs.map +1 -0
  18. package/dist/index.d.cts +539 -0
  19. package/dist/index.d.ts +539 -0
  20. package/dist/index.js +110 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/pattern-CX6iBzTD.d.ts +237 -0
  23. package/dist/pattern-P4FIKAUB.d.cts +237 -0
  24. package/dist/pattern-kit.cjs +630 -0
  25. package/dist/pattern-kit.cjs.map +1 -0
  26. package/dist/pattern-kit.d.cts +80 -0
  27. package/dist/pattern-kit.d.ts +80 -0
  28. package/dist/pattern-kit.js +55 -0
  29. package/dist/pattern-kit.js.map +1 -0
  30. package/dist/types-BQ7l6dVe.d.cts +749 -0
  31. package/dist/types-BQ7l6dVe.d.ts +749 -0
  32. package/dist/verify.cjs +2747 -0
  33. package/dist/verify.cjs.map +1 -0
  34. package/dist/verify.d.cts +245 -0
  35. package/dist/verify.d.ts +245 -0
  36. package/dist/verify.js +2700 -0
  37. package/dist/verify.js.map +1 -0
  38. package/dist/webpack-loader.cjs +4149 -0
  39. package/dist/webpack-loader.cjs.map +1 -0
  40. package/dist/webpack-loader.d.cts +21 -0
  41. package/dist/webpack-loader.d.ts +21 -0
  42. package/dist/webpack-loader.js +30 -0
  43. package/dist/webpack-loader.js.map +1 -0
  44. package/package.json +99 -0
@@ -0,0 +1,2747 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __esm = (fn, res) => function __init() {
9
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
+ };
11
+ var __commonJS = (cb, mod) => function __require() {
12
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
13
+ };
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
27
+ // If the importer is in node compatibility mode or this is not an ESM
28
+ // file that has been converted to a CommonJS file using a Babel-
29
+ // compatible transform (i.e. "__esModule" has not been set), then set
30
+ // "default" to the CommonJS "module.exports" for node compatibility.
31
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
32
+ mod
33
+ ));
34
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
35
+
36
+ // ../../node_modules/tsup/assets/cjs_shims.js
37
+ var init_cjs_shims = __esm({
38
+ "../../node_modules/tsup/assets/cjs_shims.js"() {
39
+ "use strict";
40
+ }
41
+ });
42
+
43
+ // ../../node_modules/pngjs/lib/chunkstream.js
44
+ var require_chunkstream = __commonJS({
45
+ "../../node_modules/pngjs/lib/chunkstream.js"(exports2, module2) {
46
+ "use strict";
47
+ init_cjs_shims();
48
+ var util = require("util");
49
+ var Stream = require("stream");
50
+ var ChunkStream = module2.exports = function() {
51
+ Stream.call(this);
52
+ this._buffers = [];
53
+ this._buffered = 0;
54
+ this._reads = [];
55
+ this._paused = false;
56
+ this._encoding = "utf8";
57
+ this.writable = true;
58
+ };
59
+ util.inherits(ChunkStream, Stream);
60
+ ChunkStream.prototype.read = function(length, callback) {
61
+ this._reads.push({
62
+ length: Math.abs(length),
63
+ // if length < 0 then at most this length
64
+ allowLess: length < 0,
65
+ func: callback
66
+ });
67
+ process.nextTick(
68
+ function() {
69
+ this._process();
70
+ if (this._paused && this._reads && this._reads.length > 0) {
71
+ this._paused = false;
72
+ this.emit("drain");
73
+ }
74
+ }.bind(this)
75
+ );
76
+ };
77
+ ChunkStream.prototype.write = function(data, encoding) {
78
+ if (!this.writable) {
79
+ this.emit("error", new Error("Stream not writable"));
80
+ return false;
81
+ }
82
+ let dataBuffer;
83
+ if (Buffer.isBuffer(data)) {
84
+ dataBuffer = data;
85
+ } else {
86
+ dataBuffer = Buffer.from(data, encoding || this._encoding);
87
+ }
88
+ this._buffers.push(dataBuffer);
89
+ this._buffered += dataBuffer.length;
90
+ this._process();
91
+ if (this._reads && this._reads.length === 0) {
92
+ this._paused = true;
93
+ }
94
+ return this.writable && !this._paused;
95
+ };
96
+ ChunkStream.prototype.end = function(data, encoding) {
97
+ if (data) {
98
+ this.write(data, encoding);
99
+ }
100
+ this.writable = false;
101
+ if (!this._buffers) {
102
+ return;
103
+ }
104
+ if (this._buffers.length === 0) {
105
+ this._end();
106
+ } else {
107
+ this._buffers.push(null);
108
+ this._process();
109
+ }
110
+ };
111
+ ChunkStream.prototype.destroySoon = ChunkStream.prototype.end;
112
+ ChunkStream.prototype._end = function() {
113
+ if (this._reads.length > 0) {
114
+ this.emit("error", new Error("Unexpected end of input"));
115
+ }
116
+ this.destroy();
117
+ };
118
+ ChunkStream.prototype.destroy = function() {
119
+ if (!this._buffers) {
120
+ return;
121
+ }
122
+ this.writable = false;
123
+ this._reads = null;
124
+ this._buffers = null;
125
+ this.emit("close");
126
+ };
127
+ ChunkStream.prototype._processReadAllowingLess = function(read) {
128
+ this._reads.shift();
129
+ let smallerBuf = this._buffers[0];
130
+ if (smallerBuf.length > read.length) {
131
+ this._buffered -= read.length;
132
+ this._buffers[0] = smallerBuf.slice(read.length);
133
+ read.func.call(this, smallerBuf.slice(0, read.length));
134
+ } else {
135
+ this._buffered -= smallerBuf.length;
136
+ this._buffers.shift();
137
+ read.func.call(this, smallerBuf);
138
+ }
139
+ };
140
+ ChunkStream.prototype._processRead = function(read) {
141
+ this._reads.shift();
142
+ let pos = 0;
143
+ let count = 0;
144
+ let data = Buffer.alloc(read.length);
145
+ while (pos < read.length) {
146
+ let buf = this._buffers[count++];
147
+ let len = Math.min(buf.length, read.length - pos);
148
+ buf.copy(data, pos, 0, len);
149
+ pos += len;
150
+ if (len !== buf.length) {
151
+ this._buffers[--count] = buf.slice(len);
152
+ }
153
+ }
154
+ if (count > 0) {
155
+ this._buffers.splice(0, count);
156
+ }
157
+ this._buffered -= read.length;
158
+ read.func.call(this, data);
159
+ };
160
+ ChunkStream.prototype._process = function() {
161
+ try {
162
+ while (this._buffered > 0 && this._reads && this._reads.length > 0) {
163
+ let read = this._reads[0];
164
+ if (read.allowLess) {
165
+ this._processReadAllowingLess(read);
166
+ } else if (this._buffered >= read.length) {
167
+ this._processRead(read);
168
+ } else {
169
+ break;
170
+ }
171
+ }
172
+ if (this._buffers && !this.writable) {
173
+ this._end();
174
+ }
175
+ } catch (ex) {
176
+ this.emit("error", ex);
177
+ }
178
+ };
179
+ }
180
+ });
181
+
182
+ // ../../node_modules/pngjs/lib/interlace.js
183
+ var require_interlace = __commonJS({
184
+ "../../node_modules/pngjs/lib/interlace.js"(exports2) {
185
+ "use strict";
186
+ init_cjs_shims();
187
+ var imagePasses = [
188
+ {
189
+ // pass 1 - 1px
190
+ x: [0],
191
+ y: [0]
192
+ },
193
+ {
194
+ // pass 2 - 1px
195
+ x: [4],
196
+ y: [0]
197
+ },
198
+ {
199
+ // pass 3 - 2px
200
+ x: [0, 4],
201
+ y: [4]
202
+ },
203
+ {
204
+ // pass 4 - 4px
205
+ x: [2, 6],
206
+ y: [0, 4]
207
+ },
208
+ {
209
+ // pass 5 - 8px
210
+ x: [0, 2, 4, 6],
211
+ y: [2, 6]
212
+ },
213
+ {
214
+ // pass 6 - 16px
215
+ x: [1, 3, 5, 7],
216
+ y: [0, 2, 4, 6]
217
+ },
218
+ {
219
+ // pass 7 - 32px
220
+ x: [0, 1, 2, 3, 4, 5, 6, 7],
221
+ y: [1, 3, 5, 7]
222
+ }
223
+ ];
224
+ exports2.getImagePasses = function(width, height) {
225
+ let images = [];
226
+ let xLeftOver = width % 8;
227
+ let yLeftOver = height % 8;
228
+ let xRepeats = (width - xLeftOver) / 8;
229
+ let yRepeats = (height - yLeftOver) / 8;
230
+ for (let i = 0; i < imagePasses.length; i++) {
231
+ let pass = imagePasses[i];
232
+ let passWidth = xRepeats * pass.x.length;
233
+ let passHeight = yRepeats * pass.y.length;
234
+ for (let j = 0; j < pass.x.length; j++) {
235
+ if (pass.x[j] < xLeftOver) {
236
+ passWidth++;
237
+ } else {
238
+ break;
239
+ }
240
+ }
241
+ for (let j = 0; j < pass.y.length; j++) {
242
+ if (pass.y[j] < yLeftOver) {
243
+ passHeight++;
244
+ } else {
245
+ break;
246
+ }
247
+ }
248
+ if (passWidth > 0 && passHeight > 0) {
249
+ images.push({ width: passWidth, height: passHeight, index: i });
250
+ }
251
+ }
252
+ return images;
253
+ };
254
+ exports2.getInterlaceIterator = function(width) {
255
+ return function(x, y, pass) {
256
+ let outerXLeftOver = x % imagePasses[pass].x.length;
257
+ let outerX = (x - outerXLeftOver) / imagePasses[pass].x.length * 8 + imagePasses[pass].x[outerXLeftOver];
258
+ let outerYLeftOver = y % imagePasses[pass].y.length;
259
+ let outerY = (y - outerYLeftOver) / imagePasses[pass].y.length * 8 + imagePasses[pass].y[outerYLeftOver];
260
+ return outerX * 4 + outerY * width * 4;
261
+ };
262
+ };
263
+ }
264
+ });
265
+
266
+ // ../../node_modules/pngjs/lib/paeth-predictor.js
267
+ var require_paeth_predictor = __commonJS({
268
+ "../../node_modules/pngjs/lib/paeth-predictor.js"(exports2, module2) {
269
+ "use strict";
270
+ init_cjs_shims();
271
+ module2.exports = function paethPredictor(left, above, upLeft) {
272
+ let paeth = left + above - upLeft;
273
+ let pLeft = Math.abs(paeth - left);
274
+ let pAbove = Math.abs(paeth - above);
275
+ let pUpLeft = Math.abs(paeth - upLeft);
276
+ if (pLeft <= pAbove && pLeft <= pUpLeft) {
277
+ return left;
278
+ }
279
+ if (pAbove <= pUpLeft) {
280
+ return above;
281
+ }
282
+ return upLeft;
283
+ };
284
+ }
285
+ });
286
+
287
+ // ../../node_modules/pngjs/lib/filter-parse.js
288
+ var require_filter_parse = __commonJS({
289
+ "../../node_modules/pngjs/lib/filter-parse.js"(exports2, module2) {
290
+ "use strict";
291
+ init_cjs_shims();
292
+ var interlaceUtils = require_interlace();
293
+ var paethPredictor = require_paeth_predictor();
294
+ function getByteWidth(width, bpp, depth) {
295
+ let byteWidth = width * bpp;
296
+ if (depth !== 8) {
297
+ byteWidth = Math.ceil(byteWidth / (8 / depth));
298
+ }
299
+ return byteWidth;
300
+ }
301
+ var Filter = module2.exports = function(bitmapInfo, dependencies) {
302
+ let width = bitmapInfo.width;
303
+ let height = bitmapInfo.height;
304
+ let interlace = bitmapInfo.interlace;
305
+ let bpp = bitmapInfo.bpp;
306
+ let depth = bitmapInfo.depth;
307
+ this.read = dependencies.read;
308
+ this.write = dependencies.write;
309
+ this.complete = dependencies.complete;
310
+ this._imageIndex = 0;
311
+ this._images = [];
312
+ if (interlace) {
313
+ let passes = interlaceUtils.getImagePasses(width, height);
314
+ for (let i = 0; i < passes.length; i++) {
315
+ this._images.push({
316
+ byteWidth: getByteWidth(passes[i].width, bpp, depth),
317
+ height: passes[i].height,
318
+ lineIndex: 0
319
+ });
320
+ }
321
+ } else {
322
+ this._images.push({
323
+ byteWidth: getByteWidth(width, bpp, depth),
324
+ height,
325
+ lineIndex: 0
326
+ });
327
+ }
328
+ if (depth === 8) {
329
+ this._xComparison = bpp;
330
+ } else if (depth === 16) {
331
+ this._xComparison = bpp * 2;
332
+ } else {
333
+ this._xComparison = 1;
334
+ }
335
+ };
336
+ Filter.prototype.start = function() {
337
+ this.read(
338
+ this._images[this._imageIndex].byteWidth + 1,
339
+ this._reverseFilterLine.bind(this)
340
+ );
341
+ };
342
+ Filter.prototype._unFilterType1 = function(rawData, unfilteredLine, byteWidth) {
343
+ let xComparison = this._xComparison;
344
+ let xBiggerThan = xComparison - 1;
345
+ for (let x = 0; x < byteWidth; x++) {
346
+ let rawByte = rawData[1 + x];
347
+ let f1Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
348
+ unfilteredLine[x] = rawByte + f1Left;
349
+ }
350
+ };
351
+ Filter.prototype._unFilterType2 = function(rawData, unfilteredLine, byteWidth) {
352
+ let lastLine = this._lastLine;
353
+ for (let x = 0; x < byteWidth; x++) {
354
+ let rawByte = rawData[1 + x];
355
+ let f2Up = lastLine ? lastLine[x] : 0;
356
+ unfilteredLine[x] = rawByte + f2Up;
357
+ }
358
+ };
359
+ Filter.prototype._unFilterType3 = function(rawData, unfilteredLine, byteWidth) {
360
+ let xComparison = this._xComparison;
361
+ let xBiggerThan = xComparison - 1;
362
+ let lastLine = this._lastLine;
363
+ for (let x = 0; x < byteWidth; x++) {
364
+ let rawByte = rawData[1 + x];
365
+ let f3Up = lastLine ? lastLine[x] : 0;
366
+ let f3Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
367
+ let f3Add = Math.floor((f3Left + f3Up) / 2);
368
+ unfilteredLine[x] = rawByte + f3Add;
369
+ }
370
+ };
371
+ Filter.prototype._unFilterType4 = function(rawData, unfilteredLine, byteWidth) {
372
+ let xComparison = this._xComparison;
373
+ let xBiggerThan = xComparison - 1;
374
+ let lastLine = this._lastLine;
375
+ for (let x = 0; x < byteWidth; x++) {
376
+ let rawByte = rawData[1 + x];
377
+ let f4Up = lastLine ? lastLine[x] : 0;
378
+ let f4Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
379
+ let f4UpLeft = x > xBiggerThan && lastLine ? lastLine[x - xComparison] : 0;
380
+ let f4Add = paethPredictor(f4Left, f4Up, f4UpLeft);
381
+ unfilteredLine[x] = rawByte + f4Add;
382
+ }
383
+ };
384
+ Filter.prototype._reverseFilterLine = function(rawData) {
385
+ let filter = rawData[0];
386
+ let unfilteredLine;
387
+ let currentImage = this._images[this._imageIndex];
388
+ let byteWidth = currentImage.byteWidth;
389
+ if (filter === 0) {
390
+ unfilteredLine = rawData.slice(1, byteWidth + 1);
391
+ } else {
392
+ unfilteredLine = Buffer.alloc(byteWidth);
393
+ switch (filter) {
394
+ case 1:
395
+ this._unFilterType1(rawData, unfilteredLine, byteWidth);
396
+ break;
397
+ case 2:
398
+ this._unFilterType2(rawData, unfilteredLine, byteWidth);
399
+ break;
400
+ case 3:
401
+ this._unFilterType3(rawData, unfilteredLine, byteWidth);
402
+ break;
403
+ case 4:
404
+ this._unFilterType4(rawData, unfilteredLine, byteWidth);
405
+ break;
406
+ default:
407
+ throw new Error("Unrecognised filter type - " + filter);
408
+ }
409
+ }
410
+ this.write(unfilteredLine);
411
+ currentImage.lineIndex++;
412
+ if (currentImage.lineIndex >= currentImage.height) {
413
+ this._lastLine = null;
414
+ this._imageIndex++;
415
+ currentImage = this._images[this._imageIndex];
416
+ } else {
417
+ this._lastLine = unfilteredLine;
418
+ }
419
+ if (currentImage) {
420
+ this.read(currentImage.byteWidth + 1, this._reverseFilterLine.bind(this));
421
+ } else {
422
+ this._lastLine = null;
423
+ this.complete();
424
+ }
425
+ };
426
+ }
427
+ });
428
+
429
+ // ../../node_modules/pngjs/lib/filter-parse-async.js
430
+ var require_filter_parse_async = __commonJS({
431
+ "../../node_modules/pngjs/lib/filter-parse-async.js"(exports2, module2) {
432
+ "use strict";
433
+ init_cjs_shims();
434
+ var util = require("util");
435
+ var ChunkStream = require_chunkstream();
436
+ var Filter = require_filter_parse();
437
+ var FilterAsync = module2.exports = function(bitmapInfo) {
438
+ ChunkStream.call(this);
439
+ let buffers = [];
440
+ let that = this;
441
+ this._filter = new Filter(bitmapInfo, {
442
+ read: this.read.bind(this),
443
+ write: function(buffer) {
444
+ buffers.push(buffer);
445
+ },
446
+ complete: function() {
447
+ that.emit("complete", Buffer.concat(buffers));
448
+ }
449
+ });
450
+ this._filter.start();
451
+ };
452
+ util.inherits(FilterAsync, ChunkStream);
453
+ }
454
+ });
455
+
456
+ // ../../node_modules/pngjs/lib/constants.js
457
+ var require_constants = __commonJS({
458
+ "../../node_modules/pngjs/lib/constants.js"(exports2, module2) {
459
+ "use strict";
460
+ init_cjs_shims();
461
+ module2.exports = {
462
+ PNG_SIGNATURE: [137, 80, 78, 71, 13, 10, 26, 10],
463
+ TYPE_IHDR: 1229472850,
464
+ TYPE_IEND: 1229278788,
465
+ TYPE_IDAT: 1229209940,
466
+ TYPE_PLTE: 1347179589,
467
+ TYPE_tRNS: 1951551059,
468
+ // eslint-disable-line camelcase
469
+ TYPE_gAMA: 1732332865,
470
+ // eslint-disable-line camelcase
471
+ // color-type bits
472
+ COLORTYPE_GRAYSCALE: 0,
473
+ COLORTYPE_PALETTE: 1,
474
+ COLORTYPE_COLOR: 2,
475
+ COLORTYPE_ALPHA: 4,
476
+ // e.g. grayscale and alpha
477
+ // color-type combinations
478
+ COLORTYPE_PALETTE_COLOR: 3,
479
+ COLORTYPE_COLOR_ALPHA: 6,
480
+ COLORTYPE_TO_BPP_MAP: {
481
+ 0: 1,
482
+ 2: 3,
483
+ 3: 1,
484
+ 4: 2,
485
+ 6: 4
486
+ },
487
+ GAMMA_DIVISION: 1e5
488
+ };
489
+ }
490
+ });
491
+
492
+ // ../../node_modules/pngjs/lib/crc.js
493
+ var require_crc = __commonJS({
494
+ "../../node_modules/pngjs/lib/crc.js"(exports2, module2) {
495
+ "use strict";
496
+ init_cjs_shims();
497
+ var crcTable = [];
498
+ (function() {
499
+ for (let i = 0; i < 256; i++) {
500
+ let currentCrc = i;
501
+ for (let j = 0; j < 8; j++) {
502
+ if (currentCrc & 1) {
503
+ currentCrc = 3988292384 ^ currentCrc >>> 1;
504
+ } else {
505
+ currentCrc = currentCrc >>> 1;
506
+ }
507
+ }
508
+ crcTable[i] = currentCrc;
509
+ }
510
+ })();
511
+ var CrcCalculator = module2.exports = function() {
512
+ this._crc = -1;
513
+ };
514
+ CrcCalculator.prototype.write = function(data) {
515
+ for (let i = 0; i < data.length; i++) {
516
+ this._crc = crcTable[(this._crc ^ data[i]) & 255] ^ this._crc >>> 8;
517
+ }
518
+ return true;
519
+ };
520
+ CrcCalculator.prototype.crc32 = function() {
521
+ return this._crc ^ -1;
522
+ };
523
+ CrcCalculator.crc32 = function(buf) {
524
+ let crc = -1;
525
+ for (let i = 0; i < buf.length; i++) {
526
+ crc = crcTable[(crc ^ buf[i]) & 255] ^ crc >>> 8;
527
+ }
528
+ return crc ^ -1;
529
+ };
530
+ }
531
+ });
532
+
533
+ // ../../node_modules/pngjs/lib/parser.js
534
+ var require_parser = __commonJS({
535
+ "../../node_modules/pngjs/lib/parser.js"(exports2, module2) {
536
+ "use strict";
537
+ init_cjs_shims();
538
+ var constants = require_constants();
539
+ var CrcCalculator = require_crc();
540
+ var Parser = module2.exports = function(options, dependencies) {
541
+ this._options = options;
542
+ options.checkCRC = options.checkCRC !== false;
543
+ this._hasIHDR = false;
544
+ this._hasIEND = false;
545
+ this._emittedHeadersFinished = false;
546
+ this._palette = [];
547
+ this._colorType = 0;
548
+ this._chunks = {};
549
+ this._chunks[constants.TYPE_IHDR] = this._handleIHDR.bind(this);
550
+ this._chunks[constants.TYPE_IEND] = this._handleIEND.bind(this);
551
+ this._chunks[constants.TYPE_IDAT] = this._handleIDAT.bind(this);
552
+ this._chunks[constants.TYPE_PLTE] = this._handlePLTE.bind(this);
553
+ this._chunks[constants.TYPE_tRNS] = this._handleTRNS.bind(this);
554
+ this._chunks[constants.TYPE_gAMA] = this._handleGAMA.bind(this);
555
+ this.read = dependencies.read;
556
+ this.error = dependencies.error;
557
+ this.metadata = dependencies.metadata;
558
+ this.gamma = dependencies.gamma;
559
+ this.transColor = dependencies.transColor;
560
+ this.palette = dependencies.palette;
561
+ this.parsed = dependencies.parsed;
562
+ this.inflateData = dependencies.inflateData;
563
+ this.finished = dependencies.finished;
564
+ this.simpleTransparency = dependencies.simpleTransparency;
565
+ this.headersFinished = dependencies.headersFinished || function() {
566
+ };
567
+ };
568
+ Parser.prototype.start = function() {
569
+ this.read(constants.PNG_SIGNATURE.length, this._parseSignature.bind(this));
570
+ };
571
+ Parser.prototype._parseSignature = function(data) {
572
+ let signature = constants.PNG_SIGNATURE;
573
+ for (let i = 0; i < signature.length; i++) {
574
+ if (data[i] !== signature[i]) {
575
+ this.error(new Error("Invalid file signature"));
576
+ return;
577
+ }
578
+ }
579
+ this.read(8, this._parseChunkBegin.bind(this));
580
+ };
581
+ Parser.prototype._parseChunkBegin = function(data) {
582
+ let length = data.readUInt32BE(0);
583
+ let type = data.readUInt32BE(4);
584
+ let name = "";
585
+ for (let i = 4; i < 8; i++) {
586
+ name += String.fromCharCode(data[i]);
587
+ }
588
+ let ancillary = Boolean(data[4] & 32);
589
+ if (!this._hasIHDR && type !== constants.TYPE_IHDR) {
590
+ this.error(new Error("Expected IHDR on beggining"));
591
+ return;
592
+ }
593
+ this._crc = new CrcCalculator();
594
+ this._crc.write(Buffer.from(name));
595
+ if (this._chunks[type]) {
596
+ return this._chunks[type](length);
597
+ }
598
+ if (!ancillary) {
599
+ this.error(new Error("Unsupported critical chunk type " + name));
600
+ return;
601
+ }
602
+ this.read(length + 4, this._skipChunk.bind(this));
603
+ };
604
+ Parser.prototype._skipChunk = function() {
605
+ this.read(8, this._parseChunkBegin.bind(this));
606
+ };
607
+ Parser.prototype._handleChunkEnd = function() {
608
+ this.read(4, this._parseChunkEnd.bind(this));
609
+ };
610
+ Parser.prototype._parseChunkEnd = function(data) {
611
+ let fileCrc = data.readInt32BE(0);
612
+ let calcCrc = this._crc.crc32();
613
+ if (this._options.checkCRC && calcCrc !== fileCrc) {
614
+ this.error(new Error("Crc error - " + fileCrc + " - " + calcCrc));
615
+ return;
616
+ }
617
+ if (!this._hasIEND) {
618
+ this.read(8, this._parseChunkBegin.bind(this));
619
+ }
620
+ };
621
+ Parser.prototype._handleIHDR = function(length) {
622
+ this.read(length, this._parseIHDR.bind(this));
623
+ };
624
+ Parser.prototype._parseIHDR = function(data) {
625
+ this._crc.write(data);
626
+ let width = data.readUInt32BE(0);
627
+ let height = data.readUInt32BE(4);
628
+ let depth = data[8];
629
+ let colorType = data[9];
630
+ let compr = data[10];
631
+ let filter = data[11];
632
+ let interlace = data[12];
633
+ if (depth !== 8 && depth !== 4 && depth !== 2 && depth !== 1 && depth !== 16) {
634
+ this.error(new Error("Unsupported bit depth " + depth));
635
+ return;
636
+ }
637
+ if (!(colorType in constants.COLORTYPE_TO_BPP_MAP)) {
638
+ this.error(new Error("Unsupported color type"));
639
+ return;
640
+ }
641
+ if (compr !== 0) {
642
+ this.error(new Error("Unsupported compression method"));
643
+ return;
644
+ }
645
+ if (filter !== 0) {
646
+ this.error(new Error("Unsupported filter method"));
647
+ return;
648
+ }
649
+ if (interlace !== 0 && interlace !== 1) {
650
+ this.error(new Error("Unsupported interlace method"));
651
+ return;
652
+ }
653
+ this._colorType = colorType;
654
+ let bpp = constants.COLORTYPE_TO_BPP_MAP[this._colorType];
655
+ this._hasIHDR = true;
656
+ this.metadata({
657
+ width,
658
+ height,
659
+ depth,
660
+ interlace: Boolean(interlace),
661
+ palette: Boolean(colorType & constants.COLORTYPE_PALETTE),
662
+ color: Boolean(colorType & constants.COLORTYPE_COLOR),
663
+ alpha: Boolean(colorType & constants.COLORTYPE_ALPHA),
664
+ bpp,
665
+ colorType
666
+ });
667
+ this._handleChunkEnd();
668
+ };
669
+ Parser.prototype._handlePLTE = function(length) {
670
+ this.read(length, this._parsePLTE.bind(this));
671
+ };
672
+ Parser.prototype._parsePLTE = function(data) {
673
+ this._crc.write(data);
674
+ let entries = Math.floor(data.length / 3);
675
+ for (let i = 0; i < entries; i++) {
676
+ this._palette.push([data[i * 3], data[i * 3 + 1], data[i * 3 + 2], 255]);
677
+ }
678
+ this.palette(this._palette);
679
+ this._handleChunkEnd();
680
+ };
681
+ Parser.prototype._handleTRNS = function(length) {
682
+ this.simpleTransparency();
683
+ this.read(length, this._parseTRNS.bind(this));
684
+ };
685
+ Parser.prototype._parseTRNS = function(data) {
686
+ this._crc.write(data);
687
+ if (this._colorType === constants.COLORTYPE_PALETTE_COLOR) {
688
+ if (this._palette.length === 0) {
689
+ this.error(new Error("Transparency chunk must be after palette"));
690
+ return;
691
+ }
692
+ if (data.length > this._palette.length) {
693
+ this.error(new Error("More transparent colors than palette size"));
694
+ return;
695
+ }
696
+ for (let i = 0; i < data.length; i++) {
697
+ this._palette[i][3] = data[i];
698
+ }
699
+ this.palette(this._palette);
700
+ }
701
+ if (this._colorType === constants.COLORTYPE_GRAYSCALE) {
702
+ this.transColor([data.readUInt16BE(0)]);
703
+ }
704
+ if (this._colorType === constants.COLORTYPE_COLOR) {
705
+ this.transColor([
706
+ data.readUInt16BE(0),
707
+ data.readUInt16BE(2),
708
+ data.readUInt16BE(4)
709
+ ]);
710
+ }
711
+ this._handleChunkEnd();
712
+ };
713
+ Parser.prototype._handleGAMA = function(length) {
714
+ this.read(length, this._parseGAMA.bind(this));
715
+ };
716
+ Parser.prototype._parseGAMA = function(data) {
717
+ this._crc.write(data);
718
+ this.gamma(data.readUInt32BE(0) / constants.GAMMA_DIVISION);
719
+ this._handleChunkEnd();
720
+ };
721
+ Parser.prototype._handleIDAT = function(length) {
722
+ if (!this._emittedHeadersFinished) {
723
+ this._emittedHeadersFinished = true;
724
+ this.headersFinished();
725
+ }
726
+ this.read(-length, this._parseIDAT.bind(this, length));
727
+ };
728
+ Parser.prototype._parseIDAT = function(length, data) {
729
+ this._crc.write(data);
730
+ if (this._colorType === constants.COLORTYPE_PALETTE_COLOR && this._palette.length === 0) {
731
+ throw new Error("Expected palette not found");
732
+ }
733
+ this.inflateData(data);
734
+ let leftOverLength = length - data.length;
735
+ if (leftOverLength > 0) {
736
+ this._handleIDAT(leftOverLength);
737
+ } else {
738
+ this._handleChunkEnd();
739
+ }
740
+ };
741
+ Parser.prototype._handleIEND = function(length) {
742
+ this.read(length, this._parseIEND.bind(this));
743
+ };
744
+ Parser.prototype._parseIEND = function(data) {
745
+ this._crc.write(data);
746
+ this._hasIEND = true;
747
+ this._handleChunkEnd();
748
+ if (this.finished) {
749
+ this.finished();
750
+ }
751
+ };
752
+ }
753
+ });
754
+
755
+ // ../../node_modules/pngjs/lib/bitmapper.js
756
+ var require_bitmapper = __commonJS({
757
+ "../../node_modules/pngjs/lib/bitmapper.js"(exports2) {
758
+ "use strict";
759
+ init_cjs_shims();
760
+ var interlaceUtils = require_interlace();
761
+ var pixelBppMapper = [
762
+ // 0 - dummy entry
763
+ function() {
764
+ },
765
+ // 1 - L
766
+ // 0: 0, 1: 0, 2: 0, 3: 0xff
767
+ function(pxData, data, pxPos, rawPos) {
768
+ if (rawPos === data.length) {
769
+ throw new Error("Ran out of data");
770
+ }
771
+ let pixel = data[rawPos];
772
+ pxData[pxPos] = pixel;
773
+ pxData[pxPos + 1] = pixel;
774
+ pxData[pxPos + 2] = pixel;
775
+ pxData[pxPos + 3] = 255;
776
+ },
777
+ // 2 - LA
778
+ // 0: 0, 1: 0, 2: 0, 3: 1
779
+ function(pxData, data, pxPos, rawPos) {
780
+ if (rawPos + 1 >= data.length) {
781
+ throw new Error("Ran out of data");
782
+ }
783
+ let pixel = data[rawPos];
784
+ pxData[pxPos] = pixel;
785
+ pxData[pxPos + 1] = pixel;
786
+ pxData[pxPos + 2] = pixel;
787
+ pxData[pxPos + 3] = data[rawPos + 1];
788
+ },
789
+ // 3 - RGB
790
+ // 0: 0, 1: 1, 2: 2, 3: 0xff
791
+ function(pxData, data, pxPos, rawPos) {
792
+ if (rawPos + 2 >= data.length) {
793
+ throw new Error("Ran out of data");
794
+ }
795
+ pxData[pxPos] = data[rawPos];
796
+ pxData[pxPos + 1] = data[rawPos + 1];
797
+ pxData[pxPos + 2] = data[rawPos + 2];
798
+ pxData[pxPos + 3] = 255;
799
+ },
800
+ // 4 - RGBA
801
+ // 0: 0, 1: 1, 2: 2, 3: 3
802
+ function(pxData, data, pxPos, rawPos) {
803
+ if (rawPos + 3 >= data.length) {
804
+ throw new Error("Ran out of data");
805
+ }
806
+ pxData[pxPos] = data[rawPos];
807
+ pxData[pxPos + 1] = data[rawPos + 1];
808
+ pxData[pxPos + 2] = data[rawPos + 2];
809
+ pxData[pxPos + 3] = data[rawPos + 3];
810
+ }
811
+ ];
812
+ var pixelBppCustomMapper = [
813
+ // 0 - dummy entry
814
+ function() {
815
+ },
816
+ // 1 - L
817
+ // 0: 0, 1: 0, 2: 0, 3: 0xff
818
+ function(pxData, pixelData, pxPos, maxBit) {
819
+ let pixel = pixelData[0];
820
+ pxData[pxPos] = pixel;
821
+ pxData[pxPos + 1] = pixel;
822
+ pxData[pxPos + 2] = pixel;
823
+ pxData[pxPos + 3] = maxBit;
824
+ },
825
+ // 2 - LA
826
+ // 0: 0, 1: 0, 2: 0, 3: 1
827
+ function(pxData, pixelData, pxPos) {
828
+ let pixel = pixelData[0];
829
+ pxData[pxPos] = pixel;
830
+ pxData[pxPos + 1] = pixel;
831
+ pxData[pxPos + 2] = pixel;
832
+ pxData[pxPos + 3] = pixelData[1];
833
+ },
834
+ // 3 - RGB
835
+ // 0: 0, 1: 1, 2: 2, 3: 0xff
836
+ function(pxData, pixelData, pxPos, maxBit) {
837
+ pxData[pxPos] = pixelData[0];
838
+ pxData[pxPos + 1] = pixelData[1];
839
+ pxData[pxPos + 2] = pixelData[2];
840
+ pxData[pxPos + 3] = maxBit;
841
+ },
842
+ // 4 - RGBA
843
+ // 0: 0, 1: 1, 2: 2, 3: 3
844
+ function(pxData, pixelData, pxPos) {
845
+ pxData[pxPos] = pixelData[0];
846
+ pxData[pxPos + 1] = pixelData[1];
847
+ pxData[pxPos + 2] = pixelData[2];
848
+ pxData[pxPos + 3] = pixelData[3];
849
+ }
850
+ ];
851
+ function bitRetriever(data, depth) {
852
+ let leftOver = [];
853
+ let i = 0;
854
+ function split() {
855
+ if (i === data.length) {
856
+ throw new Error("Ran out of data");
857
+ }
858
+ let byte = data[i];
859
+ i++;
860
+ let byte8, byte7, byte6, byte5, byte4, byte3, byte2, byte1;
861
+ switch (depth) {
862
+ default:
863
+ throw new Error("unrecognised depth");
864
+ case 16:
865
+ byte2 = data[i];
866
+ i++;
867
+ leftOver.push((byte << 8) + byte2);
868
+ break;
869
+ case 4:
870
+ byte2 = byte & 15;
871
+ byte1 = byte >> 4;
872
+ leftOver.push(byte1, byte2);
873
+ break;
874
+ case 2:
875
+ byte4 = byte & 3;
876
+ byte3 = byte >> 2 & 3;
877
+ byte2 = byte >> 4 & 3;
878
+ byte1 = byte >> 6 & 3;
879
+ leftOver.push(byte1, byte2, byte3, byte4);
880
+ break;
881
+ case 1:
882
+ byte8 = byte & 1;
883
+ byte7 = byte >> 1 & 1;
884
+ byte6 = byte >> 2 & 1;
885
+ byte5 = byte >> 3 & 1;
886
+ byte4 = byte >> 4 & 1;
887
+ byte3 = byte >> 5 & 1;
888
+ byte2 = byte >> 6 & 1;
889
+ byte1 = byte >> 7 & 1;
890
+ leftOver.push(byte1, byte2, byte3, byte4, byte5, byte6, byte7, byte8);
891
+ break;
892
+ }
893
+ }
894
+ return {
895
+ get: function(count) {
896
+ while (leftOver.length < count) {
897
+ split();
898
+ }
899
+ let returner = leftOver.slice(0, count);
900
+ leftOver = leftOver.slice(count);
901
+ return returner;
902
+ },
903
+ resetAfterLine: function() {
904
+ leftOver.length = 0;
905
+ },
906
+ end: function() {
907
+ if (i !== data.length) {
908
+ throw new Error("extra data found");
909
+ }
910
+ }
911
+ };
912
+ }
913
+ function mapImage8Bit(image, pxData, getPxPos, bpp, data, rawPos) {
914
+ let imageWidth = image.width;
915
+ let imageHeight = image.height;
916
+ let imagePass = image.index;
917
+ for (let y = 0; y < imageHeight; y++) {
918
+ for (let x = 0; x < imageWidth; x++) {
919
+ let pxPos = getPxPos(x, y, imagePass);
920
+ pixelBppMapper[bpp](pxData, data, pxPos, rawPos);
921
+ rawPos += bpp;
922
+ }
923
+ }
924
+ return rawPos;
925
+ }
926
+ function mapImageCustomBit(image, pxData, getPxPos, bpp, bits, maxBit) {
927
+ let imageWidth = image.width;
928
+ let imageHeight = image.height;
929
+ let imagePass = image.index;
930
+ for (let y = 0; y < imageHeight; y++) {
931
+ for (let x = 0; x < imageWidth; x++) {
932
+ let pixelData = bits.get(bpp);
933
+ let pxPos = getPxPos(x, y, imagePass);
934
+ pixelBppCustomMapper[bpp](pxData, pixelData, pxPos, maxBit);
935
+ }
936
+ bits.resetAfterLine();
937
+ }
938
+ }
939
+ exports2.dataToBitMap = function(data, bitmapInfo) {
940
+ let width = bitmapInfo.width;
941
+ let height = bitmapInfo.height;
942
+ let depth = bitmapInfo.depth;
943
+ let bpp = bitmapInfo.bpp;
944
+ let interlace = bitmapInfo.interlace;
945
+ let bits;
946
+ if (depth !== 8) {
947
+ bits = bitRetriever(data, depth);
948
+ }
949
+ let pxData;
950
+ if (depth <= 8) {
951
+ pxData = Buffer.alloc(width * height * 4);
952
+ } else {
953
+ pxData = new Uint16Array(width * height * 4);
954
+ }
955
+ let maxBit = Math.pow(2, depth) - 1;
956
+ let rawPos = 0;
957
+ let images;
958
+ let getPxPos;
959
+ if (interlace) {
960
+ images = interlaceUtils.getImagePasses(width, height);
961
+ getPxPos = interlaceUtils.getInterlaceIterator(width, height);
962
+ } else {
963
+ let nonInterlacedPxPos = 0;
964
+ getPxPos = function() {
965
+ let returner = nonInterlacedPxPos;
966
+ nonInterlacedPxPos += 4;
967
+ return returner;
968
+ };
969
+ images = [{ width, height }];
970
+ }
971
+ for (let imageIndex = 0; imageIndex < images.length; imageIndex++) {
972
+ if (depth === 8) {
973
+ rawPos = mapImage8Bit(
974
+ images[imageIndex],
975
+ pxData,
976
+ getPxPos,
977
+ bpp,
978
+ data,
979
+ rawPos
980
+ );
981
+ } else {
982
+ mapImageCustomBit(
983
+ images[imageIndex],
984
+ pxData,
985
+ getPxPos,
986
+ bpp,
987
+ bits,
988
+ maxBit
989
+ );
990
+ }
991
+ }
992
+ if (depth === 8) {
993
+ if (rawPos !== data.length) {
994
+ throw new Error("extra data found");
995
+ }
996
+ } else {
997
+ bits.end();
998
+ }
999
+ return pxData;
1000
+ };
1001
+ }
1002
+ });
1003
+
1004
+ // ../../node_modules/pngjs/lib/format-normaliser.js
1005
+ var require_format_normaliser = __commonJS({
1006
+ "../../node_modules/pngjs/lib/format-normaliser.js"(exports2, module2) {
1007
+ "use strict";
1008
+ init_cjs_shims();
1009
+ function dePalette(indata, outdata, width, height, palette) {
1010
+ let pxPos = 0;
1011
+ for (let y = 0; y < height; y++) {
1012
+ for (let x = 0; x < width; x++) {
1013
+ let color = palette[indata[pxPos]];
1014
+ if (!color) {
1015
+ throw new Error("index " + indata[pxPos] + " not in palette");
1016
+ }
1017
+ for (let i = 0; i < 4; i++) {
1018
+ outdata[pxPos + i] = color[i];
1019
+ }
1020
+ pxPos += 4;
1021
+ }
1022
+ }
1023
+ }
1024
+ function replaceTransparentColor(indata, outdata, width, height, transColor) {
1025
+ let pxPos = 0;
1026
+ for (let y = 0; y < height; y++) {
1027
+ for (let x = 0; x < width; x++) {
1028
+ let makeTrans = false;
1029
+ if (transColor.length === 1) {
1030
+ if (transColor[0] === indata[pxPos]) {
1031
+ makeTrans = true;
1032
+ }
1033
+ } else if (transColor[0] === indata[pxPos] && transColor[1] === indata[pxPos + 1] && transColor[2] === indata[pxPos + 2]) {
1034
+ makeTrans = true;
1035
+ }
1036
+ if (makeTrans) {
1037
+ for (let i = 0; i < 4; i++) {
1038
+ outdata[pxPos + i] = 0;
1039
+ }
1040
+ }
1041
+ pxPos += 4;
1042
+ }
1043
+ }
1044
+ }
1045
+ function scaleDepth(indata, outdata, width, height, depth) {
1046
+ let maxOutSample = 255;
1047
+ let maxInSample = Math.pow(2, depth) - 1;
1048
+ let pxPos = 0;
1049
+ for (let y = 0; y < height; y++) {
1050
+ for (let x = 0; x < width; x++) {
1051
+ for (let i = 0; i < 4; i++) {
1052
+ outdata[pxPos + i] = Math.floor(
1053
+ indata[pxPos + i] * maxOutSample / maxInSample + 0.5
1054
+ );
1055
+ }
1056
+ pxPos += 4;
1057
+ }
1058
+ }
1059
+ }
1060
+ module2.exports = function(indata, imageData, skipRescale = false) {
1061
+ let depth = imageData.depth;
1062
+ let width = imageData.width;
1063
+ let height = imageData.height;
1064
+ let colorType = imageData.colorType;
1065
+ let transColor = imageData.transColor;
1066
+ let palette = imageData.palette;
1067
+ let outdata = indata;
1068
+ if (colorType === 3) {
1069
+ dePalette(indata, outdata, width, height, palette);
1070
+ } else {
1071
+ if (transColor) {
1072
+ replaceTransparentColor(indata, outdata, width, height, transColor);
1073
+ }
1074
+ if (depth !== 8 && !skipRescale) {
1075
+ if (depth === 16) {
1076
+ outdata = Buffer.alloc(width * height * 4);
1077
+ }
1078
+ scaleDepth(indata, outdata, width, height, depth);
1079
+ }
1080
+ }
1081
+ return outdata;
1082
+ };
1083
+ }
1084
+ });
1085
+
1086
+ // ../../node_modules/pngjs/lib/parser-async.js
1087
+ var require_parser_async = __commonJS({
1088
+ "../../node_modules/pngjs/lib/parser-async.js"(exports2, module2) {
1089
+ "use strict";
1090
+ init_cjs_shims();
1091
+ var util = require("util");
1092
+ var zlib = require("zlib");
1093
+ var ChunkStream = require_chunkstream();
1094
+ var FilterAsync = require_filter_parse_async();
1095
+ var Parser = require_parser();
1096
+ var bitmapper = require_bitmapper();
1097
+ var formatNormaliser = require_format_normaliser();
1098
+ var ParserAsync = module2.exports = function(options) {
1099
+ ChunkStream.call(this);
1100
+ this._parser = new Parser(options, {
1101
+ read: this.read.bind(this),
1102
+ error: this._handleError.bind(this),
1103
+ metadata: this._handleMetaData.bind(this),
1104
+ gamma: this.emit.bind(this, "gamma"),
1105
+ palette: this._handlePalette.bind(this),
1106
+ transColor: this._handleTransColor.bind(this),
1107
+ finished: this._finished.bind(this),
1108
+ inflateData: this._inflateData.bind(this),
1109
+ simpleTransparency: this._simpleTransparency.bind(this),
1110
+ headersFinished: this._headersFinished.bind(this)
1111
+ });
1112
+ this._options = options;
1113
+ this.writable = true;
1114
+ this._parser.start();
1115
+ };
1116
+ util.inherits(ParserAsync, ChunkStream);
1117
+ ParserAsync.prototype._handleError = function(err) {
1118
+ this.emit("error", err);
1119
+ this.writable = false;
1120
+ this.destroy();
1121
+ if (this._inflate && this._inflate.destroy) {
1122
+ this._inflate.destroy();
1123
+ }
1124
+ if (this._filter) {
1125
+ this._filter.destroy();
1126
+ this._filter.on("error", function() {
1127
+ });
1128
+ }
1129
+ this.errord = true;
1130
+ };
1131
+ ParserAsync.prototype._inflateData = function(data) {
1132
+ if (!this._inflate) {
1133
+ if (this._bitmapInfo.interlace) {
1134
+ this._inflate = zlib.createInflate();
1135
+ this._inflate.on("error", this.emit.bind(this, "error"));
1136
+ this._filter.on("complete", this._complete.bind(this));
1137
+ this._inflate.pipe(this._filter);
1138
+ } else {
1139
+ let rowSize = (this._bitmapInfo.width * this._bitmapInfo.bpp * this._bitmapInfo.depth + 7 >> 3) + 1;
1140
+ let imageSize = rowSize * this._bitmapInfo.height;
1141
+ let chunkSize = Math.max(imageSize, zlib.Z_MIN_CHUNK);
1142
+ this._inflate = zlib.createInflate({ chunkSize });
1143
+ let leftToInflate = imageSize;
1144
+ let emitError = this.emit.bind(this, "error");
1145
+ this._inflate.on("error", function(err) {
1146
+ if (!leftToInflate) {
1147
+ return;
1148
+ }
1149
+ emitError(err);
1150
+ });
1151
+ this._filter.on("complete", this._complete.bind(this));
1152
+ let filterWrite = this._filter.write.bind(this._filter);
1153
+ this._inflate.on("data", function(chunk) {
1154
+ if (!leftToInflate) {
1155
+ return;
1156
+ }
1157
+ if (chunk.length > leftToInflate) {
1158
+ chunk = chunk.slice(0, leftToInflate);
1159
+ }
1160
+ leftToInflate -= chunk.length;
1161
+ filterWrite(chunk);
1162
+ });
1163
+ this._inflate.on("end", this._filter.end.bind(this._filter));
1164
+ }
1165
+ }
1166
+ this._inflate.write(data);
1167
+ };
1168
+ ParserAsync.prototype._handleMetaData = function(metaData) {
1169
+ this._metaData = metaData;
1170
+ this._bitmapInfo = Object.create(metaData);
1171
+ this._filter = new FilterAsync(this._bitmapInfo);
1172
+ };
1173
+ ParserAsync.prototype._handleTransColor = function(transColor) {
1174
+ this._bitmapInfo.transColor = transColor;
1175
+ };
1176
+ ParserAsync.prototype._handlePalette = function(palette) {
1177
+ this._bitmapInfo.palette = palette;
1178
+ };
1179
+ ParserAsync.prototype._simpleTransparency = function() {
1180
+ this._metaData.alpha = true;
1181
+ };
1182
+ ParserAsync.prototype._headersFinished = function() {
1183
+ this.emit("metadata", this._metaData);
1184
+ };
1185
+ ParserAsync.prototype._finished = function() {
1186
+ if (this.errord) {
1187
+ return;
1188
+ }
1189
+ if (!this._inflate) {
1190
+ this.emit("error", "No Inflate block");
1191
+ } else {
1192
+ this._inflate.end();
1193
+ }
1194
+ };
1195
+ ParserAsync.prototype._complete = function(filteredData) {
1196
+ if (this.errord) {
1197
+ return;
1198
+ }
1199
+ let normalisedBitmapData;
1200
+ try {
1201
+ let bitmapData = bitmapper.dataToBitMap(filteredData, this._bitmapInfo);
1202
+ normalisedBitmapData = formatNormaliser(
1203
+ bitmapData,
1204
+ this._bitmapInfo,
1205
+ this._options.skipRescale
1206
+ );
1207
+ bitmapData = null;
1208
+ } catch (ex) {
1209
+ this._handleError(ex);
1210
+ return;
1211
+ }
1212
+ this.emit("parsed", normalisedBitmapData);
1213
+ };
1214
+ }
1215
+ });
1216
+
1217
+ // ../../node_modules/pngjs/lib/bitpacker.js
1218
+ var require_bitpacker = __commonJS({
1219
+ "../../node_modules/pngjs/lib/bitpacker.js"(exports2, module2) {
1220
+ "use strict";
1221
+ init_cjs_shims();
1222
+ var constants = require_constants();
1223
+ module2.exports = function(dataIn, width, height, options) {
1224
+ let outHasAlpha = [constants.COLORTYPE_COLOR_ALPHA, constants.COLORTYPE_ALPHA].indexOf(
1225
+ options.colorType
1226
+ ) !== -1;
1227
+ if (options.colorType === options.inputColorType) {
1228
+ let bigEndian = (function() {
1229
+ let buffer = new ArrayBuffer(2);
1230
+ new DataView(buffer).setInt16(
1231
+ 0,
1232
+ 256,
1233
+ true
1234
+ /* littleEndian */
1235
+ );
1236
+ return new Int16Array(buffer)[0] !== 256;
1237
+ })();
1238
+ if (options.bitDepth === 8 || options.bitDepth === 16 && bigEndian) {
1239
+ return dataIn;
1240
+ }
1241
+ }
1242
+ let data = options.bitDepth !== 16 ? dataIn : new Uint16Array(dataIn.buffer);
1243
+ let maxValue = 255;
1244
+ let inBpp = constants.COLORTYPE_TO_BPP_MAP[options.inputColorType];
1245
+ if (inBpp === 4 && !options.inputHasAlpha) {
1246
+ inBpp = 3;
1247
+ }
1248
+ let outBpp = constants.COLORTYPE_TO_BPP_MAP[options.colorType];
1249
+ if (options.bitDepth === 16) {
1250
+ maxValue = 65535;
1251
+ outBpp *= 2;
1252
+ }
1253
+ let outData = Buffer.alloc(width * height * outBpp);
1254
+ let inIndex = 0;
1255
+ let outIndex = 0;
1256
+ let bgColor = options.bgColor || {};
1257
+ if (bgColor.red === void 0) {
1258
+ bgColor.red = maxValue;
1259
+ }
1260
+ if (bgColor.green === void 0) {
1261
+ bgColor.green = maxValue;
1262
+ }
1263
+ if (bgColor.blue === void 0) {
1264
+ bgColor.blue = maxValue;
1265
+ }
1266
+ function getRGBA() {
1267
+ let red;
1268
+ let green;
1269
+ let blue;
1270
+ let alpha = maxValue;
1271
+ switch (options.inputColorType) {
1272
+ case constants.COLORTYPE_COLOR_ALPHA:
1273
+ alpha = data[inIndex + 3];
1274
+ red = data[inIndex];
1275
+ green = data[inIndex + 1];
1276
+ blue = data[inIndex + 2];
1277
+ break;
1278
+ case constants.COLORTYPE_COLOR:
1279
+ red = data[inIndex];
1280
+ green = data[inIndex + 1];
1281
+ blue = data[inIndex + 2];
1282
+ break;
1283
+ case constants.COLORTYPE_ALPHA:
1284
+ alpha = data[inIndex + 1];
1285
+ red = data[inIndex];
1286
+ green = red;
1287
+ blue = red;
1288
+ break;
1289
+ case constants.COLORTYPE_GRAYSCALE:
1290
+ red = data[inIndex];
1291
+ green = red;
1292
+ blue = red;
1293
+ break;
1294
+ default:
1295
+ throw new Error(
1296
+ "input color type:" + options.inputColorType + " is not supported at present"
1297
+ );
1298
+ }
1299
+ if (options.inputHasAlpha) {
1300
+ if (!outHasAlpha) {
1301
+ alpha /= maxValue;
1302
+ red = Math.min(
1303
+ Math.max(Math.round((1 - alpha) * bgColor.red + alpha * red), 0),
1304
+ maxValue
1305
+ );
1306
+ green = Math.min(
1307
+ Math.max(Math.round((1 - alpha) * bgColor.green + alpha * green), 0),
1308
+ maxValue
1309
+ );
1310
+ blue = Math.min(
1311
+ Math.max(Math.round((1 - alpha) * bgColor.blue + alpha * blue), 0),
1312
+ maxValue
1313
+ );
1314
+ }
1315
+ }
1316
+ return { red, green, blue, alpha };
1317
+ }
1318
+ for (let y = 0; y < height; y++) {
1319
+ for (let x = 0; x < width; x++) {
1320
+ let rgba = getRGBA(data, inIndex);
1321
+ switch (options.colorType) {
1322
+ case constants.COLORTYPE_COLOR_ALPHA:
1323
+ case constants.COLORTYPE_COLOR:
1324
+ if (options.bitDepth === 8) {
1325
+ outData[outIndex] = rgba.red;
1326
+ outData[outIndex + 1] = rgba.green;
1327
+ outData[outIndex + 2] = rgba.blue;
1328
+ if (outHasAlpha) {
1329
+ outData[outIndex + 3] = rgba.alpha;
1330
+ }
1331
+ } else {
1332
+ outData.writeUInt16BE(rgba.red, outIndex);
1333
+ outData.writeUInt16BE(rgba.green, outIndex + 2);
1334
+ outData.writeUInt16BE(rgba.blue, outIndex + 4);
1335
+ if (outHasAlpha) {
1336
+ outData.writeUInt16BE(rgba.alpha, outIndex + 6);
1337
+ }
1338
+ }
1339
+ break;
1340
+ case constants.COLORTYPE_ALPHA:
1341
+ case constants.COLORTYPE_GRAYSCALE: {
1342
+ let grayscale = (rgba.red + rgba.green + rgba.blue) / 3;
1343
+ if (options.bitDepth === 8) {
1344
+ outData[outIndex] = grayscale;
1345
+ if (outHasAlpha) {
1346
+ outData[outIndex + 1] = rgba.alpha;
1347
+ }
1348
+ } else {
1349
+ outData.writeUInt16BE(grayscale, outIndex);
1350
+ if (outHasAlpha) {
1351
+ outData.writeUInt16BE(rgba.alpha, outIndex + 2);
1352
+ }
1353
+ }
1354
+ break;
1355
+ }
1356
+ default:
1357
+ throw new Error("unrecognised color Type " + options.colorType);
1358
+ }
1359
+ inIndex += inBpp;
1360
+ outIndex += outBpp;
1361
+ }
1362
+ }
1363
+ return outData;
1364
+ };
1365
+ }
1366
+ });
1367
+
1368
+ // ../../node_modules/pngjs/lib/filter-pack.js
1369
+ var require_filter_pack = __commonJS({
1370
+ "../../node_modules/pngjs/lib/filter-pack.js"(exports2, module2) {
1371
+ "use strict";
1372
+ init_cjs_shims();
1373
+ var paethPredictor = require_paeth_predictor();
1374
+ function filterNone(pxData, pxPos, byteWidth, rawData, rawPos) {
1375
+ for (let x = 0; x < byteWidth; x++) {
1376
+ rawData[rawPos + x] = pxData[pxPos + x];
1377
+ }
1378
+ }
1379
+ function filterSumNone(pxData, pxPos, byteWidth) {
1380
+ let sum = 0;
1381
+ let length = pxPos + byteWidth;
1382
+ for (let i = pxPos; i < length; i++) {
1383
+ sum += Math.abs(pxData[i]);
1384
+ }
1385
+ return sum;
1386
+ }
1387
+ function filterSub(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
1388
+ for (let x = 0; x < byteWidth; x++) {
1389
+ let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1390
+ let val = pxData[pxPos + x] - left;
1391
+ rawData[rawPos + x] = val;
1392
+ }
1393
+ }
1394
+ function filterSumSub(pxData, pxPos, byteWidth, bpp) {
1395
+ let sum = 0;
1396
+ for (let x = 0; x < byteWidth; x++) {
1397
+ let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1398
+ let val = pxData[pxPos + x] - left;
1399
+ sum += Math.abs(val);
1400
+ }
1401
+ return sum;
1402
+ }
1403
+ function filterUp(pxData, pxPos, byteWidth, rawData, rawPos) {
1404
+ for (let x = 0; x < byteWidth; x++) {
1405
+ let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
1406
+ let val = pxData[pxPos + x] - up;
1407
+ rawData[rawPos + x] = val;
1408
+ }
1409
+ }
1410
+ function filterSumUp(pxData, pxPos, byteWidth) {
1411
+ let sum = 0;
1412
+ let length = pxPos + byteWidth;
1413
+ for (let x = pxPos; x < length; x++) {
1414
+ let up = pxPos > 0 ? pxData[x - byteWidth] : 0;
1415
+ let val = pxData[x] - up;
1416
+ sum += Math.abs(val);
1417
+ }
1418
+ return sum;
1419
+ }
1420
+ function filterAvg(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
1421
+ for (let x = 0; x < byteWidth; x++) {
1422
+ let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1423
+ let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
1424
+ let val = pxData[pxPos + x] - (left + up >> 1);
1425
+ rawData[rawPos + x] = val;
1426
+ }
1427
+ }
1428
+ function filterSumAvg(pxData, pxPos, byteWidth, bpp) {
1429
+ let sum = 0;
1430
+ for (let x = 0; x < byteWidth; x++) {
1431
+ let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1432
+ let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
1433
+ let val = pxData[pxPos + x] - (left + up >> 1);
1434
+ sum += Math.abs(val);
1435
+ }
1436
+ return sum;
1437
+ }
1438
+ function filterPaeth(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
1439
+ for (let x = 0; x < byteWidth; x++) {
1440
+ let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1441
+ let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
1442
+ let upleft = pxPos > 0 && x >= bpp ? pxData[pxPos + x - (byteWidth + bpp)] : 0;
1443
+ let val = pxData[pxPos + x] - paethPredictor(left, up, upleft);
1444
+ rawData[rawPos + x] = val;
1445
+ }
1446
+ }
1447
+ function filterSumPaeth(pxData, pxPos, byteWidth, bpp) {
1448
+ let sum = 0;
1449
+ for (let x = 0; x < byteWidth; x++) {
1450
+ let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1451
+ let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
1452
+ let upleft = pxPos > 0 && x >= bpp ? pxData[pxPos + x - (byteWidth + bpp)] : 0;
1453
+ let val = pxData[pxPos + x] - paethPredictor(left, up, upleft);
1454
+ sum += Math.abs(val);
1455
+ }
1456
+ return sum;
1457
+ }
1458
+ var filters = {
1459
+ 0: filterNone,
1460
+ 1: filterSub,
1461
+ 2: filterUp,
1462
+ 3: filterAvg,
1463
+ 4: filterPaeth
1464
+ };
1465
+ var filterSums = {
1466
+ 0: filterSumNone,
1467
+ 1: filterSumSub,
1468
+ 2: filterSumUp,
1469
+ 3: filterSumAvg,
1470
+ 4: filterSumPaeth
1471
+ };
1472
+ module2.exports = function(pxData, width, height, options, bpp) {
1473
+ let filterTypes;
1474
+ if (!("filterType" in options) || options.filterType === -1) {
1475
+ filterTypes = [0, 1, 2, 3, 4];
1476
+ } else if (typeof options.filterType === "number") {
1477
+ filterTypes = [options.filterType];
1478
+ } else {
1479
+ throw new Error("unrecognised filter types");
1480
+ }
1481
+ if (options.bitDepth === 16) {
1482
+ bpp *= 2;
1483
+ }
1484
+ let byteWidth = width * bpp;
1485
+ let rawPos = 0;
1486
+ let pxPos = 0;
1487
+ let rawData = Buffer.alloc((byteWidth + 1) * height);
1488
+ let sel = filterTypes[0];
1489
+ for (let y = 0; y < height; y++) {
1490
+ if (filterTypes.length > 1) {
1491
+ let min = Infinity;
1492
+ for (let i = 0; i < filterTypes.length; i++) {
1493
+ let sum = filterSums[filterTypes[i]](pxData, pxPos, byteWidth, bpp);
1494
+ if (sum < min) {
1495
+ sel = filterTypes[i];
1496
+ min = sum;
1497
+ }
1498
+ }
1499
+ }
1500
+ rawData[rawPos] = sel;
1501
+ rawPos++;
1502
+ filters[sel](pxData, pxPos, byteWidth, rawData, rawPos, bpp);
1503
+ rawPos += byteWidth;
1504
+ pxPos += byteWidth;
1505
+ }
1506
+ return rawData;
1507
+ };
1508
+ }
1509
+ });
1510
+
1511
+ // ../../node_modules/pngjs/lib/packer.js
1512
+ var require_packer = __commonJS({
1513
+ "../../node_modules/pngjs/lib/packer.js"(exports2, module2) {
1514
+ "use strict";
1515
+ init_cjs_shims();
1516
+ var constants = require_constants();
1517
+ var CrcStream = require_crc();
1518
+ var bitPacker = require_bitpacker();
1519
+ var filter = require_filter_pack();
1520
+ var zlib = require("zlib");
1521
+ var Packer = module2.exports = function(options) {
1522
+ this._options = options;
1523
+ options.deflateChunkSize = options.deflateChunkSize || 32 * 1024;
1524
+ options.deflateLevel = options.deflateLevel != null ? options.deflateLevel : 9;
1525
+ options.deflateStrategy = options.deflateStrategy != null ? options.deflateStrategy : 3;
1526
+ options.inputHasAlpha = options.inputHasAlpha != null ? options.inputHasAlpha : true;
1527
+ options.deflateFactory = options.deflateFactory || zlib.createDeflate;
1528
+ options.bitDepth = options.bitDepth || 8;
1529
+ options.colorType = typeof options.colorType === "number" ? options.colorType : constants.COLORTYPE_COLOR_ALPHA;
1530
+ options.inputColorType = typeof options.inputColorType === "number" ? options.inputColorType : constants.COLORTYPE_COLOR_ALPHA;
1531
+ if ([
1532
+ constants.COLORTYPE_GRAYSCALE,
1533
+ constants.COLORTYPE_COLOR,
1534
+ constants.COLORTYPE_COLOR_ALPHA,
1535
+ constants.COLORTYPE_ALPHA
1536
+ ].indexOf(options.colorType) === -1) {
1537
+ throw new Error(
1538
+ "option color type:" + options.colorType + " is not supported at present"
1539
+ );
1540
+ }
1541
+ if ([
1542
+ constants.COLORTYPE_GRAYSCALE,
1543
+ constants.COLORTYPE_COLOR,
1544
+ constants.COLORTYPE_COLOR_ALPHA,
1545
+ constants.COLORTYPE_ALPHA
1546
+ ].indexOf(options.inputColorType) === -1) {
1547
+ throw new Error(
1548
+ "option input color type:" + options.inputColorType + " is not supported at present"
1549
+ );
1550
+ }
1551
+ if (options.bitDepth !== 8 && options.bitDepth !== 16) {
1552
+ throw new Error(
1553
+ "option bit depth:" + options.bitDepth + " is not supported at present"
1554
+ );
1555
+ }
1556
+ };
1557
+ Packer.prototype.getDeflateOptions = function() {
1558
+ return {
1559
+ chunkSize: this._options.deflateChunkSize,
1560
+ level: this._options.deflateLevel,
1561
+ strategy: this._options.deflateStrategy
1562
+ };
1563
+ };
1564
+ Packer.prototype.createDeflate = function() {
1565
+ return this._options.deflateFactory(this.getDeflateOptions());
1566
+ };
1567
+ Packer.prototype.filterData = function(data, width, height) {
1568
+ let packedData = bitPacker(data, width, height, this._options);
1569
+ let bpp = constants.COLORTYPE_TO_BPP_MAP[this._options.colorType];
1570
+ let filteredData = filter(packedData, width, height, this._options, bpp);
1571
+ return filteredData;
1572
+ };
1573
+ Packer.prototype._packChunk = function(type, data) {
1574
+ let len = data ? data.length : 0;
1575
+ let buf = Buffer.alloc(len + 12);
1576
+ buf.writeUInt32BE(len, 0);
1577
+ buf.writeUInt32BE(type, 4);
1578
+ if (data) {
1579
+ data.copy(buf, 8);
1580
+ }
1581
+ buf.writeInt32BE(
1582
+ CrcStream.crc32(buf.slice(4, buf.length - 4)),
1583
+ buf.length - 4
1584
+ );
1585
+ return buf;
1586
+ };
1587
+ Packer.prototype.packGAMA = function(gamma) {
1588
+ let buf = Buffer.alloc(4);
1589
+ buf.writeUInt32BE(Math.floor(gamma * constants.GAMMA_DIVISION), 0);
1590
+ return this._packChunk(constants.TYPE_gAMA, buf);
1591
+ };
1592
+ Packer.prototype.packIHDR = function(width, height) {
1593
+ let buf = Buffer.alloc(13);
1594
+ buf.writeUInt32BE(width, 0);
1595
+ buf.writeUInt32BE(height, 4);
1596
+ buf[8] = this._options.bitDepth;
1597
+ buf[9] = this._options.colorType;
1598
+ buf[10] = 0;
1599
+ buf[11] = 0;
1600
+ buf[12] = 0;
1601
+ return this._packChunk(constants.TYPE_IHDR, buf);
1602
+ };
1603
+ Packer.prototype.packIDAT = function(data) {
1604
+ return this._packChunk(constants.TYPE_IDAT, data);
1605
+ };
1606
+ Packer.prototype.packIEND = function() {
1607
+ return this._packChunk(constants.TYPE_IEND, null);
1608
+ };
1609
+ }
1610
+ });
1611
+
1612
+ // ../../node_modules/pngjs/lib/packer-async.js
1613
+ var require_packer_async = __commonJS({
1614
+ "../../node_modules/pngjs/lib/packer-async.js"(exports2, module2) {
1615
+ "use strict";
1616
+ init_cjs_shims();
1617
+ var util = require("util");
1618
+ var Stream = require("stream");
1619
+ var constants = require_constants();
1620
+ var Packer = require_packer();
1621
+ var PackerAsync = module2.exports = function(opt) {
1622
+ Stream.call(this);
1623
+ let options = opt || {};
1624
+ this._packer = new Packer(options);
1625
+ this._deflate = this._packer.createDeflate();
1626
+ this.readable = true;
1627
+ };
1628
+ util.inherits(PackerAsync, Stream);
1629
+ PackerAsync.prototype.pack = function(data, width, height, gamma) {
1630
+ this.emit("data", Buffer.from(constants.PNG_SIGNATURE));
1631
+ this.emit("data", this._packer.packIHDR(width, height));
1632
+ if (gamma) {
1633
+ this.emit("data", this._packer.packGAMA(gamma));
1634
+ }
1635
+ let filteredData = this._packer.filterData(data, width, height);
1636
+ this._deflate.on("error", this.emit.bind(this, "error"));
1637
+ this._deflate.on(
1638
+ "data",
1639
+ function(compressedData) {
1640
+ this.emit("data", this._packer.packIDAT(compressedData));
1641
+ }.bind(this)
1642
+ );
1643
+ this._deflate.on(
1644
+ "end",
1645
+ function() {
1646
+ this.emit("data", this._packer.packIEND());
1647
+ this.emit("end");
1648
+ }.bind(this)
1649
+ );
1650
+ this._deflate.end(filteredData);
1651
+ };
1652
+ }
1653
+ });
1654
+
1655
+ // ../../node_modules/pngjs/lib/sync-inflate.js
1656
+ var require_sync_inflate = __commonJS({
1657
+ "../../node_modules/pngjs/lib/sync-inflate.js"(exports2, module2) {
1658
+ "use strict";
1659
+ init_cjs_shims();
1660
+ var assert = require("assert").ok;
1661
+ var zlib = require("zlib");
1662
+ var util = require("util");
1663
+ var kMaxLength = require("buffer").kMaxLength;
1664
+ function Inflate(opts) {
1665
+ if (!(this instanceof Inflate)) {
1666
+ return new Inflate(opts);
1667
+ }
1668
+ if (opts && opts.chunkSize < zlib.Z_MIN_CHUNK) {
1669
+ opts.chunkSize = zlib.Z_MIN_CHUNK;
1670
+ }
1671
+ zlib.Inflate.call(this, opts);
1672
+ this._offset = this._offset === void 0 ? this._outOffset : this._offset;
1673
+ this._buffer = this._buffer || this._outBuffer;
1674
+ if (opts && opts.maxLength != null) {
1675
+ this._maxLength = opts.maxLength;
1676
+ }
1677
+ }
1678
+ function createInflate(opts) {
1679
+ return new Inflate(opts);
1680
+ }
1681
+ function _close(engine, callback) {
1682
+ if (callback) {
1683
+ process.nextTick(callback);
1684
+ }
1685
+ if (!engine._handle) {
1686
+ return;
1687
+ }
1688
+ engine._handle.close();
1689
+ engine._handle = null;
1690
+ }
1691
+ Inflate.prototype._processChunk = function(chunk, flushFlag, asyncCb) {
1692
+ if (typeof asyncCb === "function") {
1693
+ return zlib.Inflate._processChunk.call(this, chunk, flushFlag, asyncCb);
1694
+ }
1695
+ let self = this;
1696
+ let availInBefore = chunk && chunk.length;
1697
+ let availOutBefore = this._chunkSize - this._offset;
1698
+ let leftToInflate = this._maxLength;
1699
+ let inOff = 0;
1700
+ let buffers = [];
1701
+ let nread = 0;
1702
+ let error;
1703
+ this.on("error", function(err) {
1704
+ error = err;
1705
+ });
1706
+ function handleChunk(availInAfter, availOutAfter) {
1707
+ if (self._hadError) {
1708
+ return;
1709
+ }
1710
+ let have = availOutBefore - availOutAfter;
1711
+ assert(have >= 0, "have should not go down");
1712
+ if (have > 0) {
1713
+ let out = self._buffer.slice(self._offset, self._offset + have);
1714
+ self._offset += have;
1715
+ if (out.length > leftToInflate) {
1716
+ out = out.slice(0, leftToInflate);
1717
+ }
1718
+ buffers.push(out);
1719
+ nread += out.length;
1720
+ leftToInflate -= out.length;
1721
+ if (leftToInflate === 0) {
1722
+ return false;
1723
+ }
1724
+ }
1725
+ if (availOutAfter === 0 || self._offset >= self._chunkSize) {
1726
+ availOutBefore = self._chunkSize;
1727
+ self._offset = 0;
1728
+ self._buffer = Buffer.allocUnsafe(self._chunkSize);
1729
+ }
1730
+ if (availOutAfter === 0) {
1731
+ inOff += availInBefore - availInAfter;
1732
+ availInBefore = availInAfter;
1733
+ return true;
1734
+ }
1735
+ return false;
1736
+ }
1737
+ assert(this._handle, "zlib binding closed");
1738
+ let res;
1739
+ do {
1740
+ res = this._handle.writeSync(
1741
+ flushFlag,
1742
+ chunk,
1743
+ // in
1744
+ inOff,
1745
+ // in_off
1746
+ availInBefore,
1747
+ // in_len
1748
+ this._buffer,
1749
+ // out
1750
+ this._offset,
1751
+ //out_off
1752
+ availOutBefore
1753
+ );
1754
+ res = res || this._writeState;
1755
+ } while (!this._hadError && handleChunk(res[0], res[1]));
1756
+ if (this._hadError) {
1757
+ throw error;
1758
+ }
1759
+ if (nread >= kMaxLength) {
1760
+ _close(this);
1761
+ throw new RangeError(
1762
+ "Cannot create final Buffer. It would be larger than 0x" + kMaxLength.toString(16) + " bytes"
1763
+ );
1764
+ }
1765
+ let buf = Buffer.concat(buffers, nread);
1766
+ _close(this);
1767
+ return buf;
1768
+ };
1769
+ util.inherits(Inflate, zlib.Inflate);
1770
+ function zlibBufferSync(engine, buffer) {
1771
+ if (typeof buffer === "string") {
1772
+ buffer = Buffer.from(buffer);
1773
+ }
1774
+ if (!(buffer instanceof Buffer)) {
1775
+ throw new TypeError("Not a string or buffer");
1776
+ }
1777
+ let flushFlag = engine._finishFlushFlag;
1778
+ if (flushFlag == null) {
1779
+ flushFlag = zlib.Z_FINISH;
1780
+ }
1781
+ return engine._processChunk(buffer, flushFlag);
1782
+ }
1783
+ function inflateSync(buffer, opts) {
1784
+ return zlibBufferSync(new Inflate(opts), buffer);
1785
+ }
1786
+ module2.exports = exports2 = inflateSync;
1787
+ exports2.Inflate = Inflate;
1788
+ exports2.createInflate = createInflate;
1789
+ exports2.inflateSync = inflateSync;
1790
+ }
1791
+ });
1792
+
1793
+ // ../../node_modules/pngjs/lib/sync-reader.js
1794
+ var require_sync_reader = __commonJS({
1795
+ "../../node_modules/pngjs/lib/sync-reader.js"(exports2, module2) {
1796
+ "use strict";
1797
+ init_cjs_shims();
1798
+ var SyncReader = module2.exports = function(buffer) {
1799
+ this._buffer = buffer;
1800
+ this._reads = [];
1801
+ };
1802
+ SyncReader.prototype.read = function(length, callback) {
1803
+ this._reads.push({
1804
+ length: Math.abs(length),
1805
+ // if length < 0 then at most this length
1806
+ allowLess: length < 0,
1807
+ func: callback
1808
+ });
1809
+ };
1810
+ SyncReader.prototype.process = function() {
1811
+ while (this._reads.length > 0 && this._buffer.length) {
1812
+ let read = this._reads[0];
1813
+ if (this._buffer.length && (this._buffer.length >= read.length || read.allowLess)) {
1814
+ this._reads.shift();
1815
+ let buf = this._buffer;
1816
+ this._buffer = buf.slice(read.length);
1817
+ read.func.call(this, buf.slice(0, read.length));
1818
+ } else {
1819
+ break;
1820
+ }
1821
+ }
1822
+ if (this._reads.length > 0) {
1823
+ throw new Error("There are some read requests waitng on finished stream");
1824
+ }
1825
+ if (this._buffer.length > 0) {
1826
+ throw new Error("unrecognised content at end of stream");
1827
+ }
1828
+ };
1829
+ }
1830
+ });
1831
+
1832
+ // ../../node_modules/pngjs/lib/filter-parse-sync.js
1833
+ var require_filter_parse_sync = __commonJS({
1834
+ "../../node_modules/pngjs/lib/filter-parse-sync.js"(exports2) {
1835
+ "use strict";
1836
+ init_cjs_shims();
1837
+ var SyncReader = require_sync_reader();
1838
+ var Filter = require_filter_parse();
1839
+ exports2.process = function(inBuffer, bitmapInfo) {
1840
+ let outBuffers = [];
1841
+ let reader = new SyncReader(inBuffer);
1842
+ let filter = new Filter(bitmapInfo, {
1843
+ read: reader.read.bind(reader),
1844
+ write: function(bufferPart) {
1845
+ outBuffers.push(bufferPart);
1846
+ },
1847
+ complete: function() {
1848
+ }
1849
+ });
1850
+ filter.start();
1851
+ reader.process();
1852
+ return Buffer.concat(outBuffers);
1853
+ };
1854
+ }
1855
+ });
1856
+
1857
+ // ../../node_modules/pngjs/lib/parser-sync.js
1858
+ var require_parser_sync = __commonJS({
1859
+ "../../node_modules/pngjs/lib/parser-sync.js"(exports2, module2) {
1860
+ "use strict";
1861
+ init_cjs_shims();
1862
+ var hasSyncZlib = true;
1863
+ var zlib = require("zlib");
1864
+ var inflateSync = require_sync_inflate();
1865
+ if (!zlib.deflateSync) {
1866
+ hasSyncZlib = false;
1867
+ }
1868
+ var SyncReader = require_sync_reader();
1869
+ var FilterSync = require_filter_parse_sync();
1870
+ var Parser = require_parser();
1871
+ var bitmapper = require_bitmapper();
1872
+ var formatNormaliser = require_format_normaliser();
1873
+ module2.exports = function(buffer, options) {
1874
+ if (!hasSyncZlib) {
1875
+ throw new Error(
1876
+ "To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0"
1877
+ );
1878
+ }
1879
+ let err;
1880
+ function handleError(_err_) {
1881
+ err = _err_;
1882
+ }
1883
+ let metaData;
1884
+ function handleMetaData(_metaData_) {
1885
+ metaData = _metaData_;
1886
+ }
1887
+ function handleTransColor(transColor) {
1888
+ metaData.transColor = transColor;
1889
+ }
1890
+ function handlePalette(palette) {
1891
+ metaData.palette = palette;
1892
+ }
1893
+ function handleSimpleTransparency() {
1894
+ metaData.alpha = true;
1895
+ }
1896
+ let gamma;
1897
+ function handleGamma(_gamma_) {
1898
+ gamma = _gamma_;
1899
+ }
1900
+ let inflateDataList = [];
1901
+ function handleInflateData(inflatedData2) {
1902
+ inflateDataList.push(inflatedData2);
1903
+ }
1904
+ let reader = new SyncReader(buffer);
1905
+ let parser = new Parser(options, {
1906
+ read: reader.read.bind(reader),
1907
+ error: handleError,
1908
+ metadata: handleMetaData,
1909
+ gamma: handleGamma,
1910
+ palette: handlePalette,
1911
+ transColor: handleTransColor,
1912
+ inflateData: handleInflateData,
1913
+ simpleTransparency: handleSimpleTransparency
1914
+ });
1915
+ parser.start();
1916
+ reader.process();
1917
+ if (err) {
1918
+ throw err;
1919
+ }
1920
+ let inflateData = Buffer.concat(inflateDataList);
1921
+ inflateDataList.length = 0;
1922
+ let inflatedData;
1923
+ if (metaData.interlace) {
1924
+ inflatedData = zlib.inflateSync(inflateData);
1925
+ } else {
1926
+ let rowSize = (metaData.width * metaData.bpp * metaData.depth + 7 >> 3) + 1;
1927
+ let imageSize = rowSize * metaData.height;
1928
+ inflatedData = inflateSync(inflateData, {
1929
+ chunkSize: imageSize,
1930
+ maxLength: imageSize
1931
+ });
1932
+ }
1933
+ inflateData = null;
1934
+ if (!inflatedData || !inflatedData.length) {
1935
+ throw new Error("bad png - invalid inflate data response");
1936
+ }
1937
+ let unfilteredData = FilterSync.process(inflatedData, metaData);
1938
+ inflateData = null;
1939
+ let bitmapData = bitmapper.dataToBitMap(unfilteredData, metaData);
1940
+ unfilteredData = null;
1941
+ let normalisedBitmapData = formatNormaliser(
1942
+ bitmapData,
1943
+ metaData,
1944
+ options.skipRescale
1945
+ );
1946
+ metaData.data = normalisedBitmapData;
1947
+ metaData.gamma = gamma || 0;
1948
+ return metaData;
1949
+ };
1950
+ }
1951
+ });
1952
+
1953
+ // ../../node_modules/pngjs/lib/packer-sync.js
1954
+ var require_packer_sync = __commonJS({
1955
+ "../../node_modules/pngjs/lib/packer-sync.js"(exports2, module2) {
1956
+ "use strict";
1957
+ init_cjs_shims();
1958
+ var hasSyncZlib = true;
1959
+ var zlib = require("zlib");
1960
+ if (!zlib.deflateSync) {
1961
+ hasSyncZlib = false;
1962
+ }
1963
+ var constants = require_constants();
1964
+ var Packer = require_packer();
1965
+ module2.exports = function(metaData, opt) {
1966
+ if (!hasSyncZlib) {
1967
+ throw new Error(
1968
+ "To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0"
1969
+ );
1970
+ }
1971
+ let options = opt || {};
1972
+ let packer = new Packer(options);
1973
+ let chunks = [];
1974
+ chunks.push(Buffer.from(constants.PNG_SIGNATURE));
1975
+ chunks.push(packer.packIHDR(metaData.width, metaData.height));
1976
+ if (metaData.gamma) {
1977
+ chunks.push(packer.packGAMA(metaData.gamma));
1978
+ }
1979
+ let filteredData = packer.filterData(
1980
+ metaData.data,
1981
+ metaData.width,
1982
+ metaData.height
1983
+ );
1984
+ let compressedData = zlib.deflateSync(
1985
+ filteredData,
1986
+ packer.getDeflateOptions()
1987
+ );
1988
+ filteredData = null;
1989
+ if (!compressedData || !compressedData.length) {
1990
+ throw new Error("bad png - invalid compressed data response");
1991
+ }
1992
+ chunks.push(packer.packIDAT(compressedData));
1993
+ chunks.push(packer.packIEND());
1994
+ return Buffer.concat(chunks);
1995
+ };
1996
+ }
1997
+ });
1998
+
1999
+ // ../../node_modules/pngjs/lib/png-sync.js
2000
+ var require_png_sync = __commonJS({
2001
+ "../../node_modules/pngjs/lib/png-sync.js"(exports2) {
2002
+ "use strict";
2003
+ init_cjs_shims();
2004
+ var parse = require_parser_sync();
2005
+ var pack = require_packer_sync();
2006
+ exports2.read = function(buffer, options) {
2007
+ return parse(buffer, options || {});
2008
+ };
2009
+ exports2.write = function(png, options) {
2010
+ return pack(png, options);
2011
+ };
2012
+ }
2013
+ });
2014
+
2015
+ // ../../node_modules/pngjs/lib/png.js
2016
+ var require_png = __commonJS({
2017
+ "../../node_modules/pngjs/lib/png.js"(exports2) {
2018
+ "use strict";
2019
+ init_cjs_shims();
2020
+ var util = require("util");
2021
+ var Stream = require("stream");
2022
+ var Parser = require_parser_async();
2023
+ var Packer = require_packer_async();
2024
+ var PNGSync = require_png_sync();
2025
+ var PNG2 = exports2.PNG = function(options) {
2026
+ Stream.call(this);
2027
+ options = options || {};
2028
+ this.width = options.width | 0;
2029
+ this.height = options.height | 0;
2030
+ this.data = this.width > 0 && this.height > 0 ? Buffer.alloc(4 * this.width * this.height) : null;
2031
+ if (options.fill && this.data) {
2032
+ this.data.fill(0);
2033
+ }
2034
+ this.gamma = 0;
2035
+ this.readable = this.writable = true;
2036
+ this._parser = new Parser(options);
2037
+ this._parser.on("error", this.emit.bind(this, "error"));
2038
+ this._parser.on("close", this._handleClose.bind(this));
2039
+ this._parser.on("metadata", this._metadata.bind(this));
2040
+ this._parser.on("gamma", this._gamma.bind(this));
2041
+ this._parser.on(
2042
+ "parsed",
2043
+ function(data) {
2044
+ this.data = data;
2045
+ this.emit("parsed", data);
2046
+ }.bind(this)
2047
+ );
2048
+ this._packer = new Packer(options);
2049
+ this._packer.on("data", this.emit.bind(this, "data"));
2050
+ this._packer.on("end", this.emit.bind(this, "end"));
2051
+ this._parser.on("close", this._handleClose.bind(this));
2052
+ this._packer.on("error", this.emit.bind(this, "error"));
2053
+ };
2054
+ util.inherits(PNG2, Stream);
2055
+ PNG2.sync = PNGSync;
2056
+ PNG2.prototype.pack = function() {
2057
+ if (!this.data || !this.data.length) {
2058
+ this.emit("error", "No data provided");
2059
+ return this;
2060
+ }
2061
+ process.nextTick(
2062
+ function() {
2063
+ this._packer.pack(this.data, this.width, this.height, this.gamma);
2064
+ }.bind(this)
2065
+ );
2066
+ return this;
2067
+ };
2068
+ PNG2.prototype.parse = function(data, callback) {
2069
+ if (callback) {
2070
+ let onParsed, onError;
2071
+ onParsed = function(parsedData) {
2072
+ this.removeListener("error", onError);
2073
+ this.data = parsedData;
2074
+ callback(null, this);
2075
+ }.bind(this);
2076
+ onError = function(err) {
2077
+ this.removeListener("parsed", onParsed);
2078
+ callback(err, null);
2079
+ }.bind(this);
2080
+ this.once("parsed", onParsed);
2081
+ this.once("error", onError);
2082
+ }
2083
+ this.end(data);
2084
+ return this;
2085
+ };
2086
+ PNG2.prototype.write = function(data) {
2087
+ this._parser.write(data);
2088
+ return true;
2089
+ };
2090
+ PNG2.prototype.end = function(data) {
2091
+ this._parser.end(data);
2092
+ };
2093
+ PNG2.prototype._metadata = function(metadata) {
2094
+ this.width = metadata.width;
2095
+ this.height = metadata.height;
2096
+ this.emit("metadata", metadata);
2097
+ };
2098
+ PNG2.prototype._gamma = function(gamma) {
2099
+ this.gamma = gamma;
2100
+ };
2101
+ PNG2.prototype._handleClose = function() {
2102
+ if (!this._parser.writable && !this._packer.readable) {
2103
+ this.emit("close");
2104
+ }
2105
+ };
2106
+ PNG2.bitblt = function(src, dst, srcX, srcY, width, height, deltaX, deltaY) {
2107
+ srcX |= 0;
2108
+ srcY |= 0;
2109
+ width |= 0;
2110
+ height |= 0;
2111
+ deltaX |= 0;
2112
+ deltaY |= 0;
2113
+ if (srcX > src.width || srcY > src.height || srcX + width > src.width || srcY + height > src.height) {
2114
+ throw new Error("bitblt reading outside image");
2115
+ }
2116
+ if (deltaX > dst.width || deltaY > dst.height || deltaX + width > dst.width || deltaY + height > dst.height) {
2117
+ throw new Error("bitblt writing outside image");
2118
+ }
2119
+ for (let y = 0; y < height; y++) {
2120
+ src.data.copy(
2121
+ dst.data,
2122
+ (deltaY + y) * dst.width + deltaX << 2,
2123
+ (srcY + y) * src.width + srcX << 2,
2124
+ (srcY + y) * src.width + srcX + width << 2
2125
+ );
2126
+ }
2127
+ };
2128
+ PNG2.prototype.bitblt = function(dst, srcX, srcY, width, height, deltaX, deltaY) {
2129
+ PNG2.bitblt(this, dst, srcX, srcY, width, height, deltaX, deltaY);
2130
+ return this;
2131
+ };
2132
+ PNG2.adjustGamma = function(src) {
2133
+ if (src.gamma) {
2134
+ for (let y = 0; y < src.height; y++) {
2135
+ for (let x = 0; x < src.width; x++) {
2136
+ let idx = src.width * y + x << 2;
2137
+ for (let i = 0; i < 3; i++) {
2138
+ let sample = src.data[idx + i] / 255;
2139
+ sample = Math.pow(sample, 1 / 2.2 / src.gamma);
2140
+ src.data[idx + i] = Math.round(sample * 255);
2141
+ }
2142
+ }
2143
+ }
2144
+ src.gamma = 0;
2145
+ }
2146
+ };
2147
+ PNG2.prototype.adjustGamma = function() {
2148
+ PNG2.adjustGamma(this);
2149
+ };
2150
+ }
2151
+ });
2152
+
2153
+ // src/verify.ts
2154
+ var verify_exports = {};
2155
+ __export(verify_exports, {
2156
+ DEFAULT_STYLE_PROPERTIES: () => DEFAULT_STYLE_PROPERTIES,
2157
+ DEFAULT_VERIFY_OPTIONS: () => DEFAULT_VERIFY_OPTIONS,
2158
+ DEFAULT_VIEWPORTS: () => DEFAULT_VIEWPORTS,
2159
+ createVerifier: () => createVerifier,
2160
+ isBrowserAvailable: () => isBrowserAvailable,
2161
+ resolveVerifyOptions: () => resolveVerifyOptions,
2162
+ verifyEquivalence: () => verifyEquivalence
2163
+ });
2164
+ module.exports = __toCommonJS(verify_exports);
2165
+ init_cjs_shims();
2166
+
2167
+ // ../verify/src/index.ts
2168
+ init_cjs_shims();
2169
+
2170
+ // ../verify/src/types.ts
2171
+ init_cjs_shims();
2172
+ var DEFAULT_VIEWPORTS = [
2173
+ { name: "mobile", width: 375, height: 667, deviceScaleFactor: 2 },
2174
+ { name: "tablet", width: 768, height: 1024, deviceScaleFactor: 2 },
2175
+ { name: "desktop", width: 1280, height: 800, deviceScaleFactor: 1 }
2176
+ ];
2177
+ var DEFAULT_VERIFY_OPTIONS = {
2178
+ engine: "chromium",
2179
+ pixelThreshold: 2,
2180
+ maxPixelRatio: 0,
2181
+ maxBoxDeltaPx: 0.5,
2182
+ timeoutMs: 3e4,
2183
+ captureArtifacts: false
2184
+ };
2185
+
2186
+ // ../verify/src/diff.ts
2187
+ init_cjs_shims();
2188
+
2189
+ // ../../node_modules/pixelmatch/index.js
2190
+ init_cjs_shims();
2191
+ function pixelmatch(img1, img2, output, width, height, options = {}) {
2192
+ const {
2193
+ threshold = 0.1,
2194
+ alpha = 0.1,
2195
+ aaColor = [255, 255, 0],
2196
+ diffColor = [255, 0, 0],
2197
+ checkerboard = true,
2198
+ includeAA,
2199
+ diffColorAlt,
2200
+ diffMask
2201
+ } = options;
2202
+ if (!isPixelData(img1) || !isPixelData(img2) || output && !isPixelData(output))
2203
+ throw new Error("Image data: Uint8Array, Uint8ClampedArray or Buffer expected.");
2204
+ if (img1.length !== img2.length || output && output.length !== img1.length)
2205
+ throw new Error(`Image sizes do not match. Image 1 size: ${img1.length}, image 2 size: ${img2.length}`);
2206
+ if (img1.length !== width * height * 4) throw new Error(`Image data size does not match width/height. Expecting ${width * height * 4}. Got ${img1.length}`);
2207
+ const len = width * height;
2208
+ const a32 = new Uint32Array(img1.buffer, img1.byteOffset, len);
2209
+ const b32 = new Uint32Array(img2.buffer, img2.byteOffset, len);
2210
+ let identical = true;
2211
+ for (let i = 0; i < len; i++) {
2212
+ if (a32[i] !== b32[i]) {
2213
+ identical = false;
2214
+ break;
2215
+ }
2216
+ }
2217
+ if (identical) {
2218
+ if (output && !diffMask) {
2219
+ for (let i = 0, pos = 0; i < len; i++, pos += 4) drawGrayPixel(img1, pos, alpha, output);
2220
+ }
2221
+ return 0;
2222
+ }
2223
+ const maxDelta = 35215 * threshold * threshold;
2224
+ const [aaR, aaG, aaB] = aaColor;
2225
+ const [diffR, diffG, diffB] = diffColor;
2226
+ const [altR, altG, altB] = diffColorAlt || diffColor;
2227
+ let diff = 0;
2228
+ for (let i = 0, pos = 0; i < len; i++, pos += 4) {
2229
+ const delta = a32[i] === b32[i] ? 0 : colorDelta(img1, img2, pos, pos, checkerboard);
2230
+ if (Math.abs(delta) > maxDelta) {
2231
+ const x = i % width;
2232
+ const y = i / width | 0;
2233
+ const isExcludedAA = !includeAA && (antialiased(img1, x, y, width, height, a32, b32, checkerboard) || antialiased(img2, x, y, width, height, b32, a32, checkerboard));
2234
+ if (isExcludedAA) {
2235
+ if (output && !diffMask) drawPixel(output, pos, aaR, aaG, aaB);
2236
+ } else {
2237
+ if (output) {
2238
+ if (delta < 0) {
2239
+ drawPixel(output, pos, altR, altG, altB);
2240
+ } else {
2241
+ drawPixel(output, pos, diffR, diffG, diffB);
2242
+ }
2243
+ }
2244
+ diff++;
2245
+ }
2246
+ } else if (output && !diffMask) {
2247
+ drawGrayPixel(img1, pos, alpha, output);
2248
+ }
2249
+ }
2250
+ return diff;
2251
+ }
2252
+ function isPixelData(arr) {
2253
+ return ArrayBuffer.isView(arr) && arr.BYTES_PER_ELEMENT === 1;
2254
+ }
2255
+ function antialiased(img, x1, y1, width, height, a32, b32, checkerboard) {
2256
+ const x0 = Math.max(x1 - 1, 0);
2257
+ const y0 = Math.max(y1 - 1, 0);
2258
+ const x2 = Math.min(x1 + 1, width - 1);
2259
+ const y2 = Math.min(y1 + 1, height - 1);
2260
+ const pos4 = (y1 * width + x1) * 4;
2261
+ const cr = img[pos4];
2262
+ const cg = img[pos4 + 1];
2263
+ const cb = img[pos4 + 2];
2264
+ const ca = img[pos4 + 3];
2265
+ let zeroes = x1 === x0 || x1 === x2 || y1 === y0 || y1 === y2 ? 1 : 0;
2266
+ let min = 0;
2267
+ let max = 0;
2268
+ let minX = 0;
2269
+ let minY = 0;
2270
+ let maxX = 0;
2271
+ let maxY = 0;
2272
+ for (let x = x0; x <= x2; x++) {
2273
+ for (let y = y0; y <= y2; y++) {
2274
+ if (x === x1 && y === y1) continue;
2275
+ const delta = brightnessDelta(img, pos4, (y * width + x) * 4, cr, cg, cb, ca, checkerboard);
2276
+ if (delta === 0) {
2277
+ zeroes++;
2278
+ if (zeroes > 2) return false;
2279
+ } else if (delta < min) {
2280
+ min = delta;
2281
+ minX = x;
2282
+ minY = y;
2283
+ } else if (delta > max) {
2284
+ max = delta;
2285
+ maxX = x;
2286
+ maxY = y;
2287
+ }
2288
+ }
2289
+ }
2290
+ if (min === 0 || max === 0) return false;
2291
+ return hasManySiblings(a32, minX, minY, width, height) && hasManySiblings(b32, minX, minY, width, height) || hasManySiblings(a32, maxX, maxY, width, height) && hasManySiblings(b32, maxX, maxY, width, height);
2292
+ }
2293
+ function hasManySiblings(img, x1, y1, width, height) {
2294
+ const x0 = Math.max(x1 - 1, 0);
2295
+ const y0 = Math.max(y1 - 1, 0);
2296
+ const x2 = Math.min(x1 + 1, width - 1);
2297
+ const y2 = Math.min(y1 + 1, height - 1);
2298
+ const val = img[y1 * width + x1];
2299
+ let zeroes = x1 === x0 || x1 === x2 || y1 === y0 || y1 === y2 ? 1 : 0;
2300
+ for (let x = x0; x <= x2; x++) {
2301
+ for (let y = y0; y <= y2; y++) {
2302
+ if (x === x1 && y === y1) continue;
2303
+ zeroes += +(val === img[y * width + x]);
2304
+ if (zeroes > 2) return true;
2305
+ }
2306
+ }
2307
+ return false;
2308
+ }
2309
+ function colorDelta(img1, img2, k, m, checkerboard) {
2310
+ const r1 = img1[k];
2311
+ const g1 = img1[k + 1];
2312
+ const b1 = img1[k + 2];
2313
+ const a1 = img1[k + 3];
2314
+ const r2 = img2[m];
2315
+ const g2 = img2[m + 1];
2316
+ const b2 = img2[m + 2];
2317
+ const a2 = img2[m + 3];
2318
+ let dr = r1 - r2;
2319
+ let dg = g1 - g2;
2320
+ let db = b1 - b2;
2321
+ const da = a1 - a2;
2322
+ if (a1 < 255 || a2 < 255) {
2323
+ let rb = 255, gb = 255, bb = 255;
2324
+ if (checkerboard) {
2325
+ rb = 48 + 159 * (k % 2);
2326
+ gb = 48 + 159 * ((k / 1.618033988749895 | 0) % 2);
2327
+ bb = 48 + 159 * ((k / 2.618033988749895 | 0) % 2);
2328
+ }
2329
+ dr = (r1 * a1 - r2 * a2 - rb * da) / 255;
2330
+ dg = (g1 * a1 - g2 * a2 - gb * da) / 255;
2331
+ db = (b1 * a1 - b2 * a2 - bb * da) / 255;
2332
+ }
2333
+ const y = dr * 0.29889531 + dg * 0.58662247 + db * 0.11448223;
2334
+ const i = dr * 0.59597799 - dg * 0.2741761 - db * 0.32180189;
2335
+ const q = dr * 0.21147017 - dg * 0.52261711 + db * 0.31114694;
2336
+ const delta = 0.5053 * y * y + 0.299 * i * i + 0.1957 * q * q;
2337
+ return y > 0 ? -delta : delta;
2338
+ }
2339
+ function brightnessDelta(img, k, m, r1, g1, b1, a1, checkerboard) {
2340
+ const r2 = img[m];
2341
+ const g2 = img[m + 1];
2342
+ const b2 = img[m + 2];
2343
+ const a2 = img[m + 3];
2344
+ let dr = r1 - r2;
2345
+ let dg = g1 - g2;
2346
+ let db = b1 - b2;
2347
+ const da = a1 - a2;
2348
+ if (!dr && !dg && !db && !da) return 0;
2349
+ if (a1 < 255 || a2 < 255) {
2350
+ let rb = 255, gb = 255, bb = 255;
2351
+ if (checkerboard) {
2352
+ rb = 48 + 159 * (k % 2);
2353
+ gb = 48 + 159 * ((k / 1.618033988749895 | 0) % 2);
2354
+ bb = 48 + 159 * ((k / 2.618033988749895 | 0) % 2);
2355
+ }
2356
+ dr = (r1 * a1 - r2 * a2 - rb * da) / 255;
2357
+ dg = (g1 * a1 - g2 * a2 - gb * da) / 255;
2358
+ db = (b1 * a1 - b2 * a2 - bb * da) / 255;
2359
+ }
2360
+ return dr * 0.29889531 + dg * 0.58662247 + db * 0.11448223;
2361
+ }
2362
+ function drawPixel(output, pos, r, g, b) {
2363
+ output[pos] = r;
2364
+ output[pos + 1] = g;
2365
+ output[pos + 2] = b;
2366
+ output[pos + 3] = 255;
2367
+ }
2368
+ function drawGrayPixel(img, i, alpha, output) {
2369
+ const val = 255 + (img[i] * 0.29889531 + img[i + 1] * 0.58662247 + img[i + 2] * 0.11448223 - 255) * alpha * img[i + 3] / 255;
2370
+ drawPixel(output, i, val, val, val);
2371
+ }
2372
+
2373
+ // ../verify/src/diff.ts
2374
+ var import_pngjs = __toESM(require_png(), 1);
2375
+ var DEFAULT_STYLE_PROPERTIES = [
2376
+ "color",
2377
+ "background-color",
2378
+ "background-image",
2379
+ "opacity",
2380
+ "visibility",
2381
+ "border-top-color",
2382
+ "border-right-color",
2383
+ "border-bottom-color",
2384
+ "border-left-color",
2385
+ "border-top-width",
2386
+ "border-right-width",
2387
+ "border-bottom-width",
2388
+ "border-left-width",
2389
+ "border-top-style",
2390
+ "border-right-style",
2391
+ "border-bottom-style",
2392
+ "border-left-style",
2393
+ "border-top-left-radius",
2394
+ "border-top-right-radius",
2395
+ "border-bottom-left-radius",
2396
+ "border-bottom-right-radius",
2397
+ "box-shadow",
2398
+ "outline-color",
2399
+ "outline-width",
2400
+ "font-family",
2401
+ "font-size",
2402
+ "font-weight",
2403
+ "font-style",
2404
+ "line-height",
2405
+ "letter-spacing",
2406
+ "text-align",
2407
+ "text-transform",
2408
+ "text-decoration-line",
2409
+ "white-space"
2410
+ ];
2411
+ function pixelDiff(beforePng, afterPng, threshold01, capture) {
2412
+ const a = import_pngjs.PNG.sync.read(Buffer.from(beforePng));
2413
+ const b = import_pngjs.PNG.sync.read(Buffer.from(afterPng));
2414
+ if (a.width !== b.width || a.height !== b.height) {
2415
+ const width2 = Math.max(a.width, b.width);
2416
+ const height2 = Math.max(a.height, b.height);
2417
+ const totalPixels2 = Math.max(a.width * a.height, b.width * b.height);
2418
+ return { width: width2, height: height2, totalPixels: totalPixels2, changedPixels: totalPixels2, changedRatio: 1 };
2419
+ }
2420
+ const { width, height } = a;
2421
+ const totalPixels = width * height;
2422
+ const diff = capture ? new import_pngjs.PNG({ width, height }) : null;
2423
+ const changedPixels = pixelmatch(
2424
+ a.data,
2425
+ b.data,
2426
+ diff ? diff.data : void 0,
2427
+ width,
2428
+ height,
2429
+ { threshold: threshold01 }
2430
+ );
2431
+ return {
2432
+ width,
2433
+ height,
2434
+ totalPixels,
2435
+ changedPixels,
2436
+ changedRatio: totalPixels === 0 ? 0 : changedPixels / totalPixels,
2437
+ ...diff ? { diffPng: new Uint8Array(import_pngjs.PNG.sync.write(diff)) } : {}
2438
+ };
2439
+ }
2440
+ function leafKey(leaf) {
2441
+ return `${leaf.role}\0${leaf.text}`;
2442
+ }
2443
+ function byPosition(a, b) {
2444
+ if (Math.abs(a.box.y - b.box.y) > 1) return a.box.y - b.box.y;
2445
+ if (Math.abs(a.box.x - b.box.x) > 1) return a.box.x - b.box.x;
2446
+ return 0;
2447
+ }
2448
+ function matchLeaves(before, after) {
2449
+ const groups = /* @__PURE__ */ new Map();
2450
+ const bucket = (key) => {
2451
+ let g = groups.get(key);
2452
+ if (!g) {
2453
+ g = { before: [], after: [] };
2454
+ groups.set(key, g);
2455
+ }
2456
+ return g;
2457
+ };
2458
+ for (const leaf of before) bucket(leafKey(leaf)).before.push(leaf);
2459
+ for (const leaf of after) bucket(leafKey(leaf)).after.push(leaf);
2460
+ const pairs = [];
2461
+ for (const [key, g] of groups) {
2462
+ g.before.sort(byPosition);
2463
+ g.after.sort(byPosition);
2464
+ const n = Math.max(g.before.length, g.after.length);
2465
+ for (let i = 0; i < n; i++) {
2466
+ pairs.push({
2467
+ path: `${key.replace("\0", "\xB7")}#${i}`,
2468
+ before: g.before[i] ?? null,
2469
+ after: g.after[i] ?? null
2470
+ });
2471
+ }
2472
+ }
2473
+ return pairs;
2474
+ }
2475
+ function diffBoxes(pairs) {
2476
+ const out = [];
2477
+ for (const { path, before, after } of pairs) {
2478
+ const b = before ? before.box : null;
2479
+ const a = after ? after.box : null;
2480
+ if (!b || !a) {
2481
+ out.push({
2482
+ path,
2483
+ before: b,
2484
+ after: a,
2485
+ deltaX: Number.POSITIVE_INFINITY,
2486
+ deltaY: Number.POSITIVE_INFINITY,
2487
+ deltaWidth: Number.POSITIVE_INFINITY,
2488
+ deltaHeight: Number.POSITIVE_INFINITY,
2489
+ maxDelta: Number.POSITIVE_INFINITY
2490
+ });
2491
+ continue;
2492
+ }
2493
+ const deltaX = a.x - b.x;
2494
+ const deltaY = a.y - b.y;
2495
+ const deltaWidth = a.width - b.width;
2496
+ const deltaHeight = a.height - b.height;
2497
+ const maxDelta = Math.max(
2498
+ Math.abs(deltaX),
2499
+ Math.abs(deltaY),
2500
+ Math.abs(deltaWidth),
2501
+ Math.abs(deltaHeight)
2502
+ );
2503
+ out.push({ path, before: b, after: a, deltaX, deltaY, deltaWidth, deltaHeight, maxDelta });
2504
+ }
2505
+ return out;
2506
+ }
2507
+ function normalizeStyleValue(raw) {
2508
+ let v = raw.trim().toLowerCase();
2509
+ if (v === "transparent") v = "rgba(0, 0, 0, 0)";
2510
+ v = v.replace(/-?\d*\.\d+/g, (m) => String(Math.round(Number.parseFloat(m))));
2511
+ v = v.replace(/\s+/g, " ");
2512
+ return v;
2513
+ }
2514
+ function diffStyles(pairs, properties) {
2515
+ const out = [];
2516
+ for (const { path, before, after } of pairs) {
2517
+ if (!before || !after) continue;
2518
+ for (const property of properties) {
2519
+ const rawBefore = before.styles[property] ?? "";
2520
+ const rawAfter = after.styles[property] ?? "";
2521
+ if (normalizeStyleValue(rawBefore) !== normalizeStyleValue(rawAfter)) {
2522
+ out.push({ path, property, before: rawBefore, after: rawAfter });
2523
+ }
2524
+ }
2525
+ }
2526
+ return out;
2527
+ }
2528
+
2529
+ // ../verify/src/browser.ts
2530
+ init_cjs_shims();
2531
+ var import_playwright = require("playwright");
2532
+ var ENGINES = { chromium: import_playwright.chromium, firefox: import_playwright.firefox, webkit: import_playwright.webkit };
2533
+ var CHROMIUM_ARGS = [
2534
+ "--no-sandbox",
2535
+ "--disable-dev-shm-usage",
2536
+ "--force-color-profile=srgb",
2537
+ "--hide-scrollbars",
2538
+ "--disable-lcd-text"
2539
+ ];
2540
+ async function launchBrowser(engine) {
2541
+ const type = ENGINES[engine];
2542
+ return type.launch({
2543
+ headless: true,
2544
+ args: engine === "chromium" ? [...CHROMIUM_ARGS] : []
2545
+ });
2546
+ }
2547
+ async function isBrowserAvailable(engine = "chromium") {
2548
+ let browser = null;
2549
+ try {
2550
+ browser = await launchBrowser(engine);
2551
+ return true;
2552
+ } catch {
2553
+ return false;
2554
+ } finally {
2555
+ if (browser) await browser.close().catch(() => void 0);
2556
+ }
2557
+ }
2558
+
2559
+ // ../verify/src/render.ts
2560
+ init_cjs_shims();
2561
+ var DETERMINISM_CSS = [
2562
+ "*,*::before,*::after{",
2563
+ "animation-duration:0s!important;animation-delay:0s!important;",
2564
+ "transition-duration:0s!important;transition-delay:0s!important;",
2565
+ "caret-color:transparent!important;scroll-behavior:auto!important}",
2566
+ "::-webkit-scrollbar{display:none!important}"
2567
+ ].join("");
2568
+ function wrapHtml(code) {
2569
+ if (/<html[\s>]/i.test(code) || /<!doctype/i.test(code)) return code;
2570
+ return `<!doctype html><html><head><meta charset="utf-8"><style>html,body{margin:0;padding:0;background:#fff}</style></head><body>${code}</body></html>`;
2571
+ }
2572
+ function extractLeaves(props) {
2573
+ const leaves = [];
2574
+ const all = Array.from(document.querySelectorAll("*"));
2575
+ for (const el of all) {
2576
+ const rect = el.getBoundingClientRect();
2577
+ if (rect.width <= 0 || rect.height <= 0) continue;
2578
+ const cs = getComputedStyle(el);
2579
+ if (cs.display === "none" || cs.visibility === "hidden" || Number.parseFloat(cs.opacity) === 0) {
2580
+ continue;
2581
+ }
2582
+ const directText = Array.from(el.childNodes).filter((n) => n.nodeType === 3).map((n) => n.textContent ?? "").join("").replace(/\s+/g, " ").trim();
2583
+ const hasElementChild = el.children.length > 0;
2584
+ if (hasElementChild && directText === "") continue;
2585
+ const styles = {};
2586
+ for (const p of props) styles[p] = cs.getPropertyValue(p);
2587
+ leaves.push({
2588
+ tag: el.tagName.toLowerCase(),
2589
+ role: el.getAttribute("role") ?? el.tagName.toLowerCase(),
2590
+ text: directText,
2591
+ box: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },
2592
+ styles
2593
+ });
2594
+ }
2595
+ return leaves;
2596
+ }
2597
+ async function renderTarget(context, code, properties, timeoutMs) {
2598
+ const page = await context.newPage();
2599
+ try {
2600
+ await page.setContent(wrapHtml(code), { waitUntil: "load", timeout: timeoutMs });
2601
+ await page.addStyleTag({ content: DETERMINISM_CSS });
2602
+ await page.evaluate(async () => {
2603
+ try {
2604
+ await document.fonts.ready;
2605
+ } catch {
2606
+ }
2607
+ });
2608
+ await page.evaluate(
2609
+ () => new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(() => resolve())))
2610
+ );
2611
+ const buffer = await page.screenshot({ animations: "disabled", caret: "hide" });
2612
+ const leaves = await page.evaluate(extractLeaves, properties);
2613
+ return { png: new Uint8Array(buffer), leaves };
2614
+ } finally {
2615
+ await page.close();
2616
+ }
2617
+ }
2618
+
2619
+ // ../verify/src/index.ts
2620
+ function resolveVerifyOptions(opts = {}) {
2621
+ return {
2622
+ viewports: opts.viewports ?? DEFAULT_VIEWPORTS,
2623
+ engine: opts.engine ?? DEFAULT_VERIFY_OPTIONS.engine,
2624
+ pixelThreshold: opts.pixelThreshold ?? DEFAULT_VERIFY_OPTIONS.pixelThreshold,
2625
+ maxPixelRatio: opts.maxPixelRatio ?? DEFAULT_VERIFY_OPTIONS.maxPixelRatio,
2626
+ maxBoxDeltaPx: opts.maxBoxDeltaPx ?? DEFAULT_VERIFY_OPTIONS.maxBoxDeltaPx,
2627
+ styleProperties: opts.styleProperties ?? DEFAULT_STYLE_PROPERTIES,
2628
+ timeoutMs: opts.timeoutMs ?? DEFAULT_VERIFY_OPTIONS.timeoutMs,
2629
+ captureArtifacts: opts.captureArtifacts ?? DEFAULT_VERIFY_OPTIONS.captureArtifacts
2630
+ };
2631
+ }
2632
+ async function verifyViewport(browser, before, after, vp, resolved) {
2633
+ const context = await browser.newContext({
2634
+ viewport: { width: vp.width, height: vp.height },
2635
+ deviceScaleFactor: vp.deviceScaleFactor ?? 1,
2636
+ reducedMotion: "reduce",
2637
+ colorScheme: "light",
2638
+ forcedColors: "none"
2639
+ });
2640
+ try {
2641
+ const b = await renderTarget(context, before.code, resolved.styleProperties, resolved.timeoutMs);
2642
+ const a = await renderTarget(context, after.code, resolved.styleProperties, resolved.timeoutMs);
2643
+ const threshold01 = Math.min(1, Math.max(0, resolved.pixelThreshold / 255));
2644
+ const pixel = pixelDiff(b.png, a.png, threshold01, resolved.captureArtifacts);
2645
+ const pairs = matchLeaves(b.leaves, a.leaves);
2646
+ const boxes = diffBoxes(pairs);
2647
+ const styles = diffStyles(pairs, resolved.styleProperties);
2648
+ const pixelOk = pixel.changedRatio <= resolved.maxPixelRatio;
2649
+ const boxOk = boxes.every((box) => box.maxDelta <= resolved.maxBoxDeltaPx);
2650
+ const styleOk = styles.length === 0;
2651
+ const equivalence = pixelOk && boxOk && styleOk ? "equivalent" : "divergent";
2652
+ return {
2653
+ viewport: vp,
2654
+ equivalence,
2655
+ pixel,
2656
+ boxes,
2657
+ styles,
2658
+ ...resolved.captureArtifacts ? { beforePng: b.png, afterPng: a.png } : {}
2659
+ };
2660
+ } finally {
2661
+ await context.close();
2662
+ }
2663
+ }
2664
+ async function runVerification(browser, before, after, resolved, startedAt) {
2665
+ const viewports = [];
2666
+ for (const vp of resolved.viewports) {
2667
+ viewports.push(await verifyViewport(browser, before, after, vp, resolved));
2668
+ }
2669
+ const equivalence = viewports.every((v) => v.equivalence === "equivalent") ? "equivalent" : "divergent";
2670
+ return {
2671
+ equivalence,
2672
+ engine: resolved.engine,
2673
+ viewports,
2674
+ diagnostics: [],
2675
+ durationMs: Date.now() - startedAt
2676
+ };
2677
+ }
2678
+ function inconclusiveResult(resolved, startedAt, reason) {
2679
+ const diagnostic = {
2680
+ code: "DF_VERIFY_INCONCLUSIVE",
2681
+ severity: "warn",
2682
+ message: reason
2683
+ };
2684
+ return {
2685
+ equivalence: "inconclusive",
2686
+ engine: resolved.engine,
2687
+ viewports: [],
2688
+ diagnostics: [diagnostic],
2689
+ durationMs: Date.now() - startedAt
2690
+ };
2691
+ }
2692
+ function createVerifier() {
2693
+ let browser = null;
2694
+ let launchFailed = false;
2695
+ async function ensureBrowser(engine) {
2696
+ if (browser) return browser;
2697
+ if (launchFailed) return null;
2698
+ try {
2699
+ browser = await launchBrowser(engine);
2700
+ return browser;
2701
+ } catch {
2702
+ launchFailed = true;
2703
+ return null;
2704
+ }
2705
+ }
2706
+ return {
2707
+ async verify(before, after, opts = {}) {
2708
+ const resolved = resolveVerifyOptions(opts);
2709
+ const startedAt = Date.now();
2710
+ const live = await ensureBrowser(resolved.engine);
2711
+ if (!live) {
2712
+ return inconclusiveResult(
2713
+ resolved,
2714
+ startedAt,
2715
+ `Browser engine '${resolved.engine}' could not be launched (binary not installed?); verification skipped.`
2716
+ );
2717
+ }
2718
+ return runVerification(live, before, after, resolved, startedAt);
2719
+ },
2720
+ async close() {
2721
+ if (browser) {
2722
+ const b = browser;
2723
+ browser = null;
2724
+ await b.close().catch(() => void 0);
2725
+ }
2726
+ }
2727
+ };
2728
+ }
2729
+ async function verifyEquivalence(before, after, opts = {}) {
2730
+ const verifier = createVerifier();
2731
+ try {
2732
+ return await verifier.verify(before, after, opts);
2733
+ } finally {
2734
+ await verifier.close();
2735
+ }
2736
+ }
2737
+ // Annotate the CommonJS export names for ESM import in node:
2738
+ 0 && (module.exports = {
2739
+ DEFAULT_STYLE_PROPERTIES,
2740
+ DEFAULT_VERIFY_OPTIONS,
2741
+ DEFAULT_VIEWPORTS,
2742
+ createVerifier,
2743
+ isBrowserAvailable,
2744
+ resolveVerifyOptions,
2745
+ verifyEquivalence
2746
+ });
2747
+ //# sourceMappingURL=verify.cjs.map