@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.
- package/dist/image-ast/index.browser.js +74 -17
- package/dist/image-ast/index.js +74 -17
- package/dist/pdf-ast/ast.d.ts +8 -3
- package/dist/pdf-ast/index.js +80 -20
- package/dist/safe-bash/chunks/{chunk-AYPUGSOV.js → chunk-CRQDMBQA.js} +123 -8
- package/dist/safe-bash/command-chunks/{chunk-HVEAK3OS.js → chunk-6VX5ZQL5.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-7JA44PVV.js → chunk-GR725WRX.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-BAUGDXLZ.js → chunk-OSMLVM7P.js} +79 -17
- package/dist/safe-bash/commands/htmlq/index.d.ts +1 -1
- package/dist/safe-bash/commands/htmlq/index.js +4 -1
- package/dist/safe-bash/commands/python/index.browser.js +1 -1
- package/dist/safe-bash/commands/python/index.d.ts +1 -1
- package/dist/safe-bash/commands/python/llm-capability.d.ts +7 -3
- package/dist/safe-bash/commands/python/llm-capability.js +149 -10
- package/dist/safe-bash/core.browser.js +4 -3
- package/dist/safe-bash/shell/runtime.js +1 -1
- package/dist/safe-bash-command-ffmpeg/index.js +3125 -3085
- package/dist/safe-bash-command-gh/index.js +128 -27
- package/dist/safe-bash-command-git/LICENSE +21 -0
- package/dist/safe-bash-command-imagemagick/index.js +2 -2
- package/dist/safe-bash-command-pandoc/command.js +3 -3
- package/dist/safe-bash-command-pandoc/index.js +3 -3
- package/dist/safe-bash-command-pdfimages/index.js +74 -17
- package/dist/safe-bash-command-pdfinfo/index.js +78 -20
- package/dist/safe-bash-command-pdftk/index.js +74 -17
- package/dist/safe-bash-command-pdftoppm/index.js +78 -20
- package/dist/safe-bash-command-pdftotext/index.js +74 -17
- package/dist/safe-bash-command-qpdf/index.js +74 -17
- package/dist/safe-bash-command-sips/index.js +2 -2
- package/dist/safe-bash-command-soffice/index.js +1 -1
- package/dist/safe-bash-command-ssconvert/index.js +74 -17
- package/dist/safe-bash-command-wkhtmltopdf/index.js +74 -17
- package/dist/safe-bash-io-engine/internal.d.ts +2 -2
- package/dist/safe-bash-mcp/index.d.ts +1 -1
- package/package.json +2 -2
- package/third-party/pdf-ast/THIRD_PARTY_NOTICES.md +30 -0
- package/third-party/pdf-ast/licenses/AGG-2.3.txt +7 -0
- package/third-party/pdf-ast/licenses/MIT.txt +21 -0
|
@@ -43913,7 +43913,7 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
43913
43913
|
const [x, y] = transformPoint(st.ctm, seg.x, seg.y);
|
|
43914
43914
|
transformedSegments.push({ kind: "cubic", x1, y1, x2, y2, x, y });
|
|
43915
43915
|
} else if (seg.kind === "rect") {
|
|
43916
|
-
if (hasRotOrShear) {
|
|
43916
|
+
if (hasRotOrShear || seg.width * st.ctm[0] < 0 || seg.height * st.ctm[3] < 0) {
|
|
43917
43917
|
const [p0x, p0y] = transformPoint(st.ctm, seg.x, seg.y);
|
|
43918
43918
|
const [p1x, p1y] = transformPoint(st.ctm, seg.x + seg.width, seg.y);
|
|
43919
43919
|
const [p2x, p2y] = transformPoint(st.ctm, seg.x + seg.width, seg.y + seg.height);
|
|
@@ -43946,7 +43946,12 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
43946
43946
|
transformedSegments.push({ kind: "close" });
|
|
43947
43947
|
}
|
|
43948
43948
|
}
|
|
43949
|
-
|
|
43949
|
+
const applyClip = () => {
|
|
43950
|
+
if (!node.clip) return;
|
|
43951
|
+
st.clipPaths = [...st.clipPaths ?? [], {
|
|
43952
|
+
segments: transformedSegments,
|
|
43953
|
+
fillRule: node.clip === "W*" ? "evenodd" : "nonzero"
|
|
43954
|
+
}];
|
|
43950
43955
|
let cMinX = Infinity, cMinY = Infinity, cMaxX = -Infinity, cMaxY = -Infinity;
|
|
43951
43956
|
for (const s of transformedSegments) {
|
|
43952
43957
|
if (s.kind === "move" || s.kind === "line") {
|
|
@@ -43974,8 +43979,11 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
43974
43979
|
Math.min(st.clipRect[3], cMaxY)
|
|
43975
43980
|
] : [cMinX, cMinY, cMaxX, cMaxY];
|
|
43976
43981
|
}
|
|
43982
|
+
};
|
|
43983
|
+
if (node.paint === "n") {
|
|
43984
|
+
applyClip();
|
|
43985
|
+
break;
|
|
43977
43986
|
}
|
|
43978
|
-
if (node.paint === "n") break;
|
|
43979
43987
|
const isFill = ["f", "F", "f*", "B", "B*", "b", "b*"].includes(node.paint);
|
|
43980
43988
|
const isStroke = ["S", "s", "B", "B*", "b", "b*"].includes(node.paint);
|
|
43981
43989
|
let evaluatedFillPattern = false;
|
|
@@ -44108,7 +44116,10 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
44108
44116
|
}
|
|
44109
44117
|
}
|
|
44110
44118
|
}
|
|
44111
|
-
if (evaluatedFillPattern && !isStroke)
|
|
44119
|
+
if (evaluatedFillPattern && !isStroke) {
|
|
44120
|
+
applyClip();
|
|
44121
|
+
break;
|
|
44122
|
+
}
|
|
44112
44123
|
const fillRule = node.paint.includes("*") ? "evenodd" : "nonzero";
|
|
44113
44124
|
const ctmScale = Math.max(1e-6, Math.hypot(st.ctm[0], st.ctm[1]));
|
|
44114
44125
|
const scaledStrokeWidth = st.strokeWidth === 0 ? 0 : st.strokeWidth * ctmScale;
|
|
@@ -44128,6 +44139,7 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
44128
44139
|
...st.dashPhase !== void 0 ? { dashPhase: st.dashPhase } : {},
|
|
44129
44140
|
...st.clipRect ? { clipRect: [...st.clipRect] } : {}
|
|
44130
44141
|
} });
|
|
44142
|
+
applyClip();
|
|
44131
44143
|
break;
|
|
44132
44144
|
}
|
|
44133
44145
|
case "xobject": {
|
|
@@ -46662,6 +46674,39 @@ function createTrueTypeFontHandle(truetype) {
|
|
|
46662
46674
|
}
|
|
46663
46675
|
};
|
|
46664
46676
|
}
|
|
46677
|
+
function flattenCubic(x1, y1, x2, y2, x3, y3, x4, y4) {
|
|
46678
|
+
const points = [[x1, y1]];
|
|
46679
|
+
const subdivide = (ax, ay, bx, by, cx, cy, dx, dy, level) => {
|
|
46680
|
+
if (level > 16) return;
|
|
46681
|
+
const abx = (ax + bx) / 2, aby = (ay + by) / 2;
|
|
46682
|
+
const bcx = (bx + cx) / 2, bcy = (by + cy) / 2;
|
|
46683
|
+
const cdx = (cx + dx) / 2, cdy = (cy + dy) / 2;
|
|
46684
|
+
const abcx = (abx + bcx) / 2, abcy = (aby + bcy) / 2;
|
|
46685
|
+
const bcdx = (bcx + cdx) / 2, bcdy = (bcy + cdy) / 2;
|
|
46686
|
+
const midx = (abcx + bcdx) / 2, midy = (abcy + bcdy) / 2;
|
|
46687
|
+
const chordX = dx - ax, chordY = dy - ay;
|
|
46688
|
+
const d2 = Math.abs((bx - dx) * chordY - (by - dy) * chordX);
|
|
46689
|
+
const d3 = Math.abs((cx - dx) * chordY - (cy - dy) * chordX);
|
|
46690
|
+
const significant2 = d2 > 1e-30, significant3 = d3 > 1e-30;
|
|
46691
|
+
if (!significant2 && !significant3) {
|
|
46692
|
+
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) {
|
|
46693
|
+
points.push([midx, midy]);
|
|
46694
|
+
return;
|
|
46695
|
+
}
|
|
46696
|
+
} else {
|
|
46697
|
+
const distance = (significant2 ? d2 : 0) + (significant3 ? d3 : 0);
|
|
46698
|
+
if (distance * distance <= 0.25 * (chordX * chordX + chordY * chordY)) {
|
|
46699
|
+
points.push([bcx, bcy]);
|
|
46700
|
+
return;
|
|
46701
|
+
}
|
|
46702
|
+
}
|
|
46703
|
+
subdivide(ax, ay, abx, aby, abcx, abcy, midx, midy, level + 1);
|
|
46704
|
+
subdivide(midx, midy, bcdx, bcdy, cdx, cdy, dx, dy, level + 1);
|
|
46705
|
+
};
|
|
46706
|
+
subdivide(x1, y1, x2, y2, x3, y3, x4, y4, 0);
|
|
46707
|
+
points.push([x4, y4]);
|
|
46708
|
+
return points;
|
|
46709
|
+
}
|
|
46665
46710
|
function decodePng(pngBytes) {
|
|
46666
46711
|
if (pngBytes.length < 24 || pngBytes[0] !== 137 || pngBytes[1] !== 80 || pngBytes[2] !== 78 || pngBytes[3] !== 71) {
|
|
46667
46712
|
throw new Error("Invalid PNG signature");
|
|
@@ -47425,14 +47470,11 @@ function segmentsToScreenEdges(segments, pageHeight, scale, closeSubpaths = fals
|
|
|
47425
47470
|
const [p1x, p1y] = toScreen(seg.x1, seg.y1);
|
|
47426
47471
|
const [p2x, p2y] = toScreen(seg.x2, seg.y2);
|
|
47427
47472
|
const [p3x, p3y] = toScreen(seg.x, seg.y);
|
|
47428
|
-
const
|
|
47473
|
+
const points = flattenCubic(curX, curY, p1x, p1y, p2x, p2y, p3x, p3y);
|
|
47429
47474
|
let px = curX;
|
|
47430
47475
|
let py = curY;
|
|
47431
|
-
for (let
|
|
47432
|
-
const
|
|
47433
|
-
const mt = 1 - t;
|
|
47434
|
-
const qx = mt * mt * mt * curX + 3 * mt * mt * t * p1x + 3 * mt * t * t * p2x + t * t * t * p3x;
|
|
47435
|
-
const qy = mt * mt * mt * curY + 3 * mt * mt * t * p1y + 3 * mt * t * t * p2y + t * t * t * p3y;
|
|
47476
|
+
for (let i = 1; i < points.length; i++) {
|
|
47477
|
+
const [qx, qy] = points[i];
|
|
47436
47478
|
edges.push({ x0: px, y0: py, x1: qx, y1: qy });
|
|
47437
47479
|
px = qx;
|
|
47438
47480
|
py = qy;
|
|
@@ -47451,8 +47493,8 @@ function segmentsToScreenEdges(segments, pageHeight, scale, closeSubpaths = fals
|
|
|
47451
47493
|
if (closeSubpaths && hasOpenSubpath && (curX !== startX || curY !== startY)) {
|
|
47452
47494
|
edges.push({ x0: curX, y0: curY, x1: startX, y1: startY });
|
|
47453
47495
|
}
|
|
47454
|
-
const [rx0, ry0] = toScreen(seg.x, seg.y
|
|
47455
|
-
const [rx1, ry1] = toScreen(seg.x + seg.width, seg.y);
|
|
47496
|
+
const [rx0, ry0] = toScreen(seg.x, seg.y);
|
|
47497
|
+
const [rx1, ry1] = toScreen(seg.x + seg.width, seg.y + seg.height);
|
|
47456
47498
|
edges.push(
|
|
47457
47499
|
{ x0: rx0, y0: ry0, x1: rx1, y1: ry0 },
|
|
47458
47500
|
{ x0: rx1, y0: ry0, x1: rx1, y1: ry1 },
|
|
@@ -47595,21 +47637,24 @@ function renderDisplayListToBitmap(displayList, options = {}) {
|
|
|
47595
47637
|
}
|
|
47596
47638
|
const aaVec = options.antialiasVector !== false;
|
|
47597
47639
|
const aaTxt = options.antialiasText !== false;
|
|
47598
|
-
|
|
47640
|
+
let cachedClips;
|
|
47641
|
+
let cachedClipMask;
|
|
47599
47642
|
const imageClipMasks = /* @__PURE__ */ new Map();
|
|
47600
47643
|
for (const original of paintOperations(displayList)) {
|
|
47601
47644
|
if (original.kind === "glyph" && (original.value.renderMode === 3 || !original.value.outline && !original.value.unicode.trim())) continue;
|
|
47602
47645
|
const operation = original.kind === "glyph" ? { kind: "path", value: glyphPaint(original.value) } : original;
|
|
47603
47646
|
const clips = original.value.clipPaths;
|
|
47604
|
-
let clipMask = clips
|
|
47647
|
+
let clipMask = clips && clips === cachedClips ? cachedClipMask : void 0;
|
|
47605
47648
|
if (clips && !clipMask) {
|
|
47606
47649
|
clipMask = new Uint8Array(width * height * 4).fill(255);
|
|
47607
|
-
for (const
|
|
47650
|
+
for (const clip of clips) {
|
|
47651
|
+
const { segments, fillRule } = "segments" in clip ? clip : { segments: clip, fillRule: "nonzero" };
|
|
47608
47652
|
const layer = new Uint8Array(width * height * 4);
|
|
47609
|
-
fillEdgesScanline4x4(layer, width, height, segmentsToScreenEdges(segments, displayList.height, scale, true), { r: 1, g: 1, b: 1 });
|
|
47653
|
+
fillEdgesScanline4x4(layer, width, height, segmentsToScreenEdges(segments, displayList.height, scale, true), { r: 1, g: 1, b: 1 }, 1, fillRule);
|
|
47610
47654
|
for (let i = 3; i < layer.length; i += 4) clipMask[i] = Math.round(clipMask[i] * layer[i] / 255);
|
|
47611
47655
|
}
|
|
47612
|
-
|
|
47656
|
+
cachedClips = clips;
|
|
47657
|
+
cachedClipMask = clipMask;
|
|
47613
47658
|
}
|
|
47614
47659
|
const imageClips = original.value.clipImages;
|
|
47615
47660
|
if (imageClips) {
|
|
@@ -62451,3 +62496,15 @@ export {
|
|
|
62451
62496
|
* Copyright 2017 Mozilla Foundation. Licensed under Apache-2.0.
|
|
62452
62497
|
* See licenses/PDFJS-APACHE-2.0.txt and THIRD_PARTY_NOTICES.md.
|
|
62453
62498
|
*/
|
|
62499
|
+
/*!
|
|
62500
|
+
* Anti-Grain Geometry - Version 2.3
|
|
62501
|
+
* Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
|
|
62502
|
+
*
|
|
62503
|
+
* Permission to copy, use, modify, sell and distribute this software
|
|
62504
|
+
* is granted provided this copyright notice appears in all copies.
|
|
62505
|
+
* This software is provided "as is" without express or implied
|
|
62506
|
+
* warranty, and with no claim as to its suitability for any purpose.
|
|
62507
|
+
*
|
|
62508
|
+
* Adapted from PDFium third_party/agg23/agg_curves.cpp, curve4_div.
|
|
62509
|
+
* See THIRD_PARTY_NOTICES.md for the pinned revision and adaptations.
|
|
62510
|
+
*/
|
package/dist/image-ast/index.js
CHANGED
|
@@ -43913,7 +43913,7 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
43913
43913
|
const [x, y] = transformPoint(st.ctm, seg.x, seg.y);
|
|
43914
43914
|
transformedSegments.push({ kind: "cubic", x1, y1, x2, y2, x, y });
|
|
43915
43915
|
} else if (seg.kind === "rect") {
|
|
43916
|
-
if (hasRotOrShear) {
|
|
43916
|
+
if (hasRotOrShear || seg.width * st.ctm[0] < 0 || seg.height * st.ctm[3] < 0) {
|
|
43917
43917
|
const [p0x, p0y] = transformPoint(st.ctm, seg.x, seg.y);
|
|
43918
43918
|
const [p1x, p1y] = transformPoint(st.ctm, seg.x + seg.width, seg.y);
|
|
43919
43919
|
const [p2x, p2y] = transformPoint(st.ctm, seg.x + seg.width, seg.y + seg.height);
|
|
@@ -43946,7 +43946,12 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
43946
43946
|
transformedSegments.push({ kind: "close" });
|
|
43947
43947
|
}
|
|
43948
43948
|
}
|
|
43949
|
-
|
|
43949
|
+
const applyClip = () => {
|
|
43950
|
+
if (!node.clip) return;
|
|
43951
|
+
st.clipPaths = [...st.clipPaths ?? [], {
|
|
43952
|
+
segments: transformedSegments,
|
|
43953
|
+
fillRule: node.clip === "W*" ? "evenodd" : "nonzero"
|
|
43954
|
+
}];
|
|
43950
43955
|
let cMinX = Infinity, cMinY = Infinity, cMaxX = -Infinity, cMaxY = -Infinity;
|
|
43951
43956
|
for (const s of transformedSegments) {
|
|
43952
43957
|
if (s.kind === "move" || s.kind === "line") {
|
|
@@ -43974,8 +43979,11 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
43974
43979
|
Math.min(st.clipRect[3], cMaxY)
|
|
43975
43980
|
] : [cMinX, cMinY, cMaxX, cMaxY];
|
|
43976
43981
|
}
|
|
43982
|
+
};
|
|
43983
|
+
if (node.paint === "n") {
|
|
43984
|
+
applyClip();
|
|
43985
|
+
break;
|
|
43977
43986
|
}
|
|
43978
|
-
if (node.paint === "n") break;
|
|
43979
43987
|
const isFill = ["f", "F", "f*", "B", "B*", "b", "b*"].includes(node.paint);
|
|
43980
43988
|
const isStroke = ["S", "s", "B", "B*", "b", "b*"].includes(node.paint);
|
|
43981
43989
|
let evaluatedFillPattern = false;
|
|
@@ -44108,7 +44116,10 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
44108
44116
|
}
|
|
44109
44117
|
}
|
|
44110
44118
|
}
|
|
44111
|
-
if (evaluatedFillPattern && !isStroke)
|
|
44119
|
+
if (evaluatedFillPattern && !isStroke) {
|
|
44120
|
+
applyClip();
|
|
44121
|
+
break;
|
|
44122
|
+
}
|
|
44112
44123
|
const fillRule = node.paint.includes("*") ? "evenodd" : "nonzero";
|
|
44113
44124
|
const ctmScale = Math.max(1e-6, Math.hypot(st.ctm[0], st.ctm[1]));
|
|
44114
44125
|
const scaledStrokeWidth = st.strokeWidth === 0 ? 0 : st.strokeWidth * ctmScale;
|
|
@@ -44128,6 +44139,7 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
44128
44139
|
...st.dashPhase !== void 0 ? { dashPhase: st.dashPhase } : {},
|
|
44129
44140
|
...st.clipRect ? { clipRect: [...st.clipRect] } : {}
|
|
44130
44141
|
} });
|
|
44142
|
+
applyClip();
|
|
44131
44143
|
break;
|
|
44132
44144
|
}
|
|
44133
44145
|
case "xobject": {
|
|
@@ -46662,6 +46674,39 @@ function createTrueTypeFontHandle(truetype) {
|
|
|
46662
46674
|
}
|
|
46663
46675
|
};
|
|
46664
46676
|
}
|
|
46677
|
+
function flattenCubic(x1, y1, x2, y2, x3, y3, x4, y4) {
|
|
46678
|
+
const points = [[x1, y1]];
|
|
46679
|
+
const subdivide = (ax, ay, bx, by, cx, cy, dx, dy, level) => {
|
|
46680
|
+
if (level > 16) return;
|
|
46681
|
+
const abx = (ax + bx) / 2, aby = (ay + by) / 2;
|
|
46682
|
+
const bcx = (bx + cx) / 2, bcy = (by + cy) / 2;
|
|
46683
|
+
const cdx = (cx + dx) / 2, cdy = (cy + dy) / 2;
|
|
46684
|
+
const abcx = (abx + bcx) / 2, abcy = (aby + bcy) / 2;
|
|
46685
|
+
const bcdx = (bcx + cdx) / 2, bcdy = (bcy + cdy) / 2;
|
|
46686
|
+
const midx = (abcx + bcdx) / 2, midy = (abcy + bcdy) / 2;
|
|
46687
|
+
const chordX = dx - ax, chordY = dy - ay;
|
|
46688
|
+
const d2 = Math.abs((bx - dx) * chordY - (by - dy) * chordX);
|
|
46689
|
+
const d3 = Math.abs((cx - dx) * chordY - (cy - dy) * chordX);
|
|
46690
|
+
const significant2 = d2 > 1e-30, significant3 = d3 > 1e-30;
|
|
46691
|
+
if (!significant2 && !significant3) {
|
|
46692
|
+
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) {
|
|
46693
|
+
points.push([midx, midy]);
|
|
46694
|
+
return;
|
|
46695
|
+
}
|
|
46696
|
+
} else {
|
|
46697
|
+
const distance = (significant2 ? d2 : 0) + (significant3 ? d3 : 0);
|
|
46698
|
+
if (distance * distance <= 0.25 * (chordX * chordX + chordY * chordY)) {
|
|
46699
|
+
points.push([bcx, bcy]);
|
|
46700
|
+
return;
|
|
46701
|
+
}
|
|
46702
|
+
}
|
|
46703
|
+
subdivide(ax, ay, abx, aby, abcx, abcy, midx, midy, level + 1);
|
|
46704
|
+
subdivide(midx, midy, bcdx, bcdy, cdx, cdy, dx, dy, level + 1);
|
|
46705
|
+
};
|
|
46706
|
+
subdivide(x1, y1, x2, y2, x3, y3, x4, y4, 0);
|
|
46707
|
+
points.push([x4, y4]);
|
|
46708
|
+
return points;
|
|
46709
|
+
}
|
|
46665
46710
|
function decodePng(pngBytes) {
|
|
46666
46711
|
if (pngBytes.length < 24 || pngBytes[0] !== 137 || pngBytes[1] !== 80 || pngBytes[2] !== 78 || pngBytes[3] !== 71) {
|
|
46667
46712
|
throw new Error("Invalid PNG signature");
|
|
@@ -47425,14 +47470,11 @@ function segmentsToScreenEdges(segments, pageHeight, scale, closeSubpaths = fals
|
|
|
47425
47470
|
const [p1x, p1y] = toScreen(seg.x1, seg.y1);
|
|
47426
47471
|
const [p2x, p2y] = toScreen(seg.x2, seg.y2);
|
|
47427
47472
|
const [p3x, p3y] = toScreen(seg.x, seg.y);
|
|
47428
|
-
const
|
|
47473
|
+
const points = flattenCubic(curX, curY, p1x, p1y, p2x, p2y, p3x, p3y);
|
|
47429
47474
|
let px = curX;
|
|
47430
47475
|
let py = curY;
|
|
47431
|
-
for (let
|
|
47432
|
-
const
|
|
47433
|
-
const mt = 1 - t;
|
|
47434
|
-
const qx = mt * mt * mt * curX + 3 * mt * mt * t * p1x + 3 * mt * t * t * p2x + t * t * t * p3x;
|
|
47435
|
-
const qy = mt * mt * mt * curY + 3 * mt * mt * t * p1y + 3 * mt * t * t * p2y + t * t * t * p3y;
|
|
47476
|
+
for (let i = 1; i < points.length; i++) {
|
|
47477
|
+
const [qx, qy] = points[i];
|
|
47436
47478
|
edges.push({ x0: px, y0: py, x1: qx, y1: qy });
|
|
47437
47479
|
px = qx;
|
|
47438
47480
|
py = qy;
|
|
@@ -47451,8 +47493,8 @@ function segmentsToScreenEdges(segments, pageHeight, scale, closeSubpaths = fals
|
|
|
47451
47493
|
if (closeSubpaths && hasOpenSubpath && (curX !== startX || curY !== startY)) {
|
|
47452
47494
|
edges.push({ x0: curX, y0: curY, x1: startX, y1: startY });
|
|
47453
47495
|
}
|
|
47454
|
-
const [rx0, ry0] = toScreen(seg.x, seg.y
|
|
47455
|
-
const [rx1, ry1] = toScreen(seg.x + seg.width, seg.y);
|
|
47496
|
+
const [rx0, ry0] = toScreen(seg.x, seg.y);
|
|
47497
|
+
const [rx1, ry1] = toScreen(seg.x + seg.width, seg.y + seg.height);
|
|
47456
47498
|
edges.push(
|
|
47457
47499
|
{ x0: rx0, y0: ry0, x1: rx1, y1: ry0 },
|
|
47458
47500
|
{ x0: rx1, y0: ry0, x1: rx1, y1: ry1 },
|
|
@@ -47595,21 +47637,24 @@ function renderDisplayListToBitmap(displayList, options = {}) {
|
|
|
47595
47637
|
}
|
|
47596
47638
|
const aaVec = options.antialiasVector !== false;
|
|
47597
47639
|
const aaTxt = options.antialiasText !== false;
|
|
47598
|
-
|
|
47640
|
+
let cachedClips;
|
|
47641
|
+
let cachedClipMask;
|
|
47599
47642
|
const imageClipMasks = /* @__PURE__ */ new Map();
|
|
47600
47643
|
for (const original of paintOperations(displayList)) {
|
|
47601
47644
|
if (original.kind === "glyph" && (original.value.renderMode === 3 || !original.value.outline && !original.value.unicode.trim())) continue;
|
|
47602
47645
|
const operation = original.kind === "glyph" ? { kind: "path", value: glyphPaint(original.value) } : original;
|
|
47603
47646
|
const clips = original.value.clipPaths;
|
|
47604
|
-
let clipMask = clips
|
|
47647
|
+
let clipMask = clips && clips === cachedClips ? cachedClipMask : void 0;
|
|
47605
47648
|
if (clips && !clipMask) {
|
|
47606
47649
|
clipMask = new Uint8Array(width * height * 4).fill(255);
|
|
47607
|
-
for (const
|
|
47650
|
+
for (const clip of clips) {
|
|
47651
|
+
const { segments, fillRule } = "segments" in clip ? clip : { segments: clip, fillRule: "nonzero" };
|
|
47608
47652
|
const layer = new Uint8Array(width * height * 4);
|
|
47609
|
-
fillEdgesScanline4x4(layer, width, height, segmentsToScreenEdges(segments, displayList.height, scale, true), { r: 1, g: 1, b: 1 });
|
|
47653
|
+
fillEdgesScanline4x4(layer, width, height, segmentsToScreenEdges(segments, displayList.height, scale, true), { r: 1, g: 1, b: 1 }, 1, fillRule);
|
|
47610
47654
|
for (let i = 3; i < layer.length; i += 4) clipMask[i] = Math.round(clipMask[i] * layer[i] / 255);
|
|
47611
47655
|
}
|
|
47612
|
-
|
|
47656
|
+
cachedClips = clips;
|
|
47657
|
+
cachedClipMask = clipMask;
|
|
47613
47658
|
}
|
|
47614
47659
|
const imageClips = original.value.clipImages;
|
|
47615
47660
|
if (imageClips) {
|
|
@@ -62451,3 +62496,15 @@ export {
|
|
|
62451
62496
|
* Copyright 2017 Mozilla Foundation. Licensed under Apache-2.0.
|
|
62452
62497
|
* See licenses/PDFJS-APACHE-2.0.txt and THIRD_PARTY_NOTICES.md.
|
|
62453
62498
|
*/
|
|
62499
|
+
/*!
|
|
62500
|
+
* Anti-Grain Geometry - Version 2.3
|
|
62501
|
+
* Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
|
|
62502
|
+
*
|
|
62503
|
+
* Permission to copy, use, modify, sell and distribute this software
|
|
62504
|
+
* is granted provided this copyright notice appears in all copies.
|
|
62505
|
+
* This software is provided "as is" without express or implied
|
|
62506
|
+
* warranty, and with no claim as to its suitability for any purpose.
|
|
62507
|
+
*
|
|
62508
|
+
* Adapted from PDFium third_party/agg23/agg_curves.cpp, curve4_div.
|
|
62509
|
+
* See THIRD_PARTY_NOTICES.md for the pinned revision and adaptations.
|
|
62510
|
+
*/
|
package/dist/pdf-ast/ast.d.ts
CHANGED
|
@@ -169,6 +169,11 @@ export type PdfPathSegment = {
|
|
|
169
169
|
} | {
|
|
170
170
|
readonly kind: "close";
|
|
171
171
|
};
|
|
172
|
+
/** A clipping intersection. Bare segment arrays retain nonzero semantics. */
|
|
173
|
+
export type PdfClipPath = readonly PdfPathSegment[] | {
|
|
174
|
+
readonly segments: readonly PdfPathSegment[];
|
|
175
|
+
readonly fillRule: "nonzero" | "evenodd";
|
|
176
|
+
};
|
|
172
177
|
export type PdfContentNode = {
|
|
173
178
|
readonly kind: "graphics-group";
|
|
174
179
|
readonly ops: PdfContentNode[];
|
|
@@ -222,7 +227,7 @@ export interface PdfPlacedGlyph {
|
|
|
222
227
|
readonly mcid?: number | undefined;
|
|
223
228
|
readonly actualText?: string | undefined;
|
|
224
229
|
readonly blendMode?: string | undefined;
|
|
225
|
-
readonly clipPaths?: readonly
|
|
230
|
+
readonly clipPaths?: readonly PdfClipPath[] | undefined;
|
|
226
231
|
readonly clipImages?: readonly PdfEvaluatedImage[] | undefined;
|
|
227
232
|
readonly clipRect?: readonly [number, number, number, number] | undefined;
|
|
228
233
|
}
|
|
@@ -241,7 +246,7 @@ export interface PdfEvaluatedPath {
|
|
|
241
246
|
readonly dashPhase?: number | undefined;
|
|
242
247
|
readonly blendMode?: string | undefined;
|
|
243
248
|
readonly isClip?: boolean | undefined;
|
|
244
|
-
readonly clipPaths?: readonly
|
|
249
|
+
readonly clipPaths?: readonly PdfClipPath[] | undefined;
|
|
245
250
|
readonly clipImages?: readonly PdfEvaluatedImage[] | undefined;
|
|
246
251
|
readonly clipRect?: readonly [number, number, number, number] | undefined;
|
|
247
252
|
}
|
|
@@ -254,7 +259,7 @@ export interface PdfEvaluatedImage {
|
|
|
254
259
|
readonly bitsPerComponent: number;
|
|
255
260
|
readonly decodedRgba?: Uint8Array | undefined;
|
|
256
261
|
readonly blendMode?: string | undefined;
|
|
257
|
-
readonly clipPaths?: readonly
|
|
262
|
+
readonly clipPaths?: readonly PdfClipPath[] | undefined;
|
|
258
263
|
readonly clipImages?: readonly PdfEvaluatedImage[] | undefined;
|
|
259
264
|
readonly clipRect?: readonly [number, number, number, number] | undefined;
|
|
260
265
|
}
|
package/dist/pdf-ast/index.js
CHANGED
|
@@ -36627,7 +36627,7 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
36627
36627
|
const [x, y] = transformPoint(st.ctm, seg.x, seg.y);
|
|
36628
36628
|
transformedSegments.push({ kind: "cubic", x1, y1, x2, y2, x, y });
|
|
36629
36629
|
} else if (seg.kind === "rect") {
|
|
36630
|
-
if (hasRotOrShear) {
|
|
36630
|
+
if (hasRotOrShear || seg.width * st.ctm[0] < 0 || seg.height * st.ctm[3] < 0) {
|
|
36631
36631
|
const [p0x, p0y] = transformPoint(st.ctm, seg.x, seg.y);
|
|
36632
36632
|
const [p1x, p1y] = transformPoint(st.ctm, seg.x + seg.width, seg.y);
|
|
36633
36633
|
const [p2x, p2y] = transformPoint(st.ctm, seg.x + seg.width, seg.y + seg.height);
|
|
@@ -36660,7 +36660,12 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
36660
36660
|
transformedSegments.push({ kind: "close" });
|
|
36661
36661
|
}
|
|
36662
36662
|
}
|
|
36663
|
-
|
|
36663
|
+
const applyClip = () => {
|
|
36664
|
+
if (!node.clip) return;
|
|
36665
|
+
st.clipPaths = [...st.clipPaths ?? [], {
|
|
36666
|
+
segments: transformedSegments,
|
|
36667
|
+
fillRule: node.clip === "W*" ? "evenodd" : "nonzero"
|
|
36668
|
+
}];
|
|
36664
36669
|
let cMinX = Infinity, cMinY = Infinity, cMaxX = -Infinity, cMaxY = -Infinity;
|
|
36665
36670
|
for (const s of transformedSegments) {
|
|
36666
36671
|
if (s.kind === "move" || s.kind === "line") {
|
|
@@ -36688,8 +36693,11 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
36688
36693
|
Math.min(st.clipRect[3], cMaxY)
|
|
36689
36694
|
] : [cMinX, cMinY, cMaxX, cMaxY];
|
|
36690
36695
|
}
|
|
36696
|
+
};
|
|
36697
|
+
if (node.paint === "n") {
|
|
36698
|
+
applyClip();
|
|
36699
|
+
break;
|
|
36691
36700
|
}
|
|
36692
|
-
if (node.paint === "n") break;
|
|
36693
36701
|
const isFill = ["f", "F", "f*", "B", "B*", "b", "b*"].includes(node.paint);
|
|
36694
36702
|
const isStroke = ["S", "s", "B", "B*", "b", "b*"].includes(node.paint);
|
|
36695
36703
|
let evaluatedFillPattern = false;
|
|
@@ -36822,7 +36830,10 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
36822
36830
|
}
|
|
36823
36831
|
}
|
|
36824
36832
|
}
|
|
36825
|
-
if (evaluatedFillPattern && !isStroke)
|
|
36833
|
+
if (evaluatedFillPattern && !isStroke) {
|
|
36834
|
+
applyClip();
|
|
36835
|
+
break;
|
|
36836
|
+
}
|
|
36826
36837
|
const fillRule = node.paint.includes("*") ? "evenodd" : "nonzero";
|
|
36827
36838
|
const ctmScale = Math.max(1e-6, Math.hypot(st.ctm[0], st.ctm[1]));
|
|
36828
36839
|
const scaledStrokeWidth = st.strokeWidth === 0 ? 0 : st.strokeWidth * ctmScale;
|
|
@@ -36842,6 +36853,7 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
36842
36853
|
...st.dashPhase !== void 0 ? { dashPhase: st.dashPhase } : {},
|
|
36843
36854
|
...st.clipRect ? { clipRect: [...st.clipRect] } : {}
|
|
36844
36855
|
} });
|
|
36856
|
+
applyClip();
|
|
36845
36857
|
break;
|
|
36846
36858
|
}
|
|
36847
36859
|
case "xobject": {
|
|
@@ -40066,6 +40078,41 @@ function createTrueTypeFontHandle(truetype) {
|
|
|
40066
40078
|
};
|
|
40067
40079
|
}
|
|
40068
40080
|
|
|
40081
|
+
// src/render/cubic.ts
|
|
40082
|
+
function flattenCubic(x1, y1, x2, y2, x3, y3, x4, y4) {
|
|
40083
|
+
const points = [[x1, y1]];
|
|
40084
|
+
const subdivide = (ax, ay, bx, by, cx, cy, dx, dy, level) => {
|
|
40085
|
+
if (level > 16) return;
|
|
40086
|
+
const abx = (ax + bx) / 2, aby = (ay + by) / 2;
|
|
40087
|
+
const bcx = (bx + cx) / 2, bcy = (by + cy) / 2;
|
|
40088
|
+
const cdx = (cx + dx) / 2, cdy = (cy + dy) / 2;
|
|
40089
|
+
const abcx = (abx + bcx) / 2, abcy = (aby + bcy) / 2;
|
|
40090
|
+
const bcdx = (bcx + cdx) / 2, bcdy = (bcy + cdy) / 2;
|
|
40091
|
+
const midx = (abcx + bcdx) / 2, midy = (abcy + bcdy) / 2;
|
|
40092
|
+
const chordX = dx - ax, chordY = dy - ay;
|
|
40093
|
+
const d2 = Math.abs((bx - dx) * chordY - (by - dy) * chordX);
|
|
40094
|
+
const d3 = Math.abs((cx - dx) * chordY - (cy - dy) * chordX);
|
|
40095
|
+
const significant2 = d2 > 1e-30, significant3 = d3 > 1e-30;
|
|
40096
|
+
if (!significant2 && !significant3) {
|
|
40097
|
+
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) {
|
|
40098
|
+
points.push([midx, midy]);
|
|
40099
|
+
return;
|
|
40100
|
+
}
|
|
40101
|
+
} else {
|
|
40102
|
+
const distance = (significant2 ? d2 : 0) + (significant3 ? d3 : 0);
|
|
40103
|
+
if (distance * distance <= 0.25 * (chordX * chordX + chordY * chordY)) {
|
|
40104
|
+
points.push([bcx, bcy]);
|
|
40105
|
+
return;
|
|
40106
|
+
}
|
|
40107
|
+
}
|
|
40108
|
+
subdivide(ax, ay, abx, aby, abcx, abcy, midx, midy, level + 1);
|
|
40109
|
+
subdivide(midx, midy, bcdx, bcdy, cdx, cdy, dx, dy, level + 1);
|
|
40110
|
+
};
|
|
40111
|
+
subdivide(x1, y1, x2, y2, x3, y3, x4, y4, 0);
|
|
40112
|
+
points.push([x4, y4]);
|
|
40113
|
+
return points;
|
|
40114
|
+
}
|
|
40115
|
+
|
|
40069
40116
|
// src/render/raster.ts
|
|
40070
40117
|
function encodePng(bitmap) {
|
|
40071
40118
|
return encodeRgbaToPng(bitmap.width, bitmap.height, bitmap.data);
|
|
@@ -41226,14 +41273,11 @@ function segmentsToScreenEdges(segments, pageHeight, scale, closeSubpaths = fals
|
|
|
41226
41273
|
const [p1x, p1y] = toScreen(seg.x1, seg.y1);
|
|
41227
41274
|
const [p2x, p2y] = toScreen(seg.x2, seg.y2);
|
|
41228
41275
|
const [p3x, p3y] = toScreen(seg.x, seg.y);
|
|
41229
|
-
const
|
|
41276
|
+
const points = flattenCubic(curX, curY, p1x, p1y, p2x, p2y, p3x, p3y);
|
|
41230
41277
|
let px = curX;
|
|
41231
41278
|
let py = curY;
|
|
41232
|
-
for (let
|
|
41233
|
-
const
|
|
41234
|
-
const mt = 1 - t;
|
|
41235
|
-
const qx = mt * mt * mt * curX + 3 * mt * mt * t * p1x + 3 * mt * t * t * p2x + t * t * t * p3x;
|
|
41236
|
-
const qy = mt * mt * mt * curY + 3 * mt * mt * t * p1y + 3 * mt * t * t * p2y + t * t * t * p3y;
|
|
41279
|
+
for (let i = 1; i < points.length; i++) {
|
|
41280
|
+
const [qx, qy] = points[i];
|
|
41237
41281
|
edges.push({ x0: px, y0: py, x1: qx, y1: qy });
|
|
41238
41282
|
px = qx;
|
|
41239
41283
|
py = qy;
|
|
@@ -41252,8 +41296,8 @@ function segmentsToScreenEdges(segments, pageHeight, scale, closeSubpaths = fals
|
|
|
41252
41296
|
if (closeSubpaths && hasOpenSubpath && (curX !== startX || curY !== startY)) {
|
|
41253
41297
|
edges.push({ x0: curX, y0: curY, x1: startX, y1: startY });
|
|
41254
41298
|
}
|
|
41255
|
-
const [rx0, ry0] = toScreen(seg.x, seg.y
|
|
41256
|
-
const [rx1, ry1] = toScreen(seg.x + seg.width, seg.y);
|
|
41299
|
+
const [rx0, ry0] = toScreen(seg.x, seg.y);
|
|
41300
|
+
const [rx1, ry1] = toScreen(seg.x + seg.width, seg.y + seg.height);
|
|
41257
41301
|
edges.push(
|
|
41258
41302
|
{ x0: rx0, y0: ry0, x1: rx1, y1: ry0 },
|
|
41259
41303
|
{ x0: rx1, y0: ry0, x1: rx1, y1: ry1 },
|
|
@@ -41396,21 +41440,24 @@ function renderDisplayListToBitmap(displayList, options = {}) {
|
|
|
41396
41440
|
}
|
|
41397
41441
|
const aaVec = options.antialiasVector !== false;
|
|
41398
41442
|
const aaTxt = options.antialiasText !== false;
|
|
41399
|
-
|
|
41443
|
+
let cachedClips;
|
|
41444
|
+
let cachedClipMask;
|
|
41400
41445
|
const imageClipMasks = /* @__PURE__ */ new Map();
|
|
41401
41446
|
for (const original of paintOperations(displayList)) {
|
|
41402
41447
|
if (original.kind === "glyph" && (original.value.renderMode === 3 || !original.value.outline && !original.value.unicode.trim())) continue;
|
|
41403
41448
|
const operation = original.kind === "glyph" ? { kind: "path", value: glyphPaint(original.value) } : original;
|
|
41404
41449
|
const clips = original.value.clipPaths;
|
|
41405
|
-
let clipMask = clips
|
|
41450
|
+
let clipMask = clips && clips === cachedClips ? cachedClipMask : void 0;
|
|
41406
41451
|
if (clips && !clipMask) {
|
|
41407
41452
|
clipMask = new Uint8Array(width * height * 4).fill(255);
|
|
41408
|
-
for (const
|
|
41453
|
+
for (const clip of clips) {
|
|
41454
|
+
const { segments, fillRule } = "segments" in clip ? clip : { segments: clip, fillRule: "nonzero" };
|
|
41409
41455
|
const layer = new Uint8Array(width * height * 4);
|
|
41410
|
-
fillEdgesScanline4x4(layer, width, height, segmentsToScreenEdges(segments, displayList.height, scale, true), { r: 1, g: 1, b: 1 });
|
|
41456
|
+
fillEdgesScanline4x4(layer, width, height, segmentsToScreenEdges(segments, displayList.height, scale, true), { r: 1, g: 1, b: 1 }, 1, fillRule);
|
|
41411
41457
|
for (let i = 3; i < layer.length; i += 4) clipMask[i] = Math.round(clipMask[i] * layer[i] / 255);
|
|
41412
41458
|
}
|
|
41413
|
-
|
|
41459
|
+
cachedClips = clips;
|
|
41460
|
+
cachedClipMask = clipMask;
|
|
41414
41461
|
}
|
|
41415
41462
|
const imageClips = original.value.clipImages;
|
|
41416
41463
|
if (imageClips) {
|
|
@@ -41604,7 +41651,7 @@ function svgPathData(segments, height) {
|
|
|
41604
41651
|
} else if (seg.kind === "cubic") {
|
|
41605
41652
|
dParts.push(`C ${seg.x1} ${height - seg.y1} ${seg.x2} ${height - seg.y2} ${seg.x} ${height - seg.y}`);
|
|
41606
41653
|
} else if (seg.kind === "rect") {
|
|
41607
|
-
dParts.push(`M ${seg.x} ${height - seg.y
|
|
41654
|
+
dParts.push(`M ${seg.x} ${height - seg.y} h ${seg.width} v ${-seg.height} h ${-seg.width} Z`);
|
|
41608
41655
|
} else if (seg.kind === "close") {
|
|
41609
41656
|
dParts.push("Z");
|
|
41610
41657
|
}
|
|
@@ -41643,9 +41690,10 @@ function renderDisplayListToSvg(displayList, options = {}) {
|
|
|
41643
41690
|
const operation = original.kind === "glyph" ? { kind: "path", value: glyphPaint(original.value) } : original;
|
|
41644
41691
|
const clips = original.value.clipPaths ?? [];
|
|
41645
41692
|
const imageClips = original.value.clipImages ?? [];
|
|
41646
|
-
for (const
|
|
41693
|
+
for (const clip of clips) {
|
|
41694
|
+
const { segments, fillRule } = "segments" in clip ? clip : { segments: clip, fillRule: "nonzero" };
|
|
41647
41695
|
const id = `text-clip-${clipId++}`;
|
|
41648
|
-
const path = `<path d="${svgPathData(segments, displayList.height)}"/>`;
|
|
41696
|
+
const path = `<path d="${svgPathData(segments, displayList.height)}" clip-rule="${fillRule}"/>`;
|
|
41649
41697
|
parts.push(`<defs><clipPath id="${id}" clipPathUnits="userSpaceOnUse">${path}</clipPath></defs><g clip-path="url(#${id})">`);
|
|
41650
41698
|
}
|
|
41651
41699
|
for (const image of imageClips) {
|
|
@@ -42622,3 +42670,15 @@ export {
|
|
|
42622
42670
|
* Copyright 2017 Mozilla Foundation. Licensed under Apache-2.0.
|
|
42623
42671
|
* See licenses/PDFJS-APACHE-2.0.txt and THIRD_PARTY_NOTICES.md.
|
|
42624
42672
|
*/
|
|
42673
|
+
/*!
|
|
42674
|
+
* Anti-Grain Geometry - Version 2.3
|
|
42675
|
+
* Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
|
|
42676
|
+
*
|
|
42677
|
+
* Permission to copy, use, modify, sell and distribute this software
|
|
42678
|
+
* is granted provided this copyright notice appears in all copies.
|
|
42679
|
+
* This software is provided "as is" without express or implied
|
|
42680
|
+
* warranty, and with no claim as to its suitability for any purpose.
|
|
42681
|
+
*
|
|
42682
|
+
* Adapted from PDFium third_party/agg23/agg_curves.cpp, curve4_div.
|
|
42683
|
+
* See THIRD_PARTY_NOTICES.md for the pinned revision and adaptations.
|
|
42684
|
+
*/
|