@hankchen/canvas-editor-vue 2.0.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hankchen/canvas-editor-vue",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
4
4
  "license": "MIT",
5
5
  "description": "Vue 3 薄绑定:响应式桥、composables、画布表面组件、textarea 文本编辑 overlay、schema 驱动属性面板注册表",
6
6
  "type": "module",
@@ -36,6 +36,7 @@
36
36
  "default": "./dist/shared.js"
37
37
  },
38
38
  "./panel-theme.css": "./dist/panel-theme.css",
39
+ "./theme.css": "./dist/theme.css",
39
40
  "./style.css": "./dist/style.css",
40
41
  "./package.json": "./package.json"
41
42
  },
@@ -58,7 +59,7 @@
58
59
  },
59
60
  "dependencies": {
60
61
  "@lucide/vue": "^1.48.0",
61
- "@hankchen/canvas-editor": "2.0.0"
62
+ "@hankchen/canvas-editor": "2.2.0"
62
63
  },
63
64
  "peerDependencies": {
64
65
  "vue": "^3.5.0"
@@ -73,7 +74,7 @@
73
74
  "vue-tsc": "^3.3.11"
74
75
  },
75
76
  "scripts": {
76
- "build": "vite build && cp src/panel-theme.css dist/panel-theme.css",
77
+ "build": "vite build && cp src/panel-theme.css dist/panel-theme.css && cp src/theme.css dist/theme.css",
77
78
  "test": "vitest run",
78
79
  "typecheck": "vue-tsc --noEmit -p tsconfig.json"
79
80
  }
@@ -1,450 +0,0 @@
1
- import { n as e, p as t } from "./useTransientFeedback-BN_O7V2w.js";
2
- import { Fragment as n, createCommentVNode as r, createElementBlock as i, createElementVNode as a, createTextVNode as o, defineComponent as s, mergeProps as c, nextTick as l, normalizeClass as u, normalizeStyle as d, onScopeDispose as f, openBlock as p, ref as m, renderList as h, renderSlot as g, shallowRef as ee, toDisplayString as _, unref as v, watch as y, withModifiers as te } from "vue";
3
- //#region src/shared/useDropdownMenu.ts
4
- function b(e) {
5
- return e !== "separator" && "kind" in e && e.kind === "submenu";
6
- }
7
- function x(e) {
8
- let t = m(!1);
9
- function n(n) {
10
- let r = e.container.value, i = n.target;
11
- r !== null && i instanceof Node && r.contains(i) || (t.value = !1);
12
- }
13
- function r(e) {
14
- e.key === "Escape" && (t.value = !1);
15
- }
16
- function i() {
17
- window.removeEventListener("pointerdown", n), window.removeEventListener("keydown", r);
18
- }
19
- return y(t, (e) => {
20
- e ? (window.addEventListener("pointerdown", n), window.addEventListener("keydown", r)) : i();
21
- }), f(i, !0), {
22
- open: t,
23
- toggle: () => {
24
- t.value = !t.value;
25
- },
26
- openMenu: () => {
27
- t.value = !0;
28
- },
29
- closeMenu: () => {
30
- t.value = !1;
31
- }
32
- };
33
- }
34
- function S(e, t, n) {
35
- let r = e.length;
36
- if (r === 0) return -1;
37
- if (n === "Home" || n === "End") {
38
- for (let t = 0; t < r; t++) {
39
- let i = n === "Home" ? t : r - 1 - t;
40
- if (e[i]) return i;
41
- }
42
- return -1;
43
- }
44
- let i = n === "ArrowDown" ? 1 : -1, a = t === -1 ? i === 1 ? -1 : r : t;
45
- for (let t = 0; t < r; t++) if (a = (a + i + r) % r, e[a]) return a;
46
- return -1;
47
- }
48
- function C(e, t) {
49
- return t.type === "close" || t.target === void 0 ? null : t.type === "open" ? t.target : e === t.target ? null : t.target;
50
- }
51
- function ne(e) {
52
- let { anchor: t, flyoutWidth: n, flyoutHeight: r, viewportWidth: i, viewportHeight: a } = e, o = e.gap ?? 6, s = e.margin ?? 2, c = n > 0 && t.right + o + n > i - s ? "left" : "right", l = c === "right" ? t.right + o : t.left - o - n;
53
- n > 0 && (l = Math.max(s, Math.min(l, i - s - n)));
54
- let u = t.top;
55
- return r > 0 && (u = Math.max(s, Math.min(u, a - s - r))), {
56
- left: l,
57
- top: u,
58
- side: c
59
- };
60
- }
61
- function re(e) {
62
- return e === "ArrowDown" || e === "ArrowUp" || e === "Home" || e === "End" ? {
63
- type: "move",
64
- key: e
65
- } : e === "ArrowLeft" || e === "Escape" ? { type: "close" } : e === "Enter" || e === " " ? { type: "activate" } : e === "Tab" ? { type: "close-menu" } : { type: "none" };
66
- }
67
- function w(e, t) {
68
- return e.find((e) => !e.hasAttribute("disabled")) ?? t;
69
- }
70
- function T(e) {
71
- return e?.closest("[data-dropdown-submenu-host]")?.querySelector("[data-dropdown-submenu-arrow]") ?? null;
72
- }
73
- function E(e) {
74
- return e;
75
- }
76
- //#endregion
77
- //#region src/shared/DropdownMenu.vue?vue&type=script&setup=true&lang.ts
78
- var D = ["aria-expanded", "title"], ie = ["aria-label"], ae = {
79
- key: 0,
80
- class: "cn-dropdown__separator",
81
- role: "separator",
82
- "data-dropdown-separator": "",
83
- "aria-hidden": "true"
84
- }, oe = {
85
- key: 1,
86
- class: "cn-dropdown__submenu-host",
87
- "data-dropdown-submenu-host": ""
88
- }, se = [
89
- "disabled",
90
- "title",
91
- "onClick"
92
- ], ce = { class: "cn-dropdown__item-label" }, le = {
93
- key: 0,
94
- class: "cn-dropdown__shortcut"
95
- }, ue = [
96
- "disabled",
97
- "title",
98
- "aria-expanded",
99
- "onClick",
100
- "onMouseenter"
101
- ], de = ["aria-label"], fe = {
102
- key: 0,
103
- class: "cn-dropdown__separator",
104
- role: "separator",
105
- "data-dropdown-submenu-separator": "",
106
- "aria-hidden": "true"
107
- }, pe = [
108
- "disabled",
109
- "title",
110
- "onClick"
111
- ], me = { class: "cn-dropdown__item-label" }, he = {
112
- key: 0,
113
- class: "cn-dropdown__shortcut"
114
- }, ge = [
115
- "disabled",
116
- "title",
117
- "onClick"
118
- ], _e = { class: "cn-dropdown__item-label" }, ve = {
119
- key: 0,
120
- class: "cn-dropdown__shortcut"
121
- }, O = 6, k = 2, A = /*#__PURE__*/ t(/* @__PURE__ */ s({
122
- __name: "DropdownMenu",
123
- props: {
124
- label: {},
125
- items: {},
126
- title: {},
127
- direction: { default: "down" }
128
- },
129
- emits: ["closed"],
130
- setup(t, { emit: s }) {
131
- let f = t, A = s, j = m(null), M = m(null), N = m(null), { open: P, toggle: F, closeMenu: I } = x({ container: j }), L = ee(null), R = m({
132
- left: 0,
133
- top: 0,
134
- side: "right"
135
- });
136
- y(P, (e) => {
137
- e || (L.value = null, A("closed"));
138
- });
139
- let z = m({
140
- left: 0,
141
- edge: "top",
142
- offset: 0
143
- });
144
- function B() {
145
- E(M.value)?.focus();
146
- }
147
- function V(e) {
148
- M.value = e instanceof HTMLElement ? e : null;
149
- }
150
- async function H() {
151
- if (await l(), !P.value) return;
152
- let e = N.value;
153
- e !== null && w(K(), e).focus();
154
- }
155
- function U() {
156
- return f.items.filter((e) => e !== "separator");
157
- }
158
- function ye() {
159
- return U().filter(b);
160
- }
161
- function be() {
162
- return Array.from(N.value?.querySelectorAll("[data-dropdown-submenu-host]") ?? []);
163
- }
164
- function W() {
165
- return N.value?.querySelector("[data-dropdown-submenu]") ?? null;
166
- }
167
- function G() {
168
- return Array.from(W()?.querySelectorAll("[data-dropdown-submenu-item]") ?? []);
169
- }
170
- function K() {
171
- return Array.from(N.value?.querySelectorAll("[data-dropdown-item]") ?? []);
172
- }
173
- function q(e) {
174
- e.run(), (b(e) || e.keepsOpen !== !0) && (I(), B());
175
- }
176
- function xe(e) {
177
- let t = N.value;
178
- if (t === null) return;
179
- let n = K(), r = S(n.map((e) => !e.hasAttribute("disabled")), document.activeElement instanceof HTMLElement ? n.indexOf(document.activeElement) : -1, e);
180
- if (r === -1) {
181
- t.focus();
182
- return;
183
- }
184
- n[r]?.focus();
185
- }
186
- function Se(e) {
187
- let t = U()[K().indexOf(e)];
188
- t !== void 0 && !t.disabled && q(t);
189
- }
190
- function Ce(t) {
191
- let n = t.key, r = t.target;
192
- if (r instanceof HTMLElement && r.matches("[data-dropdown-submenu-item]")) {
193
- let e = re(n);
194
- if (e.type === "move") {
195
- t.preventDefault(), Y(e.key);
196
- return;
197
- }
198
- if (e.type === "close") {
199
- t.preventDefault(), J();
200
- return;
201
- }
202
- if (e.type === "activate") {
203
- t.preventDefault(), Te(r);
204
- return;
205
- }
206
- if (e.type === "close-menu") {
207
- I(), B();
208
- return;
209
- }
210
- return;
211
- }
212
- if (n === "Escape") {
213
- if (L.value !== null) {
214
- J();
215
- return;
216
- }
217
- I(), B();
218
- return;
219
- }
220
- if (n === "Tab") {
221
- if (r instanceof HTMLElement && !r.matches("[data-dropdown-item]") && e(r)) return;
222
- I(), B();
223
- return;
224
- }
225
- if (n === "Enter" || n === " ") {
226
- r instanceof HTMLElement && r.matches("[data-dropdown-item]") && (t.preventDefault(), Se(r));
227
- return;
228
- }
229
- if (n === "ArrowDown" || n === "ArrowUp" || n === "Home" || n === "End") {
230
- if (r instanceof HTMLElement && !r.matches("[data-dropdown-item]") && e(r)) return;
231
- t.preventDefault(), xe(n);
232
- return;
233
- }
234
- if (n === "ArrowRight") {
235
- let e = r instanceof HTMLElement ? r.closest("[data-dropdown-submenu-host]") : null;
236
- if (e !== null) {
237
- let n = ye()[be().indexOf(e)];
238
- n !== void 0 && (t.preventDefault(), we(n, e));
239
- }
240
- }
241
- }
242
- async function we(e, t) {
243
- if (e.disabled === !0 || (L.value = C(L.value, {
244
- type: "open",
245
- target: e
246
- }), await $(t.querySelector("[data-dropdown-submenu-arrow]")), L.value !== e || !P.value)) return;
247
- let n = W();
248
- n !== null && w(G(), n).focus();
249
- }
250
- function J() {
251
- let e = T(document.activeElement instanceof HTMLElement ? document.activeElement : null);
252
- L.value = null, e?.focus();
253
- }
254
- function Y(e) {
255
- let t = W();
256
- if (t === null) return;
257
- let n = G(), r = S(n.map((e) => !e.hasAttribute("disabled")), document.activeElement instanceof HTMLElement ? n.indexOf(document.activeElement) : -1, e);
258
- if (r === -1) {
259
- t.focus();
260
- return;
261
- }
262
- n[r]?.focus();
263
- }
264
- function Te(e) {
265
- let t = L.value;
266
- if (t === null) return;
267
- let n = Array.from(W()?.querySelectorAll("[data-dropdown-submenu-item]") ?? []), r = t.children.filter((e) => e !== "separator")[n.indexOf(e)];
268
- r !== void 0 && !r.disabled && q(r);
269
- }
270
- function X(e) {
271
- if (e.key === "ArrowDown") {
272
- if (e.preventDefault(), !P.value) {
273
- Z();
274
- return;
275
- }
276
- H();
277
- }
278
- }
279
- async function Z() {
280
- if (!P.value) {
281
- let e = M.value?.getBoundingClientRect();
282
- e && (z.value = f.direction === "up" ? {
283
- left: e.left,
284
- edge: "bottom",
285
- offset: window.innerHeight - e.top + O
286
- } : {
287
- left: e.left,
288
- edge: "top",
289
- offset: e.bottom + O
290
- });
291
- }
292
- if (F(), !P.value) {
293
- B();
294
- return;
295
- }
296
- await l();
297
- let e = N.value?.getBoundingClientRect();
298
- if (!e) return;
299
- let t = z.value;
300
- z.value = {
301
- left: Math.max(k, Math.min(t.left, window.innerWidth - e.width - k)),
302
- edge: t.edge,
303
- offset: Math.max(k, Math.min(t.offset, window.innerHeight - e.height - k))
304
- }, H();
305
- }
306
- function Q(e) {
307
- return e.currentTarget instanceof HTMLElement ? e.currentTarget : null;
308
- }
309
- async function $(e) {
310
- let t = L.value;
311
- if (t === null || e === null) return;
312
- let n = e.getBoundingClientRect();
313
- if (R.value = {
314
- left: n.right + 6,
315
- top: n.top,
316
- side: "right"
317
- }, await l(), L.value !== t) return;
318
- let r = W(), i = r?.getBoundingClientRect();
319
- r !== null && i !== void 0 && i.width !== 0 && (R.value = ne({
320
- anchor: {
321
- top: n.top,
322
- bottom: n.bottom,
323
- left: n.left,
324
- right: n.right
325
- },
326
- flyoutWidth: i.width,
327
- flyoutHeight: i.height,
328
- viewportWidth: window.innerWidth,
329
- viewportHeight: window.innerHeight
330
- }));
331
- }
332
- function Ee(e, t) {
333
- t.disabled !== !0 && (L.value = C(L.value, {
334
- type: "open",
335
- target: t
336
- }), $(Q(e)));
337
- }
338
- function De(e, t) {
339
- t.disabled !== !0 && (L.value = C(L.value, {
340
- type: "toggle",
341
- target: t
342
- }), $(Q(e)));
343
- }
344
- function Oe() {
345
- L.value = null;
346
- }
347
- return (e, s) => (p(), i("div", {
348
- ref_key: "container",
349
- ref: j,
350
- class: "cn-dropdown",
351
- onMouseleave: Oe
352
- }, [g(e.$slots, "trigger", {
353
- open: v(P),
354
- toggle: Z,
355
- closeMenu: v(I),
356
- triggerRef: V,
357
- onKeydown: X
358
- }, () => [a("button", {
359
- ref: V,
360
- type: "button",
361
- class: "cn-dropdown__trigger",
362
- "data-dropdown-trigger": "",
363
- "aria-haspopup": "menu",
364
- "aria-expanded": v(P),
365
- title: t.title ?? t.label,
366
- onClick: s[0] ||= (e) => Z(),
367
- onKeydown: X
368
- }, [o(_(t.label) + " ", 1), s[2] ||= a("span", {
369
- class: "cn-dropdown__caret",
370
- "aria-hidden": "true"
371
- }, "▾", -1)], 40, D)], !0), v(P) ? (p(), i("div", {
372
- key: 0,
373
- ref_key: "menuEl",
374
- ref: N,
375
- class: "cn-dropdown__menu",
376
- role: "menu",
377
- "aria-label": t.label,
378
- "data-dropdown-menu": "",
379
- tabindex: "-1",
380
- style: d(z.value.edge === "top" ? {
381
- left: `${z.value.left}px`,
382
- top: `${z.value.offset}px`
383
- } : {
384
- left: `${z.value.left}px`,
385
- bottom: `${z.value.offset}px`
386
- }),
387
- onKeydown: s[1] ||= te((e) => Ce(e), ["stop"])
388
- }, [(p(!0), i(n, null, h(t.items, (e, t) => (p(), i(n, { key: t }, [e === "separator" ? (p(), i("div", ae)) : v(b)(e) ? (p(), i("div", oe, [
389
- a("button", c({
390
- type: "button",
391
- role: "menuitem",
392
- class: "cn-dropdown__item cn-dropdown__submenu-main",
393
- "data-dropdown-item": "",
394
- tabindex: "-1",
395
- disabled: e.disabled,
396
- title: e.title
397
- }, { ref_for: !0 }, e.dataAttrs, { onClick: (t) => q(e) }), [a("span", ce, _(e.label), 1), e.shortcut ? (p(), i("span", le, _(e.shortcut), 1)) : r("", !0)], 16, se),
398
- a("button", {
399
- type: "button",
400
- class: "cn-dropdown__submenu-arrow",
401
- "data-dropdown-submenu-arrow": "",
402
- tabindex: "-1",
403
- disabled: e.disabled,
404
- title: e.title,
405
- "aria-haspopup": "menu",
406
- "aria-expanded": L.value === e,
407
- onClick: (t) => De(t, e),
408
- onMouseenter: (t) => Ee(t, e)
409
- }, [...s[3] ||= [a("span", { "aria-hidden": "true" }, "▸", -1)]], 40, ue),
410
- L.value === e ? (p(), i("div", {
411
- key: 0,
412
- class: u(["cn-dropdown__submenu", { "cn-dropdown__submenu--left": R.value.side === "left" }]),
413
- role: "menu",
414
- "aria-label": e.label,
415
- "data-dropdown-submenu": "",
416
- tabindex: "-1",
417
- style: d({
418
- left: `${R.value.left}px`,
419
- top: `${R.value.top}px`
420
- })
421
- }, [(p(!0), i(n, null, h(e.children, (e, t) => (p(), i(n, { key: t }, [e === "separator" ? (p(), i("div", fe)) : (p(), i("button", c({
422
- key: 1,
423
- type: "button",
424
- role: "menuitem",
425
- class: "cn-dropdown__item",
426
- "data-dropdown-submenu-item": "",
427
- tabindex: "-1",
428
- disabled: e.disabled,
429
- title: e.title
430
- }, { ref_for: !0 }, e.dataAttrs, { onClick: (t) => q(e) }), [a("span", me, _(e.label), 1), e.shortcut ? (p(), i("span", he, _(e.shortcut), 1)) : r("", !0)], 16, pe))], 64))), 128))], 14, de)) : r("", !0)
431
- ])) : (p(), i("button", c({
432
- key: 2,
433
- type: "button",
434
- role: "menuitem",
435
- class: "cn-dropdown__item",
436
- "data-dropdown-item": "",
437
- tabindex: "-1",
438
- disabled: e.disabled,
439
- title: e.title
440
- }, { ref_for: !0 }, e.dataAttrs, { onClick: (t) => q(e) }), [a("span", _e, _(e.label), 1), e.shortcut ? (p(), i("span", ve, _(e.shortcut), 1)) : r("", !0)], 16, ge))], 64))), 128)), g(e.$slots, "body", {
441
- open: v(P),
442
- toggle: Z,
443
- closeMenu: v(I),
444
- triggerRef: V,
445
- onKeydown: X
446
- }, void 0, !0)], 44, ie)) : r("", !0)], 544));
447
- }
448
- }), [["__scopeId", "data-v-f39579b0"]]);
449
- //#endregion
450
- export { x as n, A as t };
@@ -1,76 +0,0 @@
1
- //#region ../canvas-editor/src/shared/layerPath.ts
2
- function e(e) {
3
- return typeof e == "number" && Number.isSafeInteger(e) && e >= 0;
4
- }
5
- function t(t) {
6
- if (!Array.isArray(t) || t.length < 2 || t[0] !== "layers" || !e(t[1])) return !1;
7
- let n = [
8
- "rows",
9
- "cells",
10
- "content"
11
- ], r = 0, i = 2;
12
- for (; i < t.length;) {
13
- let a = t[i];
14
- if (r === 0 && a === "template") {
15
- if (i === t.length - 1) return !0;
16
- if (t[i + 1] !== "cells") return !1;
17
- r = 1, i += 1;
18
- continue;
19
- }
20
- let o = n[r];
21
- if (a !== o) return !1;
22
- if (o === "content") return i === t.length - 1;
23
- if (!e(t[i + 1])) return !1;
24
- r += 1, i += 2;
25
- }
26
- return !0;
27
- }
28
- function n(e) {
29
- return e.includes("template");
30
- }
31
- function r(e) {
32
- return t(e) && e.length === 2;
33
- }
34
- function i(e, t) {
35
- if (e === t) return !0;
36
- if (!e || !t || e.length !== t.length) return !1;
37
- for (let n = 0; n < e.length; n += 1) if (e[n] !== t[n]) return !1;
38
- return !0;
39
- }
40
- function a(e, t) {
41
- if (e.length < t.length) return !1;
42
- for (let n = 0; n < t.length; n += 1) if (e[n] !== t[n]) return !1;
43
- return !0;
44
- }
45
- function o(e, t) {
46
- return t.some((t) => a(e, t));
47
- }
48
- function s(e, t) {
49
- let n = e, r = 0;
50
- for (; r < t.length;) {
51
- let e = n;
52
- if (typeof e != "object" || !e) return null;
53
- let i = t[r];
54
- if (typeof i != "string" || (n = e[i], n == null)) return null;
55
- if (i === "template") {
56
- r += 1;
57
- continue;
58
- }
59
- if (r + 1 >= t.length) break;
60
- let a = n, o = t[r + 1];
61
- if (!Array.isArray(a) || typeof o != "number" || (n = a[o], n == null)) return null;
62
- r += 2;
63
- }
64
- return n;
65
- }
66
- function c(e, n) {
67
- if (!t(n)) return null;
68
- let r = s(e, n);
69
- return typeof r != "object" || !r || !("type" in r) ? null : r;
70
- }
71
- function l(e, t) {
72
- let n = t[1];
73
- return typeof n != "number" || !Number.isSafeInteger(n) || n < 0 ? null : e.layers[n] ?? null;
74
- }
75
- //#endregion
76
- export { c as a, i, r as n, l as o, n as r, o as t };