@hankchen/canvas-editor-react 0.0.0-stage → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +157 -2
- package/dist/DropdownMenu-CCvv55NI.js +967 -0
- package/dist/PanelIcon-cQ-hx-Ky.js +87 -0
- package/dist/Tooltip-BAFJN0xP.js +815 -0
- package/dist/canvas/AlignFloatBar.d.ts +6 -0
- package/dist/canvas/CanvasSurface.d.ts +13 -0
- package/dist/canvas/ContextMenu.d.ts +14 -0
- package/dist/canvas/EditOverlayToolbar.d.ts +30 -0
- package/dist/canvas/FindBar.d.ts +13 -0
- package/dist/canvas/GuidesOverlay.d.ts +19 -0
- package/dist/canvas/Ruler.d.ts +32 -0
- package/dist/canvas/TextEditingOverlay.d.ts +22 -0
- package/dist/canvas/createBand.d.ts +6 -0
- package/dist/canvas/findHighlight.d.ts +12 -0
- package/dist/canvas/gizmo.d.ts +24 -0
- package/dist/canvas/guideSnap.d.ts +5 -0
- package/dist/canvas/index.d.ts +24 -0
- package/dist/canvas/resizeHandles.d.ts +3 -0
- package/dist/canvas/scheduler.d.ts +2 -0
- package/dist/canvas/useDpr.d.ts +9 -0
- package/dist/canvas/useFindSession.d.ts +12 -0
- package/dist/canvas/useTextEditing.d.ts +90 -0
- package/dist/canvas-jJ7OaUvZ.js +2171 -0
- package/dist/canvas.js +2 -0
- package/dist/chevron-down-D0_YGxvV.js +359 -0
- package/dist/createLucideIcon-CLd1sc0f.js +140 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +16 -0
- package/dist/layer-panel/LayerPanel.d.ts +6 -0
- package/dist/layer-panel/TemplateTableForm.d.ts +10 -0
- package/dist/layer-panel/addMenu.d.ts +68 -0
- package/dist/layer-panel/index.d.ts +11 -0
- package/dist/layer-panel/useLayerPanel.d.ts +12 -0
- package/dist/layer-panel-DIfOb40N.js +779 -0
- package/dist/layer-panel.js +2 -0
- package/dist/mergeKey--xr8gdWl.js +694 -0
- package/dist/property-panel/PropertyField.d.ts +39 -0
- package/dist/property-panel/PropertyPanel.d.ts +5 -0
- package/dist/property-panel/controlStyles.d.ts +17 -0
- package/dist/property-panel/controls.d.ts +42 -0
- package/dist/property-panel/fieldSchema.d.ts +142 -0
- package/dist/property-panel/fields/AlignField.d.ts +3 -0
- package/dist/property-panel/fields/AnchorDisclosureField.d.ts +3 -0
- package/dist/property-panel/fields/BooleanField.d.ts +3 -0
- package/dist/property-panel/fields/BorderField.d.ts +3 -0
- package/dist/property-panel/fields/BorderWidthInput.d.ts +9 -0
- package/dist/property-panel/fields/ColorField.d.ts +3 -0
- package/dist/property-panel/fields/FontField.d.ts +3 -0
- package/dist/property-panel/fields/ImageSrcField.d.ts +3 -0
- package/dist/property-panel/fields/NumberField.d.ts +3 -0
- package/dist/property-panel/fields/PaddingField.d.ts +3 -0
- package/dist/property-panel/fields/PairField.d.ts +3 -0
- package/dist/property-panel/fields/ResourceValueField.d.ts +3 -0
- package/dist/property-panel/fields/RowsPathField.d.ts +3 -0
- package/dist/property-panel/fields/SelectField.d.ts +3 -0
- package/dist/property-panel/fields/ShorthandModeButton.d.ts +7 -0
- package/dist/property-panel/fields/TextField.d.ts +3 -0
- package/dist/property-panel/fields/TextareaField.d.ts +3 -0
- package/dist/property-panel/fields/ValueTypeSegmented.d.ts +8 -0
- package/dist/property-panel/fields/index.d.ts +18 -0
- package/dist/property-panel/fields/intrinsicSize.d.ts +9 -0
- package/dist/property-panel/imageUpload.d.ts +11 -0
- package/dist/property-panel/index.d.ts +14 -0
- package/dist/property-panel/shorthand.d.ts +28 -0
- package/dist/property-panel/usePropertyPanel.d.ts +67 -0
- package/dist/property-panel/useShorthandMode.d.ts +17 -0
- package/dist/property-panel-DD45Myee.js +1861 -0
- package/dist/property-panel.js +3 -0
- package/dist/resourceTemplate-B4QRWGq7.js +33 -0
- package/dist/shared/DropdownMenu.d.ts +18 -0
- package/dist/shared/ExpressionCompletionPopup.d.ts +11 -0
- package/dist/shared/ExpressionPathPicker.d.ts +23 -0
- package/dist/shared/HelpDialog.d.ts +10 -0
- package/dist/shared/PanelIcon.d.ts +11 -0
- package/dist/shared/Tooltip.d.ts +11 -0
- package/dist/shared/completion.d.ts +73 -0
- package/dist/shared/completionAnchor.d.ts +28 -0
- package/dist/shared/editableTarget.d.ts +14 -0
- package/dist/shared/expressionContext.d.ts +22 -0
- package/dist/shared/fontPicker.d.ts +13 -0
- package/dist/shared/index.d.ts +42 -0
- package/dist/shared/mergeKey.d.ts +2 -0
- package/dist/shared/pathPickerModel.d.ts +24 -0
- package/dist/shared/popupPosition.d.ts +41 -0
- package/dist/shared/resourceTemplate.d.ts +7 -0
- package/dist/shared/rowsPathPickerSource.d.ts +15 -0
- package/dist/shared/shortcutsHelp.d.ts +30 -0
- package/dist/shared/uploadFile.d.ts +2 -0
- package/dist/shared/useCnTheme.d.ts +11 -0
- package/dist/shared/useDataSourceSchema.d.ts +10 -0
- package/dist/shared/useDoc.d.ts +2 -0
- package/dist/shared/useDocumentExchange.d.ts +21 -0
- package/dist/shared/useDropdownMenu.d.ts +163 -0
- package/dist/shared/useExpressionCompletion.d.ts +35 -0
- package/dist/shared/useExpressionDiagnostics.d.ts +29 -0
- package/dist/shared/useHistory.d.ts +6 -0
- package/dist/shared/useSelection.d.ts +2 -0
- package/dist/shared/useShortcuts.d.ts +2 -0
- package/dist/shared/useShortcutsHelp.d.ts +8 -0
- package/dist/shared/useTransientFeedback.d.ts +9 -0
- package/dist/shared/useViewport.d.ts +2 -0
- package/dist/shared-QI04Xk-a.js +236 -0
- package/dist/shared.js +9 -0
- package/dist/status-bar/StatusBar.d.ts +14 -0
- package/dist/status-bar/index.d.ts +9 -0
- package/dist/status-bar/layerGeometryLabel.d.ts +13 -0
- package/dist/status-bar/layerPathLabel.d.ts +2 -0
- package/dist/status-bar-Bt3TonDm.js +181 -0
- package/dist/status-bar.js +2 -0
- package/dist/style.css +2 -0
- package/dist/theme.css +420 -0
- package/dist/useDoc-B2LXNJV7.js +32 -0
- package/dist/useViewport-DXtOHYgJ.js +18 -0
- package/package.json +83 -3
|
@@ -0,0 +1,2171 @@
|
|
|
1
|
+
import { a as e, i as t, l as n, n as r, o as i, p as a, r as o, s, t as c, u as l } from "./chevron-down-D0_YGxvV.js";
|
|
2
|
+
import { a as u, r as d, s as f, t as p } from "./PanelIcon-cQ-hx-Ky.js";
|
|
3
|
+
import { n as m, s as h, t as g } from "./Tooltip-BAFJN0xP.js";
|
|
4
|
+
import { f as _, i as v, l as y, m as b, p as x, r as S, t as C, u as w } from "./DropdownMenu-CCvv55NI.js";
|
|
5
|
+
import { a as T, c as E, d as D, f as O, m as k, p as A, r as j, s as M, t as N } from "./mergeKey--xr8gdWl.js";
|
|
6
|
+
import { n as P, t as F } from "./useViewport-DXtOHYgJ.js";
|
|
7
|
+
import { t as I } from "./createLucideIcon-CLd1sc0f.js";
|
|
8
|
+
import { useCallback as L, useEffect as R, useImperativeHandle as z, useRef as B, useState as V, useSyncExternalStore as H } from "react";
|
|
9
|
+
import { jsx as U, jsxs as W } from "react/jsx-runtime";
|
|
10
|
+
//#region ../canvas-editor/src/spatial/camera.ts
|
|
11
|
+
function ee(e, t) {
|
|
12
|
+
if (!(t > 0)) return e;
|
|
13
|
+
let n = e.zoom * t;
|
|
14
|
+
return {
|
|
15
|
+
x: Math.round(e.x * n) / n,
|
|
16
|
+
y: Math.round(e.y * n) / n,
|
|
17
|
+
zoom: e.zoom
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function te(e) {
|
|
21
|
+
return 6 / e;
|
|
22
|
+
}
|
|
23
|
+
function G(e, t, n) {
|
|
24
|
+
let r = [];
|
|
25
|
+
for (let i = 0; i < e.layers.length; i += 1) {
|
|
26
|
+
if (t !== null && i === t) continue;
|
|
27
|
+
let o = e.layers[i];
|
|
28
|
+
o.visible !== !1 && r.push(a(o, 0, 0, e.width, e.height, n));
|
|
29
|
+
}
|
|
30
|
+
return r;
|
|
31
|
+
}
|
|
32
|
+
function K(e, t, n, r) {
|
|
33
|
+
let i = [];
|
|
34
|
+
for (let e of n) i.push({
|
|
35
|
+
orientation: "vertical",
|
|
36
|
+
position: e.x,
|
|
37
|
+
source: "layer"
|
|
38
|
+
}, {
|
|
39
|
+
orientation: "vertical",
|
|
40
|
+
position: e.x + e.width / 2,
|
|
41
|
+
source: "layer"
|
|
42
|
+
}, {
|
|
43
|
+
orientation: "vertical",
|
|
44
|
+
position: e.x + e.width,
|
|
45
|
+
source: "layer"
|
|
46
|
+
}, {
|
|
47
|
+
orientation: "horizontal",
|
|
48
|
+
position: e.y,
|
|
49
|
+
source: "layer"
|
|
50
|
+
}, {
|
|
51
|
+
orientation: "horizontal",
|
|
52
|
+
position: e.y + e.height / 2,
|
|
53
|
+
source: "layer"
|
|
54
|
+
}, {
|
|
55
|
+
orientation: "horizontal",
|
|
56
|
+
position: e.y + e.height,
|
|
57
|
+
source: "layer"
|
|
58
|
+
});
|
|
59
|
+
i.push({
|
|
60
|
+
orientation: "vertical",
|
|
61
|
+
position: e / 2,
|
|
62
|
+
source: "canvas-center"
|
|
63
|
+
}, {
|
|
64
|
+
orientation: "horizontal",
|
|
65
|
+
position: t / 2,
|
|
66
|
+
source: "canvas-center"
|
|
67
|
+
});
|
|
68
|
+
for (let e of r) i.push({
|
|
69
|
+
orientation: e.orientation,
|
|
70
|
+
position: e.position,
|
|
71
|
+
source: "guide"
|
|
72
|
+
});
|
|
73
|
+
return i;
|
|
74
|
+
}
|
|
75
|
+
function q(e, t, n, r) {
|
|
76
|
+
let i = null;
|
|
77
|
+
for (let a of t) if (a.orientation === n) for (let t of e) {
|
|
78
|
+
let e = a.position - t, n = Math.abs(e);
|
|
79
|
+
n > r || (i === null || n < Math.abs(i.delta)) && (i = {
|
|
80
|
+
delta: e,
|
|
81
|
+
axis: a
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return i;
|
|
85
|
+
}
|
|
86
|
+
function J(e, t, n) {
|
|
87
|
+
let r = q(e.vertical, t, "vertical", n), i = q(e.horizontal, t, "horizontal", n);
|
|
88
|
+
return {
|
|
89
|
+
dx: r ? r.delta : 0,
|
|
90
|
+
dy: i ? i.delta : 0,
|
|
91
|
+
axes: [...r ? [r.axis] : [], ...i ? [i.axis] : []]
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function Y(e, t, n) {
|
|
95
|
+
return J({
|
|
96
|
+
vertical: [
|
|
97
|
+
e.x,
|
|
98
|
+
e.x + e.width / 2,
|
|
99
|
+
e.x + e.width
|
|
100
|
+
],
|
|
101
|
+
horizontal: [
|
|
102
|
+
e.y,
|
|
103
|
+
e.y + e.height / 2,
|
|
104
|
+
e.y + e.height
|
|
105
|
+
]
|
|
106
|
+
}, t, n);
|
|
107
|
+
}
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region ../canvas-editor/src/spatial/resize.ts
|
|
110
|
+
function X(e, t) {
|
|
111
|
+
let n = e.x + e.width, r = e.y + e.height;
|
|
112
|
+
switch (t) {
|
|
113
|
+
case "nw": return {
|
|
114
|
+
x: e.x,
|
|
115
|
+
y: e.y
|
|
116
|
+
};
|
|
117
|
+
case "n": return {
|
|
118
|
+
x: e.x + e.width / 2,
|
|
119
|
+
y: e.y
|
|
120
|
+
};
|
|
121
|
+
case "ne": return {
|
|
122
|
+
x: n,
|
|
123
|
+
y: e.y
|
|
124
|
+
};
|
|
125
|
+
case "e": return {
|
|
126
|
+
x: n,
|
|
127
|
+
y: e.y + e.height / 2
|
|
128
|
+
};
|
|
129
|
+
case "se": return {
|
|
130
|
+
x: n,
|
|
131
|
+
y: r
|
|
132
|
+
};
|
|
133
|
+
case "s": return {
|
|
134
|
+
x: e.x + e.width / 2,
|
|
135
|
+
y: r
|
|
136
|
+
};
|
|
137
|
+
case "sw": return {
|
|
138
|
+
x: e.x,
|
|
139
|
+
y: r
|
|
140
|
+
};
|
|
141
|
+
case "w": return {
|
|
142
|
+
x: e.x,
|
|
143
|
+
y: e.y + e.height / 2
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
//#endregion
|
|
148
|
+
//#region ../canvas-editor/src/spatial/wheel.ts
|
|
149
|
+
function ne(e) {
|
|
150
|
+
return e.ctrlKey || e.metaKey ? "zoom" : e.shiftKey ? "pan-x" : "pan";
|
|
151
|
+
}
|
|
152
|
+
//#endregion
|
|
153
|
+
//#region ../canvas-browser-renderer/src/fonts.ts
|
|
154
|
+
function Z(e) {
|
|
155
|
+
return e === "" || /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/.test(e.trim());
|
|
156
|
+
}
|
|
157
|
+
function re(e) {
|
|
158
|
+
return Z(e) ? "sans-serif" : `${ie(e)}, sans-serif`;
|
|
159
|
+
}
|
|
160
|
+
function ie(e) {
|
|
161
|
+
let t = 2166136261;
|
|
162
|
+
for (let n = 0; n < e.length; n++) t ^= e.charCodeAt(n), t = Math.imul(t, 16777619);
|
|
163
|
+
return `canvas-font-${(t >>> 0).toString(36)}`;
|
|
164
|
+
}
|
|
165
|
+
//#endregion
|
|
166
|
+
//#region src/canvas/ContextMenu.tsx
|
|
167
|
+
function ae({ editor: e, ref: t }) {
|
|
168
|
+
let n = B(null), [r, i] = V(!1), [a, o] = V({
|
|
169
|
+
x: 0,
|
|
170
|
+
y: 0
|
|
171
|
+
}), s = y(), c = `先 ${w("copyStyle", s)} 复制样式`, l = `图层已锁定(${w("toggleLayerLock", s)} 解锁后可删除)`, u = P(e), p = B(u);
|
|
172
|
+
p.current = u;
|
|
173
|
+
let g = L((t) => e.subscribe((e) => {
|
|
174
|
+
e.scope === "doc" && t();
|
|
175
|
+
}), [e]);
|
|
176
|
+
H(g, () => e.store.doc);
|
|
177
|
+
let _ = u !== null && d(u), b = u !== null && e.canCopySelection, x = u !== null && e.canCopyStyle, C = u !== null && e.canPasteStyle, T = (() => {
|
|
178
|
+
let t = u, n = e.store.doc;
|
|
179
|
+
return !t || !n || !d(t) ? !0 : f(n, t)?.visible ?? !0;
|
|
180
|
+
})(), E = (() => {
|
|
181
|
+
let t = u, n = e.store.doc;
|
|
182
|
+
return !t || !n ? null : f(n, t);
|
|
183
|
+
})();
|
|
184
|
+
function D() {
|
|
185
|
+
let e = u;
|
|
186
|
+
return !e || typeof e[1] != "number" ? null : ["layers", e[1]];
|
|
187
|
+
}
|
|
188
|
+
let O = E?.type === "TableLayer" && E.template !== null, k = u?.[u.length - 1] === "template", A = u !== null && e.isLocked(u), j = (() => {
|
|
189
|
+
let e = E;
|
|
190
|
+
if (!e || e.type !== "TableLayer" || e.template !== null) return !1;
|
|
191
|
+
let t = e.rows[e.rows.length - 1];
|
|
192
|
+
return t !== void 0 && t.cells.length > 0;
|
|
193
|
+
})(), M = u !== null && E?.type === "ImageLayer" ? e.baseImageConversionBlock(u) : null, N = (() => {
|
|
194
|
+
switch (M) {
|
|
195
|
+
case "not-head-root": return "仅数组头的垫底图片图层可转换";
|
|
196
|
+
case "not-image": return "仅图片图层可转换";
|
|
197
|
+
case "not-covering": return "仅覆盖整个画布的垫底图片图层可转换";
|
|
198
|
+
case "hidden": return "隐藏图层不可转换——先恢复显示再转换";
|
|
199
|
+
case "expression-marked": return "表达式驱动的底图不转换——背景是静态声明,标记保留在图层上";
|
|
200
|
+
case "no-image-src": return "该图层无图片引用——纯色底请在画布属性面板设置背景色";
|
|
201
|
+
case "locked": return "图层已锁定——解锁后可转换";
|
|
202
|
+
default: return;
|
|
203
|
+
}
|
|
204
|
+
})(), F = v(e), I = h(F), ee = (() => {
|
|
205
|
+
let e = E;
|
|
206
|
+
return !e || e.type !== "TableLayer" ? "" : `模板取自末行,其余 ${Math.max(e.rows.length - 1, 0)} 行将移除(可撤销)`;
|
|
207
|
+
})(), te = (() => {
|
|
208
|
+
if (F === null) return S;
|
|
209
|
+
if (j) return ee;
|
|
210
|
+
let e = E;
|
|
211
|
+
return e !== null && e.type === "TableLayer" && e.rows.length === 0 ? "空表无可转换行" : "末行为空——先为末行加格";
|
|
212
|
+
})(), [G, K] = V(!1), [q, J] = V("");
|
|
213
|
+
function Y() {
|
|
214
|
+
K(!0), J("");
|
|
215
|
+
}
|
|
216
|
+
function X() {
|
|
217
|
+
let t = D();
|
|
218
|
+
t && q !== "" && (e.convertTableToTemplate(t, q), Z());
|
|
219
|
+
}
|
|
220
|
+
let ne = [
|
|
221
|
+
{
|
|
222
|
+
key: "visibility",
|
|
223
|
+
label: T ? "隐藏" : "显示",
|
|
224
|
+
enabled: _,
|
|
225
|
+
title: _ ? void 0 : "显示/隐藏仅作用于根图层",
|
|
226
|
+
run: () => {
|
|
227
|
+
let t = p.current;
|
|
228
|
+
t && e.toggleLayerVisibility(t);
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
key: "duplicate",
|
|
233
|
+
label: "创建副本",
|
|
234
|
+
enabled: b,
|
|
235
|
+
title: b ? void 0 : "行/格/行模板是容器内结构,不可复制",
|
|
236
|
+
run: () => e.duplicateSelection()
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
key: "copy-style",
|
|
240
|
+
label: "复制样式",
|
|
241
|
+
enabled: x,
|
|
242
|
+
title: !x && k ? "行模板替身无样式可复制" : void 0,
|
|
243
|
+
run: () => {
|
|
244
|
+
let t = p.current;
|
|
245
|
+
t && e.copyStyle(t);
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
key: "paste-style",
|
|
250
|
+
label: "粘贴样式",
|
|
251
|
+
enabled: C,
|
|
252
|
+
title: C ? void 0 : c,
|
|
253
|
+
run: () => {
|
|
254
|
+
let t = p.current;
|
|
255
|
+
t && e.pasteStyle(t);
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
key: "forward",
|
|
260
|
+
label: "前移一层",
|
|
261
|
+
enabled: _,
|
|
262
|
+
title: _ ? void 0 : "前移/后移仅对根图层生效",
|
|
263
|
+
run: () => e.bringForward()
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
key: "backward",
|
|
267
|
+
label: "后移一层",
|
|
268
|
+
enabled: _,
|
|
269
|
+
title: _ ? void 0 : "前移/后移仅对根图层生效",
|
|
270
|
+
run: () => e.sendBackward()
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
key: "front",
|
|
274
|
+
label: "置顶",
|
|
275
|
+
enabled: _,
|
|
276
|
+
title: _ ? void 0 : "置顶/置底仅对根图层生效",
|
|
277
|
+
run: () => e.bringToFront()
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
key: "back",
|
|
281
|
+
label: "置底",
|
|
282
|
+
enabled: _,
|
|
283
|
+
title: _ ? void 0 : "置顶/置底仅对根图层生效",
|
|
284
|
+
run: () => e.sendToBack()
|
|
285
|
+
},
|
|
286
|
+
...E?.type === "ImageLayer" ? [{
|
|
287
|
+
key: "to-background",
|
|
288
|
+
label: "转为画布背景",
|
|
289
|
+
enabled: M === null,
|
|
290
|
+
title: N,
|
|
291
|
+
run: () => e.convertSelectionToBackground()
|
|
292
|
+
}] : [],
|
|
293
|
+
...O ? [{
|
|
294
|
+
key: "to-rows",
|
|
295
|
+
label: "转回普通表",
|
|
296
|
+
enabled: !0,
|
|
297
|
+
title: "行模板实例化为单行,恢复普通表格编辑",
|
|
298
|
+
run: () => {
|
|
299
|
+
let t = D();
|
|
300
|
+
t && e.convertTableToRows(t);
|
|
301
|
+
}
|
|
302
|
+
}] : E?.type === "TableLayer" ? [{
|
|
303
|
+
key: "to-template",
|
|
304
|
+
label: "转为模板表…",
|
|
305
|
+
enabled: F !== null && j,
|
|
306
|
+
title: te,
|
|
307
|
+
keepsOpen: !0,
|
|
308
|
+
run: () => Y()
|
|
309
|
+
}] : [],
|
|
310
|
+
{
|
|
311
|
+
key: "delete",
|
|
312
|
+
label: "删除",
|
|
313
|
+
enabled: u !== null && !k && !A,
|
|
314
|
+
title: k ? "行模板由表持有——转换回普通表请用 V2 转换入口" : A ? l : void 0,
|
|
315
|
+
run: () => {
|
|
316
|
+
let t = p.current;
|
|
317
|
+
t && e.deleteLayer(t);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
], Z = L(() => {
|
|
321
|
+
i(!1), K(!1), J("");
|
|
322
|
+
}, []);
|
|
323
|
+
function re(e) {
|
|
324
|
+
e.run(), e.keepsOpen !== !0 && Z();
|
|
325
|
+
}
|
|
326
|
+
let ie = L((e, t) => {
|
|
327
|
+
o({
|
|
328
|
+
x: e,
|
|
329
|
+
y: t
|
|
330
|
+
}), i(!0);
|
|
331
|
+
}, []), ae = B(r);
|
|
332
|
+
return ae.current = r, R(() => {
|
|
333
|
+
if (!r) return;
|
|
334
|
+
let e = n.current, t = e?.parentElement;
|
|
335
|
+
if (!e || !t) return;
|
|
336
|
+
let i = e.getBoundingClientRect(), a = t.clientWidth - i.width - 2, s = t.clientHeight - i.height - 2;
|
|
337
|
+
o((e) => ({
|
|
338
|
+
x: Math.max(2, Math.min(e.x, a)),
|
|
339
|
+
y: Math.max(2, Math.min(e.y, s))
|
|
340
|
+
}));
|
|
341
|
+
}, [
|
|
342
|
+
r,
|
|
343
|
+
a.x,
|
|
344
|
+
a.y
|
|
345
|
+
]), z(t, () => ({
|
|
346
|
+
openAt: ie,
|
|
347
|
+
close: Z
|
|
348
|
+
})), r ? /* @__PURE__ */ U("div", {
|
|
349
|
+
ref: n,
|
|
350
|
+
className: "cn-context-menu",
|
|
351
|
+
role: "menu",
|
|
352
|
+
"aria-label": "图层操作菜单",
|
|
353
|
+
style: {
|
|
354
|
+
left: `${a.x}px`,
|
|
355
|
+
top: `${a.y}px`
|
|
356
|
+
},
|
|
357
|
+
onPointerDown: (e) => e.stopPropagation(),
|
|
358
|
+
onContextMenu: (e) => e.preventDefault(),
|
|
359
|
+
children: G ? /* @__PURE__ */ W("div", {
|
|
360
|
+
className: "cn-context-menu__form",
|
|
361
|
+
children: [
|
|
362
|
+
/* @__PURE__ */ U("p", {
|
|
363
|
+
className: "cn-context-menu__hint",
|
|
364
|
+
children: ee
|
|
365
|
+
}),
|
|
366
|
+
/* @__PURE__ */ U(m, {
|
|
367
|
+
modelValue: q,
|
|
368
|
+
source: I,
|
|
369
|
+
mode: "rowsPath",
|
|
370
|
+
ariaLabel: "取行路径",
|
|
371
|
+
placeholder: "未选择行路径",
|
|
372
|
+
onPick: J
|
|
373
|
+
}),
|
|
374
|
+
/* @__PURE__ */ W("div", {
|
|
375
|
+
className: "cn-context-menu__form-actions",
|
|
376
|
+
children: [/* @__PURE__ */ U("button", {
|
|
377
|
+
type: "button",
|
|
378
|
+
className: "cn-context-menu__item cn-context-menu__item--confirm",
|
|
379
|
+
disabled: q === "",
|
|
380
|
+
onClick: X,
|
|
381
|
+
children: "确认转换"
|
|
382
|
+
}), /* @__PURE__ */ U("button", {
|
|
383
|
+
type: "button",
|
|
384
|
+
className: "cn-context-menu__item",
|
|
385
|
+
onClick: Z,
|
|
386
|
+
children: "取消"
|
|
387
|
+
})]
|
|
388
|
+
})
|
|
389
|
+
]
|
|
390
|
+
}) : ne.map((e) => /* @__PURE__ */ U("button", {
|
|
391
|
+
type: "button",
|
|
392
|
+
role: "menuitem",
|
|
393
|
+
className: `cn-context-menu__item cn-context-menu__item--${e.key}`,
|
|
394
|
+
disabled: !e.enabled,
|
|
395
|
+
title: e.title,
|
|
396
|
+
onClick: () => re(e),
|
|
397
|
+
children: e.label
|
|
398
|
+
}, e.key))
|
|
399
|
+
}) : null;
|
|
400
|
+
}
|
|
401
|
+
//#endregion
|
|
402
|
+
//#region ../../node_modules/.pnpm/lucide-react@1.84.0_@types+react@19.3.3_react@19.3.1/node_modules/lucide-react/dist/esm/icons/arrow-down-left.mjs
|
|
403
|
+
var oe = {
|
|
404
|
+
name: "arrow-down-left",
|
|
405
|
+
size: 24,
|
|
406
|
+
node: [["path", {
|
|
407
|
+
d: "M17 7 7 17",
|
|
408
|
+
key: "15tmo1"
|
|
409
|
+
}], ["path", {
|
|
410
|
+
d: "M17 17H7V7",
|
|
411
|
+
key: "1org7z"
|
|
412
|
+
}]]
|
|
413
|
+
};
|
|
414
|
+
oe.node;
|
|
415
|
+
var se = I(oe), ce = {
|
|
416
|
+
name: "arrow-down-right",
|
|
417
|
+
size: 24,
|
|
418
|
+
node: [["path", {
|
|
419
|
+
d: "m7 7 10 10",
|
|
420
|
+
key: "1fmybs"
|
|
421
|
+
}], ["path", {
|
|
422
|
+
d: "M17 7v10H7",
|
|
423
|
+
key: "6fjiku"
|
|
424
|
+
}]]
|
|
425
|
+
};
|
|
426
|
+
ce.node;
|
|
427
|
+
var le = I(ce), ue = {
|
|
428
|
+
name: "arrow-up-left",
|
|
429
|
+
size: 24,
|
|
430
|
+
node: [["path", {
|
|
431
|
+
d: "M7 17V7h10",
|
|
432
|
+
key: "11bw93"
|
|
433
|
+
}], ["path", {
|
|
434
|
+
d: "M17 17 7 7",
|
|
435
|
+
key: "2786uv"
|
|
436
|
+
}]]
|
|
437
|
+
};
|
|
438
|
+
ue.node;
|
|
439
|
+
var de = I(ue), fe = {
|
|
440
|
+
name: "arrow-up-right",
|
|
441
|
+
size: 24,
|
|
442
|
+
node: [["path", {
|
|
443
|
+
d: "M7 7h10v10",
|
|
444
|
+
key: "1tivn9"
|
|
445
|
+
}], ["path", {
|
|
446
|
+
d: "M7 17 17 7",
|
|
447
|
+
key: "1vkiza"
|
|
448
|
+
}]]
|
|
449
|
+
};
|
|
450
|
+
fe.node;
|
|
451
|
+
var pe = I(fe), me = {
|
|
452
|
+
name: "chevron-up",
|
|
453
|
+
size: 24,
|
|
454
|
+
node: [["path", {
|
|
455
|
+
d: "m18 15-6-6-6 6",
|
|
456
|
+
key: "153udz"
|
|
457
|
+
}]]
|
|
458
|
+
};
|
|
459
|
+
me.node;
|
|
460
|
+
var he = I(me), ge = {
|
|
461
|
+
name: "minus",
|
|
462
|
+
size: 24,
|
|
463
|
+
node: [["path", {
|
|
464
|
+
d: "M5 12h14",
|
|
465
|
+
key: "1ays0h"
|
|
466
|
+
}]]
|
|
467
|
+
};
|
|
468
|
+
ge.node;
|
|
469
|
+
var _e = I(ge), ve = {
|
|
470
|
+
name: "plus",
|
|
471
|
+
size: 24,
|
|
472
|
+
node: [["path", {
|
|
473
|
+
d: "M5 12h14",
|
|
474
|
+
key: "1ays0h"
|
|
475
|
+
}], ["path", {
|
|
476
|
+
d: "M12 5v14",
|
|
477
|
+
key: "s699le"
|
|
478
|
+
}]]
|
|
479
|
+
};
|
|
480
|
+
ve.node;
|
|
481
|
+
var ye = I(ve), be = {
|
|
482
|
+
name: "text-wrap",
|
|
483
|
+
size: 24,
|
|
484
|
+
node: [
|
|
485
|
+
["path", {
|
|
486
|
+
d: "m16 16-3 3 3 3",
|
|
487
|
+
key: "117b85"
|
|
488
|
+
}],
|
|
489
|
+
["path", {
|
|
490
|
+
d: "M3 12h14.5a1 1 0 0 1 0 7H13",
|
|
491
|
+
key: "18xa6z"
|
|
492
|
+
}],
|
|
493
|
+
["path", {
|
|
494
|
+
d: "M3 19h6",
|
|
495
|
+
key: "1ygdsz"
|
|
496
|
+
}],
|
|
497
|
+
["path", {
|
|
498
|
+
d: "M3 5h18",
|
|
499
|
+
key: "1u36vt"
|
|
500
|
+
}]
|
|
501
|
+
],
|
|
502
|
+
aliases: ["wrap-text"]
|
|
503
|
+
};
|
|
504
|
+
be.node;
|
|
505
|
+
var xe = I(be), Se = {
|
|
506
|
+
name: "x",
|
|
507
|
+
size: 24,
|
|
508
|
+
node: [["path", {
|
|
509
|
+
d: "M18 6 6 18",
|
|
510
|
+
key: "1bl5f8"
|
|
511
|
+
}], ["path", {
|
|
512
|
+
d: "m6 6 12 12",
|
|
513
|
+
key: "d8bk6v"
|
|
514
|
+
}]]
|
|
515
|
+
};
|
|
516
|
+
Se.node;
|
|
517
|
+
var Ce = I(Se);
|
|
518
|
+
//#endregion
|
|
519
|
+
//#region src/canvas/useFindSession.ts
|
|
520
|
+
function we(e) {
|
|
521
|
+
let t = B(0), n = B(null), r = L((n) => e.subscribe((e) => {
|
|
522
|
+
(e.scope === "doc" || e.scope === "ui" && e.branch === "find") && (t.current += 1, n());
|
|
523
|
+
}), [e]), i = L(() => {
|
|
524
|
+
let r = n.current;
|
|
525
|
+
if (r !== null && r.version === t.current) return r.snapshot;
|
|
526
|
+
let i = e.store.ui.find, a = {
|
|
527
|
+
open: i.open,
|
|
528
|
+
query: i.query,
|
|
529
|
+
replacement: i.replacement,
|
|
530
|
+
matches: e.listFindMatches(),
|
|
531
|
+
cursor: e.findCursor
|
|
532
|
+
};
|
|
533
|
+
return n.current = {
|
|
534
|
+
version: t.current,
|
|
535
|
+
snapshot: a
|
|
536
|
+
}, a;
|
|
537
|
+
}, [e]);
|
|
538
|
+
return H(r, i);
|
|
539
|
+
}
|
|
540
|
+
//#endregion
|
|
541
|
+
//#region src/canvas/FindBar.tsx
|
|
542
|
+
function Te({ editor: e, ref: t }) {
|
|
543
|
+
let { open: n, query: r, replacement: i, matches: a, cursor: o } = we(e), s = B(null), [l, u] = V(null), d = a.length, f = d === 0 ? r === "" ? "" : "无结果" : `第 ${o + 1}/${d} 处`, m = d > 0, h = m && o > 0, g = m && o < d - 1, _ = L((t) => {
|
|
544
|
+
let n = e.listFindMatches()[t];
|
|
545
|
+
if (!n) return;
|
|
546
|
+
e.setSelection(n.path);
|
|
547
|
+
let r = e.layerBoxAt(n.path);
|
|
548
|
+
r && e.panToBox(r);
|
|
549
|
+
}, [e]), v = L((t) => {
|
|
550
|
+
let n = e.listFindMatches().length;
|
|
551
|
+
if (n === 0) return;
|
|
552
|
+
let r = Math.min(Math.max(e.findCursor + t, 0), n - 1);
|
|
553
|
+
e.setFindCursor(r), _(r);
|
|
554
|
+
}, [e, _]), y = L(() => {
|
|
555
|
+
e.replaceOne() && _(e.findCursor);
|
|
556
|
+
}, [e, _]), b = L(() => {
|
|
557
|
+
let t = e.replaceAll();
|
|
558
|
+
t !== 0 && (u(`已替换 ${t} 处`), _(e.findCursor));
|
|
559
|
+
}, [e, _]), S = L(() => {
|
|
560
|
+
e.closeFind(), u(null);
|
|
561
|
+
}, [e]);
|
|
562
|
+
z(t, () => ({ close: S }));
|
|
563
|
+
function C(e) {
|
|
564
|
+
if (!(e.nativeEvent.isComposing || e.nativeEvent.keyCode === 229)) {
|
|
565
|
+
if (e.key === "Escape") {
|
|
566
|
+
e.preventDefault(), S();
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
e.key === "Enter" && (e.preventDefault(), v(e.shiftKey ? -1 : 1));
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
R(() => {
|
|
573
|
+
n && s.current?.focus({ preventScroll: !0 });
|
|
574
|
+
}, [n]);
|
|
575
|
+
let w = B(n);
|
|
576
|
+
return w.current = n, R(() => {
|
|
577
|
+
function e(e) {
|
|
578
|
+
w.current && (e.key.toLowerCase() !== "f" || !(e.metaKey || e.ctrlKey) || e.shiftKey || e.altKey || x(e.target) || s.current?.focus({ preventScroll: !0 }));
|
|
579
|
+
}
|
|
580
|
+
return window.addEventListener("keydown", e), () => window.removeEventListener("keydown", e);
|
|
581
|
+
}, []), R(() => {
|
|
582
|
+
u((e) => e === null ? e : null);
|
|
583
|
+
}, [r]), n ? /* @__PURE__ */ W("div", {
|
|
584
|
+
className: "cn-find-bar",
|
|
585
|
+
"data-find-bar": !0,
|
|
586
|
+
role: "search",
|
|
587
|
+
"aria-label": "查找替换",
|
|
588
|
+
onPointerDown: (e) => e.stopPropagation(),
|
|
589
|
+
children: [
|
|
590
|
+
/* @__PURE__ */ U("input", {
|
|
591
|
+
ref: s,
|
|
592
|
+
className: "cn-find-bar__input",
|
|
593
|
+
"data-find-query": !0,
|
|
594
|
+
type: "text",
|
|
595
|
+
value: r,
|
|
596
|
+
placeholder: "查找",
|
|
597
|
+
"aria-label": "查找",
|
|
598
|
+
spellCheck: !1,
|
|
599
|
+
autoComplete: "off",
|
|
600
|
+
onChange: (t) => e.setFindQuery(t.target.value),
|
|
601
|
+
onKeyDown: C
|
|
602
|
+
}),
|
|
603
|
+
/* @__PURE__ */ U("input", {
|
|
604
|
+
className: "cn-find-bar__input",
|
|
605
|
+
"data-find-replace": !0,
|
|
606
|
+
type: "text",
|
|
607
|
+
value: i,
|
|
608
|
+
placeholder: "替换",
|
|
609
|
+
"aria-label": "替换",
|
|
610
|
+
spellCheck: !1,
|
|
611
|
+
autoComplete: "off",
|
|
612
|
+
onChange: (t) => e.setFindReplacement(t.target.value),
|
|
613
|
+
onKeyDown: C
|
|
614
|
+
}),
|
|
615
|
+
/* @__PURE__ */ U("span", {
|
|
616
|
+
className: "cn-find-bar__count",
|
|
617
|
+
"data-find-count": !0,
|
|
618
|
+
children: f
|
|
619
|
+
}),
|
|
620
|
+
l !== null && /* @__PURE__ */ U("span", {
|
|
621
|
+
className: "cn-find-bar__note",
|
|
622
|
+
"data-find-note": !0,
|
|
623
|
+
children: l
|
|
624
|
+
}),
|
|
625
|
+
/* @__PURE__ */ U("button", {
|
|
626
|
+
type: "button",
|
|
627
|
+
className: "cn-find-bar__key",
|
|
628
|
+
"data-find-prev": !0,
|
|
629
|
+
disabled: !h,
|
|
630
|
+
title: "上一处(Shift+Enter)",
|
|
631
|
+
"aria-label": "上一处",
|
|
632
|
+
onClick: () => v(-1),
|
|
633
|
+
children: /* @__PURE__ */ U(p, { icon: he })
|
|
634
|
+
}),
|
|
635
|
+
/* @__PURE__ */ U("button", {
|
|
636
|
+
type: "button",
|
|
637
|
+
className: "cn-find-bar__key",
|
|
638
|
+
"data-find-next": !0,
|
|
639
|
+
disabled: !g,
|
|
640
|
+
title: "下一处(Enter)",
|
|
641
|
+
"aria-label": "下一处",
|
|
642
|
+
onClick: () => v(1),
|
|
643
|
+
children: /* @__PURE__ */ U(p, { icon: c })
|
|
644
|
+
}),
|
|
645
|
+
/* @__PURE__ */ U("button", {
|
|
646
|
+
type: "button",
|
|
647
|
+
className: "cn-find-bar__action",
|
|
648
|
+
"data-find-replace-one": !0,
|
|
649
|
+
disabled: !m,
|
|
650
|
+
title: "替换当前处",
|
|
651
|
+
onClick: y,
|
|
652
|
+
children: "替换"
|
|
653
|
+
}),
|
|
654
|
+
/* @__PURE__ */ U("button", {
|
|
655
|
+
type: "button",
|
|
656
|
+
className: "cn-find-bar__action",
|
|
657
|
+
"data-find-replace-all": !0,
|
|
658
|
+
disabled: !m,
|
|
659
|
+
title: "全部替换",
|
|
660
|
+
onClick: b,
|
|
661
|
+
children: "全部替换"
|
|
662
|
+
}),
|
|
663
|
+
/* @__PURE__ */ U("button", {
|
|
664
|
+
type: "button",
|
|
665
|
+
className: "cn-find-bar__key",
|
|
666
|
+
"data-find-close": !0,
|
|
667
|
+
title: "关闭(Esc)",
|
|
668
|
+
"aria-label": "关闭查找替换",
|
|
669
|
+
onClick: S,
|
|
670
|
+
children: /* @__PURE__ */ U(p, { icon: Ce })
|
|
671
|
+
})
|
|
672
|
+
]
|
|
673
|
+
}) : null;
|
|
674
|
+
}
|
|
675
|
+
//#endregion
|
|
676
|
+
//#region src/canvas/resizeHandles.ts
|
|
677
|
+
var Ee = {
|
|
678
|
+
nw: "nwse-resize",
|
|
679
|
+
se: "nwse-resize",
|
|
680
|
+
ne: "nesw-resize",
|
|
681
|
+
sw: "nesw-resize",
|
|
682
|
+
n: "ns-resize",
|
|
683
|
+
s: "ns-resize",
|
|
684
|
+
e: "ew-resize",
|
|
685
|
+
w: "ew-resize"
|
|
686
|
+
}, De = [{
|
|
687
|
+
value: "static",
|
|
688
|
+
label: "静态"
|
|
689
|
+
}, {
|
|
690
|
+
value: "expression",
|
|
691
|
+
label: "表达式"
|
|
692
|
+
}], Oe = {
|
|
693
|
+
left: {
|
|
694
|
+
icon: r,
|
|
695
|
+
label: "左对齐"
|
|
696
|
+
},
|
|
697
|
+
center: {
|
|
698
|
+
icon: i,
|
|
699
|
+
label: "居中对齐"
|
|
700
|
+
},
|
|
701
|
+
right: {
|
|
702
|
+
icon: t,
|
|
703
|
+
label: "右对齐"
|
|
704
|
+
}
|
|
705
|
+
}, ke = {
|
|
706
|
+
top: {
|
|
707
|
+
icon: o,
|
|
708
|
+
label: "顶对齐"
|
|
709
|
+
},
|
|
710
|
+
center: {
|
|
711
|
+
icon: s,
|
|
712
|
+
label: "居中对齐"
|
|
713
|
+
},
|
|
714
|
+
bottom: {
|
|
715
|
+
icon: e,
|
|
716
|
+
label: "底对齐"
|
|
717
|
+
}
|
|
718
|
+
}, Ae = 1;
|
|
719
|
+
function je({ mode: e, font: t, fontSize: r, fontColor: i, horizontalAlign: a, verticalAlign: o, autowrap: s, style: c, rootRef: u, onModeChange: d, onStyleWrite: f }) {
|
|
720
|
+
function m(e, t, n) {
|
|
721
|
+
f?.({
|
|
722
|
+
key: e,
|
|
723
|
+
value: t,
|
|
724
|
+
final: n
|
|
725
|
+
});
|
|
726
|
+
}
|
|
727
|
+
let h = De.find((t) => t.value === e)?.label ?? e, _ = De.map((t) => ({
|
|
728
|
+
label: t.label,
|
|
729
|
+
checked: t.value === e,
|
|
730
|
+
dataAttrs: { [`data-pill-${t.value}`]: "true" },
|
|
731
|
+
run: () => {
|
|
732
|
+
t.value !== e && d?.(t.value);
|
|
733
|
+
}
|
|
734
|
+
})), v = j(), y = (() => {
|
|
735
|
+
let e = [{
|
|
736
|
+
label: "内置默认字体",
|
|
737
|
+
value: ""
|
|
738
|
+
}];
|
|
739
|
+
if (v !== null) for (let t of v.entries) t.ref !== "" && e.push({
|
|
740
|
+
label: t.label,
|
|
741
|
+
value: t.ref
|
|
742
|
+
});
|
|
743
|
+
return t !== "" && !e.some((e) => e.value === t) && e.push({
|
|
744
|
+
label: Me(t),
|
|
745
|
+
value: t
|
|
746
|
+
}), e;
|
|
747
|
+
})();
|
|
748
|
+
function b(e) {
|
|
749
|
+
m(["font"], e.target.value, !0);
|
|
750
|
+
}
|
|
751
|
+
let [x, S] = V(String(r)), [w, T] = V(!1);
|
|
752
|
+
R(() => {
|
|
753
|
+
w || S(String(r));
|
|
754
|
+
}, [r, w]);
|
|
755
|
+
function E(e) {
|
|
756
|
+
return Math.max(Ae, Math.trunc(e));
|
|
757
|
+
}
|
|
758
|
+
function D(e) {
|
|
759
|
+
if (e.value.trim() === "") return null;
|
|
760
|
+
let t = Number(e.value);
|
|
761
|
+
return Number.isFinite(t) ? t : null;
|
|
762
|
+
}
|
|
763
|
+
function O(e) {
|
|
764
|
+
let t = e.target;
|
|
765
|
+
S(t.value);
|
|
766
|
+
let n = D(t);
|
|
767
|
+
n !== null && m(["fontSize"], E(n), !1);
|
|
768
|
+
}
|
|
769
|
+
function k(e) {
|
|
770
|
+
let t = e.target, n = D(t);
|
|
771
|
+
if (n === null) {
|
|
772
|
+
S(String(r));
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
let i = E(n);
|
|
776
|
+
S(String(i)), m(["fontSize"], i, !0);
|
|
777
|
+
}
|
|
778
|
+
function A(e) {
|
|
779
|
+
let t = E(r + e);
|
|
780
|
+
S(String(t)), m(["fontSize"], t, !1);
|
|
781
|
+
}
|
|
782
|
+
let M = /^#[0-9a-fA-F]{6}$/.test(i) ? i : "#000000";
|
|
783
|
+
function N(e) {
|
|
784
|
+
m(["fontColor"], e.target.value, !1);
|
|
785
|
+
}
|
|
786
|
+
function P(e) {
|
|
787
|
+
m(["fontColor"], e.target.value, !0);
|
|
788
|
+
}
|
|
789
|
+
let F = n.map((e) => ({
|
|
790
|
+
label: Oe[e].label,
|
|
791
|
+
icon: Oe[e].icon,
|
|
792
|
+
checked: e === a,
|
|
793
|
+
dataAttrs: { "data-align-h": e },
|
|
794
|
+
run: () => z("horizontal", e)
|
|
795
|
+
})), I = l.map((e) => ({
|
|
796
|
+
label: ke[e].label,
|
|
797
|
+
icon: ke[e].icon,
|
|
798
|
+
checked: e === o,
|
|
799
|
+
dataAttrs: { "data-align-v": e },
|
|
800
|
+
run: () => z("vertical", e)
|
|
801
|
+
}));
|
|
802
|
+
function z(e, t) {
|
|
803
|
+
t !== (e === "horizontal" ? a : o) && m(e === "horizontal" ? ["align", "horizontal"] : ["align", "vertical"], t, !0);
|
|
804
|
+
}
|
|
805
|
+
let B = L((e) => {
|
|
806
|
+
u?.(e);
|
|
807
|
+
}, [u]);
|
|
808
|
+
return /* @__PURE__ */ W("div", {
|
|
809
|
+
ref: B,
|
|
810
|
+
className: "cn-edit-toolbar",
|
|
811
|
+
role: "toolbar",
|
|
812
|
+
"aria-label": "文本编辑",
|
|
813
|
+
"data-edit-toolbar": !0,
|
|
814
|
+
style: c,
|
|
815
|
+
onPointerDown: (e) => e.preventDefault(),
|
|
816
|
+
children: [
|
|
817
|
+
/* @__PURE__ */ U("span", {
|
|
818
|
+
className: "cn-edit-toolbar__segment",
|
|
819
|
+
role: "group",
|
|
820
|
+
"aria-label": "内容类型",
|
|
821
|
+
"data-content-pill": !0,
|
|
822
|
+
children: /* @__PURE__ */ U(C, {
|
|
823
|
+
label: "内容类型",
|
|
824
|
+
items: _,
|
|
825
|
+
trigger: ({ open: e, toggle: t, triggerRef: n, onKeydown: r }) => /* @__PURE__ */ U(g, {
|
|
826
|
+
label: "内容类型",
|
|
827
|
+
children: /* @__PURE__ */ W("button", {
|
|
828
|
+
ref: n,
|
|
829
|
+
type: "button",
|
|
830
|
+
className: "cn-edit-toolbar__item cn-edit-toolbar__menu-trigger",
|
|
831
|
+
"aria-haspopup": "menu",
|
|
832
|
+
"aria-expanded": e,
|
|
833
|
+
onPointerDown: (e) => e.stopPropagation(),
|
|
834
|
+
onClick: t,
|
|
835
|
+
onKeyDown: r,
|
|
836
|
+
children: [h, /* @__PURE__ */ U("span", {
|
|
837
|
+
className: "cn-edit-toolbar__caret",
|
|
838
|
+
"aria-hidden": "true",
|
|
839
|
+
children: "▾"
|
|
840
|
+
})]
|
|
841
|
+
})
|
|
842
|
+
})
|
|
843
|
+
})
|
|
844
|
+
}),
|
|
845
|
+
/* @__PURE__ */ U("span", {
|
|
846
|
+
className: "cn-edit-toolbar__segment",
|
|
847
|
+
children: /* @__PURE__ */ U(g, {
|
|
848
|
+
label: "字体",
|
|
849
|
+
children: /* @__PURE__ */ U("select", {
|
|
850
|
+
className: "cn-edit-toolbar__font",
|
|
851
|
+
"data-toolbar-font": !0,
|
|
852
|
+
value: t,
|
|
853
|
+
"aria-label": "字体",
|
|
854
|
+
onPointerDown: (e) => e.stopPropagation(),
|
|
855
|
+
onChange: b,
|
|
856
|
+
children: y.map((e) => /* @__PURE__ */ U("option", {
|
|
857
|
+
value: e.value,
|
|
858
|
+
children: e.label
|
|
859
|
+
}, e.value))
|
|
860
|
+
})
|
|
861
|
+
})
|
|
862
|
+
}),
|
|
863
|
+
/* @__PURE__ */ W("span", {
|
|
864
|
+
className: "cn-edit-toolbar__segment",
|
|
865
|
+
role: "group",
|
|
866
|
+
"aria-label": "字号",
|
|
867
|
+
children: [
|
|
868
|
+
/* @__PURE__ */ U(g, {
|
|
869
|
+
label: "字号减 1",
|
|
870
|
+
children: /* @__PURE__ */ U("button", {
|
|
871
|
+
type: "button",
|
|
872
|
+
className: "cn-edit-toolbar__mini",
|
|
873
|
+
"data-toolbar-font-size-dec": !0,
|
|
874
|
+
"aria-label": "字号减 1",
|
|
875
|
+
onClick: () => A(-1),
|
|
876
|
+
children: /* @__PURE__ */ U(p, {
|
|
877
|
+
icon: _e,
|
|
878
|
+
size: 11
|
|
879
|
+
})
|
|
880
|
+
})
|
|
881
|
+
}),
|
|
882
|
+
/* @__PURE__ */ U(g, {
|
|
883
|
+
label: "字号(场景像素)",
|
|
884
|
+
children: /* @__PURE__ */ U("input", {
|
|
885
|
+
className: "cn-edit-toolbar__size",
|
|
886
|
+
"data-toolbar-font-size": !0,
|
|
887
|
+
type: "number",
|
|
888
|
+
min: Ae,
|
|
889
|
+
step: 1,
|
|
890
|
+
value: x,
|
|
891
|
+
"aria-label": "字号(场景像素)",
|
|
892
|
+
onPointerDown: (e) => e.stopPropagation(),
|
|
893
|
+
onChange: O,
|
|
894
|
+
onBlur: (e) => {
|
|
895
|
+
k(e), T(!1);
|
|
896
|
+
},
|
|
897
|
+
onFocus: () => T(!0)
|
|
898
|
+
})
|
|
899
|
+
}),
|
|
900
|
+
/* @__PURE__ */ U(g, {
|
|
901
|
+
label: "字号加 1",
|
|
902
|
+
children: /* @__PURE__ */ U("button", {
|
|
903
|
+
type: "button",
|
|
904
|
+
className: "cn-edit-toolbar__mini",
|
|
905
|
+
"data-toolbar-font-size-inc": !0,
|
|
906
|
+
"aria-label": "字号加 1",
|
|
907
|
+
onClick: () => A(1),
|
|
908
|
+
children: /* @__PURE__ */ U(p, {
|
|
909
|
+
icon: ye,
|
|
910
|
+
size: 11
|
|
911
|
+
})
|
|
912
|
+
})
|
|
913
|
+
})
|
|
914
|
+
]
|
|
915
|
+
}),
|
|
916
|
+
/* @__PURE__ */ U("span", {
|
|
917
|
+
className: "cn-edit-toolbar__segment",
|
|
918
|
+
children: /* @__PURE__ */ U(g, {
|
|
919
|
+
label: "字色",
|
|
920
|
+
children: /* @__PURE__ */ U("input", {
|
|
921
|
+
className: "cn-edit-toolbar__color",
|
|
922
|
+
"data-toolbar-font-color": !0,
|
|
923
|
+
type: "color",
|
|
924
|
+
value: M,
|
|
925
|
+
"aria-label": "字色",
|
|
926
|
+
onPointerDown: (e) => e.stopPropagation(),
|
|
927
|
+
onChange: N,
|
|
928
|
+
onBlur: P
|
|
929
|
+
})
|
|
930
|
+
})
|
|
931
|
+
}),
|
|
932
|
+
/* @__PURE__ */ W("span", {
|
|
933
|
+
className: "cn-edit-toolbar__segment cn-edit-toolbar__align-group",
|
|
934
|
+
role: "group",
|
|
935
|
+
"aria-label": "对齐",
|
|
936
|
+
children: [/* @__PURE__ */ U(C, {
|
|
937
|
+
label: "水平对齐",
|
|
938
|
+
items: F,
|
|
939
|
+
trigger: ({ open: e, toggle: t, triggerRef: n, onKeydown: r }) => /* @__PURE__ */ U(g, {
|
|
940
|
+
label: "水平对齐",
|
|
941
|
+
children: /* @__PURE__ */ W("button", {
|
|
942
|
+
ref: n,
|
|
943
|
+
type: "button",
|
|
944
|
+
className: "cn-edit-toolbar__item cn-edit-toolbar__icon-item cn-edit-toolbar__menu-trigger",
|
|
945
|
+
"data-toolbar-align-horizontal": !0,
|
|
946
|
+
"aria-label": "水平对齐",
|
|
947
|
+
"aria-haspopup": "menu",
|
|
948
|
+
"aria-expanded": e,
|
|
949
|
+
onPointerDown: (e) => e.stopPropagation(),
|
|
950
|
+
onClick: t,
|
|
951
|
+
onKeyDown: r,
|
|
952
|
+
children: [/* @__PURE__ */ U(p, {
|
|
953
|
+
icon: Oe[a].icon,
|
|
954
|
+
size: 12
|
|
955
|
+
}), /* @__PURE__ */ U("span", {
|
|
956
|
+
className: "cn-edit-toolbar__caret",
|
|
957
|
+
"aria-hidden": "true",
|
|
958
|
+
children: "▾"
|
|
959
|
+
})]
|
|
960
|
+
})
|
|
961
|
+
})
|
|
962
|
+
}), /* @__PURE__ */ U(C, {
|
|
963
|
+
label: "垂直对齐",
|
|
964
|
+
items: I,
|
|
965
|
+
trigger: ({ open: e, toggle: t, triggerRef: n, onKeydown: r }) => /* @__PURE__ */ U(g, {
|
|
966
|
+
label: "垂直对齐",
|
|
967
|
+
children: /* @__PURE__ */ W("button", {
|
|
968
|
+
ref: n,
|
|
969
|
+
type: "button",
|
|
970
|
+
className: "cn-edit-toolbar__item cn-edit-toolbar__icon-item cn-edit-toolbar__menu-trigger",
|
|
971
|
+
"data-toolbar-align-vertical": !0,
|
|
972
|
+
"aria-label": "垂直对齐",
|
|
973
|
+
"aria-haspopup": "menu",
|
|
974
|
+
"aria-expanded": e,
|
|
975
|
+
onPointerDown: (e) => e.stopPropagation(),
|
|
976
|
+
onClick: t,
|
|
977
|
+
onKeyDown: r,
|
|
978
|
+
children: [/* @__PURE__ */ U(p, {
|
|
979
|
+
icon: ke[o].icon,
|
|
980
|
+
size: 12
|
|
981
|
+
}), /* @__PURE__ */ U("span", {
|
|
982
|
+
className: "cn-edit-toolbar__caret",
|
|
983
|
+
"aria-hidden": "true",
|
|
984
|
+
children: "▾"
|
|
985
|
+
})]
|
|
986
|
+
})
|
|
987
|
+
})
|
|
988
|
+
})]
|
|
989
|
+
}),
|
|
990
|
+
/* @__PURE__ */ U("span", {
|
|
991
|
+
className: "cn-edit-toolbar__segment",
|
|
992
|
+
children: /* @__PURE__ */ U(g, {
|
|
993
|
+
label: "自动换行",
|
|
994
|
+
children: /* @__PURE__ */ U("button", {
|
|
995
|
+
type: "button",
|
|
996
|
+
className: `cn-edit-toolbar__item cn-edit-toolbar__icon-item${s ? " cn-edit-toolbar__item--active" : ""}`,
|
|
997
|
+
"aria-pressed": s,
|
|
998
|
+
"data-toolbar-autowrap": !0,
|
|
999
|
+
"aria-label": "自动换行",
|
|
1000
|
+
onClick: () => m(["autowrap"], !s, !0),
|
|
1001
|
+
children: /* @__PURE__ */ U(p, {
|
|
1002
|
+
icon: xe,
|
|
1003
|
+
size: 12
|
|
1004
|
+
})
|
|
1005
|
+
})
|
|
1006
|
+
})
|
|
1007
|
+
})
|
|
1008
|
+
]
|
|
1009
|
+
});
|
|
1010
|
+
}
|
|
1011
|
+
function Me(e) {
|
|
1012
|
+
return e.startsWith("data:") ? "自定义字体(内联)" : e.split("/").pop() || e;
|
|
1013
|
+
}
|
|
1014
|
+
//#endregion
|
|
1015
|
+
//#region src/canvas/useDpr.ts
|
|
1016
|
+
function Ne(e) {
|
|
1017
|
+
let t = null, n = () => {
|
|
1018
|
+
t?.removeEventListener("change", n), e(window.devicePixelRatio || 1), t = window.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`), t.addEventListener("change", n);
|
|
1019
|
+
};
|
|
1020
|
+
return n(), () => t?.removeEventListener("change", n);
|
|
1021
|
+
}
|
|
1022
|
+
var Pe = null, Fe = /* @__PURE__ */ new Set(), Q = null;
|
|
1023
|
+
function Ie() {
|
|
1024
|
+
Q === null && (Q = Ne((e) => {
|
|
1025
|
+
if (Pe !== e) {
|
|
1026
|
+
Pe = e;
|
|
1027
|
+
for (let e of Fe) e();
|
|
1028
|
+
}
|
|
1029
|
+
}));
|
|
1030
|
+
}
|
|
1031
|
+
function Le(e) {
|
|
1032
|
+
return Ie(), Fe.add(e), () => {
|
|
1033
|
+
Fe.delete(e), Fe.size === 0 && Q !== null && (Q(), Q = null);
|
|
1034
|
+
};
|
|
1035
|
+
}
|
|
1036
|
+
function Re() {
|
|
1037
|
+
return H(Le, () => Pe ?? (window.devicePixelRatio || 1));
|
|
1038
|
+
}
|
|
1039
|
+
//#endregion
|
|
1040
|
+
//#region src/canvas/useTextEditing.ts
|
|
1041
|
+
var ze = /* @__PURE__ */ new Map();
|
|
1042
|
+
function Be(e, t) {
|
|
1043
|
+
let n = `${e}|${t}`, r = ze.get(n);
|
|
1044
|
+
if (r !== void 0) return r;
|
|
1045
|
+
let i = t * 1.2;
|
|
1046
|
+
try {
|
|
1047
|
+
let n = document.createElement("canvas").getContext("2d");
|
|
1048
|
+
if (n) {
|
|
1049
|
+
n.font = `${t}px ${re(e)}`;
|
|
1050
|
+
let r = n.measureText("字"), a = (r.fontBoundingBoxAscent ?? r.actualBoundingBoxAscent) + (r.fontBoundingBoxDescent ?? r.actualBoundingBoxDescent);
|
|
1051
|
+
a > 0 && (i = a);
|
|
1052
|
+
}
|
|
1053
|
+
} catch {}
|
|
1054
|
+
return ze.set(n, i), i;
|
|
1055
|
+
}
|
|
1056
|
+
function Ve(e) {
|
|
1057
|
+
let t = e.padding.top + e.verticalAnchorY, n = e.lineHeightPx, r = Be(e.font, e.fontSize), i;
|
|
1058
|
+
return i = e.verticalAlign === "center" ? t - n / 2 : e.verticalAlign === "bottom" ? t - (n + r) / 2 : t - (n - r) / 2, {
|
|
1059
|
+
paddingTop: `${Math.max(0, i)}px`,
|
|
1060
|
+
paddingRight: `${e.padding.right}px`,
|
|
1061
|
+
paddingBottom: `${e.padding.bottom}px`,
|
|
1062
|
+
paddingLeft: `${e.padding.left}px`
|
|
1063
|
+
};
|
|
1064
|
+
}
|
|
1065
|
+
function He(e, t, n) {
|
|
1066
|
+
let { x: r, y: i, zoom: a } = e;
|
|
1067
|
+
return {
|
|
1068
|
+
left: (t - r) * a,
|
|
1069
|
+
top: (n - i) * a,
|
|
1070
|
+
zoom: a
|
|
1071
|
+
};
|
|
1072
|
+
}
|
|
1073
|
+
function Ue(e, t) {
|
|
1074
|
+
if (!e) return null;
|
|
1075
|
+
let { left: n, top: r, zoom: i } = He(t, e.box.x, e.box.y);
|
|
1076
|
+
return {
|
|
1077
|
+
transform: `translate(${n}px, ${r}px) scale(${i})`,
|
|
1078
|
+
transformOrigin: "0 0",
|
|
1079
|
+
width: `${e.box.width}px`,
|
|
1080
|
+
height: `${e.box.height}px`,
|
|
1081
|
+
color: e.fontColor,
|
|
1082
|
+
fontFamily: re(e.font),
|
|
1083
|
+
fontSize: `${e.fontSize}px`,
|
|
1084
|
+
lineHeight: `${e.lineHeightPx}px`,
|
|
1085
|
+
...Ve(e),
|
|
1086
|
+
textAlign: e.horizontalAlign,
|
|
1087
|
+
whiteSpace: e.autowrap ? "pre-wrap" : "pre"
|
|
1088
|
+
};
|
|
1089
|
+
}
|
|
1090
|
+
var $ = 4;
|
|
1091
|
+
function We(e, t, n, r) {
|
|
1092
|
+
if (!e) return null;
|
|
1093
|
+
let { width: i, height: a } = n, o = He(t, e.box.x + e.box.width / 2, e.box.y), s = He(t, e.box.x + e.box.width / 2, e.box.y + e.box.height), c = o.top - $ - a < 0, l = c ? s.top + $ : o.top - $ - a;
|
|
1094
|
+
return {
|
|
1095
|
+
left: Math.min(Math.max(o.left - i / 2, 0), Math.max(0, r.width - i)),
|
|
1096
|
+
top: l,
|
|
1097
|
+
height: a,
|
|
1098
|
+
flipped: c
|
|
1099
|
+
};
|
|
1100
|
+
}
|
|
1101
|
+
function Ge(e) {
|
|
1102
|
+
return e ? {
|
|
1103
|
+
left: `${e.left}px`,
|
|
1104
|
+
top: `${e.top}px`
|
|
1105
|
+
} : null;
|
|
1106
|
+
}
|
|
1107
|
+
function Ke(e) {
|
|
1108
|
+
return e ? e.flipped ? {
|
|
1109
|
+
left: `${e.left}px`,
|
|
1110
|
+
top: `${e.top + e.height + $}px`
|
|
1111
|
+
} : {
|
|
1112
|
+
left: `${e.left}px`,
|
|
1113
|
+
top: `${e.top - $}px`,
|
|
1114
|
+
transform: "translateY(-100%)"
|
|
1115
|
+
} : null;
|
|
1116
|
+
}
|
|
1117
|
+
function qe(e, t) {
|
|
1118
|
+
let n = B(t);
|
|
1119
|
+
n.current = t;
|
|
1120
|
+
let r = L((t) => e.subscribe((e) => {
|
|
1121
|
+
(e.scope === "doc" || e.scope === "ui" && e.branch === "editing") && t();
|
|
1122
|
+
}), [e]), i = H(r, () => e.store.ui.editing), a = B(0), o = L((t) => e.subscribe((e) => {
|
|
1123
|
+
e.scope === "doc" && (a.current += 1, t());
|
|
1124
|
+
}), [e]);
|
|
1125
|
+
H(o, () => a.current);
|
|
1126
|
+
let s = i?.path ?? null, c = Re(), l = ee(F(e), c), u = i ? e.textEditLayout(i.path) : null, [d, f] = V({
|
|
1127
|
+
width: 0,
|
|
1128
|
+
height: 0
|
|
1129
|
+
}), [p, m] = V({
|
|
1130
|
+
width: 0,
|
|
1131
|
+
height: 0
|
|
1132
|
+
});
|
|
1133
|
+
R(() => {
|
|
1134
|
+
if (s === null) return;
|
|
1135
|
+
let t = e.getSurfaceSize();
|
|
1136
|
+
f((e) => e.width === t.width && e.height === t.height ? e : {
|
|
1137
|
+
width: t.width,
|
|
1138
|
+
height: t.height
|
|
1139
|
+
});
|
|
1140
|
+
}, [e, s]);
|
|
1141
|
+
let h = B(null), g = B(null);
|
|
1142
|
+
R(() => {
|
|
1143
|
+
let e = n.current.getToolbar?.() ?? null;
|
|
1144
|
+
if (e === h.current) return;
|
|
1145
|
+
if (h.current = e, g.current?.disconnect(), g.current = null, e === null) {
|
|
1146
|
+
m((e) => e.width === 0 && e.height === 0 ? e : {
|
|
1147
|
+
width: 0,
|
|
1148
|
+
height: 0
|
|
1149
|
+
});
|
|
1150
|
+
return;
|
|
1151
|
+
}
|
|
1152
|
+
let t = () => m({
|
|
1153
|
+
width: e.offsetWidth,
|
|
1154
|
+
height: e.offsetHeight
|
|
1155
|
+
});
|
|
1156
|
+
if (t(), typeof ResizeObserver == "function") {
|
|
1157
|
+
let n = new ResizeObserver(t);
|
|
1158
|
+
n.observe(e), g.current = n;
|
|
1159
|
+
}
|
|
1160
|
+
}), R(() => () => {
|
|
1161
|
+
g.current?.disconnect(), g.current = null;
|
|
1162
|
+
}, []), R(() => {
|
|
1163
|
+
let e = n.current.getHost();
|
|
1164
|
+
if (e === null || typeof ResizeObserver != "function") return;
|
|
1165
|
+
let t = new ResizeObserver(() => {
|
|
1166
|
+
f({
|
|
1167
|
+
width: e.clientWidth,
|
|
1168
|
+
height: e.clientHeight
|
|
1169
|
+
});
|
|
1170
|
+
});
|
|
1171
|
+
return t.observe(e), () => t.disconnect();
|
|
1172
|
+
}, []);
|
|
1173
|
+
let _ = We(u, l, p, d), v = B(!1), y = B(null), b = B(!1), x = B(!1), S = L(() => {
|
|
1174
|
+
y.current !== null && clearTimeout(y.current), y.current = null;
|
|
1175
|
+
}, []), C = L(() => {
|
|
1176
|
+
e.commitTextEdit(n.current.getTextarea()?.value ?? "");
|
|
1177
|
+
}, [e]), w = L(() => {
|
|
1178
|
+
if (S(), v.current) {
|
|
1179
|
+
x.current = !0;
|
|
1180
|
+
return;
|
|
1181
|
+
}
|
|
1182
|
+
C();
|
|
1183
|
+
}, [S, C]), T = L((t) => {
|
|
1184
|
+
v.current = t, !t && x.current && (x.current = !1, e.store.ui.editing !== null && C());
|
|
1185
|
+
}, [C, e]), E = L((e) => {
|
|
1186
|
+
if (!(e instanceof Node)) return !1;
|
|
1187
|
+
let t = n.current.getToolbar?.() ?? null;
|
|
1188
|
+
if (t !== null && t.contains(e)) return !0;
|
|
1189
|
+
let r = n.current.getTextarea();
|
|
1190
|
+
return r !== null && r.contains(e);
|
|
1191
|
+
}, []), D = L(() => {
|
|
1192
|
+
if (e.store.ui.editing !== null) {
|
|
1193
|
+
if (S(), b.current) {
|
|
1194
|
+
b.current = !1;
|
|
1195
|
+
return;
|
|
1196
|
+
}
|
|
1197
|
+
y.current = setTimeout(() => {
|
|
1198
|
+
y.current = null;
|
|
1199
|
+
let e = n.current.getTextarea();
|
|
1200
|
+
if (e === null || document.activeElement !== e) {
|
|
1201
|
+
if (v.current) {
|
|
1202
|
+
x.current = !0;
|
|
1203
|
+
return;
|
|
1204
|
+
}
|
|
1205
|
+
C();
|
|
1206
|
+
}
|
|
1207
|
+
}, 0);
|
|
1208
|
+
}
|
|
1209
|
+
}, [
|
|
1210
|
+
S,
|
|
1211
|
+
C,
|
|
1212
|
+
e
|
|
1213
|
+
]);
|
|
1214
|
+
R(() => {
|
|
1215
|
+
let t = (t) => {
|
|
1216
|
+
if (e.store.ui.editing === null) return;
|
|
1217
|
+
let r = n.current.getToolbar?.() ?? null;
|
|
1218
|
+
if (r !== null && t.target instanceof Node && r.contains(t.target)) {
|
|
1219
|
+
b.current = !0;
|
|
1220
|
+
return;
|
|
1221
|
+
}
|
|
1222
|
+
if (E(t.target)) return;
|
|
1223
|
+
let i = n.current.getHost();
|
|
1224
|
+
i !== null && i.contains(t.target) || (b.current = !0);
|
|
1225
|
+
}, r = () => {
|
|
1226
|
+
b.current = !1;
|
|
1227
|
+
};
|
|
1228
|
+
return window.addEventListener("pointerdown", t, !0), window.addEventListener("pointerup", r, !0), () => {
|
|
1229
|
+
window.removeEventListener("pointerdown", t, !0), window.removeEventListener("pointerup", r, !0), S();
|
|
1230
|
+
};
|
|
1231
|
+
}, [
|
|
1232
|
+
e,
|
|
1233
|
+
E,
|
|
1234
|
+
S
|
|
1235
|
+
]);
|
|
1236
|
+
let O = L((t, n) => {
|
|
1237
|
+
let r = e.hitTest(t, n);
|
|
1238
|
+
return r !== null && e.beginTextEdit(r);
|
|
1239
|
+
}, [e]), k = L((t) => e.beginTextEdit(t), [e]), A = L((t) => {
|
|
1240
|
+
let n = e.store.ui.editing;
|
|
1241
|
+
n && n.expression !== t && e.store.setEditing({
|
|
1242
|
+
...n,
|
|
1243
|
+
expression: t
|
|
1244
|
+
});
|
|
1245
|
+
}, [e]), j = L((t, n, r) => {
|
|
1246
|
+
let i = e.store.ui.editing?.path;
|
|
1247
|
+
if (!i) return;
|
|
1248
|
+
let a = N(i, t);
|
|
1249
|
+
e.updateSpec(i, t, n, { mergeKey: a }), r && e.store.closeMerge(a);
|
|
1250
|
+
}, [e]);
|
|
1251
|
+
return {
|
|
1252
|
+
editing: s,
|
|
1253
|
+
layout: u,
|
|
1254
|
+
draftSeq: i?.draftSeq,
|
|
1255
|
+
style: Ue(u, l),
|
|
1256
|
+
toolbarStyle: Ge(_),
|
|
1257
|
+
toolbarTagStyle: Ke(_),
|
|
1258
|
+
scale: l.zoom,
|
|
1259
|
+
composing: v.current,
|
|
1260
|
+
setComposing: T,
|
|
1261
|
+
beginAt: O,
|
|
1262
|
+
beginTextEdit: k,
|
|
1263
|
+
commitNow: w,
|
|
1264
|
+
setExpressionMode: A,
|
|
1265
|
+
updateStyleField: j,
|
|
1266
|
+
armBlurCommit: D,
|
|
1267
|
+
ownsEventTarget: E
|
|
1268
|
+
};
|
|
1269
|
+
}
|
|
1270
|
+
//#endregion
|
|
1271
|
+
//#region src/canvas/TextEditingOverlay.tsx
|
|
1272
|
+
function Je({ editor: e, ref: t }) {
|
|
1273
|
+
let n = B(null), r = B(null), i = B(null), a = B(null), o = qe(e, {
|
|
1274
|
+
getTextarea: () => r.current,
|
|
1275
|
+
getHost: () => n.current?.parentElement ?? null,
|
|
1276
|
+
getToolbar: () => i.current
|
|
1277
|
+
}), s = B(o);
|
|
1278
|
+
s.current = o;
|
|
1279
|
+
let c = o.layout?.expressionMode === !0, { diagnostics: l, refresh: u, targetRef: d } = M({ enabled: () => c }), f = c ? T(l) : "", p = E({
|
|
1280
|
+
enabled: () => c,
|
|
1281
|
+
resolve: (t) => {
|
|
1282
|
+
let n = e.store.ui.dataSourceSchema, r = s.current.editing;
|
|
1283
|
+
if (n === null || r === null) return null;
|
|
1284
|
+
let i = D(n, O(n, e.store.doc, r));
|
|
1285
|
+
return i === null ? null : i(t);
|
|
1286
|
+
},
|
|
1287
|
+
popupEl: () => a.current,
|
|
1288
|
+
scale: () => s.current.scale
|
|
1289
|
+
}), m = B(p.popup);
|
|
1290
|
+
m.current = p.popup;
|
|
1291
|
+
let h = L(() => s.current.setComposing(!0), []), g = L(() => s.current.setComposing(!1), []), _ = L((e) => {
|
|
1292
|
+
e.isComposing || e.keyCode === 229 || (e.key === "Escape" || e.key === "Enter" && (e.ctrlKey || e.metaKey)) && (e.key === "Escape" && m.current.open || (e.preventDefault(), s.current.commitNow()));
|
|
1293
|
+
}, []), v = B(null), y = L((e) => {
|
|
1294
|
+
let t = v.current;
|
|
1295
|
+
t !== e && (t !== null && (t.removeEventListener("keydown", _), t.removeEventListener("compositionstart", h), t.removeEventListener("compositionend", g)), v.current = e, r.current = e, e !== null && (e.addEventListener("keydown", _), e.addEventListener("compositionstart", h), e.addEventListener("compositionend", g)), d(e), p.targetRef(e));
|
|
1296
|
+
}, [
|
|
1297
|
+
_,
|
|
1298
|
+
h,
|
|
1299
|
+
g,
|
|
1300
|
+
d,
|
|
1301
|
+
p.targetRef
|
|
1302
|
+
]), b = o.editing?.join("") ?? null;
|
|
1303
|
+
R(() => {
|
|
1304
|
+
if (b === null) return;
|
|
1305
|
+
let e = r.current;
|
|
1306
|
+
e !== null && (e.focus({ preventScroll: !0 }), e.select(), u());
|
|
1307
|
+
}, [b, u]);
|
|
1308
|
+
let x = B(void 0);
|
|
1309
|
+
R(() => {
|
|
1310
|
+
let e = o.draftSeq, t = x.current;
|
|
1311
|
+
if (x.current = e, e === void 0 || e === t) return;
|
|
1312
|
+
let n = r.current, i = o.layout;
|
|
1313
|
+
n !== null && i !== null && (n.value = i.text, u());
|
|
1314
|
+
}, [
|
|
1315
|
+
o.draftSeq,
|
|
1316
|
+
o.layout,
|
|
1317
|
+
u
|
|
1318
|
+
]), z(t, () => ({
|
|
1319
|
+
beginAt: (e, t) => s.current.beginAt(e, t),
|
|
1320
|
+
beginTextEdit: (e) => s.current.beginTextEdit(e),
|
|
1321
|
+
commitEditing: () => s.current.commitNow(),
|
|
1322
|
+
isEditing: () => s.current.editing !== null,
|
|
1323
|
+
ownsEventTarget: (e) => s.current.ownsEventTarget(e)
|
|
1324
|
+
}));
|
|
1325
|
+
let S = o.layout;
|
|
1326
|
+
return /* @__PURE__ */ W("div", {
|
|
1327
|
+
ref: n,
|
|
1328
|
+
className: "cn-text-overlay",
|
|
1329
|
+
children: [
|
|
1330
|
+
o.editing !== null && o.style !== null && S !== null ? /* @__PURE__ */ U("textarea", {
|
|
1331
|
+
ref: y,
|
|
1332
|
+
className: "cn-text-overlay__textarea",
|
|
1333
|
+
style: o.style,
|
|
1334
|
+
defaultValue: S.text,
|
|
1335
|
+
wrap: o.style.whiteSpace === "pre" ? "off" : "soft",
|
|
1336
|
+
spellCheck: !1,
|
|
1337
|
+
autoComplete: "off",
|
|
1338
|
+
onBlur: () => s.current.armBlurCommit()
|
|
1339
|
+
}, o.editing.join("")) : null,
|
|
1340
|
+
o.editing !== null && o.toolbarStyle !== null && S !== null ? /* @__PURE__ */ U(je, {
|
|
1341
|
+
style: o.toolbarStyle,
|
|
1342
|
+
mode: c ? "expression" : "static",
|
|
1343
|
+
font: S.font,
|
|
1344
|
+
fontSize: S.fontSize,
|
|
1345
|
+
fontColor: S.fontColor,
|
|
1346
|
+
horizontalAlign: S.horizontalAlign,
|
|
1347
|
+
verticalAlign: S.verticalAlign,
|
|
1348
|
+
autowrap: S.autowrap,
|
|
1349
|
+
rootRef: (e) => {
|
|
1350
|
+
i.current = e;
|
|
1351
|
+
},
|
|
1352
|
+
onModeChange: (e) => s.current.setExpressionMode(e === "expression"),
|
|
1353
|
+
onStyleWrite: (e) => s.current.updateStyleField(e.key, e.value, e.final)
|
|
1354
|
+
}) : null,
|
|
1355
|
+
o.editing !== null && f !== "" ? /* @__PURE__ */ U("span", {
|
|
1356
|
+
className: "cn-text-overlay__diagnostic",
|
|
1357
|
+
style: o.toolbarTagStyle ?? void 0,
|
|
1358
|
+
children: f
|
|
1359
|
+
}) : null,
|
|
1360
|
+
/* @__PURE__ */ U(A, {
|
|
1361
|
+
state: p.popup,
|
|
1362
|
+
onSelect: (e) => p.accept(e),
|
|
1363
|
+
rootRef: (e) => {
|
|
1364
|
+
a.current = e;
|
|
1365
|
+
}
|
|
1366
|
+
})
|
|
1367
|
+
]
|
|
1368
|
+
});
|
|
1369
|
+
}
|
|
1370
|
+
//#endregion
|
|
1371
|
+
//#region src/canvas/CanvasSurface.tsx
|
|
1372
|
+
var Ye = 16;
|
|
1373
|
+
function Xe({ editor: e, onReady: t }) {
|
|
1374
|
+
let n = B(null), r = B(null), i = B(null), a = B(null), o = B(null), s = B(null), c = B(!1), [l, u] = V(!1), [d, f] = V(!1), [p, m] = V(null), [h, g] = V(null), [v, y] = V(e.store.ui.armedCreate), [S, C] = V(!1), [w, T] = V(!1), E = _(), D = B(t);
|
|
1375
|
+
R(() => {
|
|
1376
|
+
D.current = t;
|
|
1377
|
+
}), R(() => {
|
|
1378
|
+
let t = n.current, l = r.current, d = i.current;
|
|
1379
|
+
if (!t || !l || !d) return;
|
|
1380
|
+
let p = [], h = () => {
|
|
1381
|
+
let n = window.devicePixelRatio, r = Math.max(1, Math.round(t.clientWidth * n)), i = Math.max(1, Math.round(t.clientHeight * n));
|
|
1382
|
+
for (let e of [l, d]) e.width !== r && (e.width = r), e.height !== i && (e.height = i);
|
|
1383
|
+
e.flushPendingFrames();
|
|
1384
|
+
}, _ = () => {
|
|
1385
|
+
e.setSurfaceSize(t.clientWidth, t.clientHeight), h();
|
|
1386
|
+
};
|
|
1387
|
+
e.setDevicePixelRatio(window.devicePixelRatio), _();
|
|
1388
|
+
let v = e.subscribe((t) => {
|
|
1389
|
+
(t.scope === "doc" || t.scope === "ui" && t.branch === "armedCreate") && y(e.store.ui.armedCreate);
|
|
1390
|
+
});
|
|
1391
|
+
p.push(v);
|
|
1392
|
+
let S = new ResizeObserver(_);
|
|
1393
|
+
S.observe(t), p.push(() => S.disconnect());
|
|
1394
|
+
let w = Ne(() => {
|
|
1395
|
+
e.setDevicePixelRatio(window.devicePixelRatio), h();
|
|
1396
|
+
});
|
|
1397
|
+
p.push(w);
|
|
1398
|
+
let O = (e) => {
|
|
1399
|
+
let n = t.getBoundingClientRect();
|
|
1400
|
+
return {
|
|
1401
|
+
x: e.clientX - n.left,
|
|
1402
|
+
y: e.clientY - n.top
|
|
1403
|
+
};
|
|
1404
|
+
}, A = (e) => e.deltaMode === 1 ? 16 : e.deltaMode === 2 ? 100 : 1, j = (t) => {
|
|
1405
|
+
t.preventDefault();
|
|
1406
|
+
let n = A(t), r = O(t), i = ne(t);
|
|
1407
|
+
i === "zoom" ? e.zoomByWheel(r.x, r.y, t.deltaY * n) : i === "pan-x" ? e.panBy(-(t.deltaY || t.deltaX) * n, 0) : e.panBy(-t.deltaX * n, -t.deltaY * n);
|
|
1408
|
+
};
|
|
1409
|
+
t.addEventListener("wheel", j, { passive: !1 }), p.push(() => t.removeEventListener("wheel", j));
|
|
1410
|
+
let M = null, N = {
|
|
1411
|
+
x: 0,
|
|
1412
|
+
y: 0
|
|
1413
|
+
}, P = (t) => {
|
|
1414
|
+
let n = O(t);
|
|
1415
|
+
return e.toScenePoint(n.x, n.y);
|
|
1416
|
+
}, F = (n) => {
|
|
1417
|
+
if (o.current?.close(), M !== null) return;
|
|
1418
|
+
if (n.button === 1 || n.button === 0 && c.current) {
|
|
1419
|
+
n.preventDefault(), M = {
|
|
1420
|
+
id: n.pointerId,
|
|
1421
|
+
mode: "pan"
|
|
1422
|
+
}, N = {
|
|
1423
|
+
x: n.clientX,
|
|
1424
|
+
y: n.clientY
|
|
1425
|
+
}, f(!0), t.setPointerCapture(n.pointerId);
|
|
1426
|
+
return;
|
|
1427
|
+
}
|
|
1428
|
+
if (n.button !== 0) return;
|
|
1429
|
+
if (a.current?.isEditing()) {
|
|
1430
|
+
if (a.current.ownsEventTarget(n.target)) return;
|
|
1431
|
+
a.current.commitEditing();
|
|
1432
|
+
}
|
|
1433
|
+
n.preventDefault();
|
|
1434
|
+
let r = P(n);
|
|
1435
|
+
if (e.beginLayerCreate(r.x, r.y)) {
|
|
1436
|
+
M = {
|
|
1437
|
+
id: n.pointerId,
|
|
1438
|
+
mode: "create"
|
|
1439
|
+
}, C(!0), m(null), t.setPointerCapture(n.pointerId);
|
|
1440
|
+
return;
|
|
1441
|
+
}
|
|
1442
|
+
let i = e.resizeHandleAt(r.x, r.y), s = e.store.ui.selection;
|
|
1443
|
+
if (i !== null && s !== null && e.beginResize(s, i, r.x, r.y)) {
|
|
1444
|
+
M = {
|
|
1445
|
+
id: n.pointerId,
|
|
1446
|
+
mode: "resize"
|
|
1447
|
+
}, g(i), m(null), t.setPointerCapture(n.pointerId);
|
|
1448
|
+
return;
|
|
1449
|
+
}
|
|
1450
|
+
let l = P(n), u = e.selectAt(l.x, l.y);
|
|
1451
|
+
if (u && e.beginDrag(u, l.x, l.y, { copy: n.altKey && e.canCopyLayerAt(u) })) {
|
|
1452
|
+
M = {
|
|
1453
|
+
id: n.pointerId,
|
|
1454
|
+
mode: "drag"
|
|
1455
|
+
}, t.setPointerCapture(n.pointerId);
|
|
1456
|
+
return;
|
|
1457
|
+
}
|
|
1458
|
+
u === null && (M = {
|
|
1459
|
+
id: n.pointerId,
|
|
1460
|
+
mode: "pan"
|
|
1461
|
+
}, N = {
|
|
1462
|
+
x: n.clientX,
|
|
1463
|
+
y: n.clientY
|
|
1464
|
+
}, f(!0), t.setPointerCapture(n.pointerId));
|
|
1465
|
+
}, I = (t) => {
|
|
1466
|
+
if (M !== null) {
|
|
1467
|
+
if (t.pointerId !== M.id) return;
|
|
1468
|
+
if (M.mode === "pan") e.panBy(t.clientX - N.x, t.clientY - N.y), N = {
|
|
1469
|
+
x: t.clientX,
|
|
1470
|
+
y: t.clientY
|
|
1471
|
+
};
|
|
1472
|
+
else if (M.mode === "resize") {
|
|
1473
|
+
let n = P(t);
|
|
1474
|
+
e.resizeTo(n.x, n.y, t.shiftKey);
|
|
1475
|
+
} else if (M.mode === "create") {
|
|
1476
|
+
let n = P(t);
|
|
1477
|
+
e.createTo(n.x, n.y, t.shiftKey);
|
|
1478
|
+
} else {
|
|
1479
|
+
let n = P(t);
|
|
1480
|
+
e.dragTo(n.x, n.y);
|
|
1481
|
+
}
|
|
1482
|
+
return;
|
|
1483
|
+
}
|
|
1484
|
+
let n = P(t), r = e.resizeHandleAt(n.x, n.y);
|
|
1485
|
+
if (m(r), r !== null) {
|
|
1486
|
+
e.setHovered(null);
|
|
1487
|
+
return;
|
|
1488
|
+
}
|
|
1489
|
+
e.hoverAt(n.x, n.y);
|
|
1490
|
+
}, L = (n) => {
|
|
1491
|
+
if (M !== null && n.pointerId === M.id) {
|
|
1492
|
+
if (M.mode === "drag") e.endDrag();
|
|
1493
|
+
else if (M.mode === "resize") e.endResize(), g(null);
|
|
1494
|
+
else if (M.mode === "create") {
|
|
1495
|
+
C(!1);
|
|
1496
|
+
let t = e.endCreate();
|
|
1497
|
+
t !== null && a.current?.beginTextEdit(t);
|
|
1498
|
+
} else f(!1);
|
|
1499
|
+
M = null, t.hasPointerCapture(n.pointerId) && t.releasePointerCapture(n.pointerId);
|
|
1500
|
+
}
|
|
1501
|
+
}, R = (e) => {
|
|
1502
|
+
e.button === 1 && e.preventDefault();
|
|
1503
|
+
}, z = () => {
|
|
1504
|
+
M === null && (e.setHovered(null), m(null));
|
|
1505
|
+
};
|
|
1506
|
+
t.addEventListener("pointerdown", F), t.addEventListener("pointermove", I), t.addEventListener("pointerup", L), t.addEventListener("pointercancel", L), t.addEventListener("pointerleave", z), t.addEventListener("mousedown", R);
|
|
1507
|
+
let B = (t) => {
|
|
1508
|
+
let n = O(t), r = e.toScenePoint(n.x, n.y);
|
|
1509
|
+
a.current?.beginAt(r.x, r.y);
|
|
1510
|
+
};
|
|
1511
|
+
t.addEventListener("dblclick", B), p.push(() => t.removeEventListener("dblclick", B)), p.push(() => {
|
|
1512
|
+
t.removeEventListener("pointerdown", F), t.removeEventListener("pointermove", I), t.removeEventListener("pointerup", L), t.removeEventListener("pointercancel", L), t.removeEventListener("pointerleave", z), t.removeEventListener("mousedown", R);
|
|
1513
|
+
});
|
|
1514
|
+
let V = (t) => {
|
|
1515
|
+
if (a.current?.isEditing()) {
|
|
1516
|
+
if (a.current.ownsEventTarget(t.target)) return;
|
|
1517
|
+
a.current.commitEditing();
|
|
1518
|
+
}
|
|
1519
|
+
t.preventDefault();
|
|
1520
|
+
let n = O(t), r = e.toScenePoint(n.x, n.y), i = e.hitTest(r.x, r.y) ?? e.baseImageAt(r.x, r.y);
|
|
1521
|
+
if (e.setSelection(i), i === null) {
|
|
1522
|
+
o.current?.close();
|
|
1523
|
+
return;
|
|
1524
|
+
}
|
|
1525
|
+
o.current?.openAt(n.x, n.y);
|
|
1526
|
+
};
|
|
1527
|
+
t.addEventListener("contextmenu", V), p.push(() => t.removeEventListener("contextmenu", V));
|
|
1528
|
+
let H = (e) => {
|
|
1529
|
+
e.code !== "Space" || e.repeat || x(e.target) || (e.preventDefault(), c.current = !0, u(!0));
|
|
1530
|
+
}, U = (e) => {
|
|
1531
|
+
e.code === "Space" && (c.current = !1, u(!1));
|
|
1532
|
+
}, W = (t) => {
|
|
1533
|
+
if (!(t.key !== "Escape" || b(t.target))) {
|
|
1534
|
+
if (e.store.ui.armedCreate !== null || e.store.ui.create !== null) {
|
|
1535
|
+
e.cancelCreate();
|
|
1536
|
+
return;
|
|
1537
|
+
}
|
|
1538
|
+
o.current?.close(), s.current?.close(), e.escapeSelection();
|
|
1539
|
+
}
|
|
1540
|
+
};
|
|
1541
|
+
window.addEventListener("keydown", H), window.addEventListener("keyup", U), window.addEventListener("keydown", W), p.push(() => {
|
|
1542
|
+
window.removeEventListener("keydown", H), window.removeEventListener("keyup", U), window.removeEventListener("keydown", W);
|
|
1543
|
+
});
|
|
1544
|
+
let ee = (e) => {
|
|
1545
|
+
let t = e.dataTransfer?.items;
|
|
1546
|
+
if (!t) return !1;
|
|
1547
|
+
for (let e = 0; e < t.length; e += 1) {
|
|
1548
|
+
let n = t[e];
|
|
1549
|
+
if (n !== void 0 && n.kind === "file" && n.type.startsWith("image/")) return !0;
|
|
1550
|
+
}
|
|
1551
|
+
return !1;
|
|
1552
|
+
}, te = (e) => {
|
|
1553
|
+
ee(e) && (e.preventDefault(), e.dataTransfer && (e.dataTransfer.dropEffect = "copy"), T(!0));
|
|
1554
|
+
}, G = (e) => {
|
|
1555
|
+
e.relatedTarget !== null && t.contains(e.relatedTarget) || T(!1);
|
|
1556
|
+
}, K = (t) => {
|
|
1557
|
+
t.preventDefault(), T(!1);
|
|
1558
|
+
let n = [], r = t.dataTransfer?.files;
|
|
1559
|
+
for (let e = 0; r !== void 0 && e < r.length; e += 1) {
|
|
1560
|
+
let t = r[e];
|
|
1561
|
+
t !== void 0 && t.type.startsWith("image/") && n.push(t);
|
|
1562
|
+
}
|
|
1563
|
+
if (n.length !== 0) {
|
|
1564
|
+
if (!e.canUpload) {
|
|
1565
|
+
E.show("上传不可用:未接入上传实现,图片未添加");
|
|
1566
|
+
return;
|
|
1567
|
+
}
|
|
1568
|
+
a.current?.isEditing() && a.current.commitEditing(), J(n, O(t));
|
|
1569
|
+
}
|
|
1570
|
+
}, q = (e) => new Promise((t, n) => {
|
|
1571
|
+
let r = URL.createObjectURL(e), i = new Image();
|
|
1572
|
+
i.onload = () => {
|
|
1573
|
+
URL.revokeObjectURL(r), t({
|
|
1574
|
+
width: i.naturalWidth,
|
|
1575
|
+
height: i.naturalHeight
|
|
1576
|
+
});
|
|
1577
|
+
}, i.onerror = () => {
|
|
1578
|
+
URL.revokeObjectURL(r), n(/* @__PURE__ */ Error(`无法解码图片:${e.name}`));
|
|
1579
|
+
}, i.src = r;
|
|
1580
|
+
}), J = async (t, n) => {
|
|
1581
|
+
let r = e.toScenePoint(n.x, n.y);
|
|
1582
|
+
for (let n = 0; n < t.length; n += 1) {
|
|
1583
|
+
let i = t[n];
|
|
1584
|
+
if (i) try {
|
|
1585
|
+
let t = await q(i);
|
|
1586
|
+
await e.uploadImageAsLayer(await k(i), {
|
|
1587
|
+
at: {
|
|
1588
|
+
x: r.x + n * Ye,
|
|
1589
|
+
y: r.y + n * Ye
|
|
1590
|
+
},
|
|
1591
|
+
size: t
|
|
1592
|
+
});
|
|
1593
|
+
} catch (e) {
|
|
1594
|
+
E.show(`上传失败:${e instanceof Error ? e.message : String(e)}`);
|
|
1595
|
+
return;
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
};
|
|
1599
|
+
t.addEventListener("dragover", te), t.addEventListener("dragleave", G), t.addEventListener("drop", K), p.push(() => {
|
|
1600
|
+
t.removeEventListener("dragover", te), t.removeEventListener("dragleave", G), t.removeEventListener("drop", K);
|
|
1601
|
+
});
|
|
1602
|
+
let Y = () => e.invalidate("both"), X = (e) => e.preventDefault();
|
|
1603
|
+
return l.addEventListener("contextlost", X), l.addEventListener("contextrestored", Y), d.addEventListener("contextlost", X), d.addEventListener("contextrestored", Y), p.push(() => {
|
|
1604
|
+
l.removeEventListener("contextlost", X), l.removeEventListener("contextrestored", Y), d.removeEventListener("contextlost", X), d.removeEventListener("contextrestored", Y);
|
|
1605
|
+
}), D.current?.({
|
|
1606
|
+
contentCanvas: l,
|
|
1607
|
+
overlayCanvas: d
|
|
1608
|
+
}), () => {
|
|
1609
|
+
p.forEach((e) => e()), p.length = 0, e.detachSurfaces();
|
|
1610
|
+
};
|
|
1611
|
+
}, [e]);
|
|
1612
|
+
let O = h ?? p, A = d ? "cn-surface--panning" : l ? "cn-surface--pannable" : "", j = (() => {
|
|
1613
|
+
if (!d) return v !== null || S ? l ? void 0 : { cursor: "crosshair" } : O === null ? void 0 : { cursor: Ee[O] };
|
|
1614
|
+
})();
|
|
1615
|
+
return /* @__PURE__ */ W("div", {
|
|
1616
|
+
ref: n,
|
|
1617
|
+
className: `cn-surface ${A}`.trim(),
|
|
1618
|
+
style: j,
|
|
1619
|
+
children: [
|
|
1620
|
+
/* @__PURE__ */ U("canvas", {
|
|
1621
|
+
ref: r,
|
|
1622
|
+
className: "cn-surface__canvas"
|
|
1623
|
+
}),
|
|
1624
|
+
/* @__PURE__ */ U("canvas", {
|
|
1625
|
+
ref: i,
|
|
1626
|
+
className: "cn-surface__canvas cn-surface__canvas--overlay"
|
|
1627
|
+
}),
|
|
1628
|
+
/* @__PURE__ */ U(Je, {
|
|
1629
|
+
editor: e,
|
|
1630
|
+
ref: a
|
|
1631
|
+
}),
|
|
1632
|
+
/* @__PURE__ */ U(ae, {
|
|
1633
|
+
editor: e,
|
|
1634
|
+
ref: o
|
|
1635
|
+
}),
|
|
1636
|
+
/* @__PURE__ */ U(Te, {
|
|
1637
|
+
editor: e,
|
|
1638
|
+
ref: s
|
|
1639
|
+
}),
|
|
1640
|
+
w ? /* @__PURE__ */ U("div", {
|
|
1641
|
+
className: "cn-surface__drop-hint",
|
|
1642
|
+
"data-drop-hint": !0,
|
|
1643
|
+
children: /* @__PURE__ */ U("span", {
|
|
1644
|
+
className: "cn-surface__drop-hint-text",
|
|
1645
|
+
children: "松开以上传图片"
|
|
1646
|
+
})
|
|
1647
|
+
}) : null
|
|
1648
|
+
]
|
|
1649
|
+
});
|
|
1650
|
+
}
|
|
1651
|
+
//#endregion
|
|
1652
|
+
//#region src/canvas/AlignFloatBar.tsx
|
|
1653
|
+
var Ze = (e) => `贴${e}角(边距 40px)`, Qe = [
|
|
1654
|
+
{ keys: [{
|
|
1655
|
+
mode: "h-center",
|
|
1656
|
+
icon: i,
|
|
1657
|
+
title: "水平居中"
|
|
1658
|
+
}, {
|
|
1659
|
+
mode: "v-center",
|
|
1660
|
+
icon: s,
|
|
1661
|
+
title: "垂直居中"
|
|
1662
|
+
}] },
|
|
1663
|
+
{ keys: [
|
|
1664
|
+
{
|
|
1665
|
+
mode: "left",
|
|
1666
|
+
icon: r,
|
|
1667
|
+
title: "贴左"
|
|
1668
|
+
},
|
|
1669
|
+
{
|
|
1670
|
+
mode: "right",
|
|
1671
|
+
icon: t,
|
|
1672
|
+
title: "贴右"
|
|
1673
|
+
},
|
|
1674
|
+
{
|
|
1675
|
+
mode: "top",
|
|
1676
|
+
icon: o,
|
|
1677
|
+
title: "贴顶"
|
|
1678
|
+
},
|
|
1679
|
+
{
|
|
1680
|
+
mode: "bottom",
|
|
1681
|
+
icon: e,
|
|
1682
|
+
title: "贴底"
|
|
1683
|
+
}
|
|
1684
|
+
] },
|
|
1685
|
+
{ keys: [
|
|
1686
|
+
{
|
|
1687
|
+
mode: "corner-tl",
|
|
1688
|
+
icon: de,
|
|
1689
|
+
title: Ze("左上")
|
|
1690
|
+
},
|
|
1691
|
+
{
|
|
1692
|
+
mode: "corner-tr",
|
|
1693
|
+
icon: pe,
|
|
1694
|
+
title: Ze("右上")
|
|
1695
|
+
},
|
|
1696
|
+
{
|
|
1697
|
+
mode: "corner-bl",
|
|
1698
|
+
icon: se,
|
|
1699
|
+
title: Ze("左下")
|
|
1700
|
+
},
|
|
1701
|
+
{
|
|
1702
|
+
mode: "corner-br",
|
|
1703
|
+
icon: le,
|
|
1704
|
+
title: Ze("右下")
|
|
1705
|
+
}
|
|
1706
|
+
] }
|
|
1707
|
+
];
|
|
1708
|
+
function $e({ editor: e }) {
|
|
1709
|
+
let t = P(e), n = t !== null, r = (e) => ({ [`data-align-${e}`]: "" });
|
|
1710
|
+
function i(n) {
|
|
1711
|
+
let r = t;
|
|
1712
|
+
r && (n.startsWith("corner-") ? e.alignToCanvas(r, n, { margin: 40 }) : e.alignToCanvas(r, n));
|
|
1713
|
+
}
|
|
1714
|
+
return /* @__PURE__ */ U("div", {
|
|
1715
|
+
className: `cn-align-float${n ? "" : " cn-align-float--disabled"}`,
|
|
1716
|
+
role: "toolbar",
|
|
1717
|
+
"aria-label": "对齐画布",
|
|
1718
|
+
"data-align-float": !0,
|
|
1719
|
+
"aria-disabled": n ? void 0 : "true",
|
|
1720
|
+
children: Qe.map((e, t) => /* @__PURE__ */ W("span", {
|
|
1721
|
+
style: { display: "contents" },
|
|
1722
|
+
children: [t > 0 && /* @__PURE__ */ U("span", {
|
|
1723
|
+
className: "cn-align-float__divider",
|
|
1724
|
+
"aria-hidden": "true"
|
|
1725
|
+
}), /* @__PURE__ */ U("span", {
|
|
1726
|
+
className: "cn-align-float__group",
|
|
1727
|
+
children: e.keys.map((e) => /* @__PURE__ */ U("button", {
|
|
1728
|
+
type: "button",
|
|
1729
|
+
className: "cn-align-float__key",
|
|
1730
|
+
disabled: !n,
|
|
1731
|
+
title: e.title,
|
|
1732
|
+
"aria-label": e.title,
|
|
1733
|
+
...r(e.mode),
|
|
1734
|
+
onClick: () => i(e.mode),
|
|
1735
|
+
children: /* @__PURE__ */ U(p, { icon: e.icon })
|
|
1736
|
+
}, e.mode))
|
|
1737
|
+
})]
|
|
1738
|
+
}, t))
|
|
1739
|
+
});
|
|
1740
|
+
}
|
|
1741
|
+
//#endregion
|
|
1742
|
+
//#region src/canvas/guideSnap.ts
|
|
1743
|
+
function et(e, t, n, r) {
|
|
1744
|
+
let i = e.store.doc;
|
|
1745
|
+
if (!i) return n;
|
|
1746
|
+
let a = r === void 0 ? e.listGuides() : e.listGuides().filter((e) => e.id !== r), o = Y({
|
|
1747
|
+
x: n,
|
|
1748
|
+
y: n,
|
|
1749
|
+
width: 0,
|
|
1750
|
+
height: 0
|
|
1751
|
+
}, K(i.width, i.height, G(i, -1, e.textPolicies), a), te(e.store.ui.viewport.zoom));
|
|
1752
|
+
return t === "vertical" ? n + o.dx : n + o.dy;
|
|
1753
|
+
}
|
|
1754
|
+
//#endregion
|
|
1755
|
+
//#region src/canvas/GuidesOverlay.tsx
|
|
1756
|
+
function tt(e, t) {
|
|
1757
|
+
return {
|
|
1758
|
+
orientation: t.orientation,
|
|
1759
|
+
position: et(e, t.orientation, t.position)
|
|
1760
|
+
};
|
|
1761
|
+
}
|
|
1762
|
+
function nt(e) {
|
|
1763
|
+
return String(Math.round(e * 100) / 100);
|
|
1764
|
+
}
|
|
1765
|
+
function rt(e, t, n) {
|
|
1766
|
+
let r = B(0), i = B(null), a = L((n) => e.subscribe((e) => {
|
|
1767
|
+
(e.scope === "doc" || e.scope === "ui" && t.has(e.branch)) && (r.current += 1, n());
|
|
1768
|
+
}), [e]), o = L(() => {
|
|
1769
|
+
let e = i.current;
|
|
1770
|
+
if (e !== null && e.version === r.current) return e.snapshot;
|
|
1771
|
+
let t = n();
|
|
1772
|
+
return i.current = {
|
|
1773
|
+
version: r.current,
|
|
1774
|
+
snapshot: t
|
|
1775
|
+
}, t;
|
|
1776
|
+
}, [e]);
|
|
1777
|
+
return H(a, o);
|
|
1778
|
+
}
|
|
1779
|
+
var it = /* @__PURE__ */ new Set(["guides"]), at = /* @__PURE__ */ new Set(["snapAxes"]);
|
|
1780
|
+
function ot({ editor: e, ref: t }) {
|
|
1781
|
+
let n = F(e), r = H(L((t) => e.subscribe((e) => {
|
|
1782
|
+
e.scope === "doc" && t();
|
|
1783
|
+
}), [e]), () => e.store.doc), i = rt(e, it, () => e.listGuides()), a = rt(e, at, () => e.listSnapAxes()), o = B(n);
|
|
1784
|
+
o.current = n;
|
|
1785
|
+
let s = B(r);
|
|
1786
|
+
s.current = r;
|
|
1787
|
+
function c(e, t) {
|
|
1788
|
+
let n = s.current, r = o.current;
|
|
1789
|
+
return n ? e === "vertical" ? {
|
|
1790
|
+
left: `${(t - r.x) * r.zoom}px`,
|
|
1791
|
+
top: "0px",
|
|
1792
|
+
height: "100%"
|
|
1793
|
+
} : {
|
|
1794
|
+
top: `${(t - r.y) * r.zoom}px`,
|
|
1795
|
+
left: "0px",
|
|
1796
|
+
width: "100%"
|
|
1797
|
+
} : { display: "none" };
|
|
1798
|
+
}
|
|
1799
|
+
let l = B(null), [u, d] = V(null), f = L((e) => {
|
|
1800
|
+
l.current = e, d(e);
|
|
1801
|
+
}, []), p = L((t) => {
|
|
1802
|
+
f(tt(e, t));
|
|
1803
|
+
}, [e, f]), m = L((t) => {
|
|
1804
|
+
let n = l.current;
|
|
1805
|
+
n !== null && n.orientation === t.orientation && f(tt(e, t));
|
|
1806
|
+
}, [e, f]), h = L((t) => {
|
|
1807
|
+
let n = l.current;
|
|
1808
|
+
if (f(null), n === null) return;
|
|
1809
|
+
let { orientation: r, position: i } = tt(e, t);
|
|
1810
|
+
e.listGuides().some((e) => e.orientation === r && Math.abs(e.position - i) < 1e-6) || e.addGuide({
|
|
1811
|
+
orientation: r,
|
|
1812
|
+
position: i
|
|
1813
|
+
});
|
|
1814
|
+
}, [e, f]), g = L(() => {
|
|
1815
|
+
f(null);
|
|
1816
|
+
}, [f]);
|
|
1817
|
+
z(t, () => ({
|
|
1818
|
+
beginGuideDrag: p,
|
|
1819
|
+
moveGuideDrag: m,
|
|
1820
|
+
endGuideDrag: h,
|
|
1821
|
+
cancelGuideDrag: g
|
|
1822
|
+
}));
|
|
1823
|
+
let [_, v] = V(null), y = B(null);
|
|
1824
|
+
function b(e, t) {
|
|
1825
|
+
let n = y.current?.getBoundingClientRect(), r = o.current, i = n?.left ?? 0, a = n?.top ?? 0;
|
|
1826
|
+
return t === "vertical" ? r.x + (e.clientX - i) / r.zoom : r.y + (e.clientY - a) / r.zoom;
|
|
1827
|
+
}
|
|
1828
|
+
function x(e, t) {
|
|
1829
|
+
let n = document.elementFromPoint(e, t);
|
|
1830
|
+
return n !== null && n.closest("[data-ruler-top], [data-ruler-left]") !== null;
|
|
1831
|
+
}
|
|
1832
|
+
function S(e) {
|
|
1833
|
+
try {
|
|
1834
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
1835
|
+
} catch {}
|
|
1836
|
+
}
|
|
1837
|
+
function C(e) {
|
|
1838
|
+
try {
|
|
1839
|
+
e.currentTarget.releasePointerCapture(e.pointerId);
|
|
1840
|
+
} catch {}
|
|
1841
|
+
}
|
|
1842
|
+
function w(e, t) {
|
|
1843
|
+
e.button === 0 && _ === null && (e.preventDefault(), v({
|
|
1844
|
+
id: t.id,
|
|
1845
|
+
orientation: t.orientation,
|
|
1846
|
+
pointerId: e.pointerId,
|
|
1847
|
+
current: t.position,
|
|
1848
|
+
overRuler: !1
|
|
1849
|
+
}), S(e));
|
|
1850
|
+
}
|
|
1851
|
+
function T(t) {
|
|
1852
|
+
let n = _;
|
|
1853
|
+
n !== null && t.pointerId === n.pointerId && v({
|
|
1854
|
+
...n,
|
|
1855
|
+
current: et(e, n.orientation, b(t.nativeEvent, n.orientation), n.id),
|
|
1856
|
+
overRuler: x(t.clientX, t.clientY)
|
|
1857
|
+
});
|
|
1858
|
+
}
|
|
1859
|
+
function E(t) {
|
|
1860
|
+
let n = _;
|
|
1861
|
+
if (n !== null && t.pointerId === n.pointerId) {
|
|
1862
|
+
if (v(null), C(t), x(t.clientX, t.clientY)) {
|
|
1863
|
+
e.removeGuide(n.id);
|
|
1864
|
+
return;
|
|
1865
|
+
}
|
|
1866
|
+
e.listGuides().some((e) => e.id !== n.id && e.orientation === n.orientation && Math.abs(e.position - n.current) < 1e-6) ? e.removeGuide(n.id) : e.updateGuide(n.id, n.current);
|
|
1867
|
+
}
|
|
1868
|
+
}
|
|
1869
|
+
function D(e) {
|
|
1870
|
+
let t = _;
|
|
1871
|
+
t !== null && e.pointerId === t.pointerId && (v(null), C(e));
|
|
1872
|
+
}
|
|
1873
|
+
let O = i.map((e) => {
|
|
1874
|
+
let t = _;
|
|
1875
|
+
return t !== null && t.id === e.id ? {
|
|
1876
|
+
id: e.id,
|
|
1877
|
+
orientation: e.orientation,
|
|
1878
|
+
position: t.current,
|
|
1879
|
+
dragging: !0,
|
|
1880
|
+
overRuler: t.overRuler
|
|
1881
|
+
} : {
|
|
1882
|
+
id: e.id,
|
|
1883
|
+
orientation: e.orientation,
|
|
1884
|
+
position: e.position,
|
|
1885
|
+
dragging: !1,
|
|
1886
|
+
overRuler: !1
|
|
1887
|
+
};
|
|
1888
|
+
});
|
|
1889
|
+
return /* @__PURE__ */ W("div", {
|
|
1890
|
+
ref: y,
|
|
1891
|
+
className: "cn-guides",
|
|
1892
|
+
"data-guide-overlay": !0,
|
|
1893
|
+
children: [
|
|
1894
|
+
a.map((e, t) => /* @__PURE__ */ U("div", {
|
|
1895
|
+
className: `cn-guides__snap cn-guides__snap--${e.orientation}`,
|
|
1896
|
+
"data-snap-line": !0,
|
|
1897
|
+
"data-snap-orientation": e.orientation,
|
|
1898
|
+
"data-snap-position": nt(e.position),
|
|
1899
|
+
"data-snap-source": e.source,
|
|
1900
|
+
style: c(e.orientation, e.position)
|
|
1901
|
+
}, `${e.orientation}-${e.position}-${t}`)),
|
|
1902
|
+
O.map((e) => /* @__PURE__ */ U("div", {
|
|
1903
|
+
className: [
|
|
1904
|
+
"cn-guides__guide",
|
|
1905
|
+
`cn-guides__guide--${e.orientation}`,
|
|
1906
|
+
e.dragging ? "cn-guides__guide--grabbed" : "",
|
|
1907
|
+
e.overRuler ? "cn-guides__guide--will-delete" : ""
|
|
1908
|
+
].filter(Boolean).join(" "),
|
|
1909
|
+
"data-guide-line": e.id,
|
|
1910
|
+
"data-guide-orientation": e.orientation,
|
|
1911
|
+
"data-guide-position": nt(e.position),
|
|
1912
|
+
"data-guide-dragging": e.dragging ? "" : void 0,
|
|
1913
|
+
style: c(e.orientation, e.position),
|
|
1914
|
+
onPointerDown: (t) => w(t, e),
|
|
1915
|
+
onPointerMove: T,
|
|
1916
|
+
onPointerUp: E,
|
|
1917
|
+
onPointerCancel: D
|
|
1918
|
+
}, e.id)),
|
|
1919
|
+
u !== null && /* @__PURE__ */ U("div", {
|
|
1920
|
+
className: `cn-guides__guide cn-guides__guide--preview cn-guides__guide--${u.orientation}`,
|
|
1921
|
+
"data-guide-preview": !0,
|
|
1922
|
+
"data-guide-orientation": u.orientation,
|
|
1923
|
+
"data-guide-position": nt(u.position),
|
|
1924
|
+
style: c(u.orientation, u.position)
|
|
1925
|
+
})
|
|
1926
|
+
]
|
|
1927
|
+
});
|
|
1928
|
+
}
|
|
1929
|
+
//#endregion
|
|
1930
|
+
//#region src/canvas/Ruler.tsx
|
|
1931
|
+
var st = 10, ct = [
|
|
1932
|
+
1,
|
|
1933
|
+
2,
|
|
1934
|
+
5,
|
|
1935
|
+
10,
|
|
1936
|
+
20,
|
|
1937
|
+
50,
|
|
1938
|
+
100,
|
|
1939
|
+
200,
|
|
1940
|
+
500,
|
|
1941
|
+
1e3,
|
|
1942
|
+
2e3,
|
|
1943
|
+
5e3,
|
|
1944
|
+
1e4
|
|
1945
|
+
], lt = 5;
|
|
1946
|
+
function ut(e, t, n) {
|
|
1947
|
+
if (!(t > 0) || !(n > 0) || !Number.isFinite(e)) return [];
|
|
1948
|
+
let r = ct[ct.length - 1];
|
|
1949
|
+
for (let e of ct) if (e * n >= st) {
|
|
1950
|
+
r = e;
|
|
1951
|
+
break;
|
|
1952
|
+
}
|
|
1953
|
+
let i = r * lt, a = Math.floor(e / r) * r, o = [];
|
|
1954
|
+
for (let s = 0;; s += 1) {
|
|
1955
|
+
let c = a + s * r, l = (c - e) * n;
|
|
1956
|
+
if (l > t) break;
|
|
1957
|
+
if (l >= 0) {
|
|
1958
|
+
let e = c / i, t = Math.abs(e - Math.round(e)) < 1e-6;
|
|
1959
|
+
o.push({
|
|
1960
|
+
scene: c,
|
|
1961
|
+
position: l,
|
|
1962
|
+
label: t ? String(Math.round(c)) : null
|
|
1963
|
+
});
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
return o;
|
|
1967
|
+
}
|
|
1968
|
+
function dt({ editor: e, onGuideDragStart: t, onGuideDragMove: n, onGuideDragEnd: r, onGuideDragCancel: i }) {
|
|
1969
|
+
let a = F(e), o = L((t) => e.subscribe((e) => {
|
|
1970
|
+
e.scope === "ui" && e.branch === "rulersVisible" && t();
|
|
1971
|
+
}), [e]), s = H(o, () => e.store.ui.rulersVisible), c = B(null), l = B(null), [u, d] = V(0), [f, p] = V(0);
|
|
1972
|
+
R(() => {
|
|
1973
|
+
let e = () => {
|
|
1974
|
+
d(c.current?.clientWidth ?? 0), p(l.current?.clientHeight ?? 0);
|
|
1975
|
+
};
|
|
1976
|
+
if (e(), typeof ResizeObserver != "function") return;
|
|
1977
|
+
let t = new ResizeObserver(e);
|
|
1978
|
+
return c.current && t.observe(c.current), l.current && t.observe(l.current), () => t.disconnect();
|
|
1979
|
+
}, []);
|
|
1980
|
+
let m = ut(a.x, u, a.zoom), h = ut(a.y, f, a.zoom), g = B(null), _ = B(a);
|
|
1981
|
+
_.current = a;
|
|
1982
|
+
function v(e, t, n) {
|
|
1983
|
+
let r = e.getBoundingClientRect(), i = _.current;
|
|
1984
|
+
return {
|
|
1985
|
+
orientation: t,
|
|
1986
|
+
position: t === "vertical" ? i.x + (n.clientX - r.left) / i.zoom : i.y + (n.clientY - r.top) / i.zoom
|
|
1987
|
+
};
|
|
1988
|
+
}
|
|
1989
|
+
function y(e, n) {
|
|
1990
|
+
let r = e.currentTarget;
|
|
1991
|
+
if (e.button === 0 && g.current === null) {
|
|
1992
|
+
e.preventDefault(), g.current = {
|
|
1993
|
+
pointerId: e.pointerId,
|
|
1994
|
+
orientation: n
|
|
1995
|
+
};
|
|
1996
|
+
try {
|
|
1997
|
+
r.setPointerCapture(e.pointerId);
|
|
1998
|
+
} catch {}
|
|
1999
|
+
t?.(v(r, n, e.nativeEvent));
|
|
2000
|
+
}
|
|
2001
|
+
}
|
|
2002
|
+
function b(e) {
|
|
2003
|
+
let t = g.current;
|
|
2004
|
+
t !== null && e.pointerId === t.pointerId && n?.(v(e.currentTarget, t.orientation, e.nativeEvent));
|
|
2005
|
+
}
|
|
2006
|
+
function x(e, t) {
|
|
2007
|
+
let n = g.current;
|
|
2008
|
+
if (n === null || e.pointerId !== n.pointerId) return;
|
|
2009
|
+
g.current = null;
|
|
2010
|
+
try {
|
|
2011
|
+
e.currentTarget.releasePointerCapture(e.pointerId);
|
|
2012
|
+
} catch {}
|
|
2013
|
+
let a = v(e.currentTarget, n.orientation, e.nativeEvent);
|
|
2014
|
+
t === "end" ? r?.(a) : i?.(a);
|
|
2015
|
+
}
|
|
2016
|
+
return /* @__PURE__ */ W("div", {
|
|
2017
|
+
className: "cn-ruler",
|
|
2018
|
+
"data-ruler": !0,
|
|
2019
|
+
style: s ? void 0 : { display: "none" },
|
|
2020
|
+
children: [
|
|
2021
|
+
/* @__PURE__ */ U("div", {
|
|
2022
|
+
ref: c,
|
|
2023
|
+
className: "cn-ruler__bar cn-ruler__bar--top",
|
|
2024
|
+
"data-ruler-top": !0,
|
|
2025
|
+
role: "img",
|
|
2026
|
+
"aria-label": "水平标尺",
|
|
2027
|
+
title: "水平标尺(拖出垂直参考线)",
|
|
2028
|
+
onPointerDown: (e) => y(e, "vertical"),
|
|
2029
|
+
onPointerMove: b,
|
|
2030
|
+
onPointerUp: (e) => x(e, "end"),
|
|
2031
|
+
onPointerCancel: (e) => x(e, "cancel"),
|
|
2032
|
+
children: m.map((e) => /* @__PURE__ */ U("span", {
|
|
2033
|
+
className: `cn-ruler__tick${e.label === null ? "" : " cn-ruler__tick--major"}`,
|
|
2034
|
+
style: { left: `${e.position}px` },
|
|
2035
|
+
children: e.label !== null && /* @__PURE__ */ U("span", {
|
|
2036
|
+
className: "cn-ruler__label",
|
|
2037
|
+
children: e.label
|
|
2038
|
+
})
|
|
2039
|
+
}, e.scene))
|
|
2040
|
+
}),
|
|
2041
|
+
/* @__PURE__ */ U("div", {
|
|
2042
|
+
ref: l,
|
|
2043
|
+
className: "cn-ruler__bar cn-ruler__bar--left",
|
|
2044
|
+
"data-ruler-left": !0,
|
|
2045
|
+
role: "img",
|
|
2046
|
+
"aria-label": "垂直标尺",
|
|
2047
|
+
title: "垂直标尺(拖出水平参考线)",
|
|
2048
|
+
onPointerDown: (e) => y(e, "horizontal"),
|
|
2049
|
+
onPointerMove: b,
|
|
2050
|
+
onPointerUp: (e) => x(e, "end"),
|
|
2051
|
+
onPointerCancel: (e) => x(e, "cancel"),
|
|
2052
|
+
children: h.map((e) => /* @__PURE__ */ U("span", {
|
|
2053
|
+
className: `cn-ruler__tick${e.label === null ? "" : " cn-ruler__tick--major"}`,
|
|
2054
|
+
style: { top: `${e.position}px` },
|
|
2055
|
+
children: e.label !== null && /* @__PURE__ */ U("span", {
|
|
2056
|
+
className: "cn-ruler__label",
|
|
2057
|
+
children: e.label
|
|
2058
|
+
})
|
|
2059
|
+
}, e.scene))
|
|
2060
|
+
}),
|
|
2061
|
+
/* @__PURE__ */ U("div", {
|
|
2062
|
+
className: "cn-ruler__corner",
|
|
2063
|
+
"data-ruler-corner": !0,
|
|
2064
|
+
"aria-hidden": "true"
|
|
2065
|
+
})
|
|
2066
|
+
]
|
|
2067
|
+
});
|
|
2068
|
+
}
|
|
2069
|
+
//#endregion
|
|
2070
|
+
//#region src/canvas/createBand.ts
|
|
2071
|
+
var ft = "#2563eb", pt = "rgba(37, 99, 235, 0.08)", mt = [4, 3], ht = 1, gt = "rgba(11, 18, 32, 0.9)", _t = "#ffffff", vt = 11, yt = 6, bt = 3, xt = 3, St = 6, Ct = /* @__PURE__ */ new WeakSet();
|
|
2072
|
+
function wt(e, t, n, r, i, a) {
|
|
2073
|
+
if (typeof e.roundRect == "function") {
|
|
2074
|
+
e.roundRect(t, n, r, i, a);
|
|
2075
|
+
return;
|
|
2076
|
+
}
|
|
2077
|
+
Ct.has(e) || (Ct.add(e), console.warn("[canvas-editor-react] ctx.roundRect 缺失:气泡圆角降级为 arc 四弧拼合(等效闭合形状)"));
|
|
2078
|
+
let o = Math.min(a, r / 2, i / 2);
|
|
2079
|
+
e.moveTo(t + o, n), e.arc(t + r - o, n + o, o, -Math.PI / 2, 0), e.arc(t + r - o, n + i - o, o, 0, Math.PI / 2), e.arc(t + o, n + i - o, o, Math.PI / 2, Math.PI), e.arc(t + o, n + o, o, Math.PI, Math.PI * 1.5), e.closePath();
|
|
2080
|
+
}
|
|
2081
|
+
function Tt(e, t, n) {
|
|
2082
|
+
let r = t.store.ui.create;
|
|
2083
|
+
if (!r) return;
|
|
2084
|
+
let { x: i, y: a, width: o, height: s } = r.rect;
|
|
2085
|
+
if (o === 0 && s === 0) return;
|
|
2086
|
+
let c = n.viewport.zoom;
|
|
2087
|
+
e.fillStyle = pt, e.fillRect(i, a, o, s), e.strokeStyle = ft, e.lineWidth = ht / c, e.setLineDash(mt.map((e) => e / c)), e.strokeRect(i, a, o, s), e.setLineDash([]);
|
|
2088
|
+
let l = vt / c, u = yt / c, d = bt / c;
|
|
2089
|
+
e.font = `${l}px system-ui, sans-serif`;
|
|
2090
|
+
let f = `${Math.round(o)} × ${Math.round(s)}`, p = e.measureText(f).width + u * 2, m = l + d * 2, h = i + o + St / c, g = a + s + St / c;
|
|
2091
|
+
e.fillStyle = gt, e.beginPath(), wt(e, h, g, p, m, xt / c), e.fill(), e.fillStyle = _t, e.textBaseline = "middle", e.fillText(f, h + u, g + m / 2);
|
|
2092
|
+
}
|
|
2093
|
+
//#endregion
|
|
2094
|
+
//#region src/canvas/findHighlight.ts
|
|
2095
|
+
var Et = {
|
|
2096
|
+
matchColor: "#f59e0b",
|
|
2097
|
+
currentColor: "#38bdf8",
|
|
2098
|
+
currentFill: "rgba(56, 189, 248, 0.12)",
|
|
2099
|
+
lineWidth: 2
|
|
2100
|
+
};
|
|
2101
|
+
function Dt(e, t, n, r) {
|
|
2102
|
+
if (!n.doc || !t.store.ui.find.open) return;
|
|
2103
|
+
let i = {
|
|
2104
|
+
...Et,
|
|
2105
|
+
...r
|
|
2106
|
+
}, a = t.listFindMatches();
|
|
2107
|
+
if (a.length === 0) return;
|
|
2108
|
+
let o = t.findCursor;
|
|
2109
|
+
for (let r = 0; r < a.length; r += 1) {
|
|
2110
|
+
let s = t.layerBoxAt(a[r].path);
|
|
2111
|
+
if (!s) continue;
|
|
2112
|
+
let c = r === o;
|
|
2113
|
+
c && i.currentFill && (e.fillStyle = i.currentFill, e.fillRect(s.x, s.y, s.width, s.height)), e.strokeStyle = c ? i.currentColor : i.matchColor, e.lineWidth = (c ? i.lineWidth * 1.5 : i.lineWidth) / n.viewport.zoom, e.strokeRect(s.x, s.y, s.width, s.height);
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
//#endregion
|
|
2117
|
+
//#region src/canvas/gizmo.ts
|
|
2118
|
+
var Ot = {
|
|
2119
|
+
selectionColor: "#2563eb",
|
|
2120
|
+
hoverColor: "rgba(37, 99, 235, 0.55)",
|
|
2121
|
+
selectionWidth: 2,
|
|
2122
|
+
handleSize: 8,
|
|
2123
|
+
handleFill: "#ffffff"
|
|
2124
|
+
};
|
|
2125
|
+
function kt(e, t) {
|
|
2126
|
+
return f(e, t)?.visible === !1;
|
|
2127
|
+
}
|
|
2128
|
+
function At(e, t, n, r) {
|
|
2129
|
+
let i = {
|
|
2130
|
+
...Ot,
|
|
2131
|
+
...r
|
|
2132
|
+
}, { selection: a, hovered: o } = t.store.ui, s = n.doc;
|
|
2133
|
+
if (s) {
|
|
2134
|
+
if (o && !u(o, a) && !kt(s, o) && !t.isLocked(o)) {
|
|
2135
|
+
let r = t.layerBoxAt(o);
|
|
2136
|
+
r && (e.strokeStyle = i.hoverColor, e.lineWidth = i.selectionWidth / 2 / n.viewport.zoom, e.strokeRect(r.x, r.y, r.width, r.height));
|
|
2137
|
+
}
|
|
2138
|
+
if (a && !kt(s, a)) {
|
|
2139
|
+
let r = t.layerBoxAt(a);
|
|
2140
|
+
r && (e.strokeStyle = i.selectionColor, e.lineWidth = i.selectionWidth / n.viewport.zoom, e.strokeRect(r.x, r.y, r.width, r.height), jt(e, t, a, r, n.viewport.zoom, i));
|
|
2141
|
+
}
|
|
2142
|
+
}
|
|
2143
|
+
}
|
|
2144
|
+
function jt(e, t, n, r, i, a) {
|
|
2145
|
+
let o = t.resizeHandlesAt(n);
|
|
2146
|
+
if (o.length === 0) return;
|
|
2147
|
+
let s = a.handleSize / i, c = s / 2;
|
|
2148
|
+
e.fillStyle = a.handleFill, e.strokeStyle = a.selectionColor, e.lineWidth = a.selectionWidth / i;
|
|
2149
|
+
for (let t of o) {
|
|
2150
|
+
let n = X(r, t);
|
|
2151
|
+
e.fillRect(n.x - c, n.y - c, s, s), e.strokeRect(n.x - c, n.y - c, s, s);
|
|
2152
|
+
}
|
|
2153
|
+
}
|
|
2154
|
+
function Mt(e, t, n) {
|
|
2155
|
+
return (r) => {
|
|
2156
|
+
if (!t) return;
|
|
2157
|
+
t.setTransform(1, 0, 0, 1, 0, 0), t.clearRect(0, 0, t.canvas.width, t.canvas.height);
|
|
2158
|
+
let i = r.dpr * r.viewport.zoom;
|
|
2159
|
+
t.setTransform(i, 0, 0, i, -r.viewport.x * i, -r.viewport.y * i), At(t, e, r, n);
|
|
2160
|
+
};
|
|
2161
|
+
}
|
|
2162
|
+
//#endregion
|
|
2163
|
+
//#region src/canvas/scheduler.ts
|
|
2164
|
+
function Nt() {
|
|
2165
|
+
return (e) => {
|
|
2166
|
+
let t = window.requestAnimationFrame(() => e());
|
|
2167
|
+
return () => window.cancelAnimationFrame(t);
|
|
2168
|
+
};
|
|
2169
|
+
}
|
|
2170
|
+
//#endregion
|
|
2171
|
+
export { ae as _, Tt as a, $e as c, qe as d, Re as f, we as g, Te as h, Dt as i, Xe as l, je as m, Mt as n, dt as o, Ne as p, At as r, ot as s, Nt as t, Je as u };
|