@elixpo/lixsketch 5.4.7 → 5.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/react/AIRenderer-M4LMJ66J.js +1105 -0
- package/dist/react/AIRenderer-M4LMJ66J.js.map +7 -0
- package/dist/react/Arrow-BJDAXPMH.js +8 -0
- package/dist/react/Arrow-BJDAXPMH.js.map +7 -0
- package/dist/react/Circle-KPG7TKIX.js +8 -0
- package/dist/react/Circle-KPG7TKIX.js.map +7 -0
- package/dist/react/CodeShape-K4DIZAIV.js +8 -0
- package/dist/react/CodeShape-K4DIZAIV.js.map +7 -0
- package/dist/react/CopyPaste-4CKJRHJ3.js +569 -0
- package/dist/react/CopyPaste-4CKJRHJ3.js.map +7 -0
- package/dist/react/EraserTrail-PA6IQLQN.js +20 -0
- package/dist/react/EraserTrail-PA6IQLQN.js.map +7 -0
- package/dist/react/EventDispatcher-SRFH6LQZ.js +463 -0
- package/dist/react/EventDispatcher-SRFH6LQZ.js.map +7 -0
- package/dist/react/Frame-6UR5XPAX.js +10 -0
- package/dist/react/Frame-6UR5XPAX.js.map +7 -0
- package/dist/react/FreehandStroke-CK24NUT3.js +8 -0
- package/dist/react/FreehandStroke-CK24NUT3.js.map +7 -0
- package/dist/react/GraphEngine-QE5B2PMR.js +340 -0
- package/dist/react/GraphEngine-QE5B2PMR.js.map +7 -0
- package/dist/react/GraphMathParser-2WMTY4IE.js +10 -0
- package/dist/react/GraphMathParser-2WMTY4IE.js.map +7 -0
- package/dist/react/IconShape-KMIA6T2H.js +10 -0
- package/dist/react/IconShape-KMIA6T2H.js.map +7 -0
- package/dist/react/ImageShape-CHHGBXUQ.js +10 -0
- package/dist/react/ImageShape-CHHGBXUQ.js.map +7 -0
- package/dist/react/LayerOrder-XCHF4MSS.js +66 -0
- package/dist/react/LayerOrder-XCHF4MSS.js.map +7 -0
- package/dist/react/Line-2KOQEEGA.js +10 -0
- package/dist/react/Line-2KOQEEGA.js.map +7 -0
- package/dist/react/LixScriptParser-JYWJX375.js +1033 -0
- package/dist/react/LixScriptParser-JYWJX375.js.map +7 -0
- package/dist/react/MermaidFlowchartRenderer-4QBAZ5MB.js +412 -0
- package/dist/react/MermaidFlowchartRenderer-4QBAZ5MB.js.map +7 -0
- package/dist/react/MermaidSequenceParser-UKG2NSZY.js +8 -0
- package/dist/react/MermaidSequenceParser-UKG2NSZY.js.map +7 -0
- package/dist/react/MermaidSequenceRenderer-HPLHY5II.js +387 -0
- package/dist/react/MermaidSequenceRenderer-HPLHY5II.js.map +7 -0
- package/dist/react/Rectangle-6FE7RN6W.js +8 -0
- package/dist/react/Rectangle-6FE7RN6W.js.map +7 -0
- package/dist/react/ResizeCode-WAMDTKSW.js +2 -0
- package/dist/react/ResizeCode-WAMDTKSW.js.map +7 -0
- package/dist/react/ResizeShapes-LKEQTITP.js +250 -0
- package/dist/react/ResizeShapes-LKEQTITP.js.map +7 -0
- package/dist/react/SceneSerializer-4U4B24JM.js +739 -0
- package/dist/react/SceneSerializer-4U4B24JM.js.map +7 -0
- package/dist/react/Selection-VVUHY5YJ.js +34 -0
- package/dist/react/Selection-VVUHY5YJ.js.map +7 -0
- package/dist/react/SketchEngine-YA4RG3KX.js +413 -0
- package/dist/react/SketchEngine-YA4RG3KX.js.map +7 -0
- package/dist/react/TextShape-54ZJ66E3.js +8 -0
- package/dist/react/TextShape-54ZJ66E3.js.map +7 -0
- package/dist/react/UndoRedo-M2JZUBKN.js +30 -0
- package/dist/react/UndoRedo-M2JZUBKN.js.map +7 -0
- package/dist/react/ZoomPan-U3TXC5AJ.js +186 -0
- package/dist/react/ZoomPan-U3TXC5AJ.js.map +7 -0
- package/dist/react/arrowTool-CWEMIRXK.js +17 -0
- package/dist/react/arrowTool-CWEMIRXK.js.map +7 -0
- package/dist/react/boxicons-5JNJQPUP.woff +0 -0
- package/dist/react/boxicons-6NVWQSCQ.eot +0 -0
- package/dist/react/boxicons-AQ5N6WP7.woff2 +0 -0
- package/dist/react/boxicons-GDR4JU3X.ttf +0 -0
- package/dist/react/boxicons-NNFHLMOR.svg +1660 -0
- package/dist/react/chunk-2OQXI7QB.js +564 -0
- package/dist/react/chunk-2OQXI7QB.js.map +7 -0
- package/dist/react/chunk-5OUBTHHO.js +187 -0
- package/dist/react/chunk-5OUBTHHO.js.map +7 -0
- package/dist/react/chunk-6PFXZKL2.js +628 -0
- package/dist/react/chunk-6PFXZKL2.js.map +7 -0
- package/dist/react/chunk-6SFNWGGZ.js +453 -0
- package/dist/react/chunk-6SFNWGGZ.js.map +7 -0
- package/dist/react/chunk-7TZSIR6V.js +210 -0
- package/dist/react/chunk-7TZSIR6V.js.map +7 -0
- package/dist/react/chunk-AJAZC37E.js +662 -0
- package/dist/react/chunk-AJAZC37E.js.map +7 -0
- package/dist/react/chunk-BU4D2WYQ.js +1213 -0
- package/dist/react/chunk-BU4D2WYQ.js.map +7 -0
- package/dist/react/chunk-BZE4CEBG.js +747 -0
- package/dist/react/chunk-BZE4CEBG.js.map +7 -0
- package/dist/react/chunk-CB2RANCB.js +212 -0
- package/dist/react/chunk-CB2RANCB.js.map +7 -0
- package/dist/react/chunk-DNAG7ML6.js +128 -0
- package/dist/react/chunk-DNAG7ML6.js.map +7 -0
- package/dist/react/chunk-HZWLPXFN.js +198 -0
- package/dist/react/chunk-HZWLPXFN.js.map +7 -0
- package/dist/react/chunk-I6HCCIXB.js +572 -0
- package/dist/react/chunk-I6HCCIXB.js.map +7 -0
- package/dist/react/chunk-IZ5OGWGW.js +235 -0
- package/dist/react/chunk-IZ5OGWGW.js.map +7 -0
- package/dist/react/chunk-JJCJNLNN.js +1490 -0
- package/dist/react/chunk-JJCJNLNN.js.map +7 -0
- package/dist/react/chunk-JQ3IRFDP.js +222 -0
- package/dist/react/chunk-JQ3IRFDP.js.map +7 -0
- package/dist/react/chunk-L5OARZJ7.js +1134 -0
- package/dist/react/chunk-L5OARZJ7.js.map +7 -0
- package/dist/react/chunk-LHRTXNVE.js +1600 -0
- package/dist/react/chunk-LHRTXNVE.js.map +7 -0
- package/dist/react/chunk-Q2GA4MBZ.js +1653 -0
- package/dist/react/chunk-Q2GA4MBZ.js.map +7 -0
- package/dist/react/chunk-QNSE5BAY.js +519 -0
- package/dist/react/chunk-QNSE5BAY.js.map +7 -0
- package/dist/react/chunk-QXFBG7OM.js +191 -0
- package/dist/react/chunk-QXFBG7OM.js.map +7 -0
- package/dist/react/chunk-T6ZVV5ZO.js +714 -0
- package/dist/react/chunk-T6ZVV5ZO.js.map +7 -0
- package/dist/react/chunk-URB6MY46.js +974 -0
- package/dist/react/chunk-URB6MY46.js.map +7 -0
- package/dist/react/chunk-VN62KLOC.js +931 -0
- package/dist/react/chunk-VN62KLOC.js.map +7 -0
- package/dist/react/chunk-VQVEPJSA.js +158 -0
- package/dist/react/chunk-VQVEPJSA.js.map +7 -0
- package/dist/react/chunk-XISEAGBV.js +1632 -0
- package/dist/react/chunk-XISEAGBV.js.map +7 -0
- package/dist/react/chunk-YKJUBFHE.js +575 -0
- package/dist/react/chunk-YKJUBFHE.js.map +7 -0
- package/dist/react/circleTool-NUATSEI2.js +14 -0
- package/dist/react/circleTool-NUATSEI2.js.map +7 -0
- package/dist/react/codeTool-MHCB2FNB.js +38 -0
- package/dist/react/codeTool-MHCB2FNB.js.map +7 -0
- package/dist/react/eraserTool-2GS2LQCS.js +103 -0
- package/dist/react/eraserTool-2GS2LQCS.js.map +7 -0
- package/dist/react/frameTool-PWVKKXSP.js +14 -0
- package/dist/react/frameTool-PWVKKXSP.js.map +7 -0
- package/dist/react/freehandTool-SLYGASVP.js +14 -0
- package/dist/react/freehandTool-SLYGASVP.js.map +7 -0
- package/dist/react/iconTool-GPZ7O7NH.js +18 -0
- package/dist/react/iconTool-GPZ7O7NH.js.map +7 -0
- package/dist/react/imageTool-D5R4XGEU.js +15 -0
- package/dist/react/imageTool-D5R4XGEU.js.map +7 -0
- package/dist/react/index.js +5349 -0
- package/dist/react/index.js.map +7 -0
- package/dist/react/laserTool-XVMV63AV.js +239 -0
- package/dist/react/laserTool-XVMV63AV.js.map +7 -0
- package/dist/react/lineTool-WNI5EMZ5.js +14 -0
- package/dist/react/lineTool-WNI5EMZ5.js.map +7 -0
- package/dist/react/lixCode-OJMVUXXI.ttf +0 -0
- package/dist/react/lixDefault-JEAPAUJL.ttf +0 -0
- package/dist/react/lixFancy-BPXYM5CQ.ttf +0 -0
- package/dist/react/lixFont-CPKEUDVM.woff2 +0 -0
- package/dist/react/rectangleTool-U7DZ6ZTA.js +14 -0
- package/dist/react/rectangleTool-U7DZ6ZTA.js.map +7 -0
- package/dist/react/styles.css +6627 -0
- package/dist/react/textTool-M7S6F3VC.js +21 -0
- package/dist/react/textTool-M7S6F3VC.js.map +7 -0
- package/package.json +39 -5
- package/src/EngineShortcuts.js +83 -27
- package/src/core/AIRenderer.js +30 -18
- package/src/core/GraphEngine.js +64 -41
- package/src/core/MermaidFlowchartRenderer.js +153 -88
- package/src/core/MermaidSequenceRenderer.js +168 -93
- package/src/core/SceneSerializer.js +86 -2
- package/src/core/Selection.js +119 -19
- package/src/core/UndoRedo.js +82 -15
- package/src/core/ZoomPan.js +15 -5
- package/src/index.js +14 -1
- package/src/react/LixSketchCanvas.jsx +347 -0
- package/src/react/components/AppMenu.jsx +482 -0
- package/src/react/components/Footer.jsx +85 -0
- package/src/react/components/Toolbar.jsx +140 -0
- package/src/react/components/canvas/CanvasLoadingOverlay.jsx +76 -0
- package/src/react/components/canvas/ContextMenu.jsx +466 -0
- package/src/react/components/canvas/FindBar.jsx +177 -0
- package/src/react/components/canvas/ImageSourcePicker.jsx +133 -0
- package/src/react/components/canvas/MultiSelectActions.jsx +120 -0
- package/src/react/components/canvas/SVGCanvas.jsx +145 -0
- package/src/react/components/canvas/SaveStatusIndicator.jsx +29 -0
- package/src/react/components/modals/CanvasPropertiesModal.jsx +358 -0
- package/src/react/components/modals/CommandPalette.jsx +307 -0
- package/src/react/components/modals/ExportImageModal.jsx +287 -0
- package/src/react/components/modals/GraphModal.jsx +174 -0
- package/src/react/components/modals/HelpModal.jsx +208 -0
- package/src/react/components/modals/LixScriptModal.jsx +130 -0
- package/src/react/components/modals/ShortcutsModal.jsx +125 -0
- package/src/react/components/sidebars/ArrowSidebar.jsx +173 -0
- package/src/react/components/sidebars/CircleSidebar.jsx +134 -0
- package/src/react/components/sidebars/FrameSidebar.jsx +263 -0
- package/src/react/components/sidebars/IconSidebar.jsx +279 -0
- package/src/react/components/sidebars/ImageSidebar.jsx +69 -0
- package/src/react/components/sidebars/LineSidebar.jsx +109 -0
- package/src/react/components/sidebars/PaintbrushSidebar.jsx +119 -0
- package/src/react/components/sidebars/RectangleSidebar.jsx +165 -0
- package/src/react/components/sidebars/ShapeSidebar.jsx +130 -0
- package/src/react/components/sidebars/TextSidebar.jsx +174 -0
- package/src/react/hooks/inertStores.js +58 -0
- package/src/react/hooks/useSketchEngine.js +76 -0
- package/src/react/hooks/useTranslation.js +92 -0
- package/src/react/index.js +41 -0
- package/src/react/store/useSketchStore.js +234 -0
- package/src/react/store/useUIStore.js +196 -0
- package/src/react/styles/arrowSidebar.css +263 -0
- package/src/react/styles/canvasStroke.css +47 -0
- package/src/react/styles/canvasTools.css +769 -0
- package/src/react/styles/circleSidebar.css +206 -0
- package/src/react/styles/fonts/fonts.css +29 -0
- package/src/react/styles/fonts/lixCode.ttf +0 -0
- package/src/react/styles/fonts/lixDefault.ttf +0 -0
- package/src/react/styles/fonts/lixDocs.ttf +0 -0
- package/src/react/styles/fonts/lixFancy.ttf +0 -0
- package/src/react/styles/fonts/lixFont.woff2 +0 -0
- package/src/react/styles/lineSidebar.css +207 -0
- package/src/react/styles/paintbrushSidebar.css +247 -0
- package/src/react/styles/squareSidebar.css +206 -0
- package/src/react/styles/writeText.css +149 -0
- package/src/react/styles.css +175 -0
- package/src/react/toolsEnum.js +20 -0
- package/src/react/utils/toast.js +18 -0
- package/src/shapes/Frame.js +7 -1
- package/src/shapes/Line.js +11 -5
- package/src/tools/arrowTool.js +30 -4
- package/src/tools/circleTool.js +33 -9
- package/src/tools/codeTool.js +5 -3
- package/src/tools/frameTool.js +47 -7
- package/src/tools/freehandTool.js +12 -4
- package/src/tools/iconTool.js +7 -1
- package/src/tools/imageTool.js +7 -1
- package/src/tools/lineTool.js +27 -3
- package/src/tools/rectangleTool.js +45 -8
- package/src/tools/textTool.js +23 -6
|
@@ -0,0 +1,1033 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/core/LixScriptParser.js
|
|
4
|
+
var NS = "http://www.w3.org/2000/svg";
|
|
5
|
+
function tokenize(source) {
|
|
6
|
+
const tokens = [];
|
|
7
|
+
const lines = source.split("\n");
|
|
8
|
+
for (let i = 0; i < lines.length; i++) {
|
|
9
|
+
const raw = lines[i];
|
|
10
|
+
const lineNum = i + 1;
|
|
11
|
+
const commentIdx = raw.indexOf("//");
|
|
12
|
+
const line = commentIdx !== -1 ? raw.slice(0, commentIdx) : raw;
|
|
13
|
+
const trimmed = line.trim();
|
|
14
|
+
if (!trimmed) continue;
|
|
15
|
+
tokens.push({ type: "LINE", value: trimmed, line: lineNum });
|
|
16
|
+
}
|
|
17
|
+
return tokens;
|
|
18
|
+
}
|
|
19
|
+
function parseLixScript(source) {
|
|
20
|
+
const tokens = tokenize(source);
|
|
21
|
+
const variables = {};
|
|
22
|
+
const shapes = [];
|
|
23
|
+
const errors = [];
|
|
24
|
+
let i = 0;
|
|
25
|
+
while (i < tokens.length) {
|
|
26
|
+
const token = tokens[i];
|
|
27
|
+
const line = token.value;
|
|
28
|
+
const lineNum = token.line;
|
|
29
|
+
try {
|
|
30
|
+
if (line.startsWith("$")) {
|
|
31
|
+
const match = line.match(/^\$(\w+)\s*=\s*(.+)$/);
|
|
32
|
+
if (match) {
|
|
33
|
+
variables[match[1]] = match[2].trim();
|
|
34
|
+
} else {
|
|
35
|
+
errors.push({ line: lineNum, message: `Invalid variable syntax: ${line}` });
|
|
36
|
+
}
|
|
37
|
+
i++;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const shapeMatch = line.match(/^(rect|circle|ellipse|arrow|line|text|frame|freehand|image|icon)\s+(\w+)\s+(.+)$/);
|
|
41
|
+
if (shapeMatch) {
|
|
42
|
+
const [, type, id, rest] = shapeMatch;
|
|
43
|
+
const shape = parseShapeDeclaration(type, id, rest, lineNum, errors, variables);
|
|
44
|
+
if (rest.includes("{") && !rest.includes("}")) {
|
|
45
|
+
i++;
|
|
46
|
+
const props = [];
|
|
47
|
+
while (i < tokens.length && !tokens[i].value.startsWith("}")) {
|
|
48
|
+
props.push(tokens[i].value);
|
|
49
|
+
i++;
|
|
50
|
+
}
|
|
51
|
+
if (i < tokens.length) i++;
|
|
52
|
+
parseProperties(shape, props, variables, errors);
|
|
53
|
+
} else if (rest.includes("{") && rest.includes("}")) {
|
|
54
|
+
const blockMatch = rest.match(/\{([^}]*)\}/);
|
|
55
|
+
if (blockMatch) {
|
|
56
|
+
const props = blockMatch[1].split(/[,;]/).map((s) => s.trim()).filter(Boolean);
|
|
57
|
+
parseProperties(shape, props, variables, errors);
|
|
58
|
+
}
|
|
59
|
+
i++;
|
|
60
|
+
} else {
|
|
61
|
+
i++;
|
|
62
|
+
}
|
|
63
|
+
shapes.push(shape);
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
errors.push({ line: lineNum, message: `Unrecognized syntax: ${line}` });
|
|
67
|
+
i++;
|
|
68
|
+
} catch (err) {
|
|
69
|
+
errors.push({ line: lineNum, message: err.message });
|
|
70
|
+
i++;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return { variables, shapes, errors };
|
|
74
|
+
}
|
|
75
|
+
function parseShapeDeclaration(type, id, rest, lineNum, errors, variables) {
|
|
76
|
+
const shape = { type, id, line: lineNum, props: {} };
|
|
77
|
+
if (type === "arrow" || type === "line") {
|
|
78
|
+
const connMatch = rest.match(/from\s+(.+?)\s+to\s+(.+?)(?:\s*\{|$)/);
|
|
79
|
+
if (connMatch) {
|
|
80
|
+
shape.from = parsePointOrRef(connMatch[1].trim(), variables);
|
|
81
|
+
shape.to = parsePointOrRef(connMatch[2].trim(), variables);
|
|
82
|
+
} else {
|
|
83
|
+
errors.push({ line: lineNum, message: `${type} requires 'from ... to ...' syntax` });
|
|
84
|
+
}
|
|
85
|
+
} else {
|
|
86
|
+
const atMatch = rest.match(/at\s+([\w$.+\-*\s]+?),\s*([\w$.+\-*\s]+?)(?:\s+size|\s*\{|$)/);
|
|
87
|
+
if (atMatch) {
|
|
88
|
+
shape.x = parseExpr(atMatch[1].trim(), variables);
|
|
89
|
+
shape.y = parseExpr(atMatch[2].trim(), variables);
|
|
90
|
+
} else if (type !== "frame") {
|
|
91
|
+
errors.push({ line: lineNum, message: `${type} requires 'at X, Y' syntax` });
|
|
92
|
+
}
|
|
93
|
+
const sizeMatch = rest.match(/size\s+([\w$.+\-*]+)\s*x\s*([\w$.+\-*]+)/);
|
|
94
|
+
if (sizeMatch) {
|
|
95
|
+
shape.width = parseExpr(sizeMatch[1].trim(), variables);
|
|
96
|
+
shape.height = parseExpr(sizeMatch[2].trim(), variables);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return shape;
|
|
100
|
+
}
|
|
101
|
+
function parsePointOrRef(str, variables) {
|
|
102
|
+
const refMatch = str.match(/^(\w+)\.(\w+)(?:\s*([+-])\s*([\d.]+))?$/);
|
|
103
|
+
if (refMatch) {
|
|
104
|
+
return {
|
|
105
|
+
ref: refMatch[1],
|
|
106
|
+
side: refMatch[2],
|
|
107
|
+
offset: refMatch[3] ? parseFloat((refMatch[3] === "-" ? "-" : "") + refMatch[4]) : 0
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
const coordMatch = str.match(/^([\d.]+)\s*,?\s*([\d.]+)$/);
|
|
111
|
+
if (coordMatch) {
|
|
112
|
+
return { x: parseFloat(coordMatch[1]), y: parseFloat(coordMatch[2]) };
|
|
113
|
+
}
|
|
114
|
+
if (/^\w+$/.test(str)) {
|
|
115
|
+
return { ref: str, side: "center", offset: 0 };
|
|
116
|
+
}
|
|
117
|
+
return { x: 0, y: 0 };
|
|
118
|
+
}
|
|
119
|
+
function parseExpr(str, variables) {
|
|
120
|
+
let resolved = str.replace(/\$(\w+)/g, (_, name) => {
|
|
121
|
+
return variables[name] !== void 0 ? variables[name] : "0";
|
|
122
|
+
});
|
|
123
|
+
const num = parseFloat(resolved);
|
|
124
|
+
if (!isNaN(num) && String(num) === resolved.trim()) {
|
|
125
|
+
return num;
|
|
126
|
+
}
|
|
127
|
+
if (/\w+\.\w+/.test(resolved)) {
|
|
128
|
+
return { expr: resolved };
|
|
129
|
+
}
|
|
130
|
+
const arithMatch = resolved.match(/^([\d.]+)\s*([+-])\s*([\d.]+)$/);
|
|
131
|
+
if (arithMatch) {
|
|
132
|
+
const a = parseFloat(arithMatch[1]);
|
|
133
|
+
const b = parseFloat(arithMatch[3]);
|
|
134
|
+
return arithMatch[2] === "+" ? a + b : a - b;
|
|
135
|
+
}
|
|
136
|
+
return isNaN(num) ? 0 : num;
|
|
137
|
+
}
|
|
138
|
+
function parseProperties(shape, lines, variables, errors) {
|
|
139
|
+
for (const line of lines) {
|
|
140
|
+
const propMatch = line.match(/^(\w+)\s*:\s*(.+)$/);
|
|
141
|
+
if (!propMatch) continue;
|
|
142
|
+
let [, key, value] = propMatch;
|
|
143
|
+
value = value.trim();
|
|
144
|
+
if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
|
|
145
|
+
value = value.slice(1, -1);
|
|
146
|
+
}
|
|
147
|
+
value = value.replace(/\$(\w+)/g, (_, name) => {
|
|
148
|
+
return variables[name] !== void 0 ? variables[name] : value;
|
|
149
|
+
});
|
|
150
|
+
const num = parseFloat(value);
|
|
151
|
+
if (!isNaN(num) && String(num) === value) {
|
|
152
|
+
shape.props[key] = num;
|
|
153
|
+
} else if (value === "true") {
|
|
154
|
+
shape.props[key] = true;
|
|
155
|
+
} else if (value === "false") {
|
|
156
|
+
shape.props[key] = false;
|
|
157
|
+
} else {
|
|
158
|
+
shape.props[key] = value;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function resolveShapeRefs(shapes) {
|
|
163
|
+
const shapeMap = /* @__PURE__ */ new Map();
|
|
164
|
+
const MAX_PASSES = 10;
|
|
165
|
+
for (let pass = 0; pass < MAX_PASSES; pass++) {
|
|
166
|
+
let progress = false;
|
|
167
|
+
for (const s of shapes) {
|
|
168
|
+
if (typeof s.x === "number" && typeof s.y === "number" && !shapeMap.has(s.id)) {
|
|
169
|
+
shapeMap.set(s.id, s);
|
|
170
|
+
progress = true;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
let anyUnresolved = false;
|
|
174
|
+
for (const s of shapes) {
|
|
175
|
+
if (s.x && typeof s.x === "object" && s.x.expr) {
|
|
176
|
+
const resolved = resolveExpr(s.x.expr, shapeMap);
|
|
177
|
+
if (typeof resolved === "number" && !isNaN(resolved)) {
|
|
178
|
+
s.x = resolved;
|
|
179
|
+
progress = true;
|
|
180
|
+
} else {
|
|
181
|
+
anyUnresolved = true;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (s.y && typeof s.y === "object" && s.y.expr) {
|
|
185
|
+
const resolved = resolveExpr(s.y.expr, shapeMap);
|
|
186
|
+
if (typeof resolved === "number" && !isNaN(resolved)) {
|
|
187
|
+
s.y = resolved;
|
|
188
|
+
progress = true;
|
|
189
|
+
} else {
|
|
190
|
+
anyUnresolved = true;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (!anyUnresolved || !progress) break;
|
|
195
|
+
}
|
|
196
|
+
for (const s of shapes) {
|
|
197
|
+
if (s.x && typeof s.x === "object" && s.x.expr) s.x = 0;
|
|
198
|
+
if (s.y && typeof s.y === "object" && s.y.expr) s.y = 0;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
function resolveExpr(expr, shapeMap) {
|
|
202
|
+
const m = expr.match(/^(\w+)\.(\w+)(?:\s*([+-])\s*([\d.]+))?$/);
|
|
203
|
+
if (!m) return NaN;
|
|
204
|
+
const [, ref, prop, op, offsetStr] = m;
|
|
205
|
+
const shape = shapeMap.get(ref);
|
|
206
|
+
if (!shape) return NaN;
|
|
207
|
+
let val = 0;
|
|
208
|
+
switch (prop) {
|
|
209
|
+
case "x":
|
|
210
|
+
val = shape.x || 0;
|
|
211
|
+
break;
|
|
212
|
+
case "y":
|
|
213
|
+
val = shape.y || 0;
|
|
214
|
+
break;
|
|
215
|
+
case "right":
|
|
216
|
+
val = (shape.x || 0) + (shape.width || 0);
|
|
217
|
+
break;
|
|
218
|
+
case "left":
|
|
219
|
+
val = shape.x || 0;
|
|
220
|
+
break;
|
|
221
|
+
case "top":
|
|
222
|
+
val = shape.y || 0;
|
|
223
|
+
break;
|
|
224
|
+
case "bottom":
|
|
225
|
+
val = (shape.y || 0) + (shape.height || 0);
|
|
226
|
+
break;
|
|
227
|
+
case "centerX":
|
|
228
|
+
val = (shape.x || 0) + (shape.width || 0) / 2;
|
|
229
|
+
break;
|
|
230
|
+
case "centerY":
|
|
231
|
+
val = (shape.y || 0) + (shape.height || 0) / 2;
|
|
232
|
+
break;
|
|
233
|
+
case "width":
|
|
234
|
+
val = shape.width || 0;
|
|
235
|
+
break;
|
|
236
|
+
case "height":
|
|
237
|
+
val = shape.height || 0;
|
|
238
|
+
break;
|
|
239
|
+
default:
|
|
240
|
+
val = 0;
|
|
241
|
+
}
|
|
242
|
+
const offset = offsetStr ? parseFloat(offsetStr) : 0;
|
|
243
|
+
return op === "-" ? val - offset : val + offset;
|
|
244
|
+
}
|
|
245
|
+
function renderLixScript(parsed) {
|
|
246
|
+
const { shapes: shapeDefs, errors } = parsed;
|
|
247
|
+
if (errors.length > 0) {
|
|
248
|
+
return { success: false, shapesCreated: 0, errors };
|
|
249
|
+
}
|
|
250
|
+
resolveShapeRefs(shapeDefs);
|
|
251
|
+
const svg = window.svg;
|
|
252
|
+
if (!svg) {
|
|
253
|
+
return { success: false, shapesCreated: 0, errors: [{ line: 0, message: "Canvas not initialized" }] };
|
|
254
|
+
}
|
|
255
|
+
const createdShapes = /* @__PURE__ */ new Map();
|
|
256
|
+
const renderErrors = [];
|
|
257
|
+
const userFrameDef = shapeDefs.find((s) => s.type === "frame");
|
|
258
|
+
let frame = null;
|
|
259
|
+
let frameDef = userFrameDef;
|
|
260
|
+
if (userFrameDef) {
|
|
261
|
+
frame = createFrame(userFrameDef, renderErrors);
|
|
262
|
+
if (frame) {
|
|
263
|
+
createdShapes.set(userFrameDef.id, { instance: frame, def: userFrameDef });
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
for (const def of shapeDefs) {
|
|
267
|
+
if (def.type === "frame") continue;
|
|
268
|
+
if (def.type === "arrow" || def.type === "line") continue;
|
|
269
|
+
const instance = createShape(def, renderErrors);
|
|
270
|
+
if (instance) {
|
|
271
|
+
createdShapes.set(def.id, { instance, def });
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
for (const def of shapeDefs) {
|
|
275
|
+
if (def.type !== "arrow" && def.type !== "line") continue;
|
|
276
|
+
const instance = createConnection(def, createdShapes, renderErrors);
|
|
277
|
+
if (instance) {
|
|
278
|
+
createdShapes.set(def.id, { instance, def });
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
if (!frame && createdShapes.size > 0) {
|
|
282
|
+
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
283
|
+
for (const [, { instance, def }] of createdShapes) {
|
|
284
|
+
if (def.type === "arrow" || def.type === "line") {
|
|
285
|
+
const from = resolveConnectionPoint(def.from, createdShapes);
|
|
286
|
+
const to = resolveConnectionPoint(def.to, createdShapes);
|
|
287
|
+
if (from) {
|
|
288
|
+
minX = Math.min(minX, from.x);
|
|
289
|
+
minY = Math.min(minY, from.y);
|
|
290
|
+
maxX = Math.max(maxX, from.x);
|
|
291
|
+
maxY = Math.max(maxY, from.y);
|
|
292
|
+
}
|
|
293
|
+
if (to) {
|
|
294
|
+
minX = Math.min(minX, to.x);
|
|
295
|
+
minY = Math.min(minY, to.y);
|
|
296
|
+
maxX = Math.max(maxX, to.x);
|
|
297
|
+
maxY = Math.max(maxY, to.y);
|
|
298
|
+
}
|
|
299
|
+
} else if (def.type !== "frame") {
|
|
300
|
+
const x = def.x || 0;
|
|
301
|
+
const y = def.y || 0;
|
|
302
|
+
const w = def.width || 160;
|
|
303
|
+
const h = def.height || 60;
|
|
304
|
+
minX = Math.min(minX, x);
|
|
305
|
+
minY = Math.min(minY, y);
|
|
306
|
+
maxX = Math.max(maxX, x + w);
|
|
307
|
+
maxY = Math.max(maxY, y + h);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
if (isFinite(minX)) {
|
|
311
|
+
const pad = 40;
|
|
312
|
+
const autoFrameDef = {
|
|
313
|
+
type: "frame",
|
|
314
|
+
id: "_lixscript_auto_frame",
|
|
315
|
+
line: 0,
|
|
316
|
+
x: minX - pad,
|
|
317
|
+
y: minY - pad,
|
|
318
|
+
width: maxX - minX + pad * 2,
|
|
319
|
+
height: maxY - minY + pad * 2,
|
|
320
|
+
props: { name: "LixScript" }
|
|
321
|
+
};
|
|
322
|
+
frameDef = autoFrameDef;
|
|
323
|
+
frame = createFrame(autoFrameDef, renderErrors);
|
|
324
|
+
if (frame) {
|
|
325
|
+
createdShapes.set(autoFrameDef.id, { instance: frame, def: autoFrameDef });
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
if (frame) {
|
|
330
|
+
for (const [id, { instance, def }] of createdShapes) {
|
|
331
|
+
if (def.type === "frame") continue;
|
|
332
|
+
if (shouldAddToFrame(def, frameDef)) {
|
|
333
|
+
frame.addShapeToFrame(instance);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return {
|
|
338
|
+
success: renderErrors.length === 0,
|
|
339
|
+
shapesCreated: createdShapes.size,
|
|
340
|
+
errors: renderErrors
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
function shouldAddToFrame(shapeDef, frameDef) {
|
|
344
|
+
if (!frameDef || !frameDef.props.contains) return true;
|
|
345
|
+
const ids = frameDef.props.contains.split(",").map((s) => s.trim());
|
|
346
|
+
return ids.includes(shapeDef.id);
|
|
347
|
+
}
|
|
348
|
+
function createFrame(def, errors) {
|
|
349
|
+
const Frame = window.Frame;
|
|
350
|
+
if (!Frame) {
|
|
351
|
+
errors.push({ line: def.line, message: "Frame class not available" });
|
|
352
|
+
return null;
|
|
353
|
+
}
|
|
354
|
+
try {
|
|
355
|
+
const x = def.x || 0;
|
|
356
|
+
const y = def.y || 0;
|
|
357
|
+
const w = def.width || 600;
|
|
358
|
+
const h = def.height || 400;
|
|
359
|
+
const frame = new Frame(x, y, w, h, {
|
|
360
|
+
frameName: def.props.frameName || def.props.name || def.id,
|
|
361
|
+
stroke: def.props.stroke || "#555",
|
|
362
|
+
strokeWidth: def.props.strokeWidth || 1,
|
|
363
|
+
fill: def.props.fill || "transparent",
|
|
364
|
+
fillStyle: def.props.fillStyle || "transparent",
|
|
365
|
+
fillColor: def.props.fillColor || "#1e1e28",
|
|
366
|
+
opacity: def.props.opacity || 1,
|
|
367
|
+
rotation: def.props.rotation || 0
|
|
368
|
+
});
|
|
369
|
+
window.shapes.push(frame);
|
|
370
|
+
if (window.pushCreateAction) window.pushCreateAction(frame);
|
|
371
|
+
frame._frameType = "lixscript";
|
|
372
|
+
frame._lixscriptSource = true;
|
|
373
|
+
if (def.props.imageURL && typeof frame.setImageFromURL === "function") {
|
|
374
|
+
frame.setImageFromURL(def.props.imageURL, def.props.imageFit || "cover");
|
|
375
|
+
}
|
|
376
|
+
return frame;
|
|
377
|
+
} catch (err) {
|
|
378
|
+
errors.push({ line: def.line, message: `Frame creation failed: ${err.message}` });
|
|
379
|
+
return null;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
function createShape(def, errors) {
|
|
383
|
+
try {
|
|
384
|
+
switch (def.type) {
|
|
385
|
+
case "rect":
|
|
386
|
+
return createRect(def, errors);
|
|
387
|
+
case "circle":
|
|
388
|
+
case "ellipse":
|
|
389
|
+
return createCircle(def, errors);
|
|
390
|
+
case "text":
|
|
391
|
+
return createText(def, errors);
|
|
392
|
+
case "freehand":
|
|
393
|
+
return createFreehand(def, errors);
|
|
394
|
+
case "image":
|
|
395
|
+
return createImage(def, errors);
|
|
396
|
+
case "icon":
|
|
397
|
+
return createIcon(def, errors);
|
|
398
|
+
default:
|
|
399
|
+
errors.push({ line: def.line, message: `Unknown shape type: ${def.type}` });
|
|
400
|
+
return null;
|
|
401
|
+
}
|
|
402
|
+
} catch (err) {
|
|
403
|
+
errors.push({ line: def.line, message: `Shape '${def.id}' failed: ${err.message}` });
|
|
404
|
+
return null;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
function createImage(def, errors) {
|
|
408
|
+
const ImageShape = window.ImageShape;
|
|
409
|
+
if (!ImageShape) {
|
|
410
|
+
errors.push({ line: def.line, message: "ImageShape class not available" });
|
|
411
|
+
return null;
|
|
412
|
+
}
|
|
413
|
+
const src = def.props.src || def.props.href || def.props.url || "";
|
|
414
|
+
if (!src) {
|
|
415
|
+
errors.push({ line: def.line, message: `Image '${def.id}' requires a src property` });
|
|
416
|
+
return null;
|
|
417
|
+
}
|
|
418
|
+
const svgEl = document.getElementById("freehand-canvas");
|
|
419
|
+
if (!svgEl) return null;
|
|
420
|
+
const x = def.x || 0;
|
|
421
|
+
const y = def.y || 0;
|
|
422
|
+
const w = def.width || 200;
|
|
423
|
+
const h = def.height || 200;
|
|
424
|
+
const imgEl = document.createElementNS("http://www.w3.org/2000/svg", "image");
|
|
425
|
+
imgEl.setAttribute("href", src);
|
|
426
|
+
imgEl.setAttribute("x", x);
|
|
427
|
+
imgEl.setAttribute("y", y);
|
|
428
|
+
imgEl.setAttribute("width", w);
|
|
429
|
+
imgEl.setAttribute("height", h);
|
|
430
|
+
imgEl.setAttribute("data-shape-x", x);
|
|
431
|
+
imgEl.setAttribute("data-shape-y", y);
|
|
432
|
+
imgEl.setAttribute("data-shape-width", w);
|
|
433
|
+
imgEl.setAttribute("data-shape-height", h);
|
|
434
|
+
imgEl.setAttribute("type", "image");
|
|
435
|
+
imgEl.setAttribute("preserveAspectRatio", def.props.fit === "contain" ? "xMidYMid meet" : def.props.fit === "cover" ? "xMidYMid slice" : "xMidYMid meet");
|
|
436
|
+
svgEl.appendChild(imgEl);
|
|
437
|
+
const shape = new ImageShape(imgEl);
|
|
438
|
+
if (def.props.rotation) shape.rotation = parseFloat(def.props.rotation);
|
|
439
|
+
shape.shapeID = def.id || shape.shapeID;
|
|
440
|
+
window.shapes.push(shape);
|
|
441
|
+
if (window.pushCreateAction) window.pushCreateAction(shape);
|
|
442
|
+
return shape;
|
|
443
|
+
}
|
|
444
|
+
function createIcon(def, errors) {
|
|
445
|
+
const IconShape = window.IconShape;
|
|
446
|
+
if (!IconShape) {
|
|
447
|
+
errors.push({ line: def.line, message: "IconShape class not available" });
|
|
448
|
+
return null;
|
|
449
|
+
}
|
|
450
|
+
const svgEl = document.getElementById("freehand-canvas");
|
|
451
|
+
if (!svgEl) return null;
|
|
452
|
+
const x = def.x || 0;
|
|
453
|
+
const y = def.y || 0;
|
|
454
|
+
const size = def.width || 48;
|
|
455
|
+
const color = def.props.color || def.props.fill || "#ffffff";
|
|
456
|
+
let innerSVG = "";
|
|
457
|
+
if (def.props.svg) {
|
|
458
|
+
innerSVG = def.props.svg;
|
|
459
|
+
} else if (def.props.name) {
|
|
460
|
+
innerSVG = `<circle cx="12" cy="12" r="10" fill="none" stroke="${color}" stroke-width="1.5"/><text x="12" y="16" text-anchor="middle" fill="${color}" font-size="10" font-family="sans-serif">${(def.props.name || "?").charAt(0)}</text>`;
|
|
461
|
+
} else {
|
|
462
|
+
errors.push({ line: def.line, message: `Icon '${def.id}' requires a name or svg property` });
|
|
463
|
+
return null;
|
|
464
|
+
}
|
|
465
|
+
const vbWidth = parseFloat(def.props.viewBoxWidth) || 24;
|
|
466
|
+
const vbHeight = parseFloat(def.props.viewBoxHeight) || 24;
|
|
467
|
+
const scale = size / Math.max(vbWidth, vbHeight);
|
|
468
|
+
const localCenterX = size / 2 / scale;
|
|
469
|
+
const localCenterY = size / 2 / scale;
|
|
470
|
+
const rotation = def.props.rotation || 0;
|
|
471
|
+
const iconGroup = document.createElementNS("http://www.w3.org/2000/svg", "g");
|
|
472
|
+
iconGroup.setAttribute("transform", `translate(${x}, ${y}) scale(${scale}) rotate(${rotation}, ${localCenterX}, ${localCenterY})`);
|
|
473
|
+
iconGroup.setAttribute("data-viewbox-width", vbWidth);
|
|
474
|
+
iconGroup.setAttribute("data-viewbox-height", vbHeight);
|
|
475
|
+
iconGroup.setAttribute("x", x);
|
|
476
|
+
iconGroup.setAttribute("y", y);
|
|
477
|
+
iconGroup.setAttribute("width", size);
|
|
478
|
+
iconGroup.setAttribute("height", size);
|
|
479
|
+
iconGroup.setAttribute("type", "icon");
|
|
480
|
+
iconGroup.setAttribute("data-shape-x", x);
|
|
481
|
+
iconGroup.setAttribute("data-shape-y", y);
|
|
482
|
+
iconGroup.setAttribute("data-shape-width", size);
|
|
483
|
+
iconGroup.setAttribute("data-shape-height", size);
|
|
484
|
+
iconGroup.setAttribute("data-shape-rotation", rotation);
|
|
485
|
+
iconGroup.setAttribute("style", "cursor: pointer; pointer-events: all;");
|
|
486
|
+
const bgRect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
|
|
487
|
+
bgRect.setAttribute("x", 0);
|
|
488
|
+
bgRect.setAttribute("y", 0);
|
|
489
|
+
bgRect.setAttribute("width", vbWidth);
|
|
490
|
+
bgRect.setAttribute("height", vbHeight);
|
|
491
|
+
bgRect.setAttribute("fill", "transparent");
|
|
492
|
+
bgRect.setAttribute("stroke", "none");
|
|
493
|
+
bgRect.setAttribute("style", "pointer-events: all;");
|
|
494
|
+
iconGroup.appendChild(bgRect);
|
|
495
|
+
const tempSvg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
496
|
+
tempSvg.innerHTML = innerSVG;
|
|
497
|
+
while (tempSvg.firstChild) {
|
|
498
|
+
const child = tempSvg.firstChild;
|
|
499
|
+
if (child.nodeType === 1) {
|
|
500
|
+
const fill = child.getAttribute("fill");
|
|
501
|
+
const stroke = child.getAttribute("stroke");
|
|
502
|
+
if (!fill || fill === "currentColor" || fill === "#000" || fill === "#000000" || fill === "black") {
|
|
503
|
+
child.setAttribute("fill", color);
|
|
504
|
+
}
|
|
505
|
+
if (stroke === "currentColor" || stroke === "#000" || stroke === "#000000" || stroke === "black") {
|
|
506
|
+
child.setAttribute("stroke", color);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
iconGroup.appendChild(child);
|
|
510
|
+
}
|
|
511
|
+
svgEl.appendChild(iconGroup);
|
|
512
|
+
const shape = new IconShape(iconGroup);
|
|
513
|
+
shape.shapeID = def.id || shape.shapeID;
|
|
514
|
+
window.shapes.push(shape);
|
|
515
|
+
if (window.pushCreateAction) window.pushCreateAction(shape);
|
|
516
|
+
return shape;
|
|
517
|
+
}
|
|
518
|
+
function createRect(def, errors) {
|
|
519
|
+
const Rectangle = window.Rectangle;
|
|
520
|
+
if (!Rectangle) {
|
|
521
|
+
errors.push({ line: def.line, message: "Rectangle class not available" });
|
|
522
|
+
return null;
|
|
523
|
+
}
|
|
524
|
+
const x = def.x || 0;
|
|
525
|
+
const y = def.y || 0;
|
|
526
|
+
const w = def.width || 160;
|
|
527
|
+
const h = def.height || 60;
|
|
528
|
+
const rect = new Rectangle(x, y, w, h, {
|
|
529
|
+
stroke: def.props.stroke || "#fff",
|
|
530
|
+
strokeWidth: def.props.strokeWidth || 2,
|
|
531
|
+
fill: def.props.fill || "transparent",
|
|
532
|
+
fillStyle: def.props.fillStyle || "none",
|
|
533
|
+
roughness: def.props.roughness !== void 0 ? def.props.roughness : 1.5,
|
|
534
|
+
strokeDasharray: resolveStrokeStyle(def.props.style),
|
|
535
|
+
shadeColor: def.props.shadeColor || null,
|
|
536
|
+
shadeOpacity: def.props.shadeOpacity !== void 0 ? parseFloat(def.props.shadeOpacity) : 0.15,
|
|
537
|
+
shadeDirection: def.props.shadeDirection || "bottom"
|
|
538
|
+
});
|
|
539
|
+
if (def.props.rotation) rect.rotation = def.props.rotation;
|
|
540
|
+
if (def.props.label) {
|
|
541
|
+
rect.setLabel(
|
|
542
|
+
def.props.label,
|
|
543
|
+
def.props.labelColor || "#e0e0e0",
|
|
544
|
+
def.props.labelFontSize || 14
|
|
545
|
+
);
|
|
546
|
+
}
|
|
547
|
+
window.shapes.push(rect);
|
|
548
|
+
if (window.pushCreateAction) window.pushCreateAction(rect);
|
|
549
|
+
return rect;
|
|
550
|
+
}
|
|
551
|
+
function createCircle(def, errors) {
|
|
552
|
+
const Circle = window.Circle;
|
|
553
|
+
if (!Circle) {
|
|
554
|
+
errors.push({ line: def.line, message: "Circle class not available" });
|
|
555
|
+
return null;
|
|
556
|
+
}
|
|
557
|
+
const x = def.x || 0;
|
|
558
|
+
const y = def.y || 0;
|
|
559
|
+
const w = def.width || 80;
|
|
560
|
+
const h = def.height || 80;
|
|
561
|
+
const rx = w / 2;
|
|
562
|
+
const ry = h / 2;
|
|
563
|
+
const circle = new Circle(x + rx, y + ry, rx, ry, {
|
|
564
|
+
stroke: def.props.stroke || "#fff",
|
|
565
|
+
strokeWidth: def.props.strokeWidth || 2,
|
|
566
|
+
fill: def.props.fill || "transparent",
|
|
567
|
+
fillStyle: def.props.fillStyle || "none",
|
|
568
|
+
roughness: def.props.roughness !== void 0 ? def.props.roughness : 1.5,
|
|
569
|
+
strokeDasharray: resolveStrokeStyle(def.props.style),
|
|
570
|
+
shadeColor: def.props.shadeColor || null,
|
|
571
|
+
shadeOpacity: def.props.shadeOpacity !== void 0 ? parseFloat(def.props.shadeOpacity) : 0.15,
|
|
572
|
+
shadeDirection: def.props.shadeDirection || "bottom"
|
|
573
|
+
});
|
|
574
|
+
if (def.props.rotation) circle.rotation = def.props.rotation;
|
|
575
|
+
if (def.props.label) {
|
|
576
|
+
circle.setLabel(
|
|
577
|
+
def.props.label,
|
|
578
|
+
def.props.labelColor || "#e0e0e0",
|
|
579
|
+
def.props.labelFontSize || 14
|
|
580
|
+
);
|
|
581
|
+
}
|
|
582
|
+
window.shapes.push(circle);
|
|
583
|
+
if (window.pushCreateAction) window.pushCreateAction(circle);
|
|
584
|
+
return circle;
|
|
585
|
+
}
|
|
586
|
+
function createText(def, errors) {
|
|
587
|
+
const TextShape = window.TextShape;
|
|
588
|
+
const svgEl = window.svg;
|
|
589
|
+
if (!TextShape || !svgEl) {
|
|
590
|
+
errors.push({ line: def.line, message: "TextShape class not available" });
|
|
591
|
+
return null;
|
|
592
|
+
}
|
|
593
|
+
const x = def.x || 0;
|
|
594
|
+
const y = def.y || 0;
|
|
595
|
+
const content = def.props.content || def.props.text || "Text";
|
|
596
|
+
const color = def.props.color || def.props.fill || "#fff";
|
|
597
|
+
const fontSize = def.props.fontSize || 16;
|
|
598
|
+
const g = document.createElementNS(NS, "g");
|
|
599
|
+
g.setAttribute("data-type", "text-group");
|
|
600
|
+
g.setAttribute("transform", `translate(${x}, ${y})`);
|
|
601
|
+
g.setAttribute("data-x", x);
|
|
602
|
+
g.setAttribute("data-y", y);
|
|
603
|
+
const t = document.createElementNS(NS, "text");
|
|
604
|
+
t.setAttribute("x", 0);
|
|
605
|
+
t.setAttribute("y", 0);
|
|
606
|
+
t.setAttribute("text-anchor", def.props.anchor || "middle");
|
|
607
|
+
t.setAttribute("dominant-baseline", "central");
|
|
608
|
+
t.setAttribute("fill", color);
|
|
609
|
+
t.setAttribute("font-size", fontSize);
|
|
610
|
+
t.setAttribute("font-family", def.props.fontFamily || "lixFont, sans-serif");
|
|
611
|
+
t.setAttribute("data-initial-font", def.props.fontFamily || "lixFont");
|
|
612
|
+
t.setAttribute("data-initial-color", color);
|
|
613
|
+
t.setAttribute("data-initial-size", fontSize + "px");
|
|
614
|
+
t.textContent = content;
|
|
615
|
+
g.appendChild(t);
|
|
616
|
+
svgEl.appendChild(g);
|
|
617
|
+
const shape = new TextShape(g);
|
|
618
|
+
window.shapes.push(shape);
|
|
619
|
+
if (window.pushCreateAction) window.pushCreateAction(shape);
|
|
620
|
+
return shape;
|
|
621
|
+
}
|
|
622
|
+
function createFreehand(def, errors) {
|
|
623
|
+
const FreehandStroke = window.FreehandStroke;
|
|
624
|
+
if (!FreehandStroke) {
|
|
625
|
+
errors.push({ line: def.line, message: "FreehandStroke class not available" });
|
|
626
|
+
return null;
|
|
627
|
+
}
|
|
628
|
+
const pointsStr = def.props.points || "";
|
|
629
|
+
const points = pointsStr.split(";").map((p) => {
|
|
630
|
+
const [x, y, pressure] = p.split(",").map(Number);
|
|
631
|
+
return [x || 0, y || 0, pressure || 0.5];
|
|
632
|
+
}).filter((p) => !isNaN(p[0]));
|
|
633
|
+
if (points.length < 2) {
|
|
634
|
+
errors.push({ line: def.line, message: "Freehand requires at least 2 points" });
|
|
635
|
+
return null;
|
|
636
|
+
}
|
|
637
|
+
const stroke = new FreehandStroke(points, {
|
|
638
|
+
stroke: def.props.stroke || def.props.color || "#fff",
|
|
639
|
+
strokeWidth: def.props.strokeWidth || 3,
|
|
640
|
+
thinning: def.props.thinning || 0.5,
|
|
641
|
+
roughness: def.props.roughness || "smooth",
|
|
642
|
+
strokeStyle: def.props.style || "solid"
|
|
643
|
+
});
|
|
644
|
+
window.shapes.push(stroke);
|
|
645
|
+
if (window.pushCreateAction) window.pushCreateAction(stroke);
|
|
646
|
+
return stroke;
|
|
647
|
+
}
|
|
648
|
+
function createConnection(def, createdShapes, errors) {
|
|
649
|
+
const from = resolveConnectionPoint(def.from, createdShapes);
|
|
650
|
+
const to = resolveConnectionPoint(def.to, createdShapes);
|
|
651
|
+
if (!from || !to) {
|
|
652
|
+
errors.push({ line: def.line, message: `Cannot resolve connection endpoints for '${def.id}'` });
|
|
653
|
+
return null;
|
|
654
|
+
}
|
|
655
|
+
if (def.type === "arrow") {
|
|
656
|
+
return createArrow(def, from, to, createdShapes, errors);
|
|
657
|
+
} else {
|
|
658
|
+
return createLine(def, from, to, errors);
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
function createArrow(def, from, to, createdShapes, errors) {
|
|
662
|
+
const Arrow = window.Arrow;
|
|
663
|
+
if (!Arrow) {
|
|
664
|
+
errors.push({ line: def.line, message: "Arrow class not available" });
|
|
665
|
+
return null;
|
|
666
|
+
}
|
|
667
|
+
const curveMode = def.props.curve || "straight";
|
|
668
|
+
const arrow = new Arrow(
|
|
669
|
+
{ x: from.x, y: from.y },
|
|
670
|
+
{ x: to.x, y: to.y },
|
|
671
|
+
{
|
|
672
|
+
stroke: def.props.stroke || "#fff",
|
|
673
|
+
strokeWidth: def.props.strokeWidth || 2,
|
|
674
|
+
arrowOutlineStyle: def.props.style || "solid",
|
|
675
|
+
arrowHeadStyle: def.props.head || "default",
|
|
676
|
+
arrowHeadLength: def.props.headLength || 15,
|
|
677
|
+
arrowCurved: curveMode,
|
|
678
|
+
arrowCurveAmount: def.props.curveAmount || 50
|
|
679
|
+
}
|
|
680
|
+
);
|
|
681
|
+
if (def.props.label) {
|
|
682
|
+
arrow.setLabel(
|
|
683
|
+
def.props.label,
|
|
684
|
+
def.props.labelColor || "#e0e0e0",
|
|
685
|
+
def.props.labelFontSize || 12
|
|
686
|
+
);
|
|
687
|
+
}
|
|
688
|
+
if (def.from && def.from.ref) {
|
|
689
|
+
const sourceEntry = createdShapes.get(def.from.ref);
|
|
690
|
+
if (sourceEntry) {
|
|
691
|
+
autoAttach(arrow, sourceEntry.instance, true, from);
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
if (def.to && def.to.ref) {
|
|
695
|
+
const targetEntry = createdShapes.get(def.to.ref);
|
|
696
|
+
if (targetEntry) {
|
|
697
|
+
autoAttach(arrow, targetEntry.instance, false, to);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
window.shapes.push(arrow);
|
|
701
|
+
if (window.pushCreateAction) window.pushCreateAction(arrow);
|
|
702
|
+
return arrow;
|
|
703
|
+
}
|
|
704
|
+
function createLine(def, from, to, errors) {
|
|
705
|
+
const Line = window.Line;
|
|
706
|
+
if (!Line) {
|
|
707
|
+
errors.push({ line: def.line, message: "Line class not available" });
|
|
708
|
+
return null;
|
|
709
|
+
}
|
|
710
|
+
const line = new Line(
|
|
711
|
+
{ x: from.x, y: from.y },
|
|
712
|
+
{ x: to.x, y: to.y },
|
|
713
|
+
{
|
|
714
|
+
stroke: def.props.stroke || "#fff",
|
|
715
|
+
strokeWidth: def.props.strokeWidth || 2,
|
|
716
|
+
strokeDasharray: resolveStrokeStyle(def.props.style)
|
|
717
|
+
}
|
|
718
|
+
);
|
|
719
|
+
if (def.props.curve === "true" || def.props.curve === true) {
|
|
720
|
+
line.isCurved = true;
|
|
721
|
+
line.initializeCurveControlPoint?.();
|
|
722
|
+
line.draw();
|
|
723
|
+
}
|
|
724
|
+
if (def.props.label) {
|
|
725
|
+
line.setLabel(
|
|
726
|
+
def.props.label,
|
|
727
|
+
def.props.labelColor || "#e0e0e0",
|
|
728
|
+
def.props.labelFontSize || 12
|
|
729
|
+
);
|
|
730
|
+
}
|
|
731
|
+
window.shapes.push(line);
|
|
732
|
+
if (window.pushCreateAction) window.pushCreateAction(line);
|
|
733
|
+
return line;
|
|
734
|
+
}
|
|
735
|
+
function resolveConnectionPoint(pointDef, createdShapes) {
|
|
736
|
+
if (!pointDef) return null;
|
|
737
|
+
if (pointDef.x !== void 0 && pointDef.y !== void 0) {
|
|
738
|
+
return { x: pointDef.x, y: pointDef.y };
|
|
739
|
+
}
|
|
740
|
+
if (pointDef.ref) {
|
|
741
|
+
const entry = createdShapes.get(pointDef.ref);
|
|
742
|
+
if (!entry) return null;
|
|
743
|
+
const shape = entry.instance;
|
|
744
|
+
const def = entry.def;
|
|
745
|
+
const side = pointDef.side || "center";
|
|
746
|
+
const offset = pointDef.offset || 0;
|
|
747
|
+
const sx = shape.x !== void 0 ? shape.x : def.x || 0;
|
|
748
|
+
const sy = shape.y !== void 0 ? shape.y : def.y || 0;
|
|
749
|
+
const sw = shape.width || def.width || 0;
|
|
750
|
+
const sh = shape.height || def.height || 0;
|
|
751
|
+
let cx, cy;
|
|
752
|
+
if (shape.shapeName === "circle") {
|
|
753
|
+
cx = sx;
|
|
754
|
+
cy = sy;
|
|
755
|
+
const rx = shape.rx || sw / 2;
|
|
756
|
+
const ry = shape.ry || sh / 2;
|
|
757
|
+
switch (side) {
|
|
758
|
+
case "top":
|
|
759
|
+
return { x: cx + offset, y: cy - ry };
|
|
760
|
+
case "bottom":
|
|
761
|
+
return { x: cx + offset, y: cy + ry };
|
|
762
|
+
case "left":
|
|
763
|
+
return { x: cx - rx, y: cy + offset };
|
|
764
|
+
case "right":
|
|
765
|
+
return { x: cx + rx, y: cy + offset };
|
|
766
|
+
case "center":
|
|
767
|
+
return { x: cx + offset, y: cy };
|
|
768
|
+
default:
|
|
769
|
+
return { x: cx, y: cy };
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
cx = sx + sw / 2;
|
|
773
|
+
cy = sy + sh / 2;
|
|
774
|
+
switch (side) {
|
|
775
|
+
case "top":
|
|
776
|
+
return { x: cx + offset, y: sy };
|
|
777
|
+
case "bottom":
|
|
778
|
+
return { x: cx + offset, y: sy + sh };
|
|
779
|
+
case "left":
|
|
780
|
+
return { x: sx, y: cy + offset };
|
|
781
|
+
case "right":
|
|
782
|
+
return { x: sx + sw, y: cy + offset };
|
|
783
|
+
case "center":
|
|
784
|
+
return { x: cx + offset, y: cy };
|
|
785
|
+
default:
|
|
786
|
+
return { x: cx, y: cy };
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
return null;
|
|
790
|
+
}
|
|
791
|
+
function autoAttach(arrow, shape, isStart, connectionPoint) {
|
|
792
|
+
if (!shape || !connectionPoint) return;
|
|
793
|
+
const sx = shape.x || 0;
|
|
794
|
+
const sy = shape.y || 0;
|
|
795
|
+
const sw = shape.width || 0;
|
|
796
|
+
const sh = shape.height || 0;
|
|
797
|
+
let cx, cy;
|
|
798
|
+
if (shape.shapeName === "circle") {
|
|
799
|
+
cx = sx;
|
|
800
|
+
cy = sy;
|
|
801
|
+
} else {
|
|
802
|
+
cx = sx + sw / 2;
|
|
803
|
+
cy = sy + sh / 2;
|
|
804
|
+
}
|
|
805
|
+
const dx = connectionPoint.x - cx;
|
|
806
|
+
const dy = connectionPoint.y - cy;
|
|
807
|
+
let side = "bottom";
|
|
808
|
+
if (Math.abs(dx) > Math.abs(dy)) {
|
|
809
|
+
side = dx > 0 ? "right" : "left";
|
|
810
|
+
} else {
|
|
811
|
+
side = dy > 0 ? "bottom" : "top";
|
|
812
|
+
}
|
|
813
|
+
const attachment = { shape, side, offset: { x: 0, y: 0 } };
|
|
814
|
+
if (isStart) {
|
|
815
|
+
arrow.attachedToStart = attachment;
|
|
816
|
+
} else {
|
|
817
|
+
arrow.attachedToEnd = attachment;
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
function previewLixScript(parsed) {
|
|
821
|
+
const { shapes: defs, errors } = parsed;
|
|
822
|
+
if (errors.length > 0) return "";
|
|
823
|
+
resolveShapeRefs(defs);
|
|
824
|
+
const shapeMap = /* @__PURE__ */ new Map();
|
|
825
|
+
for (const def of defs) {
|
|
826
|
+
if (def.type !== "arrow" && def.type !== "line") {
|
|
827
|
+
shapeMap.set(def.id, def);
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
function resolvePreviewPoint(pointDef) {
|
|
831
|
+
if (!pointDef) return { x: 0, y: 0 };
|
|
832
|
+
if (pointDef.x !== void 0 && pointDef.y !== void 0) return pointDef;
|
|
833
|
+
if (pointDef.ref) {
|
|
834
|
+
const target = shapeMap.get(pointDef.ref);
|
|
835
|
+
if (!target) return { x: 0, y: 0 };
|
|
836
|
+
const side = pointDef.side || "center";
|
|
837
|
+
const offset = pointDef.offset || 0;
|
|
838
|
+
const tx = target.x || 0;
|
|
839
|
+
const ty = target.y || 0;
|
|
840
|
+
const tw = target.width || 160;
|
|
841
|
+
const th = target.height || 60;
|
|
842
|
+
const cx = tx + tw / 2;
|
|
843
|
+
const cy = ty + th / 2;
|
|
844
|
+
switch (side) {
|
|
845
|
+
case "top":
|
|
846
|
+
return { x: cx + offset, y: ty };
|
|
847
|
+
case "bottom":
|
|
848
|
+
return { x: cx + offset, y: ty + th };
|
|
849
|
+
case "left":
|
|
850
|
+
return { x: tx, y: cy + offset };
|
|
851
|
+
case "right":
|
|
852
|
+
return { x: tx + tw, y: cy + offset };
|
|
853
|
+
case "center":
|
|
854
|
+
return { x: cx + offset, y: cy };
|
|
855
|
+
default:
|
|
856
|
+
return { x: cx, y: cy };
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
return { x: 0, y: 0 };
|
|
860
|
+
}
|
|
861
|
+
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
862
|
+
for (const def of defs) {
|
|
863
|
+
if (def.type === "arrow" || def.type === "line") {
|
|
864
|
+
const from = resolvePreviewPoint(def.from);
|
|
865
|
+
const to = resolvePreviewPoint(def.to);
|
|
866
|
+
minX = Math.min(minX, from.x, to.x);
|
|
867
|
+
minY = Math.min(minY, from.y, to.y);
|
|
868
|
+
maxX = Math.max(maxX, from.x, to.x);
|
|
869
|
+
maxY = Math.max(maxY, from.y, to.y);
|
|
870
|
+
} else if (def.type !== "frame") {
|
|
871
|
+
const x = def.x || 0;
|
|
872
|
+
const y = def.y || 0;
|
|
873
|
+
const w = def.width || 160;
|
|
874
|
+
const h = def.height || 60;
|
|
875
|
+
minX = Math.min(minX, x);
|
|
876
|
+
minY = Math.min(minY, y);
|
|
877
|
+
maxX = Math.max(maxX, x + w);
|
|
878
|
+
maxY = Math.max(maxY, y + h);
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
if (!isFinite(minX)) {
|
|
882
|
+
minX = 0;
|
|
883
|
+
minY = 0;
|
|
884
|
+
maxX = 400;
|
|
885
|
+
maxY = 300;
|
|
886
|
+
}
|
|
887
|
+
const pad = 40;
|
|
888
|
+
const vw = maxX - minX + pad * 2;
|
|
889
|
+
const vh = maxY - minY + pad * 2;
|
|
890
|
+
let svgContent = "";
|
|
891
|
+
for (const def of defs) {
|
|
892
|
+
const props = def.props || {};
|
|
893
|
+
switch (def.type) {
|
|
894
|
+
case "rect":
|
|
895
|
+
svgContent += `<rect x="${def.x || 0}" y="${def.y || 0}" width="${def.width || 160}" height="${def.height || 60}" stroke="${props.stroke || "#fff"}" stroke-width="${props.strokeWidth || 2}" fill="${props.fill || "transparent"}" rx="4" />`;
|
|
896
|
+
if (props.label) {
|
|
897
|
+
const cx = (def.x || 0) + (def.width || 160) / 2;
|
|
898
|
+
const cy = (def.y || 0) + (def.height || 60) / 2;
|
|
899
|
+
svgContent += `<text x="${cx}" y="${cy}" text-anchor="middle" dominant-baseline="central" fill="${props.labelColor || "#e0e0e0"}" font-size="${props.labelFontSize || 14}" font-family="sans-serif">${escapeXml(props.label)}</text>`;
|
|
900
|
+
}
|
|
901
|
+
break;
|
|
902
|
+
case "circle":
|
|
903
|
+
case "ellipse": {
|
|
904
|
+
const rx = (def.width || 80) / 2;
|
|
905
|
+
const ry = (def.height || 80) / 2;
|
|
906
|
+
const cx = (def.x || 0) + rx;
|
|
907
|
+
const cy = (def.y || 0) + ry;
|
|
908
|
+
svgContent += `<ellipse cx="${cx}" cy="${cy}" rx="${rx}" ry="${ry}" stroke="${props.stroke || "#fff"}" stroke-width="${props.strokeWidth || 2}" fill="${props.fill || "transparent"}" />`;
|
|
909
|
+
if (props.label) {
|
|
910
|
+
svgContent += `<text x="${cx}" y="${cy}" text-anchor="middle" dominant-baseline="central" fill="${props.labelColor || "#e0e0e0"}" font-size="${props.labelFontSize || 14}" font-family="sans-serif">${escapeXml(props.label)}</text>`;
|
|
911
|
+
}
|
|
912
|
+
break;
|
|
913
|
+
}
|
|
914
|
+
case "text": {
|
|
915
|
+
const content = props.content || props.text || "Text";
|
|
916
|
+
svgContent += `<text x="${def.x || 0}" y="${def.y || 0}" fill="${props.color || props.fill || "#fff"}" font-size="${props.fontSize || 16}" font-family="sans-serif">${escapeXml(content)}</text>`;
|
|
917
|
+
break;
|
|
918
|
+
}
|
|
919
|
+
case "arrow": {
|
|
920
|
+
const fromOrig = resolvePreviewPoint(def.from);
|
|
921
|
+
const toOrig = resolvePreviewPoint(def.to);
|
|
922
|
+
const stroke = props.stroke || "#fff";
|
|
923
|
+
const sw = props.strokeWidth || 2;
|
|
924
|
+
const dash = props.style === "dashed" ? ' stroke-dasharray="10,10"' : props.style === "dotted" ? ' stroke-dasharray="2,8"' : "";
|
|
925
|
+
const curve = props.curve || "straight";
|
|
926
|
+
const markerId = `ah-${def.id}`;
|
|
927
|
+
const headLen = 10;
|
|
928
|
+
const to = shortenEndpoint(fromOrig, toOrig, headLen);
|
|
929
|
+
const from = fromOrig;
|
|
930
|
+
svgContent += `<defs><marker id="${markerId}" markerWidth="10" markerHeight="7" refX="0" refY="3.5" orient="auto"><polygon points="0 0, 10 3.5, 0 7" fill="${stroke}" /></marker></defs>`;
|
|
931
|
+
if (curve === "curved") {
|
|
932
|
+
const mx = (from.x + toOrig.x) / 2;
|
|
933
|
+
const my = (from.y + toOrig.y) / 2;
|
|
934
|
+
const dx = toOrig.x - from.x;
|
|
935
|
+
const dy = toOrig.y - from.y;
|
|
936
|
+
const dist = Math.sqrt(dx * dx + dy * dy) || 1;
|
|
937
|
+
const amt = props.curveAmount || Math.min(dist * 0.3, 80);
|
|
938
|
+
const cpx = mx + dy / dist * amt;
|
|
939
|
+
const cpy = my - dx / dist * amt;
|
|
940
|
+
const toShort = shortenEndpoint({ x: cpx, y: cpy }, toOrig, headLen);
|
|
941
|
+
svgContent += `<path d="M${from.x},${from.y} Q${cpx},${cpy} ${toShort.x},${toShort.y}" stroke="${stroke}" stroke-width="${sw}" fill="none"${dash} marker-end="url(#${markerId})" />`;
|
|
942
|
+
if (props.label) {
|
|
943
|
+
const lx = 0.25 * from.x + 0.5 * cpx + 0.25 * toOrig.x;
|
|
944
|
+
const ly = 0.25 * from.y + 0.5 * cpy + 0.25 * toOrig.y - 8;
|
|
945
|
+
svgContent += `<text x="${lx}" y="${ly}" text-anchor="middle" fill="${props.labelColor || "#a0a0b0"}" font-size="11" font-family="sans-serif">${escapeXml(props.label)}</text>`;
|
|
946
|
+
}
|
|
947
|
+
} else if (curve === "elbow") {
|
|
948
|
+
const midY = from.y + (toOrig.y - from.y) / 2;
|
|
949
|
+
const lastFrom = { x: toOrig.x, y: midY };
|
|
950
|
+
const toShort = shortenEndpoint(lastFrom, toOrig, headLen);
|
|
951
|
+
svgContent += `<path d="M${from.x},${from.y} L${from.x},${midY} L${toOrig.x},${midY} L${toShort.x},${toShort.y}" stroke="${stroke}" stroke-width="${sw}" fill="none"${dash} marker-end="url(#${markerId})" />`;
|
|
952
|
+
if (props.label) {
|
|
953
|
+
const lx = (from.x + toOrig.x) / 2;
|
|
954
|
+
const ly = midY - 8;
|
|
955
|
+
svgContent += `<text x="${lx}" y="${ly}" text-anchor="middle" fill="${props.labelColor || "#a0a0b0"}" font-size="11" font-family="sans-serif">${escapeXml(props.label)}</text>`;
|
|
956
|
+
}
|
|
957
|
+
} else {
|
|
958
|
+
svgContent += `<line x1="${from.x}" y1="${from.y}" x2="${to.x}" y2="${to.y}" stroke="${stroke}" stroke-width="${sw}"${dash} marker-end="url(#${markerId})" />`;
|
|
959
|
+
if (props.label) {
|
|
960
|
+
const lx = (from.x + toOrig.x) / 2;
|
|
961
|
+
const ly = (from.y + toOrig.y) / 2 - 10;
|
|
962
|
+
svgContent += `<text x="${lx}" y="${ly}" text-anchor="middle" fill="${props.labelColor || "#a0a0b0"}" font-size="11" font-family="sans-serif">${escapeXml(props.label)}</text>`;
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
break;
|
|
966
|
+
}
|
|
967
|
+
case "line": {
|
|
968
|
+
const from = resolvePreviewPoint(def.from);
|
|
969
|
+
const to = resolvePreviewPoint(def.to);
|
|
970
|
+
const dash = props.style === "dashed" ? ' stroke-dasharray="10,10"' : props.style === "dotted" ? ' stroke-dasharray="2,8"' : "";
|
|
971
|
+
svgContent += `<line x1="${from.x}" y1="${from.y}" x2="${to.x}" y2="${to.y}" stroke="${props.stroke || "#fff"}" stroke-width="${props.strokeWidth || 2}"${dash} />`;
|
|
972
|
+
break;
|
|
973
|
+
}
|
|
974
|
+
case "frame": {
|
|
975
|
+
const frameName = props.name || def.id;
|
|
976
|
+
svgContent += `<rect x="${def.x || 0}" y="${def.y || 0}" width="${def.width || 600}" height="${def.height || 400}" stroke="${props.stroke || "#555"}" stroke-width="1" fill="transparent" stroke-dasharray="8,4" rx="8" />`;
|
|
977
|
+
svgContent += `<text x="${(def.x || 0) + 10}" y="${(def.y || 0) - 8}" fill="#888" font-size="12" font-family="sans-serif">${escapeXml(frameName)}</text>`;
|
|
978
|
+
break;
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="${minX - pad} ${minY - pad} ${vw} ${vh}" width="100%" height="100%" style="background: transparent;">
|
|
983
|
+
${svgContent}
|
|
984
|
+
</svg>`;
|
|
985
|
+
}
|
|
986
|
+
function shortenEndpoint(from, to, amount) {
|
|
987
|
+
const dx = to.x - from.x;
|
|
988
|
+
const dy = to.y - from.y;
|
|
989
|
+
const dist = Math.sqrt(dx * dx + dy * dy);
|
|
990
|
+
if (dist < amount * 2) return to;
|
|
991
|
+
return {
|
|
992
|
+
x: to.x - dx / dist * amount,
|
|
993
|
+
y: to.y - dy / dist * amount
|
|
994
|
+
};
|
|
995
|
+
}
|
|
996
|
+
function escapeXml(str) {
|
|
997
|
+
return String(str).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
998
|
+
}
|
|
999
|
+
function resolveStrokeStyle(style) {
|
|
1000
|
+
if (!style) return "";
|
|
1001
|
+
switch (style) {
|
|
1002
|
+
case "dashed":
|
|
1003
|
+
return "10,10";
|
|
1004
|
+
case "dotted":
|
|
1005
|
+
return "2,8";
|
|
1006
|
+
case "solid":
|
|
1007
|
+
default:
|
|
1008
|
+
return "";
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
function initLixScriptBridge() {
|
|
1012
|
+
window.__lixscriptParse = parseLixScript;
|
|
1013
|
+
window.__lixscriptRender = renderLixScript;
|
|
1014
|
+
window.__lixscriptPreview = (source) => {
|
|
1015
|
+
const parsed = parseLixScript(source);
|
|
1016
|
+
return previewLixScript(parsed);
|
|
1017
|
+
};
|
|
1018
|
+
window.__lixscriptExecute = (source) => {
|
|
1019
|
+
const parsed = parseLixScript(source);
|
|
1020
|
+
if (parsed.errors.length > 0) {
|
|
1021
|
+
return { success: false, errors: parsed.errors, shapesCreated: 0 };
|
|
1022
|
+
}
|
|
1023
|
+
return renderLixScript(parsed);
|
|
1024
|
+
};
|
|
1025
|
+
}
|
|
1026
|
+
export {
|
|
1027
|
+
initLixScriptBridge,
|
|
1028
|
+
parseLixScript,
|
|
1029
|
+
previewLixScript,
|
|
1030
|
+
renderLixScript,
|
|
1031
|
+
resolveShapeRefs
|
|
1032
|
+
};
|
|
1033
|
+
//# sourceMappingURL=LixScriptParser-JYWJX375.js.map
|