@hankchen/canvas-editor-vue 0.1.1 → 0.1.2

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.
@@ -0,0 +1,1601 @@
1
+ import { o as e } from "./dist-B6-i-hhY.js";
2
+ import { i as t, n, o as r } from "./layerPath-uy2ywyld.js";
3
+ import { i, r as a } from "./completionAnchor-CDR5YZhu.js";
4
+ import { l as o, n as s, o as c, s as l, t as u } from "./useTransientFeedback-Cnp6aNB7.js";
5
+ import { i as d, n as f, r as p, t as m } from "./uploadFile-BOfv8aLG.js";
6
+ import { n as h, t as g } from "./useViewport-D9Ipevzs.js";
7
+ import { Fragment as _, computed as v, createBlock as y, createCommentVNode as b, createElementBlock as x, createElementVNode as S, createVNode as C, defineComponent as w, mergeProps as T, nextTick as E, normalizeClass as D, normalizeStyle as O, onBeforeUnmount as k, onMounted as A, onScopeDispose as j, openBlock as M, ref as N, renderList as P, shallowRef as F, toDisplayString as I, unref as L, vModelText as R, vShow as z, watch as B, withDirectives as V, withKeys as ee, withModifiers as H } from "vue";
8
+ import { AlignCenterHorizontal as U, AlignCenterVertical as W, AlignEndHorizontal as G, AlignEndVertical as K, AlignStartHorizontal as q, AlignStartVertical as J, ArrowDownLeft as Y, ArrowDownRight as X, ArrowUpLeft as Z, ArrowUpRight as te, ChevronDown as ne, ChevronUp as re } from "@lucide/vue";
9
+ //#region ../canvas-editor/src/spatial/camera.ts
10
+ function ie(e, t) {
11
+ if (!(t > 0)) return e;
12
+ let n = e.zoom * t;
13
+ return {
14
+ x: Math.round(e.x * n) / n,
15
+ y: Math.round(e.y * n) / n,
16
+ zoom: e.zoom
17
+ };
18
+ }
19
+ function ae(e) {
20
+ return 6 / e;
21
+ }
22
+ function oe(t, n, r) {
23
+ let i = [];
24
+ for (let a = 0; a < t.layers.length; a += 1) {
25
+ if (n !== null && a === n) continue;
26
+ let o = t.layers[a];
27
+ o.visible !== !1 && i.push(e(o, 0, 0, t.width, t.height, r));
28
+ }
29
+ return i;
30
+ }
31
+ function se(e, t, n, r) {
32
+ let i = [];
33
+ for (let e of n) i.push({
34
+ orientation: "vertical",
35
+ position: e.x,
36
+ source: "layer"
37
+ }, {
38
+ orientation: "vertical",
39
+ position: e.x + e.width / 2,
40
+ source: "layer"
41
+ }, {
42
+ orientation: "vertical",
43
+ position: e.x + e.width,
44
+ source: "layer"
45
+ }, {
46
+ orientation: "horizontal",
47
+ position: e.y,
48
+ source: "layer"
49
+ }, {
50
+ orientation: "horizontal",
51
+ position: e.y + e.height / 2,
52
+ source: "layer"
53
+ }, {
54
+ orientation: "horizontal",
55
+ position: e.y + e.height,
56
+ source: "layer"
57
+ });
58
+ i.push({
59
+ orientation: "vertical",
60
+ position: e / 2,
61
+ source: "canvas-center"
62
+ }, {
63
+ orientation: "horizontal",
64
+ position: t / 2,
65
+ source: "canvas-center"
66
+ });
67
+ for (let e of r) i.push({
68
+ orientation: e.orientation,
69
+ position: e.position,
70
+ source: "guide"
71
+ });
72
+ return i;
73
+ }
74
+ function ce(e, t, n, r) {
75
+ let i = null;
76
+ for (let a of t) if (a.orientation === n) for (let t of e) {
77
+ let e = a.position - t, n = Math.abs(e);
78
+ n > r || (i === null || n < Math.abs(i.delta)) && (i = {
79
+ delta: e,
80
+ axis: a
81
+ });
82
+ }
83
+ return i;
84
+ }
85
+ function le(e, t, n) {
86
+ let r = ce(e.vertical, t, "vertical", n), i = ce(e.horizontal, t, "horizontal", n);
87
+ return {
88
+ dx: r ? r.delta : 0,
89
+ dy: i ? i.delta : 0,
90
+ axes: [...r ? [r.axis] : [], ...i ? [i.axis] : []]
91
+ };
92
+ }
93
+ function ue(e, t, n) {
94
+ return le({
95
+ vertical: [
96
+ e.x,
97
+ e.x + e.width / 2,
98
+ e.x + e.width
99
+ ],
100
+ horizontal: [
101
+ e.y,
102
+ e.y + e.height / 2,
103
+ e.y + e.height
104
+ ]
105
+ }, t, n);
106
+ }
107
+ //#endregion
108
+ //#region ../canvas-editor/src/spatial/resize.ts
109
+ function de(e, t) {
110
+ let n = e.x + e.width, r = e.y + e.height;
111
+ switch (t) {
112
+ case "nw": return {
113
+ x: e.x,
114
+ y: e.y
115
+ };
116
+ case "n": return {
117
+ x: e.x + e.width / 2,
118
+ y: e.y
119
+ };
120
+ case "ne": return {
121
+ x: n,
122
+ y: e.y
123
+ };
124
+ case "e": return {
125
+ x: n,
126
+ y: e.y + e.height / 2
127
+ };
128
+ case "se": return {
129
+ x: n,
130
+ y: r
131
+ };
132
+ case "s": return {
133
+ x: e.x + e.width / 2,
134
+ y: r
135
+ };
136
+ case "sw": return {
137
+ x: e.x,
138
+ y: r
139
+ };
140
+ case "w": return {
141
+ x: e.x,
142
+ y: e.y + e.height / 2
143
+ };
144
+ }
145
+ }
146
+ //#endregion
147
+ //#region ../canvas-editor/src/spatial/wheel.ts
148
+ function fe(e) {
149
+ return e.ctrlKey || e.metaKey ? "zoom" : e.shiftKey ? "pan-x" : "pan";
150
+ }
151
+ //#endregion
152
+ //#region ../canvas-browser-renderer/src/fonts.ts
153
+ function pe(e) {
154
+ return e === "" || /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/.test(e.trim());
155
+ }
156
+ function me(e) {
157
+ return pe(e) ? "sans-serif" : `${he(e)}, sans-serif`;
158
+ }
159
+ function he(e) {
160
+ let t = 2166136261;
161
+ for (let n = 0; n < e.length; n++) t ^= e.charCodeAt(n), t = Math.imul(t, 16777619);
162
+ return `canvas-font-${(t >>> 0).toString(36)}`;
163
+ }
164
+ //#endregion
165
+ //#region src/canvas/AlignFloatBar.vue?vue&type=script&setup=true&lang.ts
166
+ var ge = ["aria-disabled"], _e = {
167
+ key: 0,
168
+ class: "cn-align-float__divider",
169
+ "aria-hidden": "true"
170
+ }, ve = { class: "cn-align-float__group" }, ye = [
171
+ "disabled",
172
+ "title",
173
+ "aria-label",
174
+ "onClick"
175
+ ], be = /*#__PURE__*/ o(/* @__PURE__ */ w({
176
+ __name: "AlignFloatBar",
177
+ props: { editor: {} },
178
+ setup(e) {
179
+ let t = e, n = h(t.editor), r = v(() => n.value !== null), a = (e) => `贴${e}角(边距 40px)`, o = [
180
+ { keys: [{
181
+ mode: "h-center",
182
+ icon: W,
183
+ title: "水平居中"
184
+ }, {
185
+ mode: "v-center",
186
+ icon: U,
187
+ title: "垂直居中"
188
+ }] },
189
+ { keys: [
190
+ {
191
+ mode: "left",
192
+ icon: J,
193
+ title: "贴左"
194
+ },
195
+ {
196
+ mode: "right",
197
+ icon: K,
198
+ title: "贴右"
199
+ },
200
+ {
201
+ mode: "top",
202
+ icon: q,
203
+ title: "贴顶"
204
+ },
205
+ {
206
+ mode: "bottom",
207
+ icon: G,
208
+ title: "贴底"
209
+ }
210
+ ] },
211
+ { keys: [
212
+ {
213
+ mode: "corner-tl",
214
+ icon: Z,
215
+ title: a("左上")
216
+ },
217
+ {
218
+ mode: "corner-tr",
219
+ icon: te,
220
+ title: a("右上")
221
+ },
222
+ {
223
+ mode: "corner-bl",
224
+ icon: Y,
225
+ title: a("左下")
226
+ },
227
+ {
228
+ mode: "corner-br",
229
+ icon: X,
230
+ title: a("右下")
231
+ }
232
+ ] }
233
+ ];
234
+ function s(e) {
235
+ return { [`data-align-${e}`]: "" };
236
+ }
237
+ function c(e) {
238
+ let r = n.value;
239
+ r && (e.startsWith("corner-") ? t.editor.alignToCanvas(r, e, { margin: 40 }) : t.editor.alignToCanvas(r, e));
240
+ }
241
+ return (e, t) => (M(), x("div", {
242
+ class: D(["cn-align-float", { "cn-align-float--disabled": !r.value }]),
243
+ role: "toolbar",
244
+ "aria-label": "对齐画布",
245
+ "data-align-float": "",
246
+ "aria-disabled": r.value ? void 0 : "true"
247
+ }, [(M(), x(_, null, P(o, (e, t) => (M(), x(_, { key: t }, [t > 0 ? (M(), x("span", _e)) : b("", !0), S("span", ve, [(M(!0), x(_, null, P(e.keys, (e) => (M(), x("button", T({
248
+ key: e.mode,
249
+ type: "button",
250
+ class: "cn-align-float__key",
251
+ disabled: !r.value,
252
+ title: e.title,
253
+ "aria-label": e.title
254
+ }, { ref_for: !0 }, s(e.mode), { onClick: (t) => c(e.mode) }), [C(i, { icon: e.icon }, null, 8, ["icon"])], 16, ye))), 128))])], 64))), 64))], 10, ge));
255
+ }
256
+ }), [["__scopeId", "data-v-9a761d37"]]), xe = {
257
+ key: 0,
258
+ class: "cn-context-menu__form"
259
+ }, Se = { class: "cn-context-menu__hint" }, Ce = ["onKeydown"], we = {
260
+ key: 0,
261
+ class: "cn-context-menu__hint cn-context-menu__hint--error"
262
+ }, Te = [
263
+ "disabled",
264
+ "title",
265
+ "onClick"
266
+ ], Ee = /*#__PURE__*/ o(/* @__PURE__ */ w({
267
+ __name: "ContextMenu",
268
+ props: { editor: {} },
269
+ setup(e, { expose: t }) {
270
+ let i = e, a = N(null), o = N(!1), s = N({
271
+ x: 0,
272
+ y: 0
273
+ }), u = c(), d = `先 ${l("copyStyle", u)} 复制样式`, f = `图层已锁定(${l("toggleLayerLock", u)} 解锁后可删除)`, p = h(i.editor), m = v(() => p.value !== null && n(p.value)), g = v(() => p.value !== null && i.editor.canCopySelection), y = v(() => (o.value, p.value !== null && i.editor.canCopyStyle)), C = v(() => (o.value, p.value !== null && i.editor.canPasteStyle)), w = v(() => {
274
+ let e = p.value, t = i.editor.store.doc;
275
+ return !e || !t || !n(e) ? !0 : r(t, e)?.visible ?? !0;
276
+ }), T = v(() => {
277
+ let e = p.value, t = i.editor.store.doc;
278
+ return !e || !t ? null : r(t, e);
279
+ });
280
+ function k() {
281
+ let e = p.value;
282
+ return !e || typeof e[1] != "number" ? null : ["layers", e[1]];
283
+ }
284
+ let A = v(() => T.value?.type === "TableLayer" && T.value.template !== null), j = v(() => p.value?.[p.value.length - 1] === "template"), F = v(() => p.value !== null && i.editor.isLocked(p.value)), L = v(() => {
285
+ let e = T.value;
286
+ if (!e || e.type !== "TableLayer" || e.template !== null) return !1;
287
+ let t = e.rows[e.rows.length - 1];
288
+ return t !== void 0 && t.cells.length > 0;
289
+ }), z = v(() => {
290
+ let e = T.value;
291
+ return !e || e.type !== "TableLayer" ? "" : `模板取自末行,其余 ${Math.max(e.rows.length - 1, 0)} 行将移除(可撤销)`;
292
+ }), B = N(!1), U = N(""), W = N(!1);
293
+ function G() {
294
+ B.value = !0, U.value = "", W.value = !1;
295
+ }
296
+ function K() {
297
+ let e = k(), t = U.value.trim();
298
+ if (!e || t === "") {
299
+ W.value = !0;
300
+ return;
301
+ }
302
+ i.editor.convertTableToTemplate(e, t), Y();
303
+ }
304
+ let q = v(() => [
305
+ {
306
+ key: "visibility",
307
+ label: w.value ? "隐藏" : "显示",
308
+ enabled: m.value,
309
+ title: m.value ? void 0 : "显示/隐藏仅作用于根图层",
310
+ run: () => {
311
+ let e = p.value;
312
+ e && i.editor.toggleLayerVisibility(e);
313
+ }
314
+ },
315
+ {
316
+ key: "duplicate",
317
+ label: "创建副本",
318
+ enabled: g.value,
319
+ title: g.value ? void 0 : "行/格/行模板是容器内结构,不可复制",
320
+ run: () => i.editor.duplicateSelection()
321
+ },
322
+ {
323
+ key: "copy-style",
324
+ label: "复制样式",
325
+ enabled: y.value,
326
+ title: !y.value && j.value ? "行模板替身无样式可复制" : void 0,
327
+ run: () => {
328
+ let e = p.value;
329
+ e && i.editor.copyStyle(e);
330
+ }
331
+ },
332
+ {
333
+ key: "paste-style",
334
+ label: "粘贴样式",
335
+ enabled: C.value,
336
+ title: C.value ? void 0 : d,
337
+ run: () => {
338
+ let e = p.value;
339
+ e && i.editor.pasteStyle(e);
340
+ }
341
+ },
342
+ {
343
+ key: "forward",
344
+ label: "前移一层",
345
+ enabled: m.value,
346
+ title: m.value ? void 0 : "前移/后移仅对根图层生效",
347
+ run: () => i.editor.bringForward()
348
+ },
349
+ {
350
+ key: "backward",
351
+ label: "后移一层",
352
+ enabled: m.value,
353
+ title: m.value ? void 0 : "前移/后移仅对根图层生效",
354
+ run: () => i.editor.sendBackward()
355
+ },
356
+ {
357
+ key: "front",
358
+ label: "置顶",
359
+ enabled: m.value,
360
+ title: m.value ? void 0 : "置顶/置底仅对根图层生效",
361
+ run: () => i.editor.bringToFront()
362
+ },
363
+ {
364
+ key: "back",
365
+ label: "置底",
366
+ enabled: m.value,
367
+ title: m.value ? void 0 : "置顶/置底仅对根图层生效",
368
+ run: () => i.editor.sendToBack()
369
+ },
370
+ ...A.value ? [{
371
+ key: "to-rows",
372
+ label: "转回普通表",
373
+ enabled: !0,
374
+ title: "行模板实例化为单行,恢复普通表格编辑",
375
+ run: () => {
376
+ let e = k();
377
+ e && i.editor.convertTableToRows(e);
378
+ }
379
+ }] : T.value?.type === "TableLayer" ? [{
380
+ key: "to-template",
381
+ label: "转为模板表…",
382
+ enabled: L.value,
383
+ title: L.value ? z.value : T.value.rows.length === 0 ? "空表无可转换行" : "末行为空——先为末行加格",
384
+ keepsOpen: !0,
385
+ run: () => G()
386
+ }] : [],
387
+ {
388
+ key: "delete",
389
+ label: "删除",
390
+ enabled: p.value !== null && !j.value && !F.value,
391
+ title: j.value ? "行模板由表持有——转换回普通表请用 V2 转换入口" : F.value ? f : void 0,
392
+ run: () => {
393
+ let e = p.value;
394
+ e && i.editor.deleteLayer(e);
395
+ }
396
+ }
397
+ ]);
398
+ async function J(e, t) {
399
+ s.value = {
400
+ x: e,
401
+ y: t
402
+ }, o.value = !0, await E();
403
+ let n = a.value, r = n?.parentElement;
404
+ if (!n || !r) return;
405
+ let i = n.getBoundingClientRect(), c = r.clientWidth - i.width - 2, l = r.clientHeight - i.height - 2;
406
+ s.value = {
407
+ x: Math.max(2, Math.min(s.value.x, c)),
408
+ y: Math.max(2, Math.min(s.value.y, l))
409
+ };
410
+ }
411
+ function Y() {
412
+ o.value = !1, B.value = !1, U.value = "", W.value = !1;
413
+ }
414
+ function X(e) {
415
+ e.run(), e.keepsOpen !== !0 && Y();
416
+ }
417
+ return t({
418
+ openAt: J,
419
+ close: Y
420
+ }), (e, t) => o.value ? (M(), x("div", {
421
+ key: 0,
422
+ ref_key: "rootRef",
423
+ ref: a,
424
+ class: "cn-context-menu",
425
+ role: "menu",
426
+ "aria-label": "图层操作菜单",
427
+ style: O({
428
+ left: `${s.value.x}px`,
429
+ top: `${s.value.y}px`
430
+ }),
431
+ onPointerdown: t[1] ||= H(() => {}, ["stop"]),
432
+ onContextmenu: t[2] ||= H(() => {}, ["prevent"])
433
+ }, [B.value ? (M(), x("div", xe, [
434
+ S("p", Se, I(z.value), 1),
435
+ V(S("input", {
436
+ "onUpdate:modelValue": t[0] ||= (e) => U.value = e,
437
+ "data-convert-rows-path": "",
438
+ type: "text",
439
+ placeholder: "数据行路径,如 order.items",
440
+ class: D(["cn-context-menu__input", { "cn-context-menu__input--invalid": W.value }]),
441
+ onKeydown: ee(H(K, ["prevent"]), ["enter"])
442
+ }, null, 42, Ce), [[R, U.value]]),
443
+ W.value ? (M(), x("p", we, " rowsPath 必填 ")) : b("", !0),
444
+ S("div", { class: "cn-context-menu__form-actions" }, [S("button", {
445
+ type: "button",
446
+ class: "cn-context-menu__item cn-context-menu__item--confirm",
447
+ onClick: K
448
+ }, " 确认转换 "), S("button", {
449
+ type: "button",
450
+ class: "cn-context-menu__item",
451
+ onClick: Y
452
+ }, "取消")])
453
+ ])) : (M(!0), x(_, { key: 1 }, P(q.value, (e) => (M(), x("button", {
454
+ key: e.key,
455
+ type: "button",
456
+ role: "menuitem",
457
+ class: D(["cn-context-menu__item", [`cn-context-menu__item--${e.key}`]]),
458
+ disabled: !e.enabled,
459
+ title: e.title,
460
+ onClick: (t) => X(e)
461
+ }, I(e.label), 11, Te))), 128))], 36)) : b("", !0);
462
+ }
463
+ }), [["__scopeId", "data-v-e554ef38"]]);
464
+ //#endregion
465
+ //#region src/canvas/useFindSession.ts
466
+ function De(e) {
467
+ let t = F(e.store.ui.find.open), n = F(e.store.ui.find.query), r = F(e.store.ui.find.replacement), i = F(e.listFindMatches()), a = F(e.findCursor), o = () => {
468
+ let o = e.store.ui.find;
469
+ t.value = o.open, n.value = o.query, r.value = o.replacement, i.value = e.listFindMatches(), a.value = e.findCursor;
470
+ }, s = e.subscribe((e) => {
471
+ (e.scope === "doc" || e.scope === "ui" && e.branch === "find") && o();
472
+ });
473
+ return j(s, !0), {
474
+ open: t,
475
+ query: n,
476
+ replacement: r,
477
+ matches: i,
478
+ cursor: a
479
+ };
480
+ }
481
+ //#endregion
482
+ //#region src/canvas/FindBar.vue?vue&type=script&setup=true&lang.ts
483
+ var Oe = ["value"], ke = ["value"], Ae = {
484
+ class: "cn-find-bar__count",
485
+ "data-find-count": ""
486
+ }, je = {
487
+ key: 0,
488
+ class: "cn-find-bar__note",
489
+ "data-find-note": ""
490
+ }, Me = ["disabled"], Ne = ["disabled"], Pe = ["disabled"], Fe = ["disabled"], Ie = /*#__PURE__*/ o(/* @__PURE__ */ w({
491
+ __name: "FindBar",
492
+ props: { editor: {} },
493
+ setup(e, { expose: t }) {
494
+ let n = e, { open: r, query: a, replacement: o, matches: c, cursor: l } = De(n.editor), u = N(null), d = N(null), f = v(() => {
495
+ let e = c.value.length;
496
+ return e === 0 ? a.value === "" ? "" : "无结果" : `第 ${l.value + 1}/${e} 处`;
497
+ }), p = v(() => c.value.length > 0), m = v(() => p.value && l.value > 0), h = v(() => p.value && l.value < c.value.length - 1);
498
+ function g(e) {
499
+ let t = c.value[e];
500
+ if (!t) return;
501
+ n.editor.setSelection(t.path);
502
+ let r = n.editor.layerBoxAt(t.path);
503
+ r && n.editor.panToBox(r);
504
+ }
505
+ function _(e) {
506
+ let t = c.value.length;
507
+ if (t === 0) return;
508
+ let r = Math.min(Math.max(l.value + e, 0), t - 1);
509
+ n.editor.setFindCursor(r), g(r);
510
+ }
511
+ function y() {
512
+ n.editor.replaceOne() && g(l.value);
513
+ }
514
+ function w() {
515
+ let e = n.editor.replaceAll();
516
+ e !== 0 && (d.value = `已替换 ${e} 处`, g(l.value));
517
+ }
518
+ function T() {
519
+ n.editor.closeFind(), d.value = null;
520
+ }
521
+ function E(e) {
522
+ if (!(e.isComposing || e.keyCode === 229)) {
523
+ if (e.key === "Escape") {
524
+ e.preventDefault(), T();
525
+ return;
526
+ }
527
+ e.key === "Enter" && (e.preventDefault(), _(e.shiftKey ? -1 : 1));
528
+ }
529
+ }
530
+ function D(e) {
531
+ n.editor.setFindQuery(e.target.value);
532
+ }
533
+ function O(e) {
534
+ n.editor.setFindReplacement(e.target.value);
535
+ }
536
+ B(r, (e) => {
537
+ e && u.value?.focus({ preventScroll: !0 });
538
+ }, {
539
+ immediate: !0,
540
+ flush: "post"
541
+ });
542
+ function A(e) {
543
+ r.value && (e.key.toLowerCase() !== "f" || !(e.metaKey || e.ctrlKey) || e.shiftKey || e.altKey || s(e.target) || u.value?.focus({ preventScroll: !0 }));
544
+ }
545
+ return window.addEventListener("keydown", A), k(() => window.removeEventListener("keydown", A)), B(a, () => {
546
+ d.value = null;
547
+ }), t({ close: T }), (e, t) => L(r) ? (M(), x("div", {
548
+ key: 0,
549
+ class: "cn-find-bar",
550
+ "data-find-bar": "",
551
+ role: "search",
552
+ "aria-label": "查找替换",
553
+ onPointerdown: t[2] ||= H(() => {}, ["stop"])
554
+ }, [
555
+ S("input", {
556
+ ref_key: "queryInput",
557
+ ref: u,
558
+ class: "cn-find-bar__input",
559
+ "data-find-query": "",
560
+ type: "text",
561
+ value: L(a),
562
+ placeholder: "查找",
563
+ "aria-label": "查找",
564
+ spellcheck: "false",
565
+ autocomplete: "off",
566
+ onInput: D,
567
+ onKeydown: E
568
+ }, null, 40, Oe),
569
+ S("input", {
570
+ class: "cn-find-bar__input",
571
+ "data-find-replace": "",
572
+ type: "text",
573
+ value: L(o),
574
+ placeholder: "替换",
575
+ "aria-label": "替换",
576
+ spellcheck: "false",
577
+ autocomplete: "off",
578
+ onInput: O,
579
+ onKeydown: E
580
+ }, null, 40, ke),
581
+ S("span", Ae, I(f.value), 1),
582
+ d.value ? (M(), x("span", je, I(d.value), 1)) : b("", !0),
583
+ S("button", {
584
+ type: "button",
585
+ class: "cn-find-bar__key",
586
+ "data-find-prev": "",
587
+ disabled: !m.value,
588
+ title: "上一处(Shift+Enter)",
589
+ "aria-label": "上一处",
590
+ onClick: t[0] ||= (e) => _(-1)
591
+ }, [C(i, { icon: L(re) }, null, 8, ["icon"])], 8, Me),
592
+ S("button", {
593
+ type: "button",
594
+ class: "cn-find-bar__key",
595
+ "data-find-next": "",
596
+ disabled: !h.value,
597
+ title: "下一处(Enter)",
598
+ "aria-label": "下一处",
599
+ onClick: t[1] ||= (e) => _(1)
600
+ }, [C(i, { icon: L(ne) }, null, 8, ["icon"])], 8, Ne),
601
+ S("button", {
602
+ type: "button",
603
+ class: "cn-find-bar__action",
604
+ "data-find-replace-one": "",
605
+ disabled: !p.value,
606
+ title: "替换当前处",
607
+ onClick: y
608
+ }, " 替换 ", 8, Pe),
609
+ S("button", {
610
+ type: "button",
611
+ class: "cn-find-bar__action",
612
+ "data-find-replace-all": "",
613
+ disabled: !p.value,
614
+ title: "全部替换",
615
+ onClick: w
616
+ }, " 全部替换 ", 8, Fe)
617
+ ], 32)) : b("", !0);
618
+ }
619
+ }), [["__scopeId", "data-v-e9f0e575"]]), Le = {
620
+ nw: "nwse-resize",
621
+ se: "nwse-resize",
622
+ ne: "nesw-resize",
623
+ sw: "nesw-resize",
624
+ n: "ns-resize",
625
+ s: "ns-resize",
626
+ e: "ew-resize",
627
+ w: "ew-resize"
628
+ }, Re = [
629
+ "aria-pressed",
630
+ "data-pill-static",
631
+ "data-pill-expression",
632
+ "onClick"
633
+ ], ze = /*#__PURE__*/ o(/* @__PURE__ */ w({
634
+ __name: "ContentTypePill",
635
+ props: { mode: {} },
636
+ emits: ["change"],
637
+ setup(e, { expose: t, emit: n }) {
638
+ let r = e, i = n, a = N(null);
639
+ t({ rootEl: a });
640
+ let o = [{
641
+ value: "static",
642
+ label: "静态"
643
+ }, {
644
+ value: "expression",
645
+ label: "表达式"
646
+ }];
647
+ function s(e) {
648
+ e !== r.mode && i("change", e);
649
+ }
650
+ return (t, n) => (M(), x("div", {
651
+ ref_key: "rootRef",
652
+ ref: a,
653
+ class: "cn-content-pill",
654
+ role: "group",
655
+ "aria-label": "内容类型",
656
+ "data-content-pill": "",
657
+ onPointerdown: n[0] ||= H(() => {}, ["prevent"])
658
+ }, [(M(), x(_, null, P(o, (t) => S("button", {
659
+ key: t.value,
660
+ type: "button",
661
+ class: D(["cn-content-pill__item", { "cn-content-pill__item--active": t.value === e.mode }]),
662
+ "aria-pressed": t.value === e.mode,
663
+ "data-pill-static": t.value === "static" || void 0,
664
+ "data-pill-expression": t.value === "expression" || void 0,
665
+ onClick: (e) => s(t.value)
666
+ }, I(t.label), 11, Re)), 64))], 544));
667
+ }
668
+ }), [["__scopeId", "data-v-d99d2c13"]]);
669
+ //#endregion
670
+ //#region src/canvas/useDpr.ts
671
+ function Q(e) {
672
+ let t = null, n = () => {
673
+ t?.removeEventListener("change", n), e(window.devicePixelRatio || 1), t = window.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`), t.addEventListener("change", n);
674
+ };
675
+ return n(), () => t?.removeEventListener("change", n);
676
+ }
677
+ function $() {
678
+ let e = F(window.devicePixelRatio || 1), t = Q((t) => {
679
+ e.value = t;
680
+ });
681
+ return j(t, !0), e;
682
+ }
683
+ //#endregion
684
+ //#region src/canvas/useTextEditing.ts
685
+ var Be = /* @__PURE__ */ new Map();
686
+ function Ve(e, t) {
687
+ let n = `${e}|${t}`, r = Be.get(n);
688
+ if (r !== void 0) return r;
689
+ let i = t * 1.2;
690
+ try {
691
+ let n = document.createElement("canvas").getContext("2d");
692
+ if (n) {
693
+ n.font = `${t}px ${me(e)}`;
694
+ let r = n.measureText("字"), a = (r.fontBoundingBoxAscent ?? r.actualBoundingBoxAscent) + (r.fontBoundingBoxDescent ?? r.actualBoundingBoxDescent);
695
+ a > 0 && (i = a);
696
+ }
697
+ } catch {}
698
+ return Be.set(n, i), i;
699
+ }
700
+ function He(e, t) {
701
+ let n = F(e.store.ui.editing), r = e.subscribe((t) => {
702
+ (t.scope === "doc" || t.scope === "ui" && t.branch === "editing") && (n.value = e.store.ui.editing);
703
+ });
704
+ j(r, !0);
705
+ let i = v(() => n.value?.path ?? null), a = $(), o = g(e), s = v(() => {
706
+ let t = n.value;
707
+ return t ? e.textEditLayout(t.path) : null;
708
+ }), c = v(() => ie(o.value, a.value));
709
+ function l(e, t) {
710
+ let { x: n, y: r, zoom: i } = c.value;
711
+ return {
712
+ left: (e - n) * i,
713
+ top: (t - r) * i,
714
+ zoom: i
715
+ };
716
+ }
717
+ let u = v(() => {
718
+ let e = s.value;
719
+ if (!e) return null;
720
+ let { left: t, top: n, zoom: r } = l(e.box.x, e.box.y);
721
+ return {
722
+ transform: `translate(${t}px, ${n}px) scale(${r})`,
723
+ transformOrigin: "0 0",
724
+ width: `${e.box.width}px`,
725
+ height: `${e.box.height}px`,
726
+ color: e.fontColor,
727
+ fontFamily: me(e.font),
728
+ fontSize: `${e.fontSize}px`,
729
+ lineHeight: `${e.lineHeightPx}px`,
730
+ ...f(e),
731
+ textAlign: e.horizontalAlign,
732
+ whiteSpace: e.autowrap ? "pre-wrap" : "pre"
733
+ };
734
+ }), d = v(() => {
735
+ let e = s.value;
736
+ if (!e) return null;
737
+ let { left: t, top: n, zoom: r } = l(e.box.x + e.box.width / 2, e.box.y);
738
+ return {
739
+ transform: `translate(${t}px, ${n}px) scale(${r}) translate(-50%, -100%)`,
740
+ transformOrigin: "0 0"
741
+ };
742
+ });
743
+ function f(e) {
744
+ let t = e.padding.top + e.verticalAnchorY, n = e.lineHeightPx, r = Ve(e.font, e.fontSize), i;
745
+ return i = e.verticalAlign === "center" ? t - n / 2 : e.verticalAlign === "bottom" ? t - (n + r) / 2 : t - (n - r) / 2, {
746
+ paddingTop: `${Math.max(0, i)}px`,
747
+ paddingRight: `${e.padding.right}px`,
748
+ paddingBottom: `${e.padding.bottom}px`,
749
+ paddingLeft: `${e.padding.left}px`
750
+ };
751
+ }
752
+ let p = (t, n) => {
753
+ let r = e.hitTest(t, n);
754
+ return r !== null && e.beginTextEdit(r);
755
+ }, m = (t) => e.beginTextEdit(t), h = (t) => {
756
+ let n = e.store.ui.editing;
757
+ n && n.expression !== t && e.store.setEditing({
758
+ path: n.path,
759
+ expression: t
760
+ });
761
+ }, _ = null, y = !1, b = !1, x = () => {
762
+ e.commitTextEdit(t.getTextarea()?.value ?? "");
763
+ }, S = () => {
764
+ _ !== null && clearTimeout(_), _ = null;
765
+ }, C = () => {
766
+ if (S(), w.value) {
767
+ b = !0;
768
+ return;
769
+ }
770
+ x();
771
+ }, w = F(!1), T = (e) => {
772
+ w.value = e, !e && b && (b = !1, i.value !== null && x());
773
+ }, E = () => {
774
+ if (i.value !== null) {
775
+ if (S(), y) {
776
+ y = !1;
777
+ return;
778
+ }
779
+ _ = setTimeout(() => {
780
+ _ = null;
781
+ let e = t.getTextarea();
782
+ if (e === null || document.activeElement !== e) {
783
+ if (w.value) {
784
+ b = !0;
785
+ return;
786
+ }
787
+ x();
788
+ }
789
+ }, 0);
790
+ }
791
+ }, D = (e) => {
792
+ if (!(e instanceof Node)) return !1;
793
+ let n = t.getPill?.() ?? null;
794
+ if (n !== null && n.contains(e)) return !0;
795
+ let r = t.getTextarea();
796
+ return r !== null && r.contains(e);
797
+ }, O = (e) => {
798
+ if (i.value === null || D(e.target)) return;
799
+ let n = t.getHost();
800
+ n !== null && n.contains(e.target) || (y = !0);
801
+ }, k = () => {
802
+ y = !1;
803
+ };
804
+ return window.addEventListener("pointerdown", O, !0), window.addEventListener("pointerup", k, !0), j(() => {
805
+ window.removeEventListener("pointerdown", O, !0), window.removeEventListener("pointerup", k, !0), S();
806
+ }, !0), {
807
+ editing: i,
808
+ layout: s,
809
+ style: u,
810
+ pillStyle: d,
811
+ scale: v(() => c.value.zoom),
812
+ composing: v(() => w.value),
813
+ setComposing: T,
814
+ beginAt: p,
815
+ beginTextEdit: m,
816
+ commitNow: C,
817
+ setExpressionMode: h,
818
+ armBlurCommit: E,
819
+ ownsEventTarget: D
820
+ };
821
+ }
822
+ //#endregion
823
+ //#region src/canvas/TextEditingOverlay.vue?vue&type=script&setup=true&lang.ts
824
+ var Ue = ["wrap"], We = /*#__PURE__*/ o(/* @__PURE__ */ w({
825
+ __name: "TextEditingOverlay",
826
+ props: { editor: {} },
827
+ setup(e, { expose: t }) {
828
+ let n = e, r = N(null), i = N(null), o = N(null), s = N(null), c = He(n.editor, {
829
+ getTextarea: () => i.value,
830
+ getHost: () => r.value?.parentElement ?? null,
831
+ getPill: () => o.value?.rootEl ?? null
832
+ }), { editing: l, style: u, composing: m, pillStyle: h } = c, g = c.layout, _ = v(() => g.value?.expressionMode === !0), { popup: S, accept: w } = f({
833
+ target: i,
834
+ enabled: _,
835
+ resolve: (e) => {
836
+ let t = n.editor.store.ui.dataSourceSchema, r = l.value;
837
+ if (t === null || r === null) return null;
838
+ let i = p(t, d(t, n.editor.store.doc, r));
839
+ return i === null ? null : i(e);
840
+ },
841
+ popupEl: () => s.value?.rootEl ?? null,
842
+ scale: c.scale
843
+ });
844
+ B(l, async (e) => {
845
+ if (!e) return;
846
+ await E();
847
+ let t = i.value, n = c.layout.value;
848
+ t && n && (t.value = n.text, t.focus({ preventScroll: !0 }), t.select());
849
+ }), B(u, async (e, t) => {
850
+ if (!t || !e) return;
851
+ let n = i.value;
852
+ if (!n || m.value) return;
853
+ let r = n.selectionStart, a = n.selectionEnd;
854
+ await E(), i.value === n && (n.selectionStart !== r || n.selectionEnd !== a) && n.setSelectionRange(r, a);
855
+ }, { flush: "post" });
856
+ let T = (e) => {
857
+ e.isComposing || e.keyCode === 229 || (e.key === "Escape" || e.key === "Enter" && (e.ctrlKey || e.metaKey)) && (e.key === "Escape" && S.open || (e.preventDefault(), c.commitNow()));
858
+ }, D = () => c.armBlurCommit();
859
+ return t({
860
+ beginAt: c.beginAt,
861
+ beginTextEdit: c.beginTextEdit,
862
+ commitEditing: () => c.commitNow(),
863
+ isEditing: () => l.value !== null,
864
+ ownsEventTarget: (e) => c.ownsEventTarget(e)
865
+ }), (e, t) => (M(), x("div", {
866
+ ref_key: "rootRef",
867
+ ref: r,
868
+ class: "cn-text-overlay"
869
+ }, [
870
+ L(l) && L(u) ? (M(), x("textarea", {
871
+ key: L(l).join(""),
872
+ ref_key: "textareaRef",
873
+ ref: i,
874
+ class: "cn-text-overlay__textarea",
875
+ style: O(L(u)),
876
+ wrap: L(u).whiteSpace === "pre" ? "off" : "soft",
877
+ spellcheck: "false",
878
+ autocomplete: "off",
879
+ onKeydown: T,
880
+ onBlur: D,
881
+ onCompositionstart: t[0] ||= (e) => L(c).setComposing(!0),
882
+ onCompositionend: t[1] ||= (e) => L(c).setComposing(!1)
883
+ }, null, 44, Ue)) : b("", !0),
884
+ L(l) && L(h) ? (M(), y(ze, {
885
+ key: 1,
886
+ ref_key: "pillRef",
887
+ ref: o,
888
+ style: O(L(h)),
889
+ mode: _.value ? "expression" : "static",
890
+ onChange: t[2] ||= (e) => L(c).setExpressionMode(e === "expression")
891
+ }, null, 8, ["style", "mode"])) : b("", !0),
892
+ C(a, {
893
+ ref_key: "popupRef",
894
+ ref: s,
895
+ state: L(S),
896
+ onSelect: L(w)
897
+ }, null, 8, ["state", "onSelect"])
898
+ ], 512));
899
+ }
900
+ }), [["__scopeId", "data-v-bc9281f8"]]), Ge = {
901
+ key: 0,
902
+ class: "cn-surface__drop-hint",
903
+ "data-drop-hint": ""
904
+ }, Ke = 16, qe = /*#__PURE__*/ o(/* @__PURE__ */ w({
905
+ __name: "CanvasSurface",
906
+ props: { editor: {} },
907
+ emits: ["ready"],
908
+ setup(e, { emit: t }) {
909
+ let n = e, r = t, i = N(null), a = N(null), o = N(null), c = N(null), l = N(null), d = N(null), f = N(!1), p = N(!1), h = N(null), g = N(null), _ = N(n.editor.store.ui.armedCreate), y = N(!1), w = v(() => p.value ? "cn-surface--panning" : f.value ? "cn-surface--pannable" : ""), T = v(() => {
910
+ if (p.value) return;
911
+ if (_.value !== null || y.value) return f.value ? void 0 : { cursor: "crosshair" };
912
+ let e = g.value ?? h.value;
913
+ return e === null ? void 0 : { cursor: Le[e] };
914
+ }), E = N(!1), j = u();
915
+ function P(e) {
916
+ return new Promise((t, n) => {
917
+ let r = URL.createObjectURL(e), i = new Image();
918
+ i.onload = () => {
919
+ URL.revokeObjectURL(r), t({
920
+ width: i.naturalWidth,
921
+ height: i.naturalHeight
922
+ });
923
+ }, i.onerror = () => {
924
+ URL.revokeObjectURL(r), n(/* @__PURE__ */ Error(`无法解码图片:${e.name}`));
925
+ }, i.src = r;
926
+ });
927
+ }
928
+ let F = [];
929
+ return A(() => {
930
+ let e = i.value, t = a.value, u = o.value;
931
+ if (!e || !t || !u) return;
932
+ let v = n.editor, b = () => {
933
+ let n = window.devicePixelRatio, r = Math.max(1, Math.round(e.clientWidth * n)), i = Math.max(1, Math.round(e.clientHeight * n));
934
+ for (let e of [t, u]) e.width !== r && (e.width = r), e.height !== i && (e.height = i);
935
+ v.flushPendingFrames();
936
+ }, x = () => {
937
+ v.setSurfaceSize(e.clientWidth, e.clientHeight), b();
938
+ };
939
+ v.setDevicePixelRatio(window.devicePixelRatio), x();
940
+ let S = v.subscribe((e) => {
941
+ (e.scope === "doc" || e.scope === "ui" && e.branch === "armedCreate") && (_.value = v.store.ui.armedCreate);
942
+ });
943
+ F.push(S);
944
+ let C = new ResizeObserver(x);
945
+ C.observe(e), F.push(() => C.disconnect());
946
+ let w = Q(() => {
947
+ v.setDevicePixelRatio(window.devicePixelRatio), b();
948
+ });
949
+ F.push(w);
950
+ let T = (t) => {
951
+ let n = e.getBoundingClientRect();
952
+ return {
953
+ x: t.clientX - n.left,
954
+ y: t.clientY - n.top
955
+ };
956
+ }, D = (e) => e.deltaMode === 1 ? 16 : e.deltaMode === 2 ? 100 : 1, O = (e) => {
957
+ e.preventDefault();
958
+ let t = D(e), n = T(e), r = fe(e);
959
+ r === "zoom" ? v.zoomByWheel(n.x, n.y, e.deltaY * t) : r === "pan-x" ? v.panBy(-(e.deltaY || e.deltaX) * t, 0) : v.panBy(-e.deltaX * t, -e.deltaY * t);
960
+ };
961
+ e.addEventListener("wheel", O, { passive: !1 }), F.push(() => e.removeEventListener("wheel", O));
962
+ let k = null, A = {
963
+ x: 0,
964
+ y: 0
965
+ }, M = (e) => {
966
+ let t = T(e);
967
+ return v.toScenePoint(t.x, t.y);
968
+ }, N = (t) => {
969
+ if (l.value?.close(), k !== null) return;
970
+ if (t.button === 1 || t.button === 0 && f.value) {
971
+ t.preventDefault(), k = {
972
+ id: t.pointerId,
973
+ mode: "pan"
974
+ }, A = {
975
+ x: t.clientX,
976
+ y: t.clientY
977
+ }, p.value = !0, e.setPointerCapture(t.pointerId);
978
+ return;
979
+ }
980
+ if (t.button !== 0) return;
981
+ if (c.value?.isEditing()) {
982
+ if (c.value.ownsEventTarget(t.target)) return;
983
+ c.value.commitEditing();
984
+ }
985
+ t.preventDefault();
986
+ let n = M(t);
987
+ if (v.beginLayerCreate(n.x, n.y)) {
988
+ k = {
989
+ id: t.pointerId,
990
+ mode: "create"
991
+ }, y.value = !0, h.value = null, e.setPointerCapture(t.pointerId);
992
+ return;
993
+ }
994
+ let r = v.resizeHandleAt(n.x, n.y);
995
+ if (r !== null && v.beginResize(v.store.ui.selection, r, n.x, n.y)) {
996
+ k = {
997
+ id: t.pointerId,
998
+ mode: "resize"
999
+ }, g.value = r, h.value = null, e.setPointerCapture(t.pointerId);
1000
+ return;
1001
+ }
1002
+ let i = M(t), a = v.selectAt(i.x, i.y);
1003
+ if (a && v.beginDrag(a, i.x, i.y, { copy: t.altKey && v.canCopyLayerAt(a) })) {
1004
+ k = {
1005
+ id: t.pointerId,
1006
+ mode: "drag"
1007
+ }, e.setPointerCapture(t.pointerId);
1008
+ return;
1009
+ }
1010
+ a === null && (k = {
1011
+ id: t.pointerId,
1012
+ mode: "pan"
1013
+ }, A = {
1014
+ x: t.clientX,
1015
+ y: t.clientY
1016
+ }, p.value = !0, e.setPointerCapture(t.pointerId));
1017
+ }, I = (e) => {
1018
+ if (k !== null) {
1019
+ if (e.pointerId !== k.id) return;
1020
+ if (k.mode === "pan") v.panBy(e.clientX - A.x, e.clientY - A.y), A = {
1021
+ x: e.clientX,
1022
+ y: e.clientY
1023
+ };
1024
+ else if (k.mode === "resize") {
1025
+ let t = M(e);
1026
+ v.resizeTo(t.x, t.y);
1027
+ } else if (k.mode === "create") {
1028
+ let t = M(e);
1029
+ v.createTo(t.x, t.y);
1030
+ } else {
1031
+ let t = M(e);
1032
+ v.dragTo(t.x, t.y);
1033
+ }
1034
+ return;
1035
+ }
1036
+ let t = M(e), n = v.resizeHandleAt(t.x, t.y);
1037
+ if (h.value = n, n !== null) {
1038
+ v.setHovered(null);
1039
+ return;
1040
+ }
1041
+ v.hoverAt(t.x, t.y);
1042
+ }, L = (t) => {
1043
+ if (k !== null && t.pointerId === k.id) {
1044
+ if (k.mode === "drag") v.endDrag();
1045
+ else if (k.mode === "resize") v.endResize(), g.value = null;
1046
+ else if (k.mode === "create") {
1047
+ y.value = !1;
1048
+ let e = v.endCreate();
1049
+ e !== null && c.value?.beginTextEdit(e);
1050
+ } else p.value = !1;
1051
+ k = null, e.hasPointerCapture(t.pointerId) && e.releasePointerCapture(t.pointerId);
1052
+ }
1053
+ }, R = (e) => {
1054
+ e.button === 1 && e.preventDefault();
1055
+ }, z = (e) => {
1056
+ let t = T(e), n = v.toScenePoint(t.x, t.y);
1057
+ c.value?.beginAt(n.x, n.y);
1058
+ }, B = (e) => {
1059
+ if (c.value?.isEditing()) {
1060
+ if (c.value.ownsEventTarget(e.target)) return;
1061
+ c.value.commitEditing();
1062
+ }
1063
+ e.preventDefault();
1064
+ let t = T(e), n = v.toScenePoint(t.x, t.y);
1065
+ if (v.selectAt(n.x, n.y) === null) {
1066
+ l.value?.close();
1067
+ return;
1068
+ }
1069
+ l.value?.openAt(t.x, t.y);
1070
+ }, V = () => {
1071
+ k === null && (v.setHovered(null), h.value = null);
1072
+ };
1073
+ e.addEventListener("pointerdown", N), e.addEventListener("pointermove", I), e.addEventListener("pointerup", L), e.addEventListener("pointercancel", L), e.addEventListener("pointerleave", V), e.addEventListener("mousedown", R), e.addEventListener("dblclick", z), F.push(() => {
1074
+ e.removeEventListener("pointerdown", N), e.removeEventListener("pointermove", I), e.removeEventListener("pointerup", L), e.removeEventListener("pointercancel", L), e.removeEventListener("pointerleave", V), e.removeEventListener("mousedown", R), e.removeEventListener("dblclick", z);
1075
+ });
1076
+ let ee = s, H = (e) => {
1077
+ e.code !== "Space" || e.repeat || ee(e.target) || (e.preventDefault(), f.value = !0);
1078
+ }, U = (e) => {
1079
+ e.code === "Space" && (f.value = !1);
1080
+ }, W = (e) => {
1081
+ if (!(e.key !== "Escape" || s(e.target))) {
1082
+ if (v.store.ui.armedCreate !== null || v.store.ui.create !== null) {
1083
+ v.cancelCreate();
1084
+ return;
1085
+ }
1086
+ l.value?.close(), d.value?.close(), v.escapeSelection();
1087
+ }
1088
+ };
1089
+ window.addEventListener("keydown", H), window.addEventListener("keyup", U), window.addEventListener("keydown", W), F.push(() => {
1090
+ window.removeEventListener("keydown", H), window.removeEventListener("keyup", U), window.removeEventListener("keydown", W);
1091
+ }), e.addEventListener("contextmenu", B), F.push(() => e.removeEventListener("contextmenu", B));
1092
+ let G = (e) => {
1093
+ let t = e.dataTransfer?.items;
1094
+ if (!t) return !1;
1095
+ for (let e = 0; e < t.length; e += 1) {
1096
+ let n = t[e];
1097
+ if (n !== void 0 && n.kind === "file" && n.type.startsWith("image/")) return !0;
1098
+ }
1099
+ return !1;
1100
+ }, K = (e) => {
1101
+ G(e) && (e.preventDefault(), e.dataTransfer && (e.dataTransfer.dropEffect = "copy"), E.value = !0);
1102
+ }, q = (t) => {
1103
+ t.relatedTarget !== null && e.contains(t.relatedTarget) || (E.value = !1);
1104
+ }, J = (e) => {
1105
+ e.preventDefault(), E.value = !1;
1106
+ let t = [], n = e.dataTransfer?.files;
1107
+ for (let e = 0; n !== void 0 && e < n.length; e += 1) {
1108
+ let r = n[e];
1109
+ r !== void 0 && r.type.startsWith("image/") && t.push(r);
1110
+ }
1111
+ if (t.length !== 0) {
1112
+ if (!v.canUpload) {
1113
+ j.show("上传不可用:未接入上传实现,图片未添加");
1114
+ return;
1115
+ }
1116
+ c.value?.isEditing() && c.value.commitEditing(), Y(t, T(e));
1117
+ }
1118
+ }, Y = async (e, t) => {
1119
+ let n = v.toScenePoint(t.x, t.y);
1120
+ for (let t = 0; t < e.length; t += 1) {
1121
+ let r = e[t];
1122
+ if (r) try {
1123
+ let e = await P(r);
1124
+ await v.uploadImageAsLayer(await m(r), {
1125
+ at: {
1126
+ x: n.x + t * Ke,
1127
+ y: n.y + t * Ke
1128
+ },
1129
+ size: e
1130
+ });
1131
+ } catch (e) {
1132
+ j.show(`上传失败:${e instanceof Error ? e.message : String(e)}`);
1133
+ return;
1134
+ }
1135
+ }
1136
+ };
1137
+ e.addEventListener("dragover", K), e.addEventListener("dragleave", q), e.addEventListener("drop", J), F.push(() => {
1138
+ e.removeEventListener("dragover", K), e.removeEventListener("dragleave", q), e.removeEventListener("drop", J);
1139
+ });
1140
+ let X = () => v.invalidate("both"), Z = (e) => e.preventDefault();
1141
+ t.addEventListener("contextlost", Z), t.addEventListener("contextrestored", X), u.addEventListener("contextlost", Z), u.addEventListener("contextrestored", X), F.push(() => {
1142
+ t.removeEventListener("contextlost", Z), t.removeEventListener("contextrestored", X), u.removeEventListener("contextlost", Z), u.removeEventListener("contextrestored", X);
1143
+ }), r("ready", {
1144
+ contentCanvas: t,
1145
+ overlayCanvas: u
1146
+ });
1147
+ }), k(() => {
1148
+ F.forEach((e) => e()), F.length = 0, n.editor.detachSurfaces();
1149
+ }), (t, n) => (M(), x("div", {
1150
+ ref_key: "hostRef",
1151
+ ref: i,
1152
+ class: D(["cn-surface", w.value]),
1153
+ style: O(T.value)
1154
+ }, [
1155
+ S("canvas", {
1156
+ ref_key: "contentRef",
1157
+ ref: a,
1158
+ class: "cn-surface__canvas"
1159
+ }, null, 512),
1160
+ S("canvas", {
1161
+ ref_key: "overlayRef",
1162
+ ref: o,
1163
+ class: "cn-surface__canvas cn-surface__canvas--overlay"
1164
+ }, null, 512),
1165
+ C(We, {
1166
+ ref_key: "textEditRef",
1167
+ ref: c,
1168
+ editor: e.editor
1169
+ }, null, 8, ["editor"]),
1170
+ C(Ee, {
1171
+ ref_key: "contextMenuRef",
1172
+ ref: l,
1173
+ editor: e.editor
1174
+ }, null, 8, ["editor"]),
1175
+ C(Ie, {
1176
+ ref_key: "findBarRef",
1177
+ ref: d,
1178
+ editor: e.editor
1179
+ }, null, 8, ["editor"]),
1180
+ E.value ? (M(), x("div", Ge, [...n[0] ||= [S("span", { class: "cn-surface__drop-hint-text" }, "松开以上传图片", -1)]])) : b("", !0)
1181
+ ], 6));
1182
+ }
1183
+ }), [["__scopeId", "data-v-6e21095e"]]);
1184
+ //#endregion
1185
+ //#region src/canvas/guideSnap.ts
1186
+ function Je(e, t, n) {
1187
+ let r = e.store.doc;
1188
+ if (!r) return n;
1189
+ let i = ue({
1190
+ x: n,
1191
+ y: n,
1192
+ width: 0,
1193
+ height: 0
1194
+ }, se(r.width, r.height, oe(r, -1, e.textPolicies), e.listGuides()), ae(e.store.ui.viewport.zoom));
1195
+ return t === "vertical" ? n + i.dx : n + i.dy;
1196
+ }
1197
+ //#endregion
1198
+ //#region src/canvas/GuidesOverlay.vue?vue&type=script&setup=true&lang.ts
1199
+ var Ye = [
1200
+ "data-snap-orientation",
1201
+ "data-snap-position",
1202
+ "data-snap-source"
1203
+ ], Xe = [
1204
+ "data-guide-line",
1205
+ "data-guide-orientation",
1206
+ "data-guide-position",
1207
+ "data-guide-dragging",
1208
+ "onPointerdown"
1209
+ ], Ze = ["data-guide-orientation", "data-guide-position"], Qe = /*#__PURE__*/ o(/* @__PURE__ */ w({
1210
+ __name: "GuidesOverlay",
1211
+ props: { editor: {} },
1212
+ setup(e, { expose: t }) {
1213
+ let n = e, r = g(n.editor), i = F(n.editor.store.doc), a = F(n.editor.listGuides()), o = F(n.editor.listSnapAxes()), s = n.editor.subscribe((e) => {
1214
+ if (e.scope === "doc") {
1215
+ i.value = n.editor.store.doc, a.value = n.editor.listGuides(), o.value = n.editor.listSnapAxes();
1216
+ return;
1217
+ }
1218
+ e.branch === "guides" ? a.value = n.editor.listGuides() : e.branch === "snapAxes" && (o.value = n.editor.listSnapAxes());
1219
+ });
1220
+ j(s, !0);
1221
+ function c(e, t) {
1222
+ let n = i.value, a = r.value;
1223
+ return n ? e === "vertical" ? {
1224
+ left: `${(t - a.x) * a.zoom}px`,
1225
+ top: "0px",
1226
+ height: "100%"
1227
+ } : {
1228
+ top: `${(t - a.y) * a.zoom}px`,
1229
+ left: "0px",
1230
+ width: "100%"
1231
+ } : { display: "none" };
1232
+ }
1233
+ function l(e) {
1234
+ return String(Math.round(e * 100) / 100);
1235
+ }
1236
+ let u = N(null);
1237
+ function d(e) {
1238
+ return {
1239
+ orientation: e.orientation,
1240
+ position: Je(n.editor, e.orientation, e.position)
1241
+ };
1242
+ }
1243
+ function f(e) {
1244
+ u.value = d(e);
1245
+ }
1246
+ function p(e) {
1247
+ u.value !== null && u.value.orientation === e.orientation && (u.value = d(e));
1248
+ }
1249
+ function m(e) {
1250
+ if (u.value === null) return;
1251
+ u.value = null;
1252
+ let { orientation: t, position: r } = d(e);
1253
+ n.editor.listGuides().some((e) => e.orientation === t && Math.abs(e.position - r) < 1e-6) || n.editor.addGuide({
1254
+ orientation: t,
1255
+ position: r
1256
+ });
1257
+ }
1258
+ function h() {
1259
+ u.value = null;
1260
+ }
1261
+ t({
1262
+ beginGuideDrag: f,
1263
+ moveGuideDrag: p,
1264
+ endGuideDrag: m,
1265
+ cancelGuideDrag: h
1266
+ });
1267
+ let y = N(null), S = v(() => a.value.map((e) => {
1268
+ let t = y.value;
1269
+ return t !== null && t.id === e.id ? {
1270
+ id: e.id,
1271
+ orientation: e.orientation,
1272
+ position: t.current,
1273
+ dragging: !0,
1274
+ overRuler: t.overRuler
1275
+ } : {
1276
+ id: e.id,
1277
+ orientation: e.orientation,
1278
+ position: e.position,
1279
+ dragging: !1,
1280
+ overRuler: !1
1281
+ };
1282
+ })), C = N(null);
1283
+ function w(e, t) {
1284
+ let n = C.value?.getBoundingClientRect(), i = r.value, a = n?.left ?? 0, o = n?.top ?? 0;
1285
+ return t === "vertical" ? i.x + (e.clientX - a) / i.zoom : i.y + (e.clientY - o) / i.zoom;
1286
+ }
1287
+ function T(e, t) {
1288
+ let n = document.elementFromPoint(e, t);
1289
+ return n !== null && n.closest("[data-ruler-top], [data-ruler-left]") !== null;
1290
+ }
1291
+ function E(e) {
1292
+ try {
1293
+ e.currentTarget.setPointerCapture(e.pointerId);
1294
+ } catch {}
1295
+ }
1296
+ function k(e) {
1297
+ try {
1298
+ e.currentTarget.releasePointerCapture(e.pointerId);
1299
+ } catch {}
1300
+ }
1301
+ function A(e, t) {
1302
+ e.button === 0 && y.value === null && (e.preventDefault(), y.value = {
1303
+ id: t.id,
1304
+ orientation: t.orientation,
1305
+ pointerId: e.pointerId,
1306
+ current: t.position,
1307
+ overRuler: !1
1308
+ }, E(e));
1309
+ }
1310
+ function I(e) {
1311
+ let t = y.value;
1312
+ t !== null && e.pointerId === t.pointerId && (y.value = {
1313
+ ...t,
1314
+ current: w(e, t.orientation),
1315
+ overRuler: T(e.clientX, e.clientY)
1316
+ });
1317
+ }
1318
+ function L(e) {
1319
+ let t = y.value;
1320
+ t !== null && e.pointerId === t.pointerId && (y.value = null, k(e), T(e.clientX, e.clientY) && n.editor.removeGuide(t.id));
1321
+ }
1322
+ function R(e) {
1323
+ let t = y.value;
1324
+ t !== null && e.pointerId === t.pointerId && (y.value = null, k(e));
1325
+ }
1326
+ return (e, t) => (M(), x("div", {
1327
+ ref_key: "rootRef",
1328
+ ref: C,
1329
+ class: "cn-guides",
1330
+ "data-guide-overlay": ""
1331
+ }, [
1332
+ (M(!0), x(_, null, P(o.value, (e, t) => (M(), x("div", {
1333
+ key: `${e.orientation}-${e.position}-${t}`,
1334
+ class: D(["cn-guides__snap", `cn-guides__snap--${e.orientation}`]),
1335
+ "data-snap-line": "",
1336
+ "data-snap-orientation": e.orientation,
1337
+ "data-snap-position": l(e.position),
1338
+ "data-snap-source": e.source,
1339
+ style: O(c(e.orientation, e.position))
1340
+ }, null, 14, Ye))), 128)),
1341
+ (M(!0), x(_, null, P(S.value, (e) => (M(), x("div", {
1342
+ key: e.id,
1343
+ class: D(["cn-guides__guide", [`cn-guides__guide--${e.orientation}`, {
1344
+ "cn-guides__guide--grabbed": e.dragging,
1345
+ "cn-guides__guide--will-delete": e.overRuler
1346
+ }]]),
1347
+ "data-guide-line": e.id,
1348
+ "data-guide-orientation": e.orientation,
1349
+ "data-guide-position": l(e.position),
1350
+ "data-guide-dragging": e.dragging ? "" : void 0,
1351
+ style: O(c(e.orientation, e.position)),
1352
+ onPointerdown: (t) => A(t, e),
1353
+ onPointermove: I,
1354
+ onPointerup: L,
1355
+ onPointercancel: R
1356
+ }, null, 46, Xe))), 128)),
1357
+ u.value ? (M(), x("div", {
1358
+ key: 0,
1359
+ class: D(["cn-guides__guide cn-guides__guide--preview", `cn-guides__guide--${u.value.orientation}`]),
1360
+ "data-guide-preview": "",
1361
+ "data-guide-orientation": u.value.orientation,
1362
+ "data-guide-position": l(u.value.position),
1363
+ style: O(c(u.value.orientation, u.value.position))
1364
+ }, null, 14, Ze)) : b("", !0)
1365
+ ], 512));
1366
+ }
1367
+ }), [["__scopeId", "data-v-51fd929c"]]), $e = {
1368
+ class: "cn-ruler",
1369
+ "data-ruler": ""
1370
+ }, et = {
1371
+ key: 0,
1372
+ class: "cn-ruler__label"
1373
+ }, tt = {
1374
+ key: 0,
1375
+ class: "cn-ruler__label"
1376
+ }, nt = 10, rt = 5, it = /*#__PURE__*/ o(/* @__PURE__ */ w({
1377
+ __name: "Ruler",
1378
+ props: { editor: {} },
1379
+ emits: [
1380
+ "guide-drag-start",
1381
+ "guide-drag-move",
1382
+ "guide-drag-end",
1383
+ "guide-drag-cancel"
1384
+ ],
1385
+ setup(e, { emit: t }) {
1386
+ let n = e, r = t, i = g(n.editor), a = F(n.editor.store.ui.rulersVisible), o = n.editor.subscribe((e) => {
1387
+ e.scope === "ui" && e.branch === "rulersVisible" && (a.value = n.editor.store.ui.rulersVisible);
1388
+ });
1389
+ j(o, !0);
1390
+ let s = [
1391
+ 1,
1392
+ 2,
1393
+ 5,
1394
+ 10,
1395
+ 20,
1396
+ 50,
1397
+ 100,
1398
+ 200,
1399
+ 500,
1400
+ 1e3,
1401
+ 2e3,
1402
+ 5e3,
1403
+ 1e4
1404
+ ];
1405
+ function c(e, t, n) {
1406
+ if (!(t > 0) || !(n > 0) || !Number.isFinite(e)) return [];
1407
+ let r = s[s.length - 1];
1408
+ for (let e of s) if (e * n >= nt) {
1409
+ r = e;
1410
+ break;
1411
+ }
1412
+ let i = r * rt, a = Math.floor(e / r) * r, o = [];
1413
+ for (let s = 0;; s++) {
1414
+ let c = a + s * r, l = (c - e) * n;
1415
+ if (l > t) break;
1416
+ if (l >= 0) {
1417
+ let e = c / i, t = Math.abs(e - Math.round(e)) < 1e-6;
1418
+ o.push({
1419
+ scene: c,
1420
+ position: l,
1421
+ label: t ? String(Math.round(c)) : null
1422
+ });
1423
+ }
1424
+ }
1425
+ return o;
1426
+ }
1427
+ let l = N(null), u = N(null), d = N(0), f = N(0), p = () => {
1428
+ d.value = l.value?.clientWidth ?? 0, f.value = u.value?.clientHeight ?? 0;
1429
+ }, m = null;
1430
+ A(() => {
1431
+ p(), m = new ResizeObserver(() => p()), l.value && m.observe(l.value), u.value && m.observe(u.value);
1432
+ }), k(() => m?.disconnect());
1433
+ let h = v(() => c(i.value.x, d.value, i.value.zoom)), y = v(() => c(i.value.y, f.value, i.value.zoom)), C = N(null);
1434
+ function w(e, t, n) {
1435
+ let r = e.getBoundingClientRect(), a = i.value;
1436
+ return {
1437
+ orientation: t,
1438
+ position: t === "vertical" ? a.x + (n.clientX - r.left) / a.zoom : a.y + (n.clientY - r.top) / a.zoom
1439
+ };
1440
+ }
1441
+ function T(e, t) {
1442
+ let n = e.currentTarget;
1443
+ if (n instanceof HTMLElement && e.button === 0 && C.value === null) {
1444
+ e.preventDefault(), C.value = {
1445
+ pointerId: e.pointerId,
1446
+ orientation: t
1447
+ };
1448
+ try {
1449
+ n.setPointerCapture(e.pointerId);
1450
+ } catch {}
1451
+ r("guide-drag-start", w(n, t, e));
1452
+ }
1453
+ }
1454
+ function E(e) {
1455
+ let t = e.currentTarget, n = C.value;
1456
+ t instanceof HTMLElement && n !== null && e.pointerId === n.pointerId && r("guide-drag-move", w(t, n.orientation, e));
1457
+ }
1458
+ function L(e, t) {
1459
+ let n = e.currentTarget, i = C.value;
1460
+ if (!(n instanceof HTMLElement) || i === null || e.pointerId !== i.pointerId) return;
1461
+ C.value = null;
1462
+ try {
1463
+ n.releasePointerCapture(e.pointerId);
1464
+ } catch {}
1465
+ let a = w(n, i.orientation, e);
1466
+ r(t === "guide-drag-end" ? "guide-drag-end" : "guide-drag-cancel", a);
1467
+ }
1468
+ return (e, t) => V((M(), x("div", $e, [
1469
+ S("div", {
1470
+ ref_key: "topRef",
1471
+ ref: l,
1472
+ class: "cn-ruler__bar cn-ruler__bar--top",
1473
+ "data-ruler-top": "",
1474
+ role: "img",
1475
+ "aria-label": "水平标尺",
1476
+ title: "水平标尺(拖出垂直参考线)",
1477
+ onPointerdown: t[0] ||= (e) => T(e, "vertical"),
1478
+ onPointermove: t[1] ||= (e) => E(e),
1479
+ onPointerup: t[2] ||= (e) => L(e, "guide-drag-end"),
1480
+ onPointercancel: t[3] ||= (e) => L(e, "guide-drag-cancel")
1481
+ }, [(M(!0), x(_, null, P(h.value, (e) => (M(), x("span", {
1482
+ key: e.scene,
1483
+ class: D(["cn-ruler__tick", { "cn-ruler__tick--major": e.label !== null }]),
1484
+ style: O({ left: `${e.position}px` })
1485
+ }, [e.label === null ? b("", !0) : (M(), x("span", et, I(e.label), 1))], 6))), 128))], 544),
1486
+ S("div", {
1487
+ ref_key: "leftRef",
1488
+ ref: u,
1489
+ class: "cn-ruler__bar cn-ruler__bar--left",
1490
+ "data-ruler-left": "",
1491
+ role: "img",
1492
+ "aria-label": "垂直标尺",
1493
+ title: "垂直标尺(拖出水平参考线)",
1494
+ onPointerdown: t[4] ||= (e) => T(e, "horizontal"),
1495
+ onPointermove: t[5] ||= (e) => E(e),
1496
+ onPointerup: t[6] ||= (e) => L(e, "guide-drag-end"),
1497
+ onPointercancel: t[7] ||= (e) => L(e, "guide-drag-cancel")
1498
+ }, [(M(!0), x(_, null, P(y.value, (e) => (M(), x("span", {
1499
+ key: e.scene,
1500
+ class: D(["cn-ruler__tick", { "cn-ruler__tick--major": e.label !== null }]),
1501
+ style: O({ top: `${e.position}px` })
1502
+ }, [e.label === null ? b("", !0) : (M(), x("span", tt, I(e.label), 1))], 6))), 128))], 544),
1503
+ t[8] ||= S("div", {
1504
+ class: "cn-ruler__corner",
1505
+ "data-ruler-corner": "",
1506
+ "aria-hidden": "true"
1507
+ }, null, -1)
1508
+ ], 512)), [[z, a.value]]);
1509
+ }
1510
+ }), [["__scopeId", "data-v-5bd7248c"]]), at = "#2563eb", ot = "rgba(37, 99, 235, 0.08)", st = [4, 3], ct = 1, lt = "rgba(11, 18, 32, 0.9)", ut = "#ffffff", dt = 11, ft = 6, pt = 3, mt = 3, ht = 6;
1511
+ function gt(e, t, n) {
1512
+ let r = t.store.ui.create;
1513
+ if (!r) return;
1514
+ let { x: i, y: a, width: o, height: s } = r.rect;
1515
+ if (o === 0 && s === 0) return;
1516
+ let c = n.viewport.zoom;
1517
+ e.fillStyle = ot, e.fillRect(i, a, o, s), e.strokeStyle = at, e.lineWidth = ct / c, e.setLineDash(st.map((e) => e / c)), e.strokeRect(i, a, o, s), e.setLineDash([]);
1518
+ let l = dt / c, u = ft / c, d = pt / c;
1519
+ e.font = `${l}px system-ui, sans-serif`;
1520
+ let f = `${Math.round(o)} × ${Math.round(s)}`, p = e.measureText(f).width + u * 2, m = l + d * 2, h = i + o + ht / c, g = a + s + ht / c;
1521
+ e.fillStyle = lt, e.beginPath(), e.roundRect(h, g, p, m, mt / c), e.fill(), e.fillStyle = ut, e.textBaseline = "middle", e.fillText(f, h + u, g + m / 2);
1522
+ }
1523
+ //#endregion
1524
+ //#region src/canvas/findHighlight.ts
1525
+ var _t = {
1526
+ matchColor: "#f59e0b",
1527
+ currentColor: "#38bdf8",
1528
+ currentFill: "rgba(56, 189, 248, 0.12)",
1529
+ lineWidth: 2
1530
+ };
1531
+ function vt(e, t, n, r) {
1532
+ if (!n.doc || !t.store.ui.find.open) return;
1533
+ let i = {
1534
+ ..._t,
1535
+ ...r
1536
+ }, a = t.listFindMatches();
1537
+ if (a.length === 0) return;
1538
+ let o = t.findCursor;
1539
+ for (let r = 0; r < a.length; r += 1) {
1540
+ let s = t.layerBoxAt(a[r].path);
1541
+ if (!s) continue;
1542
+ let c = r === o;
1543
+ 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);
1544
+ }
1545
+ }
1546
+ //#endregion
1547
+ //#region src/canvas/gizmo.ts
1548
+ var yt = {
1549
+ selectionColor: "#2563eb",
1550
+ hoverColor: "rgba(37, 99, 235, 0.55)",
1551
+ selectionWidth: 2,
1552
+ handleSize: 8,
1553
+ handleFill: "#ffffff"
1554
+ };
1555
+ function bt(e, t) {
1556
+ return r(e, t)?.visible === !1;
1557
+ }
1558
+ function xt(e, n, r, i) {
1559
+ let a = {
1560
+ ...yt,
1561
+ ...i
1562
+ }, { selection: o, hovered: s } = n.store.ui, c = r.doc;
1563
+ if (c) {
1564
+ if (s && !t(s, o) && !bt(c, s) && !n.isLocked(s)) {
1565
+ let t = n.layerBoxAt(s);
1566
+ t && (e.strokeStyle = a.hoverColor, e.lineWidth = a.selectionWidth / 2 / r.viewport.zoom, e.strokeRect(t.x, t.y, t.width, t.height));
1567
+ }
1568
+ if (o && !bt(c, o)) {
1569
+ let t = n.layerBoxAt(o);
1570
+ t && (e.strokeStyle = a.selectionColor, e.lineWidth = a.selectionWidth / r.viewport.zoom, e.strokeRect(t.x, t.y, t.width, t.height), St(e, n, o, t, r.viewport.zoom, a));
1571
+ }
1572
+ }
1573
+ }
1574
+ function St(e, t, n, r, i, a) {
1575
+ let o = t.resizeHandlesAt(n);
1576
+ if (o.length === 0) return;
1577
+ let s = a.handleSize / i, c = s / 2;
1578
+ e.fillStyle = a.handleFill, e.strokeStyle = a.selectionColor, e.lineWidth = a.selectionWidth / i;
1579
+ for (let t of o) {
1580
+ let n = de(r, t);
1581
+ e.fillRect(n.x - c, n.y - c, s, s), e.strokeRect(n.x - c, n.y - c, s, s);
1582
+ }
1583
+ }
1584
+ function Ct(e, t, n) {
1585
+ return (r) => {
1586
+ if (!t) return;
1587
+ t.setTransform(1, 0, 0, 1, 0, 0), t.clearRect(0, 0, t.canvas.width, t.canvas.height);
1588
+ let i = r.dpr * r.viewport.zoom;
1589
+ t.setTransform(i, 0, 0, i, -r.viewport.x * i, -r.viewport.y * i), xt(t, e, r, n);
1590
+ };
1591
+ }
1592
+ //#endregion
1593
+ //#region src/canvas/scheduler.ts
1594
+ function wt() {
1595
+ return (e) => {
1596
+ let t = window.requestAnimationFrame(() => e());
1597
+ return () => window.cancelAnimationFrame(t);
1598
+ };
1599
+ }
1600
+ //#endregion
1601
+ export { be as _, gt as a, qe as c, $ as d, Q as f, Ee as g, De as h, vt as i, We as l, Ie as m, Ct as n, it as o, ze as p, xt as r, Qe as s, wt as t, He as u };