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