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
@@ -4,12 +4,15 @@ import JSZip from 'jszip';
4
4
  // visio/ui/contract.ts
5
5
  var propertyKeys = [
6
6
  "canEdit",
7
+ "readOnly",
7
8
  "document",
8
9
  "pageIndex",
9
10
  "zoom",
10
11
  "showToolbar",
11
12
  "ribbonAddIns",
12
- "collaboration"
13
+ "collaboration",
14
+ "storage",
15
+ "customization"
13
16
  ];
14
17
  var eventKeys = [
15
18
  "document-load",
@@ -20,9 +23,42 @@ var eventKeys = [
20
23
  "shape-select",
21
24
  "selection-change",
22
25
  "office-ribbon-add-in",
23
- "collaboration-change"
26
+ "collaboration-change",
27
+ "file-command"
24
28
  ];
25
29
 
30
+ // visio/ui/customization.ts
31
+ var VISIO_CAPABILITY_IDS = [
32
+ "edit",
33
+ "export",
34
+ "print",
35
+ "share",
36
+ "copy",
37
+ "comment",
38
+ "find",
39
+ "open",
40
+ "save",
41
+ "settings"
42
+ ];
43
+ var VISIO_CAPABILITY_BACKSTAGE_PAGES = {
44
+ open: ["new", "open"],
45
+ save: ["save", "save-as"],
46
+ export: ["export"],
47
+ print: ["print"],
48
+ share: ["share"],
49
+ settings: ["options"]
50
+ };
51
+ var VISIO_CAPABILITY_COMMANDS = {
52
+ copy: ["cut", "copy", "ctx-cut", "ctx-copy"],
53
+ comment: ["new-comment", "ctx-comment", "ctx-page-comment"],
54
+ find: ["find", "find-item", "replace"],
55
+ open: ["open", "new-blank"],
56
+ save: ["download"],
57
+ export: ["export-svg", "export-png", "export-pdf"],
58
+ print: ["print"],
59
+ share: ["email"]
60
+ };
61
+
26
62
  // visio/ui/collab-presence.ts
27
63
  var VISIO_PRESENCE_MAX_SELECTION = 64;
28
64
  var VISIO_PRESENCE_MAX_ID = 128;
@@ -1760,6 +1796,7 @@ var VisioPackage = class _VisioPackage {
1760
1796
  relationshipCache = /* @__PURE__ */ new Map();
1761
1797
  byteCache = /* @__PURE__ */ new Map();
1762
1798
  decodedNames = /* @__PURE__ */ new Map();
1799
+ noted;
1763
1800
  totalOutput = 0;
1764
1801
  totalXmlNodes = 0;
1765
1802
  check = () => {
@@ -1794,7 +1831,26 @@ var VisioPackage = class _VisioPackage {
1794
1831
  );
1795
1832
  }
1796
1833
  }
1834
+ /**
1835
+ * Starts noting every part this package is asked about (read, listed in a relationship, or
1836
+ * checked for). The returned function stops noting and gives each part with a print of its
1837
+ * declared CRC-32 and size (empty when absent), which is what {@link printOf} compares.
1838
+ */
1839
+ record() {
1840
+ const noted = /* @__PURE__ */ new Set();
1841
+ this.noted = noted;
1842
+ return () => {
1843
+ if (this.noted === noted) this.noted = void 0;
1844
+ return [...noted].sort().map((path2) => [path2, this.printOf(path2)]);
1845
+ };
1846
+ }
1847
+ /** The declared CRC-32 and size of a part, or an empty string when the package lacks it. */
1848
+ printOf(path2) {
1849
+ const entry3 = this.entries.get(path2);
1850
+ return entry3 && !entry3.directory ? `${entry3.crc}:${entry3.size}` : "";
1851
+ }
1797
1852
  has(path2) {
1853
+ this.noted?.add(path2);
1798
1854
  return this.entries.get(path2)?.directory === false;
1799
1855
  }
1800
1856
  paths() {
@@ -1802,6 +1858,7 @@ var VisioPackage = class _VisioPackage {
1802
1858
  }
1803
1859
  async readXml(path2, expectedRoot) {
1804
1860
  this.check();
1861
+ this.noted?.add(path2);
1805
1862
  safePath(path2);
1806
1863
  let pending2 = this.cache.get(path2);
1807
1864
  if (!pending2) {
@@ -1817,6 +1874,7 @@ var VisioPackage = class _VisioPackage {
1817
1874
  /** Validated declared size, so resource-specific limits can reject before inflation. */
1818
1875
  getPartByteLength(path2) {
1819
1876
  this.check();
1877
+ this.noted?.add(path2);
1820
1878
  safePath(path2);
1821
1879
  const entry3 = this.entries.get(path2);
1822
1880
  if (!entry3 || entry3.directory) fail("MISSING_PART", `Missing package part: ${path2}`);
@@ -1825,6 +1883,7 @@ var VisioPackage = class _VisioPackage {
1825
1883
  /** Shared package-owned bytes. Treat the returned buffer as immutable. */
1826
1884
  async readBytes(path2) {
1827
1885
  this.check();
1886
+ this.noted?.add(path2);
1828
1887
  safePath(path2);
1829
1888
  let pending2 = this.byteCache.get(path2);
1830
1889
  if (!pending2) {
@@ -1918,6 +1977,10 @@ var VisioPackage = class _VisioPackage {
1918
1977
  }
1919
1978
  async relationships(sourcePart) {
1920
1979
  this.check();
1980
+ if (this.noted && sourcePart) {
1981
+ const slash = sourcePart.lastIndexOf("/");
1982
+ this.noted.add(`${sourcePart.slice(0, slash + 1)}_rels/${sourcePart.slice(slash + 1)}.rels`);
1983
+ } else this.noted?.add("_rels/.rels");
1921
1984
  let pending2 = this.relationshipCache.get(sourcePart);
1922
1985
  if (!pending2) {
1923
1986
  pending2 = this.loadRelationships(sourcePart);
@@ -1951,6 +2014,7 @@ var VisioPackage = class _VisioPackage {
1951
2014
  const actual = mode === "Internal" ? this.decodedNames.get(resolved) : void 0;
1952
2015
  if (mode === "Internal" && !actual)
1953
2016
  fail("INVALID_RELATIONSHIP", `Missing relationship target: ${resolved}`);
2017
+ if (actual) this.noted?.add(actual);
1954
2018
  result2.set(id3, { id: id3, type, target: actual ?? resolved, mode });
1955
2019
  }
1956
2020
  return result2;
@@ -25499,6 +25563,10 @@ function createLayerBudget() {
25499
25563
  memberships += count;
25500
25564
  if (memberships > 1e5)
25501
25565
  throw new VisioPackageError("METADATA_LIMIT", "Layer membership budget exceeded.");
25566
+ },
25567
+ state: () => [memberships, characters],
25568
+ restore(state) {
25569
+ [memberships, characters] = state;
25502
25570
  }
25503
25571
  };
25504
25572
  }
@@ -25570,6 +25638,259 @@ function shapeLayers(sheet, layers2, report, budget = createLayerBudget()) {
25570
25638
  };
25571
25639
  }
25572
25640
 
25641
+ // visio/page-theme.ts
25642
+ function visioPageTheme(themes, pageCells) {
25643
+ const id3 = integer3(pageCells.get("ColorSchemeIndex")?.value);
25644
+ if (!themes || id3 === void 0 || id3 === 0 || id3 >= 65534) return void 0;
25645
+ const matches2 = themes.filter((theme3) => theme3.colorId === id3);
25646
+ if (matches2.length !== 1) return void 0;
25647
+ const theme2 = matches2[0];
25648
+ const variant = Math.min(3, integer3(pageCells.get("VariationColorIndex")?.value) ?? 0);
25649
+ const accents = [1, 2, 3, 4, 5, 6].map(
25650
+ (index2) => drawingColor(theme2.colors.get(`accent${index2}`), theme2.colors) ?? "#808080"
25651
+ );
25652
+ const light = drawingColor(theme2.colors.get("lt1"), theme2.colors);
25653
+ const dark = drawingColor(theme2.colors.get("dk1"), theme2.colors);
25654
+ const builtIn = VISIO_BUILT_IN_THEMES.find(
25655
+ (entry3) => entry3.schemeId === id3 && entry3.name === theme2.name
25656
+ );
25657
+ return {
25658
+ name: theme2.name ?? `Theme ${id3}`,
25659
+ ...builtIn ? { builtIn: builtIn.id } : {},
25660
+ variant,
25661
+ accents,
25662
+ ...light ? { light } : {},
25663
+ ...dark ? { dark } : {},
25664
+ variants: theme2.variants.map(
25665
+ (colors) => [1, 2, 3, 4, 5, 6, 7].map(
25666
+ (index2) => drawingColor(colors.get(String(index2)), theme2.colors) ?? "#808080"
25667
+ )
25668
+ )
25669
+ };
25670
+ }
25671
+
25672
+ // visio/diagnostics.ts
25673
+ var MAX_CHARACTERS = 1e6;
25674
+ var marker2 = {
25675
+ code: "diagnostics-truncated",
25676
+ severity: "warning",
25677
+ message: "Additional diagnostic content was omitted by the configured count or character limits."
25678
+ };
25679
+ function diagnosticCollector(maxCount) {
25680
+ const diagnostics = [], keys = /* @__PURE__ */ new Set();
25681
+ let characters = 0, truncated = false;
25682
+ const bounded6 = (value3, max) => {
25683
+ if (value3.length <= max) return value3;
25684
+ truncated = true;
25685
+ return value3.slice(0, max - 1) + "\u2026";
25686
+ };
25687
+ const report = (code, message, context = {}) => {
25688
+ if (diagnostics.length >= maxCount) {
25689
+ truncated = true;
25690
+ return;
25691
+ }
25692
+ const item = {
25693
+ code: bounded6(code, 64),
25694
+ severity: context.severity ?? "warning",
25695
+ message: bounded6(message, 2048),
25696
+ ...context.part === void 0 ? {} : { part: bounded6(context.part, 1024) },
25697
+ ...context.pageId === void 0 ? {} : { pageId: bounded6(context.pageId, 256) },
25698
+ ...context.shapeId === void 0 ? {} : { shapeId: bounded6(context.shapeId, 1024) }
25699
+ };
25700
+ const key2 = JSON.stringify(item);
25701
+ if (keys.has(key2)) return;
25702
+ const size3 = Object.values(item).reduce((sum, value3) => sum + value3.length, 0);
25703
+ if (characters + size3 > MAX_CHARACTERS - 256) {
25704
+ truncated = true;
25705
+ return;
25706
+ }
25707
+ characters += size3;
25708
+ keys.add(key2);
25709
+ diagnostics.push(item);
25710
+ };
25711
+ return {
25712
+ report,
25713
+ finish: () => {
25714
+ if (truncated) {
25715
+ if (diagnostics.length >= maxCount) diagnostics.pop();
25716
+ diagnostics.push({ ...marker2 });
25717
+ }
25718
+ return diagnostics;
25719
+ }
25720
+ };
25721
+ }
25722
+
25723
+ // visio/print-settings.ts
25724
+ var NAMES2 = [
25725
+ "PaperKind",
25726
+ "PrintPageOrientation",
25727
+ "PageLeftMargin",
25728
+ "PageRightMargin",
25729
+ "PageTopMargin",
25730
+ "PageBottomMargin",
25731
+ "ScaleX",
25732
+ "ScaleY",
25733
+ "OnPage",
25734
+ "PagesX",
25735
+ "PagesY",
25736
+ "CenterX",
25737
+ "CenterY"
25738
+ ];
25739
+ var BOOLEAN = /* @__PURE__ */ new Set(["OnPage", "CenterX", "CenterY"]);
25740
+ var LENGTH = /* @__PURE__ */ new Set(["PageLeftMargin", "PageRightMargin", "PageTopMargin", "PageBottomMargin"]);
25741
+ var CANONICAL = new Map(
25742
+ [...NAMES2, "PageWidth", "PageHeight", "PageScale", "DrawingScale"].map((name3) => [
25743
+ name3.toLowerCase(),
25744
+ name3
25745
+ ])
25746
+ );
25747
+ function indexCells2(sheet) {
25748
+ const cells4 = /* @__PURE__ */ new Map();
25749
+ let duplicate = false;
25750
+ for (const node3 of children2(sheet, "Cell")) {
25751
+ const name3 = attribute2(node3, "N") ?? "", canonical2 = CANONICAL.get(name3.toLowerCase());
25752
+ if (!canonical2) continue;
25753
+ if (canonical2 !== name3) duplicate = true;
25754
+ const values = cells4.get(canonical2) ?? [];
25755
+ if (values.length < 2) values.push(node3);
25756
+ cells4.set(canonical2, values);
25757
+ if (values.length > 1) duplicate = true;
25758
+ }
25759
+ return { cells: cells4, duplicate };
25760
+ }
25761
+ function createVisioPrintSettingsReader(documentSheets, rootStyles) {
25762
+ const indexes = { document: indexCells2(documentSheets[0]), root: indexCells2(rootStyles[0]) };
25763
+ return (pageSheets) => readVisioPrintCountSettings(pageSheets, documentSheets, rootStyles, indexes);
25764
+ }
25765
+ function readVisioPrintCountSettings(pageSheets, documentSheets, rootStyles, indexes) {
25766
+ let refusal;
25767
+ const refuse5 = (reason) => {
25768
+ refusal ??= reason;
25769
+ };
25770
+ if (pageSheets.length !== 1) refuse5("ambiguous-page-sheet");
25771
+ if (documentSheets.length > 1) refuse5("ambiguous-document-sheet");
25772
+ if (!documentSheets.length) refuse5("missing-setting");
25773
+ if (rootStyles.length > 1) refuse5("duplicate-setting");
25774
+ const root2 = rootStyles[0];
25775
+ if (!root2 || attribute2(root2, "ID") !== "0" || attribute2(root2, "NameU") !== "No Style")
25776
+ refuse5("unsupported-print-style");
25777
+ for (const sheet of [...pageSheets, ...documentSheets])
25778
+ for (const name3 of ["LineStyle", "FillStyle", "TextStyle"])
25779
+ if (attribute2(sheet, name3) !== "0") refuse5("unsupported-print-style");
25780
+ for (const name3 of ["LineStyle", "FillStyle", "TextStyle"])
25781
+ if (attribute2(root2, name3) !== void 0) refuse5("unsupported-print-style");
25782
+ const localIndex = indexCells2(pageSheets[0]), rootIndex = indexes?.root ?? indexCells2(root2);
25783
+ const documentIndex = indexes?.document ?? indexCells2(documentSheets[0]);
25784
+ if (localIndex.duplicate || rootIndex.duplicate || documentIndex.duplicate)
25785
+ refuse5("duplicate-setting");
25786
+ const local = localIndex.cells, inherited = rootIndex.cells;
25787
+ const read = (node3, name3, origin) => {
25788
+ const invalid5 = () => {
25789
+ refuse5(origin === "local" ? "invalid-local-setting" : "invalid-document-setting");
25790
+ return void 0;
25791
+ };
25792
+ if (node3.hasAttribute("E")) return invalid5();
25793
+ let raw = (attribute2(node3, "V") ?? "").trim();
25794
+ if (!raw || raw.length > 128) return invalid5();
25795
+ if (BOOLEAN.has(name3)) {
25796
+ if (!["0", "1", "false", "true"].includes(raw)) return invalid5();
25797
+ raw = raw === "true" ? "1" : raw === "false" ? "0" : raw;
25798
+ }
25799
+ try {
25800
+ const value3 = visioFormulaCachedValue(raw, attribute2(node3, "U"));
25801
+ const length = LENGTH.has(name3) || /^(PageWidth|PageHeight|PageScale|DrawingScale)$/.test(name3);
25802
+ if (!["scalar", ...length ? ["length"] : []].includes(value3.unit) || Math.abs(value3.value) > 1e9)
25803
+ return invalid5();
25804
+ const formula = attribute2(node3, "F");
25805
+ if (formula !== void 0) {
25806
+ const source = formula.trim();
25807
+ if (/^(true|false)$/i.test(source)) {
25808
+ if ((source.toLowerCase() === "true" ? 1 : 0) !== value3.value) return invalid5();
25809
+ } else {
25810
+ if (!source || source === "Inh") return invalid5();
25811
+ const limits = { maxLength: 512, maxNodes: 64, maxDepth: 16, maxSteps: 128 };
25812
+ const analysis = analyzeVisioFormula(source, limits);
25813
+ if (analysis.dynamic || analysis.guarded || analysis.references.length || analysis.unsupportedFunctions.length) {
25814
+ refuse5("dynamic-setting");
25815
+ return void 0;
25816
+ }
25817
+ const evaluated = evaluateVisioFormula(
25818
+ source,
25819
+ () => {
25820
+ throw new Error("Unexpected reference");
25821
+ },
25822
+ limits
25823
+ );
25824
+ if (evaluated.value !== value3.value || !["scalar", ...length ? ["length"] : []].includes(evaluated.unit))
25825
+ return invalid5();
25826
+ }
25827
+ }
25828
+ return value3.value;
25829
+ } catch {
25830
+ return invalid5();
25831
+ }
25832
+ };
25833
+ const values = /* @__PURE__ */ new Map();
25834
+ for (const name3 of NAMES2) {
25835
+ const nodes = local.get(name3) ?? inherited.get(name3);
25836
+ if (!nodes?.length) continue;
25837
+ if (nodes.length !== 1) continue;
25838
+ const value3 = read(nodes[0], name3, local.has(name3) ? "local" : "document");
25839
+ if (value3 !== void 0) values.set(name3, value3);
25840
+ }
25841
+ for (const name3 of ["PageWidth", "PageHeight", "PageScale", "DrawingScale"]) {
25842
+ const nodes = local.get(name3);
25843
+ if (!nodes || nodes.length !== 1 || !(read(nodes[0], name3, "local") > 0))
25844
+ refuse5("unusable-drawing-scale");
25845
+ }
25846
+ const setup = {};
25847
+ const paper = values.get("PaperKind");
25848
+ if (paper !== void 0 && Number.isSafeInteger(paper) && paper >= 0 && paper <= 65535)
25849
+ setup.paperKind = paper;
25850
+ else if (paper !== void 0)
25851
+ refuse5(local.has("PaperKind") ? "invalid-local-setting" : "invalid-document-setting");
25852
+ const orientation = values.get("PrintPageOrientation");
25853
+ if (orientation === 0 || orientation === 1 || orientation === 2)
25854
+ setup.printPageOrientation = orientation;
25855
+ else if (orientation !== void 0)
25856
+ refuse5(
25857
+ local.has("PrintPageOrientation") ? "invalid-local-setting" : "invalid-document-setting"
25858
+ );
25859
+ const margins = ["Left", "Right", "Top", "Bottom"].map((side2) => values.get(`Page${side2}Margin`));
25860
+ if (margins.every((n) => n !== void 0 && n >= 0 && n <= 1e3))
25861
+ setup.margins = {
25862
+ left: margins[0],
25863
+ right: margins[1],
25864
+ top: margins[2],
25865
+ bottom: margins[3]
25866
+ };
25867
+ else if (margins.some((n) => n !== void 0 && (n < 0 || n > 1e3)))
25868
+ refuse5("unusable-print-area");
25869
+ for (const [name3, key2] of [
25870
+ ["ScaleX", "printZoom"],
25871
+ ["ScaleY", "printZoomY"],
25872
+ ["PagesX", "printPagesAcross"],
25873
+ ["PagesY", "printPagesDown"]
25874
+ ]) {
25875
+ const value3 = values.get(name3);
25876
+ if (value3 !== void 0) {
25877
+ if ((name3 === "PagesX" || name3 === "PagesY") && (!Number.isSafeInteger(value3) || value3 < 1))
25878
+ refuse5(local.has(name3) ? "invalid-local-setting" : "invalid-document-setting");
25879
+ else setup[key2] = value3;
25880
+ }
25881
+ }
25882
+ for (const [name3, key2] of [
25883
+ ["OnPage", "printFitToPages"],
25884
+ ["CenterX", "printCenterX"],
25885
+ ["CenterY", "printCenterY"]
25886
+ ]) {
25887
+ const value3 = values.get(name3);
25888
+ if (value3 !== void 0) setup[key2] = value3 === 1;
25889
+ }
25890
+ if (refusal) setup.printCountRefusal = refusal;
25891
+ return setup;
25892
+ }
25893
+
25573
25894
  // visio/theme.ts
25574
25895
  var VISIO_SCHEME_SLOTS = [
25575
25896
  "dk1",
@@ -25661,86 +25982,82 @@ function formatList(parent, name3) {
25661
25982
  ).slice(0, 6) : [];
25662
25983
  }
25663
25984
 
25664
- // visio/page-theme.ts
25665
- function visioPageTheme(themes, pageCells) {
25666
- const id3 = integer3(pageCells.get("ColorSchemeIndex")?.value);
25667
- if (!themes || id3 === void 0 || id3 === 0 || id3 >= 65534) return void 0;
25668
- const matches2 = themes.filter((theme3) => theme3.colorId === id3);
25669
- if (matches2.length !== 1) return void 0;
25670
- const theme2 = matches2[0];
25671
- const variant = Math.min(3, integer3(pageCells.get("VariationColorIndex")?.value) ?? 0);
25672
- const accents = [1, 2, 3, 4, 5, 6].map(
25673
- (index2) => drawingColor(theme2.colors.get(`accent${index2}`), theme2.colors) ?? "#808080"
25674
- );
25675
- const light = drawingColor(theme2.colors.get("lt1"), theme2.colors);
25676
- const dark = drawingColor(theme2.colors.get("dk1"), theme2.colors);
25677
- const builtIn = VISIO_BUILT_IN_THEMES.find(
25678
- (entry3) => entry3.schemeId === id3 && entry3.name === theme2.name
25679
- );
25680
- return {
25681
- name: theme2.name ?? `Theme ${id3}`,
25682
- ...builtIn ? { builtIn: builtIn.id } : {},
25683
- variant,
25684
- accents,
25685
- ...light ? { light } : {},
25686
- ...dark ? { dark } : {},
25687
- variants: theme2.variants.map(
25688
- (colors) => [1, 2, 3, 4, 5, 6, 7].map(
25689
- (index2) => drawingColor(colors.get(String(index2)), theme2.colors) ?? "#808080"
25690
- )
25691
- )
25692
- };
25985
+ // visio/document-level.ts
25986
+ function optionsKey(options2) {
25987
+ const { metafileConverter: _converter, pages: _pages, documentCache: _cache, ...rest } = options2;
25988
+ return JSON.stringify(rest);
25693
25989
  }
25694
-
25695
- // visio/diagnostics.ts
25696
- var MAX_CHARACTERS = 1e6;
25697
- var marker2 = {
25698
- code: "diagnostics-truncated",
25699
- severity: "warning",
25700
- message: "Additional diagnostic content was omitted by the configured count or character limits."
25701
- };
25702
- function diagnosticCollector(maxCount) {
25703
- const diagnostics = [], keys = /* @__PURE__ */ new Set();
25704
- let characters = 0, truncated = false;
25705
- const bounded6 = (value3, max) => {
25706
- if (value3.length <= max) return value3;
25707
- truncated = true;
25708
- return value3.slice(0, max - 1) + "\u2026";
25990
+ 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);
25991
+ async function readDocumentLevel(pkg, documentPart2, options2, checkTime, forward) {
25992
+ const reports = [];
25993
+ const report = (...args) => {
25994
+ reports.push(args);
25995
+ forward(...args);
25709
25996
  };
25710
- const report = (code, message, context = {}) => {
25711
- if (diagnostics.length >= maxCount) {
25712
- truncated = true;
25713
- return;
25714
- }
25715
- const item = {
25716
- code: bounded6(code, 64),
25717
- severity: context.severity ?? "warning",
25718
- message: bounded6(message, 2048),
25719
- ...context.part === void 0 ? {} : { part: bounded6(context.part, 1024) },
25720
- ...context.pageId === void 0 ? {} : { pageId: bounded6(context.pageId, 256) },
25721
- ...context.shapeId === void 0 ? {} : { shapeId: bounded6(context.shapeId, 1024) }
25722
- };
25723
- const key2 = JSON.stringify(item);
25724
- if (keys.has(key2)) return;
25725
- const size3 = Object.values(item).reduce((sum, value3) => sum + value3.length, 0);
25726
- if (characters + size3 > MAX_CHARACTERS - 256) {
25727
- truncated = true;
25728
- return;
25729
- }
25730
- characters += size3;
25731
- keys.add(key2);
25732
- diagnostics.push(item);
25997
+ const documentRoot = await visioXml(pkg, documentPart2, "VisioDocument");
25998
+ const resources = {
25999
+ colors: /* @__PURE__ */ new Map(),
26000
+ fonts: /* @__PURE__ */ new Map(),
26001
+ themes: await loadVisioThemes(pkg, documentPart2, report)
25733
26002
  };
25734
- return {
25735
- report,
25736
- finish: () => {
25737
- if (truncated) {
25738
- if (diagnostics.length >= maxCount) diagnostics.pop();
25739
- diagnostics.push({ ...marker2 });
25740
- }
25741
- return diagnostics;
26003
+ for (const color2 of children2(child(documentRoot, "Colors"), "ColorEntry"))
26004
+ resources.colors.set(attribute2(color2, "IX") ?? "", attribute2(color2, "RGB") ?? "");
26005
+ const faceNames = children2(child(documentRoot, "FaceNames"), "FaceName");
26006
+ if (faceNames.length > 1e4)
26007
+ throw new VisioPackageError(
26008
+ "METADATA_LIMIT",
26009
+ "Document font count exceeds its metadata limit."
26010
+ );
26011
+ let fontCharacters = 0;
26012
+ faceNames.forEach((font, index2) => {
26013
+ checkTime();
26014
+ fontCharacters += (attribute2(font, "Name") ?? attribute2(font, "NameU") ?? "Arial").length;
26015
+ if (fontCharacters > 1e6)
26016
+ throw new VisioPackageError(
26017
+ "METADATA_LIMIT",
26018
+ "Document fonts exceed aggregate metadata limits."
26019
+ );
26020
+ resources.fonts.set(
26021
+ metadata(attribute2(font, "ID") ?? String(index2), 256, "Font ID"),
26022
+ metadata(attribute2(font, "Name") ?? attribute2(font, "NameU") ?? "Arial", 1024, "Font name")
26023
+ );
26024
+ });
26025
+ const styles = /* @__PURE__ */ new Map();
26026
+ for (const style2 of children2(child(documentRoot, "StyleSheets"), "StyleSheet"))
26027
+ styles.set(metadata(attribute2(style2, "ID") ?? "", 256, "Style ID"), {
26028
+ sheet: readSheet(style2),
26029
+ attributes: metadataAttributes(style2)
26030
+ });
26031
+ const rootStyle = styles.get("0");
26032
+ if (rootStyle?.attributes.get("NameU") === "No Style") resources.rootSheet = rootStyle.sheet;
26033
+ const printStyleGroups = children2(documentRoot, "StyleSheets");
26034
+ const readPrintSettings = createVisioPrintSettingsReader(
26035
+ children2(documentRoot, "DocumentSheet"),
26036
+ printStyleGroups.length === 1 ? children2(printStyleGroups[0], "StyleSheet").filter((node3) => attribute2(node3, "ID") === "0") : []
26037
+ );
26038
+ const masters = /* @__PURE__ */ new Map();
26039
+ const masterRecords = [];
26040
+ const mastersPart = await related(pkg, documentPart2, "masters", false);
26041
+ if (mastersPart) {
26042
+ for (const master2 of children2(await visioXml(pkg, mastersPart, "Masters"), "Master")) {
26043
+ const part = await indexedPart(pkg, mastersPart, master2, "master");
26044
+ const id3 = metadata(attribute2(master2, "ID") ?? "", 256, "Master ID");
26045
+ if (!id3 || masters.has(id3))
26046
+ throw new VisioPackageError("INVALID_MASTER_ID", "Master IDs must be present and unique.");
26047
+ const masterShapes2 = readShapes(await visioXml(pkg, part, "MasterContents"));
26048
+ await prepareImages(
26049
+ masterShapes2,
26050
+ pkg,
26051
+ part,
26052
+ report,
26053
+ options2.images,
26054
+ options2.metafileConverter
26055
+ );
26056
+ masters.set(id3, masterShapes2);
26057
+ masterRecords.push({ id: id3, node: master2, shapes: masterShapes2 });
25742
26058
  }
25743
- };
26059
+ }
26060
+ return { documentRoot, resources, styles, readPrintSettings, masters, masterRecords, reports };
25744
26061
  }
25745
26062
 
25746
26063
  // visio/shape-metadata.ts
@@ -25760,6 +26077,10 @@ function createMetadataBudget(options2 = {}) {
25760
26077
  if (characters > maxCharacters)
25761
26078
  throw new VisioPackageError("METADATA_LIMIT", "Shape metadata character budget exceeded.");
25762
26079
  return value3;
26080
+ },
26081
+ state: () => [rows, characters],
26082
+ restore(state) {
26083
+ [rows, characters] = state;
25763
26084
  }
25764
26085
  };
25765
26086
  }
@@ -26658,177 +26979,6 @@ function readVisioPageSetup(cells4) {
26658
26979
  return Object.keys(result2).length ? result2 : void 0;
26659
26980
  }
26660
26981
 
26661
- // visio/print-settings.ts
26662
- var NAMES2 = [
26663
- "PaperKind",
26664
- "PrintPageOrientation",
26665
- "PageLeftMargin",
26666
- "PageRightMargin",
26667
- "PageTopMargin",
26668
- "PageBottomMargin",
26669
- "ScaleX",
26670
- "ScaleY",
26671
- "OnPage",
26672
- "PagesX",
26673
- "PagesY",
26674
- "CenterX",
26675
- "CenterY"
26676
- ];
26677
- var BOOLEAN = /* @__PURE__ */ new Set(["OnPage", "CenterX", "CenterY"]);
26678
- var LENGTH = /* @__PURE__ */ new Set(["PageLeftMargin", "PageRightMargin", "PageTopMargin", "PageBottomMargin"]);
26679
- var CANONICAL = new Map(
26680
- [...NAMES2, "PageWidth", "PageHeight", "PageScale", "DrawingScale"].map((name3) => [
26681
- name3.toLowerCase(),
26682
- name3
26683
- ])
26684
- );
26685
- function indexCells2(sheet) {
26686
- const cells4 = /* @__PURE__ */ new Map();
26687
- let duplicate = false;
26688
- for (const node3 of children2(sheet, "Cell")) {
26689
- const name3 = attribute2(node3, "N") ?? "", canonical2 = CANONICAL.get(name3.toLowerCase());
26690
- if (!canonical2) continue;
26691
- if (canonical2 !== name3) duplicate = true;
26692
- const values = cells4.get(canonical2) ?? [];
26693
- if (values.length < 2) values.push(node3);
26694
- cells4.set(canonical2, values);
26695
- if (values.length > 1) duplicate = true;
26696
- }
26697
- return { cells: cells4, duplicate };
26698
- }
26699
- function createVisioPrintSettingsReader(documentSheets, rootStyles) {
26700
- const indexes = { document: indexCells2(documentSheets[0]), root: indexCells2(rootStyles[0]) };
26701
- return (pageSheets) => readVisioPrintCountSettings(pageSheets, documentSheets, rootStyles, indexes);
26702
- }
26703
- function readVisioPrintCountSettings(pageSheets, documentSheets, rootStyles, indexes) {
26704
- let refusal;
26705
- const refuse5 = (reason) => {
26706
- refusal ??= reason;
26707
- };
26708
- if (pageSheets.length !== 1) refuse5("ambiguous-page-sheet");
26709
- if (documentSheets.length > 1) refuse5("ambiguous-document-sheet");
26710
- if (!documentSheets.length) refuse5("missing-setting");
26711
- if (rootStyles.length > 1) refuse5("duplicate-setting");
26712
- const root2 = rootStyles[0];
26713
- if (!root2 || attribute2(root2, "ID") !== "0" || attribute2(root2, "NameU") !== "No Style")
26714
- refuse5("unsupported-print-style");
26715
- for (const sheet of [...pageSheets, ...documentSheets])
26716
- for (const name3 of ["LineStyle", "FillStyle", "TextStyle"])
26717
- if (attribute2(sheet, name3) !== "0") refuse5("unsupported-print-style");
26718
- for (const name3 of ["LineStyle", "FillStyle", "TextStyle"])
26719
- if (attribute2(root2, name3) !== void 0) refuse5("unsupported-print-style");
26720
- const localIndex = indexCells2(pageSheets[0]), rootIndex = indexes?.root ?? indexCells2(root2);
26721
- const documentIndex = indexes?.document ?? indexCells2(documentSheets[0]);
26722
- if (localIndex.duplicate || rootIndex.duplicate || documentIndex.duplicate)
26723
- refuse5("duplicate-setting");
26724
- const local = localIndex.cells, inherited = rootIndex.cells;
26725
- const read = (node3, name3, origin) => {
26726
- const invalid5 = () => {
26727
- refuse5(origin === "local" ? "invalid-local-setting" : "invalid-document-setting");
26728
- return void 0;
26729
- };
26730
- if (node3.hasAttribute("E")) return invalid5();
26731
- let raw = (attribute2(node3, "V") ?? "").trim();
26732
- if (!raw || raw.length > 128) return invalid5();
26733
- if (BOOLEAN.has(name3)) {
26734
- if (!["0", "1", "false", "true"].includes(raw)) return invalid5();
26735
- raw = raw === "true" ? "1" : raw === "false" ? "0" : raw;
26736
- }
26737
- try {
26738
- const value3 = visioFormulaCachedValue(raw, attribute2(node3, "U"));
26739
- const length = LENGTH.has(name3) || /^(PageWidth|PageHeight|PageScale|DrawingScale)$/.test(name3);
26740
- if (!["scalar", ...length ? ["length"] : []].includes(value3.unit) || Math.abs(value3.value) > 1e9)
26741
- return invalid5();
26742
- const formula = attribute2(node3, "F");
26743
- if (formula !== void 0) {
26744
- const source = formula.trim();
26745
- if (/^(true|false)$/i.test(source)) {
26746
- if ((source.toLowerCase() === "true" ? 1 : 0) !== value3.value) return invalid5();
26747
- } else {
26748
- if (!source || source === "Inh") return invalid5();
26749
- const limits = { maxLength: 512, maxNodes: 64, maxDepth: 16, maxSteps: 128 };
26750
- const analysis = analyzeVisioFormula(source, limits);
26751
- if (analysis.dynamic || analysis.guarded || analysis.references.length || analysis.unsupportedFunctions.length) {
26752
- refuse5("dynamic-setting");
26753
- return void 0;
26754
- }
26755
- const evaluated = evaluateVisioFormula(
26756
- source,
26757
- () => {
26758
- throw new Error("Unexpected reference");
26759
- },
26760
- limits
26761
- );
26762
- if (evaluated.value !== value3.value || !["scalar", ...length ? ["length"] : []].includes(evaluated.unit))
26763
- return invalid5();
26764
- }
26765
- }
26766
- return value3.value;
26767
- } catch {
26768
- return invalid5();
26769
- }
26770
- };
26771
- const values = /* @__PURE__ */ new Map();
26772
- for (const name3 of NAMES2) {
26773
- const nodes = local.get(name3) ?? inherited.get(name3);
26774
- if (!nodes?.length) continue;
26775
- if (nodes.length !== 1) continue;
26776
- const value3 = read(nodes[0], name3, local.has(name3) ? "local" : "document");
26777
- if (value3 !== void 0) values.set(name3, value3);
26778
- }
26779
- for (const name3 of ["PageWidth", "PageHeight", "PageScale", "DrawingScale"]) {
26780
- const nodes = local.get(name3);
26781
- if (!nodes || nodes.length !== 1 || !(read(nodes[0], name3, "local") > 0))
26782
- refuse5("unusable-drawing-scale");
26783
- }
26784
- const setup = {};
26785
- const paper = values.get("PaperKind");
26786
- if (paper !== void 0 && Number.isSafeInteger(paper) && paper >= 0 && paper <= 65535)
26787
- setup.paperKind = paper;
26788
- else if (paper !== void 0)
26789
- refuse5(local.has("PaperKind") ? "invalid-local-setting" : "invalid-document-setting");
26790
- const orientation = values.get("PrintPageOrientation");
26791
- if (orientation === 0 || orientation === 1 || orientation === 2)
26792
- setup.printPageOrientation = orientation;
26793
- else if (orientation !== void 0)
26794
- refuse5(
26795
- local.has("PrintPageOrientation") ? "invalid-local-setting" : "invalid-document-setting"
26796
- );
26797
- const margins = ["Left", "Right", "Top", "Bottom"].map((side2) => values.get(`Page${side2}Margin`));
26798
- if (margins.every((n) => n !== void 0 && n >= 0 && n <= 1e3))
26799
- setup.margins = {
26800
- left: margins[0],
26801
- right: margins[1],
26802
- top: margins[2],
26803
- bottom: margins[3]
26804
- };
26805
- else if (margins.some((n) => n !== void 0 && (n < 0 || n > 1e3)))
26806
- refuse5("unusable-print-area");
26807
- for (const [name3, key2] of [
26808
- ["ScaleX", "printZoom"],
26809
- ["ScaleY", "printZoomY"],
26810
- ["PagesX", "printPagesAcross"],
26811
- ["PagesY", "printPagesDown"]
26812
- ]) {
26813
- const value3 = values.get(name3);
26814
- if (value3 !== void 0) {
26815
- if ((name3 === "PagesX" || name3 === "PagesY") && (!Number.isSafeInteger(value3) || value3 < 1))
26816
- refuse5(local.has(name3) ? "invalid-local-setting" : "invalid-document-setting");
26817
- else setup[key2] = value3;
26818
- }
26819
- }
26820
- for (const [name3, key2] of [
26821
- ["OnPage", "printFitToPages"],
26822
- ["CenterX", "printCenterX"],
26823
- ["CenterY", "printCenterY"]
26824
- ]) {
26825
- const value3 = values.get(name3);
26826
- if (value3 !== void 0) setup[key2] = value3 === 1;
26827
- }
26828
- if (refusal) setup.printCountRefusal = refusal;
26829
- return setup;
26830
- }
26831
-
26832
26982
  // visio/master-list.ts
26833
26983
  var MAX_LISTED_MASTERS = 500;
26834
26984
  var PREVIEW_SHAPES = 5e3;
@@ -27026,69 +27176,18 @@ async function parseVsdx(input, options2 = {}) {
27026
27176
  );
27027
27177
  }
27028
27178
  }
27029
- const documentRoot = await visioXml(pkg, documentPart2, "VisioDocument");
27030
- const resources = {
27031
- colors: /* @__PURE__ */ new Map(),
27032
- fonts: /* @__PURE__ */ new Map(),
27033
- themes: await loadVisioThemes(pkg, documentPart2, report)
27034
- };
27035
- for (const color2 of children2(child(documentRoot, "Colors"), "ColorEntry"))
27036
- resources.colors.set(attribute2(color2, "IX") ?? "", attribute2(color2, "RGB") ?? "");
27037
- const faceNames = children2(child(documentRoot, "FaceNames"), "FaceName");
27038
- if (faceNames.length > 1e4)
27039
- throw new VisioPackageError(
27040
- "METADATA_LIMIT",
27041
- "Document font count exceeds its metadata limit."
27042
- );
27043
- let fontCharacters = 0;
27044
- faceNames.forEach((font, index2) => {
27045
- checkTime();
27046
- fontCharacters += (attribute2(font, "Name") ?? attribute2(font, "NameU") ?? "Arial").length;
27047
- if (fontCharacters > 1e6)
27048
- throw new VisioPackageError(
27049
- "METADATA_LIMIT",
27050
- "Document fonts exceed aggregate metadata limits."
27051
- );
27052
- resources.fonts.set(
27053
- metadata(attribute2(font, "ID") ?? String(index2), 256, "Font ID"),
27054
- metadata(attribute2(font, "Name") ?? attribute2(font, "NameU") ?? "Arial", 1024, "Font name")
27055
- );
27056
- });
27057
- const styles = /* @__PURE__ */ new Map();
27058
- for (const style2 of children2(child(documentRoot, "StyleSheets"), "StyleSheet"))
27059
- styles.set(metadata(attribute2(style2, "ID") ?? "", 256, "Style ID"), {
27060
- sheet: readSheet(style2),
27061
- attributes: metadataAttributes(style2)
27062
- });
27063
- const rootStyle = styles.get("0");
27064
- if (rootStyle?.attributes.get("NameU") === "No Style") resources.rootSheet = rootStyle.sheet;
27065
- const printStyleGroups = children2(documentRoot, "StyleSheets");
27066
- const readPrintSettings = createVisioPrintSettingsReader(
27067
- children2(documentRoot, "DocumentSheet"),
27068
- printStyleGroups.length === 1 ? children2(printStyleGroups[0], "StyleSheet").filter((node3) => attribute2(node3, "ID") === "0") : []
27069
- );
27070
- const masters = /* @__PURE__ */ new Map();
27071
- const masterRecords = [];
27072
- const mastersPart = await related(pkg, documentPart2, "masters", false);
27073
- if (mastersPart) {
27074
- for (const master2 of children2(await visioXml(pkg, mastersPart, "Masters"), "Master")) {
27075
- const part = await indexedPart(pkg, mastersPart, master2, "master");
27076
- const id3 = metadata(attribute2(master2, "ID") ?? "", 256, "Master ID");
27077
- if (!id3 || masters.has(id3))
27078
- throw new VisioPackageError("INVALID_MASTER_ID", "Master IDs must be present and unique.");
27079
- const masterShapes2 = readShapes(await visioXml(pkg, part, "MasterContents"));
27080
- await prepareImages(
27081
- masterShapes2,
27082
- pkg,
27083
- part,
27084
- report,
27085
- options2.images,
27086
- options2.metafileConverter
27087
- );
27088
- masters.set(id3, masterShapes2);
27089
- masterRecords.push({ id: id3, node: master2, shapes: masterShapes2 });
27090
- }
27091
- }
27179
+ const cache2 = options2.documentCache;
27180
+ const cached5 = cacheMatches(cache2?.entry, pkg, options2) ? cache2.entry : void 0;
27181
+ const stopRecording = cache2 && !cached5 ? pkg.record() : void 0;
27182
+ let level2;
27183
+ if (cached5) {
27184
+ level2 = cached5.level;
27185
+ for (const args of level2.reports) report(...args);
27186
+ } else level2 = await readDocumentLevel(pkg, documentPart2, options2, checkTime, report);
27187
+ const { documentRoot, styles, readPrintSettings, masters, masterRecords } = level2;
27188
+ const resources = { ...level2.resources };
27189
+ delete resources.pageCells;
27190
+ delete resources.fieldContext;
27092
27191
  let geometryCount = 0, textCount = 0, expansionCount = 0, textRuns = 0, paragraphCount = 0;
27093
27192
  const context = {
27094
27193
  metadataBudget: createMetadataBudget(options2.metadata),
@@ -27142,15 +27241,52 @@ async function parseVsdx(input, options2 = {}) {
27142
27241
  throw new VisioPackageError("TEXT_LIMIT", "Text character limit exceeded.");
27143
27242
  }
27144
27243
  };
27145
- const documentMasters = listVisioMasters(masterRecords, context, {
27146
- metadataBudget: createMetadataBudget(options2.metadata),
27147
- layerBudget: createLayerBudget()
27148
- });
27244
+ let documentMasters;
27245
+ if (cached5) {
27246
+ const { counters } = cached5.listed;
27247
+ curveWork = counters.curveWork;
27248
+ geometryCount = counters.geometry;
27249
+ textCount = counters.text;
27250
+ expansionCount = counters.expansion;
27251
+ textRuns = counters.textRuns;
27252
+ paragraphCount = counters.paragraphs;
27253
+ context.shapeCount = counters.shapes;
27254
+ context.metadataBudget.restore(counters.metadata);
27255
+ context.layerBudget.restore(counters.layers);
27256
+ documentMasters = cached5.listed.documentMasters;
27257
+ } else {
27258
+ documentMasters = listVisioMasters(masterRecords, context, {
27259
+ metadataBudget: createMetadataBudget(options2.metadata),
27260
+ layerBudget: createLayerBudget()
27261
+ });
27262
+ if (cache2 && stopRecording)
27263
+ cache2.entry = {
27264
+ options: optionsKey(options2),
27265
+ converter: options2.metafileConverter,
27266
+ reads: stopRecording(),
27267
+ level: { ...level2, resources: { ...resources } },
27268
+ listed: {
27269
+ documentMasters,
27270
+ counters: {
27271
+ curveWork,
27272
+ geometry: geometryCount,
27273
+ text: textCount,
27274
+ expansion: expansionCount,
27275
+ textRuns,
27276
+ paragraphs: paragraphCount,
27277
+ shapes: context.shapeCount,
27278
+ metadata: context.metadataBudget.state(),
27279
+ layers: context.layerBudget.state()
27280
+ }
27281
+ }
27282
+ };
27283
+ }
27149
27284
  const pagesPart = await related(pkg, documentPart2, "pages", !options2.stencil);
27150
27285
  if (!pagesPart && !options2.stencil)
27151
27286
  throw new VisioPackageError("INVALID_DOCUMENT", "Missing Visio pages part.");
27152
27287
  const pages = [], pageIds2 = /* @__PURE__ */ new Set();
27153
27288
  const comments = [];
27289
+ const only = options2.pages ? new Set(options2.pages) : void 0;
27154
27290
  const pageNodes = pagesPart ? children2(await visioXml(pkg, pagesPart, "Pages"), "Page") : [];
27155
27291
  const foreground = pageNodes.filter((page) => !yes(attribute2(page, "Background")));
27156
27292
  const fieldProperties = await readVisioFieldProperties(pkg);
@@ -27160,6 +27296,7 @@ async function parseVsdx(input, options2 = {}) {
27160
27296
  if (!id3 || pageIds2.has(id3))
27161
27297
  throw new VisioPackageError("INVALID_PAGE_ID", "Page IDs must be present and unique.");
27162
27298
  pageIds2.add(id3);
27299
+ if (only && !only.has(id3)) continue;
27163
27300
  const part = await indexedPart(pkg, pagesPart, page, "page");
27164
27301
  const root2 = await visioXml(pkg, part, "PageContents");
27165
27302
  const localReport = (code, message, extra) => report(code, message, { part, pageId: id3, ...extra });
@@ -27269,16 +27406,16 @@ async function parseVsdx(input, options2 = {}) {
27269
27406
  });
27270
27407
  }
27271
27408
  checkTime();
27272
- validateBackgrounds(pages, report);
27409
+ if (!only) validateBackgrounds(pages, report);
27273
27410
  try {
27274
- comments.push(...await readVisioComments(pkg, documentPart2, report));
27411
+ if (!only) comments.push(...await readVisioComments(pkg, documentPart2, report));
27275
27412
  } catch (error) {
27276
27413
  if (!(error instanceof VisioPackageError) || error.code === "LIMIT_RUNTIME") throw error;
27277
27414
  report("invalid-comments", "The comments part could not be read; comments are not shown.");
27278
27415
  }
27279
27416
  let dataRecordsets = [];
27280
27417
  try {
27281
- dataRecordsets = await readDataRecordsets(pkg, documentPart2, checkTime);
27418
+ if (!only) dataRecordsets = await readDataRecordsets(pkg, documentPart2, checkTime);
27282
27419
  } catch (error) {
27283
27420
  if (error instanceof VisioPackageError && error.code === "LIMIT_RUNTIME") throw error;
27284
27421
  report(
@@ -27286,7 +27423,7 @@ async function parseVsdx(input, options2 = {}) {
27286
27423
  `Saved external data could not be read and is preserved unchanged: ${error instanceof Error ? error.message : String(error)}`
27287
27424
  );
27288
27425
  }
27289
- const stencils = await readVisioStencilWindows(pkg, documentPart2);
27426
+ const stencils = only ? [] : await readVisioStencilWindows(pkg, documentPart2);
27290
27427
  report(
27291
27428
  "cached-values-only",
27292
27429
  "ShapeSheet formulas, automatic connector routing, and external data are not evaluated; saved cached values and supported theme records are used.",
@@ -45186,4 +45323,4 @@ async function createSampleVsdx() {
45186
45323
  return (await editVsdx(pages.bytes, PAGES.flatMap(shapeEdits))).bytes;
45187
45324
  }
45188
45325
 
45189
- export { DocumentHistory, EDIT_HISTORY_LIMITS, EMPTY_EDIT_STATE, EMPTY_SELECTION, EMPTY_TEXT_SEARCH, FOREIGN_VECTOR_SCENE_LIMITS, ForeignVectorBudget, MAX_INPUT_BYTES, TEXT_SEARCH_LIMITS, VISIO_AUTO_CONNECT_DIRECTIONS, VISIO_AUTO_CONNECT_GAP, VISIO_AUTO_CONNECT_REACH, VISIO_BULLET_STYLES, VISIO_CHART_OBJECT_SIZE, VISIO_DATA_GRAPHIC_FILL_ROW, VISIO_DATA_GRAPHIC_ICONS, VISIO_DATA_GRAPHIC_ROW, VISIO_DIAGRAM_RULE_SETS, VISIO_FIELD_CATEGORIES, VISIO_FORMAT_PAINTER_LIMITS, VISIO_GRID_DENSITY_CHOICES, IDENTITY_AFFINE as VISIO_IDENTITY_TRANSFORM, VISIO_INITIAL_PRESENCE, VISIO_LAYOUT_LABELS, VISIO_LAYOUT_STYLES, VISIO_PAGE_SIZE_PRESETS, VISIO_PAPER_SIZES, VISIO_PASTE_TEXT_LIMIT, VISIO_PATH_CLOSE_DISTANCE, VISIO_PATH_TOLERANCE, VISIO_PICTURE_DPI, VISIO_PRESENCE_MAX_COORDINATE, VISIO_PRESENCE_MAX_ID, VISIO_PRESENCE_MAX_SELECTION, VISIO_RESIZE_HANDLES, VISIO_RULER_DENSITY_CHOICES, VISIO_SELECT_TYPES, VISIO_SELECT_TYPE_LABELS, VISIO_SUBPROCESS_SHAPE, VISIO_TEXT_BLOCK_HANDLES, VISIO_TEXT_LANGUAGES, VISIO_TEXT_REPLACE_LIMITS, VisioTextDraftError, assertShapeDetails, assertViewableDocument, checkVisioDiagram, clampHistoryEntries, compatibilityNotes, compatibilityText, composeAffine as composeVisioTransform, copySnapshotScene, createSampleVsdx, demoDocument, editErrorMessage, eventKeys, excelSerialToIso, hasVisibleShapeContent, indexDocumentText, inspectForeignVectorResource, isEditCancellation, isVisioPathTool, normalizeVisioHyperlinkAddress, propertyKeys, sameSelection, sanitizeVisioPresence, searchDocumentText, selectionKey, snapshotEdits, snapshotSelection, textSearchStatus, validateSearchQuery, visioAddConnectionPointCommand, visioArrangeCommands, visioAutoAlignCommands, visioAutoConnectArrows, visioAutoConnectNeighbor, visioAutoConnectPlacement, visioAutoConnectPlan, visioAutoConnectShape, visioAutoConnectSidePoint, visioBoxCreationCommand, visioCalloutCommand, visioChangeCaseCommand, visioChangeCaseShape, visioChangeMasterCommand, visioChangeMasterTargets, visioChangeShapeCommand, visioChangeShapeRefusal, visioChartObjectInsertCommand, visioClipboardShape, visioColorRules, visioConnectableShape, visioConnectorCreationCommand, visioConnectorEdges, visioConnectorEndHandles, visioConnectorMovePreviews, visioConnectorPreviewPath, visioConnectorRouteOf, visioContainerCommand, visioCopyableShape, visioDataGraphicEdits, visioDataGraphicFields, visioDataGraphicMarker, visioDataGraphicParts, visioDataTable, visioDrawBounds, visioDrawIsLargeEnough, visioDrawPlan, visioDrawingPoint, visioDuplicateCommand, visioFileMasterDropCommand, visioFillPatternTransform, visioFitToDrawingEdits, visioFollowTarget, visioFontFamilies, visioFormatPainterEdits, visioFormatPainterSnapshot, visioFormatTargetShape, visioFormattingShape, visioGlowKey, visioGlueableShape, visioGradientInstances, visioGridSteps, visioGroupCommand, visioGuideCreateCommand, visioGuideMoveCommand, visioKeepAutoSize, visioLayerAssignCommand, visioLayerAssignCommands, visioLayerAssignState, visioLegendEdits, visioLineCreationCommand, visioLineDashLengths, visioLocalFormattingShape, visioLocalRotationShape, visioMarqueeBox, visioMarqueeSelection, visioMasterDropCommand, visioMasterDropRefusal, visioMasterDropSize, visioMasterPreviewBox, visioMatchingPaperSize, visioMovableGroup, visioMoveCommands, visioMovePreviewTransform, visioMoveTargets, visioMovementShape, visioNearestConnectionPoint, visioNewLayerNames, visioNewPageId, visioNextShapeId, visioNudgeCommands, visioOrderingShape, visioOrientationEdits, visioPageBreaks, visioPageConnectionPoints, visioPageDecorationState, visioPageDragDelta, visioPageEditToDrawing, visioPageGuides, visioPageInsertCommand, visioPageMasters, visioPageOrientationCommand, visioPageSizeCommand, visioPageSizePresetCommand, visioPageSizePresetEdits, visioPageSizeState, visioPaperSize, visioParseRange, visioPasteCommand, visioPasteTextCommand, visioPasteTextValue, visioPathDrawPlan, visioPathPreview, visioPictureInsertCommand, visioPrintTile, visioQuarterTurnCommand, visioReLayoutCommands, visioReflectionKey, visioRemoveDataGraphicEdits, visioRenderedGradientStopCount, visioRenderedGradientStops, visioResizeDrag, visioResizeFrame, visioResizeShape, visioRotationPreviewTransform, visioRotationShape, visioRulerDensityFactor, visioRulerGridEdits, visioRulerGridValues, visioSceneToLocal, visioSelectByType, visioSelectionIsOnPage, visioShadowPreset, visioShapeDataNumber, visioShapeDataRow, visioShapeDataText, visioShapeEffectValues, visioShapeFormattingState, visioShapeFrame, visioShapeLocalPoint, visioShapePageBox, visioShapeReport, visioShapeReportCsv, visioShapeReportTable, visioShapeReportText, visioShapeSelectType, visioShapeSnapBox, visioSizePositionCommand, visioSizePositionState, visioSnapMoveDelta, visioStencilDropCommand, visioStencilInstanceShape, visioStencilShape, visioStencilSubShape, visioStraightLineHandles, visioStrokeGradient, visioStyleFormattingShape, visioSubprocessCommand, visioSvgStrokeStyle, visioTextAppendEdit, visioTextBlockDrag, visioTextBlockEdit, visioTextBlockFrame, visioTextBlockMatrix, visioTextBlockShape, visioTextDialogPatch, visioTextDialogValues, visioTextDraftEdit, visioTextFontStepCommand, visioTextFormattingState, visioTextIndentCommand, visioTextOccurrenceSelection, visioTextReplaceCommands, visioTextReplaceFindNext, visioTextReplaceOccurrences, visioTextReplacePlan, visioTextShape, visioTextSource, visioUngroupCommand, visioWithCalloutLeaders, visioWithContainerMembers, visioWithDataGraphics, visioWorkbookGrid };
45326
+ export { DocumentHistory, EDIT_HISTORY_LIMITS, EMPTY_EDIT_STATE, EMPTY_SELECTION, EMPTY_TEXT_SEARCH, FOREIGN_VECTOR_SCENE_LIMITS, ForeignVectorBudget, MAX_INPUT_BYTES, TEXT_SEARCH_LIMITS, VISIO_AUTO_CONNECT_DIRECTIONS, VISIO_AUTO_CONNECT_GAP, VISIO_AUTO_CONNECT_REACH, VISIO_BULLET_STYLES, VISIO_CAPABILITY_BACKSTAGE_PAGES, VISIO_CAPABILITY_COMMANDS, VISIO_CAPABILITY_IDS, VISIO_CHART_OBJECT_SIZE, VISIO_DATA_GRAPHIC_FILL_ROW, VISIO_DATA_GRAPHIC_ICONS, VISIO_DATA_GRAPHIC_ROW, VISIO_DIAGRAM_RULE_SETS, VISIO_FIELD_CATEGORIES, VISIO_FORMAT_PAINTER_LIMITS, VISIO_GRID_DENSITY_CHOICES, IDENTITY_AFFINE as VISIO_IDENTITY_TRANSFORM, VISIO_INITIAL_PRESENCE, VISIO_LAYOUT_LABELS, VISIO_LAYOUT_STYLES, VISIO_PAGE_SIZE_PRESETS, VISIO_PAPER_SIZES, VISIO_PASTE_TEXT_LIMIT, VISIO_PATH_CLOSE_DISTANCE, VISIO_PATH_TOLERANCE, VISIO_PICTURE_DPI, VISIO_PRESENCE_MAX_COORDINATE, VISIO_PRESENCE_MAX_ID, VISIO_PRESENCE_MAX_SELECTION, VISIO_RESIZE_HANDLES, VISIO_RULER_DENSITY_CHOICES, VISIO_SELECT_TYPES, VISIO_SELECT_TYPE_LABELS, VISIO_SUBPROCESS_SHAPE, VISIO_TEXT_BLOCK_HANDLES, VISIO_TEXT_LANGUAGES, VISIO_TEXT_REPLACE_LIMITS, VisioTextDraftError, assertShapeDetails, assertViewableDocument, checkVisioDiagram, clampHistoryEntries, compatibilityNotes, compatibilityText, composeAffine as composeVisioTransform, copySnapshotScene, createSampleVsdx, demoDocument, editErrorMessage, eventKeys, excelSerialToIso, hasVisibleShapeContent, indexDocumentText, inspectForeignVectorResource, isEditCancellation, isVisioPathTool, normalizeVisioHyperlinkAddress, propertyKeys, sameSelection, sanitizeVisioPresence, searchDocumentText, selectionKey, snapshotEdits, snapshotSelection, textSearchStatus, validateSearchQuery, visioAddConnectionPointCommand, visioArrangeCommands, visioAutoAlignCommands, visioAutoConnectArrows, visioAutoConnectNeighbor, visioAutoConnectPlacement, visioAutoConnectPlan, visioAutoConnectShape, visioAutoConnectSidePoint, visioBoxCreationCommand, visioCalloutCommand, visioChangeCaseCommand, visioChangeCaseShape, visioChangeMasterCommand, visioChangeMasterTargets, visioChangeShapeCommand, visioChangeShapeRefusal, visioChartObjectInsertCommand, visioClipboardShape, visioColorRules, visioConnectableShape, visioConnectorCreationCommand, visioConnectorEdges, visioConnectorEndHandles, visioConnectorMovePreviews, visioConnectorPreviewPath, visioConnectorRouteOf, visioContainerCommand, visioCopyableShape, visioDataGraphicEdits, visioDataGraphicFields, visioDataGraphicMarker, visioDataGraphicParts, visioDataTable, visioDrawBounds, visioDrawIsLargeEnough, visioDrawPlan, visioDrawingPoint, visioDuplicateCommand, visioFileMasterDropCommand, visioFillPatternTransform, visioFitToDrawingEdits, visioFollowTarget, visioFontFamilies, visioFormatPainterEdits, visioFormatPainterSnapshot, visioFormatTargetShape, visioFormattingShape, visioGlowKey, visioGlueableShape, visioGradientInstances, visioGridSteps, visioGroupCommand, visioGuideCreateCommand, visioGuideMoveCommand, visioKeepAutoSize, visioLayerAssignCommand, visioLayerAssignCommands, visioLayerAssignState, visioLegendEdits, visioLineCreationCommand, visioLineDashLengths, visioLocalFormattingShape, visioLocalRotationShape, visioMarqueeBox, visioMarqueeSelection, visioMasterDropCommand, visioMasterDropRefusal, visioMasterDropSize, visioMasterPreviewBox, visioMatchingPaperSize, visioMovableGroup, visioMoveCommands, visioMovePreviewTransform, visioMoveTargets, visioMovementShape, visioNearestConnectionPoint, visioNewLayerNames, visioNewPageId, visioNextShapeId, visioNudgeCommands, visioOrderingShape, visioOrientationEdits, visioPageBreaks, visioPageConnectionPoints, visioPageDecorationState, visioPageDragDelta, visioPageEditToDrawing, visioPageGuides, visioPageInsertCommand, visioPageMasters, visioPageOrientationCommand, visioPageSizeCommand, visioPageSizePresetCommand, visioPageSizePresetEdits, visioPageSizeState, visioPaperSize, visioParseRange, visioPasteCommand, visioPasteTextCommand, visioPasteTextValue, visioPathDrawPlan, visioPathPreview, visioPictureInsertCommand, visioPrintTile, visioQuarterTurnCommand, visioReLayoutCommands, visioReflectionKey, visioRemoveDataGraphicEdits, visioRenderedGradientStopCount, visioRenderedGradientStops, visioResizeDrag, visioResizeFrame, visioResizeShape, visioRotationPreviewTransform, visioRotationShape, visioRulerDensityFactor, visioRulerGridEdits, visioRulerGridValues, visioSceneToLocal, visioSelectByType, visioSelectionIsOnPage, visioShadowPreset, visioShapeDataNumber, visioShapeDataRow, visioShapeDataText, visioShapeEffectValues, visioShapeFormattingState, visioShapeFrame, visioShapeLocalPoint, visioShapePageBox, visioShapeReport, visioShapeReportCsv, visioShapeReportTable, visioShapeReportText, visioShapeSelectType, visioShapeSnapBox, visioSizePositionCommand, visioSizePositionState, visioSnapMoveDelta, visioStencilDropCommand, visioStencilInstanceShape, visioStencilShape, visioStencilSubShape, visioStraightLineHandles, visioStrokeGradient, visioStyleFormattingShape, visioSubprocessCommand, visioSvgStrokeStyle, visioTextAppendEdit, visioTextBlockDrag, visioTextBlockEdit, visioTextBlockFrame, visioTextBlockMatrix, visioTextBlockShape, visioTextDialogPatch, visioTextDialogValues, visioTextDraftEdit, visioTextFontStepCommand, visioTextFormattingState, visioTextIndentCommand, visioTextOccurrenceSelection, visioTextReplaceCommands, visioTextReplaceFindNext, visioTextReplaceOccurrences, visioTextReplacePlan, visioTextShape, visioTextSource, visioUngroupCommand, visioWithCalloutLeaders, visioWithContainerMembers, visioWithDataGraphics, visioWorkbookGrid };