@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
@@ -43703,11 +43703,10 @@ function evaluateContentStreamToDisplayList(params) {
43703
43703
  } else if (operator === "d") {
43704
43704
  const arrNode = ops[0]?.kind === "array" ? ops[0] : void 0;
43705
43705
  if (arrNode) {
43706
- const ctmScale = Math.max(1e-6, Math.hypot(st.ctm[0], st.ctm[1]));
43707
- const nums = arrNode.items.map((it) => it.kind === "number" ? it.value * ctmScale : 0).filter((v) => v >= 0);
43706
+ const nums = arrNode.items.map((it) => it.kind === "number" ? it.value : 0).filter((v) => v >= 0);
43708
43707
  const sum = nums.reduce((a, b) => a + b, 0);
43709
43708
  st.dashArray = sum > 0 ? nums : void 0;
43710
- st.dashPhase = num(1, 0) * ctmScale;
43709
+ st.dashPhase = num(1, 0);
43711
43710
  } else {
43712
43711
  st.dashArray = void 0;
43713
43712
  st.dashPhase = void 0;
@@ -44243,15 +44242,14 @@ function evaluateContentStreamToDisplayList(params) {
44243
44242
  break;
44244
44243
  }
44245
44244
  const fillRule = node.paint.includes("*") ? "evenodd" : "nonzero";
44246
- const ctmScale = Math.max(1e-6, Math.hypot(st.ctm[0], st.ctm[1]));
44247
- const scaledStrokeWidth = st.strokeWidth === 0 ? 0 : st.strokeWidth * ctmScale;
44248
44245
  emit({ kind: "path", value: {
44249
44246
  segments: transformedSegments,
44250
44247
  fillColor: isFill && !evaluatedFillPattern ? st.fillColor : void 0,
44251
44248
  fillAlpha: isFill && !evaluatedFillPattern ? st.fillAlpha : void 0,
44252
44249
  strokeColor: isStroke ? st.strokeColor : void 0,
44253
44250
  strokeAlpha: isStroke ? st.strokeAlpha : void 0,
44254
- strokeWidth: scaledStrokeWidth,
44251
+ strokeWidth: st.strokeWidth,
44252
+ ...isStroke ? { strokeMatrix: [...st.ctm] } : {},
44255
44253
  ...st.lineCap !== 0 ? { lineCap: st.lineCap } : {},
44256
44254
  ...st.lineJoin !== 0 ? { lineJoin: st.lineJoin } : {},
44257
44255
  ...st.miterLimit !== 10 ? { miterLimit: st.miterLimit } : {},
@@ -44439,14 +44437,14 @@ function evaluateContentStreamToDisplayList(params) {
44439
44437
  if (st.textRenderMode >= 4 && st.textRenderMode <= 7) pendingTextClip.push(...transformedGlyphSegs);
44440
44438
  const isFillGlyph = st.textRenderMode === 0 || st.textRenderMode === 2 || st.textRenderMode === 4 || st.textRenderMode === 6;
44441
44439
  const isStrokeGlyph = st.textRenderMode === 1 || st.textRenderMode === 2 || st.textRenderMode === 5 || st.textRenderMode === 6;
44442
- const ctmScale = Math.max(1e-6, Math.hypot(st.ctm[0], st.ctm[1]));
44443
44440
  const paint = {
44444
44441
  segments: transformedGlyphSegs,
44445
44442
  fillColor: isFillGlyph ? st.fillColor : void 0,
44446
44443
  fillAlpha: isFillGlyph ? st.fillAlpha : void 0,
44447
44444
  strokeColor: isStrokeGlyph ? st.strokeColor : void 0,
44448
44445
  strokeAlpha: isStrokeGlyph ? st.strokeAlpha : void 0,
44449
- strokeWidth: isStrokeGlyph ? st.strokeWidth * ctmScale : 0,
44446
+ strokeWidth: isStrokeGlyph ? st.strokeWidth : 0,
44447
+ ...isStrokeGlyph ? { strokeMatrix: [...st.ctm] } : {},
44450
44448
  fillRule: "nonzero",
44451
44449
  ...st.blendMode && st.blendMode !== "Normal" ? { blendMode: st.blendMode } : {},
44452
44450
  ...st.clipRect ? { clipRect: [...st.clipRect] } : {}
@@ -46824,6 +46822,184 @@ function downscaleImage(image, widthScale, heightScale) {
46824
46822
  }
46825
46823
  return image;
46826
46824
  }
46825
+ var MAX_STROKE_VERTICES = 1e6;
46826
+ function dashSubpath(path, pattern, phase) {
46827
+ const cycle = pattern.reduce((sum, value) => sum + value, 0);
46828
+ if (!(cycle > 0)) return [path];
46829
+ let offset = (phase % cycle + cycle) % cycle, index = 0;
46830
+ while (offset > 0) {
46831
+ if (offset < pattern[index]) break;
46832
+ offset -= pattern[index];
46833
+ index = (index + 1) % pattern.length;
46834
+ }
46835
+ let remaining = pattern[index] - offset;
46836
+ const points = path.closed ? [...path.points, path.points[0]] : path.points;
46837
+ const result = [];
46838
+ let current = [];
46839
+ let steps = 0;
46840
+ const flush = () => {
46841
+ if (current.length) result.push({ points: current, closed: false });
46842
+ current = [];
46843
+ };
46844
+ const advance = (point) => {
46845
+ while (remaining <= 0) {
46846
+ if (++steps > MAX_STROKE_VERTICES) throw new PdfError("E_LIMIT", "Stroke dash expansion exceeds the vertex limit");
46847
+ if (index % 2 === 0) {
46848
+ if (pattern[index] === 0) result.push({ points: [point, point], closed: false });
46849
+ flush();
46850
+ }
46851
+ index = (index + 1) % pattern.length;
46852
+ remaining = pattern[index];
46853
+ }
46854
+ };
46855
+ for (let i = 1; i < points.length; i++) {
46856
+ const start = points[i - 1], end = points[i];
46857
+ const dx = end[0] - start[0], dy = end[1] - start[1];
46858
+ const length = Math.hypot(dx, dy);
46859
+ if (!Number.isFinite(length) || length / cycle * pattern.length > MAX_STROKE_VERTICES) {
46860
+ throw new PdfError("E_LIMIT", "Stroke dash expansion exceeds the vertex limit");
46861
+ }
46862
+ let distance = 0;
46863
+ while (distance < length) {
46864
+ const point = [start[0] + dx * distance / length, start[1] + dy * distance / length];
46865
+ advance(point);
46866
+ const step = Math.min(remaining, length - distance);
46867
+ if (distance + step === distance || ++steps > MAX_STROKE_VERTICES) throw new PdfError("E_LIMIT", "Stroke dash expansion exceeds the vertex limit");
46868
+ distance += step;
46869
+ remaining -= step;
46870
+ if (index % 2 === 0) {
46871
+ if (!current.length) current.push(point);
46872
+ current.push([start[0] + dx * distance / length, start[1] + dy * distance / length]);
46873
+ }
46874
+ }
46875
+ }
46876
+ flush();
46877
+ if (path.closed && result.length) {
46878
+ const first = result[0], last = result[result.length - 1];
46879
+ const start = path.points[0];
46880
+ const firstPoint = first.points[0], lastPoint = last.points[last.points.length - 1];
46881
+ if (firstPoint[0] === start[0] && firstPoint[1] === start[1] && lastPoint[0] === start[0] && lastPoint[1] === start[1]) {
46882
+ if (first === last) result[0] = { points: first.points, closed: true };
46883
+ else {
46884
+ result[0] = { points: [...last.points, ...first.points.slice(1)], closed: false };
46885
+ result.pop();
46886
+ }
46887
+ }
46888
+ }
46889
+ return result;
46890
+ }
46891
+ function strokeOutlines(paths, width, cap, join, miterLimit, dashArray = [], dashPhase = 0) {
46892
+ const half = width / 2;
46893
+ const contours = [];
46894
+ const pattern = dashArray.length % 2 ? [...dashArray, ...dashArray] : dashArray;
46895
+ let count = 0;
46896
+ let contour = [];
46897
+ const add = (x, y) => {
46898
+ if (++count > MAX_STROKE_VERTICES) throw new PdfError("E_LIMIT", "Stroke outline exceeds the vertex limit");
46899
+ contour.push([x, y]);
46900
+ };
46901
+ const arc = (point, dx1, dy1, dx2, dy2) => {
46902
+ let a1 = Math.atan2(dy1, dx1), a2 = Math.atan2(dy2, dx2);
46903
+ const ccw = a1 - a2 > 0 && a1 - a2 < Math.PI;
46904
+ const step = Math.acos(half / (half + 0.125)) * 2;
46905
+ add(point[0] + dx1, point[1] + dy1);
46906
+ if (step > 0) {
46907
+ if (!ccw) {
46908
+ if (a1 > a2) a2 += 2 * Math.PI;
46909
+ a2 -= step / 4;
46910
+ if ((a2 - a1) / step > MAX_STROKE_VERTICES - count) throw new PdfError("E_LIMIT", "Stroke arc exceeds the vertex limit");
46911
+ for (a1 += step; a1 < a2; a1 += step) add(point[0] + half * Math.cos(a1), point[1] + half * Math.sin(a1));
46912
+ } else {
46913
+ if (a1 < a2) a2 -= 2 * Math.PI;
46914
+ a2 += step / 4;
46915
+ if ((a1 - a2) / step > MAX_STROKE_VERTICES - count) throw new PdfError("E_LIMIT", "Stroke arc exceeds the vertex limit");
46916
+ for (a1 -= step; a1 > a2; a1 -= step) add(point[0] + half * Math.cos(a1), point[1] + half * Math.sin(a1));
46917
+ }
46918
+ }
46919
+ add(point[0] + dx2, point[1] + dy2);
46920
+ };
46921
+ const addCap = (point, next) => {
46922
+ const length = Math.hypot(next[0] - point[0], next[1] - point[1]);
46923
+ const dx = half * (next[1] - point[1]) / length;
46924
+ const dy = half * (next[0] - point[0]) / length;
46925
+ if (cap !== 1) {
46926
+ const sx = cap === 2 ? dy : 0, sy = cap === 2 ? dx : 0;
46927
+ add(point[0] - dx - sx, point[1] + dy - sy);
46928
+ add(point[0] + dx - sx, point[1] - dy - sy);
46929
+ } else {
46930
+ const angle = Math.atan2(dy, -dx);
46931
+ const step = Math.max(1e-3, Math.acos(half / (half + 0.125)) * 2);
46932
+ add(point[0] - dx, point[1] + dy);
46933
+ 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));
46934
+ add(point[0] + dx, point[1] - dy);
46935
+ }
46936
+ };
46937
+ const addJoin = (prev, point, next) => {
46938
+ const len1 = Math.hypot(point[0] - prev[0], point[1] - prev[1]);
46939
+ const len2 = Math.hypot(next[0] - point[0], next[1] - point[1]);
46940
+ const dx1 = half * (point[1] - prev[1]) / len1, dy1 = half * (point[0] - prev[0]) / len1;
46941
+ const dx2 = half * (next[1] - point[1]) / len2, dy2 = half * (next[0] - point[0]) / len2;
46942
+ const inner = (next[0] - point[0]) * (point[1] - prev[1]) - (next[1] - point[1]) * (point[0] - prev[0]) > 0;
46943
+ if (!inner && join === 1) {
46944
+ arc(point, dx1, -dy1, dx2, -dy2);
46945
+ return;
46946
+ }
46947
+ if (inner || join === 0) {
46948
+ const ax = prev[0] + dx1, ay = prev[1] - dy1;
46949
+ const bx = point[0] + dx1, by = point[1] - dy1;
46950
+ const cx = point[0] + dx2, cy = point[1] - dy2;
46951
+ const dx = next[0] + dx2, dy = next[1] - dy2;
46952
+ const den = (bx - ax) * (dy - cy) - (by - ay) * (dx - cx);
46953
+ if (Math.abs(den) >= 1e-30) {
46954
+ const t = ((ay - cy) * (dx - cx) - (ax - cx) * (dy - cy)) / den;
46955
+ const x = ax + (bx - ax) * t, y = ay + (by - ay) * t;
46956
+ if (Math.hypot(x - point[0], y - point[1]) <= half * (inner ? 1.01 : miterLimit)) {
46957
+ add(x, y);
46958
+ return;
46959
+ }
46960
+ } else if ((bx - prev[0]) * dy1 - (prev[1] - by) * dx1 < 0 !== (bx - next[0]) * dy1 - (next[1] - by) * dx1 < 0) {
46961
+ add(bx, by);
46962
+ return;
46963
+ }
46964
+ }
46965
+ add(point[0] + dx1, point[1] - dy1);
46966
+ add(point[0] + dx2, point[1] - dy2);
46967
+ };
46968
+ for (const path of paths) {
46969
+ for (const subpath of pattern.length ? dashSubpath(path, pattern, dashPhase) : [path]) {
46970
+ const points = [];
46971
+ for (const point of subpath.points) {
46972
+ const prev = points[points.length - 1];
46973
+ if (!prev || Math.hypot(prev[0] - point[0], prev[1] - point[1]) > 1e-14) points.push(point);
46974
+ }
46975
+ let closed = subpath.closed;
46976
+ 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();
46977
+ if (points.length < 3) closed = false;
46978
+ if (points.length === 1 && subpath.points.length > 1 && cap === 1) {
46979
+ contour = [];
46980
+ const [x, y] = points[0];
46981
+ addCap([x, y], [x + 1, y]);
46982
+ addCap([x, y], [x - 1, y]);
46983
+ contours.push(contour);
46984
+ } else if (points.length >= 2) {
46985
+ contour = [];
46986
+ if (!closed) addCap(points[0], points[1]);
46987
+ for (let i = closed ? 0 : 1; i < points.length - (closed ? 0 : 1); i++) {
46988
+ addJoin(points[(i + points.length - 1) % points.length], points[i], points[(i + 1) % points.length]);
46989
+ }
46990
+ if (closed) {
46991
+ contours.push(contour);
46992
+ contour = [];
46993
+ } else addCap(points[points.length - 1], points[points.length - 2]);
46994
+ for (let i = points.length - (closed ? 1 : 2); i >= (closed ? 0 : 1); i--) {
46995
+ addJoin(points[(i + 1) % points.length], points[i], points[(i + points.length - 1) % points.length]);
46996
+ }
46997
+ contours.push(contour);
46998
+ }
46999
+ }
47000
+ }
47001
+ return contours;
47002
+ }
46827
47003
  function decodePng(pngBytes) {
46828
47004
  if (pngBytes.length < 24 || pngBytes[0] !== 137 || pngBytes[1] !== 80 || pngBytes[2] !== 78 || pngBytes[3] !== 71) {
46829
47005
  throw new Error("Invalid PNG signature");
@@ -47518,111 +47694,116 @@ function blendPixel(rgba, width, height, px, py, color, alpha, blendMode, clipMa
47518
47694
  rgba[idx + 2] = Math.round((effB * a + cbB * dstA * (1 - a)) / outA * 255);
47519
47695
  rgba[idx + 3] = Math.round(outA * 255);
47520
47696
  }
47521
- function drawAntiAliasedSegment(rgba, width, height, x0, y0, x1, y1, strokeWidth, color, alpha = 1, lineCap = 0, antialias = true, blendMode, clipMask) {
47522
- const halfW = Math.max(0.6, strokeWidth * 0.5);
47523
- const dx = x1 - x0;
47524
- const dy = y1 - y0;
47525
- const lenSq = dx * dx + dy * dy;
47526
- const segLen = Math.sqrt(lenSq);
47527
- const pad = lineCap === 2 ? halfW + 2 : halfW + 1;
47528
- const minX = Math.max(0, Math.floor(Math.min(x0, x1) - pad));
47529
- const maxX = Math.min(width - 1, Math.ceil(Math.max(x0, x1) + pad));
47530
- const minY = Math.max(0, Math.floor(Math.min(y0, y1) - pad));
47531
- const maxY = Math.min(height - 1, Math.ceil(Math.max(y0, y1) + pad));
47532
- for (let py = minY; py <= maxY; py++) {
47533
- for (let px = minX; px <= maxX; px++) {
47534
- const cx = px + 0.5;
47535
- const cy = py + 0.5;
47536
- if (segLen > 1e-6 && (lineCap === 0 || lineCap === 2)) {
47537
- const ux = dx / segLen;
47538
- const uy = dy / segLen;
47539
- const along = (cx - x0) * ux + (cy - y0) * uy;
47540
- const perp = Math.abs(-(cx - x0) * uy + (cy - y0) * ux);
47541
- const minAlong = lineCap === 2 ? -halfW : 0;
47542
- const maxAlong = lineCap === 2 ? segLen + halfW : segLen;
47543
- const overAlong = along < minAlong ? minAlong - along : along > maxAlong ? along - maxAlong : 0;
47544
- const dist2 = overAlong > 0 ? Math.max(perp, halfW + overAlong) : perp;
47545
- if (dist2 <= halfW + 0.75) {
47546
- const cov = antialias ? Math.max(0, Math.min(1, halfW + 0.5 - dist2)) : dist2 <= halfW + 0.25 ? 1 : 0;
47547
- blendPixel(rgba, width, height, px, py, color, cov * alpha, blendMode, clipMask);
47548
- }
47549
- continue;
47550
- }
47551
- let t = lenSq > 1e-6 ? ((cx - x0) * dx + (cy - y0) * dy) / lenSq : 0;
47552
- t = Math.max(0, Math.min(1, t));
47553
- const projX = x0 + t * dx;
47554
- const projY = y0 + t * dy;
47555
- const dist = Math.hypot(cx - projX, cy - projY);
47556
- if (dist <= halfW + 0.75) {
47557
- const cov = antialias ? Math.max(0, Math.min(1, halfW + 0.5 - dist)) : dist <= halfW + 0.25 ? 1 : 0;
47558
- blendPixel(rgba, width, height, px, py, color, cov * alpha, blendMode, clipMask);
47559
- }
47560
- }
47561
- }
47697
+ function segmentsToScreenPaths(segments, pageHeight, scale, toScreen = (x, y) => [x * scale, (pageHeight - y) * scale]) {
47698
+ const paths = [];
47699
+ let points = [];
47700
+ let current = [0, 0];
47701
+ for (const segment of segments) {
47702
+ if (segment.kind === "move") {
47703
+ if (points.length) paths.push({ points, closed: false });
47704
+ current = toScreen(segment.x, segment.y);
47705
+ points = [current];
47706
+ } else if (segment.kind === "line") {
47707
+ if (!points.length) points = [current];
47708
+ current = toScreen(segment.x, segment.y);
47709
+ points.push(current);
47710
+ } else if (segment.kind === "cubic") {
47711
+ if (!points.length) points = [current];
47712
+ const a = toScreen(segment.x1, segment.y1), b = toScreen(segment.x2, segment.y2);
47713
+ const end = toScreen(segment.x, segment.y);
47714
+ const curve = flattenCubic(current[0], current[1], a[0], a[1], b[0], b[1], end[0], end[1]);
47715
+ for (let i = 1; i < curve.length; i++) points.push(curve[i]);
47716
+ current = end;
47717
+ } else if (segment.kind === "close") {
47718
+ if (points.length) {
47719
+ paths.push({ points, closed: true });
47720
+ current = points[0];
47721
+ points = [];
47722
+ }
47723
+ } else if (segment.kind === "rect") {
47724
+ if (points.length) paths.push({ points, closed: false });
47725
+ const first = toScreen(segment.x, segment.y);
47726
+ paths.push({ points: [
47727
+ first,
47728
+ toScreen(segment.x + segment.width, segment.y),
47729
+ toScreen(segment.x + segment.width, segment.y + segment.height),
47730
+ toScreen(segment.x, segment.y + segment.height)
47731
+ ], closed: true });
47732
+ current = first;
47733
+ points = [];
47734
+ }
47735
+ }
47736
+ if (points.length) paths.push({ points, closed: false });
47737
+ return paths;
47738
+ }
47739
+ function inverseStrokeMatrix(matrix) {
47740
+ const [a, b, c, d, e, f] = matrix;
47741
+ const det = a * d - b * c;
47742
+ if (!Number.isFinite(det) || det === 0) return void 0;
47743
+ return [d / det, -b / det, -c / det, a / det, (c * f - d * e) / det, (b * e - a * f) / det];
47744
+ }
47745
+ function prepareStroke(path, scale) {
47746
+ const matrix = path.strokeMatrix ? [...path.strokeMatrix] : [1, 0, 0, 1, 0, 0];
47747
+ const [a, b, c, d] = matrix;
47748
+ const area = Math.abs(a * d - b * c) * scale * scale;
47749
+ if (!(area > 0) || !Number.isFinite(area)) return void 0;
47750
+ const normX = Math.hypot(a, b) * scale, normY = Math.hypot(c, d) * scale;
47751
+ let width = path.strokeWidth || 1;
47752
+ const scaleX = path.strokeWidth === 0 ? normY / area : Math.max(1, normY / (width * area));
47753
+ const scaleY = path.strokeWidth === 0 ? normX / area : Math.max(1, normX / (width * area));
47754
+ let dashArray = path.dashArray, dashPhase = path.dashPhase ?? 0;
47755
+ if (scaleX === scaleY) {
47756
+ width *= scaleX;
47757
+ } else {
47758
+ matrix[0] *= scaleX;
47759
+ matrix[1] *= scaleX;
47760
+ matrix[2] *= scaleY;
47761
+ matrix[3] *= scaleY;
47762
+ if (dashArray?.length) {
47763
+ const dashScale = Math.max(scaleX, scaleY);
47764
+ dashArray = dashArray.map((value) => value / dashScale);
47765
+ dashPhase /= dashScale;
47766
+ }
47767
+ }
47768
+ return { matrix, width, dashArray, dashPhase };
47769
+ }
47770
+ function strokeEdges(path, pageHeight, scale) {
47771
+ const stroke = prepareStroke(path, scale);
47772
+ if (!stroke) return [];
47773
+ const inverse = inverseStrokeMatrix(stroke.matrix);
47774
+ if (!inverse) return [];
47775
+ const [a, b, c, d, e, f] = stroke.matrix;
47776
+ const strokeScale = scale * Math.hypot(a, b, c, d);
47777
+ const project = (x, y) => [
47778
+ (inverse[0] * x + inverse[2] * y + inverse[4]) * strokeScale,
47779
+ (inverse[1] * x + inverse[3] * y + inverse[5]) * strokeScale
47780
+ ];
47781
+ const toScreen = ([x, y]) => [
47782
+ (a * x / strokeScale + c * y / strokeScale + e) * scale,
47783
+ (pageHeight - b * x / strokeScale - d * y / strokeScale - f) * scale
47784
+ ];
47785
+ const contours = strokeOutlines(
47786
+ segmentsToScreenPaths(path.segments, pageHeight, scale, project),
47787
+ stroke.width * strokeScale,
47788
+ path.lineCap ?? 0,
47789
+ path.lineJoin ?? 0,
47790
+ path.miterLimit ?? 10,
47791
+ stroke.dashArray?.map((value) => Math.max(0, value * strokeScale)),
47792
+ stroke.dashPhase * strokeScale
47793
+ );
47794
+ return pathsToEdges(contours.map((points) => ({ points: points.map(toScreen), closed: true })));
47562
47795
  }
47563
- function segmentsToScreenEdges(segments, pageHeight, scale, closeSubpaths = false) {
47796
+ function pathsToEdges(paths, closeSubpaths = false) {
47564
47797
  const edges = [];
47565
- let curX = 0;
47566
- let curY = 0;
47567
- let startX = 0;
47568
- let startY = 0;
47569
- let hasOpenSubpath = false;
47570
- const toScreen = (x, y) => [x * scale, (pageHeight - y) * scale];
47571
- for (const seg of segments) {
47572
- if (seg.kind === "move") {
47573
- if (closeSubpaths && hasOpenSubpath && (curX !== startX || curY !== startY)) {
47574
- edges.push({ x0: curX, y0: curY, x1: startX, y1: startY });
47575
- }
47576
- [curX, curY] = toScreen(seg.x, seg.y);
47577
- startX = curX;
47578
- startY = curY;
47579
- hasOpenSubpath = false;
47580
- } else if (seg.kind === "line") {
47581
- const [nx, ny] = toScreen(seg.x, seg.y);
47582
- edges.push({ x0: curX, y0: curY, x1: nx, y1: ny });
47583
- curX = nx;
47584
- curY = ny;
47585
- hasOpenSubpath = true;
47586
- } else if (seg.kind === "cubic") {
47587
- const [p1x, p1y] = toScreen(seg.x1, seg.y1);
47588
- const [p2x, p2y] = toScreen(seg.x2, seg.y2);
47589
- const [p3x, p3y] = toScreen(seg.x, seg.y);
47590
- const points = flattenCubic(curX, curY, p1x, p1y, p2x, p2y, p3x, p3y);
47591
- let px = curX;
47592
- let py = curY;
47593
- for (let i = 1; i < points.length; i++) {
47594
- const [qx, qy] = points[i];
47595
- edges.push({ x0: px, y0: py, x1: qx, y1: qy });
47596
- px = qx;
47597
- py = qy;
47598
- }
47599
- curX = p3x;
47600
- curY = p3y;
47601
- hasOpenSubpath = true;
47602
- } else if (seg.kind === "close") {
47603
- if (curX !== startX || curY !== startY) {
47604
- edges.push({ x0: curX, y0: curY, x1: startX, y1: startY });
47605
- curX = startX;
47606
- curY = startY;
47607
- }
47608
- hasOpenSubpath = false;
47609
- } else if (seg.kind === "rect") {
47610
- if (closeSubpaths && hasOpenSubpath && (curX !== startX || curY !== startY)) {
47611
- edges.push({ x0: curX, y0: curY, x1: startX, y1: startY });
47612
- }
47613
- const [rx0, ry0] = toScreen(seg.x, seg.y);
47614
- const [rx1, ry1] = toScreen(seg.x + seg.width, seg.y + seg.height);
47615
- edges.push(
47616
- { x0: rx0, y0: ry0, x1: rx1, y1: ry0 },
47617
- { x0: rx1, y0: ry0, x1: rx1, y1: ry1 },
47618
- { x0: rx1, y0: ry1, x1: rx0, y1: ry1 },
47619
- { x0: rx0, y0: ry1, x1: rx0, y1: ry0 }
47620
- );
47621
- hasOpenSubpath = false;
47798
+ for (const { points, closed } of paths) {
47799
+ for (let i = 1; i < points.length; i++) {
47800
+ const a = points[i - 1], b = points[i];
47801
+ edges.push({ x0: a[0], y0: a[1], x1: b[0], y1: b[1] });
47802
+ }
47803
+ if ((closed || closeSubpaths) && points.length > 1) {
47804
+ const a = points[points.length - 1], b = points[0];
47805
+ edges.push({ x0: a[0], y0: a[1], x1: b[0], y1: b[1] });
47622
47806
  }
47623
- }
47624
- if (closeSubpaths && hasOpenSubpath && (curX !== startX || curY !== startY)) {
47625
- edges.push({ x0: curX, y0: curY, x1: startX, y1: startY });
47626
47807
  }
47627
47808
  return edges;
47628
47809
  }
@@ -47809,7 +47990,7 @@ function renderDisplayListToBitmap(displayList, options = {}) {
47809
47990
  for (const clip of clips) {
47810
47991
  const { segments, fillRule } = "segments" in clip ? clip : { segments: clip, fillRule: "nonzero" };
47811
47992
  const layer = new Uint8Array(width * height * 4);
47812
- fillEdgesScanline4x4(layer, width, height, segmentsToScreenEdges(segments, displayList.height, scale, true), { r: 1, g: 1, b: 1 }, 1, fillRule);
47993
+ fillEdgesScanline4x4(layer, width, height, pathsToEdges(segmentsToScreenPaths(segments, displayList.height, scale), true), { r: 1, g: 1, b: 1 }, 1, fillRule);
47813
47994
  for (let i = 3; i < layer.length; i += 4) clipMask[i] = Math.round(clipMask[i] * layer[i] / 255);
47814
47995
  }
47815
47996
  cachedClips = clips;
@@ -47856,62 +48037,28 @@ function renderDisplayListToBitmap(displayList, options = {}) {
47856
48037
  if (operation.kind === "path") {
47857
48038
  const path = operation.value;
47858
48039
  if (path.fillColor) {
47859
- const edges = segmentsToScreenEdges(path.segments, displayList.height, scale, true);
48040
+ const edges = pathsToEdges(segmentsToScreenPaths(path.segments, displayList.height, scale), true);
47860
48041
  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;
47861
48042
  fillEdgesScanline4x4(rgba, width, height, edges, path.fillColor, path.fillAlpha ?? 1, path.fillRule ?? "nonzero", clipScreen, original.kind === "glyph" ? aaTxt : aaVec, path.blendMode, clipMask);
47862
48043
  }
47863
48044
  if (path.strokeColor) {
47864
- const edges = segmentsToScreenEdges(path.segments, displayList.height, scale, false);
47865
- const rawSw = path.strokeWidth * scale;
47866
- const sw = Math.max(1, rawSw);
48045
+ const rawSw = path.strokeWidth * scale * (path.strokeMatrix ? Math.hypot(path.strokeMatrix[0], path.strokeMatrix[1]) : 1);
47867
48046
  const strokeAlpha = options.thinLineMode === "shape" && rawSw < 1 ? (path.strokeAlpha ?? 1) * Math.max(0.25, rawSw) : path.strokeAlpha ?? 1;
47868
- const dashArr = path.dashArray && path.dashArray.length > 0 ? path.dashArray.map((d) => Math.max(0, d * scale)) : void 0;
47869
- const dashCycle = dashArr ? dashArr.reduce((a, b) => a + b, 0) : 0;
47870
- let dashDist = (path.dashPhase ?? 0) * scale % (dashCycle || 1);
47871
- if (dashDist < 0) dashDist += dashCycle;
47872
- for (const e of edges) {
47873
- if (!dashArr || dashCycle <= 1e-4) {
47874
- 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);
47875
- } else {
47876
- const dx = e.x1 - e.x0;
47877
- const dy = e.y1 - e.y0;
47878
- const edgeLen = Math.hypot(dx, dy);
47879
- if (edgeLen <= 1e-4) continue;
47880
- let pos = 0;
47881
- while (pos < edgeLen) {
47882
- let cycleRem = dashDist % dashCycle;
47883
- let dIdx = 0;
47884
- while (dIdx < dashArr.length - 1 && cycleRem >= dashArr[dIdx]) {
47885
- cycleRem -= dashArr[dIdx];
47886
- dIdx++;
47887
- }
47888
- const segRemainInDash = Math.max(1e-4, dashArr[dIdx] - cycleRem);
47889
- const step = Math.min(edgeLen - pos, segRemainInDash);
47890
- if (dIdx % 2 === 0) {
47891
- const t0 = pos / edgeLen;
47892
- const t1 = (pos + step) / edgeLen;
47893
- drawAntiAliasedSegment(
47894
- rgba,
47895
- width,
47896
- height,
47897
- e.x0 + dx * t0,
47898
- e.y0 + dy * t0,
47899
- e.x0 + dx * t1,
47900
- e.y0 + dy * t1,
47901
- sw,
47902
- path.strokeColor,
47903
- strokeAlpha,
47904
- path.lineCap ?? 0,
47905
- original.kind === "glyph" ? aaTxt : aaVec,
47906
- path.blendMode,
47907
- clipMask
47908
- );
47909
- }
47910
- pos += step;
47911
- dashDist = (dashDist + step) % dashCycle;
47912
- }
47913
- }
47914
- }
48047
+ const edges = strokeEdges(path, displayList.height, scale);
48048
+ 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;
48049
+ fillEdgesScanline4x4(
48050
+ rgba,
48051
+ width,
48052
+ height,
48053
+ edges,
48054
+ path.strokeColor,
48055
+ strokeAlpha,
48056
+ "nonzero",
48057
+ clipScreen,
48058
+ original.kind === "glyph" ? aaTxt : aaVec,
48059
+ path.blendMode,
48060
+ clipMask
48061
+ );
47915
48062
  }
47916
48063
  } else if (operation.kind === "image") {
47917
48064
  const img = operation.value;
@@ -62701,3 +62848,15 @@ export {
62701
62848
  * Copyright 2012 Mozilla Foundation. Licensed under Apache-2.0.
62702
62849
  * See THIRD_PARTY_NOTICES.md for the source revision and adaptations.
62703
62850
  */
62851
+ /*!
62852
+ * Anti-Grain Geometry - Version 2.3
62853
+ * Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
62854
+ *
62855
+ * Permission to copy, use, modify, sell and distribute this software
62856
+ * is granted provided this copyright notice appears in all copies.
62857
+ * This software is provided "as is" without express or implied
62858
+ * warranty, and with no claim as to its suitability for any purpose.
62859
+ *
62860
+ * Adapted from PDFium agg_math_stroke.h and agg_vcgen_stroke.cpp.
62861
+ * See THIRD_PARTY_NOTICES.md for the source revision and adaptations.
62862
+ */