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