@poe-platform/safe-bash 0.1.756 → 0.1.758

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 (161) hide show
  1. package/dist/image-ast/index.browser.js +76 -23
  2. package/dist/image-ast/index.js +76 -23
  3. package/dist/pdf-ast/ast.d.ts +3 -0
  4. package/dist/pdf-ast/index.js +88 -36
  5. package/dist/safe-bash/chunks/{chunk-LESPJ3OG.js → chunk-WNWIBBJZ.js} +15 -2
  6. package/dist/safe-bash/command-chunks/{chunk-S4J6MSLY.js → chunk-444OTXM7.js} +3 -3
  7. package/dist/safe-bash/command-chunks/{chunk-F3J5ZLKF.js → chunk-522TDVLS.js} +1 -1
  8. package/dist/safe-bash/command-chunks/{chunk-VFS2MDAB.js → chunk-6YLD37NH.js} +2 -2
  9. package/dist/safe-bash/command-chunks/{chunk-YI3GKJ7Q.js → chunk-766IWMTB.js} +2 -2
  10. package/dist/safe-bash/command-chunks/{chunk-6AIOGLZO.js → chunk-CE6Z2ULX.js} +2 -2
  11. package/dist/safe-bash/command-chunks/{chunk-KSH2F6RG.js → chunk-CUFCNL6G.js} +1 -1
  12. package/dist/safe-bash/command-chunks/{chunk-5VSGEE6J.js → chunk-F4IQCXZG.js} +5 -5
  13. package/dist/safe-bash/command-chunks/{chunk-F5MORDSU.js → chunk-FDNCPZQS.js} +32 -1
  14. package/dist/safe-bash/command-chunks/{chunk-SG3ZDZCX.js → chunk-FLMLM7Y4.js} +2 -2
  15. package/dist/safe-bash/command-chunks/{chunk-DVZCHNB5.js → chunk-J2NPH7DO.js} +11 -7
  16. package/dist/safe-bash/command-chunks/{chunk-CT3FB722.js → chunk-J7UMKBRK.js} +1 -1
  17. package/dist/safe-bash/command-chunks/{chunk-QQOAK7JQ.js → chunk-KKJCKPTA.js} +1 -1
  18. package/dist/safe-bash/command-chunks/{chunk-7KS6PX4U.js → chunk-KSIGF4AG.js} +3 -3
  19. package/dist/safe-bash/command-chunks/{chunk-KBBI4CSU.js → chunk-L2C5TIII.js} +2 -2
  20. package/dist/safe-bash/command-chunks/{chunk-4HQ7WYSI.js → chunk-MED2BOOW.js} +30 -5
  21. package/dist/safe-bash/command-chunks/{chunk-JRNLDPLI.js → chunk-OZSWW23M.js} +1 -1
  22. package/dist/safe-bash/command-chunks/{chunk-DKQ5REXF.js → chunk-QDPRSPHQ.js} +1 -1
  23. package/dist/safe-bash/command-chunks/{chunk-WOPU2VWF.js → chunk-RID3B5RE.js} +1 -1
  24. package/dist/safe-bash/command-chunks/{chunk-H2FQA4OU.js → chunk-TCAGGM44.js} +72 -19
  25. package/dist/safe-bash/command-chunks/{chunk-REYTQLLB.js → chunk-TT2DMDBY.js} +1 -1
  26. package/dist/safe-bash/command-chunks/{chunk-UGX6MXDD.js → chunk-UIIT4ULR.js} +3 -3
  27. package/dist/safe-bash/command-chunks/{chunk-A6NFLWZI.js → chunk-WKPOGTZY.js} +22 -6
  28. package/dist/safe-bash/command-chunks/{chunk-WI35236J.js → chunk-XYCWDGOG.js} +1 -1
  29. package/dist/safe-bash/command-chunks/{chunk-3DOHQQJR.js → chunk-Y64PA6IA.js} +8 -8
  30. package/dist/safe-bash/command-chunks/{chunk-4F6PG2OT.js → chunk-YJWWRCIG.js} +8 -8
  31. package/dist/safe-bash/command-chunks/{chunk-6Z7OS3TZ.js → chunk-ZP5KDHB4.js} +7 -7
  32. package/dist/safe-bash/commands/pandoc/index.d.ts +1 -1
  33. package/dist/safe-bash/commands/pandoc/index.js +5 -3
  34. package/dist/safe-bash/commands/python/index.browser.js +1 -1
  35. package/dist/safe-bash/commands/python/index.js +6 -0
  36. package/dist/safe-bash/commands/python/jspi.js +11 -2
  37. package/dist/safe-bash/core.browser.js +6 -4
  38. package/dist/safe-bash-command-column/column.js +3 -3
  39. package/dist/safe-bash-command-column/index.js +3 -3
  40. package/dist/safe-bash-command-column/layout.js +2 -2
  41. package/dist/safe-bash-command-csvkit/index.js +8 -8
  42. package/dist/safe-bash-command-factor/command.js +2 -2
  43. package/dist/safe-bash-command-factor/index.js +2 -2
  44. package/dist/safe-bash-command-ffmpeg/index.js +5923 -5893
  45. package/dist/safe-bash-command-imagemagick/index.js +2 -2
  46. package/dist/safe-bash-command-pandoc/command.js +3 -3
  47. package/dist/safe-bash-command-pandoc/index.js +3 -3
  48. package/dist/safe-bash-command-pdfimages/index.js +72 -19
  49. package/dist/safe-bash-command-pdfinfo/index.js +88 -36
  50. package/dist/safe-bash-command-pdftk/index.js +72 -19
  51. package/dist/safe-bash-command-pdftoppm/index.js +88 -36
  52. package/dist/safe-bash-command-pdftotext/index.js +72 -19
  53. package/dist/safe-bash-command-qpdf/index.js +72 -19
  54. package/dist/safe-bash-command-sips/index.js +2 -2
  55. package/dist/safe-bash-command-soffice/index.js +17 -17
  56. package/dist/safe-bash-command-ssconvert/command-bindings.d.ts +18 -0
  57. package/dist/safe-bash-command-ssconvert/command.d.ts +5 -14
  58. package/dist/safe-bash-command-ssconvert/commands.d.ts +6 -0
  59. package/dist/safe-bash-command-ssconvert/commands.js +871 -0
  60. package/dist/safe-bash-command-ssconvert/core.js +8 -8
  61. package/dist/safe-bash-command-ssconvert/formats/csv.js +9 -9
  62. package/dist/safe-bash-command-ssconvert/formats/ods.js +8 -8
  63. package/dist/safe-bash-command-ssconvert/formats/spreadsheetml.js +1 -1
  64. package/dist/safe-bash-command-ssconvert/formats/xls.js +9 -8
  65. package/dist/safe-bash-command-ssconvert/formats/xlsx.js +8 -8
  66. package/dist/safe-bash-command-ssconvert/index.js +376 -236
  67. package/dist/safe-bash-command-wkhtmltopdf/index.js +72 -19
  68. package/dist/safe-bash-command-yq/index.js +4 -4
  69. package/dist/safe-bash-compression-engine/files.js +2 -2
  70. package/dist/safe-bash-compression-engine/operand.js +4 -4
  71. package/dist/safe-bash-contracts/filesystem-descriptor.js +1 -1
  72. package/dist/safe-bash-contracts/filesystem-output.js +1 -1
  73. package/dist/safe-bash-markdown-engine/commonmark-blocks.js +4 -4
  74. package/dist/safe-bash-markdown-engine/commonmark-inlines.js +4 -4
  75. package/dist/safe-bash-markdown-engine/commonmark-syntax.js +2 -2
  76. package/dist/safe-bash-markdown-engine/gfm-syntax.js +3 -3
  77. package/dist/safe-bash-markdown-engine/index.js +7 -7
  78. package/dist/safe-bash-mcp/index.js +4 -4
  79. package/dist/safe-bash-query-engine/index.js +5 -5
  80. package/dist/safe-bash-query-engine/interpreter.js +4 -4
  81. package/dist/safe-bash-query-engine/query-core.js +5 -5
  82. package/dist/spreadsheet-engine/formulas/ast.d.ts +13 -0
  83. package/dist/spreadsheet-engine/formulas/conventions.js +1 -1
  84. package/dist/spreadsheet-engine/formulas/dependencies.js +2 -2
  85. package/dist/spreadsheet-engine/formulas/evaluator.js +2 -2
  86. package/dist/spreadsheet-engine/formulas/named-expressions.d.ts +2 -2
  87. package/dist/spreadsheet-engine/formulas/named-expressions.js +31 -5
  88. package/dist/spreadsheet-engine/formulas/parser.js +34 -0
  89. package/dist/spreadsheet-engine/formulas/rewriting.js +19 -1
  90. package/dist/spreadsheet-engine/formulas/serialization.js +6 -0
  91. package/dist/spreadsheet-format-xls/biff-write-formulas.js +2 -0
  92. package/dist/xlsx-ast/formula-semantics.js +2 -0
  93. package/package.json +6 -2
  94. package/third-party/pdf-ast/THIRD_PARTY_NOTICES.md +16 -0
  95. package/dist/safe-bash/chunks/browser-ECQX6GMK.js +0 -6766
  96. package/dist/safe-bash/chunks/bz2-4OP3OWW3.js +0 -8
  97. package/dist/safe-bash/chunks/chunk-22XPAAOI.js +0 -173
  98. package/dist/safe-bash/chunks/chunk-44WUNUPV.js +0 -649
  99. package/dist/safe-bash/chunks/chunk-4E3SGG37.js +0 -876
  100. package/dist/safe-bash/chunks/chunk-4QTSSQKP.js +0 -898
  101. package/dist/safe-bash/chunks/chunk-5UVGPVXP.js +0 -410
  102. package/dist/safe-bash/chunks/chunk-64OE6Q6X.js +0 -3487
  103. package/dist/safe-bash/chunks/chunk-6IIFUPN2.js +0 -1526
  104. package/dist/safe-bash/chunks/chunk-BENDLTQD.js +0 -7065
  105. package/dist/safe-bash/chunks/chunk-BMO5LWEX.js +0 -534
  106. package/dist/safe-bash/chunks/chunk-BPMCPTNP.js +0 -1920
  107. package/dist/safe-bash/chunks/chunk-BRJTAWP5.js +0 -2955
  108. package/dist/safe-bash/chunks/chunk-C3GEIN7Q.js +0 -20054
  109. package/dist/safe-bash/chunks/chunk-CBVANNKK.js +0 -174814
  110. package/dist/safe-bash/chunks/chunk-CEWCRI6H.js +0 -2813
  111. package/dist/safe-bash/chunks/chunk-CGL53DQQ.js +0 -37
  112. package/dist/safe-bash/chunks/chunk-CTYJJD4O.js +0 -869
  113. package/dist/safe-bash/chunks/chunk-CWSS4MQA.js +0 -7
  114. package/dist/safe-bash/chunks/chunk-DLIGMTCP.js +0 -3266
  115. package/dist/safe-bash/chunks/chunk-EMAJ7WUW.js +0 -1031
  116. package/dist/safe-bash/chunks/chunk-FDKIZ2IJ.js +0 -1950
  117. package/dist/safe-bash/chunks/chunk-FZWJ2A7V.js +0 -3093
  118. package/dist/safe-bash/chunks/chunk-G2VCIF2J.js +0 -22
  119. package/dist/safe-bash/chunks/chunk-GVKBUQDX.js +0 -2649
  120. package/dist/safe-bash/chunks/chunk-IO2OGW3E.js +0 -28051
  121. package/dist/safe-bash/chunks/chunk-ISCZG7WA.js +0 -2648
  122. package/dist/safe-bash/chunks/chunk-JCN3FXLP.js +0 -38983
  123. package/dist/safe-bash/chunks/chunk-KJHDD4A2.js +0 -759
  124. package/dist/safe-bash/chunks/chunk-LB6HVRXS.js +0 -857
  125. package/dist/safe-bash/chunks/chunk-LLWAJOZH.js +0 -15
  126. package/dist/safe-bash/chunks/chunk-LMUKYZIJ.js +0 -708
  127. package/dist/safe-bash/chunks/chunk-M5SCNKIK.js +0 -2012
  128. package/dist/safe-bash/chunks/chunk-MJPFHANT.js +0 -3350
  129. package/dist/safe-bash/chunks/chunk-MZQW2DOL.js +0 -82
  130. package/dist/safe-bash/chunks/chunk-NB2V7EOY.js +0 -1348
  131. package/dist/safe-bash/chunks/chunk-NJVGOIYN.js +0 -17
  132. package/dist/safe-bash/chunks/chunk-OLNZHDIQ.js +0 -5141
  133. package/dist/safe-bash/chunks/chunk-OSUXMC43.js +0 -2317
  134. package/dist/safe-bash/chunks/chunk-OUUVROTM.js +0 -38
  135. package/dist/safe-bash/chunks/chunk-PA6GYKBQ.js +0 -151
  136. package/dist/safe-bash/chunks/chunk-PEFHZ226.js +0 -6957
  137. package/dist/safe-bash/chunks/chunk-QBB5P5KW.js +0 -4839
  138. package/dist/safe-bash/chunks/chunk-RSAWYAEH.js +0 -973
  139. package/dist/safe-bash/chunks/chunk-UWLYRWT4.js +0 -739
  140. package/dist/safe-bash/chunks/chunk-V463NBQH.js +0 -13
  141. package/dist/safe-bash/chunks/chunk-WPUALYUS.js +0 -843
  142. package/dist/safe-bash/chunks/chunk-XHKFSRGU.js +0 -5747
  143. package/dist/safe-bash/chunks/chunk-XHRCLZ3N.js +0 -13391
  144. package/dist/safe-bash/chunks/chunk-XPF5XHLY.js +0 -15
  145. package/dist/safe-bash/chunks/chunk-ZBFOWARG.js +0 -305
  146. package/dist/safe-bash/chunks/chunk-ZG7GWQ5P.js +0 -1859
  147. package/dist/safe-bash/chunks/model-store-EIY3ZQLZ.js +0 -10
  148. package/dist/safe-bash/chunks/pdf-renderer-CMF3CSVU.js +0 -22
  149. package/dist/safe-bash/chunks/pptx-ZL6L7KP2-O425BFIU.js +0 -30658
  150. package/dist/safe-bash/chunks/src-HHEPGR7U.js +0 -18969
  151. package/dist/safe-bash/chunks/src-MXIKQCIC.js +0 -187
  152. package/dist/safe-bash/chunks/usage-6TGVA2OM.js +0 -35
  153. package/dist/safe-bash/chunks/xz-EGQGQUEI.js +0 -8
  154. package/dist/safe-bash/chunks/xz-K2E2WLM6.js +0 -9
  155. package/dist/safe-bash/chunks/zstd-6JBLP5EF.js +0 -8
  156. package/dist/safe-bash/git_rust-C3QYOAZL.wasm +0 -0
  157. package/dist/safe-bash/command-chunks/{chunk-OQVIJMBY.js → chunk-7HINP7ZK.js} +4 -4
  158. package/dist/safe-bash/command-chunks/{chunk-XAYEDOV5.js → chunk-CG4JSOK2.js} +3 -3
  159. package/dist/safe-bash/command-chunks/{chunk-YIK4ZYQ4.js → chunk-DC52GWRK.js} +9 -9
  160. package/dist/safe-bash/command-chunks/{chunk-TOTZFBDT.js → chunk-TKACIO4X.js} +4 -4
  161. package/dist/safe-bash/command-chunks/{chunk-VTWKS4RM.js → chunk-WF2LSKMI.js} +3 -3
@@ -73156,7 +73156,7 @@ var odfGrammar = Object.freeze({
73156
73156
  prefixes: Object.freeze(["of:=", "oooc:=", "="]),
73157
73157
  functionPrefixes: Object.freeze(["ORG.GNUMERIC.", "COM.MICROSOFT."])
73158
73158
  });
73159
- var internalOdfGrammar = Object.freeze({ ...odfGrammar, internalLabels: true });
73159
+ var internalOdfGrammar = Object.freeze({ ...odfGrammar, internalLabels: true, internalNames: true });
73160
73160
  var sylkGrammar = Object.freeze({ ...gnumericGrammar, id: "sylk", address: "r1c1" });
73161
73161
  var sylkWriterGrammar = Object.freeze({ ...sylkGrammar, id: "sylk-writer", stringEscape: "raw" });
73162
73162
  var legacyOpenOfficeGrammar = Object.freeze({
@@ -74602,6 +74602,40 @@ function parseExpression(source, options) {
74602
74602
  throw new SsconvertError("resource-limit", "ssconvert formula node limit exceeded");
74603
74603
  try {
74604
74604
  const c4 = source[offset];
74605
+ if (source.startsWith("@name.", offset)) {
74606
+ if (grammar3.id !== "gnumeric" && !grammar3.internalNames)
74607
+ fail2("Internal live name in native formula");
74608
+ offset += 6;
74609
+ const relative = source.startsWith("relative", offset);
74610
+ if (!relative && !source.startsWith("absolute", offset))
74611
+ fail2("Invalid live name mode");
74612
+ offset += 8;
74613
+ const fixedSheet = source.startsWith(".fixed-sheet", offset);
74614
+ if (fixedSheet)
74615
+ offset += 12;
74616
+ if (source[offset++] !== "[")
74617
+ fail2("Invalid live name mode");
74618
+ const displacement = (separator2) => {
74619
+ const start2 = offset;
74620
+ if (source[offset] === "-")
74621
+ offset++;
74622
+ const begin = offset;
74623
+ while (digit(source[offset]))
74624
+ offset++;
74625
+ const value3 = Number(source.slice(start2, offset));
74626
+ if (offset === begin || !Number.isSafeInteger(value3) || source[offset++] !== separator2)
74627
+ fail2("Invalid live name displacement");
74628
+ return value3;
74629
+ };
74630
+ const row = displacement(","), column = displacement(","), sheet = displacement("]");
74631
+ if (!relative && (row !== 0 || column !== 0) || source[offset++] !== ":" || source[offset] !== '"')
74632
+ fail2("Invalid live name");
74633
+ const name = quoted('"', grammar3.stringEscape);
74634
+ if (!name)
74635
+ fail2("Empty live name");
74636
+ options.onName?.(name);
74637
+ return node3({ kind: "name", name, workbook: "", relocation: { relative, row, column, sheet, ...fixedSheet ? { sheetRelative: false } : {} }, start, end: offset });
74638
+ }
74605
74639
  if (c4 === "@" && !internalLabels)
74606
74640
  fail2("Internal label reference in native formula");
74607
74641
  if (c4 === "@" && internalLabels) {
@@ -75058,23 +75092,51 @@ function parseExpression(source, options) {
75058
75092
  return { ok: false, source, diagnostic };
75059
75093
  }
75060
75094
  }
75061
- function parseNamedExpression(name, book, parse3, tick, maximumDepth = Infinity) {
75095
+ function parseNamedExpression(name, book, parse3, tick, maximumDepth = Infinity, relocation) {
75062
75096
  if (name.expression === "" || name.expression === "=") {
75063
75097
  tick();
75064
75098
  return { kind: "literal", value: { kind: "blank" }, start: 0, end: 0 };
75065
75099
  }
75066
75100
  const position = name.position ?? { sheet: name.sheet ?? book.sheets[0]?.id ?? "", row: 0, column: 0 };
75101
+ function displace(ref, fallback) {
75102
+ if (!relocation || ref.workbook !== void 0)
75103
+ return ref;
75104
+ const origin = book.sheets.findIndex((sheet) => sheet.id === position.sheet);
75105
+ const index2 = ref.sheetRelative ? origin + (ref.sheetOffset ?? 0) : ref.sheet !== void 0 || fallback !== void 0 ? book.sheets.findIndex((sheet) => foldSheetName(sheet.name) === foldSheetName(ref.sheet ?? fallback)) : origin;
75106
+ const target = index2 >= 0 ? book.sheets[index2 + relocation.sheet] : void 0;
75107
+ if (!target)
75108
+ return void 0;
75109
+ const axis = (value3, key) => ({ value: value3.value + (value3.relative ? position[key] : 0) + relocation[key], relative: false });
75110
+ return { ...ref, sheet: target.name, sheetRelative: false, ...ref.row ? { row: axis(ref.row, "row") } : {}, ...ref.column ? { column: axis(ref.column, "column") } : {} };
75111
+ }
75067
75112
  function bind(node3, depth = 0) {
75068
75113
  tick();
75069
75114
  if (depth > maximumDepth)
75070
75115
  throw new SsconvertError("resource-limit", "ssconvert formula dependency depth limit exceeded");
75071
- if (node3.kind === "name" && (node3.workbook === void 0 || node3.workbook === "" && node3.sheet !== void 0)) {
75116
+ if (node3.kind === "reference" && relocation) {
75117
+ const first = displace(node3.first), last = node3.last ? displace(node3.last, node3.first.sheet) : void 0;
75118
+ if (!first || node3.last && !last)
75119
+ return { kind: "literal", value: { kind: "error", value: "#REF!" }, start: node3.start, end: node3.end };
75120
+ return { ...node3, first, ...last ? { last } : {} };
75121
+ }
75122
+ if (node3.kind === "name" && (node3.workbook === void 0 || node3.workbook === "")) {
75123
+ const inherited = relocation ? {
75124
+ ...relocation,
75125
+ row: relocation.row + (node3.relocation?.row ?? 0),
75126
+ column: relocation.column + (node3.relocation?.column ?? 0),
75127
+ sheet: relocation.sheet + (node3.relocation?.sheet ?? 0)
75128
+ } : node3.relocation;
75129
+ const bound = inherited ? { ...node3, relocation: inherited } : node3;
75130
+ if (node3.workbook === "" && node3.sheet === void 0)
75131
+ return bound;
75072
75132
  const scope = node3.sheet === void 0 ? name.sheet : book.sheets.find((sheet2) => foldSheetName(sheet2.name) === foldSheetName(node3.sheet))?.id;
75073
75133
  const target = resolveName(book, node3.name, scope);
75074
- if (target?.sheet === void 0)
75075
- return { kind: "name", name: node3.name, workbook: "", start: node3.start, end: node3.end };
75134
+ if (target?.sheet === void 0) {
75135
+ const { sheet: ignoredSheet, ...global2 } = bound;
75136
+ return { ...global2, workbook: "" };
75137
+ }
75076
75138
  const sheet = book.sheets.find((sheet2) => sheet2.id === target.sheet);
75077
- return sheet ? { ...node3, sheet: sheet.name } : node3;
75139
+ return sheet ? { ...bound, sheet: sheet.name } : bound;
75078
75140
  }
75079
75141
  if (node3.kind === "parentheses" || node3.kind === "unary")
75080
75142
  return { ...node3, child: bind(node3.child, depth + 1) };
@@ -75470,7 +75532,7 @@ function buildDependencyGraph(book, roots, resolve, parse3, tick, onRange, maxim
75470
75532
  const name = named(node3, position);
75471
75533
  if (!name || names2.has(name))
75472
75534
  return [];
75473
- return staticRanges(parseNamedExpression(name, book, parse3, tick, maximumDepth), position, /* @__PURE__ */ new Set([...names2, name]), depth + 1);
75535
+ return staticRanges(parseNamedExpression(name, book, parse3, tick, maximumDepth, node3.relocation), position, /* @__PURE__ */ new Set([...names2, name]), depth + 1);
75474
75536
  }
75475
75537
  if (node3.kind === "call" && (node3.name === "IF" || node3.name === "CHOOSE")) {
75476
75538
  const ranges3 = [];
@@ -75579,7 +75641,7 @@ function buildDependencyGraph(book, roots, resolve, parse3, tick, onRange, maxim
75579
75641
  if (node3.kind === "name" && (node3.workbook === void 0 || node3.workbook === "")) {
75580
75642
  const name = named(node3, position2);
75581
75643
  if (name && !names3.has(name)) {
75582
- pending.push({ node: parseNamedExpression(name, book, parse3, tick, maximumDepth), position: position2, names: /* @__PURE__ */ new Set([...names3, name]), depth: depth + 1 });
75644
+ pending.push({ node: parseNamedExpression(name, book, parse3, tick, maximumDepth, node3.relocation), position: position2, names: /* @__PURE__ */ new Set([...names3, name]), depth: depth + 1 });
75583
75645
  }
75584
75646
  }
75585
75647
  const children8 = node3.kind === "unary" || node3.kind === "parentheses" ? [node3.child] : node3.kind === "binary" ? [node3.left, node3.right] : node3.kind === "call" ? node3.args : node3.kind === "array" ? node3.rows.flat() : [];
@@ -76018,6 +76080,12 @@ function serializeExpression(document6, grammar3 = document6.grammar, preserveSo
76018
76080
  case "reference":
76019
76081
  return value3.label ? grammar3.quotedLabels === "openformula" && options.quotedLabel ? quoteFormulaString(options.quotedLabel(value3), "'", grammar3) : serializeLabelReference(value3, grammar3, position) : serializeReference(options.relativeSheets === "fixed" ? { ...value3.first, sheetRelative: false } : value3.first, options.relativeSheets === "fixed" && value3.last ? { ...value3.last, sheetRelative: false } : value3.last, grammar3, position);
76020
76082
  case "name": {
76083
+ if (value3.relocation) {
76084
+ if (grammar3.id !== "gnumeric" && !grammar3.internalNames)
76085
+ throw new SsconvertError("unsupported-feature", "Unsupported ssconvert feature: live name relocation in target grammar");
76086
+ const { relative, row, column, sheet } = value3.relocation;
76087
+ return `@name.${relative ? "relative" : "absolute"}${value3.relocation.sheetRelative === false ? ".fixed-sheet" : ""}[${row},${column},${sheet}]:` + quoteFormulaString(value3.name, '"', grammar3);
76088
+ }
76021
76089
  if (grammar3.qualifiedNames === false && (value3.sheet !== void 0 || value3.workbook !== void 0))
76022
76090
  throw new SsconvertError("unsupported-feature", "Unsupported ssconvert feature: qualified formula name in target grammar");
76023
76091
  if (value3.workbook === "" && grammar3.bracketReferences && value3.sheet === void 0)
@@ -76192,6 +76260,23 @@ function rewriteReferences(document6, edit) {
76192
76260
  const position = { ...target, sheet: document6.sheetNames?.[target.sheet] ?? target.sheet };
76193
76261
  changes.push({ start: node3.start, end: node3.end, text: label ? serializeLabelReference({ ...node3, first, ...last ? { last } : {}, label }, document6.grammar, position) : serializeReference(first, last, document6.grammar, position) });
76194
76262
  }
76263
+ } else if (node3.kind === "name" && node3.relocation && edit.translation === "copy") {
76264
+ const relocation = { ...node3.relocation };
76265
+ if (relocation.relative) {
76266
+ relocation.row += target.row - document6.position.row;
76267
+ relocation.column += target.column - document6.position.column;
76268
+ }
76269
+ if (relocation.sheetRelative !== false && target.sheet !== document6.position.sheet) {
76270
+ const origin = document6.sheetOrder?.indexOf(document6.position.sheet) ?? -1;
76271
+ const destination = document6.sheetOrder?.indexOf(target.sheet) ?? -1;
76272
+ if (origin < 0 || destination < 0)
76273
+ throw new SsconvertError("invalid-request", "Cross-sheet formula copy requires workbook tab order");
76274
+ relocation.sheet += destination - origin;
76275
+ }
76276
+ if (![relocation.row, relocation.column, relocation.sheet].every(Number.isSafeInteger))
76277
+ throw new SsconvertError("invalid-request", "Invalid live name displacement");
76278
+ const text2 = serializeExpression({ ...document6, root: { ...node3, relocation } }, document6.grammar, false).slice(document6.grammar.prefixes[0]?.length ?? 0);
76279
+ changes.push({ start: node3.start, end: node3.end, text: text2 });
76195
76280
  } else if (node3.kind === "name" && (node3.workbook === void 0 || node3.workbook === "") && node3.sheet && renamedSheet(node3.sheet) !== void 0) {
76196
76281
  const text2 = quoteFormulaString(renamedSheet(node3.sheet), "'", document6.grammar) + document6.grammar.sheetSeparator + node3.name;
76197
76282
  changes.push({ start: node3.start, end: node3.end, text: document6.grammar.bracketReferences ? "[" + text2 + "]" : text2 });
@@ -98933,7 +99018,7 @@ function* recalculateWorkbookSteps(input, context, options = false, onDiagnostic
98933
99018
  const name = book.names?.find((entry2) => entry2.sheet === sheet && matches(entry2)) ?? book.names?.find((entry2) => entry2.sheet === void 0 && matches(entry2));
98934
99019
  if (!name || names2.has(name))
98935
99020
  return error("#REF!");
98936
- return indirectRange(parseNamedExpression(name, book, parse3, tick, context.limits.formulaDependencyDepth ?? Infinity), position, /* @__PURE__ */ new Set([...names2, name]), depth2 + 1);
99021
+ return indirectRange(parseNamedExpression(name, book, parse3, tick, context.limits.formulaDependencyDepth ?? Infinity, node3.relocation), position, /* @__PURE__ */ new Set([...names2, name]), depth2 + 1);
98937
99022
  }
98938
99023
  function scalar2(value3, position) {
98939
99024
  const label = scalarLabels.get(value3);
@@ -99027,7 +99112,7 @@ function* recalculateWorkbookSteps(input, context, options = false, onDiagnostic
99027
99112
  const name = book.names?.find((entry2) => entry2.sheet === sheet && matches(entry2)) ?? book.names?.find((entry2) => entry2.sheet === void 0 && matches(entry2));
99028
99113
  if (!name || names2.has(name))
99029
99114
  return error("#NAME?");
99030
- return evaluate(parseNamedExpression(name, book, parse3, tick, context.limits.formulaDependencyDepth ?? Infinity), position, array, /* @__PURE__ */ new Set([...names2, name]), wantReference);
99115
+ return evaluate(parseNamedExpression(name, book, parse3, tick, context.limits.formulaDependencyDepth ?? Infinity, node3.relocation), position, array, /* @__PURE__ */ new Set([...names2, name]), wantReference);
99031
99116
  }
99032
99117
  if (node3.kind === "unary") {
99033
99118
  const apply = (value3) => {
@@ -126101,6 +126186,8 @@ var BiffFormulaWriter = class {
126101
126186
  } else
126102
126187
  push(first);
126103
126188
  } else if (node3.kind === "name") {
126189
+ if (node3.relocation)
126190
+ throw new SsconvertError("unsupported-feature", "Unsupported ssconvert feature: live name relocation in BIFF output");
126104
126191
  if (node3.workbook) {
126105
126192
  const bookIndex = this.externalBook(node3.workbook), book = this.externalBooks[bookIndex];
126106
126193
  const scope2 = node3.sheet === void 0 ? void 0 : this.externalScope(bookIndex, node3.sheet);
@@ -136412,6 +136499,8 @@ function nativeOpenFormula(source, position, context, arrayStringLiterals = fals
136412
136499
  throw new SsconvertError("unsupported-feature", "Unsupported ssconvert feature: automatic label intersection in Gnumeric output");
136413
136500
  if (node3.kind === "reference" && node3.label)
136414
136501
  throw new SsconvertError("unsupported-feature", "Unsupported ssconvert feature: live label reference in Gnumeric output");
136502
+ if (node3.kind === "name" && node3.relocation)
136503
+ throw new SsconvertError("unsupported-feature", "Unsupported ssconvert feature: live name relocation in Gnumeric output");
136415
136504
  });
136416
136505
  if (!source.startsWith("of:="))
136417
136506
  return source;
@@ -146798,17 +146887,8 @@ async function lotusFormula(bytes, format2, group, row, column, sheetIndex, shee
146798
146887
  stack.push("#NAME?");
146799
146888
  }
146800
146889
  } else {
146801
- const crossSheet = range3.first.sheet !== range3.last.sheet;
146802
- const endpoint = (point) => (point.sheet === sheetIndex && !crossSheet ? "" : quoteFormulaString(sheetName2(point.sheet), "'", gnumericGrammar) + "!") + ref(point.row, point.column, op === 7, op === 7);
146803
- const single = range3.first.row === range3.last.row && range3.first.column === range3.last.column && range3.first.sheet === range3.last.sheet;
146804
- const source = endpoint(range3.first) + (single ? "" : ":" + endpoint(range3.last));
146805
- stack.push(source);
146806
- if (crossSheet) indexRanges.set(source, {
146807
- firstSheet: range3.first.sheet,
146808
- lastSheet: range3.last.sheet,
146809
- first: ref(range3.first.row, range3.first.column, op === 7, op === 7),
146810
- last: ref(range3.last.row, range3.last.column, op === 7, op === 7)
146811
- });
146890
+ const fixedSheet = range3.first.sheet !== sheetIndex || range3.last.sheet !== sheetIndex;
146891
+ stack.push(`@name.${op === 7 ? "relative" : "absolute"}${fixedSheet ? ".fixed-sheet" : ""}[0,0,0]:` + quoteFormulaString(name, '"', gnumericGrammar));
146812
146892
  }
146813
146893
  } else if (modern && op >= 9 && op <= 11) {
146814
146894
  const length = op === 9 ? 4 : op === 10 ? 5 : 11;
@@ -146957,14 +147037,14 @@ async function lotusFormula(bytes, format2, group, row, column, sheetIndex, shee
146957
147037
  if (!parsed.ok) throw new SsconvertError("unsupported-feature", "Unsupported ssconvert feature: Lotus relative-sheet formula");
146958
147038
  const substitute = (node3) => {
146959
147039
  context.signal.throwIfAborted();
146960
- if (node3.kind === "name") return relativeReferences.get(node3.name) ?? node3;
147040
+ if (node3.kind === "name") return node3.relocation ? node3 : relativeReferences.get(node3.name) ?? node3;
146961
147041
  if (node3.kind === "unary" || node3.kind === "parentheses") return { ...node3, child: substitute(node3.child) };
146962
147042
  if (node3.kind === "binary") return { ...node3, left: substitute(node3.left), right: substitute(node3.right) };
146963
147043
  if (node3.kind === "call") return { ...node3, args: node3.args.map(substitute) };
146964
147044
  if (node3.kind === "array") return { ...node3, rows: node3.rows.map((row2) => row2.map(substitute)) };
146965
147045
  return node3;
146966
147046
  };
146967
- const expression2 = serializeExpression({ ...parsed.document, root: substitute(parsed.document.root) }, odfGrammar, false, true);
147047
+ const expression2 = serializeExpression({ ...parsed.document, root: substitute(parsed.document.root) }, internalOdfGrammar, false, true);
146968
147048
  if (expression2.length > (context.limits.workbookTextBytes ?? context.limits.inputBytes))
146969
147049
  throw new SsconvertError("resource-limit", "ssconvert Lotus formula length limit exceeded");
146970
147050
  return expression2;
@@ -198701,7 +198781,7 @@ var ParsedCosDocument = class {
198701
198781
  return void 0;
198702
198782
  }
198703
198783
  };
198704
- function parseNodeFromLexer(lexer, bytes, maxDepth, recoverEmptyObject = false) {
198784
+ function parseNodeFromLexer(lexer, bytes, maxDepth, repair = false) {
198705
198785
  const stack = [];
198706
198786
  while (true) {
198707
198787
  const tok = lexer.nextToken();
@@ -198710,7 +198790,7 @@ function parseNodeFromLexer(lexer, bytes, maxDepth, recoverEmptyObject = false)
198710
198790
  if (!parent) return void 0;
198711
198791
  throw new PdfError2("E_PARSE", parent.kind === "array" ? "Unterminated PDF array" : "Unterminated PDF dictionary");
198712
198792
  }
198713
- if (!parent && recoverEmptyObject && tok.kind === "keyword" && tok.value === "endobj") {
198793
+ if (!parent && repair && tok.kind === "keyword" && tok.value === "endobj") {
198714
198794
  return { kind: "null", span: tok.span };
198715
198795
  }
198716
198796
  let node3;
@@ -198725,6 +198805,7 @@ function parseNodeFromLexer(lexer, bytes, maxDepth, recoverEmptyObject = false)
198725
198805
  parent.key = { kind: "name", rawBytes: tok.rawBytes, decoded: tok.decoded, span: tok.span };
198726
198806
  continue;
198727
198807
  } else {
198808
+ if (repair) continue;
198728
198809
  throw new PdfError2("E_PARSE", `Expected dictionary key /Name, got ${tok.kind}`);
198729
198810
  }
198730
198811
  } else {
@@ -198893,7 +198974,7 @@ function parseHeaderVersion(bytes) {
198893
198974
  }
198894
198975
  return head.slice(idx + 5, idx + 8);
198895
198976
  }
198896
- function parseObjectAtOffset(bytes, offset, maxRecursionDepth, recoverEmptyObject = false) {
198977
+ function parseObjectAtOffset(bytes, offset, maxRecursionDepth, repair = false) {
198897
198978
  const lexer = new CosByteLexer(bytes, offset);
198898
198979
  const objNumTok = lexer.nextToken();
198899
198980
  const genNumTok = lexer.nextToken();
@@ -198901,7 +198982,7 @@ function parseObjectAtOffset(bytes, offset, maxRecursionDepth, recoverEmptyObjec
198901
198982
  if (objNumTok?.kind !== "number" || genNumTok?.kind !== "number" || objKwTok?.kind !== "keyword" || objKwTok.value !== "obj") {
198902
198983
  throw new PdfError2("E_PARSE", `Malformed indirect object header at byte offset ${offset}`);
198903
198984
  }
198904
- const value3 = parseNodeFromLexer(lexer, bytes, maxRecursionDepth, recoverEmptyObject);
198985
+ const value3 = parseNodeFromLexer(lexer, bytes, maxRecursionDepth, repair);
198905
198986
  if (!value3) {
198906
198987
  throw new PdfError2("E_PARSE", `Empty indirect object ${objNumTok.value} at offset ${offset}`);
198907
198988
  }
@@ -199090,7 +199171,7 @@ function repairScanCosDocument(bytes, maxObjects, maxRecursionDepth) {
199090
199171
  try {
199091
199172
  const token = lexer.nextToken();
199092
199173
  if (token?.kind === "keyword" && token.value === "trailer") {
199093
- const trailer = parseNodeFromLexer(lexer, bytes, maxRecursionDepth);
199174
+ const trailer = parseNodeFromLexer(lexer, bytes, maxRecursionDepth, true);
199094
199175
  if (trailer?.kind === "dict") trailers.push(trailer);
199095
199176
  pos = lexer.offset;
199096
199177
  continue;
@@ -199146,7 +199227,7 @@ function unpackRecoveredObjects(objects, maxObjects, maxDecompressedBytes, maxRe
199146
199227
  const t = dictGet(obj.value.dict, "Type");
199147
199228
  if (t?.kind === "name" && t.decoded === "ObjStm") {
199148
199229
  try {
199149
- for (const [unpackedNum, unpackedVal] of unpackObjectStream(obj.value, maxDecompressedBytes, maxRecursionDepth).entries()) {
199230
+ for (const [unpackedNum, unpackedVal] of unpackObjectStream(obj.value, maxDecompressedBytes, maxRecursionDepth, true).entries()) {
199150
199231
  if (!objects.has(unpackedNum)) {
199151
199232
  objects.set(unpackedNum, {
199152
199233
  objectNumber: unpackedNum,
@@ -199182,7 +199263,7 @@ function recoveredReferences(objects) {
199182
199263
  }
199183
199264
  return { ...rootRef ? { rootRef } : {}, ...infoRef ? { infoRef } : {} };
199184
199265
  }
199185
- function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth) {
199266
+ function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth, repair = false) {
199186
199267
  const nNode = dictGet(streamObj.dict, "N");
199187
199268
  const firstNode = dictGet(streamObj.dict, "First");
199188
199269
  if (nNode?.kind !== "number" || firstNode?.kind !== "number") {
@@ -199202,7 +199283,7 @@ function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth)
199202
199283
  for (const pair of pairs) {
199203
199284
  try {
199204
199285
  const valLexer = new CosByteLexer(decoded, firstNode.value + pair.relativeOffset);
199205
- const node3 = parseNodeFromLexer(valLexer, decoded, maxRecursionDepth);
199286
+ const node3 = parseNodeFromLexer(valLexer, decoded, maxRecursionDepth, repair);
199206
199287
  if (node3) {
199207
199288
  result2.set(pair.objectNumber, node3);
199208
199289
  }
@@ -199385,7 +199466,7 @@ function parseCosDocument(bytes, options = {}) {
199385
199466
  if (!unpacked) {
199386
199467
  const stmObj = objects.get(entry2.objectStreamNumber)?.value;
199387
199468
  if (stmObj?.kind === "stream") {
199388
- unpacked = unpackObjectStream(stmObj, maxDecompressedBytes, maxRecursionDepth);
199469
+ unpacked = unpackObjectStream(stmObj, maxDecompressedBytes, maxRecursionDepth, recovery === "repair");
199389
199470
  objStmCache.set(entry2.objectStreamNumber, unpacked);
199390
199471
  }
199391
199472
  }
@@ -207857,7 +207938,11 @@ function resolvePageFonts(doc, resourcesDict) {
207857
207938
  let cmap;
207858
207939
  const toUniNode = doc.resolve(dictGet(fObj, "ToUnicode"));
207859
207940
  if (toUniNode?.kind === "stream") {
207860
- cmap = parseToUnicodeCMap(doc.decodeStream(toUniNode));
207941
+ try {
207942
+ cmap = parseToUnicodeCMap(doc.decodeStream(toUniNode));
207943
+ } catch (error2) {
207944
+ if (error2 instanceof PdfError2 && error2.code === "E_LIMIT") throw error2;
207945
+ }
207861
207946
  }
207862
207947
  const encNode = doc.resolve(dictGet(fObj, "Encoding"));
207863
207948
  if (encNode?.kind === "dict") {
@@ -208981,8 +209066,12 @@ function evaluateContentStreamToDisplayList(params) {
208981
209066
  const images = [];
208982
209067
  const operations = [];
208983
209068
  const emit = (operation) => {
208984
- const clipPaths = curState().clipPaths;
208985
- if (clipPaths) operation = { ...operation, value: { ...operation.value, clipPaths } };
209069
+ const { clipPaths, clipImages } = curState();
209070
+ if (clipPaths || clipImages) operation = { ...operation, value: {
209071
+ ...operation.value,
209072
+ ...clipPaths ? { clipPaths } : {},
209073
+ ...clipImages ? { clipImages } : {}
209074
+ } };
208986
209075
  operations.push(operation);
208987
209076
  switch (operation.kind) {
208988
209077
  case "path":
@@ -209246,6 +209335,18 @@ function evaluateContentStreamToDisplayList(params) {
209246
209335
  let hasTextClip = false;
209247
209336
  let activeTm = [1, 0, 0, 1, 0, 0];
209248
209337
  let activeTlm = [1, 0, 0, 1, 0, 0];
209338
+ const paintImage = (image, patternMask, resources, activeFonts, depth) => {
209339
+ if (!patternMask) {
209340
+ emit({ kind: "image", value: image });
209341
+ return;
209342
+ }
209343
+ const st = curState();
209344
+ stateStack.push({ ...st, clipImages: [...st.clipImages ?? [], image] });
209345
+ walkNodes([{ kind: "path-op", paint: "f", segments: [
209346
+ { kind: "rect", x: 0, y: 0, width: 1, height: 1 }
209347
+ ] }], void 0, void 0, resources, activeFonts, depth);
209348
+ stateStack.pop();
209349
+ };
209249
209350
  const walkNodes = (nodes, mcid, actualText, activeResources = params.resourcesDict, activeFonts = fonts, depth = 0) => {
209250
209351
  for (const node3 of nodes) {
209251
209352
  switch (node3.kind) {
@@ -209429,7 +209530,8 @@ function evaluateContentStreamToDisplayList(params) {
209429
209530
  st.fillAlpha,
209430
209531
  "PatternShading_" + st.fillPatternName,
209431
209532
  patClip,
209432
- shading?.kind === "stream" ? shading : void 0
209533
+ shading?.kind === "stream" ? shading : void 0,
209534
+ st.blendMode
209433
209535
  );
209434
209536
  if (shImg) {
209435
209537
  emit({ kind: "image", value: shImg });
@@ -209538,18 +209640,20 @@ function evaluateContentStreamToDisplayList(params) {
209538
209640
  const subNode = params.cosDoc.resolve(dictGet(xobjNode.dict, "Subtype"));
209539
209641
  const sub = subNode?.kind === "name" ? subNode.decoded : "";
209540
209642
  if (sub === "Image") {
209643
+ const maskNode = params.cosDoc.resolve(dictGet(xobjNode.dict, "ImageMask"));
209644
+ const patternMask = !!st.fillPatternName && maskNode?.kind === "boolean" && maskNode.value;
209541
209645
  const decoded = decodeXObjectImageToRgba(
209542
209646
  params.cosDoc,
209543
209647
  xobjNode,
209544
209648
  activeResources,
209545
- {
209649
+ patternMask ? { r: 1, g: 1, b: 1, alpha: 1 } : {
209546
209650
  r: st.fillColor.r,
209547
209651
  g: st.fillColor.g,
209548
209652
  b: st.fillColor.b,
209549
209653
  alpha: st.fillAlpha
209550
209654
  }
209551
209655
  );
209552
- emit({ kind: "image", value: {
209656
+ paintImage({
209553
209657
  name: node3.name,
209554
209658
  matrix: [...st.ctm],
209555
209659
  width: decoded.width,
@@ -209559,7 +209663,7 @@ function evaluateContentStreamToDisplayList(params) {
209559
209663
  decodedRgba: decoded.rgba,
209560
209664
  ...st.blendMode && st.blendMode !== "Normal" ? { blendMode: st.blendMode } : {},
209561
209665
  ...st.clipRect ? { clipRect: [...st.clipRect] } : {}
209562
- } });
209666
+ }, patternMask, activeResources, activeFonts, depth);
209563
209667
  } else if (sub === "Form" && depth < 8) {
209564
209668
  const formStreamBytes = params.cosDoc.decodeStream(xobjNode);
209565
209669
  const formNodes = parseContentStream(formStreamBytes);
@@ -209615,19 +209719,22 @@ function evaluateContentStreamToDisplayList(params) {
209615
209719
  }
209616
209720
  case "inline-image": {
209617
209721
  const st = curState();
209722
+ const maskEntry = dictGet(node3.dict, "ImageMask") ?? dictGet(node3.dict, "IM");
209723
+ const maskNode = params.cosDoc ? params.cosDoc.resolve(maskEntry) : maskEntry;
209724
+ const patternMask = !!st.fillPatternName && maskNode?.kind === "boolean" && maskNode.value;
209618
209725
  const decoded = decodeInlineImageNodeToRgba(
209619
209726
  params.cosDoc,
209620
209727
  node3.dict,
209621
209728
  node3.data,
209622
209729
  activeResources,
209623
- {
209730
+ patternMask ? { r: 1, g: 1, b: 1, alpha: 1 } : {
209624
209731
  r: st.fillColor.r,
209625
209732
  g: st.fillColor.g,
209626
209733
  b: st.fillColor.b,
209627
209734
  alpha: st.fillAlpha
209628
209735
  }
209629
209736
  );
209630
- emit({ kind: "image", value: {
209737
+ paintImage({
209631
209738
  name: "InlineImage",
209632
209739
  matrix: [...st.ctm],
209633
209740
  width: decoded.width,
@@ -209637,7 +209744,7 @@ function evaluateContentStreamToDisplayList(params) {
209637
209744
  decodedRgba: decoded.rgba,
209638
209745
  ...st.blendMode && st.blendMode !== "Normal" ? { blendMode: st.blendMode } : {},
209639
209746
  ...st.clipRect ? { clipRect: [...st.clipRect] } : {}
209640
- } });
209747
+ }, patternMask, activeResources, activeFonts, depth);
209641
209748
  break;
209642
209749
  }
209643
209750
  case "text-object": {
@@ -212987,6 +213094,7 @@ function renderDisplayListToBitmap(displayList, options = {}) {
212987
213094
  const aaVec = options.antialiasVector !== false;
212988
213095
  const aaTxt = options.antialiasText !== false;
212989
213096
  const clipMasks = /* @__PURE__ */ new Map();
213097
+ const imageClipMasks = /* @__PURE__ */ new Map();
212990
213098
  for (const original of paintOperations(displayList)) {
212991
213099
  if (original.kind === "glyph" && (original.value.renderMode === 3 || !original.value.outline && !original.value.unicode.trim())) continue;
212992
213100
  const operation = original.kind === "glyph" ? { kind: "path", value: glyphPaint(original.value) } : original;
@@ -213001,6 +213109,31 @@ function renderDisplayListToBitmap(displayList, options = {}) {
213001
213109
  }
213002
213110
  clipMasks.set(clips, clipMask);
213003
213111
  }
213112
+ const imageClips = original.value.clipImages;
213113
+ if (imageClips) {
213114
+ let imageMask = imageClipMasks.get(imageClips);
213115
+ if (!imageMask) {
213116
+ imageMask = new Uint8Array(width2 * height * 4).fill(255);
213117
+ for (const image of imageClips) {
213118
+ const layer = renderDisplayListToBitmap({
213119
+ ...displayList,
213120
+ rotation: 0,
213121
+ paths: [],
213122
+ glyphs: [],
213123
+ images: [image],
213124
+ operations: [{ kind: "image", value: image }]
213125
+ }, { scale: scale2, transparent: true }).data;
213126
+ for (let i = 3; i < layer.length; i += 4) imageMask[i] = Math.round(imageMask[i] * layer[i] / 255);
213127
+ }
213128
+ imageClipMasks.set(imageClips, imageMask);
213129
+ }
213130
+ if (clipMask) {
213131
+ clipMask = clipMask.slice();
213132
+ for (let i = 3; i < clipMask.length; i += 4) clipMask[i] = Math.round(clipMask[i] * imageMask[i] / 255);
213133
+ } else {
213134
+ clipMask = imageMask;
213135
+ }
213136
+ }
213004
213137
  if (operation.kind === "path") {
213005
213138
  const path2 = operation.value;
213006
213139
  if (path2.fillColor) {
@@ -218619,7 +218752,7 @@ function forwardFileDescriptor(descriptor3, operation, capabilities, snapshot =
218619
218752
  write: (retained2, buffer, position, options) => operation("write", options, () => retained2.write(buffer, position, options)),
218620
218753
  truncate: (retained2, length, options) => operation("ftruncate", options, () => retained2.truncate(length, options)),
218621
218754
  sync: (retained2, dataOnly, options) => operation(dataOnly ? "fdatasync" : "fsync", options, () => retained2.sync(dataOnly, options)),
218622
- close: (retained2) => operation("close", {}, () => retained2.close())
218755
+ close: (retained2, options) => operation("close", {}, () => retained2.close(options))
218623
218756
  };
218624
218757
  }
218625
218758
  function integer6(value3, syscall, path2) {
@@ -218787,10 +218920,10 @@ var ManagedFileDescriptor = class {
218787
218920
  await backend.sync(backend.resource, dataOnly, forwarded);
218788
218921
  });
218789
218922
  }
218790
- close() {
218923
+ close(options = {}) {
218791
218924
  this.#closing ??= this.#pending.then(async () => {
218792
218925
  try {
218793
- await this.#backend.close(this.#backend.resource);
218926
+ await this.#backend.close(this.#backend.resource, options);
218794
218927
  } finally {
218795
218928
  this.#backend = void 0;
218796
218929
  this.#getPosition = void 0;
@@ -218848,7 +218981,7 @@ async function openFileDescriptor(path2, options, capabilities, acquire) {
218848
218981
  signal?.throwIfAborted();
218849
218982
  return descriptor3;
218850
218983
  } catch (error2) {
218851
- await finishCleanup(() => backend.close(backend.resource), true);
218984
+ await finishCleanup(() => backend.close(backend.resource, {}), true);
218852
218985
  signal?.throwIfAborted();
218853
218986
  throw error2;
218854
218987
  }
@@ -233215,209 +233348,216 @@ function createDatabaseFunctions(query) {
233215
233348
  }
233216
233349
  }])));
233217
233350
  }
233218
- function createSsconvertCommand(options = {}) {
233219
- const configured = { ...options };
233220
- if (configured.replace !== void 0 && typeof configured.replace !== "boolean")
233221
- throw new TypeError("ssconvert replace must be boolean");
233222
- const binding = {
233223
- ...configured,
233224
- ...configured.io === void 0 ? {} : { io: Object.freeze({
233225
- ...configured.io.descriptors === void 0 ? {} : { descriptors: Object.freeze(Object.fromEntries(
233226
- Object.entries(configured.io.descriptors).map(([key, descriptor3]) => [key, Object.freeze({ ...descriptor3 })])
233227
- )) },
233228
- ...configured.io.adapters === void 0 ? {} : { adapters: Object.freeze({ ...configured.io.adapters }) },
233229
- ...configured.io.transport === void 0 ? {} : { transport: Object.freeze({
233230
- authorize: configured.io.transport.authorize.bind(configured.io.transport),
233231
- request: configured.io.transport.request.bind(configured.io.transport),
233232
- redirects: configured.io.transport.redirects
233233
- }) }
233234
- }) },
233235
- ...configured.runtimeFunctions === void 0 ? {} : { runtimeFunctions: snapshotRuntimeFunctions(configured.runtimeFunctions) },
233236
- ...configured.profile === void 0 ? {} : { profile: Object.freeze({
233237
- ...configured.profile,
233238
- ...configured.profile.groups === void 0 ? {} : { groups: Object.freeze({ ...configured.profile.groups }) },
233239
- ...configured.profile.configurationRoots === void 0 ? {} : {
233240
- configurationRoots: Object.freeze({ ...configured.profile.configurationRoots })
233241
- }
233242
- }) },
233243
- codecs: Object.freeze([...configured.codecs ?? []]),
233244
- ...configured.formats === void 0 ? {} : { formats: snapshotFormats(configured.formats) },
233245
- limits: Object.freeze({ ...defaultSsconvertLimits, ...configured.limits }),
233246
- environment: Object.freeze({
233247
- locale: "C",
233248
- timezone: "UTC",
233249
- ...configured.environment,
233250
- env: Object.freeze({ ...configured.environment?.env })
233251
- })
233252
- };
233253
- const command = {
233254
- name: "ssconvert",
233255
- description: "Explicitly bound TypeScript spreadsheet conversion engine",
233256
- async execute(context) {
233257
- context.signal.throwIfAborted();
233258
- const owner = createOutputOperation(context, { async write() {
233259
- } });
233260
- const inputBytes = Math.min(
233261
- binding.limits.inputBytes,
233262
- context.inputBudget?.maxBytes ?? Infinity
233263
- );
233264
- let stdout;
233265
- const standardOutput = { async write(bytes) {
233266
- stdout ??= owner.child(context.stdout);
233267
- await stdout.output.write(bytes);
233268
- } };
233269
- let stderr;
233270
- const standardError = { async write(bytes) {
233271
- stderr ??= owner.child(context.stderr);
233272
- await stderr.output.write(bytes);
233273
- } };
233274
- const openOutput = createVfsOutput(context.fs, async (path2, bytes, signal) => {
233275
- await owner.acquire(() => writeFileOutput(
233276
- context,
233277
- bytes,
233278
- async (data3) => {
233279
- const capabilities = await context.fs.capabilitiesFor?.(path2, { signal }) ?? context.fs.capabilities;
233280
- signal.throwIfAborted();
233281
- if (context.fs.writeStream && capabilities.streamingWrite !== false)
233282
- await context.fs.writeStream(path2, (async function* () {
233283
- yield data3;
233284
- })(), { signal });
233285
- else await context.fs.writeFile(path2, data3, { signal });
233286
- }
233287
- ), () => {
233288
- });
233289
- }, (cleanup) => retainFileSystemCleanup(
233290
- context.fs,
233291
- (view2) => cleanup((path2) => view2.rm(path2)),
233292
- { maxOperations: 1 }
233293
- ));
233294
- let engine;
233295
- try {
233296
- const cwd = await owner.acquire(() => resolveVfsCwd(context.cwd, context.env.PWD, context.fs, owner.signal), () => {
233297
- });
233298
- engine = createEngine2({
233299
- ...binding,
233300
- environment: {
233301
- ...binding.environment,
233302
- cwd,
233303
- env: Object.freeze({ ...context.env })
233304
- },
233305
- limits: { ...binding.limits, inputBytes },
233306
- filesystem: createResourceIO({
233307
- ...binding.io,
233308
- cwd,
233309
- descriptors: {
233310
- ...binding.io?.descriptors,
233311
- 0: { source: context.stdin },
233312
- 1: { sink: standardOutput }
233351
+ function createCommandBindings(createEngine3, compatibilityDefaults = false) {
233352
+ function createSsconvertCommand2(options = {}) {
233353
+ const configured = { ...options };
233354
+ if (configured.replace !== void 0 && typeof configured.replace !== "boolean")
233355
+ throw new TypeError("ssconvert replace must be boolean");
233356
+ const binding = {
233357
+ ...configured,
233358
+ ...configured.io === void 0 ? {} : { io: Object.freeze({
233359
+ ...configured.io.descriptors === void 0 ? {} : { descriptors: Object.freeze(Object.fromEntries(
233360
+ Object.entries(configured.io.descriptors).map(([key, descriptor3]) => [key, Object.freeze({ ...descriptor3 })])
233361
+ )) },
233362
+ ...configured.io.adapters === void 0 ? {} : { adapters: Object.freeze({ ...configured.io.adapters }) },
233363
+ ...configured.io.transport === void 0 ? {} : { transport: Object.freeze({
233364
+ authorize: configured.io.transport.authorize.bind(configured.io.transport),
233365
+ request: configured.io.transport.request.bind(configured.io.transport),
233366
+ redirects: configured.io.transport.redirects
233367
+ }) }
233368
+ }) },
233369
+ ...configured.runtimeFunctions === void 0 ? {} : { runtimeFunctions: snapshotRuntimeFunctions(configured.runtimeFunctions) },
233370
+ ...configured.profile === void 0 ? {} : { profile: Object.freeze({
233371
+ ...configured.profile,
233372
+ ...configured.profile.groups === void 0 ? {} : { groups: Object.freeze({ ...configured.profile.groups }) },
233373
+ ...configured.profile.configurationRoots === void 0 ? {} : {
233374
+ configurationRoots: Object.freeze({ ...configured.profile.configurationRoots })
233375
+ }
233376
+ }) },
233377
+ codecs: Object.freeze([...configured.codecs ?? []]),
233378
+ ...configured.formats === void 0 ? {} : { formats: snapshotFormats(configured.formats) },
233379
+ limits: Object.freeze({ ...defaultSsconvertLimits, ...configured.limits }),
233380
+ environment: Object.freeze({
233381
+ locale: "C",
233382
+ timezone: "UTC",
233383
+ ...configured.environment,
233384
+ env: Object.freeze({ ...configured.environment?.env })
233385
+ })
233386
+ };
233387
+ const command = {
233388
+ name: "ssconvert",
233389
+ description: "Explicitly bound TypeScript spreadsheet conversion engine",
233390
+ async execute(context) {
233391
+ context.signal.throwIfAborted();
233392
+ const owner = createOutputOperation(context, { async write() {
233393
+ } });
233394
+ const inputBytes = Math.min(
233395
+ binding.limits.inputBytes,
233396
+ context.inputBudget?.maxBytes ?? Infinity
233397
+ );
233398
+ let stdout;
233399
+ const standardOutput = { async write(bytes) {
233400
+ stdout ??= owner.child(context.stdout);
233401
+ await stdout.output.write(bytes);
233402
+ } };
233403
+ let stderr;
233404
+ const standardError = { async write(bytes) {
233405
+ stderr ??= owner.child(context.stderr);
233406
+ await stderr.output.write(bytes);
233407
+ } };
233408
+ const openOutput = createVfsOutput(context.fs, async (path2, bytes, signal) => {
233409
+ await owner.acquire(() => writeFileOutput(
233410
+ context,
233411
+ bytes,
233412
+ async (data3) => {
233413
+ const capabilities = await context.fs.capabilitiesFor?.(path2, { signal }) ?? context.fs.capabilities;
233414
+ signal.throwIfAborted();
233415
+ if (context.fs.writeStream && capabilities.streamingWrite !== false)
233416
+ await context.fs.writeStream(path2, (async function* () {
233417
+ yield data3;
233418
+ })(), { signal });
233419
+ else await context.fs.writeFile(path2, data3, { signal });
233420
+ }
233421
+ ), () => {
233422
+ });
233423
+ }, (cleanup) => retainFileSystemCleanup(
233424
+ context.fs,
233425
+ (view2) => cleanup((path2) => view2.rm(path2)),
233426
+ { maxOperations: 1 }
233427
+ ));
233428
+ let engine;
233429
+ try {
233430
+ const cwd = await owner.acquire(() => resolveVfsCwd(context.cwd, context.env.PWD, context.fs, owner.signal), () => {
233431
+ });
233432
+ engine = createEngine3({
233433
+ ...binding,
233434
+ environment: {
233435
+ ...binding.environment,
233436
+ cwd,
233437
+ env: Object.freeze({ ...context.env })
233313
233438
  },
233314
- filesystem: {
233315
- openOutput,
233316
- async read(uri, signal) {
233317
- try {
233318
- const capabilities = await context.fs.capabilitiesFor?.(uri, { signal }) ?? context.fs.capabilities;
233319
- signal.throwIfAborted();
233320
- if (context.fs.readStream && capabilities.streamingRead !== false)
233321
- return context.fs.readStream(uri, { signal });
233322
- const bytes = await owner.acquire(
233323
- () => context.fs.readFile(uri, {
233324
- signal,
233325
- ...inputBytes === Infinity ? {} : { maxBytes: inputBytes }
233326
- }),
233327
- () => {
233328
- }
233329
- );
233330
- context.inputBudget?.check(bytes.byteLength);
233331
- return [bytes];
233332
- } catch (error2) {
233333
- signal.throwIfAborted();
233334
- throw error2;
233335
- }
233439
+ limits: { ...binding.limits, inputBytes },
233440
+ filesystem: createResourceIO({
233441
+ ...binding.io,
233442
+ cwd,
233443
+ descriptors: {
233444
+ ...binding.io?.descriptors,
233445
+ 0: { source: context.stdin },
233446
+ 1: { sink: standardOutput }
233336
233447
  },
233337
- async write(uri, bytes, signal) {
233338
- try {
233339
- await owner.acquire(
233340
- () => writeFileOutput(context, bytes, async (data3) => {
233341
- const capabilities = await context.fs.capabilitiesFor?.(uri, { signal }) ?? context.fs.capabilities;
233342
- signal.throwIfAborted();
233343
- if (context.fs.writeStream && capabilities.streamingWrite !== false)
233344
- await context.fs.writeStream(uri, (async function* () {
233345
- yield data3;
233346
- })(), { signal });
233347
- else await context.fs.writeFile(uri, data3, { signal });
233348
- }),
233349
- () => {
233350
- }
233351
- );
233352
- } catch (error2) {
233353
- signal.throwIfAborted();
233354
- throw error2;
233448
+ filesystem: {
233449
+ openOutput,
233450
+ async read(uri, signal) {
233451
+ try {
233452
+ const capabilities = await context.fs.capabilitiesFor?.(uri, { signal }) ?? context.fs.capabilities;
233453
+ signal.throwIfAborted();
233454
+ if (context.fs.readStream && capabilities.streamingRead !== false)
233455
+ return context.fs.readStream(uri, { signal });
233456
+ const bytes = await owner.acquire(
233457
+ () => context.fs.readFile(uri, {
233458
+ signal,
233459
+ ...inputBytes === Infinity ? {} : { maxBytes: inputBytes }
233460
+ }),
233461
+ () => {
233462
+ }
233463
+ );
233464
+ context.inputBudget?.check(bytes.byteLength);
233465
+ return [bytes];
233466
+ } catch (error2) {
233467
+ signal.throwIfAborted();
233468
+ throw error2;
233469
+ }
233470
+ },
233471
+ async write(uri, bytes, signal) {
233472
+ try {
233473
+ await owner.acquire(
233474
+ () => writeFileOutput(context, bytes, async (data3) => {
233475
+ const capabilities = await context.fs.capabilitiesFor?.(uri, { signal }) ?? context.fs.capabilities;
233476
+ signal.throwIfAborted();
233477
+ if (context.fs.writeStream && capabilities.streamingWrite !== false)
233478
+ await context.fs.writeStream(uri, (async function* () {
233479
+ yield data3;
233480
+ })(), { signal });
233481
+ else await context.fs.writeFile(uri, data3, { signal });
233482
+ }),
233483
+ () => {
233484
+ }
233485
+ );
233486
+ } catch (error2) {
233487
+ signal.throwIfAborted();
233488
+ throw error2;
233489
+ }
233355
233490
  }
233356
233491
  }
233492
+ })
233493
+ });
233494
+ const maximumArguments = binding.limits.argumentBytes ?? Infinity;
233495
+ const values2 = context.argumentValues?.values ?? context.args;
233496
+ let argumentBytes = 0;
233497
+ let refusal;
233498
+ if (values2.length > maximumArguments) refusal = "ssconvert arguments limit exceeded";
233499
+ for (const value3 of values2) {
233500
+ if (refusal) break;
233501
+ if (typeof value3 === "string" && value3.length > maximumArguments - argumentBytes) {
233502
+ refusal = "ssconvert argument bytes limit exceeded";
233503
+ break;
233357
233504
  }
233358
- })
233359
- });
233360
- const maximumArguments = binding.limits.argumentBytes ?? Infinity;
233361
- const values2 = context.argumentValues?.values ?? context.args;
233362
- let argumentBytes = 0;
233363
- let refusal;
233364
- if (values2.length > maximumArguments) refusal = "ssconvert arguments limit exceeded";
233365
- for (const value3 of values2) {
233366
- if (refusal) break;
233367
- if (typeof value3 === "string" && value3.length > maximumArguments - argumentBytes) {
233368
- refusal = "ssconvert argument bytes limit exceeded";
233369
- break;
233505
+ argumentBytes += shellValueByteLength(value3);
233506
+ if (argumentBytes > maximumArguments) refusal = "ssconvert argument bytes limit exceeded";
233370
233507
  }
233371
- argumentBytes += shellValueByteLength(value3);
233372
- if (argumentBytes > maximumArguments) refusal = "ssconvert argument bytes limit exceeded";
233373
- }
233374
- if (refusal) {
233375
- await standardError.write(new TextEncoder().encode(`${refusal}
233508
+ if (refusal) {
233509
+ await standardError.write(new TextEncoder().encode(`${refusal}
233376
233510
  `));
233377
- owner.signal.throwIfAborted();
233378
- return { exitCode: 1 };
233379
- }
233380
- const carrier = getCommandArguments(context);
233381
- return await runCommand(
233382
- carrier.args.map((_, index2) => carrier.bytes(index2)),
233383
- engine,
233384
- {
233385
- signal: owner.signal,
233386
- ...context.stdinIsDefault === void 0 ? {} : { stdinIsDefault: context.stdinIsDefault },
233387
- stdout: standardOutput,
233388
- stderr: standardError,
233389
- registerCleanup: (cleanup) => owner.registerCleanup(cleanup)
233390
- },
233391
- binding.profile
233392
- );
233393
- } finally {
233394
- try {
233395
- await engine?.dispose();
233511
+ owner.signal.throwIfAborted();
233512
+ return { exitCode: 1 };
233513
+ }
233514
+ const carrier = getCommandArguments(context);
233515
+ return await runCommand(
233516
+ carrier.args.map((_, index2) => carrier.bytes(index2)),
233517
+ engine,
233518
+ {
233519
+ signal: owner.signal,
233520
+ ...context.stdinIsDefault === void 0 ? {} : { stdinIsDefault: context.stdinIsDefault },
233521
+ stdout: standardOutput,
233522
+ stderr: standardError,
233523
+ registerCleanup: (cleanup) => owner.registerCleanup(cleanup)
233524
+ },
233525
+ binding.profile
233526
+ );
233396
233527
  } finally {
233397
- await owner.close();
233528
+ try {
233529
+ await engine?.dispose();
233530
+ } finally {
233531
+ await owner.close();
233532
+ }
233398
233533
  }
233399
233534
  }
233535
+ };
233536
+ if (compatibilityDefaults && Object.entries(configured).every(([key, value3]) => key === "replace" || value3 === void 0)) {
233537
+ builtInDirectContextExecutors.add(command.execute);
233400
233538
  }
233401
- };
233402
- if (Object.entries(configured).every(([key, value3]) => key === "replace" || value3 === void 0)) {
233403
- builtInDirectContextExecutors.add(command.execute);
233539
+ return command;
233404
233540
  }
233405
- return command;
233406
- }
233407
- function ssconvertCommands(options = {}) {
233408
- const commands = createSsconvertCommands(options), replace = options.replace ?? false;
233409
- return {
233410
- name: "ssconvert-commands",
233411
- setup(host) {
233412
- if (!replace && commands.some((command) => host.commands.has(command.name)))
233413
- throw new Error("Command already registered: ssconvert");
233414
- for (const command of commands) host.commands.register(command, { replace });
233415
- }
233416
- };
233417
- }
233418
- function createSsconvertCommands(options = {}) {
233419
- return Object.freeze([createSsconvertCommand(options)]);
233541
+ function ssconvertCommands2(options = {}) {
233542
+ const commands = createSsconvertCommands2(options), replace = options.replace ?? false;
233543
+ return {
233544
+ name: "ssconvert-commands",
233545
+ setup(host) {
233546
+ if (!replace && commands.some((command) => host.commands.has(command.name)))
233547
+ throw new Error("Command already registered: ssconvert");
233548
+ for (const command of commands) host.commands.register(command, { replace });
233549
+ }
233550
+ };
233551
+ }
233552
+ function createSsconvertCommands2(options = {}) {
233553
+ return Object.freeze([createSsconvertCommand2(options)]);
233554
+ }
233555
+ return { createSsconvertCommand: createSsconvertCommand2, createSsconvertCommands: createSsconvertCommands2, ssconvertCommands: ssconvertCommands2 };
233420
233556
  }
233557
+ var bindings = createCommandBindings(createEngine2, true);
233558
+ var createSsconvertCommand = bindings.createSsconvertCommand;
233559
+ var createSsconvertCommands = bindings.createSsconvertCommands;
233560
+ var ssconvertCommands = bindings.ssconvertCommands;
233421
233561
  function parseSimpleSeparatedRows(text2, sep) {
233422
233562
  const rows = [];
233423
233563
  let row = [];