@poe-platform/safe-bash 0.1.763 → 0.1.764

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 (31) hide show
  1. package/dist/image-ast/index.browser.js +268 -153
  2. package/dist/image-ast/index.js +268 -153
  3. package/dist/pdf-ast/index.js +270 -153
  4. package/dist/safe-bash/chunks/{chunk-CRQDMBQA.js → chunk-FSH7QRIC.js} +10 -1
  5. package/dist/safe-bash/command-chunks/{chunk-4XHONGIU.js → chunk-B7YLGJRF.js} +2 -2
  6. package/dist/safe-bash/command-chunks/{chunk-S3G2B4OX.js → chunk-G3IIEU2N.js} +271 -153
  7. package/dist/safe-bash/command-chunks/{chunk-S5EX6UP5.js → chunk-RDPJGIQF.js} +1 -1
  8. package/dist/safe-bash/commands/python/index.browser.js +1 -1
  9. package/dist/safe-bash/commands/python/llm-module.js +3 -1
  10. package/dist/safe-bash/commands/python/shell-module.js +7 -0
  11. package/dist/safe-bash/core.browser.js +32 -12
  12. package/dist/safe-bash/shell/runtime.js +43 -11
  13. package/dist/safe-bash-command-ffmpeg/index.js +5649 -5565
  14. package/dist/safe-bash-command-imagemagick/index.js +2 -2
  15. package/dist/safe-bash-command-pandoc/command.js +3 -3
  16. package/dist/safe-bash-command-pandoc/index.js +3 -3
  17. package/dist/safe-bash-command-pdfimages/index.js +268 -153
  18. package/dist/safe-bash-command-pdfinfo/index.js +268 -153
  19. package/dist/safe-bash-command-pdftk/index.js +268 -153
  20. package/dist/safe-bash-command-pdftoppm/index.js +268 -153
  21. package/dist/safe-bash-command-pdftotext/index.js +268 -153
  22. package/dist/safe-bash-command-qpdf/index.js +268 -153
  23. package/dist/safe-bash-command-sips/index.js +2 -2
  24. package/dist/safe-bash-command-soffice/index.js +1 -1
  25. package/dist/safe-bash-command-ssconvert/index.js +265 -150
  26. package/dist/safe-bash-command-wkhtmltopdf/index.js +269 -153
  27. package/dist/safe-playwright-cloudflare/browser-snapshot-labels.d.ts +14 -0
  28. package/dist/safe-playwright-cloudflare/browser-snapshot-labels.js +62 -0
  29. package/dist/safe-playwright-cloudflare/browser-snapshot-scheduler.js +8 -1
  30. package/package.json +2 -2
  31. package/third-party/pdf-ast/THIRD_PARTY_NOTICES.md +14 -0
@@ -14078,6 +14078,183 @@ function downscaleImage(image, widthScale, heightScale) {
14078
14078
  }
14079
14079
  return image;
14080
14080
  }
14081
+ function dashSubpath(path, pattern, phase) {
14082
+ const cycle = pattern.reduce((sum, value) => sum + value, 0);
14083
+ if (!(cycle > 0)) return [path];
14084
+ let offset = (phase % cycle + cycle) % cycle, index = 0;
14085
+ while (offset > 0) {
14086
+ if (offset < pattern[index]) break;
14087
+ offset -= pattern[index];
14088
+ index = (index + 1) % pattern.length;
14089
+ }
14090
+ let remaining = pattern[index] - offset;
14091
+ const points = path.closed ? [...path.points, path.points[0]] : path.points;
14092
+ const result = [];
14093
+ let current = [];
14094
+ let steps = 0;
14095
+ const flush = () => {
14096
+ if (current.length) result.push({ points: current, closed: false });
14097
+ current = [];
14098
+ };
14099
+ const advance = (point) => {
14100
+ while (remaining <= 0) {
14101
+ if (++steps > MAX_STROKE_VERTICES) throw new PdfError("E_LIMIT", "Stroke dash expansion exceeds the vertex limit");
14102
+ if (index % 2 === 0) {
14103
+ if (pattern[index] === 0) result.push({ points: [point, point], closed: false });
14104
+ flush();
14105
+ }
14106
+ index = (index + 1) % pattern.length;
14107
+ remaining = pattern[index];
14108
+ }
14109
+ };
14110
+ for (let i = 1; i < points.length; i++) {
14111
+ const start = points[i - 1], end = points[i];
14112
+ const dx = end[0] - start[0], dy = end[1] - start[1];
14113
+ const length2 = Math.hypot(dx, dy);
14114
+ if (!Number.isFinite(length2) || length2 / cycle * pattern.length > MAX_STROKE_VERTICES) {
14115
+ throw new PdfError("E_LIMIT", "Stroke dash expansion exceeds the vertex limit");
14116
+ }
14117
+ let distance = 0;
14118
+ while (distance < length2) {
14119
+ const point = [start[0] + dx * distance / length2, start[1] + dy * distance / length2];
14120
+ advance(point);
14121
+ const step = Math.min(remaining, length2 - distance);
14122
+ if (distance + step === distance || ++steps > MAX_STROKE_VERTICES) throw new PdfError("E_LIMIT", "Stroke dash expansion exceeds the vertex limit");
14123
+ distance += step;
14124
+ remaining -= step;
14125
+ if (index % 2 === 0) {
14126
+ if (!current.length) current.push(point);
14127
+ current.push([start[0] + dx * distance / length2, start[1] + dy * distance / length2]);
14128
+ }
14129
+ }
14130
+ }
14131
+ flush();
14132
+ if (path.closed && result.length) {
14133
+ const first = result[0], last = result[result.length - 1];
14134
+ const start = path.points[0];
14135
+ const firstPoint = first.points[0], lastPoint = last.points[last.points.length - 1];
14136
+ if (firstPoint[0] === start[0] && firstPoint[1] === start[1] && lastPoint[0] === start[0] && lastPoint[1] === start[1]) {
14137
+ if (first === last) result[0] = { points: first.points, closed: true };
14138
+ else {
14139
+ result[0] = { points: [...last.points, ...first.points.slice(1)], closed: false };
14140
+ result.pop();
14141
+ }
14142
+ }
14143
+ }
14144
+ return result;
14145
+ }
14146
+ function strokeOutlines(paths, width, cap, join, miterLimit, dashArray = [], dashPhase = 0) {
14147
+ const half = width / 2;
14148
+ const contours = [];
14149
+ const pattern = dashArray.length % 2 ? [...dashArray, ...dashArray] : dashArray;
14150
+ let count = 0;
14151
+ let contour = [];
14152
+ const add = (x, y) => {
14153
+ if (++count > MAX_STROKE_VERTICES) throw new PdfError("E_LIMIT", "Stroke outline exceeds the vertex limit");
14154
+ contour.push([x, y]);
14155
+ };
14156
+ const arc = (point, dx1, dy1, dx2, dy2) => {
14157
+ let a1 = Math.atan2(dy1, dx1), a2 = Math.atan2(dy2, dx2);
14158
+ const ccw = a1 - a2 > 0 && a1 - a2 < Math.PI;
14159
+ const step = Math.acos(half / (half + 0.125)) * 2;
14160
+ add(point[0] + dx1, point[1] + dy1);
14161
+ if (step > 0) {
14162
+ if (!ccw) {
14163
+ if (a1 > a2) a2 += 2 * Math.PI;
14164
+ a2 -= step / 4;
14165
+ if ((a2 - a1) / step > MAX_STROKE_VERTICES - count) throw new PdfError("E_LIMIT", "Stroke arc exceeds the vertex limit");
14166
+ for (a1 += step; a1 < a2; a1 += step) add(point[0] + half * Math.cos(a1), point[1] + half * Math.sin(a1));
14167
+ } else {
14168
+ if (a1 < a2) a2 -= 2 * Math.PI;
14169
+ a2 += step / 4;
14170
+ if ((a1 - a2) / step > MAX_STROKE_VERTICES - count) throw new PdfError("E_LIMIT", "Stroke arc exceeds the vertex limit");
14171
+ for (a1 -= step; a1 > a2; a1 -= step) add(point[0] + half * Math.cos(a1), point[1] + half * Math.sin(a1));
14172
+ }
14173
+ }
14174
+ add(point[0] + dx2, point[1] + dy2);
14175
+ };
14176
+ const addCap = (point, next) => {
14177
+ const length2 = Math.hypot(next[0] - point[0], next[1] - point[1]);
14178
+ const dx = half * (next[1] - point[1]) / length2;
14179
+ const dy = half * (next[0] - point[0]) / length2;
14180
+ if (cap !== 1) {
14181
+ const sx = cap === 2 ? dy : 0, sy = cap === 2 ? dx : 0;
14182
+ add(point[0] - dx - sx, point[1] + dy - sy);
14183
+ add(point[0] + dx - sx, point[1] - dy - sy);
14184
+ } else {
14185
+ const angle = Math.atan2(dy, -dx);
14186
+ const step = Math.max(1e-3, Math.acos(half / (half + 0.125)) * 2);
14187
+ add(point[0] - dx, point[1] + dy);
14188
+ 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));
14189
+ add(point[0] + dx, point[1] - dy);
14190
+ }
14191
+ };
14192
+ const addJoin = (prev, point, next) => {
14193
+ const len1 = Math.hypot(point[0] - prev[0], point[1] - prev[1]);
14194
+ const len2 = Math.hypot(next[0] - point[0], next[1] - point[1]);
14195
+ const dx1 = half * (point[1] - prev[1]) / len1, dy1 = half * (point[0] - prev[0]) / len1;
14196
+ const dx2 = half * (next[1] - point[1]) / len2, dy2 = half * (next[0] - point[0]) / len2;
14197
+ const inner = (next[0] - point[0]) * (point[1] - prev[1]) - (next[1] - point[1]) * (point[0] - prev[0]) > 0;
14198
+ if (!inner && join === 1) {
14199
+ arc(point, dx1, -dy1, dx2, -dy2);
14200
+ return;
14201
+ }
14202
+ if (inner || join === 0) {
14203
+ const ax = prev[0] + dx1, ay = prev[1] - dy1;
14204
+ const bx = point[0] + dx1, by = point[1] - dy1;
14205
+ const cx = point[0] + dx2, cy = point[1] - dy2;
14206
+ const dx = next[0] + dx2, dy = next[1] - dy2;
14207
+ const den = (bx - ax) * (dy - cy) - (by - ay) * (dx - cx);
14208
+ if (Math.abs(den) >= 1e-30) {
14209
+ const t = ((ay - cy) * (dx - cx) - (ax - cx) * (dy - cy)) / den;
14210
+ const x = ax + (bx - ax) * t, y = ay + (by - ay) * t;
14211
+ if (Math.hypot(x - point[0], y - point[1]) <= half * (inner ? 1.01 : miterLimit)) {
14212
+ add(x, y);
14213
+ return;
14214
+ }
14215
+ } else if ((bx - prev[0]) * dy1 - (prev[1] - by) * dx1 < 0 !== (bx - next[0]) * dy1 - (next[1] - by) * dx1 < 0) {
14216
+ add(bx, by);
14217
+ return;
14218
+ }
14219
+ }
14220
+ add(point[0] + dx1, point[1] - dy1);
14221
+ add(point[0] + dx2, point[1] - dy2);
14222
+ };
14223
+ for (const path of paths) {
14224
+ for (const subpath of pattern.length ? dashSubpath(path, pattern, dashPhase) : [path]) {
14225
+ const points = [];
14226
+ for (const point of subpath.points) {
14227
+ const prev = points[points.length - 1];
14228
+ if (!prev || Math.hypot(prev[0] - point[0], prev[1] - point[1]) > 1e-14) points.push(point);
14229
+ }
14230
+ let closed = subpath.closed;
14231
+ 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();
14232
+ if (points.length < 3) closed = false;
14233
+ if (points.length === 1 && subpath.points.length > 1 && cap === 1) {
14234
+ contour = [];
14235
+ const [x, y] = points[0];
14236
+ addCap([x, y], [x + 1, y]);
14237
+ addCap([x, y], [x - 1, y]);
14238
+ contours.push(contour);
14239
+ } else if (points.length >= 2) {
14240
+ contour = [];
14241
+ if (!closed) addCap(points[0], points[1]);
14242
+ for (let i = closed ? 0 : 1; i < points.length - (closed ? 0 : 1); i++) {
14243
+ addJoin(points[(i + points.length - 1) % points.length], points[i], points[(i + 1) % points.length]);
14244
+ }
14245
+ if (closed) {
14246
+ contours.push(contour);
14247
+ contour = [];
14248
+ } else addCap(points[points.length - 1], points[points.length - 2]);
14249
+ for (let i = points.length - (closed ? 1 : 2); i >= (closed ? 0 : 1); i--) {
14250
+ addJoin(points[(i + 1) % points.length], points[i], points[(i + points.length - 1) % points.length]);
14251
+ }
14252
+ contours.push(contour);
14253
+ }
14254
+ }
14255
+ }
14256
+ return contours;
14257
+ }
14081
14258
  function decodePng(pngBytes) {
14082
14259
  if (pngBytes.length < 24 || pngBytes[0] !== 137 || pngBytes[1] !== 80 || pngBytes[2] !== 78 || pngBytes[3] !== 71) {
14083
14260
  throw new Error("Invalid PNG signature");
@@ -14460,111 +14637,60 @@ function blendPixel(rgba, width, height, px, py, color, alpha, blendMode, clipMa
14460
14637
  rgba[idx + 2] = Math.round((effB * a + cbB * dstA * (1 - a)) / outA * 255);
14461
14638
  rgba[idx + 3] = Math.round(outA * 255);
14462
14639
  }
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
- }
14504
- }
14505
- function segmentsToScreenEdges(segments, pageHeight, scale, closeSubpaths = false) {
14506
- const edges = [];
14507
- let curX = 0;
14508
- let curY = 0;
14509
- let startX = 0;
14510
- let startY = 0;
14511
- let hasOpenSubpath = false;
14640
+ function segmentsToScreenPaths(segments, pageHeight, scale) {
14641
+ const paths = [];
14642
+ let points = [];
14643
+ let current = [0, 0];
14512
14644
  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;
14645
+ for (const segment of segments) {
14646
+ if (segment.kind === "move") {
14647
+ if (points.length) paths.push({ points, closed: false });
14648
+ current = toScreen(segment.x, segment.y);
14649
+ points = [current];
14650
+ } else if (segment.kind === "line") {
14651
+ if (!points.length) points = [current];
14652
+ current = toScreen(segment.x, segment.y);
14653
+ points.push(current);
14654
+ } else if (segment.kind === "cubic") {
14655
+ if (!points.length) points = [current];
14656
+ const a = toScreen(segment.x1, segment.y1), b = toScreen(segment.x2, segment.y2);
14657
+ const end = toScreen(segment.x, segment.y);
14658
+ const curve = flattenCubic(current[0], current[1], a[0], a[1], b[0], b[1], end[0], end[1]);
14659
+ for (let i = 1; i < curve.length; i++) points.push(curve[i]);
14660
+ current = end;
14661
+ } else if (segment.kind === "close") {
14662
+ if (points.length) {
14663
+ paths.push({ points, closed: true });
14664
+ current = points[0];
14665
+ points = [];
14666
+ }
14667
+ } else if (segment.kind === "rect") {
14668
+ if (points.length) paths.push({ points, closed: false });
14669
+ const first = toScreen(segment.x, segment.y);
14670
+ paths.push({ points: [
14671
+ first,
14672
+ toScreen(segment.x + segment.width, segment.y),
14673
+ toScreen(segment.x + segment.width, segment.y + segment.height),
14674
+ toScreen(segment.x, segment.y + segment.height)
14675
+ ], closed: true });
14676
+ current = first;
14677
+ points = [];
14678
+ }
14679
+ }
14680
+ if (points.length) paths.push({ points, closed: false });
14681
+ return paths;
14682
+ }
14683
+ function pathsToEdges(paths, closeSubpaths = false) {
14684
+ const edges = [];
14685
+ for (const { points, closed } of paths) {
14686
+ for (let i = 1; i < points.length; i++) {
14687
+ const a = points[i - 1], b = points[i];
14688
+ edges.push({ x0: a[0], y0: a[1], x1: b[0], y1: b[1] });
14689
+ }
14690
+ if ((closed || closeSubpaths) && points.length > 1) {
14691
+ const a = points[points.length - 1], b = points[0];
14692
+ edges.push({ x0: a[0], y0: a[1], x1: b[0], y1: b[1] });
14564
14693
  }
14565
- }
14566
- if (closeSubpaths && hasOpenSubpath && (curX !== startX || curY !== startY)) {
14567
- edges.push({ x0: curX, y0: curY, x1: startX, y1: startY });
14568
14694
  }
14569
14695
  return edges;
14570
14696
  }
@@ -14751,7 +14877,7 @@ function renderDisplayListToBitmap(displayList, options = {}) {
14751
14877
  for (const clip of clips) {
14752
14878
  const { segments, fillRule } = "segments" in clip ? clip : { segments: clip, fillRule: "nonzero" };
14753
14879
  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);
14880
+ fillEdgesScanline4x4(layer, width, height, pathsToEdges(segmentsToScreenPaths(segments, displayList.height, scale), true), { r: 1, g: 1, b: 1 }, 1, fillRule);
14755
14881
  for (let i = 3; i < layer.length; i += 4) clipMask[i] = Math.round(clipMask[i] * layer[i] / 255);
14756
14882
  }
14757
14883
  cachedClips = clips;
@@ -14798,62 +14924,38 @@ function renderDisplayListToBitmap(displayList, options = {}) {
14798
14924
  if (operation.kind === "path") {
14799
14925
  const path = operation.value;
14800
14926
  if (path.fillColor) {
14801
- const edges = segmentsToScreenEdges(path.segments, displayList.height, scale, true);
14927
+ const edges = pathsToEdges(segmentsToScreenPaths(path.segments, displayList.height, scale), true);
14802
14928
  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
14929
  fillEdgesScanline4x4(rgba, width, height, edges, path.fillColor, path.fillAlpha ?? 1, path.fillRule ?? "nonzero", clipScreen, original.kind === "glyph" ? aaTxt : aaVec, path.blendMode, clipMask);
14804
14930
  }
14805
14931
  if (path.strokeColor) {
14806
- const edges = segmentsToScreenEdges(path.segments, displayList.height, scale, false);
14807
14932
  const rawSw = path.strokeWidth * scale;
14808
14933
  const sw = Math.max(1, rawSw);
14809
14934
  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
- }
14935
+ const contours = strokeOutlines(
14936
+ segmentsToScreenPaths(path.segments, displayList.height, scale),
14937
+ sw,
14938
+ path.lineCap ?? 0,
14939
+ path.lineJoin ?? 0,
14940
+ path.miterLimit ?? 10,
14941
+ path.dashArray?.map((value) => Math.max(0, value * scale)),
14942
+ (path.dashPhase ?? 0) * scale
14943
+ );
14944
+ const edges = pathsToEdges(contours.map((points) => ({ points, closed: true })));
14945
+ 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;
14946
+ fillEdgesScanline4x4(
14947
+ rgba,
14948
+ width,
14949
+ height,
14950
+ edges,
14951
+ path.strokeColor,
14952
+ strokeAlpha,
14953
+ "nonzero",
14954
+ clipScreen,
14955
+ original.kind === "glyph" ? aaTxt : aaVec,
14956
+ path.blendMode,
14957
+ clipMask
14958
+ );
14857
14959
  }
14858
14960
  } else if (operation.kind === "image") {
14859
14961
  const img = operation.value;
@@ -15521,6 +15623,7 @@ var __webpack_exports__getVerbosityLevel;
15521
15623
  var __webpack_exports__setVerbosityLevel;
15522
15624
  var ACROFORM_FONT_ALIAS_MAP;
15523
15625
  var PdfPage;
15626
+ var MAX_STROKE_VERTICES;
15524
15627
  var STD_LUMINANCE_QUANT;
15525
15628
  var ZIGZAG_ORDER;
15526
15629
  var STD_DC_LUMA_NRCODES;
@@ -41454,6 +41557,7 @@ var init_dist = __esm({
41454
41557
  return renderDisplayListToPng(this.evaluateDisplayList(), options);
41455
41558
  }
41456
41559
  };
41560
+ MAX_STROKE_VERTICES = 1e6;
41457
41561
  STD_LUMINANCE_QUANT = new Uint8Array([
41458
41562
  16,
41459
41563
  11,
@@ -43537,3 +43641,15 @@ export {
43537
43641
  * Copyright 2012 Mozilla Foundation. Licensed under Apache-2.0.
43538
43642
  * See THIRD_PARTY_NOTICES.md for the source revision and adaptations.
43539
43643
  */
43644
+ /*!
43645
+ * Anti-Grain Geometry - Version 2.3
43646
+ * Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
43647
+ *
43648
+ * Permission to copy, use, modify, sell and distribute this software
43649
+ * is granted provided this copyright notice appears in all copies.
43650
+ * This software is provided "as is" without express or implied
43651
+ * warranty, and with no claim as to its suitability for any purpose.
43652
+ *
43653
+ * Adapted from PDFium agg_math_stroke.h and agg_vcgen_stroke.cpp.
43654
+ * See THIRD_PARTY_NOTICES.md for the source revision and adaptations.
43655
+ */
@@ -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
+ }
@@ -1,3 +1,4 @@
1
+ import { installSnapshotLabelCache } from './browser-snapshot-labels.js';
1
2
  /** Serialize native frame capture before cold utility scripts become CDP payloads.
2
3
  * The pinned provider recurses only after this callback returns, so descendants
3
4
  * do not retain a parent slot. Native traversal, retries and refs stay intact. */
@@ -54,7 +55,13 @@ export function createBrowserSnapshotScheduler() {
54
55
  }
55
56
  function snapshotAction(progress, frame, action) {
56
57
  return function (continuePolling) {
57
- return schedule(progress, frame, () => action.call(this, continuePolling));
58
+ return schedule(progress, frame, async () => {
59
+ const context = await progress.race(frame._utilityContext());
60
+ const injected = await progress.race(context.injectedScript());
61
+ await progress.race(injected.evaluate(installSnapshotLabelCache));
62
+ progress.signal.throwIfAborted();
63
+ return action.call(this, continuePolling);
64
+ });
58
65
  };
59
66
  }
60
67
  function prepareFrame(frame) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@poe-platform/safe-bash",
3
- "version": "0.1.763",
3
+ "version": "0.1.764",
4
4
  "description": "Extensible virtual shell with pluggable filesystems and streaming commands",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -841,7 +841,7 @@
841
841
  "access": "public"
842
842
  },
843
843
  "dependencies": {
844
- "@poe-platform/safe-fs": "0.1.763",
844
+ "@poe-platform/safe-fs": "0.1.764",
845
845
  "pdf-lib": "1.17.1",
846
846
  "@noble/hashes": "2.4.0",
847
847
  "pako": "3.0.1",
@@ -215,6 +215,20 @@ adapter; other cases use independently rendered PDF.js pixels.
215
215
 
216
216
  Source: https://github.com/chromium/pdfium/blob/a84323421e94f484faca52dd9d027934eba42ab8/third_party/agg23/agg_curves.cpp
217
217
 
218
+ `src/render/stroke.ts` adapts the cap, join, miter and arc calculations from
219
+ `third_party/agg23/agg_math_stroke.h`, with forward/backward contour assembly
220
+ from `agg_vcgen_stroke.cpp`, at the same PDFium revision and under the same AGG
221
+ permission terms. The adapter uses double-precision arrays, PDFium's
222
+ `miter_join_revert` bevel fallback, and a one-million-vertex expansion limit.
223
+ Local dash splitting preserves joins across vertices and closed seams, resets
224
+ phase per subpath, and handles odd arrays and zero-length round dots.
225
+ `src/render/stroke-joins.test.ts` checks native cap/join vectors plus independent
226
+ PDF.js pixels; Poppler also confirms the final zero-length dash is omitted.
227
+ The native harness calls unchanged upstream math routines with minimal support
228
+ headers and local contour assembly; it is not the full upstream generator.
229
+
230
+ Source: https://github.com/chromium/pdfium/blob/a84323421e94f484faca52dd9d027934eba42ab8/third_party/agg23/agg_math_stroke.h
231
+
218
232
 
219
233
  # SVG labels
220
234