Packages
corex
0.1.0-alpha.30
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-ZOODJA3P.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)}`;
};
function canPushEvent(liveSocket) {
return !liveSocket.main.isDead && liveSocket.main.isConnected();
}
// ../node_modules/.pnpm/@zag-js+vanilla@1.36.0/node_modules/@zag-js/vanilla/dist/chunk-QZ7TP4HQ.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);
// ../node_modules/.pnpm/@zag-js+types@1.36.0/node_modules/@zag-js/types/dist/prop-types.mjs
function createNormalizer(fn) {
return new Proxy({}, {
get(_target, key) {
if (key === "style")
return (props) => {
return fn({ style: props }).style;
};
return fn;
}
});
}
// ../node_modules/.pnpm/@zag-js+vanilla@1.36.0/node_modules/@zag-js/vanilla/dist/normalize-props.mjs
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;
}, {});
});
// ../node_modules/.pnpm/@zag-js+utils@1.36.0/node_modules/@zag-js/utils/dist/chunk-MXGZDBDQ.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"), getter ? getter.call(obj) : 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);
// ../node_modules/.pnpm/@zag-js+utils@1.36.0/node_modules/@zag-js/utils/dist/array.mjs
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];
},
[[], []]
);
}
// ../node_modules/.pnpm/@zag-js+utils@1.36.0/node_modules/@zag-js/utils/dist/equal.mjs
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 (!isEqual(a[i], b[i])) return false;
}
return true;
};
var isEqual = (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 (!isEqual(a[key], b[key])) return false;
}
return true;
};
// ../node_modules/.pnpm/@zag-js+utils@1.36.0/node_modules/@zag-js/utils/dist/guard.mjs
var isArray = (v) => Array.isArray(v);
var isBoolean = (v) => v === true || v === false;
var isObjectLike = (v) => v != null && typeof v === "object";
var isObject = (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);
// ../node_modules/.pnpm/@zag-js+utils@1.36.0/node_modules/@zag-js/utils/dist/functions.mjs
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 noop = () => {
};
var callAll = (...fns) => (...a) => {
fns.forEach(function(fn) {
fn?.(...a);
});
};
var uuid = /* @__PURE__ */ (() => {
let id = 0;
return () => {
id++;
return id.toString(36);
};
})();
function match(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, match);
throw error;
}
var tryCatch = (fn, fallback) => {
try {
return fn();
} catch (error) {
if (error instanceof Error) {
Error.captureStackTrace?.(error, tryCatch);
}
return fallback?.();
}
};
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);
}
};
}
// ../node_modules/.pnpm/@zag-js+utils@1.36.0/node_modules/@zag-js/utils/dist/object.mjs
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;
}
// ../node_modules/.pnpm/@zag-js+utils@1.36.0/node_modules/@zag-js/utils/dist/warning.mjs
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.36.0/node_modules/@zag-js/core/dist/state.mjs
var STATE_DELIMITER = ".";
var ABSOLUTE_PREFIX = "#";
var stateIndexCache = /* @__PURE__ */ new WeakMap();
var stateIdIndexCache = /* @__PURE__ */ new WeakMap();
function joinStatePath(parts) {
return parts.join(STATE_DELIMITER);
}
function isAbsoluteStatePath(value) {
return value.includes(STATE_DELIMITER);
}
function isExplicitAbsoluteStatePath(value) {
return value.startsWith(ABSOLUTE_PREFIX);
}
function stripAbsolutePrefix(value) {
return isExplicitAbsoluteStatePath(value) ? value.slice(ABSOLUTE_PREFIX.length) : value;
}
function appendStatePath(base, segment) {
return base ? `${base}${STATE_DELIMITER}${segment}` : segment;
}
function buildStateIndex(machine) {
const index = /* @__PURE__ */ new Map();
const idIndex = /* @__PURE__ */ new Map();
const visit = (basePath, state2) => {
index.set(basePath, state2);
const stateId = state2.id;
if (stateId) {
if (idIndex.has(stateId)) {
throw new Error(`Duplicate state id: ${stateId}`);
}
idIndex.set(stateId, basePath);
}
const childStates = state2.states;
if (!childStates) return;
for (const [childKey, childState] of Object.entries(childStates)) {
if (!childState) continue;
const childPath = appendStatePath(basePath, childKey);
visit(childPath, childState);
}
};
for (const [topKey, topState] of Object.entries(machine.states)) {
if (!topState) continue;
visit(topKey, topState);
}
return { index, idIndex };
}
function ensureStateIndex(machine) {
const cached = stateIndexCache.get(machine);
if (cached) return cached;
const { index, idIndex } = buildStateIndex(machine);
stateIndexCache.set(machine, index);
stateIdIndexCache.set(machine, idIndex);
return index;
}
function getStatePathById(machine, stateId) {
ensureStateIndex(machine);
return stateIdIndexCache.get(machine)?.get(stateId);
}
function toSegments(value) {
if (!value) return [];
return String(value).split(STATE_DELIMITER).filter(Boolean);
}
function getStateChain(machine, state2) {
if (!state2) return [];
const stateIndex = ensureStateIndex(machine);
const segments = toSegments(state2);
const chain = [];
const statePath = [];
for (const segment of segments) {
statePath.push(segment);
const path = joinStatePath(statePath);
const current = stateIndex.get(path);
if (!current) break;
chain.push({ path, state: current });
}
return chain;
}
function resolveAbsoluteStateValue(machine, value) {
const stateIndex = ensureStateIndex(machine);
const segments = toSegments(value);
if (!segments.length) return value;
const resolved = [];
for (const segment of segments) {
resolved.push(segment);
const path = joinStatePath(resolved);
if (!stateIndex.has(path)) return value;
}
let resolvedPath = joinStatePath(resolved);
let current = stateIndex.get(resolvedPath);
while (current?.initial) {
const nextPath = `${resolvedPath}${STATE_DELIMITER}${current.initial}`;
const nextState = stateIndex.get(nextPath);
if (!nextState) break;
resolvedPath = nextPath;
current = nextState;
}
return resolvedPath;
}
function hasStatePath(machine, value) {
const stateIndex = ensureStateIndex(machine);
return stateIndex.has(value);
}
function resolveStateValue(machine, value, source) {
const stateValue = String(value);
if (isExplicitAbsoluteStatePath(stateValue)) {
const stateId = stripAbsolutePrefix(stateValue);
const statePath = getStatePathById(machine, stateId);
if (!statePath) {
throw new Error(`Unknown state id: ${stateId}`);
}
return resolveAbsoluteStateValue(machine, statePath);
}
if (!isAbsoluteStatePath(stateValue) && source) {
const sourceSegments = toSegments(source);
for (let index = sourceSegments.length; index >= 1; index--) {
const base = sourceSegments.slice(0, index).join(STATE_DELIMITER);
const candidate = appendStatePath(base, stateValue);
if (hasStatePath(machine, candidate)) return resolveAbsoluteStateValue(machine, candidate);
}
}
return resolveAbsoluteStateValue(machine, stateValue);
}
function findTransition(machine, state2, eventType) {
const chain = getStateChain(machine, state2);
for (let index = chain.length - 1; index >= 0; index--) {
const transitionMap = chain[index]?.state.on;
const transition = transitionMap?.[eventType];
if (transition) return { transitions: transition, source: chain[index]?.path };
}
const rootTransitionMap = machine.on;
return { transitions: rootTransitionMap?.[eventType], source: void 0 };
}
function getExitEnterStates(machine, prevState, nextState, reenter) {
const prevChain = prevState ? getStateChain(machine, prevState) : [];
const nextChain = getStateChain(machine, nextState);
let commonIndex = 0;
while (commonIndex < prevChain.length && commonIndex < nextChain.length && prevChain[commonIndex]?.path === nextChain[commonIndex]?.path) {
commonIndex += 1;
}
let exiting = prevChain.slice(commonIndex).reverse();
let entering = nextChain.slice(commonIndex);
const sameLeaf = prevChain.at(-1)?.path === nextChain.at(-1)?.path;
if (reenter && sameLeaf) {
exiting = prevChain.slice().reverse();
entering = nextChain;
}
return { exiting, entering };
}
function matchesState(current, value) {
if (!current) return false;
return current === value || current.startsWith(`${value}${STATE_DELIMITER}`);
}
function hasTag(machine, state2, tag) {
return getStateChain(machine, state2).some((item) => item.state.tags?.includes(tag));
}
// ../node_modules/.pnpm/@zag-js+core@1.36.0/node_modules/@zag-js/core/dist/create-machine.mjs
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) {
ensureStateIndex(config);
return config;
}
function setup() {
return {
guards: createGuards(),
createMachine: (config) => {
return createMachine(config);
},
choose: (transitions) => {
return function chooseFn({ choose }) {
return choose(transitions)?.actions;
};
}
};
}
// ../node_modules/.pnpm/@zag-js+core@1.36.0/node_modules/@zag-js/core/dist/types.mjs
var MachineStatus = /* @__PURE__ */ ((MachineStatus2) => {
MachineStatus2["NotStarted"] = "Not Started";
MachineStatus2["Started"] = "Started";
MachineStatus2["Stopped"] = "Stopped";
return MachineStatus2;
})(MachineStatus || {});
var INIT_STATE = "__init__";
// ../node_modules/.pnpm/@zag-js+dom-query@1.36.0/node_modules/@zag-js/dom-query/dist/chunk-QZ7TP4HQ.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);
// ../node_modules/.pnpm/@zag-js+dom-query@1.36.0/node_modules/@zag-js/dom-query/dist/caret.mjs
function setCaretToEnd(input) {
if (!input) return;
try {
if (input.ownerDocument.activeElement !== input) return;
const len = input.value.length;
input.setSelectionRange(len, len);
} catch {
}
}
// ../node_modules/.pnpm/@zag-js+dom-query@1.36.0/node_modules/@zag-js/dom-query/dist/shared.mjs
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 noop2 = () => void 0;
var isObject2 = (v) => typeof v === "object" && v !== null;
var MAX_Z_INDEX = 2147483647;
var dataAttr = (guard) => guard ? "" : void 0;
var ariaAttr = (guard) => guard ? "true" : void 0;
// ../node_modules/.pnpm/@zag-js+dom-query@1.36.0/node_modules/@zag-js/dom-query/dist/node.mjs
var ELEMENT_NODE = 1;
var DOCUMENT_NODE = 9;
var DOCUMENT_FRAGMENT_NODE = 11;
var isHTMLElement = (el) => isObject2(el) && el.nodeType === ELEMENT_NODE && typeof el.nodeName === "string";
var isDocument = (el) => isObject2(el) && el.nodeType === DOCUMENT_NODE;
var isWindow = (el) => isObject2(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) => isObject2(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;
}
// ../node_modules/.pnpm/@zag-js+dom-query@1.36.0/node_modules/@zag-js/dom-query/dist/computed-style.mjs
var styleCache = /* @__PURE__ */ new WeakMap();
function getComputedStyle(el) {
if (!styleCache.has(el)) {
styleCache.set(el, getWindow(el).getComputedStyle(el));
}
return styleCache.get(el);
}
// ../node_modules/.pnpm/@zag-js+dom-query@1.36.0/node_modules/@zag-js/dom-query/dist/controller.mjs
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));
}
// ../node_modules/.pnpm/@zag-js+dom-query@1.36.0/node_modules/@zag-js/dom-query/dist/data-url.mjs
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();
};
});
}
// ../node_modules/.pnpm/@zag-js+dom-query@1.36.0/node_modules/@zag-js/dom-query/dist/platform.mjs
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);
// ../node_modules/.pnpm/@zag-js+dom-query@1.36.0/node_modules/@zag-js/dom-query/dist/event.mjs
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);
};
};
// ../node_modules/.pnpm/@zag-js+dom-query@1.36.0/node_modules/@zag-js/dom-query/dist/form.mjs
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}`);
const event = new win.Event("input", { bubbles });
el.dispatchEvent(markAsInternalChangeEvent(event));
}
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);
const event = new win.Event("click", { bubbles });
el.dispatchEvent(markAsInternalChangeEvent(event));
}
function isFormElement(el) {
return el.matches("textarea, input, select, button");
}
function trackFormReset(el, callback) {
if (!el) return;
const form = isFormElement(el) ? el.form : el.closest("form");
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 INTERNAL_CHANGE_EVENT = /* @__PURE__ */ Symbol.for("zag.changeEvent");
function isInternalChangeEvent(e) {
return Object.prototype.hasOwnProperty.call(e, INTERNAL_CHANGE_EVENT);
}
function markAsInternalChangeEvent(event) {
if (isInternalChangeEvent(event)) return event;
Object.defineProperty(event, INTERNAL_CHANGE_EVENT, { value: true });
return event;
}
// ../node_modules/.pnpm/@zag-js+dom-query@1.36.0/node_modules/@zag-js/dom-query/dist/tabbable.mjs
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;
}
// ../node_modules/.pnpm/@zag-js+dom-query@1.36.0/node_modules/@zag-js/dom-query/dist/initial-focus.mjs
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;
}
// ../node_modules/.pnpm/@zag-js+dom-query@1.36.0/node_modules/@zag-js/dom-query/dist/raf.mjs
var AnimationFrame = class _AnimationFrame {
constructor() {
__publicField3(this, "id", null);
__publicField3(this, "fn_cleanup");
__publicField3(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;
}
// ../node_modules/.pnpm/@zag-js+dom-query@1.36.0/node_modules/@zag-js/dom-query/dist/mutation-observer.mjs
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?.());
};
}
// ../node_modules/.pnpm/@zag-js+dom-query@1.36.0/node_modules/@zag-js/dom-query/dist/navigate.mjs
function clickIfLink(el) {
const click = () => {
const win = getWindow(el);
el.dispatchEvent(new win.MouseEvent("click"));
};
if (isFirefox()) {
queueBeforeEvent(el, "keyup", click);
} else {
queueMicrotask(click);
}
}
// ../node_modules/.pnpm/@zag-js+dom-query@1.36.0/node_modules/@zag-js/dom-query/dist/overflow.mjs
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);
}
// ../node_modules/.pnpm/@zag-js+dom-query@1.36.0/node_modules/@zag-js/dom-query/dist/point.mjs
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 };
}
// ../node_modules/.pnpm/@zag-js+dom-query@1.36.0/node_modules/@zag-js/dom-query/dist/pointer-lock.mjs
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();
};
}
// ../node_modules/.pnpm/@zag-js+dom-query@1.36.0/node_modules/@zag-js/dom-query/dist/text-selection.mjs
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?.());
};
}
// ../node_modules/.pnpm/@zag-js+dom-query@1.36.0/node_modules/@zag-js/dom-query/dist/pointer-move.mjs
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());
};
}
// ../node_modules/.pnpm/@zag-js+dom-query@1.36.0/node_modules/@zag-js/dom-query/dist/press.mjs
function trackPress(options) {
const {
pointerNode,
keyboardNode = pointerNode,
onPress,
onPressStart,
onPressEnd,
isValidKey = (e) => e.key === "Enter"
} = options;
if (!pointerNode) return noop2;
const win = getWindow(pointerNode);
let removeStartListeners = noop2;
let removeEndListeners = noop2;
let removeAccessibleListeners = noop2;
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();
};
}
// ../node_modules/.pnpm/@zag-js+dom-query@1.36.0/node_modules/@zag-js/dom-query/dist/query.mjs
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];
}
// ../node_modules/.pnpm/@zag-js+dom-query@1.36.0/node_modules/@zag-js/dom-query/dist/resize-observer.mjs
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"
});
// ../node_modules/.pnpm/@zag-js+dom-query@1.36.0/node_modules/@zag-js/dom-query/dist/scale.mjs
function getScale(element) {
const rect = element.getBoundingClientRect();
const offsetWidth = element.offsetWidth;
const offsetHeight = element.offsetHeight;
const hasTransform = Math.round(rect.width) !== offsetWidth || Math.round(rect.height) !== offsetHeight;
let x = hasTransform ? Math.round(rect.width) / offsetWidth : 1;
let y = hasTransform ? Math.round(rect.height) / offsetHeight : 1;
if (!x || !Number.isFinite(x)) x = 1;
if (!y || !Number.isFinite(y)) y = 1;
return { x, y };
}
// ../node_modules/.pnpm/@zag-js+dom-query@1.36.0/node_modules/@zag-js/dom-query/dist/searchable.mjs
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 match2 = (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) => match2(getValueText(item), text));
}
// ../node_modules/.pnpm/@zag-js+dom-query@1.36.0/node_modules/@zag-js/dom-query/dist/set.mjs
function setAttribute(el, attr, v) {
const prev2 = el.getAttribute(attr);
const exists = prev2 != null;
if (prev2 === v) return noop2;
el.setAttribute(attr, v);
return () => {
if (!exists) {
el.removeAttribute(attr);
} else {
el.setAttribute(attr, prev2);
}
};
}
function setStyle(el, style) {
if (!el) return noop2;
const prev2 = Object.keys(style).reduce((acc, key) => {
acc[key] = el.style.getPropertyValue(key);
return acc;
}, {});
if (isEqual2(prev2, style)) return noop2;
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 noop2;
const prev2 = el.style.getPropertyValue(prop);
if (prev2 === value) return noop2;
el.style.setProperty(prop, value);
return () => {
el.style.setProperty(prop, prev2);
if (el.style.length === 0) {
el.removeAttribute("style");
}
};
}
function isEqual2(a, b) {
return Object.keys(a).every((key) => a[key] === b[key]);
}
// ../node_modules/.pnpm/@zag-js+dom-query@1.36.0/node_modules/@zag-js/dom-query/dist/typeahead.mjs
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;
}
// ../node_modules/.pnpm/@zag-js+dom-query@1.36.0/node_modules/@zag-js/dom-query/dist/visually-hidden.mjs
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"
};
// ../node_modules/.pnpm/@zag-js+dom-query@1.36.0/node_modules/@zag-js/dom-query/dist/wait-for.mjs
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+core@1.36.0/node_modules/@zag-js/core/dist/scope.mjs
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+store@1.36.0/node_modules/@zag-js/store/dist/global.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());
// ../node_modules/.pnpm/@zag-js+store@1.36.0/node_modules/@zag-js/store/dist/utils.mjs
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;
// ../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.36.0/node_modules/@zag-js/store/dist/proxy.mjs
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.36.0/node_modules/@zag-js/vanilla/dist/bindable.mjs
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 = controlled() ? props().value : 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;
}
};
};
// ../node_modules/.pnpm/@zag-js+vanilla@1.36.0/node_modules/@zag-js/vanilla/dist/refs.mjs
function createRefs(refs) {
const ref2 = { current: refs };
return {
get(key) {
return ref2.current[key];
},
set(key, value) {
ref2.current[key] = value;
}
};
}
// ../node_modules/.pnpm/@zag-js+vanilla@1.36.0/node_modules/@zag-js/vanilla/dist/merge-machine-props.mjs
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;
}
// ../node_modules/.pnpm/@zag-js+vanilla@1.36.0/node_modules/@zag-js/vanilla/dist/machine.mjs
var VanillaMachine = class {
constructor(machine, userProps = {}) {
this.machine = machine;
__publicField(this, "scope");
__publicField(this, "context");
__publicField(this, "prop");
__publicField(this, "state");
__publicField(this, "refs");
__publicField(this, "computed");
__publicField(this, "event", { type: "" });
__publicField(this, "previousEvent", { type: "" });
__publicField(this, "effects", /* @__PURE__ */ new Map());
__publicField(this, "transition", null);
__publicField(this, "cleanups", []);
__publicField(this, "subscriptions", []);
__publicField(this, "userPropsRef");
__publicField(this, "getEvent", () => ({
...this.event,
current: () => this.event,
previous: () => this.previousEvent
}));
__publicField(this, "getState", () => ({
...this.state,
matches: (...values) => values.some((value) => matchesState(this.state.get(), value)),
hasTag: (tag) => hasTag(this.machine, this.state.get(), tag)
}));
__publicField(this, "debug", (...args) => {
if (this.machine.debug) console.log(...args);
});
__publicField(this, "notify", () => {
this.publish();
});
__publicField(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, source } = findTransition(this.machine, currentState, eventType);
const transition = this.choose(transitions);
if (!transition) return;
this.transition = transition;
const target = resolveStateValue(this.machine, transition.target ?? currentState, source);
this.debug("transition", transition);
const changed = target !== currentState;
if (changed) {
this.state.set(target);
} else if (transition.reenter) {
this.state.invoke(currentState, currentState);
} else {
this.action(transition.actions);
}
});
});
__publicField(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());
}
});
__publicField(this, "guard", (str) => {
if (isFunction(str)) return str(this.getParams());
return this.machine.implementations?.guards?.[str](this.getParams());
});
__publicField(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?.());
});
__publicField(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;
});
});
__publicField(this, "subscribe", (fn) => {
this.subscriptions.push(fn);
return () => {
const index = this.subscriptions.indexOf(fn);
if (index > -1) this.subscriptions.splice(index, 1);
};
});
__publicField(this, "status", MachineStatus.NotStarted);
__publicField(this, "publish", () => {
this.callTrackers();
this.subscriptions.forEach((fn) => fn(this.service));
});
__publicField(this, "trackers", []);
__publicField(this, "setupTrackers", () => {
this.machine.watch?.(this.getParams());
});
__publicField(this, "callTrackers", () => {
this.trackers.forEach(({ deps, fn }) => {
const next2 = deps.map((dep) => dep());
if (!isEqual(fn.prev, next2)) {
fn();
fn.prev = next2;
}
});
});
__publicField(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: resolveStateValue(machine, machine.initialState({ prop })),
onChange: (nextState, prevState) => {
const { exiting, entering } = getExitEnterStates(this.machine, prevState, nextState, this.transition?.reenter);
exiting.forEach((item) => {
const exitEffects = this.effects.get(item.path);
exitEffects?.();
this.effects.delete(item.path);
});
exiting.forEach((item) => {
this.action(item.state?.exit);
});
this.action(this.transition?.actions);
entering.forEach((item) => {
const cleanup = this.effect(item.state?.effects);
if (cleanup) this.effects.set(item.path, cleanup);
});
if (prevState === INIT_STATE) {
this.action(machine.entry);
const cleanup = this.effect(machine.effects);
if (cleanup) this.effects.set(INIT_STATE, cleanup);
}
entering.forEach((item) => {
this.action(item.state?.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
};
}
};
// ../node_modules/.pnpm/@zag-js+vanilla@1.36.0/node_modules/@zag-js/vanilla/dist/spread-props.mjs
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);
}
}
};
}
// 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();
this.el.removeAttribute("data-js");
};
destroy = () => {
this.machine.stop();
};
spreadProps = (el, props) => {
spreadProps(el, props, this.machine.scope.id);
};
updateProps = (props) => {
this.machine.updateProps(props);
};
};
// ../node_modules/.pnpm/@zag-js+anatomy@1.36.0/node_modules/@zag-js/anatomy/dist/create-anatomy.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;
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,
isInternalChangeEvent,
markAsInternalChangeEvent,
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,
getScale,
setAttribute,
setStyle,
setStyleProperty,
getByTypeahead,
visuallyHiddenStyle,
waitForElement,
__publicField2 as __publicField,
__privateGet,
__privateAdd,
toArray,
first,
last,
add,
remove,
uniq,
diff,
addOrRemove,
nextIndex,
next,
prevIndex,
prev,
chunk,
partition,
isEqual,
isArray,
isBoolean,
isObject,
isString,
isFunction,
isNull,
hasProp,
runIfFn,
cast,
noop,
callAll,
uuid,
match,
tryCatch,
throttle,
compact,
pick,
warn,
invariant,
ensure,
ensureProps,
createGuards,
createMachine,
setup,
normalizeProps,
proxy,
subscribe,
VanillaMachine,
Component,
getDir,
getString,
getStringList,
getNumber,
getBoolean,
generateId,
canPushEvent
};