feat: initial commit - Phase 1 & 2 core features

This commit is contained in:
hiderfong
2026-04-22 17:07:33 +08:00
commit 1773bda06b
25005 changed files with 6252106 additions and 0 deletions
@@ -0,0 +1,4 @@
import { _default } from "./src/focus-trap.vue.js";
import { FOCUSOUT_PREVENTED, FOCUSOUT_PREVENTED_OPTS, FOCUS_AFTER_RELEASED, FOCUS_AFTER_TRAPPED, FOCUS_AFTER_TRAPPED_OPTS, FOCUS_TRAP_INJECTION_KEY, FocusTrapInjectionContext, ON_RELEASE_FOCUS_EVT, ON_TRAP_FOCUS_EVT } from "./src/tokens.js";
import { FocusLayer, FocusStack, createFocusOutPreventedEvent, focusFirstDescendant, focusableStack, getEdges, getVisibleElement, isFocusCausedByUserEvent, isHidden, obtainAllFocusableElements, tryFocus, useFocusReason } from "./src/utils.js";
export { _default as ElFocusTrap, _default as default, FOCUSOUT_PREVENTED, FOCUSOUT_PREVENTED_OPTS, FOCUS_AFTER_RELEASED, FOCUS_AFTER_TRAPPED, FOCUS_AFTER_TRAPPED_OPTS, FOCUS_TRAP_INJECTION_KEY, FocusLayer, FocusStack, FocusTrapInjectionContext, ON_RELEASE_FOCUS_EVT, ON_TRAP_FOCUS_EVT, createFocusOutPreventedEvent, focusFirstDescendant, focusableStack, getEdges, getVisibleElement, isFocusCausedByUserEvent, isHidden, obtainAllFocusableElements, tryFocus, useFocusReason };
+10
View File
@@ -0,0 +1,10 @@
import { FOCUSOUT_PREVENTED, FOCUSOUT_PREVENTED_OPTS, FOCUS_AFTER_RELEASED, FOCUS_AFTER_TRAPPED, FOCUS_AFTER_TRAPPED_OPTS, FOCUS_TRAP_INJECTION_KEY, ON_RELEASE_FOCUS_EVT, ON_TRAP_FOCUS_EVT } from "./src/tokens.mjs";
import { createFocusOutPreventedEvent, focusFirstDescendant, focusableStack, getEdges, getVisibleElement, isFocusCausedByUserEvent, isHidden, obtainAllFocusableElements, tryFocus, useFocusReason } from "./src/utils.mjs";
import focus_trap_default from "./src/focus-trap.mjs";
//#region ../../packages/components/focus-trap/index.ts
var focus_trap_default$1 = focus_trap_default;
//#endregion
export { focus_trap_default as ElFocusTrap, FOCUSOUT_PREVENTED, FOCUSOUT_PREVENTED_OPTS, FOCUS_AFTER_RELEASED, FOCUS_AFTER_TRAPPED, FOCUS_AFTER_TRAPPED_OPTS, FOCUS_TRAP_INJECTION_KEY, ON_RELEASE_FOCUS_EVT, ON_TRAP_FOCUS_EVT, createFocusOutPreventedEvent, focus_trap_default$1 as default, focusFirstDescendant, focusableStack, getEdges, getVisibleElement, isFocusCausedByUserEvent, isHidden, obtainAllFocusableElements, tryFocus, useFocusReason };
//# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
{"version":3,"file":"index.mjs","names":["ElFocusTrap"],"sources":["../../../../../packages/components/focus-trap/index.ts"],"sourcesContent":["import ElFocusTrap from './src/focus-trap.vue'\n\nexport { ElFocusTrap }\n\nexport default ElFocusTrap\nexport * from './src/tokens'\nexport * from './src/utils'\n"],"mappings":";;;;;AAIA,2BAAeA"}
@@ -0,0 +1,13 @@
import focus_trap_vue_vue_type_script_lang_default from "./focus-trap.vue_vue_type_script_lang.mjs";
import _plugin_vue_export_helper_default from "../../../_virtual/_plugin-vue_export-helper.mjs";
import { renderSlot } from "vue";
//#region ../../packages/components/focus-trap/src/focus-trap.vue
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return renderSlot(_ctx.$slots, "default", { handleKeydown: _ctx.onKeydown });
}
var focus_trap_default = /* @__PURE__ */ _plugin_vue_export_helper_default(focus_trap_vue_vue_type_script_lang_default, [["render", _sfc_render]]);
//#endregion
export { focus_trap_default as default };
//# sourceMappingURL=focus-trap.mjs.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,37 @@
import * as vue from "vue";
import { PropType } from "vue";
//#region ../../packages/components/focus-trap/src/focus-trap.vue.d.ts
declare const _default: typeof __VLS_export;
declare const __VLS_export: vue.DefineComponent<vue.ExtractPropTypes<{
loop: BooleanConstructor;
trapped: BooleanConstructor;
focusTrapEl: PropType<HTMLElement>;
focusStartEl: {
type: PropType<"container" | "first" | HTMLElement>;
default: string;
};
}>, {
onKeydown: (e: KeyboardEvent) => void;
}, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, ("focusin" | "focusout" | "focusAfterTrapped" | "focusAfterReleased" | "focusout-prevented" | "release-requested")[], "focusin" | "focusout" | "focusAfterTrapped" | "focusAfterReleased" | "focusout-prevented" | "release-requested", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
loop: BooleanConstructor;
trapped: BooleanConstructor;
focusTrapEl: PropType<HTMLElement>;
focusStartEl: {
type: PropType<"container" | "first" | HTMLElement>;
default: string;
};
}>> & Readonly<{
onFocusin?: ((...args: any[]) => any) | undefined;
onFocusout?: ((...args: any[]) => any) | undefined;
onFocusAfterTrapped?: ((...args: any[]) => any) | undefined;
onFocusAfterReleased?: ((...args: any[]) => any) | undefined;
"onFocusout-prevented"?: ((...args: any[]) => any) | undefined;
"onRelease-requested"?: ((...args: any[]) => any) | undefined;
}>, {
loop: boolean;
trapped: boolean;
focusStartEl: HTMLElement | "first" | "container";
}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
//#endregion
export { _default };
@@ -0,0 +1,199 @@
import { EVENT_CODE } from "../../../constants/aria.mjs";
import { getEventCode } from "../../../utils/dom/event.mjs";
import { isString } from "../../../utils/types.mjs";
import { useEscapeKeydown } from "../../../hooks/use-escape-keydown/index.mjs";
import { FOCUS_AFTER_RELEASED, FOCUS_AFTER_TRAPPED, FOCUS_AFTER_TRAPPED_OPTS, FOCUS_TRAP_INJECTION_KEY, ON_RELEASE_FOCUS_EVT, ON_TRAP_FOCUS_EVT } from "./tokens.mjs";
import { createFocusOutPreventedEvent, focusFirstDescendant, focusableStack, getEdges, isFocusCausedByUserEvent, obtainAllFocusableElements, tryFocus, useFocusReason } from "./utils.mjs";
import { isNil } from "lodash-unified";
import { defineComponent, nextTick, onBeforeUnmount, onMounted, provide, ref, unref, watch } from "vue";
//#region ../../packages/components/focus-trap/src/focus-trap.vue?vue&type=script&lang.ts
var focus_trap_vue_vue_type_script_lang_default = defineComponent({
name: "ElFocusTrap",
inheritAttrs: false,
props: {
loop: Boolean,
trapped: Boolean,
focusTrapEl: Object,
focusStartEl: {
type: [Object, String],
default: "first"
}
},
emits: [
ON_TRAP_FOCUS_EVT,
ON_RELEASE_FOCUS_EVT,
"focusin",
"focusout",
"focusout-prevented",
"release-requested"
],
setup(props, { emit }) {
const forwardRef = ref();
let lastFocusBeforeTrapped;
let lastFocusAfterTrapped;
const { focusReason } = useFocusReason();
useEscapeKeydown((event) => {
if (props.trapped && !focusLayer.paused) emit("release-requested", event);
});
const focusLayer = {
paused: false,
pause() {
this.paused = true;
},
resume() {
this.paused = false;
}
};
const onKeydown = (e) => {
if (!props.loop && !props.trapped) return;
if (focusLayer.paused) return;
const { altKey, ctrlKey, metaKey, currentTarget, shiftKey } = e;
const { loop } = props;
const isTabbing = getEventCode(e) === EVENT_CODE.tab && !altKey && !ctrlKey && !metaKey;
const currentFocusingEl = document.activeElement;
if (isTabbing && currentFocusingEl) {
const container = currentTarget;
const [first, last] = getEdges(container);
if (!(first && last)) {
if (currentFocusingEl === container) {
const focusoutPreventedEvent = createFocusOutPreventedEvent({ focusReason: focusReason.value });
emit("focusout-prevented", focusoutPreventedEvent);
if (!focusoutPreventedEvent.defaultPrevented) e.preventDefault();
}
} else if (!shiftKey && currentFocusingEl === last) {
const focusoutPreventedEvent = createFocusOutPreventedEvent({ focusReason: focusReason.value });
emit("focusout-prevented", focusoutPreventedEvent);
if (!focusoutPreventedEvent.defaultPrevented) {
e.preventDefault();
if (loop) tryFocus(first, true);
}
} else if (shiftKey && [first, container].includes(currentFocusingEl)) {
const focusoutPreventedEvent = createFocusOutPreventedEvent({ focusReason: focusReason.value });
emit("focusout-prevented", focusoutPreventedEvent);
if (!focusoutPreventedEvent.defaultPrevented) {
e.preventDefault();
if (loop) tryFocus(last, true);
}
}
}
};
provide(FOCUS_TRAP_INJECTION_KEY, {
focusTrapRef: forwardRef,
onKeydown
});
watch(() => props.focusTrapEl, (focusTrapEl) => {
if (focusTrapEl) forwardRef.value = focusTrapEl;
}, { immediate: true });
watch([forwardRef], ([forwardRef], [oldForwardRef]) => {
if (forwardRef) {
forwardRef.addEventListener("keydown", onKeydown);
forwardRef.addEventListener("focusin", onFocusIn);
forwardRef.addEventListener("focusout", onFocusOut);
}
if (oldForwardRef) {
oldForwardRef.removeEventListener("keydown", onKeydown);
oldForwardRef.removeEventListener("focusin", onFocusIn);
oldForwardRef.removeEventListener("focusout", onFocusOut);
}
});
const trapOnFocus = (e) => {
emit(ON_TRAP_FOCUS_EVT, e);
};
const releaseOnFocus = (e) => emit(ON_RELEASE_FOCUS_EVT, e);
const onFocusIn = (e) => {
const trapContainer = unref(forwardRef);
if (!trapContainer) return;
const target = e.target;
const relatedTarget = e.relatedTarget;
const isFocusedInTrap = target && trapContainer.contains(target);
if (!props.trapped) {
if (!(relatedTarget && trapContainer.contains(relatedTarget))) lastFocusBeforeTrapped = relatedTarget;
}
if (isFocusedInTrap) emit("focusin", e);
if (focusLayer.paused) return;
if (props.trapped) if (isFocusedInTrap) lastFocusAfterTrapped = target;
else tryFocus(lastFocusAfterTrapped, true);
};
const onFocusOut = (e) => {
const trapContainer = unref(forwardRef);
if (focusLayer.paused || !trapContainer) return;
if (props.trapped) {
const relatedTarget = e.relatedTarget;
if (!isNil(relatedTarget) && !trapContainer.contains(relatedTarget)) setTimeout(() => {
if (!focusLayer.paused && props.trapped) {
const focusoutPreventedEvent = createFocusOutPreventedEvent({ focusReason: focusReason.value });
emit("focusout-prevented", focusoutPreventedEvent);
if (!focusoutPreventedEvent.defaultPrevented) tryFocus(lastFocusAfterTrapped, true);
}
}, 0);
} else {
const target = e.target;
if (!(target && trapContainer.contains(target))) emit("focusout", e);
}
};
async function startTrap() {
await nextTick();
const trapContainer = unref(forwardRef);
if (trapContainer) {
focusableStack.push(focusLayer);
const prevFocusedElement = trapContainer.contains(document.activeElement) ? lastFocusBeforeTrapped : document.activeElement;
lastFocusBeforeTrapped = prevFocusedElement;
if (!trapContainer.contains(prevFocusedElement)) {
const focusEvent = new Event(FOCUS_AFTER_TRAPPED, FOCUS_AFTER_TRAPPED_OPTS);
trapContainer.addEventListener(FOCUS_AFTER_TRAPPED, trapOnFocus);
trapContainer.dispatchEvent(focusEvent);
if (!focusEvent.defaultPrevented) nextTick(() => {
let focusStartEl = props.focusStartEl;
if (!isString(focusStartEl)) {
tryFocus(focusStartEl);
if (document.activeElement !== focusStartEl) focusStartEl = "first";
}
if (focusStartEl === "first") focusFirstDescendant(obtainAllFocusableElements(trapContainer), true);
if (document.activeElement === prevFocusedElement || focusStartEl === "container") tryFocus(trapContainer);
});
}
}
}
function stopTrap() {
const trapContainer = unref(forwardRef);
if (trapContainer) {
trapContainer.removeEventListener(FOCUS_AFTER_TRAPPED, trapOnFocus);
const releasedEvent = new CustomEvent(FOCUS_AFTER_RELEASED, {
...FOCUS_AFTER_TRAPPED_OPTS,
detail: { focusReason: focusReason.value }
});
trapContainer.addEventListener(FOCUS_AFTER_RELEASED, releaseOnFocus);
trapContainer.dispatchEvent(releasedEvent);
if (!releasedEvent.defaultPrevented && (focusReason.value == "keyboard" || !isFocusCausedByUserEvent() || trapContainer.contains(document.activeElement))) tryFocus(lastFocusBeforeTrapped ?? document.body);
trapContainer.removeEventListener(FOCUS_AFTER_RELEASED, releaseOnFocus);
focusableStack.remove(focusLayer);
lastFocusBeforeTrapped = null;
lastFocusAfterTrapped = null;
}
}
onMounted(() => {
if (props.trapped) startTrap();
watch(() => props.trapped, (trapped) => {
if (trapped) startTrap();
else stopTrap();
});
});
onBeforeUnmount(() => {
if (props.trapped) stopTrap();
if (forwardRef.value) {
forwardRef.value.removeEventListener("keydown", onKeydown);
forwardRef.value.removeEventListener("focusin", onFocusIn);
forwardRef.value.removeEventListener("focusout", onFocusOut);
forwardRef.value = void 0;
}
lastFocusBeforeTrapped = null;
lastFocusAfterTrapped = null;
});
return { onKeydown };
}
});
//#endregion
export { focus_trap_vue_vue_type_script_lang_default as default };
//# sourceMappingURL=focus-trap.vue_vue_type_script_lang.mjs.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,17 @@
import { InjectionKey, Ref } from "vue";
//#region ../../packages/components/focus-trap/src/tokens.d.ts
declare const FOCUS_AFTER_TRAPPED = "focus-trap.focus-after-trapped";
declare const FOCUS_AFTER_RELEASED = "focus-trap.focus-after-released";
declare const FOCUSOUT_PREVENTED = "focus-trap.focusout-prevented";
declare const FOCUS_AFTER_TRAPPED_OPTS: EventInit;
declare const FOCUSOUT_PREVENTED_OPTS: EventInit;
declare const ON_TRAP_FOCUS_EVT = "focusAfterTrapped";
declare const ON_RELEASE_FOCUS_EVT = "focusAfterReleased";
type FocusTrapInjectionContext = {
focusTrapRef: Ref<HTMLElement | undefined>;
onKeydown: (e: KeyboardEvent) => void;
};
declare const FOCUS_TRAP_INJECTION_KEY: InjectionKey<FocusTrapInjectionContext>;
//#endregion
export { FOCUSOUT_PREVENTED, FOCUSOUT_PREVENTED_OPTS, FOCUS_AFTER_RELEASED, FOCUS_AFTER_TRAPPED, FOCUS_AFTER_TRAPPED_OPTS, FOCUS_TRAP_INJECTION_KEY, FocusTrapInjectionContext, ON_RELEASE_FOCUS_EVT, ON_TRAP_FOCUS_EVT };
@@ -0,0 +1,19 @@
//#region ../../packages/components/focus-trap/src/tokens.ts
const FOCUS_AFTER_TRAPPED = "focus-trap.focus-after-trapped";
const FOCUS_AFTER_RELEASED = "focus-trap.focus-after-released";
const FOCUSOUT_PREVENTED = "focus-trap.focusout-prevented";
const FOCUS_AFTER_TRAPPED_OPTS = {
cancelable: true,
bubbles: false
};
const FOCUSOUT_PREVENTED_OPTS = {
cancelable: true,
bubbles: false
};
const ON_TRAP_FOCUS_EVT = "focusAfterTrapped";
const ON_RELEASE_FOCUS_EVT = "focusAfterReleased";
const FOCUS_TRAP_INJECTION_KEY = Symbol("elFocusTrap");
//#endregion
export { FOCUSOUT_PREVENTED, FOCUSOUT_PREVENTED_OPTS, FOCUS_AFTER_RELEASED, FOCUS_AFTER_TRAPPED, FOCUS_AFTER_TRAPPED_OPTS, FOCUS_TRAP_INJECTION_KEY, ON_RELEASE_FOCUS_EVT, ON_TRAP_FOCUS_EVT };
//# sourceMappingURL=tokens.mjs.map
@@ -0,0 +1 @@
{"version":3,"file":"tokens.mjs","names":[],"sources":["../../../../../../packages/components/focus-trap/src/tokens.ts"],"sourcesContent":["import type { InjectionKey, Ref } from 'vue'\n\nexport const FOCUS_AFTER_TRAPPED = 'focus-trap.focus-after-trapped'\nexport const FOCUS_AFTER_RELEASED = 'focus-trap.focus-after-released'\nexport const FOCUSOUT_PREVENTED = 'focus-trap.focusout-prevented'\nexport const FOCUS_AFTER_TRAPPED_OPTS: EventInit = {\n cancelable: true,\n bubbles: false,\n}\nexport const FOCUSOUT_PREVENTED_OPTS: EventInit = {\n cancelable: true,\n bubbles: false,\n}\n\nexport const ON_TRAP_FOCUS_EVT = 'focusAfterTrapped'\nexport const ON_RELEASE_FOCUS_EVT = 'focusAfterReleased'\n\nexport type FocusTrapInjectionContext = {\n focusTrapRef: Ref<HTMLElement | undefined>\n onKeydown: (e: KeyboardEvent) => void\n}\n\nexport const FOCUS_TRAP_INJECTION_KEY: InjectionKey<FocusTrapInjectionContext> =\n Symbol('elFocusTrap')\n"],"mappings":";AAEA,MAAa,sBAAsB;AACnC,MAAa,uBAAuB;AACpC,MAAa,qBAAqB;AAClC,MAAa,2BAAsC;CACjD,YAAY;CACZ,SAAS;CACV;AACD,MAAa,0BAAqC;CAChD,YAAY;CACZ,SAAS;CACV;AAED,MAAa,oBAAoB;AACjC,MAAa,uBAAuB;AAOpC,MAAa,2BACX,OAAO,cAAc"}
@@ -0,0 +1,33 @@
import * as vue from "vue";
//#region ../../packages/components/focus-trap/src/utils.d.ts
declare const focusReason: vue.Ref<"pointer" | "keyboard" | undefined, "pointer" | "keyboard" | undefined>;
declare const lastUserFocusTimestamp: vue.Ref<number, number>;
declare const lastAutomatedFocusTimestamp: vue.Ref<number, number>;
type FocusLayer = {
paused: boolean;
pause: () => void;
resume: () => void;
};
type FocusStack = FocusLayer[];
declare const obtainAllFocusableElements: (element: HTMLElement) => HTMLElement[];
declare const getVisibleElement: (elements: HTMLElement[], container: HTMLElement) => HTMLElement | undefined;
declare const isHidden: (element: HTMLElement, container: HTMLElement) => boolean;
declare const getEdges: (container: HTMLElement) => (HTMLElement | undefined)[];
declare const tryFocus: (element?: HTMLElement | {
focus: () => void;
} | null, shouldSelect?: boolean) => void;
declare const focusFirstDescendant: (elements: HTMLElement[], shouldSelect?: boolean) => void;
declare const focusableStack: {
push: (layer: FocusLayer) => void;
remove: (layer: FocusLayer) => void;
};
declare const isFocusCausedByUserEvent: () => boolean;
declare const useFocusReason: () => {
focusReason: typeof focusReason;
lastUserFocusTimestamp: typeof lastUserFocusTimestamp;
lastAutomatedFocusTimestamp: typeof lastAutomatedFocusTimestamp;
};
declare const createFocusOutPreventedEvent: (detail: CustomEventInit["detail"]) => CustomEvent<any>;
//#endregion
export { FocusLayer, FocusStack, createFocusOutPreventedEvent, focusFirstDescendant, focusableStack, getEdges, getVisibleElement, isFocusCausedByUserEvent, isHidden, obtainAllFocusableElements, tryFocus, useFocusReason };
@@ -0,0 +1,121 @@
import { focusElement } from "../../../utils/dom/aria.mjs";
import { FOCUSOUT_PREVENTED, FOCUSOUT_PREVENTED_OPTS } from "./tokens.mjs";
import { onBeforeUnmount, onMounted, ref } from "vue";
//#region ../../packages/components/focus-trap/src/utils.ts
const focusReason = ref();
const lastUserFocusTimestamp = ref(0);
const lastAutomatedFocusTimestamp = ref(0);
let focusReasonUserCount = 0;
const obtainAllFocusableElements = (element) => {
const nodes = [];
const walker = document.createTreeWalker(element, NodeFilter.SHOW_ELEMENT, { acceptNode: (node) => {
const isHiddenInput = node.tagName === "INPUT" && node.type === "hidden";
if (node.disabled || node.hidden || isHiddenInput) return NodeFilter.FILTER_SKIP;
return node.tabIndex >= 0 || node === document.activeElement ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
} });
while (walker.nextNode()) nodes.push(walker.currentNode);
return nodes;
};
const getVisibleElement = (elements, container) => {
for (const element of elements) if (!isHidden(element, container)) return element;
};
const isHidden = (element, container) => {
if (getComputedStyle(element).visibility === "hidden") return true;
while (element) {
if (container && element === container) return false;
if (getComputedStyle(element).display === "none") return true;
element = element.parentElement;
}
return false;
};
const getEdges = (container) => {
const focusable = obtainAllFocusableElements(container);
return [getVisibleElement(focusable, container), getVisibleElement(focusable.reverse(), container)];
};
const isSelectable = (element) => {
return element instanceof HTMLInputElement && "select" in element;
};
const tryFocus = (element, shouldSelect) => {
if (element) {
const prevFocusedElement = document.activeElement;
focusElement(element, { preventScroll: true });
lastAutomatedFocusTimestamp.value = window.performance.now();
if (element !== prevFocusedElement && isSelectable(element) && shouldSelect) element.select();
}
};
function removeFromStack(list, item) {
const copy = [...list];
const idx = list.indexOf(item);
if (idx !== -1) copy.splice(idx, 1);
return copy;
}
const createFocusableStack = () => {
let stack = [];
const push = (layer) => {
const currentLayer = stack[0];
if (currentLayer && layer !== currentLayer) currentLayer.pause();
stack = removeFromStack(stack, layer);
stack.unshift(layer);
};
const remove = (layer) => {
stack = removeFromStack(stack, layer);
stack[0]?.resume?.();
};
return {
push,
remove
};
};
const focusFirstDescendant = (elements, shouldSelect = false) => {
const prevFocusedElement = document.activeElement;
for (const element of elements) {
tryFocus(element, shouldSelect);
if (document.activeElement !== prevFocusedElement) return;
}
};
const focusableStack = createFocusableStack();
const isFocusCausedByUserEvent = () => {
return lastUserFocusTimestamp.value > lastAutomatedFocusTimestamp.value;
};
const notifyFocusReasonPointer = () => {
focusReason.value = "pointer";
lastUserFocusTimestamp.value = window.performance.now();
};
const notifyFocusReasonKeydown = () => {
focusReason.value = "keyboard";
lastUserFocusTimestamp.value = window.performance.now();
};
const useFocusReason = () => {
onMounted(() => {
if (focusReasonUserCount === 0) {
document.addEventListener("mousedown", notifyFocusReasonPointer);
document.addEventListener("touchstart", notifyFocusReasonPointer);
document.addEventListener("keydown", notifyFocusReasonKeydown);
}
focusReasonUserCount++;
});
onBeforeUnmount(() => {
focusReasonUserCount--;
if (focusReasonUserCount <= 0) {
document.removeEventListener("mousedown", notifyFocusReasonPointer);
document.removeEventListener("touchstart", notifyFocusReasonPointer);
document.removeEventListener("keydown", notifyFocusReasonKeydown);
}
});
return {
focusReason,
lastUserFocusTimestamp,
lastAutomatedFocusTimestamp
};
};
const createFocusOutPreventedEvent = (detail) => {
return new CustomEvent(FOCUSOUT_PREVENTED, {
...FOCUSOUT_PREVENTED_OPTS,
detail
});
};
//#endregion
export { createFocusOutPreventedEvent, focusFirstDescendant, focusableStack, getEdges, getVisibleElement, isFocusCausedByUserEvent, isHidden, obtainAllFocusableElements, tryFocus, useFocusReason };
//# sourceMappingURL=utils.mjs.map
File diff suppressed because one or more lines are too long