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