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