@nightshadeui/canvas 2.11.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.
@@ -0,0 +1,2171 @@
1
+ import { openBlock as V, createElementBlock as q, createElementVNode as j, normalizeStyle as Z, createCommentVNode as Pt, withModifiers as U, normalizeClass as _t, resolveComponent as oe, renderSlot as re, normalizeProps as jt, guardReactiveProps as Ct, Fragment as Et, renderList as It, createBlock as Xe, createVNode as K, withCtx as G, toDisplayString as X, reactive as Tt } from "vue";
2
+ const te = (o, e) => {
3
+ const t = o.__vccOpts || o;
4
+ for (const [n, r] of e)
5
+ t[n] = r;
6
+ return t;
7
+ }, zt = {
8
+ props: {
9
+ canvas: { type: Object, required: !0 }
10
+ }
11
+ }, Dt = {
12
+ key: 0,
13
+ class: "CanvasBoxSelect"
14
+ };
15
+ function Rt(o, e, t, n, r, c) {
16
+ return t.canvas.boxSelect.isSelecting() ? (V(), q("div", Dt, [
17
+ j("div", {
18
+ class: "Box",
19
+ style: Z(t.canvas.boxSelect.getSelectionStyle())
20
+ }, null, 4)
21
+ ])) : Pt("", !0);
22
+ }
23
+ const kt = /* @__PURE__ */ te(zt, [["render", Rt], ["__scopeId", "data-v-9e8905e1"]]);
24
+ function z(o, e, t) {
25
+ return Math.max(e, Math.min(t, o));
26
+ }
27
+ function We(o, e) {
28
+ return {
29
+ x: o.x - e.x,
30
+ y: o.y - e.y
31
+ };
32
+ }
33
+ function ie(o, e) {
34
+ const t = { x: Math.min(o.x, e.x), y: Math.min(o.y, e.y) }, n = { x: Math.max(o.x, e.x), y: Math.max(o.y, e.y) };
35
+ return [t, n];
36
+ }
37
+ function Le(o, e) {
38
+ const t = o[1].x >= e[0].x && e[1].x >= o[0].x, n = o[1].y >= e[0].y && e[1].y >= o[0].y;
39
+ return t && n;
40
+ }
41
+ function Bt(o) {
42
+ const [e, t] = o;
43
+ return {
44
+ x: (t.x - e.x) * 0.5 + e.x,
45
+ y: (t.y - e.y) * 0.5 + e.y
46
+ };
47
+ }
48
+ function Ze(o, e, t) {
49
+ const n = o ?? document.documentElement;
50
+ return getComputedStyle(n).getPropertyValue(e).trim() || t;
51
+ }
52
+ function W(o, e, t) {
53
+ const n = Ze(o, e, String(t)), r = Number(n.replace(/px|em|%|vh|vw/g, ""));
54
+ return Number.isFinite(r) ? r : t;
55
+ }
56
+ function $e(o, e, t) {
57
+ const n = o ?? document.documentElement, r = Ze(o, e, t), c = document.createElement("span");
58
+ c.style.position = "absolute", c.style.visibility = "hidden", c.style.pointerEvents = "none", c.style.color = t, c.style.color = r, n.appendChild(c);
59
+ const p = getComputedStyle(c).color.trim();
60
+ return c.remove(), p || t;
61
+ }
62
+ class ue {
63
+ constructor(e) {
64
+ this.target = e, this.entries = [];
65
+ }
66
+ add(e, t, n) {
67
+ this.target.addEventListener(e, t, n), this.entries.push({ type: e, listener: t, options: n });
68
+ }
69
+ removeAll() {
70
+ for (const e of this.entries)
71
+ this.target.removeEventListener(e.type, e.listener, e.options);
72
+ this.entries = [];
73
+ }
74
+ }
75
+ function Ut(o, e, t, n = 2, r, c = 1) {
76
+ const p = [0, ...Vt(o, e), o], y = [0, o], S = [
77
+ `<svg xmlns="http://www.w3.org/2000/svg"
78
+ width="${o}"
79
+ height="${o}"
80
+ viewBox="0 0 ${o} ${o}">`
81
+ ];
82
+ if (c)
83
+ for (const C of p)
84
+ for (const E of p)
85
+ S.push(
86
+ `<circle cx="${C}" cy="${E}" r="${c}" fill="${r}"/>`
87
+ );
88
+ if (n)
89
+ for (const C of y)
90
+ for (const E of y)
91
+ S.push(
92
+ `<circle cx="${C}" cy="${E}" r="${n}" fill="${t}"/>`
93
+ );
94
+ return S.push("</svg>"), S.join("");
95
+ }
96
+ function Vt(o, e) {
97
+ const t = [], n = Math.round(o / e);
98
+ for (let r = 1; r < e; r++)
99
+ t.push(n * r);
100
+ return t;
101
+ }
102
+ var Ae = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, Ge = {};
103
+ var Fe;
104
+ function Lt() {
105
+ if (Fe) return Ge;
106
+ Fe = 1;
107
+ var o;
108
+ return (function(e) {
109
+ (function(t) {
110
+ var n = typeof globalThis == "object" ? globalThis : typeof Ae == "object" ? Ae : typeof self == "object" ? self : typeof this == "object" ? this : S(), r = c(e);
111
+ typeof n.Reflect < "u" && (r = c(n.Reflect, r)), t(r, n), typeof n.Reflect > "u" && (n.Reflect = e);
112
+ function c(C, E) {
113
+ return function(R, N) {
114
+ Object.defineProperty(C, R, { configurable: !0, writable: !0, value: N }), E && E(R, N);
115
+ };
116
+ }
117
+ function p() {
118
+ try {
119
+ return Function("return this;")();
120
+ } catch {
121
+ }
122
+ }
123
+ function y() {
124
+ try {
125
+ return (0, eval)("(function() { return this; })()");
126
+ } catch {
127
+ }
128
+ }
129
+ function S() {
130
+ return p() || y();
131
+ }
132
+ })(function(t, n) {
133
+ var r = Object.prototype.hasOwnProperty, c = typeof Symbol == "function", p = c && typeof Symbol.toPrimitive < "u" ? Symbol.toPrimitive : "@@toPrimitive", y = c && typeof Symbol.iterator < "u" ? Symbol.iterator : "@@iterator", S = typeof Object.create == "function", C = { __proto__: [] } instanceof Array, E = !S && !C, R = {
134
+ // create an object in dictionary mode (a.k.a. "slow" mode in v8)
135
+ create: S ? function() {
136
+ return ge(/* @__PURE__ */ Object.create(null));
137
+ } : C ? function() {
138
+ return ge({ __proto__: null });
139
+ } : function() {
140
+ return ge({});
141
+ },
142
+ has: E ? function(s, i) {
143
+ return r.call(s, i);
144
+ } : function(s, i) {
145
+ return i in s;
146
+ },
147
+ get: E ? function(s, i) {
148
+ return r.call(s, i) ? s[i] : void 0;
149
+ } : function(s, i) {
150
+ return s[i];
151
+ }
152
+ }, N = Object.getPrototypeOf(Function), Y = typeof Map == "function" && typeof Map.prototype.entries == "function" ? Map : bt(), de = typeof Set == "function" && typeof Set.prototype.entries == "function" ? Set : xt(), fe = typeof WeakMap == "function" ? WeakMap : St(), $ = c ? /* @__PURE__ */ Symbol.for("@reflect-metadata:registry") : void 0, se = gt(), Se = wt(se);
153
+ function Qe(s, i, a, l) {
154
+ if (g(a)) {
155
+ if (!Te(s))
156
+ throw new TypeError();
157
+ if (!ze(i))
158
+ throw new TypeError();
159
+ return lt(s, i);
160
+ } else {
161
+ if (!Te(s))
162
+ throw new TypeError();
163
+ if (!O(i))
164
+ throw new TypeError();
165
+ if (!O(l) && !g(l) && !A(l))
166
+ throw new TypeError();
167
+ return A(l) && (l = void 0), a = T(a), ut(s, i, a, l);
168
+ }
169
+ }
170
+ t("decorate", Qe);
171
+ function et(s, i) {
172
+ function a(l, v) {
173
+ if (!O(l))
174
+ throw new TypeError();
175
+ if (!g(v) && !pt(v))
176
+ throw new TypeError();
177
+ _e(s, i, l, v);
178
+ }
179
+ return a;
180
+ }
181
+ t("metadata", et);
182
+ function tt(s, i, a, l) {
183
+ if (!O(a))
184
+ throw new TypeError();
185
+ return g(l) || (l = T(l)), _e(s, i, a, l);
186
+ }
187
+ t("defineMetadata", tt);
188
+ function st(s, i, a) {
189
+ if (!O(i))
190
+ throw new TypeError();
191
+ return g(a) || (a = T(a)), Me(s, i, a);
192
+ }
193
+ t("hasMetadata", st);
194
+ function nt(s, i, a) {
195
+ if (!O(i))
196
+ throw new TypeError();
197
+ return g(a) || (a = T(a)), ve(s, i, a);
198
+ }
199
+ t("hasOwnMetadata", nt);
200
+ function it(s, i, a) {
201
+ if (!O(i))
202
+ throw new TypeError();
203
+ return g(a) || (a = T(a)), Oe(s, i, a);
204
+ }
205
+ t("getMetadata", it);
206
+ function rt(s, i, a) {
207
+ if (!O(i))
208
+ throw new TypeError();
209
+ return g(a) || (a = T(a)), Pe(s, i, a);
210
+ }
211
+ t("getOwnMetadata", rt);
212
+ function ot(s, i) {
213
+ if (!O(s))
214
+ throw new TypeError();
215
+ return g(i) || (i = T(i)), je(s, i);
216
+ }
217
+ t("getMetadataKeys", ot);
218
+ function at(s, i) {
219
+ if (!O(s))
220
+ throw new TypeError();
221
+ return g(i) || (i = T(i)), Ce(s, i);
222
+ }
223
+ t("getOwnMetadataKeys", at);
224
+ function ct(s, i, a) {
225
+ if (!O(i))
226
+ throw new TypeError();
227
+ if (g(a) || (a = T(a)), !O(i))
228
+ throw new TypeError();
229
+ g(a) || (a = T(a));
230
+ var l = H(
231
+ i,
232
+ a,
233
+ /*Create*/
234
+ !1
235
+ );
236
+ return g(l) ? !1 : l.OrdinaryDeleteMetadata(s, i, a);
237
+ }
238
+ t("deleteMetadata", ct);
239
+ function lt(s, i) {
240
+ for (var a = s.length - 1; a >= 0; --a) {
241
+ var l = s[a], v = l(i);
242
+ if (!g(v) && !A(v)) {
243
+ if (!ze(v))
244
+ throw new TypeError();
245
+ i = v;
246
+ }
247
+ }
248
+ return i;
249
+ }
250
+ function ut(s, i, a, l) {
251
+ for (var v = s.length - 1; v >= 0; --v) {
252
+ var _ = s[v], P = _(i, a, l);
253
+ if (!g(P) && !A(P)) {
254
+ if (!O(P))
255
+ throw new TypeError();
256
+ l = P;
257
+ }
258
+ }
259
+ return l;
260
+ }
261
+ function Me(s, i, a) {
262
+ var l = ve(s, i, a);
263
+ if (l)
264
+ return !0;
265
+ var v = ye(i);
266
+ return A(v) ? !1 : Me(s, v, a);
267
+ }
268
+ function ve(s, i, a) {
269
+ var l = H(
270
+ i,
271
+ a,
272
+ /*Create*/
273
+ !1
274
+ );
275
+ return g(l) ? !1 : Ie(l.OrdinaryHasOwnMetadata(s, i, a));
276
+ }
277
+ function Oe(s, i, a) {
278
+ var l = ve(s, i, a);
279
+ if (l)
280
+ return Pe(s, i, a);
281
+ var v = ye(i);
282
+ if (!A(v))
283
+ return Oe(s, v, a);
284
+ }
285
+ function Pe(s, i, a) {
286
+ var l = H(
287
+ i,
288
+ a,
289
+ /*Create*/
290
+ !1
291
+ );
292
+ if (!g(l))
293
+ return l.OrdinaryGetOwnMetadata(s, i, a);
294
+ }
295
+ function _e(s, i, a, l) {
296
+ var v = H(
297
+ a,
298
+ l,
299
+ /*Create*/
300
+ !0
301
+ );
302
+ v.OrdinaryDefineOwnMetadata(s, i, a, l);
303
+ }
304
+ function je(s, i) {
305
+ var a = Ce(s, i), l = ye(s);
306
+ if (l === null)
307
+ return a;
308
+ var v = je(l, i);
309
+ if (v.length <= 0)
310
+ return a;
311
+ if (a.length <= 0)
312
+ return v;
313
+ for (var _ = new de(), P = [], w = 0, u = a; w < u.length; w++) {
314
+ var h = u[w], d = _.has(h);
315
+ d || (_.add(h), P.push(h));
316
+ }
317
+ for (var f = 0, m = v; f < m.length; f++) {
318
+ var h = m[f], d = _.has(h);
319
+ d || (_.add(h), P.push(h));
320
+ }
321
+ return P;
322
+ }
323
+ function Ce(s, i) {
324
+ var a = H(
325
+ s,
326
+ i,
327
+ /*create*/
328
+ !1
329
+ );
330
+ return a ? a.OrdinaryOwnMetadataKeys(s, i) : [];
331
+ }
332
+ function Ee(s) {
333
+ if (s === null)
334
+ return 1;
335
+ switch (typeof s) {
336
+ case "undefined":
337
+ return 0;
338
+ case "boolean":
339
+ return 2;
340
+ case "string":
341
+ return 3;
342
+ case "symbol":
343
+ return 4;
344
+ case "number":
345
+ return 5;
346
+ case "object":
347
+ return s === null ? 1 : 6;
348
+ default:
349
+ return 6;
350
+ }
351
+ }
352
+ function g(s) {
353
+ return s === void 0;
354
+ }
355
+ function A(s) {
356
+ return s === null;
357
+ }
358
+ function ht(s) {
359
+ return typeof s == "symbol";
360
+ }
361
+ function O(s) {
362
+ return typeof s == "object" ? s !== null : typeof s == "function";
363
+ }
364
+ function dt(s, i) {
365
+ switch (Ee(s)) {
366
+ case 0:
367
+ return s;
368
+ case 1:
369
+ return s;
370
+ case 2:
371
+ return s;
372
+ case 3:
373
+ return s;
374
+ case 4:
375
+ return s;
376
+ case 5:
377
+ return s;
378
+ }
379
+ var a = "string", l = De(s, p);
380
+ if (l !== void 0) {
381
+ var v = l.call(s, a);
382
+ if (O(v))
383
+ throw new TypeError();
384
+ return v;
385
+ }
386
+ return ft(s);
387
+ }
388
+ function ft(s, i) {
389
+ var a, l;
390
+ {
391
+ var v = s.toString;
392
+ if (ne(v)) {
393
+ var l = v.call(s);
394
+ if (!O(l))
395
+ return l;
396
+ }
397
+ var a = s.valueOf;
398
+ if (ne(a)) {
399
+ var l = a.call(s);
400
+ if (!O(l))
401
+ return l;
402
+ }
403
+ }
404
+ throw new TypeError();
405
+ }
406
+ function Ie(s) {
407
+ return !!s;
408
+ }
409
+ function vt(s) {
410
+ return "" + s;
411
+ }
412
+ function T(s) {
413
+ var i = dt(s);
414
+ return ht(i) ? i : vt(i);
415
+ }
416
+ function Te(s) {
417
+ return Array.isArray ? Array.isArray(s) : s instanceof Object ? s instanceof Array : Object.prototype.toString.call(s) === "[object Array]";
418
+ }
419
+ function ne(s) {
420
+ return typeof s == "function";
421
+ }
422
+ function ze(s) {
423
+ return typeof s == "function";
424
+ }
425
+ function pt(s) {
426
+ switch (Ee(s)) {
427
+ case 3:
428
+ return !0;
429
+ case 4:
430
+ return !0;
431
+ default:
432
+ return !1;
433
+ }
434
+ }
435
+ function pe(s, i) {
436
+ return s === i || s !== s && i !== i;
437
+ }
438
+ function De(s, i) {
439
+ var a = s[i];
440
+ if (a != null) {
441
+ if (!ne(a))
442
+ throw new TypeError();
443
+ return a;
444
+ }
445
+ }
446
+ function Re(s) {
447
+ var i = De(s, y);
448
+ if (!ne(i))
449
+ throw new TypeError();
450
+ var a = i.call(s);
451
+ if (!O(a))
452
+ throw new TypeError();
453
+ return a;
454
+ }
455
+ function ke(s) {
456
+ return s.value;
457
+ }
458
+ function Be(s) {
459
+ var i = s.next();
460
+ return i.done ? !1 : i;
461
+ }
462
+ function Ue(s) {
463
+ var i = s.return;
464
+ i && i.call(s);
465
+ }
466
+ function ye(s) {
467
+ var i = Object.getPrototypeOf(s);
468
+ if (typeof s != "function" || s === N || i !== N)
469
+ return i;
470
+ var a = s.prototype, l = a && Object.getPrototypeOf(a);
471
+ if (l == null || l === Object.prototype)
472
+ return i;
473
+ var v = l.constructor;
474
+ return typeof v != "function" || v === s ? i : v;
475
+ }
476
+ function yt() {
477
+ var s;
478
+ !g($) && typeof n.Reflect < "u" && !($ in n.Reflect) && typeof n.Reflect.defineMetadata == "function" && (s = mt(n.Reflect));
479
+ var i, a, l, v = new fe(), _ = {
480
+ registerProvider: P,
481
+ getProvider: u,
482
+ setProvider: d
483
+ };
484
+ return _;
485
+ function P(f) {
486
+ if (!Object.isExtensible(_))
487
+ throw new Error("Cannot add provider to a frozen registry.");
488
+ switch (!0) {
489
+ case s === f:
490
+ break;
491
+ case g(i):
492
+ i = f;
493
+ break;
494
+ case i === f:
495
+ break;
496
+ case g(a):
497
+ a = f;
498
+ break;
499
+ case a === f:
500
+ break;
501
+ default:
502
+ l === void 0 && (l = new de()), l.add(f);
503
+ break;
504
+ }
505
+ }
506
+ function w(f, m) {
507
+ if (!g(i)) {
508
+ if (i.isProviderFor(f, m))
509
+ return i;
510
+ if (!g(a)) {
511
+ if (a.isProviderFor(f, m))
512
+ return i;
513
+ if (!g(l))
514
+ for (var x = Re(l); ; ) {
515
+ var M = Be(x);
516
+ if (!M)
517
+ return;
518
+ var I = ke(M);
519
+ if (I.isProviderFor(f, m))
520
+ return Ue(x), I;
521
+ }
522
+ }
523
+ }
524
+ if (!g(s) && s.isProviderFor(f, m))
525
+ return s;
526
+ }
527
+ function u(f, m) {
528
+ var x = v.get(f), M;
529
+ return g(x) || (M = x.get(m)), g(M) && (M = w(f, m), g(M) || (g(x) && (x = new Y(), v.set(f, x)), x.set(m, M))), M;
530
+ }
531
+ function h(f) {
532
+ if (g(f))
533
+ throw new TypeError();
534
+ return i === f || a === f || !g(l) && l.has(f);
535
+ }
536
+ function d(f, m, x) {
537
+ if (!h(x))
538
+ throw new Error("Metadata provider not registered.");
539
+ var M = u(f, m);
540
+ if (M !== x) {
541
+ if (!g(M))
542
+ return !1;
543
+ var I = v.get(f);
544
+ g(I) && (I = new Y(), v.set(f, I)), I.set(m, x);
545
+ }
546
+ return !0;
547
+ }
548
+ }
549
+ function gt() {
550
+ var s;
551
+ return !g($) && O(n.Reflect) && Object.isExtensible(n.Reflect) && (s = n.Reflect[$]), g(s) && (s = yt()), !g($) && O(n.Reflect) && Object.isExtensible(n.Reflect) && Object.defineProperty(n.Reflect, $, {
552
+ enumerable: !1,
553
+ configurable: !1,
554
+ writable: !1,
555
+ value: s
556
+ }), s;
557
+ }
558
+ function wt(s) {
559
+ var i = new fe(), a = {
560
+ isProviderFor: function(h, d) {
561
+ var f = i.get(h);
562
+ return g(f) ? !1 : f.has(d);
563
+ },
564
+ OrdinaryDefineOwnMetadata: P,
565
+ OrdinaryHasOwnMetadata: v,
566
+ OrdinaryGetOwnMetadata: _,
567
+ OrdinaryOwnMetadataKeys: w,
568
+ OrdinaryDeleteMetadata: u
569
+ };
570
+ return se.registerProvider(a), a;
571
+ function l(h, d, f) {
572
+ var m = i.get(h), x = !1;
573
+ if (g(m)) {
574
+ if (!f)
575
+ return;
576
+ m = new Y(), i.set(h, m), x = !0;
577
+ }
578
+ var M = m.get(d);
579
+ if (g(M)) {
580
+ if (!f)
581
+ return;
582
+ if (M = new Y(), m.set(d, M), !s.setProvider(h, d, a))
583
+ throw m.delete(d), x && i.delete(h), new Error("Wrong provider for target.");
584
+ }
585
+ return M;
586
+ }
587
+ function v(h, d, f) {
588
+ var m = l(
589
+ d,
590
+ f,
591
+ /*Create*/
592
+ !1
593
+ );
594
+ return g(m) ? !1 : Ie(m.has(h));
595
+ }
596
+ function _(h, d, f) {
597
+ var m = l(
598
+ d,
599
+ f,
600
+ /*Create*/
601
+ !1
602
+ );
603
+ if (!g(m))
604
+ return m.get(h);
605
+ }
606
+ function P(h, d, f, m) {
607
+ var x = l(
608
+ f,
609
+ m,
610
+ /*Create*/
611
+ !0
612
+ );
613
+ x.set(h, d);
614
+ }
615
+ function w(h, d) {
616
+ var f = [], m = l(
617
+ h,
618
+ d,
619
+ /*Create*/
620
+ !1
621
+ );
622
+ if (g(m))
623
+ return f;
624
+ for (var x = m.keys(), M = Re(x), I = 0; ; ) {
625
+ var Ve = Be(M);
626
+ if (!Ve)
627
+ return f.length = I, f;
628
+ var Mt = ke(Ve);
629
+ try {
630
+ f[I] = Mt;
631
+ } catch (Ot) {
632
+ try {
633
+ Ue(M);
634
+ } finally {
635
+ throw Ot;
636
+ }
637
+ }
638
+ I++;
639
+ }
640
+ }
641
+ function u(h, d, f) {
642
+ var m = l(
643
+ d,
644
+ f,
645
+ /*Create*/
646
+ !1
647
+ );
648
+ if (g(m) || !m.delete(h))
649
+ return !1;
650
+ if (m.size === 0) {
651
+ var x = i.get(d);
652
+ g(x) || (x.delete(f), x.size === 0 && i.delete(x));
653
+ }
654
+ return !0;
655
+ }
656
+ }
657
+ function mt(s) {
658
+ var i = s.defineMetadata, a = s.hasOwnMetadata, l = s.getOwnMetadata, v = s.getOwnMetadataKeys, _ = s.deleteMetadata, P = new fe(), w = {
659
+ isProviderFor: function(u, h) {
660
+ var d = P.get(u);
661
+ return !g(d) && d.has(h) ? !0 : v(u, h).length ? (g(d) && (d = new de(), P.set(u, d)), d.add(h), !0) : !1;
662
+ },
663
+ OrdinaryDefineOwnMetadata: i,
664
+ OrdinaryHasOwnMetadata: a,
665
+ OrdinaryGetOwnMetadata: l,
666
+ OrdinaryOwnMetadataKeys: v,
667
+ OrdinaryDeleteMetadata: _
668
+ };
669
+ return w;
670
+ }
671
+ function H(s, i, a) {
672
+ var l = se.getProvider(s, i);
673
+ if (!g(l))
674
+ return l;
675
+ if (a) {
676
+ if (se.setProvider(s, i, Se))
677
+ return Se;
678
+ throw new Error("Illegal state.");
679
+ }
680
+ }
681
+ function bt() {
682
+ var s = {}, i = [], a = (
683
+ /** @class */
684
+ (function() {
685
+ function w(u, h, d) {
686
+ this._index = 0, this._keys = u, this._values = h, this._selector = d;
687
+ }
688
+ return w.prototype["@@iterator"] = function() {
689
+ return this;
690
+ }, w.prototype[y] = function() {
691
+ return this;
692
+ }, w.prototype.next = function() {
693
+ var u = this._index;
694
+ if (u >= 0 && u < this._keys.length) {
695
+ var h = this._selector(this._keys[u], this._values[u]);
696
+ return u + 1 >= this._keys.length ? (this._index = -1, this._keys = i, this._values = i) : this._index++, { value: h, done: !1 };
697
+ }
698
+ return { value: void 0, done: !0 };
699
+ }, w.prototype.throw = function(u) {
700
+ throw this._index >= 0 && (this._index = -1, this._keys = i, this._values = i), u;
701
+ }, w.prototype.return = function(u) {
702
+ return this._index >= 0 && (this._index = -1, this._keys = i, this._values = i), { value: u, done: !0 };
703
+ }, w;
704
+ })()
705
+ ), l = (
706
+ /** @class */
707
+ (function() {
708
+ function w() {
709
+ this._keys = [], this._values = [], this._cacheKey = s, this._cacheIndex = -2;
710
+ }
711
+ return Object.defineProperty(w.prototype, "size", {
712
+ get: function() {
713
+ return this._keys.length;
714
+ },
715
+ enumerable: !0,
716
+ configurable: !0
717
+ }), w.prototype.has = function(u) {
718
+ return this._find(
719
+ u,
720
+ /*insert*/
721
+ !1
722
+ ) >= 0;
723
+ }, w.prototype.get = function(u) {
724
+ var h = this._find(
725
+ u,
726
+ /*insert*/
727
+ !1
728
+ );
729
+ return h >= 0 ? this._values[h] : void 0;
730
+ }, w.prototype.set = function(u, h) {
731
+ var d = this._find(
732
+ u,
733
+ /*insert*/
734
+ !0
735
+ );
736
+ return this._values[d] = h, this;
737
+ }, w.prototype.delete = function(u) {
738
+ var h = this._find(
739
+ u,
740
+ /*insert*/
741
+ !1
742
+ );
743
+ if (h >= 0) {
744
+ for (var d = this._keys.length, f = h + 1; f < d; f++)
745
+ this._keys[f - 1] = this._keys[f], this._values[f - 1] = this._values[f];
746
+ return this._keys.length--, this._values.length--, pe(u, this._cacheKey) && (this._cacheKey = s, this._cacheIndex = -2), !0;
747
+ }
748
+ return !1;
749
+ }, w.prototype.clear = function() {
750
+ this._keys.length = 0, this._values.length = 0, this._cacheKey = s, this._cacheIndex = -2;
751
+ }, w.prototype.keys = function() {
752
+ return new a(this._keys, this._values, v);
753
+ }, w.prototype.values = function() {
754
+ return new a(this._keys, this._values, _);
755
+ }, w.prototype.entries = function() {
756
+ return new a(this._keys, this._values, P);
757
+ }, w.prototype["@@iterator"] = function() {
758
+ return this.entries();
759
+ }, w.prototype[y] = function() {
760
+ return this.entries();
761
+ }, w.prototype._find = function(u, h) {
762
+ if (!pe(this._cacheKey, u)) {
763
+ this._cacheIndex = -1;
764
+ for (var d = 0; d < this._keys.length; d++)
765
+ if (pe(this._keys[d], u)) {
766
+ this._cacheIndex = d;
767
+ break;
768
+ }
769
+ }
770
+ return this._cacheIndex < 0 && h && (this._cacheIndex = this._keys.length, this._keys.push(u), this._values.push(void 0)), this._cacheIndex;
771
+ }, w;
772
+ })()
773
+ );
774
+ return l;
775
+ function v(w, u) {
776
+ return w;
777
+ }
778
+ function _(w, u) {
779
+ return u;
780
+ }
781
+ function P(w, u) {
782
+ return [w, u];
783
+ }
784
+ }
785
+ function xt() {
786
+ var s = (
787
+ /** @class */
788
+ (function() {
789
+ function i() {
790
+ this._map = new Y();
791
+ }
792
+ return Object.defineProperty(i.prototype, "size", {
793
+ get: function() {
794
+ return this._map.size;
795
+ },
796
+ enumerable: !0,
797
+ configurable: !0
798
+ }), i.prototype.has = function(a) {
799
+ return this._map.has(a);
800
+ }, i.prototype.add = function(a) {
801
+ return this._map.set(a, a), this;
802
+ }, i.prototype.delete = function(a) {
803
+ return this._map.delete(a);
804
+ }, i.prototype.clear = function() {
805
+ this._map.clear();
806
+ }, i.prototype.keys = function() {
807
+ return this._map.keys();
808
+ }, i.prototype.values = function() {
809
+ return this._map.keys();
810
+ }, i.prototype.entries = function() {
811
+ return this._map.entries();
812
+ }, i.prototype["@@iterator"] = function() {
813
+ return this.keys();
814
+ }, i.prototype[y] = function() {
815
+ return this.keys();
816
+ }, i;
817
+ })()
818
+ );
819
+ return s;
820
+ }
821
+ function St() {
822
+ var s = 16, i = R.create(), a = l();
823
+ return (
824
+ /** @class */
825
+ (function() {
826
+ function u() {
827
+ this._key = l();
828
+ }
829
+ return u.prototype.has = function(h) {
830
+ var d = v(
831
+ h,
832
+ /*create*/
833
+ !1
834
+ );
835
+ return d !== void 0 ? R.has(d, this._key) : !1;
836
+ }, u.prototype.get = function(h) {
837
+ var d = v(
838
+ h,
839
+ /*create*/
840
+ !1
841
+ );
842
+ return d !== void 0 ? R.get(d, this._key) : void 0;
843
+ }, u.prototype.set = function(h, d) {
844
+ var f = v(
845
+ h,
846
+ /*create*/
847
+ !0
848
+ );
849
+ return f[this._key] = d, this;
850
+ }, u.prototype.delete = function(h) {
851
+ var d = v(
852
+ h,
853
+ /*create*/
854
+ !1
855
+ );
856
+ return d !== void 0 ? delete d[this._key] : !1;
857
+ }, u.prototype.clear = function() {
858
+ this._key = l();
859
+ }, u;
860
+ })()
861
+ );
862
+ function l() {
863
+ var u;
864
+ do
865
+ u = "@@WeakMap@@" + w();
866
+ while (R.has(i, u));
867
+ return i[u] = !0, u;
868
+ }
869
+ function v(u, h) {
870
+ if (!r.call(u, a)) {
871
+ if (!h)
872
+ return;
873
+ Object.defineProperty(u, a, { value: R.create() });
874
+ }
875
+ return u[a];
876
+ }
877
+ function _(u, h) {
878
+ for (var d = 0; d < h; ++d)
879
+ u[d] = Math.random() * 255 | 0;
880
+ return u;
881
+ }
882
+ function P(u) {
883
+ if (typeof Uint8Array == "function") {
884
+ var h = new Uint8Array(u);
885
+ return typeof crypto < "u" ? crypto.getRandomValues(h) : typeof msCrypto < "u" ? msCrypto.getRandomValues(h) : _(h, u), h;
886
+ }
887
+ return _(new Array(u), u);
888
+ }
889
+ function w() {
890
+ var u = P(s);
891
+ u[6] = u[6] & 79 | 64, u[8] = u[8] & 191 | 128;
892
+ for (var h = "", d = 0; d < s; ++d) {
893
+ var f = u[d];
894
+ (d === 4 || d === 6 || d === 8) && (h += "-"), f < 16 && (h += "0"), h += f.toString(16).toLowerCase();
895
+ }
896
+ return h;
897
+ }
898
+ }
899
+ function ge(s) {
900
+ return s.__ = void 0, delete s.__, s;
901
+ }
902
+ });
903
+ })(o || (o = {})), Ge;
904
+ }
905
+ Lt();
906
+ class qe extends Error {
907
+ constructor() {
908
+ super(...arguments), this.name = this.constructor.name;
909
+ }
910
+ }
911
+ class $t extends qe {
912
+ constructor(e, t) {
913
+ super(`"${t}" not found in Mesh "${e}"`);
914
+ }
915
+ }
916
+ class Ke extends qe {
917
+ constructor(e) {
918
+ super(`Invalid binding "${e}". Valid bindings are: string to constructor e.g. ("MyService", MyService) or abstract class to constructor e.g. (MyService, MyServiceImpl) orconstructor to self e.g. (MyService)`);
919
+ }
920
+ }
921
+ function D(o) {
922
+ return typeof o == "string" ? o : o.name;
923
+ }
924
+ function At(o) {
925
+ return typeof o == "function" && o.prototype != null;
926
+ }
927
+ function Gt(o, ...e) {
928
+ return At(o) ? new o(...e) : o(...e);
929
+ }
930
+ const Je = /* @__PURE__ */ Symbol.for("MESH_REF");
931
+ class ae {
932
+ constructor(e = "default", t = void 0) {
933
+ this.name = e, this.parent = t, this.bindings = /* @__PURE__ */ new Map(), this.instances = /* @__PURE__ */ new Map(), this.middlewares = [], this.constant(ae, this), this.injectRef(this);
934
+ }
935
+ *[Symbol.iterator]() {
936
+ yield* this.bindings.entries();
937
+ }
938
+ clone() {
939
+ const e = new ae();
940
+ return e.parent = this.parent, e.bindings = new Map(this.bindings), e;
941
+ }
942
+ connect(e) {
943
+ const t = this.applyMiddleware(e);
944
+ return this.injectRef(t), t;
945
+ }
946
+ use(e) {
947
+ return this.middlewares.push(e), this;
948
+ }
949
+ service(e, t) {
950
+ const n = D(e);
951
+ if (typeof t == "function")
952
+ return this.bindings.set(n, { type: "service", class: t }), this;
953
+ if (typeof e == "function")
954
+ return this.bindings.set(n, { type: "service", class: e }), this;
955
+ throw new Ke(String(e));
956
+ }
957
+ scope(e, t) {
958
+ const n = D(e);
959
+ if (typeof t == "function")
960
+ return this.bindings.set(n, { type: "scope", factory: t }), this;
961
+ if (typeof e == "function")
962
+ return this.bindings.set(n, { type: "scope", factory: e }), this;
963
+ throw new Ke(String(e));
964
+ }
965
+ constant(e, t) {
966
+ const n = D(e);
967
+ return this.bindings.set(n, { type: "constant", value: t }), this;
968
+ }
969
+ alias(e, t) {
970
+ const n = D(e), r = D(t);
971
+ return this.bindings.set(n, { type: "alias", key: r }), this;
972
+ }
973
+ delete(e) {
974
+ const t = D(e);
975
+ return this.bindings.delete(t), this;
976
+ }
977
+ resolve(e, t = !0) {
978
+ const n = this.tryResolve(e, t);
979
+ if (n === void 0) {
980
+ const r = D(e);
981
+ throw new $t(this.name, r);
982
+ }
983
+ return n;
984
+ }
985
+ tryResolve(e, t = !0) {
986
+ const n = D(e);
987
+ let r = this.instances.get(n);
988
+ if (r)
989
+ return r;
990
+ const c = this.bindings.get(n);
991
+ if (c)
992
+ return r = this.instantiate(c), r = this.connect(r), this.instances.set(n, r), r;
993
+ if (t && this.parent)
994
+ return this.parent.tryResolve(e);
995
+ }
996
+ getBinding(e, t = !0) {
997
+ const n = D(e), r = this.bindings.get(n);
998
+ if (r)
999
+ return r;
1000
+ if (t && this.parent)
1001
+ return this.parent.getBinding(e);
1002
+ }
1003
+ *allBindings() {
1004
+ yield* this.bindings.entries(), this.parent && (yield* this.parent.allBindings());
1005
+ }
1006
+ *missingDeps() {
1007
+ for (const e of this.allDeps())
1008
+ this.getBinding(e.key) || (yield e);
1009
+ }
1010
+ *allDeps() {
1011
+ const e = /* @__PURE__ */ new Set();
1012
+ for (const [, t] of this.allBindings())
1013
+ t.type === "service" && (yield* this.traverseClassDeps(t.class, e));
1014
+ }
1015
+ *traverseClassDeps(e, t = /* @__PURE__ */ new Set()) {
1016
+ const n = Kt(e);
1017
+ for (const r of n) {
1018
+ if (t.has(r.key))
1019
+ continue;
1020
+ t.add(r.key), yield r;
1021
+ const c = this.getBinding(r.key);
1022
+ c?.type === "service" && (yield* this.traverseClassDeps(c.class, t));
1023
+ }
1024
+ }
1025
+ instantiate(e) {
1026
+ switch (e.type) {
1027
+ case "alias":
1028
+ return this.resolve(e.key);
1029
+ case "service": {
1030
+ const t = e.class, n = class extends t {
1031
+ };
1032
+ return Object.defineProperty(n, "name", { value: t.name }), this.injectRef(n.prototype), new n();
1033
+ }
1034
+ case "constant":
1035
+ return e.value;
1036
+ case "scope":
1037
+ return (n) => Gt(e.factory, n ?? this);
1038
+ }
1039
+ }
1040
+ applyMiddleware(e) {
1041
+ let t = e;
1042
+ for (const n of this.middlewares)
1043
+ t = n(t);
1044
+ return this.parent && (t = this.parent.applyMiddleware(t)), t;
1045
+ }
1046
+ injectRef(e) {
1047
+ typeof e == "object" && Object.defineProperty(e, Je, {
1048
+ get: () => this,
1049
+ enumerable: !1,
1050
+ configurable: !0
1051
+ });
1052
+ }
1053
+ }
1054
+ const Ft = [];
1055
+ function Kt(o) {
1056
+ const e = [];
1057
+ let t = o;
1058
+ for (; t !== Object.prototype; ) {
1059
+ const n = Ft.filter((r) => r.class === t);
1060
+ e.push(...n), t = Object.getPrototypeOf(t);
1061
+ }
1062
+ return e;
1063
+ }
1064
+ const Nt = Object.getOwnPropertyNames(Reflect);
1065
+ function b(o, e, t = !0) {
1066
+ let n;
1067
+ const r = {};
1068
+ for (const c of Nt)
1069
+ r[c] = function(p, ...y) {
1070
+ let S = n;
1071
+ return S || (S = o[Je].resolve(e)), t && (n = S), Reflect[c](S, ...y);
1072
+ };
1073
+ return new Proxy(o, r);
1074
+ }
1075
+ class J {
1076
+ constructor() {
1077
+ this.autoCenter = !0, this.allowMultiSelect = !0;
1078
+ }
1079
+ set(e) {
1080
+ Object.assign(this, e);
1081
+ }
1082
+ }
1083
+ class F {
1084
+ constructor() {
1085
+ this._groups = /* @__PURE__ */ new Map();
1086
+ }
1087
+ on(e, t = /* @__PURE__ */ Symbol()) {
1088
+ let n = this._groups.get(t);
1089
+ return n || (n = /* @__PURE__ */ new Set(), this._groups.set(t, n)), n.add(e), () => this.remove(e, t);
1090
+ }
1091
+ once(e, t = /* @__PURE__ */ Symbol()) {
1092
+ const n = (r) => {
1093
+ e(r), this.remove(n, t);
1094
+ };
1095
+ return this.on(n, t);
1096
+ }
1097
+ remove(e, t) {
1098
+ const n = this._groups.get(t);
1099
+ n && (n.delete(e), n.size === 0 && this._groups.delete(t));
1100
+ }
1101
+ removeAll(e) {
1102
+ this._groups.delete(e);
1103
+ }
1104
+ emit(e) {
1105
+ for (const t of this._groups.values())
1106
+ for (const n of t)
1107
+ n(e);
1108
+ }
1109
+ }
1110
+ class k {
1111
+ constructor() {
1112
+ this.mounted = new F(), this.unmounted = new F(), this.selectionChanged = new F(), this.dragMove = new F(), this.dragEnd = new F(), this.objectPosUpdated = new F();
1113
+ }
1114
+ }
1115
+ const we = /* @__PURE__ */ new Map();
1116
+ function Yt(o) {
1117
+ return function(t) {
1118
+ return (n, r) => {
1119
+ const c = we.get(o) || [];
1120
+ we.set(o, c), c.push({
1121
+ target: n.constructor,
1122
+ memberName: r,
1123
+ metadata: t
1124
+ });
1125
+ };
1126
+ };
1127
+ }
1128
+ function Ht(o) {
1129
+ return we.get(o) || [];
1130
+ }
1131
+ function Xt(o, e, t = !0) {
1132
+ const n = [], r = Ht(o), c = t ? e.allBindings() : e.bindings.entries();
1133
+ for (const [p, y] of c)
1134
+ if (y.type === "service")
1135
+ for (const { target: S, memberName: C, metadata: E } of r)
1136
+ (S === y.class || Object.prototype.isPrototypeOf.call(S, y.class)) && n.push({
1137
+ target: e.resolve(p),
1138
+ memberName: C,
1139
+ metadata: E
1140
+ });
1141
+ return n;
1142
+ }
1143
+ function Wt(o, e, t = !0, ...n) {
1144
+ return Xt(o, e, t).map((p) => p.target[p.memberName](...n));
1145
+ }
1146
+ const he = Yt("init");
1147
+ async function Ne(o, e = !0) {
1148
+ const t = Wt("init", o, e);
1149
+ await Promise.all(t);
1150
+ }
1151
+ class ce {
1152
+ constructor() {
1153
+ this.objects = /* @__PURE__ */ new Map();
1154
+ }
1155
+ register(e) {
1156
+ this.objects.set(e.objectId, e);
1157
+ }
1158
+ unregister(e) {
1159
+ this.objects.delete(e);
1160
+ }
1161
+ get(e) {
1162
+ return this.objects.get(e) ?? null;
1163
+ }
1164
+ getAll() {
1165
+ return [...this.objects.values()];
1166
+ }
1167
+ }
1168
+ class Q {
1169
+ constructor() {
1170
+ this.selectedIds = /* @__PURE__ */ new Set(), this.events = b(this, k);
1171
+ }
1172
+ get size() {
1173
+ return this.selectedIds.size;
1174
+ }
1175
+ getSelectedIds() {
1176
+ return [...this.selectedIds];
1177
+ }
1178
+ getFirst() {
1179
+ return [...this.selectedIds][0] ?? null;
1180
+ }
1181
+ isSelected(e) {
1182
+ return this.selectedIds.has(e);
1183
+ }
1184
+ isSingleSelected(e) {
1185
+ return this.selectedIds.size === 1 && this.selectedIds.has(e);
1186
+ }
1187
+ setSelectedIds(e) {
1188
+ const t = new Set(this.selectedIds);
1189
+ this.selectedIds = new Set(e), this.notifySelectionChanged(t);
1190
+ }
1191
+ selectSingle(e) {
1192
+ if (this.isSingleSelected(e))
1193
+ return;
1194
+ const t = new Set(this.selectedIds);
1195
+ this.selectedIds.clear(), this.selectedIds.add(e), this.notifySelectionChanged(t);
1196
+ }
1197
+ addToSelection(...e) {
1198
+ const t = new Set(this.selectedIds);
1199
+ for (const n of e)
1200
+ this.selectedIds.add(n);
1201
+ this.notifySelectionChanged(t);
1202
+ }
1203
+ removeFromSelection(...e) {
1204
+ const t = new Set(this.selectedIds);
1205
+ for (const n of e)
1206
+ this.selectedIds.delete(n);
1207
+ this.notifySelectionChanged(t);
1208
+ }
1209
+ toggleSelection(e) {
1210
+ if (this.isSelected(e)) {
1211
+ this.removeFromSelection(e);
1212
+ return;
1213
+ }
1214
+ this.addToSelection(e);
1215
+ }
1216
+ deselectAll() {
1217
+ if (this.selectedIds.size === 0)
1218
+ return;
1219
+ const e = new Set(this.selectedIds);
1220
+ this.selectedIds.clear(), this.notifySelectionChanged(e);
1221
+ }
1222
+ notifySelectionChanged(e) {
1223
+ if (e.size === this.selectedIds.size) {
1224
+ let t = !1;
1225
+ for (const n of e)
1226
+ if (!this.selectedIds.has(n)) {
1227
+ t = !0;
1228
+ break;
1229
+ }
1230
+ if (!t)
1231
+ return;
1232
+ }
1233
+ this.events.selectionChanged.emit(this.getSelectedIds());
1234
+ }
1235
+ setSelected(e, t) {
1236
+ if (t) {
1237
+ this.addToSelection(e);
1238
+ return;
1239
+ }
1240
+ this.removeFromSelection(e);
1241
+ }
1242
+ }
1243
+ class L {
1244
+ constructor() {
1245
+ this.zoom = 1, this.cellSize = 32, this.scrollPos = { x: 0, y: 0 }, this.viewportBox = [{ x: 0, y: 0 }, { x: 0, y: 0 }], this.canvasOrigin = { x: 0, y: 0 }, this.canvasSize = { x: 0, y: 0 };
1246
+ }
1247
+ localToCanvas(e) {
1248
+ return {
1249
+ x: e.x * this.cellSize + this.canvasOrigin.x,
1250
+ y: e.y * this.cellSize + this.canvasOrigin.y
1251
+ };
1252
+ }
1253
+ canvasToLocal(e) {
1254
+ return {
1255
+ x: (e.x - this.canvasOrigin.x) / this.cellSize,
1256
+ y: (e.y - this.canvasOrigin.y) / this.cellSize
1257
+ };
1258
+ }
1259
+ viewportToCanvas(e) {
1260
+ return {
1261
+ x: (e.x + this.scrollPos.x) / this.zoom,
1262
+ y: (e.y + this.scrollPos.y) / this.zoom
1263
+ };
1264
+ }
1265
+ canvasToViewport(e) {
1266
+ return {
1267
+ x: e.x * this.zoom - this.scrollPos.x,
1268
+ y: e.y * this.zoom - this.scrollPos.y
1269
+ };
1270
+ }
1271
+ viewportToLocal(e) {
1272
+ return this.canvasToLocal(this.viewportToCanvas(e));
1273
+ }
1274
+ localToViewport(e) {
1275
+ return this.canvasToViewport(this.localToCanvas(e));
1276
+ }
1277
+ pageToViewport(e) {
1278
+ return {
1279
+ x: e.x - this.viewportBox[0].x,
1280
+ y: e.y - this.viewportBox[0].y
1281
+ };
1282
+ }
1283
+ pageToCanvas(e) {
1284
+ return this.viewportToCanvas(this.pageToViewport(e));
1285
+ }
1286
+ pageToLocal(e) {
1287
+ return this.canvasToLocal(this.pageToCanvas(e));
1288
+ }
1289
+ getViewportCenterInLocal() {
1290
+ const e = Bt(this.viewportBox), t = this.pageToViewport(e);
1291
+ return this.viewportToLocal(t);
1292
+ }
1293
+ }
1294
+ var Zt = Object.defineProperty, qt = Object.getOwnPropertyDescriptor, Jt = (o, e, t, n) => {
1295
+ for (var r = qt(e, t), c = o.length - 1, p; c >= 0; c--)
1296
+ (p = o[c]) && (r = p(e, t, r) || r);
1297
+ return r && Zt(e, t, r), r;
1298
+ };
1299
+ class xe {
1300
+ constructor() {
1301
+ this.events = b(this, k), this.selection = b(this, Q), this.objectRegistry = b(this, ce), this.space = b(this, L), this.movingIds = /* @__PURE__ */ new Set(), this.moveOriginPos = null;
1302
+ }
1303
+ init() {
1304
+ this.events.dragMove.on((e) => this.onDragMove(e)), this.events.dragEnd.on(() => this.stopMovingSelection()), this.events.unmounted.on(() => this.stopMovingSelection());
1305
+ }
1306
+ isMoving(e) {
1307
+ return this.movingIds.has(e);
1308
+ }
1309
+ startMovingSelection(e) {
1310
+ this.movingIds = new Set(this.selection.getSelectedIds()), this.moveOriginPos = { x: e.pageX, y: e.pageY };
1311
+ for (const t of this.movingIds)
1312
+ this.objectRegistry.get(t)?.onMoveStart();
1313
+ }
1314
+ onDragMove(e) {
1315
+ if (!this.moveOriginPos)
1316
+ return;
1317
+ const t = this.space.pageToLocal(this.moveOriginPos), n = this.space.pageToLocal({ x: e.pageX, y: e.pageY }), r = We(n, t);
1318
+ for (const c of this.movingIds)
1319
+ this.objectRegistry.get(c)?.onMoveOffset(r);
1320
+ }
1321
+ stopMovingSelection() {
1322
+ for (const e of this.movingIds)
1323
+ this.objectRegistry.get(e)?.onMoveEnd();
1324
+ this.movingIds.clear(), this.moveOriginPos = null;
1325
+ }
1326
+ }
1327
+ Jt([
1328
+ he()
1329
+ ], xe.prototype, "init");
1330
+ class Qt {
1331
+ constructor(e) {
1332
+ this.config = b(this, J), this.events = b(this, k), this.selection = b(this, Q), this.move = b(this, xe), this.space = b(this, L), this.element = null, this.selectable = !0, this.movable = !0, this.snapToGrid = !0, this.resizable = "none", this.bounds = [{ x: 1, y: 1 }, { x: 10, y: 10 }], this.pos = { x: 0, y: 0 }, this.localPos = { x: 0, y: 0, w: 1, h: 1 }, this.prevLocalPos = { x: 0, y: 0, w: 1, h: 1 }, this.resizingDirection = null, this.resizingBounds = [{ x: 0, y: 0 }, { x: 0, y: 0 }], this.objectId = e;
1333
+ }
1334
+ setElement(e) {
1335
+ this.element = e;
1336
+ }
1337
+ getPos() {
1338
+ return this.pos;
1339
+ }
1340
+ setPos(e) {
1341
+ this.pos = e, !this.isMoving() && !this.isResizing() && this.recalcLocalPos();
1342
+ }
1343
+ getBounds() {
1344
+ return this.bounds;
1345
+ }
1346
+ setBounds(e) {
1347
+ this.bounds = e, !this.isMoving() && !this.isResizing() && this.recalcLocalPos();
1348
+ }
1349
+ isSelectable() {
1350
+ return this.selectable;
1351
+ }
1352
+ setSelectable(e) {
1353
+ this.selectable = e, e || this.selection.removeFromSelection(this.objectId);
1354
+ }
1355
+ isSelected() {
1356
+ return this.selection.isSelected(this.objectId);
1357
+ }
1358
+ setSelected(e) {
1359
+ e && !this.selectable || this.selection.setSelected(this.objectId, e);
1360
+ }
1361
+ isMovable() {
1362
+ return this.movable;
1363
+ }
1364
+ setMovable(e) {
1365
+ this.movable = e;
1366
+ }
1367
+ isSnapToGrid() {
1368
+ return this.snapToGrid;
1369
+ }
1370
+ setSnapToGrid(e) {
1371
+ this.snapToGrid = e;
1372
+ }
1373
+ isResizable() {
1374
+ return this.resizable;
1375
+ }
1376
+ setResizable(e) {
1377
+ this.resizable = e;
1378
+ }
1379
+ /* Render state */
1380
+ getCanvasCoords() {
1381
+ const e = this.space.localToCanvas({ x: this.localPos.x, y: this.localPos.y }), t = this.space.localToCanvas({
1382
+ x: this.localPos.x + this.localPos.w,
1383
+ y: this.localPos.y + this.localPos.h
1384
+ }), n = We(t, e), r = this.pos.w === void 0 ? void 0 : n.x, c = this.pos.h === void 0 ? void 0 : n.y;
1385
+ return {
1386
+ x: e.x,
1387
+ y: e.y,
1388
+ w: r,
1389
+ h: c
1390
+ };
1391
+ }
1392
+ getStyle() {
1393
+ const e = this.getCanvasCoords();
1394
+ return {
1395
+ position: "absolute",
1396
+ left: `${e.x}px`,
1397
+ top: `${e.y}px`,
1398
+ width: e.w === void 0 ? void 0 : `${e.w}px`,
1399
+ height: e.h === void 0 ? void 0 : `${e.h}px`
1400
+ };
1401
+ }
1402
+ isMoving() {
1403
+ return this.move.isMoving(this.objectId);
1404
+ }
1405
+ isResizing() {
1406
+ return this.resizingDirection != null;
1407
+ }
1408
+ commitNewPos(e) {
1409
+ Object.assign(this.pos, e), this.events.objectPosUpdated.emit({
1410
+ objectId: this.objectId,
1411
+ pos: { ...this.pos }
1412
+ });
1413
+ }
1414
+ // Event handlers
1415
+ /**
1416
+ * Click handles selection
1417
+ * Shift/Ctrl/Meta key allows multi-select, if allowed by canvas config
1418
+ */
1419
+ onUiClick(e) {
1420
+ if (!this.selectable)
1421
+ return;
1422
+ const t = e.shiftKey || e.ctrlKey || e.metaKey;
1423
+ if (this.config.allowMultiSelect && t) {
1424
+ this.selection.toggleSelection(this.objectId);
1425
+ return;
1426
+ }
1427
+ this.selection.selectSingle(this.objectId);
1428
+ }
1429
+ /**
1430
+ * Dragging starts moving selected objects, if allowed.
1431
+ * If not selected, single selection is performed first, then dragging starts.
1432
+ */
1433
+ onUiDragStart(e) {
1434
+ this.movable && (this.isSelected() || (e.shiftKey ? this.selection.addToSelection(this.objectId) : this.selection.selectSingle(this.objectId)), !this.isResizing() && !this.isMoving() && this.move.startMovingSelection(e));
1435
+ }
1436
+ /**
1437
+ * Drag move is re-emitted to global canvas events, so that each selected object moves.
1438
+ * CanvasMove will call onMoveOffset on objects that are currently moving.
1439
+ */
1440
+ onUiDragMove(e) {
1441
+ this.events.dragMove.emit(e);
1442
+ }
1443
+ /**
1444
+ * Drag end is re-emitted to global canvas events, so that each selected object stops moving.
1445
+ * CanvasMove will call onMoveEnd on objects that are currently moving.
1446
+ */
1447
+ onUiDragEnd(e) {
1448
+ this.events.dragEnd.emit(e);
1449
+ }
1450
+ /* Moving */
1451
+ /**
1452
+ * Move start is called by CanvasMove when selected objects starts moving.
1453
+ * It saves the previous local position, so that the offset can be calculated.
1454
+ */
1455
+ onMoveStart() {
1456
+ this.prevLocalPos = { ...this.localPos };
1457
+ }
1458
+ /**
1459
+ * Move offset is called by CanvasMove when selected objects moves.
1460
+ * It calculates the new local position based on the previous local position and the offset.
1461
+ */
1462
+ onMoveOffset(e) {
1463
+ this.movable && (this.localPos = {
1464
+ x: this.prevLocalPos.x + e.x,
1465
+ y: this.prevLocalPos.y + e.y,
1466
+ w: this.prevLocalPos.w,
1467
+ h: this.prevLocalPos.h
1468
+ });
1469
+ }
1470
+ /**
1471
+ * Move end is called by CanvasMove when selected objects stops moving.
1472
+ * It commits the new local position to the object.
1473
+ */
1474
+ onMoveEnd() {
1475
+ this.commitNewPos({
1476
+ x: this.maybeRound(this.localPos.x),
1477
+ y: this.maybeRound(this.localPos.y)
1478
+ });
1479
+ }
1480
+ /* Resizing */
1481
+ startResizing(e) {
1482
+ this.resizable === "none" || !this.canResizeInDirection(e) || (this.resizingDirection = e, this.resizingBounds = this.getObjectBounds(), this.selection.selectSingle(this.objectId));
1483
+ }
1484
+ onResizeMove(e) {
1485
+ if (!this.resizingDirection)
1486
+ return;
1487
+ const t = { x: e.pageX, y: e.pageY }, n = this.space.pageToLocal(t), [r, c] = this.getResizingUpdates(this.resizingDirection, n);
1488
+ this.localPos = {
1489
+ x: r.x,
1490
+ y: r.y,
1491
+ w: c.x - r.x,
1492
+ h: c.y - r.y
1493
+ };
1494
+ }
1495
+ onResizeEnd() {
1496
+ this.resizingDirection && (this.commitNewPos({
1497
+ x: this.maybeRound(this.localPos.x),
1498
+ y: this.maybeRound(this.localPos.y),
1499
+ w: z(this.maybeRound(this.localPos.w), this.bounds[0].x, this.bounds[1].x),
1500
+ h: z(this.maybeRound(this.localPos.h), this.bounds[0].y, this.bounds[1].y)
1501
+ }), this.resizingDirection = null);
1502
+ }
1503
+ getResizeDirections() {
1504
+ switch (this.resizable) {
1505
+ case "both":
1506
+ return ["n", "ne", "e", "se", "s", "sw", "w", "nw"];
1507
+ case "horizontal":
1508
+ return ["e", "w"];
1509
+ case "vertical":
1510
+ return ["n", "s"];
1511
+ default:
1512
+ return [];
1513
+ }
1514
+ }
1515
+ getObjectBounds() {
1516
+ const e = { x: this.localPos.x, y: this.localPos.y }, t = {
1517
+ x: this.localPos.x + this.localPos.w,
1518
+ y: this.localPos.y + this.localPos.h
1519
+ };
1520
+ return [e, t];
1521
+ }
1522
+ canResizeInDirection(e) {
1523
+ return this.getResizeDirections().includes(e);
1524
+ }
1525
+ recalcLocalPos() {
1526
+ const e = this.pos.w ?? this.localPos.w, t = this.pos.h ?? this.localPos.h;
1527
+ this.localPos = {
1528
+ x: this.pos.x,
1529
+ y: this.pos.y,
1530
+ w: z(e, this.bounds[0].x, this.bounds[1].x),
1531
+ h: z(t, this.bounds[0].y, this.bounds[1].y)
1532
+ };
1533
+ }
1534
+ maybeRound(e) {
1535
+ return this.snapToGrid ? Math.round(e) : e;
1536
+ }
1537
+ getResizingUpdates(e, t) {
1538
+ const [n, r] = this.resizingBounds, c = z(t.x, r.x - this.bounds[1].x, r.x - this.bounds[0].x), p = z(t.x, n.x + this.bounds[0].x, n.x + this.bounds[1].x), y = z(t.y, r.y - this.bounds[1].y, r.y - this.bounds[0].y), S = z(t.y, n.y + this.bounds[0].y, n.y + this.bounds[1].y);
1539
+ switch (e) {
1540
+ case "n":
1541
+ return [{ x: n.x, y }, { x: r.x, y: r.y }];
1542
+ case "s":
1543
+ return [{ x: n.x, y: n.y }, { x: r.x, y: S }];
1544
+ case "w":
1545
+ return [{ x: c, y: n.y }, { x: r.x, y: r.y }];
1546
+ case "e":
1547
+ return [{ x: n.x, y: n.y }, { x: p, y: r.y }];
1548
+ case "ne":
1549
+ return [{ x: n.x, y }, { x: p, y: r.y }];
1550
+ case "nw":
1551
+ return [{ x: c, y }, { x: r.x, y: r.y }];
1552
+ case "se":
1553
+ return [{ x: n.x, y: n.y }, { x: p, y: S }];
1554
+ case "sw":
1555
+ return [{ x: c, y: n.y }, { x: r.x, y: S }];
1556
+ default:
1557
+ return [{ x: n.x, y: n.y }, { x: r.x, y: r.y }];
1558
+ }
1559
+ }
1560
+ }
1561
+ const es = {
1562
+ props: {
1563
+ canvasObject: { type: Object, required: !0 },
1564
+ direction: { type: String, required: !0 }
1565
+ }
1566
+ };
1567
+ function ts(o, e, t, n, r, c) {
1568
+ return V(), q("div", {
1569
+ class: _t(["ResizeHandle", `ResizeHandle-${t.direction}`]),
1570
+ onUidragstart: e[0] || (e[0] = U((p) => t.canvasObject.startResizing(t.direction), ["stop", "prevent"])),
1571
+ onUidragmove: e[1] || (e[1] = U((...p) => t.canvasObject.onResizeMove && t.canvasObject.onResizeMove(...p), ["stop", "prevent"])),
1572
+ onUidragend: e[2] || (e[2] = U((...p) => t.canvasObject.onResizeEnd && t.canvasObject.onResizeEnd(...p), ["stop", "prevent"]))
1573
+ }, null, 34);
1574
+ }
1575
+ const ss = /* @__PURE__ */ te(es, [["render", ts], ["__scopeId", "data-v-c83350e5"]]), ns = {
1576
+ components: {
1577
+ CanvasObjectResize: ss
1578
+ },
1579
+ props: {
1580
+ canvas: { type: Object, required: !0 },
1581
+ objectId: { type: String, required: !0 },
1582
+ pos: { type: Object, required: !0 },
1583
+ isSelected: { type: Boolean, default: !1 },
1584
+ selectable: { type: Boolean, default: !0 },
1585
+ movable: { type: Boolean, default: !0 },
1586
+ snapToGrid: { type: Boolean, default: !0 },
1587
+ resizable: { type: String, default: "none" },
1588
+ bounds: { type: Array }
1589
+ },
1590
+ emits: [
1591
+ "update:pos",
1592
+ "update:isSelected"
1593
+ ],
1594
+ data() {
1595
+ return {
1596
+ canvasObject: null
1597
+ };
1598
+ },
1599
+ computed: {
1600
+ coords() {
1601
+ return this.canvasObject.getCanvasCoords();
1602
+ },
1603
+ slotProps() {
1604
+ return {
1605
+ canvas: this.canvas,
1606
+ objectId: this.objectId,
1607
+ isSelected: this.canvas.selection.isSelected(this.objectId),
1608
+ coords: this.coords,
1609
+ pos: this.pos
1610
+ };
1611
+ },
1612
+ resizeDirections() {
1613
+ return this.canvasObject.getResizeDirections();
1614
+ }
1615
+ },
1616
+ watch: {
1617
+ pos(o) {
1618
+ this.canvasObject.setPos(o);
1619
+ },
1620
+ isSelected(o) {
1621
+ this.canvasObject.setSelected(o);
1622
+ },
1623
+ selectable(o) {
1624
+ this.canvasObject.setSelectable(o);
1625
+ },
1626
+ movable(o) {
1627
+ this.canvasObject.setMovable(o);
1628
+ },
1629
+ snapToGrid(o) {
1630
+ this.canvasObject.setSnapToGrid(o);
1631
+ },
1632
+ resizable(o) {
1633
+ this.canvasObject.setResizable(o);
1634
+ },
1635
+ bounds(o) {
1636
+ this.canvasObject.setBounds(o);
1637
+ }
1638
+ },
1639
+ created() {
1640
+ this.canvasObject = new Qt(this.objectId), this.canvas.mesh.connect(this.canvasObject), this.canvas.events.objectPosUpdated.on(({ objectId: o, pos: e }) => {
1641
+ o === this.objectId && this.$emit("update:pos", e);
1642
+ }, this), this.canvas.events.selectionChanged.on((o) => {
1643
+ const e = o.includes(this.objectId);
1644
+ this.isSelected !== e && this.$emit("update:isSelected", e);
1645
+ }, this);
1646
+ },
1647
+ mounted() {
1648
+ const o = this.canvasObject;
1649
+ this.canvas.objectRegistry.register(o), o.setElement(this.$refs.rootEl), o.setPos(this.pos), o.setSelectable(this.selectable), o.setMovable(this.movable), o.setSnapToGrid(this.snapToGrid), o.setResizable(this.resizable), o.setBounds(this.bounds), o.setSelected(this.isSelected);
1650
+ },
1651
+ unmounted() {
1652
+ this.canvas.objectRegistry.unregister(this.objectId), this.canvasObject.setElement(null), this.canvas.selection.removeFromSelection(this.objectId), this.canvas.events.objectPosUpdated.removeAll(this), this.canvas.events.selectionChanged.removeAll(this);
1653
+ }
1654
+ };
1655
+ function is(o, e, t, n, r, c) {
1656
+ const p = oe("CanvasObjectResize");
1657
+ return V(), q("div", {
1658
+ ref: "rootEl",
1659
+ class: "CanvasObject",
1660
+ style: Z(r.canvasObject.getStyle()),
1661
+ onUiclick: e[0] || (e[0] = U((...y) => r.canvasObject.onUiClick && r.canvasObject.onUiClick(...y), ["stop", "prevent"])),
1662
+ onUidragstart: e[1] || (e[1] = U((...y) => r.canvasObject.onUiDragStart && r.canvasObject.onUiDragStart(...y), ["stop", "prevent"])),
1663
+ onUidragmove: e[2] || (e[2] = U((...y) => r.canvasObject.onUiDragMove && r.canvasObject.onUiDragMove(...y), ["stop", "prevent"])),
1664
+ onUidragend: e[3] || (e[3] = U((...y) => r.canvasObject.onUiDragEnd && r.canvasObject.onUiDragEnd(...y), ["stop", "prevent"]))
1665
+ }, [
1666
+ re(o.$slots, "default", jt(Ct(c.slotProps))),
1667
+ (V(!0), q(Et, null, It(c.resizeDirections, (y) => (V(), Xe(p, {
1668
+ key: y,
1669
+ canvasObject: r.canvasObject,
1670
+ direction: y
1671
+ }, null, 8, ["canvasObject", "direction"]))), 128))
1672
+ ], 36);
1673
+ }
1674
+ const Ms = /* @__PURE__ */ te(ns, [["render", is]]), rs = {
1675
+ components: {
1676
+ CanvasBoxSelect: kt
1677
+ },
1678
+ props: {
1679
+ canvas: { type: Object, required: !0 }
1680
+ },
1681
+ mounted() {
1682
+ this.canvas.mount(this.$refs.viewport);
1683
+ },
1684
+ unmounted() {
1685
+ this.canvas.unmount();
1686
+ },
1687
+ methods: {
1688
+ onCanvasUiClick() {
1689
+ this.canvas.selection.deselectAll();
1690
+ }
1691
+ }
1692
+ }, os = { class: "CanvasView" };
1693
+ function as(o, e, t, n, r, c) {
1694
+ const p = oe("CanvasBoxSelect");
1695
+ return V(), q("div", os, [
1696
+ j("div", {
1697
+ ref: "viewport",
1698
+ class: "Viewport",
1699
+ onMousedown: e[0] || (e[0] = (...y) => t.canvas.pan.onMouseDown && t.canvas.pan.onMouseDown(...y)),
1700
+ onUidragstart: e[1] || (e[1] = (...y) => t.canvas.boxSelect.onUiDragStart && t.canvas.boxSelect.onUiDragStart(...y)),
1701
+ onUidragmove: e[2] || (e[2] = (...y) => t.canvas.boxSelect.onUiDragMove && t.canvas.boxSelect.onUiDragMove(...y)),
1702
+ onUidragend: e[3] || (e[3] = (...y) => t.canvas.boxSelect.onUiDragEnd && t.canvas.boxSelect.onUiDragEnd(...y)),
1703
+ onUiclick: e[4] || (e[4] = (...y) => c.onCanvasUiClick && c.onCanvasUiClick(...y)),
1704
+ onScroll: e[5] || (e[5] = (...y) => t.canvas.viewport.onScroll && t.canvas.viewport.onScroll(...y)),
1705
+ onWheel: e[6] || (e[6] = (...y) => t.canvas.zoom.onWheel && t.canvas.zoom.onWheel(...y))
1706
+ }, [
1707
+ j("div", {
1708
+ class: "Sizer",
1709
+ style: Z(t.canvas.viewport.getSizerStyle())
1710
+ }, null, 4),
1711
+ j("div", {
1712
+ class: "Canvas",
1713
+ style: Z(t.canvas.viewport.getCanvasStyle())
1714
+ }, [
1715
+ re(o.$slots, "default", {}, void 0, !0),
1716
+ j("div", {
1717
+ class: "Origin",
1718
+ style: Z(t.canvas.viewport.getOriginStyle())
1719
+ }, [
1720
+ re(o.$slots, "origin", {}, void 0, !0)
1721
+ ], 4)
1722
+ ], 4),
1723
+ K(p, { canvas: t.canvas }, null, 8, ["canvas"])
1724
+ ], 544),
1725
+ re(o.$slots, "overlays", {}, void 0, !0)
1726
+ ]);
1727
+ }
1728
+ const Os = /* @__PURE__ */ te(rs, [["render", as], ["__scopeId", "data-v-52407cb1"]]), cs = {
1729
+ props: {
1730
+ controller: { type: Object, required: !0 }
1731
+ },
1732
+ computed: {
1733
+ page() {
1734
+ return this.controller.inputState.lastMousePos;
1735
+ },
1736
+ viewport() {
1737
+ return this.controller.space.pageToViewport(this.page);
1738
+ },
1739
+ canvas() {
1740
+ return this.controller.space.pageToCanvas(this.page);
1741
+ },
1742
+ local() {
1743
+ return this.controller.space.pageToLocal(this.page);
1744
+ }
1745
+ },
1746
+ methods: {
1747
+ format(o) {
1748
+ return `(${o.x.toFixed(2)}, ${o.y.toFixed(2)})`;
1749
+ }
1750
+ }
1751
+ };
1752
+ function ls(o, e, t, n, r, c) {
1753
+ const p = oe("HGroup"), y = oe("VGroup");
1754
+ return V(), Xe(y, {
1755
+ class: "DebugCoords",
1756
+ gap: "s"
1757
+ }, {
1758
+ default: G(() => [
1759
+ K(p, { class: "Row" }, {
1760
+ default: G(() => [
1761
+ e[0] || (e[0] = j("strong", null, "page", -1)),
1762
+ j("span", null, X(c.format(c.page)), 1)
1763
+ ]),
1764
+ _: 1
1765
+ }),
1766
+ K(p, { class: "Row" }, {
1767
+ default: G(() => [
1768
+ e[1] || (e[1] = j("strong", null, "viewport", -1)),
1769
+ j("span", null, X(c.format(c.viewport)), 1)
1770
+ ]),
1771
+ _: 1
1772
+ }),
1773
+ K(p, { class: "Row" }, {
1774
+ default: G(() => [
1775
+ e[2] || (e[2] = j("strong", null, "canvas", -1)),
1776
+ j("span", null, X(c.format(c.canvas)), 1)
1777
+ ]),
1778
+ _: 1
1779
+ }),
1780
+ K(p, { class: "Row" }, {
1781
+ default: G(() => [
1782
+ e[3] || (e[3] = j("strong", null, "local", -1)),
1783
+ j("span", null, X(c.format(c.local)), 1)
1784
+ ]),
1785
+ _: 1
1786
+ }),
1787
+ K(p, { class: "Row" }, {
1788
+ default: G(() => [
1789
+ e[4] || (e[4] = j("strong", null, "zoom", -1)),
1790
+ j("span", null, X(t.controller.space.zoom.toFixed(2)), 1)
1791
+ ]),
1792
+ _: 1
1793
+ })
1794
+ ]),
1795
+ _: 1
1796
+ });
1797
+ }
1798
+ const Ps = /* @__PURE__ */ te(cs, [["render", ls], ["__scopeId", "data-v-54d4bb42"]]);
1799
+ var us = Object.defineProperty, hs = Object.getOwnPropertyDescriptor, ds = (o, e, t, n) => {
1800
+ for (var r = hs(e, t), c = o.length - 1, p; c >= 0; c--)
1801
+ (p = o[c]) && (r = p(e, t, r) || r);
1802
+ return r && us(e, t, r), r;
1803
+ };
1804
+ class ee {
1805
+ constructor() {
1806
+ this.lastMousePos = { x: window.innerWidth * 0.5, y: window.innerHeight * 0.5 }, this.lmbPressed = !1, this.mmbPressed = !1, this.rmbPressed = !1, this.altKey = !1, this.ctrlKey = !1, this.metaKey = !1, this.shiftKey = !1, this.events = b(this, k), this.windowEvents = new ue(window);
1807
+ }
1808
+ init() {
1809
+ this.events.mounted.on(() => {
1810
+ this.windowEvents.add("mousedown", (e) => this.onMouseDown(e)), this.windowEvents.add("mousemove", (e) => this.onMouseMove(e)), this.windowEvents.add("mouseup", (e) => this.onMouseUp(e)), this.windowEvents.add("keydown", (e) => this.onKeyDown(e)), this.windowEvents.add("keyup", (e) => this.onKeyUp(e));
1811
+ }), this.events.unmounted.on(() => {
1812
+ this.windowEvents.removeAll();
1813
+ });
1814
+ }
1815
+ get ctrlOrMetaKey() {
1816
+ return this.ctrlKey || this.metaKey;
1817
+ }
1818
+ onMouseDown(e) {
1819
+ this.lastMousePos = { x: e.pageX, y: e.pageY }, this.lmbPressed = e.button === 0, this.mmbPressed = e.button === 1, this.rmbPressed = e.button === 2;
1820
+ }
1821
+ onMouseMove(e) {
1822
+ this.lastMousePos = { x: e.pageX, y: e.pageY };
1823
+ }
1824
+ onMouseUp(e) {
1825
+ this.lastMousePos = { x: e.pageX, y: e.pageY }, this.lmbPressed = !1, this.mmbPressed = !1, this.rmbPressed = !1;
1826
+ }
1827
+ onKeyDown(e) {
1828
+ this.updateModifiers(e);
1829
+ }
1830
+ onKeyUp(e) {
1831
+ this.updateModifiers(e);
1832
+ }
1833
+ updateModifiers(e) {
1834
+ this.altKey = e.altKey, this.ctrlKey = e.ctrlKey, this.metaKey = e.metaKey, this.shiftKey = e.shiftKey;
1835
+ }
1836
+ }
1837
+ ds([
1838
+ he()
1839
+ ], ee.prototype, "init");
1840
+ class Ye {
1841
+ constructor() {
1842
+ this.config = b(this, J), this.inputState = b(this, ee), this.objectRegistry = b(this, ce), this.selection = b(this, Q), this.space = b(this, L), this.selectionOriginPos = null, this.initialSelectionIds = /* @__PURE__ */ new Set(), this.objectBoxes = [];
1843
+ }
1844
+ isSelecting() {
1845
+ return this.selectionOriginPos != null;
1846
+ }
1847
+ onUiDragStart(e) {
1848
+ this.config.allowMultiSelect && (this.isSelecting() || (this.selectionOriginPos = { x: e.pageX, y: e.pageY }, e.shiftKey ? this.initialSelectionIds = new Set(this.selection.getSelectedIds()) : (this.initialSelectionIds.clear(), this.selection.deselectAll()), this.captureObjectBoxes()));
1849
+ }
1850
+ onUiDragMove(e) {
1851
+ this.isSelecting() && (e.preventDefault(), this.updateSelection(e));
1852
+ }
1853
+ onUiDragEnd(e) {
1854
+ this.isSelecting() && this.updateSelection(e), this.stopSelecting();
1855
+ }
1856
+ getSelectionBox() {
1857
+ return this.selectionOriginPos ? ie(
1858
+ this.space.pageToLocal(this.selectionOriginPos),
1859
+ this.space.pageToLocal(this.inputState.lastMousePos)
1860
+ ) : null;
1861
+ }
1862
+ getSelectionStyle() {
1863
+ if (!this.selectionOriginPos)
1864
+ return null;
1865
+ const e = ie(this.selectionOriginPos, this.inputState.lastMousePos), t = this.space.pageToCanvas(e[0]), n = this.space.pageToCanvas(e[1]);
1866
+ return {
1867
+ left: `${t.x}px`,
1868
+ top: `${t.y}px`,
1869
+ width: `${n.x - t.x}px`,
1870
+ height: `${n.y - t.y}px`
1871
+ };
1872
+ }
1873
+ stopSelecting() {
1874
+ this.selectionOriginPos = null, this.initialSelectionIds.clear(), this.objectBoxes = [];
1875
+ }
1876
+ captureObjectBoxes() {
1877
+ this.objectBoxes = [];
1878
+ const e = this.space.viewportBox;
1879
+ for (const t of this.objectRegistry.getAll()) {
1880
+ if (!t.isSelectable())
1881
+ continue;
1882
+ const n = t.element;
1883
+ if (!n)
1884
+ continue;
1885
+ const r = n.getBoundingClientRect(), c = ie(
1886
+ { x: r.left, y: r.top },
1887
+ { x: r.right, y: r.bottom }
1888
+ );
1889
+ if (!Le(c, e))
1890
+ continue;
1891
+ const p = ie(
1892
+ this.space.pageToLocal(c[0]),
1893
+ this.space.pageToLocal(c[1])
1894
+ );
1895
+ this.objectBoxes.push([t.objectId, p]);
1896
+ }
1897
+ }
1898
+ updateSelection(e) {
1899
+ const t = this.getSelectionBox();
1900
+ if (!t)
1901
+ return;
1902
+ const n = new Set(this.initialSelectionIds);
1903
+ for (const [r, c] of this.objectBoxes)
1904
+ Le(t, c) && n.add(r);
1905
+ this.selection.setSelectedIds(n);
1906
+ }
1907
+ }
1908
+ class le {
1909
+ constructor() {
1910
+ this.viewportEl = null, this.windowEvents = new ue(window), this.config = b(this, J), this.space = b(this, L);
1911
+ }
1912
+ mount(e) {
1913
+ this.viewportEl = e, this.recalcCanvasMetrics(), this.updateViewportBox(), this.centerOnOrigin(), this.onScroll(), this.windowEvents.add("resize", () => this.updateViewportBox()), this.windowEvents.add("scroll", () => this.updateViewportBox()), this.config.autoCenter && requestAnimationFrame(() => this.centerOnOrigin());
1914
+ }
1915
+ destroy() {
1916
+ this.windowEvents.removeAll(), this.viewportEl = null, this.space.viewportBox = [{ x: 0, y: 0 }, { x: 0, y: 0 }];
1917
+ }
1918
+ getCanvasStyle() {
1919
+ const e = $e(this.viewportEl, "--canvas-grid-major-color", "#ddd"), t = $e(this.viewportEl, "--canvas-grid-minor-color", "#eee"), n = W(this.viewportEl, "--canvas-grid-subdivisions", 4), r = W(this.viewportEl, "--canvas-grid-major-radius", 2), c = W(this.viewportEl, "--canvas-grid-minor-radius", 1), p = Ut(
1920
+ this.space.cellSize,
1921
+ n,
1922
+ e,
1923
+ r,
1924
+ t,
1925
+ c
1926
+ );
1927
+ return {
1928
+ background: `url(${`data:image/svg+xml;base64,${window.btoa(p)}`}) repeat`,
1929
+ width: `${this.space.canvasSize.x}px`,
1930
+ height: `${this.space.canvasSize.y}px`,
1931
+ transformOrigin: "0 0",
1932
+ transform: `scale(${this.space.zoom})`
1933
+ };
1934
+ }
1935
+ getOriginStyle() {
1936
+ return {
1937
+ left: `${this.space.canvasOrigin.x}px`,
1938
+ top: `${this.space.canvasOrigin.y}px`
1939
+ };
1940
+ }
1941
+ getSizerStyle() {
1942
+ return {
1943
+ width: `${this.space.canvasSize.x * this.space.zoom}px`,
1944
+ height: `${this.space.canvasSize.y * this.space.zoom}px`
1945
+ };
1946
+ }
1947
+ onScroll() {
1948
+ this.viewportEl && (this.space.scrollPos = {
1949
+ x: this.viewportEl.scrollLeft,
1950
+ y: this.viewportEl.scrollTop
1951
+ });
1952
+ }
1953
+ centerOnOrigin() {
1954
+ if (!this.viewportEl)
1955
+ return;
1956
+ const e = this.getViewportSize();
1957
+ this.setViewportScroll({
1958
+ x: this.space.canvasOrigin.x * this.space.zoom - e.x * 0.5,
1959
+ y: this.space.canvasOrigin.y * this.space.zoom - e.y * 0.5
1960
+ });
1961
+ }
1962
+ scrollBy(e, t) {
1963
+ this.viewportEl && this.setViewportScroll({
1964
+ x: this.viewportEl.scrollLeft + e,
1965
+ y: this.viewportEl.scrollTop + t
1966
+ });
1967
+ }
1968
+ scrollToLocalPoint(e) {
1969
+ const t = this.getViewportSize(), n = this.space.localToCanvas(e);
1970
+ this.setViewportScroll({
1971
+ x: n.x * this.space.zoom - t.x * 0.5,
1972
+ y: n.y * this.space.zoom - t.y * 0.5
1973
+ });
1974
+ }
1975
+ setViewportScroll(e) {
1976
+ this.viewportEl && (this.viewportEl.scrollTo({
1977
+ left: Math.max(0, e.x),
1978
+ top: Math.max(0, e.y),
1979
+ behavior: "auto"
1980
+ }), this.onScroll());
1981
+ }
1982
+ updateViewportBox() {
1983
+ if (!this.viewportEl) {
1984
+ this.space.viewportBox = [{ x: 0, y: 0 }, { x: 0, y: 0 }];
1985
+ return;
1986
+ }
1987
+ const e = this.viewportEl.getBoundingClientRect();
1988
+ this.space.viewportBox = [
1989
+ { x: e.left, y: e.top },
1990
+ { x: e.right, y: e.bottom }
1991
+ ];
1992
+ }
1993
+ getViewportSize() {
1994
+ return {
1995
+ x: this.space.viewportBox[1].x - this.space.viewportBox[0].x,
1996
+ y: this.space.viewportBox[1].y - this.space.viewportBox[0].y
1997
+ };
1998
+ }
1999
+ recalcCanvasMetrics() {
2000
+ const e = W(this.viewportEl, "--canvas-margin-cells", 64);
2001
+ this.space.cellSize = W(this.viewportEl, "--canvas-grid-cell-size", 32);
2002
+ const t = e * this.space.cellSize;
2003
+ this.space.canvasSize = { x: t * 2, y: t * 2 }, this.space.canvasOrigin = { x: t, y: t };
2004
+ }
2005
+ }
2006
+ var fs = Object.defineProperty, vs = Object.getOwnPropertyDescriptor, ps = (o, e, t, n) => {
2007
+ for (var r = vs(e, t), c = o.length - 1, p; c >= 0; c--)
2008
+ (p = o[c]) && (r = p(e, t, r) || r);
2009
+ return r && fs(e, t, r), r;
2010
+ };
2011
+ class me {
2012
+ constructor() {
2013
+ this.viewport = b(this, le), this.events = b(this, k), this.windowEvents = new ue(window), this.isPanning = !1;
2014
+ }
2015
+ init() {
2016
+ this.events.unmounted.on(() => this.stopPanning());
2017
+ }
2018
+ onMouseDown(e) {
2019
+ e.button === 1 && (e.preventDefault(), this.isPanning = !0, this.windowEvents.add("mousemove", (t) => this.onMouseMove(t)), this.windowEvents.add("mouseup", (t) => this.onMouseUp(t)));
2020
+ }
2021
+ stopPanning() {
2022
+ this.isPanning = !1, this.windowEvents.removeAll();
2023
+ }
2024
+ onMouseMove(e) {
2025
+ this.isPanning && this.viewport.scrollBy(-e.movementX, -e.movementY);
2026
+ }
2027
+ onMouseUp(e) {
2028
+ e.button === 1 && this.stopPanning();
2029
+ }
2030
+ }
2031
+ ps([
2032
+ he()
2033
+ ], me.prototype, "init");
2034
+ var ys = Object.defineProperty, gs = Object.getOwnPropertyDescriptor, ws = (o, e, t, n) => {
2035
+ for (var r = gs(e, t), c = o.length - 1, p; c >= 0; c--)
2036
+ (p = o[c]) && (r = p(e, t, r) || r);
2037
+ return r && ys(e, t, r), r;
2038
+ };
2039
+ const ms = [
2040
+ "button",
2041
+ "a",
2042
+ "input",
2043
+ "textarea",
2044
+ "select",
2045
+ '[role="textbox"]',
2046
+ '[role="button"]',
2047
+ "[nodrag]"
2048
+ ];
2049
+ class be {
2050
+ constructor() {
2051
+ this.events = b(this, k), this.inputState = b(this, ee), this.windowEvents = new ue(window), this.lastMouseDownPos = { x: window.innerWidth * 0.5, y: window.innerHeight * 0.5 }, this.lastMouseDownTarget = null, this.dragTarget = null, this.inClickVicinity = !1, this.dragDistance = 4;
2052
+ }
2053
+ init() {
2054
+ this.events.mounted.on(() => {
2055
+ this.windowEvents.add("mousedown", (e) => this.onMouseDown(e)), this.windowEvents.add("mousemove", (e) => this.onMouseMove(e)), this.windowEvents.add("mouseup", (e) => this.onMouseUp(e)), this.windowEvents.add("keydown", (e) => this.onKeyDown(e));
2056
+ }), this.events.unmounted.on(() => {
2057
+ this.windowEvents.removeAll();
2058
+ });
2059
+ }
2060
+ onMouseDown(e) {
2061
+ e.button === 0 && (this.lastMouseDownPos = { x: e.pageX, y: e.pageY }, this.lastMouseDownTarget = e.target, this.inClickVicinity = !0);
2062
+ }
2063
+ onMouseMove(e) {
2064
+ if (!this.inputState.lmbPressed)
2065
+ return;
2066
+ if (this.dragTarget) {
2067
+ this.dragTarget.dispatchEvent(this.cloneMouseEvent("uidragmove", e));
2068
+ return;
2069
+ }
2070
+ if (!this.inClickVicinity || !this.lastMouseDownTarget)
2071
+ return;
2072
+ const t = e.pageX - this.lastMouseDownPos.x, n = e.pageY - this.lastMouseDownPos.y;
2073
+ Math.hypot(t, n) < this.dragDistance || (this.inClickVicinity = !1, this.isDragAllowed(this.lastMouseDownTarget) && (this.dragTarget = this.lastMouseDownTarget, this.dragTarget.dispatchEvent(this.cloneMouseEvent("uidragstart", e))));
2074
+ }
2075
+ onMouseUp(e) {
2076
+ if (e.button !== 0)
2077
+ return;
2078
+ const t = this.dragTarget, n = this.inClickVicinity, r = this.lastMouseDownTarget;
2079
+ this.dragTarget = null, this.inClickVicinity = !1, this.lastMouseDownTarget = null, t && t.dispatchEvent(this.cloneMouseEvent("uidragend", e)), n && r && (r.dispatchEvent(this.cloneMouseEvent("uiclick", e)), this.dispatchActivate(r, e));
2080
+ }
2081
+ onKeyDown(e) {
2082
+ (e.key === "Enter" || e.key === " ") && e.target && (e.target === document.body && e.key === " " && e.preventDefault(), this.dispatchActivate(e.target, e));
2083
+ }
2084
+ dispatchActivate(e, t) {
2085
+ e.closest(":disabled") || e.dispatchEvent(new CustomEvent("uiactivate", { detail: t }));
2086
+ }
2087
+ isDragAllowed(e) {
2088
+ return e instanceof Element ? !e.closest(ms.join(",")) : !1;
2089
+ }
2090
+ cloneMouseEvent(e, t) {
2091
+ return new MouseEvent(e, {
2092
+ bubbles: !0,
2093
+ cancelable: !0,
2094
+ clientX: t.clientX,
2095
+ clientY: t.clientY,
2096
+ screenX: t.screenX,
2097
+ screenY: t.screenY,
2098
+ button: t.button,
2099
+ buttons: t.buttons,
2100
+ ctrlKey: t.ctrlKey,
2101
+ shiftKey: t.shiftKey,
2102
+ altKey: t.altKey,
2103
+ metaKey: t.metaKey
2104
+ });
2105
+ }
2106
+ }
2107
+ ws([
2108
+ he()
2109
+ ], be.prototype, "init");
2110
+ const B = [0.33, 0.5, 0.6, 0.75, 0.85, 1, 1.15, 1.25, 1.5, 1.75, 2], bs = Math.min(...B), xs = Math.max(...B);
2111
+ class He {
2112
+ constructor() {
2113
+ this.viewport = b(this, le), this.space = b(this, L);
2114
+ }
2115
+ onWheel(e) {
2116
+ if (!e.ctrlKey)
2117
+ return;
2118
+ e.preventDefault();
2119
+ const t = z(e.deltaY, -40, 40) / 400, n = Math.exp(-t);
2120
+ this.setZoom(this.space.zoom * n);
2121
+ }
2122
+ setZoom(e) {
2123
+ const t = this.space.getViewportCenterInLocal();
2124
+ this.space.zoom = z(e, bs, xs), this.viewport.scrollToLocalPoint(t);
2125
+ }
2126
+ zoomIn() {
2127
+ const e = this.getClosestZoomStepIndex();
2128
+ e < B.length - 1 && this.setZoom(B[e + 1]);
2129
+ }
2130
+ zoomOut() {
2131
+ const e = this.getClosestZoomStepIndex();
2132
+ e > 0 && this.setZoom(B[e - 1]);
2133
+ }
2134
+ getClosestZoomStepIndex() {
2135
+ let e = 0, t = Number.POSITIVE_INFINITY;
2136
+ for (let n = 0; n < B.length; n++) {
2137
+ const r = Math.abs(B[n] - this.space.zoom);
2138
+ r < t && (t = r, e = n);
2139
+ }
2140
+ return e;
2141
+ }
2142
+ }
2143
+ class _s {
2144
+ constructor(e = {}) {
2145
+ this.mesh = new ae(), this.boxSelect = b(this, Ye), this.config = b(this, J), this.space = b(this, L), this.viewport = b(this, le), this.pan = b(this, me), this.events = b(this, k), this.inputState = b(this, ee), this.objectRegistry = b(this, ce), this.selection = b(this, Q), this.uiEvents = b(this, be), this.zoom = b(this, He), this.mesh.connect(this), this.mesh.use((t) => Tt(t)), this.mesh.service(Ye), this.mesh.service(le), this.mesh.service(me), this.mesh.service(J), this.mesh.service(L), this.mesh.service(k), this.mesh.service(ee), this.mesh.service(xe), this.mesh.service(ce), this.mesh.service(Q), this.mesh.service(be), this.mesh.service(He), this.config.set(e);
2146
+ }
2147
+ mount(e) {
2148
+ Ne(this.mesh), this.viewport.mount(e), this.events.mounted.emit();
2149
+ }
2150
+ unmount() {
2151
+ Ne(this.mesh), this.viewport.destroy(), this.events.unmounted.emit();
2152
+ }
2153
+ }
2154
+ export {
2155
+ kt as CanvasBoxSelect,
2156
+ J as CanvasConfig,
2157
+ _s as CanvasController,
2158
+ k as CanvasEvents,
2159
+ ee as CanvasInputState,
2160
+ Ms as CanvasObject,
2161
+ Qt as CanvasObjectController,
2162
+ ce as CanvasObjectRegistry,
2163
+ me as CanvasPan,
2164
+ Q as CanvasSelection,
2165
+ L as CanvasSpace,
2166
+ be as CanvasUiEvents,
2167
+ Os as CanvasView,
2168
+ le as CanvasViewport,
2169
+ He as CanvasZoom,
2170
+ Ps as DebugCoords
2171
+ };