@fragmentsx/client-core 0.1.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/dist/fragmentsClient.d.ts +26 -0
  2. package/dist/fragmentsClient.d.ts.map +1 -0
  3. package/dist/index.cjs.js +681 -740
  4. package/dist/index.d.ts +3 -0
  5. package/dist/index.d.ts.map +1 -0
  6. package/dist/index.es.js +681 -740
  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 +8 -0
  12. package/dist/plugins/fetch/fetcher.d.ts.map +1 -0
  13. package/dist/plugins/fetch/index.d.ts +30 -0
  14. package/dist/plugins/fetch/index.d.ts.map +1 -0
  15. package/dist/plugins/fetch/queries/AreaListQuery.d.ts +43 -0
  16. package/dist/plugins/fetch/queries/AreaListQuery.d.ts.map +1 -0
  17. package/dist/plugins/fetch/queries/AreaQuery.d.ts +24 -0
  18. package/dist/plugins/fetch/queries/AreaQuery.d.ts.map +1 -0
  19. package/dist/plugins/fetch/queries/FragmentQuery.d.ts +31 -0
  20. package/dist/plugins/fetch/queries/FragmentQuery.d.ts.map +1 -0
  21. package/dist/plugins/fetch/queries/parts.d.ts +5 -0
  22. package/dist/plugins/fetch/queries/parts.d.ts.map +1 -0
  23. package/dist/plugins/fonts/index.d.ts +10 -0
  24. package/dist/plugins/fonts/index.d.ts.map +1 -0
  25. package/dist/plugins/fragments/index.d.ts +17 -0
  26. package/dist/plugins/fragments/index.d.ts.map +1 -0
  27. package/dist/plugins/lifecycle/globalManagerLifeCycle.d.ts +16 -0
  28. package/dist/plugins/lifecycle/globalManagerLifeCycle.d.ts.map +1 -0
  29. package/dist/plugins/load/index.d.ts +18 -0
  30. package/dist/plugins/load/index.d.ts.map +1 -0
  31. package/dist/plugins/metrics/globalMetrics.d.ts +11 -0
  32. package/dist/plugins/metrics/globalMetrics.d.ts.map +1 -0
  33. package/dist/plugins/metrics/index.d.ts +3 -0
  34. package/dist/plugins/metrics/index.d.ts.map +1 -0
  35. package/dist/plugins/metrics/queries/addClientMetric.d.ts +2 -0
  36. package/dist/plugins/metrics/queries/addClientMetric.d.ts.map +1 -0
  37. package/dist/plugins/metrics/trackAdPixel.d.ts +4 -0
  38. package/dist/plugins/metrics/trackAdPixel.d.ts.map +1 -0
  39. package/dist/plugins/scopes/index.d.ts +11 -0
  40. package/dist/plugins/scopes/index.d.ts.map +1 -0
  41. package/dist/plugins/ssr/index.d.ts +11 -0
  42. package/dist/plugins/ssr/index.d.ts.map +1 -0
  43. package/dist/plugins/styleSheet/fragment/index.d.ts +9 -0
  44. package/dist/plugins/styleSheet/fragment/index.d.ts.map +1 -0
  45. package/dist/plugins/styleSheet/global/index.d.ts +3 -0
  46. package/dist/plugins/styleSheet/global/index.d.ts.map +1 -0
  47. package/dist/plugins/styleSheet/index.d.ts +3 -0
  48. package/dist/plugins/styleSheet/index.d.ts.map +1 -0
  49. package/dist/plugins/styleSheet/utils/autoInjector.d.ts +9 -0
  50. package/dist/plugins/styleSheet/utils/autoInjector.d.ts.map +1 -0
  51. package/dist/plugins/styleSheet/utils/buildCssBlock.d.ts +6 -0
  52. package/dist/plugins/styleSheet/utils/buildCssBlock.d.ts.map +1 -0
  53. package/dist/plugins/styleSheet/utils/compareRules.d.ts +3 -0
  54. package/dist/plugins/styleSheet/utils/compareRules.d.ts.map +1 -0
  55. package/dist/plugins/styleSheet/utils/destroyStyle.d.ts +2 -0
  56. package/dist/plugins/styleSheet/utils/destroyStyle.d.ts.map +1 -0
  57. package/dist/plugins/styleSheet/utils/findGroups.d.ts +11 -0
  58. package/dist/plugins/styleSheet/utils/findGroups.d.ts.map +1 -0
  59. package/dist/plugins/styleSheet/utils/getAllChildren.d.ts +4 -0
  60. package/dist/plugins/styleSheet/utils/getAllChildren.d.ts.map +1 -0
  61. package/dist/plugins/styleSheet/utils/injectStyle.d.ts +2 -0
  62. package/dist/plugins/styleSheet/utils/injectStyle.d.ts.map +1 -0
  63. package/dist/plugins/styleSheet/utils/makeCss.d.ts +5 -0
  64. package/dist/plugins/styleSheet/utils/makeCss.d.ts.map +1 -0
  65. package/dist/plugins/styleSheet/utils/toCSS.d.ts +3 -0
  66. package/dist/plugins/styleSheet/utils/toCSS.d.ts.map +1 -0
  67. package/dist/plugins/styles/index.d.ts +3 -0
  68. package/dist/plugins/styles/index.d.ts.map +1 -0
  69. package/package.json +4 -4
package/dist/index.cjs.js CHANGED
@@ -6,619 +6,220 @@ var r = (e) => !e && e == null, y = (e) => !r(e), a = (e) => typeof e == "object
6
6
  let o = null;
7
7
  return s(n) && (o = (_a = n.split(":")) == null ? void 0 : _a[0]), t(n) && (o = n._type), o ? !e.includes(o) : false;
8
8
  };
9
- var isLinkKey = (input) => s(input);
10
- var isGraphOrKey = (input) => i(input);
11
- var isGraph = (input) => t(input);
12
- var isObject$1 = (input) => a(input);
13
- var shallowEqual = (a2, b) => {
14
- if (a2 === b)
15
- return true;
16
- if (Array.isArray(a2) && Array.isArray(b)) {
17
- return a2.length === b.length && a2.every((val, index2) => b[index2] === val);
18
- }
19
- if (!isObject$1(a2) || !isObject$1(b))
20
- return false;
21
- const keysA = Object.keys(a2);
22
- const keysB = Object.keys(b);
23
- if (keysA.length !== keysB.length)
24
- return false;
25
- for (const key of keysA) {
26
- if (!keysB.includes(key))
27
- return false;
28
- const aValue = a2[key];
29
- const bValue = b[key];
30
- if (l(aValue) && l(bValue) && aValue !== bValue)
31
- return false;
9
+ var D = (e) => s(e), re = (e) => i(e), se = (e) => t(e), T = (e) => a(e), ie = (e, r2) => {
10
+ if (e === r2) return true;
11
+ if (Array.isArray(e) && Array.isArray(r2)) return e.length === r2.length && e.every((c, o) => r2[o] === c);
12
+ if (!T(e) || !T(r2)) return false;
13
+ let f2 = Object.keys(e), p = Object.keys(r2);
14
+ if (f2.length !== p.length) return false;
15
+ for (let c of f2) {
16
+ if (!p.includes(c)) return false;
17
+ let o = e[c], E = r2[c];
18
+ if (l(o) && l(E) && o !== E) return false;
32
19
  }
33
20
  return true;
34
- };
35
- var deepEqual = (a2, b) => {
36
- if (a2 === b)
37
- return true;
38
- if (Array.isArray(a2) && Array.isArray(b)) {
39
- return a2.length === b.length && a2.every((val, i2) => deepEqual(val, b[i2]));
40
- }
41
- if (!isObject$1(b) || !isObject$1(a2))
42
- return a2 === b;
43
- const keysA = Object.keys(a2);
44
- const keysB = Object.keys(b);
45
- if (keysA.length !== keysB.length)
46
- return false;
47
- for (const key of keysA) {
48
- if (!keysB.includes(key))
49
- return false;
50
- if (!deepEqual(a2[key], b[key]))
51
- return false;
52
- }
21
+ }, z = (e, r2) => {
22
+ if (e === r2) return true;
23
+ if (Array.isArray(e) && Array.isArray(r2)) return e.length === r2.length && e.every((c, o) => z(c, r2[o]));
24
+ if (!T(r2) || !T(e)) return e === r2;
25
+ let f2 = Object.keys(e), p = Object.keys(r2);
26
+ if (f2.length !== p.length) return false;
27
+ for (let c of f2) if (!p.includes(c) || !z(e[c], r2[c])) return false;
53
28
  return true;
54
29
  };
55
- var unique = (...values) => Array.from(new Set(values));
56
- var uniqueLinks = (...values) => values.filter((item, index2, arr) => s(item) ? arr.indexOf(item) === index2 : true);
57
- var isPartialKey = (key) => key && key.split(".").length > 1;
58
- var isPartialGraph = (entity) => {
59
- if (isObject$1(entity) && "_id" in entity && typeof entity._id === "string") {
60
- return entity._id.includes(".");
61
- }
62
- return false;
63
- };
64
- var isPartOfGraph = (entityKey, graphKey) => {
65
- if (!entityKey || !graphKey)
66
- return false;
67
- if (typeof entityKey !== "string" || typeof graphKey !== "string")
68
- return null;
69
- const [entityType, entityId] = entityKey.split(":");
70
- const [graphType, graphId] = graphKey.split(":");
71
- if (entityType !== graphType)
72
- return false;
73
- return entityId.startsWith(graphId);
74
- };
75
- var getGraphLink = (input) => {
76
- if (isLinkKey(input)) {
77
- if (isPartialKey(input)) {
78
- return input.split(".")[0];
79
- }
80
- }
81
- return input;
82
- };
83
- var createCache = () => {
84
- const listeners = /* @__PURE__ */ new Map();
85
- const types2 = /* @__PURE__ */ new Map();
86
- const links = /* @__PURE__ */ new Map();
87
- const parentRefs = /* @__PURE__ */ new Map();
88
- const childrenRefs = /* @__PURE__ */ new Map();
89
- const refCount = /* @__PURE__ */ new Map();
90
- const gbLinks = /* @__PURE__ */ new Set([]);
91
- const addRefs = (targetKey, depKey) => {
30
+ var Q = (...e) => Array.from(new Set(e)), oe = (...e) => e.filter((r2, f2, p) => s(r2) ? p.indexOf(r2) === f2 : true);
31
+ var P = (e) => e && e.split(".").length > 1, X = (e, r2) => {
32
+ if (!e || !r2) return false;
33
+ if (typeof e != "string" || typeof r2 != "string") return null;
34
+ let [f2, p] = e.split(":"), [c, o] = r2.split(":");
35
+ return f2 !== c ? false : p.startsWith(o);
36
+ }, ae = (e) => D(e) && P(e) ? e.split(".")[0] : e;
37
+ var ce = () => {
38
+ let e = /* @__PURE__ */ new Map(), r2 = /* @__PURE__ */ new Map(), f2 = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), E = /* @__PURE__ */ new Set([]), V = (n, u2) => {
92
39
  var _a;
93
- parentRefs.set(targetKey, unique(...parentRefs.get(targetKey) || [], depKey));
94
- childrenRefs.set(depKey, unique(...childrenRefs.get(depKey) ?? [], targetKey));
95
- updateRefCountForLink(targetKey, ((_a = parentRefs.get(targetKey)) == null ? void 0 : _a.length) || 0);
96
- };
97
- const removeRefs = (targetKey, depKey) => {
40
+ p.set(n, Q(...p.get(n) || [], u2)), c.set(u2, Q(...c.get(u2) ?? [], n)), M(n, ((_a = p.get(n)) == null ? void 0 : _a.length) || 0);
41
+ }, x = (n, u2) => {
98
42
  var _a;
99
- parentRefs.set(
100
- depKey,
101
- (parentRefs.get(depKey) || []).filter((key) => key !== targetKey)
102
- );
103
- childrenRefs.set(
104
- targetKey,
105
- (childrenRefs.get(targetKey) ?? []).filter((key) => key !== depKey)
106
- );
107
- updateRefCountForLink(depKey, ((_a = parentRefs.get(depKey)) == null ? void 0 : _a.length) || 0);
108
- };
109
- const getLinkedRefs = (key, stack = []) => {
110
- const deps = parentRefs.get(key) || [];
111
- stack.push(...deps);
112
- const deepDeps = deps.map((ref) => getLinkedRefs(ref, stack)).flat();
113
- stack.push(...deepDeps);
114
- return Array.from(new Set(stack).values());
115
- };
116
- const invalidate = (key) => {
117
- updateRefCountForLink(key, 0);
118
- runGarbageCollector();
119
- };
120
- const readLink = (key) => {
121
- if (key) {
122
- return links.get(key);
123
- }
124
- return null;
125
- };
126
- const writeLink = (key, value, depKey) => {
43
+ p.set(u2, (p.get(u2) || []).filter((k) => k !== n)), c.set(n, (c.get(n) ?? []).filter((k) => k !== u2)), M(u2, ((_a = p.get(u2)) == null ? void 0 : _a.length) || 0);
44
+ }, I = (n, u2 = []) => {
45
+ let k = p.get(n) || [];
46
+ u2.push(...k);
47
+ let S = k.map((L) => I(L, u2)).flat();
48
+ return u2.push(...S), Array.from(new Set(u2).values());
49
+ }, A = (n) => {
50
+ M(n, 0), B();
51
+ }, Y = (n) => n ? f2.get(n) : null, w = (n, u2, k) => {
127
52
  var _a;
128
- if (typeof key === "string") {
129
- links.set(key, value);
130
- const [type] = key.split(":");
131
- if (!isPartialKey(key)) {
132
- if (!types2.has(type)) {
133
- types2.set(type, /* @__PURE__ */ new Set([key]));
134
- } else {
135
- (_a = types2.get(type)) == null ? void 0 : _a.add(key);
136
- }
137
- }
138
- }
139
- if (depKey && key && key !== depKey) {
140
- addRefs(key, depKey);
141
- }
142
- };
143
- const hasLink = (key) => {
144
- if (key) {
145
- return links.has(key);
146
- }
147
- return false;
148
- };
149
- const updateRefCountForLink = (link, count) => {
150
- if (Array.isArray(link)) {
151
- link.forEach((link2, index2) => updateRefCountForLink(link2, index2));
152
- } else {
153
- const prevCount = refCount.get(link);
154
- refCount.set(link, count);
155
- if (!count) {
156
- gbLinks.add(link);
157
- } else if (!prevCount && count) {
158
- gbLinks.delete(link);
159
- }
160
- }
161
- };
162
- const getLinkEntries = () => Array.from(links.entries());
163
- const getRefCount = (link) => refCount.get(link) ?? 0;
164
- const runGarbageCollector = () => {
53
+ if (typeof n == "string") {
54
+ f2.set(n, u2);
55
+ let [S] = n.split(":");
56
+ P(n) || (r2.has(S) ? (_a = r2.get(S)) == null ? void 0 : _a.add(n) : r2.set(S, /* @__PURE__ */ new Set([n])));
57
+ }
58
+ k && n && n !== k && V(n, k);
59
+ }, j = (n) => n ? f2.has(n) : false, M = (n, u2) => {
60
+ if (Array.isArray(n)) n.forEach((k, S) => M(k, S));
61
+ else {
62
+ let k = o.get(n);
63
+ o.set(n, u2), u2 ? !k && u2 && E.delete(n) : E.add(n);
64
+ }
65
+ }, N = () => Array.from(f2.entries()), _ = (n) => o.get(n) ?? 0, B = () => {
165
66
  var _a, _b;
166
- for (const link of gbLinks.keys()) {
167
- const count = getRefCount(link);
168
- if (count > 0)
169
- continue;
170
- const currentValue = links.get(link);
171
- gbLinks.delete(link);
172
- links.delete(link);
173
- refCount.delete(link);
174
- const parents = parentRefs.get(link) ?? [];
175
- const children = childrenRefs.get(link) ?? [];
176
- parents.forEach((parentKey) => {
67
+ for (let n of E.keys()) {
68
+ if (_(n) > 0) continue;
69
+ let k = f2.get(n);
70
+ E.delete(n), f2.delete(n), o.delete(n);
71
+ let S = p.get(n) ?? [], L = c.get(n) ?? [];
72
+ S.forEach((K) => {
177
73
  var _a2, _b2;
178
- childrenRefs.set(parentKey, ((_b2 = (_a2 = childrenRefs.get(parentKey)) == null ? void 0 : _a2.filter) == null ? void 0 : _b2.call(_a2, (childLink) => childLink !== link)) ?? []);
179
- });
180
- children.forEach((childKey) => {
181
- updateRefCountForLink(childKey, getRefCount(childKey) - 1);
74
+ c.set(K, ((_b2 = (_a2 = c.get(K)) == null ? void 0 : _a2.filter) == null ? void 0 : _b2.call(_a2, (J) => J !== n)) ?? []);
75
+ }), L.forEach((K) => {
76
+ M(K, _(K) - 1);
182
77
  });
183
- const [type] = link.split(":");
184
- if (!isPartialKey(link)) {
185
- (_a = types2.get(type)) == null ? void 0 : _a.delete(link);
186
- if (!((_b = types2.get(type)) == null ? void 0 : _b.size)) {
187
- types2.delete(type);
188
- }
189
- }
190
- parentRefs.delete(link);
191
- (listeners.get("onRemoveLink") ?? []).forEach((listener) => listener(link, currentValue ?? null));
78
+ let [C] = n.split(":");
79
+ P(n) || ((_a = r2.get(C)) == null ? void 0 : _a.delete(n), ((_b = r2.get(C)) == null ? void 0 : _b.size) || r2.delete(C)), p.delete(n), (e.get("onRemoveLink") ?? []).forEach((K) => K(n, k ?? null));
192
80
  }
193
81
  };
194
- return {
195
- readLink,
196
- writeLink,
197
- hasLink,
198
- getLinkEntries,
199
- parentRefs,
200
- childrenRefs,
201
- addRefs,
202
- removeRefs,
203
- getChildren: (key) => childrenRefs.get(key),
204
- getParents: (key) => parentRefs.get(key),
205
- getLinkedRefs,
206
- invalidate,
207
- links,
208
- types: types2,
209
- refCount,
210
- runGarbageCollector,
211
- onRemoveLink: (callback) => listeners.set("onRemoveLink", [...(listeners == null ? void 0 : listeners.get("onRemoveLink")) ?? [], callback])
212
- };
82
+ return { readLink: Y, writeLink: w, hasLink: j, getLinkEntries: N, parentRefs: p, childrenRefs: c, addRefs: V, removeRefs: x, getChildren: (n) => c.get(n), getParents: (n) => p.get(n), getLinkedRefs: I, invalidate: A, links: f2, types: r2, refCount: o, runGarbageCollector: B, onRemoveLink: (n) => e.set("onRemoveLink", [...(e == null ? void 0 : e.get("onRemoveLink")) ?? [], n]) };
213
83
  };
214
- var joinKeys = (...keys) => {
84
+ var Z = (...e) => {
215
85
  var _a;
216
- return (_a = keys == null ? void 0 : keys.filter(Boolean)) == null ? void 0 : _a.join(".");
86
+ return (_a = e == null ? void 0 : e.filter(Boolean)) == null ? void 0 : _a.join(".");
217
87
  };
218
- var isDev = process.env.NODE_ENV !== "production";
219
- var createPluginsState = (initialPlugins = []) => {
220
- const plugins = [];
221
- const use = (plugin) => {
222
- plugins.push(plugin);
223
- };
224
- const runPlugins = (state) => {
225
- return plugins.reduce((graphState, plugin) => plugin(graphState) ?? graphState, state);
226
- };
227
- initialPlugins.forEach(use);
228
- return {
229
- use,
230
- runPlugins
231
- };
232
- };
233
- var isGraphState = (input) => {
234
- if (!input)
235
- return false;
236
- if (isObject$1(input)) {
237
- const fields = ["_id", "_type", "key", "mutate", "resolve"];
238
- return fields.every((field) => field in input);
239
- }
240
- return false;
88
+ var pe = process.env.NODE_ENV !== "production";
89
+ var fe = (e = []) => {
90
+ let r2 = [], f2 = (c) => {
91
+ r2.push(c);
92
+ }, p = (c) => r2.reduce((o, E) => E(o) ?? o, c);
93
+ return e.forEach(f2), { use: f2, runPlugins: p };
241
94
  };
242
- var createDebugState = () => {
243
- const listeners = /* @__PURE__ */ new Set();
244
- const onDebugEvent = (callback) => {
245
- listeners.add(callback);
246
- };
247
- const debug = (event) => {
248
- listeners.forEach((callback) => {
249
- callback({ ...event, timestamp: Date.now() });
95
+ var le = (e) => e && T(e) ? ["_id", "_type", "key", "mutate", "resolve"].every((f2) => f2 in e) : false;
96
+ var ue = () => {
97
+ let e = /* @__PURE__ */ new Set();
98
+ return { debug: (p) => {
99
+ e.forEach((c) => {
100
+ c({ ...p, timestamp: Date.now() });
250
101
  });
251
- };
252
- return {
253
- debug,
254
- onDebugEvent
255
- };
102
+ }, onDebugEvent: (p) => {
103
+ e.add(p);
104
+ } };
256
105
  };
257
- var cache = /* @__PURE__ */ new Set();
258
- var wrapMessage = (message) => `[GraphState]: ${message}`;
259
- function warn(message) {
260
- if (!cache.has(message)) {
261
- console.warn(wrapMessage(message));
262
- cache.add(message);
263
- }
106
+ var ye = /* @__PURE__ */ new Set(), Se = (e) => `[GraphState]: ${e}`;
107
+ function ee(e) {
108
+ ye.has(e) || (console.warn(Se(e)), ye.add(e));
264
109
  }
265
- var keyOfEntity = (entity) => {
266
- if (typeof entity === "string") {
267
- return entityOfKey(entity) ? entity : null;
268
- }
269
- if (!(entity == null ? void 0 : entity._type)) {
270
- return null;
271
- }
272
- let entityId = null;
273
- if (y(entity.id) || y(entity._id)) {
274
- entityId = `${entity.id ?? entity._id}`;
275
- }
276
- return !entityId ? entityId : `${entity._type}:${entityId}`;
110
+ var $ = (e) => {
111
+ if (typeof e == "string") return q(e) ? e : null;
112
+ if (!(e == null ? void 0 : e._type)) return null;
113
+ let r2 = null;
114
+ return (y(e.id) || y(e._id)) && (r2 = `${e.id ?? e._id}`), r2 && `${e._type}:${r2}`;
277
115
  };
278
- var entityOfKey = (entity) => {
279
- if (isObject$1(entity) && (entity == null ? void 0 : entity._type) && keyOfEntity(entity)) {
280
- return entity;
281
- }
282
- if (!entity || typeof entity !== "string")
283
- return null;
284
- const [typeName, ...restTypes] = entity.split(":");
285
- if (!typeName || restTypes.length < 1)
286
- return null;
287
- return {
288
- _type: typeName,
289
- _id: restTypes.join(":")
290
- };
116
+ var q = (e) => {
117
+ if (T(e) && (e == null ? void 0 : e._type) && $(e)) return e;
118
+ if (!e || typeof e != "string") return null;
119
+ let [r2, ...f2] = e.split(":");
120
+ return !r2 || f2.length < 1 ? null : { _type: r2, _id: f2.join(":") };
291
121
  };
292
- function omit(obj, ...props) {
293
- const result = { ...obj };
294
- props.forEach((prop) => {
295
- delete result[prop];
296
- });
297
- return result;
298
- }
299
- var ID = 0;
300
- var DEEP_LIMIT = 100;
301
- var STATE_TYPE = "State";
302
- var EACH_UPDATED = "$EACH:ROOT$";
303
- var createState = (options) => {
304
- const id = (options == null ? void 0 : options._id) ?? `${ID++}`;
305
- const type = (options == null ? void 0 : options._type) ?? STATE_TYPE;
306
- const stateKey = `${type}:${id}`;
307
- const skipPredictors = [isGraphState, ...(options == null ? void 0 : options.skip) ?? []];
308
- const cache2 = createCache();
309
- const debugState = createDebugState();
310
- const pluginsStore = createPluginsState(options == null ? void 0 : options.plugins);
311
- const subscribers = /* @__PURE__ */ new Map();
312
- let deepIndex = 0;
313
- const isSkipped = (entity) => {
314
- return skipPredictors.some((predictor) => predictor(entity));
315
- };
316
- const getReferences = (entity, options2) => {
317
- const withPartialKeys = (options2 == null ? void 0 : options2.withPartialKeys) ?? false;
318
- const key = keyOfEntity2(entity);
319
- if (!key)
320
- return [];
321
- const values = cache2.getParents(key) ?? [];
322
- return values.filter((v) => withPartialKeys ? !isPartialKey(v) : v);
323
- };
324
- const resolve = (input, options2) => {
325
- const isDeep = (options2 == null ? void 0 : options2.deep) ?? false;
326
- const isSafe = (options2 == null ? void 0 : options2.safe) ?? false;
327
- const keepLinks = (options2 == null ? void 0 : options2.keepLinks) ?? false;
328
- const removeLinkFromSubGraph = (options2 == null ? void 0 : options2.removeLinkFromSubGraph) ?? true;
329
- const { selector, ...coreOptions } = options2 || {};
330
- const inputKey = y(input) ? keyOfEntity2(input) : null;
331
- debugState.debug({ type: "resolve", entity: input, options: options2 });
332
- let value = inputKey ? cache2.readLink(inputKey) : null;
333
- if (isSkipped(value))
334
- return value;
335
- if (isObject$1(value) || Array.isArray(value)) {
336
- value = Object.entries(value).reduce((acc, [key, value2]) => {
337
- let resultValue = value2;
338
- if (!isSkipped(resultValue)) {
339
- if (Array.isArray(value2)) {
340
- resultValue = value2.map((v) => {
341
- if (isSkipped(v))
342
- return v;
343
- if (isLinkKey(v) && !isSafe && !cache2.hasLink(v)) {
344
- return null;
345
- }
346
- return isPartOfGraph(v, inputKey) && !keepLinks || isDeep ? safeResolve(v, coreOptions) : v;
347
- });
348
- if (!isSafe) {
349
- resultValue = resultValue.filter(y);
350
- }
351
- } else {
352
- if (isLinkKey(value2) && !isSafe && !cache2.hasLink(value2)) {
353
- resultValue = null;
354
- } else if (isPartOfGraph(keyOfEntity2(value2), inputKey) && !keepLinks || isDeep) {
355
- resultValue = safeResolve(value2, coreOptions);
356
- }
357
- }
358
- }
359
- acc[key] = isPartialGraph(resultValue) && removeLinkFromSubGraph ? omit(resultValue, "_type", "_id") : resultValue;
360
- return acc;
361
- }, {});
362
- }
363
- return value ? selector ? selector({ ...value }) : { ...value } : isSafe ? input : null;
364
- };
365
- const safeResolve = (input, options2) => resolve(input, options2) ?? input;
366
- const unlinkGraph = (entity) => {
367
- const graphKey = keyOfEntity2(entity);
368
- if (graphKey) {
369
- const deps = cache2.getChildren(graphKey) || [];
370
- deps.forEach((depLink) => {
371
- if (!isPartialKey(depLink)) {
372
- cache2.removeRefs(graphKey, depLink);
373
- }
374
- });
375
- }
376
- };
377
- const mutateField = (input, parentFieldKey, options2) => {
122
+ var he = 0, Re = 100, we = "State", me = "$EACH:ROOT$", kt = (e) => {
123
+ let r2 = (e == null ? void 0 : e._id) ?? `${he++}`, f2 = (e == null ? void 0 : e._type) ?? we, p = `${f2}:${r2}`, c = [le, ...(e == null ? void 0 : e.skip) ?? []], o = ce(), E = ue(), V = fe(e == null ? void 0 : e.plugins), x = /* @__PURE__ */ new Map(), I = 0, A = (t2) => c.some((i2) => i2(t2)), Y = (t2, i2) => {
124
+ let a2 = (i2 == null ? void 0 : i2.withPartialKeys) ?? false, s2 = L(t2);
125
+ return s2 ? (o.getParents(s2) ?? []).filter((g2) => a2 ? !P(g2) : g2) : [];
126
+ }, w = (t2, i2) => {
127
+ let a2 = (i2 == null ? void 0 : i2.deep) ?? false, s2 = (i2 == null ? void 0 : i2.safe) ?? false, l2 = (i2 == null ? void 0 : i2.keepLinks) ?? false, { selector: g2, ...y$1 } = i2 || {}, d = y(t2) ? L(t2) : null;
128
+ E.debug({ type: "resolve", entity: t2, options: i2 });
129
+ let h = d ? o.readLink(d) : null;
130
+ return A(h) ? h : ((T(h) || Array.isArray(h)) && (h = Object.entries(h).reduce((b, [G, m]) => {
131
+ let R = m;
132
+ return A(R) || (Array.isArray(m) ? (R = m.map((O) => A(O) ? O : D(O) && !s2 && !o.hasLink(O) ? null : X(O, d) && !l2 || a2 ? j(O, y$1) : O), s2 || (R = R.filter(y))) : D(m) && !s2 && !o.hasLink(m) ? R = null : (X(L(m), d) && !l2 || a2) && (R = j(m, y$1))), b[G] = R, b;
133
+ }, {})), h ? g2 ? g2({ ...h }) : { ...h } : s2 ? t2 : null);
134
+ }, j = (t2, i2) => w(t2, i2) ?? t2, M = (t2) => {
135
+ let i2 = L(t2);
136
+ i2 && (o.getChildren(i2) || []).forEach((s2) => {
137
+ P(s2) || o.removeRefs(i2, s2);
138
+ });
139
+ }, N = (t2, i2, a2) => {
378
140
  var _a, _b, _c, _d;
379
- if ((!input || l(input)) && !isLinkKey(input) || isSkipped(input)) {
380
- return input;
381
- }
382
- const inputLinkKey = isGraphOrKey(input) ? keyOfEntity2(input) : input;
383
- if (isLinkKey(inputLinkKey)) {
384
- const parentGraph = getGraphLink(parentFieldKey) ?? "";
385
- const parentPaths = ((_a = options2 == null ? void 0 : options2.internal) == null ? void 0 : _a.visitors.get(parentGraph)) ?? [];
386
- const visitorsPaths = ((_b = options2 == null ? void 0 : options2.internal) == null ? void 0 : _b.visitors.get(inputLinkKey)) ?? [];
387
- if (parentPaths.includes(inputLinkKey) || inputLinkKey === parentGraph) {
388
- return null;
389
- }
390
- (_d = (_c = options2 == null ? void 0 : options2.internal) == null ? void 0 : _c.visitors) == null ? void 0 : _d.set(inputLinkKey, [...visitorsPaths, parentGraph]);
391
- }
392
- if (Array.isArray(input)) {
393
- return input.map((item) => {
394
- const indexKey = parentFieldKey ? joinKeys(parentFieldKey, `${ID++}`) : void 0;
395
- return mutateField(item, indexKey, options2);
396
- });
397
- }
398
- const entityKey = isLinkKey(input) ? input : isGraph(input) ? keyOfEntity2(input) : null;
399
- const childKey = entityKey ?? parentFieldKey;
400
- const mutateMethod = (options2 == null ? void 0 : options2.overrideMutateMethod) || mutate;
401
- return mutateMethod(childKey, input, options2);
402
- };
403
- const mutate = (entity, ...args) => {
404
- const { graphKey: entityGraphKey, options: options2, data: rawData } = getArgumentsForMutate(entity, ...args);
405
- debugState.debug({ type: "beforeMutate", entity: entityGraphKey, data: rawData, options: options2 });
406
- const data = isLinkKey(rawData) ? entityOfKey2(rawData) : rawData;
407
- const graphKey = entityGraphKey ?? stateKey;
408
- const partialKey = isPartialKey == null ? void 0 : isPartialKey(graphKey);
409
- const parentKey = options2 == null ? void 0 : options2.parent;
410
- const prevGraph = resolve(graphKey ?? "", { removeLinkFromSubGraph: false });
411
- const internal = (options2 == null ? void 0 : options2.internal) || { hasChange: false, visitors: /* @__PURE__ */ new Map([]) };
412
- let graphData = {
413
- ...data,
414
- ...entityOfKey2(graphKey)
415
- };
416
- const isTopLevelGraph = !(options2 == null ? void 0 : options2.parent);
417
- const isReplace = (options2 == null ? void 0 : options2.replace) ? typeof (options2 == null ? void 0 : options2.replace) === "function" ? options2.replace(graphData) : (options2 == null ? void 0 : options2.replace) === "deep" ? true : isTopLevelGraph || partialKey : false;
418
- if (isSkipped(data)) {
419
- cache2.writeLink(graphKey, data, parentKey);
420
- return graphKey;
421
- }
422
- if (!isReplace && isObject$1(prevGraph) && isObject$1(graphData)) {
423
- graphData = {
424
- ...prevGraph,
425
- ...graphData
426
- };
427
- }
428
- if (isReplace) {
429
- unlinkGraph(graphKey);
430
- }
431
- const nextGraph = Object.entries(graphData).reduce((acc, [key, value]) => {
432
- const fieldKey = joinKeys(graphKey, key);
433
- let fieldValue = value;
434
- const prevValue = prevGraph == null ? void 0 : prevGraph[key];
435
- const isUpdateField = isObject$1(data) && key in data;
436
- if (!isSkipped(fieldValue)) {
437
- if (!isReplace && isUpdateField && Array.isArray(fieldValue) && Array.isArray(prevValue)) {
438
- fieldValue = [...prevValue, ...fieldValue];
439
- }
440
- if (isObject$1(fieldValue) || Array.isArray(fieldValue) || isLinkKey(fieldValue)) {
441
- fieldValue = mutateField(fieldValue, fieldKey, {
442
- ...options2,
443
- parent: graphKey,
444
- internal
445
- });
446
- }
447
- if (Array.isArray(fieldValue) && (options2 == null ? void 0 : options2.dedup) !== false) {
448
- fieldValue = uniqueLinks(...fieldValue);
449
- }
450
- }
451
- const isEqual = shallowEqual(prevValue, fieldKey === fieldValue ? safeResolve(fieldValue) : fieldValue);
452
- internal.hasChange = internal.hasChange || !isEqual;
453
- if (!isReplace && isLinkKey(prevValue) && prevValue !== fieldValue) {
454
- cache2.removeRefs(graphKey, prevValue);
455
- }
456
- acc[key] = fieldValue;
457
- return acc;
458
- }, {});
459
- cache2.writeLink(graphKey, nextGraph, parentKey);
460
- if (!parentKey) {
461
- cache2.runGarbageCollector();
462
- }
463
- if ((internal.hasChange || isReplace) && !parentKey) {
464
- notify(graphKey, prevGraph);
465
- }
466
- debugState.debug({
467
- type: "afterMutate",
468
- entity: entityGraphKey,
469
- data: rawData,
470
- nextData: nextGraph,
471
- options: options2,
472
- hasChange: internal.hasChange
141
+ if ((!t2 || l(t2)) && !D(t2) || A(t2)) return t2;
142
+ let s2 = re(t2) ? L(t2) : t2;
143
+ if (D(s2)) {
144
+ let d = ae(i2) ?? "", h = ((_a = a2 == null ? void 0 : a2.internal) == null ? void 0 : _a.visitors.get(d)) ?? [], b = ((_b = a2 == null ? void 0 : a2.internal) == null ? void 0 : _b.visitors.get(s2)) ?? [];
145
+ if (h.includes(s2) || s2 === d) return null;
146
+ (_d = (_c = a2 == null ? void 0 : a2.internal) == null ? void 0 : _c.visitors) == null ? void 0 : _d.set(s2, [...b, d]);
147
+ }
148
+ if (Array.isArray(t2)) return t2.map((d) => {
149
+ let h = i2 ? Z(i2, `${he++}`) : void 0;
150
+ return N(d, h, a2);
473
151
  });
474
- return graphKey;
475
- };
476
- const invalidate = (entity) => {
477
- const key = keyOfEntity2(entity);
478
- debugState.debug({ type: "invalidate", entity: key });
479
- if (key) {
480
- const parents = cache2.getParents(key) || [];
481
- cache2.invalidate(key);
482
- parents.forEach((parentKey) => {
483
- const prevParent = cache2.readLink(parentKey);
484
- const freshParent = resolve(parentKey, { safe: false, keepLinks: true, removeLinkFromSubGraph: false });
485
- cache2.writeLink(parentKey, freshParent);
486
- notify(parentKey, prevParent);
152
+ let g2 = (D(t2) ? t2 : se(t2) ? L(t2) : null) ?? i2;
153
+ return ((a2 == null ? void 0 : a2.overrideMutateMethod) || _)(g2, t2, a2);
154
+ }, _ = (t2, ...i2) => {
155
+ let { graphKey: a2, options: s2, data: l2 } = K(t2, ...i2);
156
+ E.debug({ type: "beforeMutate", entity: a2, data: l2, options: s2 });
157
+ let g2 = D(l2) ? C(l2) : l2, y2 = a2 ?? p, d = P == null ? void 0 : P(y2), h = s2 == null ? void 0 : s2.parent, b = w(y2 ?? ""), G = (s2 == null ? void 0 : s2.internal) || { hasChange: false, visitors: /* @__PURE__ */ new Map([]) }, m = { ...g2, ...C(y2) }, R = !(s2 == null ? void 0 : s2.parent), O = (s2 == null ? void 0 : s2.replace) ? typeof (s2 == null ? void 0 : s2.replace) == "function" ? s2.replace(m) : (s2 == null ? void 0 : s2.replace) === "deep" ? true : R || d : false;
158
+ if (A(g2)) return o.writeLink(y2, g2, h), y2;
159
+ !O && T(b) && T(m) && (m = { ...b, ...m }), O && M(y2);
160
+ let U = Object.entries(m).reduce((W, [H, be]) => {
161
+ let te = Z(y2, H), v = be, F = b == null ? void 0 : b[H], ve = T(g2) && H in g2;
162
+ A(v) || (!O && ve && Array.isArray(v) && Array.isArray(F) && (v = [...F, ...v]), (T(v) || Array.isArray(v) || D(v)) && (v = N(v, te, { ...s2, parent: y2, internal: G })), Array.isArray(v) && (s2 == null ? void 0 : s2.dedup) !== false && (v = oe(...v)));
163
+ let Le = ie(F, te === v ? j(v) : v);
164
+ return G.hasChange = G.hasChange || !Le, !O && D(F) && F !== v && o.removeRefs(y2, F), W[H] = v, W;
165
+ }, {});
166
+ return o.writeLink(y2, U, h), h || o.runGarbageCollector(), (G.hasChange || O) && !h && n(y2, b), E.debug({ type: "afterMutate", entity: a2, data: l2, nextData: U, options: s2, hasChange: G.hasChange }), y2;
167
+ }, B = (t2) => {
168
+ let i2 = L(t2);
169
+ if (E.debug({ type: "invalidate", entity: i2 }), i2) {
170
+ let a2 = o.getParents(i2) || [];
171
+ o.invalidate(i2), a2.forEach((s2) => {
172
+ let l2 = o.readLink(s2), g2 = w(s2, { safe: false, keepLinks: true });
173
+ o.writeLink(s2, g2), n(s2, l2);
487
174
  });
488
175
  }
489
- };
490
- const notify = (entity, prevState, _internal) => {
491
- if (deepIndex > DEEP_LIMIT) {
492
- throw new Error("Too deep notify.");
493
- }
494
- const depth = (_internal == null ? void 0 : _internal.depth) ?? 0;
495
- const key = keyOfEntity2(entity);
496
- debugState.debug({ type: "notify", entity: key });
497
- if (key) {
498
- deepIndex++;
499
- const subs = [...subscribers.get(key) || [], ...subscribers.get(EACH_UPDATED) || []];
500
- const deps = cache2.getChildren(key) || [];
501
- const nextResult = resolve(key);
502
- const getSelectedValues = (selector) => {
503
- const next = nextResult && (selector == null ? void 0 : selector(nextResult));
504
- const prev = prevState && (selector == null ? void 0 : selector(prevState));
505
- return { next, prev, hasChange: !deepEqual(next, prev) };
176
+ }, n = (t2, i2, a2) => {
177
+ if (I > Re) throw new Error("Too deep notify.");
178
+ let s2 = (a2 == null ? void 0 : a2.depth) ?? 0, l2 = L(t2);
179
+ if (E.debug({ type: "notify", entity: l2 }), l2) {
180
+ I++;
181
+ let g2 = [...x.get(l2) || [], ...x.get(me) || []], y2 = o.getChildren(l2) || [], d = w(l2), h = (b) => {
182
+ let G = d && (b == null ? void 0 : b(d)), m = i2 && (b == null ? void 0 : b(i2));
183
+ return { next: G, prev: m, hasChange: !z(G, m) };
506
184
  };
507
- subs.forEach(({ callback, options: options2 }) => {
508
- const selector = options2 == null ? void 0 : options2.selector;
509
- const directChangesOnly = (options2 == null ? void 0 : options2.directChangesOnly) ?? false;
510
- if (directChangesOnly && depth > 0) {
511
- return;
512
- }
513
- if (selector) {
514
- const { next, prev, hasChange } = getSelectedValues(selector);
515
- if (hasChange)
516
- callback(next, prev);
517
- } else {
518
- callback(nextResult, prevState);
519
- }
520
- });
521
- deps.forEach(
522
- (dep) => notify(dep, prevState, {
523
- depth: depth + 1
524
- })
525
- );
526
- }
527
- deepIndex = 0;
528
- };
529
- const subscribe = (...args) => {
530
- const input = typeof args[0] === "function" ? EACH_UPDATED : args[0];
531
- const callback = typeof args[0] === "function" ? args[0] : args[1];
532
- const options2 = typeof args[0] === "function" ? args[1] : args[2];
533
- const key = keyOfEntity2(input);
534
- if (key) {
535
- if (subscribers.has(key)) {
536
- subscribers.set(key, [...Array.from(subscribers.get(key) || []), { callback, options: options2 }]);
537
- } else {
538
- subscribers.set(key, [{ callback, options: options2 }]);
539
- }
540
- cache2.onRemoveLink((link, prevValue) => {
541
- if (link === key) {
542
- notify(key, prevValue);
543
- }
544
- });
545
- }
546
- const unsubscribe = () => {
547
- if (key) {
548
- const subIndex = (subscribers.get(key) || []).findIndex((sub) => sub.callback === callback);
549
- if (subIndex !== -1) {
550
- const nextSubscribers = subscribers.get(key) || [];
551
- nextSubscribers.splice(subIndex, 1);
552
- subscribers.set(key, nextSubscribers);
185
+ g2.forEach(({ callback: b, options: G }) => {
186
+ let m = G == null ? void 0 : G.selector;
187
+ if (!(((G == null ? void 0 : G.directChangesOnly) ?? false) && s2 > 0)) if (m) {
188
+ let { next: O, prev: U, hasChange: W } = h(m);
189
+ W && b(O, U);
190
+ } else b(d, i2);
191
+ }), y2.forEach((b) => n(b, i2, { depth: s2 + 1 }));
192
+ }
193
+ I = 0;
194
+ }, u2 = (...t2) => {
195
+ let i2 = typeof t2[0] == "function" ? me : t2[0], a2 = typeof t2[0] == "function" ? t2[0] : t2[1], s2 = typeof t2[0] == "function" ? t2[1] : t2[2], l2 = L(i2);
196
+ l2 && (x.has(l2) ? x.set(l2, [...Array.from(x.get(l2) || []), { callback: a2, options: s2 }]) : x.set(l2, [{ callback: a2, options: s2 }]));
197
+ let g2 = () => {
198
+ if (l2) {
199
+ let y2 = (x.get(l2) || []).findIndex((d) => d.callback === a2);
200
+ if (y2 !== -1) {
201
+ let d = x.get(l2) || [];
202
+ d.splice(y2, 1), x.set(l2, d);
553
203
  }
554
204
  }
555
205
  };
556
- if (options2 == null ? void 0 : options2.signal) {
557
- options2.signal.addEventListener("abort", unsubscribe, { once: true });
558
- }
559
- return unsubscribe;
560
- };
561
- const inspectFields = (graphType) => [...cache2.types.get(graphType) ?? []];
562
- const resolveParents = (field) => {
563
- const key = (typeof field === "string" ? field : keyOfEntity2(field)) || "";
564
- const refs = cache2.getParents(key) ?? [];
565
- return refs.map((ref) => resolve(ref));
566
- };
567
- const keyOfEntity2 = (entity) => {
568
- warn("Instance keyOfEntity is deprecated. Use static method keyOfEntity.");
569
- return keyOfEntity(entity);
570
- };
571
- const entityOfKey2 = (entity) => {
572
- warn("Instance entityOfKey is deprecated. Use static method entityOfKey.");
573
- return entityOfKey(entity);
574
- };
575
- const getArgumentsForMutate = (entity, ...args) => {
576
- let data = typeof entity === "string" ? args[0] : entity;
577
- if (typeof data === "function") {
578
- data = data(resolve(entity));
579
- } else if (isLinkKey(data)) {
580
- data = entityOfKey2(data);
581
- }
582
- return {
583
- graphKey: typeof entity === "string" ? entity : keyOfEntity2(entity),
584
- options: typeof entity === "string" ? args[1] : args[0],
585
- data
586
- };
587
- };
588
- function use(plugin) {
589
- pluginsStore.use(plugin);
590
- plugin(this);
206
+ return (s2 == null ? void 0 : s2.signal) && s2.signal.addEventListener("abort", g2, { once: true }), g2;
207
+ }, k = (t2) => [...o.types.get(t2) ?? []], S = (t2) => {
208
+ let i2 = (typeof t2 == "string" ? t2 : L(t2)) || "";
209
+ return (o.getParents(i2) ?? []).map((s2) => w(s2));
210
+ }, L = (t2) => (ee("Instance keyOfEntity is deprecated. Use static method keyOfEntity."), $(t2)), C = (t2) => (ee("Instance entityOfKey is deprecated. Use static method entityOfKey."), q(t2)), K = (t2, ...i2) => {
211
+ let a2 = typeof t2 == "string" ? i2[0] : t2;
212
+ return typeof a2 == "function" ? a2 = a2(w(t2)) : D(a2) && (a2 = C(a2)), { graphKey: typeof t2 == "string" ? t2 : L(t2), options: typeof t2 == "string" ? i2[1] : i2[0], data: a2 };
213
+ };
214
+ function J(t2) {
215
+ V.use(t2), t2(this);
591
216
  }
592
- const addSkip = (predictor) => {
593
- skipPredictors.push(predictor);
217
+ let ke = (t2) => {
218
+ c.push(t2);
594
219
  };
595
- if (options == null ? void 0 : options.initialState) {
596
- mutate(options.initialState, { replace: "deep" });
597
- }
598
- const graphState = {
599
- _type: type,
600
- _id: id,
601
- key: stateKey,
602
- getReferences,
603
- mutate,
604
- subscribe,
605
- resolve,
606
- safeResolve,
607
- resolveParents,
608
- inspectFields,
609
- invalidate,
610
- keyOfEntity: keyOfEntity2,
611
- entityOfKey: entityOfKey2,
612
- getArgumentsForMutate,
613
- types: cache2.types,
614
- cache: cache2,
615
- use,
616
- addSkip,
617
- subscribers: isDev ? subscribers : void 0,
618
- onDebugEvent: debugState.onDebugEvent
619
- };
620
- cache2.onRemoveLink((link, prevValue) => debugState.debug({ type: "garbageRemove", entity: link, prevValue }));
621
- return pluginsStore.runPlugins(graphState);
220
+ (e == null ? void 0 : e.initialState) && _(e.initialState, { replace: "deep" });
221
+ let Ee = { _type: f2, _id: r2, key: p, getReferences: Y, mutate: _, subscribe: u2, resolve: w, safeResolve: j, resolveParents: S, inspectFields: k, invalidate: B, keyOfEntity: L, entityOfKey: C, getArgumentsForMutate: K, types: o.types, cache: o, use: J, addSkip: ke, subscribers: pe ? x : void 0, onDebugEvent: E.onDebugEvent };
222
+ return o.onRemoveLink((t2, i2) => E.debug({ type: "garbageRemove", entity: t2, prevValue: i2 })), o.onRemoveLink(n), V.runPlugins(Ee);
622
223
  };
623
224
  const createConstants$1 = (...constants) => {
624
225
  return constants.reduce((acc, constant) => {
@@ -639,12 +240,27 @@ const nodes = createConstants$1(
639
240
  "CssLink",
640
241
  "Variable",
641
242
  "ComputedValue",
642
- "TransformValue"
243
+ "TransformValue",
244
+ "StopColor",
245
+ "LinearGradient",
246
+ "CssChunk",
247
+ "Border",
248
+ "Paint",
249
+ "Link",
250
+ "Classname",
251
+ "ImagePaint"
643
252
  );
644
253
  const fragmentGrowingMode = createConstants$1("auto", "fill");
645
254
  const borderType = createConstants$1("None", "Solid", "Dashed", "Dotted");
646
255
  const linkTarget = createConstants$1("_blank", "none");
647
- const paintMode = createConstants$1("None", "Solid", "Image");
256
+ const paintMode = createConstants$1(
257
+ "None",
258
+ "Solid",
259
+ "LinearGradient",
260
+ "RadialGradient",
261
+ "ConicGradient",
262
+ "Image"
263
+ );
648
264
  const imagePaintScaleModes = createConstants$1("Auto", "Contain", "Cover");
649
265
  const constrain = createConstants$1(
650
266
  "Min",
@@ -741,11 +357,13 @@ const scopeTypes = createConstants$1(
741
357
  "CollectionScope",
742
358
  "CollectionItemScope"
743
359
  );
360
+ const cssChunkScopeTypes = createConstants$1("Global", "Fragment");
744
361
  const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
745
362
  __proto__: null,
746
363
  borderType,
747
364
  constrain,
748
365
  createConstants: createConstants$1,
366
+ cssChunkScopeTypes,
749
367
  effectName,
750
368
  effectType,
751
369
  eventMode,
@@ -1581,32 +1199,7 @@ const SceneSchema = /* @__PURE__ */ object({
1581
1199
  visible: layerField(/* @__PURE__ */ boolean(), { fallback: true, variable: true }),
1582
1200
  rotate: layerField(/* @__PURE__ */ number(), { fallback: null }),
1583
1201
  zIndex: layerField(/* @__PURE__ */ number(), { fallback: null }),
1584
- classnames: layerField(/* @__PURE__ */ array(/* @__PURE__ */ number()), { fallback: [] })
1585
- });
1586
- const FillSchema = /* @__PURE__ */ object({
1587
- fillType: layerField(/* @__PURE__ */ picklist(Object.keys(paintMode)), {
1588
- fallback: paintMode.None
1589
- }),
1590
- solidFill: layerField(/* @__PURE__ */ string(), { fallback: "#fff" }),
1591
- imageFill: layerField(/* @__PURE__ */ string()),
1592
- imageSize: layerField(/* @__PURE__ */ picklist(Object.keys(imagePaintScaleModes)), {
1593
- fallback: imagePaintScaleModes.Auto
1594
- })
1595
- });
1596
- const BorderSchema = /* @__PURE__ */ object({
1597
- borderType: layerField(/* @__PURE__ */ picklist(Object.keys(borderType)), {
1598
- fallback: borderType.None
1599
- }),
1600
- borderWidth: layerField(/* @__PURE__ */ string(), {
1601
- fallback: "1px",
1602
- transform: (value) => {
1603
- if (typeof value === "number") {
1604
- return `${value}px`;
1605
- }
1606
- return value;
1607
- }
1608
- }),
1609
- borderColor: layerField(/* @__PURE__ */ string(), { fallback: "#fff" })
1202
+ classnames: layerField(/* @__PURE__ */ array(linkValidator), { fallback: [] })
1610
1203
  });
1611
1204
  const SizeSchema = /* @__PURE__ */ object({
1612
1205
  widthType: layerField(/* @__PURE__ */ picklist(Object.keys(sizing)), {
@@ -1688,15 +1281,6 @@ const InteractionsSchema = /* @__PURE__ */ object({
1688
1281
  const CssOverrideSchema = /* @__PURE__ */ object({
1689
1282
  cssOverride: layerField(/* @__PURE__ */ string(), { fallback: "" })
1690
1283
  });
1691
- const LinkSchema = /* @__PURE__ */ object({
1692
- href: layerField(/* @__PURE__ */ string(), { fallback: null }),
1693
- hrefNewTab: layerField(/* @__PURE__ */ boolean(), {
1694
- fallback: true
1695
- })
1696
- // hrefTarget: layerField(v.picklist(Object.keys(linkTarget)), {
1697
- // fallback: linkTarget._blank,
1698
- // }),
1699
- });
1700
1284
  /* @__PURE__ */ pipe(
1701
1285
  /* @__PURE__ */ object({
1702
1286
  name: layerField(/* @__PURE__ */ string(), { fallback: "Frame", overridable: false }),
@@ -1705,19 +1289,19 @@ const LinkSchema = /* @__PURE__ */ object({
1705
1289
  overridable: false
1706
1290
  }),
1707
1291
  isPrimary: layerField(/* @__PURE__ */ boolean(), { fallback: false, overridable: false }),
1708
- parent: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false }),
1292
+ border: layerField(linkValidator),
1293
+ paint: layerField(linkValidator),
1294
+ link: layerField(linkValidator),
1709
1295
  ...ChildrenSchema.entries,
1710
1296
  ...GraphFieldSchema.entries,
1711
1297
  ...OverridesSchema.entries,
1298
+ parent: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false }),
1712
1299
  ...PositionSchema.entries,
1713
1300
  ...SceneSchema.entries,
1714
- ...FillSchema.entries,
1715
- ...BorderSchema.entries,
1716
1301
  ...SizeSchema.entries,
1717
1302
  ...LayerSchema.entries,
1718
1303
  ...InteractionsSchema.entries,
1719
1304
  ...CssOverrideSchema.entries,
1720
- ...LinkSchema.entries,
1721
1305
  overflow: OverflowSchema,
1722
1306
  borderRadius: BorderRadiusSchema
1723
1307
  })
@@ -1728,18 +1312,18 @@ const LinkSchema = /* @__PURE__ */ object({
1728
1312
  fallback: ""
1729
1313
  }),
1730
1314
  whiteSpace: layerField(/* @__PURE__ */ enum_(Object.keys(whiteSpace)), {
1731
- fallback: whiteSpace.normal
1315
+ fallback: whiteSpace.pre
1732
1316
  }),
1733
1317
  textAlign: layerField(/* @__PURE__ */ string(), { fallback: "left" }),
1734
1318
  parent: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false }),
1319
+ link: layerField(linkValidator),
1735
1320
  ...GraphFieldSchema.entries,
1736
1321
  ...OverridesSchema.entries,
1737
1322
  ...CssOverrideSchema.entries,
1738
1323
  ...PositionSchema.entries,
1739
1324
  ...SceneSchema.entries,
1740
1325
  ...SizeSchema.entries,
1741
- ...InteractionsSchema.entries,
1742
- ...LinkSchema.entries
1326
+ ...InteractionsSchema.entries
1743
1327
  });
1744
1328
  /* @__PURE__ */ object({
1745
1329
  name: layerField(/* @__PURE__ */ string(), { fallback: "Fragment", overridable: false }),
@@ -1756,6 +1340,10 @@ const LinkSchema = /* @__PURE__ */ object({
1756
1340
  fallback: [],
1757
1341
  overridable: false
1758
1342
  }),
1343
+ cssChunks: layerField(/* @__PURE__ */ array(linkValidator), {
1344
+ fallback: [],
1345
+ overridable: false
1346
+ }),
1759
1347
  ...GraphFieldSchema.entries,
1760
1348
  ...ChildrenSchema.entries
1761
1349
  });
@@ -1781,13 +1369,13 @@ const LinkSchema = /* @__PURE__ */ object({
1781
1369
  fallback: {}
1782
1370
  }
1783
1371
  ),
1372
+ link: layerField(linkValidator),
1784
1373
  ...GraphFieldSchema.entries,
1785
1374
  ...OverridesSchema.entries,
1786
1375
  ...PositionSchema.entries,
1787
1376
  ...SizeSchema.entries,
1788
1377
  ...SceneSchema.entries,
1789
- ...InteractionsSchema.entries,
1790
- ...LinkSchema.entries
1378
+ ...InteractionsSchema.entries
1791
1379
  });
1792
1380
  /* @__PURE__ */ object({
1793
1381
  nodePropertyControlReference: layerField(/* @__PURE__ */ string(), { fallback: null }),
@@ -1934,9 +1522,6 @@ const LinkSchema = /* @__PURE__ */ object({
1934
1522
  parent: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false }),
1935
1523
  defaultValue: layerField(/* @__PURE__ */ string(), { fallback: null }),
1936
1524
  required: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1937
- imageSize: layerField(/* @__PURE__ */ picklist(Object.keys(imagePaintScaleModes)), {
1938
- fallback: imagePaintScaleModes.Auto
1939
- }),
1940
1525
  ...GraphFieldSchema.entries
1941
1526
  });
1942
1527
  /* @__PURE__ */ pipe(
@@ -1947,18 +1532,18 @@ const LinkSchema = /* @__PURE__ */ object({
1947
1532
  }),
1948
1533
  parent: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false }),
1949
1534
  source: layerField(linkValidator, {}),
1535
+ border: layerField(linkValidator),
1536
+ paint: layerField(linkValidator),
1537
+ link: layerField(linkValidator),
1950
1538
  ...ChildrenSchema.entries,
1951
1539
  ...GraphFieldSchema.entries,
1952
1540
  ...OverridesSchema.entries,
1953
1541
  ...PositionSchema.entries,
1954
1542
  ...SceneSchema.entries,
1955
- ...FillSchema.entries,
1956
- ...BorderSchema.entries,
1957
1543
  ...SizeSchema.entries,
1958
1544
  ...LayerSchema.entries,
1959
1545
  ...InteractionsSchema.entries,
1960
- ...CssOverrideSchema.entries,
1961
- ...LinkSchema.entries
1546
+ ...CssOverrideSchema.entries
1962
1547
  })
1963
1548
  );
1964
1549
  /* @__PURE__ */ object({
@@ -1976,17 +1561,106 @@ const LinkSchema = /* @__PURE__ */ object({
1976
1561
  required: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1977
1562
  ...GraphFieldSchema.entries
1978
1563
  });
1564
+ /* @__PURE__ */ object({
1565
+ ...OverridesSchema.entries,
1566
+ parent: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false }),
1567
+ position: layerField(/* @__PURE__ */ pipe(/* @__PURE__ */ number(), /* @__PURE__ */ maxValue(1), /* @__PURE__ */ minValue(0)), {
1568
+ fallback: 0
1569
+ }),
1570
+ value: layerField(/* @__PURE__ */ string(), { fallback: "#000", variable: true }),
1571
+ ...GraphFieldSchema.entries
1572
+ });
1573
+ /* @__PURE__ */ object({
1574
+ ...OverridesSchema.entries,
1575
+ parent: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false }),
1576
+ angle: layerField(/* @__PURE__ */ number(), {
1577
+ fallback: 0
1578
+ }),
1579
+ stops: layerField(/* @__PURE__ */ array(linkValidator), { fallback: [] }),
1580
+ ...GraphFieldSchema.entries
1581
+ });
1582
+ /* @__PURE__ */ object({
1583
+ parent: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false }),
1584
+ chunkId: layerField(/* @__PURE__ */ number()),
1585
+ // content: layerField(v.string(), {
1586
+ // fallback: "",
1587
+ // }),
1588
+ // scope: layerField(v.picklist(Object.keys(definition.cssChunkScopeTypes)), {
1589
+ // fallback: definition.cssChunkScopeTypes.Fragment,
1590
+ // }),
1591
+ enabled: layerField(/* @__PURE__ */ boolean(), {
1592
+ fallback: true,
1593
+ variable: true
1594
+ }),
1595
+ ...GraphFieldSchema.entries
1596
+ });
1597
+ /* @__PURE__ */ object({
1598
+ ...OverridesSchema.entries,
1599
+ parent: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false }),
1600
+ type: layerField(/* @__PURE__ */ picklist(Object.keys(borderType)), {
1601
+ fallback: borderType.None
1602
+ }),
1603
+ width: layerField(/* @__PURE__ */ string(), {
1604
+ fallback: "1px",
1605
+ transform: (value) => {
1606
+ if (typeof value === "number") {
1607
+ return `${value}px`;
1608
+ }
1609
+ return value;
1610
+ }
1611
+ }),
1612
+ paint: layerField(linkValidator),
1613
+ ...GraphFieldSchema.entries
1614
+ });
1615
+ /* @__PURE__ */ object({
1616
+ ...OverridesSchema.entries,
1617
+ parent: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false }),
1618
+ type: layerField(/* @__PURE__ */ picklist(Object.keys(paintMode)), {
1619
+ fallback: paintMode.None
1620
+ }),
1621
+ solid: layerField(/* @__PURE__ */ string(), { fallback: "#fff" }),
1622
+ linearGradient: layerField(linkValidator),
1623
+ image: layerField(linkValidator),
1624
+ ...GraphFieldSchema.entries
1625
+ });
1626
+ /* @__PURE__ */ object({
1627
+ ...GraphFieldSchema.entries,
1628
+ ...OverridesSchema.entries,
1629
+ parent: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false }),
1630
+ src: layerField(/* @__PURE__ */ string()),
1631
+ scale: layerField(/* @__PURE__ */ picklist(Object.keys(imagePaintScaleModes)), {
1632
+ fallback: imagePaintScaleModes.Auto
1633
+ })
1634
+ });
1635
+ /* @__PURE__ */ object({
1636
+ ...OverridesSchema.entries,
1637
+ ...GraphFieldSchema.entries,
1638
+ parent: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false }),
1639
+ href: layerField(/* @__PURE__ */ string(), { fallback: null }),
1640
+ isNewTab: layerField(/* @__PURE__ */ boolean(), {
1641
+ fallback: true
1642
+ })
1643
+ });
1644
+ /* @__PURE__ */ object({
1645
+ parent: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false }),
1646
+ value: layerField(/* @__PURE__ */ string(), { fallback: "" }),
1647
+ enabled: layerField(/* @__PURE__ */ boolean(), {
1648
+ fallback: true,
1649
+ variable: true
1650
+ }),
1651
+ ...GraphFieldSchema.entries
1652
+ });
1979
1653
  const BASE_HEADERS = {
1980
1654
  "Content-Type": "application/json"
1981
1655
  };
1982
1656
  const createFetcher = (baseUrl, defaultHeaders = {}) => {
1983
- const cache2 = /* @__PURE__ */ new Map();
1657
+ const cache = /* @__PURE__ */ new Map();
1984
1658
  const inflightRequests = /* @__PURE__ */ new Map();
1985
1659
  const getCacheKey = (query2, variables, options) => JSON.stringify({ query: query2, variables, options });
1986
1660
  const query = async (query2, variables = {}, options = {}) => {
1987
1661
  const cacheKey = getCacheKey(query2, variables, options);
1988
- if (cache2.has(cacheKey)) {
1989
- return cache2.get(cacheKey);
1662
+ if (cache.has(cacheKey)) {
1663
+ return cache.get(cacheKey);
1990
1664
  }
1991
1665
  if (inflightRequests.has(cacheKey)) {
1992
1666
  return inflightRequests.get(cacheKey);
@@ -2005,7 +1679,7 @@ const createFetcher = (baseUrl, defaultHeaders = {}) => {
2005
1679
  if (!res.ok) throw new Error(`Fetch error: ${res.status}`);
2006
1680
  const data = await res.json();
2007
1681
  if (!query2.includes("mutation")) {
2008
- cache2.set(cacheKey, data);
1682
+ cache.set(cacheKey, data);
2009
1683
  }
2010
1684
  return data;
2011
1685
  }).finally(() => {
@@ -2015,33 +1689,48 @@ const createFetcher = (baseUrl, defaultHeaders = {}) => {
2015
1689
  return request;
2016
1690
  };
2017
1691
  const invalidate = (endpoint, options) => {
2018
- cache2.delete(getCacheKey(endpoint, options));
1692
+ cache.delete(getCacheKey(endpoint, options));
2019
1693
  };
2020
- const clearCache = () => cache2.clear();
1694
+ const clearCache = () => cache.clear();
2021
1695
  return { query, invalidate, clearCache };
2022
1696
  };
2023
- const getFragmentQuery = (fragmentId, isSelf) => {
2024
- return {
2025
- query: isSelf ? `
2026
- query FragmentDocument($fragmentId: Int!) {
2027
- fragment(fragmentIds: [$fragmentId]) {
1697
+ const googleFonts = `googleFonts {
1698
+ id
1699
+ variants
1700
+ subsets
1701
+ family
1702
+ version
1703
+ files {
1704
+ url
1705
+ variant
1706
+ }
1707
+ category
1708
+ }`;
1709
+ const linkedCssChunk = `linkedCssChunk {
1710
+ id
1711
+ content
1712
+ }`;
1713
+ const fragment = `
1714
+ {
2028
1715
  id
2029
1716
  document
2030
1717
  linkedFragments {
2031
1718
  id
2032
1719
  document
2033
1720
  }
2034
- }
1721
+ ${googleFonts}
1722
+ ${linkedCssChunk}
1723
+ }
1724
+ `;
1725
+ const getFragmentQuery = (fragmentId, isSelf) => {
1726
+ return {
1727
+ query: isSelf ? `
1728
+ query FragmentDocument($fragmentId: Int!) {
1729
+ fragment(fragmentIds: [$fragmentId]) ${fragment}
2035
1730
  }
2036
1731
  ` : `
2037
1732
  query FragmentDocument($fragmentId: Int!) {
2038
- clientFragment(fragmentId: $fragmentId) {
2039
- id
2040
- document
2041
- linkedFragments {
2042
- id
2043
- document
2044
- }
1733
+ clientFragment(fragmentId: $fragmentId) ${fragment}
2045
1734
  }
2046
1735
  }`,
2047
1736
  variables: {
@@ -2061,6 +1750,7 @@ var createConstants = (...constants) => {
2061
1750
  return acc;
2062
1751
  }, {});
2063
1752
  };
1753
+ var noop = () => void 0;
2064
1754
  var isBrowser_default = typeof window !== "undefined";
2065
1755
  var getKey = (v) => isKey(v) ? v.slice(1) : null;
2066
1756
  var isKey = (v) => typeof v === "string" && v.startsWith("$");
@@ -2075,6 +1765,137 @@ function hashGenerator(layerKey) {
2075
1765
  const raw = Math.abs(hash).toString(36);
2076
1766
  return /^[0-9]/.test(raw) ? `h${raw}` : raw;
2077
1767
  }
1768
+ function toFontFamily(category, family) {
1769
+ const normalizedCategory = category.toLowerCase().trim();
1770
+ const safeFamily = family.includes(" ") || family.includes(",") ? `"${family}"` : family;
1771
+ let fallback;
1772
+ switch (normalizedCategory) {
1773
+ case "sans-serif":
1774
+ case "serif":
1775
+ const placeholder = `${family} Placeholder`;
1776
+ const safePlaceholder = placeholder.includes(" ") || placeholder.includes(",") ? `"${placeholder}"` : placeholder;
1777
+ fallback = `${safePlaceholder}, ${normalizedCategory}`;
1778
+ break;
1779
+ case "display":
1780
+ case "handwritten":
1781
+ fallback = "sans-serif";
1782
+ break;
1783
+ case "monospaced":
1784
+ fallback = "monospace";
1785
+ break;
1786
+ default:
1787
+ fallback = "sans-serif";
1788
+ }
1789
+ return `${safeFamily}, ${fallback}`;
1790
+ }
1791
+ var WEIGHT_NAMES = {
1792
+ 100: "Thin",
1793
+ 200: "Extra Light",
1794
+ 300: "Light",
1795
+ 400: "Regular",
1796
+ 500: "Medium",
1797
+ 600: "Semi Bold",
1798
+ 700: "Bold",
1799
+ 800: "Extra Bold",
1800
+ 900: "Black"
1801
+ };
1802
+ var VARIANT_NAMES = {
1803
+ normal: "",
1804
+ italic: "Italic",
1805
+ "italic-normal": "Italic"
1806
+ };
1807
+ function parseFontWeight(value) {
1808
+ const strValue = String(value).toLowerCase();
1809
+ let weight = 400;
1810
+ let variant = "normal";
1811
+ const hasItalic = strValue.includes("italic");
1812
+ const numericMatch = strValue.match(/\d+/);
1813
+ if (numericMatch) {
1814
+ weight = parseInt(numericMatch[0], 10);
1815
+ } else {
1816
+ switch (strValue.replace("italic", "").trim()) {
1817
+ case "thin":
1818
+ weight = 100;
1819
+ break;
1820
+ case "extralight":
1821
+ case "extra-light":
1822
+ weight = 200;
1823
+ break;
1824
+ case "light":
1825
+ weight = 300;
1826
+ break;
1827
+ case "normal":
1828
+ case "regular":
1829
+ weight = 400;
1830
+ break;
1831
+ case "medium":
1832
+ weight = 500;
1833
+ break;
1834
+ case "semibold":
1835
+ case "semi-bold":
1836
+ weight = 600;
1837
+ break;
1838
+ case "bold":
1839
+ weight = 700;
1840
+ break;
1841
+ case "extrabold":
1842
+ case "extra-bold":
1843
+ weight = 800;
1844
+ break;
1845
+ case "black":
1846
+ weight = 900;
1847
+ break;
1848
+ }
1849
+ }
1850
+ if (hasItalic) {
1851
+ variant = "italic";
1852
+ if (!numericMatch && !WEIGHT_NAMES[weight]) {
1853
+ variant = "italic-normal";
1854
+ }
1855
+ }
1856
+ return { weight, variant, name: "" };
1857
+ }
1858
+ function generateDisplayName(parsed) {
1859
+ const { weight, variant } = parsed;
1860
+ let baseName = WEIGHT_NAMES[weight] || `Weight ${weight}`;
1861
+ if (variant !== "normal") {
1862
+ if (weight === 400 && variant === "italic") {
1863
+ baseName = "Italic";
1864
+ } else if (variant === "italic-normal") {
1865
+ baseName = "Italic";
1866
+ } else if (variant === "italic") {
1867
+ if (weight >= 100 && weight <= 300) {
1868
+ baseName = `Thin Italic`;
1869
+ } else {
1870
+ const variantName = VARIANT_NAMES[variant];
1871
+ baseName = variantName ? `${baseName} ${variantName}` : baseName;
1872
+ }
1873
+ }
1874
+ }
1875
+ return baseName.trim();
1876
+ }
1877
+ var variantOrder = {
1878
+ normal: 0,
1879
+ "italic-normal": 1,
1880
+ italic: 2
1881
+ };
1882
+ function getFontWeights(values) {
1883
+ return [...values].map((originalValue) => {
1884
+ const parsed = parseFontWeight(originalValue);
1885
+ const displayName = generateDisplayName(parsed);
1886
+ return {
1887
+ original: String(originalValue),
1888
+ weight: parsed.weight,
1889
+ variant: parsed.variant,
1890
+ displayName
1891
+ };
1892
+ }).sort((a2, b) => {
1893
+ if (a2.weight !== b.weight) {
1894
+ return a2.weight - b.weight;
1895
+ }
1896
+ return variantOrder[a2.variant] - variantOrder[b.variant];
1897
+ });
1898
+ }
2078
1899
  const fetchBeacon = (baseUrl) => {
2079
1900
  const sender = isBrowser_default && typeof (navigator == null ? void 0 : navigator.sendBeacon) === "function" ? navigator.sendBeacon : () => null;
2080
1901
  const sendBeacon = (data) => {
@@ -2095,7 +1916,19 @@ const getAreaListQuery = (areaCodes) => {
2095
1916
  areaId
2096
1917
  campaignId
2097
1918
  areaProperties
2098
- projectProperties
1919
+ projectProperties
1920
+ font {
1921
+ id
1922
+ variants
1923
+ subsets
1924
+ family
1925
+ version
1926
+ files {
1927
+ url
1928
+ variant
1929
+ }
1930
+ category
1931
+ }
2099
1932
  variant {
2100
1933
  id
2101
1934
  fragment {
@@ -2107,6 +1940,18 @@ projectProperties
2107
1940
  id
2108
1941
  document
2109
1942
  }
1943
+ googleFonts {
1944
+ id
1945
+ variants
1946
+ subsets
1947
+ family
1948
+ version
1949
+ files {
1950
+ url
1951
+ variant
1952
+ }
1953
+ category
1954
+ }
2110
1955
  }
2111
1956
  }
2112
1957
  }
@@ -2131,6 +1976,32 @@ const fetchPlugin = (state) => {
2131
1976
  }
2132
1977
  const fetcher = createFetcher(url, headers);
2133
1978
  const beaconFetcher = fetchBeacon();
1979
+ const registerFragmentDocument = (fragmentId, fragment2) => {
1980
+ var _a2, _b2;
1981
+ const fragmentDocument = fragment2 == null ? void 0 : fragment2.document;
1982
+ if (!fragmentDocument) {
1983
+ console.error("Empty document");
1984
+ return null;
1985
+ }
1986
+ if (fragment2) {
1987
+ state.$fetch.cacheDocuments.set(fragmentId, fragmentDocument);
1988
+ if (Array.isArray(fragment2.linkedFragments)) {
1989
+ fragment2.linkedFragments.forEach(
1990
+ (linkedFragment) => registerFragmentDocument(linkedFragment.id, linkedFragment)
1991
+ );
1992
+ }
1993
+ if (Array.isArray(fragment2.linkedCssChunk)) {
1994
+ fragment2.linkedCssChunk.forEach(
1995
+ (linkedChunk) => state.$fetch.cacheCssChunks.set(linkedChunk.id, linkedChunk.content)
1996
+ );
1997
+ }
1998
+ if ("$fonts" in state) {
1999
+ (_b2 = fragment2 == null ? void 0 : fragment2.googleFonts) == null ? void 0 : _b2.forEach((_a2 = state.$fonts) == null ? void 0 : _a2.registerFont);
2000
+ }
2001
+ return fragmentDocument;
2002
+ }
2003
+ return null;
2004
+ };
2134
2005
  const queryFragment = async (fragmentId) => {
2135
2006
  var _a2;
2136
2007
  if (!apiToken || !fragmentId) return null;
@@ -2143,45 +2014,28 @@ const fetchPlugin = (state) => {
2143
2014
  fragmentQuery.variables,
2144
2015
  { referrerPolicy: "unsafe-url" }
2145
2016
  );
2146
- let fragment = null;
2017
+ let fragment2 = null;
2147
2018
  if (!!(response == null ? void 0 : response.data) && "clientFragment" in response.data) {
2148
- fragment = response.data.clientFragment;
2019
+ fragment2 = response.data.clientFragment;
2149
2020
  }
2150
2021
  if (!!(response == null ? void 0 : response.data) && "fragment" in response.data) {
2151
- fragment = (_a2 = response.data.fragment) == null ? void 0 : _a2.at(0);
2152
- }
2153
- const fragmentDocument = fragment == null ? void 0 : fragment.document;
2154
- if (!fragmentDocument) {
2155
- console.error("Empty document");
2156
- return null;
2022
+ fragment2 = (_a2 = response.data.fragment) == null ? void 0 : _a2.at(0);
2157
2023
  }
2158
- if (fragment) {
2159
- state.$fetch.cacheDocuments.set(fragmentId, fragmentDocument);
2160
- if (Array.isArray(fragment.linkedFragments)) {
2161
- fragment.linkedFragments.forEach(
2162
- (linkedFragment) => state.$fetch.cacheDocuments.set(
2163
- linkedFragment.id,
2164
- linkedFragment.document
2165
- )
2166
- );
2167
- }
2168
- return fragmentDocument;
2169
- }
2170
- return null;
2024
+ return registerFragmentDocument(fragmentId, fragment2);
2171
2025
  };
2172
2026
  const queryArea = async (areaCode) => {
2173
2027
  return queryAreaList([areaCode]).then((res) => res == null ? void 0 : res.at(0));
2174
2028
  };
2175
- const queryAreaList = async (areaCodes) => {
2029
+ const queryAreaList = async (areaCodes2) => {
2176
2030
  var _a2;
2177
- if (!apiToken || !areaCodes) return null;
2178
- const nonLoadedAreas = areaCodes.filter(
2031
+ if (!apiToken || !areaCodes2) return null;
2032
+ const nonLoadedAreas = areaCodes2.filter(
2179
2033
  (code) => !state.$fetch.cacheAreaDocuments.has(code)
2180
2034
  );
2181
2035
  if (!nonLoadedAreas.length) {
2182
- return areaCodes.map(state.$fetch.cacheAreaDocuments.get);
2036
+ return areaCodes2.map(state.$fetch.cacheAreaDocuments.get);
2183
2037
  }
2184
- const areaQuery = getAreaListQuery(areaCodes);
2038
+ const areaQuery = getAreaListQuery(areaCodes2);
2185
2039
  const response = await fetcher.query(
2186
2040
  areaQuery.query,
2187
2041
  areaQuery.variables,
@@ -2190,19 +2044,10 @@ const fetchPlugin = (state) => {
2190
2044
  const areas = (_a2 = response == null ? void 0 : response.data) == null ? void 0 : _a2.clientAreas;
2191
2045
  if (areas) {
2192
2046
  areas.forEach((area, index2) => {
2193
- const areaCode = areaCodes == null ? void 0 : areaCodes.at(index2);
2194
- state.$fetch.cacheDocuments.set(
2195
- area.variant.fragment.fragment.id,
2196
- area.variant.fragment.fragment.document
2197
- );
2198
- if (Array.isArray(area.variant.fragment.fragment.linkedFragments)) {
2199
- area.variant.fragment.fragment.linkedFragments.forEach(
2200
- (linkedFragment) => state.$fetch.cacheDocuments.set(
2201
- linkedFragment.id,
2202
- linkedFragment.document
2203
- )
2204
- );
2205
- }
2047
+ var _a3;
2048
+ const areaCode = areaCodes2 == null ? void 0 : areaCodes2.at(index2);
2049
+ const areaFragment = area.variant.fragment.fragment;
2050
+ registerFragmentDocument(areaFragment.id, areaFragment);
2206
2051
  const resultProps = [
2207
2052
  ...area.projectProperties ?? [],
2208
2053
  ...area.areaProperties ?? []
@@ -2215,15 +2060,20 @@ const fetchPlugin = (state) => {
2215
2060
  campaignId: area.campaignId,
2216
2061
  variantId: area.variant.id,
2217
2062
  fragmentId: area.variant.fragment.fragment.id,
2063
+ font: area.font,
2218
2064
  props: resultProps
2219
2065
  };
2066
+ if ("$fonts" in state) {
2067
+ (_a3 = state.$fonts) == null ? void 0 : _a3.registerFont(area.font);
2068
+ }
2220
2069
  state.$fetch.cacheAreaDocuments.set(areaCode, entity);
2221
2070
  });
2222
- return areaCodes.map((code) => state.$fetch.cacheAreaDocuments.get(code));
2071
+ return areaCodes2.map((code) => state.$fetch.cacheAreaDocuments.get(code));
2223
2072
  }
2224
2073
  return null;
2225
2074
  };
2226
2075
  state.$fetch = {
2076
+ cacheCssChunks: /* @__PURE__ */ new Map(),
2227
2077
  cacheDocuments: /* @__PURE__ */ new Map(),
2228
2078
  cacheAreaDocuments: /* @__PURE__ */ new Map(),
2229
2079
  queryFragment,
@@ -2231,6 +2081,7 @@ const fetchPlugin = (state) => {
2231
2081
  queryAreaList,
2232
2082
  query: fetcher.query,
2233
2083
  sendBeacon: beaconFetcher.sendBeacon,
2084
+ readCssChunk: (id) => state.$fetch.cacheCssChunks.get(id) ?? null,
2234
2085
  readFragment: (fragmentId) => state.$fetch.cacheDocuments.get(fragmentId) ?? null,
2235
2086
  readArea: (areaCode) => state.$fetch.cacheAreaDocuments.get(areaCode) ?? null
2236
2087
  };
@@ -2239,11 +2090,11 @@ const getAllChildren = (layerResolver, layerKey, acc = []) => {
2239
2090
  var _a;
2240
2091
  const layer = layerResolver(layerKey) ?? {};
2241
2092
  if (acc.length === 0) {
2242
- acc.push(keyOfEntity(layerKey));
2093
+ acc.push($(layerKey));
2243
2094
  }
2244
2095
  (_a = layer == null ? void 0 : layer.children) == null ? void 0 : _a.forEach((child) => {
2245
2096
  if (child) {
2246
- acc.push(keyOfEntity(child));
2097
+ acc.push($(child));
2247
2098
  getAllChildren(layerResolver, child, acc);
2248
2099
  }
2249
2100
  });
@@ -2305,53 +2156,56 @@ const makeCss = (styles, layerResolver) => (layerKey) => {
2305
2156
  css: toCSS(resultCssRules) + cssOverride
2306
2157
  };
2307
2158
  };
2159
+ const injectStyle = (id, styles) => {
2160
+ if (!styles || !isBrowser_default) {
2161
+ return noop;
2162
+ }
2163
+ const existing = document.getElementById(id);
2164
+ if (existing && existing.tagName === "STYLE") {
2165
+ existing.textContent = styles;
2166
+ return;
2167
+ }
2168
+ if (existing) existing.remove();
2169
+ const style = document.createElement("style");
2170
+ style.id = id;
2171
+ style.textContent = styles;
2172
+ document.head.appendChild(style);
2173
+ return () => {
2174
+ style.remove();
2175
+ };
2176
+ };
2308
2177
  const autoInjector = (key, state, graphKey, transformStyles) => {
2309
2178
  let countDepends = 0;
2310
- const removeStyle = () => {
2179
+ const removeStyle = (customKey) => {
2180
+ const resultKey = customKey ?? key;
2311
2181
  if (!isBrowser_default) return;
2312
2182
  countDepends--;
2313
2183
  if (countDepends <= 0) {
2314
- const el = document.getElementById(key);
2184
+ const el = document.getElementById(resultKey);
2315
2185
  if (el) el.remove();
2316
2186
  }
2317
2187
  };
2318
- const injectStyle = (styles) => {
2319
- if (!isBrowser_default) return;
2320
- if (!styles) {
2321
- removeStyle();
2322
- return;
2323
- }
2324
- countDepends++;
2325
- const existing = document.getElementById(key);
2326
- if (existing && existing.tagName === "STYLE") {
2327
- existing.textContent = styles;
2328
- return;
2329
- }
2330
- if (existing) existing.remove();
2331
- const style = document.createElement("style");
2332
- style.id = key;
2333
- style.textContent = styles;
2334
- document.head.appendChild(style);
2335
- };
2336
2188
  let isMounted = false;
2337
2189
  let pendingStyles = "";
2338
- state.subscribe(
2339
- graphKey,
2340
- (next) => {
2341
- const styles = (transformStyles == null ? void 0 : transformStyles(next)) ?? (next == null ? void 0 : next.styles) ?? [];
2342
- const resultStyle = styles.join("\n");
2343
- pendingStyles = resultStyle;
2344
- if (isMounted) {
2345
- injectStyle(resultStyle);
2346
- }
2347
- },
2348
- { directChangesOnly: true }
2349
- );
2190
+ if (graphKey) {
2191
+ state.subscribe(
2192
+ graphKey,
2193
+ (next) => {
2194
+ const styles = (transformStyles == null ? void 0 : transformStyles(next)) ?? (next == null ? void 0 : next.styles) ?? [];
2195
+ const resultStyle = styles.join("\n");
2196
+ pendingStyles = resultStyle;
2197
+ if (isMounted) {
2198
+ injectStyle(key, resultStyle);
2199
+ }
2200
+ },
2201
+ { directChangesOnly: true }
2202
+ );
2203
+ }
2350
2204
  const mount = () => {
2351
2205
  isMounted = true;
2352
2206
  if (pendingStyles) {
2353
2207
  countDepends++;
2354
- injectStyle(pendingStyles);
2208
+ injectStyle(key, pendingStyles);
2355
2209
  } else {
2356
2210
  removeStyle();
2357
2211
  }
@@ -2360,7 +2214,7 @@ const autoInjector = (key, state, graphKey, transformStyles) => {
2360
2214
  isMounted = false;
2361
2215
  removeStyle();
2362
2216
  };
2363
- return { mount, unmount };
2217
+ return { mount, unmount, injectStyle, removeStyle };
2364
2218
  };
2365
2219
  function generatePrimaryCssBlocks(layerResolver, group, cssMaker) {
2366
2220
  const children = getAllChildren(layerResolver, group.primary);
@@ -2411,7 +2265,7 @@ function extractStyleSheet(styles, layerResolver) {
2411
2265
  );
2412
2266
  return fragmentCssRules;
2413
2267
  }
2414
- const fragmentStylesheetPlugin = (state) => {
2268
+ const fragmentStylesheetPlugin = (globalState) => (state) => {
2415
2269
  const KEY = `${PLUGIN_TYPES.FragmentStylesheet}:root`;
2416
2270
  const addStyle = (layerKey, style) => {
2417
2271
  state.mutate(KEY, {
@@ -2423,9 +2277,26 @@ const fragmentStylesheetPlugin = (state) => {
2423
2277
  state.mutate(KEY, {
2424
2278
  styles: {}
2425
2279
  });
2426
- const fragmentStyleInjector = autoInjector(state.key, state, KEY, (graph) => {
2427
- return extractStyleSheet(graph.styles, state.resolve);
2428
- });
2280
+ const fragmentStyleInjector = autoInjector(
2281
+ state.key,
2282
+ state,
2283
+ KEY,
2284
+ (graph) => {
2285
+ return extractStyleSheet(graph.styles, state.resolve);
2286
+ }
2287
+ );
2288
+ const addCssChunk = (chunkId) => {
2289
+ var _a, _b, _c, _d;
2290
+ const chunkContent = (_b = (_a = globalState == null ? void 0 : globalState.$fetch) == null ? void 0 : _a.readCssChunk) == null ? void 0 : _b.call(_a, chunkId);
2291
+ if (chunkContent) {
2292
+ return (_d = (_c = globalState == null ? void 0 : globalState.$globalStylesheet) == null ? void 0 : _c.addDependStyle) == null ? void 0 : _d.call(
2293
+ _c,
2294
+ `CssChunk:${chunkId}`,
2295
+ chunkContent
2296
+ );
2297
+ }
2298
+ return noop;
2299
+ };
2429
2300
  const destroyStyles = () => {
2430
2301
  state.mutate(
2431
2302
  KEY,
@@ -2439,12 +2310,16 @@ const fragmentStylesheetPlugin = (state) => {
2439
2310
  state.$styleSheet = {
2440
2311
  key: KEY,
2441
2312
  addStyle,
2313
+ addCssChunk,
2442
2314
  mount: fragmentStyleInjector.mount,
2443
2315
  unmount: destroyStyles,
2444
2316
  extract: (withTag) => {
2445
2317
  var _a;
2446
2318
  const graph = state.resolve(KEY);
2447
- const styles = extractStyleSheet(graph == null ? void 0 : graph.styles, state.resolve);
2319
+ const styles = extractStyleSheet(
2320
+ graph == null ? void 0 : graph.styles,
2321
+ state.resolve
2322
+ );
2448
2323
  const resultStyle = styles.join("\n");
2449
2324
  if (withTag) {
2450
2325
  const id = state.entityOfKey((_a = state.$fragment) == null ? void 0 : _a.root);
@@ -2466,15 +2341,25 @@ const globalStylesheetPlugin = (state) => {
2466
2341
  styles: [style]
2467
2342
  });
2468
2343
  };
2344
+ const addDependStyle = (key, style) => {
2345
+ globalStyleInjector.injectStyle(key, style);
2346
+ return () => globalStyleInjector.removeStyle(key);
2347
+ };
2469
2348
  state.mutate({
2470
2349
  _type: PLUGIN_TYPES.GlobalStylesheet,
2471
2350
  _id: "root",
2472
2351
  styles: []
2473
2352
  });
2474
2353
  const globalStyleInjector = autoInjector("global", state, KEY);
2354
+ const addStyleTag = (key, style) => {
2355
+ globalStyleInjector.injectStyle(style, key);
2356
+ return () => globalStyleInjector.removeStyle(key);
2357
+ };
2475
2358
  state.$globalStylesheet = {
2476
2359
  key: KEY,
2477
2360
  addStyle,
2361
+ addDependStyle,
2362
+ addStyleTag,
2478
2363
  mount: globalStyleInjector.mount,
2479
2364
  unmount: globalStyleInjector.unmount,
2480
2365
  extractStyles: () => {
@@ -2520,7 +2405,7 @@ const fragmentsPlugin = (options) => (state) => {
2520
2405
  _type: "Spring",
2521
2406
  _id: "root"
2522
2407
  };
2523
- const manager = createState({
2408
+ const manager = kt({
2524
2409
  _type: "FragmentManager",
2525
2410
  _id: fragmentId,
2526
2411
  initialState: initialDocument,
@@ -2532,7 +2417,7 @@ const fragmentsPlugin = (options) => (state) => {
2532
2417
  };
2533
2418
  },
2534
2419
  // cssPlugin,
2535
- fragmentStylesheetPlugin,
2420
+ fragmentStylesheetPlugin(state),
2536
2421
  scopesPlugin,
2537
2422
  ...plugins
2538
2423
  ],
@@ -2707,7 +2592,11 @@ const loadPlugin = (state) => {
2707
2592
  const readFragment = (_a = state == null ? void 0 : state.$fetch) == null ? void 0 : _a.readFragment(fragmentId);
2708
2593
  const fragmentManager = (_b = state == null ? void 0 : state.$fragments) == null ? void 0 : _b.getManager(fragmentId);
2709
2594
  if (readFragment && !fragmentManager) {
2710
- return state.$fragments.createFragmentManager(fragmentId, readFragment);
2595
+ const fragmentManager2 = state.$fragments.createFragmentManager(
2596
+ fragmentId,
2597
+ readFragment
2598
+ );
2599
+ return fragmentManager2;
2711
2600
  }
2712
2601
  if (readFragment && fragmentManager) return fragmentManager;
2713
2602
  const loader = async () => {
@@ -2752,6 +2641,56 @@ const loadPlugin = (state) => {
2752
2641
  readArea
2753
2642
  };
2754
2643
  };
2644
+ const fontsPlugin = (state) => {
2645
+ const fonts = /* @__PURE__ */ new Map();
2646
+ let defaultFontFamily = null;
2647
+ const registerFont = (font) => {
2648
+ const fontFamily = font.family;
2649
+ if (!fonts.has(fontFamily)) {
2650
+ fonts.set(fontFamily, font);
2651
+ getStyles();
2652
+ }
2653
+ };
2654
+ const setDefaultFont = (fontFamily) => {
2655
+ defaultFontFamily = fontFamily;
2656
+ getStyles();
2657
+ };
2658
+ const getStyles = () => {
2659
+ const styles = [];
2660
+ for (const [fontFamily, font] of fonts) {
2661
+ const files = font.files ?? [];
2662
+ for (const file of files) {
2663
+ const [weightItem] = getFontWeights([file.variant]);
2664
+ styles.push(`@font-face {
2665
+ font-family: '${fontFamily}';
2666
+ font-style: ${weightItem.variant};
2667
+ font-weight: ${weightItem.weight};
2668
+ font-display: swap;
2669
+ src: url(${file.url}) format('woff2');
2670
+ }`);
2671
+ }
2672
+ }
2673
+ if (defaultFontFamily) {
2674
+ const font = fonts.get(defaultFontFamily);
2675
+ if (font) {
2676
+ const fontFamily = toFontFamily(font.category, font.family);
2677
+ styles.push(`
2678
+ [data-key^="Fragment"] {
2679
+ * {
2680
+ font-family: ${fontFamily}, sans-serif;
2681
+ }
2682
+ }`);
2683
+ }
2684
+ }
2685
+ injectStyle("fonts", styles.join("\n"));
2686
+ };
2687
+ state.$fonts = {
2688
+ fonts,
2689
+ registerFont,
2690
+ setDefaultFont
2691
+ };
2692
+ return state;
2693
+ };
2755
2694
  const PLUGIN_TYPES = createConstants(
2756
2695
  "FragmentsPlugin",
2757
2696
  "GlobalStylesheet",
@@ -2759,7 +2698,7 @@ const PLUGIN_TYPES = createConstants(
2759
2698
  );
2760
2699
  const createFragmentsClient = (options) => {
2761
2700
  const BACKEND_TARGET = (options == null ? void 0 : options.isSelf) ? "/graphql" : "http://85.192.29.65/graphql";
2762
- return createState({
2701
+ return kt({
2763
2702
  _type: "GlobalManager",
2764
2703
  initialState: {},
2765
2704
  skip: [
@@ -2778,12 +2717,14 @@ const createFragmentsClient = (options) => {
2778
2717
  };
2779
2718
  },
2780
2719
  fetchPlugin,
2720
+ fontsPlugin,
2781
2721
  fragmentsPlugin({
2782
2722
  plugins: options == null ? void 0 : options.fragmentPlugins
2783
2723
  }),
2784
2724
  loadPlugin,
2785
2725
  globalMetricsPlugin,
2786
2726
  globalStylesheetPlugin
2727
+ // stylesPlugin,
2787
2728
  ]
2788
2729
  });
2789
2730
  };