ooxml-core 0.9.0 → 0.11.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.
- package/README.md +14 -13
- package/dist/automation/docx.d.ts +13 -0
- package/dist/automation/docx.d.ts.map +1 -0
- package/dist/automation/index.cjs +36838 -0
- package/dist/automation/index.d.ts +6 -0
- package/dist/automation/index.d.ts.map +1 -0
- package/dist/automation/index.mjs +36824 -0
- package/dist/automation/node.cjs +103 -0
- package/dist/automation/node.d.ts +16 -0
- package/dist/automation/node.d.ts.map +1 -0
- package/dist/automation/node.mjs +101 -0
- package/dist/automation/visio.d.ts +30 -0
- package/dist/automation/visio.d.ts.map +1 -0
- package/dist/automation/xlsx.d.ts +25 -0
- package/dist/automation/xlsx.d.ts.map +1 -0
- package/dist/crypto/aes-ecb.d.ts +13 -0
- package/dist/crypto/aes-ecb.d.ts.map +1 -0
- package/dist/crypto/decrypt.d.ts +63 -0
- package/dist/crypto/decrypt.d.ts.map +1 -0
- package/dist/crypto/detect.d.ts +56 -0
- package/dist/crypto/detect.d.ts.map +1 -0
- package/dist/crypto/encrypt.d.ts +27 -0
- package/dist/crypto/encrypt.d.ts.map +1 -0
- package/dist/crypto/encryption-info-write.d.ts +46 -0
- package/dist/crypto/encryption-info-write.d.ts.map +1 -0
- package/dist/crypto/encryption-info.d.ts +22 -0
- package/dist/crypto/encryption-info.d.ts.map +1 -0
- package/dist/crypto/errors.d.ts +39 -0
- package/dist/crypto/errors.d.ts.map +1 -0
- package/dist/crypto/index.cjs +1805 -0
- package/dist/crypto/index.d.ts +26 -0
- package/dist/crypto/index.d.ts.map +1 -0
- package/dist/crypto/index.mjs +1774 -0
- package/dist/crypto/key-derivation.d.ts +73 -0
- package/dist/crypto/key-derivation.d.ts.map +1 -0
- package/dist/crypto/types.d.ts +104 -0
- package/dist/crypto/types.d.ts.map +1 -0
- package/dist/docx/embedded.cjs +2 -0
- package/dist/docx/embedded.mjs +2 -0
- package/dist/docx/index.cjs +2 -0
- package/dist/docx/index.mjs +2 -0
- package/dist/docx/load/detect.d.ts +14 -2
- package/dist/docx/load/detect.d.ts.map +1 -1
- package/dist/docx/load/index.cjs +8995 -7728
- package/dist/docx/load/index.d.ts +3 -1
- package/dist/docx/load/index.d.ts.map +1 -1
- package/dist/docx/load/index.mjs +8990 -7729
- package/dist/docx/load/legacy-doc.d.ts.map +1 -1
- package/dist/index.cjs +749 -19
- package/dist/index.mjs +749 -19
- package/dist/opc/index.cjs +797 -1
- package/dist/opc/index.d.ts +2 -0
- package/dist/opc/index.d.ts.map +1 -1
- package/dist/opc/index.mjs +784 -3
- package/dist/opc/properties/app.d.ts +10 -0
- package/dist/opc/properties/app.d.ts.map +1 -0
- package/dist/opc/properties/core.d.ts +13 -0
- package/dist/opc/properties/core.d.ts.map +1 -0
- package/dist/opc/properties/custom.d.ts +15 -0
- package/dist/opc/properties/custom.d.ts.map +1 -0
- package/dist/opc/properties/index.d.ts +5 -0
- package/dist/opc/properties/index.d.ts.map +1 -0
- package/dist/opc/properties/types.d.ts +114 -0
- package/dist/opc/properties/types.d.ts.map +1 -0
- package/dist/opc/relationship-types.d.ts +1 -0
- package/dist/opc/relationship-types.d.ts.map +1 -1
- package/dist/opc/safe-href.d.ts +34 -0
- package/dist/opc/safe-href.d.ts.map +1 -1
- package/dist/opc/signature/constants.d.ts +42 -0
- package/dist/opc/signature/constants.d.ts.map +1 -0
- package/dist/opc/signature/detection.d.ts +97 -0
- package/dist/opc/signature/detection.d.ts.map +1 -0
- package/dist/opc/signature/digest.d.ts +16 -0
- package/dist/opc/signature/digest.d.ts.map +1 -0
- package/dist/opc/signature/index.d.ts +8 -0
- package/dist/opc/signature/index.d.ts.map +1 -0
- package/dist/opc/signature/inspection-status.d.ts +24 -0
- package/dist/opc/signature/inspection-status.d.ts.map +1 -0
- package/dist/opc/signature/reference-utils.d.ts +12 -0
- package/dist/opc/signature/reference-utils.d.ts.map +1 -0
- package/dist/opc/signature/types.d.ts +90 -0
- package/dist/opc/signature/types.d.ts.map +1 -0
- package/dist/opc/signature/xml-utils.d.ts +35 -0
- package/dist/opc/signature/xml-utils.d.ts.map +1 -0
- package/dist/pptx/automation/index.cjs +149047 -0
- package/dist/pptx/automation/index.d.ts +1474 -0
- package/dist/pptx/automation/index.d.ts.map +1 -0
- package/dist/pptx/automation/index.mjs +148926 -0
- package/dist/pptx/chunks/{index-CojJtI77.d.ts → index-BWRd8p4y.d.ts} +10 -12
- package/dist/pptx/chunks/index-BWRd8p4y.d.ts.map +1 -0
- package/dist/pptx/chunks/index-LoCVDu8Z.d.ts +9644 -0
- package/dist/pptx/chunks/index-LoCVDu8Z.d.ts.map +1 -0
- package/dist/pptx/chunks/{signature-inspection-status-Bh2oap7B.d.ts → inspection-status-B2E-jSpG.d.ts} +8 -8
- package/dist/pptx/chunks/inspection-status-B2E-jSpG.d.ts.map +1 -0
- package/dist/pptx/chunks/{text-operations-IlJiffp7.d.ts → text-operations-2tKzrY5o.d.ts} +7381 -7381
- package/dist/pptx/chunks/text-operations-2tKzrY5o.d.ts.map +1 -0
- package/dist/pptx/cli/index.cjs +1409 -895
- package/dist/pptx/cli/index.d.ts +1 -1
- package/dist/pptx/cli/index.mjs +1409 -895
- package/dist/pptx/converter/index.d.ts +1 -1
- package/dist/pptx/index.cjs +1933 -1391
- package/dist/pptx/index.d.ts +5 -9692
- package/dist/pptx/index.mjs +1933 -1391
- package/dist/pptx/signature-node/index.cjs +5 -5
- package/dist/pptx/signature-node/index.d.ts +1 -1
- package/dist/pptx/signature-node/index.mjs +5 -5
- package/dist/visio/edit-geometry-admission.d.ts +1 -1
- package/dist/visio/edit-geometry-admission.d.ts.map +1 -1
- package/dist/visio/edit-geometry.d.ts +1 -1
- package/dist/visio/edit-geometry.d.ts.map +1 -1
- package/dist/visio/edit-master-index.d.ts +10 -0
- package/dist/visio/edit-master-index.d.ts.map +1 -0
- package/dist/visio/edit-master-move.d.ts +12 -0
- package/dist/visio/edit-master-move.d.ts.map +1 -0
- package/dist/visio/edit-master-scope.d.ts +7 -0
- package/dist/visio/edit-master-scope.d.ts.map +1 -0
- package/dist/visio/edit-recalculate-index.d.ts +2 -0
- package/dist/visio/edit-recalculate-index.d.ts.map +1 -1
- package/dist/visio/edit-scope.d.ts +1 -1
- package/dist/visio/edit-scope.d.ts.map +1 -1
- package/dist/visio/edit.d.ts.map +1 -1
- package/dist/visio/formula-arithmetic.d.ts +8 -0
- package/dist/visio/formula-arithmetic.d.ts.map +1 -0
- package/dist/visio/formula-evaluate.d.ts.map +1 -1
- package/dist/visio/formula-master.d.ts +13 -0
- package/dist/visio/formula-master.d.ts.map +1 -0
- package/dist/visio/formula-numeric-functions.d.ts +8 -0
- package/dist/visio/formula-numeric-functions.d.ts.map +1 -0
- package/dist/visio/formula.d.ts +1 -1
- package/dist/visio/formula.d.ts.map +1 -1
- package/dist/visio/index.cjs +687 -71
- package/dist/visio/index.mjs +687 -71
- package/dist/xlsx/edit/annotations.d.ts +5 -1
- package/dist/xlsx/edit/annotations.d.ts.map +1 -1
- package/dist/xlsx/edit/cell-values.d.ts +7 -2
- package/dist/xlsx/edit/cell-values.d.ts.map +1 -1
- package/dist/xlsx/edit/clipboard.d.ts.map +1 -1
- package/dist/xlsx/edit/doc-properties.d.ts +14 -0
- package/dist/xlsx/edit/doc-properties.d.ts.map +1 -0
- package/dist/xlsx/edit/fill-series.d.ts.map +1 -1
- package/dist/xlsx/edit/find.d.ts +2 -1
- package/dist/xlsx/edit/find.d.ts.map +1 -1
- package/dist/xlsx/edit/format-lines.d.ts +22 -0
- package/dist/xlsx/edit/format-lines.d.ts.map +1 -0
- package/dist/xlsx/edit/format.d.ts +2 -1
- package/dist/xlsx/edit/format.d.ts.map +1 -1
- package/dist/xlsx/edit/history-refs.d.ts +51 -0
- package/dist/xlsx/edit/history-refs.d.ts.map +1 -0
- package/dist/xlsx/edit/history.d.ts +40 -5
- package/dist/xlsx/edit/history.d.ts.map +1 -1
- package/dist/xlsx/edit/index.d.ts +3 -0
- package/dist/xlsx/edit/index.d.ts.map +1 -1
- package/dist/xlsx/edit/input-text.d.ts +13 -0
- package/dist/xlsx/edit/input-text.d.ts.map +1 -0
- package/dist/xlsx/edit/merge.d.ts +10 -2
- package/dist/xlsx/edit/merge.d.ts.map +1 -1
- package/dist/xlsx/edit/session.d.ts.map +1 -1
- package/dist/xlsx/edit/sheets.d.ts.map +1 -1
- package/dist/xlsx/edit/shift-formulas.d.ts +2 -1
- package/dist/xlsx/edit/shift-formulas.d.ts.map +1 -1
- package/dist/xlsx/edit/shift-preserved.d.ts +17 -0
- package/dist/xlsx/edit/shift-preserved.d.ts.map +1 -0
- package/dist/xlsx/edit/shift-sheet.d.ts +2 -2
- package/dist/xlsx/edit/shift-sheet.d.ts.map +1 -1
- package/dist/xlsx/edit/structure.d.ts.map +1 -1
- package/dist/xlsx/edit/types.d.ts +7 -0
- package/dist/xlsx/edit/types.d.ts.map +1 -1
- package/dist/xlsx/edit/validation-list.d.ts +24 -0
- package/dist/xlsx/edit/validation-list.d.ts.map +1 -0
- package/dist/xlsx/edit/validation.d.ts +2 -1
- package/dist/xlsx/edit/validation.d.ts.map +1 -1
- package/dist/xlsx/formula/area-index.d.ts +18 -0
- package/dist/xlsx/formula/area-index.d.ts.map +1 -0
- package/dist/xlsx/formula/array-context.d.ts.map +1 -1
- package/dist/xlsx/formula/ast.d.ts +5 -1
- package/dist/xlsx/formula/ast.d.ts.map +1 -1
- package/dist/xlsx/formula/call.d.ts.map +1 -1
- package/dist/xlsx/formula/coerce.d.ts.map +1 -1
- package/dist/xlsx/formula/context.d.ts +5 -0
- package/dist/xlsx/formula/context.d.ts.map +1 -1
- package/dist/xlsx/formula/date-serial.d.ts +11 -4
- package/dist/xlsx/formula/date-serial.d.ts.map +1 -1
- package/dist/xlsx/formula/engine-core.d.ts +6 -0
- package/dist/xlsx/formula/engine-core.d.ts.map +1 -1
- package/dist/xlsx/formula/engine-host.d.ts +35 -3
- package/dist/xlsx/formula/engine-host.d.ts.map +1 -1
- package/dist/xlsx/formula/engine-util.d.ts.map +1 -1
- package/dist/xlsx/formula/engine.d.ts.map +1 -1
- package/dist/xlsx/formula/evaluator.d.ts.map +1 -1
- package/dist/xlsx/formula/functions/array-shape.d.ts.map +1 -1
- package/dist/xlsx/formula/functions/array.d.ts.map +1 -1
- package/dist/xlsx/formula/functions/criteria-index.d.ts +12 -0
- package/dist/xlsx/formula/functions/criteria-index.d.ts.map +1 -0
- package/dist/xlsx/formula/functions/criteria.d.ts +24 -16
- package/dist/xlsx/formula/functions/criteria.d.ts.map +1 -1
- package/dist/xlsx/formula/functions/date-calc.d.ts +4 -0
- package/dist/xlsx/formula/functions/date-calc.d.ts.map +1 -1
- package/dist/xlsx/formula/functions/depreciation.d.ts.map +1 -1
- package/dist/xlsx/formula/functions/financial.d.ts.map +1 -1
- package/dist/xlsx/formula/functions/helpers.d.ts.map +1 -1
- package/dist/xlsx/formula/functions/logical.d.ts.map +1 -1
- package/dist/xlsx/formula/functions/lookup-core.d.ts +14 -2
- package/dist/xlsx/formula/functions/lookup-core.d.ts.map +1 -1
- package/dist/xlsx/formula/functions/lookup.d.ts.map +1 -1
- package/dist/xlsx/formula/functions/math-mod.d.ts +8 -0
- package/dist/xlsx/formula/functions/math-mod.d.ts.map +1 -0
- package/dist/xlsx/formula/functions/math-sum.d.ts.map +1 -1
- package/dist/xlsx/formula/functions/math.d.ts.map +1 -1
- package/dist/xlsx/formula/functions/statistical-count.d.ts.map +1 -1
- package/dist/xlsx/formula/functions/statistical.d.ts.map +1 -1
- package/dist/xlsx/formula/functions/stats-core.d.ts +6 -0
- package/dist/xlsx/formula/functions/stats-core.d.ts.map +1 -1
- package/dist/xlsx/formula/functions/text-case.d.ts +14 -0
- package/dist/xlsx/formula/functions/text-case.d.ts.map +1 -0
- package/dist/xlsx/formula/functions/text.d.ts.map +1 -1
- package/dist/xlsx/formula/functions/workdays.d.ts.map +1 -1
- package/dist/xlsx/formula/graph-index.d.ts +15 -0
- package/dist/xlsx/formula/graph-index.d.ts.map +1 -0
- package/dist/xlsx/formula/graph.d.ts +13 -18
- package/dist/xlsx/formula/graph.d.ts.map +1 -1
- package/dist/xlsx/formula/operators.d.ts +9 -0
- package/dist/xlsx/formula/operators.d.ts.map +1 -1
- package/dist/xlsx/formula/parser.d.ts +2 -0
- package/dist/xlsx/formula/parser.d.ts.map +1 -1
- package/dist/xlsx/formula/references.d.ts +4 -1
- package/dist/xlsx/formula/references.d.ts.map +1 -1
- package/dist/xlsx/formula/text-number.d.ts.map +1 -1
- package/dist/xlsx/formula/transform.d.ts.map +1 -1
- package/dist/xlsx/formula/values.d.ts +44 -3
- package/dist/xlsx/formula/values.d.ts.map +1 -1
- package/dist/xlsx/index.cjs +4698 -1322
- package/dist/xlsx/index.mjs +4688 -1323
- package/dist/xlsx/layout/anchors.d.ts +47 -0
- package/dist/xlsx/layout/anchors.d.ts.map +1 -0
- package/dist/xlsx/layout/cf-evaluator.d.ts +1 -2
- package/dist/xlsx/layout/cf-evaluator.d.ts.map +1 -1
- package/dist/xlsx/layout/cf-helpers.d.ts +8 -1
- package/dist/xlsx/layout/cf-helpers.d.ts.map +1 -1
- package/dist/xlsx/layout/index.d.ts +1 -0
- package/dist/xlsx/layout/index.d.ts.map +1 -1
- package/dist/xlsx/load/csv.d.ts +24 -3
- package/dist/xlsx/load/csv.d.ts.map +1 -1
- package/dist/xlsx/load/detect.d.ts +39 -7
- package/dist/xlsx/load/detect.d.ts.map +1 -1
- package/dist/xlsx/load/errors.d.ts +10 -0
- package/dist/xlsx/load/errors.d.ts.map +1 -0
- package/dist/xlsx/load/index.cjs +16220 -12163
- package/dist/xlsx/load/index.d.ts +5 -2
- package/dist/xlsx/load/index.d.ts.map +1 -1
- package/dist/xlsx/load/index.mjs +16213 -12164
- package/dist/xlsx/load/text-decode.d.ts +7 -0
- package/dist/xlsx/load/text-decode.d.ts.map +1 -0
- package/dist/xlsx/model.d.ts +121 -17
- package/dist/xlsx/model.d.ts.map +1 -1
- package/dist/xlsx/numfmt/date.d.ts +7 -0
- package/dist/xlsx/numfmt/date.d.ts.map +1 -1
- package/dist/xlsx/numfmt/format.d.ts.map +1 -1
- package/dist/xlsx/numfmt/fraction.d.ts +5 -1
- package/dist/xlsx/numfmt/fraction.d.ts.map +1 -1
- package/dist/xlsx/numfmt/input-date.d.ts.map +1 -1
- package/dist/xlsx/numfmt/input.d.ts.map +1 -1
- package/dist/xlsx/numfmt/number.d.ts.map +1 -1
- package/dist/xlsx/read/conditional.d.ts.map +1 -1
- package/dist/xlsx/read/drawing.d.ts +2 -2
- package/dist/xlsx/read/drawing.d.ts.map +1 -1
- package/dist/xlsx/read/load.d.ts.map +1 -1
- package/dist/xlsx/read/package.d.ts +18 -2
- package/dist/xlsx/read/package.d.ts.map +1 -1
- package/dist/xlsx/read/sheet-data.d.ts.map +1 -1
- package/dist/xlsx/read/sheet-props.d.ts +15 -1
- package/dist/xlsx/read/sheet-props.d.ts.map +1 -1
- package/dist/xlsx/read/smart-art.d.ts +12 -0
- package/dist/xlsx/read/smart-art.d.ts.map +1 -0
- package/dist/xlsx/read/styles.d.ts.map +1 -1
- package/dist/xlsx/read/workbook-part.d.ts +5 -2
- package/dist/xlsx/read/workbook-part.d.ts.map +1 -1
- package/dist/xlsx/read/worksheet.d.ts.map +1 -1
- package/dist/xlsx/write/attr-merge.d.ts +10 -0
- package/dist/xlsx/write/attr-merge.d.ts.map +1 -0
- package/dist/xlsx/write/carried-refs.d.ts +61 -0
- package/dist/xlsx/write/carried-refs.d.ts.map +1 -0
- package/dist/xlsx/write/comments.d.ts +12 -2
- package/dist/xlsx/write/comments.d.ts.map +1 -1
- package/dist/xlsx/write/conditional.d.ts.map +1 -1
- package/dist/xlsx/write/doc-props.d.ts +30 -0
- package/dist/xlsx/write/doc-props.d.ts.map +1 -0
- package/dist/xlsx/write/drawing.d.ts +5 -0
- package/dist/xlsx/write/drawing.d.ts.map +1 -1
- package/dist/xlsx/write/metadata.d.ts +23 -0
- package/dist/xlsx/write/metadata.d.ts.map +1 -0
- package/dist/xlsx/write/package-writer.d.ts +6 -0
- package/dist/xlsx/write/package-writer.d.ts.map +1 -1
- package/dist/xlsx/write/page-setup.d.ts +8 -0
- package/dist/xlsx/write/page-setup.d.ts.map +1 -0
- package/dist/xlsx/write/save.d.ts.map +1 -1
- package/dist/xlsx/write/sheet-data.d.ts +8 -0
- package/dist/xlsx/write/sheet-data.d.ts.map +1 -1
- package/dist/xlsx/write/sheet-parts.d.ts +6 -0
- package/dist/xlsx/write/sheet-parts.d.ts.map +1 -1
- package/dist/xlsx/write/sheet-props.d.ts +0 -6
- package/dist/xlsx/write/sheet-props.d.ts.map +1 -1
- package/dist/xlsx/write/styles.d.ts.map +1 -1
- package/dist/xlsx/write/table-patch.d.ts +12 -0
- package/dist/xlsx/write/table-patch.d.ts.map +1 -0
- package/dist/xlsx/write/tables.d.ts +9 -0
- package/dist/xlsx/write/tables.d.ts.map +1 -1
- package/dist/xlsx/write/vml-ids.d.ts +29 -0
- package/dist/xlsx/write/vml-ids.d.ts.map +1 -0
- package/dist/xlsx/write/workbook-part.d.ts +1 -4
- package/dist/xlsx/write/workbook-part.d.ts.map +1 -1
- package/dist/xlsx/write/worksheet.d.ts.map +1 -1
- package/dist/xml/index.cjs +4 -0
- package/dist/xml/index.mjs +4 -0
- package/dist/xml/namespaces.d.ts +4 -0
- package/dist/xml/namespaces.d.ts.map +1 -1
- package/package.json +26 -3
- package/dist/pptx/chunks/index-CojJtI77.d.ts.map +0 -1
- package/dist/pptx/chunks/signature-inspection-status-Bh2oap7B.d.ts.map +0 -1
- package/dist/pptx/chunks/text-operations-IlJiffp7.d.ts.map +0 -1
- package/dist/pptx/index.d.ts.map +0 -1
package/dist/visio/index.cjs
CHANGED
|
@@ -4356,6 +4356,8 @@ function isSafeHyperlinkHref(href) {
|
|
|
4356
4356
|
const scheme = /^([a-z][a-z0-9+.-]*:)/i.exec(href.trim())?.[1];
|
|
4357
4357
|
return scheme !== void 0 && SAFE_SCHEMES.has(scheme.toLowerCase());
|
|
4358
4358
|
}
|
|
4359
|
+
var OPEN_SCHEMES = /* @__PURE__ */ new Set(["http", "https", "mailto"]);
|
|
4360
|
+
/* @__PURE__ */ new Set([...OPEN_SCHEMES, "ftp", "file"]);
|
|
4359
4361
|
|
|
4360
4362
|
// src/visio/shape-metadata.ts
|
|
4361
4363
|
function createMetadataBudget(options = {}) {
|
|
@@ -4971,16 +4973,16 @@ async function parseVsdx(input, options = {}) {
|
|
|
4971
4973
|
const id = metadata(attribute2(master, "ID") ?? "", 256, "Master ID");
|
|
4972
4974
|
if (!id || masters.has(id))
|
|
4973
4975
|
throw new VisioPackageError("INVALID_MASTER_ID", "Master IDs must be present and unique.");
|
|
4974
|
-
const
|
|
4976
|
+
const masterShapes2 = readShapes(await visioXml(pkg, part, "MasterContents"));
|
|
4975
4977
|
await prepareImages(
|
|
4976
|
-
|
|
4978
|
+
masterShapes2,
|
|
4977
4979
|
pkg,
|
|
4978
4980
|
part,
|
|
4979
4981
|
report,
|
|
4980
4982
|
options.images,
|
|
4981
4983
|
options.metafileConverter
|
|
4982
4984
|
);
|
|
4983
|
-
masters.set(id,
|
|
4985
|
+
masters.set(id, masterShapes2);
|
|
4984
4986
|
}
|
|
4985
4987
|
}
|
|
4986
4988
|
let geometryCount = 0, textCount = 0, expansionCount = 0, textRuns = 0, paragraphCount = 0;
|
|
@@ -5496,6 +5498,105 @@ var themeInputs = [
|
|
|
5496
5498
|
"QuickStyleVariation"
|
|
5497
5499
|
];
|
|
5498
5500
|
|
|
5501
|
+
// src/visio/formula-arithmetic.ts
|
|
5502
|
+
function finiteFormulaValue(value) {
|
|
5503
|
+
if (!Number.isFinite(value.value)) return formulaFailure("value", "Formula result is not finite");
|
|
5504
|
+
if (!["scalar", "length", "area", "angle", "time"].includes(value.unit))
|
|
5505
|
+
return formulaFailure("unit", "Unknown resolved unit");
|
|
5506
|
+
return value;
|
|
5507
|
+
}
|
|
5508
|
+
function compatibleFormulaUnits(a, b) {
|
|
5509
|
+
if (a.unit === b.unit) return a.unit;
|
|
5510
|
+
if (a.unit === "scalar" && a.value === 0) return b.unit;
|
|
5511
|
+
if (b.unit === "scalar" && b.value === 0) return a.unit;
|
|
5512
|
+
return formulaFailure("unit", `Incompatible units ${a.unit} and ${b.unit}`);
|
|
5513
|
+
}
|
|
5514
|
+
var lengthPower = (unit) => unit === "scalar" ? 0 : unit === "length" ? 1 : unit === "area" ? 2 : void 0;
|
|
5515
|
+
function fromPower(power) {
|
|
5516
|
+
if (power === 0) return "scalar";
|
|
5517
|
+
if (power === 1) return "length";
|
|
5518
|
+
if (power === 2) return "area";
|
|
5519
|
+
return formulaFailure("unit", "Unsupported dimensional power");
|
|
5520
|
+
}
|
|
5521
|
+
function formulaProductUnit(a, b) {
|
|
5522
|
+
if (a === "scalar") return b;
|
|
5523
|
+
if (b === "scalar") return a;
|
|
5524
|
+
const left = lengthPower(a), right = lengthPower(b);
|
|
5525
|
+
if (left === void 0 || right === void 0)
|
|
5526
|
+
return formulaFailure("unit", "Mixed dimensions are unsupported");
|
|
5527
|
+
return fromPower(left + right);
|
|
5528
|
+
}
|
|
5529
|
+
function formulaQuotientUnit(a, b) {
|
|
5530
|
+
if (b === "scalar") return a;
|
|
5531
|
+
if (a === b) return "scalar";
|
|
5532
|
+
const left = lengthPower(a), right = lengthPower(b);
|
|
5533
|
+
if (left === void 0 || right === void 0)
|
|
5534
|
+
return formulaFailure("unit", "Mixed dimensions are unsupported");
|
|
5535
|
+
return fromPower(left - right);
|
|
5536
|
+
}
|
|
5537
|
+
function formulaExponentUnit(a, exponent) {
|
|
5538
|
+
if (exponent.unit !== "scalar") return formulaFailure("unit", "Exponents must be scalar");
|
|
5539
|
+
if (a === "scalar") return "scalar";
|
|
5540
|
+
if (exponent.value === 0) return "scalar";
|
|
5541
|
+
if (exponent.value === 1) return a;
|
|
5542
|
+
const power = lengthPower(a);
|
|
5543
|
+
if (power === void 0) return formulaFailure("unit", "Unsupported dimensional power");
|
|
5544
|
+
return fromPower(power * exponent.value);
|
|
5545
|
+
}
|
|
5546
|
+
function formulaSquareRootUnit(unit) {
|
|
5547
|
+
if (unit === "scalar") return "scalar";
|
|
5548
|
+
if (unit === "area") return "length";
|
|
5549
|
+
return formulaFailure("unit", "Square root requires scalar or square inches");
|
|
5550
|
+
}
|
|
5551
|
+
|
|
5552
|
+
// src/visio/formula-numeric-functions.ts
|
|
5553
|
+
var numericFormulaFunctions = /* @__PURE__ */ new Set([
|
|
5554
|
+
"AND",
|
|
5555
|
+
"OR",
|
|
5556
|
+
"NOT",
|
|
5557
|
+
"BITAND",
|
|
5558
|
+
"BITOR",
|
|
5559
|
+
"BITXOR",
|
|
5560
|
+
"MODULUS"
|
|
5561
|
+
]);
|
|
5562
|
+
function evaluateNumericFormulaFunction(name, args) {
|
|
5563
|
+
const arity = (min, max = min) => {
|
|
5564
|
+
if (args.length < min || args.length > max)
|
|
5565
|
+
return formulaFailure("arity", `Invalid ${name} argument count`);
|
|
5566
|
+
};
|
|
5567
|
+
const scalar2 = (value) => ({ value, unit: "scalar" });
|
|
5568
|
+
if (name === "AND" || name === "OR" || name === "NOT") {
|
|
5569
|
+
arity(1, name === "NOT" ? 1 : 1024);
|
|
5570
|
+
const values = args.map((arg) => finiteFormulaValue(arg).value !== 0);
|
|
5571
|
+
return scalar2(
|
|
5572
|
+
Number(
|
|
5573
|
+
name === "AND" ? values.every(Boolean) : name === "OR" ? values.some(Boolean) : !values[0]
|
|
5574
|
+
)
|
|
5575
|
+
);
|
|
5576
|
+
}
|
|
5577
|
+
if (["BITAND", "BITOR", "BITXOR"].includes(name)) {
|
|
5578
|
+
arity(2);
|
|
5579
|
+
const values = args.map((arg) => {
|
|
5580
|
+
if (arg.unit !== "scalar") return formulaFailure("unit", `${name} requires scalar bitmasks`);
|
|
5581
|
+
if (!Number.isInteger(arg.value) || arg.value < 0 || arg.value > 65535)
|
|
5582
|
+
return formulaFailure("value", `${name} requires an integer from 0 to 65535`);
|
|
5583
|
+
return arg.value;
|
|
5584
|
+
});
|
|
5585
|
+
return scalar2(
|
|
5586
|
+
name === "BITAND" ? values[0] & values[1] : name === "BITOR" ? values[0] | values[1] : values[0] ^ values[1]
|
|
5587
|
+
);
|
|
5588
|
+
}
|
|
5589
|
+
if (name === "MODULUS") {
|
|
5590
|
+
arity(2);
|
|
5591
|
+
const dividend = finiteFormulaValue(args[0]), divisor = finiteFormulaValue(args[1]);
|
|
5592
|
+
const unit = compatibleFormulaUnits(dividend, divisor);
|
|
5593
|
+
if (divisor.value === 0) return formulaFailure("value", "MODULUS division by zero");
|
|
5594
|
+
const remainder = dividend.value - Math.floor(dividend.value / divisor.value) * divisor.value;
|
|
5595
|
+
return finiteFormulaValue({ value: remainder === 0 ? 0 : remainder, unit });
|
|
5596
|
+
}
|
|
5597
|
+
return formulaFailure("unsupported", `Unsupported numeric function ${name}`);
|
|
5598
|
+
}
|
|
5599
|
+
|
|
5499
5600
|
// src/visio/formula-evaluate.ts
|
|
5500
5601
|
var supported = /* @__PURE__ */ new Set([
|
|
5501
5602
|
"GUARD",
|
|
@@ -5509,7 +5610,8 @@ var supported = /* @__PURE__ */ new Set([
|
|
|
5509
5610
|
"TAN",
|
|
5510
5611
|
"ATAN2",
|
|
5511
5612
|
"SIGN",
|
|
5512
|
-
"PI"
|
|
5613
|
+
"PI",
|
|
5614
|
+
...numericFormulaFunctions
|
|
5513
5615
|
]);
|
|
5514
5616
|
var staticUnsupported = /* @__PURE__ */ new Set([
|
|
5515
5617
|
"ROUND",
|
|
@@ -5541,7 +5643,9 @@ var staticUnsupported = /* @__PURE__ */ new Set([
|
|
|
5541
5643
|
"BITXOR",
|
|
5542
5644
|
"TINT",
|
|
5543
5645
|
"MSOTINT",
|
|
5544
|
-
"SHADE"
|
|
5646
|
+
"SHADE",
|
|
5647
|
+
"LUMDIFF",
|
|
5648
|
+
"MODULUS"
|
|
5545
5649
|
]);
|
|
5546
5650
|
var dynamic = /* @__PURE__ */ new Set([
|
|
5547
5651
|
"INDIRECT",
|
|
@@ -5600,41 +5704,23 @@ function analyzeVisioFormula(source, limits = {}) {
|
|
|
5600
5704
|
guarded
|
|
5601
5705
|
};
|
|
5602
5706
|
}
|
|
5603
|
-
function finite2(value) {
|
|
5604
|
-
if (!Number.isFinite(value.value)) return formulaFailure("value", "Formula result is not finite");
|
|
5605
|
-
if (!["scalar", "length", "angle", "time"].includes(value.unit))
|
|
5606
|
-
return formulaFailure("unit", "Unknown resolved unit");
|
|
5607
|
-
return value;
|
|
5608
|
-
}
|
|
5609
|
-
function compatible(a, b) {
|
|
5610
|
-
if (a.unit === b.unit) return a.unit;
|
|
5611
|
-
if (a.unit === "scalar" && a.value === 0) return b.unit;
|
|
5612
|
-
if (b.unit === "scalar" && b.value === 0) return a.unit;
|
|
5613
|
-
return formulaFailure("unit", `Incompatible units ${a.unit} and ${b.unit}`);
|
|
5614
|
-
}
|
|
5615
5707
|
function binary(operator, a, b) {
|
|
5616
5708
|
let unit;
|
|
5617
5709
|
if (operator === "+" || operator === "-") {
|
|
5618
|
-
unit =
|
|
5619
|
-
return
|
|
5710
|
+
unit = compatibleFormulaUnits(a, b);
|
|
5711
|
+
return finiteFormulaValue({ value: operator === "+" ? a.value + b.value : a.value - b.value, unit });
|
|
5620
5712
|
}
|
|
5621
5713
|
if (operator === "*") {
|
|
5622
|
-
|
|
5623
|
-
return formulaFailure("unit", "Compound dimensions are unsupported");
|
|
5624
|
-
return finite2({ value: a.value * b.value, unit: a.unit === "scalar" ? b.unit : a.unit });
|
|
5714
|
+
return finiteFormulaValue({ value: a.value * b.value, unit: formulaProductUnit(a.unit, b.unit) });
|
|
5625
5715
|
}
|
|
5626
5716
|
if (operator === "/") {
|
|
5627
5717
|
if (b.value === 0) return formulaFailure("value", "Division by zero");
|
|
5628
|
-
|
|
5629
|
-
return formulaFailure("unit", "Inverse dimensions are unsupported");
|
|
5630
|
-
return finite2({ value: a.value / b.value, unit: a.unit === b.unit ? "scalar" : a.unit });
|
|
5718
|
+
return finiteFormulaValue({ value: a.value / b.value, unit: formulaQuotientUnit(a.unit, b.unit) });
|
|
5631
5719
|
}
|
|
5632
5720
|
if (operator === "^") {
|
|
5633
|
-
|
|
5634
|
-
return formulaFailure("unit", "Dimensional powers are unsupported");
|
|
5635
|
-
return finite2({ value: a.value ** b.value, unit: b.value === 0 ? "scalar" : a.unit });
|
|
5721
|
+
return finiteFormulaValue({ value: a.value ** b.value, unit: formulaExponentUnit(a.unit, b) });
|
|
5636
5722
|
}
|
|
5637
|
-
|
|
5723
|
+
compatibleFormulaUnits(a, b);
|
|
5638
5724
|
const comparisons = {
|
|
5639
5725
|
"=": a.value === b.value,
|
|
5640
5726
|
"<>": a.value !== b.value,
|
|
@@ -5658,13 +5744,13 @@ function evaluateVisioFormula(source, resolve, limits = {}) {
|
|
|
5658
5744
|
if (++steps > maxSteps || depth > maxDepth)
|
|
5659
5745
|
return formulaFailure("limit", "Formula evaluation limit");
|
|
5660
5746
|
limits.onStep?.();
|
|
5661
|
-
if (node.kind === "number") return
|
|
5747
|
+
if (node.kind === "number") return finiteFormulaValue({ value: node.value, unit: node.unit });
|
|
5662
5748
|
if (node.kind === "string")
|
|
5663
5749
|
return formulaFailure("value", "String results are outside the numeric formula subset");
|
|
5664
|
-
if (node.kind === "reference") return
|
|
5750
|
+
if (node.kind === "reference") return finiteFormulaValue(resolve(node.reference));
|
|
5665
5751
|
if (node.kind === "unary") {
|
|
5666
5752
|
const result = evaluate(node.operand, depth + 1);
|
|
5667
|
-
return
|
|
5753
|
+
return finiteFormulaValue({
|
|
5668
5754
|
value: node.operator === "-" ? -result.value : result.value,
|
|
5669
5755
|
unit: result.unit
|
|
5670
5756
|
});
|
|
@@ -5678,6 +5764,11 @@ function evaluateVisioFormula(source, resolve, limits = {}) {
|
|
|
5678
5764
|
return formulaFailure("arity", `Invalid ${name} argument count`);
|
|
5679
5765
|
};
|
|
5680
5766
|
const arg = (index) => evaluate(node.args[index], depth + 1);
|
|
5767
|
+
if (numericFormulaFunctions.has(name))
|
|
5768
|
+
return evaluateNumericFormulaFunction(
|
|
5769
|
+
name,
|
|
5770
|
+
node.args.map((_, index) => arg(index))
|
|
5771
|
+
);
|
|
5681
5772
|
if (name === "PI") {
|
|
5682
5773
|
arity(0);
|
|
5683
5774
|
return { value: Math.PI, unit: "scalar" };
|
|
@@ -5697,18 +5788,18 @@ function evaluateVisioFormula(source, resolve, limits = {}) {
|
|
|
5697
5788
|
const args = node.args.map((_, i) => arg(i));
|
|
5698
5789
|
let result = args[0];
|
|
5699
5790
|
for (const item of args.slice(1)) {
|
|
5700
|
-
const unit =
|
|
5791
|
+
const unit = compatibleFormulaUnits(result, item);
|
|
5701
5792
|
result = {
|
|
5702
5793
|
value: name === "MIN" ? Math.min(result.value, item.value) : Math.max(result.value, item.value),
|
|
5703
5794
|
unit
|
|
5704
5795
|
};
|
|
5705
5796
|
}
|
|
5706
|
-
return
|
|
5797
|
+
return finiteFormulaValue(result);
|
|
5707
5798
|
}
|
|
5708
5799
|
if (name === "ATAN2") {
|
|
5709
5800
|
arity(2);
|
|
5710
5801
|
const y = arg(0), x = arg(1);
|
|
5711
|
-
|
|
5802
|
+
compatibleFormulaUnits(y, x);
|
|
5712
5803
|
return { value: Math.atan2(y.value, x.value), unit: "angle" };
|
|
5713
5804
|
}
|
|
5714
5805
|
if (name === "SIGN") {
|
|
@@ -5726,12 +5817,11 @@ function evaluateVisioFormula(source, resolve, limits = {}) {
|
|
|
5726
5817
|
const value = arg(0);
|
|
5727
5818
|
if (name === "ABS") return { value: Math.abs(value.value), unit: value.unit };
|
|
5728
5819
|
if (name === "SQRT") {
|
|
5729
|
-
|
|
5730
|
-
return finite2({ value: Math.sqrt(value.value), unit: "scalar" });
|
|
5820
|
+
return finiteFormulaValue({ value: Math.sqrt(value.value), unit: formulaSquareRootUnit(value.unit) });
|
|
5731
5821
|
}
|
|
5732
5822
|
if (value.unit !== "angle" && value.unit !== "scalar")
|
|
5733
5823
|
return formulaFailure("unit", `${name} requires radians`);
|
|
5734
|
-
return
|
|
5824
|
+
return finiteFormulaValue({
|
|
5735
5825
|
value: name === "SIN" ? Math.sin(value.value) : name === "COS" ? Math.cos(value.value) : Math.tan(value.value),
|
|
5736
5826
|
unit: "scalar"
|
|
5737
5827
|
});
|
|
@@ -6093,7 +6183,7 @@ function recalculateVisioCells(roots, changed, options = {}) {
|
|
|
6093
6183
|
if (active.size >= maxDepth)
|
|
6094
6184
|
fail("LIMIT_FORMULA_DEPTH", "ShapeSheet dependency depth limit exceeded.");
|
|
6095
6185
|
const item = cells3.get(id);
|
|
6096
|
-
if (!item || item.unsafe)
|
|
6186
|
+
if (!item || item.unsafe && (!item.node || !options.masterMovePins?.has(item.node)))
|
|
6097
6187
|
fail(
|
|
6098
6188
|
"EDIT_UNSUPPORTED_DEPENDENCY",
|
|
6099
6189
|
"Affected formula references missing, inherited or grouped cells."
|
|
@@ -6246,7 +6336,7 @@ function setCell(shape, name, value, formula) {
|
|
|
6246
6336
|
if (formula) node.setAttribute("F", formula);
|
|
6247
6337
|
else if (attribute2(node, "F") !== "No Formula") node.removeAttribute("F");
|
|
6248
6338
|
}
|
|
6249
|
-
function admitted(root, shapeId) {
|
|
6339
|
+
function admitted(root, shapeId, masterMovePins = /* @__PURE__ */ new Set()) {
|
|
6250
6340
|
const containers = children(root, "Shapes");
|
|
6251
6341
|
if (containers.length !== 1)
|
|
6252
6342
|
fail("UNSUPPORTED_GEOMETRY_EDIT", "One local Shapes container is required.");
|
|
@@ -6256,7 +6346,10 @@ function admitted(root, shapeId) {
|
|
|
6256
6346
|
if (candidates.length !== 1)
|
|
6257
6347
|
fail("EDIT_TARGET_NOT_FOUND", "A unique top-level local shape is required.");
|
|
6258
6348
|
const shape = candidates[0];
|
|
6259
|
-
if (shape.hasAttribute("Master") || shape.hasAttribute("MasterShape")
|
|
6349
|
+
if ((shape.hasAttribute("Master") || shape.hasAttribute("MasterShape")) && !["PinX", "PinY"].every((name) => {
|
|
6350
|
+
const cell = cells(shape).get(name);
|
|
6351
|
+
return cell && masterMovePins.has(cell);
|
|
6352
|
+
}) || ["1", "true"].includes(attribute2(shape, "Del") ?? "") || children(shape, "Shapes").length || children(shape, "ForeignData").length || children(shape, "Rel").length || attribute2(shape, "Type") && attribute2(shape, "Type") !== "Shape")
|
|
6260
6353
|
fail(
|
|
6261
6354
|
"UNSUPPORTED_GEOMETRY_EDIT",
|
|
6262
6355
|
"Master, group, foreign, deleted and non-shape operations are unsupported."
|
|
@@ -6463,7 +6556,7 @@ function createRectangle(root, edit) {
|
|
|
6463
6556
|
container.appendChild(shape);
|
|
6464
6557
|
return shape;
|
|
6465
6558
|
}
|
|
6466
|
-
function applyGeometryEdit(roots, document, edit, check) {
|
|
6559
|
+
function applyGeometryEdit(roots, document, edit, check, masterMovePins = /* @__PURE__ */ new Set()) {
|
|
6467
6560
|
check();
|
|
6468
6561
|
const root = roots.get(edit.pageId);
|
|
6469
6562
|
if (!root) fail("EDIT_TARGET_NOT_FOUND", "Page does not exist.");
|
|
@@ -6475,7 +6568,11 @@ function applyGeometryEdit(roots, document, edit, check) {
|
|
|
6475
6568
|
expected = { width: edit.width, height: edit.height, x: edit.x, y: edit.y };
|
|
6476
6569
|
for (const name of ["Width", "Height", "PinX", "PinY"]) add(name);
|
|
6477
6570
|
} else {
|
|
6478
|
-
const shape = admitted(
|
|
6571
|
+
const shape = admitted(
|
|
6572
|
+
root,
|
|
6573
|
+
edit.shapeId,
|
|
6574
|
+
edit.type === "move-shape" ? masterMovePins : /* @__PURE__ */ new Set()
|
|
6575
|
+
);
|
|
6479
6576
|
protectedShape(shape, document);
|
|
6480
6577
|
if (edit.type !== "delete-shape") {
|
|
6481
6578
|
for (const connections2 of children(root, "Connects"))
|
|
@@ -6553,8 +6650,10 @@ function applyGeometryEdit(roots, document, edit, check) {
|
|
|
6553
6650
|
}
|
|
6554
6651
|
}
|
|
6555
6652
|
if (!changed.length) return [];
|
|
6556
|
-
const affectedPages = recalculateVisioCells(roots, changed, { check });
|
|
6557
|
-
const result = cells(
|
|
6653
|
+
const affectedPages = recalculateVisioCells(roots, changed, { check, masterMovePins });
|
|
6654
|
+
const result = cells(
|
|
6655
|
+
admitted(root, edit.shapeId, edit.type === "move-shape" ? masterMovePins : /* @__PURE__ */ new Set())
|
|
6656
|
+
);
|
|
6558
6657
|
if (expected && (numeric3(result.get("Width")) !== expected.width || numeric3(result.get("Height")) !== expected.height || numeric3(result.get("PinX"), expected.width / 2) !== expected.x || numeric3(result.get("PinY"), expected.height / 2) !== expected.y))
|
|
6559
6658
|
fail(
|
|
6560
6659
|
"EDIT_UNSUPPORTED_DEPENDENCY",
|
|
@@ -6563,6 +6662,525 @@ function applyGeometryEdit(roots, document, edit, check) {
|
|
|
6563
6662
|
return [.../* @__PURE__ */ new Set([edit.pageId, ...affectedPages])];
|
|
6564
6663
|
}
|
|
6565
6664
|
|
|
6665
|
+
// src/visio/formula-master.ts
|
|
6666
|
+
function analyzeVisioMasterFormula(source, options) {
|
|
6667
|
+
const ast = parseVisioFormula(source);
|
|
6668
|
+
const analysis = analyzeVisioFormula(ast);
|
|
6669
|
+
const references = /* @__PURE__ */ new Map();
|
|
6670
|
+
for (const ref of analysis.references)
|
|
6671
|
+
references.set(`${ref.shapeId ?? ""}!${ref.cell.toLowerCase()}`, ref);
|
|
6672
|
+
let dynamic2 = false, readsText = false, readsTheme = false;
|
|
6673
|
+
const queue = [ast];
|
|
6674
|
+
while (queue.length) {
|
|
6675
|
+
const node = queue.pop();
|
|
6676
|
+
if (node.kind === "unary") queue.push(node.operand);
|
|
6677
|
+
if (node.kind === "binary") queue.push(node.left, node.right);
|
|
6678
|
+
if (node.kind !== "call") continue;
|
|
6679
|
+
queue.push(...node.args);
|
|
6680
|
+
if (["THEME", "THEMEVAL", "ISTHEMED"].includes(node.name)) readsTheme = true;
|
|
6681
|
+
let local = !analyzeVisioFormula({ kind: "call", name: node.name, args: [] }).dynamic;
|
|
6682
|
+
if (node.name === "SETATREF")
|
|
6683
|
+
local = node.args.length === 1 && node.args[0].kind === "reference";
|
|
6684
|
+
if (["TEXTWIDTH", "TEXTHEIGHT", "SHAPETEXT"].includes(node.name)) {
|
|
6685
|
+
const text = node.args[0];
|
|
6686
|
+
const count = node.name === "TEXTHEIGHT" ? node.args.length === 2 : node.args.length === 1;
|
|
6687
|
+
local = options.textFieldFree && count && text?.kind === "reference" && text.reference.shapeId === void 0 && text.reference.cell.toLowerCase() === "thetext";
|
|
6688
|
+
readsText = true;
|
|
6689
|
+
}
|
|
6690
|
+
if (["LUM", "HUE", "SAT"].includes(node.name)) {
|
|
6691
|
+
local = node.args.length === 1;
|
|
6692
|
+
const arg = node.args[0];
|
|
6693
|
+
if (arg?.kind === "string") {
|
|
6694
|
+
local = /^[A-Za-z_][A-Za-z0-9_.]*$/.test(arg.value);
|
|
6695
|
+
if (local) references.set(`!${arg.value.toLowerCase()}`, { cell: arg.value });
|
|
6696
|
+
}
|
|
6697
|
+
}
|
|
6698
|
+
if (node.name === "STRSAME") local = node.args.length === 2;
|
|
6699
|
+
if (!local) dynamic2 = true;
|
|
6700
|
+
}
|
|
6701
|
+
return { ...analysis, references: [...references.values()], dynamic: dynamic2, readsText, readsTheme };
|
|
6702
|
+
}
|
|
6703
|
+
|
|
6704
|
+
// src/visio/edit-master-move.ts
|
|
6705
|
+
var protection = [
|
|
6706
|
+
"LockMoveX",
|
|
6707
|
+
"LockMoveY",
|
|
6708
|
+
"LockWidth",
|
|
6709
|
+
"LockHeight",
|
|
6710
|
+
"LockAspect",
|
|
6711
|
+
"LockDelete"
|
|
6712
|
+
];
|
|
6713
|
+
var dimensions2 = ["PinX", "PinY", "Width", "Height", "LocPinX", "LocPinY"];
|
|
6714
|
+
function prepareMasterMovePins(roots, commands, bindings, check) {
|
|
6715
|
+
const result = /* @__PURE__ */ new Set();
|
|
6716
|
+
let work = 1e5;
|
|
6717
|
+
const charge = (amount = 1) => {
|
|
6718
|
+
check();
|
|
6719
|
+
work -= amount;
|
|
6720
|
+
if (work < 0)
|
|
6721
|
+
fail("EDIT_UNSUPPORTED_PACKAGE_DEPENDENCY", "Master move preparation budget exceeded.");
|
|
6722
|
+
};
|
|
6723
|
+
const analyze = (formula) => {
|
|
6724
|
+
charge(formula.length);
|
|
6725
|
+
return analyzeVisioFormula(formula);
|
|
6726
|
+
};
|
|
6727
|
+
for (const command2 of commands) {
|
|
6728
|
+
charge();
|
|
6729
|
+
const root = roots.get(command2.pageId);
|
|
6730
|
+
const instance = children(children(root, "Shapes")[0], "Shape").find(
|
|
6731
|
+
(shape) => attribute2(shape, "ID") === command2.shapeId
|
|
6732
|
+
);
|
|
6733
|
+
if (!instance?.hasAttribute("Master")) continue;
|
|
6734
|
+
if (command2.type !== "move-shape")
|
|
6735
|
+
fail("UNSUPPORTED_GEOMETRY_EDIT", "Master-linked resizing and deletion remain unsupported.");
|
|
6736
|
+
const binding = bindings.find((candidate) => candidate.instance === instance);
|
|
6737
|
+
if (!binding) fail("UNSUPPORTED_GEOMETRY_EDIT", "A unique effective master root is required.");
|
|
6738
|
+
for (const node of [instance, binding.template]) {
|
|
6739
|
+
charge();
|
|
6740
|
+
if (attribute2(node, "Type") !== "Shape" || children(node, "Shapes").length || children(node, "ForeignData").length || children(node, "Rel").length || ["1", "true"].includes(attribute2(node, "Del") ?? ""))
|
|
6741
|
+
fail("UNSUPPORTED_GEOMETRY_EDIT", "Master moves require top-level local 2D shape roots.");
|
|
6742
|
+
}
|
|
6743
|
+
for (const name of ["BeginX", "BeginY", "EndX", "EndY"])
|
|
6744
|
+
if (binding.cells.has(name.toLowerCase()))
|
|
6745
|
+
fail("UNSUPPORTED_GEOMETRY_EDIT", "Master lines and endpoint routing remain unsupported.");
|
|
6746
|
+
const oneD = binding.cells.get("oned")?.node;
|
|
6747
|
+
charge();
|
|
6748
|
+
if (oneD && (numeric3(oneD) !== 0 || visioFormulaCachedValue(attribute2(oneD, "V") ?? "", attribute2(oneD, "U")).unit !== "scalar" || executableCellFormula(attribute2(oneD, "F"))))
|
|
6749
|
+
fail("UNSUPPORTED_GEOMETRY_EDIT", "A static effective 2D master is required.");
|
|
6750
|
+
const local = cells(instance);
|
|
6751
|
+
for (const name of dimensions2) {
|
|
6752
|
+
charge();
|
|
6753
|
+
const node = local.get(name);
|
|
6754
|
+
numeric3(node);
|
|
6755
|
+
if (visioFormulaCachedValue("0", attribute2(node, "U") ?? "DL").unit !== "length")
|
|
6756
|
+
fail("EDIT_FORMULA_UNIT", "Master transform caches require length units.");
|
|
6757
|
+
}
|
|
6758
|
+
if (numeric3(local.get("Width")) <= 0 || numeric3(local.get("Height")) <= 0)
|
|
6759
|
+
fail("UNSUPPORTED_GEOMETRY_EDIT", "Positive explicit local dimensions are required.");
|
|
6760
|
+
for (const name of protection) {
|
|
6761
|
+
charge();
|
|
6762
|
+
const node = binding.cells.get(name.toLowerCase())?.node;
|
|
6763
|
+
if (!node || visioFormulaCachedValue(attribute2(node, "V") ?? "", attribute2(node, "U")).unit !== "scalar" || numeric3(node) !== 0)
|
|
6764
|
+
fail(
|
|
6765
|
+
"EDIT_PROTECTED_CELL",
|
|
6766
|
+
"Effective master protection must be explicitly proven inactive."
|
|
6767
|
+
);
|
|
6768
|
+
const formula = executableCellFormula(attribute2(node, "F"));
|
|
6769
|
+
if (formula) {
|
|
6770
|
+
const analysis = analyze(formula);
|
|
6771
|
+
if (analysis.dynamic || analysis.references.length || analysis.unsupportedFunctions.length)
|
|
6772
|
+
fail("EDIT_PROTECTED_CELL", "Effective master protection dependencies are unsupported.");
|
|
6773
|
+
const value = evaluateVisioFormula(
|
|
6774
|
+
formula,
|
|
6775
|
+
() => fail("EDIT_PROTECTED_CELL", "Unexpected protection dependency."),
|
|
6776
|
+
{ onStep: () => charge() }
|
|
6777
|
+
);
|
|
6778
|
+
if (value.unit !== "scalar" || value.value !== 0)
|
|
6779
|
+
fail("EDIT_PROTECTED_CELL", "Effective master protection is active or stale.");
|
|
6780
|
+
}
|
|
6781
|
+
}
|
|
6782
|
+
for (const name of ["PinX", "PinY"]) {
|
|
6783
|
+
charge();
|
|
6784
|
+
const node = local.get(name);
|
|
6785
|
+
if (binding.cells.get(name.toLowerCase())?.node !== node)
|
|
6786
|
+
fail("EDIT_PROTECTED_CELL", "The rotation pin must be an explicit local override.");
|
|
6787
|
+
charge(executableCellFormula(attribute2(node, "F"))?.length ?? 0);
|
|
6788
|
+
editableCell(node);
|
|
6789
|
+
const inherited = binding.inheritedCells.get(name.toLowerCase())?.node;
|
|
6790
|
+
numeric3(inherited);
|
|
6791
|
+
if (visioFormulaCachedValue("0", attribute2(inherited, "U") ?? "DL").unit !== "length")
|
|
6792
|
+
fail("EDIT_FORMULA_UNIT", "Inherited rotation pins require length units.");
|
|
6793
|
+
const formula = executableCellFormula(attribute2(inherited, "F"));
|
|
6794
|
+
if (formula) {
|
|
6795
|
+
const analysis = analyze(formula);
|
|
6796
|
+
if (analysis.guarded || analysis.dynamic || analysis.unsupportedFunctions.length)
|
|
6797
|
+
fail("EDIT_PROTECTED_CELL", "Protected or redirected master pins cannot be overridden.");
|
|
6798
|
+
}
|
|
6799
|
+
result.add(node);
|
|
6800
|
+
}
|
|
6801
|
+
}
|
|
6802
|
+
if (result.size) {
|
|
6803
|
+
const indexed = indexCells(roots, { check });
|
|
6804
|
+
const pins = new Set(
|
|
6805
|
+
[...indexed.values()].filter((cell) => cell.node && result.has(cell.node)).map(key)
|
|
6806
|
+
);
|
|
6807
|
+
for (const cell of indexed.values())
|
|
6808
|
+
if (charge(), cell.dependencies.some((dependency) => pins.has(dependency)))
|
|
6809
|
+
fail("EDIT_UNSUPPORTED_DEPENDENCY", "A page cache depends on a master rotation pin.");
|
|
6810
|
+
}
|
|
6811
|
+
return result;
|
|
6812
|
+
}
|
|
6813
|
+
|
|
6814
|
+
// src/visio/edit-master-index.ts
|
|
6815
|
+
function masterCells(sheet, charge = () => {
|
|
6816
|
+
}) {
|
|
6817
|
+
const result = /* @__PURE__ */ new Map();
|
|
6818
|
+
if (!sheet) return result;
|
|
6819
|
+
const add = (name, node) => {
|
|
6820
|
+
charge();
|
|
6821
|
+
const id = name.toLowerCase();
|
|
6822
|
+
if (result.has(id) && result.get(id) !== node)
|
|
6823
|
+
fail("EDIT_UNSUPPORTED_PACKAGE_DEPENDENCY", "Ambiguous effective master cells.");
|
|
6824
|
+
result.set(id, node);
|
|
6825
|
+
};
|
|
6826
|
+
for (const node of children(sheet, "Cell")) add(attribute2(node, "N") ?? "", node);
|
|
6827
|
+
for (const section of children(sheet, "Section")) {
|
|
6828
|
+
const name = attribute2(section, "N") ?? "";
|
|
6829
|
+
const prefix = name === "Geometry" ? `Geometry${Number(attribute2(section, "IX") ?? "0") + 1}` : name === "Control" ? "Controls" : name;
|
|
6830
|
+
for (const node of children(section, "Cell"))
|
|
6831
|
+
add(`${prefix}.${attribute2(node, "N") ?? ""}`, node);
|
|
6832
|
+
for (const row of children(section, "Row"))
|
|
6833
|
+
for (const node of children(row, "Cell")) {
|
|
6834
|
+
const n = attribute2(node, "N") ?? "";
|
|
6835
|
+
const rowName = attribute2(row, "N");
|
|
6836
|
+
const index = attribute2(row, "IX") ?? (prefix === "Controls" && /^Row_\d+$/.test(rowName ?? "") ? String(Number(rowName.slice(4)) - 1) : void 0);
|
|
6837
|
+
const ix = index ?? "0", r = rowName ?? (prefix === "Controls" ? `Row_${Number(ix) + 1}` : ix);
|
|
6838
|
+
add(
|
|
6839
|
+
name === "Geometry" || ["Controls", "Scratch", "Connection"].includes(prefix) ? `${prefix}.${n}${ix}` : n === "Value" && ["User", "Prop"].includes(name) ? `${prefix}.${r}` : `${prefix}.${r}.${n}`,
|
|
6840
|
+
node
|
|
6841
|
+
);
|
|
6842
|
+
if (name !== "Geometry") add(`${prefix}.${r}.${n}`, node);
|
|
6843
|
+
if (prefix === "Controls" && n === "X") add(`${prefix}.${r}`, node);
|
|
6844
|
+
if (name !== "Geometry" && index !== void 0) add(`${prefix}.$row${ix}.${n}`, node);
|
|
6845
|
+
}
|
|
6846
|
+
}
|
|
6847
|
+
return result;
|
|
6848
|
+
}
|
|
6849
|
+
function masterShapes(root) {
|
|
6850
|
+
const result = [], pending = [root];
|
|
6851
|
+
while (pending.length) {
|
|
6852
|
+
const parent = pending.pop();
|
|
6853
|
+
for (const container of children(parent, "Shapes"))
|
|
6854
|
+
for (const shape of children(container, "Shape")) {
|
|
6855
|
+
result.push(shape);
|
|
6856
|
+
pending.push(shape);
|
|
6857
|
+
}
|
|
6858
|
+
}
|
|
6859
|
+
return result;
|
|
6860
|
+
}
|
|
6861
|
+
function assertMasterMarkup(root, known, check) {
|
|
6862
|
+
for (const node of [root, ...Array.from(root.getElementsByTagName("*"))]) {
|
|
6863
|
+
check();
|
|
6864
|
+
if (node.namespaceURI === root.namespaceURI && node.hasAttribute("F") && !known.has(node))
|
|
6865
|
+
fail(
|
|
6866
|
+
"EDIT_UNSUPPORTED_PACKAGE_DEPENDENCY",
|
|
6867
|
+
"Master formula outside admitted sheet cells has unknown scope."
|
|
6868
|
+
);
|
|
6869
|
+
}
|
|
6870
|
+
}
|
|
6871
|
+
function masterStyleCells(document, template, instance, check, charge = () => {
|
|
6872
|
+
}) {
|
|
6873
|
+
const styles = /* @__PURE__ */ new Map();
|
|
6874
|
+
for (const container of children(document, "StyleSheets"))
|
|
6875
|
+
for (const style of children(container, "StyleSheet")) {
|
|
6876
|
+
charge();
|
|
6877
|
+
const id = attribute2(style, "ID");
|
|
6878
|
+
if (!id || styles.has(id))
|
|
6879
|
+
fail("EDIT_UNSUPPORTED_PACKAGE_DEPENDENCY", "Ambiguous master style IDs.");
|
|
6880
|
+
styles.set(id, style);
|
|
6881
|
+
}
|
|
6882
|
+
const defaults = children(document, "DocumentSheet")[0];
|
|
6883
|
+
const collect = (id, category, seen = /* @__PURE__ */ new Set()) => {
|
|
6884
|
+
check();
|
|
6885
|
+
if (seen.has(id) || seen.size >= 64)
|
|
6886
|
+
fail("EDIT_UNSUPPORTED_PACKAGE_DEPENDENCY", "Invalid inherited master style ancestry.");
|
|
6887
|
+
seen.add(id);
|
|
6888
|
+
const style = styles.get(id);
|
|
6889
|
+
if (!style) fail("EDIT_UNSUPPORTED_PACKAGE_DEPENDENCY", "Missing inherited master style.");
|
|
6890
|
+
const own = masterCells(style, charge);
|
|
6891
|
+
assertMasterMarkup(style, new Set(own.values()), check);
|
|
6892
|
+
const parent = attribute2(style, category);
|
|
6893
|
+
const result2 = parent !== void 0 && parent !== id ? collect(parent, category, seen) : /* @__PURE__ */ new Map();
|
|
6894
|
+
for (const [name, node] of own) {
|
|
6895
|
+
charge();
|
|
6896
|
+
if (attribute2(node, "F") !== "Inh") result2.set(name, node);
|
|
6897
|
+
}
|
|
6898
|
+
return result2;
|
|
6899
|
+
};
|
|
6900
|
+
const result = /* @__PURE__ */ new Map();
|
|
6901
|
+
for (const category of ["LineStyle", "FillStyle", "TextStyle"]) {
|
|
6902
|
+
const id = attribute2(instance, category) ?? attribute2(template, category) ?? attribute2(defaults, category) ?? (styles.has("0") ? "0" : void 0);
|
|
6903
|
+
if (id !== void 0)
|
|
6904
|
+
for (const [name, node] of collect(id, category)) {
|
|
6905
|
+
charge();
|
|
6906
|
+
if (result.has(name) && result.get(name) !== node)
|
|
6907
|
+
fail(
|
|
6908
|
+
"EDIT_UNSUPPORTED_PACKAGE_DEPENDENCY",
|
|
6909
|
+
"Master style categories have ambiguous overlapping inputs."
|
|
6910
|
+
);
|
|
6911
|
+
result.set(name, node);
|
|
6912
|
+
}
|
|
6913
|
+
}
|
|
6914
|
+
return result;
|
|
6915
|
+
}
|
|
6916
|
+
function overlay(cells3, additions, kind, charge) {
|
|
6917
|
+
const aliases = /* @__PURE__ */ new Map(), inherited = /* @__PURE__ */ new Map();
|
|
6918
|
+
for (const [name, source] of cells3) {
|
|
6919
|
+
charge();
|
|
6920
|
+
const names = aliases.get(source.node) ?? /* @__PURE__ */ new Set();
|
|
6921
|
+
names.add(name);
|
|
6922
|
+
aliases.set(source.node, names);
|
|
6923
|
+
}
|
|
6924
|
+
for (const [name, node] of additions) {
|
|
6925
|
+
charge();
|
|
6926
|
+
const source = cells3.get(name);
|
|
6927
|
+
if (source) inherited.set(node, source);
|
|
6928
|
+
}
|
|
6929
|
+
for (const [name, node] of additions) {
|
|
6930
|
+
charge();
|
|
6931
|
+
if (attribute2(node, "F") === "Inh") {
|
|
6932
|
+
const source = cells3.get(name) ?? inherited.get(node);
|
|
6933
|
+
if (!source)
|
|
6934
|
+
fail(
|
|
6935
|
+
"EDIT_UNSUPPORTED_PACKAGE_DEPENDENCY",
|
|
6936
|
+
"Inherited master cell has no effective source."
|
|
6937
|
+
);
|
|
6938
|
+
cells3.set(name, source);
|
|
6939
|
+
const names2 = aliases.get(source.node) ?? /* @__PURE__ */ new Set();
|
|
6940
|
+
names2.add(name);
|
|
6941
|
+
aliases.set(source.node, names2);
|
|
6942
|
+
continue;
|
|
6943
|
+
}
|
|
6944
|
+
const previous = cells3.get(name), names = aliases.get(node) ?? /* @__PURE__ */ new Set();
|
|
6945
|
+
if (previous && previous.node !== node) {
|
|
6946
|
+
for (const alias of aliases.get(previous.node) ?? []) {
|
|
6947
|
+
charge();
|
|
6948
|
+
cells3.set(alias, { node, kind });
|
|
6949
|
+
names.add(alias);
|
|
6950
|
+
}
|
|
6951
|
+
aliases.delete(previous.node);
|
|
6952
|
+
}
|
|
6953
|
+
cells3.set(name, { node, kind });
|
|
6954
|
+
names.add(name);
|
|
6955
|
+
aliases.set(node, names);
|
|
6956
|
+
}
|
|
6957
|
+
}
|
|
6958
|
+
|
|
6959
|
+
// src/visio/edit-master-scope.ts
|
|
6960
|
+
function problem(message) {
|
|
6961
|
+
return fail("EDIT_UNSUPPORTED_PACKAGE_DEPENDENCY", message);
|
|
6962
|
+
}
|
|
6963
|
+
var themeCell = /^(ColorSchemeIndex|EffectSchemeIndex|FontSchemeIndex|ThemeIndex|QuickStyle.*)$/i;
|
|
6964
|
+
async function assertVisioMasterIndependence(pkg, roots, commands, check) {
|
|
6965
|
+
const instances = [...roots].flatMap(
|
|
6966
|
+
([pageId, root]) => masterShapes(root).filter((shape) => shape.hasAttribute("Master")).map((instance) => ({ pageId, instance }))
|
|
6967
|
+
);
|
|
6968
|
+
if (!instances.length) return /* @__PURE__ */ new Set();
|
|
6969
|
+
const documentPart = await related(pkg, "", "document");
|
|
6970
|
+
if (!documentPart) problem("Missing master document relationship.");
|
|
6971
|
+
const document = await visioXml(pkg, documentPart, "VisioDocument");
|
|
6972
|
+
const mastersPart = await related(pkg, documentPart, "masters", false);
|
|
6973
|
+
if (!mastersPart) problem("Active master definitions are missing.");
|
|
6974
|
+
const definitions = /* @__PURE__ */ new Map();
|
|
6975
|
+
for (const node of children(await visioXml(pkg, mastersPart, "Masters"), "Master")) {
|
|
6976
|
+
const id = attribute2(node, "ID");
|
|
6977
|
+
if (!id || definitions.has(id)) problem("Master IDs are ambiguous.");
|
|
6978
|
+
definitions.set(id, node);
|
|
6979
|
+
}
|
|
6980
|
+
const loaded = /* @__PURE__ */ new Map();
|
|
6981
|
+
const bindings = [];
|
|
6982
|
+
let buildWork = 1e5;
|
|
6983
|
+
const charge = () => {
|
|
6984
|
+
check();
|
|
6985
|
+
if (--buildWork < 0) problem("Master effective-cell construction budget exceeded.");
|
|
6986
|
+
};
|
|
6987
|
+
const pageBindings = /* @__PURE__ */ new Map();
|
|
6988
|
+
const pageShapes = /* @__PURE__ */ new Map();
|
|
6989
|
+
for (const [pageId, root] of roots)
|
|
6990
|
+
for (const shape of masterShapes(root)) {
|
|
6991
|
+
const id = attribute2(shape, "ID");
|
|
6992
|
+
if (!id) problem("Page shape ID is missing.");
|
|
6993
|
+
const key2 = JSON.stringify([pageId, id]);
|
|
6994
|
+
if (pageShapes.has(key2)) problem("Page sheet IDs have ambiguous group scopes.");
|
|
6995
|
+
pageShapes.set(key2, shape);
|
|
6996
|
+
}
|
|
6997
|
+
for (const { pageId, instance } of instances) {
|
|
6998
|
+
check();
|
|
6999
|
+
const masterId = attribute2(instance, "Master"), definition = definitions.get(masterId);
|
|
7000
|
+
if (!definition) problem("Active master ID cannot be resolved.");
|
|
7001
|
+
let root = loaded.get(masterId);
|
|
7002
|
+
if (!root) {
|
|
7003
|
+
root = await visioXml(
|
|
7004
|
+
pkg,
|
|
7005
|
+
await indexedPart(pkg, mastersPart, definition, "master"),
|
|
7006
|
+
"MasterContents"
|
|
7007
|
+
);
|
|
7008
|
+
loaded.set(masterId, root);
|
|
7009
|
+
}
|
|
7010
|
+
const tops = children(children(root, "Shapes")[0], "Shape");
|
|
7011
|
+
if (tops.length !== 1) problem("Only a uniquely rooted master can prove independence.");
|
|
7012
|
+
const templates = masterShapes(root), context = /* @__PURE__ */ new Map();
|
|
7013
|
+
assertMasterMarkup(
|
|
7014
|
+
root,
|
|
7015
|
+
new Set(
|
|
7016
|
+
templates.flatMap((shape) => {
|
|
7017
|
+
charge();
|
|
7018
|
+
return [...masterCells(shape, charge).values()];
|
|
7019
|
+
})
|
|
7020
|
+
),
|
|
7021
|
+
check
|
|
7022
|
+
);
|
|
7023
|
+
const locals = [instance, ...masterShapes(instance)];
|
|
7024
|
+
const byTemplate = /* @__PURE__ */ new Map();
|
|
7025
|
+
const rootId = attribute2(tops[0], "ID");
|
|
7026
|
+
if (!rootId) problem("Master root shape ID is missing.");
|
|
7027
|
+
const explicitRoot = attribute2(instance, "MasterShape");
|
|
7028
|
+
if (explicitRoot !== void 0 && explicitRoot !== rootId)
|
|
7029
|
+
problem("Master root mapping is ambiguous.");
|
|
7030
|
+
byTemplate.set(rootId, instance);
|
|
7031
|
+
for (const local of locals.slice(1)) {
|
|
7032
|
+
if (local.hasAttribute("Master")) problem("Nested master inheritance is unsupported.");
|
|
7033
|
+
const id = attribute2(local, "MasterShape");
|
|
7034
|
+
if (id === void 0) continue;
|
|
7035
|
+
if (byTemplate.has(id)) problem("MasterShape mappings are ambiguous.");
|
|
7036
|
+
byTemplate.set(id, local);
|
|
7037
|
+
}
|
|
7038
|
+
for (const template of templates) {
|
|
7039
|
+
charge();
|
|
7040
|
+
if (bindings.length >= 1e4) problem("Master effective binding limit exceeded.");
|
|
7041
|
+
check();
|
|
7042
|
+
if (template.hasAttribute("Master") || template.hasAttribute("MasterShape"))
|
|
7043
|
+
problem("Chained master definitions are unsupported.");
|
|
7044
|
+
const templateId = attribute2(template, "ID");
|
|
7045
|
+
if (!templateId || context.has(templateId)) problem("Master-local sheet IDs are ambiguous.");
|
|
7046
|
+
const local = byTemplate.get(templateId), cells3 = /* @__PURE__ */ new Map();
|
|
7047
|
+
for (const [name, node] of masterStyleCells(document, template, local, check, charge))
|
|
7048
|
+
cells3.set(name, { node, kind: "style" });
|
|
7049
|
+
overlay(cells3, masterCells(template, charge), "template", charge);
|
|
7050
|
+
const inheritedCells = new Map(cells3);
|
|
7051
|
+
overlay(cells3, masterCells(local, charge), "instance", charge);
|
|
7052
|
+
const binding = {
|
|
7053
|
+
id: `${pageId}:${attribute2(instance, "ID")}:${templateId}`,
|
|
7054
|
+
pageId,
|
|
7055
|
+
template,
|
|
7056
|
+
cells: cells3,
|
|
7057
|
+
inheritedCells,
|
|
7058
|
+
context,
|
|
7059
|
+
...local ? { instance: local } : {}
|
|
7060
|
+
};
|
|
7061
|
+
context.set(templateId, binding);
|
|
7062
|
+
bindings.push(binding);
|
|
7063
|
+
if (local) pageBindings.set(JSON.stringify([pageId, attribute2(local, "ID")]), binding);
|
|
7064
|
+
}
|
|
7065
|
+
for (const id of byTemplate.keys())
|
|
7066
|
+
if (!context.has(id)) problem("MasterShape refers to a missing template.");
|
|
7067
|
+
}
|
|
7068
|
+
const movePins = prepareMasterMovePins(roots, commands, bindings, check);
|
|
7069
|
+
const changed = commands.flatMap(
|
|
7070
|
+
(command2) => command2.type === "delete-shape" ? [] : (command2.type === "move-shape" ? ["PinX", "PinY"] : command2.type === "resize-shape" ? ["Width", "Height"] : ["Width", "Height", "PinX", "PinY"]).map((cell) => ({ pageId: command2.pageId, shapeId: command2.shapeId, cell }))
|
|
7071
|
+
);
|
|
7072
|
+
const query = createVisioDependencyQuery(roots, { check });
|
|
7073
|
+
const directAffected = (pageId, shapeId, cell) => commands.some(
|
|
7074
|
+
(command2) => command2.pageId === pageId && command2.shapeId === shapeId && (command2.type === "delete-shape" || changed.some(
|
|
7075
|
+
(target) => target.pageId === pageId && target.shapeId === shapeId && target.cell.toLowerCase() === cell.toLowerCase()
|
|
7076
|
+
))
|
|
7077
|
+
);
|
|
7078
|
+
const active = /* @__PURE__ */ new Set(), done = /* @__PURE__ */ new Set();
|
|
7079
|
+
const pageInputs = /* @__PURE__ */ new Map();
|
|
7080
|
+
const pageInput = (pageId, shapeId) => {
|
|
7081
|
+
const id = JSON.stringify([pageId, shapeId]);
|
|
7082
|
+
const bound2 = pageBindings.get(id) ?? pageInputs.get(id);
|
|
7083
|
+
if (bound2) return bound2;
|
|
7084
|
+
const shape = pageShapes.get(id);
|
|
7085
|
+
if (!shape) problem("Local master override has a missing page reference.");
|
|
7086
|
+
const cells3 = /* @__PURE__ */ new Map();
|
|
7087
|
+
for (const [name, node] of masterStyleCells(document, shape, shape, check, charge))
|
|
7088
|
+
cells3.set(name, { node, kind: "style" });
|
|
7089
|
+
overlay(cells3, masterCells(shape, charge), "instance", charge);
|
|
7090
|
+
const result = {
|
|
7091
|
+
id: `page:${id}`,
|
|
7092
|
+
pageId,
|
|
7093
|
+
template: shape,
|
|
7094
|
+
instance: shape,
|
|
7095
|
+
cells: cells3,
|
|
7096
|
+
inheritedCells: /* @__PURE__ */ new Map(),
|
|
7097
|
+
context: /* @__PURE__ */ new Map()
|
|
7098
|
+
};
|
|
7099
|
+
pageInputs.set(id, result);
|
|
7100
|
+
return result;
|
|
7101
|
+
};
|
|
7102
|
+
let steps = 1e5;
|
|
7103
|
+
const inspect2 = (binding, name) => {
|
|
7104
|
+
check();
|
|
7105
|
+
if (--steps < 0) problem("Master dependency proof exceeded its cell budget.");
|
|
7106
|
+
name = name.toLowerCase();
|
|
7107
|
+
const pageShapeId = attribute2(binding.instance, "ID");
|
|
7108
|
+
if (pageShapeId !== void 0 && directAffected(binding.pageId, pageShapeId, name))
|
|
7109
|
+
problem("Effective master cache depends on an edited page cell.");
|
|
7110
|
+
const id = JSON.stringify([binding.id, name]);
|
|
7111
|
+
if (done.has(id)) return;
|
|
7112
|
+
if (active.has(id) || active.size >= 64)
|
|
7113
|
+
problem("Master dependency proof is cyclic or too deep.");
|
|
7114
|
+
active.add(id);
|
|
7115
|
+
const source = binding.cells.get(name);
|
|
7116
|
+
if (!source) {
|
|
7117
|
+
const defaults = {
|
|
7118
|
+
locpinx: "width",
|
|
7119
|
+
locpiny: "height",
|
|
7120
|
+
txtwidth: "width",
|
|
7121
|
+
txtheight: "height",
|
|
7122
|
+
txtpinx: "width",
|
|
7123
|
+
txtpiny: "height",
|
|
7124
|
+
txtlocpinx: "txtwidth",
|
|
7125
|
+
txtlocpiny: "txtheight"
|
|
7126
|
+
};
|
|
7127
|
+
const dimension = defaults[name];
|
|
7128
|
+
if (dimension) inspect2(binding, dimension);
|
|
7129
|
+
else if (!themeCell.test(name)) problem(`Missing effective master reference ${name}.`);
|
|
7130
|
+
} else {
|
|
7131
|
+
const formula = executableCellFormula(attribute2(source.node, "F"));
|
|
7132
|
+
if (formula && !inertDoubleClickFormula(attribute2(source.node, "N") ?? "", formula)) {
|
|
7133
|
+
const text = children(binding.instance, "Text")[0] ?? children(binding.template, "Text")[0];
|
|
7134
|
+
const textFieldFree = ![...binding.cells.keys()].some((key2) => /^fields?\./i.test(key2)) && (!text || !Array.from(text.getElementsByTagName("*")).some(
|
|
7135
|
+
(node) => node.localName.toLowerCase() === "fld"
|
|
7136
|
+
));
|
|
7137
|
+
let analysis;
|
|
7138
|
+
try {
|
|
7139
|
+
analysis = analyzeVisioMasterFormula(formula, { textFieldFree });
|
|
7140
|
+
} catch (error) {
|
|
7141
|
+
problem(
|
|
7142
|
+
`Cannot analyze effective master formula: ${error instanceof Error ? error.message : "invalid formula"}`
|
|
7143
|
+
);
|
|
7144
|
+
}
|
|
7145
|
+
if (analysis.dynamic) problem("Effective master formula has unknown dynamic dependencies.");
|
|
7146
|
+
for (const ref of analysis.references) {
|
|
7147
|
+
if (analysis.readsText && ref.shapeId === void 0 && ref.cell.toLowerCase() === "thetext")
|
|
7148
|
+
continue;
|
|
7149
|
+
if (ref.shapeId === void 0) inspect2(binding, ref.cell);
|
|
7150
|
+
else if (source.kind === "template") {
|
|
7151
|
+
const target = binding.context.get(ref.shapeId);
|
|
7152
|
+
if (!target) problem("Missing master-local Sheet reference.");
|
|
7153
|
+
inspect2(target, ref.cell);
|
|
7154
|
+
} else {
|
|
7155
|
+
if (source.kind === "style")
|
|
7156
|
+
problem("Explicit sheet references in inherited master styles are ambiguous.");
|
|
7157
|
+
if (directAffected(binding.pageId, ref.shapeId, ref.cell) || query({ pageId: binding.pageId, shapeId: ref.shapeId, cell: ref.cell }, changed))
|
|
7158
|
+
problem("Effective master cache depends on an edited page shape.");
|
|
7159
|
+
inspect2(pageInput(binding.pageId, ref.shapeId), ref.cell);
|
|
7160
|
+
}
|
|
7161
|
+
}
|
|
7162
|
+
if (analysis.readsText) {
|
|
7163
|
+
for (const cell of binding.cells.keys())
|
|
7164
|
+
if (/^(character\.|paragraph\.|tabs\.|leftmargin$|rightmargin$|topmargin$|bottommargin$)/i.test(
|
|
7165
|
+
cell
|
|
7166
|
+
))
|
|
7167
|
+
inspect2(binding, cell);
|
|
7168
|
+
}
|
|
7169
|
+
}
|
|
7170
|
+
}
|
|
7171
|
+
active.delete(id);
|
|
7172
|
+
done.add(id);
|
|
7173
|
+
};
|
|
7174
|
+
for (const binding of bindings)
|
|
7175
|
+
for (const name of binding.cells.keys()) {
|
|
7176
|
+
const source = binding.cells.get(name);
|
|
7177
|
+
if (["pinx", "piny"].includes(name) && source?.kind === "instance" && movePins.has(source.node))
|
|
7178
|
+
continue;
|
|
7179
|
+
inspect2(binding, name);
|
|
7180
|
+
}
|
|
7181
|
+
return movePins;
|
|
7182
|
+
}
|
|
7183
|
+
|
|
6566
7184
|
// src/visio/edit-scope.ts
|
|
6567
7185
|
var admitted2 = (node) => node.namespaceURI === VISIO_NS || node.namespaceURI === VISIO_LEGACY_NS;
|
|
6568
7186
|
function cells2(sheet) {
|
|
@@ -6645,31 +7263,10 @@ async function assertGeometryPackageScope(pkg, pagePaths, commands, check, roots
|
|
|
6645
7263
|
let documentRoot;
|
|
6646
7264
|
for (const path of pkg.paths()) {
|
|
6647
7265
|
if (!/^visio\/.*\.xml$/i.test(path) || pagePaths.has(path)) continue;
|
|
6648
|
-
if (/^visio\/masters\//i.test(path)
|
|
7266
|
+
if (/^visio\/masters\//i.test(path)) continue;
|
|
6649
7267
|
const root = await pkg.readXml(path);
|
|
6650
7268
|
const masterScope = /^visio\/masters\//i.test(path) || admitted2(root) && ["MasterContents", "Masters"].includes(root.localName);
|
|
6651
|
-
if (masterScope)
|
|
6652
|
-
if (hasMasterInstances)
|
|
6653
|
-
for (const node of [root, ...Array.from(root.getElementsByTagName("*"))]) {
|
|
6654
|
-
check();
|
|
6655
|
-
if (!admitted2(node)) continue;
|
|
6656
|
-
const source = executableCellFormula(attribute2(node, "F"));
|
|
6657
|
-
if (!source || inertDoubleClickFormula(attribute2(node, "N") ?? "", source)) continue;
|
|
6658
|
-
try {
|
|
6659
|
-
if (analyzeVisioFormula(source).dynamic)
|
|
6660
|
-
fail(
|
|
6661
|
-
"EDIT_UNSUPPORTED_PACKAGE_DEPENDENCY",
|
|
6662
|
-
"Used master formulas have unknown dynamic dependencies."
|
|
6663
|
-
);
|
|
6664
|
-
} catch (error) {
|
|
6665
|
-
fail(
|
|
6666
|
-
"EDIT_UNSUPPORTED_PACKAGE_DEPENDENCY",
|
|
6667
|
-
`Cannot prove used master formula independence: ${error instanceof Error ? error.message : "invalid formula"}`
|
|
6668
|
-
);
|
|
6669
|
-
}
|
|
6670
|
-
}
|
|
6671
|
-
continue;
|
|
6672
|
-
}
|
|
7269
|
+
if (masterScope) continue;
|
|
6673
7270
|
if (admitted2(root) && root.localName === "VisioDocument") {
|
|
6674
7271
|
if (documentRoot)
|
|
6675
7272
|
fail("EDIT_UNSUPPORTED_PACKAGE_DEPENDENCY", "Multiple document scopes are ambiguous.");
|
|
@@ -6701,7 +7298,24 @@ async function assertGeometryPackageScope(pkg, pagePaths, commands, check, roots
|
|
|
6701
7298
|
});
|
|
6702
7299
|
}
|
|
6703
7300
|
}
|
|
6704
|
-
|
|
7301
|
+
let movePins = /* @__PURE__ */ new Set();
|
|
7302
|
+
if (hasMasterInstances) {
|
|
7303
|
+
for (const command2 of commands) {
|
|
7304
|
+
const root = roots.get(command2.pageId);
|
|
7305
|
+
if (!root) continue;
|
|
7306
|
+
const target = Array.from(root.getElementsByTagNameNS(root.namespaceURI, "Shape")).find(
|
|
7307
|
+
(shape) => attribute2(shape, "ID") === command2.shapeId
|
|
7308
|
+
);
|
|
7309
|
+
if (target?.hasAttribute("MasterShape") && !target.hasAttribute("Master"))
|
|
7310
|
+
fail("UNSUPPORTED_GEOMETRY_EDIT", "Editing master-linked shapes is unsupported.");
|
|
7311
|
+
if (target?.hasAttribute("Master") && (command2.type !== "move-shape" || !["PinX", "PinY", "Width", "Height", "LocPinX", "LocPinY"].every(
|
|
7312
|
+
(name) => children(target, "Cell").some((node) => attribute2(node, "N") === name)
|
|
7313
|
+
)))
|
|
7314
|
+
fail("UNSUPPORTED_GEOMETRY_EDIT", "Master moves require complete local transform caches.");
|
|
7315
|
+
}
|
|
7316
|
+
movePins = await assertVisioMasterIndependence(pkg, roots, commands, check);
|
|
7317
|
+
}
|
|
7318
|
+
if (!documentRoot) return movePins;
|
|
6705
7319
|
const styles = /* @__PURE__ */ new Map();
|
|
6706
7320
|
for (const container of children(documentRoot, "StyleSheets"))
|
|
6707
7321
|
for (const style of children(container, "StyleSheet")) {
|
|
@@ -6766,6 +7380,7 @@ async function assertGeometryPackageScope(pkg, pagePaths, commands, check, roots
|
|
|
6766
7380
|
}
|
|
6767
7381
|
}
|
|
6768
7382
|
}
|
|
7383
|
+
return movePins;
|
|
6769
7384
|
}
|
|
6770
7385
|
|
|
6771
7386
|
// src/visio/edit.ts
|
|
@@ -6793,12 +7408,13 @@ async function editVsdx(input, edits, options = {}) {
|
|
|
6793
7408
|
const roots = /* @__PURE__ */ new Map();
|
|
6794
7409
|
const geometry = commands.some((command2) => command2.type !== "replace-plain-text");
|
|
6795
7410
|
let document;
|
|
7411
|
+
let masterMovePins = /* @__PURE__ */ new Set();
|
|
6796
7412
|
if (geometry) {
|
|
6797
7413
|
for (const [pageId, path2] of pages) {
|
|
6798
7414
|
const sourceRoot = await visioXml(pkg, path2, "PageContents");
|
|
6799
7415
|
roots.set(pageId, sourceRoot.ownerDocument.cloneNode(true).documentElement);
|
|
6800
7416
|
}
|
|
6801
|
-
await assertGeometryPackageScope(
|
|
7417
|
+
masterMovePins = await assertGeometryPackageScope(
|
|
6802
7418
|
pkg,
|
|
6803
7419
|
new Set(pages.values()),
|
|
6804
7420
|
commands.filter((command2) => command2.type !== "replace-plain-text"),
|
|
@@ -6825,7 +7441,7 @@ async function editVsdx(input, edits, options = {}) {
|
|
|
6825
7441
|
textChanged = true;
|
|
6826
7442
|
}
|
|
6827
7443
|
} else {
|
|
6828
|
-
for (const pageId of applyGeometryEdit(roots, document, command2, check))
|
|
7444
|
+
for (const pageId of applyGeometryEdit(roots, document, command2, check, masterMovePins))
|
|
6829
7445
|
dirty.set(pages.get(pageId), roots.get(pageId));
|
|
6830
7446
|
}
|
|
6831
7447
|
}
|