@poe-platform/safe-bash 0.1.759 → 0.1.761

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 (38) hide show
  1. package/dist/image-ast/index.browser.js +74 -17
  2. package/dist/image-ast/index.js +74 -17
  3. package/dist/pdf-ast/ast.d.ts +8 -3
  4. package/dist/pdf-ast/index.js +80 -20
  5. package/dist/safe-bash/chunks/{chunk-AYPUGSOV.js → chunk-CRQDMBQA.js} +123 -8
  6. package/dist/safe-bash/command-chunks/{chunk-HVEAK3OS.js → chunk-6VX5ZQL5.js} +2 -2
  7. package/dist/safe-bash/command-chunks/{chunk-7JA44PVV.js → chunk-GR725WRX.js} +1 -1
  8. package/dist/safe-bash/command-chunks/{chunk-BAUGDXLZ.js → chunk-OSMLVM7P.js} +79 -17
  9. package/dist/safe-bash/commands/htmlq/index.d.ts +1 -1
  10. package/dist/safe-bash/commands/htmlq/index.js +4 -1
  11. package/dist/safe-bash/commands/python/index.browser.js +1 -1
  12. package/dist/safe-bash/commands/python/index.d.ts +1 -1
  13. package/dist/safe-bash/commands/python/llm-capability.d.ts +7 -3
  14. package/dist/safe-bash/commands/python/llm-capability.js +149 -10
  15. package/dist/safe-bash/core.browser.js +4 -3
  16. package/dist/safe-bash/shell/runtime.js +1 -1
  17. package/dist/safe-bash-command-ffmpeg/index.js +3125 -3085
  18. package/dist/safe-bash-command-gh/index.js +128 -27
  19. package/dist/safe-bash-command-git/LICENSE +21 -0
  20. package/dist/safe-bash-command-imagemagick/index.js +2 -2
  21. package/dist/safe-bash-command-pandoc/command.js +3 -3
  22. package/dist/safe-bash-command-pandoc/index.js +3 -3
  23. package/dist/safe-bash-command-pdfimages/index.js +74 -17
  24. package/dist/safe-bash-command-pdfinfo/index.js +78 -20
  25. package/dist/safe-bash-command-pdftk/index.js +74 -17
  26. package/dist/safe-bash-command-pdftoppm/index.js +78 -20
  27. package/dist/safe-bash-command-pdftotext/index.js +74 -17
  28. package/dist/safe-bash-command-qpdf/index.js +74 -17
  29. package/dist/safe-bash-command-sips/index.js +2 -2
  30. package/dist/safe-bash-command-soffice/index.js +1 -1
  31. package/dist/safe-bash-command-ssconvert/index.js +74 -17
  32. package/dist/safe-bash-command-wkhtmltopdf/index.js +74 -17
  33. package/dist/safe-bash-io-engine/internal.d.ts +2 -2
  34. package/dist/safe-bash-mcp/index.d.ts +1 -1
  35. package/package.json +2 -2
  36. package/third-party/pdf-ast/THIRD_PARTY_NOTICES.md +30 -0
  37. package/third-party/pdf-ast/licenses/AGG-2.3.txt +7 -0
  38. package/third-party/pdf-ast/licenses/MIT.txt +21 -0
@@ -36453,7 +36453,7 @@ function evaluateContentStreamToDisplayList(params) {
36453
36453
  const [x, y] = transformPoint(st.ctm, seg.x, seg.y);
36454
36454
  transformedSegments.push({ kind: "cubic", x1, y1, x2, y2, x, y });
36455
36455
  } else if (seg.kind === "rect") {
36456
- if (hasRotOrShear) {
36456
+ if (hasRotOrShear || seg.width * st.ctm[0] < 0 || seg.height * st.ctm[3] < 0) {
36457
36457
  const [p0x, p0y] = transformPoint(st.ctm, seg.x, seg.y);
36458
36458
  const [p1x, p1y] = transformPoint(st.ctm, seg.x + seg.width, seg.y);
36459
36459
  const [p2x, p2y] = transformPoint(st.ctm, seg.x + seg.width, seg.y + seg.height);
@@ -36486,7 +36486,12 @@ function evaluateContentStreamToDisplayList(params) {
36486
36486
  transformedSegments.push({ kind: "close" });
36487
36487
  }
36488
36488
  }
36489
- if (node.clip && transformedSegments.length > 0) {
36489
+ const applyClip = () => {
36490
+ if (!node.clip) return;
36491
+ st.clipPaths = [...st.clipPaths ?? [], {
36492
+ segments: transformedSegments,
36493
+ fillRule: node.clip === "W*" ? "evenodd" : "nonzero"
36494
+ }];
36490
36495
  let cMinX = Infinity, cMinY = Infinity, cMaxX = -Infinity, cMaxY = -Infinity;
36491
36496
  for (const s of transformedSegments) {
36492
36497
  if (s.kind === "move" || s.kind === "line") {
@@ -36514,8 +36519,11 @@ function evaluateContentStreamToDisplayList(params) {
36514
36519
  Math.min(st.clipRect[3], cMaxY)
36515
36520
  ] : [cMinX, cMinY, cMaxX, cMaxY];
36516
36521
  }
36522
+ };
36523
+ if (node.paint === "n") {
36524
+ applyClip();
36525
+ break;
36517
36526
  }
36518
- if (node.paint === "n") break;
36519
36527
  const isFill = ["f", "F", "f*", "B", "B*", "b", "b*"].includes(node.paint);
36520
36528
  const isStroke = ["S", "s", "B", "B*", "b", "b*"].includes(node.paint);
36521
36529
  let evaluatedFillPattern = false;
@@ -36648,7 +36656,10 @@ function evaluateContentStreamToDisplayList(params) {
36648
36656
  }
36649
36657
  }
36650
36658
  }
36651
- if (evaluatedFillPattern && !isStroke) break;
36659
+ if (evaluatedFillPattern && !isStroke) {
36660
+ applyClip();
36661
+ break;
36662
+ }
36652
36663
  const fillRule = node.paint.includes("*") ? "evenodd" : "nonzero";
36653
36664
  const ctmScale = Math.max(1e-6, Math.hypot(st.ctm[0], st.ctm[1]));
36654
36665
  const scaledStrokeWidth = st.strokeWidth === 0 ? 0 : st.strokeWidth * ctmScale;
@@ -36668,6 +36679,7 @@ function evaluateContentStreamToDisplayList(params) {
36668
36679
  ...st.dashPhase !== void 0 ? { dashPhase: st.dashPhase } : {},
36669
36680
  ...st.clipRect ? { clipRect: [...st.clipRect] } : {}
36670
36681
  } });
36682
+ applyClip();
36671
36683
  break;
36672
36684
  }
36673
36685
  case "xobject": {
@@ -39202,6 +39214,39 @@ function createTrueTypeFontHandle(truetype) {
39202
39214
  }
39203
39215
  };
39204
39216
  }
39217
+ function flattenCubic(x1, y1, x2, y2, x3, y3, x4, y4) {
39218
+ const points = [[x1, y1]];
39219
+ const subdivide = (ax, ay, bx, by, cx, cy, dx, dy, level) => {
39220
+ if (level > 16) return;
39221
+ const abx = (ax + bx) / 2, aby = (ay + by) / 2;
39222
+ const bcx = (bx + cx) / 2, bcy = (by + cy) / 2;
39223
+ const cdx = (cx + dx) / 2, cdy = (cy + dy) / 2;
39224
+ const abcx = (abx + bcx) / 2, abcy = (aby + bcy) / 2;
39225
+ const bcdx = (bcx + cdx) / 2, bcdy = (bcy + cdy) / 2;
39226
+ const midx = (abcx + bcdx) / 2, midy = (abcy + bcdy) / 2;
39227
+ const chordX = dx - ax, chordY = dy - ay;
39228
+ const d2 = Math.abs((bx - dx) * chordY - (by - dy) * chordX);
39229
+ const d3 = Math.abs((cx - dx) * chordY - (cy - dy) * chordX);
39230
+ const significant2 = d2 > 1e-30, significant3 = d3 > 1e-30;
39231
+ if (!significant2 && !significant3) {
39232
+ if (Math.abs(ax + cx - 2 * bx) + Math.abs(ay + cy - 2 * by) + Math.abs(bx + dx - 2 * cx) + Math.abs(by + dy - 2 * cy) <= 4) {
39233
+ points.push([midx, midy]);
39234
+ return;
39235
+ }
39236
+ } else {
39237
+ const distance = (significant2 ? d2 : 0) + (significant3 ? d3 : 0);
39238
+ if (distance * distance <= 0.25 * (chordX * chordX + chordY * chordY)) {
39239
+ points.push([bcx, bcy]);
39240
+ return;
39241
+ }
39242
+ }
39243
+ subdivide(ax, ay, abx, aby, abcx, abcy, midx, midy, level + 1);
39244
+ subdivide(midx, midy, bcdx, bcdy, cdx, cdy, dx, dy, level + 1);
39245
+ };
39246
+ subdivide(x1, y1, x2, y2, x3, y3, x4, y4, 0);
39247
+ points.push([x4, y4]);
39248
+ return points;
39249
+ }
39205
39250
  function encodePng(bitmap) {
39206
39251
  return encodeRgbaToPng(bitmap.width, bitmap.height, bitmap.data);
39207
39252
  }
@@ -40361,14 +40406,11 @@ function segmentsToScreenEdges(segments, pageHeight, scale, closeSubpaths = fals
40361
40406
  const [p1x, p1y] = toScreen(seg.x1, seg.y1);
40362
40407
  const [p2x, p2y] = toScreen(seg.x2, seg.y2);
40363
40408
  const [p3x, p3y] = toScreen(seg.x, seg.y);
40364
- const steps = 12;
40409
+ const points = flattenCubic(curX, curY, p1x, p1y, p2x, p2y, p3x, p3y);
40365
40410
  let px = curX;
40366
40411
  let py = curY;
40367
- for (let s = 1; s <= steps; s++) {
40368
- const t = s / steps;
40369
- const mt = 1 - t;
40370
- const qx = mt * mt * mt * curX + 3 * mt * mt * t * p1x + 3 * mt * t * t * p2x + t * t * t * p3x;
40371
- const qy = mt * mt * mt * curY + 3 * mt * mt * t * p1y + 3 * mt * t * t * p2y + t * t * t * p3y;
40412
+ for (let i = 1; i < points.length; i++) {
40413
+ const [qx, qy] = points[i];
40372
40414
  edges.push({ x0: px, y0: py, x1: qx, y1: qy });
40373
40415
  px = qx;
40374
40416
  py = qy;
@@ -40387,8 +40429,8 @@ function segmentsToScreenEdges(segments, pageHeight, scale, closeSubpaths = fals
40387
40429
  if (closeSubpaths && hasOpenSubpath && (curX !== startX || curY !== startY)) {
40388
40430
  edges.push({ x0: curX, y0: curY, x1: startX, y1: startY });
40389
40431
  }
40390
- const [rx0, ry0] = toScreen(seg.x, seg.y + seg.height);
40391
- const [rx1, ry1] = toScreen(seg.x + seg.width, seg.y);
40432
+ const [rx0, ry0] = toScreen(seg.x, seg.y);
40433
+ const [rx1, ry1] = toScreen(seg.x + seg.width, seg.y + seg.height);
40392
40434
  edges.push(
40393
40435
  { x0: rx0, y0: ry0, x1: rx1, y1: ry0 },
40394
40436
  { x0: rx1, y0: ry0, x1: rx1, y1: ry1 },
@@ -40531,21 +40573,24 @@ function renderDisplayListToBitmap(displayList, options = {}) {
40531
40573
  }
40532
40574
  const aaVec = options.antialiasVector !== false;
40533
40575
  const aaTxt = options.antialiasText !== false;
40534
- const clipMasks = /* @__PURE__ */ new Map();
40576
+ let cachedClips;
40577
+ let cachedClipMask;
40535
40578
  const imageClipMasks = /* @__PURE__ */ new Map();
40536
40579
  for (const original of paintOperations(displayList)) {
40537
40580
  if (original.kind === "glyph" && (original.value.renderMode === 3 || !original.value.outline && !original.value.unicode.trim())) continue;
40538
40581
  const operation = original.kind === "glyph" ? { kind: "path", value: glyphPaint(original.value) } : original;
40539
40582
  const clips = original.value.clipPaths;
40540
- let clipMask = clips ? clipMasks.get(clips) : void 0;
40583
+ let clipMask = clips && clips === cachedClips ? cachedClipMask : void 0;
40541
40584
  if (clips && !clipMask) {
40542
40585
  clipMask = new Uint8Array(width * height * 4).fill(255);
40543
- for (const segments of clips) {
40586
+ for (const clip of clips) {
40587
+ const { segments, fillRule } = "segments" in clip ? clip : { segments: clip, fillRule: "nonzero" };
40544
40588
  const layer = new Uint8Array(width * height * 4);
40545
- fillEdgesScanline4x4(layer, width, height, segmentsToScreenEdges(segments, displayList.height, scale, true), { r: 1, g: 1, b: 1 });
40589
+ fillEdgesScanline4x4(layer, width, height, segmentsToScreenEdges(segments, displayList.height, scale, true), { r: 1, g: 1, b: 1 }, 1, fillRule);
40546
40590
  for (let i = 3; i < layer.length; i += 4) clipMask[i] = Math.round(clipMask[i] * layer[i] / 255);
40547
40591
  }
40548
- clipMasks.set(clips, clipMask);
40592
+ cachedClips = clips;
40593
+ cachedClipMask = clipMask;
40549
40594
  }
40550
40595
  const imageClips = original.value.clipImages;
40551
40596
  if (imageClips) {
@@ -40739,7 +40784,7 @@ function svgPathData(segments, height) {
40739
40784
  } else if (seg.kind === "cubic") {
40740
40785
  dParts.push(`C ${seg.x1} ${height - seg.y1} ${seg.x2} ${height - seg.y2} ${seg.x} ${height - seg.y}`);
40741
40786
  } else if (seg.kind === "rect") {
40742
- dParts.push(`M ${seg.x} ${height - seg.y - seg.height} h ${seg.width} v ${seg.height} h ${-seg.width} Z`);
40787
+ dParts.push(`M ${seg.x} ${height - seg.y} h ${seg.width} v ${-seg.height} h ${-seg.width} Z`);
40743
40788
  } else if (seg.kind === "close") {
40744
40789
  dParts.push("Z");
40745
40790
  }
@@ -40778,9 +40823,10 @@ function renderDisplayListToSvg(displayList, options = {}) {
40778
40823
  const operation = original.kind === "glyph" ? { kind: "path", value: glyphPaint(original.value) } : original;
40779
40824
  const clips = original.value.clipPaths ?? [];
40780
40825
  const imageClips = original.value.clipImages ?? [];
40781
- for (const segments of clips) {
40826
+ for (const clip of clips) {
40827
+ const { segments, fillRule } = "segments" in clip ? clip : { segments: clip, fillRule: "nonzero" };
40782
40828
  const id = `text-clip-${clipId++}`;
40783
- const path = `<path d="${svgPathData(segments, displayList.height)}"/>`;
40829
+ const path = `<path d="${svgPathData(segments, displayList.height)}" clip-rule="${fillRule}"/>`;
40784
40830
  parts.push(`<defs><clipPath id="${id}" clipPathUnits="userSpaceOnUse">${path}</clipPath></defs><g clip-path="url(#${id})">`);
40785
40831
  }
40786
40832
  for (const image of imageClips) {
@@ -44210,3 +44256,15 @@ export {
44210
44256
  * Copyright 2017 Mozilla Foundation. Licensed under Apache-2.0.
44211
44257
  * See licenses/PDFJS-APACHE-2.0.txt and THIRD_PARTY_NOTICES.md.
44212
44258
  */
44259
+ /*!
44260
+ * Anti-Grain Geometry - Version 2.3
44261
+ * Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
44262
+ *
44263
+ * Permission to copy, use, modify, sell and distribute this software
44264
+ * is granted provided this copyright notice appears in all copies.
44265
+ * This software is provided "as is" without express or implied
44266
+ * warranty, and with no claim as to its suitability for any purpose.
44267
+ *
44268
+ * Adapted from PDFium third_party/agg23/agg_curves.cpp, curve4_div.
44269
+ * See THIRD_PARTY_NOTICES.md for the pinned revision and adaptations.
44270
+ */
@@ -35914,7 +35914,7 @@ function evaluateContentStreamToDisplayList(params) {
35914
35914
  const [x, y] = transformPoint(st.ctm, seg.x, seg.y);
35915
35915
  transformedSegments.push({ kind: "cubic", x1, y1, x2, y2, x, y });
35916
35916
  } else if (seg.kind === "rect") {
35917
- if (hasRotOrShear) {
35917
+ if (hasRotOrShear || seg.width * st.ctm[0] < 0 || seg.height * st.ctm[3] < 0) {
35918
35918
  const [p0x, p0y] = transformPoint(st.ctm, seg.x, seg.y);
35919
35919
  const [p1x, p1y] = transformPoint(st.ctm, seg.x + seg.width, seg.y);
35920
35920
  const [p2x, p2y] = transformPoint(st.ctm, seg.x + seg.width, seg.y + seg.height);
@@ -35947,7 +35947,12 @@ function evaluateContentStreamToDisplayList(params) {
35947
35947
  transformedSegments.push({ kind: "close" });
35948
35948
  }
35949
35949
  }
35950
- if (node.clip && transformedSegments.length > 0) {
35950
+ const applyClip = () => {
35951
+ if (!node.clip) return;
35952
+ st.clipPaths = [...st.clipPaths ?? [], {
35953
+ segments: transformedSegments,
35954
+ fillRule: node.clip === "W*" ? "evenodd" : "nonzero"
35955
+ }];
35951
35956
  let cMinX = Infinity, cMinY = Infinity, cMaxX = -Infinity, cMaxY = -Infinity;
35952
35957
  for (const s of transformedSegments) {
35953
35958
  if (s.kind === "move" || s.kind === "line") {
@@ -35975,8 +35980,11 @@ function evaluateContentStreamToDisplayList(params) {
35975
35980
  Math.min(st.clipRect[3], cMaxY)
35976
35981
  ] : [cMinX, cMinY, cMaxX, cMaxY];
35977
35982
  }
35983
+ };
35984
+ if (node.paint === "n") {
35985
+ applyClip();
35986
+ break;
35978
35987
  }
35979
- if (node.paint === "n") break;
35980
35988
  const isFill = ["f", "F", "f*", "B", "B*", "b", "b*"].includes(node.paint);
35981
35989
  const isStroke = ["S", "s", "B", "B*", "b", "b*"].includes(node.paint);
35982
35990
  let evaluatedFillPattern = false;
@@ -36109,7 +36117,10 @@ function evaluateContentStreamToDisplayList(params) {
36109
36117
  }
36110
36118
  }
36111
36119
  }
36112
- if (evaluatedFillPattern && !isStroke) break;
36120
+ if (evaluatedFillPattern && !isStroke) {
36121
+ applyClip();
36122
+ break;
36123
+ }
36113
36124
  const fillRule = node.paint.includes("*") ? "evenodd" : "nonzero";
36114
36125
  const ctmScale = Math.max(1e-6, Math.hypot(st.ctm[0], st.ctm[1]));
36115
36126
  const scaledStrokeWidth = st.strokeWidth === 0 ? 0 : st.strokeWidth * ctmScale;
@@ -36129,6 +36140,7 @@ function evaluateContentStreamToDisplayList(params) {
36129
36140
  ...st.dashPhase !== void 0 ? { dashPhase: st.dashPhase } : {},
36130
36141
  ...st.clipRect ? { clipRect: [...st.clipRect] } : {}
36131
36142
  } });
36143
+ applyClip();
36132
36144
  break;
36133
36145
  }
36134
36146
  case "xobject": {
@@ -39227,6 +39239,39 @@ function createTrueTypeFontHandle(truetype) {
39227
39239
  }
39228
39240
  };
39229
39241
  }
39242
+ function flattenCubic(x1, y1, x2, y2, x3, y3, x4, y4) {
39243
+ const points = [[x1, y1]];
39244
+ const subdivide = (ax, ay, bx, by, cx, cy, dx, dy, level) => {
39245
+ if (level > 16) return;
39246
+ const abx = (ax + bx) / 2, aby = (ay + by) / 2;
39247
+ const bcx = (bx + cx) / 2, bcy = (by + cy) / 2;
39248
+ const cdx = (cx + dx) / 2, cdy = (cy + dy) / 2;
39249
+ const abcx = (abx + bcx) / 2, abcy = (aby + bcy) / 2;
39250
+ const bcdx = (bcx + cdx) / 2, bcdy = (bcy + cdy) / 2;
39251
+ const midx = (abcx + bcdx) / 2, midy = (abcy + bcdy) / 2;
39252
+ const chordX = dx - ax, chordY = dy - ay;
39253
+ const d2 = Math.abs((bx - dx) * chordY - (by - dy) * chordX);
39254
+ const d3 = Math.abs((cx - dx) * chordY - (cy - dy) * chordX);
39255
+ const significant2 = d2 > 1e-30, significant3 = d3 > 1e-30;
39256
+ if (!significant2 && !significant3) {
39257
+ if (Math.abs(ax + cx - 2 * bx) + Math.abs(ay + cy - 2 * by) + Math.abs(bx + dx - 2 * cx) + Math.abs(by + dy - 2 * cy) <= 4) {
39258
+ points.push([midx, midy]);
39259
+ return;
39260
+ }
39261
+ } else {
39262
+ const distance = (significant2 ? d2 : 0) + (significant3 ? d3 : 0);
39263
+ if (distance * distance <= 0.25 * (chordX * chordX + chordY * chordY)) {
39264
+ points.push([bcx, bcy]);
39265
+ return;
39266
+ }
39267
+ }
39268
+ subdivide(ax, ay, abx, aby, abcx, abcy, midx, midy, level + 1);
39269
+ subdivide(midx, midy, bcdx, bcdy, cdx, cdy, dx, dy, level + 1);
39270
+ };
39271
+ subdivide(x1, y1, x2, y2, x3, y3, x4, y4, 0);
39272
+ points.push([x4, y4]);
39273
+ return points;
39274
+ }
39230
39275
  function decodePng(pngBytes) {
39231
39276
  if (pngBytes.length < 24 || pngBytes[0] !== 137 || pngBytes[1] !== 80 || pngBytes[2] !== 78 || pngBytes[3] !== 71) {
39232
39277
  throw new Error("Invalid PNG signature");
@@ -39990,14 +40035,11 @@ function segmentsToScreenEdges(segments, pageHeight, scale, closeSubpaths = fals
39990
40035
  const [p1x, p1y] = toScreen(seg.x1, seg.y1);
39991
40036
  const [p2x, p2y] = toScreen(seg.x2, seg.y2);
39992
40037
  const [p3x, p3y] = toScreen(seg.x, seg.y);
39993
- const steps = 12;
40038
+ const points = flattenCubic(curX, curY, p1x, p1y, p2x, p2y, p3x, p3y);
39994
40039
  let px = curX;
39995
40040
  let py = curY;
39996
- for (let s = 1; s <= steps; s++) {
39997
- const t = s / steps;
39998
- const mt = 1 - t;
39999
- const qx = mt * mt * mt * curX + 3 * mt * mt * t * p1x + 3 * mt * t * t * p2x + t * t * t * p3x;
40000
- const qy = mt * mt * mt * curY + 3 * mt * mt * t * p1y + 3 * mt * t * t * p2y + t * t * t * p3y;
40041
+ for (let i = 1; i < points.length; i++) {
40042
+ const [qx, qy] = points[i];
40001
40043
  edges.push({ x0: px, y0: py, x1: qx, y1: qy });
40002
40044
  px = qx;
40003
40045
  py = qy;
@@ -40016,8 +40058,8 @@ function segmentsToScreenEdges(segments, pageHeight, scale, closeSubpaths = fals
40016
40058
  if (closeSubpaths && hasOpenSubpath && (curX !== startX || curY !== startY)) {
40017
40059
  edges.push({ x0: curX, y0: curY, x1: startX, y1: startY });
40018
40060
  }
40019
- const [rx0, ry0] = toScreen(seg.x, seg.y + seg.height);
40020
- const [rx1, ry1] = toScreen(seg.x + seg.width, seg.y);
40061
+ const [rx0, ry0] = toScreen(seg.x, seg.y);
40062
+ const [rx1, ry1] = toScreen(seg.x + seg.width, seg.y + seg.height);
40021
40063
  edges.push(
40022
40064
  { x0: rx0, y0: ry0, x1: rx1, y1: ry0 },
40023
40065
  { x0: rx1, y0: ry0, x1: rx1, y1: ry1 },
@@ -40160,21 +40202,24 @@ function renderDisplayListToBitmap(displayList, options = {}) {
40160
40202
  }
40161
40203
  const aaVec = options.antialiasVector !== false;
40162
40204
  const aaTxt = options.antialiasText !== false;
40163
- const clipMasks = /* @__PURE__ */ new Map();
40205
+ let cachedClips;
40206
+ let cachedClipMask;
40164
40207
  const imageClipMasks = /* @__PURE__ */ new Map();
40165
40208
  for (const original of paintOperations(displayList)) {
40166
40209
  if (original.kind === "glyph" && (original.value.renderMode === 3 || !original.value.outline && !original.value.unicode.trim())) continue;
40167
40210
  const operation = original.kind === "glyph" ? { kind: "path", value: glyphPaint(original.value) } : original;
40168
40211
  const clips = original.value.clipPaths;
40169
- let clipMask = clips ? clipMasks.get(clips) : void 0;
40212
+ let clipMask = clips && clips === cachedClips ? cachedClipMask : void 0;
40170
40213
  if (clips && !clipMask) {
40171
40214
  clipMask = new Uint8Array(width * height * 4).fill(255);
40172
- for (const segments of clips) {
40215
+ for (const clip of clips) {
40216
+ const { segments, fillRule } = "segments" in clip ? clip : { segments: clip, fillRule: "nonzero" };
40173
40217
  const layer = new Uint8Array(width * height * 4);
40174
- fillEdgesScanline4x4(layer, width, height, segmentsToScreenEdges(segments, displayList.height, scale, true), { r: 1, g: 1, b: 1 });
40218
+ fillEdgesScanline4x4(layer, width, height, segmentsToScreenEdges(segments, displayList.height, scale, true), { r: 1, g: 1, b: 1 }, 1, fillRule);
40175
40219
  for (let i = 3; i < layer.length; i += 4) clipMask[i] = Math.round(clipMask[i] * layer[i] / 255);
40176
40220
  }
40177
- clipMasks.set(clips, clipMask);
40221
+ cachedClips = clips;
40222
+ cachedClipMask = clipMask;
40178
40223
  }
40179
40224
  const imageClips = original.value.clipImages;
40180
40225
  if (imageClips) {
@@ -42899,3 +42944,15 @@ export {
42899
42944
  * Copyright 2017 Mozilla Foundation. Licensed under Apache-2.0.
42900
42945
  * See licenses/PDFJS-APACHE-2.0.txt and THIRD_PARTY_NOTICES.md.
42901
42946
  */
42947
+ /*!
42948
+ * Anti-Grain Geometry - Version 2.3
42949
+ * Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
42950
+ *
42951
+ * Permission to copy, use, modify, sell and distribute this software
42952
+ * is granted provided this copyright notice appears in all copies.
42953
+ * This software is provided "as is" without express or implied
42954
+ * warranty, and with no claim as to its suitability for any purpose.
42955
+ *
42956
+ * Adapted from PDFium third_party/agg23/agg_curves.cpp, curve4_div.
42957
+ * See THIRD_PARTY_NOTICES.md for the pinned revision and adaptations.
42958
+ */
@@ -36108,7 +36108,7 @@ function evaluateContentStreamToDisplayList(params) {
36108
36108
  const [x, y] = transformPoint(st.ctm, seg.x, seg.y);
36109
36109
  transformedSegments.push({ kind: "cubic", x1, y1, x2, y2, x, y });
36110
36110
  } else if (seg.kind === "rect") {
36111
- if (hasRotOrShear) {
36111
+ if (hasRotOrShear || seg.width * st.ctm[0] < 0 || seg.height * st.ctm[3] < 0) {
36112
36112
  const [p0x, p0y] = transformPoint(st.ctm, seg.x, seg.y);
36113
36113
  const [p1x, p1y] = transformPoint(st.ctm, seg.x + seg.width, seg.y);
36114
36114
  const [p2x, p2y] = transformPoint(st.ctm, seg.x + seg.width, seg.y + seg.height);
@@ -36141,7 +36141,12 @@ function evaluateContentStreamToDisplayList(params) {
36141
36141
  transformedSegments.push({ kind: "close" });
36142
36142
  }
36143
36143
  }
36144
- if (node.clip && transformedSegments.length > 0) {
36144
+ const applyClip = () => {
36145
+ if (!node.clip) return;
36146
+ st.clipPaths = [...st.clipPaths ?? [], {
36147
+ segments: transformedSegments,
36148
+ fillRule: node.clip === "W*" ? "evenodd" : "nonzero"
36149
+ }];
36145
36150
  let cMinX = Infinity, cMinY = Infinity, cMaxX = -Infinity, cMaxY = -Infinity;
36146
36151
  for (const s of transformedSegments) {
36147
36152
  if (s.kind === "move" || s.kind === "line") {
@@ -36169,8 +36174,11 @@ function evaluateContentStreamToDisplayList(params) {
36169
36174
  Math.min(st.clipRect[3], cMaxY)
36170
36175
  ] : [cMinX, cMinY, cMaxX, cMaxY];
36171
36176
  }
36177
+ };
36178
+ if (node.paint === "n") {
36179
+ applyClip();
36180
+ break;
36172
36181
  }
36173
- if (node.paint === "n") break;
36174
36182
  const isFill = ["f", "F", "f*", "B", "B*", "b", "b*"].includes(node.paint);
36175
36183
  const isStroke = ["S", "s", "B", "B*", "b", "b*"].includes(node.paint);
36176
36184
  let evaluatedFillPattern = false;
@@ -36303,7 +36311,10 @@ function evaluateContentStreamToDisplayList(params) {
36303
36311
  }
36304
36312
  }
36305
36313
  }
36306
- if (evaluatedFillPattern && !isStroke) break;
36314
+ if (evaluatedFillPattern && !isStroke) {
36315
+ applyClip();
36316
+ break;
36317
+ }
36307
36318
  const fillRule = node.paint.includes("*") ? "evenodd" : "nonzero";
36308
36319
  const ctmScale = Math.max(1e-6, Math.hypot(st.ctm[0], st.ctm[1]));
36309
36320
  const scaledStrokeWidth = st.strokeWidth === 0 ? 0 : st.strokeWidth * ctmScale;
@@ -36323,6 +36334,7 @@ function evaluateContentStreamToDisplayList(params) {
36323
36334
  ...st.dashPhase !== void 0 ? { dashPhase: st.dashPhase } : {},
36324
36335
  ...st.clipRect ? { clipRect: [...st.clipRect] } : {}
36325
36336
  } });
36337
+ applyClip();
36326
36338
  break;
36327
36339
  }
36328
36340
  case "xobject": {
@@ -38857,6 +38869,39 @@ function createTrueTypeFontHandle(truetype) {
38857
38869
  }
38858
38870
  };
38859
38871
  }
38872
+ function flattenCubic(x1, y1, x2, y2, x3, y3, x4, y4) {
38873
+ const points = [[x1, y1]];
38874
+ const subdivide = (ax, ay, bx, by, cx, cy, dx, dy, level) => {
38875
+ if (level > 16) return;
38876
+ const abx = (ax + bx) / 2, aby = (ay + by) / 2;
38877
+ const bcx = (bx + cx) / 2, bcy = (by + cy) / 2;
38878
+ const cdx = (cx + dx) / 2, cdy = (cy + dy) / 2;
38879
+ const abcx = (abx + bcx) / 2, abcy = (aby + bcy) / 2;
38880
+ const bcdx = (bcx + cdx) / 2, bcdy = (bcy + cdy) / 2;
38881
+ const midx = (abcx + bcdx) / 2, midy = (abcy + bcdy) / 2;
38882
+ const chordX = dx - ax, chordY = dy - ay;
38883
+ const d2 = Math.abs((bx - dx) * chordY - (by - dy) * chordX);
38884
+ const d3 = Math.abs((cx - dx) * chordY - (cy - dy) * chordX);
38885
+ const significant2 = d2 > 1e-30, significant3 = d3 > 1e-30;
38886
+ if (!significant2 && !significant3) {
38887
+ if (Math.abs(ax + cx - 2 * bx) + Math.abs(ay + cy - 2 * by) + Math.abs(bx + dx - 2 * cx) + Math.abs(by + dy - 2 * cy) <= 4) {
38888
+ points.push([midx, midy]);
38889
+ return;
38890
+ }
38891
+ } else {
38892
+ const distance = (significant2 ? d2 : 0) + (significant3 ? d3 : 0);
38893
+ if (distance * distance <= 0.25 * (chordX * chordX + chordY * chordY)) {
38894
+ points.push([bcx, bcy]);
38895
+ return;
38896
+ }
38897
+ }
38898
+ subdivide(ax, ay, abx, aby, abcx, abcy, midx, midy, level + 1);
38899
+ subdivide(midx, midy, bcdx, bcdy, cdx, cdy, dx, dy, level + 1);
38900
+ };
38901
+ subdivide(x1, y1, x2, y2, x3, y3, x4, y4, 0);
38902
+ points.push([x4, y4]);
38903
+ return points;
38904
+ }
38860
38905
  function encodePng(bitmap) {
38861
38906
  return encodeRgbaToPng(bitmap.width, bitmap.height, bitmap.data);
38862
38907
  }
@@ -40016,14 +40061,11 @@ function segmentsToScreenEdges(segments, pageHeight, scale, closeSubpaths = fals
40016
40061
  const [p1x, p1y] = toScreen(seg.x1, seg.y1);
40017
40062
  const [p2x, p2y] = toScreen(seg.x2, seg.y2);
40018
40063
  const [p3x, p3y] = toScreen(seg.x, seg.y);
40019
- const steps = 12;
40064
+ const points = flattenCubic(curX, curY, p1x, p1y, p2x, p2y, p3x, p3y);
40020
40065
  let px = curX;
40021
40066
  let py = curY;
40022
- for (let s = 1; s <= steps; s++) {
40023
- const t = s / steps;
40024
- const mt = 1 - t;
40025
- const qx = mt * mt * mt * curX + 3 * mt * mt * t * p1x + 3 * mt * t * t * p2x + t * t * t * p3x;
40026
- const qy = mt * mt * mt * curY + 3 * mt * mt * t * p1y + 3 * mt * t * t * p2y + t * t * t * p3y;
40067
+ for (let i = 1; i < points.length; i++) {
40068
+ const [qx, qy] = points[i];
40027
40069
  edges.push({ x0: px, y0: py, x1: qx, y1: qy });
40028
40070
  px = qx;
40029
40071
  py = qy;
@@ -40042,8 +40084,8 @@ function segmentsToScreenEdges(segments, pageHeight, scale, closeSubpaths = fals
40042
40084
  if (closeSubpaths && hasOpenSubpath && (curX !== startX || curY !== startY)) {
40043
40085
  edges.push({ x0: curX, y0: curY, x1: startX, y1: startY });
40044
40086
  }
40045
- const [rx0, ry0] = toScreen(seg.x, seg.y + seg.height);
40046
- const [rx1, ry1] = toScreen(seg.x + seg.width, seg.y);
40087
+ const [rx0, ry0] = toScreen(seg.x, seg.y);
40088
+ const [rx1, ry1] = toScreen(seg.x + seg.width, seg.y + seg.height);
40047
40089
  edges.push(
40048
40090
  { x0: rx0, y0: ry0, x1: rx1, y1: ry0 },
40049
40091
  { x0: rx1, y0: ry0, x1: rx1, y1: ry1 },
@@ -40186,21 +40228,24 @@ function renderDisplayListToBitmap(displayList, options = {}) {
40186
40228
  }
40187
40229
  const aaVec = options.antialiasVector !== false;
40188
40230
  const aaTxt = options.antialiasText !== false;
40189
- const clipMasks = /* @__PURE__ */ new Map();
40231
+ let cachedClips;
40232
+ let cachedClipMask;
40190
40233
  const imageClipMasks = /* @__PURE__ */ new Map();
40191
40234
  for (const original of paintOperations(displayList)) {
40192
40235
  if (original.kind === "glyph" && (original.value.renderMode === 3 || !original.value.outline && !original.value.unicode.trim())) continue;
40193
40236
  const operation = original.kind === "glyph" ? { kind: "path", value: glyphPaint(original.value) } : original;
40194
40237
  const clips = original.value.clipPaths;
40195
- let clipMask = clips ? clipMasks.get(clips) : void 0;
40238
+ let clipMask = clips && clips === cachedClips ? cachedClipMask : void 0;
40196
40239
  if (clips && !clipMask) {
40197
40240
  clipMask = new Uint8Array(width * height * 4).fill(255);
40198
- for (const segments of clips) {
40241
+ for (const clip of clips) {
40242
+ const { segments, fillRule } = "segments" in clip ? clip : { segments: clip, fillRule: "nonzero" };
40199
40243
  const layer = new Uint8Array(width * height * 4);
40200
- fillEdgesScanline4x4(layer, width, height, segmentsToScreenEdges(segments, displayList.height, scale, true), { r: 1, g: 1, b: 1 });
40244
+ fillEdgesScanline4x4(layer, width, height, segmentsToScreenEdges(segments, displayList.height, scale, true), { r: 1, g: 1, b: 1 }, 1, fillRule);
40201
40245
  for (let i = 3; i < layer.length; i += 4) clipMask[i] = Math.round(clipMask[i] * layer[i] / 255);
40202
40246
  }
40203
- clipMasks.set(clips, clipMask);
40247
+ cachedClips = clips;
40248
+ cachedClipMask = clipMask;
40204
40249
  }
40205
40250
  const imageClips = original.value.clipImages;
40206
40251
  if (imageClips) {
@@ -40394,7 +40439,7 @@ function svgPathData(segments, height) {
40394
40439
  } else if (seg.kind === "cubic") {
40395
40440
  dParts.push(`C ${seg.x1} ${height - seg.y1} ${seg.x2} ${height - seg.y2} ${seg.x} ${height - seg.y}`);
40396
40441
  } else if (seg.kind === "rect") {
40397
- dParts.push(`M ${seg.x} ${height - seg.y - seg.height} h ${seg.width} v ${seg.height} h ${-seg.width} Z`);
40442
+ dParts.push(`M ${seg.x} ${height - seg.y} h ${seg.width} v ${-seg.height} h ${-seg.width} Z`);
40398
40443
  } else if (seg.kind === "close") {
40399
40444
  dParts.push("Z");
40400
40445
  }
@@ -40433,9 +40478,10 @@ function renderDisplayListToSvg(displayList, options = {}) {
40433
40478
  const operation = original.kind === "glyph" ? { kind: "path", value: glyphPaint(original.value) } : original;
40434
40479
  const clips = original.value.clipPaths ?? [];
40435
40480
  const imageClips = original.value.clipImages ?? [];
40436
- for (const segments of clips) {
40481
+ for (const clip of clips) {
40482
+ const { segments, fillRule } = "segments" in clip ? clip : { segments: clip, fillRule: "nonzero" };
40437
40483
  const id = `text-clip-${clipId++}`;
40438
- const path = `<path d="${svgPathData(segments, displayList.height)}"/>`;
40484
+ const path = `<path d="${svgPathData(segments, displayList.height)}" clip-rule="${fillRule}"/>`;
40439
40485
  parts.push(`<defs><clipPath id="${id}" clipPathUnits="userSpaceOnUse">${path}</clipPath></defs><g clip-path="url(#${id})">`);
40440
40486
  }
40441
40487
  for (const image of imageClips) {
@@ -42080,3 +42126,15 @@ export {
42080
42126
  * Copyright 2017 Mozilla Foundation. Licensed under Apache-2.0.
42081
42127
  * See licenses/PDFJS-APACHE-2.0.txt and THIRD_PARTY_NOTICES.md.
42082
42128
  */
42129
+ /*!
42130
+ * Anti-Grain Geometry - Version 2.3
42131
+ * Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
42132
+ *
42133
+ * Permission to copy, use, modify, sell and distribute this software
42134
+ * is granted provided this copyright notice appears in all copies.
42135
+ * This software is provided "as is" without express or implied
42136
+ * warranty, and with no claim as to its suitability for any purpose.
42137
+ *
42138
+ * Adapted from PDFium third_party/agg23/agg_curves.cpp, curve4_div.
42139
+ * See THIRD_PARTY_NOTICES.md for the pinned revision and adaptations.
42140
+ */