Files
TaskPool/docs/.vitepress/cache/deps/vitepress___@vueuse_integrations_useFocusTrap.js
T
2026-03-10 20:12:45 +08:00

82 lines
1.8 KiB
JavaScript

import {
createFocusTrap
} from "./chunk-M5D4FP2Q.js";
import {
notNullish,
toArray,
tryOnScopeDispose,
unrefElement
} from "./chunk-YNJBICHS.js";
import {
computed,
shallowRef,
toValue,
watch
} from "./chunk-P622L5TS.js";
import "./chunk-DC5AMYBS.js";
// node_modules/@vueuse/integrations/useFocusTrap.mjs
function useFocusTrap(target, options = {}) {
let trap;
const { immediate, ...focusTrapOptions } = options;
const hasFocus = shallowRef(false);
const isPaused = shallowRef(false);
const activate = (opts) => trap && trap.activate(opts);
const deactivate = (opts) => trap && trap.deactivate(opts);
const pause = () => {
if (trap) {
trap.pause();
isPaused.value = true;
}
};
const unpause = () => {
if (trap) {
trap.unpause();
isPaused.value = false;
}
};
const targets = computed(() => {
const _targets = toValue(target);
return toArray(_targets).map((el) => {
const _el = toValue(el);
return typeof _el === "string" ? _el : unrefElement(_el);
}).filter(notNullish);
});
watch(
targets,
(els) => {
if (!els.length)
return;
trap = createFocusTrap(els, {
...focusTrapOptions,
onActivate() {
hasFocus.value = true;
if (options.onActivate)
options.onActivate();
},
onDeactivate() {
hasFocus.value = false;
if (options.onDeactivate)
options.onDeactivate();
}
});
if (immediate)
activate();
},
{ flush: "post" }
);
tryOnScopeDispose(() => deactivate());
return {
hasFocus,
isPaused,
activate,
deactivate,
pause,
unpause
};
}
export {
useFocusTrap
};
//# sourceMappingURL=vitepress___@vueuse_integrations_useFocusTrap.js.map