Packages
corex
0.1.0-alpha.29
0.1.2
0.1.1
0.1.0
0.1.0-rc.1
0.1.0-rc.0
0.1.0-beta.5
0.1.0-beta.4
0.1.0-beta.3
0.1.0-beta.2
0.1.0-beta.1
0.1.0-alpha.33
0.1.0-alpha.32
0.1.0-alpha.31
0.1.0-alpha.30
0.1.0-alpha.29
0.1.0-alpha.28
0.1.0-alpha.27
0.1.0-alpha.26
0.1.0-alpha.25
0.1.0-alpha.24
0.1.0-alpha.23
0.1.0-alpha.22
0.1.0-alpha.21
0.1.0-alpha.20
0.1.0-alpha.19
0.1.0-alpha.18
0.1.0-alpha.17
0.1.0-alpha.16
0.1.0-alpha.15
0.1.0-alpha.14
0.1.0-alpha.13
0.1.0-alpha.12
0.1.0-alpha.11
0.1.0-alpha.10
0.1.0-alpha.9
0.1.0-alpha.8
0.1.0-alpha.7
0.1.0-alpha.6
0.1.0-alpha.5
0.1.0-alpha.4
0.1.0-alpha.3
0.1.0-alpha.2
0.1.0-alpha.1
Accessible and unstyled UI components library written in Elixir and TypeScript that integrates Zag.js state machines into the Phoenix Framework.
Current section
Files
Jump to
Current section
Files
priv/static/chunk-EBQGC3XC.mjs
import {
addDomEvent,
callAll,
contains,
getDocument,
getEventTarget,
getNearestOverflowAncestor,
getWindow,
isContextMenuEvent,
isControlledElement,
isFocusable,
isHTMLElement,
isShadowRoot,
isTouchDevice,
raf
} from "./chunk-RUWIVFVB.mjs";
// ../node_modules/.pnpm/@zag-js+interact-outside@1.34.1/node_modules/@zag-js/interact-outside/dist/index.mjs
function getWindowFrames(win) {
const frames = {
each(cb) {
for (let i = 0; i < win.frames?.length; i += 1) {
const frame = win.frames[i];
if (frame) cb(frame);
}
},
addEventListener(event, listener, options) {
frames.each((frame) => {
try {
frame.document.addEventListener(event, listener, options);
} catch {
}
});
return () => {
try {
frames.removeEventListener(event, listener, options);
} catch {
}
};
},
removeEventListener(event, listener, options) {
frames.each((frame) => {
try {
frame.document.removeEventListener(event, listener, options);
} catch {
}
});
}
};
return frames;
}
function getParentWindow(win) {
const parent = win.frameElement != null ? win.parent : null;
return {
addEventListener: (event, listener, options) => {
try {
parent?.addEventListener(event, listener, options);
} catch {
}
return () => {
try {
parent?.removeEventListener(event, listener, options);
} catch {
}
};
},
removeEventListener: (event, listener, options) => {
try {
parent?.removeEventListener(event, listener, options);
} catch {
}
}
};
}
var POINTER_OUTSIDE_EVENT = "pointerdown.outside";
var FOCUS_OUTSIDE_EVENT = "focus.outside";
function isComposedPathFocusable(composedPath) {
for (const node of composedPath) {
if (isHTMLElement(node) && isFocusable(node)) return true;
}
return false;
}
var isPointerEvent = (event) => "clientY" in event;
function isEventPointWithin(node, event) {
if (!isPointerEvent(event) || !node) return false;
const rect = node.getBoundingClientRect();
if (rect.width === 0 || rect.height === 0) return false;
return rect.top <= event.clientY && event.clientY <= rect.top + rect.height && rect.left <= event.clientX && event.clientX <= rect.left + rect.width;
}
function isPointInRect(rect, point) {
return rect.y <= point.y && point.y <= rect.y + rect.height && rect.x <= point.x && point.x <= rect.x + rect.width;
}
function isEventWithinScrollbar(event, ancestor) {
if (!ancestor || !isPointerEvent(event)) return false;
const isScrollableY = ancestor.scrollHeight > ancestor.clientHeight;
const onScrollbarY = isScrollableY && event.clientX > ancestor.offsetLeft + ancestor.clientWidth;
const isScrollableX = ancestor.scrollWidth > ancestor.clientWidth;
const onScrollbarX = isScrollableX && event.clientY > ancestor.offsetTop + ancestor.clientHeight;
const rect = {
x: ancestor.offsetLeft,
y: ancestor.offsetTop,
width: ancestor.clientWidth + (isScrollableY ? 16 : 0),
height: ancestor.clientHeight + (isScrollableX ? 16 : 0)
};
const point = {
x: event.clientX,
y: event.clientY
};
if (!isPointInRect(rect, point)) return false;
return onScrollbarY || onScrollbarX;
}
function trackInteractOutsideImpl(node, options) {
const {
exclude,
onFocusOutside,
onPointerDownOutside,
onInteractOutside,
defer,
followControlledElements = true
} = options;
if (!node) return;
const doc = getDocument(node);
const win = getWindow(node);
const frames = getWindowFrames(win);
const parentWin = getParentWindow(win);
function isEventOutside(event, target) {
if (!isHTMLElement(target)) return false;
if (!target.isConnected) return false;
if (contains(node, target)) return false;
if (isEventPointWithin(node, event)) return false;
if (followControlledElements && isControlledElement(node, target)) return false;
const triggerEl = doc.querySelector(`[aria-controls="${node.id}"]`);
if (triggerEl) {
const triggerAncestor = getNearestOverflowAncestor(triggerEl);
if (isEventWithinScrollbar(event, triggerAncestor)) return false;
}
const nodeAncestor = getNearestOverflowAncestor(node);
if (isEventWithinScrollbar(event, nodeAncestor)) return false;
return !exclude?.(target);
}
const pointerdownCleanups = /* @__PURE__ */ new Set();
const isInShadowRoot = isShadowRoot(node?.getRootNode());
function onPointerDown(event) {
function handler(clickEvent) {
const func = defer && !isTouchDevice() ? raf : (v) => v();
const evt = clickEvent ?? event;
const composedPath = evt?.composedPath?.() ?? [evt?.target];
func(() => {
const target = isInShadowRoot ? composedPath[0] : getEventTarget(event);
if (!node || !isEventOutside(event, target)) return;
if (onPointerDownOutside || onInteractOutside) {
const handler2 = callAll(onPointerDownOutside, onInteractOutside);
node.addEventListener(POINTER_OUTSIDE_EVENT, handler2, { once: true });
}
fireCustomEvent(node, POINTER_OUTSIDE_EVENT, {
bubbles: false,
cancelable: true,
detail: {
originalEvent: evt,
contextmenu: isContextMenuEvent(evt),
focusable: isComposedPathFocusable(composedPath),
target
}
});
});
}
if (event.pointerType === "touch") {
pointerdownCleanups.forEach((fn) => fn());
pointerdownCleanups.add(addDomEvent(doc, "click", handler, { once: true }));
pointerdownCleanups.add(parentWin.addEventListener("click", handler, { once: true }));
pointerdownCleanups.add(frames.addEventListener("click", handler, { once: true }));
} else {
handler();
}
}
const cleanups = /* @__PURE__ */ new Set();
const timer = setTimeout(() => {
cleanups.add(addDomEvent(doc, "pointerdown", onPointerDown, true));
cleanups.add(parentWin.addEventListener("pointerdown", onPointerDown, true));
cleanups.add(frames.addEventListener("pointerdown", onPointerDown, true));
}, 0);
function onFocusin(event) {
const func = defer ? raf : (v) => v();
func(() => {
const composedPath = event?.composedPath?.() ?? [event?.target];
const target = isInShadowRoot ? composedPath[0] : getEventTarget(event);
if (!node || !isEventOutside(event, target)) return;
if (onFocusOutside || onInteractOutside) {
const handler = callAll(onFocusOutside, onInteractOutside);
node.addEventListener(FOCUS_OUTSIDE_EVENT, handler, { once: true });
}
fireCustomEvent(node, FOCUS_OUTSIDE_EVENT, {
bubbles: false,
cancelable: true,
detail: {
originalEvent: event,
contextmenu: false,
focusable: isFocusable(target),
target
}
});
});
}
if (!isTouchDevice()) {
cleanups.add(addDomEvent(doc, "focusin", onFocusin, true));
cleanups.add(parentWin.addEventListener("focusin", onFocusin, true));
cleanups.add(frames.addEventListener("focusin", onFocusin, true));
}
return () => {
clearTimeout(timer);
pointerdownCleanups.forEach((fn) => fn());
cleanups.forEach((fn) => fn());
};
}
function trackInteractOutside(nodeOrFn, options) {
const { defer } = options;
const func = defer ? raf : (v) => v();
const cleanups = [];
cleanups.push(
func(() => {
const node = typeof nodeOrFn === "function" ? nodeOrFn() : nodeOrFn;
cleanups.push(trackInteractOutsideImpl(node, options));
})
);
return () => {
cleanups.forEach((fn) => fn?.());
};
}
function fireCustomEvent(el, type, init) {
const win = el.ownerDocument.defaultView || window;
const event = new win.CustomEvent(type, init);
return el.dispatchEvent(event);
}
export {
trackInteractOutside
};