@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
@@ -35704,11 +35704,10 @@ function evaluateContentStreamToDisplayList(params) {
35704
35704
  } else if (operator === "d") {
35705
35705
  const arrNode = ops[0]?.kind === "array" ? ops[0] : void 0;
35706
35706
  if (arrNode) {
35707
- const ctmScale = Math.max(1e-6, Math.hypot(st.ctm[0], st.ctm[1]));
35708
- const nums = arrNode.items.map((it) => it.kind === "number" ? it.value * ctmScale : 0).filter((v) => v >= 0);
35707
+ const nums = arrNode.items.map((it) => it.kind === "number" ? it.value : 0).filter((v) => v >= 0);
35709
35708
  const sum = nums.reduce((a, b) => a + b, 0);
35710
35709
  st.dashArray = sum > 0 ? nums : void 0;
35711
- st.dashPhase = num(1, 0) * ctmScale;
35710
+ st.dashPhase = num(1, 0);
35712
35711
  } else {
35713
35712
  st.dashArray = void 0;
35714
35713
  st.dashPhase = void 0;
@@ -36244,15 +36243,14 @@ function evaluateContentStreamToDisplayList(params) {
36244
36243
  break;
36245
36244
  }
36246
36245
  const fillRule = node.paint.includes("*") ? "evenodd" : "nonzero";
36247
- const ctmScale = Math.max(1e-6, Math.hypot(st.ctm[0], st.ctm[1]));
36248
- const scaledStrokeWidth = st.strokeWidth === 0 ? 0 : st.strokeWidth * ctmScale;
36249
36246
  emit({ kind: "path", value: {
36250
36247
  segments: transformedSegments,
36251
36248
  fillColor: isFill && !evaluatedFillPattern ? st.fillColor : void 0,
36252
36249
  fillAlpha: isFill && !evaluatedFillPattern ? st.fillAlpha : void 0,
36253
36250
  strokeColor: isStroke ? st.strokeColor : void 0,
36254
36251
  strokeAlpha: isStroke ? st.strokeAlpha : void 0,
36255
- strokeWidth: scaledStrokeWidth,
36252
+ strokeWidth: st.strokeWidth,
36253
+ ...isStroke ? { strokeMatrix: [...st.ctm] } : {},
36256
36254
  ...st.lineCap !== 0 ? { lineCap: st.lineCap } : {},
36257
36255
  ...st.lineJoin !== 0 ? { lineJoin: st.lineJoin } : {},
36258
36256
  ...st.miterLimit !== 10 ? { miterLimit: st.miterLimit } : {},
@@ -36440,14 +36438,14 @@ function evaluateContentStreamToDisplayList(params) {
36440
36438
  if (st.textRenderMode >= 4 && st.textRenderMode <= 7) pendingTextClip.push(...transformedGlyphSegs);
36441
36439
  const isFillGlyph = st.textRenderMode === 0 || st.textRenderMode === 2 || st.textRenderMode === 4 || st.textRenderMode === 6;
36442
36440
  const isStrokeGlyph = st.textRenderMode === 1 || st.textRenderMode === 2 || st.textRenderMode === 5 || st.textRenderMode === 6;
36443
- const ctmScale = Math.max(1e-6, Math.hypot(st.ctm[0], st.ctm[1]));
36444
36441
  const paint = {
36445
36442
  segments: transformedGlyphSegs,
36446
36443
  fillColor: isFillGlyph ? st.fillColor : void 0,
36447
36444
  fillAlpha: isFillGlyph ? st.fillAlpha : void 0,
36448
36445
  strokeColor: isStrokeGlyph ? st.strokeColor : void 0,
36449
36446
  strokeAlpha: isStrokeGlyph ? st.strokeAlpha : void 0,
36450
- strokeWidth: isStrokeGlyph ? st.strokeWidth * ctmScale : 0,
36447
+ strokeWidth: isStrokeGlyph ? st.strokeWidth : 0,
36448
+ ...isStrokeGlyph ? { strokeMatrix: [...st.ctm] } : {},
36451
36449
  fillRule: "nonzero",
36452
36450
  ...st.blendMode && st.blendMode !== "Normal" ? { blendMode: st.blendMode } : {},
36453
36451
  ...st.clipRect ? { clipRect: [...st.clipRect] } : {}
@@ -38935,6 +38933,184 @@ function downscaleImage(image, widthScale, heightScale) {
38935
38933
  }
38936
38934
  return image;
38937
38935
  }
38936
+ var MAX_STROKE_VERTICES = 1e6;
38937
+ function dashSubpath(path, pattern, phase) {
38938
+ const cycle = pattern.reduce((sum, value) => sum + value, 0);
38939
+ if (!(cycle > 0)) return [path];
38940
+ let offset = (phase % cycle + cycle) % cycle, index = 0;
38941
+ while (offset > 0) {
38942
+ if (offset < pattern[index]) break;
38943
+ offset -= pattern[index];
38944
+ index = (index + 1) % pattern.length;
38945
+ }
38946
+ let remaining = pattern[index] - offset;
38947
+ const points = path.closed ? [...path.points, path.points[0]] : path.points;
38948
+ const result = [];
38949
+ let current = [];
38950
+ let steps = 0;
38951
+ const flush = () => {
38952
+ if (current.length) result.push({ points: current, closed: false });
38953
+ current = [];
38954
+ };
38955
+ const advance = (point) => {
38956
+ while (remaining <= 0) {
38957
+ if (++steps > MAX_STROKE_VERTICES) throw new PdfError("E_LIMIT", "Stroke dash expansion exceeds the vertex limit");
38958
+ if (index % 2 === 0) {
38959
+ if (pattern[index] === 0) result.push({ points: [point, point], closed: false });
38960
+ flush();
38961
+ }
38962
+ index = (index + 1) % pattern.length;
38963
+ remaining = pattern[index];
38964
+ }
38965
+ };
38966
+ for (let i = 1; i < points.length; i++) {
38967
+ const start = points[i - 1], end = points[i];
38968
+ const dx = end[0] - start[0], dy = end[1] - start[1];
38969
+ const length = Math.hypot(dx, dy);
38970
+ if (!Number.isFinite(length) || length / cycle * pattern.length > MAX_STROKE_VERTICES) {
38971
+ throw new PdfError("E_LIMIT", "Stroke dash expansion exceeds the vertex limit");
38972
+ }
38973
+ let distance = 0;
38974
+ while (distance < length) {
38975
+ const point = [start[0] + dx * distance / length, start[1] + dy * distance / length];
38976
+ advance(point);
38977
+ const step = Math.min(remaining, length - distance);
38978
+ if (distance + step === distance || ++steps > MAX_STROKE_VERTICES) throw new PdfError("E_LIMIT", "Stroke dash expansion exceeds the vertex limit");
38979
+ distance += step;
38980
+ remaining -= step;
38981
+ if (index % 2 === 0) {
38982
+ if (!current.length) current.push(point);
38983
+ current.push([start[0] + dx * distance / length, start[1] + dy * distance / length]);
38984
+ }
38985
+ }
38986
+ }
38987
+ flush();
38988
+ if (path.closed && result.length) {
38989
+ const first = result[0], last = result[result.length - 1];
38990
+ const start = path.points[0];
38991
+ const firstPoint = first.points[0], lastPoint = last.points[last.points.length - 1];
38992
+ if (firstPoint[0] === start[0] && firstPoint[1] === start[1] && lastPoint[0] === start[0] && lastPoint[1] === start[1]) {
38993
+ if (first === last) result[0] = { points: first.points, closed: true };
38994
+ else {
38995
+ result[0] = { points: [...last.points, ...first.points.slice(1)], closed: false };
38996
+ result.pop();
38997
+ }
38998
+ }
38999
+ }
39000
+ return result;
39001
+ }
39002
+ function strokeOutlines(paths, width, cap, join, miterLimit, dashArray = [], dashPhase = 0) {
39003
+ const half = width / 2;
39004
+ const contours = [];
39005
+ const pattern = dashArray.length % 2 ? [...dashArray, ...dashArray] : dashArray;
39006
+ let count = 0;
39007
+ let contour = [];
39008
+ const add = (x, y) => {
39009
+ if (++count > MAX_STROKE_VERTICES) throw new PdfError("E_LIMIT", "Stroke outline exceeds the vertex limit");
39010
+ contour.push([x, y]);
39011
+ };
39012
+ const arc = (point, dx1, dy1, dx2, dy2) => {
39013
+ let a1 = Math.atan2(dy1, dx1), a2 = Math.atan2(dy2, dx2);
39014
+ const ccw = a1 - a2 > 0 && a1 - a2 < Math.PI;
39015
+ const step = Math.acos(half / (half + 0.125)) * 2;
39016
+ add(point[0] + dx1, point[1] + dy1);
39017
+ if (step > 0) {
39018
+ if (!ccw) {
39019
+ if (a1 > a2) a2 += 2 * Math.PI;
39020
+ a2 -= step / 4;
39021
+ if ((a2 - a1) / step > MAX_STROKE_VERTICES - count) throw new PdfError("E_LIMIT", "Stroke arc exceeds the vertex limit");
39022
+ for (a1 += step; a1 < a2; a1 += step) add(point[0] + half * Math.cos(a1), point[1] + half * Math.sin(a1));
39023
+ } else {
39024
+ if (a1 < a2) a2 -= 2 * Math.PI;
39025
+ a2 += step / 4;
39026
+ if ((a1 - a2) / step > MAX_STROKE_VERTICES - count) throw new PdfError("E_LIMIT", "Stroke arc exceeds the vertex limit");
39027
+ for (a1 -= step; a1 > a2; a1 -= step) add(point[0] + half * Math.cos(a1), point[1] + half * Math.sin(a1));
39028
+ }
39029
+ }
39030
+ add(point[0] + dx2, point[1] + dy2);
39031
+ };
39032
+ const addCap = (point, next) => {
39033
+ const length = Math.hypot(next[0] - point[0], next[1] - point[1]);
39034
+ const dx = half * (next[1] - point[1]) / length;
39035
+ const dy = half * (next[0] - point[0]) / length;
39036
+ if (cap !== 1) {
39037
+ const sx = cap === 2 ? dy : 0, sy = cap === 2 ? dx : 0;
39038
+ add(point[0] - dx - sx, point[1] + dy - sy);
39039
+ add(point[0] + dx - sx, point[1] - dy - sy);
39040
+ } else {
39041
+ const angle = Math.atan2(dy, -dx);
39042
+ const step = Math.max(1e-3, Math.acos(half / (half + 0.125)) * 2);
39043
+ add(point[0] - dx, point[1] + dy);
39044
+ 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));
39045
+ add(point[0] + dx, point[1] - dy);
39046
+ }
39047
+ };
39048
+ const addJoin = (prev, point, next) => {
39049
+ const len1 = Math.hypot(point[0] - prev[0], point[1] - prev[1]);
39050
+ const len2 = Math.hypot(next[0] - point[0], next[1] - point[1]);
39051
+ const dx1 = half * (point[1] - prev[1]) / len1, dy1 = half * (point[0] - prev[0]) / len1;
39052
+ const dx2 = half * (next[1] - point[1]) / len2, dy2 = half * (next[0] - point[0]) / len2;
39053
+ const inner = (next[0] - point[0]) * (point[1] - prev[1]) - (next[1] - point[1]) * (point[0] - prev[0]) > 0;
39054
+ if (!inner && join === 1) {
39055
+ arc(point, dx1, -dy1, dx2, -dy2);
39056
+ return;
39057
+ }
39058
+ if (inner || join === 0) {
39059
+ const ax = prev[0] + dx1, ay = prev[1] - dy1;
39060
+ const bx = point[0] + dx1, by = point[1] - dy1;
39061
+ const cx = point[0] + dx2, cy = point[1] - dy2;
39062
+ const dx = next[0] + dx2, dy = next[1] - dy2;
39063
+ const den = (bx - ax) * (dy - cy) - (by - ay) * (dx - cx);
39064
+ if (Math.abs(den) >= 1e-30) {
39065
+ const t = ((ay - cy) * (dx - cx) - (ax - cx) * (dy - cy)) / den;
39066
+ const x = ax + (bx - ax) * t, y = ay + (by - ay) * t;
39067
+ if (Math.hypot(x - point[0], y - point[1]) <= half * (inner ? 1.01 : miterLimit)) {
39068
+ add(x, y);
39069
+ return;
39070
+ }
39071
+ } else if ((bx - prev[0]) * dy1 - (prev[1] - by) * dx1 < 0 !== (bx - next[0]) * dy1 - (next[1] - by) * dx1 < 0) {
39072
+ add(bx, by);
39073
+ return;
39074
+ }
39075
+ }
39076
+ add(point[0] + dx1, point[1] - dy1);
39077
+ add(point[0] + dx2, point[1] - dy2);
39078
+ };
39079
+ for (const path of paths) {
39080
+ for (const subpath of pattern.length ? dashSubpath(path, pattern, dashPhase) : [path]) {
39081
+ const points = [];
39082
+ for (const point of subpath.points) {
39083
+ const prev = points[points.length - 1];
39084
+ if (!prev || Math.hypot(prev[0] - point[0], prev[1] - point[1]) > 1e-14) points.push(point);
39085
+ }
39086
+ let closed = subpath.closed;
39087
+ 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();
39088
+ if (points.length < 3) closed = false;
39089
+ if (points.length === 1 && subpath.points.length > 1 && cap === 1) {
39090
+ contour = [];
39091
+ const [x, y] = points[0];
39092
+ addCap([x, y], [x + 1, y]);
39093
+ addCap([x, y], [x - 1, y]);
39094
+ contours.push(contour);
39095
+ } else if (points.length >= 2) {
39096
+ contour = [];
39097
+ if (!closed) addCap(points[0], points[1]);
39098
+ for (let i = closed ? 0 : 1; i < points.length - (closed ? 0 : 1); i++) {
39099
+ addJoin(points[(i + points.length - 1) % points.length], points[i], points[(i + 1) % points.length]);
39100
+ }
39101
+ if (closed) {
39102
+ contours.push(contour);
39103
+ contour = [];
39104
+ } else addCap(points[points.length - 1], points[points.length - 2]);
39105
+ for (let i = points.length - (closed ? 1 : 2); i >= (closed ? 0 : 1); i--) {
39106
+ addJoin(points[(i + 1) % points.length], points[i], points[(i + points.length - 1) % points.length]);
39107
+ }
39108
+ contours.push(contour);
39109
+ }
39110
+ }
39111
+ }
39112
+ return contours;
39113
+ }
38938
39114
  function decodePng(pngBytes) {
38939
39115
  if (pngBytes.length < 24 || pngBytes[0] !== 137 || pngBytes[1] !== 80 || pngBytes[2] !== 78 || pngBytes[3] !== 71) {
38940
39116
  throw new Error("Invalid PNG signature");
@@ -39629,111 +39805,116 @@ function blendPixel(rgba, width, height, px, py, color, alpha, blendMode, clipMa
39629
39805
  rgba[idx + 2] = Math.round((effB * a + cbB * dstA * (1 - a)) / outA * 255);
39630
39806
  rgba[idx + 3] = Math.round(outA * 255);
39631
39807
  }
39632
- function drawAntiAliasedSegment(rgba, width, height, x0, y0, x1, y1, strokeWidth, color, alpha = 1, lineCap = 0, antialias = true, blendMode, clipMask) {
39633
- const halfW = Math.max(0.6, strokeWidth * 0.5);
39634
- const dx = x1 - x0;
39635
- const dy = y1 - y0;
39636
- const lenSq = dx * dx + dy * dy;
39637
- const segLen = Math.sqrt(lenSq);
39638
- const pad = lineCap === 2 ? halfW + 2 : halfW + 1;
39639
- const minX = Math.max(0, Math.floor(Math.min(x0, x1) - pad));
39640
- const maxX = Math.min(width - 1, Math.ceil(Math.max(x0, x1) + pad));
39641
- const minY = Math.max(0, Math.floor(Math.min(y0, y1) - pad));
39642
- const maxY = Math.min(height - 1, Math.ceil(Math.max(y0, y1) + pad));
39643
- for (let py = minY; py <= maxY; py++) {
39644
- for (let px = minX; px <= maxX; px++) {
39645
- const cx = px + 0.5;
39646
- const cy = py + 0.5;
39647
- if (segLen > 1e-6 && (lineCap === 0 || lineCap === 2)) {
39648
- const ux = dx / segLen;
39649
- const uy = dy / segLen;
39650
- const along = (cx - x0) * ux + (cy - y0) * uy;
39651
- const perp = Math.abs(-(cx - x0) * uy + (cy - y0) * ux);
39652
- const minAlong = lineCap === 2 ? -halfW : 0;
39653
- const maxAlong = lineCap === 2 ? segLen + halfW : segLen;
39654
- const overAlong = along < minAlong ? minAlong - along : along > maxAlong ? along - maxAlong : 0;
39655
- const dist2 = overAlong > 0 ? Math.max(perp, halfW + overAlong) : perp;
39656
- if (dist2 <= halfW + 0.75) {
39657
- const cov = antialias ? Math.max(0, Math.min(1, halfW + 0.5 - dist2)) : dist2 <= halfW + 0.25 ? 1 : 0;
39658
- blendPixel(rgba, width, height, px, py, color, cov * alpha, blendMode, clipMask);
39659
- }
39660
- continue;
39661
- }
39662
- let t = lenSq > 1e-6 ? ((cx - x0) * dx + (cy - y0) * dy) / lenSq : 0;
39663
- t = Math.max(0, Math.min(1, t));
39664
- const projX = x0 + t * dx;
39665
- const projY = y0 + t * dy;
39666
- const dist = Math.hypot(cx - projX, cy - projY);
39667
- if (dist <= halfW + 0.75) {
39668
- const cov = antialias ? Math.max(0, Math.min(1, halfW + 0.5 - dist)) : dist <= halfW + 0.25 ? 1 : 0;
39669
- blendPixel(rgba, width, height, px, py, color, cov * alpha, blendMode, clipMask);
39670
- }
39671
- }
39672
- }
39808
+ function segmentsToScreenPaths(segments, pageHeight, scale, toScreen = (x, y) => [x * scale, (pageHeight - y) * scale]) {
39809
+ const paths = [];
39810
+ let points = [];
39811
+ let current = [0, 0];
39812
+ for (const segment of segments) {
39813
+ if (segment.kind === "move") {
39814
+ if (points.length) paths.push({ points, closed: false });
39815
+ current = toScreen(segment.x, segment.y);
39816
+ points = [current];
39817
+ } else if (segment.kind === "line") {
39818
+ if (!points.length) points = [current];
39819
+ current = toScreen(segment.x, segment.y);
39820
+ points.push(current);
39821
+ } else if (segment.kind === "cubic") {
39822
+ if (!points.length) points = [current];
39823
+ const a = toScreen(segment.x1, segment.y1), b = toScreen(segment.x2, segment.y2);
39824
+ const end = toScreen(segment.x, segment.y);
39825
+ const curve = flattenCubic(current[0], current[1], a[0], a[1], b[0], b[1], end[0], end[1]);
39826
+ for (let i = 1; i < curve.length; i++) points.push(curve[i]);
39827
+ current = end;
39828
+ } else if (segment.kind === "close") {
39829
+ if (points.length) {
39830
+ paths.push({ points, closed: true });
39831
+ current = points[0];
39832
+ points = [];
39833
+ }
39834
+ } else if (segment.kind === "rect") {
39835
+ if (points.length) paths.push({ points, closed: false });
39836
+ const first = toScreen(segment.x, segment.y);
39837
+ paths.push({ points: [
39838
+ first,
39839
+ toScreen(segment.x + segment.width, segment.y),
39840
+ toScreen(segment.x + segment.width, segment.y + segment.height),
39841
+ toScreen(segment.x, segment.y + segment.height)
39842
+ ], closed: true });
39843
+ current = first;
39844
+ points = [];
39845
+ }
39846
+ }
39847
+ if (points.length) paths.push({ points, closed: false });
39848
+ return paths;
39849
+ }
39850
+ function inverseStrokeMatrix(matrix) {
39851
+ const [a, b, c, d, e, f] = matrix;
39852
+ const det = a * d - b * c;
39853
+ if (!Number.isFinite(det) || det === 0) return void 0;
39854
+ return [d / det, -b / det, -c / det, a / det, (c * f - d * e) / det, (b * e - a * f) / det];
39855
+ }
39856
+ function prepareStroke(path, scale) {
39857
+ const matrix = path.strokeMatrix ? [...path.strokeMatrix] : [1, 0, 0, 1, 0, 0];
39858
+ const [a, b, c, d] = matrix;
39859
+ const area = Math.abs(a * d - b * c) * scale * scale;
39860
+ if (!(area > 0) || !Number.isFinite(area)) return void 0;
39861
+ const normX = Math.hypot(a, b) * scale, normY = Math.hypot(c, d) * scale;
39862
+ let width = path.strokeWidth || 1;
39863
+ const scaleX = path.strokeWidth === 0 ? normY / area : Math.max(1, normY / (width * area));
39864
+ const scaleY = path.strokeWidth === 0 ? normX / area : Math.max(1, normX / (width * area));
39865
+ let dashArray = path.dashArray, dashPhase = path.dashPhase ?? 0;
39866
+ if (scaleX === scaleY) {
39867
+ width *= scaleX;
39868
+ } else {
39869
+ matrix[0] *= scaleX;
39870
+ matrix[1] *= scaleX;
39871
+ matrix[2] *= scaleY;
39872
+ matrix[3] *= scaleY;
39873
+ if (dashArray?.length) {
39874
+ const dashScale = Math.max(scaleX, scaleY);
39875
+ dashArray = dashArray.map((value) => value / dashScale);
39876
+ dashPhase /= dashScale;
39877
+ }
39878
+ }
39879
+ return { matrix, width, dashArray, dashPhase };
39880
+ }
39881
+ function strokeEdges(path, pageHeight, scale) {
39882
+ const stroke = prepareStroke(path, scale);
39883
+ if (!stroke) return [];
39884
+ const inverse = inverseStrokeMatrix(stroke.matrix);
39885
+ if (!inverse) return [];
39886
+ const [a, b, c, d, e, f] = stroke.matrix;
39887
+ const strokeScale = scale * Math.hypot(a, b, c, d);
39888
+ const project = (x, y) => [
39889
+ (inverse[0] * x + inverse[2] * y + inverse[4]) * strokeScale,
39890
+ (inverse[1] * x + inverse[3] * y + inverse[5]) * strokeScale
39891
+ ];
39892
+ const toScreen = ([x, y]) => [
39893
+ (a * x / strokeScale + c * y / strokeScale + e) * scale,
39894
+ (pageHeight - b * x / strokeScale - d * y / strokeScale - f) * scale
39895
+ ];
39896
+ const contours = strokeOutlines(
39897
+ segmentsToScreenPaths(path.segments, pageHeight, scale, project),
39898
+ stroke.width * strokeScale,
39899
+ path.lineCap ?? 0,
39900
+ path.lineJoin ?? 0,
39901
+ path.miterLimit ?? 10,
39902
+ stroke.dashArray?.map((value) => Math.max(0, value * strokeScale)),
39903
+ stroke.dashPhase * strokeScale
39904
+ );
39905
+ return pathsToEdges(contours.map((points) => ({ points: points.map(toScreen), closed: true })));
39673
39906
  }
39674
- function segmentsToScreenEdges(segments, pageHeight, scale, closeSubpaths = false) {
39907
+ function pathsToEdges(paths, closeSubpaths = false) {
39675
39908
  const edges = [];
39676
- let curX = 0;
39677
- let curY = 0;
39678
- let startX = 0;
39679
- let startY = 0;
39680
- let hasOpenSubpath = false;
39681
- const toScreen = (x, y) => [x * scale, (pageHeight - y) * scale];
39682
- for (const seg of segments) {
39683
- if (seg.kind === "move") {
39684
- if (closeSubpaths && hasOpenSubpath && (curX !== startX || curY !== startY)) {
39685
- edges.push({ x0: curX, y0: curY, x1: startX, y1: startY });
39686
- }
39687
- [curX, curY] = toScreen(seg.x, seg.y);
39688
- startX = curX;
39689
- startY = curY;
39690
- hasOpenSubpath = false;
39691
- } else if (seg.kind === "line") {
39692
- const [nx, ny] = toScreen(seg.x, seg.y);
39693
- edges.push({ x0: curX, y0: curY, x1: nx, y1: ny });
39694
- curX = nx;
39695
- curY = ny;
39696
- hasOpenSubpath = true;
39697
- } else if (seg.kind === "cubic") {
39698
- const [p1x, p1y] = toScreen(seg.x1, seg.y1);
39699
- const [p2x, p2y] = toScreen(seg.x2, seg.y2);
39700
- const [p3x, p3y] = toScreen(seg.x, seg.y);
39701
- const points = flattenCubic(curX, curY, p1x, p1y, p2x, p2y, p3x, p3y);
39702
- let px = curX;
39703
- let py = curY;
39704
- for (let i = 1; i < points.length; i++) {
39705
- const [qx, qy] = points[i];
39706
- edges.push({ x0: px, y0: py, x1: qx, y1: qy });
39707
- px = qx;
39708
- py = qy;
39709
- }
39710
- curX = p3x;
39711
- curY = p3y;
39712
- hasOpenSubpath = true;
39713
- } else if (seg.kind === "close") {
39714
- if (curX !== startX || curY !== startY) {
39715
- edges.push({ x0: curX, y0: curY, x1: startX, y1: startY });
39716
- curX = startX;
39717
- curY = startY;
39718
- }
39719
- hasOpenSubpath = false;
39720
- } else if (seg.kind === "rect") {
39721
- if (closeSubpaths && hasOpenSubpath && (curX !== startX || curY !== startY)) {
39722
- edges.push({ x0: curX, y0: curY, x1: startX, y1: startY });
39723
- }
39724
- const [rx0, ry0] = toScreen(seg.x, seg.y);
39725
- const [rx1, ry1] = toScreen(seg.x + seg.width, seg.y + seg.height);
39726
- edges.push(
39727
- { x0: rx0, y0: ry0, x1: rx1, y1: ry0 },
39728
- { x0: rx1, y0: ry0, x1: rx1, y1: ry1 },
39729
- { x0: rx1, y0: ry1, x1: rx0, y1: ry1 },
39730
- { x0: rx0, y0: ry1, x1: rx0, y1: ry0 }
39731
- );
39732
- hasOpenSubpath = false;
39909
+ for (const { points, closed } of paths) {
39910
+ for (let i = 1; i < points.length; i++) {
39911
+ const a = points[i - 1], b = points[i];
39912
+ edges.push({ x0: a[0], y0: a[1], x1: b[0], y1: b[1] });
39913
+ }
39914
+ if ((closed || closeSubpaths) && points.length > 1) {
39915
+ const a = points[points.length - 1], b = points[0];
39916
+ edges.push({ x0: a[0], y0: a[1], x1: b[0], y1: b[1] });
39733
39917
  }
39734
- }
39735
- if (closeSubpaths && hasOpenSubpath && (curX !== startX || curY !== startY)) {
39736
- edges.push({ x0: curX, y0: curY, x1: startX, y1: startY });
39737
39918
  }
39738
39919
  return edges;
39739
39920
  }
@@ -39920,7 +40101,7 @@ function renderDisplayListToBitmap(displayList, options = {}) {
39920
40101
  for (const clip of clips) {
39921
40102
  const { segments, fillRule } = "segments" in clip ? clip : { segments: clip, fillRule: "nonzero" };
39922
40103
  const layer = new Uint8Array(width * height * 4);
39923
- fillEdgesScanline4x4(layer, width, height, segmentsToScreenEdges(segments, displayList.height, scale, true), { r: 1, g: 1, b: 1 }, 1, fillRule);
40104
+ fillEdgesScanline4x4(layer, width, height, pathsToEdges(segmentsToScreenPaths(segments, displayList.height, scale), true), { r: 1, g: 1, b: 1 }, 1, fillRule);
39924
40105
  for (let i = 3; i < layer.length; i += 4) clipMask[i] = Math.round(clipMask[i] * layer[i] / 255);
39925
40106
  }
39926
40107
  cachedClips = clips;
@@ -39967,62 +40148,28 @@ function renderDisplayListToBitmap(displayList, options = {}) {
39967
40148
  if (operation.kind === "path") {
39968
40149
  const path = operation.value;
39969
40150
  if (path.fillColor) {
39970
- const edges = segmentsToScreenEdges(path.segments, displayList.height, scale, true);
40151
+ const edges = pathsToEdges(segmentsToScreenPaths(path.segments, displayList.height, scale), true);
39971
40152
  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;
39972
40153
  fillEdgesScanline4x4(rgba, width, height, edges, path.fillColor, path.fillAlpha ?? 1, path.fillRule ?? "nonzero", clipScreen, original.kind === "glyph" ? aaTxt : aaVec, path.blendMode, clipMask);
39973
40154
  }
39974
40155
  if (path.strokeColor) {
39975
- const edges = segmentsToScreenEdges(path.segments, displayList.height, scale, false);
39976
- const rawSw = path.strokeWidth * scale;
39977
- const sw = Math.max(1, rawSw);
40156
+ const rawSw = path.strokeWidth * scale * (path.strokeMatrix ? Math.hypot(path.strokeMatrix[0], path.strokeMatrix[1]) : 1);
39978
40157
  const strokeAlpha = options.thinLineMode === "shape" && rawSw < 1 ? (path.strokeAlpha ?? 1) * Math.max(0.25, rawSw) : path.strokeAlpha ?? 1;
39979
- const dashArr = path.dashArray && path.dashArray.length > 0 ? path.dashArray.map((d) => Math.max(0, d * scale)) : void 0;
39980
- const dashCycle = dashArr ? dashArr.reduce((a, b) => a + b, 0) : 0;
39981
- let dashDist = (path.dashPhase ?? 0) * scale % (dashCycle || 1);
39982
- if (dashDist < 0) dashDist += dashCycle;
39983
- for (const e of edges) {
39984
- if (!dashArr || dashCycle <= 1e-4) {
39985
- 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);
39986
- } else {
39987
- const dx = e.x1 - e.x0;
39988
- const dy = e.y1 - e.y0;
39989
- const edgeLen = Math.hypot(dx, dy);
39990
- if (edgeLen <= 1e-4) continue;
39991
- let pos = 0;
39992
- while (pos < edgeLen) {
39993
- let cycleRem = dashDist % dashCycle;
39994
- let dIdx = 0;
39995
- while (dIdx < dashArr.length - 1 && cycleRem >= dashArr[dIdx]) {
39996
- cycleRem -= dashArr[dIdx];
39997
- dIdx++;
39998
- }
39999
- const segRemainInDash = Math.max(1e-4, dashArr[dIdx] - cycleRem);
40000
- const step = Math.min(edgeLen - pos, segRemainInDash);
40001
- if (dIdx % 2 === 0) {
40002
- const t0 = pos / edgeLen;
40003
- const t1 = (pos + step) / edgeLen;
40004
- drawAntiAliasedSegment(
40005
- rgba,
40006
- width,
40007
- height,
40008
- e.x0 + dx * t0,
40009
- e.y0 + dy * t0,
40010
- e.x0 + dx * t1,
40011
- e.y0 + dy * t1,
40012
- sw,
40013
- path.strokeColor,
40014
- strokeAlpha,
40015
- path.lineCap ?? 0,
40016
- original.kind === "glyph" ? aaTxt : aaVec,
40017
- path.blendMode,
40018
- clipMask
40019
- );
40020
- }
40021
- pos += step;
40022
- dashDist = (dashDist + step) % dashCycle;
40023
- }
40024
- }
40025
- }
40158
+ const edges = strokeEdges(path, displayList.height, scale);
40159
+ 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;
40160
+ fillEdgesScanline4x4(
40161
+ rgba,
40162
+ width,
40163
+ height,
40164
+ edges,
40165
+ path.strokeColor,
40166
+ strokeAlpha,
40167
+ "nonzero",
40168
+ clipScreen,
40169
+ original.kind === "glyph" ? aaTxt : aaVec,
40170
+ path.blendMode,
40171
+ clipMask
40172
+ );
40026
40173
  }
40027
40174
  } else if (operation.kind === "image") {
40028
40175
  const img = operation.value;
@@ -43317,3 +43464,15 @@ export {
43317
43464
  * Copyright 2012 Mozilla Foundation. Licensed under Apache-2.0.
43318
43465
  * See THIRD_PARTY_NOTICES.md for the source revision and adaptations.
43319
43466
  */
43467
+ /*!
43468
+ * Anti-Grain Geometry - Version 2.3
43469
+ * Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
43470
+ *
43471
+ * Permission to copy, use, modify, sell and distribute this software
43472
+ * is granted provided this copyright notice appears in all copies.
43473
+ * This software is provided "as is" without express or implied
43474
+ * warranty, and with no claim as to its suitability for any purpose.
43475
+ *
43476
+ * Adapted from PDFium agg_math_stroke.h and agg_vcgen_stroke.cpp.
43477
+ * See THIRD_PARTY_NOTICES.md for the source revision and adaptations.
43478
+ */
@@ -11,8 +11,8 @@ import {
11
11
  readImageMetadata,
12
12
  resizeImage,
13
13
  rotateImage
14
- } from "../safe-bash/command-chunks/chunk-S5EX6UP5.js";
15
- import "../safe-bash/command-chunks/chunk-S3G2B4OX.js";
14
+ } from "../safe-bash/command-chunks/chunk-SVL6HYQL.js";
15
+ import "../safe-bash/command-chunks/chunk-KO4PXCNL.js";
16
16
  import {
17
17
  init_buffer
18
18
  } from "../safe-bash/command-chunks/chunk-HX3SHTCE.js";
@@ -31,7 +31,7 @@ import {
31
31
  PdfDocument,
32
32
  decodeFlate,
33
33
  rgb
34
- } from "../safe-bash/command-chunks/chunk-S3G2B4OX.js";
34
+ } from "../safe-bash/command-chunks/chunk-KO4PXCNL.js";
35
35
  import {
36
36
  init_buffer
37
37
  } from "../safe-bash/command-chunks/chunk-HX3SHTCE.js";