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
@@ -734,6 +734,7 @@ var VisioPackage = class _VisioPackage {
734
734
  relationshipCache = /* @__PURE__ */ new Map();
735
735
  byteCache = /* @__PURE__ */ new Map();
736
736
  decodedNames = /* @__PURE__ */ new Map();
737
+ noted;
737
738
  totalOutput = 0;
738
739
  totalXmlNodes = 0;
739
740
  check = () => {
@@ -768,7 +769,26 @@ var VisioPackage = class _VisioPackage {
768
769
  );
769
770
  }
770
771
  }
772
+ /**
773
+ * Starts noting every part this package is asked about (read, listed in a relationship, or
774
+ * checked for). The returned function stops noting and gives each part with a print of its
775
+ * declared CRC-32 and size (empty when absent), which is what {@link printOf} compares.
776
+ */
777
+ record() {
778
+ const noted = /* @__PURE__ */ new Set();
779
+ this.noted = noted;
780
+ return () => {
781
+ if (this.noted === noted) this.noted = void 0;
782
+ return [...noted].sort().map((path2) => [path2, this.printOf(path2)]);
783
+ };
784
+ }
785
+ /** The declared CRC-32 and size of a part, or an empty string when the package lacks it. */
786
+ printOf(path2) {
787
+ const entry3 = this.entries.get(path2);
788
+ return entry3 && !entry3.directory ? `${entry3.crc}:${entry3.size}` : "";
789
+ }
771
790
  has(path2) {
791
+ this.noted?.add(path2);
772
792
  return this.entries.get(path2)?.directory === false;
773
793
  }
774
794
  paths() {
@@ -776,6 +796,7 @@ var VisioPackage = class _VisioPackage {
776
796
  }
777
797
  async readXml(path2, expectedRoot) {
778
798
  this.check();
799
+ this.noted?.add(path2);
779
800
  safePath(path2);
780
801
  let pending2 = this.cache.get(path2);
781
802
  if (!pending2) {
@@ -791,6 +812,7 @@ var VisioPackage = class _VisioPackage {
791
812
  /** Validated declared size, so resource-specific limits can reject before inflation. */
792
813
  getPartByteLength(path2) {
793
814
  this.check();
815
+ this.noted?.add(path2);
794
816
  safePath(path2);
795
817
  const entry3 = this.entries.get(path2);
796
818
  if (!entry3 || entry3.directory) fail("MISSING_PART", `Missing package part: ${path2}`);
@@ -799,6 +821,7 @@ var VisioPackage = class _VisioPackage {
799
821
  /** Shared package-owned bytes. Treat the returned buffer as immutable. */
800
822
  async readBytes(path2) {
801
823
  this.check();
824
+ this.noted?.add(path2);
802
825
  safePath(path2);
803
826
  let pending2 = this.byteCache.get(path2);
804
827
  if (!pending2) {
@@ -892,6 +915,10 @@ var VisioPackage = class _VisioPackage {
892
915
  }
893
916
  async relationships(sourcePart) {
894
917
  this.check();
918
+ if (this.noted && sourcePart) {
919
+ const slash = sourcePart.lastIndexOf("/");
920
+ this.noted.add(`${sourcePart.slice(0, slash + 1)}_rels/${sourcePart.slice(slash + 1)}.rels`);
921
+ } else this.noted?.add("_rels/.rels");
895
922
  let pending2 = this.relationshipCache.get(sourcePart);
896
923
  if (!pending2) {
897
924
  pending2 = this.loadRelationships(sourcePart);
@@ -925,6 +952,7 @@ var VisioPackage = class _VisioPackage {
925
952
  const actual = mode === "Internal" ? this.decodedNames.get(resolved) : void 0;
926
953
  if (mode === "Internal" && !actual)
927
954
  fail("INVALID_RELATIONSHIP", `Missing relationship target: ${resolved}`);
955
+ if (actual) this.noted?.add(actual);
928
956
  result2.set(id3, { id: id3, type, target: actual ?? resolved, mode });
929
957
  }
930
958
  return result2;
@@ -22198,6 +22226,10 @@ function createLayerBudget() {
22198
22226
  memberships += count;
22199
22227
  if (memberships > 1e5)
22200
22228
  throw new VisioPackageError("METADATA_LIMIT", "Layer membership budget exceeded.");
22229
+ },
22230
+ state: () => [memberships, characters],
22231
+ restore(state) {
22232
+ [memberships, characters] = state;
22201
22233
  }
22202
22234
  };
22203
22235
  }
@@ -22269,97 +22301,6 @@ function shapeLayers(sheet, layers, report, budget = createLayerBudget()) {
22269
22301
  };
22270
22302
  }
22271
22303
 
22272
- // visio/theme.ts
22273
- var VISIO_SCHEME_SLOTS = [
22274
- "dk1",
22275
- "lt1",
22276
- "accent1",
22277
- "accent2",
22278
- "accent3",
22279
- "accent4",
22280
- "accent5",
22281
- "accent6"
22282
- ];
22283
- var componentId = (node3) => integer3(themeChild(node3, "schemeID", THEME_NS)?.getAttribute("schemeEnum"));
22284
- async function loadVisioThemes(pkg, source, report) {
22285
- const result2 = [];
22286
- for (const rel of (await pkg.relationships(source)).values()) {
22287
- if (rel.type !== "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" || rel.mode === "External")
22288
- continue;
22289
- const root2 = await pkg.readXml(rel.target, "theme");
22290
- if (root2.namespaceURI !== DRAWING_NS) {
22291
- report("unsupported-theme", "A theme uses an unsupported XML namespace.", {
22292
- part: rel.target
22293
- });
22294
- continue;
22295
- }
22296
- const base2 = themeChild(root2, "themeElements");
22297
- const palette = themeChild(base2, "clrScheme");
22298
- const scheme = parseTheme(root2).colorScheme.colors;
22299
- const colors = /* @__PURE__ */ new Map();
22300
- for (const name4 of VISIO_SCHEME_SLOTS) {
22301
- const color2 = scheme[name4];
22302
- if (color2 && parsedColorChoice(themeChild(palette, name4))) colors.set(name4, color2);
22303
- }
22304
- const background2 = parsedColorChoice(extension(palette, "bkgnd"));
22305
- if (background2) colors.set("bkgnd", background2);
22306
- const variants = themeChildren(
22307
- extension(palette, "variationClrSchemeLst"),
22308
- "variationClrScheme",
22309
- THEME_NS
22310
- ).slice(0, 4).map((variant) => {
22311
- const entries = /* @__PURE__ */ new Map();
22312
- for (let index2 = 1; index2 <= 7; index2++) {
22313
- const choice2 = parsedColorChoice(themeChild(variant, `varColor${index2}`, THEME_NS));
22314
- if (choice2) entries.set(String(index2), choice2);
22315
- }
22316
- return entries;
22317
- });
22318
- const format5 = themeChild(base2, "fmtScheme");
22319
- const connector2 = extension(base2, "fmtConnectorScheme");
22320
- const fonts = extension(base2, "fontStylesGroup");
22321
- const name3 = root2.getAttribute("name");
22322
- result2.push({
22323
- ...name3 ? { name: name3.slice(0, 256) } : {},
22324
- colorId: integer3(extension(palette, "schemeID")?.getAttribute("schemeEnum")),
22325
- effectId: componentId(extension(base2, "fmtSchemeEx")),
22326
- connectorId: componentId(extension(base2, "fmtConnectorSchemeEx")),
22327
- colors,
22328
- variants,
22329
- variationStyles: themeChildren(
22330
- extension(base2, "variationStyleSchemeLst"),
22331
- "variationStyleScheme",
22332
- THEME_NS
22333
- ).slice(0, 4).map((variant) => themeChildren(variant, "varStyle", THEME_NS).slice(0, 4)),
22334
- fills: formatList(format5, "fillStyleLst"),
22335
- effects: themeChildren(themeChild(format5, "effectStyleLst"), "effectStyle").slice(0, 6),
22336
- lines: themeChildren(themeChild(format5, "lnStyleLst"), "ln").slice(0, 6),
22337
- fonts: themeChildren(themeChild(fonts, "fontStyles", THEME_NS), "fontProps", THEME_NS).slice(
22338
- 0,
22339
- 6
22340
- ),
22341
- connectorFills: formatList(connector2, "fillStyleLst"),
22342
- connectorEffects: themeChildren(themeChild(connector2, "effectStyleLst"), "effectStyle").slice(
22343
- 0,
22344
- 6
22345
- ),
22346
- connectorLines: themeChildren(themeChild(connector2, "lnStyleLst"), "ln").slice(0, 6),
22347
- connectorFonts: themeChildren(
22348
- themeChild(fonts, "connectorFontStyles", THEME_NS),
22349
- "fontProps",
22350
- THEME_NS
22351
- ).slice(0, 6)
22352
- });
22353
- }
22354
- return result2;
22355
- }
22356
- function formatList(parent, name3) {
22357
- const list2 = themeChild(parent, name3);
22358
- return list2 ? Array.from(list2.childNodes).filter(
22359
- (node3) => node3.nodeType === 1 && node3.namespaceURI === DRAWING_NS
22360
- ).slice(0, 6) : [];
22361
- }
22362
-
22363
22304
  // visio/theme-builtins.ts
22364
22305
  var VISIO_BUILT_IN_THEME_IDS = [
22365
22306
  "office",
@@ -22523,6 +22464,346 @@ function diagnosticCollector(maxCount) {
22523
22464
  };
22524
22465
  }
22525
22466
 
22467
+ // visio/print-settings.ts
22468
+ var NAMES = [
22469
+ "PaperKind",
22470
+ "PrintPageOrientation",
22471
+ "PageLeftMargin",
22472
+ "PageRightMargin",
22473
+ "PageTopMargin",
22474
+ "PageBottomMargin",
22475
+ "ScaleX",
22476
+ "ScaleY",
22477
+ "OnPage",
22478
+ "PagesX",
22479
+ "PagesY",
22480
+ "CenterX",
22481
+ "CenterY"
22482
+ ];
22483
+ var BOOLEAN = /* @__PURE__ */ new Set(["OnPage", "CenterX", "CenterY"]);
22484
+ var LENGTH = /* @__PURE__ */ new Set(["PageLeftMargin", "PageRightMargin", "PageTopMargin", "PageBottomMargin"]);
22485
+ var CANONICAL = new Map(
22486
+ [...NAMES, "PageWidth", "PageHeight", "PageScale", "DrawingScale"].map((name3) => [
22487
+ name3.toLowerCase(),
22488
+ name3
22489
+ ])
22490
+ );
22491
+ function indexCells2(sheet) {
22492
+ const cells4 = /* @__PURE__ */ new Map();
22493
+ let duplicate = false;
22494
+ for (const node3 of children2(sheet, "Cell")) {
22495
+ const name3 = attribute2(node3, "N") ?? "", canonical2 = CANONICAL.get(name3.toLowerCase());
22496
+ if (!canonical2) continue;
22497
+ if (canonical2 !== name3) duplicate = true;
22498
+ const values = cells4.get(canonical2) ?? [];
22499
+ if (values.length < 2) values.push(node3);
22500
+ cells4.set(canonical2, values);
22501
+ if (values.length > 1) duplicate = true;
22502
+ }
22503
+ return { cells: cells4, duplicate };
22504
+ }
22505
+ function createVisioPrintSettingsReader(documentSheets, rootStyles) {
22506
+ const indexes = { document: indexCells2(documentSheets[0]), root: indexCells2(rootStyles[0]) };
22507
+ return (pageSheets) => readVisioPrintCountSettings(pageSheets, documentSheets, rootStyles, indexes);
22508
+ }
22509
+ function readVisioPrintCountSettings(pageSheets, documentSheets, rootStyles, indexes) {
22510
+ let refusal;
22511
+ const refuse4 = (reason) => {
22512
+ refusal ??= reason;
22513
+ };
22514
+ if (pageSheets.length !== 1) refuse4("ambiguous-page-sheet");
22515
+ if (documentSheets.length > 1) refuse4("ambiguous-document-sheet");
22516
+ if (!documentSheets.length) refuse4("missing-setting");
22517
+ if (rootStyles.length > 1) refuse4("duplicate-setting");
22518
+ const root2 = rootStyles[0];
22519
+ if (!root2 || attribute2(root2, "ID") !== "0" || attribute2(root2, "NameU") !== "No Style")
22520
+ refuse4("unsupported-print-style");
22521
+ for (const sheet of [...pageSheets, ...documentSheets])
22522
+ for (const name3 of ["LineStyle", "FillStyle", "TextStyle"])
22523
+ if (attribute2(sheet, name3) !== "0") refuse4("unsupported-print-style");
22524
+ for (const name3 of ["LineStyle", "FillStyle", "TextStyle"])
22525
+ if (attribute2(root2, name3) !== void 0) refuse4("unsupported-print-style");
22526
+ const localIndex = indexCells2(pageSheets[0]), rootIndex = indexes?.root ?? indexCells2(root2);
22527
+ const documentIndex = indexes?.document ?? indexCells2(documentSheets[0]);
22528
+ if (localIndex.duplicate || rootIndex.duplicate || documentIndex.duplicate)
22529
+ refuse4("duplicate-setting");
22530
+ const local = localIndex.cells, inherited = rootIndex.cells;
22531
+ const read = (node3, name3, origin) => {
22532
+ const invalid4 = () => {
22533
+ refuse4(origin === "local" ? "invalid-local-setting" : "invalid-document-setting");
22534
+ return void 0;
22535
+ };
22536
+ if (node3.hasAttribute("E")) return invalid4();
22537
+ let raw = (attribute2(node3, "V") ?? "").trim();
22538
+ if (!raw || raw.length > 128) return invalid4();
22539
+ if (BOOLEAN.has(name3)) {
22540
+ if (!["0", "1", "false", "true"].includes(raw)) return invalid4();
22541
+ raw = raw === "true" ? "1" : raw === "false" ? "0" : raw;
22542
+ }
22543
+ try {
22544
+ const value3 = visioFormulaCachedValue(raw, attribute2(node3, "U"));
22545
+ const length = LENGTH.has(name3) || /^(PageWidth|PageHeight|PageScale|DrawingScale)$/.test(name3);
22546
+ if (!["scalar", ...length ? ["length"] : []].includes(value3.unit) || Math.abs(value3.value) > 1e9)
22547
+ return invalid4();
22548
+ const formula = attribute2(node3, "F");
22549
+ if (formula !== void 0) {
22550
+ const source = formula.trim();
22551
+ if (/^(true|false)$/i.test(source)) {
22552
+ if ((source.toLowerCase() === "true" ? 1 : 0) !== value3.value) return invalid4();
22553
+ } else {
22554
+ if (!source || source === "Inh") return invalid4();
22555
+ const limits = { maxLength: 512, maxNodes: 64, maxDepth: 16, maxSteps: 128 };
22556
+ const analysis = analyzeVisioFormula(source, limits);
22557
+ if (analysis.dynamic || analysis.guarded || analysis.references.length || analysis.unsupportedFunctions.length) {
22558
+ refuse4("dynamic-setting");
22559
+ return void 0;
22560
+ }
22561
+ const evaluated = evaluateVisioFormula(
22562
+ source,
22563
+ () => {
22564
+ throw new Error("Unexpected reference");
22565
+ },
22566
+ limits
22567
+ );
22568
+ if (evaluated.value !== value3.value || !["scalar", ...length ? ["length"] : []].includes(evaluated.unit))
22569
+ return invalid4();
22570
+ }
22571
+ }
22572
+ return value3.value;
22573
+ } catch {
22574
+ return invalid4();
22575
+ }
22576
+ };
22577
+ const values = /* @__PURE__ */ new Map();
22578
+ for (const name3 of NAMES) {
22579
+ const nodes = local.get(name3) ?? inherited.get(name3);
22580
+ if (!nodes?.length) continue;
22581
+ if (nodes.length !== 1) continue;
22582
+ const value3 = read(nodes[0], name3, local.has(name3) ? "local" : "document");
22583
+ if (value3 !== void 0) values.set(name3, value3);
22584
+ }
22585
+ for (const name3 of ["PageWidth", "PageHeight", "PageScale", "DrawingScale"]) {
22586
+ const nodes = local.get(name3);
22587
+ if (!nodes || nodes.length !== 1 || !(read(nodes[0], name3, "local") > 0))
22588
+ refuse4("unusable-drawing-scale");
22589
+ }
22590
+ const setup = {};
22591
+ const paper = values.get("PaperKind");
22592
+ if (paper !== void 0 && Number.isSafeInteger(paper) && paper >= 0 && paper <= 65535)
22593
+ setup.paperKind = paper;
22594
+ else if (paper !== void 0)
22595
+ refuse4(local.has("PaperKind") ? "invalid-local-setting" : "invalid-document-setting");
22596
+ const orientation = values.get("PrintPageOrientation");
22597
+ if (orientation === 0 || orientation === 1 || orientation === 2)
22598
+ setup.printPageOrientation = orientation;
22599
+ else if (orientation !== void 0)
22600
+ refuse4(
22601
+ local.has("PrintPageOrientation") ? "invalid-local-setting" : "invalid-document-setting"
22602
+ );
22603
+ const margins = ["Left", "Right", "Top", "Bottom"].map((side2) => values.get(`Page${side2}Margin`));
22604
+ if (margins.every((n) => n !== void 0 && n >= 0 && n <= 1e3))
22605
+ setup.margins = {
22606
+ left: margins[0],
22607
+ right: margins[1],
22608
+ top: margins[2],
22609
+ bottom: margins[3]
22610
+ };
22611
+ else if (margins.some((n) => n !== void 0 && (n < 0 || n > 1e3)))
22612
+ refuse4("unusable-print-area");
22613
+ for (const [name3, key2] of [
22614
+ ["ScaleX", "printZoom"],
22615
+ ["ScaleY", "printZoomY"],
22616
+ ["PagesX", "printPagesAcross"],
22617
+ ["PagesY", "printPagesDown"]
22618
+ ]) {
22619
+ const value3 = values.get(name3);
22620
+ if (value3 !== void 0) {
22621
+ if ((name3 === "PagesX" || name3 === "PagesY") && (!Number.isSafeInteger(value3) || value3 < 1))
22622
+ refuse4(local.has(name3) ? "invalid-local-setting" : "invalid-document-setting");
22623
+ else setup[key2] = value3;
22624
+ }
22625
+ }
22626
+ for (const [name3, key2] of [
22627
+ ["OnPage", "printFitToPages"],
22628
+ ["CenterX", "printCenterX"],
22629
+ ["CenterY", "printCenterY"]
22630
+ ]) {
22631
+ const value3 = values.get(name3);
22632
+ if (value3 !== void 0) setup[key2] = value3 === 1;
22633
+ }
22634
+ if (refusal) setup.printCountRefusal = refusal;
22635
+ return setup;
22636
+ }
22637
+
22638
+ // visio/theme.ts
22639
+ var VISIO_SCHEME_SLOTS = [
22640
+ "dk1",
22641
+ "lt1",
22642
+ "accent1",
22643
+ "accent2",
22644
+ "accent3",
22645
+ "accent4",
22646
+ "accent5",
22647
+ "accent6"
22648
+ ];
22649
+ var componentId = (node3) => integer3(themeChild(node3, "schemeID", THEME_NS)?.getAttribute("schemeEnum"));
22650
+ async function loadVisioThemes(pkg, source, report) {
22651
+ const result2 = [];
22652
+ for (const rel of (await pkg.relationships(source)).values()) {
22653
+ if (rel.type !== "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" || rel.mode === "External")
22654
+ continue;
22655
+ const root2 = await pkg.readXml(rel.target, "theme");
22656
+ if (root2.namespaceURI !== DRAWING_NS) {
22657
+ report("unsupported-theme", "A theme uses an unsupported XML namespace.", {
22658
+ part: rel.target
22659
+ });
22660
+ continue;
22661
+ }
22662
+ const base2 = themeChild(root2, "themeElements");
22663
+ const palette = themeChild(base2, "clrScheme");
22664
+ const scheme = parseTheme(root2).colorScheme.colors;
22665
+ const colors = /* @__PURE__ */ new Map();
22666
+ for (const name4 of VISIO_SCHEME_SLOTS) {
22667
+ const color2 = scheme[name4];
22668
+ if (color2 && parsedColorChoice(themeChild(palette, name4))) colors.set(name4, color2);
22669
+ }
22670
+ const background2 = parsedColorChoice(extension(palette, "bkgnd"));
22671
+ if (background2) colors.set("bkgnd", background2);
22672
+ const variants = themeChildren(
22673
+ extension(palette, "variationClrSchemeLst"),
22674
+ "variationClrScheme",
22675
+ THEME_NS
22676
+ ).slice(0, 4).map((variant) => {
22677
+ const entries = /* @__PURE__ */ new Map();
22678
+ for (let index2 = 1; index2 <= 7; index2++) {
22679
+ const choice2 = parsedColorChoice(themeChild(variant, `varColor${index2}`, THEME_NS));
22680
+ if (choice2) entries.set(String(index2), choice2);
22681
+ }
22682
+ return entries;
22683
+ });
22684
+ const format5 = themeChild(base2, "fmtScheme");
22685
+ const connector2 = extension(base2, "fmtConnectorScheme");
22686
+ const fonts = extension(base2, "fontStylesGroup");
22687
+ const name3 = root2.getAttribute("name");
22688
+ result2.push({
22689
+ ...name3 ? { name: name3.slice(0, 256) } : {},
22690
+ colorId: integer3(extension(palette, "schemeID")?.getAttribute("schemeEnum")),
22691
+ effectId: componentId(extension(base2, "fmtSchemeEx")),
22692
+ connectorId: componentId(extension(base2, "fmtConnectorSchemeEx")),
22693
+ colors,
22694
+ variants,
22695
+ variationStyles: themeChildren(
22696
+ extension(base2, "variationStyleSchemeLst"),
22697
+ "variationStyleScheme",
22698
+ THEME_NS
22699
+ ).slice(0, 4).map((variant) => themeChildren(variant, "varStyle", THEME_NS).slice(0, 4)),
22700
+ fills: formatList(format5, "fillStyleLst"),
22701
+ effects: themeChildren(themeChild(format5, "effectStyleLst"), "effectStyle").slice(0, 6),
22702
+ lines: themeChildren(themeChild(format5, "lnStyleLst"), "ln").slice(0, 6),
22703
+ fonts: themeChildren(themeChild(fonts, "fontStyles", THEME_NS), "fontProps", THEME_NS).slice(
22704
+ 0,
22705
+ 6
22706
+ ),
22707
+ connectorFills: formatList(connector2, "fillStyleLst"),
22708
+ connectorEffects: themeChildren(themeChild(connector2, "effectStyleLst"), "effectStyle").slice(
22709
+ 0,
22710
+ 6
22711
+ ),
22712
+ connectorLines: themeChildren(themeChild(connector2, "lnStyleLst"), "ln").slice(0, 6),
22713
+ connectorFonts: themeChildren(
22714
+ themeChild(fonts, "connectorFontStyles", THEME_NS),
22715
+ "fontProps",
22716
+ THEME_NS
22717
+ ).slice(0, 6)
22718
+ });
22719
+ }
22720
+ return result2;
22721
+ }
22722
+ function formatList(parent, name3) {
22723
+ const list2 = themeChild(parent, name3);
22724
+ return list2 ? Array.from(list2.childNodes).filter(
22725
+ (node3) => node3.nodeType === 1 && node3.namespaceURI === DRAWING_NS
22726
+ ).slice(0, 6) : [];
22727
+ }
22728
+
22729
+ // visio/document-level.ts
22730
+ function optionsKey(options2) {
22731
+ const { metafileConverter: _converter, pages: _pages, documentCache: _cache, ...rest } = options2;
22732
+ return JSON.stringify(rest);
22733
+ }
22734
+ 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);
22735
+ async function readDocumentLevel(pkg, documentPart2, options2, checkTime, forward) {
22736
+ const reports = [];
22737
+ const report = (...args) => {
22738
+ reports.push(args);
22739
+ forward(...args);
22740
+ };
22741
+ const documentRoot = await visioXml(pkg, documentPart2, "VisioDocument");
22742
+ const resources = {
22743
+ colors: /* @__PURE__ */ new Map(),
22744
+ fonts: /* @__PURE__ */ new Map(),
22745
+ themes: await loadVisioThemes(pkg, documentPart2, report)
22746
+ };
22747
+ for (const color2 of children2(child(documentRoot, "Colors"), "ColorEntry"))
22748
+ resources.colors.set(attribute2(color2, "IX") ?? "", attribute2(color2, "RGB") ?? "");
22749
+ const faceNames = children2(child(documentRoot, "FaceNames"), "FaceName");
22750
+ if (faceNames.length > 1e4)
22751
+ throw new VisioPackageError(
22752
+ "METADATA_LIMIT",
22753
+ "Document font count exceeds its metadata limit."
22754
+ );
22755
+ let fontCharacters = 0;
22756
+ faceNames.forEach((font, index2) => {
22757
+ checkTime();
22758
+ fontCharacters += (attribute2(font, "Name") ?? attribute2(font, "NameU") ?? "Arial").length;
22759
+ if (fontCharacters > 1e6)
22760
+ throw new VisioPackageError(
22761
+ "METADATA_LIMIT",
22762
+ "Document fonts exceed aggregate metadata limits."
22763
+ );
22764
+ resources.fonts.set(
22765
+ metadata(attribute2(font, "ID") ?? String(index2), 256, "Font ID"),
22766
+ metadata(attribute2(font, "Name") ?? attribute2(font, "NameU") ?? "Arial", 1024, "Font name")
22767
+ );
22768
+ });
22769
+ const styles = /* @__PURE__ */ new Map();
22770
+ for (const style2 of children2(child(documentRoot, "StyleSheets"), "StyleSheet"))
22771
+ styles.set(metadata(attribute2(style2, "ID") ?? "", 256, "Style ID"), {
22772
+ sheet: readSheet(style2),
22773
+ attributes: metadataAttributes(style2)
22774
+ });
22775
+ const rootStyle = styles.get("0");
22776
+ if (rootStyle?.attributes.get("NameU") === "No Style") resources.rootSheet = rootStyle.sheet;
22777
+ const printStyleGroups = children2(documentRoot, "StyleSheets");
22778
+ const readPrintSettings = createVisioPrintSettingsReader(
22779
+ children2(documentRoot, "DocumentSheet"),
22780
+ printStyleGroups.length === 1 ? children2(printStyleGroups[0], "StyleSheet").filter((node3) => attribute2(node3, "ID") === "0") : []
22781
+ );
22782
+ const masters = /* @__PURE__ */ new Map();
22783
+ const masterRecords = [];
22784
+ const mastersPart = await related(pkg, documentPart2, "masters", false);
22785
+ if (mastersPart) {
22786
+ for (const master2 of children2(await visioXml(pkg, mastersPart, "Masters"), "Master")) {
22787
+ const part = await indexedPart(pkg, mastersPart, master2, "master");
22788
+ const id3 = metadata(attribute2(master2, "ID") ?? "", 256, "Master ID");
22789
+ if (!id3 || masters.has(id3))
22790
+ throw new VisioPackageError("INVALID_MASTER_ID", "Master IDs must be present and unique.");
22791
+ const masterShapes2 = readShapes(await visioXml(pkg, part, "MasterContents"));
22792
+ await prepareImages(
22793
+ masterShapes2,
22794
+ pkg,
22795
+ part,
22796
+ report,
22797
+ options2.images,
22798
+ options2.metafileConverter
22799
+ );
22800
+ masters.set(id3, masterShapes2);
22801
+ masterRecords.push({ id: id3, node: master2, shapes: masterShapes2 });
22802
+ }
22803
+ }
22804
+ return { documentRoot, resources, styles, readPrintSettings, masters, masterRecords, reports };
22805
+ }
22806
+
22526
22807
  // visio/comments.ts
22527
22808
  var VISIO_COMMENTS_CONTENT_TYPE = "application/vnd.ms-visio.comments+xml";
22528
22809
  var VISIO_COMMENTS_RELATIONSHIP = "http://schemas.microsoft.com/visio/2010/relationships/comments";
@@ -22623,6 +22904,10 @@ function createMetadataBudget(options2 = {}) {
22623
22904
  if (characters > maxCharacters)
22624
22905
  throw new VisioPackageError("METADATA_LIMIT", "Shape metadata character budget exceeded.");
22625
22906
  return value3;
22907
+ },
22908
+ state: () => [rows, characters],
22909
+ restore(state) {
22910
+ [rows, characters] = state;
22626
22911
  }
22627
22912
  };
22628
22913
  }
@@ -23595,177 +23880,6 @@ function readVisioPageSetup(cells4) {
23595
23880
  return Object.keys(result2).length ? result2 : void 0;
23596
23881
  }
23597
23882
 
23598
- // visio/print-settings.ts
23599
- var NAMES = [
23600
- "PaperKind",
23601
- "PrintPageOrientation",
23602
- "PageLeftMargin",
23603
- "PageRightMargin",
23604
- "PageTopMargin",
23605
- "PageBottomMargin",
23606
- "ScaleX",
23607
- "ScaleY",
23608
- "OnPage",
23609
- "PagesX",
23610
- "PagesY",
23611
- "CenterX",
23612
- "CenterY"
23613
- ];
23614
- var BOOLEAN = /* @__PURE__ */ new Set(["OnPage", "CenterX", "CenterY"]);
23615
- var LENGTH = /* @__PURE__ */ new Set(["PageLeftMargin", "PageRightMargin", "PageTopMargin", "PageBottomMargin"]);
23616
- var CANONICAL = new Map(
23617
- [...NAMES, "PageWidth", "PageHeight", "PageScale", "DrawingScale"].map((name3) => [
23618
- name3.toLowerCase(),
23619
- name3
23620
- ])
23621
- );
23622
- function indexCells2(sheet) {
23623
- const cells4 = /* @__PURE__ */ new Map();
23624
- let duplicate = false;
23625
- for (const node3 of children2(sheet, "Cell")) {
23626
- const name3 = attribute2(node3, "N") ?? "", canonical2 = CANONICAL.get(name3.toLowerCase());
23627
- if (!canonical2) continue;
23628
- if (canonical2 !== name3) duplicate = true;
23629
- const values = cells4.get(canonical2) ?? [];
23630
- if (values.length < 2) values.push(node3);
23631
- cells4.set(canonical2, values);
23632
- if (values.length > 1) duplicate = true;
23633
- }
23634
- return { cells: cells4, duplicate };
23635
- }
23636
- function createVisioPrintSettingsReader(documentSheets, rootStyles) {
23637
- const indexes = { document: indexCells2(documentSheets[0]), root: indexCells2(rootStyles[0]) };
23638
- return (pageSheets) => readVisioPrintCountSettings(pageSheets, documentSheets, rootStyles, indexes);
23639
- }
23640
- function readVisioPrintCountSettings(pageSheets, documentSheets, rootStyles, indexes) {
23641
- let refusal;
23642
- const refuse4 = (reason) => {
23643
- refusal ??= reason;
23644
- };
23645
- if (pageSheets.length !== 1) refuse4("ambiguous-page-sheet");
23646
- if (documentSheets.length > 1) refuse4("ambiguous-document-sheet");
23647
- if (!documentSheets.length) refuse4("missing-setting");
23648
- if (rootStyles.length > 1) refuse4("duplicate-setting");
23649
- const root2 = rootStyles[0];
23650
- if (!root2 || attribute2(root2, "ID") !== "0" || attribute2(root2, "NameU") !== "No Style")
23651
- refuse4("unsupported-print-style");
23652
- for (const sheet of [...pageSheets, ...documentSheets])
23653
- for (const name3 of ["LineStyle", "FillStyle", "TextStyle"])
23654
- if (attribute2(sheet, name3) !== "0") refuse4("unsupported-print-style");
23655
- for (const name3 of ["LineStyle", "FillStyle", "TextStyle"])
23656
- if (attribute2(root2, name3) !== void 0) refuse4("unsupported-print-style");
23657
- const localIndex = indexCells2(pageSheets[0]), rootIndex = indexes?.root ?? indexCells2(root2);
23658
- const documentIndex = indexes?.document ?? indexCells2(documentSheets[0]);
23659
- if (localIndex.duplicate || rootIndex.duplicate || documentIndex.duplicate)
23660
- refuse4("duplicate-setting");
23661
- const local = localIndex.cells, inherited = rootIndex.cells;
23662
- const read = (node3, name3, origin) => {
23663
- const invalid4 = () => {
23664
- refuse4(origin === "local" ? "invalid-local-setting" : "invalid-document-setting");
23665
- return void 0;
23666
- };
23667
- if (node3.hasAttribute("E")) return invalid4();
23668
- let raw = (attribute2(node3, "V") ?? "").trim();
23669
- if (!raw || raw.length > 128) return invalid4();
23670
- if (BOOLEAN.has(name3)) {
23671
- if (!["0", "1", "false", "true"].includes(raw)) return invalid4();
23672
- raw = raw === "true" ? "1" : raw === "false" ? "0" : raw;
23673
- }
23674
- try {
23675
- const value3 = visioFormulaCachedValue(raw, attribute2(node3, "U"));
23676
- const length = LENGTH.has(name3) || /^(PageWidth|PageHeight|PageScale|DrawingScale)$/.test(name3);
23677
- if (!["scalar", ...length ? ["length"] : []].includes(value3.unit) || Math.abs(value3.value) > 1e9)
23678
- return invalid4();
23679
- const formula = attribute2(node3, "F");
23680
- if (formula !== void 0) {
23681
- const source = formula.trim();
23682
- if (/^(true|false)$/i.test(source)) {
23683
- if ((source.toLowerCase() === "true" ? 1 : 0) !== value3.value) return invalid4();
23684
- } else {
23685
- if (!source || source === "Inh") return invalid4();
23686
- const limits = { maxLength: 512, maxNodes: 64, maxDepth: 16, maxSteps: 128 };
23687
- const analysis = analyzeVisioFormula(source, limits);
23688
- if (analysis.dynamic || analysis.guarded || analysis.references.length || analysis.unsupportedFunctions.length) {
23689
- refuse4("dynamic-setting");
23690
- return void 0;
23691
- }
23692
- const evaluated = evaluateVisioFormula(
23693
- source,
23694
- () => {
23695
- throw new Error("Unexpected reference");
23696
- },
23697
- limits
23698
- );
23699
- if (evaluated.value !== value3.value || !["scalar", ...length ? ["length"] : []].includes(evaluated.unit))
23700
- return invalid4();
23701
- }
23702
- }
23703
- return value3.value;
23704
- } catch {
23705
- return invalid4();
23706
- }
23707
- };
23708
- const values = /* @__PURE__ */ new Map();
23709
- for (const name3 of NAMES) {
23710
- const nodes = local.get(name3) ?? inherited.get(name3);
23711
- if (!nodes?.length) continue;
23712
- if (nodes.length !== 1) continue;
23713
- const value3 = read(nodes[0], name3, local.has(name3) ? "local" : "document");
23714
- if (value3 !== void 0) values.set(name3, value3);
23715
- }
23716
- for (const name3 of ["PageWidth", "PageHeight", "PageScale", "DrawingScale"]) {
23717
- const nodes = local.get(name3);
23718
- if (!nodes || nodes.length !== 1 || !(read(nodes[0], name3, "local") > 0))
23719
- refuse4("unusable-drawing-scale");
23720
- }
23721
- const setup = {};
23722
- const paper = values.get("PaperKind");
23723
- if (paper !== void 0 && Number.isSafeInteger(paper) && paper >= 0 && paper <= 65535)
23724
- setup.paperKind = paper;
23725
- else if (paper !== void 0)
23726
- refuse4(local.has("PaperKind") ? "invalid-local-setting" : "invalid-document-setting");
23727
- const orientation = values.get("PrintPageOrientation");
23728
- if (orientation === 0 || orientation === 1 || orientation === 2)
23729
- setup.printPageOrientation = orientation;
23730
- else if (orientation !== void 0)
23731
- refuse4(
23732
- local.has("PrintPageOrientation") ? "invalid-local-setting" : "invalid-document-setting"
23733
- );
23734
- const margins = ["Left", "Right", "Top", "Bottom"].map((side2) => values.get(`Page${side2}Margin`));
23735
- if (margins.every((n) => n !== void 0 && n >= 0 && n <= 1e3))
23736
- setup.margins = {
23737
- left: margins[0],
23738
- right: margins[1],
23739
- top: margins[2],
23740
- bottom: margins[3]
23741
- };
23742
- else if (margins.some((n) => n !== void 0 && (n < 0 || n > 1e3)))
23743
- refuse4("unusable-print-area");
23744
- for (const [name3, key2] of [
23745
- ["ScaleX", "printZoom"],
23746
- ["ScaleY", "printZoomY"],
23747
- ["PagesX", "printPagesAcross"],
23748
- ["PagesY", "printPagesDown"]
23749
- ]) {
23750
- const value3 = values.get(name3);
23751
- if (value3 !== void 0) {
23752
- if ((name3 === "PagesX" || name3 === "PagesY") && (!Number.isSafeInteger(value3) || value3 < 1))
23753
- refuse4(local.has(name3) ? "invalid-local-setting" : "invalid-document-setting");
23754
- else setup[key2] = value3;
23755
- }
23756
- }
23757
- for (const [name3, key2] of [
23758
- ["OnPage", "printFitToPages"],
23759
- ["CenterX", "printCenterX"],
23760
- ["CenterY", "printCenterY"]
23761
- ]) {
23762
- const value3 = values.get(name3);
23763
- if (value3 !== void 0) setup[key2] = value3 === 1;
23764
- }
23765
- if (refusal) setup.printCountRefusal = refusal;
23766
- return setup;
23767
- }
23768
-
23769
23883
  // visio/page-layout.ts
23770
23884
  var VISIO_GRID_DENSITIES = Object.freeze([0, 2, 4, 8]);
23771
23885
  var VISIO_RULER_DENSITIES = Object.freeze([8, 16, 32]);
@@ -24085,69 +24199,18 @@ async function parseVsdx(input, options2 = {}) {
24085
24199
  );
24086
24200
  }
24087
24201
  }
24088
- const documentRoot = await visioXml(pkg, documentPart2, "VisioDocument");
24089
- const resources = {
24090
- colors: /* @__PURE__ */ new Map(),
24091
- fonts: /* @__PURE__ */ new Map(),
24092
- themes: await loadVisioThemes(pkg, documentPart2, report)
24093
- };
24094
- for (const color2 of children2(child(documentRoot, "Colors"), "ColorEntry"))
24095
- resources.colors.set(attribute2(color2, "IX") ?? "", attribute2(color2, "RGB") ?? "");
24096
- const faceNames = children2(child(documentRoot, "FaceNames"), "FaceName");
24097
- if (faceNames.length > 1e4)
24098
- throw new VisioPackageError(
24099
- "METADATA_LIMIT",
24100
- "Document font count exceeds its metadata limit."
24101
- );
24102
- let fontCharacters = 0;
24103
- faceNames.forEach((font, index2) => {
24104
- checkTime();
24105
- fontCharacters += (attribute2(font, "Name") ?? attribute2(font, "NameU") ?? "Arial").length;
24106
- if (fontCharacters > 1e6)
24107
- throw new VisioPackageError(
24108
- "METADATA_LIMIT",
24109
- "Document fonts exceed aggregate metadata limits."
24110
- );
24111
- resources.fonts.set(
24112
- metadata(attribute2(font, "ID") ?? String(index2), 256, "Font ID"),
24113
- metadata(attribute2(font, "Name") ?? attribute2(font, "NameU") ?? "Arial", 1024, "Font name")
24114
- );
24115
- });
24116
- const styles = /* @__PURE__ */ new Map();
24117
- for (const style2 of children2(child(documentRoot, "StyleSheets"), "StyleSheet"))
24118
- styles.set(metadata(attribute2(style2, "ID") ?? "", 256, "Style ID"), {
24119
- sheet: readSheet(style2),
24120
- attributes: metadataAttributes(style2)
24121
- });
24122
- const rootStyle = styles.get("0");
24123
- if (rootStyle?.attributes.get("NameU") === "No Style") resources.rootSheet = rootStyle.sheet;
24124
- const printStyleGroups = children2(documentRoot, "StyleSheets");
24125
- const readPrintSettings = createVisioPrintSettingsReader(
24126
- children2(documentRoot, "DocumentSheet"),
24127
- printStyleGroups.length === 1 ? children2(printStyleGroups[0], "StyleSheet").filter((node3) => attribute2(node3, "ID") === "0") : []
24128
- );
24129
- const masters = /* @__PURE__ */ new Map();
24130
- const masterRecords = [];
24131
- const mastersPart = await related(pkg, documentPart2, "masters", false);
24132
- if (mastersPart) {
24133
- for (const master2 of children2(await visioXml(pkg, mastersPart, "Masters"), "Master")) {
24134
- const part = await indexedPart(pkg, mastersPart, master2, "master");
24135
- const id3 = metadata(attribute2(master2, "ID") ?? "", 256, "Master ID");
24136
- if (!id3 || masters.has(id3))
24137
- throw new VisioPackageError("INVALID_MASTER_ID", "Master IDs must be present and unique.");
24138
- const masterShapes2 = readShapes(await visioXml(pkg, part, "MasterContents"));
24139
- await prepareImages(
24140
- masterShapes2,
24141
- pkg,
24142
- part,
24143
- report,
24144
- options2.images,
24145
- options2.metafileConverter
24146
- );
24147
- masters.set(id3, masterShapes2);
24148
- masterRecords.push({ id: id3, node: master2, shapes: masterShapes2 });
24149
- }
24150
- }
24202
+ const cache2 = options2.documentCache;
24203
+ const cached5 = cacheMatches(cache2?.entry, pkg, options2) ? cache2.entry : void 0;
24204
+ const stopRecording = cache2 && !cached5 ? pkg.record() : void 0;
24205
+ let level2;
24206
+ if (cached5) {
24207
+ level2 = cached5.level;
24208
+ for (const args of level2.reports) report(...args);
24209
+ } else level2 = await readDocumentLevel(pkg, documentPart2, options2, checkTime, report);
24210
+ const { documentRoot, styles, readPrintSettings, masters, masterRecords } = level2;
24211
+ const resources = { ...level2.resources };
24212
+ delete resources.pageCells;
24213
+ delete resources.fieldContext;
24151
24214
  let geometryCount = 0, textCount = 0, expansionCount = 0, textRuns = 0, paragraphCount = 0;
24152
24215
  const context = {
24153
24216
  metadataBudget: createMetadataBudget(options2.metadata),
@@ -24201,15 +24264,52 @@ async function parseVsdx(input, options2 = {}) {
24201
24264
  throw new VisioPackageError("TEXT_LIMIT", "Text character limit exceeded.");
24202
24265
  }
24203
24266
  };
24204
- const documentMasters = listVisioMasters(masterRecords, context, {
24205
- metadataBudget: createMetadataBudget(options2.metadata),
24206
- layerBudget: createLayerBudget()
24207
- });
24267
+ let documentMasters;
24268
+ if (cached5) {
24269
+ const { counters } = cached5.listed;
24270
+ curveWork = counters.curveWork;
24271
+ geometryCount = counters.geometry;
24272
+ textCount = counters.text;
24273
+ expansionCount = counters.expansion;
24274
+ textRuns = counters.textRuns;
24275
+ paragraphCount = counters.paragraphs;
24276
+ context.shapeCount = counters.shapes;
24277
+ context.metadataBudget.restore(counters.metadata);
24278
+ context.layerBudget.restore(counters.layers);
24279
+ documentMasters = cached5.listed.documentMasters;
24280
+ } else {
24281
+ documentMasters = listVisioMasters(masterRecords, context, {
24282
+ metadataBudget: createMetadataBudget(options2.metadata),
24283
+ layerBudget: createLayerBudget()
24284
+ });
24285
+ if (cache2 && stopRecording)
24286
+ cache2.entry = {
24287
+ options: optionsKey(options2),
24288
+ converter: options2.metafileConverter,
24289
+ reads: stopRecording(),
24290
+ level: { ...level2, resources: { ...resources } },
24291
+ listed: {
24292
+ documentMasters,
24293
+ counters: {
24294
+ curveWork,
24295
+ geometry: geometryCount,
24296
+ text: textCount,
24297
+ expansion: expansionCount,
24298
+ textRuns,
24299
+ paragraphs: paragraphCount,
24300
+ shapes: context.shapeCount,
24301
+ metadata: context.metadataBudget.state(),
24302
+ layers: context.layerBudget.state()
24303
+ }
24304
+ }
24305
+ };
24306
+ }
24208
24307
  const pagesPart = await related(pkg, documentPart2, "pages", !options2.stencil);
24209
24308
  if (!pagesPart && !options2.stencil)
24210
24309
  throw new VisioPackageError("INVALID_DOCUMENT", "Missing Visio pages part.");
24211
24310
  const pages = [], pageIds2 = /* @__PURE__ */ new Set();
24212
24311
  const comments = [];
24312
+ const only = options2.pages ? new Set(options2.pages) : void 0;
24213
24313
  const pageNodes = pagesPart ? children2(await visioXml(pkg, pagesPart, "Pages"), "Page") : [];
24214
24314
  const foreground = pageNodes.filter((page) => !yes(attribute2(page, "Background")));
24215
24315
  const fieldProperties = await readVisioFieldProperties(pkg);
@@ -24219,6 +24319,7 @@ async function parseVsdx(input, options2 = {}) {
24219
24319
  if (!id3 || pageIds2.has(id3))
24220
24320
  throw new VisioPackageError("INVALID_PAGE_ID", "Page IDs must be present and unique.");
24221
24321
  pageIds2.add(id3);
24322
+ if (only && !only.has(id3)) continue;
24222
24323
  const part = await indexedPart(pkg, pagesPart, page, "page");
24223
24324
  const root2 = await visioXml(pkg, part, "PageContents");
24224
24325
  const localReport = (code, message, extra) => report(code, message, { part, pageId: id3, ...extra });
@@ -24328,16 +24429,16 @@ async function parseVsdx(input, options2 = {}) {
24328
24429
  });
24329
24430
  }
24330
24431
  checkTime();
24331
- validateBackgrounds(pages, report);
24432
+ if (!only) validateBackgrounds(pages, report);
24332
24433
  try {
24333
- comments.push(...await readVisioComments(pkg, documentPart2, report));
24434
+ if (!only) comments.push(...await readVisioComments(pkg, documentPart2, report));
24334
24435
  } catch (error) {
24335
24436
  if (!(error instanceof VisioPackageError) || error.code === "LIMIT_RUNTIME") throw error;
24336
24437
  report("invalid-comments", "The comments part could not be read; comments are not shown.");
24337
24438
  }
24338
24439
  let dataRecordsets = [];
24339
24440
  try {
24340
- dataRecordsets = await readDataRecordsets(pkg, documentPart2, checkTime);
24441
+ if (!only) dataRecordsets = await readDataRecordsets(pkg, documentPart2, checkTime);
24341
24442
  } catch (error) {
24342
24443
  if (error instanceof VisioPackageError && error.code === "LIMIT_RUNTIME") throw error;
24343
24444
  report(
@@ -24345,7 +24446,7 @@ async function parseVsdx(input, options2 = {}) {
24345
24446
  `Saved external data could not be read and is preserved unchanged: ${error instanceof Error ? error.message : String(error)}`
24346
24447
  );
24347
24448
  }
24348
- const stencils = await readVisioStencilWindows(pkg, documentPart2);
24449
+ const stencils = only ? [] : await readVisioStencilWindows(pkg, documentPart2);
24349
24450
  report(
24350
24451
  "cached-values-only",
24351
24452
  "ShapeSheet formulas, automatic connector routing, and external data are not evaluated; saved cached values and supported theme records are used.",
@@ -33874,6 +33975,55 @@ async function loadVisio(input, options2 = {}) {
33874
33975
  );
33875
33976
  }
33876
33977
 
33978
+ // visio/parse-incremental.ts
33979
+ var BACKGROUND_CODES = /* @__PURE__ */ new Set(["background-cycle", "missing-background-page"]);
33980
+ var MAX_SPLICED_DIAGNOSTICS = 1e3;
33981
+ var DEFAULT_MAX_SHAPES = 25e3;
33982
+ var countShapes = (shapes) => shapes.reduce((sum, shape) => sum + 1 + countShapes(shape.children), 0);
33983
+ var isPageDiagnostic = (d) => d.pageId !== void 0 && !BACKGROUND_CODES.has(d.code);
33984
+ function mergeVisioPages(previous, partial, pageIds2, options2 = {}) {
33985
+ if (previous.format !== "vsdx" || partial.format !== "vsdx") return void 0;
33986
+ const wanted = new Set(pageIds2);
33987
+ const fresh = new Map(partial.pages.map((page) => [page.id, page]));
33988
+ if (fresh.size !== wanted.size || ![...wanted].every((id3) => fresh.has(id3))) return void 0;
33989
+ const before = new Map(previous.pages.map((page) => [page.id, page]));
33990
+ if (![...wanted].every((id3) => before.has(id3))) return void 0;
33991
+ for (const [id3, page] of fresh)
33992
+ if (before.get(id3).backgroundPageId === void 0) delete page.backgroundPageId;
33993
+ const pages = previous.pages.map((page) => fresh.get(page.id) ?? page);
33994
+ if (pages.reduce((sum, page) => sum + countShapes(page.shapes), 0) > (options2.maxShapes ?? DEFAULT_MAX_SHAPES))
33995
+ return void 0;
33996
+ const diagnostics = spliceDiagnostics(previous.diagnostics, partial.diagnostics, wanted);
33997
+ if (!diagnostics) return void 0;
33998
+ return { ...previous, pages, diagnostics };
33999
+ }
34000
+ function spliceDiagnostics(previous, partial, wanted) {
34001
+ const truncated = (list2) => list2.some((d) => d.code === "diagnostics-truncated");
34002
+ if (truncated(previous) || truncated(partial)) return void 0;
34003
+ const fresh = partial.filter((d) => isPageDiagnostic(d) && wanted.has(d.pageId));
34004
+ if (previous.length + fresh.length > MAX_SPLICED_DIAGNOSTICS) return void 0;
34005
+ let out = [...previous];
34006
+ for (const id3 of wanted) {
34007
+ const next = fresh.filter((d) => d.pageId === id3);
34008
+ const at2 = out.flatMap((d, i) => isPageDiagnostic(d) && d.pageId === id3 ? [i] : []);
34009
+ if (!at2.length) {
34010
+ if (next.length) return void 0;
34011
+ continue;
34012
+ }
34013
+ const first2 = at2[0];
34014
+ const last = at2[at2.length - 1];
34015
+ if (last - first2 + 1 !== at2.length) return void 0;
34016
+ out = [...out.slice(0, first2), ...next, ...out.slice(last + 1)];
34017
+ }
34018
+ return out;
34019
+ }
34020
+ async function parseVsdxPages(input, previous, pageIds2, options2 = {}) {
34021
+ const partial = await parseVsdx(input, { ...options2, pages: pageIds2 });
34022
+ return mergeVisioPages(previous, partial, pageIds2, {
34023
+ ...options2.maxShapes !== void 0 ? { maxShapes: options2.maxShapes } : {}
34024
+ });
34025
+ }
34026
+
33877
34027
  // visio/visibility.ts
33878
34028
  var VISIO_VISIBILITY_LIMITS = Object.freeze({
33879
34029
  maxShapes: 25e3,
@@ -48802,4 +48952,4 @@ function checkVisioAlternativeText(document) {
48802
48952
  return issues;
48803
48953
  }
48804
48954
 
48805
- export { EmfBitmapError, VISIO_ARROW_SHAPES, VISIO_BACKGROUND_STYLES, VISIO_BASIC_SHAPES, VISIO_BASIC_STENCIL, VISIO_BORDER_STYLES, VISIO_BUILT_IN_STENCILS, VISIO_BUILT_IN_THEMES, VISIO_BUILT_IN_THEME_IDS, VISIO_CALLOUT_STYLES, VISIO_CHART_OBJECT_MAX_BYTES, VISIO_CLIPBOARD_MAGIC, VISIO_CLIPBOARD_MAX_CHARS, VISIO_COMMENT_AUTHOR_LIMIT, VISIO_COMMENT_LIMIT, VISIO_COMMENT_TEXT_LIMIT, VISIO_CONNECTOR_ROUTES, VISIO_CONTAINER_HEADING, VISIO_CONTAINER_MARGIN, VISIO_CONTAINER_STYLES, VISIO_DATA_LIMITS, VISIO_EMF_ADMISSION_LIMITS, VISIO_FIELD_FORMATS, VISIO_FIELD_FUNCTIONS, VISIO_FLOWCHART_SHAPES, VISIO_FOREIGN_VECTOR_LIMITS, VISIO_GLOW_SIZES, VISIO_GLOW_TRANSPARENCY, VISIO_GLUE, VISIO_GRID_DENSITIES, VISIO_LAYER_NAME_LIMIT, VISIO_LINE_JUMP_LIMITS, VISIO_LINE_JUMP_WIDTH, VISIO_MANAGED_BACKGROUND, VISIO_METADATA_TEXT_LIMIT, VISIO_PAGE_LAYOUT_DEFAULTS, VISIO_PATH_SEGMENT_LIMIT, VISIO_PICTURE_MAX_BYTES, VISIO_PRINT_COUNT_LIMITS, VISIO_QUICK_STYLE_COLORS, VISIO_QUICK_STYLE_VARIANT_COLORS, VISIO_RASTER_IMAGE_LIMITS, VISIO_REFLECTION_PRESETS, VISIO_RULER_DENSITIES, VISIO_SCALE_UNITS, VISIO_SHADOW_PRESETS, VISIO_SHAPE_DATA_TYPES, VISIO_SNAP, VISIO_SNAP_GLUE_DEFAULTS, VISIO_SOFT_EDGE_SIZES, VISIO_STENCILS, VISIO_STENCIL_FILES, VISIO_TEXT_CASES, VISIO_TEXT_POSITIONS, VISIO_THEME_COLOR_SLOTS, VISIO_UNTHEMED_COLORS, VISIO_VISIBILITY_LIMITS, VisioForeignVectorError, VisioFormulaError, VisioImageError, VisioPackageError, analyzeVisioFormula, canonicalShapeDataValue, captureVisioClipboard, checkVisioAlternativeText, convertVisioMetafile, createVsdx, deserializeVisioClipboard, designTextMeasurer, editVsdx, encodeBitmapEmf, evaluateVisioFormula, evaluateVisioTextField, formatVisioFieldValue, getVisioPageLayers, inspectVisioEmfAdmission, inspectVisioRasterImage, isVisioBasicShape, isVisioBuiltInThemeId, isVisioChangeShapeTarget, isVisioDiagramPartEdit, isVisioLayerName, isVisioOutlineShape, isVisioQuickStyleColor, isVisioShadowPreset, isVisioStencilShape, isVisioThemeColorRef, layoutVisioFilledArrowLine, loadVisio, parseLegacyVsd, parseVisioFormula, parseVisioThemeColorFormula, parseVsdx, readVisioStencil, resolveVisioPageVisibility, resolveVisioThemeColor, sanitizeVisioForeignVectorTree, serializeVisioClipboard, setVisioTextMeasurer, trimVisioArrowLine, validateVisioForeignVector, visioBackgroundShapes, visioBasicShapeOutline, visioBorderShapes, visioBuiltInMaster, visioBuiltInStencil, visioBuiltInTheme, visioCircleThrough, visioCurvedRoute, visioDecorationName, visioFallbackQuickStyle, visioFilledArrow, visioFitFreeform, visioFitPencil, visioFontAssumed, visioFormulaCachedValue, visioLineJumpPaths, visioLinkedRowNames, visioOpenArrowExtent, visioOpenArrowPath, visioOrthogonalRoute, visioOutlineShape, visioPageLayout, visioPageThemeColors, visioPathBounds, visioPathSamples, visioPrintTileCount, visioQuarterArc, visioShade, visioShadowPresetGeometry, visioShapeDataRowName, visioShapeStructure, visioSimplifyPath, visioSnapGlue, visioStencilMaster, visioStencilShapeOutline, visioTextExtents, visioThemeColorFormula, visioThemeVariantColors, visioThemeXml };
48955
+ export { EmfBitmapError, VISIO_ARROW_SHAPES, VISIO_BACKGROUND_STYLES, VISIO_BASIC_SHAPES, VISIO_BASIC_STENCIL, VISIO_BORDER_STYLES, VISIO_BUILT_IN_STENCILS, VISIO_BUILT_IN_THEMES, VISIO_BUILT_IN_THEME_IDS, VISIO_CALLOUT_STYLES, VISIO_CHART_OBJECT_MAX_BYTES, VISIO_CLIPBOARD_MAGIC, VISIO_CLIPBOARD_MAX_CHARS, VISIO_COMMENT_AUTHOR_LIMIT, VISIO_COMMENT_LIMIT, VISIO_COMMENT_TEXT_LIMIT, VISIO_CONNECTOR_ROUTES, VISIO_CONTAINER_HEADING, VISIO_CONTAINER_MARGIN, VISIO_CONTAINER_STYLES, VISIO_DATA_LIMITS, VISIO_EMF_ADMISSION_LIMITS, VISIO_FIELD_FORMATS, VISIO_FIELD_FUNCTIONS, VISIO_FLOWCHART_SHAPES, VISIO_FOREIGN_VECTOR_LIMITS, VISIO_GLOW_SIZES, VISIO_GLOW_TRANSPARENCY, VISIO_GLUE, VISIO_GRID_DENSITIES, VISIO_LAYER_NAME_LIMIT, VISIO_LINE_JUMP_LIMITS, VISIO_LINE_JUMP_WIDTH, VISIO_MANAGED_BACKGROUND, VISIO_METADATA_TEXT_LIMIT, VISIO_PAGE_LAYOUT_DEFAULTS, VISIO_PATH_SEGMENT_LIMIT, VISIO_PICTURE_MAX_BYTES, VISIO_PRINT_COUNT_LIMITS, VISIO_QUICK_STYLE_COLORS, VISIO_QUICK_STYLE_VARIANT_COLORS, VISIO_RASTER_IMAGE_LIMITS, VISIO_REFLECTION_PRESETS, VISIO_RULER_DENSITIES, VISIO_SCALE_UNITS, VISIO_SHADOW_PRESETS, VISIO_SHAPE_DATA_TYPES, VISIO_SNAP, VISIO_SNAP_GLUE_DEFAULTS, VISIO_SOFT_EDGE_SIZES, VISIO_STENCILS, VISIO_STENCIL_FILES, VISIO_TEXT_CASES, VISIO_TEXT_POSITIONS, VISIO_THEME_COLOR_SLOTS, VISIO_UNTHEMED_COLORS, VISIO_VISIBILITY_LIMITS, VisioForeignVectorError, VisioFormulaError, VisioImageError, VisioPackageError, analyzeVisioFormula, canonicalShapeDataValue, captureVisioClipboard, checkVisioAlternativeText, convertVisioMetafile, createVsdx, deserializeVisioClipboard, designTextMeasurer, editVsdx, encodeBitmapEmf, evaluateVisioFormula, evaluateVisioTextField, formatVisioFieldValue, getVisioPageLayers, inspectVisioEmfAdmission, inspectVisioRasterImage, isVisioBasicShape, isVisioBuiltInThemeId, isVisioChangeShapeTarget, isVisioDiagramPartEdit, isVisioLayerName, isVisioOutlineShape, isVisioQuickStyleColor, isVisioShadowPreset, isVisioStencilShape, isVisioThemeColorRef, layoutVisioFilledArrowLine, loadVisio, mergeVisioPages, parseLegacyVsd, parseVisioFormula, parseVisioThemeColorFormula, parseVsdx, parseVsdxPages, readVisioStencil, resolveVisioPageVisibility, resolveVisioThemeColor, sanitizeVisioForeignVectorTree, serializeVisioClipboard, setVisioTextMeasurer, trimVisioArrowLine, validateVisioForeignVector, visioBackgroundShapes, visioBasicShapeOutline, visioBorderShapes, visioBuiltInMaster, visioBuiltInStencil, visioBuiltInTheme, visioCircleThrough, visioCurvedRoute, visioDecorationName, visioFallbackQuickStyle, visioFilledArrow, visioFitFreeform, visioFitPencil, visioFontAssumed, visioFormulaCachedValue, visioLineJumpPaths, visioLinkedRowNames, visioOpenArrowExtent, visioOpenArrowPath, visioOrthogonalRoute, visioOutlineShape, visioPageLayout, visioPageThemeColors, visioPathBounds, visioPathSamples, visioPrintTileCount, visioQuarterArc, visioShade, visioShadowPresetGeometry, visioShapeDataRowName, visioShapeStructure, visioSimplifyPath, visioSnapGlue, visioStencilMaster, visioStencilShapeOutline, visioTextExtents, visioThemeColorFormula, visioThemeVariantColors, visioThemeXml };