Files
Andrei 58f8093689 Rebrand from 'Redirect Intelligence v2' to 'URL Tracker Tool V2' throughout UI
- Updated all component headers and documentation
- Changed navbar and footer branding
- Updated homepage hero badge
- Modified page title in index.html
- Simplified footer text to 'Built with ❤️'
- Consistent V2 capitalization across all references
2025-08-19 19:12:23 +00:00

125 lines
3.6 KiB
JavaScript

// src/index.ts
import { isDom } from "@zag-js/dom-query";
var hasSetup = false;
var modality = null;
var hasEventBeforeFocus = false;
var hasBlurredWindowRecently = false;
var handlers = /* @__PURE__ */ new Set();
function trigger(modality2, event) {
handlers.forEach((handler) => handler(modality2, event));
}
var isMac = typeof window !== "undefined" && window.navigator != null ? /^Mac/.test(window.navigator.platform) : false;
function isValidKey(e) {
return !(e.metaKey || !isMac && e.altKey || e.ctrlKey || e.key === "Control" || e.key === "Shift" || e.key === "Meta");
}
function onKeyboardEvent(event) {
hasEventBeforeFocus = true;
if (isValidKey(event)) {
modality = "keyboard";
trigger("keyboard", event);
}
}
function onPointerEvent(event) {
modality = "pointer";
if (event.type === "mousedown" || event.type === "pointerdown") {
hasEventBeforeFocus = true;
const target = event.composedPath ? event.composedPath()[0] : event.target;
let matches = false;
try {
matches = target.matches(":focus-visible");
} catch {
}
if (matches)
return;
trigger("pointer", event);
}
}
function isVirtualClick(event) {
if (event.mozInputSource === 0 && event.isTrusted)
return true;
return event.detail === 0 && !event.pointerType;
}
function onClickEvent(e) {
if (isVirtualClick(e)) {
hasEventBeforeFocus = true;
modality = "virtual";
}
}
function onWindowFocus(event) {
if (event.target === window || event.target === document) {
return;
}
if (event.target instanceof Element && event.target.hasAttribute("tabindex")) {
return;
}
if (!hasEventBeforeFocus && !hasBlurredWindowRecently) {
modality = "virtual";
trigger("virtual", event);
}
hasEventBeforeFocus = false;
hasBlurredWindowRecently = false;
}
function onWindowBlur() {
hasEventBeforeFocus = false;
hasBlurredWindowRecently = true;
}
function isFocusVisible() {
return modality !== "pointer";
}
function setupGlobalFocusEvents() {
if (!isDom() || hasSetup) {
return;
}
const { focus } = HTMLElement.prototype;
HTMLElement.prototype.focus = function focusElement(...args) {
hasEventBeforeFocus = true;
focus.apply(this, args);
};
document.addEventListener("keydown", onKeyboardEvent, true);
document.addEventListener("keyup", onKeyboardEvent, true);
document.addEventListener("click", onClickEvent, true);
window.addEventListener("focus", onWindowFocus, true);
window.addEventListener("blur", onWindowBlur, false);
if (typeof PointerEvent !== "undefined") {
document.addEventListener("pointerdown", onPointerEvent, true);
document.addEventListener("pointermove", onPointerEvent, true);
document.addEventListener("pointerup", onPointerEvent, true);
} else {
document.addEventListener("mousedown", onPointerEvent, true);
document.addEventListener("mousemove", onPointerEvent, true);
document.addEventListener("mouseup", onPointerEvent, true);
}
hasSetup = true;
}
function trackFocusVisible(fn) {
setupGlobalFocusEvents();
fn(isFocusVisible());
const handler = () => fn(isFocusVisible());
handlers.add(handler);
return () => {
handlers.delete(handler);
};
}
function trackInteractionModality(fn) {
setupGlobalFocusEvents();
fn(modality);
const handler = () => fn(modality);
handlers.add(handler);
return () => {
handlers.delete(handler);
};
}
function setInteractionModality(value) {
modality = value;
trigger(value, null);
}
function getInteractionModality() {
return modality;
}
export {
getInteractionModality,
setInteractionModality,
trackFocusVisible,
trackInteractionModality
};
//# sourceMappingURL=index.mjs.map