@xom11/whiteboard 0.6.4 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -0
- package/dist/chunk-3SSQKRRO.mjs +58 -0
- package/dist/chunk-3SSQKRRO.mjs.map +1 -0
- package/dist/chunk-7P7SQFOW.mjs +39 -0
- package/dist/chunk-7P7SQFOW.mjs.map +1 -0
- package/dist/chunk-BJX4YNA5.mjs +137 -0
- package/dist/chunk-BJX4YNA5.mjs.map +1 -0
- package/dist/chunk-C6SCVOMC.mjs +111 -0
- package/dist/chunk-C6SCVOMC.mjs.map +1 -0
- package/dist/chunk-DJTBZEAR.mjs +25 -0
- package/dist/chunk-DJTBZEAR.mjs.map +1 -0
- package/dist/chunk-HM7RIXJE.mjs +331 -0
- package/dist/chunk-HM7RIXJE.mjs.map +1 -0
- package/dist/chunk-HTBLO5JO.mjs +41 -0
- package/dist/chunk-HTBLO5JO.mjs.map +1 -0
- package/dist/chunk-HYXFHEDJ.mjs +129 -0
- package/dist/chunk-HYXFHEDJ.mjs.map +1 -0
- package/dist/chunk-LPM4MM45.mjs +211 -0
- package/dist/chunk-LPM4MM45.mjs.map +1 -0
- package/dist/chunk-P2AOIF7S.mjs +40 -0
- package/dist/chunk-P2AOIF7S.mjs.map +1 -0
- package/dist/chunk-SHFOGORM.mjs +44 -0
- package/dist/chunk-SHFOGORM.mjs.map +1 -0
- package/dist/chunk-X5R72SSJ.mjs +52 -0
- package/dist/chunk-X5R72SSJ.mjs.map +1 -0
- package/dist/geometry-2d.d.mts +16 -0
- package/dist/geometry-2d.d.ts +16 -0
- package/dist/geometry-2d.js +3549 -0
- package/dist/geometry-2d.js.map +1 -0
- package/dist/geometry-2d.mjs +7 -0
- package/dist/geometry-2d.mjs.map +1 -0
- package/dist/geometry-3d.d.mts +16 -0
- package/dist/geometry-3d.d.ts +16 -0
- package/dist/geometry-3d.js +2030 -0
- package/dist/geometry-3d.js.map +1 -0
- package/dist/geometry-3d.mjs +6 -0
- package/dist/geometry-3d.mjs.map +1 -0
- package/dist/graph-2d.d.mts +16 -0
- package/dist/graph-2d.d.ts +16 -0
- package/dist/graph-2d.js +1725 -0
- package/dist/graph-2d.js.map +1 -0
- package/dist/graph-2d.mjs +6 -0
- package/dist/graph-2d.mjs.map +1 -0
- package/dist/host-2QGKMGCT.mjs +1066 -0
- package/dist/host-2QGKMGCT.mjs.map +1 -0
- package/dist/host-T2W6R6SO.mjs +2859 -0
- package/dist/host-T2W6R6SO.mjs.map +1 -0
- package/dist/host-XUFON6CQ.mjs +1422 -0
- package/dist/host-XUFON6CQ.mjs.map +1 -0
- package/dist/host-Z3TEJKZA.mjs +466 -0
- package/dist/host-Z3TEJKZA.mjs.map +1 -0
- package/dist/index.d.mts +27 -146
- package/dist/index.d.ts +27 -146
- package/dist/index.js +4694 -4482
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +136 -7179
- package/dist/index.mjs.map +1 -1
- package/dist/latex.d.mts +15 -0
- package/dist/latex.d.ts +15 -0
- package/dist/latex.js +750 -0
- package/dist/latex.js.map +1 -0
- package/dist/latex.mjs +6 -0
- package/dist/latex.mjs.map +1 -0
- package/dist/types-CinstD7T.d.mts +110 -0
- package/dist/types-CinstD7T.d.ts +110 -0
- package/package.json +24 -2
|
@@ -0,0 +1,3549 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
var react = require('react');
|
|
6
|
+
var reactDom = require('react-dom');
|
|
7
|
+
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
10
|
+
var __esm = (fn, res) => function __init() {
|
|
11
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
12
|
+
};
|
|
13
|
+
var __export = (target, all) => {
|
|
14
|
+
for (var name in all)
|
|
15
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// src/stamps/geometry-2d/renderInline.ts
|
|
19
|
+
function renderGeometryToSvg(boardContainer) {
|
|
20
|
+
const svgEl = boardContainer.querySelector("svg");
|
|
21
|
+
if (!svgEl) throw new Error("renderGeometryToSvg: no SVG found in board container");
|
|
22
|
+
const clone = svgEl.cloneNode(true);
|
|
23
|
+
if (!clone.getAttribute("xmlns")) {
|
|
24
|
+
clone.setAttribute("xmlns", "http://www.w3.org/2000/svg");
|
|
25
|
+
}
|
|
26
|
+
return new XMLSerializer().serializeToString(clone);
|
|
27
|
+
}
|
|
28
|
+
var init_renderInline = __esm({
|
|
29
|
+
"src/stamps/geometry-2d/renderInline.ts"() {
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// src/stamps/geometry-2d/editor/theme.ts
|
|
34
|
+
function paletteFor(isDark) {
|
|
35
|
+
return {
|
|
36
|
+
stroke: themeStroke(isDark),
|
|
37
|
+
axis: themeAxis(isDark),
|
|
38
|
+
grid: themeGrid(isDark),
|
|
39
|
+
label: themeLabel(isDark)
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function resolveAttrColors(attrs, palette) {
|
|
43
|
+
if (typeof attrs === "string") {
|
|
44
|
+
const key = SENTINEL_MAP[attrs];
|
|
45
|
+
return key ? palette[key] : attrs;
|
|
46
|
+
}
|
|
47
|
+
if (Array.isArray(attrs)) {
|
|
48
|
+
return attrs.map((a) => resolveAttrColors(a, palette));
|
|
49
|
+
}
|
|
50
|
+
if (attrs && typeof attrs === "object") {
|
|
51
|
+
const out = {};
|
|
52
|
+
for (const [k, v] of Object.entries(attrs)) {
|
|
53
|
+
out[k] = resolveAttrColors(v, palette);
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
return attrs;
|
|
58
|
+
}
|
|
59
|
+
var themeStroke, themeAxis, themeGrid, themeLabel, SENTINEL_MAP;
|
|
60
|
+
var init_theme = __esm({
|
|
61
|
+
"src/stamps/geometry-2d/editor/theme.ts"() {
|
|
62
|
+
themeStroke = (dark) => dark ? "#e2e8f0" : "#0f172a";
|
|
63
|
+
themeAxis = (dark) => dark ? "#cbd5e1" : "#94a3b8";
|
|
64
|
+
themeGrid = (dark) => dark ? "#475569" : "#e2e8f0";
|
|
65
|
+
themeLabel = (dark) => dark ? "#e2e8f0" : "#000000";
|
|
66
|
+
SENTINEL_MAP = {
|
|
67
|
+
"@stroke": "stroke",
|
|
68
|
+
"@axis": "axis",
|
|
69
|
+
"@grid": "grid",
|
|
70
|
+
"@label": "label"
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// src/stamps/geometry-2d/serialize.ts
|
|
76
|
+
function serializeBoard(board, log, options = {}) {
|
|
77
|
+
return {
|
|
78
|
+
bbox: board.getBoundingBox(),
|
|
79
|
+
elements: log.map((e) => ({ type: e.type, args: e.args, attrs: e.attrs, id: e.id })),
|
|
80
|
+
showAxis: !!options.showAxis,
|
|
81
|
+
showGrid: !!options.showGrid
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function createValueLabel(board, target) {
|
|
85
|
+
if (!board || !target) return null;
|
|
86
|
+
const e = (target.elType ?? target.type ?? "").toString().toLowerCase();
|
|
87
|
+
if (e === "segment" || e === "line" || e === "arrow") {
|
|
88
|
+
const p1 = target.point1, p2 = target.point2;
|
|
89
|
+
if (!p1 || !p2) return null;
|
|
90
|
+
return board.create("text", [
|
|
91
|
+
() => (p1.X() + p2.X()) / 2 + 0.15,
|
|
92
|
+
() => (p1.Y() + p2.Y()) / 2 + 0.25,
|
|
93
|
+
() => {
|
|
94
|
+
const len = Math.hypot(p2.X() - p1.X(), p2.Y() - p1.Y());
|
|
95
|
+
const name = typeof target.name === "string" && target.name ? target.name : "d";
|
|
96
|
+
return `${name} = ${len.toFixed(2)}`;
|
|
97
|
+
}
|
|
98
|
+
], { fontSize: 12, color: "#dc2626", fixed: true, highlight: false });
|
|
99
|
+
}
|
|
100
|
+
if (e === "circle" || e === "circumcircle") {
|
|
101
|
+
const center = target.center ?? target.midpoint ?? target.point1;
|
|
102
|
+
if (!center) return null;
|
|
103
|
+
return board.create("text", [
|
|
104
|
+
() => center.X() + 0.3,
|
|
105
|
+
() => center.Y() + 0.3,
|
|
106
|
+
() => {
|
|
107
|
+
const r = typeof target.Radius === "function" ? target.Radius() : 0;
|
|
108
|
+
const name = typeof target.name === "string" && target.name ? target.name : "r";
|
|
109
|
+
return `${name} = ${r.toFixed(2)}`;
|
|
110
|
+
}
|
|
111
|
+
], { fontSize: 12, color: "#dc2626", fixed: true, highlight: false });
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
function deserializeIntoBoard(board, serialized, options = {}) {
|
|
116
|
+
const palette = options.palette ?? paletteFor(false);
|
|
117
|
+
const idMap = /* @__PURE__ */ new Map();
|
|
118
|
+
const resolve = (a) => {
|
|
119
|
+
if (typeof a === "string" && idMap.has(a)) return idMap.get(a);
|
|
120
|
+
if (Array.isArray(a)) return a.map(resolve);
|
|
121
|
+
return a;
|
|
122
|
+
};
|
|
123
|
+
for (const el of serialized.elements) {
|
|
124
|
+
const resolvedArgs = el.args.map(resolve);
|
|
125
|
+
if (el.type === "valueLabel") {
|
|
126
|
+
const target = resolvedArgs[0];
|
|
127
|
+
const txt = createValueLabel(board, target);
|
|
128
|
+
if (txt) idMap.set(el.id, txt);
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
const themedAttrs = resolveAttrColors({ ...el.attrs }, palette);
|
|
132
|
+
const created = board.create(el.type, resolvedArgs, themedAttrs);
|
|
133
|
+
idMap.set(el.id, created);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
var init_serialize = __esm({
|
|
137
|
+
"src/stamps/geometry-2d/serialize.ts"() {
|
|
138
|
+
init_theme();
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// src/stamps/geometry-2d/render.ts
|
|
143
|
+
async function renderGeometrySvgFromState(jsonState) {
|
|
144
|
+
const parsed = JSON.parse(jsonState);
|
|
145
|
+
const palette = paletteFor(false);
|
|
146
|
+
const JXG = (await import('jsxgraph')).default;
|
|
147
|
+
try {
|
|
148
|
+
const opts = JXG.Options;
|
|
149
|
+
if (opts) {
|
|
150
|
+
opts.text = opts.text || {};
|
|
151
|
+
opts.text.display = "internal";
|
|
152
|
+
opts.text.useASCIIMathML = false;
|
|
153
|
+
opts.text.useMathJax = false;
|
|
154
|
+
opts.text.useKatex = false;
|
|
155
|
+
opts.text.strokeColor = palette.label;
|
|
156
|
+
opts.label = opts.label || {};
|
|
157
|
+
opts.label.display = "internal";
|
|
158
|
+
opts.label.strokeColor = palette.label;
|
|
159
|
+
opts.axis = opts.axis || {};
|
|
160
|
+
opts.axis.strokeColor = palette.axis;
|
|
161
|
+
opts.grid = opts.grid || {};
|
|
162
|
+
opts.grid.strokeColor = palette.grid;
|
|
163
|
+
}
|
|
164
|
+
} catch {
|
|
165
|
+
}
|
|
166
|
+
const container = document.createElement("div");
|
|
167
|
+
const containerId = "jxg_offscreen_" + Date.now() + "_" + Math.random().toString(36).slice(2, 8);
|
|
168
|
+
container.id = containerId;
|
|
169
|
+
container.style.cssText = "position:absolute;top:-99999px;left:-99999px;width:400px;height:300px;visibility:hidden;pointer-events:none;";
|
|
170
|
+
document.body.appendChild(container);
|
|
171
|
+
let board = null;
|
|
172
|
+
try {
|
|
173
|
+
board = JXG.JSXGraph.initBoard(containerId, {
|
|
174
|
+
boundingbox: parsed.bbox,
|
|
175
|
+
axis: !!parsed.showAxis,
|
|
176
|
+
grid: !!parsed.showGrid,
|
|
177
|
+
showCopyright: false,
|
|
178
|
+
showNavigation: false,
|
|
179
|
+
keepAspectRatio: false
|
|
180
|
+
});
|
|
181
|
+
deserializeIntoBoard(board, parsed, { palette });
|
|
182
|
+
board.update();
|
|
183
|
+
return renderGeometryToSvg(container);
|
|
184
|
+
} finally {
|
|
185
|
+
try {
|
|
186
|
+
if (board) JXG.JSXGraph.freeBoard(board);
|
|
187
|
+
} catch {
|
|
188
|
+
}
|
|
189
|
+
if (container.parentNode) container.parentNode.removeChild(container);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
var init_render = __esm({
|
|
193
|
+
"src/stamps/geometry-2d/render.ts"() {
|
|
194
|
+
init_renderInline();
|
|
195
|
+
init_serialize();
|
|
196
|
+
init_theme();
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
// src/stamps/geometry-2d/types.ts
|
|
201
|
+
function isGeometryCustomData(data) {
|
|
202
|
+
if (!data || typeof data !== "object") return false;
|
|
203
|
+
const d = data;
|
|
204
|
+
return d.kind === "geometry" && d.version === 1 && typeof d.jsonState === "string";
|
|
205
|
+
}
|
|
206
|
+
var init_types = __esm({
|
|
207
|
+
"src/stamps/geometry-2d/types.ts"() {
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
// src/stamps/geometry-2d/editor/transforms.ts
|
|
212
|
+
function copyVisAttrs(obj) {
|
|
213
|
+
const v = obj?.visProp ?? {};
|
|
214
|
+
const pick = (k) => v?.[k];
|
|
215
|
+
const out = {};
|
|
216
|
+
const mapping = [
|
|
217
|
+
["strokecolor", "strokeColor"],
|
|
218
|
+
["strokewidth", "strokeWidth"],
|
|
219
|
+
["strokeopacity", "strokeOpacity"],
|
|
220
|
+
["dash", "dash"],
|
|
221
|
+
["fillcolor", "fillColor"],
|
|
222
|
+
["fillopacity", "fillOpacity"]
|
|
223
|
+
];
|
|
224
|
+
for (const [from, to] of mapping) {
|
|
225
|
+
const val = pick(from);
|
|
226
|
+
if (val !== void 0) out[to] = val;
|
|
227
|
+
}
|
|
228
|
+
return out;
|
|
229
|
+
}
|
|
230
|
+
function getDefiningPoints(obj) {
|
|
231
|
+
if (!obj) return null;
|
|
232
|
+
const e = (obj.elType ?? obj.type ?? "").toString().toLowerCase();
|
|
233
|
+
if (e === "point" || e === "glider" || e === "midpoint") {
|
|
234
|
+
return { kind: "point", points: [obj], attrs: copyVisAttrs(obj) };
|
|
235
|
+
}
|
|
236
|
+
if (LINE_LIKE.has(e) && obj.point1 && obj.point2) {
|
|
237
|
+
const kind = e === "segment" ? "segment" : e === "arrow" ? "arrow" : "line";
|
|
238
|
+
return { kind, points: [obj.point1, obj.point2], attrs: copyVisAttrs(obj) };
|
|
239
|
+
}
|
|
240
|
+
if (e === "circle" && obj.center && obj.point2) {
|
|
241
|
+
return { kind: "circleCenter", points: [obj.center, obj.point2], attrs: copyVisAttrs(obj) };
|
|
242
|
+
}
|
|
243
|
+
if (e === "circumcircle" && obj.point1 && obj.point2 && obj.point3) {
|
|
244
|
+
return {
|
|
245
|
+
kind: "circle3",
|
|
246
|
+
points: [obj.point1, obj.point2, obj.point3],
|
|
247
|
+
attrs: copyVisAttrs(obj)
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
function buildTransformSpec(input) {
|
|
253
|
+
switch (input.kind) {
|
|
254
|
+
case "translate": {
|
|
255
|
+
const [a, b] = input.vectorPoints;
|
|
256
|
+
const dx = b.X() - a.X();
|
|
257
|
+
const dy = b.Y() - a.Y();
|
|
258
|
+
return { params: [dx, dy], attrs: { type: "translate" } };
|
|
259
|
+
}
|
|
260
|
+
case "rotate":
|
|
261
|
+
return {
|
|
262
|
+
params: [input.angleDeg * Math.PI / 180, input.center],
|
|
263
|
+
attrs: { type: "rotate" }
|
|
264
|
+
};
|
|
265
|
+
case "reflectLine":
|
|
266
|
+
return { params: [input.line], attrs: { type: "reflect" } };
|
|
267
|
+
case "reflectPoint":
|
|
268
|
+
return { params: [Math.PI, input.center], attrs: { type: "rotate" } };
|
|
269
|
+
case "dilate":
|
|
270
|
+
return {
|
|
271
|
+
params: [],
|
|
272
|
+
attrs: { type: "scale" },
|
|
273
|
+
chain: [
|
|
274
|
+
{ params: [-input.center.X(), -input.center.Y()], attrs: { type: "translate" } },
|
|
275
|
+
{ params: [input.k, input.k], attrs: { type: "scale" } },
|
|
276
|
+
{ params: [input.center.X(), input.center.Y()], attrs: { type: "translate" } }
|
|
277
|
+
]
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
var LINE_LIKE;
|
|
282
|
+
var init_transforms = __esm({
|
|
283
|
+
"src/stamps/geometry-2d/editor/transforms.ts"() {
|
|
284
|
+
LINE_LIKE = /* @__PURE__ */ new Set(["line", "segment", "arrow"]);
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
function letterForGroup(g) {
|
|
288
|
+
const idx = GROUP_ORDER.indexOf(g);
|
|
289
|
+
return idx >= 0 ? String.fromCharCode(A_CODE + idx) : "";
|
|
290
|
+
}
|
|
291
|
+
function objKind(obj) {
|
|
292
|
+
if (!obj) return "other";
|
|
293
|
+
const e = (obj.elType || obj.type || "").toString().toLowerCase();
|
|
294
|
+
if (e === "point" || e === "glider" || e === "midpoint") return "point";
|
|
295
|
+
if (e === "line" || e === "segment" || e === "arrow" || e === "axis" || e === "normal" || e === "parallel" || e === "perpendicular" || e === "tangent" || e === "bisector" || e === "perpendicularsegment") return "line";
|
|
296
|
+
if (e === "circle" || e === "circumcircle") return "circle";
|
|
297
|
+
return "other";
|
|
298
|
+
}
|
|
299
|
+
var Icon, TOOLS, GROUP_LABELS, GROUP_ORDER, A_CODE;
|
|
300
|
+
var init_tools = __esm({
|
|
301
|
+
"src/stamps/geometry-2d/editor/tools.tsx"() {
|
|
302
|
+
Icon = {
|
|
303
|
+
cursor: /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M4 4 L20 12 L13 13 L11 20 Z" }) }),
|
|
304
|
+
select: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
305
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M4 4 L20 12 L13 13 L11 20 Z", fill: "none" }),
|
|
306
|
+
/* @__PURE__ */ jsxRuntime.jsx("rect", { x: "2.5", y: "2.5", width: "19", height: "19", strokeDasharray: "3 2", fill: "none" })
|
|
307
|
+
] }),
|
|
308
|
+
point: /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "12", r: "4", fill: "currentColor" }) }),
|
|
309
|
+
midpoint: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
|
|
310
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "4", y1: "12", x2: "20", y2: "12" }),
|
|
311
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "12", r: "2.5", fill: "currentColor", stroke: "none" }),
|
|
312
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "4", cy: "12", r: "1.6", fill: "currentColor", stroke: "none" }),
|
|
313
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "20", cy: "12", r: "1.6", fill: "currentColor", stroke: "none" })
|
|
314
|
+
] }),
|
|
315
|
+
segment: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
|
|
316
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "5", y1: "18", x2: "19", y2: "6" }),
|
|
317
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "5", cy: "18", r: "1.7", fill: "currentColor" }),
|
|
318
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "19", cy: "6", r: "1.7", fill: "currentColor" })
|
|
319
|
+
] }),
|
|
320
|
+
line: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
|
|
321
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "2", y1: "20", x2: "22", y2: "4" }),
|
|
322
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "8", cy: "16", r: "1.6", fill: "currentColor" }),
|
|
323
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "16", cy: "8", r: "1.6", fill: "currentColor" })
|
|
324
|
+
] }),
|
|
325
|
+
ray: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
|
|
326
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "5", y1: "19", x2: "22", y2: "2" }),
|
|
327
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "5", cy: "19", r: "1.7", fill: "currentColor" }),
|
|
328
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "12", r: "1.5", fill: "currentColor" })
|
|
329
|
+
] }),
|
|
330
|
+
vector: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
331
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "4", y1: "20", x2: "20", y2: "4" }),
|
|
332
|
+
/* @__PURE__ */ jsxRuntime.jsx("polyline", { points: "14,4 20,4 20,10" })
|
|
333
|
+
] }),
|
|
334
|
+
perpendicular: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
|
|
335
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "3", y1: "18", x2: "21", y2: "18" }),
|
|
336
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "12", y1: "18", x2: "12", y2: "4" }),
|
|
337
|
+
/* @__PURE__ */ jsxRuntime.jsx("rect", { x: "12", y: "14", width: "4", height: "4", fill: "none" })
|
|
338
|
+
] }),
|
|
339
|
+
parallel: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
|
|
340
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "3", y1: "9", x2: "21", y2: "5" }),
|
|
341
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "3", y1: "19", x2: "21", y2: "15" })
|
|
342
|
+
] }),
|
|
343
|
+
perpBisector: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
|
|
344
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "4", y1: "18", x2: "20", y2: "18" }),
|
|
345
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "12", y1: "4", x2: "12", y2: "22", strokeDasharray: "3 2" }),
|
|
346
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "6", cy: "18", r: "1.5", fill: "currentColor" }),
|
|
347
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "18", cy: "18", r: "1.5", fill: "currentColor" })
|
|
348
|
+
] }),
|
|
349
|
+
bisector: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
|
|
350
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "4", y1: "20", x2: "20", y2: "4" }),
|
|
351
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "4", y1: "20", x2: "20", y2: "20" }),
|
|
352
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "4", y1: "20", x2: "22", y2: "12", strokeDasharray: "3 2" })
|
|
353
|
+
] }),
|
|
354
|
+
polygon: /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinejoin: "round", children: /* @__PURE__ */ jsxRuntime.jsx("polygon", { points: "6,6 18,6 22,14 12,22 4,14" }) }),
|
|
355
|
+
regularPolygon: /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinejoin: "round", children: /* @__PURE__ */ jsxRuntime.jsx("polygon", { points: "12,3 20,8 20,17 12,22 4,17 4,8" }) }),
|
|
356
|
+
circleCenter: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
|
|
357
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "12", r: "8" }),
|
|
358
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "12", r: "1.6", fill: "currentColor" })
|
|
359
|
+
] }),
|
|
360
|
+
circle3: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
|
|
361
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "12", r: "8" }),
|
|
362
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "4", r: "1.5", fill: "currentColor" }),
|
|
363
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "20", cy: "14", r: "1.5", fill: "currentColor" }),
|
|
364
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "5", cy: "16", r: "1.5", fill: "currentColor" })
|
|
365
|
+
] }),
|
|
366
|
+
tangent: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
|
|
367
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "11", cy: "13", r: "6" }),
|
|
368
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "2", y1: "20", x2: "22", y2: "2" })
|
|
369
|
+
] }),
|
|
370
|
+
angle: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
|
|
371
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "4", y1: "20", x2: "20", y2: "20" }),
|
|
372
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "4", y1: "20", x2: "20", y2: "6" }),
|
|
373
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M14 20 A 10 10 0 0 0 11 13" })
|
|
374
|
+
] }),
|
|
375
|
+
distance: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
|
|
376
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "4", y1: "12", x2: "20", y2: "12" }),
|
|
377
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "4", y1: "8", x2: "4", y2: "16" }),
|
|
378
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "20", y1: "8", x2: "20", y2: "16" })
|
|
379
|
+
] }),
|
|
380
|
+
area: /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: /* @__PURE__ */ jsxRuntime.jsx("polygon", { points: "5,6 19,6 21,14 13,21 3,15", fill: "currentColor", fillOpacity: "0.2" }) }),
|
|
381
|
+
toggleLabel: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
382
|
+
/* @__PURE__ */ jsxRuntime.jsx("text", { x: "3", y: "18", fontSize: "16", fontFamily: "serif", fontWeight: "700", fill: "currentColor", stroke: "none", children: "A" }),
|
|
383
|
+
/* @__PURE__ */ jsxRuntime.jsx("text", { x: "13", y: "14", fontSize: "11", fontFamily: "serif", fontWeight: "700", fill: "currentColor", stroke: "none", children: "A" })
|
|
384
|
+
] }),
|
|
385
|
+
toggleVisible: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
|
|
386
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "12", r: "3.5", fill: "currentColor", fillOpacity: "0.4" }),
|
|
387
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "12", r: "3.5" }),
|
|
388
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "20", cy: "6", r: "1.5", fill: "currentColor" })
|
|
389
|
+
] }),
|
|
390
|
+
trash: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
391
|
+
/* @__PURE__ */ jsxRuntime.jsx("polyline", { points: "3,6 5,6 21,6" }),
|
|
392
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M19 6 l-1 14 a 2 2 0 0 1 -2 2 H 8 a 2 2 0 0 1 -2 -2 l-1 -14" }),
|
|
393
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "10", y1: "11", x2: "10", y2: "17" }),
|
|
394
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "14", y1: "11", x2: "14", y2: "17" })
|
|
395
|
+
] }),
|
|
396
|
+
translate: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
|
|
397
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M4 4 L20 20" }),
|
|
398
|
+
/* @__PURE__ */ jsxRuntime.jsx("polygon", { points: "14,4 20,4 20,10", fill: "currentColor" }),
|
|
399
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "5", cy: "5", r: "1.5", fill: "currentColor" })
|
|
400
|
+
] }),
|
|
401
|
+
rotate: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
|
|
402
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M4 12 A8 8 0 1 1 12 20" }),
|
|
403
|
+
/* @__PURE__ */ jsxRuntime.jsx("polyline", { points: "4,9 4,13 8,13" })
|
|
404
|
+
] }),
|
|
405
|
+
reflectLine: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
|
|
406
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "12", y1: "2", x2: "12", y2: "22", strokeDasharray: "3 2" }),
|
|
407
|
+
/* @__PURE__ */ jsxRuntime.jsx("polygon", { points: "4,6 9,12 4,18", fill: "currentColor" }),
|
|
408
|
+
/* @__PURE__ */ jsxRuntime.jsx("polygon", { points: "20,6 15,12 20,18", fill: "currentColor" })
|
|
409
|
+
] }),
|
|
410
|
+
reflectPoint: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
|
|
411
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "12", r: "1.5", fill: "currentColor" }),
|
|
412
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "5", cy: "5", r: "1.6", fill: "currentColor" }),
|
|
413
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "19", cy: "19", r: "1.6", fill: "currentColor" }),
|
|
414
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "5", y1: "5", x2: "19", y2: "19", strokeDasharray: "2 2" })
|
|
415
|
+
] }),
|
|
416
|
+
dilate: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
|
|
417
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "12", r: "1.5", fill: "currentColor" }),
|
|
418
|
+
/* @__PURE__ */ jsxRuntime.jsx("polygon", { points: "6,18 18,18 12,6", fillOpacity: "0.1", fill: "currentColor" }),
|
|
419
|
+
/* @__PURE__ */ jsxRuntime.jsx("polygon", { points: "9,15 15,15 12,11", fill: "currentColor" })
|
|
420
|
+
] })
|
|
421
|
+
};
|
|
422
|
+
TOOLS = [
|
|
423
|
+
{ key: "move", label: "Di chuy\u1EC3n", hint: "K\xE9o \u0111i\u1EC3m ho\u1EB7c xoay n\u1EC1n", icon: Icon.cursor, group: "move", needs: 0 },
|
|
424
|
+
{ key: "select", label: "Ch\u1ECDn", hint: "Click \u0111\u1EC3 ch\u1ECDn 1 / Shift+click \u0111\u1EC3 b\u1ECF th\xEAm / K\xE9o n\u1EC1n \u0111\u1EC3 khoanh v\xF9ng / DEL \u0111\u1EC3 xo\xE1", icon: Icon.select, group: "move", needs: 0 },
|
|
425
|
+
{ key: "point", label: "\u0110i\u1EC3m m\u1EDBi", hint: "Click \u0111\u1EC3 th\xEAm \u0111i\u1EC3m", icon: Icon.point, group: "point", needs: 1 },
|
|
426
|
+
{ key: "midpoint", label: "Trung \u0111i\u1EC3m", hint: "Click 2 \u0111i\u1EC3m c\xF3 s\u1EB5n", icon: Icon.midpoint, group: "point", needs: 2, accepts: ["point", "point"] },
|
|
427
|
+
{ key: "segment", label: "\u0110o\u1EA1n th\u1EB3ng", hint: "Click 2 \u0111i\u1EC3m", icon: Icon.segment, group: "line", needs: 2 },
|
|
428
|
+
{ key: "line", label: "\u0110\u01B0\u1EDDng th\u1EB3ng qua 2 \u0111i\u1EC3m", hint: "Click 2 \u0111i\u1EC3m", icon: Icon.line, group: "line", needs: 2 },
|
|
429
|
+
{ key: "ray", label: "Tia qua 2 \u0111i\u1EC3m", hint: "Click 2 \u0111i\u1EC3m", icon: Icon.ray, group: "line", needs: 2 },
|
|
430
|
+
{ key: "vector", label: "Vector", hint: "Click 2 \u0111i\u1EC3m", icon: Icon.vector, group: "line", needs: 2 },
|
|
431
|
+
{ key: "perpendicular", label: "\u0110\u01B0\u1EDDng vu\xF4ng g\xF3c", hint: "Click 1 \u0111i\u1EC3m + 1 \u0111\u01B0\u1EDDng c\xF3 s\u1EB5n", icon: Icon.perpendicular, group: "construct", needs: 2, accepts: ["point", "line"] },
|
|
432
|
+
{ key: "parallel", label: "\u0110\u01B0\u1EDDng song song", hint: "Click 1 \u0111i\u1EC3m + 1 \u0111\u01B0\u1EDDng c\xF3 s\u1EB5n", icon: Icon.parallel, group: "construct", needs: 2, accepts: ["point", "line"] },
|
|
433
|
+
{ key: "perpBisector", label: "\u0110\u01B0\u1EDDng trung tr\u1EF1c", hint: "Click 2 \u0111i\u1EC3m c\xF3 s\u1EB5n", icon: Icon.perpBisector, group: "construct", needs: 2, accepts: ["point", "point"] },
|
|
434
|
+
{ key: "angleBisector", label: "\u0110\u01B0\u1EDDng ph\xE2n gi\xE1c", hint: "Click 3 \u0111i\u1EC3m c\xF3 s\u1EB5n (\u0111\u1EC9nh \u1EDF gi\u1EEFa)", icon: Icon.bisector, group: "construct", needs: 3, accepts: ["point", "point", "point"] },
|
|
435
|
+
{ key: "polygon", label: "\u0110a gi\xE1c", hint: "Click c\xE1c \u0111i\u1EC3m, click l\u1EA1i \u0111i\u1EC3m \u0111\u1EA7u \u0111\u1EC3 \u0111\xF3ng", icon: Icon.polygon, group: "polygon", needs: -1 },
|
|
436
|
+
{ key: "regularPolygon", label: "\u0110a gi\xE1c \u0111\u1EC1u", hint: "Click 2 \u0111i\u1EC3m r\u1ED3i nh\u1EADp s\u1ED1 c\u1EA1nh", icon: Icon.regularPolygon, group: "polygon", needs: 2, accepts: ["point", "point"] },
|
|
437
|
+
{ key: "circleCenter", label: "\u0110\u01B0\u1EDDng tr\xF2n (t\xE2m + \u0111i\u1EC3m)", hint: "Click t\xE2m r\u1ED3i 1 \u0111i\u1EC3m tr\xEAn \u0111\u01B0\u1EDDng tr\xF2n", icon: Icon.circleCenter, group: "circle", needs: 2 },
|
|
438
|
+
{ key: "circle3", label: "\u0110\u01B0\u1EDDng tr\xF2n qua 3 \u0111i\u1EC3m", hint: "Click 3 \u0111i\u1EC3m", icon: Icon.circle3, group: "circle", needs: 3 },
|
|
439
|
+
{ key: "tangent", label: "Ti\u1EBFp tuy\u1EBFn", hint: "Click 1 \u0111i\u1EC3m + 1 \u0111\u01B0\u1EDDng tr\xF2n c\xF3 s\u1EB5n", icon: Icon.tangent, group: "circle", needs: 2, accepts: ["point", "circle"] },
|
|
440
|
+
{ key: "angle", label: "G\xF3c", hint: "Click 3 \u0111i\u1EC3m c\xF3 s\u1EB5n (\u0111\u1EC9nh \u1EDF gi\u1EEFa)", icon: Icon.angle, group: "measure", needs: 3, accepts: ["point", "point", "point"] },
|
|
441
|
+
{ key: "distance", label: "Kho\u1EA3ng c\xE1ch", hint: "Click 2 \u0111i\u1EC3m c\xF3 s\u1EB5n", icon: Icon.distance, group: "measure", needs: 2, accepts: ["point", "point"] },
|
|
442
|
+
{ key: "area", label: "Di\u1EC7n t\xEDch", hint: "Click c\xE1c \u0111\u1EC9nh, click l\u1EA1i \u0111i\u1EC3m \u0111\u1EA7u \u0111\u1EC3 \u0111\xF3ng", icon: Icon.area, group: "measure", needs: -1 },
|
|
443
|
+
{ key: "toggleLabel", label: "Hi\u1EC7n/\u1EA9n t\xEAn", hint: "Click v\xE0o \u0111\u1ED1i t\u01B0\u1EE3ng", icon: Icon.toggleLabel, group: "edit", needs: 1, accepts: ["any"] },
|
|
444
|
+
{ key: "toggleVisible", label: "Hi\u1EC7n/\u1EA9n \u0111\u1ED1i t\u01B0\u1EE3ng", hint: "Click v\xE0o \u0111\u1ED1i t\u01B0\u1EE3ng", icon: Icon.toggleVisible, group: "edit", needs: 1, accepts: ["any"] },
|
|
445
|
+
{ key: "delete", label: "Xo\xE1", hint: "Click v\xE0o \u0111\u1ED1i t\u01B0\u1EE3ng", icon: Icon.trash, group: "edit", needs: 1, accepts: ["any"] },
|
|
446
|
+
{ key: "translate", label: "Ph\xE9p t\u1ECBnh ti\u1EBFn", hint: "Click object \u2192 2 \u0111i\u1EC3m t\u1EA1o vector", icon: Icon.translate, group: "transform", needs: 3, accepts: ["any", "point", "point"] },
|
|
447
|
+
{ key: "rotate", label: "Quay \u0111\u1ED1i t\u01B0\u1EE3ng", hint: "Click object \u2192 t\xE2m quay \u2192 nh\u1EADp g\xF3c", icon: Icon.rotate, group: "transform", needs: 2, accepts: ["any", "point"] },
|
|
448
|
+
{ key: "reflectLine", label: "\u0110\u1ED1i x\u1EE9ng qua \u0111\u01B0\u1EDDng th\u1EB3ng", hint: "Click object \u2192 \u0111\u01B0\u1EDDng th\u1EB3ng", icon: Icon.reflectLine, group: "transform", needs: 2, accepts: ["any", "line"] },
|
|
449
|
+
{ key: "reflectPoint", label: "\u0110\u1ED1i x\u1EE9ng qua \u0111i\u1EC3m", hint: "Click object \u2192 t\xE2m \u0111\u1ED1i x\u1EE9ng", icon: Icon.reflectPoint, group: "transform", needs: 2, accepts: ["any", "point"] },
|
|
450
|
+
{ key: "dilate", label: "Ph\xE9p v\u1ECB t\u1EF1", hint: "Click object \u2192 t\xE2m \u2192 nh\u1EADp t\u1EF7 s\u1ED1 k", icon: Icon.dilate, group: "transform", needs: 2, accepts: ["any", "point"] }
|
|
451
|
+
];
|
|
452
|
+
GROUP_LABELS = {
|
|
453
|
+
move: "C\u01A1 b\u1EA3n",
|
|
454
|
+
point: "\u0110i\u1EC3m",
|
|
455
|
+
line: "\u0110\u01B0\u1EDDng",
|
|
456
|
+
construct: "D\u1EF1ng h\xECnh",
|
|
457
|
+
polygon: "\u0110a gi\xE1c",
|
|
458
|
+
circle: "\u0110\u01B0\u1EDDng tr\xF2n",
|
|
459
|
+
measure: "\u0110o l\u01B0\u1EDDng",
|
|
460
|
+
edit: "Ch\u1EC9nh s\u1EEDa",
|
|
461
|
+
transform: "Ph\xE9p bi\u1EBFn h\xECnh"
|
|
462
|
+
};
|
|
463
|
+
GROUP_ORDER = [
|
|
464
|
+
"move",
|
|
465
|
+
"point",
|
|
466
|
+
"line",
|
|
467
|
+
"construct",
|
|
468
|
+
"polygon",
|
|
469
|
+
"circle",
|
|
470
|
+
"measure",
|
|
471
|
+
"edit",
|
|
472
|
+
"transform"
|
|
473
|
+
];
|
|
474
|
+
A_CODE = "A".charCodeAt(0);
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
// src/stamps/geometry-2d/editor/handlers.ts
|
|
479
|
+
function handleDown(ctx, e) {
|
|
480
|
+
if (!ctx.boardRef.current) return;
|
|
481
|
+
const t = ctx.toolRef.current;
|
|
482
|
+
if (t === "move") {
|
|
483
|
+
const sc = ctx.screenCoordsOf(e);
|
|
484
|
+
if (!sc) return;
|
|
485
|
+
const [sx, sy] = sc;
|
|
486
|
+
ctx.moveDownRef.current = { sx, sy };
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
if (t === "select") {
|
|
490
|
+
const sc = ctx.screenCoordsOf(e);
|
|
491
|
+
if (!sc) return;
|
|
492
|
+
const [sx, sy] = sc;
|
|
493
|
+
const hits2 = ctx.objectsAt(e).map(ctx.promoteLabel).filter((o) => o !== ctx.axisObjsRef.current.x && o !== ctx.axisObjsRef.current.y);
|
|
494
|
+
const obj = hits2.find((o) => objKind(o) === "point") ?? hits2[0] ?? ctx.findNearestPoint(e, 12);
|
|
495
|
+
if (obj) {
|
|
496
|
+
const shift = !!(e.shiftKey || e.altKey);
|
|
497
|
+
ctx.toggleSelect(obj, shift);
|
|
498
|
+
ctx.moveDownRef.current = { sx, sy };
|
|
499
|
+
ctx.marqueeRef.current = null;
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
ctx.marqueeRef.current = { startSx: sx, startSy: sy };
|
|
503
|
+
if (!(e.shiftKey || e.altKey)) ctx.clearSelection();
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
const toolDef = TOOLS.find((td) => td.key === t);
|
|
507
|
+
if (!toolDef) return;
|
|
508
|
+
const coords = ctx.boardRef.current.getUsrCoordsOfMouse(e);
|
|
509
|
+
const x = coords[0], y = coords[1];
|
|
510
|
+
const hits = ctx.objectsAt(e).map(ctx.promoteLabel).filter((o) => o !== ctx.axisObjsRef.current.x && o !== ctx.axisObjsRef.current.y);
|
|
511
|
+
const bestHit = hits.find((o) => objKind(o) === "point") ?? hits[0] ?? null;
|
|
512
|
+
const snapPointForPointSlot = () => bestHit && objKind(bestHit) === "point" ? bestHit : ctx.findNearestPoint(e, 12);
|
|
513
|
+
if (t === "point") {
|
|
514
|
+
const curves = hits.filter((o) => objKind(o) === "line" || objKind(o) === "circle");
|
|
515
|
+
if (curves.length >= 2) {
|
|
516
|
+
const a = curves[0];
|
|
517
|
+
const b = curves[1];
|
|
518
|
+
const aId = ctx.localIdOf(a);
|
|
519
|
+
const bId = ctx.localIdOf(b);
|
|
520
|
+
if (aId && bId) {
|
|
521
|
+
const name2 = ctx.nextLabel();
|
|
522
|
+
const attrs = { name: name2, color: "@stroke", size: 3, fillColor: "@stroke", strokeColor: "@stroke" };
|
|
523
|
+
try {
|
|
524
|
+
const isLineLine = objKind(a) === "line" && objKind(b) === "line";
|
|
525
|
+
if (isLineLine) {
|
|
526
|
+
ctx.create("intersection", [aId, bId, 0], attrs);
|
|
527
|
+
} else {
|
|
528
|
+
const tmp0 = ctx.boardRef.current.create("intersection", [a, b, 0], { visible: false, withLabel: false });
|
|
529
|
+
const tmp1 = ctx.boardRef.current.create("intersection", [a, b, 1], { visible: false, withLabel: false });
|
|
530
|
+
const d0 = Math.hypot((tmp0.X?.() ?? 0) - x, (tmp0.Y?.() ?? 0) - y);
|
|
531
|
+
const d1 = Math.hypot((tmp1.X?.() ?? 0) - x, (tmp1.Y?.() ?? 0) - y);
|
|
532
|
+
try {
|
|
533
|
+
ctx.boardRef.current.removeObject(tmp0);
|
|
534
|
+
} catch {
|
|
535
|
+
}
|
|
536
|
+
try {
|
|
537
|
+
ctx.boardRef.current.removeObject(tmp1);
|
|
538
|
+
} catch {
|
|
539
|
+
}
|
|
540
|
+
const idx = d0 <= d1 ? 0 : 1;
|
|
541
|
+
ctx.create("intersection", [aId, bId, idx], attrs);
|
|
542
|
+
}
|
|
543
|
+
return;
|
|
544
|
+
} catch {
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
const name = ctx.nextLabel();
|
|
549
|
+
ctx.create("point", [x, y], { name, color: "@stroke", size: 3, fillColor: "@stroke", strokeColor: "@stroke" });
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
if (toolDef.needs === 1 && toolDef.accepts) {
|
|
553
|
+
const hit = bestHit ?? ctx.findNearestPoint(e, 12);
|
|
554
|
+
if (hit) ctx.finalize(toolDef, [hit]);
|
|
555
|
+
else ctx.flashWarn("Click v\xE0o m\u1ED9t \u0111\u1ED1i t\u01B0\u1EE3ng \u0111\u1EC3 \xE1p d\u1EE5ng");
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
if (toolDef.needs === -1) {
|
|
559
|
+
const snappedPoint = snapPointForPointSlot();
|
|
560
|
+
if (ctx.pendingRef.current.length >= 3 && snappedPoint && snappedPoint === ctx.pendingRef.current[0]) {
|
|
561
|
+
ctx.clearPreviewSegs();
|
|
562
|
+
ctx.finalize(toolDef, ctx.pendingRef.current);
|
|
563
|
+
ctx.clearPending();
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
if (snappedPoint && ctx.pendingRef.current.includes(snappedPoint)) {
|
|
567
|
+
ctx.flashWarn("\u0110\u1EC9nh n\xE0y \u0111\xE3 c\xF3 \u2014 click \u0111i\u1EC3m kh\xE1c ho\u1EB7c click l\u1EA1i \u0111i\u1EC3m \u0111\u1EA7u \u0111\u1EC3 \u0111\xF3ng");
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
const pick2 = snappedPoint ?? (() => {
|
|
571
|
+
const name = ctx.nextLabel();
|
|
572
|
+
return ctx.create("point", [x, y], { name, color: "@stroke", size: 3 });
|
|
573
|
+
})();
|
|
574
|
+
if (ctx.pendingRef.current.length > 0 && ctx.boardRef.current) {
|
|
575
|
+
const prev = ctx.pendingRef.current[ctx.pendingRef.current.length - 1];
|
|
576
|
+
try {
|
|
577
|
+
const seg = ctx.boardRef.current.create("segment", [prev, pick2], {
|
|
578
|
+
strokeColor: "#3b82f6",
|
|
579
|
+
strokeWidth: 1.5,
|
|
580
|
+
strokeOpacity: 0.75,
|
|
581
|
+
fixed: true,
|
|
582
|
+
highlight: false,
|
|
583
|
+
withLabel: false
|
|
584
|
+
});
|
|
585
|
+
ctx.previewSegRef.current.push(seg);
|
|
586
|
+
} catch {
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
ctx.pendingRef.current.push(pick2);
|
|
590
|
+
ctx.setPendingCount(ctx.pendingRef.current.length);
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
let pick = null;
|
|
594
|
+
if (toolDef.accepts) {
|
|
595
|
+
const usedKinds = ctx.pendingRef.current.map((p) => objKind(p));
|
|
596
|
+
const remaining = [...toolDef.accepts];
|
|
597
|
+
for (const u of usedKinds) {
|
|
598
|
+
if (u === "other") continue;
|
|
599
|
+
const i = remaining.indexOf(u);
|
|
600
|
+
if (i >= 0) remaining.splice(i, 1);
|
|
601
|
+
}
|
|
602
|
+
const strictPoint = hits.find((o) => objKind(o) === "point") ?? null;
|
|
603
|
+
const lineHit = hits.find((o) => objKind(o) === "line") ?? null;
|
|
604
|
+
const circleHit = hits.find((o) => objKind(o) === "circle") ?? null;
|
|
605
|
+
if (remaining.includes("point") && strictPoint) pick = strictPoint;
|
|
606
|
+
else if (remaining.includes("line") && lineHit) pick = lineHit;
|
|
607
|
+
else if (remaining.includes("circle") && circleHit) pick = circleHit;
|
|
608
|
+
else if (remaining.includes("any") && (strictPoint || lineHit || circleHit)) {
|
|
609
|
+
pick = strictPoint ?? lineHit ?? circleHit;
|
|
610
|
+
} else if (remaining.includes("point")) {
|
|
611
|
+
const near = ctx.findNearestPoint(e, 12);
|
|
612
|
+
if (near) pick = near;
|
|
613
|
+
}
|
|
614
|
+
if (!pick) {
|
|
615
|
+
const needs = remaining.map(
|
|
616
|
+
(k) => k === "point" ? "m\u1ED9t \u0111i\u1EC3m" : k === "line" ? "m\u1ED9t \u0111\u01B0\u1EDDng/\u0111o\u1EA1n" : k === "circle" ? "m\u1ED9t \u0111\u01B0\u1EDDng tr\xF2n" : "m\u1ED9t \u0111\u1ED1i t\u01B0\u1EE3ng"
|
|
617
|
+
);
|
|
618
|
+
ctx.flashWarn(`C\xF2n c\u1EA7n click v\xE0o ${needs.join(" + ")} c\xF3 s\u1EB5n`);
|
|
619
|
+
return;
|
|
620
|
+
}
|
|
621
|
+
if (ctx.pendingRef.current.includes(pick)) {
|
|
622
|
+
ctx.flashWarn("\u0110\xE3 ch\u1ECDn \u0111\u1ED1i t\u01B0\u1EE3ng n\xE0y \u2014 ch\u1ECDn \u0111\u1ED1i t\u01B0\u1EE3ng kh\xE1c");
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
} else {
|
|
626
|
+
const snapped = snapPointForPointSlot();
|
|
627
|
+
if (snapped && ctx.pendingRef.current.includes(snapped)) {
|
|
628
|
+
ctx.flashWarn("\u0110\xE3 ch\u1ECDn \u0111i\u1EC3m n\xE0y \u2014 ch\u1ECDn \u0111i\u1EC3m kh\xE1c ho\u1EB7c click ch\u1ED7 tr\u1ED1ng");
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
if (snapped) pick = snapped;
|
|
632
|
+
else {
|
|
633
|
+
const name = ctx.nextLabel();
|
|
634
|
+
pick = ctx.create("point", [x, y], { name, color: "@stroke", size: 3, fillColor: "@stroke", strokeColor: "@stroke" });
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
if (!pick) return;
|
|
638
|
+
ctx.pendingRef.current.push(pick);
|
|
639
|
+
ctx.setPendingCount(ctx.pendingRef.current.length);
|
|
640
|
+
if (ctx.pendingRef.current.length >= toolDef.needs) {
|
|
641
|
+
const tk = toolDef.key;
|
|
642
|
+
if (tk === "rotate" || tk === "dilate") {
|
|
643
|
+
const source = ctx.pendingRef.current[0];
|
|
644
|
+
const center = ctx.pendingRef.current[1];
|
|
645
|
+
const cx = (e.clientX ?? 0) + 8;
|
|
646
|
+
const cy = (e.clientY ?? 0) + 8;
|
|
647
|
+
ctx.pendingTransformRef.current = { tool: tk, source, center, anchorScreen: { x: cx, y: cy } };
|
|
648
|
+
ctx.emitTransform({ tool: tk, anchor: { x: cx, y: cy } });
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
651
|
+
if (tk === "regularPolygon") {
|
|
652
|
+
const p1 = ctx.pendingRef.current[0];
|
|
653
|
+
const p2 = ctx.pendingRef.current[1];
|
|
654
|
+
const cx = (e.clientX ?? 0) + 8;
|
|
655
|
+
const cy = (e.clientY ?? 0) + 8;
|
|
656
|
+
ctx.pendingTransformRef.current = { tool: tk, source: p1, center: p2, anchorScreen: { x: cx, y: cy } };
|
|
657
|
+
ctx.emitTransform({ tool: tk, anchor: { x: cx, y: cy } });
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
if (tk === "translate") {
|
|
661
|
+
const source = ctx.pendingRef.current[0];
|
|
662
|
+
const spec = buildTransformSpec({ kind: "translate", vectorPoints: [ctx.pendingRef.current[1], ctx.pendingRef.current[2]] });
|
|
663
|
+
ctx.finalizeTransformCreate(spec, source);
|
|
664
|
+
ctx.clearPending();
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
if (tk === "reflectLine") {
|
|
668
|
+
const source = ctx.pendingRef.current[0];
|
|
669
|
+
const spec = buildTransformSpec({ kind: "reflectLine", line: ctx.pendingRef.current[1] });
|
|
670
|
+
ctx.finalizeTransformCreate(spec, source);
|
|
671
|
+
ctx.clearPending();
|
|
672
|
+
return;
|
|
673
|
+
}
|
|
674
|
+
if (tk === "reflectPoint") {
|
|
675
|
+
const source = ctx.pendingRef.current[0];
|
|
676
|
+
const spec = buildTransformSpec({ kind: "reflectPoint", center: ctx.pendingRef.current[1] });
|
|
677
|
+
ctx.finalizeTransformCreate(spec, source);
|
|
678
|
+
ctx.clearPending();
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
681
|
+
ctx.finalize(toolDef, ctx.pendingRef.current);
|
|
682
|
+
ctx.clearPending();
|
|
683
|
+
} else {
|
|
684
|
+
ctx.refreshPreview();
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
function handleUp(ctx, e) {
|
|
688
|
+
const t = ctx.toolRef.current;
|
|
689
|
+
if (t === "select") {
|
|
690
|
+
const mq = ctx.marqueeRef.current;
|
|
691
|
+
ctx.marqueeRef.current = null;
|
|
692
|
+
ctx.moveDownRef.current = null;
|
|
693
|
+
if (!mq) return;
|
|
694
|
+
const sc2 = ctx.screenCoordsOf(e);
|
|
695
|
+
if (!sc2) return;
|
|
696
|
+
const [ex, ey] = sc2;
|
|
697
|
+
if (mq.rect) {
|
|
698
|
+
try {
|
|
699
|
+
ctx.boardRef.current?.removeObject(mq.rect);
|
|
700
|
+
} catch {
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
if (Math.hypot(ex - mq.startSx, ey - mq.startSy) < 4) return;
|
|
704
|
+
const x1 = Math.min(mq.startSx, ex), x2 = Math.max(mq.startSx, ex);
|
|
705
|
+
const y1 = Math.min(mq.startSy, ey), y2 = Math.max(mq.startSy, ey);
|
|
706
|
+
const board = ctx.boardRef.current;
|
|
707
|
+
if (!board) return;
|
|
708
|
+
const list = board.objectsList || [];
|
|
709
|
+
for (const o of list) {
|
|
710
|
+
if (o === ctx.axisObjsRef.current.x || o === ctx.axisObjsRef.current.y) continue;
|
|
711
|
+
const kind = objKind(o);
|
|
712
|
+
if (kind === "point") {
|
|
713
|
+
const pc = o.coords?.scrCoords;
|
|
714
|
+
if (!pc) continue;
|
|
715
|
+
if (pc[1] >= x1 && pc[1] <= x2 && pc[2] >= y1 && pc[2] <= y2) {
|
|
716
|
+
if (!ctx.selectedSetRef.current.has(o)) {
|
|
717
|
+
ctx.selectedSetRef.current.add(o);
|
|
718
|
+
ctx.applySelectionStyle(o);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
} else if (kind === "line" || kind === "circle") {
|
|
722
|
+
const defs = [o.point1, o.point2, o.center, o.midpoint, o.point3].filter(Boolean);
|
|
723
|
+
const anyInside = defs.some((p) => {
|
|
724
|
+
const pc = p?.coords?.scrCoords;
|
|
725
|
+
return pc && pc[1] >= x1 && pc[1] <= x2 && pc[2] >= y1 && pc[2] <= y2;
|
|
726
|
+
});
|
|
727
|
+
if (anyInside && !ctx.selectedSetRef.current.has(o)) {
|
|
728
|
+
ctx.selectedSetRef.current.add(o);
|
|
729
|
+
ctx.applySelectionStyle(o);
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
ctx.setSelectionTick((tt) => tt + 1);
|
|
734
|
+
try {
|
|
735
|
+
board.update();
|
|
736
|
+
} catch {
|
|
737
|
+
}
|
|
738
|
+
return;
|
|
739
|
+
}
|
|
740
|
+
if (t !== "move") return;
|
|
741
|
+
const start = ctx.moveDownRef.current;
|
|
742
|
+
ctx.moveDownRef.current = null;
|
|
743
|
+
if (!start) return;
|
|
744
|
+
const sc = ctx.screenCoordsOf(e);
|
|
745
|
+
if (!sc) return;
|
|
746
|
+
const [sx, sy] = sc;
|
|
747
|
+
const moved = Math.hypot(sx - start.sx, sy - start.sy);
|
|
748
|
+
if (moved > 4) return;
|
|
749
|
+
const hits = ctx.objectsAt(e).map(ctx.promoteLabel).filter((o) => o !== ctx.axisObjsRef.current.x && o !== ctx.axisObjsRef.current.y);
|
|
750
|
+
const best = hits.find((o) => objKind(o) === "point") ?? hits[0] ?? ctx.findNearestPoint(e, 12);
|
|
751
|
+
if (!best) {
|
|
752
|
+
ctx.lastMoveClickRef.current = { obj: null, time: 0 };
|
|
753
|
+
return;
|
|
754
|
+
}
|
|
755
|
+
const now = Date.now();
|
|
756
|
+
const isDouble = ctx.lastMoveClickRef.current.obj === best && now - ctx.lastMoveClickRef.current.time < 400;
|
|
757
|
+
ctx.lastMoveClickRef.current = { obj: best, time: now };
|
|
758
|
+
if (!isDouble) return;
|
|
759
|
+
const cx = e.clientX ?? e.touches?.[0]?.clientX ?? 0;
|
|
760
|
+
const cy = e.clientY ?? e.touches?.[0]?.clientY ?? 0;
|
|
761
|
+
const snap = ctx.snapshotObject(best, { x: cx + 8, y: cy + 8 });
|
|
762
|
+
if (snap) ctx.emitSelect(snap);
|
|
763
|
+
}
|
|
764
|
+
function handleMove(ctx, e) {
|
|
765
|
+
if (ctx.toolRef.current === "select" && ctx.marqueeRef.current) {
|
|
766
|
+
const sc = ctx.screenCoordsOf(e);
|
|
767
|
+
if (sc && ctx.boardRef.current) {
|
|
768
|
+
const [sx, sy] = sc;
|
|
769
|
+
const { startSx, startSy } = ctx.marqueeRef.current;
|
|
770
|
+
const b = ctx.boardRef.current;
|
|
771
|
+
const ux1 = b.screenCoords2userCoords?.([Math.min(startSx, sx), Math.min(startSy, sy)]) ?? null;
|
|
772
|
+
const ux2 = b.screenCoords2userCoords?.([Math.max(startSx, sx), Math.max(startSy, sy)]) ?? null;
|
|
773
|
+
const toUsr = (px, py) => {
|
|
774
|
+
const ox = b.origin?.scrCoords?.[1] ?? 0;
|
|
775
|
+
const oy = b.origin?.scrCoords?.[2] ?? 0;
|
|
776
|
+
const ux = (px - ox) / b.unitX;
|
|
777
|
+
const uy = (oy - py) / b.unitY;
|
|
778
|
+
return [ux, uy];
|
|
779
|
+
};
|
|
780
|
+
const [x1u, y1u] = ux1 && ux1.length >= 2 ? [ux1[0], ux1[1]] : toUsr(Math.min(startSx, sx), Math.min(startSy, sy));
|
|
781
|
+
const [x2u, y2u] = ux2 && ux2.length >= 2 ? [ux2[0], ux2[1]] : toUsr(Math.max(startSx, sx), Math.max(startSy, sy));
|
|
782
|
+
const rect = ctx.marqueeRef.current.rect;
|
|
783
|
+
if (rect) {
|
|
784
|
+
try {
|
|
785
|
+
ctx.boardRef.current.removeObject(rect);
|
|
786
|
+
} catch {
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
try {
|
|
790
|
+
ctx.marqueeRef.current.rect = ctx.boardRef.current.create("polygon", [
|
|
791
|
+
[x1u, y1u],
|
|
792
|
+
[x2u, y1u],
|
|
793
|
+
[x2u, y2u],
|
|
794
|
+
[x1u, y2u]
|
|
795
|
+
], {
|
|
796
|
+
fillColor: "#06b6d4",
|
|
797
|
+
fillOpacity: 0.08,
|
|
798
|
+
borders: { strokeColor: "#06b6d4", strokeWidth: 1, dash: 2 },
|
|
799
|
+
vertices: { visible: false },
|
|
800
|
+
fixed: true,
|
|
801
|
+
highlight: false,
|
|
802
|
+
withLabel: false
|
|
803
|
+
});
|
|
804
|
+
} catch {
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
809
|
+
const ph = ctx.phantomRef.current;
|
|
810
|
+
if (!ph || !ctx.boardRef.current) return;
|
|
811
|
+
if (ctx.previewRafRef.current != null) return;
|
|
812
|
+
ctx.previewRafRef.current = requestAnimationFrame(() => {
|
|
813
|
+
ctx.previewRafRef.current = null;
|
|
814
|
+
if (!ctx.boardRef.current || !ctx.phantomRef.current) return;
|
|
815
|
+
try {
|
|
816
|
+
const coords = ctx.boardRef.current.getUsrCoordsOfMouse(e);
|
|
817
|
+
const JXG = ctx.jxgRef.current;
|
|
818
|
+
if (!JXG) return;
|
|
819
|
+
ctx.phantomRef.current.setPositionDirectly(JXG.COORDS_BY_USER, [coords[0], coords[1]]);
|
|
820
|
+
ctx.boardRef.current.update();
|
|
821
|
+
} catch {
|
|
822
|
+
}
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
var init_handlers = __esm({
|
|
826
|
+
"src/stamps/geometry-2d/editor/handlers.ts"() {
|
|
827
|
+
init_tools();
|
|
828
|
+
init_transforms();
|
|
829
|
+
}
|
|
830
|
+
});
|
|
831
|
+
var JSXGraphMiniBoard;
|
|
832
|
+
var init_MiniBoard = __esm({
|
|
833
|
+
"src/stamps/geometry-2d/editor/MiniBoard.tsx"() {
|
|
834
|
+
"use client";
|
|
835
|
+
init_transforms();
|
|
836
|
+
init_tools();
|
|
837
|
+
init_theme();
|
|
838
|
+
init_handlers();
|
|
839
|
+
JSXGraphMiniBoard = ({ onReady, initialState, isDark }) => {
|
|
840
|
+
const isDarkRef = react.useRef(!!isDark);
|
|
841
|
+
isDarkRef.current = !!isDark;
|
|
842
|
+
const containerId = react.useId().replace(/:/g, "_") + "_jxgmini";
|
|
843
|
+
const containerRef = react.useRef(null);
|
|
844
|
+
const boardRef = react.useRef(null);
|
|
845
|
+
const jxgRef = react.useRef(null);
|
|
846
|
+
const axisObjsRef = react.useRef({});
|
|
847
|
+
const creationLogRef = react.useRef([]);
|
|
848
|
+
const [tool, setTool] = react.useState("move");
|
|
849
|
+
const toolRef = react.useRef("move");
|
|
850
|
+
toolRef.current = tool;
|
|
851
|
+
const [showAxis, setShowAxis] = react.useState(initialState?.showAxis ?? false);
|
|
852
|
+
const [showGrid, setShowGrid] = react.useState(initialState?.showGrid ?? false);
|
|
853
|
+
const showAxisRef = react.useRef(showAxis);
|
|
854
|
+
showAxisRef.current = showAxis;
|
|
855
|
+
const showGridRef = react.useRef(showGrid);
|
|
856
|
+
showGridRef.current = showGrid;
|
|
857
|
+
const objMapRef = react.useRef(/* @__PURE__ */ new Map());
|
|
858
|
+
const valueLabelsRef = react.useRef(/* @__PURE__ */ new Map());
|
|
859
|
+
const pendingRef = react.useRef([]);
|
|
860
|
+
const [, setPendingCount] = react.useState(0);
|
|
861
|
+
const selectedSetRef = react.useRef(/* @__PURE__ */ new Set());
|
|
862
|
+
const selOriginalRef = react.useRef(/* @__PURE__ */ new Map());
|
|
863
|
+
const [, setSelectionTick] = react.useState(0);
|
|
864
|
+
const marqueeRef = react.useRef(null);
|
|
865
|
+
const previewSegRef = react.useRef([]);
|
|
866
|
+
const phantomRef = react.useRef(null);
|
|
867
|
+
const previewShapeRef = react.useRef(null);
|
|
868
|
+
const previewRafRef = react.useRef(null);
|
|
869
|
+
const [historyTick, setHistoryTick] = react.useState(0);
|
|
870
|
+
const [, setWarn] = react.useState(null);
|
|
871
|
+
const warnTimerRef = react.useRef(null);
|
|
872
|
+
const flashWarn = react.useCallback((msg) => {
|
|
873
|
+
if (warnTimerRef.current) clearTimeout(warnTimerRef.current);
|
|
874
|
+
setWarn(msg);
|
|
875
|
+
warnTimerRef.current = setTimeout(() => setWarn(null), 1800);
|
|
876
|
+
}, []);
|
|
877
|
+
react.useEffect(() => () => {
|
|
878
|
+
if (warnTimerRef.current) clearTimeout(warnTimerRef.current);
|
|
879
|
+
}, []);
|
|
880
|
+
const labelIdxRef = react.useRef(0);
|
|
881
|
+
const nextLabel = react.useCallback(() => {
|
|
882
|
+
const idx = labelIdxRef.current;
|
|
883
|
+
const suffix = idx >= 26 ? String(Math.floor(idx / 26)) : "";
|
|
884
|
+
const code = "A".charCodeAt(0) + idx % 26;
|
|
885
|
+
labelIdxRef.current = idx + 1;
|
|
886
|
+
return String.fromCharCode(code) + suffix;
|
|
887
|
+
}, []);
|
|
888
|
+
const nextLocalId = react.useCallback(() => "j" + creationLogRef.current.length, []);
|
|
889
|
+
const resolveArgs = react.useCallback((args) => {
|
|
890
|
+
return args.map((a) => {
|
|
891
|
+
if (typeof a === "string" && objMapRef.current.has(a)) {
|
|
892
|
+
return objMapRef.current.get(a);
|
|
893
|
+
}
|
|
894
|
+
return a;
|
|
895
|
+
});
|
|
896
|
+
}, []);
|
|
897
|
+
const pushLog = react.useCallback(
|
|
898
|
+
(id, type, args, attrs, obj) => {
|
|
899
|
+
creationLogRef.current.push({ id, type, args, attrs });
|
|
900
|
+
objMapRef.current.set(id, obj);
|
|
901
|
+
setHistoryTick((t) => t + 1);
|
|
902
|
+
},
|
|
903
|
+
[]
|
|
904
|
+
);
|
|
905
|
+
const create = react.useCallback(
|
|
906
|
+
(type, args, attrs = {}) => {
|
|
907
|
+
if (!boardRef.current) return null;
|
|
908
|
+
const id = nextLocalId();
|
|
909
|
+
const resolved = resolveArgs(args);
|
|
910
|
+
const resolvedAttrs = resolveAttrColors(attrs, paletteFor(isDarkRef.current));
|
|
911
|
+
const obj = boardRef.current.create(type, resolved, resolvedAttrs);
|
|
912
|
+
pushLog(id, type, args, attrs, obj);
|
|
913
|
+
return obj;
|
|
914
|
+
},
|
|
915
|
+
[nextLocalId, resolveArgs, pushLog]
|
|
916
|
+
);
|
|
917
|
+
const localIdOf = react.useCallback((obj) => {
|
|
918
|
+
for (const [id, o] of objMapRef.current.entries()) {
|
|
919
|
+
if (o === obj) return id;
|
|
920
|
+
}
|
|
921
|
+
return null;
|
|
922
|
+
}, []);
|
|
923
|
+
const snapshotObject = react.useCallback((obj, anchorScreen) => {
|
|
924
|
+
const o = obj;
|
|
925
|
+
const k = objKind(o);
|
|
926
|
+
if (k !== "point" && k !== "line" && k !== "circle") return null;
|
|
927
|
+
const v = o.visProp ?? {};
|
|
928
|
+
const showLabel = v.withlabel !== false;
|
|
929
|
+
const showValue = valueLabelsRef.current.has(o);
|
|
930
|
+
return {
|
|
931
|
+
obj: o,
|
|
932
|
+
kind: k,
|
|
933
|
+
name: typeof o.name === "string" ? o.name : "",
|
|
934
|
+
color: v.strokecolor ?? "#1e1e1e",
|
|
935
|
+
dash: typeof v.dash === "number" ? v.dash : 0,
|
|
936
|
+
width: typeof v.strokewidth === "number" ? v.strokewidth : 2,
|
|
937
|
+
face: v.face ?? "o",
|
|
938
|
+
showLabel,
|
|
939
|
+
showValue,
|
|
940
|
+
screenCoords: anchorScreen
|
|
941
|
+
};
|
|
942
|
+
}, []);
|
|
943
|
+
const createValueLabelFor = react.useCallback((target) => {
|
|
944
|
+
const b = boardRef.current;
|
|
945
|
+
if (!b || !target) return null;
|
|
946
|
+
const k = objKind(target);
|
|
947
|
+
if (k === "line") {
|
|
948
|
+
const p1 = target.point1;
|
|
949
|
+
const p2 = target.point2;
|
|
950
|
+
if (!p1 || !p2) return null;
|
|
951
|
+
const txt = b.create("text", [
|
|
952
|
+
() => (p1.X() + p2.X()) / 2 + 0.15,
|
|
953
|
+
() => (p1.Y() + p2.Y()) / 2 + 0.25,
|
|
954
|
+
() => {
|
|
955
|
+
const dx = p2.X() - p1.X();
|
|
956
|
+
const dy = p2.Y() - p1.Y();
|
|
957
|
+
const len = Math.hypot(dx, dy);
|
|
958
|
+
const name = typeof target.name === "string" && target.name ? target.name : "d";
|
|
959
|
+
return `${name} = ${len.toFixed(2)}`;
|
|
960
|
+
}
|
|
961
|
+
], { fontSize: 12, color: "#dc2626", fixed: true, highlight: false });
|
|
962
|
+
return txt;
|
|
963
|
+
}
|
|
964
|
+
if (k === "circle") {
|
|
965
|
+
const center = target.center ?? target.midpoint;
|
|
966
|
+
if (!center) return null;
|
|
967
|
+
const txt = b.create("text", [
|
|
968
|
+
() => center.X() + 0.3,
|
|
969
|
+
() => center.Y() + 0.3,
|
|
970
|
+
() => {
|
|
971
|
+
const r = typeof target.Radius === "function" ? target.Radius() : 0;
|
|
972
|
+
const name = typeof target.name === "string" && target.name ? target.name : "r";
|
|
973
|
+
return `${name} = ${r.toFixed(2)}`;
|
|
974
|
+
}
|
|
975
|
+
], { fontSize: 12, color: "#dc2626", fixed: true, highlight: false });
|
|
976
|
+
return txt;
|
|
977
|
+
}
|
|
978
|
+
return null;
|
|
979
|
+
}, []);
|
|
980
|
+
const mutateObject = react.useCallback((obj, patch) => {
|
|
981
|
+
if (!boardRef.current) return;
|
|
982
|
+
const o = obj;
|
|
983
|
+
if (patch.remove) {
|
|
984
|
+
const vl = valueLabelsRef.current.get(o);
|
|
985
|
+
if (vl) {
|
|
986
|
+
try {
|
|
987
|
+
boardRef.current.removeObject(vl);
|
|
988
|
+
} catch {
|
|
989
|
+
}
|
|
990
|
+
valueLabelsRef.current.delete(o);
|
|
991
|
+
}
|
|
992
|
+
try {
|
|
993
|
+
boardRef.current.removeObject(o);
|
|
994
|
+
} catch {
|
|
995
|
+
}
|
|
996
|
+
const board = boardRef.current;
|
|
997
|
+
const aliveIds = /* @__PURE__ */ new Set();
|
|
998
|
+
for (const [id, obj2] of objMapRef.current.entries()) {
|
|
999
|
+
const jxgId = obj2?.id;
|
|
1000
|
+
if (jxgId && board && board.objects && board.objects[jxgId]) {
|
|
1001
|
+
aliveIds.add(id);
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
creationLogRef.current = creationLogRef.current.filter((e) => aliveIds.has(e.id));
|
|
1005
|
+
for (const id of Array.from(objMapRef.current.keys())) {
|
|
1006
|
+
if (!aliveIds.has(id)) objMapRef.current.delete(id);
|
|
1007
|
+
}
|
|
1008
|
+
setHistoryTick((t) => t + 1);
|
|
1009
|
+
return;
|
|
1010
|
+
}
|
|
1011
|
+
if (typeof patch.valueLabel === "boolean") {
|
|
1012
|
+
const has = valueLabelsRef.current.has(o);
|
|
1013
|
+
if (patch.valueLabel && !has) {
|
|
1014
|
+
const txt = createValueLabelFor(o);
|
|
1015
|
+
if (txt) {
|
|
1016
|
+
valueLabelsRef.current.set(o, txt);
|
|
1017
|
+
const targetId = localIdOf(o);
|
|
1018
|
+
if (targetId) {
|
|
1019
|
+
const id = nextLocalId();
|
|
1020
|
+
creationLogRef.current.push({ id, type: "valueLabel", args: [targetId], attrs: {} });
|
|
1021
|
+
objMapRef.current.set(id, txt);
|
|
1022
|
+
setHistoryTick((t) => t + 1);
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
} else if (!patch.valueLabel && has) {
|
|
1026
|
+
const txt = valueLabelsRef.current.get(o);
|
|
1027
|
+
valueLabelsRef.current.delete(o);
|
|
1028
|
+
if (txt) {
|
|
1029
|
+
try {
|
|
1030
|
+
boardRef.current.removeObject(txt);
|
|
1031
|
+
} catch {
|
|
1032
|
+
}
|
|
1033
|
+
const txtId = localIdOf(txt);
|
|
1034
|
+
if (txtId) {
|
|
1035
|
+
creationLogRef.current = creationLogRef.current.filter((e) => e.id !== txtId);
|
|
1036
|
+
objMapRef.current.delete(txtId);
|
|
1037
|
+
setHistoryTick((t) => t + 1);
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
if (patch.attrs) {
|
|
1043
|
+
try {
|
|
1044
|
+
o.setAttribute(patch.attrs);
|
|
1045
|
+
} catch {
|
|
1046
|
+
}
|
|
1047
|
+
const id = localIdOf(o);
|
|
1048
|
+
if (id) {
|
|
1049
|
+
const entry = creationLogRef.current.find((e) => e.id === id);
|
|
1050
|
+
if (entry) entry.attrs = { ...entry.attrs, ...patch.attrs };
|
|
1051
|
+
setHistoryTick((t) => t + 1);
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
try {
|
|
1055
|
+
boardRef.current.update();
|
|
1056
|
+
} catch {
|
|
1057
|
+
}
|
|
1058
|
+
}, [createValueLabelFor, localIdOf, nextLocalId]);
|
|
1059
|
+
const clearPreviewSegs = react.useCallback(() => {
|
|
1060
|
+
const b = boardRef.current;
|
|
1061
|
+
if (!b) return;
|
|
1062
|
+
for (const s of previewSegRef.current) {
|
|
1063
|
+
try {
|
|
1064
|
+
b.removeObject(s);
|
|
1065
|
+
} catch {
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
previewSegRef.current = [];
|
|
1069
|
+
}, []);
|
|
1070
|
+
const removePhantom = react.useCallback(() => {
|
|
1071
|
+
const b = boardRef.current;
|
|
1072
|
+
if (!b) return;
|
|
1073
|
+
if (previewShapeRef.current) {
|
|
1074
|
+
try {
|
|
1075
|
+
b.removeObject(previewShapeRef.current);
|
|
1076
|
+
} catch {
|
|
1077
|
+
}
|
|
1078
|
+
previewShapeRef.current = null;
|
|
1079
|
+
}
|
|
1080
|
+
if (phantomRef.current) {
|
|
1081
|
+
try {
|
|
1082
|
+
b.removeObject(phantomRef.current);
|
|
1083
|
+
} catch {
|
|
1084
|
+
}
|
|
1085
|
+
phantomRef.current = null;
|
|
1086
|
+
}
|
|
1087
|
+
}, []);
|
|
1088
|
+
const clearPending = react.useCallback(() => {
|
|
1089
|
+
removePhantom();
|
|
1090
|
+
clearPreviewSegs();
|
|
1091
|
+
pendingRef.current = [];
|
|
1092
|
+
setPendingCount(0);
|
|
1093
|
+
}, [clearPreviewSegs, removePhantom]);
|
|
1094
|
+
const applySelectionStyle = react.useCallback((obj) => {
|
|
1095
|
+
if (!obj || selOriginalRef.current.has(obj)) return;
|
|
1096
|
+
try {
|
|
1097
|
+
const visProp = obj.visProp ?? {};
|
|
1098
|
+
selOriginalRef.current.set(obj, {
|
|
1099
|
+
strokeColor: visProp.strokecolor,
|
|
1100
|
+
strokeWidth: visProp.strokewidth
|
|
1101
|
+
});
|
|
1102
|
+
const kind = objKind(obj);
|
|
1103
|
+
if (kind === "point") {
|
|
1104
|
+
obj.setAttribute({ strokeColor: "#06b6d4", strokeWidth: 3 });
|
|
1105
|
+
} else {
|
|
1106
|
+
obj.setAttribute({ strokeColor: "#06b6d4", strokeWidth: 3 });
|
|
1107
|
+
}
|
|
1108
|
+
} catch {
|
|
1109
|
+
}
|
|
1110
|
+
}, []);
|
|
1111
|
+
const restoreSelectionStyle = react.useCallback((obj) => {
|
|
1112
|
+
const orig = selOriginalRef.current.get(obj);
|
|
1113
|
+
if (!orig) return;
|
|
1114
|
+
try {
|
|
1115
|
+
const attrs = {};
|
|
1116
|
+
if (orig.strokeColor !== void 0) attrs.strokeColor = orig.strokeColor;
|
|
1117
|
+
if (orig.strokeWidth !== void 0) attrs.strokeWidth = orig.strokeWidth;
|
|
1118
|
+
obj.setAttribute(attrs);
|
|
1119
|
+
} catch {
|
|
1120
|
+
}
|
|
1121
|
+
selOriginalRef.current.delete(obj);
|
|
1122
|
+
}, []);
|
|
1123
|
+
const clearSelection = react.useCallback(() => {
|
|
1124
|
+
for (const o of selectedSetRef.current) {
|
|
1125
|
+
restoreSelectionStyle(o);
|
|
1126
|
+
}
|
|
1127
|
+
selectedSetRef.current.clear();
|
|
1128
|
+
setSelectionTick((t) => t + 1);
|
|
1129
|
+
try {
|
|
1130
|
+
boardRef.current?.update();
|
|
1131
|
+
} catch {
|
|
1132
|
+
}
|
|
1133
|
+
}, [restoreSelectionStyle]);
|
|
1134
|
+
const toggleSelect = react.useCallback((obj, additive) => {
|
|
1135
|
+
if (!obj) return;
|
|
1136
|
+
if (!additive) {
|
|
1137
|
+
for (const o of selectedSetRef.current) {
|
|
1138
|
+
if (o !== obj) restoreSelectionStyle(o);
|
|
1139
|
+
}
|
|
1140
|
+
selectedSetRef.current = /* @__PURE__ */ new Set([obj]);
|
|
1141
|
+
applySelectionStyle(obj);
|
|
1142
|
+
} else {
|
|
1143
|
+
if (selectedSetRef.current.has(obj)) {
|
|
1144
|
+
restoreSelectionStyle(obj);
|
|
1145
|
+
selectedSetRef.current.delete(obj);
|
|
1146
|
+
} else {
|
|
1147
|
+
selectedSetRef.current.add(obj);
|
|
1148
|
+
applySelectionStyle(obj);
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
setSelectionTick((t) => t + 1);
|
|
1152
|
+
try {
|
|
1153
|
+
boardRef.current?.update();
|
|
1154
|
+
} catch {
|
|
1155
|
+
}
|
|
1156
|
+
}, [applySelectionStyle, restoreSelectionStyle]);
|
|
1157
|
+
const deleteSelected = react.useCallback(() => {
|
|
1158
|
+
const board = boardRef.current;
|
|
1159
|
+
if (!board) return;
|
|
1160
|
+
if (selectedSetRef.current.size === 0) return;
|
|
1161
|
+
for (const o of selectedSetRef.current) selOriginalRef.current.delete(o);
|
|
1162
|
+
for (const o of selectedSetRef.current) {
|
|
1163
|
+
try {
|
|
1164
|
+
board.removeObject(o);
|
|
1165
|
+
} catch {
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
selectedSetRef.current.clear();
|
|
1169
|
+
const aliveIds = /* @__PURE__ */ new Set();
|
|
1170
|
+
for (const [id, o] of objMapRef.current.entries()) {
|
|
1171
|
+
const jxgId = o?.id;
|
|
1172
|
+
if (jxgId && board.objects && board.objects[jxgId]) aliveIds.add(id);
|
|
1173
|
+
}
|
|
1174
|
+
creationLogRef.current = creationLogRef.current.filter((e) => aliveIds.has(e.id));
|
|
1175
|
+
for (const id of Array.from(objMapRef.current.keys())) {
|
|
1176
|
+
if (!aliveIds.has(id)) objMapRef.current.delete(id);
|
|
1177
|
+
}
|
|
1178
|
+
setSelectionTick((t) => t + 1);
|
|
1179
|
+
setHistoryTick((t) => t + 1);
|
|
1180
|
+
}, []);
|
|
1181
|
+
const buildPreview = react.useCallback((toolDef, picks, phantom) => {
|
|
1182
|
+
const b = boardRef.current;
|
|
1183
|
+
if (!b) return null;
|
|
1184
|
+
const style = { strokeColor: "#3b82f6", strokeWidth: 1.5, strokeOpacity: 0.65, dash: 2, fixed: true, highlight: false, withLabel: false };
|
|
1185
|
+
const circStyle = { ...style, fillColor: "none", fillOpacity: 0 };
|
|
1186
|
+
try {
|
|
1187
|
+
switch (toolDef.key) {
|
|
1188
|
+
case "segment":
|
|
1189
|
+
case "midpoint":
|
|
1190
|
+
case "distance":
|
|
1191
|
+
return b.create("segment", [picks[0], phantom], style);
|
|
1192
|
+
case "line":
|
|
1193
|
+
return b.create("line", [picks[0], phantom], style);
|
|
1194
|
+
case "ray":
|
|
1195
|
+
return b.create("line", [picks[0], phantom], { ...style, straightFirst: false, straightLast: true });
|
|
1196
|
+
case "vector":
|
|
1197
|
+
return b.create("arrow", [picks[0], phantom], style);
|
|
1198
|
+
case "circleCenter":
|
|
1199
|
+
return b.create("circle", [picks[0], phantom], circStyle);
|
|
1200
|
+
case "circle3":
|
|
1201
|
+
if (picks.length === 1) return b.create("circle", [picks[0], phantom], circStyle);
|
|
1202
|
+
if (picks.length === 2) return b.create("circumcircle", [picks[0], picks[1], phantom], circStyle);
|
|
1203
|
+
return null;
|
|
1204
|
+
case "angle":
|
|
1205
|
+
if (picks.length === 1) return b.create("segment", [picks[0], phantom], style);
|
|
1206
|
+
if (picks.length === 2) return b.create("angle", [picks[0], picks[1], phantom], { ...style, radius: 1, fillColor: "#22c55e", fillOpacity: 0.15 });
|
|
1207
|
+
return null;
|
|
1208
|
+
case "perpBisector":
|
|
1209
|
+
return b.create("segment", [picks[0], phantom], style);
|
|
1210
|
+
case "angleBisector":
|
|
1211
|
+
if (picks.length === 1) return b.create("segment", [picks[0], phantom], style);
|
|
1212
|
+
if (picks.length === 2) return b.create("bisector", [picks[0], picks[1], phantom], style);
|
|
1213
|
+
return null;
|
|
1214
|
+
case "perpendicular":
|
|
1215
|
+
case "parallel":
|
|
1216
|
+
case "tangent":
|
|
1217
|
+
if (picks.length === 1) {
|
|
1218
|
+
const k = objKind(picks[0]);
|
|
1219
|
+
if (k === "line" && toolDef.key !== "tangent") {
|
|
1220
|
+
return b.create(toolDef.key, [picks[0], phantom], style);
|
|
1221
|
+
}
|
|
1222
|
+
if (k === "circle" && toolDef.key === "tangent") {
|
|
1223
|
+
const glider = b.create("glider", [phantom.X(), phantom.Y(), picks[0]], { visible: false, withLabel: false });
|
|
1224
|
+
return b.create("tangent", [glider], style);
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
return null;
|
|
1228
|
+
default:
|
|
1229
|
+
return null;
|
|
1230
|
+
}
|
|
1231
|
+
} catch {
|
|
1232
|
+
return null;
|
|
1233
|
+
}
|
|
1234
|
+
}, []);
|
|
1235
|
+
const refreshPreview = react.useCallback(() => {
|
|
1236
|
+
const b = boardRef.current;
|
|
1237
|
+
if (!b) return;
|
|
1238
|
+
if (previewShapeRef.current) {
|
|
1239
|
+
try {
|
|
1240
|
+
b.removeObject(previewShapeRef.current);
|
|
1241
|
+
} catch {
|
|
1242
|
+
}
|
|
1243
|
+
previewShapeRef.current = null;
|
|
1244
|
+
}
|
|
1245
|
+
const t = toolRef.current;
|
|
1246
|
+
const toolDef = TOOLS.find((td) => td.key === t);
|
|
1247
|
+
if (!toolDef) return;
|
|
1248
|
+
const picks = pendingRef.current;
|
|
1249
|
+
if (picks.length === 0 || toolDef.needs <= 0) return;
|
|
1250
|
+
if (picks.length >= toolDef.needs) return;
|
|
1251
|
+
if (!phantomRef.current) {
|
|
1252
|
+
try {
|
|
1253
|
+
phantomRef.current = b.create("point", [0, 0], { visible: false, fixed: true, withLabel: false, name: "" });
|
|
1254
|
+
} catch {
|
|
1255
|
+
return;
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
previewShapeRef.current = buildPreview(toolDef, picks, phantomRef.current);
|
|
1259
|
+
}, [buildPreview]);
|
|
1260
|
+
const finalize = react.useCallback((toolDef, picks) => {
|
|
1261
|
+
if (!boardRef.current) return;
|
|
1262
|
+
const labels = picks.map(localIdOf).filter(Boolean);
|
|
1263
|
+
const stroke = { strokeColor: "@stroke", strokeWidth: 2 };
|
|
1264
|
+
const strokeOnly = { ...stroke, fillColor: "none", fillOpacity: 0 };
|
|
1265
|
+
const lblName = nextLabel();
|
|
1266
|
+
switch (toolDef.key) {
|
|
1267
|
+
case "midpoint":
|
|
1268
|
+
create("midpoint", labels, { name: lblName, color: "@stroke", size: 3 });
|
|
1269
|
+
break;
|
|
1270
|
+
case "segment":
|
|
1271
|
+
create("segment", labels, stroke);
|
|
1272
|
+
break;
|
|
1273
|
+
case "line":
|
|
1274
|
+
create("line", labels, stroke);
|
|
1275
|
+
break;
|
|
1276
|
+
case "ray": {
|
|
1277
|
+
create("line", labels, { ...stroke, straightFirst: false, straightLast: true });
|
|
1278
|
+
break;
|
|
1279
|
+
}
|
|
1280
|
+
case "vector":
|
|
1281
|
+
create("arrow", labels, stroke);
|
|
1282
|
+
break;
|
|
1283
|
+
case "perpendicular": {
|
|
1284
|
+
const [p, l] = picks[0] && objKind(picks[0]) === "point" ? [labels[0], labels[1]] : [labels[1], labels[0]];
|
|
1285
|
+
create("perpendicular", [l, p], stroke);
|
|
1286
|
+
break;
|
|
1287
|
+
}
|
|
1288
|
+
case "parallel": {
|
|
1289
|
+
const [p, l] = picks[0] && objKind(picks[0]) === "point" ? [labels[0], labels[1]] : [labels[1], labels[0]];
|
|
1290
|
+
create("parallel", [l, p], stroke);
|
|
1291
|
+
break;
|
|
1292
|
+
}
|
|
1293
|
+
case "perpBisector": {
|
|
1294
|
+
const mid = create("midpoint", labels, { visible: false, withLabel: false, name: "" });
|
|
1295
|
+
const seg = create("segment", labels, { visible: false, withLabel: false });
|
|
1296
|
+
const midId = localIdOf(mid);
|
|
1297
|
+
const segId = localIdOf(seg);
|
|
1298
|
+
if (midId && segId) create("perpendicular", [segId, midId], stroke);
|
|
1299
|
+
break;
|
|
1300
|
+
}
|
|
1301
|
+
case "angleBisector":
|
|
1302
|
+
create("bisector", labels, stroke);
|
|
1303
|
+
break;
|
|
1304
|
+
case "circleCenter":
|
|
1305
|
+
create("circle", labels, strokeOnly);
|
|
1306
|
+
break;
|
|
1307
|
+
case "circle3":
|
|
1308
|
+
create("circumcircle", labels, strokeOnly);
|
|
1309
|
+
break;
|
|
1310
|
+
case "tangent": {
|
|
1311
|
+
const firstIsPoint = picks[0] && objKind(picks[0]) === "point";
|
|
1312
|
+
const pointPick = firstIsPoint ? picks[0] : picks[1];
|
|
1313
|
+
const circleLabel = firstIsPoint ? labels[1] : labels[0];
|
|
1314
|
+
if (!pointPick || !circleLabel) break;
|
|
1315
|
+
const px = typeof pointPick.X === "function" ? pointPick.X() : 0;
|
|
1316
|
+
const py = typeof pointPick.Y === "function" ? pointPick.Y() : 0;
|
|
1317
|
+
const glider = create("glider", [px, py, circleLabel], { name: "", size: 2, strokeColor: "#666", visible: false });
|
|
1318
|
+
const gid = localIdOf(glider);
|
|
1319
|
+
if (gid) create("tangent", [gid], stroke);
|
|
1320
|
+
break;
|
|
1321
|
+
}
|
|
1322
|
+
case "angle": {
|
|
1323
|
+
const [pa, pb, pc] = picks;
|
|
1324
|
+
let order = labels;
|
|
1325
|
+
try {
|
|
1326
|
+
const ax = pa.X() - pb.X(), ay = pa.Y() - pb.Y();
|
|
1327
|
+
const cx = pc.X() - pb.X(), cy = pc.Y() - pb.Y();
|
|
1328
|
+
const cross = ax * cy - ay * cx;
|
|
1329
|
+
if (cross < 0) order = [labels[2], labels[1], labels[0]];
|
|
1330
|
+
} catch {
|
|
1331
|
+
}
|
|
1332
|
+
create("angle", order, {
|
|
1333
|
+
radius: 1,
|
|
1334
|
+
fillColor: "#22c55e",
|
|
1335
|
+
fillOpacity: 0.25,
|
|
1336
|
+
strokeColor: "#16a34a",
|
|
1337
|
+
strokeWidth: 1.5,
|
|
1338
|
+
name: "",
|
|
1339
|
+
withLabel: false
|
|
1340
|
+
});
|
|
1341
|
+
break;
|
|
1342
|
+
}
|
|
1343
|
+
case "distance": {
|
|
1344
|
+
const pA = picks[0], pB = picks[1];
|
|
1345
|
+
const dist = Math.hypot(pA.X() - pB.X(), pA.Y() - pB.Y());
|
|
1346
|
+
const midX = (pA.X() + pB.X()) / 2;
|
|
1347
|
+
const midY = (pA.Y() + pB.Y()) / 2;
|
|
1348
|
+
create("text", [midX, midY, `d = ${dist.toFixed(2)}`], { fontSize: 14, color: "#dc2626" });
|
|
1349
|
+
break;
|
|
1350
|
+
}
|
|
1351
|
+
case "polygon": {
|
|
1352
|
+
create("polygon", labels, { fillColor: "#1e3a8a", fillOpacity: 0.1, borders: { strokeColor: "@stroke", strokeWidth: 2 } });
|
|
1353
|
+
break;
|
|
1354
|
+
}
|
|
1355
|
+
case "area": {
|
|
1356
|
+
create("polygon", labels, { fillColor: "#3b82f6", fillOpacity: 0.18, borders: { strokeColor: "#1d4ed8", strokeWidth: 2 } });
|
|
1357
|
+
break;
|
|
1358
|
+
}
|
|
1359
|
+
case "toggleLabel": {
|
|
1360
|
+
const obj = picks[0];
|
|
1361
|
+
try {
|
|
1362
|
+
if (obj.label) {
|
|
1363
|
+
const visible = obj.label.visProp.visible !== false;
|
|
1364
|
+
obj.label.setAttribute({ visible: !visible });
|
|
1365
|
+
} else if (obj.setAttribute) {
|
|
1366
|
+
const cur = obj.visProp.withlabel !== false;
|
|
1367
|
+
obj.setAttribute({ withLabel: !cur });
|
|
1368
|
+
}
|
|
1369
|
+
boardRef.current.update();
|
|
1370
|
+
} catch {
|
|
1371
|
+
}
|
|
1372
|
+
break;
|
|
1373
|
+
}
|
|
1374
|
+
case "toggleVisible": {
|
|
1375
|
+
const obj = picks[0];
|
|
1376
|
+
try {
|
|
1377
|
+
const visible = obj.visProp.visible !== false;
|
|
1378
|
+
obj.setAttribute({ visible: !visible });
|
|
1379
|
+
boardRef.current.update();
|
|
1380
|
+
} catch {
|
|
1381
|
+
}
|
|
1382
|
+
break;
|
|
1383
|
+
}
|
|
1384
|
+
case "delete": {
|
|
1385
|
+
const obj = picks[0];
|
|
1386
|
+
try {
|
|
1387
|
+
boardRef.current.removeObject(obj);
|
|
1388
|
+
const board = boardRef.current;
|
|
1389
|
+
const aliveIds = /* @__PURE__ */ new Set();
|
|
1390
|
+
for (const [id, o] of objMapRef.current.entries()) {
|
|
1391
|
+
const jxgId = o?.id;
|
|
1392
|
+
if (jxgId && board && board.objects && board.objects[jxgId]) {
|
|
1393
|
+
aliveIds.add(id);
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
creationLogRef.current = creationLogRef.current.filter((e) => aliveIds.has(e.id));
|
|
1397
|
+
for (const id of Array.from(objMapRef.current.keys())) {
|
|
1398
|
+
if (!aliveIds.has(id)) objMapRef.current.delete(id);
|
|
1399
|
+
}
|
|
1400
|
+
setHistoryTick((t) => t + 1);
|
|
1401
|
+
} catch {
|
|
1402
|
+
}
|
|
1403
|
+
break;
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
}, [create, localIdOf, nextLabel]);
|
|
1407
|
+
const finalizeTransformCreate = react.useCallback((spec, source) => {
|
|
1408
|
+
if (!boardRef.current) return;
|
|
1409
|
+
const def = getDefiningPoints(source);
|
|
1410
|
+
if (!def) {
|
|
1411
|
+
flashWarn("Kh\xF4ng th\u1EC3 bi\u1EBFn \u0111\u1ED5i \u0111\u1ED1i t\u01B0\u1EE3ng n\xE0y");
|
|
1412
|
+
return;
|
|
1413
|
+
}
|
|
1414
|
+
const transformObjs = [];
|
|
1415
|
+
const transformIds = [];
|
|
1416
|
+
const steps = spec.chain ?? [{ params: spec.params, attrs: spec.attrs }];
|
|
1417
|
+
for (const step of steps) {
|
|
1418
|
+
const stepLogArgs = [];
|
|
1419
|
+
for (const p of step.params) {
|
|
1420
|
+
if (typeof p === "function") {
|
|
1421
|
+
flashWarn("Tham s\u1ED1 transform kh\xF4ng serialize \u0111\u01B0\u1EE3c \u2014 b\u1ECF qua");
|
|
1422
|
+
return;
|
|
1423
|
+
}
|
|
1424
|
+
if (p && typeof p === "object") {
|
|
1425
|
+
const id = localIdOf(p);
|
|
1426
|
+
if (!id) {
|
|
1427
|
+
flashWarn("\u0110\u1ED1i t\u01B0\u1EE3ng tham chi\u1EBFu kh\xF4ng n\u1EB1m trong board \u2014 kh\xF4ng th\u1EC3 bi\u1EBFn \u0111\u1ED5i");
|
|
1428
|
+
return;
|
|
1429
|
+
}
|
|
1430
|
+
stepLogArgs.push(id);
|
|
1431
|
+
} else {
|
|
1432
|
+
stepLogArgs.push(p);
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
const stepId = nextLocalId();
|
|
1436
|
+
const stepObj = boardRef.current.create("transform", step.params, step.attrs);
|
|
1437
|
+
creationLogRef.current.push({ id: stepId, type: "transform", args: stepLogArgs, attrs: step.attrs });
|
|
1438
|
+
objMapRef.current.set(stepId, stepObj);
|
|
1439
|
+
transformObjs.push(stepObj);
|
|
1440
|
+
transformIds.push(stepId);
|
|
1441
|
+
}
|
|
1442
|
+
const transformParent = transformObjs.length === 1 ? transformObjs[0] : transformObjs;
|
|
1443
|
+
const transformLogRef = transformObjs.length === 1 ? transformIds[0] : transformIds;
|
|
1444
|
+
const transformedPoints = def.points.map((src) => {
|
|
1445
|
+
const srcId = localIdOf(src);
|
|
1446
|
+
const id = nextLocalId();
|
|
1447
|
+
const srcName = typeof src.name === "string" ? src.name : "";
|
|
1448
|
+
const newName = srcName ? `${srcName}'` : nextLabel();
|
|
1449
|
+
const attrs = { name: newName, size: 3, color: "#0ea5e9", strokeColor: "#0ea5e9", fillColor: "#0ea5e9" };
|
|
1450
|
+
const obj = boardRef.current.create("point", [src, transformParent], attrs);
|
|
1451
|
+
creationLogRef.current.push({ id, type: "point", args: [srcId ?? src, transformLogRef], attrs });
|
|
1452
|
+
objMapRef.current.set(id, obj);
|
|
1453
|
+
return obj;
|
|
1454
|
+
});
|
|
1455
|
+
const baseStyle = { ...def.attrs, strokeColor: "#0ea5e9" };
|
|
1456
|
+
const strokeOnly = { ...baseStyle, fillColor: "none", fillOpacity: 0 };
|
|
1457
|
+
const ids = transformedPoints.map((p) => localIdOf(p)).filter((s) => !!s);
|
|
1458
|
+
switch (def.kind) {
|
|
1459
|
+
case "point":
|
|
1460
|
+
break;
|
|
1461
|
+
case "segment":
|
|
1462
|
+
create("segment", ids, baseStyle);
|
|
1463
|
+
break;
|
|
1464
|
+
case "line":
|
|
1465
|
+
create("line", ids, baseStyle);
|
|
1466
|
+
break;
|
|
1467
|
+
case "ray":
|
|
1468
|
+
create("line", ids, { ...baseStyle, straightFirst: false, straightLast: true });
|
|
1469
|
+
break;
|
|
1470
|
+
case "arrow":
|
|
1471
|
+
create("arrow", ids, baseStyle);
|
|
1472
|
+
break;
|
|
1473
|
+
case "circleCenter":
|
|
1474
|
+
create("circle", ids, strokeOnly);
|
|
1475
|
+
break;
|
|
1476
|
+
case "circle3":
|
|
1477
|
+
create("circumcircle", ids, strokeOnly);
|
|
1478
|
+
break;
|
|
1479
|
+
}
|
|
1480
|
+
setHistoryTick((t) => t + 1);
|
|
1481
|
+
}, [create, flashWarn, localIdOf, nextLabel, nextLocalId]);
|
|
1482
|
+
const undoLast = react.useCallback(() => {
|
|
1483
|
+
const b = boardRef.current;
|
|
1484
|
+
if (!b) return;
|
|
1485
|
+
while (creationLogRef.current.length > 0) {
|
|
1486
|
+
const last = creationLogRef.current.pop();
|
|
1487
|
+
if (!last) break;
|
|
1488
|
+
const obj = objMapRef.current.get(last.id);
|
|
1489
|
+
objMapRef.current.delete(last.id);
|
|
1490
|
+
if (obj) {
|
|
1491
|
+
try {
|
|
1492
|
+
b.removeObject(obj);
|
|
1493
|
+
} catch {
|
|
1494
|
+
}
|
|
1495
|
+
clearPending();
|
|
1496
|
+
setHistoryTick((t) => t + 1);
|
|
1497
|
+
try {
|
|
1498
|
+
b.update();
|
|
1499
|
+
} catch {
|
|
1500
|
+
}
|
|
1501
|
+
return;
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
setHistoryTick((t) => t + 1);
|
|
1505
|
+
}, [clearPending]);
|
|
1506
|
+
react.useEffect(() => {
|
|
1507
|
+
const onKey = (e) => {
|
|
1508
|
+
const ae = document.activeElement;
|
|
1509
|
+
const inField = !!(ae && (ae.tagName === "INPUT" || ae.tagName === "TEXTAREA" || ae.isContentEditable));
|
|
1510
|
+
if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === "z" && !e.shiftKey) {
|
|
1511
|
+
if (inField) return;
|
|
1512
|
+
e.preventDefault();
|
|
1513
|
+
e.stopPropagation();
|
|
1514
|
+
undoLastRef.current();
|
|
1515
|
+
return;
|
|
1516
|
+
}
|
|
1517
|
+
if (e.key === "Escape" && !inField) {
|
|
1518
|
+
if (pendingRef.current.length > 0) {
|
|
1519
|
+
e.preventDefault();
|
|
1520
|
+
e.stopPropagation();
|
|
1521
|
+
clearPendingRef.current();
|
|
1522
|
+
}
|
|
1523
|
+
if (selectedSetRef.current.size > 0) {
|
|
1524
|
+
e.preventDefault();
|
|
1525
|
+
e.stopPropagation();
|
|
1526
|
+
clearSelectionRef.current();
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
if ((e.key === "Delete" || e.key === "Backspace") && !inField) {
|
|
1530
|
+
if (selectedSetRef.current.size > 0) {
|
|
1531
|
+
e.preventDefault();
|
|
1532
|
+
e.stopPropagation();
|
|
1533
|
+
deleteSelectedRef.current();
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
};
|
|
1537
|
+
window.addEventListener("keydown", onKey, { capture: true });
|
|
1538
|
+
return () => window.removeEventListener("keydown", onKey, { capture: true });
|
|
1539
|
+
}, []);
|
|
1540
|
+
const screenCoordsOf = react.useCallback((evt) => {
|
|
1541
|
+
const b = boardRef.current;
|
|
1542
|
+
if (!b) return null;
|
|
1543
|
+
try {
|
|
1544
|
+
const mp = b.getMousePosition ? b.getMousePosition(evt) : null;
|
|
1545
|
+
if (mp && mp.length >= 2) return [mp[0], mp[1]];
|
|
1546
|
+
} catch {
|
|
1547
|
+
}
|
|
1548
|
+
if (containerRef.current) {
|
|
1549
|
+
const rect = containerRef.current.getBoundingClientRect();
|
|
1550
|
+
const cx = evt.clientX ?? evt.touches?.[0]?.clientX ?? 0;
|
|
1551
|
+
const cy = evt.clientY ?? evt.touches?.[0]?.clientY ?? 0;
|
|
1552
|
+
return [cx - rect.left, cy - rect.top];
|
|
1553
|
+
}
|
|
1554
|
+
return null;
|
|
1555
|
+
}, []);
|
|
1556
|
+
const objectsAt = react.useCallback((evt) => {
|
|
1557
|
+
const b = boardRef.current;
|
|
1558
|
+
if (!b) return [];
|
|
1559
|
+
const sc = screenCoordsOf(evt);
|
|
1560
|
+
if (!sc) return [];
|
|
1561
|
+
const [sx, sy] = sc;
|
|
1562
|
+
const list = [];
|
|
1563
|
+
try {
|
|
1564
|
+
const objs = b.objectsList || [];
|
|
1565
|
+
for (const o of objs) {
|
|
1566
|
+
try {
|
|
1567
|
+
if (o.hasPoint && o.hasPoint(sx, sy)) list.push(o);
|
|
1568
|
+
} catch {
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
} catch {
|
|
1572
|
+
}
|
|
1573
|
+
return list;
|
|
1574
|
+
}, [screenCoordsOf]);
|
|
1575
|
+
const findNearestPoint = react.useCallback((evt, tolPx = 12) => {
|
|
1576
|
+
const b = boardRef.current;
|
|
1577
|
+
if (!b) return null;
|
|
1578
|
+
const sc = screenCoordsOf(evt);
|
|
1579
|
+
if (!sc) return null;
|
|
1580
|
+
const [sx, sy] = sc;
|
|
1581
|
+
const tol2 = tolPx * tolPx;
|
|
1582
|
+
let best = null;
|
|
1583
|
+
try {
|
|
1584
|
+
const objs = b.objectsList || [];
|
|
1585
|
+
for (const o of objs) {
|
|
1586
|
+
try {
|
|
1587
|
+
if (objKind(o) !== "point") continue;
|
|
1588
|
+
const pc = o.coords?.scrCoords;
|
|
1589
|
+
if (!pc) continue;
|
|
1590
|
+
const dx = pc[1] - sx;
|
|
1591
|
+
const dy = pc[2] - sy;
|
|
1592
|
+
const d2 = dx * dx + dy * dy;
|
|
1593
|
+
if (d2 <= tol2 && (!best || d2 < best.d2)) best = { obj: o, d2 };
|
|
1594
|
+
} catch {
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
} catch {
|
|
1598
|
+
}
|
|
1599
|
+
return best ? best.obj : null;
|
|
1600
|
+
}, [screenCoordsOf]);
|
|
1601
|
+
const promoteLabel = react.useCallback((o) => {
|
|
1602
|
+
if (!o) return o;
|
|
1603
|
+
const t = (o.elType || o.type || "").toString().toLowerCase();
|
|
1604
|
+
if (t !== "text") return o;
|
|
1605
|
+
const b = boardRef.current;
|
|
1606
|
+
if (!b) return o;
|
|
1607
|
+
try {
|
|
1608
|
+
for (const c of b.objectsList || []) {
|
|
1609
|
+
if (c.label === o) return c;
|
|
1610
|
+
}
|
|
1611
|
+
} catch {
|
|
1612
|
+
}
|
|
1613
|
+
return o;
|
|
1614
|
+
}, []);
|
|
1615
|
+
const pendingTransformRef = react.useRef(null);
|
|
1616
|
+
const transformSubsRef = react.useRef(/* @__PURE__ */ new Set());
|
|
1617
|
+
const emitTransform = react.useCallback((info) => {
|
|
1618
|
+
transformSubsRef.current.forEach((cb) => {
|
|
1619
|
+
try {
|
|
1620
|
+
cb(info);
|
|
1621
|
+
} catch {
|
|
1622
|
+
}
|
|
1623
|
+
});
|
|
1624
|
+
}, []);
|
|
1625
|
+
const selectSubsRef = react.useRef(/* @__PURE__ */ new Set());
|
|
1626
|
+
const emitSelect = react.useCallback((snap) => {
|
|
1627
|
+
selectSubsRef.current.forEach((cb) => {
|
|
1628
|
+
try {
|
|
1629
|
+
cb(snap);
|
|
1630
|
+
} catch {
|
|
1631
|
+
}
|
|
1632
|
+
});
|
|
1633
|
+
}, []);
|
|
1634
|
+
const moveDownRef = react.useRef(null);
|
|
1635
|
+
const lastMoveClickRef = react.useRef({ obj: null, time: 0 });
|
|
1636
|
+
react.useEffect(() => {
|
|
1637
|
+
if (typeof window === "undefined" || !containerRef.current) return;
|
|
1638
|
+
let cancelled = false;
|
|
1639
|
+
(async () => {
|
|
1640
|
+
const JXG = (await import('jsxgraph')).default;
|
|
1641
|
+
if (cancelled || !containerRef.current) return;
|
|
1642
|
+
jxgRef.current = JXG;
|
|
1643
|
+
try {
|
|
1644
|
+
const opts = JXG.Options;
|
|
1645
|
+
if (opts) {
|
|
1646
|
+
opts.text = opts.text || {};
|
|
1647
|
+
opts.text.display = "internal";
|
|
1648
|
+
opts.text.useASCIIMathML = false;
|
|
1649
|
+
opts.text.useMathJax = false;
|
|
1650
|
+
opts.text.useKatex = false;
|
|
1651
|
+
opts.label = opts.label || {};
|
|
1652
|
+
opts.label.display = "internal";
|
|
1653
|
+
opts.label.strokeColor = themeLabel(isDarkRef.current);
|
|
1654
|
+
opts.text.strokeColor = themeLabel(isDarkRef.current);
|
|
1655
|
+
}
|
|
1656
|
+
} catch {
|
|
1657
|
+
}
|
|
1658
|
+
const board = JXG.JSXGraph.initBoard(containerId, {
|
|
1659
|
+
boundingbox: initialState?.bbox ?? [-10, 10, 10, -10],
|
|
1660
|
+
axis: false,
|
|
1661
|
+
// We manage axis manually via toggle for clean default
|
|
1662
|
+
grid: false,
|
|
1663
|
+
showCopyright: false,
|
|
1664
|
+
showNavigation: true,
|
|
1665
|
+
// Keep 1:1 user→pixel ratio so circles stay circular regardless of the
|
|
1666
|
+
// container aspect ratio (Excalidraw panel is taller than wide and
|
|
1667
|
+
// without this circles became ellipses after reload).
|
|
1668
|
+
keepAspectRatio: true,
|
|
1669
|
+
pan: { enabled: true, needShift: false },
|
|
1670
|
+
zoom: { wheel: true },
|
|
1671
|
+
// Looser hit-test radius so clicking on a thin segment/line/circle
|
|
1672
|
+
// actually registers without pixel-perfect aim. `precision` is a real
|
|
1673
|
+
// JSXGraph option (Options.precision) but isn't in the d.ts file.
|
|
1674
|
+
...{ precision: { hasPoint: 8, mouse: 4, touch: 16 } }
|
|
1675
|
+
});
|
|
1676
|
+
boardRef.current = board;
|
|
1677
|
+
if (initialState && initialState.elements.length > 0) {
|
|
1678
|
+
const idMap = objMapRef.current;
|
|
1679
|
+
for (const el of initialState.elements) {
|
|
1680
|
+
const resolved = el.args.map((a) => typeof a === "string" && idMap.has(a) ? idMap.get(a) : a);
|
|
1681
|
+
try {
|
|
1682
|
+
if (el.type === "valueLabel") {
|
|
1683
|
+
const target = resolved[0];
|
|
1684
|
+
if (target) {
|
|
1685
|
+
const txt = createValueLabelFor(target);
|
|
1686
|
+
if (txt) {
|
|
1687
|
+
idMap.set(el.id, txt);
|
|
1688
|
+
valueLabelsRef.current.set(target, txt);
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
continue;
|
|
1692
|
+
}
|
|
1693
|
+
const themedAttrs = resolveAttrColors({ ...el.attrs }, paletteFor(isDarkRef.current));
|
|
1694
|
+
const obj = board.create(el.type, resolved, themedAttrs);
|
|
1695
|
+
idMap.set(el.id, obj);
|
|
1696
|
+
} catch (err) {
|
|
1697
|
+
console.warn("Replay failed for", el.type, err);
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
creationLogRef.current = [...initialState.elements];
|
|
1701
|
+
labelIdxRef.current = initialState.elements.filter((e) => e.type === "point").length;
|
|
1702
|
+
}
|
|
1703
|
+
if (showAxisRef.current) {
|
|
1704
|
+
try {
|
|
1705
|
+
axisObjsRef.current.x = board.create("axis", [[0, 0], [1, 0]], { strokeColor: themeAxis(isDarkRef.current), name: "", withLabel: false });
|
|
1706
|
+
axisObjsRef.current.y = board.create("axis", [[0, 0], [0, 1]], { strokeColor: themeAxis(isDarkRef.current), name: "", withLabel: false });
|
|
1707
|
+
} catch {
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
if (showGridRef.current) {
|
|
1711
|
+
try {
|
|
1712
|
+
board.create("grid", [], { strokeColor: themeGrid(isDarkRef.current), strokeOpacity: 1 });
|
|
1713
|
+
} catch {
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
board.on("down", (e) => {
|
|
1717
|
+
const ctx = {
|
|
1718
|
+
boardRef,
|
|
1719
|
+
toolRef,
|
|
1720
|
+
pendingRef,
|
|
1721
|
+
previewSegRef,
|
|
1722
|
+
axisObjsRef,
|
|
1723
|
+
selectedSetRef,
|
|
1724
|
+
marqueeRef,
|
|
1725
|
+
moveDownRef,
|
|
1726
|
+
lastMoveClickRef,
|
|
1727
|
+
pendingTransformRef,
|
|
1728
|
+
phantomRef,
|
|
1729
|
+
previewShapeRef,
|
|
1730
|
+
previewRafRef,
|
|
1731
|
+
jxgRef,
|
|
1732
|
+
screenCoordsOf,
|
|
1733
|
+
objectsAt,
|
|
1734
|
+
promoteLabel,
|
|
1735
|
+
findNearestPoint,
|
|
1736
|
+
toggleSelect,
|
|
1737
|
+
clearSelection,
|
|
1738
|
+
applySelectionStyle,
|
|
1739
|
+
localIdOf,
|
|
1740
|
+
nextLabel,
|
|
1741
|
+
create,
|
|
1742
|
+
finalize,
|
|
1743
|
+
finalizeTransformCreate,
|
|
1744
|
+
clearPending,
|
|
1745
|
+
clearPreviewSegs,
|
|
1746
|
+
refreshPreview,
|
|
1747
|
+
flashWarn,
|
|
1748
|
+
emitTransform,
|
|
1749
|
+
snapshotObject,
|
|
1750
|
+
emitSelect,
|
|
1751
|
+
setPendingCount,
|
|
1752
|
+
setSelectionTick
|
|
1753
|
+
};
|
|
1754
|
+
handleDown(ctx, e);
|
|
1755
|
+
});
|
|
1756
|
+
board.on("up", (e) => {
|
|
1757
|
+
const ctx = {
|
|
1758
|
+
boardRef,
|
|
1759
|
+
toolRef,
|
|
1760
|
+
pendingRef,
|
|
1761
|
+
previewSegRef,
|
|
1762
|
+
axisObjsRef,
|
|
1763
|
+
selectedSetRef,
|
|
1764
|
+
marqueeRef,
|
|
1765
|
+
moveDownRef,
|
|
1766
|
+
lastMoveClickRef,
|
|
1767
|
+
pendingTransformRef,
|
|
1768
|
+
phantomRef,
|
|
1769
|
+
previewShapeRef,
|
|
1770
|
+
previewRafRef,
|
|
1771
|
+
jxgRef,
|
|
1772
|
+
screenCoordsOf,
|
|
1773
|
+
objectsAt,
|
|
1774
|
+
promoteLabel,
|
|
1775
|
+
findNearestPoint,
|
|
1776
|
+
toggleSelect,
|
|
1777
|
+
clearSelection,
|
|
1778
|
+
applySelectionStyle,
|
|
1779
|
+
localIdOf,
|
|
1780
|
+
nextLabel,
|
|
1781
|
+
create,
|
|
1782
|
+
finalize,
|
|
1783
|
+
finalizeTransformCreate,
|
|
1784
|
+
clearPending,
|
|
1785
|
+
clearPreviewSegs,
|
|
1786
|
+
refreshPreview,
|
|
1787
|
+
flashWarn,
|
|
1788
|
+
emitTransform,
|
|
1789
|
+
snapshotObject,
|
|
1790
|
+
emitSelect,
|
|
1791
|
+
setPendingCount,
|
|
1792
|
+
setSelectionTick
|
|
1793
|
+
};
|
|
1794
|
+
handleUp(ctx, e);
|
|
1795
|
+
});
|
|
1796
|
+
board.on("move", (e) => {
|
|
1797
|
+
const ctx = {
|
|
1798
|
+
boardRef,
|
|
1799
|
+
toolRef,
|
|
1800
|
+
pendingRef,
|
|
1801
|
+
previewSegRef,
|
|
1802
|
+
axisObjsRef,
|
|
1803
|
+
selectedSetRef,
|
|
1804
|
+
marqueeRef,
|
|
1805
|
+
moveDownRef,
|
|
1806
|
+
lastMoveClickRef,
|
|
1807
|
+
pendingTransformRef,
|
|
1808
|
+
phantomRef,
|
|
1809
|
+
previewShapeRef,
|
|
1810
|
+
previewRafRef,
|
|
1811
|
+
jxgRef,
|
|
1812
|
+
screenCoordsOf,
|
|
1813
|
+
objectsAt,
|
|
1814
|
+
promoteLabel,
|
|
1815
|
+
findNearestPoint,
|
|
1816
|
+
toggleSelect,
|
|
1817
|
+
clearSelection,
|
|
1818
|
+
applySelectionStyle,
|
|
1819
|
+
localIdOf,
|
|
1820
|
+
nextLabel,
|
|
1821
|
+
create,
|
|
1822
|
+
finalize,
|
|
1823
|
+
finalizeTransformCreate,
|
|
1824
|
+
clearPending,
|
|
1825
|
+
clearPreviewSegs,
|
|
1826
|
+
refreshPreview,
|
|
1827
|
+
flashWarn,
|
|
1828
|
+
emitTransform,
|
|
1829
|
+
snapshotObject,
|
|
1830
|
+
emitSelect,
|
|
1831
|
+
setPendingCount,
|
|
1832
|
+
setSelectionTick
|
|
1833
|
+
};
|
|
1834
|
+
handleMove(ctx, e);
|
|
1835
|
+
});
|
|
1836
|
+
onReady({
|
|
1837
|
+
getContainer: () => containerRef.current,
|
|
1838
|
+
// Sync toạ độ live của free point về log trước khi trả ra. JSXGraph
|
|
1839
|
+
// cho phép drag free point (args=[x,y] không có ref), việc drag chỉ
|
|
1840
|
+
// cập nhật obj.X()/Y() trên board chứ không đụng log → re-edit + Chèn
|
|
1841
|
+
// sẽ serialize toạ độ cũ → SVG không đổi → fileId trùng → user thấy
|
|
1842
|
+
// "k thay đổi". Line/segment/circle/polygon tham chiếu point qua id
|
|
1843
|
+
// nên auto-update theo.
|
|
1844
|
+
getCreationLog: () => creationLogRef.current.map((e) => {
|
|
1845
|
+
if (e.type !== "point") return { ...e };
|
|
1846
|
+
const args = e.args;
|
|
1847
|
+
if (!Array.isArray(args) || args.length !== 2) return { ...e };
|
|
1848
|
+
if (typeof args[0] !== "number" || typeof args[1] !== "number") return { ...e };
|
|
1849
|
+
const obj = objMapRef.current.get(e.id);
|
|
1850
|
+
if (!obj || typeof obj.X !== "function" || typeof obj.Y !== "function") return { ...e };
|
|
1851
|
+
const x = obj.X();
|
|
1852
|
+
const y = obj.Y();
|
|
1853
|
+
if (!Number.isFinite(x) || !Number.isFinite(y)) return { ...e };
|
|
1854
|
+
return { ...e, args: [x, y] };
|
|
1855
|
+
}),
|
|
1856
|
+
getBbox: () => boardRef.current ? boardRef.current.getBoundingBox() : [-10, 10, 10, -10],
|
|
1857
|
+
getShowAxis: () => showAxisRef.current,
|
|
1858
|
+
getShowGrid: () => showGridRef.current,
|
|
1859
|
+
setTool: (t) => handleToolChangeRef.current(t),
|
|
1860
|
+
getTool: () => toolRef.current,
|
|
1861
|
+
setShowAxis: (b) => setShowAxisRef.current(b),
|
|
1862
|
+
setShowGrid: (b) => setShowGridRef.current(b),
|
|
1863
|
+
undo: () => undoLastRef.current(),
|
|
1864
|
+
canUndo: () => creationLogRef.current.length > 0,
|
|
1865
|
+
subscribe: (cb) => {
|
|
1866
|
+
subscribersRef.current.add(cb);
|
|
1867
|
+
return () => {
|
|
1868
|
+
subscribersRef.current.delete(cb);
|
|
1869
|
+
};
|
|
1870
|
+
},
|
|
1871
|
+
snapshotObject,
|
|
1872
|
+
mutateObject,
|
|
1873
|
+
getAllPointNames: () => {
|
|
1874
|
+
const b = boardRef.current;
|
|
1875
|
+
if (!b) return [];
|
|
1876
|
+
const out = [];
|
|
1877
|
+
try {
|
|
1878
|
+
const objs = b.objectsList || [];
|
|
1879
|
+
for (const o of objs) {
|
|
1880
|
+
if (objKind(o) === "point" && typeof o.name === "string" && o.name) {
|
|
1881
|
+
out.push(o.name);
|
|
1882
|
+
}
|
|
1883
|
+
}
|
|
1884
|
+
} catch {
|
|
1885
|
+
}
|
|
1886
|
+
return out;
|
|
1887
|
+
},
|
|
1888
|
+
onSelect: (cb) => {
|
|
1889
|
+
selectSubsRef.current.add(cb);
|
|
1890
|
+
return () => {
|
|
1891
|
+
selectSubsRef.current.delete(cb);
|
|
1892
|
+
};
|
|
1893
|
+
},
|
|
1894
|
+
onTransformParam: (cb) => {
|
|
1895
|
+
transformSubsRef.current.add(cb);
|
|
1896
|
+
return () => {
|
|
1897
|
+
transformSubsRef.current.delete(cb);
|
|
1898
|
+
};
|
|
1899
|
+
},
|
|
1900
|
+
confirmTransformParam: (value) => {
|
|
1901
|
+
const p = pendingTransformRef.current;
|
|
1902
|
+
if (!p) return;
|
|
1903
|
+
if (p.tool === "regularPolygon") {
|
|
1904
|
+
const n = Math.max(3, Math.round(value));
|
|
1905
|
+
const p1Id = localIdOf(p.source);
|
|
1906
|
+
const p2Id = localIdOf(p.center);
|
|
1907
|
+
if (p1Id && p2Id && boardRef.current) {
|
|
1908
|
+
try {
|
|
1909
|
+
create("regularpolygon", [p1Id, p2Id, n], {
|
|
1910
|
+
fillColor: "#1e3a8a",
|
|
1911
|
+
fillOpacity: 0.1,
|
|
1912
|
+
borders: { strokeColor: "@stroke", strokeWidth: 2 }
|
|
1913
|
+
});
|
|
1914
|
+
} catch (err) {
|
|
1915
|
+
console.warn("regularpolygon failed", err);
|
|
1916
|
+
}
|
|
1917
|
+
}
|
|
1918
|
+
pendingTransformRef.current = null;
|
|
1919
|
+
emitTransformRef.current(null);
|
|
1920
|
+
clearPendingRef.current();
|
|
1921
|
+
return;
|
|
1922
|
+
}
|
|
1923
|
+
const spec = p.tool === "rotate" ? buildTransformSpec({ kind: "rotate", center: p.center, angleDeg: value }) : buildTransformSpec({ kind: "dilate", center: p.center, k: value });
|
|
1924
|
+
finalizeTransformCreateRef.current(spec, p.source);
|
|
1925
|
+
pendingTransformRef.current = null;
|
|
1926
|
+
emitTransformRef.current(null);
|
|
1927
|
+
clearPendingRef.current();
|
|
1928
|
+
},
|
|
1929
|
+
cancelTransformParam: () => {
|
|
1930
|
+
pendingTransformRef.current = null;
|
|
1931
|
+
emitTransformRef.current(null);
|
|
1932
|
+
clearPendingRef.current();
|
|
1933
|
+
},
|
|
1934
|
+
getSelectionSize: () => selectedSetRef.current.size,
|
|
1935
|
+
clearSelection: () => clearSelectionRef.current(),
|
|
1936
|
+
deleteSelection: () => deleteSelectedRef.current()
|
|
1937
|
+
});
|
|
1938
|
+
})();
|
|
1939
|
+
return () => {
|
|
1940
|
+
cancelled = true;
|
|
1941
|
+
if (previewRafRef.current != null) {
|
|
1942
|
+
cancelAnimationFrame(previewRafRef.current);
|
|
1943
|
+
previewRafRef.current = null;
|
|
1944
|
+
}
|
|
1945
|
+
if (boardRef.current && jxgRef.current) {
|
|
1946
|
+
try {
|
|
1947
|
+
jxgRef.current.JSXGraph.freeBoard(boardRef.current);
|
|
1948
|
+
} catch {
|
|
1949
|
+
}
|
|
1950
|
+
boardRef.current = null;
|
|
1951
|
+
}
|
|
1952
|
+
};
|
|
1953
|
+
}, [containerId]);
|
|
1954
|
+
react.useEffect(() => {
|
|
1955
|
+
const b = boardRef.current;
|
|
1956
|
+
if (!b) return;
|
|
1957
|
+
try {
|
|
1958
|
+
if (axisObjsRef.current.x) {
|
|
1959
|
+
try {
|
|
1960
|
+
b.removeObject(axisObjsRef.current.x);
|
|
1961
|
+
} catch {
|
|
1962
|
+
}
|
|
1963
|
+
axisObjsRef.current.x = void 0;
|
|
1964
|
+
}
|
|
1965
|
+
if (axisObjsRef.current.y) {
|
|
1966
|
+
try {
|
|
1967
|
+
b.removeObject(axisObjsRef.current.y);
|
|
1968
|
+
} catch {
|
|
1969
|
+
}
|
|
1970
|
+
axisObjsRef.current.y = void 0;
|
|
1971
|
+
}
|
|
1972
|
+
if (showAxis) {
|
|
1973
|
+
axisObjsRef.current.x = b.create("axis", [[0, 0], [1, 0]], { strokeColor: themeAxis(isDarkRef.current), name: "", withLabel: false });
|
|
1974
|
+
axisObjsRef.current.y = b.create("axis", [[0, 0], [0, 1]], { strokeColor: themeAxis(isDarkRef.current), name: "", withLabel: false });
|
|
1975
|
+
}
|
|
1976
|
+
b.update();
|
|
1977
|
+
} catch {
|
|
1978
|
+
}
|
|
1979
|
+
}, [showAxis]);
|
|
1980
|
+
react.useEffect(() => {
|
|
1981
|
+
const b = boardRef.current;
|
|
1982
|
+
if (!b) return;
|
|
1983
|
+
try {
|
|
1984
|
+
const objs = Object.values(b.objects || {});
|
|
1985
|
+
for (const o of objs) {
|
|
1986
|
+
if (o && (o.elType === "grid" || o.type === "grid" || o.visProp && o.visProp.type === "grid")) {
|
|
1987
|
+
try {
|
|
1988
|
+
b.removeObject(o);
|
|
1989
|
+
} catch {
|
|
1990
|
+
}
|
|
1991
|
+
}
|
|
1992
|
+
}
|
|
1993
|
+
if (showGrid) {
|
|
1994
|
+
b.create("grid", [], { strokeColor: themeGrid(isDarkRef.current), strokeOpacity: 1 });
|
|
1995
|
+
}
|
|
1996
|
+
b.update();
|
|
1997
|
+
} catch {
|
|
1998
|
+
}
|
|
1999
|
+
}, [showGrid]);
|
|
2000
|
+
const handleToolChange = react.useCallback((t) => {
|
|
2001
|
+
clearPending();
|
|
2002
|
+
toolRef.current = t;
|
|
2003
|
+
setTool(t);
|
|
2004
|
+
const b = boardRef.current;
|
|
2005
|
+
if (b) {
|
|
2006
|
+
try {
|
|
2007
|
+
if (b.attr?.pan) b.attr.pan.enabled = t !== "select";
|
|
2008
|
+
} catch {
|
|
2009
|
+
}
|
|
2010
|
+
}
|
|
2011
|
+
}, [clearPending]);
|
|
2012
|
+
const handleToolChangeRef = react.useRef(handleToolChange);
|
|
2013
|
+
handleToolChangeRef.current = handleToolChange;
|
|
2014
|
+
const subscribersRef = react.useRef(/* @__PURE__ */ new Set());
|
|
2015
|
+
const notifySubscribers = react.useCallback(() => {
|
|
2016
|
+
subscribersRef.current.forEach((cb) => {
|
|
2017
|
+
try {
|
|
2018
|
+
cb();
|
|
2019
|
+
} catch {
|
|
2020
|
+
}
|
|
2021
|
+
});
|
|
2022
|
+
}, []);
|
|
2023
|
+
react.useEffect(() => {
|
|
2024
|
+
notifySubscribers();
|
|
2025
|
+
}, [tool, showAxis, showGrid, historyTick, notifySubscribers]);
|
|
2026
|
+
const undoLastRef = react.useRef(undoLast);
|
|
2027
|
+
undoLastRef.current = undoLast;
|
|
2028
|
+
const clearPendingRef = react.useRef(clearPending);
|
|
2029
|
+
clearPendingRef.current = clearPending;
|
|
2030
|
+
const finalizeTransformCreateRef = react.useRef(finalizeTransformCreate);
|
|
2031
|
+
finalizeTransformCreateRef.current = finalizeTransformCreate;
|
|
2032
|
+
const clearSelectionRef = react.useRef(clearSelection);
|
|
2033
|
+
clearSelectionRef.current = clearSelection;
|
|
2034
|
+
const deleteSelectedRef = react.useRef(deleteSelected);
|
|
2035
|
+
deleteSelectedRef.current = deleteSelected;
|
|
2036
|
+
const emitTransformRef = react.useRef(emitTransform);
|
|
2037
|
+
emitTransformRef.current = emitTransform;
|
|
2038
|
+
const setShowAxisRef = react.useRef(setShowAxis);
|
|
2039
|
+
setShowAxisRef.current = setShowAxis;
|
|
2040
|
+
const setShowGridRef = react.useRef(setShowGrid);
|
|
2041
|
+
setShowGridRef.current = setShowGrid;
|
|
2042
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2043
|
+
"div",
|
|
2044
|
+
{
|
|
2045
|
+
ref: containerRef,
|
|
2046
|
+
id: containerId,
|
|
2047
|
+
"data-testid": "jxgmini-container",
|
|
2048
|
+
className: "h-full min-h-0 bg-white",
|
|
2049
|
+
style: { touchAction: "none" }
|
|
2050
|
+
}
|
|
2051
|
+
);
|
|
2052
|
+
};
|
|
2053
|
+
}
|
|
2054
|
+
});
|
|
2055
|
+
function MobileToolDrawer({
|
|
2056
|
+
title,
|
|
2057
|
+
headerIcon,
|
|
2058
|
+
chips,
|
|
2059
|
+
actions,
|
|
2060
|
+
groups,
|
|
2061
|
+
activeTool,
|
|
2062
|
+
onToolSelect,
|
|
2063
|
+
drawerOpen,
|
|
2064
|
+
onDrawerClose,
|
|
2065
|
+
isDark,
|
|
2066
|
+
testId
|
|
2067
|
+
}) {
|
|
2068
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
2069
|
+
drawerOpen && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2070
|
+
"div",
|
|
2071
|
+
{
|
|
2072
|
+
className: "stamp-drawer-backdrop",
|
|
2073
|
+
onPointerDown: onDrawerClose,
|
|
2074
|
+
"aria-hidden": "true"
|
|
2075
|
+
}
|
|
2076
|
+
),
|
|
2077
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
2078
|
+
"aside",
|
|
2079
|
+
{
|
|
2080
|
+
role: "complementary",
|
|
2081
|
+
"aria-label": title,
|
|
2082
|
+
"aria-hidden": !drawerOpen ? "true" : void 0,
|
|
2083
|
+
"data-testid": testId,
|
|
2084
|
+
"data-stamp-area": "true",
|
|
2085
|
+
"data-mobile-drawer": "true",
|
|
2086
|
+
"data-geo-mobile": "true",
|
|
2087
|
+
"data-drawer-state": drawerOpen ? "open" : "closed",
|
|
2088
|
+
className: [
|
|
2089
|
+
isDark ? "theme--dark " : "",
|
|
2090
|
+
"stamp-drawer-mobile flex flex-col border-r border-slate-200 bg-white shadow-md"
|
|
2091
|
+
].join(""),
|
|
2092
|
+
children: [
|
|
2093
|
+
/* @__PURE__ */ jsxRuntime.jsxs("header", { className: "flex items-center justify-between border-b border-slate-200 bg-gradient-to-r from-slate-50 to-white px-4 py-3", children: [
|
|
2094
|
+
/* @__PURE__ */ jsxRuntime.jsxs("h3", { className: "flex items-center gap-2 text-base font-semibold text-slate-800", children: [
|
|
2095
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "inline-flex h-7 w-7 items-center justify-center rounded-lg bg-emerald-50 text-emerald-700", children: headerIcon }),
|
|
2096
|
+
title
|
|
2097
|
+
] }),
|
|
2098
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2099
|
+
"button",
|
|
2100
|
+
{
|
|
2101
|
+
type: "button",
|
|
2102
|
+
onClick: onDrawerClose,
|
|
2103
|
+
"aria-label": "\u0110\xF3ng ng\u0103n c\xF4ng c\u1EE5",
|
|
2104
|
+
className: "inline-flex h-9 w-9 items-center justify-center rounded-full text-slate-500 transition hover:bg-slate-100 hover:text-slate-800",
|
|
2105
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
2106
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "6", y1: "6", x2: "18", y2: "18" }),
|
|
2107
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "18", y1: "6", x2: "6", y2: "18" })
|
|
2108
|
+
] })
|
|
2109
|
+
}
|
|
2110
|
+
)
|
|
2111
|
+
] }),
|
|
2112
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sticky top-0 z-10 flex items-center gap-2 border-b border-slate-200 bg-white/95 px-3 py-2 backdrop-blur", children: [
|
|
2113
|
+
chips.map((c) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2114
|
+
"button",
|
|
2115
|
+
{
|
|
2116
|
+
type: "button",
|
|
2117
|
+
role: "switch",
|
|
2118
|
+
"aria-pressed": c.pressed,
|
|
2119
|
+
"aria-label": c.label,
|
|
2120
|
+
"data-testid": c.testId,
|
|
2121
|
+
onClick: () => c.onToggle(!c.pressed),
|
|
2122
|
+
className: "geo-mobile-chip",
|
|
2123
|
+
children: [
|
|
2124
|
+
c.icon,
|
|
2125
|
+
c.label
|
|
2126
|
+
]
|
|
2127
|
+
},
|
|
2128
|
+
c.label
|
|
2129
|
+
)),
|
|
2130
|
+
actions.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "ml-auto flex items-center gap-1", children: actions.map((a) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2131
|
+
"button",
|
|
2132
|
+
{
|
|
2133
|
+
type: "button",
|
|
2134
|
+
onClick: a.onClick,
|
|
2135
|
+
disabled: a.disabled,
|
|
2136
|
+
"aria-label": a.label,
|
|
2137
|
+
title: a.title ?? a.label,
|
|
2138
|
+
className: "inline-flex h-9 w-9 items-center justify-center rounded-full text-slate-600 transition hover:bg-slate-100 hover:text-slate-900 disabled:cursor-not-allowed disabled:text-slate-300 disabled:hover:bg-transparent",
|
|
2139
|
+
children: a.icon
|
|
2140
|
+
},
|
|
2141
|
+
a.label
|
|
2142
|
+
)) })
|
|
2143
|
+
] }),
|
|
2144
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2145
|
+
"div",
|
|
2146
|
+
{
|
|
2147
|
+
className: "min-h-0 flex-1 overflow-y-auto",
|
|
2148
|
+
style: { paddingBottom: "calc(0.75rem + env(safe-area-inset-bottom))" },
|
|
2149
|
+
children: groups.map((g) => /* @__PURE__ */ jsxRuntime.jsxs("section", { className: "px-3 pt-3 pb-1", children: [
|
|
2150
|
+
/* @__PURE__ */ jsxRuntime.jsxs("h4", { className: "mb-2 flex items-center gap-2 text-[11px] font-semibold uppercase tracking-wider text-slate-500", children: [
|
|
2151
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "h-1 w-1 rounded-full bg-emerald-500" }),
|
|
2152
|
+
g.groupLabel
|
|
2153
|
+
] }),
|
|
2154
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-3 gap-2", children: g.tools.map((t) => {
|
|
2155
|
+
const active = activeTool === t.key;
|
|
2156
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2157
|
+
"button",
|
|
2158
|
+
{
|
|
2159
|
+
type: "button",
|
|
2160
|
+
"aria-label": t.label,
|
|
2161
|
+
"aria-pressed": active,
|
|
2162
|
+
"data-tool": t.key,
|
|
2163
|
+
onClick: () => {
|
|
2164
|
+
onToolSelect(t.key);
|
|
2165
|
+
onDrawerClose();
|
|
2166
|
+
},
|
|
2167
|
+
className: [
|
|
2168
|
+
"flex flex-col items-center justify-center gap-1.5 rounded-2xl px-2 py-3 transition active:scale-95",
|
|
2169
|
+
active ? "geo-mobile-tool-active" : "bg-slate-50 text-slate-700 hover:bg-slate-100"
|
|
2170
|
+
].join(" "),
|
|
2171
|
+
children: [
|
|
2172
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex h-6 w-6 items-center justify-center", children: t.icon }),
|
|
2173
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-center text-[11px] font-medium leading-tight line-clamp-2", children: t.label })
|
|
2174
|
+
]
|
|
2175
|
+
},
|
|
2176
|
+
t.key
|
|
2177
|
+
);
|
|
2178
|
+
}) })
|
|
2179
|
+
] }, g.group))
|
|
2180
|
+
}
|
|
2181
|
+
)
|
|
2182
|
+
]
|
|
2183
|
+
}
|
|
2184
|
+
)
|
|
2185
|
+
] });
|
|
2186
|
+
}
|
|
2187
|
+
var init_MobileToolDrawer = __esm({
|
|
2188
|
+
"src/stamps/shared/MobileToolDrawer.tsx"() {
|
|
2189
|
+
"use client";
|
|
2190
|
+
}
|
|
2191
|
+
});
|
|
2192
|
+
function Shell({ title, icon, onClose, children, isDark, closeLabel = "\u0110\xF3ng" }) {
|
|
2193
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2194
|
+
"aside",
|
|
2195
|
+
{
|
|
2196
|
+
role: "complementary",
|
|
2197
|
+
"aria-label": title,
|
|
2198
|
+
"data-testid": "stamp-left-panel",
|
|
2199
|
+
"data-stamp-area": "true",
|
|
2200
|
+
className: [
|
|
2201
|
+
isDark ? "theme--dark " : "",
|
|
2202
|
+
"absolute left-0 top-0 z-30 flex h-full w-60 flex-col border-r border-slate-200 bg-white shadow-md animate-in slide-in-from-left duration-200"
|
|
2203
|
+
].join(""),
|
|
2204
|
+
children: [
|
|
2205
|
+
/* @__PURE__ */ jsxRuntime.jsxs("header", { className: "flex items-center justify-between border-b border-slate-200 bg-gradient-to-r from-slate-50 to-white px-3 py-2", children: [
|
|
2206
|
+
/* @__PURE__ */ jsxRuntime.jsxs("h3", { className: "flex items-center gap-2 text-sm font-semibold text-slate-800", children: [
|
|
2207
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-base leading-none", children: icon }),
|
|
2208
|
+
title
|
|
2209
|
+
] }),
|
|
2210
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2211
|
+
"button",
|
|
2212
|
+
{
|
|
2213
|
+
onClick: onClose,
|
|
2214
|
+
"aria-label": closeLabel,
|
|
2215
|
+
className: "rounded p-1 text-slate-500 transition hover:bg-slate-100 hover:text-slate-800",
|
|
2216
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(CloseIcon, {})
|
|
2217
|
+
}
|
|
2218
|
+
)
|
|
2219
|
+
] }),
|
|
2220
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "min-h-0 flex-1 overflow-y-auto p-3 space-y-4", children })
|
|
2221
|
+
]
|
|
2222
|
+
}
|
|
2223
|
+
);
|
|
2224
|
+
}
|
|
2225
|
+
function Section({ label, children }) {
|
|
2226
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("section", { children: [
|
|
2227
|
+
/* @__PURE__ */ jsxRuntime.jsx("h4", { className: "mb-1.5 text-[10px] font-semibold uppercase tracking-wider text-slate-500", children: label }),
|
|
2228
|
+
children
|
|
2229
|
+
] });
|
|
2230
|
+
}
|
|
2231
|
+
function CloseIcon() {
|
|
2232
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
2233
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "6", y1: "6", x2: "18", y2: "18" }),
|
|
2234
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "18", y1: "6", x2: "6", y2: "18" })
|
|
2235
|
+
] });
|
|
2236
|
+
}
|
|
2237
|
+
function UndoIcon() {
|
|
2238
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
2239
|
+
/* @__PURE__ */ jsxRuntime.jsx("polyline", { points: "3 7 3 13 9 13" }),
|
|
2240
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M3.51 13a9 9 0 1 0 2.13-9.36L3 7" })
|
|
2241
|
+
] });
|
|
2242
|
+
}
|
|
2243
|
+
function AxisIcon() {
|
|
2244
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
2245
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "4", y1: "20", x2: "20", y2: "20" }),
|
|
2246
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "4", y1: "20", x2: "4", y2: "4" }),
|
|
2247
|
+
/* @__PURE__ */ jsxRuntime.jsx("polyline", { points: "2 6 4 4 6 6" }),
|
|
2248
|
+
/* @__PURE__ */ jsxRuntime.jsx("polyline", { points: "18 18 20 20 18 22" })
|
|
2249
|
+
] });
|
|
2250
|
+
}
|
|
2251
|
+
function GridIcon() {
|
|
2252
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
2253
|
+
/* @__PURE__ */ jsxRuntime.jsx("rect", { x: "4", y: "4", width: "16", height: "16", rx: "1" }),
|
|
2254
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "4", y1: "10", x2: "20", y2: "10" }),
|
|
2255
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "4", y1: "16", x2: "20", y2: "16" }),
|
|
2256
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "10", y1: "4", x2: "10", y2: "20" }),
|
|
2257
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "16", y1: "4", x2: "16", y2: "20" })
|
|
2258
|
+
] });
|
|
2259
|
+
}
|
|
2260
|
+
function useToolHoverTooltip() {
|
|
2261
|
+
const [hover, setHover] = react.useState(null);
|
|
2262
|
+
const [portalReady, setPortalReady] = react.useState(false);
|
|
2263
|
+
const hoverTimerRef = react.useRef(null);
|
|
2264
|
+
react.useEffect(() => {
|
|
2265
|
+
setPortalReady(true);
|
|
2266
|
+
return () => {
|
|
2267
|
+
if (hoverTimerRef.current) clearTimeout(hoverTimerRef.current);
|
|
2268
|
+
};
|
|
2269
|
+
}, []);
|
|
2270
|
+
const showHover = react.useCallback((el, t) => {
|
|
2271
|
+
if (hoverTimerRef.current) clearTimeout(hoverTimerRef.current);
|
|
2272
|
+
hoverTimerRef.current = setTimeout(() => {
|
|
2273
|
+
const r = el.getBoundingClientRect();
|
|
2274
|
+
setHover({ label: t.label, hint: t.hint, x: r.right, y: r.top + r.height / 2 });
|
|
2275
|
+
}, TOOLTIP_DELAY_MS);
|
|
2276
|
+
}, []);
|
|
2277
|
+
const hideHover = react.useCallback(() => {
|
|
2278
|
+
if (hoverTimerRef.current) {
|
|
2279
|
+
clearTimeout(hoverTimerRef.current);
|
|
2280
|
+
hoverTimerRef.current = null;
|
|
2281
|
+
}
|
|
2282
|
+
setHover(null);
|
|
2283
|
+
}, []);
|
|
2284
|
+
return { hover, portalReady, showHover, hideHover };
|
|
2285
|
+
}
|
|
2286
|
+
function DesktopGeometryPanel(props) {
|
|
2287
|
+
const { activeTool, onToolChange, showAxis, showGrid, onShowAxisChange, onShowGridChange, onUndo, canUndo, onClose, isDark, chordGroup } = props;
|
|
2288
|
+
const grouped = react.useMemo(() => {
|
|
2289
|
+
return TOOLS.reduce((acc, t) => {
|
|
2290
|
+
var _a;
|
|
2291
|
+
(acc[_a = t.group] ?? (acc[_a] = [])).push(t);
|
|
2292
|
+
return acc;
|
|
2293
|
+
}, {});
|
|
2294
|
+
}, []);
|
|
2295
|
+
const groupKeys = react.useMemo(
|
|
2296
|
+
() => GROUP_ORDER.filter((g) => grouped[g]),
|
|
2297
|
+
[grouped]
|
|
2298
|
+
);
|
|
2299
|
+
const activeGroupTools = chordGroup ? grouped[chordGroup] ?? null : null;
|
|
2300
|
+
const { hover, portalReady, showHover, hideHover } = useToolHoverTooltip();
|
|
2301
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
2302
|
+
/* @__PURE__ */ jsxRuntime.jsxs(Shell, { title: "H\xECnh h\u1ECDc", icon: GeometryIconHeader, onClose, isDark, children: [
|
|
2303
|
+
/* @__PURE__ */ jsxRuntime.jsx(Section, { label: "B\u1ED1 c\u1EE5c", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3 text-[11px] text-slate-700", children: [
|
|
2304
|
+
/* @__PURE__ */ jsxRuntime.jsxs("label", { className: "inline-flex select-none items-center gap-1.5", children: [
|
|
2305
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2306
|
+
"input",
|
|
2307
|
+
{
|
|
2308
|
+
type: "checkbox",
|
|
2309
|
+
checked: showAxis,
|
|
2310
|
+
onChange: (e) => onShowAxisChange(e.target.checked),
|
|
2311
|
+
"data-testid": "toggle-axis"
|
|
2312
|
+
}
|
|
2313
|
+
),
|
|
2314
|
+
"Tr\u1EE5c to\u1EA1 \u0111\u1ED9"
|
|
2315
|
+
] }),
|
|
2316
|
+
/* @__PURE__ */ jsxRuntime.jsxs("label", { className: "inline-flex select-none items-center gap-1.5", children: [
|
|
2317
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2318
|
+
"input",
|
|
2319
|
+
{
|
|
2320
|
+
type: "checkbox",
|
|
2321
|
+
checked: showGrid,
|
|
2322
|
+
onChange: (e) => onShowGridChange(e.target.checked),
|
|
2323
|
+
"data-testid": "toggle-grid"
|
|
2324
|
+
}
|
|
2325
|
+
),
|
|
2326
|
+
"L\u01B0\u1EDBi"
|
|
2327
|
+
] }),
|
|
2328
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2329
|
+
"button",
|
|
2330
|
+
{
|
|
2331
|
+
type: "button",
|
|
2332
|
+
onClick: onUndo,
|
|
2333
|
+
disabled: !canUndo,
|
|
2334
|
+
title: "Ho\xE0n t\xE1c (Ctrl/Cmd+Z)",
|
|
2335
|
+
"aria-label": "Ho\xE0n t\xE1c",
|
|
2336
|
+
className: "ml-auto inline-flex items-center justify-center rounded p-1 text-slate-600 transition hover:bg-slate-100 hover:text-slate-900 disabled:cursor-not-allowed disabled:text-slate-300 disabled:hover:bg-transparent",
|
|
2337
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(UndoIcon, {})
|
|
2338
|
+
}
|
|
2339
|
+
)
|
|
2340
|
+
] }) }),
|
|
2341
|
+
groupKeys.map((group) => {
|
|
2342
|
+
const isChordActive = chordGroup === group;
|
|
2343
|
+
const dimmed = chordGroup !== null && !isChordActive;
|
|
2344
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2345
|
+
"section",
|
|
2346
|
+
{
|
|
2347
|
+
"data-chord-group": group,
|
|
2348
|
+
"data-chord-active": isChordActive ? "true" : "false",
|
|
2349
|
+
className: [
|
|
2350
|
+
"rounded-md transition",
|
|
2351
|
+
isChordActive ? "bg-emerald-50 ring-1 ring-emerald-400 p-1" : "p-0",
|
|
2352
|
+
dimmed ? "opacity-55" : "opacity-100"
|
|
2353
|
+
].join(" "),
|
|
2354
|
+
children: [
|
|
2355
|
+
/* @__PURE__ */ jsxRuntime.jsxs("h4", { className: "mb-1.5 flex items-center justify-between text-[10px] font-semibold uppercase tracking-wider text-slate-500", children: [
|
|
2356
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: GROUP_LABELS[group] }),
|
|
2357
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2358
|
+
"span",
|
|
2359
|
+
{
|
|
2360
|
+
"data-testid": `chord-letter-${group}`,
|
|
2361
|
+
className: [
|
|
2362
|
+
"font-mono text-[10px] leading-none transition",
|
|
2363
|
+
isChordActive ? "text-emerald-700 font-bold" : "text-slate-400"
|
|
2364
|
+
].join(" "),
|
|
2365
|
+
children: letterForGroup(group)
|
|
2366
|
+
}
|
|
2367
|
+
)
|
|
2368
|
+
] }),
|
|
2369
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-4 gap-1", children: grouped[group].map((t, i) => {
|
|
2370
|
+
const active = activeTool === t.key;
|
|
2371
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2372
|
+
"button",
|
|
2373
|
+
{
|
|
2374
|
+
type: "button",
|
|
2375
|
+
"aria-label": t.label,
|
|
2376
|
+
"aria-pressed": active,
|
|
2377
|
+
"data-tool": t.key,
|
|
2378
|
+
onClick: () => onToolChange(t.key),
|
|
2379
|
+
onMouseEnter: (e) => showHover(e.currentTarget, t),
|
|
2380
|
+
onMouseLeave: hideHover,
|
|
2381
|
+
onFocus: (e) => showHover(e.currentTarget, t),
|
|
2382
|
+
onBlur: hideHover,
|
|
2383
|
+
className: [
|
|
2384
|
+
"relative flex h-8 items-center justify-center rounded-md transition",
|
|
2385
|
+
active ? "bg-emerald-600 text-white shadow-sm" : "text-slate-700 hover:bg-slate-100 hover:text-slate-900"
|
|
2386
|
+
].join(" "),
|
|
2387
|
+
children: [
|
|
2388
|
+
t.icon,
|
|
2389
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2390
|
+
"span",
|
|
2391
|
+
{
|
|
2392
|
+
"data-testid": `chord-num-${t.key}`,
|
|
2393
|
+
className: [
|
|
2394
|
+
"pointer-events-none absolute bottom-0 right-0.5 font-mono text-[9px] leading-none transition",
|
|
2395
|
+
active ? "text-white/70" : isChordActive ? "text-emerald-700 font-bold" : "text-slate-400"
|
|
2396
|
+
].join(" "),
|
|
2397
|
+
children: i + 1
|
|
2398
|
+
}
|
|
2399
|
+
)
|
|
2400
|
+
]
|
|
2401
|
+
},
|
|
2402
|
+
t.key
|
|
2403
|
+
);
|
|
2404
|
+
}) })
|
|
2405
|
+
]
|
|
2406
|
+
},
|
|
2407
|
+
group
|
|
2408
|
+
);
|
|
2409
|
+
}),
|
|
2410
|
+
chordGroup && activeGroupTools && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2411
|
+
"div",
|
|
2412
|
+
{
|
|
2413
|
+
"data-testid": "chord-hint",
|
|
2414
|
+
className: "mt-1 rounded border border-emerald-200 bg-emerald-50/60 px-2 py-1 text-[11px] leading-snug text-slate-600",
|
|
2415
|
+
children: [
|
|
2416
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-mono font-semibold text-emerald-700", children: letterForGroup(chordGroup) }),
|
|
2417
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "mx-1 text-slate-400", children: "\u2192" }),
|
|
2418
|
+
activeGroupTools.map((t, i) => /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "mr-2 inline-block", children: [
|
|
2419
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-mono font-semibold text-emerald-700", children: i + 1 }),
|
|
2420
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "ml-1", children: t.label })
|
|
2421
|
+
] }, t.key)),
|
|
2422
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-slate-400", children: "Esc hu\u1EF7" })
|
|
2423
|
+
]
|
|
2424
|
+
}
|
|
2425
|
+
)
|
|
2426
|
+
] }),
|
|
2427
|
+
portalReady && hover && typeof document !== "undefined" ? reactDom.createPortal(
|
|
2428
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
2429
|
+
"div",
|
|
2430
|
+
{
|
|
2431
|
+
role: "tooltip",
|
|
2432
|
+
className: "pointer-events-none fixed w-max max-w-[220px] rounded-md bg-slate-900 px-2 py-1 text-left text-[11px] leading-tight text-white shadow-lg",
|
|
2433
|
+
style: {
|
|
2434
|
+
left: hover.x + 8,
|
|
2435
|
+
top: hover.y,
|
|
2436
|
+
transform: "translate(0, -50%)",
|
|
2437
|
+
zIndex: 2147483600
|
|
2438
|
+
},
|
|
2439
|
+
children: [
|
|
2440
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "block font-medium", children: hover.label }),
|
|
2441
|
+
hover.hint && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "mt-0.5 block text-slate-300", children: hover.hint })
|
|
2442
|
+
]
|
|
2443
|
+
}
|
|
2444
|
+
),
|
|
2445
|
+
document.body
|
|
2446
|
+
) : null
|
|
2447
|
+
] });
|
|
2448
|
+
}
|
|
2449
|
+
function MobileGeometryPanel(props) {
|
|
2450
|
+
const {
|
|
2451
|
+
activeTool,
|
|
2452
|
+
onToolChange,
|
|
2453
|
+
showAxis,
|
|
2454
|
+
showGrid,
|
|
2455
|
+
onShowAxisChange,
|
|
2456
|
+
onShowGridChange,
|
|
2457
|
+
onUndo,
|
|
2458
|
+
canUndo,
|
|
2459
|
+
isDark,
|
|
2460
|
+
drawerOpen,
|
|
2461
|
+
onDrawerClose
|
|
2462
|
+
} = props;
|
|
2463
|
+
const groups = react.useMemo(() => {
|
|
2464
|
+
const acc = /* @__PURE__ */ new Map();
|
|
2465
|
+
for (const t of TOOLS) {
|
|
2466
|
+
if (!acc.has(t.group)) acc.set(t.group, []);
|
|
2467
|
+
acc.get(t.group).push(t);
|
|
2468
|
+
}
|
|
2469
|
+
return Array.from(acc.entries()).map(([group, tools]) => ({
|
|
2470
|
+
group,
|
|
2471
|
+
groupLabel: GROUP_LABELS[group],
|
|
2472
|
+
tools: tools.map((t) => ({ key: t.key, label: t.label, icon: t.icon }))
|
|
2473
|
+
}));
|
|
2474
|
+
}, []);
|
|
2475
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2476
|
+
MobileToolDrawer,
|
|
2477
|
+
{
|
|
2478
|
+
title: "H\xECnh h\u1ECDc",
|
|
2479
|
+
headerIcon: GeometryIconHeader,
|
|
2480
|
+
testId: "stamp-left-panel",
|
|
2481
|
+
isDark,
|
|
2482
|
+
drawerOpen: !!drawerOpen,
|
|
2483
|
+
onDrawerClose: () => onDrawerClose?.(),
|
|
2484
|
+
chips: [
|
|
2485
|
+
{
|
|
2486
|
+
label: "Tr\u1EE5c",
|
|
2487
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(AxisIcon, {}),
|
|
2488
|
+
pressed: showAxis,
|
|
2489
|
+
onToggle: onShowAxisChange,
|
|
2490
|
+
testId: "toggle-axis"
|
|
2491
|
+
},
|
|
2492
|
+
{
|
|
2493
|
+
label: "L\u01B0\u1EDBi",
|
|
2494
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(GridIcon, {}),
|
|
2495
|
+
pressed: showGrid,
|
|
2496
|
+
onToggle: onShowGridChange,
|
|
2497
|
+
testId: "toggle-grid"
|
|
2498
|
+
}
|
|
2499
|
+
],
|
|
2500
|
+
actions: [
|
|
2501
|
+
{
|
|
2502
|
+
label: "Ho\xE0n t\xE1c",
|
|
2503
|
+
title: "Ho\xE0n t\xE1c (Ctrl/Cmd+Z)",
|
|
2504
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(UndoIcon, {}),
|
|
2505
|
+
onClick: onUndo,
|
|
2506
|
+
disabled: !canUndo
|
|
2507
|
+
}
|
|
2508
|
+
],
|
|
2509
|
+
groups,
|
|
2510
|
+
activeTool,
|
|
2511
|
+
onToolSelect: onToolChange
|
|
2512
|
+
}
|
|
2513
|
+
);
|
|
2514
|
+
}
|
|
2515
|
+
function LeftPanel(props) {
|
|
2516
|
+
if (props.isMobile) {
|
|
2517
|
+
return /* @__PURE__ */ jsxRuntime.jsx(MobileGeometryPanel, { ...props });
|
|
2518
|
+
}
|
|
2519
|
+
return /* @__PURE__ */ jsxRuntime.jsx(DesktopGeometryPanel, { ...props });
|
|
2520
|
+
}
|
|
2521
|
+
var TOOLTIP_DELAY_MS, GeometryIconHeader;
|
|
2522
|
+
var init_LeftPanel = __esm({
|
|
2523
|
+
"src/stamps/geometry-2d/editor/LeftPanel.tsx"() {
|
|
2524
|
+
"use client";
|
|
2525
|
+
init_MiniBoard();
|
|
2526
|
+
init_tools();
|
|
2527
|
+
init_MobileToolDrawer();
|
|
2528
|
+
TOOLTIP_DELAY_MS = 400;
|
|
2529
|
+
GeometryIconHeader = /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
2530
|
+
/* @__PURE__ */ jsxRuntime.jsx("polygon", { points: "4,20 20,20 12,5" }),
|
|
2531
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "4", cy: "20", r: "1.5", fill: "currentColor", stroke: "none" }),
|
|
2532
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "20", cy: "20", r: "1.5", fill: "currentColor", stroke: "none" }),
|
|
2533
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "5", r: "1.5", fill: "currentColor", stroke: "none" })
|
|
2534
|
+
] });
|
|
2535
|
+
}
|
|
2536
|
+
});
|
|
2537
|
+
|
|
2538
|
+
// src/stamps/shared/excalidrawPalette.ts
|
|
2539
|
+
var STROKE_PALETTE;
|
|
2540
|
+
var init_excalidrawPalette = __esm({
|
|
2541
|
+
"src/stamps/shared/excalidrawPalette.ts"() {
|
|
2542
|
+
STROKE_PALETTE = [
|
|
2543
|
+
"#1e1e1e",
|
|
2544
|
+
// black
|
|
2545
|
+
"#e03131",
|
|
2546
|
+
// red
|
|
2547
|
+
"#e8590c",
|
|
2548
|
+
// orange
|
|
2549
|
+
"#f08c00",
|
|
2550
|
+
// yellow
|
|
2551
|
+
"#2f9e44",
|
|
2552
|
+
// green
|
|
2553
|
+
"#1971c2",
|
|
2554
|
+
// blue
|
|
2555
|
+
"#9c36b5",
|
|
2556
|
+
// grape
|
|
2557
|
+
"#868e96"
|
|
2558
|
+
// gray
|
|
2559
|
+
];
|
|
2560
|
+
}
|
|
2561
|
+
});
|
|
2562
|
+
function readMatch(query) {
|
|
2563
|
+
if (typeof window === "undefined" || !window.matchMedia) return false;
|
|
2564
|
+
try {
|
|
2565
|
+
return window.matchMedia(query).matches;
|
|
2566
|
+
} catch {
|
|
2567
|
+
return false;
|
|
2568
|
+
}
|
|
2569
|
+
}
|
|
2570
|
+
function useIsMobile() {
|
|
2571
|
+
const [state, setState] = react.useState(() => ({
|
|
2572
|
+
isMobile: readMatch(MOBILE_QUERY),
|
|
2573
|
+
isTouchOnly: readMatch(NO_HOVER_QUERY)
|
|
2574
|
+
}));
|
|
2575
|
+
react.useEffect(() => {
|
|
2576
|
+
if (typeof window === "undefined" || !window.matchMedia) return;
|
|
2577
|
+
const mql = window.matchMedia(MOBILE_QUERY);
|
|
2578
|
+
const tql = window.matchMedia(NO_HOVER_QUERY);
|
|
2579
|
+
const update = () => {
|
|
2580
|
+
setState({ isMobile: mql.matches, isTouchOnly: tql.matches });
|
|
2581
|
+
};
|
|
2582
|
+
update();
|
|
2583
|
+
mql.addEventListener("change", update);
|
|
2584
|
+
tql.addEventListener("change", update);
|
|
2585
|
+
return () => {
|
|
2586
|
+
mql.removeEventListener("change", update);
|
|
2587
|
+
tql.removeEventListener("change", update);
|
|
2588
|
+
};
|
|
2589
|
+
}, []);
|
|
2590
|
+
return state;
|
|
2591
|
+
}
|
|
2592
|
+
var MOBILE_QUERY, NO_HOVER_QUERY;
|
|
2593
|
+
var init_useIsMobile = __esm({
|
|
2594
|
+
"src/stamps/shared/useIsMobile.ts"() {
|
|
2595
|
+
"use client";
|
|
2596
|
+
MOBILE_QUERY = "(max-width: 768px)";
|
|
2597
|
+
NO_HOVER_QUERY = "(hover: none)";
|
|
2598
|
+
}
|
|
2599
|
+
});
|
|
2600
|
+
function toSubscript(n) {
|
|
2601
|
+
return String(n).split("").map((d) => SUB_DIGITS[+d] ?? d).join("");
|
|
2602
|
+
}
|
|
2603
|
+
function stripTrailingSubscript(s) {
|
|
2604
|
+
let i = s.length;
|
|
2605
|
+
while (i > 0 && SUB_SET.has(s[i - 1])) i--;
|
|
2606
|
+
return s.slice(0, i);
|
|
2607
|
+
}
|
|
2608
|
+
function disambiguateName(name, existing) {
|
|
2609
|
+
if (!name) return name;
|
|
2610
|
+
if (!existing.has(name)) return name;
|
|
2611
|
+
const base = stripTrailingSubscript(name) || name;
|
|
2612
|
+
for (let n = 2; n < 1e3; n++) {
|
|
2613
|
+
const candidate = base + toSubscript(n);
|
|
2614
|
+
if (!existing.has(candidate)) return candidate;
|
|
2615
|
+
}
|
|
2616
|
+
return name;
|
|
2617
|
+
}
|
|
2618
|
+
var DASH_OPTIONS, WIDTH_OPTIONS, FACE_OPTIONS, SUB_DIGITS, SUB_SET, Icons, PropertiesPopover;
|
|
2619
|
+
var init_PropertiesPopover = __esm({
|
|
2620
|
+
"src/stamps/geometry-2d/editor/PropertiesPopover.tsx"() {
|
|
2621
|
+
"use client";
|
|
2622
|
+
init_excalidrawPalette();
|
|
2623
|
+
init_useIsMobile();
|
|
2624
|
+
DASH_OPTIONS = [
|
|
2625
|
+
{ value: 0, label: "N\xE9t li\u1EC1n" },
|
|
2626
|
+
{ value: 2, label: "N\xE9t \u0111\u1EE9t" },
|
|
2627
|
+
{ value: 1, label: "N\xE9t ch\u1EA5m" }
|
|
2628
|
+
];
|
|
2629
|
+
WIDTH_OPTIONS = [1, 2, 3];
|
|
2630
|
+
FACE_OPTIONS = [
|
|
2631
|
+
{ value: "o", symbol: "\u25CF" },
|
|
2632
|
+
{ value: "circle", symbol: "\u25EF" },
|
|
2633
|
+
{ value: "cross", symbol: "\u2715" },
|
|
2634
|
+
{ value: "plus", symbol: "\u271A" }
|
|
2635
|
+
];
|
|
2636
|
+
SUB_DIGITS = ["\u2080", "\u2081", "\u2082", "\u2083", "\u2084", "\u2085", "\u2086", "\u2087", "\u2088", "\u2089"];
|
|
2637
|
+
SUB_SET = new Set(SUB_DIGITS);
|
|
2638
|
+
Icons = {
|
|
2639
|
+
color: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
2640
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M19 11 L11 3 L3 11 L11 19 Z" }),
|
|
2641
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M19 11 L21 16 a2 2 0 1 1 -4 0 Z", fill: "currentColor", stroke: "none" })
|
|
2642
|
+
] }),
|
|
2643
|
+
style: /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "12", r: "5", fill: "currentColor" }) }),
|
|
2644
|
+
size: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", children: [
|
|
2645
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "4", y1: "9", x2: "20", y2: "9", strokeWidth: "1" }),
|
|
2646
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "4", y1: "13", x2: "20", y2: "13", strokeWidth: "2" }),
|
|
2647
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "4", y1: "17", x2: "20", y2: "17", strokeWidth: "3.2" })
|
|
2648
|
+
] }),
|
|
2649
|
+
name: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "currentColor", children: [
|
|
2650
|
+
/* @__PURE__ */ jsxRuntime.jsx("text", { x: "2", y: "17", fontSize: "14", fontFamily: "serif", fontWeight: "700", children: "A" }),
|
|
2651
|
+
/* @__PURE__ */ jsxRuntime.jsx("text", { x: "12", y: "17", fontSize: "11", fontFamily: "serif", fontWeight: "700", children: "a" })
|
|
2652
|
+
] }),
|
|
2653
|
+
trash: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
2654
|
+
/* @__PURE__ */ jsxRuntime.jsx("polyline", { points: "3,6 5,6 21,6" }),
|
|
2655
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M19 6 l-1 14 a 2 2 0 0 1 -2 2 H 8 a 2 2 0 0 1 -2 -2 l-1 -14" }),
|
|
2656
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "10", y1: "11", x2: "10", y2: "17" }),
|
|
2657
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "14", y1: "11", x2: "14", y2: "17" })
|
|
2658
|
+
] })
|
|
2659
|
+
};
|
|
2660
|
+
PropertiesPopover = (props) => {
|
|
2661
|
+
const { anchor, onClose, onMutate, isDark, getAllNames } = props;
|
|
2662
|
+
const rootRef = react.useRef(null);
|
|
2663
|
+
const [section, setSection] = react.useState(null);
|
|
2664
|
+
const { isMobile } = useIsMobile();
|
|
2665
|
+
const [clamped, setClamped] = react.useState(null);
|
|
2666
|
+
react.useLayoutEffect(() => {
|
|
2667
|
+
if (typeof window === "undefined") return;
|
|
2668
|
+
const margin = 8;
|
|
2669
|
+
if (isMobile) {
|
|
2670
|
+
const rect2 = rootRef.current?.getBoundingClientRect();
|
|
2671
|
+
const w2 = rect2?.width ?? 280;
|
|
2672
|
+
const left2 = Math.max(margin, (window.innerWidth - w2) / 2);
|
|
2673
|
+
const top2 = window.innerHeight - (rect2?.height ?? 80) - margin - 12;
|
|
2674
|
+
setClamped({ left: left2, top: Math.max(margin, top2) });
|
|
2675
|
+
return;
|
|
2676
|
+
}
|
|
2677
|
+
const rect = rootRef.current?.getBoundingClientRect();
|
|
2678
|
+
const w = rect?.width ?? 280;
|
|
2679
|
+
const h = rect?.height ?? 80;
|
|
2680
|
+
const left = Math.max(margin, Math.min(anchor.x, window.innerWidth - w - margin));
|
|
2681
|
+
const top = Math.max(margin, Math.min(anchor.y, window.innerHeight - h - margin));
|
|
2682
|
+
setClamped({ left, top });
|
|
2683
|
+
}, [anchor.x, anchor.y, isMobile, section]);
|
|
2684
|
+
const initialName = props.kind === "point" ? props.currentName : props.kind === "line" || props.kind === "circle" ? props.currentName : "";
|
|
2685
|
+
const [name, setName] = react.useState(initialName);
|
|
2686
|
+
react.useEffect(() => {
|
|
2687
|
+
setName(initialName);
|
|
2688
|
+
}, [initialName]);
|
|
2689
|
+
react.useEffect(() => {
|
|
2690
|
+
const onKey = (e) => {
|
|
2691
|
+
if (e.key === "Escape") {
|
|
2692
|
+
e.preventDefault();
|
|
2693
|
+
onClose();
|
|
2694
|
+
}
|
|
2695
|
+
};
|
|
2696
|
+
const onPointerDown = (e) => {
|
|
2697
|
+
if (!rootRef.current?.contains(e.target)) onClose();
|
|
2698
|
+
};
|
|
2699
|
+
document.addEventListener("keydown", onKey);
|
|
2700
|
+
document.addEventListener("pointerdown", onPointerDown, { capture: true });
|
|
2701
|
+
return () => {
|
|
2702
|
+
document.removeEventListener("keydown", onKey);
|
|
2703
|
+
document.removeEventListener("pointerdown", onPointerDown, { capture: true });
|
|
2704
|
+
};
|
|
2705
|
+
}, [onClose]);
|
|
2706
|
+
const pickColor = (c) => {
|
|
2707
|
+
onMutate({ attrs: { strokeColor: c, fillColor: props.kind === "circle" ? "none" : c, color: c } });
|
|
2708
|
+
};
|
|
2709
|
+
const pickDash = (d) => onMutate({ attrs: { dash: d } });
|
|
2710
|
+
const pickWidth = (w) => onMutate({ attrs: { strokeWidth: w } });
|
|
2711
|
+
const pickFace = (f) => onMutate({ attrs: { face: f } });
|
|
2712
|
+
const currentName = props.kind === "point" || props.kind === "line" || props.kind === "circle" ? props.currentName : "";
|
|
2713
|
+
const commitName = () => {
|
|
2714
|
+
const trimmed = name.trim();
|
|
2715
|
+
if (trimmed === currentName) return;
|
|
2716
|
+
let final = trimmed;
|
|
2717
|
+
if (trimmed) {
|
|
2718
|
+
const others = new Set((getAllNames?.() ?? []).filter((n) => n !== currentName));
|
|
2719
|
+
final = disambiguateName(trimmed, others);
|
|
2720
|
+
}
|
|
2721
|
+
if (final !== name) setName(final);
|
|
2722
|
+
onMutate({ attrs: { name: final } });
|
|
2723
|
+
};
|
|
2724
|
+
const toggleShowLabel = (next) => onMutate({ attrs: { withLabel: next } });
|
|
2725
|
+
const toggleShowValue = (next) => onMutate({ valueLabel: next });
|
|
2726
|
+
const doDelete = () => {
|
|
2727
|
+
onMutate({ remove: true });
|
|
2728
|
+
onClose();
|
|
2729
|
+
};
|
|
2730
|
+
const toggleSection = (s) => setSection((cur) => cur === s ? null : s);
|
|
2731
|
+
const currentColor = props.currentColor;
|
|
2732
|
+
const currentDash = props.currentDash;
|
|
2733
|
+
const currentWidth = props.currentWidth;
|
|
2734
|
+
if (typeof document === "undefined") return null;
|
|
2735
|
+
const PillBtn = ({ id, label, icon, active, onClick, indicatorColor }) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2736
|
+
"button",
|
|
2737
|
+
{
|
|
2738
|
+
type: "button",
|
|
2739
|
+
"data-section": id,
|
|
2740
|
+
"data-pill-btn": id,
|
|
2741
|
+
"aria-label": label,
|
|
2742
|
+
"aria-pressed": !!active,
|
|
2743
|
+
onClick,
|
|
2744
|
+
className: `relative flex h-8 w-8 items-center justify-center rounded-md transition ${active ? "bg-slate-200 text-slate-900" : "text-slate-700 hover:bg-slate-100"}`,
|
|
2745
|
+
children: [
|
|
2746
|
+
icon,
|
|
2747
|
+
indicatorColor && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2748
|
+
"span",
|
|
2749
|
+
{
|
|
2750
|
+
"aria-hidden": true,
|
|
2751
|
+
className: "absolute bottom-0.5 left-1/2 -translate-x-1/2 h-1 w-4 rounded-full",
|
|
2752
|
+
style: { background: indicatorColor }
|
|
2753
|
+
}
|
|
2754
|
+
)
|
|
2755
|
+
]
|
|
2756
|
+
}
|
|
2757
|
+
);
|
|
2758
|
+
const colorIndicatorTint = react.useMemo(() => currentColor, [currentColor]);
|
|
2759
|
+
const pos = clamped ?? { left: anchor.x, top: anchor.y };
|
|
2760
|
+
const node = /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2761
|
+
"div",
|
|
2762
|
+
{
|
|
2763
|
+
ref: rootRef,
|
|
2764
|
+
"data-stamp-area": "true",
|
|
2765
|
+
className: `${isDark ? "theme--dark " : ""}fixed z-[2147483600] flex flex-col gap-1.5`,
|
|
2766
|
+
style: { left: pos.left, top: pos.top },
|
|
2767
|
+
role: "dialog",
|
|
2768
|
+
"aria-label": "Thu\u1ED9c t\xEDnh \u0111\u1ED1i t\u01B0\u1EE3ng",
|
|
2769
|
+
children: [
|
|
2770
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1 rounded-full border border-slate-300 bg-white px-1.5 py-1 shadow-lg ring-1 ring-black/5", children: [
|
|
2771
|
+
/* @__PURE__ */ jsxRuntime.jsx(PillBtn, { id: "color", label: "M\xE0u", icon: Icons.color, active: section === "color", onClick: () => toggleSection("color"), indicatorColor: colorIndicatorTint }),
|
|
2772
|
+
/* @__PURE__ */ jsxRuntime.jsx(PillBtn, { id: "style", label: "Ki\u1EC3u", icon: Icons.style, active: section === "style", onClick: () => toggleSection("style") }),
|
|
2773
|
+
/* @__PURE__ */ jsxRuntime.jsx(PillBtn, { id: "size", label: "\u0110\u1ED9 d\xE0y", icon: Icons.size, active: section === "size", onClick: () => toggleSection("size") }),
|
|
2774
|
+
/* @__PURE__ */ jsxRuntime.jsx(PillBtn, { id: "name", label: "T\xEAn", icon: Icons.name, active: section === "name", onClick: () => toggleSection("name") }),
|
|
2775
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": true, className: "mx-0.5 h-5 w-px bg-slate-200" }),
|
|
2776
|
+
/* @__PURE__ */ jsxRuntime.jsx(PillBtn, { id: "delete", label: "Xo\xE1", icon: Icons.trash, onClick: doDelete })
|
|
2777
|
+
] }),
|
|
2778
|
+
section && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-[220px] rounded-lg border border-slate-300 bg-white p-3 shadow-2xl ring-1 ring-black/5", children: [
|
|
2779
|
+
section === "color" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
|
|
2780
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-[11px] font-medium text-slate-500", children: "M\xE0u" }),
|
|
2781
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap gap-1", children: STROKE_PALETTE.map((c) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2782
|
+
"button",
|
|
2783
|
+
{
|
|
2784
|
+
"aria-label": `M\xE0u ${c}`,
|
|
2785
|
+
onClick: () => pickColor(c),
|
|
2786
|
+
className: `h-6 w-6 rounded border ${currentColor === c ? "border-emerald-500 ring-2 ring-emerald-300" : "border-slate-200"}`,
|
|
2787
|
+
style: { background: c }
|
|
2788
|
+
},
|
|
2789
|
+
c
|
|
2790
|
+
)) })
|
|
2791
|
+
] }),
|
|
2792
|
+
section === "style" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
|
|
2793
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-[11px] font-medium text-slate-500", children: "Ki\u1EC3u" }),
|
|
2794
|
+
props.kind === "point" ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex gap-1", children: FACE_OPTIONS.map((f) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2795
|
+
"button",
|
|
2796
|
+
{
|
|
2797
|
+
"aria-label": `H\xECnh ${f.value}`,
|
|
2798
|
+
onClick: () => pickFace(f.value),
|
|
2799
|
+
className: `h-7 w-7 rounded border text-sm ${props.currentFace === f.value ? "border-emerald-500 bg-emerald-50" : "border-slate-300 bg-white"}`,
|
|
2800
|
+
children: f.symbol
|
|
2801
|
+
},
|
|
2802
|
+
f.value
|
|
2803
|
+
)) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex gap-1", children: DASH_OPTIONS.map((d) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2804
|
+
"button",
|
|
2805
|
+
{
|
|
2806
|
+
"aria-label": `Ki\u1EC3u ${d.label.toLowerCase()}`,
|
|
2807
|
+
onClick: () => pickDash(d.value),
|
|
2808
|
+
className: `flex-1 rounded border px-1 py-1 text-[11px] ${currentDash === d.value ? "border-emerald-500 bg-emerald-50" : "border-slate-300 bg-white"}`,
|
|
2809
|
+
children: d.label
|
|
2810
|
+
},
|
|
2811
|
+
d.value
|
|
2812
|
+
)) })
|
|
2813
|
+
] }),
|
|
2814
|
+
section === "size" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
|
|
2815
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-[11px] font-medium text-slate-500", children: "\u0110\u1ED9 d\xE0y" }),
|
|
2816
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex gap-1", children: WIDTH_OPTIONS.map((w) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2817
|
+
"button",
|
|
2818
|
+
{
|
|
2819
|
+
"aria-label": `\u0110\u1ED9 d\xE0y ${w}`,
|
|
2820
|
+
onClick: () => pickWidth(w),
|
|
2821
|
+
className: `flex-1 rounded border py-1 ${currentWidth === w ? "border-emerald-500 bg-emerald-50" : "border-slate-300 bg-white"}`,
|
|
2822
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "inline-block rounded bg-slate-800", style: { width: 30, height: w } })
|
|
2823
|
+
},
|
|
2824
|
+
w
|
|
2825
|
+
)) })
|
|
2826
|
+
] }),
|
|
2827
|
+
section === "name" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2", children: [
|
|
2828
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
|
|
2829
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-[11px] font-medium text-slate-500", children: "T\xEAn" }),
|
|
2830
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2831
|
+
"input",
|
|
2832
|
+
{
|
|
2833
|
+
value: name,
|
|
2834
|
+
onChange: (e) => setName(e.target.value),
|
|
2835
|
+
onBlur: commitName,
|
|
2836
|
+
onKeyDown: (e) => {
|
|
2837
|
+
if (e.key === "Enter") {
|
|
2838
|
+
e.preventDefault();
|
|
2839
|
+
commitName();
|
|
2840
|
+
}
|
|
2841
|
+
},
|
|
2842
|
+
autoFocus: true,
|
|
2843
|
+
placeholder: props.kind === "point" ? "A, B, \u2026" : props.kind === "line" ? "a, b, f, \u2026" : "O, c, \u2026",
|
|
2844
|
+
className: "rounded border border-slate-300 bg-white px-2 py-1 text-sm text-slate-800"
|
|
2845
|
+
}
|
|
2846
|
+
),
|
|
2847
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-[10px] text-slate-400", children: "Tr\xF9ng t\xEAn s\u1EBD t\u1EF1 th\xEAm ch\u1EC9 s\u1ED1 (B \u2192 B\u2082)" })
|
|
2848
|
+
] }),
|
|
2849
|
+
/* @__PURE__ */ jsxRuntime.jsxs("label", { className: "flex items-center justify-between gap-2 text-[12px] text-slate-700", children: [
|
|
2850
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: "Hi\u1EC3n th\u1ECB t\xEAn" }),
|
|
2851
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2852
|
+
"input",
|
|
2853
|
+
{
|
|
2854
|
+
type: "checkbox",
|
|
2855
|
+
checked: props.currentShowLabel !== false,
|
|
2856
|
+
onChange: (e) => toggleShowLabel(e.target.checked),
|
|
2857
|
+
"aria-label": "Hi\u1EC3n th\u1ECB t\xEAn"
|
|
2858
|
+
}
|
|
2859
|
+
)
|
|
2860
|
+
] }),
|
|
2861
|
+
(props.kind === "line" || props.kind === "circle") && /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "flex items-center justify-between gap-2 text-[12px] text-slate-700", children: [
|
|
2862
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: "Hi\u1EC3n th\u1ECB gi\xE1 tr\u1ECB" }),
|
|
2863
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2864
|
+
"input",
|
|
2865
|
+
{
|
|
2866
|
+
type: "checkbox",
|
|
2867
|
+
checked: !!props.currentShowValue,
|
|
2868
|
+
onChange: (e) => toggleShowValue(e.target.checked),
|
|
2869
|
+
"aria-label": "Hi\u1EC3n th\u1ECB gi\xE1 tr\u1ECB"
|
|
2870
|
+
}
|
|
2871
|
+
)
|
|
2872
|
+
] })
|
|
2873
|
+
] })
|
|
2874
|
+
] })
|
|
2875
|
+
]
|
|
2876
|
+
}
|
|
2877
|
+
);
|
|
2878
|
+
return reactDom.createPortal(node, document.body);
|
|
2879
|
+
};
|
|
2880
|
+
}
|
|
2881
|
+
});
|
|
2882
|
+
var LABELS, TransformParamPopover;
|
|
2883
|
+
var init_TransformParamPopover = __esm({
|
|
2884
|
+
"src/stamps/geometry-2d/editor/TransformParamPopover.tsx"() {
|
|
2885
|
+
"use client";
|
|
2886
|
+
LABELS = {
|
|
2887
|
+
rotate: { aria: "G\xF3c quay", label: "G\xF3c (\xB0)", step: 15 },
|
|
2888
|
+
dilate: { aria: "T\u1EF7 s\u1ED1 k", label: "T\u1EF7 s\u1ED1 k", step: 0.5 },
|
|
2889
|
+
regularPolygon: { aria: "S\u1ED1 c\u1EA1nh \u0111a gi\xE1c \u0111\u1EC1u", label: "S\u1ED1 c\u1EA1nh (n \u2265 3)", step: 1, min: 3 }
|
|
2890
|
+
};
|
|
2891
|
+
TransformParamPopover = ({ kind, anchor, defaultValue, onConfirm, onCancel, isDark }) => {
|
|
2892
|
+
const [value, setValue] = react.useState(defaultValue);
|
|
2893
|
+
const inputRef = react.useRef(null);
|
|
2894
|
+
const meta = LABELS[kind];
|
|
2895
|
+
react.useEffect(() => {
|
|
2896
|
+
inputRef.current?.focus();
|
|
2897
|
+
inputRef.current?.select();
|
|
2898
|
+
}, []);
|
|
2899
|
+
const submit = () => {
|
|
2900
|
+
let v = Number.isFinite(value) ? value : defaultValue;
|
|
2901
|
+
if (kind === "regularPolygon") {
|
|
2902
|
+
v = Math.max(3, Math.round(v));
|
|
2903
|
+
}
|
|
2904
|
+
onConfirm(v);
|
|
2905
|
+
};
|
|
2906
|
+
if (typeof document === "undefined") return null;
|
|
2907
|
+
const node = /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2908
|
+
"div",
|
|
2909
|
+
{
|
|
2910
|
+
"data-stamp-area": "true",
|
|
2911
|
+
className: `${isDark ? "theme--dark " : ""}fixed z-[2147483600] flex flex-col gap-2 rounded-lg border border-slate-300 bg-white p-3 shadow-2xl ring-1 ring-black/5`,
|
|
2912
|
+
style: { left: anchor.x, top: anchor.y, minWidth: 180 },
|
|
2913
|
+
role: "dialog",
|
|
2914
|
+
"aria-label": meta.aria,
|
|
2915
|
+
children: [
|
|
2916
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { className: "text-xs font-medium text-slate-700", children: meta.label }),
|
|
2917
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2918
|
+
"input",
|
|
2919
|
+
{
|
|
2920
|
+
ref: inputRef,
|
|
2921
|
+
type: "number",
|
|
2922
|
+
value,
|
|
2923
|
+
step: meta.step,
|
|
2924
|
+
min: meta.min,
|
|
2925
|
+
onChange: (e) => setValue(parseFloat(e.target.value)),
|
|
2926
|
+
onKeyDown: (e) => {
|
|
2927
|
+
if (e.key === "Enter") {
|
|
2928
|
+
e.preventDefault();
|
|
2929
|
+
submit();
|
|
2930
|
+
} else if (e.key === "Escape") {
|
|
2931
|
+
e.preventDefault();
|
|
2932
|
+
onCancel();
|
|
2933
|
+
}
|
|
2934
|
+
},
|
|
2935
|
+
className: "rounded border border-slate-300 bg-white px-2 py-1 text-sm text-slate-800"
|
|
2936
|
+
}
|
|
2937
|
+
),
|
|
2938
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
2939
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2940
|
+
"button",
|
|
2941
|
+
{
|
|
2942
|
+
onClick: onCancel,
|
|
2943
|
+
className: "rounded border border-slate-300 bg-white px-2 py-1 text-xs text-slate-700 hover:bg-slate-100",
|
|
2944
|
+
children: "Hu\u1EF7"
|
|
2945
|
+
}
|
|
2946
|
+
),
|
|
2947
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2948
|
+
"button",
|
|
2949
|
+
{
|
|
2950
|
+
onClick: submit,
|
|
2951
|
+
className: "rounded bg-emerald-600 px-2 py-1 text-xs font-medium text-white hover:bg-emerald-700",
|
|
2952
|
+
children: "\xC1p d\u1EE5ng"
|
|
2953
|
+
}
|
|
2954
|
+
)
|
|
2955
|
+
] })
|
|
2956
|
+
]
|
|
2957
|
+
}
|
|
2958
|
+
);
|
|
2959
|
+
return reactDom.createPortal(node, document.body);
|
|
2960
|
+
};
|
|
2961
|
+
}
|
|
2962
|
+
});
|
|
2963
|
+
var GeometryEditorPanel;
|
|
2964
|
+
var init_EditorPanel = __esm({
|
|
2965
|
+
"src/stamps/geometry-2d/editor/EditorPanel.tsx"() {
|
|
2966
|
+
"use client";
|
|
2967
|
+
init_MiniBoard();
|
|
2968
|
+
init_serialize();
|
|
2969
|
+
init_render();
|
|
2970
|
+
init_PropertiesPopover();
|
|
2971
|
+
init_TransformParamPopover();
|
|
2972
|
+
GeometryEditorPanel = react.forwardRef(
|
|
2973
|
+
function GeometryEditorPanel2({ initialState, onInsert, onClose, withLeftPanel = false, onStateChange, isDark, isMobile = false, onOpenDrawer }, ref) {
|
|
2974
|
+
const handleRef = react.useRef(null);
|
|
2975
|
+
const [ready, setReady] = react.useState(false);
|
|
2976
|
+
const [propsPopover, setPropsPopover] = react.useState(null);
|
|
2977
|
+
const [transformPopover, setTransformPopover] = react.useState(null);
|
|
2978
|
+
const onStateChangeRef = react.useRef(onStateChange);
|
|
2979
|
+
react.useEffect(() => {
|
|
2980
|
+
onStateChangeRef.current = onStateChange;
|
|
2981
|
+
}, [onStateChange]);
|
|
2982
|
+
const emitState = react.useCallback(() => {
|
|
2983
|
+
const h = handleRef.current;
|
|
2984
|
+
const cb = onStateChangeRef.current;
|
|
2985
|
+
if (!h || !cb) return;
|
|
2986
|
+
cb({
|
|
2987
|
+
tool: h.getTool(),
|
|
2988
|
+
showAxis: h.getShowAxis(),
|
|
2989
|
+
showGrid: h.getShowGrid(),
|
|
2990
|
+
canUndo: h.canUndo()
|
|
2991
|
+
});
|
|
2992
|
+
}, []);
|
|
2993
|
+
const handleReady = react.useCallback((h) => {
|
|
2994
|
+
handleRef.current = h;
|
|
2995
|
+
setReady(true);
|
|
2996
|
+
emitState();
|
|
2997
|
+
h.subscribe(emitState);
|
|
2998
|
+
h.onSelect((snap) => setPropsPopover(snap));
|
|
2999
|
+
h.onTransformParam((info) => setTransformPopover(info));
|
|
3000
|
+
}, [emitState]);
|
|
3001
|
+
const performInsert = react.useCallback(() => {
|
|
3002
|
+
if (!handleRef.current) return false;
|
|
3003
|
+
const log = handleRef.current.getCreationLog();
|
|
3004
|
+
if (log.length === 0) return false;
|
|
3005
|
+
const bbox = handleRef.current.getBbox();
|
|
3006
|
+
const showAxis = handleRef.current.getShowAxis();
|
|
3007
|
+
const showGrid = handleRef.current.getShowGrid();
|
|
3008
|
+
const serialized = serializeBoard(
|
|
3009
|
+
{ getBoundingBox: () => bbox, create: () => void 0 },
|
|
3010
|
+
log,
|
|
3011
|
+
{ showAxis, showGrid }
|
|
3012
|
+
);
|
|
3013
|
+
const jsonState = JSON.stringify(serialized);
|
|
3014
|
+
void (async () => {
|
|
3015
|
+
try {
|
|
3016
|
+
const svgString = await renderGeometrySvgFromState(jsonState);
|
|
3017
|
+
onInsert(jsonState, svgString);
|
|
3018
|
+
} catch (err) {
|
|
3019
|
+
console.error("Geometry insert failed:", err);
|
|
3020
|
+
}
|
|
3021
|
+
})();
|
|
3022
|
+
return true;
|
|
3023
|
+
}, [onInsert]);
|
|
3024
|
+
const handleInsert = react.useCallback(() => {
|
|
3025
|
+
performInsert();
|
|
3026
|
+
}, [performInsert]);
|
|
3027
|
+
react.useImperativeHandle(ref, () => ({
|
|
3028
|
+
setTool: (t) => handleRef.current?.setTool(t),
|
|
3029
|
+
setShowAxis: (b) => handleRef.current?.setShowAxis(b),
|
|
3030
|
+
setShowGrid: (b) => handleRef.current?.setShowGrid(b),
|
|
3031
|
+
undo: () => handleRef.current?.undo(),
|
|
3032
|
+
insert: performInsert,
|
|
3033
|
+
hasContent: () => (handleRef.current?.getCreationLog().length ?? 0) > 0
|
|
3034
|
+
}), [performInsert]);
|
|
3035
|
+
const wrapperStyle = isMobile ? { position: "fixed", inset: 0, zIndex: 40 } : {
|
|
3036
|
+
position: "absolute",
|
|
3037
|
+
top: "50%",
|
|
3038
|
+
left: withLeftPanel ? "calc(50% + 120px)" : "50%",
|
|
3039
|
+
transform: "translate(-50%, -50%)",
|
|
3040
|
+
zIndex: 40
|
|
3041
|
+
};
|
|
3042
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3043
|
+
"div",
|
|
3044
|
+
{
|
|
3045
|
+
role: "dialog",
|
|
3046
|
+
"aria-label": "D\u1EF1ng h\xECnh h\u1ECDc",
|
|
3047
|
+
"data-testid": "geometry-editor-panel",
|
|
3048
|
+
"data-stamp-area": "true",
|
|
3049
|
+
"data-mobile-editor": isMobile ? "true" : void 0,
|
|
3050
|
+
style: wrapperStyle,
|
|
3051
|
+
className: [
|
|
3052
|
+
isDark ? "theme--dark " : "",
|
|
3053
|
+
"flex flex-col overflow-hidden bg-white",
|
|
3054
|
+
isMobile ? "h-full w-full" : "h-[540px] max-h-[85vh] w-[640px] max-w-[calc(100vw-280px)] rounded-lg border border-slate-300 shadow-2xl ring-1 ring-black/5"
|
|
3055
|
+
].join(" "),
|
|
3056
|
+
children: [
|
|
3057
|
+
/* @__PURE__ */ jsxRuntime.jsxs("header", { className: "flex items-center gap-2 border-b border-slate-200 bg-gradient-to-r from-emerald-600 to-teal-600 px-3 py-2 text-white", children: [
|
|
3058
|
+
isMobile && /* @__PURE__ */ jsxRuntime.jsx(
|
|
3059
|
+
"button",
|
|
3060
|
+
{
|
|
3061
|
+
type: "button",
|
|
3062
|
+
onClick: onOpenDrawer,
|
|
3063
|
+
"aria-label": "M\u1EDF ng\u0103n c\xF4ng c\u1EE5",
|
|
3064
|
+
className: "-ml-1 inline-flex h-10 w-10 items-center justify-center rounded transition hover:bg-white/15",
|
|
3065
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
3066
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "4", y1: "6", x2: "20", y2: "6" }),
|
|
3067
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "4", y1: "12", x2: "20", y2: "12" }),
|
|
3068
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "4", y1: "18", x2: "20", y2: "18" })
|
|
3069
|
+
] })
|
|
3070
|
+
}
|
|
3071
|
+
),
|
|
3072
|
+
/* @__PURE__ */ jsxRuntime.jsxs("h3", { className: "flex flex-1 items-center gap-2 text-sm font-semibold", children: [
|
|
3073
|
+
/* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
3074
|
+
/* @__PURE__ */ jsxRuntime.jsx("polygon", { points: "3,18 12,3 21,18" }),
|
|
3075
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "3", r: "1.5", fill: "currentColor" }),
|
|
3076
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "3", cy: "18", r: "1.5", fill: "currentColor" }),
|
|
3077
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "21", cy: "18", r: "1.5", fill: "currentColor" })
|
|
3078
|
+
] }),
|
|
3079
|
+
"D\u1EF1ng h\xECnh h\u1ECDc"
|
|
3080
|
+
] }),
|
|
3081
|
+
isMobile && /* @__PURE__ */ jsxRuntime.jsx(
|
|
3082
|
+
"button",
|
|
3083
|
+
{
|
|
3084
|
+
type: "button",
|
|
3085
|
+
onClick: handleInsert,
|
|
3086
|
+
disabled: !ready,
|
|
3087
|
+
"data-testid": "geometry-insert-btn-mobile",
|
|
3088
|
+
className: "rounded bg-white/15 px-3 py-1.5 text-xs font-semibold transition hover:bg-white/25 disabled:opacity-50",
|
|
3089
|
+
children: "Ch\xE8n"
|
|
3090
|
+
}
|
|
3091
|
+
),
|
|
3092
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { onClick: onClose, "aria-label": "\u0110\xF3ng", className: "inline-flex h-9 w-9 items-center justify-center rounded transition hover:bg-white/15", children: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
3093
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "6", y1: "6", x2: "18", y2: "18" }),
|
|
3094
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "18", y1: "6", x2: "6", y2: "18" })
|
|
3095
|
+
] }) })
|
|
3096
|
+
] }),
|
|
3097
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "min-h-0 flex-1", style: isMobile ? void 0 : { height: "420px" }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3098
|
+
JSXGraphMiniBoard,
|
|
3099
|
+
{
|
|
3100
|
+
onReady: handleReady,
|
|
3101
|
+
initialState,
|
|
3102
|
+
isDark
|
|
3103
|
+
}
|
|
3104
|
+
) }),
|
|
3105
|
+
propsPopover && (propsPopover.kind === "point" ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
3106
|
+
PropertiesPopover,
|
|
3107
|
+
{
|
|
3108
|
+
kind: "point",
|
|
3109
|
+
anchor: propsPopover.screenCoords,
|
|
3110
|
+
isDark,
|
|
3111
|
+
currentName: propsPopover.name,
|
|
3112
|
+
currentColor: propsPopover.color,
|
|
3113
|
+
currentDash: propsPopover.dash,
|
|
3114
|
+
currentWidth: propsPopover.width,
|
|
3115
|
+
currentFace: propsPopover.face,
|
|
3116
|
+
currentShowLabel: propsPopover.showLabel,
|
|
3117
|
+
getAllNames: () => handleRef.current?.getAllPointNames() ?? [],
|
|
3118
|
+
onClose: () => setPropsPopover(null),
|
|
3119
|
+
onMutate: (patch) => {
|
|
3120
|
+
handleRef.current?.mutateObject(propsPopover.obj, patch);
|
|
3121
|
+
if (patch.remove) setPropsPopover(null);
|
|
3122
|
+
if (typeof patch.valueLabel === "boolean" || patch.attrs) {
|
|
3123
|
+
setPropsPopover((cur) => cur ? { ...cur, showValue: patch.valueLabel ?? cur.showValue } : cur);
|
|
3124
|
+
}
|
|
3125
|
+
}
|
|
3126
|
+
}
|
|
3127
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
3128
|
+
PropertiesPopover,
|
|
3129
|
+
{
|
|
3130
|
+
kind: propsPopover.kind,
|
|
3131
|
+
anchor: propsPopover.screenCoords,
|
|
3132
|
+
isDark,
|
|
3133
|
+
currentName: propsPopover.name,
|
|
3134
|
+
currentColor: propsPopover.color,
|
|
3135
|
+
currentDash: propsPopover.dash,
|
|
3136
|
+
currentWidth: propsPopover.width,
|
|
3137
|
+
currentShowLabel: propsPopover.showLabel,
|
|
3138
|
+
currentShowValue: propsPopover.showValue,
|
|
3139
|
+
getAllNames: () => handleRef.current?.getAllPointNames() ?? [],
|
|
3140
|
+
onClose: () => setPropsPopover(null),
|
|
3141
|
+
onMutate: (patch) => {
|
|
3142
|
+
handleRef.current?.mutateObject(propsPopover.obj, patch);
|
|
3143
|
+
if (patch.remove) setPropsPopover(null);
|
|
3144
|
+
if (typeof patch.valueLabel === "boolean") {
|
|
3145
|
+
setPropsPopover((cur) => cur ? { ...cur, showValue: patch.valueLabel ?? cur.showValue } : cur);
|
|
3146
|
+
}
|
|
3147
|
+
if (patch.attrs && "withLabel" in patch.attrs) {
|
|
3148
|
+
setPropsPopover((cur) => cur ? { ...cur, showLabel: !!patch.attrs?.withLabel } : cur);
|
|
3149
|
+
}
|
|
3150
|
+
}
|
|
3151
|
+
}
|
|
3152
|
+
)),
|
|
3153
|
+
transformPopover && /* @__PURE__ */ jsxRuntime.jsx(
|
|
3154
|
+
TransformParamPopover,
|
|
3155
|
+
{
|
|
3156
|
+
kind: transformPopover.tool,
|
|
3157
|
+
anchor: transformPopover.anchor,
|
|
3158
|
+
defaultValue: transformPopover.tool === "rotate" ? 90 : transformPopover.tool === "dilate" ? 2 : 6,
|
|
3159
|
+
isDark,
|
|
3160
|
+
onConfirm: (v) => {
|
|
3161
|
+
handleRef.current?.confirmTransformParam(v);
|
|
3162
|
+
setTransformPopover(null);
|
|
3163
|
+
},
|
|
3164
|
+
onCancel: () => {
|
|
3165
|
+
handleRef.current?.cancelTransformParam();
|
|
3166
|
+
setTransformPopover(null);
|
|
3167
|
+
}
|
|
3168
|
+
}
|
|
3169
|
+
),
|
|
3170
|
+
!isMobile && /* @__PURE__ */ jsxRuntime.jsxs("footer", { className: "flex items-center justify-between border-t border-slate-200 bg-slate-50 px-3 py-2", children: [
|
|
3171
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs text-slate-500", children: "Ch\u1ECDn c\xF4ng c\u1EE5 b\xEAn tr\xE1i, click tr\xEAn b\u1EA3ng \u0111\u1EC3 d\u1EF1ng h\xECnh." }),
|
|
3172
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2", children: [
|
|
3173
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3174
|
+
"button",
|
|
3175
|
+
{
|
|
3176
|
+
onClick: onClose,
|
|
3177
|
+
className: "rounded border border-slate-300 bg-white px-3 py-1 text-xs font-medium text-slate-700 transition hover:bg-slate-100",
|
|
3178
|
+
children: "Hu\u1EF7"
|
|
3179
|
+
}
|
|
3180
|
+
),
|
|
3181
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3182
|
+
"button",
|
|
3183
|
+
{
|
|
3184
|
+
onClick: handleInsert,
|
|
3185
|
+
disabled: !ready,
|
|
3186
|
+
"data-testid": "geometry-insert-btn",
|
|
3187
|
+
className: "rounded bg-emerald-600 px-3 py-1 text-xs font-medium text-white transition hover:bg-emerald-700 disabled:opacity-50",
|
|
3188
|
+
children: "Ch\xE8n"
|
|
3189
|
+
}
|
|
3190
|
+
)
|
|
3191
|
+
] })
|
|
3192
|
+
] })
|
|
3193
|
+
]
|
|
3194
|
+
}
|
|
3195
|
+
);
|
|
3196
|
+
}
|
|
3197
|
+
);
|
|
3198
|
+
}
|
|
3199
|
+
});
|
|
3200
|
+
function isFieldFocused() {
|
|
3201
|
+
const ae = typeof document !== "undefined" ? document.activeElement : null;
|
|
3202
|
+
return !!(ae && (ae.tagName === "INPUT" || ae.tagName === "TEXTAREA" || ae.isContentEditable));
|
|
3203
|
+
}
|
|
3204
|
+
function useChordShortcut(args) {
|
|
3205
|
+
const { groupOrder, tools, onSelect, enabled } = args;
|
|
3206
|
+
const [chordGroup, setChordGroup] = react.useState(null);
|
|
3207
|
+
const groupOrderRef = react.useRef(groupOrder);
|
|
3208
|
+
const toolsRef = react.useRef(tools);
|
|
3209
|
+
const onSelectRef = react.useRef(onSelect);
|
|
3210
|
+
const chordGroupRef = react.useRef(null);
|
|
3211
|
+
groupOrderRef.current = groupOrder;
|
|
3212
|
+
toolsRef.current = tools;
|
|
3213
|
+
onSelectRef.current = onSelect;
|
|
3214
|
+
const cancel = react.useCallback(() => {
|
|
3215
|
+
chordGroupRef.current = null;
|
|
3216
|
+
setChordGroup(null);
|
|
3217
|
+
}, []);
|
|
3218
|
+
react.useEffect(() => {
|
|
3219
|
+
if (!enabled) return;
|
|
3220
|
+
const setChord = (next) => {
|
|
3221
|
+
chordGroupRef.current = next;
|
|
3222
|
+
setChordGroup(next);
|
|
3223
|
+
};
|
|
3224
|
+
const onKey = (e) => {
|
|
3225
|
+
if (e.metaKey || e.ctrlKey || e.altKey) return;
|
|
3226
|
+
if (isFieldFocused()) return;
|
|
3227
|
+
const key = e.key;
|
|
3228
|
+
const lower = key.length === 1 ? key.toLowerCase() : key;
|
|
3229
|
+
if (key === "Escape") {
|
|
3230
|
+
if (chordGroupRef.current !== null) {
|
|
3231
|
+
e.preventDefault();
|
|
3232
|
+
e.stopPropagation();
|
|
3233
|
+
setChord(null);
|
|
3234
|
+
}
|
|
3235
|
+
return;
|
|
3236
|
+
}
|
|
3237
|
+
if (lower.length === 1 && lower >= "a" && lower <= "z") {
|
|
3238
|
+
const idx = lower.charCodeAt(0) - A_CODE2;
|
|
3239
|
+
if (idx < groupOrderRef.current.length) {
|
|
3240
|
+
e.preventDefault();
|
|
3241
|
+
e.stopPropagation();
|
|
3242
|
+
setChord(groupOrderRef.current[idx]);
|
|
3243
|
+
}
|
|
3244
|
+
return;
|
|
3245
|
+
}
|
|
3246
|
+
if (key >= "1" && key <= "9") {
|
|
3247
|
+
const active = chordGroupRef.current;
|
|
3248
|
+
if (active === null) return;
|
|
3249
|
+
const n = key.charCodeAt(0) - "1".charCodeAt(0);
|
|
3250
|
+
const toolsInGroup = toolsRef.current.filter(
|
|
3251
|
+
(t) => t.group === active
|
|
3252
|
+
);
|
|
3253
|
+
e.preventDefault();
|
|
3254
|
+
e.stopPropagation();
|
|
3255
|
+
if (n < toolsInGroup.length) {
|
|
3256
|
+
onSelectRef.current(toolsInGroup[n].key);
|
|
3257
|
+
}
|
|
3258
|
+
setChord(null);
|
|
3259
|
+
return;
|
|
3260
|
+
}
|
|
3261
|
+
};
|
|
3262
|
+
window.addEventListener("keydown", onKey, { capture: true });
|
|
3263
|
+
return () => {
|
|
3264
|
+
window.removeEventListener("keydown", onKey, { capture: true });
|
|
3265
|
+
};
|
|
3266
|
+
}, [enabled]);
|
|
3267
|
+
return { chordGroup, cancel };
|
|
3268
|
+
}
|
|
3269
|
+
var A_CODE2;
|
|
3270
|
+
var init_useChordShortcut = __esm({
|
|
3271
|
+
"src/stamps/shared/useChordShortcut.ts"() {
|
|
3272
|
+
A_CODE2 = "a".charCodeAt(0);
|
|
3273
|
+
}
|
|
3274
|
+
});
|
|
3275
|
+
|
|
3276
|
+
// src/stamps/shared/svgToImage.ts
|
|
3277
|
+
async function hashString(input) {
|
|
3278
|
+
if (typeof crypto !== "undefined" && crypto.subtle) {
|
|
3279
|
+
const buf = new TextEncoder().encode(input);
|
|
3280
|
+
const digest = await crypto.subtle.digest("SHA-256", buf);
|
|
3281
|
+
return Array.from(new Uint8Array(digest)).slice(0, 16).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
3282
|
+
}
|
|
3283
|
+
let h1 = 2166136261;
|
|
3284
|
+
let h2 = 3421674724;
|
|
3285
|
+
for (let i = 0; i < input.length; i++) {
|
|
3286
|
+
const c = input.charCodeAt(i);
|
|
3287
|
+
h1 ^= c;
|
|
3288
|
+
h1 = Math.imul(h1, 16777619);
|
|
3289
|
+
h2 ^= c + i;
|
|
3290
|
+
h2 = Math.imul(h2, 1099511628211 & 4294967295);
|
|
3291
|
+
}
|
|
3292
|
+
return (h1 >>> 0).toString(16).padStart(8, "0") + (h2 >>> 0).toString(16).padStart(8, "0");
|
|
3293
|
+
}
|
|
3294
|
+
function parseSize(svg, attr) {
|
|
3295
|
+
const re = new RegExp(`<svg[^>]*\\s${attr}="(\\d+(?:\\.\\d+)?)`, "i");
|
|
3296
|
+
const m = svg.match(re);
|
|
3297
|
+
if (m) return Math.max(1, Math.round(parseFloat(m[1])));
|
|
3298
|
+
const vb = svg.match(/viewBox="([\d.\s-]+)"/i);
|
|
3299
|
+
if (vb) {
|
|
3300
|
+
const parts = vb[1].trim().split(/\s+/).map(parseFloat);
|
|
3301
|
+
if (parts.length === 4) return Math.max(1, Math.round(attr === "width" ? parts[2] : parts[3]));
|
|
3302
|
+
}
|
|
3303
|
+
return attr === "width" ? 200 : 100;
|
|
3304
|
+
}
|
|
3305
|
+
async function svgToImageElement(svg) {
|
|
3306
|
+
const width = parseSize(svg, "width");
|
|
3307
|
+
const height = parseSize(svg, "height");
|
|
3308
|
+
const utf8 = unescape(encodeURIComponent(svg));
|
|
3309
|
+
const dataURL = "data:image/svg+xml;base64," + btoa(utf8);
|
|
3310
|
+
const fileId = await hashString(dataURL);
|
|
3311
|
+
return { dataURL, fileId, width, height, mimeType: "image/svg+xml" };
|
|
3312
|
+
}
|
|
3313
|
+
var init_svgToImage = __esm({
|
|
3314
|
+
"src/stamps/shared/svgToImage.ts"() {
|
|
3315
|
+
}
|
|
3316
|
+
});
|
|
3317
|
+
|
|
3318
|
+
// src/stamps/shared/insertImage.ts
|
|
3319
|
+
function buildStampImageElement(api, fileId, width, height, customData, x, y) {
|
|
3320
|
+
const appState = api?.getAppState() ?? { scrollX: 0, scrollY: 0, width: 800, height: 600, zoom: { value: 1 } };
|
|
3321
|
+
const cx = x ?? appState.scrollX + (appState.width ?? 800) / 2 / (appState.zoom?.value ?? 1) - width / 2;
|
|
3322
|
+
const cy = y ?? appState.scrollY + (appState.height ?? 600) / 2 / (appState.zoom?.value ?? 1) - height / 2;
|
|
3323
|
+
return {
|
|
3324
|
+
type: "image",
|
|
3325
|
+
id: "stamp_" + Date.now() + "_" + Math.random().toString(36).slice(2, 8),
|
|
3326
|
+
x: cx,
|
|
3327
|
+
y: cy,
|
|
3328
|
+
width,
|
|
3329
|
+
height,
|
|
3330
|
+
fileId,
|
|
3331
|
+
customData,
|
|
3332
|
+
angle: 0,
|
|
3333
|
+
strokeColor: "transparent",
|
|
3334
|
+
backgroundColor: "transparent",
|
|
3335
|
+
fillStyle: "solid",
|
|
3336
|
+
strokeWidth: 1,
|
|
3337
|
+
strokeStyle: "solid",
|
|
3338
|
+
roughness: 0,
|
|
3339
|
+
opacity: 100,
|
|
3340
|
+
groupIds: [],
|
|
3341
|
+
roundness: null,
|
|
3342
|
+
seed: Math.floor(Math.random() * 1e9),
|
|
3343
|
+
versionNonce: 0,
|
|
3344
|
+
version: 1,
|
|
3345
|
+
isDeleted: false,
|
|
3346
|
+
boundElements: null,
|
|
3347
|
+
updated: Date.now(),
|
|
3348
|
+
link: null,
|
|
3349
|
+
locked: false,
|
|
3350
|
+
status: "saved",
|
|
3351
|
+
scale: [1, 1]
|
|
3352
|
+
};
|
|
3353
|
+
}
|
|
3354
|
+
async function insertStampImage(api, opts) {
|
|
3355
|
+
const { dataURL, fileId, width, height, mimeType } = await svgToImageElement(opts.svgString);
|
|
3356
|
+
api.addFiles([{ id: fileId, dataURL, mimeType, created: Date.now() }]);
|
|
3357
|
+
const customData = opts.makeCustomData(width, height);
|
|
3358
|
+
const elements = api.getSceneElements();
|
|
3359
|
+
const editingId = opts.editingElementId ?? null;
|
|
3360
|
+
if (editingId) {
|
|
3361
|
+
const updated = elements.map(
|
|
3362
|
+
(e) => e.id === editingId ? { ...e, fileId, customData, width, height } : e
|
|
3363
|
+
);
|
|
3364
|
+
api.updateScene({ elements: updated, appState: clearAppStateAfterInsert() });
|
|
3365
|
+
return { fileId, width, height, elementId: editingId };
|
|
3366
|
+
}
|
|
3367
|
+
const newElement = buildStampImageElement(
|
|
3368
|
+
api,
|
|
3369
|
+
fileId,
|
|
3370
|
+
width,
|
|
3371
|
+
height,
|
|
3372
|
+
customData,
|
|
3373
|
+
opts.position?.x,
|
|
3374
|
+
opts.position?.y
|
|
3375
|
+
);
|
|
3376
|
+
api.updateScene({
|
|
3377
|
+
elements: [...elements, newElement],
|
|
3378
|
+
appState: clearAppStateAfterInsert()
|
|
3379
|
+
});
|
|
3380
|
+
return { fileId, width, height, elementId: newElement.id };
|
|
3381
|
+
}
|
|
3382
|
+
var clearAppStateAfterInsert;
|
|
3383
|
+
var init_insertImage = __esm({
|
|
3384
|
+
"src/stamps/shared/insertImage.ts"() {
|
|
3385
|
+
init_svgToImage();
|
|
3386
|
+
clearAppStateAfterInsert = () => ({
|
|
3387
|
+
selectedElementIds: {},
|
|
3388
|
+
croppingElementId: null
|
|
3389
|
+
});
|
|
3390
|
+
}
|
|
3391
|
+
});
|
|
3392
|
+
|
|
3393
|
+
// src/stamps/geometry-2d/host.tsx
|
|
3394
|
+
var host_exports = {};
|
|
3395
|
+
__export(host_exports, {
|
|
3396
|
+
GeometryStampHost: () => GeometryStampHost
|
|
3397
|
+
});
|
|
3398
|
+
var INITIAL_GEOM_STATE, GeometryStampHost;
|
|
3399
|
+
var init_host = __esm({
|
|
3400
|
+
"src/stamps/geometry-2d/host.tsx"() {
|
|
3401
|
+
"use client";
|
|
3402
|
+
init_LeftPanel();
|
|
3403
|
+
init_EditorPanel();
|
|
3404
|
+
init_tools();
|
|
3405
|
+
init_useChordShortcut();
|
|
3406
|
+
init_insertImage();
|
|
3407
|
+
init_types();
|
|
3408
|
+
init_useIsMobile();
|
|
3409
|
+
INITIAL_GEOM_STATE = {
|
|
3410
|
+
tool: "move",
|
|
3411
|
+
showAxis: false,
|
|
3412
|
+
showGrid: false,
|
|
3413
|
+
canUndo: false
|
|
3414
|
+
};
|
|
3415
|
+
GeometryStampHost = react.forwardRef(
|
|
3416
|
+
function GeometryStampHost2({ api, editingElement, onClose, isDark }, ref) {
|
|
3417
|
+
const panelRef = react.useRef(null);
|
|
3418
|
+
const [geomState, setGeomState] = react.useState(INITIAL_GEOM_STATE);
|
|
3419
|
+
const { isMobile } = useIsMobile();
|
|
3420
|
+
const [drawerOpen, setDrawerOpen] = react.useState(false);
|
|
3421
|
+
const { chordGroup } = useChordShortcut({
|
|
3422
|
+
groupOrder: GROUP_ORDER,
|
|
3423
|
+
tools: TOOLS,
|
|
3424
|
+
onSelect: (key) => panelRef.current?.setTool(key),
|
|
3425
|
+
enabled: !isMobile
|
|
3426
|
+
});
|
|
3427
|
+
const initialState = react.useMemo(() => {
|
|
3428
|
+
if (!editingElement) return null;
|
|
3429
|
+
if (!isGeometryCustomData(editingElement.customData)) return null;
|
|
3430
|
+
try {
|
|
3431
|
+
return JSON.parse(editingElement.customData.jsonState);
|
|
3432
|
+
} catch {
|
|
3433
|
+
console.warn("GeometryStampHost: customData jsonState corrupted");
|
|
3434
|
+
return null;
|
|
3435
|
+
}
|
|
3436
|
+
}, [editingElement]);
|
|
3437
|
+
const handleInsert = react.useCallback(
|
|
3438
|
+
async (jsonState, svgString) => {
|
|
3439
|
+
if (!api) return;
|
|
3440
|
+
try {
|
|
3441
|
+
await insertStampImage(api, {
|
|
3442
|
+
svgString,
|
|
3443
|
+
makeCustomData: (width, height) => ({
|
|
3444
|
+
kind: "geometry",
|
|
3445
|
+
version: 1,
|
|
3446
|
+
jsonState,
|
|
3447
|
+
svgWidth: width,
|
|
3448
|
+
svgHeight: height
|
|
3449
|
+
}),
|
|
3450
|
+
editingElementId: editingElement?.id ?? null
|
|
3451
|
+
});
|
|
3452
|
+
} catch (err) {
|
|
3453
|
+
console.error("Geometry insert failed:", err);
|
|
3454
|
+
}
|
|
3455
|
+
onClose();
|
|
3456
|
+
},
|
|
3457
|
+
[api, editingElement?.id, onClose]
|
|
3458
|
+
);
|
|
3459
|
+
react.useImperativeHandle(
|
|
3460
|
+
ref,
|
|
3461
|
+
() => ({
|
|
3462
|
+
tryInsert: () => panelRef.current?.insert() ?? false,
|
|
3463
|
+
hasContent: () => panelRef.current?.hasContent() ?? false
|
|
3464
|
+
}),
|
|
3465
|
+
[]
|
|
3466
|
+
);
|
|
3467
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
3468
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3469
|
+
LeftPanel,
|
|
3470
|
+
{
|
|
3471
|
+
activeTool: geomState.tool,
|
|
3472
|
+
onToolChange: (t) => panelRef.current?.setTool(t),
|
|
3473
|
+
showAxis: geomState.showAxis,
|
|
3474
|
+
showGrid: geomState.showGrid,
|
|
3475
|
+
onShowAxisChange: (b) => panelRef.current?.setShowAxis(b),
|
|
3476
|
+
onShowGridChange: (b) => panelRef.current?.setShowGrid(b),
|
|
3477
|
+
onUndo: () => panelRef.current?.undo(),
|
|
3478
|
+
canUndo: geomState.canUndo,
|
|
3479
|
+
onClose,
|
|
3480
|
+
isDark,
|
|
3481
|
+
isMobile,
|
|
3482
|
+
drawerOpen,
|
|
3483
|
+
onDrawerClose: () => setDrawerOpen(false),
|
|
3484
|
+
chordGroup
|
|
3485
|
+
}
|
|
3486
|
+
),
|
|
3487
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3488
|
+
GeometryEditorPanel,
|
|
3489
|
+
{
|
|
3490
|
+
ref: panelRef,
|
|
3491
|
+
initialState,
|
|
3492
|
+
onInsert: handleInsert,
|
|
3493
|
+
onClose,
|
|
3494
|
+
onStateChange: setGeomState,
|
|
3495
|
+
withLeftPanel: !isMobile,
|
|
3496
|
+
isDark,
|
|
3497
|
+
isMobile,
|
|
3498
|
+
onOpenDrawer: () => setDrawerOpen(true)
|
|
3499
|
+
}
|
|
3500
|
+
)
|
|
3501
|
+
] });
|
|
3502
|
+
}
|
|
3503
|
+
);
|
|
3504
|
+
}
|
|
3505
|
+
});
|
|
3506
|
+
|
|
3507
|
+
// src/stamps/geometry-2d/index.tsx
|
|
3508
|
+
init_render();
|
|
3509
|
+
init_types();
|
|
3510
|
+
var GeometryStampHost3 = react.lazy(
|
|
3511
|
+
() => Promise.resolve().then(() => (init_host(), host_exports)).then((m) => ({ default: m.GeometryStampHost }))
|
|
3512
|
+
);
|
|
3513
|
+
var GeometryIcon = /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
|
|
3514
|
+
/* @__PURE__ */ jsxRuntime.jsx("polygon", { points: "4,20 20,20 12,5" }),
|
|
3515
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "4", cy: "20", r: "1.4", fill: "currentColor", stroke: "none" }),
|
|
3516
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "20", cy: "20", r: "1.4", fill: "currentColor", stroke: "none" }),
|
|
3517
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "5", r: "1.4", fill: "currentColor", stroke: "none" })
|
|
3518
|
+
] });
|
|
3519
|
+
var geometryStamp = {
|
|
3520
|
+
kind: "geometry",
|
|
3521
|
+
shortcutKey: "g",
|
|
3522
|
+
toolbarLabel: "G",
|
|
3523
|
+
toolbarTitle: "Ch\xE8n h\xECnh h\u1ECDc (G)",
|
|
3524
|
+
toolbarIcon: GeometryIcon,
|
|
3525
|
+
toolbarTestId: "stamp-toolbar-geometry",
|
|
3526
|
+
matchesCustomData: isGeometryCustomData,
|
|
3527
|
+
async renderSvgFromCustomData(data) {
|
|
3528
|
+
if (!isGeometryCustomData(data)) {
|
|
3529
|
+
throw new Error("geometryStamp.renderSvgFromCustomData: customData kh\xF4ng ph\u1EA3i geometry");
|
|
3530
|
+
}
|
|
3531
|
+
return renderGeometrySvgFromState(data.jsonState);
|
|
3532
|
+
},
|
|
3533
|
+
async restoreFileFromCustomData(element) {
|
|
3534
|
+
const data = element.customData;
|
|
3535
|
+
const fileId = element.fileId;
|
|
3536
|
+
if (!data || !fileId) return null;
|
|
3537
|
+
if (!isGeometryCustomData(data)) return null;
|
|
3538
|
+
const svgString = await renderGeometrySvgFromState(data.jsonState);
|
|
3539
|
+
const utf8 = unescape(encodeURIComponent(svgString));
|
|
3540
|
+
const dataURL = "data:image/svg+xml;base64," + (typeof btoa !== "undefined" ? btoa(utf8) : Buffer.from(utf8).toString("base64"));
|
|
3541
|
+
return { fileId, dataURL, mimeType: "image/svg+xml" };
|
|
3542
|
+
},
|
|
3543
|
+
Host: GeometryStampHost3
|
|
3544
|
+
};
|
|
3545
|
+
|
|
3546
|
+
exports.geometryStamp = geometryStamp;
|
|
3547
|
+
exports.isGeometryCustomData = isGeometryCustomData;
|
|
3548
|
+
//# sourceMappingURL=geometry-2d.js.map
|
|
3549
|
+
//# sourceMappingURL=geometry-2d.js.map
|