ooxml-core 1.23.0 → 1.24.1

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 (123) hide show
  1. package/README.md +2 -2
  2. package/dist/{PptxHandler-FSKKPZZC.mjs → PptxHandler-5TWAQWPK.mjs} +2 -2
  3. package/dist/{PptxHandler-H7MEWJJJ.mjs → PptxHandler-KBJ4TN3T.mjs} +1 -1
  4. package/dist/{PptxHandler-DNSXWTQV.cjs → PptxHandler-KFEE7O7W.cjs} +2 -2
  5. package/dist/{PresentationBuilder-7TSENZTX.mjs → PresentationBuilder-SCT5AQBP.mjs} +1 -1
  6. package/dist/{PresentationBuilder-RIJWQSEU.mjs → PresentationBuilder-SVHIKT4C.mjs} +2 -2
  7. package/dist/{PresentationBuilder-A5NI35VN.cjs → PresentationBuilder-SXLRXYDI.cjs} +4 -4
  8. package/dist/automation/index.cjs +553 -335
  9. package/dist/automation/index.d.ts +1 -0
  10. package/dist/automation/index.d.ts.map +1 -1
  11. package/dist/automation/index.mjs +552 -336
  12. package/dist/automation/live.d.ts +89 -0
  13. package/dist/automation/live.d.ts.map +1 -0
  14. package/dist/{chunk-4QPOJCJG.mjs → chunk-7N7C5BNM.mjs} +1 -1
  15. package/dist/{chunk-DLFMCZZT.mjs → chunk-CWCDFPKN.mjs} +1 -1
  16. package/dist/{chunk-LF5E5ZOH.mjs → chunk-GVP262WE.mjs} +25 -62
  17. package/dist/{chunk-VQF6HQEE.mjs → chunk-KVKTHGIY.mjs} +1 -1
  18. package/dist/{chunk-BA7Z6ATM.mjs → chunk-NE7626A4.mjs} +4 -4
  19. package/dist/{chunk-Q5PKBQXH.mjs → chunk-ON7XVRHQ.mjs} +26 -63
  20. package/dist/{chunk-HL3FBJ6X.cjs → chunk-XK55DEUD.cjs} +25 -62
  21. package/dist/docx/ui/customization.d.ts +30 -0
  22. package/dist/docx/ui/customization.d.ts.map +1 -0
  23. package/dist/docx/ui/index.cjs +51 -0
  24. package/dist/docx/ui/index.d.ts +1 -0
  25. package/dist/docx/ui/index.d.ts.map +1 -1
  26. package/dist/docx/ui/index.mjs +46 -1
  27. package/dist/embedding/backstage.d.ts +48 -0
  28. package/dist/embedding/backstage.d.ts.map +1 -0
  29. package/dist/embedding/capabilities.d.ts +60 -0
  30. package/dist/embedding/capabilities.d.ts.map +1 -0
  31. package/dist/embedding/customization.d.ts +32 -0
  32. package/dist/embedding/customization.d.ts.map +1 -0
  33. package/dist/embedding/index.cjs +229 -0
  34. package/dist/embedding/index.d.ts +7 -0
  35. package/dist/embedding/index.d.ts.map +1 -0
  36. package/dist/embedding/index.mjs +204 -0
  37. package/dist/embedding/menu-commands.d.ts +66 -0
  38. package/dist/embedding/menu-commands.d.ts.map +1 -0
  39. package/dist/embedding/regions.d.ts +58 -0
  40. package/dist/embedding/regions.d.ts.map +1 -0
  41. package/dist/embedding/storage.d.ts +111 -0
  42. package/dist/embedding/storage.d.ts.map +1 -0
  43. package/dist/index.cjs +233 -0
  44. package/dist/index.d.ts +1 -0
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.mjs +233 -1
  47. package/dist/pptx/automation/index.cjs +25 -67
  48. package/dist/pptx/automation/index.d.ts +3 -2
  49. package/dist/pptx/automation/index.d.ts.map +1 -1
  50. package/dist/pptx/automation/index.mjs +5 -5
  51. package/dist/pptx/chunks/{index-Q5mM8kIR.d.ts → index-4FmgJajb.d.ts} +3 -2
  52. package/dist/pptx/chunks/index-4FmgJajb.d.ts.map +1 -0
  53. package/dist/pptx/chunks/index-C3xhAMSa.d.ts +837 -0
  54. package/dist/pptx/chunks/index-C3xhAMSa.d.ts.map +1 -0
  55. package/dist/pptx/chunks/{index-CPhsd7Df.d.ts → index-nKQ4s7FA.d.ts} +24 -834
  56. package/dist/pptx/chunks/index-nKQ4s7FA.d.ts.map +1 -0
  57. package/dist/pptx/cli/index.cjs +25 -67
  58. package/dist/pptx/cli/index.mjs +4 -4
  59. package/dist/pptx/converter/index.d.ts +1 -1
  60. package/dist/pptx/converter/index.mjs +2 -2
  61. package/dist/pptx/editor/render/find-replace.d.ts +1 -1
  62. package/dist/pptx/editor/render/slide-operations.cjs +1 -1
  63. package/dist/pptx/editor/render/slide-operations.mjs +1 -1
  64. package/dist/pptx/index.cjs +25 -67
  65. package/dist/pptx/index.d.ts +4 -3
  66. package/dist/pptx/index.mjs +5 -5
  67. package/dist/pptx/node/index.cjs +40 -0
  68. package/dist/pptx/node/index.d.ts +13 -0
  69. package/dist/pptx/node/index.d.ts.map +1 -0
  70. package/dist/pptx/node/index.mjs +40 -0
  71. package/dist/visio/collab/compose.d.ts.map +1 -1
  72. package/dist/visio/collab/fixups.d.ts.map +1 -1
  73. package/dist/visio/collab/index.cjs +167 -62
  74. package/dist/visio/collab/index.mjs +167 -62
  75. package/dist/visio/collab/keys.d.ts +2 -0
  76. package/dist/visio/collab/keys.d.ts.map +1 -1
  77. package/dist/visio/collab/pieces.d.ts +7 -0
  78. package/dist/visio/collab/pieces.d.ts.map +1 -1
  79. package/dist/visio/collab/read-ids.d.ts +7 -1
  80. package/dist/visio/collab/read-ids.d.ts.map +1 -1
  81. package/dist/visio/collab/read-parts.d.ts.map +1 -1
  82. package/dist/visio/collab/read-shapes.d.ts +0 -1
  83. package/dist/visio/collab/read-shapes.d.ts.map +1 -1
  84. package/dist/visio/collab/read.d.ts.map +1 -1
  85. package/dist/visio/collab/schema.d.ts +1 -1
  86. package/dist/visio/collab/schema.d.ts.map +1 -1
  87. package/dist/visio/collab/snapshot-contents.d.ts.map +1 -1
  88. package/dist/visio/collab/write-shapes.d.ts.map +1 -1
  89. package/dist/visio/collab/zip-store.d.ts +4 -0
  90. package/dist/visio/collab/zip-store.d.ts.map +1 -0
  91. package/dist/visio/document-level.d.ts +57 -0
  92. package/dist/visio/document-level.d.ts.map +1 -0
  93. package/dist/visio/index.cjs +543 -444
  94. package/dist/visio/index.d.ts +1 -0
  95. package/dist/visio/index.d.ts.map +1 -1
  96. package/dist/visio/index.mjs +543 -444
  97. package/dist/visio/layers.d.ts +3 -0
  98. package/dist/visio/layers.d.ts.map +1 -1
  99. package/dist/visio/package.d.ts +9 -0
  100. package/dist/visio/package.d.ts.map +1 -1
  101. package/dist/visio/parser.d.ts +7 -0
  102. package/dist/visio/parser.d.ts.map +1 -1
  103. package/dist/visio/shape-metadata.d.ts +3 -0
  104. package/dist/visio/shape-metadata.d.ts.map +1 -1
  105. package/dist/visio/ui/contract.d.ts +27 -2
  106. package/dist/visio/ui/contract.d.ts.map +1 -1
  107. package/dist/visio/ui/customization.d.ts +46 -0
  108. package/dist/visio/ui/customization.d.ts.map +1 -0
  109. package/dist/visio/ui/index.cjs +454 -316
  110. package/dist/visio/ui/index.d.ts +1 -0
  111. package/dist/visio/ui/index.d.ts.map +1 -1
  112. package/dist/visio/ui/index.mjs +452 -317
  113. package/dist/xlsx/ui/commands.d.ts +2 -0
  114. package/dist/xlsx/ui/commands.d.ts.map +1 -1
  115. package/dist/xlsx/ui/customization.d.ts +49 -0
  116. package/dist/xlsx/ui/customization.d.ts.map +1 -0
  117. package/dist/xlsx/ui/index.cjs +39 -1
  118. package/dist/xlsx/ui/index.d.ts +1 -0
  119. package/dist/xlsx/ui/index.d.ts.map +1 -1
  120. package/dist/xlsx/ui/index.mjs +37 -2
  121. package/package.json +11 -1
  122. package/dist/pptx/chunks/index-CPhsd7Df.d.ts.map +0 -1
  123. package/dist/pptx/chunks/index-Q5mM8kIR.d.ts.map +0 -1
@@ -58139,7 +58139,7 @@ function isValidSpinCount(spinCount, maxSpinCount = DEFAULT_MAX_SPIN_COUNT) {
58139
58139
  const limit3 = Math.min(maxSpinCount, MAX_SPIN_COUNT);
58140
58140
  return spinCount === void 0 || Number.isInteger(spinCount) && spinCount >= 0 && spinCount <= limit3;
58141
58141
  }
58142
- function spinPasswordHash(password, salt, spinCount, digest) {
58142
+ function spinPasswordHash(password, salt, spinCount, digest2) {
58143
58143
  const input2 = new Uint8Array(salt.length + password.length * 2);
58144
58144
  input2.set(salt);
58145
58145
  for (let i2 = 0; i2 < password.length; i2++) {
@@ -58147,21 +58147,21 @@ function spinPasswordHash(password, salt, spinCount, digest) {
58147
58147
  input2[salt.length + i2 * 2] = code & 255;
58148
58148
  input2[salt.length + i2 * 2 + 1] = code >> 8;
58149
58149
  }
58150
- let value3 = digest(input2);
58150
+ let value3 = digest2(input2);
58151
58151
  const buffer = new Uint8Array(value3.length + 4);
58152
58152
  const view = new DataView(buffer.buffer);
58153
58153
  for (let i2 = 0; i2 < spinCount; i2++) {
58154
58154
  buffer.set(value3);
58155
58155
  view.setUint32(value3.length, i2, true);
58156
- value3 = digest(buffer);
58156
+ value3 = digest2(buffer);
58157
58157
  }
58158
58158
  return value3;
58159
58159
  }
58160
58160
  function hashBytes(password, { algorithmName, saltValue, spinCount }, limits) {
58161
- const digest = digestFunction(algorithmName);
58161
+ const digest2 = digestFunction(algorithmName);
58162
58162
  const salt = decodeBase64(saltValue);
58163
- if (!digest || !salt || !isValidSpinCount(spinCount, limits.maxSpinCount)) return void 0;
58164
- return spinPasswordHash(password, salt, spinCount ?? 0, digest);
58163
+ if (!digest2 || !salt || !isValidSpinCount(spinCount, limits.maxSpinCount)) return void 0;
58164
+ return spinPasswordHash(password, salt, spinCount ?? 0, digest2);
58165
58165
  }
58166
58166
  function verifyPasswordHash(password, hash2, limits = {}) {
58167
58167
  if (!digestFunction(hash2.algorithmName)) return void 0;
@@ -61223,6 +61223,7 @@ var VisioPackage = class _VisioPackage {
61223
61223
  relationshipCache = /* @__PURE__ */ new Map();
61224
61224
  byteCache = /* @__PURE__ */ new Map();
61225
61225
  decodedNames = /* @__PURE__ */ new Map();
61226
+ noted;
61226
61227
  totalOutput = 0;
61227
61228
  totalXmlNodes = 0;
61228
61229
  check = () => {
@@ -61257,7 +61258,26 @@ var VisioPackage = class _VisioPackage {
61257
61258
  );
61258
61259
  }
61259
61260
  }
61261
+ /**
61262
+ * Starts noting every part this package is asked about (read, listed in a relationship, or
61263
+ * checked for). The returned function stops noting and gives each part with a print of its
61264
+ * declared CRC-32 and size (empty when absent), which is what {@link printOf} compares.
61265
+ */
61266
+ record() {
61267
+ const noted = /* @__PURE__ */ new Set();
61268
+ this.noted = noted;
61269
+ return () => {
61270
+ if (this.noted === noted) this.noted = void 0;
61271
+ return [...noted].sort().map((path3) => [path3, this.printOf(path3)]);
61272
+ };
61273
+ }
61274
+ /** The declared CRC-32 and size of a part, or an empty string when the package lacks it. */
61275
+ printOf(path3) {
61276
+ const entry3 = this.entries.get(path3);
61277
+ return entry3 && !entry3.directory ? `${entry3.crc}:${entry3.size}` : "";
61278
+ }
61260
61279
  has(path3) {
61280
+ this.noted?.add(path3);
61261
61281
  return this.entries.get(path3)?.directory === false;
61262
61282
  }
61263
61283
  paths() {
@@ -61265,6 +61285,7 @@ var VisioPackage = class _VisioPackage {
61265
61285
  }
61266
61286
  async readXml(path3, expectedRoot) {
61267
61287
  this.check();
61288
+ this.noted?.add(path3);
61268
61289
  safePath(path3);
61269
61290
  let pending2 = this.cache.get(path3);
61270
61291
  if (!pending2) {
@@ -61280,6 +61301,7 @@ var VisioPackage = class _VisioPackage {
61280
61301
  /** Validated declared size, so resource-specific limits can reject before inflation. */
61281
61302
  getPartByteLength(path3) {
61282
61303
  this.check();
61304
+ this.noted?.add(path3);
61283
61305
  safePath(path3);
61284
61306
  const entry3 = this.entries.get(path3);
61285
61307
  if (!entry3 || entry3.directory) fail3("MISSING_PART", `Missing package part: ${path3}`);
@@ -61288,6 +61310,7 @@ var VisioPackage = class _VisioPackage {
61288
61310
  /** Shared package-owned bytes. Treat the returned buffer as immutable. */
61289
61311
  async readBytes(path3) {
61290
61312
  this.check();
61313
+ this.noted?.add(path3);
61291
61314
  safePath(path3);
61292
61315
  let pending2 = this.byteCache.get(path3);
61293
61316
  if (!pending2) {
@@ -61381,6 +61404,10 @@ var VisioPackage = class _VisioPackage {
61381
61404
  }
61382
61405
  async relationships(sourcePart) {
61383
61406
  this.check();
61407
+ if (this.noted && sourcePart) {
61408
+ const slash = sourcePart.lastIndexOf("/");
61409
+ this.noted.add(`${sourcePart.slice(0, slash + 1)}_rels/${sourcePart.slice(slash + 1)}.rels`);
61410
+ } else this.noted?.add("_rels/.rels");
61384
61411
  let pending2 = this.relationshipCache.get(sourcePart);
61385
61412
  if (!pending2) {
61386
61413
  pending2 = this.loadRelationships(sourcePart);
@@ -61414,6 +61441,7 @@ var VisioPackage = class _VisioPackage {
61414
61441
  const actual = mode === "Internal" ? this.decodedNames.get(resolved) : void 0;
61415
61442
  if (mode === "Internal" && !actual)
61416
61443
  fail3("INVALID_RELATIONSHIP", `Missing relationship target: ${resolved}`);
61444
+ if (actual) this.noted?.add(actual);
61417
61445
  result2.set(id4, { id: id4, type, target: actual ?? resolved, mode });
61418
61446
  }
61419
61447
  return result2;
@@ -67768,6 +67796,10 @@ function createLayerBudget() {
67768
67796
  memberships += count3;
67769
67797
  if (memberships > 1e5)
67770
67798
  throw new VisioPackageError("METADATA_LIMIT", "Layer membership budget exceeded.");
67799
+ },
67800
+ state: () => [memberships, characters],
67801
+ restore(state) {
67802
+ [memberships, characters] = state;
67771
67803
  }
67772
67804
  };
67773
67805
  }
@@ -67839,97 +67871,6 @@ function shapeLayers(sheet2, layers, report, budget = createLayerBudget()) {
67839
67871
  };
67840
67872
  }
67841
67873
 
67842
- // visio/theme.ts
67843
- var VISIO_SCHEME_SLOTS = [
67844
- "dk1",
67845
- "lt1",
67846
- "accent1",
67847
- "accent2",
67848
- "accent3",
67849
- "accent4",
67850
- "accent5",
67851
- "accent6"
67852
- ];
67853
- var componentId = (node4) => integer5(themeChild(node4, "schemeID", THEME_NS)?.getAttribute("schemeEnum"));
67854
- async function loadVisioThemes(pkg, source2, report) {
67855
- const result2 = [];
67856
- for (const rel of (await pkg.relationships(source2)).values()) {
67857
- if (rel.type !== "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" || rel.mode === "External")
67858
- continue;
67859
- const root = await pkg.readXml(rel.target, "theme");
67860
- if (root.namespaceURI !== DRAWING_NS) {
67861
- report("unsupported-theme", "A theme uses an unsupported XML namespace.", {
67862
- part: rel.target
67863
- });
67864
- continue;
67865
- }
67866
- const base3 = themeChild(root, "themeElements");
67867
- const palette = themeChild(base3, "clrScheme");
67868
- const scheme = parseTheme(root).colorScheme.colors;
67869
- const colors = /* @__PURE__ */ new Map();
67870
- for (const name4 of VISIO_SCHEME_SLOTS) {
67871
- const color3 = scheme[name4];
67872
- if (color3 && parsedColorChoice(themeChild(palette, name4))) colors.set(name4, color3);
67873
- }
67874
- const background2 = parsedColorChoice(extension(palette, "bkgnd"));
67875
- if (background2) colors.set("bkgnd", background2);
67876
- const variants = themeChildren(
67877
- extension(palette, "variationClrSchemeLst"),
67878
- "variationClrScheme",
67879
- THEME_NS
67880
- ).slice(0, 4).map((variant) => {
67881
- const entries = /* @__PURE__ */ new Map();
67882
- for (let index4 = 1; index4 <= 7; index4++) {
67883
- const choice2 = parsedColorChoice(themeChild(variant, `varColor${index4}`, THEME_NS));
67884
- if (choice2) entries.set(String(index4), choice2);
67885
- }
67886
- return entries;
67887
- });
67888
- const format8 = themeChild(base3, "fmtScheme");
67889
- const connector2 = extension(base3, "fmtConnectorScheme");
67890
- const fonts = extension(base3, "fontStylesGroup");
67891
- const name3 = root.getAttribute("name");
67892
- result2.push({
67893
- ...name3 ? { name: name3.slice(0, 256) } : {},
67894
- colorId: integer5(extension(palette, "schemeID")?.getAttribute("schemeEnum")),
67895
- effectId: componentId(extension(base3, "fmtSchemeEx")),
67896
- connectorId: componentId(extension(base3, "fmtConnectorSchemeEx")),
67897
- colors,
67898
- variants,
67899
- variationStyles: themeChildren(
67900
- extension(base3, "variationStyleSchemeLst"),
67901
- "variationStyleScheme",
67902
- THEME_NS
67903
- ).slice(0, 4).map((variant) => themeChildren(variant, "varStyle", THEME_NS).slice(0, 4)),
67904
- fills: formatList(format8, "fillStyleLst"),
67905
- effects: themeChildren(themeChild(format8, "effectStyleLst"), "effectStyle").slice(0, 6),
67906
- lines: themeChildren(themeChild(format8, "lnStyleLst"), "ln").slice(0, 6),
67907
- fonts: themeChildren(themeChild(fonts, "fontStyles", THEME_NS), "fontProps", THEME_NS).slice(
67908
- 0,
67909
- 6
67910
- ),
67911
- connectorFills: formatList(connector2, "fillStyleLst"),
67912
- connectorEffects: themeChildren(themeChild(connector2, "effectStyleLst"), "effectStyle").slice(
67913
- 0,
67914
- 6
67915
- ),
67916
- connectorLines: themeChildren(themeChild(connector2, "lnStyleLst"), "ln").slice(0, 6),
67917
- connectorFonts: themeChildren(
67918
- themeChild(fonts, "connectorFontStyles", THEME_NS),
67919
- "fontProps",
67920
- THEME_NS
67921
- ).slice(0, 6)
67922
- });
67923
- }
67924
- return result2;
67925
- }
67926
- function formatList(parent, name3) {
67927
- const list2 = themeChild(parent, name3);
67928
- return list2 ? Array.from(list2.childNodes).filter(
67929
- (node4) => node4.nodeType === 1 && node4.namespaceURI === DRAWING_NS
67930
- ).slice(0, 6) : [];
67931
- }
67932
-
67933
67874
  // visio/theme-builtins.ts
67934
67875
  var VISIO_BUILT_IN_THEME_IDS = [
67935
67876
  "office",
@@ -68093,6 +68034,346 @@ function diagnosticCollector(maxCount) {
68093
68034
  };
68094
68035
  }
68095
68036
 
68037
+ // visio/print-settings.ts
68038
+ var NAMES = [
68039
+ "PaperKind",
68040
+ "PrintPageOrientation",
68041
+ "PageLeftMargin",
68042
+ "PageRightMargin",
68043
+ "PageTopMargin",
68044
+ "PageBottomMargin",
68045
+ "ScaleX",
68046
+ "ScaleY",
68047
+ "OnPage",
68048
+ "PagesX",
68049
+ "PagesY",
68050
+ "CenterX",
68051
+ "CenterY"
68052
+ ];
68053
+ var BOOLEAN = /* @__PURE__ */ new Set(["OnPage", "CenterX", "CenterY"]);
68054
+ var LENGTH = /* @__PURE__ */ new Set(["PageLeftMargin", "PageRightMargin", "PageTopMargin", "PageBottomMargin"]);
68055
+ var CANONICAL = new Map(
68056
+ [...NAMES, "PageWidth", "PageHeight", "PageScale", "DrawingScale"].map((name3) => [
68057
+ name3.toLowerCase(),
68058
+ name3
68059
+ ])
68060
+ );
68061
+ function indexCells(sheet2) {
68062
+ const cells3 = /* @__PURE__ */ new Map();
68063
+ let duplicate = false;
68064
+ for (const node4 of children3(sheet2, "Cell")) {
68065
+ const name3 = attribute3(node4, "N") ?? "", canonical3 = CANONICAL.get(name3.toLowerCase());
68066
+ if (!canonical3) continue;
68067
+ if (canonical3 !== name3) duplicate = true;
68068
+ const values2 = cells3.get(canonical3) ?? [];
68069
+ if (values2.length < 2) values2.push(node4);
68070
+ cells3.set(canonical3, values2);
68071
+ if (values2.length > 1) duplicate = true;
68072
+ }
68073
+ return { cells: cells3, duplicate };
68074
+ }
68075
+ function createVisioPrintSettingsReader(documentSheets, rootStyles) {
68076
+ const indexes2 = { document: indexCells(documentSheets[0]), root: indexCells(rootStyles[0]) };
68077
+ return (pageSheets) => readVisioPrintCountSettings(pageSheets, documentSheets, rootStyles, indexes2);
68078
+ }
68079
+ function readVisioPrintCountSettings(pageSheets, documentSheets, rootStyles, indexes2) {
68080
+ let refusal;
68081
+ const refuse4 = (reason) => {
68082
+ refusal ??= reason;
68083
+ };
68084
+ if (pageSheets.length !== 1) refuse4("ambiguous-page-sheet");
68085
+ if (documentSheets.length > 1) refuse4("ambiguous-document-sheet");
68086
+ if (!documentSheets.length) refuse4("missing-setting");
68087
+ if (rootStyles.length > 1) refuse4("duplicate-setting");
68088
+ const root = rootStyles[0];
68089
+ if (!root || attribute3(root, "ID") !== "0" || attribute3(root, "NameU") !== "No Style")
68090
+ refuse4("unsupported-print-style");
68091
+ for (const sheet2 of [...pageSheets, ...documentSheets])
68092
+ for (const name3 of ["LineStyle", "FillStyle", "TextStyle"])
68093
+ if (attribute3(sheet2, name3) !== "0") refuse4("unsupported-print-style");
68094
+ for (const name3 of ["LineStyle", "FillStyle", "TextStyle"])
68095
+ if (attribute3(root, name3) !== void 0) refuse4("unsupported-print-style");
68096
+ const localIndex = indexCells(pageSheets[0]), rootIndex = indexes2?.root ?? indexCells(root);
68097
+ const documentIndex = indexes2?.document ?? indexCells(documentSheets[0]);
68098
+ if (localIndex.duplicate || rootIndex.duplicate || documentIndex.duplicate)
68099
+ refuse4("duplicate-setting");
68100
+ const local = localIndex.cells, inherited = rootIndex.cells;
68101
+ const read = (node4, name3, origin) => {
68102
+ const invalid3 = () => {
68103
+ refuse4(origin === "local" ? "invalid-local-setting" : "invalid-document-setting");
68104
+ return void 0;
68105
+ };
68106
+ if (node4.hasAttribute("E")) return invalid3();
68107
+ let raw2 = (attribute3(node4, "V") ?? "").trim();
68108
+ if (!raw2 || raw2.length > 128) return invalid3();
68109
+ if (BOOLEAN.has(name3)) {
68110
+ if (!["0", "1", "false", "true"].includes(raw2)) return invalid3();
68111
+ raw2 = raw2 === "true" ? "1" : raw2 === "false" ? "0" : raw2;
68112
+ }
68113
+ try {
68114
+ const value3 = visioFormulaCachedValue(raw2, attribute3(node4, "U"));
68115
+ const length = LENGTH.has(name3) || /^(PageWidth|PageHeight|PageScale|DrawingScale)$/.test(name3);
68116
+ if (!["scalar", ...length ? ["length"] : []].includes(value3.unit) || Math.abs(value3.value) > 1e9)
68117
+ return invalid3();
68118
+ const formula = attribute3(node4, "F");
68119
+ if (formula !== void 0) {
68120
+ const source2 = formula.trim();
68121
+ if (/^(true|false)$/i.test(source2)) {
68122
+ if ((source2.toLowerCase() === "true" ? 1 : 0) !== value3.value) return invalid3();
68123
+ } else {
68124
+ if (!source2 || source2 === "Inh") return invalid3();
68125
+ const limits = { maxLength: 512, maxNodes: 64, maxDepth: 16, maxSteps: 128 };
68126
+ const analysis = analyzeVisioFormula(source2, limits);
68127
+ if (analysis.dynamic || analysis.guarded || analysis.references.length || analysis.unsupportedFunctions.length) {
68128
+ refuse4("dynamic-setting");
68129
+ return void 0;
68130
+ }
68131
+ const evaluated = evaluateVisioFormula(
68132
+ source2,
68133
+ () => {
68134
+ throw new Error("Unexpected reference");
68135
+ },
68136
+ limits
68137
+ );
68138
+ if (evaluated.value !== value3.value || !["scalar", ...length ? ["length"] : []].includes(evaluated.unit))
68139
+ return invalid3();
68140
+ }
68141
+ }
68142
+ return value3.value;
68143
+ } catch {
68144
+ return invalid3();
68145
+ }
68146
+ };
68147
+ const values2 = /* @__PURE__ */ new Map();
68148
+ for (const name3 of NAMES) {
68149
+ const nodes = local.get(name3) ?? inherited.get(name3);
68150
+ if (!nodes?.length) continue;
68151
+ if (nodes.length !== 1) continue;
68152
+ const value3 = read(nodes[0], name3, local.has(name3) ? "local" : "document");
68153
+ if (value3 !== void 0) values2.set(name3, value3);
68154
+ }
68155
+ for (const name3 of ["PageWidth", "PageHeight", "PageScale", "DrawingScale"]) {
68156
+ const nodes = local.get(name3);
68157
+ if (!nodes || nodes.length !== 1 || !(read(nodes[0], name3, "local") > 0))
68158
+ refuse4("unusable-drawing-scale");
68159
+ }
68160
+ const setup = {};
68161
+ const paper = values2.get("PaperKind");
68162
+ if (paper !== void 0 && Number.isSafeInteger(paper) && paper >= 0 && paper <= 65535)
68163
+ setup.paperKind = paper;
68164
+ else if (paper !== void 0)
68165
+ refuse4(local.has("PaperKind") ? "invalid-local-setting" : "invalid-document-setting");
68166
+ const orientation = values2.get("PrintPageOrientation");
68167
+ if (orientation === 0 || orientation === 1 || orientation === 2)
68168
+ setup.printPageOrientation = orientation;
68169
+ else if (orientation !== void 0)
68170
+ refuse4(
68171
+ local.has("PrintPageOrientation") ? "invalid-local-setting" : "invalid-document-setting"
68172
+ );
68173
+ const margins = ["Left", "Right", "Top", "Bottom"].map((side2) => values2.get(`Page${side2}Margin`));
68174
+ if (margins.every((n) => n !== void 0 && n >= 0 && n <= 1e3))
68175
+ setup.margins = {
68176
+ left: margins[0],
68177
+ right: margins[1],
68178
+ top: margins[2],
68179
+ bottom: margins[3]
68180
+ };
68181
+ else if (margins.some((n) => n !== void 0 && (n < 0 || n > 1e3)))
68182
+ refuse4("unusable-print-area");
68183
+ for (const [name3, key2] of [
68184
+ ["ScaleX", "printZoom"],
68185
+ ["ScaleY", "printZoomY"],
68186
+ ["PagesX", "printPagesAcross"],
68187
+ ["PagesY", "printPagesDown"]
68188
+ ]) {
68189
+ const value3 = values2.get(name3);
68190
+ if (value3 !== void 0) {
68191
+ if ((name3 === "PagesX" || name3 === "PagesY") && (!Number.isSafeInteger(value3) || value3 < 1))
68192
+ refuse4(local.has(name3) ? "invalid-local-setting" : "invalid-document-setting");
68193
+ else setup[key2] = value3;
68194
+ }
68195
+ }
68196
+ for (const [name3, key2] of [
68197
+ ["OnPage", "printFitToPages"],
68198
+ ["CenterX", "printCenterX"],
68199
+ ["CenterY", "printCenterY"]
68200
+ ]) {
68201
+ const value3 = values2.get(name3);
68202
+ if (value3 !== void 0) setup[key2] = value3 === 1;
68203
+ }
68204
+ if (refusal) setup.printCountRefusal = refusal;
68205
+ return setup;
68206
+ }
68207
+
68208
+ // visio/theme.ts
68209
+ var VISIO_SCHEME_SLOTS = [
68210
+ "dk1",
68211
+ "lt1",
68212
+ "accent1",
68213
+ "accent2",
68214
+ "accent3",
68215
+ "accent4",
68216
+ "accent5",
68217
+ "accent6"
68218
+ ];
68219
+ var componentId = (node4) => integer5(themeChild(node4, "schemeID", THEME_NS)?.getAttribute("schemeEnum"));
68220
+ async function loadVisioThemes(pkg, source2, report) {
68221
+ const result2 = [];
68222
+ for (const rel of (await pkg.relationships(source2)).values()) {
68223
+ if (rel.type !== "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" || rel.mode === "External")
68224
+ continue;
68225
+ const root = await pkg.readXml(rel.target, "theme");
68226
+ if (root.namespaceURI !== DRAWING_NS) {
68227
+ report("unsupported-theme", "A theme uses an unsupported XML namespace.", {
68228
+ part: rel.target
68229
+ });
68230
+ continue;
68231
+ }
68232
+ const base3 = themeChild(root, "themeElements");
68233
+ const palette = themeChild(base3, "clrScheme");
68234
+ const scheme = parseTheme(root).colorScheme.colors;
68235
+ const colors = /* @__PURE__ */ new Map();
68236
+ for (const name4 of VISIO_SCHEME_SLOTS) {
68237
+ const color3 = scheme[name4];
68238
+ if (color3 && parsedColorChoice(themeChild(palette, name4))) colors.set(name4, color3);
68239
+ }
68240
+ const background2 = parsedColorChoice(extension(palette, "bkgnd"));
68241
+ if (background2) colors.set("bkgnd", background2);
68242
+ const variants = themeChildren(
68243
+ extension(palette, "variationClrSchemeLst"),
68244
+ "variationClrScheme",
68245
+ THEME_NS
68246
+ ).slice(0, 4).map((variant) => {
68247
+ const entries = /* @__PURE__ */ new Map();
68248
+ for (let index4 = 1; index4 <= 7; index4++) {
68249
+ const choice2 = parsedColorChoice(themeChild(variant, `varColor${index4}`, THEME_NS));
68250
+ if (choice2) entries.set(String(index4), choice2);
68251
+ }
68252
+ return entries;
68253
+ });
68254
+ const format8 = themeChild(base3, "fmtScheme");
68255
+ const connector2 = extension(base3, "fmtConnectorScheme");
68256
+ const fonts = extension(base3, "fontStylesGroup");
68257
+ const name3 = root.getAttribute("name");
68258
+ result2.push({
68259
+ ...name3 ? { name: name3.slice(0, 256) } : {},
68260
+ colorId: integer5(extension(palette, "schemeID")?.getAttribute("schemeEnum")),
68261
+ effectId: componentId(extension(base3, "fmtSchemeEx")),
68262
+ connectorId: componentId(extension(base3, "fmtConnectorSchemeEx")),
68263
+ colors,
68264
+ variants,
68265
+ variationStyles: themeChildren(
68266
+ extension(base3, "variationStyleSchemeLst"),
68267
+ "variationStyleScheme",
68268
+ THEME_NS
68269
+ ).slice(0, 4).map((variant) => themeChildren(variant, "varStyle", THEME_NS).slice(0, 4)),
68270
+ fills: formatList(format8, "fillStyleLst"),
68271
+ effects: themeChildren(themeChild(format8, "effectStyleLst"), "effectStyle").slice(0, 6),
68272
+ lines: themeChildren(themeChild(format8, "lnStyleLst"), "ln").slice(0, 6),
68273
+ fonts: themeChildren(themeChild(fonts, "fontStyles", THEME_NS), "fontProps", THEME_NS).slice(
68274
+ 0,
68275
+ 6
68276
+ ),
68277
+ connectorFills: formatList(connector2, "fillStyleLst"),
68278
+ connectorEffects: themeChildren(themeChild(connector2, "effectStyleLst"), "effectStyle").slice(
68279
+ 0,
68280
+ 6
68281
+ ),
68282
+ connectorLines: themeChildren(themeChild(connector2, "lnStyleLst"), "ln").slice(0, 6),
68283
+ connectorFonts: themeChildren(
68284
+ themeChild(fonts, "connectorFontStyles", THEME_NS),
68285
+ "fontProps",
68286
+ THEME_NS
68287
+ ).slice(0, 6)
68288
+ });
68289
+ }
68290
+ return result2;
68291
+ }
68292
+ function formatList(parent, name3) {
68293
+ const list2 = themeChild(parent, name3);
68294
+ return list2 ? Array.from(list2.childNodes).filter(
68295
+ (node4) => node4.nodeType === 1 && node4.namespaceURI === DRAWING_NS
68296
+ ).slice(0, 6) : [];
68297
+ }
68298
+
68299
+ // visio/document-level.ts
68300
+ function optionsKey(options2) {
68301
+ const { metafileConverter: _converter, pages: _pages, documentCache: _cache, ...rest } = options2;
68302
+ return JSON.stringify(rest);
68303
+ }
68304
+ var cacheMatches = (entry3, pkg, options2) => entry3 !== void 0 && entry3.options === optionsKey(options2) && entry3.converter === options2.metafileConverter && entry3.reads.every(([path3, print]) => pkg.printOf(path3) === print);
68305
+ async function readDocumentLevel(pkg, documentPart, options2, checkTime, forward) {
68306
+ const reports = [];
68307
+ const report = (...args) => {
68308
+ reports.push(args);
68309
+ forward(...args);
68310
+ };
68311
+ const documentRoot = await visioXml(pkg, documentPart, "VisioDocument");
68312
+ const resources = {
68313
+ colors: /* @__PURE__ */ new Map(),
68314
+ fonts: /* @__PURE__ */ new Map(),
68315
+ themes: await loadVisioThemes(pkg, documentPart, report)
68316
+ };
68317
+ for (const color3 of children3(child6(documentRoot, "Colors"), "ColorEntry"))
68318
+ resources.colors.set(attribute3(color3, "IX") ?? "", attribute3(color3, "RGB") ?? "");
68319
+ const faceNames = children3(child6(documentRoot, "FaceNames"), "FaceName");
68320
+ if (faceNames.length > 1e4)
68321
+ throw new VisioPackageError(
68322
+ "METADATA_LIMIT",
68323
+ "Document font count exceeds its metadata limit."
68324
+ );
68325
+ let fontCharacters = 0;
68326
+ faceNames.forEach((font, index4) => {
68327
+ checkTime();
68328
+ fontCharacters += (attribute3(font, "Name") ?? attribute3(font, "NameU") ?? "Arial").length;
68329
+ if (fontCharacters > 1e6)
68330
+ throw new VisioPackageError(
68331
+ "METADATA_LIMIT",
68332
+ "Document fonts exceed aggregate metadata limits."
68333
+ );
68334
+ resources.fonts.set(
68335
+ metadata(attribute3(font, "ID") ?? String(index4), 256, "Font ID"),
68336
+ metadata(attribute3(font, "Name") ?? attribute3(font, "NameU") ?? "Arial", 1024, "Font name")
68337
+ );
68338
+ });
68339
+ const styles = /* @__PURE__ */ new Map();
68340
+ for (const style3 of children3(child6(documentRoot, "StyleSheets"), "StyleSheet"))
68341
+ styles.set(metadata(attribute3(style3, "ID") ?? "", 256, "Style ID"), {
68342
+ sheet: readSheet(style3),
68343
+ attributes: metadataAttributes(style3)
68344
+ });
68345
+ const rootStyle = styles.get("0");
68346
+ if (rootStyle?.attributes.get("NameU") === "No Style") resources.rootSheet = rootStyle.sheet;
68347
+ const printStyleGroups = children3(documentRoot, "StyleSheets");
68348
+ const readPrintSettings = createVisioPrintSettingsReader(
68349
+ children3(documentRoot, "DocumentSheet"),
68350
+ printStyleGroups.length === 1 ? children3(printStyleGroups[0], "StyleSheet").filter((node4) => attribute3(node4, "ID") === "0") : []
68351
+ );
68352
+ const masters = /* @__PURE__ */ new Map();
68353
+ const masterRecords = [];
68354
+ const mastersPart = await related(pkg, documentPart, "masters", false);
68355
+ if (mastersPart) {
68356
+ for (const master2 of children3(await visioXml(pkg, mastersPart, "Masters"), "Master")) {
68357
+ const part = await indexedPart(pkg, mastersPart, master2, "master");
68358
+ const id4 = metadata(attribute3(master2, "ID") ?? "", 256, "Master ID");
68359
+ if (!id4 || masters.has(id4))
68360
+ throw new VisioPackageError("INVALID_MASTER_ID", "Master IDs must be present and unique.");
68361
+ const masterShapes2 = readShapes(await visioXml(pkg, part, "MasterContents"));
68362
+ await prepareImages(
68363
+ masterShapes2,
68364
+ pkg,
68365
+ part,
68366
+ report,
68367
+ options2.images,
68368
+ options2.metafileConverter
68369
+ );
68370
+ masters.set(id4, masterShapes2);
68371
+ masterRecords.push({ id: id4, node: master2, shapes: masterShapes2 });
68372
+ }
68373
+ }
68374
+ return { documentRoot, resources, styles, readPrintSettings, masters, masterRecords, reports };
68375
+ }
68376
+
68096
68377
  // visio/comments.ts
68097
68378
  var VISIO_COMMENTS_CONTENT_TYPE = "application/vnd.ms-visio.comments+xml";
68098
68379
  var VISIO_COMMENTS_RELATIONSHIP = "http://schemas.microsoft.com/visio/2010/relationships/comments";
@@ -68193,6 +68474,10 @@ function createMetadataBudget(options2 = {}) {
68193
68474
  if (characters > maxCharacters)
68194
68475
  throw new VisioPackageError("METADATA_LIMIT", "Shape metadata character budget exceeded.");
68195
68476
  return value3;
68477
+ },
68478
+ state: () => [rows, characters],
68479
+ restore(state) {
68480
+ [rows, characters] = state;
68196
68481
  }
68197
68482
  };
68198
68483
  }
@@ -69313,177 +69598,6 @@ function readVisioPageSetup(cells3) {
69313
69598
  return Object.keys(result2).length ? result2 : void 0;
69314
69599
  }
69315
69600
 
69316
- // visio/print-settings.ts
69317
- var NAMES = [
69318
- "PaperKind",
69319
- "PrintPageOrientation",
69320
- "PageLeftMargin",
69321
- "PageRightMargin",
69322
- "PageTopMargin",
69323
- "PageBottomMargin",
69324
- "ScaleX",
69325
- "ScaleY",
69326
- "OnPage",
69327
- "PagesX",
69328
- "PagesY",
69329
- "CenterX",
69330
- "CenterY"
69331
- ];
69332
- var BOOLEAN = /* @__PURE__ */ new Set(["OnPage", "CenterX", "CenterY"]);
69333
- var LENGTH = /* @__PURE__ */ new Set(["PageLeftMargin", "PageRightMargin", "PageTopMargin", "PageBottomMargin"]);
69334
- var CANONICAL = new Map(
69335
- [...NAMES, "PageWidth", "PageHeight", "PageScale", "DrawingScale"].map((name3) => [
69336
- name3.toLowerCase(),
69337
- name3
69338
- ])
69339
- );
69340
- function indexCells(sheet2) {
69341
- const cells3 = /* @__PURE__ */ new Map();
69342
- let duplicate = false;
69343
- for (const node4 of children3(sheet2, "Cell")) {
69344
- const name3 = attribute3(node4, "N") ?? "", canonical3 = CANONICAL.get(name3.toLowerCase());
69345
- if (!canonical3) continue;
69346
- if (canonical3 !== name3) duplicate = true;
69347
- const values2 = cells3.get(canonical3) ?? [];
69348
- if (values2.length < 2) values2.push(node4);
69349
- cells3.set(canonical3, values2);
69350
- if (values2.length > 1) duplicate = true;
69351
- }
69352
- return { cells: cells3, duplicate };
69353
- }
69354
- function createVisioPrintSettingsReader(documentSheets, rootStyles) {
69355
- const indexes2 = { document: indexCells(documentSheets[0]), root: indexCells(rootStyles[0]) };
69356
- return (pageSheets) => readVisioPrintCountSettings(pageSheets, documentSheets, rootStyles, indexes2);
69357
- }
69358
- function readVisioPrintCountSettings(pageSheets, documentSheets, rootStyles, indexes2) {
69359
- let refusal;
69360
- const refuse4 = (reason) => {
69361
- refusal ??= reason;
69362
- };
69363
- if (pageSheets.length !== 1) refuse4("ambiguous-page-sheet");
69364
- if (documentSheets.length > 1) refuse4("ambiguous-document-sheet");
69365
- if (!documentSheets.length) refuse4("missing-setting");
69366
- if (rootStyles.length > 1) refuse4("duplicate-setting");
69367
- const root = rootStyles[0];
69368
- if (!root || attribute3(root, "ID") !== "0" || attribute3(root, "NameU") !== "No Style")
69369
- refuse4("unsupported-print-style");
69370
- for (const sheet2 of [...pageSheets, ...documentSheets])
69371
- for (const name3 of ["LineStyle", "FillStyle", "TextStyle"])
69372
- if (attribute3(sheet2, name3) !== "0") refuse4("unsupported-print-style");
69373
- for (const name3 of ["LineStyle", "FillStyle", "TextStyle"])
69374
- if (attribute3(root, name3) !== void 0) refuse4("unsupported-print-style");
69375
- const localIndex = indexCells(pageSheets[0]), rootIndex = indexes2?.root ?? indexCells(root);
69376
- const documentIndex = indexes2?.document ?? indexCells(documentSheets[0]);
69377
- if (localIndex.duplicate || rootIndex.duplicate || documentIndex.duplicate)
69378
- refuse4("duplicate-setting");
69379
- const local = localIndex.cells, inherited = rootIndex.cells;
69380
- const read = (node4, name3, origin) => {
69381
- const invalid3 = () => {
69382
- refuse4(origin === "local" ? "invalid-local-setting" : "invalid-document-setting");
69383
- return void 0;
69384
- };
69385
- if (node4.hasAttribute("E")) return invalid3();
69386
- let raw2 = (attribute3(node4, "V") ?? "").trim();
69387
- if (!raw2 || raw2.length > 128) return invalid3();
69388
- if (BOOLEAN.has(name3)) {
69389
- if (!["0", "1", "false", "true"].includes(raw2)) return invalid3();
69390
- raw2 = raw2 === "true" ? "1" : raw2 === "false" ? "0" : raw2;
69391
- }
69392
- try {
69393
- const value3 = visioFormulaCachedValue(raw2, attribute3(node4, "U"));
69394
- const length = LENGTH.has(name3) || /^(PageWidth|PageHeight|PageScale|DrawingScale)$/.test(name3);
69395
- if (!["scalar", ...length ? ["length"] : []].includes(value3.unit) || Math.abs(value3.value) > 1e9)
69396
- return invalid3();
69397
- const formula = attribute3(node4, "F");
69398
- if (formula !== void 0) {
69399
- const source2 = formula.trim();
69400
- if (/^(true|false)$/i.test(source2)) {
69401
- if ((source2.toLowerCase() === "true" ? 1 : 0) !== value3.value) return invalid3();
69402
- } else {
69403
- if (!source2 || source2 === "Inh") return invalid3();
69404
- const limits = { maxLength: 512, maxNodes: 64, maxDepth: 16, maxSteps: 128 };
69405
- const analysis = analyzeVisioFormula(source2, limits);
69406
- if (analysis.dynamic || analysis.guarded || analysis.references.length || analysis.unsupportedFunctions.length) {
69407
- refuse4("dynamic-setting");
69408
- return void 0;
69409
- }
69410
- const evaluated = evaluateVisioFormula(
69411
- source2,
69412
- () => {
69413
- throw new Error("Unexpected reference");
69414
- },
69415
- limits
69416
- );
69417
- if (evaluated.value !== value3.value || !["scalar", ...length ? ["length"] : []].includes(evaluated.unit))
69418
- return invalid3();
69419
- }
69420
- }
69421
- return value3.value;
69422
- } catch {
69423
- return invalid3();
69424
- }
69425
- };
69426
- const values2 = /* @__PURE__ */ new Map();
69427
- for (const name3 of NAMES) {
69428
- const nodes = local.get(name3) ?? inherited.get(name3);
69429
- if (!nodes?.length) continue;
69430
- if (nodes.length !== 1) continue;
69431
- const value3 = read(nodes[0], name3, local.has(name3) ? "local" : "document");
69432
- if (value3 !== void 0) values2.set(name3, value3);
69433
- }
69434
- for (const name3 of ["PageWidth", "PageHeight", "PageScale", "DrawingScale"]) {
69435
- const nodes = local.get(name3);
69436
- if (!nodes || nodes.length !== 1 || !(read(nodes[0], name3, "local") > 0))
69437
- refuse4("unusable-drawing-scale");
69438
- }
69439
- const setup = {};
69440
- const paper = values2.get("PaperKind");
69441
- if (paper !== void 0 && Number.isSafeInteger(paper) && paper >= 0 && paper <= 65535)
69442
- setup.paperKind = paper;
69443
- else if (paper !== void 0)
69444
- refuse4(local.has("PaperKind") ? "invalid-local-setting" : "invalid-document-setting");
69445
- const orientation = values2.get("PrintPageOrientation");
69446
- if (orientation === 0 || orientation === 1 || orientation === 2)
69447
- setup.printPageOrientation = orientation;
69448
- else if (orientation !== void 0)
69449
- refuse4(
69450
- local.has("PrintPageOrientation") ? "invalid-local-setting" : "invalid-document-setting"
69451
- );
69452
- const margins = ["Left", "Right", "Top", "Bottom"].map((side2) => values2.get(`Page${side2}Margin`));
69453
- if (margins.every((n) => n !== void 0 && n >= 0 && n <= 1e3))
69454
- setup.margins = {
69455
- left: margins[0],
69456
- right: margins[1],
69457
- top: margins[2],
69458
- bottom: margins[3]
69459
- };
69460
- else if (margins.some((n) => n !== void 0 && (n < 0 || n > 1e3)))
69461
- refuse4("unusable-print-area");
69462
- for (const [name3, key2] of [
69463
- ["ScaleX", "printZoom"],
69464
- ["ScaleY", "printZoomY"],
69465
- ["PagesX", "printPagesAcross"],
69466
- ["PagesY", "printPagesDown"]
69467
- ]) {
69468
- const value3 = values2.get(name3);
69469
- if (value3 !== void 0) {
69470
- if ((name3 === "PagesX" || name3 === "PagesY") && (!Number.isSafeInteger(value3) || value3 < 1))
69471
- refuse4(local.has(name3) ? "invalid-local-setting" : "invalid-document-setting");
69472
- else setup[key2] = value3;
69473
- }
69474
- }
69475
- for (const [name3, key2] of [
69476
- ["OnPage", "printFitToPages"],
69477
- ["CenterX", "printCenterX"],
69478
- ["CenterY", "printCenterY"]
69479
- ]) {
69480
- const value3 = values2.get(name3);
69481
- if (value3 !== void 0) setup[key2] = value3 === 1;
69482
- }
69483
- if (refusal) setup.printCountRefusal = refusal;
69484
- return setup;
69485
- }
69486
-
69487
69601
  // visio/page-layout.ts
69488
69602
  var VISIO_GRID_DENSITIES = Object.freeze([0, 2, 4, 8]);
69489
69603
  var VISIO_RULER_DENSITIES = Object.freeze([8, 16, 32]);
@@ -69786,69 +69900,18 @@ async function parseVsdx(input2, options2 = {}) {
69786
69900
  );
69787
69901
  }
69788
69902
  }
69789
- const documentRoot = await visioXml(pkg, documentPart, "VisioDocument");
69790
- const resources = {
69791
- colors: /* @__PURE__ */ new Map(),
69792
- fonts: /* @__PURE__ */ new Map(),
69793
- themes: await loadVisioThemes(pkg, documentPart, report)
69794
- };
69795
- for (const color3 of children3(child6(documentRoot, "Colors"), "ColorEntry"))
69796
- resources.colors.set(attribute3(color3, "IX") ?? "", attribute3(color3, "RGB") ?? "");
69797
- const faceNames = children3(child6(documentRoot, "FaceNames"), "FaceName");
69798
- if (faceNames.length > 1e4)
69799
- throw new VisioPackageError(
69800
- "METADATA_LIMIT",
69801
- "Document font count exceeds its metadata limit."
69802
- );
69803
- let fontCharacters = 0;
69804
- faceNames.forEach((font, index4) => {
69805
- checkTime();
69806
- fontCharacters += (attribute3(font, "Name") ?? attribute3(font, "NameU") ?? "Arial").length;
69807
- if (fontCharacters > 1e6)
69808
- throw new VisioPackageError(
69809
- "METADATA_LIMIT",
69810
- "Document fonts exceed aggregate metadata limits."
69811
- );
69812
- resources.fonts.set(
69813
- metadata(attribute3(font, "ID") ?? String(index4), 256, "Font ID"),
69814
- metadata(attribute3(font, "Name") ?? attribute3(font, "NameU") ?? "Arial", 1024, "Font name")
69815
- );
69816
- });
69817
- const styles = /* @__PURE__ */ new Map();
69818
- for (const style3 of children3(child6(documentRoot, "StyleSheets"), "StyleSheet"))
69819
- styles.set(metadata(attribute3(style3, "ID") ?? "", 256, "Style ID"), {
69820
- sheet: readSheet(style3),
69821
- attributes: metadataAttributes(style3)
69822
- });
69823
- const rootStyle = styles.get("0");
69824
- if (rootStyle?.attributes.get("NameU") === "No Style") resources.rootSheet = rootStyle.sheet;
69825
- const printStyleGroups = children3(documentRoot, "StyleSheets");
69826
- const readPrintSettings = createVisioPrintSettingsReader(
69827
- children3(documentRoot, "DocumentSheet"),
69828
- printStyleGroups.length === 1 ? children3(printStyleGroups[0], "StyleSheet").filter((node4) => attribute3(node4, "ID") === "0") : []
69829
- );
69830
- const masters = /* @__PURE__ */ new Map();
69831
- const masterRecords = [];
69832
- const mastersPart = await related(pkg, documentPart, "masters", false);
69833
- if (mastersPart) {
69834
- for (const master2 of children3(await visioXml(pkg, mastersPart, "Masters"), "Master")) {
69835
- const part = await indexedPart(pkg, mastersPart, master2, "master");
69836
- const id4 = metadata(attribute3(master2, "ID") ?? "", 256, "Master ID");
69837
- if (!id4 || masters.has(id4))
69838
- throw new VisioPackageError("INVALID_MASTER_ID", "Master IDs must be present and unique.");
69839
- const masterShapes2 = readShapes(await visioXml(pkg, part, "MasterContents"));
69840
- await prepareImages(
69841
- masterShapes2,
69842
- pkg,
69843
- part,
69844
- report,
69845
- options2.images,
69846
- options2.metafileConverter
69847
- );
69848
- masters.set(id4, masterShapes2);
69849
- masterRecords.push({ id: id4, node: master2, shapes: masterShapes2 });
69850
- }
69851
- }
69903
+ const cache3 = options2.documentCache;
69904
+ const cached7 = cacheMatches(cache3?.entry, pkg, options2) ? cache3.entry : void 0;
69905
+ const stopRecording = cache3 && !cached7 ? pkg.record() : void 0;
69906
+ let level2;
69907
+ if (cached7) {
69908
+ level2 = cached7.level;
69909
+ for (const args of level2.reports) report(...args);
69910
+ } else level2 = await readDocumentLevel(pkg, documentPart, options2, checkTime, report);
69911
+ const { documentRoot, styles, readPrintSettings, masters, masterRecords } = level2;
69912
+ const resources = { ...level2.resources };
69913
+ delete resources.pageCells;
69914
+ delete resources.fieldContext;
69852
69915
  let geometryCount = 0, textCount = 0, expansionCount = 0, textRuns = 0, paragraphCount = 0;
69853
69916
  const context = {
69854
69917
  metadataBudget: createMetadataBudget(options2.metadata),
@@ -69902,10 +69965,46 @@ async function parseVsdx(input2, options2 = {}) {
69902
69965
  throw new VisioPackageError("TEXT_LIMIT", "Text character limit exceeded.");
69903
69966
  }
69904
69967
  };
69905
- const documentMasters = listVisioMasters(masterRecords, context, {
69906
- metadataBudget: createMetadataBudget(options2.metadata),
69907
- layerBudget: createLayerBudget()
69908
- });
69968
+ let documentMasters;
69969
+ if (cached7) {
69970
+ const { counters } = cached7.listed;
69971
+ curveWork = counters.curveWork;
69972
+ geometryCount = counters.geometry;
69973
+ textCount = counters.text;
69974
+ expansionCount = counters.expansion;
69975
+ textRuns = counters.textRuns;
69976
+ paragraphCount = counters.paragraphs;
69977
+ context.shapeCount = counters.shapes;
69978
+ context.metadataBudget.restore(counters.metadata);
69979
+ context.layerBudget.restore(counters.layers);
69980
+ documentMasters = cached7.listed.documentMasters;
69981
+ } else {
69982
+ documentMasters = listVisioMasters(masterRecords, context, {
69983
+ metadataBudget: createMetadataBudget(options2.metadata),
69984
+ layerBudget: createLayerBudget()
69985
+ });
69986
+ if (cache3 && stopRecording)
69987
+ cache3.entry = {
69988
+ options: optionsKey(options2),
69989
+ converter: options2.metafileConverter,
69990
+ reads: stopRecording(),
69991
+ level: { ...level2, resources: { ...resources } },
69992
+ listed: {
69993
+ documentMasters,
69994
+ counters: {
69995
+ curveWork,
69996
+ geometry: geometryCount,
69997
+ text: textCount,
69998
+ expansion: expansionCount,
69999
+ textRuns,
70000
+ paragraphs: paragraphCount,
70001
+ shapes: context.shapeCount,
70002
+ metadata: context.metadataBudget.state(),
70003
+ layers: context.layerBudget.state()
70004
+ }
70005
+ }
70006
+ };
70007
+ }
69909
70008
  const pagesPart = await related(pkg, documentPart, "pages", !options2.stencil);
69910
70009
  if (!pagesPart && !options2.stencil)
69911
70010
  throw new VisioPackageError("INVALID_DOCUMENT", "Missing Visio pages part.");
@@ -107509,4 +107608,121 @@ function findAutomationTool(name3) {
107509
107608
  return void 0;
107510
107609
  }
107511
107610
 
107512
- export { UNTRUSTED_NOTE, XLSX_EDIT_LIMITS, applyXlsxEdits, applyXlsxProposal, automationTools, checkEditProposal, createDocx, createDocxFromOutline, createEditProposal, createXlsx, createXlsxFromSheets, documentDigest, docxTools, editVsdx as editVisio, fillDocxFormFields, findAutomationTool, findXlsxCells, inspectDocx, inspectVisio, inspectXlsx, listDocxFormFields, proposeXlsxEdits, readXlsxFilledCells, readXlsxRange, readXlsxTable, setDocxRunText, setXlsxCells, suggestDocxRunText, visioTools, xlsxTools };
107611
+ // automation/live.ts
107612
+ var digest = (bytes) => Array.from(sha256(bytes), (byte) => byte.toString(16).padStart(2, "0")).join("");
107613
+ function createLiveToolHost(tools, options2 = {}) {
107614
+ const editors = /* @__PURE__ */ new Map();
107615
+ const serve = tools.filter((tool) => tool.kind !== "create");
107616
+ const queues = /* @__PURE__ */ new Map();
107617
+ function editorFor(target3) {
107618
+ if (typeof target3 !== "string" || target3 === "")
107619
+ throw new Error("Every call needs a target: the id of the document to act on.");
107620
+ const editor = editors.get(target3);
107621
+ if (!editor) throw new Error(`No open document is registered as "${target3}".`);
107622
+ return editor;
107623
+ }
107624
+ async function run2(name3, call) {
107625
+ const tool = serve.find((candidate) => candidate.name === name3);
107626
+ if (!tool) throw new Error(`Unknown tool "${name3}".`);
107627
+ const editor = editorFor(call?.target);
107628
+ const target3 = call.target;
107629
+ if (tool.format !== editor.format)
107630
+ throw new Error(
107631
+ `${name3} works on ${tool.format} documents, but "${target3}" is a ${editor.format} document.`
107632
+ );
107633
+ const before = new Uint8Array(await editor.save());
107634
+ if (tool.kind === "read")
107635
+ return { target: target3, tool: name3, result: await tool.run(before, call.params), changed: false };
107636
+ if (editor.readOnly) throw new Error(`"${target3}" is read-only, so it cannot be edited.`);
107637
+ const { bytes: after, ...result2 } = await tool.run(before, call.params);
107638
+ if (!after) return { target: target3, tool: name3, result: result2, changed: false };
107639
+ if (options2.review) {
107640
+ const accepted = await options2.review({
107641
+ target: target3,
107642
+ tool: name3,
107643
+ params: call.params,
107644
+ result: result2,
107645
+ before,
107646
+ after
107647
+ });
107648
+ if (!accepted)
107649
+ return { target: target3, tool: name3, result: { ...result2, discarded: true }, changed: false };
107650
+ }
107651
+ if (editor.readOnly)
107652
+ throw new Error(`"${target3}" became read-only, so the edit was not applied.`);
107653
+ if (digest(new Uint8Array(await editor.save())) !== digest(before))
107654
+ throw new Error(`"${target3}" changed while the edit was prepared; read it again and retry.`);
107655
+ await editor.load(after);
107656
+ return { target: target3, tool: name3, result: result2, changed: true };
107657
+ }
107658
+ return {
107659
+ register(id4, editor) {
107660
+ if (editors.has(id4)) throw new Error(`A document is already registered as "${id4}".`);
107661
+ editors.set(id4, editor);
107662
+ return () => {
107663
+ if (editors.get(id4) === editor) editors.delete(id4);
107664
+ };
107665
+ },
107666
+ targets: () => [...editors].map(([id4, editor]) => ({
107667
+ id: id4,
107668
+ format: editor.format,
107669
+ readOnly: Boolean(editor.readOnly)
107670
+ })),
107671
+ describe() {
107672
+ const open2 = new Set([...editors.values()].map((editor) => editor.format));
107673
+ return serve.filter((tool) => open2.has(tool.format)).map((tool) => {
107674
+ const schema = tool.jsonSchema();
107675
+ return {
107676
+ name: tool.name,
107677
+ description: tool.description,
107678
+ kind: tool.kind,
107679
+ format: tool.format,
107680
+ inputSchema: {
107681
+ type: "object",
107682
+ additionalProperties: false,
107683
+ properties: {
107684
+ target: {
107685
+ type: "string",
107686
+ description: "The id of the open document to act on."
107687
+ },
107688
+ params: schema
107689
+ },
107690
+ required: ["target"]
107691
+ }
107692
+ };
107693
+ });
107694
+ },
107695
+ call(name3, call) {
107696
+ const key2 = typeof call?.target === "string" ? call.target : "";
107697
+ const next = (queues.get(key2) ?? Promise.resolve()).then(
107698
+ () => run2(name3, call),
107699
+ () => run2(name3, call)
107700
+ );
107701
+ queues.set(
107702
+ key2,
107703
+ next.catch(() => void 0)
107704
+ );
107705
+ return next;
107706
+ }
107707
+ };
107708
+ }
107709
+ function liveEditorFromElement(format8, element3, name3) {
107710
+ return {
107711
+ format: format8,
107712
+ save: async () => {
107713
+ if (element3.commitEdit && !element3.commitEdit())
107714
+ throw new Error("Finish the current cell edit before using the document.");
107715
+ if (format8 === "visio" && element3.exportVsdx) return (await element3.exportVsdx()).bytes;
107716
+ if (!element3.saveBytes) throw new Error("The editor cannot save its document.");
107717
+ return element3.saveBytes();
107718
+ },
107719
+ load: async (bytes) => {
107720
+ await element3.load(bytes, name3);
107721
+ },
107722
+ get readOnly() {
107723
+ return element3.readOnly === true;
107724
+ }
107725
+ };
107726
+ }
107727
+
107728
+ export { UNTRUSTED_NOTE, XLSX_EDIT_LIMITS, applyXlsxEdits, applyXlsxProposal, automationTools, checkEditProposal, createDocx, createDocxFromOutline, createEditProposal, createLiveToolHost, createXlsx, createXlsxFromSheets, documentDigest, docxTools, editVsdx as editVisio, fillDocxFormFields, findAutomationTool, findXlsxCells, inspectDocx, inspectVisio, inspectXlsx, listDocxFormFields, liveEditorFromElement, proposeXlsxEdits, readXlsxFilledCells, readXlsxRange, readXlsxTable, setDocxRunText, setXlsxCells, suggestDocxRunText, visioTools, xlsxTools };