@hfd-sdk/keyboard-kit 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/ai-lighting/engine.d.ts +9 -0
- package/dist/ai-lighting/index.d.ts +6 -0
- package/dist/ai-lighting/index.es.js +946 -0
- package/dist/ai-lighting/params.d.ts +5 -0
- package/dist/ai-lighting/preset-store.d.ts +17 -0
- package/dist/ai-lighting/validate.d.ts +3 -0
- package/dist/index.d.ts +2 -0
- package/dist/keyboard-kit.es.js +10 -0
- package/dist/runtime/index.d.ts +3 -0
- package/dist/runtime-core.es.js +5484 -0
- package/dist/runtime.es.js +44 -0
- package/dist/shared/composables/useKeySampler.d.ts +8 -0
- package/dist/shared/hardware/assert-hfd-device.d.ts +3 -0
- package/dist/shared/hardware/build-music-data.d.ts +4 -0
- package/dist/shared/serialize.d.ts +4 -0
- package/dist/shared/types.d.ts +123 -0
- package/package.json +58 -0
|
@@ -0,0 +1,946 @@
|
|
|
1
|
+
import { c as Y, o as xe, w as ae, t as F, r as L, d as be, a as He, b as ee, e as te, f as X, g as ge, n as se, u as $, F as ve, h as fe, i as ke, j as oe, s as Ce, k as Ee, l as Me, m as _e, p as he, q as Ve, v as Ne, x as Pe } from "../runtime-core.es.js";
|
|
2
|
+
import { serializePreset as Ke } from "../runtime.es.js";
|
|
3
|
+
import { deserializePreset as Pt } from "../runtime.es.js";
|
|
4
|
+
const me = 40, De = 0.1, qe = 3;
|
|
5
|
+
function J(e) {
|
|
6
|
+
return Math.round(e * 100) / 100;
|
|
7
|
+
}
|
|
8
|
+
function ye(e) {
|
|
9
|
+
return {
|
|
10
|
+
x: J(e.x),
|
|
11
|
+
y: J(e.y),
|
|
12
|
+
width: J(e.width),
|
|
13
|
+
height: J(e.height),
|
|
14
|
+
rotation: J(e.rotation)
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const Be = {
|
|
18
|
+
"scale-se": { x: 1, y: 1 },
|
|
19
|
+
"scale-sw": { x: -1, y: 1 },
|
|
20
|
+
"scale-ne": { x: 1, y: -1 },
|
|
21
|
+
"scale-nw": { x: -1, y: -1 }
|
|
22
|
+
}, Fe = {
|
|
23
|
+
"resize-e": { x: -1, y: 0 },
|
|
24
|
+
"resize-w": { x: 1, y: 0 },
|
|
25
|
+
"resize-n": { x: 0, y: 1 },
|
|
26
|
+
"resize-s": { x: 0, y: -1 }
|
|
27
|
+
}, Oe = {
|
|
28
|
+
"scale-se": { x: -1, y: -1 },
|
|
29
|
+
"scale-sw": { x: 1, y: -1 },
|
|
30
|
+
"scale-ne": { x: -1, y: 1 },
|
|
31
|
+
"scale-nw": { x: 1, y: 1 }
|
|
32
|
+
};
|
|
33
|
+
function We(e) {
|
|
34
|
+
const t = L({ x: 0, y: 0 }), a = L(1), o = L(1), n = L(0), c = L(!0), k = L(1), i = L({ width: 0, height: 0 }), f = Y(() => c.value ? a.value : o.value), m = Y(() => ({
|
|
35
|
+
left: `${t.value.x}px`,
|
|
36
|
+
top: `${t.value.y}px`,
|
|
37
|
+
transform: `translate(-50%, -50%) scale(${a.value}, ${f.value}) rotate(${n.value}deg)`,
|
|
38
|
+
transformOrigin: "center center"
|
|
39
|
+
}));
|
|
40
|
+
let d = null;
|
|
41
|
+
function w() {
|
|
42
|
+
return {
|
|
43
|
+
width: F(e.canvasWidth),
|
|
44
|
+
height: F(e.canvasHeight)
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function y(r, s) {
|
|
48
|
+
const { width: l, height: v } = w();
|
|
49
|
+
return !r || !s ? 1 : Math.min((l - me * 2) / r, (v - me * 2) / s, 1);
|
|
50
|
+
}
|
|
51
|
+
function x(r) {
|
|
52
|
+
return Math.min(qe, Math.max(De, r));
|
|
53
|
+
}
|
|
54
|
+
function b(r, s) {
|
|
55
|
+
const { width: l, height: v } = w(), h = i.value.width * a.value / 2, g = i.value.height * f.value / 2;
|
|
56
|
+
return {
|
|
57
|
+
x: Math.max(h, Math.min(l - h, r)),
|
|
58
|
+
y: Math.max(g, Math.min(v - g, s))
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function E() {
|
|
62
|
+
return ye({
|
|
63
|
+
x: t.value.x,
|
|
64
|
+
y: t.value.y,
|
|
65
|
+
width: i.value.width * a.value,
|
|
66
|
+
height: i.value.height * f.value,
|
|
67
|
+
rotation: n.value
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
function A(r) {
|
|
71
|
+
if (!i.value.width || !i.value.height) return;
|
|
72
|
+
const s = ye(r), l = x(s.width / i.value.width), v = x(s.height / i.value.height);
|
|
73
|
+
a.value = l, o.value = v, c.value = Math.abs(l - v) < 1e-3, n.value = s.rotation, t.value = b(s.x, s.y);
|
|
74
|
+
}
|
|
75
|
+
function H() {
|
|
76
|
+
var r;
|
|
77
|
+
(r = F(e.onLayoutChange)) == null || r(E());
|
|
78
|
+
}
|
|
79
|
+
function M() {
|
|
80
|
+
H();
|
|
81
|
+
}
|
|
82
|
+
async function K(r, s = !1) {
|
|
83
|
+
if (!r) return;
|
|
84
|
+
if (i.value = {
|
|
85
|
+
width: r.offsetWidth,
|
|
86
|
+
height: r.offsetHeight
|
|
87
|
+
}, !s) {
|
|
88
|
+
const g = F(e.initialLayout);
|
|
89
|
+
if (g) {
|
|
90
|
+
A(g);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const l = y(i.value.width, i.value.height);
|
|
95
|
+
k.value = l, a.value = l, o.value = l, n.value = 0, c.value = !0;
|
|
96
|
+
const { width: v, height: h } = w();
|
|
97
|
+
t.value = { x: v / 2, y: h / 2 };
|
|
98
|
+
}
|
|
99
|
+
async function D(r) {
|
|
100
|
+
await K(r, !0), H();
|
|
101
|
+
}
|
|
102
|
+
function p() {
|
|
103
|
+
c.value = !c.value, c.value && (o.value = a.value);
|
|
104
|
+
}
|
|
105
|
+
function S(r, s, l, v) {
|
|
106
|
+
const h = -n.value * Math.PI / 180, g = r - l, P = s - v;
|
|
107
|
+
return {
|
|
108
|
+
x: g * Math.cos(h) - P * Math.sin(h),
|
|
109
|
+
y: g * Math.sin(h) + P * Math.cos(h)
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function V(r, s) {
|
|
113
|
+
var h;
|
|
114
|
+
const l = (h = e.getOverlayEl) == null ? void 0 : h.call(e);
|
|
115
|
+
if (!l) return { x: r, y: s };
|
|
116
|
+
const v = l.getBoundingClientRect();
|
|
117
|
+
return { x: r - v.left, y: s - v.top };
|
|
118
|
+
}
|
|
119
|
+
function B(r, s, l, v) {
|
|
120
|
+
return Math.atan2(s - v, r - l) * 180 / Math.PI;
|
|
121
|
+
}
|
|
122
|
+
function C(r, s, l, v, h) {
|
|
123
|
+
const g = h * Math.PI / 180;
|
|
124
|
+
return {
|
|
125
|
+
x: r + l * Math.cos(g) - v * Math.sin(g),
|
|
126
|
+
y: s + l * Math.sin(g) + v * Math.cos(g)
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function O(r, s, l, v, h) {
|
|
130
|
+
const g = [
|
|
131
|
+
C(r, s, -l, -v, h),
|
|
132
|
+
C(r, s, l, -v, h),
|
|
133
|
+
C(r, s, -l, v, h),
|
|
134
|
+
C(r, s, l, v, h)
|
|
135
|
+
];
|
|
136
|
+
return {
|
|
137
|
+
minX: Math.min(...g.map((P) => P.x)),
|
|
138
|
+
minY: Math.min(...g.map((P) => P.y)),
|
|
139
|
+
maxX: Math.max(...g.map((P) => P.x)),
|
|
140
|
+
maxY: Math.max(...g.map((P) => P.y))
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function j(r, s, l, v, h, g, P) {
|
|
144
|
+
const R = g * l / 2, _ = P * v / 2, T = C(r.x, r.y, -s.x * R, -s.y * _, h), z = O(T.x, T.y, R, _, h), { width: q, height: N } = w();
|
|
145
|
+
return z.minX >= 0 && z.minY >= 0 && z.maxX <= q && z.maxY <= N;
|
|
146
|
+
}
|
|
147
|
+
function le(r, s, l, v, h, g, P, R, _) {
|
|
148
|
+
if (j(r, s, h, g, P, R, _))
|
|
149
|
+
return { scale: h, scaleY: g };
|
|
150
|
+
if (!j(r, s, l, v, P, R, _))
|
|
151
|
+
return { scale: l, scaleY: v };
|
|
152
|
+
let T = 0, z = 1;
|
|
153
|
+
for (let q = 0; q < 20; q++) {
|
|
154
|
+
const N = (T + z) / 2, G = l + N * (h - l), Z = v + N * (g - v);
|
|
155
|
+
j(r, s, G, Z, P, R, _) ? T = N : z = N;
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
scale: l + T * (h - l),
|
|
159
|
+
scaleY: v + T * (g - v)
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function ne(r, s, l, v, h, g, P, R) {
|
|
163
|
+
const _ = i.value.width || 1, T = i.value.height || 1, z = _ * g / 2, q = T * P / 2, N = C(
|
|
164
|
+
v,
|
|
165
|
+
h,
|
|
166
|
+
r.x * z,
|
|
167
|
+
r.y * q,
|
|
168
|
+
R
|
|
169
|
+
), G = le(
|
|
170
|
+
N,
|
|
171
|
+
r,
|
|
172
|
+
g,
|
|
173
|
+
P,
|
|
174
|
+
s,
|
|
175
|
+
l,
|
|
176
|
+
R,
|
|
177
|
+
_,
|
|
178
|
+
T
|
|
179
|
+
), Z = _ * G.scale / 2, Re = T * G.scaleY / 2, Ae = C(
|
|
180
|
+
N.x,
|
|
181
|
+
N.y,
|
|
182
|
+
-r.x * Z,
|
|
183
|
+
-r.y * Re,
|
|
184
|
+
R
|
|
185
|
+
);
|
|
186
|
+
a.value = G.scale, o.value = G.scaleY, t.value = Ae;
|
|
187
|
+
}
|
|
188
|
+
function ce(r, s, l, v, h, g, P) {
|
|
189
|
+
const R = Be[r], _ = Oe[r], T = i.value.width || 1, z = i.value.height || 1;
|
|
190
|
+
let q, N;
|
|
191
|
+
if (c.value) {
|
|
192
|
+
const G = Math.max(T, z), Z = (s.x * R.x + s.y * R.y) / 2;
|
|
193
|
+
q = x(h + Z / G), N = q;
|
|
194
|
+
} else
|
|
195
|
+
q = x(h + s.x * R.x / T), N = x(g + s.y * R.y / z);
|
|
196
|
+
ne(_, q, N, l, v, h, g, P);
|
|
197
|
+
}
|
|
198
|
+
function ue(r, s, l, v, h, g, P) {
|
|
199
|
+
const R = i.value.width || 1, _ = i.value.height || 1;
|
|
200
|
+
let T = h, z = g;
|
|
201
|
+
r === "resize-e" ? (T = x(h + s.x / R), c.value && (z = T)) : r === "resize-w" ? (T = x(h - s.x / R), c.value && (z = T)) : r === "resize-s" ? (z = x(g + s.y / _), c.value && (T = z)) : r === "resize-n" && (z = x(g - s.y / _), c.value && (T = z)), ne(
|
|
202
|
+
Fe[r],
|
|
203
|
+
T,
|
|
204
|
+
z,
|
|
205
|
+
l,
|
|
206
|
+
v,
|
|
207
|
+
h,
|
|
208
|
+
g,
|
|
209
|
+
P
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
function U(r, s) {
|
|
213
|
+
s.preventDefault(), s.stopPropagation();
|
|
214
|
+
const l = V(s.clientX, s.clientY), v = B(l.x, l.y, t.value.x, t.value.y);
|
|
215
|
+
d = {
|
|
216
|
+
mode: r,
|
|
217
|
+
startLocalX: l.x,
|
|
218
|
+
startLocalY: l.y,
|
|
219
|
+
startPosX: t.value.x,
|
|
220
|
+
startPosY: t.value.y,
|
|
221
|
+
startScale: a.value,
|
|
222
|
+
startScaleY: o.value,
|
|
223
|
+
startRotation: n.value,
|
|
224
|
+
startAngle: v
|
|
225
|
+
}, window.addEventListener("mousemove", re), window.addEventListener("mouseup", Q);
|
|
226
|
+
}
|
|
227
|
+
function re(r) {
|
|
228
|
+
if (!d) return;
|
|
229
|
+
const s = V(r.clientX, r.clientY), { mode: l, startLocalX: v, startLocalY: h, startPosX: g, startPosY: P, startScale: R, startScaleY: _, startRotation: T, startAngle: z } = d;
|
|
230
|
+
if (l === "drag") {
|
|
231
|
+
t.value = b(g + (s.x - v), P + (s.y - h));
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
if (l.startsWith("rotate-")) {
|
|
235
|
+
const N = B(s.x, s.y, t.value.x, t.value.y);
|
|
236
|
+
n.value = T + (N - z);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
const q = S(s.x, s.y, v, h);
|
|
240
|
+
if (l.startsWith("scale-")) {
|
|
241
|
+
ce(
|
|
242
|
+
l,
|
|
243
|
+
q,
|
|
244
|
+
g,
|
|
245
|
+
P,
|
|
246
|
+
R,
|
|
247
|
+
_,
|
|
248
|
+
T
|
|
249
|
+
);
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
(l === "resize-e" || l === "resize-w" || l === "resize-n" || l === "resize-s") && ue(l, q, g, P, R, _, T);
|
|
253
|
+
}
|
|
254
|
+
function Q() {
|
|
255
|
+
d && M(), d = null, window.removeEventListener("mousemove", re), window.removeEventListener("mouseup", Q);
|
|
256
|
+
}
|
|
257
|
+
function de(r) {
|
|
258
|
+
U("drag", r);
|
|
259
|
+
}
|
|
260
|
+
function u(r, s) {
|
|
261
|
+
U(r, s);
|
|
262
|
+
}
|
|
263
|
+
function I(r, s) {
|
|
264
|
+
U(r, s);
|
|
265
|
+
}
|
|
266
|
+
function W(r, s) {
|
|
267
|
+
U(r, s);
|
|
268
|
+
}
|
|
269
|
+
return xe(() => {
|
|
270
|
+
Q();
|
|
271
|
+
}), ae(
|
|
272
|
+
() => [F(e.canvasWidth), F(e.canvasHeight)],
|
|
273
|
+
() => {
|
|
274
|
+
t.value = b(t.value.x, t.value.y);
|
|
275
|
+
}
|
|
276
|
+
), {
|
|
277
|
+
lockAspectRatio: c,
|
|
278
|
+
rotation: n,
|
|
279
|
+
wrapperStyle: m,
|
|
280
|
+
applyFitScale: K,
|
|
281
|
+
getLayout: E,
|
|
282
|
+
resetKeyboardLayout: D,
|
|
283
|
+
toggleLockAspectRatio: p,
|
|
284
|
+
onDragStart: de,
|
|
285
|
+
onResizeStart: u,
|
|
286
|
+
onScaleCornerStart: I,
|
|
287
|
+
onRotateStart: W
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
function $e(e, t, a) {
|
|
291
|
+
var d, w;
|
|
292
|
+
const { keys: o, musicConfig: n } = e, c = o[t], k = c == null ? void 0 : c[a];
|
|
293
|
+
if (!k) return a;
|
|
294
|
+
let i = 0;
|
|
295
|
+
for (let y = 0; y < a; y++) {
|
|
296
|
+
const x = (d = n == null ? void 0 : n.keyOffset) == null ? void 0 : d.find((b) => {
|
|
297
|
+
var E;
|
|
298
|
+
return b.value === ((E = c[y]) == null ? void 0 : E.value);
|
|
299
|
+
});
|
|
300
|
+
x && (i += x.offsetX);
|
|
301
|
+
}
|
|
302
|
+
let f = a + i;
|
|
303
|
+
const m = (w = n == null ? void 0 : n.keyOffset) == null ? void 0 : w.find((y) => y.value === k.value);
|
|
304
|
+
return m && (f += m.offsetX), f;
|
|
305
|
+
}
|
|
306
|
+
function Xe(e) {
|
|
307
|
+
const { keys: t, musicConfig: a } = e, o = t.reduce((k, i) => Math.max(k, i.length), 0), n = (a == null ? void 0 : a.maxColOffset) || 0, c = o + n + 1;
|
|
308
|
+
return Array.from({ length: t.length }, () => Array.from({ length: c }, () => ({ r: 0, g: 0, b: 0 })));
|
|
309
|
+
}
|
|
310
|
+
function je(e, t) {
|
|
311
|
+
var k;
|
|
312
|
+
const { keys: a, musicConfig: o } = t, n = a.flatMap((i, f) => {
|
|
313
|
+
let m = 0;
|
|
314
|
+
return i.map((d, w) => {
|
|
315
|
+
let y = w + m;
|
|
316
|
+
if (o != null && o.keyOffset) {
|
|
317
|
+
const x = o.keyOffset.find((b) => b.value === d.value);
|
|
318
|
+
x && (y += x.offsetX, m += x.offsetX);
|
|
319
|
+
}
|
|
320
|
+
return {
|
|
321
|
+
row: f,
|
|
322
|
+
col: y,
|
|
323
|
+
value: d.value
|
|
324
|
+
};
|
|
325
|
+
});
|
|
326
|
+
}), c = new Array(n.length * 4).fill(0);
|
|
327
|
+
for (let i = 0; i < n.length; i++) {
|
|
328
|
+
const f = n[i], m = ((k = e[f.row]) == null ? void 0 : k[f.col]) ?? { r: 0, g: 0, b: 0 }, d = i * 4;
|
|
329
|
+
c[d] = f.value, c[d + 1] = m.r, c[d + 2] = m.g, c[d + 3] = m.b;
|
|
330
|
+
}
|
|
331
|
+
return c;
|
|
332
|
+
}
|
|
333
|
+
function Ge(e) {
|
|
334
|
+
const t = e.length / 4;
|
|
335
|
+
if (!t) return { r: 0, g: 0, b: 0 };
|
|
336
|
+
let a = 0, o = 0, n = 0;
|
|
337
|
+
for (let c = 0; c < e.length; c += 4)
|
|
338
|
+
a += e[c] ?? 0, o += e[c + 1] ?? 0, n += e[c + 2] ?? 0;
|
|
339
|
+
return {
|
|
340
|
+
r: Math.round(a / t),
|
|
341
|
+
g: Math.round(o / t),
|
|
342
|
+
b: Math.round(n / t)
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
function Ue(e, t, a, o) {
|
|
346
|
+
const n = o.getBoundingClientRect(), c = t.width / a.width, k = t.height / a.height, i = (n.left - a.left) * c, f = (n.top - a.top) * k, m = i + n.width * c, d = f + n.height * k, w = Math.max(0, i), y = Math.max(0, f), x = Math.min(t.width, m), b = Math.min(t.height, d);
|
|
347
|
+
if (w >= x || y >= b)
|
|
348
|
+
return { r: 0, g: 0, b: 0 };
|
|
349
|
+
const E = Math.floor(w), A = Math.floor(y), H = Math.max(1, Math.ceil(x - w)), M = Math.max(1, Math.ceil(b - y));
|
|
350
|
+
return Ge(e.getImageData(E, A, H, M).data);
|
|
351
|
+
}
|
|
352
|
+
function Le(e) {
|
|
353
|
+
const t = e.querySelector("slot");
|
|
354
|
+
if (t instanceof HTMLSlotElement) {
|
|
355
|
+
const a = t.assignedElements();
|
|
356
|
+
return a.length ? a.flatMap((o) => Le(o)) : [];
|
|
357
|
+
}
|
|
358
|
+
return [e];
|
|
359
|
+
}
|
|
360
|
+
function Te(e) {
|
|
361
|
+
return Le(e).flatMap(
|
|
362
|
+
(t) => Array.from(t.querySelectorAll("[data-row][data-col]")).map((a) => ({
|
|
363
|
+
row: Number(a.dataset.row),
|
|
364
|
+
col: Number(a.dataset.col),
|
|
365
|
+
el: a
|
|
366
|
+
}))
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
function Ye(e) {
|
|
370
|
+
const { canvas: t, keyboardConfig: a, getKeyElements: o } = e, n = o();
|
|
371
|
+
if (!n.length) return null;
|
|
372
|
+
const c = t.getContext("2d", { willReadFrequently: !0 });
|
|
373
|
+
if (!c) return null;
|
|
374
|
+
const k = Xe(a), i = t.getBoundingClientRect();
|
|
375
|
+
return n.forEach(({ row: f, col: m, el: d }) => {
|
|
376
|
+
var x;
|
|
377
|
+
const w = $e(a, f, m), y = Ue(c, t, i, d);
|
|
378
|
+
(x = k[f]) != null && x[w] && (k[f][w] = y);
|
|
379
|
+
}), k;
|
|
380
|
+
}
|
|
381
|
+
const Qe = { class: "relative" }, Ze = ["onMousedown"], Je = ["onMousedown"], et = ["onMousedown"], tt = /* @__PURE__ */ be({
|
|
382
|
+
__name: "keyboard-overlay.ce",
|
|
383
|
+
props: {
|
|
384
|
+
canvasWidth: { default: 800, type: Number },
|
|
385
|
+
canvasHeight: { default: 480, type: Number },
|
|
386
|
+
initialLayout: { type: [Object, null] },
|
|
387
|
+
onLayoutChange: { type: Function },
|
|
388
|
+
getKeyElements: { type: Function }
|
|
389
|
+
},
|
|
390
|
+
setup(e, { expose: t }) {
|
|
391
|
+
const a = e, o = L(null), n = L(null), {
|
|
392
|
+
lockAspectRatio: c,
|
|
393
|
+
rotation: k,
|
|
394
|
+
wrapperStyle: i,
|
|
395
|
+
applyFitScale: f,
|
|
396
|
+
getLayout: m,
|
|
397
|
+
resetKeyboardLayout: d,
|
|
398
|
+
toggleLockAspectRatio: w,
|
|
399
|
+
onDragStart: y,
|
|
400
|
+
onResizeStart: x,
|
|
401
|
+
onScaleCornerStart: b,
|
|
402
|
+
onRotateStart: E
|
|
403
|
+
} = We({
|
|
404
|
+
canvasWidth: () => a.canvasWidth,
|
|
405
|
+
canvasHeight: () => a.canvasHeight,
|
|
406
|
+
getOverlayEl: () => o.value,
|
|
407
|
+
initialLayout: () => a.initialLayout,
|
|
408
|
+
onLayoutChange: () => a.onLayoutChange
|
|
409
|
+
}), A = [
|
|
410
|
+
{ mode: "resize-n", baseAngle: 0, className: "resize-n" },
|
|
411
|
+
{ mode: "resize-s", baseAngle: 0, className: "resize-s" },
|
|
412
|
+
{ mode: "resize-w", baseAngle: 90, className: "resize-w" },
|
|
413
|
+
{ mode: "resize-e", baseAngle: 90, className: "resize-e" }
|
|
414
|
+
], H = [
|
|
415
|
+
{ mode: "scale-nw", baseAngle: 135, className: "corner-nw" },
|
|
416
|
+
{ mode: "scale-ne", baseAngle: 45, className: "corner-ne" },
|
|
417
|
+
{ mode: "scale-sw", baseAngle: 45, className: "corner-sw" },
|
|
418
|
+
{ mode: "scale-se", baseAngle: 135, className: "corner-se" }
|
|
419
|
+
], M = [
|
|
420
|
+
{ mode: "rotate-nw", className: "rotate-nw" },
|
|
421
|
+
{ mode: "rotate-ne", className: "rotate-ne" },
|
|
422
|
+
{ mode: "rotate-sw", className: "rotate-sw" },
|
|
423
|
+
{ mode: "rotate-se", className: "rotate-se" }
|
|
424
|
+
], K = ["ns-resize", "nesw-resize", "ew-resize", "nwse-resize"];
|
|
425
|
+
function D(V) {
|
|
426
|
+
const B = ((V + k.value) % 360 + 360) % 360, C = Math.round(B / 45) % 4;
|
|
427
|
+
return K[C];
|
|
428
|
+
}
|
|
429
|
+
function p() {
|
|
430
|
+
if (a.getKeyElements) return a.getKeyElements();
|
|
431
|
+
const V = n.value;
|
|
432
|
+
return V ? Te(V) : [];
|
|
433
|
+
}
|
|
434
|
+
function S() {
|
|
435
|
+
d(n.value);
|
|
436
|
+
}
|
|
437
|
+
return He(() => {
|
|
438
|
+
f(n.value);
|
|
439
|
+
}), ae(
|
|
440
|
+
() => [a.canvasWidth, a.canvasHeight],
|
|
441
|
+
() => {
|
|
442
|
+
f(n.value);
|
|
443
|
+
}
|
|
444
|
+
), t({
|
|
445
|
+
getMountEl: () => n.value,
|
|
446
|
+
getKeyElements: p,
|
|
447
|
+
getLayout: m,
|
|
448
|
+
resetLayout: S,
|
|
449
|
+
applyFitScale: () => f(n.value)
|
|
450
|
+
}), (V, B) => (ee(), te("div", {
|
|
451
|
+
ref_key: "overlayRef",
|
|
452
|
+
ref: o,
|
|
453
|
+
class: "overlay-root",
|
|
454
|
+
part: "overlay-root"
|
|
455
|
+
}, [
|
|
456
|
+
X("div", {
|
|
457
|
+
class: "transform-wrapper",
|
|
458
|
+
part: "transform-wrapper",
|
|
459
|
+
style: oe($(i))
|
|
460
|
+
}, [
|
|
461
|
+
X("div", Qe, [
|
|
462
|
+
X("button", {
|
|
463
|
+
type: "button",
|
|
464
|
+
class: "lock-btn",
|
|
465
|
+
part: "lock-button",
|
|
466
|
+
onMousedown: B[0] || (B[0] = ge(() => {
|
|
467
|
+
}, ["stop"])),
|
|
468
|
+
onClick: B[1] || (B[1] = ge(
|
|
469
|
+
//@ts-ignore
|
|
470
|
+
(...C) => $(w) && $(w)(...C),
|
|
471
|
+
["stop"]
|
|
472
|
+
))
|
|
473
|
+
}, [
|
|
474
|
+
X("i", {
|
|
475
|
+
class: se(["lock-icon", $(c) ? "lock-icon--locked" : "lock-icon--open"])
|
|
476
|
+
}, null, 2)
|
|
477
|
+
], 32),
|
|
478
|
+
(ee(), te(ve, null, fe(M, (C) => X("div", {
|
|
479
|
+
key: C.mode,
|
|
480
|
+
class: se(["rotate-handle", C.className]),
|
|
481
|
+
part: "rotate-handle",
|
|
482
|
+
onMousedown: (O) => $(E)(C.mode, O)
|
|
483
|
+
}, null, 42, Ze)), 64)),
|
|
484
|
+
(ee(), te(ve, null, fe(A, (C) => X("div", {
|
|
485
|
+
key: C.mode,
|
|
486
|
+
class: se(["resize-handle", C.className]),
|
|
487
|
+
part: "resize-handle",
|
|
488
|
+
style: oe({ cursor: D(C.baseAngle) }),
|
|
489
|
+
onMousedown: (O) => $(x)(C.mode, O)
|
|
490
|
+
}, null, 46, Je)), 64)),
|
|
491
|
+
(ee(), te(ve, null, fe(H, (C) => X("div", {
|
|
492
|
+
key: C.mode,
|
|
493
|
+
class: se(["corner-handle", C.className]),
|
|
494
|
+
part: "corner-handle",
|
|
495
|
+
style: oe({ cursor: D(C.baseAngle) }),
|
|
496
|
+
onMousedown: (O) => $(b)(C.mode, O)
|
|
497
|
+
}, null, 46, et)), 64)),
|
|
498
|
+
X("div", {
|
|
499
|
+
ref_key: "mountRef",
|
|
500
|
+
ref: n,
|
|
501
|
+
class: "keyboard-mount",
|
|
502
|
+
part: "keyboard-mount",
|
|
503
|
+
onMousedown: B[2] || (B[2] = //@ts-ignore
|
|
504
|
+
(...C) => $(y) && $(y)(...C))
|
|
505
|
+
}, [
|
|
506
|
+
ke(V.$slots, "keyboard", {}, void 0)
|
|
507
|
+
], 544)
|
|
508
|
+
])
|
|
509
|
+
], 4)
|
|
510
|
+
], 512));
|
|
511
|
+
}
|
|
512
|
+
}), at = `.overlay-root[data-v-1403efc7]{pointer-events:none;position:absolute;top:0;right:0;bottom:0;left:0;overflow:hidden}.transform-wrapper[data-v-1403efc7]{pointer-events:auto;position:absolute;-webkit-user-select:none;user-select:none}.lock-btn[data-v-1403efc7]{position:absolute;top:16px;right:-40px;z-index:20;width:32px;height:32px;display:flex;align-items:center;justify-content:center;cursor:pointer;border-radius:9999px;border-style:none;--un-bg-opacity:1;background-color:rgb(22 22 22 / var(--un-bg-opacity));--un-text-opacity:1;color:rgb(255 255 255 / var(--un-text-opacity));--un-shadow:var(--un-shadow-inset) 0 4px 6px -1px var(--un-shadow-color, rgb(0 0 0 / .1)),var(--un-shadow-inset) 0 2px 4px -2px var(--un-shadow-color, rgb(0 0 0 / .1));box-shadow:var(--un-ring-offset-shadow),var(--un-ring-shadow),var(--un-shadow);transition-property:color,background-color,border-color,text-decoration-color,fill,stroke;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.lock-btn[data-v-1403efc7]:hover{--un-bg-opacity:1;background-color:rgb(32 128 240 / var(--un-bg-opacity))}.lock-icon[data-v-1403efc7]{pointer-events:none;display:inline-block;font-size:24px}.lock-icon--locked[data-v-1403efc7],.lock-icon--open[data-v-1403efc7]{width:1em;height:1em;background-color:currentColor;-webkit-mask:no-repeat center / 100% 100%;mask:no-repeat center / 100% 100%}.lock-icon--locked[data-v-1403efc7]{-webkit-mask-image:url("data:image/svg+xml;utf8,%3Csvg viewBox='0 0 24 24' width='1em' height='1em' xmlns='http://www.w3.org/2000/svg' %3E%3Cpath fill='currentColor' d='M6 22q-.825 0-1.412-.587T4 20V10q0-.825.588-1.412T6 8h1V6q0-2.075 1.463-3.537T12 1t3.538 1.463T17 6v2h1q.825 0 1.413.588T20 10v10q0 .825-.587 1.413T18 22zm7.413-5.587Q14 15.825 14 15t-.587-1.412T12 13t-1.412.588T10 15t.588 1.413T12 17t1.413-.587M9 8h6V6q0-1.25-.875-2.125T12 3t-2.125.875T9 6z'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml;utf8,%3Csvg viewBox='0 0 24 24' width='1em' height='1em' xmlns='http://www.w3.org/2000/svg' %3E%3Cpath fill='currentColor' d='M6 22q-.825 0-1.412-.587T4 20V10q0-.825.588-1.412T6 8h1V6q0-2.075 1.463-3.537T12 1t3.538 1.463T17 6v2h1q.825 0 1.413.588T20 10v10q0 .825-.587 1.413T18 22zm7.413-5.587Q14 15.825 14 15t-.587-1.412T12 13t-1.412.588T10 15t.588 1.413T12 17t1.413-.587M9 8h6V6q0-1.25-.875-2.125T12 3t-2.125.875T9 6z'/%3E%3C/svg%3E")}.lock-icon--open[data-v-1403efc7]{-webkit-mask-image:url("data:image/svg+xml;utf8,%3Csvg viewBox='0 0 24 24' width='1em' height='1em' xmlns='http://www.w3.org/2000/svg' %3E%3Cpath fill='currentColor' d='M6 8h9V6q0-1.25-.875-2.125T12 3t-2.125.875T9 6H7q0-2.075 1.463-3.537T12 1t3.538 1.463T17 6v2h1q.825 0 1.413.588T20 10v10q0 .825-.587 1.413T18 22H6q-.825 0-1.412-.587T4 20V10q0-.825.588-1.412T6 8m7.413 8.413Q14 15.825 14 15t-.587-1.412T12 13t-1.412.588T10 15t.588 1.413T12 17t1.413-.587'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml;utf8,%3Csvg viewBox='0 0 24 24' width='1em' height='1em' xmlns='http://www.w3.org/2000/svg' %3E%3Cpath fill='currentColor' d='M6 8h9V6q0-1.25-.875-2.125T12 3t-2.125.875T9 6H7q0-2.075 1.463-3.537T12 1t3.538 1.463T17 6v2h1q.825 0 1.413.588T20 10v10q0 .825-.587 1.413T18 22H6q-.825 0-1.412-.587T4 20V10q0-.825.588-1.412T6 8m7.413 8.413Q14 15.825 14 15t-.587-1.412T12 13t-1.412.588T10 15t.588 1.413T12 17t1.413-.587'/%3E%3C/svg%3E")}.rotate-handle[data-v-1403efc7]{position:absolute;z-index:20;width:32px;height:32px;cursor:grab;--un-text-opacity:1;color:rgb(156 163 175 / var(--un-text-opacity));background-color:currentColor;-webkit-mask:no-repeat center / 100% 100%;mask:no-repeat center / 100% 100%}.rotate-nw[data-v-1403efc7]{top:-40px;left:-40px;-webkit-mask-image:url("data:image/svg+xml;utf8,%3Csvg viewBox='0 0 24 24' width='1em' height='1em' xmlns='http://www.w3.org/2000/svg' %3E%3Cpath fill='currentColor' d='M20.92 6.62a1 1 0 0 0-.21-.33l-3-3a1 1 0 0 0-1.42 1.42L17.59 6H9a3 3 0 0 0-3 3v8.59l-1.29-1.3a1 1 0 0 0-1.42 1.42l3 3a1 1 0 0 0 .33.21a.94.94 0 0 0 .76 0a1 1 0 0 0 .33-.21l3-3a1 1 0 0 0-1.42-1.42L8 17.59V9a1 1 0 0 1 1-1h8.59l-1.3 1.29a1 1 0 0 0 0 1.42a1 1 0 0 0 1.42 0l3-3a1 1 0 0 0 .21-.33a1 1 0 0 0 0-.76'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml;utf8,%3Csvg viewBox='0 0 24 24' width='1em' height='1em' xmlns='http://www.w3.org/2000/svg' %3E%3Cpath fill='currentColor' d='M20.92 6.62a1 1 0 0 0-.21-.33l-3-3a1 1 0 0 0-1.42 1.42L17.59 6H9a3 3 0 0 0-3 3v8.59l-1.29-1.3a1 1 0 0 0-1.42 1.42l3 3a1 1 0 0 0 .33.21a.94.94 0 0 0 .76 0a1 1 0 0 0 .33-.21l3-3a1 1 0 0 0-1.42-1.42L8 17.59V9a1 1 0 0 1 1-1h8.59l-1.3 1.29a1 1 0 0 0 0 1.42a1 1 0 0 0 1.42 0l3-3a1 1 0 0 0 .21-.33a1 1 0 0 0 0-.76'/%3E%3C/svg%3E")}.rotate-ne[data-v-1403efc7]{top:-40px;right:-40px;-webkit-mask-image:url("data:image/svg+xml;utf8,%3Csvg viewBox='0 0 24 24' width='1em' height='1em' xmlns='http://www.w3.org/2000/svg' %3E%3Cpath fill='currentColor' d='M21.71 16.29a1 1 0 0 0-1.42 0L18 18.59V9a3 3 0 0 0-3-3H5.41l2.3-2.29a1 1 0 0 0-1.42-1.42l-4 4a1 1 0 0 0-.21.33a1 1 0 0 0 0 .76a1 1 0 0 0 .21.33l4 4a1 1 0 0 0 1.42 0a1 1 0 0 0 0-1.42L5.41 8H15a1 1 0 0 1 1 1v9.59l-2.29-2.3a1 1 0 0 0-1.42 1.42l4 4a1 1 0 0 0 .33.21a.94.94 0 0 0 .76 0a1 1 0 0 0 .33-.21l4-4a1 1 0 0 0 0-1.42'/%3E%3C/svg%3E");mask-image:url("data:image/svg+xml;utf8,%3Csvg viewBox='0 0 24 24' width='1em' height='1em' xmlns='http://www.w3.org/2000/svg' %3E%3Cpath fill='currentColor' d='M21.71 16.29a1 1 0 0 0-1.42 0L18 18.59V9a3 3 0 0 0-3-3H5.41l2.3-2.29a1 1 0 0 0-1.42-1.42l-4 4a1 1 0 0 0-.21.33a1 1 0 0 0 0 .76a1 1 0 0 0 .21.33l4 4a1 1 0 0 0 1.42 0a1 1 0 0 0 0-1.42L5.41 8H15a1 1 0 0 1 1 1v9.59l-2.29-2.3a1 1 0 0 0-1.42 1.42l4 4a1 1 0 0 0 .33.21a.94.94 0 0 0 .76 0a1 1 0 0 0 .33-.21l4-4a1 1 0 0 0 0-1.42'/%3E%3C/svg%3E")}.rotate-sw[data-v-1403efc7]{bottom:-40px;left:-40px;-webkit-mask-image:url("data:image/svg+xml;utf8,%3Csvg viewBox='0 0 24 24' width='1em' height='1em' xmlns='http://www.w3.org/2000/svg' %3E%3Cg fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='2'%3E%3Cpath d='m17 21l4-4l-4-4'/%3E%3Cpath d='M21 17H10a3 3 0 0 1-3-3V3'/%3E%3Cpath d='M11 7L7 3L3 7'/%3E%3C/g%3E%3C/svg%3E");mask-image:url("data:image/svg+xml;utf8,%3Csvg viewBox='0 0 24 24' width='1em' height='1em' xmlns='http://www.w3.org/2000/svg' %3E%3Cg fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='2'%3E%3Cpath d='m17 21l4-4l-4-4'/%3E%3Cpath d='M21 17H10a3 3 0 0 1-3-3V3'/%3E%3Cpath d='M11 7L7 3L3 7'/%3E%3C/g%3E%3C/svg%3E")}.rotate-se[data-v-1403efc7]{bottom:-40px;right:-40px;-webkit-mask-image:url("data:image/svg+xml;utf8,%3Csvg viewBox='0 0 24 24' width='1em' height='1em' xmlns='http://www.w3.org/2000/svg' %3E%3Cg fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='2'%3E%3Cpath d='m21 7l-4-4l-4 4'/%3E%3Cpath d='M17 3v11a3 3 0 0 1-3 3H3'/%3E%3Cpath d='m7 13l-4 4l4 4'/%3E%3C/g%3E%3C/svg%3E");mask-image:url("data:image/svg+xml;utf8,%3Csvg viewBox='0 0 24 24' width='1em' height='1em' xmlns='http://www.w3.org/2000/svg' %3E%3Cg fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='2'%3E%3Cpath d='m21 7l-4-4l-4 4'/%3E%3Cpath d='M17 3v11a3 3 0 0 1-3 3H3'/%3E%3Cpath d='m7 13l-4 4l4 4'/%3E%3C/g%3E%3C/svg%3E")}.resize-handle[data-v-1403efc7]{position:absolute;z-index:10}.resize-n[data-v-1403efc7]{top:-4px;left:12px;right:12px;height:4px}.resize-s[data-v-1403efc7]{bottom:-4px;left:12px;right:12px;height:4px}.resize-w[data-v-1403efc7]{left:-4px;top:12px;bottom:12px;width:4px}.resize-e[data-v-1403efc7]{right:-4px;top:12px;bottom:12px;width:4px}.corner-handle[data-v-1403efc7]{position:absolute;z-index:20;width:16px;height:16px;border-radius:9999px;--un-bg-opacity:1;background-color:rgb(156 163 175 / var(--un-bg-opacity))}.corner-nw[data-v-1403efc7]{top:-8px;left:-8px}.corner-ne[data-v-1403efc7]{top:-8px;right:-8px}.corner-sw[data-v-1403efc7]{bottom:-8px;left:-8px}.corner-se[data-v-1403efc7]{bottom:-8px;right:-8px}.keyboard-mount[data-v-1403efc7]{position:relative;width:fit-content;cursor:move}`, Se = (e, t) => {
|
|
513
|
+
const a = e.__vccOpts || e;
|
|
514
|
+
for (const [o, n] of t)
|
|
515
|
+
a[o] = n;
|
|
516
|
+
return a;
|
|
517
|
+
}, ze = /* @__PURE__ */ Se(tt, [["styles", [at]], ["__scopeId", "data-v-1403efc7"]]);
|
|
518
|
+
function nt(e) {
|
|
519
|
+
var t, a;
|
|
520
|
+
if (e.default !== void 0) return e.default;
|
|
521
|
+
switch (e.type) {
|
|
522
|
+
case "color":
|
|
523
|
+
return "#000000";
|
|
524
|
+
case "switch":
|
|
525
|
+
return !1;
|
|
526
|
+
case "select":
|
|
527
|
+
return ((a = (t = e.options) == null ? void 0 : t[0]) == null ? void 0 : a.value) ?? 0;
|
|
528
|
+
default:
|
|
529
|
+
return 0;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
function Ie(e) {
|
|
533
|
+
return Object.fromEntries((e.params ?? []).map((t) => [t.key, nt(t)]));
|
|
534
|
+
}
|
|
535
|
+
function ie(e, t = {}) {
|
|
536
|
+
if (!e) return {};
|
|
537
|
+
const a = Ie(e);
|
|
538
|
+
for (const o of e.params ?? [])
|
|
539
|
+
o.key in t && t[o.key] !== void 0 && (a[o.key] = t[o.key]);
|
|
540
|
+
return a;
|
|
541
|
+
}
|
|
542
|
+
const rt = 50;
|
|
543
|
+
function pe(e, t, a) {
|
|
544
|
+
e.setTransform(1, 0, 0, 1, 0, 0), e.globalAlpha = 1, e.globalCompositeOperation = "source-over", e.clearRect(0, 0, t, a);
|
|
545
|
+
}
|
|
546
|
+
function st(e, t, a) {
|
|
547
|
+
const o = e.getContext("2d");
|
|
548
|
+
if (!o) return null;
|
|
549
|
+
const n = {
|
|
550
|
+
canvas2d: o,
|
|
551
|
+
width: e.width,
|
|
552
|
+
height: e.height
|
|
553
|
+
}, c = { ...Ie(t), ...a }, k = t.initialize(n, c);
|
|
554
|
+
let i = 0, f = 0, m = 0, d = 0;
|
|
555
|
+
const w = (D) => {
|
|
556
|
+
pe(o, e.width, e.height), d || (d = D);
|
|
557
|
+
const p = m ? D - m : 16, S = D - d;
|
|
558
|
+
m = D, t.render(n, k, { deltaTime: p, elapsedTime: S }, c);
|
|
559
|
+
}, y = () => {
|
|
560
|
+
i && (cancelAnimationFrame(i), i = 0);
|
|
561
|
+
}, x = () => {
|
|
562
|
+
f && (Ee(f), f = 0);
|
|
563
|
+
}, b = (D) => {
|
|
564
|
+
w(D), i = requestAnimationFrame(b);
|
|
565
|
+
}, E = () => {
|
|
566
|
+
w(performance.now());
|
|
567
|
+
}, A = () => {
|
|
568
|
+
x(), y(), i = requestAnimationFrame(b);
|
|
569
|
+
}, H = () => {
|
|
570
|
+
y(), x(), E(), f = Ce(E, rt);
|
|
571
|
+
}, M = () => {
|
|
572
|
+
document.visibilityState === "visible" ? A() : H();
|
|
573
|
+
}, K = () => {
|
|
574
|
+
M();
|
|
575
|
+
};
|
|
576
|
+
return document.addEventListener("visibilitychange", K), M(), () => {
|
|
577
|
+
document.removeEventListener("visibilitychange", K), y(), x(), t.shutdown(n, k), pe(o, e.width, e.height);
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
function ot(e, t = {}) {
|
|
581
|
+
return ie(e, t);
|
|
582
|
+
}
|
|
583
|
+
function it(e) {
|
|
584
|
+
const t = L(null), a = Y(() => F(e.canvasRef) ?? t.value), o = L(null), n = L({}), c = L(!1), k = Y(() => {
|
|
585
|
+
var p;
|
|
586
|
+
return ((p = o.value) == null ? void 0 : p.params) ?? [];
|
|
587
|
+
});
|
|
588
|
+
let i = null;
|
|
589
|
+
function f() {
|
|
590
|
+
const p = o.value, S = a.value;
|
|
591
|
+
if (!p || !S) return !1;
|
|
592
|
+
i == null || i(), i = null;
|
|
593
|
+
const V = st(S, p, n.value);
|
|
594
|
+
return V && (i = V, c.value = !0), !0;
|
|
595
|
+
}
|
|
596
|
+
function m() {
|
|
597
|
+
o.value && (f() || Me(() => f()));
|
|
598
|
+
}
|
|
599
|
+
function d(p, S) {
|
|
600
|
+
w(), o.value = p, S && (n.value = { ...S }), m();
|
|
601
|
+
}
|
|
602
|
+
function w() {
|
|
603
|
+
i == null || i(), i = null, c.value = !1;
|
|
604
|
+
}
|
|
605
|
+
function y(p) {
|
|
606
|
+
n.value = ie(o.value, { ...n.value, ...p }), m();
|
|
607
|
+
}
|
|
608
|
+
function x(p) {
|
|
609
|
+
return p.name ?? p.key;
|
|
610
|
+
}
|
|
611
|
+
function b(p) {
|
|
612
|
+
return Number(n.value[p] ?? 0);
|
|
613
|
+
}
|
|
614
|
+
function E(p) {
|
|
615
|
+
return String(n.value[p] ?? "#000000");
|
|
616
|
+
}
|
|
617
|
+
function A(p) {
|
|
618
|
+
const S = n.value[p];
|
|
619
|
+
return typeof S == "number" || typeof S == "string" ? S : 0;
|
|
620
|
+
}
|
|
621
|
+
function H(p) {
|
|
622
|
+
return !!n.value[p];
|
|
623
|
+
}
|
|
624
|
+
function M(p) {
|
|
625
|
+
const S = Number(p ?? 0);
|
|
626
|
+
return Number.isInteger(S) ? String(S) : S.toFixed(2).replace(/\.?0+$/, "");
|
|
627
|
+
}
|
|
628
|
+
function K(p, S) {
|
|
629
|
+
y({ [p]: S });
|
|
630
|
+
}
|
|
631
|
+
function D() {
|
|
632
|
+
const p = F(e.preset) ?? null, S = F(e.params) ?? {};
|
|
633
|
+
if (!p) {
|
|
634
|
+
o.value = null, n.value = {}, w();
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
637
|
+
o.value = p, n.value = ot(p, S), m();
|
|
638
|
+
}
|
|
639
|
+
return ae(() => ({ preset: F(e.preset), params: F(e.params) }), D, {
|
|
640
|
+
immediate: !0,
|
|
641
|
+
deep: !0,
|
|
642
|
+
flush: "sync"
|
|
643
|
+
}), xe(w), {
|
|
644
|
+
internalCanvasRef: t,
|
|
645
|
+
canvasRef: a,
|
|
646
|
+
currentPreset: o,
|
|
647
|
+
paramValues: n,
|
|
648
|
+
paramFields: k,
|
|
649
|
+
isRunning: c,
|
|
650
|
+
getParamLabel: x,
|
|
651
|
+
getSliderValue: b,
|
|
652
|
+
getColorValue: E,
|
|
653
|
+
getSelectValue: A,
|
|
654
|
+
getSwitchValue: H,
|
|
655
|
+
formatSliderValue: M,
|
|
656
|
+
handleParamChange: K,
|
|
657
|
+
start: d,
|
|
658
|
+
stop: w,
|
|
659
|
+
updateParams: y
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
const lt = 50;
|
|
663
|
+
function ct(e) {
|
|
664
|
+
const t = e.syncIntervalMs ?? lt;
|
|
665
|
+
let a = 0, o = !1, n = null;
|
|
666
|
+
function c() {
|
|
667
|
+
const d = e.getCanvas();
|
|
668
|
+
return d ? Ye({
|
|
669
|
+
canvas: d,
|
|
670
|
+
keyboardConfig: e.keyboardConfig,
|
|
671
|
+
getKeyElements: e.getKeyElements
|
|
672
|
+
}) : null;
|
|
673
|
+
}
|
|
674
|
+
async function k(d) {
|
|
675
|
+
var w;
|
|
676
|
+
if ((w = e.onKeysRgbChange) == null || w.call(e, d), o) {
|
|
677
|
+
n = d;
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
o = !0;
|
|
681
|
+
try {
|
|
682
|
+
const y = je(d, e.keyboardConfig);
|
|
683
|
+
await e.device.setMusicData(y, 0, e.isUSBDevice, e.lightingVersion);
|
|
684
|
+
} catch {
|
|
685
|
+
} finally {
|
|
686
|
+
if (o = !1, n) {
|
|
687
|
+
const y = n;
|
|
688
|
+
n = null, k(y);
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
function i() {
|
|
693
|
+
if (e.enabled && !e.enabled.value) return;
|
|
694
|
+
const d = c();
|
|
695
|
+
d && k(d);
|
|
696
|
+
}
|
|
697
|
+
function f() {
|
|
698
|
+
a || (a = Ce(i, t));
|
|
699
|
+
}
|
|
700
|
+
function m() {
|
|
701
|
+
a && (Ee(a), a = 0);
|
|
702
|
+
}
|
|
703
|
+
return e.enabled ? ae(
|
|
704
|
+
e.enabled,
|
|
705
|
+
(d) => {
|
|
706
|
+
d ? f() : m();
|
|
707
|
+
},
|
|
708
|
+
{ immediate: !0 }
|
|
709
|
+
) : f(), _e(m), {
|
|
710
|
+
syncKeyColors: i,
|
|
711
|
+
startKeySync: f,
|
|
712
|
+
stopKeySync: m
|
|
713
|
+
};
|
|
714
|
+
}
|
|
715
|
+
function ut(e) {
|
|
716
|
+
if (!e || typeof e != "object") return !1;
|
|
717
|
+
const t = e;
|
|
718
|
+
return !(typeof t.id != "string" || !t.id.trim() || typeof t.name != "string" || !t.name.trim() || typeof t.initialize != "function" || typeof t.render != "function" || typeof t.shutdown != "function" || t.params !== void 0 && (!Array.isArray(t.params) || !t.params.every((a) => a && typeof a == "object" && typeof a.key == "string")));
|
|
719
|
+
}
|
|
720
|
+
function dt(e) {
|
|
721
|
+
const t = new Function(`return (${e})`)();
|
|
722
|
+
if (!ut(t))
|
|
723
|
+
throw new Error("INVALID_PRESET");
|
|
724
|
+
return t;
|
|
725
|
+
}
|
|
726
|
+
function we(e = {}) {
|
|
727
|
+
var y, x;
|
|
728
|
+
const t = e.initialPresets ?? [], a = he(e.initialImported ?? []), o = he([...t, ...a.value]), n = L(((y = t[0]) == null ? void 0 : y.id) ?? ((x = a.value[0]) == null ? void 0 : x.id) ?? ""), c = () => o.value.find((b) => b.id === n.value) ?? o.value[0] ?? null;
|
|
729
|
+
function k() {
|
|
730
|
+
o.value = [...t, ...a.value];
|
|
731
|
+
}
|
|
732
|
+
function i() {
|
|
733
|
+
var b;
|
|
734
|
+
(b = e.onPresetsChange) == null || b.call(e, a.value.map((E) => Ke(E)));
|
|
735
|
+
}
|
|
736
|
+
function f(b) {
|
|
737
|
+
o.value.some((E) => E.id === b) && (n.value = b);
|
|
738
|
+
}
|
|
739
|
+
function m(b) {
|
|
740
|
+
return t.some((E) => E.id === b);
|
|
741
|
+
}
|
|
742
|
+
async function d(b) {
|
|
743
|
+
var E, A, H;
|
|
744
|
+
try {
|
|
745
|
+
const M = dt(b);
|
|
746
|
+
return o.value.some((K) => K.id === M.id) ? ((E = e.onImportPreset) == null || E.call(e, {
|
|
747
|
+
code: 1,
|
|
748
|
+
message: "Preset id already exists"
|
|
749
|
+
}), null) : (a.value = [...a.value, M], k(), i(), n.value = M.id, (A = e.onImportPreset) == null || A.call(e, {
|
|
750
|
+
code: 0,
|
|
751
|
+
message: "Import success"
|
|
752
|
+
}), M);
|
|
753
|
+
} catch {
|
|
754
|
+
return (H = e.onImportPreset) == null || H.call(e, {
|
|
755
|
+
code: 2,
|
|
756
|
+
message: "Invalid preset code"
|
|
757
|
+
}), null;
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
async function w(b) {
|
|
761
|
+
var E;
|
|
762
|
+
m(b) || (a.value = a.value.filter((A) => A.id !== b), k(), i(), n.value === b && (n.value = ((E = o.value[0]) == null ? void 0 : E.id) ?? ""));
|
|
763
|
+
}
|
|
764
|
+
return {
|
|
765
|
+
presetList: o,
|
|
766
|
+
selectedPresetId: n,
|
|
767
|
+
selectedPreset: c,
|
|
768
|
+
selectPreset: f,
|
|
769
|
+
isInitialPreset: m,
|
|
770
|
+
importPreset: d,
|
|
771
|
+
deleteImportedPreset: w
|
|
772
|
+
};
|
|
773
|
+
}
|
|
774
|
+
const vt = ["setMusicData", "getDeviceId", "isConnected", "getDevice"];
|
|
775
|
+
function ft(e) {
|
|
776
|
+
if (!e || typeof e != "object") return !1;
|
|
777
|
+
const t = e;
|
|
778
|
+
return vt.every((a) => typeof t[a] == "function");
|
|
779
|
+
}
|
|
780
|
+
async function ht(e) {
|
|
781
|
+
if (!e)
|
|
782
|
+
throw new Error("[keyboard-kit] init.device is required");
|
|
783
|
+
if (!ft(e))
|
|
784
|
+
throw new Error("[keyboard-kit] init.device must be an @hfd-sdk/keyboard-sdk HFDDevice instance");
|
|
785
|
+
const { HFDDevice: t } = await import("@hfd-sdk/keyboard-sdk");
|
|
786
|
+
if (!(e instanceof t))
|
|
787
|
+
throw new Error("[keyboard-kit] init.device must be created via new HFDDevice() from @hfd-sdk/keyboard-sdk");
|
|
788
|
+
return e;
|
|
789
|
+
}
|
|
790
|
+
const gt = ["width", "height"], mt = /* @__PURE__ */ be({
|
|
791
|
+
__name: "hfd-ai-lighting.ce",
|
|
792
|
+
props: {
|
|
793
|
+
width: { default: 800, type: Number },
|
|
794
|
+
height: { default: 480, type: Number }
|
|
795
|
+
},
|
|
796
|
+
emits: ["keys-rgb-change", "preset-change", "param-change", "presets-change", "layout-change", "keyboard-ready", "import-preset"],
|
|
797
|
+
setup(e, { expose: t, emit: a }) {
|
|
798
|
+
const o = e, n = a, c = L(o.width), k = L(o.height), i = L(), f = L(), m = L(null), d = L(null), w = L(), y = L(), x = L(50), b = L(!0), E = L({}), A = L(null), H = L(null);
|
|
799
|
+
let M = he(we());
|
|
800
|
+
const K = Y(() => M.value.selectedPreset()), D = Y(() => ({
|
|
801
|
+
width: `${c.value}px`,
|
|
802
|
+
height: `${k.value}px`
|
|
803
|
+
})), { paramValues: p, handleParamChange: S } = it({
|
|
804
|
+
preset: () => K.value,
|
|
805
|
+
params: () => E.value,
|
|
806
|
+
canvasRef: () => A.value
|
|
807
|
+
});
|
|
808
|
+
function V() {
|
|
809
|
+
var I, W;
|
|
810
|
+
if (f.value) return f.value();
|
|
811
|
+
const u = (W = (I = H.value) == null ? void 0 : I.getMountEl) == null ? void 0 : W.call(I);
|
|
812
|
+
return u ? Te(u) : [];
|
|
813
|
+
}
|
|
814
|
+
function B(u) {
|
|
815
|
+
n("layout-change", { layout: u });
|
|
816
|
+
}
|
|
817
|
+
let C = null;
|
|
818
|
+
function O() {
|
|
819
|
+
if (C == null || C(), C = null, !m.value || !A.value || !d.value) return;
|
|
820
|
+
C = ct({
|
|
821
|
+
keyboardConfig: m.value,
|
|
822
|
+
getCanvas: () => A.value,
|
|
823
|
+
getKeyElements: V,
|
|
824
|
+
device: d.value,
|
|
825
|
+
isUSBDevice: w.value,
|
|
826
|
+
lightingVersion: y.value,
|
|
827
|
+
syncIntervalMs: x.value,
|
|
828
|
+
enabled: b,
|
|
829
|
+
onKeysRgbChange: (I) => {
|
|
830
|
+
n("keys-rgb-change", { keysRgb: I });
|
|
831
|
+
}
|
|
832
|
+
}).stopKeySync;
|
|
833
|
+
}
|
|
834
|
+
function j(u) {
|
|
835
|
+
n("preset-change", {
|
|
836
|
+
presetId: u,
|
|
837
|
+
preset: M.value.selectedPreset()
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
async function le(u) {
|
|
841
|
+
var W, r, s, l;
|
|
842
|
+
const I = await ht(u.device);
|
|
843
|
+
c.value = u.canvasWidth ?? o.width, k.value = u.canvasHeight ?? o.height, i.value = u.initialLayout, f.value = u.getKeyElements, m.value = u.keyboardConfig, d.value = I, w.value = u.isUSBDevice, y.value = u.lightingVersion, x.value = u.syncIntervalMs ?? 50, E.value = u.defaultParams ?? {}, M.value = we({
|
|
844
|
+
initialPresets: u.presets ?? [],
|
|
845
|
+
initialImported: u.importedPresets ?? [],
|
|
846
|
+
onPresetsChange: (v) => n("presets-change", { importedSerialized: v }),
|
|
847
|
+
onImportPreset: (v) => n("import-preset", v)
|
|
848
|
+
}), u.selectedPresetId ? M.value.selectPreset(u.selectedPresetId) : (W = u.presets) != null && W[0] ? M.value.selectPreset(u.presets[0].id) : (r = u.importedPresets) != null && r[0] && M.value.selectPreset(u.importedPresets[0].id), await Me(), (l = (s = H.value) == null ? void 0 : s.applyFitScale) == null || l.call(s), O(), j(M.value.selectedPresetId.value), n("keyboard-ready");
|
|
849
|
+
}
|
|
850
|
+
function ne(u) {
|
|
851
|
+
M.value.selectPreset(u), j(u);
|
|
852
|
+
}
|
|
853
|
+
async function ce(u) {
|
|
854
|
+
await M.value.deleteImportedPreset(u), j(M.value.selectedPresetId.value);
|
|
855
|
+
}
|
|
856
|
+
async function ue(u) {
|
|
857
|
+
const I = await M.value.importPreset(u);
|
|
858
|
+
return I && j(I.id), I;
|
|
859
|
+
}
|
|
860
|
+
function U(u, I) {
|
|
861
|
+
S(u, I);
|
|
862
|
+
const W = K.value, r = {
|
|
863
|
+
key: u,
|
|
864
|
+
value: I,
|
|
865
|
+
params: ie(W, p.value)
|
|
866
|
+
};
|
|
867
|
+
n("param-change", r);
|
|
868
|
+
}
|
|
869
|
+
function re() {
|
|
870
|
+
const u = M.value;
|
|
871
|
+
return {
|
|
872
|
+
presetList: u.presetList,
|
|
873
|
+
selectedPresetId: u.selectedPresetId,
|
|
874
|
+
selectedPreset: u.selectedPreset,
|
|
875
|
+
isInitialPreset: u.isInitialPreset
|
|
876
|
+
};
|
|
877
|
+
}
|
|
878
|
+
function Q() {
|
|
879
|
+
return ie(K.value, p.value);
|
|
880
|
+
}
|
|
881
|
+
function de() {
|
|
882
|
+
var u, I;
|
|
883
|
+
(I = (u = H.value) == null ? void 0 : u.resetLayout) == null || I.call(u);
|
|
884
|
+
}
|
|
885
|
+
return ae(
|
|
886
|
+
() => [m.value, d.value, w.value, y.value],
|
|
887
|
+
() => O()
|
|
888
|
+
), t({
|
|
889
|
+
init: le,
|
|
890
|
+
getPresetState: re,
|
|
891
|
+
selectPreset: ne,
|
|
892
|
+
deletePreset: ce,
|
|
893
|
+
importPreset: ue,
|
|
894
|
+
setParam: U,
|
|
895
|
+
getParamValues: Q,
|
|
896
|
+
resetKeyboardLayout: de,
|
|
897
|
+
getKeyElements: V
|
|
898
|
+
}), (u, I) => (ee(), te("div", {
|
|
899
|
+
class: "preview-wrap",
|
|
900
|
+
style: oe(D.value)
|
|
901
|
+
}, [
|
|
902
|
+
X("canvas", {
|
|
903
|
+
ref_key: "canvasEl",
|
|
904
|
+
ref: A,
|
|
905
|
+
class: "preview-canvas",
|
|
906
|
+
width: c.value,
|
|
907
|
+
height: k.value
|
|
908
|
+
}, null, 8, gt),
|
|
909
|
+
Ve(ze, {
|
|
910
|
+
ref_key: "overlayRef",
|
|
911
|
+
ref: H,
|
|
912
|
+
"canvas-width": c.value,
|
|
913
|
+
"canvas-height": k.value,
|
|
914
|
+
"initial-layout": i.value,
|
|
915
|
+
"on-layout-change": B,
|
|
916
|
+
"get-key-elements": V
|
|
917
|
+
}, {
|
|
918
|
+
keyboard: Ne(() => [
|
|
919
|
+
ke(u.$slots, "keyboard", {}, void 0, !0)
|
|
920
|
+
]),
|
|
921
|
+
_: 3
|
|
922
|
+
}, 8, ["canvas-width", "canvas-height", "initial-layout"])
|
|
923
|
+
], 4));
|
|
924
|
+
}
|
|
925
|
+
}), yt = ".preview-wrap[data-v-ba92361e]{position:relative;flex-shrink:0;overflow:hidden;border-radius:8px;background:#000}.preview-canvas[data-v-ba92361e]{display:block;width:100%;height:100%}", pt = /* @__PURE__ */ Se(mt, [["styles", [yt]], ["__scopeId", "data-v-ba92361e"]]), wt = Pe(
|
|
926
|
+
pt
|
|
927
|
+
), xt = Pe(
|
|
928
|
+
ze
|
|
929
|
+
);
|
|
930
|
+
function bt() {
|
|
931
|
+
const e = [
|
|
932
|
+
["hfd-ai-lighting", wt],
|
|
933
|
+
["hfd-ai-lighting-keyboard-overlay", xt]
|
|
934
|
+
];
|
|
935
|
+
for (const [t, a] of e)
|
|
936
|
+
customElements.get(t) || customElements.define(t, a);
|
|
937
|
+
}
|
|
938
|
+
bt();
|
|
939
|
+
export {
|
|
940
|
+
wt as HfdAiLightingElement,
|
|
941
|
+
xt as HfdAiLightingKeyboardOverlayElement,
|
|
942
|
+
Pt as deserializePreset,
|
|
943
|
+
bt as registerAiLightingElements,
|
|
944
|
+
Ke as serializePreset,
|
|
945
|
+
ut as validatePreset
|
|
946
|
+
};
|