@fragmentsx/render-react 0.0.4 → 0.0.5

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 (39) hide show
  1. package/dist/components/Fragment/index.d.ts +8 -0
  2. package/dist/components/Fragment/index.d.ts.map +1 -0
  3. package/dist/components/Frame/index.d.ts +9 -0
  4. package/dist/components/Frame/index.d.ts.map +1 -0
  5. package/dist/components/GlobalManager/index.d.ts +5 -0
  6. package/dist/components/GlobalManager/index.d.ts.map +1 -0
  7. package/dist/components/Instance/index.d.ts +10 -0
  8. package/dist/components/Instance/index.d.ts.map +1 -0
  9. package/dist/components/Text/index.d.ts +8 -0
  10. package/dist/components/Text/index.d.ts.map +1 -0
  11. package/dist/helpers/collectStyles.d.ts +3 -0
  12. package/dist/helpers/collectStyles.d.ts.map +1 -0
  13. package/dist/helpers/hydration.d.ts +3 -0
  14. package/dist/helpers/hydration.d.ts.map +1 -0
  15. package/dist/helpers/isBrowser.d.ts +2 -0
  16. package/dist/helpers/isBrowser.d.ts.map +1 -0
  17. package/dist/helpers/loadFragmentManager.d.ts +3 -0
  18. package/dist/helpers/loadFragmentManager.d.ts.map +1 -0
  19. package/dist/hocs/reactCSRAdapter.d.ts +2 -0
  20. package/dist/hocs/reactCSRAdapter.d.ts.map +1 -0
  21. package/dist/hocs/reactSSRAdapter.d.ts +3 -0
  22. package/dist/hocs/reactSSRAdapter.d.ts.map +1 -0
  23. package/dist/index.cjs.js +2320 -105
  24. package/dist/index.d.ts +3 -6
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.es.js +2317 -102
  27. package/dist/reactAdapter.d.ts +1 -2
  28. package/dist/reactAdapter.d.ts.map +1 -1
  29. package/package.json +17 -14
  30. package/dist/components/GlobalManager.d.ts +0 -2
  31. package/dist/components/GlobalManager.d.ts.map +0 -1
  32. package/dist/hooks/useFragmentManager.d.ts +0 -5
  33. package/dist/hooks/useFragmentManager.d.ts.map +0 -1
  34. package/dist/hooks/useFragmentProperties.d.ts +0 -2
  35. package/dist/hooks/useFragmentProperties.d.ts.map +0 -1
  36. package/dist/hooks/useGlobalManager.d.ts +0 -2
  37. package/dist/hooks/useGlobalManager.d.ts.map +0 -1
  38. package/dist/hooks/useRenderTarget.d.ts +0 -7
  39. package/dist/hooks/useRenderTarget.d.ts.map +0 -1
package/dist/index.es.js CHANGED
@@ -1,32 +1,1347 @@
1
- import { render, createElement, Instance as Instance$1, Fragment as Fragment$1 } from "@fragmentsx/render-core";
2
- import require$$0, { createContext, useContext, useRef, useCallback, useState, useEffect } from "react";
3
- import "react/jsx-runtime";
1
+ import { jsx } from "react/jsx-runtime";
2
+ import require$$0, { createContext, useContext, useRef, useCallback, useState, useEffect, useMemo } from "react";
3
+ import { isLinkKey } from "@graph-state/core";
4
4
  import { definition } from "@fragmentsx/definition";
5
- const GlobalManager = createContext(null);
6
- function createReactComponent(PreactComponent) {
7
- return function ReactWrapper(props) {
8
- const globalManager = useContext(GlobalManager);
9
- const containerRef = require$$0.useRef(null);
10
- require$$0.useEffect(() => {
11
- if (containerRef.current) {
12
- render(
13
- createElement(PreactComponent, {
14
- ...props,
15
- globalManager: (props == null ? void 0 : props.globalManager) ?? globalManager
16
- }),
17
- containerRef.current
18
- );
5
+ const collectStyles = (globalManager) => {
6
+ if (!globalManager) return null;
7
+ const allFragments = globalManager.$fragments.getManagers();
8
+ const extractors = Object.entries(allFragments).filter(([, value]) => !!(value == null ? void 0 : value.resolve)).map(([fragmentId, manager]) => {
9
+ var _a;
10
+ const a = (_a = manager.extractStyleSheet()) == null ? void 0 : _a.at(0);
11
+ return a;
12
+ });
13
+ return extractors.map((extractor) => /* @__PURE__ */ jsx(
14
+ "style",
15
+ {
16
+ id: `fragments-${extractor == null ? void 0 : extractor.fragment}`,
17
+ dangerouslySetInnerHTML: { __html: extractor == null ? void 0 : extractor.styles.join("") }
18
+ }
19
+ ));
20
+ };
21
+ "function" == typeof Promise ? Promise.prototype.then.bind(Promise.resolve()) : setTimeout;
22
+ (function() {
23
+ try {
24
+ if (typeof document != "undefined") {
25
+ var elementStyle = document.createElement("style");
26
+ elementStyle.appendChild(document.createTextNode("._fragment_1c708_1 {\n width: 100%;\n height: 100%;\n}\n\n._fragmentDocument_1c708_6 {\n display: contents;\n}\n._text_1liuf_1 {\n white-space: pre;\n :where(p) {\n margin: 0;\n }\n}"));
27
+ document.head.appendChild(elementStyle);
28
+ }
29
+ } catch (e) {
30
+ console.error("vite-plugin-css-injected-by-js", e);
31
+ }
32
+ })();
33
+ const createConstants = (...constants) => {
34
+ return constants.reduce((acc, constant) => {
35
+ acc[constant] = constant;
36
+ return acc;
37
+ }, {});
38
+ };
39
+ const nodes = createConstants(
40
+ "Fragment",
41
+ "FragmentInstance",
42
+ "Instance",
43
+ "Breakpoint",
44
+ "Frame",
45
+ "Image",
46
+ "Text",
47
+ "SolidPaintStyle",
48
+ "CssLink",
49
+ "Variable",
50
+ "ComputedValue",
51
+ "TransformValue"
52
+ );
53
+ const fragmentGrowingMode = createConstants("auto", "fill");
54
+ const borderType = createConstants("None", "Solid", "Dashed", "Dotted");
55
+ const linkTarget = createConstants("_blank");
56
+ const paintMode = createConstants("None", "Solid", "Image");
57
+ const imagePaintScaleModes = createConstants(
58
+ "Fill",
59
+ "Fit",
60
+ "Crop",
61
+ "Tile"
62
+ );
63
+ const constrain = createConstants(
64
+ "Min",
65
+ "Center",
66
+ "Max",
67
+ "Stretch",
68
+ "Scale"
69
+ );
70
+ const positionType = createConstants("absolute", "relative");
71
+ const sizing = createConstants("Fixed", "Hug", "Fill", "Relative");
72
+ const layerMode = createConstants("none", "flex");
73
+ const layerDirection = createConstants("vertical", "horizontal");
74
+ const layerAlign = createConstants("start", "center", "end");
75
+ const layerDistribute = createConstants(
76
+ "start",
77
+ "center",
78
+ "end",
79
+ "space-between",
80
+ "space-around"
81
+ );
82
+ const textTransform = createConstants(
83
+ "none",
84
+ "uppercase",
85
+ "lowercase",
86
+ "capitalize"
87
+ );
88
+ const textDecorations = createConstants(
89
+ "none",
90
+ "underline",
91
+ "line-through"
92
+ );
93
+ const effectType = createConstants("loop", "appear", "hover", "tap");
94
+ const effectName = createConstants(
95
+ "fade",
96
+ "slide",
97
+ "bounce",
98
+ "wiggle",
99
+ "increase"
100
+ );
101
+ const variableType = createConstants(
102
+ "Event",
103
+ "String",
104
+ "Boolean",
105
+ "Array",
106
+ "Color",
107
+ "ComponentInstance",
108
+ "Date",
109
+ "Enum",
110
+ "Number",
111
+ "Object"
112
+ );
113
+ const whiteSpace = createConstants(
114
+ "normal",
115
+ "nowrap",
116
+ "pre",
117
+ "pre-wrap",
118
+ "pre-line",
119
+ "break-spaces"
120
+ );
121
+ const overflow = createConstants("visible", "hidden", "scroll");
122
+ const variableTransforms = createConstants(
123
+ "convert",
124
+ "exists",
125
+ "equals",
126
+ "startWith",
127
+ "endWith",
128
+ "contains",
129
+ "dateBefore",
130
+ "dateAfter",
131
+ "dateBetween",
132
+ "feature",
133
+ "notFeature",
134
+ "gt",
135
+ // Greater than
136
+ "gte",
137
+ // Greater than or equals
138
+ "lt",
139
+ // Less than
140
+ "lte",
141
+ // Less than or equals,
142
+ "convertFromBoolean",
143
+ "negative"
144
+ );
145
+ const renderTarget = createConstants("canvas", "document");
146
+ const renderMode = createConstants("viewport", "parent", "fixed");
147
+ const interactions = createConstants("click", "mouseover");
148
+ const eventMode = createConstants("goal", "callback");
149
+ const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
150
+ __proto__: null,
151
+ borderType,
152
+ constrain,
153
+ createConstants,
154
+ effectName,
155
+ effectType,
156
+ eventMode,
157
+ fragmentGrowingMode,
158
+ imagePaintScaleModes,
159
+ interactions,
160
+ layerAlign,
161
+ layerDirection,
162
+ layerDistribute,
163
+ layerMode,
164
+ linkTarget,
165
+ nodes,
166
+ overflow,
167
+ paintMode,
168
+ positionType,
169
+ renderMode,
170
+ renderTarget,
171
+ sizing,
172
+ textDecorations,
173
+ textTransform,
174
+ variableTransforms,
175
+ variableType,
176
+ whiteSpace
177
+ }, Symbol.toStringTag, { value: "Module" }));
178
+ // @__NO_SIDE_EFFECTS__
179
+ function getGlobalConfig(config2) {
180
+ return {
181
+ lang: (config2 == null ? void 0 : config2.lang) ?? void 0,
182
+ message: config2 == null ? void 0 : config2.message,
183
+ abortEarly: (config2 == null ? void 0 : config2.abortEarly) ?? void 0,
184
+ abortPipeEarly: (config2 == null ? void 0 : config2.abortPipeEarly) ?? void 0
185
+ };
186
+ }
187
+ // @__NO_SIDE_EFFECTS__
188
+ function getGlobalMessage(lang) {
189
+ return void 0;
190
+ }
191
+ // @__NO_SIDE_EFFECTS__
192
+ function getSchemaMessage(lang) {
193
+ return void 0;
194
+ }
195
+ // @__NO_SIDE_EFFECTS__
196
+ function getSpecificMessage(reference, lang) {
197
+ var _a;
198
+ return (_a = void 0) == null ? void 0 : _a.get(lang);
199
+ }
200
+ // @__NO_SIDE_EFFECTS__
201
+ function _stringify(input) {
202
+ var _a, _b;
203
+ const type = typeof input;
204
+ if (type === "string") {
205
+ return `"${input}"`;
206
+ }
207
+ if (type === "number" || type === "bigint" || type === "boolean") {
208
+ return `${input}`;
209
+ }
210
+ if (type === "object" || type === "function") {
211
+ return (input && ((_b = (_a = Object.getPrototypeOf(input)) == null ? void 0 : _a.constructor) == null ? void 0 : _b.name)) ?? "null";
212
+ }
213
+ return type;
214
+ }
215
+ function _addIssue(context, label, dataset, config2, other) {
216
+ const input = other && "input" in other ? other.input : dataset.value;
217
+ const expected = (other == null ? void 0 : other.expected) ?? context.expects ?? null;
218
+ const received = (other == null ? void 0 : other.received) ?? /* @__PURE__ */ _stringify(input);
219
+ const issue = {
220
+ kind: context.kind,
221
+ type: context.type,
222
+ input,
223
+ expected,
224
+ received,
225
+ message: `Invalid ${label}: ${expected ? `Expected ${expected} but r` : "R"}eceived ${received}`,
226
+ requirement: context.requirement,
227
+ path: other == null ? void 0 : other.path,
228
+ issues: other == null ? void 0 : other.issues,
229
+ lang: config2.lang,
230
+ abortEarly: config2.abortEarly,
231
+ abortPipeEarly: config2.abortPipeEarly
232
+ };
233
+ const isSchema = context.kind === "schema";
234
+ const message = (other == null ? void 0 : other.message) ?? context.message ?? /* @__PURE__ */ getSpecificMessage(context.reference, issue.lang) ?? (isSchema ? /* @__PURE__ */ getSchemaMessage(issue.lang) : null) ?? config2.message ?? /* @__PURE__ */ getGlobalMessage(issue.lang);
235
+ if (message !== void 0) {
236
+ issue.message = typeof message === "function" ? (
237
+ // @ts-expect-error
238
+ message(issue)
239
+ ) : message;
240
+ }
241
+ if (isSchema) {
242
+ dataset.typed = false;
243
+ }
244
+ if (dataset.issues) {
245
+ dataset.issues.push(issue);
246
+ } else {
247
+ dataset.issues = [issue];
248
+ }
249
+ }
250
+ // @__NO_SIDE_EFFECTS__
251
+ function _getStandardProps(context) {
252
+ return {
253
+ version: 1,
254
+ vendor: "valibot",
255
+ validate(value2) {
256
+ return context["~run"]({ value: value2 }, /* @__PURE__ */ getGlobalConfig());
257
+ }
258
+ };
259
+ }
260
+ // @__NO_SIDE_EFFECTS__
261
+ function _isValidObjectKey(object2, key) {
262
+ return Object.hasOwn(object2, key) && key !== "__proto__" && key !== "prototype" && key !== "constructor";
263
+ }
264
+ // @__NO_SIDE_EFFECTS__
265
+ function _joinExpects(values2, separator) {
266
+ const list = [...new Set(values2)];
267
+ if (list.length > 1) {
268
+ return `(${list.join(` ${separator} `)})`;
269
+ }
270
+ return list[0] ?? "never";
271
+ }
272
+ // @__NO_SIDE_EFFECTS__
273
+ function isOfKind(kind, object2) {
274
+ return object2.kind === kind;
275
+ }
276
+ var ValiError = class extends Error {
277
+ /**
278
+ * Creates a Valibot error with useful information.
279
+ *
280
+ * @param issues The error issues.
281
+ */
282
+ constructor(issues) {
283
+ super(issues[0].message);
284
+ this.name = "ValiError";
285
+ this.issues = issues;
286
+ }
287
+ };
288
+ // @__NO_SIDE_EFFECTS__
289
+ function check(requirement, message) {
290
+ return {
291
+ kind: "validation",
292
+ type: "check",
293
+ reference: check,
294
+ async: false,
295
+ expects: null,
296
+ requirement,
297
+ message,
298
+ "~run"(dataset, config2) {
299
+ if (dataset.typed && !this.requirement(dataset.value)) {
300
+ _addIssue(this, "input", dataset, config2);
301
+ }
302
+ return dataset;
303
+ }
304
+ };
305
+ }
306
+ // @__NO_SIDE_EFFECTS__
307
+ function maxValue(requirement, message) {
308
+ return {
309
+ kind: "validation",
310
+ type: "max_value",
311
+ reference: maxValue,
312
+ async: false,
313
+ expects: `<=${requirement instanceof Date ? requirement.toJSON() : /* @__PURE__ */ _stringify(requirement)}`,
314
+ requirement,
315
+ message,
316
+ "~run"(dataset, config2) {
317
+ if (dataset.typed && !(dataset.value <= this.requirement)) {
318
+ _addIssue(this, "value", dataset, config2, {
319
+ received: dataset.value instanceof Date ? dataset.value.toJSON() : /* @__PURE__ */ _stringify(dataset.value)
320
+ });
321
+ }
322
+ return dataset;
323
+ }
324
+ };
325
+ }
326
+ // @__NO_SIDE_EFFECTS__
327
+ function metadata(metadata_) {
328
+ return {
329
+ kind: "metadata",
330
+ type: "metadata",
331
+ reference: metadata,
332
+ metadata: metadata_
333
+ };
334
+ }
335
+ // @__NO_SIDE_EFFECTS__
336
+ function minValue(requirement, message) {
337
+ return {
338
+ kind: "validation",
339
+ type: "min_value",
340
+ reference: minValue,
341
+ async: false,
342
+ expects: `>=${requirement instanceof Date ? requirement.toJSON() : /* @__PURE__ */ _stringify(requirement)}`,
343
+ requirement,
344
+ message,
345
+ "~run"(dataset, config2) {
346
+ if (dataset.typed && !(dataset.value >= this.requirement)) {
347
+ _addIssue(this, "value", dataset, config2, {
348
+ received: dataset.value instanceof Date ? dataset.value.toJSON() : /* @__PURE__ */ _stringify(dataset.value)
349
+ });
19
350
  }
20
- return () => {
21
- if (containerRef.current) {
22
- render(null, containerRef.current);
351
+ return dataset;
352
+ }
353
+ };
354
+ }
355
+ // @__NO_SIDE_EFFECTS__
356
+ function transform(operation) {
357
+ return {
358
+ kind: "transformation",
359
+ type: "transform",
360
+ reference: transform,
361
+ async: false,
362
+ operation,
363
+ "~run"(dataset) {
364
+ dataset.value = this.operation(dataset.value);
365
+ return dataset;
366
+ }
367
+ };
368
+ }
369
+ // @__NO_SIDE_EFFECTS__
370
+ function getFallback(schema, dataset, config2) {
371
+ return typeof schema.fallback === "function" ? (
372
+ // @ts-expect-error
373
+ schema.fallback(dataset, config2)
374
+ ) : (
375
+ // @ts-expect-error
376
+ schema.fallback
377
+ );
378
+ }
379
+ // @__NO_SIDE_EFFECTS__
380
+ function getDefault(schema, dataset, config2) {
381
+ return typeof schema.default === "function" ? (
382
+ // @ts-expect-error
383
+ schema.default(dataset, config2)
384
+ ) : (
385
+ // @ts-expect-error
386
+ schema.default
387
+ );
388
+ }
389
+ // @__NO_SIDE_EFFECTS__
390
+ function any() {
391
+ return {
392
+ kind: "schema",
393
+ type: "any",
394
+ reference: any,
395
+ expects: "any",
396
+ async: false,
397
+ get "~standard"() {
398
+ return /* @__PURE__ */ _getStandardProps(this);
399
+ },
400
+ "~run"(dataset) {
401
+ dataset.typed = true;
402
+ return dataset;
403
+ }
404
+ };
405
+ }
406
+ // @__NO_SIDE_EFFECTS__
407
+ function array(item, message) {
408
+ return {
409
+ kind: "schema",
410
+ type: "array",
411
+ reference: array,
412
+ expects: "Array",
413
+ async: false,
414
+ item,
415
+ message,
416
+ get "~standard"() {
417
+ return /* @__PURE__ */ _getStandardProps(this);
418
+ },
419
+ "~run"(dataset, config2) {
420
+ var _a;
421
+ const input = dataset.value;
422
+ if (Array.isArray(input)) {
423
+ dataset.typed = true;
424
+ dataset.value = [];
425
+ for (let key = 0; key < input.length; key++) {
426
+ const value2 = input[key];
427
+ const itemDataset = this.item["~run"]({ value: value2 }, config2);
428
+ if (itemDataset.issues) {
429
+ const pathItem = {
430
+ type: "array",
431
+ origin: "value",
432
+ input,
433
+ key,
434
+ value: value2
435
+ };
436
+ for (const issue of itemDataset.issues) {
437
+ if (issue.path) {
438
+ issue.path.unshift(pathItem);
439
+ } else {
440
+ issue.path = [pathItem];
441
+ }
442
+ (_a = dataset.issues) == null ? void 0 : _a.push(issue);
443
+ }
444
+ if (!dataset.issues) {
445
+ dataset.issues = itemDataset.issues;
446
+ }
447
+ if (config2.abortEarly) {
448
+ dataset.typed = false;
449
+ break;
450
+ }
451
+ }
452
+ if (!itemDataset.typed) {
453
+ dataset.typed = false;
454
+ }
455
+ dataset.value.push(itemDataset.value);
23
456
  }
24
- };
25
- }, [props, globalManager]);
26
- return require$$0.createElement("div", { ref: containerRef });
457
+ } else {
458
+ _addIssue(this, "type", dataset, config2);
459
+ }
460
+ return dataset;
461
+ }
462
+ };
463
+ }
464
+ // @__NO_SIDE_EFFECTS__
465
+ function boolean(message) {
466
+ return {
467
+ kind: "schema",
468
+ type: "boolean",
469
+ reference: boolean,
470
+ expects: "boolean",
471
+ async: false,
472
+ message,
473
+ get "~standard"() {
474
+ return /* @__PURE__ */ _getStandardProps(this);
475
+ },
476
+ "~run"(dataset, config2) {
477
+ if (typeof dataset.value === "boolean") {
478
+ dataset.typed = true;
479
+ } else {
480
+ _addIssue(this, "type", dataset, config2);
481
+ }
482
+ return dataset;
483
+ }
484
+ };
485
+ }
486
+ // @__NO_SIDE_EFFECTS__
487
+ function enum_(enum__, message) {
488
+ const options2 = [];
489
+ for (const key in enum__) {
490
+ if (`${+key}` !== key || typeof enum__[key] !== "string" || !Object.is(enum__[enum__[key]], +key)) {
491
+ options2.push(enum__[key]);
492
+ }
493
+ }
494
+ return {
495
+ kind: "schema",
496
+ type: "enum",
497
+ reference: enum_,
498
+ expects: /* @__PURE__ */ _joinExpects(options2.map(_stringify), "|"),
499
+ async: false,
500
+ enum: enum__,
501
+ options: options2,
502
+ message,
503
+ get "~standard"() {
504
+ return /* @__PURE__ */ _getStandardProps(this);
505
+ },
506
+ "~run"(dataset, config2) {
507
+ if (this.options.includes(dataset.value)) {
508
+ dataset.typed = true;
509
+ } else {
510
+ _addIssue(this, "type", dataset, config2);
511
+ }
512
+ return dataset;
513
+ }
514
+ };
515
+ }
516
+ // @__NO_SIDE_EFFECTS__
517
+ function literal(literal_, message) {
518
+ return {
519
+ kind: "schema",
520
+ type: "literal",
521
+ reference: literal,
522
+ expects: /* @__PURE__ */ _stringify(literal_),
523
+ async: false,
524
+ literal: literal_,
525
+ message,
526
+ get "~standard"() {
527
+ return /* @__PURE__ */ _getStandardProps(this);
528
+ },
529
+ "~run"(dataset, config2) {
530
+ if (dataset.value === this.literal) {
531
+ dataset.typed = true;
532
+ } else {
533
+ _addIssue(this, "type", dataset, config2);
534
+ }
535
+ return dataset;
536
+ }
537
+ };
538
+ }
539
+ // @__NO_SIDE_EFFECTS__
540
+ function nullable(wrapped, default_) {
541
+ return {
542
+ kind: "schema",
543
+ type: "nullable",
544
+ reference: nullable,
545
+ expects: `(${wrapped.expects} | null)`,
546
+ async: false,
547
+ wrapped,
548
+ default: default_,
549
+ get "~standard"() {
550
+ return /* @__PURE__ */ _getStandardProps(this);
551
+ },
552
+ "~run"(dataset, config2) {
553
+ if (dataset.value === null) {
554
+ if (this.default !== void 0) {
555
+ dataset.value = /* @__PURE__ */ getDefault(this, dataset, config2);
556
+ }
557
+ if (dataset.value === null) {
558
+ dataset.typed = true;
559
+ return dataset;
560
+ }
561
+ }
562
+ return this.wrapped["~run"](dataset, config2);
563
+ }
564
+ };
565
+ }
566
+ // @__NO_SIDE_EFFECTS__
567
+ function number(message) {
568
+ return {
569
+ kind: "schema",
570
+ type: "number",
571
+ reference: number,
572
+ expects: "number",
573
+ async: false,
574
+ message,
575
+ get "~standard"() {
576
+ return /* @__PURE__ */ _getStandardProps(this);
577
+ },
578
+ "~run"(dataset, config2) {
579
+ if (typeof dataset.value === "number" && !isNaN(dataset.value)) {
580
+ dataset.typed = true;
581
+ } else {
582
+ _addIssue(this, "type", dataset, config2);
583
+ }
584
+ return dataset;
585
+ }
586
+ };
587
+ }
588
+ // @__NO_SIDE_EFFECTS__
589
+ function object(entries, message) {
590
+ return {
591
+ kind: "schema",
592
+ type: "object",
593
+ reference: object,
594
+ expects: "Object",
595
+ async: false,
596
+ entries,
597
+ message,
598
+ get "~standard"() {
599
+ return /* @__PURE__ */ _getStandardProps(this);
600
+ },
601
+ "~run"(dataset, config2) {
602
+ var _a;
603
+ const input = dataset.value;
604
+ if (input && typeof input === "object") {
605
+ dataset.typed = true;
606
+ dataset.value = {};
607
+ for (const key in this.entries) {
608
+ const valueSchema = this.entries[key];
609
+ if (key in input || (valueSchema.type === "exact_optional" || valueSchema.type === "optional" || valueSchema.type === "nullish") && // @ts-expect-error
610
+ valueSchema.default !== void 0) {
611
+ const value2 = key in input ? (
612
+ // @ts-expect-error
613
+ input[key]
614
+ ) : /* @__PURE__ */ getDefault(valueSchema);
615
+ const valueDataset = valueSchema["~run"]({ value: value2 }, config2);
616
+ if (valueDataset.issues) {
617
+ const pathItem = {
618
+ type: "object",
619
+ origin: "value",
620
+ input,
621
+ key,
622
+ value: value2
623
+ };
624
+ for (const issue of valueDataset.issues) {
625
+ if (issue.path) {
626
+ issue.path.unshift(pathItem);
627
+ } else {
628
+ issue.path = [pathItem];
629
+ }
630
+ (_a = dataset.issues) == null ? void 0 : _a.push(issue);
631
+ }
632
+ if (!dataset.issues) {
633
+ dataset.issues = valueDataset.issues;
634
+ }
635
+ if (config2.abortEarly) {
636
+ dataset.typed = false;
637
+ break;
638
+ }
639
+ }
640
+ if (!valueDataset.typed) {
641
+ dataset.typed = false;
642
+ }
643
+ dataset.value[key] = valueDataset.value;
644
+ } else if (valueSchema.fallback !== void 0) {
645
+ dataset.value[key] = /* @__PURE__ */ getFallback(valueSchema);
646
+ } else if (valueSchema.type !== "exact_optional" && valueSchema.type !== "optional" && valueSchema.type !== "nullish") {
647
+ _addIssue(this, "key", dataset, config2, {
648
+ input: void 0,
649
+ expected: `"${key}"`,
650
+ path: [
651
+ {
652
+ type: "object",
653
+ origin: "key",
654
+ input,
655
+ key,
656
+ // @ts-expect-error
657
+ value: input[key]
658
+ }
659
+ ]
660
+ });
661
+ if (config2.abortEarly) {
662
+ break;
663
+ }
664
+ }
665
+ }
666
+ } else {
667
+ _addIssue(this, "type", dataset, config2);
668
+ }
669
+ return dataset;
670
+ }
671
+ };
672
+ }
673
+ // @__NO_SIDE_EFFECTS__
674
+ function optional(wrapped, default_) {
675
+ return {
676
+ kind: "schema",
677
+ type: "optional",
678
+ reference: optional,
679
+ expects: `(${wrapped.expects} | undefined)`,
680
+ async: false,
681
+ wrapped,
682
+ default: default_,
683
+ get "~standard"() {
684
+ return /* @__PURE__ */ _getStandardProps(this);
685
+ },
686
+ "~run"(dataset, config2) {
687
+ if (dataset.value === void 0) {
688
+ if (this.default !== void 0) {
689
+ dataset.value = /* @__PURE__ */ getDefault(this, dataset, config2);
690
+ }
691
+ if (dataset.value === void 0) {
692
+ dataset.typed = true;
693
+ return dataset;
694
+ }
695
+ }
696
+ return this.wrapped["~run"](dataset, config2);
697
+ }
698
+ };
699
+ }
700
+ // @__NO_SIDE_EFFECTS__
701
+ function picklist(options2, message) {
702
+ return {
703
+ kind: "schema",
704
+ type: "picklist",
705
+ reference: picklist,
706
+ expects: /* @__PURE__ */ _joinExpects(options2.map(_stringify), "|"),
707
+ async: false,
708
+ options: options2,
709
+ message,
710
+ get "~standard"() {
711
+ return /* @__PURE__ */ _getStandardProps(this);
712
+ },
713
+ "~run"(dataset, config2) {
714
+ if (this.options.includes(dataset.value)) {
715
+ dataset.typed = true;
716
+ } else {
717
+ _addIssue(this, "type", dataset, config2);
718
+ }
719
+ return dataset;
720
+ }
721
+ };
722
+ }
723
+ // @__NO_SIDE_EFFECTS__
724
+ function record(key, value2, message) {
725
+ return {
726
+ kind: "schema",
727
+ type: "record",
728
+ reference: record,
729
+ expects: "Object",
730
+ async: false,
731
+ key,
732
+ value: value2,
733
+ message,
734
+ get "~standard"() {
735
+ return /* @__PURE__ */ _getStandardProps(this);
736
+ },
737
+ "~run"(dataset, config2) {
738
+ var _a, _b;
739
+ const input = dataset.value;
740
+ if (input && typeof input === "object") {
741
+ dataset.typed = true;
742
+ dataset.value = {};
743
+ for (const entryKey in input) {
744
+ if (/* @__PURE__ */ _isValidObjectKey(input, entryKey)) {
745
+ const entryValue = input[entryKey];
746
+ const keyDataset = this.key["~run"]({ value: entryKey }, config2);
747
+ if (keyDataset.issues) {
748
+ const pathItem = {
749
+ type: "object",
750
+ origin: "key",
751
+ input,
752
+ key: entryKey,
753
+ value: entryValue
754
+ };
755
+ for (const issue of keyDataset.issues) {
756
+ issue.path = [pathItem];
757
+ (_a = dataset.issues) == null ? void 0 : _a.push(issue);
758
+ }
759
+ if (!dataset.issues) {
760
+ dataset.issues = keyDataset.issues;
761
+ }
762
+ if (config2.abortEarly) {
763
+ dataset.typed = false;
764
+ break;
765
+ }
766
+ }
767
+ const valueDataset = this.value["~run"](
768
+ { value: entryValue },
769
+ config2
770
+ );
771
+ if (valueDataset.issues) {
772
+ const pathItem = {
773
+ type: "object",
774
+ origin: "value",
775
+ input,
776
+ key: entryKey,
777
+ value: entryValue
778
+ };
779
+ for (const issue of valueDataset.issues) {
780
+ if (issue.path) {
781
+ issue.path.unshift(pathItem);
782
+ } else {
783
+ issue.path = [pathItem];
784
+ }
785
+ (_b = dataset.issues) == null ? void 0 : _b.push(issue);
786
+ }
787
+ if (!dataset.issues) {
788
+ dataset.issues = valueDataset.issues;
789
+ }
790
+ if (config2.abortEarly) {
791
+ dataset.typed = false;
792
+ break;
793
+ }
794
+ }
795
+ if (!keyDataset.typed || !valueDataset.typed) {
796
+ dataset.typed = false;
797
+ }
798
+ if (keyDataset.typed) {
799
+ dataset.value[keyDataset.value] = valueDataset.value;
800
+ }
801
+ }
802
+ }
803
+ } else {
804
+ _addIssue(this, "type", dataset, config2);
805
+ }
806
+ return dataset;
807
+ }
808
+ };
809
+ }
810
+ // @__NO_SIDE_EFFECTS__
811
+ function string(message) {
812
+ return {
813
+ kind: "schema",
814
+ type: "string",
815
+ reference: string,
816
+ expects: "string",
817
+ async: false,
818
+ message,
819
+ get "~standard"() {
820
+ return /* @__PURE__ */ _getStandardProps(this);
821
+ },
822
+ "~run"(dataset, config2) {
823
+ if (typeof dataset.value === "string") {
824
+ dataset.typed = true;
825
+ } else {
826
+ _addIssue(this, "type", dataset, config2);
827
+ }
828
+ return dataset;
829
+ }
830
+ };
831
+ }
832
+ // @__NO_SIDE_EFFECTS__
833
+ function _subIssues(datasets) {
834
+ let issues;
835
+ if (datasets) {
836
+ for (const dataset of datasets) {
837
+ if (issues) {
838
+ issues.push(...dataset.issues);
839
+ } else {
840
+ issues = dataset.issues;
841
+ }
842
+ }
843
+ }
844
+ return issues;
845
+ }
846
+ // @__NO_SIDE_EFFECTS__
847
+ function union(options2, message) {
848
+ return {
849
+ kind: "schema",
850
+ type: "union",
851
+ reference: union,
852
+ expects: /* @__PURE__ */ _joinExpects(
853
+ options2.map((option) => option.expects),
854
+ "|"
855
+ ),
856
+ async: false,
857
+ options: options2,
858
+ message,
859
+ get "~standard"() {
860
+ return /* @__PURE__ */ _getStandardProps(this);
861
+ },
862
+ "~run"(dataset, config2) {
863
+ let validDataset;
864
+ let typedDatasets;
865
+ let untypedDatasets;
866
+ for (const schema of this.options) {
867
+ const optionDataset = schema["~run"]({ value: dataset.value }, config2);
868
+ if (optionDataset.typed) {
869
+ if (optionDataset.issues) {
870
+ if (typedDatasets) {
871
+ typedDatasets.push(optionDataset);
872
+ } else {
873
+ typedDatasets = [optionDataset];
874
+ }
875
+ } else {
876
+ validDataset = optionDataset;
877
+ break;
878
+ }
879
+ } else {
880
+ if (untypedDatasets) {
881
+ untypedDatasets.push(optionDataset);
882
+ } else {
883
+ untypedDatasets = [optionDataset];
884
+ }
885
+ }
886
+ }
887
+ if (validDataset) {
888
+ return validDataset;
889
+ }
890
+ if (typedDatasets) {
891
+ if (typedDatasets.length === 1) {
892
+ return typedDatasets[0];
893
+ }
894
+ _addIssue(this, "type", dataset, config2, {
895
+ issues: /* @__PURE__ */ _subIssues(typedDatasets)
896
+ });
897
+ dataset.typed = true;
898
+ } else if ((untypedDatasets == null ? void 0 : untypedDatasets.length) === 1) {
899
+ return untypedDatasets[0];
900
+ } else {
901
+ _addIssue(this, "type", dataset, config2, {
902
+ issues: /* @__PURE__ */ _subIssues(untypedDatasets)
903
+ });
904
+ }
905
+ return dataset;
906
+ }
907
+ };
908
+ }
909
+ function parse(schema, input, config2) {
910
+ const dataset = schema["~run"]({ value: input }, /* @__PURE__ */ getGlobalConfig(config2));
911
+ if (dataset.issues) {
912
+ throw new ValiError(dataset.issues);
913
+ }
914
+ return dataset.value;
915
+ }
916
+ // @__NO_SIDE_EFFECTS__
917
+ function pipe(...pipe2) {
918
+ return {
919
+ ...pipe2[0],
920
+ pipe: pipe2,
921
+ get "~standard"() {
922
+ return /* @__PURE__ */ _getStandardProps(this);
923
+ },
924
+ "~run"(dataset, config2) {
925
+ for (const item of pipe2) {
926
+ if (item.kind !== "metadata") {
927
+ if (dataset.issues && (item.kind === "schema" || item.kind === "transformation")) {
928
+ dataset.typed = false;
929
+ break;
930
+ }
931
+ if (!dataset.issues || !config2.abortEarly && !config2.abortPipeEarly) {
932
+ dataset = item["~run"](dataset, config2);
933
+ }
934
+ }
935
+ }
936
+ return dataset;
937
+ }
27
938
  };
28
939
  }
29
- const useGlobalManager = () => useContext(GlobalManager);
940
+ // @__NO_SIDE_EFFECTS__
941
+ function safeParse(schema, input, config2) {
942
+ const dataset = schema["~run"]({ value: input }, /* @__PURE__ */ getGlobalConfig(config2));
943
+ return {
944
+ typed: dataset.typed,
945
+ success: !dataset.issues,
946
+ output: dataset.value,
947
+ issues: dataset.issues
948
+ };
949
+ }
950
+ const linkValidator = /* @__PURE__ */ check(
951
+ (value) => {
952
+ var _a, _b;
953
+ return !!value && ((_b = (_a = value == null ? void 0 : value.split) == null ? void 0 : _a.call(value, ":")) == null ? void 0 : _b.length) === 2;
954
+ }
955
+ );
956
+ const isLink = (value) => {
957
+ var _a;
958
+ return (_a = /* @__PURE__ */ safeParse(linkValidator, value)) == null ? void 0 : _a.success;
959
+ };
960
+ const isVariableLink = (value) => {
961
+ var _a, _b;
962
+ return isLink(value) && ((_b = (_a = value == null ? void 0 : value.split) == null ? void 0 : _a.call(value, ":")) == null ? void 0 : _b.at(0)) === nodes.Variable;
963
+ };
964
+ const getMetadata = (schema) => {
965
+ var _a;
966
+ const pipelines = (schema == null ? void 0 : schema.pipe) ?? [];
967
+ return ((_a = pipelines == null ? void 0 : pipelines.find((pipe2) => /* @__PURE__ */ isOfKind("metadata", pipe2))) == null ? void 0 : _a.metadata) ?? null;
968
+ };
969
+ const layerField = (schema, meta) => {
970
+ const modifiedSchema = (meta == null ? void 0 : meta.variable) ? /* @__PURE__ */ union([schema, /* @__PURE__ */ pipe(/* @__PURE__ */ string(), linkValidator)]) : schema;
971
+ return /* @__PURE__ */ pipe(
972
+ /* @__PURE__ */ optional(modifiedSchema),
973
+ /* @__PURE__ */ transform((meta == null ? void 0 : meta.transform) ?? ((v2) => v2)),
974
+ /* @__PURE__ */ metadata(meta ?? {})
975
+ );
976
+ };
977
+ const ChildrenSchema = /* @__PURE__ */ object({
978
+ children: layerField(/* @__PURE__ */ array(/* @__PURE__ */ string()), {
979
+ fallback: [],
980
+ overridable: false
981
+ })
982
+ });
983
+ const GraphFieldSchema = /* @__PURE__ */ object({
984
+ _id: /* @__PURE__ */ union([/* @__PURE__ */ string(), /* @__PURE__ */ number()]),
985
+ _type: /* @__PURE__ */ picklist(Object.keys(nodes))
986
+ });
987
+ const OverridesSchema = /* @__PURE__ */ object({
988
+ overrides: layerField(/* @__PURE__ */ array(/* @__PURE__ */ string()), { overridable: false }),
989
+ overrideFrom: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false })
990
+ });
991
+ const PositionSchema = /* @__PURE__ */ object({
992
+ position: layerField(/* @__PURE__ */ enum_(Object.keys(positionType)), {
993
+ fallback: positionType.absolute
994
+ }),
995
+ top: layerField(/* @__PURE__ */ number(), { fallback: 0, transform: Math.ceil }),
996
+ left: layerField(/* @__PURE__ */ number(), { fallback: 0, transform: Math.ceil })
997
+ });
998
+ const SceneSchema = /* @__PURE__ */ object({
999
+ opacity: layerField(/* @__PURE__ */ pipe(/* @__PURE__ */ number(), /* @__PURE__ */ minValue(0), /* @__PURE__ */ maxValue(1)), {
1000
+ fallback: 1,
1001
+ variable: true
1002
+ }),
1003
+ visible: layerField(/* @__PURE__ */ boolean(), { fallback: true, variable: true }),
1004
+ zIndex: layerField(/* @__PURE__ */ number(), { fallback: -1 })
1005
+ });
1006
+ const FillSchema = /* @__PURE__ */ object({
1007
+ fillType: layerField(/* @__PURE__ */ picklist(Object.keys(paintMode)), {
1008
+ fallback: paintMode.None
1009
+ }),
1010
+ solidFill: layerField(/* @__PURE__ */ string(), { fallback: "#fff" }),
1011
+ imageFill: layerField(/* @__PURE__ */ string()),
1012
+ imageSize: layerField(/* @__PURE__ */ picklist(Object.keys(imagePaintScaleModes)), {
1013
+ fallback: imagePaintScaleModes.Fill
1014
+ })
1015
+ });
1016
+ const BorderSchema = /* @__PURE__ */ object({
1017
+ borderType: layerField(/* @__PURE__ */ picklist(Object.keys(borderType)), {
1018
+ fallback: borderType.None
1019
+ }),
1020
+ borderWidth: layerField(/* @__PURE__ */ pipe(/* @__PURE__ */ number(), /* @__PURE__ */ minValue(0)), { fallback: 0 }),
1021
+ borderColor: layerField(/* @__PURE__ */ string(), { fallback: "#fff" })
1022
+ });
1023
+ const SizeSchema = /* @__PURE__ */ object({
1024
+ widthType: layerField(/* @__PURE__ */ picklist(Object.keys(sizing)), {
1025
+ fallback: sizing.Fixed
1026
+ }),
1027
+ heightType: layerField(/* @__PURE__ */ picklist(Object.keys(sizing)), {
1028
+ fallback: sizing.Fixed
1029
+ }),
1030
+ width: layerField(/* @__PURE__ */ pipe(/* @__PURE__ */ number(), /* @__PURE__ */ minValue(0)), {
1031
+ fallback: 0,
1032
+ transform: Math.ceil
1033
+ }),
1034
+ height: layerField(/* @__PURE__ */ pipe(/* @__PURE__ */ number(), /* @__PURE__ */ minValue(0)), {
1035
+ fallback: 0,
1036
+ transform: Math.ceil
1037
+ }),
1038
+ aspectRatio: layerField(/* @__PURE__ */ number(), { fallback: -1 }),
1039
+ minWidth: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ pipe(/* @__PURE__ */ number(), /* @__PURE__ */ minValue(-1))), {
1040
+ fallback: -1,
1041
+ transform: Math.ceil
1042
+ }),
1043
+ minWidthType: layerField(/* @__PURE__ */ picklist(Object.keys(sizing)), {
1044
+ fallback: sizing.Fixed
1045
+ }),
1046
+ maxWidth: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ pipe(/* @__PURE__ */ number(), /* @__PURE__ */ minValue(-1))), {
1047
+ fallback: -1,
1048
+ transform: Math.ceil
1049
+ }),
1050
+ maxWidthType: layerField(/* @__PURE__ */ picklist(Object.keys(sizing)), {
1051
+ fallback: sizing.Fixed
1052
+ }),
1053
+ minHeight: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ pipe(/* @__PURE__ */ number(), /* @__PURE__ */ minValue(-1))), {
1054
+ fallback: -1,
1055
+ transform: Math.ceil
1056
+ }),
1057
+ minHeightType: layerField(/* @__PURE__ */ picklist(Object.keys(sizing)), {
1058
+ fallback: sizing.Fixed
1059
+ }),
1060
+ maxHeight: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ pipe(/* @__PURE__ */ number(), /* @__PURE__ */ minValue(-1))), {
1061
+ fallback: -1,
1062
+ transform: Math.ceil
1063
+ }),
1064
+ maxHeightType: layerField(/* @__PURE__ */ picklist(Object.keys(sizing)), {
1065
+ fallback: sizing.Fixed
1066
+ })
1067
+ });
1068
+ const LayerSchema = /* @__PURE__ */ object({
1069
+ layerMode: layerField(/* @__PURE__ */ picklist(Object.keys(layerMode)), {
1070
+ fallback: layerMode.none
1071
+ }),
1072
+ layerAlign: layerField(/* @__PURE__ */ picklist(Object.keys(layerAlign)), {
1073
+ fallback: layerAlign.start
1074
+ }),
1075
+ layerDirection: layerField(/* @__PURE__ */ picklist(Object.keys(layerDirection)), {
1076
+ fallback: layerDirection.horizontal
1077
+ }),
1078
+ layerDistribute: layerField(/* @__PURE__ */ picklist(Object.keys(layerDistribute)), {
1079
+ fallback: layerDistribute.start
1080
+ }),
1081
+ layerWrap: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1082
+ layerGap: layerField(/* @__PURE__ */ pipe(/* @__PURE__ */ number(), /* @__PURE__ */ minValue(0)), { fallback: 0 }),
1083
+ padding: layerField(/* @__PURE__ */ string(), { fallback: "0px" })
1084
+ });
1085
+ const OverflowSchema = layerField(/* @__PURE__ */ picklist(Object.keys(overflow)), {
1086
+ fallback: overflow.hidden
1087
+ });
1088
+ const BorderRadiusSchema = layerField(/* @__PURE__ */ string(), { fallback: "0px" });
1089
+ const InteractionsSchema = /* @__PURE__ */ object({
1090
+ interactions: layerField(
1091
+ /* @__PURE__ */ array(
1092
+ /* @__PURE__ */ object({
1093
+ on: /* @__PURE__ */ enum_(Object.keys(interactions)),
1094
+ event: /* @__PURE__ */ nullable(linkValidator)
1095
+ })
1096
+ ),
1097
+ { fallback: [] }
1098
+ )
1099
+ });
1100
+ const CssOverrideSchema = /* @__PURE__ */ object({
1101
+ cssOverride: layerField(/* @__PURE__ */ string(), { fallback: "" })
1102
+ });
1103
+ const FrameSchema = /* @__PURE__ */ pipe(
1104
+ /* @__PURE__ */ object({
1105
+ name: layerField(/* @__PURE__ */ string(), { fallback: "Frame", overridable: false }),
1106
+ isBreakpoint: layerField(/* @__PURE__ */ boolean(), {
1107
+ fallback: false,
1108
+ overridable: false
1109
+ }),
1110
+ isPrimary: layerField(/* @__PURE__ */ boolean(), { fallback: false, overridable: false }),
1111
+ parent: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false }),
1112
+ ...ChildrenSchema.entries,
1113
+ ...GraphFieldSchema.entries,
1114
+ ...OverridesSchema.entries,
1115
+ ...PositionSchema.entries,
1116
+ ...SceneSchema.entries,
1117
+ ...FillSchema.entries,
1118
+ ...BorderSchema.entries,
1119
+ ...SizeSchema.entries,
1120
+ ...LayerSchema.entries,
1121
+ ...InteractionsSchema.entries,
1122
+ ...CssOverrideSchema.entries,
1123
+ overflow: OverflowSchema,
1124
+ borderRadius: BorderRadiusSchema
1125
+ })
1126
+ );
1127
+ const TextSchema = /* @__PURE__ */ object({
1128
+ name: layerField(/* @__PURE__ */ string(), { fallback: "Text", overridable: false }),
1129
+ content: layerField(/* @__PURE__ */ string(), {
1130
+ fallback: ""
1131
+ }),
1132
+ whiteSpace: layerField(/* @__PURE__ */ enum_(Object.keys(whiteSpace)), {
1133
+ fallback: whiteSpace.pre
1134
+ }),
1135
+ variableContent: layerField(/* @__PURE__ */ string(), { fallback: null, variable: true }),
1136
+ parent: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false }),
1137
+ attributes: layerField(
1138
+ /* @__PURE__ */ object({
1139
+ fontSize: layerField(/* @__PURE__ */ string(), { fallback: "14px" }),
1140
+ color: layerField(/* @__PURE__ */ string(), { fallback: "#000" }),
1141
+ lineHeight: layerField(/* @__PURE__ */ string(), { fallback: "14px" }),
1142
+ fontWeight: layerField(/* @__PURE__ */ string(), { fallback: "normal" }),
1143
+ letterSpacing: layerField(/* @__PURE__ */ string(), { fallback: "0px" }),
1144
+ textTransform: layerField(/* @__PURE__ */ string(), { fallback: "none" }),
1145
+ textDecoration: layerField(/* @__PURE__ */ string(), { fallback: "none" }),
1146
+ whiteSpace: layerField(/* @__PURE__ */ string(), { fallback: "pre" }),
1147
+ textAlign: layerField(/* @__PURE__ */ string(), { fallback: "left" })
1148
+ }),
1149
+ { fallback: {} }
1150
+ ),
1151
+ ...GraphFieldSchema.entries,
1152
+ ...OverridesSchema.entries,
1153
+ ...PositionSchema.entries,
1154
+ ...SceneSchema.entries,
1155
+ ...SizeSchema.entries
1156
+ });
1157
+ const FragmentSchema = /* @__PURE__ */ object({
1158
+ name: layerField(/* @__PURE__ */ string(), { fallback: "Fragment", overridable: false }),
1159
+ parent: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false }),
1160
+ horizontalGrow: layerField(/* @__PURE__ */ enum_(Object.keys(fragmentGrowingMode)), {
1161
+ fallback: fragmentGrowingMode.auto,
1162
+ overridable: false
1163
+ }),
1164
+ verticalGrow: layerField(/* @__PURE__ */ enum_(Object.keys(fragmentGrowingMode)), {
1165
+ fallback: fragmentGrowingMode.auto,
1166
+ overridable: false
1167
+ }),
1168
+ properties: layerField(/* @__PURE__ */ array(/* @__PURE__ */ string()), {
1169
+ fallback: [],
1170
+ overridable: false
1171
+ }),
1172
+ ...GraphFieldSchema.entries,
1173
+ ...ChildrenSchema.entries
1174
+ });
1175
+ const InstanceSchema = /* @__PURE__ */ object({
1176
+ name: layerField(/* @__PURE__ */ string(), { fallback: "Instance", overridable: false }),
1177
+ fragment: layerField(/* @__PURE__ */ number()),
1178
+ parent: layerField(/* @__PURE__ */ nullable(/* @__PURE__ */ string()), { overridable: false }),
1179
+ props: layerField(
1180
+ /* @__PURE__ */ record(
1181
+ /* @__PURE__ */ string(),
1182
+ /* @__PURE__ */ union([
1183
+ /* @__PURE__ */ string(),
1184
+ /* @__PURE__ */ number(),
1185
+ /* @__PURE__ */ boolean(),
1186
+ // For goals
1187
+ /* @__PURE__ */ object({
1188
+ code: /* @__PURE__ */ string(),
1189
+ name: /* @__PURE__ */ string()
1190
+ })
1191
+ ])
1192
+ ),
1193
+ {
1194
+ fallback: {}
1195
+ }
1196
+ ),
1197
+ ...GraphFieldSchema.entries,
1198
+ ...OverridesSchema.entries,
1199
+ ...PositionSchema.entries,
1200
+ ...SizeSchema.entries,
1201
+ ...SceneSchema.entries
1202
+ });
1203
+ const NumberVariableSchema = /* @__PURE__ */ object({
1204
+ name: layerField(/* @__PURE__ */ string(), {
1205
+ fallback: "Number",
1206
+ overridable: false
1207
+ }),
1208
+ type: layerField(/* @__PURE__ */ literal(variableType.Number), {
1209
+ fallback: variableType.Number
1210
+ }),
1211
+ defaultValue: layerField(/* @__PURE__ */ number(), { fallback: 0 }),
1212
+ required: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1213
+ min: layerField(/* @__PURE__ */ number(), { fallback: 1 }),
1214
+ max: layerField(/* @__PURE__ */ number(), { fallback: 100 }),
1215
+ step: layerField(/* @__PURE__ */ number(), { fallback: 1 }),
1216
+ displayStepper: layerField(/* @__PURE__ */ boolean(), { fallback: true }),
1217
+ ...GraphFieldSchema.entries
1218
+ });
1219
+ const BooleanVariableSchema = /* @__PURE__ */ object({
1220
+ name: layerField(/* @__PURE__ */ string(), {
1221
+ fallback: "Boolean",
1222
+ overridable: false
1223
+ }),
1224
+ type: layerField(/* @__PURE__ */ literal(variableType.Boolean), {
1225
+ fallback: variableType.Boolean
1226
+ }),
1227
+ defaultValue: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1228
+ required: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1229
+ ...GraphFieldSchema.entries
1230
+ });
1231
+ const ColorVariableSchema = /* @__PURE__ */ object({
1232
+ name: layerField(/* @__PURE__ */ string(), {
1233
+ fallback: "String",
1234
+ overridable: false
1235
+ }),
1236
+ type: layerField(/* @__PURE__ */ literal(variableType.Color), {
1237
+ fallback: variableType.Color
1238
+ }),
1239
+ // TODO Add color validator
1240
+ defaultValue: layerField(/* @__PURE__ */ string(), { fallback: "#000" }),
1241
+ required: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1242
+ ...GraphFieldSchema.entries
1243
+ });
1244
+ const StringVariableSchema = /* @__PURE__ */ object({
1245
+ name: layerField(/* @__PURE__ */ string(), {
1246
+ fallback: "String",
1247
+ overridable: false
1248
+ }),
1249
+ type: layerField(/* @__PURE__ */ literal(variableType.String), {
1250
+ fallback: variableType.String
1251
+ }),
1252
+ defaultValue: layerField(/* @__PURE__ */ string(), { fallback: "" }),
1253
+ required: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1254
+ placeholder: layerField(/* @__PURE__ */ string(), { fallback: "" }),
1255
+ isTextarea: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1256
+ ...GraphFieldSchema.entries
1257
+ });
1258
+ const EventVariableSchema = /* @__PURE__ */ object({
1259
+ name: layerField(/* @__PURE__ */ string(), {
1260
+ fallback: "Event",
1261
+ overridable: false
1262
+ }),
1263
+ type: layerField(/* @__PURE__ */ literal(variableType.Event), {
1264
+ fallback: variableType.Event
1265
+ }),
1266
+ mode: layerField(/* @__PURE__ */ picklist(Object.keys(eventMode)), {
1267
+ fallback: eventMode.callback
1268
+ }),
1269
+ defaultValue: layerField(/* @__PURE__ */ any()),
1270
+ required: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1271
+ ...GraphFieldSchema.entries
1272
+ });
1273
+ const getLayerSchema = (layer) => {
1274
+ if (!(layer == null ? void 0 : layer._type)) return null;
1275
+ if ((layer == null ? void 0 : layer._type) === nodes.Frame) return FrameSchema;
1276
+ if ((layer == null ? void 0 : layer._type) === nodes.Text) return TextSchema;
1277
+ if ((layer == null ? void 0 : layer._type) === nodes.Fragment) return FragmentSchema;
1278
+ if ((layer == null ? void 0 : layer._type) === nodes.Instance) return InstanceSchema;
1279
+ if (layer._type === nodes.Variable) {
1280
+ const types = {
1281
+ [variableType.Number]: NumberVariableSchema,
1282
+ [variableType.Boolean]: BooleanVariableSchema,
1283
+ [variableType.String]: StringVariableSchema,
1284
+ [variableType.Color]: ColorVariableSchema,
1285
+ [variableType.Event]: EventVariableSchema
1286
+ };
1287
+ if (layer.type in types) {
1288
+ return types[layer.type];
1289
+ }
1290
+ }
1291
+ };
1292
+ const normalizeLayer = (schema, rawLayer, options2) => {
1293
+ try {
1294
+ if (!rawLayer) return null;
1295
+ const withFallback = (options2 == null ? void 0 : options2.withFallback) ?? true;
1296
+ const overrideTarget = options2 == null ? void 0 : options2.overrideTarget;
1297
+ const parsedLayer = parse(schema, rawLayer);
1298
+ return Object.fromEntries(
1299
+ Object.entries(schema.entries).map(([key, schemaEntity]) => {
1300
+ const schemaMeta = getMetadata(schemaEntity);
1301
+ const fallback = withFallback ? schemaMeta == null ? void 0 : schemaMeta.fallback : null;
1302
+ const overrideValue = (schemaMeta == null ? void 0 : schemaMeta.overridable) !== false && overrideTarget ? overrideTarget == null ? void 0 : overrideTarget[key] : null;
1303
+ const resultValue = parsedLayer[key] ?? overrideValue ?? fallback;
1304
+ return [key, resultValue];
1305
+ })
1306
+ );
1307
+ } catch (e) {
1308
+ console.error(e);
1309
+ return null;
1310
+ }
1311
+ };
1312
+ const getNormalizeLayer$1 = (layer, overrider) => {
1313
+ if (!layer) return null;
1314
+ const schema = getLayerSchema(layer);
1315
+ if (!schema) return null;
1316
+ return normalizeLayer(schema, layer, {
1317
+ overrideTarget: overrider
1318
+ });
1319
+ };
1320
+ const parseLayerField = (layer, field, value) => {
1321
+ var _a, _b;
1322
+ const schema = getLayerSchema(layer);
1323
+ if (schema && ((_a = schema == null ? void 0 : schema.entries) == null ? void 0 : _a[field])) {
1324
+ return /* @__PURE__ */ safeParse((_b = schema.entries) == null ? void 0 : _b[field], value);
1325
+ }
1326
+ return { success: false, output: value };
1327
+ };
1328
+ const RenderTargetContext = createContext(
1329
+ index.renderTarget.document
1330
+ );
1331
+ RenderTargetContext.Provider;
1332
+ const useRenderTarget = () => {
1333
+ const renderTarget2 = useContext(RenderTargetContext);
1334
+ return {
1335
+ renderTarget: renderTarget2,
1336
+ isCanvas: renderTarget2 === index.renderTarget.canvas,
1337
+ isDocument: renderTarget2 === index.renderTarget.document
1338
+ };
1339
+ };
1340
+ const FragmentContext = createContext({
1341
+ manager: null
1342
+ });
1343
+ var withSelector = { exports: {} };
1344
+ var withSelector_production_min = {};
30
1345
  var shim = { exports: {} };
31
1346
  var useSyncExternalStoreShim_production_min = {};
32
1347
  /**
@@ -43,17 +1358,17 @@ function requireUseSyncExternalStoreShim_production_min() {
43
1358
  if (hasRequiredUseSyncExternalStoreShim_production_min) return useSyncExternalStoreShim_production_min;
44
1359
  hasRequiredUseSyncExternalStoreShim_production_min = 1;
45
1360
  var e = require$$0;
46
- function h(a, b) {
47
- return a === b && (0 !== a || 1 / a === 1 / b) || a !== a && b !== b;
1361
+ function h(a, b2) {
1362
+ return a === b2 && (0 !== a || 1 / a === 1 / b2) || a !== a && b2 !== b2;
48
1363
  }
49
1364
  var k = "function" === typeof Object.is ? Object.is : h, l = e.useState, m = e.useEffect, n = e.useLayoutEffect, p = e.useDebugValue;
50
- function q(a, b) {
51
- var d = b(), f = l({ inst: { value: d, getSnapshot: b } }), c = f[0].inst, g = f[1];
1365
+ function q(a, b2) {
1366
+ var d = b2(), f2 = l({ inst: { value: d, getSnapshot: b2 } }), c = f2[0].inst, g = f2[1];
52
1367
  n(function() {
53
1368
  c.value = d;
54
- c.getSnapshot = b;
1369
+ c.getSnapshot = b2;
55
1370
  r(c) && g({ inst: c });
56
- }, [a, d, b]);
1371
+ }, [a, d, b2]);
57
1372
  m(function() {
58
1373
  r(c) && g({ inst: c });
59
1374
  return a(function() {
@@ -64,20 +1379,20 @@ function requireUseSyncExternalStoreShim_production_min() {
64
1379
  return d;
65
1380
  }
66
1381
  function r(a) {
67
- var b = a.getSnapshot;
1382
+ var b2 = a.getSnapshot;
68
1383
  a = a.value;
69
1384
  try {
70
- var d = b();
1385
+ var d = b2();
71
1386
  return !k(a, d);
72
- } catch (f) {
1387
+ } catch (f2) {
73
1388
  return true;
74
1389
  }
75
1390
  }
76
- function t(a, b) {
77
- return b();
1391
+ function t(a, b2) {
1392
+ return b2();
78
1393
  }
79
- var u = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? t : q;
80
- useSyncExternalStoreShim_production_min.useSyncExternalStore = void 0 !== e.useSyncExternalStore ? e.useSyncExternalStore : u;
1394
+ var u2 = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? t : q;
1395
+ useSyncExternalStoreShim_production_min.useSyncExternalStore = void 0 !== e.useSyncExternalStore ? e.useSyncExternalStore : u2;
81
1396
  return useSyncExternalStoreShim_production_min;
82
1397
  }
83
1398
  var useSyncExternalStoreShim_development = {};
@@ -221,9 +1536,6 @@ function requireShim() {
221
1536
  }
222
1537
  return shim.exports;
223
1538
  }
224
- var shimExports = requireShim();
225
- var withSelector = { exports: {} };
226
- var withSelector_production_min = {};
227
1539
  /**
228
1540
  * @license React
229
1541
  * use-sync-external-store-shim/with-selector.production.min.js
@@ -238,46 +1550,46 @@ function requireWithSelector_production_min() {
238
1550
  if (hasRequiredWithSelector_production_min) return withSelector_production_min;
239
1551
  hasRequiredWithSelector_production_min = 1;
240
1552
  var h = require$$0, n = requireShim();
241
- function p(a, b) {
242
- return a === b && (0 !== a || 1 / a === 1 / b) || a !== a && b !== b;
1553
+ function p(a, b2) {
1554
+ return a === b2 && (0 !== a || 1 / a === 1 / b2) || a !== a && b2 !== b2;
243
1555
  }
244
- var q = "function" === typeof Object.is ? Object.is : p, r = n.useSyncExternalStore, t = h.useRef, u = h.useEffect, v = h.useMemo, w = h.useDebugValue;
245
- withSelector_production_min.useSyncExternalStoreWithSelector = function(a, b, e, l, g) {
1556
+ var q = "function" === typeof Object.is ? Object.is : p, r = n.useSyncExternalStore, t = h.useRef, u2 = h.useEffect, v = h.useMemo, w = h.useDebugValue;
1557
+ withSelector_production_min.useSyncExternalStoreWithSelector = function(a, b2, e, l, g) {
246
1558
  var c = t(null);
247
1559
  if (null === c.current) {
248
- var f = { hasValue: false, value: null };
249
- c.current = f;
250
- } else f = c.current;
1560
+ var f2 = { hasValue: false, value: null };
1561
+ c.current = f2;
1562
+ } else f2 = c.current;
251
1563
  c = v(function() {
252
1564
  function a2(a3) {
253
1565
  if (!c2) {
254
1566
  c2 = true;
255
1567
  d2 = a3;
256
1568
  a3 = l(a3);
257
- if (void 0 !== g && f.hasValue) {
258
- var b2 = f.value;
259
- if (g(b2, a3)) return k = b2;
1569
+ if (void 0 !== g && f2.hasValue) {
1570
+ var b3 = f2.value;
1571
+ if (g(b3, a3)) return k = b3;
260
1572
  }
261
1573
  return k = a3;
262
1574
  }
263
- b2 = k;
264
- if (q(d2, a3)) return b2;
1575
+ b3 = k;
1576
+ if (q(d2, a3)) return b3;
265
1577
  var e2 = l(a3);
266
- if (void 0 !== g && g(b2, e2)) return b2;
1578
+ if (void 0 !== g && g(b3, e2)) return b3;
267
1579
  d2 = a3;
268
1580
  return k = e2;
269
1581
  }
270
1582
  var c2 = false, d2, k, m = void 0 === e ? null : e;
271
1583
  return [function() {
272
- return a2(b());
1584
+ return a2(b2());
273
1585
  }, null === m ? void 0 : function() {
274
1586
  return a2(m());
275
1587
  }];
276
- }, [b, e, l, g]);
1588
+ }, [b2, e, l, g]);
277
1589
  var d = r(a, c[0], c[1]);
278
- u(function() {
279
- f.hasValue = true;
280
- f.value = d;
1590
+ u2(function() {
1591
+ f2.hasValue = true;
1592
+ f2.value = d;
281
1593
  }, [d]);
282
1594
  w(d);
283
1595
  return d;
@@ -310,7 +1622,7 @@ function requireWithSelector_development() {
310
1622
  }
311
1623
  var objectIs = typeof Object.is === "function" ? Object.is : is;
312
1624
  var useSyncExternalStore = shim2.useSyncExternalStore;
313
- var useRef2 = React.useRef, useEffect2 = React.useEffect, useMemo = React.useMemo, useDebugValue = React.useDebugValue;
1625
+ var useRef2 = React.useRef, useEffect2 = React.useEffect, useMemo2 = React.useMemo, useDebugValue = React.useDebugValue;
314
1626
  function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
315
1627
  var instRef = useRef2(null);
316
1628
  var inst;
@@ -323,7 +1635,7 @@ function requireWithSelector_development() {
323
1635
  } else {
324
1636
  inst = instRef.current;
325
1637
  }
326
- var _useMemo = useMemo(function() {
1638
+ var _useMemo = useMemo2(function() {
327
1639
  var hasMemo = false;
328
1640
  var memoizedSnapshot;
329
1641
  var memoizedSelection;
@@ -393,72 +1705,975 @@ function requireWithSelector() {
393
1705
  }
394
1706
  return withSelector.exports;
395
1707
  }
396
- requireWithSelector();
397
- var y = (t, e, n) => {
1708
+ var withSelectorExports = requireWithSelector();
1709
+ var b = (t) => t, y = (t, e, n) => {
398
1710
  var _a, _b;
399
- let r = useRef((_a = t == null ? void 0 : t.resolve) == null ? void 0 : _a.call(t, e, n)), s = ((_b = t == null ? void 0 : t.keyOfEntity) == null ? void 0 : _b.call(t, e)) ?? e, u = useCallback((o) => {
1711
+ let r = useRef((_a = t == null ? void 0 : t.resolve) == null ? void 0 : _a.call(t, e, n)), o = ((_b = t == null ? void 0 : t.keyOfEntity) == null ? void 0 : _b.call(t, e)) ?? e, p = useCallback((s) => {
400
1712
  var _a2, _b2;
401
- return s ? (r.current = (_a2 = t == null ? void 0 : t.resolve) == null ? void 0 : _a2.call(t, s, n), o(), (_b2 = t == null ? void 0 : t.subscribe) == null ? void 0 : _b2.call(t, s, () => {
1713
+ return o ? (r.current = (_a2 = t == null ? void 0 : t.resolve) == null ? void 0 : _a2.call(t, o, n), s(), (_b2 = t == null ? void 0 : t.subscribe) == null ? void 0 : _b2.call(t, o, () => {
402
1714
  var _a3;
403
- return r.current = (_a3 = t == null ? void 0 : t.resolve) == null ? void 0 : _a3.call(t, s, n), o();
1715
+ return r.current = (_a3 = t == null ? void 0 : t.resolve) == null ? void 0 : _a3.call(t, o, n), s();
404
1716
  }, n)) : () => {
405
1717
  };
406
- }, [t, s]), i = useCallback((o) => {
407
- let p = typeof e == "string" ? e : t.keyOfEntity(e);
408
- e && p && t.mutate(p, o);
1718
+ }, [t, o]), i = useCallback((s, u2) => {
1719
+ let c = typeof e == "string" ? e : t.keyOfEntity(e);
1720
+ e && c && t.mutate(c, s, u2);
409
1721
  }, [t, e]), a = () => r.current;
410
- return [shimExports.useSyncExternalStore(u, a, a), i];
1722
+ return [withSelectorExports.useSyncExternalStoreWithSelector(p, a, a, b), i];
411
1723
  };
412
- const useFragmentManager = (fragmentId) => {
413
- const globalManager = useGlobalManager();
414
- const [globalGraph] = y(globalManager, globalManager == null ? void 0 : globalManager.key);
415
- const [loading, setLoading] = useState(false);
416
- const getFragmentManager = (id) => {
417
- var _a;
418
- return (_a = globalGraph == null ? void 0 : globalGraph.fragmentsManagers) == null ? void 0 : _a[id];
1724
+ var __defProp = Object.defineProperty;
1725
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
1726
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
1727
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
1728
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1729
+ var __spreadValues = (a, b2) => {
1730
+ for (var prop in b2 || (b2 = {}))
1731
+ if (__hasOwnProp.call(b2, prop))
1732
+ __defNormalProp(a, prop, b2[prop]);
1733
+ if (__getOwnPropSymbols)
1734
+ for (var prop of __getOwnPropSymbols(b2)) {
1735
+ if (__propIsEnum.call(b2, prop))
1736
+ __defNormalProp(a, prop, b2[prop]);
1737
+ }
1738
+ return a;
1739
+ };
1740
+ var toPx = (val) => typeof val === "string" || typeof val === "number" ? `${val}px` : "0px";
1741
+ var isEmptyValue = (value) => !value && (value === null || value === void 0);
1742
+ var isValue = (value) => !isEmptyValue(value);
1743
+ var toKebabCase = (value) => value.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? "-" : "") + $.toLowerCase());
1744
+ var noop = () => void 0;
1745
+ var pick = (obj, ...props) => {
1746
+ return props.reduce((result, prop) => {
1747
+ result[prop] = obj[prop];
1748
+ return result;
1749
+ }, {});
1750
+ };
1751
+ function omit(obj, ...props) {
1752
+ const result = __spreadValues({}, obj);
1753
+ props.forEach((prop) => {
1754
+ delete result[prop];
1755
+ });
1756
+ return result;
1757
+ }
1758
+ var isBrowser_default = typeof window !== "undefined";
1759
+ function hashGenerator(layerKey) {
1760
+ let hash = 0;
1761
+ for (let i = 0; i < layerKey.length; i++) {
1762
+ hash = (hash << 5) - hash + layerKey.charCodeAt(i);
1763
+ hash |= 0;
1764
+ }
1765
+ const raw = Math.abs(hash).toString(36);
1766
+ return /^[0-9]/.test(raw) ? `h${raw}` : raw;
1767
+ }
1768
+ const getKey = (v) => isKey(v) ? v.slice(1) : null;
1769
+ const isKey = (v) => typeof v === "string" && v.startsWith("$");
1770
+ const getParent = (manager, layerKey) => {
1771
+ const layer = manager.resolve(layerKey);
1772
+ return manager.resolve(getKey(layer == null ? void 0 : layer.parent) ?? null);
1773
+ };
1774
+ const isTopLevel = (manager, layerKey) => {
1775
+ var _a;
1776
+ return ((_a = getParent(manager, layerKey)) == null ? void 0 : _a._type) === index.nodes.Fragment;
1777
+ };
1778
+ const getAllParents = (manager, layerKey, stack = []) => {
1779
+ const parent = getParent(manager, layerKey);
1780
+ if (parent) {
1781
+ stack.push(parent);
1782
+ getAllParents(manager, manager.keyOfEntity(parent), stack);
1783
+ }
1784
+ return stack;
1785
+ };
1786
+ const isPartOfPrimary = (manager, layerKey) => {
1787
+ var _a;
1788
+ const allParents = getAllParents(manager, manager.keyOfEntity(layerKey));
1789
+ const layer = manager.resolve(layerKey);
1790
+ return (layer == null ? void 0 : layer.isPrimary) ?? !!((_a = allParents == null ? void 0 : allParents.find) == null ? void 0 : _a.call(allParents, (parent) => !!(parent == null ? void 0 : parent.isPrimary)));
1791
+ };
1792
+ const getOverrider = (manager, layerEntity) => {
1793
+ const layer = manager.resolve(layerEntity);
1794
+ return manager.resolve(getKey(layer == null ? void 0 : layer.overrideFrom) ?? layerEntity);
1795
+ };
1796
+ const isInheritField = (manager, layerEntity, field) => {
1797
+ const layer = manager.resolve(layerEntity);
1798
+ if (layer) {
1799
+ const overrider = getOverrider(manager, layer);
1800
+ if ((overrider == null ? void 0 : overrider._id) === (layer == null ? void 0 : layer._id)) return false;
1801
+ return !!overrider && !isValue(layer == null ? void 0 : layer[field]);
1802
+ }
1803
+ return false;
1804
+ };
1805
+ const getLayer = (manager, layer) => {
1806
+ if (!manager || !layer) return null;
1807
+ const layerKey = manager.keyOfEntity(layer);
1808
+ const layerData = manager.resolve(layerKey);
1809
+ const overrider = getOverrider(manager, layerKey);
1810
+ return getNormalizeLayer$1(layerData, overrider);
1811
+ };
1812
+ const getNormalizeLayer = (layerKey, manager) => {
1813
+ const layer = manager == null ? void 0 : manager.resolve(layerKey);
1814
+ const parsedLayer = getLayer(manager, layerKey);
1815
+ return {
1816
+ rawLayer: layer,
1817
+ layer: parsedLayer
419
1818
  };
420
- const loadFragmentManager = async (id) => {
421
- setLoading(true);
422
- const fragmentDocument = await globalGraph.fetchManager.queryFragment(id);
423
- const res = globalManager == null ? void 0 : globalManager.createFragmentManager(id, fragmentDocument);
424
- setLoading(false);
425
- return res;
1819
+ };
1820
+ const useNormalizeLayer = (layerKey, manager) => {
1821
+ const { manager: fragmentManager } = useContext(FragmentContext);
1822
+ const resultManager = manager ?? fragmentManager;
1823
+ return getNormalizeLayer(layerKey, resultManager);
1824
+ };
1825
+ const useReadVariable = (variableKey) => {
1826
+ const isVariable = isVariableLink(variableKey);
1827
+ const { manager: fragmentManager } = useContext(FragmentContext);
1828
+ const { props, innerManager, layerKey } = useContext(InstanceContext);
1829
+ const resultManager = innerManager ?? fragmentManager;
1830
+ const { _id: propertyId } = (resultManager == null ? void 0 : resultManager.entityOfKey(variableKey)) ?? {};
1831
+ const [variableLayer] = y(
1832
+ isVariable ? fragmentManager : null,
1833
+ variableKey,
1834
+ {
1835
+ selector: (graph) => graph ? pick(graph, "defaultValue", "required") : graph
1836
+ }
1837
+ );
1838
+ (props == null ? void 0 : props[propertyId]) ?? null;
1839
+ (variableLayer == null ? void 0 : variableLayer.required) ?? false;
1840
+ (variableLayer == null ? void 0 : variableLayer.defaultValue) ?? null;
1841
+ const readVariable = (variableKey2) => {
1842
+ const isVariable2 = isVariableLink(variableKey2);
1843
+ if (!isVariable2) {
1844
+ return {
1845
+ value: null,
1846
+ layer: null
1847
+ };
1848
+ }
1849
+ const variableLayer2 = pick(
1850
+ (resultManager == null ? void 0 : resultManager.resolve(variableKey2)) ?? {},
1851
+ "defaultValue",
1852
+ "required"
1853
+ );
1854
+ const { _id: propertyId2 } = (resultManager == null ? void 0 : resultManager.entityOfKey(variableKey2)) ?? {};
1855
+ const currentValue2 = (props == null ? void 0 : props[propertyId2]) ?? null;
1856
+ const required2 = (variableLayer2 == null ? void 0 : variableLayer2.required) ?? false;
1857
+ const defaultValue2 = (variableLayer2 == null ? void 0 : variableLayer2.defaultValue) ?? null;
1858
+ const resultValue2 = required2 ? currentValue2 : currentValue2 ?? defaultValue2;
1859
+ return {
1860
+ value: resultValue2,
1861
+ layer: variableLayer2
1862
+ };
426
1863
  };
1864
+ const { layer, value } = readVariable(variableKey);
1865
+ return {
1866
+ value,
1867
+ layer,
1868
+ readVariable
1869
+ };
1870
+ };
1871
+ const useLayerCssVariable = (inputValue) => {
1872
+ const { manager } = useContext(FragmentContext);
1873
+ const isVariable = isVariableLink(inputValue);
1874
+ const [variableValue] = y(isVariable ? manager : null, inputValue, {
1875
+ selector: (graph) => pick(graph, "defaultValue", "_id")
1876
+ });
1877
+ return {
1878
+ value: isVariable ? `var(--${variableValue == null ? void 0 : variableValue._id}, ${variableValue == null ? void 0 : variableValue.defaultValue})` : null
1879
+ };
1880
+ };
1881
+ const useLayerValue = (layerKey, fieldKey, manager) => {
1882
+ const resultManager = manager;
1883
+ const key = layerKey;
1884
+ const [, updateLayerData] = y(resultManager, key, {
1885
+ selector: (data) => data ? pick(data, fieldKey) : data
1886
+ });
1887
+ const { layer, rawLayer } = useNormalizeLayer(key, resultManager);
1888
+ const rawValue = rawLayer == null ? void 0 : rawLayer[fieldKey];
1889
+ const layerValue = layer == null ? void 0 : layer[fieldKey];
1890
+ const { value: variableValue } = useReadVariable(layerValue);
1891
+ const currentValue = variableValue ?? layerValue;
1892
+ const isInherit = isInheritField(resultManager, key, fieldKey);
1893
+ const isOverride = !isInherit && !isPartOfPrimary(resultManager, key);
1894
+ const resetOverride = useCallback(() => {
1895
+ resultManager.mutate(
1896
+ layerKey,
1897
+ (prev) => {
1898
+ const r = omit(prev, fieldKey);
1899
+ return r;
1900
+ },
1901
+ { replace: true }
1902
+ );
1903
+ }, [updateLayerData]);
1904
+ const restore = useCallback(
1905
+ (fallbackValue) => {
1906
+ var _a, _b, _c;
1907
+ const tempValue = (_c = (_b = resultManager.resolve((_a = resultManager == null ? void 0 : resultManager.$fragment) == null ? void 0 : _a.temp)) == null ? void 0 : _b[layerKey]) == null ? void 0 : _c[fieldKey];
1908
+ updateLayerData({ [fieldKey]: tempValue ?? fallbackValue });
1909
+ },
1910
+ [updateLayerData, resultManager]
1911
+ );
1912
+ const updateValue = useCallback(
1913
+ (value, options2) => {
1914
+ var _a, _b;
1915
+ const { success, output } = parseLayerField(layer, fieldKey, value);
1916
+ if (success) {
1917
+ if (isVariableLink(value)) {
1918
+ resultManager.mutate((_a = resultManager == null ? void 0 : resultManager.$fragment) == null ? void 0 : _a.temp, {
1919
+ [layerKey]: {
1920
+ [fieldKey]: currentValue
1921
+ }
1922
+ });
1923
+ resultManager.resolve((_b = resultManager == null ? void 0 : resultManager.$fragment) == null ? void 0 : _b.temp);
1924
+ }
1925
+ updateLayerData({ [fieldKey]: output }, options2);
1926
+ }
1927
+ },
1928
+ [layer, fieldKey, updateLayerData, resultManager, layerKey, currentValue]
1929
+ );
1930
+ const { value: cssValue } = useLayerCssVariable(rawValue);
1931
+ return [
1932
+ currentValue,
1933
+ updateValue,
1934
+ {
1935
+ isOverride,
1936
+ resetOverride,
1937
+ isVariable: isVariableLink(rawValue ?? layerValue),
1938
+ cssVariableValue: cssValue ?? currentValue,
1939
+ rawValue,
1940
+ restore,
1941
+ ...resultManager.entityOfKey(key)
1942
+ }
1943
+ ];
1944
+ };
1945
+ const autoSizes = [index.sizing.Hug];
1946
+ const useLayerSizeValue = (layerKey, sizeType) => {
1947
+ const { manager: fragmentManager } = useContext(FragmentContext);
1948
+ const { layerKey: instanceLayerKey } = useContext(InstanceContext);
1949
+ const { isDocument } = useRenderTarget();
1950
+ const isTop = isTopLevel(fragmentManager, layerKey);
1951
+ const isPartOfInstance = !!instanceLayerKey;
1952
+ const layerParent = getParent(fragmentManager, layerKey);
1953
+ const layerNode = fragmentManager.resolve(layerKey);
1954
+ const [instanceType] = useLayerValue(
1955
+ instanceLayerKey,
1956
+ `${sizeType}Type`,
1957
+ fragmentManager
1958
+ );
1959
+ const [valueType] = useLayerValue(
1960
+ layerKey,
1961
+ `${sizeType}Type`,
1962
+ fragmentManager
1963
+ );
1964
+ const growType = sizeType === "width" ? "horizontalGrow" : "verticalGrow";
1965
+ return useCallback(
1966
+ (value) => {
1967
+ if (isTop && isDocument && (layerParent == null ? void 0 : layerParent[growType]) === index.fragmentGrowingMode.fill) {
1968
+ return "100%";
1969
+ }
1970
+ if (isTop && isPartOfInstance && !autoSizes.includes(instanceType)) {
1971
+ return "100%";
1972
+ }
1973
+ if (autoSizes.includes(valueType)) {
1974
+ return layerNode._type === index.nodes.Instance ? "auto" : "min-content";
1975
+ }
1976
+ if (valueType === index.sizing.Relative) {
1977
+ return `${value}%`;
1978
+ }
1979
+ if (valueType === index.sizing.Fill) {
1980
+ return `100%`;
1981
+ }
1982
+ return toPx(value);
1983
+ },
1984
+ [
1985
+ isTop,
1986
+ isDocument,
1987
+ layerParent,
1988
+ growType,
1989
+ isPartOfInstance,
1990
+ instanceType,
1991
+ valueType,
1992
+ layerNode
1993
+ ]
1994
+ );
1995
+ };
1996
+ const processOptionalSize = (value, type) => {
1997
+ if (value === -1) return "";
1998
+ if (type === index.sizing.Fixed) return toPx(value);
1999
+ if (type === index.sizing.Relative) return `${value}%`;
2000
+ return "";
2001
+ };
2002
+ const useOptionalSize = (type, layerKey) => {
2003
+ const { manager: fragmentManager } = useContext(FragmentContext);
2004
+ const [value] = useLayerValue(layerKey, type, fragmentManager);
2005
+ const [valueType] = useLayerValue(layerKey, `${type}Type`, fragmentManager);
2006
+ return useMemo(
2007
+ () => processOptionalSize(value, valueType),
2008
+ [valueType, value]
2009
+ );
2010
+ };
2011
+ const useLayerSize = (layerKey) => {
2012
+ const { manager } = useContext(FragmentContext);
2013
+ const [widthValue] = useLayerValue(layerKey, "width", manager);
2014
+ const [heightValue] = useLayerValue(layerKey, "height", manager);
2015
+ const widthCalc = useLayerSizeValue(layerKey, "width");
2016
+ const heightCalc = useLayerSizeValue(layerKey, "height");
2017
+ const minWidth = useOptionalSize("minWidth", layerKey);
2018
+ const minHeight = useOptionalSize("minHeight", layerKey);
2019
+ const maxWidth = useOptionalSize("maxWidth", layerKey);
2020
+ const maxHeight = useOptionalSize("maxHeight", layerKey);
2021
+ return {
2022
+ width: widthCalc(widthValue),
2023
+ height: heightCalc(heightValue),
2024
+ minWidth,
2025
+ minHeight,
2026
+ maxWidth,
2027
+ maxHeight
2028
+ };
2029
+ };
2030
+ const useLayerPosition = (layerKey) => {
2031
+ const { layerKey: instanceLayerKey } = useContext(InstanceContext);
2032
+ const { manager: fragmentManager } = useContext(FragmentContext);
2033
+ const { isDocument } = useRenderTarget();
2034
+ const isTop = isTopLevel(fragmentManager, layerKey);
2035
+ const skipPosition = isTop && isDocument || !!instanceLayerKey && isTop;
2036
+ const [position] = useLayerValue(layerKey, "position", fragmentManager);
2037
+ const [top] = useLayerValue(layerKey, "top", fragmentManager);
2038
+ const [left] = useLayerValue(layerKey, "left", fragmentManager);
2039
+ return useMemo(
2040
+ () => ({
2041
+ position: skipPosition ? index.positionType.relative : position,
2042
+ top: position === index.positionType.absolute && !skipPosition ? toPx(top) : null,
2043
+ left: position === index.positionType.absolute && !skipPosition ? toPx(left) : null
2044
+ }),
2045
+ [skipPosition, position, top]
2046
+ );
2047
+ };
2048
+ const useLayerBackground = (layerKey) => {
2049
+ const { manager: fragmentManager } = useContext(FragmentContext);
2050
+ const [fillType] = useLayerValue(layerKey, "fillType", fragmentManager);
2051
+ const [, , { cssVariableValue: cssSolidFill }] = useLayerValue(
2052
+ layerKey,
2053
+ "solidFill",
2054
+ fragmentManager
2055
+ );
2056
+ const [, , { cssVariableValue: cssImageFill }] = useLayerValue(
2057
+ layerKey,
2058
+ "imageFill",
2059
+ fragmentManager
2060
+ );
2061
+ const [, , { cssVariableValue: cssImageSize }] = useLayerValue(
2062
+ layerKey,
2063
+ "imageSize",
2064
+ fragmentManager
2065
+ );
2066
+ return useMemo(() => {
2067
+ if (fillType === index.paintMode.Solid) {
2068
+ return {
2069
+ background: cssSolidFill
2070
+ };
2071
+ }
2072
+ if (fillType === index.paintMode.Image && cssImageFill) {
2073
+ const sizeMap = {
2074
+ [index.imagePaintScaleModes.Fill]: "cover",
2075
+ [index.imagePaintScaleModes.Fit]: "contain"
2076
+ };
2077
+ return {
2078
+ background: `url(${cssImageFill})`,
2079
+ backgroundSize: sizeMap[cssImageSize]
2080
+ };
2081
+ }
2082
+ return {
2083
+ background: "transparent"
2084
+ };
2085
+ }, [fillType, cssImageFill, cssSolidFill]);
2086
+ };
2087
+ const useLayerDisplay = (layerKey) => {
2088
+ const { manager } = useContext(FragmentContext);
2089
+ const [layerModeValue] = useLayerValue(layerKey, "layerMode", manager);
2090
+ const [visible] = useLayerValue(layerKey, "visible", manager);
2091
+ return useMemo(() => {
2092
+ if (!visible) {
2093
+ return "none";
2094
+ }
2095
+ return layerModeValue === index.layerMode.flex ? "flex" : null;
2096
+ }, [layerModeValue, visible]);
2097
+ };
2098
+ const useCalcLayerBorder = (layerKey) => {
2099
+ const { manager: fragmentManager } = useContext(FragmentContext);
2100
+ const [borderTypeValue] = useLayerValue(
2101
+ layerKey,
2102
+ "borderType",
2103
+ fragmentManager
2104
+ );
2105
+ return (width, color) => {
2106
+ let value = "";
2107
+ if (typeof borderTypeValue === "string" && borderTypeValue !== index.borderType.None) {
2108
+ value = `${toPx(width)} ${borderTypeValue.toLowerCase()} ${color}`;
2109
+ }
2110
+ return value;
2111
+ };
2112
+ };
2113
+ const useLayerBorder = (layerKey) => {
2114
+ const { manager: fragmentManager } = useContext(FragmentContext);
2115
+ const [borderWidth] = useLayerValue(layerKey, "borderWidth", fragmentManager);
2116
+ const [borderColor] = useLayerValue(layerKey, "borderColor", fragmentManager);
2117
+ const calcBorder = useCalcLayerBorder(layerKey);
2118
+ return useMemo(
2119
+ () => ({ border: calcBorder(borderWidth, borderColor) }),
2120
+ [borderWidth, borderColor]
2121
+ );
2122
+ };
2123
+ const useLayerLayout = (layerKey) => {
2124
+ const { manager: fragmentManager } = useContext(FragmentContext);
2125
+ const [layerModeValue] = useLayerValue(
2126
+ layerKey,
2127
+ "layerMode",
2128
+ fragmentManager
2129
+ );
2130
+ const [layerWrap] = useLayerValue(layerKey, "layerWrap", fragmentManager);
2131
+ const [layerDistribute2] = useLayerValue(
2132
+ layerKey,
2133
+ "layerDistribute",
2134
+ fragmentManager
2135
+ );
2136
+ const [layerDirectionValue] = useLayerValue(
2137
+ layerKey,
2138
+ "layerDirection",
2139
+ fragmentManager
2140
+ );
2141
+ const [layerAlign2] = useLayerValue(layerKey, "layerAlign", fragmentManager);
2142
+ const [padding] = useLayerValue(layerKey, "padding", fragmentManager);
2143
+ const [gap] = useLayerValue(layerKey, "layerGap", fragmentManager);
2144
+ const isFlex = layerModeValue === index.layerMode.flex;
2145
+ return useMemo(
2146
+ () => ({
2147
+ display: isFlex ? "flex" : null,
2148
+ gap: toPx(gap),
2149
+ flexWrap: isFlex ? layerWrap ? "wrap" : null : null,
2150
+ justifyContent: isFlex ? layerDistribute2 : null,
2151
+ flexDirection: isFlex ? layerDirectionValue === index.layerDirection.vertical ? "column" : "row" : null,
2152
+ alignItems: isFlex ? layerAlign2 : null,
2153
+ padding: isFlex ? padding : null
2154
+ }),
2155
+ [
2156
+ isFlex,
2157
+ layerWrap,
2158
+ layerDistribute2,
2159
+ layerDirectionValue,
2160
+ layerAlign2,
2161
+ padding
2162
+ ]
2163
+ );
2164
+ };
2165
+ const useLayerStyles = (layerKey) => {
2166
+ var _a;
2167
+ try {
2168
+ if (!layerKey) {
2169
+ throw new Error("Empty layer key");
2170
+ }
2171
+ const { manager: fragmentManager } = useContext(FragmentContext);
2172
+ const [opacity] = useLayerValue(layerKey, "opacity", fragmentManager);
2173
+ const layerSize = useLayerSize(layerKey);
2174
+ const { position, top, left } = useLayerPosition(layerKey);
2175
+ const display = useLayerDisplay(layerKey);
2176
+ const background = useLayerBackground(layerKey);
2177
+ const { border } = useLayerBorder(layerKey);
2178
+ const layout = useLayerLayout(layerKey);
2179
+ const [zIndex] = useLayerValue(layerKey, "zIndex", fragmentManager);
2180
+ const [borderRadius] = useLayerValue(
2181
+ layerKey,
2182
+ "borderRadius",
2183
+ fragmentManager
2184
+ );
2185
+ const [whiteSpace2] = useLayerValue(layerKey, "whiteSpace", fragmentManager);
2186
+ let props = {};
2187
+ const { _type } = fragmentManager.entityOfKey(layerKey) ?? {};
2188
+ if (_type === index.nodes.Instance) {
2189
+ const instanceProps = omit(
2190
+ (_a = fragmentManager == null ? void 0 : fragmentManager.resolve(layerKey)) == null ? void 0 : _a.props,
2191
+ "_id",
2192
+ "_type"
2193
+ );
2194
+ props = Object.entries(instanceProps).reduce((acc, [key, value]) => {
2195
+ acc[`--${key}`] = value;
2196
+ return acc;
2197
+ }, {});
2198
+ }
2199
+ return {
2200
+ ...props ?? {},
2201
+ display,
2202
+ border,
2203
+ ...background,
2204
+ position,
2205
+ top,
2206
+ left,
2207
+ opacity,
2208
+ "border-radius": borderRadius,
2209
+ "white-space": whiteSpace2,
2210
+ "z-index": zIndex !== -1 ? zIndex : null,
2211
+ ...layout,
2212
+ ...layerSize,
2213
+ "user-select": "none"
2214
+ };
2215
+ } catch (e) {
2216
+ console.debug(e);
2217
+ return {};
2218
+ }
2219
+ };
2220
+ const GlobalManager$1 = createContext(null);
2221
+ const useGlobalManager = (globalManager) => {
2222
+ var _a, _b;
2223
+ const currentGlobalManager = useContext(GlobalManager$1);
2224
+ const resultManager = globalManager ?? currentGlobalManager;
2225
+ const [fragmentsGraph] = y(
2226
+ resultManager,
2227
+ (_a = resultManager == null ? void 0 : resultManager.$fragments) == null ? void 0 : _a.key
2228
+ );
2229
+ const queryFragmentManager = async (id) => {
2230
+ var _a2;
2231
+ const queryResult = await ((_a2 = resultManager == null ? void 0 : resultManager.$fetch) == null ? void 0 : _a2.queryFragment(id));
2232
+ const { document: document2, linkedFragments } = queryResult ?? {};
2233
+ if (linkedFragments) {
2234
+ linkedFragments.forEach(({ id: id2, document: document22 }) => {
2235
+ resultManager.$fragments.createFragmentManager(id2, document22);
2236
+ });
2237
+ }
2238
+ return resultManager.$fragments.createFragmentManager(id, document2);
2239
+ };
2240
+ const setRenderTarget = (value) => {
2241
+ resultManager == null ? void 0 : resultManager.setRenderTarget(value);
2242
+ };
2243
+ return {
2244
+ fragmentsGraph,
2245
+ manager: resultManager,
2246
+ queryFragmentManager,
2247
+ getFragmentManager: ((_b = resultManager == null ? void 0 : resultManager.$fragments) == null ? void 0 : _b.getManager) ?? noop,
2248
+ setRenderTarget
2249
+ };
2250
+ };
2251
+ const useFragmentManager = (fragmentId, inputGlobalManager) => {
2252
+ const {
2253
+ fragmentsGraph,
2254
+ manager: globalManager,
2255
+ getFragmentManager,
2256
+ queryFragmentManager
2257
+ } = useGlobalManager(inputGlobalManager);
2258
+ const [loading, setLoading] = useState(false);
427
2259
  useEffect(() => {
428
- loadFragmentManager(fragmentId);
429
- }, [fragmentId]);
2260
+ (async () => {
2261
+ if (fragmentsGraph && !getFragmentManager(fragmentId)) {
2262
+ setLoading(true);
2263
+ await queryFragmentManager(fragmentId);
2264
+ setLoading(false);
2265
+ }
2266
+ })();
2267
+ }, [fragmentId, fragmentsGraph]);
430
2268
  return {
431
2269
  loading,
432
- manager: getFragmentManager(fragmentId)
2270
+ manager: getFragmentManager(fragmentId),
2271
+ queryFragmentManager
2272
+ // loadFragmentManager,
433
2273
  };
434
2274
  };
435
2275
  const useFragmentProperties = (fragmentId) => {
436
2276
  var _a;
437
2277
  const { manager } = useFragmentManager(fragmentId);
438
2278
  const [instanceFragment] = y(manager, (_a = manager == null ? void 0 : manager.$fragment) == null ? void 0 : _a.root);
439
- return (instanceFragment == null ? void 0 : instanceFragment.properties) ?? [];
2279
+ return {
2280
+ properties: (instanceFragment == null ? void 0 : instanceFragment.properties) ?? [],
2281
+ manager
2282
+ };
440
2283
  };
441
- const useRenderTarget = () => {
442
- const globalManager = useGlobalManager();
443
- const [globalManagerGraph] = y(globalManager, globalManager == null ? void 0 : globalManager.key);
444
- const renderTargetValue = (globalManagerGraph == null ? void 0 : globalManagerGraph.renderTarget) ?? definition.renderTarget.canvas;
2284
+ const useHash = (layerKey) => {
2285
+ const { manager } = useContext(FragmentContext);
2286
+ if (!layerKey || !manager) return null;
2287
+ const layer = manager.resolve(layerKey);
2288
+ const overrideFrom = getKey(layer == null ? void 0 : layer.overrideFrom);
2289
+ return hashGenerator(overrideFrom ?? layerKey);
2290
+ };
2291
+ const useInstance = (instanceProps) => {
2292
+ const { manager: parentManager } = useContext(FragmentContext);
2293
+ const [instanceLayer] = y(parentManager, instanceProps.layerKey);
2294
+ const instanceLayerProps = (instanceLayer == null ? void 0 : instanceLayer.props) ?? {};
2295
+ const styles2 = useLayerStyles(instanceProps.layerKey);
2296
+ const { manager: resultGlobalManager } = useGlobalManager(
2297
+ instanceProps == null ? void 0 : instanceProps.globalManager
2298
+ );
2299
+ const resultProps = { ...instanceLayerProps, ...instanceProps.props ?? {} };
2300
+ const resultFragmentId = (instanceProps == null ? void 0 : instanceProps.fragmentId) ?? (instanceLayer == null ? void 0 : instanceLayer.fragment);
2301
+ const { properties: definitions, manager: innerFragmentManager } = useFragmentProperties(resultFragmentId);
2302
+ const hash = useHash(instanceProps.layerKey);
445
2303
  return {
446
- renderTarget: renderTargetValue,
447
- isCanvas: renderTargetValue === definition.renderTarget.canvas,
448
- isDocument: renderTargetValue === definition.renderTarget.document,
449
- setRenderTarget: (target) => {
450
- globalManager == null ? void 0 : globalManager.setRenderTarget(target);
2304
+ hash,
2305
+ styles: styles2,
2306
+ definitions,
2307
+ props: resultProps,
2308
+ parentManager,
2309
+ innerManager: innerFragmentManager,
2310
+ fragmentId: resultFragmentId,
2311
+ globalManager: resultGlobalManager
2312
+ };
2313
+ };
2314
+ const InstanceContext = createContext({
2315
+ layerKey: null,
2316
+ parentManager: null,
2317
+ innerManager: null,
2318
+ props: {},
2319
+ definitions: []
2320
+ });
2321
+ const useLayerChildren = (layerKey, customManager) => {
2322
+ const { manager: fragmentManager } = useContext(FragmentContext);
2323
+ const [layerData] = y(customManager ?? fragmentManager, layerKey, {
2324
+ selector: (data) => pick(data, "children")
2325
+ });
2326
+ return (layerData == null ? void 0 : layerData.children) ?? [];
2327
+ };
2328
+ const useFragmentChildren = (fragmentId) => {
2329
+ const { layerKey: instanceLayerKey } = useContext(InstanceContext);
2330
+ const { manager } = useFragmentManager(fragmentId);
2331
+ const layerKey = `${index.nodes.Fragment}:${fragmentId}`;
2332
+ const children = useLayerChildren(layerKey, manager);
2333
+ const { isDocument } = useRenderTarget();
2334
+ const [resizeChildren, setResizeChildren] = useState(null);
2335
+ useRef();
2336
+ const setRef = useCallback(
2337
+ (node) => {
2338
+ },
2339
+ [isDocument, instanceLayerKey, manager, children]
2340
+ );
2341
+ const primary = children == null ? void 0 : children.find(
2342
+ (breakpoint) => {
2343
+ var _a;
2344
+ return (_a = manager.resolve(breakpoint)) == null ? void 0 : _a.isPrimary;
2345
+ }
2346
+ );
2347
+ return {
2348
+ primary,
2349
+ children,
2350
+ //isBrowser && resizeChildren ? resizeChildren : children, //isStyleSheetRender ? children ?? [] : primary ? [primary] : [],
2351
+ isResize: isBrowser_default && resizeChildren,
2352
+ setRef
2353
+ };
2354
+ };
2355
+ const getStylesheetKey = (fragmentKey) => {
2356
+ const isLink2 = isLinkKey(fragmentKey);
2357
+ if (isLink2) {
2358
+ const [type, id] = fragmentKey.split(":");
2359
+ return `stylesheet-${id}`;
2360
+ }
2361
+ return `stylesheet-unknown`;
2362
+ };
2363
+ function useInjectedStyle() {
2364
+ const { manager } = useContext(FragmentContext);
2365
+ const injectStyle = () => {
2366
+ var _a, _b;
2367
+ const styles2 = (_b = (_a = manager == null ? void 0 : manager.$styleSheet.extract()) == null ? void 0 : _a.at(0)) == null ? void 0 : _b.styles;
2368
+ if (isBrowser_default && styles2) {
2369
+ const stylesheetKey = getStylesheetKey(manager == null ? void 0 : manager.key);
2370
+ if (document.getElementById(stylesheetKey)) {
2371
+ const el = document.getElementById(stylesheetKey);
2372
+ if (el) el.remove();
2373
+ }
2374
+ const style = document.createElement("style");
2375
+ style.id = stylesheetKey;
2376
+ style.textContent = styles2.join("");
2377
+ document.head.appendChild(style);
451
2378
  }
452
2379
  };
2380
+ return {
2381
+ injectStyle
2382
+ };
2383
+ }
2384
+ const useStyleSheet = () => {
2385
+ const { manager } = useContext(FragmentContext);
2386
+ const { injectStyle } = useInjectedStyle();
2387
+ const addLayerStyle = useCallback(
2388
+ (layerKey, styles2, layer) => {
2389
+ var _a;
2390
+ if ("addStyle" in (manager == null ? void 0 : manager.$styleSheet)) {
2391
+ (_a = manager == null ? void 0 : manager.$styleSheet) == null ? void 0 : _a.addStyle(layerKey, styles2, layer);
2392
+ if (isBrowser_default) {
2393
+ injectStyle();
2394
+ }
2395
+ }
2396
+ },
2397
+ [manager]
2398
+ );
2399
+ return {
2400
+ addLayerStyle
2401
+ };
2402
+ };
2403
+ const useFragment = (fragmentId, globalManager) => {
2404
+ const layerKey = `${index.nodes.Fragment}:${fragmentId}`;
2405
+ const { manager } = useContext(FragmentContext);
2406
+ const { isDocument } = useRenderTarget();
2407
+ const { setRef, children, isResize } = useFragmentChildren(fragmentId);
2408
+ const hash = useHash(layerKey);
2409
+ const { addLayerStyle } = useStyleSheet();
2410
+ if (manager) {
2411
+ addLayerStyle(
2412
+ layerKey,
2413
+ {
2414
+ width: "100%",
2415
+ height: "100%",
2416
+ "container-type": (children == null ? void 0 : children.length) === 1 ? "normal" : "inline-size"
2417
+ },
2418
+ manager == null ? void 0 : manager.resolve(layerKey),
2419
+ manager == null ? void 0 : manager.key
2420
+ );
2421
+ }
2422
+ return {
2423
+ hash,
2424
+ isDocument,
2425
+ manager,
2426
+ setRef,
2427
+ children,
2428
+ isResize
2429
+ };
2430
+ };
2431
+ const useLayerInteractions = (layerKey) => {
2432
+ const { manager: globalManager } = useGlobalManager();
2433
+ const { manager: fragmentManager } = useContext(FragmentContext);
2434
+ const [interactions2] = useLayerValue(
2435
+ layerKey,
2436
+ "interactions",
2437
+ fragmentManager
2438
+ );
2439
+ const { readVariable } = useReadVariable();
2440
+ const fireEvent = useCallback(
2441
+ (eventLink) => {
2442
+ var _a, _b;
2443
+ const event = fragmentManager.resolve(eventLink);
2444
+ const { value: eventValue } = readVariable(eventLink);
2445
+ if ((event == null ? void 0 : event.mode) === index.eventMode.goal) {
2446
+ (_b = (_a = globalManager == null ? void 0 : globalManager.$metrics) == null ? void 0 : _a.reachGoal) == null ? void 0 : _b.call(_a, eventValue == null ? void 0 : eventValue.code);
2447
+ }
2448
+ },
2449
+ [globalManager, fragmentManager]
2450
+ );
2451
+ return useMemo(() => {
2452
+ if (!interactions2 || !Array.isArray(interactions2)) return {};
2453
+ const clickEvents = interactions2 == null ? void 0 : interactions2.filter((el) => (el == null ? void 0 : el.on) === index.interactions.click).map((el) => el.event);
2454
+ return {
2455
+ onClick: () => {
2456
+ clickEvents.map(fireEvent);
2457
+ }
2458
+ };
2459
+ }, [interactions2, fireEvent]);
2460
+ };
2461
+ const useFrame = (layerKey) => {
2462
+ const { manager: fragmentManager } = useContext(FragmentContext);
2463
+ const layer = fragmentManager.entityOfKey(layerKey);
2464
+ const styles2 = useLayerStyles(layerKey);
2465
+ const children = useLayerChildren(layerKey);
2466
+ const hash = useHash(layerKey);
2467
+ const { addLayerStyle } = useStyleSheet();
2468
+ const events = useLayerInteractions(layerKey);
2469
+ addLayerStyle(layerKey, styles2, fragmentManager.resolve(layerKey));
2470
+ return {
2471
+ type: layer == null ? void 0 : layer._type,
2472
+ hash,
2473
+ styles: {},
2474
+ //isBrowser ? pick(styles, "background") : {},
2475
+ children,
2476
+ events
2477
+ };
2478
+ };
2479
+ const allowAttributes = [
2480
+ "fontSize",
2481
+ "fontWeight",
2482
+ "color",
2483
+ "lineHeight",
2484
+ "letterSpacing",
2485
+ "textTransform",
2486
+ "textDecoration",
2487
+ "textAlign"
2488
+ ];
2489
+ const wrapTextInParagraphWithAttributes = (text2, attributes) => {
2490
+ if (text2.startsWith("<p")) return text2;
2491
+ const style = Object.entries(attributes).filter(
2492
+ ([key, value]) => isValue(value) && allowAttributes.includes(key) && typeof value === "string" && !!value.length
2493
+ ).map(([key, value]) => `${toKebabCase(key)}: ${value}`).join("; ");
2494
+ return `<p style="${style}">${text2}</p>`;
2495
+ };
2496
+ const useTextContent = (layerKey, manager) => {
2497
+ const { manager: fragmentManager } = useContext(FragmentContext);
2498
+ const [content, , contentInfo] = useLayerValue(
2499
+ layerKey,
2500
+ "content",
2501
+ fragmentManager
2502
+ );
2503
+ const [attributes] = useLayerValue(layerKey, "attributes", fragmentManager);
2504
+ return useMemo(() => {
2505
+ if (typeof content === "string" && isValue(attributes)) {
2506
+ return wrapTextInParagraphWithAttributes(content, attributes);
2507
+ }
2508
+ return content;
2509
+ }, [contentInfo, content, attributes]);
2510
+ };
2511
+ const useTextAttributes = (layerKey) => {
2512
+ const { manager: fragmentManager } = useContext(FragmentContext);
2513
+ const styles2 = useLayerStyles(layerKey);
2514
+ const content = useTextContent(layerKey);
2515
+ const hash = useHash(layerKey);
2516
+ const { addLayerStyle } = useStyleSheet();
2517
+ addLayerStyle(layerKey, styles2, fragmentManager.resolve(layerKey));
2518
+ return {
2519
+ hash,
2520
+ content
2521
+ };
2522
+ };
2523
+ function useMounted() {
2524
+ const [isMounted, setIsMounted] = useState(false);
2525
+ useEffect(() => {
2526
+ setIsMounted(true);
2527
+ return () => {
2528
+ setIsMounted(false);
2529
+ };
2530
+ }, []);
2531
+ return isMounted;
2532
+ }
2533
+ const StyleSheetContext = createContext(null);
2534
+ StyleSheetContext.Provider;
2535
+ const Text = ({ layerKey }) => {
2536
+ const { hash, content } = useTextAttributes(layerKey);
2537
+ return /* @__PURE__ */ jsx("div", { className: hash, "data-key": layerKey, children: /* @__PURE__ */ jsx("div", { dangerouslySetInnerHTML: { __html: content } }) });
2538
+ };
2539
+ const Frame = ({ layerKey, hidden }) => {
2540
+ const { styles, hash, children, type, events } = useFrame(layerKey);
2541
+ const isMounted = useMounted();
2542
+ if (isMounted && hidden) {
2543
+ return null;
2544
+ }
2545
+ if (type === definition.nodes.Text) {
2546
+ return /* @__PURE__ */ jsx(Text, { layerKey });
2547
+ }
2548
+ if (type === definition.nodes.Instance) {
2549
+ return /* @__PURE__ */ jsx(Instance, { layerKey });
2550
+ }
2551
+ return /* @__PURE__ */ jsx(
2552
+ "div",
2553
+ {
2554
+ className: hash,
2555
+ "data-key": layerKey,
2556
+ style: { ...styles, display: hidden ? "none" : styles.display },
2557
+ ...events,
2558
+ children: children.map((childLink) => /* @__PURE__ */ jsx(Frame, { layerKey: childLink }, childLink))
2559
+ }
2560
+ );
2561
+ };
2562
+ const FragmentInternal = ({ fragmentId, globalManager }) => {
2563
+ const { children, manager, hash, isResize } = useFragment(
2564
+ fragmentId
2565
+ );
2566
+ if (!manager) return null;
2567
+ return /* @__PURE__ */ jsx(
2568
+ "div",
2569
+ {
2570
+ "data-key": `${definition.nodes.Fragment}:${fragmentId}`,
2571
+ className: hash,
2572
+ children: children.map((childLink) => {
2573
+ const childLayer = manager == null ? void 0 : manager.resolve(childLink);
2574
+ const isPrimary = (childLayer == null ? void 0 : childLayer.isPrimary) ?? false;
2575
+ return /* @__PURE__ */ jsx(
2576
+ Frame,
2577
+ {
2578
+ layerKey: childLink,
2579
+ hidden: !isResize && !isPrimary
2580
+ },
2581
+ childLink
2582
+ );
2583
+ })
2584
+ }
2585
+ );
2586
+ };
2587
+ const Fragment = (props) => {
2588
+ const { manager: resultGlobalManager } = useGlobalManager();
2589
+ const { manager } = useFragmentManager(props.fragmentId, resultGlobalManager);
2590
+ return /* @__PURE__ */ jsx(FragmentContext.Provider, { value: { manager }, children: /* @__PURE__ */ jsx(FragmentInternal, { ...props }) });
2591
+ };
2592
+ const isBrowser = typeof window !== "undefined";
2593
+ const loadFragmentManager = async (globalManager, fragmentId) => {
2594
+ var _a;
2595
+ const { document: document2, linkedFragments } = await ((_a = globalManager == null ? void 0 : globalManager.queryFragment) == null ? void 0 : _a.call(
2596
+ globalManager,
2597
+ fragmentId
2598
+ ));
2599
+ if (fragmentId && document2) {
2600
+ if (linkedFragments) {
2601
+ linkedFragments.forEach(({ id, document: document22 }) => {
2602
+ globalManager == null ? void 0 : globalManager.createFragmentManager(id, document22);
2603
+ });
2604
+ }
2605
+ return globalManager == null ? void 0 : globalManager.createFragmentManager(fragmentId, document2);
2606
+ }
2607
+ return null;
2608
+ };
2609
+ function createResource(resourceCache, key, fetcher) {
2610
+ if (resourceCache.has(key)) return resourceCache.get(key);
2611
+ let status = "pending";
2612
+ let result;
2613
+ const suspender = fetcher().then(
2614
+ (r) => {
2615
+ status = "success";
2616
+ result = r;
2617
+ },
2618
+ (e) => {
2619
+ status = "error";
2620
+ result = e;
2621
+ }
2622
+ );
2623
+ const resource = {
2624
+ read() {
2625
+ if (status === "pending") throw suspender;
2626
+ if (status === "error") throw result;
2627
+ return result;
2628
+ }
2629
+ };
2630
+ resourceCache.set(key, resource);
2631
+ return resource;
2632
+ }
2633
+ const InstanceInitial = (instanceProps) => {
2634
+ const {
2635
+ fragmentId,
2636
+ parentManager,
2637
+ props,
2638
+ hash,
2639
+ innerManager,
2640
+ definitions,
2641
+ globalManager
2642
+ } = useInstance(instanceProps);
2643
+ if (!isBrowser) {
2644
+ if (globalManager && !("resourceCache" in globalManager)) {
2645
+ globalManager.resourceCache = /* @__PURE__ */ new Map();
2646
+ }
2647
+ const resource = createResource(
2648
+ globalManager.resourceCache,
2649
+ fragmentId,
2650
+ () => loadFragmentManager(globalManager, fragmentId)
2651
+ );
2652
+ resource.read();
2653
+ }
2654
+ return /* @__PURE__ */ jsx(
2655
+ InstanceContext.Provider,
2656
+ {
2657
+ value: {
2658
+ layerKey: instanceProps.layerKey,
2659
+ definitions,
2660
+ innerManager,
2661
+ parentManager,
2662
+ props
2663
+ },
2664
+ children: parentManager ? /* @__PURE__ */ jsx("div", { className: hash, "data-key": instanceProps.layerKey, children: /* @__PURE__ */ jsx(Fragment, { fragmentId, globalManager }) }) : /* @__PURE__ */ jsx(Fragment, { fragmentId, globalManager })
2665
+ }
2666
+ );
2667
+ };
2668
+ const Instance = (props) => {
2669
+ return "globalManager" in props ? /* @__PURE__ */ jsx(GlobalManager$1, { value: props.globalManager, children: /* @__PURE__ */ jsx(InstanceInitial, { ...props }) }) : /* @__PURE__ */ jsx(InstanceInitial, { ...props });
2670
+ };
2671
+ const GlobalManager = ({ children, value }) => {
2672
+ return /* @__PURE__ */ jsx(GlobalManager$1, { value, children });
453
2673
  };
454
- const Fragment = createReactComponent(Fragment$1);
455
- const Instance = createReactComponent(Instance$1);
456
2674
  export {
457
- Fragment,
458
2675
  GlobalManager,
459
2676
  Instance,
460
- useFragmentManager,
461
- useFragmentProperties,
462
- useGlobalManager,
463
- useRenderTarget
2677
+ collectStyles,
2678
+ useGlobalManager
464
2679
  };