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
@@ -740,6 +740,7 @@ var VisioPackage = class _VisioPackage {
740
740
  relationshipCache = /* @__PURE__ */ new Map();
741
741
  byteCache = /* @__PURE__ */ new Map();
742
742
  decodedNames = /* @__PURE__ */ new Map();
743
+ noted;
743
744
  totalOutput = 0;
744
745
  totalXmlNodes = 0;
745
746
  check = () => {
@@ -774,7 +775,26 @@ var VisioPackage = class _VisioPackage {
774
775
  );
775
776
  }
776
777
  }
778
+ /**
779
+ * Starts noting every part this package is asked about (read, listed in a relationship, or
780
+ * checked for). The returned function stops noting and gives each part with a print of its
781
+ * declared CRC-32 and size (empty when absent), which is what {@link printOf} compares.
782
+ */
783
+ record() {
784
+ const noted = /* @__PURE__ */ new Set();
785
+ this.noted = noted;
786
+ return () => {
787
+ if (this.noted === noted) this.noted = void 0;
788
+ return [...noted].sort().map((path2) => [path2, this.printOf(path2)]);
789
+ };
790
+ }
791
+ /** The declared CRC-32 and size of a part, or an empty string when the package lacks it. */
792
+ printOf(path2) {
793
+ const entry3 = this.entries.get(path2);
794
+ return entry3 && !entry3.directory ? `${entry3.crc}:${entry3.size}` : "";
795
+ }
777
796
  has(path2) {
797
+ this.noted?.add(path2);
778
798
  return this.entries.get(path2)?.directory === false;
779
799
  }
780
800
  paths() {
@@ -782,6 +802,7 @@ var VisioPackage = class _VisioPackage {
782
802
  }
783
803
  async readXml(path2, expectedRoot) {
784
804
  this.check();
805
+ this.noted?.add(path2);
785
806
  safePath(path2);
786
807
  let pending2 = this.cache.get(path2);
787
808
  if (!pending2) {
@@ -797,6 +818,7 @@ var VisioPackage = class _VisioPackage {
797
818
  /** Validated declared size, so resource-specific limits can reject before inflation. */
798
819
  getPartByteLength(path2) {
799
820
  this.check();
821
+ this.noted?.add(path2);
800
822
  safePath(path2);
801
823
  const entry3 = this.entries.get(path2);
802
824
  if (!entry3 || entry3.directory) fail("MISSING_PART", `Missing package part: ${path2}`);
@@ -805,6 +827,7 @@ var VisioPackage = class _VisioPackage {
805
827
  /** Shared package-owned bytes. Treat the returned buffer as immutable. */
806
828
  async readBytes(path2) {
807
829
  this.check();
830
+ this.noted?.add(path2);
808
831
  safePath(path2);
809
832
  let pending2 = this.byteCache.get(path2);
810
833
  if (!pending2) {
@@ -898,6 +921,10 @@ var VisioPackage = class _VisioPackage {
898
921
  }
899
922
  async relationships(sourcePart) {
900
923
  this.check();
924
+ if (this.noted && sourcePart) {
925
+ const slash = sourcePart.lastIndexOf("/");
926
+ this.noted.add(`${sourcePart.slice(0, slash + 1)}_rels/${sourcePart.slice(slash + 1)}.rels`);
927
+ } else this.noted?.add("_rels/.rels");
901
928
  let pending2 = this.relationshipCache.get(sourcePart);
902
929
  if (!pending2) {
903
930
  pending2 = this.loadRelationships(sourcePart);
@@ -931,6 +958,7 @@ var VisioPackage = class _VisioPackage {
931
958
  const actual = mode === "Internal" ? this.decodedNames.get(resolved) : void 0;
932
959
  if (mode === "Internal" && !actual)
933
960
  fail("INVALID_RELATIONSHIP", `Missing relationship target: ${resolved}`);
961
+ if (actual) this.noted?.add(actual);
934
962
  result2.set(id3, { id: id3, type, target: actual ?? resolved, mode });
935
963
  }
936
964
  return result2;
@@ -22204,6 +22232,10 @@ function createLayerBudget() {
22204
22232
  memberships += count;
22205
22233
  if (memberships > 1e5)
22206
22234
  throw new VisioPackageError("METADATA_LIMIT", "Layer membership budget exceeded.");
22235
+ },
22236
+ state: () => [memberships, characters],
22237
+ restore(state) {
22238
+ [memberships, characters] = state;
22207
22239
  }
22208
22240
  };
22209
22241
  }
@@ -22275,97 +22307,6 @@ function shapeLayers(sheet, layers, report, budget = createLayerBudget()) {
22275
22307
  };
22276
22308
  }
22277
22309
 
22278
- // visio/theme.ts
22279
- var VISIO_SCHEME_SLOTS = [
22280
- "dk1",
22281
- "lt1",
22282
- "accent1",
22283
- "accent2",
22284
- "accent3",
22285
- "accent4",
22286
- "accent5",
22287
- "accent6"
22288
- ];
22289
- var componentId = (node3) => integer3(themeChild(node3, "schemeID", THEME_NS)?.getAttribute("schemeEnum"));
22290
- async function loadVisioThemes(pkg, source, report) {
22291
- const result2 = [];
22292
- for (const rel of (await pkg.relationships(source)).values()) {
22293
- if (rel.type !== "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" || rel.mode === "External")
22294
- continue;
22295
- const root2 = await pkg.readXml(rel.target, "theme");
22296
- if (root2.namespaceURI !== DRAWING_NS) {
22297
- report("unsupported-theme", "A theme uses an unsupported XML namespace.", {
22298
- part: rel.target
22299
- });
22300
- continue;
22301
- }
22302
- const base2 = themeChild(root2, "themeElements");
22303
- const palette = themeChild(base2, "clrScheme");
22304
- const scheme = parseTheme(root2).colorScheme.colors;
22305
- const colors = /* @__PURE__ */ new Map();
22306
- for (const name4 of VISIO_SCHEME_SLOTS) {
22307
- const color2 = scheme[name4];
22308
- if (color2 && parsedColorChoice(themeChild(palette, name4))) colors.set(name4, color2);
22309
- }
22310
- const background2 = parsedColorChoice(extension(palette, "bkgnd"));
22311
- if (background2) colors.set("bkgnd", background2);
22312
- const variants = themeChildren(
22313
- extension(palette, "variationClrSchemeLst"),
22314
- "variationClrScheme",
22315
- THEME_NS
22316
- ).slice(0, 4).map((variant) => {
22317
- const entries = /* @__PURE__ */ new Map();
22318
- for (let index2 = 1; index2 <= 7; index2++) {
22319
- const choice2 = parsedColorChoice(themeChild(variant, `varColor${index2}`, THEME_NS));
22320
- if (choice2) entries.set(String(index2), choice2);
22321
- }
22322
- return entries;
22323
- });
22324
- const format5 = themeChild(base2, "fmtScheme");
22325
- const connector2 = extension(base2, "fmtConnectorScheme");
22326
- const fonts = extension(base2, "fontStylesGroup");
22327
- const name3 = root2.getAttribute("name");
22328
- result2.push({
22329
- ...name3 ? { name: name3.slice(0, 256) } : {},
22330
- colorId: integer3(extension(palette, "schemeID")?.getAttribute("schemeEnum")),
22331
- effectId: componentId(extension(base2, "fmtSchemeEx")),
22332
- connectorId: componentId(extension(base2, "fmtConnectorSchemeEx")),
22333
- colors,
22334
- variants,
22335
- variationStyles: themeChildren(
22336
- extension(base2, "variationStyleSchemeLst"),
22337
- "variationStyleScheme",
22338
- THEME_NS
22339
- ).slice(0, 4).map((variant) => themeChildren(variant, "varStyle", THEME_NS).slice(0, 4)),
22340
- fills: formatList(format5, "fillStyleLst"),
22341
- effects: themeChildren(themeChild(format5, "effectStyleLst"), "effectStyle").slice(0, 6),
22342
- lines: themeChildren(themeChild(format5, "lnStyleLst"), "ln").slice(0, 6),
22343
- fonts: themeChildren(themeChild(fonts, "fontStyles", THEME_NS), "fontProps", THEME_NS).slice(
22344
- 0,
22345
- 6
22346
- ),
22347
- connectorFills: formatList(connector2, "fillStyleLst"),
22348
- connectorEffects: themeChildren(themeChild(connector2, "effectStyleLst"), "effectStyle").slice(
22349
- 0,
22350
- 6
22351
- ),
22352
- connectorLines: themeChildren(themeChild(connector2, "lnStyleLst"), "ln").slice(0, 6),
22353
- connectorFonts: themeChildren(
22354
- themeChild(fonts, "connectorFontStyles", THEME_NS),
22355
- "fontProps",
22356
- THEME_NS
22357
- ).slice(0, 6)
22358
- });
22359
- }
22360
- return result2;
22361
- }
22362
- function formatList(parent, name3) {
22363
- const list2 = themeChild(parent, name3);
22364
- return list2 ? Array.from(list2.childNodes).filter(
22365
- (node3) => node3.nodeType === 1 && node3.namespaceURI === DRAWING_NS
22366
- ).slice(0, 6) : [];
22367
- }
22368
-
22369
22310
  // visio/theme-builtins.ts
22370
22311
  var VISIO_BUILT_IN_THEME_IDS = [
22371
22312
  "office",
@@ -22529,6 +22470,346 @@ function diagnosticCollector(maxCount) {
22529
22470
  };
22530
22471
  }
22531
22472
 
22473
+ // visio/print-settings.ts
22474
+ var NAMES = [
22475
+ "PaperKind",
22476
+ "PrintPageOrientation",
22477
+ "PageLeftMargin",
22478
+ "PageRightMargin",
22479
+ "PageTopMargin",
22480
+ "PageBottomMargin",
22481
+ "ScaleX",
22482
+ "ScaleY",
22483
+ "OnPage",
22484
+ "PagesX",
22485
+ "PagesY",
22486
+ "CenterX",
22487
+ "CenterY"
22488
+ ];
22489
+ var BOOLEAN = /* @__PURE__ */ new Set(["OnPage", "CenterX", "CenterY"]);
22490
+ var LENGTH = /* @__PURE__ */ new Set(["PageLeftMargin", "PageRightMargin", "PageTopMargin", "PageBottomMargin"]);
22491
+ var CANONICAL = new Map(
22492
+ [...NAMES, "PageWidth", "PageHeight", "PageScale", "DrawingScale"].map((name3) => [
22493
+ name3.toLowerCase(),
22494
+ name3
22495
+ ])
22496
+ );
22497
+ function indexCells2(sheet) {
22498
+ const cells4 = /* @__PURE__ */ new Map();
22499
+ let duplicate = false;
22500
+ for (const node3 of children2(sheet, "Cell")) {
22501
+ const name3 = attribute2(node3, "N") ?? "", canonical2 = CANONICAL.get(name3.toLowerCase());
22502
+ if (!canonical2) continue;
22503
+ if (canonical2 !== name3) duplicate = true;
22504
+ const values = cells4.get(canonical2) ?? [];
22505
+ if (values.length < 2) values.push(node3);
22506
+ cells4.set(canonical2, values);
22507
+ if (values.length > 1) duplicate = true;
22508
+ }
22509
+ return { cells: cells4, duplicate };
22510
+ }
22511
+ function createVisioPrintSettingsReader(documentSheets, rootStyles) {
22512
+ const indexes = { document: indexCells2(documentSheets[0]), root: indexCells2(rootStyles[0]) };
22513
+ return (pageSheets) => readVisioPrintCountSettings(pageSheets, documentSheets, rootStyles, indexes);
22514
+ }
22515
+ function readVisioPrintCountSettings(pageSheets, documentSheets, rootStyles, indexes) {
22516
+ let refusal;
22517
+ const refuse4 = (reason) => {
22518
+ refusal ??= reason;
22519
+ };
22520
+ if (pageSheets.length !== 1) refuse4("ambiguous-page-sheet");
22521
+ if (documentSheets.length > 1) refuse4("ambiguous-document-sheet");
22522
+ if (!documentSheets.length) refuse4("missing-setting");
22523
+ if (rootStyles.length > 1) refuse4("duplicate-setting");
22524
+ const root2 = rootStyles[0];
22525
+ if (!root2 || attribute2(root2, "ID") !== "0" || attribute2(root2, "NameU") !== "No Style")
22526
+ refuse4("unsupported-print-style");
22527
+ for (const sheet of [...pageSheets, ...documentSheets])
22528
+ for (const name3 of ["LineStyle", "FillStyle", "TextStyle"])
22529
+ if (attribute2(sheet, name3) !== "0") refuse4("unsupported-print-style");
22530
+ for (const name3 of ["LineStyle", "FillStyle", "TextStyle"])
22531
+ if (attribute2(root2, name3) !== void 0) refuse4("unsupported-print-style");
22532
+ const localIndex = indexCells2(pageSheets[0]), rootIndex = indexes?.root ?? indexCells2(root2);
22533
+ const documentIndex = indexes?.document ?? indexCells2(documentSheets[0]);
22534
+ if (localIndex.duplicate || rootIndex.duplicate || documentIndex.duplicate)
22535
+ refuse4("duplicate-setting");
22536
+ const local = localIndex.cells, inherited = rootIndex.cells;
22537
+ const read = (node3, name3, origin) => {
22538
+ const invalid4 = () => {
22539
+ refuse4(origin === "local" ? "invalid-local-setting" : "invalid-document-setting");
22540
+ return void 0;
22541
+ };
22542
+ if (node3.hasAttribute("E")) return invalid4();
22543
+ let raw = (attribute2(node3, "V") ?? "").trim();
22544
+ if (!raw || raw.length > 128) return invalid4();
22545
+ if (BOOLEAN.has(name3)) {
22546
+ if (!["0", "1", "false", "true"].includes(raw)) return invalid4();
22547
+ raw = raw === "true" ? "1" : raw === "false" ? "0" : raw;
22548
+ }
22549
+ try {
22550
+ const value3 = visioFormulaCachedValue(raw, attribute2(node3, "U"));
22551
+ const length = LENGTH.has(name3) || /^(PageWidth|PageHeight|PageScale|DrawingScale)$/.test(name3);
22552
+ if (!["scalar", ...length ? ["length"] : []].includes(value3.unit) || Math.abs(value3.value) > 1e9)
22553
+ return invalid4();
22554
+ const formula = attribute2(node3, "F");
22555
+ if (formula !== void 0) {
22556
+ const source = formula.trim();
22557
+ if (/^(true|false)$/i.test(source)) {
22558
+ if ((source.toLowerCase() === "true" ? 1 : 0) !== value3.value) return invalid4();
22559
+ } else {
22560
+ if (!source || source === "Inh") return invalid4();
22561
+ const limits = { maxLength: 512, maxNodes: 64, maxDepth: 16, maxSteps: 128 };
22562
+ const analysis = analyzeVisioFormula(source, limits);
22563
+ if (analysis.dynamic || analysis.guarded || analysis.references.length || analysis.unsupportedFunctions.length) {
22564
+ refuse4("dynamic-setting");
22565
+ return void 0;
22566
+ }
22567
+ const evaluated = evaluateVisioFormula(
22568
+ source,
22569
+ () => {
22570
+ throw new Error("Unexpected reference");
22571
+ },
22572
+ limits
22573
+ );
22574
+ if (evaluated.value !== value3.value || !["scalar", ...length ? ["length"] : []].includes(evaluated.unit))
22575
+ return invalid4();
22576
+ }
22577
+ }
22578
+ return value3.value;
22579
+ } catch {
22580
+ return invalid4();
22581
+ }
22582
+ };
22583
+ const values = /* @__PURE__ */ new Map();
22584
+ for (const name3 of NAMES) {
22585
+ const nodes = local.get(name3) ?? inherited.get(name3);
22586
+ if (!nodes?.length) continue;
22587
+ if (nodes.length !== 1) continue;
22588
+ const value3 = read(nodes[0], name3, local.has(name3) ? "local" : "document");
22589
+ if (value3 !== void 0) values.set(name3, value3);
22590
+ }
22591
+ for (const name3 of ["PageWidth", "PageHeight", "PageScale", "DrawingScale"]) {
22592
+ const nodes = local.get(name3);
22593
+ if (!nodes || nodes.length !== 1 || !(read(nodes[0], name3, "local") > 0))
22594
+ refuse4("unusable-drawing-scale");
22595
+ }
22596
+ const setup = {};
22597
+ const paper = values.get("PaperKind");
22598
+ if (paper !== void 0 && Number.isSafeInteger(paper) && paper >= 0 && paper <= 65535)
22599
+ setup.paperKind = paper;
22600
+ else if (paper !== void 0)
22601
+ refuse4(local.has("PaperKind") ? "invalid-local-setting" : "invalid-document-setting");
22602
+ const orientation = values.get("PrintPageOrientation");
22603
+ if (orientation === 0 || orientation === 1 || orientation === 2)
22604
+ setup.printPageOrientation = orientation;
22605
+ else if (orientation !== void 0)
22606
+ refuse4(
22607
+ local.has("PrintPageOrientation") ? "invalid-local-setting" : "invalid-document-setting"
22608
+ );
22609
+ const margins = ["Left", "Right", "Top", "Bottom"].map((side2) => values.get(`Page${side2}Margin`));
22610
+ if (margins.every((n) => n !== void 0 && n >= 0 && n <= 1e3))
22611
+ setup.margins = {
22612
+ left: margins[0],
22613
+ right: margins[1],
22614
+ top: margins[2],
22615
+ bottom: margins[3]
22616
+ };
22617
+ else if (margins.some((n) => n !== void 0 && (n < 0 || n > 1e3)))
22618
+ refuse4("unusable-print-area");
22619
+ for (const [name3, key2] of [
22620
+ ["ScaleX", "printZoom"],
22621
+ ["ScaleY", "printZoomY"],
22622
+ ["PagesX", "printPagesAcross"],
22623
+ ["PagesY", "printPagesDown"]
22624
+ ]) {
22625
+ const value3 = values.get(name3);
22626
+ if (value3 !== void 0) {
22627
+ if ((name3 === "PagesX" || name3 === "PagesY") && (!Number.isSafeInteger(value3) || value3 < 1))
22628
+ refuse4(local.has(name3) ? "invalid-local-setting" : "invalid-document-setting");
22629
+ else setup[key2] = value3;
22630
+ }
22631
+ }
22632
+ for (const [name3, key2] of [
22633
+ ["OnPage", "printFitToPages"],
22634
+ ["CenterX", "printCenterX"],
22635
+ ["CenterY", "printCenterY"]
22636
+ ]) {
22637
+ const value3 = values.get(name3);
22638
+ if (value3 !== void 0) setup[key2] = value3 === 1;
22639
+ }
22640
+ if (refusal) setup.printCountRefusal = refusal;
22641
+ return setup;
22642
+ }
22643
+
22644
+ // visio/theme.ts
22645
+ var VISIO_SCHEME_SLOTS = [
22646
+ "dk1",
22647
+ "lt1",
22648
+ "accent1",
22649
+ "accent2",
22650
+ "accent3",
22651
+ "accent4",
22652
+ "accent5",
22653
+ "accent6"
22654
+ ];
22655
+ var componentId = (node3) => integer3(themeChild(node3, "schemeID", THEME_NS)?.getAttribute("schemeEnum"));
22656
+ async function loadVisioThemes(pkg, source, report) {
22657
+ const result2 = [];
22658
+ for (const rel of (await pkg.relationships(source)).values()) {
22659
+ if (rel.type !== "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" || rel.mode === "External")
22660
+ continue;
22661
+ const root2 = await pkg.readXml(rel.target, "theme");
22662
+ if (root2.namespaceURI !== DRAWING_NS) {
22663
+ report("unsupported-theme", "A theme uses an unsupported XML namespace.", {
22664
+ part: rel.target
22665
+ });
22666
+ continue;
22667
+ }
22668
+ const base2 = themeChild(root2, "themeElements");
22669
+ const palette = themeChild(base2, "clrScheme");
22670
+ const scheme = parseTheme(root2).colorScheme.colors;
22671
+ const colors = /* @__PURE__ */ new Map();
22672
+ for (const name4 of VISIO_SCHEME_SLOTS) {
22673
+ const color2 = scheme[name4];
22674
+ if (color2 && parsedColorChoice(themeChild(palette, name4))) colors.set(name4, color2);
22675
+ }
22676
+ const background2 = parsedColorChoice(extension(palette, "bkgnd"));
22677
+ if (background2) colors.set("bkgnd", background2);
22678
+ const variants = themeChildren(
22679
+ extension(palette, "variationClrSchemeLst"),
22680
+ "variationClrScheme",
22681
+ THEME_NS
22682
+ ).slice(0, 4).map((variant) => {
22683
+ const entries = /* @__PURE__ */ new Map();
22684
+ for (let index2 = 1; index2 <= 7; index2++) {
22685
+ const choice2 = parsedColorChoice(themeChild(variant, `varColor${index2}`, THEME_NS));
22686
+ if (choice2) entries.set(String(index2), choice2);
22687
+ }
22688
+ return entries;
22689
+ });
22690
+ const format5 = themeChild(base2, "fmtScheme");
22691
+ const connector2 = extension(base2, "fmtConnectorScheme");
22692
+ const fonts = extension(base2, "fontStylesGroup");
22693
+ const name3 = root2.getAttribute("name");
22694
+ result2.push({
22695
+ ...name3 ? { name: name3.slice(0, 256) } : {},
22696
+ colorId: integer3(extension(palette, "schemeID")?.getAttribute("schemeEnum")),
22697
+ effectId: componentId(extension(base2, "fmtSchemeEx")),
22698
+ connectorId: componentId(extension(base2, "fmtConnectorSchemeEx")),
22699
+ colors,
22700
+ variants,
22701
+ variationStyles: themeChildren(
22702
+ extension(base2, "variationStyleSchemeLst"),
22703
+ "variationStyleScheme",
22704
+ THEME_NS
22705
+ ).slice(0, 4).map((variant) => themeChildren(variant, "varStyle", THEME_NS).slice(0, 4)),
22706
+ fills: formatList(format5, "fillStyleLst"),
22707
+ effects: themeChildren(themeChild(format5, "effectStyleLst"), "effectStyle").slice(0, 6),
22708
+ lines: themeChildren(themeChild(format5, "lnStyleLst"), "ln").slice(0, 6),
22709
+ fonts: themeChildren(themeChild(fonts, "fontStyles", THEME_NS), "fontProps", THEME_NS).slice(
22710
+ 0,
22711
+ 6
22712
+ ),
22713
+ connectorFills: formatList(connector2, "fillStyleLst"),
22714
+ connectorEffects: themeChildren(themeChild(connector2, "effectStyleLst"), "effectStyle").slice(
22715
+ 0,
22716
+ 6
22717
+ ),
22718
+ connectorLines: themeChildren(themeChild(connector2, "lnStyleLst"), "ln").slice(0, 6),
22719
+ connectorFonts: themeChildren(
22720
+ themeChild(fonts, "connectorFontStyles", THEME_NS),
22721
+ "fontProps",
22722
+ THEME_NS
22723
+ ).slice(0, 6)
22724
+ });
22725
+ }
22726
+ return result2;
22727
+ }
22728
+ function formatList(parent, name3) {
22729
+ const list2 = themeChild(parent, name3);
22730
+ return list2 ? Array.from(list2.childNodes).filter(
22731
+ (node3) => node3.nodeType === 1 && node3.namespaceURI === DRAWING_NS
22732
+ ).slice(0, 6) : [];
22733
+ }
22734
+
22735
+ // visio/document-level.ts
22736
+ function optionsKey(options2) {
22737
+ const { metafileConverter: _converter, pages: _pages, documentCache: _cache, ...rest } = options2;
22738
+ return JSON.stringify(rest);
22739
+ }
22740
+ 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);
22741
+ async function readDocumentLevel(pkg, documentPart2, options2, checkTime, forward) {
22742
+ const reports = [];
22743
+ const report = (...args) => {
22744
+ reports.push(args);
22745
+ forward(...args);
22746
+ };
22747
+ const documentRoot = await visioXml(pkg, documentPart2, "VisioDocument");
22748
+ const resources = {
22749
+ colors: /* @__PURE__ */ new Map(),
22750
+ fonts: /* @__PURE__ */ new Map(),
22751
+ themes: await loadVisioThemes(pkg, documentPart2, report)
22752
+ };
22753
+ for (const color2 of children2(child(documentRoot, "Colors"), "ColorEntry"))
22754
+ resources.colors.set(attribute2(color2, "IX") ?? "", attribute2(color2, "RGB") ?? "");
22755
+ const faceNames = children2(child(documentRoot, "FaceNames"), "FaceName");
22756
+ if (faceNames.length > 1e4)
22757
+ throw new VisioPackageError(
22758
+ "METADATA_LIMIT",
22759
+ "Document font count exceeds its metadata limit."
22760
+ );
22761
+ let fontCharacters = 0;
22762
+ faceNames.forEach((font, index2) => {
22763
+ checkTime();
22764
+ fontCharacters += (attribute2(font, "Name") ?? attribute2(font, "NameU") ?? "Arial").length;
22765
+ if (fontCharacters > 1e6)
22766
+ throw new VisioPackageError(
22767
+ "METADATA_LIMIT",
22768
+ "Document fonts exceed aggregate metadata limits."
22769
+ );
22770
+ resources.fonts.set(
22771
+ metadata(attribute2(font, "ID") ?? String(index2), 256, "Font ID"),
22772
+ metadata(attribute2(font, "Name") ?? attribute2(font, "NameU") ?? "Arial", 1024, "Font name")
22773
+ );
22774
+ });
22775
+ const styles = /* @__PURE__ */ new Map();
22776
+ for (const style2 of children2(child(documentRoot, "StyleSheets"), "StyleSheet"))
22777
+ styles.set(metadata(attribute2(style2, "ID") ?? "", 256, "Style ID"), {
22778
+ sheet: readSheet(style2),
22779
+ attributes: metadataAttributes(style2)
22780
+ });
22781
+ const rootStyle = styles.get("0");
22782
+ if (rootStyle?.attributes.get("NameU") === "No Style") resources.rootSheet = rootStyle.sheet;
22783
+ const printStyleGroups = children2(documentRoot, "StyleSheets");
22784
+ const readPrintSettings = createVisioPrintSettingsReader(
22785
+ children2(documentRoot, "DocumentSheet"),
22786
+ printStyleGroups.length === 1 ? children2(printStyleGroups[0], "StyleSheet").filter((node3) => attribute2(node3, "ID") === "0") : []
22787
+ );
22788
+ const masters = /* @__PURE__ */ new Map();
22789
+ const masterRecords = [];
22790
+ const mastersPart = await related(pkg, documentPart2, "masters", false);
22791
+ if (mastersPart) {
22792
+ for (const master2 of children2(await visioXml(pkg, mastersPart, "Masters"), "Master")) {
22793
+ const part = await indexedPart(pkg, mastersPart, master2, "master");
22794
+ const id3 = metadata(attribute2(master2, "ID") ?? "", 256, "Master ID");
22795
+ if (!id3 || masters.has(id3))
22796
+ throw new VisioPackageError("INVALID_MASTER_ID", "Master IDs must be present and unique.");
22797
+ const masterShapes2 = readShapes(await visioXml(pkg, part, "MasterContents"));
22798
+ await prepareImages(
22799
+ masterShapes2,
22800
+ pkg,
22801
+ part,
22802
+ report,
22803
+ options2.images,
22804
+ options2.metafileConverter
22805
+ );
22806
+ masters.set(id3, masterShapes2);
22807
+ masterRecords.push({ id: id3, node: master2, shapes: masterShapes2 });
22808
+ }
22809
+ }
22810
+ return { documentRoot, resources, styles, readPrintSettings, masters, masterRecords, reports };
22811
+ }
22812
+
22532
22813
  // visio/comments.ts
22533
22814
  var VISIO_COMMENTS_CONTENT_TYPE = "application/vnd.ms-visio.comments+xml";
22534
22815
  var VISIO_COMMENTS_RELATIONSHIP = "http://schemas.microsoft.com/visio/2010/relationships/comments";
@@ -22629,6 +22910,10 @@ function createMetadataBudget(options2 = {}) {
22629
22910
  if (characters > maxCharacters)
22630
22911
  throw new VisioPackageError("METADATA_LIMIT", "Shape metadata character budget exceeded.");
22631
22912
  return value3;
22913
+ },
22914
+ state: () => [rows, characters],
22915
+ restore(state) {
22916
+ [rows, characters] = state;
22632
22917
  }
22633
22918
  };
22634
22919
  }
@@ -23601,177 +23886,6 @@ function readVisioPageSetup(cells4) {
23601
23886
  return Object.keys(result2).length ? result2 : void 0;
23602
23887
  }
23603
23888
 
23604
- // visio/print-settings.ts
23605
- var NAMES = [
23606
- "PaperKind",
23607
- "PrintPageOrientation",
23608
- "PageLeftMargin",
23609
- "PageRightMargin",
23610
- "PageTopMargin",
23611
- "PageBottomMargin",
23612
- "ScaleX",
23613
- "ScaleY",
23614
- "OnPage",
23615
- "PagesX",
23616
- "PagesY",
23617
- "CenterX",
23618
- "CenterY"
23619
- ];
23620
- var BOOLEAN = /* @__PURE__ */ new Set(["OnPage", "CenterX", "CenterY"]);
23621
- var LENGTH = /* @__PURE__ */ new Set(["PageLeftMargin", "PageRightMargin", "PageTopMargin", "PageBottomMargin"]);
23622
- var CANONICAL = new Map(
23623
- [...NAMES, "PageWidth", "PageHeight", "PageScale", "DrawingScale"].map((name3) => [
23624
- name3.toLowerCase(),
23625
- name3
23626
- ])
23627
- );
23628
- function indexCells2(sheet) {
23629
- const cells4 = /* @__PURE__ */ new Map();
23630
- let duplicate = false;
23631
- for (const node3 of children2(sheet, "Cell")) {
23632
- const name3 = attribute2(node3, "N") ?? "", canonical2 = CANONICAL.get(name3.toLowerCase());
23633
- if (!canonical2) continue;
23634
- if (canonical2 !== name3) duplicate = true;
23635
- const values = cells4.get(canonical2) ?? [];
23636
- if (values.length < 2) values.push(node3);
23637
- cells4.set(canonical2, values);
23638
- if (values.length > 1) duplicate = true;
23639
- }
23640
- return { cells: cells4, duplicate };
23641
- }
23642
- function createVisioPrintSettingsReader(documentSheets, rootStyles) {
23643
- const indexes = { document: indexCells2(documentSheets[0]), root: indexCells2(rootStyles[0]) };
23644
- return (pageSheets) => readVisioPrintCountSettings(pageSheets, documentSheets, rootStyles, indexes);
23645
- }
23646
- function readVisioPrintCountSettings(pageSheets, documentSheets, rootStyles, indexes) {
23647
- let refusal;
23648
- const refuse4 = (reason) => {
23649
- refusal ??= reason;
23650
- };
23651
- if (pageSheets.length !== 1) refuse4("ambiguous-page-sheet");
23652
- if (documentSheets.length > 1) refuse4("ambiguous-document-sheet");
23653
- if (!documentSheets.length) refuse4("missing-setting");
23654
- if (rootStyles.length > 1) refuse4("duplicate-setting");
23655
- const root2 = rootStyles[0];
23656
- if (!root2 || attribute2(root2, "ID") !== "0" || attribute2(root2, "NameU") !== "No Style")
23657
- refuse4("unsupported-print-style");
23658
- for (const sheet of [...pageSheets, ...documentSheets])
23659
- for (const name3 of ["LineStyle", "FillStyle", "TextStyle"])
23660
- if (attribute2(sheet, name3) !== "0") refuse4("unsupported-print-style");
23661
- for (const name3 of ["LineStyle", "FillStyle", "TextStyle"])
23662
- if (attribute2(root2, name3) !== void 0) refuse4("unsupported-print-style");
23663
- const localIndex = indexCells2(pageSheets[0]), rootIndex = indexes?.root ?? indexCells2(root2);
23664
- const documentIndex = indexes?.document ?? indexCells2(documentSheets[0]);
23665
- if (localIndex.duplicate || rootIndex.duplicate || documentIndex.duplicate)
23666
- refuse4("duplicate-setting");
23667
- const local = localIndex.cells, inherited = rootIndex.cells;
23668
- const read = (node3, name3, origin) => {
23669
- const invalid4 = () => {
23670
- refuse4(origin === "local" ? "invalid-local-setting" : "invalid-document-setting");
23671
- return void 0;
23672
- };
23673
- if (node3.hasAttribute("E")) return invalid4();
23674
- let raw = (attribute2(node3, "V") ?? "").trim();
23675
- if (!raw || raw.length > 128) return invalid4();
23676
- if (BOOLEAN.has(name3)) {
23677
- if (!["0", "1", "false", "true"].includes(raw)) return invalid4();
23678
- raw = raw === "true" ? "1" : raw === "false" ? "0" : raw;
23679
- }
23680
- try {
23681
- const value3 = visioFormulaCachedValue(raw, attribute2(node3, "U"));
23682
- const length = LENGTH.has(name3) || /^(PageWidth|PageHeight|PageScale|DrawingScale)$/.test(name3);
23683
- if (!["scalar", ...length ? ["length"] : []].includes(value3.unit) || Math.abs(value3.value) > 1e9)
23684
- return invalid4();
23685
- const formula = attribute2(node3, "F");
23686
- if (formula !== void 0) {
23687
- const source = formula.trim();
23688
- if (/^(true|false)$/i.test(source)) {
23689
- if ((source.toLowerCase() === "true" ? 1 : 0) !== value3.value) return invalid4();
23690
- } else {
23691
- if (!source || source === "Inh") return invalid4();
23692
- const limits = { maxLength: 512, maxNodes: 64, maxDepth: 16, maxSteps: 128 };
23693
- const analysis = analyzeVisioFormula(source, limits);
23694
- if (analysis.dynamic || analysis.guarded || analysis.references.length || analysis.unsupportedFunctions.length) {
23695
- refuse4("dynamic-setting");
23696
- return void 0;
23697
- }
23698
- const evaluated = evaluateVisioFormula(
23699
- source,
23700
- () => {
23701
- throw new Error("Unexpected reference");
23702
- },
23703
- limits
23704
- );
23705
- if (evaluated.value !== value3.value || !["scalar", ...length ? ["length"] : []].includes(evaluated.unit))
23706
- return invalid4();
23707
- }
23708
- }
23709
- return value3.value;
23710
- } catch {
23711
- return invalid4();
23712
- }
23713
- };
23714
- const values = /* @__PURE__ */ new Map();
23715
- for (const name3 of NAMES) {
23716
- const nodes = local.get(name3) ?? inherited.get(name3);
23717
- if (!nodes?.length) continue;
23718
- if (nodes.length !== 1) continue;
23719
- const value3 = read(nodes[0], name3, local.has(name3) ? "local" : "document");
23720
- if (value3 !== void 0) values.set(name3, value3);
23721
- }
23722
- for (const name3 of ["PageWidth", "PageHeight", "PageScale", "DrawingScale"]) {
23723
- const nodes = local.get(name3);
23724
- if (!nodes || nodes.length !== 1 || !(read(nodes[0], name3, "local") > 0))
23725
- refuse4("unusable-drawing-scale");
23726
- }
23727
- const setup = {};
23728
- const paper = values.get("PaperKind");
23729
- if (paper !== void 0 && Number.isSafeInteger(paper) && paper >= 0 && paper <= 65535)
23730
- setup.paperKind = paper;
23731
- else if (paper !== void 0)
23732
- refuse4(local.has("PaperKind") ? "invalid-local-setting" : "invalid-document-setting");
23733
- const orientation = values.get("PrintPageOrientation");
23734
- if (orientation === 0 || orientation === 1 || orientation === 2)
23735
- setup.printPageOrientation = orientation;
23736
- else if (orientation !== void 0)
23737
- refuse4(
23738
- local.has("PrintPageOrientation") ? "invalid-local-setting" : "invalid-document-setting"
23739
- );
23740
- const margins = ["Left", "Right", "Top", "Bottom"].map((side2) => values.get(`Page${side2}Margin`));
23741
- if (margins.every((n) => n !== void 0 && n >= 0 && n <= 1e3))
23742
- setup.margins = {
23743
- left: margins[0],
23744
- right: margins[1],
23745
- top: margins[2],
23746
- bottom: margins[3]
23747
- };
23748
- else if (margins.some((n) => n !== void 0 && (n < 0 || n > 1e3)))
23749
- refuse4("unusable-print-area");
23750
- for (const [name3, key2] of [
23751
- ["ScaleX", "printZoom"],
23752
- ["ScaleY", "printZoomY"],
23753
- ["PagesX", "printPagesAcross"],
23754
- ["PagesY", "printPagesDown"]
23755
- ]) {
23756
- const value3 = values.get(name3);
23757
- if (value3 !== void 0) {
23758
- if ((name3 === "PagesX" || name3 === "PagesY") && (!Number.isSafeInteger(value3) || value3 < 1))
23759
- refuse4(local.has(name3) ? "invalid-local-setting" : "invalid-document-setting");
23760
- else setup[key2] = value3;
23761
- }
23762
- }
23763
- for (const [name3, key2] of [
23764
- ["OnPage", "printFitToPages"],
23765
- ["CenterX", "printCenterX"],
23766
- ["CenterY", "printCenterY"]
23767
- ]) {
23768
- const value3 = values.get(name3);
23769
- if (value3 !== void 0) setup[key2] = value3 === 1;
23770
- }
23771
- if (refusal) setup.printCountRefusal = refusal;
23772
- return setup;
23773
- }
23774
-
23775
23889
  // visio/page-layout.ts
23776
23890
  var VISIO_GRID_DENSITIES = Object.freeze([0, 2, 4, 8]);
23777
23891
  var VISIO_RULER_DENSITIES = Object.freeze([8, 16, 32]);
@@ -24091,69 +24205,18 @@ async function parseVsdx(input, options2 = {}) {
24091
24205
  );
24092
24206
  }
24093
24207
  }
24094
- const documentRoot = await visioXml(pkg, documentPart2, "VisioDocument");
24095
- const resources = {
24096
- colors: /* @__PURE__ */ new Map(),
24097
- fonts: /* @__PURE__ */ new Map(),
24098
- themes: await loadVisioThemes(pkg, documentPart2, report)
24099
- };
24100
- for (const color2 of children2(child(documentRoot, "Colors"), "ColorEntry"))
24101
- resources.colors.set(attribute2(color2, "IX") ?? "", attribute2(color2, "RGB") ?? "");
24102
- const faceNames = children2(child(documentRoot, "FaceNames"), "FaceName");
24103
- if (faceNames.length > 1e4)
24104
- throw new VisioPackageError(
24105
- "METADATA_LIMIT",
24106
- "Document font count exceeds its metadata limit."
24107
- );
24108
- let fontCharacters = 0;
24109
- faceNames.forEach((font, index2) => {
24110
- checkTime();
24111
- fontCharacters += (attribute2(font, "Name") ?? attribute2(font, "NameU") ?? "Arial").length;
24112
- if (fontCharacters > 1e6)
24113
- throw new VisioPackageError(
24114
- "METADATA_LIMIT",
24115
- "Document fonts exceed aggregate metadata limits."
24116
- );
24117
- resources.fonts.set(
24118
- metadata(attribute2(font, "ID") ?? String(index2), 256, "Font ID"),
24119
- metadata(attribute2(font, "Name") ?? attribute2(font, "NameU") ?? "Arial", 1024, "Font name")
24120
- );
24121
- });
24122
- const styles = /* @__PURE__ */ new Map();
24123
- for (const style2 of children2(child(documentRoot, "StyleSheets"), "StyleSheet"))
24124
- styles.set(metadata(attribute2(style2, "ID") ?? "", 256, "Style ID"), {
24125
- sheet: readSheet(style2),
24126
- attributes: metadataAttributes(style2)
24127
- });
24128
- const rootStyle = styles.get("0");
24129
- if (rootStyle?.attributes.get("NameU") === "No Style") resources.rootSheet = rootStyle.sheet;
24130
- const printStyleGroups = children2(documentRoot, "StyleSheets");
24131
- const readPrintSettings = createVisioPrintSettingsReader(
24132
- children2(documentRoot, "DocumentSheet"),
24133
- printStyleGroups.length === 1 ? children2(printStyleGroups[0], "StyleSheet").filter((node3) => attribute2(node3, "ID") === "0") : []
24134
- );
24135
- const masters = /* @__PURE__ */ new Map();
24136
- const masterRecords = [];
24137
- const mastersPart = await related(pkg, documentPart2, "masters", false);
24138
- if (mastersPart) {
24139
- for (const master2 of children2(await visioXml(pkg, mastersPart, "Masters"), "Master")) {
24140
- const part = await indexedPart(pkg, mastersPart, master2, "master");
24141
- const id3 = metadata(attribute2(master2, "ID") ?? "", 256, "Master ID");
24142
- if (!id3 || masters.has(id3))
24143
- throw new VisioPackageError("INVALID_MASTER_ID", "Master IDs must be present and unique.");
24144
- const masterShapes2 = readShapes(await visioXml(pkg, part, "MasterContents"));
24145
- await prepareImages(
24146
- masterShapes2,
24147
- pkg,
24148
- part,
24149
- report,
24150
- options2.images,
24151
- options2.metafileConverter
24152
- );
24153
- masters.set(id3, masterShapes2);
24154
- masterRecords.push({ id: id3, node: master2, shapes: masterShapes2 });
24155
- }
24156
- }
24208
+ const cache2 = options2.documentCache;
24209
+ const cached5 = cacheMatches(cache2?.entry, pkg, options2) ? cache2.entry : void 0;
24210
+ const stopRecording = cache2 && !cached5 ? pkg.record() : void 0;
24211
+ let level2;
24212
+ if (cached5) {
24213
+ level2 = cached5.level;
24214
+ for (const args of level2.reports) report(...args);
24215
+ } else level2 = await readDocumentLevel(pkg, documentPart2, options2, checkTime, report);
24216
+ const { documentRoot, styles, readPrintSettings, masters, masterRecords } = level2;
24217
+ const resources = { ...level2.resources };
24218
+ delete resources.pageCells;
24219
+ delete resources.fieldContext;
24157
24220
  let geometryCount = 0, textCount = 0, expansionCount = 0, textRuns = 0, paragraphCount = 0;
24158
24221
  const context = {
24159
24222
  metadataBudget: createMetadataBudget(options2.metadata),
@@ -24207,15 +24270,52 @@ async function parseVsdx(input, options2 = {}) {
24207
24270
  throw new VisioPackageError("TEXT_LIMIT", "Text character limit exceeded.");
24208
24271
  }
24209
24272
  };
24210
- const documentMasters = listVisioMasters(masterRecords, context, {
24211
- metadataBudget: createMetadataBudget(options2.metadata),
24212
- layerBudget: createLayerBudget()
24213
- });
24273
+ let documentMasters;
24274
+ if (cached5) {
24275
+ const { counters } = cached5.listed;
24276
+ curveWork = counters.curveWork;
24277
+ geometryCount = counters.geometry;
24278
+ textCount = counters.text;
24279
+ expansionCount = counters.expansion;
24280
+ textRuns = counters.textRuns;
24281
+ paragraphCount = counters.paragraphs;
24282
+ context.shapeCount = counters.shapes;
24283
+ context.metadataBudget.restore(counters.metadata);
24284
+ context.layerBudget.restore(counters.layers);
24285
+ documentMasters = cached5.listed.documentMasters;
24286
+ } else {
24287
+ documentMasters = listVisioMasters(masterRecords, context, {
24288
+ metadataBudget: createMetadataBudget(options2.metadata),
24289
+ layerBudget: createLayerBudget()
24290
+ });
24291
+ if (cache2 && stopRecording)
24292
+ cache2.entry = {
24293
+ options: optionsKey(options2),
24294
+ converter: options2.metafileConverter,
24295
+ reads: stopRecording(),
24296
+ level: { ...level2, resources: { ...resources } },
24297
+ listed: {
24298
+ documentMasters,
24299
+ counters: {
24300
+ curveWork,
24301
+ geometry: geometryCount,
24302
+ text: textCount,
24303
+ expansion: expansionCount,
24304
+ textRuns,
24305
+ paragraphs: paragraphCount,
24306
+ shapes: context.shapeCount,
24307
+ metadata: context.metadataBudget.state(),
24308
+ layers: context.layerBudget.state()
24309
+ }
24310
+ }
24311
+ };
24312
+ }
24214
24313
  const pagesPart = await related(pkg, documentPart2, "pages", !options2.stencil);
24215
24314
  if (!pagesPart && !options2.stencil)
24216
24315
  throw new VisioPackageError("INVALID_DOCUMENT", "Missing Visio pages part.");
24217
24316
  const pages = [], pageIds2 = /* @__PURE__ */ new Set();
24218
24317
  const comments = [];
24318
+ const only = options2.pages ? new Set(options2.pages) : void 0;
24219
24319
  const pageNodes = pagesPart ? children2(await visioXml(pkg, pagesPart, "Pages"), "Page") : [];
24220
24320
  const foreground = pageNodes.filter((page) => !yes(attribute2(page, "Background")));
24221
24321
  const fieldProperties = await readVisioFieldProperties(pkg);
@@ -24225,6 +24325,7 @@ async function parseVsdx(input, options2 = {}) {
24225
24325
  if (!id3 || pageIds2.has(id3))
24226
24326
  throw new VisioPackageError("INVALID_PAGE_ID", "Page IDs must be present and unique.");
24227
24327
  pageIds2.add(id3);
24328
+ if (only && !only.has(id3)) continue;
24228
24329
  const part = await indexedPart(pkg, pagesPart, page, "page");
24229
24330
  const root2 = await visioXml(pkg, part, "PageContents");
24230
24331
  const localReport = (code, message, extra) => report(code, message, { part, pageId: id3, ...extra });
@@ -24334,16 +24435,16 @@ async function parseVsdx(input, options2 = {}) {
24334
24435
  });
24335
24436
  }
24336
24437
  checkTime();
24337
- validateBackgrounds(pages, report);
24438
+ if (!only) validateBackgrounds(pages, report);
24338
24439
  try {
24339
- comments.push(...await readVisioComments(pkg, documentPart2, report));
24440
+ if (!only) comments.push(...await readVisioComments(pkg, documentPart2, report));
24340
24441
  } catch (error) {
24341
24442
  if (!(error instanceof VisioPackageError) || error.code === "LIMIT_RUNTIME") throw error;
24342
24443
  report("invalid-comments", "The comments part could not be read; comments are not shown.");
24343
24444
  }
24344
24445
  let dataRecordsets = [];
24345
24446
  try {
24346
- dataRecordsets = await readDataRecordsets(pkg, documentPart2, checkTime);
24447
+ if (!only) dataRecordsets = await readDataRecordsets(pkg, documentPart2, checkTime);
24347
24448
  } catch (error) {
24348
24449
  if (error instanceof VisioPackageError && error.code === "LIMIT_RUNTIME") throw error;
24349
24450
  report(
@@ -24351,7 +24452,7 @@ async function parseVsdx(input, options2 = {}) {
24351
24452
  `Saved external data could not be read and is preserved unchanged: ${error instanceof Error ? error.message : String(error)}`
24352
24453
  );
24353
24454
  }
24354
- const stencils = await readVisioStencilWindows(pkg, documentPart2);
24455
+ const stencils = only ? [] : await readVisioStencilWindows(pkg, documentPart2);
24355
24456
  report(
24356
24457
  "cached-values-only",
24357
24458
  "ShapeSheet formulas, automatic connector routing, and external data are not evaluated; saved cached values and supported theme records are used.",
@@ -33880,6 +33981,55 @@ async function loadVisio(input, options2 = {}) {
33880
33981
  );
33881
33982
  }
33882
33983
 
33984
+ // visio/parse-incremental.ts
33985
+ var BACKGROUND_CODES = /* @__PURE__ */ new Set(["background-cycle", "missing-background-page"]);
33986
+ var MAX_SPLICED_DIAGNOSTICS = 1e3;
33987
+ var DEFAULT_MAX_SHAPES = 25e3;
33988
+ var countShapes = (shapes) => shapes.reduce((sum, shape) => sum + 1 + countShapes(shape.children), 0);
33989
+ var isPageDiagnostic = (d) => d.pageId !== void 0 && !BACKGROUND_CODES.has(d.code);
33990
+ function mergeVisioPages(previous, partial, pageIds2, options2 = {}) {
33991
+ if (previous.format !== "vsdx" || partial.format !== "vsdx") return void 0;
33992
+ const wanted = new Set(pageIds2);
33993
+ const fresh = new Map(partial.pages.map((page) => [page.id, page]));
33994
+ if (fresh.size !== wanted.size || ![...wanted].every((id3) => fresh.has(id3))) return void 0;
33995
+ const before = new Map(previous.pages.map((page) => [page.id, page]));
33996
+ if (![...wanted].every((id3) => before.has(id3))) return void 0;
33997
+ for (const [id3, page] of fresh)
33998
+ if (before.get(id3).backgroundPageId === void 0) delete page.backgroundPageId;
33999
+ const pages = previous.pages.map((page) => fresh.get(page.id) ?? page);
34000
+ if (pages.reduce((sum, page) => sum + countShapes(page.shapes), 0) > (options2.maxShapes ?? DEFAULT_MAX_SHAPES))
34001
+ return void 0;
34002
+ const diagnostics = spliceDiagnostics(previous.diagnostics, partial.diagnostics, wanted);
34003
+ if (!diagnostics) return void 0;
34004
+ return { ...previous, pages, diagnostics };
34005
+ }
34006
+ function spliceDiagnostics(previous, partial, wanted) {
34007
+ const truncated = (list2) => list2.some((d) => d.code === "diagnostics-truncated");
34008
+ if (truncated(previous) || truncated(partial)) return void 0;
34009
+ const fresh = partial.filter((d) => isPageDiagnostic(d) && wanted.has(d.pageId));
34010
+ if (previous.length + fresh.length > MAX_SPLICED_DIAGNOSTICS) return void 0;
34011
+ let out = [...previous];
34012
+ for (const id3 of wanted) {
34013
+ const next = fresh.filter((d) => d.pageId === id3);
34014
+ const at2 = out.flatMap((d, i) => isPageDiagnostic(d) && d.pageId === id3 ? [i] : []);
34015
+ if (!at2.length) {
34016
+ if (next.length) return void 0;
34017
+ continue;
34018
+ }
34019
+ const first2 = at2[0];
34020
+ const last = at2[at2.length - 1];
34021
+ if (last - first2 + 1 !== at2.length) return void 0;
34022
+ out = [...out.slice(0, first2), ...next, ...out.slice(last + 1)];
34023
+ }
34024
+ return out;
34025
+ }
34026
+ async function parseVsdxPages(input, previous, pageIds2, options2 = {}) {
34027
+ const partial = await parseVsdx(input, { ...options2, pages: pageIds2 });
34028
+ return mergeVisioPages(previous, partial, pageIds2, {
34029
+ ...options2.maxShapes !== void 0 ? { maxShapes: options2.maxShapes } : {}
34030
+ });
34031
+ }
34032
+
33883
34033
  // visio/visibility.ts
33884
34034
  var VISIO_VISIBILITY_LIMITS = Object.freeze({
33885
34035
  maxShapes: 25e3,
@@ -48897,10 +49047,12 @@ exports.isVisioStencilShape = isVisioStencilShape;
48897
49047
  exports.isVisioThemeColorRef = isVisioThemeColorRef;
48898
49048
  exports.layoutVisioFilledArrowLine = layoutVisioFilledArrowLine;
48899
49049
  exports.loadVisio = loadVisio;
49050
+ exports.mergeVisioPages = mergeVisioPages;
48900
49051
  exports.parseLegacyVsd = parseLegacyVsd;
48901
49052
  exports.parseVisioFormula = parseVisioFormula;
48902
49053
  exports.parseVisioThemeColorFormula = parseVisioThemeColorFormula;
48903
49054
  exports.parseVsdx = parseVsdx;
49055
+ exports.parseVsdxPages = parseVsdxPages;
48904
49056
  exports.readVisioStencil = readVisioStencil;
48905
49057
  exports.resolveVisioPageVisibility = resolveVisioPageVisibility;
48906
49058
  exports.resolveVisioThemeColor = resolveVisioThemeColor;