@fragmentsx/definition 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1135 @@
1
+ const createConstants = (...constants) => {
2
+ return constants.reduce((acc, constant) => {
3
+ acc[constant] = constant;
4
+ return acc;
5
+ }, {});
6
+ };
7
+ const nodes = createConstants(
8
+ "Fragment",
9
+ "FragmentInstance",
10
+ "Instance",
11
+ "Breakpoint",
12
+ "Frame",
13
+ "Image",
14
+ "Text",
15
+ "SolidPaintStyle",
16
+ "CssLink",
17
+ "Variable",
18
+ "ComputedValue",
19
+ "TransformValue"
20
+ );
21
+ const fragmentGrowingMode = createConstants("auto", "fill");
22
+ const borderType = createConstants("None", "Solid", "Dashed", "Dotted");
23
+ const linkTarget = createConstants("_blank");
24
+ const paintMode = createConstants("None", "Solid", "Image");
25
+ const imagePaintScaleModes = createConstants(
26
+ "Fill",
27
+ "Fit",
28
+ "Crop",
29
+ "Tile"
30
+ );
31
+ const constrain = createConstants(
32
+ "Min",
33
+ "Center",
34
+ "Max",
35
+ "Stretch",
36
+ "Scale"
37
+ );
38
+ const positionType = createConstants("absolute", "relative");
39
+ const sizing = createConstants("Fixed", "Hug", "Fill", "Relative");
40
+ const layerMode = createConstants("none", "flex");
41
+ const layerDirection = createConstants("vertical", "horizontal");
42
+ const layerAlign = createConstants("start", "center", "end");
43
+ const layerDistribute = createConstants(
44
+ "start",
45
+ "center",
46
+ "end",
47
+ "space-between",
48
+ "space-around"
49
+ );
50
+ const textTransform = createConstants(
51
+ "none",
52
+ "uppercase",
53
+ "lowercase",
54
+ "capitalize"
55
+ );
56
+ const textDecorations = createConstants(
57
+ "none",
58
+ "underline",
59
+ "line-through"
60
+ );
61
+ const effectType = createConstants("loop", "appear", "hover", "tap");
62
+ const effectName = createConstants(
63
+ "fade",
64
+ "slide",
65
+ "bounce",
66
+ "wiggle",
67
+ "increase"
68
+ );
69
+ const variableType = createConstants(
70
+ "String",
71
+ "Boolean",
72
+ "Array",
73
+ "Color",
74
+ "ComponentInstance",
75
+ "Date",
76
+ "Enum",
77
+ "Number",
78
+ "Object"
79
+ );
80
+ const whiteSpace = createConstants(
81
+ "normal",
82
+ "nowrap",
83
+ "pre",
84
+ "pre-wrap",
85
+ "pre-line",
86
+ "break-spaces"
87
+ );
88
+ const overflow = createConstants("visible", "hidden", "scroll");
89
+ const variableTransforms = createConstants(
90
+ "convert",
91
+ "exists",
92
+ "equals",
93
+ "startWith",
94
+ "endWith",
95
+ "contains",
96
+ "dateBefore",
97
+ "dateAfter",
98
+ "dateBetween",
99
+ "feature",
100
+ "notFeature",
101
+ "gt",
102
+ // Greater than
103
+ "gte",
104
+ // Greater than or equals
105
+ "lt",
106
+ // Less than
107
+ "lte",
108
+ // Less than or equals,
109
+ "convertFromBoolean",
110
+ "negative"
111
+ );
112
+ const renderTarget = createConstants("canvas", "document");
113
+ const renderMode = createConstants("viewport", "parent", "fixed");
114
+ const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
115
+ __proto__: null,
116
+ borderType,
117
+ constrain,
118
+ createConstants,
119
+ effectName,
120
+ effectType,
121
+ fragmentGrowingMode,
122
+ imagePaintScaleModes,
123
+ layerAlign,
124
+ layerDirection,
125
+ layerDistribute,
126
+ layerMode,
127
+ linkTarget,
128
+ nodes,
129
+ overflow,
130
+ paintMode,
131
+ positionType,
132
+ renderMode,
133
+ renderTarget,
134
+ sizing,
135
+ textDecorations,
136
+ textTransform,
137
+ variableTransforms,
138
+ variableType,
139
+ whiteSpace
140
+ }, Symbol.toStringTag, { value: "Module" }));
141
+ var store;
142
+ // @__NO_SIDE_EFFECTS__
143
+ function getGlobalConfig(config2) {
144
+ return {
145
+ lang: (config2 == null ? void 0 : config2.lang) ?? (store == null ? void 0 : store.lang),
146
+ message: config2 == null ? void 0 : config2.message,
147
+ abortEarly: (config2 == null ? void 0 : config2.abortEarly) ?? (store == null ? void 0 : store.abortEarly),
148
+ abortPipeEarly: (config2 == null ? void 0 : config2.abortPipeEarly) ?? (store == null ? void 0 : store.abortPipeEarly)
149
+ };
150
+ }
151
+ var store2;
152
+ // @__NO_SIDE_EFFECTS__
153
+ function getGlobalMessage(lang) {
154
+ return store2 == null ? void 0 : store2.get(lang);
155
+ }
156
+ var store3;
157
+ // @__NO_SIDE_EFFECTS__
158
+ function getSchemaMessage(lang) {
159
+ return store3 == null ? void 0 : store3.get(lang);
160
+ }
161
+ var store4;
162
+ // @__NO_SIDE_EFFECTS__
163
+ function getSpecificMessage(reference, lang) {
164
+ var _a;
165
+ return (_a = store4 == null ? void 0 : store4.get(reference)) == null ? void 0 : _a.get(lang);
166
+ }
167
+ // @__NO_SIDE_EFFECTS__
168
+ function _stringify(input) {
169
+ var _a, _b;
170
+ const type = typeof input;
171
+ if (type === "string") {
172
+ return `"${input}"`;
173
+ }
174
+ if (type === "number" || type === "bigint" || type === "boolean") {
175
+ return `${input}`;
176
+ }
177
+ if (type === "object" || type === "function") {
178
+ return (input && ((_b = (_a = Object.getPrototypeOf(input)) == null ? void 0 : _a.constructor) == null ? void 0 : _b.name)) ?? "null";
179
+ }
180
+ return type;
181
+ }
182
+ function _addIssue(context, label, dataset, config2, other) {
183
+ const input = other && "input" in other ? other.input : dataset.value;
184
+ const expected = (other == null ? void 0 : other.expected) ?? context.expects ?? null;
185
+ const received = (other == null ? void 0 : other.received) ?? /* @__PURE__ */ _stringify(input);
186
+ const issue = {
187
+ kind: context.kind,
188
+ type: context.type,
189
+ input,
190
+ expected,
191
+ received,
192
+ message: `Invalid ${label}: ${expected ? `Expected ${expected} but r` : "R"}eceived ${received}`,
193
+ requirement: context.requirement,
194
+ path: other == null ? void 0 : other.path,
195
+ issues: other == null ? void 0 : other.issues,
196
+ lang: config2.lang,
197
+ abortEarly: config2.abortEarly,
198
+ abortPipeEarly: config2.abortPipeEarly
199
+ };
200
+ const isSchema = context.kind === "schema";
201
+ 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);
202
+ if (message !== void 0) {
203
+ issue.message = typeof message === "function" ? (
204
+ // @ts-expect-error
205
+ message(issue)
206
+ ) : message;
207
+ }
208
+ if (isSchema) {
209
+ dataset.typed = false;
210
+ }
211
+ if (dataset.issues) {
212
+ dataset.issues.push(issue);
213
+ } else {
214
+ dataset.issues = [issue];
215
+ }
216
+ }
217
+ // @__NO_SIDE_EFFECTS__
218
+ function _getStandardProps(context) {
219
+ return {
220
+ version: 1,
221
+ vendor: "valibot",
222
+ validate(value2) {
223
+ return context["~run"]({ value: value2 }, /* @__PURE__ */ getGlobalConfig());
224
+ }
225
+ };
226
+ }
227
+ // @__NO_SIDE_EFFECTS__
228
+ function _isValidObjectKey(object2, key) {
229
+ return Object.hasOwn(object2, key) && key !== "__proto__" && key !== "prototype" && key !== "constructor";
230
+ }
231
+ // @__NO_SIDE_EFFECTS__
232
+ function _joinExpects(values2, separator) {
233
+ const list = [...new Set(values2)];
234
+ if (list.length > 1) {
235
+ return `(${list.join(` ${separator} `)})`;
236
+ }
237
+ return list[0] ?? "never";
238
+ }
239
+ // @__NO_SIDE_EFFECTS__
240
+ function isOfKind(kind, object2) {
241
+ return object2.kind === kind;
242
+ }
243
+ var ValiError = class extends Error {
244
+ /**
245
+ * Creates a Valibot error with useful information.
246
+ *
247
+ * @param issues The error issues.
248
+ */
249
+ constructor(issues) {
250
+ super(issues[0].message);
251
+ this.name = "ValiError";
252
+ this.issues = issues;
253
+ }
254
+ };
255
+ // @__NO_SIDE_EFFECTS__
256
+ function check(requirement, message) {
257
+ return {
258
+ kind: "validation",
259
+ type: "check",
260
+ reference: check,
261
+ async: false,
262
+ expects: null,
263
+ requirement,
264
+ message,
265
+ "~run"(dataset, config2) {
266
+ if (dataset.typed && !this.requirement(dataset.value)) {
267
+ _addIssue(this, "input", dataset, config2);
268
+ }
269
+ return dataset;
270
+ }
271
+ };
272
+ }
273
+ // @__NO_SIDE_EFFECTS__
274
+ function maxValue(requirement, message) {
275
+ return {
276
+ kind: "validation",
277
+ type: "max_value",
278
+ reference: maxValue,
279
+ async: false,
280
+ expects: `<=${requirement instanceof Date ? requirement.toJSON() : /* @__PURE__ */ _stringify(requirement)}`,
281
+ requirement,
282
+ message,
283
+ "~run"(dataset, config2) {
284
+ if (dataset.typed && !(dataset.value <= this.requirement)) {
285
+ _addIssue(this, "value", dataset, config2, {
286
+ received: dataset.value instanceof Date ? dataset.value.toJSON() : /* @__PURE__ */ _stringify(dataset.value)
287
+ });
288
+ }
289
+ return dataset;
290
+ }
291
+ };
292
+ }
293
+ // @__NO_SIDE_EFFECTS__
294
+ function metadata(metadata_) {
295
+ return {
296
+ kind: "metadata",
297
+ type: "metadata",
298
+ reference: metadata,
299
+ metadata: metadata_
300
+ };
301
+ }
302
+ // @__NO_SIDE_EFFECTS__
303
+ function minValue(requirement, message) {
304
+ return {
305
+ kind: "validation",
306
+ type: "min_value",
307
+ reference: minValue,
308
+ async: false,
309
+ expects: `>=${requirement instanceof Date ? requirement.toJSON() : /* @__PURE__ */ _stringify(requirement)}`,
310
+ requirement,
311
+ message,
312
+ "~run"(dataset, config2) {
313
+ if (dataset.typed && !(dataset.value >= this.requirement)) {
314
+ _addIssue(this, "value", dataset, config2, {
315
+ received: dataset.value instanceof Date ? dataset.value.toJSON() : /* @__PURE__ */ _stringify(dataset.value)
316
+ });
317
+ }
318
+ return dataset;
319
+ }
320
+ };
321
+ }
322
+ // @__NO_SIDE_EFFECTS__
323
+ function getFallback(schema, dataset, config2) {
324
+ return typeof schema.fallback === "function" ? (
325
+ // @ts-expect-error
326
+ schema.fallback(dataset, config2)
327
+ ) : (
328
+ // @ts-expect-error
329
+ schema.fallback
330
+ );
331
+ }
332
+ // @__NO_SIDE_EFFECTS__
333
+ function getDefault(schema, dataset, config2) {
334
+ return typeof schema.default === "function" ? (
335
+ // @ts-expect-error
336
+ schema.default(dataset, config2)
337
+ ) : (
338
+ // @ts-expect-error
339
+ schema.default
340
+ );
341
+ }
342
+ // @__NO_SIDE_EFFECTS__
343
+ function array(item, message) {
344
+ return {
345
+ kind: "schema",
346
+ type: "array",
347
+ reference: array,
348
+ expects: "Array",
349
+ async: false,
350
+ item,
351
+ message,
352
+ get "~standard"() {
353
+ return /* @__PURE__ */ _getStandardProps(this);
354
+ },
355
+ "~run"(dataset, config2) {
356
+ var _a;
357
+ const input = dataset.value;
358
+ if (Array.isArray(input)) {
359
+ dataset.typed = true;
360
+ dataset.value = [];
361
+ for (let key = 0; key < input.length; key++) {
362
+ const value2 = input[key];
363
+ const itemDataset = this.item["~run"]({ value: value2 }, config2);
364
+ if (itemDataset.issues) {
365
+ const pathItem = {
366
+ type: "array",
367
+ origin: "value",
368
+ input,
369
+ key,
370
+ value: value2
371
+ };
372
+ for (const issue of itemDataset.issues) {
373
+ if (issue.path) {
374
+ issue.path.unshift(pathItem);
375
+ } else {
376
+ issue.path = [pathItem];
377
+ }
378
+ (_a = dataset.issues) == null ? void 0 : _a.push(issue);
379
+ }
380
+ if (!dataset.issues) {
381
+ dataset.issues = itemDataset.issues;
382
+ }
383
+ if (config2.abortEarly) {
384
+ dataset.typed = false;
385
+ break;
386
+ }
387
+ }
388
+ if (!itemDataset.typed) {
389
+ dataset.typed = false;
390
+ }
391
+ dataset.value.push(itemDataset.value);
392
+ }
393
+ } else {
394
+ _addIssue(this, "type", dataset, config2);
395
+ }
396
+ return dataset;
397
+ }
398
+ };
399
+ }
400
+ // @__NO_SIDE_EFFECTS__
401
+ function boolean(message) {
402
+ return {
403
+ kind: "schema",
404
+ type: "boolean",
405
+ reference: boolean,
406
+ expects: "boolean",
407
+ async: false,
408
+ message,
409
+ get "~standard"() {
410
+ return /* @__PURE__ */ _getStandardProps(this);
411
+ },
412
+ "~run"(dataset, config2) {
413
+ if (typeof dataset.value === "boolean") {
414
+ dataset.typed = true;
415
+ } else {
416
+ _addIssue(this, "type", dataset, config2);
417
+ }
418
+ return dataset;
419
+ }
420
+ };
421
+ }
422
+ // @__NO_SIDE_EFFECTS__
423
+ function enum_(enum__, message) {
424
+ const options = [];
425
+ for (const key in enum__) {
426
+ if (`${+key}` !== key || typeof enum__[key] !== "string" || !Object.is(enum__[enum__[key]], +key)) {
427
+ options.push(enum__[key]);
428
+ }
429
+ }
430
+ return {
431
+ kind: "schema",
432
+ type: "enum",
433
+ reference: enum_,
434
+ expects: /* @__PURE__ */ _joinExpects(options.map(_stringify), "|"),
435
+ async: false,
436
+ enum: enum__,
437
+ options,
438
+ message,
439
+ get "~standard"() {
440
+ return /* @__PURE__ */ _getStandardProps(this);
441
+ },
442
+ "~run"(dataset, config2) {
443
+ if (this.options.includes(dataset.value)) {
444
+ dataset.typed = true;
445
+ } else {
446
+ _addIssue(this, "type", dataset, config2);
447
+ }
448
+ return dataset;
449
+ }
450
+ };
451
+ }
452
+ // @__NO_SIDE_EFFECTS__
453
+ function literal(literal_, message) {
454
+ return {
455
+ kind: "schema",
456
+ type: "literal",
457
+ reference: literal,
458
+ expects: /* @__PURE__ */ _stringify(literal_),
459
+ async: false,
460
+ literal: literal_,
461
+ message,
462
+ get "~standard"() {
463
+ return /* @__PURE__ */ _getStandardProps(this);
464
+ },
465
+ "~run"(dataset, config2) {
466
+ if (dataset.value === this.literal) {
467
+ dataset.typed = true;
468
+ } else {
469
+ _addIssue(this, "type", dataset, config2);
470
+ }
471
+ return dataset;
472
+ }
473
+ };
474
+ }
475
+ // @__NO_SIDE_EFFECTS__
476
+ function number(message) {
477
+ return {
478
+ kind: "schema",
479
+ type: "number",
480
+ reference: number,
481
+ expects: "number",
482
+ async: false,
483
+ message,
484
+ get "~standard"() {
485
+ return /* @__PURE__ */ _getStandardProps(this);
486
+ },
487
+ "~run"(dataset, config2) {
488
+ if (typeof dataset.value === "number" && !isNaN(dataset.value)) {
489
+ dataset.typed = true;
490
+ } else {
491
+ _addIssue(this, "type", dataset, config2);
492
+ }
493
+ return dataset;
494
+ }
495
+ };
496
+ }
497
+ // @__NO_SIDE_EFFECTS__
498
+ function object(entries, message) {
499
+ return {
500
+ kind: "schema",
501
+ type: "object",
502
+ reference: object,
503
+ expects: "Object",
504
+ async: false,
505
+ entries,
506
+ message,
507
+ get "~standard"() {
508
+ return /* @__PURE__ */ _getStandardProps(this);
509
+ },
510
+ "~run"(dataset, config2) {
511
+ var _a;
512
+ const input = dataset.value;
513
+ if (input && typeof input === "object") {
514
+ dataset.typed = true;
515
+ dataset.value = {};
516
+ for (const key in this.entries) {
517
+ const valueSchema = this.entries[key];
518
+ if (key in input || (valueSchema.type === "exact_optional" || valueSchema.type === "optional" || valueSchema.type === "nullish") && // @ts-expect-error
519
+ valueSchema.default !== void 0) {
520
+ const value2 = key in input ? (
521
+ // @ts-expect-error
522
+ input[key]
523
+ ) : /* @__PURE__ */ getDefault(valueSchema);
524
+ const valueDataset = valueSchema["~run"]({ value: value2 }, config2);
525
+ if (valueDataset.issues) {
526
+ const pathItem = {
527
+ type: "object",
528
+ origin: "value",
529
+ input,
530
+ key,
531
+ value: value2
532
+ };
533
+ for (const issue of valueDataset.issues) {
534
+ if (issue.path) {
535
+ issue.path.unshift(pathItem);
536
+ } else {
537
+ issue.path = [pathItem];
538
+ }
539
+ (_a = dataset.issues) == null ? void 0 : _a.push(issue);
540
+ }
541
+ if (!dataset.issues) {
542
+ dataset.issues = valueDataset.issues;
543
+ }
544
+ if (config2.abortEarly) {
545
+ dataset.typed = false;
546
+ break;
547
+ }
548
+ }
549
+ if (!valueDataset.typed) {
550
+ dataset.typed = false;
551
+ }
552
+ dataset.value[key] = valueDataset.value;
553
+ } else if (valueSchema.fallback !== void 0) {
554
+ dataset.value[key] = /* @__PURE__ */ getFallback(valueSchema);
555
+ } else if (valueSchema.type !== "exact_optional" && valueSchema.type !== "optional" && valueSchema.type !== "nullish") {
556
+ _addIssue(this, "key", dataset, config2, {
557
+ input: void 0,
558
+ expected: `"${key}"`,
559
+ path: [
560
+ {
561
+ type: "object",
562
+ origin: "key",
563
+ input,
564
+ key,
565
+ // @ts-expect-error
566
+ value: input[key]
567
+ }
568
+ ]
569
+ });
570
+ if (config2.abortEarly) {
571
+ break;
572
+ }
573
+ }
574
+ }
575
+ } else {
576
+ _addIssue(this, "type", dataset, config2);
577
+ }
578
+ return dataset;
579
+ }
580
+ };
581
+ }
582
+ // @__NO_SIDE_EFFECTS__
583
+ function optional(wrapped, default_) {
584
+ return {
585
+ kind: "schema",
586
+ type: "optional",
587
+ reference: optional,
588
+ expects: `(${wrapped.expects} | undefined)`,
589
+ async: false,
590
+ wrapped,
591
+ default: default_,
592
+ get "~standard"() {
593
+ return /* @__PURE__ */ _getStandardProps(this);
594
+ },
595
+ "~run"(dataset, config2) {
596
+ if (dataset.value === void 0) {
597
+ if (this.default !== void 0) {
598
+ dataset.value = /* @__PURE__ */ getDefault(this, dataset, config2);
599
+ }
600
+ if (dataset.value === void 0) {
601
+ dataset.typed = true;
602
+ return dataset;
603
+ }
604
+ }
605
+ return this.wrapped["~run"](dataset, config2);
606
+ }
607
+ };
608
+ }
609
+ // @__NO_SIDE_EFFECTS__
610
+ function picklist(options, message) {
611
+ return {
612
+ kind: "schema",
613
+ type: "picklist",
614
+ reference: picklist,
615
+ expects: /* @__PURE__ */ _joinExpects(options.map(_stringify), "|"),
616
+ async: false,
617
+ options,
618
+ message,
619
+ get "~standard"() {
620
+ return /* @__PURE__ */ _getStandardProps(this);
621
+ },
622
+ "~run"(dataset, config2) {
623
+ if (this.options.includes(dataset.value)) {
624
+ dataset.typed = true;
625
+ } else {
626
+ _addIssue(this, "type", dataset, config2);
627
+ }
628
+ return dataset;
629
+ }
630
+ };
631
+ }
632
+ // @__NO_SIDE_EFFECTS__
633
+ function record(key, value2, message) {
634
+ return {
635
+ kind: "schema",
636
+ type: "record",
637
+ reference: record,
638
+ expects: "Object",
639
+ async: false,
640
+ key,
641
+ value: value2,
642
+ message,
643
+ get "~standard"() {
644
+ return /* @__PURE__ */ _getStandardProps(this);
645
+ },
646
+ "~run"(dataset, config2) {
647
+ var _a, _b;
648
+ const input = dataset.value;
649
+ if (input && typeof input === "object") {
650
+ dataset.typed = true;
651
+ dataset.value = {};
652
+ for (const entryKey in input) {
653
+ if (/* @__PURE__ */ _isValidObjectKey(input, entryKey)) {
654
+ const entryValue = input[entryKey];
655
+ const keyDataset = this.key["~run"]({ value: entryKey }, config2);
656
+ if (keyDataset.issues) {
657
+ const pathItem = {
658
+ type: "object",
659
+ origin: "key",
660
+ input,
661
+ key: entryKey,
662
+ value: entryValue
663
+ };
664
+ for (const issue of keyDataset.issues) {
665
+ issue.path = [pathItem];
666
+ (_a = dataset.issues) == null ? void 0 : _a.push(issue);
667
+ }
668
+ if (!dataset.issues) {
669
+ dataset.issues = keyDataset.issues;
670
+ }
671
+ if (config2.abortEarly) {
672
+ dataset.typed = false;
673
+ break;
674
+ }
675
+ }
676
+ const valueDataset = this.value["~run"](
677
+ { value: entryValue },
678
+ config2
679
+ );
680
+ if (valueDataset.issues) {
681
+ const pathItem = {
682
+ type: "object",
683
+ origin: "value",
684
+ input,
685
+ key: entryKey,
686
+ value: entryValue
687
+ };
688
+ for (const issue of valueDataset.issues) {
689
+ if (issue.path) {
690
+ issue.path.unshift(pathItem);
691
+ } else {
692
+ issue.path = [pathItem];
693
+ }
694
+ (_b = dataset.issues) == null ? void 0 : _b.push(issue);
695
+ }
696
+ if (!dataset.issues) {
697
+ dataset.issues = valueDataset.issues;
698
+ }
699
+ if (config2.abortEarly) {
700
+ dataset.typed = false;
701
+ break;
702
+ }
703
+ }
704
+ if (!keyDataset.typed || !valueDataset.typed) {
705
+ dataset.typed = false;
706
+ }
707
+ if (keyDataset.typed) {
708
+ dataset.value[keyDataset.value] = valueDataset.value;
709
+ }
710
+ }
711
+ }
712
+ } else {
713
+ _addIssue(this, "type", dataset, config2);
714
+ }
715
+ return dataset;
716
+ }
717
+ };
718
+ }
719
+ // @__NO_SIDE_EFFECTS__
720
+ function string(message) {
721
+ return {
722
+ kind: "schema",
723
+ type: "string",
724
+ reference: string,
725
+ expects: "string",
726
+ async: false,
727
+ message,
728
+ get "~standard"() {
729
+ return /* @__PURE__ */ _getStandardProps(this);
730
+ },
731
+ "~run"(dataset, config2) {
732
+ if (typeof dataset.value === "string") {
733
+ dataset.typed = true;
734
+ } else {
735
+ _addIssue(this, "type", dataset, config2);
736
+ }
737
+ return dataset;
738
+ }
739
+ };
740
+ }
741
+ // @__NO_SIDE_EFFECTS__
742
+ function _subIssues(datasets) {
743
+ let issues;
744
+ if (datasets) {
745
+ for (const dataset of datasets) {
746
+ if (issues) {
747
+ issues.push(...dataset.issues);
748
+ } else {
749
+ issues = dataset.issues;
750
+ }
751
+ }
752
+ }
753
+ return issues;
754
+ }
755
+ // @__NO_SIDE_EFFECTS__
756
+ function union(options, message) {
757
+ return {
758
+ kind: "schema",
759
+ type: "union",
760
+ reference: union,
761
+ expects: /* @__PURE__ */ _joinExpects(
762
+ options.map((option) => option.expects),
763
+ "|"
764
+ ),
765
+ async: false,
766
+ options,
767
+ message,
768
+ get "~standard"() {
769
+ return /* @__PURE__ */ _getStandardProps(this);
770
+ },
771
+ "~run"(dataset, config2) {
772
+ let validDataset;
773
+ let typedDatasets;
774
+ let untypedDatasets;
775
+ for (const schema of this.options) {
776
+ const optionDataset = schema["~run"]({ value: dataset.value }, config2);
777
+ if (optionDataset.typed) {
778
+ if (optionDataset.issues) {
779
+ if (typedDatasets) {
780
+ typedDatasets.push(optionDataset);
781
+ } else {
782
+ typedDatasets = [optionDataset];
783
+ }
784
+ } else {
785
+ validDataset = optionDataset;
786
+ break;
787
+ }
788
+ } else {
789
+ if (untypedDatasets) {
790
+ untypedDatasets.push(optionDataset);
791
+ } else {
792
+ untypedDatasets = [optionDataset];
793
+ }
794
+ }
795
+ }
796
+ if (validDataset) {
797
+ return validDataset;
798
+ }
799
+ if (typedDatasets) {
800
+ if (typedDatasets.length === 1) {
801
+ return typedDatasets[0];
802
+ }
803
+ _addIssue(this, "type", dataset, config2, {
804
+ issues: /* @__PURE__ */ _subIssues(typedDatasets)
805
+ });
806
+ dataset.typed = true;
807
+ } else if ((untypedDatasets == null ? void 0 : untypedDatasets.length) === 1) {
808
+ return untypedDatasets[0];
809
+ } else {
810
+ _addIssue(this, "type", dataset, config2, {
811
+ issues: /* @__PURE__ */ _subIssues(untypedDatasets)
812
+ });
813
+ }
814
+ return dataset;
815
+ }
816
+ };
817
+ }
818
+ function parse(schema, input, config2) {
819
+ const dataset = schema["~run"]({ value: input }, /* @__PURE__ */ getGlobalConfig(config2));
820
+ if (dataset.issues) {
821
+ throw new ValiError(dataset.issues);
822
+ }
823
+ return dataset.value;
824
+ }
825
+ // @__NO_SIDE_EFFECTS__
826
+ function pipe(...pipe2) {
827
+ return {
828
+ ...pipe2[0],
829
+ pipe: pipe2,
830
+ get "~standard"() {
831
+ return /* @__PURE__ */ _getStandardProps(this);
832
+ },
833
+ "~run"(dataset, config2) {
834
+ for (const item of pipe2) {
835
+ if (item.kind !== "metadata") {
836
+ if (dataset.issues && (item.kind === "schema" || item.kind === "transformation")) {
837
+ dataset.typed = false;
838
+ break;
839
+ }
840
+ if (!dataset.issues || !config2.abortEarly && !config2.abortPipeEarly) {
841
+ dataset = item["~run"](dataset, config2);
842
+ }
843
+ }
844
+ }
845
+ return dataset;
846
+ }
847
+ };
848
+ }
849
+ // @__NO_SIDE_EFFECTS__
850
+ function safeParse(schema, input, config2) {
851
+ const dataset = schema["~run"]({ value: input }, /* @__PURE__ */ getGlobalConfig(config2));
852
+ return {
853
+ typed: dataset.typed,
854
+ success: !dataset.issues,
855
+ output: dataset.value,
856
+ issues: dataset.issues
857
+ };
858
+ }
859
+ const linkValidator = /* @__PURE__ */ check(
860
+ (value) => {
861
+ var _a, _b;
862
+ return !!value && ((_b = (_a = value == null ? void 0 : value.split) == null ? void 0 : _a.call(value, ":")) == null ? void 0 : _b.length) === 2;
863
+ }
864
+ );
865
+ const getMetadata = (schema) => {
866
+ var _a;
867
+ const pipelines = (schema == null ? void 0 : schema.pipe) ?? [];
868
+ return ((_a = pipelines == null ? void 0 : pipelines.find((pipe2) => /* @__PURE__ */ isOfKind("metadata", pipe2))) == null ? void 0 : _a.metadata) ?? null;
869
+ };
870
+ const layerField = (schema, meta) => {
871
+ const modifiedSchema = (meta == null ? void 0 : meta.variable) ? /* @__PURE__ */ union([schema, /* @__PURE__ */ pipe(/* @__PURE__ */ string(), linkValidator)]) : schema;
872
+ return /* @__PURE__ */ pipe(/* @__PURE__ */ optional(modifiedSchema), /* @__PURE__ */ metadata(meta ?? {}));
873
+ };
874
+ const ChildrenSchema = /* @__PURE__ */ object({
875
+ children: layerField(/* @__PURE__ */ array(/* @__PURE__ */ string()), {
876
+ fallback: [],
877
+ overridable: false
878
+ })
879
+ });
880
+ const GraphFieldSchema = /* @__PURE__ */ object({
881
+ _id: /* @__PURE__ */ union([/* @__PURE__ */ string(), /* @__PURE__ */ number()]),
882
+ _type: /* @__PURE__ */ picklist(Object.keys(nodes))
883
+ });
884
+ const OverridesSchema = /* @__PURE__ */ object({
885
+ overrides: layerField(/* @__PURE__ */ array(/* @__PURE__ */ string()), { overridable: false })
886
+ });
887
+ const PositionSchema = /* @__PURE__ */ object({
888
+ position: layerField(/* @__PURE__ */ enum_(Object.keys(positionType)), {
889
+ fallback: positionType.absolute
890
+ }),
891
+ top: layerField(/* @__PURE__ */ number(), { fallback: 0 }),
892
+ left: layerField(/* @__PURE__ */ number(), { fallback: 0 })
893
+ });
894
+ const SceneSchema = /* @__PURE__ */ object({
895
+ opacity: layerField(/* @__PURE__ */ pipe(/* @__PURE__ */ number(), /* @__PURE__ */ minValue(0), /* @__PURE__ */ maxValue(1)), {
896
+ fallback: 1,
897
+ variable: true
898
+ }),
899
+ visible: layerField(/* @__PURE__ */ boolean(), { fallback: true, variable: true }),
900
+ zIndex: layerField(/* @__PURE__ */ number(), { fallback: -1 }),
901
+ borderRadius: layerField(/* @__PURE__ */ string(), { fallback: "0px" }),
902
+ overflow: layerField(/* @__PURE__ */ picklist(Object.keys(overflow)), {
903
+ fallback: overflow.hidden
904
+ })
905
+ });
906
+ const FillSchema = /* @__PURE__ */ object({
907
+ fillType: layerField(/* @__PURE__ */ picklist(Object.keys(paintMode)), {
908
+ fallback: paintMode.None
909
+ }),
910
+ solidFill: layerField(/* @__PURE__ */ string(), { fallback: "#fff" })
911
+ });
912
+ const BorderSchema = /* @__PURE__ */ object({
913
+ borderType: layerField(/* @__PURE__ */ picklist(Object.keys(borderType)), {
914
+ fallback: borderType.None
915
+ }),
916
+ borderWidth: layerField(/* @__PURE__ */ pipe(/* @__PURE__ */ number(), /* @__PURE__ */ minValue(0)), { fallback: 0 }),
917
+ borderColor: layerField(/* @__PURE__ */ string(), { fallback: "#fff" })
918
+ });
919
+ const SizeSchema = /* @__PURE__ */ object({
920
+ widthType: layerField(/* @__PURE__ */ picklist(Object.keys(sizing)), {
921
+ fallback: sizing.Fixed
922
+ }),
923
+ heightType: layerField(/* @__PURE__ */ picklist(Object.keys(sizing)), {
924
+ fallback: sizing.Fixed
925
+ }),
926
+ width: layerField(/* @__PURE__ */ pipe(/* @__PURE__ */ number(), /* @__PURE__ */ minValue(0)), { fallback: 0 }),
927
+ height: layerField(/* @__PURE__ */ pipe(/* @__PURE__ */ number(), /* @__PURE__ */ minValue(0)), { fallback: 0 }),
928
+ aspectRatio: layerField(/* @__PURE__ */ number(), { fallback: -1 })
929
+ });
930
+ const LayerSchema = /* @__PURE__ */ object({
931
+ layerMode: layerField(/* @__PURE__ */ picklist(Object.keys(layerMode)), {
932
+ fallback: layerMode.none
933
+ }),
934
+ layerAlign: layerField(/* @__PURE__ */ picklist(Object.keys(layerAlign)), {
935
+ fallback: layerAlign.start
936
+ }),
937
+ layerDirection: layerField(/* @__PURE__ */ picklist(Object.keys(layerDirection)), {
938
+ fallback: layerDirection.horizontal
939
+ }),
940
+ layerDistribute: layerField(/* @__PURE__ */ picklist(Object.keys(layerDistribute)), {
941
+ fallback: layerDistribute.start
942
+ }),
943
+ layerWrap: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
944
+ layerGap: layerField(/* @__PURE__ */ pipe(/* @__PURE__ */ number(), /* @__PURE__ */ minValue(0)), { fallback: 0 }),
945
+ padding: layerField(/* @__PURE__ */ string(), { fallback: "0px" })
946
+ });
947
+ const FrameSchema = /* @__PURE__ */ pipe(
948
+ /* @__PURE__ */ object({
949
+ name: layerField(/* @__PURE__ */ string(), { fallback: "Frame", overridable: false }),
950
+ isBreakpoint: layerField(/* @__PURE__ */ boolean(), {
951
+ fallback: false,
952
+ overridable: false
953
+ }),
954
+ isPrimary: layerField(/* @__PURE__ */ boolean(), { fallback: false, overridable: false }),
955
+ threshold: layerField(/* @__PURE__ */ pipe(/* @__PURE__ */ number(), /* @__PURE__ */ minValue(0)), {
956
+ fallback: 320,
957
+ overridable: false
958
+ }),
959
+ ...ChildrenSchema.entries,
960
+ ...GraphFieldSchema.entries,
961
+ ...OverridesSchema.entries,
962
+ ...PositionSchema.entries,
963
+ ...SceneSchema.entries,
964
+ ...FillSchema.entries,
965
+ ...BorderSchema.entries,
966
+ ...SizeSchema.entries,
967
+ ...LayerSchema.entries
968
+ })
969
+ );
970
+ const TextSchema = /* @__PURE__ */ object({
971
+ name: layerField(/* @__PURE__ */ string(), { fallback: "Text", overridable: false }),
972
+ content: layerField(/* @__PURE__ */ string(), {
973
+ fallback: ""
974
+ }),
975
+ variableContent: layerField(/* @__PURE__ */ string(), { fallback: null, variable: true }),
976
+ attributes: layerField(
977
+ /* @__PURE__ */ object({
978
+ fontSize: layerField(/* @__PURE__ */ string(), { fallback: "14px" }),
979
+ color: layerField(/* @__PURE__ */ string(), { fallback: "#000" }),
980
+ lineHeight: layerField(/* @__PURE__ */ string(), { fallback: "14px" })
981
+ }),
982
+ { fallback: {} }
983
+ ),
984
+ ...GraphFieldSchema.entries,
985
+ ...OverridesSchema.entries,
986
+ ...PositionSchema.entries,
987
+ ...SceneSchema.entries,
988
+ ...SizeSchema.entries
989
+ });
990
+ const FragmentSchema = /* @__PURE__ */ object({
991
+ name: layerField(/* @__PURE__ */ string(), { fallback: "Fragment", overridable: false }),
992
+ horizontalGrow: layerField(/* @__PURE__ */ enum_(Object.keys(fragmentGrowingMode)), {
993
+ fallback: fragmentGrowingMode.auto,
994
+ overridable: false
995
+ }),
996
+ verticalGrow: layerField(/* @__PURE__ */ enum_(Object.keys(fragmentGrowingMode)), {
997
+ fallback: fragmentGrowingMode.auto,
998
+ overridable: false
999
+ }),
1000
+ properties: layerField(/* @__PURE__ */ array(/* @__PURE__ */ string()), {
1001
+ fallback: [],
1002
+ overridable: false
1003
+ }),
1004
+ ...GraphFieldSchema.entries,
1005
+ ...ChildrenSchema.entries
1006
+ });
1007
+ const InstanceSchema = /* @__PURE__ */ object({
1008
+ name: layerField(/* @__PURE__ */ string(), { fallback: "Instance", overridable: false }),
1009
+ fragment: layerField(/* @__PURE__ */ string()),
1010
+ props: layerField(
1011
+ /* @__PURE__ */ record(/* @__PURE__ */ string(), /* @__PURE__ */ union([/* @__PURE__ */ string(), /* @__PURE__ */ number(), /* @__PURE__ */ boolean()])),
1012
+ {
1013
+ fallback: {}
1014
+ }
1015
+ ),
1016
+ ...GraphFieldSchema.entries,
1017
+ ...OverridesSchema.entries,
1018
+ ...PositionSchema.entries,
1019
+ ...SizeSchema.entries,
1020
+ ...SceneSchema.entries
1021
+ });
1022
+ const NumberVariableSchema = /* @__PURE__ */ object({
1023
+ name: layerField(/* @__PURE__ */ string(), {
1024
+ fallback: "Number",
1025
+ overridable: false
1026
+ }),
1027
+ type: layerField(/* @__PURE__ */ literal(variableType.Number), {
1028
+ fallback: variableType.Number
1029
+ }),
1030
+ defaultValue: layerField(/* @__PURE__ */ number(), { fallback: 0 }),
1031
+ required: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1032
+ min: layerField(/* @__PURE__ */ number(), { fallback: 1 }),
1033
+ max: layerField(/* @__PURE__ */ number(), { fallback: 100 }),
1034
+ step: layerField(/* @__PURE__ */ number(), { fallback: 1 }),
1035
+ displayStepper: layerField(/* @__PURE__ */ boolean(), { fallback: true }),
1036
+ ...GraphFieldSchema.entries
1037
+ });
1038
+ const BooleanVariableSchema = /* @__PURE__ */ object({
1039
+ name: layerField(/* @__PURE__ */ string(), {
1040
+ fallback: "Boolean",
1041
+ overridable: false
1042
+ }),
1043
+ type: layerField(/* @__PURE__ */ literal(variableType.Boolean), {
1044
+ fallback: variableType.Boolean
1045
+ }),
1046
+ defaultValue: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1047
+ required: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1048
+ ...GraphFieldSchema.entries
1049
+ });
1050
+ const ColorVariableSchema = /* @__PURE__ */ object({
1051
+ name: layerField(/* @__PURE__ */ string(), {
1052
+ fallback: "String",
1053
+ overridable: false
1054
+ }),
1055
+ type: layerField(/* @__PURE__ */ literal(variableType.Color), {
1056
+ fallback: variableType.Color
1057
+ }),
1058
+ // TODO Add color validator
1059
+ defaultValue: layerField(/* @__PURE__ */ string(), { fallback: "#000" }),
1060
+ required: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1061
+ ...GraphFieldSchema.entries
1062
+ });
1063
+ const StringVariableSchema = /* @__PURE__ */ object({
1064
+ name: layerField(/* @__PURE__ */ string(), {
1065
+ fallback: "String",
1066
+ overridable: false
1067
+ }),
1068
+ type: layerField(/* @__PURE__ */ literal(variableType.String), {
1069
+ fallback: variableType.String
1070
+ }),
1071
+ defaultValue: layerField(/* @__PURE__ */ string(), { fallback: "" }),
1072
+ required: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1073
+ placeholder: layerField(/* @__PURE__ */ string(), { fallback: "" }),
1074
+ isTextarea: layerField(/* @__PURE__ */ boolean(), { fallback: false }),
1075
+ ...GraphFieldSchema.entries
1076
+ });
1077
+ const getLayerSchema = (layer) => {
1078
+ if (!(layer == null ? void 0 : layer._type)) return null;
1079
+ if ((layer == null ? void 0 : layer._type) === nodes.Frame) return FrameSchema;
1080
+ if ((layer == null ? void 0 : layer._type) === nodes.Text) return TextSchema;
1081
+ if ((layer == null ? void 0 : layer._type) === nodes.Fragment) return FragmentSchema;
1082
+ if ((layer == null ? void 0 : layer._type) === nodes.Instance) return InstanceSchema;
1083
+ if (layer._type === nodes.Variable) {
1084
+ const types = {
1085
+ [variableType.Number]: NumberVariableSchema,
1086
+ [variableType.Boolean]: BooleanVariableSchema,
1087
+ [variableType.String]: StringVariableSchema,
1088
+ [variableType.Color]: ColorVariableSchema
1089
+ };
1090
+ if (layer.type in types) {
1091
+ return types[layer.type];
1092
+ }
1093
+ }
1094
+ };
1095
+ const normalizeLayer = (schema, rawLayer, options) => {
1096
+ try {
1097
+ if (!rawLayer) return null;
1098
+ const withFallback = (options == null ? void 0 : options.withFallback) ?? true;
1099
+ const overrideTarget = options == null ? void 0 : options.overrideTarget;
1100
+ const parsedLayer = parse(schema, rawLayer);
1101
+ return Object.fromEntries(
1102
+ Object.entries(schema.entries).map(([key, schemaEntity]) => {
1103
+ const schemaMeta = getMetadata(schemaEntity);
1104
+ const fallback = withFallback ? schemaMeta == null ? void 0 : schemaMeta.fallback : null;
1105
+ const overrideValue = (schemaMeta == null ? void 0 : schemaMeta.overridable) !== false && overrideTarget ? overrideTarget == null ? void 0 : overrideTarget[key] : null;
1106
+ return [key, parsedLayer[key] ?? overrideValue ?? fallback];
1107
+ })
1108
+ );
1109
+ } catch (e) {
1110
+ console.error(e);
1111
+ return null;
1112
+ }
1113
+ };
1114
+ const getNormalizeLayer = (layer, overrider) => {
1115
+ if (!layer) return null;
1116
+ const schema = getLayerSchema(layer);
1117
+ if (!schema) return null;
1118
+ return normalizeLayer(schema, layer, {
1119
+ overrideTarget: overrider
1120
+ });
1121
+ };
1122
+ const isValidLayerField = (layer, field, value) => {
1123
+ var _a, _b;
1124
+ const schema = getLayerSchema(layer);
1125
+ if (schema && ((_a = schema == null ? void 0 : schema.entries) == null ? void 0 : _a[field])) {
1126
+ const { success } = /* @__PURE__ */ safeParse((_b = schema.entries) == null ? void 0 : _b[field], value);
1127
+ return success;
1128
+ }
1129
+ return false;
1130
+ };
1131
+ export {
1132
+ index as definition,
1133
+ getNormalizeLayer,
1134
+ isValidLayerField
1135
+ };