ooxml-core 1.6.1 → 1.7.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 (72) hide show
  1. package/dist/{PptxHandler-BTXB54UC.mjs → PptxHandler-BL4B7CZO.mjs} +2 -2
  2. package/dist/automation/index.cjs +482 -232
  3. package/dist/automation/index.mjs +482 -232
  4. package/dist/{chunk-CS7HRNHL.mjs → chunk-GAGSCAR3.mjs} +43 -43
  5. package/dist/{chunk-5CJRDY7Q.mjs → chunk-NIHPA63A.mjs} +1 -1
  6. package/dist/{chunk-Q5LESLDA.mjs → chunk-TTPZITQN.mjs} +841 -614
  7. package/dist/{chunk-4L4UB3RQ.mjs → chunk-Z7IQR4S4.mjs} +3 -3
  8. package/dist/{chunk-RIFVZP2S.mjs → chunk-ZAP5WLEN.mjs} +1 -1
  9. package/dist/crypto/index.cjs +281 -109
  10. package/dist/crypto/index.mjs +281 -109
  11. package/dist/docx/load/index.cjs +481 -254
  12. package/dist/docx/load/index.mjs +481 -254
  13. package/dist/geometry/index.cjs +25 -0
  14. package/dist/geometry/index.d.ts +1 -0
  15. package/dist/geometry/index.d.ts.map +1 -1
  16. package/dist/geometry/index.mjs +24 -1
  17. package/dist/geometry/nudge.d.ts +12 -0
  18. package/dist/geometry/nudge.d.ts.map +1 -0
  19. package/dist/geometry/rotation-drag.d.ts +6 -0
  20. package/dist/geometry/rotation-drag.d.ts.map +1 -1
  21. package/dist/index.cjs +25 -0
  22. package/dist/index.mjs +25 -0
  23. package/dist/pptx/automation/index.cjs +1395 -1156
  24. package/dist/pptx/automation/index.d.ts +1 -1
  25. package/dist/pptx/automation/index.mjs +5 -5
  26. package/dist/pptx/chunks/{index-DkHgeV1p.d.ts → index-Cn-GzYGp.d.ts} +62 -13
  27. package/dist/pptx/chunks/{index-DkHgeV1p.d.ts.map → index-Cn-GzYGp.d.ts.map} +1 -1
  28. package/dist/pptx/cli/index.cjs +1274 -1090
  29. package/dist/pptx/cli/index.mjs +4 -4
  30. package/dist/pptx/converter/index.cjs +7 -2
  31. package/dist/pptx/converter/index.mjs +2 -2
  32. package/dist/pptx/index.cjs +1415 -1176
  33. package/dist/pptx/index.d.ts +1 -1
  34. package/dist/pptx/index.mjs +5 -5
  35. package/dist/teams/index.cjs +7 -2
  36. package/dist/teams/index.mjs +7 -2
  37. package/dist/visio/edit-commands.d.ts +3 -1
  38. package/dist/visio/edit-commands.d.ts.map +1 -1
  39. package/dist/visio/edit-layer-properties.d.ts +22 -0
  40. package/dist/visio/edit-layer-properties.d.ts.map +1 -0
  41. package/dist/visio/edit-text-instance.d.ts +21 -0
  42. package/dist/visio/edit-text-instance.d.ts.map +1 -0
  43. package/dist/visio/edit-text-ranges.d.ts.map +1 -1
  44. package/dist/visio/edit-text-scope.d.ts +6 -1
  45. package/dist/visio/edit-text-scope.d.ts.map +1 -1
  46. package/dist/visio/edit-text-target.d.ts +11 -1
  47. package/dist/visio/edit-text-target.d.ts.map +1 -1
  48. package/dist/visio/edit-text.d.ts +2 -1
  49. package/dist/visio/edit-text.d.ts.map +1 -1
  50. package/dist/visio/edit.d.ts +1 -1
  51. package/dist/visio/edit.d.ts.map +1 -1
  52. package/dist/visio/index.cjs +1038 -538
  53. package/dist/visio/index.d.ts +1 -1
  54. package/dist/visio/index.d.ts.map +1 -1
  55. package/dist/visio/index.mjs +1038 -538
  56. package/dist/visio/text-fields.d.ts.map +1 -1
  57. package/dist/visio/ui/edit-commands.d.ts.map +1 -1
  58. package/dist/visio/ui/edit-error.d.ts +4 -1
  59. package/dist/visio/ui/edit-error.d.ts.map +1 -1
  60. package/dist/visio/ui/guides.d.ts +5 -0
  61. package/dist/visio/ui/guides.d.ts.map +1 -1
  62. package/dist/visio/ui/index.cjs +19768 -1874
  63. package/dist/visio/ui/index.d.ts +1 -0
  64. package/dist/visio/ui/index.d.ts.map +1 -1
  65. package/dist/visio/ui/index.mjs +19765 -1877
  66. package/dist/visio/ui/sample-drawing.d.ts +8 -0
  67. package/dist/visio/ui/sample-drawing.d.ts.map +1 -0
  68. package/dist/visio/ui/shape-move.d.ts +6 -0
  69. package/dist/visio/ui/shape-move.d.ts.map +1 -1
  70. package/dist/xlsx/load/index.cjs +415 -188
  71. package/dist/xlsx/load/index.mjs +415 -188
  72. package/package.json +6 -5
@@ -4079,9 +4079,9 @@ function isSimpleTextBox(graphicData, anchored) {
4079
4079
  if (!graphicData || anchored) return false;
4080
4080
  const content2 = descendants(graphicData, W_NS, "txbxContent")[0];
4081
4081
  if (!content2) return false;
4082
- const plain2 = (node2, allowed) => Array.from(node2.childNodes).filter(isElement).every((child6) => child6.namespaceURI === W_NS && allowed.includes(child6.localName));
4083
- return plain2(content2, ["p"]) && descendants(content2, W_NS, "p").every(
4084
- (paragraph2) => plain2(paragraph2, ["r"]) && descendants(paragraph2, W_NS, "r").every((run2) => plain2(run2, ["t"]))
4082
+ const plain3 = (node2, allowed) => Array.from(node2.childNodes).filter(isElement).every((child6) => child6.namespaceURI === W_NS && allowed.includes(child6.localName));
4083
+ return plain3(content2, ["p"]) && descendants(content2, W_NS, "p").every(
4084
+ (paragraph2) => plain3(paragraph2, ["r"]) && descendants(paragraph2, W_NS, "r").every((run2) => plain3(run2, ["t"]))
4085
4085
  );
4086
4086
  }
4087
4087
  function textBoxHasBorder(graphicData) {
@@ -14466,9 +14466,9 @@ function fromStoredSyntax(formula) {
14466
14466
  const close2 = nextIndex(list2, arg + 1);
14467
14467
  const target2 = list2[arg];
14468
14468
  if (list2[open]?.kind !== "open" || list2[close2]?.kind !== "close" || !target2) continue;
14469
- const single = target2.kind === "ref" || target2.kind === "name" || target2.kind === "structured";
14469
+ const single2 = target2.kind === "ref" || target2.kind === "name" || target2.kind === "structured";
14470
14470
  if (name3 === "ANCHORARRAY" && !(target2.kind === "ref" && target2.ref?.kind === "cell")) continue;
14471
- if (name3 === "SINGLE" && !single) continue;
14471
+ if (name3 === "SINGLE" && !single2) continue;
14472
14472
  const text4 = name3 === "ANCHORARRAY" ? `${target2.text}#` : `@${target2.text}`;
14473
14473
  for (let k = i2; k <= close2; k++) list2[k].text = "";
14474
14474
  token.text = text4;
@@ -14525,14 +14525,14 @@ function rewrite(formula, visit2) {
14525
14525
  }
14526
14526
  function stripFuturePrefixes(formula) {
14527
14527
  if (!formula.includes("_xl")) return formula;
14528
- const plain2 = rewrite(formula, (token, next, out) => {
14528
+ const plain3 = rewrite(formula, (token, next, out) => {
14529
14529
  if (!next.startsWith("(")) return false;
14530
14530
  const stripped = token.replace(/^(_xlfn\.)?(_xlws\.)?/i, "");
14531
14531
  if (stripped === token) return false;
14532
14532
  out.push(stripped);
14533
14533
  return true;
14534
14534
  });
14535
- return fromStoredSyntax(plain2);
14535
+ return fromStoredSyntax(plain3);
14536
14536
  }
14537
14537
  function addFuturePrefixes(formula) {
14538
14538
  return rewrite(toStoredSyntax(formula), (token, next, out) => {
@@ -17828,8 +17828,8 @@ function parseNumberText(input) {
17828
17828
  const signText = `${signed?.[1] ?? ""}${signed?.[2] ?? ""}`;
17829
17829
  if (signText.length <= 1) {
17830
17830
  const body = text4.slice(signed?.[0].length ?? 0);
17831
- const plain2 = parsePlainNumber(body);
17832
- if (plain2 !== void 0) return (signText === "-" ? -1 : 1) * sign * plain2 * scale2;
17831
+ const plain3 = parsePlainNumber(body);
17832
+ if (plain3 !== void 0) return (signText === "-" ? -1 : 1) * sign * plain3 * scale2;
17833
17833
  }
17834
17834
  if (scale2 !== 1 || sign !== 1) return void 0;
17835
17835
  const fraction = /^([+-]?)(?:(\d+)\s+)?(\d+)\/(\d+)$/.exec(text4);
@@ -17870,13 +17870,13 @@ function numberToText(value) {
17870
17870
  const [mantissa = "0", expText = "0"] = abs2.toExponential(14).split("e");
17871
17871
  const exponent = Number(expText);
17872
17872
  const digits2 = mantissa.replace(".", "").replace(/0+$/, "") || "0";
17873
- let plain2;
17873
+ let plain3;
17874
17874
  if (exponent >= 0) {
17875
- plain2 = digits2.length <= exponent + 1 ? digits2 + "0".repeat(exponent + 1 - digits2.length) : `${digits2.slice(0, exponent + 1)}.${digits2.slice(exponent + 1)}`;
17875
+ plain3 = digits2.length <= exponent + 1 ? digits2 + "0".repeat(exponent + 1 - digits2.length) : `${digits2.slice(0, exponent + 1)}.${digits2.slice(exponent + 1)}`;
17876
17876
  } else {
17877
- plain2 = `0.${"0".repeat(-exponent - 1)}${digits2}`;
17877
+ plain3 = `0.${"0".repeat(-exponent - 1)}${digits2}`;
17878
17878
  }
17879
- if (plain2.length <= 20) return negative ? `-${plain2}` : plain2;
17879
+ if (plain3.length <= 20) return negative ? `-${plain3}` : plain3;
17880
17880
  const mant = digits2.length > 1 ? `${digits2[0]}.${digits2.slice(1)}` : digits2;
17881
17881
  const exp2 = `${exponent < 0 ? "-" : "+"}${String(Math.abs(exponent)).padStart(2, "0")}`;
17882
17882
  return `${negative ? "-" : ""}${mant}E${exp2}`;
@@ -23675,8 +23675,8 @@ var REGRESSION_FUNCTIONS = [
23675
23675
  const stats = !omitted(args, 3) && bool(args[3]);
23676
23676
  const table3 = coefficientTable(fit3, stats, Math.exp);
23677
23677
  if (!stats) return table3;
23678
- const plain2 = coefficientTable(fit3, true, (v) => v).data;
23679
- return new Matrix([table3.data[0] ?? [], ...plain2.slice(1)]);
23678
+ const plain3 = coefficientTable(fit3, true, (v) => v).data;
23679
+ return new Matrix([table3.data[0] ?? [], ...plain3.slice(1)]);
23680
23680
  },
23681
23681
  ARGS
23682
23682
  ),
@@ -41804,7 +41804,7 @@ function legacyFillGradient(cells3, width, height, resolve2) {
41804
41804
  };
41805
41805
  }
41806
41806
 
41807
- // ../../node_modules/.bun/@christophervr+ole2@0.12.0/node_modules/@christophervr/ole2/dist/utils/png-encoder.js
41807
+ // ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/utils/png-encoder.js
41808
41808
  var CRC_TABLE = (() => {
41809
41809
  const table3 = new Uint32Array(256);
41810
41810
  for (let n = 0; n < 256; n++) {
@@ -43073,31 +43073,32 @@ var DAYS2 = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "
43073
43073
  var pad4 = (value, length = 2) => String(value).padStart(length, "0");
43074
43074
  function formatDate(date2, picture) {
43075
43075
  const hours = date2.getUTCHours();
43076
- const tokens3 = {
43077
- yyyy: () => pad4(date2.getUTCFullYear(), 4),
43078
- yy: () => pad4(date2.getUTCFullYear() % 100),
43079
- MMMM: () => MONTHS3[date2.getUTCMonth()],
43080
- MMM: () => MONTHS3[date2.getUTCMonth()].slice(0, 3),
43081
- MM: () => pad4(date2.getUTCMonth() + 1),
43082
- M: () => String(date2.getUTCMonth() + 1),
43083
- dddd: () => DAYS2[date2.getUTCDay()],
43084
- ddd: () => DAYS2[date2.getUTCDay()].slice(0, 3),
43085
- dd: () => pad4(date2.getUTCDate()),
43086
- d: () => String(date2.getUTCDate()),
43087
- HH: () => pad4(hours),
43088
- H: () => String(hours),
43089
- hh: () => pad4(hours % 12 || 12),
43090
- h: () => String(hours % 12 || 12),
43091
- mm: () => pad4(date2.getUTCMinutes()),
43092
- ss: () => pad4(date2.getUTCSeconds()),
43093
- tt: () => hours < 12 ? "AM" : "PM"
43094
- };
43076
+ const tokens3 = new Map(
43077
+ Object.entries({
43078
+ yyyy: () => pad4(date2.getUTCFullYear(), 4),
43079
+ yy: () => pad4(date2.getUTCFullYear() % 100),
43080
+ MMMM: () => MONTHS3[date2.getUTCMonth()],
43081
+ MMM: () => MONTHS3[date2.getUTCMonth()].slice(0, 3),
43082
+ MM: () => pad4(date2.getUTCMonth() + 1),
43083
+ M: () => String(date2.getUTCMonth() + 1),
43084
+ dddd: () => DAYS2[date2.getUTCDay()],
43085
+ ddd: () => DAYS2[date2.getUTCDay()].slice(0, 3),
43086
+ dd: () => pad4(date2.getUTCDate()),
43087
+ d: () => String(date2.getUTCDate()),
43088
+ HH: () => pad4(hours),
43089
+ H: () => String(hours),
43090
+ hh: () => pad4(hours % 12 || 12),
43091
+ h: () => String(hours % 12 || 12),
43092
+ mm: () => pad4(date2.getUTCMinutes()),
43093
+ ss: () => pad4(date2.getUTCSeconds()),
43094
+ tt: () => hours < 12 ? "AM" : "PM"
43095
+ })
43096
+ );
43095
43097
  return picture.replace(
43096
43098
  /yyyy|yy|MMMM|MMM|MM|M|dddd|ddd|dd|d|HH|H|hh|h|mm|ss|tt|"[^"]*"/g,
43097
43099
  (token) => {
43098
43100
  if (token.startsWith('"')) return token.slice(1, -1);
43099
- const format = tokens3[token];
43100
- return typeof format === "function" ? format() : token;
43101
+ return tokens3.get(token)?.() ?? token;
43101
43102
  }
43102
43103
  );
43103
43104
  }
@@ -47940,7 +47941,7 @@ function assertUnlayeredShape(shape2, document) {
47940
47941
  }
47941
47942
 
47942
47943
  // visio/edit-text-target.ts
47943
- function localTextTarget(root, document, shapeId2, check3) {
47944
+ function textTarget(root, shapeId2, check3) {
47944
47945
  const shapeChildren = (parent) => {
47945
47946
  const containers = children3(parent, "Shapes");
47946
47947
  if (containers.length > 1)
@@ -47948,35 +47949,145 @@ function localTextTarget(root, document, shapeId2, check3) {
47948
47949
  return children3(containers[0], "Shape");
47949
47950
  };
47950
47951
  const shapes = /* @__PURE__ */ new Map();
47951
- const pending2 = shapeChildren(root).map((node2) => ({ node: node2, inherited: false, deleted: false }));
47952
+ const pending2 = shapeChildren(root).map((node2) => ({
47953
+ node: node2,
47954
+ masterId: void 0,
47955
+ deleted: false
47956
+ }));
47952
47957
  while (pending2.length) {
47953
47958
  check3();
47954
47959
  const item = pending2.pop(), id3 = attribute3(item.node, "ID");
47955
47960
  if (!id3 || shapes.has(id3))
47956
47961
  fail2("INVALID_SHAPE_ID", "Local shape IDs must be present and unique.");
47957
- const inherited = item.inherited || item.node.hasAttribute("Master") || item.node.hasAttribute("MasterShape");
47962
+ const masterId = attribute3(item.node, "Master") ?? item.masterId;
47958
47963
  const deleted = item.deleted || ["1", "true"].includes(attribute3(item.node, "Del") ?? "");
47959
- shapes.set(id3, { node: item.node, inherited, deleted });
47960
- for (const node2 of shapeChildren(item.node)) pending2.push({ node: node2, inherited, deleted });
47964
+ shapes.set(id3, { node: item.node, masterId, deleted });
47965
+ for (const node2 of shapeChildren(item.node)) pending2.push({ node: node2, masterId, deleted });
47961
47966
  }
47962
47967
  const target2 = shapes.get(shapeId2);
47963
47968
  if (!target2) fail2("EDIT_TARGET_NOT_FOUND", "Local shape does not exist.");
47964
- if (target2.inherited || target2.deleted)
47965
- fail2("UNSUPPORTED_TEXT_EDIT", "Master-linked or deleted shapes cannot be edited.");
47969
+ if (target2.deleted) fail2("UNSUPPORTED_TEXT_EDIT", "Deleted shapes cannot be edited.");
47970
+ const masterShapeId = attribute3(target2.node, "MasterShape");
47971
+ if (masterShapeId !== void 0 && target2.masterId === void 0)
47972
+ fail2("UNSUPPORTED_TEXT_EDIT", "The shape refers to a master that is not on this page.");
47973
+ return {
47974
+ node: target2.node,
47975
+ ...target2.masterId !== void 0 ? { masterId: target2.masterId } : {},
47976
+ ...masterShapeId !== void 0 ? { masterShapeId } : {}
47977
+ };
47978
+ }
47979
+ function localTextTarget(root, document, shapeId2, check3) {
47980
+ const target2 = textTarget(root, shapeId2, check3);
47981
+ if (target2.masterId !== void 0)
47982
+ fail2("UNSUPPORTED_TEXT_EDIT", "Text ranges and fields of stencil shapes cannot be edited.");
47966
47983
  assertShapeLocks(target2.node, document, ["LockTextEdit"]);
47967
47984
  return target2.node;
47968
47985
  }
47969
47986
 
47987
+ // visio/edit-text-instance.ts
47988
+ var fieldSections = (shape2) => children3(shape2, "Section").filter((section2) => attribute3(section2, "N") === "Field");
47989
+ var isMarkup = (node2) => node2.nodeType !== 3 && node2.nodeType !== 4;
47990
+ var knownMarkup = (text4) => Array.from(text4.childNodes).every(
47991
+ (node2) => !isMarkup(node2) || ["cp", "pp", "tp", "fld"].includes(node2.localName)
47992
+ );
47993
+ function assertUnlocked2(shape2, template) {
47994
+ const local = children3(shape2, "Cell").some((cell) => attribute3(cell, "N") === "LockTextEdit");
47995
+ for (const cell of children3(local ? shape2 : template, "Cell")) {
47996
+ if (attribute3(cell, "N") !== "LockTextEdit") continue;
47997
+ if (cell.hasAttribute("E") || cell.hasAttribute("F") || Number(attribute3(cell, "V")) !== 0)
47998
+ fail2("EDIT_PROTECTED_CELL", "The shape is protected against text editing.");
47999
+ }
48000
+ }
48001
+ function single(shape2, what) {
48002
+ const texts = children3(shape2, "Text");
48003
+ if (texts.length > 1) fail2("UNSUPPORTED_TEXT_EDIT", `${what} has more than one Text element.`);
48004
+ return texts[0];
48005
+ }
48006
+ function insertBeforeTail(shape2, node2, tail) {
48007
+ const after = Array.from(shape2.childNodes).find(
48008
+ (child6) => child6.nodeType === 1 && tail.includes(child6.localName)
48009
+ );
48010
+ shape2.insertBefore(node2, after ?? null);
48011
+ }
48012
+ var AFTER_TEXT = ["Data1", "Data2", "Data3", "ForeignData", "Shapes"];
48013
+ function replaceInstanceText(shape2, template, text4) {
48014
+ const local = single(shape2, "The shape");
48015
+ const inherited = single(template, "The master shape");
48016
+ if (local && Array.from(local.childNodes).some(isMarkup))
48017
+ fail2(
48018
+ "UNSUPPORTED_TEXT_EDIT",
48019
+ "This stencil shape has its own formatted text; edit part of the text instead."
48020
+ );
48021
+ if (!local && inherited && !knownMarkup(inherited))
48022
+ fail2("UNSUPPORTED_TEXT_EDIT", "The master text has markup this editor does not know.");
48023
+ if (fieldSections(shape2).length)
48024
+ fail2("UNSUPPORTED_TEXT_EDIT", "This stencil shape has its own text fields; edit around them.");
48025
+ assertUnlocked2(shape2, template);
48026
+ const fields = local ? [] : fieldSections(template).flatMap((section2) => children3(section2, "Row"));
48027
+ const current = local ?? inherited;
48028
+ if (!fields.length && current && !Array.from(current.childNodes).some(isMarkup)) {
48029
+ if (decodeVisioPlainText(current.textContent ?? "") === text4) return false;
48030
+ }
48031
+ const document = shape2.ownerDocument;
48032
+ if (fields.length) {
48033
+ const section2 = document.createElementNS(shape2.namespaceURI, "Section");
48034
+ section2.setAttribute("N", "Field");
48035
+ for (const row3 of fields) {
48036
+ const index2 = attribute3(row3, "IX");
48037
+ if (index2 === void 0)
48038
+ fail2("UNSUPPORTED_TEXT_EDIT", "The master text fields cannot be identified.");
48039
+ const removed = document.createElementNS(shape2.namespaceURI, "Row");
48040
+ removed.setAttribute("IX", index2);
48041
+ removed.setAttribute("Del", "1");
48042
+ section2.appendChild(removed);
48043
+ }
48044
+ insertBeforeTail(shape2, section2, ["Text", ...AFTER_TEXT]);
48045
+ }
48046
+ let node2 = local;
48047
+ if (!node2) {
48048
+ node2 = document.createElementNS(shape2.namespaceURI, "Text");
48049
+ insertBeforeTail(shape2, node2, AFTER_TEXT);
48050
+ }
48051
+ while (node2.firstChild) node2.removeChild(node2.firstChild);
48052
+ node2.appendChild(document.createTextNode(encodeVisioPlainText(text4)));
48053
+ return true;
48054
+ }
48055
+ function instanceTextNode(shape2, template) {
48056
+ const local = single(shape2, "The shape");
48057
+ assertUnlocked2(shape2, template);
48058
+ if (local) return { text: local, discard: () => {
48059
+ } };
48060
+ const inherited = single(template, "The master shape");
48061
+ if (!inherited) fail2("UNSUPPORTED_TEXT_RANGE", "The stencil shape has no text to edit.");
48062
+ if (!knownMarkup(inherited))
48063
+ fail2("UNSUPPORTED_TEXT_RANGE", "The master text has markup this editor does not know.");
48064
+ if (fieldSections(shape2).length)
48065
+ fail2("UNSUPPORTED_TEXT_RANGE", "This stencil shape overrides its master text fields.");
48066
+ const text4 = shape2.ownerDocument.importNode(inherited, true);
48067
+ insertBeforeTail(shape2, text4, AFTER_TEXT);
48068
+ return { text: text4, discard: () => void shape2.removeChild(text4) };
48069
+ }
48070
+
47970
48071
  // visio/edit-text.ts
47971
- async function replacePlainText(root, document, shapeId2, text4, check3, assertDependencies2) {
48072
+ var plain2 = (node2) => Array.from(node2.childNodes).every((item) => item.nodeType === 3 || item.nodeType === 4);
48073
+ var hasFields = (shape2) => children3(shape2, "Section").some((section2) => attribute3(section2, "N") === "Field");
48074
+ async function replacePlainText(root, document, shapeId2, text4, check3, assertDependencies2, masterTemplate2) {
48075
+ const found = textTarget(root, shapeId2, check3);
48076
+ if (found.masterId !== void 0) {
48077
+ if (!masterTemplate2)
48078
+ fail2("UNSUPPORTED_TEXT_EDIT", "Stencil shapes cannot be edited without their masters.");
48079
+ const template = await masterTemplate2(found.masterId, found.masterShapeId);
48080
+ check3();
48081
+ return replaceInstanceText(found.node, template, text4);
48082
+ }
47972
48083
  const target2 = localTextTarget(root, document, shapeId2, check3);
47973
48084
  const texts = children3(target2, "Text");
47974
48085
  if (texts.length !== 1)
47975
48086
  fail2("UNSUPPORTED_TEXT_EDIT", "Editing requires one existing local Text element.");
47976
48087
  const node2 = texts[0];
47977
- if (Array.from(node2.childNodes).some((item) => item.nodeType !== 3 && item.nodeType !== 4))
48088
+ if (!plain2(node2))
47978
48089
  fail2("UNSUPPORTED_TEXT_EDIT", "Rich text, fields and unknown text markup cannot be edited.");
47979
- if (children3(target2, "Section").some((section2) => attribute3(section2, "N") === "Field"))
48090
+ if (hasFields(target2))
47980
48091
  fail2(
47981
48092
  "UNSUPPORTED_TEXT_EDIT",
47982
48093
  "Replacing all text would remove its text fields; edit the text around the fields instead."
@@ -48058,7 +48169,201 @@ async function assertFormattingDependencies(pkg, pagePaths, roots, pageId2, shap
48058
48169
  }
48059
48170
  }
48060
48171
 
48172
+ // visio/edit-master-index.ts
48173
+ function inheritedProtection(node2, ancestor) {
48174
+ try {
48175
+ const boolean2 = (cell) => {
48176
+ if (!cell || cell.hasAttribute("E"))
48177
+ fail2("EDIT_PROTECTED_CELL", "Inherited protection has an unresolved or error cache.");
48178
+ const value = visioFormulaCachedValue(attribute3(cell, "V") ?? "", attribute3(cell, "U"));
48179
+ if (value.unit !== "scalar" || ![0, 1].includes(value.value))
48180
+ fail2("EDIT_PROTECTED_CELL", "Inherited protection requires scalar boolean caches.");
48181
+ return value.value;
48182
+ };
48183
+ if (boolean2(node2) !== boolean2(ancestor))
48184
+ fail2(
48185
+ "EDIT_PROTECTED_CELL",
48186
+ "Delegated master style protection cache disagrees with its ancestor."
48187
+ );
48188
+ } catch (error) {
48189
+ fail2(
48190
+ "EDIT_PROTECTED_CELL",
48191
+ `Inherited master style protection cannot be proven: ${error instanceof Error ? error.message : "invalid cache"}`
48192
+ );
48193
+ }
48194
+ }
48195
+ function masterCells(sheet, charge = () => {
48196
+ }) {
48197
+ const result2 = /* @__PURE__ */ new Map();
48198
+ if (!sheet) return result2;
48199
+ const add3 = (name3, node2) => {
48200
+ charge();
48201
+ const id3 = name3.toLowerCase();
48202
+ if (result2.has(id3) && result2.get(id3) !== node2)
48203
+ fail2("EDIT_UNSUPPORTED_PACKAGE_DEPENDENCY", "Ambiguous effective master cells.");
48204
+ result2.set(id3, node2);
48205
+ };
48206
+ for (const node2 of children3(sheet, "Cell")) add3(attribute3(node2, "N") ?? "", node2);
48207
+ for (const section2 of children3(sheet, "Section")) {
48208
+ const name3 = attribute3(section2, "N") ?? "";
48209
+ const prefix2 = name3 === "Geometry" ? `Geometry${Number(attribute3(section2, "IX") ?? "0") + 1}` : name3 === "Control" ? "Controls" : name3;
48210
+ for (const node2 of children3(section2, "Cell"))
48211
+ add3(`${prefix2}.${attribute3(node2, "N") ?? ""}`, node2);
48212
+ for (const row3 of children3(section2, "Row"))
48213
+ for (const node2 of children3(row3, "Cell")) {
48214
+ const n = attribute3(node2, "N") ?? "";
48215
+ const rowName = attribute3(row3, "N");
48216
+ const index2 = attribute3(row3, "IX") ?? (prefix2 === "Controls" && /^Row_\d+$/.test(rowName ?? "") ? String(Number(rowName.slice(4)) - 1) : void 0);
48217
+ const ix = index2 ?? "0", r = rowName ?? (prefix2 === "Controls" ? `Row_${Number(ix) + 1}` : ix);
48218
+ add3(
48219
+ name3 === "Geometry" || ["Controls", "Scratch", "Connection"].includes(prefix2) ? `${prefix2}.${n}${ix}` : n === "Value" && ["User", "Prop"].includes(name3) ? `${prefix2}.${r}` : `${prefix2}.${r}.${n}`,
48220
+ node2
48221
+ );
48222
+ if (name3 !== "Geometry") add3(`${prefix2}.${r}.${n}`, node2);
48223
+ if (prefix2 === "Controls" && n === "X") add3(`${prefix2}.${r}`, node2);
48224
+ if (name3 !== "Geometry" && index2 !== void 0) add3(`${prefix2}.$row${ix}.${n}`, node2);
48225
+ }
48226
+ }
48227
+ return result2;
48228
+ }
48229
+ function masterShapes(root) {
48230
+ const result2 = [], pending2 = [root];
48231
+ while (pending2.length) {
48232
+ const parent = pending2.pop();
48233
+ for (const container of children3(parent, "Shapes"))
48234
+ for (const shape2 of children3(container, "Shape")) {
48235
+ result2.push(shape2);
48236
+ pending2.push(shape2);
48237
+ }
48238
+ }
48239
+ return result2;
48240
+ }
48241
+ function assertMasterMarkup(root, known, check3) {
48242
+ for (const node2 of [root, ...Array.from(root.getElementsByTagName("*"))]) {
48243
+ check3();
48244
+ if (node2.namespaceURI === root.namespaceURI && node2.hasAttribute("F") && !known.has(node2))
48245
+ fail2(
48246
+ "EDIT_UNSUPPORTED_PACKAGE_DEPENDENCY",
48247
+ "Master formula outside admitted sheet cells has unknown scope."
48248
+ );
48249
+ }
48250
+ }
48251
+ function masterStyleCells(document, template, instance, check3, charge = () => {
48252
+ }, verifyMovementProtection = false) {
48253
+ const styles = /* @__PURE__ */ new Map();
48254
+ for (const container of children3(document, "StyleSheets"))
48255
+ for (const style3 of children3(container, "StyleSheet")) {
48256
+ charge();
48257
+ const id3 = attribute3(style3, "ID");
48258
+ if (!id3 || styles.has(id3))
48259
+ fail2("EDIT_UNSUPPORTED_PACKAGE_DEPENDENCY", "Ambiguous master style IDs.");
48260
+ styles.set(id3, style3);
48261
+ }
48262
+ const defaults = children3(document, "DocumentSheet")[0];
48263
+ const collect = (id3, category, seen = /* @__PURE__ */ new Set()) => {
48264
+ check3();
48265
+ if (seen.has(id3) || seen.size >= 64)
48266
+ fail2("EDIT_UNSUPPORTED_PACKAGE_DEPENDENCY", "Invalid inherited master style ancestry.");
48267
+ seen.add(id3);
48268
+ const style3 = styles.get(id3);
48269
+ if (!style3) fail2("EDIT_UNSUPPORTED_PACKAGE_DEPENDENCY", "Missing inherited master style.");
48270
+ const own = masterCells(style3, charge);
48271
+ assertMasterMarkup(style3, new Set(own.values()), check3);
48272
+ const parent = attribute3(style3, category);
48273
+ const result3 = parent !== void 0 && parent !== id3 ? collect(parent, category, seen) : /* @__PURE__ */ new Map();
48274
+ for (const [name3, node2] of own) {
48275
+ charge();
48276
+ if (attribute3(node2, "F") !== "Inh") result3.set(name3, node2);
48277
+ else if (verifyMovementProtection && /^lock(move[xy]|width|height|aspect|delete)$/.test(name3)) {
48278
+ charge();
48279
+ inheritedProtection(node2, result3.get(name3));
48280
+ }
48281
+ }
48282
+ return result3;
48283
+ };
48284
+ const result2 = /* @__PURE__ */ new Map();
48285
+ for (const category of ["LineStyle", "FillStyle", "TextStyle"]) {
48286
+ const id3 = attribute3(instance, category) ?? attribute3(template, category) ?? attribute3(defaults, category) ?? (styles.has("0") ? "0" : void 0);
48287
+ if (id3 !== void 0)
48288
+ for (const [name3, node2] of collect(id3, category)) {
48289
+ charge();
48290
+ if (result2.has(name3) && result2.get(name3) !== node2)
48291
+ fail2(
48292
+ "EDIT_UNSUPPORTED_PACKAGE_DEPENDENCY",
48293
+ "Master style categories have ambiguous overlapping inputs."
48294
+ );
48295
+ result2.set(name3, node2);
48296
+ }
48297
+ }
48298
+ return result2;
48299
+ }
48300
+ function overlay(cells3, additions, kind, charge) {
48301
+ const aliases = /* @__PURE__ */ new Map(), inherited = /* @__PURE__ */ new Map();
48302
+ for (const [name3, source2] of cells3) {
48303
+ charge();
48304
+ const names = aliases.get(source2.node) ?? /* @__PURE__ */ new Set();
48305
+ names.add(name3);
48306
+ aliases.set(source2.node, names);
48307
+ }
48308
+ for (const [name3, node2] of additions) {
48309
+ charge();
48310
+ const source2 = cells3.get(name3);
48311
+ if (source2) inherited.set(node2, source2);
48312
+ }
48313
+ for (const [name3, node2] of additions) {
48314
+ charge();
48315
+ if (attribute3(node2, "F") === "Inh") {
48316
+ const source2 = cells3.get(name3) ?? inherited.get(node2);
48317
+ if (!source2)
48318
+ fail2(
48319
+ "EDIT_UNSUPPORTED_PACKAGE_DEPENDENCY",
48320
+ "Inherited master cell has no effective source."
48321
+ );
48322
+ cells3.set(name3, source2);
48323
+ const names2 = aliases.get(source2.node) ?? /* @__PURE__ */ new Set();
48324
+ names2.add(name3);
48325
+ aliases.set(source2.node, names2);
48326
+ continue;
48327
+ }
48328
+ const previous = cells3.get(name3), names = aliases.get(node2) ?? /* @__PURE__ */ new Set();
48329
+ if (previous && previous.node !== node2) {
48330
+ for (const alias of aliases.get(previous.node) ?? []) {
48331
+ charge();
48332
+ cells3.set(alias, { node: node2, kind });
48333
+ names.add(alias);
48334
+ }
48335
+ aliases.delete(previous.node);
48336
+ }
48337
+ cells3.set(name3, { node: node2, kind });
48338
+ names.add(name3);
48339
+ aliases.set(node2, names);
48340
+ }
48341
+ }
48342
+
48061
48343
  // visio/edit-text-scope.ts
48344
+ function masterTemplate(pkg) {
48345
+ const missing = () => fail2("UNSUPPORTED_TEXT_EDIT", "The master of this stencil shape cannot be resolved.");
48346
+ return async (masterId, masterShapeId) => {
48347
+ const documentPart = await related(pkg, "", "document");
48348
+ const mastersPart = documentPart && await related(pkg, documentPart, "masters", false);
48349
+ if (!mastersPart) return missing();
48350
+ const definitions = children3(await visioXml(pkg, mastersPart, "Masters"), "Master").filter(
48351
+ (node2) => attribute3(node2, "ID") === masterId
48352
+ );
48353
+ if (definitions.length !== 1) return missing();
48354
+ const root = await visioXml(
48355
+ pkg,
48356
+ await indexedPart(pkg, mastersPart, definitions[0], "master"),
48357
+ "MasterContents"
48358
+ );
48359
+ if (masterShapeId === void 0) {
48360
+ const tops = children3(children3(root, "Shapes")[0], "Shape");
48361
+ return tops.length === 1 ? tops[0] : missing();
48362
+ }
48363
+ const matches2 = masterShapes(root).filter((shape2) => attribute3(shape2, "ID") === masterShapeId);
48364
+ return matches2.length === 1 ? matches2[0] : missing();
48365
+ };
48366
+ }
48062
48367
  function replaceScopedPlainText(pkg, pagePaths, roots, document, edit, check3) {
48063
48368
  return replacePlainText(
48064
48369
  roots.get(edit.pageId),
@@ -48074,7 +48379,8 @@ function replaceScopedPlainText(pkg, pagePaths, roots, document, edit, check3) {
48074
48379
  shape2,
48075
48380
  /* @__PURE__ */ new Map([["TheText", text4]]),
48076
48381
  check3
48077
- )
48382
+ ),
48383
+ masterTemplate(pkg)
48078
48384
  );
48079
48385
  }
48080
48386
 
@@ -48198,12 +48504,17 @@ function textRangeNodes(node2, edit) {
48198
48504
 
48199
48505
  // visio/edit-text-ranges.ts
48200
48506
  async function replaceScopedTextRanges(pkg, pagePaths, roots, document, edit, check3) {
48201
- const shape2 = localTextTarget(roots.get(edit.pageId), document, edit.shapeId, check3);
48507
+ const found = textTarget(roots.get(edit.pageId), edit.shapeId, check3);
48508
+ const instance = found.masterId === void 0 ? void 0 : instanceTextNode(
48509
+ found.node,
48510
+ await masterTemplate(pkg)(found.masterId, found.masterShapeId)
48511
+ );
48512
+ const shape2 = instance ? found.node : localTextTarget(roots.get(edit.pageId), document, edit.shapeId, check3);
48202
48513
  const texts = children3(shape2, "Text");
48203
48514
  if (texts.length !== 1)
48204
48515
  fail2("UNSUPPORTED_TEXT_RANGE", "Range editing requires one existing local Text element.");
48205
48516
  const text4 = texts[0];
48206
- if (Array.from(text4.childNodes).some((node2) => ![3, 4].includes(node2.nodeType))) {
48517
+ if (!instance && Array.from(text4.childNodes).some((node2) => ![3, 4].includes(node2.nodeType))) {
48207
48518
  const characters = effectiveFormattingRows(shape2, document, "Character"), paragraphs = effectiveFormattingRows(shape2, document, "Paragraph");
48208
48519
  assertFormattingText(shape2, characters, paragraphs);
48209
48520
  }
@@ -48220,16 +48531,20 @@ async function replaceScopedTextRanges(pkg, pagePaths, roots, document, edit, ch
48220
48531
  }
48221
48532
  }
48222
48533
  const plan = textRangeNodes(text4, edit);
48223
- if (!plan.changed) return false;
48224
- await assertFormattingDependencies(
48225
- pkg,
48226
- pagePaths,
48227
- roots,
48228
- edit.pageId,
48229
- shape2,
48230
- /* @__PURE__ */ new Map([["TheText", text4]]),
48231
- check3
48232
- );
48534
+ if (!plan.changed) {
48535
+ instance?.discard();
48536
+ return false;
48537
+ }
48538
+ if (!instance)
48539
+ await assertFormattingDependencies(
48540
+ pkg,
48541
+ pagePaths,
48542
+ roots,
48543
+ edit.pageId,
48544
+ shape2,
48545
+ /* @__PURE__ */ new Map([["TheText", text4]]),
48546
+ check3
48547
+ );
48233
48548
  check3();
48234
48549
  while (text4.firstChild) text4.removeChild(text4.firstChild);
48235
48550
  for (const node2 of plan.nodes) text4.appendChild(node2);
@@ -49379,6 +49694,96 @@ function snapshotAssignLayers(edit) {
49379
49694
  };
49380
49695
  }
49381
49696
 
49697
+ // visio/edit-layer-properties.ts
49698
+ var FLAGS = [
49699
+ ["visible", "Visible"],
49700
+ ["print", "Print"],
49701
+ ["lock", "Lock"]
49702
+ ];
49703
+ function snapshotLayerProperties(edit) {
49704
+ if (typeof edit.pageId !== "string" || !edit.pageId || edit.pageId.length > 256)
49705
+ fail2("INVALID_EDIT", "Invalid edit target.");
49706
+ if (typeof edit.layerId !== "string" || !/^(0|[1-9]\d{0,9})$/.test(edit.layerId))
49707
+ fail2("INVALID_EDIT", "Layer IDs must be canonical unsigned integers.");
49708
+ const result2 = {
49709
+ type: "set-layer-properties",
49710
+ pageId: edit.pageId,
49711
+ layerId: edit.layerId
49712
+ };
49713
+ for (const [key2] of FLAGS) {
49714
+ const value = edit[key2];
49715
+ if (value === void 0) continue;
49716
+ if (typeof value !== "boolean") fail2("INVALID_EDIT", "Layer flags are true or false.");
49717
+ result2[key2] = value;
49718
+ }
49719
+ if (!FLAGS.some(([key2]) => result2[key2] !== void 0))
49720
+ fail2("INVALID_EDIT", "A layer edit needs at least one flag.");
49721
+ return result2;
49722
+ }
49723
+ async function editVsdxLayerProperties(pkg, parts, pages, edits, limits, maxOutput, deadline, check3) {
49724
+ const documentPart = await related(pkg, "", "document");
49725
+ const pagesPart = await related(pkg, documentPart, "pages");
49726
+ const source2 = await visioXml(pkg, pagesPart, "Pages");
49727
+ const pageList = source2.ownerDocument.cloneNode(true).documentElement;
49728
+ let changed = false;
49729
+ for (const edit of edits) {
49730
+ check3();
49731
+ if (!pages.has(edit.pageId)) fail2("EDIT_TARGET_NOT_FOUND", "Page does not exist.");
49732
+ const page = children3(pageList, "Page").find((node2) => attribute3(node2, "ID") === edit.pageId);
49733
+ const sheets = page ? children3(page, "PageSheet") : [];
49734
+ if (sheets.length !== 1) fail2("UNSUPPORTED_LAYER_EDIT", "One explicit PageSheet is required.");
49735
+ const sections = children3(sheets[0], "Section").filter(
49736
+ (node2) => attribute3(node2, "N") === "Layer"
49737
+ );
49738
+ if (sections.length !== 1)
49739
+ fail2("EDIT_TARGET_NOT_FOUND", "The layer does not belong to this page.");
49740
+ const rows = children3(sections[0], "Row").filter(
49741
+ (row4) => attribute3(row4, "IX") === edit.layerId
49742
+ );
49743
+ if (rows.length !== 1 || rows[0].hasAttribute("Del"))
49744
+ fail2("EDIT_TARGET_NOT_FOUND", "The layer does not belong to this page.");
49745
+ const row3 = rows[0];
49746
+ for (const [key2, name3] of FLAGS) {
49747
+ const value = edit[key2];
49748
+ if (value === void 0) continue;
49749
+ const cells3 = children3(row3, "Cell").filter((cell2) => attribute3(cell2, "N") === name3);
49750
+ if (cells3.length > 1) fail2("UNSUPPORTED_LAYER_EDIT", `Duplicate layer ${name3} cells.`);
49751
+ let cell = cells3[0];
49752
+ if (cell && (cell.hasAttribute("E") || executableCellFormula(attribute3(cell, "F"))))
49753
+ fail2("UNSUPPORTED_LAYER_EDIT", `The layer's ${name3} flag is set by a formula.`);
49754
+ const next = value ? "1" : "0";
49755
+ if (cell && attribute3(cell, "V") === next) continue;
49756
+ if (!cell) {
49757
+ cell = row3.ownerDocument.createElementNS(row3.namespaceURI, "Cell");
49758
+ cell.setAttribute("N", name3);
49759
+ row3.appendChild(cell);
49760
+ }
49761
+ cell.setAttribute("V", next);
49762
+ changed = true;
49763
+ }
49764
+ }
49765
+ const original = parts.get(pagesPart);
49766
+ if (!changed)
49767
+ return {
49768
+ bytes: await writeEditedPackage(parts, maxOutput, deadline, check3),
49769
+ changedParts: [],
49770
+ diagnostics: []
49771
+ };
49772
+ const serialized = serializeEditedXml(pageList, limits, check3);
49773
+ const total2 = [...parts.values()].reduce((sum2, bytes2) => sum2 + bytes2.length, 0) + serialized.bytes.length - (original?.length ?? 0);
49774
+ if (total2 > limits.maxTotalBytes) fail2("LIMIT_TOTAL", "Edited package total exceeds limit.");
49775
+ parts.set(pagesPart, serialized.bytes);
49776
+ const bytes = await writeEditedPackage(parts, maxOutput, deadline, check3);
49777
+ const verified = await openEditablePackage(
49778
+ bytes,
49779
+ { ...limits, maxInputBytes: maxOutput, maxRuntimeMs: Math.max(1, deadline - Date.now()) },
49780
+ check3
49781
+ );
49782
+ await visioXml(verified.pkg, pagesPart, "Pages");
49783
+ check3();
49784
+ return { bytes, changedParts: [pagesPart], diagnostics: [] };
49785
+ }
49786
+
49382
49787
  // visio/edit-guide-commands.ts
49383
49788
  var isVisioGuideEdit = (edit) => edit.type === "create-guide" || edit.type === "move-guide" || edit.type === "delete-guide";
49384
49789
  function snapshotGuideEdit(edit) {
@@ -49958,6 +50363,7 @@ function snapshotVisioEdits(edits, maxEdits, maxText) {
49958
50363
  if (edit.type === "insert-picture") return snapshotPictureInsert(edit);
49959
50364
  if (edit.type === "set-page-theme") return snapshotPageTheme(edit);
49960
50365
  if (edit.type === "assign-layers") return snapshotAssignLayers(edit);
50366
+ if (edit.type === "set-layer-properties") return snapshotLayerProperties(edit);
49961
50367
  if (isVisioGuideEdit(edit)) return snapshotGuideEdit(edit);
49962
50368
  if (isVisioMetadataEdit(edit)) return snapshotMetadataEdit(edit);
49963
50369
  if (isVisioGroupEdit(edit)) return snapshotGroupEdit(edit);
@@ -51868,177 +52274,6 @@ function analyzeVisioMasterFormula(source2, options) {
51868
52274
  return { ...analysis, references: [...references.values()], dynamic: dynamic2, readsText, readsTheme };
51869
52275
  }
51870
52276
 
51871
- // visio/edit-master-index.ts
51872
- function inheritedProtection(node2, ancestor) {
51873
- try {
51874
- const boolean2 = (cell) => {
51875
- if (!cell || cell.hasAttribute("E"))
51876
- fail2("EDIT_PROTECTED_CELL", "Inherited protection has an unresolved or error cache.");
51877
- const value = visioFormulaCachedValue(attribute3(cell, "V") ?? "", attribute3(cell, "U"));
51878
- if (value.unit !== "scalar" || ![0, 1].includes(value.value))
51879
- fail2("EDIT_PROTECTED_CELL", "Inherited protection requires scalar boolean caches.");
51880
- return value.value;
51881
- };
51882
- if (boolean2(node2) !== boolean2(ancestor))
51883
- fail2(
51884
- "EDIT_PROTECTED_CELL",
51885
- "Delegated master style protection cache disagrees with its ancestor."
51886
- );
51887
- } catch (error) {
51888
- fail2(
51889
- "EDIT_PROTECTED_CELL",
51890
- `Inherited master style protection cannot be proven: ${error instanceof Error ? error.message : "invalid cache"}`
51891
- );
51892
- }
51893
- }
51894
- function masterCells(sheet, charge = () => {
51895
- }) {
51896
- const result2 = /* @__PURE__ */ new Map();
51897
- if (!sheet) return result2;
51898
- const add3 = (name3, node2) => {
51899
- charge();
51900
- const id3 = name3.toLowerCase();
51901
- if (result2.has(id3) && result2.get(id3) !== node2)
51902
- fail2("EDIT_UNSUPPORTED_PACKAGE_DEPENDENCY", "Ambiguous effective master cells.");
51903
- result2.set(id3, node2);
51904
- };
51905
- for (const node2 of children3(sheet, "Cell")) add3(attribute3(node2, "N") ?? "", node2);
51906
- for (const section2 of children3(sheet, "Section")) {
51907
- const name3 = attribute3(section2, "N") ?? "";
51908
- const prefix2 = name3 === "Geometry" ? `Geometry${Number(attribute3(section2, "IX") ?? "0") + 1}` : name3 === "Control" ? "Controls" : name3;
51909
- for (const node2 of children3(section2, "Cell"))
51910
- add3(`${prefix2}.${attribute3(node2, "N") ?? ""}`, node2);
51911
- for (const row3 of children3(section2, "Row"))
51912
- for (const node2 of children3(row3, "Cell")) {
51913
- const n = attribute3(node2, "N") ?? "";
51914
- const rowName = attribute3(row3, "N");
51915
- const index2 = attribute3(row3, "IX") ?? (prefix2 === "Controls" && /^Row_\d+$/.test(rowName ?? "") ? String(Number(rowName.slice(4)) - 1) : void 0);
51916
- const ix = index2 ?? "0", r = rowName ?? (prefix2 === "Controls" ? `Row_${Number(ix) + 1}` : ix);
51917
- add3(
51918
- name3 === "Geometry" || ["Controls", "Scratch", "Connection"].includes(prefix2) ? `${prefix2}.${n}${ix}` : n === "Value" && ["User", "Prop"].includes(name3) ? `${prefix2}.${r}` : `${prefix2}.${r}.${n}`,
51919
- node2
51920
- );
51921
- if (name3 !== "Geometry") add3(`${prefix2}.${r}.${n}`, node2);
51922
- if (prefix2 === "Controls" && n === "X") add3(`${prefix2}.${r}`, node2);
51923
- if (name3 !== "Geometry" && index2 !== void 0) add3(`${prefix2}.$row${ix}.${n}`, node2);
51924
- }
51925
- }
51926
- return result2;
51927
- }
51928
- function masterShapes(root) {
51929
- const result2 = [], pending2 = [root];
51930
- while (pending2.length) {
51931
- const parent = pending2.pop();
51932
- for (const container of children3(parent, "Shapes"))
51933
- for (const shape2 of children3(container, "Shape")) {
51934
- result2.push(shape2);
51935
- pending2.push(shape2);
51936
- }
51937
- }
51938
- return result2;
51939
- }
51940
- function assertMasterMarkup(root, known, check3) {
51941
- for (const node2 of [root, ...Array.from(root.getElementsByTagName("*"))]) {
51942
- check3();
51943
- if (node2.namespaceURI === root.namespaceURI && node2.hasAttribute("F") && !known.has(node2))
51944
- fail2(
51945
- "EDIT_UNSUPPORTED_PACKAGE_DEPENDENCY",
51946
- "Master formula outside admitted sheet cells has unknown scope."
51947
- );
51948
- }
51949
- }
51950
- function masterStyleCells(document, template, instance, check3, charge = () => {
51951
- }, verifyMovementProtection = false) {
51952
- const styles = /* @__PURE__ */ new Map();
51953
- for (const container of children3(document, "StyleSheets"))
51954
- for (const style3 of children3(container, "StyleSheet")) {
51955
- charge();
51956
- const id3 = attribute3(style3, "ID");
51957
- if (!id3 || styles.has(id3))
51958
- fail2("EDIT_UNSUPPORTED_PACKAGE_DEPENDENCY", "Ambiguous master style IDs.");
51959
- styles.set(id3, style3);
51960
- }
51961
- const defaults = children3(document, "DocumentSheet")[0];
51962
- const collect = (id3, category, seen = /* @__PURE__ */ new Set()) => {
51963
- check3();
51964
- if (seen.has(id3) || seen.size >= 64)
51965
- fail2("EDIT_UNSUPPORTED_PACKAGE_DEPENDENCY", "Invalid inherited master style ancestry.");
51966
- seen.add(id3);
51967
- const style3 = styles.get(id3);
51968
- if (!style3) fail2("EDIT_UNSUPPORTED_PACKAGE_DEPENDENCY", "Missing inherited master style.");
51969
- const own = masterCells(style3, charge);
51970
- assertMasterMarkup(style3, new Set(own.values()), check3);
51971
- const parent = attribute3(style3, category);
51972
- const result3 = parent !== void 0 && parent !== id3 ? collect(parent, category, seen) : /* @__PURE__ */ new Map();
51973
- for (const [name3, node2] of own) {
51974
- charge();
51975
- if (attribute3(node2, "F") !== "Inh") result3.set(name3, node2);
51976
- else if (verifyMovementProtection && /^lock(move[xy]|width|height|aspect|delete)$/.test(name3)) {
51977
- charge();
51978
- inheritedProtection(node2, result3.get(name3));
51979
- }
51980
- }
51981
- return result3;
51982
- };
51983
- const result2 = /* @__PURE__ */ new Map();
51984
- for (const category of ["LineStyle", "FillStyle", "TextStyle"]) {
51985
- const id3 = attribute3(instance, category) ?? attribute3(template, category) ?? attribute3(defaults, category) ?? (styles.has("0") ? "0" : void 0);
51986
- if (id3 !== void 0)
51987
- for (const [name3, node2] of collect(id3, category)) {
51988
- charge();
51989
- if (result2.has(name3) && result2.get(name3) !== node2)
51990
- fail2(
51991
- "EDIT_UNSUPPORTED_PACKAGE_DEPENDENCY",
51992
- "Master style categories have ambiguous overlapping inputs."
51993
- );
51994
- result2.set(name3, node2);
51995
- }
51996
- }
51997
- return result2;
51998
- }
51999
- function overlay(cells3, additions, kind, charge) {
52000
- const aliases = /* @__PURE__ */ new Map(), inherited = /* @__PURE__ */ new Map();
52001
- for (const [name3, source2] of cells3) {
52002
- charge();
52003
- const names = aliases.get(source2.node) ?? /* @__PURE__ */ new Set();
52004
- names.add(name3);
52005
- aliases.set(source2.node, names);
52006
- }
52007
- for (const [name3, node2] of additions) {
52008
- charge();
52009
- const source2 = cells3.get(name3);
52010
- if (source2) inherited.set(node2, source2);
52011
- }
52012
- for (const [name3, node2] of additions) {
52013
- charge();
52014
- if (attribute3(node2, "F") === "Inh") {
52015
- const source2 = cells3.get(name3) ?? inherited.get(node2);
52016
- if (!source2)
52017
- fail2(
52018
- "EDIT_UNSUPPORTED_PACKAGE_DEPENDENCY",
52019
- "Inherited master cell has no effective source."
52020
- );
52021
- cells3.set(name3, source2);
52022
- const names2 = aliases.get(source2.node) ?? /* @__PURE__ */ new Set();
52023
- names2.add(name3);
52024
- aliases.set(source2.node, names2);
52025
- continue;
52026
- }
52027
- const previous = cells3.get(name3), names = aliases.get(node2) ?? /* @__PURE__ */ new Set();
52028
- if (previous && previous.node !== node2) {
52029
- for (const alias of aliases.get(previous.node) ?? []) {
52030
- charge();
52031
- cells3.set(alias, { node: node2, kind });
52032
- names.add(alias);
52033
- }
52034
- aliases.delete(previous.node);
52035
- }
52036
- cells3.set(name3, { node: node2, kind });
52037
- names.add(name3);
52038
- aliases.set(node2, names);
52039
- }
52040
- }
52041
-
52042
52277
  // visio/edit-master-scope.ts
52043
52278
  function problem(message) {
52044
52279
  return fail2("EDIT_UNSUPPORTED_PACKAGE_DEPENDENCY", message);
@@ -56973,6 +57208,21 @@ async function editVsdxTransaction(input, edits, options, clock = { deadline: 0,
56973
57208
  check3
56974
57209
  );
56975
57210
  }
57211
+ const layerFlags = allCommands.filter((command2) => command2.type === "set-layer-properties");
57212
+ if (layerFlags.length) {
57213
+ if (layerFlags.length !== allCommands.length)
57214
+ fail2("EDIT_MIXED_LAYER_TRANSACTION", "Layer properties require their own transaction.");
57215
+ return editVsdxLayerProperties(
57216
+ pkg,
57217
+ parts,
57218
+ pages,
57219
+ layerFlags,
57220
+ limits,
57221
+ maxOutput,
57222
+ deadline,
57223
+ check3
57224
+ );
57225
+ }
56976
57226
  const layers = allCommands.filter((command2) => command2.type === "assign-layers");
56977
57227
  if (layers.length) {
56978
57228
  if (layers.length !== allCommands.length)
@@ -57154,7 +57404,7 @@ async function editVsdxTransaction(input, edits, options, clock = { deadline: 0,
57154
57404
  ))
57155
57405
  dirty.set(pages.get(pageId2), roots.get(pageId2));
57156
57406
  duplicateChanged = true;
57157
- } else if (command2.type !== "insert-picture" && command2.type !== "set-page-theme" && command2.type !== "create-subprocess" && !isVisioCommentEdit(command2) && !isVisioDataEdit(command2) && command2.type !== "assign-layers") {
57407
+ } else if (command2.type !== "insert-picture" && command2.type !== "set-page-theme" && command2.type !== "create-subprocess" && !isVisioCommentEdit(command2) && !isVisioDataEdit(command2) && command2.type !== "assign-layers" && command2.type !== "set-layer-properties") {
57158
57408
  for (const pageId2 of applyGeometryEdit(roots, document, command2, check3, masterMovePins))
57159
57409
  dirty.set(pages.get(pageId2), roots.get(pageId2));
57160
57410
  }