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