@ptahjs/dnd 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/dnd.js DELETED
@@ -1,1709 +0,0 @@
1
- //#region src/core/EventDispatcher.js
2
- var e = class {
3
- #e = /* @__PURE__ */ new Map();
4
- emit(e, t) {
5
- let n = this.#e.get(e);
6
- if (!n || n.length === 0) return t;
7
- let r = t;
8
- for (let e of n) {
9
- let t = e(r);
10
- t !== void 0 && (r = t);
11
- }
12
- return r;
13
- }
14
- on(e, t) {
15
- let n = this.#e.get(e);
16
- return n ? n.push(t) : this.#e.set(e, [t]), this;
17
- }
18
- off(e, t) {
19
- let n = this.#e.get(e);
20
- if (n) if (t) {
21
- let e = n.indexOf(t);
22
- e !== -1 && n.splice(e, 1);
23
- } else this.#e.delete(e);
24
- return this;
25
- }
26
- offAll() {
27
- this.#e.clear();
28
- }
29
- }, t = {
30
- dataAttr: "data",
31
- copyAttr: "copy",
32
- dragAttr: "drag",
33
- dragScopeAttr: "drag-scope",
34
- dragdropAttr: "dragdrop",
35
- dropAttr: "drop",
36
- handleAttr: "drag-handle",
37
- handleResizeAttr: "drag-handle-resize",
38
- handleRotateAttr: "drag-handle-rotate",
39
- namespaceAttr: "namespace",
40
- dropIndicatorAttr: "drop-indicator",
41
- ignoreClickAttr: "ignore-click",
42
- ignoreMirrorAttr: "ignore-mirror",
43
- resizableAttr: "resizable",
44
- rotatableAttr: "rotatable",
45
- scaleRatioAttr: "scale-ratio"
46
- }, n = {
47
- canDrop: "dnd-canDrop",
48
- noDrop: "dnd-noDrop",
49
- dragging: "dnd-dragging",
50
- mirror: "dnd-mirror",
51
- active: "dnd-active",
52
- dropIndicator: "dnd-indicator",
53
- dropIndicatorActive: "dnd-indicator-active",
54
- indicatorTop: "dnd-indicator--top",
55
- indicatorRight: "dnd-indicator--right",
56
- indicatorBottom: "dnd-indicator--bottom",
57
- indicatorLeft: "dnd-indicator--left",
58
- marquee: "dnd-marquee"
59
- }, r = .5, i = 1 / 3, a = {
60
- MARQUEE_MOVE: 5,
61
- DRAG_START: 3
62
- }, o = {
63
- EDGE: 48,
64
- MIN_SPEED: 180,
65
- MAX_SPEED: 600
66
- };
67
- //#endregion
68
- //#region src/utils/computeDropRegion.js
69
- function s(e) {
70
- if (e?.cache?.dropRegionFns) return e.cache.dropRegionFns;
71
- let t = () => {
72
- if (e.currentDrop) return e.currentDropRect || void 0;
73
- }, n = {
74
- isOverBottom: () => {
75
- let n = t();
76
- return n ? e.y > n.y + n.height * (1 - r) : !1;
77
- },
78
- isOverLeft: () => {
79
- let n = t();
80
- return n ? e.x < n.x + n.width * i : !1;
81
- },
82
- isOverRight: () => {
83
- let n = t();
84
- return n ? e.x > n.x + n.width * (1 - i) : !1;
85
- },
86
- isOverTop: () => {
87
- let n = t();
88
- return n ? e.y < n.y + n.height * r : !1;
89
- }
90
- };
91
- return e?.cache && (e.cache.dropRegionFns = n), n;
92
- }
93
- //#endregion
94
- //#region src/utils/parseData.js
95
- function c(e) {
96
- if (e === void 0) return;
97
- let t = String(e).trim();
98
- if (!t) return "";
99
- try {
100
- return JSON.parse(t);
101
- } catch {
102
- return t;
103
- }
104
- }
105
- //#endregion
106
- //#region src/utils/createPayload.js
107
- function l(e, n) {
108
- let r = () => {
109
- let e = n.currentDrop;
110
- if (!e) return;
111
- let r = n.currentDropRect || e.getBoundingClientRect(), i = n.adapter.getAttr(e, t.scaleRatioAttr) ?? e.getAttribute?.("data-scale-ratio"), a = Number(i), o = Number.isFinite(a) && a > 0 ? a : 1, s = r.left + (e.clientLeft || 0), c = r.top + (e.clientTop || 0), l = n.x - s, u = n.y - c, d = l + (e.scrollLeft || 0), f = u + (e.scrollTop || 0);
112
- return {
113
- x: d / o,
114
- y: f / o,
115
- scale: o,
116
- px: d,
117
- py: f
118
- };
119
- }, i = () => {
120
- let e = n.currentDrop, r = n.cache;
121
- if (!e) {
122
- r.dropDataEl = void 0, r.dropDataRaw = void 0, r.dropDataParsed = void 0;
123
- return;
124
- }
125
- let i = n.adapter.getAttr(e, t.dataAttr);
126
- return r.dropDataEl === e && i === r.dropDataRaw ? r.dropDataParsed : (r.dropDataEl = e, r.dropDataRaw = i, r.dropDataParsed = c(i), r.dropDataParsed);
127
- };
128
- if (!n.cache.hitDropFn) {
129
- let e = -1, t = 0, r = 0, i, a;
130
- n.cache.hitDropFn = (o, s, c) => {
131
- let l = n?.adapter?.frameId ?? n?.cache?.frameId ?? 0;
132
- if (l === e && o === t && s === r && c === i) return a;
133
- e = l, t = o, r = s, i = c;
134
- let u = n.adapter;
135
- if (!u?.hitDrop) throw Error("createPayload requires monitor.adapter.hitDrop");
136
- return a = u.hitDrop(o, s, n.namespace, c), a;
137
- };
138
- }
139
- return {
140
- type: e,
141
- namespace: n.namespace,
142
- data: n.data,
143
- dropData: i(),
144
- dropPoint: r(),
145
- indicatorRegion: n.lastIndicatorRegion,
146
- isDragScope: n.isDragScope,
147
- isCopy: n.isCopy,
148
- sourceEl: n.sourceEl,
149
- handleEl: n.handleEl,
150
- originDrop: n.originDrop,
151
- currentDrop: n.currentDrop,
152
- x: n.x,
153
- y: n.y,
154
- dx: n.dx,
155
- dy: n.dy,
156
- started: n.started,
157
- hitDrop: n.cache.hitDropFn,
158
- ...s(n)
159
- };
160
- }
161
- //#endregion
162
- //#region src/utils/createSession.js
163
- function u(e) {
164
- return {
165
- adapter: void 0,
166
- currentDropRect: void 0,
167
- dragAbort: void 0,
168
- isDragScope: !1,
169
- isCopy: !1,
170
- active: !1,
171
- pointerId: void 0,
172
- startX: 0,
173
- startY: 0,
174
- x: 0,
175
- y: 0,
176
- dx: 0,
177
- dy: 0,
178
- started: !1,
179
- threshold: a.DRAG_START,
180
- lastMoveTs: 0,
181
- sourceEl: void 0,
182
- handleEl: void 0,
183
- originDrop: void 0,
184
- currentDrop: void 0,
185
- namespace: void 0,
186
- data: void 0,
187
- mirrorEl: void 0,
188
- mirrorOffsetX: 0,
189
- mirrorOffsetY: 0,
190
- currentAllowed: !1,
191
- dirty: !1,
192
- prevX: 0,
193
- prevY: 0,
194
- cache: {
195
- frameId: 0,
196
- dropDataEl: void 0,
197
- dropDataRaw: void 0,
198
- dropDataParsed: void 0,
199
- dropRegionFns: void 0,
200
- hitDropFn: void 0,
201
- canDropCtx: void 0,
202
- dropRectDirty: !1,
203
- autoScrollPlan: void 0,
204
- autoScrollLastTs: 0
205
- },
206
- indicatorEl: void 0,
207
- indicatorRegion: void 0,
208
- lastIndicatorRegion: void 0,
209
- selectedByNs: e?.selectedByNs,
210
- lastDragTs: 0,
211
- suppressNextClick: !1
212
- };
213
- }
214
- //#endregion
215
- //#region src/utils/createContext.js
216
- function d({ dnd: e, session: t, store: n, frame: r, adapter: i }) {
217
- let a = /* @__PURE__ */ new Map();
218
- return {
219
- dnd: e,
220
- session: t,
221
- store: n,
222
- frame: r,
223
- adapter: i,
224
- payload: (e = "drag") => {
225
- if (a.has(e)) return a.get(e);
226
- let n = l(e, t);
227
- return a.set(e, n), n;
228
- }
229
- };
230
- }
231
- //#endregion
232
- //#region src/utils/isToggleEnabled.js
233
- function f(e, t, n = !0) {
234
- if (!e?.getAttribute) return n;
235
- let r = `data-${t}`, i = e.getAttribute(t) ?? e.getAttribute(r);
236
- return i === null ? n : String(i).toLowerCase() !== "false";
237
- }
238
- //#endregion
239
- //#region src/utils/matchHandle.js
240
- function p(e, n) {
241
- let r = n?.closestDraggable?.(e) || e?.closest?.(`[${t.dragAttr}], [${t.dragdropAttr}]`);
242
- if (!r) return;
243
- let i = f(r, t.rotatableAttr, !0), a = f(r, t.resizableAttr, !0);
244
- if (i && (r.hasAttribute(t.handleRotateAttr) || r.querySelector?.(`[${t.handleRotateAttr}]`)) || a && (r.hasAttribute(t.handleResizeAttr) || r.querySelector?.(`[${t.handleResizeAttr}]`))) {
245
- let n = (i ? e.closest?.(`[${t.handleRotateAttr}]`) : null) || (a ? e.closest?.(`[${t.handleResizeAttr}]`) : null);
246
- return n && r.contains(n) ? n : r;
247
- }
248
- if (r.hasAttribute(t.handleAttr) || r.querySelector?.(`[${t.handleAttr}]`)) {
249
- let n = e.closest?.(`[${t.handleAttr}]`);
250
- return n && r.contains(n) ? n : void 0;
251
- }
252
- return r;
253
- }
254
- //#endregion
255
- //#region src/utils/isHTMLElement.js
256
- function m(e) {
257
- return e && typeof e == "object" && e.nodeType === 1;
258
- }
259
- //#endregion
260
- //#region src/utils/isIgnoreClick.js
261
- function h(e) {
262
- if (!m(e)) return !1;
263
- let n = t.ignoreClickAttr, r = `data-${n}`;
264
- return !!(e.closest?.(`[${n}], [${r}]`) || e.hasAttribute?.(n) || e.hasAttribute?.(r));
265
- }
266
- //#endregion
267
- //#region src/utils/scopeHelpers.js
268
- var g = t.dragScopeAttr, _ = `[${g}], [data-${g}]`, v = class {
269
- #e = 0;
270
- #t = /* @__PURE__ */ new WeakMap();
271
- #n = /* @__PURE__ */ new WeakMap();
272
- get frameId() {
273
- return this.#e;
274
- }
275
- beginFrame() {
276
- this.#e++;
277
- }
278
- endFrame() {}
279
- resolveRoot(e) {
280
- if (e) {
281
- if (typeof e == "string") {
282
- let t = document.querySelector(e);
283
- return t instanceof HTMLElement ? t : void 0;
284
- }
285
- return e instanceof HTMLElement ? e : void 0;
286
- }
287
- }
288
- getAttr(e, t) {
289
- return e?.getAttribute?.(t) ?? void 0;
290
- }
291
- getNamespace(e) {
292
- if (!e) return "_default";
293
- let n = this.#n.get(e);
294
- if (n && n.frameId === this.#e) return n.ns;
295
- let r = this.getAttr(e, t.namespaceAttr) || "_default";
296
- return this.#n.set(e, {
297
- frameId: this.#e,
298
- ns: r
299
- }), r;
300
- }
301
- isDrop(e) {
302
- return e ? e.hasAttribute?.(t.dropAttr) || e.hasAttribute?.(t.dragdropAttr) : !1;
303
- }
304
- closestDraggable(e) {
305
- let { dragAttr: n, dragdropAttr: r } = t;
306
- if (e) return e.hasAttribute(n) || e.hasAttribute(r) ? e : e.closest?.(`[${n}], [${r}]`) || void 0;
307
- }
308
- closestDrop(e) {
309
- if (e) {
310
- let { dropAttr: n, dragdropAttr: r } = t;
311
- return e.closest?.(`[${n}], [${r}]`) || void 0;
312
- }
313
- }
314
- closestDragScope(e) {
315
- let { dragScopeAttr: n } = t;
316
- if (e) return e.hasAttribute(n) ? e : e.closest?.(`[${n}]`) || void 0;
317
- }
318
- measureRect(e) {
319
- if (!e) return;
320
- let t = this.#t.get(e);
321
- if (t && t.frameId === this.#e) return t.rect;
322
- let n = e.getBoundingClientRect();
323
- return this.#t.set(e, {
324
- frameId: this.#e,
325
- rect: n
326
- }), n;
327
- }
328
- hitDrop(e, t, n, r) {
329
- let i = document.elementFromPoint(e, t);
330
- if (!i) return;
331
- let a = n || "_default", o = i;
332
- if (!(r && r.contains(o) && (o = r.parentElement ?? null, !o))) for (; o;) {
333
- if (this.isDrop(o) && this.getNamespace(o) === a) return o;
334
- o = o.parentElement;
335
- }
336
- }
337
- }, y = class {
338
- #e = !1;
339
- #t = !1;
340
- #n = 0;
341
- #r;
342
- constructor(e) {
343
- this.#r = typeof e == "function" ? e : () => !1;
344
- }
345
- request() {
346
- this.#t = !0, !this.#e && (this.#e = !0, this.#n = requestAnimationFrame(this.#i));
347
- }
348
- cancel() {
349
- this.#e && (this.#e = !1, this.#t = !1, this.#n &&= (cancelAnimationFrame(this.#n), 0));
350
- }
351
- #i = () => {
352
- if (!this.#e) return;
353
- this.#t = !1;
354
- let e = !1;
355
- try {
356
- e = !!this.#r(performance.now());
357
- } catch {
358
- e = !1;
359
- }
360
- if (this.#e) {
361
- if (e || this.#t) {
362
- this.#n = requestAnimationFrame(this.#i);
363
- return;
364
- }
365
- this.#e = !1, this.#n = 0;
366
- }
367
- };
368
- }, b = class {
369
- #e;
370
- #t = new AbortController();
371
- #n = !1;
372
- #r;
373
- #i = 0;
374
- #a = 0;
375
- #o;
376
- #s;
377
- #c;
378
- constructor({ onDown: e, onMove: t, onUp: n } = {}) {
379
- this.#o = typeof e == "function" ? e : void 0, this.#s = typeof t == "function" ? t : void 0, this.#c = typeof n == "function" ? n : void 0;
380
- }
381
- setRoot(e) {
382
- e !== this.#e && (this.#t.abort(), this.#t = new AbortController(), this.#e = e, this.#e && this.#e.addEventListener("pointerdown", this.#l, {
383
- passive: !1,
384
- signal: this.#t.signal
385
- }));
386
- }
387
- destroy() {
388
- this.#t.abort(), this.#d(), this.#e = void 0;
389
- }
390
- #l = (e) => {
391
- if (!this.#o || !this.#e) return;
392
- let t = this.#o(e);
393
- !t?.accepted || !t?.signal || !Number.isFinite(t.pointerId) || (this.#n = !0, this.#r = t.pointerId, this.#i = e.clientX, this.#a = e.clientY, this.#u(t.signal));
394
- };
395
- #u(e) {
396
- globalThis.addEventListener("pointermove", this.#f, {
397
- passive: !1,
398
- signal: e
399
- }), globalThis.addEventListener("pointerup", this.#p, {
400
- passive: !1,
401
- signal: e
402
- }), globalThis.addEventListener("pointercancel", this.#p, {
403
- passive: !1,
404
- signal: e
405
- }), globalThis.addEventListener("blur", this.#p, {
406
- passive: !1,
407
- signal: e
408
- });
409
- }
410
- #d() {
411
- this.#n = !1, this.#r = void 0;
412
- }
413
- #f = (e) => {
414
- if (!this.#n || !this.#s || e.pointerId !== this.#r) return;
415
- let t = e.getCoalescedEvents?.(), n = t?.length ? t[t.length - 1] : e, r = performance.now(), i = n.clientX, a = n.clientY;
416
- if (i === this.#i && a === this.#a) {
417
- e.preventDefault();
418
- return;
419
- }
420
- this.#i = i, this.#a = a, this.#s({
421
- pointerId: e.pointerId,
422
- x: i,
423
- y: a,
424
- event: e,
425
- now: r
426
- }), e.preventDefault();
427
- };
428
- #p = (e) => {
429
- !this.#n || !this.#c || "pointerId" in e && e.pointerId !== this.#r || (this.#c({
430
- event: e,
431
- pointerId: this.#r,
432
- reason: e.type
433
- }), this.#d(), e.preventDefault?.());
434
- };
435
- }, ee = class {
436
- scrolled = !1;
437
- now = 0;
438
- classOps = /* @__PURE__ */ new Map();
439
- styleOps = /* @__PURE__ */ new Map();
440
- appendOps = /* @__PURE__ */ new Map();
441
- removeOps = /* @__PURE__ */ new Set();
442
- fnOps = [];
443
- reset(e) {
444
- this.now = e, this.scrolled = !1, this.classOps.clear(), this.styleOps.clear(), this.appendOps.clear(), this.removeOps.clear(), this.fnOps.length = 0;
445
- }
446
- toggleClass(e, t, n) {
447
- if (!e || !t || this.removeOps.has(e)) return;
448
- let r = this.classOps.get(e);
449
- r || (r = /* @__PURE__ */ new Map(), this.classOps.set(e, r)), r.set(t, !!n);
450
- }
451
- setStyle(e, t, n) {
452
- if (!e || !t || this.removeOps.has(e)) return;
453
- let r = this.styleOps.get(e);
454
- r || (r = /* @__PURE__ */ new Map(), this.styleOps.set(e, r)), r.set(t, n);
455
- }
456
- append(e, t) {
457
- !e || !t || this.removeOps.has(t) || this.appendOps.set(t, e);
458
- }
459
- remove(e) {
460
- e && (this.removeOps.add(e), this.classOps.delete(e), this.styleOps.delete(e), this.appendOps.delete(e));
461
- }
462
- run(e) {
463
- typeof e == "function" && this.fnOps.push(e);
464
- }
465
- commit() {
466
- for (let e of this.removeOps) e?.parentNode?.removeChild?.(e);
467
- let e = this.removeOps.size > 0;
468
- for (let [t, n] of this.appendOps) (!e || !this.removeOps.has(t) && !this.removeOps.has(n)) && n?.appendChild?.(t);
469
- for (let [t, n] of this.classOps) if (!e || !this.removeOps.has(t)) for (let [e, r] of n) r ? t?.classList?.add?.(e) : t?.classList?.remove?.(e);
470
- for (let [t, n] of this.styleOps) if (!e || !this.removeOps.has(t)) for (let [e, r] of n) r == null ? e.includes("-") ? t?.style?.removeProperty?.(e) : t?.style && (t.style[e] = "") : e.includes("-") ? t?.style?.setProperty?.(e, String(r)) : t?.style && (t.style[e] = r);
471
- for (let e of this.fnOps) e?.();
472
- }
473
- }, te = class {
474
- #e = [];
475
- use(e, t) {
476
- e && (this.#e.push(e), this.#e.sort((e, t) => (e.order ?? 0) - (t.order ?? 0)), e.onAttach?.(t));
477
- }
478
- onRootChange(e, t, n) {
479
- for (let r of this.#e) r.onRootChange?.(e, t, n);
480
- }
481
- onDown(e, t) {
482
- for (let n of this.#e) n.onDown?.(e, t);
483
- }
484
- onStart(e) {
485
- for (let t of this.#e) t.onStart?.(e);
486
- }
487
- onMeasure(e) {
488
- for (let t of this.#e) t.onMeasure?.(e);
489
- }
490
- onCompute(e) {
491
- for (let t of this.#e) t.onCompute?.(e);
492
- }
493
- onCommit(e) {
494
- for (let t of this.#e) t.onCommit?.(e);
495
- }
496
- onAfterDrag(e) {
497
- let t = !1;
498
- for (let n of this.#e) {
499
- let r = n.onAfterDrag?.(e);
500
- (r === !0 || r?.scrolled) && (t = !0);
501
- }
502
- return t;
503
- }
504
- onEnd(e, t) {
505
- for (let n of this.#e) n.onEnd?.(e, t);
506
- }
507
- onDestroy(e, t) {
508
- for (let n of this.#e) n.onDestroy?.(e, t);
509
- }
510
- }, ne = class {
511
- #e;
512
- #t;
513
- constructor({ store: e, session: t } = {}) {
514
- this.#e = e, this.#t = t;
515
- }
516
- get session() {
517
- return this.#t;
518
- }
519
- get store() {
520
- return this.#e;
521
- }
522
- dispatch(e) {
523
- if (!e || !this.#t) return { handled: !1 };
524
- switch (e.type) {
525
- case "DOWN": {
526
- if (this.#t.active) return { handled: !1 };
527
- Object.assign(this.#t, {
528
- active: !0,
529
- started: !1,
530
- dirty: !1,
531
- pointerId: e.pointerId,
532
- startX: e.x,
533
- startY: e.y,
534
- x: e.x,
535
- y: e.y,
536
- prevX: e.x,
537
- prevY: e.y,
538
- dx: 0,
539
- dy: 0,
540
- namespace: e.namespace,
541
- data: e.data,
542
- sourceEl: e.sourceEl,
543
- handleEl: e.handleEl,
544
- originDrop: e.originDrop,
545
- currentDrop: void 0,
546
- currentDropRect: void 0,
547
- isDragScope: !!e.isDragScope,
548
- isCopy: !!e.isCopy,
549
- mirrorOffsetX: e.mirrorOffsetX ?? 0,
550
- mirrorOffsetY: e.mirrorOffsetY ?? 0,
551
- lastMoveTs: 0
552
- }), this.#t.dragAbort = new AbortController();
553
- let { cache: t } = this.#t;
554
- return t && (t.dropDataEl = void 0, t.dropDataRaw = void 0, t.dropDataParsed = void 0, t.dropRegionFns = void 0, t.hitDropFn = void 0, t.dropRectDirty = !0), {
555
- handled: !0,
556
- accepted: !0,
557
- dragAbort: this.#t.dragAbort
558
- };
559
- }
560
- case "MOVE": {
561
- if (!this.#t.active || e.pointerId !== this.#t.pointerId) return { handled: !1 };
562
- let t = e.x, n = e.y;
563
- if (t === this.#t.x && n === this.#t.y) return {
564
- handled: !0,
565
- moved: !1
566
- };
567
- this.#t.prevX = this.#t.x, this.#t.prevY = this.#t.y, this.#t.x = t, this.#t.y = n, this.#t.dx = t - this.#t.startX, this.#t.dy = n - this.#t.startY, this.#t.dirty = !0;
568
- let r = !1;
569
- return this.#t.started || Math.hypot(this.#t.dx, this.#t.dy) >= this.#t.threshold && (this.#t.started = !0, r = !0), {
570
- handled: !0,
571
- moved: !0,
572
- startedNow: r,
573
- started: this.#t.started
574
- };
575
- }
576
- case "END": return !this.#t.active || e.pointerId !== void 0 && e.pointerId !== this.#t.pointerId ? { handled: !1 } : {
577
- handled: !0,
578
- ended: !!this.#t.started,
579
- reason: e.reason
580
- };
581
- default: return { handled: !1 };
582
- }
583
- }
584
- resetSession({ ended: e } = { ended: !1 }) {
585
- let t = this.#e, n = this.#t, r = u(t);
586
- return r.adapter = n?.adapter, e && (r.suppressNextClick = !0, r.lastDragTs = performance.now()), this.#t = r, r;
587
- }
588
- }, re = class extends e {
589
- #e = new AbortController();
590
- #t;
591
- #n;
592
- #r = new v();
593
- #i = new ee();
594
- #a = { selectedByNs: /* @__PURE__ */ new Map() };
595
- #o;
596
- #s = new te();
597
- #c;
598
- #l;
599
- canDrop = () => !0;
600
- renderMirror = void 0;
601
- get root() {
602
- return this.#t;
603
- }
604
- get monitor() {
605
- return this.#o?.session;
606
- }
607
- constructor(e = {}) {
608
- super(), this.#n = { threshold: e.threshold ?? a.DRAG_START };
609
- let t = u(this.#a);
610
- t.threshold = this.#n.threshold, t.adapter = this.#r, this.#o = new ne({
611
- store: this.#a,
612
- session: t
613
- }), this.#c = new y(this.#m), this.#l = new b({
614
- onDown: this.#d,
615
- onMove: this.#f,
616
- onUp: this.#p
617
- }), this.setRoot(e.root);
618
- }
619
- use(e) {
620
- return e ? (this.#s.use(e, this), this.#t && e.onRootChange?.(this.#t, void 0, this.#e.signal), this) : this;
621
- }
622
- setRoot(e) {
623
- let t = this.#r.resolveRoot(e);
624
- if (t === this.#t) return;
625
- let n = this.#t;
626
- this.#e.abort(), this.#e = new AbortController(), this.#t = t, this.#l.setRoot(this.#t), this.#t && (this.#s.onRootChange(this.#t, n, this.#e.signal), this.#t.addEventListener("click", this.#u, {
627
- capture: !0,
628
- passive: !1,
629
- signal: this.#e.signal
630
- }));
631
- }
632
- destroy() {
633
- this.#e.abort(), this.#l.destroy(), this.#c.cancel();
634
- let e = this.#o.session;
635
- e?.active && (this.#s.onEnd(d({
636
- dnd: this,
637
- session: e,
638
- store: this.#a,
639
- frame: this.#i,
640
- adapter: this.#r
641
- }), {
642
- ended: !1,
643
- reason: "destroy"
644
- }), e.dragAbort?.abort()), this.offAll(), this.#s.onDestroy(this, e);
645
- let t = this.#o.resetSession({ ended: !1 });
646
- t.adapter = this.#r;
647
- }
648
- #u = (e) => {
649
- let t = this.#o?.session;
650
- if (!t?.suppressNextClick) return;
651
- let n = performance.now(), r = !t.lastDragTs || n - t.lastDragTs < 800;
652
- t.suppressNextClick = !1, r && (e.preventDefault?.(), e.stopPropagation?.(), e.stopImmediatePropagation?.());
653
- };
654
- #d = (e) => {
655
- if (!this.#t || e.button !== 0) return { accepted: !1 };
656
- let n = p(e.target, this.#r);
657
- if (!n) return { accepted: !1 };
658
- let r = this.#r.closestDraggable(n);
659
- if (!r) return { accepted: !1 };
660
- e.preventDefault(), e.target?.setPointerCapture?.(e.pointerId);
661
- let i = this.#r.getNamespace(r), a = this.#r.closestDrop(r), o = r.getBoundingClientRect(), s = c(this.#r.getAttr(r, t.dataAttr));
662
- if (!this.#o.dispatch({
663
- type: "DOWN",
664
- pointerId: e.pointerId,
665
- x: e.clientX,
666
- y: e.clientY,
667
- namespace: i,
668
- data: s,
669
- sourceEl: r,
670
- handleEl: n,
671
- originDrop: a,
672
- isDragScope: !!this.#r.closestDragScope(r),
673
- isCopy: !!this.#r.getAttr(r, t.copyAttr),
674
- mirrorOffsetX: e.clientX - o.left,
675
- mirrorOffsetY: e.clientY - o.top
676
- })?.accepted) return { accepted: !1 };
677
- let l = this.#o.session;
678
- l.threshold = this.#n.threshold, l.adapter = this.#r, this.#i.reset(performance.now()), this.#r.beginFrame(), l.cache.frameId = this.#r.frameId;
679
- let u = d({
680
- dnd: this,
681
- session: l,
682
- store: this.#a,
683
- frame: this.#i,
684
- adapter: this.#r
685
- });
686
- return this.#s.onDown(u, e), this.#i.commit(), this.#r.endFrame(), {
687
- accepted: !0,
688
- pointerId: e.pointerId,
689
- signal: l.dragAbort.signal
690
- };
691
- };
692
- #f = ({ pointerId: e, x: t, y: n }) => {
693
- let r = this.#o.dispatch({
694
- type: "MOVE",
695
- pointerId: e,
696
- x: t,
697
- y: n
698
- });
699
- if (!r?.handled) return;
700
- let i = this.#o.session;
701
- if (r.startedNow) {
702
- let e = d({
703
- dnd: this,
704
- session: i,
705
- store: this.#a,
706
- frame: this.#i,
707
- adapter: this.#r
708
- });
709
- this.#s.onStart(e), this.emit("dragstart", l("dragstart", i));
710
- }
711
- r.started && this.#c.request();
712
- };
713
- #p = ({ event: e, pointerId: t, reason: n }) => {
714
- let r = this.#o.dispatch({
715
- type: "END",
716
- pointerId: t,
717
- reason: n
718
- });
719
- if (!r?.handled) return;
720
- let i = this.#o.session;
721
- "pointerId" in e && e.target?.releasePointerCapture?.(e.pointerId);
722
- let a = !!r.ended;
723
- this.#r.beginFrame(), i.cache.frameId = this.#r.frameId, i.currentDrop = this.#r.hitDrop(i.x, i.y, i.namespace, i.sourceEl), i.currentDropRect = i.currentDrop ? this.#r.measureRect(i.currentDrop) : void 0, this.#r.endFrame();
724
- let o = d({
725
- dnd: this,
726
- session: i,
727
- store: this.#a,
728
- frame: this.#i,
729
- adapter: this.#r
730
- });
731
- this.#s.onEnd(o, {
732
- ended: a,
733
- reason: n || "pointerup"
734
- });
735
- let s = l(a ? "drop" : "cancel", i);
736
- i.dragAbort?.abort(), i.dragAbort = void 0, this.#c.cancel();
737
- let c = this.#o.resetSession({ ended: a });
738
- c.adapter = this.#r, a ? this.emit("drop", s) : this.emit("cancel", s), e.preventDefault?.();
739
- };
740
- #m = (e) => {
741
- let t = this.#o.session;
742
- if (!t.active || !t.started) return !1;
743
- this.#i.reset(e), this.#r.beginFrame(), t.cache.frameId = this.#r.frameId;
744
- let n = d({
745
- dnd: this,
746
- session: t,
747
- store: this.#a,
748
- frame: this.#i,
749
- adapter: this.#r
750
- }), r = !1;
751
- return t.dirty &&= (this.#s.onMeasure(n), this.#s.onCompute(n), this.emit("drag", n.payload("drag")), this.#s.onCommit(n), this.#i.commit(), this.#i.scrolled && (r = !0), !1), this.#s.onAfterDrag(n) && (r = !0), r && (t.dirty = !0), this.#r.endFrame(), t.dirty || r;
752
- };
753
- }, x = class {
754
- order = 10;
755
- onMeasure(e) {
756
- let t = e.session;
757
- if (!t.active || !t.started) return;
758
- let n = e.adapter.hitDrop(t.x, t.y, t.namespace, t.sourceEl);
759
- if (n && t.sourceEl && e.adapter.isDrop(t.sourceEl)) {
760
- let r = e.adapter.measureRect(t.sourceEl);
761
- r && t.x >= r.left && t.x <= r.right && t.y >= r.top && t.y <= r.bottom && (n = void 0);
762
- }
763
- if (n !== t.currentDrop && (t.currentDrop = n, t.cache && (t.cache.dropRectDirty = !0)), !n) {
764
- t.currentDropRect = void 0, t.cache && (t.cache.dropRectDirty = !1);
765
- return;
766
- }
767
- (t.cache?.dropRectDirty || !t.currentDropRect) && (t.currentDropRect = e.adapter.measureRect(n), t.cache.dropRectDirty = !1);
768
- }
769
- onCompute(e) {
770
- let t = e.session;
771
- if (!t.active || !t.started) return;
772
- if (!t.currentDrop) {
773
- t.currentAllowed = !1;
774
- return;
775
- }
776
- let n = e.dnd?.canDrop;
777
- if (typeof n != "function") {
778
- t.currentAllowed = !0;
779
- return;
780
- }
781
- try {
782
- t.currentAllowed = !!n(e.payload("drag"));
783
- } catch {
784
- t.currentAllowed = !1;
785
- }
786
- }
787
- onCommit(e) {
788
- let t = e.session;
789
- if (!t?.active || !t?.started) return;
790
- let r = t.cache ||= {}, i = r._dropClassEl, a = t.currentDrop;
791
- m(i) && i !== a && (e.frame.toggleClass(i, n.canDrop, !1), e.frame.toggleClass(i, n.noDrop, !1)), m(a) && (e.frame.toggleClass(a, n.canDrop, !!t.currentAllowed), e.frame.toggleClass(a, n.noDrop, !t.currentAllowed)), r._dropClassEl = a;
792
- }
793
- onEnd(e) {
794
- let t = e?.session;
795
- if (!t) return;
796
- let r = t.cache?._dropClassEl;
797
- m(r) && r.classList.remove(n.canDrop, n.noDrop), t.cache && (t.cache._dropClassEl = void 0);
798
- }
799
- onDestroy(e, t) {
800
- this.onEnd({ session: t });
801
- }
802
- }, S = class {
803
- order = 0;
804
- onStart = (e) => {
805
- let r = e?.session;
806
- if (!r?.sourceEl || r.mirrorEl || (r.sourceEl.classList.add(n.dragging), r.sourceEl.hasAttribute?.(t.ignoreMirrorAttr))) return;
807
- let i = e.adapter.measureRect(r.sourceEl), a = typeof e?.dnd?.renderMirror == "function" ? e.dnd.renderMirror(e) : r.sourceEl.cloneNode(!0);
808
- a instanceof HTMLElement && (a.setAttribute(t.ignoreMirrorAttr, ""), a.classList.add(n.mirror), Object.assign(a.style, {
809
- width: `${i.width}px`,
810
- height: `${i.height}px`,
811
- position: "fixed"
812
- }), document.body.appendChild(a), r.mirrorEl = a);
813
- };
814
- onCommit = (e) => {
815
- let t = e?.session;
816
- if (!(!t?.active || !t.started) && t.mirrorEl) {
817
- let n = t.x - (t.mirrorOffsetX || 0), r = t.y - (t.mirrorOffsetY || 0);
818
- e.frame.setStyle(t.mirrorEl, "transform", `translate3d(${n}px, ${r}px, 0)`);
819
- }
820
- };
821
- onEnd = (e) => {
822
- let t = e?.session;
823
- t && (t.mirrorEl &&= (t.mirrorEl.remove(), void 0), t.sourceEl?.classList.remove(n.dragging));
824
- };
825
- onDestroy = (e, t) => {
826
- this.onEnd({ session: t });
827
- };
828
- }, C = /(auto|scroll|overlay)/i;
829
- function w(e) {
830
- if (!(e instanceof HTMLElement)) return !1;
831
- let t = getComputedStyle(e), n = C.test(t.overflowY) && e.scrollHeight > e.clientHeight + 1;
832
- return C.test(t.overflowX) && e.scrollWidth > e.clientWidth + 1 || n;
833
- }
834
- function T(e) {
835
- let t = e;
836
- for (; t;) {
837
- if (w(t)) return t;
838
- t = t.parentElement;
839
- }
840
- }
841
- function E(e, t, n, r) {
842
- return e < t + r ? {
843
- dir: -1,
844
- k: (t + r - e) / r
845
- } : e > n - r ? {
846
- dir: 1,
847
- k: (e - (n - r)) / r
848
- } : {
849
- dir: 0,
850
- k: 0
851
- };
852
- }
853
- var D = class {
854
- order = 1e4;
855
- constructor(e = {}) {
856
- this.edge = e.edge ?? o.EDGE, this.minSpeed = e.minSpeed ?? o.MIN_SPEED, this.maxSpeed = e.maxSpeed ?? o.MAX_SPEED, this.allowWindowScroll = e.allowWindowScroll ?? !0;
857
- }
858
- onAfterDrag = (e) => {
859
- let t = e.session;
860
- if (!t.active || !t.started) return !1;
861
- let n = t.currentDrop ? T(t.currentDrop) : void 0, r = !1;
862
- if (!n && this.allowWindowScroll && (n = document.scrollingElement || document.documentElement, r = !!n), !n) return !1;
863
- let i = e.frame.now, a = t.cache.autoScrollLastTs || 0, o = a ? Math.max(8, Math.min(64, i - a)) : 16.67;
864
- t.cache && (t.cache.autoScrollLastTs = i);
865
- let s = r ? {
866
- left: 0,
867
- top: 0,
868
- right: innerWidth,
869
- bottom: innerHeight
870
- } : e.adapter.measureRect(n), c = t.x, l = t.y, u = E(c, s.left, s.right, this.edge), d = E(l, s.top, s.bottom, this.edge), f = (e) => this.minSpeed + (this.maxSpeed - this.minSpeed) * e, p = u.dir ? u.dir * f(u.k) * o / 1e3 : 0, m = d.dir ? d.dir * f(d.k) * o / 1e3 : 0;
871
- if (!p && !m) return !1;
872
- let h = n.scrollTop, g = n.scrollLeft;
873
- r ? window.scrollBy(p, m) : n.scrollBy({
874
- left: p,
875
- top: m,
876
- behavior: "auto"
877
- });
878
- let _ = h !== n.scrollTop || g !== n.scrollLeft;
879
- return _ && e.frame && (e.frame.scrolled = !0), _;
880
- };
881
- onEnd = (e) => {
882
- let t = e?.session;
883
- t?.cache && (t.cache.autoScrollLastTs = 0);
884
- };
885
- }, O = {
886
- top: n.indicatorTop,
887
- right: n.indicatorRight,
888
- bottom: n.indicatorBottom,
889
- left: n.indicatorLeft
890
- }, k = Object.values(O), ie = new Set([
891
- "top",
892
- "right",
893
- "bottom",
894
- "left"
895
- ]);
896
- function A(e, t, n, r) {
897
- m(t) && (e.frame.toggleClass ? e.frame.toggleClass(t, n, !!r) : t.classList.toggle(n, !!r));
898
- }
899
- function ae(e) {
900
- if (!m(e)) return;
901
- let n = t?.dropIndicatorAttr || "drop-indicator", r = `data-${n}`, i;
902
- if (e.hasAttribute?.(n)) i = e.getAttribute?.(n);
903
- else if (e.hasAttribute?.(r)) i = e.getAttribute?.(r);
904
- else return;
905
- let a = (i ?? "").trim();
906
- if (!a) return "all";
907
- let o = /* @__PURE__ */ new Set();
908
- for (let e of a.split(/[,\s]+/)) {
909
- let t = (e || "").trim().toLowerCase();
910
- ie.has(t) && o.add(t);
911
- }
912
- return o.size ? o : void 0;
913
- }
914
- function oe(e) {
915
- let t = e.session, r = e.dnd?.root?.ownerDocument || document, i = t.indicatorEl;
916
- m(i) || (i = r.createElement("div"), i.classList.add(n.dropIndicator), t.indicatorEl = i);
917
- let a = t.currentDrop || e.dnd?.root || r.body;
918
- return m(a) && i.parentNode !== a && a.appendChild(i), i;
919
- }
920
- function se(e) {
921
- if (!e.currentDrop || !e.currentDropRect) return;
922
- let t = s(e);
923
- if (t.isOverLeft()) return "left";
924
- if (t.isOverRight()) return "right";
925
- if (t.isOverTop()) return "top";
926
- if (t.isOverBottom()) return "bottom";
927
- }
928
- function ce(e) {
929
- let t = e.session;
930
- return t.currentDrop ? typeof t.currentAllowed == "boolean" ? t.currentAllowed : !0 : !1;
931
- }
932
- var le = class {
933
- order = 40;
934
- onCommit(e) {
935
- let t = e.session;
936
- if (!t?.active || !t?.started) return;
937
- let r = t.currentDrop, i = ae(r);
938
- if (!i) {
939
- let r = t.indicatorEl;
940
- if (m(r)) {
941
- A(e, r, n.dropIndicatorActive, !1);
942
- for (let t of k) A(e, r, t, !1);
943
- }
944
- t.indicatorRegion = void 0;
945
- return;
946
- }
947
- let a = oe(e), o = ce(e), s = se(t), c = i === "all" || s && i.has(s) ? s : void 0, l = !!(r && t.currentDropRect && o && c);
948
- if (A(e, a, n.dropIndicatorActive, l), t.indicatorRegion = l ? c : void 0, l) for (let [t, n] of Object.entries(O)) A(e, a, n, t === c);
949
- else for (let t of k) A(e, a, t, !1);
950
- }
951
- onEnd(e) {
952
- let t = e.session;
953
- t && (t.lastIndicatorRegion = t.indicatorRegion ?? "inside", m(t.indicatorEl) && t.indicatorEl.remove(), t.indicatorEl = void 0, t.indicatorRegion = void 0);
954
- }
955
- onDestroy(e, t) {
956
- this.onEnd({ session: t });
957
- }
958
- }, j = "draggable-dot-wrap", M = "draggable-dot", N = "draggable-rotate";
959
- function P(e, n = {}) {
960
- let { resizable: r = !0, rotatable: i = !0 } = n, a = e.createElement("div");
961
- if (a.classList.add(j), a.dataset.resizable = String(r), a.dataset.rotatable = String(i), r) for (let [n, r] of [
962
- ["nw", "tl"],
963
- ["n", "tm"],
964
- ["ne", "tr"],
965
- ["e", "rm"],
966
- ["se", "br"],
967
- ["s", "bm"],
968
- ["sw", "bl"],
969
- ["w", "lm"]
970
- ]) {
971
- let i = e.createElement("div");
972
- i.classList.add(M), i.setAttribute(t.handleResizeAttr, ""), i.dataset.dir = n, i.dataset.pos = r, a.appendChild(i);
973
- }
974
- if (i) {
975
- let n = e.createElement("div");
976
- n.classList.add(N), n.setAttribute(t.handleRotateAttr, ""), n.dataset.dir = "rotate", a.appendChild(n);
977
- }
978
- return a;
979
- }
980
- function F(e) {
981
- m(e) && e.querySelector?.(`.${j}`)?.remove();
982
- }
983
- function I(e) {
984
- if (!m(e)) return;
985
- let n = !!e.closest?.(_), r = e.querySelector?.(".draggable-dot-wrap") || null, i = !!r, a = f(e, t.resizableAttr, !0), o = f(e, t.rotatableAttr, !0), s = a || o;
986
- if (!n) {
987
- i && F(e);
988
- return;
989
- }
990
- if (!s) {
991
- i && F(e);
992
- return;
993
- }
994
- if (r && (String(r.dataset?.resizable) !== String(a) || String(r.dataset?.rotatable) !== String(o)) && (r.remove(), r = null, i = !1), !i) {
995
- let t = getComputedStyle(e).position;
996
- (t === "static" || !t) && (e.style.position = "relative"), e.appendChild(P(e.ownerDocument || document, {
997
- resizable: a,
998
- rotatable: o
999
- }));
1000
- }
1001
- }
1002
- function L(e, t, r, i) {
1003
- let a = t.get(i);
1004
- if (a && a !== r) if (Array.isArray(a)) for (let e of a) e?.classList?.remove?.(n.active), F(e);
1005
- else a.classList.remove(n.active), F(a);
1006
- r.classList.add(n.active), I(r), t.set(i, r);
1007
- }
1008
- function R(e, t, r) {
1009
- let i = e.get(r);
1010
- if (i) if (Array.isArray(i)) for (let e of i) e?.classList?.remove?.(n.active), F(e);
1011
- else i.classList.remove(n.active), F(i);
1012
- for (let e of t) e.classList.add(n.active), I(e);
1013
- e.set(r, t);
1014
- }
1015
- function z(e, t) {
1016
- if (t !== void 0) {
1017
- let r = e.get(t);
1018
- if (r) {
1019
- if (Array.isArray(r)) for (let e of r) e?.classList?.remove?.(n.active), F(e);
1020
- else r?.classList?.remove?.(n.active), F(r);
1021
- e.delete(t);
1022
- }
1023
- return;
1024
- }
1025
- for (let t of e.values()) if (Array.isArray(t)) for (let e of t) e?.classList?.remove?.(n.active), F(e);
1026
- else t?.classList?.remove?.(n.active), F(t);
1027
- e.clear();
1028
- }
1029
- var B = class {
1030
- order = -50;
1031
- #e;
1032
- onAttach(e) {
1033
- this.#e = e;
1034
- }
1035
- onRootChange(e, t, n) {
1036
- if (!m(e)) return;
1037
- let r = this.#e.monitor;
1038
- e.addEventListener("pointerdown", (e) => {
1039
- if (e.button !== 0 || h(e.target)) return;
1040
- let t = r.selectedByNs;
1041
- if (!t) return;
1042
- let n = r.adapter.closestDraggable(e.target);
1043
- if (!n) {
1044
- z(t);
1045
- return;
1046
- }
1047
- let i = r.adapter.getNamespace(n), a = t.get(i);
1048
- Array.isArray(a) && a.length > 1 && a.includes(n) || L(null, t, n, i);
1049
- }, {
1050
- capture: !0,
1051
- signal: n
1052
- });
1053
- }
1054
- onDown(e, t) {
1055
- let r = e?.session;
1056
- if (!r?.sourceEl || t?.button !== 0 || h(t.target)) return;
1057
- let i = e.store?.selectedByNs || r.selectedByNs;
1058
- if (!i) return;
1059
- let a = r.namespace || e.adapter.getNamespace(r.sourceEl), o = i.get(a);
1060
- Array.isArray(o) && o.length > 1 && o.includes(r.sourceEl) || (o && o !== r.sourceEl && (Array.isArray(o) ? o.forEach((t) => {
1061
- e.frame.toggleClass(t, n.active, !1), F(t);
1062
- }) : (e.frame.toggleClass(o, n.active, !1), F(o))), e.frame.toggleClass(r.sourceEl, n.active, !0), I(r.sourceEl), i.set(a, r.sourceEl));
1063
- }
1064
- onDestroy(e, t) {
1065
- let n = t?.selectedByNs;
1066
- n && z(n);
1067
- }
1068
- };
1069
- //#endregion
1070
- //#region src/services/MarqueeSelectionService.js
1071
- function V(e, t, n, r) {
1072
- return {
1073
- left: Math.min(e, n),
1074
- right: Math.max(e, n),
1075
- top: Math.min(t, r),
1076
- bottom: Math.max(t, r),
1077
- width: Math.abs(n - e),
1078
- height: Math.abs(r - t)
1079
- };
1080
- }
1081
- function H(e, t) {
1082
- let n = Math.max(e.left, t.left), r = Math.min(e.right, t.right), i = Math.max(e.top, t.top), a = Math.min(e.bottom, t.bottom), o = r - n, s = a - i;
1083
- return o <= 0 || s <= 0 ? !1 : o * s > (t.right - t.left) * (t.bottom - t.top) * .5;
1084
- }
1085
- var U = class {
1086
- order = -40;
1087
- #e;
1088
- onAttach(e) {
1089
- this.#e = e;
1090
- }
1091
- onRootChange(e, t, n) {
1092
- m(e) && e.addEventListener("pointerdown", (e) => {
1093
- if (e.button !== 0 || h(e.target)) return;
1094
- let t = e.target.closest(_);
1095
- t && (this.#e.monitor.adapter.closestDraggable(e.target) || this.#t(t, e));
1096
- }, {
1097
- capture: !0,
1098
- signal: n
1099
- });
1100
- }
1101
- #t(e, r) {
1102
- let i = r.clientX, o = r.clientY, s = this.#e.monitor.adapter.getNamespace(e), c = parseFloat(e.getAttribute(t.scaleRatioAttr) || "1"), l = document.createElement("div");
1103
- l.classList.add(n.marquee), e.appendChild(l);
1104
- let u = !1, d = (t) => {
1105
- let n = t.clientX - i, r = t.clientY - o;
1106
- if (!u && Math.abs(n) < a.MARQUEE_MOVE && Math.abs(r) < a.MARQUEE_MOVE) return;
1107
- u = !0;
1108
- let d = V(i, o, t.clientX, t.clientY);
1109
- this.#n(l, d, e, c);
1110
- let f = this.#r(e, s, d), p = this.#e.monitor.selectedByNs;
1111
- p && (z(p, s), f.length > 0 && R(p, f, s));
1112
- }, f = () => {
1113
- if (l.remove(), document.removeEventListener("pointermove", d), document.removeEventListener("pointerup", f), !u) {
1114
- let e = this.#e.monitor.selectedByNs;
1115
- e && z(e, s);
1116
- }
1117
- };
1118
- document.addEventListener("pointermove", d), document.addEventListener("pointerup", f);
1119
- }
1120
- #n(e, t, n, r) {
1121
- let i = n.getBoundingClientRect(), a = (t.left - i.left) / r, o = (t.top - i.top) / r, s = t.width / r, c = t.height / r;
1122
- e.style.left = `${a}px`, e.style.top = `${o}px`, e.style.width = `${s}px`, e.style.height = `${c}px`;
1123
- }
1124
- #r(e, n, r) {
1125
- let i = this.#e.monitor.adapter, a = e.querySelectorAll(`[${t.dragAttr}], [${t.dragdropAttr}]`), o = [];
1126
- for (let e of a) {
1127
- if (i.getNamespace(e) !== n) continue;
1128
- let t = i.measureRect(e);
1129
- t && H(r, t) && o.push(e);
1130
- }
1131
- return o;
1132
- }
1133
- };
1134
- //#endregion
1135
- //#region src/services/transform/utils/geometry.js
1136
- function W(e = 0) {
1137
- return `${Number.parseInt(String(e), 10) || 0}px`;
1138
- }
1139
- function G(e) {
1140
- return e * Math.PI / 180;
1141
- }
1142
- function ue(e, t) {
1143
- return Math.sqrt(e * e + t * t);
1144
- }
1145
- function K(e, t) {
1146
- let n = Math.max(1, Number(t) || 1), r = Math.abs(e) % n, i = e > 0 ? n : -n;
1147
- return r > n / 2 ? i * Math.ceil(Math.abs(e) / n) : i * Math.floor(Math.abs(e) / n);
1148
- }
1149
- function q(e, t = 1, n) {
1150
- let r = n.measureRect(e), i = Number(t) || 1;
1151
- return {
1152
- bottom: r.bottom / i,
1153
- height: r.height / i,
1154
- left: r.left / i,
1155
- right: r.right / i,
1156
- top: r.top / i,
1157
- width: r.width / i
1158
- };
1159
- }
1160
- function J(e, t, n, r) {
1161
- let i = n - e, a = r - t, o = Math.atan2(a, i) * 180 / Math.PI + 90;
1162
- return o = (o % 360 + 360) % 360, o;
1163
- }
1164
- function de(e, t, n) {
1165
- let { width: r, height: i } = e;
1166
- return {
1167
- height: Math.abs(i),
1168
- width: Math.abs(r),
1169
- x: t - Math.abs(r) / 2,
1170
- y: n - Math.abs(i) / 2
1171
- };
1172
- }
1173
- function fe({ centerX: e, centerY: t, width: n, height: r, angle: i }) {
1174
- return {
1175
- angle: i,
1176
- height: r,
1177
- width: n,
1178
- x: e - n / 2,
1179
- y: t - r / 2
1180
- };
1181
- }
1182
- function Y(e) {
1183
- let t = getComputedStyle(e), n = {};
1184
- try {
1185
- n = new DOMMatrixReadOnly(t.transform);
1186
- } catch {
1187
- n = new DOMMatrixReadOnly();
1188
- }
1189
- let r = n.m41, i = n.m42, a = Number.parseFloat(t.width), o = Number.parseFloat(t.height);
1190
- if (!Number.isFinite(a) || !Number.isFinite(o)) {
1191
- let t = e.getBoundingClientRect();
1192
- a = t.width, o = t.height;
1193
- }
1194
- return {
1195
- angle: -Math.atan2(n.m21, n.m11) * (180 / Math.PI),
1196
- height: o,
1197
- width: a,
1198
- x: r,
1199
- y: i
1200
- };
1201
- }
1202
- //#endregion
1203
- //#region src/services/transform/utils/cursor.js
1204
- var pe = {
1205
- e: "right",
1206
- n: "top",
1207
- ne: "top-right",
1208
- nw: "top-left",
1209
- s: "bottom",
1210
- se: "bottom-right",
1211
- sw: "bottom-left",
1212
- w: "left"
1213
- }, me = [
1214
- "n",
1215
- "ne",
1216
- "e",
1217
- "se",
1218
- "s",
1219
- "sw",
1220
- "w",
1221
- "nw"
1222
- ], he = {
1223
- 0: 0,
1224
- 1: 1,
1225
- 2: 1,
1226
- 3: 2,
1227
- 4: 3,
1228
- 5: 3,
1229
- 6: 4,
1230
- 7: 5,
1231
- 8: 5,
1232
- 9: 6,
1233
- 10: 7,
1234
- 11: 7
1235
- }, ge = {
1236
- e: 2,
1237
- n: 0,
1238
- ne: 1,
1239
- nw: 7,
1240
- s: 4,
1241
- se: 3,
1242
- sw: 5,
1243
- w: 6
1244
- };
1245
- function _e(e, t) {
1246
- let n = he[Math.floor((e % 360 + 360) % 360 / 30)];
1247
- return me[(ge[t] + n) % 8];
1248
- }
1249
- //#endregion
1250
- //#region src/services/transform/utils/markline.js
1251
- function ve(e, t) {
1252
- let n = {
1253
- x: [],
1254
- y: []
1255
- }, { width: r = 0, height: i = 0 } = t;
1256
- return e.forEach((e) => {
1257
- let { top: t, left: a, width: o, height: s } = e;
1258
- n.y.push({
1259
- showTop: t,
1260
- top: t
1261
- }), n.y.push({
1262
- showTop: t,
1263
- top: t - i
1264
- }), n.y.push({
1265
- showTop: t + s / 2,
1266
- top: t + s / 2 - i / 2
1267
- }), n.y.push({
1268
- showTop: t + s,
1269
- top: t + s
1270
- }), n.y.push({
1271
- showTop: t + s,
1272
- top: t + s - i
1273
- }), n.x.push({
1274
- left: a,
1275
- showLeft: a
1276
- }), n.x.push({
1277
- left: a + o,
1278
- showLeft: a + o
1279
- }), n.x.push({
1280
- left: a + o / 2 - r / 2,
1281
- showLeft: a + o / 2
1282
- }), n.x.push({
1283
- left: a + o - r,
1284
- showLeft: a + o
1285
- }), n.x.push({
1286
- left: a - r,
1287
- showLeft: a
1288
- });
1289
- }), n;
1290
- }
1291
- function ye(e) {
1292
- let t = e.querySelector(".draggable-markline-x"), n = e.querySelector(".draggable-markline-y");
1293
- return t || (t = document.createElement("div"), t.className = "draggable-markline-x", e.appendChild(t)), n || (n = document.createElement("div"), n.className = "draggable-markline-y", e.appendChild(n)), {
1294
- x: t,
1295
- y: n
1296
- };
1297
- }
1298
- function X(e) {
1299
- e && (e.style.display = "none");
1300
- }
1301
- //#endregion
1302
- //#region src/services/transform/utils/resize.js
1303
- function Z(e, t, n) {
1304
- let r = e + t;
1305
- return r > n ? e = r : (t = n - e, e = n), {
1306
- deltaW: t,
1307
- width: e
1308
- };
1309
- }
1310
- function Q(e, t, n) {
1311
- let r = e + t;
1312
- return r > n ? e = r : (t = n - e, e = n), {
1313
- deltaH: t,
1314
- height: e
1315
- };
1316
- }
1317
- function be(e, t, n, r, i, a, o) {
1318
- let { width: s, height: c, centerX: l, centerY: u, rotateAngle: d } = t, f = s < 0 ? -1 : 1, p = c < 0 ? -1 : 1;
1319
- switch (s = Math.abs(s), c = Math.abs(c), [
1320
- "top-left",
1321
- "top-right",
1322
- "bottom-left",
1323
- "bottom-right"
1324
- ].includes(e) && (e === "top-right" ? r = -r : e === "bottom-left" ? n = -n : e === "top-left" && (n = -n, r = -r), {width: s, deltaW: n} = Z(s, n, a), {height: c, deltaH: r} = Q(c, r, o), i && (r = n / i, c = s / i)), e) {
1325
- case "right":
1326
- ({width: s, deltaW: n} = Z(s, n, a)), i ? (r = n / i, c = s / i, l += n / 2 * Math.cos(G(d)) - r / 2 * Math.sin(G(d)), u += n / 2 * Math.sin(G(d)) + r / 2 * Math.cos(G(d))) : (l += n / 2 * Math.cos(G(d)), u += n / 2 * Math.sin(G(d)));
1327
- break;
1328
- case "top-right":
1329
- l += n / 2 * Math.cos(G(d)) + r / 2 * Math.sin(G(d)), u += n / 2 * Math.sin(G(d)) - r / 2 * Math.cos(G(d));
1330
- break;
1331
- case "bottom-right":
1332
- l += n / 2 * Math.cos(G(d)) - r / 2 * Math.sin(G(d)), u += n / 2 * Math.sin(G(d)) + r / 2 * Math.cos(G(d));
1333
- break;
1334
- case "bottom":
1335
- ({height: c, deltaH: r} = Q(c, r, o)), i ? (n = r * i, s = c * i, l += n / 2 * Math.cos(G(d)) - r / 2 * Math.sin(G(d)), u += n / 2 * Math.sin(G(d)) + r / 2 * Math.cos(G(d))) : (l -= r / 2 * Math.sin(G(d)), u += r / 2 * Math.cos(G(d)));
1336
- break;
1337
- case "bottom-left":
1338
- l -= n / 2 * Math.cos(G(d)) + r / 2 * Math.sin(G(d)), u -= n / 2 * Math.sin(G(d)) - r / 2 * Math.cos(G(d));
1339
- break;
1340
- case "left":
1341
- n = -n, {width: s, deltaW: n} = Z(s, n, a), i ? (c = s / i, r = n / i, l -= n / 2 * Math.cos(G(d)) + r / 2 * Math.sin(G(d)), u -= n / 2 * Math.sin(G(d)) - r / 2 * Math.cos(G(d))) : (l -= n / 2 * Math.cos(G(d)), u -= n / 2 * Math.sin(G(d)));
1342
- break;
1343
- case "top-left":
1344
- l -= n / 2 * Math.cos(G(d)) - r / 2 * Math.sin(G(d)), u -= n / 2 * Math.sin(G(d)) + r / 2 * Math.cos(G(d));
1345
- break;
1346
- case "top":
1347
- r = -r, {height: c, deltaH: r} = Q(c, r, o), i ? (s = c * i, n = r * i, l += n / 2 * Math.cos(G(d)) + r / 2 * Math.sin(G(d)), u += n / 2 * Math.sin(G(d)) - r / 2 * Math.cos(G(d))) : (l += r / 2 * Math.sin(G(d)), u -= r / 2 * Math.cos(G(d)));
1348
- break;
1349
- default: break;
1350
- }
1351
- return {
1352
- position: {
1353
- centerX: l,
1354
- centerY: u
1355
- },
1356
- size: {
1357
- height: c * p,
1358
- width: s * f
1359
- }
1360
- };
1361
- }
1362
- //#endregion
1363
- //#region src/services/transform/utils/handles.js
1364
- function xe(e) {
1365
- let t = e?.querySelector?.(":scope > .draggable-dot-wrap");
1366
- return t ? [...t.querySelectorAll?.(".draggable-dot") || []] : [];
1367
- }
1368
- function Se(e) {
1369
- let t = e?.dataset?.dir;
1370
- return t && pe[t] || "right";
1371
- }
1372
- function Ce(e) {
1373
- return !!e?.hasAttribute?.(t.handleRotateAttr);
1374
- }
1375
- function $(e) {
1376
- return !!e?.hasAttribute?.(t.handleResizeAttr);
1377
- }
1378
- //#endregion
1379
- //#region src/services/TransformControllerService.js
1380
- var we = class {
1381
- order = 25;
1382
- #e;
1383
- constructor(e = {}) {
1384
- this.#e = {
1385
- resizable: !0,
1386
- rotatable: !0,
1387
- boundary: !0,
1388
- scaleRatio: 1,
1389
- snapToGrid: !1,
1390
- gridX: 10,
1391
- gridY: 10,
1392
- aspectRatio: void 0,
1393
- minWidth: 10,
1394
- minHeight: 10,
1395
- maxWidth: 0,
1396
- maxHeight: 0,
1397
- rotateSnap: !1,
1398
- rotateStep: 15,
1399
- snap: !0,
1400
- snapThreshold: 10,
1401
- markline: !0,
1402
- disableMirrorInScope: !0,
1403
- disableDropIndicatorInScope: !0,
1404
- canTransform: () => !0,
1405
- ...e
1406
- };
1407
- }
1408
- #t(e, n) {
1409
- let r = t.scaleRatioAttr || "scale-ratio", i = n?.getAttr?.(e, r) ?? n?.getAttr?.(e, `data-${r}`) ?? e?.getAttribute?.(r) ?? e?.getAttribute?.(`data-${r}`), a = Number.parseFloat(String(i ?? ""));
1410
- if (Number.isFinite(a) && a > 0) return a;
1411
- let o = Number(this.#e.scaleRatio);
1412
- return Number.isFinite(o) && o > 0 ? o : 1;
1413
- }
1414
- #n(e) {
1415
- let t = Number(e?.scaleRatio);
1416
- if (Number.isFinite(t) && t > 0) return t;
1417
- let n = Number(this.#e.scaleRatio);
1418
- return Number.isFinite(n) && n > 0 ? n : 1;
1419
- }
1420
- onDown(e) {
1421
- let t = e?.session;
1422
- if (!t?.isDragScope || !m(t.sourceEl) || !this.#e.resizable) return;
1423
- let { angle: n } = Y(t.sourceEl);
1424
- n && this.#l(t.sourceEl, n);
1425
- }
1426
- onStart(e) {
1427
- let n = e.session;
1428
- if (!n?.active || !n?.started || !n.isDragScope || !m(n.sourceEl) || typeof this.#e.canTransform == "function" && !this.#e.canTransform(n.sourceEl)) return;
1429
- let r = n.selectedByNs?.get(n.namespace), i = Array.isArray(r) && r.length > 1, a = "move", o = "", s = this.#e.rotatable && f(n.sourceEl, t.rotatableAttr, !0), c = this.#e.resizable && f(n.sourceEl, t.resizableAttr, !0);
1430
- if (Ce(n.handleEl) && s) {
1431
- if (i) return;
1432
- a = "rotate";
1433
- } else if ($(n.handleEl) && c) {
1434
- if (i) return;
1435
- a = "resize", o = Se(n.handleEl);
1436
- }
1437
- this.#e.disableMirrorInScope && this.#m(n), this.#e.disableDropIndicatorInScope && this.#h(n), n.cache.__transform = {
1438
- phase: 0,
1439
- type: a,
1440
- side: o,
1441
- scaleRatio: void 0,
1442
- container: void 0,
1443
- containerRect: void 0,
1444
- containerRectScaled: void 0,
1445
- boundary: void 0,
1446
- start: void 0,
1447
- data: void 0,
1448
- center: void 0,
1449
- rotateOffset: 0,
1450
- startRect: void 0,
1451
- viewportCenterOffset: void 0,
1452
- lines: void 0,
1453
- guideX: void 0,
1454
- guideY: void 0,
1455
- mark: {
1456
- diffX: 0,
1457
- diffY: 0,
1458
- left: void 0,
1459
- top: void 0
1460
- },
1461
- didCompute: !1,
1462
- lastValidData: void 0,
1463
- lastAppliedX: void 0,
1464
- lastAppliedY: void 0,
1465
- lastAppliedW: void 0,
1466
- lastAppliedH: void 0,
1467
- lastAppliedAngle: void 0,
1468
- multiSelection: {
1469
- enabled: i,
1470
- elements: [],
1471
- initialTransforms: []
1472
- }
1473
- };
1474
- }
1475
- onMeasure(e) {
1476
- let n = e.session, r = n?.cache?.__transform;
1477
- if (!n?.active || !n?.started || !n.isDragScope || !r || r.phase !== 0) return;
1478
- if (!m(n.sourceEl)) {
1479
- n.cache.__transform = void 0;
1480
- return;
1481
- }
1482
- let i = e.adapter.closestDragScope(n.sourceEl);
1483
- if (!m(i)) {
1484
- n.cache.__transform = void 0;
1485
- return;
1486
- }
1487
- let a = this.#t(i, e.adapter), o = Y(n.sourceEl), s = e.adapter.measureRect(i), c = {
1488
- height: s.height / a,
1489
- left: s.left / a,
1490
- top: s.top / a,
1491
- width: s.width / a
1492
- };
1493
- if (r.container = i, r.scaleRatio = a, r.containerRect = s, r.containerRectScaled = c, r.start = { ...o }, r.data = { ...o }, r.center = {
1494
- x: o.x + o.width / 2,
1495
- y: o.y + o.height / 2
1496
- }, this.#e.boundary && (r.boundary = {
1497
- w: Math.max(0, i.clientWidth),
1498
- h: Math.max(0, i.clientHeight)
1499
- }), r.type === "rotate") {
1500
- let e = (n.x - s.left) / a, t = (n.y - s.top) / a;
1501
- r.rotateOffset = J(r.center.x, r.center.y, e, t) - r.data.angle;
1502
- }
1503
- if (this.#e.snap || this.#e.markline) {
1504
- let o = q(n.sourceEl, a, e.adapter);
1505
- r.startRect = o, r.viewportCenterOffset = {
1506
- x: o.left + o.width / 2 - r.center.x,
1507
- y: o.top + o.height / 2 - r.center.y
1508
- };
1509
- let s = [...i.querySelectorAll?.(`[${t.dragAttr}]`) || []], c = [];
1510
- for (let t of s) t !== n.sourceEl && m(t) && c.push(q(t, a, e.adapter));
1511
- if (r.lines = ve(c, o), this.#e.markline) {
1512
- let e = ye(i);
1513
- r.guideX = e.x, r.guideY = e.y;
1514
- }
1515
- }
1516
- if (r.multiSelection.enabled) {
1517
- let e = n.selectedByNs?.get(n.namespace);
1518
- if (Array.isArray(e)) for (let t of e) t !== n.sourceEl && m(t) && (r.multiSelection.elements.push(t), r.multiSelection.initialTransforms.push(Y(t)));
1519
- }
1520
- r.phase = 1;
1521
- }
1522
- onCompute(e) {
1523
- let t = e.session, n = t?.cache?.__transform;
1524
- !t?.active || !t?.started || !t.isDragScope || !n || n.phase !== 1 || m(t.sourceEl) && (n.didCompute = !0, n.type === "move" ? this.#r(t, n) : n.type === "rotate" ? this.#i(t, n) : n.type === "resize" && this.#a(t, n));
1525
- }
1526
- onCommit(e) {
1527
- let t = e.session, n = t?.cache?.__transform;
1528
- if (!t?.active || !t?.started || !t.isDragScope || !n || n.phase !== 1 || !n.didCompute || !m(t.sourceEl)) return;
1529
- if (this.#d(e, t.sourceEl, n), n.multiSelection.enabled && n.type === "move") {
1530
- let t = n.data.x - n.start.x, r = n.data.y - n.start.y;
1531
- for (let i = 0; i < n.multiSelection.elements.length; i++) {
1532
- let a = n.multiSelection.elements[i], o = n.multiSelection.initialTransforms[i], s = {
1533
- x: o.x + t,
1534
- y: o.y + r,
1535
- width: o.width,
1536
- height: o.height,
1537
- angle: o.angle
1538
- };
1539
- this.#u(e, a, s);
1540
- }
1541
- }
1542
- n.type === "rotate" && this.#e.resizable && n.lastCursorAngle !== n.data?.angle && (n.lastCursorAngle = n.data?.angle, e.frame?.run?.(() => {
1543
- this.#l(t.sourceEl, n.lastCursorAngle || 0);
1544
- })), this.#e.markline && this.#c(e, n);
1545
- let r = e.dnd;
1546
- if (r?.emit && n?.data) {
1547
- let i = {
1548
- type: n.type,
1549
- el: t.sourceEl,
1550
- ...n.data
1551
- }, a = n.type === "move" ? "draggable:drag" : n.type === "rotate" ? "draggable:rotate" : "draggable:resize";
1552
- e.frame?.run?.(() => {
1553
- r.emit(a, i);
1554
- });
1555
- }
1556
- n.didCompute = !1;
1557
- }
1558
- onEnd(e, t) {
1559
- let n = e.session, r = n?.cache?.__transform;
1560
- r && (X(r.guideX), X(r.guideY), t?.ended && m(n?.sourceEl) && r?.data && e.dnd?.emit?.("draggable:drop", {
1561
- type: r.type,
1562
- el: n.sourceEl,
1563
- data: n.data,
1564
- ...r.data
1565
- }), t?.ended && r.type === "rotate" && this.#e.resizable && m(n?.sourceEl) && this.#l(n.sourceEl, r.data?.angle || 0), n.cache.__transform = void 0);
1566
- }
1567
- onDestroy(e, t) {
1568
- let n = t?.cache?.__transform;
1569
- n && (X(n.guideX), X(n.guideY), t.cache.__transform = void 0);
1570
- }
1571
- #r(e, t) {
1572
- let n = this.#n(t), r = t.start.x + e.dx / n, i = t.start.y + e.dy / n;
1573
- this.#e.snapToGrid && (r = t.start.x + K(r - t.start.x, this.#e.gridX), i = t.start.y + K(i - t.start.y, this.#e.gridY)), t.data = {
1574
- ...t.data,
1575
- x: r,
1576
- y: i
1577
- }, this.#s(t), this.#f(t.data, t.boundary);
1578
- }
1579
- #i(e, t) {
1580
- let n = this.#n(t), r = t.containerRect;
1581
- if (!r) return;
1582
- let i = (e.x - r.left) / n, a = (e.y - r.top) / n, o = J(t.center.x, t.center.y, i, a) - (t.rotateOffset ?? 0);
1583
- if (o = (o % 360 + 360) % 360, this.#e.rotateSnap) {
1584
- let e = Number(this.#e.rotateStep) || 15;
1585
- o = Math.round(o / e) * e;
1586
- }
1587
- t.data = {
1588
- ...t.data,
1589
- angle: o
1590
- };
1591
- }
1592
- #a(e, t) {
1593
- let n = this.#n(t), r = this.#e.aspectRatio, i = e.dx / n, a = e.dy / n, o = Math.atan2(a, i), s = ue(i, a), c = o - G(t.start.angle), l = s * Math.cos(c), u = s * Math.sin(c), d = {
1594
- centerX: t.start.x + t.start.width / 2,
1595
- centerY: t.start.y + t.start.height / 2,
1596
- height: t.start.height,
1597
- rotateAngle: t.start.angle,
1598
- width: t.start.width
1599
- }, { position: { centerX: f, centerY: p }, size: { width: m, height: h } } = be(t.side, d, l, u, r, this.#e.minWidth, this.#e.minHeight), g = fe({
1600
- angle: t.data.angle,
1601
- centerX: f,
1602
- centerY: p,
1603
- height: h,
1604
- width: m
1605
- }), _ = {
1606
- ...t.data,
1607
- ...de(g, f, p)
1608
- };
1609
- if (this.#e.maxWidth > 0 && (_.width = Math.min(_.width, this.#e.maxWidth)), this.#e.maxHeight > 0 && (_.height = Math.min(_.height, this.#e.maxHeight)), this.#e.snapToGrid) {
1610
- let e = _.x + _.width / 2, n = _.y + _.height / 2, i = this.#e.gridX, a = this.#e.gridY, o = t.start.width + K(_.width - t.start.width, i), s;
1611
- s = r ? o / r : t.start.height + K(_.height - t.start.height, a), _.width = Math.abs(o), _.height = Math.abs(s), _.x = e - _.width / 2, _.y = n - _.height / 2;
1612
- }
1613
- let v = _;
1614
- this.#p(v, t.boundary) ? (t.data = v, t.lastValidData = { ...v }) : t.data = t.lastValidData ? { ...t.lastValidData } : { ...t.start }, this.#s(t);
1615
- }
1616
- #o(e) {
1617
- let t = e?.data, n = e?.viewportCenterOffset;
1618
- if (!t || !n) return e.startRect;
1619
- let r = G(t.angle || 0), i = Math.cos(r), a = Math.sin(r), o = Math.abs(t.width * i) + Math.abs(t.height * a), s = Math.abs(t.width * a) + Math.abs(t.height * i), c = t.x + t.width / 2 + n.x, l = t.y + t.height / 2 + n.y, u = c - o / 2, d = l - s / 2;
1620
- return {
1621
- bottom: d + s,
1622
- height: s,
1623
- left: u,
1624
- right: u + o,
1625
- top: d,
1626
- width: o
1627
- };
1628
- }
1629
- #s(e) {
1630
- if (!this.#e.snap && !this.#e.markline || !e?.lines || !e.containerRectScaled) return;
1631
- let t = this.#o(e), n = e.lines || {
1632
- x: [],
1633
- y: []
1634
- }, r = {
1635
- diffX: 0,
1636
- diffY: 0,
1637
- left: void 0,
1638
- top: void 0
1639
- };
1640
- for (let i = 0; i < (n.y.length || 0); i++) {
1641
- let { top: a, showTop: o } = n.y[i], s = a - t.top;
1642
- if (Math.abs(s) < this.#e.snapThreshold) {
1643
- r.diffY = s, r.top = o - e.containerRectScaled.top;
1644
- break;
1645
- }
1646
- }
1647
- for (let i = 0; i < (n.x.length || 0); i++) {
1648
- let { left: a, showLeft: o } = n.x[i], s = a - t.left;
1649
- if (Math.abs(s) < this.#e.snapThreshold) {
1650
- r.diffX = s, r.left = o - e.containerRectScaled.left;
1651
- break;
1652
- }
1653
- }
1654
- this.#e.snap && (r.diffX && (e.data.x += r.diffX), r.diffY && (e.data.y += r.diffY)), e.mark = r;
1655
- }
1656
- #c(e, t) {
1657
- let { guideX: n, guideY: r } = t, i = t.mark || {};
1658
- n && (i.left === void 0 ? e.frame?.setStyle?.(n, "display", "none") : (e.frame?.setStyle?.(n, "display", "block"), e.frame?.setStyle?.(n, "transform", `translate(${W(i.left)}, 0)`))), r && (i.top === void 0 ? e.frame?.setStyle?.(r, "display", "none") : (e.frame?.setStyle?.(r, "display", "block"), e.frame?.setStyle?.(r, "transform", `translate(0, ${W(i.top)})`)));
1659
- }
1660
- #l(e, t) {
1661
- let n = xe(e);
1662
- for (let e of n) {
1663
- let n = e?.dataset?.dir;
1664
- n && (e.style.cursor = `${_e(t, n)}-resize`);
1665
- }
1666
- }
1667
- #u(e, t, n) {
1668
- e.frame?.setStyle?.(t, "transform", `translate(${W(n.x)}, ${W(n.y)}) rotate(${n.angle}deg)`);
1669
- }
1670
- #d(e, t, n) {
1671
- let r = n.data;
1672
- n.lastAppliedW !== r.width && (e.frame?.setStyle?.(t, "width", W(r.width)), n.lastAppliedW = r.width), n.lastAppliedH !== r.height && (e.frame?.setStyle?.(t, "height", W(r.height)), n.lastAppliedH = r.height), (n.lastAppliedX !== r.x || n.lastAppliedY !== r.y || n.lastAppliedAngle !== r.angle) && (this.#u(e, t, r), n.lastAppliedX = r.x, n.lastAppliedY = r.y, n.lastAppliedAngle = r.angle);
1673
- }
1674
- #f(e, t) {
1675
- if (!t) return;
1676
- let n = G(e.angle || 0), r = Math.abs(Math.cos(n)), i = Math.abs(Math.sin(n)), a = e.width * r + e.height * i, o = e.width * i + e.height * r, s = (a - e.width) / 2, c = t.w - a / 2 - e.width / 2, l = (o - e.height) / 2, u = t.h - o / 2 - e.height / 2;
1677
- e.x = Math.max(Math.min(s, c), Math.min(e.x, Math.max(s, c))), e.y = Math.max(Math.min(l, u), Math.min(e.y, Math.max(l, u)));
1678
- }
1679
- #p(e, t) {
1680
- if (!t) return !0;
1681
- let n = G(e.angle || 0), r = Math.abs(Math.cos(n)), i = Math.abs(Math.sin(n)), a = e.width * r + e.height * i, o = e.width * i + e.height * r, s = e.x + e.width / 2, c = e.y + e.height / 2, l = s - a / 2, u = s + a / 2, d = c - o / 2, f = c + o / 2;
1682
- return !(l < -.5 || d < -.5 || u > t.w + .5 || f > t.h + .5);
1683
- }
1684
- #m(e) {
1685
- if (e?.mirrorEl) {
1686
- try {
1687
- e.mirrorEl.parentNode?.removeChild?.(e.mirrorEl);
1688
- } catch {}
1689
- e.mirrorEl = void 0;
1690
- }
1691
- if (m(e?.sourceEl)) try {
1692
- e.sourceEl.style.visibility = "";
1693
- } catch {}
1694
- }
1695
- #h(e) {
1696
- if (e?.indicatorEl) {
1697
- try {
1698
- e.indicatorEl.parentNode?.removeChild?.(e.indicatorEl);
1699
- } catch {}
1700
- e.indicatorEl = void 0, e.indicatorRegion = void 0;
1701
- }
1702
- e.currentDrop = void 0, e.currentDropRect = void 0, e.currentAllowed = !1;
1703
- }
1704
- }, Te = {
1705
- name: "@ptahjs/dnd",
1706
- version: "0.0.4"
1707
- };
1708
- //#endregion
1709
- export { j as ACTIVE_WRAP_CLASS, B as ActiveSelectionService, D as AutoScrollService, M as DOT_CLASS, re as Dnd, Te as DndVersion, le as DropIndicatorService, x as DropService, U as MarqueeSelectionService, S as MirrorService, N as ROTATE_CLASS, we as TransformControllerService, z as clearAll, R as setMultipleActive };