@poe-platform/safe-bash 0.1.757 → 0.1.759

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 (59) hide show
  1. package/dist/image-ast/index.browser.js +87 -24
  2. package/dist/image-ast/index.js +87 -24
  3. package/dist/pdf-ast/ast.d.ts +3 -0
  4. package/dist/pdf-ast/index.js +103 -41
  5. package/dist/safe-bash/chunks/{chunk-WNWIBBJZ.js → chunk-AYPUGSOV.js} +7 -1
  6. package/dist/safe-bash/command-chunks/{chunk-F3J5ZLKF.js → chunk-522TDVLS.js} +1 -1
  7. package/dist/safe-bash/command-chunks/{chunk-VFS2MDAB.js → chunk-6YLD37NH.js} +2 -2
  8. package/dist/safe-bash/command-chunks/{chunk-YI3GKJ7Q.js → chunk-766IWMTB.js} +2 -2
  9. package/dist/safe-bash/command-chunks/{chunk-WI35236J.js → chunk-7JA44PVV.js} +1 -1
  10. package/dist/safe-bash/command-chunks/{chunk-H2FQA4OU.js → chunk-BAUGDXLZ.js} +87 -25
  11. package/dist/safe-bash/command-chunks/{chunk-KSH2F6RG.js → chunk-CUFCNL6G.js} +1 -1
  12. package/dist/safe-bash/command-chunks/{chunk-KBBI4CSU.js → chunk-HVEAK3OS.js} +2 -2
  13. package/dist/safe-bash/command-chunks/{chunk-S4MLIYSN.js → chunk-J2NPH7DO.js} +4 -0
  14. package/dist/safe-bash/command-chunks/{chunk-4F6PG2OT.js → chunk-YJWWRCIG.js} +8 -8
  15. package/dist/safe-bash/commands/python/index.browser.js +1 -1
  16. package/dist/safe-bash/commands/python/shell-capability.js +10 -2
  17. package/dist/safe-bash/core.browser.js +1 -1
  18. package/dist/safe-bash-command-column/column.js +3 -3
  19. package/dist/safe-bash-command-column/index.js +3 -3
  20. package/dist/safe-bash-command-column/layout.js +2 -2
  21. package/dist/safe-bash-command-factor/command.js +2 -2
  22. package/dist/safe-bash-command-factor/index.js +2 -2
  23. package/dist/safe-bash-command-ffmpeg/index.js +6300 -6265
  24. package/dist/safe-bash-command-imagemagick/index.js +2 -2
  25. package/dist/safe-bash-command-pandoc/command.js +3 -3
  26. package/dist/safe-bash-command-pandoc/index.js +3 -3
  27. package/dist/safe-bash-command-pdfimages/index.js +87 -24
  28. package/dist/safe-bash-command-pdfinfo/index.js +103 -41
  29. package/dist/safe-bash-command-pdftk/index.js +87 -24
  30. package/dist/safe-bash-command-pdftoppm/index.js +103 -41
  31. package/dist/safe-bash-command-pdftotext/index.js +87 -24
  32. package/dist/safe-bash-command-qpdf/index.js +87 -24
  33. package/dist/safe-bash-command-sips/index.js +2 -2
  34. package/dist/safe-bash-command-soffice/index.js +2 -2
  35. package/dist/safe-bash-command-ssconvert/command-bindings.d.ts +18 -0
  36. package/dist/safe-bash-command-ssconvert/command.d.ts +5 -14
  37. package/dist/safe-bash-command-ssconvert/commands.d.ts +6 -0
  38. package/dist/safe-bash-command-ssconvert/commands.js +871 -0
  39. package/dist/safe-bash-command-ssconvert/core.js +1 -1
  40. package/dist/safe-bash-command-ssconvert/index.js +306 -236
  41. package/dist/safe-bash-command-wkhtmltopdf/index.js +88 -24
  42. package/dist/safe-bash-command-yq/index.js +4 -4
  43. package/dist/safe-bash-compression-engine/files.js +2 -2
  44. package/dist/safe-bash-compression-engine/operand.js +4 -4
  45. package/dist/safe-bash-markdown-engine/commonmark-blocks.js +4 -4
  46. package/dist/safe-bash-markdown-engine/commonmark-inlines.js +4 -4
  47. package/dist/safe-bash-markdown-engine/commonmark-syntax.js +2 -2
  48. package/dist/safe-bash-markdown-engine/gfm-syntax.js +3 -3
  49. package/dist/safe-bash-markdown-engine/index.js +7 -7
  50. package/dist/safe-bash-query-engine/index.js +5 -5
  51. package/dist/safe-bash-query-engine/interpreter.js +4 -4
  52. package/dist/safe-bash-query-engine/query-core.js +5 -5
  53. package/package.json +6 -2
  54. package/third-party/pdf-ast/THIRD_PARTY_NOTICES.md +30 -0
  55. package/dist/safe-bash/command-chunks/{chunk-OQVIJMBY.js → chunk-7HINP7ZK.js} +4 -4
  56. package/dist/safe-bash/command-chunks/{chunk-XAYEDOV5.js → chunk-CG4JSOK2.js} +3 -3
  57. package/dist/safe-bash/command-chunks/{chunk-YIK4ZYQ4.js → chunk-DC52GWRK.js} +9 -9
  58. package/dist/safe-bash/command-chunks/{chunk-TOTZFBDT.js → chunk-TKACIO4X.js} +4 -4
  59. package/dist/safe-bash/command-chunks/{chunk-VTWKS4RM.js → chunk-WF2LSKMI.js} +3 -3
@@ -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: !(bytes[0] === 31 && bytes[1] === 139),
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
- decoder.chunks.push(chunk);
22751
+ chunks.push(chunk);
22749
22752
  };
22750
- if (!decoder.push(bytes, true) || decoder.err || !decoder.ended) {
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 = decoder.result;
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
  }
@@ -25603,7 +25613,7 @@ var ParsedCosDocument = class {
25603
25613
  return void 0;
25604
25614
  }
25605
25615
  };
25606
- function parseNodeFromLexer(lexer, bytes, maxDepth, recoverEmptyObject = false) {
25616
+ function parseNodeFromLexer(lexer, bytes, maxDepth, repair = false) {
25607
25617
  const stack = [];
25608
25618
  while (true) {
25609
25619
  const tok = lexer.nextToken();
@@ -25612,7 +25622,7 @@ function parseNodeFromLexer(lexer, bytes, maxDepth, recoverEmptyObject = false)
25612
25622
  if (!parent) return void 0;
25613
25623
  throw new PdfError("E_PARSE", parent.kind === "array" ? "Unterminated PDF array" : "Unterminated PDF dictionary");
25614
25624
  }
25615
- if (!parent && recoverEmptyObject && tok.kind === "keyword" && tok.value === "endobj") {
25625
+ if (!parent && repair && tok.kind === "keyword" && tok.value === "endobj") {
25616
25626
  return { kind: "null", span: tok.span };
25617
25627
  }
25618
25628
  let node;
@@ -25627,6 +25637,7 @@ function parseNodeFromLexer(lexer, bytes, maxDepth, recoverEmptyObject = false)
25627
25637
  parent.key = { kind: "name", rawBytes: tok.rawBytes, decoded: tok.decoded, span: tok.span };
25628
25638
  continue;
25629
25639
  } else {
25640
+ if (repair) continue;
25630
25641
  throw new PdfError("E_PARSE", `Expected dictionary key /Name, got ${tok.kind}`);
25631
25642
  }
25632
25643
  } else {
@@ -25795,7 +25806,7 @@ function parseHeaderVersion(bytes) {
25795
25806
  }
25796
25807
  return head.slice(idx + 5, idx + 8);
25797
25808
  }
25798
- function parseObjectAtOffset(bytes, offset, maxRecursionDepth, recoverEmptyObject = false) {
25809
+ function parseObjectAtOffset(bytes, offset, maxRecursionDepth, repair = false) {
25799
25810
  const lexer = new CosByteLexer(bytes, offset);
25800
25811
  const objNumTok = lexer.nextToken();
25801
25812
  const genNumTok = lexer.nextToken();
@@ -25803,7 +25814,7 @@ function parseObjectAtOffset(bytes, offset, maxRecursionDepth, recoverEmptyObjec
25803
25814
  if (objNumTok?.kind !== "number" || genNumTok?.kind !== "number" || objKwTok?.kind !== "keyword" || objKwTok.value !== "obj") {
25804
25815
  throw new PdfError("E_PARSE", `Malformed indirect object header at byte offset ${offset}`);
25805
25816
  }
25806
- const value = parseNodeFromLexer(lexer, bytes, maxRecursionDepth, recoverEmptyObject);
25817
+ const value = parseNodeFromLexer(lexer, bytes, maxRecursionDepth, repair);
25807
25818
  if (!value) {
25808
25819
  throw new PdfError("E_PARSE", `Empty indirect object ${objNumTok.value} at offset ${offset}`);
25809
25820
  }
@@ -25992,7 +26003,7 @@ function repairScanCosDocument(bytes, maxObjects, maxRecursionDepth) {
25992
26003
  try {
25993
26004
  const token = lexer.nextToken();
25994
26005
  if (token?.kind === "keyword" && token.value === "trailer") {
25995
- const trailer = parseNodeFromLexer(lexer, bytes, maxRecursionDepth);
26006
+ const trailer = parseNodeFromLexer(lexer, bytes, maxRecursionDepth, true);
25996
26007
  if (trailer?.kind === "dict") trailers.push(trailer);
25997
26008
  pos = lexer.offset;
25998
26009
  continue;
@@ -26048,7 +26059,7 @@ function unpackRecoveredObjects(objects, maxObjects, maxDecompressedBytes, maxRe
26048
26059
  const t = dictGet(obj.value.dict, "Type");
26049
26060
  if (t?.kind === "name" && t.decoded === "ObjStm") {
26050
26061
  try {
26051
- for (const [unpackedNum, unpackedVal] of unpackObjectStream(obj.value, maxDecompressedBytes, maxRecursionDepth).entries()) {
26062
+ for (const [unpackedNum, unpackedVal] of unpackObjectStream(obj.value, maxDecompressedBytes, maxRecursionDepth, true).entries()) {
26052
26063
  if (!objects.has(unpackedNum)) {
26053
26064
  objects.set(unpackedNum, {
26054
26065
  objectNumber: unpackedNum,
@@ -26084,7 +26095,7 @@ function recoveredReferences(objects) {
26084
26095
  }
26085
26096
  return { ...rootRef ? { rootRef } : {}, ...infoRef ? { infoRef } : {} };
26086
26097
  }
26087
- function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth) {
26098
+ function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth, repair = false) {
26088
26099
  const nNode = dictGet(streamObj.dict, "N");
26089
26100
  const firstNode = dictGet(streamObj.dict, "First");
26090
26101
  if (nNode?.kind !== "number" || firstNode?.kind !== "number") {
@@ -26104,7 +26115,7 @@ function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth)
26104
26115
  for (const pair of pairs) {
26105
26116
  try {
26106
26117
  const valLexer = new CosByteLexer(decoded, firstNode.value + pair.relativeOffset);
26107
- const node = parseNodeFromLexer(valLexer, decoded, maxRecursionDepth);
26118
+ const node = parseNodeFromLexer(valLexer, decoded, maxRecursionDepth, repair);
26108
26119
  if (node) {
26109
26120
  result.set(pair.objectNumber, node);
26110
26121
  }
@@ -26287,7 +26298,7 @@ function parseCosDocument(bytes, options = {}) {
26287
26298
  if (!unpacked) {
26288
26299
  const stmObj = objects.get(entry.objectStreamNumber)?.value;
26289
26300
  if (stmObj?.kind === "stream") {
26290
- unpacked = unpackObjectStream(stmObj, maxDecompressedBytes, maxRecursionDepth);
26301
+ unpacked = unpackObjectStream(stmObj, maxDecompressedBytes, maxRecursionDepth, recovery === "repair");
26291
26302
  objStmCache.set(entry.objectStreamNumber, unpacked);
26292
26303
  }
26293
26304
  }
@@ -35143,7 +35154,11 @@ function resolvePageFonts(doc, resourcesDict) {
35143
35154
  let cmap;
35144
35155
  const toUniNode = doc.resolve(dictGet(fObj, "ToUnicode"));
35145
35156
  if (toUniNode?.kind === "stream") {
35146
- cmap = parseToUnicodeCMap(doc.decodeStream(toUniNode));
35157
+ try {
35158
+ cmap = parseToUnicodeCMap(doc.decodeStream(toUniNode));
35159
+ } catch (error) {
35160
+ if (error instanceof PdfError && error.code === "E_LIMIT") throw error;
35161
+ }
35147
35162
  }
35148
35163
  const encNode = doc.resolve(dictGet(fObj, "Encoding"));
35149
35164
  if (encNode?.kind === "dict") {
@@ -35159,7 +35174,7 @@ function resolvePageFonts(doc, resourcesDict) {
35159
35174
  const glyphNames = buildFontEncodingGlyphNamesMap(encNode);
35160
35175
  const widths = /* @__PURE__ */ new Map();
35161
35176
  let defaultWidth = 556;
35162
- const isTwoByteCid = subtype === "Type0" || Boolean(cmap?.isTwoByte);
35177
+ const isTwoByteCid = subtype === "Type0";
35163
35178
  let fontMatrix;
35164
35179
  let charProcs;
35165
35180
  let fontResources;
@@ -36267,8 +36282,12 @@ function evaluateContentStreamToDisplayList(params) {
36267
36282
  const images = [];
36268
36283
  const operations = [];
36269
36284
  const emit = (operation) => {
36270
- const clipPaths = curState().clipPaths;
36271
- if (clipPaths) operation = { ...operation, value: { ...operation.value, clipPaths } };
36285
+ const { clipPaths, clipImages } = curState();
36286
+ if (clipPaths || clipImages) operation = { ...operation, value: {
36287
+ ...operation.value,
36288
+ ...clipPaths ? { clipPaths } : {},
36289
+ ...clipImages ? { clipImages } : {}
36290
+ } };
36272
36291
  operations.push(operation);
36273
36292
  switch (operation.kind) {
36274
36293
  case "path":
@@ -36532,6 +36551,18 @@ function evaluateContentStreamToDisplayList(params) {
36532
36551
  let hasTextClip = false;
36533
36552
  let activeTm = [1, 0, 0, 1, 0, 0];
36534
36553
  let activeTlm = [1, 0, 0, 1, 0, 0];
36554
+ const paintImage = (image, patternMask, resources, activeFonts, depth) => {
36555
+ if (!patternMask) {
36556
+ emit({ kind: "image", value: image });
36557
+ return;
36558
+ }
36559
+ const st = curState();
36560
+ stateStack.push({ ...st, clipImages: [...st.clipImages ?? [], image] });
36561
+ walkNodes([{ kind: "path-op", paint: "f", segments: [
36562
+ { kind: "rect", x: 0, y: 0, width: 1, height: 1 }
36563
+ ] }], void 0, void 0, resources, activeFonts, depth);
36564
+ stateStack.pop();
36565
+ };
36535
36566
  const walkNodes = (nodes, mcid, actualText, activeResources = params.resourcesDict, activeFonts = fonts, depth = 0) => {
36536
36567
  for (const node of nodes) {
36537
36568
  switch (node.kind) {
@@ -36715,7 +36746,8 @@ function evaluateContentStreamToDisplayList(params) {
36715
36746
  st.fillAlpha,
36716
36747
  "PatternShading_" + st.fillPatternName,
36717
36748
  patClip,
36718
- shading?.kind === "stream" ? shading : void 0
36749
+ shading?.kind === "stream" ? shading : void 0,
36750
+ st.blendMode
36719
36751
  );
36720
36752
  if (shImg) {
36721
36753
  emit({ kind: "image", value: shImg });
@@ -36824,18 +36856,20 @@ function evaluateContentStreamToDisplayList(params) {
36824
36856
  const subNode = params.cosDoc.resolve(dictGet(xobjNode.dict, "Subtype"));
36825
36857
  const sub = subNode?.kind === "name" ? subNode.decoded : "";
36826
36858
  if (sub === "Image") {
36859
+ const maskNode = params.cosDoc.resolve(dictGet(xobjNode.dict, "ImageMask"));
36860
+ const patternMask = !!st.fillPatternName && maskNode?.kind === "boolean" && maskNode.value;
36827
36861
  const decoded = decodeXObjectImageToRgba(
36828
36862
  params.cosDoc,
36829
36863
  xobjNode,
36830
36864
  activeResources,
36831
- {
36865
+ patternMask ? { r: 1, g: 1, b: 1, alpha: 1 } : {
36832
36866
  r: st.fillColor.r,
36833
36867
  g: st.fillColor.g,
36834
36868
  b: st.fillColor.b,
36835
36869
  alpha: st.fillAlpha
36836
36870
  }
36837
36871
  );
36838
- emit({ kind: "image", value: {
36872
+ paintImage({
36839
36873
  name: node.name,
36840
36874
  matrix: [...st.ctm],
36841
36875
  width: decoded.width,
@@ -36845,7 +36879,7 @@ function evaluateContentStreamToDisplayList(params) {
36845
36879
  decodedRgba: decoded.rgba,
36846
36880
  ...st.blendMode && st.blendMode !== "Normal" ? { blendMode: st.blendMode } : {},
36847
36881
  ...st.clipRect ? { clipRect: [...st.clipRect] } : {}
36848
- } });
36882
+ }, patternMask, activeResources, activeFonts, depth);
36849
36883
  } else if (sub === "Form" && depth < 8) {
36850
36884
  const formStreamBytes = params.cosDoc.decodeStream(xobjNode);
36851
36885
  const formNodes = parseContentStream(formStreamBytes);
@@ -36901,19 +36935,22 @@ function evaluateContentStreamToDisplayList(params) {
36901
36935
  }
36902
36936
  case "inline-image": {
36903
36937
  const st = curState();
36938
+ const maskEntry = dictGet(node.dict, "ImageMask") ?? dictGet(node.dict, "IM");
36939
+ const maskNode = params.cosDoc ? params.cosDoc.resolve(maskEntry) : maskEntry;
36940
+ const patternMask = !!st.fillPatternName && maskNode?.kind === "boolean" && maskNode.value;
36904
36941
  const decoded = decodeInlineImageNodeToRgba(
36905
36942
  params.cosDoc,
36906
36943
  node.dict,
36907
36944
  node.data,
36908
36945
  activeResources,
36909
- {
36946
+ patternMask ? { r: 1, g: 1, b: 1, alpha: 1 } : {
36910
36947
  r: st.fillColor.r,
36911
36948
  g: st.fillColor.g,
36912
36949
  b: st.fillColor.b,
36913
36950
  alpha: st.fillAlpha
36914
36951
  }
36915
36952
  );
36916
- emit({ kind: "image", value: {
36953
+ paintImage({
36917
36954
  name: "InlineImage",
36918
36955
  matrix: [...st.ctm],
36919
36956
  width: decoded.width,
@@ -36923,7 +36960,7 @@ function evaluateContentStreamToDisplayList(params) {
36923
36960
  decodedRgba: decoded.rgba,
36924
36961
  ...st.blendMode && st.blendMode !== "Normal" ? { blendMode: st.blendMode } : {},
36925
36962
  ...st.clipRect ? { clipRect: [...st.clipRect] } : {}
36926
- } });
36963
+ }, patternMask, activeResources, activeFonts, depth);
36927
36964
  break;
36928
36965
  }
36929
36966
  case "text-object": {
@@ -41360,6 +41397,7 @@ function renderDisplayListToBitmap(displayList, options = {}) {
41360
41397
  const aaVec = options.antialiasVector !== false;
41361
41398
  const aaTxt = options.antialiasText !== false;
41362
41399
  const clipMasks = /* @__PURE__ */ new Map();
41400
+ const imageClipMasks = /* @__PURE__ */ new Map();
41363
41401
  for (const original of paintOperations(displayList)) {
41364
41402
  if (original.kind === "glyph" && (original.value.renderMode === 3 || !original.value.outline && !original.value.unicode.trim())) continue;
41365
41403
  const operation = original.kind === "glyph" ? { kind: "path", value: glyphPaint(original.value) } : original;
@@ -41374,6 +41412,31 @@ function renderDisplayListToBitmap(displayList, options = {}) {
41374
41412
  }
41375
41413
  clipMasks.set(clips, clipMask);
41376
41414
  }
41415
+ const imageClips = original.value.clipImages;
41416
+ if (imageClips) {
41417
+ let imageMask = imageClipMasks.get(imageClips);
41418
+ if (!imageMask) {
41419
+ imageMask = new Uint8Array(width * height * 4).fill(255);
41420
+ for (const image of imageClips) {
41421
+ const layer = renderDisplayListToBitmap({
41422
+ ...displayList,
41423
+ rotation: 0,
41424
+ paths: [],
41425
+ glyphs: [],
41426
+ images: [image],
41427
+ operations: [{ kind: "image", value: image }]
41428
+ }, { scale, transparent: true }).data;
41429
+ for (let i = 3; i < layer.length; i += 4) imageMask[i] = Math.round(imageMask[i] * layer[i] / 255);
41430
+ }
41431
+ imageClipMasks.set(imageClips, imageMask);
41432
+ }
41433
+ if (clipMask) {
41434
+ clipMask = clipMask.slice();
41435
+ for (let i = 3; i < clipMask.length; i += 4) clipMask[i] = Math.round(clipMask[i] * imageMask[i] / 255);
41436
+ } else {
41437
+ clipMask = imageMask;
41438
+ }
41439
+ }
41377
41440
  if (operation.kind === "path") {
41378
41441
  const path = operation.value;
41379
41442
  if (path.fillColor) {
@@ -41522,6 +41585,15 @@ function escapeXmlText(str) {
41522
41585
  }
41523
41586
  return encodeToXmlString(valid);
41524
41587
  }
41588
+ function svgImage(image, pageHeight) {
41589
+ if (!image.decodedRgba) return "";
41590
+ const png = encodeRgbaToPng(image.width, image.height, image.decodedRgba);
41591
+ const chunks = [];
41592
+ for (let offset = 0; offset < png.length; offset += 8192)
41593
+ chunks.push(String.fromCharCode(...png.subarray(offset, offset + 8192)));
41594
+ const [a, b, c, d, e, f] = image.matrix;
41595
+ return `<image width="1" height="1" preserveAspectRatio="none" transform="matrix(${a} ${-b} ${-c} ${d} ${e + c} ${pageHeight - f - d})" href="data:image/png;base64,${btoa(chunks.join(""))}"/>`;
41596
+ }
41525
41597
  function svgPathData(segments, height) {
41526
41598
  const dParts = [];
41527
41599
  for (const seg of segments) {
@@ -41570,11 +41642,16 @@ function renderDisplayListToSvg(displayList, options = {}) {
41570
41642
  if (original.kind === "glyph" && (original.value.renderMode === 3 || !original.value.outline && !original.value.unicode.trim())) continue;
41571
41643
  const operation = original.kind === "glyph" ? { kind: "path", value: glyphPaint(original.value) } : original;
41572
41644
  const clips = original.value.clipPaths ?? [];
41645
+ const imageClips = original.value.clipImages ?? [];
41573
41646
  for (const segments of clips) {
41574
41647
  const id = `text-clip-${clipId++}`;
41575
41648
  const path = `<path d="${svgPathData(segments, displayList.height)}"/>`;
41576
41649
  parts.push(`<defs><clipPath id="${id}" clipPathUnits="userSpaceOnUse">${path}</clipPath></defs><g clip-path="url(#${id})">`);
41577
41650
  }
41651
+ for (const image of imageClips) {
41652
+ const id = `image-clip-${clipId++}`;
41653
+ parts.push(`<defs><mask id="${id}" maskUnits="userSpaceOnUse" x="0" y="0" width="${displayList.width}" height="${displayList.height}" style="mask-type:alpha">${svgImage(image, displayList.height)}</mask></defs><g mask="url(#${id})">`);
41654
+ }
41578
41655
  if (operation.kind === "path") {
41579
41656
  const p = operation.value;
41580
41657
  const pathData = svgPathData(p.segments, displayList.height);
@@ -41594,24 +41671,9 @@ function renderDisplayListToSvg(displayList, options = {}) {
41594
41671
  parts.push(` <path${labelAttr} d="${pathData}" fill="${fill}"${fillRuleAttr}${fillOpacityAttr} stroke="${stroke}"${strokeOpacityAttr}${strokeWidthAttr}${lineCapAttr}${lineJoinAttr}${miterLimitAttr}${dashArrayAttr}${dashOffsetAttr}/>`);
41595
41672
  }
41596
41673
  } else if (operation.kind === "image") {
41597
- const img = operation.value;
41598
- if (!img.decodedRgba) {
41599
- for (let i = 0; i < clips.length; i++) parts.push("</g>");
41600
- continue;
41601
- }
41602
- const pngBytes = encodeRgbaToPng(img.width, img.height, img.decodedRgba);
41603
- const chunks = [];
41604
- for (let offset = 0; offset < pngBytes.length; offset += 8192)
41605
- chunks.push(String.fromCharCode(...pngBytes.subarray(offset, offset + 8192)));
41606
- const b64 = btoa(chunks.join(""));
41607
- const [a, b, c, d, e, f] = img.matrix;
41608
- const svgTx = e + c;
41609
- const svgTy = displayList.height - f - d;
41610
- parts.push(
41611
- ` <image width="1" height="1" preserveAspectRatio="none" transform="matrix(${a} ${-b} ${-c} ${d} ${svgTx} ${svgTy})" href="data:image/png;base64,${b64}"/>`
41612
- );
41674
+ parts.push(` ${svgImage(operation.value, displayList.height)}`);
41613
41675
  }
41614
- for (let i = 0; i < clips.length; i++) parts.push("</g>");
41676
+ for (let i = 0; i < clips.length + imageClips.length; i++) parts.push("</g>");
41615
41677
  }
41616
41678
  if (displayList.rotation) parts.push("</g>");
41617
41679
  parts.push("</svg>\n");
@@ -1626,9 +1626,14 @@ function createPythonShellCapability(context, options = {}) {
1626
1626
  const stdout = [];
1627
1627
  const stderr = [];
1628
1628
  let captured = 0;
1629
+ let outputFailure;
1629
1630
  const sink = (target, type) => ({ async write(chunk) {
1630
1631
  childSignal.throwIfAborted();
1631
- if (chunk.length > outputLimit - captured) throw new RangeError("Python shell output limit exceeded");
1632
+ if (outputFailure) throw outputFailure;
1633
+ if (chunk.length > outputLimit - captured) {
1634
+ outputFailure = new RangeError("Python shell output limit exceeded");
1635
+ throw outputFailure;
1636
+ }
1632
1637
  captured += chunk.length;
1633
1638
  if (publish) {
1634
1639
  for (let offset = 0; offset < chunk.length; offset += chunkBytes) {
@@ -1652,6 +1657,7 @@ function createPythonShellCapability(context, options = {}) {
1652
1657
  externalInvocation: true
1653
1658
  });
1654
1659
  childSignal.throwIfAborted();
1660
+ if (outputFailure) throw outputFailure;
1655
1661
  return { stdout, stderr, exitCode: result.exitCode };
1656
1662
  } catch (error) {
1657
1663
  if (!publish && !signal.aborted && childSignal.aborted && childSignal.reason?.name === "TimeoutError") {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  digit,
3
3
  letter
4
- } from "./chunk-VTWKS4RM.js";
4
+ } from "./chunk-WF2LSKMI.js";
5
5
  import {
6
6
  unicodeWhitespace
7
7
  } from "./chunk-UI6H6YG4.js";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  pipeRow
3
- } from "./chunk-F3J5ZLKF.js";
3
+ } from "./chunk-522TDVLS.js";
4
4
  import {
5
5
  normalizeLabel
6
- } from "./chunk-VTWKS4RM.js";
6
+ } from "./chunk-WF2LSKMI.js";
7
7
  import {
8
8
  init_buffer
9
9
  } from "./chunk-HX3SHTCE.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  bareAutolink,
3
3
  filterGfmHtml
4
- } from "./chunk-F3J5ZLKF.js";
4
+ } from "./chunk-522TDVLS.js";
5
5
  import {
6
6
  asciiPunctuation,
7
7
  decodeSyntax,
@@ -14,7 +14,7 @@ import {
14
14
  readLabel,
15
15
  readTitle,
16
16
  whitespace
17
- } from "./chunk-VTWKS4RM.js";
17
+ } from "./chunk-WF2LSKMI.js";
18
18
  import {
19
19
  unicodePunctuation,
20
20
  unicodeWhitespace
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  PdfDocument,
3
3
  renderPdfPageToPng
4
- } from "./chunk-H2FQA4OU.js";
4
+ } from "./chunk-BAUGDXLZ.js";
5
5
  import {
6
6
  init_buffer
7
7
  } from "./chunk-HX3SHTCE.js";