@poe-platform/safe-bash 0.1.744 → 0.1.746

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 (70) hide show
  1. package/README.md +10 -1
  2. package/dist/image-ast/browser/sharp.d.ts +1 -1
  3. package/dist/image-ast/index.js +133 -35
  4. package/dist/image-ast/sharp.d.ts +1 -1
  5. package/dist/safe-bash/chunks/{chunk-2CO4WCMK.js → chunk-3ZNXN3XO.js} +434 -245
  6. package/dist/safe-bash/chunks/{chunk-2F7Q532M.js → chunk-4GK4FAT6.js} +3 -3
  7. package/dist/safe-bash/chunks/{chunk-WCNFCN2G.js → chunk-BS6QFRNX.js} +2 -2
  8. package/dist/safe-bash/chunks/{chunk-IZZ7KX4E.js → chunk-JCXAGOEK.js} +40 -3
  9. package/dist/safe-bash/chunks/{chunk-WN7FYUWU.js → chunk-MC2KZY3D.js} +26 -13
  10. package/dist/safe-bash/chunks/{chunk-I3DOFJSJ.js → chunk-MUWJPSGN.js} +2 -2
  11. package/dist/safe-bash/chunks/{chunk-7RP6WOWK.js → chunk-OF2PDE3W.js} +2 -2
  12. package/dist/safe-bash/chunks/{pdf-renderer-3TVUXNBT.js → pdf-renderer-4APIM7F7.js} +2 -2
  13. package/dist/safe-bash/chunks/{src-5VZS2ZKB.js → src-T2WAWJXF.js} +2 -2
  14. package/dist/safe-bash/command-chunks/{chunk-DRCPJVZF.js → chunk-44N2IRVP.js} +17 -5
  15. package/dist/safe-bash/command-chunks/{chunk-LYKC7WJB.js → chunk-6742OVAC.js} +37 -3
  16. package/dist/safe-bash/command-chunks/{chunk-BMBXSLVX.js → chunk-6QU5OLPJ.js} +2 -2
  17. package/dist/safe-bash/command-chunks/{chunk-YHANNN7I.js → chunk-S3BO2NJT.js} +7 -0
  18. package/dist/safe-bash/commands/basic.d.ts +2 -0
  19. package/dist/safe-bash/commands/basic.js +236 -9
  20. package/dist/safe-bash/commands/pr/index.browser.js +1 -1
  21. package/dist/safe-bash/commands/streams.js +9 -56
  22. package/dist/safe-bash/commands/table-text/index.js +5 -1
  23. package/dist/safe-bash/commands/text.js +13 -2
  24. package/dist/safe-bash/commands/time-env/shared.js +2 -2
  25. package/dist/safe-bash/commands/time-env/sleep.js +6 -4
  26. package/dist/safe-bash/commands/timeout/index.d.ts +7 -0
  27. package/dist/safe-bash/commands/timeout/index.js +52 -32
  28. package/dist/safe-bash/commands/timeout/scheduler.js +7 -6
  29. package/dist/safe-bash/core.browser.js +3475 -883
  30. package/dist/safe-bash/opt-in/commands/shuf/random.js +2 -3
  31. package/dist/safe-bash/opt-in/shell/extensions/read/index.js +1 -2
  32. package/dist/safe-bash/opt-in/shell/extensions/trap/index.d.ts +1 -2
  33. package/dist/safe-bash/opt-in/shell/extensions/trap/index.js +1 -8
  34. package/dist/safe-bash/playwright/adapter.d.ts +2 -0
  35. package/dist/safe-bash/playwright/capability-events.d.ts +7 -0
  36. package/dist/safe-bash/playwright/capability-events.js +11 -3
  37. package/dist/safe-bash/playwright/controller.d.ts +14 -0
  38. package/dist/safe-bash/playwright/controller.js +36 -8
  39. package/dist/safe-bash/playwright/index.d.ts +1 -0
  40. package/dist/safe-bash/playwright/index.js +1 -0
  41. package/dist/safe-bash/playwright/private-target-transport.d.ts +1 -0
  42. package/dist/safe-bash/playwright/private-target-transport.js +21 -21
  43. package/dist/safe-bash/shell/runtime.d.ts +34 -2
  44. package/dist/safe-bash/shell/runtime.js +4107 -947
  45. package/dist/safe-bash/shell/sync-jq-expression.d.ts +6 -0
  46. package/dist/safe-bash/shell/sync-jq-expression.js +46 -0
  47. package/dist/safe-bash-command-cal/index.js +32 -12
  48. package/dist/safe-bash-command-hostname/index.js +22 -7
  49. package/dist/safe-bash-command-id/index.js +28 -9
  50. package/dist/safe-bash-command-pandoc/command.js +1 -1
  51. package/dist/safe-bash-command-pandoc/index.js +1 -1
  52. package/dist/safe-bash-command-ssconvert/command.d.ts +2 -2
  53. package/dist/safe-bash-command-ssconvert/contracts.d.ts +4 -0
  54. package/dist/safe-bash-command-ssconvert/engine.d.ts +2 -2
  55. package/dist/safe-bash-command-ssconvert/index.js +421 -237
  56. package/dist/safe-bash-command-whoami/index.js +26 -12
  57. package/dist/safe-bash-command-wkhtmltopdf/index.js +24 -11
  58. package/dist/safe-bash-command-wkhtmltopdf/limits.d.ts +1 -1
  59. package/dist/safe-bash-command-wkhtmltopdf/resources.d.ts +1 -1
  60. package/dist/safe-bash-query-engine/index.js +3 -3
  61. package/dist/safe-bash-query-engine/interpreter.js +1 -1
  62. package/dist/safe-bash-query-engine/parser.js +1 -1
  63. package/dist/safe-bash-query-engine/query-core.js +3 -3
  64. package/dist/safe-playwright-cloudflare/browser-private-transport.js +8 -13
  65. package/dist/safe-playwright-cloudflare/browser-storage-control.js +13 -4
  66. package/dist/safe-playwright-cloudflare/browser-trace-archive.js +1 -1
  67. package/package.json +18 -14
  68. package/dist/image-ast/streams/node.d.ts +0 -10
  69. package/dist/image-ast/streams/node.js +0 -5
  70. package/dist/image-ast/streams/web.js +0 -94
@@ -6,10 +6,10 @@ import {
6
6
  // packages/safe-bash-command-ssconvert/dist/index.js
7
7
  init_buffer();
8
8
  import { parseXmlSteps } from "@poe-platform/safe-fs/xml";
9
- import { parseXmlSteps as parseXmlSteps2, XmlLimitError } from "@poe-platform/safe-fs/xml";
10
- import { parseXmlSteps as parseXmlSteps3, XmlLimitError as XmlLimitError2 } from "@poe-platform/safe-fs/xml";
9
+ import { parseXmlSteps as parseXmlSteps2 } from "@poe-platform/safe-fs/xml";
10
+ import { parseXmlSteps as parseXmlSteps3, XmlLimitError } from "@poe-platform/safe-fs/xml";
11
+ import { parseXmlSteps as parseXmlSteps4, XmlLimitError as XmlLimitError2 } from "@poe-platform/safe-fs/xml";
11
12
  import { parseXmlSteps as parseXmlSteps5, XmlLimitError as XmlLimitError3 } from "@poe-platform/safe-fs/xml";
12
- import { parseXmlSteps as parseXmlSteps4 } from "@poe-platform/safe-fs/xml";
13
13
  import { parseXmlSteps as parseXmlSteps6, XmlLimitError as XmlLimitError4 } from "@poe-platform/safe-fs/xml";
14
14
  import { retainFileSystemCleanup } from "@poe-platform/safe-fs/core";
15
15
  import {
@@ -76424,9 +76424,9 @@ function parseExpression(source, options) {
76424
76424
  }
76425
76425
  let sheetRelative;
76426
76426
  const readSheet = () => {
76427
+ if (grammar3.bracketReferences && grammar3.absoluteSheetReferences) sheetRelative = source[offset] !== "$";
76428
+ if (grammar3.absoluteSheetReferences && source[offset] === "$") offset++;
76427
76429
  if (grammar3.bracketReferences) {
76428
- if (grammar3.absoluteSheetReferences) sheetRelative = source[offset] !== "$";
76429
- if (grammar3.absoluteSheetReferences && source[offset] === "$") offset++;
76430
76430
  if (source[offset] === "'") return quoted("'", grammar3.stringEscape);
76431
76431
  const begin2 = offset;
76432
76432
  while (offset < source.length && source[offset] !== grammar3.sheetSeparator && !" []:' \r\n".includes(source[offset])) offset++;
@@ -76434,7 +76434,6 @@ function parseExpression(source, options) {
76434
76434
  }
76435
76435
  if (grammar3.unquotedSheets) {
76436
76436
  const begin2 = offset;
76437
- if (grammar3.absoluteSheetReferences && source[offset] === "$") offset++;
76438
76437
  while (letter(source[offset]) || digit(source[offset])) offset++;
76439
76438
  return source.slice(begin2, offset);
76440
76439
  }
@@ -76458,7 +76457,6 @@ function parseExpression(source, options) {
76458
76457
  return {};
76459
76458
  }
76460
76459
  offset++;
76461
- if (grammar3.absoluteSheetReferences && !grammar3.bracketReferences && sheet.startsWith("$")) sheet = sheet.slice(1);
76462
76460
  if (sheet.startsWith("[")) {
76463
76461
  const close = sheet.indexOf("]");
76464
76462
  if (close >= 0) {
@@ -78281,6 +78279,371 @@ var chartDataTypes = Object.freeze(Object.fromEntries(Object.entries({
78281
78279
  GODataVectorStr: { storage: "literal", dimensions: 1 },
78282
78280
  GODataMatrixVal: { storage: "literal", dimensions: 2 }
78283
78281
  }).map(([name, descriptor3]) => [name, Object.freeze(descriptor3)])));
78282
+ var urn = "urn:oasis:names:tc:opendocument:xmlns:";
78283
+ var odfEncryptionNamespace = "urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0";
78284
+ var odfNamespaces = {
78285
+ xml: "http://www.w3.org/XML/1998/namespace",
78286
+ office: urn + "office:1.0",
78287
+ style: urn + "style:1.0",
78288
+ text: urn + "text:1.0",
78289
+ table: urn + "table:1.0",
78290
+ draw: urn + "drawing:1.0",
78291
+ fo: urn + "xsl-fo-compatible:1.0",
78292
+ xlink: "http://www.w3.org/1999/xlink",
78293
+ dc: "http://purl.org/dc/elements/1.1/",
78294
+ meta: urn + "meta:1.0",
78295
+ number: urn + "datastyle:1.0",
78296
+ svg: urn + "svg-compatible:1.0",
78297
+ chart: urn + "chart:1.0",
78298
+ config: urn + "config:1.0",
78299
+ form: urn + "form:1.0",
78300
+ script: urn + "script:1.0",
78301
+ of: urn + "of:1.2",
78302
+ manifest: urn + "manifest:1.0",
78303
+ gnm: "http://www.gnumeric.org/odf-extension/1.0",
78304
+ calcext: "urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0"
78305
+ };
78306
+ function odfObject(value3) {
78307
+ return value3 !== null && typeof value3 === "object" && !Array.isArray(value3) ? value3 : void 0;
78308
+ }
78309
+ function odfAttributes(value3, namespace5) {
78310
+ const source = odfObject(value3)?.attributes;
78311
+ if (Array.isArray(source)) return Object.fromEntries(source.flatMap((a3) => {
78312
+ const v = odfObject(a3);
78313
+ return typeof v?.name === "string" && typeof v.value === "string" && (namespace5 === void 0 || v.namespace === namespace5) ? [[v.name, v.value]] : [];
78314
+ }));
78315
+ if (namespace5 !== void 0) return {};
78316
+ return Object.fromEntries(Object.entries(odfObject(source) ?? {}).filter((entry2) => typeof entry2[1] === "string"));
78317
+ }
78318
+ function odfChildren(value3) {
78319
+ const source = odfObject(value3)?.children;
78320
+ return Array.isArray(source) ? source : [];
78321
+ }
78322
+ function createOdfXml(context, extended) {
78323
+ let work = 0, nodes = 0;
78324
+ const encoder3 = new TextEncoder(), names2 = /* @__PURE__ */ new Set();
78325
+ const declarations = {
78326
+ ...Object.fromEntries(Object.entries(odfNamespaces).map(([prefix, uri]) => ["xmlns:" + prefix, uri])),
78327
+ "xmlns:loext": odfEncryptionNamespace
78328
+ };
78329
+ function charge(amount = 1) {
78330
+ context.signal.throwIfAborted();
78331
+ if (!Number.isSafeInteger(amount) || amount < 0 || amount > (context.limits.workbookWork ?? Infinity) - work)
78332
+ throw new SsconvertError("resource-limit", "ssconvert OpenDocument work limit exceeded");
78333
+ work += amount;
78334
+ }
78335
+ function name(value3) {
78336
+ charge(value3.length);
78337
+ if (names2.has(value3)) return;
78338
+ try {
78339
+ const parser = parseXmlSteps(`<${value3} ${Object.entries(declarations).map(([k, v]) => `${k}="${v}"`).join(" ")}/>`, { maxNodes: 1, maxAttributes: 100 });
78340
+ let step = parser.next();
78341
+ while (!step.done) step = parser.next();
78342
+ if (step.value.name !== value3 || step.value.children.length) throw new Error("name");
78343
+ } catch {
78344
+ throw new SsconvertError("invalid-request", "Invalid OpenDocument XML name");
78345
+ }
78346
+ names2.add(value3);
78347
+ }
78348
+ function escape3(value3) {
78349
+ charge(value3.length);
78350
+ let result2 = "";
78351
+ for (const c4 of value3) {
78352
+ const code = c4.codePointAt(0);
78353
+ if (code < 32 && !" \n\r".includes(c4) || code === 65534 || code === 65535 || code >= 55296 && code <= 57343)
78354
+ throw new SsconvertError("unsupported-feature", "Unsupported ssconvert feature: non-XML OpenDocument character");
78355
+ result2 += c4 === "&" ? "&amp;" : c4 === "<" ? "&lt;" : c4 === ">" ? "&gt;" : c4 === '"' ? "&quot;" : c4 === "\r" ? "&#13;" : c4 === "\n" ? "&#10;" : c4 === " " ? "&#9;" : c4;
78356
+ }
78357
+ return result2;
78358
+ }
78359
+ function element2(tag, attributes4 = {}, content2 = "") {
78360
+ charge();
78361
+ if (++nodes > (context.limits.workbookNodes ?? Infinity))
78362
+ throw new SsconvertError("resource-limit", "ssconvert OpenDocument XML nodes limit exceeded");
78363
+ name(tag);
78364
+ let result2 = "<" + tag;
78365
+ for (const [key, value3] of Object.entries(attributes4)) if (value3 !== void 0) {
78366
+ if (!key.startsWith("xmlns:")) name(key);
78367
+ result2 += ` ${key}="${escape3(String(value3))}"`;
78368
+ }
78369
+ result2 += content2 ? ">" + content2 + "</" + tag + ">" : "/>";
78370
+ if (result2.length > context.limits.outputBytes || encoder3.encode(result2).length > context.limits.outputBytes)
78371
+ throw new SsconvertError("resource-limit", "ssconvert OpenDocument output bytes limit exceeded");
78372
+ return result2;
78373
+ }
78374
+ function text2(value3) {
78375
+ charge(value3.length);
78376
+ let result2 = "", plain = "";
78377
+ function flush() {
78378
+ result2 += escape3(plain);
78379
+ plain = "";
78380
+ }
78381
+ for (let i = 0; i < value3.length; i++) {
78382
+ const c4 = value3[i];
78383
+ if (c4 === " ") {
78384
+ flush();
78385
+ let count = 1;
78386
+ while (value3[i + 1] === " ") {
78387
+ i++;
78388
+ count++;
78389
+ }
78390
+ result2 += element2("text:s", count > 1 ? { "text:c": count } : {});
78391
+ } else if (c4 === " " || c4 === "\n") {
78392
+ flush();
78393
+ result2 += element2(c4 === " " ? "text:tab" : "text:line-break");
78394
+ } else plain += c4;
78395
+ }
78396
+ flush();
78397
+ return result2;
78398
+ }
78399
+ const active = /* @__PURE__ */ new Set();
78400
+ function retained2(value3, depth = 0, hyperlink, hyperlinkContent = false) {
78401
+ charge();
78402
+ const v = odfObject(value3);
78403
+ if (!v || typeof v.name !== "string" || typeof v.namespace !== "string") return "";
78404
+ if (depth > (context.limits.xmlDepth ?? Infinity)) throw new SsconvertError("resource-limit", "ssconvert OpenDocument metadata depth limit exceeded");
78405
+ if (active.has(v)) throw new SsconvertError("invalid-request", "Invalid cyclic OpenDocument metadata");
78406
+ const prefix = Object.entries(odfNamespaces).find(([, uri]) => uri === v.namespace)?.[0];
78407
+ if (!prefix || !extended && ["gnm", "calcext"].includes(prefix)) return "";
78408
+ active.add(v);
78409
+ try {
78410
+ const attributes4 = {};
78411
+ if (Array.isArray(v.attributes)) for (const a3 of v.attributes) {
78412
+ charge();
78413
+ const attribute5 = odfObject(a3);
78414
+ if (typeof attribute5?.name !== "string" || typeof attribute5.value !== "string" || typeof attribute5.namespace !== "string") continue;
78415
+ const p2 = Object.entries(odfNamespaces).find(([, uri]) => uri === attribute5.namespace)?.[0];
78416
+ if (attribute5.namespace && (!p2 || !extended && ["gnm", "calcext"].includes(p2))) continue;
78417
+ attributes4[(p2 ? p2 + ":" : "") + attribute5.name] = attribute5.value;
78418
+ }
78419
+ if (prefix === "text" && v.name === "a" && attributes4["xlink:href"] !== void 0 && hyperlink)
78420
+ attributes4["xlink:href"] = hyperlink(attributes4["xlink:href"]);
78421
+ const children7 = odfChildren(v);
78422
+ const childHyperlinkContent = Boolean(hyperlink) && prefix === "text" && v.name === "a" && attributes4["xlink:href"] !== void 0;
78423
+ const content2 = Array.isArray(v.content) ? v.content.map((c4) => {
78424
+ charge();
78425
+ const item = odfObject(c4);
78426
+ if (item?.kind === "text" && typeof item.text === "string") return escape3(item.text);
78427
+ if (item?.kind !== "element") return "";
78428
+ if (item.index === void 0) return retained2(item.value, depth + 1, hyperlink, childHyperlinkContent);
78429
+ if (typeof item.index !== "number" || !Number.isSafeInteger(item.index) || item.index < 0 || item.index >= children7.length)
78430
+ throw new SsconvertError("invalid-request", "Invalid OpenDocument metadata child index");
78431
+ return retained2(children7[item.index], depth + 1, hyperlink, childHyperlinkContent);
78432
+ }).join("") : (typeof v.text === "string" ? escape3(v.text) : "") + children7.map((c4) => retained2(c4, depth + 1, hyperlink, childHyperlinkContent)).join("");
78433
+ if (hyperlinkContent && prefix === "text" && !content2 && !children7.length) {
78434
+ if (v.name === "s" && Object.keys(attributes4).every((key) => key === "text:c")) {
78435
+ const count = Number(attributes4["text:c"] ?? "1");
78436
+ if (!Number.isSafeInteger(count) || count < 0) throw new SsconvertError("invalid-request", "Invalid OpenDocument whitespace count");
78437
+ if (count > context.limits.outputBytes) throw new SsconvertError("resource-limit", "ssconvert OpenDocument output bytes limit exceeded");
78438
+ charge(count);
78439
+ return " ".repeat(count);
78440
+ }
78441
+ if (!Object.keys(attributes4).length && (v.name === "tab" || v.name === "line-break"))
78442
+ return escape3(v.name === "tab" ? " " : "\n");
78443
+ }
78444
+ return element2(prefix + ":" + v.name, attributes4, content2);
78445
+ } finally {
78446
+ active.delete(v);
78447
+ }
78448
+ }
78449
+ function document6(tag, body) {
78450
+ return '<?xml version="1.0" encoding="UTF-8"?>\n' + element2(tag, { ...declarations, "xmlns:loext": void 0, "office:version": "1.2" }, body);
78451
+ }
78452
+ return { element: element2, escape: escape3, text: text2, retained: retained2, document: document6, charge };
78453
+ }
78454
+ var linkGrammar = { ...excelGrammar, id: "odf-hyperlink", sheetSeparator: ".", absoluteSheetReferences: true };
78455
+ function decodeFragment(source, charge) {
78456
+ let result2 = "";
78457
+ for (let at = 0; at < source.length; ) {
78458
+ charge();
78459
+ const high = "0123456789abcdef".indexOf(source[at + 1]?.toLowerCase() ?? " ");
78460
+ const low = "0123456789abcdef".indexOf(source[at + 2]?.toLowerCase() ?? " ");
78461
+ if (source[at] !== "%" || high < 0 || low < 0) {
78462
+ result2 += source[at++];
78463
+ continue;
78464
+ }
78465
+ const octet = high * 16 + low;
78466
+ const length = octet >= 192 && octet <= 223 ? 6 : octet >= 224 && octet <= 239 ? 9 : octet >= 240 && octet <= 244 ? 12 : 3;
78467
+ const encoded2 = source.slice(at, at + length);
78468
+ try {
78469
+ result2 += decodeURIComponent(encoded2);
78470
+ at += length;
78471
+ } catch {
78472
+ result2 += source.slice(at, at + 3).toUpperCase();
78473
+ at += 3;
78474
+ }
78475
+ }
78476
+ return result2;
78477
+ }
78478
+ function encodeFragment(source) {
78479
+ return "#" + encodeURI(source).split("#").join("%23").split("?").join("%3F");
78480
+ }
78481
+ function translateOdfHyperlink(source, direction, charge, sheetNames = []) {
78482
+ charge(source.length);
78483
+ if (direction === "normalize" && !source.startsWith("#")) return source;
78484
+ function findSheet(name) {
78485
+ const folded = foldSheetName(name);
78486
+ return sheetNames.find((candidate) => {
78487
+ charge(candidate.length);
78488
+ return foldSheetName(candidate) === folded;
78489
+ });
78490
+ }
78491
+ let target = direction !== "export" && source.startsWith("#") ? source.slice(1) : source;
78492
+ if (direction !== "export") {
78493
+ target = decodeFragment(target, charge);
78494
+ const separator2 = target.indexOf(" (");
78495
+ if (separator2 > 0 && target.endsWith(")")) {
78496
+ const name = target.slice(0, separator2), sheet = findSheet(target.slice(separator2 + 2, -1));
78497
+ if (sheet !== void 0) {
78498
+ const qualified = quoteNativeSheet(sheet) + "!" + name;
78499
+ const parsed2 = parseExpression("=" + qualified, { position: { sheet, row: 0, column: 0 }, onWork: charge });
78500
+ if (parsed2.ok && parsed2.document.root.kind === "name" && parsed2.document.root.name === name && parsed2.document.root.sheet === sheet)
78501
+ return direction === "import" ? qualified : encodeFragment(target);
78502
+ }
78503
+ }
78504
+ }
78505
+ const parsed = parseExpression("=" + target, {
78506
+ grammar: direction !== "export" ? linkGrammar : gnumericGrammar,
78507
+ position: { sheet: "", row: 0, column: 0 },
78508
+ onWork: charge
78509
+ });
78510
+ if (parsed.ok) {
78511
+ const node3 = parsed.document.root;
78512
+ if (node3.kind === "name" && node3.workbook === void 0 || node3.kind === "reference" && !node3.label && node3.first.workbook === void 0 && node3.last?.workbook === void 0) {
78513
+ const sheet = direction !== "import" && node3.kind === "name" && node3.sheet !== void 0 ? findSheet(node3.sheet) : void 0;
78514
+ if (sheet !== void 0 && node3.kind === "name") return encodeFragment(node3.name + " (" + sheet + ")");
78515
+ if (direction !== "normalize") target = serializeExpression(parsed.document, direction === "import" ? { ...gnumericGrammar, quoteSheetName: quoteNativeSheet } : linkGrammar, false, true).slice(1);
78516
+ }
78517
+ }
78518
+ return direction === "import" ? target : direction === "normalize" ? source : encodeFragment(target);
78519
+ }
78520
+ function rewriteWorkbookHyperlinks(book, names2, context) {
78521
+ let work = 0;
78522
+ const maximum = context.limits.workbookWork ?? context.limits.inputBytes + context.limits.cells * 32;
78523
+ function charge(amount = 1) {
78524
+ context.signal.throwIfAborted();
78525
+ if (amount > maximum - work) throw new SsconvertError("resource-limit", "ssconvert hyperlink work limit exceeded");
78526
+ work += amount;
78527
+ }
78528
+ const sheets = [...book.sheets, ...book.detachedSheets ?? []].map((sheet2) => sheet2.name);
78529
+ const changes = new Map(sheets.flatMap((name) => {
78530
+ charge(name.length);
78531
+ const next = names2.get(foldSheetName(name));
78532
+ return next === void 0 || next === name ? [] : [[foldSheetName(name), next]];
78533
+ }));
78534
+ if (!changes.size) return book;
78535
+ const renamedSheets = sheets.map((name) => names2.get(foldSheetName(name)) ?? name);
78536
+ function target(source, odf) {
78537
+ charge(source.length);
78538
+ if (odf && !source.startsWith("#")) return source;
78539
+ const native = odf ? translateOdfHyperlink(source, "import", charge, sheets) : source;
78540
+ const parsed = parseExpression("=" + native, { position: { sheet: "", row: 0, column: 0 }, onWork: charge, signal: context.signal });
78541
+ if (!parsed.ok) return source;
78542
+ const node3 = parsed.document.root;
78543
+ const spellings = node3.kind === "name" && node3.workbook === void 0 ? [node3.sheet] : node3.kind === "reference" && !node3.label && node3.first.workbook === void 0 && node3.last?.workbook === void 0 ? [node3.first.sheet, node3.last?.sheet] : [];
78544
+ const replacements = /* @__PURE__ */ new Map();
78545
+ for (const spelling of spellings) if (spelling !== void 0) {
78546
+ charge(spelling.length);
78547
+ const name = changes.get(foldSheetName(spelling));
78548
+ if (name !== void 0 && name !== spelling) replacements.set(spelling, name);
78549
+ }
78550
+ if (!replacements.size) return source;
78551
+ const rewritten = rewriteReferences(parsed.document, { sheets: replacements, signal: context.signal }).slice(1);
78552
+ charge(rewritten.length);
78553
+ return odf ? translateOdfHyperlink(rewritten, "export", charge, renamedSheets) : rewritten;
78554
+ }
78555
+ function xml2(value3, odf, root, implicitNamespace = false) {
78556
+ let result2 = value3;
78557
+ const pending = [{ value: value3, role: root, depth: 0, assign: (next) => {
78558
+ result2 = next;
78559
+ } }];
78560
+ while (pending.length) {
78561
+ const item = pending.pop();
78562
+ charge();
78563
+ const node3 = odfObject(item.value);
78564
+ if (!node3 || typeof node3.name !== "string" || node3.name !== item.role) continue;
78565
+ const validNamespace = odf ? node3.namespace === odfNamespaces.text || node3.namespace === "http://openoffice.org/2000/text" : node3.namespace === "http://www.gnumeric.org/v10.dtd" || implicitNamespace && (node3.namespace === void 0 || node3.namespace === "");
78566
+ if (!validNamespace) continue;
78567
+ if (item.depth > (context.limits.xmlDepth ?? Infinity)) throw new SsconvertError("resource-limit", "ssconvert hyperlink depth limit exceeded");
78568
+ const updated = { ...node3 };
78569
+ item.assign(updated);
78570
+ const attributes4 = odfObject(node3.attributes);
78571
+ const list = Array.isArray(node3.attributes) ? node3.attributes : [];
78572
+ const field = (name, namespace5) => {
78573
+ if (attributes4 && !namespace5 && typeof attributes4[name] === "string") return attributes4[name];
78574
+ for (const value4 of list) {
78575
+ charge();
78576
+ const attribute5 = odfObject(value4);
78577
+ if (attribute5?.name === name && attribute5.namespace === namespace5 && typeof attribute5.value === "string") return attribute5.value;
78578
+ }
78579
+ return void 0;
78580
+ };
78581
+ const link = odf ? node3.name === "a" : node3.name === "HyperLink" && field("type", "") === "GnmHLinkCurWB";
78582
+ if (link) {
78583
+ const name = odf ? "href" : "target", namespace5 = odf ? odfNamespaces.xlink : "";
78584
+ const source = field(name, namespace5);
78585
+ if (source !== void 0) {
78586
+ const rewritten = target(source, odf);
78587
+ updated.attributes = attributes4 ? { ...attributes4, [name]: rewritten } : list.map((value4) => {
78588
+ charge();
78589
+ const attribute5 = odfObject(value4);
78590
+ return attribute5?.name === name && attribute5.namespace === namespace5 ? { ...attribute5, value: rewritten } : value4;
78591
+ });
78592
+ }
78593
+ }
78594
+ const childRole = odf ? void 0 : node3.name === "Styles" ? "StyleRegion" : node3.name === "StyleRegion" ? "Style" : node3.name === "Style" ? "HyperLink" : "";
78595
+ const enqueue = (value4, assign) => {
78596
+ charge();
78597
+ const child7 = odfObject(value4);
78598
+ if (typeof child7?.name === "string") pending.push({ value: value4, role: childRole ?? child7.name, depth: item.depth + 1, assign });
78599
+ };
78600
+ if (Array.isArray(node3.children)) {
78601
+ const children7 = [...node3.children];
78602
+ updated.children = children7;
78603
+ children7.forEach((child7, index2) => enqueue(child7, (next) => {
78604
+ children7[index2] = next;
78605
+ }));
78606
+ }
78607
+ if (odf && Array.isArray(node3.content)) {
78608
+ const content2 = [...node3.content];
78609
+ updated.content = content2;
78610
+ content2.forEach((value4, index2) => {
78611
+ charge();
78612
+ const entry2 = odfObject(value4);
78613
+ if (entry2?.kind === "element" && entry2.index === void 0 && entry2.value !== void 0)
78614
+ enqueue(entry2.value, (next) => {
78615
+ content2[index2] = { ...entry2, value: next };
78616
+ });
78617
+ });
78618
+ }
78619
+ }
78620
+ return result2;
78621
+ }
78622
+ const style2 = (value3) => {
78623
+ charge();
78624
+ return value3?.gnumeric === void 0 ? value3 : { ...value3, gnumeric: xml2(value3.gnumeric, false, "Style", true) };
78625
+ };
78626
+ const sheet = (value3) => ({
78627
+ ...value3,
78628
+ cells: value3.cells.map((cell) => {
78629
+ charge();
78630
+ return { ...cell, ...cell.style ? { style: style2(cell.style) } : {} };
78631
+ }),
78632
+ ...value3.rows ? { rows: value3.rows.map((row) => ({ ...row, ...row.style ? { style: style2(row.style) } : {} })) } : {},
78633
+ ...value3.columns ? { columns: value3.columns.map((column) => ({ ...column, ...column.style ? { style: style2(column.style) } : {} })) } : {},
78634
+ ...value3.unsupportedRecords ? { unsupportedRecords: value3.unsupportedRecords.map((record7) => {
78635
+ charge();
78636
+ if (record7.disposition !== "retained" || record7.data === void 0) return record7;
78637
+ if (record7.source === "Gnumeric_XmlIO:sax" && record7.kind === "Styles") return { ...record7, data: xml2(record7.data, false, "Styles") };
78638
+ if (record7.kind === "p" && (record7.source === "Gnumeric_OpenCalc:openoffice" || record7.source === "odf:cell-content")) {
78639
+ const data3 = odfObject(record7.data);
78640
+ return data3?.xml === void 0 ? { ...record7, data: xml2(record7.data, true, "p") } : { ...record7, data: { ...data3, xml: xml2(data3.xml, true, "p") } };
78641
+ }
78642
+ return record7;
78643
+ }) } : {}
78644
+ });
78645
+ return { ...book, sheets: book.sheets.map(sheet), ...book.detachedSheets ? { detachedSheets: book.detachedSheets.map(sheet) } : {} };
78646
+ }
78284
78647
  function rewriteWorkbook(book, context, rewrite) {
78285
78648
  let work = 0;
78286
78649
  const maximum = context.limits.workbookWork ?? context.limits.inputBytes + context.limits.cells * 32;
@@ -78337,14 +78700,14 @@ function renameWorkbookSheet(book, sheetId, name, context) {
78337
78700
  if (!sheet || !name || name.includes("\0") || book.sheets.some((s) => s.id !== sheetId && foldSheetName(s.name) === foldSheetName(name)))
78338
78701
  throw new SsconvertError("invalid-request", "Invalid sheet rename");
78339
78702
  if (sheet.name === name) return book;
78340
- const renamed = rewriteWorkbook(book, context, (document6) => {
78703
+ const renamed = rewriteWorkbookHyperlinks(rewriteWorkbook(book, context, (document6) => {
78341
78704
  const spellings = /* @__PURE__ */ new Map();
78342
78705
  visitFormula(document6.root, (node3) => {
78343
78706
  const names2 = node3.kind === "reference" ? [node3.first.sheet, node3.last?.sheet] : node3.kind === "name" ? [node3.sheet] : [];
78344
78707
  for (const spelling of names2) if (spelling !== void 0 && foldSheetName(spelling) === foldSheetName(sheet.name)) spellings.set(spelling, name);
78345
78708
  });
78346
78709
  return rewriteReferences(document6, { sheets: spellings, signal: context.signal });
78347
- });
78710
+ }), /* @__PURE__ */ new Map([[foldSheetName(sheet.name), name]]), context);
78348
78711
  return snapshotWorkbook({
78349
78712
  ...renamed,
78350
78713
  sheets: renamed.sheets.map((s) => s.id === sheetId ? { ...s, name } : s),
@@ -78354,15 +78717,15 @@ function renameWorkbookSheet(book, sheetId, name, context) {
78354
78717
  function remapWorkbookSheets(book, mapping, context) {
78355
78718
  context.signal.throwIfAborted();
78356
78719
  book = snapshotWorkbook(book, context.limits);
78357
- const names2 = new Map(book.sheets.map((sheet) => [foldSheetName(sheet.name), mapping.get(sheet.id)?.name ?? sheet.name]));
78358
- const rewritten = rewriteWorkbook(book, context, (document6) => {
78720
+ const names2 = new Map([...book.sheets, ...book.detachedSheets ?? []].map((sheet) => [foldSheetName(sheet.name), mapping.get(sheet.id)?.name ?? sheet.name]));
78721
+ const rewritten = rewriteWorkbookHyperlinks(rewriteWorkbook(book, context, (document6) => {
78359
78722
  const spellings = /* @__PURE__ */ new Map();
78360
78723
  visitFormula(document6.root, (node3) => {
78361
78724
  const refs = node3.kind === "reference" ? [node3.first.sheet, node3.last?.sheet] : node3.kind === "name" ? [node3.sheet] : [];
78362
78725
  for (const spelling of refs) if (spelling !== void 0 && names2.has(foldSheetName(spelling))) spellings.set(spelling, names2.get(foldSheetName(spelling)));
78363
78726
  });
78364
78727
  return rewriteReferences(document6, { sheets: spellings, signal: context.signal });
78365
- });
78728
+ }), names2, context);
78366
78729
  const id = (value3) => mapping.get(value3)?.id ?? value3;
78367
78730
  const renamedTitles = new Map(book.sheets.flatMap((sheet) => {
78368
78731
  const target = mapping.get(sheet.id);
@@ -84428,7 +84791,7 @@ var german = Object.freeze({
84428
84791
  shortWeekdays: Object.freeze(["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"])
84429
84792
  });
84430
84793
  function formattingLocale(name) {
84431
- if (["C", "POSIX", "C.UTF-8", "C.utf8", "en_US", "en_US.UTF-8"].includes(name)) return english;
84794
+ if (["C", "POSIX", "C.UTF-8", "C.utf8", "en_US", "en_US.UTF-8", "en_US.utf8"].includes(name)) return english;
84432
84795
  if (["de_DE", "de_DE.UTF-8", "de_DE.utf8"].includes(name)) return german;
84433
84796
  throw new SsconvertError("unsupported-feature", "Unsupported ssconvert feature: uncaptured format locale");
84434
84797
  }
@@ -100501,7 +100864,7 @@ function createXlsxXml(context) {
100501
100864
  try {
100502
100865
  if (parts.length > 2) throw new Error("qualified name");
100503
100866
  for (const part of parts) {
100504
- const parser = parseXmlSteps(`<${part}/>`, { maxNodes: 1, maxAttributes: 1 });
100867
+ const parser = parseXmlSteps2(`<${part}/>`, { maxNodes: 1, maxAttributes: 1 });
100505
100868
  let step = parser.next();
100506
100869
  while (!step.done) step = parser.next();
100507
100870
  if (step.value.name !== part || step.value.namespace || step.value.children.length || step.value.attributes.length)
@@ -106961,7 +107324,10 @@ var capturedLocales = Object.freeze({
106961
107324
  C: "C",
106962
107325
  POSIX: "C",
106963
107326
  "C.UTF-8": "C.UTF-8",
106964
- "C.utf8": "C.UTF-8"
107327
+ "C.utf8": "C.UTF-8",
107328
+ en_US: "en_US",
107329
+ "en_US.UTF-8": "en_US.UTF-8",
107330
+ "en_US.utf8": "en_US.UTF-8"
106965
107331
  });
106966
107332
  function localeCategory(environment, category) {
106967
107333
  const env = environment.env;
@@ -108356,7 +108722,7 @@ async function openPackage(bytes, context) {
108356
108722
  const text2 = new TextDecoder(encoding, { fatal: true }).decode(plain);
108357
108723
  textBytes += plain.length;
108358
108724
  if (textBytes > (context.limits.workbookTextBytes ?? bounds2.maxTotalBytes)) limit("XML text");
108359
- const parser = parseXmlSteps2(text2, {
108725
+ const parser = parseXmlSteps3(text2, {
108360
108726
  expectedEncoding: encoding,
108361
108727
  maxDepth: context.limits.xmlDepth ?? Infinity,
108362
108728
  maxNodes: (context.limits.workbookNodes ?? Infinity) - nodes,
@@ -127757,7 +128123,8 @@ function encodeText(text2, charset, transliterate, context) {
127757
128123
  const suffixTransliteration = parts.length > 1 && parts.slice(1).every((part) => part.toLowerCase() === "translit");
127758
128124
  if (suffixTransliteration) transliterate = true;
127759
128125
  const base = suffixTransliteration ? parts[0] : charset;
127760
- const name = base === "" ? converterLocale(context.environment) === "C" ? "ascii" : "utf-8" : encodingName(base);
128126
+ const locale = base === "" ? converterLocale(context.environment) : void 0;
128127
+ const name = base === "" ? locale === "C" ? "ascii" : locale === "en_US" ? "iso-8859-1" : "utf-8" : encodingName(base);
127761
128128
  const admit2 = (length) => {
127762
128129
  context.signal.throwIfAborted();
127763
128130
  if (length > context.limits.outputBytes)
@@ -131084,7 +131451,7 @@ async function document3(bytes, context, probe = false) {
131084
131451
  const at = text2.indexOf(declared, encodingAt + 8);
131085
131452
  text2 = text2.slice(0, at) + "UTF-8" + text2.slice(at + declared.length);
131086
131453
  } else text2 = new TextDecoder(encoding, { fatal: true }).decode(bytes);
131087
- const parser = parseXmlSteps3(text2, {
131454
+ const parser = parseXmlSteps4(text2, {
131088
131455
  expectedEncoding: encoding,
131089
131456
  maxDepth: context.limits.xmlDepth ?? Infinity,
131090
131457
  maxNodes: context.limits.workbookNodes ?? Infinity,
@@ -139533,6 +139900,13 @@ function probeLotus(bytes, context) {
139533
139900
  return (b3.u16(0) === 0 || b3.u16(0) === 255) && ([1028, 1029, 1030].includes(version) ? length === 2 : [4098, 4099, 4100, 4101].includes(version) && length >= 19);
139534
139901
  }
139535
139902
  var lmbcsDoubleByteCodepages = { 16: 932, 17: 949, 18: 950, 19: 936 };
139903
+ function decodeSheetName(bytes) {
139904
+ const zero2 = bytes.indexOf(0);
139905
+ return Array.from(zero2 < 0 ? bytes : bytes.subarray(0, zero2), (byte) => {
139906
+ const character = singleByteTables["windows-1252"][byte];
139907
+ return character === "\uFFFF" ? String.fromCharCode(byte) : character;
139908
+ }).join("");
139909
+ }
139536
139910
  async function lmbcs(bytes, group, context) {
139537
139911
  let text2 = "";
139538
139912
  const warn = async (message) => context.diagnostic?.({ code: "lotus", severity: "warning", message });
@@ -139993,6 +140367,15 @@ async function readLotus(bytes, context) {
139993
140367
  active = -1;
139994
140368
  continue;
139995
140369
  }
140370
+ if (version >= 4099 && version <= 4101 && id === 35) {
140371
+ consumeOperation();
140372
+ if (length < 5) await warn(`Record with type 0x23 has wrong length ${length}.`);
140373
+ else {
140374
+ const name = decodeSheetName(data3.bytes.subarray(4));
140375
+ if (name) sheet(data3.u16(2)).name = name;
140376
+ }
140377
+ continue;
140378
+ }
139996
140379
  if (id === (modern ? 9 : 11)) {
139997
140380
  consumeOperation();
139998
140381
  if (length < (modern ? 26 : 24)) {
@@ -140187,11 +140570,11 @@ async function readLotus(bytes, context) {
140187
140570
  else {
140188
140571
  const subtype = data3.u16(0);
140189
140572
  if (subtype === 14e3) {
140190
- if (length <= 5) await warn(`Record with type 0x1b has wrong length ${length}.`);
140573
+ consumeOperation();
140574
+ if (length < 5) await warn(`Record with type 0x1b has wrong length ${length}.`);
140191
140575
  else {
140192
- consumeOperation();
140193
- const nameBytes = data3.bytes.subarray(4, length - 1), zero2 = nameBytes.indexOf(0);
140194
- sheet(data3.u8(2)).name = new TextDecoder().decode(zero2 < 0 ? nameBytes : nameBytes.subarray(0, zero2));
140576
+ const name = decodeSheetName(data3.bytes.subarray(4));
140577
+ if (name) sheet(data3.u16(2)).name = name;
140195
140578
  }
140196
140579
  } else if (subtype === 4001) {
140197
140580
  if (length < 24) await warn(`Record with type 0x1b has wrong length ${length}.`);
@@ -143166,50 +143549,6 @@ function prepareOdfFormulaLabels(book, context, tick) {
143166
143549
  });
143167
143550
  return { book, documents: documents2 };
143168
143551
  }
143169
- var linkGrammar = { ...excelGrammar, id: "odf-hyperlink", sheetSeparator: "." };
143170
- function translateOdfHyperlink(source, direction, charge, sheetNames = []) {
143171
- charge(source.length);
143172
- if (direction === "normalize" && !source.startsWith("#")) return source;
143173
- function findSheet(name) {
143174
- const folded = foldSheetName(name);
143175
- return sheetNames.find((candidate) => {
143176
- charge(candidate.length);
143177
- return foldSheetName(candidate) === folded;
143178
- });
143179
- }
143180
- let target = direction !== "export" && source.startsWith("#") ? source.slice(1) : source;
143181
- if (direction !== "export") {
143182
- try {
143183
- target = decodeURIComponent(target);
143184
- } catch {
143185
- if (direction === "normalize") return source;
143186
- }
143187
- const separator2 = target.indexOf(" (");
143188
- if (separator2 > 0 && target.endsWith(")")) {
143189
- const name = target.slice(0, separator2), sheet = findSheet(target.slice(separator2 + 2, -1));
143190
- if (sheet !== void 0) {
143191
- const qualified = quoteNativeSheet(sheet) + "!" + name;
143192
- const parsed2 = parseExpression("=" + qualified, { position: { sheet, row: 0, column: 0 }, onWork: charge });
143193
- if (parsed2.ok && parsed2.document.root.kind === "name" && parsed2.document.root.name === name && parsed2.document.root.sheet === sheet)
143194
- return direction === "import" ? qualified : source;
143195
- }
143196
- }
143197
- }
143198
- const parsed = parseExpression("=" + target, {
143199
- grammar: direction !== "export" ? linkGrammar : gnumericGrammar,
143200
- position: { sheet: "", row: 0, column: 0 },
143201
- onWork: charge
143202
- });
143203
- if (parsed.ok) {
143204
- const node3 = parsed.document.root;
143205
- if (node3.kind === "name" && node3.workbook === void 0 || node3.kind === "reference" && !node3.label && node3.first.workbook === void 0 && node3.last?.workbook === void 0) {
143206
- const sheet = direction !== "import" && node3.kind === "name" && node3.sheet !== void 0 ? findSheet(node3.sheet) : void 0;
143207
- if (sheet !== void 0 && node3.kind === "name") return "#" + encodeURI(node3.name + " (" + sheet + ")");
143208
- if (direction !== "normalize") target = serializeExpression(parsed.document, direction === "import" ? { ...gnumericGrammar, quoteSheetName: quoteNativeSheet } : linkGrammar, false, true).slice(1);
143209
- }
143210
- }
143211
- return direction === "import" ? target : direction === "normalize" ? source : "#" + encodeURI(target);
143212
- }
143213
143552
  var odfReaderStates = {
143214
143553
  opendoc_content_dtd: `START OFFICE OO_NS_OFFICE document-content
143215
143554
  OFFICE SCRIPT OO_NS_OFFICE scripts
@@ -143321,6 +143660,7 @@ TEXT_SPAN TEXT_LINE_BREAK OO_NS_TEXT line-break
143321
143660
  TEXT_SPAN TEXT_TAB OO_NS_TEXT tab
143322
143661
  TEXT_SPAN TEXT_ADDR OO_NS_TEXT a
143323
143662
  TEXT_ADDR TEXT_S OO_NS_TEXT s
143663
+ TEXT_ADDR TEXT_LINE_BREAK OO_NS_TEXT line-break
143324
143664
  TEXT_ADDR TEXT_TAB OO_NS_TEXT tab
143325
143665
  TEXT_ADDR TEXT_SPAN OO_NS_TEXT span
143326
143666
  CONTENT_VALIDATION HELP_MESSAGE OO_NS_TABLE help-message
@@ -143761,13 +144101,13 @@ MASTER_PAGE_FOOTER MASTER_PAGE_HF_R_RIGHT OO_NS_STYLE region-right
143761
144101
  MASTER_PAGE_FOOTER MASTER_PAGE_HF_R_CENTER OO_NS_STYLE region-center
143762
144102
  MASTER_PAGE_FOOTER MASTER_PAGE_HF_P OO_NS_TEXT p`
143763
144103
  };
143764
- var urn = "urn:oasis:names:tc:opendocument:xmlns:";
144104
+ var urn2 = "urn:oasis:names:tc:opendocument:xmlns:";
143765
144105
  var ns = {
143766
- table: [urn + "table:1.0", "http://openoffice.org/2000/table"],
143767
- office: [urn + "office:1.0", "http://openoffice.org/2000/office"],
143768
- text: [urn + "text:1.0", "http://openoffice.org/2000/text"],
143769
- style: [urn + "style:1.0", "http://openoffice.org/2000/style"],
143770
- fo: [urn + "xsl-fo-compatible:1.0", "http://www.w3.org/1999/XSL/Format"],
144106
+ table: [urn2 + "table:1.0", "http://openoffice.org/2000/table"],
144107
+ office: [urn2 + "office:1.0", "http://openoffice.org/2000/office"],
144108
+ text: [urn2 + "text:1.0", "http://openoffice.org/2000/text"],
144109
+ style: [urn2 + "style:1.0", "http://openoffice.org/2000/style"],
144110
+ fo: [urn2 + "xsl-fo-compatible:1.0", "http://www.w3.org/1999/XSL/Format"],
143771
144111
  dc: ["http://purl.org/dc/elements/1.1/"],
143772
144112
  xlink: ["http://www.w3.org/1999/xlink"],
143773
144113
  gnm: ["http://www.gnumeric.org/odf-extension/1.0"]
@@ -144078,166 +144418,6 @@ function readOdfLabelRanges(parent, sheets, context, charge) {
144078
144418
  return { ...sheet, size: sizes.get(sheet.id), ...pairs ? { labelRanges: pairs } : {} };
144079
144419
  });
144080
144420
  }
144081
- var urn2 = "urn:oasis:names:tc:opendocument:xmlns:";
144082
- var odfEncryptionNamespace = "urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0";
144083
- var odfNamespaces = {
144084
- xml: "http://www.w3.org/XML/1998/namespace",
144085
- office: urn2 + "office:1.0",
144086
- style: urn2 + "style:1.0",
144087
- text: urn2 + "text:1.0",
144088
- table: urn2 + "table:1.0",
144089
- draw: urn2 + "drawing:1.0",
144090
- fo: urn2 + "xsl-fo-compatible:1.0",
144091
- xlink: "http://www.w3.org/1999/xlink",
144092
- dc: "http://purl.org/dc/elements/1.1/",
144093
- meta: urn2 + "meta:1.0",
144094
- number: urn2 + "datastyle:1.0",
144095
- svg: urn2 + "svg-compatible:1.0",
144096
- chart: urn2 + "chart:1.0",
144097
- config: urn2 + "config:1.0",
144098
- form: urn2 + "form:1.0",
144099
- script: urn2 + "script:1.0",
144100
- of: urn2 + "of:1.2",
144101
- manifest: urn2 + "manifest:1.0",
144102
- gnm: "http://www.gnumeric.org/odf-extension/1.0",
144103
- calcext: "urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0"
144104
- };
144105
- function odfObject(value3) {
144106
- return value3 !== null && typeof value3 === "object" && !Array.isArray(value3) ? value3 : void 0;
144107
- }
144108
- function odfAttributes(value3, namespace5) {
144109
- const source = odfObject(value3)?.attributes;
144110
- if (Array.isArray(source)) return Object.fromEntries(source.flatMap((a3) => {
144111
- const v = odfObject(a3);
144112
- return typeof v?.name === "string" && typeof v.value === "string" && (namespace5 === void 0 || v.namespace === namespace5) ? [[v.name, v.value]] : [];
144113
- }));
144114
- if (namespace5 !== void 0) return {};
144115
- return Object.fromEntries(Object.entries(odfObject(source) ?? {}).filter((entry2) => typeof entry2[1] === "string"));
144116
- }
144117
- function odfChildren(value3) {
144118
- const source = odfObject(value3)?.children;
144119
- return Array.isArray(source) ? source : [];
144120
- }
144121
- function createOdfXml(context, extended) {
144122
- let work = 0, nodes = 0;
144123
- const encoder3 = new TextEncoder(), names2 = /* @__PURE__ */ new Set();
144124
- const declarations = {
144125
- ...Object.fromEntries(Object.entries(odfNamespaces).map(([prefix, uri]) => ["xmlns:" + prefix, uri])),
144126
- "xmlns:loext": odfEncryptionNamespace
144127
- };
144128
- function charge(amount = 1) {
144129
- context.signal.throwIfAborted();
144130
- if (!Number.isSafeInteger(amount) || amount < 0 || amount > (context.limits.workbookWork ?? Infinity) - work)
144131
- throw new SsconvertError("resource-limit", "ssconvert OpenDocument work limit exceeded");
144132
- work += amount;
144133
- }
144134
- function name(value3) {
144135
- charge(value3.length);
144136
- if (names2.has(value3)) return;
144137
- try {
144138
- const parser = parseXmlSteps4(`<${value3} ${Object.entries(declarations).map(([k, v]) => `${k}="${v}"`).join(" ")}/>`, { maxNodes: 1, maxAttributes: 100 });
144139
- let step = parser.next();
144140
- while (!step.done) step = parser.next();
144141
- if (step.value.name !== value3 || step.value.children.length) throw new Error("name");
144142
- } catch {
144143
- throw new SsconvertError("invalid-request", "Invalid OpenDocument XML name");
144144
- }
144145
- names2.add(value3);
144146
- }
144147
- function escape3(value3) {
144148
- charge(value3.length);
144149
- let result2 = "";
144150
- for (const c4 of value3) {
144151
- const code = c4.codePointAt(0);
144152
- if (code < 32 && !" \n\r".includes(c4) || code === 65534 || code === 65535 || code >= 55296 && code <= 57343)
144153
- throw new SsconvertError("unsupported-feature", "Unsupported ssconvert feature: non-XML OpenDocument character");
144154
- result2 += c4 === "&" ? "&amp;" : c4 === "<" ? "&lt;" : c4 === ">" ? "&gt;" : c4 === '"' ? "&quot;" : c4 === "\r" ? "&#13;" : c4 === "\n" ? "&#10;" : c4 === " " ? "&#9;" : c4;
144155
- }
144156
- return result2;
144157
- }
144158
- function element2(tag, attributes4 = {}, content2 = "") {
144159
- charge();
144160
- if (++nodes > (context.limits.workbookNodes ?? Infinity))
144161
- throw new SsconvertError("resource-limit", "ssconvert OpenDocument XML nodes limit exceeded");
144162
- name(tag);
144163
- let result2 = "<" + tag;
144164
- for (const [key, value3] of Object.entries(attributes4)) if (value3 !== void 0) {
144165
- if (!key.startsWith("xmlns:")) name(key);
144166
- result2 += ` ${key}="${escape3(String(value3))}"`;
144167
- }
144168
- result2 += content2 ? ">" + content2 + "</" + tag + ">" : "/>";
144169
- if (result2.length > context.limits.outputBytes || encoder3.encode(result2).length > context.limits.outputBytes)
144170
- throw new SsconvertError("resource-limit", "ssconvert OpenDocument output bytes limit exceeded");
144171
- return result2;
144172
- }
144173
- function text2(value3) {
144174
- charge(value3.length);
144175
- let result2 = "", plain = "";
144176
- function flush() {
144177
- result2 += escape3(plain);
144178
- plain = "";
144179
- }
144180
- for (let i = 0; i < value3.length; i++) {
144181
- const c4 = value3[i];
144182
- if (c4 === " ") {
144183
- flush();
144184
- let count = 1;
144185
- while (value3[i + 1] === " ") {
144186
- i++;
144187
- count++;
144188
- }
144189
- result2 += element2("text:s", count > 1 ? { "text:c": count } : {});
144190
- } else if (c4 === " " || c4 === "\n") {
144191
- flush();
144192
- result2 += element2(c4 === " " ? "text:tab" : "text:line-break");
144193
- } else plain += c4;
144194
- }
144195
- flush();
144196
- return result2;
144197
- }
144198
- const active = /* @__PURE__ */ new Set();
144199
- function retained2(value3, depth = 0, hyperlink) {
144200
- charge();
144201
- const v = odfObject(value3);
144202
- if (!v || typeof v.name !== "string" || typeof v.namespace !== "string") return "";
144203
- if (depth > (context.limits.xmlDepth ?? Infinity)) throw new SsconvertError("resource-limit", "ssconvert OpenDocument metadata depth limit exceeded");
144204
- if (active.has(v)) throw new SsconvertError("invalid-request", "Invalid cyclic OpenDocument metadata");
144205
- const prefix = Object.entries(odfNamespaces).find(([, uri]) => uri === v.namespace)?.[0];
144206
- if (!prefix || !extended && ["gnm", "calcext"].includes(prefix)) return "";
144207
- active.add(v);
144208
- try {
144209
- const attributes4 = {};
144210
- if (Array.isArray(v.attributes)) for (const a3 of v.attributes) {
144211
- charge();
144212
- const attribute5 = odfObject(a3);
144213
- if (typeof attribute5?.name !== "string" || typeof attribute5.value !== "string" || typeof attribute5.namespace !== "string") continue;
144214
- const p2 = Object.entries(odfNamespaces).find(([, uri]) => uri === attribute5.namespace)?.[0];
144215
- if (attribute5.namespace && (!p2 || !extended && ["gnm", "calcext"].includes(p2))) continue;
144216
- attributes4[(p2 ? p2 + ":" : "") + attribute5.name] = attribute5.value;
144217
- }
144218
- if (prefix === "text" && v.name === "a" && attributes4["xlink:href"] !== void 0 && hyperlink)
144219
- attributes4["xlink:href"] = hyperlink(attributes4["xlink:href"]);
144220
- const children7 = odfChildren(v);
144221
- const content2 = Array.isArray(v.content) ? v.content.map((c4) => {
144222
- charge();
144223
- const item = odfObject(c4);
144224
- if (item?.kind === "text" && typeof item.text === "string") return escape3(item.text);
144225
- if (item?.kind !== "element") return "";
144226
- if (item.index === void 0) return retained2(item.value, depth + 1, hyperlink);
144227
- if (typeof item.index !== "number" || !Number.isSafeInteger(item.index) || item.index < 0 || item.index >= children7.length)
144228
- throw new SsconvertError("invalid-request", "Invalid OpenDocument metadata child index");
144229
- return retained2(children7[item.index], depth + 1, hyperlink);
144230
- }).join("") : (typeof v.text === "string" ? escape3(v.text) : "") + children7.map((c4) => retained2(c4, depth + 1, hyperlink)).join("");
144231
- return element2(prefix + ":" + v.name, attributes4, content2);
144232
- } finally {
144233
- active.delete(v);
144234
- }
144235
- }
144236
- function document6(tag, body) {
144237
- return '<?xml version="1.0" encoding="UTF-8"?>\n' + element2(tag, { ...declarations, "xmlns:loext": void 0, "office:version": "1.2" }, body);
144238
- }
144239
- return { element: element2, escape: escape3, text: text2, retained: retained2, document: document6, charge };
144240
- }
144241
144421
  var iterations = 1024;
144242
144422
  var argon2 = { t: 3, m: 65536, p: 4, dkLen: 32, version: 19, maxmem: 64 * 1024 * 1024, asyncTick: 10 };
144243
144423
  var odfEncryptionProfiles = /* @__PURE__ */ new Map([
@@ -146259,8 +146439,9 @@ function createOdfWriter(profile) {
146259
146439
  }
146260
146440
  }
146261
146441
  xml2.charge(originalParagraphs.size);
146262
- const renderedText = cell.displayedText ?? await renderCellText(cell, book, context), rendered2 = xml2.text(renderedText), paragraph = originalParagraphs.get(key) ?? [...originalParagraphs.values()].find((p2) => row >= p2.range.startRow && row <= p2.range.endRow && start >= p2.range.startColumn && start <= p2.range.endColumn);
146442
+ const renderedText = cell.displayedText ?? await renderCellText(cell, book, context), paragraph = originalParagraphs.get(key) ?? [...originalParagraphs.values()].find((p2) => row >= p2.range.startRow && row <= p2.range.endRow && start >= p2.range.startColumn && start <= p2.range.endColumn);
146263
146443
  const link = meta?.link ?? links.get(key);
146444
+ const rendered2 = link ? xml2.escape(renderedText) : xml2.text(renderedText);
146264
146445
  content2 += paragraph?.text === renderedText ? paragraph.xml : e("text:p", {}, link ? e("text:a", link, rendered2) : rendered2);
146265
146446
  }
146266
146447
  const next = !cell && !merge && meta ? Math.min(meta.range.endColumn + 1, stops.find((s) => s > start) ?? meta.range.endColumn + 1) : start + 1;
@@ -163704,7 +163885,7 @@ function bounded2(value3, maximum, name) {
163704
163885
  if (!Number.isSafeInteger(value3) || value3 < 0 || value3 > maximum)
163705
163886
  throw new SsconvertError("resource-limit", `ssconvert ${name} limit exceeded`);
163706
163887
  }
163707
- function createEngine(supplied) {
163888
+ function createEngine(supplied = {}) {
163708
163889
  const config = {
163709
163890
  ...supplied,
163710
163891
  ...supplied.entropy === void 0 ? {} : { entropy: Object.freeze({ read: supplied.entropy.read.bind(supplied.entropy) }) },
@@ -163712,16 +163893,19 @@ function createEngine(supplied) {
163712
163893
  ...supplied.fonts === void 0 ? {} : { fonts: Object.freeze({ resolve: supplied.fonts.resolve.bind(supplied.fonts) }) },
163713
163894
  ...supplied.password === void 0 ? {} : { password: Object.freeze({ read: supplied.password.read.bind(supplied.password) }) },
163714
163895
  ...supplied.runtimeFunctions === void 0 ? {} : { runtimeFunctions: snapshotRuntimeFunctions(supplied.runtimeFunctions) },
163896
+ codecs: supplied.codecs ?? [],
163715
163897
  limits: Object.freeze({ ...defaultSsconvertLimits, ...supplied.limits }),
163716
163898
  environment: Object.freeze({
163717
163899
  ...supplied.environment,
163718
- cwd: supplied.filesystem?.cwd ?? supplied.environment.cwd ?? supplied.environment.env.PWD ?? "/",
163719
- env: Object.freeze({ ...supplied.environment.env })
163900
+ locale: supplied.environment?.locale ?? "C",
163901
+ timezone: supplied.environment?.timezone ?? "UTC",
163902
+ cwd: supplied.filesystem?.cwd ?? supplied.environment?.cwd ?? supplied.environment?.env?.PWD ?? "/",
163903
+ env: Object.freeze({ ...supplied.environment?.env })
163720
163904
  })
163721
163905
  };
163722
163906
  if (config.datasource && Object.hasOwn(config.runtimeFunctions ?? {}, "ATL_LAST"))
163723
163907
  throw new TypeError("Conflicting ssconvert datasource runtime function: ATL_LAST");
163724
- if ((supplied.filesystem?.cwd !== void 0 || supplied.environment.cwd !== void 0) && (!config.environment.cwd.startsWith("/") || config.environment.cwd.includes("\0")))
163908
+ if ((supplied.filesystem?.cwd !== void 0 || supplied.environment?.cwd !== void 0) && (!config.environment.cwd.startsWith("/") || config.environment.cwd.includes("\0")))
163725
163909
  throw new TypeError("ssconvert cwd must be an absolute VFS path");
163726
163910
  for (const name of ["inputBytes", "outputBytes", "cells", "sheets", "operations"]) {
163727
163911
  const value3 = config.limits[name];