@fragmentsx/client-core 0.0.1

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.
Files changed (39) hide show
  1. package/dist/fragmentsClient.d.ts +7 -0
  2. package/dist/fragmentsClient.d.ts.map +1 -0
  3. package/dist/index.cjs.js +1862 -0
  4. package/dist/index.d.ts +2 -0
  5. package/dist/index.d.ts.map +1 -0
  6. package/dist/index.es.js +1862 -0
  7. package/dist/plugins/fetch/beacon.d.ts +4 -0
  8. package/dist/plugins/fetch/beacon.d.ts.map +1 -0
  9. package/dist/plugins/fetch/emptyFragment.d.ts +50 -0
  10. package/dist/plugins/fetch/emptyFragment.d.ts.map +1 -0
  11. package/dist/plugins/fetch/fetcher.d.ts +6 -0
  12. package/dist/plugins/fetch/fetcher.d.ts.map +1 -0
  13. package/dist/plugins/fetch/index.d.ts +3 -0
  14. package/dist/plugins/fetch/index.d.ts.map +1 -0
  15. package/dist/plugins/fetch/queries/FragmentQuery.d.ts +2 -0
  16. package/dist/plugins/fetch/queries/FragmentQuery.d.ts.map +1 -0
  17. package/dist/plugins/fetch/queries/LandingQuery.d.ts +2 -0
  18. package/dist/plugins/fetch/queries/LandingQuery.d.ts.map +1 -0
  19. package/dist/plugins/fragments/index.d.ts +3 -0
  20. package/dist/plugins/fragments/index.d.ts.map +1 -0
  21. package/dist/plugins/metrics/index.d.ts +3 -0
  22. package/dist/plugins/metrics/index.d.ts.map +1 -0
  23. package/dist/plugins/metrics/queries/addClientMetric.d.ts +2 -0
  24. package/dist/plugins/metrics/queries/addClientMetric.d.ts.map +1 -0
  25. package/dist/plugins/styleSheet/buildCssBlock.d.ts +2 -0
  26. package/dist/plugins/styleSheet/buildCssBlock.d.ts.map +1 -0
  27. package/dist/plugins/styleSheet/compareRules.d.ts +4 -0
  28. package/dist/plugins/styleSheet/compareRules.d.ts.map +1 -0
  29. package/dist/plugins/styleSheet/findGroups.d.ts +8 -0
  30. package/dist/plugins/styleSheet/findGroups.d.ts.map +1 -0
  31. package/dist/plugins/styleSheet/getAllChildren.d.ts +3 -0
  32. package/dist/plugins/styleSheet/getAllChildren.d.ts.map +1 -0
  33. package/dist/plugins/styleSheet/index.d.ts +3 -0
  34. package/dist/plugins/styleSheet/index.d.ts.map +1 -0
  35. package/dist/plugins/styleSheet/makeCss.d.ts +6 -0
  36. package/dist/plugins/styleSheet/makeCss.d.ts.map +1 -0
  37. package/dist/plugins/styleSheet/toCSS.d.ts +2 -0
  38. package/dist/plugins/styleSheet/toCSS.d.ts.map +1 -0
  39. package/package.json +38 -0
@@ -0,0 +1,1862 @@
1
+ var t = (e) => !e && e == null, s = (e) => !t(e), y = (e) => typeof e == "object" && !Array.isArray(e) && s(e), a = (e) => typeof Node == "object" ? e instanceof Node : e && typeof e == "object" && typeof e.nodeType == "number" && typeof e.nodeName == "string", p = (e) => typeof e == "string" || n(e), n = (e) => typeof e == "object" && typeof e._type == "string", r = (e) => typeof e == "string" && e.split(":").length >= 2, i = (e) => typeof e != "object" && typeof e != "function" || e === null, b = (e) => typeof e == "string" ? /<\/?[a-z][\s\S]*>/i.test(e) : false;
2
+ var G = (t2) => r(t2), te = (t2) => p(t2), ne = (t2) => n(t2), S = (t2) => y(t2), re = (t2, s2) => {
3
+ if (t2 === s2) return true;
4
+ if (Array.isArray(t2) && Array.isArray(s2)) return t2.length === s2.length && t2.every((a2, h) => s2[h] === a2);
5
+ if (!S(t2) || !S(s2)) return false;
6
+ let p2 = Object.keys(t2), c = Object.keys(s2);
7
+ if (p2.length !== c.length) return false;
8
+ for (let a2 of p2) {
9
+ if (!c.includes(a2)) return false;
10
+ let h = t2[a2], l = s2[a2];
11
+ if (i(h) && i(l) && h !== l) return false;
12
+ }
13
+ return true;
14
+ }, W = (t2, s2) => {
15
+ if (t2 === s2) return true;
16
+ if (Array.isArray(t2) && Array.isArray(s2)) return t2.length === s2.length && t2.every((a2, h) => W(a2, s2[h]));
17
+ if (!S(s2) || !S(t2)) return t2 === s2;
18
+ let p2 = Object.keys(t2), c = Object.keys(s2);
19
+ if (p2.length !== c.length) return false;
20
+ for (let a2 of p2) if (!c.includes(a2) || !W(t2[a2], s2[a2])) return false;
21
+ return true;
22
+ };
23
+ var z = (...t2) => Array.from(new Set(t2)), se = (...t2) => t2.filter((s2, p2, c) => r(s2) ? c.indexOf(s2) === p2 : true);
24
+ var I = (t2) => t2 && t2.split(".").length > 1, Y = (t2, s2) => {
25
+ if (!t2 || !s2) return false;
26
+ if (typeof t2 != "string" || typeof s2 != "string") return null;
27
+ let [p2, c] = t2.split(":"), [a2, h] = s2.split(":");
28
+ return p2 !== a2 ? false : c.startsWith(h);
29
+ }, ie = (t2) => G(t2) && I(t2) ? t2.split(".")[0] : t2;
30
+ var oe = () => {
31
+ let t2 = /* @__PURE__ */ new Map(), s2 = /* @__PURE__ */ new Map(), p2 = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), a2 = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Set([]), O = (n2, g) => {
32
+ var _a;
33
+ c.set(n2, z(...c.get(n2) || [], g)), a2.set(g, z(...a2.get(g) ?? [], n2)), M(n2, ((_a = c.get(n2)) == null ? void 0 : _a.length) || 0);
34
+ }, q = (n2, g) => {
35
+ var _a;
36
+ c.set(g, (c.get(g) || []).filter((k) => k !== n2)), a2.set(n2, (a2.get(n2) ?? []).filter((k) => k !== g)), M(g, ((_a = c.get(g)) == null ? void 0 : _a.length) || 0);
37
+ }, T = (n2, g = []) => {
38
+ let k = c.get(n2) || [];
39
+ g.push(...k);
40
+ let x = k.map((E) => T(E, g)).flat();
41
+ return g.push(...x), Array.from(new Set(g).values());
42
+ }, V = (n2) => {
43
+ M(n2, 0), B();
44
+ }, P = (n2) => n2 ? p2.get(n2) : null, R = (n2, g, k) => {
45
+ var _a;
46
+ if (typeof n2 == "string") {
47
+ p2.set(n2, g);
48
+ let [x] = n2.split(":");
49
+ I(n2) || (s2.has(x) ? (_a = s2.get(x)) == null ? void 0 : _a.add(n2) : s2.set(x, /* @__PURE__ */ new Set([n2])));
50
+ }
51
+ k && n2 && n2 !== k && O(n2, k);
52
+ }, _ = (n2) => n2 ? p2.has(n2) : false, M = (n2, g) => {
53
+ if (Array.isArray(n2)) n2.forEach((k, x) => M(k, x));
54
+ else {
55
+ let k = h.get(n2);
56
+ h.set(n2, g), g ? !k && g && l.delete(n2) : l.add(n2);
57
+ }
58
+ }, $ = () => Array.from(p2.entries()), j = (n2) => h.get(n2) ?? 0, B = () => {
59
+ var _a, _b;
60
+ for (let n2 of l.keys()) {
61
+ if (j(n2) > 0) continue;
62
+ let k = p2.get(n2);
63
+ l.delete(n2), p2.delete(n2), h.delete(n2);
64
+ let x = c.get(n2) ?? [], E = a2.get(n2) ?? [];
65
+ x.forEach((A) => {
66
+ var _a2, _b2;
67
+ a2.set(A, ((_b2 = (_a2 = a2.get(A)) == null ? void 0 : _a2.filter) == null ? void 0 : _b2.call(_a2, (U) => U !== n2)) ?? []);
68
+ }), E.forEach((A) => {
69
+ M(A, j(A) - 1);
70
+ });
71
+ let [C] = n2.split(":");
72
+ I(n2) || ((_a = s2.get(C)) == null ? void 0 : _a.delete(n2), ((_b = s2.get(C)) == null ? void 0 : _b.size) || s2.delete(C)), c.delete(n2), (t2.get("onRemoveLink") ?? []).forEach((A) => A(n2, k ?? null));
73
+ }
74
+ };
75
+ return { readLink: P, writeLink: R, hasLink: _, getLinkEntries: $, parentRefs: c, childrenRefs: a2, addRefs: O, removeRefs: q, getChildren: (n2) => a2.get(n2), getParents: (n2) => c.get(n2), getLinkedRefs: T, invalidate: V, links: p2, types: s2, refCount: h, runGarbageCollector: B, onRemoveLink: (n2) => t2.set("onRemoveLink", [...(t2 == null ? void 0 : t2.get("onRemoveLink")) ?? [], n2]) };
76
+ };
77
+ var J = (...t2) => {
78
+ var _a;
79
+ return (_a = t2 == null ? void 0 : t2.filter(Boolean)) == null ? void 0 : _a.join(".");
80
+ };
81
+ var ae = process.env.NODE_ENV !== "production";
82
+ var ce = (t2 = []) => {
83
+ let s2 = [], p2 = (a2) => {
84
+ s2.push(a2);
85
+ }, c = (a2) => s2.reduce((h, l) => l(h) ?? h, a2);
86
+ return t2.forEach(p2), { use: p2, runPlugins: c };
87
+ };
88
+ var le = (t2) => t2 && S(t2) ? ["_id", "_type", "key", "mutate", "resolve"].every((p2) => p2 in t2) : false;
89
+ var ue = () => {
90
+ let t2 = /* @__PURE__ */ new Set();
91
+ return { debug: (c) => {
92
+ t2.forEach((a2) => {
93
+ a2({ ...c, timestamp: Date.now() });
94
+ });
95
+ }, onDebugEvent: (c) => {
96
+ t2.add(c);
97
+ } };
98
+ };
99
+ var pe = () => Math.random().toString(16).slice(2);
100
+ var De = 0, Se = 100, Ge = "State", fe = "$EACH:ROOT$", it = (t2) => {
101
+ let s$1 = (t2 == null ? void 0 : t2._id) ?? `${De++}`, p2 = (t2 == null ? void 0 : t2._type) ?? Ge, c = (t2 == null ? void 0 : t2.keys) ?? {}, a2 = `${p2}:${s$1}`, h = [le, ...(t2 == null ? void 0 : t2.skip) ?? []], l = oe(), O = ue(), q = ce(t2 == null ? void 0 : t2.plugins), T = /* @__PURE__ */ new Map(), V = 0, P = (e) => h.some((r2) => r2(e)), R = (e, r2) => {
102
+ let i2 = (r2 == null ? void 0 : r2.deep) ?? false, o = (r2 == null ? void 0 : r2.safe) ?? false, f = (r2 == null ? void 0 : r2.keepLinks) ?? false, { selector: m, ...d } = r2 || {}, y2 = s(e) ? E(e) : null;
103
+ O.debug({ type: "resolve", entity: e, options: r2 });
104
+ let u = y2 ? l.readLink(y2) : null;
105
+ return P(u) ? u : ((S(u) || Array.isArray(u)) && (u = Object.entries(u).reduce((L, [w, v]) => {
106
+ let K = v;
107
+ return P(K) || (Array.isArray(v) ? (K = v.map((D) => P(D) ? D : G(D) && !o && !l.hasLink(D) ? null : Y(D, y2) && !f || i2 ? _(D, d) : D), o || (K = K.filter(s))) : G(v) && !o && !l.hasLink(v) ? K = null : (Y(E(v), y2) && !f || i2) && (K = _(v, d))), L[w] = K, L;
108
+ }, {})), u ? m ? m({ ...u }) : { ...u } : o ? e : null);
109
+ }, _ = (e, r2) => R(e, r2) ?? e, M = (e) => {
110
+ let r2 = E(e);
111
+ r2 && (l.getChildren(r2) || []).forEach((o) => {
112
+ I(o) || l.removeRefs(r2, o);
113
+ });
114
+ }, $ = (e, r2, i$1) => {
115
+ var _a, _b, _c, _d;
116
+ if ((!e || i(e)) && !G(e) || P(e)) return e;
117
+ let o = te(e) ? E(e) : e;
118
+ if (G(o)) {
119
+ let y2 = ie(r2) ?? "", u = ((_a = i$1 == null ? void 0 : i$1.internal) == null ? void 0 : _a.visitors.get(y2)) ?? [], L = ((_b = i$1 == null ? void 0 : i$1.internal) == null ? void 0 : _b.visitors.get(o)) ?? [];
120
+ if (u.includes(o) || o === y2) return null;
121
+ (_d = (_c = i$1 == null ? void 0 : i$1.internal) == null ? void 0 : _c.visitors) == null ? void 0 : _d.set(o, [...L, y2]);
122
+ }
123
+ if (Array.isArray(e)) return e.map((y2) => {
124
+ let u = r2 ? J(r2, `${pe()}`) : void 0;
125
+ return $(y2, u, i$1);
126
+ });
127
+ let m = (G(e) ? e : ne(e) ? E(e) : null) ?? r2;
128
+ return ((i$1 == null ? void 0 : i$1.overrideMutateMethod) || j)(m, e, i$1);
129
+ }, j = (e, ...r2) => {
130
+ let { graphKey: i2, options: o, data: f } = A(e, ...r2);
131
+ O.debug({ type: "beforeMutate", entity: i2, data: f, options: o });
132
+ let m = G(f) ? C(f) : f, d = i2 ?? a2, y2 = I == null ? void 0 : I(d), u = o == null ? void 0 : o.parent, L = R(d ?? ""), w = (o == null ? void 0 : o.internal) || { hasChange: false, visitors: /* @__PURE__ */ new Map([]) }, v = { ...m, ...C(d) }, K = !(o == null ? void 0 : o.parent), D = (o == null ? void 0 : o.replace) ? typeof (o == null ? void 0 : o.replace) == "function" ? o.replace(v) : (o == null ? void 0 : o.replace) === "deep" ? true : K || y2 : false;
133
+ if (P(m)) return l.writeLink(d, m, u), d;
134
+ !D && S(L) && S(v) && (v = { ...L, ...v }), D && M(d);
135
+ let Q = Object.entries(v).reduce((X, [N, de]) => {
136
+ let Z = J(d, N), b2 = de, F = L == null ? void 0 : L[N], he = S(m) && N in m;
137
+ P(b2) || (!D && he && Array.isArray(b2) && Array.isArray(F) && (b2 = [...F, ...b2]), (S(b2) || Array.isArray(b2) || G(b2)) && (b2 = $(b2, Z, { ...o, parent: d, internal: w })), Array.isArray(b2) && (o == null ? void 0 : o.dedup) !== false && (b2 = se(...b2)));
138
+ let me = re(F, Z === b2 ? _(b2) : b2);
139
+ return w.hasChange = w.hasChange || !me, !D && G(F) && F !== b2 && l.removeRefs(d, F), X[N] = b2, X;
140
+ }, {});
141
+ return l.writeLink(d, Q, u), u || l.runGarbageCollector(), (w.hasChange || D) && n2(d, L), O.debug({ type: "afterMutate", entity: i2, data: f, nextData: Q, options: o, hasChange: w.hasChange }), d;
142
+ }, B = (e) => {
143
+ let r2 = E(e);
144
+ if (O.debug({ type: "invalidate", entity: r2 }), r2) {
145
+ let i2 = l.getParents(r2) || [];
146
+ l.invalidate(r2), i2.forEach((o) => {
147
+ let f = l.readLink(o), m = R(o, { safe: false, keepLinks: true });
148
+ l.writeLink(o, m), n2(o, f);
149
+ });
150
+ }
151
+ }, n2 = (e, r2) => {
152
+ if (V > Se) throw new Error("Too deep notify.");
153
+ let i2 = E(e);
154
+ if (O.debug({ type: "notify", entity: i2 }), i2) {
155
+ V++;
156
+ let o = [...T.get(i2) || [], ...T.get(fe) || []], f = l.getChildren(i2) || [], m = R(i2), d = (y2) => {
157
+ let u = m && (y2 == null ? void 0 : y2(m)), L = r2 && (y2 == null ? void 0 : y2(r2));
158
+ return { next: u, prev: L, hasChange: !W(u, L) };
159
+ };
160
+ o.forEach(({ callback: y2, selector: u }) => {
161
+ if (u) {
162
+ let { next: L, prev: w, hasChange: v } = d(u);
163
+ v && y2(L, w);
164
+ } else y2(m, r2);
165
+ }), f.forEach((y2) => n2(y2, r2));
166
+ }
167
+ V = 0;
168
+ }, g = (...e) => {
169
+ let r2 = typeof e[0] == "function" ? fe : e[0], i2 = typeof e[0] == "function" ? e[0] : e[1], o = typeof e[0] == "function" ? e[1] : e[2], f = E(r2), m = o == null ? void 0 : o.selector;
170
+ f && (T.has(f) ? T.set(f, [...Array.from(T.get(f) || []), { callback: i2, selector: m }]) : T.set(f, [{ callback: i2, selector: m }]), l.onRemoveLink((y2, u) => {
171
+ y2 === f && n2(f, u);
172
+ }));
173
+ let d = () => {
174
+ if (f) {
175
+ let y2 = (T.get(f) || []).findIndex((u) => u.callback === i2);
176
+ if (y2 !== -1) {
177
+ let u = T.get(f) || [];
178
+ u.splice(y2, 1), T.set(f, u);
179
+ }
180
+ }
181
+ };
182
+ return (o == null ? void 0 : o.signal) && o.signal.addEventListener("abort", d, { once: true }), d;
183
+ }, k = (e) => [...l.types.get(e) ?? []], x = (e) => {
184
+ let r2 = (typeof e == "string" ? e : E(e)) || "";
185
+ return (l.getParents(r2) ?? []).map((o) => R(o));
186
+ }, E = (e) => {
187
+ var _a;
188
+ if (typeof e == "string") return C(e) ? e : null;
189
+ if (!(e == null ? void 0 : e._type)) return null;
190
+ let r2 = null;
191
+ return e._type in c ? r2 = ((_a = c[e._type]) == null ? void 0 : _a.call(c, e)) ?? null : (s(e.id) || s(e._id)) && (r2 = `${e.id ?? e._id}`), r2 && `${e._type}:${r2}`;
192
+ }, C = (e) => {
193
+ if (S(e) && (e == null ? void 0 : e._type) && E(e)) return e;
194
+ if (!e || typeof e != "string") return null;
195
+ let [r2, ...i2] = e.split(":");
196
+ return !r2 || i2.length < 1 ? null : { _type: r2, _id: i2.join(":") };
197
+ }, A = (e, ...r2) => {
198
+ let i2 = typeof e == "string" ? r2[0] : e;
199
+ return typeof i2 == "function" ? i2 = i2(R(e)) : G(i2) && (i2 = C(i2)), { graphKey: typeof e == "string" ? e : E(e), options: typeof e == "string" ? r2[1] : r2[0], data: i2 };
200
+ };
201
+ function U(e) {
202
+ q.use(e), e(this);
203
+ }
204
+ let ye = (e) => {
205
+ h.push(e);
206
+ };
207
+ (t2 == null ? void 0 : t2.initialState) && j(t2.initialState, { replace: true });
208
+ let ge = { _type: p2, _id: s$1, key: a2, mutate: j, subscribe: g, resolve: R, safeResolve: _, resolveParents: x, inspectFields: k, invalidate: B, keyOfEntity: E, entityOfKey: C, getArgumentsForMutate: A, types: l.types, cache: l, use: U, addSkip: ye, subscribers: ae ? T : void 0, onDebugEvent: O.onDebugEvent };
209
+ return l.onRemoveLink((e, r2) => O.debug({ type: "garbageRemove", entity: e, prevValue: r2 })), q.runPlugins(ge);
210
+ };
211
+ const BASE_HEADERS = {
212
+ "Content-Type": "application/json"
213
+ };
214
+ const createFetcher = (baseUrl, defaultHeaders = {}) => {
215
+ const cache = /* @__PURE__ */ new Map();
216
+ const inflightRequests = /* @__PURE__ */ new Map();
217
+ const getCacheKey = (query2, variables, options) => JSON.stringify({ query: query2, variables, options });
218
+ const query = async (query2, variables = {}, options = {}) => {
219
+ const cacheKey = getCacheKey(query2, variables, options);
220
+ if (cache.has(cacheKey)) {
221
+ return cache.get(cacheKey);
222
+ }
223
+ if (inflightRequests.has(cacheKey)) {
224
+ return inflightRequests.get(cacheKey);
225
+ }
226
+ const request = fetch(baseUrl, {
227
+ ...options,
228
+ method: "POST",
229
+ body: JSON.stringify({ query: query2, variables }),
230
+ headers: {
231
+ ...BASE_HEADERS,
232
+ ...defaultHeaders,
233
+ ...options.headers
234
+ }
235
+ }).then(async (res) => {
236
+ if (!res.ok) throw new Error(`Fetch error: ${res.status}`);
237
+ const data = await res.json();
238
+ if (!query2.includes("mutation")) {
239
+ cache.set(cacheKey, data);
240
+ }
241
+ return data;
242
+ }).finally(() => {
243
+ inflightRequests.delete(cacheKey);
244
+ });
245
+ inflightRequests.set(cacheKey, request);
246
+ return request;
247
+ };
248
+ const invalidate = (endpoint, options) => {
249
+ cache.delete(getCacheKey(endpoint, options));
250
+ };
251
+ const clearCache = () => cache.clear();
252
+ return { query, invalidate, clearCache };
253
+ };
254
+ const getFragmentQuery = (isSelf) => isSelf ? `
255
+ query FragmentDocument($fragmentSlug: Int!) {
256
+ fragment(fragmentIds: [$fragmentSlug]) {
257
+ id
258
+ document
259
+ linkedFragments {
260
+ id
261
+ document
262
+ }
263
+ }
264
+ }
265
+ ` : `
266
+ query FragmentDocument($fragmentSlug: Int!) {
267
+ clientFragment(fragmentId: $fragmentSlug) {
268
+ id
269
+ document
270
+ linkedFragments {
271
+ id
272
+ document
273
+ }
274
+ }
275
+ }
276
+ `;
277
+ var isEmptyValue = (value) => !value && (value === null || value === void 0);
278
+ var isValue = (value) => !isEmptyValue(value);
279
+ var createConstants$1 = (...constants) => {
280
+ return constants.reduce((acc, constant) => {
281
+ acc[constant] = constant;
282
+ return acc;
283
+ }, {});
284
+ };
285
+ var isBrowser_default = typeof window !== "undefined";
286
+ var generateId = () => Math.random().toString(16).slice(2);
287
+ var setKey = (v) => `$${v}`;
288
+ var getKey = (v) => isKey(v) ? v.slice(1) : null;
289
+ var isKey = (v) => typeof v === "string" && v.startsWith("$");
290
+ function hashGenerator(layerKey) {
291
+ let hash = 0;
292
+ for (let i2 = 0; i2 < layerKey.length; i2++) {
293
+ hash = (hash << 5) - hash + layerKey.charCodeAt(i2);
294
+ hash |= 0;
295
+ }
296
+ const raw = Math.abs(hash).toString(36);
297
+ return /^[0-9]/.test(raw) ? `h${raw}` : raw;
298
+ }
299
+ const getEmptyFragment = (fragmentId) => {
300
+ const layerId = generateId();
301
+ return {
302
+ [`Fragment:${fragmentId}`]: {
303
+ _type: "Fragment",
304
+ _id: fragmentId,
305
+ children: [`Frame:${layerId}`],
306
+ layoutSizingHorizontal: "Fixed",
307
+ layoutSizingVertical: "Fixed",
308
+ horizontalGrow: "auto",
309
+ verticalGrow: "auto",
310
+ renderMode: "parent",
311
+ opacity: 1,
312
+ visible: true,
313
+ overflow: "hidden",
314
+ overrides: [],
315
+ properties: ["Variable:62218c840bd111"]
316
+ },
317
+ [`Frame:${layerId}`]: {
318
+ _type: "Frame",
319
+ _id: layerId,
320
+ opacity: 1,
321
+ parent: setKey(`Fragment:${fragmentId}`),
322
+ visible: true,
323
+ overflow: "visible",
324
+ children: [],
325
+ width: 320,
326
+ height: 200,
327
+ layoutSizingHorizontal: "Fixed",
328
+ layoutSizingVertical: "Fixed",
329
+ fillType: "Solid",
330
+ positionType: "absolute",
331
+ solidFill: "rgba(255, 255, 255, 1)",
332
+ name: "Frame",
333
+ isPrimary: true,
334
+ threshold: 320
335
+ }
336
+ };
337
+ };
338
+ const fetchBeacon = (baseUrl) => {
339
+ const sender = isBrowser_default && typeof (navigator == null ? void 0 : navigator.sendBeacon) === "function" ? navigator.sendBeacon : () => null;
340
+ const sendBeacon = (data) => {
341
+ try {
342
+ sender("/graphql", "test");
343
+ } catch (e) {
344
+ console.error(e);
345
+ }
346
+ };
347
+ return {
348
+ sendBeacon
349
+ };
350
+ };
351
+ const fetchPlugin = (state) => {
352
+ var _a, _b, _c;
353
+ const isSelf = ((_a = state == null ? void 0 : state.env) == null ? void 0 : _a.isSelf) ?? false;
354
+ const url = ((_b = state == null ? void 0 : state.env) == null ? void 0 : _b.url) ?? "http://localhost/graphql";
355
+ const apiToken = (_c = state == null ? void 0 : state.env) == null ? void 0 : _c.apiToken;
356
+ const fetcher = createFetcher(url, {
357
+ Authorization: `Bearer ${apiToken}`
358
+ });
359
+ const beaconFetcher = fetchBeacon();
360
+ const queryFragment = async (fragmentId) => {
361
+ var _a2, _b2, _c2, _d;
362
+ if (!apiToken) return null;
363
+ if (state.$fetch.cacheLinks.get(fragmentId)) {
364
+ return state.$fetch.cacheLinks.get(fragmentId);
365
+ }
366
+ const response = await fetcher.query(getFragmentQuery(isSelf), {
367
+ fragmentSlug: fragmentId
368
+ });
369
+ const fragment = isSelf ? (_b2 = (_a2 = response == null ? void 0 : response.data) == null ? void 0 : _a2.fragment) == null ? void 0 : _b2[0] : (_c2 = response == null ? void 0 : response.data) == null ? void 0 : _c2.clientFragment;
370
+ let fragmentDocument = fragment == null ? void 0 : fragment.document;
371
+ if (typeof fragmentDocument === "string") {
372
+ try {
373
+ if (Object.keys(JSON.parse(fragmentDocument)).length === 0) {
374
+ fragmentDocument = getEmptyFragment(fragmentId);
375
+ }
376
+ } catch (e) {
377
+ console.error(e);
378
+ }
379
+ }
380
+ if (fragment) {
381
+ state.$fetch.cacheDocuments.set(fragmentId, fragmentDocument);
382
+ if (Array.isArray(fragment.linkedFragments)) {
383
+ fragment.linkedFragments.forEach(
384
+ (linkedFragment) => state.$fetch.cacheDocuments.set(
385
+ linkedFragment.id,
386
+ linkedFragment.document
387
+ )
388
+ );
389
+ }
390
+ (_d = state.$fetch.cacheLinks) == null ? void 0 : _d.set(fragmentId, {
391
+ document: state.$fetch.cacheDocuments.get(fragmentId),
392
+ linkedFragments: fragment.linkedFragments ?? []
393
+ });
394
+ return state.$fetch.cacheLinks.get(fragmentId);
395
+ }
396
+ return null;
397
+ };
398
+ state.$fetch = {
399
+ cacheDocuments: /* @__PURE__ */ new Map(),
400
+ cacheLinks: /* @__PURE__ */ new Map(),
401
+ queryFragment,
402
+ query: fetcher.query,
403
+ sendBeacon: beaconFetcher.sendBeacon,
404
+ readFragment: (fragmentId) => state.$fetch.cacheDocuments.get(fragmentId)
405
+ };
406
+ };
407
+ const createConstants = (...constants) => {
408
+ return constants.reduce((acc, constant) => {
409
+ acc[constant] = constant;
410
+ return acc;
411
+ }, {});
412
+ };
413
+ const nodes = createConstants(
414
+ "Fragment",
415
+ "FragmentInstance",
416
+ "Instance",
417
+ "Breakpoint",
418
+ "Frame",
419
+ "Image",
420
+ "Text",
421
+ "SolidPaintStyle",
422
+ "CssLink",
423
+ "Variable",
424
+ "ComputedValue",
425
+ "TransformValue"
426
+ );
427
+ const fragmentGrowingMode = createConstants("auto", "fill");
428
+ const borderType = createConstants("None", "Solid", "Dashed", "Dotted");
429
+ const linkTarget = createConstants("_blank");
430
+ const paintMode = createConstants("None", "Solid", "Image");
431
+ const imagePaintScaleModes = createConstants(
432
+ "Fill",
433
+ "Fit",
434
+ "Crop",
435
+ "Tile"
436
+ );
437
+ const constrain = createConstants(
438
+ "Min",
439
+ "Center",
440
+ "Max",
441
+ "Stretch",
442
+ "Scale"
443
+ );
444
+ const positionType = createConstants("absolute", "relative");
445
+ const sizing = createConstants("Fixed", "Hug", "Fill", "Relative");
446
+ const layerMode = createConstants("none", "flex");
447
+ const layerDirection = createConstants("vertical", "horizontal");
448
+ const layerAlign = createConstants("start", "center", "end");
449
+ const layerDistribute = createConstants(
450
+ "start",
451
+ "center",
452
+ "end",
453
+ "space-between",
454
+ "space-around"
455
+ );
456
+ const textTransform = createConstants(
457
+ "none",
458
+ "uppercase",
459
+ "lowercase",
460
+ "capitalize"
461
+ );
462
+ const textDecorations = createConstants(
463
+ "none",
464
+ "underline",
465
+ "line-through"
466
+ );
467
+ const effectType = createConstants("loop", "appear", "hover", "tap");
468
+ const effectName = createConstants(
469
+ "fade",
470
+ "slide",
471
+ "bounce",
472
+ "wiggle",
473
+ "increase"
474
+ );
475
+ const variableType = createConstants(
476
+ "Event",
477
+ "String",
478
+ "Boolean",
479
+ "Array",
480
+ "Color",
481
+ "ComponentInstance",
482
+ "Date",
483
+ "Enum",
484
+ "Number",
485
+ "Object"
486
+ );
487
+ const whiteSpace = createConstants(
488
+ "normal",
489
+ "nowrap",
490
+ "pre",
491
+ "pre-wrap",
492
+ "pre-line",
493
+ "break-spaces"
494
+ );
495
+ const overflow = createConstants("visible", "hidden", "scroll");
496
+ const variableTransforms = createConstants(
497
+ "convert",
498
+ "exists",
499
+ "equals",
500
+ "startWith",
501
+ "endWith",
502
+ "contains",
503
+ "dateBefore",
504
+ "dateAfter",
505
+ "dateBetween",
506
+ "feature",
507
+ "notFeature",
508
+ "gt",
509
+ // Greater than
510
+ "gte",
511
+ // Greater than or equals
512
+ "lt",
513
+ // Less than
514
+ "lte",
515
+ // Less than or equals,
516
+ "convertFromBoolean",
517
+ "negative"
518
+ );
519
+ const renderTarget = createConstants("canvas", "document");
520
+ const renderMode = createConstants("viewport", "parent", "fixed");
521
+ const interactions = createConstants("click", "mouseover");
522
+ const eventMode = createConstants("goal", "callback");
523
+ const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
524
+ __proto__: null,
525
+ borderType,
526
+ constrain,
527
+ createConstants,
528
+ effectName,
529
+ effectType,
530
+ eventMode,
531
+ fragmentGrowingMode,
532
+ imagePaintScaleModes,
533
+ interactions,
534
+ layerAlign,
535
+ layerDirection,
536
+ layerDistribute,
537
+ layerMode,
538
+ linkTarget,
539
+ nodes,
540
+ overflow,
541
+ paintMode,
542
+ positionType,
543
+ renderMode,
544
+ renderTarget,
545
+ sizing,
546
+ textDecorations,
547
+ textTransform,
548
+ variableTransforms,
549
+ variableType,
550
+ whiteSpace
551
+ }, Symbol.toStringTag, { value: "Module" }));
552
+ // @__NO_SIDE_EFFECTS__
553
+ function getGlobalConfig(config2) {
554
+ return {
555
+ lang: (config2 == null ? void 0 : config2.lang) ?? void 0,
556
+ message: config2 == null ? void 0 : config2.message,
557
+ abortEarly: (config2 == null ? void 0 : config2.abortEarly) ?? void 0,
558
+ abortPipeEarly: (config2 == null ? void 0 : config2.abortPipeEarly) ?? void 0
559
+ };
560
+ }
561
+ // @__NO_SIDE_EFFECTS__
562
+ function getGlobalMessage(lang) {
563
+ return void 0;
564
+ }
565
+ // @__NO_SIDE_EFFECTS__
566
+ function getSchemaMessage(lang) {
567
+ return void 0;
568
+ }
569
+ // @__NO_SIDE_EFFECTS__
570
+ function getSpecificMessage(reference, lang) {
571
+ var _a;
572
+ return (_a = void 0) == null ? void 0 : _a.get(lang);
573
+ }
574
+ // @__NO_SIDE_EFFECTS__
575
+ function _stringify(input) {
576
+ var _a, _b;
577
+ const type = typeof input;
578
+ if (type === "string") {
579
+ return `"${input}"`;
580
+ }
581
+ if (type === "number" || type === "bigint" || type === "boolean") {
582
+ return `${input}`;
583
+ }
584
+ if (type === "object" || type === "function") {
585
+ return (input && ((_b = (_a = Object.getPrototypeOf(input)) == null ? void 0 : _a.constructor) == null ? void 0 : _b.name)) ?? "null";
586
+ }
587
+ return type;
588
+ }
589
+ function _addIssue(context, label, dataset, config2, other) {
590
+ const input = other && "input" in other ? other.input : dataset.value;
591
+ const expected = (other == null ? void 0 : other.expected) ?? context.expects ?? null;
592
+ const received = (other == null ? void 0 : other.received) ?? /* @__PURE__ */ _stringify(input);
593
+ const issue = {
594
+ kind: context.kind,
595
+ type: context.type,
596
+ input,
597
+ expected,
598
+ received,
599
+ message: `Invalid ${label}: ${expected ? `Expected ${expected} but r` : "R"}eceived ${received}`,
600
+ requirement: context.requirement,
601
+ path: other == null ? void 0 : other.path,
602
+ issues: other == null ? void 0 : other.issues,
603
+ lang: config2.lang,
604
+ abortEarly: config2.abortEarly,
605
+ abortPipeEarly: config2.abortPipeEarly
606
+ };
607
+ const isSchema = context.kind === "schema";
608
+ 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);
609
+ if (message !== void 0) {
610
+ issue.message = typeof message === "function" ? (
611
+ // @ts-expect-error
612
+ message(issue)
613
+ ) : message;
614
+ }
615
+ if (isSchema) {
616
+ dataset.typed = false;
617
+ }
618
+ if (dataset.issues) {
619
+ dataset.issues.push(issue);
620
+ } else {
621
+ dataset.issues = [issue];
622
+ }
623
+ }
624
+ // @__NO_SIDE_EFFECTS__
625
+ function _getStandardProps(context) {
626
+ return {
627
+ version: 1,
628
+ vendor: "valibot",
629
+ validate(value2) {
630
+ return context["~run"]({ value: value2 }, /* @__PURE__ */ getGlobalConfig());
631
+ }
632
+ };
633
+ }
634
+ // @__NO_SIDE_EFFECTS__
635
+ function _isValidObjectKey(object2, key) {
636
+ return Object.hasOwn(object2, key) && key !== "__proto__" && key !== "prototype" && key !== "constructor";
637
+ }
638
+ // @__NO_SIDE_EFFECTS__
639
+ function _joinExpects(values2, separator) {
640
+ const list = [...new Set(values2)];
641
+ if (list.length > 1) {
642
+ return `(${list.join(` ${separator} `)})`;
643
+ }
644
+ return list[0] ?? "never";
645
+ }
646
+ // @__NO_SIDE_EFFECTS__
647
+ function check(requirement, message) {
648
+ return {
649
+ kind: "validation",
650
+ type: "check",
651
+ reference: check,
652
+ async: false,
653
+ expects: null,
654
+ requirement,
655
+ message,
656
+ "~run"(dataset, config2) {
657
+ if (dataset.typed && !this.requirement(dataset.value)) {
658
+ _addIssue(this, "input", dataset, config2);
659
+ }
660
+ return dataset;
661
+ }
662
+ };
663
+ }
664
+ // @__NO_SIDE_EFFECTS__
665
+ function maxValue(requirement, message) {
666
+ return {
667
+ kind: "validation",
668
+ type: "max_value",
669
+ reference: maxValue,
670
+ async: false,
671
+ expects: `<=${requirement instanceof Date ? requirement.toJSON() : /* @__PURE__ */ _stringify(requirement)}`,
672
+ requirement,
673
+ message,
674
+ "~run"(dataset, config2) {
675
+ if (dataset.typed && !(dataset.value <= this.requirement)) {
676
+ _addIssue(this, "value", dataset, config2, {
677
+ received: dataset.value instanceof Date ? dataset.value.toJSON() : /* @__PURE__ */ _stringify(dataset.value)
678
+ });
679
+ }
680
+ return dataset;
681
+ }
682
+ };
683
+ }
684
+ // @__NO_SIDE_EFFECTS__
685
+ function metadata(metadata_) {
686
+ return {
687
+ kind: "metadata",
688
+ type: "metadata",
689
+ reference: metadata,
690
+ metadata: metadata_
691
+ };
692
+ }
693
+ // @__NO_SIDE_EFFECTS__
694
+ function minValue(requirement, message) {
695
+ return {
696
+ kind: "validation",
697
+ type: "min_value",
698
+ reference: minValue,
699
+ async: false,
700
+ expects: `>=${requirement instanceof Date ? requirement.toJSON() : /* @__PURE__ */ _stringify(requirement)}`,
701
+ requirement,
702
+ message,
703
+ "~run"(dataset, config2) {
704
+ if (dataset.typed && !(dataset.value >= this.requirement)) {
705
+ _addIssue(this, "value", dataset, config2, {
706
+ received: dataset.value instanceof Date ? dataset.value.toJSON() : /* @__PURE__ */ _stringify(dataset.value)
707
+ });
708
+ }
709
+ return dataset;
710
+ }
711
+ };
712
+ }
713
+ // @__NO_SIDE_EFFECTS__
714
+ function transform(operation) {
715
+ return {
716
+ kind: "transformation",
717
+ type: "transform",
718
+ reference: transform,
719
+ async: false,
720
+ operation,
721
+ "~run"(dataset) {
722
+ dataset.value = this.operation(dataset.value);
723
+ return dataset;
724
+ }
725
+ };
726
+ }
727
+ // @__NO_SIDE_EFFECTS__
728
+ function getFallback(schema, dataset, config2) {
729
+ return typeof schema.fallback === "function" ? (
730
+ // @ts-expect-error
731
+ schema.fallback(dataset, config2)
732
+ ) : (
733
+ // @ts-expect-error
734
+ schema.fallback
735
+ );
736
+ }
737
+ // @__NO_SIDE_EFFECTS__
738
+ function getDefault(schema, dataset, config2) {
739
+ return typeof schema.default === "function" ? (
740
+ // @ts-expect-error
741
+ schema.default(dataset, config2)
742
+ ) : (
743
+ // @ts-expect-error
744
+ schema.default
745
+ );
746
+ }
747
+ // @__NO_SIDE_EFFECTS__
748
+ function any() {
749
+ return {
750
+ kind: "schema",
751
+ type: "any",
752
+ reference: any,
753
+ expects: "any",
754
+ async: false,
755
+ get "~standard"() {
756
+ return /* @__PURE__ */ _getStandardProps(this);
757
+ },
758
+ "~run"(dataset) {
759
+ dataset.typed = true;
760
+ return dataset;
761
+ }
762
+ };
763
+ }
764
+ // @__NO_SIDE_EFFECTS__
765
+ function array(item, message) {
766
+ return {
767
+ kind: "schema",
768
+ type: "array",
769
+ reference: array,
770
+ expects: "Array",
771
+ async: false,
772
+ item,
773
+ message,
774
+ get "~standard"() {
775
+ return /* @__PURE__ */ _getStandardProps(this);
776
+ },
777
+ "~run"(dataset, config2) {
778
+ var _a;
779
+ const input = dataset.value;
780
+ if (Array.isArray(input)) {
781
+ dataset.typed = true;
782
+ dataset.value = [];
783
+ for (let key = 0; key < input.length; key++) {
784
+ const value2 = input[key];
785
+ const itemDataset = this.item["~run"]({ value: value2 }, config2);
786
+ if (itemDataset.issues) {
787
+ const pathItem = {
788
+ type: "array",
789
+ origin: "value",
790
+ input,
791
+ key,
792
+ value: value2
793
+ };
794
+ for (const issue of itemDataset.issues) {
795
+ if (issue.path) {
796
+ issue.path.unshift(pathItem);
797
+ } else {
798
+ issue.path = [pathItem];
799
+ }
800
+ (_a = dataset.issues) == null ? void 0 : _a.push(issue);
801
+ }
802
+ if (!dataset.issues) {
803
+ dataset.issues = itemDataset.issues;
804
+ }
805
+ if (config2.abortEarly) {
806
+ dataset.typed = false;
807
+ break;
808
+ }
809
+ }
810
+ if (!itemDataset.typed) {
811
+ dataset.typed = false;
812
+ }
813
+ dataset.value.push(itemDataset.value);
814
+ }
815
+ } else {
816
+ _addIssue(this, "type", dataset, config2);
817
+ }
818
+ return dataset;
819
+ }
820
+ };
821
+ }
822
+ // @__NO_SIDE_EFFECTS__
823
+ function boolean(message) {
824
+ return {
825
+ kind: "schema",
826
+ type: "boolean",
827
+ reference: boolean,
828
+ expects: "boolean",
829
+ async: false,
830
+ message,
831
+ get "~standard"() {
832
+ return /* @__PURE__ */ _getStandardProps(this);
833
+ },
834
+ "~run"(dataset, config2) {
835
+ if (typeof dataset.value === "boolean") {
836
+ dataset.typed = true;
837
+ } else {
838
+ _addIssue(this, "type", dataset, config2);
839
+ }
840
+ return dataset;
841
+ }
842
+ };
843
+ }
844
+ // @__NO_SIDE_EFFECTS__
845
+ function enum_(enum__, message) {
846
+ const options = [];
847
+ for (const key in enum__) {
848
+ if (`${+key}` !== key || typeof enum__[key] !== "string" || !Object.is(enum__[enum__[key]], +key)) {
849
+ options.push(enum__[key]);
850
+ }
851
+ }
852
+ return {
853
+ kind: "schema",
854
+ type: "enum",
855
+ reference: enum_,
856
+ expects: /* @__PURE__ */ _joinExpects(options.map(_stringify), "|"),
857
+ async: false,
858
+ enum: enum__,
859
+ options,
860
+ message,
861
+ get "~standard"() {
862
+ return /* @__PURE__ */ _getStandardProps(this);
863
+ },
864
+ "~run"(dataset, config2) {
865
+ if (this.options.includes(dataset.value)) {
866
+ dataset.typed = true;
867
+ } else {
868
+ _addIssue(this, "type", dataset, config2);
869
+ }
870
+ return dataset;
871
+ }
872
+ };
873
+ }
874
+ // @__NO_SIDE_EFFECTS__
875
+ function literal(literal_, message) {
876
+ return {
877
+ kind: "schema",
878
+ type: "literal",
879
+ reference: literal,
880
+ expects: /* @__PURE__ */ _stringify(literal_),
881
+ async: false,
882
+ literal: literal_,
883
+ message,
884
+ get "~standard"() {
885
+ return /* @__PURE__ */ _getStandardProps(this);
886
+ },
887
+ "~run"(dataset, config2) {
888
+ if (dataset.value === this.literal) {
889
+ dataset.typed = true;
890
+ } else {
891
+ _addIssue(this, "type", dataset, config2);
892
+ }
893
+ return dataset;
894
+ }
895
+ };
896
+ }
897
+ // @__NO_SIDE_EFFECTS__
898
+ function nullable(wrapped, default_) {
899
+ return {
900
+ kind: "schema",
901
+ type: "nullable",
902
+ reference: nullable,
903
+ expects: `(${wrapped.expects} | null)`,
904
+ async: false,
905
+ wrapped,
906
+ default: default_,
907
+ get "~standard"() {
908
+ return /* @__PURE__ */ _getStandardProps(this);
909
+ },
910
+ "~run"(dataset, config2) {
911
+ if (dataset.value === null) {
912
+ if (this.default !== void 0) {
913
+ dataset.value = /* @__PURE__ */ getDefault(this, dataset, config2);
914
+ }
915
+ if (dataset.value === null) {
916
+ dataset.typed = true;
917
+ return dataset;
918
+ }
919
+ }
920
+ return this.wrapped["~run"](dataset, config2);
921
+ }
922
+ };
923
+ }
924
+ // @__NO_SIDE_EFFECTS__
925
+ function number(message) {
926
+ return {
927
+ kind: "schema",
928
+ type: "number",
929
+ reference: number,
930
+ expects: "number",
931
+ async: false,
932
+ message,
933
+ get "~standard"() {
934
+ return /* @__PURE__ */ _getStandardProps(this);
935
+ },
936
+ "~run"(dataset, config2) {
937
+ if (typeof dataset.value === "number" && !isNaN(dataset.value)) {
938
+ dataset.typed = true;
939
+ } else {
940
+ _addIssue(this, "type", dataset, config2);
941
+ }
942
+ return dataset;
943
+ }
944
+ };
945
+ }
946
+ // @__NO_SIDE_EFFECTS__
947
+ function object(entries, message) {
948
+ return {
949
+ kind: "schema",
950
+ type: "object",
951
+ reference: object,
952
+ expects: "Object",
953
+ async: false,
954
+ entries,
955
+ message,
956
+ get "~standard"() {
957
+ return /* @__PURE__ */ _getStandardProps(this);
958
+ },
959
+ "~run"(dataset, config2) {
960
+ var _a;
961
+ const input = dataset.value;
962
+ if (input && typeof input === "object") {
963
+ dataset.typed = true;
964
+ dataset.value = {};
965
+ for (const key in this.entries) {
966
+ const valueSchema = this.entries[key];
967
+ if (key in input || (valueSchema.type === "exact_optional" || valueSchema.type === "optional" || valueSchema.type === "nullish") && // @ts-expect-error
968
+ valueSchema.default !== void 0) {
969
+ const value2 = key in input ? (
970
+ // @ts-expect-error
971
+ input[key]
972
+ ) : /* @__PURE__ */ getDefault(valueSchema);
973
+ const valueDataset = valueSchema["~run"]({ value: value2 }, config2);
974
+ if (valueDataset.issues) {
975
+ const pathItem = {
976
+ type: "object",
977
+ origin: "value",
978
+ input,
979
+ key,
980
+ value: value2
981
+ };
982
+ for (const issue of valueDataset.issues) {
983
+ if (issue.path) {
984
+ issue.path.unshift(pathItem);
985
+ } else {
986
+ issue.path = [pathItem];
987
+ }
988
+ (_a = dataset.issues) == null ? void 0 : _a.push(issue);
989
+ }
990
+ if (!dataset.issues) {
991
+ dataset.issues = valueDataset.issues;
992
+ }
993
+ if (config2.abortEarly) {
994
+ dataset.typed = false;
995
+ break;
996
+ }
997
+ }
998
+ if (!valueDataset.typed) {
999
+ dataset.typed = false;
1000
+ }
1001
+ dataset.value[key] = valueDataset.value;
1002
+ } else if (valueSchema.fallback !== void 0) {
1003
+ dataset.value[key] = /* @__PURE__ */ getFallback(valueSchema);
1004
+ } else if (valueSchema.type !== "exact_optional" && valueSchema.type !== "optional" && valueSchema.type !== "nullish") {
1005
+ _addIssue(this, "key", dataset, config2, {
1006
+ input: void 0,
1007
+ expected: `"${key}"`,
1008
+ path: [
1009
+ {
1010
+ type: "object",
1011
+ origin: "key",
1012
+ input,
1013
+ key,
1014
+ // @ts-expect-error
1015
+ value: input[key]
1016
+ }
1017
+ ]
1018
+ });
1019
+ if (config2.abortEarly) {
1020
+ break;
1021
+ }
1022
+ }
1023
+ }
1024
+ } else {
1025
+ _addIssue(this, "type", dataset, config2);
1026
+ }
1027
+ return dataset;
1028
+ }
1029
+ };
1030
+ }
1031
+ // @__NO_SIDE_EFFECTS__
1032
+ function optional(wrapped, default_) {
1033
+ return {
1034
+ kind: "schema",
1035
+ type: "optional",
1036
+ reference: optional,
1037
+ expects: `(${wrapped.expects} | undefined)`,
1038
+ async: false,
1039
+ wrapped,
1040
+ default: default_,
1041
+ get "~standard"() {
1042
+ return /* @__PURE__ */ _getStandardProps(this);
1043
+ },
1044
+ "~run"(dataset, config2) {
1045
+ if (dataset.value === void 0) {
1046
+ if (this.default !== void 0) {
1047
+ dataset.value = /* @__PURE__ */ getDefault(this, dataset, config2);
1048
+ }
1049
+ if (dataset.value === void 0) {
1050
+ dataset.typed = true;
1051
+ return dataset;
1052
+ }
1053
+ }
1054
+ return this.wrapped["~run"](dataset, config2);
1055
+ }
1056
+ };
1057
+ }
1058
+ // @__NO_SIDE_EFFECTS__
1059
+ function picklist(options, message) {
1060
+ return {
1061
+ kind: "schema",
1062
+ type: "picklist",
1063
+ reference: picklist,
1064
+ expects: /* @__PURE__ */ _joinExpects(options.map(_stringify), "|"),
1065
+ async: false,
1066
+ options,
1067
+ message,
1068
+ get "~standard"() {
1069
+ return /* @__PURE__ */ _getStandardProps(this);
1070
+ },
1071
+ "~run"(dataset, config2) {
1072
+ if (this.options.includes(dataset.value)) {
1073
+ dataset.typed = true;
1074
+ } else {
1075
+ _addIssue(this, "type", dataset, config2);
1076
+ }
1077
+ return dataset;
1078
+ }
1079
+ };
1080
+ }
1081
+ // @__NO_SIDE_EFFECTS__
1082
+ function record(key, value2, message) {
1083
+ return {
1084
+ kind: "schema",
1085
+ type: "record",
1086
+ reference: record,
1087
+ expects: "Object",
1088
+ async: false,
1089
+ key,
1090
+ value: value2,
1091
+ message,
1092
+ get "~standard"() {
1093
+ return /* @__PURE__ */ _getStandardProps(this);
1094
+ },
1095
+ "~run"(dataset, config2) {
1096
+ var _a, _b;
1097
+ const input = dataset.value;
1098
+ if (input && typeof input === "object") {
1099
+ dataset.typed = true;
1100
+ dataset.value = {};
1101
+ for (const entryKey in input) {
1102
+ if (/* @__PURE__ */ _isValidObjectKey(input, entryKey)) {
1103
+ const entryValue = input[entryKey];
1104
+ const keyDataset = this.key["~run"]({ value: entryKey }, config2);
1105
+ if (keyDataset.issues) {
1106
+ const pathItem = {
1107
+ type: "object",
1108
+ origin: "key",
1109
+ input,
1110
+ key: entryKey,
1111
+ value: entryValue
1112
+ };
1113
+ for (const issue of keyDataset.issues) {
1114
+ issue.path = [pathItem];
1115
+ (_a = dataset.issues) == null ? void 0 : _a.push(issue);
1116
+ }
1117
+ if (!dataset.issues) {
1118
+ dataset.issues = keyDataset.issues;
1119
+ }
1120
+ if (config2.abortEarly) {
1121
+ dataset.typed = false;
1122
+ break;
1123
+ }
1124
+ }
1125
+ const valueDataset = this.value["~run"](
1126
+ { value: entryValue },
1127
+ config2
1128
+ );
1129
+ if (valueDataset.issues) {
1130
+ const pathItem = {
1131
+ type: "object",
1132
+ origin: "value",
1133
+ input,
1134
+ key: entryKey,
1135
+ value: entryValue
1136
+ };
1137
+ for (const issue of valueDataset.issues) {
1138
+ if (issue.path) {
1139
+ issue.path.unshift(pathItem);
1140
+ } else {
1141
+ issue.path = [pathItem];
1142
+ }
1143
+ (_b = dataset.issues) == null ? void 0 : _b.push(issue);
1144
+ }
1145
+ if (!dataset.issues) {
1146
+ dataset.issues = valueDataset.issues;
1147
+ }
1148
+ if (config2.abortEarly) {
1149
+ dataset.typed = false;
1150
+ break;
1151
+ }
1152
+ }
1153
+ if (!keyDataset.typed || !valueDataset.typed) {
1154
+ dataset.typed = false;
1155
+ }
1156
+ if (keyDataset.typed) {
1157
+ dataset.value[keyDataset.value] = valueDataset.value;
1158
+ }
1159
+ }
1160
+ }
1161
+ } else {
1162
+ _addIssue(this, "type", dataset, config2);
1163
+ }
1164
+ return dataset;
1165
+ }
1166
+ };
1167
+ }
1168
+ // @__NO_SIDE_EFFECTS__
1169
+ function string(message) {
1170
+ return {
1171
+ kind: "schema",
1172
+ type: "string",
1173
+ reference: string,
1174
+ expects: "string",
1175
+ async: false,
1176
+ message,
1177
+ get "~standard"() {
1178
+ return /* @__PURE__ */ _getStandardProps(this);
1179
+ },
1180
+ "~run"(dataset, config2) {
1181
+ if (typeof dataset.value === "string") {
1182
+ dataset.typed = true;
1183
+ } else {
1184
+ _addIssue(this, "type", dataset, config2);
1185
+ }
1186
+ return dataset;
1187
+ }
1188
+ };
1189
+ }
1190
+ // @__NO_SIDE_EFFECTS__
1191
+ function _subIssues(datasets) {
1192
+ let issues;
1193
+ if (datasets) {
1194
+ for (const dataset of datasets) {
1195
+ if (issues) {
1196
+ issues.push(...dataset.issues);
1197
+ } else {
1198
+ issues = dataset.issues;
1199
+ }
1200
+ }
1201
+ }
1202
+ return issues;
1203
+ }
1204
+ // @__NO_SIDE_EFFECTS__
1205
+ function union(options, message) {
1206
+ return {
1207
+ kind: "schema",
1208
+ type: "union",
1209
+ reference: union,
1210
+ expects: /* @__PURE__ */ _joinExpects(
1211
+ options.map((option) => option.expects),
1212
+ "|"
1213
+ ),
1214
+ async: false,
1215
+ options,
1216
+ message,
1217
+ get "~standard"() {
1218
+ return /* @__PURE__ */ _getStandardProps(this);
1219
+ },
1220
+ "~run"(dataset, config2) {
1221
+ let validDataset;
1222
+ let typedDatasets;
1223
+ let untypedDatasets;
1224
+ for (const schema of this.options) {
1225
+ const optionDataset = schema["~run"]({ value: dataset.value }, config2);
1226
+ if (optionDataset.typed) {
1227
+ if (optionDataset.issues) {
1228
+ if (typedDatasets) {
1229
+ typedDatasets.push(optionDataset);
1230
+ } else {
1231
+ typedDatasets = [optionDataset];
1232
+ }
1233
+ } else {
1234
+ validDataset = optionDataset;
1235
+ break;
1236
+ }
1237
+ } else {
1238
+ if (untypedDatasets) {
1239
+ untypedDatasets.push(optionDataset);
1240
+ } else {
1241
+ untypedDatasets = [optionDataset];
1242
+ }
1243
+ }
1244
+ }
1245
+ if (validDataset) {
1246
+ return validDataset;
1247
+ }
1248
+ if (typedDatasets) {
1249
+ if (typedDatasets.length === 1) {
1250
+ return typedDatasets[0];
1251
+ }
1252
+ _addIssue(this, "type", dataset, config2, {
1253
+ issues: /* @__PURE__ */ _subIssues(typedDatasets)
1254
+ });
1255
+ dataset.typed = true;
1256
+ } else if ((untypedDatasets == null ? void 0 : untypedDatasets.length) === 1) {
1257
+ return untypedDatasets[0];
1258
+ } else {
1259
+ _addIssue(this, "type", dataset, config2, {
1260
+ issues: /* @__PURE__ */ _subIssues(untypedDatasets)
1261
+ });
1262
+ }
1263
+ return dataset;
1264
+ }
1265
+ };
1266
+ }
1267
+ // @__NO_SIDE_EFFECTS__
1268
+ function pipe(...pipe2) {
1269
+ return {
1270
+ ...pipe2[0],
1271
+ pipe: pipe2,
1272
+ get "~standard"() {
1273
+ return /* @__PURE__ */ _getStandardProps(this);
1274
+ },
1275
+ "~run"(dataset, config2) {
1276
+ for (const item of pipe2) {
1277
+ if (item.kind !== "metadata") {
1278
+ if (dataset.issues && (item.kind === "schema" || item.kind === "transformation")) {
1279
+ dataset.typed = false;
1280
+ break;
1281
+ }
1282
+ if (!dataset.issues || !config2.abortEarly && !config2.abortPipeEarly) {
1283
+ dataset = item["~run"](dataset, config2);
1284
+ }
1285
+ }
1286
+ }
1287
+ return dataset;
1288
+ }
1289
+ };
1290
+ }
1291
+ const linkValidator = /* @__PURE__ */ check(
1292
+ (value) => {
1293
+ var _a, _b;
1294
+ return !!value && ((_b = (_a = value == null ? void 0 : value.split) == null ? void 0 : _a.call(value, ":")) == null ? void 0 : _b.length) === 2;
1295
+ }
1296
+ );
1297
+ const layerField = (schema, meta) => {
1298
+ const modifiedSchema = (meta == null ? void 0 : meta.variable) ? /* @__PURE__ */ union([schema, /* @__PURE__ */ pipe(/* @__PURE__ */ string(), linkValidator)]) : schema;
1299
+ return /* @__PURE__ */ pipe(
1300
+ /* @__PURE__ */ optional(modifiedSchema),
1301
+ /* @__PURE__ */ transform((meta == null ? void 0 : meta.transform) ?? ((v2) => v2)),
1302
+ /* @__PURE__ */ metadata(meta ?? {})
1303
+ );
1304
+ };
1305
+ const ChildrenSchema = /* @__PURE__ */ object({
1306
+ children: layerField(/* @__PURE__ */ array(/* @__PURE__ */ string()), {
1307
+ fallback: [],
1308
+ overridable: false
1309
+ })
1310
+ });
1311
+ const GraphFieldSchema = /* @__PURE__ */ object({
1312
+ _id: /* @__PURE__ */ union([/* @__PURE__ */ string(), /* @__PURE__ */ number()]),
1313
+ _type: /* @__PURE__ */ picklist(Object.keys(nodes))
1314
+ });
1315
+ const OverridesSchema = /* @__PURE__ */ object({
1316
+ overrides: layerField(/* @__PURE__ */ array(/* @__PURE__ */ string()), { overridable: false }),
1317
+ overrideFrom: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false })
1318
+ });
1319
+ const PositionSchema = /* @__PURE__ */ object({
1320
+ position: layerField(/* @__PURE__ */ enum_(Object.keys(positionType)), {
1321
+ fallback: positionType.absolute
1322
+ }),
1323
+ top: layerField(/* @__PURE__ */ number(), { fallback: 0, transform: Math.ceil }),
1324
+ left: layerField(/* @__PURE__ */ number(), { fallback: 0, transform: Math.ceil })
1325
+ });
1326
+ const SceneSchema = /* @__PURE__ */ object({
1327
+ opacity: layerField(/* @__PURE__ */ pipe(/* @__PURE__ */ number(), /* @__PURE__ */ minValue(0), /* @__PURE__ */ maxValue(1)), {
1328
+ fallback: 1,
1329
+ variable: true
1330
+ }),
1331
+ visible: layerField(/* @__PURE__ */ boolean(), { fallback: true, variable: true }),
1332
+ zIndex: layerField(/* @__PURE__ */ number(), { fallback: -1 })
1333
+ });
1334
+ const FillSchema = /* @__PURE__ */ object({
1335
+ fillType: layerField(/* @__PURE__ */ picklist(Object.keys(paintMode)), {
1336
+ fallback: paintMode.None
1337
+ }),
1338
+ solidFill: layerField(/* @__PURE__ */ string(), { fallback: "#fff" }),
1339
+ imageFill: layerField(/* @__PURE__ */ string()),
1340
+ imageSize: layerField(/* @__PURE__ */ picklist(Object.keys(imagePaintScaleModes)), {
1341
+ fallback: imagePaintScaleModes.Fill
1342
+ })
1343
+ });
1344
+ const BorderSchema = /* @__PURE__ */ object({
1345
+ borderType: layerField(/* @__PURE__ */ picklist(Object.keys(borderType)), {
1346
+ fallback: borderType.None
1347
+ }),
1348
+ borderWidth: layerField(/* @__PURE__ */ pipe(/* @__PURE__ */ number(), /* @__PURE__ */ minValue(0)), { fallback: 0 }),
1349
+ borderColor: layerField(/* @__PURE__ */ string(), { fallback: "#fff" })
1350
+ });
1351
+ const SizeSchema = /* @__PURE__ */ object({
1352
+ widthType: layerField(/* @__PURE__ */ picklist(Object.keys(sizing)), {
1353
+ fallback: sizing.Fixed
1354
+ }),
1355
+ heightType: layerField(/* @__PURE__ */ picklist(Object.keys(sizing)), {
1356
+ fallback: sizing.Fixed
1357
+ }),
1358
+ width: layerField(/* @__PURE__ */ pipe(/* @__PURE__ */ number(), /* @__PURE__ */ minValue(0)), {
1359
+ fallback: 0,
1360
+ transform: Math.ceil
1361
+ }),
1362
+ height: layerField(/* @__PURE__ */ pipe(/* @__PURE__ */ number(), /* @__PURE__ */ minValue(0)), {
1363
+ fallback: 0,
1364
+ transform: Math.ceil
1365
+ }),
1366
+ aspectRatio: layerField(/* @__PURE__ */ number(), { fallback: -1 }),
1367
+ minWidth: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ pipe(/* @__PURE__ */ number(), /* @__PURE__ */ minValue(-1))), {
1368
+ fallback: -1,
1369
+ transform: Math.ceil
1370
+ }),
1371
+ minWidthType: layerField(/* @__PURE__ */ picklist(Object.keys(sizing)), {
1372
+ fallback: sizing.Fixed
1373
+ }),
1374
+ maxWidth: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ pipe(/* @__PURE__ */ number(), /* @__PURE__ */ minValue(-1))), {
1375
+ fallback: -1,
1376
+ transform: Math.ceil
1377
+ }),
1378
+ maxWidthType: layerField(/* @__PURE__ */ picklist(Object.keys(sizing)), {
1379
+ fallback: sizing.Fixed
1380
+ }),
1381
+ minHeight: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ pipe(/* @__PURE__ */ number(), /* @__PURE__ */ minValue(-1))), {
1382
+ fallback: -1,
1383
+ transform: Math.ceil
1384
+ }),
1385
+ minHeightType: layerField(/* @__PURE__ */ picklist(Object.keys(sizing)), {
1386
+ fallback: sizing.Fixed
1387
+ }),
1388
+ maxHeight: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ pipe(/* @__PURE__ */ number(), /* @__PURE__ */ minValue(-1))), {
1389
+ fallback: -1,
1390
+ transform: Math.ceil
1391
+ }),
1392
+ maxHeightType: layerField(/* @__PURE__ */ picklist(Object.keys(sizing)), {
1393
+ fallback: sizing.Fixed
1394
+ })
1395
+ });
1396
+ const LayerSchema = /* @__PURE__ */ object({
1397
+ layerMode: layerField(/* @__PURE__ */ picklist(Object.keys(layerMode)), {
1398
+ fallback: layerMode.none
1399
+ }),
1400
+ layerAlign: layerField(/* @__PURE__ */ picklist(Object.keys(layerAlign)), {
1401
+ fallback: layerAlign.start
1402
+ }),
1403
+ layerDirection: layerField(/* @__PURE__ */ picklist(Object.keys(layerDirection)), {
1404
+ fallback: layerDirection.horizontal
1405
+ }),
1406
+ layerDistribute: layerField(/* @__PURE__ */ picklist(Object.keys(layerDistribute)), {
1407
+ fallback: layerDistribute.start
1408
+ }),
1409
+ layerWrap: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1410
+ layerGap: layerField(/* @__PURE__ */ pipe(/* @__PURE__ */ number(), /* @__PURE__ */ minValue(0)), { fallback: 0 }),
1411
+ padding: layerField(/* @__PURE__ */ string(), { fallback: "0px" })
1412
+ });
1413
+ const OverflowSchema = layerField(/* @__PURE__ */ picklist(Object.keys(overflow)), {
1414
+ fallback: overflow.hidden
1415
+ });
1416
+ const BorderRadiusSchema = layerField(/* @__PURE__ */ string(), { fallback: "0px" });
1417
+ const InteractionsSchema = /* @__PURE__ */ object({
1418
+ interactions: layerField(
1419
+ /* @__PURE__ */ array(
1420
+ /* @__PURE__ */ object({
1421
+ on: /* @__PURE__ */ enum_(Object.keys(interactions)),
1422
+ event: /* @__PURE__ */ nullable(linkValidator)
1423
+ })
1424
+ ),
1425
+ { fallback: [] }
1426
+ )
1427
+ });
1428
+ const CssOverrideSchema = /* @__PURE__ */ object({
1429
+ cssOverride: layerField(/* @__PURE__ */ string(), { fallback: "" })
1430
+ });
1431
+ /* @__PURE__ */ pipe(
1432
+ /* @__PURE__ */ object({
1433
+ name: layerField(/* @__PURE__ */ string(), { fallback: "Frame", overridable: false }),
1434
+ isBreakpoint: layerField(/* @__PURE__ */ boolean(), {
1435
+ fallback: false,
1436
+ overridable: false
1437
+ }),
1438
+ isPrimary: layerField(/* @__PURE__ */ boolean(), { fallback: false, overridable: false }),
1439
+ parent: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false }),
1440
+ ...ChildrenSchema.entries,
1441
+ ...GraphFieldSchema.entries,
1442
+ ...OverridesSchema.entries,
1443
+ ...PositionSchema.entries,
1444
+ ...SceneSchema.entries,
1445
+ ...FillSchema.entries,
1446
+ ...BorderSchema.entries,
1447
+ ...SizeSchema.entries,
1448
+ ...LayerSchema.entries,
1449
+ ...InteractionsSchema.entries,
1450
+ ...CssOverrideSchema.entries,
1451
+ overflow: OverflowSchema,
1452
+ borderRadius: BorderRadiusSchema
1453
+ })
1454
+ );
1455
+ /* @__PURE__ */ object({
1456
+ name: layerField(/* @__PURE__ */ string(), { fallback: "Text", overridable: false }),
1457
+ content: layerField(/* @__PURE__ */ string(), {
1458
+ fallback: ""
1459
+ }),
1460
+ whiteSpace: layerField(/* @__PURE__ */ enum_(Object.keys(whiteSpace)), {
1461
+ fallback: whiteSpace.pre
1462
+ }),
1463
+ variableContent: layerField(/* @__PURE__ */ string(), { fallback: null, variable: true }),
1464
+ parent: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false }),
1465
+ attributes: layerField(
1466
+ /* @__PURE__ */ object({
1467
+ fontSize: layerField(/* @__PURE__ */ string(), { fallback: "14px" }),
1468
+ color: layerField(/* @__PURE__ */ string(), { fallback: "#000" }),
1469
+ lineHeight: layerField(/* @__PURE__ */ string(), { fallback: "14px" }),
1470
+ fontWeight: layerField(/* @__PURE__ */ string(), { fallback: "normal" }),
1471
+ letterSpacing: layerField(/* @__PURE__ */ string(), { fallback: "0px" }),
1472
+ textTransform: layerField(/* @__PURE__ */ string(), { fallback: "none" }),
1473
+ textDecoration: layerField(/* @__PURE__ */ string(), { fallback: "none" }),
1474
+ whiteSpace: layerField(/* @__PURE__ */ string(), { fallback: "pre" }),
1475
+ textAlign: layerField(/* @__PURE__ */ string(), { fallback: "left" })
1476
+ }),
1477
+ { fallback: {} }
1478
+ ),
1479
+ ...GraphFieldSchema.entries,
1480
+ ...OverridesSchema.entries,
1481
+ ...PositionSchema.entries,
1482
+ ...SceneSchema.entries,
1483
+ ...SizeSchema.entries
1484
+ });
1485
+ /* @__PURE__ */ object({
1486
+ name: layerField(/* @__PURE__ */ string(), { fallback: "Fragment", overridable: false }),
1487
+ parent: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false }),
1488
+ horizontalGrow: layerField(/* @__PURE__ */ enum_(Object.keys(fragmentGrowingMode)), {
1489
+ fallback: fragmentGrowingMode.auto,
1490
+ overridable: false
1491
+ }),
1492
+ verticalGrow: layerField(/* @__PURE__ */ enum_(Object.keys(fragmentGrowingMode)), {
1493
+ fallback: fragmentGrowingMode.auto,
1494
+ overridable: false
1495
+ }),
1496
+ properties: layerField(/* @__PURE__ */ array(/* @__PURE__ */ string()), {
1497
+ fallback: [],
1498
+ overridable: false
1499
+ }),
1500
+ ...GraphFieldSchema.entries,
1501
+ ...ChildrenSchema.entries
1502
+ });
1503
+ /* @__PURE__ */ object({
1504
+ name: layerField(/* @__PURE__ */ string(), { fallback: "Instance", overridable: false }),
1505
+ fragment: layerField(/* @__PURE__ */ number()),
1506
+ parent: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false }),
1507
+ props: layerField(
1508
+ /* @__PURE__ */ record(
1509
+ /* @__PURE__ */ string(),
1510
+ /* @__PURE__ */ union([
1511
+ /* @__PURE__ */ string(),
1512
+ /* @__PURE__ */ number(),
1513
+ /* @__PURE__ */ boolean(),
1514
+ // For goals
1515
+ /* @__PURE__ */ object({
1516
+ code: /* @__PURE__ */ string(),
1517
+ name: /* @__PURE__ */ string()
1518
+ })
1519
+ ])
1520
+ ),
1521
+ {
1522
+ fallback: {}
1523
+ }
1524
+ ),
1525
+ ...GraphFieldSchema.entries,
1526
+ ...OverridesSchema.entries,
1527
+ ...PositionSchema.entries,
1528
+ ...SizeSchema.entries,
1529
+ ...SceneSchema.entries
1530
+ });
1531
+ /* @__PURE__ */ object({
1532
+ name: layerField(/* @__PURE__ */ string(), {
1533
+ fallback: "Number",
1534
+ overridable: false
1535
+ }),
1536
+ type: layerField(/* @__PURE__ */ literal(variableType.Number), {
1537
+ fallback: variableType.Number
1538
+ }),
1539
+ defaultValue: layerField(/* @__PURE__ */ number(), { fallback: 0 }),
1540
+ required: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1541
+ min: layerField(/* @__PURE__ */ number(), { fallback: 1 }),
1542
+ max: layerField(/* @__PURE__ */ number(), { fallback: 100 }),
1543
+ step: layerField(/* @__PURE__ */ number(), { fallback: 1 }),
1544
+ displayStepper: layerField(/* @__PURE__ */ boolean(), { fallback: true }),
1545
+ ...GraphFieldSchema.entries
1546
+ });
1547
+ /* @__PURE__ */ object({
1548
+ name: layerField(/* @__PURE__ */ string(), {
1549
+ fallback: "Boolean",
1550
+ overridable: false
1551
+ }),
1552
+ type: layerField(/* @__PURE__ */ literal(variableType.Boolean), {
1553
+ fallback: variableType.Boolean
1554
+ }),
1555
+ defaultValue: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1556
+ required: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1557
+ ...GraphFieldSchema.entries
1558
+ });
1559
+ /* @__PURE__ */ object({
1560
+ name: layerField(/* @__PURE__ */ string(), {
1561
+ fallback: "String",
1562
+ overridable: false
1563
+ }),
1564
+ type: layerField(/* @__PURE__ */ literal(variableType.Color), {
1565
+ fallback: variableType.Color
1566
+ }),
1567
+ // TODO Add color validator
1568
+ defaultValue: layerField(/* @__PURE__ */ string(), { fallback: "#000" }),
1569
+ required: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1570
+ ...GraphFieldSchema.entries
1571
+ });
1572
+ /* @__PURE__ */ object({
1573
+ name: layerField(/* @__PURE__ */ string(), {
1574
+ fallback: "String",
1575
+ overridable: false
1576
+ }),
1577
+ type: layerField(/* @__PURE__ */ literal(variableType.String), {
1578
+ fallback: variableType.String
1579
+ }),
1580
+ defaultValue: layerField(/* @__PURE__ */ string(), { fallback: "" }),
1581
+ required: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1582
+ placeholder: layerField(/* @__PURE__ */ string(), { fallback: "" }),
1583
+ isTextarea: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1584
+ ...GraphFieldSchema.entries
1585
+ });
1586
+ /* @__PURE__ */ object({
1587
+ name: layerField(/* @__PURE__ */ string(), {
1588
+ fallback: "Event",
1589
+ overridable: false
1590
+ }),
1591
+ type: layerField(/* @__PURE__ */ literal(variableType.Event), {
1592
+ fallback: variableType.Event
1593
+ }),
1594
+ mode: layerField(/* @__PURE__ */ picklist(Object.keys(eventMode)), {
1595
+ fallback: eventMode.callback
1596
+ }),
1597
+ defaultValue: layerField(/* @__PURE__ */ any()),
1598
+ required: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1599
+ ...GraphFieldSchema.entries
1600
+ });
1601
+ const findGroups = (state) => {
1602
+ var _a;
1603
+ const cache = (_a = state.$styleSheet) == null ? void 0 : _a.cache;
1604
+ const fragments = Array.from(cache.keys()).filter(
1605
+ (key) => key == null ? void 0 : key.includes(index.nodes.Fragment)
1606
+ ) ?? [];
1607
+ const createFragmentSlice = (fragmentLayerKey) => {
1608
+ var _a2;
1609
+ const rootLayer = (_a2 = cache.get(fragmentLayerKey)) == null ? void 0 : _a2.layer;
1610
+ const breakpoints = ((rootLayer == null ? void 0 : rootLayer.children) ?? []).map(
1611
+ (child) => {
1612
+ var _a3;
1613
+ return (_a3 = cache.get(child)) == null ? void 0 : _a3.layer;
1614
+ }
1615
+ );
1616
+ const primaryBreakpoint = breakpoints.find(
1617
+ (breakpoint) => breakpoint == null ? void 0 : breakpoint.isPrimary
1618
+ );
1619
+ const smaller = breakpoints.filter((f) => !!f && (f == null ? void 0 : f.width) < (primaryBreakpoint == null ? void 0 : primaryBreakpoint.width)).sort((a2, b2) => b2.width - a2.width);
1620
+ const larger = breakpoints.filter((f) => !!f && (f == null ? void 0 : f.width) > (primaryBreakpoint == null ? void 0 : primaryBreakpoint.width)).sort((a2, b2) => a2.width - b2.width);
1621
+ return {
1622
+ fragment: rootLayer,
1623
+ primary: primaryBreakpoint,
1624
+ smaller: smaller ?? [],
1625
+ larger: larger ?? []
1626
+ };
1627
+ };
1628
+ return fragments.map(createFragmentSlice).filter((slice) => slice.primary);
1629
+ };
1630
+ const toCSS = (styles) => Object.entries(styles).filter(([, value]) => isValue(value) && value !== "").map(
1631
+ ([key, value]) => `${key.replace(/([A-Z])/g, "-$1").toLowerCase()}: ${value};`
1632
+ ).join("\n");
1633
+ function compareRules(prev = {}, next = {}) {
1634
+ const diff = {};
1635
+ for (const key of Object.keys(next)) {
1636
+ if (prev[key] !== next[key]) {
1637
+ diff[key] = next[key];
1638
+ }
1639
+ }
1640
+ return diff;
1641
+ }
1642
+ const makeCss = (state) => (entity) => {
1643
+ var _a, _b, _c, _d, _e;
1644
+ const cache = (_a = state.$styleSheet) == null ? void 0 : _a.cache;
1645
+ const layerKey = state.keyOfEntity(entity);
1646
+ const cacheLayer = cache.get(layerKey);
1647
+ const isPrimary = !((_b = cacheLayer == null ? void 0 : cacheLayer.layer) == null ? void 0 : _b.overrideFrom);
1648
+ const layerHash = hashGenerator(
1649
+ isPrimary ? layerKey : getKey((_c = cacheLayer == null ? void 0 : cacheLayer.layer) == null ? void 0 : _c.overrideFrom)
1650
+ );
1651
+ const layerCss = cacheLayer == null ? void 0 : cacheLayer.styles;
1652
+ const overriderLayerCss = ((_e = cache.get(getKey((_d = cacheLayer == null ? void 0 : cacheLayer.layer) == null ? void 0 : _d.overrideFrom))) == null ? void 0 : _e.styles) ?? {};
1653
+ const resultCssRules = compareRules(overriderLayerCss, layerCss);
1654
+ return {
1655
+ hash: layerHash,
1656
+ css: toCSS(resultCssRules)
1657
+ };
1658
+ };
1659
+ const getAllChildren = (state, start, acc = []) => {
1660
+ var _a, _b;
1661
+ const cache = (_a = state.$styleSheet) == null ? void 0 : _a.cache;
1662
+ const layerKey = state.keyOfEntity(start);
1663
+ const { layer } = cache.get(layerKey) ?? {};
1664
+ if (acc.length === 0) {
1665
+ acc.push(layerKey);
1666
+ }
1667
+ (_b = layer == null ? void 0 : layer.children) == null ? void 0 : _b.forEach((child) => {
1668
+ acc.push(child);
1669
+ getAllChildren(state, child, acc);
1670
+ });
1671
+ return acc;
1672
+ };
1673
+ const buildCssBlock = (block) => {
1674
+ if (!block || block.css === "") return "";
1675
+ return `.${block.hash} {${block.css}}`;
1676
+ };
1677
+ const styleSheetPlugin = (state) => {
1678
+ const extractStyleSheet = () => {
1679
+ const fragments = findGroups(state);
1680
+ const cssMaker = makeCss(state);
1681
+ const fragmentsStyle = fragments.map((group) => {
1682
+ const fragmentCssRules = [];
1683
+ fragmentCssRules.push(buildCssBlock(cssMaker(group.fragment)));
1684
+ const children = getAllChildren(state, group.primary);
1685
+ const primaryCssBlocks = children.map(cssMaker);
1686
+ primaryCssBlocks.forEach((block) => {
1687
+ fragmentCssRules.push(buildCssBlock(block));
1688
+ });
1689
+ group.smaller.forEach((smallerLayer, index2, arr) => {
1690
+ const smallerChildren = getAllChildren(state, smallerLayer);
1691
+ const smallerCssBlocks = smallerChildren.map(cssMaker);
1692
+ const max = index2 === 0 ? group.primary.width - 1 : arr[index2 - 1].width;
1693
+ fragmentCssRules.push(
1694
+ `@container (max-width: ${max}px) {${smallerCssBlocks.map(buildCssBlock).join("")}}`
1695
+ );
1696
+ });
1697
+ group.larger.forEach((largerLayer, index2, arr) => {
1698
+ const largerChildren = getAllChildren(state, largerLayer);
1699
+ const largerCssBlocks = largerChildren.map((l) => cssMaker(l, 123));
1700
+ const min = largerLayer.width;
1701
+ const max = index2 < arr.length - 1 ? arr[index2 + 1].width - 1 : null;
1702
+ const containerQuery = max ? `@container (min-width: ${min}px) and (max-width: ${max}px)` : `@container (min-width: ${min}px)`;
1703
+ fragmentCssRules.push(
1704
+ `${containerQuery} {${largerCssBlocks.map(buildCssBlock).join("")}}`
1705
+ );
1706
+ });
1707
+ fragmentCssRules.push(`[data-key^="Text"] { p {margin: 0;} }`);
1708
+ return {
1709
+ fragment: state.keyOfEntity(group.fragment),
1710
+ styles: fragmentCssRules
1711
+ };
1712
+ });
1713
+ return fragmentsStyle;
1714
+ };
1715
+ state.$styleSheet = {
1716
+ cache: /* @__PURE__ */ new Map(),
1717
+ addStyle: (layerKey, styles, layer) => {
1718
+ var _a, _b;
1719
+ return (_b = (_a = state.$styleSheet) == null ? void 0 : _a.cache) == null ? void 0 : _b.set(layerKey, { styles, layer });
1720
+ },
1721
+ extract: extractStyleSheet
1722
+ };
1723
+ };
1724
+ const fragmentsPlugin = (state) => {
1725
+ const createFragmentManager = (fragmentId, initialDocument = {}) => {
1726
+ var _a, _b;
1727
+ if (!fragmentId || !initialDocument) return null;
1728
+ const cacheManager = (_b = (_a = state.resolve(state.$fragments.key)) == null ? void 0 : _a.managers) == null ? void 0 : _b[fragmentId];
1729
+ if (cacheManager) {
1730
+ return cacheManager;
1731
+ }
1732
+ const tempGraph = {
1733
+ _type: "Temp",
1734
+ _id: "root"
1735
+ };
1736
+ const springGraph = {
1737
+ _type: "Spring",
1738
+ _id: "root"
1739
+ };
1740
+ const manager = it({
1741
+ _type: "FragmentManager",
1742
+ _id: fragmentId,
1743
+ initialState: initialDocument,
1744
+ plugins: [
1745
+ (state2) => {
1746
+ state2.$fragment = {
1747
+ root: `${index.nodes.Fragment}:${fragmentId}`,
1748
+ temp: "Temp:root"
1749
+ };
1750
+ },
1751
+ // cssPlugin,
1752
+ styleSheetPlugin
1753
+ ],
1754
+ skip: [b, a, isKey]
1755
+ });
1756
+ manager.mutate(tempGraph);
1757
+ manager.mutate(springGraph);
1758
+ state.mutate(state.$fragments.key, {
1759
+ managers: {
1760
+ [fragmentId]: manager
1761
+ }
1762
+ });
1763
+ };
1764
+ const getManager = (fragmentId) => {
1765
+ var _a, _b;
1766
+ return (_b = (_a = state.resolve(state.$fragments.key)) == null ? void 0 : _a.managers) == null ? void 0 : _b[fragmentId];
1767
+ };
1768
+ const getManagers = () => {
1769
+ var _a;
1770
+ return (_a = state.resolve(state.$fragments.key)) == null ? void 0 : _a.managers;
1771
+ };
1772
+ state.$fragments = {
1773
+ key: `FragmentsPlugin:root`,
1774
+ createFragmentManager,
1775
+ getManager,
1776
+ getManagers
1777
+ };
1778
+ state.mutate({
1779
+ _type: "FragmentsPlugin",
1780
+ _id: "root",
1781
+ managers: {}
1782
+ });
1783
+ return state;
1784
+ };
1785
+ const addClientMetric = `mutation AddClientMetric($type: ClientMetricType!, $value: String) {
1786
+ addClientMetric(metric: {metricType: $type, metricValue: $value})
1787
+ }`;
1788
+ const types = createConstants$1(
1789
+ "INIT_SESSION",
1790
+ "RELEASE_SESSION",
1791
+ "REACH_PROJECT_GOAL"
1792
+ );
1793
+ const metricsPlugin = (state) => {
1794
+ const sendMetric = (type, value) => {
1795
+ var _a, _b;
1796
+ (_a = state == null ? void 0 : state.$fetch) == null ? void 0 : _a.sendBeacon;
1797
+ const query = (_b = state == null ? void 0 : state.$fetch) == null ? void 0 : _b.query;
1798
+ query(addClientMetric, { type, value });
1799
+ };
1800
+ const initClient = async () => {
1801
+ console.log("initClient");
1802
+ sendMetric(types.INIT_SESSION);
1803
+ };
1804
+ const releaseClient = async () => {
1805
+ sendMetric(types.RELEASE_SESSION);
1806
+ };
1807
+ const reachGoal = (goal) => {
1808
+ sendMetric(types.REACH_PROJECT_GOAL, goal);
1809
+ };
1810
+ state.$metrics = {
1811
+ initClient,
1812
+ releaseClient,
1813
+ reachGoal
1814
+ };
1815
+ };
1816
+ const createFragmentsClient = (options) => {
1817
+ return it({
1818
+ _type: "GlobalManager",
1819
+ initialState: {},
1820
+ plugins: [
1821
+ (state) => {
1822
+ state.env = {
1823
+ isSelf: (options == null ? void 0 : options.isSelf) ?? false,
1824
+ url: options == null ? void 0 : options.url,
1825
+ apiToken: options == null ? void 0 : options.apiToken
1826
+ };
1827
+ state.$global = {};
1828
+ state.extractStyles = async () => {
1829
+ const allFragments = state.$fragments.getManagers();
1830
+ const extractors = Object.entries(allFragments).filter(([, value]) => !!(value == null ? void 0 : value.resolve)).map(([, manager]) => manager.$styleSheet.extract());
1831
+ const extractedStyles = await Promise.all(extractors);
1832
+ return Object.values(
1833
+ extractedStyles.reduce((acc, extrected) => {
1834
+ Object.entries(extrected).forEach(([key, styleTag]) => {
1835
+ acc[key] = styleTag;
1836
+ });
1837
+ return acc;
1838
+ }, {})
1839
+ );
1840
+ };
1841
+ },
1842
+ fetchPlugin,
1843
+ fragmentsPlugin,
1844
+ metricsPlugin,
1845
+ (state) => {
1846
+ var _a, _b, _c, _d, _e;
1847
+ if (isBrowser_default) {
1848
+ if (!((_a = state == null ? void 0 : state.env) == null ? void 0 : _a.isSelf)) {
1849
+ (_c = (_b = state == null ? void 0 : state.$metrics) == null ? void 0 : _b.initClient) == null ? void 0 : _c.call(_b);
1850
+ window.addEventListener(
1851
+ "beforeunload",
1852
+ (_e = (_d = state == null ? void 0 : state.$metrics) == null ? void 0 : _d.releaseClient) == null ? void 0 : _e.call(_d)
1853
+ );
1854
+ }
1855
+ }
1856
+ }
1857
+ ]
1858
+ });
1859
+ };
1860
+ export {
1861
+ createFragmentsClient
1862
+ };