Skip to content

Commit 21ab2b8

Browse files
committed
v0.7.0
1 parent b4f2a02 commit 21ab2b8

File tree

4 files changed

+88
-55
lines changed

4 files changed

+88
-55
lines changed

dist/veloxi.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ declare class App {
6565
getPlugin<TPluginApi extends PluginApi>(pluginFactory: PluginFactory<PluginConfig> | string, pluginKey?: string): TPluginApi;
6666
getPlugins<TPluginApi extends PluginApi>(pluginFactory: PluginFactory<PluginConfig> | string, pluginKey?: string): TPluginApi[];
6767
onPluginEvent<TEvent>(pluginFactory: PluginFactory, EventCtor: new (eventData: TEvent) => TEvent, listener: (eventData: TEvent) => void): void;
68+
removePluginEventListener<TEvent>(pluginFactory: PluginFactory, EventCtor: new (eventData: TEvent) => TEvent, listener: (eventData: TEvent) => void): void;
6869
run(): void;
6970
ready<TPluginApi extends PluginApi>(pluginName: string, callback: ReadyCallback<TPluginApi>): void;
7071
private _start;
@@ -329,7 +330,9 @@ export declare class EventBus {
329330
private _listeners;
330331
private _keyedListeners;
331332
subscribeToEvent<TEvent>(EventCtor: new (props: TEvent) => TEvent, listener: (props: TEvent) => void, key?: string): void;
333+
removeEventListener<TEvent>(EventCtor: new (props: TEvent) => TEvent, listener: (props: TEvent) => void, key?: string): void;
332334
private _subscribeToKeyedEvent;
335+
private _removeKeyedEventListener;
333336
emitEvent<TEvent>(EventCtor: new (props: TEvent) => TEvent, props: TEvent, key?: string): void;
334337
private _emitKeyedEvent;
335338
private _convertListener;
@@ -389,6 +392,7 @@ declare abstract class IPlugin<TConfig extends PluginConfig = PluginConfig, TPlu
389392
get internalBusEvent(): EventBus;
390393
emit<TEvent>(eventCtor: new (eventData: TEvent) => TEvent, eventData: TEvent): void;
391394
on<TEvent>(eventCtor: new (eventData: TEvent) => TEvent, listener: (eventData: TEvent) => void): void;
395+
removeListener<TEvent>(eventCtor: new (eventData: TEvent) => TEvent, listener: (eventData: TEvent) => void): void;
392396
useEventPlugin<TConfig extends PluginConfig = PluginConfig, TPluginApi extends PluginApi = PluginApi>(pluginFactory: PluginFactory<TConfig, TPluginApi>, config?: TConfig): EventPlugin<TConfig, TPluginApi>;
393397
notifyAboutDataChanged(data: ChangedData): void;
394398
onDataChanged(data: ChangedData): void;

dist/veloxi.js

+81-52
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ class Se {
8383
if (i && /data-vel-data-.+/gi.test(i)) {
8484
const n = t.target, r = n.dataset.velPluginId || "", u = n.dataset.velPlugin || "", h = n.dataset.velView || "", c = n.getAttribute(i);
8585
if (c && c !== t.oldValue) {
86-
const _ = Le(
86+
const g = Le(
8787
i.replace("data-vel-data-", "")
8888
);
8989
this._eventBus.emitEvent(fe, {
9090
pluginId: r,
9191
pluginName: u,
9292
viewName: h,
93-
dataName: _,
93+
dataName: g,
9494
dataValue: c
9595
});
9696
}
@@ -109,6 +109,9 @@ class he extends Fe {
109109
a(this, "_handler");
110110
this._handler = t;
111111
}
112+
getHandler() {
113+
return this._handler;
114+
}
112115
call(t) {
113116
this._handler(t);
114117
}
@@ -126,12 +129,31 @@ class k {
126129
let s = this._listeners.get(e);
127130
s || (s = [], this._listeners.set(e, s)), s.push(new he(t));
128131
}
132+
removeEventListener(e, t, i) {
133+
if (i) {
134+
this._removeKeyedEventListener(e, t, i);
135+
return;
136+
}
137+
let s = this._listeners.get(e);
138+
s && (s = s.filter(
139+
(n) => n.getHandler() !== t
140+
), this._listeners.set(e, s));
141+
}
129142
_subscribeToKeyedEvent(e, t, i) {
130143
let s = this._keyedListeners.get(e);
131144
s || (s = /* @__PURE__ */ new Map(), this._keyedListeners.set(e, s));
132145
let n = s.get(i);
133146
n || (n = [], s.set(i, n)), n.push(new he(t));
134147
}
148+
_removeKeyedEventListener(e, t, i) {
149+
let s = this._keyedListeners.get(e);
150+
if (!s)
151+
return;
152+
let n = s.get(i);
153+
n && (n = n.filter(
154+
(r) => r.getHandler() !== t
155+
), s.set(i, n));
156+
}
135157
emitEvent(e, t, i) {
136158
if (i) {
137159
this._emitKeyedEvent(e, t, i);
@@ -164,7 +186,7 @@ class k {
164186
return;
165187
}
166188
this.subscribeToEvent(
167-
ge,
189+
_e,
168190
this._convertListener(e),
169191
t
170192
);
@@ -179,7 +201,7 @@ class k {
179201
return;
180202
}
181203
this.emitEvent(
182-
ge,
204+
_e,
183205
t,
184206
e
185207
);
@@ -260,6 +282,9 @@ class ve {
260282
on(e, t) {
261283
this._internalEventBus.subscribeToEvent(e, t);
262284
}
285+
removeListener(e, t) {
286+
this._internalEventBus.removeEventListener(e, t);
287+
}
263288
useEventPlugin(e, t = {}) {
264289
const i = this._registry.createPlugin(
265290
e,
@@ -498,8 +523,8 @@ function ze(o, e, t, i, s) {
498523
return (o - e) / (t - e) * (s - i) + i;
499524
}
500525
function We(o, e, t) {
501-
const i = e.getScroll(), s = e.position.x - i.x, n = e.position.y - i.y, r = o.x || s, u = o.y || n, h = Math.abs(s - r), c = Math.abs(n - u), _ = Math.sqrt(h * h + c * c);
502-
return 1 - we(0, _ / t, 1);
526+
const i = e.getScroll(), s = e.position.x - i.x, n = e.position.y - i.y, r = o.x || s, u = o.y || n, h = Math.abs(s - r), c = Math.abs(n - u), g = Math.sqrt(h * h + c * c);
527+
return 1 - we(0, g / t, 1);
503528
}
504529
function m(o) {
505530
let e = o.match(/^([\d.]+)([a-zA-Z%]*)$/);
@@ -599,8 +624,8 @@ function qe(o, e) {
599624
h: m(`${u.value}%`),
600625
v: m(`${u.value}%`)
601626
};
602-
const c = u.value / h.width * 100, _ = u.value / h.height * 100;
603-
return { h: m(`${c}%`), v: m(`${_}%`) };
627+
const c = u.value / h.width * 100, g = u.value / h.height * 100;
628+
return { h: m(`${c}%`), v: m(`${g}%`) };
604629
}
605630
}
606631
function de(o, e) {
@@ -761,9 +786,9 @@ class et extends X {
761786
class tt extends X {
762787
update({ animatorProp: e, current: t, target: i, dt: s }) {
763788
return i.map((n, r) => {
764-
const u = t[r], h = n.value === 0 ? u.unit : n.unit, _ = (n.value - u.value) * this._config.speed, g = u.value + _ * s;
765-
let d = m(`${g}${h}`);
766-
return this._shouldFinish(n.value, u.value, _) && (d = n, requestAnimationFrame(() => {
789+
const u = t[r], h = n.value === 0 ? u.unit : n.unit, g = (n.value - u.value) * this._config.speed, _ = u.value + g * s;
790+
let d = m(`${_}${h}`);
791+
return this._shouldFinish(n.value, u.value, g) && (d = n, requestAnimationFrame(() => {
767792
e.callCompleteCallback();
768793
})), e.callUpdateCallback(), d;
769794
});
@@ -848,10 +873,10 @@ class nt extends K {
848873
}
849874
update({ animatorProp: t, current: i, target: s, dt: n }) {
850875
return s.map((r, u) => {
851-
const h = i[u], c = r.value === 0 ? h.unit : r.unit, _ = -(h.value - r.value) * this._config.stiffness;
852-
this._velocity += _, this._velocity *= this._config.damping;
853-
const g = h.value + this._velocity * n * this._config.speed;
854-
let d = m(`${g}${c}`);
876+
const h = i[u], c = r.value === 0 ? h.unit : r.unit, g = -(h.value - r.value) * this._config.stiffness;
877+
this._velocity += g, this._velocity *= this._config.damping;
878+
const _ = h.value + this._velocity * n * this._config.speed;
879+
let d = m(`${_}${c}`);
855880
return this._shouldFinish(r.value, h.value) && (d = r, requestAnimationFrame(() => {
856881
t.callCompleteCallback();
857882
})), d;
@@ -901,8 +926,8 @@ class ot extends Z {
901926
return p(n, 1) ? (requestAnimationFrame(() => {
902927
e.callCompleteCallback();
903928
}), i) : t.map((r, u) => {
904-
const h = i[u], c = h.value === 0 ? r.unit : h.unit, _ = r.value + this._config.ease(n) * (i[u].value - r.value);
905-
return m(`${_}${c}`);
929+
const h = i[u], c = h.value === 0 ? r.unit : h.unit, g = r.value + this._config.ease(n) * (i[u].value - r.value);
930+
return m(`${g}${c}`);
906931
});
907932
}
908933
}
@@ -961,7 +986,7 @@ class lt extends J {
961986
return new nt({ ...H, ...e });
962987
}
963988
}
964-
class _e extends J {
989+
class ge extends J {
965990
createInstantAnimator() {
966991
return new j();
967992
}
@@ -1240,7 +1265,7 @@ class dt extends V {
12401265
return !1;
12411266
}
12421267
}
1243-
class _t extends V {
1268+
class gt extends V {
12441269
get x() {
12451270
return this._currentValue.x;
12461271
}
@@ -1287,7 +1312,7 @@ class _t extends V {
12871312
return !1;
12881313
}
12891314
}
1290-
class gt extends V {
1315+
class _t extends V {
12911316
constructor() {
12921317
super(...arguments);
12931318
a(this, "_animateLayoutUpdateNextFrame", !1);
@@ -1335,8 +1360,8 @@ class gt extends V {
13351360
}
13361361
update(t, i) {
13371362
if ((this._view.isInverseEffectEnabled || this._view.isLayoutTransitionEnabled) && !this._view.isTemporaryView && this._runLayoutTransition(), this._view.isInverseEffectEnabled) {
1338-
const c = this._view._parent, _ = c ? c.scale.x : 1, g = c ? c.scale.y : 1;
1339-
this._parentScaleInverse = new l(1 / _, 1 / g), this._parentScaleInverse.equals(new l(1, 1)) || (this._hasChanged = !0);
1363+
const c = this._view._parent, g = c ? c.scale.x : 1, _ = c ? c.scale.y : 1;
1364+
this._parentScaleInverse = new l(1 / g, 1 / _), this._parentScaleInverse.equals(new l(1, 1)) || (this._hasChanged = !0);
13401365
}
13411366
if (this._targetValue.x === this._currentValue.x && this._targetValue.y === this._currentValue.y)
13421367
return;
@@ -1363,9 +1388,9 @@ class gt extends V {
13631388
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;
13641389
let c = !1;
13651390
if (n !== 0 || r !== 0 || !Number.isNaN(u) && u !== 1 || !Number.isNaN(h) && h !== 1 ? c = !0 : c = (() => {
1366-
const _ = this._view._parents;
1367-
for (let g = 0; g < _.length; g++) {
1368-
const d = _[g], f = d.previousRect.size.width / d.rect.size.width, v = d.previousRect.size.height / d.rect.size.height;
1391+
const g = this._view._parents;
1392+
for (let _ = 0; _ < g.length; _++) {
1393+
const d = g[_], f = d.previousRect.size.width / d.rect.size.width, v = d.previousRect.size.height / d.rect.size.height;
13691394
if (f !== 1 || v !== 1)
13701395
return !0;
13711396
}
@@ -1403,14 +1428,14 @@ class gt extends V {
14031428
return;
14041429
}
14051430
this._animateLayoutUpdateNextFrame = !0;
1406-
const _ = this._previousRect, g = this._rect, d = this._view._parent;
1431+
const g = this._previousRect, _ = this._rect, d = this._view._parent;
14071432
let f = 0, v = 0;
14081433
d && d.position.animator.name !== "instant" && (f = d.previousRect.viewportOffset.left - d.rect.viewportOffset.left), d && d.position.animator.name !== "instant" && (v = d.previousRect.viewportOffset.top - d.rect.viewportOffset.top);
14091434
let y = 1, F = 1;
14101435
d && d.scale.animator.name !== "instant" && (y = d.previousRect.size.width / d.rect.size.width, F = d.previousRect.size.height / d.rect.size.height);
1411-
const ye = d && d.position.animator.name !== "instant" ? d.previousRect.viewportOffset.left : 0, Ve = d && d.position.animator.name !== "instant" ? d.previousRect.viewportOffset.top : 0, ee = _.viewportOffset.left - ye, te = _.viewportOffset.top - Ve, Pe = ee / y - ee, be = te / F - te;
1412-
let Re = _.viewportOffset.left - g.viewportOffset.left - f + Pe;
1413-
const xe = _.viewportOffset.top - g.viewportOffset.top - v + be;
1436+
const ye = d && d.position.animator.name !== "instant" ? d.previousRect.viewportOffset.left : 0, Ve = d && d.position.animator.name !== "instant" ? d.previousRect.viewportOffset.top : 0, ee = g.viewportOffset.left - ye, te = g.viewportOffset.top - Ve, Pe = ee / y - ee, be = te / F - te;
1437+
let Re = g.viewportOffset.left - _.viewportOffset.left - f + Pe;
1438+
const xe = g.viewportOffset.top - _.viewportOffset.top - v + be;
14141439
this._setTarget(new l(Re, xe), !1);
14151440
} else
14161441
this._animateLayoutUpdateNextFrame && (this._setTarget(this._initialValue, !0), this._animateLayoutUpdateNextFrame = !1);
@@ -1532,9 +1557,9 @@ class ft extends V {
15321557
let n = !1;
15331558
if ((!Number.isNaN(i) && i !== 1 || !Number.isNaN(s) && s !== 1) && (n = !0), n) {
15341559
if (this._currentValue.x !== 1 || this._currentValue.y !== 1) {
1535-
const _ = this._view.previousRect.size.width / this._view.rect.size.width, g = this._view.previousRect.size.height / this._view.rect.size.height;
1560+
const g = this._view.previousRect.size.width / this._view.rect.size.width, _ = this._view.previousRect.size.height / this._view.rect.size.height;
15361561
this._setTarget(
1537-
new l(this._currentValue.x * _, this._currentValue.y * g),
1562+
new l(this._currentValue.x * g, this._currentValue.y * _),
15381563
!1
15391564
), t && (this._animateLayoutUpdateNextFrame = !0);
15401565
return;
@@ -1652,13 +1677,13 @@ class vt {
16521677
a(this, "_props", /* @__PURE__ */ new Map());
16531678
this._props.set(
16541679
"position",
1655-
new gt(new I(), new l(0, 0), e)
1680+
new _t(new I(), new l(0, 0), e)
16561681
), this._props.set(
16571682
"scale",
16581683
new ft(new I(), new l(1, 1), e)
16591684
), this._props.set(
16601685
"rotation",
1661-
new pt(new _e(), 0, e)
1686+
new pt(new ge(), 0, e)
16621687
), this._props.set(
16631688
"size",
16641689
new mt(
@@ -1669,7 +1694,7 @@ class vt {
16691694
), this._props.set(
16701695
"opacity",
16711696
new dt(
1672-
new _e(),
1697+
new ge(),
16731698
e.elementReader.opacity.value,
16741699
e
16751700
)
@@ -1687,7 +1712,7 @@ class vt {
16871712
)
16881713
), this._props.set(
16891714
"origin",
1690-
new _t(
1715+
new gt(
16911716
new I(),
16921717
e.elementReader.origin.value,
16931718
e
@@ -2041,8 +2066,8 @@ class yt {
20412066
h
20422067
);
20432068
this._plugins.push(c);
2044-
const _ = s.dataset.velView, g = this._createNewView(s, _, c);
2045-
g.isInverseEffectEnabled && g.setAnimatorsFromParent(), c.notifyAboutViewAdded(g);
2069+
const g = s.dataset.velView, _ = this._createNewView(s, g, c);
2070+
_.isInverseEffectEnabled && _.setAnimatorsFromParent(), c.notifyAboutViewAdded(_);
20462071
});
20472072
const i = t.filter((s) => !!this._getPluginIdForElement(s));
20482073
i.length !== 0 && i.forEach((s) => {
@@ -2244,13 +2269,13 @@ class yt {
22442269
h
22452270
);
22462271
this._plugins.push(c);
2247-
let _ = [];
2248-
u !== document.documentElement && _.push(u);
2249-
const g = u.querySelectorAll(
2272+
let g = [];
2273+
u !== document.documentElement && g.push(u);
2274+
const _ = u.querySelectorAll(
22502275
`[data-vel-plugin=${c.pluginName}]`
22512276
);
2252-
_ = [..._, ...g];
2253-
const d = _.filter((f) => {
2277+
g = [...g, ..._];
2278+
const d = g.filter((f) => {
22542279
if (!f.parentElement)
22552280
return !0;
22562281
const y = this._getPluginNameForElement(f.parentElement);
@@ -2300,7 +2325,7 @@ class yt {
23002325
);
23012326
}
23022327
}
2303-
class ge {
2328+
class _e {
23042329
constructor(e) {
23052330
a(this, "pluginApi");
23062331
this.pluginApi = e.pluginApi;
@@ -2354,6 +2379,10 @@ class Q {
23542379
const s = this._registry.getPluginByName(e.pluginName);
23552380
s && s.on(t, i);
23562381
}
2382+
removePluginEventListener(e, t, i) {
2383+
const s = this._registry.getPluginByName(e.pluginName);
2384+
s && s.removeListener(t, i);
2385+
}
23572386
run() {
23582387
document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", this._start.bind(this)) : this._start();
23592388
}
@@ -2514,7 +2543,7 @@ class Pt extends q {
25142543
});
25152544
}
25162545
_emitEvent(t, i) {
2517-
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 = n ? n.x - this._initialPointerPerView.get(t.id).x : r, c = n ? n.y - this._initialPointerPerView.get(t.id).y : u, _ = this._pointerY - this._initialPointer.y, g = this._pointerX - this._initialPointer.x, d = this._targetPerView.get(t.id);
2546+
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 = n ? n.x - this._initialPointerPerView.get(t.id).x : r, c = n ? n.y - this._initialPointerPerView.get(t.id).y : u, g = this._pointerY - this._initialPointer.y, _ = this._pointerX - this._initialPointer.x, d = this._targetPerView.get(t.id);
25182547
if (!d || !t.hasElement(d))
25192548
return;
25202549
const f = this._pointerDownPerView.get(t.id) === !0;
@@ -2526,8 +2555,8 @@ class Pt extends q {
25262555
previousY: c,
25272556
x: r,
25282557
y: u,
2529-
width: g,
2530-
height: _,
2558+
width: _,
2559+
height: g,
25312560
isDragging: f,
25322561
directions: i
25332562
};
@@ -2591,10 +2620,10 @@ class Rt extends q {
25912620
this.getViews().forEach((r) => {
25922621
if (!this._viewIsPointerDownMap.get(r.id) || !this._viewPointerPositionLog.has(r.id))
25932622
return;
2594-
const u = new l(i, s), h = this._viewPointerPositionLog.get(r.id), c = h[h.length - 2] || u.clone(), _ = this._targetPerView.get(r.id), g = n(c, u);
2595-
_ && r.hasElement(_) && g.hasSwiped && this.emit(bt, {
2623+
const u = new l(i, s), h = this._viewPointerPositionLog.get(r.id), c = h[h.length - 2] || u.clone(), g = this._targetPerView.get(r.id), _ = n(c, u);
2624+
g && r.hasElement(g) && _.hasSwiped && this.emit(bt, {
25962625
view: r,
2597-
direction: g.direction
2626+
direction: _.direction
25982627
}), this._viewPointerPositionLog.set(r.id, []), this._viewIsPointerDownMap.set(r.id, !1);
25992628
});
26002629
function n(r, u) {
@@ -2603,17 +2632,17 @@ class Rt extends q {
26032632
down: l.sub(new l(r.x, r.y + 1), r),
26042633
left: l.sub(new l(r.x - 1, r.y), r),
26052634
right: l.sub(new l(r.x + 1, r.y), r)
2606-
}, c = l.sub(u, r).unitVector, _ = [
2635+
}, c = l.sub(u, r).unitVector, g = [
26072636
"up",
26082637
"down",
26092638
"left",
26102639
"right"
2611-
], g = [
2640+
], _ = [
26122641
c.dot(h.up),
26132642
c.dot(h.down),
26142643
c.dot(h.left),
26152644
c.dot(h.right)
2616-
], d = Math.max(...g), f = g.indexOf(d), v = _[f], y = l.sub(u, r).magnitude;
2645+
], d = Math.max(..._), f = _.indexOf(d), v = g[f], y = l.sub(u, r).magnitude;
26172646
return {
26182647
hasSwiped: c.dot(h[v]) * y > 30,
26192648
direction: v

0 commit comments

Comments
 (0)