Current section

Files

Jump to
corex priv static chunk-IXOYOLUJ.mjs
Raw

priv/static/chunk-IXOYOLUJ.mjs

// lib/util.ts
var DIR_VALUES = ["ltr", "rtl"];
function getDir(element) {
const fromEl = element.dataset.dir;
if (fromEl !== void 0 && DIR_VALUES.includes(fromEl)) {
return fromEl;
}
const fromDoc = document.documentElement.getAttribute("dir");
if (fromDoc === "ltr" || fromDoc === "rtl") return fromDoc;
return "ltr";
}
var getString = (element, attrName, validValues) => {
const value = element.dataset[attrName];
if (value !== void 0 && (!validValues || validValues.includes(value))) {
return value;
}
return void 0;
};
var getStringList = (element, attrName) => {
const value = element.dataset[attrName];
if (typeof value === "string") {
return value.split(",").map((v) => v.trim()).filter((v) => v.length > 0);
}
return void 0;
};
var getNumber = (element, attrName, validValues) => {
const raw = element.dataset[attrName];
if (raw === void 0) return void 0;
const parsed = Number(raw);
if (Number.isNaN(parsed)) return void 0;
if (validValues && !validValues.includes(parsed)) return 0;
return parsed;
};
var getBoolean = (element, attrName) => {
const dashName = attrName.replace(/([A-Z])/g, "-$1").toLowerCase();
return element.hasAttribute(`data-${dashName}`);
};
var generateId = (element, fallbackId = "element") => {
if (element?.id) return element.id;
return `${fallbackId}-${Math.random().toString(36).substring(2, 9)}`;
};
// ../node_modules/.pnpm/@zag-js+anatomy@1.33.1/node_modules/@zag-js/anatomy/dist/index.mjs
var createAnatomy = (name, parts = []) => ({
parts: (...values) => {
if (isEmpty(parts)) {
return createAnatomy(name, values);
}
throw new Error("createAnatomy().parts(...) should only be called once. Did you mean to use .extendWith(...) ?");
},
extendWith: (...values) => createAnatomy(name, [...parts, ...values]),
omit: (...values) => createAnatomy(name, parts.filter((part) => !values.includes(part))),
rename: (newName) => createAnatomy(newName, parts),
keys: () => parts,
build: () => [...new Set(parts)].reduce(
(prev2, part) => Object.assign(prev2, {
[part]: {
selector: [
`&[data-scope="${toKebabCase(name)}"][data-part="${toKebabCase(part)}"]`,
`& [data-scope="${toKebabCase(name)}"][data-part="${toKebabCase(part)}"]`
].join(", "),
attrs: { "data-scope": toKebabCase(name), "data-part": toKebabCase(part) }
}
}),
{}
)
});
var toKebabCase = (value) => value.replace(/([A-Z])([A-Z])/g, "$1-$2").replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
var isEmpty = (v) => v.length === 0;
// ../node_modules/.pnpm/@zag-js+dom-query@1.33.1/node_modules/@zag-js/dom-query/dist/index.mjs
var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
function setCaretToEnd(input) {
if (!input) return;
try {
if (input.ownerDocument.activeElement !== input) return;
const len = input.value.length;
input.setSelectionRange(len, len);
} catch {
}
}
var clamp = (value) => Math.max(0, Math.min(1, value));
var wrap = (v, idx) => {
return v.map((_, index) => v[(Math.max(idx, 0) + index) % v.length]);
};
var pipe = (...fns) => (arg) => fns.reduce((acc, fn) => fn(acc), arg);
var noop = () => void 0;
var isObject = (v) => typeof v === "object" && v !== null;
var MAX_Z_INDEX = 2147483647;
var dataAttr = (guard) => guard ? "" : void 0;
var ariaAttr = (guard) => guard ? "true" : void 0;
var ELEMENT_NODE = 1;
var DOCUMENT_NODE = 9;
var DOCUMENT_FRAGMENT_NODE = 11;
var isHTMLElement = (el) => isObject(el) && el.nodeType === ELEMENT_NODE && typeof el.nodeName === "string";
var isDocument = (el) => isObject(el) && el.nodeType === DOCUMENT_NODE;
var isWindow = (el) => isObject(el) && el === el.window;
var getNodeName = (node) => {
if (isHTMLElement(node)) return node.localName || "";
return "#document";
};
function isRootElement(node) {
return ["html", "body", "#document"].includes(getNodeName(node));
}
var isNode = (el) => isObject(el) && el.nodeType !== void 0;
var isShadowRoot = (el) => isNode(el) && el.nodeType === DOCUMENT_FRAGMENT_NODE && "host" in el;
var isInputElement = (el) => isHTMLElement(el) && el.localName === "input";
var isAnchorElement = (el) => !!el?.matches("a[href]");
var isElementVisible = (el) => {
if (!isHTMLElement(el)) return false;
return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
};
function isActiveElement(element) {
if (!element) return false;
const rootNode = element.getRootNode();
return getActiveElement(rootNode) === element;
}
var TEXTAREA_SELECT_REGEX = /(textarea|select)/;
function isEditableElement(el) {
if (el == null || !isHTMLElement(el)) return false;
try {
return isInputElement(el) && el.selectionStart != null || TEXTAREA_SELECT_REGEX.test(el.localName) || el.isContentEditable || el.getAttribute("contenteditable") === "true" || el.getAttribute("contenteditable") === "";
} catch {
return false;
}
}
function contains(parent, child) {
if (!parent || !child) return false;
if (!isHTMLElement(parent) || !isHTMLElement(child)) return false;
const rootNode = child.getRootNode?.();
if (parent === child) return true;
if (parent.contains(child)) return true;
if (rootNode && isShadowRoot(rootNode)) {
let next2 = child;
while (next2) {
if (parent === next2) return true;
next2 = next2.parentNode || next2.host;
}
}
return false;
}
function getDocument(el) {
if (isDocument(el)) return el;
if (isWindow(el)) return el.document;
return el?.ownerDocument ?? document;
}
function getDocumentElement(el) {
return getDocument(el).documentElement;
}
function getWindow(el) {
if (isShadowRoot(el)) return getWindow(el.host);
if (isDocument(el)) return el.defaultView ?? window;
if (isHTMLElement(el)) return el.ownerDocument?.defaultView ?? window;
return window;
}
function getActiveElement(rootNode) {
let activeElement = rootNode.activeElement;
while (activeElement?.shadowRoot) {
const el = activeElement.shadowRoot.activeElement;
if (!el || el === activeElement) break;
else activeElement = el;
}
return activeElement;
}
function getParentNode(node) {
if (getNodeName(node) === "html") return node;
const result = node.assignedSlot || node.parentNode || isShadowRoot(node) && node.host || getDocumentElement(node);
return isShadowRoot(result) ? result.host : result;
}
function getRootNode(node) {
let result;
try {
result = node.getRootNode({ composed: true });
if (isDocument(result) || isShadowRoot(result)) return result;
} catch {
}
return node.ownerDocument ?? document;
}
var styleCache = /* @__PURE__ */ new WeakMap();
function getComputedStyle(el) {
if (!styleCache.has(el)) {
styleCache.set(el, getWindow(el).getComputedStyle(el));
}
return styleCache.get(el);
}
var INTERACTIVE_CONTAINER_ROLE = /* @__PURE__ */ new Set(["menu", "listbox", "dialog", "grid", "tree", "region"]);
var isInteractiveContainerRole = (role) => INTERACTIVE_CONTAINER_ROLE.has(role);
var getAriaControls = (element) => element.getAttribute("aria-controls")?.split(" ") || [];
function isControlledElement(container, element) {
const visitedIds = /* @__PURE__ */ new Set();
const rootNode = getRootNode(container);
const checkElement = (searchRoot) => {
const controllingElements = searchRoot.querySelectorAll("[aria-controls]");
for (const controller of controllingElements) {
if (controller.getAttribute("aria-expanded") !== "true") continue;
const controlledIds = getAriaControls(controller);
for (const id of controlledIds) {
if (!id || visitedIds.has(id)) continue;
visitedIds.add(id);
const controlledElement = rootNode.getElementById(id);
if (controlledElement) {
const role = controlledElement.getAttribute("role");
const modal = controlledElement.getAttribute("aria-modal") === "true";
if (role && isInteractiveContainerRole(role) && !modal) {
if (controlledElement === element || controlledElement.contains(element)) {
return true;
}
if (checkElement(controlledElement)) {
return true;
}
}
}
}
}
return false;
};
return checkElement(container);
}
function findControlledElements(searchRoot, callback) {
const rootNode = getRootNode(searchRoot);
const visitedIds = /* @__PURE__ */ new Set();
const findRecursive = (root) => {
const controllingElements = root.querySelectorAll("[aria-controls]");
for (const controller of controllingElements) {
if (controller.getAttribute("aria-expanded") !== "true") continue;
const controlledIds = getAriaControls(controller);
for (const id of controlledIds) {
if (!id || visitedIds.has(id)) continue;
visitedIds.add(id);
const controlledElement = rootNode.getElementById(id);
if (controlledElement) {
const role = controlledElement.getAttribute("role");
const modal = controlledElement.getAttribute("aria-modal") === "true";
if (role && INTERACTIVE_CONTAINER_ROLE.has(role) && !modal) {
callback(controlledElement);
findRecursive(controlledElement);
}
}
}
}
};
findRecursive(searchRoot);
}
function getControlledElements(container) {
const controlledElements = /* @__PURE__ */ new Set();
findControlledElements(container, (controlledElement) => {
if (!container.contains(controlledElement)) {
controlledElements.add(controlledElement);
}
});
return Array.from(controlledElements);
}
function isInteractiveContainerElement(element) {
const role = element.getAttribute("role");
return Boolean(role && INTERACTIVE_CONTAINER_ROLE.has(role));
}
function isControllerElement(element) {
return element.hasAttribute("aria-controls") && element.getAttribute("aria-expanded") === "true";
}
function hasControllerElements(element) {
if (isControllerElement(element)) return true;
return Boolean(element.querySelector?.('[aria-controls][aria-expanded="true"]'));
}
function isControlledByExpandedController(element) {
if (!element.id) return false;
const rootNode = getRootNode(element);
const escapedId = CSS.escape(element.id);
const selector = `[aria-controls~="${escapedId}"][aria-expanded="true"], [aria-controls="${escapedId}"][aria-expanded="true"]`;
const controller = rootNode.querySelector(selector);
return Boolean(controller && isInteractiveContainerElement(element));
}
function getDataUrl(svg, opts) {
const { type, quality = 0.92, background } = opts;
if (!svg) throw new Error("[zag-js > getDataUrl]: Could not find the svg element");
const win = getWindow(svg);
const doc = win.document;
const svgBounds = svg.getBoundingClientRect();
const svgClone = svg.cloneNode(true);
if (!svgClone.hasAttribute("viewBox")) {
svgClone.setAttribute("viewBox", `0 0 ${svgBounds.width} ${svgBounds.height}`);
}
const serializer = new win.XMLSerializer();
const source = '<?xml version="1.0" standalone="no"?>\r\n' + serializer.serializeToString(svgClone);
const svgString = "data:image/svg+xml;charset=utf-8," + encodeURIComponent(source);
if (type === "image/svg+xml") {
return Promise.resolve(svgString).then((str) => {
svgClone.remove();
return str;
});
}
const dpr = win.devicePixelRatio || 1;
const canvas = doc.createElement("canvas");
const image = new win.Image();
image.src = svgString;
canvas.width = svgBounds.width * dpr;
canvas.height = svgBounds.height * dpr;
const context = canvas.getContext("2d");
if (type === "image/jpeg" || background) {
context.fillStyle = background || "white";
context.fillRect(0, 0, canvas.width, canvas.height);
}
return new Promise((resolve) => {
image.onload = () => {
context?.drawImage(image, 0, 0, canvas.width, canvas.height);
resolve(canvas.toDataURL(type, quality));
svgClone.remove();
};
});
}
var isDom = () => typeof document !== "undefined";
function getPlatform() {
const agent = navigator.userAgentData;
return agent?.platform ?? navigator.platform;
}
function getUserAgent() {
const ua2 = navigator.userAgentData;
if (ua2 && Array.isArray(ua2.brands)) {
return ua2.brands.map(({ brand, version }) => `${brand}/${version}`).join(" ");
}
return navigator.userAgent;
}
var pt = (v) => isDom() && v.test(getPlatform());
var ua = (v) => isDom() && v.test(getUserAgent());
var vn = (v) => isDom() && v.test(navigator.vendor);
var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
var isIPhone = () => pt(/^iPhone/i);
var isIPad = () => pt(/^iPad/i) || isMac() && navigator.maxTouchPoints > 1;
var isIos = () => isIPhone() || isIPad();
var isApple = () => isMac() || isIos();
var isMac = () => pt(/^Mac/i);
var isSafari = () => isApple() && vn(/apple/i);
var isFirefox = () => ua(/Firefox/i);
var isAndroid = () => ua(/Android/i);
function getBeforeInputValue(event) {
const { selectionStart, selectionEnd, value } = event.currentTarget;
const data = event.data;
return value.slice(0, selectionStart) + (data ?? "") + value.slice(selectionEnd);
}
function getComposedPath(event) {
return event.composedPath?.() ?? event.nativeEvent?.composedPath?.();
}
function getEventTarget(event) {
const composedPath = getComposedPath(event);
return composedPath?.[0] ?? event.target;
}
function isOpeningInNewTab(event) {
const element = event.currentTarget;
if (!element) return false;
const validElement = element.matches("a[href], button[type='submit'], input[type='submit']");
if (!validElement) return false;
const isMiddleClick = event.button === 1;
const isModKeyClick = isCtrlOrMetaKey(event);
return isMiddleClick || isModKeyClick;
}
function isDownloadingEvent(event) {
const element = event.currentTarget;
if (!element) return false;
const localName = element.localName;
if (!event.altKey) return false;
if (localName === "a") return true;
if (localName === "button" && element.type === "submit") return true;
if (localName === "input" && element.type === "submit") return true;
return false;
}
function isComposingEvent(event) {
return getNativeEvent(event).isComposing || event.keyCode === 229;
}
function isCtrlOrMetaKey(e) {
if (isMac()) return e.metaKey;
return e.ctrlKey;
}
function isPrintableKey(e) {
return e.key.length === 1 && !e.ctrlKey && !e.metaKey;
}
function isVirtualClick(e) {
if (e.pointerType === "" && e.isTrusted) return true;
if (isAndroid() && e.pointerType) {
return e.type === "click" && e.buttons === 1;
}
return e.detail === 0 && !e.pointerType;
}
var isLeftClick = (e) => e.button === 0;
var isContextMenuEvent = (e) => {
return e.button === 2 || isMac() && e.ctrlKey && e.button === 0;
};
var isModifierKey = (e) => e.ctrlKey || e.altKey || e.metaKey;
var isTouchEvent = (event) => "touches" in event && event.touches.length > 0;
var keyMap = {
Up: "ArrowUp",
Down: "ArrowDown",
Esc: "Escape",
" ": "Space",
",": "Comma",
Left: "ArrowLeft",
Right: "ArrowRight"
};
var rtlKeyMap = {
ArrowLeft: "ArrowRight",
ArrowRight: "ArrowLeft"
};
function getEventKey(event, options = {}) {
const { dir = "ltr", orientation = "horizontal" } = options;
let key = event.key;
key = keyMap[key] ?? key;
const isRtl = dir === "rtl" && orientation === "horizontal";
if (isRtl && key in rtlKeyMap) key = rtlKeyMap[key];
return key;
}
function getNativeEvent(event) {
return event.nativeEvent ?? event;
}
var pageKeys = /* @__PURE__ */ new Set(["PageUp", "PageDown"]);
var arrowKeys = /* @__PURE__ */ new Set(["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"]);
function getEventStep(event) {
if (event.ctrlKey || event.metaKey) {
return 0.1;
} else {
const isPageKey = pageKeys.has(event.key);
const isSkipKey = isPageKey || event.shiftKey && arrowKeys.has(event.key);
return isSkipKey ? 10 : 1;
}
}
function getEventPoint(event, type = "client") {
const point = isTouchEvent(event) ? event.touches[0] || event.changedTouches[0] : event;
return { x: point[`${type}X`], y: point[`${type}Y`] };
}
var addDomEvent = (target, eventName, handler, options) => {
const node = typeof target === "function" ? target() : target;
node?.addEventListener(eventName, handler, options);
return () => {
node?.removeEventListener(eventName, handler, options);
};
};
function getDescriptor(el, options) {
const { type = "HTMLInputElement", property = "value" } = options;
const proto = getWindow(el)[type].prototype;
return Object.getOwnPropertyDescriptor(proto, property) ?? {};
}
function getElementType(el) {
if (el.localName === "input") return "HTMLInputElement";
if (el.localName === "textarea") return "HTMLTextAreaElement";
if (el.localName === "select") return "HTMLSelectElement";
}
function setElementValue(el, value, property = "value") {
if (!el) return;
const type = getElementType(el);
if (type) {
const descriptor = getDescriptor(el, { type, property });
descriptor.set?.call(el, value);
}
el.setAttribute(property, value);
}
function setElementChecked(el, checked) {
if (!el) return;
const descriptor = getDescriptor(el, { type: "HTMLInputElement", property: "checked" });
descriptor.set?.call(el, checked);
if (checked) el.setAttribute("checked", "");
else el.removeAttribute("checked");
}
function dispatchInputValueEvent(el, options) {
const { value, bubbles = true } = options;
if (!el) return;
const win = getWindow(el);
if (!(el instanceof win.HTMLInputElement)) return;
setElementValue(el, `${value}`);
el.dispatchEvent(new win.Event("input", { bubbles }));
}
function dispatchInputCheckedEvent(el, options) {
const { checked, bubbles = true } = options;
if (!el) return;
const win = getWindow(el);
if (!(el instanceof win.HTMLInputElement)) return;
setElementChecked(el, checked);
el.dispatchEvent(new win.Event("click", { bubbles }));
}
function getClosestForm(el) {
return isFormElement(el) ? el.form : el.closest("form");
}
function isFormElement(el) {
return el.matches("textarea, input, select, button");
}
function trackFormReset(el, callback) {
if (!el) return;
const form = getClosestForm(el);
const onReset = (e) => {
if (e.defaultPrevented) return;
callback();
};
form?.addEventListener("reset", onReset, { passive: true });
return () => form?.removeEventListener("reset", onReset);
}
function trackFieldsetDisabled(el, callback) {
const fieldset = el?.closest("fieldset");
if (!fieldset) return;
callback(fieldset.disabled);
const win = getWindow(fieldset);
const obs = new win.MutationObserver(() => callback(fieldset.disabled));
obs.observe(fieldset, {
attributes: true,
attributeFilter: ["disabled"]
});
return () => obs.disconnect();
}
function trackFormControl(el, options) {
if (!el) return;
const { onFieldsetDisabledChange, onFormReset } = options;
const cleanups = [trackFormReset(el, onFormReset), trackFieldsetDisabled(el, onFieldsetDisabledChange)];
return () => cleanups.forEach((cleanup) => cleanup?.());
}
var isFrame = (el) => isHTMLElement(el) && el.tagName === "IFRAME";
var NATURALLY_TABBABLE_REGEX = /^(audio|video|details)$/;
function parseTabIndex(el) {
const attr = el.getAttribute("tabindex");
if (!attr) return NaN;
return parseInt(attr, 10);
}
var hasTabIndex = (el) => !Number.isNaN(parseTabIndex(el));
var hasNegativeTabIndex = (el) => parseTabIndex(el) < 0;
function getShadowRootForNode(element, getShadowRoot) {
if (!getShadowRoot) return null;
if (getShadowRoot === true) {
return element.shadowRoot || null;
}
const result = getShadowRoot(element);
return (result === true ? element.shadowRoot : result) || null;
}
function collectElementsWithShadowDOM(elements, getShadowRoot, filterFn) {
const allElements = [...elements];
const toProcess = [...elements];
const processed = /* @__PURE__ */ new Set();
const positionMap = /* @__PURE__ */ new Map();
elements.forEach((el, i) => positionMap.set(el, i));
let processIndex = 0;
while (processIndex < toProcess.length) {
const element = toProcess[processIndex++];
if (!element || processed.has(element)) continue;
processed.add(element);
const shadowRoot = getShadowRootForNode(element, getShadowRoot);
if (shadowRoot) {
const shadowElements = Array.from(shadowRoot.querySelectorAll(focusableSelector)).filter(filterFn);
const hostIndex = positionMap.get(element);
if (hostIndex !== void 0) {
const insertPosition = hostIndex + 1;
allElements.splice(insertPosition, 0, ...shadowElements);
shadowElements.forEach((el, i) => {
positionMap.set(el, insertPosition + i);
});
for (let i = insertPosition + shadowElements.length; i < allElements.length; i++) {
positionMap.set(allElements[i], i);
}
} else {
const insertPosition = allElements.length;
allElements.push(...shadowElements);
shadowElements.forEach((el, i) => {
positionMap.set(el, insertPosition + i);
});
}
toProcess.push(...shadowElements);
}
}
return allElements;
}
var focusableSelector = "input:not([type='hidden']):not([disabled]), select:not([disabled]), textarea:not([disabled]), a[href], button:not([disabled]), [tabindex], iframe, object, embed, area[href], audio[controls], video[controls], [contenteditable]:not([contenteditable='false']), details > summary:first-of-type";
var getFocusables = (container, options = {}) => {
if (!container) return [];
const { includeContainer = false, getShadowRoot } = options;
const elements = Array.from(container.querySelectorAll(focusableSelector));
const include = includeContainer == true || includeContainer == "if-empty" && elements.length === 0;
if (include && isHTMLElement(container) && isFocusable(container)) {
elements.unshift(container);
}
const focusableElements = [];
for (const element of elements) {
if (!isFocusable(element)) continue;
if (isFrame(element) && element.contentDocument) {
const frameBody = element.contentDocument.body;
focusableElements.push(...getFocusables(frameBody, { getShadowRoot }));
continue;
}
focusableElements.push(element);
}
if (getShadowRoot) {
return collectElementsWithShadowDOM(focusableElements, getShadowRoot, isFocusable);
}
return focusableElements;
};
function isFocusable(element) {
if (!isHTMLElement(element) || element.closest("[inert]")) return false;
return element.matches(focusableSelector) && isElementVisible(element);
}
function getTabbables(container, options = {}) {
if (!container) return [];
const { includeContainer, getShadowRoot } = options;
const elements = Array.from(container.querySelectorAll(focusableSelector));
if (includeContainer && isTabbable(container)) {
elements.unshift(container);
}
const tabbableElements = [];
for (const element of elements) {
if (!isTabbable(element)) continue;
if (isFrame(element) && element.contentDocument) {
const frameBody = element.contentDocument.body;
tabbableElements.push(...getTabbables(frameBody, { getShadowRoot }));
continue;
}
tabbableElements.push(element);
}
if (getShadowRoot) {
const allElements = collectElementsWithShadowDOM(tabbableElements, getShadowRoot, isTabbable);
if (!allElements.length && includeContainer) {
return elements;
}
return allElements;
}
if (!tabbableElements.length && includeContainer) {
return elements;
}
return tabbableElements;
}
function isTabbable(el) {
if (isHTMLElement(el) && el.tabIndex > 0) return true;
return isFocusable(el) && !hasNegativeTabIndex(el);
}
function getTabbableEdges(container, options = {}) {
const elements = getTabbables(container, options);
const first2 = elements[0] || null;
const last2 = elements[elements.length - 1] || null;
return [first2, last2];
}
function getTabIndex(node) {
if (node.tabIndex < 0) {
if ((NATURALLY_TABBABLE_REGEX.test(node.localName) || isEditableElement(node)) && !hasTabIndex(node)) {
return 0;
}
}
return node.tabIndex;
}
function getInitialFocus(options) {
const { root, getInitialEl, filter, enabled = true } = options;
if (!enabled) return;
let node = null;
node || (node = typeof getInitialEl === "function" ? getInitialEl() : getInitialEl);
node || (node = root?.querySelector("[data-autofocus],[autofocus]"));
if (!node) {
const tabbables = getTabbables(root);
node = filter ? tabbables.filter(filter)[0] : tabbables[0];
}
return node || root || void 0;
}
function isValidTabEvent(event) {
const container = event.currentTarget;
if (!container) return false;
const [firstTabbable, lastTabbable] = getTabbableEdges(container);
if (isActiveElement(firstTabbable) && event.shiftKey) return false;
if (isActiveElement(lastTabbable) && !event.shiftKey) return false;
if (!firstTabbable && !lastTabbable) return false;
return true;
}
var AnimationFrame = class _AnimationFrame {
constructor() {
__publicField(this, "id", null);
__publicField(this, "fn_cleanup");
__publicField(this, "cleanup", () => {
this.cancel();
});
}
static create() {
return new _AnimationFrame();
}
request(fn) {
this.cancel();
this.id = globalThis.requestAnimationFrame(() => {
this.id = null;
this.fn_cleanup = fn?.();
});
}
cancel() {
if (this.id !== null) {
globalThis.cancelAnimationFrame(this.id);
this.id = null;
}
this.fn_cleanup?.();
this.fn_cleanup = void 0;
}
isActive() {
return this.id !== null;
}
};
function raf(fn) {
const frame = AnimationFrame.create();
frame.request(fn);
return frame.cleanup;
}
function nextTick(fn) {
const set = /* @__PURE__ */ new Set();
function raf2(fn2) {
const id = globalThis.requestAnimationFrame(fn2);
set.add(() => globalThis.cancelAnimationFrame(id));
}
raf2(() => raf2(fn));
return function cleanup() {
set.forEach((fn2) => fn2());
};
}
function queueBeforeEvent(el, type, cb) {
const cancelTimer = raf(() => {
el.removeEventListener(type, exec, true);
cb();
});
const exec = () => {
cancelTimer();
cb();
};
el.addEventListener(type, exec, { once: true, capture: true });
return cancelTimer;
}
function observeAttributesImpl(node, options) {
if (!node) return;
const { attributes, callback: fn } = options;
const win = node.ownerDocument.defaultView || window;
const obs = new win.MutationObserver((changes) => {
for (const change of changes) {
if (change.type === "attributes" && change.attributeName && attributes.includes(change.attributeName)) {
fn(change);
}
}
});
obs.observe(node, { attributes: true, attributeFilter: attributes });
return () => obs.disconnect();
}
function observeAttributes(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(observeAttributesImpl(node, options));
})
);
return () => {
cleanups.forEach((fn) => fn?.());
};
}
function observeChildrenImpl(node, options) {
const { callback: fn } = options;
if (!node) return;
const win = node.ownerDocument.defaultView || window;
const obs = new win.MutationObserver(fn);
obs.observe(node, { childList: true, subtree: true });
return () => obs.disconnect();
}
function observeChildren(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(observeChildrenImpl(node, options));
})
);
return () => {
cleanups.forEach((fn) => fn?.());
};
}
function clickIfLink(el) {
const click = () => {
const win = getWindow(el);
el.dispatchEvent(new win.MouseEvent("click"));
};
if (isFirefox()) {
queueBeforeEvent(el, "keyup", click);
} else {
queueMicrotask(click);
}
}
function getNearestOverflowAncestor(el) {
const parentNode = getParentNode(el);
if (isRootElement(parentNode)) return getDocument(parentNode).body;
if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) return parentNode;
return getNearestOverflowAncestor(parentNode);
}
var OVERFLOW_RE = /auto|scroll|overlay|hidden|clip/;
var nonOverflowValues = /* @__PURE__ */ new Set(["inline", "contents"]);
function isOverflowElement(el) {
const win = getWindow(el);
const { overflow, overflowX, overflowY, display } = win.getComputedStyle(el);
return OVERFLOW_RE.test(overflow + overflowY + overflowX) && !nonOverflowValues.has(display);
}
function isScrollable(el) {
return el.scrollHeight > el.clientHeight || el.scrollWidth > el.clientWidth;
}
function scrollIntoView(el, options) {
const { rootEl, ...scrollOptions } = options || {};
if (!el || !rootEl) return;
if (!isOverflowElement(rootEl) || !isScrollable(rootEl)) return;
el.scrollIntoView(scrollOptions);
}
function getRelativePoint(point, element) {
const { left, top, width, height } = element.getBoundingClientRect();
const offset = { x: point.x - left, y: point.y - top };
const percent = { x: clamp(offset.x / width), y: clamp(offset.y / height) };
function getPercentValue(options = {}) {
const { dir = "ltr", orientation = "horizontal", inverted } = options;
const invertX = typeof inverted === "object" ? inverted.x : inverted;
const invertY = typeof inverted === "object" ? inverted.y : inverted;
if (orientation === "horizontal") {
return dir === "rtl" || invertX ? 1 - percent.x : percent.x;
}
return invertY ? 1 - percent.y : percent.y;
}
return { offset, percent, getPercentValue };
}
function requestPointerLock(doc, fn) {
const body = doc.body;
const supported = "pointerLockElement" in doc || "mozPointerLockElement" in doc;
const isLocked = () => !!doc.pointerLockElement;
function onPointerChange() {
fn?.(isLocked());
}
function onPointerError(event) {
if (isLocked()) fn?.(false);
console.error("PointerLock error occurred:", event);
doc.exitPointerLock();
}
if (!supported) return;
try {
body.requestPointerLock();
} catch {
}
const cleanup = [
addDomEvent(doc, "pointerlockchange", onPointerChange, false),
addDomEvent(doc, "pointerlockerror", onPointerError, false)
];
return () => {
cleanup.forEach((cleanup2) => cleanup2());
doc.exitPointerLock();
};
}
var state = "default";
var userSelect = "";
var elementMap = /* @__PURE__ */ new WeakMap();
function disableTextSelectionImpl(options = {}) {
const { target, doc } = options;
const docNode = doc ?? document;
const rootEl = docNode.documentElement;
if (isIos()) {
if (state === "default") {
userSelect = rootEl.style.webkitUserSelect;
rootEl.style.webkitUserSelect = "none";
}
state = "disabled";
} else if (target) {
elementMap.set(target, target.style.userSelect);
target.style.userSelect = "none";
}
return () => restoreTextSelection({ target, doc: docNode });
}
function restoreTextSelection(options = {}) {
const { target, doc } = options;
const docNode = doc ?? document;
const rootEl = docNode.documentElement;
if (isIos()) {
if (state !== "disabled") return;
state = "restoring";
setTimeout(() => {
nextTick(() => {
if (state === "restoring") {
if (rootEl.style.webkitUserSelect === "none") {
rootEl.style.webkitUserSelect = userSelect || "";
}
userSelect = "";
state = "default";
}
});
}, 300);
} else {
if (target && elementMap.has(target)) {
const prevUserSelect = elementMap.get(target);
if (target.style.userSelect === "none") {
target.style.userSelect = prevUserSelect ?? "";
}
if (target.getAttribute("style") === "") {
target.removeAttribute("style");
}
elementMap.delete(target);
}
}
}
function disableTextSelection(options = {}) {
const { defer, target, ...restOptions } = options;
const func = defer ? raf : (v) => v();
const cleanups = [];
cleanups.push(
func(() => {
const node = typeof target === "function" ? target() : target;
cleanups.push(disableTextSelectionImpl({ ...restOptions, target: node }));
})
);
return () => {
cleanups.forEach((fn) => fn?.());
};
}
function trackPointerMove(doc, handlers) {
const { onPointerMove, onPointerUp } = handlers;
const handleMove = (event) => {
const point = getEventPoint(event);
const distance = Math.sqrt(point.x ** 2 + point.y ** 2);
const moveBuffer = event.pointerType === "touch" ? 10 : 5;
if (distance < moveBuffer) return;
if (event.pointerType === "mouse" && event.buttons === 0) {
handleUp(event);
return;
}
onPointerMove({ point, event });
};
const handleUp = (event) => {
const point = getEventPoint(event);
onPointerUp({ point, event });
};
const cleanups = [
addDomEvent(doc, "pointermove", handleMove, false),
addDomEvent(doc, "pointerup", handleUp, false),
addDomEvent(doc, "pointercancel", handleUp, false),
addDomEvent(doc, "contextmenu", handleUp, false),
disableTextSelection({ doc })
];
return () => {
cleanups.forEach((cleanup) => cleanup());
};
}
function trackPress(options) {
const {
pointerNode,
keyboardNode = pointerNode,
onPress,
onPressStart,
onPressEnd,
isValidKey = (e) => e.key === "Enter"
} = options;
if (!pointerNode) return noop;
const win = getWindow(pointerNode);
let removeStartListeners = noop;
let removeEndListeners = noop;
let removeAccessibleListeners = noop;
const getInfo = (event) => ({
point: getEventPoint(event),
event
});
function startPress(event) {
onPressStart?.(getInfo(event));
}
function cancelPress(event) {
onPressEnd?.(getInfo(event));
}
const startPointerPress = (startEvent) => {
removeEndListeners();
const endPointerPress = (endEvent) => {
const target = getEventTarget(endEvent);
if (contains(pointerNode, target)) {
onPress?.(getInfo(endEvent));
} else {
onPressEnd?.(getInfo(endEvent));
}
};
const removePointerUpListener = addDomEvent(win, "pointerup", endPointerPress, { passive: !onPress, once: true });
const removePointerCancelListener = addDomEvent(win, "pointercancel", cancelPress, {
passive: !onPressEnd,
once: true
});
removeEndListeners = pipe(removePointerUpListener, removePointerCancelListener);
if (isActiveElement(keyboardNode) && startEvent.pointerType === "mouse") {
startEvent.preventDefault();
}
startPress(startEvent);
};
const removePointerListener = addDomEvent(pointerNode, "pointerdown", startPointerPress, { passive: !onPressStart });
const removeFocusListener = addDomEvent(keyboardNode, "focus", startAccessiblePress);
removeStartListeners = pipe(removePointerListener, removeFocusListener);
function startAccessiblePress() {
const handleKeydown = (keydownEvent) => {
if (!isValidKey(keydownEvent)) return;
const handleKeyup = (keyupEvent) => {
if (!isValidKey(keyupEvent)) return;
const evt2 = new win.PointerEvent("pointerup");
const info = getInfo(evt2);
onPress?.(info);
onPressEnd?.(info);
};
removeEndListeners();
removeEndListeners = addDomEvent(keyboardNode, "keyup", handleKeyup);
const evt = new win.PointerEvent("pointerdown");
startPress(evt);
};
const handleBlur = () => {
const evt = new win.PointerEvent("pointercancel");
cancelPress(evt);
};
const removeKeydownListener = addDomEvent(keyboardNode, "keydown", handleKeydown);
const removeBlurListener = addDomEvent(keyboardNode, "blur", handleBlur);
removeAccessibleListeners = pipe(removeKeydownListener, removeBlurListener);
}
return () => {
removeStartListeners();
removeEndListeners();
removeAccessibleListeners();
};
}
function queryAll(root, selector) {
return Array.from(root?.querySelectorAll(selector) ?? []);
}
function query(root, selector) {
return root?.querySelector(selector) ?? null;
}
var defaultItemToId = (v) => v.id;
function itemById(v, id, itemToId = defaultItemToId) {
return v.find((item) => itemToId(item) === id);
}
function indexOfId(v, id, itemToId = defaultItemToId) {
const item = itemById(v, id, itemToId);
return item ? v.indexOf(item) : -1;
}
function nextById(v, id, loop = true) {
let idx = indexOfId(v, id);
idx = loop ? (idx + 1) % v.length : Math.min(idx + 1, v.length - 1);
return v[idx];
}
function prevById(v, id, loop = true) {
let idx = indexOfId(v, id);
if (idx === -1) return loop ? v[v.length - 1] : null;
idx = loop ? (idx - 1 + v.length) % v.length : Math.max(0, idx - 1);
return v[idx];
}
function createSharedResizeObserver(options) {
const listeners = /* @__PURE__ */ new WeakMap();
let observer;
const entries = /* @__PURE__ */ new WeakMap();
const getObserver = (win) => {
if (observer) return observer;
observer = new win.ResizeObserver((observedEntries) => {
for (const entry of observedEntries) {
entries.set(entry.target, entry);
const elementListeners = listeners.get(entry.target);
if (elementListeners) {
for (const listener of elementListeners) {
listener(entry);
}
}
}
});
return observer;
};
const observe = (element, listener) => {
let elementListeners = listeners.get(element) || /* @__PURE__ */ new Set();
elementListeners.add(listener);
listeners.set(element, elementListeners);
const win = getWindow(element);
getObserver(win).observe(element, options);
return () => {
const elementListeners2 = listeners.get(element);
if (!elementListeners2) return;
elementListeners2.delete(listener);
if (elementListeners2.size === 0) {
listeners.delete(element);
getObserver(win).unobserve(element);
}
};
};
const unobserve = (element) => {
listeners.delete(element);
observer?.unobserve(element);
};
return {
observe,
unobserve
};
}
var resizeObserverBorderBox = /* @__PURE__ */ createSharedResizeObserver({
box: "border-box"
});
var sanitize = (str) => str.split("").map((char) => {
const code = char.charCodeAt(0);
if (code > 0 && code < 128) return char;
if (code >= 128 && code <= 255) return `/x${code.toString(16)}`.replace("/", "\\");
return "";
}).join("").trim();
var getValueText = (el) => {
return sanitize(el.dataset?.valuetext ?? el.textContent ?? "");
};
var match = (valueText, query2) => {
return valueText.trim().toLowerCase().startsWith(query2.toLowerCase());
};
function getByText(v, text, currentId, itemToId = defaultItemToId) {
const index = currentId ? indexOfId(v, currentId, itemToId) : -1;
let items = currentId ? wrap(v, index) : v;
const isSingleKey = text.length === 1;
if (isSingleKey) {
items = items.filter((item) => itemToId(item) !== currentId);
}
return items.find((item) => match(getValueText(item), text));
}
function setAttribute(el, attr, v) {
const prev2 = el.getAttribute(attr);
const exists = prev2 != null;
if (prev2 === v) return noop;
el.setAttribute(attr, v);
return () => {
if (!exists) {
el.removeAttribute(attr);
} else {
el.setAttribute(attr, prev2);
}
};
}
function setStyle(el, style) {
if (!el) return noop;
const prev2 = Object.keys(style).reduce((acc, key) => {
acc[key] = el.style.getPropertyValue(key);
return acc;
}, {});
if (isEqual(prev2, style)) return noop;
Object.assign(el.style, style);
return () => {
Object.assign(el.style, prev2);
if (el.style.length === 0) {
el.removeAttribute("style");
}
};
}
function setStyleProperty(el, prop, value) {
if (!el) return noop;
const prev2 = el.style.getPropertyValue(prop);
if (prev2 === value) return noop;
el.style.setProperty(prop, value);
return () => {
el.style.setProperty(prop, prev2);
if (el.style.length === 0) {
el.removeAttribute("style");
}
};
}
function isEqual(a, b) {
return Object.keys(a).every((key) => a[key] === b[key]);
}
function getByTypeaheadImpl(baseItems, options) {
const { state: state2, activeId, key, timeout = 350, itemToId } = options;
const search = state2.keysSoFar + key;
const isRepeated = search.length > 1 && Array.from(search).every((char) => char === search[0]);
const query2 = isRepeated ? search[0] : search;
let items = baseItems.slice();
const next2 = getByText(items, query2, activeId, itemToId);
function cleanup() {
clearTimeout(state2.timer);
state2.timer = -1;
}
function update(value) {
state2.keysSoFar = value;
cleanup();
if (value !== "") {
state2.timer = +setTimeout(() => {
update("");
cleanup();
}, timeout);
}
}
update(search);
return next2;
}
var getByTypeahead = /* @__PURE__ */ Object.assign(getByTypeaheadImpl, {
defaultOptions: { keysSoFar: "", timer: -1 },
isValidEvent: isValidTypeaheadEvent
});
function isValidTypeaheadEvent(event) {
return event.key.length === 1 && !event.ctrlKey && !event.metaKey;
}
var visuallyHiddenStyle = {
border: "0",
clip: "rect(0 0 0 0)",
height: "1px",
margin: "-1px",
overflow: "hidden",
padding: "0",
position: "absolute",
width: "1px",
whiteSpace: "nowrap",
wordWrap: "normal"
};
function waitForPromise(promise, controller, timeout) {
const { signal } = controller;
const wrappedPromise = new Promise((resolve, reject) => {
const timeoutId = setTimeout(() => {
reject(new Error(`Timeout of ${timeout}ms exceeded`));
}, timeout);
signal.addEventListener("abort", () => {
clearTimeout(timeoutId);
reject(new Error("Promise aborted"));
});
promise.then((result) => {
if (!signal.aborted) {
clearTimeout(timeoutId);
resolve(result);
}
}).catch((error) => {
if (!signal.aborted) {
clearTimeout(timeoutId);
reject(error);
}
});
});
const abort = () => controller.abort();
return [wrappedPromise, abort];
}
function waitForElement(target, options) {
const { timeout, rootNode } = options;
const win = getWindow(rootNode);
const doc = getDocument(rootNode);
const controller = new win.AbortController();
return waitForPromise(
new Promise((resolve) => {
const el = target();
if (el) {
resolve(el);
return;
}
const observer = new win.MutationObserver(() => {
const el2 = target();
if (el2 && el2.isConnected) {
observer.disconnect();
resolve(el2);
}
});
observer.observe(doc.body, {
childList: true,
subtree: true
});
}),
controller,
timeout
);
}
// ../node_modules/.pnpm/@zag-js+utils@1.33.1/node_modules/@zag-js/utils/dist/index.mjs
var __defProp2 = Object.defineProperty;
var __typeError = (msg) => {
throw TypeError(msg);
};
var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField2 = (obj, key, value) => __defNormalProp2(obj, typeof key !== "symbol" ? key + "" : key, value);
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), member.get(obj));
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
function toArray(v) {
if (v == null) return [];
return Array.isArray(v) ? v : [v];
}
var first = (v) => v[0];
var last = (v) => v[v.length - 1];
var has = (v, t) => v.indexOf(t) !== -1;
var add = (v, ...items) => v.concat(items);
var remove = (v, ...items) => v.filter((t) => !items.includes(t));
var uniq = (v) => Array.from(new Set(v));
var diff = (a, b) => {
const set = new Set(b);
return a.filter((t) => !set.has(t));
};
var addOrRemove = (v, item) => has(v, item) ? remove(v, item) : add(v, item);
function nextIndex(v, idx, opts = {}) {
const { step = 1, loop = true } = opts;
const next2 = idx + step;
const len = v.length;
const last2 = len - 1;
if (idx === -1) return step > 0 ? 0 : last2;
if (next2 < 0) return loop ? last2 : 0;
if (next2 >= len) return loop ? 0 : idx > len ? len : idx;
return next2;
}
function next(v, idx, opts = {}) {
return v[nextIndex(v, idx, opts)];
}
function prevIndex(v, idx, opts = {}) {
const { step = 1, loop = true } = opts;
return nextIndex(v, idx, { step: -step, loop });
}
function prev(v, index, opts = {}) {
return v[prevIndex(v, index, opts)];
}
function chunk(v, size) {
return v.reduce((rows, value, index) => {
if (index % size === 0) rows.push([value]);
else last(rows)?.push(value);
return rows;
}, []);
}
function partition(arr, fn) {
return arr.reduce(
([pass, fail], value) => {
if (fn(value)) pass.push(value);
else fail.push(value);
return [pass, fail];
},
[[], []]
);
}
var isArrayLike = (value) => value?.constructor.name === "Array";
var isArrayEqual = (a, b) => {
if (a.length !== b.length) return false;
for (let i = 0; i < a.length; i++) {
if (!isEqual2(a[i], b[i])) return false;
}
return true;
};
var isEqual2 = (a, b) => {
if (Object.is(a, b)) return true;
if (a == null && b != null || a != null && b == null) return false;
if (typeof a?.isEqual === "function" && typeof b?.isEqual === "function") {
return a.isEqual(b);
}
if (typeof a === "function" && typeof b === "function") {
return a.toString() === b.toString();
}
if (isArrayLike(a) && isArrayLike(b)) {
return isArrayEqual(Array.from(a), Array.from(b));
}
if (!(typeof a === "object") || !(typeof b === "object")) return false;
const keys = Object.keys(b ?? /* @__PURE__ */ Object.create(null));
const length = keys.length;
for (let i = 0; i < length; i++) {
const hasKey = Reflect.has(a, keys[i]);
if (!hasKey) return false;
}
for (let i = 0; i < length; i++) {
const key = keys[i];
if (!isEqual2(a[key], b[key])) return false;
}
return true;
};
var isArray = (v) => Array.isArray(v);
var isBoolean = (v) => v === true || v === false;
var isObjectLike = (v) => v != null && typeof v === "object";
var isObject2 = (v) => isObjectLike(v) && !isArray(v);
var isString = (v) => typeof v === "string";
var isFunction = (v) => typeof v === "function";
var isNull = (v) => v == null;
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
var baseGetTag = (v) => Object.prototype.toString.call(v);
var fnToString = Function.prototype.toString;
var objectCtorString = fnToString.call(Object);
var isPlainObject = (v) => {
if (!isObjectLike(v) || baseGetTag(v) != "[object Object]" || isFrameworkElement(v)) return false;
const proto = Object.getPrototypeOf(v);
if (proto === null) return true;
const Ctor = hasProp(proto, "constructor") && proto.constructor;
return typeof Ctor == "function" && Ctor instanceof Ctor && fnToString.call(Ctor) == objectCtorString;
};
var isReactElement = (x) => typeof x === "object" && x !== null && "$$typeof" in x && "props" in x;
var isVueElement = (x) => typeof x === "object" && x !== null && "__v_isVNode" in x;
var isFrameworkElement = (x) => isReactElement(x) || isVueElement(x);
var runIfFn = (v, ...a) => {
const res = typeof v === "function" ? v(...a) : v;
return res ?? void 0;
};
var cast = (v) => v;
var identity = (v) => v();
var noop2 = () => {
};
var callAll = (...fns) => (...a) => {
fns.forEach(function(fn) {
fn?.(...a);
});
};
var uuid = /* @__PURE__ */ (() => {
let id = 0;
return () => {
id++;
return id.toString(36);
};
})();
function match2(key, record, ...args) {
if (key in record) {
const fn = record[key];
return isFunction(fn) ? fn(...args) : fn;
}
const error = new Error(`No matching key: ${JSON.stringify(key)} in ${JSON.stringify(Object.keys(record))}`);
Error.captureStackTrace?.(error, match2);
throw error;
}
function throttle(fn, wait = 0) {
let lastCall = 0;
let timeout = null;
return (...args) => {
const now = Date.now();
const timeSinceLastCall = now - lastCall;
if (timeSinceLastCall >= wait) {
if (timeout) {
clearTimeout(timeout);
timeout = null;
}
fn(...args);
lastCall = now;
} else if (!timeout) {
timeout = setTimeout(() => {
fn(...args);
lastCall = Date.now();
timeout = null;
}, wait - timeSinceLastCall);
}
};
}
var { floor, abs, round, min, max, pow, sign } = Math;
var isNaN = (v) => Number.isNaN(v);
var nan = (v) => isNaN(v) ? 0 : v;
var wrap2 = (v, vmax) => (v % vmax + vmax) % vmax;
var isValueAtMax = (v, vmax) => nan(v) >= vmax;
var isValueAtMin = (v, vmin) => nan(v) <= vmin;
var isValueWithinRange = (v, vmin, vmax) => {
const value = nan(v);
const minCheck = vmin == null || value >= vmin;
const maxCheck = vmax == null || value <= vmax;
return minCheck && maxCheck;
};
var clampValue = (v, vmin, vmax) => min(max(nan(v), vmin), vmax);
var roundToStepPrecision = (v, step) => {
let rv = v;
let ss = step.toString();
let pi = ss.indexOf(".");
let p = pi >= 0 ? ss.length - pi : 0;
if (p > 0) {
let pw = pow(10, p);
rv = round(rv * pw) / pw;
}
return rv;
};
var roundToDpr = (v, dpr) => typeof dpr === "number" ? floor(v * dpr + 0.5) / dpr : round(v);
var snapValueToStep = (v, vmin, vmax, step) => {
const min2 = vmin != null ? Number(vmin) : 0;
const max2 = Number(vmax);
const remainder = (v - min2) % step;
let snapped = abs(remainder) * 2 >= step ? v + sign(remainder) * (step - abs(remainder)) : v - remainder;
snapped = roundToStepPrecision(snapped, step);
if (!isNaN(min2) && snapped < min2) {
snapped = min2;
} else if (!isNaN(max2) && snapped > max2) {
const stepsInRange = floor((max2 - min2) / step);
const largestValidStep = min2 + stepsInRange * step;
snapped = stepsInRange <= 0 || largestValidStep < min2 ? max2 : largestValidStep;
}
return roundToStepPrecision(snapped, step);
};
var setValueAtIndex = (vs, i, v) => {
if (vs[i] === v) return vs;
return [...vs.slice(0, i), v, ...vs.slice(i + 1)];
};
var countDecimals = (value) => {
if (!Number.isFinite(value)) return 0;
let e = 1, p = 0;
while (Math.round(value * e) / e !== value) {
e *= 10;
p += 1;
}
return p;
};
var decimalOp = (a, op, b) => {
let result = op === "+" ? a + b : a - b;
if (a % 1 !== 0 || b % 1 !== 0) {
const multiplier = 10 ** Math.max(countDecimals(a), countDecimals(b));
a = Math.round(a * multiplier);
b = Math.round(b * multiplier);
result = op === "+" ? a + b : a - b;
result /= multiplier;
}
return result;
};
var incrementValue = (v, s) => decimalOp(nan(v), "+", s);
var decrementValue = (v, s) => decimalOp(nan(v), "-", s);
var toPx = (v) => typeof v === "number" ? `${v}px` : v;
function compact(obj) {
if (!isPlainObject(obj) || obj === void 0) return obj;
const keys = Reflect.ownKeys(obj).filter((key) => typeof key === "string");
const filtered = {};
for (const key of keys) {
const value = obj[key];
if (value !== void 0) {
filtered[key] = compact(value);
}
}
return filtered;
}
function pick(obj, keys) {
const filtered = {};
for (const key of keys) {
const value = obj[key];
if (value !== void 0) {
filtered[key] = value;
}
}
return filtered;
}
function splitProps(props, keys) {
const rest = {};
const result = {};
const keySet = new Set(keys);
const ownKeys = Reflect.ownKeys(props);
for (const key of ownKeys) {
if (keySet.has(key)) {
result[key] = props[key];
} else {
rest[key] = props[key];
}
}
return [result, rest];
}
var createSplitProps = (keys) => {
return function split(props) {
return splitProps(props, keys);
};
};
var currentTime = () => performance.now();
var _tick;
var Timer = class {
constructor(onTick) {
this.onTick = onTick;
__publicField2(this, "frameId", null);
__publicField2(this, "pausedAtMs", null);
__publicField2(this, "context");
__publicField2(this, "cancelFrame", () => {
if (this.frameId === null) return;
cancelAnimationFrame(this.frameId);
this.frameId = null;
});
__publicField2(this, "setStartMs", (startMs) => {
this.context.startMs = startMs;
});
__publicField2(this, "start", () => {
if (this.frameId !== null) return;
const now = currentTime();
if (this.pausedAtMs !== null) {
this.context.startMs += now - this.pausedAtMs;
this.pausedAtMs = null;
} else {
this.context.startMs = now;
}
this.frameId = requestAnimationFrame(__privateGet(this, _tick));
});
__publicField2(this, "pause", () => {
if (this.frameId === null) return;
this.cancelFrame();
this.pausedAtMs = currentTime();
});
__publicField2(this, "stop", () => {
if (this.frameId === null) return;
this.cancelFrame();
this.pausedAtMs = null;
});
__privateAdd(this, _tick, (now) => {
this.context.now = now;
this.context.deltaMs = now - this.context.startMs;
const shouldContinue = this.onTick(this.context);
if (shouldContinue === false) {
this.stop();
return;
}
this.frameId = requestAnimationFrame(__privateGet(this, _tick));
});
this.context = { now: 0, startMs: currentTime(), deltaMs: 0 };
}
get elapsedMs() {
if (this.pausedAtMs !== null) {
return this.pausedAtMs - this.context.startMs;
}
return currentTime() - this.context.startMs;
}
};
_tick = /* @__PURE__ */ new WeakMap();
function setRafInterval(fn, intervalMs) {
const timer = new Timer(({ now, deltaMs }) => {
if (deltaMs >= intervalMs) {
const startMs = intervalMs > 0 ? now - deltaMs % intervalMs : now;
timer.setStartMs(startMs);
fn({ startMs, deltaMs });
}
});
timer.start();
return () => timer.stop();
}
function setRafTimeout(fn, delayMs) {
const timer = new Timer(({ deltaMs }) => {
if (deltaMs >= delayMs) {
fn();
return false;
}
});
timer.start();
return () => timer.stop();
}
function warn(...a) {
const m = a.length === 1 ? a[0] : a[1];
const c = a.length === 2 ? a[0] : true;
if (c && true) {
console.warn(m);
}
}
function invariant(...a) {
const m = a.length === 1 ? a[0] : a[1];
const c = a.length === 2 ? a[0] : true;
if (c && true) {
throw new Error(m);
}
}
function ensure(c, m) {
if (c == null) throw new Error(m());
}
function ensureProps(props, keys, scope) {
let missingKeys = [];
for (const key of keys) {
if (props[key] == null) missingKeys.push(key);
}
if (missingKeys.length > 0)
throw new Error(`[zag-js${scope ? ` > ${scope}` : ""}] missing required props: ${missingKeys.join(", ")}`);
}
// ../node_modules/.pnpm/@zag-js+core@1.33.1/node_modules/@zag-js/core/dist/index.mjs
var clsx = (...args) => args.map((str) => str?.trim?.()).filter(Boolean).join(" ");
var CSS_REGEX = /((?:--)?(?:\w+-?)+)\s*:\s*([^;]*)/g;
var serialize = (style) => {
const res = {};
let match3;
while (match3 = CSS_REGEX.exec(style)) {
res[match3[1]] = match3[2];
}
return res;
};
var css = (a, b) => {
if (isString(a)) {
if (isString(b)) return `${a};${b}`;
a = serialize(a);
} else if (isString(b)) {
b = serialize(b);
}
return Object.assign({}, a ?? {}, b ?? {});
};
function mergeProps(...args) {
let result = {};
for (let props of args) {
if (!props) continue;
for (let key in result) {
if (key.startsWith("on") && typeof result[key] === "function" && typeof props[key] === "function") {
result[key] = callAll(props[key], result[key]);
continue;
}
if (key === "className" || key === "class") {
result[key] = clsx(result[key], props[key]);
continue;
}
if (key === "style") {
result[key] = css(result[key], props[key]);
continue;
}
result[key] = props[key] !== void 0 ? props[key] : result[key];
}
for (let key in props) {
if (result[key] === void 0) {
result[key] = props[key];
}
}
const symbols = Object.getOwnPropertySymbols(props);
for (let symbol of symbols) {
result[symbol] = props[symbol];
}
}
return result;
}
function memo(getDeps, fn, opts) {
let deps = [];
let result;
return (depArgs) => {
const newDeps = getDeps(depArgs);
const depsChanged = newDeps.length !== deps.length || newDeps.some((dep, index) => !isEqual2(deps[index], dep));
if (!depsChanged) return result;
deps = newDeps;
result = fn(newDeps, depArgs);
opts?.onChange?.(result);
return result;
};
}
function createGuards() {
return {
and: (...guards) => {
return function andGuard(params) {
return guards.every((str) => params.guard(str));
};
},
or: (...guards) => {
return function orGuard(params) {
return guards.some((str) => params.guard(str));
};
},
not: (guard) => {
return function notGuard(params) {
return !params.guard(guard);
};
}
};
}
function createMachine(config) {
return config;
}
function setup() {
return {
guards: createGuards(),
createMachine: (config) => {
return createMachine(config);
},
choose: (transitions) => {
return function chooseFn({ choose }) {
return choose(transitions)?.actions;
};
}
};
}
var MachineStatus = /* @__PURE__ */ ((MachineStatus2) => {
MachineStatus2["NotStarted"] = "Not Started";
MachineStatus2["Started"] = "Started";
MachineStatus2["Stopped"] = "Stopped";
return MachineStatus2;
})(MachineStatus || {});
var INIT_STATE = "__init__";
function createScope(props) {
const getRootNode2 = () => props.getRootNode?.() ?? document;
const getDoc = () => getDocument(getRootNode2());
const getWin = () => getDoc().defaultView ?? window;
const getActiveElementFn = () => getActiveElement(getRootNode2());
const getById = (id) => getRootNode2().getElementById(id);
return {
...props,
getRootNode: getRootNode2,
getDoc,
getWin,
getActiveElement: getActiveElementFn,
isActiveElement,
getById
};
}
// ../node_modules/.pnpm/@zag-js+types@1.33.1/node_modules/@zag-js/types/dist/index.mjs
function createNormalizer(fn) {
return new Proxy({}, {
get(_target, key) {
if (key === "style")
return (props) => {
return fn({ style: props }).style;
};
return fn;
}
});
}
var createProps = () => (props) => Array.from(new Set(props));
// ../node_modules/.pnpm/proxy-compare@3.0.1/node_modules/proxy-compare/dist/index.js
var TRACK_MEMO_SYMBOL = Symbol();
var GET_ORIGINAL_SYMBOL = Symbol();
var getProto = Object.getPrototypeOf;
var objectsToTrack = /* @__PURE__ */ new WeakMap();
var isObjectToTrack = (obj) => obj && (objectsToTrack.has(obj) ? objectsToTrack.get(obj) : getProto(obj) === Object.prototype || getProto(obj) === Array.prototype);
var getUntracked = (obj) => {
if (isObjectToTrack(obj)) {
return obj[GET_ORIGINAL_SYMBOL] || null;
}
return null;
};
var markToTrack = (obj, mark = true) => {
objectsToTrack.set(obj, mark);
};
// ../node_modules/.pnpm/@zag-js+store@1.33.1/node_modules/@zag-js/store/dist/index.mjs
function glob() {
if (typeof globalThis !== "undefined") return globalThis;
if (typeof self !== "undefined") return self;
if (typeof window !== "undefined") return window;
if (typeof global !== "undefined") return global;
}
function globalRef(key, value) {
const g = glob();
if (!g) return value();
g[key] || (g[key] = value());
return g[key];
}
var refSet = globalRef("__zag__refSet", () => /* @__PURE__ */ new WeakSet());
var isReactElement2 = (x) => typeof x === "object" && x !== null && "$$typeof" in x && "props" in x;
var isVueElement2 = (x) => typeof x === "object" && x !== null && "__v_isVNode" in x;
var isDOMElement = (x) => typeof x === "object" && x !== null && "nodeType" in x && typeof x.nodeName === "string";
var isElement = (x) => isReactElement2(x) || isVueElement2(x) || isDOMElement(x);
var isObject3 = (x) => x !== null && typeof x === "object";
var canProxy = (x) => isObject3(x) && !refSet.has(x) && (Array.isArray(x) || !(Symbol.iterator in x)) && !isElement(x) && !(x instanceof WeakMap) && !(x instanceof WeakSet) && !(x instanceof Error) && !(x instanceof Number) && !(x instanceof Date) && !(x instanceof String) && !(x instanceof RegExp) && !(x instanceof ArrayBuffer) && !(x instanceof Promise) && !(x instanceof File) && !(x instanceof Blob) && !(x instanceof AbortController);
var isDev = () => true;
var proxyStateMap = globalRef("__zag__proxyStateMap", () => /* @__PURE__ */ new WeakMap());
var buildProxyFunction = (objectIs = Object.is, newProxy = (target, handler) => new Proxy(target, handler), snapCache = /* @__PURE__ */ new WeakMap(), createSnapshot = (target, version) => {
const cache = snapCache.get(target);
if (cache?.[0] === version) {
return cache[1];
}
const snap = Array.isArray(target) ? [] : Object.create(Object.getPrototypeOf(target));
markToTrack(snap, true);
snapCache.set(target, [version, snap]);
Reflect.ownKeys(target).forEach((key) => {
const value = Reflect.get(target, key);
if (refSet.has(value)) {
markToTrack(value, false);
snap[key] = value;
} else if (proxyStateMap.has(value)) {
snap[key] = snapshot(value);
} else {
snap[key] = value;
}
});
return Object.freeze(snap);
}, proxyCache = /* @__PURE__ */ new WeakMap(), versionHolder = [1, 1], proxyFunction2 = (initialObject) => {
if (!isObject3(initialObject)) {
throw new Error("object required");
}
const found = proxyCache.get(initialObject);
if (found) {
return found;
}
let version = versionHolder[0];
const listeners = /* @__PURE__ */ new Set();
const notifyUpdate = (op, nextVersion = ++versionHolder[0]) => {
if (version !== nextVersion) {
version = nextVersion;
listeners.forEach((listener) => listener(op, nextVersion));
}
};
let checkVersion = versionHolder[1];
const ensureVersion = (nextCheckVersion = ++versionHolder[1]) => {
if (checkVersion !== nextCheckVersion && !listeners.size) {
checkVersion = nextCheckVersion;
propProxyStates.forEach(([propProxyState]) => {
const propVersion = propProxyState[1](nextCheckVersion);
if (propVersion > version) {
version = propVersion;
}
});
}
return version;
};
const createPropListener = (prop) => (op, nextVersion) => {
const newOp = [...op];
newOp[1] = [prop, ...newOp[1]];
notifyUpdate(newOp, nextVersion);
};
const propProxyStates = /* @__PURE__ */ new Map();
const addPropListener = (prop, propProxyState) => {
if (isDev() && propProxyStates.has(prop)) {
throw new Error("prop listener already exists");
}
if (listeners.size) {
const remove2 = propProxyState[3](createPropListener(prop));
propProxyStates.set(prop, [propProxyState, remove2]);
} else {
propProxyStates.set(prop, [propProxyState]);
}
};
const removePropListener = (prop) => {
const entry = propProxyStates.get(prop);
if (entry) {
propProxyStates.delete(prop);
entry[1]?.();
}
};
const addListener = (listener) => {
listeners.add(listener);
if (listeners.size === 1) {
propProxyStates.forEach(([propProxyState, prevRemove], prop) => {
if (isDev() && prevRemove) {
throw new Error("remove already exists");
}
const remove2 = propProxyState[3](createPropListener(prop));
propProxyStates.set(prop, [propProxyState, remove2]);
});
}
const removeListener = () => {
listeners.delete(listener);
if (listeners.size === 0) {
propProxyStates.forEach(([propProxyState, remove2], prop) => {
if (remove2) {
remove2();
propProxyStates.set(prop, [propProxyState]);
}
});
}
};
return removeListener;
};
const baseObject = Array.isArray(initialObject) ? [] : Object.create(Object.getPrototypeOf(initialObject));
const handler = {
deleteProperty(target, prop) {
const prevValue = Reflect.get(target, prop);
removePropListener(prop);
const deleted = Reflect.deleteProperty(target, prop);
if (deleted) {
notifyUpdate(["delete", [prop], prevValue]);
}
return deleted;
},
set(target, prop, value, receiver) {
const hasPrevValue = Reflect.has(target, prop);
const prevValue = Reflect.get(target, prop, receiver);
if (hasPrevValue && (objectIs(prevValue, value) || proxyCache.has(value) && objectIs(prevValue, proxyCache.get(value)))) {
return true;
}
removePropListener(prop);
if (isObject3(value)) {
value = getUntracked(value) || value;
}
let nextValue = value;
if (Object.getOwnPropertyDescriptor(target, prop)?.set) ;
else {
if (!proxyStateMap.has(value) && canProxy(value)) {
nextValue = proxy(value);
}
const childProxyState = !refSet.has(nextValue) && proxyStateMap.get(nextValue);
if (childProxyState) {
addPropListener(prop, childProxyState);
}
}
Reflect.set(target, prop, nextValue, receiver);
notifyUpdate(["set", [prop], value, prevValue]);
return true;
}
};
const proxyObject = newProxy(baseObject, handler);
proxyCache.set(initialObject, proxyObject);
const proxyState = [baseObject, ensureVersion, createSnapshot, addListener];
proxyStateMap.set(proxyObject, proxyState);
Reflect.ownKeys(initialObject).forEach((key) => {
const desc = Object.getOwnPropertyDescriptor(initialObject, key);
if (desc.get || desc.set) {
Object.defineProperty(baseObject, key, desc);
} else {
proxyObject[key] = initialObject[key];
}
});
return proxyObject;
}) => [
// public functions
proxyFunction2,
// shared state
proxyStateMap,
refSet,
// internal things
objectIs,
newProxy,
canProxy,
snapCache,
createSnapshot,
proxyCache,
versionHolder
];
var [proxyFunction] = buildProxyFunction();
function proxy(initialObject = {}) {
return proxyFunction(initialObject);
}
function subscribe(proxyObject, callback, notifyInSync) {
const proxyState = proxyStateMap.get(proxyObject);
if (isDev() && !proxyState) {
console.warn("Please use proxy object");
}
let promise;
const ops = [];
const addListener = proxyState[3];
let isListenerActive = false;
const listener = (op) => {
ops.push(op);
if (notifyInSync) {
callback(ops.splice(0));
return;
}
if (!promise) {
promise = Promise.resolve().then(() => {
promise = void 0;
if (isListenerActive) {
callback(ops.splice(0));
}
});
}
};
const removeListener = addListener(listener);
isListenerActive = true;
return () => {
isListenerActive = false;
removeListener();
};
}
function snapshot(proxyObject) {
const proxyState = proxyStateMap.get(proxyObject);
if (isDev() && !proxyState) {
console.warn("Please use proxy object");
}
const [target, ensureVersion, createSnapshot] = proxyState;
return createSnapshot(target, ensureVersion());
}
// ../node_modules/.pnpm/@zag-js+vanilla@1.33.1/node_modules/@zag-js/vanilla/dist/index.mjs
var __defProp3 = Object.defineProperty;
var __defNormalProp3 = (obj, key, value) => key in obj ? __defProp3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField3 = (obj, key, value) => __defNormalProp3(obj, typeof key !== "symbol" ? key + "" : key, value);
var propMap = {
onFocus: "onFocusin",
onBlur: "onFocusout",
onChange: "onInput",
onDoubleClick: "onDblclick",
htmlFor: "for",
className: "class",
defaultValue: "value",
defaultChecked: "checked"
};
var caseSensitiveSvgAttrs = /* @__PURE__ */ new Set(["viewBox", "preserveAspectRatio"]);
var toStyleString = (style) => {
let string = "";
for (let key in style) {
const value = style[key];
if (value === null || value === void 0) continue;
if (!key.startsWith("--")) key = key.replace(/[A-Z]/g, (match3) => `-${match3.toLowerCase()}`);
string += `${key}:${value};`;
}
return string;
};
var normalizeProps = createNormalizer((props) => {
return Object.entries(props).reduce((acc, [key, value]) => {
if (value === void 0) return acc;
if (key in propMap) {
key = propMap[key];
}
if (key === "style" && typeof value === "object") {
acc.style = toStyleString(value);
return acc;
}
const normalizedKey = caseSensitiveSvgAttrs.has(key) ? key : key.toLowerCase();
acc[normalizedKey] = value;
return acc;
}, {});
});
var prevAttrsMap = /* @__PURE__ */ new WeakMap();
var assignableProps = /* @__PURE__ */ new Set(["value", "checked", "selected"]);
var caseSensitiveSvgAttrs2 = /* @__PURE__ */ new Set([
"viewBox",
"preserveAspectRatio",
"clipPath",
"clipRule",
"fillRule",
"strokeWidth",
"strokeLinecap",
"strokeLinejoin",
"strokeDasharray",
"strokeDashoffset",
"strokeMiterlimit"
]);
var isSvgElement = (node) => {
return node.tagName === "svg" || node.namespaceURI === "http://www.w3.org/2000/svg";
};
var getAttributeName = (node, attrName) => {
const shouldPreserveCase = isSvgElement(node) && caseSensitiveSvgAttrs2.has(attrName);
return shouldPreserveCase ? attrName : attrName.toLowerCase();
};
function spreadProps(node, attrs, machineId) {
const scopeKey = machineId || "default";
let machineMap = prevAttrsMap.get(node);
if (!machineMap) {
machineMap = /* @__PURE__ */ new Map();
prevAttrsMap.set(node, machineMap);
}
const oldAttrs = machineMap.get(scopeKey) || {};
const attrKeys = Object.keys(attrs);
const addEvt = (e, f) => {
node.addEventListener(e.toLowerCase(), f);
};
const remEvt = (e, f) => {
node.removeEventListener(e.toLowerCase(), f);
};
const onEvents = (attr) => attr.startsWith("on");
const others = (attr) => !attr.startsWith("on");
const setup2 = (attr) => addEvt(attr.substring(2), attrs[attr]);
const teardown = (attr) => remEvt(attr.substring(2), attrs[attr]);
const apply = (attrName) => {
const value = attrs[attrName];
const oldValue = oldAttrs[attrName];
if (value === oldValue) return;
if (attrName === "class") {
node.className = value ?? "";
return;
}
if (assignableProps.has(attrName)) {
node[attrName] = value ?? "";
return;
}
if (typeof value === "boolean" && !attrName.includes("aria-")) {
node.toggleAttribute(getAttributeName(node, attrName), value);
return;
}
if (attrName === "children") {
node.innerHTML = value;
return;
}
if (value != null) {
node.setAttribute(getAttributeName(node, attrName), value);
return;
}
node.removeAttribute(getAttributeName(node, attrName));
};
for (const key in oldAttrs) {
if (attrs[key] == null) {
if (key === "class") {
node.className = "";
} else if (assignableProps.has(key)) {
node[key] = "";
} else {
node.removeAttribute(getAttributeName(node, key));
}
}
}
const oldEvents = Object.keys(oldAttrs).filter(onEvents);
oldEvents.forEach((evt) => {
remEvt(evt.substring(2), oldAttrs[evt]);
});
attrKeys.filter(onEvents).forEach(setup2);
attrKeys.filter(others).forEach(apply);
machineMap.set(scopeKey, attrs);
return function cleanup() {
attrKeys.filter(onEvents).forEach(teardown);
const currentMachineMap = prevAttrsMap.get(node);
if (currentMachineMap) {
currentMachineMap.delete(scopeKey);
if (currentMachineMap.size === 0) {
prevAttrsMap.delete(node);
}
}
};
}
function bindable(props) {
const initial = props().value ?? props().defaultValue;
if (props().debug) {
console.log(`[bindable > ${props().debug}] initial`, initial);
}
const eq = props().isEqual ?? Object.is;
const store = proxy({ value: initial });
const controlled = () => props().value !== void 0;
return {
initial,
ref: store,
get() {
return controlled() ? props().value : store.value;
},
set(nextValue) {
const prev2 = store.value;
const next2 = isFunction(nextValue) ? nextValue(prev2) : nextValue;
if (props().debug) {
console.log(`[bindable > ${props().debug}] setValue`, { next: next2, prev: prev2 });
}
if (!controlled()) store.value = next2;
if (!eq(next2, prev2)) {
props().onChange?.(next2, prev2);
}
},
invoke(nextValue, prevValue) {
props().onChange?.(nextValue, prevValue);
},
hash(value) {
return props().hash?.(value) ?? String(value);
}
};
}
bindable.cleanup = (_fn) => {
};
bindable.ref = (defaultValue) => {
let value = defaultValue;
return {
get: () => value,
set: (next2) => {
value = next2;
}
};
};
function createRefs(refs) {
const ref = { current: refs };
return {
get(key) {
return ref.current[key];
},
set(key, value) {
ref.current[key] = value;
}
};
}
function mergeMachineProps(prev2, next2) {
if (!isPlainObject(prev2) || !isPlainObject(next2)) {
return next2 === void 0 ? prev2 : next2;
}
const result = { ...prev2 };
for (const key of Object.keys(next2)) {
const nextValue = next2[key];
const prevValue = prev2[key];
if (nextValue === void 0) {
continue;
}
if (isPlainObject(prevValue) && isPlainObject(nextValue)) {
result[key] = mergeMachineProps(prevValue, nextValue);
} else {
result[key] = nextValue;
}
}
return result;
}
var VanillaMachine = class {
constructor(machine, userProps = {}) {
this.machine = machine;
__publicField3(this, "scope");
__publicField3(this, "context");
__publicField3(this, "prop");
__publicField3(this, "state");
__publicField3(this, "refs");
__publicField3(this, "computed");
__publicField3(this, "event", { type: "" });
__publicField3(this, "previousEvent", { type: "" });
__publicField3(this, "effects", /* @__PURE__ */ new Map());
__publicField3(this, "transition", null);
__publicField3(this, "cleanups", []);
__publicField3(this, "subscriptions", []);
__publicField3(this, "userPropsRef");
__publicField3(this, "getEvent", () => ({
...this.event,
current: () => this.event,
previous: () => this.previousEvent
}));
__publicField3(this, "getStateConfig", (state3) => {
return this.machine.states[state3];
});
__publicField3(this, "getState", () => ({
...this.state,
matches: (...values) => values.includes(this.state.get()),
hasTag: (tag) => !!this.getStateConfig(this.state.get())?.tags?.includes(tag)
}));
__publicField3(this, "debug", (...args) => {
if (this.machine.debug) console.log(...args);
});
__publicField3(this, "notify", () => {
this.publish();
});
__publicField3(this, "send", (event) => {
if (this.status !== MachineStatus.Started) return;
queueMicrotask(() => {
if (!event) return;
this.previousEvent = this.event;
this.event = event;
this.debug("send", event);
let currentState = this.state.get();
const eventType = event.type;
const transitions = this.getStateConfig(currentState)?.on?.[eventType] ?? this.machine.on?.[eventType];
const transition = this.choose(transitions);
if (!transition) return;
this.transition = transition;
const target = transition.target ?? currentState;
this.debug("transition", transition);
const changed = target !== currentState;
if (changed) {
this.state.set(target);
} else if (transition.reenter && !changed) {
this.state.invoke(currentState, currentState);
} else {
this.action(transition.actions);
}
});
});
__publicField3(this, "action", (keys) => {
const strs = isFunction(keys) ? keys(this.getParams()) : keys;
if (!strs) return;
const fns = strs.map((s) => {
const fn = this.machine.implementations?.actions?.[s];
if (!fn) warn(`[zag-js] No implementation found for action "${JSON.stringify(s)}"`);
return fn;
});
for (const fn of fns) {
fn?.(this.getParams());
}
});
__publicField3(this, "guard", (str) => {
if (isFunction(str)) return str(this.getParams());
return this.machine.implementations?.guards?.[str](this.getParams());
});
__publicField3(this, "effect", (keys) => {
const strs = isFunction(keys) ? keys(this.getParams()) : keys;
if (!strs) return;
const fns = strs.map((s) => {
const fn = this.machine.implementations?.effects?.[s];
if (!fn) warn(`[zag-js] No implementation found for effect "${JSON.stringify(s)}"`);
return fn;
});
const cleanups = [];
for (const fn of fns) {
const cleanup = fn?.(this.getParams());
if (cleanup) cleanups.push(cleanup);
}
return () => cleanups.forEach((fn) => fn?.());
});
__publicField3(this, "choose", (transitions) => {
return toArray(transitions).find((t) => {
let result = !t.guard;
if (isString(t.guard)) result = !!this.guard(t.guard);
else if (isFunction(t.guard)) result = t.guard(this.getParams());
return result;
});
});
__publicField3(this, "subscribe", (fn) => {
this.subscriptions.push(fn);
return () => {
const index = this.subscriptions.indexOf(fn);
if (index > -1) this.subscriptions.splice(index, 1);
};
});
__publicField3(this, "status", MachineStatus.NotStarted);
__publicField3(this, "publish", () => {
this.callTrackers();
this.subscriptions.forEach((fn) => fn(this.service));
});
__publicField3(this, "trackers", []);
__publicField3(this, "setupTrackers", () => {
this.machine.watch?.(this.getParams());
});
__publicField3(this, "callTrackers", () => {
this.trackers.forEach(({ deps, fn }) => {
const next2 = deps.map((dep) => dep());
if (!isEqual2(fn.prev, next2)) {
fn();
fn.prev = next2;
}
});
});
__publicField3(this, "getParams", () => ({
state: this.getState(),
context: this.context,
event: this.getEvent(),
prop: this.prop,
send: this.send,
action: this.action,
guard: this.guard,
track: (deps, fn) => {
fn.prev = deps.map((dep) => dep());
this.trackers.push({ deps, fn });
},
refs: this.refs,
computed: this.computed,
flush: identity,
scope: this.scope,
choose: this.choose
}));
this.userPropsRef = { current: userProps };
const { id, ids, getRootNode: getRootNode2 } = runIfFn(userProps);
this.scope = createScope({ id, ids, getRootNode: getRootNode2 });
const prop = (key) => {
const __props = runIfFn(this.userPropsRef.current);
const props = machine.props?.({ props: compact(__props), scope: this.scope }) ?? __props;
return props[key];
};
this.prop = prop;
const context = machine.context?.({
prop,
bindable,
scope: this.scope,
flush(fn) {
queueMicrotask(fn);
},
getContext() {
return ctx;
},
getComputed() {
return computed;
},
getRefs() {
return refs;
},
getEvent: this.getEvent.bind(this)
});
if (context) {
Object.values(context).forEach((item) => {
const unsub = subscribe(item.ref, () => this.notify());
this.cleanups.push(unsub);
});
}
const ctx = {
get(key) {
return context?.[key].get();
},
set(key, value) {
context?.[key].set(value);
},
initial(key) {
return context?.[key].initial;
},
hash(key) {
const current = context?.[key].get();
return context?.[key].hash(current);
}
};
this.context = ctx;
const computed = (key) => {
return machine.computed?.[key]({
context: ctx,
event: this.getEvent(),
prop,
refs: this.refs,
scope: this.scope,
computed
}) ?? {};
};
this.computed = computed;
const refs = createRefs(machine.refs?.({ prop, context: ctx }) ?? {});
this.refs = refs;
const state2 = bindable(() => ({
defaultValue: machine.initialState({ prop }),
onChange: (nextState, prevState) => {
if (prevState) {
const exitEffects = this.effects.get(prevState);
exitEffects?.();
this.effects.delete(prevState);
}
if (prevState) {
this.action(this.getStateConfig(prevState)?.exit);
}
this.action(this.transition?.actions);
const cleanup = this.effect(this.getStateConfig(nextState)?.effects);
if (cleanup) this.effects.set(nextState, cleanup);
if (prevState === INIT_STATE) {
this.action(machine.entry);
const cleanup2 = this.effect(machine.effects);
if (cleanup2) this.effects.set(INIT_STATE, cleanup2);
}
this.action(this.getStateConfig(nextState)?.entry);
}
}));
this.state = state2;
this.cleanups.push(subscribe(this.state.ref, () => this.notify()));
}
updateProps(newProps) {
const prevSource = this.userPropsRef.current;
this.userPropsRef.current = () => {
const prev2 = runIfFn(prevSource);
const next2 = runIfFn(newProps);
return mergeMachineProps(prev2, next2);
};
this.notify();
}
start() {
this.status = MachineStatus.Started;
this.debug("initializing...");
this.state.invoke(this.state.initial, INIT_STATE);
this.setupTrackers();
}
stop() {
this.effects.forEach((fn) => fn?.());
this.effects.clear();
this.transition = null;
this.action(this.machine.exit);
this.cleanups.forEach((unsub) => unsub());
this.cleanups = [];
this.subscriptions = [];
this.status = MachineStatus.Stopped;
this.debug("unmounting...");
}
get service() {
return {
state: this.getState(),
send: this.send,
context: this.context,
prop: this.prop,
scope: this.scope,
refs: this.refs,
computed: this.computed,
event: this.getEvent(),
getStatus: () => this.status
};
}
};
// lib/core.ts
var Component = class {
el;
doc;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
machine;
api;
constructor(el, props) {
if (!el) throw new Error("Root element not found");
this.el = el;
this.doc = document;
this.machine = this.initMachine(props);
this.api = this.initApi();
}
init = () => {
this.render();
this.machine.subscribe(() => {
this.api = this.initApi();
this.render();
});
this.machine.start();
};
destroy = () => {
this.machine.stop();
};
spreadProps = (el, props) => {
spreadProps(el, props, this.machine.scope.id);
};
updateProps = (props) => {
this.machine.updateProps(props);
};
};
export {
createAnatomy,
setCaretToEnd,
MAX_Z_INDEX,
dataAttr,
ariaAttr,
isHTMLElement,
isDocument,
isShadowRoot,
isAnchorElement,
isEditableElement,
contains,
getDocument,
getWindow,
getActiveElement,
getComputedStyle,
isControlledElement,
findControlledElements,
getControlledElements,
hasControllerElements,
isControlledByExpandedController,
getDataUrl,
isTouchDevice,
isIos,
isApple,
isMac,
isSafari,
getBeforeInputValue,
getEventTarget,
isOpeningInNewTab,
isDownloadingEvent,
isComposingEvent,
isCtrlOrMetaKey,
isPrintableKey,
isVirtualClick,
isLeftClick,
isContextMenuEvent,
isModifierKey,
getEventKey,
getNativeEvent,
getEventStep,
getEventPoint,
addDomEvent,
setElementValue,
setElementChecked,
dispatchInputValueEvent,
dispatchInputCheckedEvent,
trackFormControl,
getFocusables,
isFocusable,
getTabbables,
isTabbable,
getTabIndex,
getInitialFocus,
isValidTabEvent,
AnimationFrame,
raf,
nextTick,
observeAttributes,
observeChildren,
clickIfLink,
getNearestOverflowAncestor,
scrollIntoView,
getRelativePoint,
requestPointerLock,
restoreTextSelection,
disableTextSelection,
trackPointerMove,
trackPress,
queryAll,
query,
itemById,
nextById,
prevById,
resizeObserverBorderBox,
setAttribute,
setStyle,
setStyleProperty,
getByTypeahead,
visuallyHiddenStyle,
waitForElement,
toArray,
first,
last,
add,
remove,
uniq,
diff,
addOrRemove,
nextIndex,
next,
prevIndex,
prev,
chunk,
partition,
isEqual2 as isEqual,
isArray,
isBoolean,
isObject2 as isObject,
isFunction,
isNull,
hasProp,
runIfFn,
cast,
noop2 as noop,
callAll,
uuid,
match2 as match,
throttle,
wrap2 as wrap,
isValueAtMax,
isValueAtMin,
isValueWithinRange,
clampValue,
roundToDpr,
snapValueToStep,
setValueAtIndex,
incrementValue,
decrementValue,
toPx,
compact,
pick,
createSplitProps,
setRafInterval,
setRafTimeout,
warn,
invariant,
ensure,
ensureProps,
mergeProps,
memo,
createGuards,
createMachine,
setup,
createProps,
proxy,
subscribe,
normalizeProps,
VanillaMachine,
Component,
getDir,
getString,
getStringList,
getNumber,
getBoolean,
generateId
};