@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,340 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
isValidExpression,
|
|
4
|
+
parseExpression
|
|
5
|
+
} from "./chunk-HZWLPXFN.js";
|
|
6
|
+
|
|
7
|
+
// src/core/GraphRenderer.js
|
|
8
|
+
var GRAPH_COLORS = [
|
|
9
|
+
"#4A90D9",
|
|
10
|
+
"#E74C3C",
|
|
11
|
+
"#2ECC71",
|
|
12
|
+
"#F39C12",
|
|
13
|
+
"#9B59B6",
|
|
14
|
+
"#1ABC9C",
|
|
15
|
+
"#E67E22",
|
|
16
|
+
"#3498DB",
|
|
17
|
+
"#E91E63",
|
|
18
|
+
"#00BCD4"
|
|
19
|
+
];
|
|
20
|
+
function niceInterval(range) {
|
|
21
|
+
const rough = range / 8;
|
|
22
|
+
const mag = Math.pow(10, Math.floor(Math.log10(rough)));
|
|
23
|
+
const residual = rough / mag;
|
|
24
|
+
let nice;
|
|
25
|
+
if (residual <= 1.5) nice = 1;
|
|
26
|
+
else if (residual <= 3) nice = 2;
|
|
27
|
+
else if (residual <= 7) nice = 5;
|
|
28
|
+
else nice = 10;
|
|
29
|
+
return nice * mag;
|
|
30
|
+
}
|
|
31
|
+
function renderGraphSVG(equations, settings) {
|
|
32
|
+
const {
|
|
33
|
+
xMin = -10,
|
|
34
|
+
xMax = 10,
|
|
35
|
+
yMin = -10,
|
|
36
|
+
yMax = 10,
|
|
37
|
+
showGrid = true,
|
|
38
|
+
width = 600,
|
|
39
|
+
height = 400
|
|
40
|
+
} = settings || {};
|
|
41
|
+
const pad = { top: 20, right: 20, bottom: 35, left: 45 };
|
|
42
|
+
const plotW = width - pad.left - pad.right;
|
|
43
|
+
const plotH = height - pad.top - pad.bottom;
|
|
44
|
+
const xRange = xMax - xMin || 1;
|
|
45
|
+
const yRange = yMax - yMin || 1;
|
|
46
|
+
const toSvgX = (x) => pad.left + (x - xMin) / xRange * plotW;
|
|
47
|
+
const toSvgY = (y) => pad.top + (yMax - y) / yRange * plotH;
|
|
48
|
+
let svg = "";
|
|
49
|
+
svg += `<rect x="0" y="0" width="${width}" height="${height}" fill="#0d1117" rx="8" />`;
|
|
50
|
+
svg += `<rect x="${pad.left}" y="${pad.top}" width="${plotW}" height="${plotH}" fill="#111822" />`;
|
|
51
|
+
const xTick = niceInterval(xRange);
|
|
52
|
+
const yTick = niceInterval(yRange);
|
|
53
|
+
const xStart = Math.ceil(xMin / xTick) * xTick;
|
|
54
|
+
for (let x = xStart; x <= xMax; x += xTick) {
|
|
55
|
+
const sx = toSvgX(x);
|
|
56
|
+
if (sx < pad.left || sx > pad.left + plotW) continue;
|
|
57
|
+
if (showGrid) {
|
|
58
|
+
svg += `<line x1="${sx}" y1="${pad.top}" x2="${sx}" y2="${pad.top + plotH}" stroke="rgba(255,255,255,0.06)" stroke-width="0.5" />`;
|
|
59
|
+
}
|
|
60
|
+
const label = Math.abs(x) < 1e-10 ? "0" : Number.isInteger(x) ? x : x.toFixed(1);
|
|
61
|
+
svg += `<text x="${sx}" y="${pad.top + plotH + 16}" text-anchor="middle" fill="#8b949e" font-size="10" font-family="lixCode, monospace">${label}</text>`;
|
|
62
|
+
}
|
|
63
|
+
const yStart = Math.ceil(yMin / yTick) * yTick;
|
|
64
|
+
for (let y = yStart; y <= yMax; y += yTick) {
|
|
65
|
+
const sy = toSvgY(y);
|
|
66
|
+
if (sy < pad.top || sy > pad.top + plotH) continue;
|
|
67
|
+
if (showGrid) {
|
|
68
|
+
svg += `<line x1="${pad.left}" y1="${sy}" x2="${pad.left + plotW}" y2="${sy}" stroke="rgba(255,255,255,0.06)" stroke-width="0.5" />`;
|
|
69
|
+
}
|
|
70
|
+
const label = Math.abs(y) < 1e-10 ? "0" : Number.isInteger(y) ? y : y.toFixed(1);
|
|
71
|
+
svg += `<text x="${pad.left - 8}" y="${sy + 3}" text-anchor="end" fill="#8b949e" font-size="10" font-family="lixCode, monospace">${label}</text>`;
|
|
72
|
+
}
|
|
73
|
+
if (xMin <= 0 && xMax >= 0) {
|
|
74
|
+
const ax = toSvgX(0);
|
|
75
|
+
svg += `<line x1="${ax}" y1="${pad.top}" x2="${ax}" y2="${pad.top + plotH}" stroke="rgba(255,255,255,0.25)" stroke-width="1" />`;
|
|
76
|
+
}
|
|
77
|
+
if (yMin <= 0 && yMax >= 0) {
|
|
78
|
+
const ay = toSvgY(0);
|
|
79
|
+
svg += `<line x1="${pad.left}" y1="${ay}" x2="${pad.left + plotW}" y2="${ay}" stroke="rgba(255,255,255,0.25)" stroke-width="1" />`;
|
|
80
|
+
}
|
|
81
|
+
svg += `<rect x="${pad.left}" y="${pad.top}" width="${plotW}" height="${plotH}" fill="none" stroke="rgba(255,255,255,0.1)" stroke-width="1" />`;
|
|
82
|
+
const samplesPerPixel = 2;
|
|
83
|
+
const totalSamples = plotW * samplesPerPixel;
|
|
84
|
+
const dx = xRange / totalSamples;
|
|
85
|
+
equations.forEach((eq, eqIdx) => {
|
|
86
|
+
if (!eq.expression || !eq.expression.trim()) return;
|
|
87
|
+
const fn = parseExpression(eq.expression);
|
|
88
|
+
if (!fn) return;
|
|
89
|
+
const color = eq.color || GRAPH_COLORS[eqIdx % GRAPH_COLORS.length];
|
|
90
|
+
let pathData = "";
|
|
91
|
+
let drawing = false;
|
|
92
|
+
for (let i = 0; i <= totalSamples; i++) {
|
|
93
|
+
const x = xMin + i * dx;
|
|
94
|
+
let y;
|
|
95
|
+
try {
|
|
96
|
+
y = fn(x);
|
|
97
|
+
} catch {
|
|
98
|
+
y = NaN;
|
|
99
|
+
}
|
|
100
|
+
if (!isFinite(y) || isNaN(y) || y < yMin - yRange * 5 || y > yMax + yRange * 5) {
|
|
101
|
+
drawing = false;
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
const clampedY = Math.max(yMin - yRange * 0.5, Math.min(yMax + yRange * 0.5, y));
|
|
105
|
+
const sx = toSvgX(x);
|
|
106
|
+
const sy = toSvgY(clampedY);
|
|
107
|
+
if (!drawing) {
|
|
108
|
+
pathData += `M ${sx.toFixed(1)} ${sy.toFixed(1)} `;
|
|
109
|
+
drawing = true;
|
|
110
|
+
} else {
|
|
111
|
+
pathData += `L ${sx.toFixed(1)} ${sy.toFixed(1)} `;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (pathData) {
|
|
115
|
+
svg += `<path d="${pathData.trim()}" fill="none" stroke="${color}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />`;
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
const clipId = "graph-clip-" + Date.now();
|
|
119
|
+
const defs = `<defs><clipPath id="${clipId}"><rect x="${pad.left}" y="${pad.top}" width="${plotW}" height="${plotH}" /></clipPath></defs>`;
|
|
120
|
+
let curves = "";
|
|
121
|
+
equations.forEach((eq, eqIdx) => {
|
|
122
|
+
if (!eq.expression || !eq.expression.trim()) return;
|
|
123
|
+
const fn = parseExpression(eq.expression);
|
|
124
|
+
if (!fn) return;
|
|
125
|
+
const color = eq.color || GRAPH_COLORS[eqIdx % GRAPH_COLORS.length];
|
|
126
|
+
let pathData = "";
|
|
127
|
+
let drawing = false;
|
|
128
|
+
for (let i = 0; i <= totalSamples; i++) {
|
|
129
|
+
const x = xMin + i * dx;
|
|
130
|
+
let y;
|
|
131
|
+
try {
|
|
132
|
+
y = fn(x);
|
|
133
|
+
} catch {
|
|
134
|
+
y = NaN;
|
|
135
|
+
}
|
|
136
|
+
if (!isFinite(y) || isNaN(y)) {
|
|
137
|
+
drawing = false;
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
const sx = toSvgX(x);
|
|
141
|
+
const sy = toSvgY(y);
|
|
142
|
+
if (!drawing) {
|
|
143
|
+
pathData += `M ${sx.toFixed(1)} ${sy.toFixed(1)} `;
|
|
144
|
+
drawing = true;
|
|
145
|
+
} else {
|
|
146
|
+
pathData += `L ${sx.toFixed(1)} ${sy.toFixed(1)} `;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (pathData) {
|
|
150
|
+
curves += `<path d="${pathData.trim()}" fill="none" stroke="${color}" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" />`;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
let legendY = pad.top + 12;
|
|
154
|
+
let legend = "";
|
|
155
|
+
equations.forEach((eq, eqIdx) => {
|
|
156
|
+
if (!eq.expression || !eq.expression.trim()) return;
|
|
157
|
+
const color = eq.color || GRAPH_COLORS[eqIdx % GRAPH_COLORS.length];
|
|
158
|
+
legend += `<circle cx="${pad.left + 12}" cy="${legendY}" r="4" fill="${color}" />`;
|
|
159
|
+
legend += `<text x="${pad.left + 22}" y="${legendY + 3}" fill="${color}" font-size="11" font-family="lixCode, monospace">${escapeXml(eq.expression)}</text>`;
|
|
160
|
+
legendY += 18;
|
|
161
|
+
});
|
|
162
|
+
let cleanSvg = "";
|
|
163
|
+
cleanSvg += `<rect x="0" y="0" width="${width}" height="${height}" fill="#0d1117" rx="8" />`;
|
|
164
|
+
cleanSvg += `<rect x="${pad.left}" y="${pad.top}" width="${plotW}" height="${plotH}" fill="#111822" />`;
|
|
165
|
+
for (let x = xStart; x <= xMax; x += xTick) {
|
|
166
|
+
const sx = toSvgX(x);
|
|
167
|
+
if (sx < pad.left || sx > pad.left + plotW) continue;
|
|
168
|
+
if (showGrid) {
|
|
169
|
+
cleanSvg += `<line x1="${sx}" y1="${pad.top}" x2="${sx}" y2="${pad.top + plotH}" stroke="rgba(255,255,255,0.06)" stroke-width="0.5" />`;
|
|
170
|
+
}
|
|
171
|
+
const label = Math.abs(x) < 1e-10 ? "0" : Number.isInteger(x) ? x : x.toFixed(1);
|
|
172
|
+
cleanSvg += `<text x="${sx}" y="${pad.top + plotH + 16}" text-anchor="middle" fill="#8b949e" font-size="10" font-family="lixCode, monospace">${label}</text>`;
|
|
173
|
+
}
|
|
174
|
+
for (let y = yStart; y <= yMax; y += yTick) {
|
|
175
|
+
const sy = toSvgY(y);
|
|
176
|
+
if (sy < pad.top || sy > pad.top + plotH) continue;
|
|
177
|
+
if (showGrid) {
|
|
178
|
+
cleanSvg += `<line x1="${pad.left}" y1="${sy}" x2="${pad.left + plotW}" y2="${sy}" stroke="rgba(255,255,255,0.06)" stroke-width="0.5" />`;
|
|
179
|
+
}
|
|
180
|
+
const label = Math.abs(y) < 1e-10 ? "0" : Number.isInteger(y) ? y : y.toFixed(1);
|
|
181
|
+
cleanSvg += `<text x="${pad.left - 8}" y="${sy + 3}" text-anchor="end" fill="#8b949e" font-size="10" font-family="lixCode, monospace">${label}</text>`;
|
|
182
|
+
}
|
|
183
|
+
if (xMin <= 0 && xMax >= 0) {
|
|
184
|
+
const ax = toSvgX(0);
|
|
185
|
+
cleanSvg += `<line x1="${ax}" y1="${pad.top}" x2="${ax}" y2="${pad.top + plotH}" stroke="rgba(255,255,255,0.25)" stroke-width="1" />`;
|
|
186
|
+
}
|
|
187
|
+
if (yMin <= 0 && yMax >= 0) {
|
|
188
|
+
const ay = toSvgY(0);
|
|
189
|
+
cleanSvg += `<line x1="${pad.left}" y1="${ay}" x2="${pad.left + plotW}" y2="${ay}" stroke="rgba(255,255,255,0.25)" stroke-width="1" />`;
|
|
190
|
+
}
|
|
191
|
+
cleanSvg += `<rect x="${pad.left}" y="${pad.top}" width="${plotW}" height="${plotH}" fill="none" stroke="rgba(255,255,255,0.1)" stroke-width="1" />`;
|
|
192
|
+
cleanSvg += `<g clip-path="url(#${clipId})">${curves}</g>`;
|
|
193
|
+
cleanSvg += legend;
|
|
194
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">${defs}${cleanSvg}</svg>`;
|
|
195
|
+
}
|
|
196
|
+
function renderGraphPreviewSVG(equations, settings) {
|
|
197
|
+
return renderGraphSVG(equations, {
|
|
198
|
+
...settings,
|
|
199
|
+
width: 520,
|
|
200
|
+
height: 380
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
function escapeXml(str) {
|
|
204
|
+
return String(str).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// src/core/GraphEngine.js
|
|
208
|
+
var NS = "http://www.w3.org/2000/svg";
|
|
209
|
+
var GRAPH_WIDTH = 600;
|
|
210
|
+
var GRAPH_HEIGHT = 420;
|
|
211
|
+
function renderGraphOnCanvas(equations, settings) {
|
|
212
|
+
if (!equations || equations.length === 0) return false;
|
|
213
|
+
if (!window.svg || !window.Frame) {
|
|
214
|
+
console.error("[GraphEngine] Engine not initialized");
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
const svgMarkup = renderGraphSVG(equations, {
|
|
218
|
+
...settings,
|
|
219
|
+
width: GRAPH_WIDTH,
|
|
220
|
+
height: GRAPH_HEIGHT
|
|
221
|
+
});
|
|
222
|
+
if (!svgMarkup) return false;
|
|
223
|
+
const vb = window.currentViewBox || { x: 0, y: 0, width: window.innerWidth, height: window.innerHeight };
|
|
224
|
+
const vcx = vb.x + vb.width / 2;
|
|
225
|
+
const vcy = vb.y + vb.height / 2;
|
|
226
|
+
const frameW = GRAPH_WIDTH + 40;
|
|
227
|
+
const frameH = GRAPH_HEIGHT + 40;
|
|
228
|
+
const frameX = vcx - frameW / 2;
|
|
229
|
+
const frameY = vcy - frameH / 2;
|
|
230
|
+
const eqLabels = equations.filter((eq) => eq.expression && eq.expression.trim()).map((eq) => eq.expression.trim()).slice(0, 3);
|
|
231
|
+
const title = eqLabels.length > 0 ? "Graph: " + eqLabels.join(", ") : "Graph";
|
|
232
|
+
try {
|
|
233
|
+
const parser = new DOMParser();
|
|
234
|
+
const doc = parser.parseFromString(svgMarkup, "image/svg+xml");
|
|
235
|
+
const svgEl = doc.querySelector("svg");
|
|
236
|
+
if (!svgEl) return false;
|
|
237
|
+
const graphGroup = document.createElementNS(NS, "g");
|
|
238
|
+
graphGroup.setAttribute("data-type", "graph-group");
|
|
239
|
+
graphGroup.setAttribute("transform", `translate(${frameX + 20}, ${frameY + 20})`);
|
|
240
|
+
const defs = svgEl.querySelector("defs");
|
|
241
|
+
if (defs) {
|
|
242
|
+
const defsClone = defs.cloneNode(true);
|
|
243
|
+
window.svg.querySelector("defs")?.appendChild(defsClone.firstChild) || window.svg.insertBefore(defsClone, window.svg.firstChild);
|
|
244
|
+
}
|
|
245
|
+
while (svgEl.childNodes.length > 0) {
|
|
246
|
+
const child = svgEl.childNodes[0];
|
|
247
|
+
if (child.nodeName === "defs") {
|
|
248
|
+
svgEl.removeChild(child);
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
graphGroup.appendChild(child);
|
|
252
|
+
}
|
|
253
|
+
window.svg.appendChild(graphGroup);
|
|
254
|
+
const graphShape = {
|
|
255
|
+
shapeName: "graph",
|
|
256
|
+
// first-class shapeName
|
|
257
|
+
shapeID: `graph-${Date.now().toString(36)}-${Math.floor(Math.random() * 1e4)}`,
|
|
258
|
+
group: graphGroup,
|
|
259
|
+
element: graphGroup,
|
|
260
|
+
x: frameX + 20,
|
|
261
|
+
y: frameY + 20,
|
|
262
|
+
width: GRAPH_WIDTH,
|
|
263
|
+
height: GRAPH_HEIGHT,
|
|
264
|
+
rotation: 0,
|
|
265
|
+
isSelected: false,
|
|
266
|
+
_selectionRect: null,
|
|
267
|
+
_graphData: {
|
|
268
|
+
equations: equations.map((eq) => ({ expression: eq.expression, color: eq.color })),
|
|
269
|
+
settings: { ...settings }
|
|
270
|
+
},
|
|
271
|
+
// ── Shape API the engine relies on ────────────────────────
|
|
272
|
+
contains(px, py) {
|
|
273
|
+
return px >= this.x && px <= this.x + this.width && py >= this.y && py <= this.y + this.height;
|
|
274
|
+
},
|
|
275
|
+
move(dx, dy) {
|
|
276
|
+
this.x += dx;
|
|
277
|
+
this.y += dy;
|
|
278
|
+
this.group.setAttribute("transform", `translate(${this.x}, ${this.y})`);
|
|
279
|
+
this._updateSelectionRect();
|
|
280
|
+
},
|
|
281
|
+
selectShape() {
|
|
282
|
+
this.isSelected = true;
|
|
283
|
+
if (this._selectionRect) return;
|
|
284
|
+
const r = document.createElementNS(NS, "rect");
|
|
285
|
+
r.setAttribute("fill", "none");
|
|
286
|
+
r.setAttribute("stroke", "#9b7bf7");
|
|
287
|
+
r.setAttribute("stroke-width", "1.5");
|
|
288
|
+
r.setAttribute("stroke-dasharray", "4 3");
|
|
289
|
+
r.setAttribute("pointer-events", "none");
|
|
290
|
+
window.svg.appendChild(r);
|
|
291
|
+
this._selectionRect = r;
|
|
292
|
+
this._updateSelectionRect();
|
|
293
|
+
},
|
|
294
|
+
removeSelection() {
|
|
295
|
+
this.isSelected = false;
|
|
296
|
+
if (this._selectionRect && this._selectionRect.parentNode) {
|
|
297
|
+
this._selectionRect.parentNode.removeChild(this._selectionRect);
|
|
298
|
+
}
|
|
299
|
+
this._selectionRect = null;
|
|
300
|
+
},
|
|
301
|
+
_updateSelectionRect() {
|
|
302
|
+
if (!this._selectionRect) return;
|
|
303
|
+
const pad = 4;
|
|
304
|
+
this._selectionRect.setAttribute("x", this.x - pad);
|
|
305
|
+
this._selectionRect.setAttribute("y", this.y - pad);
|
|
306
|
+
this._selectionRect.setAttribute("width", this.width + pad * 2);
|
|
307
|
+
this._selectionRect.setAttribute("height", this.height + pad * 2);
|
|
308
|
+
},
|
|
309
|
+
updateAttachedArrows() {
|
|
310
|
+
if (typeof window.updateAttachedArrows === "function") {
|
|
311
|
+
window.updateAttachedArrows(this);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
window.shapes.push(graphShape);
|
|
316
|
+
if (window.pushCreateAction) window.pushCreateAction(graphShape);
|
|
317
|
+
window.currentShape = graphShape;
|
|
318
|
+
graphShape.selectShape();
|
|
319
|
+
} catch (err) {
|
|
320
|
+
console.error("[GraphEngine] SVG insertion failed:", err);
|
|
321
|
+
return false;
|
|
322
|
+
}
|
|
323
|
+
return true;
|
|
324
|
+
}
|
|
325
|
+
function initGraphEngine() {
|
|
326
|
+
window.__graphPreview = (equations, settings) => {
|
|
327
|
+
return renderGraphPreviewSVG(equations, settings);
|
|
328
|
+
};
|
|
329
|
+
window.__graphRenderer = renderGraphOnCanvas;
|
|
330
|
+
window.__graphParser = (expr) => {
|
|
331
|
+
const fn = parseExpression(expr);
|
|
332
|
+
return fn ? true : false;
|
|
333
|
+
};
|
|
334
|
+
window.__graphValidate = isValidExpression;
|
|
335
|
+
window.__graphColors = GRAPH_COLORS;
|
|
336
|
+
}
|
|
337
|
+
export {
|
|
338
|
+
initGraphEngine
|
|
339
|
+
};
|
|
340
|
+
//# sourceMappingURL=GraphEngine-QE5B2PMR.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/core/GraphRenderer.js", "../../src/core/GraphEngine.js"],
|
|
4
|
+
"sourcesContent": ["/* eslint-disable */\n/**\n * GraphRenderer - Renders mathematical equations as SVG graphs.\n * Produces axes, grid, tick labels, and equation curves.\n */\n\nimport { parseExpression } from './GraphMathParser.js';\n\nconst GRAPH_COLORS = [\n '#4A90D9', '#E74C3C', '#2ECC71', '#F39C12', '#9B59B6',\n '#1ABC9C', '#E67E22', '#3498DB', '#E91E63', '#00BCD4',\n];\n\n/**\n * Calculate nice tick intervals for a given range.\n */\nfunction niceInterval(range) {\n const rough = range / 8;\n const mag = Math.pow(10, Math.floor(Math.log10(rough)));\n const residual = rough / mag;\n let nice;\n if (residual <= 1.5) nice = 1;\n else if (residual <= 3) nice = 2;\n else if (residual <= 7) nice = 5;\n else nice = 10;\n return nice * mag;\n}\n\n/**\n * Render graph as SVG markup string.\n * @param {Array} equations - [{expression: string, color: string}]\n * @param {Object} settings - {xMin, xMax, yMin, yMax, showGrid, width, height}\n * @returns {string} SVG markup\n */\nexport function renderGraphSVG(equations, settings) {\n const {\n xMin = -10, xMax = 10,\n yMin = -10, yMax = 10,\n showGrid = true,\n width = 600, height = 400,\n } = settings || {};\n\n const pad = { top: 20, right: 20, bottom: 35, left: 45 };\n const plotW = width - pad.left - pad.right;\n const plotH = height - pad.top - pad.bottom;\n const xRange = xMax - xMin || 1;\n const yRange = yMax - yMin || 1;\n\n // Coordinate transforms\n const toSvgX = (x) => pad.left + ((x - xMin) / xRange) * plotW;\n const toSvgY = (y) => pad.top + ((yMax - y) / yRange) * plotH;\n\n let svg = '';\n\n // Background\n svg += `<rect x=\"0\" y=\"0\" width=\"${width}\" height=\"${height}\" fill=\"#0d1117\" rx=\"8\" />`;\n svg += `<rect x=\"${pad.left}\" y=\"${pad.top}\" width=\"${plotW}\" height=\"${plotH}\" fill=\"#111822\" />`;\n\n // Grid & ticks\n const xTick = niceInterval(xRange);\n const yTick = niceInterval(yRange);\n\n // Vertical grid lines + x labels\n const xStart = Math.ceil(xMin / xTick) * xTick;\n for (let x = xStart; x <= xMax; x += xTick) {\n const sx = toSvgX(x);\n if (sx < pad.left || sx > pad.left + plotW) continue;\n if (showGrid) {\n svg += `<line x1=\"${sx}\" y1=\"${pad.top}\" x2=\"${sx}\" y2=\"${pad.top + plotH}\" stroke=\"rgba(255,255,255,0.06)\" stroke-width=\"0.5\" />`;\n }\n // Tick label\n const label = Math.abs(x) < 1e-10 ? '0' : (Number.isInteger(x) ? x : x.toFixed(1));\n svg += `<text x=\"${sx}\" y=\"${pad.top + plotH + 16}\" text-anchor=\"middle\" fill=\"#8b949e\" font-size=\"10\" font-family=\"lixCode, monospace\">${label}</text>`;\n }\n\n // Horizontal grid lines + y labels\n const yStart = Math.ceil(yMin / yTick) * yTick;\n for (let y = yStart; y <= yMax; y += yTick) {\n const sy = toSvgY(y);\n if (sy < pad.top || sy > pad.top + plotH) continue;\n if (showGrid) {\n svg += `<line x1=\"${pad.left}\" y1=\"${sy}\" x2=\"${pad.left + plotW}\" y2=\"${sy}\" stroke=\"rgba(255,255,255,0.06)\" stroke-width=\"0.5\" />`;\n }\n const label = Math.abs(y) < 1e-10 ? '0' : (Number.isInteger(y) ? y : y.toFixed(1));\n svg += `<text x=\"${pad.left - 8}\" y=\"${sy + 3}\" text-anchor=\"end\" fill=\"#8b949e\" font-size=\"10\" font-family=\"lixCode, monospace\">${label}</text>`;\n }\n\n // Axes\n if (xMin <= 0 && xMax >= 0) {\n const ax = toSvgX(0);\n svg += `<line x1=\"${ax}\" y1=\"${pad.top}\" x2=\"${ax}\" y2=\"${pad.top + plotH}\" stroke=\"rgba(255,255,255,0.25)\" stroke-width=\"1\" />`;\n }\n if (yMin <= 0 && yMax >= 0) {\n const ay = toSvgY(0);\n svg += `<line x1=\"${pad.left}\" y1=\"${ay}\" x2=\"${pad.left + plotW}\" y2=\"${ay}\" stroke=\"rgba(255,255,255,0.25)\" stroke-width=\"1\" />`;\n }\n\n // Plot border\n svg += `<rect x=\"${pad.left}\" y=\"${pad.top}\" width=\"${plotW}\" height=\"${plotH}\" fill=\"none\" stroke=\"rgba(255,255,255,0.1)\" stroke-width=\"1\" />`;\n\n // Equations\n const samplesPerPixel = 2;\n const totalSamples = plotW * samplesPerPixel;\n const dx = xRange / totalSamples;\n\n equations.forEach((eq, eqIdx) => {\n if (!eq.expression || !eq.expression.trim()) return;\n\n const fn = parseExpression(eq.expression);\n if (!fn) return;\n\n const color = eq.color || GRAPH_COLORS[eqIdx % GRAPH_COLORS.length];\n let pathData = '';\n let drawing = false;\n\n for (let i = 0; i <= totalSamples; i++) {\n const x = xMin + i * dx;\n let y;\n try { y = fn(x); } catch { y = NaN; }\n\n if (!isFinite(y) || isNaN(y) || y < yMin - yRange * 5 || y > yMax + yRange * 5) {\n drawing = false;\n continue;\n }\n\n // Clamp to plot area for rendering\n const clampedY = Math.max(yMin - yRange * 0.5, Math.min(yMax + yRange * 0.5, y));\n const sx = toSvgX(x);\n const sy = toSvgY(clampedY);\n\n if (!drawing) {\n pathData += `M ${sx.toFixed(1)} ${sy.toFixed(1)} `;\n drawing = true;\n } else {\n pathData += `L ${sx.toFixed(1)} ${sy.toFixed(1)} `;\n }\n }\n\n if (pathData) {\n svg += `<path d=\"${pathData.trim()}\" fill=\"none\" stroke=\"${color}\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" />`;\n }\n });\n\n // Clip path for plot area\n const clipId = 'graph-clip-' + Date.now();\n const defs = `<defs><clipPath id=\"${clipId}\"><rect x=\"${pad.left}\" y=\"${pad.top}\" width=\"${plotW}\" height=\"${plotH}\" /></clipPath></defs>`;\n\n // Re-wrap: curves should be clipped\n // Rebuild with clip group\n let curves = '';\n equations.forEach((eq, eqIdx) => {\n if (!eq.expression || !eq.expression.trim()) return;\n const fn = parseExpression(eq.expression);\n if (!fn) return;\n\n const color = eq.color || GRAPH_COLORS[eqIdx % GRAPH_COLORS.length];\n let pathData = '';\n let drawing = false;\n\n for (let i = 0; i <= totalSamples; i++) {\n const x = xMin + i * dx;\n let y;\n try { y = fn(x); } catch { y = NaN; }\n\n if (!isFinite(y) || isNaN(y)) { drawing = false; continue; }\n\n const sx = toSvgX(x);\n const sy = toSvgY(y);\n\n if (!drawing) {\n pathData += `M ${sx.toFixed(1)} ${sy.toFixed(1)} `;\n drawing = true;\n } else {\n pathData += `L ${sx.toFixed(1)} ${sy.toFixed(1)} `;\n }\n }\n\n if (pathData) {\n curves += `<path d=\"${pathData.trim()}\" fill=\"none\" stroke=\"${color}\" stroke-width=\"2.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\" />`;\n }\n });\n\n // Equation legend\n let legendY = pad.top + 12;\n let legend = '';\n equations.forEach((eq, eqIdx) => {\n if (!eq.expression || !eq.expression.trim()) return;\n const color = eq.color || GRAPH_COLORS[eqIdx % GRAPH_COLORS.length];\n legend += `<circle cx=\"${pad.left + 12}\" cy=\"${legendY}\" r=\"4\" fill=\"${color}\" />`;\n legend += `<text x=\"${pad.left + 22}\" y=\"${legendY + 3}\" fill=\"${color}\" font-size=\"11\" font-family=\"lixCode, monospace\">${escapeXml(eq.expression)}</text>`;\n legendY += 18;\n });\n\n // Remove the non-clipped curves from svg (we added them above for building)\n // Rebuild cleanly\n let cleanSvg = '';\n cleanSvg += `<rect x=\"0\" y=\"0\" width=\"${width}\" height=\"${height}\" fill=\"#0d1117\" rx=\"8\" />`;\n cleanSvg += `<rect x=\"${pad.left}\" y=\"${pad.top}\" width=\"${plotW}\" height=\"${plotH}\" fill=\"#111822\" />`;\n\n // Grid + ticks (re-add)\n for (let x = xStart; x <= xMax; x += xTick) {\n const sx = toSvgX(x);\n if (sx < pad.left || sx > pad.left + plotW) continue;\n if (showGrid) {\n cleanSvg += `<line x1=\"${sx}\" y1=\"${pad.top}\" x2=\"${sx}\" y2=\"${pad.top + plotH}\" stroke=\"rgba(255,255,255,0.06)\" stroke-width=\"0.5\" />`;\n }\n const label = Math.abs(x) < 1e-10 ? '0' : (Number.isInteger(x) ? x : x.toFixed(1));\n cleanSvg += `<text x=\"${sx}\" y=\"${pad.top + plotH + 16}\" text-anchor=\"middle\" fill=\"#8b949e\" font-size=\"10\" font-family=\"lixCode, monospace\">${label}</text>`;\n }\n for (let y = yStart; y <= yMax; y += yTick) {\n const sy = toSvgY(y);\n if (sy < pad.top || sy > pad.top + plotH) continue;\n if (showGrid) {\n cleanSvg += `<line x1=\"${pad.left}\" y1=\"${sy}\" x2=\"${pad.left + plotW}\" y2=\"${sy}\" stroke=\"rgba(255,255,255,0.06)\" stroke-width=\"0.5\" />`;\n }\n const label = Math.abs(y) < 1e-10 ? '0' : (Number.isInteger(y) ? y : y.toFixed(1));\n cleanSvg += `<text x=\"${pad.left - 8}\" y=\"${sy + 3}\" text-anchor=\"end\" fill=\"#8b949e\" font-size=\"10\" font-family=\"lixCode, monospace\">${label}</text>`;\n }\n // Axes\n if (xMin <= 0 && xMax >= 0) {\n const ax = toSvgX(0);\n cleanSvg += `<line x1=\"${ax}\" y1=\"${pad.top}\" x2=\"${ax}\" y2=\"${pad.top + plotH}\" stroke=\"rgba(255,255,255,0.25)\" stroke-width=\"1\" />`;\n }\n if (yMin <= 0 && yMax >= 0) {\n const ay = toSvgY(0);\n cleanSvg += `<line x1=\"${pad.left}\" y1=\"${ay}\" x2=\"${pad.left + plotW}\" y2=\"${ay}\" stroke=\"rgba(255,255,255,0.25)\" stroke-width=\"1\" />`;\n }\n // Plot border\n cleanSvg += `<rect x=\"${pad.left}\" y=\"${pad.top}\" width=\"${plotW}\" height=\"${plotH}\" fill=\"none\" stroke=\"rgba(255,255,255,0.1)\" stroke-width=\"1\" />`;\n\n // Clipped curves\n cleanSvg += `<g clip-path=\"url(#${clipId})\">${curves}</g>`;\n\n // Legend\n cleanSvg += legend;\n\n return `<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"${width}\" height=\"${height}\" viewBox=\"0 0 ${width} ${height}\">${defs}${cleanSvg}</svg>`;\n}\n\n/**\n * Generate a preview SVG for the modal.\n */\nexport function renderGraphPreviewSVG(equations, settings) {\n return renderGraphSVG(equations, {\n ...settings,\n width: 520,\n height: 380,\n });\n}\n\nfunction escapeXml(str) {\n return String(str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/\"/g, '"');\n}\n\nexport { GRAPH_COLORS };\n", "/* eslint-disable */\n/**\n * GraphEngine - Bridge between graph rendering and the sketch canvas.\n * Creates Frames containing rendered graph SVG elements.\n */\n\nimport { parseExpression, isValidExpression } from './GraphMathParser.js';\nimport { renderGraphSVG, renderGraphPreviewSVG, GRAPH_COLORS } from './GraphRenderer.js';\n\nconst NS = 'http://www.w3.org/2000/svg';\nconst GRAPH_WIDTH = 600;\nconst GRAPH_HEIGHT = 420;\n\n/**\n * Place a graph on the canvas inside a Frame.\n */\nfunction renderGraphOnCanvas(equations, settings) {\n if (!equations || equations.length === 0) return false;\n if (!window.svg || !window.Frame) {\n console.error('[GraphEngine] Engine not initialized');\n return false;\n }\n\n // Generate full-size SVG\n const svgMarkup = renderGraphSVG(equations, {\n ...settings,\n width: GRAPH_WIDTH,\n height: GRAPH_HEIGHT,\n });\n if (!svgMarkup) return false;\n\n // Viewport center\n const vb = window.currentViewBox || { x: 0, y: 0, width: window.innerWidth, height: window.innerHeight };\n const vcx = vb.x + vb.width / 2;\n const vcy = vb.y + vb.height / 2;\n\n const frameW = GRAPH_WIDTH + 40;\n const frameH = GRAPH_HEIGHT + 40;\n const frameX = vcx - frameW / 2;\n const frameY = vcy - frameH / 2;\n\n // Build title from equations\n const eqLabels = equations\n .filter(eq => eq.expression && eq.expression.trim())\n .map(eq => eq.expression.trim())\n .slice(0, 3);\n const title = eqLabels.length > 0\n ? 'Graph: ' + eqLabels.join(', ')\n : 'Graph';\n\n // Phase 5 (issue #22): no wrapper frame. The graph is conceptually a\n // single rendering \u2014 axes, grid, curves all interlocked \u2014 so we don't\n // split it into per-curve shapes. Instead the graph becomes ONE\n // first-class shape on the canvas: a `graphShape` that implements the\n // shape API the engine relies on (contains / selectShape / etc.) so\n // it can be selected, dragged, attached to by arrows, picked up by\n // the rect-drag \u2014 exactly like a user-drawn shape.\n try {\n const parser = new DOMParser();\n const doc = parser.parseFromString(svgMarkup, 'image/svg+xml');\n const svgEl = doc.querySelector('svg');\n if (!svgEl) return false;\n\n const graphGroup = document.createElementNS(NS, 'g');\n graphGroup.setAttribute('data-type', 'graph-group');\n graphGroup.setAttribute('transform', `translate(${frameX + 20}, ${frameY + 20})`);\n\n // Copy defs (clip paths)\n const defs = svgEl.querySelector('defs');\n if (defs) {\n const defsClone = defs.cloneNode(true);\n window.svg.querySelector('defs')?.appendChild(defsClone.firstChild) ||\n window.svg.insertBefore(defsClone, window.svg.firstChild);\n }\n\n while (svgEl.childNodes.length > 0) {\n const child = svgEl.childNodes[0];\n if (child.nodeName === 'defs') { svgEl.removeChild(child); continue; }\n graphGroup.appendChild(child);\n }\n window.svg.appendChild(graphGroup);\n\n const graphShape = {\n shapeName: 'graph', // first-class shapeName\n shapeID: `graph-${Date.now().toString(36)}-${Math.floor(Math.random() * 10000)}`,\n group: graphGroup,\n element: graphGroup,\n x: frameX + 20,\n y: frameY + 20,\n width: GRAPH_WIDTH,\n height: GRAPH_HEIGHT,\n rotation: 0,\n isSelected: false,\n _selectionRect: null,\n _graphData: {\n equations: equations.map(eq => ({ expression: eq.expression, color: eq.color })),\n settings: { ...settings },\n },\n\n // \u2500\u2500 Shape API the engine relies on \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n contains(px, py) {\n return px >= this.x && px <= this.x + this.width\n && py >= this.y && py <= this.y + this.height;\n },\n move(dx, dy) {\n this.x += dx; this.y += dy;\n this.group.setAttribute('transform', `translate(${this.x}, ${this.y})`);\n this._updateSelectionRect();\n },\n selectShape() {\n this.isSelected = true;\n if (this._selectionRect) return;\n const r = document.createElementNS(NS, 'rect');\n r.setAttribute('fill', 'none');\n r.setAttribute('stroke', '#9b7bf7');\n r.setAttribute('stroke-width', '1.5');\n r.setAttribute('stroke-dasharray', '4 3');\n r.setAttribute('pointer-events', 'none');\n window.svg.appendChild(r);\n this._selectionRect = r;\n this._updateSelectionRect();\n },\n removeSelection() {\n this.isSelected = false;\n if (this._selectionRect && this._selectionRect.parentNode) {\n this._selectionRect.parentNode.removeChild(this._selectionRect);\n }\n this._selectionRect = null;\n },\n _updateSelectionRect() {\n if (!this._selectionRect) return;\n const pad = 4;\n this._selectionRect.setAttribute('x', this.x - pad);\n this._selectionRect.setAttribute('y', this.y - pad);\n this._selectionRect.setAttribute('width', this.width + pad * 2);\n this._selectionRect.setAttribute('height', this.height + pad * 2);\n },\n updateAttachedArrows() {\n if (typeof window.updateAttachedArrows === 'function') {\n window.updateAttachedArrows(this);\n }\n },\n };\n\n window.shapes.push(graphShape);\n if (window.pushCreateAction) window.pushCreateAction(graphShape);\n\n // Auto-select so the user sees something landed.\n window.currentShape = graphShape;\n graphShape.selectShape();\n } catch (err) {\n console.error('[GraphEngine] SVG insertion failed:', err);\n return false;\n }\n\n return true;\n}\n\n/**\n * Initialize the graph engine \u2014 expose bridge functions on window.\n */\nexport function initGraphEngine() {\n window.__graphPreview = (equations, settings) => {\n return renderGraphPreviewSVG(equations, settings);\n };\n window.__graphRenderer = renderGraphOnCanvas;\n window.__graphParser = (expr) => {\n const fn = parseExpression(expr);\n return fn ? true : false;\n };\n window.__graphValidate = isValidExpression;\n window.__graphColors = GRAPH_COLORS;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;AAQA,IAAM,eAAe;AAAA,EACjB;AAAA,EAAW;AAAA,EAAW;AAAA,EAAW;AAAA,EAAW;AAAA,EAC5C;AAAA,EAAW;AAAA,EAAW;AAAA,EAAW;AAAA,EAAW;AAChD;AAKA,SAAS,aAAa,OAAO;AACzB,QAAM,QAAQ,QAAQ;AACtB,QAAM,MAAM,KAAK,IAAI,IAAI,KAAK,MAAM,KAAK,MAAM,KAAK,CAAC,CAAC;AACtD,QAAM,WAAW,QAAQ;AACzB,MAAI;AACJ,MAAI,YAAY,IAAK,QAAO;AAAA,WACnB,YAAY,EAAG,QAAO;AAAA,WACtB,YAAY,EAAG,QAAO;AAAA,MAC1B,QAAO;AACZ,SAAO,OAAO;AAClB;AAQO,SAAS,eAAe,WAAW,UAAU;AAChD,QAAM;AAAA,IACF,OAAO;AAAA,IAAK,OAAO;AAAA,IACnB,OAAO;AAAA,IAAK,OAAO;AAAA,IACnB,WAAW;AAAA,IACX,QAAQ;AAAA,IAAK,SAAS;AAAA,EAC1B,IAAI,YAAY,CAAC;AAEjB,QAAM,MAAM,EAAE,KAAK,IAAI,OAAO,IAAI,QAAQ,IAAI,MAAM,GAAG;AACvD,QAAM,QAAQ,QAAQ,IAAI,OAAO,IAAI;AACrC,QAAM,QAAQ,SAAS,IAAI,MAAM,IAAI;AACrC,QAAM,SAAS,OAAO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BAAkB;AACzB,SAAO,gBAAgB;AAC3B;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/core/LayerOrder.js
|
|
4
|
+
function bringForward(shape) {
|
|
5
|
+
const shapes = window.shapes;
|
|
6
|
+
if (!shapes) return;
|
|
7
|
+
const idx = shapes.indexOf(shape);
|
|
8
|
+
if (idx < 0 || idx >= shapes.length - 1) return;
|
|
9
|
+
[shapes[idx], shapes[idx + 1]] = [shapes[idx + 1], shapes[idx]];
|
|
10
|
+
const el = shape.group || shape.element;
|
|
11
|
+
const nextEl = shapes[idx].group || shapes[idx].element;
|
|
12
|
+
if (el && nextEl && el.parentNode) {
|
|
13
|
+
if (nextEl.nextSibling) {
|
|
14
|
+
el.parentNode.insertBefore(el, nextEl.nextSibling);
|
|
15
|
+
} else {
|
|
16
|
+
el.parentNode.appendChild(el);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function sendBackward(shape) {
|
|
21
|
+
const shapes = window.shapes;
|
|
22
|
+
if (!shapes) return;
|
|
23
|
+
const idx = shapes.indexOf(shape);
|
|
24
|
+
if (idx <= 0) return;
|
|
25
|
+
[shapes[idx], shapes[idx - 1]] = [shapes[idx - 1], shapes[idx]];
|
|
26
|
+
const el = shape.group || shape.element;
|
|
27
|
+
const prevEl = shapes[idx].group || shapes[idx].element;
|
|
28
|
+
if (el && prevEl && el.parentNode) {
|
|
29
|
+
el.parentNode.insertBefore(el, prevEl);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function bringToFront(shape) {
|
|
33
|
+
const shapes = window.shapes;
|
|
34
|
+
if (!shapes) return;
|
|
35
|
+
const idx = shapes.indexOf(shape);
|
|
36
|
+
if (idx < 0) return;
|
|
37
|
+
shapes.splice(idx, 1);
|
|
38
|
+
shapes.push(shape);
|
|
39
|
+
const el = shape.group || shape.element;
|
|
40
|
+
if (el && el.parentNode) {
|
|
41
|
+
el.parentNode.appendChild(el);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function sendToBack(shape) {
|
|
45
|
+
const shapes = window.shapes;
|
|
46
|
+
if (!shapes) return;
|
|
47
|
+
const idx = shapes.indexOf(shape);
|
|
48
|
+
if (idx < 0) return;
|
|
49
|
+
shapes.splice(idx, 1);
|
|
50
|
+
shapes.unshift(shape);
|
|
51
|
+
const el = shape.group || shape.element;
|
|
52
|
+
if (el && el.parentNode) {
|
|
53
|
+
el.parentNode.insertBefore(el, el.parentNode.firstChild);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function initLayerOrder() {
|
|
57
|
+
window.__layerOrder = { bringForward, sendBackward, bringToFront, sendToBack };
|
|
58
|
+
}
|
|
59
|
+
export {
|
|
60
|
+
bringForward,
|
|
61
|
+
bringToFront,
|
|
62
|
+
initLayerOrder,
|
|
63
|
+
sendBackward,
|
|
64
|
+
sendToBack
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=LayerOrder-XCHF4MSS.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/core/LayerOrder.js"],
|
|
4
|
+
"sourcesContent": ["/* eslint-disable */\n/**\n * LayerOrder - Controls z-ordering of shapes on the SVG canvas.\n * Shapes are ordered by their position in window.shapes[] and their DOM order in the SVG.\n */\n\n/**\n * Move a shape one layer forward (closer to top).\n */\nexport function bringForward(shape) {\n const shapes = window.shapes;\n if (!shapes) return;\n const idx = shapes.indexOf(shape);\n if (idx < 0 || idx >= shapes.length - 1) return;\n\n // Swap in array\n [shapes[idx], shapes[idx + 1]] = [shapes[idx + 1], shapes[idx]];\n\n // Move in DOM \u2014 insert after the next sibling\n const el = shape.group || shape.element;\n const nextEl = shapes[idx].group || shapes[idx].element; // the shape that was swapped down\n if (el && nextEl && el.parentNode) {\n // el should come after nextEl in DOM\n if (nextEl.nextSibling) {\n el.parentNode.insertBefore(el, nextEl.nextSibling);\n } else {\n el.parentNode.appendChild(el);\n }\n }\n}\n\n/**\n * Move a shape one layer backward (closer to bottom).\n */\nexport function sendBackward(shape) {\n const shapes = window.shapes;\n if (!shapes) return;\n const idx = shapes.indexOf(shape);\n if (idx <= 0) return;\n\n // Swap in array\n [shapes[idx], shapes[idx - 1]] = [shapes[idx - 1], shapes[idx]];\n\n // Move in DOM \u2014 insert before the previous sibling\n const el = shape.group || shape.element;\n const prevEl = shapes[idx].group || shapes[idx].element;\n if (el && prevEl && el.parentNode) {\n el.parentNode.insertBefore(el, prevEl);\n }\n}\n\n/**\n * Bring shape to the very front.\n */\nexport function bringToFront(shape) {\n const shapes = window.shapes;\n if (!shapes) return;\n const idx = shapes.indexOf(shape);\n if (idx < 0) return;\n\n shapes.splice(idx, 1);\n shapes.push(shape);\n\n const el = shape.group || shape.element;\n if (el && el.parentNode) {\n el.parentNode.appendChild(el);\n }\n}\n\n/**\n * Send shape to the very back.\n */\nexport function sendToBack(shape) {\n const shapes = window.shapes;\n if (!shapes) return;\n const idx = shapes.indexOf(shape);\n if (idx < 0) return;\n\n shapes.splice(idx, 1);\n shapes.unshift(shape);\n\n const el = shape.group || shape.element;\n if (el && el.parentNode) {\n el.parentNode.insertBefore(el, el.parentNode.firstChild);\n }\n}\n\n// Expose globally for React sidebar access\nexport function initLayerOrder() {\n window.__layerOrder = { bringForward, sendBackward, bringToFront, sendToBack };\n}\n"],
|
|
5
|
+
"mappings": ";;;AASO,SAAS,aAAa,OAAO;AAChC,QAAM,SAAS,OAAO;AACtB,MAAI,CAAC,OAAQ;AACb,QAAM,MAAM,OAAO,QAAQ,KAAK;AAChC,MAAI,MAAM,KAAK,OAAO,OAAO,SAAS,EAAG;AAGzC,GAAC,OAAO,GAAG,GAAG,OAAO,MAAM,CAAC,CAAC,IAAI,CAAC,OAAO,MAAM,CAAC,GAAG,OAAO,GAAG,CAAC;AAG9D,QAAM,KAAK,MAAM,SAAS,M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