motion-dom 11.18.1 → 12.4.4-alpha.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/dist/cjs/index.js +73 -36
- package/dist/es/gestures/hover.mjs +11 -15
- package/dist/es/gestures/press/index.mjs +61 -20
- package/dist/es/utils/resolve-elements.mjs +1 -1
- package/dist/index.d.ts +3 -3
- package/package.json +3 -3
package/dist/cjs/index.js
CHANGED
|
@@ -309,7 +309,7 @@ function isDragActive() {
|
|
|
309
309
|
|
|
310
310
|
function resolveElements(elementOrSelector, scope, selectorCache) {
|
|
311
311
|
var _a;
|
|
312
|
-
if (elementOrSelector instanceof
|
|
312
|
+
if (elementOrSelector instanceof EventTarget) {
|
|
313
313
|
return [elementOrSelector];
|
|
314
314
|
}
|
|
315
315
|
else if (typeof elementOrSelector === "string") {
|
|
@@ -340,16 +340,8 @@ function setupGesture(elementOrSelector, options) {
|
|
|
340
340
|
return [elements, eventOptions, cancel];
|
|
341
341
|
}
|
|
342
342
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
* while a Motion gesture is active.
|
|
346
|
-
*/
|
|
347
|
-
function filterEvents$1(callback) {
|
|
348
|
-
return (event) => {
|
|
349
|
-
if (event.pointerType === "touch" || isDragActive())
|
|
350
|
-
return;
|
|
351
|
-
callback(event);
|
|
352
|
-
};
|
|
343
|
+
function isValidHover(event) {
|
|
344
|
+
return !(event.pointerType === "touch" || isDragActive());
|
|
353
345
|
}
|
|
354
346
|
/**
|
|
355
347
|
* Create a hover gesture. hover() is different to .addEventListener("pointerenter")
|
|
@@ -360,17 +352,21 @@ function filterEvents$1(callback) {
|
|
|
360
352
|
*/
|
|
361
353
|
function hover(elementOrSelector, onHoverStart, options = {}) {
|
|
362
354
|
const [elements, eventOptions, cancel] = setupGesture(elementOrSelector, options);
|
|
363
|
-
const onPointerEnter =
|
|
355
|
+
const onPointerEnter = (enterEvent) => {
|
|
356
|
+
if (!isValidHover(enterEvent))
|
|
357
|
+
return;
|
|
364
358
|
const { target } = enterEvent;
|
|
365
|
-
const onHoverEnd = onHoverStart(enterEvent);
|
|
359
|
+
const onHoverEnd = onHoverStart(target, enterEvent);
|
|
366
360
|
if (typeof onHoverEnd !== "function" || !target)
|
|
367
361
|
return;
|
|
368
|
-
const onPointerLeave =
|
|
362
|
+
const onPointerLeave = (leaveEvent) => {
|
|
363
|
+
if (!isValidHover(leaveEvent))
|
|
364
|
+
return;
|
|
369
365
|
onHoverEnd(leaveEvent);
|
|
370
366
|
target.removeEventListener("pointerleave", onPointerLeave);
|
|
371
|
-
}
|
|
367
|
+
};
|
|
372
368
|
target.addEventListener("pointerleave", onPointerLeave, eventOptions);
|
|
373
|
-
}
|
|
369
|
+
};
|
|
374
370
|
elements.forEach((element) => {
|
|
375
371
|
element.addEventListener("pointerenter", onPointerEnter, eventOptions);
|
|
376
372
|
});
|
|
@@ -488,46 +484,87 @@ function isValidPressEvent(event) {
|
|
|
488
484
|
*
|
|
489
485
|
* @public
|
|
490
486
|
*/
|
|
491
|
-
function press(
|
|
492
|
-
const [
|
|
487
|
+
function press(targetOrSelector, onPressStart, options = {}) {
|
|
488
|
+
const [targets, eventOptions, cancelEvents] = setupGesture(targetOrSelector, options);
|
|
493
489
|
const startPress = (startEvent) => {
|
|
494
|
-
const
|
|
495
|
-
if (!isValidPressEvent(startEvent) || isPressing.has(
|
|
490
|
+
const target = startEvent.currentTarget;
|
|
491
|
+
if (!target || !isValidPressEvent(startEvent) || isPressing.has(target))
|
|
496
492
|
return;
|
|
497
|
-
isPressing.add(
|
|
498
|
-
|
|
493
|
+
isPressing.add(target);
|
|
494
|
+
if (target.setPointerCapture && startEvent.pointerId !== undefined) {
|
|
495
|
+
try {
|
|
496
|
+
target.setPointerCapture(startEvent.pointerId);
|
|
497
|
+
}
|
|
498
|
+
catch (e) { }
|
|
499
|
+
}
|
|
500
|
+
const onPressEnd = onPressStart(target, startEvent);
|
|
499
501
|
const onPointerEnd = (endEvent, success) => {
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
if (
|
|
502
|
+
target.removeEventListener("pointerup", onPointerUp);
|
|
503
|
+
target.removeEventListener("pointercancel", onPointerCancel);
|
|
504
|
+
if (target.releasePointerCapture &&
|
|
505
|
+
endEvent.pointerId !== undefined) {
|
|
506
|
+
try {
|
|
507
|
+
target.releasePointerCapture(endEvent.pointerId);
|
|
508
|
+
}
|
|
509
|
+
catch (e) { }
|
|
510
|
+
}
|
|
511
|
+
if (!isValidPressEvent(endEvent) || !isPressing.has(target)) {
|
|
503
512
|
return;
|
|
504
513
|
}
|
|
505
|
-
isPressing.delete(
|
|
514
|
+
isPressing.delete(target);
|
|
506
515
|
if (typeof onPressEnd === "function") {
|
|
507
516
|
onPressEnd(endEvent, { success });
|
|
508
517
|
}
|
|
509
518
|
};
|
|
510
519
|
const onPointerUp = (upEvent) => {
|
|
511
|
-
|
|
512
|
-
|
|
520
|
+
const isOutside = !upEvent.isTrusted
|
|
521
|
+
? false
|
|
522
|
+
: checkOutside(upEvent, target instanceof Element
|
|
523
|
+
? target.getBoundingClientRect()
|
|
524
|
+
: {
|
|
525
|
+
left: 0,
|
|
526
|
+
top: 0,
|
|
527
|
+
right: window.innerWidth,
|
|
528
|
+
bottom: window.innerHeight,
|
|
529
|
+
});
|
|
530
|
+
if (isOutside) {
|
|
531
|
+
onPointerEnd(upEvent, false);
|
|
532
|
+
}
|
|
533
|
+
else {
|
|
534
|
+
onPointerEnd(upEvent, !(target instanceof Element) ||
|
|
535
|
+
isNodeOrChild(target, upEvent.target));
|
|
536
|
+
}
|
|
513
537
|
};
|
|
514
538
|
const onPointerCancel = (cancelEvent) => {
|
|
515
539
|
onPointerEnd(cancelEvent, false);
|
|
516
540
|
};
|
|
517
|
-
|
|
518
|
-
|
|
541
|
+
target.addEventListener("pointerup", onPointerUp, eventOptions);
|
|
542
|
+
target.addEventListener("pointercancel", onPointerCancel, eventOptions);
|
|
543
|
+
target.addEventListener("lostpointercapture", onPointerCancel, eventOptions);
|
|
519
544
|
};
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
545
|
+
targets.forEach((target) => {
|
|
546
|
+
target = options.useGlobalTarget ? window : target;
|
|
547
|
+
let canAddKeyboardAccessibility = false;
|
|
548
|
+
if (target instanceof HTMLElement) {
|
|
549
|
+
canAddKeyboardAccessibility = true;
|
|
550
|
+
if (!isElementKeyboardAccessible(target) &&
|
|
551
|
+
target.getAttribute("tabindex") === null) {
|
|
552
|
+
target.tabIndex = 0;
|
|
553
|
+
}
|
|
524
554
|
}
|
|
525
|
-
const target = options.useGlobalTarget ? window : element;
|
|
526
555
|
target.addEventListener("pointerdown", startPress, eventOptions);
|
|
527
|
-
|
|
556
|
+
if (canAddKeyboardAccessibility) {
|
|
557
|
+
target.addEventListener("focus", (event) => enableKeyboardPress(event, eventOptions), eventOptions);
|
|
558
|
+
}
|
|
528
559
|
});
|
|
529
560
|
return cancelEvents;
|
|
530
561
|
}
|
|
562
|
+
function checkOutside(event, rect) {
|
|
563
|
+
return (event.clientX < rect.left ||
|
|
564
|
+
event.clientX > rect.right ||
|
|
565
|
+
event.clientY < rect.top ||
|
|
566
|
+
event.clientY > rect.bottom);
|
|
567
|
+
}
|
|
531
568
|
|
|
532
569
|
const defaultEasing = "easeOut";
|
|
533
570
|
function applyGeneratorOptions(options) {
|
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
import { isDragActive } from './drag/state/is-active.mjs';
|
|
2
2
|
import { setupGesture } from './utils/setup.mjs';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* while a Motion gesture is active.
|
|
7
|
-
*/
|
|
8
|
-
function filterEvents(callback) {
|
|
9
|
-
return (event) => {
|
|
10
|
-
if (event.pointerType === "touch" || isDragActive())
|
|
11
|
-
return;
|
|
12
|
-
callback(event);
|
|
13
|
-
};
|
|
4
|
+
function isValidHover(event) {
|
|
5
|
+
return !(event.pointerType === "touch" || isDragActive());
|
|
14
6
|
}
|
|
15
7
|
/**
|
|
16
8
|
* Create a hover gesture. hover() is different to .addEventListener("pointerenter")
|
|
@@ -21,17 +13,21 @@ function filterEvents(callback) {
|
|
|
21
13
|
*/
|
|
22
14
|
function hover(elementOrSelector, onHoverStart, options = {}) {
|
|
23
15
|
const [elements, eventOptions, cancel] = setupGesture(elementOrSelector, options);
|
|
24
|
-
const onPointerEnter =
|
|
16
|
+
const onPointerEnter = (enterEvent) => {
|
|
17
|
+
if (!isValidHover(enterEvent))
|
|
18
|
+
return;
|
|
25
19
|
const { target } = enterEvent;
|
|
26
|
-
const onHoverEnd = onHoverStart(enterEvent);
|
|
20
|
+
const onHoverEnd = onHoverStart(target, enterEvent);
|
|
27
21
|
if (typeof onHoverEnd !== "function" || !target)
|
|
28
22
|
return;
|
|
29
|
-
const onPointerLeave =
|
|
23
|
+
const onPointerLeave = (leaveEvent) => {
|
|
24
|
+
if (!isValidHover(leaveEvent))
|
|
25
|
+
return;
|
|
30
26
|
onHoverEnd(leaveEvent);
|
|
31
27
|
target.removeEventListener("pointerleave", onPointerLeave);
|
|
32
|
-
}
|
|
28
|
+
};
|
|
33
29
|
target.addEventListener("pointerleave", onPointerLeave, eventOptions);
|
|
34
|
-
}
|
|
30
|
+
};
|
|
35
31
|
elements.forEach((element) => {
|
|
36
32
|
element.addEventListener("pointerenter", onPointerEnter, eventOptions);
|
|
37
33
|
});
|
|
@@ -32,45 +32,86 @@ function isValidPressEvent(event) {
|
|
|
32
32
|
*
|
|
33
33
|
* @public
|
|
34
34
|
*/
|
|
35
|
-
function press(
|
|
36
|
-
const [
|
|
35
|
+
function press(targetOrSelector, onPressStart, options = {}) {
|
|
36
|
+
const [targets, eventOptions, cancelEvents] = setupGesture(targetOrSelector, options);
|
|
37
37
|
const startPress = (startEvent) => {
|
|
38
|
-
const
|
|
39
|
-
if (!isValidPressEvent(startEvent) || isPressing.has(
|
|
38
|
+
const target = startEvent.currentTarget;
|
|
39
|
+
if (!target || !isValidPressEvent(startEvent) || isPressing.has(target))
|
|
40
40
|
return;
|
|
41
|
-
isPressing.add(
|
|
42
|
-
|
|
41
|
+
isPressing.add(target);
|
|
42
|
+
if (target.setPointerCapture && startEvent.pointerId !== undefined) {
|
|
43
|
+
try {
|
|
44
|
+
target.setPointerCapture(startEvent.pointerId);
|
|
45
|
+
}
|
|
46
|
+
catch (e) { }
|
|
47
|
+
}
|
|
48
|
+
const onPressEnd = onPressStart(target, startEvent);
|
|
43
49
|
const onPointerEnd = (endEvent, success) => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (
|
|
50
|
+
target.removeEventListener("pointerup", onPointerUp);
|
|
51
|
+
target.removeEventListener("pointercancel", onPointerCancel);
|
|
52
|
+
if (target.releasePointerCapture &&
|
|
53
|
+
endEvent.pointerId !== undefined) {
|
|
54
|
+
try {
|
|
55
|
+
target.releasePointerCapture(endEvent.pointerId);
|
|
56
|
+
}
|
|
57
|
+
catch (e) { }
|
|
58
|
+
}
|
|
59
|
+
if (!isValidPressEvent(endEvent) || !isPressing.has(target)) {
|
|
47
60
|
return;
|
|
48
61
|
}
|
|
49
|
-
isPressing.delete(
|
|
62
|
+
isPressing.delete(target);
|
|
50
63
|
if (typeof onPressEnd === "function") {
|
|
51
64
|
onPressEnd(endEvent, { success });
|
|
52
65
|
}
|
|
53
66
|
};
|
|
54
67
|
const onPointerUp = (upEvent) => {
|
|
55
|
-
|
|
56
|
-
|
|
68
|
+
const isOutside = !upEvent.isTrusted
|
|
69
|
+
? false
|
|
70
|
+
: checkOutside(upEvent, target instanceof Element
|
|
71
|
+
? target.getBoundingClientRect()
|
|
72
|
+
: {
|
|
73
|
+
left: 0,
|
|
74
|
+
top: 0,
|
|
75
|
+
right: window.innerWidth,
|
|
76
|
+
bottom: window.innerHeight,
|
|
77
|
+
});
|
|
78
|
+
if (isOutside) {
|
|
79
|
+
onPointerEnd(upEvent, false);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
onPointerEnd(upEvent, !(target instanceof Element) ||
|
|
83
|
+
isNodeOrChild(target, upEvent.target));
|
|
84
|
+
}
|
|
57
85
|
};
|
|
58
86
|
const onPointerCancel = (cancelEvent) => {
|
|
59
87
|
onPointerEnd(cancelEvent, false);
|
|
60
88
|
};
|
|
61
|
-
|
|
62
|
-
|
|
89
|
+
target.addEventListener("pointerup", onPointerUp, eventOptions);
|
|
90
|
+
target.addEventListener("pointercancel", onPointerCancel, eventOptions);
|
|
91
|
+
target.addEventListener("lostpointercapture", onPointerCancel, eventOptions);
|
|
63
92
|
};
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
93
|
+
targets.forEach((target) => {
|
|
94
|
+
target = options.useGlobalTarget ? window : target;
|
|
95
|
+
let canAddKeyboardAccessibility = false;
|
|
96
|
+
if (target instanceof HTMLElement) {
|
|
97
|
+
canAddKeyboardAccessibility = true;
|
|
98
|
+
if (!isElementKeyboardAccessible(target) &&
|
|
99
|
+
target.getAttribute("tabindex") === null) {
|
|
100
|
+
target.tabIndex = 0;
|
|
101
|
+
}
|
|
68
102
|
}
|
|
69
|
-
const target = options.useGlobalTarget ? window : element;
|
|
70
103
|
target.addEventListener("pointerdown", startPress, eventOptions);
|
|
71
|
-
|
|
104
|
+
if (canAddKeyboardAccessibility) {
|
|
105
|
+
target.addEventListener("focus", (event) => enableKeyboardPress(event, eventOptions), eventOptions);
|
|
106
|
+
}
|
|
72
107
|
});
|
|
73
108
|
return cancelEvents;
|
|
74
109
|
}
|
|
110
|
+
function checkOutside(event, rect) {
|
|
111
|
+
return (event.clientX < rect.left ||
|
|
112
|
+
event.clientX > rect.right ||
|
|
113
|
+
event.clientY < rect.top ||
|
|
114
|
+
event.clientY > rect.bottom);
|
|
115
|
+
}
|
|
75
116
|
|
|
76
117
|
export { press };
|
package/dist/index.d.ts
CHANGED
|
@@ -622,7 +622,7 @@ interface EventOptions {
|
|
|
622
622
|
*
|
|
623
623
|
* @public
|
|
624
624
|
*/
|
|
625
|
-
type OnHoverStartEvent = (event: PointerEvent) => void | OnHoverEndEvent;
|
|
625
|
+
type OnHoverStartEvent = (element: Element, event: PointerEvent) => void | OnHoverEndEvent;
|
|
626
626
|
/**
|
|
627
627
|
* A function to be called when a hover gesture ends.
|
|
628
628
|
*
|
|
@@ -642,7 +642,7 @@ interface PressGestureInfo {
|
|
|
642
642
|
success: boolean;
|
|
643
643
|
}
|
|
644
644
|
type OnPressEndEvent = (event: PointerEvent, info: PressGestureInfo) => void;
|
|
645
|
-
type OnPressStartEvent = (event: PointerEvent) => OnPressEndEvent | void;
|
|
645
|
+
type OnPressStartEvent = (element: Element, event: PointerEvent) => OnPressEndEvent | void;
|
|
646
646
|
|
|
647
647
|
interface PointerEventOptions extends EventOptions {
|
|
648
648
|
useGlobalTarget?: boolean;
|
|
@@ -666,7 +666,7 @@ interface PointerEventOptions extends EventOptions {
|
|
|
666
666
|
*
|
|
667
667
|
* @public
|
|
668
668
|
*/
|
|
669
|
-
declare function press(
|
|
669
|
+
declare function press(targetOrSelector: ElementOrSelector, onPressStart: OnPressStartEvent, options?: PointerEventOptions): VoidFunction;
|
|
670
670
|
|
|
671
671
|
declare const isBezierDefinition: (easing: Easing | Easing[]) => easing is BezierDefinition;
|
|
672
672
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "motion-dom",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.4.4-alpha.0",
|
|
4
4
|
"author": "Matt Perry",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "https://github.com/motiondivision/motion",
|
|
@@ -16,12 +16,12 @@
|
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"motion-utils": "^
|
|
19
|
+
"motion-utils": "^12.0.0"
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
22
|
"clean": "rm -rf types dist lib",
|
|
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": "c4e631cd3a25fd226e2409f07efa331b3567f840"
|
|
27
27
|
}
|