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