@poe-platform/safe-bash 0.1.763 → 0.1.765

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 (32) hide show
  1. package/dist/image-ast/index.browser.js +321 -162
  2. package/dist/image-ast/index.js +321 -162
  3. package/dist/pdf-ast/ast.d.ts +2 -0
  4. package/dist/pdf-ast/index.js +340 -173
  5. package/dist/safe-bash/chunks/{chunk-CRQDMBQA.js → chunk-FSH7QRIC.js} +10 -1
  6. package/dist/safe-bash/command-chunks/{chunk-4XHONGIU.js → chunk-DT4MFWV4.js} +2 -2
  7. package/dist/safe-bash/command-chunks/{chunk-S3G2B4OX.js → chunk-KO4PXCNL.js} +324 -162
  8. package/dist/safe-bash/command-chunks/{chunk-S5EX6UP5.js → chunk-SVL6HYQL.js} +1 -1
  9. package/dist/safe-bash/commands/python/index.browser.js +1 -1
  10. package/dist/safe-bash/commands/python/llm-module.js +3 -1
  11. package/dist/safe-bash/commands/python/shell-module.js +7 -0
  12. package/dist/safe-bash/core.browser.js +32 -12
  13. package/dist/safe-bash/shell/runtime.js +43 -11
  14. package/dist/safe-bash-command-ffmpeg/index.js +5800 -5693
  15. package/dist/safe-bash-command-imagemagick/index.js +2 -2
  16. package/dist/safe-bash-command-pandoc/command.js +3 -3
  17. package/dist/safe-bash-command-pandoc/index.js +3 -3
  18. package/dist/safe-bash-command-pdfimages/index.js +321 -162
  19. package/dist/safe-bash-command-pdfinfo/index.js +338 -173
  20. package/dist/safe-bash-command-pdftk/index.js +321 -162
  21. package/dist/safe-bash-command-pdftoppm/index.js +338 -173
  22. package/dist/safe-bash-command-pdftotext/index.js +321 -162
  23. package/dist/safe-bash-command-qpdf/index.js +321 -162
  24. package/dist/safe-bash-command-sips/index.js +2 -2
  25. package/dist/safe-bash-command-soffice/index.js +1 -1
  26. package/dist/safe-bash-command-ssconvert/index.js +373 -169
  27. package/dist/safe-bash-command-wkhtmltopdf/index.js +322 -162
  28. package/dist/safe-playwright-cloudflare/browser-snapshot-labels.d.ts +14 -0
  29. package/dist/safe-playwright-cloudflare/browser-snapshot-labels.js +62 -0
  30. package/dist/safe-playwright-cloudflare/browser-snapshot-scheduler.js +8 -1
  31. package/package.json +2 -2
  32. package/third-party/pdf-ast/THIRD_PARTY_NOTICES.md +24 -0
@@ -11742,11 +11742,10 @@ function evaluateContentStreamToDisplayList(params) {
11742
11742
  } else if (operator === "d") {
11743
11743
  const arrNode = ops[0]?.kind === "array" ? ops[0] : void 0;
11744
11744
  if (arrNode) {
11745
- const ctmScale = Math.max(1e-6, Math.hypot(st.ctm[0], st.ctm[1]));
11746
- const nums = arrNode.items.map((it) => it.kind === "number" ? it.value * ctmScale : 0).filter((v) => v >= 0);
11745
+ const nums = arrNode.items.map((it) => it.kind === "number" ? it.value : 0).filter((v) => v >= 0);
11747
11746
  const sum = nums.reduce((a, b) => a + b, 0);
11748
11747
  st.dashArray = sum > 0 ? nums : void 0;
11749
- st.dashPhase = num(1, 0) * ctmScale;
11748
+ st.dashPhase = num(1, 0);
11750
11749
  } else {
11751
11750
  st.dashArray = void 0;
11752
11751
  st.dashPhase = void 0;
@@ -12282,15 +12281,14 @@ function evaluateContentStreamToDisplayList(params) {
12282
12281
  break;
12283
12282
  }
12284
12283
  const fillRule = node.paint.includes("*") ? "evenodd" : "nonzero";
12285
- const ctmScale = Math.max(1e-6, Math.hypot(st.ctm[0], st.ctm[1]));
12286
- const scaledStrokeWidth = st.strokeWidth === 0 ? 0 : st.strokeWidth * ctmScale;
12287
12284
  emit({ kind: "path", value: {
12288
12285
  segments: transformedSegments,
12289
12286
  fillColor: isFill && !evaluatedFillPattern ? st.fillColor : void 0,
12290
12287
  fillAlpha: isFill && !evaluatedFillPattern ? st.fillAlpha : void 0,
12291
12288
  strokeColor: isStroke ? st.strokeColor : void 0,
12292
12289
  strokeAlpha: isStroke ? st.strokeAlpha : void 0,
12293
- strokeWidth: scaledStrokeWidth,
12290
+ strokeWidth: st.strokeWidth,
12291
+ ...isStroke ? { strokeMatrix: [...st.ctm] } : {},
12294
12292
  ...st.lineCap !== 0 ? { lineCap: st.lineCap } : {},
12295
12293
  ...st.lineJoin !== 0 ? { lineJoin: st.lineJoin } : {},
12296
12294
  ...st.miterLimit !== 10 ? { miterLimit: st.miterLimit } : {},
@@ -12478,14 +12476,14 @@ function evaluateContentStreamToDisplayList(params) {
12478
12476
  if (st.textRenderMode >= 4 && st.textRenderMode <= 7) pendingTextClip.push(...transformedGlyphSegs);
12479
12477
  const isFillGlyph = st.textRenderMode === 0 || st.textRenderMode === 2 || st.textRenderMode === 4 || st.textRenderMode === 6;
12480
12478
  const isStrokeGlyph = st.textRenderMode === 1 || st.textRenderMode === 2 || st.textRenderMode === 5 || st.textRenderMode === 6;
12481
- const ctmScale = Math.max(1e-6, Math.hypot(st.ctm[0], st.ctm[1]));
12482
12479
  const paint = {
12483
12480
  segments: transformedGlyphSegs,
12484
12481
  fillColor: isFillGlyph ? st.fillColor : void 0,
12485
12482
  fillAlpha: isFillGlyph ? st.fillAlpha : void 0,
12486
12483
  strokeColor: isStrokeGlyph ? st.strokeColor : void 0,
12487
12484
  strokeAlpha: isStrokeGlyph ? st.strokeAlpha : void 0,
12488
- strokeWidth: isStrokeGlyph ? st.strokeWidth * ctmScale : 0,
12485
+ strokeWidth: isStrokeGlyph ? st.strokeWidth : 0,
12486
+ ...isStrokeGlyph ? { strokeMatrix: [...st.ctm] } : {},
12489
12487
  fillRule: "nonzero",
12490
12488
  ...st.blendMode && st.blendMode !== "Normal" ? { blendMode: st.blendMode } : {},
12491
12489
  ...st.clipRect ? { clipRect: [...st.clipRect] } : {}
@@ -14078,6 +14076,183 @@ function downscaleImage(image, widthScale, heightScale) {
14078
14076
  }
14079
14077
  return image;
14080
14078
  }
14079
+ function dashSubpath(path, pattern, phase) {
14080
+ const cycle = pattern.reduce((sum, value) => sum + value, 0);
14081
+ if (!(cycle > 0)) return [path];
14082
+ let offset = (phase % cycle + cycle) % cycle, index = 0;
14083
+ while (offset > 0) {
14084
+ if (offset < pattern[index]) break;
14085
+ offset -= pattern[index];
14086
+ index = (index + 1) % pattern.length;
14087
+ }
14088
+ let remaining = pattern[index] - offset;
14089
+ const points = path.closed ? [...path.points, path.points[0]] : path.points;
14090
+ const result = [];
14091
+ let current = [];
14092
+ let steps = 0;
14093
+ const flush = () => {
14094
+ if (current.length) result.push({ points: current, closed: false });
14095
+ current = [];
14096
+ };
14097
+ const advance = (point) => {
14098
+ while (remaining <= 0) {
14099
+ if (++steps > MAX_STROKE_VERTICES) throw new PdfError("E_LIMIT", "Stroke dash expansion exceeds the vertex limit");
14100
+ if (index % 2 === 0) {
14101
+ if (pattern[index] === 0) result.push({ points: [point, point], closed: false });
14102
+ flush();
14103
+ }
14104
+ index = (index + 1) % pattern.length;
14105
+ remaining = pattern[index];
14106
+ }
14107
+ };
14108
+ for (let i = 1; i < points.length; i++) {
14109
+ const start = points[i - 1], end = points[i];
14110
+ const dx = end[0] - start[0], dy = end[1] - start[1];
14111
+ const length2 = Math.hypot(dx, dy);
14112
+ if (!Number.isFinite(length2) || length2 / cycle * pattern.length > MAX_STROKE_VERTICES) {
14113
+ throw new PdfError("E_LIMIT", "Stroke dash expansion exceeds the vertex limit");
14114
+ }
14115
+ let distance = 0;
14116
+ while (distance < length2) {
14117
+ const point = [start[0] + dx * distance / length2, start[1] + dy * distance / length2];
14118
+ advance(point);
14119
+ const step = Math.min(remaining, length2 - distance);
14120
+ if (distance + step === distance || ++steps > MAX_STROKE_VERTICES) throw new PdfError("E_LIMIT", "Stroke dash expansion exceeds the vertex limit");
14121
+ distance += step;
14122
+ remaining -= step;
14123
+ if (index % 2 === 0) {
14124
+ if (!current.length) current.push(point);
14125
+ current.push([start[0] + dx * distance / length2, start[1] + dy * distance / length2]);
14126
+ }
14127
+ }
14128
+ }
14129
+ flush();
14130
+ if (path.closed && result.length) {
14131
+ const first = result[0], last = result[result.length - 1];
14132
+ const start = path.points[0];
14133
+ const firstPoint = first.points[0], lastPoint = last.points[last.points.length - 1];
14134
+ if (firstPoint[0] === start[0] && firstPoint[1] === start[1] && lastPoint[0] === start[0] && lastPoint[1] === start[1]) {
14135
+ if (first === last) result[0] = { points: first.points, closed: true };
14136
+ else {
14137
+ result[0] = { points: [...last.points, ...first.points.slice(1)], closed: false };
14138
+ result.pop();
14139
+ }
14140
+ }
14141
+ }
14142
+ return result;
14143
+ }
14144
+ function strokeOutlines(paths, width, cap, join, miterLimit, dashArray = [], dashPhase = 0) {
14145
+ const half = width / 2;
14146
+ const contours = [];
14147
+ const pattern = dashArray.length % 2 ? [...dashArray, ...dashArray] : dashArray;
14148
+ let count = 0;
14149
+ let contour = [];
14150
+ const add = (x, y) => {
14151
+ if (++count > MAX_STROKE_VERTICES) throw new PdfError("E_LIMIT", "Stroke outline exceeds the vertex limit");
14152
+ contour.push([x, y]);
14153
+ };
14154
+ const arc = (point, dx1, dy1, dx2, dy2) => {
14155
+ let a1 = Math.atan2(dy1, dx1), a2 = Math.atan2(dy2, dx2);
14156
+ const ccw = a1 - a2 > 0 && a1 - a2 < Math.PI;
14157
+ const step = Math.acos(half / (half + 0.125)) * 2;
14158
+ add(point[0] + dx1, point[1] + dy1);
14159
+ if (step > 0) {
14160
+ if (!ccw) {
14161
+ if (a1 > a2) a2 += 2 * Math.PI;
14162
+ a2 -= step / 4;
14163
+ if ((a2 - a1) / step > MAX_STROKE_VERTICES - count) throw new PdfError("E_LIMIT", "Stroke arc exceeds the vertex limit");
14164
+ for (a1 += step; a1 < a2; a1 += step) add(point[0] + half * Math.cos(a1), point[1] + half * Math.sin(a1));
14165
+ } else {
14166
+ if (a1 < a2) a2 -= 2 * Math.PI;
14167
+ a2 += step / 4;
14168
+ if ((a1 - a2) / step > MAX_STROKE_VERTICES - count) throw new PdfError("E_LIMIT", "Stroke arc exceeds the vertex limit");
14169
+ for (a1 -= step; a1 > a2; a1 -= step) add(point[0] + half * Math.cos(a1), point[1] + half * Math.sin(a1));
14170
+ }
14171
+ }
14172
+ add(point[0] + dx2, point[1] + dy2);
14173
+ };
14174
+ const addCap = (point, next) => {
14175
+ const length2 = Math.hypot(next[0] - point[0], next[1] - point[1]);
14176
+ const dx = half * (next[1] - point[1]) / length2;
14177
+ const dy = half * (next[0] - point[0]) / length2;
14178
+ if (cap !== 1) {
14179
+ const sx = cap === 2 ? dy : 0, sy = cap === 2 ? dx : 0;
14180
+ add(point[0] - dx - sx, point[1] + dy - sy);
14181
+ add(point[0] + dx - sx, point[1] - dy - sy);
14182
+ } else {
14183
+ const angle = Math.atan2(dy, -dx);
14184
+ const step = Math.max(1e-3, Math.acos(half / (half + 0.125)) * 2);
14185
+ add(point[0] - dx, point[1] + dy);
14186
+ for (let a = angle + step; a < angle + Math.PI - step / 4; a += step) add(point[0] + half * Math.cos(a), point[1] + half * Math.sin(a));
14187
+ add(point[0] + dx, point[1] - dy);
14188
+ }
14189
+ };
14190
+ const addJoin = (prev, point, next) => {
14191
+ const len1 = Math.hypot(point[0] - prev[0], point[1] - prev[1]);
14192
+ const len2 = Math.hypot(next[0] - point[0], next[1] - point[1]);
14193
+ const dx1 = half * (point[1] - prev[1]) / len1, dy1 = half * (point[0] - prev[0]) / len1;
14194
+ const dx2 = half * (next[1] - point[1]) / len2, dy2 = half * (next[0] - point[0]) / len2;
14195
+ const inner = (next[0] - point[0]) * (point[1] - prev[1]) - (next[1] - point[1]) * (point[0] - prev[0]) > 0;
14196
+ if (!inner && join === 1) {
14197
+ arc(point, dx1, -dy1, dx2, -dy2);
14198
+ return;
14199
+ }
14200
+ if (inner || join === 0) {
14201
+ const ax = prev[0] + dx1, ay = prev[1] - dy1;
14202
+ const bx = point[0] + dx1, by = point[1] - dy1;
14203
+ const cx = point[0] + dx2, cy = point[1] - dy2;
14204
+ const dx = next[0] + dx2, dy = next[1] - dy2;
14205
+ const den = (bx - ax) * (dy - cy) - (by - ay) * (dx - cx);
14206
+ if (Math.abs(den) >= 1e-30) {
14207
+ const t = ((ay - cy) * (dx - cx) - (ax - cx) * (dy - cy)) / den;
14208
+ const x = ax + (bx - ax) * t, y = ay + (by - ay) * t;
14209
+ if (Math.hypot(x - point[0], y - point[1]) <= half * (inner ? 1.01 : miterLimit)) {
14210
+ add(x, y);
14211
+ return;
14212
+ }
14213
+ } else if ((bx - prev[0]) * dy1 - (prev[1] - by) * dx1 < 0 !== (bx - next[0]) * dy1 - (next[1] - by) * dx1 < 0) {
14214
+ add(bx, by);
14215
+ return;
14216
+ }
14217
+ }
14218
+ add(point[0] + dx1, point[1] - dy1);
14219
+ add(point[0] + dx2, point[1] - dy2);
14220
+ };
14221
+ for (const path of paths) {
14222
+ for (const subpath of pattern.length ? dashSubpath(path, pattern, dashPhase) : [path]) {
14223
+ const points = [];
14224
+ for (const point of subpath.points) {
14225
+ const prev = points[points.length - 1];
14226
+ if (!prev || Math.hypot(prev[0] - point[0], prev[1] - point[1]) > 1e-14) points.push(point);
14227
+ }
14228
+ let closed = subpath.closed;
14229
+ if (closed && points.length > 1 && Math.hypot(points[0][0] - points[points.length - 1][0], points[0][1] - points[points.length - 1][1]) <= 1e-14) points.pop();
14230
+ if (points.length < 3) closed = false;
14231
+ if (points.length === 1 && subpath.points.length > 1 && cap === 1) {
14232
+ contour = [];
14233
+ const [x, y] = points[0];
14234
+ addCap([x, y], [x + 1, y]);
14235
+ addCap([x, y], [x - 1, y]);
14236
+ contours.push(contour);
14237
+ } else if (points.length >= 2) {
14238
+ contour = [];
14239
+ if (!closed) addCap(points[0], points[1]);
14240
+ for (let i = closed ? 0 : 1; i < points.length - (closed ? 0 : 1); i++) {
14241
+ addJoin(points[(i + points.length - 1) % points.length], points[i], points[(i + 1) % points.length]);
14242
+ }
14243
+ if (closed) {
14244
+ contours.push(contour);
14245
+ contour = [];
14246
+ } else addCap(points[points.length - 1], points[points.length - 2]);
14247
+ for (let i = points.length - (closed ? 1 : 2); i >= (closed ? 0 : 1); i--) {
14248
+ addJoin(points[(i + 1) % points.length], points[i], points[(i + points.length - 1) % points.length]);
14249
+ }
14250
+ contours.push(contour);
14251
+ }
14252
+ }
14253
+ }
14254
+ return contours;
14255
+ }
14081
14256
  function decodePng(pngBytes) {
14082
14257
  if (pngBytes.length < 24 || pngBytes[0] !== 137 || pngBytes[1] !== 80 || pngBytes[2] !== 78 || pngBytes[3] !== 71) {
14083
14258
  throw new Error("Invalid PNG signature");
@@ -14460,111 +14635,116 @@ function blendPixel(rgba, width, height, px, py, color, alpha, blendMode, clipMa
14460
14635
  rgba[idx + 2] = Math.round((effB * a + cbB * dstA * (1 - a)) / outA * 255);
14461
14636
  rgba[idx + 3] = Math.round(outA * 255);
14462
14637
  }
14463
- function drawAntiAliasedSegment(rgba, width, height, x0, y0, x1, y1, strokeWidth, color, alpha = 1, lineCap = 0, antialias = true, blendMode, clipMask) {
14464
- const halfW = Math.max(0.6, strokeWidth * 0.5);
14465
- const dx = x1 - x0;
14466
- const dy = y1 - y0;
14467
- const lenSq = dx * dx + dy * dy;
14468
- const segLen = Math.sqrt(lenSq);
14469
- const pad = lineCap === 2 ? halfW + 2 : halfW + 1;
14470
- const minX = Math.max(0, Math.floor(Math.min(x0, x1) - pad));
14471
- const maxX = Math.min(width - 1, Math.ceil(Math.max(x0, x1) + pad));
14472
- const minY = Math.max(0, Math.floor(Math.min(y0, y1) - pad));
14473
- const maxY = Math.min(height - 1, Math.ceil(Math.max(y0, y1) + pad));
14474
- for (let py = minY; py <= maxY; py++) {
14475
- for (let px = minX; px <= maxX; px++) {
14476
- const cx = px + 0.5;
14477
- const cy = py + 0.5;
14478
- if (segLen > 1e-6 && (lineCap === 0 || lineCap === 2)) {
14479
- const ux = dx / segLen;
14480
- const uy = dy / segLen;
14481
- const along = (cx - x0) * ux + (cy - y0) * uy;
14482
- const perp = Math.abs(-(cx - x0) * uy + (cy - y0) * ux);
14483
- const minAlong = lineCap === 2 ? -halfW : 0;
14484
- const maxAlong = lineCap === 2 ? segLen + halfW : segLen;
14485
- const overAlong = along < minAlong ? minAlong - along : along > maxAlong ? along - maxAlong : 0;
14486
- const dist2 = overAlong > 0 ? Math.max(perp, halfW + overAlong) : perp;
14487
- if (dist2 <= halfW + 0.75) {
14488
- const cov = antialias ? Math.max(0, Math.min(1, halfW + 0.5 - dist2)) : dist2 <= halfW + 0.25 ? 1 : 0;
14489
- blendPixel(rgba, width, height, px, py, color, cov * alpha, blendMode, clipMask);
14490
- }
14491
- continue;
14492
- }
14493
- let t = lenSq > 1e-6 ? ((cx - x0) * dx + (cy - y0) * dy) / lenSq : 0;
14494
- t = Math.max(0, Math.min(1, t));
14495
- const projX = x0 + t * dx;
14496
- const projY = y0 + t * dy;
14497
- const dist = Math.hypot(cx - projX, cy - projY);
14498
- if (dist <= halfW + 0.75) {
14499
- const cov = antialias ? Math.max(0, Math.min(1, halfW + 0.5 - dist)) : dist <= halfW + 0.25 ? 1 : 0;
14500
- blendPixel(rgba, width, height, px, py, color, cov * alpha, blendMode, clipMask);
14501
- }
14502
- }
14503
- }
14638
+ function segmentsToScreenPaths(segments, pageHeight, scale, toScreen = (x, y) => [x * scale, (pageHeight - y) * scale]) {
14639
+ const paths = [];
14640
+ let points = [];
14641
+ let current = [0, 0];
14642
+ for (const segment of segments) {
14643
+ if (segment.kind === "move") {
14644
+ if (points.length) paths.push({ points, closed: false });
14645
+ current = toScreen(segment.x, segment.y);
14646
+ points = [current];
14647
+ } else if (segment.kind === "line") {
14648
+ if (!points.length) points = [current];
14649
+ current = toScreen(segment.x, segment.y);
14650
+ points.push(current);
14651
+ } else if (segment.kind === "cubic") {
14652
+ if (!points.length) points = [current];
14653
+ const a = toScreen(segment.x1, segment.y1), b = toScreen(segment.x2, segment.y2);
14654
+ const end = toScreen(segment.x, segment.y);
14655
+ const curve = flattenCubic(current[0], current[1], a[0], a[1], b[0], b[1], end[0], end[1]);
14656
+ for (let i = 1; i < curve.length; i++) points.push(curve[i]);
14657
+ current = end;
14658
+ } else if (segment.kind === "close") {
14659
+ if (points.length) {
14660
+ paths.push({ points, closed: true });
14661
+ current = points[0];
14662
+ points = [];
14663
+ }
14664
+ } else if (segment.kind === "rect") {
14665
+ if (points.length) paths.push({ points, closed: false });
14666
+ const first = toScreen(segment.x, segment.y);
14667
+ paths.push({ points: [
14668
+ first,
14669
+ toScreen(segment.x + segment.width, segment.y),
14670
+ toScreen(segment.x + segment.width, segment.y + segment.height),
14671
+ toScreen(segment.x, segment.y + segment.height)
14672
+ ], closed: true });
14673
+ current = first;
14674
+ points = [];
14675
+ }
14676
+ }
14677
+ if (points.length) paths.push({ points, closed: false });
14678
+ return paths;
14679
+ }
14680
+ function inverseStrokeMatrix(matrix) {
14681
+ const [a, b, c, d, e, f] = matrix;
14682
+ const det = a * d - b * c;
14683
+ if (!Number.isFinite(det) || det === 0) return void 0;
14684
+ return [d / det, -b / det, -c / det, a / det, (c * f - d * e) / det, (b * e - a * f) / det];
14685
+ }
14686
+ function prepareStroke(path, scale) {
14687
+ const matrix = path.strokeMatrix ? [...path.strokeMatrix] : [1, 0, 0, 1, 0, 0];
14688
+ const [a, b, c, d] = matrix;
14689
+ const area = Math.abs(a * d - b * c) * scale * scale;
14690
+ if (!(area > 0) || !Number.isFinite(area)) return void 0;
14691
+ const normX = Math.hypot(a, b) * scale, normY = Math.hypot(c, d) * scale;
14692
+ let width = path.strokeWidth || 1;
14693
+ const scaleX = path.strokeWidth === 0 ? normY / area : Math.max(1, normY / (width * area));
14694
+ const scaleY = path.strokeWidth === 0 ? normX / area : Math.max(1, normX / (width * area));
14695
+ let dashArray = path.dashArray, dashPhase = path.dashPhase ?? 0;
14696
+ if (scaleX === scaleY) {
14697
+ width *= scaleX;
14698
+ } else {
14699
+ matrix[0] *= scaleX;
14700
+ matrix[1] *= scaleX;
14701
+ matrix[2] *= scaleY;
14702
+ matrix[3] *= scaleY;
14703
+ if (dashArray?.length) {
14704
+ const dashScale = Math.max(scaleX, scaleY);
14705
+ dashArray = dashArray.map((value) => value / dashScale);
14706
+ dashPhase /= dashScale;
14707
+ }
14708
+ }
14709
+ return { matrix, width, dashArray, dashPhase };
14710
+ }
14711
+ function strokeEdges(path, pageHeight, scale) {
14712
+ const stroke = prepareStroke(path, scale);
14713
+ if (!stroke) return [];
14714
+ const inverse = inverseStrokeMatrix(stroke.matrix);
14715
+ if (!inverse) return [];
14716
+ const [a, b, c, d, e, f] = stroke.matrix;
14717
+ const strokeScale = scale * Math.hypot(a, b, c, d);
14718
+ const project = (x, y) => [
14719
+ (inverse[0] * x + inverse[2] * y + inverse[4]) * strokeScale,
14720
+ (inverse[1] * x + inverse[3] * y + inverse[5]) * strokeScale
14721
+ ];
14722
+ const toScreen = ([x, y]) => [
14723
+ (a * x / strokeScale + c * y / strokeScale + e) * scale,
14724
+ (pageHeight - b * x / strokeScale - d * y / strokeScale - f) * scale
14725
+ ];
14726
+ const contours = strokeOutlines(
14727
+ segmentsToScreenPaths(path.segments, pageHeight, scale, project),
14728
+ stroke.width * strokeScale,
14729
+ path.lineCap ?? 0,
14730
+ path.lineJoin ?? 0,
14731
+ path.miterLimit ?? 10,
14732
+ stroke.dashArray?.map((value) => Math.max(0, value * strokeScale)),
14733
+ stroke.dashPhase * strokeScale
14734
+ );
14735
+ return pathsToEdges(contours.map((points) => ({ points: points.map(toScreen), closed: true })));
14504
14736
  }
14505
- function segmentsToScreenEdges(segments, pageHeight, scale, closeSubpaths = false) {
14737
+ function pathsToEdges(paths, closeSubpaths = false) {
14506
14738
  const edges = [];
14507
- let curX = 0;
14508
- let curY = 0;
14509
- let startX = 0;
14510
- let startY = 0;
14511
- let hasOpenSubpath = false;
14512
- const toScreen = (x, y) => [x * scale, (pageHeight - y) * scale];
14513
- for (const seg of segments) {
14514
- if (seg.kind === "move") {
14515
- if (closeSubpaths && hasOpenSubpath && (curX !== startX || curY !== startY)) {
14516
- edges.push({ x0: curX, y0: curY, x1: startX, y1: startY });
14517
- }
14518
- [curX, curY] = toScreen(seg.x, seg.y);
14519
- startX = curX;
14520
- startY = curY;
14521
- hasOpenSubpath = false;
14522
- } else if (seg.kind === "line") {
14523
- const [nx, ny] = toScreen(seg.x, seg.y);
14524
- edges.push({ x0: curX, y0: curY, x1: nx, y1: ny });
14525
- curX = nx;
14526
- curY = ny;
14527
- hasOpenSubpath = true;
14528
- } else if (seg.kind === "cubic") {
14529
- const [p1x, p1y] = toScreen(seg.x1, seg.y1);
14530
- const [p2x, p2y] = toScreen(seg.x2, seg.y2);
14531
- const [p3x, p3y] = toScreen(seg.x, seg.y);
14532
- const points = flattenCubic(curX, curY, p1x, p1y, p2x, p2y, p3x, p3y);
14533
- let px = curX;
14534
- let py = curY;
14535
- for (let i = 1; i < points.length; i++) {
14536
- const [qx, qy] = points[i];
14537
- edges.push({ x0: px, y0: py, x1: qx, y1: qy });
14538
- px = qx;
14539
- py = qy;
14540
- }
14541
- curX = p3x;
14542
- curY = p3y;
14543
- hasOpenSubpath = true;
14544
- } else if (seg.kind === "close") {
14545
- if (curX !== startX || curY !== startY) {
14546
- edges.push({ x0: curX, y0: curY, x1: startX, y1: startY });
14547
- curX = startX;
14548
- curY = startY;
14549
- }
14550
- hasOpenSubpath = false;
14551
- } else if (seg.kind === "rect") {
14552
- if (closeSubpaths && hasOpenSubpath && (curX !== startX || curY !== startY)) {
14553
- edges.push({ x0: curX, y0: curY, x1: startX, y1: startY });
14554
- }
14555
- const [rx0, ry0] = toScreen(seg.x, seg.y);
14556
- const [rx1, ry1] = toScreen(seg.x + seg.width, seg.y + seg.height);
14557
- edges.push(
14558
- { x0: rx0, y0: ry0, x1: rx1, y1: ry0 },
14559
- { x0: rx1, y0: ry0, x1: rx1, y1: ry1 },
14560
- { x0: rx1, y0: ry1, x1: rx0, y1: ry1 },
14561
- { x0: rx0, y0: ry1, x1: rx0, y1: ry0 }
14562
- );
14563
- hasOpenSubpath = false;
14739
+ for (const { points, closed } of paths) {
14740
+ for (let i = 1; i < points.length; i++) {
14741
+ const a = points[i - 1], b = points[i];
14742
+ edges.push({ x0: a[0], y0: a[1], x1: b[0], y1: b[1] });
14743
+ }
14744
+ if ((closed || closeSubpaths) && points.length > 1) {
14745
+ const a = points[points.length - 1], b = points[0];
14746
+ edges.push({ x0: a[0], y0: a[1], x1: b[0], y1: b[1] });
14564
14747
  }
14565
- }
14566
- if (closeSubpaths && hasOpenSubpath && (curX !== startX || curY !== startY)) {
14567
- edges.push({ x0: curX, y0: curY, x1: startX, y1: startY });
14568
14748
  }
14569
14749
  return edges;
14570
14750
  }
@@ -14751,7 +14931,7 @@ function renderDisplayListToBitmap(displayList, options = {}) {
14751
14931
  for (const clip of clips) {
14752
14932
  const { segments, fillRule } = "segments" in clip ? clip : { segments: clip, fillRule: "nonzero" };
14753
14933
  const layer = new Uint8Array(width * height * 4);
14754
- fillEdgesScanline4x4(layer, width, height, segmentsToScreenEdges(segments, displayList.height, scale, true), { r: 1, g: 1, b: 1 }, 1, fillRule);
14934
+ fillEdgesScanline4x4(layer, width, height, pathsToEdges(segmentsToScreenPaths(segments, displayList.height, scale), true), { r: 1, g: 1, b: 1 }, 1, fillRule);
14755
14935
  for (let i = 3; i < layer.length; i += 4) clipMask[i] = Math.round(clipMask[i] * layer[i] / 255);
14756
14936
  }
14757
14937
  cachedClips = clips;
@@ -14798,62 +14978,28 @@ function renderDisplayListToBitmap(displayList, options = {}) {
14798
14978
  if (operation.kind === "path") {
14799
14979
  const path = operation.value;
14800
14980
  if (path.fillColor) {
14801
- const edges = segmentsToScreenEdges(path.segments, displayList.height, scale, true);
14981
+ const edges = pathsToEdges(segmentsToScreenPaths(path.segments, displayList.height, scale), true);
14802
14982
  const clipScreen = path.clipRect ? [path.clipRect[0] * scale, (displayList.height - path.clipRect[3]) * scale, path.clipRect[2] * scale, (displayList.height - path.clipRect[1]) * scale] : void 0;
14803
14983
  fillEdgesScanline4x4(rgba, width, height, edges, path.fillColor, path.fillAlpha ?? 1, path.fillRule ?? "nonzero", clipScreen, original.kind === "glyph" ? aaTxt : aaVec, path.blendMode, clipMask);
14804
14984
  }
14805
14985
  if (path.strokeColor) {
14806
- const edges = segmentsToScreenEdges(path.segments, displayList.height, scale, false);
14807
- const rawSw = path.strokeWidth * scale;
14808
- const sw = Math.max(1, rawSw);
14986
+ const rawSw = path.strokeWidth * scale * (path.strokeMatrix ? Math.hypot(path.strokeMatrix[0], path.strokeMatrix[1]) : 1);
14809
14987
  const strokeAlpha = options.thinLineMode === "shape" && rawSw < 1 ? (path.strokeAlpha ?? 1) * Math.max(0.25, rawSw) : path.strokeAlpha ?? 1;
14810
- const dashArr = path.dashArray && path.dashArray.length > 0 ? path.dashArray.map((d) => Math.max(0, d * scale)) : void 0;
14811
- const dashCycle = dashArr ? dashArr.reduce((a, b) => a + b, 0) : 0;
14812
- let dashDist = (path.dashPhase ?? 0) * scale % (dashCycle || 1);
14813
- if (dashDist < 0) dashDist += dashCycle;
14814
- for (const e of edges) {
14815
- if (!dashArr || dashCycle <= 1e-4) {
14816
- drawAntiAliasedSegment(rgba, width, height, e.x0, e.y0, e.x1, e.y1, sw, path.strokeColor, strokeAlpha, path.lineCap ?? 0, original.kind === "glyph" ? aaTxt : aaVec, path.blendMode, clipMask);
14817
- } else {
14818
- const dx = e.x1 - e.x0;
14819
- const dy = e.y1 - e.y0;
14820
- const edgeLen = Math.hypot(dx, dy);
14821
- if (edgeLen <= 1e-4) continue;
14822
- let pos = 0;
14823
- while (pos < edgeLen) {
14824
- let cycleRem = dashDist % dashCycle;
14825
- let dIdx = 0;
14826
- while (dIdx < dashArr.length - 1 && cycleRem >= dashArr[dIdx]) {
14827
- cycleRem -= dashArr[dIdx];
14828
- dIdx++;
14829
- }
14830
- const segRemainInDash = Math.max(1e-4, dashArr[dIdx] - cycleRem);
14831
- const step = Math.min(edgeLen - pos, segRemainInDash);
14832
- if (dIdx % 2 === 0) {
14833
- const t0 = pos / edgeLen;
14834
- const t1 = (pos + step) / edgeLen;
14835
- drawAntiAliasedSegment(
14836
- rgba,
14837
- width,
14838
- height,
14839
- e.x0 + dx * t0,
14840
- e.y0 + dy * t0,
14841
- e.x0 + dx * t1,
14842
- e.y0 + dy * t1,
14843
- sw,
14844
- path.strokeColor,
14845
- strokeAlpha,
14846
- path.lineCap ?? 0,
14847
- original.kind === "glyph" ? aaTxt : aaVec,
14848
- path.blendMode,
14849
- clipMask
14850
- );
14851
- }
14852
- pos += step;
14853
- dashDist = (dashDist + step) % dashCycle;
14854
- }
14855
- }
14856
- }
14988
+ const edges = strokeEdges(path, displayList.height, scale);
14989
+ const clipScreen = path.clipRect ? [path.clipRect[0] * scale, (displayList.height - path.clipRect[3]) * scale, path.clipRect[2] * scale, (displayList.height - path.clipRect[1]) * scale] : void 0;
14990
+ fillEdgesScanline4x4(
14991
+ rgba,
14992
+ width,
14993
+ height,
14994
+ edges,
14995
+ path.strokeColor,
14996
+ strokeAlpha,
14997
+ "nonzero",
14998
+ clipScreen,
14999
+ original.kind === "glyph" ? aaTxt : aaVec,
15000
+ path.blendMode,
15001
+ clipMask
15002
+ );
14857
15003
  }
14858
15004
  } else if (operation.kind === "image") {
14859
15005
  const img = operation.value;
@@ -15521,6 +15667,7 @@ var __webpack_exports__getVerbosityLevel;
15521
15667
  var __webpack_exports__setVerbosityLevel;
15522
15668
  var ACROFORM_FONT_ALIAS_MAP;
15523
15669
  var PdfPage;
15670
+ var MAX_STROKE_VERTICES;
15524
15671
  var STD_LUMINANCE_QUANT;
15525
15672
  var ZIGZAG_ORDER;
15526
15673
  var STD_DC_LUMA_NRCODES;
@@ -41454,6 +41601,7 @@ var init_dist = __esm({
41454
41601
  return renderDisplayListToPng(this.evaluateDisplayList(), options);
41455
41602
  }
41456
41603
  };
41604
+ MAX_STROKE_VERTICES = 1e6;
41457
41605
  STD_LUMINANCE_QUANT = new Uint8Array([
41458
41606
  16,
41459
41607
  11,
@@ -43537,3 +43685,15 @@ export {
43537
43685
  * Copyright 2012 Mozilla Foundation. Licensed under Apache-2.0.
43538
43686
  * See THIRD_PARTY_NOTICES.md for the source revision and adaptations.
43539
43687
  */
43688
+ /*!
43689
+ * Anti-Grain Geometry - Version 2.3
43690
+ * Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
43691
+ *
43692
+ * Permission to copy, use, modify, sell and distribute this software
43693
+ * is granted provided this copyright notice appears in all copies.
43694
+ * This software is provided "as is" without express or implied
43695
+ * warranty, and with no claim as to its suitability for any purpose.
43696
+ *
43697
+ * Adapted from PDFium agg_math_stroke.h and agg_vcgen_stroke.cpp.
43698
+ * See THIRD_PARTY_NOTICES.md for the source revision and adaptations.
43699
+ */
@@ -0,0 +1,14 @@
1
+ export interface SnapshotScript {
2
+ incrementalAriaSnapshot(node: Node, options: {
3
+ mode: string;
4
+ refPrefix?: string;
5
+ track?: string;
6
+ doNotRenderActive?: boolean;
7
+ }): {
8
+ full: string;
9
+ incremental?: string;
10
+ iframeRefs: string[];
11
+ };
12
+ _safeBashSnapshotLabels?: boolean;
13
+ }
14
+ export declare function installSnapshotLabelCache(injected: SnapshotScript): void;
@@ -0,0 +1,62 @@
1
+ // Chromium's control.labels NodeList scans the tree for each control. Reverse
2
+ // the lookup through native label.control once per tree and synchronous capture.
3
+ // Only the provider's utility world is changed; restore its descriptors even
4
+ // when capture throws, and never keep an index across DOM mutations.
5
+ export function installSnapshotLabelCache(injected) {
6
+ if (injected._safeBashSnapshotLabels)
7
+ return;
8
+ const snapshot = injected.incrementalAriaSnapshot;
9
+ injected.incrementalAriaSnapshot = function (node, options) {
10
+ const roots = new Map();
11
+ const descriptors = [];
12
+ try {
13
+ for (const constructor of [
14
+ HTMLButtonElement,
15
+ HTMLInputElement,
16
+ HTMLMeterElement,
17
+ HTMLOutputElement,
18
+ HTMLProgressElement,
19
+ HTMLSelectElement,
20
+ HTMLTextAreaElement
21
+ ]) {
22
+ const prototype = constructor.prototype;
23
+ const descriptor = Object.getOwnPropertyDescriptor(prototype, "labels");
24
+ if (!descriptor?.get)
25
+ throw new Error("Native labels getter is unavailable");
26
+ descriptors.push([prototype, descriptor]);
27
+ Object.defineProperty(prototype, "labels", {
28
+ ...descriptor,
29
+ get() {
30
+ if (this instanceof HTMLInputElement && this.type === "hidden")
31
+ return null;
32
+ const root = this.getRootNode();
33
+ let controls = roots.get(root);
34
+ if (!controls) {
35
+ controls = new Map();
36
+ roots.set(root, controls);
37
+ const labels = Array.from(root.querySelectorAll("label"));
38
+ if (root instanceof HTMLLabelElement)
39
+ labels.unshift(root);
40
+ for (const label of labels) {
41
+ const control = label.control;
42
+ if (!control)
43
+ continue;
44
+ let associated = controls.get(control);
45
+ if (!associated)
46
+ controls.set(control, (associated = []));
47
+ associated.push(label);
48
+ }
49
+ }
50
+ return controls.get(this) ?? [];
51
+ }
52
+ });
53
+ }
54
+ return snapshot.call(this, node, options);
55
+ }
56
+ finally {
57
+ for (const [prototype, descriptor] of descriptors)
58
+ Object.defineProperty(prototype, "labels", descriptor);
59
+ }
60
+ };
61
+ injected._safeBashSnapshotLabels = true;
62
+ }