@poe-platform/safe-bash 0.1.839 → 0.1.841

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 (68) hide show
  1. package/dist/audio-ast/binary.d.ts +19 -0
  2. package/dist/audio-ast/index.d.ts +1 -0
  3. package/dist/audio-ast/index.js +92 -91
  4. package/dist/audio-ast/mpeg.d.ts +23 -0
  5. package/dist/mp4-ast/containers/adapters.d.ts +1 -0
  6. package/dist/mp4-ast/types.d.ts +8 -2
  7. package/dist/pdf-ast/cos/security.d.ts +10 -0
  8. package/dist/pdf-ast/edit/retained-attachment-edits.d.ts +4 -0
  9. package/dist/pdf-ast/edit/retained-graph.d.ts +1 -1
  10. package/dist/pdf-ast/image.js +1 -1
  11. package/dist/pdf-ast/index.d.ts +2 -1
  12. package/dist/pdf-ast/index.js +7 -1
  13. package/dist/pdf-ast/vendor/pdfjs-fonts.d.mts +8 -0
  14. package/dist/pdf-ast/vendor/pdfjs-fonts.mjs +28 -0
  15. package/dist/safe-bash/audio-ast.browser.js +2 -1
  16. package/dist/safe-bash/audio-ast.js +1 -1
  17. package/dist/safe-bash/command-chunks/{chunk-SG2KOOD4.js → chunk-3SAYZFMD.js} +2 -2
  18. package/dist/safe-bash/command-chunks/{chunk-T6OXG7QQ.js → chunk-AAOPVEPF.js} +66 -1
  19. package/dist/safe-bash/command-chunks/{chunk-FH5VMAPS.js → chunk-BZW25LNV.js} +420 -131
  20. package/dist/safe-bash/command-chunks/{chunk-DQVOBGI2.js → chunk-CIV3GER2.js} +6770 -6523
  21. package/dist/safe-bash/command-chunks/{chunk-46GA576V.js → chunk-CPKVUB7S.js} +2 -2
  22. package/dist/safe-bash/command-chunks/{chunk-MBXNG6C3.js → chunk-DLLN3C3Q.js} +1 -1
  23. package/dist/safe-bash/command-chunks/{chunk-ZSQCROFE.js → chunk-DM5T5D2K.js} +5 -1
  24. package/dist/safe-bash/command-chunks/{chunk-3EAZRKI4.js → chunk-G7HQYFIU.js} +10 -1
  25. package/dist/safe-bash/command-chunks/{chunk-GYKQ3IOV.js → chunk-LMYQMJYY.js} +94 -18
  26. package/dist/safe-bash/command-chunks/{chunk-DX7KU6YU.js → chunk-N52AHO6S.js} +1 -1
  27. package/dist/safe-bash/command-chunks/{chunk-4BSD2RGK.js → chunk-QPKL5GWH.js} +102 -42
  28. package/dist/safe-bash/command-chunks/{chunk-Z2T7E4ID.js → chunk-R7QLP5RH.js} +1212 -1119
  29. package/dist/safe-bash/command-chunks/{chunk-77ROD2TR.js → chunk-X3WNWRVT.js} +11 -5
  30. package/dist/safe-bash/command-chunks/{chunk-RSFKQE2U.js → chunk-YAXP4EHP.js} +19 -10
  31. package/dist/safe-bash/command-chunks/{chunk-TCXM7BSZ.js → chunk-YFMNXPLP.js} +4 -4
  32. package/dist/safe-bash-command-exiftool/index.js +25 -1
  33. package/dist/safe-bash-command-ffmpeg/index.js +191 -49
  34. package/dist/safe-bash-command-ffprobe/index.js +2 -2
  35. package/dist/safe-bash-command-ffprobe/media.js +2 -2
  36. package/dist/safe-bash-command-imagemagick/index.js +498 -101
  37. package/dist/safe-bash-command-mdq/index.js +2 -0
  38. package/dist/safe-bash-command-pandoc/citeproc-filters.js +7 -7
  39. package/dist/safe-bash-command-pandoc/command.js +8 -8
  40. package/dist/safe-bash-command-pandoc/index.js +52 -52
  41. package/dist/safe-bash-command-qpdf/index.js +1037 -654
  42. package/dist/safe-bash-command-qpdf/page-range.d.ts +2 -0
  43. package/dist/safe-bash-command-soffice/index.js +28 -8
  44. package/dist/safe-bash-command-sqlite3/btree.d.ts +2 -1
  45. package/dist/safe-bash-command-sqlite3/engine.d.ts +15 -1
  46. package/dist/safe-bash-command-sqlite3/index.js +294 -68
  47. package/dist/safe-bash-command-tar/create.js +2 -2
  48. package/dist/safe-bash-command-tar/extract.js +2 -2
  49. package/dist/safe-bash-command-tar/format.js +1 -1
  50. package/dist/safe-bash-command-tar/index.js +4 -4
  51. package/dist/safe-bash-command-tar/modes.js +4 -4
  52. package/dist/safe-bash-command-unzip/index.js +1 -1
  53. package/dist/safe-bash-command-unzip/unzip.js +1 -1
  54. package/dist/safe-bash-markdown-engine/commonmark-blocks.d.ts +17 -1
  55. package/dist/safe-bash-markdown-engine/commonmark-blocks.js +3 -3
  56. package/dist/safe-bash-markdown-engine/commonmark-inlines.d.ts +1 -1
  57. package/dist/safe-bash-markdown-engine/commonmark-inlines.js +3 -3
  58. package/dist/safe-bash-markdown-engine/commonmark-syntax.d.ts +5 -0
  59. package/dist/safe-bash-markdown-engine/commonmark-syntax.js +5 -1
  60. package/dist/safe-bash-markdown-engine/gfm-syntax.js +2 -2
  61. package/dist/safe-bash-markdown-engine/index.js +4 -4
  62. package/dist/safe-bash-zip-engine/index.js +1 -1
  63. package/dist/safe-bash-zip-engine/zip/repair.js +1 -1
  64. package/dist/safe-bash-zip-engine/zip/sfx.js +1 -1
  65. package/dist/safe-bash-zip-engine/zip-format.d.ts +2 -0
  66. package/dist/safe-bash-zip-engine/zip-format.js +1 -1
  67. package/package.json +2 -2
  68. package/third-party/pdf-ast/THIRD_PARTY_NOTICES.md +2 -0
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  createArchive,
3
3
  manifest
4
- } from "./chunk-MBXNG6C3.js";
4
+ } from "./chunk-DLLN3C3Q.js";
5
5
  import {
6
6
  readArchive
7
- } from "./chunk-SG2KOOD4.js";
7
+ } from "./chunk-3SAYZFMD.js";
8
8
  import {
9
9
  quoteName
10
10
  } from "./chunk-PYIG32ZI.js";
@@ -12,7 +12,7 @@ import {
12
12
  } from "./chunk-LSYPQ2W5.js";
13
13
  import {
14
14
  encodeEntry
15
- } from "./chunk-TCXM7BSZ.js";
15
+ } from "./chunk-YFMNXPLP.js";
16
16
 
17
17
  // packages/safe-bash-command-tar/src/create.ts
18
18
  import { compareIdentity as compareIdentity2, compareFileVersion } from "@poe-platform/safe-fs/contracts";
@@ -288,7 +288,11 @@ function createUnzipCommand(options = {}) {
288
288
  }
289
289
  let parent = await extraction.operation(() => context.fs.lstat(dirname(path), { signal: context.signal }));
290
290
  let existing = await extraction.destination(path, archivePath, archiveStat);
291
- if (parsed.update && existing && Math.ceil(Math.floor(existing.mtimeMs / 1e3) / 2) * 2e3 >= entry.modified.getTime()) continue;
291
+ if (parsed.update && existing) {
292
+ const seconds = Math.floor(existing.mtimeMs / 1e3);
293
+ const modified = entry.extendedTimestamp ? seconds * 1e3 : Math.ceil(seconds / 2) * 2e3;
294
+ if (modified >= entry.modified.getTime()) continue;
295
+ }
292
296
  let skip = false;
293
297
  let prompting = 0;
294
298
  while (existing && overwrite !== "all") {
@@ -246,7 +246,15 @@ function extras(bytes, rawName, comment, central, limits) {
246
246
  }
247
247
  function nameFrom(rawName, flags, metadata, limits) {
248
248
  number(rawName.length, Math.min(limits.maxPathBytes, 65535), "raw path byte");
249
- const raw = flags & 2048 ? text(rawName) : legacyName(rawName);
249
+ let raw;
250
+ if (flags & 2048) raw = text(rawName);
251
+ else {
252
+ try {
253
+ raw = text(rawName);
254
+ } catch {
255
+ raw = legacyName(rawName);
256
+ }
257
+ }
250
258
  pathBytes(raw, limits);
251
259
  if (flags & 2048 && metadata.name !== void 0 && metadata.name !== raw) fail2("ZIP conflicting UTF-8 and Unicode extra names");
252
260
  return metadata.name ?? raw;
@@ -448,6 +456,7 @@ async function openZipDirectory(input, limits, signal, profile = {}) {
448
456
  if (timestamp !== void 0) modified.setTime(timestamp);
449
457
  const entry = { name, data: buffered ? await bytes.subarray(payloadStart, payloadStart + compressedSize) : new Uint8Array(), ...buffered ? {} : { compressedSize, compressedOffset: payloadStart, compressedSource: () => bytes.stream(payloadStart, compressedSize) }, size, method, crc32: checksum, modified, mode, directory, symlink, rawName, localName, comment, localExtra, centralExtra, flags, versionMadeBy, internalAttributes, externalAttributes, dosTime, dosDate };
450
458
  if (aes) entry.aes = aes;
459
+ entry.extendedTimestamp = timestamp !== void 0;
451
460
  entryBounds(entry, limits);
452
461
  if ((profile.grow || !buffered) && (centralMetadata.zip64 || localMetadata.zip64)) entry.zip64 = true;
453
462
  if (profile.grow) {
@@ -1,9 +1,11 @@
1
1
  import {
2
2
  pipeRow
3
- } from "./chunk-DX7KU6YU.js";
3
+ } from "./chunk-N52AHO6S.js";
4
4
  import {
5
- normalizeLabel
6
- } from "./chunk-T6OXG7QQ.js";
5
+ fencedDivAttributes,
6
+ normalizeLabel,
7
+ romanListNumber
8
+ } from "./chunk-AAOPVEPF.js";
7
9
 
8
10
  // packages/safe-bash-markdown-engine/src/commonmark-blocks.ts
9
11
  function spaces(text, offset) {
@@ -77,22 +79,30 @@ function fence(text, offset) {
77
79
  if (end - offset < 3 || char === "`" && text.indexOf("`", end) !== -1) return;
78
80
  return { char, length: end - offset };
79
81
  }
80
- function marker(text, offset) {
82
+ function marker(text, offset, fancy = false) {
81
83
  let end = offset;
82
84
  let start = null;
85
+ let style;
83
86
  let char = text[end];
84
87
  if (char === "-" || char === "+" || char === "*") end++;
85
88
  else {
86
89
  while (text[end] !== void 0 && text[end] >= "0" && text[end] <= "9" && end - offset < 10) end++;
87
- if (end === offset || end - offset > 9 || text[end] !== "." && text[end] !== ")") return;
88
- start = Number(text.slice(offset, end));
90
+ if (end === offset && fancy) {
91
+ while (end - offset < 16 && text[end] && "ivxlcdmIVXLCDM".includes(text[end])) end++;
92
+ const label = text.slice(offset, end), number = romanListNumber(label);
93
+ if (number === void 0) return;
94
+ start = number;
95
+ style = label === label.toLowerCase() ? "LowerRoman" : "UpperRoman";
96
+ }
97
+ if (end === offset || !style && end - offset > 9 || text[end] !== "." && text[end] !== ")") return;
98
+ start ??= Number(text.slice(offset, end));
89
99
  char = text[end++];
90
100
  }
91
101
  if (end !== text.length && text[end] !== " ") return;
92
102
  const padding = spaces(text, end);
93
103
  const empty = end + padding === text.length;
94
104
  const content = end + (empty || padding > 4 ? Math.min(padding, 1) : padding);
95
- return { start, marker: char, content, indent: end - offset + (empty ? 1 : padding > 4 ? 1 : padding), empty };
105
+ return { start, style, marker: char, content, indent: end - offset + (empty ? 1 : padding > 4 ? 1 : padding), empty };
96
106
  }
97
107
  var blockTags = /* @__PURE__ */ new Set([
98
108
  "address",
@@ -227,11 +237,11 @@ function htmlStart(text, offset, interrupt) {
227
237
  if (blockTags.has(name)) return { end: null };
228
238
  if (!interrupt && (closing || !["script", "pre", "style", "textarea"].includes(name)) && completeTag(text, offset)) return { end: null };
229
239
  }
230
- function interrupts(text, offset, rawHtml = true) {
240
+ function interrupts(text, offset, rawHtml = true, fancy = false) {
231
241
  const indent = spaces(text, offset);
232
242
  if (indent > 3) return false;
233
243
  const at = offset + indent;
234
- const item = marker(text, at);
244
+ const item = marker(text, at, fancy);
235
245
  return Boolean(heading(text, at) || rule(text, at) || fence(text, at) || text[at] === ">" || rawHtml && htmlStart(text, at, true) || item && !item.empty && (item.start === null || item.start === 1));
236
246
  }
237
247
  async function parseCommonMarkBlocks(text, context, source = "input", extensions = {}) {
@@ -249,7 +259,7 @@ async function parseCommonMarkBlocks(text, context, source = "input", extensions
249
259
  const range = (line, offset) => ({ source, start: point(line, offset), end: endPoint(line) });
250
260
  const blocks = () => {
251
261
  const top = stack[stack.length - 1];
252
- return top?.kind === "quote" || top?.kind === "item" || top?.kind === "footnote" ? top.node.blocks : document.blocks;
262
+ return top?.kind === "div" || top?.kind === "quote" || top?.kind === "item" || top?.kind === "footnote" || top?.kind === "definition" ? top.node.blocks : document.blocks;
253
263
  };
254
264
  const add = (node) => {
255
265
  context.bound("depth", stack.length + 1);
@@ -258,6 +268,8 @@ async function parseCommonMarkBlocks(text, context, source = "input", extensions
258
268
  const item = stack[stack.length - 1];
259
269
  if (item?.kind === "item" && item.blank && item.node.blocks.length > 0) item.list.tight = false;
260
270
  if (item?.kind === "item") item.blank = false;
271
+ if (item?.kind === "definition" && item.blank) item.node.tight = false;
272
+ if (item?.kind === "definition") item.blank = false;
261
273
  blocks().push(node);
262
274
  };
263
275
  const push = (container) => {
@@ -358,7 +370,7 @@ async function parseCommonMarkBlocks(text, context, source = "input", extensions
358
370
  for (; matched < stack.length; matched++) {
359
371
  context.checkpoint();
360
372
  const container = stack[matched];
361
- if (container.kind === "list") continue;
373
+ if (container.kind === "list" || container.kind === "div") continue;
362
374
  const indent = spaces(line.text, offset);
363
375
  if (container.kind === "quote") {
364
376
  if (indent > 3 || line.text[offset + indent] !== ">") break;
@@ -374,10 +386,11 @@ async function parseCommonMarkBlocks(text, context, source = "input", extensions
374
386
  if (matched < stack.length) {
375
387
  const failed = stack[matched];
376
388
  const siblingIndent = spaces(line.text, offset);
377
- const sibling = siblingIndent <= 3 ? marker(line.text, offset + siblingIndent) : void 0;
389
+ const sibling = siblingIndent <= 3 ? marker(line.text, offset + siblingIndent, extensions.fancy_lists) : void 0;
378
390
  const siblingItem = failed?.kind === "item" && sibling;
379
391
  const siblingFootnote = failed?.kind === "footnote" && line.text.startsWith("[^", offset + siblingIndent) && line.text.includes("]:", offset + siblingIndent + 2);
380
- if (leaf?.kind === "paragraph" && !blank && !siblingItem && !siblingFootnote && !interrupts(line.text, offset, extensions.raw_html !== false)) {
392
+ const siblingDefinition = extensions.definition_lists && siblingIndent <= 3 && [":", "~"].includes(line.text[offset + siblingIndent] ?? "") && line.text[offset + siblingIndent + 1] === " ";
393
+ if (leaf?.kind === "paragraph" && !blank && !siblingItem && !siblingFootnote && !siblingDefinition && !interrupts(line.text, offset, extensions.raw_html !== false, extensions.fancy_lists)) {
381
394
  leaf.node.inline.lines.push(inlineLine(line, offset + spaces(line.text, offset)));
382
395
  leaf.node.source.end = endPoint(line);
383
396
  for (const container of stack) container.node.source.end = endPoint(line);
@@ -432,6 +445,31 @@ async function parseCommonMarkBlocks(text, context, source = "input", extensions
432
445
  }
433
446
  finish();
434
447
  }
448
+ if (extensions.fenced_divs && spaces(line.text, offset) <= 3) {
449
+ const at = offset + spaces(line.text, offset);
450
+ let stop = at;
451
+ while (line.text[stop] === ":") stop++;
452
+ if (stop - at >= 3) {
453
+ const tail = rawFrom(line, stop).trim();
454
+ const attributes = fencedDivAttributes(tail, context);
455
+ if (attributes) {
456
+ finish();
457
+ const node = { kind: "div", attributes, blocks: [], source: range(line, at) };
458
+ add(node);
459
+ push({ kind: "div", node });
460
+ continue;
461
+ }
462
+ if (!tail) {
463
+ let index = stack.length - 1;
464
+ while (index >= 0 && stack[index].kind !== "div") index--;
465
+ if (index >= 0) {
466
+ finish();
467
+ stack.length = index;
468
+ continue;
469
+ }
470
+ }
471
+ }
472
+ }
435
473
  if (blank) {
436
474
  finish();
437
475
  let deepest;
@@ -442,10 +480,12 @@ async function parseCommonMarkBlocks(text, context, source = "input", extensions
442
480
  }
443
481
  }
444
482
  if (deepest) deepest.blank = true;
483
+ const top = stack[stack.length - 1];
484
+ if (top?.kind === "definition") top.blank = true;
445
485
  continue;
446
486
  }
447
487
  if (leaf?.kind === "table") {
448
- const row = !interrupts(line.text, offset, extensions.raw_html !== false) ? pipeRow(rawFrom(line, offset), context) : void 0;
488
+ const row = !interrupts(line.text, offset, extensions.raw_html !== false, extensions.fancy_lists) ? pipeRow(rawFrom(line, offset), context) : void 0;
449
489
  if (row) {
450
490
  context.charge("tableCells", extensions.preserve_table_columns ? row.length : leaf.node.alignments.length);
451
491
  leaf.node.rows.push(extensions.preserve_table_columns ? row : row.slice(0, leaf.node.alignments.length));
@@ -480,6 +520,31 @@ async function parseCommonMarkBlocks(text, context, source = "input", extensions
480
520
  }
481
521
  }
482
522
  }
523
+ const definitionIndent = spaces(line.text, offset), definitionAt = offset + definitionIndent;
524
+ if (extensions.definition_lists && definitionIndent <= 3 && [":", "~"].includes(line.text[definitionAt] ?? "") && line.text[definitionAt + 1] === " ") {
525
+ if (leaf?.kind === "paragraph") extractDefinitions(leaf.node);
526
+ const siblings = blocks(), previous = siblings[siblings.length - 1];
527
+ if (previous?.kind === "paragraph" || previous?.kind === "definitionList") {
528
+ finish();
529
+ const term = previous.kind === "paragraph" ? previous : void 0;
530
+ if (term) siblings.pop();
531
+ let list = siblings[siblings.length - 1];
532
+ if (list?.kind !== "definitionList") {
533
+ list = { kind: "definitionList", items: [], source: { ...previous.source } };
534
+ add(list);
535
+ }
536
+ if (term) list.items.push({ term: term.inline, definitions: [] });
537
+ const lastDefinition = previous.kind === "definitionList" ? previous.items.at(-1)?.definitions.at(-1) : void 0;
538
+ const previousEnd = lastDefinition?.blocks.at(-1)?.source.end.line ?? previous.source.end.line;
539
+ const definition = { blocks: [], tight: previousEnd + 1 === line.number, source: range(line, definitionAt) };
540
+ context.charge("nodes", 1);
541
+ context.charge("retainedBytes", 128);
542
+ list.items[list.items.length - 1].definitions.push(definition);
543
+ list.source.end = endPoint(line);
544
+ push({ kind: "definition", node: definition, indent: definitionIndent + 4, blank: false, empty: false });
545
+ offset = definitionAt + 1 + Math.min(3, spaces(line.text, definitionAt + 1));
546
+ }
547
+ }
483
548
  const initialIndent = spaces(line.text, offset);
484
549
  const underline = initialIndent <= 3 ? setext(line.text, offset + initialIndent) : 0;
485
550
  if (leaf?.kind === "paragraph" && underline) {
@@ -493,7 +558,7 @@ async function parseCommonMarkBlocks(text, context, source = "input", extensions
493
558
  }
494
559
  leaf = void 0;
495
560
  }
496
- if (leaf?.kind === "paragraph" && !interrupts(line.text, offset, extensions.raw_html !== false)) {
561
+ if (leaf?.kind === "paragraph" && !interrupts(line.text, offset, extensions.raw_html !== false, extensions.fancy_lists)) {
497
562
  leaf.node.inline.lines.push(inlineLine(line, offset + initialIndent));
498
563
  leaf.node.source.end = endPoint(line);
499
564
  continue;
@@ -516,8 +581,8 @@ async function parseCommonMarkBlocks(text, context, source = "input", extensions
516
581
  continue;
517
582
  }
518
583
  }
519
- const item = indent <= 3 && !rule(line.text, at) ? marker(line.text, at) : void 0;
520
- if (top?.kind === "list" && (!item || item.start !== null !== (top.node.start !== null) || item.marker !== top.node.marker)) {
584
+ const item = indent <= 3 && !rule(line.text, at) ? marker(line.text, at, extensions.fancy_lists) : void 0;
585
+ if (top?.kind === "list" && (!item || item.start !== null !== (top.node.start !== null) || item.marker !== top.node.marker || item.style !== top.node.style)) {
521
586
  stack.pop();
522
587
  const parent = stack[stack.length - 1];
523
588
  const previous = top.node.items[top.node.items.length - 1];
@@ -534,7 +599,7 @@ async function parseCommonMarkBlocks(text, context, source = "input", extensions
534
599
  if (item && (!wasParagraph || !item.empty && (item.start === null || item.start === 1))) {
535
600
  let listContainer = stack[stack.length - 1];
536
601
  if (listContainer?.kind !== "list") {
537
- const node3 = { kind: "list", start: item.start, marker: item.marker, tight: true, items: [], source: range(line, at) };
602
+ const node3 = { kind: "list", start: item.start, marker: item.marker, style: item.style, tight: true, items: [], source: range(line, at) };
538
603
  add(node3);
539
604
  listContainer = { kind: "list", node: node3 };
540
605
  push(listContainer);
@@ -550,6 +615,17 @@ async function parseCommonMarkBlocks(text, context, source = "input", extensions
550
615
  if (item.empty) break;
551
616
  continue;
552
617
  }
618
+ if (extensions.fenced_divs && indent <= 3 && line.text.startsWith(":::", at)) {
619
+ let stop = at + 3;
620
+ while (line.text[stop] === ":") stop++;
621
+ const attributes = fencedDivAttributes(rawFrom(line, stop), context);
622
+ if (attributes) {
623
+ const node2 = { kind: "div", attributes, blocks: [], source: range(line, at) };
624
+ add(node2);
625
+ push({ kind: "div", node: node2 });
626
+ break;
627
+ }
628
+ }
553
629
  if (at === line.text.length) break;
554
630
  const level = indent <= 3 ? heading(line.text, at) : 0;
555
631
  if (level) {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  digit,
3
3
  letter
4
- } from "./chunk-T6OXG7QQ.js";
4
+ } from "./chunk-AAOPVEPF.js";
5
5
  import {
6
6
  unicodeWhitespace
7
7
  } from "./chunk-C5OMNOKM.js";
@@ -15519,6 +15519,8 @@ function utf8PasswordToBytes(password) {
15519
15519
  }
15520
15520
  var CipherTransformFactory = class _CipherTransformFactory {
15521
15521
  #fileId;
15522
+ passwordType;
15523
+ userPasswordBytes;
15522
15524
  static get _defaultPasswordBytes() {
15523
15525
  return shadow2(
15524
15526
  this,
@@ -15559,6 +15561,21 @@ var CipherTransformFactory = class _CipherTransformFactory {
15559
15561
  ])
15560
15562
  );
15561
15563
  }
15564
+ matchesOwnerPassword() {
15565
+ if (this.passwordType === "owner") return true;
15566
+ if (this.passwordType !== "user") return false;
15567
+ const dict = this.dict, revision = dict.get("R");
15568
+ const owner = stringToBytes(dict.get("O"));
15569
+ const user = stringToBytes(dict.get("U"));
15570
+ const password = this.userPasswordBytes;
15571
+ if (revision >= 5) {
15572
+ const algorithm = revision === 6 ? new PDF20() : new PDF17();
15573
+ return algorithm.checkOwnerPassword(password, owner.subarray(32, 40), user.subarray(0, 48), owner.subarray(0, 32));
15574
+ }
15575
+ const keyLength = this.encryptionKey.length * 8;
15576
+ const decoded = this.#decodeUserPassword(password, owner, revision, keyLength);
15577
+ return !!this.#prepareKeyData(stringToBytes(this.#fileId), decoded, owner, user, dict.get("P"), revision, keyLength, this.encryptMetadata);
15578
+ }
15562
15579
  #createEncryptionKey20(revision, password, ownerPassword, ownerValidationSalt, ownerKeySalt, uBytes, userPassword, userValidationSalt, userKeySalt, ownerEncryption, userEncryption, perms) {
15563
15580
  if (password) {
15564
15581
  const passwordLength = Math.min(127, password.length);
@@ -15568,6 +15585,8 @@ var CipherTransformFactory = class _CipherTransformFactory {
15568
15585
  }
15569
15586
  const pdfAlgorithm = revision === 6 ? new PDF20() : new PDF17();
15570
15587
  if (pdfAlgorithm.checkUserPassword(password, userValidationSalt, userPassword)) {
15588
+ this.passwordType = "user";
15589
+ this.userPasswordBytes = Uint8Array.from(password);
15571
15590
  return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
15572
15591
  } else if (password.length && pdfAlgorithm.checkOwnerPassword(
15573
15592
  password,
@@ -15575,6 +15594,7 @@ var CipherTransformFactory = class _CipherTransformFactory {
15575
15594
  uBytes,
15576
15595
  ownerPassword
15577
15596
  )) {
15597
+ this.passwordType = "owner";
15578
15598
  return pdfAlgorithm.getOwnerKey(
15579
15599
  password,
15580
15600
  ownerKeySalt,
@@ -15782,6 +15802,10 @@ var CipherTransformFactory = class _CipherTransformFactory {
15782
15802
  keyLength,
15783
15803
  encryptMetadata
15784
15804
  );
15805
+ if (encryptionKey) {
15806
+ this.passwordType = "user";
15807
+ this.userPasswordBytes = passwordBytes ?? new Uint8Array();
15808
+ }
15785
15809
  } else {
15786
15810
  const ownerValidationSalt = ownerBytes.subarray(32, 40);
15787
15811
  const ownerKeySalt = ownerBytes.subarray(40, 48);
@@ -15842,6 +15866,10 @@ var CipherTransformFactory = class _CipherTransformFactory {
15842
15866
  keyLength,
15843
15867
  encryptMetadata
15844
15868
  );
15869
+ if (encryptionKey) {
15870
+ this.passwordType = "owner";
15871
+ this.userPasswordBytes = decodedPassword;
15872
+ }
15845
15873
  }
15846
15874
  if (!encryptionKey) {
15847
15875
  throw new PasswordException(
@@ -31444,6 +31472,37 @@ function derivePdfEncryptionKey(encryptDict, documentId0, password = "", options
31444
31472
  throw new PdfError("E_CAPABILITY", error instanceof Error && error.name === "PasswordException" ? "Invalid PDF password" : `PDF security handler: ${error instanceof Error ? error.message : String(error)}`);
31445
31473
  }
31446
31474
  }
31475
+ function getPdfEncryptionInfo(state) {
31476
+ const handler = securityHandlers.get(state);
31477
+ if (!handler) throw new PdfError("E_CAPABILITY", "Encryption inspection requires authenticated PDF security state");
31478
+ const { factory } = handler;
31479
+ let userBytes = factory.userPasswordBytes ?? new Uint8Array();
31480
+ if (state.revision < 5) {
31481
+ for (let length = 0; length < userBytes.length; length++) {
31482
+ if (userBytes.subarray(length).every((byte3, index2) => byte3 === PADDING_32[index2])) {
31483
+ userBytes = userBytes.subarray(0, length);
31484
+ break;
31485
+ }
31486
+ }
31487
+ }
31488
+ const method = (filter) => {
31489
+ if (state.version < 4) return "RC4";
31490
+ if (filter.name === "Identity") return "none";
31491
+ const entry = factory.cf?.get(filter.name);
31492
+ const cipher = entry instanceof Dict2 ? entry.get("CFM") : void 0;
31493
+ const name = cipher instanceof Name ? cipher.name : void 0;
31494
+ return name === "V2" ? "RC4" : name === "AESV2" ? "AESv2" : name === "AESV3" ? "AESv3" : "none";
31495
+ };
31496
+ return {
31497
+ permissionsMask: factory.dict.get("P"),
31498
+ ownerPasswordMatched: factory.matchesOwnerPassword(),
31499
+ userPasswordMatched: factory.passwordType === "user",
31500
+ userPassword: state.revision >= 5 ? new TextDecoder().decode(userBytes) : bytesToString3(userBytes),
31501
+ streamMethod: method(factory.stmf),
31502
+ stringMethod: method(factory.strf),
31503
+ fileMethod: method(factory.eff)
31504
+ };
31505
+ }
31447
31506
  function decryptPdfBuffer(state, objectNumber, generationNumber, data) {
31448
31507
  if (data.length === 0) return data;
31449
31508
  const handler = securityHandlers.get(state);
@@ -64656,6 +64715,11 @@ async function* saveRetainedDocumentChunks(document2, storage, options = {}) {
64656
64715
  }
64657
64716
  try {
64658
64717
  for await (const object of retainedCosObjects(document2, storage, { ...options.streamMode ? { streamMode: options.streamMode } : {}, ...options.normalizeContent ? { normalizeContent: true } : {}, ...options.maxObjects === void 0 ? {} : { maxObjects: options.maxObjects }, ...options.maxOutputBytes === void 0 ? {} : { maxStreamBytes: options.maxOutputBytes }, signal })) {
64718
+ const type = object.value.kind === "dict" ? dictGet(object.value, "Type") : void 0;
64719
+ if (object.stream && type?.kind === "name" && type.decoded === "ObjStm") {
64720
+ for await (const ignored of object.stream.chunks) void ignored;
64721
+ continue;
64722
+ }
64659
64723
  if (!object.stream && object.value.kind === "dict" && dictGet(object.value, "Linearized") !== void 0) mayLinearize = true;
64660
64724
  await objects.set(object);
64661
64725
  }
@@ -66822,44 +66886,22 @@ async function stampRetainedPages(document2, store, storage, getPage, stamps, si
66822
66886
  }
66823
66887
  }
66824
66888
  function retainedStampTransform(dstAttributes, srcAttributes) {
66825
- const dstSize = { width: Math.abs(dstAttributes.mediaBox[2] - dstAttributes.mediaBox[0]), height: Math.abs(dstAttributes.mediaBox[3] - dstAttributes.mediaBox[1]) };
66826
- const srcSize = { width: Math.abs(srcAttributes.mediaBox[2] - srcAttributes.mediaBox[0]), height: Math.abs(srcAttributes.mediaBox[3] - srcAttributes.mediaBox[1]) };
66827
- const rotDiff = ((dstAttributes.rotation - srcAttributes.rotation) % 360 + 360) % 360;
66828
- let stampOpenStr = "q\n";
66829
- if (srcSize.width > 0 && srcSize.height > 0) {
66830
- const fmt6 = (n) => Number(n.toFixed(6));
66831
- const fmt4 = (n) => Number(n.toFixed(4));
66832
- if (rotDiff === 90) {
66833
- const s = Math.min(dstSize.height / srcSize.width, dstSize.width / srcSize.height);
66834
- const ox = (dstSize.height - srcSize.width * s) / 2;
66835
- const oy = (dstSize.width - srcSize.height * s) / 2;
66836
- stampOpenStr = `q
66837
- 0 ${fmt6(s)} ${fmt6(-s)} 0 ${fmt4(dstSize.width - oy)} ${fmt4(ox)} cm
66889
+ const [dx0, dy0, dx1, dy1] = dstAttributes.mediaBox;
66890
+ const [sx0, sy0, sx1, sy1] = srcAttributes.mediaBox;
66891
+ const width = Math.abs(sx1 - sx0), height = Math.abs(sy1 - sy0);
66892
+ if (width === 0 || height === 0) return "q\n";
66893
+ const rotation = ((dstAttributes.rotation - srcAttributes.rotation) % 360 + 360) % 360;
66894
+ const swapped = rotation === 90 || rotation === 270;
66895
+ const scale = Math.min(1, Math.abs(dx1 - dx0) / (swapped ? height : width), Math.abs(dy1 - dy0) / (swapped ? width : height));
66896
+ const a = rotation === 180 ? -scale : swapped ? 0 : scale;
66897
+ const b = rotation === 90 ? scale : rotation === 270 ? -scale : 0;
66898
+ const c = -b, d = a;
66899
+ const sx = (sx0 + sx1) / 2, sy = (sy0 + sy1) / 2;
66900
+ const tx = (dx0 + dx1) / 2 - a * sx - c * sy;
66901
+ const ty = (dy0 + dy1) / 2 - b * sx - d * sy;
66902
+ return `q
66903
+ ${[a, b, c, d, tx, ty].map((n) => Number(n.toFixed(6))).join(" ")} cm
66838
66904
  `;
66839
- } else if (rotDiff === 180) {
66840
- const s = Math.min(dstSize.width / srcSize.width, dstSize.height / srcSize.height);
66841
- const ox = (dstSize.width - srcSize.width * s) / 2;
66842
- const oy = (dstSize.height - srcSize.height * s) / 2;
66843
- stampOpenStr = `q
66844
- ${fmt6(-s)} 0 0 ${fmt6(-s)} ${fmt4(dstSize.width - ox)} ${fmt4(dstSize.height - oy)} cm
66845
- `;
66846
- } else if (rotDiff === 270) {
66847
- const s = Math.min(dstSize.height / srcSize.width, dstSize.width / srcSize.height);
66848
- const ox = (dstSize.height - srcSize.width * s) / 2;
66849
- const oy = (dstSize.width - srcSize.height * s) / 2;
66850
- stampOpenStr = `q
66851
- 0 ${fmt6(-s)} ${fmt6(s)} 0 ${fmt4(oy)} ${fmt4(dstSize.height - ox)} cm
66852
- `;
66853
- } else if (Math.abs(srcSize.width - dstSize.width) > 0.5 || Math.abs(srcSize.height - dstSize.height) > 0.5) {
66854
- const s = Math.min(dstSize.width / srcSize.width, dstSize.height / srcSize.height);
66855
- const tx = (dstSize.width - srcSize.width * s) / 2;
66856
- const ty = (dstSize.height - srcSize.height * s) / 2;
66857
- stampOpenStr = `q
66858
- ${fmt6(s)} 0 0 ${fmt6(s)} ${fmt4(tx)} ${fmt4(ty)} cm
66859
- `;
66860
- }
66861
- }
66862
- return stampOpenStr;
66863
66905
  }
66864
66906
 
66865
66907
  // packages/pdf-ast/src/edit/retained-inline-images.ts
@@ -67180,8 +67222,15 @@ var PdfDuplicateAttachment = class extends PdfError {
67180
67222
  }
67181
67223
  key;
67182
67224
  };
67225
+ var PdfMissingAttachment = class extends PdfError {
67226
+ constructor(key) {
67227
+ super("E_CAPABILITY", `Attachment ${key} not found`);
67228
+ this.key = key;
67229
+ }
67230
+ key;
67231
+ };
67183
67232
  async function editRetainedAttachments(document2, target, storage, remove, additions, signal, preserveTree = false) {
67184
- const pairs = new PdfMutableObjectStore(storage, { signal });
67233
+ const pairs = new PdfMutableObjectStore(storage, { signal }), requested = new PdfMutableObjectStore(storage, { signal });
67185
67234
  const names = new PdfNameIndex(storage, Infinity, signal), removed = new PdfNameIndex(storage, Infinity, signal);
67186
67235
  const backing = new PagedStorage30({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), first = new IntegerTable17(backing), removals = new IntegerTable17(backing);
67187
67236
  let failed = false, count = 0, work = 0;
@@ -67221,7 +67270,9 @@ async function editRetainedAttachments(document2, target, storage, remove, addit
67221
67270
  if (tree.reference) owner = tree;
67222
67271
  for await (const key of remove) {
67223
67272
  await checkpoint();
67224
- await removals.set(BigInt((await removed.intern(key)).index), 1n);
67273
+ const { index: index2, added } = await removed.intern(key);
67274
+ if (added) await requested.set({ objectNumber: index2 + 1, generationNumber: 0, value: cosString(key) });
67275
+ await removals.set(BigInt(index2), 1n);
67225
67276
  }
67226
67277
  let keyNode;
67227
67278
  for await (const node of retainedAttachmentNameTokens(document2, storage, tree.value, signal, !preserveTree)) {
@@ -67230,15 +67281,21 @@ async function editRetainedAttachments(document2, target, storage, remove, addit
67230
67281
  continue;
67231
67282
  }
67232
67283
  const keyValue = (await resolve2(keyNode))?.value, key = keyValue?.kind === "string" ? decodePdfString(keyValue) : "";
67233
- if (await removals.get(BigInt((await removed.intern(key)).index)) === void 0) {
67284
+ const removalIndex = BigInt((await removed.intern(key)).index);
67285
+ if (await removals.get(removalIndex) === void 0) {
67234
67286
  await pairs.set({ objectNumber: ++count, generationNumber: 0, value: cosArray([keyNode, node]) });
67235
67287
  if (keyValue?.kind === "string") {
67236
67288
  const name = await names.intern(key);
67237
67289
  if (name.added) await first.set(BigInt(name.index), BigInt(count));
67238
67290
  }
67239
- }
67291
+ } else await removals.set(removalIndex, 0n);
67240
67292
  keyNode = void 0;
67241
67293
  }
67294
+ for await (const request of requested.objects()) {
67295
+ if (await removals.get(BigInt(request.objectNumber - 1)) === 1n && request.value.kind === "string") {
67296
+ throw new PdfMissingAttachment(decodePdfString(request.value));
67297
+ }
67298
+ }
67242
67299
  let hasRemovals = false;
67243
67300
  for await (const ignored of removals.entries()) {
67244
67301
  void ignored;
@@ -67332,7 +67389,7 @@ async function editRetainedAttachments(document2, target, storage, remove, addit
67332
67389
  failed = true;
67333
67390
  throw error;
67334
67391
  } finally {
67335
- const results = await Promise.allSettled([pairs.close(), names.close(), removed.close(), backing.close()]);
67392
+ const results = await Promise.allSettled([pairs.close(), requested.close(), names.close(), removed.close(), backing.close()]);
67336
67393
  if (!failed) {
67337
67394
  for (const result of results) if (result.status === "rejected") await Promise.reject(result.reason);
67338
67395
  }
@@ -68954,6 +69011,7 @@ export {
68954
69011
  encodePermissionsMask,
68955
69012
  computeR5R6Hash,
68956
69013
  derivePdfEncryptionKey,
69014
+ getPdfEncryptionInfo,
68957
69015
  decryptPdfBuffer,
68958
69016
  decryptPdfObjectStrings,
68959
69017
  decryptedPdfStreamDictionary,
@@ -69120,7 +69178,9 @@ export {
69120
69178
  retainedCosObjects,
69121
69179
  saveRetainedDocumentChunks,
69122
69180
  replaceRetainedPdfName,
69181
+ retainedStampTransform,
69123
69182
  PdfDuplicateAttachment,
69183
+ PdfMissingAttachment,
69124
69184
  editRetainedDocument,
69125
69185
  copyRetainedAttachments,
69126
69186
  retainedObjectOrder,