motion-dom 12.0.0 → 12.4.4
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 +62 -21
- package/dist/es/gestures/press/index.mjs +61 -20
- package/dist/es/utils/resolve-elements.mjs +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +2 -2
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") {
|
|
@@ -484,46 +484,87 @@ function isValidPressEvent(event) {
|
|
|
484
484
|
*
|
|
485
485
|
* @public
|
|
486
486
|
*/
|
|
487
|
-
function press(
|
|
488
|
-
const [
|
|
487
|
+
function press(targetOrSelector, onPressStart, options = {}) {
|
|
488
|
+
const [targets, eventOptions, cancelEvents] = setupGesture(targetOrSelector, options);
|
|
489
489
|
const startPress = (startEvent) => {
|
|
490
|
-
const
|
|
491
|
-
if (!isValidPressEvent(startEvent) || isPressing.has(
|
|
490
|
+
const target = startEvent.currentTarget;
|
|
491
|
+
if (!target || !isValidPressEvent(startEvent) || isPressing.has(target))
|
|
492
492
|
return;
|
|
493
|
-
isPressing.add(
|
|
494
|
-
|
|
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);
|
|
495
501
|
const onPointerEnd = (endEvent, success) => {
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
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)) {
|
|
499
512
|
return;
|
|
500
513
|
}
|
|
501
|
-
isPressing.delete(
|
|
514
|
+
isPressing.delete(target);
|
|
502
515
|
if (typeof onPressEnd === "function") {
|
|
503
516
|
onPressEnd(endEvent, { success });
|
|
504
517
|
}
|
|
505
518
|
};
|
|
506
519
|
const onPointerUp = (upEvent) => {
|
|
507
|
-
|
|
508
|
-
|
|
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
|
+
}
|
|
509
537
|
};
|
|
510
538
|
const onPointerCancel = (cancelEvent) => {
|
|
511
539
|
onPointerEnd(cancelEvent, false);
|
|
512
540
|
};
|
|
513
|
-
|
|
514
|
-
|
|
541
|
+
target.addEventListener("pointerup", onPointerUp, eventOptions);
|
|
542
|
+
target.addEventListener("pointercancel", onPointerCancel, eventOptions);
|
|
543
|
+
target.addEventListener("lostpointercapture", onPointerCancel, eventOptions);
|
|
515
544
|
};
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
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
|
+
}
|
|
520
554
|
}
|
|
521
|
-
const target = options.useGlobalTarget ? window : element;
|
|
522
555
|
target.addEventListener("pointerdown", startPress, eventOptions);
|
|
523
|
-
|
|
556
|
+
if (canAddKeyboardAccessibility) {
|
|
557
|
+
target.addEventListener("focus", (event) => enableKeyboardPress(event, eventOptions), eventOptions);
|
|
558
|
+
}
|
|
524
559
|
});
|
|
525
560
|
return cancelEvents;
|
|
526
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
|
+
}
|
|
527
568
|
|
|
528
569
|
const defaultEasing = "easeOut";
|
|
529
570
|
function applyGeneratorOptions(options) {
|
|
@@ -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
|
@@ -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": "12.
|
|
3
|
+
"version": "12.4.4",
|
|
4
4
|
"author": "Matt Perry",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "https://github.com/motiondivision/motion",
|
|
@@ -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": "7e307934d8fafe5bb918450f55cb925bc02b3e5d"
|
|
27
27
|
}
|