motion-dom 12.30.0 → 12.31.2
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 +66 -21
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/gestures/hover.mjs +45 -13
- package/dist/es/gestures/hover.mjs.map +1 -1
- package/dist/es/gestures/press/utils/is-keyboard-accessible.mjs +21 -9
- package/dist/es/gestures/press/utils/is-keyboard-accessible.mjs.map +1 -1
- package/dist/es/index.mjs +1 -1
- package/dist/index.d.ts +17 -9
- package/dist/motion-dom.dev.js +66 -21
- package/dist/motion-dom.js +1 -1
- package/package.json +2 -2
package/dist/cjs/index.js
CHANGED
|
@@ -4225,23 +4225,55 @@ function isValidHover(event) {
|
|
|
4225
4225
|
*/
|
|
4226
4226
|
function hover(elementOrSelector, onHoverStart, options = {}) {
|
|
4227
4227
|
const [elements, eventOptions, cancel] = setupGesture(elementOrSelector, options);
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
|
|
4232
|
-
const
|
|
4233
|
-
|
|
4234
|
-
|
|
4228
|
+
elements.forEach((element) => {
|
|
4229
|
+
let isPressed = false;
|
|
4230
|
+
let deferredHoverEnd = false;
|
|
4231
|
+
let hoverEndCallback;
|
|
4232
|
+
const removePointerLeave = () => {
|
|
4233
|
+
element.removeEventListener("pointerleave", onPointerLeave);
|
|
4234
|
+
};
|
|
4235
|
+
const endHover = (event) => {
|
|
4236
|
+
if (hoverEndCallback) {
|
|
4237
|
+
hoverEndCallback(event);
|
|
4238
|
+
hoverEndCallback = undefined;
|
|
4239
|
+
}
|
|
4240
|
+
removePointerLeave();
|
|
4241
|
+
};
|
|
4242
|
+
const onPointerUp = (event) => {
|
|
4243
|
+
isPressed = false;
|
|
4244
|
+
window.removeEventListener("pointerup", onPointerUp);
|
|
4245
|
+
window.removeEventListener("pointercancel", onPointerUp);
|
|
4246
|
+
if (deferredHoverEnd) {
|
|
4247
|
+
deferredHoverEnd = false;
|
|
4248
|
+
endHover(event);
|
|
4249
|
+
}
|
|
4250
|
+
};
|
|
4251
|
+
const onPointerDown = () => {
|
|
4252
|
+
isPressed = true;
|
|
4253
|
+
window.addEventListener("pointerup", onPointerUp, eventOptions);
|
|
4254
|
+
window.addEventListener("pointercancel", onPointerUp, eventOptions);
|
|
4255
|
+
};
|
|
4235
4256
|
const onPointerLeave = (leaveEvent) => {
|
|
4236
|
-
if (
|
|
4257
|
+
if (leaveEvent.pointerType === "touch")
|
|
4258
|
+
return;
|
|
4259
|
+
if (isPressed) {
|
|
4260
|
+
deferredHoverEnd = true;
|
|
4261
|
+
return;
|
|
4262
|
+
}
|
|
4263
|
+
endHover(leaveEvent);
|
|
4264
|
+
};
|
|
4265
|
+
const onPointerEnter = (enterEvent) => {
|
|
4266
|
+
if (!isValidHover(enterEvent))
|
|
4267
|
+
return;
|
|
4268
|
+
deferredHoverEnd = false;
|
|
4269
|
+
const onHoverEnd = onHoverStart(element, enterEvent);
|
|
4270
|
+
if (typeof onHoverEnd !== "function")
|
|
4237
4271
|
return;
|
|
4238
|
-
onHoverEnd
|
|
4239
|
-
|
|
4272
|
+
hoverEndCallback = onHoverEnd;
|
|
4273
|
+
element.addEventListener("pointerleave", onPointerLeave, eventOptions);
|
|
4240
4274
|
};
|
|
4241
|
-
target.addEventListener("pointerleave", onPointerLeave, eventOptions);
|
|
4242
|
-
};
|
|
4243
|
-
elements.forEach((element) => {
|
|
4244
4275
|
element.addEventListener("pointerenter", onPointerEnter, eventOptions);
|
|
4276
|
+
element.addEventListener("pointerdown", onPointerDown, eventOptions);
|
|
4245
4277
|
});
|
|
4246
4278
|
return cancel;
|
|
4247
4279
|
}
|
|
@@ -4282,7 +4314,7 @@ const isPrimaryPointer = (event) => {
|
|
|
4282
4314
|
}
|
|
4283
4315
|
};
|
|
4284
4316
|
|
|
4285
|
-
const
|
|
4317
|
+
const keyboardAccessibleElements = new Set([
|
|
4286
4318
|
"BUTTON",
|
|
4287
4319
|
"INPUT",
|
|
4288
4320
|
"SELECT",
|
|
@@ -4290,15 +4322,27 @@ const interactiveElements = new Set([
|
|
|
4290
4322
|
"A",
|
|
4291
4323
|
]);
|
|
4292
4324
|
/**
|
|
4293
|
-
* Checks if an element is
|
|
4294
|
-
*
|
|
4295
|
-
*
|
|
4296
|
-
* This specifically targets form controls, buttons, and links - not just any
|
|
4297
|
-
* element with tabIndex, since motion elements with tap handlers automatically
|
|
4298
|
-
* get tabIndex=0 for keyboard accessibility.
|
|
4325
|
+
* Checks if an element is natively keyboard accessible (focusable).
|
|
4326
|
+
* Used by the press gesture to determine if we need to add tabIndex.
|
|
4299
4327
|
*/
|
|
4300
4328
|
function isElementKeyboardAccessible(element) {
|
|
4301
|
-
return (
|
|
4329
|
+
return (keyboardAccessibleElements.has(element.tagName) ||
|
|
4330
|
+
element.isContentEditable === true);
|
|
4331
|
+
}
|
|
4332
|
+
const textInputElements = new Set(["INPUT", "SELECT", "TEXTAREA"]);
|
|
4333
|
+
/**
|
|
4334
|
+
* Checks if an element has text selection or direct interaction behavior
|
|
4335
|
+
* that should block drag gestures from starting.
|
|
4336
|
+
*
|
|
4337
|
+
* This specifically targets form controls where the user might want to select
|
|
4338
|
+
* text or interact with the control (e.g., sliders, dropdowns).
|
|
4339
|
+
*
|
|
4340
|
+
* Buttons and links are NOT included because they don't have click-and-move
|
|
4341
|
+
* actions of their own - they only respond to click events, so dragging
|
|
4342
|
+
* should still work when initiated from these elements.
|
|
4343
|
+
*/
|
|
4344
|
+
function isElementTextInput(element) {
|
|
4345
|
+
return (textInputElements.has(element.tagName) ||
|
|
4302
4346
|
element.isContentEditable === true);
|
|
4303
4347
|
}
|
|
4304
4348
|
|
|
@@ -9508,6 +9552,7 @@ exports.isDeltaZero = isDeltaZero;
|
|
|
9508
9552
|
exports.isDragActive = isDragActive;
|
|
9509
9553
|
exports.isDragging = isDragging;
|
|
9510
9554
|
exports.isElementKeyboardAccessible = isElementKeyboardAccessible;
|
|
9555
|
+
exports.isElementTextInput = isElementTextInput;
|
|
9511
9556
|
exports.isForcedMotionValue = isForcedMotionValue;
|
|
9512
9557
|
exports.isGenerator = isGenerator;
|
|
9513
9558
|
exports.isHTMLElement = isHTMLElement;
|