@capagents/forgeqe 3.3.7 → 3.3.9

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 (132) hide show
  1. package/HOW_TO_USE.md +92 -0
  2. package/dist/a11y-runtime.mjs +3204 -0
  3. package/dist/docs-site/docs/area-quality/index.html +90 -2
  4. package/dist/docs-site/docs/overview/index.html +1 -1
  5. package/dist/docs-site/docs/search.js +1 -1
  6. package/dist/forgeqe.js +2215 -2094
  7. package/dist/template.html +69 -70
  8. package/dist/web/assets/{3d-force-graph-Bsispdm1.js → 3d-force-graph-BPsVSYjw.js} +1 -1
  9. package/dist/web/assets/Agent-DY6pRvcD.js +10 -0
  10. package/dist/web/assets/{AgentWork-BugEUl60.js → AgentWork-Brch_Mn3.js} +1 -1
  11. package/dist/web/assets/ApiTests-BtWKVPw5.js +17 -0
  12. package/dist/web/assets/{Browse-Dl2Lneca.js → Browse-DbIFxsy8.js} +1 -1
  13. package/dist/web/assets/Chat-BWiH0XGV.js +3 -0
  14. package/dist/web/assets/{CommandPalette-B7YPDCOk.js → CommandPalette-DfoEUEL6.js} +1 -1
  15. package/dist/web/assets/{Compare-D6XsFmmb.js → Compare-DTZ_BW1P.js} +1 -1
  16. package/dist/web/assets/Cost-DDghPWch.js +1 -0
  17. package/dist/web/assets/Data-DZlKsTwA.js +6 -0
  18. package/dist/web/assets/Desktop-DTIZ62Pi.js +1 -0
  19. package/dist/web/assets/DesktopReview-B8-dSGJH.js +2 -0
  20. package/dist/web/assets/Evidence-BYw_Q4Ul.js +1 -0
  21. package/dist/web/assets/Explore-BL_c5WK1.js +2 -0
  22. package/dist/web/assets/{Features-N3_77mz-.js → Features-DrFNrvbh.js} +1 -1
  23. package/dist/web/assets/Flags-CHrDwhqG.js +2 -0
  24. package/dist/web/assets/Flaky-DtcLf8h6.js +1 -0
  25. package/dist/web/assets/Impact-CMU_ijo2.js +3 -0
  26. package/dist/web/assets/Jobs-BjybdQb_.js +5 -0
  27. package/dist/web/assets/KindPage-VK-Vgkzv.js +6 -0
  28. package/dist/web/assets/{LiveDevice-j7NZXIJZ.js → LiveDevice-BqL1P33F.js} +1 -1
  29. package/dist/web/assets/Migration-7BI7iXIv.js +8 -0
  30. package/dist/web/assets/Mobile-AgAhvlVL.js +1 -0
  31. package/dist/web/assets/Observability-5r36Xf3d.js +1 -0
  32. package/dist/web/assets/{OwnItems-BdiPfdTw.js → OwnItems-CqCOuvba.js} +4 -4
  33. package/dist/web/assets/PageAgent-00NQxK49.js +1 -0
  34. package/dist/web/assets/Product-B75ztJFn.js +6 -0
  35. package/dist/web/assets/Production-lIUlcjf0.js +1 -0
  36. package/dist/web/assets/Quality-BlRpB6mx.js +1 -0
  37. package/dist/web/assets/Readiness-CesaSDtp.js +1 -0
  38. package/dist/web/assets/Record-CLy9jQ5N.js +1 -0
  39. package/dist/web/assets/Regression-BjpZrkfK.js +5 -0
  40. package/dist/web/assets/{RelationGraph-Blfs7PhK.js → RelationGraph-ClPBGuMw.js} +1 -1
  41. package/dist/web/assets/{Reports-HQkTX4Kr.js → Reports-Du8SNiHM.js} +2 -2
  42. package/dist/web/assets/Requirements-Dr1iLoMc.js +2 -0
  43. package/dist/web/assets/Responsive-DcD6MLzG.js +3 -0
  44. package/dist/web/assets/{RunDiff-75a-smeg.js → RunDiff-cLSFOsfC.js} +1 -1
  45. package/dist/web/assets/{Settings-BaodIliH.js → Settings-CUT5ggDd.js} +16 -16
  46. package/dist/web/assets/SiteScan-iUfWBeLV.js +5 -0
  47. package/dist/web/assets/{Steps-ZPH_rTJh.js → Steps-DJYwIiDu.js} +2 -2
  48. package/dist/web/assets/{TestData-DUlTo5qt.js → TestData-DqEcL5o4.js} +2 -2
  49. package/dist/web/assets/TestManagement-mBcfWTVH.js +4 -0
  50. package/dist/web/assets/{WhatsNew-BrVNacPl.js → WhatsNew-DrPf6l9-.js} +1 -1
  51. package/dist/web/assets/{agentSettingsSheet-UCqUtdjq.js → agentSettingsSheet-DyaVNewv.js} +1 -1
  52. package/dist/web/assets/api-Dr3U7W5w.js +1 -0
  53. package/dist/web/assets/{choice-C4-yW2x9.js → choice-W0qOx_1k.js} +1 -1
  54. package/dist/web/assets/{coverage-pqIlfEP0.js → coverage-DbHm8BUP.js} +3 -3
  55. package/dist/web/assets/{dataParts-C0C67bVQ.js → dataParts-Bdf97ZOD.js} +3 -3
  56. package/dist/web/assets/{desktopAppPath-B89LKvjx.js → desktopAppPath-kQmQOW6a.js} +1 -1
  57. package/dist/web/assets/{flowTheme-BNKwRxun.js → flowTheme-CVnIjV_m.js} +1 -1
  58. package/dist/web/assets/frame-CavkQick.js +13 -0
  59. package/dist/web/assets/index-BaEsXdFc.css +2 -0
  60. package/dist/web/assets/index-C1kXcI0E.js +57 -0
  61. package/dist/web/assets/line-icons-Cwj9OmCz.js +1 -0
  62. package/dist/web/assets/{logos-P2LOMyTK.js → logos-Cf-Wf5ex.js} +1 -1
  63. package/dist/web/assets/{markdown-CxsWgpYs.js → markdown-Bvv6oj4v.js} +3 -3
  64. package/dist/web/assets/{nav-DYgvAJu-.js → nav-DVPiPhOy.js} +1 -1
  65. package/dist/web/assets/pageBack-Blig1Uqs.js +3 -0
  66. package/dist/web/assets/{palette-BgJTq_Ot.js → palette-DwrGI2Fp.js} +1 -1
  67. package/dist/web/assets/{paletteCommands-Isq1rLs-.js → paletteCommands-DOF2o-rv.js} +1 -1
  68. package/dist/web/assets/parts-DgJ2y_ic.js +1 -0
  69. package/dist/web/assets/{productParts-ZEi0sPIk.js → productParts-B78jij3z.js} +1 -1
  70. package/dist/web/assets/qualityParts-t5t9kEKG.js +2 -0
  71. package/dist/web/assets/{recordTest-Bz5ryzpS.js → recordTest-BbXVOuGZ.js} +1 -1
  72. package/dist/web/assets/{route-oDy8sV6H.js → route-9BkoTWUE.js} +1 -1
  73. package/dist/web/assets/{sectionList-B651VPon.js → sectionList-DMyhAqst.js} +1 -1
  74. package/dist/web/assets/{step-mark-CaKf4dAR.js → step-mark-Bu6fNKW8.js} +1 -1
  75. package/dist/web/assets/stepper-CE4yOLqn.js +1 -0
  76. package/dist/web/assets/wizardParts-Bxb9UG5k.js +1 -0
  77. package/dist/web/index.html +11 -11
  78. package/docs/ForgeQE-Static-Analysis-Report-4008e9ee.html +207 -0
  79. package/docs/ForgeQE-Static-Analysis-Report-4008e9ee.pdf +0 -0
  80. package/docs/{ForgeQE-Static-Analysis-Report-5bbf0da7.html → ForgeQE-Static-Analysis-Report-ccbdac00.html} +33 -33
  81. package/docs/ForgeQE-Static-Analysis-Report-ccbdac00.pdf +0 -0
  82. package/docs/user-guide.html +89 -1
  83. package/forgeqe.example.yaml +1 -1
  84. package/package.json +2 -2
  85. package/prompts/brain.md +7 -0
  86. package/py/forgeqe_engine/cli.py +57 -0
  87. package/py/forgeqe_engine/diagnostics.py +32 -2
  88. package/py/forgeqe_engine/logins.py +11 -0
  89. package/py/forgeqe_engine/persona.py +90 -1
  90. package/py/forgeqe_engine/scan.py +202 -0
  91. package/py/forgeqe_engine/seo.py +95 -0
  92. package/py/forgeqe_engine/seo_analytics.mjs +59 -0
  93. package/py/forgeqe_engine/seo_facts.mjs +63 -0
  94. package/py/forgeqe_engine/seo_site.mjs +36 -0
  95. package/py/forgeqe_engine/service.py +3 -2
  96. package/dist/web/assets/Agent-39FbaH7G.js +0 -10
  97. package/dist/web/assets/ApiTests-B9rtwCbe.js +0 -17
  98. package/dist/web/assets/Chat-DocT7FlH.js +0 -3
  99. package/dist/web/assets/Cost-DvbuXS6u.js +0 -1
  100. package/dist/web/assets/Data-BmZHJkfj.js +0 -6
  101. package/dist/web/assets/Desktop-DD3F69ih.js +0 -1
  102. package/dist/web/assets/DesktopReview-BR0LtVFw.js +0 -2
  103. package/dist/web/assets/Evidence-OqAiYzrl.js +0 -1
  104. package/dist/web/assets/Explore-QNyusEFo.js +0 -2
  105. package/dist/web/assets/Flags-Yv4Ttmmh.js +0 -2
  106. package/dist/web/assets/Flaky-Bg2f2K1U.js +0 -1
  107. package/dist/web/assets/Impact-CpxvVnKj.js +0 -3
  108. package/dist/web/assets/Jobs-_gZTxoaG.js +0 -5
  109. package/dist/web/assets/KindPage-Amr6R7Ym.js +0 -6
  110. package/dist/web/assets/Migration-DfPYzTfk.js +0 -8
  111. package/dist/web/assets/Mobile-fIhhQPsp.js +0 -1
  112. package/dist/web/assets/Observability-13DkrRp2.js +0 -1
  113. package/dist/web/assets/PageAgent-CC8Ha6vu.js +0 -1
  114. package/dist/web/assets/Product-CnXkqwQm.js +0 -6
  115. package/dist/web/assets/Production-5mTIt4sr.js +0 -1
  116. package/dist/web/assets/Quality-DbLcbP1X.js +0 -1
  117. package/dist/web/assets/Readiness-BG1xmC09.js +0 -1
  118. package/dist/web/assets/Record-sFth-2I1.js +0 -1
  119. package/dist/web/assets/Regression-Dd4y8I1z.js +0 -5
  120. package/dist/web/assets/Requirements-DmhUNCIP.js +0 -2
  121. package/dist/web/assets/Responsive-D18eYdCh.js +0 -3
  122. package/dist/web/assets/TestManagement-DUMGdHDw.js +0 -4
  123. package/dist/web/assets/api-D8-lxyQi.js +0 -1
  124. package/dist/web/assets/frame-C8sL1yo-.js +0 -13
  125. package/dist/web/assets/index-BFG13fbg.js +0 -55
  126. package/dist/web/assets/index-DBnWgocz.css +0 -2
  127. package/dist/web/assets/line-icons-CwCZidXs.js +0 -1
  128. package/dist/web/assets/pageBack-BefA2rh7.js +0 -3
  129. package/dist/web/assets/parts-BNpm4gXC.js +0 -1
  130. package/dist/web/assets/qualityParts-DtsD70Qh.js +0 -1
  131. package/dist/web/assets/stepper-CONWT_tv.js +0 -1
  132. package/dist/web/assets/wizardParts-CulZqqjz.js +0 -1
@@ -0,0 +1,3204 @@
1
+ import { createRequire } from "node:module";
2
+ var __create = Object.create;
3
+ var __getProtoOf = Object.getPrototypeOf;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ function __accessProp(key) {
8
+ return this[key];
9
+ }
10
+ var __toESMCache_node;
11
+ var __toESMCache_esm;
12
+ var __toESM = (mod, isNodeMode, target) => {
13
+ var canCache = mod != null && typeof mod === "object";
14
+ if (canCache) {
15
+ var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
16
+ var cached = cache.get(mod);
17
+ if (cached)
18
+ return cached;
19
+ }
20
+ target = mod != null ? __create(__getProtoOf(mod)) : {};
21
+ const to = isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
22
+ if (mod && typeof mod === "object" || typeof mod === "function") {
23
+ for (let key of __getOwnPropNames(mod))
24
+ if (!__hasOwnProp.call(to, key))
25
+ __defProp(to, key, {
26
+ get: __accessProp.bind(mod, key),
27
+ enumerable: true
28
+ });
29
+ }
30
+ if (canCache)
31
+ cache.set(mod, to);
32
+ return to;
33
+ };
34
+ var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
35
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
36
+
37
+ // node_modules/pngjs/lib/chunkstream.js
38
+ var require_chunkstream = __commonJS(function(exports, module) {
39
+ var util = __require("util");
40
+ var Stream = __require("stream");
41
+ var ChunkStream = module.exports = function() {
42
+ Stream.call(this);
43
+ this._buffers = [];
44
+ this._buffered = 0;
45
+ this._reads = [];
46
+ this._paused = false;
47
+ this._encoding = "utf8";
48
+ this.writable = true;
49
+ };
50
+ util.inherits(ChunkStream, Stream);
51
+ ChunkStream.prototype.read = function(length, callback) {
52
+ this._reads.push({
53
+ length: Math.abs(length),
54
+ allowLess: length < 0,
55
+ func: callback
56
+ });
57
+ process.nextTick(function() {
58
+ this._process();
59
+ if (this._paused && this._reads && this._reads.length > 0) {
60
+ this._paused = false;
61
+ this.emit("drain");
62
+ }
63
+ }.bind(this));
64
+ };
65
+ ChunkStream.prototype.write = function(data, encoding) {
66
+ if (!this.writable) {
67
+ this.emit("error", new Error("Stream not writable"));
68
+ return false;
69
+ }
70
+ let dataBuffer;
71
+ if (Buffer.isBuffer(data)) {
72
+ dataBuffer = data;
73
+ } else {
74
+ dataBuffer = Buffer.from(data, encoding || this._encoding);
75
+ }
76
+ this._buffers.push(dataBuffer);
77
+ this._buffered += dataBuffer.length;
78
+ this._process();
79
+ if (this._reads && this._reads.length === 0) {
80
+ this._paused = true;
81
+ }
82
+ return this.writable && !this._paused;
83
+ };
84
+ ChunkStream.prototype.end = function(data, encoding) {
85
+ if (data) {
86
+ this.write(data, encoding);
87
+ }
88
+ this.writable = false;
89
+ if (!this._buffers) {
90
+ return;
91
+ }
92
+ if (this._buffers.length === 0) {
93
+ this._end();
94
+ } else {
95
+ this._buffers.push(null);
96
+ this._process();
97
+ }
98
+ };
99
+ ChunkStream.prototype.destroySoon = ChunkStream.prototype.end;
100
+ ChunkStream.prototype._end = function() {
101
+ if (this._reads.length > 0) {
102
+ this.emit("error", new Error("Unexpected end of input"));
103
+ }
104
+ this.destroy();
105
+ };
106
+ ChunkStream.prototype.destroy = function() {
107
+ if (!this._buffers) {
108
+ return;
109
+ }
110
+ this.writable = false;
111
+ this._reads = null;
112
+ this._buffers = null;
113
+ this.emit("close");
114
+ };
115
+ ChunkStream.prototype._processReadAllowingLess = function(read) {
116
+ this._reads.shift();
117
+ let smallerBuf = this._buffers[0];
118
+ if (smallerBuf.length > read.length) {
119
+ this._buffered -= read.length;
120
+ this._buffers[0] = smallerBuf.slice(read.length);
121
+ read.func.call(this, smallerBuf.slice(0, read.length));
122
+ } else {
123
+ this._buffered -= smallerBuf.length;
124
+ this._buffers.shift();
125
+ read.func.call(this, smallerBuf);
126
+ }
127
+ };
128
+ ChunkStream.prototype._processRead = function(read) {
129
+ this._reads.shift();
130
+ let pos = 0;
131
+ let count = 0;
132
+ let data = Buffer.alloc(read.length);
133
+ while (pos < read.length) {
134
+ let buf = this._buffers[count++];
135
+ let len = Math.min(buf.length, read.length - pos);
136
+ buf.copy(data, pos, 0, len);
137
+ pos += len;
138
+ if (len !== buf.length) {
139
+ this._buffers[--count] = buf.slice(len);
140
+ }
141
+ }
142
+ if (count > 0) {
143
+ this._buffers.splice(0, count);
144
+ }
145
+ this._buffered -= read.length;
146
+ read.func.call(this, data);
147
+ };
148
+ ChunkStream.prototype._process = function() {
149
+ try {
150
+ while (this._buffered > 0 && this._reads && this._reads.length > 0) {
151
+ let read = this._reads[0];
152
+ if (read.allowLess) {
153
+ this._processReadAllowingLess(read);
154
+ } else if (this._buffered >= read.length) {
155
+ this._processRead(read);
156
+ } else {
157
+ break;
158
+ }
159
+ }
160
+ if (this._buffers && !this.writable) {
161
+ this._end();
162
+ }
163
+ } catch (ex) {
164
+ this.emit("error", ex);
165
+ }
166
+ };
167
+ });
168
+
169
+ // node_modules/pngjs/lib/interlace.js
170
+ var require_interlace = __commonJS(function(exports) {
171
+ var imagePasses = [
172
+ {
173
+ x: [0],
174
+ y: [0]
175
+ },
176
+ {
177
+ x: [4],
178
+ y: [0]
179
+ },
180
+ {
181
+ x: [0, 4],
182
+ y: [4]
183
+ },
184
+ {
185
+ x: [2, 6],
186
+ y: [0, 4]
187
+ },
188
+ {
189
+ x: [0, 2, 4, 6],
190
+ y: [2, 6]
191
+ },
192
+ {
193
+ x: [1, 3, 5, 7],
194
+ y: [0, 2, 4, 6]
195
+ },
196
+ {
197
+ x: [0, 1, 2, 3, 4, 5, 6, 7],
198
+ y: [1, 3, 5, 7]
199
+ }
200
+ ];
201
+ exports.getImagePasses = function(width, height) {
202
+ let images = [];
203
+ let xLeftOver = width % 8;
204
+ let yLeftOver = height % 8;
205
+ let xRepeats = (width - xLeftOver) / 8;
206
+ let yRepeats = (height - yLeftOver) / 8;
207
+ for (let i = 0;i < imagePasses.length; i++) {
208
+ let pass = imagePasses[i];
209
+ let passWidth = xRepeats * pass.x.length;
210
+ let passHeight = yRepeats * pass.y.length;
211
+ for (let j = 0;j < pass.x.length; j++) {
212
+ if (pass.x[j] < xLeftOver) {
213
+ passWidth++;
214
+ } else {
215
+ break;
216
+ }
217
+ }
218
+ for (let j = 0;j < pass.y.length; j++) {
219
+ if (pass.y[j] < yLeftOver) {
220
+ passHeight++;
221
+ } else {
222
+ break;
223
+ }
224
+ }
225
+ if (passWidth > 0 && passHeight > 0) {
226
+ images.push({ width: passWidth, height: passHeight, index: i });
227
+ }
228
+ }
229
+ return images;
230
+ };
231
+ exports.getInterlaceIterator = function(width) {
232
+ return function(x, y, pass) {
233
+ let outerXLeftOver = x % imagePasses[pass].x.length;
234
+ let outerX = (x - outerXLeftOver) / imagePasses[pass].x.length * 8 + imagePasses[pass].x[outerXLeftOver];
235
+ let outerYLeftOver = y % imagePasses[pass].y.length;
236
+ let outerY = (y - outerYLeftOver) / imagePasses[pass].y.length * 8 + imagePasses[pass].y[outerYLeftOver];
237
+ return outerX * 4 + outerY * width * 4;
238
+ };
239
+ };
240
+ });
241
+
242
+ // node_modules/pngjs/lib/paeth-predictor.js
243
+ var require_paeth_predictor = __commonJS(function(exports, module) {
244
+ module.exports = function paethPredictor(left, above, upLeft) {
245
+ let paeth = left + above - upLeft;
246
+ let pLeft = Math.abs(paeth - left);
247
+ let pAbove = Math.abs(paeth - above);
248
+ let pUpLeft = Math.abs(paeth - upLeft);
249
+ if (pLeft <= pAbove && pLeft <= pUpLeft) {
250
+ return left;
251
+ }
252
+ if (pAbove <= pUpLeft) {
253
+ return above;
254
+ }
255
+ return upLeft;
256
+ };
257
+ });
258
+
259
+ // node_modules/pngjs/lib/filter-parse.js
260
+ var require_filter_parse = __commonJS(function(exports, module) {
261
+ var interlaceUtils = require_interlace();
262
+ var paethPredictor = require_paeth_predictor();
263
+ function getByteWidth(width, bpp, depth) {
264
+ let byteWidth = width * bpp;
265
+ if (depth !== 8) {
266
+ byteWidth = Math.ceil(byteWidth / (8 / depth));
267
+ }
268
+ return byteWidth;
269
+ }
270
+ var Filter = module.exports = function(bitmapInfo, dependencies) {
271
+ let width = bitmapInfo.width;
272
+ let height = bitmapInfo.height;
273
+ let interlace = bitmapInfo.interlace;
274
+ let bpp = bitmapInfo.bpp;
275
+ let depth = bitmapInfo.depth;
276
+ this.read = dependencies.read;
277
+ this.write = dependencies.write;
278
+ this.complete = dependencies.complete;
279
+ this._imageIndex = 0;
280
+ this._images = [];
281
+ if (interlace) {
282
+ let passes = interlaceUtils.getImagePasses(width, height);
283
+ for (let i = 0;i < passes.length; i++) {
284
+ this._images.push({
285
+ byteWidth: getByteWidth(passes[i].width, bpp, depth),
286
+ height: passes[i].height,
287
+ lineIndex: 0
288
+ });
289
+ }
290
+ } else {
291
+ this._images.push({
292
+ byteWidth: getByteWidth(width, bpp, depth),
293
+ height,
294
+ lineIndex: 0
295
+ });
296
+ }
297
+ if (depth === 8) {
298
+ this._xComparison = bpp;
299
+ } else if (depth === 16) {
300
+ this._xComparison = bpp * 2;
301
+ } else {
302
+ this._xComparison = 1;
303
+ }
304
+ };
305
+ Filter.prototype.start = function() {
306
+ this.read(this._images[this._imageIndex].byteWidth + 1, this._reverseFilterLine.bind(this));
307
+ };
308
+ Filter.prototype._unFilterType1 = function(rawData, unfilteredLine, byteWidth) {
309
+ let xComparison = this._xComparison;
310
+ let xBiggerThan = xComparison - 1;
311
+ for (let x = 0;x < byteWidth; x++) {
312
+ let rawByte = rawData[1 + x];
313
+ let f1Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
314
+ unfilteredLine[x] = rawByte + f1Left;
315
+ }
316
+ };
317
+ Filter.prototype._unFilterType2 = function(rawData, unfilteredLine, byteWidth) {
318
+ let lastLine = this._lastLine;
319
+ for (let x = 0;x < byteWidth; x++) {
320
+ let rawByte = rawData[1 + x];
321
+ let f2Up = lastLine ? lastLine[x] : 0;
322
+ unfilteredLine[x] = rawByte + f2Up;
323
+ }
324
+ };
325
+ Filter.prototype._unFilterType3 = function(rawData, unfilteredLine, byteWidth) {
326
+ let xComparison = this._xComparison;
327
+ let xBiggerThan = xComparison - 1;
328
+ let lastLine = this._lastLine;
329
+ for (let x = 0;x < byteWidth; x++) {
330
+ let rawByte = rawData[1 + x];
331
+ let f3Up = lastLine ? lastLine[x] : 0;
332
+ let f3Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
333
+ let f3Add = Math.floor((f3Left + f3Up) / 2);
334
+ unfilteredLine[x] = rawByte + f3Add;
335
+ }
336
+ };
337
+ Filter.prototype._unFilterType4 = function(rawData, unfilteredLine, byteWidth) {
338
+ let xComparison = this._xComparison;
339
+ let xBiggerThan = xComparison - 1;
340
+ let lastLine = this._lastLine;
341
+ for (let x = 0;x < byteWidth; x++) {
342
+ let rawByte = rawData[1 + x];
343
+ let f4Up = lastLine ? lastLine[x] : 0;
344
+ let f4Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
345
+ let f4UpLeft = x > xBiggerThan && lastLine ? lastLine[x - xComparison] : 0;
346
+ let f4Add = paethPredictor(f4Left, f4Up, f4UpLeft);
347
+ unfilteredLine[x] = rawByte + f4Add;
348
+ }
349
+ };
350
+ Filter.prototype._reverseFilterLine = function(rawData) {
351
+ let filter = rawData[0];
352
+ let unfilteredLine;
353
+ let currentImage = this._images[this._imageIndex];
354
+ let byteWidth = currentImage.byteWidth;
355
+ if (filter === 0) {
356
+ unfilteredLine = rawData.slice(1, byteWidth + 1);
357
+ } else {
358
+ unfilteredLine = Buffer.alloc(byteWidth);
359
+ switch (filter) {
360
+ case 1:
361
+ this._unFilterType1(rawData, unfilteredLine, byteWidth);
362
+ break;
363
+ case 2:
364
+ this._unFilterType2(rawData, unfilteredLine, byteWidth);
365
+ break;
366
+ case 3:
367
+ this._unFilterType3(rawData, unfilteredLine, byteWidth);
368
+ break;
369
+ case 4:
370
+ this._unFilterType4(rawData, unfilteredLine, byteWidth);
371
+ break;
372
+ default:
373
+ throw new Error("Unrecognised filter type - " + filter);
374
+ }
375
+ }
376
+ this.write(unfilteredLine);
377
+ currentImage.lineIndex++;
378
+ if (currentImage.lineIndex >= currentImage.height) {
379
+ this._lastLine = null;
380
+ this._imageIndex++;
381
+ currentImage = this._images[this._imageIndex];
382
+ } else {
383
+ this._lastLine = unfilteredLine;
384
+ }
385
+ if (currentImage) {
386
+ this.read(currentImage.byteWidth + 1, this._reverseFilterLine.bind(this));
387
+ } else {
388
+ this._lastLine = null;
389
+ this.complete();
390
+ }
391
+ };
392
+ });
393
+
394
+ // node_modules/pngjs/lib/filter-parse-async.js
395
+ var require_filter_parse_async = __commonJS(function(exports, module) {
396
+ var util = __require("util");
397
+ var ChunkStream = require_chunkstream();
398
+ var Filter = require_filter_parse();
399
+ var FilterAsync = module.exports = function(bitmapInfo) {
400
+ ChunkStream.call(this);
401
+ let buffers = [];
402
+ let that = this;
403
+ this._filter = new Filter(bitmapInfo, {
404
+ read: this.read.bind(this),
405
+ write: function(buffer) {
406
+ buffers.push(buffer);
407
+ },
408
+ complete: function() {
409
+ that.emit("complete", Buffer.concat(buffers));
410
+ }
411
+ });
412
+ this._filter.start();
413
+ };
414
+ util.inherits(FilterAsync, ChunkStream);
415
+ });
416
+
417
+ // node_modules/pngjs/lib/constants.js
418
+ var require_constants = __commonJS(function(exports, module) {
419
+ module.exports = {
420
+ PNG_SIGNATURE: [137, 80, 78, 71, 13, 10, 26, 10],
421
+ TYPE_IHDR: 1229472850,
422
+ TYPE_IEND: 1229278788,
423
+ TYPE_IDAT: 1229209940,
424
+ TYPE_PLTE: 1347179589,
425
+ TYPE_tRNS: 1951551059,
426
+ TYPE_gAMA: 1732332865,
427
+ COLORTYPE_GRAYSCALE: 0,
428
+ COLORTYPE_PALETTE: 1,
429
+ COLORTYPE_COLOR: 2,
430
+ COLORTYPE_ALPHA: 4,
431
+ COLORTYPE_PALETTE_COLOR: 3,
432
+ COLORTYPE_COLOR_ALPHA: 6,
433
+ COLORTYPE_TO_BPP_MAP: {
434
+ 0: 1,
435
+ 2: 3,
436
+ 3: 1,
437
+ 4: 2,
438
+ 6: 4
439
+ },
440
+ GAMMA_DIVISION: 1e5
441
+ };
442
+ });
443
+
444
+ // node_modules/pngjs/lib/crc.js
445
+ var require_crc = __commonJS(function(exports, module) {
446
+ var crcTable = [];
447
+ (function() {
448
+ for (let i = 0;i < 256; i++) {
449
+ let currentCrc = i;
450
+ for (let j = 0;j < 8; j++) {
451
+ if (currentCrc & 1) {
452
+ currentCrc = 3988292384 ^ currentCrc >>> 1;
453
+ } else {
454
+ currentCrc = currentCrc >>> 1;
455
+ }
456
+ }
457
+ crcTable[i] = currentCrc;
458
+ }
459
+ })();
460
+ var CrcCalculator = module.exports = function() {
461
+ this._crc = -1;
462
+ };
463
+ CrcCalculator.prototype.write = function(data) {
464
+ for (let i = 0;i < data.length; i++) {
465
+ this._crc = crcTable[(this._crc ^ data[i]) & 255] ^ this._crc >>> 8;
466
+ }
467
+ return true;
468
+ };
469
+ CrcCalculator.prototype.crc32 = function() {
470
+ return this._crc ^ -1;
471
+ };
472
+ CrcCalculator.crc32 = function(buf) {
473
+ let crc = -1;
474
+ for (let i = 0;i < buf.length; i++) {
475
+ crc = crcTable[(crc ^ buf[i]) & 255] ^ crc >>> 8;
476
+ }
477
+ return crc ^ -1;
478
+ };
479
+ });
480
+
481
+ // node_modules/pngjs/lib/parser.js
482
+ var require_parser = __commonJS(function(exports, module) {
483
+ var constants = require_constants();
484
+ var CrcCalculator = require_crc();
485
+ var Parser = module.exports = function(options, dependencies) {
486
+ this._options = options;
487
+ options.checkCRC = options.checkCRC !== false;
488
+ this._hasIHDR = false;
489
+ this._hasIEND = false;
490
+ this._emittedHeadersFinished = false;
491
+ this._palette = [];
492
+ this._colorType = 0;
493
+ this._chunks = {};
494
+ this._chunks[constants.TYPE_IHDR] = this._handleIHDR.bind(this);
495
+ this._chunks[constants.TYPE_IEND] = this._handleIEND.bind(this);
496
+ this._chunks[constants.TYPE_IDAT] = this._handleIDAT.bind(this);
497
+ this._chunks[constants.TYPE_PLTE] = this._handlePLTE.bind(this);
498
+ this._chunks[constants.TYPE_tRNS] = this._handleTRNS.bind(this);
499
+ this._chunks[constants.TYPE_gAMA] = this._handleGAMA.bind(this);
500
+ this.read = dependencies.read;
501
+ this.error = dependencies.error;
502
+ this.metadata = dependencies.metadata;
503
+ this.gamma = dependencies.gamma;
504
+ this.transColor = dependencies.transColor;
505
+ this.palette = dependencies.palette;
506
+ this.parsed = dependencies.parsed;
507
+ this.inflateData = dependencies.inflateData;
508
+ this.finished = dependencies.finished;
509
+ this.simpleTransparency = dependencies.simpleTransparency;
510
+ this.headersFinished = dependencies.headersFinished || function() {};
511
+ };
512
+ Parser.prototype.start = function() {
513
+ this.read(constants.PNG_SIGNATURE.length, this._parseSignature.bind(this));
514
+ };
515
+ Parser.prototype._parseSignature = function(data) {
516
+ let signature = constants.PNG_SIGNATURE;
517
+ for (let i = 0;i < signature.length; i++) {
518
+ if (data[i] !== signature[i]) {
519
+ this.error(new Error("Invalid file signature"));
520
+ return;
521
+ }
522
+ }
523
+ this.read(8, this._parseChunkBegin.bind(this));
524
+ };
525
+ Parser.prototype._parseChunkBegin = function(data) {
526
+ let length = data.readUInt32BE(0);
527
+ let type = data.readUInt32BE(4);
528
+ let name = "";
529
+ for (let i = 4;i < 8; i++) {
530
+ name += String.fromCharCode(data[i]);
531
+ }
532
+ let ancillary = Boolean(data[4] & 32);
533
+ if (!this._hasIHDR && type !== constants.TYPE_IHDR) {
534
+ this.error(new Error("Expected IHDR on beggining"));
535
+ return;
536
+ }
537
+ this._crc = new CrcCalculator;
538
+ this._crc.write(Buffer.from(name));
539
+ if (this._chunks[type]) {
540
+ return this._chunks[type](length);
541
+ }
542
+ if (!ancillary) {
543
+ this.error(new Error("Unsupported critical chunk type " + name));
544
+ return;
545
+ }
546
+ this.read(length + 4, this._skipChunk.bind(this));
547
+ };
548
+ Parser.prototype._skipChunk = function() {
549
+ this.read(8, this._parseChunkBegin.bind(this));
550
+ };
551
+ Parser.prototype._handleChunkEnd = function() {
552
+ this.read(4, this._parseChunkEnd.bind(this));
553
+ };
554
+ Parser.prototype._parseChunkEnd = function(data) {
555
+ let fileCrc = data.readInt32BE(0);
556
+ let calcCrc = this._crc.crc32();
557
+ if (this._options.checkCRC && calcCrc !== fileCrc) {
558
+ this.error(new Error("Crc error - " + fileCrc + " - " + calcCrc));
559
+ return;
560
+ }
561
+ if (!this._hasIEND) {
562
+ this.read(8, this._parseChunkBegin.bind(this));
563
+ }
564
+ };
565
+ Parser.prototype._handleIHDR = function(length) {
566
+ this.read(length, this._parseIHDR.bind(this));
567
+ };
568
+ Parser.prototype._parseIHDR = function(data) {
569
+ this._crc.write(data);
570
+ let width = data.readUInt32BE(0);
571
+ let height = data.readUInt32BE(4);
572
+ let depth = data[8];
573
+ let colorType = data[9];
574
+ let compr = data[10];
575
+ let filter = data[11];
576
+ let interlace = data[12];
577
+ if (depth !== 8 && depth !== 4 && depth !== 2 && depth !== 1 && depth !== 16) {
578
+ this.error(new Error("Unsupported bit depth " + depth));
579
+ return;
580
+ }
581
+ if (!(colorType in constants.COLORTYPE_TO_BPP_MAP)) {
582
+ this.error(new Error("Unsupported color type"));
583
+ return;
584
+ }
585
+ if (compr !== 0) {
586
+ this.error(new Error("Unsupported compression method"));
587
+ return;
588
+ }
589
+ if (filter !== 0) {
590
+ this.error(new Error("Unsupported filter method"));
591
+ return;
592
+ }
593
+ if (interlace !== 0 && interlace !== 1) {
594
+ this.error(new Error("Unsupported interlace method"));
595
+ return;
596
+ }
597
+ this._colorType = colorType;
598
+ let bpp = constants.COLORTYPE_TO_BPP_MAP[this._colorType];
599
+ this._hasIHDR = true;
600
+ this.metadata({
601
+ width,
602
+ height,
603
+ depth,
604
+ interlace: Boolean(interlace),
605
+ palette: Boolean(colorType & constants.COLORTYPE_PALETTE),
606
+ color: Boolean(colorType & constants.COLORTYPE_COLOR),
607
+ alpha: Boolean(colorType & constants.COLORTYPE_ALPHA),
608
+ bpp,
609
+ colorType
610
+ });
611
+ this._handleChunkEnd();
612
+ };
613
+ Parser.prototype._handlePLTE = function(length) {
614
+ this.read(length, this._parsePLTE.bind(this));
615
+ };
616
+ Parser.prototype._parsePLTE = function(data) {
617
+ this._crc.write(data);
618
+ let entries = Math.floor(data.length / 3);
619
+ for (let i = 0;i < entries; i++) {
620
+ this._palette.push([data[i * 3], data[i * 3 + 1], data[i * 3 + 2], 255]);
621
+ }
622
+ this.palette(this._palette);
623
+ this._handleChunkEnd();
624
+ };
625
+ Parser.prototype._handleTRNS = function(length) {
626
+ this.simpleTransparency();
627
+ this.read(length, this._parseTRNS.bind(this));
628
+ };
629
+ Parser.prototype._parseTRNS = function(data) {
630
+ this._crc.write(data);
631
+ if (this._colorType === constants.COLORTYPE_PALETTE_COLOR) {
632
+ if (this._palette.length === 0) {
633
+ this.error(new Error("Transparency chunk must be after palette"));
634
+ return;
635
+ }
636
+ if (data.length > this._palette.length) {
637
+ this.error(new Error("More transparent colors than palette size"));
638
+ return;
639
+ }
640
+ for (let i = 0;i < data.length; i++) {
641
+ this._palette[i][3] = data[i];
642
+ }
643
+ this.palette(this._palette);
644
+ }
645
+ if (this._colorType === constants.COLORTYPE_GRAYSCALE) {
646
+ this.transColor([data.readUInt16BE(0)]);
647
+ }
648
+ if (this._colorType === constants.COLORTYPE_COLOR) {
649
+ this.transColor([
650
+ data.readUInt16BE(0),
651
+ data.readUInt16BE(2),
652
+ data.readUInt16BE(4)
653
+ ]);
654
+ }
655
+ this._handleChunkEnd();
656
+ };
657
+ Parser.prototype._handleGAMA = function(length) {
658
+ this.read(length, this._parseGAMA.bind(this));
659
+ };
660
+ Parser.prototype._parseGAMA = function(data) {
661
+ this._crc.write(data);
662
+ this.gamma(data.readUInt32BE(0) / constants.GAMMA_DIVISION);
663
+ this._handleChunkEnd();
664
+ };
665
+ Parser.prototype._handleIDAT = function(length) {
666
+ if (!this._emittedHeadersFinished) {
667
+ this._emittedHeadersFinished = true;
668
+ this.headersFinished();
669
+ }
670
+ this.read(-length, this._parseIDAT.bind(this, length));
671
+ };
672
+ Parser.prototype._parseIDAT = function(length, data) {
673
+ this._crc.write(data);
674
+ if (this._colorType === constants.COLORTYPE_PALETTE_COLOR && this._palette.length === 0) {
675
+ throw new Error("Expected palette not found");
676
+ }
677
+ this.inflateData(data);
678
+ let leftOverLength = length - data.length;
679
+ if (leftOverLength > 0) {
680
+ this._handleIDAT(leftOverLength);
681
+ } else {
682
+ this._handleChunkEnd();
683
+ }
684
+ };
685
+ Parser.prototype._handleIEND = function(length) {
686
+ this.read(length, this._parseIEND.bind(this));
687
+ };
688
+ Parser.prototype._parseIEND = function(data) {
689
+ this._crc.write(data);
690
+ this._hasIEND = true;
691
+ this._handleChunkEnd();
692
+ if (this.finished) {
693
+ this.finished();
694
+ }
695
+ };
696
+ });
697
+
698
+ // node_modules/pngjs/lib/bitmapper.js
699
+ var require_bitmapper = __commonJS(function(exports) {
700
+ var interlaceUtils = require_interlace();
701
+ var pixelBppMapper = [
702
+ function() {},
703
+ function(pxData, data, pxPos, rawPos) {
704
+ if (rawPos === data.length) {
705
+ throw new Error("Ran out of data");
706
+ }
707
+ let pixel = data[rawPos];
708
+ pxData[pxPos] = pixel;
709
+ pxData[pxPos + 1] = pixel;
710
+ pxData[pxPos + 2] = pixel;
711
+ pxData[pxPos + 3] = 255;
712
+ },
713
+ function(pxData, data, pxPos, rawPos) {
714
+ if (rawPos + 1 >= data.length) {
715
+ throw new Error("Ran out of data");
716
+ }
717
+ let pixel = data[rawPos];
718
+ pxData[pxPos] = pixel;
719
+ pxData[pxPos + 1] = pixel;
720
+ pxData[pxPos + 2] = pixel;
721
+ pxData[pxPos + 3] = data[rawPos + 1];
722
+ },
723
+ function(pxData, data, pxPos, rawPos) {
724
+ if (rawPos + 2 >= data.length) {
725
+ throw new Error("Ran out of data");
726
+ }
727
+ pxData[pxPos] = data[rawPos];
728
+ pxData[pxPos + 1] = data[rawPos + 1];
729
+ pxData[pxPos + 2] = data[rawPos + 2];
730
+ pxData[pxPos + 3] = 255;
731
+ },
732
+ function(pxData, data, pxPos, rawPos) {
733
+ if (rawPos + 3 >= data.length) {
734
+ throw new Error("Ran out of data");
735
+ }
736
+ pxData[pxPos] = data[rawPos];
737
+ pxData[pxPos + 1] = data[rawPos + 1];
738
+ pxData[pxPos + 2] = data[rawPos + 2];
739
+ pxData[pxPos + 3] = data[rawPos + 3];
740
+ }
741
+ ];
742
+ var pixelBppCustomMapper = [
743
+ function() {},
744
+ function(pxData, pixelData, pxPos, maxBit) {
745
+ let pixel = pixelData[0];
746
+ pxData[pxPos] = pixel;
747
+ pxData[pxPos + 1] = pixel;
748
+ pxData[pxPos + 2] = pixel;
749
+ pxData[pxPos + 3] = maxBit;
750
+ },
751
+ function(pxData, pixelData, pxPos) {
752
+ let pixel = pixelData[0];
753
+ pxData[pxPos] = pixel;
754
+ pxData[pxPos + 1] = pixel;
755
+ pxData[pxPos + 2] = pixel;
756
+ pxData[pxPos + 3] = pixelData[1];
757
+ },
758
+ function(pxData, pixelData, pxPos, maxBit) {
759
+ pxData[pxPos] = pixelData[0];
760
+ pxData[pxPos + 1] = pixelData[1];
761
+ pxData[pxPos + 2] = pixelData[2];
762
+ pxData[pxPos + 3] = maxBit;
763
+ },
764
+ function(pxData, pixelData, pxPos) {
765
+ pxData[pxPos] = pixelData[0];
766
+ pxData[pxPos + 1] = pixelData[1];
767
+ pxData[pxPos + 2] = pixelData[2];
768
+ pxData[pxPos + 3] = pixelData[3];
769
+ }
770
+ ];
771
+ function bitRetriever(data, depth) {
772
+ let leftOver = [];
773
+ let i = 0;
774
+ function split() {
775
+ if (i === data.length) {
776
+ throw new Error("Ran out of data");
777
+ }
778
+ let byte = data[i];
779
+ i++;
780
+ let byte8, byte7, byte6, byte5, byte4, byte3, byte2, byte1;
781
+ switch (depth) {
782
+ default:
783
+ throw new Error("unrecognised depth");
784
+ case 16:
785
+ byte2 = data[i];
786
+ i++;
787
+ leftOver.push((byte << 8) + byte2);
788
+ break;
789
+ case 4:
790
+ byte2 = byte & 15;
791
+ byte1 = byte >> 4;
792
+ leftOver.push(byte1, byte2);
793
+ break;
794
+ case 2:
795
+ byte4 = byte & 3;
796
+ byte3 = byte >> 2 & 3;
797
+ byte2 = byte >> 4 & 3;
798
+ byte1 = byte >> 6 & 3;
799
+ leftOver.push(byte1, byte2, byte3, byte4);
800
+ break;
801
+ case 1:
802
+ byte8 = byte & 1;
803
+ byte7 = byte >> 1 & 1;
804
+ byte6 = byte >> 2 & 1;
805
+ byte5 = byte >> 3 & 1;
806
+ byte4 = byte >> 4 & 1;
807
+ byte3 = byte >> 5 & 1;
808
+ byte2 = byte >> 6 & 1;
809
+ byte1 = byte >> 7 & 1;
810
+ leftOver.push(byte1, byte2, byte3, byte4, byte5, byte6, byte7, byte8);
811
+ break;
812
+ }
813
+ }
814
+ return {
815
+ get: function(count) {
816
+ while (leftOver.length < count) {
817
+ split();
818
+ }
819
+ let returner = leftOver.slice(0, count);
820
+ leftOver = leftOver.slice(count);
821
+ return returner;
822
+ },
823
+ resetAfterLine: function() {
824
+ leftOver.length = 0;
825
+ },
826
+ end: function() {
827
+ if (i !== data.length) {
828
+ throw new Error("extra data found");
829
+ }
830
+ }
831
+ };
832
+ }
833
+ function mapImage8Bit(image, pxData, getPxPos, bpp, data, rawPos) {
834
+ let imageWidth = image.width;
835
+ let imageHeight = image.height;
836
+ let imagePass = image.index;
837
+ for (let y = 0;y < imageHeight; y++) {
838
+ for (let x = 0;x < imageWidth; x++) {
839
+ let pxPos = getPxPos(x, y, imagePass);
840
+ pixelBppMapper[bpp](pxData, data, pxPos, rawPos);
841
+ rawPos += bpp;
842
+ }
843
+ }
844
+ return rawPos;
845
+ }
846
+ function mapImageCustomBit(image, pxData, getPxPos, bpp, bits, maxBit) {
847
+ let imageWidth = image.width;
848
+ let imageHeight = image.height;
849
+ let imagePass = image.index;
850
+ for (let y = 0;y < imageHeight; y++) {
851
+ for (let x = 0;x < imageWidth; x++) {
852
+ let pixelData = bits.get(bpp);
853
+ let pxPos = getPxPos(x, y, imagePass);
854
+ pixelBppCustomMapper[bpp](pxData, pixelData, pxPos, maxBit);
855
+ }
856
+ bits.resetAfterLine();
857
+ }
858
+ }
859
+ exports.dataToBitMap = function(data, bitmapInfo) {
860
+ let width = bitmapInfo.width;
861
+ let height = bitmapInfo.height;
862
+ let depth = bitmapInfo.depth;
863
+ let bpp = bitmapInfo.bpp;
864
+ let interlace = bitmapInfo.interlace;
865
+ let bits;
866
+ if (depth !== 8) {
867
+ bits = bitRetriever(data, depth);
868
+ }
869
+ let pxData;
870
+ if (depth <= 8) {
871
+ pxData = Buffer.alloc(width * height * 4);
872
+ } else {
873
+ pxData = new Uint16Array(width * height * 4);
874
+ }
875
+ let maxBit = Math.pow(2, depth) - 1;
876
+ let rawPos = 0;
877
+ let images;
878
+ let getPxPos;
879
+ if (interlace) {
880
+ images = interlaceUtils.getImagePasses(width, height);
881
+ getPxPos = interlaceUtils.getInterlaceIterator(width, height);
882
+ } else {
883
+ let nonInterlacedPxPos = 0;
884
+ getPxPos = function() {
885
+ let returner = nonInterlacedPxPos;
886
+ nonInterlacedPxPos += 4;
887
+ return returner;
888
+ };
889
+ images = [{ width, height }];
890
+ }
891
+ for (let imageIndex = 0;imageIndex < images.length; imageIndex++) {
892
+ if (depth === 8) {
893
+ rawPos = mapImage8Bit(images[imageIndex], pxData, getPxPos, bpp, data, rawPos);
894
+ } else {
895
+ mapImageCustomBit(images[imageIndex], pxData, getPxPos, bpp, bits, maxBit);
896
+ }
897
+ }
898
+ if (depth === 8) {
899
+ if (rawPos !== data.length) {
900
+ throw new Error("extra data found");
901
+ }
902
+ } else {
903
+ bits.end();
904
+ }
905
+ return pxData;
906
+ };
907
+ });
908
+
909
+ // node_modules/pngjs/lib/format-normaliser.js
910
+ var require_format_normaliser = __commonJS(function(exports, module) {
911
+ function dePalette(indata, outdata, width, height, palette) {
912
+ let pxPos = 0;
913
+ for (let y = 0;y < height; y++) {
914
+ for (let x = 0;x < width; x++) {
915
+ let color = palette[indata[pxPos]];
916
+ if (!color) {
917
+ throw new Error("index " + indata[pxPos] + " not in palette");
918
+ }
919
+ for (let i = 0;i < 4; i++) {
920
+ outdata[pxPos + i] = color[i];
921
+ }
922
+ pxPos += 4;
923
+ }
924
+ }
925
+ }
926
+ function replaceTransparentColor(indata, outdata, width, height, transColor) {
927
+ let pxPos = 0;
928
+ for (let y = 0;y < height; y++) {
929
+ for (let x = 0;x < width; x++) {
930
+ let makeTrans = false;
931
+ if (transColor.length === 1) {
932
+ if (transColor[0] === indata[pxPos]) {
933
+ makeTrans = true;
934
+ }
935
+ } else if (transColor[0] === indata[pxPos] && transColor[1] === indata[pxPos + 1] && transColor[2] === indata[pxPos + 2]) {
936
+ makeTrans = true;
937
+ }
938
+ if (makeTrans) {
939
+ for (let i = 0;i < 4; i++) {
940
+ outdata[pxPos + i] = 0;
941
+ }
942
+ }
943
+ pxPos += 4;
944
+ }
945
+ }
946
+ }
947
+ function scaleDepth(indata, outdata, width, height, depth) {
948
+ let maxOutSample = 255;
949
+ let maxInSample = Math.pow(2, depth) - 1;
950
+ let pxPos = 0;
951
+ for (let y = 0;y < height; y++) {
952
+ for (let x = 0;x < width; x++) {
953
+ for (let i = 0;i < 4; i++) {
954
+ outdata[pxPos + i] = Math.floor(indata[pxPos + i] * maxOutSample / maxInSample + 0.5);
955
+ }
956
+ pxPos += 4;
957
+ }
958
+ }
959
+ }
960
+ module.exports = function(indata, imageData, skipRescale = false) {
961
+ let depth = imageData.depth;
962
+ let width = imageData.width;
963
+ let height = imageData.height;
964
+ let colorType = imageData.colorType;
965
+ let transColor = imageData.transColor;
966
+ let palette = imageData.palette;
967
+ let outdata = indata;
968
+ if (colorType === 3) {
969
+ dePalette(indata, outdata, width, height, palette);
970
+ } else {
971
+ if (transColor) {
972
+ replaceTransparentColor(indata, outdata, width, height, transColor);
973
+ }
974
+ if (depth !== 8 && !skipRescale) {
975
+ if (depth === 16) {
976
+ outdata = Buffer.alloc(width * height * 4);
977
+ }
978
+ scaleDepth(indata, outdata, width, height, depth);
979
+ }
980
+ }
981
+ return outdata;
982
+ };
983
+ });
984
+
985
+ // node_modules/pngjs/lib/parser-async.js
986
+ var require_parser_async = __commonJS(function(exports, module) {
987
+ var util = __require("util");
988
+ var zlib = __require("zlib");
989
+ var ChunkStream = require_chunkstream();
990
+ var FilterAsync = require_filter_parse_async();
991
+ var Parser = require_parser();
992
+ var bitmapper = require_bitmapper();
993
+ var formatNormaliser = require_format_normaliser();
994
+ var ParserAsync = module.exports = function(options) {
995
+ ChunkStream.call(this);
996
+ this._parser = new Parser(options, {
997
+ read: this.read.bind(this),
998
+ error: this._handleError.bind(this),
999
+ metadata: this._handleMetaData.bind(this),
1000
+ gamma: this.emit.bind(this, "gamma"),
1001
+ palette: this._handlePalette.bind(this),
1002
+ transColor: this._handleTransColor.bind(this),
1003
+ finished: this._finished.bind(this),
1004
+ inflateData: this._inflateData.bind(this),
1005
+ simpleTransparency: this._simpleTransparency.bind(this),
1006
+ headersFinished: this._headersFinished.bind(this)
1007
+ });
1008
+ this._options = options;
1009
+ this.writable = true;
1010
+ this._parser.start();
1011
+ };
1012
+ util.inherits(ParserAsync, ChunkStream);
1013
+ ParserAsync.prototype._handleError = function(err) {
1014
+ this.emit("error", err);
1015
+ this.writable = false;
1016
+ this.destroy();
1017
+ if (this._inflate && this._inflate.destroy) {
1018
+ this._inflate.destroy();
1019
+ }
1020
+ if (this._filter) {
1021
+ this._filter.destroy();
1022
+ this._filter.on("error", function() {});
1023
+ }
1024
+ this.errord = true;
1025
+ };
1026
+ ParserAsync.prototype._inflateData = function(data) {
1027
+ if (!this._inflate) {
1028
+ if (this._bitmapInfo.interlace) {
1029
+ this._inflate = zlib.createInflate();
1030
+ this._inflate.on("error", this.emit.bind(this, "error"));
1031
+ this._filter.on("complete", this._complete.bind(this));
1032
+ this._inflate.pipe(this._filter);
1033
+ } else {
1034
+ let rowSize = (this._bitmapInfo.width * this._bitmapInfo.bpp * this._bitmapInfo.depth + 7 >> 3) + 1;
1035
+ let imageSize = rowSize * this._bitmapInfo.height;
1036
+ let chunkSize = Math.max(imageSize, zlib.Z_MIN_CHUNK);
1037
+ this._inflate = zlib.createInflate({ chunkSize });
1038
+ let leftToInflate = imageSize;
1039
+ let emitError = this.emit.bind(this, "error");
1040
+ this._inflate.on("error", function(err) {
1041
+ if (!leftToInflate) {
1042
+ return;
1043
+ }
1044
+ emitError(err);
1045
+ });
1046
+ this._filter.on("complete", this._complete.bind(this));
1047
+ let filterWrite = this._filter.write.bind(this._filter);
1048
+ this._inflate.on("data", function(chunk) {
1049
+ if (!leftToInflate) {
1050
+ return;
1051
+ }
1052
+ if (chunk.length > leftToInflate) {
1053
+ chunk = chunk.slice(0, leftToInflate);
1054
+ }
1055
+ leftToInflate -= chunk.length;
1056
+ filterWrite(chunk);
1057
+ });
1058
+ this._inflate.on("end", this._filter.end.bind(this._filter));
1059
+ }
1060
+ }
1061
+ this._inflate.write(data);
1062
+ };
1063
+ ParserAsync.prototype._handleMetaData = function(metaData) {
1064
+ this._metaData = metaData;
1065
+ this._bitmapInfo = Object.create(metaData);
1066
+ this._filter = new FilterAsync(this._bitmapInfo);
1067
+ };
1068
+ ParserAsync.prototype._handleTransColor = function(transColor) {
1069
+ this._bitmapInfo.transColor = transColor;
1070
+ };
1071
+ ParserAsync.prototype._handlePalette = function(palette) {
1072
+ this._bitmapInfo.palette = palette;
1073
+ };
1074
+ ParserAsync.prototype._simpleTransparency = function() {
1075
+ this._metaData.alpha = true;
1076
+ };
1077
+ ParserAsync.prototype._headersFinished = function() {
1078
+ this.emit("metadata", this._metaData);
1079
+ };
1080
+ ParserAsync.prototype._finished = function() {
1081
+ if (this.errord) {
1082
+ return;
1083
+ }
1084
+ if (!this._inflate) {
1085
+ this.emit("error", "No Inflate block");
1086
+ } else {
1087
+ this._inflate.end();
1088
+ }
1089
+ };
1090
+ ParserAsync.prototype._complete = function(filteredData) {
1091
+ if (this.errord) {
1092
+ return;
1093
+ }
1094
+ let normalisedBitmapData;
1095
+ try {
1096
+ let bitmapData = bitmapper.dataToBitMap(filteredData, this._bitmapInfo);
1097
+ normalisedBitmapData = formatNormaliser(bitmapData, this._bitmapInfo, this._options.skipRescale);
1098
+ bitmapData = null;
1099
+ } catch (ex) {
1100
+ this._handleError(ex);
1101
+ return;
1102
+ }
1103
+ this.emit("parsed", normalisedBitmapData);
1104
+ };
1105
+ });
1106
+
1107
+ // node_modules/pngjs/lib/bitpacker.js
1108
+ var require_bitpacker = __commonJS(function(exports, module) {
1109
+ var constants = require_constants();
1110
+ module.exports = function(dataIn, width, height, options) {
1111
+ let outHasAlpha = [constants.COLORTYPE_COLOR_ALPHA, constants.COLORTYPE_ALPHA].indexOf(options.colorType) !== -1;
1112
+ if (options.colorType === options.inputColorType) {
1113
+ let bigEndian = function() {
1114
+ let buffer = new ArrayBuffer(2);
1115
+ new DataView(buffer).setInt16(0, 256, true);
1116
+ return new Int16Array(buffer)[0] !== 256;
1117
+ }();
1118
+ if (options.bitDepth === 8 || options.bitDepth === 16 && bigEndian) {
1119
+ return dataIn;
1120
+ }
1121
+ }
1122
+ let data = options.bitDepth !== 16 ? dataIn : new Uint16Array(dataIn.buffer);
1123
+ let maxValue = 255;
1124
+ let inBpp = constants.COLORTYPE_TO_BPP_MAP[options.inputColorType];
1125
+ if (inBpp === 4 && !options.inputHasAlpha) {
1126
+ inBpp = 3;
1127
+ }
1128
+ let outBpp = constants.COLORTYPE_TO_BPP_MAP[options.colorType];
1129
+ if (options.bitDepth === 16) {
1130
+ maxValue = 65535;
1131
+ outBpp *= 2;
1132
+ }
1133
+ let outData = Buffer.alloc(width * height * outBpp);
1134
+ let inIndex = 0;
1135
+ let outIndex = 0;
1136
+ let bgColor = options.bgColor || {};
1137
+ if (bgColor.red === undefined) {
1138
+ bgColor.red = maxValue;
1139
+ }
1140
+ if (bgColor.green === undefined) {
1141
+ bgColor.green = maxValue;
1142
+ }
1143
+ if (bgColor.blue === undefined) {
1144
+ bgColor.blue = maxValue;
1145
+ }
1146
+ function getRGBA() {
1147
+ let red;
1148
+ let green;
1149
+ let blue;
1150
+ let alpha = maxValue;
1151
+ switch (options.inputColorType) {
1152
+ case constants.COLORTYPE_COLOR_ALPHA:
1153
+ alpha = data[inIndex + 3];
1154
+ red = data[inIndex];
1155
+ green = data[inIndex + 1];
1156
+ blue = data[inIndex + 2];
1157
+ break;
1158
+ case constants.COLORTYPE_COLOR:
1159
+ red = data[inIndex];
1160
+ green = data[inIndex + 1];
1161
+ blue = data[inIndex + 2];
1162
+ break;
1163
+ case constants.COLORTYPE_ALPHA:
1164
+ alpha = data[inIndex + 1];
1165
+ red = data[inIndex];
1166
+ green = red;
1167
+ blue = red;
1168
+ break;
1169
+ case constants.COLORTYPE_GRAYSCALE:
1170
+ red = data[inIndex];
1171
+ green = red;
1172
+ blue = red;
1173
+ break;
1174
+ default:
1175
+ throw new Error("input color type:" + options.inputColorType + " is not supported at present");
1176
+ }
1177
+ if (options.inputHasAlpha) {
1178
+ if (!outHasAlpha) {
1179
+ alpha /= maxValue;
1180
+ red = Math.min(Math.max(Math.round((1 - alpha) * bgColor.red + alpha * red), 0), maxValue);
1181
+ green = Math.min(Math.max(Math.round((1 - alpha) * bgColor.green + alpha * green), 0), maxValue);
1182
+ blue = Math.min(Math.max(Math.round((1 - alpha) * bgColor.blue + alpha * blue), 0), maxValue);
1183
+ }
1184
+ }
1185
+ return { red, green, blue, alpha };
1186
+ }
1187
+ for (let y = 0;y < height; y++) {
1188
+ for (let x = 0;x < width; x++) {
1189
+ let rgba = getRGBA(data, inIndex);
1190
+ switch (options.colorType) {
1191
+ case constants.COLORTYPE_COLOR_ALPHA:
1192
+ case constants.COLORTYPE_COLOR:
1193
+ if (options.bitDepth === 8) {
1194
+ outData[outIndex] = rgba.red;
1195
+ outData[outIndex + 1] = rgba.green;
1196
+ outData[outIndex + 2] = rgba.blue;
1197
+ if (outHasAlpha) {
1198
+ outData[outIndex + 3] = rgba.alpha;
1199
+ }
1200
+ } else {
1201
+ outData.writeUInt16BE(rgba.red, outIndex);
1202
+ outData.writeUInt16BE(rgba.green, outIndex + 2);
1203
+ outData.writeUInt16BE(rgba.blue, outIndex + 4);
1204
+ if (outHasAlpha) {
1205
+ outData.writeUInt16BE(rgba.alpha, outIndex + 6);
1206
+ }
1207
+ }
1208
+ break;
1209
+ case constants.COLORTYPE_ALPHA:
1210
+ case constants.COLORTYPE_GRAYSCALE: {
1211
+ let grayscale = (rgba.red + rgba.green + rgba.blue) / 3;
1212
+ if (options.bitDepth === 8) {
1213
+ outData[outIndex] = grayscale;
1214
+ if (outHasAlpha) {
1215
+ outData[outIndex + 1] = rgba.alpha;
1216
+ }
1217
+ } else {
1218
+ outData.writeUInt16BE(grayscale, outIndex);
1219
+ if (outHasAlpha) {
1220
+ outData.writeUInt16BE(rgba.alpha, outIndex + 2);
1221
+ }
1222
+ }
1223
+ break;
1224
+ }
1225
+ default:
1226
+ throw new Error("unrecognised color Type " + options.colorType);
1227
+ }
1228
+ inIndex += inBpp;
1229
+ outIndex += outBpp;
1230
+ }
1231
+ }
1232
+ return outData;
1233
+ };
1234
+ });
1235
+
1236
+ // node_modules/pngjs/lib/filter-pack.js
1237
+ var require_filter_pack = __commonJS(function(exports, module) {
1238
+ var paethPredictor = require_paeth_predictor();
1239
+ function filterNone(pxData, pxPos, byteWidth, rawData, rawPos) {
1240
+ for (let x = 0;x < byteWidth; x++) {
1241
+ rawData[rawPos + x] = pxData[pxPos + x];
1242
+ }
1243
+ }
1244
+ function filterSumNone(pxData, pxPos, byteWidth) {
1245
+ let sum = 0;
1246
+ let length = pxPos + byteWidth;
1247
+ for (let i = pxPos;i < length; i++) {
1248
+ sum += Math.abs(pxData[i]);
1249
+ }
1250
+ return sum;
1251
+ }
1252
+ function filterSub(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
1253
+ for (let x = 0;x < byteWidth; x++) {
1254
+ let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1255
+ let val = pxData[pxPos + x] - left;
1256
+ rawData[rawPos + x] = val;
1257
+ }
1258
+ }
1259
+ function filterSumSub(pxData, pxPos, byteWidth, bpp) {
1260
+ let sum = 0;
1261
+ for (let x = 0;x < byteWidth; x++) {
1262
+ let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1263
+ let val = pxData[pxPos + x] - left;
1264
+ sum += Math.abs(val);
1265
+ }
1266
+ return sum;
1267
+ }
1268
+ function filterUp(pxData, pxPos, byteWidth, rawData, rawPos) {
1269
+ for (let x = 0;x < byteWidth; x++) {
1270
+ let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
1271
+ let val = pxData[pxPos + x] - up;
1272
+ rawData[rawPos + x] = val;
1273
+ }
1274
+ }
1275
+ function filterSumUp(pxData, pxPos, byteWidth) {
1276
+ let sum = 0;
1277
+ let length = pxPos + byteWidth;
1278
+ for (let x = pxPos;x < length; x++) {
1279
+ let up = pxPos > 0 ? pxData[x - byteWidth] : 0;
1280
+ let val = pxData[x] - up;
1281
+ sum += Math.abs(val);
1282
+ }
1283
+ return sum;
1284
+ }
1285
+ function filterAvg(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
1286
+ for (let x = 0;x < byteWidth; x++) {
1287
+ let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1288
+ let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
1289
+ let val = pxData[pxPos + x] - (left + up >> 1);
1290
+ rawData[rawPos + x] = val;
1291
+ }
1292
+ }
1293
+ function filterSumAvg(pxData, pxPos, byteWidth, bpp) {
1294
+ let sum = 0;
1295
+ for (let x = 0;x < byteWidth; x++) {
1296
+ let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1297
+ let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
1298
+ let val = pxData[pxPos + x] - (left + up >> 1);
1299
+ sum += Math.abs(val);
1300
+ }
1301
+ return sum;
1302
+ }
1303
+ function filterPaeth(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
1304
+ for (let x = 0;x < byteWidth; x++) {
1305
+ let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1306
+ let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
1307
+ let upleft = pxPos > 0 && x >= bpp ? pxData[pxPos + x - (byteWidth + bpp)] : 0;
1308
+ let val = pxData[pxPos + x] - paethPredictor(left, up, upleft);
1309
+ rawData[rawPos + x] = val;
1310
+ }
1311
+ }
1312
+ function filterSumPaeth(pxData, pxPos, byteWidth, bpp) {
1313
+ let sum = 0;
1314
+ for (let x = 0;x < byteWidth; x++) {
1315
+ let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1316
+ let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
1317
+ let upleft = pxPos > 0 && x >= bpp ? pxData[pxPos + x - (byteWidth + bpp)] : 0;
1318
+ let val = pxData[pxPos + x] - paethPredictor(left, up, upleft);
1319
+ sum += Math.abs(val);
1320
+ }
1321
+ return sum;
1322
+ }
1323
+ var filters = {
1324
+ 0: filterNone,
1325
+ 1: filterSub,
1326
+ 2: filterUp,
1327
+ 3: filterAvg,
1328
+ 4: filterPaeth
1329
+ };
1330
+ var filterSums = {
1331
+ 0: filterSumNone,
1332
+ 1: filterSumSub,
1333
+ 2: filterSumUp,
1334
+ 3: filterSumAvg,
1335
+ 4: filterSumPaeth
1336
+ };
1337
+ module.exports = function(pxData, width, height, options, bpp) {
1338
+ let filterTypes;
1339
+ if (!("filterType" in options) || options.filterType === -1) {
1340
+ filterTypes = [0, 1, 2, 3, 4];
1341
+ } else if (typeof options.filterType === "number") {
1342
+ filterTypes = [options.filterType];
1343
+ } else {
1344
+ throw new Error("unrecognised filter types");
1345
+ }
1346
+ if (options.bitDepth === 16) {
1347
+ bpp *= 2;
1348
+ }
1349
+ let byteWidth = width * bpp;
1350
+ let rawPos = 0;
1351
+ let pxPos = 0;
1352
+ let rawData = Buffer.alloc((byteWidth + 1) * height);
1353
+ let sel = filterTypes[0];
1354
+ for (let y = 0;y < height; y++) {
1355
+ if (filterTypes.length > 1) {
1356
+ let min = Infinity;
1357
+ for (let i = 0;i < filterTypes.length; i++) {
1358
+ let sum = filterSums[filterTypes[i]](pxData, pxPos, byteWidth, bpp);
1359
+ if (sum < min) {
1360
+ sel = filterTypes[i];
1361
+ min = sum;
1362
+ }
1363
+ }
1364
+ }
1365
+ rawData[rawPos] = sel;
1366
+ rawPos++;
1367
+ filters[sel](pxData, pxPos, byteWidth, rawData, rawPos, bpp);
1368
+ rawPos += byteWidth;
1369
+ pxPos += byteWidth;
1370
+ }
1371
+ return rawData;
1372
+ };
1373
+ });
1374
+
1375
+ // node_modules/pngjs/lib/packer.js
1376
+ var require_packer = __commonJS(function(exports, module) {
1377
+ var constants = require_constants();
1378
+ var CrcStream = require_crc();
1379
+ var bitPacker = require_bitpacker();
1380
+ var filter = require_filter_pack();
1381
+ var zlib = __require("zlib");
1382
+ var Packer = module.exports = function(options) {
1383
+ this._options = options;
1384
+ options.deflateChunkSize = options.deflateChunkSize || 32 * 1024;
1385
+ options.deflateLevel = options.deflateLevel != null ? options.deflateLevel : 9;
1386
+ options.deflateStrategy = options.deflateStrategy != null ? options.deflateStrategy : 3;
1387
+ options.inputHasAlpha = options.inputHasAlpha != null ? options.inputHasAlpha : true;
1388
+ options.deflateFactory = options.deflateFactory || zlib.createDeflate;
1389
+ options.bitDepth = options.bitDepth || 8;
1390
+ options.colorType = typeof options.colorType === "number" ? options.colorType : constants.COLORTYPE_COLOR_ALPHA;
1391
+ options.inputColorType = typeof options.inputColorType === "number" ? options.inputColorType : constants.COLORTYPE_COLOR_ALPHA;
1392
+ if ([
1393
+ constants.COLORTYPE_GRAYSCALE,
1394
+ constants.COLORTYPE_COLOR,
1395
+ constants.COLORTYPE_COLOR_ALPHA,
1396
+ constants.COLORTYPE_ALPHA
1397
+ ].indexOf(options.colorType) === -1) {
1398
+ throw new Error("option color type:" + options.colorType + " is not supported at present");
1399
+ }
1400
+ if ([
1401
+ constants.COLORTYPE_GRAYSCALE,
1402
+ constants.COLORTYPE_COLOR,
1403
+ constants.COLORTYPE_COLOR_ALPHA,
1404
+ constants.COLORTYPE_ALPHA
1405
+ ].indexOf(options.inputColorType) === -1) {
1406
+ throw new Error("option input color type:" + options.inputColorType + " is not supported at present");
1407
+ }
1408
+ if (options.bitDepth !== 8 && options.bitDepth !== 16) {
1409
+ throw new Error("option bit depth:" + options.bitDepth + " is not supported at present");
1410
+ }
1411
+ };
1412
+ Packer.prototype.getDeflateOptions = function() {
1413
+ return {
1414
+ chunkSize: this._options.deflateChunkSize,
1415
+ level: this._options.deflateLevel,
1416
+ strategy: this._options.deflateStrategy
1417
+ };
1418
+ };
1419
+ Packer.prototype.createDeflate = function() {
1420
+ return this._options.deflateFactory(this.getDeflateOptions());
1421
+ };
1422
+ Packer.prototype.filterData = function(data, width, height) {
1423
+ let packedData = bitPacker(data, width, height, this._options);
1424
+ let bpp = constants.COLORTYPE_TO_BPP_MAP[this._options.colorType];
1425
+ let filteredData = filter(packedData, width, height, this._options, bpp);
1426
+ return filteredData;
1427
+ };
1428
+ Packer.prototype._packChunk = function(type, data) {
1429
+ let len = data ? data.length : 0;
1430
+ let buf = Buffer.alloc(len + 12);
1431
+ buf.writeUInt32BE(len, 0);
1432
+ buf.writeUInt32BE(type, 4);
1433
+ if (data) {
1434
+ data.copy(buf, 8);
1435
+ }
1436
+ buf.writeInt32BE(CrcStream.crc32(buf.slice(4, buf.length - 4)), buf.length - 4);
1437
+ return buf;
1438
+ };
1439
+ Packer.prototype.packGAMA = function(gamma) {
1440
+ let buf = Buffer.alloc(4);
1441
+ buf.writeUInt32BE(Math.floor(gamma * constants.GAMMA_DIVISION), 0);
1442
+ return this._packChunk(constants.TYPE_gAMA, buf);
1443
+ };
1444
+ Packer.prototype.packIHDR = function(width, height) {
1445
+ let buf = Buffer.alloc(13);
1446
+ buf.writeUInt32BE(width, 0);
1447
+ buf.writeUInt32BE(height, 4);
1448
+ buf[8] = this._options.bitDepth;
1449
+ buf[9] = this._options.colorType;
1450
+ buf[10] = 0;
1451
+ buf[11] = 0;
1452
+ buf[12] = 0;
1453
+ return this._packChunk(constants.TYPE_IHDR, buf);
1454
+ };
1455
+ Packer.prototype.packIDAT = function(data) {
1456
+ return this._packChunk(constants.TYPE_IDAT, data);
1457
+ };
1458
+ Packer.prototype.packIEND = function() {
1459
+ return this._packChunk(constants.TYPE_IEND, null);
1460
+ };
1461
+ });
1462
+
1463
+ // node_modules/pngjs/lib/packer-async.js
1464
+ var require_packer_async = __commonJS(function(exports, module) {
1465
+ var util = __require("util");
1466
+ var Stream = __require("stream");
1467
+ var constants = require_constants();
1468
+ var Packer = require_packer();
1469
+ var PackerAsync = module.exports = function(opt) {
1470
+ Stream.call(this);
1471
+ let options = opt || {};
1472
+ this._packer = new Packer(options);
1473
+ this._deflate = this._packer.createDeflate();
1474
+ this.readable = true;
1475
+ };
1476
+ util.inherits(PackerAsync, Stream);
1477
+ PackerAsync.prototype.pack = function(data, width, height, gamma) {
1478
+ this.emit("data", Buffer.from(constants.PNG_SIGNATURE));
1479
+ this.emit("data", this._packer.packIHDR(width, height));
1480
+ if (gamma) {
1481
+ this.emit("data", this._packer.packGAMA(gamma));
1482
+ }
1483
+ let filteredData = this._packer.filterData(data, width, height);
1484
+ this._deflate.on("error", this.emit.bind(this, "error"));
1485
+ this._deflate.on("data", function(compressedData) {
1486
+ this.emit("data", this._packer.packIDAT(compressedData));
1487
+ }.bind(this));
1488
+ this._deflate.on("end", function() {
1489
+ this.emit("data", this._packer.packIEND());
1490
+ this.emit("end");
1491
+ }.bind(this));
1492
+ this._deflate.end(filteredData);
1493
+ };
1494
+ });
1495
+
1496
+ // node_modules/pngjs/lib/sync-inflate.js
1497
+ var require_sync_inflate = __commonJS(function(exports, module) {
1498
+ var assert = __require("assert").ok;
1499
+ var zlib = __require("zlib");
1500
+ var util = __require("util");
1501
+ var kMaxLength = __require("buffer").kMaxLength;
1502
+ function Inflate(opts) {
1503
+ if (!(this instanceof Inflate)) {
1504
+ return new Inflate(opts);
1505
+ }
1506
+ if (opts && opts.chunkSize < zlib.Z_MIN_CHUNK) {
1507
+ opts.chunkSize = zlib.Z_MIN_CHUNK;
1508
+ }
1509
+ zlib.Inflate.call(this, opts);
1510
+ this._offset = this._offset === undefined ? this._outOffset : this._offset;
1511
+ this._buffer = this._buffer || this._outBuffer;
1512
+ if (opts && opts.maxLength != null) {
1513
+ this._maxLength = opts.maxLength;
1514
+ }
1515
+ }
1516
+ function createInflate(opts) {
1517
+ return new Inflate(opts);
1518
+ }
1519
+ function _close(engine, callback) {
1520
+ if (callback) {
1521
+ process.nextTick(callback);
1522
+ }
1523
+ if (!engine._handle) {
1524
+ return;
1525
+ }
1526
+ engine._handle.close();
1527
+ engine._handle = null;
1528
+ }
1529
+ Inflate.prototype._processChunk = function(chunk, flushFlag, asyncCb) {
1530
+ if (typeof asyncCb === "function") {
1531
+ return zlib.Inflate._processChunk.call(this, chunk, flushFlag, asyncCb);
1532
+ }
1533
+ let self = this;
1534
+ let availInBefore = chunk && chunk.length;
1535
+ let availOutBefore = this._chunkSize - this._offset;
1536
+ let leftToInflate = this._maxLength;
1537
+ let inOff = 0;
1538
+ let buffers = [];
1539
+ let nread = 0;
1540
+ let error;
1541
+ this.on("error", function(err) {
1542
+ error = err;
1543
+ });
1544
+ function handleChunk(availInAfter, availOutAfter) {
1545
+ if (self._hadError) {
1546
+ return;
1547
+ }
1548
+ let have = availOutBefore - availOutAfter;
1549
+ assert(have >= 0, "have should not go down");
1550
+ if (have > 0) {
1551
+ let out = self._buffer.slice(self._offset, self._offset + have);
1552
+ self._offset += have;
1553
+ if (out.length > leftToInflate) {
1554
+ out = out.slice(0, leftToInflate);
1555
+ }
1556
+ buffers.push(out);
1557
+ nread += out.length;
1558
+ leftToInflate -= out.length;
1559
+ if (leftToInflate === 0) {
1560
+ return false;
1561
+ }
1562
+ }
1563
+ if (availOutAfter === 0 || self._offset >= self._chunkSize) {
1564
+ availOutBefore = self._chunkSize;
1565
+ self._offset = 0;
1566
+ self._buffer = Buffer.allocUnsafe(self._chunkSize);
1567
+ }
1568
+ if (availOutAfter === 0) {
1569
+ inOff += availInBefore - availInAfter;
1570
+ availInBefore = availInAfter;
1571
+ return true;
1572
+ }
1573
+ return false;
1574
+ }
1575
+ assert(this._handle, "zlib binding closed");
1576
+ let res;
1577
+ do {
1578
+ res = this._handle.writeSync(flushFlag, chunk, inOff, availInBefore, this._buffer, this._offset, availOutBefore);
1579
+ res = res || this._writeState;
1580
+ } while (!this._hadError && handleChunk(res[0], res[1]));
1581
+ if (this._hadError) {
1582
+ throw error;
1583
+ }
1584
+ if (nread >= kMaxLength) {
1585
+ _close(this);
1586
+ throw new RangeError("Cannot create final Buffer. It would be larger than 0x" + kMaxLength.toString(16) + " bytes");
1587
+ }
1588
+ let buf = Buffer.concat(buffers, nread);
1589
+ _close(this);
1590
+ return buf;
1591
+ };
1592
+ util.inherits(Inflate, zlib.Inflate);
1593
+ function zlibBufferSync(engine, buffer) {
1594
+ if (typeof buffer === "string") {
1595
+ buffer = Buffer.from(buffer);
1596
+ }
1597
+ if (!(buffer instanceof Buffer)) {
1598
+ throw new TypeError("Not a string or buffer");
1599
+ }
1600
+ let flushFlag = engine._finishFlushFlag;
1601
+ if (flushFlag == null) {
1602
+ flushFlag = zlib.Z_FINISH;
1603
+ }
1604
+ return engine._processChunk(buffer, flushFlag);
1605
+ }
1606
+ function inflateSync(buffer, opts) {
1607
+ return zlibBufferSync(new Inflate(opts), buffer);
1608
+ }
1609
+ module.exports = exports = inflateSync;
1610
+ exports.Inflate = Inflate;
1611
+ exports.createInflate = createInflate;
1612
+ exports.inflateSync = inflateSync;
1613
+ });
1614
+
1615
+ // node_modules/pngjs/lib/sync-reader.js
1616
+ var require_sync_reader = __commonJS(function(exports, module) {
1617
+ var SyncReader = module.exports = function(buffer) {
1618
+ this._buffer = buffer;
1619
+ this._reads = [];
1620
+ };
1621
+ SyncReader.prototype.read = function(length, callback) {
1622
+ this._reads.push({
1623
+ length: Math.abs(length),
1624
+ allowLess: length < 0,
1625
+ func: callback
1626
+ });
1627
+ };
1628
+ SyncReader.prototype.process = function() {
1629
+ while (this._reads.length > 0 && this._buffer.length) {
1630
+ let read = this._reads[0];
1631
+ if (this._buffer.length && (this._buffer.length >= read.length || read.allowLess)) {
1632
+ this._reads.shift();
1633
+ let buf = this._buffer;
1634
+ this._buffer = buf.slice(read.length);
1635
+ read.func.call(this, buf.slice(0, read.length));
1636
+ } else {
1637
+ break;
1638
+ }
1639
+ }
1640
+ if (this._reads.length > 0) {
1641
+ throw new Error("There are some read requests waitng on finished stream");
1642
+ }
1643
+ if (this._buffer.length > 0) {
1644
+ throw new Error("unrecognised content at end of stream");
1645
+ }
1646
+ };
1647
+ });
1648
+
1649
+ // node_modules/pngjs/lib/filter-parse-sync.js
1650
+ var require_filter_parse_sync = __commonJS(function(exports) {
1651
+ var SyncReader = require_sync_reader();
1652
+ var Filter = require_filter_parse();
1653
+ exports.process = function(inBuffer, bitmapInfo) {
1654
+ let outBuffers = [];
1655
+ let reader = new SyncReader(inBuffer);
1656
+ let filter = new Filter(bitmapInfo, {
1657
+ read: reader.read.bind(reader),
1658
+ write: function(bufferPart) {
1659
+ outBuffers.push(bufferPart);
1660
+ },
1661
+ complete: function() {}
1662
+ });
1663
+ filter.start();
1664
+ reader.process();
1665
+ return Buffer.concat(outBuffers);
1666
+ };
1667
+ });
1668
+
1669
+ // node_modules/pngjs/lib/parser-sync.js
1670
+ var require_parser_sync = __commonJS(function(exports, module) {
1671
+ var hasSyncZlib = true;
1672
+ var zlib = __require("zlib");
1673
+ var inflateSync = require_sync_inflate();
1674
+ if (!zlib.deflateSync) {
1675
+ hasSyncZlib = false;
1676
+ }
1677
+ var SyncReader = require_sync_reader();
1678
+ var FilterSync = require_filter_parse_sync();
1679
+ var Parser = require_parser();
1680
+ var bitmapper = require_bitmapper();
1681
+ var formatNormaliser = require_format_normaliser();
1682
+ module.exports = function(buffer, options) {
1683
+ if (!hasSyncZlib) {
1684
+ throw new Error("To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0");
1685
+ }
1686
+ let err;
1687
+ function handleError(_err_) {
1688
+ err = _err_;
1689
+ }
1690
+ let metaData;
1691
+ function handleMetaData(_metaData_) {
1692
+ metaData = _metaData_;
1693
+ }
1694
+ function handleTransColor(transColor) {
1695
+ metaData.transColor = transColor;
1696
+ }
1697
+ function handlePalette(palette) {
1698
+ metaData.palette = palette;
1699
+ }
1700
+ function handleSimpleTransparency() {
1701
+ metaData.alpha = true;
1702
+ }
1703
+ let gamma;
1704
+ function handleGamma(_gamma_) {
1705
+ gamma = _gamma_;
1706
+ }
1707
+ let inflateDataList = [];
1708
+ function handleInflateData(inflatedData) {
1709
+ inflateDataList.push(inflatedData);
1710
+ }
1711
+ let reader = new SyncReader(buffer);
1712
+ let parser = new Parser(options, {
1713
+ read: reader.read.bind(reader),
1714
+ error: handleError,
1715
+ metadata: handleMetaData,
1716
+ gamma: handleGamma,
1717
+ palette: handlePalette,
1718
+ transColor: handleTransColor,
1719
+ inflateData: handleInflateData,
1720
+ simpleTransparency: handleSimpleTransparency
1721
+ });
1722
+ parser.start();
1723
+ reader.process();
1724
+ if (err) {
1725
+ throw err;
1726
+ }
1727
+ let inflateData = Buffer.concat(inflateDataList);
1728
+ inflateDataList.length = 0;
1729
+ let inflatedData;
1730
+ if (metaData.interlace) {
1731
+ inflatedData = zlib.inflateSync(inflateData);
1732
+ } else {
1733
+ let rowSize = (metaData.width * metaData.bpp * metaData.depth + 7 >> 3) + 1;
1734
+ let imageSize = rowSize * metaData.height;
1735
+ inflatedData = inflateSync(inflateData, {
1736
+ chunkSize: imageSize,
1737
+ maxLength: imageSize
1738
+ });
1739
+ }
1740
+ inflateData = null;
1741
+ if (!inflatedData || !inflatedData.length) {
1742
+ throw new Error("bad png - invalid inflate data response");
1743
+ }
1744
+ let unfilteredData = FilterSync.process(inflatedData, metaData);
1745
+ inflateData = null;
1746
+ let bitmapData = bitmapper.dataToBitMap(unfilteredData, metaData);
1747
+ unfilteredData = null;
1748
+ let normalisedBitmapData = formatNormaliser(bitmapData, metaData, options.skipRescale);
1749
+ metaData.data = normalisedBitmapData;
1750
+ metaData.gamma = gamma || 0;
1751
+ return metaData;
1752
+ };
1753
+ });
1754
+
1755
+ // node_modules/pngjs/lib/packer-sync.js
1756
+ var require_packer_sync = __commonJS(function(exports, module) {
1757
+ var hasSyncZlib = true;
1758
+ var zlib = __require("zlib");
1759
+ if (!zlib.deflateSync) {
1760
+ hasSyncZlib = false;
1761
+ }
1762
+ var constants = require_constants();
1763
+ var Packer = require_packer();
1764
+ module.exports = function(metaData, opt) {
1765
+ if (!hasSyncZlib) {
1766
+ throw new Error("To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0");
1767
+ }
1768
+ let options = opt || {};
1769
+ let packer = new Packer(options);
1770
+ let chunks = [];
1771
+ chunks.push(Buffer.from(constants.PNG_SIGNATURE));
1772
+ chunks.push(packer.packIHDR(metaData.width, metaData.height));
1773
+ if (metaData.gamma) {
1774
+ chunks.push(packer.packGAMA(metaData.gamma));
1775
+ }
1776
+ let filteredData = packer.filterData(metaData.data, metaData.width, metaData.height);
1777
+ let compressedData = zlib.deflateSync(filteredData, packer.getDeflateOptions());
1778
+ filteredData = null;
1779
+ if (!compressedData || !compressedData.length) {
1780
+ throw new Error("bad png - invalid compressed data response");
1781
+ }
1782
+ chunks.push(packer.packIDAT(compressedData));
1783
+ chunks.push(packer.packIEND());
1784
+ return Buffer.concat(chunks);
1785
+ };
1786
+ });
1787
+
1788
+ // node_modules/pngjs/lib/png-sync.js
1789
+ var require_png_sync = __commonJS(function(exports) {
1790
+ var parse = require_parser_sync();
1791
+ var pack = require_packer_sync();
1792
+ exports.read = function(buffer, options) {
1793
+ return parse(buffer, options || {});
1794
+ };
1795
+ exports.write = function(png, options) {
1796
+ return pack(png, options);
1797
+ };
1798
+ });
1799
+
1800
+ // node_modules/pngjs/lib/png.js
1801
+ var require_png = __commonJS(function(exports) {
1802
+ var util = __require("util");
1803
+ var Stream = __require("stream");
1804
+ var Parser = require_parser_async();
1805
+ var Packer = require_packer_async();
1806
+ var PNGSync = require_png_sync();
1807
+ var PNG = exports.PNG = function(options) {
1808
+ Stream.call(this);
1809
+ options = options || {};
1810
+ this.width = options.width | 0;
1811
+ this.height = options.height | 0;
1812
+ this.data = this.width > 0 && this.height > 0 ? Buffer.alloc(4 * this.width * this.height) : null;
1813
+ if (options.fill && this.data) {
1814
+ this.data.fill(0);
1815
+ }
1816
+ this.gamma = 0;
1817
+ this.readable = this.writable = true;
1818
+ this._parser = new Parser(options);
1819
+ this._parser.on("error", this.emit.bind(this, "error"));
1820
+ this._parser.on("close", this._handleClose.bind(this));
1821
+ this._parser.on("metadata", this._metadata.bind(this));
1822
+ this._parser.on("gamma", this._gamma.bind(this));
1823
+ this._parser.on("parsed", function(data) {
1824
+ this.data = data;
1825
+ this.emit("parsed", data);
1826
+ }.bind(this));
1827
+ this._packer = new Packer(options);
1828
+ this._packer.on("data", this.emit.bind(this, "data"));
1829
+ this._packer.on("end", this.emit.bind(this, "end"));
1830
+ this._parser.on("close", this._handleClose.bind(this));
1831
+ this._packer.on("error", this.emit.bind(this, "error"));
1832
+ };
1833
+ util.inherits(PNG, Stream);
1834
+ PNG.sync = PNGSync;
1835
+ PNG.prototype.pack = function() {
1836
+ if (!this.data || !this.data.length) {
1837
+ this.emit("error", "No data provided");
1838
+ return this;
1839
+ }
1840
+ process.nextTick(function() {
1841
+ this._packer.pack(this.data, this.width, this.height, this.gamma);
1842
+ }.bind(this));
1843
+ return this;
1844
+ };
1845
+ PNG.prototype.parse = function(data, callback) {
1846
+ if (callback) {
1847
+ let onParsed, onError;
1848
+ onParsed = function(parsedData) {
1849
+ this.removeListener("error", onError);
1850
+ this.data = parsedData;
1851
+ callback(null, this);
1852
+ }.bind(this);
1853
+ onError = function(err) {
1854
+ this.removeListener("parsed", onParsed);
1855
+ callback(err, null);
1856
+ }.bind(this);
1857
+ this.once("parsed", onParsed);
1858
+ this.once("error", onError);
1859
+ }
1860
+ this.end(data);
1861
+ return this;
1862
+ };
1863
+ PNG.prototype.write = function(data) {
1864
+ this._parser.write(data);
1865
+ return true;
1866
+ };
1867
+ PNG.prototype.end = function(data) {
1868
+ this._parser.end(data);
1869
+ };
1870
+ PNG.prototype._metadata = function(metadata) {
1871
+ this.width = metadata.width;
1872
+ this.height = metadata.height;
1873
+ this.emit("metadata", metadata);
1874
+ };
1875
+ PNG.prototype._gamma = function(gamma) {
1876
+ this.gamma = gamma;
1877
+ };
1878
+ PNG.prototype._handleClose = function() {
1879
+ if (!this._parser.writable && !this._packer.readable) {
1880
+ this.emit("close");
1881
+ }
1882
+ };
1883
+ PNG.bitblt = function(src, dst, srcX, srcY, width, height, deltaX, deltaY) {
1884
+ srcX |= 0;
1885
+ srcY |= 0;
1886
+ width |= 0;
1887
+ height |= 0;
1888
+ deltaX |= 0;
1889
+ deltaY |= 0;
1890
+ if (srcX > src.width || srcY > src.height || srcX + width > src.width || srcY + height > src.height) {
1891
+ throw new Error("bitblt reading outside image");
1892
+ }
1893
+ if (deltaX > dst.width || deltaY > dst.height || deltaX + width > dst.width || deltaY + height > dst.height) {
1894
+ throw new Error("bitblt writing outside image");
1895
+ }
1896
+ for (let y = 0;y < height; y++) {
1897
+ src.data.copy(dst.data, (deltaY + y) * dst.width + deltaX << 2, (srcY + y) * src.width + srcX << 2, (srcY + y) * src.width + srcX + width << 2);
1898
+ }
1899
+ };
1900
+ PNG.prototype.bitblt = function(dst, srcX, srcY, width, height, deltaX, deltaY) {
1901
+ PNG.bitblt(this, dst, srcX, srcY, width, height, deltaX, deltaY);
1902
+ return this;
1903
+ };
1904
+ PNG.adjustGamma = function(src) {
1905
+ if (src.gamma) {
1906
+ for (let y = 0;y < src.height; y++) {
1907
+ for (let x = 0;x < src.width; x++) {
1908
+ let idx = src.width * y + x << 2;
1909
+ for (let i = 0;i < 3; i++) {
1910
+ let sample = src.data[idx + i] / 255;
1911
+ sample = Math.pow(sample, 1 / 2.2 / src.gamma);
1912
+ src.data[idx + i] = Math.round(sample * 255);
1913
+ }
1914
+ }
1915
+ }
1916
+ src.gamma = 0;
1917
+ }
1918
+ };
1919
+ PNG.prototype.adjustGamma = function() {
1920
+ PNG.adjustGamma(this);
1921
+ };
1922
+ });
1923
+
1924
+ // node_modules/pixelmatch/index.js
1925
+ var LIN = new Float64Array(257);
1926
+ for (let i = 0;i < 256; i++) {
1927
+ const c = i / 255;
1928
+ LIN[i] = c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
1929
+ }
1930
+ LIN[256] = LIN[255];
1931
+ var L_R = new Float64Array(256);
1932
+ var L_G = new Float64Array(256);
1933
+ var L_B = new Float64Array(256);
1934
+ var M_R = new Float64Array(256);
1935
+ var M_G = new Float64Array(256);
1936
+ var M_B = new Float64Array(256);
1937
+ var S_R = new Float64Array(256);
1938
+ var S_G = new Float64Array(256);
1939
+ var S_B = new Float64Array(256);
1940
+ for (let i = 0;i < 256; i++) {
1941
+ const lr = LIN[i];
1942
+ L_R[i] = 0.4122214708 * lr;
1943
+ M_R[i] = 0.2119034982 * lr;
1944
+ S_R[i] = 0.0883024619 * lr;
1945
+ L_G[i] = 0.5363325363 * lr;
1946
+ M_G[i] = 0.6806995451 * lr;
1947
+ S_G[i] = 0.2817188376 * lr;
1948
+ L_B[i] = 0.0514459929 * lr;
1949
+ M_B[i] = 0.1073969566 * lr;
1950
+ S_B[i] = 0.6299787005 * lr;
1951
+ }
1952
+ var CBRT_N = 4096;
1953
+ var CBRT = new Float64Array(CBRT_N + 2);
1954
+ for (let i = 0;i <= CBRT_N + 1; i++)
1955
+ CBRT[i] = Math.cbrt(i / CBRT_N);
1956
+ var OKLAB_CACHE_BITS = 12;
1957
+ var OKLAB_CACHE_SHIFT = 32 - OKLAB_CACHE_BITS;
1958
+ var OKLAB_CACHE_SIZE = 1 << OKLAB_CACHE_BITS;
1959
+ var OKLAB_CACHE_KEYS = new Uint32Array(OKLAB_CACHE_SIZE);
1960
+ var OKLAB_CACHE_VALUES = new Float64Array(OKLAB_CACHE_SIZE * 4);
1961
+ var TOE_K1 = 0.206;
1962
+ var TOE_K2 = 0.03;
1963
+ var TOE_K3 = (1 + TOE_K1) / (1 + TOE_K2);
1964
+
1965
+ // src/quality/visual.ts
1966
+ var import_pngjs = __toESM(require_png(), 1);
1967
+
1968
+ // src/quality/budgets.ts
1969
+ var STANDARDS = {
1970
+ wcag2a: { label: "WCAG 2.x A", tags: ["wcag2a"], wcag: { version: "2.0", level: "A" } },
1971
+ wcag2aa: { label: "WCAG 2.0 AA", tags: ["wcag2a", "wcag2aa"], wcag: { version: "2.0", level: "AA" } },
1972
+ wcag2aaa: { label: "WCAG 2.0 AAA", tags: ["wcag2a", "wcag2aa", "wcag2aaa"], wcag: { version: "2.0", level: "AAA" } },
1973
+ wcag21a: { label: "WCAG 2.1 A", tags: ["wcag2a", "wcag21a"], wcag: { version: "2.1", level: "A" } },
1974
+ wcag21aa: { label: "WCAG 2.1 AA", tags: ["wcag2a", "wcag2aa", "wcag21a", "wcag21aa"], wcag: { version: "2.1", level: "AA" } },
1975
+ wcag21aaa: { label: "WCAG 2.1 AAA", tags: ["wcag2a", "wcag2aa", "wcag2aaa", "wcag21a", "wcag21aa", "wcag21aaa"], wcag: { version: "2.1", level: "AAA" } },
1976
+ wcag22a: { label: "WCAG 2.2 A", tags: ["wcag2a", "wcag21a", "wcag22a"], wcag: { version: "2.2", level: "A" } },
1977
+ wcag22aa: { label: "WCAG 2.2 AA", tags: ["wcag2a", "wcag2aa", "wcag21a", "wcag21aa", "wcag22aa"], wcag: { version: "2.2", level: "AA" } },
1978
+ wcag22aaa: { label: "WCAG 2.2 AAA", tags: ["wcag2a", "wcag2aa", "wcag2aaa", "wcag21a", "wcag21aa", "wcag21aaa", "wcag22aa", "wcag22aaa"], wcag: { version: "2.2", level: "AAA" } },
1979
+ section508: { label: "Section 508", tags: ["section508", "wcag2a", "wcag2aa"], wcag: { version: "2.0", level: "AA" } },
1980
+ en301549: { label: "EN 301 549", tags: ["EN-301-549", "wcag2a", "wcag2aa", "wcag21a", "wcag21aa"], wcag: { version: "2.1", level: "AA" } },
1981
+ "best-practice": { label: "Best practice", tags: ["best-practice"] }
1982
+ };
1983
+
1984
+ // src/a11y/rulemap.ts
1985
+ var AXE_RULES = {
1986
+ accesskeys: { criteria: [], tags: ["best-practice"] },
1987
+ "area-alt": { criteria: ["2.4.4", "4.1.2"], tags: ["wcag2a", "section508", "EN-301-549"] },
1988
+ "aria-allowed-attr": { criteria: ["4.1.2"], tags: ["wcag2a", "EN-301-549"] },
1989
+ "aria-allowed-role": { criteria: [], tags: ["best-practice"] },
1990
+ "aria-braille-equivalent": { criteria: ["4.1.2"], tags: ["wcag2a", "EN-301-549"] },
1991
+ "aria-command-name": { criteria: ["4.1.2"], tags: ["wcag2a", "EN-301-549"] },
1992
+ "aria-conditional-attr": { criteria: ["4.1.2"], tags: ["wcag2a", "EN-301-549"] },
1993
+ "aria-deprecated-role": { criteria: ["4.1.2"], tags: ["wcag2a", "EN-301-549"] },
1994
+ "aria-dialog-name": { criteria: [], tags: ["best-practice"] },
1995
+ "aria-hidden-body": { criteria: ["1.3.1", "4.1.2"], tags: ["wcag2a", "EN-301-549"] },
1996
+ "aria-hidden-focus": { criteria: ["4.1.2"], tags: ["wcag2a", "EN-301-549"] },
1997
+ "aria-input-field-name": { criteria: ["4.1.2"], tags: ["wcag2a", "EN-301-549"] },
1998
+ "aria-meter-name": { criteria: ["1.1.1"], tags: ["wcag2a", "EN-301-549"] },
1999
+ "aria-progressbar-name": { criteria: ["1.1.1"], tags: ["wcag2a", "EN-301-549"] },
2000
+ "aria-prohibited-attr": { criteria: ["4.1.2"], tags: ["wcag2a", "EN-301-549"] },
2001
+ "aria-required-attr": { criteria: ["4.1.2"], tags: ["wcag2a", "EN-301-549"] },
2002
+ "aria-required-children": { criteria: ["1.3.1"], tags: ["wcag2a", "EN-301-549"] },
2003
+ "aria-required-parent": { criteria: ["1.3.1"], tags: ["wcag2a", "EN-301-549"] },
2004
+ "aria-roles": { criteria: ["4.1.2"], tags: ["wcag2a", "EN-301-549"] },
2005
+ "aria-tab-name": { criteria: ["4.1.2"], tags: ["wcag2a", "EN-301-549"] },
2006
+ "aria-text": { criteria: [], tags: ["best-practice"] },
2007
+ "aria-toggle-field-name": { criteria: ["4.1.2"], tags: ["wcag2a", "EN-301-549"] },
2008
+ "aria-tooltip-name": { criteria: ["4.1.2"], tags: ["wcag2a", "EN-301-549"] },
2009
+ "aria-treeitem-name": { criteria: [], tags: ["best-practice"] },
2010
+ "aria-valid-attr": { criteria: ["4.1.2"], tags: ["wcag2a", "EN-301-549"] },
2011
+ "aria-valid-attr-value": { criteria: ["4.1.2"], tags: ["wcag2a", "EN-301-549"] },
2012
+ "autocomplete-valid": { criteria: ["1.3.5"], tags: ["wcag21aa", "EN-301-549"] },
2013
+ "avoid-inline-spacing": { criteria: ["1.4.12"], tags: ["wcag21aa", "EN-301-549"] },
2014
+ blink: { criteria: ["2.2.2"], tags: ["wcag2a", "section508", "EN-301-549"] },
2015
+ "button-name": { criteria: ["4.1.2"], tags: ["wcag2a", "section508", "EN-301-549"] },
2016
+ bypass: { criteria: ["2.4.1"], tags: ["wcag2a", "section508", "EN-301-549"] },
2017
+ "color-contrast": { criteria: ["1.4.3"], tags: ["wcag2aa", "EN-301-549"] },
2018
+ "color-contrast-enhanced": { criteria: ["1.4.6"], tags: ["wcag2aaa"] },
2019
+ "definition-list": { criteria: ["1.3.1"], tags: ["wcag2a", "EN-301-549"] },
2020
+ dlitem: { criteria: ["1.3.1"], tags: ["wcag2a", "EN-301-549"] },
2021
+ "document-title": { criteria: ["2.4.2"], tags: ["wcag2a", "EN-301-549"] },
2022
+ "duplicate-id-aria": { criteria: ["4.1.2"], tags: ["wcag2a", "EN-301-549"] },
2023
+ "empty-heading": { criteria: [], tags: ["best-practice"] },
2024
+ "empty-table-header": { criteria: [], tags: ["best-practice"] },
2025
+ "form-field-multiple-labels": { criteria: ["3.3.2"], tags: ["wcag2a", "EN-301-549"] },
2026
+ "frame-focusable-content": { criteria: ["2.1.1"], tags: ["wcag2a", "EN-301-549"] },
2027
+ "frame-tested": { criteria: [], tags: ["best-practice"] },
2028
+ "frame-title": { criteria: ["4.1.2"], tags: ["wcag2a", "section508", "EN-301-549"] },
2029
+ "frame-title-unique": { criteria: ["4.1.2"], tags: ["wcag2a", "EN-301-549"] },
2030
+ "heading-order": { criteria: [], tags: ["best-practice"] },
2031
+ "html-has-lang": { criteria: ["3.1.1"], tags: ["wcag2a", "EN-301-549"] },
2032
+ "html-lang-valid": { criteria: ["3.1.1"], tags: ["wcag2a", "EN-301-549"] },
2033
+ "html-xml-lang-mismatch": { criteria: ["3.1.1"], tags: ["wcag2a", "EN-301-549"] },
2034
+ "identical-links-same-purpose": { criteria: ["2.4.9"], tags: ["wcag2aaa"] },
2035
+ "image-alt": { criteria: ["1.1.1"], tags: ["wcag2a", "section508", "EN-301-549"] },
2036
+ "image-redundant-alt": { criteria: [], tags: ["best-practice"] },
2037
+ "input-button-name": { criteria: ["4.1.2"], tags: ["wcag2a", "section508", "EN-301-549"] },
2038
+ "input-image-alt": { criteria: ["1.1.1", "4.1.2"], tags: ["wcag2a", "section508", "EN-301-549"] },
2039
+ label: { criteria: ["4.1.2"], tags: ["wcag2a", "section508", "EN-301-549"] },
2040
+ "label-content-name-mismatch": { criteria: ["2.5.3"], tags: ["wcag21a", "EN-301-549"] },
2041
+ "label-title-only": { criteria: [], tags: ["best-practice"] },
2042
+ "landmark-banner-is-top-level": { criteria: [], tags: ["best-practice"] },
2043
+ "landmark-contentinfo-is-top-level": { criteria: [], tags: ["best-practice"] },
2044
+ "landmark-main-is-top-level": { criteria: [], tags: ["best-practice"] },
2045
+ "landmark-no-duplicate-banner": { criteria: [], tags: ["best-practice"] },
2046
+ "landmark-no-duplicate-contentinfo": { criteria: [], tags: ["best-practice"] },
2047
+ "landmark-no-duplicate-main": { criteria: [], tags: ["best-practice"] },
2048
+ "landmark-one-main": { criteria: [], tags: ["best-practice"] },
2049
+ "landmark-unique": { criteria: [], tags: ["best-practice"] },
2050
+ "link-in-text-block": { criteria: ["1.4.1"], tags: ["wcag2a", "EN-301-549"] },
2051
+ "link-name": { criteria: ["2.4.4", "4.1.2"], tags: ["wcag2a", "section508", "EN-301-549"] },
2052
+ list: { criteria: ["1.3.1"], tags: ["wcag2a", "EN-301-549"] },
2053
+ listitem: { criteria: ["1.3.1"], tags: ["wcag2a", "EN-301-549"] },
2054
+ marquee: { criteria: ["2.2.2"], tags: ["wcag2a", "EN-301-549"] },
2055
+ "meta-refresh": { criteria: ["2.2.1"], tags: ["wcag2a", "EN-301-549"] },
2056
+ "meta-refresh-no-exceptions": { criteria: ["2.2.4", "3.2.5"], tags: ["wcag2aaa"] },
2057
+ "meta-viewport": { criteria: ["1.4.4"], tags: ["wcag2aa", "EN-301-549"] },
2058
+ "meta-viewport-large": { criteria: [], tags: ["best-practice"] },
2059
+ "nested-interactive": { criteria: ["4.1.2"], tags: ["wcag2a", "EN-301-549"] },
2060
+ "no-autoplay-audio": { criteria: ["1.4.2"], tags: ["wcag2a", "EN-301-549"] },
2061
+ "object-alt": { criteria: ["1.1.1"], tags: ["wcag2a", "section508", "EN-301-549"] },
2062
+ "page-has-heading-one": { criteria: [], tags: ["best-practice"] },
2063
+ "presentation-role-conflict": { criteria: [], tags: ["best-practice"] },
2064
+ region: { criteria: [], tags: ["best-practice"] },
2065
+ "role-img-alt": { criteria: ["1.1.1"], tags: ["wcag2a", "section508", "EN-301-549"] },
2066
+ "scope-attr-valid": { criteria: [], tags: ["best-practice"] },
2067
+ "scrollable-region-focusable": { criteria: ["2.1.1", "2.1.3"], tags: ["wcag2a", "EN-301-549"] },
2068
+ "select-name": { criteria: ["4.1.2"], tags: ["wcag2a", "section508", "EN-301-549"] },
2069
+ "server-side-image-map": { criteria: ["2.1.1"], tags: ["wcag2a", "section508", "EN-301-549"] },
2070
+ "skip-link": { criteria: [], tags: ["best-practice"] },
2071
+ "summary-name": { criteria: ["4.1.2"], tags: ["wcag2a", "section508", "EN-301-549"] },
2072
+ "svg-img-alt": { criteria: ["1.1.1"], tags: ["wcag2a", "section508", "EN-301-549"] },
2073
+ tabindex: { criteria: [], tags: ["best-practice"] },
2074
+ "table-duplicate-name": { criteria: [], tags: ["best-practice"] },
2075
+ "target-size": { criteria: ["2.5.8"], tags: ["wcag22aa"] },
2076
+ "td-headers-attr": { criteria: ["1.3.1"], tags: ["wcag2a", "section508", "EN-301-549"] },
2077
+ "th-has-data-cells": { criteria: ["1.3.1"], tags: ["wcag2a", "section508", "EN-301-549"] },
2078
+ "valid-lang": { criteria: ["3.1.2"], tags: ["wcag2aa", "EN-301-549"] },
2079
+ "video-caption": { criteria: ["1.2.2"], tags: ["wcag2a", "section508", "EN-301-549"] }
2080
+ };
2081
+ var IBM_RULES = {
2082
+ WCAG_2_2: {
2083
+ "1.1.1": ["applet_alt_exists", "application_content_accessible", "area_alt_exists", "imagebutton_alt_exists", "imagemap_alt_exists", "img_alt_decorative", "img_alt_misuse", "img_alt_null", "img_alt_redundant", "img_alt_valid", "img_ismap_misuse", "img_longdesc_misuse", "media_alt_exists", "object_text_exists", "style_background_decorative", "svg_graphics_labelled"],
2084
+ "1.2.2": ["caption_track_exists"],
2085
+ "1.3.1": ["aria_banner_label_unique", "aria_banner_single", "aria_complementary_label_unique", "aria_complementary_labelled", "aria_contentinfo_label_unique", "aria_contentinfo_single", "aria_form_label_unique", "aria_hidden_nontabbable", "aria_main_label_unique", "aria_navigation_label_unique", "aria_parent_required", "aria_region_label_unique", "aria_region_labelled", "blockquote_cite_exists", "fieldset_label_valid", "form_label_unique", "heading_markup_misuse", "input_checkboxes_grouped", "label_ref_valid", "list_markup_review", "table_caption_empty", "table_caption_nested", "table_headers_exists", "table_headers_ref_valid", "table_headers_related", "table_scope_valid", "table_structure_misuse", "table_summary_redundant", "text_block_heading", "text_quoted_correctly"],
2086
+ "1.3.2": ["dir_attribute_valid", "text_whitespace_valid"],
2087
+ "1.3.3": ["text_sensory_misuse"],
2088
+ "1.3.4": ["element_orientation_unlocked"],
2089
+ "1.3.5": ["input_autocomplete_valid"],
2090
+ "1.4.1": ["form_font_color", "style_color_misuse"],
2091
+ "1.4.2": ["media_autostart_controllable"],
2092
+ "1.4.3": ["text_contrast_sufficient"],
2093
+ "1.4.4": ["style_viewport_resizable"],
2094
+ "1.4.10": ["style_viewport_resizable"],
2095
+ "1.4.12": ["text_spacing_valid"],
2096
+ "1.4.13": ["style_hover_persistent"],
2097
+ "2.1.1": ["application_content_accessible", "aria_activedescendant_tabindex_valid", "aria_child_tabbable", "aria_keyboard_handler_exists", "iframe_interactive_tabbable", "media_keyboard_controllable", "script_focus_blur_review", "script_onclick_misuse", "widget_tabbable_exists", "widget_tabbable_single"],
2098
+ "2.2.1": ["meta_refresh_delay"],
2099
+ "2.2.2": ["blink_css_review", "blink_elem_deprecated", "marquee_elem_avoid"],
2100
+ "2.4.1": ["aria_application_label_unique", "aria_application_labelled", "aria_article_label_unique", "aria_document_label_unique", "aria_toolbar_label_unique", "frame_src_valid", "html_skipnav_exists", "skip_main_described", "skip_main_exists"],
2101
+ "2.4.2": ["page_title_exists", "page_title_valid"],
2102
+ "2.4.3": ["widget_tabbable_single"],
2103
+ "2.4.4": ["a_text_purpose", "img_alt_redundant"],
2104
+ "2.4.7": ["element_tabbable_visible", "script_focus_blur_review", "style_focus_visible"],
2105
+ "2.4.11": ["element_tabbable_unobscured"],
2106
+ "2.5.3": ["input_label_visible", "label_name_visible"],
2107
+ "2.5.7": ["draggable_alternative_exists"],
2108
+ "2.5.8": ["target_spacing_sufficient"],
2109
+ "3.1.1": ["html_lang_exists", "html_lang_valid"],
2110
+ "3.1.2": ["element_lang_valid"],
2111
+ "3.2.1": ["script_focus_blur_review", "script_select_review"],
2112
+ "3.2.2": ["form_interaction_review", "form_submit_button_exists", "input_onchange_review"],
2113
+ "3.3.1": ["error_message_exists"],
2114
+ "3.3.2": ["fieldset_label_valid", "input_label_after", "input_label_before", "input_label_visible"],
2115
+ "4.1.2": ["a_text_purpose", "aria_activedescendant_valid", "aria_attribute_allowed", "aria_attribute_conflict", "aria_attribute_exists", "aria_attribute_required", "aria_attribute_value_valid", "aria_descendant_valid", "aria_eventhandler_role_valid", "aria_hidden_nontabbable", "aria_id_unique", "aria_role_allowed", "aria_role_valid", "aria_widget_labelled", "combobox_active_descendant", "combobox_autocomplete_valid", "combobox_design_valid", "combobox_focusable_elements", "combobox_haspopup_valid", "combobox_popup_reference", "frame_title_exists", "input_haspopup_conflict", "input_label_exists", "label_content_exists", "list_children_valid", "table_aria_descendants"]
2116
+ },
2117
+ WCAG_2_1: {
2118
+ "1.1.1": ["applet_alt_exists", "application_content_accessible", "area_alt_exists", "imagebutton_alt_exists", "imagemap_alt_exists", "img_alt_decorative", "img_alt_misuse", "img_alt_null", "img_alt_redundant", "img_alt_valid", "img_ismap_misuse", "img_longdesc_misuse", "media_alt_exists", "object_text_exists", "style_background_decorative", "svg_graphics_labelled"],
2119
+ "1.2.2": ["caption_track_exists"],
2120
+ "1.3.1": ["aria_banner_label_unique", "aria_banner_single", "aria_complementary_label_unique", "aria_complementary_labelled", "aria_contentinfo_label_unique", "aria_contentinfo_single", "aria_form_label_unique", "aria_hidden_nontabbable", "aria_main_label_unique", "aria_navigation_label_unique", "aria_parent_required", "aria_region_label_unique", "aria_region_labelled", "blockquote_cite_exists", "fieldset_label_valid", "form_label_unique", "heading_markup_misuse", "input_checkboxes_grouped", "label_ref_valid", "list_markup_review", "table_caption_empty", "table_caption_nested", "table_headers_exists", "table_headers_ref_valid", "table_headers_related", "table_scope_valid", "table_structure_misuse", "table_summary_redundant", "text_block_heading", "text_quoted_correctly"],
2121
+ "1.3.2": ["dir_attribute_valid", "text_whitespace_valid"],
2122
+ "1.3.3": ["text_sensory_misuse"],
2123
+ "1.3.4": ["element_orientation_unlocked"],
2124
+ "1.3.5": ["input_autocomplete_valid"],
2125
+ "1.4.1": ["form_font_color", "style_color_misuse"],
2126
+ "1.4.2": ["media_autostart_controllable"],
2127
+ "1.4.3": ["text_contrast_sufficient"],
2128
+ "1.4.4": ["style_viewport_resizable"],
2129
+ "1.4.10": ["style_viewport_resizable"],
2130
+ "1.4.12": ["text_spacing_valid"],
2131
+ "1.4.13": ["style_hover_persistent"],
2132
+ "2.1.1": ["application_content_accessible", "aria_activedescendant_tabindex_valid", "aria_child_tabbable", "aria_keyboard_handler_exists", "iframe_interactive_tabbable", "media_keyboard_controllable", "script_focus_blur_review", "script_onclick_misuse", "widget_tabbable_exists", "widget_tabbable_single"],
2133
+ "2.2.1": ["meta_refresh_delay"],
2134
+ "2.2.2": ["blink_css_review", "blink_elem_deprecated", "marquee_elem_avoid"],
2135
+ "2.4.1": ["aria_application_label_unique", "aria_application_labelled", "aria_article_label_unique", "aria_document_label_unique", "aria_toolbar_label_unique", "frame_src_valid", "html_skipnav_exists", "skip_main_described", "skip_main_exists"],
2136
+ "2.4.2": ["page_title_exists", "page_title_valid"],
2137
+ "2.4.3": ["widget_tabbable_single"],
2138
+ "2.4.4": ["a_text_purpose", "img_alt_redundant"],
2139
+ "2.4.7": ["element_tabbable_visible", "script_focus_blur_review", "style_focus_visible"],
2140
+ "2.5.3": ["input_label_visible", "label_name_visible"],
2141
+ "3.1.1": ["html_lang_exists", "html_lang_valid"],
2142
+ "3.1.2": ["element_lang_valid"],
2143
+ "3.2.1": ["script_focus_blur_review", "script_select_review"],
2144
+ "3.2.2": ["form_interaction_review", "form_submit_button_exists", "input_onchange_review"],
2145
+ "3.3.1": ["error_message_exists"],
2146
+ "3.3.2": ["fieldset_label_valid", "input_label_after", "input_label_before", "input_label_visible"],
2147
+ "4.1.2": ["a_text_purpose", "aria_activedescendant_valid", "aria_attribute_allowed", "aria_attribute_conflict", "aria_attribute_exists", "aria_attribute_required", "aria_attribute_value_valid", "aria_descendant_valid", "aria_eventhandler_role_valid", "aria_hidden_nontabbable", "aria_id_unique", "aria_role_allowed", "aria_role_valid", "aria_widget_labelled", "combobox_active_descendant", "combobox_autocomplete_valid", "combobox_design_valid", "combobox_focusable_elements", "combobox_haspopup_valid", "combobox_popup_reference", "frame_title_exists", "input_haspopup_conflict", "input_label_exists", "label_content_exists", "list_children_valid", "table_aria_descendants"]
2148
+ },
2149
+ WCAG_2_0: {
2150
+ "1.1.1": ["applet_alt_exists", "application_content_accessible", "area_alt_exists", "imagebutton_alt_exists", "imagemap_alt_exists", "img_alt_decorative", "img_alt_misuse", "img_alt_null", "img_alt_redundant", "img_alt_valid", "img_ismap_misuse", "img_longdesc_misuse", "media_alt_exists", "object_text_exists", "style_background_decorative", "svg_graphics_labelled"],
2151
+ "1.2.2": ["caption_track_exists"],
2152
+ "1.3.1": ["aria_banner_label_unique", "aria_banner_single", "aria_complementary_label_unique", "aria_complementary_labelled", "aria_contentinfo_label_unique", "aria_contentinfo_single", "aria_form_label_unique", "aria_hidden_nontabbable", "aria_main_label_unique", "aria_navigation_label_unique", "aria_parent_required", "aria_region_label_unique", "aria_region_labelled", "blockquote_cite_exists", "fieldset_label_valid", "form_label_unique", "heading_markup_misuse", "input_checkboxes_grouped", "label_ref_valid", "list_markup_review", "table_caption_empty", "table_caption_nested", "table_headers_exists", "table_headers_ref_valid", "table_headers_related", "table_scope_valid", "table_structure_misuse", "table_summary_redundant", "text_block_heading", "text_quoted_correctly"],
2153
+ "1.3.2": ["dir_attribute_valid", "text_whitespace_valid"],
2154
+ "1.3.3": ["text_sensory_misuse"],
2155
+ "1.4.1": ["form_font_color", "style_color_misuse"],
2156
+ "1.4.2": ["media_autostart_controllable"],
2157
+ "1.4.3": ["text_contrast_sufficient"],
2158
+ "1.4.4": ["style_viewport_resizable"],
2159
+ "2.1.1": ["application_content_accessible", "aria_activedescendant_tabindex_valid", "aria_child_tabbable", "aria_keyboard_handler_exists", "iframe_interactive_tabbable", "media_keyboard_controllable", "script_focus_blur_review", "script_onclick_misuse", "widget_tabbable_exists", "widget_tabbable_single"],
2160
+ "2.2.1": ["meta_refresh_delay"],
2161
+ "2.2.2": ["blink_css_review", "blink_elem_deprecated", "marquee_elem_avoid"],
2162
+ "2.4.1": ["aria_application_label_unique", "aria_application_labelled", "aria_article_label_unique", "aria_document_label_unique", "aria_toolbar_label_unique", "frame_src_valid", "html_skipnav_exists", "skip_main_described", "skip_main_exists"],
2163
+ "2.4.2": ["page_title_exists", "page_title_valid"],
2164
+ "2.4.3": ["widget_tabbable_single"],
2165
+ "2.4.4": ["a_text_purpose", "img_alt_redundant"],
2166
+ "2.4.7": ["element_tabbable_visible", "script_focus_blur_review", "style_focus_visible"],
2167
+ "3.1.1": ["html_lang_exists", "html_lang_valid"],
2168
+ "3.1.2": ["element_lang_valid"],
2169
+ "3.2.1": ["script_focus_blur_review", "script_select_review"],
2170
+ "3.2.2": ["form_interaction_review", "form_submit_button_exists", "input_onchange_review"],
2171
+ "3.3.1": ["error_message_exists"],
2172
+ "3.3.2": ["fieldset_label_valid", "input_label_after", "input_label_before", "input_label_visible"],
2173
+ "4.1.2": ["a_text_purpose", "aria_activedescendant_valid", "aria_attribute_allowed", "aria_attribute_conflict", "aria_attribute_exists", "aria_attribute_required", "aria_attribute_value_valid", "aria_descendant_valid", "aria_eventhandler_role_valid", "aria_hidden_nontabbable", "aria_id_unique", "aria_role_allowed", "aria_role_valid", "aria_widget_labelled", "combobox_active_descendant", "combobox_autocomplete_valid", "combobox_design_valid", "combobox_focusable_elements", "combobox_haspopup_valid", "combobox_popup_reference", "frame_title_exists", "input_haspopup_conflict", "input_label_exists", "label_content_exists", "list_children_valid", "table_aria_descendants"]
2174
+ }
2175
+ };
2176
+
2177
+ // src/a11y/wcag.ts
2178
+ var PRINCIPLES = { "1": "Perceivable", "2": "Operable", "3": "Understandable", "4": "Robust" };
2179
+ var c = (id, title, level, since = "2.0", removed) => ({ id, title, level, since, ...removed ? { removed } : {} });
2180
+ var CRITERIA = Object.freeze([
2181
+ c("1.1.1", "Non-text Content", "A"),
2182
+ c("1.2.1", "Audio-only and Video-only (Prerecorded)", "A"),
2183
+ c("1.2.2", "Captions (Prerecorded)", "A"),
2184
+ c("1.2.3", "Audio Description or Media Alternative (Prerecorded)", "A"),
2185
+ c("1.2.4", "Captions (Live)", "AA"),
2186
+ c("1.2.5", "Audio Description (Prerecorded)", "AA"),
2187
+ c("1.2.6", "Sign Language (Prerecorded)", "AAA"),
2188
+ c("1.2.7", "Extended Audio Description (Prerecorded)", "AAA"),
2189
+ c("1.2.8", "Media Alternative (Prerecorded)", "AAA"),
2190
+ c("1.2.9", "Audio-only (Live)", "AAA"),
2191
+ c("1.3.1", "Info and Relationships", "A"),
2192
+ c("1.3.2", "Meaningful Sequence", "A"),
2193
+ c("1.3.3", "Sensory Characteristics", "A"),
2194
+ c("1.3.4", "Orientation", "AA", "2.1"),
2195
+ c("1.3.5", "Identify Input Purpose", "AA", "2.1"),
2196
+ c("1.3.6", "Identify Purpose", "AAA", "2.1"),
2197
+ c("1.4.1", "Use of Color", "A"),
2198
+ c("1.4.2", "Audio Control", "A"),
2199
+ c("1.4.3", "Contrast (Minimum)", "AA"),
2200
+ c("1.4.4", "Resize Text", "AA"),
2201
+ c("1.4.5", "Images of Text", "AA"),
2202
+ c("1.4.6", "Contrast (Enhanced)", "AAA"),
2203
+ c("1.4.7", "Low or No Background Audio", "AAA"),
2204
+ c("1.4.8", "Visual Presentation", "AAA"),
2205
+ c("1.4.9", "Images of Text (No Exception)", "AAA"),
2206
+ c("1.4.10", "Reflow", "AA", "2.1"),
2207
+ c("1.4.11", "Non-text Contrast", "AA", "2.1"),
2208
+ c("1.4.12", "Text Spacing", "AA", "2.1"),
2209
+ c("1.4.13", "Content on Hover or Focus", "AA", "2.1"),
2210
+ c("2.1.1", "Keyboard", "A"),
2211
+ c("2.1.2", "No Keyboard Trap", "A"),
2212
+ c("2.1.3", "Keyboard (No Exception)", "AAA"),
2213
+ c("2.1.4", "Character Key Shortcuts", "A", "2.1"),
2214
+ c("2.2.1", "Timing Adjustable", "A"),
2215
+ c("2.2.2", "Pause, Stop, Hide", "A"),
2216
+ c("2.2.3", "No Timing", "AAA"),
2217
+ c("2.2.4", "Interruptions", "AAA"),
2218
+ c("2.2.5", "Re-authenticating", "AAA"),
2219
+ c("2.2.6", "Timeouts", "AAA", "2.1"),
2220
+ c("2.3.1", "Three Flashes or Below Threshold", "A"),
2221
+ c("2.3.2", "Three Flashes", "AAA"),
2222
+ c("2.3.3", "Animation from Interactions", "AAA", "2.1"),
2223
+ c("2.4.1", "Bypass Blocks", "A"),
2224
+ c("2.4.2", "Page Titled", "A"),
2225
+ c("2.4.3", "Focus Order", "A"),
2226
+ c("2.4.4", "Link Purpose (In Context)", "A"),
2227
+ c("2.4.5", "Multiple Ways", "AA"),
2228
+ c("2.4.6", "Headings and Labels", "AA"),
2229
+ c("2.4.7", "Focus Visible", "AA"),
2230
+ c("2.4.8", "Location", "AAA"),
2231
+ c("2.4.9", "Link Purpose (Link Only)", "AAA"),
2232
+ c("2.4.10", "Section Headings", "AAA"),
2233
+ c("2.4.11", "Focus Not Obscured (Minimum)", "AA", "2.2"),
2234
+ c("2.4.12", "Focus Not Obscured (Enhanced)", "AAA", "2.2"),
2235
+ c("2.4.13", "Focus Appearance", "AAA", "2.2"),
2236
+ c("2.5.1", "Pointer Gestures", "A", "2.1"),
2237
+ c("2.5.2", "Pointer Cancellation", "A", "2.1"),
2238
+ c("2.5.3", "Label in Name", "A", "2.1"),
2239
+ c("2.5.4", "Motion Actuation", "A", "2.1"),
2240
+ c("2.5.5", "Target Size (Enhanced)", "AAA", "2.1"),
2241
+ c("2.5.6", "Concurrent Input Mechanisms", "AAA", "2.1"),
2242
+ c("2.5.7", "Dragging Movements", "AA", "2.2"),
2243
+ c("2.5.8", "Target Size (Minimum)", "AA", "2.2"),
2244
+ c("3.1.1", "Language of Page", "A"),
2245
+ c("3.1.2", "Language of Parts", "AA"),
2246
+ c("3.1.3", "Unusual Words", "AAA"),
2247
+ c("3.1.4", "Abbreviations", "AAA"),
2248
+ c("3.1.5", "Reading Level", "AAA"),
2249
+ c("3.1.6", "Pronunciation", "AAA"),
2250
+ c("3.2.1", "On Focus", "A"),
2251
+ c("3.2.2", "On Input", "A"),
2252
+ c("3.2.3", "Consistent Navigation", "AA"),
2253
+ c("3.2.4", "Consistent Identification", "AA"),
2254
+ c("3.2.5", "Change on Request", "AAA"),
2255
+ c("3.2.6", "Consistent Help", "A", "2.2"),
2256
+ c("3.3.1", "Error Identification", "A"),
2257
+ c("3.3.2", "Labels or Instructions", "A"),
2258
+ c("3.3.3", "Error Suggestion", "AA"),
2259
+ c("3.3.4", "Error Prevention (Legal, Financial, Data)", "AA"),
2260
+ c("3.3.5", "Help", "AAA"),
2261
+ c("3.3.6", "Error Prevention (All)", "AAA"),
2262
+ c("3.3.7", "Redundant Entry", "A", "2.2"),
2263
+ c("3.3.8", "Accessible Authentication (Minimum)", "AA", "2.2"),
2264
+ c("3.3.9", "Accessible Authentication (Enhanced)", "AAA", "2.2"),
2265
+ c("4.1.1", "Parsing", "A", "2.0", "2.2"),
2266
+ c("4.1.2", "Name, Role, Value", "A"),
2267
+ c("4.1.3", "Status Messages", "AA", "2.1")
2268
+ ]);
2269
+ var CRITERION_ID = /^[1-4]\.\d{1,2}\.\d{1,2}$/;
2270
+ var BY_ID = new Map(CRITERIA.map((x) => [x.id, x]));
2271
+ var VERSIONS = ["2.0", "2.1", "2.2"];
2272
+ var LEVELS = ["A", "AA", "AAA"];
2273
+ function criteriaFor(version, level) {
2274
+ const v = VERSIONS.indexOf(version);
2275
+ const l = LEVELS.indexOf(level);
2276
+ return CRITERIA.filter((x) => VERSIONS.indexOf(x.since) <= v && (!x.removed || VERSIONS.indexOf(x.removed) > v) && LEVELS.indexOf(x.level) <= l);
2277
+ }
2278
+
2279
+ // src/a11y/coverage.ts
2280
+ var RESULTS = ["failed", "review", "exercised", "passed", "not_tested"];
2281
+ var TRAIT_LABEL = {
2282
+ screen_reader: "Screen reader",
2283
+ keyboard: "Keyboard only",
2284
+ touch: "Touch",
2285
+ colour: "Colour vision",
2286
+ low_contrast: "Blur or low contrast",
2287
+ zoom: "200% zoom",
2288
+ text: "Large text",
2289
+ motion: "Reduced motion",
2290
+ forced_colours: "High contrast",
2291
+ hearing: "Deaf or hard of hearing",
2292
+ cognitive: "Cognitive",
2293
+ dexterity: "Hand tremor"
2294
+ };
2295
+ var TRAIT_CRITERIA = {
2296
+ screen_reader: ["1.1.1", "1.3.1", "1.3.2", "2.4.1", "2.4.2", "2.4.4", "2.4.6", "3.2.1", "3.2.2", "3.3.1", "3.3.2", "4.1.2", "4.1.3"],
2297
+ keyboard: ["2.1.1", "2.1.2", "2.1.3", "2.4.1", "2.4.3", "2.4.7", "2.4.11", "2.4.12", "2.4.13", "1.4.13", "3.2.1"],
2298
+ touch: ["1.3.4", "2.5.1", "2.5.2", "2.5.7", "2.5.8"],
2299
+ colour: ["1.3.3", "1.4.1", "1.4.11"],
2300
+ low_contrast: ["1.4.3", "1.4.6", "1.4.11"],
2301
+ zoom: ["1.4.4", "1.4.10", "1.4.13"],
2302
+ text: ["1.4.4", "1.4.12"],
2303
+ motion: ["2.2.2", "2.3.3"],
2304
+ forced_colours: ["1.4.1", "1.4.11", "2.4.7"],
2305
+ hearing: ["1.2.1", "1.2.2", "1.2.4", "1.2.6", "1.2.9", "1.4.2", "1.4.7"],
2306
+ cognitive: ["1.3.3", "2.2.1", "2.4.6", "3.1.5", "3.2.3", "3.2.4", "3.2.6", "3.3.1", "3.3.3", "3.3.4", "3.3.7", "3.3.8"],
2307
+ dexterity: ["2.5.1", "2.5.2", "2.5.5", "2.5.7", "2.5.8"]
2308
+ };
2309
+ var traitCriteria = (traits) => new Set(traits.flatMap((t) => TRAIT_CRITERIA[t] || []));
2310
+ var TRAITS = Object.keys(TRAIT_CRITERIA);
2311
+ function engineRules(engine, standard) {
2312
+ const out = new Map;
2313
+ const add = (sc, rule) => out.set(sc, [...new Set([...out.get(sc) || [], rule])].sort());
2314
+ if (engine === "axe") {
2315
+ const tags = new Set(STANDARDS[standard]?.tags || []);
2316
+ for (const [rule, r] of Object.entries(AXE_RULES))
2317
+ if (r.tags.some((t) => tags.has(t)))
2318
+ for (const sc of r.criteria)
2319
+ add(sc, rule);
2320
+ } else if (engine === "ibm") {
2321
+ const w = STANDARDS[standard]?.wcag;
2322
+ const set = IBM_RULES[w ? `WCAG_${w.version.replace(".", "_")}` : "WCAG_2_1"] || {};
2323
+ for (const [sc, rules] of Object.entries(set))
2324
+ for (const r of rules)
2325
+ add(sc, r);
2326
+ } else {
2327
+ for (const [sc, rule] of [["2.4.2", "document-title"], ["4.1.2", "button-name"], ["4.1.2", "link-name"], ["1.1.1", "image-alt"], ["1.3.1", "heading-order"], ["3.1.1", "html-lang"], ["1.4.3", "color-contrast"], ["1.4.4", "meta-viewport"]])
2328
+ add(sc, rule);
2329
+ }
2330
+ return out;
2331
+ }
2332
+ function standardCriteria(standard) {
2333
+ const w = STANDARDS[standard]?.wcag || { version: "2.2", level: "AA" };
2334
+ return criteriaFor(w.version, w.level);
2335
+ }
2336
+ var NOTE = "Rules never prove a success criterion is met: a criterion with rules that pass still needs a person to confirm it. A persona exercises a criterion by how they use the page; reaching the goal without a barrier of it is evidence, not conformance.";
2337
+ function coverageMatrix(opts) {
2338
+ const rulesBy = engineRules(opts.engine, opts.standard);
2339
+ const peopleBy = new Map;
2340
+ for (const t of new Set(opts.traits))
2341
+ for (const sc of TRAIT_CRITERIA[t] || [])
2342
+ peopleBy.set(sc, (peopleBy.get(sc) || new Set).add(TRAIT_LABEL[t]));
2343
+ const ev = opts.evidence ? evidenceBy(opts.evidence, opts.engine) : undefined;
2344
+ const rows = standardCriteria(opts.standard).map((c) => {
2345
+ const rules = rulesBy.get(c.id) || [];
2346
+ const people = [...peopleBy.get(c.id) || []].sort();
2347
+ const row = { id: c.id, title: c.title, level: c.level, since: c.since, principle: PRINCIPLES[c.id[0]], automation: rules.length ? "rules" : people.length ? "people" : "manual", rules, people };
2348
+ if (ev)
2349
+ Object.assign(row, resultOf(c.id, rules, ev));
2350
+ return row;
2351
+ });
2352
+ const count = (a) => rows.filter((r) => r.automation === a).length;
2353
+ const summary = { total: rows.length, rules: count("rules"), people: count("people"), manual: count("manual") };
2354
+ if (ev)
2355
+ summary.results = Object.fromEntries(RESULTS.map((r) => [r, rows.filter((x) => x.result === r).length]));
2356
+ return { standard: opts.standard, label: STANDARDS[opts.standard]?.label || opts.standard, engine: opts.engine, rows, summary, note: NOTE };
2357
+ }
2358
+ function criteriaOfRule(rule, engine, named) {
2359
+ if (named && CRITERION_ID.test(named))
2360
+ return [named];
2361
+ if (engine === "axe")
2362
+ return AXE_RULES[rule]?.criteria || [];
2363
+ if (engine === "ibm")
2364
+ return [...new Set(Object.values(IBM_RULES).flatMap((set) => Object.entries(set).filter(([, rs]) => rs.includes(rule)).map(([sc]) => sc)))];
2365
+ return [];
2366
+ }
2367
+ function evidenceBy(e, engine) {
2368
+ const out = { failed: new Map, review: new Map, passedRules: new Set, barriers: new Map, exercised: new Map };
2369
+ for (const page of e.pages) {
2370
+ for (const r of page.passed || [])
2371
+ out.passedRules.add(String(r));
2372
+ for (const r of page.incomplete || [])
2373
+ for (const sc of criteriaOfRule(String(r), engine))
2374
+ out.review.set(sc, (out.review.get(sc) || new Set).add(String(r)));
2375
+ for (const i of page.issues || []) {
2376
+ for (const sc of new Set([...criteriaOfRule(i.rule, engine, i.wcag), ...criteriaOfRule(i.rule, engine)])) {
2377
+ const m = out.failed.get(sc) || new Map;
2378
+ m.set(i.rule, (m.get(i.rule) || 0) + (Number(i.count) || 0));
2379
+ out.failed.set(sc, m);
2380
+ }
2381
+ }
2382
+ }
2383
+ for (const p of e.personas || []) {
2384
+ if (!p.ran)
2385
+ continue;
2386
+ for (const f of p.findings)
2387
+ if (f.wcag && CRITERION_ID.test(f.wcag))
2388
+ out.barriers.set(f.wcag, [...out.barriers.get(f.wcag) || [], { persona: p.name, title: f.title, severity: f.severity }]);
2389
+ if (p.reached === "yes" || p.reached === "partly")
2390
+ for (const sc of traitCriteria(p.traits))
2391
+ out.exercised.set(sc, (out.exercised.get(sc) || new Set).add(p.name));
2392
+ }
2393
+ return out;
2394
+ }
2395
+ function resultOf(id, rules, ev) {
2396
+ const failed = [...(ev.failed.get(id) || new Map).entries()].map(([rule, count]) => ({ rule, count }));
2397
+ const review = [...ev.review.get(id) || []].sort();
2398
+ const barriers = ev.barriers.get(id) || [];
2399
+ const exercisedBy = [...ev.exercised.get(id) || []].filter((name) => !barriers.some((b) => b.persona === name)).sort();
2400
+ const passed = rules.some((r) => ev.passedRules.has(r));
2401
+ const result = failed.length || barriers.length ? "failed" : review.length ? "review" : exercisedBy.length ? "exercised" : passed ? "passed" : "not_tested";
2402
+ return { result, ...failed.length ? { failed } : {}, ...review.length ? { review } : {}, ...barriers.length ? { barriers } : {}, ...exercisedBy.length ? { exercisedBy } : {} };
2403
+ }
2404
+
2405
+ // src/a11y/snapshot.ts
2406
+ var clip = (v, n) => String(v ?? "").replace(/[\u0000-\u001f\u007f]+/g, " ").replace(/\s+/g, " ").trim().slice(0, n);
2407
+ var REACH = ["no", "unknown", "partly", "yes"];
2408
+ var SEO_DROP = 5;
2409
+ function compareSnapshots(base, now) {
2410
+ const worse = [];
2411
+ const better = [];
2412
+ for (const [id, r] of Object.entries(now.criteria)) {
2413
+ const was = base.criteria[id];
2414
+ if (r === "failed" && was && was !== "failed")
2415
+ worse.push({ kind: "criterion", where: id, text: `WCAG ${id} now fails (was ${was.replace("_", " ")}).` });
2416
+ if (was === "failed" && r !== "failed")
2417
+ better.push({ kind: "criterion", where: id, text: `WCAG ${id} no longer fails.` });
2418
+ }
2419
+ for (const [page, rules] of Object.entries(now.rules)) {
2420
+ const was = base.rules[page];
2421
+ if (!was)
2422
+ continue;
2423
+ for (const rule of rules.filter((x) => !was.includes(x)))
2424
+ worse.push({ kind: "rule", where: page, text: `${rule} newly fails on ${page}.` });
2425
+ for (const rule of was.filter((x) => !rules.includes(x)))
2426
+ better.push({ kind: "rule", where: page, text: `${rule} is fixed on ${page}.` });
2427
+ }
2428
+ for (const page of now.broken.filter((p) => !base.broken.includes(p)))
2429
+ worse.push({ kind: "page", where: page, text: `${page} could not be opened.` });
2430
+ for (const [page, score] of Object.entries(now.seo)) {
2431
+ const was = base.seo[page];
2432
+ if (was !== undefined && was - score >= SEO_DROP)
2433
+ worse.push({ kind: "seo", where: page, text: `SEO score of ${page} fell from ${was} to ${score}.` });
2434
+ if (was !== undefined && score - was >= SEO_DROP)
2435
+ better.push({ kind: "seo", where: page, text: `SEO score of ${page} rose from ${was} to ${score}.` });
2436
+ }
2437
+ for (const [page, tools] of Object.entries(base.analytics)) {
2438
+ const nowTools = now.analytics[page];
2439
+ if (!nowTools)
2440
+ continue;
2441
+ for (const t of tools.filter((x) => !nowTools.includes(x)))
2442
+ worse.push({ kind: "analytics", where: page, text: `${t} is no longer on ${page}.` });
2443
+ }
2444
+ for (const [who, p] of Object.entries(now.personas)) {
2445
+ const was = base.personas[who];
2446
+ if (!was)
2447
+ continue;
2448
+ if (REACH.indexOf(p.reached) < REACH.indexOf(was.reached))
2449
+ worse.push({ kind: "persona", where: who, text: `${who} ${p.reached === "no" ? "can no longer reach the goal" : p.reached === "unknown" ? "was not tested" : "only partly reached the goal"} (was ${was.reached}).` });
2450
+ if (REACH.indexOf(p.reached) > REACH.indexOf(was.reached))
2451
+ better.push({ kind: "persona", where: who, text: `${who} now reaches the goal${p.reached === "partly" ? " partly" : ""} (was ${was.reached}).` });
2452
+ for (const b of p.barriers.filter((x) => !was.barriers.includes(x)))
2453
+ worse.push({ kind: "barrier", where: who, text: `${who} meets a new barrier of WCAG ${b}.` });
2454
+ for (const b of was.barriers.filter((x) => !p.barriers.includes(x)))
2455
+ better.push({ kind: "barrier", where: who, text: `${who} no longer meets a barrier of WCAG ${b}.` });
2456
+ }
2457
+ return { worse, better };
2458
+ }
2459
+ var PLAIN = /^[\w.:-]{1,80}$/;
2460
+ var strs = (v, n, re = PLAIN) => Array.isArray(v) ? v.filter((x) => typeof x === "string" && re.test(x)).slice(0, n) : [];
2461
+ var pageOk = (k) => /^https?:\/\/[^\s]{1,600}$/.test(k);
2462
+ function cleanSnapshot(raw) {
2463
+ if (!raw || typeof raw !== "object" || Array.isArray(raw))
2464
+ return null;
2465
+ const r = raw;
2466
+ const map = (v, f, keyOk) => {
2467
+ const out = {};
2468
+ if (!v || typeof v !== "object" || Array.isArray(v))
2469
+ return out;
2470
+ for (const [k, x] of Object.entries(v).slice(0, 500)) {
2471
+ const y = keyOk(k) ? f(x) : null;
2472
+ if (y !== null)
2473
+ out[k] = y;
2474
+ }
2475
+ return out;
2476
+ };
2477
+ const RESULT = new Set(["failed", "review", "exercised", "passed", "not_tested"]);
2478
+ return {
2479
+ run: clip(r.run, 160),
2480
+ at: clip(r.at, 40),
2481
+ criteria: map(r.criteria, (x) => typeof x === "string" && RESULT.has(x) ? x : null, (k) => CRITERION_ID.test(k)),
2482
+ rules: map(r.rules, (x) => strs(x, 200), pageOk),
2483
+ broken: strs(r.broken, 50, /^https?:\/\/\S{1,600}$/),
2484
+ seo: map(r.seo, (x) => typeof x === "number" && x >= 0 && x <= 100 ? Math.round(x) : null, pageOk),
2485
+ analytics: map(r.analytics, (x) => strs(x, 30, /^[\w .-]{1,40}$/), pageOk),
2486
+ personas: map(r.personas, (x) => {
2487
+ const p = x && typeof x === "object" ? x : null;
2488
+ if (!p || !REACH.includes(String(p.reached)))
2489
+ return null;
2490
+ return { reached: String(p.reached), barriers: strs(p.barriers, 100, CRITERION_ID), ...p.replayed === true ? { replayed: true } : {} };
2491
+ }, (k) => /^[a-z0-9][a-z0-9-]{0,47}\/[a-z0-9][a-z0-9-]{0,39}$/.test(k))
2492
+ };
2493
+ }
2494
+
2495
+ // src/seo/checks.ts
2496
+ var ANALYTICS_TOOLS = [
2497
+ "Google Analytics 4",
2498
+ "Universal Analytics",
2499
+ "Google Tag Manager",
2500
+ "Google Ads",
2501
+ "Adobe Analytics",
2502
+ "Meta Pixel",
2503
+ "Microsoft Clarity",
2504
+ "Hotjar",
2505
+ "Segment",
2506
+ "Mixpanel",
2507
+ "Amplitude",
2508
+ "Heap",
2509
+ "Matomo",
2510
+ "Plausible",
2511
+ "PostHog",
2512
+ "LinkedIn Insight",
2513
+ "TikTok Pixel",
2514
+ "Microsoft Advertising UET",
2515
+ "Piano Analytics"
2516
+ ];
2517
+ var SENDS_HITS = new Set(ANALYTICS_TOOLS.filter((t) => t !== "Google Tag Manager"));
2518
+ var line = (v, n) => typeof v === "string" ? v.replace(/[\u0000-\u001f\u007f\u2028\u2029]+/g, " ").replace(/\s+/g, " ").trim().slice(0, n) : "";
2519
+ var opt = (v, n) => typeof v === "string" ? line(v, n) : null;
2520
+ var int = (v, max = 1e9) => typeof v === "number" && Number.isFinite(v) ? Math.max(0, Math.min(max, Math.round(v))) : 0;
2521
+ var web = (v) => {
2522
+ const s = line(v, 600);
2523
+ try {
2524
+ const u = new URL(s);
2525
+ return (u.protocol === "https:" || u.protocol === "http:") && !u.username && !u.password ? u.href : "";
2526
+ } catch {
2527
+ return "";
2528
+ }
2529
+ };
2530
+ var list = (v, n, f) => Array.isArray(v) ? v.slice(0, n).map(f).filter((x) => x !== null && x !== undefined && x !== "") : [];
2531
+ var ID = /^[A-Za-z0-9-]{1,30}$/;
2532
+ var obj = (v) => v && typeof v === "object" && !Array.isArray(v) ? v : {};
2533
+ function cleanTool(v) {
2534
+ const t = obj(v);
2535
+ if (!ANALYTICS_TOOLS.includes(String(t.tool)))
2536
+ return null;
2537
+ const cm = t.consent_mode;
2538
+ return {
2539
+ tool: t.tool,
2540
+ ids: list(t.ids, 10, (x) => typeof x === "string" && ID.test(x) ? x : null),
2541
+ loaded: t.loaded === true,
2542
+ scripts: int(t.scripts, 1000),
2543
+ hits: int(t.hits, 1e5),
2544
+ consentMode: cm === "granted" || cm === "denied" || cm === "mixed" ? cm : null
2545
+ };
2546
+ }
2547
+ function cleanPage(v) {
2548
+ const p = obj(v);
2549
+ const url = web(p.url);
2550
+ if (!url)
2551
+ return null;
2552
+ const og = obj(p.og);
2553
+ const tw = obj(p.twitter);
2554
+ const a = obj(p.analytics);
2555
+ return {
2556
+ url,
2557
+ status: int(p.status, 999),
2558
+ title: line(p.title, 300),
2559
+ titles: int(p.titles, 100),
2560
+ description: opt(p.description, 600),
2561
+ descriptions: int(p.descriptions, 100),
2562
+ robots: opt(p.robots, 200),
2563
+ googlebot: opt(p.googlebot, 200),
2564
+ viewport: opt(p.viewport, 200),
2565
+ lang: line(p.lang, 40),
2566
+ canonical: list(p.canonical, 5, web),
2567
+ h1: list(p.h1, 10, (x) => line(x, 150)),
2568
+ h1Count: int(p.h1_count, 1000),
2569
+ headingSkips: int(p.heading_skips, 1000),
2570
+ words: int(p.words),
2571
+ images: int(p.images, 1e5),
2572
+ imagesNoAlt: int(p.images_no_alt, 1e5),
2573
+ linksInternal: int(p.links_internal, 1e5),
2574
+ linksExternal: int(p.links_external, 1e5),
2575
+ linksEmpty: int(p.links_empty, 1e5),
2576
+ og: { title: opt(og.title, 300), description: opt(og.description, 600), image: web(og.image) || null, url: web(og.url) || null, type: opt(og.type, 60) },
2577
+ twitter: { card: opt(tw.card, 60), title: opt(tw.title, 300), image: web(tw.image) || null },
2578
+ jsonldTypes: list(p.jsonld_types, 30, (x) => line(x, 60)),
2579
+ jsonldErrors: list(p.jsonld_errors, 5, (x) => line(x, 120)),
2580
+ hreflang: list(p.hreflang, 50, (x) => {
2581
+ const h = obj(x);
2582
+ const href = web(h.href);
2583
+ const lang = line(h.lang, 20);
2584
+ return href && /^[A-Za-z]{1,8}(-[A-Za-z0-9]{1,8})*$|^x-default$/i.test(lang) ? { lang, href } : null;
2585
+ }),
2586
+ favicon: p.favicon === true,
2587
+ mixed: int(p.mixed, 1e5),
2588
+ bytes: int(p.bytes),
2589
+ requests: int(p.requests, 1e5),
2590
+ analytics: { tools: list(a.tools, 30, cleanTool), dataLayer: typeof a.data_layer === "number" ? int(a.data_layer, 1e6) : null, consentManager: opt(a.consent_manager, 40) || null }
2591
+ };
2592
+ }
2593
+ function cleanSite(v) {
2594
+ const s = obj(v);
2595
+ let origin = "";
2596
+ try {
2597
+ const u = new URL(web(s.origin));
2598
+ origin = u.origin;
2599
+ } catch {
2600
+ return null;
2601
+ }
2602
+ const r = obj(s.robots);
2603
+ const m = obj(s.sitemap);
2604
+ return {
2605
+ origin,
2606
+ robots: { status: int(r.status, 999), userAgentStar: r.user_agent_star === true, disallow: list(r.disallow, 100, (x) => line(x, 200)), sitemaps: list(r.sitemaps, 20, web) },
2607
+ sitemap: { url: web(m.url), status: int(m.status, 999), xml: m.xml === true, index: m.index === true, urls: int(m.urls, 1e7) }
2608
+ };
2609
+ }
2610
+ function seoData(raw) {
2611
+ const d = obj(raw);
2612
+ return { pages: list(d.pages, 100, cleanPage), sites: list(d.sites, 100, cleanSite) };
2613
+ }
2614
+ function robotsBlocks(rule, pathAndQuery) {
2615
+ if (!rule || rule.length > 200)
2616
+ return false;
2617
+ const anchored = rule.endsWith("$");
2618
+ const body = (anchored ? rule.slice(0, -1) : rule).split("*").map((part) => part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join(".*");
2619
+ return new RegExp(`^${body}${anchored ? "$" : ""}`, "s").test(pathAndQuery);
2620
+ }
2621
+ var ck = (id, label, status, text, weight = 1) => ({ id, label, status, text, weight });
2622
+ var noindex = (v) => Boolean(v && /\bnoindex\b|\bnone\b/i.test(v));
2623
+ var plural = (n, w) => `${n} ${w}${n === 1 ? "" : "s"}`;
2624
+ function pageChecks(p, others, site) {
2625
+ const out = [];
2626
+ const u = new URL(p.url);
2627
+ out.push(p.status === 0 ? ck("status", "Page answers", "warn", "The status code was not reported.", 3) : p.status >= 400 ? ck("status", "Page answers", "fail", `The page answered ${p.status}.`, 3) : ck("status", "Page answers", "pass", `The page answered ${p.status}.`, 3));
2628
+ out.push(u.protocol === "https:" ? ck("https", "Served over HTTPS", "pass", "The page is served over HTTPS.", 2) : ck("https", "Served over HTTPS", "fail", "The page is served over plain HTTP.", 2));
2629
+ const blockedBy = site?.robots.disallow.find((r) => robotsBlocks(r, `${u.pathname}${u.search}`));
2630
+ if (noindex(p.robots) || noindex(p.googlebot))
2631
+ out.push(ck("indexable", "Search engines may index it", "fail", `A robots meta tag says "${p.robots || p.googlebot}".`, 3));
2632
+ else if (blockedBy)
2633
+ out.push(ck("indexable", "Search engines may index it", "fail", `robots.txt disallows it for every crawler ("Disallow: ${blockedBy}").`, 3));
2634
+ else
2635
+ out.push(ck("indexable", "Search engines may index it", "pass", "Nothing tells search engines to leave it out.", 3));
2636
+ const t = p.title.length;
2637
+ out.push(!t ? ck("title", "Title", "fail", "The page has no title.", 3) : t < 15 || t > 60 ? ck("title", "Title", "warn", `The title is ${t} characters; 15 to 60 shows in full in results.`, 3) : ck("title", "Title", "pass", `"${p.title}" (${t} characters).`, 3));
2638
+ if (t && others.some((o) => o.url !== p.url && o.title === p.title))
2639
+ out.push(ck("title-unique", "Title is unique", "warn", "Another scanned page has the same title.", 1));
2640
+ if (p.titles > 1)
2641
+ out.push(ck("title-once", "One title", "warn", `The page has ${p.titles} <title> elements.`, 1));
2642
+ const d = (p.description || "").length;
2643
+ out.push(!d ? ck("description", "Meta description", "warn", "No meta description: search engines write their own snippet.", 2) : d < 70 || d > 160 ? ck("description", "Meta description", "warn", `The description is ${d} characters; 70 to 160 suits a result's snippet.`, 2) : ck("description", "Meta description", "pass", `${d} characters.`, 2));
2644
+ if (d && others.some((o) => o.url !== p.url && o.description === p.description))
2645
+ out.push(ck("description-unique", "Description is unique", "warn", "Another scanned page has the same description.", 1));
2646
+ if (p.descriptions > 1)
2647
+ out.push(ck("description-once", "One description", "warn", `The page has ${p.descriptions} meta descriptions.`, 1));
2648
+ out.push(p.h1Count === 1 ? ck("h1", "One main heading", "pass", `"${p.h1[0] || ""}".`, 2) : p.h1Count === 0 ? ck("h1", "One main heading", "fail", "The page has no <h1>.", 2) : ck("h1", "One main heading", "warn", `The page has ${p.h1Count} <h1> headings.`, 2));
2649
+ out.push(p.headingSkips ? ck("headings", "Heading levels in order", "warn", `${plural(p.headingSkips, "heading")} skip a level.`, 1) : ck("headings", "Heading levels in order", "pass", "No heading skips a level.", 1));
2650
+ out.push(p.lang ? ck("lang", "Language declared", "pass", `lang="${p.lang}".`, 1) : ck("lang", "Language declared", "warn", "<html> has no lang attribute.", 1));
2651
+ out.push(p.words < 200 ? ck("content", "Enough text", "warn", `${plural(p.words, "word")} of text; thin pages rank poorly.`, 1) : ck("content", "Enough text", "pass", `${plural(p.words, "word")}.`, 1));
2652
+ if (!p.canonical.length)
2653
+ out.push(ck("canonical", "Canonical address", "warn", "No canonical link: duplicates of this page may be indexed instead.", 2));
2654
+ else if (new Set(p.canonical).size > 1)
2655
+ out.push(ck("canonical", "Canonical address", "fail", `${p.canonical.length} different canonical links.`, 2));
2656
+ else {
2657
+ const c = new URL(p.canonical[0]);
2658
+ if (c.origin !== u.origin)
2659
+ out.push(ck("canonical", "Canonical address", "warn", `The canonical link points to another site (${c.origin}).`, 2));
2660
+ else if (`${c.origin}${c.pathname}` !== `${u.origin}${u.pathname}`)
2661
+ out.push(ck("canonical", "Canonical address", "warn", `The canonical link points to another page (${c.pathname}).`, 2));
2662
+ else
2663
+ out.push(ck("canonical", "Canonical address", "pass", "The page names itself as canonical.", 2));
2664
+ }
2665
+ if (p.hreflang.length) {
2666
+ const self = p.hreflang.some((h) => h.href.replace(/\/$/, "") === p.url.replace(/\/$/, ""));
2667
+ const xd = p.hreflang.some((h) => h.lang.toLowerCase() === "x-default");
2668
+ out.push(self && xd ? ck("hreflang", "Language versions", "pass", `${plural(p.hreflang.length, "language version")}, with x-default.`, 1) : ck("hreflang", "Language versions", "warn", `${!self ? "The hreflang links leave out this page itself" : ""}${!self && !xd ? "; " : ""}${!xd ? "no x-default" : ""}.`, 1));
2669
+ }
2670
+ out.push(p.viewport ? ck("viewport", "Mobile viewport", "pass", p.viewport, 2) : ck("viewport", "Mobile viewport", "fail", "No viewport meta tag: phones show the desktop page shrunk.", 2));
2671
+ out.push(p.mixed ? ck("mixed", "No mixed content", "fail", `${plural(p.mixed, "resource")} loaded over plain HTTP on an HTTPS page.`, 2) : ck("mixed", "No mixed content", "pass", "Every resource is loaded over HTTPS.", 2));
2672
+ const mb = p.bytes / 1024 / 1024;
2673
+ out.push(mb > 3 ? ck("weight", "Page weight", "warn", `${mb.toFixed(1)} MB in ${p.requests} requests.`, 1) : ck("weight", "Page weight", "pass", `${mb >= 1 ? `${mb.toFixed(1)} MB` : `${Math.round(p.bytes / 1024)} KB`} in ${p.requests} requests.`, 1));
2674
+ out.push(p.imagesNoAlt ? ck("img-alt", "Images described", "warn", `${plural(p.imagesNoAlt, "image")} of ${p.images} have no alt attribute.`, 1) : ck("img-alt", "Images described", "pass", p.images ? `All ${plural(p.images, "image")} have an alt attribute.` : "No images.", 1));
2675
+ out.push(p.linksEmpty ? ck("link-text", "Links have text", "warn", `${plural(p.linksEmpty, "link")} have no text a crawler can read.`, 1) : ck("link-text", "Links have text", "pass", `${p.linksInternal} internal and ${p.linksExternal} external links.`, 1));
2676
+ const ogMissing = ["title", "description", "image"].filter((k) => !p.og[k]);
2677
+ out.push(ogMissing.length ? ck("social", "Social preview", "warn", `Open Graph ${ogMissing.join(", ")} missing: shared links show a plain preview.`, 1) : ck("social", "Social preview", "pass", `Open Graph title, description and image${p.twitter.card ? `; Twitter card "${p.twitter.card}"` : ""}.`, 1));
2678
+ if (p.jsonldErrors.length)
2679
+ out.push(ck("structured-data", "Structured data", "fail", `${plural(p.jsonldErrors.length, "JSON-LD block")} could not be read: ${p.jsonldErrors[0]}`, 2));
2680
+ else
2681
+ out.push(p.jsonldTypes.length ? ck("structured-data", "Structured data", "pass", p.jsonldTypes.join(", "), 1) : ck("structured-data", "Structured data", "warn", "No structured data (JSON-LD): no rich results.", 1));
2682
+ out.push(p.favicon ? ck("favicon", "Favicon", "pass", "The page links an icon.", 1) : ck("favicon", "Favicon", "warn", "No icon link.", 1));
2683
+ return out;
2684
+ }
2685
+ function siteChecks(s) {
2686
+ const out = [];
2687
+ const r = s.robots;
2688
+ if (r.status === 404 || r.status === 410)
2689
+ out.push(ck("robots", "robots.txt", "warn", "No robots.txt: crawlers may crawl everything.", 1));
2690
+ else if (r.status >= 200 && r.status < 300)
2691
+ out.push(r.disallow.includes("/") ? ck("robots", "robots.txt", "fail", 'robots.txt disallows the whole site for every crawler ("Disallow: /").', 3) : ck("robots", "robots.txt", "pass", `${plural(r.disallow.length, "path")} disallowed for every crawler.`, 1));
2692
+ else
2693
+ out.push(ck("robots", "robots.txt", "warn", r.status ? `robots.txt answered ${r.status}.` : "robots.txt could not be read.", 1));
2694
+ const m = s.sitemap;
2695
+ out.push(m.xml ? ck("sitemap", "Sitemap", "pass", `${m.index ? "A sitemap index" : "A sitemap"} with ${m.urls} ${m.urls === 1 ? "entry" : "entries"}.`, 2) : ck("sitemap", "Sitemap", "warn", m.status === 200 ? `${m.url} is not a sitemap.` : `No sitemap at ${m.url}${m.status ? ` (${m.status})` : ""}.`, 2));
2696
+ if (m.xml && !r.sitemaps.length)
2697
+ out.push(ck("sitemap-listed", "Sitemap in robots.txt", "warn", "robots.txt does not name the sitemap.", 1));
2698
+ return out;
2699
+ }
2700
+ function score(checks) {
2701
+ const total = checks.reduce((a, c) => a + c.weight, 0);
2702
+ const got = checks.reduce((a, c) => a + (c.status === "pass" ? c.weight : c.status === "warn" ? c.weight / 2 : 0), 0);
2703
+ return total ? Math.round(got / total * 100) : 100;
2704
+ }
2705
+ function analyticsOf(pages) {
2706
+ const by = new Map;
2707
+ const findings = [];
2708
+ const add = (tool, status, text, page) => {
2709
+ const f = findings.find((x) => x.tool === tool && x.text === text);
2710
+ if (f)
2711
+ f.pages.push(page);
2712
+ else
2713
+ findings.push({ tool, status, text, pages: [page] });
2714
+ };
2715
+ for (const p of pages) {
2716
+ const cmp = p.analytics.consentManager;
2717
+ for (const t of p.analytics.tools) {
2718
+ const e = by.get(t.tool) || { pages: [], ids: new Set, hits: 0 };
2719
+ e.pages.push(p.url);
2720
+ for (const i of t.ids)
2721
+ e.ids.add(i);
2722
+ e.hits += t.hits;
2723
+ by.set(t.tool, e);
2724
+ if (t.tool === "Universal Analytics")
2725
+ add(t.tool, "fail", "Universal Analytics stopped processing data in July 2024: this tag collects nothing.", p.url);
2726
+ if (t.scripts > 1)
2727
+ add(t.tool, "warn", "Loaded more than once on the page: hits may be counted twice.", p.url);
2728
+ if (t.tool === "Google Analytics 4" && t.ids.length > 1)
2729
+ add(t.tool, "warn", "More than one GA4 measurement id on the page.", p.url);
2730
+ if (SENDS_HITS.has(t.tool) && t.loaded && !t.hits && t.consentMode !== "denied")
2731
+ add(t.tool, "warn", cmp ? "Loaded but sent no hit (it may wait for consent)." : "Loaded but sent no hit.", p.url);
2732
+ if (cmp && t.hits && t.consentMode !== "denied")
2733
+ add(t.tool, "fail", `Sent ${t.consentMode === "granted" ? "hits marked as consented" : "hits"} before anyone answered the ${cmp} consent banner.`, p.url);
2734
+ if (t.consentMode === "denied")
2735
+ add(t.tool, "pass", "Google consent mode: only cookieless pings until consent.", p.url);
2736
+ }
2737
+ if (!cmp && p.analytics.tools.some((t) => SENDS_HITS.has(t.tool) && t.hits))
2738
+ add("Consent", "warn", "Analytics sent hits and no consent banner was found.", p.url);
2739
+ }
2740
+ const tools = [...by.entries()].map(([tool, e]) => ({ tool, pages: e.pages, ids: [...e.ids].sort(), hits: e.hits })).sort((a, b) => b.pages.length - a.pages.length || a.tool.localeCompare(b.tool));
2741
+ const bySite = new Map;
2742
+ for (const p of pages) {
2743
+ const o = new URL(p.url).origin;
2744
+ bySite.set(o, [...bySite.get(o) || [], p]);
2745
+ }
2746
+ const many = bySite.size > 1;
2747
+ for (const [site, own] of bySite) {
2748
+ const where = many ? ` of ${new URL(site).host}` : "";
2749
+ for (const t of tools) {
2750
+ const on = own.filter((p) => t.pages.includes(p.url));
2751
+ if (own.length > 1 && on.length && on.length < own.length)
2752
+ findings.push({ tool: t.tool, status: "warn", text: `On ${on.length} of ${own.length} pages${where}: the others are not measured.`, pages: own.filter((p) => !on.includes(p)).map((p) => p.url) });
2753
+ }
2754
+ if (!own.some((p) => p.analytics.tools.length))
2755
+ findings.push({ tool: "Analytics", status: "warn", text: `No analytics tag was found on any scanned page${where}.`, pages: own.map((p) => p.url) });
2756
+ }
2757
+ const order = { fail: 0, warn: 1, pass: 2 };
2758
+ return { tools, consentManagers: [...new Set(pages.map((p) => p.analytics.consentManager).filter((x) => Boolean(x)))], findings: findings.sort((a, b) => order[a.status] - order[b.status]) };
2759
+ }
2760
+ function seoReport(data) {
2761
+ const siteOf = (url) => data.sites.find((s) => s.origin === new URL(url).origin);
2762
+ const pages = data.pages.map((p) => {
2763
+ const checks = pageChecks(p, data.pages, siteOf(p.url));
2764
+ return { url: p.url, title: p.title, score: score(checks), checks };
2765
+ });
2766
+ const sites = data.sites.map((s) => ({ origin: s.origin, checks: siteChecks(s) }));
2767
+ const all = [...pages.map((p) => p.score)];
2768
+ return { pages, sites, score: all.length ? Math.round(all.reduce((a, b) => a + b, 0) / all.length) : 0, analytics: analyticsOf(data.pages) };
2769
+ }
2770
+
2771
+ // src/a11y/runtime.ts
2772
+ var samePage = (a, b) => {
2773
+ try {
2774
+ const x = new URL(a);
2775
+ const y = new URL(b);
2776
+ return x.origin === y.origin && x.pathname.replace(/\/+$/, "") === y.pathname.replace(/\/+$/, "");
2777
+ } catch {
2778
+ return a === b;
2779
+ }
2780
+ };
2781
+ var pageKeyOf = (u) => {
2782
+ try {
2783
+ const x = new URL(u);
2784
+ return `${x.origin}${x.pathname.replace(/(?<!\/)\/+$/, "") || "/"}`;
2785
+ } catch {
2786
+ return u;
2787
+ }
2788
+ };
2789
+ var cssString = (v) => `"${v.replace(/\\/g, "\\\\").replace(/"/g, "\\\"").replace(/[\n\r\f]/g, " ")}"`;
2790
+ function contextOptions(e) {
2791
+ return {
2792
+ viewport: e.viewport,
2793
+ deviceScaleFactor: e.deviceScaleFactor,
2794
+ isMobile: e.isMobile,
2795
+ hasTouch: e.hasTouch,
2796
+ ...e.userAgent ? { userAgent: e.userAgent } : {},
2797
+ ...e.colorScheme ? { colorScheme: e.colorScheme } : {},
2798
+ ...e.reducedMotion ? { reducedMotion: e.reducedMotion } : {},
2799
+ ...e.forcedColors ? { forcedColors: e.forcedColors } : {},
2800
+ ...e.contrast ? { contrast: e.contrast } : {}
2801
+ };
2802
+ }
2803
+ async function cdp(page) {
2804
+ return page.context().newCDPSession(page);
2805
+ }
2806
+ async function applyEmulation(page, e) {
2807
+ if (!e.vision && !e.fontScale)
2808
+ return;
2809
+ const s = await cdp(page);
2810
+ if (e.vision)
2811
+ await s.send("Emulation.setEmulatedVisionDeficiency", { type: e.vision });
2812
+ if (e.fontScale)
2813
+ await s.send("Page.setFontSizes", { fontSizes: { standard: Math.round(16 * e.fontScale), fixed: Math.round(13 * e.fontScale) } });
2814
+ }
2815
+ var IDENTITY_FN = `function () {
2816
+ const a = (n) => (this.getAttribute(n) || '').slice(0, 200);
2817
+ return { tag: this.tagName.toLowerCase(), id: (this.id || '').slice(0, 200), testid: a('data-testid') || a('data-test') || a('data-cy'), href: a('href') };
2818
+ }`;
2819
+ var axValue = (v) => v && typeof v === "object" ? String(v.value ?? "") : "";
2820
+ async function focusIdentity(page) {
2821
+ const s = await cdp(page);
2822
+ try {
2823
+ const ref = await s.send("Runtime.evaluate", { expression: "document.activeElement === document.body || !document.activeElement ? null : document.activeElement", returnByValue: false });
2824
+ const objectId = ref?.result?.objectId;
2825
+ if (!objectId)
2826
+ return {};
2827
+ const out = {};
2828
+ const tree = await s.send("Accessibility.getPartialAXTree", { objectId, fetchRelatives: false });
2829
+ const node = (tree?.nodes || []).find((n) => !n.ignored);
2830
+ if (node) {
2831
+ out.role = axValue(node.role).slice(0, 40);
2832
+ out.name = axValue(node.name).replace(/\s+/g, " ").trim().slice(0, 150);
2833
+ }
2834
+ const dom = await s.send("Runtime.callFunctionOn", { objectId, functionDeclaration: IDENTITY_FN, returnByValue: true });
2835
+ for (const [k, v] of Object.entries(dom?.result?.value || {}))
2836
+ if (typeof v === "string" && v && ["tag", "id", "testid", "href"].includes(k))
2837
+ out[k] = v;
2838
+ return out;
2839
+ } finally {
2840
+ await s.detach().catch(() => {});
2841
+ }
2842
+ }
2843
+ var norm = (s) => (s || "").replace(/\s+/g, " ").trim().toLowerCase();
2844
+ function sameIdent(recorded, now) {
2845
+ if (!recorded || !Object.keys(recorded).length)
2846
+ return true;
2847
+ if (recorded.testid)
2848
+ return recorded.testid === now.testid;
2849
+ if (recorded.id)
2850
+ return recorded.id === now.id;
2851
+ if (recorded.role || recorded.name)
2852
+ return norm(recorded.role) === norm(now.role) && norm(recorded.name) === norm(now.name);
2853
+ return recorded.tag === now.tag;
2854
+ }
2855
+ var describeIdent = (i) => !i ? "nothing" : `${i.role || i.tag || "element"}${i.name ? ` "${i.name}"` : ""}${i.testid ? ` [${i.testid}]` : i.id ? ` #${i.id}` : ""}`;
2856
+ var CHROME_TO_ARIA = { image: "img", StaticText: "", generic: "", LabelText: "", paragraph: "paragraph", RootWebArea: "", Section: "region", DescriptionListTerm: "term", DescriptionListDetail: "definition", ListMarker: "", LayoutTable: "table", LayoutTableRow: "row", LayoutTableCell: "cell" };
2857
+ var ARIA_ROLES = new Set("alert alertdialog application article banner blockquote button caption cell checkbox code columnheader combobox complementary contentinfo definition deletion dialog directory document emphasis feed figure form generic grid gridcell group heading img insertion link list listbox listitem log main marquee math menu menubar menuitem menuitemcheckbox menuitemradio meter navigation none note option paragraph presentation progressbar radio radiogroup region row rowgroup rowheader scrollbar search searchbox separator slider spinbutton status strong subscript superscript switch tab table tablist tabpanel term textbox time timer toolbar tooltip tree treegrid treeitem".split(" "));
2858
+ var ariaRole = (role) => {
2859
+ if (!role)
2860
+ return;
2861
+ const r = Object.hasOwn(CHROME_TO_ARIA, role) ? CHROME_TO_ARIA[role] : role;
2862
+ return r && ARIA_ROLES.has(r) ? r : undefined;
2863
+ };
2864
+ function byIdent(page, i) {
2865
+ if (i.testid)
2866
+ return page.locator(`[data-testid=${cssString(i.testid)}], [data-test=${cssString(i.testid)}], [data-cy=${cssString(i.testid)}]`).first();
2867
+ if (i.id)
2868
+ return page.locator(`[id=${cssString(i.id)}]`).first();
2869
+ const role = ariaRole(i.role);
2870
+ if (role && i.name)
2871
+ return page.getByRole(role, { name: i.name, exact: true }).first();
2872
+ if (i.name)
2873
+ return page.getByText(new RegExp(`^\\s*${i.name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\s*$`, "i")).or(page.getByLabel(i.name, { exact: true })).first();
2874
+ return page.locator(`[id=${cssString("\x00none")}]`);
2875
+ }
2876
+ async function byLocators(page, locs) {
2877
+ for (const l of locs) {
2878
+ let loc;
2879
+ switch (l.type) {
2880
+ case "test_id":
2881
+ loc = page.locator(`[${l.attr || "data-testid"}=${cssString(l.value)}]`);
2882
+ break;
2883
+ case "id":
2884
+ loc = page.locator(`[id=${cssString(l.value)}]`);
2885
+ break;
2886
+ case "role": {
2887
+ const at = l.value.indexOf("|");
2888
+ loc = at < 0 ? page.getByRole(l.value) : page.getByRole(l.value.slice(0, at), { name: l.value.slice(at + 1), exact: true });
2889
+ break;
2890
+ }
2891
+ case "label":
2892
+ loc = page.getByLabel(l.value, { exact: true });
2893
+ break;
2894
+ case "placeholder":
2895
+ loc = page.getByPlaceholder(l.value, { exact: true });
2896
+ break;
2897
+ case "alt":
2898
+ loc = page.getByAltText(l.value, { exact: true });
2899
+ break;
2900
+ case "title":
2901
+ loc = page.getByTitle(l.value, { exact: true });
2902
+ break;
2903
+ default:
2904
+ loc = page.getByText(l.value, { exact: true });
2905
+ }
2906
+ try {
2907
+ if (await loc.count() >= 1)
2908
+ return loc.first();
2909
+ } catch {}
2910
+ }
2911
+ return null;
2912
+ }
2913
+ var pathOf = (u) => {
2914
+ try {
2915
+ return new URL(u).pathname;
2916
+ } catch {
2917
+ return u;
2918
+ }
2919
+ };
2920
+ async function runJourney(page, steps, opts) {
2921
+ const seen = new Set;
2922
+ const pages = [];
2923
+ const timeout = opts.stepTimeoutMs ?? 1e4;
2924
+ const visit = async () => {
2925
+ const k = pageKeyOf(page.url());
2926
+ if (seen.has(k) || !/^https?:/.test(page.url()))
2927
+ return;
2928
+ seen.add(k);
2929
+ pages.push(k);
2930
+ await page.waitForLoadState("load", { timeout }).catch(() => {});
2931
+ await opts.onPage?.(page);
2932
+ };
2933
+ const value = (t) => {
2934
+ if (!t.secret)
2935
+ return t.text || "";
2936
+ const v = opts.secrets?.[t.secret];
2937
+ if (v === undefined)
2938
+ throw new Error(`set the environment variable ${t.secret}: the journey types its value`);
2939
+ return v;
2940
+ };
2941
+ let expected;
2942
+ for (const [i, s] of steps.entries()) {
2943
+ const fail = (error) => ({ ok: false, steps: steps.length, done: i, failedAt: i + 1, error: `Step ${i + 1} (${s.op}): ${error}`, pages });
2944
+ try {
2945
+ if (s.op === "wait") {
2946
+ await page.waitForTimeout(s.seconds * 1000);
2947
+ continue;
2948
+ }
2949
+ if (s.op === "navigate") {
2950
+ await page.goto(s.url, { timeout: timeout * 3 });
2951
+ expected = s.url;
2952
+ await visit();
2953
+ continue;
2954
+ }
2955
+ if (!samePage(page.url(), s.url)) {
2956
+ if (expected && samePage(expected, s.url)) {
2957
+ try {
2958
+ await page.waitForURL((u) => samePage(String(u), s.url), { timeout });
2959
+ } catch {
2960
+ return fail(`the step before no longer leads to ${pathOf(s.url)} (the page is ${pathOf(page.url())})`);
2961
+ }
2962
+ } else
2963
+ await page.goto(s.url, { timeout: timeout * 3 });
2964
+ await visit();
2965
+ }
2966
+ switch (s.op) {
2967
+ case "press": {
2968
+ await page.keyboard.press(s.key);
2969
+ await page.waitForTimeout(150);
2970
+ const now = await focusIdentity(page);
2971
+ if (s.focus && !sameIdent(s.focus, now))
2972
+ return fail(`${s.key} now puts focus on ${describeIdent(now)}, not ${describeIdent(s.focus)}`);
2973
+ break;
2974
+ }
2975
+ case "type":
2976
+ await page.keyboard.insertText(value(s));
2977
+ break;
2978
+ case "tap": {
2979
+ const el = byIdent(page, s.target);
2980
+ if (!await el.count())
2981
+ return fail(`${describeIdent(s.target)} is no longer on the page`);
2982
+ await el.scrollIntoViewIfNeeded({ timeout }).catch(() => {});
2983
+ if (page.context()._options?.hasTouch !== false)
2984
+ await el.tap({ timeout }).catch(async () => el.click({ timeout }));
2985
+ else
2986
+ await el.click({ timeout });
2987
+ break;
2988
+ }
2989
+ case "swipe":
2990
+ if (s.item && (s.item.testid || s.item.id || s.item.role && s.item.name) && !await byIdent(page, s.item).count())
2991
+ return fail(`${describeIdent(s.item)} is no longer on the page`);
2992
+ break;
2993
+ case "click": {
2994
+ const el = await byLocators(page, s.locators);
2995
+ if (!el)
2996
+ return fail(`the element it clicked is not on the page any more`);
2997
+ await el.click({ timeout });
2998
+ break;
2999
+ }
3000
+ case "fill": {
3001
+ const el = await byLocators(page, s.locators);
3002
+ if (!el)
3003
+ return fail(`the field it typed in is not on the page any more`);
3004
+ await el.fill(value(s), { timeout });
3005
+ break;
3006
+ }
3007
+ case "select": {
3008
+ const el = await byLocators(page, s.locators);
3009
+ if (!el)
3010
+ return fail(`the list it chose from is not on the page any more`);
3011
+ await el.selectOption({ label: s.label }, { timeout });
3012
+ break;
3013
+ }
3014
+ case "scroll":
3015
+ await page.mouse.wheel(0, s.down ? 600 : -600);
3016
+ break;
3017
+ }
3018
+ expected = "after" in s ? s.after : s.url;
3019
+ if (expected && !samePage(expected, s.url)) {
3020
+ try {
3021
+ await page.waitForURL((u) => samePage(String(u), expected), { timeout });
3022
+ } catch {
3023
+ return fail(`it no longer leads to ${pathOf(expected)} (the page is ${pathOf(page.url())})`);
3024
+ }
3025
+ }
3026
+ await visit();
3027
+ } catch (err) {
3028
+ return fail(String(err?.message || err).split(`
3029
+ `)[0].slice(0, 300));
3030
+ }
3031
+ }
3032
+ return { ok: true, steps: steps.length, done: steps.length, pages };
3033
+ }
3034
+ var WCAG_SC = /^wcag(\d)(\d)(\d{1,2})$/;
3035
+ var WCAG_LEVEL = /^wcag2\d?(a{1,3})$/;
3036
+ async function axePage(page, axeSource, tags) {
3037
+ const loaded = await page.evaluate("typeof window.axe !== 'undefined'");
3038
+ if (!loaded)
3039
+ await page.evaluate(axeSource);
3040
+ const r = await page.evaluate(async (t) => {
3041
+ const res = await window.axe.run(document, { runOnly: { type: "tag", values: t }, resultTypes: ["violations"] });
3042
+ return {
3043
+ version: res.testEngine && res.testEngine.version,
3044
+ passed: res.passes.map((p) => p.id),
3045
+ incomplete: res.incomplete.map((p) => p.id),
3046
+ violations: res.violations.map((v) => ({ id: v.id, impact: v.impact, help: v.help, helpUrl: v.helpUrl, tags: v.tags, count: v.nodes.length, examples: v.nodes.slice(0, 5).map((n) => ({ html: String(n.html || "").slice(0, 160), target: (n.target || []).join(" ") })) }))
3047
+ };
3048
+ }, tags);
3049
+ const order = ["critical", "serious", "moderate", "minor"];
3050
+ return {
3051
+ url: page.url(),
3052
+ title: String(await page.title()).slice(0, 300),
3053
+ engine: `axe-core ${r.version || ""}`.trim(),
3054
+ tags,
3055
+ passed: r.passed,
3056
+ incomplete: r.incomplete,
3057
+ issues: r.violations.map((v) => {
3058
+ const sc = v.tags.map((t) => WCAG_SC.exec(t)).find(Boolean);
3059
+ const level = v.tags.map((t) => WCAG_LEVEL.exec(t)).find(Boolean);
3060
+ return { rule: v.id, wcag: sc ? `${sc[1]}.${sc[2]}.${sc[3]}` : undefined, level: level ? level[1].toUpperCase() : undefined, impact: v.impact || "minor", help: v.help || "", helpUrl: v.helpUrl || "", count: v.count, examples: v.examples };
3061
+ }).sort((a, b) => order.indexOf(a.impact) - order.indexOf(b.impact) || b.count - a.count)
3062
+ };
3063
+ }
3064
+ async function checkPage(page, scripts, tags, opts) {
3065
+ const out = { url: page.url() };
3066
+ try {
3067
+ if (opts.seo) {
3068
+ const facts = await page.evaluate(scripts.facts);
3069
+ const analytics = await page.evaluate(scripts.analytics);
3070
+ out.seo = { ...facts && typeof facts === "object" ? facts : {}, analytics };
3071
+ const origin = new URL(page.url()).origin;
3072
+ if (opts.sitesSeen && !opts.sitesSeen.has(origin)) {
3073
+ opts.sitesSeen.add(origin);
3074
+ out.site = await page.evaluate(scripts.site);
3075
+ }
3076
+ }
3077
+ out.a11y = await axePage(page, scripts.axe, tags);
3078
+ } catch (err) {
3079
+ out.error = String(err?.message || err).split(`
3080
+ `)[0].slice(0, 300);
3081
+ }
3082
+ return out;
3083
+ }
3084
+ function makeSnapshot(x) {
3085
+ const a11yPages = x.pages.map((p) => p.a11y).filter((p) => Boolean(p));
3086
+ const coverage = coverageMatrix({
3087
+ standard: x.standard,
3088
+ engine: x.engine,
3089
+ traits: x.personas.flatMap((p) => p.traits),
3090
+ evidence: { pages: a11yPages, personas: x.personas.map((p) => ({ name: p.name, traits: p.traits, ran: p.reached !== "unknown", reached: p.reached, findings: p.barriers })) }
3091
+ });
3092
+ const rules = {};
3093
+ for (const p of a11yPages) {
3094
+ const k = pageKeyOf(p.url);
3095
+ rules[k] = [...new Set([...rules[k] || [], ...p.issues.map((i) => i.rule)])].sort();
3096
+ }
3097
+ const seoPages = x.pages.filter((p) => p.seo);
3098
+ const seo = seoPages.length ? seoReport(seoData({ pages: seoPages.map((p) => p.seo), sites: x.pages.map((p) => p.site).filter(Boolean) })) : null;
3099
+ const raw = {
3100
+ run: x.run,
3101
+ at: x.at,
3102
+ criteria: Object.fromEntries(coverage.rows.map((r) => [r.id, r.result || "not_tested"])),
3103
+ rules,
3104
+ broken: x.broken,
3105
+ seo: Object.fromEntries((seo?.pages || []).map((p) => [pageKeyOf(p.url), p.score])),
3106
+ analytics: Object.fromEntries(seoPages.map((p) => [pageKeyOf(p.url), (p.seo?.analytics?.tools || []).map((t) => String(t.tool))])),
3107
+ personas: Object.fromEntries(x.personas.map((p) => [p.key, { reached: p.reached, barriers: [...new Set(p.barriers.map((b) => b.wcag))].sort(), ...p.replayed ? { replayed: true } : {} }]))
3108
+ };
3109
+ return cleanSnapshot(raw);
3110
+ }
3111
+ var LINGER_MS = 2500;
3112
+ async function scanUrl(browser, url, job, scripts, sitesSeen) {
3113
+ const context = await browser.newContext({ viewport: job.window });
3114
+ try {
3115
+ const page = await context.newPage();
3116
+ try {
3117
+ await page.goto(url, { timeout: 45000 });
3118
+ await page.waitForLoadState("load", { timeout: 20000 }).catch(() => {});
3119
+ } catch (err) {
3120
+ return { url, broken: true, error: String(err?.message || err).split(`
3121
+ `)[0].slice(0, 300) };
3122
+ }
3123
+ await page.waitForTimeout(LINGER_MS);
3124
+ return await checkPage(page, scripts, job.tags, { seo: true, sitesSeen });
3125
+ } finally {
3126
+ await context.close().catch(() => {});
3127
+ }
3128
+ }
3129
+ async function replayPersona(browser, session, persona, job, scripts, secrets) {
3130
+ const pages = [];
3131
+ if (!persona.steps.length)
3132
+ return { journey: { ok: false, steps: 0, done: 0, error: "No journey was recorded for this persona: run the session again in ForgeQE to record one.", pages: [] }, pages };
3133
+ const context = await browser.newContext(contextOptions(persona.emulation));
3134
+ try {
3135
+ const page = await context.newPage();
3136
+ await applyEmulation(page, persona.emulation);
3137
+ await page.goto(session.url, { timeout: 45000 });
3138
+ const journey = await runJourney(page, persona.steps, { secrets, onPage: async (p) => void pages.push(await checkPage(p, scripts, job.tags, { seo: false })) });
3139
+ return { journey, pages };
3140
+ } finally {
3141
+ await context.close().catch(() => {});
3142
+ }
3143
+ }
3144
+ function personaOutcome(persona, journey, baseline) {
3145
+ const base = baseline?.personas[persona.key];
3146
+ return {
3147
+ key: persona.key,
3148
+ name: persona.name,
3149
+ traits: persona.traits,
3150
+ reached: journey.ok ? base?.reached || "yes" : journey.steps ? "no" : "unknown",
3151
+ barriers: (base?.barriers || []).map((w) => ({ wcag: w, severity: "moderate", title: "recorded" })),
3152
+ replayed: true
3153
+ };
3154
+ }
3155
+ async function runSuite(browser, job, scripts, baseline, secrets, opts) {
3156
+ const log = opts.log || (() => {});
3157
+ const pages = [];
3158
+ const broken = [];
3159
+ const sites = new Set;
3160
+ for (const url of job.urls) {
3161
+ log(`Scanning ${url}`);
3162
+ const r = await scanUrl(browser, url, job, scripts, sites);
3163
+ if (r.broken)
3164
+ broken.push(pageKeyOf(url));
3165
+ pages.push(r);
3166
+ }
3167
+ const personas = [];
3168
+ const journeys = {};
3169
+ for (const s of job.sessions)
3170
+ for (const p of s.personas) {
3171
+ log(`Replaying ${s.id} as ${p.name}`);
3172
+ const r = await replayPersona(browser, s, p, job, scripts, secrets);
3173
+ journeys[p.key] = r.journey;
3174
+ pages.push(...r.pages);
3175
+ personas.push(personaOutcome(p, r.journey, baseline));
3176
+ log(r.journey.ok ? ` ${p.name}: the journey still works (${r.journey.steps} steps)` : ` ${p.name}: ${r.journey.error}`);
3177
+ }
3178
+ const snapshot = makeSnapshot({ run: opts.run, at: new Date().toISOString(), standard: job.standard, engine: "axe", pages, broken, personas });
3179
+ const { worse, better } = baseline ? compareSnapshots(baseline, snapshot) : { worse: [], better: [] };
3180
+ return { snapshot, worse, better, journeys, pages };
3181
+ }
3182
+ export {
3183
+ LINGER_MS,
3184
+ applyEmulation,
3185
+ ariaRole,
3186
+ axePage,
3187
+ byIdent,
3188
+ checkPage,
3189
+ cleanSnapshot,
3190
+ compareSnapshots,
3191
+ contextOptions,
3192
+ cssString,
3193
+ describeIdent,
3194
+ focusIdentity,
3195
+ makeSnapshot,
3196
+ pageKeyOf,
3197
+ personaOutcome,
3198
+ replayPersona,
3199
+ runJourney,
3200
+ runSuite,
3201
+ sameIdent,
3202
+ samePage,
3203
+ scanUrl
3204
+ };