@poe-platform/safe-bash 0.1.809 → 0.1.810

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 (109) hide show
  1. package/dist/audio-ast/index.d.ts +1 -1
  2. package/dist/audio-ast/index.js +6 -0
  3. package/dist/audio-ast/wav-source.d.ts +7 -1
  4. package/dist/image-ast/index.js +1 -1
  5. package/dist/pdf-ast/cos/mutable-object-store.d.ts +3 -0
  6. package/dist/pdf-ast/cos/qpdf-json-document.d.ts +42 -0
  7. package/dist/pdf-ast/cos/qpdf-json-values.d.ts +7 -0
  8. package/dist/pdf-ast/index.d.ts +1 -0
  9. package/dist/pdf-ast/index.js +508 -37
  10. package/dist/pdf-ast/retained-document.d.ts +3 -1
  11. package/dist/safe-bash/chunks/{chunk-RQCK77SC.js → chunk-65TFMAZU.js} +2 -2
  12. package/dist/safe-bash/chunks/{chunk-SOFBGDXG.js → chunk-HHSOUC3Z.js} +32 -0
  13. package/dist/safe-bash/chunks/{chunk-WAZEELYB.js → chunk-ZA5FQ34E.js} +10 -5
  14. package/dist/safe-bash/command-chunks/biff-ORSHM4YX-QYPGRDAZ.js +4937 -0
  15. package/dist/safe-bash/command-chunks/{chunk-62ZAHKFS.js → chunk-2VCKUNDZ.js} +130 -14
  16. package/dist/safe-bash/command-chunks/{chunk-GLVD3JJG.js → chunk-BYZUOF6X.js} +2858 -2816
  17. package/dist/safe-bash/command-chunks/{chunk-6OKH4X67.js → chunk-CAXJ4RLF.js} +264 -1
  18. package/dist/safe-bash/command-chunks/{chunk-YJJBGN7U.js → chunk-CHR2OD2U.js} +9 -9
  19. package/dist/safe-bash/command-chunks/{chunk-D7XBUF76.js → chunk-D2ASPM7R.js} +109 -23
  20. package/dist/safe-bash/command-chunks/chunk-D5AYP2UM.js +816 -0
  21. package/dist/safe-bash/command-chunks/{chunk-WFDG3N5R.js → chunk-ECDEPKKW.js} +1 -1
  22. package/dist/safe-bash/command-chunks/{chunk-OQCJGUI6.js → chunk-HARUYHH7.js} +10 -10
  23. package/dist/safe-bash/command-chunks/{chunk-NVBUC644.js → chunk-HKGNBH7Z.js} +2 -2
  24. package/dist/safe-bash/command-chunks/chunk-MGBHGZEX.js +12 -0
  25. package/dist/safe-bash/command-chunks/{chunk-4557HE3J.js → chunk-PMWW7KSB.js} +161 -42
  26. package/dist/safe-bash/command-chunks/{chunk-JW3KIZU6.js → chunk-RUXY7GN5.js} +1 -1
  27. package/dist/safe-bash/command-chunks/{chunk-KELMIFVV.js → chunk-TI52LKLL.js} +1 -1
  28. package/dist/safe-bash/command-chunks/{chunk-JJQ72P3V.js → chunk-VCML4T5D.js} +1 -1
  29. package/dist/safe-bash/command-chunks/{chunk-5HGEXQVD.js → chunk-WC2OCF4H.js} +1 -1
  30. package/dist/safe-bash/command-chunks/chunk-WH3TIOTS.js +326 -0
  31. package/dist/safe-bash/command-chunks/{chunk-45FI2IPY.js → chunk-WQ6ABTJU.js} +3 -6
  32. package/dist/safe-bash/command-chunks/{chunk-NB7JO7FE.js → chunk-YTFWPJ3F.js} +1 -1
  33. package/dist/safe-bash/command-chunks/{chunk-GKYCV6BU.js → chunk-ZEPDT6I5.js} +482 -168
  34. package/dist/safe-bash/command-chunks/{command-engine-P5DFM4OU.js → command-engine-BEWABZ75.js} +10 -3
  35. package/dist/safe-bash/command-chunks/{engine-RU4OFLPO-CPLFYD67.js → engine-MEPOXIXT-WZMRHACG.js} +1 -1
  36. package/dist/safe-bash/command-chunks/pdf-LOZAXXS6-ERI57IAV.js +557 -0
  37. package/dist/safe-bash/commands/audio/index.browser.js +2 -14
  38. package/dist/safe-bash/commands/diff-patch/index.js +0 -2
  39. package/dist/safe-bash/commands/ffprobe/index.browser.js +2 -5
  40. package/dist/safe-bash/commands/pandoc/index.browser.js +3 -1
  41. package/dist/safe-bash/commands/text.js +10 -1
  42. package/dist/safe-bash/core.d.ts +2 -2
  43. package/dist/safe-bash/core.js +2 -2
  44. package/dist/safe-bash/full-core.browser.js +18 -22
  45. package/dist/safe-bash/lazy-optional.d.ts +9 -0
  46. package/dist/safe-bash/lazy-optional.js +24 -0
  47. package/dist/safe-bash/plugins/index.browser.js +5 -3
  48. package/dist/safe-bash/registry-entry.browser.js +1 -1
  49. package/dist/safe-bash-command-apply-patch/apply.js +2 -2
  50. package/dist/safe-bash-command-apply-patch/index.js +2 -2
  51. package/dist/safe-bash-command-apply-patch/parser.d.ts +20 -1
  52. package/dist/safe-bash-command-apply-patch/parser.js +1 -1
  53. package/dist/safe-bash-command-ffprobe/index.js +2 -1
  54. package/dist/safe-bash-command-ffprobe/media.js +2 -1
  55. package/dist/safe-bash-command-ffprobe/options.d.ts +15 -0
  56. package/dist/safe-bash-command-ffprobe/options.js +7 -0
  57. package/dist/safe-bash-command-media/index.js +2 -2
  58. package/dist/safe-bash-command-media/plugin.js +1 -1
  59. package/dist/safe-bash-command-media/remote.js +2 -2
  60. package/dist/safe-bash-command-pandoc/command.js +6 -6
  61. package/dist/safe-bash-command-pandoc/index.js +31 -31
  62. package/dist/safe-bash-command-patch/index.js +2 -2
  63. package/dist/safe-bash-command-patch/patch-publication.d.ts +2 -2
  64. package/dist/safe-bash-command-patch/patch-publication.js +1 -1
  65. package/dist/safe-bash-command-patch/patch.js +2 -2
  66. package/dist/safe-bash-command-pptx/engine.js +1 -1
  67. package/dist/safe-bash-command-ssconvert/index.js +2 -2
  68. package/dist/safe-bash-command-xmllint/index.js +137 -30
  69. package/dist/safe-bash-compression-engine/bounded-codec.js +2 -2
  70. package/dist/safe-bash-compression-engine/codec-loader.js +1 -1
  71. package/dist/safe-bash-compression-engine/files.js +5 -5
  72. package/dist/safe-bash-compression-engine/index.js +4 -4
  73. package/dist/safe-bash-compression-engine/operand.js +5 -5
  74. package/dist/safe-bash-compression-engine/stream.js +4 -4
  75. package/dist/safe-bash-compression-engine/zstd-decode.js +3 -3
  76. package/dist/safe-bash-media-engine/imagemagick.d.ts +2 -0
  77. package/dist/safe-bash-media-engine/index.js +162 -72
  78. package/dist/safe-bash-network-engine/body.d.ts +1 -0
  79. package/dist/safe-bash-network-engine/body.js +1 -1
  80. package/dist/safe-bash-network-engine/transfer.js +11 -3
  81. package/dist/safe-bash-presentation-engine/command-placeholder.js +4 -3
  82. package/dist/safe-bash-presentation-engine/index.d.ts +1 -1
  83. package/dist/safe-bash-presentation-engine/index.js +9 -4
  84. package/dist/safe-bash-presentation-engine/presentation-model.js +3 -2
  85. package/dist/safe-bash-presentation-engine/retained-text.js +3 -3
  86. package/dist/safe-bash-presentation-engine/retained-xml-parts.d.ts +26 -0
  87. package/dist/safe-bash-presentation-engine/xml-parts.d.ts +1 -0
  88. package/dist/safe-bash-presentation-engine/xml-parts.js +7 -1
  89. package/dist/safe-bash-xml-engine/document.js +1 -1
  90. package/dist/safe-bash-xml-engine/index.js +1 -1
  91. package/dist/spreadsheet-engine/rendering/print/tab-layout.d.ts +11 -0
  92. package/dist/spreadsheet-engine/rendering/print/tab-layout.js +15 -0
  93. package/dist/spreadsheet-engine/rendering/print/text-lines.d.ts +2 -2
  94. package/dist/spreadsheet-engine/rendering/print/text-lines.js +3 -3
  95. package/dist/spreadsheet-format-xls/biff-encrypted-properties.d.ts +4 -0
  96. package/dist/spreadsheet-format-xls/biff-encrypted-properties.js +137 -56
  97. package/dist/spreadsheet-format-xls/biff-encryption.d.ts +1 -1
  98. package/dist/spreadsheet-format-xls/biff-encryption.js +8 -3
  99. package/dist/spreadsheet-format-xls/biff-property-bytes.d.ts +1 -1
  100. package/dist/spreadsheet-format-xls/biff-property-bytes.js +2 -2
  101. package/dist/spreadsheet-format-xls/biff.js +11 -3
  102. package/package.json +3 -2
  103. package/dist/safe-bash/chunks/chunk-I2A5ZCPD.js +0 -17
  104. package/dist/safe-bash/chunks/chunk-PQTT2EZP.js +0 -8
  105. package/dist/safe-bash/command-chunks/biff-DS263V2K-2GP4GZT7.js +0 -4868
  106. package/dist/safe-bash/command-chunks/chunk-6ZFYWT3U.js +0 -581
  107. package/dist/safe-bash/command-chunks/chunk-S244SWDH.js +0 -153
  108. package/dist/safe-bash/command-chunks/pdf-T7AWYZGQ-KNAYJ7YF.js +0 -552
  109. /package/dist/safe-bash/command-chunks/{chunk-EMMSXKEJ.js → chunk-4Q4R3VZU.js} +0 -0
@@ -1,6 +1,14 @@
1
+ import {
2
+ openRetainedPresentationIndex,
3
+ stageRetainedOutput,
4
+ streamJson
5
+ } from "./chunk-U6QHTC5J.js";
1
6
  import {
2
7
  writePackageArchive
3
8
  } from "./chunk-VPDSQPSN.js";
9
+ import {
10
+ SelectionError
11
+ } from "./chunk-S4IIOSRA.js";
4
12
  import {
5
13
  readPackage
6
14
  } from "./chunk-SFCERNHU.js";
@@ -10,6 +18,9 @@ import {
10
18
  import {
11
19
  validatePresentation
12
20
  } from "./chunk-MMBRBANA.js";
21
+ import {
22
+ openRetainedContentTypes
23
+ } from "./chunk-FXKBM5KJ.js";
13
24
  import {
14
25
  parseXmlPart
15
26
  } from "./chunk-5L6GHFRW.js";
@@ -20,10 +31,15 @@ import {
20
31
  readRelationshipGraph
21
32
  } from "./chunk-NTRZMQZP.js";
22
33
  import {
34
+ packageUri,
23
35
  partName
24
36
  } from "./chunk-AXWPJRY6.js";
25
37
  import {
26
- OfficeError
38
+ OfficeError,
39
+ characters,
40
+ literal,
41
+ openRetainedXml,
42
+ openRetainedXmlDocument
27
43
  } from "./chunk-KJ3PEDI2.js";
28
44
 
29
45
  // packages/safe-bash-presentation-engine/src/xml-view-validation.ts
@@ -144,6 +160,251 @@ function validateXmlViewReplacement(reader, part, bytes, context, validate) {
144
160
 
145
161
  // packages/safe-bash-presentation-engine/src/xml-parts.ts
146
162
  import { SaxesParser } from "saxes";
163
+
164
+ // packages/safe-bash-presentation-engine/src/retained-xml-parts.ts
165
+ import { PagedStorage } from "@poe-platform/safe-fs/storage";
166
+ async function prettySpans(xml, settings) {
167
+ const working = settings.workingStorage, signal = settings.signal ?? new AbortController().signal;
168
+ const pages = new PagedStorage({ fs: working.fs, cwd: working.directory, env: {}, signal }, (working.cacheBytes ?? 1024 * 1024) / 16384);
169
+ async function row(pointer) {
170
+ const bytes = await pages.read(pointer, 9 /* Count */ * 8), view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
171
+ return Array.from({ length: 9 /* Count */ }, (_, i) => view.getFloat64(i * 8, true));
172
+ }
173
+ async function save(pointer, row2) {
174
+ const bytes = new Uint8Array(9 /* Count */ * 8), view = new DataView(bytes.buffer);
175
+ row2.forEach((value, i) => view.setFloat64(i * 8, value, true));
176
+ await pages.write(pointer, bytes);
177
+ }
178
+ let current = 0, root = 0;
179
+ try {
180
+ for await (const token of xml.tokens()) {
181
+ if (token.kind === "start-name") {
182
+ const pointer = pages.allocate(9 /* Count */ * 8), value = Array(9 /* Count */).fill(0);
183
+ value[0 /* Parent */] = current;
184
+ value[4 /* Start */] = token.range.start - 1;
185
+ if (current) {
186
+ const parent = await row(current);
187
+ if (parent[2 /* Last */]) {
188
+ const previous = await row(parent[2 /* Last */]);
189
+ previous[3 /* Next */] = pointer;
190
+ await save(parent[2 /* Last */], previous);
191
+ } else parent[1 /* First */] = pointer;
192
+ parent[2 /* Last */] = pointer;
193
+ await save(current, parent);
194
+ } else root = pointer;
195
+ await save(pointer, value);
196
+ current = pointer;
197
+ } else if (token.kind === "start-end") {
198
+ const value = await row(current);
199
+ value[5 /* Open */] = token.range.start;
200
+ if (token.empty) value[7 /* End */] = token.range.start;
201
+ await save(current, value);
202
+ if (token.empty) current = value[0 /* Parent */];
203
+ } else if (token.kind === "end-name") {
204
+ const value = await row(current);
205
+ value[6 /* Close */] = token.range.start - 2;
206
+ let end = token.range.start + token.range.length;
207
+ outer: for await (const bytes of xml.read({ start: end, length: xml.byteLength - end })) for (const byte of bytes) {
208
+ end++;
209
+ if (byte === 62) break outer;
210
+ }
211
+ value[7 /* End */] = end;
212
+ await save(current, value);
213
+ current = value[0 /* Parent */];
214
+ } else if (current && ["text", "comment", "cdata", "instruction"].includes(token.kind)) {
215
+ let mixed = token.kind !== "text";
216
+ if (!mixed) {
217
+ for await (const character of characters(xml.value(token.range))) if (character.trim()) {
218
+ mixed = true;
219
+ break;
220
+ }
221
+ }
222
+ if (mixed) {
223
+ const value = await row(current);
224
+ value[8 /* Mixed */] = 1;
225
+ await save(current, value);
226
+ }
227
+ }
228
+ }
229
+ const formatted = !(await row(root))[8 /* Mixed */] && Boolean((await row(root))[1 /* First */]);
230
+ async function* indent(depth) {
231
+ yield* literal("\n");
232
+ const spaces = new Uint8Array(4096).fill(32);
233
+ for (let left = depth * 2; left; left -= Math.min(left, spaces.length)) yield spaces.subarray(0, Math.min(left, spaces.length));
234
+ }
235
+ async function* render() {
236
+ let pointer = root, depth = 0, returning = false;
237
+ while (pointer) {
238
+ signal.throwIfAborted();
239
+ const value = await row(pointer);
240
+ if (returning) {
241
+ yield* indent(depth);
242
+ yield* xml.read({ start: value[6 /* Close */], length: value[7 /* End */] - value[6 /* Close */] });
243
+ } else if (value[8 /* Mixed */] || !value[1 /* First */]) yield* xml.read({ start: value[4 /* Start */], length: value[7 /* End */] - value[4 /* Start */] });
244
+ else {
245
+ yield* xml.read({ start: value[4 /* Start */], length: value[5 /* Open */] - value[4 /* Start */] });
246
+ pointer = value[1 /* First */];
247
+ depth++;
248
+ yield* indent(depth);
249
+ continue;
250
+ }
251
+ if (value[3 /* Next */]) {
252
+ pointer = value[3 /* Next */];
253
+ returning = false;
254
+ yield* indent(depth);
255
+ } else {
256
+ pointer = value[0 /* Parent */];
257
+ depth--;
258
+ returning = true;
259
+ }
260
+ }
261
+ }
262
+ return { formatted, render, close: () => pages.close() };
263
+ } catch (error) {
264
+ await pages.close().catch(() => {
265
+ });
266
+ throw error;
267
+ }
268
+ }
269
+ async function openRetainedXmlPart(archive, requested, settings, options = {}) {
270
+ if (Object.keys(options).some((key) => key !== "pretty") || options.pretty !== void 0 && typeof options.pretty !== "boolean") throw new OfficeError("invalid-value", "Invalid XML display options.", "usage");
271
+ settings = { ...settings, workingStorage: { ...settings.workingStorage }, ...settings.validationLimits ? { validationLimits: { ...settings.validationLimits } } : {} };
272
+ const pretty2 = options.pretty ?? false, part = partName(requested, false), limits = settings.validationLimits;
273
+ if (!limits) throw new OfficeError("invalid-value", "XML operations require explicit validation limits.", "usage");
274
+ if (part !== requested || !await archive.has(part)) throw new OfficeError("missing-selection", "An exact existing package part is required.", "select");
275
+ if (part !== "/[Content_Types].xml") {
276
+ const types = await openRetainedContentTypes(archive.read("/[Content_Types].xml"), { ...settings, xmlLimits: { maxBytes: limits.maxBytes, maxNodes: Infinity, maxDepth: Infinity } }, limits);
277
+ let failed = false;
278
+ try {
279
+ let prefix = "", suffix = "";
280
+ for await (const character of characters(await types.get(part))) {
281
+ if (character === ";") break;
282
+ if (!character.trim()) continue;
283
+ if (prefix.length < 16) prefix += character.toLowerCase();
284
+ suffix = (suffix + character.toLowerCase()).slice(-4);
285
+ }
286
+ if (prefix !== "application/xml" && prefix !== "text/xml" && suffix !== "+xml") throw new OfficeError("unsupported-profile", "The selected part is not XML.", "select");
287
+ } catch (error) {
288
+ failed = true;
289
+ throw error;
290
+ } finally {
291
+ try {
292
+ await types.close();
293
+ } catch (error) {
294
+ if (!failed) await Promise.reject(error);
295
+ }
296
+ }
297
+ }
298
+ const context = { ...settings, xmlLimits: limits };
299
+ const document = await openRetainedXmlDocument(archive.read(part), context);
300
+ await document.close();
301
+ const xml = await openRetainedXml(archive.read(part), context);
302
+ let spans, closed = false, closing;
303
+ const check = () => {
304
+ if (closed) throw new OfficeError("invalid-handle", "XML part is closed.", "select");
305
+ if (settings.signal?.aborted) throw new OfficeError("cancelled", "Operation cancelled.", "select");
306
+ };
307
+ const close = () => {
308
+ closed = true;
309
+ return closing ??= (async () => {
310
+ const results = await Promise.allSettled([xml.close(), spans?.close()]);
311
+ for (const result of results) if (result.status === "rejected") throw result.reason;
312
+ })();
313
+ };
314
+ try {
315
+ if (pretty2) spans = await prettySpans(xml, context);
316
+ return Object.freeze({
317
+ part,
318
+ format: pretty2 ? "pretty" : "original",
319
+ close,
320
+ async *bytes() {
321
+ check();
322
+ for await (const bytes of archive.read(part)) {
323
+ check();
324
+ yield bytes;
325
+ }
326
+ check();
327
+ },
328
+ async *xml() {
329
+ check();
330
+ const source = spans ? spans.render() : xml.read({ start: 0, length: xml.byteLength });
331
+ let count = 0;
332
+ for await (const bytes of source) {
333
+ check();
334
+ count += bytes.length;
335
+ if (spans?.formatted && count > limits.maxBytes) throw new OfficeError("resource-limit", "Pretty XML byte limit exceeded.", "serialize");
336
+ yield bytes;
337
+ }
338
+ check();
339
+ }
340
+ });
341
+ } catch (error) {
342
+ await close().catch(() => {
343
+ });
344
+ throw error;
345
+ }
346
+ }
347
+ async function stageRetainedXmlPart(archive, fingerprint, selection, settings, output) {
348
+ const options = { ...selection }, format = { ...output }, index = await openRetainedPresentationIndex(archive, fingerprint, settings);
349
+ let xml, staged;
350
+ try {
351
+ let metadata = false;
352
+ if (options.scope === "shared" && options.part) {
353
+ metadata = options.part === "/[Content_Types].xml" || options.part === packageUri("/").relsUri;
354
+ if (!metadata) {
355
+ for await (const record2 of index.records.records("part")) if (packageUri(record2.part).relsUri === options.part) {
356
+ metadata = true;
357
+ break;
358
+ }
359
+ }
360
+ }
361
+ async function* selected() {
362
+ if (options.token) {
363
+ yield* index.records.select({ token: options.token });
364
+ return;
365
+ }
366
+ const scope = options.scope ?? "slides", all = options.all ?? false;
367
+ if (options.slide !== void 0) for await (const slide of index.records.select({ kind: "slide", position: { coordinateSystem: "one-based", value: options.slide } })) {
368
+ if (options.shape) yield* index.records.select({ kind: "object", owner: slide.part, name: options.shape, scope, all });
369
+ else yield slide;
370
+ }
371
+ else if (options.part) yield* index.records.select(options.shape ? { kind: "object", owner: options.part, name: options.shape, scope, all } : { kind: "part", part: options.part, scope, all });
372
+ else if (scope === "slides") yield* index.records.records("slide");
373
+ else for await (const record2 of index.records.records("part")) if (record2.location.scope === scope) yield record2;
374
+ }
375
+ let record, count = 0;
376
+ if (!metadata) {
377
+ for await (const item of selected()) {
378
+ record = item;
379
+ count++;
380
+ }
381
+ if (count !== 1 || record.kind === "object") throw new SelectionError("invalid-selection");
382
+ }
383
+ const part = metadata ? options.part : record.part;
384
+ const location = metadata ? { fingerprint, scope: "shared", owner: part, objectId: part, coordinateSystem: "identity" } : record.location;
385
+ xml = await openRetainedXmlPart(archive, part, settings, { pretty: format.pretty ?? false });
386
+ const data = xml;
387
+ async function* render() {
388
+ if (format.json) {
389
+ yield* streamJson({ version: 1, operation: "xml.get", ok: true, data: { part, format: data.format, xml: data.xml }, warnings: [], errors: [], affected: 0, locations: [location] });
390
+ yield* literal("\n");
391
+ } else if (format.pretty) {
392
+ yield* literal("Pretty XML (not original bytes)\n");
393
+ yield* data.xml();
394
+ yield* literal("\n");
395
+ } else yield* data.bytes();
396
+ }
397
+ staged = await stageRetainedOutput(render(), settings, format.maxOutputBytes);
398
+ await xml.close();
399
+ await index.close();
400
+ return staged;
401
+ } catch (error) {
402
+ await Promise.allSettled([xml?.close(), index.close(), staged?.close()]);
403
+ throw error;
404
+ }
405
+ }
406
+
407
+ // packages/safe-bash-presentation-engine/src/xml-parts.ts
147
408
  var namespaces = [
148
409
  "http://schemas.openxmlformats.org/presentationml/2006/main",
149
410
  "http://purl.oclc.org/ooxml/presentationml/main"
@@ -449,6 +710,8 @@ function validateXmlPartReplacement(reader, part, bytes, context) {
449
710
 
450
711
  export {
451
712
  validateXmlViewReplacement,
713
+ openRetainedXmlPart,
714
+ stageRetainedXmlPart,
452
715
  getXmlPart,
453
716
  replaceXmlPart,
454
717
  validateXmlPartReplacement
@@ -2,7 +2,7 @@ import {
2
2
  g
3
3
  } from "./chunk-Z7ESJVFP.js";
4
4
 
5
- // packages/safe-bash-command-ssconvert/dist/chunks/chunk-LMJ46OBK.js
5
+ // packages/safe-bash-command-ssconvert/dist/chunks/chunk-GL2HE4HF.js
6
6
  import { createEngine as vt } from "../../spreadsheet-engine/index.js";
7
7
  import { SsconvertError as O } from "../../spreadsheet-engine/contracts.js";
8
8
  import { decodeTextSource as ot } from "../../spreadsheet-engine/encoding/decode-source.js";
@@ -35,13 +35,13 @@ var te = { id: "Gnumeric_applix", services: [{ id: "applix", direction: "read",
35
35
  var re = { id: "Gnumeric_dif", services: [{ id: "dif", direction: "read", read: async (e, t) => (await import("./dif-BXKPQOCO-4KB3RC6G.js")).readDif(e, t), description: "Data Interchange Format (*.dif)", extensions: ["dif"], probePriority: 1 }, { id: "dif", direction: "write", write: async (e, t, i) => (await import("./dif-BXKPQOCO-4KB3RC6G.js")).writeDif(e, t, i), description: "Data Interchange Format (*.dif)", extensions: ["dif"], formatLevel: "manual_remember", saveScope: "sheet", selectionSource: "view" }], source: "plugins/dif/plugin.xml.in" };
36
36
  var Qe = ["xor", "rc4", ...[false, true].flatMap((e) => [40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128].map((t) => `rc4-cryptoapi-${t}${e ? "-properties" : ""}`))];
37
37
  var ie = ["xor"];
38
- var W = { id: "Gnumeric_Excel", source: "plugins/excel/plugin.xml.in", services: [{ id: "excel", direction: "read", readWorkbookSource: async (...e) => (await import("./biff-DS263V2K-2GP4GZT7.js")).readBiffWorkbookSource(...e), readSource: async (...e) => (await import("./biff-DS263V2K-2GP4GZT7.js")).readBiff(...e), probeSource: async (...e) => (await import("./biff-DS263V2K-2GP4GZT7.js")).probeBiff(...e), read: async (...e) => (await import("./biff-DS263V2K-2GP4GZT7.js")).readBiff(...e), probeContent: async (...e) => (await import("./biff-DS263V2K-2GP4GZT7.js")).probeBiff(...e), description: "MS Excel\u2122 (*.xls)", extensions: ["xls", "xlw", "xlt"], mimeTypes: ["application/vnd.ms-excel", "application/excel", "application/msexcel", "application/x-excel", "application/x-ms-excel", "application/x-msexcel", "application/x-xls", "application/xls", "application/x-dos_ms_excel", "zz-application/zz-winassoc-xls"], probePriority: 100, contentProbe: true }, { id: "excel_biff8", write: async (...e) => (await import("./biff-DS263V2K-2GP4GZT7.js")).createBiffWriter(8)(...e), writeStream: async function* (...e) {
39
- yield* (await import("./biff-DS263V2K-2GP4GZT7.js")).createBiffStreamWriter(8)(...e);
40
- }, labelRanges: true, exportOptionRules: { encryption: { kind: "enum", values: Qe } }, direction: "write", description: "MS Excel\u2122 97/2000/XP", extensions: ["xls"], mimeTypes: ["application/vnd.ms-excel"], formatLevel: "auto", defaultSaverPriority: 1 }, { id: "excel_biff7", write: async (...e) => (await import("./biff-DS263V2K-2GP4GZT7.js")).createBiffWriter(7)(...e), writeStream: async function* (...e) {
41
- yield* (await import("./biff-DS263V2K-2GP4GZT7.js")).createBiffStreamWriter(7)(...e);
42
- }, labelRanges: true, exportOptionRules: { encryption: { kind: "enum", values: ie } }, direction: "write", description: "MS Excel\u2122 5.0/95", extensions: ["xls"], mimeTypes: ["application/vnd.ms-excel"], formatLevel: "auto" }, { id: "excel_dsf", write: async (...e) => (await import("./biff-DS263V2K-2GP4GZT7.js")).createBiffWriter("dsf")(...e), writeStream: async function* (...e) {
43
- yield* (await import("./biff-DS263V2K-2GP4GZT7.js")).createBiffStreamWriter("dsf")(...e);
44
- }, labelRanges: true, exportOptionRules: { encryption: { kind: "enum", values: ie } }, direction: "write", description: "MS Excel\u2122 97/2000/XP & 5.0/95", extensions: ["xls"], mimeTypes: ["application/vnd.ms-excel"], formatLevel: "auto" }, { id: "excel_enc", direction: "read", read: async (...e) => (await import("./biff-DS263V2K-2GP4GZT7.js")).readBiff(...e), description: "MS Excel\u2122 (*.xls) requiring encoding specification", extensions: [], probePriority: 200, encodingDependent: true }] };
38
+ var W = { id: "Gnumeric_Excel", source: "plugins/excel/plugin.xml.in", services: [{ id: "excel", direction: "read", readWorkbookSource: async (...e) => (await import("./biff-ORSHM4YX-QYPGRDAZ.js")).readBiffWorkbookSource(...e), readSource: async (...e) => (await import("./biff-ORSHM4YX-QYPGRDAZ.js")).readBiff(...e), probeSource: async (...e) => (await import("./biff-ORSHM4YX-QYPGRDAZ.js")).probeBiff(...e), read: async (...e) => (await import("./biff-ORSHM4YX-QYPGRDAZ.js")).readBiff(...e), probeContent: async (...e) => (await import("./biff-ORSHM4YX-QYPGRDAZ.js")).probeBiff(...e), description: "MS Excel\u2122 (*.xls)", extensions: ["xls", "xlw", "xlt"], mimeTypes: ["application/vnd.ms-excel", "application/excel", "application/msexcel", "application/x-excel", "application/x-ms-excel", "application/x-msexcel", "application/x-xls", "application/xls", "application/x-dos_ms_excel", "zz-application/zz-winassoc-xls"], probePriority: 100, contentProbe: true }, { id: "excel_biff8", write: async (...e) => (await import("./biff-ORSHM4YX-QYPGRDAZ.js")).createBiffWriter(8)(...e), writeStream: async function* (...e) {
39
+ yield* (await import("./biff-ORSHM4YX-QYPGRDAZ.js")).createBiffStreamWriter(8)(...e);
40
+ }, labelRanges: true, exportOptionRules: { encryption: { kind: "enum", values: Qe } }, direction: "write", description: "MS Excel\u2122 97/2000/XP", extensions: ["xls"], mimeTypes: ["application/vnd.ms-excel"], formatLevel: "auto", defaultSaverPriority: 1 }, { id: "excel_biff7", write: async (...e) => (await import("./biff-ORSHM4YX-QYPGRDAZ.js")).createBiffWriter(7)(...e), writeStream: async function* (...e) {
41
+ yield* (await import("./biff-ORSHM4YX-QYPGRDAZ.js")).createBiffStreamWriter(7)(...e);
42
+ }, labelRanges: true, exportOptionRules: { encryption: { kind: "enum", values: ie } }, direction: "write", description: "MS Excel\u2122 5.0/95", extensions: ["xls"], mimeTypes: ["application/vnd.ms-excel"], formatLevel: "auto" }, { id: "excel_dsf", write: async (...e) => (await import("./biff-ORSHM4YX-QYPGRDAZ.js")).createBiffWriter("dsf")(...e), writeStream: async function* (...e) {
43
+ yield* (await import("./biff-ORSHM4YX-QYPGRDAZ.js")).createBiffStreamWriter("dsf")(...e);
44
+ }, labelRanges: true, exportOptionRules: { encryption: { kind: "enum", values: ie } }, direction: "write", description: "MS Excel\u2122 97/2000/XP & 5.0/95", extensions: ["xls"], mimeTypes: ["application/vnd.ms-excel"], formatLevel: "auto" }, { id: "excel_enc", direction: "read", read: async (...e) => (await import("./biff-ORSHM4YX-QYPGRDAZ.js")).readBiff(...e), description: "MS Excel\u2122 (*.xls) requiring encoding specification", extensions: [], probePriority: 200, encodingDependent: true }] };
45
45
  var oe = { id: "Gnumeric_Excel", source: "plugins/excel/plugin.xml.in", services: [{ id: "xlsx", direction: "read", probeContent: async (e, t) => (await import("./xlsx-RE54MFCS-DI3F765V.js")).probeXlsx(e, t), probeSource: async (e, t) => (await import("./xlsx-RE54MFCS-DI3F765V.js")).probeXlsx(e, t), readWorkbookSource: async (e, t) => (await import("./xlsx-RE54MFCS-DI3F765V.js")).readXlsx(e, t, true), readSource: async (e, t) => (await import("./xlsx-RE54MFCS-DI3F765V.js")).readXlsx(e, t), read: async (e, t) => (await import("./xlsx-RE54MFCS-DI3F765V.js")).readXlsx(e, t), description: "ECMA 376 / Office Open XML [MS Excel\u2122 2007/2010] (*.xlsx)", extensions: ["xlsx", "xltx", "xlsb", "xlsm", "xltm"], mimeTypes: ["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "application/vnd.openxmlformats-officedocument.spreadsheetml.template"], probePriority: 100, contentProbe: true }, { id: "xlsx", direction: "write", sourceAxes: true, write: async (e, t, i) => (await import("./xlsx-RE54MFCS-DI3F765V.js")).createXlsxWriter("2006")(e, t, i), writeStream: async function* (e, t, i) {
46
46
  yield* (await import("./xlsx-RE54MFCS-DI3F765V.js")).createXlsxStreamWriter("2006")(e, t, i);
47
47
  }, writeWorkbookSource: async function* (e, t, i) {
@@ -72,7 +72,7 @@ var j = { id: "Gnumeric_OpenCalc", services: [{ id: "openoffice", direction: "re
72
72
  yield* (await import("./odf-3EA3EVSD-7B5GVNTC.js")).createOdfStreamWriter("extended")(e, t, i);
73
73
  }, labelRanges: true, exportOptionRules: { encryption: { kind: "enum", values: pe } }, description: "ODF 1.2 extended conformance (*.ods)", extensions: ["ods"], mimeTypes: ["application/vnd.oasis.opendocument.spreadsheet"], formatLevel: "auto" }], source: "plugins/openoffice/plugin.xml.in" };
74
74
  var fe = { id: "Gnumeric_paradox", services: [{ id: "paradox", direction: "read", read: async (e, t) => (await import("./paradox-ZWWXYY4J-JYOSWSBL.js")).readParadox(e, t), description: "Paradox database or primary index file (*.db, *.px)", extensions: ["db", "px"], probePriority: 100 }, { id: "paradox", direction: "write", write: async (e, t, i) => (await import("./paradox-ZWWXYY4J-JYOSWSBL.js")).writeParadox(e, t, i), exportOptionRules: { encryption: { kind: "enum", values: ["paradox"] } }, description: "Paradox database (*.db)", extensions: ["db"] }], source: "plugins/paradox/plugin.xml.in" };
75
- var xe = { id: "Gnumeric_pdf", source: "src/print-info.c:1074", services: [{ id: "pdf_assistant", direction: "write", description: "PDF export", extensions: ["pdf"], sheetSelection: true, honorsExportRange: false, write: async (...e) => (await import("./pdf-T7AWYZGQ-KNAYJ7YF.js")).writePdf(...e), exportOptions: async (...e) => (await import("./pdf-T7AWYZGQ-KNAYJ7YF.js")).pdfExportOptions(...e), exportOptionRules: { object: { kind: "string" }, paper: { kind: "string" } } }] };
75
+ var xe = { id: "Gnumeric_pdf", source: "src/print-info.c:1074", services: [{ id: "pdf_assistant", direction: "write", description: "PDF export", extensions: ["pdf"], sheetSelection: true, honorsExportRange: false, write: async (...e) => (await import("./pdf-LOZAXXS6-ERI57IAV.js")).writePdf(...e), exportOptions: async (...e) => (await import("./pdf-LOZAXXS6-ERI57IAV.js")).pdfExportOptions(...e), exportOptionRules: { object: { kind: "string" }, paper: { kind: "string" } } }] };
76
76
  var we = { id: "Gnumeric_plan_perfect", services: [{ id: "pln", direction: "read", probeContent: async (e, t) => (await import("./pln-DFS7VLVS-JATX6FS7.js")).probePln(e, t), read: async (e, t) => (await import("./pln-DFS7VLVS-JATX6FS7.js")).readPln(e, t), description: "Plan Perfect Format (PLN) import", extensions: ["pln"], mimeTypes: ["application/x-planperfect"], probePriority: 1, contentProbe: true }], source: "plugins/plan-perfect/plugin.xml.in" };
77
77
  var ye = { id: "Gnumeric_psiconv", services: [{ id: "psiconv", direction: "read", probeContent: async (e, t) => (await import("./psion-YBI6JEQI-6OMC2PGC.js")).probePsion(e, t), read: async (e, t) => (await import("./psion-YBI6JEQI-6OMC2PGC.js")).readPsion(e, t), description: "Psion (*.psisheet)", extensions: ["psisheet"], probePriority: 100, contentProbe: true }], source: "plugins/psiconv/plugin.xml.in" };
78
78
  var he = { id: "Gnumeric_QPro", services: [{ id: "qpro", direction: "read", probeContent: async (e, t) => (await import("./qpro-WLWWL7C3-XZ5DBS44.js")).probeQpro(e, t), read: async (e, t) => (await import("./qpro-WLWWL7C3-XZ5DBS44.js")).readQpro(e, t), description: "Quattro Pro (*.wb1, *.wb2, *.wb3)", extensions: ["wb1", "wb2", "wb3"], mimeTypes: ["application/x-quattropro", "application/x-quattro-pro"], probePriority: 100, contentProbe: true }], source: "plugins/qpro/plugin.xml.in" };
@@ -83,6 +83,68 @@ async function attributes(element, inherited, budget, exclusive) {
83
83
  });
84
84
  return selected;
85
85
  }
86
+ var StoredFrames = class {
87
+ constructor(document) {
88
+ this.document = document;
89
+ }
90
+ document;
91
+ head = 0;
92
+ namespaces = /* @__PURE__ */ new WeakMap();
93
+ async store(value) {
94
+ const bytes = new TextEncoder().encode(JSON.stringify(value));
95
+ const header = new Uint8Array(8);
96
+ new DataView(header.buffer).setFloat64(0, bytes.length, true);
97
+ const reference = await this.document.storage.append(header);
98
+ await this.document.storage.append(bytes);
99
+ return reference;
100
+ }
101
+ async load(reference) {
102
+ const size = await this.document.storage.read(reference, 8);
103
+ const length = new DataView(size.buffer, size.byteOffset, 8).getFloat64(0, true);
104
+ return JSON.parse(new TextDecoder().decode(await this.document.storage.read(reference + 8, length)));
105
+ }
106
+ async push(source) {
107
+ let reversed = 0;
108
+ for await (const frame of source) {
109
+ const checkpoint = this.document.budget.tick();
110
+ if (checkpoint) await checkpoint;
111
+ let namespaces = this.namespaces.get(frame.namespaces);
112
+ if (namespaces === void 0) {
113
+ namespaces = await this.store([...frame.namespaces]);
114
+ this.namespaces.set(frame.namespaces, namespaces);
115
+ }
116
+ const value = await this.store({ ...frame, namespaces });
117
+ const link = new Uint8Array(16), view = new DataView(link.buffer);
118
+ view.setFloat64(0, reversed, true);
119
+ view.setFloat64(8, value, true);
120
+ reversed = await this.document.storage.append(link);
121
+ }
122
+ while (reversed) {
123
+ const checkpoint = this.document.budget.tick();
124
+ if (checkpoint) await checkpoint;
125
+ const link = await this.document.storage.read(reversed, 8);
126
+ const view = new DataView(link.buffer, link.byteOffset, 8), previous = view.getFloat64(0, true);
127
+ view.setFloat64(0, this.head, true);
128
+ await this.document.storage.write(reversed, link);
129
+ this.head = reversed;
130
+ reversed = previous;
131
+ }
132
+ }
133
+ async pop() {
134
+ if (!this.head) return void 0;
135
+ const link = await this.document.storage.read(this.head, 16);
136
+ const view = new DataView(link.buffer, link.byteOffset, 16);
137
+ this.head = view.getFloat64(0, true);
138
+ const frame = await this.load(view.getFloat64(8, true));
139
+ const namespaces = new Map(await this.load(frame.namespaces));
140
+ this.namespaces.set(namespaces, frame.namespaces);
141
+ return { ...frame, namespaces };
142
+ }
143
+ };
144
+ function* indentation(depth) {
145
+ yield "\n";
146
+ for (let left = depth; left > 0; left -= 2048) yield " ".repeat(Math.min(left, 2048));
147
+ }
86
148
  async function* serializeDocument(source, mode, budget, format = mode === "format", options = {}) {
87
149
  const stored = source instanceof StoredXmlDocument ? source : void 0;
88
150
  const rootReference = stored ? stored.root : source;
@@ -100,16 +162,26 @@ async function* serializeDocument(source, mode, budget, format = mode === "forma
100
162
  const documentDeclaration = options.declaration ?? root.declaration;
101
163
  const escaping = { canonical, ascii: !canonical && !documentDeclaration?.includes("encoding") };
102
164
  if (canonical) {
103
- const pending2 = [(async function* () {
104
- yield rootReference;
105
- })()];
106
- while (pending2.length) {
107
- const next = await pending2.at(-1).next();
108
- if (next.done) {
109
- pending2.pop();
110
- continue;
165
+ async function* descendants() {
166
+ if (stored) {
167
+ for await (const entry of stored.walk(stored.root)) if (!entry.closing) yield entry.reference;
168
+ } else {
169
+ const pending2 = [(async function* () {
170
+ yield rootReference;
171
+ })()];
172
+ while (pending2.length) {
173
+ const next = await pending2.at(-1).next();
174
+ if (next.done) {
175
+ pending2.pop();
176
+ continue;
177
+ }
178
+ yield next.value;
179
+ pending2.push(children(next.value));
180
+ }
111
181
  }
112
- const element = await load(next.value);
182
+ }
183
+ for await (const reference of descendants()) {
184
+ const element = await load(reference);
113
185
  if (element.kind !== "element") continue;
114
186
  {
115
187
  const p = budget.tick();
@@ -128,7 +200,6 @@ async function* serializeDocument(source, mode, budget, format = mode === "forma
128
200
  }
129
201
  if (!absolute) throw new XmlQueryError("Failed to canonicalize: relative namespace URI", 6);
130
202
  }
131
- pending2.push(children(next.value));
132
203
  }
133
204
  } else yield declaration(documentDeclaration);
134
205
  const namespaces = /* @__PURE__ */ new Map([["xml", xml]]);
@@ -196,18 +267,29 @@ async function* serializeDocument(source, mode, budget, format = mode === "forma
196
267
  await iterator.return(void 0);
197
268
  }
198
269
  }
199
- const pending = [documentFrames()];
200
- while (pending.length) {
270
+ const pending = [];
271
+ const frames = stored ? new StoredFrames(stored) : void 0;
272
+ async function push(source2) {
273
+ if (frames) await frames.push(source2);
274
+ else pending.push(source2[Symbol.asyncIterator]());
275
+ }
276
+ await push(documentFrames());
277
+ while (true) {
201
278
  {
202
279
  const p = budget.tick();
203
280
  if (p) await p;
204
281
  }
205
- const next = await pending.at(-1).next();
206
- if (next.done) {
207
- pending.pop();
208
- continue;
282
+ let frame;
283
+ if (frames) frame = await frames.pop();
284
+ else while (pending.length) {
285
+ const next = await pending.at(-1).next();
286
+ if (next.done) pending.pop();
287
+ else {
288
+ frame = next.value;
289
+ break;
290
+ }
209
291
  }
210
- const frame = next.value;
292
+ if (!frame) break;
211
293
  if (typeof frame.content === "string") {
212
294
  yield frame.content;
213
295
  continue;
@@ -259,17 +341,21 @@ async function* serializeDocument(source, mode, budget, format = mode === "forma
259
341
  }
260
342
  yield ">";
261
343
  const indent = !canonical && format && !frame.inline && !mixed && count > 0;
262
- const childNamespaces = new Map(frame.namespaces);
263
- if (canonical) for (const attribute of ordered) {
264
- if (attribute.namespace === xmlns) childNamespaces.set(attribute.localName, attribute.value);
344
+ let childNamespaces = frame.namespaces;
345
+ if (canonical && ordered.some((attribute) => attribute.namespace === xmlns)) {
346
+ const changed = new Map(frame.namespaces);
347
+ for (const attribute of ordered) if (attribute.namespace === xmlns) changed.set(attribute.localName, attribute.value);
348
+ childNamespaces = changed;
265
349
  }
266
350
  const childFrame = { depth: frame.depth + 1, namespaces: childNamespaces, preserveSpace, preserveBlanks, inline: frame.inline || mixed };
267
- pending.push((async function* () {
351
+ const parentFrame = frame;
352
+ await push((async function* () {
268
353
  for await (const child of selectedChildren(reference, preserveSpace, preserveBlanks)) {
269
- if (indent) yield { ...childFrame, content: "\n" + " ".repeat(childFrame.depth) };
354
+ if (indent) for (const part of indentation(childFrame.depth)) yield { ...childFrame, content: part };
270
355
  yield { ...childFrame, content: child.reference };
271
356
  }
272
- yield { ...frame, content: `${indent ? "\n" + " ".repeat(frame.depth) : ""}</${current.name}>` };
357
+ if (indent) for (const part of indentation(parentFrame.depth)) yield { ...parentFrame, content: part };
358
+ yield { ...parentFrame, content: `</${current.name}>` };
273
359
  })());
274
360
  } else if (current.kind === "text" || current.kind === "cdata" && canonical) {
275
361
  for await (const part of typeof reference === "number" ? stored.text(reference) : [current.text])