UNPKG

@zag-js/preact

Version:

The react wrapper for zag

1,026 lines (1,012 loc) 39.8 kB
import { MachineStatus, createScope, INIT_STATE } from '@zag-js/core'; export { mergeProps } from '@zag-js/core'; import { flushSync } from 'react-dom'; import { createNormalizer } from '@zag-js/types'; // src/index.ts // ../../utilities/core/src/array.ts function toArray(v3) { if (!v3) return []; return Array.isArray(v3) ? v3 : [v3]; } // ../../utilities/core/src/equal.ts var isArrayLike = (value) => value?.constructor.name === "Array"; var isArrayEqual = (a3, b2) => { if (a3.length !== b2.length) return false; for (let i3 = 0; i3 < a3.length; i3++) { if (!isEqual(a3[i3], b2[i3])) return false; } return true; }; var isEqual = (a3, b2) => { if (Object.is(a3, b2)) return true; if (a3 == null && b2 != null || a3 != null && b2 == null) return false; if (typeof a3?.isEqual === "function" && typeof b2?.isEqual === "function") { return a3.isEqual(b2); } if (typeof a3 === "function" && typeof b2 === "function") { return a3.toString() === b2.toString(); } if (isArrayLike(a3) && isArrayLike(b2)) { return isArrayEqual(Array.from(a3), Array.from(b2)); } if (!(typeof a3 === "object") || !(typeof b2 === "object")) return false; const keys = Object.keys(b2 ?? /* @__PURE__ */ Object.create(null)); const length = keys.length; for (let i3 = 0; i3 < length; i3++) { const hasKey = Reflect.has(a3, keys[i3]); if (!hasKey) return false; } for (let i3 = 0; i3 < length; i3++) { const key = keys[i3]; if (!isEqual(a3[key], b2[key])) return false; } return true; }; // ../../utilities/core/src/guard.ts var isString = (v3) => typeof v3 === "string"; var isFunction = (v3) => typeof v3 === "function"; var fnToString = Function.prototype.toString; fnToString.call(Object); // ../../utilities/core/src/warning.ts function warn(...a3) { const m3 = a3.length === 1 ? a3[0] : a3[1]; const c3 = a3.length === 2 ? a3[0] : true; if (c3 && process.env.NODE_ENV !== "production") { console.warn(m3); } } function ensure(c3, m3) { if (c3 == null) throw new Error(m3()); } // ../../../node_modules/.pnpm/preact@10.26.4/node_modules/preact/dist/preact.mjs var n; var l; var t; var i; var r; var o; var e; var f; var c; var s; var a; var p = {}; var v = []; var y = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i; var d = Array.isArray; function w(n2, l3) { for (var t3 in l3) n2[t3] = l3[t3]; return n2; } function g(n2) { n2 && n2.parentNode && n2.parentNode.removeChild(n2); } function _(l3, t3, u3) { var i3, r3, o3, e3 = {}; for (o3 in t3) "key" == o3 ? i3 = t3[o3] : "ref" == o3 ? r3 = t3[o3] : e3[o3] = t3[o3]; if (arguments.length > 2 && (e3.children = arguments.length > 3 ? n.call(arguments, 2) : u3), "function" == typeof l3 && null != l3.defaultProps) for (o3 in l3.defaultProps) void 0 === e3[o3] && (e3[o3] = l3.defaultProps[o3]); return m(l3, e3, i3, r3, null); } function m(n2, u3, i3, r3, o3) { var e3 = { type: n2, props: u3, key: i3, ref: r3, __k: null, __: null, __b: 0, __e: null, __c: null, constructor: void 0, __v: null == o3 ? ++t : o3, __i: -1, __u: 0 }; return null == o3 && null != l.vnode && l.vnode(e3), e3; } function k(n2) { return n2.children; } function x(n2, l3) { this.props = n2, this.context = l3; } function S(n2, l3) { if (null == l3) return n2.__ ? S(n2.__, n2.__i + 1) : null; for (var t3; l3 < n2.__k.length; l3++) if (null != (t3 = n2.__k[l3]) && null != t3.__e) return t3.__e; return "function" == typeof n2.type ? S(n2) : null; } function C(n2) { var l3, t3; if (null != (n2 = n2.__) && null != n2.__c) { for (n2.__e = n2.__c.base = null, l3 = 0; l3 < n2.__k.length; l3++) if (null != (t3 = n2.__k[l3]) && null != t3.__e) { n2.__e = n2.__c.base = t3.__e; break; } return C(n2); } } function M(n2) { (!n2.__d && (n2.__d = true) && i.push(n2) && !$.__r++ || r !== l.debounceRendering) && ((r = l.debounceRendering) || o)($); } function $() { for (var n2, t3, u3, r3, o3, f3, c3, s3 = 1; i.length; ) i.length > s3 && i.sort(e), n2 = i.shift(), s3 = i.length, n2.__d && (u3 = void 0, o3 = (r3 = (t3 = n2).__v).__e, f3 = [], c3 = [], t3.__P && ((u3 = w({}, r3)).__v = r3.__v + 1, l.vnode && l.vnode(u3), O(t3.__P, u3, r3, t3.__n, t3.__P.namespaceURI, 32 & r3.__u ? [o3] : null, f3, null == o3 ? S(r3) : o3, !!(32 & r3.__u), c3), u3.__v = r3.__v, u3.__.__k[u3.__i] = u3, z(f3, u3, c3), u3.__e != o3 && C(u3))); $.__r = 0; } function I(n2, l3, t3, u3, i3, r3, o3, e3, f3, c3, s3) { var a3, h3, y3, d3, w3, g4, _3 = u3 && u3.__k || v, m3 = l3.length; for (f3 = P(t3, l3, _3, f3, m3), a3 = 0; a3 < m3; a3++) null != (y3 = t3.__k[a3]) && (h3 = -1 === y3.__i ? p : _3[y3.__i] || p, y3.__i = a3, g4 = O(n2, y3, h3, i3, r3, o3, e3, f3, c3, s3), d3 = y3.__e, y3.ref && h3.ref != y3.ref && (h3.ref && q(h3.ref, null, y3), s3.push(y3.ref, y3.__c || d3, y3)), null == w3 && null != d3 && (w3 = d3), 4 & y3.__u || h3.__k === y3.__k ? f3 = A(y3, f3, n2) : "function" == typeof y3.type && void 0 !== g4 ? f3 = g4 : d3 && (f3 = d3.nextSibling), y3.__u &= -7); return t3.__e = w3, f3; } function P(n2, l3, t3, u3, i3) { var r3, o3, e3, f3, c3, s3 = t3.length, a3 = s3, h3 = 0; for (n2.__k = new Array(i3), r3 = 0; r3 < i3; r3++) null != (o3 = l3[r3]) && "boolean" != typeof o3 && "function" != typeof o3 ? (f3 = r3 + h3, (o3 = n2.__k[r3] = "string" == typeof o3 || "number" == typeof o3 || "bigint" == typeof o3 || o3.constructor == String ? m(null, o3, null, null, null) : d(o3) ? m(k, { children: o3 }, null, null, null) : void 0 === o3.constructor && o3.__b > 0 ? m(o3.type, o3.props, o3.key, o3.ref ? o3.ref : null, o3.__v) : o3).__ = n2, o3.__b = n2.__b + 1, e3 = null, -1 !== (c3 = o3.__i = L(o3, t3, f3, a3)) && (a3--, (e3 = t3[c3]) && (e3.__u |= 2)), null == e3 || null === e3.__v ? (-1 == c3 && (i3 > s3 ? h3-- : i3 < s3 && h3++), "function" != typeof o3.type && (o3.__u |= 4)) : c3 != f3 && (c3 == f3 - 1 ? h3-- : c3 == f3 + 1 ? h3++ : (c3 > f3 ? h3-- : h3++, o3.__u |= 4))) : n2.__k[r3] = null; if (a3) for (r3 = 0; r3 < s3; r3++) null != (e3 = t3[r3]) && 0 == (2 & e3.__u) && (e3.__e == u3 && (u3 = S(e3)), B(e3, e3)); return u3; } function A(n2, l3, t3) { var u3, i3; if ("function" == typeof n2.type) { for (u3 = n2.__k, i3 = 0; u3 && i3 < u3.length; i3++) u3[i3] && (u3[i3].__ = n2, l3 = A(u3[i3], l3, t3)); return l3; } n2.__e != l3 && (l3 && n2.type && !t3.contains(l3) && (l3 = S(n2)), t3.insertBefore(n2.__e, l3 || null), l3 = n2.__e); do { l3 = l3 && l3.nextSibling; } while (null != l3 && 8 == l3.nodeType); return l3; } function H(n2, l3) { return l3 = l3 || [], null == n2 || "boolean" == typeof n2 || (d(n2) ? n2.some(function(n3) { H(n3, l3); }) : l3.push(n2)), l3; } function L(n2, l3, t3, u3) { var i3, r3, o3 = n2.key, e3 = n2.type, f3 = l3[t3]; if (null === f3 && null == n2.key || f3 && o3 == f3.key && e3 === f3.type && 0 == (2 & f3.__u)) return t3; if (u3 > (null != f3 && 0 == (2 & f3.__u) ? 1 : 0)) for (i3 = t3 - 1, r3 = t3 + 1; i3 >= 0 || r3 < l3.length; ) { if (i3 >= 0) { if ((f3 = l3[i3]) && 0 == (2 & f3.__u) && o3 == f3.key && e3 === f3.type) return i3; i3--; } if (r3 < l3.length) { if ((f3 = l3[r3]) && 0 == (2 & f3.__u) && o3 == f3.key && e3 === f3.type) return r3; r3++; } } return -1; } function T(n2, l3, t3) { "-" == l3[0] ? n2.setProperty(l3, null == t3 ? "" : t3) : n2[l3] = null == t3 ? "" : "number" != typeof t3 || y.test(l3) ? t3 : t3 + "px"; } function j(n2, l3, t3, u3, i3) { var r3; n: if ("style" == l3) if ("string" == typeof t3) n2.style.cssText = t3; else { if ("string" == typeof u3 && (n2.style.cssText = u3 = ""), u3) for (l3 in u3) t3 && l3 in t3 || T(n2.style, l3, ""); if (t3) for (l3 in t3) u3 && t3[l3] === u3[l3] || T(n2.style, l3, t3[l3]); } else if ("o" == l3[0] && "n" == l3[1]) r3 = l3 != (l3 = l3.replace(f, "$1")), l3 = l3.toLowerCase() in n2 || "onFocusOut" == l3 || "onFocusIn" == l3 ? l3.toLowerCase().slice(2) : l3.slice(2), n2.l || (n2.l = {}), n2.l[l3 + r3] = t3, t3 ? u3 ? t3.t = u3.t : (t3.t = c, n2.addEventListener(l3, r3 ? a : s, r3)) : n2.removeEventListener(l3, r3 ? a : s, r3); else { if ("http://www.w3.org/2000/svg" == i3) l3 = l3.replace(/xlink(H|:h)/, "h").replace(/sName$/, "s"); else if ("width" != l3 && "height" != l3 && "href" != l3 && "list" != l3 && "form" != l3 && "tabIndex" != l3 && "download" != l3 && "rowSpan" != l3 && "colSpan" != l3 && "role" != l3 && "popover" != l3 && l3 in n2) try { n2[l3] = null == t3 ? "" : t3; break n; } catch (n3) { } "function" == typeof t3 || (null == t3 || false === t3 && "-" != l3[4] ? n2.removeAttribute(l3) : n2.setAttribute(l3, "popover" == l3 && 1 == t3 ? "" : t3)); } } function F(n2) { return function(t3) { if (this.l) { var u3 = this.l[t3.type + n2]; if (null == t3.u) t3.u = c++; else if (t3.u < u3.t) return; return u3(l.event ? l.event(t3) : t3); } }; } function O(n2, t3, u3, i3, r3, o3, e3, f3, c3, s3) { var a3, h3, p3, v3, y3, _3, m3, b2, S2, C3, M2, $3, P4, A4, H3, L3, T4, j4 = t3.type; if (void 0 !== t3.constructor) return null; 128 & u3.__u && (c3 = !!(32 & u3.__u), o3 = [f3 = t3.__e = u3.__e]), (a3 = l.__b) && a3(t3); n: if ("function" == typeof j4) try { if (b2 = t3.props, S2 = "prototype" in j4 && j4.prototype.render, C3 = (a3 = j4.contextType) && i3[a3.__c], M2 = a3 ? C3 ? C3.props.value : a3.__ : i3, u3.__c ? m3 = (h3 = t3.__c = u3.__c).__ = h3.__E : (S2 ? t3.__c = h3 = new j4(b2, M2) : (t3.__c = h3 = new x(b2, M2), h3.constructor = j4, h3.render = D), C3 && C3.sub(h3), h3.props = b2, h3.state || (h3.state = {}), h3.context = M2, h3.__n = i3, p3 = h3.__d = true, h3.__h = [], h3._sb = []), S2 && null == h3.__s && (h3.__s = h3.state), S2 && null != j4.getDerivedStateFromProps && (h3.__s == h3.state && (h3.__s = w({}, h3.__s)), w(h3.__s, j4.getDerivedStateFromProps(b2, h3.__s))), v3 = h3.props, y3 = h3.state, h3.__v = t3, p3) S2 && null == j4.getDerivedStateFromProps && null != h3.componentWillMount && h3.componentWillMount(), S2 && null != h3.componentDidMount && h3.__h.push(h3.componentDidMount); else { if (S2 && null == j4.getDerivedStateFromProps && b2 !== v3 && null != h3.componentWillReceiveProps && h3.componentWillReceiveProps(b2, M2), !h3.__e && (null != h3.shouldComponentUpdate && false === h3.shouldComponentUpdate(b2, h3.__s, M2) || t3.__v == u3.__v)) { for (t3.__v != u3.__v && (h3.props = b2, h3.state = h3.__s, h3.__d = false), t3.__e = u3.__e, t3.__k = u3.__k, t3.__k.some(function(n3) { n3 && (n3.__ = t3); }), $3 = 0; $3 < h3._sb.length; $3++) h3.__h.push(h3._sb[$3]); h3._sb = [], h3.__h.length && e3.push(h3); break n; } null != h3.componentWillUpdate && h3.componentWillUpdate(b2, h3.__s, M2), S2 && null != h3.componentDidUpdate && h3.__h.push(function() { h3.componentDidUpdate(v3, y3, _3); }); } if (h3.context = M2, h3.props = b2, h3.__P = n2, h3.__e = false, P4 = l.__r, A4 = 0, S2) { for (h3.state = h3.__s, h3.__d = false, P4 && P4(t3), a3 = h3.render(h3.props, h3.state, h3.context), H3 = 0; H3 < h3._sb.length; H3++) h3.__h.push(h3._sb[H3]); h3._sb = []; } else do { h3.__d = false, P4 && P4(t3), a3 = h3.render(h3.props, h3.state, h3.context), h3.state = h3.__s; } while (h3.__d && ++A4 < 25); h3.state = h3.__s, null != h3.getChildContext && (i3 = w(w({}, i3), h3.getChildContext())), S2 && !p3 && null != h3.getSnapshotBeforeUpdate && (_3 = h3.getSnapshotBeforeUpdate(v3, y3)), L3 = a3, null != a3 && a3.type === k && null == a3.key && (L3 = N(a3.props.children)), f3 = I(n2, d(L3) ? L3 : [L3], t3, u3, i3, r3, o3, e3, f3, c3, s3), h3.base = t3.__e, t3.__u &= -161, h3.__h.length && e3.push(h3), m3 && (h3.__E = h3.__ = null); } catch (n3) { if (t3.__v = null, c3 || null != o3) if (n3.then) { for (t3.__u |= c3 ? 160 : 128; f3 && 8 == f3.nodeType && f3.nextSibling; ) f3 = f3.nextSibling; o3[o3.indexOf(f3)] = null, t3.__e = f3; } else for (T4 = o3.length; T4--; ) g(o3[T4]); else t3.__e = u3.__e, t3.__k = u3.__k; l.__e(n3, t3, u3); } else null == o3 && t3.__v == u3.__v ? (t3.__k = u3.__k, t3.__e = u3.__e) : f3 = t3.__e = V(u3.__e, t3, u3, i3, r3, o3, e3, c3, s3); return (a3 = l.diffed) && a3(t3), 128 & t3.__u ? void 0 : f3; } function z(n2, t3, u3) { for (var i3 = 0; i3 < u3.length; i3++) q(u3[i3], u3[++i3], u3[++i3]); l.__c && l.__c(t3, n2), n2.some(function(t4) { try { n2 = t4.__h, t4.__h = [], n2.some(function(n3) { n3.call(t4); }); } catch (n3) { l.__e(n3, t4.__v); } }); } function N(n2) { return "object" != typeof n2 || null == n2 ? n2 : d(n2) ? n2.map(N) : w({}, n2); } function V(t3, u3, i3, r3, o3, e3, f3, c3, s3) { var a3, h3, v3, y3, w3, _3, m3, b2 = i3.props, k3 = u3.props, x3 = u3.type; if ("svg" == x3 ? o3 = "http://www.w3.org/2000/svg" : "math" == x3 ? o3 = "http://www.w3.org/1998/Math/MathML" : o3 || (o3 = "http://www.w3.org/1999/xhtml"), null != e3) { for (a3 = 0; a3 < e3.length; a3++) if ((w3 = e3[a3]) && "setAttribute" in w3 == !!x3 && (x3 ? w3.localName == x3 : 3 == w3.nodeType)) { t3 = w3, e3[a3] = null; break; } } if (null == t3) { if (null == x3) return document.createTextNode(k3); t3 = document.createElementNS(o3, x3, k3.is && k3), c3 && (l.__m && l.__m(u3, e3), c3 = false), e3 = null; } if (null === x3) b2 === k3 || c3 && t3.data === k3 || (t3.data = k3); else { if (e3 = e3 && n.call(t3.childNodes), b2 = i3.props || p, !c3 && null != e3) for (b2 = {}, a3 = 0; a3 < t3.attributes.length; a3++) b2[(w3 = t3.attributes[a3]).name] = w3.value; for (a3 in b2) if (w3 = b2[a3], "children" == a3) ; else if ("dangerouslySetInnerHTML" == a3) v3 = w3; else if (!(a3 in k3)) { if ("value" == a3 && "defaultValue" in k3 || "checked" == a3 && "defaultChecked" in k3) continue; j(t3, a3, null, w3, o3); } for (a3 in k3) w3 = k3[a3], "children" == a3 ? y3 = w3 : "dangerouslySetInnerHTML" == a3 ? h3 = w3 : "value" == a3 ? _3 = w3 : "checked" == a3 ? m3 = w3 : c3 && "function" != typeof w3 || b2[a3] === w3 || j(t3, a3, w3, b2[a3], o3); if (h3) c3 || v3 && (h3.__html === v3.__html || h3.__html === t3.innerHTML) || (t3.innerHTML = h3.__html), u3.__k = []; else if (v3 && (t3.innerHTML = ""), I("template" === u3.type ? t3.content : t3, d(y3) ? y3 : [y3], u3, i3, r3, "foreignObject" == x3 ? "http://www.w3.org/1999/xhtml" : o3, e3, f3, e3 ? e3[0] : i3.__k && S(i3, 0), c3, s3), null != e3) for (a3 = e3.length; a3--; ) g(e3[a3]); c3 || (a3 = "value", "progress" == x3 && null == _3 ? t3.removeAttribute("value") : void 0 !== _3 && (_3 !== t3[a3] || "progress" == x3 && !_3 || "option" == x3 && _3 !== b2[a3]) && j(t3, a3, _3, b2[a3], o3), a3 = "checked", void 0 !== m3 && m3 !== t3[a3] && j(t3, a3, m3, b2[a3], o3)); } return t3; } function q(n2, t3, u3) { try { if ("function" == typeof n2) { var i3 = "function" == typeof n2.__u; i3 && n2.__u(), i3 && null == t3 || (n2.__u = n2(t3)); } else n2.current = t3; } catch (n3) { l.__e(n3, u3); } } function B(n2, t3, u3) { var i3, r3; if (l.unmount && l.unmount(n2), (i3 = n2.ref) && (i3.current && i3.current !== n2.__e || q(i3, null, t3)), null != (i3 = n2.__c)) { if (i3.componentWillUnmount) try { i3.componentWillUnmount(); } catch (n3) { l.__e(n3, t3); } i3.base = i3.__P = null; } if (i3 = n2.__k) for (r3 = 0; r3 < i3.length; r3++) i3[r3] && B(i3[r3], t3, u3 || "function" != typeof n2.type); u3 || g(n2.__e), n2.__c = n2.__ = n2.__e = void 0; } function D(n2, l3, t3) { return this.constructor(n2, t3); } function E(t3, u3, i3) { var r3, o3, e3, f3; u3 == document && (u3 = document.documentElement), l.__ && l.__(t3, u3), o3 = (r3 = "function" == "undefined") ? null : u3.__k, e3 = [], f3 = [], O(u3, t3 = (u3).__k = _(k, null, [t3]), o3 || p, p, u3.namespaceURI, o3 ? null : u3.firstChild ? n.call(u3.childNodes) : null, e3, o3 ? o3.__e : u3.firstChild, r3, f3), z(e3, t3, f3); } n = v.slice, l = { __e: function(n2, l3, t3, u3) { for (var i3, r3, o3; l3 = l3.__; ) if ((i3 = l3.__c) && !i3.__) try { if ((r3 = i3.constructor) && null != r3.getDerivedStateFromError && (i3.setState(r3.getDerivedStateFromError(n2)), o3 = i3.__d), null != i3.componentDidCatch && (i3.componentDidCatch(n2, u3 || {}), o3 = i3.__d), o3) return i3.__E = i3; } catch (l4) { n2 = l4; } throw n2; } }, t = 0, x.prototype.setState = function(n2, l3) { var t3; t3 = null != this.__s && this.__s !== this.state ? this.__s : this.__s = w({}, this.state), "function" == typeof n2 && (n2 = n2(w({}, t3), this.props)), n2 && w(t3, n2), null != n2 && this.__v && (l3 && this._sb.push(l3), M(this)); }, x.prototype.forceUpdate = function(n2) { this.__v && (this.__e = true, n2 && this.__h.push(n2), M(this)); }, x.prototype.render = k, i = [], o = "function" == typeof Promise ? Promise.prototype.then.bind(Promise.resolve()) : setTimeout, e = function(n2, l3) { return n2.__v.__b - l3.__v.__b; }, $.__r = 0, f = /(PointerCapture)$|Capture$/i, c = 0, s = F(false), a = F(true); // ../../../node_modules/.pnpm/preact@10.26.4/node_modules/preact/hooks/dist/hooks.mjs var t2; var r2; var u2; var i2; var o2 = 0; var f2 = []; var c2 = l; var e2 = c2.__b; var a2 = c2.__r; var v2 = c2.diffed; var l2 = c2.__c; var m2 = c2.unmount; var s2 = c2.__; function p2(n2, t3) { c2.__h && c2.__h(r2, n2, o2 || t3), o2 = 0; var u3 = r2.__H || (r2.__H = { __: [], __h: [] }); return n2 >= u3.__.length && u3.__.push({}), u3.__[n2]; } function d2(n2) { return o2 = 1, h2(D2, n2); } function h2(n2, u3, i3) { var o3 = p2(t2++, 2); if (o3.t = n2, !o3.__c && (o3.__ = [D2(void 0, u3), function(n3) { var t3 = o3.__N ? o3.__N[0] : o3.__[0], r3 = o3.t(t3, n3); t3 !== r3 && (o3.__N = [r3, o3.__[1]], o3.__c.setState({})); }], o3.__c = r2, !r2.__f)) { var f3 = function(n3, t3, r3) { if (!o3.__c.__H) return true; var u4 = o3.__c.__H.__.filter(function(n4) { return !!n4.__c; }); if (u4.every(function(n4) { return !n4.__N; })) return !c3 || c3.call(this, n3, t3, r3); var i4 = o3.__c.props !== n3; return u4.forEach(function(n4) { if (n4.__N) { var t4 = n4.__[0]; n4.__ = n4.__N, n4.__N = void 0, t4 !== n4.__[0] && (i4 = true); } }), c3 && c3.call(this, n3, t3, r3) || i4; }; r2.__f = true; var c3 = r2.shouldComponentUpdate, e3 = r2.componentWillUpdate; r2.componentWillUpdate = function(n3, t3, r3) { if (this.__e) { var u4 = c3; c3 = void 0, f3(n3, t3, r3), c3 = u4; } e3 && e3.call(this, n3, t3, r3); }, r2.shouldComponentUpdate = f3; } return o3.__N || o3.__; } function y2(n2, u3) { var i3 = p2(t2++, 3); !c2.__s && C2(i3.__H, u3) && (i3.__ = n2, i3.u = u3, r2.__H.__h.push(i3)); } function _2(n2, u3) { var i3 = p2(t2++, 4); !c2.__s && C2(i3.__H, u3) && (i3.__ = n2, i3.u = u3, r2.__h.push(i3)); } function A2(n2) { return o2 = 5, T2(function() { return { current: n2 }; }, []); } function T2(n2, r3) { var u3 = p2(t2++, 7); return C2(u3.__H, r3) && (u3.__ = n2(), u3.__H = r3, u3.__h = n2), u3.__; } function j2() { for (var n2; n2 = f2.shift(); ) if (n2.__P && n2.__H) try { n2.__H.__h.forEach(z2), n2.__H.__h.forEach(B2), n2.__H.__h = []; } catch (t3) { n2.__H.__h = [], c2.__e(t3, n2.__v); } } c2.__b = function(n2) { r2 = null, e2 && e2(n2); }, c2.__ = function(n2, t3) { n2 && t3.__k && t3.__k.__m && (n2.__m = t3.__k.__m), s2 && s2(n2, t3); }, c2.__r = function(n2) { a2 && a2(n2), t2 = 0; var i3 = (r2 = n2.__c).__H; i3 && (u2 === r2 ? (i3.__h = [], r2.__h = [], i3.__.forEach(function(n3) { n3.__N && (n3.__ = n3.__N), n3.u = n3.__N = void 0; })) : (i3.__h.forEach(z2), i3.__h.forEach(B2), i3.__h = [], t2 = 0)), u2 = r2; }, c2.diffed = function(n2) { v2 && v2(n2); var t3 = n2.__c; t3 && t3.__H && (t3.__H.__h.length && (1 !== f2.push(t3) && i2 === c2.requestAnimationFrame || ((i2 = c2.requestAnimationFrame) || w2)(j2)), t3.__H.__.forEach(function(n3) { n3.u && (n3.__H = n3.u), n3.u = void 0; })), u2 = r2 = null; }, c2.__c = function(n2, t3) { t3.some(function(n3) { try { n3.__h.forEach(z2), n3.__h = n3.__h.filter(function(n4) { return !n4.__ || B2(n4); }); } catch (r3) { t3.some(function(n4) { n4.__h && (n4.__h = []); }), t3 = [], c2.__e(r3, n3.__v); } }), l2 && l2(n2, t3); }, c2.unmount = function(n2) { m2 && m2(n2); var t3, r3 = n2.__c; r3 && r3.__H && (r3.__H.__.forEach(function(n3) { try { z2(n3); } catch (n4) { t3 = n4; } }), r3.__H = void 0, t3 && c2.__e(t3, r3.__v)); }; var k2 = "function" == typeof requestAnimationFrame; function w2(n2) { var t3, r3 = function() { clearTimeout(u3), k2 && cancelAnimationFrame(t3), setTimeout(n2); }, u3 = setTimeout(r3, 100); k2 && (t3 = requestAnimationFrame(r3)); } function z2(n2) { var t3 = r2, u3 = n2.__c; "function" == typeof u3 && (n2.__c = void 0, u3()), r2 = t3; } function B2(n2) { var t3 = r2; n2.__c = n2.__(), r2 = t3; } function C2(n2, t3) { return !n2 || n2.length !== t3.length || t3.some(function(t4, r3) { return t4 !== n2[r3]; }); } function D2(n2, t3) { return "function" == typeof t3 ? t3(n2) : t3; } var identity = (v3) => v3(); function useBindable(props) { const initial = props().value ?? props().defaultValue; const eq = props().isEqual ?? isEqual; const [initialValue] = d2(initial); const [value, setValue] = d2(initialValue); const controlled = props().value !== void 0; const valueRef = A2(value); valueRef.current = controlled ? props().value : value; const prevValue = A2(valueRef.current); _2(() => { prevValue.current = valueRef.current; }, [value, props().value]); const setFn = (value2) => { const prev = prevValue.current; const next = isFunction(value2) ? value2(prev) : value2; if (props().debug) { console.log(`[bindable > ${props().debug}] setValue`, { next, prev }); } if (!controlled) setValue(next); if (!eq(next, prev)) { props().onChange?.(next, prev); } }; function get() { return controlled ? props().value : value; } return { initial: initialValue, ref: valueRef, get, set(value2) { const exec = props().sync ? flushSync : identity; exec(() => setFn(value2)); }, invoke(nextValue, prevValue2) { props().onChange?.(nextValue, prevValue2); }, hash(value2) { return props().hash?.(value2) ?? String(value2); } }; } useBindable.cleanup = (fn2) => { _2(() => fn2, []); }; useBindable.ref = (defaultValue) => { const value = A2(defaultValue); return { get: () => value.current, set: (next) => { value.current = next; } }; }; // src/refs.ts function useRefs(refs) { const ref = A2(refs); return { get(key) { return ref.current[key]; }, set(key, value) { ref.current[key] = value; } }; } // src/track.ts var useTrack = (deps, effect) => { const render = A2(false); const called = A2(false); y2(() => { const mounted = render.current; const run = mounted && called.current; if (run) return effect(); called.current = true; }, [...(deps ?? []).map((d3) => typeof d3 === "function" ? d3() : d3)]); y2(() => { render.current = true; return () => { render.current = false; }; }, []); }; // src/machine.ts function useMachine(machine, userProps = {}) { const scope = T2(() => { const { id, ids, getRootNode } = userProps; return createScope({ id, ids, getRootNode }); }, [userProps]); const debug = (...args) => { if (machine.debug) console.log(...args); }; const props = machine.props?.({ props: userProps, scope }) ?? userProps; const prop = useProp(props); const context = machine.context?.({ prop, bindable: useBindable, scope, flush, getContext() { return ctx; }, getComputed() { return computed; }, getRefs() { return refs; } }); const contextRef = useLiveRef(context); const ctx = { get(key) { return contextRef.current?.[key].get(); }, set(key, value) { contextRef.current?.[key].set(value); }, initial(key) { return contextRef.current?.[key].initial; }, hash(key) { const current = contextRef.current?.[key].get(); return contextRef.current?.[key].hash(current); } }; const effects = A2(/* @__PURE__ */ new Map()); const transitionRef = A2(null); const previousEventRef = A2(null); const eventRef = A2({ type: "" }); const refs = useRefs(machine.refs?.({ prop, context: ctx }) ?? {}); const getEvent = () => ({ ...eventRef.current, current() { return eventRef.current; }, previous() { return previousEventRef.current; } }); const getState = () => ({ ...state, hasTag(tag) { const currentState = state.get(); return !!machine.states[currentState]?.tags?.includes(tag); }, matches(...values) { const currentState = state.get(); return values.includes(currentState); } }); const getParams = () => ({ state: getState(), context: ctx, event: getEvent(), prop, send, action, guard, track: useTrack, refs, computed, flush, scope, choose }); const action = (keys) => { const strs = isFunction(keys) ? keys(getParams()) : keys; if (!strs) return; const fns = strs.map((s3) => { const fn2 = machine.implementations?.actions?.[s3]; if (!fn2) warn(`[zag-js] No implementation found for action "${JSON.stringify(s3)}"`); return fn2; }); for (const fn2 of fns) { fn2?.(getParams()); } }; const guard = (str) => { if (isFunction(str)) return str(getParams()); return machine.implementations?.guards?.[str](getParams()); }; const effect = (keys) => { const strs = isFunction(keys) ? keys(getParams()) : keys; if (!strs) return; const fns = strs.map((s3) => { const fn2 = machine.implementations?.effects?.[s3]; if (!fn2) warn(`[zag-js] No implementation found for effect "${JSON.stringify(s3)}"`); return fn2; }); const cleanups = []; for (const fn2 of fns) { const cleanup = fn2?.(getParams()); if (cleanup) cleanups.push(cleanup); } return () => cleanups.forEach((fn2) => fn2?.()); }; const choose = (transitions) => { return toArray(transitions).find((t3) => { let result = !t3.guard; if (isString(t3.guard)) result = !!guard(t3.guard); else if (isFunction(t3.guard)) result = t3.guard(getParams()); return result; }); }; const computed = (key) => { ensure(machine.computed, () => `[zag-js] No computed object found on machine`); const fn2 = machine.computed[key]; return fn2({ context: ctx, event: getEvent(), prop, refs, scope, computed }); }; const state = useBindable(() => ({ defaultValue: machine.initialState({ prop }), onChange(nextState, prevState) { if (prevState) { const exitEffects = effects.current.get(prevState); exitEffects?.(); effects.current.delete(prevState); } if (prevState) { action(machine.states[prevState]?.exit); } action(transitionRef.current?.actions); const cleanup = effect(machine.states[nextState]?.effects); if (cleanup) effects.current.set(nextState, cleanup); if (prevState === INIT_STATE) { action(machine.entry); const cleanup2 = effect(machine.effects); if (cleanup2) effects.current.set(INIT_STATE, cleanup2); } action(machine.states[nextState]?.entry); } })); const hydratedStateRef = A2(void 0); const statusRef = A2(MachineStatus.NotStarted); _2(() => { const started = statusRef.current === MachineStatus.Started; statusRef.current = MachineStatus.Started; debug(started ? "rehydrating..." : "initializing..."); const initialState = hydratedStateRef.current ?? state.initial; state.invoke(initialState, started ? state.get() : INIT_STATE); const fns = effects.current; const currentState = state.ref.current; return () => { debug("unmounting..."); hydratedStateRef.current = currentState; statusRef.current = MachineStatus.Stopped; fns.forEach((fn2) => fn2?.()); effects.current = /* @__PURE__ */ new Map(); transitionRef.current = null; action(machine.exit); }; }, []); const getCurrentState = () => { if ("ref" in state) return state.ref.current; return state.get(); }; const send = (event) => { queueMicrotask(() => { if (statusRef.current !== MachineStatus.Started) return; previousEventRef.current = eventRef.current; eventRef.current = event; let currentState = getCurrentState(); const transitions = ( // @ts-ignore machine.states[currentState].on?.[event.type] ?? // @ts-ignore machine.on?.[event.type] ); const transition = choose(transitions); if (!transition) return; transitionRef.current = transition; const target = transition.target ?? currentState; const changed = target !== currentState; if (changed) { flushSync(() => state.set(target)); } else { action(transition.actions ?? []); } }); }; machine.watch?.(getParams()); return { state: getState(), send, context: ctx, prop, scope, refs, computed, event: getEvent(), getStatus: () => statusRef.current }; } function useLiveRef(value) { const ref = A2(value); ref.current = value; return ref; } function useProp(value) { const ref = useLiveRef(value); return function get(key) { return ref.current[key]; }; } function flush(fn2) { queueMicrotask(() => { flushSync(() => fn2()); }); } var eventMap = { onFocus: "onfocusin", onBlur: "onfocusout", onDoubleClick: "onDblClick", onChange: "onInput", defaultChecked: "checked", defaultValue: "value" }; function toPreactProp(prop) { return prop in eventMap ? eventMap[prop] : prop; } var normalizeProps = createNormalizer((props) => { const normalized = {}; for (const key in props) { normalized[toPreactProp(key)] = props[key]; } return normalized; }); // ../../../node_modules/.pnpm/preact@10.26.4/node_modules/preact/compat/dist/compat.mjs function g3(n2, t3) { for (var e3 in t3) n2[e3] = t3[e3]; return n2; } function E2(n2, t3) { for (var e3 in n2) if ("__source" !== e3 && !(e3 in t3)) return true; for (var r3 in t3) if ("__source" !== r3 && n2[r3] !== t3[r3]) return true; return false; } function N2(n2, t3) { this.props = n2, this.context = t3; } (N2.prototype = new x()).isPureReactComponent = true, N2.prototype.shouldComponentUpdate = function(n2, t3) { return E2(this.props, n2) || E2(this.state, t3); }; var T3 = l.__b; l.__b = function(n2) { n2.type && n2.type.__f && n2.ref && (n2.props.ref = n2.ref, n2.ref = null), T3 && T3(n2); }; var L2 = function(n2, t3) { return null == n2 ? null : H(H(n2).map(t3)); }; var O2 = { map: L2, forEach: L2, count: function(n2) { return n2 ? H(n2).length : 0; }, only: function(n2) { var t3 = H(n2); if (1 !== t3.length) throw "Children.only"; return t3[0]; }, toArray: H }; var F3 = l.__e; l.__e = function(n2, t3, e3, r3) { if (n2.then) { for (var u3, o3 = t3; o3 = o3.__; ) if ((u3 = o3.__c) && u3.__c) return null == t3.__e && (t3.__e = e3.__e, t3.__k = e3.__k), u3.__c(n2, t3); } F3(n2, t3, e3, r3); }; var U = l.unmount; function V2(n2, t3, e3) { return n2 && (n2.__c && n2.__c.__H && (n2.__c.__H.__.forEach(function(n3) { "function" == typeof n3.__c && n3.__c(); }), n2.__c.__H = null), null != (n2 = g3({}, n2)).__c && (n2.__c.__P === e3 && (n2.__c.__P = t3), n2.__c = null), n2.__k = n2.__k && n2.__k.map(function(n3) { return V2(n3, t3, e3); })), n2; } function W(n2, t3, e3) { return n2 && e3 && (n2.__v = null, n2.__k = n2.__k && n2.__k.map(function(n3) { return W(n3, t3, e3); }), n2.__c && n2.__c.__P === t3 && (n2.__e && e3.appendChild(n2.__e), n2.__c.__e = true, n2.__c.__P = e3)), n2; } function P3() { this.__u = 0, this.o = null, this.__b = null; } function j3(n2) { var t3 = n2.__.__c; return t3 && t3.__a && t3.__a(n2); } function B3() { this.i = null, this.l = null; } l.unmount = function(n2) { var t3 = n2.__c; t3 && t3.__R && t3.__R(), t3 && 32 & n2.__u && (n2.type = null), U && U(n2); }, (P3.prototype = new x()).__c = function(n2, t3) { var e3 = t3.__c, r3 = this; null == r3.o && (r3.o = []), r3.o.push(e3); var u3 = j3(r3.__v), o3 = false, i3 = function() { o3 || (o3 = true, e3.__R = null, u3 ? u3(c3) : c3()); }; e3.__R = i3; var c3 = function() { if (!--r3.__u) { if (r3.state.__a) { var n3 = r3.state.__a; r3.__v.__k[0] = W(n3, n3.__c.__P, n3.__c.__O); } var t4; for (r3.setState({ __a: r3.__b = null }); t4 = r3.o.pop(); ) t4.forceUpdate(); } }; r3.__u++ || 32 & t3.__u || r3.setState({ __a: r3.__b = r3.__v.__k[0] }), n2.then(i3, i3); }, P3.prototype.componentWillUnmount = function() { this.o = []; }, P3.prototype.render = function(n2, e3) { if (this.__b) { if (this.__v.__k) { var r3 = document.createElement("div"), o3 = this.__v.__k[0].__c; this.__v.__k[0] = V2(this.__b, r3, o3.__O = o3.__P); } this.__b = null; } var i3 = e3.__a && _(k, null, n2.fallback); return i3 && (i3.__u &= -33), [_(k, null, e3.__a ? null : n2.children), i3]; }; var H2 = function(n2, t3, e3) { if (++e3[1] === e3[0] && n2.l.delete(t3), n2.props.revealOrder && ("t" !== n2.props.revealOrder[0] || !n2.l.size)) for (e3 = n2.i; e3; ) { for (; e3.length > 3; ) e3.pop()(); if (e3[1] < e3[0]) break; n2.i = e3 = e3[2]; } }; function Z(n2) { return this.getChildContext = function() { return n2.context; }, n2.children; } function Y(n2) { var e3 = this, r3 = n2.h; e3.componentWillUnmount = function() { E(null, e3.v), e3.v = null, e3.h = null; }, e3.h && e3.h !== r3 && e3.componentWillUnmount(), e3.v || (e3.h = r3, e3.v = { nodeType: 1, parentNode: r3, childNodes: [], contains: function() { return true; }, appendChild: function(n3) { this.childNodes.push(n3), e3.h.appendChild(n3); }, insertBefore: function(n3, t3) { this.childNodes.push(n3), e3.h.insertBefore(n3, t3); }, removeChild: function(n3) { this.childNodes.splice(this.childNodes.indexOf(n3) >>> 1, 1), e3.h.removeChild(n3); } }), E(_(Z, { context: e3.context }, n2.__v), e3.v); } function $2(n2, e3) { var r3 = _(Y, { __v: n2, h: e3 }); return r3.containerInfo = e3, r3; } (B3.prototype = new x()).__a = function(n2) { var t3 = this, e3 = j3(t3.__v), r3 = t3.l.get(n2); return r3[0]++, function(u3) { var o3 = function() { t3.props.revealOrder ? (r3.push(u3), H2(t3, n2, r3)) : u3(); }; e3 ? e3(o3) : o3(); }; }, B3.prototype.render = function(n2) { this.i = null, this.l = /* @__PURE__ */ new Map(); var t3 = H(n2.children); n2.revealOrder && "b" === n2.revealOrder[0] && t3.reverse(); for (var e3 = t3.length; e3--; ) this.l.set(t3[e3], this.i = [1, 0, this.i]); return n2.children; }, B3.prototype.componentDidUpdate = B3.prototype.componentDidMount = function() { var n2 = this; this.l.forEach(function(t3, e3) { H2(n2, e3, t3); }); }; var q3 = "undefined" != typeof Symbol && Symbol.for && Symbol.for("react.element") || 60103; var G2 = /^(?:accent|alignment|arabic|baseline|cap|clip(?!PathU)|color|dominant|fill|flood|font|glyph(?!R)|horiz|image(!S)|letter|lighting|marker(?!H|W|U)|overline|paint|pointer|shape|stop|strikethrough|stroke|text(?!L)|transform|underline|unicode|units|v|vector|vert|word|writing|x(?!C))[A-Z]/; var J2 = /^on(Ani|Tra|Tou|BeforeInp|Compo)/; var K2 = /[A-Z0-9]/g; var Q = "undefined" != typeof document; var X = function(n2) { return ("undefined" != typeof Symbol && "symbol" == typeof Symbol() ? /fil|che|rad/ : /fil|che|ra/).test(n2); }; x.prototype.isReactComponent = {}, ["componentWillMount", "componentWillReceiveProps", "componentWillUpdate"].forEach(function(t3) { Object.defineProperty(x.prototype, t3, { configurable: true, get: function() { return this["UNSAFE_" + t3]; }, set: function(n2) { Object.defineProperty(this, t3, { configurable: true, writable: true, value: n2 }); } }); }); var en = l.event; function rn() { } function un() { return this.cancelBubble; } function on() { return this.defaultPrevented; } l.event = function(n2) { return en && (n2 = en(n2)), n2.persist = rn, n2.isPropagationStopped = un, n2.isDefaultPrevented = on, n2.nativeEvent = n2; }; var ln = { enumerable: false, configurable: true, get: function() { return this.class; } }; var fn = l.vnode; l.vnode = function(n2) { "string" == typeof n2.type && function(n3) { var t3 = n3.props, e3 = n3.type, u3 = {}, o3 = -1 === e3.indexOf("-"); for (var i3 in t3) { var c3 = t3[i3]; if (!("value" === i3 && "defaultValue" in t3 && null == c3 || Q && "children" === i3 && "noscript" === e3 || "class" === i3 || "className" === i3)) { var l3 = i3.toLowerCase(); "defaultValue" === i3 && "value" in t3 && null == t3.value ? i3 = "value" : "download" === i3 && true === c3 ? c3 = "" : "translate" === l3 && "no" === c3 ? c3 = false : "o" === l3[0] && "n" === l3[1] ? "ondoubleclick" === l3 ? i3 = "ondblclick" : "onchange" !== l3 || "input" !== e3 && "textarea" !== e3 || X(t3.type) ? "onfocus" === l3 ? i3 = "onfocusin" : "onblur" === l3 ? i3 = "onfocusout" : J2.test(i3) && (i3 = l3) : l3 = i3 = "oninput" : o3 && G2.test(i3) ? i3 = i3.replace(K2, "-$&").toLowerCase() : null === c3 && (c3 = void 0), "oninput" === l3 && u3[i3 = l3] && (i3 = "oninputCapture"), u3[i3] = c3; } } "select" == e3 && u3.multiple && Array.isArray(u3.value) && (u3.value = H(t3.children).forEach(function(n4) { n4.props.selected = -1 != u3.value.indexOf(n4.props.value); })), "select" == e3 && null != u3.defaultValue && (u3.value = H(t3.children).forEach(function(n4) { n4.props.selected = u3.multiple ? -1 != u3.defaultValue.indexOf(n4.props.value) : u3.defaultValue == n4.props.value; })), t3.class && !t3.className ? (u3.class = t3.class, Object.defineProperty(u3, "className", ln)) : (t3.className && !t3.class || t3.class && t3.className) && (u3.class = u3.className = t3.className), n3.props = u3; }(n2), n2.$$typeof = q3, fn && fn(n2); }; var an = l.__r; l.__r = function(n2) { an && an(n2); }; var sn = l.diffed; l.diffed = function(n2) { sn && sn(n2); var t3 = n2.props, e3 = n2.__e; null != e3 && "textarea" === n2.type && "value" in t3 && t3.value !== e3.value && (e3.value = null == t3.value ? "" : t3.value); }; // src/portal.tsx var Portal = (props) => { const { children, container, disabled, getRootNode } = props; const [, forceUpdate] = h2((c3) => c3 + 1, 0); _2(() => { forceUpdate({}); }, []); const isServer = typeof window === "undefined"; if (isServer || disabled) return /* @__PURE__ */ React.createElement(React.Fragment, null, children); const doc = getRootNode?.().ownerDocument ?? document; const mountNode = container?.current ?? doc.body; return /* @__PURE__ */ React.createElement(React.Fragment, null, O2.map(children, (child) => { return $2(/* @__PURE__ */ React.createElement(React.Fragment, null, child), mountNode); })); }; export { Portal, normalizeProps, useMachine };