@eightshift/ui-components 1.5.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/{Dialog-DSquJZb-.js → Dialog-BdtBguys.js} +1 -1
  2. package/dist/Heading-DGnF6JDc.js +17 -0
  3. package/dist/List-Bx2anbX-.js +583 -0
  4. package/dist/{RSPContexts-DQtGvvpM.js → RSPContexts-2lR5GG9p.js} +2 -2
  5. package/dist/{Select-49a62830.esm-D8voKavK.js → Select-c7902d94.esm-DtzFQzf-.js} +6 -4
  6. package/dist/assets/style.css +1 -1
  7. package/dist/components/animated-visibility/animated-visibility.js +139 -118
  8. package/dist/components/checkbox/checkbox.js +1 -1
  9. package/dist/components/color-pickers/color-picker.js +18 -11
  10. package/dist/components/color-pickers/solid-color-picker.js +1 -1
  11. package/dist/components/component-toggle/component-toggle.js +44 -4
  12. package/dist/components/draggable/draggable-handle.js +45 -0
  13. package/dist/components/draggable/draggable.js +5138 -96
  14. package/dist/components/draggable-list/draggable-list-item.js +16 -25
  15. package/dist/components/draggable-list/draggable-list.js +54 -86
  16. package/dist/components/expandable/expandable.js +63 -40
  17. package/dist/components/index.js +6 -4
  18. package/dist/components/link-input/link-input.js +2 -2
  19. package/dist/components/menu/menu.js +2 -2
  20. package/dist/components/modal/modal.js +4 -15
  21. package/dist/components/options-panel/options-panel.js +55 -1
  22. package/dist/components/popover/popover.js +1 -1
  23. package/dist/components/repeater/repeater-item.js +76 -27
  24. package/dist/components/repeater/repeater.js +72 -5110
  25. package/dist/components/select/async-multi-select.js +1 -1
  26. package/dist/components/select/async-single-select.js +1 -1
  27. package/dist/components/select/multi-select.js +1 -1
  28. package/dist/components/select/single-select.js +1 -1
  29. package/dist/components/select/styles.js +1 -1
  30. package/dist/icons/jsx-svg.js +1 -1
  31. package/dist/index.js +6 -4
  32. package/dist/{react-jsx-parser.min-CAGfntg1.js → react-jsx-parser.min-sPC96O_U.js} +124 -85
  33. package/dist/{react-select-async.esm-DY-cP0QK.js → react-select-async.esm-CxA8wpeT.js} +1 -1
  34. package/dist/{react-select.esm-DNlXj0hV.js → react-select.esm-CeE7o5M9.js} +1 -1
  35. package/dist/{useMenuTrigger-BbwpSVmh.js → useMenuTrigger-CT2-BFLo.js} +1 -1
  36. package/package.json +14 -14
  37. package/dist/components/draggable/draggable-item.js +0 -66
  38. package/dist/swapy-qb4t7itb.js +0 -3059
@@ -1,3059 +0,0 @@
1
- var Ot = Object.defineProperty;
2
- var Dt = (r, t, e) => t in r ? Ot(r, t, { enumerable: true, configurable: true, writable: true, value: e }) : r[t] = e;
3
- var E = (r, t, e) => Dt(r, typeof t != "symbol" ? t + "" : t, e);
4
- function Ct(r, t) {
5
- if (r.size !== t.size)
6
- return false;
7
- for (let [e, i] of r)
8
- if (!t.has(e) || t.get(e) !== i)
9
- return false;
10
- return true;
11
- }
12
- let Wt = 0;
13
- function qt() {
14
- return Wt++ + "";
15
- }
16
- var Ut = Object.defineProperty, Ht = (r, t, e) => t in r ? Ut(r, t, { enumerable: true, configurable: true, writable: true, value: e }) : r[t] = e, a = (r, t, e) => Ht(r, typeof t != "symbol" ? t + "" : t, e);
17
- class K {
18
- constructor(t) {
19
- a(this, "x"), a(this, "y"), a(this, "target"), this.x = t.x, this.y = t.y, this.target = t.target;
20
- }
21
- }
22
- class Lt extends K {
23
- }
24
- class nt extends K {
25
- }
26
- class rt extends K {
27
- }
28
- class at extends K {
29
- }
30
- class Nt {
31
- constructor(t) {
32
- a(this, "pluginId"), a(this, "pluginName"), a(this, "viewName"), a(this, "dataName"), a(this, "dataValue"), this.event = t, this.pluginId = t.pluginId, this.pluginName = t.pluginName, this.viewName = t.viewName, this.dataName = t.dataName, this.dataValue = t.dataValue;
33
- }
34
- }
35
- function Yt(r) {
36
- return r.replace(/(?:^\w|[A-Z]|\b\w)/g, function(t, e) {
37
- return e === 0 ? t.toLowerCase() : t.toUpperCase();
38
- }).replace(/\s+/g, "").replace(/-+/g, "");
39
- }
40
- function yt(r) {
41
- return r.split("").map((t, e) => t.toUpperCase() === t ? `${e !== 0 ? "-" : ""}${t.toLowerCase()}` : t).join("");
42
- }
43
- class Y {
44
- constructor(t) {
45
- a(this, "node"), this.node = t.node;
46
- }
47
- }
48
- class Q {
49
- constructor(t) {
50
- a(this, "node"), this.node = t.node;
51
- }
52
- }
53
- class jt {
54
- constructor(t) {
55
- a(this, "_eventBus"), a(this, "_observer"), this._eventBus = t, this._observer = new MutationObserver(this._handler.bind(this)), this._observer.observe(document.body, {
56
- childList: true,
57
- subtree: true,
58
- attributes: true,
59
- attributeOldValue: true
60
- });
61
- }
62
- _handler(t) {
63
- t.forEach((e) => {
64
- e.addedNodes.forEach((s) => {
65
- if (!(s instanceof HTMLElement) || s.dataset.velViewId || s.parentElement && typeof s.parentElement.dataset.velAdded < "u")
66
- return;
67
- let n = s;
68
- if (s.dataset.velView || (n = s.querySelector("[data-vel-view][data-vel-plugin]")), !n) return;
69
- this._eventBus.emitEvent(Y, { node: n });
70
- const o = n.querySelectorAll("[data-vel-plugin]");
71
- o.length && o.forEach((l) => {
72
- this._eventBus.emitEvent(Y, { node: l });
73
- });
74
- }), e.removedNodes.forEach((s) => {
75
- if (!(s instanceof HTMLElement) || typeof s.dataset.velProcessing < "u") return;
76
- const n = s.querySelectorAll("[data-vel-plugin]");
77
- n.length && n.forEach((o) => {
78
- this._eventBus.emitEvent(Q, { node: o });
79
- }), this._eventBus.emitEvent(Q, { node: s });
80
- });
81
- const i = e.attributeName;
82
- if (i === "data-vel-view" && this._eventBus.emitEvent(Y, {
83
- node: e.target
84
- }), i && /data-vel-data-.+/gi.test(i)) {
85
- const s = e.target, n = s.dataset.velPluginId || "", o = s.dataset.velPlugin || "", l = s.dataset.velView || "", h = s.getAttribute(i);
86
- if (h && h !== e.oldValue) {
87
- const g = Yt(
88
- i.replace("data-vel-data-", "")
89
- );
90
- this._eventBus.emitEvent(Nt, {
91
- pluginId: n,
92
- pluginName: o,
93
- viewName: l,
94
- dataName: g,
95
- dataValue: h
96
- });
97
- }
98
- }
99
- });
100
- }
101
- }
102
- class Xt {
103
- execute(t) {
104
- this.call(t);
105
- }
106
- }
107
- class Vt extends Xt {
108
- constructor(t) {
109
- super(), a(this, "_handler"), this._handler = t;
110
- }
111
- getHandler() {
112
- return this._handler;
113
- }
114
- call(t) {
115
- this._handler(t);
116
- }
117
- }
118
- class tt {
119
- constructor() {
120
- a(this, "_listeners", /* @__PURE__ */ new Map()), a(this, "_keyedListeners", /* @__PURE__ */ new Map());
121
- }
122
- subscribeToEvent(t, e, i) {
123
- if (i) {
124
- this._subscribeToKeyedEvent(t, e, i);
125
- return;
126
- }
127
- let s = this._listeners.get(t);
128
- s || (s = [], this._listeners.set(t, s)), s.push(new Vt(e));
129
- }
130
- removeEventListener(t, e, i) {
131
- if (i) {
132
- this._removeKeyedEventListener(t, e, i);
133
- return;
134
- }
135
- let s = this._listeners.get(t);
136
- s && (s = s.filter(
137
- (n) => n.getHandler() !== e
138
- ), this._listeners.set(t, s));
139
- }
140
- _subscribeToKeyedEvent(t, e, i) {
141
- let s = this._keyedListeners.get(t);
142
- s || (s = /* @__PURE__ */ new Map(), this._keyedListeners.set(t, s));
143
- let n = s.get(i);
144
- n || (n = [], s.set(i, n)), n.push(new Vt(e));
145
- }
146
- _removeKeyedEventListener(t, e, i) {
147
- let s = this._keyedListeners.get(t);
148
- if (!s)
149
- return;
150
- let n = s.get(i);
151
- n && (n = n.filter(
152
- (o) => o.getHandler() !== e
153
- ), s.set(i, n));
154
- }
155
- emitEvent(t, e, i) {
156
- if (i) {
157
- this._emitKeyedEvent(t, e, i);
158
- return;
159
- }
160
- const s = this._listeners.get(t);
161
- s && s.forEach((n) => {
162
- n.execute(e);
163
- });
164
- }
165
- _emitKeyedEvent(t, e, i) {
166
- const s = this._keyedListeners.get(t);
167
- if (!s) return;
168
- const n = s.get(i);
169
- n && n.forEach((o) => {
170
- o.execute(e);
171
- });
172
- }
173
- _convertListener(t) {
174
- return (e) => t(e);
175
- }
176
- subscribeToPluginReadyEvent(t, e, i = false) {
177
- if (i) {
178
- this.subscribeToEvent(
179
- It,
180
- this._convertListener(t),
181
- e
182
- );
183
- return;
184
- }
185
- this.subscribeToEvent(
186
- Tt,
187
- this._convertListener(t),
188
- e
189
- );
190
- }
191
- emitPluginReadyEvent(t, e, i = false) {
192
- if (i) {
193
- this.emitEvent(
194
- It,
195
- e,
196
- t
197
- );
198
- return;
199
- }
200
- this.emitEvent(
201
- Tt,
202
- e,
203
- t
204
- );
205
- }
206
- reset() {
207
- this._listeners.clear();
208
- }
209
- }
210
- let Kt = 0;
211
- function St() {
212
- return Kt++ + "";
213
- }
214
- class Bt {
215
- constructor(t, e, i, s, n, o, l) {
216
- a(this, "_registry"), a(this, "_eventBus"), a(this, "_appEventBus"), a(this, "_internalEventBus"), a(this, "_initialized", false), a(this, "_config"), a(this, "_pluginFactory"), a(this, "_pluginName"), a(this, "_id"), a(this, "_pluginKey"), a(this, "_layoutIdViewMapWaitingToEnter"), a(this, "_apiData"), a(this, "_isReady", false), this._id = St(), this._pluginFactory = t, this._pluginName = e, this._registry = i, this._eventBus = s, this._appEventBus = n, this._internalEventBus = new tt(), this._config = o, this._layoutIdViewMapWaitingToEnter = /* @__PURE__ */ new Map(), this._pluginKey = l, this._apiData = {}, this._appEventBus.subscribeToPluginReadyEvent(
217
- () => {
218
- this._isReady = true;
219
- },
220
- this._pluginName,
221
- true
222
- );
223
- }
224
- get api() {
225
- return this._apiData;
226
- }
227
- _setApi(t) {
228
- this._apiData = t;
229
- }
230
- get pluginName() {
231
- return this._pluginName;
232
- }
233
- get pluginFactory() {
234
- return this._pluginFactory;
235
- }
236
- get pluginKey() {
237
- return this._pluginKey;
238
- }
239
- get id() {
240
- return this._id;
241
- }
242
- get config() {
243
- return { ...this._config };
244
- }
245
- getViews(t) {
246
- return t ? this._registry.getViewsByNameForPlugin(this, t) : this._registry.getViewsForPlugin(this);
247
- }
248
- getView(t) {
249
- return t ? this._registry.getViewsByNameForPlugin(this, t)[0] : this._registry.getViewsForPlugin(this)[0];
250
- }
251
- getViewById(t) {
252
- return this._registry.getViewById(t);
253
- }
254
- addView(t) {
255
- this._registry.assignViewToPlugin(t, this);
256
- }
257
- setInternalEventBus(t) {
258
- this._internalEventBus = t;
259
- }
260
- get internalBusEvent() {
261
- return this._internalEventBus;
262
- }
263
- emit(t, e) {
264
- this._internalEventBus.emitEvent(t, e, this.pluginKey);
265
- }
266
- on(t, e) {
267
- this._internalEventBus.subscribeToEvent(t, e, this.pluginKey);
268
- }
269
- removeListener(t, e) {
270
- this._internalEventBus.removeEventListener(t, e);
271
- }
272
- useEventPlugin(t, e = {}) {
273
- const i = this._registry.createPlugin(
274
- t,
275
- this._eventBus,
276
- e
277
- );
278
- return this._registry.associateEventPluginWithPlugin(this.id, i.id), i;
279
- }
280
- notifyAboutDataChanged(t) {
281
- this.onDataChanged(t);
282
- }
283
- // @ts-ignore
284
- onDataChanged(t) {
285
- }
286
- removeView(t) {
287
- t.onRemoveCallback ? this._invokeRemoveCallback(t) : this._deleteView(t), this.onViewRemoved(t);
288
- }
289
- _invokeRemoveCallback(t) {
290
- const e = this._createTemporaryView(t);
291
- requestAnimationFrame(() => {
292
- var i;
293
- (i = e.onRemoveCallback) == null || i.call(e, e, () => {
294
- var s, n;
295
- if ((s = t.onAddCallbacks) != null && s.afterRemoved && t.layoutId) {
296
- const o = this._layoutIdViewMapWaitingToEnter.get(
297
- t.layoutId
298
- );
299
- (n = o == null ? void 0 : o.onAddCallbacks) == null || n.afterEnter(o), this._layoutIdViewMapWaitingToEnter.delete(t.layoutId);
300
- }
301
- this._deleteView(e, true);
302
- }), setTimeout(() => {
303
- e.element.parentElement && this._deleteView(e, true);
304
- }, 1e4);
305
- });
306
- }
307
- _deleteView(t, e = false) {
308
- (e || !t.layoutId) && (this._registry.removeViewById(t.id, this.id), t.element.remove());
309
- }
310
- // This is a temporary view for deleted view. We need to create it
311
- // to show it again so the user can animate it before it disappears.
312
- _createTemporaryView(t) {
313
- const e = t.previousRect.viewportOffset, i = t.previousRect.size, s = t.rotation.degrees < 0 ? 0 : Math.sin(t.rotation.radians) * i.height * t.scale.y, n = t.rotation.degrees > 0 ? 0 : Math.sin(t.rotation.radians) * i.width * t.scale.y, o = t.element.cloneNode(true);
314
- t.element.remove(), o.style.cssText = "", o.style.position = "absolute", o.style.left = `${e.left + s}px`, o.style.top = `${e.top - n}px`, o.style.width = `${i.width}px`, o.style.height = `${i.height}px`, o.style.transform = `
315
- scale3d(${t.scale.x}, ${t.scale.y}, 1) rotate(${t.rotation.degrees}deg)
316
- `, o.style.pointerEvents = "none", o.dataset.velRemoved = "", document.body.appendChild(o);
317
- const l = this._registry.createView(o, t.name);
318
- return l.setAsTemporaryView(), l.styles.position = "absolute", l.styles.left = `${e.left + s}px`, l.styles.top = `${e.top - n}px`, l.rotation.setDegrees(t.rotation.degrees, false), l.scale.set({ x: t.scale.x, y: t.scale.y }, false), l.size.set(
319
- { width: t._localWidth, height: t._localHeight },
320
- false
321
- ), t._copyAnimatorsToAnotherView(l), t.onRemoveCallback && l.onRemove(t.onRemoveCallback), l;
322
- }
323
- // @ts-ignore
324
- onViewRemoved(t) {
325
- }
326
- notifyAboutViewAdded(t) {
327
- this.onViewAdded(t), this._invokeAddCallbacks(t);
328
- }
329
- _invokeAddCallbacks(t) {
330
- var e, i, s;
331
- !((e = t.onAddCallbacks) != null && e.onInitialLoad) && !this._initialized || ((i = t.onAddCallbacks) == null || i.beforeEnter(t), !((s = t.onAddCallbacks) != null && s.afterRemoved) || !this._initialized ? requestAnimationFrame(() => {
332
- var n;
333
- (n = t.onAddCallbacks) == null || n.afterEnter(t);
334
- }) : t.layoutId && this._layoutIdViewMapWaitingToEnter.set(t.layoutId, t));
335
- }
336
- // @ts-ignore
337
- onViewAdded(t) {
338
- }
339
- init() {
340
- !this._initialized && this._isReady && (this.setup(), this._initialized = true);
341
- }
342
- setup() {
343
- }
344
- // @ts-ignore
345
- subscribeToEvents(t) {
346
- }
347
- }
348
- class Gt extends Bt {
349
- isRenderable() {
350
- return true;
351
- }
352
- isInitialized() {
353
- return this._initialized;
354
- }
355
- get initialized() {
356
- return this._initialized;
357
- }
358
- // @ts-ignore
359
- update(t, e) {
360
- }
361
- render() {
362
- }
363
- addView(t) {
364
- t.setPluginId(this.id), super.addView(t);
365
- }
366
- }
367
- class ot extends Bt {
368
- isRenderable() {
369
- return false;
370
- }
371
- }
372
- class Zt {
373
- constructor(t) {
374
- a(this, "_plugin"), this._plugin = t;
375
- }
376
- get initialized() {
377
- return this._plugin.isInitialized();
378
- }
379
- get config() {
380
- return this._plugin.config;
381
- }
382
- setup(t) {
383
- this._plugin.setup = t;
384
- }
385
- api(t) {
386
- this._plugin._setApi(t);
387
- }
388
- update(t) {
389
- this._plugin.update = t;
390
- }
391
- render(t) {
392
- this._plugin.render = t;
393
- }
394
- getViews(t) {
395
- return this._plugin.getViews(t);
396
- }
397
- getView(t) {
398
- return this._plugin.getView(t);
399
- }
400
- getViewById(t) {
401
- return this._plugin.getViewById(t);
402
- }
403
- useEventPlugin(t, e = {}) {
404
- return this._plugin.useEventPlugin(t, e);
405
- }
406
- emit(t, e) {
407
- this._plugin.emit(t, e);
408
- }
409
- on(t, e) {
410
- this._plugin.on(t, e);
411
- }
412
- onDataChanged(t) {
413
- this._plugin.onDataChanged = t;
414
- }
415
- onViewRemoved(t) {
416
- this._plugin.onViewRemoved = t;
417
- }
418
- onViewAdded(t) {
419
- this._plugin.onViewAdded = t;
420
- }
421
- subscribeToEvents(t) {
422
- this._plugin.subscribeToEvents = t;
423
- }
424
- }
425
- function Z(r, t, e, i, s, n) {
426
- if (Jt(r))
427
- return new r(
428
- r,
429
- r.pluginName,
430
- t,
431
- e,
432
- i,
433
- s,
434
- n
435
- );
436
- const o = new Gt(
437
- r,
438
- r.pluginName,
439
- t,
440
- e,
441
- i,
442
- s,
443
- n
444
- ), l = new Zt(o);
445
- return r(l), o;
446
- }
447
- function Jt(r) {
448
- var t;
449
- return ((t = r.prototype) == null ? void 0 : t.constructor.toString().indexOf("class ")) === 0;
450
- }
451
- class u {
452
- constructor(t, e) {
453
- a(this, "x"), a(this, "y"), this.x = t, this.y = e;
454
- }
455
- get magnitudeSquared() {
456
- return this.x * this.x + this.y * this.y;
457
- }
458
- get magnitude() {
459
- return Math.sqrt(this.x * this.x + this.y * this.y);
460
- }
461
- get unitVector() {
462
- const t = new u(0, 0), e = this.magnitude;
463
- return e !== 0 && (t.x = this.x / e, t.y = this.y / e), t;
464
- }
465
- add(t) {
466
- this.x += t.x, this.y += t.y;
467
- }
468
- sub(t) {
469
- this.x -= t.x, this.y -= t.y;
470
- }
471
- scale(t) {
472
- this.x *= t, this.y *= t;
473
- }
474
- dot(t) {
475
- return this.x * t.x + this.y * t.y;
476
- }
477
- equals(t) {
478
- return this.x === t.x && this.y === t.y;
479
- }
480
- clone() {
481
- return new u(this.x, this.y);
482
- }
483
- static scale(t, e) {
484
- return new u(t.x * e, t.y * e);
485
- }
486
- static sub(t, e) {
487
- return new u(t.x - e.x, t.y - e.y);
488
- }
489
- static add(t, e) {
490
- return new u(t.x + e.x, t.y + e.y);
491
- }
492
- }
493
- class Qt {
494
- constructor(t) {
495
- a(this, "_element"), a(this, "_callback"), this._element = t, this._observe();
496
- }
497
- setElement(t) {
498
- this._element = t, this._observe();
499
- }
500
- _observe() {
501
- var t;
502
- const e = new MutationObserver(() => {
503
- var n;
504
- (n = this._callback) == null || n.call(this, false);
505
- }), i = {
506
- attributes: true,
507
- childList: true,
508
- attributeOldValue: true
509
- };
510
- e.observe(this._element, i), new ResizeObserver(() => {
511
- var n;
512
- (n = this._callback) == null || n.call(this, true);
513
- }).observe(this._element);
514
- function s(n, o) {
515
- let l, h = true;
516
- return function() {
517
- h && (n(), h = false), clearTimeout(l), l = setTimeout(() => {
518
- n(), h = true;
519
- }, o);
520
- };
521
- }
522
- (t = this._element.parentElement) == null || t.addEventListener(
523
- "scroll",
524
- s(() => {
525
- var n;
526
- (n = this._callback) == null || n.call(this, true);
527
- }, 30)
528
- ), window.addEventListener(
529
- "scroll",
530
- s(() => {
531
- var n;
532
- (n = this._callback) == null || n.call(this, true);
533
- }, 30)
534
- ), window.addEventListener(
535
- "resize",
536
- s(() => {
537
- var n;
538
- (n = this._callback) == null || n.call(this, true);
539
- }, 30)
540
- );
541
- }
542
- onChange(t) {
543
- this._callback = t;
544
- }
545
- }
546
- function te(r) {
547
- return new Qt(r);
548
- }
549
- function ee(r, t) {
550
- const e = t.x - r.x, i = t.y - r.y;
551
- return Math.sqrt(e * e + i * i);
552
- }
553
- function _(r, t) {
554
- const e = r - t;
555
- return Math.abs(e) <= 0.01;
556
- }
557
- function b(r) {
558
- let t = r.match(/^([\d.]+)([a-zA-Z%]*)$/);
559
- t || (t = "0px".match(/^([\d.]+)([a-zA-Z%]*)$/));
560
- const e = parseFloat(t[1]), i = t[2];
561
- return { value: e, unit: i, valueWithUnit: r };
562
- }
563
- function ie(r, t, e = false) {
564
- if (r === t) return true;
565
- if (r.length !== t.length) return false;
566
- for (let i = 0; i < r.length; i++)
567
- if (e && !_(r[i].value, t[i].value) || r[i].value !== t[i].value)
568
- return false;
569
- return true;
570
- }
571
- function bt(r, t) {
572
- return ie(r, t, true);
573
- }
574
- class z {
575
- constructor(t, e, i, s) {
576
- a(this, "_topLeft"), a(this, "_topRight"), a(this, "_bottomLeft"), a(this, "_bottomRight"), this._topLeft = t, this._topRight = e, this._bottomLeft = i, this._bottomRight = s;
577
- }
578
- get value() {
579
- return {
580
- topLeft: this._topLeft,
581
- topRight: this._topRight,
582
- bottomRight: this._bottomRight,
583
- bottomLeft: this._bottomLeft
584
- };
585
- }
586
- equals(t) {
587
- return _(this.value.topLeft.value, t.value.topLeft.value) && _(this.value.topRight.value, t.value.topRight.value) && _(this.value.bottomRight.value, t.value.bottomRight.value) && _(this.value.bottomLeft.value, t.value.bottomLeft.value);
588
- }
589
- toCssPercentageForNewSize(t) {
590
- const e = this._convertToPercentage(this._topLeft, t), i = this._convertToPercentage(this._topRight, t), s = this._convertToPercentage(this._bottomLeft, t), n = this._convertToPercentage(this._bottomRight, t);
591
- return `${e.h} ${i.h} ${n.h} ${s.h} / ${e.v} ${i.v} ${n.v} ${s.v}`;
592
- }
593
- _convertToPercentage(t, e) {
594
- if (t.unit === "%")
595
- return { h: `${t.value}%`, v: `${t.value}%` };
596
- const i = t.value / e.width * 100, s = t.value / e.height * 100;
597
- return { h: `${i}%`, v: `${s}%` };
598
- }
599
- }
600
- function et(r) {
601
- const t = r.split(" ").map((i) => b(i)), e = {
602
- value: 0,
603
- unit: "",
604
- valueWithUnit: "0"
605
- };
606
- switch (t.length) {
607
- case 1:
608
- return new z(t[0], t[0], t[0], t[0]);
609
- case 2:
610
- return new z(t[0], t[1], t[0], t[1]);
611
- case 3:
612
- return new z(t[0], t[1], t[2], t[1]);
613
- case 4:
614
- return new z(t[0], t[1], t[3], t[2]);
615
- default:
616
- return new z(
617
- e,
618
- e,
619
- e,
620
- e
621
- );
622
- }
623
- }
624
- function se(r, t) {
625
- const e = o(r.topLeft, t), i = o(r.topRight, t), s = o(r.bottomLeft, t), n = o(r.bottomRight, t);
626
- return {
627
- v: {
628
- topLeft: e.v,
629
- topRight: i.v,
630
- bottomRight: n.v,
631
- bottomLeft: s.v
632
- },
633
- h: {
634
- topLeft: e.h,
635
- topRight: i.h,
636
- bottomRight: n.h,
637
- bottomLeft: s.h
638
- }
639
- };
640
- function o(l, h) {
641
- if (l.unit === "%")
642
- return {
643
- h: b(`${l.value}%`),
644
- v: b(`${l.value}%`)
645
- };
646
- const g = l.value / h.width * 100, d = l.value / h.height * 100;
647
- return { h: b(`${g}%`), v: b(`${d}%`) };
648
- }
649
- }
650
- function Pt(r, t) {
651
- return _(r.topLeft.value, t.topLeft.value) && _(r.topRight.value, t.topRight.value) && _(r.bottomRight.value, t.bottomRight.value) && _(r.bottomLeft.value, t.bottomLeft.value);
652
- }
653
- class ne {
654
- constructor(t) {
655
- a(this, "_value"), this._value = t;
656
- }
657
- get value() {
658
- return this._value;
659
- }
660
- equals(t) {
661
- return _(this.value, t.value);
662
- }
663
- }
664
- function re(r) {
665
- return new ne(parseFloat(r));
666
- }
667
- class ae {
668
- constructor(t, e) {
669
- a(this, "_x"), a(this, "_y"), this._x = t, this._y = e;
670
- }
671
- get value() {
672
- return new u(this._x, this._y);
673
- }
674
- }
675
- function oe(r, t) {
676
- const [e, i] = r.split(" "), s = b(e), n = b(i);
677
- return new ae(
678
- s.value / t.width,
679
- n.value / t.height
680
- );
681
- }
682
- function Et(r, t) {
683
- const e = le(r), i = r.offsetWidth, s = r.offsetHeight;
684
- return {
685
- viewportOffset: {
686
- left: Math.round(e.left),
687
- top: Math.round(e.top),
688
- right: Math.round(e.right),
689
- bottom: Math.round(e.bottom)
690
- },
691
- pageOffset: t.read({
692
- width: i,
693
- height: s
694
- }),
695
- size: {
696
- width: i,
697
- height: s
698
- }
699
- };
700
- }
701
- function le(r) {
702
- const t = r.getBoundingClientRect();
703
- return {
704
- left: t.left,
705
- top: t.top,
706
- right: t.right,
707
- bottom: t.bottom,
708
- width: t.width,
709
- height: t.height
710
- };
711
- }
712
- function Rt(r) {
713
- let t = r, e = 0, i = 0;
714
- for (; t; )
715
- e += t.offsetTop, i += t.offsetLeft, t = t.offsetParent;
716
- return { top: e, left: i };
717
- }
718
- class he {
719
- constructor(t) {
720
- a(this, "_currentPageRect"), a(this, "_view"), a(this, "_element"), a(this, "_offsetLeft"), a(this, "_offsetTop"), a(this, "_width"), a(this, "_height"), a(this, "_parentWidth"), a(this, "_parentHeight"), a(this, "_parentEl"), a(this, "_isSvg"), a(this, "_invalid"), this._invalid = true, this._view = t, this._element = t.element, this._isSvg = !!this._element.closest("svg"), this._offsetLeft = 0, this._offsetTop = 0, this._width = 0, this._height = 0, this._parentWidth = 0, this._parentHeight = 0, this._offsetLeft = 0, this._parentEl = this._element.parentElement, window.addEventListener("resize", () => {
721
- this.invalidate();
722
- });
723
- }
724
- invalidate() {
725
- this._invalid = true;
726
- }
727
- read(t) {
728
- if (this._isSvg)
729
- return this._currentPageRect || (this._currentPageRect = Rt(this._element)), this._currentPageRect;
730
- const e = this._element.parentElement, i = this._element.offsetLeft, s = this._element.offsetTop, n = t.width, o = t.height, l = (e == null ? void 0 : e.offsetWidth) || 0, h = (e == null ? void 0 : e.offsetHeight) || 0;
731
- return (this._offsetLeft !== i || this._offsetTop !== s || !_(this._width, n) || !_(this._height, o)) && this._view._children.forEach(
732
- (g) => g.elementReader.invalidatePageRect()
733
- ), !this._invalid && this._currentPageRect && this._offsetLeft === i && this._offsetTop === s && _(this._width, n) && _(this._height, o) && _(this._parentWidth, l) && _(this._parentHeight, h) && this._parentEl === e ? this._currentPageRect : (this._offsetLeft = i, this._offsetTop = s, this._width = n, this._height = o, this._parentWidth = l, this._parentHeight = h, this._parentEl = e, this._currentPageRect = Rt(this._element), this._invalid = false, this._currentPageRect);
734
- }
735
- }
736
- function ue(r) {
737
- return new he(r);
738
- }
739
- class ce {
740
- constructor(t) {
741
- a(this, "_element"), a(this, "_rect"), a(this, "_computedStyle"), a(this, "_pageRectReader"), a(this, "_scroll"), this._element = t.element, this._pageRectReader = ue(t), this._rect = Et(this._element, this._pageRectReader), this._computedStyle = getComputedStyle(this._element), this._scroll = this._calculateScroll();
742
- }
743
- invalidatePageRect() {
744
- this._pageRectReader.invalidate();
745
- }
746
- update(t = false) {
747
- this._rect = Et(this._element, this._pageRectReader), this._computedStyle = getComputedStyle(this._element), t && (this._scroll = this._calculateScroll());
748
- }
749
- get rect() {
750
- return this._rect;
751
- }
752
- get opacity() {
753
- return re(this._computedStyle.opacity);
754
- }
755
- get borderRadius() {
756
- return et(this._computedStyle.borderRadius);
757
- }
758
- get origin() {
759
- return oe(
760
- this._computedStyle.transformOrigin,
761
- this._rect.size
762
- );
763
- }
764
- _calculateScroll() {
765
- let t = this._element, e = 0, i = 0;
766
- for (; t; )
767
- e += t.scrollTop, i += t.scrollLeft, t = t.offsetParent;
768
- return i += window.scrollX, e += window.scrollY, { y: e, x: i };
769
- }
770
- get scroll() {
771
- return this._scroll;
772
- }
773
- }
774
- function xt(r) {
775
- return new ce(r);
776
- }
777
- function it(r, t) {
778
- const e = {
779
- set: (i, s, n) => (typeof i[s] == "object" && i[s] !== null ? i[s] = it(n, t) : (t(), i[s] = n), true),
780
- get: (i, s) => typeof i[s] == "object" && i[s] !== null ? it(i[s], t) : i[s]
781
- };
782
- return new Proxy(r, e);
783
- }
784
- const j = 0.01, lt = {
785
- speed: 15
786
- };
787
- class ht {
788
- constructor(t) {
789
- a(this, "name", "dynamic"), a(this, "_config"), this._config = t;
790
- }
791
- get config() {
792
- return this._config;
793
- }
794
- }
795
- class de extends ht {
796
- update({ animatorProp: t, current: e, target: i, dt: s }) {
797
- const n = u.sub(i, e), o = u.scale(n, this._config.speed);
798
- let l = u.add(e, u.scale(o, s));
799
- return this._shouldFinish(i, e, o) && (l = i, requestAnimationFrame(() => {
800
- t.callCompleteCallback();
801
- })), t.callUpdateCallback(), l;
802
- }
803
- _shouldFinish(t, e, i) {
804
- return u.sub(t, e).magnitude < j && i.magnitude < j;
805
- }
806
- }
807
- class ge extends ht {
808
- update({ animatorProp: t, current: e, target: i, dt: s }) {
809
- const n = (i - e) * this._config.speed;
810
- let o = e + n * s;
811
- return _(o, i) && (o = i, requestAnimationFrame(() => {
812
- t.callCompleteCallback();
813
- })), t.callUpdateCallback(), o;
814
- }
815
- }
816
- class pe extends ht {
817
- update({ animatorProp: t, current: e, target: i, dt: s }) {
818
- return i.map((n, o) => {
819
- const l = e[o], h = n.value === 0 ? l.unit : n.unit, g = (n.value - l.value) * this._config.speed, d = l.value + g * s;
820
- let p = b(`${d}${h}`);
821
- return this._shouldFinish(n.value, l.value, g) && (p = n, requestAnimationFrame(() => {
822
- t.callCompleteCallback();
823
- })), t.callUpdateCallback(), p;
824
- });
825
- }
826
- _shouldFinish(t, e, i) {
827
- return Math.abs(t - e) < j && Math.abs(i) < j;
828
- }
829
- }
830
- class ut {
831
- constructor() {
832
- a(this, "name", "instant"), a(this, "_config", {});
833
- }
834
- get config() {
835
- return this._config;
836
- }
837
- update(t) {
838
- return requestAnimationFrame(() => {
839
- t.animatorProp.callCompleteCallback();
840
- }), t.target;
841
- }
842
- }
843
- const ct = {
844
- stiffness: 0.5,
845
- damping: 0.75,
846
- speed: 10
847
- }, X = 0.01;
848
- class dt {
849
- constructor(t) {
850
- a(this, "name", "spring"), a(this, "_config"), this._config = t;
851
- }
852
- get config() {
853
- return this._config;
854
- }
855
- }
856
- class _e extends dt {
857
- constructor() {
858
- super(...arguments), a(this, "_velocity", new u(0, 0));
859
- }
860
- update({ animatorProp: t, current: e, target: i, dt: s }) {
861
- const n = u.scale(
862
- u.scale(u.sub(e, i), -1),
863
- this._config.stiffness
864
- );
865
- this._velocity = u.add(this._velocity, n), this._velocity = u.scale(this._velocity, this._config.damping);
866
- let o = u.add(
867
- e,
868
- u.scale(this._velocity, s * this._config.speed)
869
- );
870
- return this._shouldFinish(i, e) && (o = i, requestAnimationFrame(() => {
871
- t.callCompleteCallback();
872
- })), o;
873
- }
874
- _shouldFinish(t, e) {
875
- return u.sub(t, e).magnitude < X && this._velocity.magnitude < X;
876
- }
877
- }
878
- class me extends dt {
879
- constructor() {
880
- super(...arguments), a(this, "_velocity", 0);
881
- }
882
- update({ animatorProp: t, current: e, target: i, dt: s }) {
883
- const n = -(e - i) * this._config.stiffness;
884
- this._velocity += n, this._velocity *= this._config.damping;
885
- let o = e + this._velocity * s * this._config.speed;
886
- return _(o, i) && (o = i, requestAnimationFrame(() => {
887
- t.callCompleteCallback();
888
- })), o;
889
- }
890
- }
891
- class ve extends dt {
892
- constructor() {
893
- super(...arguments), a(this, "_velocity", 0);
894
- }
895
- update({ animatorProp: t, current: e, target: i, dt: s }) {
896
- return i.map((n, o) => {
897
- const l = e[o], h = n.value === 0 ? l.unit : n.unit, g = -(l.value - n.value) * this._config.stiffness;
898
- this._velocity += g, this._velocity *= this._config.damping;
899
- const d = l.value + this._velocity * s * this._config.speed;
900
- let p = b(`${d}${h}`);
901
- return this._shouldFinish(n.value, l.value) && (p = n, requestAnimationFrame(() => {
902
- t.callCompleteCallback();
903
- })), p;
904
- });
905
- }
906
- _shouldFinish(t, e) {
907
- return Math.abs(t - e) < X && Math.abs(this._velocity) < X;
908
- }
909
- }
910
- function fe(r) {
911
- return r;
912
- }
913
- const gt = {
914
- duration: 350,
915
- ease: fe
916
- };
917
- class pt {
918
- constructor(t) {
919
- a(this, "name", "tween"), a(this, "_config"), a(this, "_startTime"), this._config = t;
920
- }
921
- get config() {
922
- return this._config;
923
- }
924
- reset() {
925
- this._startTime = void 0;
926
- }
927
- }
928
- class we extends pt {
929
- update({ animatorProp: t, initial: e, target: i, ts: s }) {
930
- this._startTime || (this._startTime = s);
931
- const n = Math.min(1, (s - this._startTime) / this._config.duration);
932
- return _(n, 1) ? (requestAnimationFrame(() => {
933
- t.callCompleteCallback();
934
- }), i) : u.add(
935
- e,
936
- u.scale(u.sub(i, e), this._config.ease(n))
937
- );
938
- }
939
- }
940
- class ye extends pt {
941
- update({ animatorProp: t, initial: e, target: i, ts: s }) {
942
- this._startTime || (this._startTime = s);
943
- const n = Math.min(1, (s - this._startTime) / this._config.duration);
944
- return _(n, 1) ? (requestAnimationFrame(() => {
945
- t.callCompleteCallback();
946
- }), i) : e.map((o, l) => {
947
- const h = i[l], g = h.value === 0 ? o.unit : h.unit, d = o.value + this._config.ease(n) * (i[l].value - o.value);
948
- return b(`${d}${g}`);
949
- });
950
- }
951
- }
952
- class Ve extends pt {
953
- update({ animatorProp: t, initial: e, target: i, ts: s }) {
954
- this._startTime || (this._startTime = s);
955
- const n = Math.min(1, (s - this._startTime) / this._config.duration);
956
- return _(n, 1) ? (requestAnimationFrame(() => {
957
- t.callCompleteCallback();
958
- }), i) : e + (i - e) * this._config.ease(n);
959
- }
960
- }
961
- class _t {
962
- createAnimatorByName(t, e) {
963
- switch (t) {
964
- case "instant":
965
- return this.createInstantAnimator();
966
- case "dynamic":
967
- return this.createDynamicAnimator(e);
968
- case "tween":
969
- return this.createTweenAnimator(e);
970
- case "spring":
971
- return this.createSpringAnimator(e);
972
- }
973
- return this.createInstantAnimator();
974
- }
975
- }
976
- class H extends _t {
977
- createInstantAnimator() {
978
- return new ut();
979
- }
980
- createTweenAnimator(t) {
981
- return new we({ ...gt, ...t });
982
- }
983
- createDynamicAnimator(t) {
984
- return new de({ ...lt, ...t });
985
- }
986
- createSpringAnimator(t) {
987
- return new _e({ ...ct, ...t });
988
- }
989
- }
990
- class be extends _t {
991
- createInstantAnimator() {
992
- return new ut();
993
- }
994
- createTweenAnimator(t) {
995
- return new ye({ ...gt, ...t });
996
- }
997
- createDynamicAnimator(t) {
998
- return new pe({
999
- ...lt,
1000
- ...t
1001
- });
1002
- }
1003
- createSpringAnimator(t) {
1004
- return new ve({ ...ct, ...t });
1005
- }
1006
- }
1007
- class At extends _t {
1008
- createInstantAnimator() {
1009
- return new ut();
1010
- }
1011
- createDynamicAnimator(t) {
1012
- return new ge({ ...lt, ...t });
1013
- }
1014
- createTweenAnimator(t) {
1015
- return new Ve({ ...gt, ...t });
1016
- }
1017
- createSpringAnimator(t) {
1018
- return new me({ ...ct, ...t });
1019
- }
1020
- }
1021
- function O(r) {
1022
- return structuredClone(r);
1023
- }
1024
- class Pe {
1025
- constructor(t) {
1026
- a(this, "_viewProp"), a(this, "_completeCallback"), a(this, "_updateCallback"), a(this, "_isAnimating"), this._viewProp = t, this._isAnimating = false;
1027
- }
1028
- set(t, e) {
1029
- this._viewProp.setAnimator(t, e);
1030
- }
1031
- get name() {
1032
- return this._viewProp.getAnimator().name;
1033
- }
1034
- onComplete(t) {
1035
- this._completeCallback = t;
1036
- }
1037
- get isAnimating() {
1038
- return this._isAnimating;
1039
- }
1040
- markAsAnimating() {
1041
- this._isAnimating = true;
1042
- }
1043
- callCompleteCallback() {
1044
- var t;
1045
- (t = this._completeCallback) == null || t.call(this), this._isAnimating = false;
1046
- }
1047
- onUpdate(t) {
1048
- this._updateCallback = t;
1049
- }
1050
- callUpdateCallback() {
1051
- var t;
1052
- (t = this._updateCallback) == null || t.call(this);
1053
- }
1054
- }
1055
- class C {
1056
- constructor(t, e, i) {
1057
- a(this, "_animatorProp"), a(this, "_animator"), a(this, "_initialValue"), a(this, "_previousValue"), a(this, "_targetValue"), a(this, "_currentValue"), a(this, "_hasChanged"), a(this, "_view"), a(this, "_animatorFactory"), a(this, "_previousRenderValue"), this._animatorProp = new Pe(this), this._animatorFactory = t, this._initialValue = O(e), this._previousValue = O(e), this._targetValue = O(e), this._currentValue = O(e), this._hasChanged = false, this._previousRenderValue = void 0, this._view = i, this._animator = this._animatorFactory.createInstantAnimator();
1058
- }
1059
- get shouldRender() {
1060
- return true;
1061
- }
1062
- get isAnimating() {
1063
- return this.animator.isAnimating;
1064
- }
1065
- getAnimator() {
1066
- return this._animator;
1067
- }
1068
- get animator() {
1069
- return this._animatorProp;
1070
- }
1071
- get _rect() {
1072
- return this._view.rect;
1073
- }
1074
- get _previousRect() {
1075
- return this._view.previousRect;
1076
- }
1077
- setAnimator(t, e) {
1078
- this._animator = this._animatorFactory.createAnimatorByName(
1079
- t,
1080
- e
1081
- );
1082
- }
1083
- _setTarget(t, e = true) {
1084
- var i, s;
1085
- this._previousValue = O(this._currentValue), this._targetValue = t, e ? ((s = (i = this._animator).reset) == null || s.call(i), this.animator.markAsAnimating()) : this._currentValue = t, this._hasChanged = true;
1086
- }
1087
- hasChanged() {
1088
- return this._hasChanged;
1089
- }
1090
- destroy() {
1091
- this._hasChanged = false;
1092
- }
1093
- // @ts-ignore
1094
- update(t, e) {
1095
- }
1096
- }
1097
- class Ee extends C {
1098
- constructor() {
1099
- super(...arguments), a(this, "_invertedBorderRadius"), a(this, "_forceStyleUpdateThisFrame", false), a(this, "_updateWithScale", false);
1100
- }
1101
- setFromElementPropValue(t) {
1102
- this._setTarget(
1103
- [
1104
- t.value.topLeft,
1105
- t.value.topRight,
1106
- t.value.bottomRight,
1107
- t.value.bottomLeft
1108
- ],
1109
- true
1110
- );
1111
- }
1112
- enableUpdateWithScale() {
1113
- this._updateWithScale = true;
1114
- }
1115
- disableUpdateWithScale() {
1116
- this._updateWithScale = false;
1117
- }
1118
- get value() {
1119
- return {
1120
- topLeft: this._currentValue[0],
1121
- topRight: this._currentValue[1],
1122
- bottomRight: this._currentValue[2],
1123
- bottomLeft: this._currentValue[3]
1124
- };
1125
- }
1126
- get invertedBorderRadius() {
1127
- return this._invertedBorderRadius;
1128
- }
1129
- set(t, e = true) {
1130
- let i;
1131
- if (typeof t == "string") {
1132
- const h = et(t.trim());
1133
- i = {
1134
- topLeft: h.value.topLeft.valueWithUnit,
1135
- topRight: h.value.topRight.valueWithUnit,
1136
- bottomRight: h.value.bottomRight.valueWithUnit,
1137
- bottomLeft: h.value.bottomLeft.valueWithUnit
1138
- };
1139
- } else
1140
- i = t;
1141
- const s = i.topLeft ? b(i.topLeft) : this._currentValue[0], n = i.topRight ? b(i.topRight) : this._currentValue[1], o = i.bottomRight ? b(i.bottomRight) : this._currentValue[2], l = i.bottomLeft ? b(i.bottomLeft) : this._currentValue[3];
1142
- this._setTarget([s, n, o, l], e);
1143
- }
1144
- reset(t = true) {
1145
- this._setTarget(this._initialValue, t);
1146
- }
1147
- update(t, e) {
1148
- if (this._forceStyleUpdateThisFrame)
1149
- this._hasChanged = true, this._forceStyleUpdateThisFrame = false;
1150
- else if (this._view.scale.isAnimating && this._updateWithScale)
1151
- this._hasChanged = true;
1152
- else if (bt(this._targetValue, this._currentValue)) {
1153
- this._hasChanged = !bt(
1154
- this._targetValue,
1155
- this._initialValue
1156
- );
1157
- return;
1158
- }
1159
- this._currentValue = this._animator.update({
1160
- animatorProp: this._animatorProp,
1161
- current: this._currentValue,
1162
- target: this._targetValue,
1163
- initial: this._previousValue,
1164
- ts: t,
1165
- dt: e
1166
- }), this._updateWithScale && this._applyScaleInverse();
1167
- }
1168
- applyScaleInverse() {
1169
- this._updateWithScale && (this._forceStyleUpdateThisFrame = true);
1170
- }
1171
- _applyScaleInverse() {
1172
- if (_(this._view.scale.x, 1) && _(this._view.scale.y, 1))
1173
- return;
1174
- const t = this._rect.size.width * this._view.scale.x, e = this._rect.size.height * this._view.scale.y;
1175
- this._invertedBorderRadius = se(
1176
- et(
1177
- `${this._currentValue[0].valueWithUnit} ${this._currentValue[1].valueWithUnit} ${this._currentValue[2].valueWithUnit} ${this._currentValue[3].valueWithUnit}`
1178
- ).value,
1179
- {
1180
- width: t,
1181
- height: e
1182
- }
1183
- );
1184
- }
1185
- get shouldRender() {
1186
- return this._hasChanged ? this._previousRenderValue ? !(Pt(
1187
- this.renderValue.v,
1188
- this._previousRenderValue.v
1189
- ) && Pt(this.renderValue.h, this._previousRenderValue.h)) : true : false;
1190
- }
1191
- get renderValue() {
1192
- return this.invertedBorderRadius ? {
1193
- v: {
1194
- topLeft: this.invertedBorderRadius.v.topLeft,
1195
- topRight: this.invertedBorderRadius.v.topRight,
1196
- bottomLeft: this.invertedBorderRadius.v.bottomLeft,
1197
- bottomRight: this.invertedBorderRadius.v.bottomRight
1198
- },
1199
- h: {
1200
- topLeft: this.invertedBorderRadius.h.topLeft,
1201
- topRight: this.invertedBorderRadius.h.topRight,
1202
- bottomLeft: this.invertedBorderRadius.h.bottomLeft,
1203
- bottomRight: this.invertedBorderRadius.h.bottomRight
1204
- }
1205
- } : {
1206
- v: {
1207
- topLeft: this.value.topLeft,
1208
- topRight: this.value.topRight,
1209
- bottomLeft: this.value.bottomLeft,
1210
- bottomRight: this.value.bottomRight
1211
- },
1212
- h: {
1213
- topLeft: this.value.topLeft,
1214
- topRight: this.value.topRight,
1215
- bottomLeft: this.value.bottomLeft,
1216
- bottomRight: this.value.bottomRight
1217
- }
1218
- };
1219
- }
1220
- projectStyles() {
1221
- const t = this.renderValue, e = `border-radius: ${t.h.topLeft.valueWithUnit} ${t.h.topRight.valueWithUnit} ${t.h.bottomRight.valueWithUnit} ${t.h.bottomLeft.valueWithUnit} / ${t.v.topLeft.valueWithUnit} ${t.v.topRight.valueWithUnit} ${t.v.bottomRight.valueWithUnit} ${t.v.bottomLeft.valueWithUnit};`;
1222
- return this._previousRenderValue = t, e;
1223
- }
1224
- isTransform() {
1225
- return false;
1226
- }
1227
- }
1228
- class Re extends C {
1229
- setFromElementPropValue(t) {
1230
- this._setTarget(t.value, true);
1231
- }
1232
- get value() {
1233
- return this._currentValue;
1234
- }
1235
- set(t, e = true) {
1236
- this._setTarget(t, e);
1237
- }
1238
- reset(t = true) {
1239
- this._setTarget(1, t);
1240
- }
1241
- update(t, e) {
1242
- if (_(this._targetValue, this._currentValue)) {
1243
- this._hasChanged = !_(this._targetValue, this._initialValue);
1244
- return;
1245
- }
1246
- this._currentValue = this._animator.update({
1247
- animatorProp: this._animatorProp,
1248
- current: this._currentValue,
1249
- target: this._targetValue,
1250
- initial: this._previousValue,
1251
- ts: t,
1252
- dt: e
1253
- });
1254
- }
1255
- get shouldRender() {
1256
- return this._hasChanged ? typeof this._previousRenderValue > "u" ? true : this.renderValue !== this._previousRenderValue : false;
1257
- }
1258
- get renderValue() {
1259
- return this.value;
1260
- }
1261
- projectStyles() {
1262
- const t = this.renderValue, e = `opacity: ${t};`;
1263
- return this._previousRenderValue = t, e;
1264
- }
1265
- isTransform() {
1266
- return false;
1267
- }
1268
- }
1269
- class xe extends C {
1270
- get x() {
1271
- return this._currentValue.x;
1272
- }
1273
- get y() {
1274
- return this._currentValue.y;
1275
- }
1276
- set(t) {
1277
- const e = { x: this.x, y: this.y, ...t };
1278
- if (e.x < 0 || e.x > 1) {
1279
- console.log(
1280
- `%c WARNING: ${this._view.name}.origin.x property can only be a value from 0 to 1`,
1281
- "background: #885500"
1282
- );
1283
- return;
1284
- }
1285
- if (e.y < 0 || e.y > 1) {
1286
- console.log(
1287
- `%c WARNING: ${this._view.name}.origin.y property can only be a value from 0 to 1`,
1288
- "background: #885500"
1289
- );
1290
- return;
1291
- }
1292
- this._setTarget(new u(e.x, e.y), false);
1293
- }
1294
- reset() {
1295
- this._setTarget(this._initialValue, false);
1296
- }
1297
- get shouldRender() {
1298
- if (!this._hasChanged)
1299
- return false;
1300
- if (!this._previousRenderValue)
1301
- return true;
1302
- const t = this.renderValue;
1303
- return !(_(t.x, this._previousRenderValue.x) && _(t.y, this._previousRenderValue.y));
1304
- }
1305
- get renderValue() {
1306
- return new u(this.x * 100, this.y * 100);
1307
- }
1308
- projectStyles() {
1309
- const t = this.renderValue, e = `transform-origin: ${t.x}% ${t.y}%;`;
1310
- return this._previousRenderValue = t, e;
1311
- }
1312
- isTransform() {
1313
- return false;
1314
- }
1315
- }
1316
- class Ae extends C {
1317
- constructor() {
1318
- super(...arguments), a(this, "_animateLayoutUpdateNextFrame", false), a(this, "_parentScaleInverse", new u(1, 1));
1319
- }
1320
- get _parentDiff() {
1321
- let t = this._view._parent, e = 0, i = 0;
1322
- if (t) {
1323
- const s = t.rect.pageOffset, n = t.getScroll(), o = {
1324
- left: t.previousRect.viewportOffset.left + n.x,
1325
- top: t.previousRect.viewportOffset.top + n.y
1326
- };
1327
- e = o.left - s.left, i = o.top - s.top;
1328
- }
1329
- return { parentDx: e, parentDy: i };
1330
- }
1331
- get x() {
1332
- return this._currentValue.x + this._rect.pageOffset.left + this._parentDiff.parentDx;
1333
- }
1334
- get y() {
1335
- return this._currentValue.y + this._rect.pageOffset.top + this._parentDiff.parentDy;
1336
- }
1337
- get initialX() {
1338
- return this._rect.pageOffset.left;
1339
- }
1340
- get initialY() {
1341
- return this._rect.pageOffset.top;
1342
- }
1343
- progressTo(t) {
1344
- const e = typeof t.x > "u" ? this.initialX : t.x, i = typeof t.y > "u" ? this.initialY : t.y, s = new u(e, i), n = new u(this.initialX, this.initialY), o = new u(this.x, this.y), l = u.sub(o, n), h = u.sub(s, n);
1345
- return 1 - u.sub(h, l).magnitude / h.magnitude;
1346
- }
1347
- set(t, e = true) {
1348
- const i = { x: this.x, y: this.y, ...t };
1349
- this._setTarget(
1350
- new u(
1351
- i.x - this._rect.pageOffset.left,
1352
- i.y - this._rect.pageOffset.top
1353
- ),
1354
- e
1355
- );
1356
- }
1357
- reset(t = true) {
1358
- this._setTarget(new u(0, 0), t);
1359
- }
1360
- update(t, e) {
1361
- if ((this._view.isInverseEffectEnabled || this._view.isLayoutTransitionEnabled) && !this._view.isTemporaryView && this._runLayoutTransition(), this._view.isInverseEffectEnabled) {
1362
- const h = this._view._parent, g = h ? h.scale.x : 1, d = h ? h.scale.y : 1;
1363
- this._parentScaleInverse = new u(1 / g, 1 / d), this._parentScaleInverse.equals(new u(1, 1)) || (this._hasChanged = true);
1364
- }
1365
- if (this._targetValue.x === this._currentValue.x && this._targetValue.y === this._currentValue.y)
1366
- return;
1367
- const i = this._view._parent, s = i ? i.scale.x : 1, n = i ? i.scale.y : 1, o = i ? i.scale._previousValue.x : 1, l = i ? i.scale._previousValue.y : 1;
1368
- this._currentValue = this._animator.update({
1369
- animatorProp: this._animatorProp,
1370
- current: new u(
1371
- this._currentValue.x * s,
1372
- this._currentValue.y * n
1373
- ),
1374
- target: this._targetValue,
1375
- initial: new u(
1376
- this._previousValue.x * o,
1377
- this._previousValue.y * l
1378
- ),
1379
- ts: t,
1380
- dt: e
1381
- }), this._currentValue = new u(
1382
- this._currentValue.x / s,
1383
- this._currentValue.y / n
1384
- );
1385
- }
1386
- _runLayoutTransition() {
1387
- const t = !(this._targetValue.x === this._currentValue.x && this._targetValue.y === this._currentValue.y), e = !(this._view.scale._targetValue.x === this._view.scale._currentValue.x && this._view.scale._targetValue.y === this._view.scale._currentValue.y), i = t || e, s = this._rect.pageOffset.left - this._previousRect.pageOffset.left, n = this._rect.pageOffset.top - this._previousRect.pageOffset.top, o = this._previousRect.size.width / this._rect.size.width, l = this._previousRect.size.height / this._rect.size.height;
1388
- let h = false;
1389
- if (s !== 0 || n !== 0 || !Number.isNaN(o) && o !== 1 || !Number.isNaN(l) && l !== 1 ? h = true : h = (() => {
1390
- const g = this._view._parents;
1391
- for (let d = 0; d < g.length; d++) {
1392
- const p = g[d], w = p.previousRect.size.width / p.rect.size.width, v = p.previousRect.size.height / p.rect.size.height;
1393
- if (w !== 1 || v !== 1)
1394
- return true;
1395
- }
1396
- return false;
1397
- })(), h) {
1398
- if (this._currentValue.x !== 0 || this._currentValue.y !== 0 || this._view.scale._currentValue.x !== 1 || this._view.scale._currentValue.y !== 1) {
1399
- if (!i) {
1400
- const W = this._rect.pageOffset.left - this._previousRect.pageOffset.left, q = this._rect.pageOffset.top - this._previousRect.pageOffset.top;
1401
- this._setTarget(
1402
- new u(this._currentValue.x - W, this._currentValue.y - q),
1403
- false
1404
- );
1405
- return;
1406
- }
1407
- const c = this._view._parent, f = this._rect.pageOffset, m = this._view.getScroll(), R = {
1408
- left: this._previousRect.viewportOffset.left + m.x,
1409
- top: this._previousRect.viewportOffset.top + m.y
1410
- }, T = R.left - f.left, F = R.top - f.top;
1411
- let k = 0, x = 0, $ = 0, vt = 0;
1412
- if (c) {
1413
- const W = c.rect.pageOffset, q = c.getScroll(), U = {
1414
- left: c.previousRect.viewportOffset.left + q.x,
1415
- top: c.previousRect.viewportOffset.top + q.y
1416
- };
1417
- k = U.left - W.left, x = U.top - W.top;
1418
- const ft = R.top - U.top, wt = R.left - U.left, $t = c.scale.y * ft;
1419
- $ = (ft - $t) / c.scale.y;
1420
- const zt = c.scale.x * wt;
1421
- vt = (wt - zt) / c.scale.x;
1422
- }
1423
- this._setTarget(
1424
- new u(T - k + vt, F - x + $),
1425
- false
1426
- ), i && (this._animateLayoutUpdateNextFrame = true);
1427
- return;
1428
- }
1429
- this._animateLayoutUpdateNextFrame = true;
1430
- const g = this._previousRect, d = this._rect, p = this._view._parent;
1431
- let w = 0, v = 0;
1432
- p && (w = p.previousRect.viewportOffset.left - p.rect.viewportOffset.left), p && (v = p.previousRect.viewportOffset.top - p.rect.viewportOffset.top);
1433
- let y = 1, V = 1;
1434
- p && (y = p.previousRect.size.width / p.rect.size.width, V = p.previousRect.size.height / p.rect.size.height);
1435
- const P = p ? p.previousRect.viewportOffset.left : 0, S = p ? p.previousRect.viewportOffset.top : 0, B = g.viewportOffset.left - P, M = g.viewportOffset.top - S, G = B / y - B, D = M / V - M;
1436
- let A = g.viewportOffset.left - d.viewportOffset.left - w + G, L = g.viewportOffset.top - d.viewportOffset.top - v + D;
1437
- A = Number.isFinite(A) ? A : 0, L = Number.isFinite(L) ? L : 0, this._setTarget(new u(A, L), false);
1438
- } else this._animateLayoutUpdateNextFrame && (this._setTarget(this._initialValue, true), this._animateLayoutUpdateNextFrame = false);
1439
- }
1440
- get shouldRender() {
1441
- if (!this._hasChanged)
1442
- return false;
1443
- if (!this._previousRenderValue)
1444
- return true;
1445
- const t = this.renderValue;
1446
- return !(_(t.x, this._previousRenderValue.x) && _(t.y, this._previousRenderValue.y));
1447
- }
1448
- get renderValue() {
1449
- let t = 0, e = 0;
1450
- return (this._view.isInverseEffectEnabled || this._view.isLayoutTransitionEnabled) && (t = (this._rect.size.width * this._parentScaleInverse.x * this._view.scale.x - this._rect.size.width) * this._view.origin.x, e = (this._rect.size.height * this._parentScaleInverse.y * this._view.scale.y - this._rect.size.height) * this._view.origin.y), new u(
1451
- this._currentValue.x + t,
1452
- this._currentValue.y + e
1453
- );
1454
- }
1455
- projectStyles() {
1456
- const t = this.renderValue, e = `translate3d(${t.x}px, ${t.y}px, 0px)`;
1457
- return this._previousRenderValue = t, e;
1458
- }
1459
- isTransform() {
1460
- return true;
1461
- }
1462
- }
1463
- class Te extends C {
1464
- constructor() {
1465
- super(...arguments), a(this, "_unit", "deg");
1466
- }
1467
- get degrees() {
1468
- let t = this._currentValue;
1469
- return this._unit === "rad" && (t = t * (180 / Math.PI)), t;
1470
- }
1471
- get radians() {
1472
- let t = this._currentValue;
1473
- return this._unit === "deg" && (t = t * (Math.PI / 180)), t;
1474
- }
1475
- setDegrees(t, e = true) {
1476
- this._unit = "deg", this._setTarget(t, e);
1477
- }
1478
- setRadians(t, e = true) {
1479
- this._unit = "rad", this._setTarget(t, e);
1480
- }
1481
- reset(t = true) {
1482
- this._setTarget(0, t);
1483
- }
1484
- update(t, e) {
1485
- this._targetValue !== this._currentValue && (this._currentValue = this._animator.update({
1486
- animatorProp: this._animatorProp,
1487
- current: this._currentValue,
1488
- target: this._targetValue,
1489
- initial: this._previousValue,
1490
- ts: t,
1491
- dt: e
1492
- }));
1493
- }
1494
- get shouldRender() {
1495
- if (!this._hasChanged)
1496
- return false;
1497
- if (typeof this._previousRenderValue > "u")
1498
- return true;
1499
- const t = this.renderValue;
1500
- return !_(t, this._previousRenderValue);
1501
- }
1502
- get renderValue() {
1503
- return this._currentValue;
1504
- }
1505
- projectStyles() {
1506
- const t = this.renderValue, e = `rotate(${t}${this._unit})`;
1507
- return this._previousRenderValue = t, e;
1508
- }
1509
- isTransform() {
1510
- return true;
1511
- }
1512
- }
1513
- class Ie extends C {
1514
- constructor() {
1515
- super(...arguments), a(this, "_animateLayoutUpdateNextFrame", false);
1516
- }
1517
- get x() {
1518
- return this._currentValue.x;
1519
- }
1520
- get y() {
1521
- return this._currentValue.y;
1522
- }
1523
- set(t, e = true) {
1524
- const i = { x: this._currentValue.x, y: this._currentValue.y, ...typeof t == "number" ? { x: t, y: t } : t };
1525
- this._setTarget(new u(i.x, i.y), e);
1526
- }
1527
- setWithSize(t, e = true) {
1528
- let i = this._currentValue.x, s = this._currentValue.y;
1529
- t.width && (i = t.width / this._rect.size.width), t.height && (s = t.height / this._rect.size.height), !t.width && t.height && (i = s), !t.height && t.width && (s = i);
1530
- const n = { x: i, y: s };
1531
- this._setTarget(new u(n.x, n.y), e);
1532
- }
1533
- reset(t = true) {
1534
- this._setTarget(new u(1, 1), t);
1535
- }
1536
- update(t, e) {
1537
- if (this._view.layoutOption !== "position") {
1538
- if ((this._view.isInverseEffectEnabled || this._view.isLayoutTransitionEnabled) && !this._view.isTemporaryView && this._runLayoutTransition(), this._view.isInverseEffectEnabled) {
1539
- const i = this._view._parent, s = i ? i.scale.x : 1, n = i ? i.scale.y : 1;
1540
- this._hasChanged = s !== 1 || n !== 1;
1541
- }
1542
- this._targetValue.x === this._currentValue.x && this._targetValue.y === this._currentValue.y || (this._currentValue = this._animator.update({
1543
- animatorProp: this._animatorProp,
1544
- current: this._currentValue,
1545
- target: this._targetValue,
1546
- initial: new u(this._previousValue.x, this._previousValue.y),
1547
- ts: t,
1548
- dt: e
1549
- }));
1550
- }
1551
- }
1552
- _runLayoutTransition() {
1553
- const t = !(this._targetValue.x === this._currentValue.x && this._targetValue.y === this._currentValue.y), e = this._previousRect.size.width / this._rect.size.width, i = this._previousRect.size.height / this._rect.size.height;
1554
- let s = false;
1555
- if ((!Number.isNaN(e) && e !== 1 || !Number.isNaN(i) && i !== 1) && (s = true), s) {
1556
- if (this._currentValue.x !== 1 || this._currentValue.y !== 1) {
1557
- const g = this._view.previousRect.size.width / this._view.rect.size.width, d = this._view.previousRect.size.height / this._view.rect.size.height;
1558
- this._setTarget(
1559
- new u(this._currentValue.x * g, this._currentValue.y * d),
1560
- false
1561
- ), t && (this._animateLayoutUpdateNextFrame = true);
1562
- return;
1563
- }
1564
- const n = this._previousRect.size.width / this._rect.size.width, o = this._previousRect.size.height / this._rect.size.height, l = n, h = o;
1565
- this._view.viewProps.borderRadius.applyScaleInverse(), this._setTarget(new u(l, h), false), this._animateLayoutUpdateNextFrame = true;
1566
- } else this._animateLayoutUpdateNextFrame && (this._setTarget(this._initialValue, true), this._animateLayoutUpdateNextFrame = false);
1567
- }
1568
- get shouldRender() {
1569
- if (!this._hasChanged)
1570
- return false;
1571
- if (!this._previousRenderValue)
1572
- return true;
1573
- const t = this.renderValue;
1574
- return !(_(t.x, this._previousRenderValue.x) && _(t.y, this._previousRenderValue.y));
1575
- }
1576
- get renderValue() {
1577
- const t = this._view._parent ? this._view._parent.scale.x : 1, e = this._view._parent ? this._view._parent.scale.y : 1, i = this._currentValue.x / t, s = this._currentValue.y / e;
1578
- return new u(i, s);
1579
- }
1580
- projectStyles() {
1581
- const t = this.renderValue, e = `scale3d(${t.x}, ${t.y}, 1)`;
1582
- return this._previousRenderValue = t, e;
1583
- }
1584
- isTransform() {
1585
- return true;
1586
- }
1587
- }
1588
- class Ce extends C {
1589
- get width() {
1590
- return this._view.rect.size.width;
1591
- }
1592
- get height() {
1593
- return this._view.rect.size.height;
1594
- }
1595
- get localWidth() {
1596
- return this._currentValue.x;
1597
- }
1598
- get localHeight() {
1599
- return this._currentValue.y;
1600
- }
1601
- get widthAfterScale() {
1602
- const t = this._view.scale.x;
1603
- return this.localWidth * t;
1604
- }
1605
- get heightAfterScale() {
1606
- const t = this._view.scale.y;
1607
- return this.localHeight * t;
1608
- }
1609
- get initialWidth() {
1610
- return this._initialValue.x;
1611
- }
1612
- get initialHeight() {
1613
- return this._initialValue.y;
1614
- }
1615
- set(t, e = true) {
1616
- const i = { width: this._currentValue.x, height: this._currentValue.y, ...t };
1617
- this._setTarget(new u(i.width, i.height), e);
1618
- }
1619
- setWidth(t, e = true) {
1620
- const i = { width: this._currentValue.x, height: this._currentValue.y, width: t };
1621
- this._setTarget(new u(i.width, i.height), e);
1622
- }
1623
- setHeight(t, e = true) {
1624
- const i = { width: this._currentValue.x, height: this._currentValue.y, height: t };
1625
- this._setTarget(new u(i.width, i.height), e);
1626
- }
1627
- reset(t = true) {
1628
- this._setTarget(
1629
- new u(this.initialWidth, this.initialHeight),
1630
- t
1631
- );
1632
- }
1633
- update(t, e) {
1634
- this._targetValue.x === this._currentValue.x && this._targetValue.y === this._currentValue.y || (this._currentValue = this._animator.update({
1635
- animatorProp: this._animatorProp,
1636
- current: this._currentValue,
1637
- target: this._targetValue,
1638
- initial: this._previousValue,
1639
- ts: t,
1640
- dt: e
1641
- }));
1642
- }
1643
- get shouldRender() {
1644
- if (!this._hasChanged)
1645
- return false;
1646
- if (!this._previousRenderValue)
1647
- return true;
1648
- const t = this.renderValue;
1649
- return !(_(t.x, this._previousRenderValue.x) && _(t.y, this._previousRenderValue.y));
1650
- }
1651
- get renderValue() {
1652
- return new u(this._currentValue.x, this._currentValue.y);
1653
- }
1654
- projectStyles() {
1655
- const t = this.renderValue, e = `width: ${t.x}px; height: ${t.y}px;`;
1656
- return this._previousRenderValue = t, e;
1657
- }
1658
- isTransform() {
1659
- return false;
1660
- }
1661
- }
1662
- class Le {
1663
- constructor(t) {
1664
- a(this, "_props", /* @__PURE__ */ new Map()), this._props.set(
1665
- "position",
1666
- new Ae(new H(), new u(0, 0), t)
1667
- ), this._props.set(
1668
- "scale",
1669
- new Ie(new H(), new u(1, 1), t)
1670
- ), this._props.set(
1671
- "rotation",
1672
- new Te(new At(), 0, t)
1673
- ), this._props.set(
1674
- "size",
1675
- new Ce(
1676
- new H(),
1677
- new u(t.rect.size.width, t.rect.size.height),
1678
- t
1679
- )
1680
- ), this._props.set(
1681
- "opacity",
1682
- new Re(
1683
- new At(),
1684
- t.elementReader.opacity.value,
1685
- t
1686
- )
1687
- ), this._props.set(
1688
- "borderRadius",
1689
- new Ee(
1690
- new be(),
1691
- [
1692
- t.elementReader.borderRadius.value.topLeft,
1693
- t.elementReader.borderRadius.value.topRight,
1694
- t.elementReader.borderRadius.value.bottomRight,
1695
- t.elementReader.borderRadius.value.bottomLeft
1696
- ],
1697
- t
1698
- )
1699
- ), this._props.set(
1700
- "origin",
1701
- new xe(
1702
- new H(),
1703
- t.elementReader.origin.value,
1704
- t
1705
- )
1706
- );
1707
- }
1708
- allProps() {
1709
- return Array.from(this._props.values());
1710
- }
1711
- allPropNames() {
1712
- return Array.from(this._props.keys());
1713
- }
1714
- getPropByName(t) {
1715
- return this._props.get(t);
1716
- }
1717
- get position() {
1718
- return this._props.get("position");
1719
- }
1720
- get scale() {
1721
- return this._props.get("scale");
1722
- }
1723
- get rotation() {
1724
- return this._props.get("rotation");
1725
- }
1726
- get size() {
1727
- return this._props.get("size");
1728
- }
1729
- get opacity() {
1730
- return this._props.get("opacity");
1731
- }
1732
- get borderRadius() {
1733
- return this._props.get("borderRadius");
1734
- }
1735
- get origin() {
1736
- return this._props.get("origin");
1737
- }
1738
- }
1739
- class Ne {
1740
- constructor(t, e, i, s) {
1741
- a(this, "id"), a(this, "name"), a(this, "element"), a(this, "styles", {}), a(this, "_viewProps"), a(this, "_previousRect"), a(this, "_onAddCallbacks"), a(this, "_onRemoveCallback"), a(this, "_skipFirstRenderFrame"), a(this, "_layoutTransition"), a(this, "_registry"), a(this, "_layoutId"), a(this, "_elementReader"), a(this, "_viewParents"), a(this, "_temporaryView"), a(this, "_inverseEffect"), a(this, "_renderNextTick"), a(this, "_layoutOption"), a(this, "_elementObserver"), a(this, "_hasReadElement"), a(this, "_shouldReadRect"), a(this, "_readWithScroll"), a(this, "_externalUserStyles"), this._registry = i, this.id = St(), this.name = e, this.element = t, this.element.dataset.velViewId = this.id, this._elementReader = xt(this), this._viewParents = this._getParents(), this._previousRect = this._elementReader.rect, this._viewProps = new Le(this), this._skipFirstRenderFrame = true, this._layoutId = s, this._layoutTransition = false, this._temporaryView = false, this.styles = it(this.styles, () => {
1742
- this._renderNextTick = true;
1743
- }), this._externalUserStyles = this._getExternalUserStyles(), this._renderNextTick = false, this._layoutOption = this._getLayoutOption(), this._hasReadElement = false, this._shouldReadRect = false, this._readWithScroll = false, this._elementObserver = te(t), this._elementObserver.onChange((n) => {
1744
- if (this._hasReadElement) {
1745
- this._shouldReadRect = false;
1746
- return;
1747
- }
1748
- this._externalUserStyles = this._getExternalUserStyles(), this._shouldReadRect = true, this._readWithScroll = n;
1749
- });
1750
- }
1751
- destroy() {
1752
- this._viewProps.allProps().forEach((t) => t.destroy()), this.element.removeAttribute("data-vel-view-id"), this.element.removeAttribute("data-vel-plugin-id"), this._renderNextTick = true;
1753
- }
1754
- get elementReader() {
1755
- return this._elementReader;
1756
- }
1757
- get layoutOption() {
1758
- return this._layoutOption;
1759
- }
1760
- _getLayoutOption() {
1761
- return this.element.closest("[data-vel-layout-position]") ? "position" : this.element.closest("[data-vel-layout-size]") ? "size" : "all";
1762
- }
1763
- setElement(t) {
1764
- this.element = t, this._elementReader = xt(this), this.element.dataset.velViewId = this.id, this._elementObserver.setElement(t), this._viewParents = this._getParents();
1765
- }
1766
- get layoutId() {
1767
- return this._layoutId;
1768
- }
1769
- get position() {
1770
- return this._viewProps.position;
1771
- }
1772
- get scale() {
1773
- return this._viewProps.scale;
1774
- }
1775
- get _children() {
1776
- const t = this.element.querySelectorAll("*");
1777
- return Array.from(t).map((e) => e.dataset.velViewId).filter((e) => e && typeof e == "string").map((e) => this._registry.getViewById(e)).filter((e) => !!e);
1778
- }
1779
- get _parent() {
1780
- return this._parents[0];
1781
- }
1782
- get _parents() {
1783
- return this._viewParents;
1784
- }
1785
- _getParents() {
1786
- var t;
1787
- const e = [];
1788
- let i = this.element.parentElement;
1789
- if (!i) return e;
1790
- for (i = i.closest("[data-vel-view-id]"); i; ) {
1791
- const s = i.dataset.velViewId;
1792
- if (s) {
1793
- const n = this._registry.getViewById(s);
1794
- n && e.push(n);
1795
- }
1796
- i = (t = i.parentElement) == null ? void 0 : t.closest(
1797
- "[data-vel-view-id]"
1798
- );
1799
- }
1800
- return e;
1801
- }
1802
- get rotation() {
1803
- return this._viewProps.rotation;
1804
- }
1805
- get size() {
1806
- return this._viewProps.size;
1807
- }
1808
- get _localWidth() {
1809
- return this._viewProps.size.localWidth;
1810
- }
1811
- get _localHeight() {
1812
- return this._viewProps.size.localHeight;
1813
- }
1814
- get opacity() {
1815
- return this._viewProps.opacity;
1816
- }
1817
- get borderRadius() {
1818
- return this._viewProps.borderRadius;
1819
- }
1820
- get origin() {
1821
- return this._viewProps.origin;
1822
- }
1823
- get data() {
1824
- const t = this.element.dataset;
1825
- return Object.keys(t).filter((e) => e.includes("velData")).map((e) => e.replace("velData", "")).map((e) => `${e[0].toLowerCase()}${e.slice(1)}`).reduce((e, i) => {
1826
- const s = t[`velData${i[0].toUpperCase()}${i.slice(1)}`];
1827
- return !e[i] && s && (e[i] = s), e;
1828
- }, {});
1829
- }
1830
- get onAddCallbacks() {
1831
- return this._onAddCallbacks;
1832
- }
1833
- get onRemoveCallback() {
1834
- return this._onRemoveCallback;
1835
- }
1836
- get isLayoutTransitionEnabled() {
1837
- return this._layoutTransition;
1838
- }
1839
- get hasLayoutTransitionEnabledForParents() {
1840
- return this._parents.some((t) => t.isLayoutTransitionEnabled);
1841
- }
1842
- get isInverseEffectEnabled() {
1843
- let t = false;
1844
- for (let e = 0; e < this._parents.length; e++) {
1845
- const i = this._parents[e];
1846
- if (typeof i._inverseEffect < "u") {
1847
- t = i._inverseEffect;
1848
- break;
1849
- }
1850
- }
1851
- return t;
1852
- }
1853
- layoutTransition(t) {
1854
- this._layoutTransition = t, this.inverseEffect(t);
1855
- }
1856
- inverseEffect(t) {
1857
- this._inverseEffect = t, t && this._children.forEach((e) => {
1858
- if (e.position.animator.name === "instant") {
1859
- const i = this.viewProps.position.getAnimator();
1860
- e.position.setAnimator(
1861
- i.name,
1862
- i.config
1863
- );
1864
- }
1865
- if (e.scale.animator.name === "instant") {
1866
- const i = this.viewProps.scale.getAnimator();
1867
- e.scale.setAnimator(i.name, i.config);
1868
- }
1869
- });
1870
- }
1871
- setAnimatorsFromParent() {
1872
- let t = this._parent;
1873
- for (; t && !t._inverseEffect; )
1874
- t = t._parent;
1875
- if (t) {
1876
- if (this.position.animator.name === "instant") {
1877
- const e = t.viewProps.position.getAnimator();
1878
- this.position.setAnimator(e.name, e.config);
1879
- }
1880
- if (this.scale.animator.name === "instant") {
1881
- const e = t.viewProps.scale.getAnimator();
1882
- this.scale.setAnimator(e.name, e.config);
1883
- }
1884
- }
1885
- }
1886
- get _isRemoved() {
1887
- return !this._registry.getViewById(this.id);
1888
- }
1889
- setPluginId(t) {
1890
- this.element.dataset.velPluginId = t;
1891
- }
1892
- hasElement(t) {
1893
- return this.element.contains(t);
1894
- }
1895
- getScroll() {
1896
- return this._elementReader.scroll;
1897
- }
1898
- intersects(t, e) {
1899
- const i = this.element.getBoundingClientRect(), s = {
1900
- x: i.left,
1901
- y: i.top
1902
- };
1903
- return t >= s.x && t <= s.x + i.width && e >= s.y && e <= s.y + i.height;
1904
- }
1905
- // Using AABB collision detection
1906
- overlapsWith(t) {
1907
- const e = t._localWidth * t.scale.x, i = t._localHeight * t.scale.y, s = this._localWidth * this.scale.x, n = this._localHeight * this.scale.y;
1908
- return this.position.x < t.position.x + e && this.position.x + s > t.position.x && this.position.y < t.position.y + i && this.position.y + n > t.position.y;
1909
- }
1910
- distanceTo(t) {
1911
- const e = new u(this.position.x, this.position.y), i = new u(t.position.x, t.position.y);
1912
- return u.sub(i, e).magnitude;
1913
- }
1914
- read() {
1915
- this._shouldReadRect && (this._elementReader.update(this._readWithScroll), this._children.forEach((t) => {
1916
- t.setHasReadElement(true), t.elementReader.update(this._readWithScroll);
1917
- }), this._shouldReadRect = false, this._readWithScroll = false), this.setHasReadElement(false);
1918
- }
1919
- setHasReadElement(t) {
1920
- this._hasReadElement = t;
1921
- }
1922
- get rect() {
1923
- return this._elementReader.rect;
1924
- }
1925
- get previousRect() {
1926
- return this._previousRect;
1927
- }
1928
- update(t, e) {
1929
- this._viewProps.allProps().forEach((i) => i.update(t, e));
1930
- }
1931
- _updatePreviousRect() {
1932
- this._previousRect = this._elementReader.rect;
1933
- }
1934
- setAsTemporaryView() {
1935
- this._temporaryView = true;
1936
- }
1937
- get isTemporaryView() {
1938
- return this._temporaryView;
1939
- }
1940
- get shouldRender() {
1941
- return this._renderNextTick || this._viewProps.allProps().some((t) => t.shouldRender);
1942
- }
1943
- _cleanCssText(t) {
1944
- const e = /* @__PURE__ */ new Map(), i = /([-\w]+)\s*:\s*([^;]+)\s*;?/g;
1945
- let s;
1946
- for (; (s = i.exec(t)) !== null; ) {
1947
- const [n, o, l] = s;
1948
- if (!l.trim()) continue;
1949
- const h = o.replace(/^-\w+-/, "");
1950
- (!e.has(h) || !o.startsWith("-")) && e.set(
1951
- h,
1952
- `${h}: ${l.trim()}`
1953
- );
1954
- }
1955
- return Array.from(e.values()).join("; ");
1956
- }
1957
- render() {
1958
- if (!this.shouldRender)
1959
- return;
1960
- if (this._isRemoved && this._skipFirstRenderFrame) {
1961
- this._skipFirstRenderFrame = false;
1962
- return;
1963
- }
1964
- let t = "";
1965
- const e = this._viewProps.allProps(), i = e.filter((n) => n.isTransform()), s = e.filter((n) => !n.isTransform());
1966
- if (i.some((n) => n.hasChanged())) {
1967
- const n = i.reduce((o, l, h) => (o += l.projectStyles(), h < i.length - 1 && (o += " "), h === i.length - 1 && (o += ";"), o), "transform: ");
1968
- t += n;
1969
- }
1970
- s.forEach((n) => {
1971
- n.hasChanged() && (t += n.projectStyles());
1972
- }), t += this._getUserStyles(), this._cleanCssText(this.element.style.cssText) !== this._cleanCssText(t) && (this.element.style.cssText = t), this._renderNextTick = false;
1973
- }
1974
- _getExternalUserStyles() {
1975
- const t = this.element.style.cssText, e = this.styles;
1976
- if (t.length === 0)
1977
- return "";
1978
- const i = [
1979
- "transform",
1980
- "transform-origin",
1981
- "opacity",
1982
- "width",
1983
- "height",
1984
- "border-radius"
1985
- ], s = {};
1986
- for (const n in e)
1987
- e.hasOwnProperty(n) && (s[yt(n)] = e[n]);
1988
- return t.split(";").map((n) => n.trim()).filter(Boolean).filter((n) => {
1989
- const o = n.indexOf(":");
1990
- if (o === -1) return false;
1991
- const l = n.slice(0, o).trim();
1992
- return !s.hasOwnProperty(l) && !i.includes(l);
1993
- }).join("; ");
1994
- }
1995
- _getUserStyles() {
1996
- return Object.keys(this.styles).reduce((t, e) => {
1997
- if (!e) return t;
1998
- const i = yt(e).replace("webkit", "-webkit").replace("moz", "-moz");
1999
- return t + `${i}: ${this.styles[e]}; `;
2000
- }, this._externalUserStyles);
2001
- }
2002
- markAsAdded() {
2003
- delete this.element.dataset.velProcessing;
2004
- }
2005
- onAdd(t) {
2006
- this._onAddCallbacks = t;
2007
- }
2008
- onRemove(t) {
2009
- this._onRemoveCallback = t;
2010
- }
2011
- get viewProps() {
2012
- return this._viewProps;
2013
- }
2014
- getPropByName(t) {
2015
- return this._viewProps.getPropByName(t);
2016
- }
2017
- _copyAnimatorsToAnotherView(t) {
2018
- t.viewProps.allPropNames().forEach((e) => {
2019
- var i, s;
2020
- const n = (i = this.viewProps.getPropByName(e)) == null ? void 0 : i.getAnimator();
2021
- n && ((s = t.viewProps.getPropByName(e)) == null || s.setAnimator(n.name, n.config));
2022
- });
2023
- }
2024
- getChildren(t) {
2025
- const e = this.element.querySelectorAll("*"), i = Array.from(e).filter((s) => {
2026
- const n = s;
2027
- return typeof n.dataset.velViewId < "u" && n.dataset.velView === t;
2028
- }).map((s) => s.dataset.velViewId);
2029
- return this._registry.getViewsById(i);
2030
- }
2031
- getChild(t) {
2032
- return this.getChildren(t)[0];
2033
- }
2034
- getParent(t) {
2035
- const e = this.element.closest(
2036
- `[data-vel-view="${t}"]`
2037
- );
2038
- if (!e) return;
2039
- const i = e.dataset.velViewId;
2040
- if (i)
2041
- return this._registry.getViewById(i);
2042
- }
2043
- }
2044
- class Se {
2045
- constructor(t, e) {
2046
- a(this, "_appEventBus"), a(this, "_eventBus"), a(this, "_plugins", []), a(this, "_views", []), a(this, "_viewsPerPlugin", /* @__PURE__ */ new Map()), a(this, "_viewsToBeCreated", []), a(this, "_viewsToBeRemoved", []), a(this, "_viewsCreatedInPreviousFrame", []), a(this, "_layoutIdToViewMap", /* @__PURE__ */ new Map()), a(this, "_eventPluginsPerPlugin", /* @__PURE__ */ new Map()), a(this, "_pluginNameToPluginFactoryMap", /* @__PURE__ */ new Map()), a(this, "_pluginNameToPluginConfigMap", /* @__PURE__ */ new Map()), this._appEventBus = t, this._eventBus = e;
2047
- }
2048
- update() {
2049
- this._handleRemovedViews(), this._handleAddedViews();
2050
- }
2051
- associateEventPluginWithPlugin(t, e) {
2052
- let i = this._eventPluginsPerPlugin.get(t);
2053
- i || (i = [], this._eventPluginsPerPlugin.set(t, i)), i.push(e);
2054
- }
2055
- _handleRemovedViews() {
2056
- const t = this._viewsToBeRemoved.filter((e) => e.dataset.velViewId);
2057
- t.length && (t.forEach((e) => {
2058
- const i = e.dataset.velViewId;
2059
- i && this._handleRemoveView(i);
2060
- }), this._viewsToBeRemoved = []);
2061
- }
2062
- _getPluginNameForElement(t) {
2063
- const e = t.dataset.velPlugin;
2064
- if (e && e.length > 0) return e;
2065
- const i = t.closest("[data-vel-plugin]");
2066
- if (i)
2067
- return i.dataset.velPlugin;
2068
- }
2069
- _getPluginIdForElement(t) {
2070
- const e = this._getPluginNameForElement(t);
2071
- if (!e)
2072
- return;
2073
- const i = t.closest("[data-vel-plugin-id]");
2074
- if (i)
2075
- return i.dataset.velPluginId;
2076
- const s = this.getPluginByName(e);
2077
- if (s)
2078
- return s.id;
2079
- }
2080
- _isScopedElement(t) {
2081
- const e = this._getPluginNameForElement(t);
2082
- if (!e)
2083
- return false;
2084
- const i = this._pluginNameToPluginFactoryMap.get(e), s = i == null ? void 0 : i.scope;
2085
- return t.dataset.velView === s;
2086
- }
2087
- _removeElementsWithParent(t) {
2088
- const e = new Set(t);
2089
- return t.filter((i) => {
2090
- let s = i.parentElement;
2091
- for (; s; ) {
2092
- if (e.has(s))
2093
- return false;
2094
- s = s.parentElement;
2095
- }
2096
- return true;
2097
- });
2098
- }
2099
- _handleAddedViews() {
2100
- this._viewsCreatedInPreviousFrame.forEach((n) => {
2101
- n.markAsAdded();
2102
- }), this._viewsCreatedInPreviousFrame = [];
2103
- const t = this._removeElementsWithParent(
2104
- this._viewsToBeCreated
2105
- ), e = Array.from(
2106
- new Set(
2107
- t.filter(
2108
- (n) => this._isScopedElement(n) && !this._isElementIgnored(n)
2109
- )
2110
- )
2111
- ), i = t.filter(
2112
- (n) => !this._isScopedElement(n) && !this._isElementIgnored(n)
2113
- );
2114
- this._viewsToBeCreated = [], e.forEach((n) => {
2115
- const o = this._getPluginNameForElement(n), l = this._pluginNameToPluginFactoryMap.get(o), h = this._pluginNameToPluginConfigMap.get(o), g = n.dataset.velPluginKey, d = Z(
2116
- l,
2117
- this,
2118
- this._eventBus,
2119
- this._appEventBus,
2120
- h,
2121
- g
2122
- );
2123
- this._plugins.push(d);
2124
- const p = n.dataset.velView, w = this._createNewView(n, p, d);
2125
- w.isInverseEffectEnabled && w.setAnimatorsFromParent(), d.notifyAboutViewAdded(w);
2126
- });
2127
- const s = i.filter((n) => !!this._getPluginIdForElement(n));
2128
- s.length !== 0 && s.forEach((n) => {
2129
- const o = this._getPluginIdForElement(n), l = n.dataset.velView;
2130
- if (!l || !o) return;
2131
- const h = this._getPluginById(o);
2132
- if (!h)
2133
- return;
2134
- const g = this._getLayoutIdForElement(n, h);
2135
- let d;
2136
- g && this._layoutIdToViewMap.has(g) ? (d = this._layoutIdToViewMap.get(g), d.setElement(n), d.setPluginId(h.id), this._createChildrenForView(d, h)) : d = this._createNewView(n, l, h), d.isInverseEffectEnabled && d.setAnimatorsFromParent(), h.notifyAboutViewAdded(d);
2137
- });
2138
- }
2139
- _getLayoutIdForElement(t, e) {
2140
- const i = t.dataset.velLayoutId;
2141
- if (i)
2142
- return `${i}-${e.id}`;
2143
- }
2144
- _createNewView(t, e, i) {
2145
- const s = this._getLayoutIdForElement(t, i), n = this.createView(t, e, s);
2146
- return i.addView(n), n.layoutId && this._layoutIdToViewMap.set(n.layoutId, n), this._createChildrenForView(n, i), this._appEventBus.emitPluginReadyEvent(i.pluginName, i.api, true), requestAnimationFrame(() => {
2147
- requestAnimationFrame(() => {
2148
- this._appEventBus.emitPluginReadyEvent(i.pluginName, i.api);
2149
- });
2150
- }), n;
2151
- }
2152
- _createChildrenForView(t, e) {
2153
- const i = t.element.querySelectorAll("*");
2154
- if (i.length) {
2155
- if (Array.from(i).some(
2156
- (s) => this._getPluginNameForElement(s) !== e.pluginName
2157
- )) {
2158
- console.log(
2159
- `%c WARNING: The plugin "${e.pluginName}" has view(s) created for a different plugin. Make sure all views inside that plugin don't have data-vel-plugin set or the pluginName is set to "${e.pluginName}"`,
2160
- "background: #885500"
2161
- );
2162
- return;
2163
- }
2164
- Array.from(i).filter((s) => !this._isElementIgnored(s)).forEach((s) => {
2165
- const n = s, o = n.dataset.velView ? n.dataset.velView : `${t.name}-child`, l = this._getLayoutIdForElement(n, e), h = this.createView(n, o, l);
2166
- l && !this._layoutIdToViewMap.has(l) && this._layoutIdToViewMap.set(l, h), e.addView(h), e.notifyAboutViewAdded(h);
2167
- });
2168
- }
2169
- }
2170
- _handleRemoveView(t) {
2171
- this._plugins.forEach((e) => {
2172
- if (!this._viewsPerPlugin.get(e.id)) return;
2173
- const i = this._getPluginViewById(e, t);
2174
- i && e.removeView(i);
2175
- });
2176
- }
2177
- removeViewById(t, e) {
2178
- this._unassignViewFromPlugin(t, e), this._views = this._views.filter((i) => i.id !== t);
2179
- }
2180
- _unassignViewFromPlugin(t, e) {
2181
- const i = this._viewsPerPlugin.get(e);
2182
- if (!i) return;
2183
- const s = i.indexOf(t);
2184
- s !== -1 && i.splice(s, 1);
2185
- }
2186
- getViewById(t) {
2187
- return this._views.find((e) => e.id === t);
2188
- }
2189
- getViewsById(t) {
2190
- return this._views.filter((e) => t.includes(e.id));
2191
- }
2192
- _getPluginById(t) {
2193
- return this._plugins.find((e) => e.id === t);
2194
- }
2195
- _getPluginViewById(t, e) {
2196
- return this.getViewsForPlugin(t).find((i) => i.id === e);
2197
- }
2198
- destroy(t, e) {
2199
- if (!t) {
2200
- this._destroyAll(e);
2201
- return;
2202
- }
2203
- let i = [];
2204
- if (t && t.length > 0) {
2205
- const s = this.getPluginByName(t);
2206
- if (s) {
2207
- const n = (this._eventPluginsPerPlugin.get(s.id) || []).map((o) => this._getPluginById(o)).filter((o) => typeof o < "u");
2208
- i.push(s), i.push(...n);
2209
- }
2210
- } else
2211
- i = this._plugins;
2212
- i.forEach((s) => {
2213
- this._destroyPlugin(s);
2214
- }), requestAnimationFrame(() => {
2215
- e == null || e();
2216
- });
2217
- }
2218
- _destroyPlugin(t) {
2219
- const e = this.getViewsForPlugin(t);
2220
- e.forEach((i) => {
2221
- i.layoutId && this._layoutIdToViewMap.delete(i.layoutId), i.destroy();
2222
- }), this._views = this._views.filter(
2223
- (i) => !e.find((s) => s.id === i.id)
2224
- ), this._viewsPerPlugin.delete(t.id), this._plugins = this._plugins.filter((i) => i.id !== t.id);
2225
- }
2226
- _destroyAll(t) {
2227
- this._views.forEach((e) => e.destroy()), requestAnimationFrame(() => {
2228
- this._plugins = [], this._views = [], this._viewsPerPlugin.clear(), this._viewsToBeCreated = [], this._viewsToBeRemoved = [], this._viewsCreatedInPreviousFrame = [], this._layoutIdToViewMap.clear(), this._eventPluginsPerPlugin.clear(), t == null || t();
2229
- });
2230
- }
2231
- reset(t, e) {
2232
- let i = [];
2233
- if (t && t.length > 0) {
2234
- const s = this.getPluginByName(t);
2235
- if (s) {
2236
- const n = (this._eventPluginsPerPlugin.get(s.id) || []).map((o) => this._getPluginById(o)).filter((o) => typeof o < "u");
2237
- i.push(s), i.push(...n);
2238
- }
2239
- } else
2240
- i = this._plugins;
2241
- requestAnimationFrame(() => {
2242
- i.forEach((s) => {
2243
- this._resetPlugin(s);
2244
- }), requestAnimationFrame(() => {
2245
- e == null || e();
2246
- });
2247
- });
2248
- }
2249
- _resetPlugin(t) {
2250
- const e = t.config, i = t.pluginFactory, s = t.internalBusEvent, n = !t.isRenderable(), o = this.getViewsForPlugin(t);
2251
- o.forEach((l) => {
2252
- l.layoutId && this._layoutIdToViewMap.delete(l.layoutId), l.destroy();
2253
- }), this._views = this._views.filter(
2254
- (l) => !o.find((h) => h.id === l.id)
2255
- ), this._viewsPerPlugin.delete(t.id), this._plugins = this._plugins.filter((l) => l.id !== t.id), n || requestAnimationFrame(() => {
2256
- this.createPlugin(
2257
- i,
2258
- this._eventBus,
2259
- e
2260
- ).setInternalEventBus(s);
2261
- });
2262
- }
2263
- queueNodeToBeCreated(t) {
2264
- this._viewsToBeCreated.push(t);
2265
- }
2266
- queueNodeToBeRemoved(t) {
2267
- this._viewsToBeRemoved.push(t);
2268
- }
2269
- notifyPluginAboutDataChange(t) {
2270
- const e = this._plugins.filter(
2271
- (i) => i.id === t.pluginId
2272
- );
2273
- !e || !e.length || e.forEach((i) => {
2274
- i.notifyAboutDataChanged({
2275
- dataName: t.dataName,
2276
- dataValue: t.dataValue,
2277
- viewName: t.viewName
2278
- });
2279
- });
2280
- }
2281
- getPlugins() {
2282
- return this._plugins;
2283
- }
2284
- getRenderablePlugins() {
2285
- function t(e) {
2286
- return e.isRenderable();
2287
- }
2288
- return this._plugins.filter(t);
2289
- }
2290
- getPluginByName(t, e) {
2291
- return this._plugins.find((i) => e ? i.pluginKey === e && i.pluginName === t : i.pluginName === t);
2292
- }
2293
- getPluginsByName(t, e) {
2294
- return this._plugins.filter((i) => e ? i.pluginKey === e && i.pluginName === t : i.pluginName === t);
2295
- }
2296
- hasPlugin(t) {
2297
- return t.pluginName ? !!this.getPluginByName(t.pluginName) : false;
2298
- }
2299
- createPlugin(t, e, i = {}, s = false) {
2300
- if (!t.pluginName)
2301
- throw Error(
2302
- `Plugin ${t.name} must contain a pluginName field`
2303
- );
2304
- let n = [];
2305
- if (t.scope) {
2306
- const h = s ? `[data-vel-plugin=${t.pluginName}][data-vel-view=${t.scope}]:not([data-vel-plugin-id])` : `[data-vel-plugin=${t.pluginName}][data-vel-view=${t.scope}]`, g = document.querySelectorAll(h);
2307
- this._pluginNameToPluginFactoryMap.has(t.pluginName) || this._pluginNameToPluginFactoryMap.set(
2308
- t.pluginName,
2309
- t
2310
- ), this._pluginNameToPluginConfigMap.has(t.pluginName) || this._pluginNameToPluginConfigMap.set(t.pluginName, i), g ? n = Array.from(g) : n = [document.documentElement];
2311
- } else
2312
- n = [document.documentElement];
2313
- const o = n.map((h) => {
2314
- const g = h.dataset.velPluginKey, d = Z(
2315
- t,
2316
- this,
2317
- e,
2318
- this._appEventBus,
2319
- i,
2320
- g
2321
- );
2322
- this._plugins.push(d);
2323
- let p = [];
2324
- h !== document.documentElement && p.push(h);
2325
- const w = h.querySelectorAll(
2326
- `[data-vel-plugin=${d.pluginName}]`
2327
- );
2328
- p = [...p, ...w];
2329
- const v = p.filter((y) => {
2330
- if (this._isElementIgnored(y))
2331
- return false;
2332
- if (!y.parentElement)
2333
- return true;
2334
- const V = this._getPluginNameForElement(y.parentElement);
2335
- return !(V && V.length > 0);
2336
- });
2337
- return v.length && v.forEach((y) => {
2338
- const V = y.dataset.velView;
2339
- if (!V) return;
2340
- const P = this._createNewView(y, V, d);
2341
- d.notifyAboutViewAdded(P);
2342
- }), d;
2343
- });
2344
- if (o && o.length > 0)
2345
- return o[0];
2346
- const l = Z(
2347
- t,
2348
- this,
2349
- e,
2350
- this._appEventBus,
2351
- i
2352
- );
2353
- return t.scope || console.log(
2354
- `%c WARNING: The plugin "${l.pluginName}" is created but there are no elements using it on the page`,
2355
- "background: #885500"
2356
- ), l;
2357
- }
2358
- updatePlugin(t, e, i = {}) {
2359
- return this.createPlugin(t, e, i, true);
2360
- }
2361
- getViews() {
2362
- return this._views;
2363
- }
2364
- createView(t, e, i) {
2365
- const s = new Ne(t, e, this, i);
2366
- return this._views.push(s), this._viewsCreatedInPreviousFrame.push(s), s;
2367
- }
2368
- _isElementIgnored(t) {
2369
- return t.closest("[data-vel-ignore]");
2370
- }
2371
- assignViewToPlugin(t, e) {
2372
- this._viewsPerPlugin.has(e.id) || this._viewsPerPlugin.set(e.id, []);
2373
- const i = this._viewsPerPlugin.get(e.id);
2374
- i.includes(t.id) || i.push(t.id);
2375
- }
2376
- getViewsForPlugin(t) {
2377
- const e = this._viewsPerPlugin.get(t.id);
2378
- return e ? e.map((i) => this._views.find((s) => s.id === i)).filter((i) => !!i) : [];
2379
- }
2380
- getViewsByNameForPlugin(t, e) {
2381
- return this.getViewsForPlugin(t).filter(
2382
- (i) => i.name === e
2383
- );
2384
- }
2385
- }
2386
- class Tt {
2387
- constructor(t) {
2388
- a(this, "pluginApi"), this.pluginApi = t.pluginApi;
2389
- }
2390
- }
2391
- class It {
2392
- constructor(t) {
2393
- a(this, "pluginApi"), this.pluginApi = t.pluginApi;
2394
- }
2395
- }
2396
- class mt {
2397
- constructor() {
2398
- a(this, "previousTime", 0), a(this, "registry"), a(this, "eventBus"), a(this, "appEventBus"), this.eventBus = new tt(), this.appEventBus = new tt(), this.registry = new Se(this.appEventBus, this.eventBus), new jt(this.eventBus);
2399
- }
2400
- static create() {
2401
- return new mt();
2402
- }
2403
- addPlugin(t, e = {}) {
2404
- this.registry.hasPlugin(t) || this.registry.createPlugin(t, this.eventBus, e);
2405
- }
2406
- updatePlugin(t, e = {}) {
2407
- this.registry.hasPlugin(t) && this.registry.updatePlugin(t, this.eventBus, e);
2408
- }
2409
- reset(t, e) {
2410
- this.registry.reset(t, e);
2411
- }
2412
- destroy(t, e) {
2413
- this.registry.destroy(t, e);
2414
- }
2415
- getPlugin(t, e) {
2416
- let i = typeof t == "string" ? t : t.pluginName;
2417
- const s = this.registry.getPluginByName(i, e);
2418
- if (!s)
2419
- throw new Error(
2420
- `You can't call getPlugin for ${i} with key: ${e} because it does not exist in your app`
2421
- );
2422
- return s.api;
2423
- }
2424
- getPlugins(t, e) {
2425
- let i = typeof t == "string" ? t : t.pluginName;
2426
- const s = this.registry.getPluginsByName(i, e);
2427
- if (s.length === 0)
2428
- throw new Error(
2429
- `You can't call getPlugins for ${i} with key: ${e} because they don't exist in your app`
2430
- );
2431
- return s.map((n) => n.api);
2432
- }
2433
- onPluginEvent(t, e, i, s) {
2434
- requestAnimationFrame(() => {
2435
- const n = this.registry.getPluginByName(
2436
- t.pluginName,
2437
- s
2438
- );
2439
- n && n.on(e, i);
2440
- });
2441
- }
2442
- removePluginEventListener(t, e, i) {
2443
- const s = this.registry.getPluginByName(t.pluginName);
2444
- s && s.removeListener(e, i);
2445
- }
2446
- run() {
2447
- document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", this.start.bind(this)) : this.start();
2448
- }
2449
- start() {
2450
- this.setup(), requestAnimationFrame(this.tick.bind(this));
2451
- }
2452
- setup() {
2453
- this.listenToNativeEvents(), this.subscribeToEvents();
2454
- }
2455
- listenToNativeEvents() {
2456
- document.addEventListener("click", (t) => {
2457
- this.eventBus.emitEvent(Lt, {
2458
- x: t.clientX,
2459
- y: t.clientY,
2460
- target: t.target
2461
- });
2462
- }), document.addEventListener("pointermove", (t) => {
2463
- this.eventBus.emitEvent(nt, {
2464
- x: t.clientX,
2465
- y: t.clientY,
2466
- target: t.target
2467
- });
2468
- }), document.addEventListener("pointerdown", (t) => {
2469
- this.eventBus.emitEvent(rt, {
2470
- x: t.clientX,
2471
- y: t.clientY,
2472
- target: t.target
2473
- });
2474
- }), document.addEventListener("pointerup", (t) => {
2475
- this.eventBus.emitEvent(at, {
2476
- x: t.clientX,
2477
- y: t.clientY,
2478
- target: t.target
2479
- });
2480
- });
2481
- }
2482
- tick(t) {
2483
- let e = (t - this.previousTime) / 1e3;
2484
- e > 0.016 && (e = 1 / 60), this.previousTime = t, this.eventBus.reset(), this.subscribeToEvents(), this.read(), this.update(t, e), this.render(), requestAnimationFrame(this.tick.bind(this));
2485
- }
2486
- subscribeToEvents() {
2487
- this.eventBus.subscribeToEvent(Y, this.onNodeAdded.bind(this)), this.eventBus.subscribeToEvent(
2488
- Q,
2489
- this.onNodeRemoved.bind(this)
2490
- ), this.eventBus.subscribeToEvent(
2491
- Nt,
2492
- this.onDataChanged.bind(this)
2493
- ), this.registry.getPlugins().forEach((t) => {
2494
- t.subscribeToEvents(this.eventBus);
2495
- });
2496
- }
2497
- onNodeAdded({ node: t }) {
2498
- this.registry.queueNodeToBeCreated(t);
2499
- }
2500
- onNodeRemoved({ node: t }) {
2501
- this.registry.queueNodeToBeRemoved(t);
2502
- }
2503
- onDataChanged(t) {
2504
- this.registry.notifyPluginAboutDataChange(t);
2505
- }
2506
- read() {
2507
- this.registry.getViews().forEach((t) => {
2508
- t.read();
2509
- });
2510
- }
2511
- update(t, e) {
2512
- this.registry.update(), this.registry.getPlugins().slice().reverse().forEach((i) => {
2513
- i.init();
2514
- }), this.registry.getRenderablePlugins().forEach((i) => {
2515
- i.update(t, e);
2516
- }), this.registry.getViews().forEach((i) => {
2517
- i.update(t, e);
2518
- }), this.registry.getViews().forEach((i) => {
2519
- i._updatePreviousRect();
2520
- });
2521
- }
2522
- render() {
2523
- this.registry.getRenderablePlugins().forEach((t) => {
2524
- t.render();
2525
- }), this.registry.getViews().forEach((t) => {
2526
- t.render();
2527
- });
2528
- }
2529
- }
2530
- function Be() {
2531
- return mt.create();
2532
- }
2533
- class Mt {
2534
- constructor(t) {
2535
- a(this, "view"), a(this, "previousX"), a(this, "previousY"), a(this, "x"), a(this, "y"), a(this, "pointerX"), a(this, "pointerY"), a(this, "isDragging"), a(this, "target"), a(this, "directions", []), a(this, "width"), a(this, "height"), a(this, "distance"), a(this, "stopped"), this.props = t, this.previousX = t.previousX, this.previousY = t.previousY, this.x = t.x, this.y = t.y, this.pointerX = t.pointerX, this.pointerY = t.pointerY, this.width = t.width, this.height = t.height, this.distance = t.distance, this.view = t.view, this.isDragging = t.isDragging, this.stopped = t.stopped, this.target = t.target, this.directions = t.directions;
2536
- }
2537
- }
2538
- class Ft extends ot {
2539
- constructor() {
2540
- super(...arguments), a(this, "_pointerX", 0), a(this, "_pointerY", 0), a(this, "_initialPointer", new u(0, 0)), a(this, "_initialPointerPerView", /* @__PURE__ */ new Map()), a(this, "_pointerDownPerView", /* @__PURE__ */ new Map()), a(this, "_viewPointerPositionLog", /* @__PURE__ */ new Map()), a(this, "_stopTimer", 0);
2541
- }
2542
- setup() {
2543
- document.addEventListener("selectstart", this.onSelect.bind(this));
2544
- }
2545
- onSelect(t) {
2546
- this._isDragging && t.preventDefault();
2547
- }
2548
- get _isDragging() {
2549
- return Array.from(this._pointerDownPerView.values()).some(
2550
- (t) => !!t
2551
- );
2552
- }
2553
- subscribeToEvents(t) {
2554
- t.subscribeToEvent(rt, ({ x: e, y: i }) => {
2555
- this._initialPointer = new u(e, i), this.getViews().forEach((s) => {
2556
- this._pointerDownPerView.set(s.id, s.intersects(e, i));
2557
- const n = s.isLayoutTransitionEnabled ? s.position.initialX : s.position.x, o = s.isLayoutTransitionEnabled ? s.position.initialY : s.position.y, l = new u(e - n, i - o);
2558
- this._pointerX = e, this._pointerY = i, this._initialPointerPerView.set(s.id, l);
2559
- });
2560
- }), t.subscribeToEvent(at, () => {
2561
- this.getViews().forEach((e) => {
2562
- this._pointerDownPerView.get(e.id) && this._initialPointerPerView.get(e.id) && (this._pointerDownPerView.set(e.id, false), this._emitEvent(e, []));
2563
- });
2564
- }), t.subscribeToEvent(nt, ({ x: e, y: i }) => {
2565
- this._pointerX = e, this._pointerY = i, this.getViews().forEach((s) => {
2566
- if (this._pointerDownPerView.get(s.id) && this._initialPointerPerView.get(s.id)) {
2567
- this._viewPointerPositionLog.has(s.id) || this._viewPointerPositionLog.set(s.id, []);
2568
- const n = new u(e, i), o = this._viewPointerPositionLog.get(s.id);
2569
- o && o.push(new u(e, i));
2570
- const l = o && o.length >= 2 ? o[o.length - 2] : n.clone(), h = this._calculateDirections(
2571
- l,
2572
- n
2573
- );
2574
- this._emitEvent(s, h), clearTimeout(this._stopTimer), this._stopTimer = setTimeout(() => {
2575
- this._emitEvent(s, h, true);
2576
- }, 120);
2577
- }
2578
- });
2579
- });
2580
- }
2581
- _emitEvent(t, e, i = false) {
2582
- const s = this._viewPointerPositionLog.get(t.id), n = s && s.length >= 2 ? s[s.length - 2] : null, o = this._pointerX - this._initialPointerPerView.get(t.id).x, l = this._pointerY - this._initialPointerPerView.get(t.id).y, h = this._pointerX, g = this._pointerY, d = n ? n.x - this._initialPointerPerView.get(t.id).x : o, p = n ? n.y - this._initialPointerPerView.get(t.id).y : l, w = this._pointerY - this._initialPointer.y, v = this._pointerX - this._initialPointer.x, y = ee(this._initialPointer, {
2583
- x: this._pointerX,
2584
- y: this._pointerY
2585
- }), V = this._pointerDownPerView.get(t.id) === true;
2586
- V || this._viewPointerPositionLog.clear();
2587
- const P = {
2588
- view: t,
2589
- target: t.element,
2590
- previousX: d,
2591
- previousY: p,
2592
- x: o,
2593
- y: l,
2594
- pointerX: h,
2595
- pointerY: g,
2596
- distance: y,
2597
- width: v,
2598
- height: w,
2599
- isDragging: V,
2600
- directions: e,
2601
- stopped: i
2602
- };
2603
- this.emit(Mt, P);
2604
- }
2605
- _calculateDirections(t, e) {
2606
- const i = {
2607
- up: u.sub(new u(t.x, t.y - 1), t),
2608
- down: u.sub(new u(t.x, t.y + 1), t),
2609
- left: u.sub(new u(t.x - 1, t.y), t),
2610
- right: u.sub(new u(t.x + 1, t.y), t)
2611
- }, s = u.sub(e, t).unitVector;
2612
- return [
2613
- { direction: "up", projection: s.dot(i.up) },
2614
- {
2615
- direction: "down",
2616
- projection: s.dot(i.down)
2617
- },
2618
- {
2619
- direction: "left",
2620
- projection: s.dot(i.left)
2621
- },
2622
- {
2623
- direction: "right",
2624
- projection: s.dot(i.right)
2625
- }
2626
- ].filter(
2627
- (n) => n.projection > 0
2628
- ).map(
2629
- (n) => n.direction
2630
- );
2631
- }
2632
- }
2633
- a(Ft, "pluginName", "DragEventPlugin");
2634
- class Me {
2635
- constructor(t) {
2636
- a(this, "view"), a(this, "direction"), this.props = t, this.view = t.view, this.direction = t.direction;
2637
- }
2638
- }
2639
- class Fe extends ot {
2640
- constructor() {
2641
- super(...arguments), a(this, "_viewIsPointerDownMap", /* @__PURE__ */ new Map()), a(this, "_viewPointerPositionLog", /* @__PURE__ */ new Map()), a(this, "_targetPerView", /* @__PURE__ */ new Map());
2642
- }
2643
- subscribeToEvents(t) {
2644
- t.subscribeToEvent(rt, ({ x: e, y: i, target: s }) => {
2645
- this.getViews().forEach((n) => {
2646
- this._targetPerView.set(n.id, s), n.intersects(e, i) && this._viewIsPointerDownMap.set(n.id, true);
2647
- });
2648
- }), t.subscribeToEvent(nt, ({ x: e, y: i }) => {
2649
- this.getViews().forEach((s) => {
2650
- this._viewIsPointerDownMap.get(s.id) && (this._viewPointerPositionLog.has(s.id) || this._viewPointerPositionLog.set(s.id, []), this._viewPointerPositionLog.get(s.id).push(new u(e, i)));
2651
- });
2652
- }), t.subscribeToEvent(at, ({ x: e, y: i }) => {
2653
- this.getViews().forEach((n) => {
2654
- if (!this._viewIsPointerDownMap.get(n.id) || !this._viewPointerPositionLog.has(n.id))
2655
- return;
2656
- const o = new u(e, i), l = this._viewPointerPositionLog.get(n.id), h = l[l.length - 2] || o.clone(), g = this._targetPerView.get(n.id), d = s(h, o);
2657
- g && n.hasElement(g) && d.hasSwiped && this.emit(Me, {
2658
- view: n,
2659
- direction: d.direction
2660
- }), this._viewPointerPositionLog.set(n.id, []), this._viewIsPointerDownMap.set(n.id, false);
2661
- });
2662
- function s(n, o) {
2663
- const l = {
2664
- up: u.sub(new u(n.x, n.y - 1), n),
2665
- down: u.sub(new u(n.x, n.y + 1), n),
2666
- left: u.sub(new u(n.x - 1, n.y), n),
2667
- right: u.sub(new u(n.x + 1, n.y), n)
2668
- }, h = u.sub(o, n).unitVector, g = [
2669
- "up",
2670
- "down",
2671
- "left",
2672
- "right"
2673
- ], d = [
2674
- h.dot(l.up),
2675
- h.dot(l.down),
2676
- h.dot(l.left),
2677
- h.dot(l.right)
2678
- ], p = Math.max(...d), w = d.indexOf(p), v = g[w], y = u.sub(o, n).magnitude;
2679
- return {
2680
- hasSwiped: h.dot(l[v]) * y > 30,
2681
- direction: v
2682
- };
2683
- }
2684
- });
2685
- }
2686
- }
2687
- a(Fe, "pluginName", "SwipeEventPlugin");
2688
- class ke {
2689
- constructor(t) {
2690
- a(this, "view"), this.props = t, this.view = t.view;
2691
- }
2692
- }
2693
- class $e extends ot {
2694
- subscribeToEvents(t) {
2695
- t.subscribeToEvent(Lt, ({ x: e, y: i, target: s }) => {
2696
- this.getViews().forEach((n) => {
2697
- const o = s, l = n.element === o || n.element.contains(o);
2698
- n.intersects(e, i) && l && this.emit(ke, {
2699
- view: n
2700
- });
2701
- });
2702
- });
2703
- }
2704
- }
2705
- a($e, "pluginName", "ClickEventPlugin");
2706
- class st {
2707
- constructor(t) {
2708
- E(this, "data");
2709
- this.data = t.data;
2710
- }
2711
- }
2712
- class kt {
2713
- constructor(t) {
2714
- E(this, "data");
2715
- this.data = t.data;
2716
- }
2717
- }
2718
- function J(r) {
2719
- return {
2720
- map: new Map(r),
2721
- array: Array.from(r).map(([e, i]) => ({ slotId: e, itemId: i })),
2722
- object: Array.from(r).reduce(
2723
- (e, [i, s]) => (e[i] = s, e),
2724
- {}
2725
- )
2726
- };
2727
- }
2728
- function ze(r) {
2729
- if (r.map)
2730
- return {
2731
- map: new Map(r.map),
2732
- array: Array.from(r.map).map(([e, i]) => ({
2733
- slotId: e,
2734
- itemId: i
2735
- })),
2736
- object: Array.from(r.map).reduce(
2737
- (e, [i, s]) => (e[i] = s, e),
2738
- {}
2739
- )
2740
- };
2741
- if (r.object) {
2742
- const t = { ...r.object };
2743
- return {
2744
- map: new Map(Object.entries(t)),
2745
- array: Object.entries(t).map(([e, i]) => ({
2746
- slotId: e,
2747
- itemId: i
2748
- })),
2749
- object: t
2750
- };
2751
- } else {
2752
- const t = [...r.array];
2753
- return {
2754
- map: new Map(t.map(({ slotId: e, itemId: i }) => [e, i])),
2755
- array: t,
2756
- object: t.reduce((e, { slotId: i, itemId: s }) => (e[i] = s, e), {})
2757
- };
2758
- }
2759
- }
2760
- const N = (r) => {
2761
- const t = r.useEventPlugin(Ft);
2762
- t.on(Mt, L);
2763
- let e, i, s, n, o = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(), h, g, d, p, w = true, v, y, V, P;
2764
- r.api({
2765
- setEnabled(c) {
2766
- w = c;
2767
- },
2768
- setData(c) {
2769
- const f = ze(c);
2770
- o = new Map(f.map), l = new Map(o);
2771
- }
2772
- });
2773
- function S() {
2774
- return {
2775
- animation: e.data.configAnimation,
2776
- continuousMode: typeof e.data.configContinuousMode < "u",
2777
- manualSwap: typeof e.data.configManualSwap < "u"
2778
- };
2779
- }
2780
- function B() {
2781
- const c = S().animation;
2782
- return c === "dynamic" ? {
2783
- animator: "dynamic",
2784
- config: {}
2785
- } : c === "spring" ? {
2786
- animator: "spring",
2787
- config: {
2788
- damping: 0.7,
2789
- stiffness: 0.62
2790
- }
2791
- } : c === "none" ? {
2792
- animator: "instant",
2793
- config: {}
2794
- } : {
2795
- animator: "instant",
2796
- config: {}
2797
- };
2798
- }
2799
- r.setup(() => {
2800
- e = r.getView("root"), i = r.getViews("slot"), s = r.getViews("item"), y = S().continuousMode, V = S().manualSwap, i.forEach((c) => {
2801
- M(c);
2802
- }), D(), l = new Map(o), requestAnimationFrame(() => {
2803
- r.emit(kt, { data: J(o) });
2804
- });
2805
- });
2806
- function M(c) {
2807
- const f = c.getChild("item");
2808
- f && G(f), o.set(
2809
- c.element.dataset.swapySlot,
2810
- f ? f.element.dataset.swapyItem : null
2811
- );
2812
- }
2813
- function G(c) {
2814
- const f = B();
2815
- c.styles.position = "relative", c.styles.userSelect = "none", c.styles.webkitUserSelect = "none", c.position.setAnimator(f.animator, f.config), c.scale.setAnimator(f.animator, f.config), c.layoutTransition(true), requestAnimationFrame(() => {
2816
- const m = c.getChild("handle");
2817
- m ? (t.addView(m), m.styles.touchAction = "none") : (t.addView(c), c.styles.touchAction = "none");
2818
- });
2819
- }
2820
- r.onViewAdded((c) => {
2821
- if (r.initialized)
2822
- if (c.name === "item") {
2823
- s = r.getViews("item");
2824
- const f = c.getParent("slot");
2825
- M(f), D(), l = new Map(o), r.emit(st, { data: J(o) });
2826
- } else c.name === "slot" && (i = r.getViews("slot"));
2827
- });
2828
- function D() {
2829
- const c = B();
2830
- r.getViews("root-child").forEach((m) => {
2831
- m.position.setAnimator(c.animator, c.config), m.scale.setAnimator(c.animator, c.config), m.layoutTransition(true);
2832
- });
2833
- }
2834
- function A() {
2835
- if (!v) return;
2836
- if (!h || !g) {
2837
- const T = n.getScroll();
2838
- h = v.pointerX - n.position.x + T.x, g = v.pointerY - n.position.y + T.y;
2839
- }
2840
- (!d || !p) && (d = n.size.width, p = n.size.height);
2841
- const c = n.size.width / d, f = n.size.height / p, m = h * (c - 1), R = g * (f - 1);
2842
- n.position.set(
2843
- {
2844
- x: v.x - m,
2845
- y: v.y - R
2846
- },
2847
- n.scale.x !== 1 || n.scale.y !== 1
2848
- );
2849
- }
2850
- function L(c) {
2851
- if (!w) return;
2852
- n = c.view.name === "handle" ? c.view.getParent("item") : c.view, P || (P = n.getParent("slot")), c.isDragging ? (v = c, A(), i.forEach((m) => {
2853
- var $;
2854
- if (!m.intersects(c.pointerX, c.pointerY)) {
2855
- m !== P && m.element.removeAttribute("data-swapy-highlighted");
2856
- return;
2857
- }
2858
- if (typeof m.element.dataset.swapyHighlighted > "u" && (m.element.dataset.swapyHighlighted = ""), !P || !c.stopped && !y)
2859
- return;
2860
- const R = m.element.dataset.swapySlot, T = ($ = m.getChild("item")) == null ? void 0 : $.element.dataset.swapyItem, F = P.element.dataset.swapySlot, k = n.element.dataset.swapyItem;
2861
- if (!R || !F || !k)
2862
- return;
2863
- const x = new Map(o);
2864
- x.set(R, k), T ? x.set(F, T) : x.set(F, null), Ct(x, l) || (V || (o = x, l = new Map(o)), P = null, r.emit(st, { data: J(x) }));
2865
- }), s.forEach((m) => {
2866
- m.styles.zIndex = m === n ? "2" : "";
2867
- })) : (i.forEach((m) => {
2868
- m.element.removeAttribute("data-swapy-highlighted");
2869
- }), n.position.reset(), P = null, h = null, g = null, d = null, p = null, v = null), requestAnimationFrame(() => {
2870
- A();
2871
- });
2872
- }
2873
- };
2874
- N.pluginName = "Swapy";
2875
- N.scope = "root";
2876
- let I;
2877
- function Oe() {
2878
- return I ? (I.updatePlugin(N), I) : (I = Be(), I.addPlugin(N), I.run(), I);
2879
- }
2880
- const De = {
2881
- animation: "dynamic",
2882
- continuousMode: true,
2883
- manualSwap: false
2884
- };
2885
- function We(r) {
2886
- let t = true;
2887
- const e = r.querySelectorAll("[data-swapy-slot]");
2888
- return e.length === 0 && (console.error("There are no slots defined in your root element:", r), t = false), e.forEach((i) => {
2889
- const s = i, n = s.dataset.swapySlot;
2890
- (!n || n.length === 0) && (console.error(i, "does not contain a slotId using data-swapy-slot"), t = false);
2891
- const o = s.children;
2892
- o.length > 1 && (console.error(
2893
- "slot:",
2894
- `"${n}"`,
2895
- "cannot contain more than one element"
2896
- ), t = false);
2897
- const l = o[0];
2898
- l && (!l.dataset.swapyItem || l.dataset.swapyItem.length === 0) && (console.error(
2899
- "slot:",
2900
- `"${n}"`,
2901
- "does not contain an element with item id using data-swapy-item"
2902
- ), t = false);
2903
- }), t;
2904
- }
2905
- function qe(r, t = {}) {
2906
- const e = qt();
2907
- return r.dataset.velPluginKey = e, r.dataset.velPlugin = "Swapy", r.dataset.velView = "root", r.dataset.velDataConfigAnimation = t.animation, t.continuousMode && (r.dataset.velDataConfigContinuousMode = "true"), t.manualSwap && (r.dataset.velDataConfigManualSwap = "true"), Array.from(
2908
- r.querySelectorAll("[data-swapy-slot]")
2909
- ).forEach((l) => {
2910
- l.dataset.velView = "slot";
2911
- }), Array.from(
2912
- r.querySelectorAll("[data-swapy-item]")
2913
- ).forEach((l) => {
2914
- l.dataset.velView = "item", l.dataset.velLayoutId = l.dataset.swapyItem;
2915
- const h = l.querySelector("[data-swapy-handle]");
2916
- h && (h.dataset.velView = "handle");
2917
- }), Array.from(
2918
- r.querySelectorAll("[data-swapy-text]")
2919
- ).forEach((l) => {
2920
- l.dataset.velLayoutPosition = "";
2921
- }), Array.from(
2922
- r.querySelectorAll("[data-swapy-exclude]")
2923
- ).forEach((l) => {
2924
- l.dataset.velIgnore = "";
2925
- }), e;
2926
- }
2927
- function Ue(r) {
2928
- const t = Array.from(
2929
- r.querySelectorAll("[data-swapy-slot]:not([data-vel-view])")
2930
- );
2931
- t.forEach((i) => {
2932
- i.dataset.velView = "slot";
2933
- });
2934
- const e = Array.from(
2935
- r.querySelectorAll("[data-swapy-item]:not([data-vel-view]")
2936
- );
2937
- return e.forEach((i) => {
2938
- i.dataset.velView = "item", i.dataset.velLayoutId = i.dataset.swapyItem;
2939
- const s = i.querySelector("[data-swapy-handle]");
2940
- s && (s.dataset.velView = "handle"), Array.from(
2941
- i.querySelectorAll("[data-swapy-text]")
2942
- ).forEach((l) => {
2943
- l.dataset.velLayoutPosition = "";
2944
- }), Array.from(
2945
- i.querySelectorAll("[data-swapy-exclude]")
2946
- ).forEach((l) => {
2947
- l.dataset.velIgnore = "";
2948
- });
2949
- }), e.length > 0 || t.length > 0;
2950
- }
2951
- function je(r, t = {}) {
2952
- if (!r)
2953
- throw new Error(
2954
- "Cannot create a Swapy instance because the element you provided does not exist on the page!"
2955
- );
2956
- const e = { ...De, ...t }, i = r;
2957
- if (!We(i))
2958
- throw new Error(
2959
- "Cannot create a Swapy instance because your HTML structure is invalid. Fix all above errors and then try!"
2960
- );
2961
- const s = qe(i, e), n = new He(i, s, e);
2962
- return {
2963
- onSwap(o) {
2964
- n.setSwapCallback(o);
2965
- },
2966
- enable(o) {
2967
- n.setEnabled(o);
2968
- },
2969
- destroy() {
2970
- n.destroy();
2971
- },
2972
- setData(o) {
2973
- n.setData(o);
2974
- }
2975
- };
2976
- }
2977
- class He {
2978
- constructor(t, e, i) {
2979
- E(this, "_rootEl");
2980
- E(this, "_veloxiApp");
2981
- E(this, "_slotElMap");
2982
- E(this, "_itemElMap");
2983
- E(this, "_swapCallback");
2984
- E(this, "_previousMap");
2985
- E(this, "_pluginKey");
2986
- this._rootEl = t, this._veloxiApp = Oe(), this._slotElMap = this._createSlotElMap(), this._itemElMap = this._createItemElMap(), this._pluginKey = e, this._veloxiApp.onPluginEvent(
2987
- N,
2988
- kt,
2989
- ({ data: s }) => {
2990
- this._previousMap = s.map;
2991
- },
2992
- e
2993
- ), this._veloxiApp.onPluginEvent(
2994
- N,
2995
- st,
2996
- (s) => {
2997
- var n;
2998
- this._previousMap && Ct(this._previousMap, s.data.map) || (i.manualSwap || this._applyOrder(s.data.map), this._previousMap = s.data.map, (n = this._swapCallback) == null || n.call(this, s));
2999
- },
3000
- e
3001
- ), this.setupMutationObserver();
3002
- }
3003
- setupMutationObserver() {
3004
- new MutationObserver((e) => {
3005
- e.some((i) => i.type === "childList") && Ue(this._rootEl) && (this._slotElMap = this._createSlotElMap(), this._itemElMap = this._createItemElMap());
3006
- }).observe(this._rootEl, {
3007
- childList: true,
3008
- subtree: true
3009
- });
3010
- }
3011
- setData(t) {
3012
- try {
3013
- this._veloxiApp.getPlugin(
3014
- "Swapy",
3015
- this._pluginKey
3016
- ).setData(t);
3017
- } catch {
3018
- }
3019
- }
3020
- destroy() {
3021
- this._veloxiApp.destroy("Swapy");
3022
- }
3023
- setEnabled(t) {
3024
- try {
3025
- this._veloxiApp.getPlugin(
3026
- "Swapy",
3027
- this._pluginKey
3028
- ).setEnabled(t);
3029
- } catch {
3030
- }
3031
- }
3032
- setSwapCallback(t) {
3033
- this._swapCallback = t;
3034
- }
3035
- _applyOrder(t) {
3036
- Array.from(t.keys()).forEach((e) => {
3037
- var o;
3038
- if (t.get(e) === ((o = this._previousMap) == null ? void 0 : o.get(e)))
3039
- return;
3040
- const i = t.get(e);
3041
- if (!i) return;
3042
- const s = this._slotElMap.get(e), n = this._itemElMap.get(i);
3043
- !s || !n || (s.innerHTML = "", s.appendChild(n));
3044
- });
3045
- }
3046
- _createSlotElMap() {
3047
- return Array.from(
3048
- this._rootEl.querySelectorAll("[data-swapy-slot]")
3049
- ).reduce((t, e) => (t.set(e.dataset.swapySlot, e), t), /* @__PURE__ */ new Map());
3050
- }
3051
- _createItemElMap() {
3052
- return Array.from(
3053
- this._rootEl.querySelectorAll("[data-swapy-item]")
3054
- ).reduce((t, e) => (t.set(e.dataset.swapyItem, e), t), /* @__PURE__ */ new Map());
3055
- }
3056
- }
3057
- export {
3058
- je as j
3059
- };