mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
62 lines
2.0 KiB
JavaScript
62 lines
2.0 KiB
JavaScript
import { resolveEventTarget } from "./event.js";
|
|
//#region src/dom/interactive.ts
|
|
const INTERACTIVE_SELECTOR = [
|
|
"button",
|
|
"input",
|
|
"select",
|
|
"textarea",
|
|
"a[href]",
|
|
"[role=\"button\"]",
|
|
"[role=\"menu\"]",
|
|
"[role=\"menuitem\"]",
|
|
"[role=\"menuitemcheckbox\"]",
|
|
"[role=\"menuitemradio\"]",
|
|
"[role=\"slider\"]",
|
|
"[data-interactive]"
|
|
].join(",");
|
|
const EDITABLE_SELECTOR = [
|
|
"textarea",
|
|
"select",
|
|
"input:not([type])",
|
|
...[
|
|
"text",
|
|
"search",
|
|
"url",
|
|
"tel",
|
|
"email",
|
|
"password",
|
|
"number"
|
|
].map((type) => `input[type="${type}"]`),
|
|
"[contenteditable]:not([contenteditable=\"false\"])"
|
|
].join(",");
|
|
function isEditableElement(el) {
|
|
return el.matches(EDITABLE_SELECTOR);
|
|
}
|
|
/** Whether the keyboard event target is an editable element (input, textarea, etc). */
|
|
function isEditableTarget(event) {
|
|
const target = resolveEventTarget(event);
|
|
return target instanceof Element && isEditableElement(target);
|
|
}
|
|
/** Whether the event originated from an interactive control (button, slider, etc). */
|
|
function isInteractiveTarget(event) {
|
|
const target = resolveEventTarget(event);
|
|
if (!(target instanceof Element)) return false;
|
|
return target.closest(INTERACTIVE_SELECTOR) !== null;
|
|
}
|
|
const ACTIVATION_KEYS = /* @__PURE__ */ new Set([" ", "Enter"]);
|
|
/**
|
|
* Selector for elements that use Space/Enter as a native activation key.
|
|
* Narrower than `INTERACTIVE_SELECTOR` — excludes editable elements like
|
|
* `input`, `textarea`, `select` where Space/Enter is text input, not activation.
|
|
*/
|
|
const ACTIVATABLE_SELECTOR = "button,a[href],[role=\"slider\"],[role=\"button\"]";
|
|
/** Whether the event is an activation key on an activatable element (button, link, slider). */
|
|
function isInteractiveActivation(event) {
|
|
if (!ACTIVATION_KEYS.has(event.key)) return false;
|
|
const target = resolveEventTarget(event);
|
|
return target instanceof Element && target.matches(ACTIVATABLE_SELECTOR);
|
|
}
|
|
//#endregion
|
|
export { EDITABLE_SELECTOR, INTERACTIVE_SELECTOR, isEditableElement, isEditableTarget, isInteractiveActivation, isInteractiveTarget };
|
|
|
|
//# sourceMappingURL=interactive.js.map
|