ooxml-core 1.2.0 → 1.3.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/dist/{PptxHandler-SJTINPU4.mjs → PptxHandler-ZPJNHEZZ.mjs} +2 -2
- package/dist/automation/index.cjs +3294 -661
- package/dist/automation/index.mjs +3294 -661
- package/dist/chart/bar-cluster-geometry.d.ts +6 -0
- package/dist/chart/bar-cluster-geometry.d.ts.map +1 -1
- package/dist/chart/index.cjs +5 -2
- package/dist/chart/index.mjs +5 -3
- package/dist/chart/render/chart-spacing.d.ts.map +1 -1
- package/dist/{chunk-TEOAOAIF.mjs → chunk-BB55ASTX.mjs} +3 -3
- package/dist/{chunk-CQQAPUAG.mjs → chunk-H4TPDZV4.mjs} +11 -9
- package/dist/{chunk-VYTA2OUN.mjs → chunk-IVDC75E5.mjs} +1 -1
- package/dist/{chunk-FI4RSJ24.mjs → chunk-QPQDLSJQ.mjs} +1 -1
- package/dist/{chunk-XCZ7U3GZ.mjs → chunk-XGLKW3JJ.mjs} +13 -9
- package/dist/docx/index.cjs +4 -2
- package/dist/docx/index.mjs +4 -2
- package/dist/docx/layout/index.cjs +4 -2
- package/dist/docx/layout/index.mjs +4 -2
- package/dist/docx/ui/index.cjs +4 -2
- package/dist/docx/ui/index.mjs +4 -2
- package/dist/index.cjs +5 -2
- package/dist/index.mjs +5 -2
- package/dist/pptx/automation/index.cjs +29 -17
- package/dist/pptx/automation/index.mjs +5 -5
- package/dist/pptx/chunks/index-EZJZ7USt.d.ts.map +1 -1
- package/dist/pptx/cli/index.cjs +29 -17
- package/dist/pptx/cli/index.mjs +4 -4
- package/dist/pptx/converter/index.mjs +2 -2
- package/dist/pptx/index.cjs +29 -17
- package/dist/pptx/index.mjs +5 -5
- package/dist/teams/index.cjs +176 -92
- package/dist/teams/index.mjs +176 -92
- package/dist/visio/clipboard-resources.d.ts +11 -0
- package/dist/visio/clipboard-resources.d.ts.map +1 -0
- package/dist/visio/clipboard-types.d.ts +26 -0
- package/dist/visio/clipboard-types.d.ts.map +1 -0
- package/dist/visio/clipboard-xml.d.ts +8 -0
- package/dist/visio/clipboard-xml.d.ts.map +1 -0
- package/dist/visio/clipboard.d.ts +7 -0
- package/dist/visio/clipboard.d.ts.map +1 -0
- package/dist/visio/create-document.d.ts +8 -0
- package/dist/visio/create-document.d.ts.map +1 -0
- package/dist/visio/edit-commands.d.ts +19 -2
- package/dist/visio/edit-commands.d.ts.map +1 -1
- package/dist/visio/edit-delete.d.ts +9 -0
- package/dist/visio/edit-delete.d.ts.map +1 -0
- package/dist/visio/edit-duplicate-commands.d.ts +14 -0
- package/dist/visio/edit-duplicate-commands.d.ts.map +1 -0
- package/dist/visio/edit-duplicate-scope.d.ts +4 -0
- package/dist/visio/edit-duplicate-scope.d.ts.map +1 -0
- package/dist/visio/edit-duplicate.d.ts +10 -0
- package/dist/visio/edit-duplicate.d.ts.map +1 -0
- package/dist/visio/edit-formatting-cell-admission.d.ts +3 -0
- package/dist/visio/edit-formatting-cell-admission.d.ts.map +1 -0
- package/dist/visio/edit-formatting-commands.d.ts +46 -0
- package/dist/visio/edit-formatting-commands.d.ts.map +1 -0
- package/dist/visio/edit-formatting-font.d.ts +6 -0
- package/dist/visio/edit-formatting-font.d.ts.map +1 -0
- package/dist/visio/edit-formatting-paint-scope.d.ts +6 -0
- package/dist/visio/edit-formatting-paint-scope.d.ts.map +1 -0
- package/dist/visio/edit-formatting-paint.d.ts +6 -0
- package/dist/visio/edit-formatting-paint.d.ts.map +1 -0
- package/dist/visio/edit-formatting-rows.d.ts +14 -0
- package/dist/visio/edit-formatting-rows.d.ts.map +1 -0
- package/dist/visio/edit-formatting-scope.d.ts +6 -0
- package/dist/visio/edit-formatting-scope.d.ts.map +1 -0
- package/dist/visio/edit-formatting-text.d.ts +8 -0
- package/dist/visio/edit-formatting-text.d.ts.map +1 -0
- package/dist/visio/edit-formatting.d.ts +12 -0
- package/dist/visio/edit-formatting.d.ts.map +1 -0
- package/dist/visio/edit-geometry.d.ts.map +1 -1
- package/dist/visio/edit-paste-commands.d.ts +15 -0
- package/dist/visio/edit-paste-commands.d.ts.map +1 -0
- package/dist/visio/edit-paste.d.ts +5 -0
- package/dist/visio/edit-paste.d.ts.map +1 -0
- package/dist/visio/edit-recalculate.d.ts +3 -1
- package/dist/visio/edit-recalculate.d.ts.map +1 -1
- package/dist/visio/edit-resize-anchor.d.ts +8 -0
- package/dist/visio/edit-resize-anchor.d.ts.map +1 -0
- package/dist/visio/edit-scope.d.ts.map +1 -1
- package/dist/visio/edit-shape-create.d.ts +1 -1
- package/dist/visio/edit-shape-create.d.ts.map +1 -1
- package/dist/visio/edit-shape-order.d.ts +7 -0
- package/dist/visio/edit-shape-order.d.ts.map +1 -0
- package/dist/visio/edit-style-admission.d.ts +17 -0
- package/dist/visio/edit-style-admission.d.ts.map +1 -0
- package/dist/visio/edit-text-scope.d.ts +7 -0
- package/dist/visio/edit-text-scope.d.ts.map +1 -0
- package/dist/visio/edit-text.d.ts +1 -1
- package/dist/visio/edit-text.d.ts.map +1 -1
- package/dist/visio/edit.d.ts +1 -1
- package/dist/visio/edit.d.ts.map +1 -1
- package/dist/visio/index.cjs +3245 -1077
- package/dist/visio/index.d.ts +3 -1
- package/dist/visio/index.d.ts.map +1 -1
- package/dist/visio/index.mjs +3241 -1079
- package/dist/visio/line-pattern.d.ts +1 -1
- package/dist/visio/line-pattern.d.ts.map +1 -1
- package/dist/visio/line-style.d.ts.map +1 -1
- package/dist/visio/model.d.ts +23 -3
- package/dist/visio/model.d.ts.map +1 -1
- package/dist/visio/parser.d.ts.map +1 -1
- package/dist/visio/plain-text.d.ts +5 -0
- package/dist/visio/plain-text.d.ts.map +1 -0
- package/dist/visio/resize-anchor.d.ts +27 -0
- package/dist/visio/resize-anchor.d.ts.map +1 -0
- package/dist/visio/source-paint.d.ts +5 -0
- package/dist/visio/source-paint.d.ts.map +1 -0
- package/dist/visio/style.d.ts.map +1 -1
- package/dist/visio/theme-root.d.ts.map +1 -1
- package/dist/visio/ui/contract.d.ts +10 -6
- package/dist/visio/ui/contract.d.ts.map +1 -1
- package/dist/visio/ui/draw-plan.d.ts +32 -0
- package/dist/visio/ui/draw-plan.d.ts.map +1 -0
- package/dist/visio/ui/edit-commands.d.ts.map +1 -1
- package/dist/visio/ui/formatting.d.ts +28 -0
- package/dist/visio/ui/formatting.d.ts.map +1 -0
- package/dist/visio/ui/index.cjs +1305 -15
- package/dist/visio/ui/index.d.ts +15 -0
- package/dist/visio/ui/index.d.ts.map +1 -1
- package/dist/visio/ui/index.mjs +1261 -16
- package/dist/visio/ui/line-dash.d.ts +4 -0
- package/dist/visio/ui/line-dash.d.ts.map +1 -0
- package/dist/visio/ui/marquee.d.ts +15 -0
- package/dist/visio/ui/marquee.d.ts.map +1 -0
- package/dist/visio/ui/page-edit.d.ts.map +1 -1
- package/dist/visio/ui/scene-validation.d.ts.map +1 -1
- package/dist/visio/ui/selection.d.ts +12 -0
- package/dist/visio/ui/selection.d.ts.map +1 -0
- package/dist/visio/ui/shape-arrange.d.ts +17 -0
- package/dist/visio/ui/shape-arrange.d.ts.map +1 -0
- package/dist/visio/ui/shape-clipboard.d.ts +10 -0
- package/dist/visio/ui/shape-clipboard.d.ts.map +1 -0
- package/dist/visio/ui/shape-duplicate.d.ts +5 -0
- package/dist/visio/ui/shape-duplicate.d.ts.map +1 -0
- package/dist/visio/ui/shape-formatting.d.ts +14 -0
- package/dist/visio/ui/shape-formatting.d.ts.map +1 -0
- package/dist/visio/ui/shape-move.d.ts +14 -0
- package/dist/visio/ui/shape-move.d.ts.map +1 -0
- package/dist/visio/ui/shape-order.d.ts +4 -0
- package/dist/visio/ui/shape-order.d.ts.map +1 -0
- package/dist/visio/ui/shape-resize.d.ts +61 -0
- package/dist/visio/ui/shape-resize.d.ts.map +1 -0
- package/dist/visio/ui/size-position.d.ts +19 -0
- package/dist/visio/ui/size-position.d.ts.map +1 -0
- package/dist/visio/ui/snapshot-scene.d.ts.map +1 -1
- package/dist/visio/ui/svg-stroke.d.ts +8 -0
- package/dist/visio/ui/svg-stroke.d.ts.map +1 -0
- package/dist/visio/ui/text-replace-selection.d.ts +9 -0
- package/dist/visio/ui/text-replace-selection.d.ts.map +1 -0
- package/dist/visio/ui/text-replace-snapshot.d.ts +14 -0
- package/dist/visio/ui/text-replace-snapshot.d.ts.map +1 -0
- package/dist/visio/ui/text-replace-types.d.ts +48 -0
- package/dist/visio/ui/text-replace-types.d.ts.map +1 -0
- package/dist/visio/ui/text-replace.d.ts +18 -0
- package/dist/visio/ui/text-replace.d.ts.map +1 -0
- package/dist/xlsx/edit/context.d.ts +3 -1
- package/dist/xlsx/edit/context.d.ts.map +1 -1
- package/dist/xlsx/edit/history.d.ts +18 -0
- package/dist/xlsx/edit/history.d.ts.map +1 -1
- package/dist/xlsx/edit/session-calc.d.ts +30 -8
- package/dist/xlsx/edit/session-calc.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/types.d.ts +23 -3
- package/dist/xlsx/edit/types.d.ts.map +1 -1
- package/dist/xlsx/formula/engine-core.d.ts.map +1 -1
- package/dist/xlsx/formula/engine-host.d.ts +6 -2
- package/dist/xlsx/formula/engine-host.d.ts.map +1 -1
- package/dist/xlsx/formula/engine-prepare.d.ts +33 -0
- package/dist/xlsx/formula/engine-prepare.d.ts.map +1 -0
- package/dist/xlsx/formula/engine-structure.d.ts +40 -0
- package/dist/xlsx/formula/engine-structure.d.ts.map +1 -0
- package/dist/xlsx/formula/engine-types.d.ts +26 -0
- package/dist/xlsx/formula/engine-types.d.ts.map +1 -1
- package/dist/xlsx/formula/engine.d.ts.map +1 -1
- package/dist/xlsx/formula/formula-shape.d.ts +28 -0
- package/dist/xlsx/formula/formula-shape.d.ts.map +1 -0
- package/dist/xlsx/formula/graph-index.d.ts +3 -1
- package/dist/xlsx/formula/graph-index.d.ts.map +1 -1
- package/dist/xlsx/formula/graph.d.ts +5 -0
- package/dist/xlsx/formula/graph.d.ts.map +1 -1
- package/dist/xlsx/formula/lexemes.d.ts.map +1 -1
- package/dist/xlsx/formula/parse-cache.d.ts +9 -0
- package/dist/xlsx/formula/parse-cache.d.ts.map +1 -0
- package/dist/xlsx/formula/parser.d.ts +3 -0
- package/dist/xlsx/formula/parser.d.ts.map +1 -1
- package/dist/xlsx/formula/ref-text.d.ts +14 -0
- package/dist/xlsx/formula/ref-text.d.ts.map +1 -0
- package/dist/xlsx/formula/references.d.ts.map +1 -1
- package/dist/xlsx/formula/shift-formula.d.ts +19 -0
- package/dist/xlsx/formula/shift-formula.d.ts.map +1 -0
- package/dist/xlsx/formula/shift-graph.d.ts +42 -0
- package/dist/xlsx/formula/shift-graph.d.ts.map +1 -0
- package/dist/xlsx/formula/transform.d.ts +2 -23
- package/dist/xlsx/formula/transform.d.ts.map +1 -1
- package/dist/xlsx/index.cjs +1087 -338
- package/dist/xlsx/index.mjs +1087 -339
- package/dist/xlsx/layout/index.d.ts +1 -1
- package/dist/xlsx/layout/index.d.ts.map +1 -1
- package/dist/xlsx/layout/sheet-queries.d.ts +7 -0
- package/dist/xlsx/layout/sheet-queries.d.ts.map +1 -1
- package/dist/xlsx/load/index.cjs +170 -99
- package/dist/xlsx/load/index.mjs +170 -99
- package/dist/xlsx/ui/index.cjs +1072 -332
- package/dist/xlsx/ui/index.mjs +1072 -332
- package/package.json +1 -1
package/dist/visio/ui/index.cjs
CHANGED
|
@@ -13,7 +13,8 @@ var eventKeys = [
|
|
|
13
13
|
"document-error",
|
|
14
14
|
"page-change",
|
|
15
15
|
"zoom-change",
|
|
16
|
-
"shape-select"
|
|
16
|
+
"shape-select",
|
|
17
|
+
"selection-change"
|
|
17
18
|
];
|
|
18
19
|
|
|
19
20
|
// visio/ui/demo-document.ts
|
|
@@ -324,6 +325,259 @@ function textSearchStatus(search) {
|
|
|
324
325
|
return result + (search.indexTruncated ? " \xB7 Partial text index" : "");
|
|
325
326
|
}
|
|
326
327
|
|
|
328
|
+
// visio/package-common.ts
|
|
329
|
+
var VisioPackageError = class extends Error {
|
|
330
|
+
constructor(code, message) {
|
|
331
|
+
super(message);
|
|
332
|
+
this.code = code;
|
|
333
|
+
this.name = "VisioPackageError";
|
|
334
|
+
}
|
|
335
|
+
code;
|
|
336
|
+
};
|
|
337
|
+
function fail(code, message) {
|
|
338
|
+
throw new VisioPackageError(code, message);
|
|
339
|
+
}
|
|
340
|
+
new TextDecoder("utf-8", { fatal: true });
|
|
341
|
+
var crcTable = Uint32Array.from({ length: 256 }, (_, value) => {
|
|
342
|
+
for (let i = 0; i < 8; i++) value = value & 1 ? 3988292384 ^ value >>> 1 : value >>> 1;
|
|
343
|
+
return value >>> 0;
|
|
344
|
+
});
|
|
345
|
+
function crc32(bytes, crc = 4294967295) {
|
|
346
|
+
for (const byte of bytes) crc = (crcTable[(crc ^ byte) & 255] ?? 0) ^ crc >>> 8;
|
|
347
|
+
return crc >>> 0;
|
|
348
|
+
}
|
|
349
|
+
function decodePath(path) {
|
|
350
|
+
try {
|
|
351
|
+
return decodeURIComponent(path);
|
|
352
|
+
} catch {
|
|
353
|
+
return fail("UNSAFE_PATH", "Invalid percent encoding in package path");
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
function safePath(path, directory = false) {
|
|
357
|
+
const decoded = decodePath(path);
|
|
358
|
+
if (/%(?:2f|5c)/i.test(path)) fail("UNSAFE_PATH", "Encoded path separators are unsupported");
|
|
359
|
+
if (/[\\:#?\u0000-\u001f\u007f]/.test(path) || /[\\:#?%\u0000-\u001f\u007f]/.test(decoded))
|
|
360
|
+
fail("UNSAFE_PATH", `Unsafe package path: ${path}`);
|
|
361
|
+
for (const candidate of [path, decoded]) {
|
|
362
|
+
const name = directory && candidate.endsWith("/") ? candidate.slice(0, -1) : candidate;
|
|
363
|
+
if (!name || name.split("/").some((part) => !part || part === "." || part === ".."))
|
|
364
|
+
fail("UNSAFE_PATH", `Unsafe package path: ${path}`);
|
|
365
|
+
}
|
|
366
|
+
return path;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// visio/edit-formatting-commands.ts
|
|
370
|
+
var isVisioFormatEdit = (edit) => edit.type === "format-text" || edit.type === "format-shape";
|
|
371
|
+
function snapshotFormatting(edit) {
|
|
372
|
+
const result = { type: edit.type, pageId: edit.pageId, shapeId: edit.shapeId };
|
|
373
|
+
const points = (value, minimum, maximum) => {
|
|
374
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < minimum || value > maximum)
|
|
375
|
+
fail("INVALID_EDIT", "Formatting point size is outside supported limits.");
|
|
376
|
+
return value;
|
|
377
|
+
};
|
|
378
|
+
const color = (value, allowNone = false) => {
|
|
379
|
+
if (typeof value !== "string" || !(allowNone && value === "none") && !/^#[0-9a-f]{6}$/i.test(value))
|
|
380
|
+
fail("INVALID_EDIT", "Formatting colors require six hexadecimal digits.");
|
|
381
|
+
return value.toLowerCase();
|
|
382
|
+
};
|
|
383
|
+
if (edit.type === "format-text" && result.type === "format-text") {
|
|
384
|
+
if (edit.fontSize !== void 0) result.fontSize = points(edit.fontSize, 1, 1e3);
|
|
385
|
+
if (edit.fontColor !== void 0) result.fontColor = color(edit.fontColor);
|
|
386
|
+
if (edit.indentLeft !== void 0) result.indentLeft = points(edit.indentLeft, 0, 7200);
|
|
387
|
+
if (edit.fontFamily !== void 0) {
|
|
388
|
+
if (typeof edit.fontFamily !== "string" || !edit.fontFamily.trim() || edit.fontFamily.length > 256 || /[\u0000-\u001f\u007f]/.test(edit.fontFamily))
|
|
389
|
+
fail("INVALID_EDIT", "Invalid font family.");
|
|
390
|
+
result.fontFamily = edit.fontFamily;
|
|
391
|
+
}
|
|
392
|
+
for (const name of ["bold", "italic", "underline", "strikethrough", "bullets"]) {
|
|
393
|
+
if (edit[name] === void 0) continue;
|
|
394
|
+
if (typeof edit[name] !== "boolean") fail("INVALID_EDIT", "Text styles require booleans.");
|
|
395
|
+
result[name] = edit[name];
|
|
396
|
+
}
|
|
397
|
+
if (edit.horizontalAlign !== void 0) {
|
|
398
|
+
if (!["left", "center", "right", "justify"].includes(edit.horizontalAlign))
|
|
399
|
+
fail("INVALID_EDIT", "Invalid horizontal alignment.");
|
|
400
|
+
result.horizontalAlign = edit.horizontalAlign;
|
|
401
|
+
}
|
|
402
|
+
if (edit.verticalAlign !== void 0) {
|
|
403
|
+
if (!["top", "middle", "bottom"].includes(edit.verticalAlign))
|
|
404
|
+
fail("INVALID_EDIT", "Invalid vertical alignment.");
|
|
405
|
+
result.verticalAlign = edit.verticalAlign;
|
|
406
|
+
}
|
|
407
|
+
} else if (edit.type === "format-shape" && result.type === "format-shape") {
|
|
408
|
+
if (edit.fillColor !== void 0) result.fillColor = color(edit.fillColor, true);
|
|
409
|
+
if (edit.lineColor !== void 0) result.lineColor = color(edit.lineColor);
|
|
410
|
+
if (edit.lineWeight !== void 0) result.lineWeight = points(edit.lineWeight, 0, 100);
|
|
411
|
+
for (const [name, maximum] of [
|
|
412
|
+
["linePattern", 23],
|
|
413
|
+
["fillPattern", 24]
|
|
414
|
+
]) {
|
|
415
|
+
if (edit[name] === void 0) continue;
|
|
416
|
+
const value = points(edit[name], 0, maximum);
|
|
417
|
+
if (!Number.isInteger(value)) fail("INVALID_EDIT", "Paint patterns require integers.");
|
|
418
|
+
result[name] = value;
|
|
419
|
+
}
|
|
420
|
+
for (const name of ["lineTransparency", "fillTransparency"])
|
|
421
|
+
if (edit[name] !== void 0) result[name] = Math.round(points(edit[name], 0, 100) * 2) / 2;
|
|
422
|
+
if (edit.fillBackgroundColor !== void 0)
|
|
423
|
+
result.fillBackgroundColor = color(edit.fillBackgroundColor);
|
|
424
|
+
if (result.fillColor === "none" && result.fillPattern !== void 0 && result.fillPattern !== 0)
|
|
425
|
+
fail("INVALID_EDIT", "No fill conflicts with a visible fill pattern.");
|
|
426
|
+
}
|
|
427
|
+
if (Object.keys(result).length === 3)
|
|
428
|
+
fail("INVALID_EDIT", "Formatting requires at least one property.");
|
|
429
|
+
return result;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// visio/edit-duplicate-commands.ts
|
|
433
|
+
function snapshotDuplicateShapes(edit) {
|
|
434
|
+
if (!Array.isArray(edit.copies) || !edit.copies.length || edit.copies.length > 1e3)
|
|
435
|
+
fail("INVALID_EDIT", "Duplication requires between one and 1000 shape mappings.");
|
|
436
|
+
if ([edit.offsetX, edit.offsetY].some(
|
|
437
|
+
(value) => typeof value !== "number" || !Number.isFinite(value) || Math.abs(value) > 1e6
|
|
438
|
+
))
|
|
439
|
+
fail("INVALID_EDIT", "Duplication offsets require bounded finite drawing inches.");
|
|
440
|
+
const sources = /* @__PURE__ */ new Set(), targets = /* @__PURE__ */ new Set();
|
|
441
|
+
const id = (value) => {
|
|
442
|
+
if (typeof value !== "string" || !/^(0|[1-9]\d{0,9})$/.test(value) || Number(value) > 4294967295)
|
|
443
|
+
fail("INVALID_EDIT", "Duplicate shape IDs require canonical unsigned integers.");
|
|
444
|
+
return value;
|
|
445
|
+
};
|
|
446
|
+
const copies = edit.copies.map((copy) => {
|
|
447
|
+
if (!copy || typeof copy !== "object") fail("INVALID_EDIT", "Invalid duplicate shape mapping.");
|
|
448
|
+
const shapeId = id(copy.shapeId), newShapeId = id(copy.newShapeId);
|
|
449
|
+
if (sources.has(shapeId) || targets.has(newShapeId))
|
|
450
|
+
fail("INVALID_EDIT", "Duplicate shape mappings must have unique sources and targets.");
|
|
451
|
+
sources.add(shapeId);
|
|
452
|
+
targets.add(newShapeId);
|
|
453
|
+
return { shapeId, newShapeId };
|
|
454
|
+
});
|
|
455
|
+
return {
|
|
456
|
+
type: edit.type,
|
|
457
|
+
pageId: edit.pageId,
|
|
458
|
+
copies,
|
|
459
|
+
offsetX: edit.offsetX,
|
|
460
|
+
offsetY: edit.offsetY
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// visio/clipboard-types.ts
|
|
465
|
+
var VISIO_CLIPBOARD_MAX_CHARS = 8 * 1024 * 1024;
|
|
466
|
+
function clipboardId(value) {
|
|
467
|
+
if (typeof value !== "string" || !/^(0|[1-9]\d{0,9})$/.test(value) || Number(value) > 4294967295)
|
|
468
|
+
fail("INVALID_CLIPBOARD", "Clipboard IDs require canonical unsigned integers.");
|
|
469
|
+
return value;
|
|
470
|
+
}
|
|
471
|
+
function snapshotVisioClipboard(value) {
|
|
472
|
+
if (!value || typeof value !== "object" || value.format !== "ooxml.visio-shapes" || value.version !== 1)
|
|
473
|
+
fail("INVALID_CLIPBOARD", "Unsupported Visio clipboard format or version.");
|
|
474
|
+
const sourcePageId = clipboardId(value.sourcePageId), sourceDrawingScale = value.sourceDrawingScale;
|
|
475
|
+
if (!Number.isFinite(sourceDrawingScale) || sourceDrawingScale <= 0 || sourceDrawingScale > 1e6)
|
|
476
|
+
fail("INVALID_CLIPBOARD", "Invalid clipboard drawing ratio.");
|
|
477
|
+
let characters = 0;
|
|
478
|
+
const text = (input) => {
|
|
479
|
+
if (typeof input !== "string" || (characters += input.length) > VISIO_CLIPBOARD_MAX_CHARS)
|
|
480
|
+
fail("LIMIT_CLIPBOARD", "Clipboard XML exceeds bounded text limits.");
|
|
481
|
+
if (/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/.test(input))
|
|
482
|
+
fail("INVALID_CLIPBOARD", "Clipboard XML must contain well-formed Unicode.");
|
|
483
|
+
return input;
|
|
484
|
+
};
|
|
485
|
+
const list = (input, max) => {
|
|
486
|
+
if (!Array.isArray(input) || !input.length || input.length > max)
|
|
487
|
+
fail("INVALID_CLIPBOARD", "Invalid clipboard array length.");
|
|
488
|
+
return input;
|
|
489
|
+
};
|
|
490
|
+
const selectionIds = list(value.selectionIds, 1e3).map(clipboardId);
|
|
491
|
+
const shapes = list(value.shapes, 1e3).map((shape) => {
|
|
492
|
+
if (!shape || typeof shape !== "object") fail("INVALID_CLIPBOARD", "Invalid captured shape.");
|
|
493
|
+
return { shapeId: clipboardId(shape.shapeId), xml: text(shape.xml) };
|
|
494
|
+
});
|
|
495
|
+
const resources = list(value.resources, 64).map((resource) => {
|
|
496
|
+
const path = resource?.path;
|
|
497
|
+
if (!resource || typeof resource !== "object" || typeof path !== "string" || path.length > 1024 || !/^visio\/(?:document\.xml|_rels\/document\.xml\.rels|theme\/[^/]+\.(?:xml|rels)|theme\/_rels\/[^/]+\.rels)$/.test(
|
|
498
|
+
path
|
|
499
|
+
))
|
|
500
|
+
fail("INVALID_CLIPBOARD", "Invalid clipboard resource path.");
|
|
501
|
+
return { path: text(safePath(path)), xml: text(resource.xml) };
|
|
502
|
+
});
|
|
503
|
+
if (new Set(selectionIds).size !== selectionIds.length || new Set(shapes.map((shape) => shape.shapeId)).size !== shapes.length || selectionIds.length !== shapes.length || selectionIds.some((id) => !shapes.some((shape) => shape.shapeId === id)) || new Set(resources.map((resource) => resource.path)).size !== resources.length)
|
|
504
|
+
fail("INVALID_CLIPBOARD", "Clipboard mappings and resources must be unique and complete.");
|
|
505
|
+
return {
|
|
506
|
+
format: "ooxml.visio-shapes",
|
|
507
|
+
version: 1,
|
|
508
|
+
sourcePageId,
|
|
509
|
+
sourceDrawingScale,
|
|
510
|
+
selectionIds,
|
|
511
|
+
shapes,
|
|
512
|
+
resources: resources.sort((a, b) => a.path.localeCompare(b.path)),
|
|
513
|
+
pageContext: text(value.pageContext)
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
// visio/edit-paste-commands.ts
|
|
518
|
+
function snapshotPasteShapes(edit) {
|
|
519
|
+
const clipboard = snapshotVisioClipboard(edit.clipboard);
|
|
520
|
+
const copies = snapshotDuplicateShapes({
|
|
521
|
+
type: "duplicate-shapes",
|
|
522
|
+
pageId: edit.pageId,
|
|
523
|
+
copies: edit.copies,
|
|
524
|
+
offsetX: edit.offsetX,
|
|
525
|
+
offsetY: edit.offsetY
|
|
526
|
+
});
|
|
527
|
+
if (copies.copies.length !== clipboard.shapes.length || copies.copies.some((copy) => !clipboard.selectionIds.includes(copy.shapeId)))
|
|
528
|
+
fail("INVALID_CLIPBOARD", "Paste mappings must cover every captured shape exactly once.");
|
|
529
|
+
return {
|
|
530
|
+
type: "paste-shapes",
|
|
531
|
+
pageId: copies.pageId,
|
|
532
|
+
copies: copies.copies,
|
|
533
|
+
offsetX: copies.offsetX,
|
|
534
|
+
offsetY: copies.offsetY,
|
|
535
|
+
clipboard
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
// visio/resize-anchor.ts
|
|
540
|
+
function snapshotResizeAnchor(value) {
|
|
541
|
+
if (value === void 0) return void 0;
|
|
542
|
+
if (!value || typeof value !== "object") fail("INVALID_EDIT", "Invalid resize anchor.");
|
|
543
|
+
const { x, y } = value;
|
|
544
|
+
if (![0, 0.5, 1].includes(x) || ![0, 0.5, 1].includes(y))
|
|
545
|
+
fail("INVALID_EDIT", "Resize anchor coordinates must be 0, 0.5 or 1.");
|
|
546
|
+
return { x, y };
|
|
547
|
+
}
|
|
548
|
+
function visioAnchoredResizeGeometry(current, size, anchor) {
|
|
549
|
+
const [a, b, c, d, e, f] = current.transform;
|
|
550
|
+
const determinant = a * d - b * c;
|
|
551
|
+
if (![0, 0.5, 1].includes(anchor.x) || ![0, 0.5, 1].includes(anchor.y) || ![
|
|
552
|
+
current.width,
|
|
553
|
+
current.height,
|
|
554
|
+
current.pinX,
|
|
555
|
+
current.pinY,
|
|
556
|
+
...current.transform,
|
|
557
|
+
size.width,
|
|
558
|
+
size.height,
|
|
559
|
+
anchor.x,
|
|
560
|
+
anchor.y
|
|
561
|
+
].every(Number.isFinite) || !(current.width > 0 && current.height > 0 && size.width > 0 && size.height > 0) || Math.abs(Math.abs(determinant) - 1) > 1e-8 || Math.abs(a * a + b * b - 1) > 1e-8 || Math.abs(c * c + d * d - 1) > 1e-8 || Math.abs(a * c + b * d) > 1e-8)
|
|
562
|
+
return void 0;
|
|
563
|
+
const offsetX = current.pinX - e, offsetY = current.pinY - f;
|
|
564
|
+
const oldX = (d * offsetX - c * offsetY) / determinant;
|
|
565
|
+
const oldY = (-b * offsetX + a * offsetY) / determinant;
|
|
566
|
+
const locPinX = oldX / current.width * size.width, locPinY = oldY / current.height * size.height;
|
|
567
|
+
const deltaX = anchor.x * (current.width - size.width) - oldX + locPinX;
|
|
568
|
+
const deltaY = anchor.y * (current.height - size.height) - oldY + locPinY;
|
|
569
|
+
const pinX = current.pinX + a * deltaX + c * deltaY, pinY = current.pinY + b * deltaX + d * deltaY;
|
|
570
|
+
const matrix2 = [
|
|
571
|
+
a,
|
|
572
|
+
b,
|
|
573
|
+
c,
|
|
574
|
+
d,
|
|
575
|
+
pinX - a * locPinX - c * locPinY,
|
|
576
|
+
pinY - b * locPinX - d * locPinY
|
|
577
|
+
];
|
|
578
|
+
return [pinX, pinY, locPinX, locPinY, ...matrix2].every(Number.isFinite) ? { pinX, pinY, locPinX, locPinY, transform: matrix2 } : void 0;
|
|
579
|
+
}
|
|
580
|
+
|
|
327
581
|
// visio/ui/edit-commands.ts
|
|
328
582
|
function snapshotEdits(edits) {
|
|
329
583
|
if (!Array.isArray(edits) || edits.length > 1e3)
|
|
@@ -332,6 +586,8 @@ function snapshotEdits(edits) {
|
|
|
332
586
|
return edits.map((command) => {
|
|
333
587
|
if (!command || typeof command.pageId !== "string" || !command.pageId || command.pageId.length > 256)
|
|
334
588
|
throw new Error("Invalid edit command.");
|
|
589
|
+
if (command.type === "duplicate-shapes") return snapshotDuplicateShapes(command);
|
|
590
|
+
if (command.type === "paste-shapes") return snapshotPasteShapes(command);
|
|
335
591
|
if (command.type === "reorder-page") {
|
|
336
592
|
if (!Number.isSafeInteger(command.index) || command.index < 0 || command.index > 1e6)
|
|
337
593
|
throw new Error("Invalid page order index.");
|
|
@@ -364,7 +620,23 @@ function snapshotEdits(edits) {
|
|
|
364
620
|
if (typeof command.shapeId !== "string" || !command.shapeId || command.shapeId.length > 256)
|
|
365
621
|
throw new Error("Invalid edit shape target.");
|
|
366
622
|
const target = { pageId: command.pageId, shapeId: command.shapeId };
|
|
623
|
+
if (isVisioFormatEdit(command)) return snapshotFormatting(command);
|
|
367
624
|
switch (command.type) {
|
|
625
|
+
case "create-text-box":
|
|
626
|
+
numbers(command.x, command.y, command.width, command.height);
|
|
627
|
+
return {
|
|
628
|
+
type: command.type,
|
|
629
|
+
...target,
|
|
630
|
+
x: command.x,
|
|
631
|
+
y: command.y,
|
|
632
|
+
width: command.width,
|
|
633
|
+
height: command.height,
|
|
634
|
+
text: text(command.text)
|
|
635
|
+
};
|
|
636
|
+
case "reorder-shape":
|
|
637
|
+
if (!["front", "back", "forward", "backward"].includes(command.order))
|
|
638
|
+
throw new Error("Invalid shape order.");
|
|
639
|
+
return { ...target, type: command.type, order: command.order };
|
|
368
640
|
case "create-line":
|
|
369
641
|
numbers(command.beginX, command.beginY, command.endX, command.endY);
|
|
370
642
|
return {
|
|
@@ -400,9 +672,17 @@ function snapshotEdits(edits) {
|
|
|
400
672
|
x: command.x,
|
|
401
673
|
y: command.y
|
|
402
674
|
};
|
|
403
|
-
case "resize-shape":
|
|
675
|
+
case "resize-shape": {
|
|
404
676
|
numbers(command.width, command.height);
|
|
405
|
-
|
|
677
|
+
const anchor = snapshotResizeAnchor(command.anchor);
|
|
678
|
+
return {
|
|
679
|
+
type: command.type,
|
|
680
|
+
...target,
|
|
681
|
+
width: command.width,
|
|
682
|
+
height: command.height,
|
|
683
|
+
...anchor === void 0 ? {} : { anchor }
|
|
684
|
+
};
|
|
685
|
+
}
|
|
406
686
|
case "create-rectangle":
|
|
407
687
|
case "create-ellipse":
|
|
408
688
|
numbers(command.x, command.y, command.width, command.height);
|
|
@@ -430,15 +710,6 @@ function editErrorMessage(error) {
|
|
|
430
710
|
function isEditCancellation(error) {
|
|
431
711
|
return !!error && typeof error === "object" && "name" in error && error.name === "AbortError";
|
|
432
712
|
}
|
|
433
|
-
new TextDecoder("utf-8", { fatal: true });
|
|
434
|
-
var crcTable = Uint32Array.from({ length: 256 }, (_, value) => {
|
|
435
|
-
for (let i = 0; i < 8; i++) value = value & 1 ? 3988292384 ^ value >>> 1 : value >>> 1;
|
|
436
|
-
return value >>> 0;
|
|
437
|
-
});
|
|
438
|
-
function crc32(bytes, crc = 4294967295) {
|
|
439
|
-
for (const byte of bytes) crc = (crcTable[(crc ^ byte) & 255] ?? 0) ^ crc >>> 8;
|
|
440
|
-
return crc >>> 0;
|
|
441
|
-
}
|
|
442
713
|
|
|
443
714
|
// visio/foreign-vector-types.ts
|
|
444
715
|
var VISIO_FOREIGN_VECTOR_LIMITS = Object.freeze({
|
|
@@ -1378,6 +1649,29 @@ function transform(x, y, localX, localY, angle, flipX = false, flipY = false) {
|
|
|
1378
1649
|
return [a, b, c, d, x - a * localX - c * localY, y - b * localX - d * localY];
|
|
1379
1650
|
}
|
|
1380
1651
|
|
|
1652
|
+
// visio/parser.ts
|
|
1653
|
+
function getVisioPageLayers(document, pageId) {
|
|
1654
|
+
const result = [], seen = /* @__PURE__ */ new Set();
|
|
1655
|
+
const pages = new Map(document.pages.map((page) => [page.id, page]));
|
|
1656
|
+
let current = pages.get(pageId);
|
|
1657
|
+
while (current && !seen.has(current.id)) {
|
|
1658
|
+
seen.add(current.id);
|
|
1659
|
+
result.push(current);
|
|
1660
|
+
current = current.backgroundPageId === void 0 ? void 0 : pages.get(current.backgroundPageId);
|
|
1661
|
+
}
|
|
1662
|
+
return result.reverse();
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
// visio/visibility.ts
|
|
1666
|
+
var VISIO_VISIBILITY_LIMITS = Object.freeze({
|
|
1667
|
+
maxShapes: 25e3,
|
|
1668
|
+
maxDepth: 64,
|
|
1669
|
+
maxLayers: 25e3,
|
|
1670
|
+
maxMemberships: 1e5,
|
|
1671
|
+
maxMembershipsPerShape: 1024,
|
|
1672
|
+
maxLayerIdLength: 256
|
|
1673
|
+
});
|
|
1674
|
+
|
|
1381
1675
|
// visio/ui/foreign-vector-budget.ts
|
|
1382
1676
|
var FOREIGN_VECTOR_SCENE_LIMITS = Object.freeze({
|
|
1383
1677
|
maxNodes: 1e5,
|
|
@@ -1575,6 +1869,11 @@ function assertViewableDocument(model) {
|
|
|
1575
1869
|
metadataBytes += value.length;
|
|
1576
1870
|
if (metadataBytes > 1e6) throw new Error("The scene exceeds aggregate metadata limits.");
|
|
1577
1871
|
};
|
|
1872
|
+
if (model.fontFamilies !== void 0) {
|
|
1873
|
+
if (!Array.isArray(model.fontFamilies) || model.fontFamilies.length > 1e4)
|
|
1874
|
+
throw new Error("The scene has an invalid font family list.");
|
|
1875
|
+
for (const family of model.fontFamilies) label(family, 1024);
|
|
1876
|
+
}
|
|
1578
1877
|
for (const diagnostic of model.diagnostics) {
|
|
1579
1878
|
label(diagnostic.code, 256);
|
|
1580
1879
|
label(diagnostic.message);
|
|
@@ -1620,7 +1919,9 @@ function assertViewableDocument(model) {
|
|
|
1620
1919
|
member(shape.kind, ["shape", "group", "connector", "foreign"], "shape kind");
|
|
1621
1920
|
if (shape.groupDisplayMode !== void 0)
|
|
1622
1921
|
member(shape.groupDisplayMode, [0, 1, 2], "group display mode");
|
|
1623
|
-
member(shape.text.horizontalAlign, ["left", "center", "right"], "text alignment");
|
|
1922
|
+
member(shape.text.horizontalAlign, ["left", "center", "right", "justify"], "text alignment");
|
|
1923
|
+
for (const key of ["bold", "italic", "underline", "strikethrough"])
|
|
1924
|
+
if (shape.text[key] !== void 0) member(shape.text[key], [true, false], "text style");
|
|
1624
1925
|
member(shape.text.verticalAlign, ["top", "middle", "bottom"], "text alignment");
|
|
1625
1926
|
label(shape.name);
|
|
1626
1927
|
label(shape.text.fontFamily, 1024);
|
|
@@ -1659,7 +1960,7 @@ function assertViewableDocument(model) {
|
|
|
1659
1960
|
const dash = shape.style.lineDash;
|
|
1660
1961
|
if (!Array.isArray(dash) || dash.length < 2 || dash.length > 6 || dash.length % 2 !== 0)
|
|
1661
1962
|
throw new Error("The scene has an invalid normalized line dash.");
|
|
1662
|
-
for (const value of dash) finite2(value, "line dash length", 0,
|
|
1963
|
+
for (const value of dash) finite2(value, "line dash length", 0, 40);
|
|
1663
1964
|
if (!dash.some((value) => value > 0))
|
|
1664
1965
|
throw new Error("The scene has an empty line dash pattern.");
|
|
1665
1966
|
}
|
|
@@ -1674,6 +1975,21 @@ function assertViewableDocument(model) {
|
|
|
1674
1975
|
throw new Error("The scene has an invalid normalized line cap.");
|
|
1675
1976
|
finite2(shape.style.fillOpacity, "fill opacity", 0, 1);
|
|
1676
1977
|
finite2(shape.style.lineOpacity, "line opacity", 0, 1);
|
|
1978
|
+
if (shape.style.lineDashDotLength !== void 0)
|
|
1979
|
+
finite2(shape.style.lineDashDotLength, "line dash dot length", 0, 1e6);
|
|
1980
|
+
for (const name of [
|
|
1981
|
+
"fillForegroundOpacity",
|
|
1982
|
+
"fillBackgroundOpacity",
|
|
1983
|
+
"lineColorOpacity"
|
|
1984
|
+
])
|
|
1985
|
+
if (shape.style[name] !== void 0) finite2(shape.style[name], "source paint opacity", 0, 1);
|
|
1986
|
+
if (shape.style.fillPatternIndex !== void 0) {
|
|
1987
|
+
finite2(shape.style.fillPatternIndex, "source fill pattern", 0, 65535);
|
|
1988
|
+
if (!Number.isInteger(shape.style.fillPatternIndex))
|
|
1989
|
+
throw new Error("The scene has an invalid source fill pattern.");
|
|
1990
|
+
}
|
|
1991
|
+
if (shape.style.fillBackgroundColor !== void 0 && (typeof shape.style.fillBackgroundColor !== "string" || !/^#[0-9a-f]{6}$/i.test(shape.style.fillBackgroundColor)))
|
|
1992
|
+
throw new Error("The scene has an invalid source fill background color.");
|
|
1677
1993
|
if (shape.style.fillPattern) {
|
|
1678
1994
|
const tile = shape.style.fillPattern;
|
|
1679
1995
|
finite2(tile.width, "fill pattern width", 1 / 12, 1 / 12);
|
|
@@ -1696,6 +2012,8 @@ function assertViewableDocument(model) {
|
|
|
1696
2012
|
if (!Array.isArray(shape.text.runs) || runCount + shape.text.runs.length > 1e5)
|
|
1697
2013
|
throw new Error("The scene exceeds safe text run limits or has an invalid run list.");
|
|
1698
2014
|
for (const run of shape.text.runs) {
|
|
2015
|
+
if (run.strikethrough !== void 0)
|
|
2016
|
+
member(run.strikethrough, [true, false], "strikethrough style");
|
|
1699
2017
|
label(run.fontFamily, 1024);
|
|
1700
2018
|
label(run.color, 256);
|
|
1701
2019
|
if (run.opacity !== void 0) finite2(run.opacity, "text run opacity", 0, 1);
|
|
@@ -1868,10 +2186,16 @@ function copySnapshotScene(model) {
|
|
|
1868
2186
|
const style = (source) => {
|
|
1869
2187
|
const result = fields(source, [
|
|
1870
2188
|
"fill",
|
|
2189
|
+
"fillPatternIndex",
|
|
2190
|
+
"fillForegroundOpacity",
|
|
2191
|
+
"fillBackgroundColor",
|
|
2192
|
+
"fillBackgroundOpacity",
|
|
1871
2193
|
"lineColor",
|
|
1872
2194
|
"lineWidth",
|
|
1873
2195
|
"lineCap",
|
|
1874
2196
|
"linePattern",
|
|
2197
|
+
"lineDashDotLength",
|
|
2198
|
+
"lineColorOpacity",
|
|
1875
2199
|
"fillOpacity",
|
|
1876
2200
|
"lineOpacity",
|
|
1877
2201
|
"startArrow",
|
|
@@ -1950,6 +2274,10 @@ function copySnapshotScene(model) {
|
|
|
1950
2274
|
const text = (source) => ({
|
|
1951
2275
|
...fields(source, [
|
|
1952
2276
|
"plainText",
|
|
2277
|
+
"bold",
|
|
2278
|
+
"italic",
|
|
2279
|
+
"underline",
|
|
2280
|
+
"strikethrough",
|
|
1953
2281
|
"backgroundColor",
|
|
1954
2282
|
"backgroundOpacity",
|
|
1955
2283
|
"opacity",
|
|
@@ -1967,7 +2295,8 @@ function copySnapshotScene(model) {
|
|
|
1967
2295
|
...fields(run, ["text", "fontFamily", "fontSize", "color", "opacity"]),
|
|
1968
2296
|
bold: !!run.bold,
|
|
1969
2297
|
italic: !!run.italic,
|
|
1970
|
-
underline: !!run.underline
|
|
2298
|
+
underline: !!run.underline,
|
|
2299
|
+
...run.strikethrough === void 0 ? {} : { strikethrough: !!run.strikethrough }
|
|
1971
2300
|
})),
|
|
1972
2301
|
...source.paragraphs === void 0 ? {} : { paragraphs: list(source.paragraphs, "paragraphs", 5e4, paragraph) }
|
|
1973
2302
|
});
|
|
@@ -1999,6 +2328,12 @@ function copySnapshotScene(model) {
|
|
|
1999
2328
|
};
|
|
2000
2329
|
return {
|
|
2001
2330
|
format: "vsdx",
|
|
2331
|
+
...model.fontFamilies === void 0 ? {} : {
|
|
2332
|
+
fontFamilies: list(model.fontFamilies, "font families", 1e4, (font) => {
|
|
2333
|
+
if (typeof font !== "string" || font.length > 1024) throw invalid2();
|
|
2334
|
+
return font;
|
|
2335
|
+
})
|
|
2336
|
+
},
|
|
2002
2337
|
diagnostics: list(
|
|
2003
2338
|
model.diagnostics,
|
|
2004
2339
|
"diagnostics",
|
|
@@ -2053,6 +2388,7 @@ function visioPageEditToDrawing(page, edit) {
|
|
|
2053
2388
|
return edit;
|
|
2054
2389
|
case "create-rectangle":
|
|
2055
2390
|
case "create-ellipse":
|
|
2391
|
+
case "create-text-box":
|
|
2056
2392
|
return {
|
|
2057
2393
|
...edit,
|
|
2058
2394
|
x: coordinate(edit.x),
|
|
@@ -2100,6 +2436,103 @@ function visioNextShapeId(page) {
|
|
|
2100
2436
|
return String(max + 1);
|
|
2101
2437
|
}
|
|
2102
2438
|
|
|
2439
|
+
// visio/ui/formatting.ts
|
|
2440
|
+
function visioStyleFormattingShape(page, shapeId) {
|
|
2441
|
+
const candidates = page.shapes.filter((shape2) => shape2.id === shapeId);
|
|
2442
|
+
if (candidates.length !== 1) return void 0;
|
|
2443
|
+
const shape = candidates[0];
|
|
2444
|
+
if (shape.hidden || shape.masterId || shape.layerIds?.length || shape.children.length || !["shape", "connector"].includes(shape.kind) || shape.image || shape.foreignVector)
|
|
2445
|
+
return void 0;
|
|
2446
|
+
return shape;
|
|
2447
|
+
}
|
|
2448
|
+
function visioFormattingShape(page, shapeId) {
|
|
2449
|
+
return visioStyleFormattingShape(page, shapeId);
|
|
2450
|
+
}
|
|
2451
|
+
function visioFontFamilies(document) {
|
|
2452
|
+
return [...new Set(document.fontFamilies ?? [])].sort((left, right) => left.localeCompare(right));
|
|
2453
|
+
}
|
|
2454
|
+
function visioTextFormattingState(shapes) {
|
|
2455
|
+
const common = (values) => values.length && values.every((value) => value === values[0]) ? values[0] : void 0;
|
|
2456
|
+
const runs = shapes.flatMap(
|
|
2457
|
+
(shape) => shape.text.runs.length ? shape.text.runs : [shape.text]
|
|
2458
|
+
);
|
|
2459
|
+
const styled = (key) => !!runs.length && runs.every((run) => !!run[key]);
|
|
2460
|
+
const paragraphs = shapes.flatMap((shape) => shape.text.paragraphs ?? []);
|
|
2461
|
+
const alignment = common(
|
|
2462
|
+
shapes.flatMap(
|
|
2463
|
+
(shape) => shape.text.paragraphs?.length ? shape.text.paragraphs.map((paragraph) => paragraph.horizontalAlign) : [shape.text.horizontalAlign]
|
|
2464
|
+
)
|
|
2465
|
+
);
|
|
2466
|
+
return {
|
|
2467
|
+
bold: styled("bold"),
|
|
2468
|
+
italic: styled("italic"),
|
|
2469
|
+
underline: styled("underline"),
|
|
2470
|
+
strikethrough: styled("strikethrough"),
|
|
2471
|
+
bullets: !!shapes.length && shapes.every(
|
|
2472
|
+
(shape) => !!shape.text.paragraphs?.length && shape.text.paragraphs.every((paragraph) => !!paragraph.bullet)
|
|
2473
|
+
),
|
|
2474
|
+
fontFamily: common(runs.map((run) => run.fontFamily)),
|
|
2475
|
+
fontSize: common(runs.map((run) => run.fontSize)),
|
|
2476
|
+
fontColor: common(runs.map((run) => run.color)),
|
|
2477
|
+
horizontalAlign: alignment === "distributed" ? void 0 : alignment,
|
|
2478
|
+
verticalAlign: common(shapes.map((shape) => shape.text.verticalAlign)),
|
|
2479
|
+
canIndentDecrease: paragraphs.some((paragraph) => paragraph.indentLeft > 0)
|
|
2480
|
+
};
|
|
2481
|
+
}
|
|
2482
|
+
function visioTextIndentCommand(page, shapeId, direction) {
|
|
2483
|
+
const shape = visioFormattingShape(page, shapeId);
|
|
2484
|
+
if (!shape || !["increase", "decrease"].includes(direction)) return void 0;
|
|
2485
|
+
const paragraphs = shape.text.paragraphs ?? [];
|
|
2486
|
+
const left = paragraphs[0]?.indentLeft ?? 0;
|
|
2487
|
+
if (!Number.isFinite(left) || left < 0 || paragraphs.some((paragraph) => paragraph.indentLeft !== left))
|
|
2488
|
+
return void 0;
|
|
2489
|
+
const points = left * 72;
|
|
2490
|
+
const indentLeft = Math.min(7200, Math.max(0, points + (direction === "increase" ? 18 : -18)));
|
|
2491
|
+
return { type: "format-text", pageId: page.id, shapeId, indentLeft };
|
|
2492
|
+
}
|
|
2493
|
+
function visioTextFontStepCommand(page, shapeId, direction) {
|
|
2494
|
+
const shape = visioFormattingShape(page, shapeId);
|
|
2495
|
+
if (!shape || !["increase", "decrease"].includes(direction)) return void 0;
|
|
2496
|
+
const sizes = shape.text.runs.length ? shape.text.runs.map((run) => run.fontSize) : [shape.text.fontSize];
|
|
2497
|
+
const size = sizes[0];
|
|
2498
|
+
if (!Number.isFinite(size) || sizes.some((value) => Math.abs(value - size) > 1e-10))
|
|
2499
|
+
return void 0;
|
|
2500
|
+
const current = size * 72;
|
|
2501
|
+
if (current < 1 || current > 1e3) return void 0;
|
|
2502
|
+
const steps = [6, 8, 9, 10, 11, 12, 14, 16, 18, 20, 24, 28, 32, 36, 48, 72];
|
|
2503
|
+
const fontSize = direction === "increase" ? steps.find((value) => value > current + 1e-3) ?? Math.min(1e3, Math.ceil(current * 1.2)) : steps.reverse().find((value) => value < current - 1e-3) ?? Math.max(1, Math.floor(current / 1.2));
|
|
2504
|
+
return { type: "format-text", pageId: page.id, shapeId, fontSize };
|
|
2505
|
+
}
|
|
2506
|
+
|
|
2507
|
+
// visio/ui/shape-duplicate.ts
|
|
2508
|
+
function visioDuplicateCommand(page, shapeIds) {
|
|
2509
|
+
if (!shapeIds.length || shapeIds.length > 1e3 || new Set(shapeIds).size !== shapeIds.length || shapeIds.some((id) => {
|
|
2510
|
+
const shape = visioStyleFormattingShape(page, id);
|
|
2511
|
+
return !shape || shape.kind !== "shape" || !(shape.width > 0) || !(shape.height > 0) || page.connectors.some(
|
|
2512
|
+
(connection) => connection.fromShapeId === id || connection.toShapeId === id
|
|
2513
|
+
);
|
|
2514
|
+
}))
|
|
2515
|
+
return void 0;
|
|
2516
|
+
let next;
|
|
2517
|
+
try {
|
|
2518
|
+
next = Number(visioNextShapeId(page));
|
|
2519
|
+
} catch {
|
|
2520
|
+
return void 0;
|
|
2521
|
+
}
|
|
2522
|
+
if (next + shapeIds.length - 1 > 4294967295) return void 0;
|
|
2523
|
+
const selected = new Set(shapeIds);
|
|
2524
|
+
const mapping = new Map(
|
|
2525
|
+
page.shapes.filter((shape) => selected.has(shape.id)).map((shape) => [shape.id, String(next++)])
|
|
2526
|
+
);
|
|
2527
|
+
return {
|
|
2528
|
+
type: "duplicate-shapes",
|
|
2529
|
+
pageId: page.id,
|
|
2530
|
+
copies: shapeIds.map((shapeId) => ({ shapeId, newShapeId: mapping.get(shapeId) })),
|
|
2531
|
+
offsetX: 0.33,
|
|
2532
|
+
offsetY: -0.33
|
|
2533
|
+
};
|
|
2534
|
+
}
|
|
2535
|
+
|
|
2103
2536
|
// visio/ui/fill-pattern-transform.ts
|
|
2104
2537
|
function visioFillPatternTransform(world, pageHeight = 0) {
|
|
2105
2538
|
const determinant = world[0] * world[3] - world[1] * world[2];
|
|
@@ -2159,15 +2592,830 @@ function visioQuarterTurnCommand(page, shapeId, direction) {
|
|
|
2159
2592
|
};
|
|
2160
2593
|
}
|
|
2161
2594
|
|
|
2595
|
+
// visio/ui/shape-order.ts
|
|
2596
|
+
function visioOrderingShape(page, shapeId) {
|
|
2597
|
+
if (page.shapes.some(
|
|
2598
|
+
(shape2) => shape2.kind !== "shape" || shape2.masterId || shape2.children.length || shape2.image || shape2.foreignVector
|
|
2599
|
+
))
|
|
2600
|
+
return void 0;
|
|
2601
|
+
const shape = page.shapes.find((candidate) => candidate.id === shapeId);
|
|
2602
|
+
return shape && !shape.hidden && !shape.layerIds?.length ? shape : void 0;
|
|
2603
|
+
}
|
|
2604
|
+
|
|
2605
|
+
// geometry/align-distribute.ts
|
|
2606
|
+
function usesSlideReference(elementCount, options) {
|
|
2607
|
+
if (!options?.slideSize) {
|
|
2608
|
+
return false;
|
|
2609
|
+
}
|
|
2610
|
+
return options.reference === "slide";
|
|
2611
|
+
}
|
|
2612
|
+
function resolveAlignReferenceBox(elements, options) {
|
|
2613
|
+
if (elements.length === 0) {
|
|
2614
|
+
return null;
|
|
2615
|
+
}
|
|
2616
|
+
if (usesSlideReference(elements.length, options)) {
|
|
2617
|
+
return { minX: 0, minY: 0, maxX: options.slideSize.width, maxY: options.slideSize.height };
|
|
2618
|
+
}
|
|
2619
|
+
if (elements.length < 2) {
|
|
2620
|
+
return null;
|
|
2621
|
+
}
|
|
2622
|
+
return {
|
|
2623
|
+
minX: Math.min(...elements.map((e) => e.x)),
|
|
2624
|
+
minY: Math.min(...elements.map((e) => e.y)),
|
|
2625
|
+
maxX: Math.max(...elements.map((e) => e.x + e.width)),
|
|
2626
|
+
maxY: Math.max(...elements.map((e) => e.y + e.height))
|
|
2627
|
+
};
|
|
2628
|
+
}
|
|
2629
|
+
function alignElements(elements, edge, options) {
|
|
2630
|
+
const result = /* @__PURE__ */ new Map();
|
|
2631
|
+
const ref = resolveAlignReferenceBox(elements, options);
|
|
2632
|
+
if (!ref) {
|
|
2633
|
+
return result;
|
|
2634
|
+
}
|
|
2635
|
+
const { minX, minY, maxX, maxY } = ref;
|
|
2636
|
+
const centerX = (minX + maxX) / 2;
|
|
2637
|
+
const centerY = (minY + maxY) / 2;
|
|
2638
|
+
for (const el of elements) {
|
|
2639
|
+
switch (edge) {
|
|
2640
|
+
case "left":
|
|
2641
|
+
result.set(el.id, { x: minX });
|
|
2642
|
+
break;
|
|
2643
|
+
case "right":
|
|
2644
|
+
result.set(el.id, { x: maxX - el.width });
|
|
2645
|
+
break;
|
|
2646
|
+
case "centerH":
|
|
2647
|
+
result.set(el.id, { x: centerX - el.width / 2 });
|
|
2648
|
+
break;
|
|
2649
|
+
case "top":
|
|
2650
|
+
result.set(el.id, { y: minY });
|
|
2651
|
+
break;
|
|
2652
|
+
case "bottom":
|
|
2653
|
+
result.set(el.id, { y: maxY - el.height });
|
|
2654
|
+
break;
|
|
2655
|
+
case "middle":
|
|
2656
|
+
result.set(el.id, { y: centerY - el.height / 2 });
|
|
2657
|
+
break;
|
|
2658
|
+
}
|
|
2659
|
+
}
|
|
2660
|
+
return result;
|
|
2661
|
+
}
|
|
2662
|
+
|
|
2663
|
+
// visio/ui/shape-arrange.ts
|
|
2664
|
+
function distributeBoxes(boxes, axis) {
|
|
2665
|
+
const horizontal = axis === "horizontal";
|
|
2666
|
+
const start = (box2) => horizontal ? box2.x : -box2.y - box2.height;
|
|
2667
|
+
const size = (box2) => horizontal ? box2.width : box2.height;
|
|
2668
|
+
const center = (box2) => start(box2) + size(box2) / 2;
|
|
2669
|
+
const sorted = [...boxes].sort((left, right) => center(left) - center(right));
|
|
2670
|
+
const first = sorted[0], last = sorted.at(-1);
|
|
2671
|
+
const total = sorted.reduce((sum, box2) => sum + size(box2), 0);
|
|
2672
|
+
const gap = (start(last) + size(last) - start(first) - total) / (sorted.length - 1);
|
|
2673
|
+
let cursor = start(first);
|
|
2674
|
+
const positions = /* @__PURE__ */ new Map();
|
|
2675
|
+
for (const box2 of sorted) {
|
|
2676
|
+
positions.set(box2.id, horizontal ? { x: cursor } : { y: -cursor - box2.height });
|
|
2677
|
+
cursor += size(box2) + gap;
|
|
2678
|
+
}
|
|
2679
|
+
return positions;
|
|
2680
|
+
}
|
|
2681
|
+
function alignmentBox(shape) {
|
|
2682
|
+
if (!shape.rotation || shape.kind !== "shape" || !(shape.width > 0 && shape.height > 0))
|
|
2683
|
+
return void 0;
|
|
2684
|
+
const [a, b, c, d, e, f] = shape.transform;
|
|
2685
|
+
if (![a, b, c, d, e, f, shape.rotation.pinX, shape.rotation.pinY, shape.width, shape.height].every(
|
|
2686
|
+
Number.isFinite
|
|
2687
|
+
))
|
|
2688
|
+
return void 0;
|
|
2689
|
+
const points = [
|
|
2690
|
+
[0, 0],
|
|
2691
|
+
[shape.width, 0],
|
|
2692
|
+
[0, shape.height],
|
|
2693
|
+
[shape.width, shape.height]
|
|
2694
|
+
];
|
|
2695
|
+
const xs = points.map(([x2, y]) => a * x2 + c * y + e);
|
|
2696
|
+
const ys = points.map(([x2, y]) => b * x2 + d * y + f);
|
|
2697
|
+
const x = Math.min(...xs), top = Math.max(...ys);
|
|
2698
|
+
const width = Math.max(...xs) - x, height = top - Math.min(...ys);
|
|
2699
|
+
if (![x, top, width, height].every(Number.isFinite) || width <= 0 || height <= 0)
|
|
2700
|
+
return void 0;
|
|
2701
|
+
return { id: shape.id, x, y: -top, width, height };
|
|
2702
|
+
}
|
|
2703
|
+
function visioArrangeCommands(page, shapeIds, action) {
|
|
2704
|
+
const minimum = action.type === "align" ? 2 : 3;
|
|
2705
|
+
if (shapeIds.length < minimum || shapeIds.length > 1e3 || new Set(shapeIds).size !== shapeIds.length)
|
|
2706
|
+
return void 0;
|
|
2707
|
+
if (action.type === "align" ? !["left", "center", "right", "top", "middle", "bottom"].includes(action.edge) : action.type !== "distribute" || !["horizontal", "vertical"].includes(action.axis))
|
|
2708
|
+
return void 0;
|
|
2709
|
+
const shapes = [];
|
|
2710
|
+
const boxes = [];
|
|
2711
|
+
for (const id of shapeIds) {
|
|
2712
|
+
const shape = visioStyleFormattingShape(page, id);
|
|
2713
|
+
const box2 = shape && alignmentBox(shape);
|
|
2714
|
+
if (!shape || !box2 || page.connectors.some(
|
|
2715
|
+
(connection) => connection.fromShapeId === id || connection.toShapeId === id
|
|
2716
|
+
))
|
|
2717
|
+
return void 0;
|
|
2718
|
+
shapes.push(shape);
|
|
2719
|
+
boxes.push(box2);
|
|
2720
|
+
}
|
|
2721
|
+
const reference = boxes[0];
|
|
2722
|
+
const normalized = boxes.map((box2) => ({
|
|
2723
|
+
...box2,
|
|
2724
|
+
x: box2.x - reference.x,
|
|
2725
|
+
y: box2.y - reference.y
|
|
2726
|
+
}));
|
|
2727
|
+
const edge = action.type === "align" ? action.edge === "center" ? "centerH" : action.edge : void 0;
|
|
2728
|
+
const positions = action.type === "align" ? alignElements(normalized, edge, {
|
|
2729
|
+
reference: "slide",
|
|
2730
|
+
slideSize: { width: reference.width, height: reference.height }
|
|
2731
|
+
}) : distributeBoxes(normalized, action.axis);
|
|
2732
|
+
const commands = [];
|
|
2733
|
+
try {
|
|
2734
|
+
for (let index = 0; index < shapes.length; index++) {
|
|
2735
|
+
const shape = shapes[index], box2 = normalized[index];
|
|
2736
|
+
const position = positions.get(shape.id);
|
|
2737
|
+
if (!position) return void 0;
|
|
2738
|
+
const dx = (position.x ?? box2.x) - box2.x, dy = -((position.y ?? box2.y) - box2.y);
|
|
2739
|
+
if (Math.abs(dx) < 1e-10 && Math.abs(dy) < 1e-10) continue;
|
|
2740
|
+
commands.push(
|
|
2741
|
+
visioPageEditToDrawing(page, {
|
|
2742
|
+
type: "move-shape",
|
|
2743
|
+
pageId: page.id,
|
|
2744
|
+
shapeId: shape.id,
|
|
2745
|
+
x: shape.rotation.pinX + dx,
|
|
2746
|
+
y: shape.rotation.pinY + dy
|
|
2747
|
+
})
|
|
2748
|
+
);
|
|
2749
|
+
}
|
|
2750
|
+
} catch {
|
|
2751
|
+
return void 0;
|
|
2752
|
+
}
|
|
2753
|
+
return commands;
|
|
2754
|
+
}
|
|
2755
|
+
|
|
2756
|
+
// visio/ui/selection.ts
|
|
2757
|
+
var EMPTY_SELECTION = Object.freeze([]);
|
|
2758
|
+
var selectionKey = (shape, pageId) => JSON.stringify([shape.pageId ?? pageId, shape.id]);
|
|
2759
|
+
function visioSelectionIsOnPage(selection, pageId) {
|
|
2760
|
+
return !!selection && (selection.pageId === void 0 || selection.pageId === pageId);
|
|
2761
|
+
}
|
|
2762
|
+
function sameSelection(left, right) {
|
|
2763
|
+
return left.length === right.length && left.every((shape, index) => {
|
|
2764
|
+
const other = right[index];
|
|
2765
|
+
return shape.id === other.id && shape.pageId === other.pageId && shape.name === other.name;
|
|
2766
|
+
});
|
|
2767
|
+
}
|
|
2768
|
+
function snapshotSelection(model, pageIndex, input, visible) {
|
|
2769
|
+
if (!Array.isArray(input)) throw new Error("Selection requires an array.");
|
|
2770
|
+
const length = input.length;
|
|
2771
|
+
if (length > VISIO_VISIBILITY_LIMITS.maxShapes)
|
|
2772
|
+
throw new Error("Selection exceeds the supported shape count.");
|
|
2773
|
+
const page = model?.pages[pageIndex];
|
|
2774
|
+
const candidates = /* @__PURE__ */ new Map();
|
|
2775
|
+
for (let index = 0; index < length; index++) {
|
|
2776
|
+
const item = input[index];
|
|
2777
|
+
const id = item?.id, name = item?.name, pageId = item?.pageId;
|
|
2778
|
+
if (typeof id !== "string" || typeof name !== "string" || id.length > 1024 || name.length > 4096 || pageId !== void 0 && (typeof pageId !== "string" || pageId.length > 256))
|
|
2779
|
+
throw new Error("Selection requires shape IDs, names and optional page IDs.");
|
|
2780
|
+
const copied = Object.freeze({ id, name, ...pageId === void 0 ? {} : { pageId } });
|
|
2781
|
+
const key = selectionKey(copied, page?.id ?? "");
|
|
2782
|
+
if (!candidates.has(key)) candidates.set(key, copied);
|
|
2783
|
+
}
|
|
2784
|
+
if (!model || !page || !length) return EMPTY_SELECTION;
|
|
2785
|
+
const accepted = /* @__PURE__ */ new Map();
|
|
2786
|
+
const content = /* @__PURE__ */ new WeakMap();
|
|
2787
|
+
for (const source of getVisioPageLayers(model, page.id)) {
|
|
2788
|
+
const pending = source.shapes.map((shape) => ({ shape, ancestors: [] }));
|
|
2789
|
+
while (pending.length) {
|
|
2790
|
+
const { shape, ancestors } = pending.pop();
|
|
2791
|
+
const key = selectionKey({ id: shape.id, pageId: source.id }, page.id);
|
|
2792
|
+
if (candidates.has(key) && hasVisibleShapeContent(shape, visible, content))
|
|
2793
|
+
accepted.set(key, ancestors);
|
|
2794
|
+
for (const child of shape.children)
|
|
2795
|
+
pending.push({ shape: child, ancestors: [...ancestors, key] });
|
|
2796
|
+
}
|
|
2797
|
+
}
|
|
2798
|
+
const result = [];
|
|
2799
|
+
for (const [key, item] of candidates) {
|
|
2800
|
+
const ancestors = accepted.get(key);
|
|
2801
|
+
if (!ancestors || ancestors.some((ancestor) => accepted.has(ancestor))) continue;
|
|
2802
|
+
result.push(item);
|
|
2803
|
+
}
|
|
2804
|
+
return result.length ? Object.freeze(result) : EMPTY_SELECTION;
|
|
2805
|
+
}
|
|
2806
|
+
function hasVisibleShapeContent(shape, visible, cache = /* @__PURE__ */ new WeakMap()) {
|
|
2807
|
+
const cached = cache.get(shape);
|
|
2808
|
+
if (cached !== void 0) return cached;
|
|
2809
|
+
const own = !(shape.kind === "group" && shape.groupDisplayMode === 0) && (shape.geometry.length > 0 || !!shape.image || !!shape.foreignVector || !!shape.text.plainText || shape.kind === "foreign");
|
|
2810
|
+
const renderable = (visible?.get(shape) ?? !shape.hidden) && (own || shape.children.some((child) => hasVisibleShapeContent(child, visible, cache)));
|
|
2811
|
+
cache.set(shape, renderable);
|
|
2812
|
+
return renderable;
|
|
2813
|
+
}
|
|
2814
|
+
|
|
2815
|
+
// visio/ui/shape-clipboard.ts
|
|
2816
|
+
function visioClipboardShape(page, shapeId) {
|
|
2817
|
+
const shape = visioStyleFormattingShape(page, shapeId);
|
|
2818
|
+
if (!shape || shape.kind !== "shape" || !(shape.width > 0) || !(shape.height > 0) || page.connectors.some(
|
|
2819
|
+
(connection) => connection.fromShapeId === shapeId || connection.toShapeId === shapeId
|
|
2820
|
+
))
|
|
2821
|
+
return void 0;
|
|
2822
|
+
return shape;
|
|
2823
|
+
}
|
|
2824
|
+
function visioPasteCommand(page, value, offset = { x: 0.33, y: -0.33 }) {
|
|
2825
|
+
try {
|
|
2826
|
+
const clipboard = snapshotVisioClipboard(value);
|
|
2827
|
+
if ((page.drawingToPageScale ?? 1) !== clipboard.sourceDrawingScale || [offset.x, offset.y].some((number) => !Number.isFinite(number) || Math.abs(number) > 1e6))
|
|
2828
|
+
return void 0;
|
|
2829
|
+
let next = Number(visioNextShapeId(page));
|
|
2830
|
+
if (next + clipboard.shapes.length - 1 > 4294967295) return void 0;
|
|
2831
|
+
const ids = new Map(clipboard.shapes.map((shape) => [shape.shapeId, String(next++)]));
|
|
2832
|
+
return {
|
|
2833
|
+
type: "paste-shapes",
|
|
2834
|
+
pageId: page.id,
|
|
2835
|
+
clipboard,
|
|
2836
|
+
copies: clipboard.selectionIds.map((shapeId) => ({ shapeId, newShapeId: ids.get(shapeId) })),
|
|
2837
|
+
offsetX: offset.x,
|
|
2838
|
+
offsetY: offset.y
|
|
2839
|
+
};
|
|
2840
|
+
} catch {
|
|
2841
|
+
return void 0;
|
|
2842
|
+
}
|
|
2843
|
+
}
|
|
2844
|
+
|
|
2845
|
+
// visio/ui/shape-move.ts
|
|
2846
|
+
function visioMovementShape(page, id) {
|
|
2847
|
+
const shape = visioStyleFormattingShape(page, id);
|
|
2848
|
+
if (!shape || shape.kind !== "shape" || !shape.rotation || !(shape.width > 0 && shape.height > 0) || ![
|
|
2849
|
+
shape.width,
|
|
2850
|
+
shape.height,
|
|
2851
|
+
shape.rotation.pinX,
|
|
2852
|
+
shape.rotation.pinY,
|
|
2853
|
+
...shape.transform
|
|
2854
|
+
].every(Number.isFinite) || page.connectors.some(
|
|
2855
|
+
(connection) => connection.fromShapeId === id || connection.toShapeId === id
|
|
2856
|
+
))
|
|
2857
|
+
return void 0;
|
|
2858
|
+
return shape;
|
|
2859
|
+
}
|
|
2860
|
+
function visioPageDragDelta(start, end) {
|
|
2861
|
+
return { x: end.x - start.x, y: start.y - end.y };
|
|
2862
|
+
}
|
|
2863
|
+
function visioMovePreviewTransform(shape, delta) {
|
|
2864
|
+
if (![delta.x, delta.y, ...shape.transform].every(Number.isFinite)) return void 0;
|
|
2865
|
+
const [a, b, c, d, e, f] = shape.transform;
|
|
2866
|
+
const result = [a, b, c, d, e + delta.x, f + delta.y];
|
|
2867
|
+
return result.every(Number.isFinite) ? result : void 0;
|
|
2868
|
+
}
|
|
2869
|
+
function visioMoveCommands(page, ids, delta) {
|
|
2870
|
+
if (!ids.length || ids.length > 1e3 || new Set(ids).size !== ids.length || ![delta.x, delta.y].every(Number.isFinite))
|
|
2871
|
+
return void 0;
|
|
2872
|
+
const shapes = ids.map((id) => visioMovementShape(page, id));
|
|
2873
|
+
if (shapes.some((shape) => !shape)) return void 0;
|
|
2874
|
+
if (delta.x === 0 && delta.y === 0) return [];
|
|
2875
|
+
try {
|
|
2876
|
+
const edits = shapes.map(
|
|
2877
|
+
(shape) => visioPageEditToDrawing(page, {
|
|
2878
|
+
type: "move-shape",
|
|
2879
|
+
pageId: page.id,
|
|
2880
|
+
shapeId: shape.id,
|
|
2881
|
+
x: shape.rotation.pinX + delta.x,
|
|
2882
|
+
y: shape.rotation.pinY + delta.y
|
|
2883
|
+
})
|
|
2884
|
+
);
|
|
2885
|
+
return edits.every(
|
|
2886
|
+
(edit) => edit.type === "move-shape" && Number.isFinite(edit.x) && Number.isFinite(edit.y)
|
|
2887
|
+
) ? edits : void 0;
|
|
2888
|
+
} catch {
|
|
2889
|
+
return void 0;
|
|
2890
|
+
}
|
|
2891
|
+
}
|
|
2892
|
+
|
|
2893
|
+
// visio/ui/size-position.ts
|
|
2894
|
+
var bounded = (value) => Number.isFinite(value) && Math.abs(value) <= 1e6;
|
|
2895
|
+
function visioSizePositionState(page, id) {
|
|
2896
|
+
const shape = visioMovementShape(page, id), ratio = page.drawingToPageScale ?? 1;
|
|
2897
|
+
if (!shape || !Number.isFinite(ratio) || ratio <= 0) return void 0;
|
|
2898
|
+
const rotation = shape.rotation;
|
|
2899
|
+
const state = {
|
|
2900
|
+
pageId: page.id,
|
|
2901
|
+
shapeId: id,
|
|
2902
|
+
x: rotation.pinX / ratio,
|
|
2903
|
+
y: rotation.pinY / ratio,
|
|
2904
|
+
width: shape.width / ratio,
|
|
2905
|
+
height: shape.height / ratio,
|
|
2906
|
+
angle: rotation.angle * 180 / Math.PI
|
|
2907
|
+
};
|
|
2908
|
+
if (![state.x, state.y, state.width, state.height, rotation.angle].every(bounded) || !Number.isFinite(state.angle))
|
|
2909
|
+
return void 0;
|
|
2910
|
+
return Object.freeze(state);
|
|
2911
|
+
}
|
|
2912
|
+
function visioSizePositionCommand(page, id, field, value) {
|
|
2913
|
+
const state = visioSizePositionState(page, id);
|
|
2914
|
+
if (!state || !Number.isFinite(value)) return void 0;
|
|
2915
|
+
if (!["x", "y", "width", "height", "angle"].includes(field)) return void 0;
|
|
2916
|
+
if (value === state[field]) return [];
|
|
2917
|
+
const target = { pageId: page.id, shapeId: id };
|
|
2918
|
+
if (field === "angle") {
|
|
2919
|
+
const angle = value * Math.PI / 180;
|
|
2920
|
+
return bounded(angle) ? [{ type: "rotate-shape", ...target, angle }] : void 0;
|
|
2921
|
+
}
|
|
2922
|
+
if (!bounded(value)) return void 0;
|
|
2923
|
+
if (field === "x" || field === "y")
|
|
2924
|
+
return [
|
|
2925
|
+
{
|
|
2926
|
+
type: "move-shape",
|
|
2927
|
+
...target,
|
|
2928
|
+
x: field === "x" ? value : state.x,
|
|
2929
|
+
y: field === "y" ? value : state.y
|
|
2930
|
+
}
|
|
2931
|
+
];
|
|
2932
|
+
if (value <= 0) return void 0;
|
|
2933
|
+
return [
|
|
2934
|
+
{
|
|
2935
|
+
type: "resize-shape",
|
|
2936
|
+
...target,
|
|
2937
|
+
width: field === "width" ? value : state.width,
|
|
2938
|
+
height: field === "height" ? value : state.height
|
|
2939
|
+
}
|
|
2940
|
+
];
|
|
2941
|
+
}
|
|
2942
|
+
|
|
2943
|
+
// visio/ui/marquee.ts
|
|
2944
|
+
function visioMarqueeBox(start, end) {
|
|
2945
|
+
if (![start.x, start.y, end.x, end.y].every(Number.isFinite)) return void 0;
|
|
2946
|
+
const box2 = {
|
|
2947
|
+
x: Math.min(start.x, end.x),
|
|
2948
|
+
y: Math.min(start.y, end.y),
|
|
2949
|
+
width: Math.abs(end.x - start.x),
|
|
2950
|
+
height: Math.abs(end.y - start.y)
|
|
2951
|
+
};
|
|
2952
|
+
return Object.values(box2).every(Number.isFinite) ? box2 : void 0;
|
|
2953
|
+
}
|
|
2954
|
+
function visioShapePageBox(page, shape) {
|
|
2955
|
+
if (![page.height, shape.width, shape.height, ...shape.transform].every(Number.isFinite) || shape.width < 0 || shape.height < 0)
|
|
2956
|
+
return void 0;
|
|
2957
|
+
const [a, b, c, d, e, f] = shape.transform;
|
|
2958
|
+
const corners = [
|
|
2959
|
+
[0, 0],
|
|
2960
|
+
[shape.width, 0],
|
|
2961
|
+
[0, shape.height],
|
|
2962
|
+
[shape.width, shape.height]
|
|
2963
|
+
];
|
|
2964
|
+
const xs = corners.map(([x, y]) => a * x + c * y + e), ys = corners.map(([x, y]) => b * x + d * y + f);
|
|
2965
|
+
const left = Math.min(...xs), right = Math.max(...xs), bottom = Math.min(...ys), top = Math.max(...ys);
|
|
2966
|
+
const box2 = { x: left, y: page.height - top, width: right - left, height: top - bottom };
|
|
2967
|
+
return Object.values(box2).every(Number.isFinite) ? box2 : void 0;
|
|
2968
|
+
}
|
|
2969
|
+
function visioMarqueeSelection(page, box2, visible) {
|
|
2970
|
+
if (![box2.x, box2.y, box2.width, box2.height].every(Number.isFinite) || box2.width <= 0 || box2.height <= 0)
|
|
2971
|
+
return [];
|
|
2972
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
2973
|
+
return page.shapes.flatMap((shape) => {
|
|
2974
|
+
const extent = visioShapePageBox(page, shape);
|
|
2975
|
+
return extent && hasVisibleShapeContent(shape, visible, cache) && extent.x >= box2.x && extent.y >= box2.y && extent.x + extent.width <= box2.x + box2.width && extent.y + extent.height <= box2.y + box2.height ? [{ id: shape.id, name: shape.name, pageId: page.id }] : [];
|
|
2976
|
+
});
|
|
2977
|
+
}
|
|
2978
|
+
|
|
2979
|
+
// visio/ui/shape-resize.ts
|
|
2980
|
+
var VISIO_RESIZE_HANDLES = [
|
|
2981
|
+
{ id: "sw", x: 0, y: 0 },
|
|
2982
|
+
{ id: "s", x: 0.5, y: 0 },
|
|
2983
|
+
{ id: "se", x: 1, y: 0 },
|
|
2984
|
+
{ id: "e", x: 1, y: 0.5 },
|
|
2985
|
+
{ id: "ne", x: 1, y: 1 },
|
|
2986
|
+
{ id: "n", x: 0.5, y: 1 },
|
|
2987
|
+
{ id: "nw", x: 0, y: 1 },
|
|
2988
|
+
{ id: "w", x: 0, y: 0.5 }
|
|
2989
|
+
];
|
|
2990
|
+
function visioResizeShape(page, id) {
|
|
2991
|
+
const shape = visioMovementShape(page, id);
|
|
2992
|
+
return shape && visioResizeFrame(shape, { width: shape.width, height: shape.height }, { x: 0, y: 0 }) ? shape : void 0;
|
|
2993
|
+
}
|
|
2994
|
+
function visioResizeFrame(shape, size, anchor) {
|
|
2995
|
+
if (!shape.rotation) return void 0;
|
|
2996
|
+
const geometry = visioAnchoredResizeGeometry(
|
|
2997
|
+
{ ...shape, pinX: shape.rotation.pinX, pinY: shape.rotation.pinY },
|
|
2998
|
+
size,
|
|
2999
|
+
anchor
|
|
3000
|
+
);
|
|
3001
|
+
return geometry ? {
|
|
3002
|
+
width: size.width,
|
|
3003
|
+
height: size.height,
|
|
3004
|
+
transform: geometry.transform,
|
|
3005
|
+
pinX: geometry.pinX,
|
|
3006
|
+
pinY: geometry.pinY
|
|
3007
|
+
} : void 0;
|
|
3008
|
+
}
|
|
3009
|
+
function visioResizeDrag(page, id, handle, start, end) {
|
|
3010
|
+
const shape = visioResizeShape(page, id), location = VISIO_RESIZE_HANDLES.find((item) => item.id === handle);
|
|
3011
|
+
if (!shape || !location) return void 0;
|
|
3012
|
+
const delta = visioPageDragDelta(start, end), [a, b, c, d] = shape.transform, determinant = a * d - b * c;
|
|
3013
|
+
const x = (d * delta.x - c * delta.y) / determinant, y = (-b * delta.x + a * delta.y) / determinant;
|
|
3014
|
+
const size = {
|
|
3015
|
+
width: location.x === 0.5 ? shape.width : Math.max(Math.min(1 / 16, shape.width), shape.width + (location.x === 1 ? x : -x)),
|
|
3016
|
+
height: location.y === 0.5 ? shape.height : Math.max(Math.min(1 / 16, shape.height), shape.height + (location.y === 1 ? y : -y))
|
|
3017
|
+
};
|
|
3018
|
+
const anchor = {
|
|
3019
|
+
x: 1 - location.x,
|
|
3020
|
+
y: 1 - location.y
|
|
3021
|
+
};
|
|
3022
|
+
const frame = visioResizeFrame(shape, size, anchor);
|
|
3023
|
+
if (!frame) return void 0;
|
|
3024
|
+
try {
|
|
3025
|
+
const command = visioPageEditToDrawing(page, {
|
|
3026
|
+
type: "resize-shape",
|
|
3027
|
+
pageId: page.id,
|
|
3028
|
+
shapeId: id,
|
|
3029
|
+
...size,
|
|
3030
|
+
anchor
|
|
3031
|
+
});
|
|
3032
|
+
return command.type === "resize-shape" && command.width <= 1e6 && command.height <= 1e6 ? { frame, command } : void 0;
|
|
3033
|
+
} catch {
|
|
3034
|
+
return void 0;
|
|
3035
|
+
}
|
|
3036
|
+
}
|
|
3037
|
+
|
|
3038
|
+
// visio/ui/draw-plan.ts
|
|
3039
|
+
var SNAP = 1 / 16;
|
|
3040
|
+
var boundedNumber = (value) => Number.isFinite(value) && Math.abs(value) <= 1e6;
|
|
3041
|
+
function visioDrawingPoint(page, point, options = {}) {
|
|
3042
|
+
if (![point.x, point.y, page.width, page.height].every(boundedNumber) || page.width <= 0 || page.height <= 0)
|
|
3043
|
+
return void 0;
|
|
3044
|
+
const coordinate = (value, maximum) => {
|
|
3045
|
+
const bounded2 = options.bounded === false ? value : Math.max(0, Math.min(maximum, value));
|
|
3046
|
+
return options.snap === false ? bounded2 : Math.round(bounded2 / SNAP) * SNAP;
|
|
3047
|
+
};
|
|
3048
|
+
return { x: coordinate(point.x, page.width), y: coordinate(point.y, page.height) };
|
|
3049
|
+
}
|
|
3050
|
+
function visioDrawBounds(start, end) {
|
|
3051
|
+
if (![start.x, start.y, end.x, end.y].every(boundedNumber))
|
|
3052
|
+
throw new Error("Invalid drawing bounds.");
|
|
3053
|
+
return {
|
|
3054
|
+
x: Math.min(start.x, end.x),
|
|
3055
|
+
y: Math.min(start.y, end.y),
|
|
3056
|
+
width: Math.abs(end.x - start.x),
|
|
3057
|
+
height: Math.abs(end.y - start.y),
|
|
3058
|
+
centerX: (start.x + end.x) / 2,
|
|
3059
|
+
centerY: (start.y + end.y) / 2,
|
|
3060
|
+
radiusX: Math.abs(end.x - start.x) / 2,
|
|
3061
|
+
radiusY: Math.abs(end.y - start.y) / 2
|
|
3062
|
+
};
|
|
3063
|
+
}
|
|
3064
|
+
function visioBoxCreationCommand(page, kind, centre, size, text) {
|
|
3065
|
+
if (!["rectangle", "ellipse", "text"].includes(kind) || ![centre.x, centre.y, size.width, size.height].every(boundedNumber) || size.width <= 0 || size.height <= 0)
|
|
3066
|
+
throw new Error("Invalid box creation geometry or tool.");
|
|
3067
|
+
const box2 = {
|
|
3068
|
+
pageId: page.id,
|
|
3069
|
+
shapeId: visioNextShapeId(page),
|
|
3070
|
+
x: centre.x,
|
|
3071
|
+
y: page.height - centre.y,
|
|
3072
|
+
width: size.width,
|
|
3073
|
+
height: size.height
|
|
3074
|
+
};
|
|
3075
|
+
const command = kind === "text" ? { ...box2, type: "create-text-box", text: text ?? "" } : {
|
|
3076
|
+
...box2,
|
|
3077
|
+
type: kind === "ellipse" ? "create-ellipse" : "create-rectangle",
|
|
3078
|
+
...text === void 0 ? {} : { text }
|
|
3079
|
+
};
|
|
3080
|
+
return drawingCommand(page, command);
|
|
3081
|
+
}
|
|
3082
|
+
function drawingCommand(page, command) {
|
|
3083
|
+
const result = visioPageEditToDrawing(page, command);
|
|
3084
|
+
if (Object.values(result).some((value) => typeof value === "number" && !boundedNumber(value)))
|
|
3085
|
+
throw new Error("Drawing coordinates exceed finite limits.");
|
|
3086
|
+
return result;
|
|
3087
|
+
}
|
|
3088
|
+
function visioLineCreationCommand(page, begin, end) {
|
|
3089
|
+
if (![begin.x, begin.y, end.x, end.y].every(boundedNumber))
|
|
3090
|
+
throw new Error("Invalid line creation geometry.");
|
|
3091
|
+
return drawingCommand(page, {
|
|
3092
|
+
type: "create-line",
|
|
3093
|
+
pageId: page.id,
|
|
3094
|
+
shapeId: visioNextShapeId(page),
|
|
3095
|
+
beginX: begin.x,
|
|
3096
|
+
beginY: page.height - begin.y,
|
|
3097
|
+
endX: end.x,
|
|
3098
|
+
endY: page.height - end.y
|
|
3099
|
+
});
|
|
3100
|
+
}
|
|
3101
|
+
function visioDrawIsLargeEnough(kind, start, end) {
|
|
3102
|
+
if (!["rectangle", "ellipse", "line", "text"].includes(kind) || ![start.x, start.y, end.x, end.y].every(boundedNumber))
|
|
3103
|
+
return false;
|
|
3104
|
+
const bounds = visioDrawBounds(start, end);
|
|
3105
|
+
return kind === "line" ? Math.hypot(bounds.width, bounds.height) >= SNAP : bounds.width >= SNAP && bounds.height >= SNAP;
|
|
3106
|
+
}
|
|
3107
|
+
function visioDrawPlan(page, kind, start, end, text) {
|
|
3108
|
+
if (!visioDrawIsLargeEnough(kind, start, end)) return void 0;
|
|
3109
|
+
const bounds = visioDrawBounds(start, end);
|
|
3110
|
+
return kind === "line" ? visioLineCreationCommand(page, start, end) : visioBoxCreationCommand(page, kind, { x: bounds.centerX, y: bounds.centerY }, bounds, text);
|
|
3111
|
+
}
|
|
3112
|
+
|
|
3113
|
+
// visio/ui/line-dash.ts
|
|
3114
|
+
function visioLineDashLengths(style) {
|
|
3115
|
+
return style.lineDash?.map(
|
|
3116
|
+
(length, index) => length === 0 && index % 2 === 0 ? style.lineDashDotLength ?? 0 : length * style.lineWidth
|
|
3117
|
+
);
|
|
3118
|
+
}
|
|
3119
|
+
|
|
3120
|
+
// visio/ui/shape-formatting.ts
|
|
3121
|
+
function visioShapeFormattingState(shapes) {
|
|
3122
|
+
const common = (values) => values.length && values.every((value) => value === values[0]) ? values[0] : void 0;
|
|
3123
|
+
const percent = (opacity) => opacity === void 0 || !Number.isFinite(opacity) || opacity < 0 || opacity > 1 ? void 0 : Math.round((1 - opacity) * 200) / 2;
|
|
3124
|
+
const foreground = shapes.map(
|
|
3125
|
+
(shape) => percent(
|
|
3126
|
+
shape.style.fillForegroundOpacity ?? (shape.style.fillGradient || shape.style.fillPattern ? void 0 : shape.style.fillOpacity)
|
|
3127
|
+
)
|
|
3128
|
+
);
|
|
3129
|
+
const background = shapes.map((shape) => percent(shape.style.fillBackgroundOpacity));
|
|
3130
|
+
return {
|
|
3131
|
+
linePattern: common(shapes.map((shape) => shape.style.linePattern)),
|
|
3132
|
+
fillPatternIndex: common(shapes.map((shape) => shape.style.fillPatternIndex)),
|
|
3133
|
+
fillBackgroundColor: common(shapes.map((shape) => shape.style.fillBackgroundColor)),
|
|
3134
|
+
fillForegroundTransparency: common(foreground),
|
|
3135
|
+
fillBackgroundTransparency: common(background),
|
|
3136
|
+
fillTransparency: common([...foreground, ...background]),
|
|
3137
|
+
lineTransparency: common(
|
|
3138
|
+
shapes.map(
|
|
3139
|
+
(shape) => percent(
|
|
3140
|
+
shape.style.lineColorOpacity ?? (shape.style.lineGradient ? void 0 : shape.style.lineOpacity)
|
|
3141
|
+
)
|
|
3142
|
+
)
|
|
3143
|
+
)
|
|
3144
|
+
};
|
|
3145
|
+
}
|
|
3146
|
+
|
|
3147
|
+
// visio/ui/text-replace-types.ts
|
|
3148
|
+
var VISIO_TEXT_REPLACE_LIMITS = Object.freeze({
|
|
3149
|
+
query: 256,
|
|
3150
|
+
replacement: 32768,
|
|
3151
|
+
text: 2e6,
|
|
3152
|
+
names: 1e6,
|
|
3153
|
+
output: 1e6,
|
|
3154
|
+
matches: 1e4,
|
|
3155
|
+
commands: 1e3,
|
|
3156
|
+
shapes: 25e3,
|
|
3157
|
+
pages: 256,
|
|
3158
|
+
depth: 64
|
|
3159
|
+
});
|
|
3160
|
+
var textReplaceError = (message) => {
|
|
3161
|
+
throw new Error(message);
|
|
3162
|
+
};
|
|
3163
|
+
function replaceString(value, maximum, label) {
|
|
3164
|
+
if (typeof value !== "string" || value.length > maximum)
|
|
3165
|
+
return textReplaceError(`Replace ${label} exceeds supported string limits.`);
|
|
3166
|
+
return value;
|
|
3167
|
+
}
|
|
3168
|
+
function replaceIdentity(value) {
|
|
3169
|
+
const id = replaceString(value, 256, "identity");
|
|
3170
|
+
if (!id) textReplaceError("Replace requires nonempty identities.");
|
|
3171
|
+
return id;
|
|
3172
|
+
}
|
|
3173
|
+
|
|
3174
|
+
// visio/ui/text-replace-snapshot.ts
|
|
3175
|
+
function snapshotReplaceScope(input) {
|
|
3176
|
+
const query = replaceString(input.query, VISIO_TEXT_REPLACE_LIMITS.query, "query");
|
|
3177
|
+
const scope = input.scope, pageId = replaceIdentity(input.pageId), matchCase = input.matchCase;
|
|
3178
|
+
if (!query || matchCase !== true || !["selection", "current-page", "all-pages"].includes(scope))
|
|
3179
|
+
textReplaceError(
|
|
3180
|
+
"Replace requires a nonempty literal query, Match case, and an explicit scope."
|
|
3181
|
+
);
|
|
3182
|
+
let selection;
|
|
3183
|
+
const original = input.selection;
|
|
3184
|
+
if (original !== void 0) {
|
|
3185
|
+
const length = original.length;
|
|
3186
|
+
if (!Array.isArray(original) || !Number.isSafeInteger(length) || length > VISIO_TEXT_REPLACE_LIMITS.shapes || length < 0)
|
|
3187
|
+
textReplaceError("Replace selection exceeds supported limits.");
|
|
3188
|
+
selection = [];
|
|
3189
|
+
for (let index = 0; index < length; index++) {
|
|
3190
|
+
const item = original[index], id = replaceIdentity(item.id), page = item.pageId;
|
|
3191
|
+
selection.push(
|
|
3192
|
+
Object.freeze({ id, ...page === void 0 ? {} : { pageId: replaceIdentity(page) } })
|
|
3193
|
+
);
|
|
3194
|
+
}
|
|
3195
|
+
Object.freeze(selection);
|
|
3196
|
+
}
|
|
3197
|
+
return Object.freeze({ query, scope, pageId, matchCase, ...selection ? { selection } : {} });
|
|
3198
|
+
}
|
|
3199
|
+
function replaceEntries(model, scope, requirePage = true) {
|
|
3200
|
+
const pages = model.pages;
|
|
3201
|
+
const count = pages.length;
|
|
3202
|
+
if (!Array.isArray(pages) || !Number.isSafeInteger(count) || count > VISIO_TEXT_REPLACE_LIMITS.pages || count < 0)
|
|
3203
|
+
textReplaceError("Replace page list exceeds supported limits.");
|
|
3204
|
+
const all = [], identities = /* @__PURE__ */ new Map(), pageIds = /* @__PURE__ */ new Set(), seen = /* @__PURE__ */ new Set();
|
|
3205
|
+
let characters = 0, names = 0;
|
|
3206
|
+
for (let pageIndex = 0; pageIndex < count; pageIndex++) {
|
|
3207
|
+
const page = pages[pageIndex], pageId = replaceIdentity(page.id), ids = /* @__PURE__ */ new Set();
|
|
3208
|
+
if (pageIds.has(pageId)) textReplaceError("Replace page identities are ambiguous.");
|
|
3209
|
+
pageIds.add(pageId);
|
|
3210
|
+
const walk = (source, depth) => {
|
|
3211
|
+
const length = source.length;
|
|
3212
|
+
if (!Array.isArray(source) || !Number.isSafeInteger(length) || length < 0 || length > 0 && depth > VISIO_TEXT_REPLACE_LIMITS.depth || length > VISIO_TEXT_REPLACE_LIMITS.shapes)
|
|
3213
|
+
textReplaceError("Replace shape list exceeds supported limits.");
|
|
3214
|
+
for (let index = 0; index < length; index++) {
|
|
3215
|
+
const shape = source[index], shapeId = replaceIdentity(shape.id);
|
|
3216
|
+
if (seen.has(shape) || ids.has(shapeId) || seen.size >= VISIO_TEXT_REPLACE_LIMITS.shapes)
|
|
3217
|
+
textReplaceError("Replace shape identities, depth or cycles are invalid.");
|
|
3218
|
+
seen.add(shape);
|
|
3219
|
+
ids.add(shapeId);
|
|
3220
|
+
const text = replaceString(shape.text.plainText, VISIO_TEXT_REPLACE_LIMITS.text, "source text");
|
|
3221
|
+
const name = replaceString(shape.name, 4096, "shape name");
|
|
3222
|
+
names += name.length;
|
|
3223
|
+
if (names > VISIO_TEXT_REPLACE_LIMITS.names) textReplaceError("Replace shape names exceed aggregate limits.");
|
|
3224
|
+
characters += text.length;
|
|
3225
|
+
if (characters > VISIO_TEXT_REPLACE_LIMITS.text) textReplaceError("Replace text exceeds aggregate limits.");
|
|
3226
|
+
const entry = { pageId, shapeId, name, pageIndex, text, end: 0 };
|
|
3227
|
+
identities.set(JSON.stringify([pageId, shapeId]), all.length);
|
|
3228
|
+
all.push(entry);
|
|
3229
|
+
walk(shape.children, depth + 1);
|
|
3230
|
+
entry.end = all.length;
|
|
3231
|
+
}
|
|
3232
|
+
};
|
|
3233
|
+
walk(page.shapes, 0);
|
|
3234
|
+
}
|
|
3235
|
+
if (requirePage && !pageIds.has(scope.pageId))
|
|
3236
|
+
textReplaceError("Replace current page does not exist.");
|
|
3237
|
+
if (scope.scope === "all-pages") return all;
|
|
3238
|
+
if (scope.scope === "current-page") return all.filter((entry) => entry.pageId === scope.pageId);
|
|
3239
|
+
const result = [], added = /* @__PURE__ */ new Set();
|
|
3240
|
+
for (const selected of scope.selection ?? []) {
|
|
3241
|
+
const pageId = selected.pageId ?? scope.pageId;
|
|
3242
|
+
const start = identities.get(JSON.stringify([pageId, selected.id]));
|
|
3243
|
+
if (start === void 0) return textReplaceError("Replace selected shape does not exist.");
|
|
3244
|
+
for (let index = start; index < all[start].end; index++) {
|
|
3245
|
+
const entry = all[index];
|
|
3246
|
+
if (added.has(entry)) {
|
|
3247
|
+
index = entry.end - 1;
|
|
3248
|
+
continue;
|
|
3249
|
+
}
|
|
3250
|
+
result.push(entry);
|
|
3251
|
+
added.add(entry);
|
|
3252
|
+
}
|
|
3253
|
+
}
|
|
3254
|
+
return result;
|
|
3255
|
+
}
|
|
3256
|
+
|
|
3257
|
+
// visio/ui/text-replace-selection.ts
|
|
3258
|
+
function visioTextOccurrenceSelection(model, occurrence) {
|
|
3259
|
+
const pageId = replaceIdentity(occurrence.pageId), shapeId = replaceIdentity(occurrence.shapeId), start = occurrence.start, end = occurrence.end;
|
|
3260
|
+
if (!Number.isSafeInteger(start) || !Number.isSafeInteger(end) || start < 0 || end <= start)
|
|
3261
|
+
return void 0;
|
|
3262
|
+
const entries = replaceEntries(
|
|
3263
|
+
model,
|
|
3264
|
+
{ pageId, scope: "all-pages"},
|
|
3265
|
+
false
|
|
3266
|
+
);
|
|
3267
|
+
const entry = entries.find((item) => item.pageId === pageId && item.shapeId === shapeId);
|
|
3268
|
+
if (!entry || end > entry.text.length) return void 0;
|
|
3269
|
+
return Object.freeze({
|
|
3270
|
+
pageIndex: entry.pageIndex,
|
|
3271
|
+
selection: Object.freeze({ id: shapeId, name: entry.name, pageId })
|
|
3272
|
+
});
|
|
3273
|
+
}
|
|
3274
|
+
|
|
3275
|
+
// visio/ui/text-replace.ts
|
|
3276
|
+
function occurrences(entries, query) {
|
|
3277
|
+
const result = [];
|
|
3278
|
+
for (const entry of entries) {
|
|
3279
|
+
let start = entry.text.indexOf(query);
|
|
3280
|
+
while (start >= 0) {
|
|
3281
|
+
if (result.length >= VISIO_TEXT_REPLACE_LIMITS.matches)
|
|
3282
|
+
textReplaceError("Replace occurrence count exceeds limits.");
|
|
3283
|
+
result.push(
|
|
3284
|
+
Object.freeze({
|
|
3285
|
+
pageId: entry.pageId,
|
|
3286
|
+
shapeId: entry.shapeId,
|
|
3287
|
+
start,
|
|
3288
|
+
end: start + query.length
|
|
3289
|
+
})
|
|
3290
|
+
);
|
|
3291
|
+
start = entry.text.indexOf(query, start + query.length);
|
|
3292
|
+
}
|
|
3293
|
+
}
|
|
3294
|
+
return Object.freeze(result);
|
|
3295
|
+
}
|
|
3296
|
+
function visioTextReplaceOccurrences(model, input) {
|
|
3297
|
+
const scope = snapshotReplaceScope(input);
|
|
3298
|
+
return occurrences(replaceEntries(model, scope), scope.query);
|
|
3299
|
+
}
|
|
3300
|
+
function visioTextReplaceFindNext(model, input, current) {
|
|
3301
|
+
const saved = snapshotOccurrence(current);
|
|
3302
|
+
const found = visioTextReplaceOccurrences(model, input);
|
|
3303
|
+
if (saved === void 0) return found[0];
|
|
3304
|
+
const index = found.findIndex((match) => sameOccurrence(match, saved));
|
|
3305
|
+
if (index < 0) return textReplaceError("Find occurrence is stale or outside the scope.");
|
|
3306
|
+
return found[(index + 1) % found.length];
|
|
3307
|
+
}
|
|
3308
|
+
var records = /* @__PURE__ */ new WeakMap();
|
|
3309
|
+
var sameOccurrence = (a, b) => a.pageId === b.pageId && a.shapeId === b.shapeId && a.start === b.start && a.end === b.end;
|
|
3310
|
+
var sameTarget = (entry, match) => entry.pageId === match.pageId && entry.shapeId === match.shapeId;
|
|
3311
|
+
function snapshotOccurrence(original) {
|
|
3312
|
+
if (original === void 0) return void 0;
|
|
3313
|
+
const current = {
|
|
3314
|
+
pageId: replaceIdentity(original.pageId),
|
|
3315
|
+
shapeId: replaceIdentity(original.shapeId),
|
|
3316
|
+
start: original.start,
|
|
3317
|
+
end: original.end
|
|
3318
|
+
};
|
|
3319
|
+
if (!Number.isSafeInteger(current.start) || !Number.isSafeInteger(current.end) || current.start < 0 || current.end <= current.start || current.end > VISIO_TEXT_REPLACE_LIMITS.text)
|
|
3320
|
+
textReplaceError("Invalid replacement occurrence range.");
|
|
3321
|
+
return current;
|
|
3322
|
+
}
|
|
3323
|
+
function visioTextReplacePlan(model, input) {
|
|
3324
|
+
const scope = snapshotReplaceScope(input), replacement = replaceString(input.replacement, VISIO_TEXT_REPLACE_LIMITS.replacement, "replacement"), mode = input.mode, current = snapshotOccurrence(input.current);
|
|
3325
|
+
if (mode !== "current" && mode !== "all") textReplaceError("Invalid replacement mode.");
|
|
3326
|
+
if (/[\u0000-\u0008\u000b\u000c\u000d\u000e-\u001f\ufffe\uffff]|[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/u.test(
|
|
3327
|
+
replacement
|
|
3328
|
+
))
|
|
3329
|
+
textReplaceError("Replacement contains invalid XML text characters.");
|
|
3330
|
+
const entries = replaceEntries(model, scope), found = occurrences(entries, scope.query);
|
|
3331
|
+
const active = current === void 0 ? found[0] : found.find((match) => sameOccurrence(match, current));
|
|
3332
|
+
if (current !== void 0 && !active)
|
|
3333
|
+
textReplaceError("Replace occurrence is stale or outside the scope.");
|
|
3334
|
+
const selected = mode === "all" ? found : active ? [active] : [];
|
|
3335
|
+
const targets = /* @__PURE__ */ new Map();
|
|
3336
|
+
for (const match of selected) {
|
|
3337
|
+
const key = JSON.stringify([match.pageId, match.shapeId]);
|
|
3338
|
+
const list = targets.get(key) ?? [];
|
|
3339
|
+
list.push(match);
|
|
3340
|
+
targets.set(key, list);
|
|
3341
|
+
}
|
|
3342
|
+
if (targets.size > VISIO_TEXT_REPLACE_LIMITS.commands) textReplaceError("Replace command count exceeds limits.");
|
|
3343
|
+
const edits = [], updated = [];
|
|
3344
|
+
let outputCharacters = 0;
|
|
3345
|
+
for (const entry of entries) {
|
|
3346
|
+
const matches = targets.get(JSON.stringify([entry.pageId, entry.shapeId]));
|
|
3347
|
+
let text = entry.text;
|
|
3348
|
+
if (matches) {
|
|
3349
|
+
const length = text.length + matches.length * (replacement.length - scope.query.length);
|
|
3350
|
+
outputCharacters += length;
|
|
3351
|
+
if (length > VISIO_TEXT_REPLACE_LIMITS.output || outputCharacters > VISIO_TEXT_REPLACE_LIMITS.output)
|
|
3352
|
+
textReplaceError("Replace output exceeds aggregate command text limits.");
|
|
3353
|
+
const parts = [];
|
|
3354
|
+
let from = 0;
|
|
3355
|
+
for (const match of matches) {
|
|
3356
|
+
parts.push(text.slice(from, match.start), replacement);
|
|
3357
|
+
from = match.end;
|
|
3358
|
+
}
|
|
3359
|
+
parts.push(text.slice(from));
|
|
3360
|
+
text = parts.join("");
|
|
3361
|
+
edits.push(
|
|
3362
|
+
Object.freeze({
|
|
3363
|
+
type: "replace-plain-text",
|
|
3364
|
+
pageId: entry.pageId,
|
|
3365
|
+
shapeId: entry.shapeId,
|
|
3366
|
+
text
|
|
3367
|
+
})
|
|
3368
|
+
);
|
|
3369
|
+
}
|
|
3370
|
+
updated.push({ ...entry, text });
|
|
3371
|
+
}
|
|
3372
|
+
const remaining = mode === "current" ? occurrences(updated, scope.query) : [];
|
|
3373
|
+
const activeEntry = active ? entries.findIndex((entry) => sameTarget(entry, active)) : -1;
|
|
3374
|
+
const entryIndices = new Map(
|
|
3375
|
+
entries.map((entry, index) => [JSON.stringify([entry.pageId, entry.shapeId]), index])
|
|
3376
|
+
);
|
|
3377
|
+
const nextOccurrence = active ? remaining.find((match) => {
|
|
3378
|
+
const index = entryIndices.get(JSON.stringify([match.pageId, match.shapeId]));
|
|
3379
|
+
return index > activeEntry || index === activeEntry && match.start >= active.start + replacement.length;
|
|
3380
|
+
}) ?? remaining[0] : remaining[0];
|
|
3381
|
+
const plan = Object.freeze({
|
|
3382
|
+
occurrences: found,
|
|
3383
|
+
replacementCount: selected.length,
|
|
3384
|
+
edits: Object.freeze(edits),
|
|
3385
|
+
nextOccurrence
|
|
3386
|
+
});
|
|
3387
|
+
records.set(plan, { scope, entries });
|
|
3388
|
+
return plan;
|
|
3389
|
+
}
|
|
3390
|
+
function visioTextReplaceCommands(model, plan) {
|
|
3391
|
+
const record2 = records.get(plan);
|
|
3392
|
+
if (!record2) return textReplaceError("Replace plan was not produced by this planner.");
|
|
3393
|
+
const current = replaceEntries(model, record2.scope);
|
|
3394
|
+
if (current.length !== record2.entries.length || current.some((entry, index) => {
|
|
3395
|
+
const saved = record2.entries[index];
|
|
3396
|
+
return entry.pageId !== saved.pageId || entry.shapeId !== saved.shapeId || entry.text !== saved.text;
|
|
3397
|
+
}))
|
|
3398
|
+
textReplaceError("Replace plan is stale. Search the current drawing again.");
|
|
3399
|
+
return plan.edits.map((edit) => ({ ...edit }));
|
|
3400
|
+
}
|
|
3401
|
+
|
|
3402
|
+
// visio/ui/svg-stroke.ts
|
|
3403
|
+
function visioSvgStrokeStyle(style) {
|
|
3404
|
+
return style.lineWidth === 0 ? { ...style, lineWidth: 0.75 / 72 } : style;
|
|
3405
|
+
}
|
|
3406
|
+
|
|
2162
3407
|
exports.DocumentHistory = DocumentHistory;
|
|
2163
3408
|
exports.EDIT_HISTORY_LIMITS = EDIT_HISTORY_LIMITS;
|
|
2164
3409
|
exports.EMPTY_EDIT_STATE = EMPTY_EDIT_STATE;
|
|
3410
|
+
exports.EMPTY_SELECTION = EMPTY_SELECTION;
|
|
2165
3411
|
exports.EMPTY_TEXT_SEARCH = EMPTY_TEXT_SEARCH;
|
|
2166
3412
|
exports.FOREIGN_VECTOR_SCENE_LIMITS = FOREIGN_VECTOR_SCENE_LIMITS;
|
|
2167
3413
|
exports.ForeignVectorBudget = ForeignVectorBudget;
|
|
2168
3414
|
exports.MAX_INPUT_BYTES = MAX_INPUT_BYTES;
|
|
2169
3415
|
exports.TEXT_SEARCH_LIMITS = TEXT_SEARCH_LIMITS;
|
|
2170
3416
|
exports.VISIO_IDENTITY_TRANSFORM = IDENTITY_AFFINE;
|
|
3417
|
+
exports.VISIO_RESIZE_HANDLES = VISIO_RESIZE_HANDLES;
|
|
3418
|
+
exports.VISIO_TEXT_REPLACE_LIMITS = VISIO_TEXT_REPLACE_LIMITS;
|
|
2171
3419
|
exports.assertShapeDetails = assertShapeDetails;
|
|
2172
3420
|
exports.assertViewableDocument = assertViewableDocument;
|
|
2173
3421
|
exports.compatibilityNotes = compatibilityNotes;
|
|
@@ -2177,23 +3425,65 @@ exports.copySnapshotScene = copySnapshotScene;
|
|
|
2177
3425
|
exports.demoDocument = demoDocument;
|
|
2178
3426
|
exports.editErrorMessage = editErrorMessage;
|
|
2179
3427
|
exports.eventKeys = eventKeys;
|
|
3428
|
+
exports.hasVisibleShapeContent = hasVisibleShapeContent;
|
|
2180
3429
|
exports.indexDocumentText = indexDocumentText;
|
|
2181
3430
|
exports.inspectForeignVectorResource = inspectForeignVectorResource;
|
|
2182
3431
|
exports.isEditCancellation = isEditCancellation;
|
|
2183
3432
|
exports.propertyKeys = propertyKeys;
|
|
3433
|
+
exports.sameSelection = sameSelection;
|
|
2184
3434
|
exports.searchDocumentText = searchDocumentText;
|
|
3435
|
+
exports.selectionKey = selectionKey;
|
|
2185
3436
|
exports.snapshotEdits = snapshotEdits;
|
|
3437
|
+
exports.snapshotSelection = snapshotSelection;
|
|
2186
3438
|
exports.textSearchStatus = textSearchStatus;
|
|
2187
3439
|
exports.validateSearchQuery = validateSearchQuery;
|
|
3440
|
+
exports.visioArrangeCommands = visioArrangeCommands;
|
|
3441
|
+
exports.visioBoxCreationCommand = visioBoxCreationCommand;
|
|
3442
|
+
exports.visioClipboardShape = visioClipboardShape;
|
|
3443
|
+
exports.visioDrawBounds = visioDrawBounds;
|
|
3444
|
+
exports.visioDrawIsLargeEnough = visioDrawIsLargeEnough;
|
|
3445
|
+
exports.visioDrawPlan = visioDrawPlan;
|
|
3446
|
+
exports.visioDrawingPoint = visioDrawingPoint;
|
|
3447
|
+
exports.visioDuplicateCommand = visioDuplicateCommand;
|
|
2188
3448
|
exports.visioFillPatternTransform = visioFillPatternTransform;
|
|
3449
|
+
exports.visioFontFamilies = visioFontFamilies;
|
|
3450
|
+
exports.visioFormattingShape = visioFormattingShape;
|
|
2189
3451
|
exports.visioGradientInstances = visioGradientInstances;
|
|
3452
|
+
exports.visioLineCreationCommand = visioLineCreationCommand;
|
|
3453
|
+
exports.visioLineDashLengths = visioLineDashLengths;
|
|
2190
3454
|
exports.visioLocalRotationShape = visioLocalRotationShape;
|
|
3455
|
+
exports.visioMarqueeBox = visioMarqueeBox;
|
|
3456
|
+
exports.visioMarqueeSelection = visioMarqueeSelection;
|
|
3457
|
+
exports.visioMoveCommands = visioMoveCommands;
|
|
3458
|
+
exports.visioMovePreviewTransform = visioMovePreviewTransform;
|
|
3459
|
+
exports.visioMovementShape = visioMovementShape;
|
|
2191
3460
|
exports.visioNextShapeId = visioNextShapeId;
|
|
3461
|
+
exports.visioOrderingShape = visioOrderingShape;
|
|
3462
|
+
exports.visioPageDragDelta = visioPageDragDelta;
|
|
2192
3463
|
exports.visioPageEditToDrawing = visioPageEditToDrawing;
|
|
2193
3464
|
exports.visioPageInsertCommand = visioPageInsertCommand;
|
|
3465
|
+
exports.visioPasteCommand = visioPasteCommand;
|
|
2194
3466
|
exports.visioQuarterTurnCommand = visioQuarterTurnCommand;
|
|
2195
3467
|
exports.visioRenderedGradientStopCount = visioRenderedGradientStopCount;
|
|
2196
3468
|
exports.visioRenderedGradientStops = visioRenderedGradientStops;
|
|
3469
|
+
exports.visioResizeDrag = visioResizeDrag;
|
|
3470
|
+
exports.visioResizeFrame = visioResizeFrame;
|
|
3471
|
+
exports.visioResizeShape = visioResizeShape;
|
|
2197
3472
|
exports.visioRotationPreviewTransform = visioRotationPreviewTransform;
|
|
3473
|
+
exports.visioSelectionIsOnPage = visioSelectionIsOnPage;
|
|
3474
|
+
exports.visioShapeFormattingState = visioShapeFormattingState;
|
|
3475
|
+
exports.visioShapePageBox = visioShapePageBox;
|
|
3476
|
+
exports.visioSizePositionCommand = visioSizePositionCommand;
|
|
3477
|
+
exports.visioSizePositionState = visioSizePositionState;
|
|
2198
3478
|
exports.visioStraightLineHandles = visioStraightLineHandles;
|
|
2199
3479
|
exports.visioStrokeGradient = visioStrokeGradient;
|
|
3480
|
+
exports.visioStyleFormattingShape = visioStyleFormattingShape;
|
|
3481
|
+
exports.visioSvgStrokeStyle = visioSvgStrokeStyle;
|
|
3482
|
+
exports.visioTextFontStepCommand = visioTextFontStepCommand;
|
|
3483
|
+
exports.visioTextFormattingState = visioTextFormattingState;
|
|
3484
|
+
exports.visioTextIndentCommand = visioTextIndentCommand;
|
|
3485
|
+
exports.visioTextOccurrenceSelection = visioTextOccurrenceSelection;
|
|
3486
|
+
exports.visioTextReplaceCommands = visioTextReplaceCommands;
|
|
3487
|
+
exports.visioTextReplaceFindNext = visioTextReplaceFindNext;
|
|
3488
|
+
exports.visioTextReplaceOccurrences = visioTextReplaceOccurrences;
|
|
3489
|
+
exports.visioTextReplacePlan = visioTextReplacePlan;
|