@fragmentsx/render-react 0.0.4 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -1,464 +1,3959 @@
1
- import { render, createElement, Instance as Instance$1, Fragment as Fragment$1 } from "@fragmentsx/render-core";
2
- import require$$0, { createContext, useContext, useRef, useCallback, useState, useEffect } from "react";
3
- import "react/jsx-runtime";
1
+ import { jsx } from "react/jsx-runtime";
2
+ import require$$0, { createContext, useState, useEffect, useContext, useRef, useCallback, useMemo, Suspense } from "react";
4
3
  import { definition } from "@fragmentsx/definition";
5
- const GlobalManager = createContext(null);
6
- function createReactComponent(PreactComponent) {
7
- return function ReactWrapper(props) {
8
- const globalManager = useContext(GlobalManager);
9
- const containerRef = require$$0.useRef(null);
10
- require$$0.useEffect(() => {
11
- if (containerRef.current) {
12
- render(
13
- createElement(PreactComponent, {
14
- ...props,
15
- globalManager: (props == null ? void 0 : props.globalManager) ?? globalManager
16
- }),
17
- containerRef.current
18
- );
19
- }
20
- return () => {
21
- if (containerRef.current) {
22
- render(null, containerRef.current);
23
- }
24
- };
25
- }, [props, globalManager]);
26
- return require$$0.createElement("div", { ref: containerRef });
4
+ import { isPartialKey, keyOfEntity, entityOfKey, isLinkKey } from "@graph-state/core";
5
+ const collectStyles = (globalManager) => {
6
+ if (!globalManager) return null;
7
+ const allFragments = globalManager.$fragments.getManagers();
8
+ const extractors = Object.entries(allFragments).filter(([, value]) => !!(value == null ? void 0 : value.resolve)).map(([fragmentId, manager]) => {
9
+ var _a, _b, _c;
10
+ return (_c = (_b = (_a = manager == null ? void 0 : manager.$styleSheet) == null ? void 0 : _a.extract) == null ? void 0 : _b.call(_a)) == null ? void 0 : _c.at(0);
11
+ });
12
+ return extractors.map((extractor) => /* @__PURE__ */ jsx(
13
+ "style",
14
+ {
15
+ id: `fragments-${extractor == null ? void 0 : extractor.fragment}`,
16
+ dangerouslySetInnerHTML: { __html: extractor == null ? void 0 : extractor.styles.join("") }
17
+ }
18
+ ));
19
+ };
20
+ var n, l, t, i, r, o, e, f, c, s, a, p = {}, v = [], y$1 = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i, d = Array.isArray;
21
+ function w(n2, l2) {
22
+ for (var t2 in l2) n2[t2] = l2[t2];
23
+ return n2;
24
+ }
25
+ function g(n2) {
26
+ n2 && n2.parentNode && n2.parentNode.removeChild(n2);
27
+ }
28
+ function _(l2, t2, u) {
29
+ var i2, r2, o2, e2 = {};
30
+ for (o2 in t2) "key" == o2 ? i2 = t2[o2] : "ref" == o2 ? r2 = t2[o2] : e2[o2] = t2[o2];
31
+ if (arguments.length > 2 && (e2.children = arguments.length > 3 ? n.call(arguments, 2) : u), "function" == typeof l2 && null != l2.defaultProps) for (o2 in l2.defaultProps) void 0 === e2[o2] && (e2[o2] = l2.defaultProps[o2]);
32
+ return m(l2, e2, i2, r2, null);
33
+ }
34
+ function m(n2, u, i2, r2, o2) {
35
+ var e2 = { type: n2, props: u, key: i2, ref: r2, __k: null, __: null, __b: 0, __e: null, __c: null, constructor: void 0, __v: null == o2 ? ++t : o2, __i: -1, __u: 0 };
36
+ return null == o2 && null != l.vnode && l.vnode(e2), e2;
37
+ }
38
+ function k(n2) {
39
+ return n2.children;
40
+ }
41
+ function x$1(n2, l2) {
42
+ this.props = n2, this.context = l2;
43
+ }
44
+ function S$1(n2, l2) {
45
+ if (null == l2) return n2.__ ? S$1(n2.__, n2.__i + 1) : null;
46
+ for (var t2; l2 < n2.__k.length; l2++) if (null != (t2 = n2.__k[l2]) && null != t2.__e) return t2.__e;
47
+ return "function" == typeof n2.type ? S$1(n2) : null;
48
+ }
49
+ function C(n2) {
50
+ var l2, t2;
51
+ if (null != (n2 = n2.__) && null != n2.__c) {
52
+ for (n2.__e = n2.__c.base = null, l2 = 0; l2 < n2.__k.length; l2++) if (null != (t2 = n2.__k[l2]) && null != t2.__e) {
53
+ n2.__e = n2.__c.base = t2.__e;
54
+ break;
55
+ }
56
+ return C(n2);
57
+ }
58
+ }
59
+ function M(n2) {
60
+ (!n2.__d && (n2.__d = true) && i.push(n2) && !$.__r++ || r !== l.debounceRendering) && ((r = l.debounceRendering) || o)($);
61
+ }
62
+ function $() {
63
+ for (var n2, t2, u, r2, o2, f2, c2, s2 = 1; i.length; ) i.length > s2 && i.sort(e), n2 = i.shift(), s2 = i.length, n2.__d && (u = void 0, o2 = (r2 = (t2 = n2).__v).__e, f2 = [], c2 = [], t2.__P && ((u = w({}, r2)).__v = r2.__v + 1, l.vnode && l.vnode(u), O(t2.__P, u, r2, t2.__n, t2.__P.namespaceURI, 32 & r2.__u ? [o2] : null, f2, null == o2 ? S$1(r2) : o2, !!(32 & r2.__u), c2), u.__v = r2.__v, u.__.__k[u.__i] = u, z(f2, u, c2), u.__e != o2 && C(u)));
64
+ $.__r = 0;
65
+ }
66
+ function I(n2, l2, t2, u, i2, r2, o2, e2, f2, c2, s2) {
67
+ var a2, h, y2, d2, w2, g2, _2 = u && u.__k || v, m2 = l2.length;
68
+ for (f2 = P(t2, l2, _2, f2, m2), a2 = 0; a2 < m2; a2++) null != (y2 = t2.__k[a2]) && (h = -1 === y2.__i ? p : _2[y2.__i] || p, y2.__i = a2, g2 = O(n2, y2, h, i2, r2, o2, e2, f2, c2, s2), d2 = y2.__e, y2.ref && h.ref != y2.ref && (h.ref && q(h.ref, null, y2), s2.push(y2.ref, y2.__c || d2, y2)), null == w2 && null != d2 && (w2 = d2), 4 & y2.__u || h.__k === y2.__k ? f2 = A(y2, f2, n2) : "function" == typeof y2.type && void 0 !== g2 ? f2 = g2 : d2 && (f2 = d2.nextSibling), y2.__u &= -7);
69
+ return t2.__e = w2, f2;
70
+ }
71
+ function P(n2, l2, t2, u, i2) {
72
+ var r2, o2, e2, f2, c2, s2 = t2.length, a2 = s2, h = 0;
73
+ for (n2.__k = new Array(i2), r2 = 0; r2 < i2; r2++) null != (o2 = l2[r2]) && "boolean" != typeof o2 && "function" != typeof o2 ? (f2 = r2 + h, (o2 = n2.__k[r2] = "string" == typeof o2 || "number" == typeof o2 || "bigint" == typeof o2 || o2.constructor == String ? m(null, o2, null, null, null) : d(o2) ? m(k, { children: o2 }, null, null, null) : void 0 === o2.constructor && o2.__b > 0 ? m(o2.type, o2.props, o2.key, o2.ref ? o2.ref : null, o2.__v) : o2).__ = n2, o2.__b = n2.__b + 1, e2 = null, -1 !== (c2 = o2.__i = L(o2, t2, f2, a2)) && (a2--, (e2 = t2[c2]) && (e2.__u |= 2)), null == e2 || null === e2.__v ? (-1 == c2 && (i2 > s2 ? h-- : i2 < s2 && h++), "function" != typeof o2.type && (o2.__u |= 4)) : c2 != f2 && (c2 == f2 - 1 ? h-- : c2 == f2 + 1 ? h++ : (c2 > f2 ? h-- : h++, o2.__u |= 4))) : n2.__k[r2] = null;
74
+ if (a2) for (r2 = 0; r2 < s2; r2++) null != (e2 = t2[r2]) && 0 == (2 & e2.__u) && (e2.__e == u && (u = S$1(e2)), B(e2, e2));
75
+ return u;
76
+ }
77
+ function A(n2, l2, t2) {
78
+ var u, i2;
79
+ if ("function" == typeof n2.type) {
80
+ for (u = n2.__k, i2 = 0; u && i2 < u.length; i2++) u[i2] && (u[i2].__ = n2, l2 = A(u[i2], l2, t2));
81
+ return l2;
82
+ }
83
+ n2.__e != l2 && (l2 && n2.type && !t2.contains(l2) && (l2 = S$1(n2)), t2.insertBefore(n2.__e, l2 || null), l2 = n2.__e);
84
+ do {
85
+ l2 = l2 && l2.nextSibling;
86
+ } while (null != l2 && 8 == l2.nodeType);
87
+ return l2;
88
+ }
89
+ function L(n2, l2, t2, u) {
90
+ var i2, r2, o2 = n2.key, e2 = n2.type, f2 = l2[t2];
91
+ if (null === f2 && null == n2.key || f2 && o2 == f2.key && e2 === f2.type && 0 == (2 & f2.__u)) return t2;
92
+ if (u > (null != f2 && 0 == (2 & f2.__u) ? 1 : 0)) for (i2 = t2 - 1, r2 = t2 + 1; i2 >= 0 || r2 < l2.length; ) {
93
+ if (i2 >= 0) {
94
+ if ((f2 = l2[i2]) && 0 == (2 & f2.__u) && o2 == f2.key && e2 === f2.type) return i2;
95
+ i2--;
96
+ }
97
+ if (r2 < l2.length) {
98
+ if ((f2 = l2[r2]) && 0 == (2 & f2.__u) && o2 == f2.key && e2 === f2.type) return r2;
99
+ r2++;
100
+ }
101
+ }
102
+ return -1;
103
+ }
104
+ function T(n2, l2, t2) {
105
+ "-" == l2[0] ? n2.setProperty(l2, null == t2 ? "" : t2) : n2[l2] = null == t2 ? "" : "number" != typeof t2 || y$1.test(l2) ? t2 : t2 + "px";
106
+ }
107
+ function j(n2, l2, t2, u, i2) {
108
+ var r2;
109
+ n: if ("style" == l2) if ("string" == typeof t2) n2.style.cssText = t2;
110
+ else {
111
+ if ("string" == typeof u && (n2.style.cssText = u = ""), u) for (l2 in u) t2 && l2 in t2 || T(n2.style, l2, "");
112
+ if (t2) for (l2 in t2) u && t2[l2] === u[l2] || T(n2.style, l2, t2[l2]);
113
+ }
114
+ else if ("o" == l2[0] && "n" == l2[1]) r2 = l2 != (l2 = l2.replace(f, "$1")), l2 = l2.toLowerCase() in n2 || "onFocusOut" == l2 || "onFocusIn" == l2 ? l2.toLowerCase().slice(2) : l2.slice(2), n2.l || (n2.l = {}), n2.l[l2 + r2] = t2, t2 ? u ? t2.t = u.t : (t2.t = c, n2.addEventListener(l2, r2 ? a : s, r2)) : n2.removeEventListener(l2, r2 ? a : s, r2);
115
+ else {
116
+ if ("http://www.w3.org/2000/svg" == i2) l2 = l2.replace(/xlink(H|:h)/, "h").replace(/sName$/, "s");
117
+ else if ("width" != l2 && "height" != l2 && "href" != l2 && "list" != l2 && "form" != l2 && "tabIndex" != l2 && "download" != l2 && "rowSpan" != l2 && "colSpan" != l2 && "role" != l2 && "popover" != l2 && l2 in n2) try {
118
+ n2[l2] = null == t2 ? "" : t2;
119
+ break n;
120
+ } catch (n3) {
121
+ }
122
+ "function" == typeof t2 || (null == t2 || false === t2 && "-" != l2[4] ? n2.removeAttribute(l2) : n2.setAttribute(l2, "popover" == l2 && 1 == t2 ? "" : t2));
123
+ }
124
+ }
125
+ function F(n2) {
126
+ return function(t2) {
127
+ if (this.l) {
128
+ var u = this.l[t2.type + n2];
129
+ if (null == t2.u) t2.u = c++;
130
+ else if (t2.u < u.t) return;
131
+ return u(l.event ? l.event(t2) : t2);
132
+ }
27
133
  };
28
134
  }
29
- const useGlobalManager = () => useContext(GlobalManager);
30
- var shim = { exports: {} };
31
- var useSyncExternalStoreShim_production_min = {};
32
- /**
33
- * @license React
34
- * use-sync-external-store-shim.production.min.js
35
- *
36
- * Copyright (c) Facebook, Inc. and its affiliates.
37
- *
38
- * This source code is licensed under the MIT license found in the
39
- * LICENSE file in the root directory of this source tree.
40
- */
41
- var hasRequiredUseSyncExternalStoreShim_production_min;
42
- function requireUseSyncExternalStoreShim_production_min() {
43
- if (hasRequiredUseSyncExternalStoreShim_production_min) return useSyncExternalStoreShim_production_min;
44
- hasRequiredUseSyncExternalStoreShim_production_min = 1;
45
- var e = require$$0;
46
- function h(a, b) {
47
- return a === b && (0 !== a || 1 / a === 1 / b) || a !== a && b !== b;
48
- }
49
- var k = "function" === typeof Object.is ? Object.is : h, l = e.useState, m = e.useEffect, n = e.useLayoutEffect, p = e.useDebugValue;
50
- function q(a, b) {
51
- var d = b(), f = l({ inst: { value: d, getSnapshot: b } }), c = f[0].inst, g = f[1];
52
- n(function() {
53
- c.value = d;
54
- c.getSnapshot = b;
55
- r(c) && g({ inst: c });
56
- }, [a, d, b]);
57
- m(function() {
58
- r(c) && g({ inst: c });
59
- return a(function() {
60
- r(c) && g({ inst: c });
135
+ function O(n2, t2, u, i2, r2, o2, e2, f2, c2, s2) {
136
+ var a2, h, p2, v2, y2, _2, m2, b, S2, C2, M2, $2, P2, A2, H, L2, T2, j2 = t2.type;
137
+ if (void 0 !== t2.constructor) return null;
138
+ 128 & u.__u && (c2 = !!(32 & u.__u), o2 = [f2 = t2.__e = u.__e]), (a2 = l.__b) && a2(t2);
139
+ n: if ("function" == typeof j2) try {
140
+ if (b = t2.props, S2 = "prototype" in j2 && j2.prototype.render, C2 = (a2 = j2.contextType) && i2[a2.__c], M2 = a2 ? C2 ? C2.props.value : a2.__ : i2, u.__c ? m2 = (h = t2.__c = u.__c).__ = h.__E : (S2 ? t2.__c = h = new j2(b, M2) : (t2.__c = h = new x$1(b, M2), h.constructor = j2, h.render = D), C2 && C2.sub(h), h.props = b, h.state || (h.state = {}), h.context = M2, h.__n = i2, p2 = h.__d = true, h.__h = [], h._sb = []), S2 && null == h.__s && (h.__s = h.state), S2 && null != j2.getDerivedStateFromProps && (h.__s == h.state && (h.__s = w({}, h.__s)), w(h.__s, j2.getDerivedStateFromProps(b, h.__s))), v2 = h.props, y2 = h.state, h.__v = t2, p2) S2 && null == j2.getDerivedStateFromProps && null != h.componentWillMount && h.componentWillMount(), S2 && null != h.componentDidMount && h.__h.push(h.componentDidMount);
141
+ else {
142
+ if (S2 && null == j2.getDerivedStateFromProps && b !== v2 && null != h.componentWillReceiveProps && h.componentWillReceiveProps(b, M2), !h.__e && (null != h.shouldComponentUpdate && false === h.shouldComponentUpdate(b, h.__s, M2) || t2.__v == u.__v)) {
143
+ for (t2.__v != u.__v && (h.props = b, h.state = h.__s, h.__d = false), t2.__e = u.__e, t2.__k = u.__k, t2.__k.some(function(n3) {
144
+ n3 && (n3.__ = t2);
145
+ }), $2 = 0; $2 < h._sb.length; $2++) h.__h.push(h._sb[$2]);
146
+ h._sb = [], h.__h.length && e2.push(h);
147
+ break n;
148
+ }
149
+ null != h.componentWillUpdate && h.componentWillUpdate(b, h.__s, M2), S2 && null != h.componentDidUpdate && h.__h.push(function() {
150
+ h.componentDidUpdate(v2, y2, _2);
61
151
  });
62
- }, [a]);
63
- p(d);
64
- return d;
152
+ }
153
+ if (h.context = M2, h.props = b, h.__P = n2, h.__e = false, P2 = l.__r, A2 = 0, S2) {
154
+ for (h.state = h.__s, h.__d = false, P2 && P2(t2), a2 = h.render(h.props, h.state, h.context), H = 0; H < h._sb.length; H++) h.__h.push(h._sb[H]);
155
+ h._sb = [];
156
+ } else do {
157
+ h.__d = false, P2 && P2(t2), a2 = h.render(h.props, h.state, h.context), h.state = h.__s;
158
+ } while (h.__d && ++A2 < 25);
159
+ h.state = h.__s, null != h.getChildContext && (i2 = w(w({}, i2), h.getChildContext())), S2 && !p2 && null != h.getSnapshotBeforeUpdate && (_2 = h.getSnapshotBeforeUpdate(v2, y2)), L2 = a2, null != a2 && a2.type === k && null == a2.key && (L2 = N(a2.props.children)), f2 = I(n2, d(L2) ? L2 : [L2], t2, u, i2, r2, o2, e2, f2, c2, s2), h.base = t2.__e, t2.__u &= -161, h.__h.length && e2.push(h), m2 && (h.__E = h.__ = null);
160
+ } catch (n3) {
161
+ if (t2.__v = null, c2 || null != o2) if (n3.then) {
162
+ for (t2.__u |= c2 ? 160 : 128; f2 && 8 == f2.nodeType && f2.nextSibling; ) f2 = f2.nextSibling;
163
+ o2[o2.indexOf(f2)] = null, t2.__e = f2;
164
+ } else for (T2 = o2.length; T2--; ) g(o2[T2]);
165
+ else t2.__e = u.__e, t2.__k = u.__k;
166
+ l.__e(n3, t2, u);
65
167
  }
66
- function r(a) {
67
- var b = a.getSnapshot;
68
- a = a.value;
168
+ else null == o2 && t2.__v == u.__v ? (t2.__k = u.__k, t2.__e = u.__e) : f2 = t2.__e = V(u.__e, t2, u, i2, r2, o2, e2, c2, s2);
169
+ return (a2 = l.diffed) && a2(t2), 128 & t2.__u ? void 0 : f2;
170
+ }
171
+ function z(n2, t2, u) {
172
+ for (var i2 = 0; i2 < u.length; i2++) q(u[i2], u[++i2], u[++i2]);
173
+ l.__c && l.__c(t2, n2), n2.some(function(t3) {
69
174
  try {
70
- var d = b();
71
- return !k(a, d);
72
- } catch (f) {
73
- return true;
175
+ n2 = t3.__h, t3.__h = [], n2.some(function(n3) {
176
+ n3.call(t3);
177
+ });
178
+ } catch (n3) {
179
+ l.__e(n3, t3.__v);
180
+ }
181
+ });
182
+ }
183
+ function N(n2) {
184
+ return "object" != typeof n2 || null == n2 ? n2 : d(n2) ? n2.map(N) : w({}, n2);
185
+ }
186
+ function V(t2, u, i2, r2, o2, e2, f2, c2, s2) {
187
+ var a2, h, v2, y2, w2, _2, m2, b = i2.props, k2 = u.props, x2 = u.type;
188
+ if ("svg" == x2 ? o2 = "http://www.w3.org/2000/svg" : "math" == x2 ? o2 = "http://www.w3.org/1998/Math/MathML" : o2 || (o2 = "http://www.w3.org/1999/xhtml"), null != e2) {
189
+ for (a2 = 0; a2 < e2.length; a2++) if ((w2 = e2[a2]) && "setAttribute" in w2 == !!x2 && (x2 ? w2.localName == x2 : 3 == w2.nodeType)) {
190
+ t2 = w2, e2[a2] = null;
191
+ break;
74
192
  }
75
193
  }
76
- function t(a, b) {
77
- return b();
194
+ if (null == t2) {
195
+ if (null == x2) return document.createTextNode(k2);
196
+ t2 = document.createElementNS(o2, x2, k2.is && k2), c2 && (l.__m && l.__m(u, e2), c2 = false), e2 = null;
197
+ }
198
+ if (null === x2) b === k2 || c2 && t2.data === k2 || (t2.data = k2);
199
+ else {
200
+ if (e2 = e2 && n.call(t2.childNodes), b = i2.props || p, !c2 && null != e2) for (b = {}, a2 = 0; a2 < t2.attributes.length; a2++) b[(w2 = t2.attributes[a2]).name] = w2.value;
201
+ for (a2 in b) if (w2 = b[a2], "children" == a2) ;
202
+ else if ("dangerouslySetInnerHTML" == a2) v2 = w2;
203
+ else if (!(a2 in k2)) {
204
+ if ("value" == a2 && "defaultValue" in k2 || "checked" == a2 && "defaultChecked" in k2) continue;
205
+ j(t2, a2, null, w2, o2);
206
+ }
207
+ for (a2 in k2) w2 = k2[a2], "children" == a2 ? y2 = w2 : "dangerouslySetInnerHTML" == a2 ? h = w2 : "value" == a2 ? _2 = w2 : "checked" == a2 ? m2 = w2 : c2 && "function" != typeof w2 || b[a2] === w2 || j(t2, a2, w2, b[a2], o2);
208
+ if (h) c2 || v2 && (h.__html === v2.__html || h.__html === t2.innerHTML) || (t2.innerHTML = h.__html), u.__k = [];
209
+ else if (v2 && (t2.innerHTML = ""), I("template" === u.type ? t2.content : t2, d(y2) ? y2 : [y2], u, i2, r2, "foreignObject" == x2 ? "http://www.w3.org/1999/xhtml" : o2, e2, f2, e2 ? e2[0] : i2.__k && S$1(i2, 0), c2, s2), null != e2) for (a2 = e2.length; a2--; ) g(e2[a2]);
210
+ c2 || (a2 = "value", "progress" == x2 && null == _2 ? t2.removeAttribute("value") : void 0 !== _2 && (_2 !== t2[a2] || "progress" == x2 && !_2 || "option" == x2 && _2 !== b[a2]) && j(t2, a2, _2, b[a2], o2), a2 = "checked", void 0 !== m2 && m2 !== t2[a2] && j(t2, a2, m2, b[a2], o2));
78
211
  }
79
- var u = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? t : q;
80
- useSyncExternalStoreShim_production_min.useSyncExternalStore = void 0 !== e.useSyncExternalStore ? e.useSyncExternalStore : u;
81
- return useSyncExternalStoreShim_production_min;
212
+ return t2;
82
213
  }
83
- var useSyncExternalStoreShim_development = {};
84
- /**
85
- * @license React
86
- * use-sync-external-store-shim.development.js
87
- *
88
- * Copyright (c) Facebook, Inc. and its affiliates.
89
- *
90
- * This source code is licensed under the MIT license found in the
91
- * LICENSE file in the root directory of this source tree.
92
- */
93
- var hasRequiredUseSyncExternalStoreShim_development;
94
- function requireUseSyncExternalStoreShim_development() {
95
- if (hasRequiredUseSyncExternalStoreShim_development) return useSyncExternalStoreShim_development;
96
- hasRequiredUseSyncExternalStoreShim_development = 1;
97
- if (process.env.NODE_ENV !== "production") {
98
- (function() {
99
- if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === "function") {
100
- __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
101
- }
102
- var React = require$$0;
103
- var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
104
- function error(format) {
105
- {
106
- {
107
- for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
108
- args[_key2 - 1] = arguments[_key2];
109
- }
110
- printWarning("error", format, args);
111
- }
112
- }
214
+ function q(n2, t2, u) {
215
+ try {
216
+ if ("function" == typeof n2) {
217
+ var i2 = "function" == typeof n2.__u;
218
+ i2 && n2.__u(), i2 && null == t2 || (n2.__u = n2(t2));
219
+ } else n2.current = t2;
220
+ } catch (n3) {
221
+ l.__e(n3, u);
222
+ }
223
+ }
224
+ function B(n2, t2, u) {
225
+ var i2, r2;
226
+ if (l.unmount && l.unmount(n2), (i2 = n2.ref) && (i2.current && i2.current !== n2.__e || q(i2, null, t2)), null != (i2 = n2.__c)) {
227
+ if (i2.componentWillUnmount) try {
228
+ i2.componentWillUnmount();
229
+ } catch (n3) {
230
+ l.__e(n3, t2);
231
+ }
232
+ i2.base = i2.__P = null;
233
+ }
234
+ if (i2 = n2.__k) for (r2 = 0; r2 < i2.length; r2++) i2[r2] && B(i2[r2], t2, u || "function" != typeof n2.type);
235
+ u || g(n2.__e), n2.__c = n2.__ = n2.__e = void 0;
236
+ }
237
+ function D(n2, l2, t2) {
238
+ return this.constructor(n2, t2);
239
+ }
240
+ function E(t2, u, i2) {
241
+ var r2, o2, e2, f2;
242
+ u == document && (u = document.documentElement), l.__ && l.__(t2, u), o2 = (r2 = "function" == typeof i2) ? null : i2 && i2.__k || u.__k, e2 = [], f2 = [], O(u, t2 = (!r2 && i2 || u).__k = _(k, null, [t2]), o2 || p, p, u.namespaceURI, !r2 && i2 ? [i2] : o2 ? null : u.firstChild ? n.call(u.childNodes) : null, e2, !r2 && i2 ? i2 : o2 ? o2.__e : u.firstChild, r2, f2), z(e2, t2, f2);
243
+ }
244
+ function G(n2, l2) {
245
+ E(n2, l2, G);
246
+ }
247
+ function J(l2, t2, u) {
248
+ var i2, r2, o2, e2, f2 = w({}, l2.props);
249
+ for (o2 in l2.type && l2.type.defaultProps && (e2 = l2.type.defaultProps), t2) "key" == o2 ? i2 = t2[o2] : "ref" == o2 ? r2 = t2[o2] : f2[o2] = void 0 === t2[o2] && void 0 !== e2 ? e2[o2] : t2[o2];
250
+ return arguments.length > 2 && (f2.children = arguments.length > 3 ? n.call(arguments, 2) : u), m(l2.type, f2, i2 || l2.key, r2 || l2.ref, null);
251
+ }
252
+ n = v.slice, l = { __e: function(n2, l2, t2, u) {
253
+ for (var i2, r2, o2; l2 = l2.__; ) if ((i2 = l2.__c) && !i2.__) try {
254
+ if ((r2 = i2.constructor) && null != r2.getDerivedStateFromError && (i2.setState(r2.getDerivedStateFromError(n2)), o2 = i2.__d), null != i2.componentDidCatch && (i2.componentDidCatch(n2, u || {}), o2 = i2.__d), o2) return i2.__E = i2;
255
+ } catch (l3) {
256
+ n2 = l3;
257
+ }
258
+ throw n2;
259
+ } }, t = 0, x$1.prototype.setState = function(n2, l2) {
260
+ var t2;
261
+ t2 = null != this.__s && this.__s !== this.state ? this.__s : this.__s = w({}, this.state), "function" == typeof n2 && (n2 = n2(w({}, t2), this.props)), n2 && w(t2, n2), null != n2 && this.__v && (l2 && this._sb.push(l2), M(this));
262
+ }, x$1.prototype.forceUpdate = function(n2) {
263
+ this.__v && (this.__e = true, n2 && this.__h.push(n2), M(this));
264
+ }, x$1.prototype.render = k, i = [], o = "function" == typeof Promise ? Promise.prototype.then.bind(Promise.resolve()) : setTimeout, e = function(n2, l2) {
265
+ return n2.__v.__b - l2.__v.__b;
266
+ }, $.__r = 0, f = /(PointerCapture)$|Capture$/i, c = 0, s = F(false), a = F(true);
267
+ (function() {
268
+ try {
269
+ if (typeof document != "undefined") {
270
+ var elementStyle = document.createElement("style");
271
+ elementStyle.appendChild(document.createTextNode("._fragment_1c708_1 {\n width: 100%;\n height: 100%;\n}\n\n._fragmentDocument_1c708_6 {\n display: contents;\n}\n._text_1liuf_1 {\n white-space: pre;\n :where(p) {\n margin: 0;\n }\n}"));
272
+ document.head.appendChild(elementStyle);
273
+ }
274
+ } catch (e2) {
275
+ console.error("vite-plugin-css-injected-by-js", e2);
276
+ }
277
+ })();
278
+ const createConstants = (...constants) => {
279
+ return constants.reduce((acc, constant) => {
280
+ acc[constant] = constant;
281
+ return acc;
282
+ }, {});
283
+ };
284
+ const nodes = createConstants(
285
+ "Fragment",
286
+ "FragmentInstance",
287
+ "Instance",
288
+ "Collection",
289
+ "Breakpoint",
290
+ "Frame",
291
+ "Image",
292
+ "Text",
293
+ "SolidPaintStyle",
294
+ "CssLink",
295
+ "Variable",
296
+ "ComputedValue",
297
+ "TransformValue"
298
+ );
299
+ const fragmentGrowingMode = createConstants("auto", "fill");
300
+ const borderType = createConstants("None", "Solid", "Dashed", "Dotted");
301
+ const linkTarget = createConstants("_blank", "none");
302
+ const paintMode = createConstants("None", "Solid", "Image");
303
+ const imagePaintScaleModes = createConstants("Auto", "Contain", "Cover");
304
+ const constrain = createConstants(
305
+ "Min",
306
+ "Center",
307
+ "Max",
308
+ "Stretch",
309
+ "Scale"
310
+ );
311
+ const positionType = createConstants("absolute", "relative");
312
+ const sizing = createConstants("Fixed", "Hug", "Fill", "Relative");
313
+ const layerMode = createConstants("none", "flex");
314
+ const layerDirection = createConstants("vertical", "horizontal");
315
+ const layerAlign = createConstants("start", "center", "end");
316
+ const layerDistribute = createConstants(
317
+ "start",
318
+ "center",
319
+ "end",
320
+ "space-between",
321
+ "space-around"
322
+ );
323
+ const textTransform = createConstants(
324
+ "none",
325
+ "uppercase",
326
+ "lowercase",
327
+ "capitalize"
328
+ );
329
+ const textDecorations = createConstants(
330
+ "none",
331
+ "underline",
332
+ "line-through"
333
+ );
334
+ const effectType = createConstants("loop", "appear", "hover", "tap");
335
+ const effectName = createConstants(
336
+ "fade",
337
+ "slide",
338
+ "bounce",
339
+ "wiggle",
340
+ "increase"
341
+ );
342
+ const variableType = createConstants(
343
+ "Event",
344
+ "String",
345
+ "Link",
346
+ "Boolean",
347
+ "Array",
348
+ "Color",
349
+ "ComponentInstance",
350
+ "Date",
351
+ "Enum",
352
+ "Number",
353
+ "Image",
354
+ "Object"
355
+ );
356
+ const whiteSpace = createConstants(
357
+ "normal",
358
+ "nowrap",
359
+ "pre",
360
+ "pre-wrap",
361
+ "pre-line",
362
+ "break-spaces"
363
+ );
364
+ const overflow = createConstants("visible", "hidden", "scroll");
365
+ const variableTransforms = createConstants(
366
+ "convert",
367
+ "exists",
368
+ "equals",
369
+ "startWith",
370
+ "endWith",
371
+ "contains",
372
+ "dateBefore",
373
+ "dateAfter",
374
+ "dateBetween",
375
+ "feature",
376
+ "notFeature",
377
+ "gt",
378
+ // Greater than
379
+ "gte",
380
+ // Greater than or equals
381
+ "lt",
382
+ // Less than
383
+ "lte",
384
+ // Less than or equals,
385
+ "convertFromBoolean",
386
+ "negative"
387
+ );
388
+ const renderTarget = createConstants("canvas", "document");
389
+ const renderMode = createConstants("viewport", "parent", "fixed");
390
+ const interactions = createConstants("click", "mouseover", "appear");
391
+ const eventMode = createConstants("goal", "callback", "tracker");
392
+ const scopeTypes = createConstants(
393
+ "InstanceScope",
394
+ "FragmentScope",
395
+ "CollectionScope",
396
+ "CollectionItemScope"
397
+ );
398
+ const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
399
+ __proto__: null,
400
+ borderType,
401
+ constrain,
402
+ createConstants,
403
+ effectName,
404
+ effectType,
405
+ eventMode,
406
+ fragmentGrowingMode,
407
+ imagePaintScaleModes,
408
+ interactions,
409
+ layerAlign,
410
+ layerDirection,
411
+ layerDistribute,
412
+ layerMode,
413
+ linkTarget,
414
+ nodes,
415
+ overflow,
416
+ paintMode,
417
+ positionType,
418
+ renderMode,
419
+ renderTarget,
420
+ scopeTypes,
421
+ sizing,
422
+ textDecorations,
423
+ textTransform,
424
+ variableTransforms,
425
+ variableType,
426
+ whiteSpace
427
+ }, Symbol.toStringTag, { value: "Module" }));
428
+ // @__NO_SIDE_EFFECTS__
429
+ function getGlobalConfig(config2) {
430
+ return {
431
+ lang: (config2 == null ? void 0 : config2.lang) ?? void 0,
432
+ message: config2 == null ? void 0 : config2.message,
433
+ abortEarly: (config2 == null ? void 0 : config2.abortEarly) ?? void 0,
434
+ abortPipeEarly: (config2 == null ? void 0 : config2.abortPipeEarly) ?? void 0
435
+ };
436
+ }
437
+ // @__NO_SIDE_EFFECTS__
438
+ function getGlobalMessage(lang) {
439
+ return void 0;
440
+ }
441
+ // @__NO_SIDE_EFFECTS__
442
+ function getSchemaMessage(lang) {
443
+ return void 0;
444
+ }
445
+ // @__NO_SIDE_EFFECTS__
446
+ function getSpecificMessage(reference, lang) {
447
+ var _a;
448
+ return (_a = void 0) == null ? void 0 : _a.get(lang);
449
+ }
450
+ // @__NO_SIDE_EFFECTS__
451
+ function _stringify(input) {
452
+ var _a, _b;
453
+ const type = typeof input;
454
+ if (type === "string") {
455
+ return `"${input}"`;
456
+ }
457
+ if (type === "number" || type === "bigint" || type === "boolean") {
458
+ return `${input}`;
459
+ }
460
+ if (type === "object" || type === "function") {
461
+ return (input && ((_b = (_a = Object.getPrototypeOf(input)) == null ? void 0 : _a.constructor) == null ? void 0 : _b.name)) ?? "null";
462
+ }
463
+ return type;
464
+ }
465
+ function _addIssue(context, label, dataset, config2, other) {
466
+ const input = other && "input" in other ? other.input : dataset.value;
467
+ const expected = (other == null ? void 0 : other.expected) ?? context.expects ?? null;
468
+ const received = (other == null ? void 0 : other.received) ?? /* @__PURE__ */ _stringify(input);
469
+ const issue = {
470
+ kind: context.kind,
471
+ type: context.type,
472
+ input,
473
+ expected,
474
+ received,
475
+ message: `Invalid ${label}: ${expected ? `Expected ${expected} but r` : "R"}eceived ${received}`,
476
+ requirement: context.requirement,
477
+ path: other == null ? void 0 : other.path,
478
+ issues: other == null ? void 0 : other.issues,
479
+ lang: config2.lang,
480
+ abortEarly: config2.abortEarly,
481
+ abortPipeEarly: config2.abortPipeEarly
482
+ };
483
+ const isSchema = context.kind === "schema";
484
+ const message = (other == null ? void 0 : other.message) ?? context.message ?? /* @__PURE__ */ getSpecificMessage(context.reference, issue.lang) ?? (isSchema ? /* @__PURE__ */ getSchemaMessage(issue.lang) : null) ?? config2.message ?? /* @__PURE__ */ getGlobalMessage(issue.lang);
485
+ if (message !== void 0) {
486
+ issue.message = typeof message === "function" ? (
487
+ // @ts-expect-error
488
+ message(issue)
489
+ ) : message;
490
+ }
491
+ if (isSchema) {
492
+ dataset.typed = false;
493
+ }
494
+ if (dataset.issues) {
495
+ dataset.issues.push(issue);
496
+ } else {
497
+ dataset.issues = [issue];
498
+ }
499
+ }
500
+ // @__NO_SIDE_EFFECTS__
501
+ function _getStandardProps(context) {
502
+ return {
503
+ version: 1,
504
+ vendor: "valibot",
505
+ validate(value2) {
506
+ return context["~run"]({ value: value2 }, /* @__PURE__ */ getGlobalConfig());
507
+ }
508
+ };
509
+ }
510
+ // @__NO_SIDE_EFFECTS__
511
+ function _isValidObjectKey(object2, key) {
512
+ return Object.hasOwn(object2, key) && key !== "__proto__" && key !== "prototype" && key !== "constructor";
513
+ }
514
+ // @__NO_SIDE_EFFECTS__
515
+ function _joinExpects(values2, separator) {
516
+ const list = [...new Set(values2)];
517
+ if (list.length > 1) {
518
+ return `(${list.join(` ${separator} `)})`;
519
+ }
520
+ return list[0] ?? "never";
521
+ }
522
+ // @__NO_SIDE_EFFECTS__
523
+ function isOfKind(kind, object2) {
524
+ return object2.kind === kind;
525
+ }
526
+ var ValiError = class extends Error {
527
+ /**
528
+ * Creates a Valibot error with useful information.
529
+ *
530
+ * @param issues The error issues.
531
+ */
532
+ constructor(issues) {
533
+ super(issues[0].message);
534
+ this.name = "ValiError";
535
+ this.issues = issues;
536
+ }
537
+ };
538
+ // @__NO_SIDE_EFFECTS__
539
+ function check(requirement, message) {
540
+ return {
541
+ kind: "validation",
542
+ type: "check",
543
+ reference: check,
544
+ async: false,
545
+ expects: null,
546
+ requirement,
547
+ message,
548
+ "~run"(dataset, config2) {
549
+ if (dataset.typed && !this.requirement(dataset.value)) {
550
+ _addIssue(this, "input", dataset, config2);
113
551
  }
114
- function printWarning(level, format, args) {
115
- {
116
- var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
117
- var stack = ReactDebugCurrentFrame.getStackAddendum();
118
- if (stack !== "") {
119
- format += "%s";
120
- args = args.concat([stack]);
121
- }
122
- var argsWithFormat = args.map(function(item) {
123
- return String(item);
124
- });
125
- argsWithFormat.unshift("Warning: " + format);
126
- Function.prototype.apply.call(console[level], console, argsWithFormat);
127
- }
552
+ return dataset;
553
+ }
554
+ };
555
+ }
556
+ // @__NO_SIDE_EFFECTS__
557
+ function maxValue(requirement, message) {
558
+ return {
559
+ kind: "validation",
560
+ type: "max_value",
561
+ reference: maxValue,
562
+ async: false,
563
+ expects: `<=${requirement instanceof Date ? requirement.toJSON() : /* @__PURE__ */ _stringify(requirement)}`,
564
+ requirement,
565
+ message,
566
+ "~run"(dataset, config2) {
567
+ if (dataset.typed && !(dataset.value <= this.requirement)) {
568
+ _addIssue(this, "value", dataset, config2, {
569
+ received: dataset.value instanceof Date ? dataset.value.toJSON() : /* @__PURE__ */ _stringify(dataset.value)
570
+ });
128
571
  }
129
- function is(x, y2) {
130
- return x === y2 && (x !== 0 || 1 / x === 1 / y2) || x !== x && y2 !== y2;
572
+ return dataset;
573
+ }
574
+ };
575
+ }
576
+ // @__NO_SIDE_EFFECTS__
577
+ function metadata(metadata_) {
578
+ return {
579
+ kind: "metadata",
580
+ type: "metadata",
581
+ reference: metadata,
582
+ metadata: metadata_
583
+ };
584
+ }
585
+ // @__NO_SIDE_EFFECTS__
586
+ function minValue(requirement, message) {
587
+ return {
588
+ kind: "validation",
589
+ type: "min_value",
590
+ reference: minValue,
591
+ async: false,
592
+ expects: `>=${requirement instanceof Date ? requirement.toJSON() : /* @__PURE__ */ _stringify(requirement)}`,
593
+ requirement,
594
+ message,
595
+ "~run"(dataset, config2) {
596
+ if (dataset.typed && !(dataset.value >= this.requirement)) {
597
+ _addIssue(this, "value", dataset, config2, {
598
+ received: dataset.value instanceof Date ? dataset.value.toJSON() : /* @__PURE__ */ _stringify(dataset.value)
599
+ });
131
600
  }
132
- var objectIs = typeof Object.is === "function" ? Object.is : is;
133
- var useState2 = React.useState, useEffect2 = React.useEffect, useLayoutEffect = React.useLayoutEffect, useDebugValue = React.useDebugValue;
134
- var didWarnOld18Alpha = false;
135
- var didWarnUncachedGetSnapshot = false;
136
- function useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot) {
137
- {
138
- if (!didWarnOld18Alpha) {
139
- if (React.startTransition !== void 0) {
140
- didWarnOld18Alpha = true;
141
- error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release.");
601
+ return dataset;
602
+ }
603
+ };
604
+ }
605
+ // @__NO_SIDE_EFFECTS__
606
+ function transform(operation) {
607
+ return {
608
+ kind: "transformation",
609
+ type: "transform",
610
+ reference: transform,
611
+ async: false,
612
+ operation,
613
+ "~run"(dataset) {
614
+ dataset.value = this.operation(dataset.value);
615
+ return dataset;
616
+ }
617
+ };
618
+ }
619
+ // @__NO_SIDE_EFFECTS__
620
+ function getFallback(schema, dataset, config2) {
621
+ return typeof schema.fallback === "function" ? (
622
+ // @ts-expect-error
623
+ schema.fallback(dataset, config2)
624
+ ) : (
625
+ // @ts-expect-error
626
+ schema.fallback
627
+ );
628
+ }
629
+ // @__NO_SIDE_EFFECTS__
630
+ function getDefault(schema, dataset, config2) {
631
+ return typeof schema.default === "function" ? (
632
+ // @ts-expect-error
633
+ schema.default(dataset, config2)
634
+ ) : (
635
+ // @ts-expect-error
636
+ schema.default
637
+ );
638
+ }
639
+ // @__NO_SIDE_EFFECTS__
640
+ function any() {
641
+ return {
642
+ kind: "schema",
643
+ type: "any",
644
+ reference: any,
645
+ expects: "any",
646
+ async: false,
647
+ get "~standard"() {
648
+ return /* @__PURE__ */ _getStandardProps(this);
649
+ },
650
+ "~run"(dataset) {
651
+ dataset.typed = true;
652
+ return dataset;
653
+ }
654
+ };
655
+ }
656
+ // @__NO_SIDE_EFFECTS__
657
+ function array(item, message) {
658
+ return {
659
+ kind: "schema",
660
+ type: "array",
661
+ reference: array,
662
+ expects: "Array",
663
+ async: false,
664
+ item,
665
+ message,
666
+ get "~standard"() {
667
+ return /* @__PURE__ */ _getStandardProps(this);
668
+ },
669
+ "~run"(dataset, config2) {
670
+ var _a;
671
+ const input = dataset.value;
672
+ if (Array.isArray(input)) {
673
+ dataset.typed = true;
674
+ dataset.value = [];
675
+ for (let key = 0; key < input.length; key++) {
676
+ const value2 = input[key];
677
+ const itemDataset = this.item["~run"]({ value: value2 }, config2);
678
+ if (itemDataset.issues) {
679
+ const pathItem = {
680
+ type: "array",
681
+ origin: "value",
682
+ input,
683
+ key,
684
+ value: value2
685
+ };
686
+ for (const issue of itemDataset.issues) {
687
+ if (issue.path) {
688
+ issue.path.unshift(pathItem);
689
+ } else {
690
+ issue.path = [pathItem];
691
+ }
692
+ (_a = dataset.issues) == null ? void 0 : _a.push(issue);
142
693
  }
143
- }
144
- }
145
- var value = getSnapshot();
146
- {
147
- if (!didWarnUncachedGetSnapshot) {
148
- var cachedValue = getSnapshot();
149
- if (!objectIs(value, cachedValue)) {
150
- error("The result of getSnapshot should be cached to avoid an infinite loop");
151
- didWarnUncachedGetSnapshot = true;
694
+ if (!dataset.issues) {
695
+ dataset.issues = itemDataset.issues;
696
+ }
697
+ if (config2.abortEarly) {
698
+ dataset.typed = false;
699
+ break;
152
700
  }
153
701
  }
154
- }
155
- var _useState = useState2({
156
- inst: {
157
- value,
158
- getSnapshot
159
- }
160
- }), inst = _useState[0].inst, forceUpdate = _useState[1];
161
- useLayoutEffect(function() {
162
- inst.value = value;
163
- inst.getSnapshot = getSnapshot;
164
- if (checkIfSnapshotChanged(inst)) {
165
- forceUpdate({
166
- inst
167
- });
168
- }
169
- }, [subscribe, value, getSnapshot]);
170
- useEffect2(function() {
171
- if (checkIfSnapshotChanged(inst)) {
172
- forceUpdate({
173
- inst
174
- });
702
+ if (!itemDataset.typed) {
703
+ dataset.typed = false;
175
704
  }
176
- var handleStoreChange = function() {
177
- if (checkIfSnapshotChanged(inst)) {
178
- forceUpdate({
179
- inst
180
- });
181
- }
182
- };
183
- return subscribe(handleStoreChange);
184
- }, [subscribe]);
185
- useDebugValue(value);
186
- return value;
187
- }
188
- function checkIfSnapshotChanged(inst) {
189
- var latestGetSnapshot = inst.getSnapshot;
190
- var prevValue = inst.value;
191
- try {
192
- var nextValue = latestGetSnapshot();
193
- return !objectIs(prevValue, nextValue);
194
- } catch (error2) {
195
- return true;
705
+ dataset.value.push(itemDataset.value);
196
706
  }
707
+ } else {
708
+ _addIssue(this, "type", dataset, config2);
197
709
  }
198
- function useSyncExternalStore$1(subscribe, getSnapshot, getServerSnapshot) {
199
- return getSnapshot();
200
- }
201
- var canUseDOM = !!(typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined");
202
- var isServerEnvironment = !canUseDOM;
203
- var shim2 = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore;
204
- var useSyncExternalStore$2 = React.useSyncExternalStore !== void 0 ? React.useSyncExternalStore : shim2;
205
- useSyncExternalStoreShim_development.useSyncExternalStore = useSyncExternalStore$2;
206
- if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop === "function") {
207
- __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
710
+ return dataset;
711
+ }
712
+ };
713
+ }
714
+ // @__NO_SIDE_EFFECTS__
715
+ function boolean(message) {
716
+ return {
717
+ kind: "schema",
718
+ type: "boolean",
719
+ reference: boolean,
720
+ expects: "boolean",
721
+ async: false,
722
+ message,
723
+ get "~standard"() {
724
+ return /* @__PURE__ */ _getStandardProps(this);
725
+ },
726
+ "~run"(dataset, config2) {
727
+ if (typeof dataset.value === "boolean") {
728
+ dataset.typed = true;
729
+ } else {
730
+ _addIssue(this, "type", dataset, config2);
208
731
  }
209
- })();
210
- }
211
- return useSyncExternalStoreShim_development;
732
+ return dataset;
733
+ }
734
+ };
212
735
  }
213
- var hasRequiredShim;
214
- function requireShim() {
215
- if (hasRequiredShim) return shim.exports;
216
- hasRequiredShim = 1;
217
- if (process.env.NODE_ENV === "production") {
218
- shim.exports = requireUseSyncExternalStoreShim_production_min();
219
- } else {
220
- shim.exports = requireUseSyncExternalStoreShim_development();
736
+ // @__NO_SIDE_EFFECTS__
737
+ function enum_(enum__, message) {
738
+ const options2 = [];
739
+ for (const key in enum__) {
740
+ if (`${+key}` !== key || typeof enum__[key] !== "string" || !Object.is(enum__[enum__[key]], +key)) {
741
+ options2.push(enum__[key]);
742
+ }
221
743
  }
222
- return shim.exports;
744
+ return {
745
+ kind: "schema",
746
+ type: "enum",
747
+ reference: enum_,
748
+ expects: /* @__PURE__ */ _joinExpects(options2.map(_stringify), "|"),
749
+ async: false,
750
+ enum: enum__,
751
+ options: options2,
752
+ message,
753
+ get "~standard"() {
754
+ return /* @__PURE__ */ _getStandardProps(this);
755
+ },
756
+ "~run"(dataset, config2) {
757
+ if (this.options.includes(dataset.value)) {
758
+ dataset.typed = true;
759
+ } else {
760
+ _addIssue(this, "type", dataset, config2);
761
+ }
762
+ return dataset;
763
+ }
764
+ };
223
765
  }
224
- var shimExports = requireShim();
225
- var withSelector = { exports: {} };
226
- var withSelector_production_min = {};
227
- /**
228
- * @license React
229
- * use-sync-external-store-shim/with-selector.production.min.js
230
- *
231
- * Copyright (c) Facebook, Inc. and its affiliates.
232
- *
233
- * This source code is licensed under the MIT license found in the
234
- * LICENSE file in the root directory of this source tree.
235
- */
236
- var hasRequiredWithSelector_production_min;
237
- function requireWithSelector_production_min() {
238
- if (hasRequiredWithSelector_production_min) return withSelector_production_min;
239
- hasRequiredWithSelector_production_min = 1;
240
- var h = require$$0, n = requireShim();
241
- function p(a, b) {
242
- return a === b && (0 !== a || 1 / a === 1 / b) || a !== a && b !== b;
243
- }
244
- var q = "function" === typeof Object.is ? Object.is : p, r = n.useSyncExternalStore, t = h.useRef, u = h.useEffect, v = h.useMemo, w = h.useDebugValue;
245
- withSelector_production_min.useSyncExternalStoreWithSelector = function(a, b, e, l, g) {
246
- var c = t(null);
247
- if (null === c.current) {
248
- var f = { hasValue: false, value: null };
249
- c.current = f;
250
- } else f = c.current;
251
- c = v(function() {
252
- function a2(a3) {
253
- if (!c2) {
254
- c2 = true;
255
- d2 = a3;
256
- a3 = l(a3);
257
- if (void 0 !== g && f.hasValue) {
258
- var b2 = f.value;
259
- if (g(b2, a3)) return k = b2;
260
- }
261
- return k = a3;
262
- }
263
- b2 = k;
264
- if (q(d2, a3)) return b2;
265
- var e2 = l(a3);
266
- if (void 0 !== g && g(b2, e2)) return b2;
267
- d2 = a3;
268
- return k = e2;
269
- }
270
- var c2 = false, d2, k, m = void 0 === e ? null : e;
271
- return [function() {
272
- return a2(b());
273
- }, null === m ? void 0 : function() {
274
- return a2(m());
275
- }];
276
- }, [b, e, l, g]);
277
- var d = r(a, c[0], c[1]);
278
- u(function() {
279
- f.hasValue = true;
280
- f.value = d;
281
- }, [d]);
282
- w(d);
283
- return d;
284
- };
285
- return withSelector_production_min;
766
+ // @__NO_SIDE_EFFECTS__
767
+ function literal(literal_, message) {
768
+ return {
769
+ kind: "schema",
770
+ type: "literal",
771
+ reference: literal,
772
+ expects: /* @__PURE__ */ _stringify(literal_),
773
+ async: false,
774
+ literal: literal_,
775
+ message,
776
+ get "~standard"() {
777
+ return /* @__PURE__ */ _getStandardProps(this);
778
+ },
779
+ "~run"(dataset, config2) {
780
+ if (dataset.value === this.literal) {
781
+ dataset.typed = true;
782
+ } else {
783
+ _addIssue(this, "type", dataset, config2);
784
+ }
785
+ return dataset;
786
+ }
787
+ };
286
788
  }
287
- var withSelector_development = {};
288
- /**
289
- * @license React
290
- * use-sync-external-store-shim/with-selector.development.js
291
- *
292
- * Copyright (c) Facebook, Inc. and its affiliates.
293
- *
294
- * This source code is licensed under the MIT license found in the
295
- * LICENSE file in the root directory of this source tree.
296
- */
297
- var hasRequiredWithSelector_development;
298
- function requireWithSelector_development() {
299
- if (hasRequiredWithSelector_development) return withSelector_development;
300
- hasRequiredWithSelector_development = 1;
301
- if (process.env.NODE_ENV !== "production") {
302
- (function() {
303
- if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === "function") {
304
- __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
305
- }
306
- var React = require$$0;
307
- var shim2 = requireShim();
308
- function is(x, y2) {
309
- return x === y2 && (x !== 0 || 1 / x === 1 / y2) || x !== x && y2 !== y2;
310
- }
311
- var objectIs = typeof Object.is === "function" ? Object.is : is;
312
- var useSyncExternalStore = shim2.useSyncExternalStore;
313
- var useRef2 = React.useRef, useEffect2 = React.useEffect, useMemo = React.useMemo, useDebugValue = React.useDebugValue;
314
- function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
315
- var instRef = useRef2(null);
316
- var inst;
317
- if (instRef.current === null) {
318
- inst = {
319
- hasValue: false,
320
- value: null
321
- };
322
- instRef.current = inst;
323
- } else {
324
- inst = instRef.current;
789
+ // @__NO_SIDE_EFFECTS__
790
+ function nullable(wrapped, default_) {
791
+ return {
792
+ kind: "schema",
793
+ type: "nullable",
794
+ reference: nullable,
795
+ expects: `(${wrapped.expects} | null)`,
796
+ async: false,
797
+ wrapped,
798
+ default: default_,
799
+ get "~standard"() {
800
+ return /* @__PURE__ */ _getStandardProps(this);
801
+ },
802
+ "~run"(dataset, config2) {
803
+ if (dataset.value === null) {
804
+ if (this.default !== void 0) {
805
+ dataset.value = /* @__PURE__ */ getDefault(this, dataset, config2);
325
806
  }
326
- var _useMemo = useMemo(function() {
327
- var hasMemo = false;
328
- var memoizedSnapshot;
329
- var memoizedSelection;
330
- var memoizedSelector = function(nextSnapshot) {
331
- if (!hasMemo) {
332
- hasMemo = true;
333
- memoizedSnapshot = nextSnapshot;
334
- var _nextSelection = selector(nextSnapshot);
335
- if (isEqual !== void 0) {
336
- if (inst.hasValue) {
337
- var currentSelection = inst.value;
338
- if (isEqual(currentSelection, _nextSelection)) {
339
- memoizedSelection = currentSelection;
340
- return currentSelection;
341
- }
807
+ if (dataset.value === null) {
808
+ dataset.typed = true;
809
+ return dataset;
810
+ }
811
+ }
812
+ return this.wrapped["~run"](dataset, config2);
813
+ }
814
+ };
815
+ }
816
+ // @__NO_SIDE_EFFECTS__
817
+ function number(message) {
818
+ return {
819
+ kind: "schema",
820
+ type: "number",
821
+ reference: number,
822
+ expects: "number",
823
+ async: false,
824
+ message,
825
+ get "~standard"() {
826
+ return /* @__PURE__ */ _getStandardProps(this);
827
+ },
828
+ "~run"(dataset, config2) {
829
+ if (typeof dataset.value === "number" && !isNaN(dataset.value)) {
830
+ dataset.typed = true;
831
+ } else {
832
+ _addIssue(this, "type", dataset, config2);
833
+ }
834
+ return dataset;
835
+ }
836
+ };
837
+ }
838
+ // @__NO_SIDE_EFFECTS__
839
+ function object(entries, message) {
840
+ return {
841
+ kind: "schema",
842
+ type: "object",
843
+ reference: object,
844
+ expects: "Object",
845
+ async: false,
846
+ entries,
847
+ message,
848
+ get "~standard"() {
849
+ return /* @__PURE__ */ _getStandardProps(this);
850
+ },
851
+ "~run"(dataset, config2) {
852
+ var _a;
853
+ const input = dataset.value;
854
+ if (input && typeof input === "object") {
855
+ dataset.typed = true;
856
+ dataset.value = {};
857
+ for (const key in this.entries) {
858
+ const valueSchema = this.entries[key];
859
+ if (key in input || (valueSchema.type === "exact_optional" || valueSchema.type === "optional" || valueSchema.type === "nullish") && // @ts-expect-error
860
+ valueSchema.default !== void 0) {
861
+ const value2 = key in input ? (
862
+ // @ts-expect-error
863
+ input[key]
864
+ ) : /* @__PURE__ */ getDefault(valueSchema);
865
+ const valueDataset = valueSchema["~run"]({ value: value2 }, config2);
866
+ if (valueDataset.issues) {
867
+ const pathItem = {
868
+ type: "object",
869
+ origin: "value",
870
+ input,
871
+ key,
872
+ value: value2
873
+ };
874
+ for (const issue of valueDataset.issues) {
875
+ if (issue.path) {
876
+ issue.path.unshift(pathItem);
877
+ } else {
878
+ issue.path = [pathItem];
342
879
  }
880
+ (_a = dataset.issues) == null ? void 0 : _a.push(issue);
881
+ }
882
+ if (!dataset.issues) {
883
+ dataset.issues = valueDataset.issues;
884
+ }
885
+ if (config2.abortEarly) {
886
+ dataset.typed = false;
887
+ break;
343
888
  }
344
- memoizedSelection = _nextSelection;
345
- return _nextSelection;
346
889
  }
347
- var prevSnapshot = memoizedSnapshot;
348
- var prevSelection = memoizedSelection;
349
- if (objectIs(prevSnapshot, nextSnapshot)) {
350
- return prevSelection;
890
+ if (!valueDataset.typed) {
891
+ dataset.typed = false;
351
892
  }
352
- var nextSelection = selector(nextSnapshot);
353
- if (isEqual !== void 0 && isEqual(prevSelection, nextSelection)) {
354
- return prevSelection;
893
+ dataset.value[key] = valueDataset.value;
894
+ } else if (valueSchema.fallback !== void 0) {
895
+ dataset.value[key] = /* @__PURE__ */ getFallback(valueSchema);
896
+ } else if (valueSchema.type !== "exact_optional" && valueSchema.type !== "optional" && valueSchema.type !== "nullish") {
897
+ _addIssue(this, "key", dataset, config2, {
898
+ input: void 0,
899
+ expected: `"${key}"`,
900
+ path: [
901
+ {
902
+ type: "object",
903
+ origin: "key",
904
+ input,
905
+ key,
906
+ // @ts-expect-error
907
+ value: input[key]
908
+ }
909
+ ]
910
+ });
911
+ if (config2.abortEarly) {
912
+ break;
355
913
  }
356
- memoizedSnapshot = nextSnapshot;
357
- memoizedSelection = nextSelection;
358
- return nextSelection;
359
- };
360
- var maybeGetServerSnapshot = getServerSnapshot === void 0 ? null : getServerSnapshot;
361
- var getSnapshotWithSelector = function() {
362
- return memoizedSelector(getSnapshot());
363
- };
364
- var getServerSnapshotWithSelector = maybeGetServerSnapshot === null ? void 0 : function() {
365
- return memoizedSelector(maybeGetServerSnapshot());
366
- };
367
- return [getSnapshotWithSelector, getServerSnapshotWithSelector];
368
- }, [getSnapshot, getServerSnapshot, selector, isEqual]), getSelection = _useMemo[0], getServerSelection = _useMemo[1];
369
- var value = useSyncExternalStore(subscribe, getSelection, getServerSelection);
370
- useEffect2(function() {
371
- inst.hasValue = true;
372
- inst.value = value;
373
- }, [value]);
374
- useDebugValue(value);
375
- return value;
914
+ }
915
+ }
916
+ } else {
917
+ _addIssue(this, "type", dataset, config2);
376
918
  }
377
- withSelector_development.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector;
378
- if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop === "function") {
379
- __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
919
+ return dataset;
920
+ }
921
+ };
922
+ }
923
+ // @__NO_SIDE_EFFECTS__
924
+ function optional(wrapped, default_) {
925
+ return {
926
+ kind: "schema",
927
+ type: "optional",
928
+ reference: optional,
929
+ expects: `(${wrapped.expects} | undefined)`,
930
+ async: false,
931
+ wrapped,
932
+ default: default_,
933
+ get "~standard"() {
934
+ return /* @__PURE__ */ _getStandardProps(this);
935
+ },
936
+ "~run"(dataset, config2) {
937
+ if (dataset.value === void 0) {
938
+ if (this.default !== void 0) {
939
+ dataset.value = /* @__PURE__ */ getDefault(this, dataset, config2);
940
+ }
941
+ if (dataset.value === void 0) {
942
+ dataset.typed = true;
943
+ return dataset;
944
+ }
380
945
  }
381
- })();
382
- }
383
- return withSelector_development;
946
+ return this.wrapped["~run"](dataset, config2);
947
+ }
948
+ };
384
949
  }
385
- var hasRequiredWithSelector;
386
- function requireWithSelector() {
387
- if (hasRequiredWithSelector) return withSelector.exports;
388
- hasRequiredWithSelector = 1;
389
- if (process.env.NODE_ENV === "production") {
390
- withSelector.exports = requireWithSelector_production_min();
391
- } else {
392
- withSelector.exports = requireWithSelector_development();
393
- }
394
- return withSelector.exports;
950
+ // @__NO_SIDE_EFFECTS__
951
+ function picklist(options2, message) {
952
+ return {
953
+ kind: "schema",
954
+ type: "picklist",
955
+ reference: picklist,
956
+ expects: /* @__PURE__ */ _joinExpects(options2.map(_stringify), "|"),
957
+ async: false,
958
+ options: options2,
959
+ message,
960
+ get "~standard"() {
961
+ return /* @__PURE__ */ _getStandardProps(this);
962
+ },
963
+ "~run"(dataset, config2) {
964
+ if (this.options.includes(dataset.value)) {
965
+ dataset.typed = true;
966
+ } else {
967
+ _addIssue(this, "type", dataset, config2);
968
+ }
969
+ return dataset;
970
+ }
971
+ };
395
972
  }
396
- requireWithSelector();
397
- var y = (t, e, n) => {
398
- var _a, _b;
399
- let r = useRef((_a = t == null ? void 0 : t.resolve) == null ? void 0 : _a.call(t, e, n)), s = ((_b = t == null ? void 0 : t.keyOfEntity) == null ? void 0 : _b.call(t, e)) ?? e, u = useCallback((o) => {
973
+ // @__NO_SIDE_EFFECTS__
974
+ function record(key, value2, message) {
975
+ return {
976
+ kind: "schema",
977
+ type: "record",
978
+ reference: record,
979
+ expects: "Object",
980
+ async: false,
981
+ key,
982
+ value: value2,
983
+ message,
984
+ get "~standard"() {
985
+ return /* @__PURE__ */ _getStandardProps(this);
986
+ },
987
+ "~run"(dataset, config2) {
988
+ var _a, _b;
989
+ const input = dataset.value;
990
+ if (input && typeof input === "object") {
991
+ dataset.typed = true;
992
+ dataset.value = {};
993
+ for (const entryKey in input) {
994
+ if (/* @__PURE__ */ _isValidObjectKey(input, entryKey)) {
995
+ const entryValue = input[entryKey];
996
+ const keyDataset = this.key["~run"]({ value: entryKey }, config2);
997
+ if (keyDataset.issues) {
998
+ const pathItem = {
999
+ type: "object",
1000
+ origin: "key",
1001
+ input,
1002
+ key: entryKey,
1003
+ value: entryValue
1004
+ };
1005
+ for (const issue of keyDataset.issues) {
1006
+ issue.path = [pathItem];
1007
+ (_a = dataset.issues) == null ? void 0 : _a.push(issue);
1008
+ }
1009
+ if (!dataset.issues) {
1010
+ dataset.issues = keyDataset.issues;
1011
+ }
1012
+ if (config2.abortEarly) {
1013
+ dataset.typed = false;
1014
+ break;
1015
+ }
1016
+ }
1017
+ const valueDataset = this.value["~run"](
1018
+ { value: entryValue },
1019
+ config2
1020
+ );
1021
+ if (valueDataset.issues) {
1022
+ const pathItem = {
1023
+ type: "object",
1024
+ origin: "value",
1025
+ input,
1026
+ key: entryKey,
1027
+ value: entryValue
1028
+ };
1029
+ for (const issue of valueDataset.issues) {
1030
+ if (issue.path) {
1031
+ issue.path.unshift(pathItem);
1032
+ } else {
1033
+ issue.path = [pathItem];
1034
+ }
1035
+ (_b = dataset.issues) == null ? void 0 : _b.push(issue);
1036
+ }
1037
+ if (!dataset.issues) {
1038
+ dataset.issues = valueDataset.issues;
1039
+ }
1040
+ if (config2.abortEarly) {
1041
+ dataset.typed = false;
1042
+ break;
1043
+ }
1044
+ }
1045
+ if (!keyDataset.typed || !valueDataset.typed) {
1046
+ dataset.typed = false;
1047
+ }
1048
+ if (keyDataset.typed) {
1049
+ dataset.value[keyDataset.value] = valueDataset.value;
1050
+ }
1051
+ }
1052
+ }
1053
+ } else {
1054
+ _addIssue(this, "type", dataset, config2);
1055
+ }
1056
+ return dataset;
1057
+ }
1058
+ };
1059
+ }
1060
+ // @__NO_SIDE_EFFECTS__
1061
+ function string(message) {
1062
+ return {
1063
+ kind: "schema",
1064
+ type: "string",
1065
+ reference: string,
1066
+ expects: "string",
1067
+ async: false,
1068
+ message,
1069
+ get "~standard"() {
1070
+ return /* @__PURE__ */ _getStandardProps(this);
1071
+ },
1072
+ "~run"(dataset, config2) {
1073
+ if (typeof dataset.value === "string") {
1074
+ dataset.typed = true;
1075
+ } else {
1076
+ _addIssue(this, "type", dataset, config2);
1077
+ }
1078
+ return dataset;
1079
+ }
1080
+ };
1081
+ }
1082
+ // @__NO_SIDE_EFFECTS__
1083
+ function _subIssues(datasets) {
1084
+ let issues;
1085
+ if (datasets) {
1086
+ for (const dataset of datasets) {
1087
+ if (issues) {
1088
+ issues.push(...dataset.issues);
1089
+ } else {
1090
+ issues = dataset.issues;
1091
+ }
1092
+ }
1093
+ }
1094
+ return issues;
1095
+ }
1096
+ // @__NO_SIDE_EFFECTS__
1097
+ function union(options2, message) {
1098
+ return {
1099
+ kind: "schema",
1100
+ type: "union",
1101
+ reference: union,
1102
+ expects: /* @__PURE__ */ _joinExpects(
1103
+ options2.map((option) => option.expects),
1104
+ "|"
1105
+ ),
1106
+ async: false,
1107
+ options: options2,
1108
+ message,
1109
+ get "~standard"() {
1110
+ return /* @__PURE__ */ _getStandardProps(this);
1111
+ },
1112
+ "~run"(dataset, config2) {
1113
+ let validDataset;
1114
+ let typedDatasets;
1115
+ let untypedDatasets;
1116
+ for (const schema of this.options) {
1117
+ const optionDataset = schema["~run"]({ value: dataset.value }, config2);
1118
+ if (optionDataset.typed) {
1119
+ if (optionDataset.issues) {
1120
+ if (typedDatasets) {
1121
+ typedDatasets.push(optionDataset);
1122
+ } else {
1123
+ typedDatasets = [optionDataset];
1124
+ }
1125
+ } else {
1126
+ validDataset = optionDataset;
1127
+ break;
1128
+ }
1129
+ } else {
1130
+ if (untypedDatasets) {
1131
+ untypedDatasets.push(optionDataset);
1132
+ } else {
1133
+ untypedDatasets = [optionDataset];
1134
+ }
1135
+ }
1136
+ }
1137
+ if (validDataset) {
1138
+ return validDataset;
1139
+ }
1140
+ if (typedDatasets) {
1141
+ if (typedDatasets.length === 1) {
1142
+ return typedDatasets[0];
1143
+ }
1144
+ _addIssue(this, "type", dataset, config2, {
1145
+ issues: /* @__PURE__ */ _subIssues(typedDatasets)
1146
+ });
1147
+ dataset.typed = true;
1148
+ } else if ((untypedDatasets == null ? void 0 : untypedDatasets.length) === 1) {
1149
+ return untypedDatasets[0];
1150
+ } else {
1151
+ _addIssue(this, "type", dataset, config2, {
1152
+ issues: /* @__PURE__ */ _subIssues(untypedDatasets)
1153
+ });
1154
+ }
1155
+ return dataset;
1156
+ }
1157
+ };
1158
+ }
1159
+ function parse(schema, input, config2) {
1160
+ const dataset = schema["~run"]({ value: input }, /* @__PURE__ */ getGlobalConfig(config2));
1161
+ if (dataset.issues) {
1162
+ throw new ValiError(dataset.issues);
1163
+ }
1164
+ return dataset.value;
1165
+ }
1166
+ // @__NO_SIDE_EFFECTS__
1167
+ function pipe(...pipe2) {
1168
+ return {
1169
+ ...pipe2[0],
1170
+ pipe: pipe2,
1171
+ get "~standard"() {
1172
+ return /* @__PURE__ */ _getStandardProps(this);
1173
+ },
1174
+ "~run"(dataset, config2) {
1175
+ for (const item of pipe2) {
1176
+ if (item.kind !== "metadata") {
1177
+ if (dataset.issues && (item.kind === "schema" || item.kind === "transformation")) {
1178
+ dataset.typed = false;
1179
+ break;
1180
+ }
1181
+ if (!dataset.issues || !config2.abortEarly && !config2.abortPipeEarly) {
1182
+ dataset = item["~run"](dataset, config2);
1183
+ }
1184
+ }
1185
+ }
1186
+ return dataset;
1187
+ }
1188
+ };
1189
+ }
1190
+ // @__NO_SIDE_EFFECTS__
1191
+ function safeParse(schema, input, config2) {
1192
+ const dataset = schema["~run"]({ value: input }, /* @__PURE__ */ getGlobalConfig(config2));
1193
+ return {
1194
+ typed: dataset.typed,
1195
+ success: !dataset.issues,
1196
+ output: dataset.value,
1197
+ issues: dataset.issues
1198
+ };
1199
+ }
1200
+ const linkValidator = /* @__PURE__ */ check(
1201
+ (value) => {
1202
+ var _a, _b;
1203
+ return !!value && ((_b = (_a = value == null ? void 0 : value.split) == null ? void 0 : _a.call(value, ":")) == null ? void 0 : _b.length) === 2;
1204
+ }
1205
+ );
1206
+ const isLink$1 = (value) => {
1207
+ var _a;
1208
+ return (_a = /* @__PURE__ */ safeParse(linkValidator, value)) == null ? void 0 : _a.success;
1209
+ };
1210
+ const isVariableLink$1 = (value) => {
1211
+ var _a, _b;
1212
+ return isLink$1(value) && ((_b = (_a = value == null ? void 0 : value.split) == null ? void 0 : _a.call(value, ":")) == null ? void 0 : _b.at(0)) === nodes.Variable;
1213
+ };
1214
+ const getMetadata = (schema) => {
1215
+ var _a;
1216
+ const pipelines = (schema == null ? void 0 : schema.pipe) ?? [];
1217
+ return ((_a = pipelines == null ? void 0 : pipelines.find((pipe2) => /* @__PURE__ */ isOfKind("metadata", pipe2))) == null ? void 0 : _a.metadata) ?? null;
1218
+ };
1219
+ const layerField = (schema, meta) => {
1220
+ const overridable = (meta == null ? void 0 : meta.overridable) ?? true;
1221
+ const variable = (meta == null ? void 0 : meta.variable) ?? false;
1222
+ const schemaParts = [schema];
1223
+ if (variable) {
1224
+ schemaParts.push(/* @__PURE__ */ pipe(/* @__PURE__ */ string(), linkValidator));
1225
+ }
1226
+ if (overridable) {
1227
+ schemaParts.push(/* @__PURE__ */ any());
1228
+ }
1229
+ return /* @__PURE__ */ pipe(
1230
+ /* @__PURE__ */ optional(/* @__PURE__ */ union(schemaParts)),
1231
+ /* @__PURE__ */ transform((meta == null ? void 0 : meta.transform) ?? ((v2) => v2)),
1232
+ /* @__PURE__ */ metadata(meta ?? {})
1233
+ );
1234
+ };
1235
+ const ChildrenSchema = /* @__PURE__ */ object({
1236
+ children: layerField(/* @__PURE__ */ array(/* @__PURE__ */ string()), {
1237
+ fallback: [],
1238
+ overridable: false
1239
+ })
1240
+ });
1241
+ const GraphFieldSchema = /* @__PURE__ */ object({
1242
+ _id: /* @__PURE__ */ union([/* @__PURE__ */ string(), /* @__PURE__ */ number()]),
1243
+ _type: /* @__PURE__ */ picklist(Object.keys(nodes))
1244
+ });
1245
+ const OverridesSchema = /* @__PURE__ */ object({
1246
+ overrides: layerField(/* @__PURE__ */ array(/* @__PURE__ */ string()), { overridable: false }),
1247
+ overrideFrom: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false })
1248
+ });
1249
+ const PositionSchema = /* @__PURE__ */ object({
1250
+ position: layerField(/* @__PURE__ */ enum_(Object.keys(positionType)), {
1251
+ fallback: positionType.absolute
1252
+ }),
1253
+ top: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ number()), {
1254
+ fallback: null,
1255
+ transform: (value) => typeof value === "number" ? Math.ceil(value) : value
1256
+ }),
1257
+ left: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ number()), {
1258
+ fallback: null,
1259
+ transform: (value) => typeof value === "number" ? Math.ceil(value) : value
1260
+ }),
1261
+ right: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ number()), {
1262
+ fallback: null,
1263
+ transform: (value) => typeof value === "number" ? Math.ceil(value) : value
1264
+ }),
1265
+ bottom: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ number()), {
1266
+ fallback: null,
1267
+ transform: (value) => typeof value === "number" ? Math.ceil(value) : value
1268
+ }),
1269
+ centerAnchorX: layerField(/* @__PURE__ */ number(), {
1270
+ fallback: 0.5
1271
+ }),
1272
+ centerAnchorY: layerField(/* @__PURE__ */ number(), {
1273
+ fallback: 0.5
1274
+ })
1275
+ });
1276
+ const SceneSchema = /* @__PURE__ */ object({
1277
+ opacity: layerField(/* @__PURE__ */ pipe(/* @__PURE__ */ number(), /* @__PURE__ */ minValue(0), /* @__PURE__ */ maxValue(1)), {
1278
+ fallback: 1,
1279
+ variable: true
1280
+ }),
1281
+ visible: layerField(/* @__PURE__ */ boolean(), { fallback: true, variable: true }),
1282
+ rotate: layerField(/* @__PURE__ */ number(), { fallback: null }),
1283
+ zIndex: layerField(/* @__PURE__ */ number(), { fallback: -1 })
1284
+ });
1285
+ const FillSchema = /* @__PURE__ */ object({
1286
+ fillType: layerField(/* @__PURE__ */ picklist(Object.keys(paintMode)), {
1287
+ fallback: paintMode.None
1288
+ }),
1289
+ solidFill: layerField(/* @__PURE__ */ string(), { fallback: "#fff" }),
1290
+ imageFill: layerField(/* @__PURE__ */ string()),
1291
+ imageSize: layerField(/* @__PURE__ */ picklist(Object.keys(imagePaintScaleModes)), {
1292
+ fallback: imagePaintScaleModes.Auto
1293
+ })
1294
+ });
1295
+ const BorderSchema = /* @__PURE__ */ object({
1296
+ borderType: layerField(/* @__PURE__ */ picklist(Object.keys(borderType)), {
1297
+ fallback: borderType.None
1298
+ }),
1299
+ borderWidth: layerField(/* @__PURE__ */ string(), {
1300
+ fallback: "1px",
1301
+ transform: (value) => {
1302
+ if (typeof value === "number") {
1303
+ return `${value}px`;
1304
+ }
1305
+ return value;
1306
+ }
1307
+ }),
1308
+ borderColor: layerField(/* @__PURE__ */ string(), { fallback: "#fff" })
1309
+ });
1310
+ const SizeSchema = /* @__PURE__ */ object({
1311
+ widthType: layerField(/* @__PURE__ */ picklist(Object.keys(sizing)), {
1312
+ fallback: sizing.Fixed
1313
+ }),
1314
+ heightType: layerField(/* @__PURE__ */ picklist(Object.keys(sizing)), {
1315
+ fallback: sizing.Fixed
1316
+ }),
1317
+ width: layerField(/* @__PURE__ */ pipe(/* @__PURE__ */ number(), /* @__PURE__ */ minValue(0)), {
1318
+ fallback: 0,
1319
+ transform: Math.ceil
1320
+ }),
1321
+ height: layerField(/* @__PURE__ */ pipe(/* @__PURE__ */ number(), /* @__PURE__ */ minValue(0)), {
1322
+ fallback: 0,
1323
+ transform: Math.ceil
1324
+ }),
1325
+ aspectRatio: layerField(/* @__PURE__ */ number(), { fallback: -1 }),
1326
+ minWidth: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ pipe(/* @__PURE__ */ number(), /* @__PURE__ */ minValue(-1))), {
1327
+ fallback: -1,
1328
+ transform: Math.ceil
1329
+ }),
1330
+ minWidthType: layerField(/* @__PURE__ */ picklist(Object.keys(sizing)), {
1331
+ fallback: sizing.Fixed
1332
+ }),
1333
+ maxWidth: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ pipe(/* @__PURE__ */ number(), /* @__PURE__ */ minValue(-1))), {
1334
+ fallback: -1,
1335
+ transform: Math.ceil
1336
+ }),
1337
+ maxWidthType: layerField(/* @__PURE__ */ picklist(Object.keys(sizing)), {
1338
+ fallback: sizing.Fixed
1339
+ }),
1340
+ minHeight: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ pipe(/* @__PURE__ */ number(), /* @__PURE__ */ minValue(-1))), {
1341
+ fallback: -1,
1342
+ transform: Math.ceil
1343
+ }),
1344
+ minHeightType: layerField(/* @__PURE__ */ picklist(Object.keys(sizing)), {
1345
+ fallback: sizing.Fixed
1346
+ }),
1347
+ maxHeight: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ pipe(/* @__PURE__ */ number(), /* @__PURE__ */ minValue(-1))), {
1348
+ fallback: -1,
1349
+ transform: Math.ceil
1350
+ }),
1351
+ maxHeightType: layerField(/* @__PURE__ */ picklist(Object.keys(sizing)), {
1352
+ fallback: sizing.Fixed
1353
+ })
1354
+ });
1355
+ const LayerSchema = /* @__PURE__ */ object({
1356
+ layerMode: layerField(/* @__PURE__ */ picklist(Object.keys(layerMode)), {
1357
+ fallback: layerMode.none
1358
+ }),
1359
+ layerAlign: layerField(/* @__PURE__ */ picklist(Object.keys(layerAlign)), {
1360
+ fallback: layerAlign.start
1361
+ }),
1362
+ layerDirection: layerField(/* @__PURE__ */ picklist(Object.keys(layerDirection)), {
1363
+ fallback: layerDirection.horizontal
1364
+ }),
1365
+ layerDistribute: layerField(/* @__PURE__ */ picklist(Object.keys(layerDistribute)), {
1366
+ fallback: layerDistribute.start
1367
+ }),
1368
+ layerWrap: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1369
+ layerGap: layerField(/* @__PURE__ */ pipe(/* @__PURE__ */ number(), /* @__PURE__ */ minValue(0)), { fallback: 0 }),
1370
+ padding: layerField(/* @__PURE__ */ string(), { fallback: "0px" })
1371
+ });
1372
+ const OverflowSchema = layerField(/* @__PURE__ */ picklist(Object.keys(overflow)), {
1373
+ fallback: overflow.hidden
1374
+ });
1375
+ const BorderRadiusSchema = layerField(/* @__PURE__ */ string(), { fallback: "0px" });
1376
+ const InteractionsSchema = /* @__PURE__ */ object({
1377
+ interactions: layerField(
1378
+ /* @__PURE__ */ array(
1379
+ /* @__PURE__ */ object({
1380
+ on: /* @__PURE__ */ enum_(Object.keys(interactions)),
1381
+ event: /* @__PURE__ */ nullable(linkValidator)
1382
+ })
1383
+ ),
1384
+ { fallback: [] }
1385
+ )
1386
+ });
1387
+ const CssOverrideSchema = /* @__PURE__ */ object({
1388
+ cssOverride: layerField(/* @__PURE__ */ string(), { fallback: "" })
1389
+ });
1390
+ const LinkSchema = /* @__PURE__ */ object({
1391
+ href: layerField(/* @__PURE__ */ string(), { fallback: null }),
1392
+ hrefNewTab: layerField(/* @__PURE__ */ boolean(), {
1393
+ fallback: true
1394
+ })
1395
+ // hrefTarget: layerField(v.picklist(Object.keys(linkTarget)), {
1396
+ // fallback: linkTarget._blank,
1397
+ // }),
1398
+ });
1399
+ const FrameSchema = /* @__PURE__ */ pipe(
1400
+ /* @__PURE__ */ object({
1401
+ name: layerField(/* @__PURE__ */ string(), { fallback: "Frame", overridable: false }),
1402
+ isBreakpoint: layerField(/* @__PURE__ */ boolean(), {
1403
+ fallback: false,
1404
+ overridable: false
1405
+ }),
1406
+ isPrimary: layerField(/* @__PURE__ */ boolean(), { fallback: false, overridable: false }),
1407
+ parent: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false }),
1408
+ ...ChildrenSchema.entries,
1409
+ ...GraphFieldSchema.entries,
1410
+ ...OverridesSchema.entries,
1411
+ ...PositionSchema.entries,
1412
+ ...SceneSchema.entries,
1413
+ ...FillSchema.entries,
1414
+ ...BorderSchema.entries,
1415
+ ...SizeSchema.entries,
1416
+ ...LayerSchema.entries,
1417
+ ...InteractionsSchema.entries,
1418
+ ...CssOverrideSchema.entries,
1419
+ ...LinkSchema.entries,
1420
+ overflow: OverflowSchema,
1421
+ borderRadius: BorderRadiusSchema
1422
+ })
1423
+ );
1424
+ const TextSchema = /* @__PURE__ */ object({
1425
+ name: layerField(/* @__PURE__ */ string(), { fallback: "Text", overridable: false }),
1426
+ content: layerField(/* @__PURE__ */ string(), {
1427
+ fallback: ""
1428
+ }),
1429
+ whiteSpace: layerField(/* @__PURE__ */ enum_(Object.keys(whiteSpace)), {
1430
+ fallback: whiteSpace.pre
1431
+ }),
1432
+ textAlign: layerField(/* @__PURE__ */ string(), { fallback: "left" }),
1433
+ parent: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false }),
1434
+ ...GraphFieldSchema.entries,
1435
+ ...OverridesSchema.entries,
1436
+ ...CssOverrideSchema.entries,
1437
+ ...PositionSchema.entries,
1438
+ ...SceneSchema.entries,
1439
+ ...SizeSchema.entries,
1440
+ ...InteractionsSchema.entries,
1441
+ ...LinkSchema.entries
1442
+ });
1443
+ const FragmentSchema = /* @__PURE__ */ object({
1444
+ name: layerField(/* @__PURE__ */ string(), { fallback: "Fragment", overridable: false }),
1445
+ parent: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false }),
1446
+ horizontalGrow: layerField(/* @__PURE__ */ enum_(Object.keys(fragmentGrowingMode)), {
1447
+ fallback: fragmentGrowingMode.fill,
1448
+ overridable: false
1449
+ }),
1450
+ verticalGrow: layerField(/* @__PURE__ */ enum_(Object.keys(fragmentGrowingMode)), {
1451
+ fallback: fragmentGrowingMode.auto,
1452
+ overridable: false
1453
+ }),
1454
+ properties: layerField(/* @__PURE__ */ array(/* @__PURE__ */ string()), {
1455
+ fallback: [],
1456
+ overridable: false
1457
+ }),
1458
+ ...GraphFieldSchema.entries,
1459
+ ...ChildrenSchema.entries
1460
+ });
1461
+ const InstanceSchema = /* @__PURE__ */ object({
1462
+ name: layerField(/* @__PURE__ */ string(), { fallback: "Instance", overridable: false }),
1463
+ fragment: layerField(/* @__PURE__ */ number()),
1464
+ parent: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false }),
1465
+ props: layerField(
1466
+ /* @__PURE__ */ record(
1467
+ /* @__PURE__ */ string(),
1468
+ /* @__PURE__ */ union([
1469
+ /* @__PURE__ */ string(),
1470
+ /* @__PURE__ */ number(),
1471
+ /* @__PURE__ */ boolean(),
1472
+ // For goals
1473
+ /* @__PURE__ */ object({
1474
+ code: /* @__PURE__ */ string(),
1475
+ name: /* @__PURE__ */ string()
1476
+ })
1477
+ ])
1478
+ ),
1479
+ {
1480
+ fallback: {}
1481
+ }
1482
+ ),
1483
+ ...GraphFieldSchema.entries,
1484
+ ...OverridesSchema.entries,
1485
+ ...PositionSchema.entries,
1486
+ ...SizeSchema.entries,
1487
+ ...SceneSchema.entries,
1488
+ ...InteractionsSchema.entries,
1489
+ ...LinkSchema.entries
1490
+ });
1491
+ const NumberVariableSchema = /* @__PURE__ */ object({
1492
+ nodePropertyControlReference: layerField(/* @__PURE__ */ string(), { fallback: null }),
1493
+ name: layerField(/* @__PURE__ */ string(), {
1494
+ fallback: "Number",
1495
+ overridable: false
1496
+ }),
1497
+ parent: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false }),
1498
+ type: layerField(/* @__PURE__ */ literal(variableType.Number), {
1499
+ fallback: variableType.Number
1500
+ }),
1501
+ defaultValue: layerField(/* @__PURE__ */ number(), { fallback: 0 }),
1502
+ required: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1503
+ min: layerField(/* @__PURE__ */ number(), { fallback: 1 }),
1504
+ max: layerField(/* @__PURE__ */ number(), { fallback: 100 }),
1505
+ step: layerField(/* @__PURE__ */ number(), { fallback: 1 }),
1506
+ displayStepper: layerField(/* @__PURE__ */ boolean(), { fallback: true }),
1507
+ ...GraphFieldSchema.entries
1508
+ });
1509
+ const BooleanVariableSchema = /* @__PURE__ */ object({
1510
+ nodePropertyControlReference: layerField(/* @__PURE__ */ string(), { fallback: null }),
1511
+ name: layerField(/* @__PURE__ */ string(), {
1512
+ fallback: "Boolean",
1513
+ overridable: false
1514
+ }),
1515
+ parent: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false }),
1516
+ type: layerField(/* @__PURE__ */ literal(variableType.Boolean), {
1517
+ fallback: variableType.Boolean
1518
+ }),
1519
+ defaultValue: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1520
+ required: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1521
+ ...GraphFieldSchema.entries
1522
+ });
1523
+ const ColorVariableSchema = /* @__PURE__ */ object({
1524
+ nodePropertyControlReference: layerField(/* @__PURE__ */ string(), { fallback: null }),
1525
+ name: layerField(/* @__PURE__ */ string(), {
1526
+ fallback: "String",
1527
+ overridable: false
1528
+ }),
1529
+ parent: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false }),
1530
+ type: layerField(/* @__PURE__ */ literal(variableType.Color), {
1531
+ fallback: variableType.Color
1532
+ }),
1533
+ // TODO Add color validator
1534
+ defaultValue: layerField(/* @__PURE__ */ string(), { fallback: "#000" }),
1535
+ required: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1536
+ ...GraphFieldSchema.entries
1537
+ });
1538
+ const StringVariableSchema = /* @__PURE__ */ object({
1539
+ nodePropertyControlReference: layerField(/* @__PURE__ */ string(), { fallback: null }),
1540
+ name: layerField(/* @__PURE__ */ string(), {
1541
+ fallback: "String",
1542
+ overridable: false
1543
+ }),
1544
+ type: layerField(/* @__PURE__ */ literal(variableType.String), {
1545
+ fallback: variableType.String
1546
+ }),
1547
+ parent: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false }),
1548
+ defaultValue: layerField(/* @__PURE__ */ string(), { fallback: "" }),
1549
+ required: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1550
+ placeholder: layerField(/* @__PURE__ */ string(), { fallback: "" }),
1551
+ isTextarea: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1552
+ ...GraphFieldSchema.entries
1553
+ });
1554
+ const EventVariableSchema = /* @__PURE__ */ object({
1555
+ nodePropertyControlReference: layerField(/* @__PURE__ */ string(), { fallback: null }),
1556
+ name: layerField(/* @__PURE__ */ string(), {
1557
+ fallback: "Event",
1558
+ overridable: false
1559
+ }),
1560
+ parent: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false }),
1561
+ type: layerField(/* @__PURE__ */ literal(variableType.Event), {
1562
+ fallback: variableType.Event
1563
+ }),
1564
+ mode: layerField(/* @__PURE__ */ picklist(Object.keys(eventMode)), {
1565
+ fallback: eventMode.callback
1566
+ }),
1567
+ defaultValue: layerField(/* @__PURE__ */ any()),
1568
+ required: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1569
+ ...GraphFieldSchema.entries
1570
+ });
1571
+ const LinkVariableSchema = /* @__PURE__ */ object({
1572
+ nodePropertyControlReference: layerField(/* @__PURE__ */ string(), { fallback: null }),
1573
+ name: layerField(/* @__PURE__ */ string(), {
1574
+ fallback: "Link",
1575
+ overridable: false
1576
+ }),
1577
+ parent: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false }),
1578
+ type: layerField(/* @__PURE__ */ literal(variableType.Link), {
1579
+ fallback: variableType.Link
1580
+ }),
1581
+ defaultValue: layerField(/* @__PURE__ */ string(), { fallback: "" }),
1582
+ required: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1583
+ ...GraphFieldSchema.entries
1584
+ });
1585
+ const EnumVariableSchema = /* @__PURE__ */ object({
1586
+ nodePropertyControlReference: layerField(/* @__PURE__ */ string(), { fallback: null }),
1587
+ name: layerField(/* @__PURE__ */ string(), {
1588
+ fallback: "Option",
1589
+ overridable: false
1590
+ }),
1591
+ parent: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false }),
1592
+ type: layerField(/* @__PURE__ */ literal(variableType.Enum), {
1593
+ fallback: variableType.Enum
1594
+ }),
1595
+ defaultValue: layerField(/* @__PURE__ */ string(), { fallback: "" }),
1596
+ required: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1597
+ cases: layerField(
1598
+ /* @__PURE__ */ array(
1599
+ /* @__PURE__ */ object({
1600
+ id: /* @__PURE__ */ string(),
1601
+ name: /* @__PURE__ */ string()
1602
+ })
1603
+ ),
1604
+ { fallback: [] }
1605
+ ),
1606
+ ...GraphFieldSchema.entries
1607
+ });
1608
+ const ObjectVariableSchema = /* @__PURE__ */ object({
1609
+ nodePropertyControlReference: layerField(/* @__PURE__ */ string(), { fallback: null }),
1610
+ name: layerField(/* @__PURE__ */ string(), {
1611
+ fallback: "Object",
1612
+ overridable: false
1613
+ }),
1614
+ type: layerField(/* @__PURE__ */ literal(variableType.Object), {
1615
+ fallback: variableType.Object
1616
+ }),
1617
+ parent: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false }),
1618
+ defaultValue: layerField(/* @__PURE__ */ object({}), { fallback: {} }),
1619
+ fields: layerField(/* @__PURE__ */ record(/* @__PURE__ */ string(), linkValidator), { fallback: {} }),
1620
+ required: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1621
+ ...GraphFieldSchema.entries
1622
+ });
1623
+ const ImageVariableSchema = /* @__PURE__ */ object({
1624
+ nodePropertyControlReference: layerField(/* @__PURE__ */ string(), { fallback: null }),
1625
+ name: layerField(/* @__PURE__ */ string(), {
1626
+ fallback: "Image",
1627
+ overridable: false
1628
+ }),
1629
+ type: layerField(/* @__PURE__ */ literal(variableType.Image), {
1630
+ fallback: variableType.Image
1631
+ }),
1632
+ parent: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false }),
1633
+ defaultValue: layerField(/* @__PURE__ */ string(), { fallback: null }),
1634
+ required: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1635
+ imageSize: layerField(/* @__PURE__ */ picklist(Object.keys(imagePaintScaleModes)), {
1636
+ fallback: imagePaintScaleModes.Auto
1637
+ }),
1638
+ ...GraphFieldSchema.entries
1639
+ });
1640
+ const CollectionSchema = /* @__PURE__ */ pipe(
1641
+ /* @__PURE__ */ object({
1642
+ name: layerField(/* @__PURE__ */ string(), {
1643
+ fallback: "Collection",
1644
+ overridable: false
1645
+ }),
1646
+ parent: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false }),
1647
+ source: layerField(linkValidator, {}),
1648
+ ...ChildrenSchema.entries,
1649
+ ...GraphFieldSchema.entries,
1650
+ ...OverridesSchema.entries,
1651
+ ...PositionSchema.entries,
1652
+ ...SceneSchema.entries,
1653
+ ...FillSchema.entries,
1654
+ ...BorderSchema.entries,
1655
+ ...SizeSchema.entries,
1656
+ ...LayerSchema.entries,
1657
+ ...InteractionsSchema.entries,
1658
+ ...CssOverrideSchema.entries,
1659
+ ...LinkSchema.entries
1660
+ })
1661
+ );
1662
+ const ArrayVariableSchema = /* @__PURE__ */ object({
1663
+ nodePropertyControlReference: layerField(/* @__PURE__ */ string(), { fallback: null }),
1664
+ name: layerField(/* @__PURE__ */ string(), {
1665
+ fallback: "Collection",
1666
+ overridable: false
1667
+ }),
1668
+ type: layerField(/* @__PURE__ */ literal(variableType.Array), {
1669
+ fallback: variableType.Array
1670
+ }),
1671
+ parent: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false }),
1672
+ defaultValue: layerField(/* @__PURE__ */ array(/* @__PURE__ */ any()), { fallback: [] }),
1673
+ definition: layerField(linkValidator, { fallback: null }),
1674
+ required: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1675
+ ...GraphFieldSchema.entries
1676
+ });
1677
+ const getLayerSchema = (layer) => {
1678
+ if (!(layer == null ? void 0 : layer._type)) return null;
1679
+ if ((layer == null ? void 0 : layer._type) === nodes.Frame) return FrameSchema;
1680
+ if ((layer == null ? void 0 : layer._type) === nodes.Text) return TextSchema;
1681
+ if ((layer == null ? void 0 : layer._type) === nodes.Fragment) return FragmentSchema;
1682
+ if ((layer == null ? void 0 : layer._type) === nodes.Instance) return InstanceSchema;
1683
+ if ((layer == null ? void 0 : layer._type) === nodes.Collection) return CollectionSchema;
1684
+ if (layer._type === nodes.Variable) {
1685
+ const types = {
1686
+ [variableType.Number]: NumberVariableSchema,
1687
+ [variableType.Boolean]: BooleanVariableSchema,
1688
+ [variableType.String]: StringVariableSchema,
1689
+ [variableType.Color]: ColorVariableSchema,
1690
+ [variableType.Event]: EventVariableSchema,
1691
+ [variableType.Link]: LinkVariableSchema,
1692
+ [variableType.Enum]: EnumVariableSchema,
1693
+ [variableType.Object]: ObjectVariableSchema,
1694
+ [variableType.Image]: ImageVariableSchema,
1695
+ [variableType.Array]: ArrayVariableSchema
1696
+ };
1697
+ if (layer.type in types) {
1698
+ return types[layer.type];
1699
+ }
1700
+ }
1701
+ };
1702
+ const isObject$1 = (x2) => !!x2 && typeof x2 === "object" && !Array.isArray(x2);
1703
+ const normalizeLayer = (schema, rawLayer, options2) => {
1704
+ try {
1705
+ if (!rawLayer || !schema.entries) return null;
1706
+ const withFallback = (options2 == null ? void 0 : options2.withFallback) ?? true;
1707
+ const overrideTarget = options2 == null ? void 0 : options2.overrideTarget;
1708
+ const parsedLayer = parse(schema, rawLayer);
1709
+ return Object.fromEntries(
1710
+ Object.entries(schema.entries).map(([key, schemaEntity]) => {
1711
+ const schemaMeta = getMetadata(schemaEntity);
1712
+ const fallback = withFallback ? schemaMeta == null ? void 0 : schemaMeta.fallback : null;
1713
+ const overrideValue = (schemaMeta == null ? void 0 : schemaMeta.overridable) !== false && overrideTarget ? overrideTarget == null ? void 0 : overrideTarget[key] : null;
1714
+ let layerValue = parsedLayer[key];
1715
+ if (isObject$1(layerValue) && isObject$1(overrideValue)) {
1716
+ layerValue = { ...overrideValue, ...layerValue };
1717
+ }
1718
+ if (schemaEntity && "wrapped" in schemaEntity && "entries" in schemaEntity.wrapped && isObject$1(schemaEntity.wrapped.entries)) {
1719
+ layerValue = normalizeLayer(
1720
+ schemaEntity.wrapped,
1721
+ layerValue,
1722
+ options2
1723
+ );
1724
+ }
1725
+ const resultValue = layerValue ?? overrideValue ?? fallback;
1726
+ return [key, resultValue];
1727
+ })
1728
+ );
1729
+ } catch (e2) {
1730
+ console.error(e2);
1731
+ return null;
1732
+ }
1733
+ };
1734
+ const getNormalizeLayer$1 = (layer, overrider, withFallback) => {
1735
+ if (!layer) return null;
1736
+ const schema = getLayerSchema(layer);
1737
+ if (!schema) return null;
1738
+ return normalizeLayer(schema, layer, {
1739
+ overrideTarget: overrider,
1740
+ withFallback
1741
+ });
1742
+ };
1743
+ function findSchemaByPath(schema, path) {
1744
+ if (!path) return void 0;
1745
+ const parts = path.split(".");
1746
+ let current = schema;
1747
+ for (const part of parts) {
1748
+ if (!current || typeof current !== "object") return void 0;
1749
+ if ("entries" in current) {
1750
+ if (!(part in current.entries)) return void 0;
1751
+ current = current.entries[part];
1752
+ } else if ("wrapped" in current && "entries" in current.wrapped) {
1753
+ current = current.wrapped.entries[part];
1754
+ }
1755
+ }
1756
+ return current;
1757
+ }
1758
+ const parseLayerField = (layer, field, value) => {
1759
+ const schema = getLayerSchema(layer);
1760
+ const fieldSchema = findSchemaByPath(schema, field);
1761
+ if (fieldSchema) {
1762
+ return /* @__PURE__ */ safeParse(fieldSchema, value);
1763
+ }
1764
+ return { success: false, output: value };
1765
+ };
1766
+ const RenderTargetContext = createContext(
1767
+ index.renderTarget.document
1768
+ );
1769
+ const RenderTargetProvider = RenderTargetContext.Provider;
1770
+ const useRenderTarget = () => {
1771
+ const renderTarget2 = useContext(RenderTargetContext);
1772
+ return {
1773
+ renderTarget: renderTarget2,
1774
+ isCanvas: renderTarget2 === index.renderTarget.canvas,
1775
+ isDocument: renderTarget2 === index.renderTarget.document
1776
+ };
1777
+ };
1778
+ var withSelector = { exports: {} };
1779
+ var withSelector_production = {};
1780
+ var shim = { exports: {} };
1781
+ var useSyncExternalStoreShim_production = {};
1782
+ /**
1783
+ * @license React
1784
+ * use-sync-external-store-shim.production.js
1785
+ *
1786
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
1787
+ *
1788
+ * This source code is licensed under the MIT license found in the
1789
+ * LICENSE file in the root directory of this source tree.
1790
+ */
1791
+ var hasRequiredUseSyncExternalStoreShim_production;
1792
+ function requireUseSyncExternalStoreShim_production() {
1793
+ if (hasRequiredUseSyncExternalStoreShim_production) return useSyncExternalStoreShim_production;
1794
+ hasRequiredUseSyncExternalStoreShim_production = 1;
1795
+ var React = require$$0;
1796
+ function is(x2, y2) {
1797
+ return x2 === y2 && (0 !== x2 || 1 / x2 === 1 / y2) || x2 !== x2 && y2 !== y2;
1798
+ }
1799
+ var objectIs = "function" === typeof Object.is ? Object.is : is, useState2 = React.useState, useEffect2 = React.useEffect, useLayoutEffect = React.useLayoutEffect, useDebugValue = React.useDebugValue;
1800
+ function useSyncExternalStore$2(subscribe, getSnapshot) {
1801
+ var value = getSnapshot(), _useState = useState2({ inst: { value, getSnapshot } }), inst = _useState[0].inst, forceUpdate = _useState[1];
1802
+ useLayoutEffect(
1803
+ function() {
1804
+ inst.value = value;
1805
+ inst.getSnapshot = getSnapshot;
1806
+ checkIfSnapshotChanged(inst) && forceUpdate({ inst });
1807
+ },
1808
+ [subscribe, value, getSnapshot]
1809
+ );
1810
+ useEffect2(
1811
+ function() {
1812
+ checkIfSnapshotChanged(inst) && forceUpdate({ inst });
1813
+ return subscribe(function() {
1814
+ checkIfSnapshotChanged(inst) && forceUpdate({ inst });
1815
+ });
1816
+ },
1817
+ [subscribe]
1818
+ );
1819
+ useDebugValue(value);
1820
+ return value;
1821
+ }
1822
+ function checkIfSnapshotChanged(inst) {
1823
+ var latestGetSnapshot = inst.getSnapshot;
1824
+ inst = inst.value;
1825
+ try {
1826
+ var nextValue = latestGetSnapshot();
1827
+ return !objectIs(inst, nextValue);
1828
+ } catch (error) {
1829
+ return true;
1830
+ }
1831
+ }
1832
+ function useSyncExternalStore$1(subscribe, getSnapshot) {
1833
+ return getSnapshot();
1834
+ }
1835
+ var shim2 = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? useSyncExternalStore$1 : useSyncExternalStore$2;
1836
+ useSyncExternalStoreShim_production.useSyncExternalStore = void 0 !== React.useSyncExternalStore ? React.useSyncExternalStore : shim2;
1837
+ return useSyncExternalStoreShim_production;
1838
+ }
1839
+ var useSyncExternalStoreShim_development = {};
1840
+ /**
1841
+ * @license React
1842
+ * use-sync-external-store-shim.development.js
1843
+ *
1844
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
1845
+ *
1846
+ * This source code is licensed under the MIT license found in the
1847
+ * LICENSE file in the root directory of this source tree.
1848
+ */
1849
+ var hasRequiredUseSyncExternalStoreShim_development;
1850
+ function requireUseSyncExternalStoreShim_development() {
1851
+ if (hasRequiredUseSyncExternalStoreShim_development) return useSyncExternalStoreShim_development;
1852
+ hasRequiredUseSyncExternalStoreShim_development = 1;
1853
+ "production" !== process.env.NODE_ENV && function() {
1854
+ function is(x2, y2) {
1855
+ return x2 === y2 && (0 !== x2 || 1 / x2 === 1 / y2) || x2 !== x2 && y2 !== y2;
1856
+ }
1857
+ function useSyncExternalStore$2(subscribe, getSnapshot) {
1858
+ didWarnOld18Alpha || void 0 === React.startTransition || (didWarnOld18Alpha = true, console.error(
1859
+ "You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."
1860
+ ));
1861
+ var value = getSnapshot();
1862
+ if (!didWarnUncachedGetSnapshot) {
1863
+ var cachedValue = getSnapshot();
1864
+ objectIs(value, cachedValue) || (console.error(
1865
+ "The result of getSnapshot should be cached to avoid an infinite loop"
1866
+ ), didWarnUncachedGetSnapshot = true);
1867
+ }
1868
+ cachedValue = useState2({
1869
+ inst: { value, getSnapshot }
1870
+ });
1871
+ var inst = cachedValue[0].inst, forceUpdate = cachedValue[1];
1872
+ useLayoutEffect(
1873
+ function() {
1874
+ inst.value = value;
1875
+ inst.getSnapshot = getSnapshot;
1876
+ checkIfSnapshotChanged(inst) && forceUpdate({ inst });
1877
+ },
1878
+ [subscribe, value, getSnapshot]
1879
+ );
1880
+ useEffect2(
1881
+ function() {
1882
+ checkIfSnapshotChanged(inst) && forceUpdate({ inst });
1883
+ return subscribe(function() {
1884
+ checkIfSnapshotChanged(inst) && forceUpdate({ inst });
1885
+ });
1886
+ },
1887
+ [subscribe]
1888
+ );
1889
+ useDebugValue(value);
1890
+ return value;
1891
+ }
1892
+ function checkIfSnapshotChanged(inst) {
1893
+ var latestGetSnapshot = inst.getSnapshot;
1894
+ inst = inst.value;
1895
+ try {
1896
+ var nextValue = latestGetSnapshot();
1897
+ return !objectIs(inst, nextValue);
1898
+ } catch (error) {
1899
+ return true;
1900
+ }
1901
+ }
1902
+ function useSyncExternalStore$1(subscribe, getSnapshot) {
1903
+ return getSnapshot();
1904
+ }
1905
+ "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
1906
+ var React = require$$0, objectIs = "function" === typeof Object.is ? Object.is : is, useState2 = React.useState, useEffect2 = React.useEffect, useLayoutEffect = React.useLayoutEffect, useDebugValue = React.useDebugValue, didWarnOld18Alpha = false, didWarnUncachedGetSnapshot = false, shim2 = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? useSyncExternalStore$1 : useSyncExternalStore$2;
1907
+ useSyncExternalStoreShim_development.useSyncExternalStore = void 0 !== React.useSyncExternalStore ? React.useSyncExternalStore : shim2;
1908
+ "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
1909
+ }();
1910
+ return useSyncExternalStoreShim_development;
1911
+ }
1912
+ var hasRequiredShim;
1913
+ function requireShim() {
1914
+ if (hasRequiredShim) return shim.exports;
1915
+ hasRequiredShim = 1;
1916
+ if (process.env.NODE_ENV === "production") {
1917
+ shim.exports = requireUseSyncExternalStoreShim_production();
1918
+ } else {
1919
+ shim.exports = requireUseSyncExternalStoreShim_development();
1920
+ }
1921
+ return shim.exports;
1922
+ }
1923
+ /**
1924
+ * @license React
1925
+ * use-sync-external-store-shim/with-selector.production.js
1926
+ *
1927
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
1928
+ *
1929
+ * This source code is licensed under the MIT license found in the
1930
+ * LICENSE file in the root directory of this source tree.
1931
+ */
1932
+ var hasRequiredWithSelector_production;
1933
+ function requireWithSelector_production() {
1934
+ if (hasRequiredWithSelector_production) return withSelector_production;
1935
+ hasRequiredWithSelector_production = 1;
1936
+ var React = require$$0, shim2 = requireShim();
1937
+ function is(x2, y2) {
1938
+ return x2 === y2 && (0 !== x2 || 1 / x2 === 1 / y2) || x2 !== x2 && y2 !== y2;
1939
+ }
1940
+ var objectIs = "function" === typeof Object.is ? Object.is : is, useSyncExternalStore = shim2.useSyncExternalStore, useRef2 = React.useRef, useEffect2 = React.useEffect, useMemo2 = React.useMemo, useDebugValue = React.useDebugValue;
1941
+ withSelector_production.useSyncExternalStoreWithSelector = function(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
1942
+ var instRef = useRef2(null);
1943
+ if (null === instRef.current) {
1944
+ var inst = { hasValue: false, value: null };
1945
+ instRef.current = inst;
1946
+ } else inst = instRef.current;
1947
+ instRef = useMemo2(
1948
+ function() {
1949
+ function memoizedSelector(nextSnapshot) {
1950
+ if (!hasMemo) {
1951
+ hasMemo = true;
1952
+ memoizedSnapshot = nextSnapshot;
1953
+ nextSnapshot = selector(nextSnapshot);
1954
+ if (void 0 !== isEqual && inst.hasValue) {
1955
+ var currentSelection = inst.value;
1956
+ if (isEqual(currentSelection, nextSnapshot))
1957
+ return memoizedSelection = currentSelection;
1958
+ }
1959
+ return memoizedSelection = nextSnapshot;
1960
+ }
1961
+ currentSelection = memoizedSelection;
1962
+ if (objectIs(memoizedSnapshot, nextSnapshot)) return currentSelection;
1963
+ var nextSelection = selector(nextSnapshot);
1964
+ if (void 0 !== isEqual && isEqual(currentSelection, nextSelection))
1965
+ return memoizedSnapshot = nextSnapshot, currentSelection;
1966
+ memoizedSnapshot = nextSnapshot;
1967
+ return memoizedSelection = nextSelection;
1968
+ }
1969
+ var hasMemo = false, memoizedSnapshot, memoizedSelection, maybeGetServerSnapshot = void 0 === getServerSnapshot ? null : getServerSnapshot;
1970
+ return [
1971
+ function() {
1972
+ return memoizedSelector(getSnapshot());
1973
+ },
1974
+ null === maybeGetServerSnapshot ? void 0 : function() {
1975
+ return memoizedSelector(maybeGetServerSnapshot());
1976
+ }
1977
+ ];
1978
+ },
1979
+ [getSnapshot, getServerSnapshot, selector, isEqual]
1980
+ );
1981
+ var value = useSyncExternalStore(subscribe, instRef[0], instRef[1]);
1982
+ useEffect2(
1983
+ function() {
1984
+ inst.hasValue = true;
1985
+ inst.value = value;
1986
+ },
1987
+ [value]
1988
+ );
1989
+ useDebugValue(value);
1990
+ return value;
1991
+ };
1992
+ return withSelector_production;
1993
+ }
1994
+ var withSelector_development = {};
1995
+ /**
1996
+ * @license React
1997
+ * use-sync-external-store-shim/with-selector.development.js
1998
+ *
1999
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
2000
+ *
2001
+ * This source code is licensed under the MIT license found in the
2002
+ * LICENSE file in the root directory of this source tree.
2003
+ */
2004
+ var hasRequiredWithSelector_development;
2005
+ function requireWithSelector_development() {
2006
+ if (hasRequiredWithSelector_development) return withSelector_development;
2007
+ hasRequiredWithSelector_development = 1;
2008
+ "production" !== process.env.NODE_ENV && function() {
2009
+ function is(x2, y2) {
2010
+ return x2 === y2 && (0 !== x2 || 1 / x2 === 1 / y2) || x2 !== x2 && y2 !== y2;
2011
+ }
2012
+ "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
2013
+ var React = require$$0, shim2 = requireShim(), objectIs = "function" === typeof Object.is ? Object.is : is, useSyncExternalStore = shim2.useSyncExternalStore, useRef2 = React.useRef, useEffect2 = React.useEffect, useMemo2 = React.useMemo, useDebugValue = React.useDebugValue;
2014
+ withSelector_development.useSyncExternalStoreWithSelector = function(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
2015
+ var instRef = useRef2(null);
2016
+ if (null === instRef.current) {
2017
+ var inst = { hasValue: false, value: null };
2018
+ instRef.current = inst;
2019
+ } else inst = instRef.current;
2020
+ instRef = useMemo2(
2021
+ function() {
2022
+ function memoizedSelector(nextSnapshot) {
2023
+ if (!hasMemo) {
2024
+ hasMemo = true;
2025
+ memoizedSnapshot = nextSnapshot;
2026
+ nextSnapshot = selector(nextSnapshot);
2027
+ if (void 0 !== isEqual && inst.hasValue) {
2028
+ var currentSelection = inst.value;
2029
+ if (isEqual(currentSelection, nextSnapshot))
2030
+ return memoizedSelection = currentSelection;
2031
+ }
2032
+ return memoizedSelection = nextSnapshot;
2033
+ }
2034
+ currentSelection = memoizedSelection;
2035
+ if (objectIs(memoizedSnapshot, nextSnapshot))
2036
+ return currentSelection;
2037
+ var nextSelection = selector(nextSnapshot);
2038
+ if (void 0 !== isEqual && isEqual(currentSelection, nextSelection))
2039
+ return memoizedSnapshot = nextSnapshot, currentSelection;
2040
+ memoizedSnapshot = nextSnapshot;
2041
+ return memoizedSelection = nextSelection;
2042
+ }
2043
+ var hasMemo = false, memoizedSnapshot, memoizedSelection, maybeGetServerSnapshot = void 0 === getServerSnapshot ? null : getServerSnapshot;
2044
+ return [
2045
+ function() {
2046
+ return memoizedSelector(getSnapshot());
2047
+ },
2048
+ null === maybeGetServerSnapshot ? void 0 : function() {
2049
+ return memoizedSelector(maybeGetServerSnapshot());
2050
+ }
2051
+ ];
2052
+ },
2053
+ [getSnapshot, getServerSnapshot, selector, isEqual]
2054
+ );
2055
+ var value = useSyncExternalStore(subscribe, instRef[0], instRef[1]);
2056
+ useEffect2(
2057
+ function() {
2058
+ inst.hasValue = true;
2059
+ inst.value = value;
2060
+ },
2061
+ [value]
2062
+ );
2063
+ useDebugValue(value);
2064
+ return value;
2065
+ };
2066
+ "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
2067
+ }();
2068
+ return withSelector_development;
2069
+ }
2070
+ var hasRequiredWithSelector;
2071
+ function requireWithSelector() {
2072
+ if (hasRequiredWithSelector) return withSelector.exports;
2073
+ hasRequiredWithSelector = 1;
2074
+ if (process.env.NODE_ENV === "production") {
2075
+ withSelector.exports = requireWithSelector_production();
2076
+ } else {
2077
+ withSelector.exports = requireWithSelector_development();
2078
+ }
2079
+ return withSelector.exports;
2080
+ }
2081
+ var withSelectorExports = requireWithSelector();
2082
+ var x = (t2) => t2, y = (t2, e2, n2) => {
2083
+ var _a, _b;
2084
+ let r2 = useRef((_a = t2 == null ? void 0 : t2.resolve) == null ? void 0 : _a.call(t2, e2, n2)), s2 = ((_b = t2 == null ? void 0 : t2.keyOfEntity) == null ? void 0 : _b.call(t2, e2)) ?? e2, o2 = useCallback((p2) => {
400
2085
  var _a2, _b2;
401
- return s ? (r.current = (_a2 = t == null ? void 0 : t.resolve) == null ? void 0 : _a2.call(t, s, n), o(), (_b2 = t == null ? void 0 : t.subscribe) == null ? void 0 : _b2.call(t, s, () => {
2086
+ return s2 ? (r2.current = (_a2 = t2 == null ? void 0 : t2.resolve) == null ? void 0 : _a2.call(t2, s2, n2), p2(), (_b2 = t2 == null ? void 0 : t2.subscribe) == null ? void 0 : _b2.call(t2, s2, () => {
402
2087
  var _a3;
403
- return r.current = (_a3 = t == null ? void 0 : t.resolve) == null ? void 0 : _a3.call(t, s, n), o();
404
- }, n)) : () => {
2088
+ return r2.current = (_a3 = t2 == null ? void 0 : t2.resolve) == null ? void 0 : _a3.call(t2, s2, n2), p2();
2089
+ }, n2)) : () => {
405
2090
  };
406
- }, [t, s]), i = useCallback((o) => {
407
- let p = typeof e == "string" ? e : t.keyOfEntity(e);
408
- e && p && t.mutate(p, o);
409
- }, [t, e]), a = () => r.current;
410
- return [shimExports.useSyncExternalStore(u, a, a), i];
411
- };
412
- const useFragmentManager = (fragmentId) => {
413
- const globalManager = useGlobalManager();
414
- const [globalGraph] = y(globalManager, globalManager == null ? void 0 : globalManager.key);
415
- const [loading, setLoading] = useState(false);
416
- const getFragmentManager = (id) => {
417
- var _a;
418
- return (_a = globalGraph == null ? void 0 : globalGraph.fragmentsManagers) == null ? void 0 : _a[id];
2091
+ }, [t2, s2]), a2 = useCallback((p2, c2) => {
2092
+ let u2 = typeof e2 == "string" ? e2 : keyOfEntity(e2);
2093
+ e2 && u2 && t2.mutate(u2, p2, c2);
2094
+ }, [t2, e2]), i2 = () => (n2 == null ? void 0 : n2.pause) ? null : r2.current;
2095
+ return [withSelectorExports.useSyncExternalStoreWithSelector(o2, i2, i2, x), a2];
2096
+ };
2097
+ var R = (t2) => t2, S = (t2, e2, n2) => {
2098
+ let r2 = useCallback((c2) => c2.map((u2) => t2.resolve(u2, n2)).filter(Boolean), [t2, n2]), s2 = useMemo(() => e2.map((c2) => t2.keyOfEntity(c2) || c2).join(), [e2]), o2 = useRef(r2(e2));
2099
+ useRef([]);
2100
+ let i2 = useCallback((c2) => {
2101
+ if (e2) {
2102
+ let u2 = () => {
2103
+ o2.current = r2(e2), c2();
2104
+ }, l2 = new AbortController();
2105
+ return e2.forEach((f2) => {
2106
+ f2 && t2.subscribe(f2, u2, { signal: l2.signal, ...n2 });
2107
+ }), u2(), () => l2.abort("unsubscribe");
2108
+ }
2109
+ return () => {
2110
+ };
2111
+ }, [t2, s2]), p2 = () => o2.current;
2112
+ return withSelectorExports.useSyncExternalStoreWithSelector(i2, p2, p2, R);
2113
+ };
2114
+ const GlobalManager = createContext(null);
2115
+ var __defProp = Object.defineProperty;
2116
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
2117
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
2118
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
2119
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2120
+ var __spreadValues = (a2, b) => {
2121
+ for (var prop in b || (b = {}))
2122
+ if (__hasOwnProp.call(b, prop))
2123
+ __defNormalProp(a2, prop, b[prop]);
2124
+ if (__getOwnPropSymbols)
2125
+ for (var prop of __getOwnPropSymbols(b)) {
2126
+ if (__propIsEnum.call(b, prop))
2127
+ __defNormalProp(a2, prop, b[prop]);
2128
+ }
2129
+ return a2;
2130
+ };
2131
+ var toPx = (val) => typeof val === "string" || typeof val === "number" ? `${val}px` : "0px";
2132
+ var isObject = (input) => {
2133
+ return typeof input === "object" && input !== null && !Array.isArray(input);
2134
+ };
2135
+ var isEmptyValue = (value) => !value && (value === null || value === void 0);
2136
+ var isValue = (value) => !isEmptyValue(value);
2137
+ var get = (obj, path, defValue) => {
2138
+ if (!path)
2139
+ return void 0;
2140
+ const pathArray = Array.isArray(path) ? path : path.match(/([^[.\]])+/g);
2141
+ const result = pathArray.reduce((prevObj, key) => prevObj && prevObj[key], obj);
2142
+ return result === void 0 ? defValue : result;
2143
+ };
2144
+ var set = (obj, path, value) => {
2145
+ const pathArray = Array.isArray(path) ? path : path.match(/([^[.\]])+/g);
2146
+ return pathArray.reduce((acc, key, i2) => {
2147
+ if (acc[key] === void 0)
2148
+ acc[key] = {};
2149
+ if (i2 === pathArray.length - 1)
2150
+ acc[key] = value;
2151
+ return acc[key];
2152
+ }, obj);
2153
+ };
2154
+ var isPrimitive = (value) => typeof value !== "object" && typeof value !== "function" || value === null;
2155
+ var toKebabCase = (value) => value.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($2, ofs) => (ofs ? "-" : "") + $2.toLowerCase());
2156
+ var noop = () => void 0;
2157
+ var pick = (obj, ...props) => {
2158
+ return props.reduce((result, prop) => {
2159
+ result[prop] = obj[prop];
2160
+ return result;
2161
+ }, {});
2162
+ };
2163
+ function omit(obj, ...props) {
2164
+ const result = __spreadValues({}, obj);
2165
+ props.forEach((prop) => {
2166
+ delete result[prop];
2167
+ });
2168
+ return result;
2169
+ }
2170
+ var cleanGraph = (input) => isObject(input) ? omit(input, "_type", "_id") : input;
2171
+ var isBrowser_default = typeof window !== "undefined";
2172
+ var generateId = () => Math.random().toString(16).slice(2);
2173
+ var flattenObject = (obj) => {
2174
+ const result = {};
2175
+ function flatten(current) {
2176
+ for (let key in current) {
2177
+ if (current.hasOwnProperty(key)) {
2178
+ const value = current[key];
2179
+ if (value && typeof value === "object" && !Array.isArray(value)) {
2180
+ flatten(value);
2181
+ } else {
2182
+ result[key] = value;
2183
+ }
2184
+ }
2185
+ }
2186
+ }
2187
+ flatten(obj);
2188
+ return result;
2189
+ };
2190
+ function isFiniteNumber(value) {
2191
+ return typeof value === "number" && isFinite(value);
2192
+ }
2193
+ var setKey$1 = (v2) => `$${v2}`;
2194
+ function hashGenerator(layerKey) {
2195
+ let hash = 0;
2196
+ for (let i2 = 0; i2 < layerKey.length; i2++) {
2197
+ hash = (hash << 5) - hash + layerKey.charCodeAt(i2);
2198
+ hash |= 0;
2199
+ }
2200
+ const raw = Math.abs(hash).toString(36);
2201
+ return /^[0-9]/.test(raw) ? `h${raw}` : raw;
2202
+ }
2203
+ const useGlobalManager = (globalManager) => {
2204
+ var _a, _b;
2205
+ const currentGlobalManager = useContext(GlobalManager);
2206
+ const resultManager = globalManager ?? currentGlobalManager;
2207
+ const [fragmentsGraph] = y(
2208
+ resultManager,
2209
+ (_a = resultManager == null ? void 0 : resultManager.$fragments) == null ? void 0 : _a.key
2210
+ );
2211
+ const queryFragmentManager = (id) => {
2212
+ var _a2, _b2;
2213
+ return (_b2 = (_a2 = resultManager == null ? void 0 : resultManager.$load) == null ? void 0 : _a2.loadFragment) == null ? void 0 : _b2.call(_a2, id);
2214
+ };
2215
+ const queryArea = (id) => {
2216
+ var _a2, _b2;
2217
+ return (_b2 = (_a2 = resultManager == null ? void 0 : resultManager.$load) == null ? void 0 : _a2.loadArea) == null ? void 0 : _b2.call(_a2, id);
419
2218
  };
420
- const loadFragmentManager = async (id) => {
421
- setLoading(true);
422
- const fragmentDocument = await globalGraph.fetchManager.queryFragment(id);
423
- const res = globalManager == null ? void 0 : globalManager.createFragmentManager(id, fragmentDocument);
424
- setLoading(false);
425
- return res;
2219
+ const setRenderTarget = (value) => {
2220
+ resultManager == null ? void 0 : resultManager.setRenderTarget(value);
426
2221
  };
2222
+ return {
2223
+ fragmentsGraph,
2224
+ manager: resultManager,
2225
+ queryFragmentManager,
2226
+ queryArea,
2227
+ getFragmentManager: ((_b = resultManager == null ? void 0 : resultManager.$fragments) == null ? void 0 : _b.getManager) ?? noop,
2228
+ setRenderTarget
2229
+ };
2230
+ };
2231
+ const useFragmentManager = (fragmentId, inputGlobalManager, aa) => {
2232
+ var _a;
2233
+ const {
2234
+ fragmentsGraph,
2235
+ manager: gg,
2236
+ getFragmentManager,
2237
+ queryFragmentManager
2238
+ } = useGlobalManager(inputGlobalManager);
2239
+ const [loading, setLoading] = useState(false);
2240
+ const manager = getFragmentManager(fragmentId);
427
2241
  useEffect(() => {
428
- loadFragmentManager(fragmentId);
429
- }, [fragmentId]);
2242
+ (async () => {
2243
+ if (fragmentsGraph && !getFragmentManager(fragmentId) && !!fragmentId) {
2244
+ setLoading(true);
2245
+ await queryFragmentManager(fragmentId);
2246
+ setLoading(false);
2247
+ }
2248
+ })();
2249
+ }, [fragmentId, fragmentsGraph]);
430
2250
  return {
431
2251
  loading,
432
- manager: getFragmentManager(fragmentId)
2252
+ manager,
2253
+ fragmentLayerKey: (_a = manager == null ? void 0 : manager.$fragment) == null ? void 0 : _a.root,
2254
+ queryFragmentManager
2255
+ // loadFragmentManager,
2256
+ };
2257
+ };
2258
+ const FragmentContext = createContext({
2259
+ manager: null
2260
+ });
2261
+ const setKey = (v2) => `$${v2}`;
2262
+ const getKey = (v2) => isKey(v2) ? v2.slice(1) : null;
2263
+ const isKey = (v2) => typeof v2 === "string" && v2.startsWith("$");
2264
+ const getParent = (manager, layerKey) => {
2265
+ const layer = manager.resolve(layerKey);
2266
+ return manager.resolve(getKey(layer == null ? void 0 : layer.parent) ?? null);
2267
+ };
2268
+ const isRootLayer = (manager, layerKey) => {
2269
+ var _a, _b;
2270
+ const resolvedNode = (_a = manager == null ? void 0 : manager.resolve) == null ? void 0 : _a.call(manager, layerKey);
2271
+ return ((_b = getParent(manager, layerKey)) == null ? void 0 : _b._type) === index.nodes.Fragment && !(resolvedNode == null ? void 0 : resolvedNode.isBreakpoint);
2272
+ };
2273
+ const isTopLevel = (manager, layerKey) => {
2274
+ var _a;
2275
+ return ((_a = getParent(manager, layerKey)) == null ? void 0 : _a._type) === index.nodes.Fragment;
2276
+ };
2277
+ const getAllParents = (manager, layerKey, stack = []) => {
2278
+ const parent = getParent(manager, layerKey);
2279
+ if (parent) {
2280
+ stack.push(parent);
2281
+ getAllParents(manager, manager.keyOfEntity(parent), stack);
2282
+ }
2283
+ return stack;
2284
+ };
2285
+ const isPartOfPrimary = (manager, layerKey) => {
2286
+ var _a;
2287
+ const allParents = getAllParents(manager, manager.keyOfEntity(layerKey));
2288
+ const layer = manager.resolve(layerKey);
2289
+ return (layer == null ? void 0 : layer.isPrimary) ?? !!((_a = allParents == null ? void 0 : allParents.find) == null ? void 0 : _a.call(allParents, (parent) => !!(parent == null ? void 0 : parent.isPrimary)));
2290
+ };
2291
+ const createLayer = (externalLayerData, overrideId = false) => {
2292
+ if (!externalLayerData || !isObject(externalLayerData)) return null;
2293
+ const cleanLayer = Object.entries(externalLayerData).reduce(
2294
+ (acc, [key, value]) => {
2295
+ if (isObject(value) && "_type" in value && "_id" in value && isPartialKey(`${value._type}:${value._id}`)) {
2296
+ delete value._id;
2297
+ delete value._type;
2298
+ }
2299
+ acc[key] = value;
2300
+ return acc;
2301
+ },
2302
+ {}
2303
+ );
2304
+ return overrideId ? {
2305
+ ...cleanLayer,
2306
+ _id: generateId()
2307
+ } : {
2308
+ _id: generateId(),
2309
+ ...cleanLayer
2310
+ };
2311
+ };
2312
+ const cloneLayer = (manager, layer, externalProps = {}, _parent) => {
2313
+ const layerGraph = manager.resolve(layer);
2314
+ const layerKey = manager.keyOfEntity(layer);
2315
+ const layerParent = _parent ?? manager.keyOfEntity(getParent(manager, layerKey));
2316
+ if (layerGraph) {
2317
+ const clonedLayer = createLayer(
2318
+ {
2319
+ _type: layerGraph._type,
2320
+ overrideFrom: setKey(layerKey),
2321
+ parent: setKey(layerParent),
2322
+ ...(layerGraph == null ? void 0 : layerGraph._type) === index.nodes.Instance ? pick(layerGraph, "fragment") : {},
2323
+ ...externalProps
2324
+ },
2325
+ true
2326
+ );
2327
+ const clonedChildren = ((layerGraph == null ? void 0 : layerGraph.children) ?? []).map(
2328
+ (child) => cloneLayer(manager, child, {}, manager.keyOfEntity(clonedLayer))
2329
+ );
2330
+ const clonedKey = manager.mutate({
2331
+ ...clonedLayer,
2332
+ children: clonedChildren
2333
+ });
2334
+ manager.mutate(layerKey, {
2335
+ overrides: [clonedKey]
2336
+ });
2337
+ return clonedKey;
2338
+ }
2339
+ return null;
2340
+ };
2341
+ function makeSnapshot(globalManager, targetFragmentId) {
2342
+ var _a, _b;
2343
+ if (!globalManager || !targetFragmentId) return null;
2344
+ const targetFragment = (_b = (_a = globalManager == null ? void 0 : globalManager.$fragments) == null ? void 0 : _a.getManager) == null ? void 0 : _b.call(_a, targetFragmentId);
2345
+ if (!targetFragment) return null;
2346
+ const fragmentDocument = targetFragment.resolve(
2347
+ targetFragment.$fragment.root,
2348
+ { deep: true }
2349
+ );
2350
+ const linkedFragments = Array.from(
2351
+ new Set(
2352
+ targetFragment.inspectFields(index.nodes.Instance).map((link) => {
2353
+ var _a2;
2354
+ return (_a2 = targetFragment.resolve(link)) == null ? void 0 : _a2.fragment;
2355
+ }).values()
2356
+ )
2357
+ );
2358
+ const linkedGoals = Array.from(
2359
+ new Set(
2360
+ targetFragment.inspectFields(index.nodes.Variable).map(targetFragment == null ? void 0 : targetFragment.resolve).filter((graph) => {
2361
+ return (graph == null ? void 0 : graph.type) === index.variableType.Event && (graph == null ? void 0 : graph.mode) === index.eventMode.goal;
2362
+ }).map((graph) => {
2363
+ var _a2;
2364
+ return (_a2 = graph == null ? void 0 : graph.defaultValue) == null ? void 0 : _a2.goalId;
2365
+ }).filter(Boolean).values()
2366
+ )
2367
+ );
2368
+ return {
2369
+ document: fragmentDocument,
2370
+ linkedFragments,
2371
+ linkedGoals
2372
+ };
2373
+ }
2374
+ const getOverrider = (manager, layerEntity) => {
2375
+ const layer = manager.resolve(layerEntity);
2376
+ return manager.resolve(getKey(layer == null ? void 0 : layer.overrideFrom) ?? layerEntity);
2377
+ };
2378
+ const isInheritField = (manager, layerEntity, field) => {
2379
+ const layer = manager.resolve(layerEntity);
2380
+ if (layer) {
2381
+ const overrider = getOverrider(manager, layer);
2382
+ if ((overrider == null ? void 0 : overrider._id) === (layer == null ? void 0 : layer._id)) return false;
2383
+ return !!overrider && !isValue(layer == null ? void 0 : layer[field]);
2384
+ }
2385
+ return false;
2386
+ };
2387
+ const declareFragmentProperty = (manager, property, fragmentLink = manager.$fragment.root) => {
2388
+ const propertyLayer = createLayer(property);
2389
+ if (propertyLayer && "type" in propertyLayer) {
2390
+ manager.mutate(manager.keyOfEntity(fragmentLink), {
2391
+ properties: [propertyLayer]
2392
+ });
2393
+ return manager.keyOfEntity(propertyLayer);
2394
+ }
2395
+ return null;
2396
+ };
2397
+ const appendChildren = (manager, target, ...children) => {
2398
+ const targetEntity = manager.entityOfKey(target);
2399
+ const parseChildren = children.map(
2400
+ (child) => createLayer({
2401
+ ...manager.entityOfKey(child) ?? child,
2402
+ parent: setKey(manager.keyOfEntity(target))
2403
+ })
2404
+ ).filter(Boolean);
2405
+ if (targetEntity._type !== index.nodes.Frame) {
2406
+ manager.mutate(manager.keyOfEntity(target), {
2407
+ children: parseChildren
2408
+ });
2409
+ return;
2410
+ }
2411
+ const primaryTarget = getOverrider(manager, target);
2412
+ const isPrimaryTarget = isPartOfPrimary(manager, target);
2413
+ ((primaryTarget == null ? void 0 : primaryTarget.overrides) ?? []).forEach((override) => {
2414
+ const overridesChildren = parseChildren.map((child) => {
2415
+ const nextChild = createLayer(
2416
+ {
2417
+ ...pick(child, "parent", "_type"),
2418
+ overrideFrom: setKey(manager.keyOfEntity(child))
2419
+ },
2420
+ true
2421
+ );
2422
+ if (!isPrimaryTarget) {
2423
+ nextChild.visible = true;
2424
+ }
2425
+ return nextChild;
2426
+ }).filter(Boolean);
2427
+ overridesChildren.forEach((child, index2) => {
2428
+ const primaryChild = parseChildren.at(index2);
2429
+ if ("overrides" in primaryChild) {
2430
+ primaryChild.overrides.push(manager.keyOfEntity(child));
2431
+ } else {
2432
+ primaryChild.overrides = [manager.keyOfEntity(child)];
2433
+ }
2434
+ });
2435
+ manager.mutate(manager.keyOfEntity(override), {
2436
+ children: overridesChildren
2437
+ });
2438
+ });
2439
+ manager.mutate(manager.keyOfEntity(primaryTarget), {
2440
+ children: parseChildren.map((child) => ({
2441
+ ...child,
2442
+ visible: isPrimaryTarget
2443
+ }))
2444
+ });
2445
+ return parseChildren.map(manager.keyOfEntity);
2446
+ };
2447
+ const insertChildren = (manager, target, index2, ...layerKeys) => {
2448
+ appendChildren(manager, target, ...layerKeys);
2449
+ const targetLayer = manager.resolve(target);
2450
+ const overrideLayers = ((targetLayer == null ? void 0 : targetLayer.overrides) ?? []).map(manager.resolve);
2451
+ [targetLayer, ...overrideLayers].forEach((layer) => {
2452
+ const children = (layer == null ? void 0 : layer.children) ?? [];
2453
+ const appendedLayers = children.slice(layerKeys.length * -1);
2454
+ const nextChildren = children.slice(0, layerKeys.length * -1);
2455
+ nextChildren.splice(index2, 0, ...appendedLayers);
2456
+ manager.mutate(
2457
+ manager.keyOfEntity(layer),
2458
+ (prev) => ({
2459
+ ...prev,
2460
+ children: nextChildren
2461
+ }),
2462
+ { replace: true }
2463
+ );
2464
+ });
2465
+ };
2466
+ const removeChildren = (manager, ...layerKeys) => {
2467
+ layerKeys.map(manager.resolve).forEach((layer) => {
2468
+ const isPrimary = isPartOfPrimary(manager, layer);
2469
+ if (isPrimary || (layer == null ? void 0 : layer.isBreakpoint)) {
2470
+ ((layer == null ? void 0 : layer.overrides) ?? []).concat((layer == null ? void 0 : layer.children) ?? []).forEach(manager.invalidate);
2471
+ manager.invalidate(layer);
2472
+ } else {
2473
+ manager.mutate(manager.keyOfEntity(layer), {
2474
+ visible: false
2475
+ });
2476
+ }
2477
+ });
2478
+ };
2479
+ const moveChildren = (manager, targetKey, toKey, index2) => {
2480
+ const targetClone = duplicateLayer(manager, targetKey, true);
2481
+ insertChildren(manager, toKey, index2, targetClone);
2482
+ removeChildren(manager, targetKey);
2483
+ };
2484
+ const duplicateLayer = (manager, layer, _deep, _newParent) => {
2485
+ var _a;
2486
+ const layerGraph = manager.resolve(layer);
2487
+ if (layerGraph) {
2488
+ const nextId = generateId();
2489
+ const nextLayerKey = keyOfEntity({
2490
+ _type: layerGraph._type,
2491
+ _id: nextId
2492
+ });
2493
+ const clonedChildren = ((layerGraph == null ? void 0 : layerGraph.children) ?? []).map(
2494
+ (child) => duplicateLayer(manager, child, true, nextLayerKey)
2495
+ );
2496
+ const duplicatedLayer = createLayer(
2497
+ {
2498
+ _type: layerGraph._type,
2499
+ ...layerGraph,
2500
+ _id: nextId,
2501
+ parent: _deep ? setKey$1(_newParent) : layerGraph == null ? void 0 : layerGraph.parent,
2502
+ children: clonedChildren
2503
+ },
2504
+ false
2505
+ );
2506
+ const duplicatedKey = manager.mutate(duplicatedLayer);
2507
+ if (!_deep) {
2508
+ const parent = getParent(manager, layer);
2509
+ if (parent) {
2510
+ const layerIndex = (_a = parent == null ? void 0 : parent.children) == null ? void 0 : _a.findIndex(
2511
+ (child) => child === manager.keyOfEntity(layer)
2512
+ );
2513
+ insertChildren(manager, parent, layerIndex + 1, duplicatedKey);
2514
+ }
2515
+ }
2516
+ return duplicatedKey;
2517
+ }
2518
+ return null;
2519
+ };
2520
+ const isVariableLink = (value) => {
2521
+ var _a;
2522
+ return isLink(value) && ((_a = value == null ? void 0 : value.split(":")) == null ? void 0 : _a.at(0)) === index.nodes.Variable;
2523
+ };
2524
+ const isLink = (value) => {
2525
+ var _a, _b;
2526
+ return value && ((_b = (_a = value == null ? void 0 : value.split) == null ? void 0 : _a.call(value, ":")) == null ? void 0 : _b.length) === 2;
2527
+ };
2528
+ const getCssVariables = (props) => {
2529
+ return Object.entries(cleanGraph(flattenObject(props))).reduce(
2530
+ (acc, [key, value]) => {
2531
+ var _a;
2532
+ if (isVariableLink(value)) {
2533
+ const nestedVariableId = (_a = entityOfKey(value)) == null ? void 0 : _a._id;
2534
+ value = `var(--${nestedVariableId})`;
2535
+ }
2536
+ acc[`--${key}`] = value;
2537
+ return acc;
2538
+ },
2539
+ {}
2540
+ );
2541
+ };
2542
+ const layerFieldSetter = (manager, layerKey, fieldKey, currentValue) => (value, options2) => {
2543
+ var _a;
2544
+ const { success, output } = parseLayerField(
2545
+ manager.resolve(layerKey),
2546
+ fieldKey,
2547
+ value
2548
+ );
2549
+ if (success) {
2550
+ if (isVariableLink$1(value)) {
2551
+ manager.mutate((_a = manager == null ? void 0 : manager.$fragment) == null ? void 0 : _a.temp, {
2552
+ [layerKey]: {
2553
+ [fieldKey]: currentValue
2554
+ }
2555
+ });
2556
+ }
2557
+ manager.mutate(
2558
+ layerKey,
2559
+ (prev) => {
2560
+ set(prev, fieldKey, output);
2561
+ return prev;
2562
+ },
2563
+ options2
2564
+ );
2565
+ }
2566
+ };
2567
+ const getLayer = (manager, layer, options2) => {
2568
+ if (!manager || !layer) return null;
2569
+ const layerKey = manager.keyOfEntity(layer);
2570
+ const layerData = manager.resolve(layerKey);
2571
+ const overrider = getOverrider(manager, layerKey);
2572
+ return getNormalizeLayer$1(layerData, overrider, options2 == null ? void 0 : options2.withFallback);
2573
+ };
2574
+ const getNormalizeLayer = (layerKey, manager, options2) => {
2575
+ const layer = manager == null ? void 0 : manager.resolve(layerKey);
2576
+ const parsedLayer = getLayer(manager, layerKey, options2);
2577
+ return {
2578
+ rawLayer: layer,
2579
+ layer: parsedLayer
2580
+ };
2581
+ };
2582
+ const useNormalizeLayer = (layerKey, manager, options2) => {
2583
+ const { manager: fragmentManager } = useContext(FragmentContext);
2584
+ const resultManager = manager ?? fragmentManager;
2585
+ return getNormalizeLayer(layerKey, resultManager, options2);
2586
+ };
2587
+ const ScopeContext = createContext([]);
2588
+ const extractVariableValue = (input, variableId) => {
2589
+ if (isObject(input)) {
2590
+ if (variableId in input) {
2591
+ return input[variableId];
2592
+ }
2593
+ for (let key in input) {
2594
+ if (input.hasOwnProperty(key)) {
2595
+ const result = extractVariableValue(input[key], variableId);
2596
+ if (result !== void 0) {
2597
+ return result;
2598
+ }
2599
+ }
2600
+ }
2601
+ }
2602
+ return void 0;
2603
+ };
2604
+ function deepMerge(a2, b) {
2605
+ if (!isObject(a2) || !isObject(b)) return a2;
2606
+ const result = { ...b };
2607
+ for (const [key, value] of Object.entries(a2)) {
2608
+ if (key in result && typeof result[key] === "object" && typeof value === "object") {
2609
+ result[key] = deepMerge(value, result[key]);
2610
+ } else {
2611
+ result[key] = value;
2612
+ }
2613
+ }
2614
+ return result;
2615
+ }
2616
+ const useReadVariable = (variableKey) => {
2617
+ const scopes = useContext(ScopeContext);
2618
+ const extractVariableDefaultValue = (manager, variableEntity) => {
2619
+ const variableLayer = manager.resolve(variableEntity);
2620
+ if ((variableLayer == null ? void 0 : variableLayer.type) !== index.variableType.Object)
2621
+ return variableLayer == null ? void 0 : variableLayer.defaultValue;
2622
+ return Object.values((variableLayer == null ? void 0 : variableLayer.fields) ?? {}).reduce(
2623
+ (acc, fieldLink) => {
2624
+ var _a;
2625
+ if (!!fieldLink && isVariableLink$1(fieldLink)) {
2626
+ const _id = (_a = entityOfKey(fieldLink)) == null ? void 0 : _a._id;
2627
+ if (_id) {
2628
+ acc[_id] = extractVariableDefaultValue(manager, fieldLink);
2629
+ }
2630
+ }
2631
+ return acc;
2632
+ },
2633
+ {}
2634
+ );
433
2635
  };
2636
+ const resolveVariableLayer = (manager, variableLink, customProps) => {
2637
+ var _a;
2638
+ const variableLayer = manager == null ? void 0 : manager.resolve(variableLink);
2639
+ if (!variableLayer) return null;
2640
+ if ((variableLayer == null ? void 0 : variableLayer.type) === index.variableType.Array) {
2641
+ const definitionLayer = manager.resolve(variableLayer == null ? void 0 : variableLayer.definition);
2642
+ if (!((_a = variableLayer == null ? void 0 : variableLayer.defaultValue) == null ? void 0 : _a.length) || (definitionLayer == null ? void 0 : definitionLayer.type) !== index.variableType.Object)
2643
+ return variableLayer;
2644
+ const definitionDefaultValue = extractVariableDefaultValue(
2645
+ manager,
2646
+ definitionLayer
2647
+ );
2648
+ const customValue = customProps == null ? void 0 : customProps[variableLayer == null ? void 0 : variableLayer._id];
2649
+ return {
2650
+ ...variableLayer,
2651
+ defaultValue: (variableLayer == null ? void 0 : variableLayer.defaultValue).map((item, index2) => {
2652
+ const customItemValue = Array.isArray(customValue) ? customValue.at(index2) : null;
2653
+ return deepMerge(
2654
+ customItemValue ? { ...item, ...customItemValue } : item,
2655
+ definitionDefaultValue
2656
+ );
2657
+ })
2658
+ };
2659
+ }
2660
+ return variableLayer;
2661
+ };
2662
+ const readVariable = (variableKey2) => {
2663
+ var _a, _b, _c;
2664
+ const variableId = (_a = entityOfKey(variableKey2)) == null ? void 0 : _a._id;
2665
+ if (!isVariableLink$1(variableKey2)) {
2666
+ return {
2667
+ value: null,
2668
+ layer: null
2669
+ };
2670
+ }
2671
+ const instanceScope = scopes.findLast(
2672
+ (scope) => {
2673
+ var _a2;
2674
+ return (scope == null ? void 0 : scope.type) === index.scopeTypes.InstanceScope && !!((_a2 = scope.documentManager) == null ? void 0 : _a2.resolve(variableKey2));
2675
+ }
2676
+ );
2677
+ const variableLayer = resolveVariableLayer(
2678
+ instanceScope == null ? void 0 : instanceScope.documentManager,
2679
+ variableKey2
2680
+ );
2681
+ let instanceProp = (_b = instanceScope == null ? void 0 : instanceScope.props) == null ? void 0 : _b[variableId];
2682
+ if (Array.isArray(instanceProp)) {
2683
+ instanceProp = instanceProp.map(
2684
+ (rawProp, index2) => {
2685
+ var _a2;
2686
+ return deepMerge(rawProp, (_a2 = variableLayer == null ? void 0 : variableLayer.defaultValue) == null ? void 0 : _a2.at(index2));
2687
+ }
2688
+ );
2689
+ }
2690
+ const lastCollectionItem = scopes.findLast(
2691
+ (scope) => (scope == null ? void 0 : scope.type) === index.scopeTypes.CollectionItemScope
2692
+ );
2693
+ resolveVariableLayer(
2694
+ lastCollectionItem == null ? void 0 : lastCollectionItem.manager,
2695
+ lastCollectionItem == null ? void 0 : lastCollectionItem.sourceDefinition,
2696
+ lastCollectionItem == null ? void 0 : lastCollectionItem.value
2697
+ );
2698
+ const collectionItemProp = isPrimitive(lastCollectionItem == null ? void 0 : lastCollectionItem.value) && ((_c = entityOfKey(lastCollectionItem == null ? void 0 : lastCollectionItem.sourceDefinition)) == null ? void 0 : _c._id) === variableId ? lastCollectionItem == null ? void 0 : lastCollectionItem.value : extractVariableValue(lastCollectionItem == null ? void 0 : lastCollectionItem.value, variableId);
2699
+ const currentValue = variableKey2 === instanceProp ? null : collectionItemProp ?? instanceProp ?? null;
2700
+ const required = (variableLayer == null ? void 0 : variableLayer.required) ?? false;
2701
+ const defaultValue = (variableLayer == null ? void 0 : variableLayer.defaultValue) ?? null;
2702
+ const resultValue = required ? currentValue : currentValue ?? collectionItemProp ?? defaultValue;
2703
+ if (isVariableLink$1(resultValue)) {
2704
+ return readVariable(resultValue);
2705
+ }
2706
+ return {
2707
+ value: resultValue,
2708
+ layer: variableLayer
2709
+ };
2710
+ };
2711
+ const { layer, value } = readVariable(variableKey);
2712
+ return {
2713
+ value,
2714
+ layer,
2715
+ readVariable
2716
+ };
2717
+ };
2718
+ const useLayerCssVariable = (inputValue) => {
2719
+ const { manager } = useContext(FragmentContext);
2720
+ const isVariable = isVariableLink$1(inputValue);
2721
+ const [variableValue] = y(isVariable ? manager : null, inputValue, {
2722
+ selector: (graph) => pick(graph, "defaultValue", "_id")
2723
+ });
2724
+ return {
2725
+ value: isVariable ? `var(--${variableValue == null ? void 0 : variableValue._id}, ${variableValue == null ? void 0 : variableValue.defaultValue})` : null
2726
+ };
2727
+ };
2728
+ const useLayerValue = (layerKey, fieldKey, options2) => {
2729
+ const { manager: fragmentManager } = useContext(FragmentContext);
2730
+ const resultManager = (options2 == null ? void 0 : options2.manager) ?? fragmentManager;
2731
+ if (!resultManager) {
2732
+ return [null, noop, {}];
2733
+ }
2734
+ const key = keyOfEntity(layerKey);
2735
+ const [, updateLayerData] = y(resultManager, key, {
2736
+ // selector: (data) => (data ? pick(data, fieldKey) : data),
2737
+ });
2738
+ const { layer, rawLayer } = useNormalizeLayer(key, resultManager, options2);
2739
+ const rawValue = get(rawLayer, fieldKey);
2740
+ const layerValue = get(layer, fieldKey);
2741
+ const { value: variableValue } = useReadVariable(layerValue);
2742
+ const currentValue = variableValue ?? layerValue;
2743
+ const isInherit = isInheritField(resultManager, key, fieldKey);
2744
+ const isOverride = !isInherit && !isPartOfPrimary(resultManager, key);
2745
+ const setter = layerFieldSetter(resultManager, key, fieldKey, currentValue);
2746
+ const resetOverride = useCallback(() => {
2747
+ resultManager.mutate(
2748
+ key,
2749
+ (prev) => {
2750
+ const r2 = omit(prev, fieldKey);
2751
+ return r2;
2752
+ },
2753
+ { replace: true }
2754
+ );
2755
+ }, [updateLayerData]);
2756
+ const restore = useCallback(
2757
+ (fallbackValue) => {
2758
+ var _a, _b, _c;
2759
+ const tempValue = ((_c = (_b = resultManager.resolve((_a = resultManager == null ? void 0 : resultManager.$fragment) == null ? void 0 : _a.temp)) == null ? void 0 : _b[key]) == null ? void 0 : _c[fieldKey]) ?? fallbackValue;
2760
+ updateLayerData({ [fieldKey]: tempValue });
2761
+ return tempValue;
2762
+ },
2763
+ [updateLayerData, resultManager]
2764
+ );
2765
+ const updateValue = useCallback(
2766
+ (value, options22) => {
2767
+ setter(value, options22);
2768
+ },
2769
+ [setter]
2770
+ );
2771
+ const { value: cssValue } = useLayerCssVariable(rawValue ?? layerValue);
2772
+ return [
2773
+ currentValue,
2774
+ updateValue,
2775
+ {
2776
+ isOverride,
2777
+ resetOverride,
2778
+ isVariable: isVariableLink$1(rawValue ?? layerValue),
2779
+ cssVariableValue: cssValue ?? currentValue,
2780
+ rawValue,
2781
+ restore,
2782
+ ...resultManager.entityOfKey(key)
2783
+ }
2784
+ ];
2785
+ };
2786
+ const processOptionalSize = (value, type) => {
2787
+ if (value === -1) return "";
2788
+ if (type === index.sizing.Fixed) return toPx(value);
2789
+ if (type === index.sizing.Relative) return `${value}%`;
2790
+ return "";
2791
+ };
2792
+ const useOptionalSize = (type, layerKey) => {
2793
+ const { manager: fragmentManager } = useContext(FragmentContext);
2794
+ const [value] = useLayerValue(layerKey, type, fragmentManager);
2795
+ const [valueType] = useLayerValue(layerKey, `${type}Type`, fragmentManager);
2796
+ return useMemo(
2797
+ () => processOptionalSize(value, valueType),
2798
+ [valueType, value]
2799
+ );
2800
+ };
2801
+ const useLayerSize = (layerKey) => {
2802
+ const { manager } = useContext(FragmentContext);
2803
+ const minWidth = useOptionalSize("minWidth", layerKey);
2804
+ const minHeight = useOptionalSize("minHeight", layerKey);
2805
+ const maxWidth = useOptionalSize("maxWidth", layerKey);
2806
+ const maxHeight = useOptionalSize("maxHeight", layerKey);
2807
+ return {
2808
+ // width: widthCalc(widthValue),
2809
+ // height: heightCalc(heightValue),
2810
+ minWidth,
2811
+ minHeight,
2812
+ maxWidth,
2813
+ maxHeight
2814
+ };
2815
+ };
2816
+ const autoSizes = [index.sizing.Hug];
2817
+ const useLayerSizeValue = (layerKey, sizeType) => {
2818
+ const { manager: fragmentManager } = useContext(FragmentContext);
2819
+ const { layerKey: instanceLayerKey } = useContext(InstanceContext);
2820
+ const { isDocument, renderTarget: renderTarget2 } = useRenderTarget();
2821
+ const isTop = isTopLevel(fragmentManager, layerKey);
2822
+ const isPartOfInstance = !!instanceLayerKey;
2823
+ const layerParent = getParent(fragmentManager, layerKey);
2824
+ const { layer: normalizeParentLayer } = useNormalizeLayer(
2825
+ layerParent,
2826
+ fragmentManager
2827
+ );
2828
+ const layerNode = fragmentManager.resolve(layerKey);
2829
+ const [instanceType] = useLayerValue(
2830
+ instanceLayerKey,
2831
+ `${sizeType}Type`,
2832
+ fragmentManager
2833
+ );
2834
+ const [valueType] = useLayerValue(
2835
+ layerKey,
2836
+ `${sizeType}Type`,
2837
+ fragmentManager
2838
+ );
2839
+ const growType = sizeType === "width" ? "horizontalGrow" : "verticalGrow";
2840
+ return useCallback(
2841
+ (value) => {
2842
+ if (isTop && isDocument && (normalizeParentLayer == null ? void 0 : normalizeParentLayer[growType]) === index.fragmentGrowingMode.fill) {
2843
+ return "100%";
2844
+ }
2845
+ if (isTop && isPartOfInstance && !autoSizes.includes(instanceType)) {
2846
+ return "100%";
2847
+ }
2848
+ if (autoSizes.includes(valueType)) {
2849
+ return layerNode._type === index.nodes.Instance ? "auto" : "min-content";
2850
+ }
2851
+ if (valueType === index.sizing.Relative) {
2852
+ return `${value}%`;
2853
+ }
2854
+ if (valueType === index.sizing.Fill) {
2855
+ return `100%`;
2856
+ }
2857
+ return toPx(value);
2858
+ },
2859
+ [
2860
+ isTop,
2861
+ isDocument,
2862
+ layerParent,
2863
+ growType,
2864
+ isPartOfInstance,
2865
+ instanceType,
2866
+ valueType,
2867
+ layerNode
2868
+ ]
2869
+ );
2870
+ };
2871
+ const useLayerPosition = (layerKey) => {
2872
+ const { layerKey: instanceLayerKey } = useContext(InstanceContext);
2873
+ const { manager: fragmentManager } = useContext(FragmentContext);
2874
+ const { isDocument } = useRenderTarget();
2875
+ const isTop = isTopLevel(fragmentManager, layerKey);
2876
+ const [width] = useLayerValue(layerKey, "width");
2877
+ const [height] = useLayerValue(layerKey, "height");
2878
+ const widthCalc = useLayerSizeValue(layerKey, "width")(width);
2879
+ const heightCalc = useLayerSizeValue(layerKey, "height")(height);
2880
+ const [position] = useLayerValue(layerKey, "position");
2881
+ const [centerAnchorX] = useLayerValue(layerKey, "centerAnchorX");
2882
+ const [centerAnchorY] = useLayerValue(layerKey, "centerAnchorY");
2883
+ const [top] = useLayerValue(layerKey, "top");
2884
+ const [left] = useLayerValue(layerKey, "left");
2885
+ const [right] = useLayerValue(layerKey, "right");
2886
+ const [bottom] = useLayerValue(layerKey, "bottom");
2887
+ const skipPosition = isTop && isDocument || !!instanceLayerKey && isTop;
2888
+ if (isTop && !skipPosition) {
2889
+ return {
2890
+ position: index.positionType.absolute,
2891
+ top: toPx(top),
2892
+ left: toPx(left),
2893
+ width,
2894
+ height
2895
+ };
2896
+ }
2897
+ if (position === index.positionType.relative || skipPosition) {
2898
+ return {
2899
+ position: index.positionType.relative,
2900
+ width: widthCalc,
2901
+ height: heightCalc
2902
+ };
2903
+ }
2904
+ const hasConstrainX = isFiniteNumber(left) && isFiniteNumber(right);
2905
+ const hasConstrainY = isFiniteNumber(top) && isFiniteNumber(bottom);
2906
+ const hasAnyConstrainX = isFiniteNumber(left) || isFiniteNumber(right);
2907
+ const hasAnyConstrainY = isFiniteNumber(top) || isFiniteNumber(bottom);
2908
+ return {
2909
+ position,
2910
+ left: isFiniteNumber(left) ? toPx(left) : !isFiniteNumber(right) ? `${centerAnchorX * 100}%` : null,
2911
+ top: isFiniteNumber(top) ? toPx(top) : !isFiniteNumber(bottom) ? `${centerAnchorY * 100}%` : null,
2912
+ right: isFiniteNumber(right) ? toPx(right) : null,
2913
+ bottom: isFiniteNumber(bottom) ? toPx(bottom) : null,
2914
+ width: hasConstrainX ? null : widthCalc,
2915
+ height: hasConstrainY ? null : heightCalc,
2916
+ transform: !hasAnyConstrainX || !hasAnyConstrainY ? `translate3d(${!hasAnyConstrainX ? "-50%" : 0}, ${!hasAnyConstrainY ? "-50%" : 0}, 0px)` : null
2917
+ };
2918
+ };
2919
+ const useLayerBackground = (layerKey) => {
2920
+ const { manager: fragmentManager } = useContext(FragmentContext);
2921
+ const [fillType] = useLayerValue(layerKey, "fillType", fragmentManager);
2922
+ const [, , { cssVariableValue: cssSolidFill }] = useLayerValue(
2923
+ layerKey,
2924
+ "solidFill",
2925
+ fragmentManager
2926
+ );
2927
+ const [imageFill, , { cssVariableValue: cssImageFill }] = useLayerValue(
2928
+ layerKey,
2929
+ "imageFill",
2930
+ fragmentManager
2931
+ );
2932
+ const [, , { cssVariableValue: cssImageSize }] = useLayerValue(
2933
+ layerKey,
2934
+ "imageSize",
2935
+ fragmentManager
2936
+ );
2937
+ return useMemo(() => {
2938
+ if (fillType === index.paintMode.Solid) {
2939
+ return {
2940
+ background: cssSolidFill
2941
+ };
2942
+ }
2943
+ if (fillType === index.paintMode.Image && cssImageFill) {
2944
+ return {
2945
+ background: `url(${imageFill})`,
2946
+ backgroundSize: cssImageSize == null ? void 0 : cssImageSize.toLowerCase(),
2947
+ backgroundRepeat: "no-repeat"
2948
+ };
2949
+ }
2950
+ return {
2951
+ background: "transparent"
2952
+ };
2953
+ }, [fillType, cssImageFill, cssSolidFill]);
2954
+ };
2955
+ const useLayerDisplay = (layerKey) => {
2956
+ const { manager } = useContext(FragmentContext);
2957
+ const [layerModeValue] = useLayerValue(layerKey, "layerMode", manager);
2958
+ const [visible] = useLayerValue(layerKey, "visible", manager);
2959
+ return useMemo(() => {
2960
+ if (!visible) {
2961
+ return "none";
2962
+ }
2963
+ return layerModeValue === index.layerMode.flex ? "flex" : null;
2964
+ }, [layerModeValue, visible]);
2965
+ };
2966
+ const useCalcLayerBorder = (layerKey) => {
2967
+ const { manager: fragmentManager } = useContext(FragmentContext);
2968
+ const [borderTypeValue] = useLayerValue(
2969
+ layerKey,
2970
+ "borderType",
2971
+ fragmentManager
2972
+ );
2973
+ return (width, color) => {
2974
+ let value = {
2975
+ borderTop: ``,
2976
+ borderRight: ``,
2977
+ borderBottom: ``,
2978
+ borderLeft: ``
2979
+ };
2980
+ if (typeof borderTypeValue === "string" && borderTypeValue !== index.borderType.None) {
2981
+ const staticPart = `${borderTypeValue.toLowerCase()} ${color}`;
2982
+ const widthSides = width == null ? void 0 : width.split(" ");
2983
+ if (widthSides.length === 1) {
2984
+ const widthValue = widthSides == null ? void 0 : widthSides.at(0);
2985
+ value = {
2986
+ borderTop: `${widthValue} ${staticPart}`,
2987
+ borderRight: `${widthValue} ${staticPart}`,
2988
+ borderBottom: `${widthValue} ${staticPart}`,
2989
+ borderLeft: `${widthValue} ${staticPart}`
2990
+ };
2991
+ } else {
2992
+ value = {
2993
+ borderTop: `${widthSides == null ? void 0 : widthSides.at(0)} ${staticPart}`,
2994
+ borderRight: `${widthSides == null ? void 0 : widthSides.at(1)} ${staticPart}`,
2995
+ borderBottom: `${widthSides == null ? void 0 : widthSides.at(2)} ${staticPart}`,
2996
+ borderLeft: `${widthSides == null ? void 0 : widthSides.at(3)} ${staticPart}`
2997
+ };
2998
+ }
2999
+ }
3000
+ return value;
3001
+ };
3002
+ };
3003
+ const useLayerBorder = (layerKey) => {
3004
+ const { manager: fragmentManager } = useContext(FragmentContext);
3005
+ const [borderWidth] = useLayerValue(layerKey, "borderWidth", fragmentManager);
3006
+ const [borderColor] = useLayerValue(layerKey, "borderColor", fragmentManager);
3007
+ const calcBorder = useCalcLayerBorder(layerKey);
3008
+ return useMemo(
3009
+ () => calcBorder(borderWidth, borderColor),
3010
+ [borderWidth, borderColor]
3011
+ );
3012
+ };
3013
+ const useLayerLayout = (layerKey) => {
3014
+ const { manager: fragmentManager } = useContext(FragmentContext);
3015
+ const [layerModeValue] = useLayerValue(
3016
+ layerKey,
3017
+ "layerMode",
3018
+ fragmentManager
3019
+ );
3020
+ const [layerWrap] = useLayerValue(layerKey, "layerWrap", fragmentManager);
3021
+ const [layerDistribute2] = useLayerValue(
3022
+ layerKey,
3023
+ "layerDistribute",
3024
+ fragmentManager
3025
+ );
3026
+ const [layerDirectionValue] = useLayerValue(
3027
+ layerKey,
3028
+ "layerDirection",
3029
+ fragmentManager
3030
+ );
3031
+ const [layerAlign2] = useLayerValue(layerKey, "layerAlign", fragmentManager);
3032
+ const [padding] = useLayerValue(layerKey, "padding", fragmentManager);
3033
+ const [gap] = useLayerValue(layerKey, "layerGap", fragmentManager);
3034
+ const isFlex = layerModeValue === index.layerMode.flex;
3035
+ return useMemo(
3036
+ () => ({
3037
+ display: isFlex ? "flex" : null,
3038
+ gap: toPx(gap),
3039
+ flexWrap: isFlex ? layerWrap ? "wrap" : null : null,
3040
+ justifyContent: isFlex ? layerDistribute2 : null,
3041
+ flexDirection: isFlex ? layerDirectionValue === index.layerDirection.vertical ? "column" : "row" : null,
3042
+ alignItems: isFlex ? layerAlign2 : null,
3043
+ padding: isFlex ? padding : null
3044
+ }),
3045
+ [
3046
+ isFlex,
3047
+ layerWrap,
3048
+ layerDistribute2,
3049
+ layerDirectionValue,
3050
+ layerAlign2,
3051
+ padding
3052
+ ]
3053
+ );
3054
+ };
3055
+ const useLayerTextStyles = (layerKey) => {
3056
+ const { manager: fragmentManager } = useContext(FragmentContext);
3057
+ const [attributes] = useLayerValue(layerKey, "attributes", fragmentManager);
3058
+ const [color] = useLayerValue(layerKey, "attributes.color", fragmentManager);
3059
+ const cleanAttributes = omit(attributes, "_id", "_type");
3060
+ return {
3061
+ ...cleanAttributes,
3062
+ color
3063
+ };
3064
+ };
3065
+ const useLayerStyles = (layerKey) => {
3066
+ try {
3067
+ if (!layerKey) {
3068
+ throw new Error("Empty layer key");
3069
+ }
3070
+ const { manager: fragmentManager } = useContext(FragmentContext);
3071
+ const [opacity] = useLayerValue(layerKey, "opacity", fragmentManager);
3072
+ const layerSize = useLayerSize(layerKey);
3073
+ const position = useLayerPosition(layerKey);
3074
+ const display = useLayerDisplay(layerKey);
3075
+ const background = useLayerBackground(layerKey);
3076
+ const border = useLayerBorder(layerKey);
3077
+ const layout = useLayerLayout(layerKey);
3078
+ const [zIndex] = useLayerValue(layerKey, "zIndex", fragmentManager);
3079
+ const [rotate] = useLayerValue(layerKey, "rotate", fragmentManager);
3080
+ const [borderRadius] = useLayerValue(
3081
+ layerKey,
3082
+ "borderRadius",
3083
+ fragmentManager
3084
+ );
3085
+ const [whiteSpace2] = useLayerValue(layerKey, "whiteSpace", fragmentManager);
3086
+ const textStyles = useLayerTextStyles(layerKey);
3087
+ return {
3088
+ // ...(props ?? {}),
3089
+ ...border,
3090
+ ...background,
3091
+ ...position,
3092
+ opacity,
3093
+ rotate: isValue(rotate) ? `${rotate}deg` : null,
3094
+ "border-radius": borderRadius,
3095
+ "white-space": whiteSpace2,
3096
+ "z-index": zIndex !== -1 ? zIndex : null,
3097
+ ...layout,
3098
+ ...layerSize,
3099
+ ...textStyles,
3100
+ display,
3101
+ "user-select": "none"
3102
+ // ...cssOverride,
3103
+ };
3104
+ } catch (e2) {
3105
+ return {};
3106
+ }
434
3107
  };
435
3108
  const useFragmentProperties = (fragmentId) => {
436
3109
  var _a;
437
3110
  const { manager } = useFragmentManager(fragmentId);
438
3111
  const [instanceFragment] = y(manager, (_a = manager == null ? void 0 : manager.$fragment) == null ? void 0 : _a.root);
439
- return (instanceFragment == null ? void 0 : instanceFragment.properties) ?? [];
3112
+ return {
3113
+ properties: ((instanceFragment == null ? void 0 : instanceFragment.properties) ?? []).map((manager == null ? void 0 : manager.resolve) ?? noop).filter((prop) => !(prop == null ? void 0 : prop.parent)).map(keyOfEntity),
3114
+ manager
3115
+ };
440
3116
  };
441
- const useRenderTarget = () => {
442
- const globalManager = useGlobalManager();
443
- const [globalManagerGraph] = y(globalManager, globalManager == null ? void 0 : globalManager.key);
444
- const renderTargetValue = (globalManagerGraph == null ? void 0 : globalManagerGraph.renderTarget) ?? definition.renderTarget.canvas;
3117
+ const useHash = (layerKey, manager) => {
3118
+ if (!layerKey || !manager) return null;
3119
+ const layer = manager.resolve(layerKey);
3120
+ const overrideFrom = getKey(layer == null ? void 0 : layer.overrideFrom);
3121
+ return hashGenerator(overrideFrom ?? layerKey);
3122
+ };
3123
+ const useInstanceProps = (instanceProps) => {
3124
+ const isTopInstance = !(instanceProps == null ? void 0 : instanceProps.layerKey);
3125
+ const { manager: loadedManager } = useFragmentManager(
3126
+ isTopInstance ? instanceProps == null ? void 0 : instanceProps.fragmentId : null
3127
+ );
3128
+ const { manager: fragmentContextManager } = useContext(FragmentContext);
3129
+ const { properties: definitions, manager: innerFragmentManager } = useFragmentProperties(instanceProps == null ? void 0 : instanceProps.fragmentId);
3130
+ const definitionsData = S(innerFragmentManager, definitions);
3131
+ const fragmentManager = isTopInstance ? loadedManager : fragmentContextManager;
3132
+ const [instanceLayer] = y(fragmentManager, instanceProps.layerKey);
3133
+ const instanceLayerProps = (instanceLayer == null ? void 0 : instanceLayer.props) ?? {};
3134
+ const mergedProps = useMemo(() => {
3135
+ let base = instanceLayerProps;
3136
+ if (isTopInstance && isObject(base) && isObject(instanceProps == null ? void 0 : instanceProps.props)) {
3137
+ base = {
3138
+ ...base,
3139
+ ...instanceProps == null ? void 0 : instanceProps.props
3140
+ };
3141
+ }
3142
+ if (isTopInstance && fragmentManager) {
3143
+ definitionsData.forEach((definition2) => {
3144
+ var _a;
3145
+ const defId = definition2._id;
3146
+ base[defId] = ((_a = instanceProps == null ? void 0 : instanceProps.props) == null ? void 0 : _a[defId]) ?? (definition2 == null ? void 0 : definition2.defaultValue);
3147
+ });
3148
+ }
3149
+ return omit(base, "_type", "_id");
3150
+ }, [isTopInstance, fragmentManager, instanceLayerProps, definitionsData]);
3151
+ return {
3152
+ props: mergedProps,
3153
+ cssProps: getCssVariables(mergedProps)
3154
+ };
3155
+ };
3156
+ const useLayerInteractions = (layerKey, options2) => {
3157
+ const pause = (options2 == null ? void 0 : options2.pauseInteractions) ?? false;
3158
+ const { manager: globalManager } = useGlobalManager();
3159
+ const { manager: fragmentManager } = useContext(FragmentContext);
3160
+ const [interactions2] = useLayerValue(
3161
+ layerKey,
3162
+ "interactions",
3163
+ fragmentManager
3164
+ );
3165
+ const { readVariable } = useReadVariable();
3166
+ const fireEvent = useCallback(
3167
+ (eventLink) => {
3168
+ var _a, _b, _c, _d;
3169
+ const event = fragmentManager.resolve(eventLink);
3170
+ const { value: eventValue } = readVariable(eventLink);
3171
+ if ((event == null ? void 0 : event.mode) === index.eventMode.goal && (eventValue == null ? void 0 : eventValue.code)) {
3172
+ (_b = (_a = globalManager == null ? void 0 : globalManager.$metrics) == null ? void 0 : _a.reachGoal) == null ? void 0 : _b.call(_a, eventValue == null ? void 0 : eventValue.code);
3173
+ }
3174
+ if ((event == null ? void 0 : event.mode) === index.eventMode.tracker && eventValue) {
3175
+ (_d = (_c = globalManager == null ? void 0 : globalManager.$metrics) == null ? void 0 : _c.trackAdPixel) == null ? void 0 : _d.call(_c, eventValue);
3176
+ }
3177
+ if ((event == null ? void 0 : event.mode) === index.eventMode.callback && typeof eventValue === "function") {
3178
+ eventValue();
3179
+ }
3180
+ },
3181
+ [globalManager, fragmentManager]
3182
+ );
3183
+ useEffect(() => {
3184
+ if (!pause && Array.isArray(interactions2)) {
3185
+ interactions2 == null ? void 0 : interactions2.filter((el) => (el == null ? void 0 : el.on) === index.interactions.appear).map((el) => el.event).forEach(fireEvent);
3186
+ }
3187
+ }, [pause]);
3188
+ return useMemo(() => {
3189
+ if (!pause && !interactions2 || !Array.isArray(interactions2)) return {};
3190
+ if (pause) return {};
3191
+ const clickEvents = interactions2 == null ? void 0 : interactions2.filter((el) => (el == null ? void 0 : el.on) === index.interactions.click).map((el) => el.event);
3192
+ return {
3193
+ onClick: () => {
3194
+ clickEvents.map(fireEvent);
3195
+ }
3196
+ };
3197
+ }, [interactions2, fireEvent, pause]);
3198
+ };
3199
+ const useInstance = (instanceProps) => {
3200
+ const { manager: parentManager } = useContext(FragmentContext);
3201
+ const [instanceLayer] = y(parentManager, instanceProps.layerKey);
3202
+ const styles2 = useLayerStyles(instanceProps.layerKey);
3203
+ const events = useLayerInteractions(instanceProps.layerKey, instanceProps);
3204
+ const { manager: resultGlobalManager } = useGlobalManager(
3205
+ instanceProps == null ? void 0 : instanceProps.globalManager
3206
+ );
3207
+ const resultFragmentId = (instanceProps == null ? void 0 : instanceProps.fragmentId) ?? (instanceLayer == null ? void 0 : instanceLayer.fragment);
3208
+ const { properties: definitions, manager: innerFragmentManager } = useFragmentProperties(resultFragmentId);
3209
+ const { props, cssProps } = useInstanceProps(instanceProps);
3210
+ const hash = useHash(instanceProps.layerKey, innerFragmentManager);
3211
+ return {
3212
+ hash,
3213
+ styles: styles2,
3214
+ events,
3215
+ definitions,
3216
+ props,
3217
+ cssProps,
3218
+ parentManager,
3219
+ innerManager: innerFragmentManager,
3220
+ fragmentId: resultFragmentId,
3221
+ globalManager: resultGlobalManager
3222
+ };
3223
+ };
3224
+ const InstanceContext = createContext({
3225
+ layerKey: null,
3226
+ parentManager: null,
3227
+ innerManager: null,
3228
+ props: {},
3229
+ definitions: []
3230
+ });
3231
+ const useLayerChildren = (layerKey, customManager) => {
3232
+ const { manager: fragmentManager } = useContext(FragmentContext);
3233
+ const [layerData] = y(customManager ?? fragmentManager, layerKey, {
3234
+ selector: (data) => pick(data, "children")
3235
+ });
3236
+ return (layerData == null ? void 0 : layerData.children) ?? [];
3237
+ };
3238
+ const useFragmentChildren = (fragmentId) => {
3239
+ const { layerKey: instanceLayerKey } = useContext(InstanceContext);
3240
+ const { manager, fragmentLayerKey } = useFragmentManager(fragmentId);
3241
+ const children = useLayerChildren(fragmentLayerKey, manager);
3242
+ const { isDocument, renderTarget: renderTarget2 } = useRenderTarget();
3243
+ const [resizeChildren, setResizeChildren] = useState(null);
3244
+ useRef();
3245
+ const setRef = useCallback(
3246
+ (node) => {
3247
+ },
3248
+ [isDocument, instanceLayerKey, manager, children]
3249
+ );
3250
+ const primary = children == null ? void 0 : children.find(
3251
+ (breakpoint) => {
3252
+ var _a;
3253
+ return (_a = manager.resolve(breakpoint)) == null ? void 0 : _a.isPrimary;
3254
+ }
3255
+ );
3256
+ return {
3257
+ primary,
3258
+ children,
3259
+ //isBrowser && resizeChildren ? resizeChildren : children, //isStyleSheetRender ? children ?? [] : primary ? [primary] : [],
3260
+ isResize: isBrowser_default && resizeChildren,
3261
+ setRef
3262
+ };
3263
+ };
3264
+ const useStyleSheet = (manager) => {
3265
+ var _a, _b;
3266
+ const addLayerStyle = useCallback(
3267
+ (layerKey, styles2, layer) => {
3268
+ var _a2, _b2;
3269
+ if (!!(manager == null ? void 0 : manager.$styleSheet) && manager && "addStyle" in (manager == null ? void 0 : manager.$styleSheet)) {
3270
+ (_b2 = (_a2 = manager == null ? void 0 : manager.$styleSheet) == null ? void 0 : _a2.addStyle) == null ? void 0 : _b2.call(_a2, layerKey, styles2, layer);
3271
+ }
3272
+ },
3273
+ [manager]
3274
+ );
3275
+ return {
3276
+ addLayerStyle,
3277
+ mount: ((_a = manager == null ? void 0 : manager.$styleSheet) == null ? void 0 : _a.mount) ?? noop,
3278
+ unmount: ((_b = manager == null ? void 0 : manager.$styleSheet) == null ? void 0 : _b.unmount) ?? noop
3279
+ };
3280
+ };
3281
+ const useFragment = (fragmentId, globalManager) => {
3282
+ var _a, _b;
3283
+ const instanceContext = useContext(InstanceContext);
3284
+ const fragmentContext = useFragmentManager(fragmentId);
3285
+ const { isDocument } = useRenderTarget();
3286
+ const { setRef, children, isResize, primary } = useFragmentChildren(fragmentId);
3287
+ const hash = useHash(
3288
+ fragmentContext.fragmentLayerKey,
3289
+ fragmentContext.manager
3290
+ );
3291
+ const { properties: definitions } = useFragmentProperties(fragmentId);
3292
+ const scopes = useContext(ScopeContext);
3293
+ !(scopes == null ? void 0 : scopes.length);
3294
+ const { addLayerStyle, mount, unmount } = useStyleSheet(
3295
+ fragmentContext.manager
3296
+ );
3297
+ if (fragmentContext.manager) {
3298
+ addLayerStyle(
3299
+ fragmentContext.fragmentLayerKey,
3300
+ {
3301
+ width: "100%",
3302
+ height: "100%",
3303
+ "container-type": (children == null ? void 0 : children.length) === 1 ? "normal" : "inline-size"
3304
+ },
3305
+ (_a = fragmentContext.manager) == null ? void 0 : _a.resolve(fragmentContext.fragmentLayerKey),
3306
+ (_b = fragmentContext.manager) == null ? void 0 : _b.key
3307
+ );
3308
+ mount();
3309
+ }
3310
+ useEffect(() => {
3311
+ return () => {
3312
+ unmount();
3313
+ };
3314
+ }, []);
3315
+ return {
3316
+ hash,
3317
+ isDocument,
3318
+ fragmentContext,
3319
+ layerKey: fragmentContext.fragmentLayerKey,
3320
+ isTopFragment: !instanceContext.layerKey,
3321
+ setRef,
3322
+ children,
3323
+ isResize,
3324
+ definitions
3325
+ };
3326
+ };
3327
+ const useLayerLink = (layerKey) => {
3328
+ const { manager: fragmentManager } = useContext(FragmentContext);
3329
+ const [href] = useLayerValue(layerKey, "href", fragmentManager);
3330
+ const [hrefNewTab] = useLayerValue(layerKey, "hrefNewTab", fragmentManager);
3331
+ const isLink2 = isValue(href) && typeof href === "string" && !!(href == null ? void 0 : href.length);
3332
+ const linkTarget2 = hrefNewTab ? "_blank" : "";
3333
+ const linkProps = useMemo(() => {
3334
+ if (isLink2) {
3335
+ return {
3336
+ target: linkTarget2,
3337
+ href
3338
+ };
3339
+ }
3340
+ return {};
3341
+ }, [linkTarget2, href, isLink2]);
3342
+ return {
3343
+ isLink: isLink2,
3344
+ linkHref: href,
3345
+ linkTarget: hrefNewTab ? "_blank" : "",
3346
+ linkProps
3347
+ };
3348
+ };
3349
+ const useFrame = (layerKey, options2) => {
3350
+ const collectStyle = (options2 == null ? void 0 : options2.collectStyle) ?? true;
3351
+ const { manager: fragmentManager } = useContext(FragmentContext);
3352
+ const layer = fragmentManager.entityOfKey(layerKey);
3353
+ const styles2 = useLayerStyles(layerKey);
3354
+ const children = useLayerChildren(layerKey);
3355
+ const hash = useHash(layerKey, fragmentManager);
3356
+ const { addLayerStyle } = useStyleSheet(fragmentManager);
3357
+ const events = useLayerInteractions(layerKey, options2);
3358
+ const link = useLayerLink(layerKey);
3359
+ if (collectStyle) {
3360
+ addLayerStyle(layerKey, styles2, fragmentManager.resolve(layerKey));
3361
+ }
3362
+ return {
3363
+ Tag: (link == null ? void 0 : link.isLink) ? (options2 == null ? void 0 : options2.FrameTag) ?? "a" : (options2 == null ? void 0 : options2.FrameTag) ?? "div",
3364
+ type: layer == null ? void 0 : layer._type,
3365
+ hash,
3366
+ styles: {},
3367
+ //isBrowser ? pick(styles, "background") : {},
3368
+ children,
3369
+ events,
3370
+ linkProps: link.linkProps
3371
+ };
3372
+ };
3373
+ function extractVariablesFromHtml(html) {
3374
+ if (!html) return [];
3375
+ const regex = /<span(?=\s)(?=(?:[^>]*?\s)?class="[^"]*variable[^"]*")(?=(?:[^>]*?\s)?data-type="mention")(?=(?:[^>]*?\s)?data-id="([^"]+)")[^>]*>.*?<\/span>/gi;
3376
+ const mentions = [];
3377
+ let match;
3378
+ while ((match = regex.exec(html)) !== null) {
3379
+ mentions.push({
3380
+ fullMatch: match[0],
3381
+ dataId: match[1],
3382
+ variableKey: keyOfEntity({
3383
+ _type: index.nodes.Variable,
3384
+ _id: match[1]
3385
+ }),
3386
+ position: match.index
3387
+ });
3388
+ }
3389
+ return mentions;
3390
+ }
3391
+ const useTextContent = (layerKey, manager) => {
3392
+ const { manager: fragmentManager } = useContext(FragmentContext);
3393
+ const [content, , contentInfo] = useLayerValue(
3394
+ layerKey,
3395
+ "content",
3396
+ fragmentManager
3397
+ );
3398
+ const variables = extractVariablesFromHtml(content);
3399
+ const { readVariable } = useReadVariable();
3400
+ S(
3401
+ fragmentManager,
3402
+ variables.map((variable) => variable.variableKey)
3403
+ );
3404
+ let nextContent = content;
3405
+ variables.forEach((variable) => {
3406
+ nextContent = nextContent.replace(
3407
+ variable.fullMatch,
3408
+ readVariable(variable.variableKey).value
3409
+ );
3410
+ });
3411
+ return nextContent;
3412
+ };
3413
+ const useTextAttributes = (layerKey, options2) => {
3414
+ const collectStyle = (options2 == null ? void 0 : options2.collectStyle) ?? true;
3415
+ const { manager: fragmentManager } = useContext(FragmentContext);
3416
+ const styles2 = useLayerStyles(layerKey);
3417
+ const content = useTextContent(layerKey);
3418
+ const hash = useHash(layerKey, fragmentManager);
3419
+ const { addLayerStyle } = useStyleSheet(fragmentManager);
3420
+ if (collectStyle) {
3421
+ addLayerStyle(layerKey, styles2, fragmentManager.resolve(layerKey));
3422
+ }
3423
+ return {
3424
+ styles: styles2,
3425
+ hash,
3426
+ content
3427
+ };
3428
+ };
3429
+ function useMounted() {
3430
+ const [isMounted, setIsMounted] = useState(false);
3431
+ useEffect(() => {
3432
+ setIsMounted(true);
3433
+ return () => {
3434
+ setIsMounted(false);
3435
+ };
3436
+ }, []);
3437
+ return isMounted;
3438
+ }
3439
+ const allowAttributes = [
3440
+ "fontSize",
3441
+ "fontWeight",
3442
+ "color",
3443
+ "lineHeight",
3444
+ "letterSpacing",
3445
+ "textTransform",
3446
+ "textDecoration",
3447
+ "textAlign"
3448
+ ];
3449
+ const wrapTextInParagraphWithAttributes = (text2, attributes) => {
3450
+ if (text2.startsWith("<p")) return text2;
3451
+ const style = Object.entries(attributes).filter(
3452
+ ([key, value]) => isValue(value) && allowAttributes.includes(key) && typeof value === "string" && !!value.length
3453
+ ).map(([key, value]) => `${toKebabCase(key)}: ${value}`).join("; ");
3454
+ return `<p style="${style}">${text2}</p>`;
3455
+ };
3456
+ const findBreakpoint = (breakpoints = [], width) => {
3457
+ if (!(breakpoints == null ? void 0 : breakpoints.length)) return null;
3458
+ const sortBreakpoints = breakpoints.toSorted((a2, b) => (a2 == null ? void 0 : a2.width) - (b == null ? void 0 : b.width));
3459
+ return sortBreakpoints.reduce(
3460
+ (prev, curr) => width >= curr.width ? curr : prev
3461
+ );
3462
+ };
3463
+ const copyLayer = (manager, layer) => {
3464
+ const layerGraph = manager.resolve(layer);
3465
+ if (layerGraph) {
3466
+ const layer2 = createLayer(
3467
+ {
3468
+ _type: layerGraph._type,
3469
+ ...layerGraph
3470
+ },
3471
+ true
3472
+ );
3473
+ if ((layerGraph == null ? void 0 : layerGraph.children) && layer2) {
3474
+ layer2.children = ((layerGraph == null ? void 0 : layerGraph.children) ?? []).map(
3475
+ (child) => copyLayer(manager, child)
3476
+ );
3477
+ }
3478
+ return layer2;
3479
+ }
3480
+ return null;
3481
+ };
3482
+ const getStylesheetKey = (fragmentKey) => {
3483
+ const isLink2 = isLinkKey(fragmentKey);
3484
+ if (isLink2) {
3485
+ const [type, id] = fragmentKey.split(":");
3486
+ return `stylesheet-${id}`;
3487
+ }
3488
+ return `stylesheet-${fragmentKey ?? "unknown"}`;
3489
+ };
3490
+ function useInjectedStyle() {
3491
+ const { manager } = useContext(FragmentContext);
3492
+ const injectStyle = () => {
3493
+ var _a, _b;
3494
+ const styles2 = (_b = (_a = manager == null ? void 0 : manager.$styleSheet.extract()) == null ? void 0 : _a.at(0)) == null ? void 0 : _b.styles;
3495
+ if (isBrowser_default && styles2) {
3496
+ const stylesheetKey = getStylesheetKey(manager == null ? void 0 : manager.key);
3497
+ if (document.getElementById(stylesheetKey)) {
3498
+ const el = document.getElementById(stylesheetKey);
3499
+ if (el) el.remove();
3500
+ }
3501
+ const style = document.createElement("style");
3502
+ style.id = stylesheetKey;
3503
+ style.textContent = styles2.join("");
3504
+ document.head.appendChild(style);
3505
+ }
3506
+ };
445
3507
  return {
446
- renderTarget: renderTargetValue,
447
- isCanvas: renderTargetValue === definition.renderTarget.canvas,
448
- isDocument: renderTargetValue === definition.renderTarget.document,
449
- setRenderTarget: (target) => {
450
- globalManager == null ? void 0 : globalManager.setRenderTarget(target);
3508
+ injectStyle
3509
+ };
3510
+ }
3511
+ const useLayerScopes = (fragmentManager, layerKey) => {
3512
+ var _a, _b;
3513
+ const layerParents = getAllParents(fragmentManager, layerKey);
3514
+ const resultScopes = [(_b = (_a = fragmentManager == null ? void 0 : fragmentManager.$scopes) == null ? void 0 : _a.scopes) == null ? void 0 : _b.get(void 0)];
3515
+ layerParents.forEach((parent) => {
3516
+ var _a2, _b2, _c, _d;
3517
+ const parentLink = keyOfEntity(parent);
3518
+ if ((_b2 = (_a2 = fragmentManager == null ? void 0 : fragmentManager.$scopes) == null ? void 0 : _a2.scopes) == null ? void 0 : _b2.has(parentLink)) {
3519
+ resultScopes.push((_d = (_c = fragmentManager == null ? void 0 : fragmentManager.$scopes) == null ? void 0 : _c.scopes) == null ? void 0 : _d.get(parentLink));
451
3520
  }
3521
+ });
3522
+ return resultScopes;
3523
+ };
3524
+ function cssToJsStyle(cssKey) {
3525
+ return cssKey.replace(/-([a-z])/g, (_2, letter) => letter.toUpperCase());
3526
+ }
3527
+ function cssStringToJsObject(cssString) {
3528
+ const jsStyles = {};
3529
+ const declarations = cssString.split(";");
3530
+ declarations.forEach((decl) => {
3531
+ if (!decl.trim()) return;
3532
+ const [property, value] = decl.split(":").map((s2) => s2.trim());
3533
+ if (!property || !value) return;
3534
+ const jsProperty = cssToJsStyle(property);
3535
+ jsStyles[jsProperty] = value;
3536
+ });
3537
+ return jsStyles;
3538
+ }
3539
+ const useLayerCssOverride = (layerKey) => {
3540
+ const { manager: fragmentManager } = useContext(FragmentContext);
3541
+ const [cssOverride] = useLayerValue(layerKey, "cssOverride", fragmentManager);
3542
+ return isValue(cssOverride) ? cssStringToJsObject(cssOverride) : {};
3543
+ };
3544
+ const StyleSheetContext = createContext(null);
3545
+ const StyleSheetProvider = StyleSheetContext.Provider;
3546
+ const useArea = (options2) => {
3547
+ const { manager: resultGlobalManager, queryArea } = useGlobalManager(
3548
+ options2 == null ? void 0 : options2.globalManager
3549
+ );
3550
+ const [areaData, setAreaData] = useState(queryArea(options2.areaCode));
3551
+ useEffect(() => {
3552
+ (async () => {
3553
+ const response = await queryArea(options2.areaCode);
3554
+ if (response) {
3555
+ setAreaData(response);
3556
+ }
3557
+ })();
3558
+ }, []);
3559
+ return {
3560
+ ...areaData,
3561
+ globalManager: resultGlobalManager
452
3562
  };
453
3563
  };
454
- const Fragment = createReactComponent(Fragment$1);
455
- const Instance = createReactComponent(Instance$1);
3564
+ const useCollection = (layerKey, options2) => {
3565
+ var _a;
3566
+ const { manager: fragmentManager } = useContext(FragmentContext);
3567
+ const frame = useFrame(layerKey, options2);
3568
+ const children = useLayerChildren(layerKey, fragmentManager);
3569
+ const [collectionLayer] = y(fragmentManager, layerKey, {
3570
+ selector: (graph) => pick(graph, "source")
3571
+ });
3572
+ const source = collectionLayer == null ? void 0 : collectionLayer.source;
3573
+ const sourceDefinition = (_a = fragmentManager == null ? void 0 : fragmentManager.resolve(source)) == null ? void 0 : _a.definition;
3574
+ const [sourceValue] = useLayerValue(layerKey, "source", fragmentManager);
3575
+ return {
3576
+ source,
3577
+ sourceDefinition,
3578
+ sourceValue: sourceValue ?? [],
3579
+ fragmentManager,
3580
+ children,
3581
+ ...frame
3582
+ };
3583
+ };
3584
+ const text = "_text_1tdzv_1";
3585
+ const styles = {
3586
+ text
3587
+ };
3588
+ const Text = ({
3589
+ layerKey,
3590
+ Tag = "div",
3591
+ collectStyle,
3592
+ ...restProps
3593
+ }) => {
3594
+ const { hash, content } = useTextAttributes(layerKey, { collectStyle });
3595
+ return /* @__PURE__ */ jsx(Tag, { className: hash, "data-key": layerKey, ...restProps, children: /* @__PURE__ */ jsx(
3596
+ "div",
3597
+ {
3598
+ className: styles.text,
3599
+ dangerouslySetInnerHTML: { __html: content }
3600
+ }
3601
+ ) });
3602
+ };
3603
+ const Scope = ({
3604
+ value,
3605
+ children,
3606
+ fragmentManager,
3607
+ layerKey
3608
+ }) => {
3609
+ var _a, _b;
3610
+ const currentScope = useContext(ScopeContext) ?? [];
3611
+ const nextScope = [...currentScope, value];
3612
+ (_b = (_a = fragmentManager == null ? void 0 : fragmentManager.$scopes) == null ? void 0 : _a.registerScope) == null ? void 0 : _b.call(_a, layerKey, value);
3613
+ return /* @__PURE__ */ jsx(ScopeContext.Provider, { value: nextScope, children });
3614
+ };
3615
+ const Collection = ({
3616
+ layerKey,
3617
+ styles: inputStyles,
3618
+ ...restProps
3619
+ }) => {
3620
+ var _a;
3621
+ const {
3622
+ fragmentManager,
3623
+ styles: styles2,
3624
+ sourceDefinition,
3625
+ hash,
3626
+ source,
3627
+ children,
3628
+ sourceValue
3629
+ } = useCollection(layerKey, restProps);
3630
+ const FrameTag = (restProps == null ? void 0 : restProps.FrameTag) ?? "div";
3631
+ const FrameElement = (restProps == null ? void 0 : restProps.FrameElement) ?? Frame;
3632
+ const resultStyles = inputStyles ?? styles2;
3633
+ return /* @__PURE__ */ jsx(
3634
+ Scope,
3635
+ {
3636
+ fragmentManager,
3637
+ layerKey,
3638
+ value: {
3639
+ type: definition.scopeTypes.CollectionScope,
3640
+ source,
3641
+ manager: fragmentManager
3642
+ },
3643
+ children: /* @__PURE__ */ jsx(
3644
+ FrameTag,
3645
+ {
3646
+ className: hash,
3647
+ "data-key": layerKey,
3648
+ style: resultStyles,
3649
+ ...restProps,
3650
+ children: (_a = sourceValue == null ? void 0 : sourceValue.map) == null ? void 0 : _a.call(sourceValue, (collectionItem, index2) => /* @__PURE__ */ jsx(
3651
+ Scope,
3652
+ {
3653
+ fragmentManager,
3654
+ layerKey: `${layerKey}.${index2}`,
3655
+ value: {
3656
+ type: definition.scopeTypes.CollectionItemScope,
3657
+ source,
3658
+ sourceDefinition,
3659
+ value: collectionItem,
3660
+ manager: fragmentManager
3661
+ },
3662
+ children: children == null ? void 0 : children.map((child) => /* @__PURE__ */ jsx(
3663
+ "div",
3664
+ {
3665
+ style: {
3666
+ display: "contents",
3667
+ ...getCssVariables(collectionItem ?? {})
3668
+ },
3669
+ children: /* @__PURE__ */ jsx(FrameElement, { ...restProps, layerKey: child })
3670
+ },
3671
+ child
3672
+ ))
3673
+ }
3674
+ ))
3675
+ }
3676
+ )
3677
+ }
3678
+ );
3679
+ };
3680
+ const Frame = ({
3681
+ layerKey,
3682
+ styles: inputStyles,
3683
+ hidden,
3684
+ interactive,
3685
+ ...restProps
3686
+ }) => {
3687
+ const { styles: styles2, hash, children, type, events, linkProps, Tag } = useFrame(
3688
+ layerKey,
3689
+ {
3690
+ ...restProps,
3691
+ pauseInteractions: !interactive
3692
+ }
3693
+ );
3694
+ const resultStyles = inputStyles ?? styles2;
3695
+ const isMounted = useMounted();
3696
+ if (isMounted && hidden) {
3697
+ return /* @__PURE__ */ jsx("div", {});
3698
+ }
3699
+ if (type === definition.nodes.Collection) {
3700
+ const Tag2 = (restProps == null ? void 0 : restProps.CollectionElement) ?? Collection;
3701
+ return /* @__PURE__ */ jsx(Tag2, { layerKey, ...restProps });
3702
+ }
3703
+ if (type === definition.nodes.Text) {
3704
+ const Tag2 = (restProps == null ? void 0 : restProps.TextElement) ?? Text;
3705
+ return /* @__PURE__ */ jsx(Tag2, { layerKey, ...restProps });
3706
+ }
3707
+ if (type === definition.nodes.Instance) {
3708
+ const Tag2 = (restProps == null ? void 0 : restProps.InstanceElement) ?? Instance;
3709
+ return /* @__PURE__ */ jsx(Tag2, { layerKey, ...restProps });
3710
+ }
3711
+ const FrameElement = (restProps == null ? void 0 : restProps.FrameElement) ?? Frame;
3712
+ return /* @__PURE__ */ jsx(
3713
+ Tag,
3714
+ {
3715
+ className: hash,
3716
+ "data-key": layerKey,
3717
+ style: {
3718
+ ...resultStyles,
3719
+ display: hidden ? "none" : resultStyles.display
3720
+ },
3721
+ ...events,
3722
+ ...linkProps,
3723
+ ...restProps,
3724
+ children: children.map((childLink) => /* @__PURE__ */ jsx(FrameElement, { layerKey: childLink, ...restProps }, childLink))
3725
+ }
3726
+ );
3727
+ };
3728
+ const FragmentInternal = ({
3729
+ fragmentId,
3730
+ globalManager,
3731
+ interactive,
3732
+ collectStyle,
3733
+ FrameElement = Frame
3734
+ }) => {
3735
+ const {
3736
+ children,
3737
+ fragmentContext,
3738
+ hash,
3739
+ isResize,
3740
+ isTopFragment,
3741
+ definitions,
3742
+ layerKey
3743
+ } = useFragment(fragmentId);
3744
+ if (!fragmentContext.manager) return null;
3745
+ return (
3746
+ // <Scope
3747
+ // fragmentManager={fragmentContext.manager}
3748
+ // layerKey={layerKey}
3749
+ // value={{
3750
+ // type: definition.scopeTypes.FragmentScope,
3751
+ // manager: fragmentContext.manager,
3752
+ // definitions,
3753
+ // }}
3754
+ // >
3755
+ /* @__PURE__ */ jsx("div", { "data-key": layerKey, className: hash, children: children.map((childLink) => {
3756
+ var _a;
3757
+ const childLayer = (_a = fragmentContext.manager) == null ? void 0 : _a.resolve(childLink);
3758
+ const isPrimary = (childLayer == null ? void 0 : childLayer.isPrimary) ?? false;
3759
+ return /* @__PURE__ */ jsx(
3760
+ FrameElement,
3761
+ {
3762
+ layerKey: childLink,
3763
+ interactive,
3764
+ collectStyle,
3765
+ hidden: !isResize && !isPrimary && !isTopFragment,
3766
+ style: { display: isPrimary ? null : "none" }
3767
+ },
3768
+ childLink
3769
+ );
3770
+ }) })
3771
+ );
3772
+ };
3773
+ const Fragment = (props) => {
3774
+ const currentGlobalManager = useContext(GlobalManager);
3775
+ const { manager: resultGlobalManager } = useGlobalManager(
3776
+ props.globalManager
3777
+ );
3778
+ const { manager } = useFragmentManager(props.fragmentId, resultGlobalManager);
3779
+ const Base = /* @__PURE__ */ jsx(FragmentContext.Provider, { value: { manager }, children: /* @__PURE__ */ jsx(FragmentInternal, { ...props }) });
3780
+ if (!currentGlobalManager) {
3781
+ return /* @__PURE__ */ jsx(GlobalManager.Provider, { value: resultGlobalManager, children: Base });
3782
+ }
3783
+ return Base;
3784
+ };
3785
+ const InstanceInitial = ({
3786
+ Tag: inputTag,
3787
+ style = {},
3788
+ interactive = true,
3789
+ FrameElement,
3790
+ ...instanceProps
3791
+ }) => {
3792
+ var _a, _b, _c;
3793
+ const ssr = ((_a = instanceProps == null ? void 0 : instanceProps.options) == null ? void 0 : _a.ssr) ?? true;
3794
+ const link = useLayerLink(instanceProps.layerKey);
3795
+ const Tag = (link == null ? void 0 : link.isLink) ? inputTag ?? "a" : inputTag ?? "div";
3796
+ const {
3797
+ fragmentId,
3798
+ cssProps,
3799
+ parentManager,
3800
+ events,
3801
+ props,
3802
+ hash,
3803
+ innerManager,
3804
+ definitions,
3805
+ globalManager
3806
+ } = useInstance({
3807
+ ...instanceProps,
3808
+ pauseInteractions: !interactive
3809
+ });
3810
+ if (ssr) {
3811
+ (_c = (_b = globalManager == null ? void 0 : globalManager.$load) == null ? void 0 : _b.loadFragment) == null ? void 0 : _c.call(_b, fragmentId, { suspense: true });
3812
+ }
3813
+ return /* @__PURE__ */ jsx(
3814
+ Scope,
3815
+ {
3816
+ fragmentManager: innerManager,
3817
+ layerKey: instanceProps.layerKey,
3818
+ value: {
3819
+ type: definition.scopeTypes.InstanceScope,
3820
+ props,
3821
+ definitions,
3822
+ fragmentId,
3823
+ documentManager: innerManager,
3824
+ layerKey: instanceProps.layerKey
3825
+ },
3826
+ children: /* @__PURE__ */ jsx(
3827
+ InstanceContext.Provider,
3828
+ {
3829
+ value: {
3830
+ layerKey: instanceProps.layerKey,
3831
+ definitions,
3832
+ innerManager,
3833
+ parentManager,
3834
+ props
3835
+ },
3836
+ children: parentManager ? /* @__PURE__ */ jsx(
3837
+ Tag,
3838
+ {
3839
+ className: hash,
3840
+ "data-key": instanceProps.layerKey,
3841
+ style: { ...style, ...cssProps },
3842
+ ...link.linkProps,
3843
+ ...events,
3844
+ children: /* @__PURE__ */ jsx(
3845
+ Fragment,
3846
+ {
3847
+ fragmentId,
3848
+ globalManager,
3849
+ FrameElement,
3850
+ interactive
3851
+ }
3852
+ )
3853
+ }
3854
+ ) : /* @__PURE__ */ jsx(Tag, { style: { ...style, ...cssProps }, ...link.linkProps, children: /* @__PURE__ */ jsx(
3855
+ Fragment,
3856
+ {
3857
+ fragmentId,
3858
+ globalManager,
3859
+ FrameElement,
3860
+ interactive
3861
+ }
3862
+ ) })
3863
+ }
3864
+ )
3865
+ }
3866
+ );
3867
+ };
3868
+ const Instance = (props) => {
3869
+ return "globalManager" in props ? /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx("h1", { children: "Test" }), children: /* @__PURE__ */ jsx(GlobalManager, { value: props.globalManager, children: /* @__PURE__ */ jsx(InstanceInitial, { ...props }) }) }) : /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx("h1", { children: "Test" }), children: /* @__PURE__ */ jsx(InstanceInitial, { ...props }) });
3870
+ };
3871
+ const isBrowser = typeof window !== "undefined";
3872
+ const AreaInitial = (areaProps) => {
3873
+ var _a, _b, _c;
3874
+ const { manager: globalManager } = useGlobalManager(areaProps == null ? void 0 : areaProps.globalManager);
3875
+ const ssr = ((_a = areaProps == null ? void 0 : areaProps.options) == null ? void 0 : _a.ssr) ?? true;
3876
+ if (isBrowser || ssr) {
3877
+ (_c = (_b = globalManager == null ? void 0 : globalManager.$load) == null ? void 0 : _b.loadArea) == null ? void 0 : _c.call(_b, areaProps.areaCode, {
3878
+ suspense: true
3879
+ });
3880
+ }
3881
+ const areaData = useArea(areaProps);
3882
+ if (!areaData) return null;
3883
+ return /* @__PURE__ */ jsx(Instance, { fragmentId: areaData.fragmentId, props: areaData == null ? void 0 : areaData.props });
3884
+ };
3885
+ const Area = (props) => {
3886
+ return "globalManager" in props ? /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(GlobalManager, { value: props.globalManager, children: /* @__PURE__ */ jsx(AreaInitial, { ...props }) }) }) : /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(AreaInitial, { ...props }) });
3887
+ };
456
3888
  export {
3889
+ Area,
3890
+ Collection,
457
3891
  Fragment,
3892
+ FragmentContext,
3893
+ Frame,
458
3894
  GlobalManager,
459
3895
  Instance,
3896
+ InstanceContext,
3897
+ RenderTargetContext,
3898
+ RenderTargetProvider,
3899
+ Scope,
3900
+ ScopeContext,
3901
+ StyleSheetContext,
3902
+ StyleSheetProvider,
3903
+ Text,
3904
+ appendChildren,
3905
+ J as cloneElement,
3906
+ cloneLayer,
3907
+ collectStyles,
3908
+ copyLayer,
3909
+ _ as createElement,
3910
+ createLayer,
3911
+ declareFragmentProperty,
3912
+ duplicateLayer,
3913
+ findBreakpoint,
3914
+ getAllParents,
3915
+ getCssVariables,
3916
+ getNormalizeLayer,
3917
+ getOverrider,
3918
+ getParent,
3919
+ _ as h,
3920
+ G as hydrate,
3921
+ insertChildren,
3922
+ isInheritField,
3923
+ isPartOfPrimary,
3924
+ isRootLayer,
3925
+ isTopLevel,
3926
+ layerFieldSetter,
3927
+ makeSnapshot,
3928
+ moveChildren,
3929
+ processOptionalSize,
3930
+ removeChildren,
3931
+ E as render,
3932
+ useArea,
3933
+ useCalcLayerBorder,
3934
+ useCollection,
3935
+ useFragment,
3936
+ useFragmentChildren,
460
3937
  useFragmentManager,
461
3938
  useFragmentProperties,
3939
+ useFrame,
462
3940
  useGlobalManager,
463
- useRenderTarget
3941
+ useInjectedStyle,
3942
+ useInstance,
3943
+ useLayerChildren,
3944
+ useLayerCssOverride,
3945
+ useLayerDisplay,
3946
+ useLayerLayout,
3947
+ useLayerLink,
3948
+ useLayerScopes,
3949
+ useLayerSizeValue,
3950
+ useLayerTextStyles,
3951
+ useLayerValue,
3952
+ useMounted,
3953
+ useNormalizeLayer,
3954
+ useReadVariable,
3955
+ useRenderTarget,
3956
+ useTextAttributes,
3957
+ useTextContent,
3958
+ wrapTextInParagraphWithAttributes
464
3959
  };