@webstudio-is/sdk 0.0.0-4f7bf18 → 0.0.0-50b8685

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.
package/lib/index.js CHANGED
@@ -57,7 +57,7 @@ var commonPageFields = {
57
57
  title: PageTitle,
58
58
  history: z2.optional(z2.array(z2.string())),
59
59
  rootInstanceId: z2.string(),
60
- systemDataSourceId: z2.string(),
60
+ systemDataSourceId: z2.string().optional(),
61
61
  meta: z2.object({
62
62
  description: z2.string().optional(),
63
63
  title: z2.string().optional(),
@@ -88,7 +88,10 @@ var HomePage = z2.object({
88
88
  ...commonPageFields,
89
89
  path: HomePagePath
90
90
  });
91
- var PagePath = z2.string().refine((path) => path !== "", "Can't be empty").refine((path) => path !== "/", "Can't be just a /").refine((path) => path === "" || path.startsWith("/"), "Must start with a /").refine((path) => path.endsWith("/") === false, "Can't end with a /").refine((path) => path.includes("//") === false, "Can't contain repeating /").refine(
91
+ var PagePath = z2.string().refine((path) => path !== "", "Can't be empty").refine((path) => path !== "/", "Can't be just a /").refine(
92
+ (path) => path === "" || path.startsWith("/"),
93
+ "Must start with a / or a full URL e.g. https://website.org"
94
+ ).refine((path) => path.endsWith("/") === false, "Can't end with a /").refine((path) => path.includes("//") === false, "Can't contain repeating /").refine(
92
95
  (path) => /^[-_a-z0-9*:?\\/.]*$/.test(path),
93
96
  "Only a-z, 0-9, -, _, /, :, ?, . and * are allowed"
94
97
  ).refine(
@@ -184,7 +187,13 @@ var MatcherOperation = z3.object({
184
187
  var Matcher = z3.object({
185
188
  relation: MatcherRelation,
186
189
  component: MatcherOperation.optional(),
187
- tag: MatcherOperation.optional()
190
+ tag: MatcherOperation.optional(),
191
+ text: z3.literal(false).describe(
192
+ `
193
+ To disallow text editing on a container instance,
194
+ use: { relation: 'child', text: false }
195
+ `
196
+ ).optional()
188
197
  });
189
198
  var Matchers = z3.union([Matcher, z3.array(Matcher)]);
190
199
 
@@ -218,20 +227,25 @@ var DataSource = z4.union([
218
227
  z4.object({
219
228
  type: z4.literal("variable"),
220
229
  id: DataSourceId,
221
- scopeInstanceId: z4.string(),
230
+ // The instance should always be specified for variables,
231
+ // however, there was a bug in the embed template
232
+ // which produced variables without an instance
233
+ // and these variables will fail validation
234
+ // if we make it required
235
+ scopeInstanceId: z4.string().optional(),
222
236
  name: z4.string(),
223
237
  value: DataSourceVariableValue
224
238
  }),
225
239
  z4.object({
226
240
  type: z4.literal("parameter"),
227
241
  id: DataSourceId,
228
- scopeInstanceId: z4.string(),
242
+ scopeInstanceId: z4.string().optional(),
229
243
  name: z4.string()
230
244
  }),
231
245
  z4.object({
232
246
  type: z4.literal("resource"),
233
247
  id: DataSourceId,
234
- scopeInstanceId: z4.string(),
248
+ scopeInstanceId: z4.string().optional(),
235
249
  name: z4.string(),
236
250
  resourceId: z4.string()
237
251
  })
@@ -274,98 +288,262 @@ var ResourceRequest = z5.object({
274
288
  var Resources = z5.map(ResourceId, Resource);
275
289
 
276
290
  // src/schema/props.ts
291
+ import { z as z7 } from "zod";
292
+
293
+ // src/schema/animation-schema.ts
294
+ import { StyleValue } from "@webstudio-is/css-engine";
277
295
  import { z as z6 } from "zod";
278
- var PropId = z6.string();
296
+ var literalUnion = (arr) => z6.union(
297
+ arr.map((val) => z6.literal(val))
298
+ );
299
+ var RANGE_UNITS = [
300
+ "%",
301
+ "px",
302
+ "cm",
303
+ "mm",
304
+ "q",
305
+ "in",
306
+ "pt",
307
+ "pc",
308
+ "em",
309
+ "rem",
310
+ "ex",
311
+ "rex",
312
+ "cap",
313
+ "rcap",
314
+ "ch",
315
+ "rch",
316
+ "lh",
317
+ "rlh",
318
+ "vw",
319
+ "svw",
320
+ "lvw",
321
+ "dvw",
322
+ "vh",
323
+ "svh",
324
+ "lvh",
325
+ "dvh",
326
+ "vi",
327
+ "svi",
328
+ "lvi",
329
+ "dvi",
330
+ "vb",
331
+ "svb",
332
+ "lvb",
333
+ "dvb",
334
+ "vmin",
335
+ "svmin",
336
+ "lvmin",
337
+ "dvmin",
338
+ "vmax",
339
+ "svmax",
340
+ "lvmax",
341
+ "dvmax"
342
+ ];
343
+ var rangeUnitSchema = literalUnion(RANGE_UNITS);
344
+ var rangeUnitValueSchema = z6.union([
345
+ z6.object({
346
+ type: z6.literal("unit"),
347
+ value: z6.number(),
348
+ unit: rangeUnitSchema
349
+ }),
350
+ z6.object({
351
+ type: z6.literal("unparsed"),
352
+ value: z6.string()
353
+ })
354
+ ]);
355
+ var insetUnitValueSchema = z6.union([
356
+ rangeUnitValueSchema,
357
+ z6.object({
358
+ type: z6.literal("keyword"),
359
+ value: z6.literal("auto")
360
+ })
361
+ ]);
362
+ var keyframeStylesSchema = z6.record(StyleValue);
363
+ var animationKeyframeSchema = z6.object({
364
+ offset: z6.number().optional(),
365
+ styles: keyframeStylesSchema
366
+ });
367
+ var keyframeEffectOptionsSchema = z6.object({
368
+ easing: z6.string().optional(),
369
+ fill: z6.union([
370
+ z6.literal("none"),
371
+ z6.literal("forwards"),
372
+ z6.literal("backwards"),
373
+ z6.literal("both")
374
+ ]).optional()
375
+ // FillMode
376
+ });
377
+ var scrollNamedRangeSchema = z6.union([
378
+ z6.literal("start"),
379
+ z6.literal("end")
380
+ ]);
381
+ var scrollRangeValueSchema = z6.tuple([
382
+ scrollNamedRangeSchema,
383
+ rangeUnitValueSchema
384
+ ]);
385
+ var scrollRangeOptionsSchema = z6.object({
386
+ rangeStart: scrollRangeValueSchema.optional(),
387
+ rangeEnd: scrollRangeValueSchema.optional()
388
+ });
389
+ var animationAxisSchema = z6.union([
390
+ z6.literal("block"),
391
+ z6.literal("inline"),
392
+ z6.literal("x"),
393
+ z6.literal("y")
394
+ ]);
395
+ var viewNamedRangeSchema = z6.union([
396
+ z6.literal("contain"),
397
+ z6.literal("cover"),
398
+ z6.literal("entry"),
399
+ z6.literal("exit"),
400
+ z6.literal("entry-crossing"),
401
+ z6.literal("exit-crossing")
402
+ ]);
403
+ var viewRangeValueSchema = z6.tuple([
404
+ viewNamedRangeSchema,
405
+ rangeUnitValueSchema
406
+ ]);
407
+ var viewRangeOptionsSchema = z6.object({
408
+ rangeStart: viewRangeValueSchema.optional(),
409
+ rangeEnd: viewRangeValueSchema.optional()
410
+ });
411
+ var baseAnimation = z6.object({
412
+ name: z6.string().optional(),
413
+ description: z6.string().optional(),
414
+ enabled: z6.array(z6.tuple([z6.string().describe("breakpointId"), z6.boolean()])).optional(),
415
+ keyframes: z6.array(animationKeyframeSchema)
416
+ });
417
+ var scrollAnimationSchema = baseAnimation.merge(
418
+ z6.object({
419
+ timing: keyframeEffectOptionsSchema.merge(scrollRangeOptionsSchema)
420
+ })
421
+ );
422
+ var scrollActionSchema = z6.object({
423
+ type: z6.literal("scroll"),
424
+ source: z6.union([z6.literal("closest"), z6.literal("nearest"), z6.literal("root")]).optional(),
425
+ axis: animationAxisSchema.optional(),
426
+ animations: z6.array(scrollAnimationSchema),
427
+ isPinned: z6.boolean().optional(),
428
+ debug: z6.boolean().optional()
429
+ });
430
+ var viewAnimationSchema = baseAnimation.merge(
431
+ z6.object({
432
+ timing: keyframeEffectOptionsSchema.merge(viewRangeOptionsSchema)
433
+ })
434
+ );
435
+ var viewActionSchema = z6.object({
436
+ type: z6.literal("view"),
437
+ subject: z6.string().optional(),
438
+ axis: animationAxisSchema.optional(),
439
+ animations: z6.array(viewAnimationSchema),
440
+ insetStart: insetUnitValueSchema.optional(),
441
+ insetEnd: insetUnitValueSchema.optional(),
442
+ isPinned: z6.boolean().optional(),
443
+ debug: z6.boolean().optional()
444
+ });
445
+ var animationActionSchema = z6.discriminatedUnion("type", [
446
+ scrollActionSchema,
447
+ viewActionSchema
448
+ ]);
449
+
450
+ // src/schema/props.ts
451
+ var PropId = z7.string();
279
452
  var baseProp = {
280
453
  id: PropId,
281
- instanceId: z6.string(),
282
- name: z6.string(),
283
- required: z6.optional(z6.boolean())
454
+ instanceId: z7.string(),
455
+ name: z7.string(),
456
+ required: z7.optional(z7.boolean())
284
457
  };
285
- var Prop = z6.union([
286
- z6.object({
458
+ var Prop = z7.union([
459
+ z7.object({
287
460
  ...baseProp,
288
- type: z6.literal("number"),
289
- value: z6.number()
461
+ type: z7.literal("number"),
462
+ value: z7.number()
290
463
  }),
291
- z6.object({
464
+ z7.object({
292
465
  ...baseProp,
293
- type: z6.literal("string"),
294
- value: z6.string()
466
+ type: z7.literal("string"),
467
+ value: z7.string()
295
468
  }),
296
- z6.object({
469
+ z7.object({
297
470
  ...baseProp,
298
- type: z6.literal("boolean"),
299
- value: z6.boolean()
471
+ type: z7.literal("boolean"),
472
+ value: z7.boolean()
300
473
  }),
301
- z6.object({
474
+ z7.object({
302
475
  ...baseProp,
303
- type: z6.literal("json"),
304
- value: z6.unknown()
476
+ type: z7.literal("json"),
477
+ value: z7.unknown()
305
478
  }),
306
- z6.object({
479
+ z7.object({
307
480
  ...baseProp,
308
- type: z6.literal("asset"),
309
- value: z6.string()
481
+ type: z7.literal("asset"),
482
+ value: z7.string()
310
483
  // asset id
311
484
  }),
312
- z6.object({
485
+ z7.object({
313
486
  ...baseProp,
314
- type: z6.literal("page"),
315
- value: z6.union([
316
- z6.string(),
487
+ type: z7.literal("page"),
488
+ value: z7.union([
489
+ z7.string(),
317
490
  // page id
318
- z6.object({
319
- pageId: z6.string(),
320
- instanceId: z6.string()
491
+ z7.object({
492
+ pageId: z7.string(),
493
+ instanceId: z7.string()
321
494
  })
322
495
  ])
323
496
  }),
324
- z6.object({
497
+ z7.object({
325
498
  ...baseProp,
326
- type: z6.literal("string[]"),
327
- value: z6.array(z6.string())
499
+ type: z7.literal("string[]"),
500
+ value: z7.array(z7.string())
328
501
  }),
329
- z6.object({
502
+ z7.object({
330
503
  ...baseProp,
331
- type: z6.literal("parameter"),
504
+ type: z7.literal("parameter"),
332
505
  // data source id
333
- value: z6.string()
506
+ value: z7.string()
334
507
  }),
335
- z6.object({
508
+ z7.object({
336
509
  ...baseProp,
337
- type: z6.literal("resource"),
510
+ type: z7.literal("resource"),
338
511
  // resource id
339
- value: z6.string()
512
+ value: z7.string()
340
513
  }),
341
- z6.object({
514
+ z7.object({
342
515
  ...baseProp,
343
- type: z6.literal("expression"),
516
+ type: z7.literal("expression"),
344
517
  // expression code
345
- value: z6.string()
518
+ value: z7.string()
346
519
  }),
347
- z6.object({
520
+ z7.object({
348
521
  ...baseProp,
349
- type: z6.literal("action"),
350
- value: z6.array(
351
- z6.object({
352
- type: z6.literal("execute"),
353
- args: z6.array(z6.string()),
354
- code: z6.string()
522
+ type: z7.literal("action"),
523
+ value: z7.array(
524
+ z7.object({
525
+ type: z7.literal("execute"),
526
+ args: z7.array(z7.string()),
527
+ code: z7.string()
355
528
  })
356
529
  )
530
+ }),
531
+ z7.object({
532
+ ...baseProp,
533
+ type: z7.literal("animationAction"),
534
+ value: animationActionSchema
357
535
  })
358
536
  ]);
359
- var Props = z6.map(PropId, Prop);
537
+ var Props = z7.map(PropId, Prop);
360
538
 
361
539
  // src/schema/breakpoints.ts
362
- import { z as z7 } from "zod";
363
- var BreakpointId = z7.string();
364
- var Breakpoint = z7.object({
540
+ import { z as z8 } from "zod";
541
+ var BreakpointId = z8.string();
542
+ var Breakpoint = z8.object({
365
543
  id: BreakpointId,
366
- label: z7.string(),
367
- minWidth: z7.number().optional(),
368
- maxWidth: z7.number().optional()
544
+ label: z8.string(),
545
+ minWidth: z8.number().optional(),
546
+ maxWidth: z8.number().optional()
369
547
  }).refine(({ minWidth, maxWidth }) => {
370
548
  return (
371
549
  // Either min or max width have to be defined
@@ -373,7 +551,7 @@ var Breakpoint = z7.object({
373
551
  minWidth === void 0 && maxWidth === void 0
374
552
  );
375
553
  }, "Either minWidth or maxWidth should be defined");
376
- var Breakpoints = z7.map(BreakpointId, Breakpoint);
554
+ var Breakpoints = z8.map(BreakpointId, Breakpoint);
377
555
  var initialBreakpoints = [
378
556
  { id: "placeholder", label: "Base" },
379
557
  { id: "placeholder", label: "Tablet", maxWidth: 991 },
@@ -382,235 +560,247 @@ var initialBreakpoints = [
382
560
  ];
383
561
 
384
562
  // src/schema/style-sources.ts
385
- import { z as z8 } from "zod";
386
- var StyleSourceId = z8.string();
387
- var StyleSourceToken = z8.object({
388
- type: z8.literal("token"),
563
+ import { z as z9 } from "zod";
564
+ var StyleSourceId = z9.string();
565
+ var StyleSourceToken = z9.object({
566
+ type: z9.literal("token"),
389
567
  id: StyleSourceId,
390
- name: z8.string()
568
+ name: z9.string()
391
569
  });
392
- var StyleSourceLocal = z8.object({
393
- type: z8.literal("local"),
570
+ var StyleSourceLocal = z9.object({
571
+ type: z9.literal("local"),
394
572
  id: StyleSourceId
395
573
  });
396
- var StyleSource = z8.union([StyleSourceToken, StyleSourceLocal]);
397
- var StyleSources = z8.map(StyleSourceId, StyleSource);
574
+ var StyleSource = z9.union([StyleSourceToken, StyleSourceLocal]);
575
+ var StyleSources = z9.map(StyleSourceId, StyleSource);
398
576
 
399
577
  // src/schema/style-source-selections.ts
400
- import { z as z9 } from "zod";
401
- var InstanceId2 = z9.string();
402
- var StyleSourceId2 = z9.string();
403
- var StyleSourceSelection = z9.object({
578
+ import { z as z10 } from "zod";
579
+ var InstanceId2 = z10.string();
580
+ var StyleSourceId2 = z10.string();
581
+ var StyleSourceSelection = z10.object({
404
582
  instanceId: InstanceId2,
405
- values: z9.array(StyleSourceId2)
583
+ values: z10.array(StyleSourceId2)
406
584
  });
407
- var StyleSourceSelections = z9.map(InstanceId2, StyleSourceSelection);
585
+ var StyleSourceSelections = z10.map(InstanceId2, StyleSourceSelection);
408
586
 
409
587
  // src/schema/styles.ts
410
- import { z as z10 } from "zod";
411
- import { StyleValue } from "@webstudio-is/css-engine";
412
- var StyleDeclRaw = z10.object({
413
- styleSourceId: z10.string(),
414
- breakpointId: z10.string(),
415
- state: z10.optional(z10.string()),
588
+ import { z as z11 } from "zod";
589
+ import { StyleValue as StyleValue2 } from "@webstudio-is/css-engine";
590
+ var StyleDeclRaw = z11.object({
591
+ styleSourceId: z11.string(),
592
+ breakpointId: z11.string(),
593
+ state: z11.optional(z11.string()),
416
594
  // @todo can't figure out how to make property to be enum
417
- property: z10.string(),
418
- value: StyleValue,
419
- listed: z10.boolean().optional()
595
+ property: z11.string(),
596
+ value: StyleValue2,
597
+ listed: z11.boolean().optional().describe("Whether the style is from the Advanced panel")
420
598
  });
421
599
  var StyleDecl = StyleDeclRaw;
422
600
  var getStyleDeclKey = (styleDecl) => {
423
601
  return `${styleDecl.styleSourceId}:${styleDecl.breakpointId}:${styleDecl.property}:${styleDecl.state ?? ""}`;
424
602
  };
425
- var Styles = z10.map(z10.string(), StyleDecl);
603
+ var Styles = z11.map(z11.string(), StyleDecl);
426
604
 
427
605
  // src/schema/deployment.ts
428
- import { z as z11 } from "zod";
429
- var Templates = z11.enum([
430
- "vanilla",
606
+ import { z as z12 } from "zod";
607
+ var Templates = z12.enum([
608
+ "docker",
431
609
  "vercel",
432
- "netlify-functions",
433
- "netlify-edge-functions",
610
+ "netlify",
434
611
  "ssg",
435
612
  "ssg-netlify",
436
613
  "ssg-vercel"
437
614
  ]);
438
- var Deployment = z11.union([
439
- z11.object({
440
- destination: z11.literal("static"),
441
- name: z11.string(),
442
- assetsDomain: z11.string(),
615
+ var Deployment = z12.union([
616
+ z12.object({
617
+ destination: z12.literal("static"),
618
+ name: z12.string(),
619
+ assetsDomain: z12.string(),
443
620
  // Must be validated very strictly
444
- templates: z11.array(Templates)
621
+ templates: z12.array(Templates)
445
622
  }),
446
- z11.object({
447
- destination: z11.literal("saas").optional(),
448
- domains: z11.array(z11.string()),
449
- assetsDomain: z11.string().optional(),
623
+ z12.object({
624
+ destination: z12.literal("saas").optional(),
625
+ domains: z12.array(z12.string()),
626
+ assetsDomain: z12.string().optional(),
450
627
  /**
451
628
  * @deprecated This field is deprecated, use `domains` instead.
452
629
  */
453
- projectDomain: z11.string().optional(),
454
- excludeWstdDomainFromSearch: z11.boolean().optional()
630
+ projectDomain: z12.string().optional(),
631
+ excludeWstdDomainFromSearch: z12.boolean().optional()
455
632
  })
456
633
  ]);
457
634
 
458
635
  // src/schema/webstudio.ts
459
- import { z as z12 } from "zod";
460
- var WebstudioFragment = z12.object({
461
- children: z12.array(InstanceChild),
462
- instances: z12.array(Instance),
463
- assets: z12.array(Asset),
464
- dataSources: z12.array(DataSource),
465
- resources: z12.array(Resource),
466
- props: z12.array(Prop),
467
- breakpoints: z12.array(Breakpoint),
468
- styleSourceSelections: z12.array(StyleSourceSelection),
469
- styleSources: z12.array(StyleSource),
470
- styles: z12.array(StyleDecl)
636
+ import { z as z13 } from "zod";
637
+ var WebstudioFragment = z13.object({
638
+ children: z13.array(InstanceChild),
639
+ instances: z13.array(Instance),
640
+ assets: z13.array(Asset),
641
+ dataSources: z13.array(DataSource),
642
+ resources: z13.array(Resource),
643
+ props: z13.array(Prop),
644
+ breakpoints: z13.array(Breakpoint),
645
+ styleSourceSelections: z13.array(StyleSourceSelection),
646
+ styleSources: z13.array(StyleSource),
647
+ styles: z13.array(StyleDecl)
471
648
  });
472
649
 
473
650
  // src/schema/prop-meta.ts
474
- import { z as z13 } from "zod";
651
+ import { z as z14 } from "zod";
475
652
  var common = {
476
- label: z13.string().optional(),
477
- description: z13.string().optional(),
478
- required: z13.boolean()
653
+ label: z14.string().optional(),
654
+ description: z14.string().optional(),
655
+ required: z14.boolean()
479
656
  };
480
- var Number = z13.object({
657
+ var Number = z14.object({
481
658
  ...common,
482
- control: z13.literal("number"),
483
- type: z13.literal("number"),
484
- defaultValue: z13.number().optional()
659
+ control: z14.literal("number"),
660
+ type: z14.literal("number"),
661
+ defaultValue: z14.number().optional()
485
662
  });
486
- var Range = z13.object({
663
+ var Range = z14.object({
487
664
  ...common,
488
- control: z13.literal("range"),
489
- type: z13.literal("number"),
490
- defaultValue: z13.number().optional()
665
+ control: z14.literal("range"),
666
+ type: z14.literal("number"),
667
+ defaultValue: z14.number().optional()
491
668
  });
492
- var Text = z13.object({
669
+ var Text = z14.object({
493
670
  ...common,
494
- control: z13.literal("text"),
495
- type: z13.literal("string"),
496
- defaultValue: z13.string().optional(),
671
+ control: z14.literal("text"),
672
+ type: z14.literal("string"),
673
+ defaultValue: z14.string().optional(),
497
674
  /**
498
675
  * The number of rows in <textarea>. If set to 0 an <input> will be used instead.
499
676
  * In line with Storybook team's plan: https://github.com/storybookjs/storybook/issues/21100
500
677
  */
501
- rows: z13.number().optional()
678
+ rows: z14.number().optional()
502
679
  });
503
- var Code = z13.object({
680
+ var Resource2 = z14.object({
504
681
  ...common,
505
- control: z13.literal("code"),
506
- type: z13.literal("string"),
507
- language: z13.union([z13.literal("html"), z13.literal("markdown")]),
508
- defaultValue: z13.string().optional()
682
+ control: z14.literal("resource"),
683
+ type: z14.literal("resource"),
684
+ defaultValue: z14.string().optional()
509
685
  });
510
- var CodeText = z13.object({
686
+ var Code = z14.object({
511
687
  ...common,
512
- control: z13.literal("codetext"),
513
- type: z13.literal("string"),
514
- defaultValue: z13.string().optional()
688
+ control: z14.literal("code"),
689
+ type: z14.literal("string"),
690
+ language: z14.union([z14.literal("html"), z14.literal("markdown")]),
691
+ defaultValue: z14.string().optional()
515
692
  });
516
- var Color = z13.object({
693
+ var CodeText = z14.object({
517
694
  ...common,
518
- control: z13.literal("color"),
519
- type: z13.literal("string"),
520
- defaultValue: z13.string().optional()
695
+ control: z14.literal("codetext"),
696
+ type: z14.literal("string"),
697
+ defaultValue: z14.string().optional()
521
698
  });
522
- var Boolean = z13.object({
699
+ var Color = z14.object({
523
700
  ...common,
524
- control: z13.literal("boolean"),
525
- type: z13.literal("boolean"),
526
- defaultValue: z13.boolean().optional()
701
+ control: z14.literal("color"),
702
+ type: z14.literal("string"),
703
+ defaultValue: z14.string().optional()
527
704
  });
528
- var Radio = z13.object({
705
+ var Boolean = z14.object({
529
706
  ...common,
530
- control: z13.literal("radio"),
531
- type: z13.literal("string"),
532
- defaultValue: z13.string().optional(),
533
- options: z13.array(z13.string())
707
+ control: z14.literal("boolean"),
708
+ type: z14.literal("boolean"),
709
+ defaultValue: z14.boolean().optional()
534
710
  });
535
- var InlineRadio = z13.object({
711
+ var Radio = z14.object({
536
712
  ...common,
537
- control: z13.literal("inline-radio"),
538
- type: z13.literal("string"),
539
- defaultValue: z13.string().optional(),
540
- options: z13.array(z13.string())
713
+ control: z14.literal("radio"),
714
+ type: z14.literal("string"),
715
+ defaultValue: z14.string().optional(),
716
+ options: z14.array(z14.string())
541
717
  });
542
- var Select = z13.object({
718
+ var InlineRadio = z14.object({
543
719
  ...common,
544
- control: z13.literal("select"),
545
- type: z13.literal("string"),
546
- defaultValue: z13.string().optional(),
547
- options: z13.array(z13.string())
720
+ control: z14.literal("inline-radio"),
721
+ type: z14.literal("string"),
722
+ defaultValue: z14.string().optional(),
723
+ options: z14.array(z14.string())
548
724
  });
549
- var Check = z13.object({
725
+ var Select = z14.object({
550
726
  ...common,
551
- control: z13.literal("check"),
552
- type: z13.literal("string[]"),
553
- defaultValue: z13.array(z13.string()).optional(),
554
- options: z13.array(z13.string())
727
+ control: z14.literal("select"),
728
+ type: z14.literal("string"),
729
+ defaultValue: z14.string().optional(),
730
+ options: z14.array(z14.string())
555
731
  });
556
- var InlineCheck = z13.object({
732
+ var Check = z14.object({
557
733
  ...common,
558
- control: z13.literal("inline-check"),
559
- type: z13.literal("string[]"),
560
- defaultValue: z13.array(z13.string()).optional(),
561
- options: z13.array(z13.string())
734
+ control: z14.literal("check"),
735
+ type: z14.literal("string[]"),
736
+ defaultValue: z14.array(z14.string()).optional(),
737
+ options: z14.array(z14.string())
562
738
  });
563
- var MultiSelect = z13.object({
739
+ var InlineCheck = z14.object({
564
740
  ...common,
565
- control: z13.literal("multi-select"),
566
- type: z13.literal("string[]"),
567
- defaultValue: z13.array(z13.string()).optional(),
568
- options: z13.array(z13.string())
741
+ control: z14.literal("inline-check"),
742
+ type: z14.literal("string[]"),
743
+ defaultValue: z14.array(z14.string()).optional(),
744
+ options: z14.array(z14.string())
569
745
  });
570
- var File = z13.object({
746
+ var MultiSelect = z14.object({
571
747
  ...common,
572
- control: z13.literal("file"),
573
- type: z13.literal("string"),
574
- defaultValue: z13.string().optional(),
748
+ control: z14.literal("multi-select"),
749
+ type: z14.literal("string[]"),
750
+ defaultValue: z14.array(z14.string()).optional(),
751
+ options: z14.array(z14.string())
752
+ });
753
+ var File = z14.object({
754
+ ...common,
755
+ control: z14.literal("file"),
756
+ type: z14.literal("string"),
757
+ defaultValue: z14.string().optional(),
575
758
  /** https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#accept */
576
- accept: z13.string().optional()
759
+ accept: z14.string().optional()
577
760
  });
578
- var Url = z13.object({
761
+ var Url = z14.object({
579
762
  ...common,
580
- control: z13.literal("url"),
581
- type: z13.literal("string"),
582
- defaultValue: z13.string().optional()
763
+ control: z14.literal("url"),
764
+ type: z14.literal("string"),
765
+ defaultValue: z14.string().optional()
583
766
  });
584
- var Json = z13.object({
767
+ var Json = z14.object({
585
768
  ...common,
586
- control: z13.literal("json"),
587
- type: z13.literal("json"),
588
- defaultValue: z13.unknown().optional()
769
+ control: z14.literal("json"),
770
+ type: z14.literal("json"),
771
+ defaultValue: z14.unknown().optional()
589
772
  });
590
- var Date = z13.object({
773
+ var Date = z14.object({
591
774
  ...common,
592
- control: z13.literal("date"),
775
+ control: z14.literal("date"),
593
776
  // @todo not sure what type should be here
594
777
  // (we don't support Date yet, added for completeness)
595
- type: z13.literal("string"),
596
- defaultValue: z13.string().optional()
778
+ type: z14.literal("string"),
779
+ defaultValue: z14.string().optional()
597
780
  });
598
- var Action = z13.object({
781
+ var Action = z14.object({
599
782
  ...common,
600
- control: z13.literal("action"),
601
- type: z13.literal("action"),
602
- defaultValue: z13.undefined().optional()
783
+ control: z14.literal("action"),
784
+ type: z14.literal("action"),
785
+ defaultValue: z14.undefined().optional()
603
786
  });
604
- var TextContent = z13.object({
787
+ var TextContent = z14.object({
605
788
  ...common,
606
- control: z13.literal("textContent"),
607
- type: z13.literal("string"),
608
- defaultValue: z13.string().optional()
789
+ control: z14.literal("textContent"),
790
+ type: z14.literal("string"),
791
+ defaultValue: z14.string().optional()
609
792
  });
610
- var PropMeta = z13.union([
793
+ var AnimationAction = z14.object({
794
+ ...common,
795
+ control: z14.literal("animationAction"),
796
+ type: z14.literal("animationAction"),
797
+ defaultValue: z14.undefined().optional()
798
+ });
799
+ var PropMeta = z14.union([
611
800
  Number,
612
801
  Range,
613
802
  Text,
803
+ Resource2,
614
804
  Code,
615
805
  CodeText,
616
806
  Color,
@@ -626,104 +816,112 @@ var PropMeta = z13.union([
626
816
  Json,
627
817
  Date,
628
818
  Action,
629
- TextContent
819
+ TextContent,
820
+ AnimationAction
630
821
  ]);
631
822
 
632
823
  // src/schema/embed-template.ts
633
- import { z as z14 } from "zod";
634
- import { StyleValue as StyleValue2 } from "@webstudio-is/css-engine";
635
- var EmbedTemplateText = z14.object({
636
- type: z14.literal("text"),
637
- value: z14.string(),
638
- placeholder: z14.boolean().optional()
824
+ import { z as z15 } from "zod";
825
+ import { StyleValue as StyleValue3 } from "@webstudio-is/css-engine";
826
+ var EmbedTemplateText = z15.object({
827
+ type: z15.literal("text"),
828
+ value: z15.string(),
829
+ placeholder: z15.boolean().optional()
639
830
  });
640
- var EmbedTemplateExpression = z14.object({
641
- type: z14.literal("expression"),
642
- value: z14.string()
831
+ var EmbedTemplateExpression = z15.object({
832
+ type: z15.literal("expression"),
833
+ value: z15.string()
643
834
  });
644
- var EmbedTemplateVariable = z14.object({
645
- alias: z14.optional(z14.string()),
646
- initialValue: z14.unknown()
835
+ var EmbedTemplateVariable = z15.object({
836
+ alias: z15.optional(z15.string()),
837
+ initialValue: z15.unknown()
647
838
  });
648
- var EmbedTemplateProp = z14.union([
649
- z14.object({
650
- type: z14.literal("number"),
651
- name: z14.string(),
652
- value: z14.number()
839
+ var EmbedTemplateProp = z15.union([
840
+ z15.object({
841
+ type: z15.literal("number"),
842
+ name: z15.string(),
843
+ value: z15.number()
653
844
  }),
654
- z14.object({
655
- type: z14.literal("string"),
656
- name: z14.string(),
657
- value: z14.string()
845
+ z15.object({
846
+ type: z15.literal("string"),
847
+ name: z15.string(),
848
+ value: z15.string()
658
849
  }),
659
- z14.object({
660
- type: z14.literal("boolean"),
661
- name: z14.string(),
662
- value: z14.boolean()
850
+ z15.object({
851
+ type: z15.literal("boolean"),
852
+ name: z15.string(),
853
+ value: z15.boolean()
663
854
  }),
664
- z14.object({
665
- type: z14.literal("string[]"),
666
- name: z14.string(),
667
- value: z14.array(z14.string())
855
+ z15.object({
856
+ type: z15.literal("string[]"),
857
+ name: z15.string(),
858
+ value: z15.array(z15.string())
668
859
  }),
669
- z14.object({
670
- type: z14.literal("json"),
671
- name: z14.string(),
672
- value: z14.unknown()
860
+ z15.object({
861
+ type: z15.literal("json"),
862
+ name: z15.string(),
863
+ value: z15.unknown()
673
864
  }),
674
- z14.object({
675
- type: z14.literal("expression"),
676
- name: z14.string(),
677
- code: z14.string()
865
+ z15.object({
866
+ type: z15.literal("expression"),
867
+ name: z15.string(),
868
+ code: z15.string()
678
869
  }),
679
- z14.object({
680
- type: z14.literal("parameter"),
681
- name: z14.string(),
682
- variableName: z14.string(),
683
- variableAlias: z14.optional(z14.string())
870
+ z15.object({
871
+ type: z15.literal("parameter"),
872
+ name: z15.string(),
873
+ variableName: z15.string(),
874
+ variableAlias: z15.optional(z15.string())
684
875
  }),
685
- z14.object({
686
- type: z14.literal("action"),
687
- name: z14.string(),
688
- value: z14.array(
689
- z14.object({
690
- type: z14.literal("execute"),
691
- args: z14.optional(z14.array(z14.string())),
692
- code: z14.string()
876
+ z15.object({
877
+ type: z15.literal("action"),
878
+ name: z15.string(),
879
+ value: z15.array(
880
+ z15.object({
881
+ type: z15.literal("execute"),
882
+ args: z15.optional(z15.array(z15.string())),
883
+ code: z15.string()
693
884
  })
694
885
  )
695
886
  })
696
887
  ]);
697
- var EmbedTemplateStyleDeclRaw = z14.object({
888
+ var EmbedTemplateStyleDeclRaw = z15.object({
698
889
  // State selector, e.g. :hover
699
- state: z14.optional(z14.string()),
700
- property: z14.string(),
701
- value: StyleValue2
890
+ state: z15.optional(z15.string()),
891
+ property: z15.string(),
892
+ value: StyleValue3
702
893
  });
703
894
  var EmbedTemplateStyleDecl = EmbedTemplateStyleDeclRaw;
704
- var EmbedTemplateInstance = z14.lazy(
705
- () => z14.object({
706
- type: z14.literal("instance"),
707
- component: z14.string(),
708
- label: z14.optional(z14.string()),
709
- variables: z14.optional(z14.record(z14.string(), EmbedTemplateVariable)),
710
- props: z14.optional(z14.array(EmbedTemplateProp)),
711
- styles: z14.optional(z14.array(EmbedTemplateStyleDecl)),
895
+ var EmbedTemplateInstance = z15.lazy(
896
+ () => z15.object({
897
+ type: z15.literal("instance"),
898
+ component: z15.string(),
899
+ label: z15.optional(z15.string()),
900
+ variables: z15.optional(z15.record(z15.string(), EmbedTemplateVariable)),
901
+ props: z15.optional(z15.array(EmbedTemplateProp)),
902
+ styles: z15.optional(z15.array(EmbedTemplateStyleDecl)),
712
903
  children: WsEmbedTemplate
713
904
  })
714
905
  );
715
- var WsEmbedTemplate = z14.lazy(
716
- () => z14.array(
717
- z14.union([EmbedTemplateInstance, EmbedTemplateText, EmbedTemplateExpression])
906
+ var WsEmbedTemplate = z15.lazy(
907
+ () => z15.array(
908
+ z15.union([EmbedTemplateInstance, EmbedTemplateText, EmbedTemplateExpression])
718
909
  )
719
910
  );
720
911
 
721
912
  // src/schema/component-meta.ts
722
- import { z as z15 } from "zod";
723
- var WsComponentPropsMeta = z15.object({
724
- props: z15.record(PropMeta),
913
+ import { z as z16 } from "zod";
914
+ import { StyleValue as StyleValue4 } from "@webstudio-is/css-engine";
915
+ var PresetStyleDecl = z16.object({
916
+ // State selector, e.g. :hover
917
+ state: z16.optional(z16.string()),
918
+ property: z16.string(),
919
+ value: StyleValue4
920
+ });
921
+ var WsComponentPropsMeta = z16.object({
922
+ props: z16.record(PropMeta),
725
923
  // Props that will be always visible in properties panel.
726
- initialProps: z15.array(z15.string()).optional()
924
+ initialProps: z16.array(z16.string()).optional()
727
925
  });
728
926
  var componentCategories = [
729
927
  "general",
@@ -738,10 +936,10 @@ var componentCategories = [
738
936
  "internal"
739
937
  ];
740
938
  var stateCategories = ["states", "component-states"];
741
- var ComponentState = z15.object({
742
- category: z15.enum(stateCategories).optional(),
743
- selector: z15.string(),
744
- label: z15.string()
939
+ var ComponentState = z16.object({
940
+ category: z16.enum(stateCategories).optional(),
941
+ selector: z16.string(),
942
+ label: z16.string()
745
943
  });
746
944
  var defaultStates = [
747
945
  { selector: ":hover", label: "Hover" },
@@ -750,28 +948,30 @@ var defaultStates = [
750
948
  { selector: ":focus-visible", label: "Focus Visible" },
751
949
  { selector: ":focus-within", label: "Focus Within" }
752
950
  ];
753
- var WsComponentMeta = z15.object({
754
- category: z15.enum(componentCategories).optional(),
951
+ var WsComponentMeta = z16.object({
952
+ category: z16.enum(componentCategories).optional(),
755
953
  // container - can accept other components with dnd or be edited as text
756
954
  // control - usually form controls like inputs, without children
757
955
  // embed - images, videos or other embeddable components, without children
758
956
  // rich-text-child - formatted text fragment, not listed in components list
759
- type: z15.enum(["container", "control", "embed", "rich-text-child"]),
957
+ type: z16.enum(["container", "control", "embed", "rich-text-child"]),
958
+ /**
959
+ * a property used as textual placeholder when no content specified while in builder
960
+ * also signals to not insert components inside unless dropped explicitly
961
+ */
962
+ placeholder: z16.string().optional(),
760
963
  constraints: Matchers.optional(),
761
964
  // when this field is specified component receives
762
965
  // prop with index of same components withiin specified ancestor
763
966
  // important to automatically enumerate collections without
764
967
  // naming every item manually
765
- indexWithinAncestor: z15.optional(z15.string()),
766
- label: z15.optional(z15.string()),
767
- description: z15.string().optional(),
768
- icon: z15.string(),
769
- presetStyle: z15.optional(
770
- z15.record(z15.string(), z15.array(EmbedTemplateStyleDecl))
771
- ),
772
- states: z15.optional(z15.array(ComponentState)),
773
- template: z15.optional(WsEmbedTemplate),
774
- order: z15.number().optional()
968
+ indexWithinAncestor: z16.optional(z16.string()),
969
+ label: z16.optional(z16.string()),
970
+ description: z16.string().optional(),
971
+ icon: z16.string(),
972
+ presetStyle: z16.optional(z16.record(z16.string(), z16.array(PresetStyleDecl))),
973
+ states: z16.optional(z16.array(ComponentState)),
974
+ order: z16.number().optional()
775
975
  });
776
976
 
777
977
  // src/core-metas.ts
@@ -786,18 +986,18 @@ import {
786
986
  // src/__generated__/normalize.css.ts
787
987
  var html = [
788
988
  { property: "display", value: { type: "keyword", value: "grid" } },
789
- { property: "minHeight", value: { type: "unit", unit: "%", value: 100 } },
989
+ { property: "min-height", value: { type: "unit", unit: "%", value: 100 } },
790
990
  {
791
- property: "fontFamily",
991
+ property: "font-family",
792
992
  value: { type: "fontFamily", value: ["Arial", "Roboto", "sans-serif"] }
793
993
  },
794
- { property: "fontSize", value: { type: "unit", unit: "px", value: 16 } },
994
+ { property: "font-size", value: { type: "unit", unit: "px", value: 16 } },
795
995
  {
796
- property: "lineHeight",
996
+ property: "line-height",
797
997
  value: { type: "unit", unit: "number", value: 1.2 }
798
998
  },
799
999
  {
800
- property: "whiteSpaceCollapse",
1000
+ property: "white-space-collapse",
801
1001
  value: { type: "keyword", value: "preserve" }
802
1002
  }
803
1003
  ];
@@ -964,23 +1164,78 @@ var parseComponentName = (componentName) => {
964
1164
  }
965
1165
  return [namespace, name];
966
1166
  };
1167
+ var getIndexesWithinAncestors = (metas, instances, rootIds) => {
1168
+ const ancestors = /* @__PURE__ */ new Set();
1169
+ for (const meta of metas.values()) {
1170
+ if (meta.indexWithinAncestor !== void 0) {
1171
+ ancestors.add(meta.indexWithinAncestor);
1172
+ }
1173
+ }
1174
+ const indexes = /* @__PURE__ */ new Map();
1175
+ const traverseInstances2 = (instances2, instanceId, latestIndexes2 = /* @__PURE__ */ new Map()) => {
1176
+ const instance = instances2.get(instanceId);
1177
+ if (instance === void 0) {
1178
+ return;
1179
+ }
1180
+ const meta = metas.get(instance.component);
1181
+ if (ancestors.has(instance.component)) {
1182
+ latestIndexes2 = new Map(latestIndexes2);
1183
+ latestIndexes2.set(instance.component, /* @__PURE__ */ new Map());
1184
+ }
1185
+ if (instance.component === blockTemplateComponent) {
1186
+ latestIndexes2 = new Map(latestIndexes2);
1187
+ for (const key of latestIndexes2.keys()) {
1188
+ latestIndexes2.set(key, /* @__PURE__ */ new Map());
1189
+ }
1190
+ }
1191
+ if (meta?.indexWithinAncestor !== void 0) {
1192
+ const ancestorIndexes = latestIndexes2.get(meta.indexWithinAncestor);
1193
+ if (ancestorIndexes) {
1194
+ let index = ancestorIndexes.get(instance.component) ?? -1;
1195
+ index += 1;
1196
+ ancestorIndexes.set(instance.component, index);
1197
+ indexes.set(instance.id, index);
1198
+ }
1199
+ }
1200
+ for (const child of instance.children) {
1201
+ if (child.type === "id") {
1202
+ traverseInstances2(instances2, child.value, latestIndexes2);
1203
+ }
1204
+ }
1205
+ };
1206
+ const latestIndexes = /* @__PURE__ */ new Map();
1207
+ for (const instanceId of rootIds) {
1208
+ traverseInstances2(instances, instanceId, latestIndexes);
1209
+ }
1210
+ return indexes;
1211
+ };
967
1212
 
968
1213
  // src/expression.ts
969
- import { parseExpressionAt } from "acorn";
1214
+ import {
1215
+ parse,
1216
+ parseExpressionAt
1217
+ } from "acorn";
970
1218
  import { simple } from "acorn-walk";
1219
+ var SYSTEM_VARIABLE_ID = ":system";
1220
+ var systemParameter = {
1221
+ id: SYSTEM_VARIABLE_ID,
1222
+ scopeInstanceId: ROOT_INSTANCE_ID,
1223
+ type: "parameter",
1224
+ name: "system"
1225
+ };
971
1226
  var lintExpression = ({
972
1227
  expression,
973
1228
  availableVariables = /* @__PURE__ */ new Set(),
974
1229
  allowAssignment = false
975
1230
  }) => {
976
1231
  const diagnostics = [];
977
- const addError = (message) => {
1232
+ const addMessage = (message, severity = "error") => {
978
1233
  return (node) => {
979
1234
  diagnostics.push({
980
1235
  // tune error position after wrapping expression with parentheses
981
1236
  from: node.start - 1,
982
1237
  to: node.end - 1,
983
- severity: "error",
1238
+ severity,
984
1239
  message
985
1240
  });
986
1241
  };
@@ -995,7 +1250,7 @@ var lintExpression = ({
995
1250
  return diagnostics;
996
1251
  }
997
1252
  try {
998
- const root = parseExpressionAt(`(${expression})`, 0, {
1253
+ const root = parse(`(${expression})`, {
999
1254
  ecmaVersion: "latest",
1000
1255
  // support parsing import to forbid explicitly
1001
1256
  sourceType: "module"
@@ -1003,7 +1258,10 @@ var lintExpression = ({
1003
1258
  simple(root, {
1004
1259
  Identifier(node) {
1005
1260
  if (availableVariables.has(node.name) === false) {
1006
- addError(`"${node.name}" is not defined in the scope`)(node);
1261
+ addMessage(
1262
+ `"${node.name}" is not defined in the scope`,
1263
+ "warning"
1264
+ )(node);
1007
1265
  }
1008
1266
  },
1009
1267
  Literal() {
@@ -1030,13 +1288,16 @@ var lintExpression = ({
1030
1288
  },
1031
1289
  AssignmentExpression(node) {
1032
1290
  if (allowAssignment === false) {
1033
- addError("Assignment is supported only inside actions")(node);
1291
+ addMessage("Assignment is supported only inside actions")(node);
1034
1292
  return;
1035
1293
  }
1036
1294
  simple(node.left, {
1037
1295
  Identifier(node2) {
1038
1296
  if (availableVariables.has(node2.name) === false) {
1039
- addError(`"${node2.name}" is not defined in the scope`)(node2);
1297
+ addMessage(
1298
+ `"${node2.name}" is not defined in the scope`,
1299
+ "warning"
1300
+ )(node2);
1040
1301
  }
1041
1302
  }
1042
1303
  });
@@ -1044,18 +1305,18 @@ var lintExpression = ({
1044
1305
  // parser forbids to yield inside module
1045
1306
  YieldExpression() {
1046
1307
  },
1047
- ThisExpression: addError(`"this" keyword is not supported`),
1048
- FunctionExpression: addError("Functions are not supported"),
1049
- UpdateExpression: addError("Increment and decrement are not supported"),
1050
- CallExpression: addError("Functions are not supported"),
1051
- NewExpression: addError("Classes are not supported"),
1052
- SequenceExpression: addError(`Only single expression is supported`),
1053
- ArrowFunctionExpression: addError("Functions are not supported"),
1054
- TaggedTemplateExpression: addError("Tagged template is not supported"),
1055
- ClassExpression: addError("Classes are not supported"),
1056
- MetaProperty: addError("Imports are not supported"),
1057
- AwaitExpression: addError(`"await" keyword is not supported`),
1058
- ImportExpression: addError("Imports are not supported")
1308
+ ThisExpression: addMessage(`"this" keyword is not supported`),
1309
+ FunctionExpression: addMessage("Functions are not supported"),
1310
+ UpdateExpression: addMessage("Increment and decrement are not supported"),
1311
+ CallExpression: addMessage("Functions are not supported"),
1312
+ NewExpression: addMessage("Classes are not supported"),
1313
+ SequenceExpression: addMessage(`Only single expression is supported`),
1314
+ ArrowFunctionExpression: addMessage("Functions are not supported"),
1315
+ TaggedTemplateExpression: addMessage("Tagged template is not supported"),
1316
+ ClassExpression: addMessage("Classes are not supported"),
1317
+ MetaProperty: addMessage("Imports are not supported"),
1318
+ AwaitExpression: addMessage(`"await" keyword is not supported`),
1319
+ ImportExpression: addMessage("Imports are not supported")
1059
1320
  });
1060
1321
  } catch (error) {
1061
1322
  const castedError = error;
@@ -1072,6 +1333,9 @@ var lintExpression = ({
1072
1333
  return diagnostics;
1073
1334
  };
1074
1335
  var isLiteralNode = (node) => {
1336
+ if (node.type === "Identifier" && node.name === "undefined") {
1337
+ return true;
1338
+ }
1075
1339
  if (node.type === "Literal") {
1076
1340
  return true;
1077
1341
  }
@@ -1213,11 +1477,17 @@ var generateObjectExpression = (map) => {
1213
1477
  return generated;
1214
1478
  };
1215
1479
  var dataSourceVariablePrefix = "$ws$dataSource$";
1216
- var encodeDataSourceVariable = (id) => {
1480
+ var encodeDataVariableId = (id) => {
1481
+ if (id === SYSTEM_VARIABLE_ID) {
1482
+ return "$ws$system";
1483
+ }
1217
1484
  const encoded = id.replaceAll("-", "__DASH__");
1218
1485
  return `${dataSourceVariablePrefix}${encoded}`;
1219
1486
  };
1220
- var decodeDataSourceVariable = (name) => {
1487
+ var decodeDataVariableId = (name) => {
1488
+ if (name === "$ws$system") {
1489
+ return SYSTEM_VARIABLE_ID;
1490
+ }
1221
1491
  if (name.startsWith(dataSourceVariablePrefix)) {
1222
1492
  const encoded = name.slice(dataSourceVariablePrefix.length);
1223
1493
  return encoded.replaceAll("__DASH__", "-");
@@ -1234,12 +1504,16 @@ var generateExpression = ({
1234
1504
  expression,
1235
1505
  executable: true,
1236
1506
  replaceVariable: (identifier) => {
1237
- const depId = decodeDataSourceVariable(identifier);
1238
- const dep = depId ? dataSources.get(depId) : void 0;
1507
+ const depId = decodeDataVariableId(identifier);
1508
+ let dep = depId ? dataSources.get(depId) : void 0;
1509
+ if (depId === SYSTEM_VARIABLE_ID) {
1510
+ dep = systemParameter;
1511
+ }
1239
1512
  if (dep) {
1240
1513
  usedDataSources?.set(dep.id, dep);
1241
1514
  return scope.getName(dep.id, dep.name);
1242
1515
  }
1516
+ return "undefined";
1243
1517
  }
1244
1518
  });
1245
1519
  };
@@ -1426,12 +1700,11 @@ var generateResources = ({
1426
1700
  `;
1427
1701
  }
1428
1702
  if (dataSource.type === "parameter") {
1429
- if (dataSource.id !== page.systemDataSourceId) {
1430
- continue;
1431
- }
1432
- const name = scope.getName(dataSource.id, dataSource.name);
1433
- generatedVariables += ` const ${name} = _props.system
1703
+ if (dataSource.id === page.systemDataSourceId || dataSource.id === SYSTEM_VARIABLE_ID) {
1704
+ const name = scope.getName(dataSource.id, dataSource.name);
1705
+ generatedVariables += ` const ${name} = _props.system
1434
1706
  `;
1707
+ }
1435
1708
  }
1436
1709
  }
1437
1710
  let generated = "";
@@ -1520,7 +1793,9 @@ var replaceFormActionsWithResources = ({
1520
1793
  name: "action",
1521
1794
  method: getMethod(method),
1522
1795
  url: JSON.stringify(action),
1523
- headers: []
1796
+ headers: [
1797
+ { name: "Content-Type", value: JSON.stringify("application/json") }
1798
+ ]
1524
1799
  });
1525
1800
  }
1526
1801
  }
@@ -1628,7 +1903,7 @@ var generatePageMeta = ({
1628
1903
  continue;
1629
1904
  }
1630
1905
  if (dataSource.type === "parameter") {
1631
- if (dataSource.id === page.systemDataSourceId) {
1906
+ if (dataSource.id === page.systemDataSourceId || dataSource.id === SYSTEM_VARIABLE_ID) {
1632
1907
  const valueName = localScope.getName(dataSource.id, dataSource.name);
1633
1908
  generated += ` let ${valueName} = system
1634
1909
  `;
@@ -1672,6 +1947,182 @@ var generatePageMeta = ({
1672
1947
  `;
1673
1948
  return generated;
1674
1949
  };
1950
+
1951
+ // src/css.ts
1952
+ import { kebabCase } from "change-case";
1953
+ import {
1954
+ createRegularStyleSheet,
1955
+ generateAtomic
1956
+ } from "@webstudio-is/css-engine";
1957
+ import { getFontFaces } from "@webstudio-is/fonts";
1958
+ var addFontRules = ({
1959
+ sheet,
1960
+ assets,
1961
+ assetBaseUrl
1962
+ }) => {
1963
+ const fontAssets = [];
1964
+ for (const asset of assets.values()) {
1965
+ if (asset.type === "font") {
1966
+ fontAssets.push(asset);
1967
+ }
1968
+ }
1969
+ const fontFaces = getFontFaces(fontAssets, { assetBaseUrl });
1970
+ for (const fontFace of fontFaces) {
1971
+ sheet.addFontFaceRule(fontFace);
1972
+ }
1973
+ };
1974
+ var createImageValueTransformer = (assets, { assetBaseUrl }) => (styleValue) => {
1975
+ if (styleValue.type === "image" && styleValue.value.type === "asset") {
1976
+ const asset = assets.get(styleValue.value.value);
1977
+ if (asset === void 0) {
1978
+ return { type: "keyword", value: "none" };
1979
+ }
1980
+ const url = `${assetBaseUrl}${asset.name}`;
1981
+ return {
1982
+ type: "image",
1983
+ value: {
1984
+ type: "url",
1985
+ url
1986
+ },
1987
+ hidden: styleValue.hidden
1988
+ };
1989
+ }
1990
+ };
1991
+ var normalizeClassName = (name) => kebabCase(name);
1992
+ var generateCss = ({
1993
+ assets,
1994
+ instances,
1995
+ props,
1996
+ breakpoints,
1997
+ styles,
1998
+ styleSourceSelections,
1999
+ componentMetas,
2000
+ assetBaseUrl,
2001
+ atomic
2002
+ }) => {
2003
+ const fontSheet = createRegularStyleSheet({ name: "ssr" });
2004
+ const presetSheet = createRegularStyleSheet({ name: "ssr" });
2005
+ const userSheet = createRegularStyleSheet({ name: "ssr" });
2006
+ addFontRules({ sheet: fontSheet, assets, assetBaseUrl });
2007
+ presetSheet.addMediaRule("presets");
2008
+ const presetClasses = /* @__PURE__ */ new Map();
2009
+ const scope = createScope([], normalizeClassName, "-");
2010
+ for (const [component, meta] of componentMetas) {
2011
+ const [_namespace, componentName] = parseComponentName(component);
2012
+ const className = `w-${scope.getName(component, meta.label ?? componentName)}`;
2013
+ const presetStyle = Object.entries(meta.presetStyle ?? {});
2014
+ if (presetStyle.length > 0) {
2015
+ presetClasses.set(component, className);
2016
+ }
2017
+ for (const [tag, styles2] of presetStyle) {
2018
+ const selector = component === rootComponent ? ":root" : `${tag}.${className}`;
2019
+ const rule = presetSheet.addNestingRule(selector);
2020
+ for (const declaration of styles2) {
2021
+ rule.setDeclaration({
2022
+ breakpoint: "presets",
2023
+ selector: declaration.state ?? "",
2024
+ property: declaration.property,
2025
+ value: declaration.value
2026
+ });
2027
+ }
2028
+ }
2029
+ }
2030
+ for (const breakpoint of breakpoints.values()) {
2031
+ userSheet.addMediaRule(breakpoint.id, breakpoint);
2032
+ }
2033
+ const imageValueTransformer = createImageValueTransformer(assets, {
2034
+ assetBaseUrl
2035
+ });
2036
+ userSheet.setTransformer(imageValueTransformer);
2037
+ for (const styleDecl of styles.values()) {
2038
+ const rule = userSheet.addMixinRule(styleDecl.styleSourceId);
2039
+ rule.setDeclaration({
2040
+ breakpoint: styleDecl.breakpointId,
2041
+ selector: styleDecl.state ?? "",
2042
+ property: styleDecl.property,
2043
+ value: styleDecl.value
2044
+ });
2045
+ }
2046
+ const classes = /* @__PURE__ */ new Map();
2047
+ const parentIdByInstanceId = /* @__PURE__ */ new Map();
2048
+ for (const instance of instances.values()) {
2049
+ const presetClass = presetClasses.get(instance.component);
2050
+ if (presetClass) {
2051
+ classes.set(instance.id, [presetClass]);
2052
+ }
2053
+ for (const child of instance.children) {
2054
+ if (child.type === "id") {
2055
+ parentIdByInstanceId.set(child.value, instance.id);
2056
+ }
2057
+ }
2058
+ }
2059
+ const descendantSelectorByInstanceId = /* @__PURE__ */ new Map();
2060
+ for (const prop of props.values()) {
2061
+ if (prop.name === "selector" && prop.type === "string") {
2062
+ descendantSelectorByInstanceId.set(prop.instanceId, prop.value);
2063
+ }
2064
+ }
2065
+ const instanceByRule = /* @__PURE__ */ new Map();
2066
+ for (const selection of styleSourceSelections.values()) {
2067
+ let { instanceId } = selection;
2068
+ const { values } = selection;
2069
+ if (instanceId === ROOT_INSTANCE_ID) {
2070
+ const rule2 = userSheet.addNestingRule(`:root`);
2071
+ rule2.applyMixins(values);
2072
+ continue;
2073
+ }
2074
+ let descendantSuffix = "";
2075
+ const instance = instances.get(instanceId);
2076
+ if (instance === void 0) {
2077
+ continue;
2078
+ }
2079
+ if (instance.component === descendantComponent) {
2080
+ const parentId = parentIdByInstanceId.get(instanceId);
2081
+ const descendantSelector = descendantSelectorByInstanceId.get(instanceId);
2082
+ if (parentId && descendantSelector) {
2083
+ descendantSuffix = descendantSelector;
2084
+ instanceId = parentId;
2085
+ }
2086
+ }
2087
+ const meta = componentMetas.get(instance.component);
2088
+ const [_namespace, shortName] = parseComponentName(instance.component);
2089
+ const baseName = instance.label ?? meta?.label ?? shortName;
2090
+ const className = `w-${scope.getName(instanceId, baseName)}`;
2091
+ if (atomic === false) {
2092
+ let classList = classes.get(instanceId);
2093
+ if (classList === void 0) {
2094
+ classList = [];
2095
+ classes.set(instanceId, classList);
2096
+ }
2097
+ classList.push(className);
2098
+ }
2099
+ const rule = userSheet.addNestingRule(`.${className}`, descendantSuffix);
2100
+ rule.applyMixins(values);
2101
+ instanceByRule.set(rule, instanceId);
2102
+ }
2103
+ const fontCss = fontSheet.cssText;
2104
+ const presetCss = presetSheet.cssText.replaceAll(
2105
+ "@media all ",
2106
+ "@layer presets "
2107
+ );
2108
+ if (atomic) {
2109
+ const { cssText } = generateAtomic(userSheet, {
2110
+ getKey: (rule) => instanceByRule.get(rule),
2111
+ transformValue: imageValueTransformer,
2112
+ classes
2113
+ });
2114
+ return {
2115
+ cssText: `${fontCss}${presetCss}
2116
+ ${cssText}`,
2117
+ classes
2118
+ };
2119
+ }
2120
+ return {
2121
+ cssText: `${fontCss}${presetCss}
2122
+ ${userSheet.cssText}`,
2123
+ classes
2124
+ };
2125
+ };
1675
2126
  export {
1676
2127
  Asset,
1677
2128
  Assets,
@@ -1707,15 +2158,18 @@ export {
1707
2158
  PageRedirect,
1708
2159
  PageTitle,
1709
2160
  Pages,
2161
+ PresetStyleDecl,
1710
2162
  ProjectNewRedirectPath,
1711
2163
  Prop,
1712
2164
  PropMeta,
1713
2165
  Props,
2166
+ RANGE_UNITS,
1714
2167
  ROOT_FOLDER_ID,
1715
2168
  ROOT_INSTANCE_ID,
1716
2169
  Resource,
1717
2170
  ResourceRequest,
1718
2171
  Resources,
2172
+ SYSTEM_VARIABLE_ID,
1719
2173
  StyleDecl,
1720
2174
  StyleSource,
1721
2175
  StyleSourceSelection,
@@ -1727,6 +2181,9 @@ export {
1727
2181
  WebstudioFragment,
1728
2182
  WsComponentMeta,
1729
2183
  WsEmbedTemplate,
2184
+ addFontRules,
2185
+ animationActionSchema,
2186
+ animationKeyframeSchema,
1730
2187
  blockComponent,
1731
2188
  blockTemplateComponent,
1732
2189
  blockTemplateMeta,
@@ -1734,26 +2191,32 @@ export {
1734
2191
  componentCategories,
1735
2192
  coreMetas,
1736
2193
  corePropsMetas,
2194
+ createImageValueTransformer,
1737
2195
  createScope,
1738
- decodeDataSourceVariable,
2196
+ decodeDataVariableId as decodeDataSourceVariable,
2197
+ decodeDataVariableId,
1739
2198
  defaultStates,
1740
2199
  descendantComponent,
1741
2200
  documentTypes,
1742
- encodeDataSourceVariable,
2201
+ encodeDataVariableId as encodeDataSourceVariable,
2202
+ encodeDataVariableId,
1743
2203
  executeExpression,
1744
2204
  findPageByIdOrPath,
1745
2205
  findParentFolderByChildId,
1746
2206
  findTreeInstanceIds,
1747
2207
  findTreeInstanceIdsExcludingSlotDescendants,
2208
+ generateCss,
1748
2209
  generateExpression,
1749
2210
  generateObjectExpression,
1750
2211
  generatePageMeta,
1751
2212
  generateResources,
1752
2213
  getExpressionIdentifiers,
2214
+ getIndexesWithinAncestors,
1753
2215
  getPagePath,
1754
2216
  getStaticSiteMapXml,
1755
2217
  getStyleDeclKey,
1756
2218
  initialBreakpoints,
2219
+ insetUnitValueSchema,
1757
2220
  isCoreComponent,
1758
2221
  isLiteralExpression,
1759
2222
  isPathnamePattern,
@@ -1763,8 +2226,12 @@ export {
1763
2226
  parseComponentName,
1764
2227
  parseObjectExpression,
1765
2228
  portalComponent,
2229
+ rangeUnitValueSchema,
1766
2230
  replaceFormActionsWithResources,
1767
2231
  rootComponent,
2232
+ scrollAnimationSchema,
1768
2233
  stateCategories,
1769
- transpileExpression
2234
+ systemParameter,
2235
+ transpileExpression,
2236
+ viewAnimationSchema
1770
2237
  };