From 00b316d2e30b4e5ed6c2e30cf440238cf42d2bcd Mon Sep 17 00:00:00 2001 From: Taha Shashtari Date: Mon, 15 Jul 2024 18:38:48 +0300 Subject: [PATCH] v0.12.0 --- dist/veloxi.d.ts | 6 +- dist/veloxi.js | 317 +++++++++++++++++++++++---------------------- dist/veloxi.min.js | 4 +- package.json | 2 +- 4 files changed, 169 insertions(+), 160 deletions(-) diff --git a/dist/veloxi.d.ts b/dist/veloxi.d.ts index 1e452ea..3a15efd 100644 --- a/dist/veloxi.d.ts +++ b/dist/veloxi.d.ts @@ -60,11 +60,12 @@ declare class App { static create(): App; constructor(); addPlugin(pluginFactory: PluginFactory, config?: TConfig): void; + updatePlugin(pluginFactory: PluginFactory, config?: TConfig): void; reset(pluginName?: string, callback?: () => void): void; destroy(pluginName?: string, callback?: () => void): void; getPlugin(pluginFactory: PluginFactory | string, pluginKey?: string): TPluginApi; getPlugins(pluginFactory: PluginFactory | string, pluginKey?: string): TPluginApi[]; - onPluginEvent(pluginFactory: PluginFactory, EventCtor: new (eventData: TEvent) => TEvent, listener: (eventData: TEvent) => void): void; + onPluginEvent, TEvent>(pluginFactory: TPlugin, EventCtor: new (eventData: TEvent) => TEvent, listener: (eventData: TEvent) => void, pluginKey?: string): void; removePluginEventListener(pluginFactory: PluginFactory, EventCtor: new (eventData: TEvent) => TEvent, listener: (eventData: TEvent) => void): void; run(): void; ready(pluginName: string, callback: ReadyCallback): void; @@ -627,7 +628,8 @@ declare class Registry { getPluginByName(pluginName: string, pluginKey?: string): IPlugin | undefined; getPluginsByName(pluginName: string, pluginKey?: string): IPlugin[]; hasPlugin(pluginFactory: PluginFactory): boolean; - createPlugin(pluginFactory: PluginFactory, eventBus: EventBus, config?: TConfig): IPlugin; + createPlugin(pluginFactory: PluginFactory, eventBus: EventBus, config?: TConfig, forUpdate?: boolean): IPlugin; + updatePlugin(pluginFactory: PluginFactory, eventBus: EventBus, config?: TConfig): IPlugin; getViews(): ReadonlyArray; createView(domEl: HTMLElement, name: string, layoutId?: string): CoreView; assignViewToPlugin(view: View, plugin: IPlugin): void; diff --git a/dist/veloxi.js b/dist/veloxi.js index 61b2c7d..e792405 100644 --- a/dist/veloxi.js +++ b/dist/veloxi.js @@ -68,8 +68,8 @@ class Fe { return; this._eventBus.emitEvent(O, { node: r }); const u = r.querySelectorAll("[data-vel-plugin]"); - u.length && u.forEach((c) => { - this._eventBus.emitEvent(O, { node: c }); + u.length && u.forEach((h) => { + this._eventBus.emitEvent(O, { node: h }); }); }), t.removedNodes.forEach((n) => { if (!(n instanceof HTMLElement) || typeof n.dataset.velProcessing < "u") @@ -81,17 +81,17 @@ class Fe { }); const i = t.attributeName; if (i && /data-vel-data-.+/gi.test(i)) { - const n = t.target, r = n.dataset.velPluginId || "", u = n.dataset.velPlugin || "", c = n.dataset.velView || "", h = n.getAttribute(i); - if (h && h !== t.oldValue) { + const n = t.target, r = n.dataset.velPluginId || "", u = n.dataset.velPlugin || "", h = n.dataset.velView || "", c = n.getAttribute(i); + if (c && c !== t.oldValue) { const d = Be( i.replace("data-vel-data-", "") ); this._eventBus.emitEvent(ve, { pluginId: r, pluginName: u, - viewName: c, + viewName: h, dataName: d, - dataValue: h + dataValue: c }); } } @@ -530,9 +530,9 @@ function Ue(a, e, t, i, s) { return (a - e) / (t - e) * (s - i) + i; } function qe(a, e, t, i) { - const s = e.getScroll(), n = e.position.x - s.x, r = e.position.y - s.y, u = a.x || n, c = a.y || r, h = Math.abs(n - u), d = Math.abs(r - c), _ = Math.sqrt(h * h + d * d); - let g = W(0, _ / t, 1); - return typeof i > "u" ? 1 - g : _ <= i ? 1 : (g = W((_ - i) / t, 0, 1), 1 - g); + const s = e.getScroll(), n = e.position.x - s.x, r = e.position.y - s.y, u = a.x || n, h = a.y || r, c = Math.abs(n - u), d = Math.abs(r - h), g = Math.sqrt(c * c + d * d); + let _ = W(0, g / t, 1); + return typeof i > "u" ? 1 - _ : g <= i ? 1 : (_ = W((g - i) / t, 0, 1), 1 - _); } function m(a) { let e = a.match(/^([\d.]+)([a-zA-Z%]*)$/); @@ -626,14 +626,14 @@ function Xe(a, e) { bottomLeft: s.h } }; - function r(u, c) { + function r(u, h) { if (u.unit === "%") return { h: m(`${u.value}%`), v: m(`${u.value}%`) }; - const h = u.value / c.width * 100, d = u.value / c.height * 100; - return { h: m(`${h}%`), v: m(`${d}%`) }; + const c = u.value / h.width * 100, d = u.value / h.height * 100; + return { h: m(`${c}%`), v: m(`${d}%`) }; } } function _e(a, e) { @@ -754,7 +754,7 @@ function q(a, e) { }; return new Proxy(a, t); } -const N = 0.01, j = { +const I = 0.01, j = { speed: 15 }; class H { @@ -776,7 +776,7 @@ class tt extends H { })), e.callUpdateCallback(), u; } _shouldFinish(e, t, i) { - return l.sub(e, t).magnitude < N && i.magnitude < N; + return l.sub(e, t).magnitude < I && i.magnitude < I; } } class it extends H { @@ -791,15 +791,15 @@ class it extends H { class st extends H { update({ animatorProp: e, current: t, target: i, dt: s }) { return i.map((n, r) => { - const u = t[r], c = n.value === 0 ? u.unit : n.unit, d = (n.value - u.value) * this._config.speed, _ = u.value + d * s; - let g = m(`${_}${c}`); - return this._shouldFinish(n.value, u.value, d) && (g = n, requestAnimationFrame(() => { + const u = t[r], h = n.value === 0 ? u.unit : n.unit, d = (n.value - u.value) * this._config.speed, g = u.value + d * s; + let _ = m(`${g}${h}`); + return this._shouldFinish(n.value, u.value, d) && (_ = n, requestAnimationFrame(() => { e.callCompleteCallback(); - })), e.callUpdateCallback(), g; + })), e.callUpdateCallback(), _; }); } _shouldFinish(e, t, i) { - return Math.abs(e - t) < N && Math.abs(i) < N; + return Math.abs(e - t) < I && Math.abs(i) < I; } } class K { @@ -875,13 +875,13 @@ class at extends Z { } update({ animatorProp: t, current: i, target: s, dt: n }) { return s.map((r, u) => { - const c = i[u], h = r.value === 0 ? c.unit : r.unit, d = -(c.value - r.value) * this._config.stiffness; + const h = i[u], c = r.value === 0 ? h.unit : r.unit, d = -(h.value - r.value) * this._config.stiffness; this._velocity += d, this._velocity *= this._config.damping; - const _ = c.value + this._velocity * n * this._config.speed; - let g = m(`${_}${h}`); - return this._shouldFinish(r.value, c.value) && (g = r, requestAnimationFrame(() => { + const g = h.value + this._velocity * n * this._config.speed; + let _ = m(`${g}${c}`); + return this._shouldFinish(r.value, h.value) && (_ = r, requestAnimationFrame(() => { t.callCompleteCallback(); - })), g; + })), _; }); } _shouldFinish(t, i) { @@ -928,8 +928,8 @@ class lt extends Q { return p(n, 1) ? (requestAnimationFrame(() => { e.callCompleteCallback(); }), i) : t.map((r, u) => { - const c = i[u], h = c.value === 0 ? r.unit : c.unit, d = r.value + this._config.ease(n) * (i[u].value - r.value); - return m(`${d}${h}`); + const h = i[u], c = h.value === 0 ? r.unit : h.unit, d = r.value + this._config.ease(n) * (i[u].value - r.value); + return m(`${d}${c}`); }); } } @@ -957,7 +957,7 @@ class ee { return this.createInstantAnimator(); } } -class I extends ee { +class N extends ee { createInstantAnimator() { return new K(); } @@ -1040,7 +1040,7 @@ class dt { (e = this._updateCallback) == null || e.call(this); } } -class V { +class P { constructor(e, t, i) { o(this, "_animatorProp"); o(this, "_animator"); @@ -1092,7 +1092,7 @@ class V { update(e, t) { } } -class gt extends V { +class gt extends P { constructor() { super(...arguments); o(this, "_invertedBorderRadius"); @@ -1130,17 +1130,17 @@ class gt extends V { set(t, i = !0) { let s; if (typeof t == "string") { - const h = U(t.trim()); + const c = U(t.trim()); s = { - topLeft: h.value.topLeft.valueWithUnit, - topRight: h.value.topRight.valueWithUnit, - bottomRight: h.value.bottomRight.valueWithUnit, - bottomLeft: h.value.bottomLeft.valueWithUnit + topLeft: c.value.topLeft.valueWithUnit, + topRight: c.value.topRight.valueWithUnit, + bottomRight: c.value.bottomRight.valueWithUnit, + bottomLeft: c.value.bottomLeft.valueWithUnit }; } else s = t; - const n = s.topLeft ? m(s.topLeft) : this._currentValue[0], r = s.topRight ? m(s.topRight) : this._currentValue[1], u = s.bottomRight ? m(s.bottomRight) : this._currentValue[2], c = s.bottomLeft ? m(s.bottomLeft) : this._currentValue[3]; - this._setTarget([n, r, u, c], i); + const n = s.topLeft ? m(s.topLeft) : this._currentValue[0], r = s.topRight ? m(s.topRight) : this._currentValue[1], u = s.bottomRight ? m(s.bottomRight) : this._currentValue[2], h = s.bottomLeft ? m(s.bottomLeft) : this._currentValue[3]; + this._setTarget([n, r, u, h], i); } reset(t = !0) { this._setTarget(this._initialValue, t); @@ -1226,7 +1226,7 @@ class gt extends V { return !1; } } -class _t extends V { +class _t extends P { setFromElementPropValue(e) { this._setTarget(e.value, !0); } @@ -1267,7 +1267,7 @@ class _t extends V { return !1; } } -class pt extends V { +class pt extends P { get x() { return this._currentValue.x; } @@ -1314,7 +1314,7 @@ class pt extends V { return !1; } } -class ft extends V { +class ft extends P { constructor() { super(...arguments); o(this, "_animateLayoutUpdateNextFrame", !1); @@ -1344,8 +1344,8 @@ class ft extends V { return this._rect.pageOffset.top; } progressTo(t) { - const i = typeof t.x > "u" ? this.initialX : t.x, s = typeof t.y > "u" ? this.initialY : t.y, n = new l(i, s), r = new l(this.initialX, this.initialY), u = new l(this.x, this.y), c = l.sub(u, r), h = l.sub(n, r); - return 1 - l.sub(h, c).magnitude / h.magnitude; + const i = typeof t.x > "u" ? this.initialX : t.x, s = typeof t.y > "u" ? this.initialY : t.y, n = new l(i, s), r = new l(this.initialX, this.initialY), u = new l(this.x, this.y), h = l.sub(u, r), c = l.sub(n, r); + return 1 - l.sub(c, h).magnitude / c.magnitude; } set(t, i = !0) { const n = { ...{ x: this.x, y: this.y }, ...t }; @@ -1362,12 +1362,12 @@ class ft extends V { } update(t, i) { if ((this._view.isInverseEffectEnabled || this._view.isLayoutTransitionEnabled) && !this._view.isTemporaryView && this._runLayoutTransition(), this._view.isInverseEffectEnabled) { - const h = this._view._parent, d = h ? h.scale.x : 1, _ = h ? h.scale.y : 1; - this._parentScaleInverse = new l(1 / d, 1 / _), this._parentScaleInverse.equals(new l(1, 1)) || (this._hasChanged = !0); + const c = this._view._parent, d = c ? c.scale.x : 1, g = c ? c.scale.y : 1; + this._parentScaleInverse = new l(1 / d, 1 / g), this._parentScaleInverse.equals(new l(1, 1)) || (this._hasChanged = !0); } if (this._targetValue.x === this._currentValue.x && this._targetValue.y === this._currentValue.y) return; - const s = this._view._parent, n = s ? s.scale.x : 1, r = s ? s.scale.y : 1, u = s ? s.scale._previousValue.x : 1, c = s ? s.scale._previousValue.y : 1; + const s = this._view._parent, n = s ? s.scale.x : 1, r = s ? s.scale.y : 1, u = s ? s.scale._previousValue.x : 1, h = s ? s.scale._previousValue.y : 1; this._currentValue = this._animator.update({ animatorProp: this._animatorProp, current: new l( @@ -1377,7 +1377,7 @@ class ft extends V { target: this._targetValue, initial: new l( this._previousValue.x * u, - this._previousValue.y * c + this._previousValue.y * h ), ts: t, dt: i @@ -1387,17 +1387,17 @@ class ft extends V { ); } _runLayoutTransition() { - const t = !(this._targetValue.x === this._currentValue.x && this._targetValue.y === this._currentValue.y), i = !(this._view.scale._targetValue.x === this._view.scale._currentValue.x && this._view.scale._targetValue.y === this._view.scale._currentValue.y), s = t || i, n = this._rect.pageOffset.left - this._previousRect.pageOffset.left, r = this._rect.pageOffset.top - this._previousRect.pageOffset.top, u = this._previousRect.size.width / this._rect.size.width, c = this._previousRect.size.height / this._rect.size.height; - let h = !1; - if (n !== 0 || r !== 0 || !Number.isNaN(u) && u !== 1 || !Number.isNaN(c) && c !== 1 ? h = !0 : h = (() => { + const t = !(this._targetValue.x === this._currentValue.x && this._targetValue.y === this._currentValue.y), i = !(this._view.scale._targetValue.x === this._view.scale._currentValue.x && this._view.scale._targetValue.y === this._view.scale._currentValue.y), s = t || i, n = this._rect.pageOffset.left - this._previousRect.pageOffset.left, r = this._rect.pageOffset.top - this._previousRect.pageOffset.top, u = this._previousRect.size.width / this._rect.size.width, h = this._previousRect.size.height / this._rect.size.height; + let c = !1; + if (n !== 0 || r !== 0 || !Number.isNaN(u) && u !== 1 || !Number.isNaN(h) && h !== 1 ? c = !0 : c = (() => { const d = this._view._parents; - for (let _ = 0; _ < d.length; _++) { - const g = d[_], f = g.previousRect.size.width / g.rect.size.width, v = g.previousRect.size.height / g.rect.size.height; - if (f !== 1 || v !== 1) + for (let g = 0; g < d.length; g++) { + const _ = d[g], w = _.previousRect.size.width / _.rect.size.width, f = _.previousRect.size.height / _.rect.size.height; + if (w !== 1 || f !== 1) return !0; } return !1; - })(), h) { + })(), c) { if (this._currentValue.x !== 0 || this._currentValue.y !== 0 || this._view.scale._currentValue.x !== 1 || this._view.scale._currentValue.y !== 1) { if (!s) { const E = this._rect.pageOffset.left - this._previousRect.pageOffset.left, T = this._rect.pageOffset.top - this._previousRect.pageOffset.top; @@ -1407,21 +1407,21 @@ class ft extends V { ); return; } - const y = this._view._parent, ne = this._rect.pageOffset, re = this._view.getScroll(), x = { + const V = this._view._parent, ne = this._rect.pageOffset, re = this._view.getScroll(), x = { left: this._previousRect.viewportOffset.left + re.x, top: this._previousRect.viewportOffset.top + re.y }, Te = x.left - ne.left, Ae = x.top - ne.top; let ae = 0, oe = 0, ue = 0, le = 0; - if (y) { - const E = y.rect.pageOffset, T = y.getScroll(), A = { - left: y.previousRect.viewportOffset.left + T.x, - top: y.previousRect.viewportOffset.top + T.y + if (V) { + const E = V.rect.pageOffset, T = V.getScroll(), A = { + left: V.previousRect.viewportOffset.left + T.x, + top: V.previousRect.viewportOffset.top + T.y }; ae = A.left - E.left, oe = A.top - E.top; - const he = x.top - A.top, ce = x.left - A.left, Ie = y.scale.y * he; - ue = (he - Ie) / y.scale.y; - const Ne = y.scale.x * ce; - le = (ce - Ne) / y.scale.x; + const he = x.top - A.top, ce = x.left - A.left, Ne = V.scale.y * he; + ue = (he - Ne) / V.scale.y; + const Ie = V.scale.x * ce; + le = (ce - Ie) / V.scale.x; } this._setTarget( new l(Te - ae + le, Ae - oe + ue), @@ -1430,14 +1430,14 @@ class ft extends V { return; } this._animateLayoutUpdateNextFrame = !0; - const d = this._previousRect, _ = this._rect, g = this._view._parent; - let f = 0, v = 0; - g && (f = g.previousRect.viewportOffset.left - g.rect.viewportOffset.left), g && (v = g.previousRect.viewportOffset.top - g.rect.viewportOffset.top); - let w = 1, P = 1; - g && (w = g.previousRect.size.width / g.rect.size.width, P = g.previousRect.size.height / g.rect.size.height); - const M = g ? g.previousRect.viewportOffset.left : 0, Pe = g ? g.previousRect.viewportOffset.top : 0, ie = d.viewportOffset.left - M, se = d.viewportOffset.top - Pe, be = ie / w - ie, Re = se / P - se; - let xe = d.viewportOffset.left - _.viewportOffset.left - f + be; - const Ee = d.viewportOffset.top - _.viewportOffset.top - v + Re; + const d = this._previousRect, g = this._rect, _ = this._view._parent; + let w = 0, f = 0; + _ && (w = _.previousRect.viewportOffset.left - _.rect.viewportOffset.left), _ && (f = _.previousRect.viewportOffset.top - _.rect.viewportOffset.top); + let v = 1, y = 1; + _ && (v = _.previousRect.size.width / _.rect.size.width, y = _.previousRect.size.height / _.rect.size.height); + const M = _ ? _.previousRect.viewportOffset.left : 0, Pe = _ ? _.previousRect.viewportOffset.top : 0, ie = d.viewportOffset.left - M, se = d.viewportOffset.top - Pe, be = ie / v - ie, Re = se / y - se; + let xe = d.viewportOffset.left - g.viewportOffset.left - w + be; + const Ee = d.viewportOffset.top - g.viewportOffset.top - f + Re; this._setTarget(new l(xe, Ee), !1); } else this._animateLayoutUpdateNextFrame && (this._setTarget(this._initialValue, !0), this._animateLayoutUpdateNextFrame = !1); @@ -1465,7 +1465,7 @@ class ft extends V { return !0; } } -class mt extends V { +class mt extends P { constructor() { super(...arguments); o(this, "_unit", "deg"); @@ -1516,7 +1516,7 @@ class mt extends V { return !0; } } -class vt extends V { +class vt extends P { constructor() { super(...arguments); o(this, "_animateLayoutUpdateNextFrame", !1); @@ -1559,15 +1559,15 @@ class vt extends V { let n = !1; if ((!Number.isNaN(i) && i !== 1 || !Number.isNaN(s) && s !== 1) && (n = !0), n) { if (this._currentValue.x !== 1 || this._currentValue.y !== 1) { - const d = this._view.previousRect.size.width / this._view.rect.size.width, _ = this._view.previousRect.size.height / this._view.rect.size.height; + const d = this._view.previousRect.size.width / this._view.rect.size.width, g = this._view.previousRect.size.height / this._view.rect.size.height; this._setTarget( - new l(this._currentValue.x * d, this._currentValue.y * _), + new l(this._currentValue.x * d, this._currentValue.y * g), !1 ), t && (this._animateLayoutUpdateNextFrame = !0); return; } - const r = this._previousRect.size.width / this._rect.size.width, u = this._previousRect.size.height / this._rect.size.height, c = r, h = u; - this._view.viewProps.borderRadius.applyScaleInverse(), this._setTarget(new l(c, h), !1), this._animateLayoutUpdateNextFrame = !0; + const r = this._previousRect.size.width / this._rect.size.width, u = this._previousRect.size.height / this._rect.size.height, h = r, c = u; + this._view.viewProps.borderRadius.applyScaleInverse(), this._setTarget(new l(h, c), !1), this._animateLayoutUpdateNextFrame = !0; } else this._animateLayoutUpdateNextFrame && (this._setTarget(this._initialValue, !0), this._animateLayoutUpdateNextFrame = !1); } @@ -1591,7 +1591,7 @@ class vt extends V { return !0; } } -class wt extends V { +class wt extends P { get width() { return this._view.rect.size.width; } @@ -1679,17 +1679,17 @@ class yt { o(this, "_props", /* @__PURE__ */ new Map()); this._props.set( "position", - new ft(new I(), new l(0, 0), e) + new ft(new N(), new l(0, 0), e) ), this._props.set( "scale", - new vt(new I(), new l(1, 1), e) + new vt(new N(), new l(1, 1), e) ), this._props.set( "rotation", new mt(new pe(), 0, e) ), this._props.set( "size", new wt( - new I(), + new N(), new l(e.rect.size.width, e.rect.size.height), e ) @@ -1715,7 +1715,7 @@ class yt { ), this._props.set( "origin", new pt( - new I(), + new N(), e.elementReader.origin.value, e ) @@ -1960,7 +1960,7 @@ class Vt { let e = ""; const t = this._viewProps.allProps(), i = t.filter((n) => n.isTransform()), s = t.filter((n) => !n.isTransform()); if (i.some((n) => n.hasChanged())) { - const n = i.reduce((r, u, c) => (r += u.projectStyles(), c === i.length - 1 && (r += ";"), r), "transform: "); + const n = i.reduce((r, u, h) => (r += u.projectStyles(), h === i.length - 1 && (r += ";"), r), "transform: "); e += n; } s.forEach((n) => { @@ -2077,17 +2077,17 @@ class Pt { (s) => !this._isScopedElement(s) ); this._viewsToBeCreated = [], e.forEach((s) => { - const n = this._getPluginNameForElement(s), r = this._pluginNameToPluginFactoryMap.get(n), u = this._pluginNameToPluginConfigMap.get(n), c = s.dataset.velPluginKey, h = $( + const n = this._getPluginNameForElement(s), r = this._pluginNameToPluginFactoryMap.get(n), u = this._pluginNameToPluginConfigMap.get(n), h = s.dataset.velPluginKey, c = $( r, this, this._eventBus, this._appEventBus, u, - c + h ); - this._plugins.push(h); - const d = s.dataset.velView, _ = this._createNewView(s, d, h); - _.isInverseEffectEnabled && _.setAnimatorsFromParent(), h.notifyAboutViewAdded(_); + this._plugins.push(c); + const d = s.dataset.velView, g = this._createNewView(s, d, c); + g.isInverseEffectEnabled && g.setAnimatorsFromParent(), c.notifyAboutViewAdded(g); }); const i = t.filter((s) => !!this._getPluginIdForElement(s)); i.length !== 0 && i.forEach((s) => { @@ -2097,9 +2097,9 @@ class Pt { const u = this._getPluginById(n); if (!u) return; - const c = this._getLayoutIdForElement(s, u); - let h; - c && this._layoutIdToViewMap.has(c) ? (h = this._layoutIdToViewMap.get(c), h.setElement(s), h.setPluginId(u.id), this._createChildrenForView(h, u)) : h = this._createNewView(s, r, u), h.isInverseEffectEnabled && h.setAnimatorsFromParent(), u.notifyAboutViewAdded(h); + const h = this._getLayoutIdForElement(s, u); + let c; + h && this._layoutIdToViewMap.has(h) ? (c = this._layoutIdToViewMap.get(h), c.setElement(s), c.setPluginId(u.id), this._createChildrenForView(c, u)) : c = this._createNewView(s, r, u), c.isInverseEffectEnabled && c.setAnimatorsFromParent(), u.notifyAboutViewAdded(c); }); } _getLayoutIdForElement(e, t) { @@ -2128,8 +2128,8 @@ class Pt { return; } Array.from(i).forEach((s) => { - const n = s, r = n.dataset.velView ? n.dataset.velView : `${e.name}-child`, u = this._getLayoutIdForElement(n, t), c = this.createView(n, r, u); - u && !this._layoutIdToViewMap.has(u) && this._layoutIdToViewMap.set(u, c), t.addView(c), t.notifyAboutViewAdded(c); + const n = s, r = n.dataset.velView ? n.dataset.velView : `${e.name}-child`, u = this._getLayoutIdForElement(n, t), h = this.createView(n, r, u); + u && !this._layoutIdToViewMap.has(u) && this._layoutIdToViewMap.set(u, h), t.addView(h), t.notifyAboutViewAdded(h); }); } } @@ -2221,7 +2221,7 @@ class Pt { r.forEach((u) => { u.layoutId && this._layoutIdToViewMap.delete(u.layoutId), u.destroy(); }), this._views = this._views.filter( - (u) => !r.find((c) => c.id === u.id) + (u) => !r.find((h) => h.id === u.id) ), this._viewsPerPlugin.delete(e.id), this._plugins = this._plugins.filter((u) => u.id !== e.id), n || requestAnimationFrame(() => { this.createPlugin( i, @@ -2266,24 +2266,22 @@ class Pt { hasPlugin(e) { return e.pluginName ? !!this.getPluginByName(e.pluginName) : !1; } - createPlugin(e, t, i = {}) { + createPlugin(e, t, i = {}, s = !1) { if (!e.pluginName) throw Error( `Plugin ${e.name} must contain a pluginName field` ); - let s = []; + let n = []; if (e.scope) { - const u = document.querySelectorAll( - `[data-vel-plugin=${e.pluginName}][data-vel-view=${e.scope}]` - ); + const h = s ? `[data-vel-plugin=${e.pluginName}][data-vel-view=${e.scope}]:not([data-vel-plugin-id])` : `[data-vel-plugin=${e.pluginName}][data-vel-view=${e.scope}]`, c = document.querySelectorAll(h); this._pluginNameToPluginFactoryMap.has(e.pluginName) || this._pluginNameToPluginFactoryMap.set( e.pluginName, e - ), this._pluginNameToPluginConfigMap.has(e.pluginName) || this._pluginNameToPluginConfigMap.set(e.pluginName, i), u ? s = Array.from(u) : s = [document.documentElement]; + ), this._pluginNameToPluginConfigMap.has(e.pluginName) || this._pluginNameToPluginConfigMap.set(e.pluginName, i), c ? n = Array.from(c) : n = [document.documentElement]; } else - s = [document.documentElement]; - const n = s.map((u) => { - const c = u.dataset.velPluginKey, h = $( + n = [document.documentElement]; + const r = n.map((h) => { + const c = h.dataset.velPluginKey, d = $( e, this, t, @@ -2291,30 +2289,30 @@ class Pt { i, c ); - this._plugins.push(h); - let d = []; - u !== document.documentElement && d.push(u); - const _ = u.querySelectorAll( - `[data-vel-plugin=${h.pluginName}]` + this._plugins.push(d); + let g = []; + h !== document.documentElement && g.push(h); + const _ = h.querySelectorAll( + `[data-vel-plugin=${d.pluginName}]` ); - d = [...d, ..._]; - const g = d.filter((f) => { + g = [...g, ..._]; + const w = g.filter((f) => { if (!f.parentElement) return !0; - const w = this._getPluginNameForElement(f.parentElement); - return !(w && w.length > 0); + const y = this._getPluginNameForElement(f.parentElement); + return !(y && y.length > 0); }); - return g.length && g.forEach((f) => { + return w.length && w.forEach((f) => { const v = f.dataset.velView; if (!v) return; - const w = this._createNewView(f, v, h); - h.notifyAboutViewAdded(w); - }), h; + const y = this._createNewView(f, v, d); + d.notifyAboutViewAdded(y); + }), d; }); - if (n && n.length > 0) - return n[0]; - const r = $( + if (r && r.length > 0) + return r[0]; + const u = $( e, this, t, @@ -2322,9 +2320,12 @@ class Pt { i ); return e.scope || console.log( - `%c WARNING: The plugin "${r.pluginName}" is created but there are no elements using it on the page`, + `%c WARNING: The plugin "${u.pluginName}" is created but there are no elements using it on the page`, "background: #885500" - ), r; + ), u; + } + updatePlugin(e, t, i = {}) { + return this.createPlugin(e, t, i, !0); } getViews() { return this._views; @@ -2374,6 +2375,9 @@ class te { addPlugin(e, t = {}) { this._registry.hasPlugin(e) || this._registry.createPlugin(e, this._eventBus, t); } + updatePlugin(e, t = {}) { + this._registry.hasPlugin(e) && this._registry.updatePlugin(e, this._eventBus, t); + } reset(e, t) { this._registry.reset(e, t); } @@ -2398,9 +2402,12 @@ class te { ); return s.map((n) => n.api); } - onPluginEvent(e, t, i) { - const s = this._registry.getPluginByName(e.pluginName); - s && s.on(t, i); + onPluginEvent(e, t, i, s) { + const n = this._registry.getPluginByName( + e.pluginName, + s + ); + n && n.on(t, i); } removePluginEventListener(e, t, i) { const s = this._registry.getPluginByName(e.pluginName); @@ -2559,37 +2566,37 @@ class Rt extends X { this._viewPointerPositionLog.has(n.id) || this._viewPointerPositionLog.set(n.id, []); const r = new l(i, s), u = this._viewPointerPositionLog.get(n.id); u && u.push(new l(i, s)); - const c = u && u.length >= 2 ? u[u.length - 2] : r.clone(), h = this._calculateDirections( - c, + const h = u && u.length >= 2 ? u[u.length - 2] : r.clone(), c = this._calculateDirections( + h, r ); - this._emitEvent(n, h); + this._emitEvent(n, c); } }); }); } _emitEvent(t, i) { - const s = this._viewPointerPositionLog.get(t.id), n = s && s.length >= 2 ? s[s.length - 2] : null, r = this._pointerX - this._initialPointerPerView.get(t.id).x, u = this._pointerY - this._initialPointerPerView.get(t.id).y, c = this._pointerX, h = this._pointerY, d = n ? n.x - this._initialPointerPerView.get(t.id).x : r, _ = n ? n.y - this._initialPointerPerView.get(t.id).y : u, g = this._pointerY - this._initialPointer.y, f = this._pointerX - this._initialPointer.x, v = Ve(this._initialPointer, { + const s = this._viewPointerPositionLog.get(t.id), n = s && s.length >= 2 ? s[s.length - 2] : null, r = this._pointerX - this._initialPointerPerView.get(t.id).x, u = this._pointerY - this._initialPointerPerView.get(t.id).y, h = this._pointerX, c = this._pointerY, d = n ? n.x - this._initialPointerPerView.get(t.id).x : r, g = n ? n.y - this._initialPointerPerView.get(t.id).y : u, _ = this._pointerY - this._initialPointer.y, w = this._pointerX - this._initialPointer.x, f = Ve(this._initialPointer, { x: this._pointerX, y: this._pointerY - }), w = this._targetPerView.get(t.id); - if (!w || !t.hasElement(w)) + }), v = this._targetPerView.get(t.id); + if (!v || !t.hasElement(v)) return; - const P = this._pointerDownPerView.get(t.id) === !0; - P || this._viewPointerPositionLog.clear(); + const y = this._pointerDownPerView.get(t.id) === !0; + y || this._viewPointerPositionLog.clear(); const M = { view: t, - target: w, + target: v, previousX: d, - previousY: _, + previousY: g, x: r, y: u, - pointerX: c, - pointerY: h, - distance: v, - width: f, - height: g, - isDragging: P, + pointerX: h, + pointerY: c, + distance: f, + width: w, + height: _, + isDragging: y, directions: i }; this.emit(bt, M); @@ -2616,9 +2623,9 @@ class Rt extends X { projection: n.dot(s.right) } ].filter( - (c) => c.projection > 0 + (h) => h.projection > 0 ).map( - (c) => c.direction + (h) => h.direction ); } } @@ -2652,32 +2659,32 @@ class Et extends X { this.getViews().forEach((r) => { if (!this._viewIsPointerDownMap.get(r.id) || !this._viewPointerPositionLog.has(r.id)) return; - const u = new l(i, s), c = this._viewPointerPositionLog.get(r.id), h = c[c.length - 2] || u.clone(), d = this._targetPerView.get(r.id), _ = n(h, u); - d && r.hasElement(d) && _.hasSwiped && this.emit(xt, { + const u = new l(i, s), h = this._viewPointerPositionLog.get(r.id), c = h[h.length - 2] || u.clone(), d = this._targetPerView.get(r.id), g = n(c, u); + d && r.hasElement(d) && g.hasSwiped && this.emit(xt, { view: r, - direction: _.direction + direction: g.direction }), this._viewPointerPositionLog.set(r.id, []), this._viewIsPointerDownMap.set(r.id, !1); }); function n(r, u) { - const c = { + const h = { up: l.sub(new l(r.x, r.y - 1), r), down: l.sub(new l(r.x, r.y + 1), r), left: l.sub(new l(r.x - 1, r.y), r), right: l.sub(new l(r.x + 1, r.y), r) - }, h = l.sub(u, r).unitVector, d = [ + }, c = l.sub(u, r).unitVector, d = [ "up", "down", "left", "right" - ], _ = [ - h.dot(c.up), - h.dot(c.down), - h.dot(c.left), - h.dot(c.right) - ], g = Math.max(..._), f = _.indexOf(g), v = d[f], w = l.sub(u, r).magnitude; + ], g = [ + c.dot(h.up), + c.dot(h.down), + c.dot(h.left), + c.dot(h.right) + ], _ = Math.max(...g), w = g.indexOf(_), f = d[w], v = l.sub(u, r).magnitude; return { - hasSwiped: h.dot(c[v]) * w > 30, - direction: v + hasSwiped: c.dot(h[f]) * v > 30, + direction: f }; } }); @@ -2703,7 +2710,7 @@ class At extends X { } } o(At, "pluginName", "ClickEventPlugin"); -function It(a, e) { +function Nt(a, e) { const t = a.map(e), i = Math.min(...t), s = t.indexOf(i); return a[s]; } @@ -2711,7 +2718,7 @@ const St = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, clamp: W, distanceBetweenTwoPoints: Ve, - minBy: It, + minBy: Nt, pointToViewProgress: qe, randomNumber: ze, remap: Ue, diff --git a/dist/veloxi.min.js b/dist/veloxi.min.js index 70dae1c..c0b1ac2 100644 --- a/dist/veloxi.min.js +++ b/dist/veloxi.min.js @@ -1,3 +1,3 @@ -(function(f,v){typeof exports=="object"&&typeof module<"u"?v(exports):typeof define=="function"&&define.amd?define(["exports"],v):(f=typeof globalThis<"u"?globalThis:f||self,v(f.Veloxi={}))})(this,function(f){"use strict";var Lt=Object.defineProperty;var Bt=(f,v,P)=>v in f?Lt(f,v,{enumerable:!0,configurable:!0,writable:!0,value:P}):f[v]=P;var a=(f,v,P)=>(Bt(f,typeof v!="symbol"?v+"":v,P),P);class v{constructor(e){a(this,"x");a(this,"y");a(this,"target");this.x=e.x,this.y=e.y,this.target=e.target}}class P extends v{}class A extends v{}class I extends v{}class N extends v{}class k{constructor(e){a(this,"pluginId");a(this,"pluginName");a(this,"viewName");a(this,"dataName");a(this,"dataValue");this.event=e,this.pluginId=e.pluginId,this.pluginName=e.pluginName,this.viewName=e.viewName,this.dataName=e.dataName,this.dataValue=e.dataValue}}function Ce(o){return o.replace(/(?:^\w|[A-Z]|\b\w)/g,function(e,t){return t===0?e.toLowerCase():e.toUpperCase()}).replace(/\s+/g,"").replace(/-+/g,"")}function Le(o){return o.split("").map((e,t)=>e.toUpperCase()===e?`${t!==0?"-":""}${e.toLowerCase()}`:e).join("")}class z{constructor(e){a(this,"node");this.node=e.node}}class W{constructor(e){a(this,"node");this.node=e.node}}class Be{constructor(e){a(this,"_eventBus");a(this,"_observer");this._eventBus=e,this._observer=new MutationObserver(this._handler.bind(this)),this._observer.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeOldValue:!0})}_handler(e){e.forEach(t=>{t.addedNodes.forEach(n=>{if(!(n instanceof HTMLElement)||n.dataset.velViewId||n.parentElement&&typeof n.parentElement.dataset.velAdded<"u")return;let r=n;if(n.dataset.velView||(r=n.querySelector("[data-vel-view][data-vel-plugin]")),!r)return;this._eventBus.emitEvent(z,{node:r});const u=r.querySelectorAll("[data-vel-plugin]");u.length&&u.forEach(c=>{this._eventBus.emitEvent(z,{node:c})})}),t.removedNodes.forEach(n=>{if(!(n instanceof HTMLElement)||typeof n.dataset.velProcessing<"u")return;const r=n.querySelectorAll("[data-vel-plugin]");r.length&&r.forEach(u=>{this._eventBus.emitEvent(W,{node:u})}),this._eventBus.emitEvent(W,{node:n})});const i=t.attributeName;if(i&&/data-vel-data-.+/gi.test(i)){const n=t.target,r=n.dataset.velPluginId||"",u=n.dataset.velPlugin||"",c=n.dataset.velView||"",h=n.getAttribute(i);if(h&&h!==t.oldValue){const d=Ce(i.replace("data-vel-data-",""));this._eventBus.emitEvent(k,{pluginId:r,pluginName:u,viewName:c,dataName:d,dataValue:h})}}})}}class Se{execute(e){this.call(e)}}class ne extends Se{constructor(t){super();a(this,"_handler");this._handler=t}getHandler(){return this._handler}call(t){this._handler(t)}}class C{constructor(){a(this,"_listeners",new Map);a(this,"_keyedListeners",new Map)}subscribeToEvent(e,t,i){if(i){this._subscribeToKeyedEvent(e,t,i);return}let s=this._listeners.get(e);s||(s=[],this._listeners.set(e,s)),s.push(new ne(t))}removeEventListener(e,t,i){if(i){this._removeKeyedEventListener(e,t,i);return}let s=this._listeners.get(e);s&&(s=s.filter(n=>n.getHandler()!==t),this._listeners.set(e,s))}_subscribeToKeyedEvent(e,t,i){let s=this._keyedListeners.get(e);s||(s=new Map,this._keyedListeners.set(e,s));let n=s.get(i);n||(n=[],s.set(i,n)),n.push(new ne(t))}_removeKeyedEventListener(e,t,i){let s=this._keyedListeners.get(e);if(!s)return;let n=s.get(i);n&&(n=n.filter(r=>r.getHandler()!==t),s.set(i,n))}emitEvent(e,t,i){if(i){this._emitKeyedEvent(e,t,i);return}const s=this._listeners.get(e);s&&s.forEach(n=>{n.execute(t)})}_emitKeyedEvent(e,t,i){const s=this._keyedListeners.get(e);if(!s)return;const n=s.get(i);n&&n.forEach(r=>{r.execute(t)})}_convertListener(e){return t=>e(t)}subscribeToPluginReadyEvent(e,t,i=!1){if(i){this.subscribeToEvent(_e,this._convertListener(e),t);return}this.subscribeToEvent(ge,this._convertListener(e),t)}emitPluginReadyEvent(e,t,i=!1){if(i){this.emitEvent(_e,t,e);return}this.emitEvent(ge,t,e)}reset(){this._listeners.clear()}}let Fe=0;function re(){return Fe+++""}class ae{constructor(e,t,i,s,n,r,u){a(this,"_registry");a(this,"_eventBus");a(this,"_appEventBus");a(this,"_internalEventBus");a(this,"_initialized",!1);a(this,"_config");a(this,"_pluginFactory");a(this,"_pluginName");a(this,"_id");a(this,"_pluginKey");a(this,"_layoutIdViewMapWaitingToEnter");a(this,"_apiData");a(this,"_isReady",!1);this._id=re(),this._pluginFactory=e,this._pluginName=t,this._registry=i,this._eventBus=s,this._appEventBus=n,this._internalEventBus=new C,this._config=r,this._layoutIdViewMapWaitingToEnter=new Map,this._pluginKey=u,this._apiData={},this._appEventBus.subscribeToPluginReadyEvent(()=>{this._isReady=!0},this._pluginName,!0)}get api(){return this._apiData}_setApi(e){this._apiData=e}get pluginName(){return this._pluginName}get pluginFactory(){return this._pluginFactory}get pluginKey(){return this._pluginKey}get id(){return this._id}get config(){return{...this._config}}getViews(e){return e?this._registry.getViewsByNameForPlugin(this,e):this._registry.getViewsForPlugin(this)}getView(e){return e?this._registry.getViewsByNameForPlugin(this,e)[0]:this._registry.getViewsForPlugin(this)[0]}getViewById(e){return this._registry.getViewById(e)}addView(e){this._registry.assignViewToPlugin(e,this)}setInternalEventBus(e){this._internalEventBus=e}get internalBusEvent(){return this._internalEventBus}emit(e,t){this._internalEventBus.emitEvent(e,t)}on(e,t){this._internalEventBus.subscribeToEvent(e,t)}removeListener(e,t){this._internalEventBus.removeEventListener(e,t)}useEventPlugin(e,t={}){const i=this._registry.createPlugin(e,this._eventBus,t);return this._registry.associateEventPluginWithPlugin(this.id,i.id),i}notifyAboutDataChanged(e){this.onDataChanged(e)}onDataChanged(e){}removeView(e){e.onRemoveCallback?this._invokeRemoveCallback(e):this._deleteView(e),this.onViewRemoved(e)}_invokeRemoveCallback(e){const t=this._createTemporaryView(e);requestAnimationFrame(()=>{var i;(i=t.onRemoveCallback)==null||i.call(t,t,()=>{var s,n;if((s=e.onAddCallbacks)!=null&&s.afterRemoved&&e.layoutId){const r=this._layoutIdViewMapWaitingToEnter.get(e.layoutId);(n=r==null?void 0:r.onAddCallbacks)==null||n.afterEnter(r),this._layoutIdViewMapWaitingToEnter.delete(e.layoutId)}this._deleteView(t,!0)}),setTimeout(()=>{t.element.parentElement&&this._deleteView(t,!0)},1e4)})}_deleteView(e,t=!1){(t||!e.layoutId)&&(this._registry.removeViewById(e.id,this.id),e.element.remove())}_createTemporaryView(e){const t=e.previousRect.viewportOffset,i=e.previousRect.size,s=e.rotation.degrees<0?0:Math.sin(e.rotation.radians)*i.height*e.scale.y,n=e.rotation.degrees>0?0:Math.sin(e.rotation.radians)*i.width*e.scale.y,r=e.element.cloneNode(!0);e.element.remove(),r.style.cssText="",r.style.position="absolute",r.style.left=`${t.left+s}px`,r.style.top=`${t.top-n}px`,r.style.width=`${i.width}px`,r.style.height=`${i.height}px`,r.style.transform=` +(function(f,v){typeof exports=="object"&&typeof module<"u"?v(exports):typeof define=="function"&&define.amd?define(["exports"],v):(f=typeof globalThis<"u"?globalThis:f||self,v(f.Veloxi={}))})(this,function(f){"use strict";var Lt=Object.defineProperty;var Bt=(f,v,b)=>v in f?Lt(f,v,{enumerable:!0,configurable:!0,writable:!0,value:b}):f[v]=b;var a=(f,v,b)=>(Bt(f,typeof v!="symbol"?v+"":v,b),b);class v{constructor(e){a(this,"x");a(this,"y");a(this,"target");this.x=e.x,this.y=e.y,this.target=e.target}}class b extends v{}class A extends v{}class N extends v{}class I extends v{}class k{constructor(e){a(this,"pluginId");a(this,"pluginName");a(this,"viewName");a(this,"dataName");a(this,"dataValue");this.event=e,this.pluginId=e.pluginId,this.pluginName=e.pluginName,this.viewName=e.viewName,this.dataName=e.dataName,this.dataValue=e.dataValue}}function Ce(o){return o.replace(/(?:^\w|[A-Z]|\b\w)/g,function(e,t){return t===0?e.toLowerCase():e.toUpperCase()}).replace(/\s+/g,"").replace(/-+/g,"")}function Le(o){return o.split("").map((e,t)=>e.toUpperCase()===e?`${t!==0?"-":""}${e.toLowerCase()}`:e).join("")}class z{constructor(e){a(this,"node");this.node=e.node}}class W{constructor(e){a(this,"node");this.node=e.node}}class Be{constructor(e){a(this,"_eventBus");a(this,"_observer");this._eventBus=e,this._observer=new MutationObserver(this._handler.bind(this)),this._observer.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeOldValue:!0})}_handler(e){e.forEach(t=>{t.addedNodes.forEach(n=>{if(!(n instanceof HTMLElement)||n.dataset.velViewId||n.parentElement&&typeof n.parentElement.dataset.velAdded<"u")return;let r=n;if(n.dataset.velView||(r=n.querySelector("[data-vel-view][data-vel-plugin]")),!r)return;this._eventBus.emitEvent(z,{node:r});const u=r.querySelectorAll("[data-vel-plugin]");u.length&&u.forEach(h=>{this._eventBus.emitEvent(z,{node:h})})}),t.removedNodes.forEach(n=>{if(!(n instanceof HTMLElement)||typeof n.dataset.velProcessing<"u")return;const r=n.querySelectorAll("[data-vel-plugin]");r.length&&r.forEach(u=>{this._eventBus.emitEvent(W,{node:u})}),this._eventBus.emitEvent(W,{node:n})});const i=t.attributeName;if(i&&/data-vel-data-.+/gi.test(i)){const n=t.target,r=n.dataset.velPluginId||"",u=n.dataset.velPlugin||"",h=n.dataset.velView||"",c=n.getAttribute(i);if(c&&c!==t.oldValue){const d=Ce(i.replace("data-vel-data-",""));this._eventBus.emitEvent(k,{pluginId:r,pluginName:u,viewName:h,dataName:d,dataValue:c})}}})}}class Se{execute(e){this.call(e)}}class ne extends Se{constructor(t){super();a(this,"_handler");this._handler=t}getHandler(){return this._handler}call(t){this._handler(t)}}class C{constructor(){a(this,"_listeners",new Map);a(this,"_keyedListeners",new Map)}subscribeToEvent(e,t,i){if(i){this._subscribeToKeyedEvent(e,t,i);return}let s=this._listeners.get(e);s||(s=[],this._listeners.set(e,s)),s.push(new ne(t))}removeEventListener(e,t,i){if(i){this._removeKeyedEventListener(e,t,i);return}let s=this._listeners.get(e);s&&(s=s.filter(n=>n.getHandler()!==t),this._listeners.set(e,s))}_subscribeToKeyedEvent(e,t,i){let s=this._keyedListeners.get(e);s||(s=new Map,this._keyedListeners.set(e,s));let n=s.get(i);n||(n=[],s.set(i,n)),n.push(new ne(t))}_removeKeyedEventListener(e,t,i){let s=this._keyedListeners.get(e);if(!s)return;let n=s.get(i);n&&(n=n.filter(r=>r.getHandler()!==t),s.set(i,n))}emitEvent(e,t,i){if(i){this._emitKeyedEvent(e,t,i);return}const s=this._listeners.get(e);s&&s.forEach(n=>{n.execute(t)})}_emitKeyedEvent(e,t,i){const s=this._keyedListeners.get(e);if(!s)return;const n=s.get(i);n&&n.forEach(r=>{r.execute(t)})}_convertListener(e){return t=>e(t)}subscribeToPluginReadyEvent(e,t,i=!1){if(i){this.subscribeToEvent(_e,this._convertListener(e),t);return}this.subscribeToEvent(ge,this._convertListener(e),t)}emitPluginReadyEvent(e,t,i=!1){if(i){this.emitEvent(_e,t,e);return}this.emitEvent(ge,t,e)}reset(){this._listeners.clear()}}let Fe=0;function re(){return Fe+++""}class ae{constructor(e,t,i,s,n,r,u){a(this,"_registry");a(this,"_eventBus");a(this,"_appEventBus");a(this,"_internalEventBus");a(this,"_initialized",!1);a(this,"_config");a(this,"_pluginFactory");a(this,"_pluginName");a(this,"_id");a(this,"_pluginKey");a(this,"_layoutIdViewMapWaitingToEnter");a(this,"_apiData");a(this,"_isReady",!1);this._id=re(),this._pluginFactory=e,this._pluginName=t,this._registry=i,this._eventBus=s,this._appEventBus=n,this._internalEventBus=new C,this._config=r,this._layoutIdViewMapWaitingToEnter=new Map,this._pluginKey=u,this._apiData={},this._appEventBus.subscribeToPluginReadyEvent(()=>{this._isReady=!0},this._pluginName,!0)}get api(){return this._apiData}_setApi(e){this._apiData=e}get pluginName(){return this._pluginName}get pluginFactory(){return this._pluginFactory}get pluginKey(){return this._pluginKey}get id(){return this._id}get config(){return{...this._config}}getViews(e){return e?this._registry.getViewsByNameForPlugin(this,e):this._registry.getViewsForPlugin(this)}getView(e){return e?this._registry.getViewsByNameForPlugin(this,e)[0]:this._registry.getViewsForPlugin(this)[0]}getViewById(e){return this._registry.getViewById(e)}addView(e){this._registry.assignViewToPlugin(e,this)}setInternalEventBus(e){this._internalEventBus=e}get internalBusEvent(){return this._internalEventBus}emit(e,t){this._internalEventBus.emitEvent(e,t)}on(e,t){this._internalEventBus.subscribeToEvent(e,t)}removeListener(e,t){this._internalEventBus.removeEventListener(e,t)}useEventPlugin(e,t={}){const i=this._registry.createPlugin(e,this._eventBus,t);return this._registry.associateEventPluginWithPlugin(this.id,i.id),i}notifyAboutDataChanged(e){this.onDataChanged(e)}onDataChanged(e){}removeView(e){e.onRemoveCallback?this._invokeRemoveCallback(e):this._deleteView(e),this.onViewRemoved(e)}_invokeRemoveCallback(e){const t=this._createTemporaryView(e);requestAnimationFrame(()=>{var i;(i=t.onRemoveCallback)==null||i.call(t,t,()=>{var s,n;if((s=e.onAddCallbacks)!=null&&s.afterRemoved&&e.layoutId){const r=this._layoutIdViewMapWaitingToEnter.get(e.layoutId);(n=r==null?void 0:r.onAddCallbacks)==null||n.afterEnter(r),this._layoutIdViewMapWaitingToEnter.delete(e.layoutId)}this._deleteView(t,!0)}),setTimeout(()=>{t.element.parentElement&&this._deleteView(t,!0)},1e4)})}_deleteView(e,t=!1){(t||!e.layoutId)&&(this._registry.removeViewById(e.id,this.id),e.element.remove())}_createTemporaryView(e){const t=e.previousRect.viewportOffset,i=e.previousRect.size,s=e.rotation.degrees<0?0:Math.sin(e.rotation.radians)*i.height*e.scale.y,n=e.rotation.degrees>0?0:Math.sin(e.rotation.radians)*i.width*e.scale.y,r=e.element.cloneNode(!0);e.element.remove(),r.style.cssText="",r.style.position="absolute",r.style.left=`${t.left+s}px`,r.style.top=`${t.top-n}px`,r.style.width=`${i.width}px`,r.style.height=`${i.height}px`,r.style.transform=` scale3d(${e.scale.x}, ${e.scale.y}, 1) rotate(${e.rotation.degrees}deg) - `,r.style.pointerEvents="none",r.dataset.velRemoved="",document.body.appendChild(r);const u=this._registry.createView(r,e.name);return u.setAsTemporaryView(),u.styles.position="absolute",u.styles.left=`${t.left+s}px`,u.styles.top=`${t.top-n}px`,u.rotation.setDegrees(e.rotation.degrees,!1),u.scale.set({x:e.scale.x,y:e.scale.y},!1),u.size.set({width:e._localWidth,height:e._localHeight},!1),e._copyAnimatorsToAnotherView(u),e.onRemoveCallback&&u.onRemove(e.onRemoveCallback),u}onViewRemoved(e){}notifyAboutViewAdded(e){this.onViewAdded(e),this._invokeAddCallbacks(e)}_invokeAddCallbacks(e){var t,i,s;!((t=e.onAddCallbacks)!=null&&t.onInitialLoad)&&!this._initialized||((i=e.onAddCallbacks)==null||i.beforeEnter(e),!((s=e.onAddCallbacks)!=null&&s.afterRemoved)||!this._initialized?requestAnimationFrame(()=>{var n;(n=e.onAddCallbacks)==null||n.afterEnter(e)}):e.layoutId&&this._layoutIdViewMapWaitingToEnter.set(e.layoutId,e))}onViewAdded(e){}init(){!this._initialized&&this._isReady&&(this.setup(),this._initialized=!0)}setup(){}subscribeToEvents(e){}}class oe extends ae{isRenderable(){return!0}isInitialized(){return this._initialized}get initialized(){return this._initialized}update(e,t){}render(){}addView(e){e.setPluginId(this.id),super.addView(e)}}class L extends ae{isRenderable(){return!1}}class ue{constructor(e){a(this,"_plugin");this._plugin=e}get initialized(){return this._plugin.isInitialized()}get config(){return this._plugin.config}setup(e){this._plugin.setup=e}api(e){this._plugin._setApi(e)}update(e){this._plugin.update=e}render(e){this._plugin.render=e}getViews(e){return this._plugin.getViews(e)}getView(e){return this._plugin.getView(e)}getViewById(e){return this._plugin.getViewById(e)}useEventPlugin(e,t={}){return this._plugin.useEventPlugin(e,t)}emit(e,t){this._plugin.emit(e,t)}on(e,t){this._plugin.on(e,t)}onDataChanged(e){this._plugin.onDataChanged=e}onViewRemoved(e){this._plugin.onViewRemoved=e}onViewAdded(e){this._plugin.onViewAdded=e}subscribeToEvents(e){this._plugin.subscribeToEvents=e}}function U(o,e,t,i,s,n){if(Me(o))return new o(o,o.pluginName,e,t,i,s,n);const r=new oe(o,o.pluginName,e,t,i,s,n),u=new ue(r);return o(u),r}function Me(o){var e;return((e=o.prototype)==null?void 0:e.constructor.toString().indexOf("class "))===0}class l{constructor(e,t){a(this,"x");a(this,"y");this.x=e,this.y=t}get magnitudeSquared(){return this.x*this.x+this.y*this.y}get magnitude(){return Math.sqrt(this.x*this.x+this.y*this.y)}get unitVector(){const e=new l(0,0),t=this.magnitude;return t!==0&&(e.x=this.x/t,e.y=this.y/t),e}add(e){this.x+=e.x,this.y+=e.y}sub(e){this.x-=e.x,this.y-=e.y}scale(e){this.x*=e,this.y*=e}dot(e){return this.x*e.x+this.y*e.y}equals(e){return this.x===e.x&&this.y===e.y}clone(){return new l(this.x,this.y)}static scale(e,t){return new l(e.x*t,e.y*t)}static sub(e,t){return new l(e.x-t.x,e.y-t.y)}static add(e,t){return new l(e.x+t.x,e.y+t.y)}}function q(o,e,t){return Math.min(Math.max(o,e),t)}function $e(o,e){return Math.floor(Math.random()*(e-o+1)+o)}function le(o,e){const t=e.x-o.x,i=e.y-o.y;return Math.sqrt(t*t+i*i)}function De(o,e,t){return o+(e-o)*t}function p(o,e){const i=o-e;return Math.abs(i)<=.01}function Oe(o,e,t,i,s){return(o-e)/(t-e)*(s-i)+i}function ke(o,e,t,i){const s=e.getScroll(),n=e.position.x-s.x,r=e.position.y-s.y,u=o.x||n,c=o.y||r,h=Math.abs(n-u),d=Math.abs(r-c),_=Math.sqrt(h*h+d*d);let g=q(0,_/t,1);return typeof i>"u"?1-g:_<=i?1:(g=q((_-i)/t,0,1),1-g)}function m(o){let e=o.match(/^([\d.]+)([a-zA-Z%]*)$/);e||(e="0px".match(/^([\d.]+)([a-zA-Z%]*)$/));const t=parseFloat(e[1]),i=e[2];return{value:t,unit:i,valueWithUnit:o}}function ze(o,e,t=!1){if(o===e)return!0;if(o.length!==e.length)return!1;for(let i=0;im(i)),t={value:0,unit:"",valueWithUnit:"0"};switch(e.length){case 1:return new x(e[0],e[0],e[0],e[0]);case 2:return new x(e[0],e[1],e[0],e[1]);case 3:return new x(e[0],e[1],e[2],e[1]);case 4:return new x(e[0],e[1],e[3],e[2]);default:return new x(t,t,t,t)}}function We(o,e){const t=r(o.topLeft,e),i=r(o.topRight,e),s=r(o.bottomLeft,e),n=r(o.bottomRight,e);return{v:{topLeft:t.v,topRight:i.v,bottomRight:n.v,bottomLeft:s.v},h:{topLeft:t.h,topRight:i.h,bottomRight:n.h,bottomLeft:s.h}};function r(u,c){if(u.unit==="%")return{h:m(`${u.value}%`),v:m(`${u.value}%`)};const h=u.value/c.width*100,d=u.value/c.height*100;return{h:m(`${h}%`),v:m(`${d}%`)}}}function ce(o,e){return p(o.topLeft.value,e.topLeft.value)&&p(o.topRight.value,e.topRight.value)&&p(o.bottomRight.value,e.bottomRight.value)&&p(o.bottomLeft.value,e.bottomLeft.value)}class Ue{constructor(e){a(this,"_value");this._value=e}get value(){return this._value}equals(e){return p(this.value,e.value)}}function qe(o){return new Ue(parseFloat(o))}class Ye{constructor(e,t){a(this,"_x");a(this,"_y");this._x=e,this._y=t}get value(){return new l(this._x,this._y)}}function Xe(o,e){const[t,i]=o.split(" "),s=m(t),n=m(i);return new Ye(s.value/e.width,n.value/e.height)}function je(o){const e=He(o),t=Ke(o);return{viewportOffset:{left:Math.round(e.left),top:Math.round(e.top),right:Math.round(e.right),bottom:Math.round(e.bottom)},pageOffset:{top:t.top,left:t.left},size:{width:o.offsetWidth,height:o.offsetHeight}}}function He(o){const e=o.getBoundingClientRect();return{left:e.left,top:e.top,right:e.right,bottom:e.bottom,width:e.width,height:e.height}}function Ke(o){let e=o,t=0,i=0;for(;e;)t+=e.offsetTop,i+=e.offsetLeft,e=e.offsetParent;return{top:t,left:i}}class Ge{constructor(e){a(this,"_element");a(this,"_rect");a(this,"_computedStyle");this._rect=je(e),this._computedStyle=getComputedStyle(e),this._element=e}read(e){switch(e){case"opacity":return this.opacity;case"borderRadius":return this.borderRadius}}get rect(){return this._rect}get opacity(){return qe(this._computedStyle.opacity)}get borderRadius(){return Y(this._computedStyle.borderRadius)}get origin(){return Xe(this._computedStyle.transformOrigin,this._rect.size)}get scroll(){let e=this._element,t=0,i=0;for(;e;)t+=e.scrollTop,i+=e.scrollLeft,e=e.offsetParent;return i+=window.scrollX,t+=window.scrollY,{y:t,x:i}}}function X(o){return new Ge(o)}function j(o,e){const t={set:(i,s,n)=>(typeof i[s]=="object"&&i[s]!==null?i[s]=j(n,e):(e(),i[s]=n),!0),get:(i,s)=>typeof i[s]=="object"&&i[s]!==null?j(i[s],e):i[s]};return new Proxy(o,t)}const B=.01,H={speed:15};class K{constructor(e){a(this,"name","dynamic");a(this,"_config");this._config=e}get config(){return this._config}}class Ze extends K{update({animatorProp:e,current:t,target:i,dt:s}){const n=l.sub(i,t),r=l.scale(n,this._config.speed);let u=l.add(t,l.scale(r,s));return this._shouldFinish(i,t,r)&&(u=i,requestAnimationFrame(()=>{e.callCompleteCallback()})),e.callUpdateCallback(),u}_shouldFinish(e,t,i){return l.sub(e,t).magnitude{e.callCompleteCallback()})),e.callUpdateCallback(),u}}class Qe extends K{update({animatorProp:e,current:t,target:i,dt:s}){return i.map((n,r)=>{const u=t[r],c=n.value===0?u.unit:n.unit,d=(n.value-u.value)*this._config.speed,_=u.value+d*s;let g=m(`${_}${c}`);return this._shouldFinish(n.value,u.value,d)&&(g=n,requestAnimationFrame(()=>{e.callCompleteCallback()})),e.callUpdateCallback(),g})}_shouldFinish(e,t,i){return Math.abs(e-t){e.animatorProp.callCompleteCallback()}),e.target}}const Z={stiffness:.5,damping:.75,speed:10},S=.01;class J{constructor(e){a(this,"name","spring");a(this,"_config");this._config=e}get config(){return this._config}}class et extends J{constructor(){super(...arguments);a(this,"_velocity",new l(0,0))}update({animatorProp:t,current:i,target:s,dt:n}){const r=l.scale(l.scale(l.sub(i,s),-1),this._config.stiffness);this._velocity=l.add(this._velocity,r),this._velocity=l.scale(this._velocity,this._config.damping);let u=l.add(i,l.scale(this._velocity,n*this._config.speed));return this._shouldFinish(s,i)&&(u=s,requestAnimationFrame(()=>{t.callCompleteCallback()})),u}_shouldFinish(t,i){return l.sub(t,i).magnitude{t.callCompleteCallback()})),u}}class it extends J{constructor(){super(...arguments);a(this,"_velocity",0)}update({animatorProp:t,current:i,target:s,dt:n}){return s.map((r,u)=>{const c=i[u],h=r.value===0?c.unit:r.unit,d=-(c.value-r.value)*this._config.stiffness;this._velocity+=d,this._velocity*=this._config.damping;const _=c.value+this._velocity*n*this._config.speed;let g=m(`${_}${h}`);return this._shouldFinish(r.value,c.value)&&(g=r,requestAnimationFrame(()=>{t.callCompleteCallback()})),g})}_shouldFinish(t,i){return Math.abs(t-i){e.callCompleteCallback()}),i):l.add(t,l.scale(l.sub(i,t),this._config.ease(n)))}}class rt extends ee{update({animatorProp:e,initial:t,target:i,ts:s}){this._startTime||(this._startTime=s);const n=Math.min(1,(s-this._startTime)/this._config.duration);return p(n,1)?(requestAnimationFrame(()=>{e.callCompleteCallback()}),i):t.map((r,u)=>{const c=i[u],h=c.value===0?r.unit:c.unit,d=r.value+this._config.ease(n)*(i[u].value-r.value);return m(`${d}${h}`)})}}class at extends ee{update({animatorProp:e,initial:t,target:i,ts:s}){this._startTime||(this._startTime=s);const n=Math.min(1,(s-this._startTime)/this._config.duration);return p(n,1)?(requestAnimationFrame(()=>{e.callCompleteCallback()}),i):t+(i-t)*this._config.ease(n)}}class te{createAnimatorByName(e,t){switch(e){case"instant":return this.createInstantAnimator();case"dynamic":return this.createDynamicAnimator(t);case"tween":return this.createTweenAnimator(t);case"spring":return this.createSpringAnimator(t)}return this.createInstantAnimator()}}class F extends te{createInstantAnimator(){return new G}createTweenAnimator(e){return new nt({...Q,...e})}createDynamicAnimator(e){return new Ze({...H,...e})}createSpringAnimator(e){return new et({...Z,...e})}}class ot extends te{createInstantAnimator(){return new G}createTweenAnimator(e){return new rt({...Q,...e})}createDynamicAnimator(e){return new Qe({...H,...e})}createSpringAnimator(e){return new it({...Z,...e})}}class de extends te{createInstantAnimator(){return new G}createDynamicAnimator(e){return new Je({...H,...e})}createTweenAnimator(e){return new at({...Q,...e})}createSpringAnimator(e){return new tt({...Z,...e})}}function T(o){return structuredClone(o)}class ut{constructor(e){a(this,"_viewProp");a(this,"_completeCallback");a(this,"_updateCallback");a(this,"_isAnimating");this._viewProp=e,this._isAnimating=!1}set(e,t){this._viewProp.setAnimator(e,t)}get name(){return this._viewProp.getAnimator().name}onComplete(e){this._completeCallback=e}get isAnimating(){return this._isAnimating}markAsAnimating(){this._isAnimating=!0}callCompleteCallback(){var e;(e=this._completeCallback)==null||e.call(this),this._isAnimating=!1}onUpdate(e){this._updateCallback=e}callUpdateCallback(){var e;(e=this._updateCallback)==null||e.call(this)}}class R{constructor(e,t,i){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 ut(this),this._animatorFactory=e,this._initialValue=T(t),this._previousValue=T(t),this._targetValue=T(t),this._currentValue=T(t),this._hasChanged=!1,this._previousRenderValue=void 0,this._view=i,this._animator=this._animatorFactory.createInstantAnimator()}get shouldRender(){return!0}get isAnimating(){return this.animator.isAnimating}getAnimator(){return this._animator}get animator(){return this._animatorProp}get _rect(){return this._view.rect}get _previousRect(){return this._view.previousRect}setAnimator(e,t){this._animator=this._animatorFactory.createAnimatorByName(e,t)}_setTarget(e,t=!0){var i,s;this._previousValue=T(this._currentValue),this._targetValue=e,t?((s=(i=this._animator).reset)==null||s.call(i),this.animator.markAsAnimating()):this._currentValue=e,this._hasChanged=!0}hasChanged(){return this._hasChanged}destroy(){this._hasChanged=!1}update(e,t){}}class lt extends R{constructor(){super(...arguments);a(this,"_invertedBorderRadius");a(this,"_forceStyleUpdateThisFrame",!1);a(this,"_updateWithScale",!1)}setFromElementPropValue(t){this._setTarget([t.value.topLeft,t.value.topRight,t.value.bottomRight,t.value.bottomLeft],!0)}enableUpdateWithScale(){this._updateWithScale=!0}disableUpdateWithScale(){this._updateWithScale=!1}get value(){return{topLeft:this._currentValue[0],topRight:this._currentValue[1],bottomRight:this._currentValue[2],bottomLeft:this._currentValue[3]}}get invertedBorderRadius(){return this._invertedBorderRadius}set(t,i=!0){let s;if(typeof t=="string"){const h=Y(t.trim());s={topLeft:h.value.topLeft.valueWithUnit,topRight:h.value.topRight.valueWithUnit,bottomRight:h.value.bottomRight.valueWithUnit,bottomLeft:h.value.bottomLeft.valueWithUnit}}else s=t;const n=s.topLeft?m(s.topLeft):this._currentValue[0],r=s.topRight?m(s.topRight):this._currentValue[1],u=s.bottomRight?m(s.bottomRight):this._currentValue[2],c=s.bottomLeft?m(s.bottomLeft):this._currentValue[3];this._setTarget([n,r,u,c],i)}reset(t=!0){this._setTarget(this._initialValue,t)}update(t,i){if(this._forceStyleUpdateThisFrame)this._hasChanged=!0,this._forceStyleUpdateThisFrame=!1;else if(this._view.scale.isAnimating&&this._updateWithScale)this._hasChanged=!0;else if(he(this._targetValue,this._currentValue)){this._hasChanged=!he(this._targetValue,this._initialValue);return}this._currentValue=this._animator.update({animatorProp:this._animatorProp,current:this._currentValue,target:this._targetValue,initial:this._previousValue,ts:t,dt:i}),this._updateWithScale&&this._applyScaleInverse()}applyScaleInverse(){this._updateWithScale&&(this._forceStyleUpdateThisFrame=!0)}_applyScaleInverse(){if(p(this._view.scale.x,1)&&p(this._view.scale.y,1))return;const t=this._rect.size.width*this._view.scale.x,i=this._rect.size.height*this._view.scale.y;this._invertedBorderRadius=We(Y(`${this._currentValue[0].valueWithUnit} ${this._currentValue[1].valueWithUnit} ${this._currentValue[2].valueWithUnit} ${this._currentValue[3].valueWithUnit}`).value,{width:t,height:i})}get shouldRender(){return this._hasChanged?this._previousRenderValue?!(ce(this.renderValue.v,this._previousRenderValue.v)&&ce(this.renderValue.h,this._previousRenderValue.h)):!0:!1}get renderValue(){return this.invertedBorderRadius?{v:{topLeft:this.invertedBorderRadius.v.topLeft,topRight:this.invertedBorderRadius.v.topRight,bottomLeft:this.invertedBorderRadius.v.bottomLeft,bottomRight:this.invertedBorderRadius.v.bottomRight},h:{topLeft:this.invertedBorderRadius.h.topLeft,topRight:this.invertedBorderRadius.h.topRight,bottomLeft:this.invertedBorderRadius.h.bottomLeft,bottomRight:this.invertedBorderRadius.h.bottomRight}}:{v:{topLeft:this.value.topLeft,topRight:this.value.topRight,bottomLeft:this.value.bottomLeft,bottomRight:this.value.bottomRight},h:{topLeft:this.value.topLeft,topRight:this.value.topRight,bottomLeft:this.value.bottomLeft,bottomRight:this.value.bottomRight}}}projectStyles(){const t=this.renderValue,i=`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};`;return this._previousRenderValue=t,i}isTransform(){return!1}}class ht extends R{setFromElementPropValue(e){this._setTarget(e.value,!0)}get value(){return this._currentValue}set(e,t=!0){this._setTarget(e,t)}reset(e=!0){this._setTarget(1,e)}update(e,t){if(p(this._targetValue,this._currentValue)){this._hasChanged=!p(this._targetValue,this._initialValue);return}this._currentValue=this._animator.update({animatorProp:this._animatorProp,current:this._currentValue,target:this._targetValue,initial:this._previousValue,ts:e,dt:t})}get shouldRender(){return this._hasChanged?typeof this._previousRenderValue>"u"?!0:this.renderValue!==this._previousRenderValue:!1}get renderValue(){return this.value}projectStyles(){const e=this.renderValue,t=`opacity: ${e};`;return this._previousRenderValue=e,t}isTransform(){return!1}}class ct extends R{get x(){return this._currentValue.x}get y(){return this._currentValue.y}set(e){const i={...{x:this.x,y:this.y},...e};if(i.x<0||i.x>1){console.log(`%c WARNING: ${this._view.name}.origin.x property can only be a value from 0 to 1`,"background: #885500");return}if(i.y<0||i.y>1){console.log(`%c WARNING: ${this._view.name}.origin.y property can only be a value from 0 to 1`,"background: #885500");return}this._setTarget(new l(i.x,i.y),!1)}reset(){this._setTarget(this._initialValue,!1)}get shouldRender(){if(!this._hasChanged)return!1;if(!this._previousRenderValue)return!0;const e=this.renderValue;return!(p(e.x,this._previousRenderValue.x)&&p(e.y,this._previousRenderValue.y))}get renderValue(){return new l(this.x*100,this.y*100)}projectStyles(){const e=this.renderValue,t=`transform-origin: ${e.x}% ${e.y}%;`;return this._previousRenderValue=e,t}isTransform(){return!1}}class dt extends R{constructor(){super(...arguments);a(this,"_animateLayoutUpdateNextFrame",!1);a(this,"_parentScaleInverse",new l(1,1))}get _parentDiff(){let t=this._view._parent,i=0,s=0;if(t){const n=t.rect.pageOffset,r=t.getScroll(),u={left:t.previousRect.viewportOffset.left+r.x,top:t.previousRect.viewportOffset.top+r.y};i=u.left-n.left,s=u.top-n.top}return{parentDx:i,parentDy:s}}get x(){return this._currentValue.x+this._rect.pageOffset.left+this._parentDiff.parentDx}get y(){return this._currentValue.y+this._rect.pageOffset.top+this._parentDiff.parentDy}get initialX(){return this._rect.pageOffset.left}get initialY(){return this._rect.pageOffset.top}progressTo(t){const i=typeof t.x>"u"?this.initialX:t.x,s=typeof t.y>"u"?this.initialY:t.y,n=new l(i,s),r=new l(this.initialX,this.initialY),u=new l(this.x,this.y),c=l.sub(u,r),h=l.sub(n,r);return 1-l.sub(h,c).magnitude/h.magnitude}set(t,i=!0){const n={...{x:this.x,y:this.y},...t};this._setTarget(new l(n.x-this._rect.pageOffset.left,n.y-this._rect.pageOffset.top),i)}reset(t=!0){this._setTarget(new l(0,0),t)}update(t,i){if((this._view.isInverseEffectEnabled||this._view.isLayoutTransitionEnabled)&&!this._view.isTemporaryView&&this._runLayoutTransition(),this._view.isInverseEffectEnabled){const h=this._view._parent,d=h?h.scale.x:1,_=h?h.scale.y:1;this._parentScaleInverse=new l(1/d,1/_),this._parentScaleInverse.equals(new l(1,1))||(this._hasChanged=!0)}if(this._targetValue.x===this._currentValue.x&&this._targetValue.y===this._currentValue.y)return;const s=this._view._parent,n=s?s.scale.x:1,r=s?s.scale.y:1,u=s?s.scale._previousValue.x:1,c=s?s.scale._previousValue.y:1;this._currentValue=this._animator.update({animatorProp:this._animatorProp,current:new l(this._currentValue.x*n,this._currentValue.y*r),target:this._targetValue,initial:new l(this._previousValue.x*u,this._previousValue.y*c),ts:t,dt:i}),this._currentValue=new l(this._currentValue.x/n,this._currentValue.y/r)}_runLayoutTransition(){const t=!(this._targetValue.x===this._currentValue.x&&this._targetValue.y===this._currentValue.y),i=!(this._view.scale._targetValue.x===this._view.scale._currentValue.x&&this._view.scale._targetValue.y===this._view.scale._currentValue.y),s=t||i,n=this._rect.pageOffset.left-this._previousRect.pageOffset.left,r=this._rect.pageOffset.top-this._previousRect.pageOffset.top,u=this._previousRect.size.width/this._rect.size.width,c=this._previousRect.size.height/this._rect.size.height;let h=!1;if(n!==0||r!==0||!Number.isNaN(u)&&u!==1||!Number.isNaN(c)&&c!==1?h=!0:h=(()=>{const d=this._view._parents;for(let _=0;_"u")return!0;const t=this.renderValue;return!p(t,this._previousRenderValue)}get renderValue(){return this._currentValue}projectStyles(){const t=this.renderValue,i=`rotate(${t}${this._unit})`;return this._previousRenderValue=t,i}isTransform(){return!0}}class _t extends R{constructor(){super(...arguments);a(this,"_animateLayoutUpdateNextFrame",!1)}get x(){return this._currentValue.x}get y(){return this._currentValue.y}set(t,i=!0){const r={...{x:this._currentValue.x,y:this._currentValue.y},...typeof t=="number"?{x:t,y:t}:t};this._setTarget(new l(r.x,r.y),i)}setWithSize(t,i=!0){let s=this._currentValue.x,n=this._currentValue.y;t.width&&(s=t.width/this._rect.size.width),t.height&&(n=t.height/this._rect.size.height),!t.width&&t.height&&(s=n),!t.height&&t.width&&(n=s);const r={x:s,y:n};this._setTarget(new l(r.x,r.y),i)}reset(t=!0){this._setTarget(new l(1,1),t)}update(t,i){if((this._view.isInverseEffectEnabled||this._view.isLayoutTransitionEnabled)&&!this._view.isTemporaryView&&this._runLayoutTransition(),this._view.isInverseEffectEnabled){const s=this._view._parent,n=s?s.scale.x:1,r=s?s.scale.y:1;this._hasChanged=n!==1||r!==1}this._targetValue.x===this._currentValue.x&&this._targetValue.y===this._currentValue.y||(this._currentValue=this._animator.update({animatorProp:this._animatorProp,current:this._currentValue,target:this._targetValue,initial:new l(this._previousValue.x,this._previousValue.y),ts:t,dt:i}))}_runLayoutTransition(){const t=!(this._targetValue.x===this._currentValue.x&&this._targetValue.y===this._currentValue.y),i=this._previousRect.size.width/this._rect.size.width,s=this._previousRect.size.height/this._rect.size.height;let n=!1;if((!Number.isNaN(i)&&i!==1||!Number.isNaN(s)&&s!==1)&&(n=!0),n){if(this._currentValue.x!==1||this._currentValue.y!==1){const d=this._view.previousRect.size.width/this._view.rect.size.width,_=this._view.previousRect.size.height/this._view.rect.size.height;this._setTarget(new l(this._currentValue.x*d,this._currentValue.y*_),!1),t&&(this._animateLayoutUpdateNextFrame=!0);return}const r=this._previousRect.size.width/this._rect.size.width,u=this._previousRect.size.height/this._rect.size.height,c=r,h=u;this._view.viewProps.borderRadius.applyScaleInverse(),this._setTarget(new l(c,h),!1),this._animateLayoutUpdateNextFrame=!0}else this._animateLayoutUpdateNextFrame&&(this._setTarget(this._initialValue,!0),this._animateLayoutUpdateNextFrame=!1)}get shouldRender(){if(!this._hasChanged)return!1;if(!this._previousRenderValue)return!0;const t=this.renderValue;return!(p(t.x,this._previousRenderValue.x)&&p(t.y,this._previousRenderValue.y))}get renderValue(){const t=this._view._parent?this._view._parent.scale.x:1,i=this._view._parent?this._view._parent.scale.y:1,s=this._currentValue.x/t,n=this._currentValue.y/i;return new l(s,n)}projectStyles(){const t=this.renderValue,i=`scale3d(${t.x}, ${t.y}, 1)`;return this._previousRenderValue=t,i}isTransform(){return!0}}class pt extends R{get width(){return this._view.rect.size.width}get height(){return this._view.rect.size.height}get localWidth(){return this._currentValue.x}get localHeight(){return this._currentValue.y}get widthAfterScale(){const e=this._view.scale.x;return this.localWidth*e}get heightAfterScale(){const e=this._view.scale.y;return this.localHeight*e}get initialWidth(){return this._initialValue.x}get initialHeight(){return this._initialValue.y}set(e,t=!0){const s={...{width:this._currentValue.x,height:this._currentValue.y},...e};this._setTarget(new l(s.width,s.height),t)}setWidth(e,t=!0){const s={...{width:this._currentValue.x,height:this._currentValue.y},width:e};this._setTarget(new l(s.width,s.height),t)}setHeight(e,t=!0){const s={...{width:this._currentValue.x,height:this._currentValue.y},height:e};this._setTarget(new l(s.width,s.height),t)}reset(e=!0){this._setTarget(new l(this.initialWidth,this.initialHeight),e)}update(e,t){this._targetValue.x===this._currentValue.x&&this._targetValue.y===this._currentValue.y||(this._currentValue=this._animator.update({animatorProp:this._animatorProp,current:this._currentValue,target:this._targetValue,initial:this._previousValue,ts:e,dt:t}))}get shouldRender(){if(!this._hasChanged)return!1;if(!this._previousRenderValue)return!0;const e=this.renderValue;return!(p(e.x,this._previousRenderValue.x)&&p(e.y,this._previousRenderValue.y))}get renderValue(){return new l(this._currentValue.x,this._currentValue.y)}projectStyles(){const e=this.renderValue,t=`width: ${e.x}px; height: ${e.y}px;`;return this._previousRenderValue=e,t}isTransform(){return!1}}class ft{constructor(e){a(this,"_props",new Map);this._props.set("position",new dt(new F,new l(0,0),e)),this._props.set("scale",new _t(new F,new l(1,1),e)),this._props.set("rotation",new gt(new de,0,e)),this._props.set("size",new pt(new F,new l(e.rect.size.width,e.rect.size.height),e)),this._props.set("opacity",new ht(new de,e.elementReader.opacity.value,e)),this._props.set("borderRadius",new lt(new ot,[e.elementReader.borderRadius.value.topLeft,e.elementReader.borderRadius.value.topRight,e.elementReader.borderRadius.value.bottomRight,e.elementReader.borderRadius.value.bottomLeft],e)),this._props.set("origin",new ct(new F,e.elementReader.origin.value,e))}allProps(){return Array.from(this._props.values())}allPropNames(){return Array.from(this._props.keys())}getPropByName(e){return this._props.get(e)}get position(){return this._props.get("position")}get scale(){return this._props.get("scale")}get rotation(){return this._props.get("rotation")}get size(){return this._props.get("size")}get opacity(){return this._props.get("opacity")}get borderRadius(){return this._props.get("borderRadius")}get origin(){return this._props.get("origin")}}class vt{constructor(e,t,i,s){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,"_temporaryView");a(this,"_inverseEffect");a(this,"_renderNextTick");this.id=re(),this.name=t,this.element=e,this._elementReader=X(e),this._previousRect=this._elementReader.rect,this._viewProps=new ft(this),this._skipFirstRenderFrame=!0,this._layoutId=s,this._layoutTransition=!1,this._registry=i,this.element.dataset.velViewId=this.id,this._temporaryView=!1,this._inverseEffect=!1,this.styles=j(this.styles,()=>{this._renderNextTick=!0}),this._renderNextTick=!1}destroy(){this._viewProps.allProps().forEach(e=>e.destroy()),this.element.removeAttribute("data-vel-view-id"),this.element.removeAttribute("data-vel-plugin-id"),this._renderNextTick=!0}get elementReader(){return this._elementReader}setElement(e){this.element=e,this._elementReader=X(this.element),this.element.dataset.velViewId=this.id}get layoutId(){return this._layoutId}get position(){return this._viewProps.position}get scale(){return this._viewProps.scale}get _children(){return Array.from(this.element.children).map(t=>t.dataset.velViewId).filter(t=>t&&typeof t=="string").map(t=>this._registry.getViewById(t)).filter(t=>!!t)}get _parent(){var i;const e=this.element.parentElement;if(!e)return;const t=e.closest("[data-vel-view-id]");if((i=t==null?void 0:t.dataset)!=null&&i.velViewId)return this._registry.getViewById(t.dataset.velViewId)}get _parents(){var i;const e=[];let t=this.element.parentElement;if(!t)return e;for(t=t.closest("[data-vel-view-id]");t;){const s=t.dataset.velViewId;if(s){const n=this._registry.getViewById(s);n&&e.push(n)}t=(i=t.parentElement)==null?void 0:i.closest("[data-vel-view-id]")}return e}get rotation(){return this._viewProps.rotation}get size(){return this._viewProps.size}get _localWidth(){return this._viewProps.size.localWidth}get _localHeight(){return this._viewProps.size.localHeight}get opacity(){return this._viewProps.opacity}get borderRadius(){return this._viewProps.borderRadius}get origin(){return this._viewProps.origin}get data(){const e=this.element.dataset;return Object.keys(e).filter(s=>s.includes("velData")).map(s=>s.replace("velData","")).map(s=>`${s[0].toLowerCase()}${s.slice(1)}`).reduce((s,n)=>{const r=e[`velData${n[0].toUpperCase()}${n.slice(1)}`];return!s[n]&&r&&(s[n]=r),s},{})}get onAddCallbacks(){return this._onAddCallbacks}get onRemoveCallback(){return this._onRemoveCallback}get isLayoutTransitionEnabled(){return this._layoutTransition}get hasLayoutTransitionEnabledForParents(){return this._parents.some(e=>e.isLayoutTransitionEnabled)}get isInverseEffectEnabled(){return this._parents.some(e=>e._inverseEffect)}layoutTransition(e){this._layoutTransition=e,this.inverseEffect(e)}inverseEffect(e){this._inverseEffect=e,e&&this._children.forEach(t=>{if(t.position.animator.name==="instant"){const i=this.viewProps.position.getAnimator();t.position.setAnimator(i.name,i.config)}if(t.scale.animator.name==="instant"){const i=this.viewProps.scale.getAnimator();t.scale.setAnimator(i.name,i.config)}})}setAnimatorsFromParent(){let e=this._parent;for(;e&&!e._inverseEffect;)e=e._parent;if(e){if(this.position.animator.name==="instant"){const t=e.viewProps.position.getAnimator();this.position.setAnimator(t.name,t.config)}if(this.scale.animator.name==="instant"){const t=e.viewProps.scale.getAnimator();this.scale.setAnimator(t.name,t.config)}}}get _isRemoved(){return!this._registry.getViewById(this.id)}setPluginId(e){this.element.dataset.velPluginId=e}hasElement(e){return this.element.contains(e)}getScroll(){return this._elementReader.scroll}intersects(e,t){const i={x:this.rect.viewportOffset.left,y:this.rect.viewportOffset.top};return e>=i.x&&e<=i.x+this.size.width&&t>=i.y&&t<=i.y+this.size.height}overlapsWith(e){const t=e._localWidth*e.scale.x,i=e._localHeight*e.scale.y,s=this._localWidth*this.scale.x,n=this._localHeight*this.scale.y;return this.position.xe.position.x&&this.position.ye.position.y}distanceTo(e){const t=new l(this.position.x,this.position.y),i=new l(e.position.x,e.position.y);return l.sub(i,t).magnitude}read(){this._elementReader=X(this.element)}get rect(){return this._elementReader.rect}get previousRect(){return this._previousRect}update(e,t){this._viewProps.allProps().forEach(i=>i.update(e,t))}_updatePreviousRect(){this._previousRect=this._elementReader.rect}setAsTemporaryView(){this._temporaryView=!0}get isTemporaryView(){return this._temporaryView}get shouldRender(){return this._renderNextTick||this._viewProps.allProps().some(e=>e.shouldRender)}render(){if(!this.shouldRender)return;if(this._isRemoved&&this._skipFirstRenderFrame){this._skipFirstRenderFrame=!1;return}let e="";const t=this._viewProps.allProps(),i=t.filter(n=>n.isTransform()),s=t.filter(n=>!n.isTransform());if(i.some(n=>n.hasChanged())){const n=i.reduce((r,u,c)=>(r+=u.projectStyles(),c===i.length-1&&(r+=";"),r),"transform: ");e+=n}s.forEach(n=>{n.hasChanged()&&(e+=n.projectStyles())}),e+=this._getUserStyles(),this.element.style.cssText=e,this._renderNextTick=!1}_getUserStyles(){return Object.keys(this.styles).reduce((e,t)=>t?e+`${Le(t)}: ${this.styles[t]};`:e,"")}markAsAdded(){delete this.element.dataset.velProcessing}onAdd(e){this._onAddCallbacks=e}onRemove(e){this._onRemoveCallback=e}get viewProps(){return this._viewProps}getPropByName(e){return this._viewProps.getPropByName(e)}_copyAnimatorsToAnotherView(e){e.viewProps.allPropNames().forEach(t=>{var s,n;const i=(s=this.viewProps.getPropByName(t))==null?void 0:s.getAnimator();i&&((n=e.viewProps.getPropByName(t))==null||n.setAnimator(i.name,i.config))})}getChildren(e){const t=Array.from(this.element.children).filter(i=>{const s=i;return typeof s.dataset.velViewId<"u"&&s.dataset.velView===e}).map(i=>i.dataset.velViewId);return this._registry.getViewsById(t)}getChild(e){return this.getChildren(e)[0]}getParent(e){const t=this.element.parentElement;if(!t)return;const i=t.dataset.velViewId;if(i&&t.dataset.velView===e)return this._registry.getViewById(i)}}class mt{constructor(e,t){a(this,"_appEventBus");a(this,"_eventBus");a(this,"_plugins",[]);a(this,"_views",[]);a(this,"_viewsPerPlugin",new Map);a(this,"_viewsToBeCreated",[]);a(this,"_viewsToBeRemoved",[]);a(this,"_viewsCreatedInPreviousFrame",[]);a(this,"_layoutIdToViewMap",new Map);a(this,"_eventPluginsPerPlugin",new Map);a(this,"_pluginNameToPluginFactoryMap",new Map);a(this,"_pluginNameToPluginConfigMap",new Map);this._appEventBus=e,this._eventBus=t}update(){this._handleRemovedViews(),this._handleAddedViews()}associateEventPluginWithPlugin(e,t){let i=this._eventPluginsPerPlugin.get(e);i||(i=[],this._eventPluginsPerPlugin.set(e,i)),i.push(t)}_handleRemovedViews(){const e=this._viewsToBeRemoved.filter(t=>t.dataset.velViewId);e.length&&(e.forEach(t=>{const i=t.dataset.velViewId;i&&this._handleRemoveView(i)}),this._viewsToBeRemoved=[])}_getPluginNameForElement(e){const t=e.dataset.velPlugin;if(t&&t.length>0)return t;const i=e.closest("[data-vel-plugin]");if(i)return i.dataset.velPlugin}_getPluginIdForElement(e){const t=this._getPluginNameForElement(e);if(!t)return;const i=e.closest("[data-vel-plugin-id]");if(i)return i.dataset.velPluginId;const s=this.getPluginByName(t);if(s)return s.id}_isScopedElement(e){const t=this._getPluginNameForElement(e);if(!t)return!1;const i=this._pluginNameToPluginFactoryMap.get(t),s=i==null?void 0:i.scope;return e.dataset.velView===s}_handleAddedViews(){this._viewsCreatedInPreviousFrame.forEach(s=>{s.markAsAdded()}),this._viewsCreatedInPreviousFrame=[];const e=this._viewsToBeCreated.filter(s=>this._isScopedElement(s)),t=this._viewsToBeCreated.filter(s=>!this._isScopedElement(s));this._viewsToBeCreated=[],e.forEach(s=>{const n=this._getPluginNameForElement(s),r=this._pluginNameToPluginFactoryMap.get(n),u=this._pluginNameToPluginConfigMap.get(n),c=s.dataset.velPluginKey,h=U(r,this,this._eventBus,this._appEventBus,u,c);this._plugins.push(h);const d=s.dataset.velView,_=this._createNewView(s,d,h);_.isInverseEffectEnabled&&_.setAnimatorsFromParent(),h.notifyAboutViewAdded(_)});const i=t.filter(s=>!!this._getPluginIdForElement(s));i.length!==0&&i.forEach(s=>{const n=this._getPluginIdForElement(s),r=s.dataset.velView;if(!r||!n)return;const u=this._getPluginById(n);if(!u)return;const c=this._getLayoutIdForElement(s,u);let h;c&&this._layoutIdToViewMap.has(c)?(h=this._layoutIdToViewMap.get(c),h.setElement(s),h.setPluginId(u.id),this._createChildrenForView(h,u)):h=this._createNewView(s,r,u),h.isInverseEffectEnabled&&h.setAnimatorsFromParent(),u.notifyAboutViewAdded(h)})}_getLayoutIdForElement(e,t){const i=e.dataset.velLayoutId;if(i)return`${i}-${t.id}`}_createNewView(e,t,i){const s=this._getLayoutIdForElement(e,i),n=this.createView(e,t,s);return i.addView(n),n.layoutId&&this._layoutIdToViewMap.set(n.layoutId,n),this._createChildrenForView(n,i),this._appEventBus.emitPluginReadyEvent(i.pluginName,i.api,!0),requestAnimationFrame(()=>{requestAnimationFrame(()=>{this._appEventBus.emitPluginReadyEvent(i.pluginName,i.api)})}),n}_createChildrenForView(e,t){const i=e.element.querySelectorAll("*");if(i.length){if(Array.from(i).some(s=>this._getPluginNameForElement(s)!==t.pluginName)){console.log(`%c WARNING: The plugin "${t.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 "${t.pluginName}"`,"background: #885500");return}Array.from(i).forEach(s=>{const n=s,r=n.dataset.velView?n.dataset.velView:`${e.name}-child`,u=this._getLayoutIdForElement(n,t),c=this.createView(n,r,u);u&&!this._layoutIdToViewMap.has(u)&&this._layoutIdToViewMap.set(u,c),t.addView(c),t.notifyAboutViewAdded(c)})}}_handleRemoveView(e){this._plugins.forEach(t=>{if(!this._viewsPerPlugin.get(t.id))return;const s=this._getPluginViewById(t,e);s&&t.removeView(s)})}removeViewById(e,t){this._unassignViewFromPlugin(e,t),this._views=this._views.filter(i=>i.id!==e)}_unassignViewFromPlugin(e,t){const i=this._viewsPerPlugin.get(t);if(!i)return;const s=i.indexOf(e);s!==-1&&i.splice(s,1)}getViewById(e){return this._views.find(t=>t.id===e)}getViewsById(e){return this._views.filter(t=>e.includes(t.id))}_getPluginById(e){return this._plugins.find(t=>t.id===e)}_getPluginViewById(e,t){return this.getViewsForPlugin(e).find(i=>i.id===t)}destroy(e,t){if(!e){this._destroyAll(t);return}let i=[];if(e&&e.length>0){const s=this.getPluginByName(e);if(s){const r=(this._eventPluginsPerPlugin.get(s.id)||[]).map(u=>this._getPluginById(u)).filter(u=>typeof u<"u");i.push(s),i.push(...r)}}else i=this._plugins;requestAnimationFrame(()=>{i.forEach(s=>{this._destroyPlugin(s)}),requestAnimationFrame(()=>{t==null||t()})})}_destroyPlugin(e){const t=this.getViewsForPlugin(e);t.forEach(i=>{i.layoutId&&this._layoutIdToViewMap.delete(i.layoutId),i.destroy()}),this._views=this._views.filter(i=>!t.find(s=>s.id===i.id)),this._viewsPerPlugin.delete(e.id),this._plugins=this._plugins.filter(i=>i.id!==e.id)}_destroyAll(e){this._views.forEach(t=>t.destroy()),requestAnimationFrame(()=>{this._plugins=[],this._views=[],this._viewsPerPlugin.clear(),this._viewsToBeCreated=[],this._viewsToBeRemoved=[],this._viewsCreatedInPreviousFrame=[],this._layoutIdToViewMap.clear(),this._eventPluginsPerPlugin.clear(),e==null||e()})}reset(e,t){let i=[];if(e&&e.length>0){const s=this.getPluginByName(e);if(s){const r=(this._eventPluginsPerPlugin.get(s.id)||[]).map(u=>this._getPluginById(u)).filter(u=>typeof u<"u");i.push(s),i.push(...r)}}else i=this._plugins;requestAnimationFrame(()=>{i.forEach(s=>{this._resetPlugin(s)}),requestAnimationFrame(()=>{t==null||t()})})}_resetPlugin(e){const t=e.config,i=e.pluginFactory,s=e.internalBusEvent,n=!e.isRenderable(),r=this.getViewsForPlugin(e);r.forEach(u=>{u.layoutId&&this._layoutIdToViewMap.delete(u.layoutId),u.destroy()}),this._views=this._views.filter(u=>!r.find(c=>c.id===u.id)),this._viewsPerPlugin.delete(e.id),this._plugins=this._plugins.filter(u=>u.id!==e.id),n||requestAnimationFrame(()=>{this.createPlugin(i,this._eventBus,t).setInternalEventBus(s)})}queueNodeToBeCreated(e){this._viewsToBeCreated.push(e)}queueNodeToBeRemoved(e){this._viewsToBeRemoved.push(e)}notifyPluginAboutDataChange(e){const t=this._plugins.filter(i=>i.id===e.pluginId);!t||!t.length||t.forEach(i=>{i.notifyAboutDataChanged({dataName:e.dataName,dataValue:e.dataValue,viewName:e.viewName})})}getPlugins(){return this._plugins}getRenderablePlugins(){function e(t){return t.isRenderable()}return this._plugins.filter(e)}getPluginByName(e,t){return this._plugins.find(i=>t?i.pluginKey===t&&i.pluginName===e:i.pluginName===e)}getPluginsByName(e,t){return this._plugins.filter(i=>t?i.pluginKey===t&&i.pluginName===e:i.pluginName===e)}hasPlugin(e){return e.pluginName?!!this.getPluginByName(e.pluginName):!1}createPlugin(e,t,i={}){if(!e.pluginName)throw Error(`Plugin ${e.name} must contain a pluginName field`);let s=[];if(e.scope){const u=document.querySelectorAll(`[data-vel-plugin=${e.pluginName}][data-vel-view=${e.scope}]`);this._pluginNameToPluginFactoryMap.has(e.pluginName)||this._pluginNameToPluginFactoryMap.set(e.pluginName,e),this._pluginNameToPluginConfigMap.has(e.pluginName)||this._pluginNameToPluginConfigMap.set(e.pluginName,i),u?s=Array.from(u):s=[document.documentElement]}else s=[document.documentElement];const n=s.map(u=>{const c=u.dataset.velPluginKey,h=U(e,this,t,this._appEventBus,i,c);this._plugins.push(h);let d=[];u!==document.documentElement&&d.push(u);const _=u.querySelectorAll(`[data-vel-plugin=${h.pluginName}]`);d=[...d,..._];const g=d.filter(w=>{if(!w.parentElement)return!0;const V=this._getPluginNameForElement(w.parentElement);return!(V&&V.length>0)});return g.length&&g.forEach(w=>{const y=w.dataset.velView;if(!y)return;const V=this._createNewView(w,y,h);h.notifyAboutViewAdded(V)}),h});if(n&&n.length>0)return n[0];const r=U(e,this,t,this._appEventBus,i);return e.scope||console.log(`%c WARNING: The plugin "${r.pluginName}" is created but there are no elements using it on the page`,"background: #885500"),r}getViews(){return this._views}createView(e,t,i){const s=new vt(e,t,this,i);return this._views.push(s),this._viewsCreatedInPreviousFrame.push(s),s}assignViewToPlugin(e,t){this._viewsPerPlugin.has(t.id)||this._viewsPerPlugin.set(t.id,[]);const i=this._viewsPerPlugin.get(t.id);i.includes(e.id)||i.push(e.id)}getViewsForPlugin(e){const t=this._viewsPerPlugin.get(e.id);return t?t.map(s=>this._views.find(n=>n.id===s)).filter(s=>!!s):[]}getViewsByNameForPlugin(e,t){return this.getViewsForPlugin(e).filter(i=>i.name===t)}}class ge{constructor(e){a(this,"pluginApi");this.pluginApi=e.pluginApi}}class _e{constructor(e){a(this,"pluginApi");this.pluginApi=e.pluginApi}}class ie{constructor(){a(this,"_previousTime",0);a(this,"_registry");a(this,"_eventBus");a(this,"_appEventBus");this._eventBus=new C,this._appEventBus=new C,this._registry=new mt(this._appEventBus,this._eventBus),new Be(this._eventBus)}static create(){return new ie}addPlugin(e,t={}){this._registry.hasPlugin(e)||this._registry.createPlugin(e,this._eventBus,t)}reset(e,t){this._registry.reset(e,t)}destroy(e,t){this._registry.destroy(e,t)}getPlugin(e,t){let i=typeof e=="string"?e:e.pluginName;const s=this._registry.getPluginByName(i,t);if(!s)throw new Error(`You can't call getPlugin for ${i} with key: ${t} because it does not exist in your app`);return s.api}getPlugins(e,t){let i=typeof e=="string"?e:e.pluginName;const s=this._registry.getPluginsByName(i,t);if(s.length===0)throw new Error(`You can't call getPlugins for ${i} with key: ${t} because they don't exist in your app`);return s.map(n=>n.api)}onPluginEvent(e,t,i){const s=this._registry.getPluginByName(e.pluginName);s&&s.on(t,i)}removePluginEventListener(e,t,i){const s=this._registry.getPluginByName(e.pluginName);s&&s.removeListener(t,i)}run(){document.readyState==="loading"?document.addEventListener("DOMContentLoaded",this._start.bind(this)):this._start()}ready(e,t){this._appEventBus.subscribeToPluginReadyEvent(t,e)}_start(){this._setup(),requestAnimationFrame(this._tick.bind(this))}_setup(){this._listenToNativeEvents(),this._subscribeToEvents()}_listenToNativeEvents(){document.addEventListener("click",e=>{this._eventBus.emitEvent(P,{x:e.clientX,y:e.clientY,target:e.target})}),document.addEventListener("pointermove",e=>{this._eventBus.emitEvent(A,{x:e.clientX,y:e.clientY,target:e.target})}),document.addEventListener("pointerdown",e=>{this._eventBus.emitEvent(I,{x:e.clientX,y:e.clientY,target:e.target})}),document.addEventListener("pointerup",e=>{this._eventBus.emitEvent(N,{x:e.clientX,y:e.clientY,target:e.target})})}_tick(e){let t=(e-this._previousTime)/1e3;t>.016&&(t=1/60),this._previousTime=e,this._eventBus.reset(),this._subscribeToEvents(),this._read(),this._update(e,t),this._render(),requestAnimationFrame(this._tick.bind(this))}_subscribeToEvents(){this._eventBus.subscribeToEvent(z,this._onNodeAdded.bind(this)),this._eventBus.subscribeToEvent(W,this._onNodeRemoved.bind(this)),this._eventBus.subscribeToEvent(k,this._onDataChanged.bind(this)),this._registry.getPlugins().forEach(e=>{e.subscribeToEvents(this._eventBus)})}_onNodeAdded({node:e}){this._registry.queueNodeToBeCreated(e)}_onNodeRemoved({node:e}){this._registry.queueNodeToBeRemoved(e)}_onDataChanged(e){this._registry.notifyPluginAboutDataChange(e)}_read(){this._registry.getViews().forEach(e=>{e.read()})}_update(e,t){this._registry.update(),this._registry.getPlugins().slice().reverse().forEach(i=>{i.init()}),this._registry.getRenderablePlugins().forEach(i=>{i.update(e,t)}),this._registry.getViews().forEach(i=>{i.update(e,t)}),this._registry.getViews().forEach(i=>{i._updatePreviousRect()})}_render(){this._registry.getRenderablePlugins().forEach(e=>{e.render()}),this._registry.getViews().forEach(e=>{e.render()})}}function wt(){return ie.create()}class pe{constructor(e){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");this.props=e,this.previousX=e.previousX,this.previousY=e.previousY,this.x=e.x,this.y=e.y,this.pointerX=e.pointerX,this.pointerY=e.pointerY,this.width=e.width,this.height=e.height,this.distance=e.distance,this.view=e.view,this.isDragging=e.isDragging,this.target=e.target,this.directions=e.directions}}class fe extends L{constructor(){super(...arguments);a(this,"_pointerX",0);a(this,"_pointerY",0);a(this,"_initialPointer",new l(0,0));a(this,"_initialPointerPerView",new Map);a(this,"_pointerDownPerView",new Map);a(this,"_targetPerView",new Map);a(this,"_viewPointerPositionLog",new Map)}setup(){document.addEventListener("selectstart",this.onSelect.bind(this))}onSelect(t){this._isDragging&&t.preventDefault()}get _isDragging(){return Array.from(this._pointerDownPerView.values()).some(t=>!!t)}subscribeToEvents(t){t.subscribeToEvent(I,({x:i,y:s,target:n})=>{this._initialPointer=new l(i,s),this.getViews().forEach(r=>{this._pointerDownPerView.set(r.id,r.intersects(i,s)),this._targetPerView.set(r.id,n);const u=new l(i-r.position.x,s-r.position.y);this._pointerX=i,this._pointerY=s,this._initialPointerPerView.set(r.id,u)})}),t.subscribeToEvent(N,()=>{this.getViews().forEach(i=>{this._pointerDownPerView.get(i.id)&&this._initialPointerPerView.get(i.id)&&(this._pointerDownPerView.set(i.id,!1),this._emitEvent(i,[]))})}),t.subscribeToEvent(A,({x:i,y:s})=>{this._pointerX=i,this._pointerY=s,this.getViews().forEach(n=>{if(this._pointerDownPerView.get(n.id)&&this._initialPointerPerView.get(n.id)){this._viewPointerPositionLog.has(n.id)||this._viewPointerPositionLog.set(n.id,[]);const r=new l(i,s),u=this._viewPointerPositionLog.get(n.id);u&&u.push(new l(i,s));const c=u&&u.length>=2?u[u.length-2]:r.clone(),h=this._calculateDirections(c,r);this._emitEvent(n,h)}})})}_emitEvent(t,i){const s=this._viewPointerPositionLog.get(t.id),n=s&&s.length>=2?s[s.length-2]:null,r=this._pointerX-this._initialPointerPerView.get(t.id).x,u=this._pointerY-this._initialPointerPerView.get(t.id).y,c=this._pointerX,h=this._pointerY,d=n?n.x-this._initialPointerPerView.get(t.id).x:r,_=n?n.y-this._initialPointerPerView.get(t.id).y:u,g=this._pointerY-this._initialPointer.y,w=this._pointerX-this._initialPointer.x,y=le(this._initialPointer,{x:this._pointerX,y:this._pointerY}),V=this._targetPerView.get(t.id);if(!V||!t.hasElement(V))return;const E=this._pointerDownPerView.get(t.id)===!0;E||this._viewPointerPositionLog.clear();const se={view:t,target:V,previousX:d,previousY:_,x:r,y:u,pointerX:c,pointerY:h,distance:y,width:w,height:g,isDragging:E,directions:i};this.emit(pe,se)}_calculateDirections(t,i){const s={up:l.sub(new l(t.x,t.y-1),t),down:l.sub(new l(t.x,t.y+1),t),left:l.sub(new l(t.x-1,t.y),t),right:l.sub(new l(t.x+1,t.y),t)},n=l.sub(i,t).unitVector;return[{direction:"up",projection:n.dot(s.up)},{direction:"down",projection:n.dot(s.down)},{direction:"left",projection:n.dot(s.left)},{direction:"right",projection:n.dot(s.right)}].filter(c=>c.projection>0).map(c=>c.direction)}}a(fe,"pluginName","DragEventPlugin");class ve{constructor(e){a(this,"view");a(this,"direction");this.props=e,this.view=e.view,this.direction=e.direction}}class me extends L{constructor(){super(...arguments);a(this,"_viewIsPointerDownMap",new Map);a(this,"_viewPointerPositionLog",new Map);a(this,"_targetPerView",new Map)}subscribeToEvents(t){t.subscribeToEvent(I,({x:i,y:s,target:n})=>{this.getViews().forEach(r=>{this._targetPerView.set(r.id,n),r.intersects(i,s)&&this._viewIsPointerDownMap.set(r.id,!0)})}),t.subscribeToEvent(A,({x:i,y:s})=>{this.getViews().forEach(n=>{if(!this._viewIsPointerDownMap.get(n.id))return;this._viewPointerPositionLog.has(n.id)||this._viewPointerPositionLog.set(n.id,[]),this._viewPointerPositionLog.get(n.id).push(new l(i,s))})}),t.subscribeToEvent(N,({x:i,y:s})=>{this.getViews().forEach(r=>{if(!this._viewIsPointerDownMap.get(r.id)||!this._viewPointerPositionLog.has(r.id))return;const u=new l(i,s),c=this._viewPointerPositionLog.get(r.id),h=c[c.length-2]||u.clone(),d=this._targetPerView.get(r.id),_=n(h,u);d&&r.hasElement(d)&&_.hasSwiped&&this.emit(ve,{view:r,direction:_.direction}),this._viewPointerPositionLog.set(r.id,[]),this._viewIsPointerDownMap.set(r.id,!1)});function n(r,u){const c={up:l.sub(new l(r.x,r.y-1),r),down:l.sub(new l(r.x,r.y+1),r),left:l.sub(new l(r.x-1,r.y),r),right:l.sub(new l(r.x+1,r.y),r)},h=l.sub(u,r).unitVector,d=["up","down","left","right"],_=[h.dot(c.up),h.dot(c.down),h.dot(c.left),h.dot(c.right)],g=Math.max(..._),w=_.indexOf(g),y=d[w],V=l.sub(u,r).magnitude;return{hasSwiped:h.dot(c[y])*V>30,direction:y}}})}}a(me,"pluginName","SwipeEventPlugin");class we{constructor(e){a(this,"view");this.props=e,this.view=e.view}}class ye extends L{subscribeToEvents(e){e.subscribeToEvent(P,({x:t,y:i,target:s})=>{this.getViews().forEach(n=>{const r=s,u=n.element===r||n.element.contains(r);n.intersects(t,i)&&u&&this.emit(we,{view:n})})})}}a(ye,"pluginName","ClickEventPlugin");function yt(o,e){const t=o.map(e),i=Math.min(...t),s=t.indexOf(i);return o[s]}const Vt=Object.freeze(Object.defineProperty({__proto__:null,clamp:q,distanceBetweenTwoPoints:le,minBy:yt,pointToViewProgress:ke,randomNumber:$e,remap:Oe,valueAtPercentage:De},Symbol.toStringTag,{value:"Module"})),Pt=Object.freeze(Object.defineProperty({__proto__:null,PointerClickEvent:P,PointerDownEvent:I,PointerMoveEvent:A,PointerUpEvent:N},Symbol.toStringTag,{value:"Module"}));f.ClickEvent=we,f.ClickEventPlugin=ye,f.DataChangedEvent=k,f.DragEvent=pe,f.DragEventPlugin=fe,f.EventBus=C,f.EventPlugin=L,f.Events=Pt,f.Plugin=oe,f.PluginContext=ue,f.SwipeEvent=ve,f.SwipeEventPlugin=me,f.Utils=Vt,f.createApp=wt,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})}); + `,r.style.pointerEvents="none",r.dataset.velRemoved="",document.body.appendChild(r);const u=this._registry.createView(r,e.name);return u.setAsTemporaryView(),u.styles.position="absolute",u.styles.left=`${t.left+s}px`,u.styles.top=`${t.top-n}px`,u.rotation.setDegrees(e.rotation.degrees,!1),u.scale.set({x:e.scale.x,y:e.scale.y},!1),u.size.set({width:e._localWidth,height:e._localHeight},!1),e._copyAnimatorsToAnotherView(u),e.onRemoveCallback&&u.onRemove(e.onRemoveCallback),u}onViewRemoved(e){}notifyAboutViewAdded(e){this.onViewAdded(e),this._invokeAddCallbacks(e)}_invokeAddCallbacks(e){var t,i,s;!((t=e.onAddCallbacks)!=null&&t.onInitialLoad)&&!this._initialized||((i=e.onAddCallbacks)==null||i.beforeEnter(e),!((s=e.onAddCallbacks)!=null&&s.afterRemoved)||!this._initialized?requestAnimationFrame(()=>{var n;(n=e.onAddCallbacks)==null||n.afterEnter(e)}):e.layoutId&&this._layoutIdViewMapWaitingToEnter.set(e.layoutId,e))}onViewAdded(e){}init(){!this._initialized&&this._isReady&&(this.setup(),this._initialized=!0)}setup(){}subscribeToEvents(e){}}class oe extends ae{isRenderable(){return!0}isInitialized(){return this._initialized}get initialized(){return this._initialized}update(e,t){}render(){}addView(e){e.setPluginId(this.id),super.addView(e)}}class L extends ae{isRenderable(){return!1}}class ue{constructor(e){a(this,"_plugin");this._plugin=e}get initialized(){return this._plugin.isInitialized()}get config(){return this._plugin.config}setup(e){this._plugin.setup=e}api(e){this._plugin._setApi(e)}update(e){this._plugin.update=e}render(e){this._plugin.render=e}getViews(e){return this._plugin.getViews(e)}getView(e){return this._plugin.getView(e)}getViewById(e){return this._plugin.getViewById(e)}useEventPlugin(e,t={}){return this._plugin.useEventPlugin(e,t)}emit(e,t){this._plugin.emit(e,t)}on(e,t){this._plugin.on(e,t)}onDataChanged(e){this._plugin.onDataChanged=e}onViewRemoved(e){this._plugin.onViewRemoved=e}onViewAdded(e){this._plugin.onViewAdded=e}subscribeToEvents(e){this._plugin.subscribeToEvents=e}}function U(o,e,t,i,s,n){if(Me(o))return new o(o,o.pluginName,e,t,i,s,n);const r=new oe(o,o.pluginName,e,t,i,s,n),u=new ue(r);return o(u),r}function Me(o){var e;return((e=o.prototype)==null?void 0:e.constructor.toString().indexOf("class "))===0}class l{constructor(e,t){a(this,"x");a(this,"y");this.x=e,this.y=t}get magnitudeSquared(){return this.x*this.x+this.y*this.y}get magnitude(){return Math.sqrt(this.x*this.x+this.y*this.y)}get unitVector(){const e=new l(0,0),t=this.magnitude;return t!==0&&(e.x=this.x/t,e.y=this.y/t),e}add(e){this.x+=e.x,this.y+=e.y}sub(e){this.x-=e.x,this.y-=e.y}scale(e){this.x*=e,this.y*=e}dot(e){return this.x*e.x+this.y*e.y}equals(e){return this.x===e.x&&this.y===e.y}clone(){return new l(this.x,this.y)}static scale(e,t){return new l(e.x*t,e.y*t)}static sub(e,t){return new l(e.x-t.x,e.y-t.y)}static add(e,t){return new l(e.x+t.x,e.y+t.y)}}function q(o,e,t){return Math.min(Math.max(o,e),t)}function $e(o,e){return Math.floor(Math.random()*(e-o+1)+o)}function le(o,e){const t=e.x-o.x,i=e.y-o.y;return Math.sqrt(t*t+i*i)}function De(o,e,t){return o+(e-o)*t}function p(o,e){const i=o-e;return Math.abs(i)<=.01}function Oe(o,e,t,i,s){return(o-e)/(t-e)*(s-i)+i}function ke(o,e,t,i){const s=e.getScroll(),n=e.position.x-s.x,r=e.position.y-s.y,u=o.x||n,h=o.y||r,c=Math.abs(n-u),d=Math.abs(r-h),g=Math.sqrt(c*c+d*d);let _=q(0,g/t,1);return typeof i>"u"?1-_:g<=i?1:(_=q((g-i)/t,0,1),1-_)}function w(o){let e=o.match(/^([\d.]+)([a-zA-Z%]*)$/);e||(e="0px".match(/^([\d.]+)([a-zA-Z%]*)$/));const t=parseFloat(e[1]),i=e[2];return{value:t,unit:i,valueWithUnit:o}}function ze(o,e,t=!1){if(o===e)return!0;if(o.length!==e.length)return!1;for(let i=0;iw(i)),t={value:0,unit:"",valueWithUnit:"0"};switch(e.length){case 1:return new x(e[0],e[0],e[0],e[0]);case 2:return new x(e[0],e[1],e[0],e[1]);case 3:return new x(e[0],e[1],e[2],e[1]);case 4:return new x(e[0],e[1],e[3],e[2]);default:return new x(t,t,t,t)}}function We(o,e){const t=r(o.topLeft,e),i=r(o.topRight,e),s=r(o.bottomLeft,e),n=r(o.bottomRight,e);return{v:{topLeft:t.v,topRight:i.v,bottomRight:n.v,bottomLeft:s.v},h:{topLeft:t.h,topRight:i.h,bottomRight:n.h,bottomLeft:s.h}};function r(u,h){if(u.unit==="%")return{h:w(`${u.value}%`),v:w(`${u.value}%`)};const c=u.value/h.width*100,d=u.value/h.height*100;return{h:w(`${c}%`),v:w(`${d}%`)}}}function ce(o,e){return p(o.topLeft.value,e.topLeft.value)&&p(o.topRight.value,e.topRight.value)&&p(o.bottomRight.value,e.bottomRight.value)&&p(o.bottomLeft.value,e.bottomLeft.value)}class Ue{constructor(e){a(this,"_value");this._value=e}get value(){return this._value}equals(e){return p(this.value,e.value)}}function qe(o){return new Ue(parseFloat(o))}class Ye{constructor(e,t){a(this,"_x");a(this,"_y");this._x=e,this._y=t}get value(){return new l(this._x,this._y)}}function Xe(o,e){const[t,i]=o.split(" "),s=w(t),n=w(i);return new Ye(s.value/e.width,n.value/e.height)}function je(o){const e=He(o),t=Ke(o);return{viewportOffset:{left:Math.round(e.left),top:Math.round(e.top),right:Math.round(e.right),bottom:Math.round(e.bottom)},pageOffset:{top:t.top,left:t.left},size:{width:o.offsetWidth,height:o.offsetHeight}}}function He(o){const e=o.getBoundingClientRect();return{left:e.left,top:e.top,right:e.right,bottom:e.bottom,width:e.width,height:e.height}}function Ke(o){let e=o,t=0,i=0;for(;e;)t+=e.offsetTop,i+=e.offsetLeft,e=e.offsetParent;return{top:t,left:i}}class Ge{constructor(e){a(this,"_element");a(this,"_rect");a(this,"_computedStyle");this._rect=je(e),this._computedStyle=getComputedStyle(e),this._element=e}read(e){switch(e){case"opacity":return this.opacity;case"borderRadius":return this.borderRadius}}get rect(){return this._rect}get opacity(){return qe(this._computedStyle.opacity)}get borderRadius(){return Y(this._computedStyle.borderRadius)}get origin(){return Xe(this._computedStyle.transformOrigin,this._rect.size)}get scroll(){let e=this._element,t=0,i=0;for(;e;)t+=e.scrollTop,i+=e.scrollLeft,e=e.offsetParent;return i+=window.scrollX,t+=window.scrollY,{y:t,x:i}}}function X(o){return new Ge(o)}function j(o,e){const t={set:(i,s,n)=>(typeof i[s]=="object"&&i[s]!==null?i[s]=j(n,e):(e(),i[s]=n),!0),get:(i,s)=>typeof i[s]=="object"&&i[s]!==null?j(i[s],e):i[s]};return new Proxy(o,t)}const B=.01,H={speed:15};class K{constructor(e){a(this,"name","dynamic");a(this,"_config");this._config=e}get config(){return this._config}}class Ze extends K{update({animatorProp:e,current:t,target:i,dt:s}){const n=l.sub(i,t),r=l.scale(n,this._config.speed);let u=l.add(t,l.scale(r,s));return this._shouldFinish(i,t,r)&&(u=i,requestAnimationFrame(()=>{e.callCompleteCallback()})),e.callUpdateCallback(),u}_shouldFinish(e,t,i){return l.sub(e,t).magnitude{e.callCompleteCallback()})),e.callUpdateCallback(),u}}class Qe extends K{update({animatorProp:e,current:t,target:i,dt:s}){return i.map((n,r)=>{const u=t[r],h=n.value===0?u.unit:n.unit,d=(n.value-u.value)*this._config.speed,g=u.value+d*s;let _=w(`${g}${h}`);return this._shouldFinish(n.value,u.value,d)&&(_=n,requestAnimationFrame(()=>{e.callCompleteCallback()})),e.callUpdateCallback(),_})}_shouldFinish(e,t,i){return Math.abs(e-t){e.animatorProp.callCompleteCallback()}),e.target}}const Z={stiffness:.5,damping:.75,speed:10},S=.01;class J{constructor(e){a(this,"name","spring");a(this,"_config");this._config=e}get config(){return this._config}}class et extends J{constructor(){super(...arguments);a(this,"_velocity",new l(0,0))}update({animatorProp:t,current:i,target:s,dt:n}){const r=l.scale(l.scale(l.sub(i,s),-1),this._config.stiffness);this._velocity=l.add(this._velocity,r),this._velocity=l.scale(this._velocity,this._config.damping);let u=l.add(i,l.scale(this._velocity,n*this._config.speed));return this._shouldFinish(s,i)&&(u=s,requestAnimationFrame(()=>{t.callCompleteCallback()})),u}_shouldFinish(t,i){return l.sub(t,i).magnitude{t.callCompleteCallback()})),u}}class it extends J{constructor(){super(...arguments);a(this,"_velocity",0)}update({animatorProp:t,current:i,target:s,dt:n}){return s.map((r,u)=>{const h=i[u],c=r.value===0?h.unit:r.unit,d=-(h.value-r.value)*this._config.stiffness;this._velocity+=d,this._velocity*=this._config.damping;const g=h.value+this._velocity*n*this._config.speed;let _=w(`${g}${c}`);return this._shouldFinish(r.value,h.value)&&(_=r,requestAnimationFrame(()=>{t.callCompleteCallback()})),_})}_shouldFinish(t,i){return Math.abs(t-i){e.callCompleteCallback()}),i):l.add(t,l.scale(l.sub(i,t),this._config.ease(n)))}}class rt extends ee{update({animatorProp:e,initial:t,target:i,ts:s}){this._startTime||(this._startTime=s);const n=Math.min(1,(s-this._startTime)/this._config.duration);return p(n,1)?(requestAnimationFrame(()=>{e.callCompleteCallback()}),i):t.map((r,u)=>{const h=i[u],c=h.value===0?r.unit:h.unit,d=r.value+this._config.ease(n)*(i[u].value-r.value);return w(`${d}${c}`)})}}class at extends ee{update({animatorProp:e,initial:t,target:i,ts:s}){this._startTime||(this._startTime=s);const n=Math.min(1,(s-this._startTime)/this._config.duration);return p(n,1)?(requestAnimationFrame(()=>{e.callCompleteCallback()}),i):t+(i-t)*this._config.ease(n)}}class te{createAnimatorByName(e,t){switch(e){case"instant":return this.createInstantAnimator();case"dynamic":return this.createDynamicAnimator(t);case"tween":return this.createTweenAnimator(t);case"spring":return this.createSpringAnimator(t)}return this.createInstantAnimator()}}class F extends te{createInstantAnimator(){return new G}createTweenAnimator(e){return new nt({...Q,...e})}createDynamicAnimator(e){return new Ze({...H,...e})}createSpringAnimator(e){return new et({...Z,...e})}}class ot extends te{createInstantAnimator(){return new G}createTweenAnimator(e){return new rt({...Q,...e})}createDynamicAnimator(e){return new Qe({...H,...e})}createSpringAnimator(e){return new it({...Z,...e})}}class de extends te{createInstantAnimator(){return new G}createDynamicAnimator(e){return new Je({...H,...e})}createTweenAnimator(e){return new at({...Q,...e})}createSpringAnimator(e){return new tt({...Z,...e})}}function T(o){return structuredClone(o)}class ut{constructor(e){a(this,"_viewProp");a(this,"_completeCallback");a(this,"_updateCallback");a(this,"_isAnimating");this._viewProp=e,this._isAnimating=!1}set(e,t){this._viewProp.setAnimator(e,t)}get name(){return this._viewProp.getAnimator().name}onComplete(e){this._completeCallback=e}get isAnimating(){return this._isAnimating}markAsAnimating(){this._isAnimating=!0}callCompleteCallback(){var e;(e=this._completeCallback)==null||e.call(this),this._isAnimating=!1}onUpdate(e){this._updateCallback=e}callUpdateCallback(){var e;(e=this._updateCallback)==null||e.call(this)}}class E{constructor(e,t,i){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 ut(this),this._animatorFactory=e,this._initialValue=T(t),this._previousValue=T(t),this._targetValue=T(t),this._currentValue=T(t),this._hasChanged=!1,this._previousRenderValue=void 0,this._view=i,this._animator=this._animatorFactory.createInstantAnimator()}get shouldRender(){return!0}get isAnimating(){return this.animator.isAnimating}getAnimator(){return this._animator}get animator(){return this._animatorProp}get _rect(){return this._view.rect}get _previousRect(){return this._view.previousRect}setAnimator(e,t){this._animator=this._animatorFactory.createAnimatorByName(e,t)}_setTarget(e,t=!0){var i,s;this._previousValue=T(this._currentValue),this._targetValue=e,t?((s=(i=this._animator).reset)==null||s.call(i),this.animator.markAsAnimating()):this._currentValue=e,this._hasChanged=!0}hasChanged(){return this._hasChanged}destroy(){this._hasChanged=!1}update(e,t){}}class lt extends E{constructor(){super(...arguments);a(this,"_invertedBorderRadius");a(this,"_forceStyleUpdateThisFrame",!1);a(this,"_updateWithScale",!1)}setFromElementPropValue(t){this._setTarget([t.value.topLeft,t.value.topRight,t.value.bottomRight,t.value.bottomLeft],!0)}enableUpdateWithScale(){this._updateWithScale=!0}disableUpdateWithScale(){this._updateWithScale=!1}get value(){return{topLeft:this._currentValue[0],topRight:this._currentValue[1],bottomRight:this._currentValue[2],bottomLeft:this._currentValue[3]}}get invertedBorderRadius(){return this._invertedBorderRadius}set(t,i=!0){let s;if(typeof t=="string"){const c=Y(t.trim());s={topLeft:c.value.topLeft.valueWithUnit,topRight:c.value.topRight.valueWithUnit,bottomRight:c.value.bottomRight.valueWithUnit,bottomLeft:c.value.bottomLeft.valueWithUnit}}else s=t;const n=s.topLeft?w(s.topLeft):this._currentValue[0],r=s.topRight?w(s.topRight):this._currentValue[1],u=s.bottomRight?w(s.bottomRight):this._currentValue[2],h=s.bottomLeft?w(s.bottomLeft):this._currentValue[3];this._setTarget([n,r,u,h],i)}reset(t=!0){this._setTarget(this._initialValue,t)}update(t,i){if(this._forceStyleUpdateThisFrame)this._hasChanged=!0,this._forceStyleUpdateThisFrame=!1;else if(this._view.scale.isAnimating&&this._updateWithScale)this._hasChanged=!0;else if(he(this._targetValue,this._currentValue)){this._hasChanged=!he(this._targetValue,this._initialValue);return}this._currentValue=this._animator.update({animatorProp:this._animatorProp,current:this._currentValue,target:this._targetValue,initial:this._previousValue,ts:t,dt:i}),this._updateWithScale&&this._applyScaleInverse()}applyScaleInverse(){this._updateWithScale&&(this._forceStyleUpdateThisFrame=!0)}_applyScaleInverse(){if(p(this._view.scale.x,1)&&p(this._view.scale.y,1))return;const t=this._rect.size.width*this._view.scale.x,i=this._rect.size.height*this._view.scale.y;this._invertedBorderRadius=We(Y(`${this._currentValue[0].valueWithUnit} ${this._currentValue[1].valueWithUnit} ${this._currentValue[2].valueWithUnit} ${this._currentValue[3].valueWithUnit}`).value,{width:t,height:i})}get shouldRender(){return this._hasChanged?this._previousRenderValue?!(ce(this.renderValue.v,this._previousRenderValue.v)&&ce(this.renderValue.h,this._previousRenderValue.h)):!0:!1}get renderValue(){return this.invertedBorderRadius?{v:{topLeft:this.invertedBorderRadius.v.topLeft,topRight:this.invertedBorderRadius.v.topRight,bottomLeft:this.invertedBorderRadius.v.bottomLeft,bottomRight:this.invertedBorderRadius.v.bottomRight},h:{topLeft:this.invertedBorderRadius.h.topLeft,topRight:this.invertedBorderRadius.h.topRight,bottomLeft:this.invertedBorderRadius.h.bottomLeft,bottomRight:this.invertedBorderRadius.h.bottomRight}}:{v:{topLeft:this.value.topLeft,topRight:this.value.topRight,bottomLeft:this.value.bottomLeft,bottomRight:this.value.bottomRight},h:{topLeft:this.value.topLeft,topRight:this.value.topRight,bottomLeft:this.value.bottomLeft,bottomRight:this.value.bottomRight}}}projectStyles(){const t=this.renderValue,i=`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};`;return this._previousRenderValue=t,i}isTransform(){return!1}}class ht extends E{setFromElementPropValue(e){this._setTarget(e.value,!0)}get value(){return this._currentValue}set(e,t=!0){this._setTarget(e,t)}reset(e=!0){this._setTarget(1,e)}update(e,t){if(p(this._targetValue,this._currentValue)){this._hasChanged=!p(this._targetValue,this._initialValue);return}this._currentValue=this._animator.update({animatorProp:this._animatorProp,current:this._currentValue,target:this._targetValue,initial:this._previousValue,ts:e,dt:t})}get shouldRender(){return this._hasChanged?typeof this._previousRenderValue>"u"?!0:this.renderValue!==this._previousRenderValue:!1}get renderValue(){return this.value}projectStyles(){const e=this.renderValue,t=`opacity: ${e};`;return this._previousRenderValue=e,t}isTransform(){return!1}}class ct extends E{get x(){return this._currentValue.x}get y(){return this._currentValue.y}set(e){const i={...{x:this.x,y:this.y},...e};if(i.x<0||i.x>1){console.log(`%c WARNING: ${this._view.name}.origin.x property can only be a value from 0 to 1`,"background: #885500");return}if(i.y<0||i.y>1){console.log(`%c WARNING: ${this._view.name}.origin.y property can only be a value from 0 to 1`,"background: #885500");return}this._setTarget(new l(i.x,i.y),!1)}reset(){this._setTarget(this._initialValue,!1)}get shouldRender(){if(!this._hasChanged)return!1;if(!this._previousRenderValue)return!0;const e=this.renderValue;return!(p(e.x,this._previousRenderValue.x)&&p(e.y,this._previousRenderValue.y))}get renderValue(){return new l(this.x*100,this.y*100)}projectStyles(){const e=this.renderValue,t=`transform-origin: ${e.x}% ${e.y}%;`;return this._previousRenderValue=e,t}isTransform(){return!1}}class dt extends E{constructor(){super(...arguments);a(this,"_animateLayoutUpdateNextFrame",!1);a(this,"_parentScaleInverse",new l(1,1))}get _parentDiff(){let t=this._view._parent,i=0,s=0;if(t){const n=t.rect.pageOffset,r=t.getScroll(),u={left:t.previousRect.viewportOffset.left+r.x,top:t.previousRect.viewportOffset.top+r.y};i=u.left-n.left,s=u.top-n.top}return{parentDx:i,parentDy:s}}get x(){return this._currentValue.x+this._rect.pageOffset.left+this._parentDiff.parentDx}get y(){return this._currentValue.y+this._rect.pageOffset.top+this._parentDiff.parentDy}get initialX(){return this._rect.pageOffset.left}get initialY(){return this._rect.pageOffset.top}progressTo(t){const i=typeof t.x>"u"?this.initialX:t.x,s=typeof t.y>"u"?this.initialY:t.y,n=new l(i,s),r=new l(this.initialX,this.initialY),u=new l(this.x,this.y),h=l.sub(u,r),c=l.sub(n,r);return 1-l.sub(c,h).magnitude/c.magnitude}set(t,i=!0){const n={...{x:this.x,y:this.y},...t};this._setTarget(new l(n.x-this._rect.pageOffset.left,n.y-this._rect.pageOffset.top),i)}reset(t=!0){this._setTarget(new l(0,0),t)}update(t,i){if((this._view.isInverseEffectEnabled||this._view.isLayoutTransitionEnabled)&&!this._view.isTemporaryView&&this._runLayoutTransition(),this._view.isInverseEffectEnabled){const c=this._view._parent,d=c?c.scale.x:1,g=c?c.scale.y:1;this._parentScaleInverse=new l(1/d,1/g),this._parentScaleInverse.equals(new l(1,1))||(this._hasChanged=!0)}if(this._targetValue.x===this._currentValue.x&&this._targetValue.y===this._currentValue.y)return;const s=this._view._parent,n=s?s.scale.x:1,r=s?s.scale.y:1,u=s?s.scale._previousValue.x:1,h=s?s.scale._previousValue.y:1;this._currentValue=this._animator.update({animatorProp:this._animatorProp,current:new l(this._currentValue.x*n,this._currentValue.y*r),target:this._targetValue,initial:new l(this._previousValue.x*u,this._previousValue.y*h),ts:t,dt:i}),this._currentValue=new l(this._currentValue.x/n,this._currentValue.y/r)}_runLayoutTransition(){const t=!(this._targetValue.x===this._currentValue.x&&this._targetValue.y===this._currentValue.y),i=!(this._view.scale._targetValue.x===this._view.scale._currentValue.x&&this._view.scale._targetValue.y===this._view.scale._currentValue.y),s=t||i,n=this._rect.pageOffset.left-this._previousRect.pageOffset.left,r=this._rect.pageOffset.top-this._previousRect.pageOffset.top,u=this._previousRect.size.width/this._rect.size.width,h=this._previousRect.size.height/this._rect.size.height;let c=!1;if(n!==0||r!==0||!Number.isNaN(u)&&u!==1||!Number.isNaN(h)&&h!==1?c=!0:c=(()=>{const d=this._view._parents;for(let g=0;g"u")return!0;const t=this.renderValue;return!p(t,this._previousRenderValue)}get renderValue(){return this._currentValue}projectStyles(){const t=this.renderValue,i=`rotate(${t}${this._unit})`;return this._previousRenderValue=t,i}isTransform(){return!0}}class _t extends E{constructor(){super(...arguments);a(this,"_animateLayoutUpdateNextFrame",!1)}get x(){return this._currentValue.x}get y(){return this._currentValue.y}set(t,i=!0){const r={...{x:this._currentValue.x,y:this._currentValue.y},...typeof t=="number"?{x:t,y:t}:t};this._setTarget(new l(r.x,r.y),i)}setWithSize(t,i=!0){let s=this._currentValue.x,n=this._currentValue.y;t.width&&(s=t.width/this._rect.size.width),t.height&&(n=t.height/this._rect.size.height),!t.width&&t.height&&(s=n),!t.height&&t.width&&(n=s);const r={x:s,y:n};this._setTarget(new l(r.x,r.y),i)}reset(t=!0){this._setTarget(new l(1,1),t)}update(t,i){if((this._view.isInverseEffectEnabled||this._view.isLayoutTransitionEnabled)&&!this._view.isTemporaryView&&this._runLayoutTransition(),this._view.isInverseEffectEnabled){const s=this._view._parent,n=s?s.scale.x:1,r=s?s.scale.y:1;this._hasChanged=n!==1||r!==1}this._targetValue.x===this._currentValue.x&&this._targetValue.y===this._currentValue.y||(this._currentValue=this._animator.update({animatorProp:this._animatorProp,current:this._currentValue,target:this._targetValue,initial:new l(this._previousValue.x,this._previousValue.y),ts:t,dt:i}))}_runLayoutTransition(){const t=!(this._targetValue.x===this._currentValue.x&&this._targetValue.y===this._currentValue.y),i=this._previousRect.size.width/this._rect.size.width,s=this._previousRect.size.height/this._rect.size.height;let n=!1;if((!Number.isNaN(i)&&i!==1||!Number.isNaN(s)&&s!==1)&&(n=!0),n){if(this._currentValue.x!==1||this._currentValue.y!==1){const d=this._view.previousRect.size.width/this._view.rect.size.width,g=this._view.previousRect.size.height/this._view.rect.size.height;this._setTarget(new l(this._currentValue.x*d,this._currentValue.y*g),!1),t&&(this._animateLayoutUpdateNextFrame=!0);return}const r=this._previousRect.size.width/this._rect.size.width,u=this._previousRect.size.height/this._rect.size.height,h=r,c=u;this._view.viewProps.borderRadius.applyScaleInverse(),this._setTarget(new l(h,c),!1),this._animateLayoutUpdateNextFrame=!0}else this._animateLayoutUpdateNextFrame&&(this._setTarget(this._initialValue,!0),this._animateLayoutUpdateNextFrame=!1)}get shouldRender(){if(!this._hasChanged)return!1;if(!this._previousRenderValue)return!0;const t=this.renderValue;return!(p(t.x,this._previousRenderValue.x)&&p(t.y,this._previousRenderValue.y))}get renderValue(){const t=this._view._parent?this._view._parent.scale.x:1,i=this._view._parent?this._view._parent.scale.y:1,s=this._currentValue.x/t,n=this._currentValue.y/i;return new l(s,n)}projectStyles(){const t=this.renderValue,i=`scale3d(${t.x}, ${t.y}, 1)`;return this._previousRenderValue=t,i}isTransform(){return!0}}class pt extends E{get width(){return this._view.rect.size.width}get height(){return this._view.rect.size.height}get localWidth(){return this._currentValue.x}get localHeight(){return this._currentValue.y}get widthAfterScale(){const e=this._view.scale.x;return this.localWidth*e}get heightAfterScale(){const e=this._view.scale.y;return this.localHeight*e}get initialWidth(){return this._initialValue.x}get initialHeight(){return this._initialValue.y}set(e,t=!0){const s={...{width:this._currentValue.x,height:this._currentValue.y},...e};this._setTarget(new l(s.width,s.height),t)}setWidth(e,t=!0){const s={...{width:this._currentValue.x,height:this._currentValue.y},width:e};this._setTarget(new l(s.width,s.height),t)}setHeight(e,t=!0){const s={...{width:this._currentValue.x,height:this._currentValue.y},height:e};this._setTarget(new l(s.width,s.height),t)}reset(e=!0){this._setTarget(new l(this.initialWidth,this.initialHeight),e)}update(e,t){this._targetValue.x===this._currentValue.x&&this._targetValue.y===this._currentValue.y||(this._currentValue=this._animator.update({animatorProp:this._animatorProp,current:this._currentValue,target:this._targetValue,initial:this._previousValue,ts:e,dt:t}))}get shouldRender(){if(!this._hasChanged)return!1;if(!this._previousRenderValue)return!0;const e=this.renderValue;return!(p(e.x,this._previousRenderValue.x)&&p(e.y,this._previousRenderValue.y))}get renderValue(){return new l(this._currentValue.x,this._currentValue.y)}projectStyles(){const e=this.renderValue,t=`width: ${e.x}px; height: ${e.y}px;`;return this._previousRenderValue=e,t}isTransform(){return!1}}class ft{constructor(e){a(this,"_props",new Map);this._props.set("position",new dt(new F,new l(0,0),e)),this._props.set("scale",new _t(new F,new l(1,1),e)),this._props.set("rotation",new gt(new de,0,e)),this._props.set("size",new pt(new F,new l(e.rect.size.width,e.rect.size.height),e)),this._props.set("opacity",new ht(new de,e.elementReader.opacity.value,e)),this._props.set("borderRadius",new lt(new ot,[e.elementReader.borderRadius.value.topLeft,e.elementReader.borderRadius.value.topRight,e.elementReader.borderRadius.value.bottomRight,e.elementReader.borderRadius.value.bottomLeft],e)),this._props.set("origin",new ct(new F,e.elementReader.origin.value,e))}allProps(){return Array.from(this._props.values())}allPropNames(){return Array.from(this._props.keys())}getPropByName(e){return this._props.get(e)}get position(){return this._props.get("position")}get scale(){return this._props.get("scale")}get rotation(){return this._props.get("rotation")}get size(){return this._props.get("size")}get opacity(){return this._props.get("opacity")}get borderRadius(){return this._props.get("borderRadius")}get origin(){return this._props.get("origin")}}class vt{constructor(e,t,i,s){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,"_temporaryView");a(this,"_inverseEffect");a(this,"_renderNextTick");this.id=re(),this.name=t,this.element=e,this._elementReader=X(e),this._previousRect=this._elementReader.rect,this._viewProps=new ft(this),this._skipFirstRenderFrame=!0,this._layoutId=s,this._layoutTransition=!1,this._registry=i,this.element.dataset.velViewId=this.id,this._temporaryView=!1,this._inverseEffect=!1,this.styles=j(this.styles,()=>{this._renderNextTick=!0}),this._renderNextTick=!1}destroy(){this._viewProps.allProps().forEach(e=>e.destroy()),this.element.removeAttribute("data-vel-view-id"),this.element.removeAttribute("data-vel-plugin-id"),this._renderNextTick=!0}get elementReader(){return this._elementReader}setElement(e){this.element=e,this._elementReader=X(this.element),this.element.dataset.velViewId=this.id}get layoutId(){return this._layoutId}get position(){return this._viewProps.position}get scale(){return this._viewProps.scale}get _children(){return Array.from(this.element.children).map(t=>t.dataset.velViewId).filter(t=>t&&typeof t=="string").map(t=>this._registry.getViewById(t)).filter(t=>!!t)}get _parent(){var i;const e=this.element.parentElement;if(!e)return;const t=e.closest("[data-vel-view-id]");if((i=t==null?void 0:t.dataset)!=null&&i.velViewId)return this._registry.getViewById(t.dataset.velViewId)}get _parents(){var i;const e=[];let t=this.element.parentElement;if(!t)return e;for(t=t.closest("[data-vel-view-id]");t;){const s=t.dataset.velViewId;if(s){const n=this._registry.getViewById(s);n&&e.push(n)}t=(i=t.parentElement)==null?void 0:i.closest("[data-vel-view-id]")}return e}get rotation(){return this._viewProps.rotation}get size(){return this._viewProps.size}get _localWidth(){return this._viewProps.size.localWidth}get _localHeight(){return this._viewProps.size.localHeight}get opacity(){return this._viewProps.opacity}get borderRadius(){return this._viewProps.borderRadius}get origin(){return this._viewProps.origin}get data(){const e=this.element.dataset;return Object.keys(e).filter(s=>s.includes("velData")).map(s=>s.replace("velData","")).map(s=>`${s[0].toLowerCase()}${s.slice(1)}`).reduce((s,n)=>{const r=e[`velData${n[0].toUpperCase()}${n.slice(1)}`];return!s[n]&&r&&(s[n]=r),s},{})}get onAddCallbacks(){return this._onAddCallbacks}get onRemoveCallback(){return this._onRemoveCallback}get isLayoutTransitionEnabled(){return this._layoutTransition}get hasLayoutTransitionEnabledForParents(){return this._parents.some(e=>e.isLayoutTransitionEnabled)}get isInverseEffectEnabled(){return this._parents.some(e=>e._inverseEffect)}layoutTransition(e){this._layoutTransition=e,this.inverseEffect(e)}inverseEffect(e){this._inverseEffect=e,e&&this._children.forEach(t=>{if(t.position.animator.name==="instant"){const i=this.viewProps.position.getAnimator();t.position.setAnimator(i.name,i.config)}if(t.scale.animator.name==="instant"){const i=this.viewProps.scale.getAnimator();t.scale.setAnimator(i.name,i.config)}})}setAnimatorsFromParent(){let e=this._parent;for(;e&&!e._inverseEffect;)e=e._parent;if(e){if(this.position.animator.name==="instant"){const t=e.viewProps.position.getAnimator();this.position.setAnimator(t.name,t.config)}if(this.scale.animator.name==="instant"){const t=e.viewProps.scale.getAnimator();this.scale.setAnimator(t.name,t.config)}}}get _isRemoved(){return!this._registry.getViewById(this.id)}setPluginId(e){this.element.dataset.velPluginId=e}hasElement(e){return this.element.contains(e)}getScroll(){return this._elementReader.scroll}intersects(e,t){const i={x:this.rect.viewportOffset.left,y:this.rect.viewportOffset.top};return e>=i.x&&e<=i.x+this.size.width&&t>=i.y&&t<=i.y+this.size.height}overlapsWith(e){const t=e._localWidth*e.scale.x,i=e._localHeight*e.scale.y,s=this._localWidth*this.scale.x,n=this._localHeight*this.scale.y;return this.position.xe.position.x&&this.position.ye.position.y}distanceTo(e){const t=new l(this.position.x,this.position.y),i=new l(e.position.x,e.position.y);return l.sub(i,t).magnitude}read(){this._elementReader=X(this.element)}get rect(){return this._elementReader.rect}get previousRect(){return this._previousRect}update(e,t){this._viewProps.allProps().forEach(i=>i.update(e,t))}_updatePreviousRect(){this._previousRect=this._elementReader.rect}setAsTemporaryView(){this._temporaryView=!0}get isTemporaryView(){return this._temporaryView}get shouldRender(){return this._renderNextTick||this._viewProps.allProps().some(e=>e.shouldRender)}render(){if(!this.shouldRender)return;if(this._isRemoved&&this._skipFirstRenderFrame){this._skipFirstRenderFrame=!1;return}let e="";const t=this._viewProps.allProps(),i=t.filter(n=>n.isTransform()),s=t.filter(n=>!n.isTransform());if(i.some(n=>n.hasChanged())){const n=i.reduce((r,u,h)=>(r+=u.projectStyles(),h===i.length-1&&(r+=";"),r),"transform: ");e+=n}s.forEach(n=>{n.hasChanged()&&(e+=n.projectStyles())}),e+=this._getUserStyles(),this.element.style.cssText=e,this._renderNextTick=!1}_getUserStyles(){return Object.keys(this.styles).reduce((e,t)=>t?e+`${Le(t)}: ${this.styles[t]};`:e,"")}markAsAdded(){delete this.element.dataset.velProcessing}onAdd(e){this._onAddCallbacks=e}onRemove(e){this._onRemoveCallback=e}get viewProps(){return this._viewProps}getPropByName(e){return this._viewProps.getPropByName(e)}_copyAnimatorsToAnotherView(e){e.viewProps.allPropNames().forEach(t=>{var s,n;const i=(s=this.viewProps.getPropByName(t))==null?void 0:s.getAnimator();i&&((n=e.viewProps.getPropByName(t))==null||n.setAnimator(i.name,i.config))})}getChildren(e){const t=Array.from(this.element.children).filter(i=>{const s=i;return typeof s.dataset.velViewId<"u"&&s.dataset.velView===e}).map(i=>i.dataset.velViewId);return this._registry.getViewsById(t)}getChild(e){return this.getChildren(e)[0]}getParent(e){const t=this.element.parentElement;if(!t)return;const i=t.dataset.velViewId;if(i&&t.dataset.velView===e)return this._registry.getViewById(i)}}class mt{constructor(e,t){a(this,"_appEventBus");a(this,"_eventBus");a(this,"_plugins",[]);a(this,"_views",[]);a(this,"_viewsPerPlugin",new Map);a(this,"_viewsToBeCreated",[]);a(this,"_viewsToBeRemoved",[]);a(this,"_viewsCreatedInPreviousFrame",[]);a(this,"_layoutIdToViewMap",new Map);a(this,"_eventPluginsPerPlugin",new Map);a(this,"_pluginNameToPluginFactoryMap",new Map);a(this,"_pluginNameToPluginConfigMap",new Map);this._appEventBus=e,this._eventBus=t}update(){this._handleRemovedViews(),this._handleAddedViews()}associateEventPluginWithPlugin(e,t){let i=this._eventPluginsPerPlugin.get(e);i||(i=[],this._eventPluginsPerPlugin.set(e,i)),i.push(t)}_handleRemovedViews(){const e=this._viewsToBeRemoved.filter(t=>t.dataset.velViewId);e.length&&(e.forEach(t=>{const i=t.dataset.velViewId;i&&this._handleRemoveView(i)}),this._viewsToBeRemoved=[])}_getPluginNameForElement(e){const t=e.dataset.velPlugin;if(t&&t.length>0)return t;const i=e.closest("[data-vel-plugin]");if(i)return i.dataset.velPlugin}_getPluginIdForElement(e){const t=this._getPluginNameForElement(e);if(!t)return;const i=e.closest("[data-vel-plugin-id]");if(i)return i.dataset.velPluginId;const s=this.getPluginByName(t);if(s)return s.id}_isScopedElement(e){const t=this._getPluginNameForElement(e);if(!t)return!1;const i=this._pluginNameToPluginFactoryMap.get(t),s=i==null?void 0:i.scope;return e.dataset.velView===s}_handleAddedViews(){this._viewsCreatedInPreviousFrame.forEach(s=>{s.markAsAdded()}),this._viewsCreatedInPreviousFrame=[];const e=this._viewsToBeCreated.filter(s=>this._isScopedElement(s)),t=this._viewsToBeCreated.filter(s=>!this._isScopedElement(s));this._viewsToBeCreated=[],e.forEach(s=>{const n=this._getPluginNameForElement(s),r=this._pluginNameToPluginFactoryMap.get(n),u=this._pluginNameToPluginConfigMap.get(n),h=s.dataset.velPluginKey,c=U(r,this,this._eventBus,this._appEventBus,u,h);this._plugins.push(c);const d=s.dataset.velView,g=this._createNewView(s,d,c);g.isInverseEffectEnabled&&g.setAnimatorsFromParent(),c.notifyAboutViewAdded(g)});const i=t.filter(s=>!!this._getPluginIdForElement(s));i.length!==0&&i.forEach(s=>{const n=this._getPluginIdForElement(s),r=s.dataset.velView;if(!r||!n)return;const u=this._getPluginById(n);if(!u)return;const h=this._getLayoutIdForElement(s,u);let c;h&&this._layoutIdToViewMap.has(h)?(c=this._layoutIdToViewMap.get(h),c.setElement(s),c.setPluginId(u.id),this._createChildrenForView(c,u)):c=this._createNewView(s,r,u),c.isInverseEffectEnabled&&c.setAnimatorsFromParent(),u.notifyAboutViewAdded(c)})}_getLayoutIdForElement(e,t){const i=e.dataset.velLayoutId;if(i)return`${i}-${t.id}`}_createNewView(e,t,i){const s=this._getLayoutIdForElement(e,i),n=this.createView(e,t,s);return i.addView(n),n.layoutId&&this._layoutIdToViewMap.set(n.layoutId,n),this._createChildrenForView(n,i),this._appEventBus.emitPluginReadyEvent(i.pluginName,i.api,!0),requestAnimationFrame(()=>{requestAnimationFrame(()=>{this._appEventBus.emitPluginReadyEvent(i.pluginName,i.api)})}),n}_createChildrenForView(e,t){const i=e.element.querySelectorAll("*");if(i.length){if(Array.from(i).some(s=>this._getPluginNameForElement(s)!==t.pluginName)){console.log(`%c WARNING: The plugin "${t.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 "${t.pluginName}"`,"background: #885500");return}Array.from(i).forEach(s=>{const n=s,r=n.dataset.velView?n.dataset.velView:`${e.name}-child`,u=this._getLayoutIdForElement(n,t),h=this.createView(n,r,u);u&&!this._layoutIdToViewMap.has(u)&&this._layoutIdToViewMap.set(u,h),t.addView(h),t.notifyAboutViewAdded(h)})}}_handleRemoveView(e){this._plugins.forEach(t=>{if(!this._viewsPerPlugin.get(t.id))return;const s=this._getPluginViewById(t,e);s&&t.removeView(s)})}removeViewById(e,t){this._unassignViewFromPlugin(e,t),this._views=this._views.filter(i=>i.id!==e)}_unassignViewFromPlugin(e,t){const i=this._viewsPerPlugin.get(t);if(!i)return;const s=i.indexOf(e);s!==-1&&i.splice(s,1)}getViewById(e){return this._views.find(t=>t.id===e)}getViewsById(e){return this._views.filter(t=>e.includes(t.id))}_getPluginById(e){return this._plugins.find(t=>t.id===e)}_getPluginViewById(e,t){return this.getViewsForPlugin(e).find(i=>i.id===t)}destroy(e,t){if(!e){this._destroyAll(t);return}let i=[];if(e&&e.length>0){const s=this.getPluginByName(e);if(s){const r=(this._eventPluginsPerPlugin.get(s.id)||[]).map(u=>this._getPluginById(u)).filter(u=>typeof u<"u");i.push(s),i.push(...r)}}else i=this._plugins;requestAnimationFrame(()=>{i.forEach(s=>{this._destroyPlugin(s)}),requestAnimationFrame(()=>{t==null||t()})})}_destroyPlugin(e){const t=this.getViewsForPlugin(e);t.forEach(i=>{i.layoutId&&this._layoutIdToViewMap.delete(i.layoutId),i.destroy()}),this._views=this._views.filter(i=>!t.find(s=>s.id===i.id)),this._viewsPerPlugin.delete(e.id),this._plugins=this._plugins.filter(i=>i.id!==e.id)}_destroyAll(e){this._views.forEach(t=>t.destroy()),requestAnimationFrame(()=>{this._plugins=[],this._views=[],this._viewsPerPlugin.clear(),this._viewsToBeCreated=[],this._viewsToBeRemoved=[],this._viewsCreatedInPreviousFrame=[],this._layoutIdToViewMap.clear(),this._eventPluginsPerPlugin.clear(),e==null||e()})}reset(e,t){let i=[];if(e&&e.length>0){const s=this.getPluginByName(e);if(s){const r=(this._eventPluginsPerPlugin.get(s.id)||[]).map(u=>this._getPluginById(u)).filter(u=>typeof u<"u");i.push(s),i.push(...r)}}else i=this._plugins;requestAnimationFrame(()=>{i.forEach(s=>{this._resetPlugin(s)}),requestAnimationFrame(()=>{t==null||t()})})}_resetPlugin(e){const t=e.config,i=e.pluginFactory,s=e.internalBusEvent,n=!e.isRenderable(),r=this.getViewsForPlugin(e);r.forEach(u=>{u.layoutId&&this._layoutIdToViewMap.delete(u.layoutId),u.destroy()}),this._views=this._views.filter(u=>!r.find(h=>h.id===u.id)),this._viewsPerPlugin.delete(e.id),this._plugins=this._plugins.filter(u=>u.id!==e.id),n||requestAnimationFrame(()=>{this.createPlugin(i,this._eventBus,t).setInternalEventBus(s)})}queueNodeToBeCreated(e){this._viewsToBeCreated.push(e)}queueNodeToBeRemoved(e){this._viewsToBeRemoved.push(e)}notifyPluginAboutDataChange(e){const t=this._plugins.filter(i=>i.id===e.pluginId);!t||!t.length||t.forEach(i=>{i.notifyAboutDataChanged({dataName:e.dataName,dataValue:e.dataValue,viewName:e.viewName})})}getPlugins(){return this._plugins}getRenderablePlugins(){function e(t){return t.isRenderable()}return this._plugins.filter(e)}getPluginByName(e,t){return this._plugins.find(i=>t?i.pluginKey===t&&i.pluginName===e:i.pluginName===e)}getPluginsByName(e,t){return this._plugins.filter(i=>t?i.pluginKey===t&&i.pluginName===e:i.pluginName===e)}hasPlugin(e){return e.pluginName?!!this.getPluginByName(e.pluginName):!1}createPlugin(e,t,i={},s=!1){if(!e.pluginName)throw Error(`Plugin ${e.name} must contain a pluginName field`);let n=[];if(e.scope){const h=s?`[data-vel-plugin=${e.pluginName}][data-vel-view=${e.scope}]:not([data-vel-plugin-id])`:`[data-vel-plugin=${e.pluginName}][data-vel-view=${e.scope}]`,c=document.querySelectorAll(h);this._pluginNameToPluginFactoryMap.has(e.pluginName)||this._pluginNameToPluginFactoryMap.set(e.pluginName,e),this._pluginNameToPluginConfigMap.has(e.pluginName)||this._pluginNameToPluginConfigMap.set(e.pluginName,i),c?n=Array.from(c):n=[document.documentElement]}else n=[document.documentElement];const r=n.map(h=>{const c=h.dataset.velPluginKey,d=U(e,this,t,this._appEventBus,i,c);this._plugins.push(d);let g=[];h!==document.documentElement&&g.push(h);const _=h.querySelectorAll(`[data-vel-plugin=${d.pluginName}]`);g=[...g,..._];const V=g.filter(m=>{if(!m.parentElement)return!0;const P=this._getPluginNameForElement(m.parentElement);return!(P&&P.length>0)});return V.length&&V.forEach(m=>{const y=m.dataset.velView;if(!y)return;const P=this._createNewView(m,y,d);d.notifyAboutViewAdded(P)}),d});if(r&&r.length>0)return r[0];const u=U(e,this,t,this._appEventBus,i);return e.scope||console.log(`%c WARNING: The plugin "${u.pluginName}" is created but there are no elements using it on the page`,"background: #885500"),u}updatePlugin(e,t,i={}){return this.createPlugin(e,t,i,!0)}getViews(){return this._views}createView(e,t,i){const s=new vt(e,t,this,i);return this._views.push(s),this._viewsCreatedInPreviousFrame.push(s),s}assignViewToPlugin(e,t){this._viewsPerPlugin.has(t.id)||this._viewsPerPlugin.set(t.id,[]);const i=this._viewsPerPlugin.get(t.id);i.includes(e.id)||i.push(e.id)}getViewsForPlugin(e){const t=this._viewsPerPlugin.get(e.id);return t?t.map(s=>this._views.find(n=>n.id===s)).filter(s=>!!s):[]}getViewsByNameForPlugin(e,t){return this.getViewsForPlugin(e).filter(i=>i.name===t)}}class ge{constructor(e){a(this,"pluginApi");this.pluginApi=e.pluginApi}}class _e{constructor(e){a(this,"pluginApi");this.pluginApi=e.pluginApi}}class ie{constructor(){a(this,"_previousTime",0);a(this,"_registry");a(this,"_eventBus");a(this,"_appEventBus");this._eventBus=new C,this._appEventBus=new C,this._registry=new mt(this._appEventBus,this._eventBus),new Be(this._eventBus)}static create(){return new ie}addPlugin(e,t={}){this._registry.hasPlugin(e)||this._registry.createPlugin(e,this._eventBus,t)}updatePlugin(e,t={}){this._registry.hasPlugin(e)&&this._registry.updatePlugin(e,this._eventBus,t)}reset(e,t){this._registry.reset(e,t)}destroy(e,t){this._registry.destroy(e,t)}getPlugin(e,t){let i=typeof e=="string"?e:e.pluginName;const s=this._registry.getPluginByName(i,t);if(!s)throw new Error(`You can't call getPlugin for ${i} with key: ${t} because it does not exist in your app`);return s.api}getPlugins(e,t){let i=typeof e=="string"?e:e.pluginName;const s=this._registry.getPluginsByName(i,t);if(s.length===0)throw new Error(`You can't call getPlugins for ${i} with key: ${t} because they don't exist in your app`);return s.map(n=>n.api)}onPluginEvent(e,t,i,s){const n=this._registry.getPluginByName(e.pluginName,s);n&&n.on(t,i)}removePluginEventListener(e,t,i){const s=this._registry.getPluginByName(e.pluginName);s&&s.removeListener(t,i)}run(){document.readyState==="loading"?document.addEventListener("DOMContentLoaded",this._start.bind(this)):this._start()}ready(e,t){this._appEventBus.subscribeToPluginReadyEvent(t,e)}_start(){this._setup(),requestAnimationFrame(this._tick.bind(this))}_setup(){this._listenToNativeEvents(),this._subscribeToEvents()}_listenToNativeEvents(){document.addEventListener("click",e=>{this._eventBus.emitEvent(b,{x:e.clientX,y:e.clientY,target:e.target})}),document.addEventListener("pointermove",e=>{this._eventBus.emitEvent(A,{x:e.clientX,y:e.clientY,target:e.target})}),document.addEventListener("pointerdown",e=>{this._eventBus.emitEvent(N,{x:e.clientX,y:e.clientY,target:e.target})}),document.addEventListener("pointerup",e=>{this._eventBus.emitEvent(I,{x:e.clientX,y:e.clientY,target:e.target})})}_tick(e){let t=(e-this._previousTime)/1e3;t>.016&&(t=1/60),this._previousTime=e,this._eventBus.reset(),this._subscribeToEvents(),this._read(),this._update(e,t),this._render(),requestAnimationFrame(this._tick.bind(this))}_subscribeToEvents(){this._eventBus.subscribeToEvent(z,this._onNodeAdded.bind(this)),this._eventBus.subscribeToEvent(W,this._onNodeRemoved.bind(this)),this._eventBus.subscribeToEvent(k,this._onDataChanged.bind(this)),this._registry.getPlugins().forEach(e=>{e.subscribeToEvents(this._eventBus)})}_onNodeAdded({node:e}){this._registry.queueNodeToBeCreated(e)}_onNodeRemoved({node:e}){this._registry.queueNodeToBeRemoved(e)}_onDataChanged(e){this._registry.notifyPluginAboutDataChange(e)}_read(){this._registry.getViews().forEach(e=>{e.read()})}_update(e,t){this._registry.update(),this._registry.getPlugins().slice().reverse().forEach(i=>{i.init()}),this._registry.getRenderablePlugins().forEach(i=>{i.update(e,t)}),this._registry.getViews().forEach(i=>{i.update(e,t)}),this._registry.getViews().forEach(i=>{i._updatePreviousRect()})}_render(){this._registry.getRenderablePlugins().forEach(e=>{e.render()}),this._registry.getViews().forEach(e=>{e.render()})}}function wt(){return ie.create()}class pe{constructor(e){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");this.props=e,this.previousX=e.previousX,this.previousY=e.previousY,this.x=e.x,this.y=e.y,this.pointerX=e.pointerX,this.pointerY=e.pointerY,this.width=e.width,this.height=e.height,this.distance=e.distance,this.view=e.view,this.isDragging=e.isDragging,this.target=e.target,this.directions=e.directions}}class fe extends L{constructor(){super(...arguments);a(this,"_pointerX",0);a(this,"_pointerY",0);a(this,"_initialPointer",new l(0,0));a(this,"_initialPointerPerView",new Map);a(this,"_pointerDownPerView",new Map);a(this,"_targetPerView",new Map);a(this,"_viewPointerPositionLog",new Map)}setup(){document.addEventListener("selectstart",this.onSelect.bind(this))}onSelect(t){this._isDragging&&t.preventDefault()}get _isDragging(){return Array.from(this._pointerDownPerView.values()).some(t=>!!t)}subscribeToEvents(t){t.subscribeToEvent(N,({x:i,y:s,target:n})=>{this._initialPointer=new l(i,s),this.getViews().forEach(r=>{this._pointerDownPerView.set(r.id,r.intersects(i,s)),this._targetPerView.set(r.id,n);const u=new l(i-r.position.x,s-r.position.y);this._pointerX=i,this._pointerY=s,this._initialPointerPerView.set(r.id,u)})}),t.subscribeToEvent(I,()=>{this.getViews().forEach(i=>{this._pointerDownPerView.get(i.id)&&this._initialPointerPerView.get(i.id)&&(this._pointerDownPerView.set(i.id,!1),this._emitEvent(i,[]))})}),t.subscribeToEvent(A,({x:i,y:s})=>{this._pointerX=i,this._pointerY=s,this.getViews().forEach(n=>{if(this._pointerDownPerView.get(n.id)&&this._initialPointerPerView.get(n.id)){this._viewPointerPositionLog.has(n.id)||this._viewPointerPositionLog.set(n.id,[]);const r=new l(i,s),u=this._viewPointerPositionLog.get(n.id);u&&u.push(new l(i,s));const h=u&&u.length>=2?u[u.length-2]:r.clone(),c=this._calculateDirections(h,r);this._emitEvent(n,c)}})})}_emitEvent(t,i){const s=this._viewPointerPositionLog.get(t.id),n=s&&s.length>=2?s[s.length-2]:null,r=this._pointerX-this._initialPointerPerView.get(t.id).x,u=this._pointerY-this._initialPointerPerView.get(t.id).y,h=this._pointerX,c=this._pointerY,d=n?n.x-this._initialPointerPerView.get(t.id).x:r,g=n?n.y-this._initialPointerPerView.get(t.id).y:u,_=this._pointerY-this._initialPointer.y,V=this._pointerX-this._initialPointer.x,m=le(this._initialPointer,{x:this._pointerX,y:this._pointerY}),y=this._targetPerView.get(t.id);if(!y||!t.hasElement(y))return;const P=this._pointerDownPerView.get(t.id)===!0;P||this._viewPointerPositionLog.clear();const se={view:t,target:y,previousX:d,previousY:g,x:r,y:u,pointerX:h,pointerY:c,distance:m,width:V,height:_,isDragging:P,directions:i};this.emit(pe,se)}_calculateDirections(t,i){const s={up:l.sub(new l(t.x,t.y-1),t),down:l.sub(new l(t.x,t.y+1),t),left:l.sub(new l(t.x-1,t.y),t),right:l.sub(new l(t.x+1,t.y),t)},n=l.sub(i,t).unitVector;return[{direction:"up",projection:n.dot(s.up)},{direction:"down",projection:n.dot(s.down)},{direction:"left",projection:n.dot(s.left)},{direction:"right",projection:n.dot(s.right)}].filter(h=>h.projection>0).map(h=>h.direction)}}a(fe,"pluginName","DragEventPlugin");class ve{constructor(e){a(this,"view");a(this,"direction");this.props=e,this.view=e.view,this.direction=e.direction}}class me extends L{constructor(){super(...arguments);a(this,"_viewIsPointerDownMap",new Map);a(this,"_viewPointerPositionLog",new Map);a(this,"_targetPerView",new Map)}subscribeToEvents(t){t.subscribeToEvent(N,({x:i,y:s,target:n})=>{this.getViews().forEach(r=>{this._targetPerView.set(r.id,n),r.intersects(i,s)&&this._viewIsPointerDownMap.set(r.id,!0)})}),t.subscribeToEvent(A,({x:i,y:s})=>{this.getViews().forEach(n=>{if(!this._viewIsPointerDownMap.get(n.id))return;this._viewPointerPositionLog.has(n.id)||this._viewPointerPositionLog.set(n.id,[]),this._viewPointerPositionLog.get(n.id).push(new l(i,s))})}),t.subscribeToEvent(I,({x:i,y:s})=>{this.getViews().forEach(r=>{if(!this._viewIsPointerDownMap.get(r.id)||!this._viewPointerPositionLog.has(r.id))return;const u=new l(i,s),h=this._viewPointerPositionLog.get(r.id),c=h[h.length-2]||u.clone(),d=this._targetPerView.get(r.id),g=n(c,u);d&&r.hasElement(d)&&g.hasSwiped&&this.emit(ve,{view:r,direction:g.direction}),this._viewPointerPositionLog.set(r.id,[]),this._viewIsPointerDownMap.set(r.id,!1)});function n(r,u){const h={up:l.sub(new l(r.x,r.y-1),r),down:l.sub(new l(r.x,r.y+1),r),left:l.sub(new l(r.x-1,r.y),r),right:l.sub(new l(r.x+1,r.y),r)},c=l.sub(u,r).unitVector,d=["up","down","left","right"],g=[c.dot(h.up),c.dot(h.down),c.dot(h.left),c.dot(h.right)],_=Math.max(...g),V=g.indexOf(_),m=d[V],y=l.sub(u,r).magnitude;return{hasSwiped:c.dot(h[m])*y>30,direction:m}}})}}a(me,"pluginName","SwipeEventPlugin");class we{constructor(e){a(this,"view");this.props=e,this.view=e.view}}class ye extends L{subscribeToEvents(e){e.subscribeToEvent(b,({x:t,y:i,target:s})=>{this.getViews().forEach(n=>{const r=s,u=n.element===r||n.element.contains(r);n.intersects(t,i)&&u&&this.emit(we,{view:n})})})}}a(ye,"pluginName","ClickEventPlugin");function yt(o,e){const t=o.map(e),i=Math.min(...t),s=t.indexOf(i);return o[s]}const Vt=Object.freeze(Object.defineProperty({__proto__:null,clamp:q,distanceBetweenTwoPoints:le,minBy:yt,pointToViewProgress:ke,randomNumber:$e,remap:Oe,valueAtPercentage:De},Symbol.toStringTag,{value:"Module"})),Pt=Object.freeze(Object.defineProperty({__proto__:null,PointerClickEvent:b,PointerDownEvent:N,PointerMoveEvent:A,PointerUpEvent:I},Symbol.toStringTag,{value:"Module"}));f.ClickEvent=we,f.ClickEventPlugin=ye,f.DataChangedEvent=k,f.DragEvent=pe,f.DragEventPlugin=fe,f.EventBus=C,f.EventPlugin=L,f.Events=Pt,f.Plugin=oe,f.PluginContext=ue,f.SwipeEvent=ve,f.SwipeEventPlugin=me,f.Utils=Vt,f.createApp=wt,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})}); diff --git a/package.json b/package.json index 25f4873..1791d45 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "veloxi", "author": "Taha Shashtari (taha@tahazsh.com)", - "version": "0.11.0", + "version": "0.12.0", "private": false, "type": "module", "main": "./dist/veloxi.min.js",