@fragmentsx/client-core 0.1.4 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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 +670 -748
  4. package/dist/index.d.ts +3 -0
  5. package/dist/index.d.ts.map +1 -0
  6. package/dist/index.es.js +670 -748
  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(".");
217
- };
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
- };
86
+ return (_a = e == null ? void 0 : e.filter(Boolean)) == null ? void 0 : _a.join(".");
232
87
  };
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,19 +1916,24 @@ 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 {
2102
1935
  props
2103
- fragment {
2104
- id
2105
- document
2106
- linkedFragments {
2107
- id
2108
- document
2109
- }
2110
- }
1936
+ fragment ${fragment}
2111
1937
  }
2112
1938
  }
2113
1939
  }
@@ -2131,6 +1957,32 @@ const fetchPlugin = (state) => {
2131
1957
  }
2132
1958
  const fetcher = createFetcher(url, headers);
2133
1959
  const beaconFetcher = fetchBeacon();
1960
+ const registerFragmentDocument = (fragmentId, fragment2) => {
1961
+ var _a2, _b2;
1962
+ const fragmentDocument = fragment2 == null ? void 0 : fragment2.document;
1963
+ if (!fragmentDocument) {
1964
+ console.error("Empty document");
1965
+ return null;
1966
+ }
1967
+ if (fragment2) {
1968
+ state.$fetch.cacheDocuments.set(fragmentId, fragmentDocument);
1969
+ if (Array.isArray(fragment2.linkedFragments)) {
1970
+ fragment2.linkedFragments.forEach(
1971
+ (linkedFragment) => registerFragmentDocument(linkedFragment.id, linkedFragment)
1972
+ );
1973
+ }
1974
+ if (Array.isArray(fragment2.linkedCssChunk)) {
1975
+ fragment2.linkedCssChunk.forEach(
1976
+ (linkedChunk) => state.$fetch.cacheCssChunks.set(linkedChunk.id, linkedChunk.content)
1977
+ );
1978
+ }
1979
+ if ("$fonts" in state) {
1980
+ (_b2 = fragment2 == null ? void 0 : fragment2.googleFonts) == null ? void 0 : _b2.forEach((_a2 = state.$fonts) == null ? void 0 : _a2.registerFont);
1981
+ }
1982
+ return fragmentDocument;
1983
+ }
1984
+ return null;
1985
+ };
2134
1986
  const queryFragment = async (fragmentId) => {
2135
1987
  var _a2;
2136
1988
  if (!apiToken || !fragmentId) return null;
@@ -2143,45 +1995,28 @@ const fetchPlugin = (state) => {
2143
1995
  fragmentQuery.variables,
2144
1996
  { referrerPolicy: "unsafe-url" }
2145
1997
  );
2146
- let fragment = null;
1998
+ let fragment2 = null;
2147
1999
  if (!!(response == null ? void 0 : response.data) && "clientFragment" in response.data) {
2148
- fragment = response.data.clientFragment;
2000
+ fragment2 = response.data.clientFragment;
2149
2001
  }
2150
2002
  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;
2003
+ fragment2 = (_a2 = response.data.fragment) == null ? void 0 : _a2.at(0);
2157
2004
  }
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;
2005
+ return registerFragmentDocument(fragmentId, fragment2);
2171
2006
  };
2172
2007
  const queryArea = async (areaCode) => {
2173
2008
  return queryAreaList([areaCode]).then((res) => res == null ? void 0 : res.at(0));
2174
2009
  };
2175
- const queryAreaList = async (areaCodes) => {
2010
+ const queryAreaList = async (areaCodes2) => {
2176
2011
  var _a2;
2177
- if (!apiToken || !areaCodes) return null;
2178
- const nonLoadedAreas = areaCodes.filter(
2012
+ if (!apiToken || !areaCodes2) return null;
2013
+ const nonLoadedAreas = areaCodes2.filter(
2179
2014
  (code) => !state.$fetch.cacheAreaDocuments.has(code)
2180
2015
  );
2181
2016
  if (!nonLoadedAreas.length) {
2182
- return areaCodes.map(state.$fetch.cacheAreaDocuments.get);
2017
+ return areaCodes2.map(state.$fetch.cacheAreaDocuments.get);
2183
2018
  }
2184
- const areaQuery = getAreaListQuery(areaCodes);
2019
+ const areaQuery = getAreaListQuery(areaCodes2);
2185
2020
  const response = await fetcher.query(
2186
2021
  areaQuery.query,
2187
2022
  areaQuery.variables,
@@ -2190,19 +2025,10 @@ const fetchPlugin = (state) => {
2190
2025
  const areas = (_a2 = response == null ? void 0 : response.data) == null ? void 0 : _a2.clientAreas;
2191
2026
  if (areas) {
2192
2027
  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
- }
2028
+ var _a3;
2029
+ const areaCode = areaCodes2 == null ? void 0 : areaCodes2.at(index2);
2030
+ const areaFragment = area.variant.fragment.fragment;
2031
+ registerFragmentDocument(areaFragment.id, areaFragment);
2206
2032
  const resultProps = [
2207
2033
  ...area.projectProperties ?? [],
2208
2034
  ...area.areaProperties ?? []
@@ -2215,15 +2041,20 @@ const fetchPlugin = (state) => {
2215
2041
  campaignId: area.campaignId,
2216
2042
  variantId: area.variant.id,
2217
2043
  fragmentId: area.variant.fragment.fragment.id,
2044
+ font: area.font,
2218
2045
  props: resultProps
2219
2046
  };
2047
+ if ("$fonts" in state) {
2048
+ (_a3 = state.$fonts) == null ? void 0 : _a3.registerFont(area.font);
2049
+ }
2220
2050
  state.$fetch.cacheAreaDocuments.set(areaCode, entity);
2221
2051
  });
2222
- return areaCodes.map((code) => state.$fetch.cacheAreaDocuments.get(code));
2052
+ return areaCodes2.map((code) => state.$fetch.cacheAreaDocuments.get(code));
2223
2053
  }
2224
2054
  return null;
2225
2055
  };
2226
2056
  state.$fetch = {
2057
+ cacheCssChunks: /* @__PURE__ */ new Map(),
2227
2058
  cacheDocuments: /* @__PURE__ */ new Map(),
2228
2059
  cacheAreaDocuments: /* @__PURE__ */ new Map(),
2229
2060
  queryFragment,
@@ -2231,6 +2062,7 @@ const fetchPlugin = (state) => {
2231
2062
  queryAreaList,
2232
2063
  query: fetcher.query,
2233
2064
  sendBeacon: beaconFetcher.sendBeacon,
2065
+ readCssChunk: (id) => state.$fetch.cacheCssChunks.get(id) ?? null,
2234
2066
  readFragment: (fragmentId) => state.$fetch.cacheDocuments.get(fragmentId) ?? null,
2235
2067
  readArea: (areaCode) => state.$fetch.cacheAreaDocuments.get(areaCode) ?? null
2236
2068
  };
@@ -2239,11 +2071,11 @@ const getAllChildren = (layerResolver, layerKey, acc = []) => {
2239
2071
  var _a;
2240
2072
  const layer = layerResolver(layerKey) ?? {};
2241
2073
  if (acc.length === 0) {
2242
- acc.push(keyOfEntity(layerKey));
2074
+ acc.push($(layerKey));
2243
2075
  }
2244
2076
  (_a = layer == null ? void 0 : layer.children) == null ? void 0 : _a.forEach((child) => {
2245
2077
  if (child) {
2246
- acc.push(keyOfEntity(child));
2078
+ acc.push($(child));
2247
2079
  getAllChildren(layerResolver, child, acc);
2248
2080
  }
2249
2081
  });
@@ -2305,53 +2137,56 @@ const makeCss = (styles, layerResolver) => (layerKey) => {
2305
2137
  css: toCSS(resultCssRules) + cssOverride
2306
2138
  };
2307
2139
  };
2140
+ const injectStyle = (id, styles) => {
2141
+ if (!styles || !isBrowser_default) {
2142
+ return noop;
2143
+ }
2144
+ const existing = document.getElementById(id);
2145
+ if (existing && existing.tagName === "STYLE") {
2146
+ existing.textContent = styles;
2147
+ return;
2148
+ }
2149
+ if (existing) existing.remove();
2150
+ const style = document.createElement("style");
2151
+ style.id = id;
2152
+ style.textContent = styles;
2153
+ document.head.appendChild(style);
2154
+ return () => {
2155
+ style.remove();
2156
+ };
2157
+ };
2308
2158
  const autoInjector = (key, state, graphKey, transformStyles) => {
2309
2159
  let countDepends = 0;
2310
- const removeStyle = () => {
2160
+ const removeStyle = (customKey) => {
2161
+ const resultKey = customKey ?? key;
2311
2162
  if (!isBrowser_default) return;
2312
2163
  countDepends--;
2313
2164
  if (countDepends <= 0) {
2314
- const el = document.getElementById(key);
2165
+ const el = document.getElementById(resultKey);
2315
2166
  if (el) el.remove();
2316
2167
  }
2317
2168
  };
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
2169
  let isMounted = false;
2337
2170
  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
- );
2171
+ if (graphKey) {
2172
+ state.subscribe(
2173
+ graphKey,
2174
+ (next) => {
2175
+ const styles = (transformStyles == null ? void 0 : transformStyles(next)) ?? (next == null ? void 0 : next.styles) ?? [];
2176
+ const resultStyle = styles.join("\n");
2177
+ pendingStyles = resultStyle;
2178
+ if (isMounted) {
2179
+ injectStyle(key, resultStyle);
2180
+ }
2181
+ },
2182
+ { directChangesOnly: true }
2183
+ );
2184
+ }
2350
2185
  const mount = () => {
2351
2186
  isMounted = true;
2352
2187
  if (pendingStyles) {
2353
2188
  countDepends++;
2354
- injectStyle(pendingStyles);
2189
+ injectStyle(key, pendingStyles);
2355
2190
  } else {
2356
2191
  removeStyle();
2357
2192
  }
@@ -2360,7 +2195,7 @@ const autoInjector = (key, state, graphKey, transformStyles) => {
2360
2195
  isMounted = false;
2361
2196
  removeStyle();
2362
2197
  };
2363
- return { mount, unmount };
2198
+ return { mount, unmount, injectStyle, removeStyle };
2364
2199
  };
2365
2200
  function generatePrimaryCssBlocks(layerResolver, group, cssMaker) {
2366
2201
  const children = getAllChildren(layerResolver, group.primary);
@@ -2411,7 +2246,7 @@ function extractStyleSheet(styles, layerResolver) {
2411
2246
  );
2412
2247
  return fragmentCssRules;
2413
2248
  }
2414
- const fragmentStylesheetPlugin = (state) => {
2249
+ const fragmentStylesheetPlugin = (globalState) => (state) => {
2415
2250
  const KEY = `${PLUGIN_TYPES.FragmentStylesheet}:root`;
2416
2251
  const addStyle = (layerKey, style) => {
2417
2252
  state.mutate(KEY, {
@@ -2423,9 +2258,26 @@ const fragmentStylesheetPlugin = (state) => {
2423
2258
  state.mutate(KEY, {
2424
2259
  styles: {}
2425
2260
  });
2426
- const fragmentStyleInjector = autoInjector(state.key, state, KEY, (graph) => {
2427
- return extractStyleSheet(graph.styles, state.resolve);
2428
- });
2261
+ const fragmentStyleInjector = autoInjector(
2262
+ state.key,
2263
+ state,
2264
+ KEY,
2265
+ (graph) => {
2266
+ return extractStyleSheet(graph.styles, state.resolve);
2267
+ }
2268
+ );
2269
+ const addCssChunk = (chunkId) => {
2270
+ var _a, _b, _c, _d;
2271
+ const chunkContent = (_b = (_a = globalState == null ? void 0 : globalState.$fetch) == null ? void 0 : _a.readCssChunk) == null ? void 0 : _b.call(_a, chunkId);
2272
+ if (chunkContent) {
2273
+ return (_d = (_c = globalState == null ? void 0 : globalState.$globalStylesheet) == null ? void 0 : _c.addDependStyle) == null ? void 0 : _d.call(
2274
+ _c,
2275
+ `CssChunk:${chunkId}`,
2276
+ chunkContent
2277
+ );
2278
+ }
2279
+ return noop;
2280
+ };
2429
2281
  const destroyStyles = () => {
2430
2282
  state.mutate(
2431
2283
  KEY,
@@ -2439,12 +2291,16 @@ const fragmentStylesheetPlugin = (state) => {
2439
2291
  state.$styleSheet = {
2440
2292
  key: KEY,
2441
2293
  addStyle,
2294
+ addCssChunk,
2442
2295
  mount: fragmentStyleInjector.mount,
2443
2296
  unmount: destroyStyles,
2444
2297
  extract: (withTag) => {
2445
2298
  var _a;
2446
2299
  const graph = state.resolve(KEY);
2447
- const styles = extractStyleSheet(graph == null ? void 0 : graph.styles, state.resolve);
2300
+ const styles = extractStyleSheet(
2301
+ graph == null ? void 0 : graph.styles,
2302
+ state.resolve
2303
+ );
2448
2304
  const resultStyle = styles.join("\n");
2449
2305
  if (withTag) {
2450
2306
  const id = state.entityOfKey((_a = state.$fragment) == null ? void 0 : _a.root);
@@ -2466,15 +2322,25 @@ const globalStylesheetPlugin = (state) => {
2466
2322
  styles: [style]
2467
2323
  });
2468
2324
  };
2325
+ const addDependStyle = (key, style) => {
2326
+ globalStyleInjector.injectStyle(key, style);
2327
+ return () => globalStyleInjector.removeStyle(key);
2328
+ };
2469
2329
  state.mutate({
2470
2330
  _type: PLUGIN_TYPES.GlobalStylesheet,
2471
2331
  _id: "root",
2472
2332
  styles: []
2473
2333
  });
2474
2334
  const globalStyleInjector = autoInjector("global", state, KEY);
2335
+ const addStyleTag = (key, style) => {
2336
+ globalStyleInjector.injectStyle(style, key);
2337
+ return () => globalStyleInjector.removeStyle(key);
2338
+ };
2475
2339
  state.$globalStylesheet = {
2476
2340
  key: KEY,
2477
2341
  addStyle,
2342
+ addDependStyle,
2343
+ addStyleTag,
2478
2344
  mount: globalStyleInjector.mount,
2479
2345
  unmount: globalStyleInjector.unmount,
2480
2346
  extractStyles: () => {
@@ -2520,7 +2386,7 @@ const fragmentsPlugin = (options) => (state) => {
2520
2386
  _type: "Spring",
2521
2387
  _id: "root"
2522
2388
  };
2523
- const manager = createState({
2389
+ const manager = kt({
2524
2390
  _type: "FragmentManager",
2525
2391
  _id: fragmentId,
2526
2392
  initialState: initialDocument,
@@ -2532,7 +2398,7 @@ const fragmentsPlugin = (options) => (state) => {
2532
2398
  };
2533
2399
  },
2534
2400
  // cssPlugin,
2535
- fragmentStylesheetPlugin,
2401
+ fragmentStylesheetPlugin(state),
2536
2402
  scopesPlugin,
2537
2403
  ...plugins
2538
2404
  ],
@@ -2707,7 +2573,11 @@ const loadPlugin = (state) => {
2707
2573
  const readFragment = (_a = state == null ? void 0 : state.$fetch) == null ? void 0 : _a.readFragment(fragmentId);
2708
2574
  const fragmentManager = (_b = state == null ? void 0 : state.$fragments) == null ? void 0 : _b.getManager(fragmentId);
2709
2575
  if (readFragment && !fragmentManager) {
2710
- return state.$fragments.createFragmentManager(fragmentId, readFragment);
2576
+ const fragmentManager2 = state.$fragments.createFragmentManager(
2577
+ fragmentId,
2578
+ readFragment
2579
+ );
2580
+ return fragmentManager2;
2711
2581
  }
2712
2582
  if (readFragment && fragmentManager) return fragmentManager;
2713
2583
  const loader = async () => {
@@ -2752,6 +2622,56 @@ const loadPlugin = (state) => {
2752
2622
  readArea
2753
2623
  };
2754
2624
  };
2625
+ const fontsPlugin = (state) => {
2626
+ const fonts = /* @__PURE__ */ new Map();
2627
+ let defaultFontFamily = null;
2628
+ const registerFont = (font) => {
2629
+ const fontFamily = font.family;
2630
+ if (!fonts.has(fontFamily)) {
2631
+ fonts.set(fontFamily, font);
2632
+ getStyles();
2633
+ }
2634
+ };
2635
+ const setDefaultFont = (fontFamily) => {
2636
+ defaultFontFamily = fontFamily;
2637
+ getStyles();
2638
+ };
2639
+ const getStyles = () => {
2640
+ const styles = [];
2641
+ for (const [fontFamily, font] of fonts) {
2642
+ const files = font.files ?? [];
2643
+ for (const file of files) {
2644
+ const [weightItem] = getFontWeights([file.variant]);
2645
+ styles.push(`@font-face {
2646
+ font-family: '${fontFamily}';
2647
+ font-style: ${weightItem.variant};
2648
+ font-weight: ${weightItem.weight};
2649
+ font-display: swap;
2650
+ src: url(${file.url}) format('woff2');
2651
+ }`);
2652
+ }
2653
+ }
2654
+ if (defaultFontFamily) {
2655
+ const font = fonts.get(defaultFontFamily);
2656
+ if (font) {
2657
+ const fontFamily = toFontFamily(font.category, font.family);
2658
+ styles.push(`
2659
+ [data-key^="Fragment"] {
2660
+ * {
2661
+ font-family: ${fontFamily}, sans-serif;
2662
+ }
2663
+ }`);
2664
+ }
2665
+ }
2666
+ injectStyle("fonts", styles.join("\n"));
2667
+ };
2668
+ state.$fonts = {
2669
+ fonts,
2670
+ registerFont,
2671
+ setDefaultFont
2672
+ };
2673
+ return state;
2674
+ };
2755
2675
  const PLUGIN_TYPES = createConstants(
2756
2676
  "FragmentsPlugin",
2757
2677
  "GlobalStylesheet",
@@ -2759,7 +2679,7 @@ const PLUGIN_TYPES = createConstants(
2759
2679
  );
2760
2680
  const createFragmentsClient = (options) => {
2761
2681
  const BACKEND_TARGET = (options == null ? void 0 : options.isSelf) ? "/graphql" : "http://85.192.29.65/graphql";
2762
- return createState({
2682
+ return kt({
2763
2683
  _type: "GlobalManager",
2764
2684
  initialState: {},
2765
2685
  skip: [
@@ -2778,12 +2698,14 @@ const createFragmentsClient = (options) => {
2778
2698
  };
2779
2699
  },
2780
2700
  fetchPlugin,
2701
+ fontsPlugin,
2781
2702
  fragmentsPlugin({
2782
2703
  plugins: options == null ? void 0 : options.fragmentPlugins
2783
2704
  }),
2784
2705
  loadPlugin,
2785
2706
  globalMetricsPlugin,
2786
2707
  globalStylesheetPlugin
2708
+ // stylesPlugin,
2787
2709
  ]
2788
2710
  });
2789
2711
  };