@poe-platform/safe-bash 0.1.758 → 0.1.760
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 +41 -16
- package/dist/image-ast/index.js +41 -16
- package/dist/pdf-ast/ast.d.ts +8 -3
- package/dist/pdf-ast/index.js +45 -19
- package/dist/safe-bash/chunks/{chunk-WNWIBBJZ.js → chunk-CRQDMBQA.js} +130 -9
- package/dist/safe-bash/command-chunks/{chunk-L2C5TIII.js → chunk-MC4XXPQJ.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-TCAGGM44.js → chunk-S3SCPBHC.js} +41 -17
- package/dist/safe-bash/command-chunks/{chunk-XYCWDGOG.js → chunk-UCI6ZQFB.js} +1 -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/commands/python/shell-capability.js +10 -2
- package/dist/safe-bash/core.browser.js +1 -1
- package/dist/safe-bash-command-ffmpeg/index.js +3513 -3500
- package/dist/safe-bash-command-gh/index.js +128 -27
- 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 +41 -16
- package/dist/safe-bash-command-pdfinfo/index.js +45 -19
- package/dist/safe-bash-command-pdftk/index.js +41 -16
- package/dist/safe-bash-command-pdftoppm/index.js +45 -19
- package/dist/safe-bash-command-pdftotext/index.js +41 -16
- package/dist/safe-bash-command-qpdf/index.js +41 -16
- 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 +63 -38
- package/dist/safe-bash-command-wkhtmltopdf/index.js +42 -16
- 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 +22 -0
|
@@ -8654,6 +8654,7 @@ var messages_default2 = {
|
|
|
8654
8654
|
"-5": "buffer error",
|
|
8655
8655
|
"-6": "incompatible version"
|
|
8656
8656
|
};
|
|
8657
|
+
var Z_BUF_ERROR = -5;
|
|
8657
8658
|
var MAX_MEM_LEVEL2 = 9;
|
|
8658
8659
|
var HEAP_SIZE2 = 573;
|
|
8659
8660
|
var MIN_MATCH2 = 3;
|
|
@@ -30545,22 +30546,31 @@ function decodeFlate(bytes, parms, maxDecodedBytes = DEFAULT_MAX_DECODED_BYTES)
|
|
|
30545
30546
|
inflated = new BoundedFlateStream(bytes, maxDecodedBytes).getBytes();
|
|
30546
30547
|
} catch (error) {
|
|
30547
30548
|
if (error instanceof PdfError && error.code === "E_LIMIT") throw error;
|
|
30549
|
+
const wrapped = bytes[0] === 31 && bytes[1] === 139 || bytes.length >= 2 && (bytes[0] & 15) === 8 && bytes[0] >>> 4 <= 7 && (bytes[0] << 8 | bytes[1]) % 31 === 0;
|
|
30548
30550
|
const decoder = new Inflate2({
|
|
30549
|
-
raw: !
|
|
30551
|
+
raw: !wrapped,
|
|
30550
30552
|
chunkSize: Math.max(1, Math.min(64 * 1024, maxDecodedBytes + 1))
|
|
30551
30553
|
});
|
|
30554
|
+
const chunks = [];
|
|
30552
30555
|
let length = 0;
|
|
30553
30556
|
decoder.onData = (chunk) => {
|
|
30554
30557
|
length += chunk.length;
|
|
30555
30558
|
if (length > maxDecodedBytes) {
|
|
30556
30559
|
throw new PdfError("E_LIMIT", "FlateDecode output exceeds maximum decoded byte budget");
|
|
30557
30560
|
}
|
|
30558
|
-
|
|
30561
|
+
chunks.push(chunk);
|
|
30559
30562
|
};
|
|
30560
|
-
|
|
30563
|
+
const complete2 = decoder.push(bytes, true);
|
|
30564
|
+
const truncated = wrapped && decoder.err === Z_BUF_ERROR && length > 0;
|
|
30565
|
+
if ((!complete2 || decoder.err || !decoder.ended) && !truncated) {
|
|
30561
30566
|
throw new PdfError("E_CAPABILITY", "Invalid FlateDecode compressed stream");
|
|
30562
30567
|
}
|
|
30563
|
-
inflated =
|
|
30568
|
+
inflated = new Uint8Array(length);
|
|
30569
|
+
let offset = 0;
|
|
30570
|
+
for (const chunk of chunks) {
|
|
30571
|
+
inflated.set(chunk, offset);
|
|
30572
|
+
offset += chunk.length;
|
|
30573
|
+
}
|
|
30564
30574
|
}
|
|
30565
30575
|
return applyPredictor(inflated, parms);
|
|
30566
30576
|
}
|
|
@@ -42450,7 +42460,7 @@ function resolvePageFonts(doc, resourcesDict) {
|
|
|
42450
42460
|
const glyphNames = buildFontEncodingGlyphNamesMap(encNode);
|
|
42451
42461
|
const widths = /* @__PURE__ */ new Map();
|
|
42452
42462
|
let defaultWidth = 556;
|
|
42453
|
-
const isTwoByteCid = subtype === "Type0"
|
|
42463
|
+
const isTwoByteCid = subtype === "Type0";
|
|
42454
42464
|
let fontMatrix;
|
|
42455
42465
|
let charProcs;
|
|
42456
42466
|
let fontResources;
|
|
@@ -43903,7 +43913,7 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
43903
43913
|
const [x, y] = transformPoint(st.ctm, seg.x, seg.y);
|
|
43904
43914
|
transformedSegments.push({ kind: "cubic", x1, y1, x2, y2, x, y });
|
|
43905
43915
|
} else if (seg.kind === "rect") {
|
|
43906
|
-
if (hasRotOrShear) {
|
|
43916
|
+
if (hasRotOrShear || seg.width * st.ctm[0] < 0 || seg.height * st.ctm[3] < 0) {
|
|
43907
43917
|
const [p0x, p0y] = transformPoint(st.ctm, seg.x, seg.y);
|
|
43908
43918
|
const [p1x, p1y] = transformPoint(st.ctm, seg.x + seg.width, seg.y);
|
|
43909
43919
|
const [p2x, p2y] = transformPoint(st.ctm, seg.x + seg.width, seg.y + seg.height);
|
|
@@ -43936,7 +43946,12 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
43936
43946
|
transformedSegments.push({ kind: "close" });
|
|
43937
43947
|
}
|
|
43938
43948
|
}
|
|
43939
|
-
|
|
43949
|
+
const applyClip = () => {
|
|
43950
|
+
if (!node.clip) return;
|
|
43951
|
+
st.clipPaths = [...st.clipPaths ?? [], {
|
|
43952
|
+
segments: transformedSegments,
|
|
43953
|
+
fillRule: node.clip === "W*" ? "evenodd" : "nonzero"
|
|
43954
|
+
}];
|
|
43940
43955
|
let cMinX = Infinity, cMinY = Infinity, cMaxX = -Infinity, cMaxY = -Infinity;
|
|
43941
43956
|
for (const s of transformedSegments) {
|
|
43942
43957
|
if (s.kind === "move" || s.kind === "line") {
|
|
@@ -43964,8 +43979,11 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
43964
43979
|
Math.min(st.clipRect[3], cMaxY)
|
|
43965
43980
|
] : [cMinX, cMinY, cMaxX, cMaxY];
|
|
43966
43981
|
}
|
|
43982
|
+
};
|
|
43983
|
+
if (node.paint === "n") {
|
|
43984
|
+
applyClip();
|
|
43985
|
+
break;
|
|
43967
43986
|
}
|
|
43968
|
-
if (node.paint === "n") break;
|
|
43969
43987
|
const isFill = ["f", "F", "f*", "B", "B*", "b", "b*"].includes(node.paint);
|
|
43970
43988
|
const isStroke = ["S", "s", "B", "B*", "b", "b*"].includes(node.paint);
|
|
43971
43989
|
let evaluatedFillPattern = false;
|
|
@@ -44098,7 +44116,10 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
44098
44116
|
}
|
|
44099
44117
|
}
|
|
44100
44118
|
}
|
|
44101
|
-
if (evaluatedFillPattern && !isStroke)
|
|
44119
|
+
if (evaluatedFillPattern && !isStroke) {
|
|
44120
|
+
applyClip();
|
|
44121
|
+
break;
|
|
44122
|
+
}
|
|
44102
44123
|
const fillRule = node.paint.includes("*") ? "evenodd" : "nonzero";
|
|
44103
44124
|
const ctmScale = Math.max(1e-6, Math.hypot(st.ctm[0], st.ctm[1]));
|
|
44104
44125
|
const scaledStrokeWidth = st.strokeWidth === 0 ? 0 : st.strokeWidth * ctmScale;
|
|
@@ -44118,6 +44139,7 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
44118
44139
|
...st.dashPhase !== void 0 ? { dashPhase: st.dashPhase } : {},
|
|
44119
44140
|
...st.clipRect ? { clipRect: [...st.clipRect] } : {}
|
|
44120
44141
|
} });
|
|
44142
|
+
applyClip();
|
|
44121
44143
|
break;
|
|
44122
44144
|
}
|
|
44123
44145
|
case "xobject": {
|
|
@@ -47441,8 +47463,8 @@ function segmentsToScreenEdges(segments, pageHeight, scale, closeSubpaths = fals
|
|
|
47441
47463
|
if (closeSubpaths && hasOpenSubpath && (curX !== startX || curY !== startY)) {
|
|
47442
47464
|
edges.push({ x0: curX, y0: curY, x1: startX, y1: startY });
|
|
47443
47465
|
}
|
|
47444
|
-
const [rx0, ry0] = toScreen(seg.x, seg.y
|
|
47445
|
-
const [rx1, ry1] = toScreen(seg.x + seg.width, seg.y);
|
|
47466
|
+
const [rx0, ry0] = toScreen(seg.x, seg.y);
|
|
47467
|
+
const [rx1, ry1] = toScreen(seg.x + seg.width, seg.y + seg.height);
|
|
47446
47468
|
edges.push(
|
|
47447
47469
|
{ x0: rx0, y0: ry0, x1: rx1, y1: ry0 },
|
|
47448
47470
|
{ x0: rx1, y0: ry0, x1: rx1, y1: ry1 },
|
|
@@ -47585,21 +47607,24 @@ function renderDisplayListToBitmap(displayList, options = {}) {
|
|
|
47585
47607
|
}
|
|
47586
47608
|
const aaVec = options.antialiasVector !== false;
|
|
47587
47609
|
const aaTxt = options.antialiasText !== false;
|
|
47588
|
-
|
|
47610
|
+
let cachedClips;
|
|
47611
|
+
let cachedClipMask;
|
|
47589
47612
|
const imageClipMasks = /* @__PURE__ */ new Map();
|
|
47590
47613
|
for (const original of paintOperations(displayList)) {
|
|
47591
47614
|
if (original.kind === "glyph" && (original.value.renderMode === 3 || !original.value.outline && !original.value.unicode.trim())) continue;
|
|
47592
47615
|
const operation = original.kind === "glyph" ? { kind: "path", value: glyphPaint(original.value) } : original;
|
|
47593
47616
|
const clips = original.value.clipPaths;
|
|
47594
|
-
let clipMask = clips
|
|
47617
|
+
let clipMask = clips && clips === cachedClips ? cachedClipMask : void 0;
|
|
47595
47618
|
if (clips && !clipMask) {
|
|
47596
47619
|
clipMask = new Uint8Array(width * height * 4).fill(255);
|
|
47597
|
-
for (const
|
|
47620
|
+
for (const clip of clips) {
|
|
47621
|
+
const { segments, fillRule } = "segments" in clip ? clip : { segments: clip, fillRule: "nonzero" };
|
|
47598
47622
|
const layer = new Uint8Array(width * height * 4);
|
|
47599
|
-
fillEdgesScanline4x4(layer, width, height, segmentsToScreenEdges(segments, displayList.height, scale, true), { r: 1, g: 1, b: 1 });
|
|
47623
|
+
fillEdgesScanline4x4(layer, width, height, segmentsToScreenEdges(segments, displayList.height, scale, true), { r: 1, g: 1, b: 1 }, 1, fillRule);
|
|
47600
47624
|
for (let i = 3; i < layer.length; i += 4) clipMask[i] = Math.round(clipMask[i] * layer[i] / 255);
|
|
47601
47625
|
}
|
|
47602
|
-
|
|
47626
|
+
cachedClips = clips;
|
|
47627
|
+
cachedClipMask = clipMask;
|
|
47603
47628
|
}
|
|
47604
47629
|
const imageClips = original.value.clipImages;
|
|
47605
47630
|
if (imageClips) {
|
package/dist/image-ast/index.js
CHANGED
|
@@ -8654,6 +8654,7 @@ var messages_default2 = {
|
|
|
8654
8654
|
"-5": "buffer error",
|
|
8655
8655
|
"-6": "incompatible version"
|
|
8656
8656
|
};
|
|
8657
|
+
var Z_BUF_ERROR = -5;
|
|
8657
8658
|
var MAX_MEM_LEVEL2 = 9;
|
|
8658
8659
|
var HEAP_SIZE2 = 573;
|
|
8659
8660
|
var MIN_MATCH2 = 3;
|
|
@@ -30545,22 +30546,31 @@ function decodeFlate(bytes, parms, maxDecodedBytes = DEFAULT_MAX_DECODED_BYTES)
|
|
|
30545
30546
|
inflated = new BoundedFlateStream(bytes, maxDecodedBytes).getBytes();
|
|
30546
30547
|
} catch (error) {
|
|
30547
30548
|
if (error instanceof PdfError && error.code === "E_LIMIT") throw error;
|
|
30549
|
+
const wrapped = bytes[0] === 31 && bytes[1] === 139 || bytes.length >= 2 && (bytes[0] & 15) === 8 && bytes[0] >>> 4 <= 7 && (bytes[0] << 8 | bytes[1]) % 31 === 0;
|
|
30548
30550
|
const decoder = new Inflate2({
|
|
30549
|
-
raw: !
|
|
30551
|
+
raw: !wrapped,
|
|
30550
30552
|
chunkSize: Math.max(1, Math.min(64 * 1024, maxDecodedBytes + 1))
|
|
30551
30553
|
});
|
|
30554
|
+
const chunks = [];
|
|
30552
30555
|
let length = 0;
|
|
30553
30556
|
decoder.onData = (chunk) => {
|
|
30554
30557
|
length += chunk.length;
|
|
30555
30558
|
if (length > maxDecodedBytes) {
|
|
30556
30559
|
throw new PdfError("E_LIMIT", "FlateDecode output exceeds maximum decoded byte budget");
|
|
30557
30560
|
}
|
|
30558
|
-
|
|
30561
|
+
chunks.push(chunk);
|
|
30559
30562
|
};
|
|
30560
|
-
|
|
30563
|
+
const complete2 = decoder.push(bytes, true);
|
|
30564
|
+
const truncated = wrapped && decoder.err === Z_BUF_ERROR && length > 0;
|
|
30565
|
+
if ((!complete2 || decoder.err || !decoder.ended) && !truncated) {
|
|
30561
30566
|
throw new PdfError("E_CAPABILITY", "Invalid FlateDecode compressed stream");
|
|
30562
30567
|
}
|
|
30563
|
-
inflated =
|
|
30568
|
+
inflated = new Uint8Array(length);
|
|
30569
|
+
let offset = 0;
|
|
30570
|
+
for (const chunk of chunks) {
|
|
30571
|
+
inflated.set(chunk, offset);
|
|
30572
|
+
offset += chunk.length;
|
|
30573
|
+
}
|
|
30564
30574
|
}
|
|
30565
30575
|
return applyPredictor(inflated, parms);
|
|
30566
30576
|
}
|
|
@@ -42450,7 +42460,7 @@ function resolvePageFonts(doc, resourcesDict) {
|
|
|
42450
42460
|
const glyphNames = buildFontEncodingGlyphNamesMap(encNode);
|
|
42451
42461
|
const widths = /* @__PURE__ */ new Map();
|
|
42452
42462
|
let defaultWidth = 556;
|
|
42453
|
-
const isTwoByteCid = subtype === "Type0"
|
|
42463
|
+
const isTwoByteCid = subtype === "Type0";
|
|
42454
42464
|
let fontMatrix;
|
|
42455
42465
|
let charProcs;
|
|
42456
42466
|
let fontResources;
|
|
@@ -43903,7 +43913,7 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
43903
43913
|
const [x, y] = transformPoint(st.ctm, seg.x, seg.y);
|
|
43904
43914
|
transformedSegments.push({ kind: "cubic", x1, y1, x2, y2, x, y });
|
|
43905
43915
|
} else if (seg.kind === "rect") {
|
|
43906
|
-
if (hasRotOrShear) {
|
|
43916
|
+
if (hasRotOrShear || seg.width * st.ctm[0] < 0 || seg.height * st.ctm[3] < 0) {
|
|
43907
43917
|
const [p0x, p0y] = transformPoint(st.ctm, seg.x, seg.y);
|
|
43908
43918
|
const [p1x, p1y] = transformPoint(st.ctm, seg.x + seg.width, seg.y);
|
|
43909
43919
|
const [p2x, p2y] = transformPoint(st.ctm, seg.x + seg.width, seg.y + seg.height);
|
|
@@ -43936,7 +43946,12 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
43936
43946
|
transformedSegments.push({ kind: "close" });
|
|
43937
43947
|
}
|
|
43938
43948
|
}
|
|
43939
|
-
|
|
43949
|
+
const applyClip = () => {
|
|
43950
|
+
if (!node.clip) return;
|
|
43951
|
+
st.clipPaths = [...st.clipPaths ?? [], {
|
|
43952
|
+
segments: transformedSegments,
|
|
43953
|
+
fillRule: node.clip === "W*" ? "evenodd" : "nonzero"
|
|
43954
|
+
}];
|
|
43940
43955
|
let cMinX = Infinity, cMinY = Infinity, cMaxX = -Infinity, cMaxY = -Infinity;
|
|
43941
43956
|
for (const s of transformedSegments) {
|
|
43942
43957
|
if (s.kind === "move" || s.kind === "line") {
|
|
@@ -43964,8 +43979,11 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
43964
43979
|
Math.min(st.clipRect[3], cMaxY)
|
|
43965
43980
|
] : [cMinX, cMinY, cMaxX, cMaxY];
|
|
43966
43981
|
}
|
|
43982
|
+
};
|
|
43983
|
+
if (node.paint === "n") {
|
|
43984
|
+
applyClip();
|
|
43985
|
+
break;
|
|
43967
43986
|
}
|
|
43968
|
-
if (node.paint === "n") break;
|
|
43969
43987
|
const isFill = ["f", "F", "f*", "B", "B*", "b", "b*"].includes(node.paint);
|
|
43970
43988
|
const isStroke = ["S", "s", "B", "B*", "b", "b*"].includes(node.paint);
|
|
43971
43989
|
let evaluatedFillPattern = false;
|
|
@@ -44098,7 +44116,10 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
44098
44116
|
}
|
|
44099
44117
|
}
|
|
44100
44118
|
}
|
|
44101
|
-
if (evaluatedFillPattern && !isStroke)
|
|
44119
|
+
if (evaluatedFillPattern && !isStroke) {
|
|
44120
|
+
applyClip();
|
|
44121
|
+
break;
|
|
44122
|
+
}
|
|
44102
44123
|
const fillRule = node.paint.includes("*") ? "evenodd" : "nonzero";
|
|
44103
44124
|
const ctmScale = Math.max(1e-6, Math.hypot(st.ctm[0], st.ctm[1]));
|
|
44104
44125
|
const scaledStrokeWidth = st.strokeWidth === 0 ? 0 : st.strokeWidth * ctmScale;
|
|
@@ -44118,6 +44139,7 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
44118
44139
|
...st.dashPhase !== void 0 ? { dashPhase: st.dashPhase } : {},
|
|
44119
44140
|
...st.clipRect ? { clipRect: [...st.clipRect] } : {}
|
|
44120
44141
|
} });
|
|
44142
|
+
applyClip();
|
|
44121
44143
|
break;
|
|
44122
44144
|
}
|
|
44123
44145
|
case "xobject": {
|
|
@@ -47441,8 +47463,8 @@ function segmentsToScreenEdges(segments, pageHeight, scale, closeSubpaths = fals
|
|
|
47441
47463
|
if (closeSubpaths && hasOpenSubpath && (curX !== startX || curY !== startY)) {
|
|
47442
47464
|
edges.push({ x0: curX, y0: curY, x1: startX, y1: startY });
|
|
47443
47465
|
}
|
|
47444
|
-
const [rx0, ry0] = toScreen(seg.x, seg.y
|
|
47445
|
-
const [rx1, ry1] = toScreen(seg.x + seg.width, seg.y);
|
|
47466
|
+
const [rx0, ry0] = toScreen(seg.x, seg.y);
|
|
47467
|
+
const [rx1, ry1] = toScreen(seg.x + seg.width, seg.y + seg.height);
|
|
47446
47468
|
edges.push(
|
|
47447
47469
|
{ x0: rx0, y0: ry0, x1: rx1, y1: ry0 },
|
|
47448
47470
|
{ x0: rx1, y0: ry0, x1: rx1, y1: ry1 },
|
|
@@ -47585,21 +47607,24 @@ function renderDisplayListToBitmap(displayList, options = {}) {
|
|
|
47585
47607
|
}
|
|
47586
47608
|
const aaVec = options.antialiasVector !== false;
|
|
47587
47609
|
const aaTxt = options.antialiasText !== false;
|
|
47588
|
-
|
|
47610
|
+
let cachedClips;
|
|
47611
|
+
let cachedClipMask;
|
|
47589
47612
|
const imageClipMasks = /* @__PURE__ */ new Map();
|
|
47590
47613
|
for (const original of paintOperations(displayList)) {
|
|
47591
47614
|
if (original.kind === "glyph" && (original.value.renderMode === 3 || !original.value.outline && !original.value.unicode.trim())) continue;
|
|
47592
47615
|
const operation = original.kind === "glyph" ? { kind: "path", value: glyphPaint(original.value) } : original;
|
|
47593
47616
|
const clips = original.value.clipPaths;
|
|
47594
|
-
let clipMask = clips
|
|
47617
|
+
let clipMask = clips && clips === cachedClips ? cachedClipMask : void 0;
|
|
47595
47618
|
if (clips && !clipMask) {
|
|
47596
47619
|
clipMask = new Uint8Array(width * height * 4).fill(255);
|
|
47597
|
-
for (const
|
|
47620
|
+
for (const clip of clips) {
|
|
47621
|
+
const { segments, fillRule } = "segments" in clip ? clip : { segments: clip, fillRule: "nonzero" };
|
|
47598
47622
|
const layer = new Uint8Array(width * height * 4);
|
|
47599
|
-
fillEdgesScanline4x4(layer, width, height, segmentsToScreenEdges(segments, displayList.height, scale, true), { r: 1, g: 1, b: 1 });
|
|
47623
|
+
fillEdgesScanline4x4(layer, width, height, segmentsToScreenEdges(segments, displayList.height, scale, true), { r: 1, g: 1, b: 1 }, 1, fillRule);
|
|
47600
47624
|
for (let i = 3; i < layer.length; i += 4) clipMask[i] = Math.round(clipMask[i] * layer[i] / 255);
|
|
47601
47625
|
}
|
|
47602
|
-
|
|
47626
|
+
cachedClips = clips;
|
|
47627
|
+
cachedClipMask = clipMask;
|
|
47603
47628
|
}
|
|
47604
47629
|
const imageClips = original.value.clipImages;
|
|
47605
47630
|
if (imageClips) {
|
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
|
@@ -644,6 +644,7 @@ var messages_default = {
|
|
|
644
644
|
"-5": "buffer error",
|
|
645
645
|
"-6": "incompatible version"
|
|
646
646
|
};
|
|
647
|
+
var Z_BUF_ERROR = -5;
|
|
647
648
|
var MAX_MEM_LEVEL = 9;
|
|
648
649
|
var HEAP_SIZE = 573;
|
|
649
650
|
var MIN_MATCH = 3;
|
|
@@ -22735,22 +22736,31 @@ function decodeFlate(bytes, parms, maxDecodedBytes = DEFAULT_MAX_DECODED_BYTES)
|
|
|
22735
22736
|
inflated = new BoundedFlateStream(bytes, maxDecodedBytes).getBytes();
|
|
22736
22737
|
} catch (error) {
|
|
22737
22738
|
if (error instanceof PdfError && error.code === "E_LIMIT") throw error;
|
|
22739
|
+
const wrapped = bytes[0] === 31 && bytes[1] === 139 || bytes.length >= 2 && (bytes[0] & 15) === 8 && bytes[0] >>> 4 <= 7 && (bytes[0] << 8 | bytes[1]) % 31 === 0;
|
|
22738
22740
|
const decoder = new Inflate({
|
|
22739
|
-
raw: !
|
|
22741
|
+
raw: !wrapped,
|
|
22740
22742
|
chunkSize: Math.max(1, Math.min(64 * 1024, maxDecodedBytes + 1))
|
|
22741
22743
|
});
|
|
22744
|
+
const chunks = [];
|
|
22742
22745
|
let length = 0;
|
|
22743
22746
|
decoder.onData = (chunk) => {
|
|
22744
22747
|
length += chunk.length;
|
|
22745
22748
|
if (length > maxDecodedBytes) {
|
|
22746
22749
|
throw new PdfError("E_LIMIT", "FlateDecode output exceeds maximum decoded byte budget");
|
|
22747
22750
|
}
|
|
22748
|
-
|
|
22751
|
+
chunks.push(chunk);
|
|
22749
22752
|
};
|
|
22750
|
-
|
|
22753
|
+
const complete = decoder.push(bytes, true);
|
|
22754
|
+
const truncated = wrapped && decoder.err === Z_BUF_ERROR && length > 0;
|
|
22755
|
+
if ((!complete || decoder.err || !decoder.ended) && !truncated) {
|
|
22751
22756
|
throw new PdfError("E_CAPABILITY", "Invalid FlateDecode compressed stream");
|
|
22752
22757
|
}
|
|
22753
|
-
inflated =
|
|
22758
|
+
inflated = new Uint8Array(length);
|
|
22759
|
+
let offset = 0;
|
|
22760
|
+
for (const chunk of chunks) {
|
|
22761
|
+
inflated.set(chunk, offset);
|
|
22762
|
+
offset += chunk.length;
|
|
22763
|
+
}
|
|
22754
22764
|
}
|
|
22755
22765
|
return applyPredictor(inflated, parms);
|
|
22756
22766
|
}
|
|
@@ -35164,7 +35174,7 @@ function resolvePageFonts(doc, resourcesDict) {
|
|
|
35164
35174
|
const glyphNames = buildFontEncodingGlyphNamesMap(encNode);
|
|
35165
35175
|
const widths = /* @__PURE__ */ new Map();
|
|
35166
35176
|
let defaultWidth = 556;
|
|
35167
|
-
const isTwoByteCid = subtype === "Type0"
|
|
35177
|
+
const isTwoByteCid = subtype === "Type0";
|
|
35168
35178
|
let fontMatrix;
|
|
35169
35179
|
let charProcs;
|
|
35170
35180
|
let fontResources;
|
|
@@ -36617,7 +36627,7 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
36617
36627
|
const [x, y] = transformPoint(st.ctm, seg.x, seg.y);
|
|
36618
36628
|
transformedSegments.push({ kind: "cubic", x1, y1, x2, y2, x, y });
|
|
36619
36629
|
} else if (seg.kind === "rect") {
|
|
36620
|
-
if (hasRotOrShear) {
|
|
36630
|
+
if (hasRotOrShear || seg.width * st.ctm[0] < 0 || seg.height * st.ctm[3] < 0) {
|
|
36621
36631
|
const [p0x, p0y] = transformPoint(st.ctm, seg.x, seg.y);
|
|
36622
36632
|
const [p1x, p1y] = transformPoint(st.ctm, seg.x + seg.width, seg.y);
|
|
36623
36633
|
const [p2x, p2y] = transformPoint(st.ctm, seg.x + seg.width, seg.y + seg.height);
|
|
@@ -36650,7 +36660,12 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
36650
36660
|
transformedSegments.push({ kind: "close" });
|
|
36651
36661
|
}
|
|
36652
36662
|
}
|
|
36653
|
-
|
|
36663
|
+
const applyClip = () => {
|
|
36664
|
+
if (!node.clip) return;
|
|
36665
|
+
st.clipPaths = [...st.clipPaths ?? [], {
|
|
36666
|
+
segments: transformedSegments,
|
|
36667
|
+
fillRule: node.clip === "W*" ? "evenodd" : "nonzero"
|
|
36668
|
+
}];
|
|
36654
36669
|
let cMinX = Infinity, cMinY = Infinity, cMaxX = -Infinity, cMaxY = -Infinity;
|
|
36655
36670
|
for (const s of transformedSegments) {
|
|
36656
36671
|
if (s.kind === "move" || s.kind === "line") {
|
|
@@ -36678,8 +36693,11 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
36678
36693
|
Math.min(st.clipRect[3], cMaxY)
|
|
36679
36694
|
] : [cMinX, cMinY, cMaxX, cMaxY];
|
|
36680
36695
|
}
|
|
36696
|
+
};
|
|
36697
|
+
if (node.paint === "n") {
|
|
36698
|
+
applyClip();
|
|
36699
|
+
break;
|
|
36681
36700
|
}
|
|
36682
|
-
if (node.paint === "n") break;
|
|
36683
36701
|
const isFill = ["f", "F", "f*", "B", "B*", "b", "b*"].includes(node.paint);
|
|
36684
36702
|
const isStroke = ["S", "s", "B", "B*", "b", "b*"].includes(node.paint);
|
|
36685
36703
|
let evaluatedFillPattern = false;
|
|
@@ -36812,7 +36830,10 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
36812
36830
|
}
|
|
36813
36831
|
}
|
|
36814
36832
|
}
|
|
36815
|
-
if (evaluatedFillPattern && !isStroke)
|
|
36833
|
+
if (evaluatedFillPattern && !isStroke) {
|
|
36834
|
+
applyClip();
|
|
36835
|
+
break;
|
|
36836
|
+
}
|
|
36816
36837
|
const fillRule = node.paint.includes("*") ? "evenodd" : "nonzero";
|
|
36817
36838
|
const ctmScale = Math.max(1e-6, Math.hypot(st.ctm[0], st.ctm[1]));
|
|
36818
36839
|
const scaledStrokeWidth = st.strokeWidth === 0 ? 0 : st.strokeWidth * ctmScale;
|
|
@@ -36832,6 +36853,7 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
36832
36853
|
...st.dashPhase !== void 0 ? { dashPhase: st.dashPhase } : {},
|
|
36833
36854
|
...st.clipRect ? { clipRect: [...st.clipRect] } : {}
|
|
36834
36855
|
} });
|
|
36856
|
+
applyClip();
|
|
36835
36857
|
break;
|
|
36836
36858
|
}
|
|
36837
36859
|
case "xobject": {
|
|
@@ -41242,8 +41264,8 @@ function segmentsToScreenEdges(segments, pageHeight, scale, closeSubpaths = fals
|
|
|
41242
41264
|
if (closeSubpaths && hasOpenSubpath && (curX !== startX || curY !== startY)) {
|
|
41243
41265
|
edges.push({ x0: curX, y0: curY, x1: startX, y1: startY });
|
|
41244
41266
|
}
|
|
41245
|
-
const [rx0, ry0] = toScreen(seg.x, seg.y
|
|
41246
|
-
const [rx1, ry1] = toScreen(seg.x + seg.width, seg.y);
|
|
41267
|
+
const [rx0, ry0] = toScreen(seg.x, seg.y);
|
|
41268
|
+
const [rx1, ry1] = toScreen(seg.x + seg.width, seg.y + seg.height);
|
|
41247
41269
|
edges.push(
|
|
41248
41270
|
{ x0: rx0, y0: ry0, x1: rx1, y1: ry0 },
|
|
41249
41271
|
{ x0: rx1, y0: ry0, x1: rx1, y1: ry1 },
|
|
@@ -41386,21 +41408,24 @@ function renderDisplayListToBitmap(displayList, options = {}) {
|
|
|
41386
41408
|
}
|
|
41387
41409
|
const aaVec = options.antialiasVector !== false;
|
|
41388
41410
|
const aaTxt = options.antialiasText !== false;
|
|
41389
|
-
|
|
41411
|
+
let cachedClips;
|
|
41412
|
+
let cachedClipMask;
|
|
41390
41413
|
const imageClipMasks = /* @__PURE__ */ new Map();
|
|
41391
41414
|
for (const original of paintOperations(displayList)) {
|
|
41392
41415
|
if (original.kind === "glyph" && (original.value.renderMode === 3 || !original.value.outline && !original.value.unicode.trim())) continue;
|
|
41393
41416
|
const operation = original.kind === "glyph" ? { kind: "path", value: glyphPaint(original.value) } : original;
|
|
41394
41417
|
const clips = original.value.clipPaths;
|
|
41395
|
-
let clipMask = clips
|
|
41418
|
+
let clipMask = clips && clips === cachedClips ? cachedClipMask : void 0;
|
|
41396
41419
|
if (clips && !clipMask) {
|
|
41397
41420
|
clipMask = new Uint8Array(width * height * 4).fill(255);
|
|
41398
|
-
for (const
|
|
41421
|
+
for (const clip of clips) {
|
|
41422
|
+
const { segments, fillRule } = "segments" in clip ? clip : { segments: clip, fillRule: "nonzero" };
|
|
41399
41423
|
const layer = new Uint8Array(width * height * 4);
|
|
41400
|
-
fillEdgesScanline4x4(layer, width, height, segmentsToScreenEdges(segments, displayList.height, scale, true), { r: 1, g: 1, b: 1 });
|
|
41424
|
+
fillEdgesScanline4x4(layer, width, height, segmentsToScreenEdges(segments, displayList.height, scale, true), { r: 1, g: 1, b: 1 }, 1, fillRule);
|
|
41401
41425
|
for (let i = 3; i < layer.length; i += 4) clipMask[i] = Math.round(clipMask[i] * layer[i] / 255);
|
|
41402
41426
|
}
|
|
41403
|
-
|
|
41427
|
+
cachedClips = clips;
|
|
41428
|
+
cachedClipMask = clipMask;
|
|
41404
41429
|
}
|
|
41405
41430
|
const imageClips = original.value.clipImages;
|
|
41406
41431
|
if (imageClips) {
|
|
@@ -41594,7 +41619,7 @@ function svgPathData(segments, height) {
|
|
|
41594
41619
|
} else if (seg.kind === "cubic") {
|
|
41595
41620
|
dParts.push(`C ${seg.x1} ${height - seg.y1} ${seg.x2} ${height - seg.y2} ${seg.x} ${height - seg.y}`);
|
|
41596
41621
|
} else if (seg.kind === "rect") {
|
|
41597
|
-
dParts.push(`M ${seg.x} ${height - seg.y
|
|
41622
|
+
dParts.push(`M ${seg.x} ${height - seg.y} h ${seg.width} v ${-seg.height} h ${-seg.width} Z`);
|
|
41598
41623
|
} else if (seg.kind === "close") {
|
|
41599
41624
|
dParts.push("Z");
|
|
41600
41625
|
}
|
|
@@ -41633,9 +41658,10 @@ function renderDisplayListToSvg(displayList, options = {}) {
|
|
|
41633
41658
|
const operation = original.kind === "glyph" ? { kind: "path", value: glyphPaint(original.value) } : original;
|
|
41634
41659
|
const clips = original.value.clipPaths ?? [];
|
|
41635
41660
|
const imageClips = original.value.clipImages ?? [];
|
|
41636
|
-
for (const
|
|
41661
|
+
for (const clip of clips) {
|
|
41662
|
+
const { segments, fillRule } = "segments" in clip ? clip : { segments: clip, fillRule: "nonzero" };
|
|
41637
41663
|
const id = `text-clip-${clipId++}`;
|
|
41638
|
-
const path = `<path d="${svgPathData(segments, displayList.height)}"/>`;
|
|
41664
|
+
const path = `<path d="${svgPathData(segments, displayList.height)}" clip-rule="${fillRule}"/>`;
|
|
41639
41665
|
parts.push(`<defs><clipPath id="${id}" clipPathUnits="userSpaceOnUse">${path}</clipPath></defs><g clip-path="url(#${id})">`);
|
|
41640
41666
|
}
|
|
41641
41667
|
for (const image of imageClips) {
|