ooxml-core 1.22.0 → 1.24.0

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 (126) hide show
  1. package/README.md +7 -2
  2. package/dist/automation/index.cjs +559 -339
  3. package/dist/automation/index.d.ts +1 -0
  4. package/dist/automation/index.d.ts.map +1 -1
  5. package/dist/automation/index.mjs +558 -340
  6. package/dist/automation/live.d.ts +89 -0
  7. package/dist/automation/live.d.ts.map +1 -0
  8. package/dist/collab/embedding.d.ts +7 -0
  9. package/dist/collab/embedding.d.ts.map +1 -1
  10. package/dist/collab/index.cjs +189 -0
  11. package/dist/collab/index.d.ts +2 -0
  12. package/dist/collab/index.d.ts.map +1 -1
  13. package/dist/collab/index.mjs +186 -1
  14. package/dist/collab/write-back-lifecycle.d.ts +33 -0
  15. package/dist/collab/write-back-lifecycle.d.ts.map +1 -0
  16. package/dist/collab/write-back.d.ts +75 -0
  17. package/dist/collab/write-back.d.ts.map +1 -0
  18. package/dist/docx/ui/customization.d.ts +30 -0
  19. package/dist/docx/ui/customization.d.ts.map +1 -0
  20. package/dist/docx/ui/index.cjs +51 -0
  21. package/dist/docx/ui/index.d.ts +1 -0
  22. package/dist/docx/ui/index.d.ts.map +1 -1
  23. package/dist/docx/ui/index.mjs +46 -1
  24. package/dist/embedding/backstage.d.ts +48 -0
  25. package/dist/embedding/backstage.d.ts.map +1 -0
  26. package/dist/embedding/capabilities.d.ts +60 -0
  27. package/dist/embedding/capabilities.d.ts.map +1 -0
  28. package/dist/embedding/customization.d.ts +32 -0
  29. package/dist/embedding/customization.d.ts.map +1 -0
  30. package/dist/embedding/index.cjs +229 -0
  31. package/dist/embedding/index.d.ts +7 -0
  32. package/dist/embedding/index.d.ts.map +1 -0
  33. package/dist/embedding/index.mjs +204 -0
  34. package/dist/embedding/menu-commands.d.ts +66 -0
  35. package/dist/embedding/menu-commands.d.ts.map +1 -0
  36. package/dist/embedding/regions.d.ts +58 -0
  37. package/dist/embedding/regions.d.ts.map +1 -0
  38. package/dist/embedding/storage.d.ts +111 -0
  39. package/dist/embedding/storage.d.ts.map +1 -0
  40. package/dist/index.cjs +233 -0
  41. package/dist/index.d.ts +1 -0
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.mjs +233 -1
  44. package/dist/visio/collab/baseline.d.ts +36 -0
  45. package/dist/visio/collab/baseline.d.ts.map +1 -0
  46. package/dist/visio/collab/bind.d.ts +20 -2
  47. package/dist/visio/collab/bind.d.ts.map +1 -1
  48. package/dist/visio/collab/compose-lists.d.ts +27 -0
  49. package/dist/visio/collab/compose-lists.d.ts.map +1 -0
  50. package/dist/visio/collab/compose.d.ts +6 -2
  51. package/dist/visio/collab/compose.d.ts.map +1 -1
  52. package/dist/visio/collab/fixups.d.ts +5 -0
  53. package/dist/visio/collab/fixups.d.ts.map +1 -0
  54. package/dist/visio/collab/index.cjs +1603 -361
  55. package/dist/visio/collab/index.d.ts +3 -2
  56. package/dist/visio/collab/index.d.ts.map +1 -1
  57. package/dist/visio/collab/index.mjs +1596 -362
  58. package/dist/visio/collab/keys.d.ts +32 -1
  59. package/dist/visio/collab/keys.d.ts.map +1 -1
  60. package/dist/visio/collab/package.d.ts +22 -1
  61. package/dist/visio/collab/package.d.ts.map +1 -1
  62. package/dist/visio/collab/pieces.d.ts +41 -0
  63. package/dist/visio/collab/pieces.d.ts.map +1 -0
  64. package/dist/visio/collab/read-ids.d.ts +35 -0
  65. package/dist/visio/collab/read-ids.d.ts.map +1 -0
  66. package/dist/visio/collab/read-parts.d.ts +34 -0
  67. package/dist/visio/collab/read-parts.d.ts.map +1 -0
  68. package/dist/visio/collab/read-shapes.d.ts +34 -0
  69. package/dist/visio/collab/read-shapes.d.ts.map +1 -0
  70. package/dist/visio/collab/read-util.d.ts +20 -0
  71. package/dist/visio/collab/read-util.d.ts.map +1 -0
  72. package/dist/visio/collab/read.d.ts +40 -19
  73. package/dist/visio/collab/read.d.ts.map +1 -1
  74. package/dist/visio/collab/schema.d.ts +55 -1
  75. package/dist/visio/collab/schema.d.ts.map +1 -1
  76. package/dist/visio/collab/snapshot-contents.d.ts +9 -0
  77. package/dist/visio/collab/snapshot-contents.d.ts.map +1 -0
  78. package/dist/visio/collab/snapshot-io.d.ts +26 -0
  79. package/dist/visio/collab/snapshot-io.d.ts.map +1 -0
  80. package/dist/visio/collab/snapshot-parts.d.ts +14 -0
  81. package/dist/visio/collab/snapshot-parts.d.ts.map +1 -0
  82. package/dist/visio/collab/snapshot.d.ts +31 -24
  83. package/dist/visio/collab/snapshot.d.ts.map +1 -1
  84. package/dist/visio/collab/write-parts.d.ts +8 -0
  85. package/dist/visio/collab/write-parts.d.ts.map +1 -0
  86. package/dist/visio/collab/write-shapes.d.ts +30 -0
  87. package/dist/visio/collab/write-shapes.d.ts.map +1 -0
  88. package/dist/visio/collab/write.d.ts +4 -16
  89. package/dist/visio/collab/write.d.ts.map +1 -1
  90. package/dist/visio/collab/zip-store.d.ts +4 -0
  91. package/dist/visio/collab/zip-store.d.ts.map +1 -0
  92. package/dist/visio/document-level.d.ts +57 -0
  93. package/dist/visio/document-level.d.ts.map +1 -0
  94. package/dist/visio/index.cjs +485 -333
  95. package/dist/visio/index.d.ts +2 -0
  96. package/dist/visio/index.d.ts.map +1 -1
  97. package/dist/visio/index.mjs +484 -334
  98. package/dist/visio/layers.d.ts +3 -0
  99. package/dist/visio/layers.d.ts.map +1 -1
  100. package/dist/visio/package.d.ts +9 -0
  101. package/dist/visio/package.d.ts.map +1 -1
  102. package/dist/visio/parse-incremental.d.ts +16 -0
  103. package/dist/visio/parse-incremental.d.ts.map +1 -0
  104. package/dist/visio/parser.d.ts +14 -0
  105. package/dist/visio/parser.d.ts.map +1 -1
  106. package/dist/visio/shape-metadata.d.ts +3 -0
  107. package/dist/visio/shape-metadata.d.ts.map +1 -1
  108. package/dist/visio/ui/collab-options.d.ts +10 -5
  109. package/dist/visio/ui/collab-options.d.ts.map +1 -1
  110. package/dist/visio/ui/contract.d.ts +27 -2
  111. package/dist/visio/ui/contract.d.ts.map +1 -1
  112. package/dist/visio/ui/customization.d.ts +46 -0
  113. package/dist/visio/ui/customization.d.ts.map +1 -0
  114. package/dist/visio/ui/index.cjs +460 -320
  115. package/dist/visio/ui/index.d.ts +1 -0
  116. package/dist/visio/ui/index.d.ts.map +1 -1
  117. package/dist/visio/ui/index.mjs +458 -321
  118. package/dist/xlsx/ui/commands.d.ts +2 -0
  119. package/dist/xlsx/ui/commands.d.ts.map +1 -1
  120. package/dist/xlsx/ui/customization.d.ts +49 -0
  121. package/dist/xlsx/ui/customization.d.ts.map +1 -0
  122. package/dist/xlsx/ui/index.cjs +39 -1
  123. package/dist/xlsx/ui/index.d.ts +1 -0
  124. package/dist/xlsx/ui/index.d.ts.map +1 -1
  125. package/dist/xlsx/ui/index.mjs +37 -2
  126. package/package.json +6 -1
@@ -10,12 +10,15 @@ var JSZip__default = /*#__PURE__*/_interopDefault(JSZip);
10
10
  // visio/ui/contract.ts
11
11
  var propertyKeys = [
12
12
  "canEdit",
13
+ "readOnly",
13
14
  "document",
14
15
  "pageIndex",
15
16
  "zoom",
16
17
  "showToolbar",
17
18
  "ribbonAddIns",
18
- "collaboration"
19
+ "collaboration",
20
+ "storage",
21
+ "customization"
19
22
  ];
20
23
  var eventKeys = [
21
24
  "document-load",
@@ -26,9 +29,42 @@ var eventKeys = [
26
29
  "shape-select",
27
30
  "selection-change",
28
31
  "office-ribbon-add-in",
29
- "collaboration-change"
32
+ "collaboration-change",
33
+ "file-command"
30
34
  ];
31
35
 
36
+ // visio/ui/customization.ts
37
+ var VISIO_CAPABILITY_IDS = [
38
+ "edit",
39
+ "export",
40
+ "print",
41
+ "share",
42
+ "copy",
43
+ "comment",
44
+ "find",
45
+ "open",
46
+ "save",
47
+ "settings"
48
+ ];
49
+ var VISIO_CAPABILITY_BACKSTAGE_PAGES = {
50
+ open: ["new", "open"],
51
+ save: ["save", "save-as"],
52
+ export: ["export"],
53
+ print: ["print"],
54
+ share: ["share"],
55
+ settings: ["options"]
56
+ };
57
+ var VISIO_CAPABILITY_COMMANDS = {
58
+ copy: ["cut", "copy", "ctx-cut", "ctx-copy"],
59
+ comment: ["new-comment", "ctx-comment", "ctx-page-comment"],
60
+ find: ["find", "find-item", "replace"],
61
+ open: ["open", "new-blank"],
62
+ save: ["download"],
63
+ export: ["export-svg", "export-png", "export-pdf"],
64
+ print: ["print"],
65
+ share: ["email"]
66
+ };
67
+
32
68
  // visio/ui/collab-presence.ts
33
69
  var VISIO_PRESENCE_MAX_SELECTION = 64;
34
70
  var VISIO_PRESENCE_MAX_ID = 128;
@@ -1766,6 +1802,7 @@ var VisioPackage = class _VisioPackage {
1766
1802
  relationshipCache = /* @__PURE__ */ new Map();
1767
1803
  byteCache = /* @__PURE__ */ new Map();
1768
1804
  decodedNames = /* @__PURE__ */ new Map();
1805
+ noted;
1769
1806
  totalOutput = 0;
1770
1807
  totalXmlNodes = 0;
1771
1808
  check = () => {
@@ -1800,7 +1837,26 @@ var VisioPackage = class _VisioPackage {
1800
1837
  );
1801
1838
  }
1802
1839
  }
1840
+ /**
1841
+ * Starts noting every part this package is asked about (read, listed in a relationship, or
1842
+ * checked for). The returned function stops noting and gives each part with a print of its
1843
+ * declared CRC-32 and size (empty when absent), which is what {@link printOf} compares.
1844
+ */
1845
+ record() {
1846
+ const noted = /* @__PURE__ */ new Set();
1847
+ this.noted = noted;
1848
+ return () => {
1849
+ if (this.noted === noted) this.noted = void 0;
1850
+ return [...noted].sort().map((path2) => [path2, this.printOf(path2)]);
1851
+ };
1852
+ }
1853
+ /** The declared CRC-32 and size of a part, or an empty string when the package lacks it. */
1854
+ printOf(path2) {
1855
+ const entry3 = this.entries.get(path2);
1856
+ return entry3 && !entry3.directory ? `${entry3.crc}:${entry3.size}` : "";
1857
+ }
1803
1858
  has(path2) {
1859
+ this.noted?.add(path2);
1804
1860
  return this.entries.get(path2)?.directory === false;
1805
1861
  }
1806
1862
  paths() {
@@ -1808,6 +1864,7 @@ var VisioPackage = class _VisioPackage {
1808
1864
  }
1809
1865
  async readXml(path2, expectedRoot) {
1810
1866
  this.check();
1867
+ this.noted?.add(path2);
1811
1868
  safePath(path2);
1812
1869
  let pending2 = this.cache.get(path2);
1813
1870
  if (!pending2) {
@@ -1823,6 +1880,7 @@ var VisioPackage = class _VisioPackage {
1823
1880
  /** Validated declared size, so resource-specific limits can reject before inflation. */
1824
1881
  getPartByteLength(path2) {
1825
1882
  this.check();
1883
+ this.noted?.add(path2);
1826
1884
  safePath(path2);
1827
1885
  const entry3 = this.entries.get(path2);
1828
1886
  if (!entry3 || entry3.directory) fail("MISSING_PART", `Missing package part: ${path2}`);
@@ -1831,6 +1889,7 @@ var VisioPackage = class _VisioPackage {
1831
1889
  /** Shared package-owned bytes. Treat the returned buffer as immutable. */
1832
1890
  async readBytes(path2) {
1833
1891
  this.check();
1892
+ this.noted?.add(path2);
1834
1893
  safePath(path2);
1835
1894
  let pending2 = this.byteCache.get(path2);
1836
1895
  if (!pending2) {
@@ -1924,6 +1983,10 @@ var VisioPackage = class _VisioPackage {
1924
1983
  }
1925
1984
  async relationships(sourcePart) {
1926
1985
  this.check();
1986
+ if (this.noted && sourcePart) {
1987
+ const slash = sourcePart.lastIndexOf("/");
1988
+ this.noted.add(`${sourcePart.slice(0, slash + 1)}_rels/${sourcePart.slice(slash + 1)}.rels`);
1989
+ } else this.noted?.add("_rels/.rels");
1927
1990
  let pending2 = this.relationshipCache.get(sourcePart);
1928
1991
  if (!pending2) {
1929
1992
  pending2 = this.loadRelationships(sourcePart);
@@ -1957,6 +2020,7 @@ var VisioPackage = class _VisioPackage {
1957
2020
  const actual = mode === "Internal" ? this.decodedNames.get(resolved) : void 0;
1958
2021
  if (mode === "Internal" && !actual)
1959
2022
  fail("INVALID_RELATIONSHIP", `Missing relationship target: ${resolved}`);
2023
+ if (actual) this.noted?.add(actual);
1960
2024
  result2.set(id3, { id: id3, type, target: actual ?? resolved, mode });
1961
2025
  }
1962
2026
  return result2;
@@ -25505,6 +25569,10 @@ function createLayerBudget() {
25505
25569
  memberships += count;
25506
25570
  if (memberships > 1e5)
25507
25571
  throw new VisioPackageError("METADATA_LIMIT", "Layer membership budget exceeded.");
25572
+ },
25573
+ state: () => [memberships, characters],
25574
+ restore(state) {
25575
+ [memberships, characters] = state;
25508
25576
  }
25509
25577
  };
25510
25578
  }
@@ -25576,6 +25644,259 @@ function shapeLayers(sheet, layers2, report, budget = createLayerBudget()) {
25576
25644
  };
25577
25645
  }
25578
25646
 
25647
+ // visio/page-theme.ts
25648
+ function visioPageTheme(themes, pageCells) {
25649
+ const id3 = integer3(pageCells.get("ColorSchemeIndex")?.value);
25650
+ if (!themes || id3 === void 0 || id3 === 0 || id3 >= 65534) return void 0;
25651
+ const matches2 = themes.filter((theme3) => theme3.colorId === id3);
25652
+ if (matches2.length !== 1) return void 0;
25653
+ const theme2 = matches2[0];
25654
+ const variant = Math.min(3, integer3(pageCells.get("VariationColorIndex")?.value) ?? 0);
25655
+ const accents = [1, 2, 3, 4, 5, 6].map(
25656
+ (index2) => drawingColor(theme2.colors.get(`accent${index2}`), theme2.colors) ?? "#808080"
25657
+ );
25658
+ const light = drawingColor(theme2.colors.get("lt1"), theme2.colors);
25659
+ const dark = drawingColor(theme2.colors.get("dk1"), theme2.colors);
25660
+ const builtIn = VISIO_BUILT_IN_THEMES.find(
25661
+ (entry3) => entry3.schemeId === id3 && entry3.name === theme2.name
25662
+ );
25663
+ return {
25664
+ name: theme2.name ?? `Theme ${id3}`,
25665
+ ...builtIn ? { builtIn: builtIn.id } : {},
25666
+ variant,
25667
+ accents,
25668
+ ...light ? { light } : {},
25669
+ ...dark ? { dark } : {},
25670
+ variants: theme2.variants.map(
25671
+ (colors) => [1, 2, 3, 4, 5, 6, 7].map(
25672
+ (index2) => drawingColor(colors.get(String(index2)), theme2.colors) ?? "#808080"
25673
+ )
25674
+ )
25675
+ };
25676
+ }
25677
+
25678
+ // visio/diagnostics.ts
25679
+ var MAX_CHARACTERS = 1e6;
25680
+ var marker2 = {
25681
+ code: "diagnostics-truncated",
25682
+ severity: "warning",
25683
+ message: "Additional diagnostic content was omitted by the configured count or character limits."
25684
+ };
25685
+ function diagnosticCollector(maxCount) {
25686
+ const diagnostics = [], keys = /* @__PURE__ */ new Set();
25687
+ let characters = 0, truncated = false;
25688
+ const bounded6 = (value3, max) => {
25689
+ if (value3.length <= max) return value3;
25690
+ truncated = true;
25691
+ return value3.slice(0, max - 1) + "\u2026";
25692
+ };
25693
+ const report = (code, message, context = {}) => {
25694
+ if (diagnostics.length >= maxCount) {
25695
+ truncated = true;
25696
+ return;
25697
+ }
25698
+ const item = {
25699
+ code: bounded6(code, 64),
25700
+ severity: context.severity ?? "warning",
25701
+ message: bounded6(message, 2048),
25702
+ ...context.part === void 0 ? {} : { part: bounded6(context.part, 1024) },
25703
+ ...context.pageId === void 0 ? {} : { pageId: bounded6(context.pageId, 256) },
25704
+ ...context.shapeId === void 0 ? {} : { shapeId: bounded6(context.shapeId, 1024) }
25705
+ };
25706
+ const key2 = JSON.stringify(item);
25707
+ if (keys.has(key2)) return;
25708
+ const size3 = Object.values(item).reduce((sum, value3) => sum + value3.length, 0);
25709
+ if (characters + size3 > MAX_CHARACTERS - 256) {
25710
+ truncated = true;
25711
+ return;
25712
+ }
25713
+ characters += size3;
25714
+ keys.add(key2);
25715
+ diagnostics.push(item);
25716
+ };
25717
+ return {
25718
+ report,
25719
+ finish: () => {
25720
+ if (truncated) {
25721
+ if (diagnostics.length >= maxCount) diagnostics.pop();
25722
+ diagnostics.push({ ...marker2 });
25723
+ }
25724
+ return diagnostics;
25725
+ }
25726
+ };
25727
+ }
25728
+
25729
+ // visio/print-settings.ts
25730
+ var NAMES2 = [
25731
+ "PaperKind",
25732
+ "PrintPageOrientation",
25733
+ "PageLeftMargin",
25734
+ "PageRightMargin",
25735
+ "PageTopMargin",
25736
+ "PageBottomMargin",
25737
+ "ScaleX",
25738
+ "ScaleY",
25739
+ "OnPage",
25740
+ "PagesX",
25741
+ "PagesY",
25742
+ "CenterX",
25743
+ "CenterY"
25744
+ ];
25745
+ var BOOLEAN = /* @__PURE__ */ new Set(["OnPage", "CenterX", "CenterY"]);
25746
+ var LENGTH = /* @__PURE__ */ new Set(["PageLeftMargin", "PageRightMargin", "PageTopMargin", "PageBottomMargin"]);
25747
+ var CANONICAL = new Map(
25748
+ [...NAMES2, "PageWidth", "PageHeight", "PageScale", "DrawingScale"].map((name3) => [
25749
+ name3.toLowerCase(),
25750
+ name3
25751
+ ])
25752
+ );
25753
+ function indexCells2(sheet) {
25754
+ const cells4 = /* @__PURE__ */ new Map();
25755
+ let duplicate = false;
25756
+ for (const node3 of children2(sheet, "Cell")) {
25757
+ const name3 = attribute2(node3, "N") ?? "", canonical2 = CANONICAL.get(name3.toLowerCase());
25758
+ if (!canonical2) continue;
25759
+ if (canonical2 !== name3) duplicate = true;
25760
+ const values = cells4.get(canonical2) ?? [];
25761
+ if (values.length < 2) values.push(node3);
25762
+ cells4.set(canonical2, values);
25763
+ if (values.length > 1) duplicate = true;
25764
+ }
25765
+ return { cells: cells4, duplicate };
25766
+ }
25767
+ function createVisioPrintSettingsReader(documentSheets, rootStyles) {
25768
+ const indexes = { document: indexCells2(documentSheets[0]), root: indexCells2(rootStyles[0]) };
25769
+ return (pageSheets) => readVisioPrintCountSettings(pageSheets, documentSheets, rootStyles, indexes);
25770
+ }
25771
+ function readVisioPrintCountSettings(pageSheets, documentSheets, rootStyles, indexes) {
25772
+ let refusal;
25773
+ const refuse5 = (reason) => {
25774
+ refusal ??= reason;
25775
+ };
25776
+ if (pageSheets.length !== 1) refuse5("ambiguous-page-sheet");
25777
+ if (documentSheets.length > 1) refuse5("ambiguous-document-sheet");
25778
+ if (!documentSheets.length) refuse5("missing-setting");
25779
+ if (rootStyles.length > 1) refuse5("duplicate-setting");
25780
+ const root2 = rootStyles[0];
25781
+ if (!root2 || attribute2(root2, "ID") !== "0" || attribute2(root2, "NameU") !== "No Style")
25782
+ refuse5("unsupported-print-style");
25783
+ for (const sheet of [...pageSheets, ...documentSheets])
25784
+ for (const name3 of ["LineStyle", "FillStyle", "TextStyle"])
25785
+ if (attribute2(sheet, name3) !== "0") refuse5("unsupported-print-style");
25786
+ for (const name3 of ["LineStyle", "FillStyle", "TextStyle"])
25787
+ if (attribute2(root2, name3) !== void 0) refuse5("unsupported-print-style");
25788
+ const localIndex = indexCells2(pageSheets[0]), rootIndex = indexes?.root ?? indexCells2(root2);
25789
+ const documentIndex = indexes?.document ?? indexCells2(documentSheets[0]);
25790
+ if (localIndex.duplicate || rootIndex.duplicate || documentIndex.duplicate)
25791
+ refuse5("duplicate-setting");
25792
+ const local = localIndex.cells, inherited = rootIndex.cells;
25793
+ const read = (node3, name3, origin) => {
25794
+ const invalid5 = () => {
25795
+ refuse5(origin === "local" ? "invalid-local-setting" : "invalid-document-setting");
25796
+ return void 0;
25797
+ };
25798
+ if (node3.hasAttribute("E")) return invalid5();
25799
+ let raw = (attribute2(node3, "V") ?? "").trim();
25800
+ if (!raw || raw.length > 128) return invalid5();
25801
+ if (BOOLEAN.has(name3)) {
25802
+ if (!["0", "1", "false", "true"].includes(raw)) return invalid5();
25803
+ raw = raw === "true" ? "1" : raw === "false" ? "0" : raw;
25804
+ }
25805
+ try {
25806
+ const value3 = visioFormulaCachedValue(raw, attribute2(node3, "U"));
25807
+ const length = LENGTH.has(name3) || /^(PageWidth|PageHeight|PageScale|DrawingScale)$/.test(name3);
25808
+ if (!["scalar", ...length ? ["length"] : []].includes(value3.unit) || Math.abs(value3.value) > 1e9)
25809
+ return invalid5();
25810
+ const formula = attribute2(node3, "F");
25811
+ if (formula !== void 0) {
25812
+ const source = formula.trim();
25813
+ if (/^(true|false)$/i.test(source)) {
25814
+ if ((source.toLowerCase() === "true" ? 1 : 0) !== value3.value) return invalid5();
25815
+ } else {
25816
+ if (!source || source === "Inh") return invalid5();
25817
+ const limits = { maxLength: 512, maxNodes: 64, maxDepth: 16, maxSteps: 128 };
25818
+ const analysis = analyzeVisioFormula(source, limits);
25819
+ if (analysis.dynamic || analysis.guarded || analysis.references.length || analysis.unsupportedFunctions.length) {
25820
+ refuse5("dynamic-setting");
25821
+ return void 0;
25822
+ }
25823
+ const evaluated = evaluateVisioFormula(
25824
+ source,
25825
+ () => {
25826
+ throw new Error("Unexpected reference");
25827
+ },
25828
+ limits
25829
+ );
25830
+ if (evaluated.value !== value3.value || !["scalar", ...length ? ["length"] : []].includes(evaluated.unit))
25831
+ return invalid5();
25832
+ }
25833
+ }
25834
+ return value3.value;
25835
+ } catch {
25836
+ return invalid5();
25837
+ }
25838
+ };
25839
+ const values = /* @__PURE__ */ new Map();
25840
+ for (const name3 of NAMES2) {
25841
+ const nodes = local.get(name3) ?? inherited.get(name3);
25842
+ if (!nodes?.length) continue;
25843
+ if (nodes.length !== 1) continue;
25844
+ const value3 = read(nodes[0], name3, local.has(name3) ? "local" : "document");
25845
+ if (value3 !== void 0) values.set(name3, value3);
25846
+ }
25847
+ for (const name3 of ["PageWidth", "PageHeight", "PageScale", "DrawingScale"]) {
25848
+ const nodes = local.get(name3);
25849
+ if (!nodes || nodes.length !== 1 || !(read(nodes[0], name3, "local") > 0))
25850
+ refuse5("unusable-drawing-scale");
25851
+ }
25852
+ const setup = {};
25853
+ const paper = values.get("PaperKind");
25854
+ if (paper !== void 0 && Number.isSafeInteger(paper) && paper >= 0 && paper <= 65535)
25855
+ setup.paperKind = paper;
25856
+ else if (paper !== void 0)
25857
+ refuse5(local.has("PaperKind") ? "invalid-local-setting" : "invalid-document-setting");
25858
+ const orientation = values.get("PrintPageOrientation");
25859
+ if (orientation === 0 || orientation === 1 || orientation === 2)
25860
+ setup.printPageOrientation = orientation;
25861
+ else if (orientation !== void 0)
25862
+ refuse5(
25863
+ local.has("PrintPageOrientation") ? "invalid-local-setting" : "invalid-document-setting"
25864
+ );
25865
+ const margins = ["Left", "Right", "Top", "Bottom"].map((side2) => values.get(`Page${side2}Margin`));
25866
+ if (margins.every((n) => n !== void 0 && n >= 0 && n <= 1e3))
25867
+ setup.margins = {
25868
+ left: margins[0],
25869
+ right: margins[1],
25870
+ top: margins[2],
25871
+ bottom: margins[3]
25872
+ };
25873
+ else if (margins.some((n) => n !== void 0 && (n < 0 || n > 1e3)))
25874
+ refuse5("unusable-print-area");
25875
+ for (const [name3, key2] of [
25876
+ ["ScaleX", "printZoom"],
25877
+ ["ScaleY", "printZoomY"],
25878
+ ["PagesX", "printPagesAcross"],
25879
+ ["PagesY", "printPagesDown"]
25880
+ ]) {
25881
+ const value3 = values.get(name3);
25882
+ if (value3 !== void 0) {
25883
+ if ((name3 === "PagesX" || name3 === "PagesY") && (!Number.isSafeInteger(value3) || value3 < 1))
25884
+ refuse5(local.has(name3) ? "invalid-local-setting" : "invalid-document-setting");
25885
+ else setup[key2] = value3;
25886
+ }
25887
+ }
25888
+ for (const [name3, key2] of [
25889
+ ["OnPage", "printFitToPages"],
25890
+ ["CenterX", "printCenterX"],
25891
+ ["CenterY", "printCenterY"]
25892
+ ]) {
25893
+ const value3 = values.get(name3);
25894
+ if (value3 !== void 0) setup[key2] = value3 === 1;
25895
+ }
25896
+ if (refusal) setup.printCountRefusal = refusal;
25897
+ return setup;
25898
+ }
25899
+
25579
25900
  // visio/theme.ts
25580
25901
  var VISIO_SCHEME_SLOTS = [
25581
25902
  "dk1",
@@ -25667,86 +25988,82 @@ function formatList(parent, name3) {
25667
25988
  ).slice(0, 6) : [];
25668
25989
  }
25669
25990
 
25670
- // visio/page-theme.ts
25671
- function visioPageTheme(themes, pageCells) {
25672
- const id3 = integer3(pageCells.get("ColorSchemeIndex")?.value);
25673
- if (!themes || id3 === void 0 || id3 === 0 || id3 >= 65534) return void 0;
25674
- const matches2 = themes.filter((theme3) => theme3.colorId === id3);
25675
- if (matches2.length !== 1) return void 0;
25676
- const theme2 = matches2[0];
25677
- const variant = Math.min(3, integer3(pageCells.get("VariationColorIndex")?.value) ?? 0);
25678
- const accents = [1, 2, 3, 4, 5, 6].map(
25679
- (index2) => drawingColor(theme2.colors.get(`accent${index2}`), theme2.colors) ?? "#808080"
25680
- );
25681
- const light = drawingColor(theme2.colors.get("lt1"), theme2.colors);
25682
- const dark = drawingColor(theme2.colors.get("dk1"), theme2.colors);
25683
- const builtIn = VISIO_BUILT_IN_THEMES.find(
25684
- (entry3) => entry3.schemeId === id3 && entry3.name === theme2.name
25685
- );
25686
- return {
25687
- name: theme2.name ?? `Theme ${id3}`,
25688
- ...builtIn ? { builtIn: builtIn.id } : {},
25689
- variant,
25690
- accents,
25691
- ...light ? { light } : {},
25692
- ...dark ? { dark } : {},
25693
- variants: theme2.variants.map(
25694
- (colors) => [1, 2, 3, 4, 5, 6, 7].map(
25695
- (index2) => drawingColor(colors.get(String(index2)), theme2.colors) ?? "#808080"
25696
- )
25697
- )
25698
- };
25991
+ // visio/document-level.ts
25992
+ function optionsKey(options2) {
25993
+ const { metafileConverter: _converter, pages: _pages, documentCache: _cache, ...rest } = options2;
25994
+ return JSON.stringify(rest);
25699
25995
  }
25700
-
25701
- // visio/diagnostics.ts
25702
- var MAX_CHARACTERS = 1e6;
25703
- var marker2 = {
25704
- code: "diagnostics-truncated",
25705
- severity: "warning",
25706
- message: "Additional diagnostic content was omitted by the configured count or character limits."
25707
- };
25708
- function diagnosticCollector(maxCount) {
25709
- const diagnostics = [], keys = /* @__PURE__ */ new Set();
25710
- let characters = 0, truncated = false;
25711
- const bounded6 = (value3, max) => {
25712
- if (value3.length <= max) return value3;
25713
- truncated = true;
25714
- return value3.slice(0, max - 1) + "\u2026";
25996
+ var cacheMatches = (entry3, pkg, options2) => entry3 !== void 0 && entry3.options === optionsKey(options2) && entry3.converter === options2.metafileConverter && entry3.reads.every(([path2, print]) => pkg.printOf(path2) === print);
25997
+ async function readDocumentLevel(pkg, documentPart2, options2, checkTime, forward) {
25998
+ const reports = [];
25999
+ const report = (...args) => {
26000
+ reports.push(args);
26001
+ forward(...args);
25715
26002
  };
25716
- const report = (code, message, context = {}) => {
25717
- if (diagnostics.length >= maxCount) {
25718
- truncated = true;
25719
- return;
25720
- }
25721
- const item = {
25722
- code: bounded6(code, 64),
25723
- severity: context.severity ?? "warning",
25724
- message: bounded6(message, 2048),
25725
- ...context.part === void 0 ? {} : { part: bounded6(context.part, 1024) },
25726
- ...context.pageId === void 0 ? {} : { pageId: bounded6(context.pageId, 256) },
25727
- ...context.shapeId === void 0 ? {} : { shapeId: bounded6(context.shapeId, 1024) }
25728
- };
25729
- const key2 = JSON.stringify(item);
25730
- if (keys.has(key2)) return;
25731
- const size3 = Object.values(item).reduce((sum, value3) => sum + value3.length, 0);
25732
- if (characters + size3 > MAX_CHARACTERS - 256) {
25733
- truncated = true;
25734
- return;
25735
- }
25736
- characters += size3;
25737
- keys.add(key2);
25738
- diagnostics.push(item);
26003
+ const documentRoot = await visioXml(pkg, documentPart2, "VisioDocument");
26004
+ const resources = {
26005
+ colors: /* @__PURE__ */ new Map(),
26006
+ fonts: /* @__PURE__ */ new Map(),
26007
+ themes: await loadVisioThemes(pkg, documentPart2, report)
25739
26008
  };
25740
- return {
25741
- report,
25742
- finish: () => {
25743
- if (truncated) {
25744
- if (diagnostics.length >= maxCount) diagnostics.pop();
25745
- diagnostics.push({ ...marker2 });
25746
- }
25747
- return diagnostics;
26009
+ for (const color2 of children2(child(documentRoot, "Colors"), "ColorEntry"))
26010
+ resources.colors.set(attribute2(color2, "IX") ?? "", attribute2(color2, "RGB") ?? "");
26011
+ const faceNames = children2(child(documentRoot, "FaceNames"), "FaceName");
26012
+ if (faceNames.length > 1e4)
26013
+ throw new VisioPackageError(
26014
+ "METADATA_LIMIT",
26015
+ "Document font count exceeds its metadata limit."
26016
+ );
26017
+ let fontCharacters = 0;
26018
+ faceNames.forEach((font, index2) => {
26019
+ checkTime();
26020
+ fontCharacters += (attribute2(font, "Name") ?? attribute2(font, "NameU") ?? "Arial").length;
26021
+ if (fontCharacters > 1e6)
26022
+ throw new VisioPackageError(
26023
+ "METADATA_LIMIT",
26024
+ "Document fonts exceed aggregate metadata limits."
26025
+ );
26026
+ resources.fonts.set(
26027
+ metadata(attribute2(font, "ID") ?? String(index2), 256, "Font ID"),
26028
+ metadata(attribute2(font, "Name") ?? attribute2(font, "NameU") ?? "Arial", 1024, "Font name")
26029
+ );
26030
+ });
26031
+ const styles = /* @__PURE__ */ new Map();
26032
+ for (const style2 of children2(child(documentRoot, "StyleSheets"), "StyleSheet"))
26033
+ styles.set(metadata(attribute2(style2, "ID") ?? "", 256, "Style ID"), {
26034
+ sheet: readSheet(style2),
26035
+ attributes: metadataAttributes(style2)
26036
+ });
26037
+ const rootStyle = styles.get("0");
26038
+ if (rootStyle?.attributes.get("NameU") === "No Style") resources.rootSheet = rootStyle.sheet;
26039
+ const printStyleGroups = children2(documentRoot, "StyleSheets");
26040
+ const readPrintSettings = createVisioPrintSettingsReader(
26041
+ children2(documentRoot, "DocumentSheet"),
26042
+ printStyleGroups.length === 1 ? children2(printStyleGroups[0], "StyleSheet").filter((node3) => attribute2(node3, "ID") === "0") : []
26043
+ );
26044
+ const masters = /* @__PURE__ */ new Map();
26045
+ const masterRecords = [];
26046
+ const mastersPart = await related(pkg, documentPart2, "masters", false);
26047
+ if (mastersPart) {
26048
+ for (const master2 of children2(await visioXml(pkg, mastersPart, "Masters"), "Master")) {
26049
+ const part = await indexedPart(pkg, mastersPart, master2, "master");
26050
+ const id3 = metadata(attribute2(master2, "ID") ?? "", 256, "Master ID");
26051
+ if (!id3 || masters.has(id3))
26052
+ throw new VisioPackageError("INVALID_MASTER_ID", "Master IDs must be present and unique.");
26053
+ const masterShapes2 = readShapes(await visioXml(pkg, part, "MasterContents"));
26054
+ await prepareImages(
26055
+ masterShapes2,
26056
+ pkg,
26057
+ part,
26058
+ report,
26059
+ options2.images,
26060
+ options2.metafileConverter
26061
+ );
26062
+ masters.set(id3, masterShapes2);
26063
+ masterRecords.push({ id: id3, node: master2, shapes: masterShapes2 });
25748
26064
  }
25749
- };
26065
+ }
26066
+ return { documentRoot, resources, styles, readPrintSettings, masters, masterRecords, reports };
25750
26067
  }
25751
26068
 
25752
26069
  // visio/shape-metadata.ts
@@ -25766,6 +26083,10 @@ function createMetadataBudget(options2 = {}) {
25766
26083
  if (characters > maxCharacters)
25767
26084
  throw new VisioPackageError("METADATA_LIMIT", "Shape metadata character budget exceeded.");
25768
26085
  return value3;
26086
+ },
26087
+ state: () => [rows, characters],
26088
+ restore(state) {
26089
+ [rows, characters] = state;
25769
26090
  }
25770
26091
  };
25771
26092
  }
@@ -26664,177 +26985,6 @@ function readVisioPageSetup(cells4) {
26664
26985
  return Object.keys(result2).length ? result2 : void 0;
26665
26986
  }
26666
26987
 
26667
- // visio/print-settings.ts
26668
- var NAMES2 = [
26669
- "PaperKind",
26670
- "PrintPageOrientation",
26671
- "PageLeftMargin",
26672
- "PageRightMargin",
26673
- "PageTopMargin",
26674
- "PageBottomMargin",
26675
- "ScaleX",
26676
- "ScaleY",
26677
- "OnPage",
26678
- "PagesX",
26679
- "PagesY",
26680
- "CenterX",
26681
- "CenterY"
26682
- ];
26683
- var BOOLEAN = /* @__PURE__ */ new Set(["OnPage", "CenterX", "CenterY"]);
26684
- var LENGTH = /* @__PURE__ */ new Set(["PageLeftMargin", "PageRightMargin", "PageTopMargin", "PageBottomMargin"]);
26685
- var CANONICAL = new Map(
26686
- [...NAMES2, "PageWidth", "PageHeight", "PageScale", "DrawingScale"].map((name3) => [
26687
- name3.toLowerCase(),
26688
- name3
26689
- ])
26690
- );
26691
- function indexCells2(sheet) {
26692
- const cells4 = /* @__PURE__ */ new Map();
26693
- let duplicate = false;
26694
- for (const node3 of children2(sheet, "Cell")) {
26695
- const name3 = attribute2(node3, "N") ?? "", canonical2 = CANONICAL.get(name3.toLowerCase());
26696
- if (!canonical2) continue;
26697
- if (canonical2 !== name3) duplicate = true;
26698
- const values = cells4.get(canonical2) ?? [];
26699
- if (values.length < 2) values.push(node3);
26700
- cells4.set(canonical2, values);
26701
- if (values.length > 1) duplicate = true;
26702
- }
26703
- return { cells: cells4, duplicate };
26704
- }
26705
- function createVisioPrintSettingsReader(documentSheets, rootStyles) {
26706
- const indexes = { document: indexCells2(documentSheets[0]), root: indexCells2(rootStyles[0]) };
26707
- return (pageSheets) => readVisioPrintCountSettings(pageSheets, documentSheets, rootStyles, indexes);
26708
- }
26709
- function readVisioPrintCountSettings(pageSheets, documentSheets, rootStyles, indexes) {
26710
- let refusal;
26711
- const refuse5 = (reason) => {
26712
- refusal ??= reason;
26713
- };
26714
- if (pageSheets.length !== 1) refuse5("ambiguous-page-sheet");
26715
- if (documentSheets.length > 1) refuse5("ambiguous-document-sheet");
26716
- if (!documentSheets.length) refuse5("missing-setting");
26717
- if (rootStyles.length > 1) refuse5("duplicate-setting");
26718
- const root2 = rootStyles[0];
26719
- if (!root2 || attribute2(root2, "ID") !== "0" || attribute2(root2, "NameU") !== "No Style")
26720
- refuse5("unsupported-print-style");
26721
- for (const sheet of [...pageSheets, ...documentSheets])
26722
- for (const name3 of ["LineStyle", "FillStyle", "TextStyle"])
26723
- if (attribute2(sheet, name3) !== "0") refuse5("unsupported-print-style");
26724
- for (const name3 of ["LineStyle", "FillStyle", "TextStyle"])
26725
- if (attribute2(root2, name3) !== void 0) refuse5("unsupported-print-style");
26726
- const localIndex = indexCells2(pageSheets[0]), rootIndex = indexes?.root ?? indexCells2(root2);
26727
- const documentIndex = indexes?.document ?? indexCells2(documentSheets[0]);
26728
- if (localIndex.duplicate || rootIndex.duplicate || documentIndex.duplicate)
26729
- refuse5("duplicate-setting");
26730
- const local = localIndex.cells, inherited = rootIndex.cells;
26731
- const read = (node3, name3, origin) => {
26732
- const invalid5 = () => {
26733
- refuse5(origin === "local" ? "invalid-local-setting" : "invalid-document-setting");
26734
- return void 0;
26735
- };
26736
- if (node3.hasAttribute("E")) return invalid5();
26737
- let raw = (attribute2(node3, "V") ?? "").trim();
26738
- if (!raw || raw.length > 128) return invalid5();
26739
- if (BOOLEAN.has(name3)) {
26740
- if (!["0", "1", "false", "true"].includes(raw)) return invalid5();
26741
- raw = raw === "true" ? "1" : raw === "false" ? "0" : raw;
26742
- }
26743
- try {
26744
- const value3 = visioFormulaCachedValue(raw, attribute2(node3, "U"));
26745
- const length = LENGTH.has(name3) || /^(PageWidth|PageHeight|PageScale|DrawingScale)$/.test(name3);
26746
- if (!["scalar", ...length ? ["length"] : []].includes(value3.unit) || Math.abs(value3.value) > 1e9)
26747
- return invalid5();
26748
- const formula = attribute2(node3, "F");
26749
- if (formula !== void 0) {
26750
- const source = formula.trim();
26751
- if (/^(true|false)$/i.test(source)) {
26752
- if ((source.toLowerCase() === "true" ? 1 : 0) !== value3.value) return invalid5();
26753
- } else {
26754
- if (!source || source === "Inh") return invalid5();
26755
- const limits = { maxLength: 512, maxNodes: 64, maxDepth: 16, maxSteps: 128 };
26756
- const analysis = analyzeVisioFormula(source, limits);
26757
- if (analysis.dynamic || analysis.guarded || analysis.references.length || analysis.unsupportedFunctions.length) {
26758
- refuse5("dynamic-setting");
26759
- return void 0;
26760
- }
26761
- const evaluated = evaluateVisioFormula(
26762
- source,
26763
- () => {
26764
- throw new Error("Unexpected reference");
26765
- },
26766
- limits
26767
- );
26768
- if (evaluated.value !== value3.value || !["scalar", ...length ? ["length"] : []].includes(evaluated.unit))
26769
- return invalid5();
26770
- }
26771
- }
26772
- return value3.value;
26773
- } catch {
26774
- return invalid5();
26775
- }
26776
- };
26777
- const values = /* @__PURE__ */ new Map();
26778
- for (const name3 of NAMES2) {
26779
- const nodes = local.get(name3) ?? inherited.get(name3);
26780
- if (!nodes?.length) continue;
26781
- if (nodes.length !== 1) continue;
26782
- const value3 = read(nodes[0], name3, local.has(name3) ? "local" : "document");
26783
- if (value3 !== void 0) values.set(name3, value3);
26784
- }
26785
- for (const name3 of ["PageWidth", "PageHeight", "PageScale", "DrawingScale"]) {
26786
- const nodes = local.get(name3);
26787
- if (!nodes || nodes.length !== 1 || !(read(nodes[0], name3, "local") > 0))
26788
- refuse5("unusable-drawing-scale");
26789
- }
26790
- const setup = {};
26791
- const paper = values.get("PaperKind");
26792
- if (paper !== void 0 && Number.isSafeInteger(paper) && paper >= 0 && paper <= 65535)
26793
- setup.paperKind = paper;
26794
- else if (paper !== void 0)
26795
- refuse5(local.has("PaperKind") ? "invalid-local-setting" : "invalid-document-setting");
26796
- const orientation = values.get("PrintPageOrientation");
26797
- if (orientation === 0 || orientation === 1 || orientation === 2)
26798
- setup.printPageOrientation = orientation;
26799
- else if (orientation !== void 0)
26800
- refuse5(
26801
- local.has("PrintPageOrientation") ? "invalid-local-setting" : "invalid-document-setting"
26802
- );
26803
- const margins = ["Left", "Right", "Top", "Bottom"].map((side2) => values.get(`Page${side2}Margin`));
26804
- if (margins.every((n) => n !== void 0 && n >= 0 && n <= 1e3))
26805
- setup.margins = {
26806
- left: margins[0],
26807
- right: margins[1],
26808
- top: margins[2],
26809
- bottom: margins[3]
26810
- };
26811
- else if (margins.some((n) => n !== void 0 && (n < 0 || n > 1e3)))
26812
- refuse5("unusable-print-area");
26813
- for (const [name3, key2] of [
26814
- ["ScaleX", "printZoom"],
26815
- ["ScaleY", "printZoomY"],
26816
- ["PagesX", "printPagesAcross"],
26817
- ["PagesY", "printPagesDown"]
26818
- ]) {
26819
- const value3 = values.get(name3);
26820
- if (value3 !== void 0) {
26821
- if ((name3 === "PagesX" || name3 === "PagesY") && (!Number.isSafeInteger(value3) || value3 < 1))
26822
- refuse5(local.has(name3) ? "invalid-local-setting" : "invalid-document-setting");
26823
- else setup[key2] = value3;
26824
- }
26825
- }
26826
- for (const [name3, key2] of [
26827
- ["OnPage", "printFitToPages"],
26828
- ["CenterX", "printCenterX"],
26829
- ["CenterY", "printCenterY"]
26830
- ]) {
26831
- const value3 = values.get(name3);
26832
- if (value3 !== void 0) setup[key2] = value3 === 1;
26833
- }
26834
- if (refusal) setup.printCountRefusal = refusal;
26835
- return setup;
26836
- }
26837
-
26838
26988
  // visio/master-list.ts
26839
26989
  var MAX_LISTED_MASTERS = 500;
26840
26990
  var PREVIEW_SHAPES = 5e3;
@@ -27032,69 +27182,18 @@ async function parseVsdx(input, options2 = {}) {
27032
27182
  );
27033
27183
  }
27034
27184
  }
27035
- const documentRoot = await visioXml(pkg, documentPart2, "VisioDocument");
27036
- const resources = {
27037
- colors: /* @__PURE__ */ new Map(),
27038
- fonts: /* @__PURE__ */ new Map(),
27039
- themes: await loadVisioThemes(pkg, documentPart2, report)
27040
- };
27041
- for (const color2 of children2(child(documentRoot, "Colors"), "ColorEntry"))
27042
- resources.colors.set(attribute2(color2, "IX") ?? "", attribute2(color2, "RGB") ?? "");
27043
- const faceNames = children2(child(documentRoot, "FaceNames"), "FaceName");
27044
- if (faceNames.length > 1e4)
27045
- throw new VisioPackageError(
27046
- "METADATA_LIMIT",
27047
- "Document font count exceeds its metadata limit."
27048
- );
27049
- let fontCharacters = 0;
27050
- faceNames.forEach((font, index2) => {
27051
- checkTime();
27052
- fontCharacters += (attribute2(font, "Name") ?? attribute2(font, "NameU") ?? "Arial").length;
27053
- if (fontCharacters > 1e6)
27054
- throw new VisioPackageError(
27055
- "METADATA_LIMIT",
27056
- "Document fonts exceed aggregate metadata limits."
27057
- );
27058
- resources.fonts.set(
27059
- metadata(attribute2(font, "ID") ?? String(index2), 256, "Font ID"),
27060
- metadata(attribute2(font, "Name") ?? attribute2(font, "NameU") ?? "Arial", 1024, "Font name")
27061
- );
27062
- });
27063
- const styles = /* @__PURE__ */ new Map();
27064
- for (const style2 of children2(child(documentRoot, "StyleSheets"), "StyleSheet"))
27065
- styles.set(metadata(attribute2(style2, "ID") ?? "", 256, "Style ID"), {
27066
- sheet: readSheet(style2),
27067
- attributes: metadataAttributes(style2)
27068
- });
27069
- const rootStyle = styles.get("0");
27070
- if (rootStyle?.attributes.get("NameU") === "No Style") resources.rootSheet = rootStyle.sheet;
27071
- const printStyleGroups = children2(documentRoot, "StyleSheets");
27072
- const readPrintSettings = createVisioPrintSettingsReader(
27073
- children2(documentRoot, "DocumentSheet"),
27074
- printStyleGroups.length === 1 ? children2(printStyleGroups[0], "StyleSheet").filter((node3) => attribute2(node3, "ID") === "0") : []
27075
- );
27076
- const masters = /* @__PURE__ */ new Map();
27077
- const masterRecords = [];
27078
- const mastersPart = await related(pkg, documentPart2, "masters", false);
27079
- if (mastersPart) {
27080
- for (const master2 of children2(await visioXml(pkg, mastersPart, "Masters"), "Master")) {
27081
- const part = await indexedPart(pkg, mastersPart, master2, "master");
27082
- const id3 = metadata(attribute2(master2, "ID") ?? "", 256, "Master ID");
27083
- if (!id3 || masters.has(id3))
27084
- throw new VisioPackageError("INVALID_MASTER_ID", "Master IDs must be present and unique.");
27085
- const masterShapes2 = readShapes(await visioXml(pkg, part, "MasterContents"));
27086
- await prepareImages(
27087
- masterShapes2,
27088
- pkg,
27089
- part,
27090
- report,
27091
- options2.images,
27092
- options2.metafileConverter
27093
- );
27094
- masters.set(id3, masterShapes2);
27095
- masterRecords.push({ id: id3, node: master2, shapes: masterShapes2 });
27096
- }
27097
- }
27185
+ const cache2 = options2.documentCache;
27186
+ const cached5 = cacheMatches(cache2?.entry, pkg, options2) ? cache2.entry : void 0;
27187
+ const stopRecording = cache2 && !cached5 ? pkg.record() : void 0;
27188
+ let level2;
27189
+ if (cached5) {
27190
+ level2 = cached5.level;
27191
+ for (const args of level2.reports) report(...args);
27192
+ } else level2 = await readDocumentLevel(pkg, documentPart2, options2, checkTime, report);
27193
+ const { documentRoot, styles, readPrintSettings, masters, masterRecords } = level2;
27194
+ const resources = { ...level2.resources };
27195
+ delete resources.pageCells;
27196
+ delete resources.fieldContext;
27098
27197
  let geometryCount = 0, textCount = 0, expansionCount = 0, textRuns = 0, paragraphCount = 0;
27099
27198
  const context = {
27100
27199
  metadataBudget: createMetadataBudget(options2.metadata),
@@ -27148,15 +27247,52 @@ async function parseVsdx(input, options2 = {}) {
27148
27247
  throw new VisioPackageError("TEXT_LIMIT", "Text character limit exceeded.");
27149
27248
  }
27150
27249
  };
27151
- const documentMasters = listVisioMasters(masterRecords, context, {
27152
- metadataBudget: createMetadataBudget(options2.metadata),
27153
- layerBudget: createLayerBudget()
27154
- });
27250
+ let documentMasters;
27251
+ if (cached5) {
27252
+ const { counters } = cached5.listed;
27253
+ curveWork = counters.curveWork;
27254
+ geometryCount = counters.geometry;
27255
+ textCount = counters.text;
27256
+ expansionCount = counters.expansion;
27257
+ textRuns = counters.textRuns;
27258
+ paragraphCount = counters.paragraphs;
27259
+ context.shapeCount = counters.shapes;
27260
+ context.metadataBudget.restore(counters.metadata);
27261
+ context.layerBudget.restore(counters.layers);
27262
+ documentMasters = cached5.listed.documentMasters;
27263
+ } else {
27264
+ documentMasters = listVisioMasters(masterRecords, context, {
27265
+ metadataBudget: createMetadataBudget(options2.metadata),
27266
+ layerBudget: createLayerBudget()
27267
+ });
27268
+ if (cache2 && stopRecording)
27269
+ cache2.entry = {
27270
+ options: optionsKey(options2),
27271
+ converter: options2.metafileConverter,
27272
+ reads: stopRecording(),
27273
+ level: { ...level2, resources: { ...resources } },
27274
+ listed: {
27275
+ documentMasters,
27276
+ counters: {
27277
+ curveWork,
27278
+ geometry: geometryCount,
27279
+ text: textCount,
27280
+ expansion: expansionCount,
27281
+ textRuns,
27282
+ paragraphs: paragraphCount,
27283
+ shapes: context.shapeCount,
27284
+ metadata: context.metadataBudget.state(),
27285
+ layers: context.layerBudget.state()
27286
+ }
27287
+ }
27288
+ };
27289
+ }
27155
27290
  const pagesPart = await related(pkg, documentPart2, "pages", !options2.stencil);
27156
27291
  if (!pagesPart && !options2.stencil)
27157
27292
  throw new VisioPackageError("INVALID_DOCUMENT", "Missing Visio pages part.");
27158
27293
  const pages = [], pageIds2 = /* @__PURE__ */ new Set();
27159
27294
  const comments = [];
27295
+ const only = options2.pages ? new Set(options2.pages) : void 0;
27160
27296
  const pageNodes = pagesPart ? children2(await visioXml(pkg, pagesPart, "Pages"), "Page") : [];
27161
27297
  const foreground = pageNodes.filter((page) => !yes(attribute2(page, "Background")));
27162
27298
  const fieldProperties = await readVisioFieldProperties(pkg);
@@ -27166,6 +27302,7 @@ async function parseVsdx(input, options2 = {}) {
27166
27302
  if (!id3 || pageIds2.has(id3))
27167
27303
  throw new VisioPackageError("INVALID_PAGE_ID", "Page IDs must be present and unique.");
27168
27304
  pageIds2.add(id3);
27305
+ if (only && !only.has(id3)) continue;
27169
27306
  const part = await indexedPart(pkg, pagesPart, page, "page");
27170
27307
  const root2 = await visioXml(pkg, part, "PageContents");
27171
27308
  const localReport = (code, message, extra) => report(code, message, { part, pageId: id3, ...extra });
@@ -27275,16 +27412,16 @@ async function parseVsdx(input, options2 = {}) {
27275
27412
  });
27276
27413
  }
27277
27414
  checkTime();
27278
- validateBackgrounds(pages, report);
27415
+ if (!only) validateBackgrounds(pages, report);
27279
27416
  try {
27280
- comments.push(...await readVisioComments(pkg, documentPart2, report));
27417
+ if (!only) comments.push(...await readVisioComments(pkg, documentPart2, report));
27281
27418
  } catch (error) {
27282
27419
  if (!(error instanceof VisioPackageError) || error.code === "LIMIT_RUNTIME") throw error;
27283
27420
  report("invalid-comments", "The comments part could not be read; comments are not shown.");
27284
27421
  }
27285
27422
  let dataRecordsets = [];
27286
27423
  try {
27287
- dataRecordsets = await readDataRecordsets(pkg, documentPart2, checkTime);
27424
+ if (!only) dataRecordsets = await readDataRecordsets(pkg, documentPart2, checkTime);
27288
27425
  } catch (error) {
27289
27426
  if (error instanceof VisioPackageError && error.code === "LIMIT_RUNTIME") throw error;
27290
27427
  report(
@@ -27292,7 +27429,7 @@ async function parseVsdx(input, options2 = {}) {
27292
27429
  `Saved external data could not be read and is preserved unchanged: ${error instanceof Error ? error.message : String(error)}`
27293
27430
  );
27294
27431
  }
27295
- const stencils = await readVisioStencilWindows(pkg, documentPart2);
27432
+ const stencils = only ? [] : await readVisioStencilWindows(pkg, documentPart2);
27296
27433
  report(
27297
27434
  "cached-values-only",
27298
27435
  "ShapeSheet formulas, automatic connector routing, and external data are not evaluated; saved cached values and supported theme records are used.",
@@ -45205,6 +45342,9 @@ exports.VISIO_AUTO_CONNECT_DIRECTIONS = VISIO_AUTO_CONNECT_DIRECTIONS;
45205
45342
  exports.VISIO_AUTO_CONNECT_GAP = VISIO_AUTO_CONNECT_GAP;
45206
45343
  exports.VISIO_AUTO_CONNECT_REACH = VISIO_AUTO_CONNECT_REACH;
45207
45344
  exports.VISIO_BULLET_STYLES = VISIO_BULLET_STYLES;
45345
+ exports.VISIO_CAPABILITY_BACKSTAGE_PAGES = VISIO_CAPABILITY_BACKSTAGE_PAGES;
45346
+ exports.VISIO_CAPABILITY_COMMANDS = VISIO_CAPABILITY_COMMANDS;
45347
+ exports.VISIO_CAPABILITY_IDS = VISIO_CAPABILITY_IDS;
45208
45348
  exports.VISIO_CHART_OBJECT_SIZE = VISIO_CHART_OBJECT_SIZE;
45209
45349
  exports.VISIO_DATA_GRAPHIC_FILL_ROW = VISIO_DATA_GRAPHIC_FILL_ROW;
45210
45350
  exports.VISIO_DATA_GRAPHIC_ICONS = VISIO_DATA_GRAPHIC_ICONS;