motion-dom 11.13.0-beta.0 → 11.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +9 -9
- package/dist/cjs/index.js +71 -16
- package/dist/es/gestures/drag/state/is-active.mjs +9 -0
- package/dist/es/gestures/drag/state/set-active.mjs +28 -0
- package/dist/es/gestures/hover.mjs +37 -17
- package/dist/es/index.mjs +2 -0
- package/dist/index.d.ts +50 -2
- package/lib/gestures/drag/state/is-active.js +8 -0
- package/lib/gestures/drag/state/is-active.js.map +1 -0
- package/lib/gestures/drag/state/set-active.js +26 -0
- package/lib/gestures/drag/state/set-active.js.map +1 -0
- package/lib/gestures/hover.js +37 -17
- package/lib/gestures/hover.js.map +1 -1
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/package.json +2 -2
- package/src/gestures/drag/state/is-active.ts +8 -0
- package/src/gestures/drag/state/set-active.ts +23 -0
- package/src/gestures/hover.ts +75 -18
- package/src/index.ts +3 -0
- package/types/gestures/drag/state/is-active.d.ts +5 -0
- package/types/gestures/drag/state/set-active.d.ts +1 -0
- package/types/gestures/hover.d.ts +41 -1
- package/types/index.d.ts +2 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
[36m
|
|
2
|
-
[1mlib/index.js[22m → [1mdist/cjs[22m...[39m
|
|
3
|
-
[32mcreated [1mdist/cjs[22m in [
|
|
4
|
-
[36m
|
|
5
|
-
[1mlib/index.js[22m → [1mdist/es[22m...[39m
|
|
6
|
-
[32mcreated [1mdist/es[22m in [
|
|
7
|
-
[36m
|
|
8
|
-
[1mtypes/index.d.ts[22m → [1mdist/index.d.ts[22m...[39m
|
|
9
|
-
[32mcreated [1mdist/index.d.ts[22m in [
|
|
1
|
+
[36m
|
|
2
|
+
[1mlib/index.js[22m → [1mdist/cjs[22m...[39m
|
|
3
|
+
[32mcreated [1mdist/cjs[22m in [1m22ms[22m[39m
|
|
4
|
+
[36m
|
|
5
|
+
[1mlib/index.js[22m → [1mdist/es[22m...[39m
|
|
6
|
+
[32mcreated [1mdist/es[22m in [1m11ms[22m[39m
|
|
7
|
+
[36m
|
|
8
|
+
[1mtypes/index.d.ts[22m → [1mdist/index.d.ts[22m...[39m
|
|
9
|
+
[32mcreated [1mdist/index.d.ts[22m in [1m18ms[22m[39m
|
package/dist/cjs/index.js
CHANGED
|
@@ -23,28 +23,83 @@ function resolveElements(elementOrSelector, scope, selectorCache) {
|
|
|
23
23
|
return Array.from(elementOrSelector);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
const isDragging = {
|
|
27
|
+
x: false,
|
|
28
|
+
y: false,
|
|
29
|
+
};
|
|
30
|
+
function isDragActive() {
|
|
31
|
+
return isDragging.x || isDragging.y;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Filter out events that are not pointer events, or are triggering
|
|
36
|
+
* while a Motion gesture is active.
|
|
37
|
+
*/
|
|
38
|
+
function filterEvents(callback) {
|
|
39
|
+
return (event) => {
|
|
40
|
+
if (event.pointerType === "touch" || isDragActive())
|
|
32
41
|
return;
|
|
42
|
+
callback(event);
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Create a hover gesture. hover() is different to .addEventListener("pointerenter")
|
|
47
|
+
* in that it has an easier syntax, filters out polyfilled touch events, interoperates
|
|
48
|
+
* with drag gestures, and automatically removes the "pointerennd" event listener when the hover ends.
|
|
49
|
+
*
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
function hover(elementOrSelector, onHoverStart, options = {}) {
|
|
53
|
+
const gestureAbortController = new AbortController();
|
|
54
|
+
const eventOptions = {
|
|
55
|
+
passive: true,
|
|
56
|
+
...options,
|
|
57
|
+
signal: gestureAbortController.signal,
|
|
58
|
+
};
|
|
59
|
+
const onPointerEnter = filterEvents((enterEvent) => {
|
|
33
60
|
const { target } = enterEvent;
|
|
34
61
|
const onHoverEnd = onHoverStart(enterEvent);
|
|
35
|
-
if (onHoverEnd
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
62
|
+
if (!onHoverEnd || !target)
|
|
63
|
+
return;
|
|
64
|
+
const onPointerLeave = filterEvents((leaveEvent) => {
|
|
65
|
+
onHoverEnd(leaveEvent);
|
|
66
|
+
target.removeEventListener("pointerleave", onPointerLeave);
|
|
67
|
+
});
|
|
68
|
+
target.addEventListener("pointerleave", onPointerLeave, eventOptions);
|
|
69
|
+
});
|
|
70
|
+
resolveElements(elementOrSelector).forEach((element) => {
|
|
71
|
+
element.addEventListener("pointerenter", onPointerEnter, eventOptions);
|
|
72
|
+
});
|
|
73
|
+
return () => gestureAbortController.abort();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function setDragLock(axis) {
|
|
77
|
+
if (axis === "x" || axis === "y") {
|
|
78
|
+
if (isDragging[axis]) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
isDragging[axis] = true;
|
|
83
|
+
return () => {
|
|
84
|
+
isDragging[axis] = false;
|
|
39
85
|
};
|
|
40
|
-
target.addEventListener("pointerleave", onPointerLeave, options);
|
|
41
86
|
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
if (isDragging.x || isDragging.y) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
isDragging.x = isDragging.y = true;
|
|
94
|
+
return () => {
|
|
95
|
+
isDragging.x = isDragging.y = false;
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
47
99
|
}
|
|
48
100
|
|
|
49
101
|
exports.hover = hover;
|
|
102
|
+
exports.isDragActive = isDragActive;
|
|
103
|
+
exports.isDragging = isDragging;
|
|
50
104
|
exports.resolveElements = resolveElements;
|
|
105
|
+
exports.setDragLock = setDragLock;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { isDragging } from './is-active.mjs';
|
|
2
|
+
|
|
3
|
+
function setDragLock(axis) {
|
|
4
|
+
if (axis === "x" || axis === "y") {
|
|
5
|
+
if (isDragging[axis]) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
isDragging[axis] = true;
|
|
10
|
+
return () => {
|
|
11
|
+
isDragging[axis] = false;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
if (isDragging.x || isDragging.y) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
isDragging.x = isDragging.y = true;
|
|
21
|
+
return () => {
|
|
22
|
+
isDragging.x = isDragging.y = false;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { setDragLock };
|
|
@@ -1,26 +1,46 @@
|
|
|
1
1
|
import { resolveElements } from '../utils/resolve-elements.mjs';
|
|
2
|
+
import { isDragActive } from './drag/state/is-active.mjs';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Filter out events that are not pointer events, or are triggering
|
|
6
|
+
* while a Motion gesture is active.
|
|
7
|
+
*/
|
|
8
|
+
function filterEvents(callback) {
|
|
9
|
+
return (event) => {
|
|
10
|
+
if (event.pointerType === "touch" || isDragActive())
|
|
9
11
|
return;
|
|
12
|
+
callback(event);
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Create a hover gesture. hover() is different to .addEventListener("pointerenter")
|
|
17
|
+
* in that it has an easier syntax, filters out polyfilled touch events, interoperates
|
|
18
|
+
* with drag gestures, and automatically removes the "pointerennd" event listener when the hover ends.
|
|
19
|
+
*
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
function hover(elementOrSelector, onHoverStart, options = {}) {
|
|
23
|
+
const gestureAbortController = new AbortController();
|
|
24
|
+
const eventOptions = {
|
|
25
|
+
passive: true,
|
|
26
|
+
...options,
|
|
27
|
+
signal: gestureAbortController.signal,
|
|
28
|
+
};
|
|
29
|
+
const onPointerEnter = filterEvents((enterEvent) => {
|
|
10
30
|
const { target } = enterEvent;
|
|
11
31
|
const onHoverEnd = onHoverStart(enterEvent);
|
|
12
|
-
if (onHoverEnd
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
element.addEventListener("pointerenter", onPointerEnter,
|
|
32
|
+
if (!onHoverEnd || !target)
|
|
33
|
+
return;
|
|
34
|
+
const onPointerLeave = filterEvents((leaveEvent) => {
|
|
35
|
+
onHoverEnd(leaveEvent);
|
|
36
|
+
target.removeEventListener("pointerleave", onPointerLeave);
|
|
37
|
+
});
|
|
38
|
+
target.addEventListener("pointerleave", onPointerLeave, eventOptions);
|
|
39
|
+
});
|
|
40
|
+
resolveElements(elementOrSelector).forEach((element) => {
|
|
41
|
+
element.addEventListener("pointerenter", onPointerEnter, eventOptions);
|
|
22
42
|
});
|
|
23
|
-
return () =>
|
|
43
|
+
return () => gestureAbortController.abort();
|
|
24
44
|
}
|
|
25
45
|
|
|
26
46
|
export { hover };
|
package/dist/es/index.mjs
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -11,8 +11,56 @@ interface SelectorCache {
|
|
|
11
11
|
}
|
|
12
12
|
declare function resolveElements(elementOrSelector: ElementOrSelector, scope?: AnimationScope, selectorCache?: SelectorCache): Element[];
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Options for the hover gesture.
|
|
16
|
+
*
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
interface HoverOptions {
|
|
20
|
+
/**
|
|
21
|
+
* Use passive event listeners. Doing so allows the browser to optimize
|
|
22
|
+
* scrolling performance by not allowing the use of `preventDefault()`.
|
|
23
|
+
*
|
|
24
|
+
* @default true
|
|
25
|
+
*/
|
|
26
|
+
passive?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Remove the event listener after the first event.
|
|
29
|
+
*
|
|
30
|
+
* @default false
|
|
31
|
+
*/
|
|
32
|
+
once?: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A function to be called when a hover gesture starts.
|
|
36
|
+
*
|
|
37
|
+
* This function can optionally return a function that will be called
|
|
38
|
+
* when the hover gesture ends.
|
|
39
|
+
*
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
14
42
|
type OnHoverStartEvent = (event: PointerEvent) => void | OnHoverEndEvent;
|
|
43
|
+
/**
|
|
44
|
+
* A function to be called when a hover gesture ends.
|
|
45
|
+
*
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
15
48
|
type OnHoverEndEvent = (event: PointerEvent) => void;
|
|
16
|
-
|
|
49
|
+
/**
|
|
50
|
+
* Create a hover gesture. hover() is different to .addEventListener("pointerenter")
|
|
51
|
+
* in that it has an easier syntax, filters out polyfilled touch events, interoperates
|
|
52
|
+
* with drag gestures, and automatically removes the "pointerennd" event listener when the hover ends.
|
|
53
|
+
*
|
|
54
|
+
* @public
|
|
55
|
+
*/
|
|
56
|
+
declare function hover(elementOrSelector: ElementOrSelector, onHoverStart: OnHoverStartEvent, options?: HoverOptions): () => void;
|
|
57
|
+
|
|
58
|
+
declare const isDragging: {
|
|
59
|
+
x: boolean;
|
|
60
|
+
y: boolean;
|
|
61
|
+
};
|
|
62
|
+
declare function isDragActive(): boolean;
|
|
63
|
+
|
|
64
|
+
declare function setDragLock(axis: boolean | "x" | "y" | "lockDirection"): (() => void) | null;
|
|
17
65
|
|
|
18
|
-
export { type AnimationScope, type ElementOrSelector, type OnHoverEndEvent, type OnHoverStartEvent, type SelectorCache, type WithQuerySelectorAll, hover, resolveElements };
|
|
66
|
+
export { type AnimationScope, type ElementOrSelector, type HoverOptions, type OnHoverEndEvent, type OnHoverStartEvent, type SelectorCache, type WithQuerySelectorAll, hover, isDragActive, isDragging, resolveElements, setDragLock };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-active.js","sourceRoot":"","sources":["../../../../src/gestures/drag/state/is-active.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG;IACtB,CAAC,EAAE,KAAK;IACR,CAAC,EAAE,KAAK;CACX,CAAA;AAED,MAAM,UAAU,YAAY;IACxB,OAAO,UAAU,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,CAAA;AACvC,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { isDragging } from "./is-active";
|
|
2
|
+
export function setDragLock(axis) {
|
|
3
|
+
if (axis === "x" || axis === "y") {
|
|
4
|
+
if (isDragging[axis]) {
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
7
|
+
else {
|
|
8
|
+
isDragging[axis] = true;
|
|
9
|
+
return () => {
|
|
10
|
+
isDragging[axis] = false;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
if (isDragging.x || isDragging.y) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
isDragging.x = isDragging.y = true;
|
|
20
|
+
return () => {
|
|
21
|
+
isDragging.x = isDragging.y = false;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=set-active.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set-active.js","sourceRoot":"","sources":["../../../../src/gestures/drag/state/set-active.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC,MAAM,UAAU,WAAW,CAAC,IAA2C;IACnE,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;QAC/B,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YACnB,OAAO,IAAI,CAAA;QACf,CAAC;aAAM,CAAC;YACJ,UAAU,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;YACvB,OAAO,GAAG,EAAE;gBACR,UAAU,CAAC,IAAI,CAAC,GAAG,KAAK,CAAA;YAC5B,CAAC,CAAA;QACL,CAAC;IACL,CAAC;SAAM,CAAC;QACJ,IAAI,UAAU,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,EAAE,CAAC;YAC/B,OAAO,IAAI,CAAA;QACf,CAAC;aAAM,CAAC;YACJ,UAAU,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,GAAG,IAAI,CAAA;YAClC,OAAO,GAAG,EAAE;gBACR,UAAU,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,GAAG,KAAK,CAAA;YACvC,CAAC,CAAA;QACL,CAAC;IACL,CAAC;AACL,CAAC"}
|
package/lib/gestures/hover.js
CHANGED
|
@@ -1,24 +1,44 @@
|
|
|
1
1
|
import { resolveElements } from "../utils/resolve-elements";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import { isDragActive } from "./drag/state/is-active";
|
|
3
|
+
/**
|
|
4
|
+
* Filter out events that are not pointer events, or are triggering
|
|
5
|
+
* while a Motion gesture is active.
|
|
6
|
+
*/
|
|
7
|
+
function filterEvents(callback) {
|
|
8
|
+
return (event) => {
|
|
9
|
+
if (event.pointerType === "touch" || isDragActive())
|
|
8
10
|
return;
|
|
11
|
+
callback(event);
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Create a hover gesture. hover() is different to .addEventListener("pointerenter")
|
|
16
|
+
* in that it has an easier syntax, filters out polyfilled touch events, interoperates
|
|
17
|
+
* with drag gestures, and automatically removes the "pointerennd" event listener when the hover ends.
|
|
18
|
+
*
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
export function hover(elementOrSelector, onHoverStart, options = {}) {
|
|
22
|
+
const gestureAbortController = new AbortController();
|
|
23
|
+
const eventOptions = {
|
|
24
|
+
passive: true,
|
|
25
|
+
...options,
|
|
26
|
+
signal: gestureAbortController.signal,
|
|
27
|
+
};
|
|
28
|
+
const onPointerEnter = filterEvents((enterEvent) => {
|
|
9
29
|
const { target } = enterEvent;
|
|
10
30
|
const onHoverEnd = onHoverStart(enterEvent);
|
|
11
|
-
if (onHoverEnd
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
element.addEventListener("pointerenter", onPointerEnter,
|
|
31
|
+
if (!onHoverEnd || !target)
|
|
32
|
+
return;
|
|
33
|
+
const onPointerLeave = filterEvents((leaveEvent) => {
|
|
34
|
+
onHoverEnd(leaveEvent);
|
|
35
|
+
target.removeEventListener("pointerleave", onPointerLeave);
|
|
36
|
+
});
|
|
37
|
+
target.addEventListener("pointerleave", onPointerLeave, eventOptions);
|
|
38
|
+
});
|
|
39
|
+
resolveElements(elementOrSelector).forEach((element) => {
|
|
40
|
+
element.addEventListener("pointerenter", onPointerEnter, eventOptions);
|
|
21
41
|
});
|
|
22
|
-
return () =>
|
|
42
|
+
return () => gestureAbortController.abort();
|
|
23
43
|
}
|
|
24
44
|
//# sourceMappingURL=hover.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hover.js","sourceRoot":"","sources":["../../src/gestures/hover.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,eAAe,EAAE,MAAM,2BAA2B,CAAA;
|
|
1
|
+
{"version":3,"file":"hover.js","sourceRoot":"","sources":["../../src/gestures/hover.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAyCrD;;;GAGG;AACH,SAAS,YAAY,CAAC,QAA2B;IAC7C,OAAO,CAAC,KAAmB,EAAE,EAAE;QAC3B,IAAI,KAAK,CAAC,WAAW,KAAK,OAAO,IAAI,YAAY,EAAE;YAAE,OAAM;QAC3D,QAAQ,CAAC,KAAK,CAAC,CAAA;IACnB,CAAC,CAAA;AACL,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,KAAK,CACjB,iBAAoC,EACpC,YAA+B,EAC/B,UAAwB,EAAE;IAE1B,MAAM,sBAAsB,GAAG,IAAI,eAAe,EAAE,CAAA;IAEpD,MAAM,YAAY,GAAG;QACjB,OAAO,EAAE,IAAI;QACb,GAAG,OAAO;QACV,MAAM,EAAE,sBAAsB,CAAC,MAAM;KACxC,CAAA;IAED,MAAM,cAAc,GAAG,YAAY,CAAC,CAAC,UAAwB,EAAE,EAAE;QAC7D,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAA;QAC7B,MAAM,UAAU,GAAG,YAAY,CAAC,UAAU,CAAC,CAAA;QAE3C,IAAI,CAAC,UAAU,IAAI,CAAC,MAAM;YAAE,OAAM;QAElC,MAAM,cAAc,GAAG,YAAY,CAAC,CAAC,UAAwB,EAAE,EAAE;YAC7D,UAAU,CAAC,UAAU,CAAC,CAAA;YACtB,MAAM,CAAC,mBAAmB,CAAC,cAAc,EAAE,cAAc,CAAC,CAAA;QAC9D,CAAC,CAAC,CAAA;QAEF,MAAM,CAAC,gBAAgB,CAAC,cAAc,EAAE,cAAc,EAAE,YAAY,CAAC,CAAA;IACzE,CAAC,CAAC,CAAA;IAEF,eAAe,CAAC,iBAAiB,CAAC,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QACnD,OAAO,CAAC,gBAAgB,CAAC,cAAc,EAAE,cAAc,EAAE,YAAY,CAAC,CAAA;IAC1E,CAAC,CAAC,CAAA;IAEF,OAAO,GAAG,EAAE,CAAC,sBAAsB,CAAC,KAAK,EAAE,CAAA;AAC/C,CAAC"}
|
package/lib/index.js
CHANGED
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAEhC,cAAc,0BAA0B,CAAA;AACxC,cAAc,iCAAiC,CAAA;AAC/C,cAAc,kCAAkC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "motion-dom",
|
|
3
|
-
"version": "11.13.0
|
|
3
|
+
"version": "11.13.0",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"types": "./types/index.d.ts",
|
|
6
6
|
"module": "./lib/index.js",
|
|
@@ -23,5 +23,5 @@
|
|
|
23
23
|
"build": "yarn clean && tsc -p . && rollup -c",
|
|
24
24
|
"dev": "concurrently -c blue,red -n tsc,rollup --kill-others \"tsc --watch -p . --preserveWatchOutput\" \"rollup --config --watch --no-watch.clearScreen\""
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "c6ea900aecfec3e946a0f33db4672e0194f3048b"
|
|
27
27
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { isDragging } from "./is-active"
|
|
2
|
+
|
|
3
|
+
export function setDragLock(axis: boolean | "x" | "y" | "lockDirection") {
|
|
4
|
+
if (axis === "x" || axis === "y") {
|
|
5
|
+
if (isDragging[axis]) {
|
|
6
|
+
return null
|
|
7
|
+
} else {
|
|
8
|
+
isDragging[axis] = true
|
|
9
|
+
return () => {
|
|
10
|
+
isDragging[axis] = false
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
} else {
|
|
14
|
+
if (isDragging.x || isDragging.y) {
|
|
15
|
+
return null
|
|
16
|
+
} else {
|
|
17
|
+
isDragging.x = isDragging.y = true
|
|
18
|
+
return () => {
|
|
19
|
+
isDragging.x = isDragging.y = false
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
package/src/gestures/hover.ts
CHANGED
|
@@ -1,36 +1,93 @@
|
|
|
1
1
|
import { ElementOrSelector, resolveElements } from "../utils/resolve-elements"
|
|
2
|
+
import { isDragActive } from "./drag/state/is-active"
|
|
2
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Options for the hover gesture.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface HoverOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Use passive event listeners. Doing so allows the browser to optimize
|
|
12
|
+
* scrolling performance by not allowing the use of `preventDefault()`.
|
|
13
|
+
*
|
|
14
|
+
* @default true
|
|
15
|
+
*/
|
|
16
|
+
passive?: boolean
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Remove the event listener after the first event.
|
|
20
|
+
*
|
|
21
|
+
* @default false
|
|
22
|
+
*/
|
|
23
|
+
once?: boolean
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A function to be called when a hover gesture starts.
|
|
28
|
+
*
|
|
29
|
+
* This function can optionally return a function that will be called
|
|
30
|
+
* when the hover gesture ends.
|
|
31
|
+
*
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
3
34
|
export type OnHoverStartEvent = (event: PointerEvent) => void | OnHoverEndEvent
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A function to be called when a hover gesture ends.
|
|
38
|
+
*
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
4
41
|
export type OnHoverEndEvent = (event: PointerEvent) => void
|
|
5
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Filter out events that are not pointer events, or are triggering
|
|
45
|
+
* while a Motion gesture is active.
|
|
46
|
+
*/
|
|
47
|
+
function filterEvents(callback: OnHoverStartEvent) {
|
|
48
|
+
return (event: PointerEvent) => {
|
|
49
|
+
if (event.pointerType === "touch" || isDragActive()) return
|
|
50
|
+
callback(event)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Create a hover gesture. hover() is different to .addEventListener("pointerenter")
|
|
56
|
+
* in that it has an easier syntax, filters out polyfilled touch events, interoperates
|
|
57
|
+
* with drag gestures, and automatically removes the "pointerennd" event listener when the hover ends.
|
|
58
|
+
*
|
|
59
|
+
* @public
|
|
60
|
+
*/
|
|
6
61
|
export function hover(
|
|
7
62
|
elementOrSelector: ElementOrSelector,
|
|
8
|
-
onHoverStart: OnHoverStartEvent
|
|
63
|
+
onHoverStart: OnHoverStartEvent,
|
|
64
|
+
options: HoverOptions = {}
|
|
9
65
|
) {
|
|
10
|
-
const
|
|
11
|
-
const cancelGesture = new AbortController()
|
|
12
|
-
|
|
13
|
-
const options = { signal: cancelGesture.signal }
|
|
66
|
+
const gestureAbortController = new AbortController()
|
|
14
67
|
|
|
15
|
-
const
|
|
16
|
-
|
|
68
|
+
const eventOptions = {
|
|
69
|
+
passive: true,
|
|
70
|
+
...options,
|
|
71
|
+
signal: gestureAbortController.signal,
|
|
72
|
+
}
|
|
17
73
|
|
|
74
|
+
const onPointerEnter = filterEvents((enterEvent: PointerEvent) => {
|
|
18
75
|
const { target } = enterEvent
|
|
19
76
|
const onHoverEnd = onHoverStart(enterEvent)
|
|
20
77
|
|
|
21
|
-
if (onHoverEnd
|
|
22
|
-
const onPointerLeave = (leaveEvent: PointerEvent) => {
|
|
23
|
-
onHoverEnd(leaveEvent)
|
|
24
|
-
target.removeEventListener("pointerleave", onPointerLeave)
|
|
25
|
-
}
|
|
78
|
+
if (!onHoverEnd || !target) return
|
|
26
79
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
80
|
+
const onPointerLeave = filterEvents((leaveEvent: PointerEvent) => {
|
|
81
|
+
onHoverEnd(leaveEvent)
|
|
82
|
+
target.removeEventListener("pointerleave", onPointerLeave)
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
target.addEventListener("pointerleave", onPointerLeave, eventOptions)
|
|
86
|
+
})
|
|
30
87
|
|
|
31
|
-
|
|
32
|
-
element.addEventListener("pointerenter", onPointerEnter,
|
|
88
|
+
resolveElements(elementOrSelector).forEach((element) => {
|
|
89
|
+
element.addEventListener("pointerenter", onPointerEnter, eventOptions)
|
|
33
90
|
})
|
|
34
91
|
|
|
35
|
-
return () =>
|
|
92
|
+
return () => gestureAbortController.abort()
|
|
36
93
|
}
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function setDragLock(axis: boolean | "x" | "y" | "lockDirection"): (() => void) | null;
|
|
@@ -1,4 +1,44 @@
|
|
|
1
1
|
import { ElementOrSelector } from "../utils/resolve-elements";
|
|
2
|
+
/**
|
|
3
|
+
* Options for the hover gesture.
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export interface HoverOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Use passive event listeners. Doing so allows the browser to optimize
|
|
10
|
+
* scrolling performance by not allowing the use of `preventDefault()`.
|
|
11
|
+
*
|
|
12
|
+
* @default true
|
|
13
|
+
*/
|
|
14
|
+
passive?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Remove the event listener after the first event.
|
|
17
|
+
*
|
|
18
|
+
* @default false
|
|
19
|
+
*/
|
|
20
|
+
once?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A function to be called when a hover gesture starts.
|
|
24
|
+
*
|
|
25
|
+
* This function can optionally return a function that will be called
|
|
26
|
+
* when the hover gesture ends.
|
|
27
|
+
*
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
2
30
|
export type OnHoverStartEvent = (event: PointerEvent) => void | OnHoverEndEvent;
|
|
31
|
+
/**
|
|
32
|
+
* A function to be called when a hover gesture ends.
|
|
33
|
+
*
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
3
36
|
export type OnHoverEndEvent = (event: PointerEvent) => void;
|
|
4
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Create a hover gesture. hover() is different to .addEventListener("pointerenter")
|
|
39
|
+
* in that it has an easier syntax, filters out polyfilled touch events, interoperates
|
|
40
|
+
* with drag gestures, and automatically removes the "pointerennd" event listener when the hover ends.
|
|
41
|
+
*
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
export declare function hover(elementOrSelector: ElementOrSelector, onHoverStart: OnHoverStartEvent, options?: HoverOptions): () => void;
|
package/types/index.d.ts
CHANGED