@webstudio-is/sdk 0.0.0-017f1bd

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/LICENSE +661 -0
  2. package/lib/__generated__/normalize.css.js +593 -0
  3. package/lib/core-templates.js +1267 -0
  4. package/lib/index.js +2918 -0
  5. package/lib/runtime.js +117 -0
  6. package/lib/types/__generated__/normalize.css.d.ts +57 -0
  7. package/lib/types/__generated__/tags.d.ts +1 -0
  8. package/lib/types/core-metas.d.ts +20 -0
  9. package/lib/types/core-templates.d.ts +9 -0
  10. package/lib/types/css.d.ts +31 -0
  11. package/lib/types/css.test.d.ts +1 -0
  12. package/lib/types/expression.d.ts +60 -0
  13. package/lib/types/expression.test.d.ts +1 -0
  14. package/lib/types/form-fields.d.ts +8 -0
  15. package/lib/types/index.d.ts +26 -0
  16. package/lib/types/instances-utils.d.ts +8 -0
  17. package/lib/types/instances-utils.test.d.ts +1 -0
  18. package/lib/types/page-meta-generator.d.ts +24 -0
  19. package/lib/types/page-meta-generator.test.d.ts +1 -0
  20. package/lib/types/page-utils.d.ts +24 -0
  21. package/lib/types/page-utils.test.d.ts +1 -0
  22. package/lib/types/resource-loader.d.ts +30 -0
  23. package/lib/types/resource-loader.test.d.ts +1 -0
  24. package/lib/types/resources-generator.d.ts +22 -0
  25. package/lib/types/resources-generator.test.d.ts +1 -0
  26. package/lib/types/runtime.d.ts +8 -0
  27. package/lib/types/schema/animation-schema.d.ts +53844 -0
  28. package/lib/types/schema/assets.d.ts +455 -0
  29. package/lib/types/schema/breakpoints.d.ts +56 -0
  30. package/lib/types/schema/component-meta.d.ts +12262 -0
  31. package/lib/types/schema/data-sources.d.ts +303 -0
  32. package/lib/types/schema/deployment.d.ts +41 -0
  33. package/lib/types/schema/instances.d.ts +214 -0
  34. package/lib/types/schema/pages.d.ts +676 -0
  35. package/lib/types/schema/prop-meta.d.ts +500 -0
  36. package/lib/types/schema/props.d.ts +37387 -0
  37. package/lib/types/schema/resources.d.ts +121 -0
  38. package/lib/types/schema/style-source-selections.d.ts +23 -0
  39. package/lib/types/schema/style-sources.d.ts +62 -0
  40. package/lib/types/schema/styles.d.ts +6293 -0
  41. package/lib/types/schema/webstudio.d.ts +24734 -0
  42. package/lib/types/scope.d.ts +16 -0
  43. package/lib/types/scope.test.d.ts +1 -0
  44. package/lib/types/to-string.d.ts +2 -0
  45. package/lib/types/url-pattern.d.ts +2 -0
  46. package/lib/types/url-pattern.test.d.ts +1 -0
  47. package/package.json +61 -0
package/lib/index.js ADDED
@@ -0,0 +1,2918 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/schema/assets.ts
8
+ import { z } from "zod";
9
+ import { FontFormat, FontMeta } from "@webstudio-is/fonts";
10
+ var AssetId = z.string();
11
+ var baseAsset = {
12
+ id: AssetId,
13
+ projectId: z.string(),
14
+ size: z.number(),
15
+ name: z.string(),
16
+ description: z.union([z.string(), z.null()]),
17
+ createdAt: z.string()
18
+ };
19
+ var FontAsset = z.object({
20
+ ...baseAsset,
21
+ format: FontFormat,
22
+ meta: FontMeta,
23
+ type: z.literal("font")
24
+ });
25
+ var ImageMeta = z.object({
26
+ width: z.number(),
27
+ height: z.number()
28
+ });
29
+ var ImageAsset = z.object({
30
+ ...baseAsset,
31
+ format: z.string(),
32
+ meta: ImageMeta,
33
+ type: z.literal("image")
34
+ });
35
+ var Asset = z.union([FontAsset, ImageAsset]);
36
+ var Assets = z.map(AssetId, Asset);
37
+
38
+ // src/schema/pages.ts
39
+ import { z as z2 } from "zod";
40
+ var MIN_TITLE_LENGTH = 2;
41
+ var PageId = z2.string();
42
+ var FolderId = z2.string();
43
+ var FolderName = z2.string().refine((value) => value.trim() !== "", "Can't be empty");
44
+ var Slug = z2.string().refine(
45
+ (path) => /^[-a-z0-9]*$/.test(path),
46
+ "Only a-z, 0-9 and - are allowed"
47
+ );
48
+ var Folder = z2.object({
49
+ id: FolderId,
50
+ name: FolderName,
51
+ slug: Slug,
52
+ children: z2.array(z2.union([FolderId, PageId]))
53
+ });
54
+ var PageName = z2.string().refine((value) => value.trim() !== "", "Can't be empty");
55
+ var PageTitle = z2.string().refine(
56
+ (val) => val.length >= MIN_TITLE_LENGTH,
57
+ `Minimum ${MIN_TITLE_LENGTH} characters required`
58
+ );
59
+ var documentTypes = ["html", "xml"];
60
+ var commonPageFields = {
61
+ id: PageId,
62
+ name: PageName,
63
+ title: PageTitle,
64
+ history: z2.optional(z2.array(z2.string())),
65
+ rootInstanceId: z2.string(),
66
+ systemDataSourceId: z2.string().optional(),
67
+ meta: z2.object({
68
+ description: z2.string().optional(),
69
+ title: z2.string().optional(),
70
+ excludePageFromSearch: z2.string().optional(),
71
+ language: z2.string().optional(),
72
+ socialImageAssetId: z2.string().optional(),
73
+ socialImageUrl: z2.string().optional(),
74
+ status: z2.string().optional(),
75
+ redirect: z2.string().optional(),
76
+ documentType: z2.optional(z2.enum(documentTypes)),
77
+ custom: z2.array(
78
+ z2.object({
79
+ property: z2.string(),
80
+ content: z2.string()
81
+ })
82
+ ).optional()
83
+ }),
84
+ marketplace: z2.optional(
85
+ z2.object({
86
+ include: z2.optional(z2.boolean()),
87
+ category: z2.optional(z2.string()),
88
+ thumbnailAssetId: z2.optional(z2.string())
89
+ })
90
+ )
91
+ };
92
+ var HomePagePath = z2.string().refine((path) => path === "", "Home page path must be empty");
93
+ var HomePage = z2.object({
94
+ ...commonPageFields,
95
+ path: HomePagePath
96
+ });
97
+ var DefaultPagePage = z2.string().refine((path) => path !== "", "Can't be empty").refine((path) => path !== "/", "Can't be just a /").refine((path) => path.endsWith("/") === false, "Can't end with a /").refine((path) => path.includes("//") === false, "Can't contain repeating /").refine(
98
+ (path) => /^[-_a-z0-9*:?\\/.]*$/.test(path),
99
+ "Only a-z, 0-9, -, _, /, :, ?, . and * are allowed"
100
+ ).refine(
101
+ // We use /s for our system stuff like /s/css or /s/uploads
102
+ (path) => path !== "/s" && path.startsWith("/s/") === false,
103
+ "/s prefix is reserved for the system"
104
+ ).refine(
105
+ // Remix serves build artefacts like JS bundles from /build
106
+ // And we cannot customize it due to bug in Remix: https://github.com/remix-run/remix/issues/2933
107
+ (path) => path !== "/build" && path.startsWith("/build/") === false,
108
+ "/build prefix is reserved for the system"
109
+ );
110
+ var OldPagePath = z2.string().refine((path) => path !== "", "Can't be empty").refine((path) => path !== "/", "Can't be just a /").refine(
111
+ (path) => path === "" || path.startsWith("/"),
112
+ "Must start with a / or a full URL e.g. https://website.org"
113
+ ).refine((path) => path.endsWith("/") === false, "Can't end with a /").refine((path) => path.includes("//") === false, "Can't contain repeating /").refine(
114
+ (path) => /^[-_a-zA-Z0-9*:?\\/.]*$/.test(path),
115
+ // Allow uppercase letters (A-Z)
116
+ "Only a-z, A-Z, 0-9, -, _, /, :, ?, . and * are allowed"
117
+ ).refine(
118
+ (path) => path !== "/s" && path.startsWith("/s/") === false,
119
+ "/s prefix is reserved for the system"
120
+ ).refine(
121
+ (path) => path !== "/build" && path.startsWith("/build/") === false,
122
+ "/build prefix is reserved for the system"
123
+ );
124
+ var PagePath = DefaultPagePage.refine(
125
+ (path) => path === "" || path.startsWith("/"),
126
+ "Must start with a / or a full URL e.g. https://website.org"
127
+ );
128
+ var Page = z2.object({
129
+ ...commonPageFields,
130
+ path: PagePath
131
+ });
132
+ var ProjectMeta = z2.object({
133
+ // All fields are optional to ensure consistency and allow for the addition of new fields without requiring migration
134
+ siteName: z2.string().optional(),
135
+ contactEmail: z2.string().optional(),
136
+ faviconAssetId: z2.string().optional(),
137
+ code: z2.string().optional()
138
+ });
139
+ var ProjectNewRedirectPath = z2.string().refine((data) => {
140
+ try {
141
+ new URL(data, "http://url.com");
142
+ return true;
143
+ } catch {
144
+ return false;
145
+ }
146
+ }, "Must be a valid URL");
147
+ var PageRedirect = z2.object({
148
+ old: OldPagePath,
149
+ new: ProjectNewRedirectPath,
150
+ status: z2.enum(["301", "302"]).optional()
151
+ });
152
+ var CompilerSettings = z2.object({
153
+ // All fields are optional to ensure consistency and allow for the addition of new fields without requiring migration
154
+ atomicStyles: z2.boolean().optional()
155
+ });
156
+ var Pages = z2.object({
157
+ meta: ProjectMeta.optional(),
158
+ compiler: CompilerSettings.optional(),
159
+ redirects: z2.array(PageRedirect).optional(),
160
+ homePage: HomePage,
161
+ pages: z2.array(Page),
162
+ folders: z2.array(Folder).refine((folders) => folders.length > 0, "Folders can't be empty")
163
+ });
164
+
165
+ // src/schema/instances.ts
166
+ import { z as z3 } from "zod";
167
+ var TextChild = z3.object({
168
+ type: z3.literal("text"),
169
+ value: z3.string(),
170
+ placeholder: z3.boolean().optional()
171
+ });
172
+ var InstanceId = z3.string();
173
+ var IdChild = z3.object({
174
+ type: z3.literal("id"),
175
+ value: InstanceId
176
+ });
177
+ var ExpressionChild = z3.object({
178
+ type: z3.literal("expression"),
179
+ value: z3.string()
180
+ });
181
+ var InstanceChild = z3.union([IdChild, TextChild, ExpressionChild]);
182
+ var Instance = z3.object({
183
+ type: z3.literal("instance"),
184
+ id: InstanceId,
185
+ component: z3.string(),
186
+ tag: z3.string().optional(),
187
+ label: z3.string().optional(),
188
+ children: z3.array(InstanceChild)
189
+ });
190
+ var Instances = z3.map(InstanceId, Instance);
191
+
192
+ // src/schema/data-sources.ts
193
+ import { z as z4 } from "zod";
194
+ var DataSourceId = z4.string();
195
+ var DataSourceVariableValue = z4.union([
196
+ z4.object({
197
+ type: z4.literal("number"),
198
+ // initial value of variable store
199
+ value: z4.number()
200
+ }),
201
+ z4.object({
202
+ type: z4.literal("string"),
203
+ value: z4.string()
204
+ }),
205
+ z4.object({
206
+ type: z4.literal("boolean"),
207
+ value: z4.boolean()
208
+ }),
209
+ z4.object({
210
+ type: z4.literal("string[]"),
211
+ value: z4.array(z4.string())
212
+ }),
213
+ z4.object({
214
+ type: z4.literal("json"),
215
+ value: z4.unknown()
216
+ })
217
+ ]);
218
+ var DataSource = z4.union([
219
+ z4.object({
220
+ type: z4.literal("variable"),
221
+ id: DataSourceId,
222
+ // The instance should always be specified for variables,
223
+ // however, there was a bug in the embed template
224
+ // which produced variables without an instance
225
+ // and these variables will fail validation
226
+ // if we make it required
227
+ scopeInstanceId: z4.string().optional(),
228
+ name: z4.string(),
229
+ value: DataSourceVariableValue
230
+ }),
231
+ z4.object({
232
+ type: z4.literal("parameter"),
233
+ id: DataSourceId,
234
+ scopeInstanceId: z4.string().optional(),
235
+ name: z4.string()
236
+ }),
237
+ z4.object({
238
+ type: z4.literal("resource"),
239
+ id: DataSourceId,
240
+ scopeInstanceId: z4.string().optional(),
241
+ name: z4.string(),
242
+ resourceId: z4.string()
243
+ })
244
+ ]);
245
+ var DataSources = z4.map(DataSourceId, DataSource);
246
+
247
+ // src/schema/resources.ts
248
+ import { z as z5 } from "zod";
249
+ var ResourceId = z5.string();
250
+ var Method = z5.union([
251
+ z5.literal("get"),
252
+ z5.literal("post"),
253
+ z5.literal("put"),
254
+ z5.literal("delete")
255
+ ]);
256
+ var Header = z5.object({
257
+ name: z5.string(),
258
+ // expression
259
+ value: z5.string()
260
+ });
261
+ var Resource = z5.object({
262
+ id: ResourceId,
263
+ name: z5.string(),
264
+ control: z5.optional(z5.union([z5.literal("system"), z5.literal("graphql")])),
265
+ method: Method,
266
+ // expression
267
+ url: z5.string(),
268
+ headers: z5.array(Header),
269
+ // expression
270
+ body: z5.optional(z5.string())
271
+ });
272
+ var ResourceRequest = z5.object({
273
+ id: ResourceId,
274
+ name: z5.string(),
275
+ method: Method,
276
+ url: z5.string(),
277
+ headers: z5.array(Header),
278
+ body: z5.optional(z5.unknown())
279
+ });
280
+ var Resources = z5.map(ResourceId, Resource);
281
+
282
+ // src/schema/props.ts
283
+ import { z as z7 } from "zod";
284
+
285
+ // src/schema/animation-schema.ts
286
+ import { StyleValue } from "@webstudio-is/css-engine";
287
+ import { z as z6 } from "zod";
288
+ var literalUnion = (arr) => z6.union(
289
+ arr.map((val) => z6.literal(val))
290
+ );
291
+ var RANGE_UNITS = [
292
+ "%",
293
+ "px",
294
+ "cm",
295
+ "mm",
296
+ "q",
297
+ "in",
298
+ "pt",
299
+ "pc",
300
+ "em",
301
+ "rem",
302
+ "ex",
303
+ "rex",
304
+ "cap",
305
+ "rcap",
306
+ "ch",
307
+ "rch",
308
+ "lh",
309
+ "rlh",
310
+ "vw",
311
+ "svw",
312
+ "lvw",
313
+ "dvw",
314
+ "vh",
315
+ "svh",
316
+ "lvh",
317
+ "dvh",
318
+ "vi",
319
+ "svi",
320
+ "lvi",
321
+ "dvi",
322
+ "vb",
323
+ "svb",
324
+ "lvb",
325
+ "dvb",
326
+ "vmin",
327
+ "svmin",
328
+ "lvmin",
329
+ "dvmin",
330
+ "vmax",
331
+ "svmax",
332
+ "lvmax",
333
+ "dvmax"
334
+ ];
335
+ var rangeUnitSchema = literalUnion(RANGE_UNITS);
336
+ var rangeUnitValueSchema = z6.union([
337
+ z6.object({
338
+ type: z6.literal("unit"),
339
+ value: z6.number(),
340
+ unit: rangeUnitSchema
341
+ }),
342
+ z6.object({
343
+ type: z6.literal("unparsed"),
344
+ value: z6.string()
345
+ }),
346
+ z6.object({
347
+ type: z6.literal("var"),
348
+ value: z6.string()
349
+ })
350
+ ]);
351
+ var TIME_UNITS = ["ms", "s"];
352
+ var timeUnitSchema = literalUnion(TIME_UNITS);
353
+ var durationUnitValueSchema = z6.union([
354
+ z6.object({
355
+ type: z6.literal("unit"),
356
+ value: z6.number(),
357
+ unit: timeUnitSchema
358
+ }),
359
+ z6.object({
360
+ type: z6.literal("var"),
361
+ value: z6.string()
362
+ })
363
+ ]);
364
+ var insetUnitValueSchema = z6.union([
365
+ rangeUnitValueSchema,
366
+ z6.object({
367
+ type: z6.literal("keyword"),
368
+ value: z6.literal("auto")
369
+ })
370
+ ]);
371
+ var keyframeStylesSchema = z6.record(StyleValue);
372
+ var animationKeyframeSchema = z6.object({
373
+ offset: z6.number().optional(),
374
+ styles: keyframeStylesSchema
375
+ });
376
+ var keyframeEffectOptionsSchema = z6.object({
377
+ easing: z6.string().optional(),
378
+ fill: z6.union([
379
+ z6.literal("none"),
380
+ z6.literal("forwards"),
381
+ z6.literal("backwards"),
382
+ z6.literal("both")
383
+ ]).optional(),
384
+ // FillMode
385
+ duration: durationUnitValueSchema.optional()
386
+ });
387
+ var scrollNamedRangeSchema = z6.union([
388
+ z6.literal("start"),
389
+ z6.literal("end")
390
+ ]);
391
+ var scrollRangeValueSchema = z6.tuple([
392
+ scrollNamedRangeSchema,
393
+ rangeUnitValueSchema
394
+ ]);
395
+ var scrollRangeOptionsSchema = z6.object({
396
+ rangeStart: scrollRangeValueSchema.optional(),
397
+ rangeEnd: scrollRangeValueSchema.optional()
398
+ });
399
+ var animationAxisSchema = z6.union([
400
+ z6.literal("block"),
401
+ z6.literal("inline"),
402
+ z6.literal("x"),
403
+ z6.literal("y")
404
+ ]);
405
+ var viewNamedRangeSchema = z6.union([
406
+ z6.literal("contain"),
407
+ z6.literal("cover"),
408
+ z6.literal("entry"),
409
+ z6.literal("exit"),
410
+ z6.literal("entry-crossing"),
411
+ z6.literal("exit-crossing")
412
+ ]);
413
+ var viewRangeValueSchema = z6.tuple([
414
+ viewNamedRangeSchema,
415
+ rangeUnitValueSchema
416
+ ]);
417
+ var viewRangeOptionsSchema = z6.object({
418
+ rangeStart: viewRangeValueSchema.optional(),
419
+ rangeEnd: viewRangeValueSchema.optional()
420
+ });
421
+ var baseAnimation = z6.object({
422
+ name: z6.string().optional(),
423
+ description: z6.string().optional(),
424
+ enabled: z6.array(z6.tuple([z6.string().describe("breakpointId"), z6.boolean()])).optional(),
425
+ keyframes: z6.array(animationKeyframeSchema)
426
+ });
427
+ var scrollAnimationSchema = baseAnimation.merge(
428
+ z6.object({
429
+ timing: keyframeEffectOptionsSchema.merge(scrollRangeOptionsSchema)
430
+ })
431
+ );
432
+ var scrollActionSchema = z6.object({
433
+ type: z6.literal("scroll"),
434
+ source: z6.union([z6.literal("closest"), z6.literal("nearest"), z6.literal("root")]).optional(),
435
+ axis: animationAxisSchema.optional(),
436
+ animations: z6.array(scrollAnimationSchema),
437
+ isPinned: z6.boolean().optional(),
438
+ debug: z6.boolean().optional()
439
+ });
440
+ var viewAnimationSchema = baseAnimation.merge(
441
+ z6.object({
442
+ timing: keyframeEffectOptionsSchema.merge(viewRangeOptionsSchema)
443
+ })
444
+ );
445
+ var viewActionSchema = z6.object({
446
+ type: z6.literal("view"),
447
+ subject: z6.string().optional(),
448
+ axis: animationAxisSchema.optional(),
449
+ animations: z6.array(viewAnimationSchema),
450
+ insetStart: insetUnitValueSchema.optional(),
451
+ insetEnd: insetUnitValueSchema.optional(),
452
+ isPinned: z6.boolean().optional(),
453
+ debug: z6.boolean().optional()
454
+ });
455
+ var animationActionSchema = z6.discriminatedUnion("type", [
456
+ scrollActionSchema,
457
+ viewActionSchema
458
+ ]);
459
+
460
+ // src/schema/props.ts
461
+ var PropId = z7.string();
462
+ var baseProp = {
463
+ id: PropId,
464
+ instanceId: z7.string(),
465
+ name: z7.string(),
466
+ required: z7.optional(z7.boolean())
467
+ };
468
+ var Prop = z7.union([
469
+ z7.object({
470
+ ...baseProp,
471
+ type: z7.literal("number"),
472
+ value: z7.number()
473
+ }),
474
+ z7.object({
475
+ ...baseProp,
476
+ type: z7.literal("string"),
477
+ value: z7.string()
478
+ }),
479
+ z7.object({
480
+ ...baseProp,
481
+ type: z7.literal("boolean"),
482
+ value: z7.boolean()
483
+ }),
484
+ z7.object({
485
+ ...baseProp,
486
+ type: z7.literal("json"),
487
+ value: z7.unknown()
488
+ }),
489
+ z7.object({
490
+ ...baseProp,
491
+ type: z7.literal("asset"),
492
+ value: z7.string()
493
+ // asset id
494
+ }),
495
+ z7.object({
496
+ ...baseProp,
497
+ type: z7.literal("page"),
498
+ value: z7.union([
499
+ z7.string(),
500
+ // page id
501
+ z7.object({
502
+ pageId: z7.string(),
503
+ instanceId: z7.string()
504
+ })
505
+ ])
506
+ }),
507
+ z7.object({
508
+ ...baseProp,
509
+ type: z7.literal("string[]"),
510
+ value: z7.array(z7.string())
511
+ }),
512
+ z7.object({
513
+ ...baseProp,
514
+ type: z7.literal("parameter"),
515
+ // data source id
516
+ value: z7.string()
517
+ }),
518
+ z7.object({
519
+ ...baseProp,
520
+ type: z7.literal("resource"),
521
+ // resource id
522
+ value: z7.string()
523
+ }),
524
+ z7.object({
525
+ ...baseProp,
526
+ type: z7.literal("expression"),
527
+ // expression code
528
+ value: z7.string()
529
+ }),
530
+ z7.object({
531
+ ...baseProp,
532
+ type: z7.literal("action"),
533
+ value: z7.array(
534
+ z7.object({
535
+ type: z7.literal("execute"),
536
+ args: z7.array(z7.string()),
537
+ code: z7.string()
538
+ })
539
+ )
540
+ }),
541
+ z7.object({
542
+ ...baseProp,
543
+ type: z7.literal("animationAction"),
544
+ value: animationActionSchema
545
+ })
546
+ ]);
547
+ var Props = z7.map(PropId, Prop);
548
+
549
+ // src/schema/breakpoints.ts
550
+ import { z as z8 } from "zod";
551
+ var BreakpointId = z8.string();
552
+ var Breakpoint = z8.object({
553
+ id: BreakpointId,
554
+ label: z8.string(),
555
+ minWidth: z8.number().optional(),
556
+ maxWidth: z8.number().optional()
557
+ }).refine(({ minWidth, maxWidth }) => {
558
+ return (
559
+ // Either min or max width have to be defined
560
+ minWidth !== void 0 && maxWidth === void 0 || minWidth === void 0 && maxWidth !== void 0 || // This is a base breakpoint
561
+ minWidth === void 0 && maxWidth === void 0
562
+ );
563
+ }, "Either minWidth or maxWidth should be defined");
564
+ var Breakpoints = z8.map(BreakpointId, Breakpoint);
565
+ var initialBreakpoints = [
566
+ { id: "placeholder", label: "Base" },
567
+ { id: "placeholder", label: "Tablet", maxWidth: 991 },
568
+ { id: "placeholder", label: "Mobile landscape", maxWidth: 767 },
569
+ { id: "placeholder", label: "Mobile portrait", maxWidth: 479 }
570
+ ];
571
+
572
+ // src/schema/style-sources.ts
573
+ import { z as z9 } from "zod";
574
+ var StyleSourceId = z9.string();
575
+ var StyleSourceToken = z9.object({
576
+ type: z9.literal("token"),
577
+ id: StyleSourceId,
578
+ name: z9.string()
579
+ });
580
+ var StyleSourceLocal = z9.object({
581
+ type: z9.literal("local"),
582
+ id: StyleSourceId
583
+ });
584
+ var StyleSource = z9.union([StyleSourceToken, StyleSourceLocal]);
585
+ var StyleSources = z9.map(StyleSourceId, StyleSource);
586
+
587
+ // src/schema/style-source-selections.ts
588
+ import { z as z10 } from "zod";
589
+ var InstanceId2 = z10.string();
590
+ var StyleSourceId2 = z10.string();
591
+ var StyleSourceSelection = z10.object({
592
+ instanceId: InstanceId2,
593
+ values: z10.array(StyleSourceId2)
594
+ });
595
+ var StyleSourceSelections = z10.map(InstanceId2, StyleSourceSelection);
596
+
597
+ // src/schema/styles.ts
598
+ import { z as z11 } from "zod";
599
+ import { StyleValue as StyleValue2 } from "@webstudio-is/css-engine";
600
+ var StyleDeclRaw = z11.object({
601
+ styleSourceId: z11.string(),
602
+ breakpointId: z11.string(),
603
+ state: z11.optional(z11.string()),
604
+ // @todo can't figure out how to make property to be enum
605
+ property: z11.string(),
606
+ value: StyleValue2,
607
+ listed: z11.boolean().optional().describe("Whether the style is from the Advanced panel")
608
+ });
609
+ var StyleDecl = StyleDeclRaw;
610
+ var getStyleDeclKey = (styleDecl) => {
611
+ return `${styleDecl.styleSourceId}:${styleDecl.breakpointId}:${styleDecl.property}:${styleDecl.state ?? ""}`;
612
+ };
613
+ var Styles = z11.map(z11.string(), StyleDecl);
614
+
615
+ // src/schema/deployment.ts
616
+ import { z as z12 } from "zod";
617
+ var Templates = z12.enum([
618
+ "docker",
619
+ "vercel",
620
+ "netlify",
621
+ "ssg",
622
+ "ssg-netlify",
623
+ "ssg-vercel"
624
+ ]);
625
+ var Deployment = z12.union([
626
+ z12.object({
627
+ destination: z12.literal("static"),
628
+ name: z12.string(),
629
+ assetsDomain: z12.string(),
630
+ // Must be validated very strictly
631
+ templates: z12.array(Templates)
632
+ }),
633
+ z12.object({
634
+ destination: z12.literal("saas").optional(),
635
+ domains: z12.array(z12.string()),
636
+ assetsDomain: z12.string().optional(),
637
+ /**
638
+ * @deprecated This field is deprecated, use `domains` instead.
639
+ */
640
+ projectDomain: z12.string().optional(),
641
+ excludeWstdDomainFromSearch: z12.boolean().optional()
642
+ })
643
+ ]);
644
+
645
+ // src/schema/webstudio.ts
646
+ import { z as z13 } from "zod";
647
+ var WebstudioFragment = z13.object({
648
+ children: z13.array(InstanceChild),
649
+ instances: z13.array(Instance),
650
+ assets: z13.array(Asset),
651
+ dataSources: z13.array(DataSource),
652
+ resources: z13.array(Resource),
653
+ props: z13.array(Prop),
654
+ breakpoints: z13.array(Breakpoint),
655
+ styleSourceSelections: z13.array(StyleSourceSelection),
656
+ styleSources: z13.array(StyleSource),
657
+ styles: z13.array(StyleDecl)
658
+ });
659
+
660
+ // src/schema/prop-meta.ts
661
+ import { z as z14 } from "zod";
662
+ var common = {
663
+ label: z14.string().optional(),
664
+ description: z14.string().optional(),
665
+ required: z14.boolean()
666
+ };
667
+ var Tag = z14.object({
668
+ ...common,
669
+ control: z14.literal("tag"),
670
+ type: z14.literal("string"),
671
+ defaultValue: z14.undefined().optional(),
672
+ options: z14.array(z14.string())
673
+ });
674
+ var Number = z14.object({
675
+ ...common,
676
+ control: z14.literal("number"),
677
+ type: z14.literal("number"),
678
+ defaultValue: z14.number().optional()
679
+ });
680
+ var Range = z14.object({
681
+ ...common,
682
+ control: z14.literal("range"),
683
+ type: z14.literal("number"),
684
+ defaultValue: z14.number().optional()
685
+ });
686
+ var Text = z14.object({
687
+ ...common,
688
+ control: z14.literal("text"),
689
+ type: z14.literal("string"),
690
+ defaultValue: z14.string().optional(),
691
+ /**
692
+ * The number of rows in <textarea>. If set to 0 an <input> will be used instead.
693
+ * In line with Storybook team's plan: https://github.com/storybookjs/storybook/issues/21100
694
+ */
695
+ rows: z14.number().optional()
696
+ });
697
+ var Resource2 = z14.object({
698
+ ...common,
699
+ control: z14.literal("resource"),
700
+ type: z14.literal("resource"),
701
+ defaultValue: z14.string().optional()
702
+ });
703
+ var Code = z14.object({
704
+ ...common,
705
+ control: z14.literal("code"),
706
+ type: z14.literal("string"),
707
+ language: z14.union([z14.literal("html"), z14.literal("markdown")]),
708
+ defaultValue: z14.string().optional()
709
+ });
710
+ var CodeText = z14.object({
711
+ ...common,
712
+ control: z14.literal("codetext"),
713
+ type: z14.literal("string"),
714
+ defaultValue: z14.string().optional()
715
+ });
716
+ var Color = z14.object({
717
+ ...common,
718
+ control: z14.literal("color"),
719
+ type: z14.literal("string"),
720
+ defaultValue: z14.string().optional()
721
+ });
722
+ var Boolean = z14.object({
723
+ ...common,
724
+ control: z14.literal("boolean"),
725
+ type: z14.literal("boolean"),
726
+ defaultValue: z14.boolean().optional()
727
+ });
728
+ var Radio = z14.object({
729
+ ...common,
730
+ control: z14.literal("radio"),
731
+ type: z14.literal("string"),
732
+ defaultValue: z14.string().optional(),
733
+ options: z14.array(z14.string())
734
+ });
735
+ var InlineRadio = z14.object({
736
+ ...common,
737
+ control: z14.literal("inline-radio"),
738
+ type: z14.literal("string"),
739
+ defaultValue: z14.string().optional(),
740
+ options: z14.array(z14.string())
741
+ });
742
+ var Select = z14.object({
743
+ ...common,
744
+ control: z14.literal("select"),
745
+ type: z14.literal("string"),
746
+ defaultValue: z14.string().optional(),
747
+ options: z14.array(z14.string())
748
+ });
749
+ var Check = z14.object({
750
+ ...common,
751
+ control: z14.literal("check"),
752
+ type: z14.literal("string[]"),
753
+ defaultValue: z14.array(z14.string()).optional(),
754
+ options: z14.array(z14.string())
755
+ });
756
+ var InlineCheck = z14.object({
757
+ ...common,
758
+ control: z14.literal("inline-check"),
759
+ type: z14.literal("string[]"),
760
+ defaultValue: z14.array(z14.string()).optional(),
761
+ options: z14.array(z14.string())
762
+ });
763
+ var MultiSelect = z14.object({
764
+ ...common,
765
+ control: z14.literal("multi-select"),
766
+ type: z14.literal("string[]"),
767
+ defaultValue: z14.array(z14.string()).optional(),
768
+ options: z14.array(z14.string())
769
+ });
770
+ var File = z14.object({
771
+ ...common,
772
+ control: z14.literal("file"),
773
+ type: z14.literal("string"),
774
+ defaultValue: z14.string().optional(),
775
+ /** https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#accept */
776
+ accept: z14.string().optional()
777
+ });
778
+ var Url = z14.object({
779
+ ...common,
780
+ control: z14.literal("url"),
781
+ type: z14.literal("string"),
782
+ defaultValue: z14.string().optional()
783
+ });
784
+ var Json = z14.object({
785
+ ...common,
786
+ control: z14.literal("json"),
787
+ type: z14.literal("json"),
788
+ defaultValue: z14.unknown().optional()
789
+ });
790
+ var Date = z14.object({
791
+ ...common,
792
+ control: z14.literal("date"),
793
+ // @todo not sure what type should be here
794
+ // (we don't support Date yet, added for completeness)
795
+ type: z14.literal("string"),
796
+ defaultValue: z14.string().optional()
797
+ });
798
+ var Action = z14.object({
799
+ ...common,
800
+ control: z14.literal("action"),
801
+ type: z14.literal("action"),
802
+ defaultValue: z14.undefined().optional()
803
+ });
804
+ var TextContent = z14.object({
805
+ ...common,
806
+ control: z14.literal("textContent"),
807
+ type: z14.literal("string"),
808
+ defaultValue: z14.string().optional()
809
+ });
810
+ var AnimationAction = z14.object({
811
+ ...common,
812
+ control: z14.literal("animationAction"),
813
+ type: z14.literal("animationAction"),
814
+ defaultValue: z14.undefined().optional()
815
+ });
816
+ var PropMeta = z14.union([
817
+ Tag,
818
+ Number,
819
+ Range,
820
+ Text,
821
+ Resource2,
822
+ Code,
823
+ CodeText,
824
+ Color,
825
+ Boolean,
826
+ Radio,
827
+ InlineRadio,
828
+ Select,
829
+ MultiSelect,
830
+ Check,
831
+ InlineCheck,
832
+ File,
833
+ Url,
834
+ Json,
835
+ Date,
836
+ Action,
837
+ TextContent,
838
+ AnimationAction
839
+ ]);
840
+
841
+ // src/schema/component-meta.ts
842
+ import { z as z15 } from "zod";
843
+ import { StyleValue as StyleValue3 } from "@webstudio-is/css-engine";
844
+ var PresetStyleDecl = z15.object({
845
+ // State selector, e.g. :hover
846
+ state: z15.optional(z15.string()),
847
+ property: z15.string(),
848
+ value: StyleValue3
849
+ });
850
+ var componentCategories = [
851
+ "general",
852
+ "typography",
853
+ "media",
854
+ "animations",
855
+ "data",
856
+ "forms",
857
+ "localization",
858
+ "radix",
859
+ "xml",
860
+ "other",
861
+ "hidden",
862
+ "internal"
863
+ ];
864
+ var ComponentState = z15.object({
865
+ selector: z15.string(),
866
+ label: z15.string()
867
+ });
868
+ var ComponentContent = z15.string();
869
+ var ContentModel = z15.object({
870
+ /*
871
+ * instance - accepted by any parent with "instance" in children categories
872
+ * none - accepted by parents with this component name in children categories
873
+ */
874
+ category: z15.union([z15.literal("instance"), z15.literal("none")]),
875
+ /**
876
+ * enforce direct children of category or components
877
+ */
878
+ children: z15.array(ComponentContent),
879
+ /**
880
+ * enforce descendants of category or components
881
+ */
882
+ descendants: z15.array(ComponentContent).optional()
883
+ });
884
+ var WsComponentMeta = z15.object({
885
+ category: z15.enum(componentCategories).optional(),
886
+ contentModel: ContentModel.optional(),
887
+ // when this field is specified component receives
888
+ // prop with index of same components withiin specified ancestor
889
+ // important to automatically enumerate collections without
890
+ // naming every item manually
891
+ indexWithinAncestor: z15.optional(z15.string()),
892
+ label: z15.optional(z15.string()),
893
+ description: z15.string().optional(),
894
+ icon: z15.string().optional(),
895
+ presetStyle: z15.optional(z15.record(z15.string(), z15.array(PresetStyleDecl))),
896
+ states: z15.optional(z15.array(ComponentState)),
897
+ order: z15.number().optional(),
898
+ // properties and html attributes that will be always visible in properties panel
899
+ initialProps: z15.array(z15.string()).optional(),
900
+ props: z15.record(PropMeta).optional()
901
+ });
902
+
903
+ // src/core-metas.ts
904
+ import {
905
+ ContentBlockIcon,
906
+ ListViewIcon,
907
+ PaintBrushIcon,
908
+ SettingsIcon,
909
+ AddTemplateInstanceIcon
910
+ } from "@webstudio-is/icons/svg";
911
+
912
+ // src/__generated__/normalize.css.ts
913
+ var normalize_css_exports = {};
914
+ __export(normalize_css_exports, {
915
+ a: () => a,
916
+ address: () => address,
917
+ article: () => article,
918
+ aside: () => aside,
919
+ b: () => b,
920
+ body: () => body,
921
+ button: () => button,
922
+ checkbox: () => checkbox,
923
+ code: () => code,
924
+ div: () => div,
925
+ figure: () => figure,
926
+ footer: () => footer,
927
+ form: () => form,
928
+ h1: () => h1,
929
+ h2: () => h2,
930
+ h3: () => h3,
931
+ h4: () => h4,
932
+ h5: () => h5,
933
+ h6: () => h6,
934
+ header: () => header,
935
+ hr: () => hr,
936
+ html: () => html,
937
+ i: () => i,
938
+ img: () => img,
939
+ input: () => input,
940
+ kbd: () => kbd,
941
+ label: () => label,
942
+ legend: () => legend,
943
+ li: () => li,
944
+ main: () => main,
945
+ nav: () => nav,
946
+ ol: () => ol,
947
+ optgroup: () => optgroup,
948
+ p: () => p,
949
+ pre: () => pre,
950
+ progress: () => progress,
951
+ radio: () => radio,
952
+ samp: () => samp,
953
+ section: () => section,
954
+ select: () => select,
955
+ small: () => small,
956
+ span: () => span,
957
+ strong: () => strong,
958
+ sub: () => sub,
959
+ summary: () => summary,
960
+ sup: () => sup,
961
+ table: () => table,
962
+ textarea: () => textarea,
963
+ time: () => time,
964
+ ul: () => ul
965
+ });
966
+ var div = [
967
+ { property: "box-sizing", value: { type: "keyword", value: "border-box" } },
968
+ {
969
+ property: "border-top-width",
970
+ value: { type: "unit", unit: "px", value: 1 }
971
+ },
972
+ {
973
+ property: "border-right-width",
974
+ value: { type: "unit", unit: "px", value: 1 }
975
+ },
976
+ {
977
+ property: "border-bottom-width",
978
+ value: { type: "unit", unit: "px", value: 1 }
979
+ },
980
+ {
981
+ property: "border-left-width",
982
+ value: { type: "unit", unit: "px", value: 1 }
983
+ },
984
+ { property: "outline-width", value: { type: "unit", unit: "px", value: 1 } }
985
+ ];
986
+ var address = div;
987
+ var article = div;
988
+ var aside = div;
989
+ var figure = div;
990
+ var footer = div;
991
+ var header = div;
992
+ var main = div;
993
+ var nav = div;
994
+ var section = div;
995
+ var form = div;
996
+ var label = div;
997
+ var time = div;
998
+ var h1 = div;
999
+ var h2 = div;
1000
+ var h3 = div;
1001
+ var h4 = div;
1002
+ var h5 = div;
1003
+ var h6 = div;
1004
+ var i = div;
1005
+ var img = div;
1006
+ var a = div;
1007
+ var li = div;
1008
+ var ul = div;
1009
+ var ol = div;
1010
+ var p = div;
1011
+ var span = div;
1012
+ var html = [
1013
+ { property: "display", value: { type: "keyword", value: "grid" } },
1014
+ { property: "min-height", value: { type: "unit", unit: "%", value: 100 } },
1015
+ {
1016
+ property: "font-family",
1017
+ value: { type: "fontFamily", value: ["Arial", "Roboto", "sans-serif"] }
1018
+ },
1019
+ { property: "font-size", value: { type: "unit", unit: "px", value: 16 } },
1020
+ {
1021
+ property: "line-height",
1022
+ value: { type: "unit", unit: "number", value: 1.2 }
1023
+ },
1024
+ {
1025
+ property: "white-space-collapse",
1026
+ value: { type: "keyword", value: "preserve" }
1027
+ }
1028
+ ];
1029
+ var body = [
1030
+ { property: "margin-top", value: { type: "unit", unit: "number", value: 0 } },
1031
+ {
1032
+ property: "margin-right",
1033
+ value: { type: "unit", unit: "number", value: 0 }
1034
+ },
1035
+ {
1036
+ property: "margin-bottom",
1037
+ value: { type: "unit", unit: "number", value: 0 }
1038
+ },
1039
+ {
1040
+ property: "margin-left",
1041
+ value: { type: "unit", unit: "number", value: 0 }
1042
+ },
1043
+ { property: "box-sizing", value: { type: "keyword", value: "border-box" } },
1044
+ {
1045
+ property: "border-top-width",
1046
+ value: { type: "unit", unit: "px", value: 1 }
1047
+ },
1048
+ {
1049
+ property: "border-right-width",
1050
+ value: { type: "unit", unit: "px", value: 1 }
1051
+ },
1052
+ {
1053
+ property: "border-bottom-width",
1054
+ value: { type: "unit", unit: "px", value: 1 }
1055
+ },
1056
+ {
1057
+ property: "border-left-width",
1058
+ value: { type: "unit", unit: "px", value: 1 }
1059
+ },
1060
+ {
1061
+ property: "-webkit-font-smoothing",
1062
+ value: { type: "keyword", value: "antialiased" }
1063
+ },
1064
+ {
1065
+ property: "-moz-osx-font-smoothing",
1066
+ value: { type: "keyword", value: "grayscale" }
1067
+ }
1068
+ ];
1069
+ var hr = [
1070
+ { property: "height", value: { type: "unit", unit: "number", value: 0 } },
1071
+ { property: "color", value: { type: "keyword", value: "inherit" } },
1072
+ { property: "box-sizing", value: { type: "keyword", value: "border-box" } }
1073
+ ];
1074
+ var b = [
1075
+ {
1076
+ property: "font-weight",
1077
+ value: { type: "unit", unit: "number", value: 700 }
1078
+ },
1079
+ { property: "box-sizing", value: { type: "keyword", value: "border-box" } },
1080
+ {
1081
+ property: "border-top-width",
1082
+ value: { type: "unit", unit: "px", value: 1 }
1083
+ },
1084
+ {
1085
+ property: "border-right-width",
1086
+ value: { type: "unit", unit: "px", value: 1 }
1087
+ },
1088
+ {
1089
+ property: "border-bottom-width",
1090
+ value: { type: "unit", unit: "px", value: 1 }
1091
+ },
1092
+ {
1093
+ property: "border-left-width",
1094
+ value: { type: "unit", unit: "px", value: 1 }
1095
+ }
1096
+ ];
1097
+ var strong = b;
1098
+ var code = [
1099
+ {
1100
+ property: "font-family",
1101
+ value: {
1102
+ type: "fontFamily",
1103
+ value: [
1104
+ "ui-monospace",
1105
+ "SFMono-Regular",
1106
+ "Consolas",
1107
+ "Liberation Mono",
1108
+ "Menlo",
1109
+ "monospace"
1110
+ ]
1111
+ }
1112
+ },
1113
+ { property: "font-size", value: { type: "unit", unit: "em", value: 1 } },
1114
+ { property: "box-sizing", value: { type: "keyword", value: "border-box" } },
1115
+ {
1116
+ property: "border-top-width",
1117
+ value: { type: "unit", unit: "px", value: 1 }
1118
+ },
1119
+ {
1120
+ property: "border-right-width",
1121
+ value: { type: "unit", unit: "px", value: 1 }
1122
+ },
1123
+ {
1124
+ property: "border-bottom-width",
1125
+ value: { type: "unit", unit: "px", value: 1 }
1126
+ },
1127
+ {
1128
+ property: "border-left-width",
1129
+ value: { type: "unit", unit: "px", value: 1 }
1130
+ }
1131
+ ];
1132
+ var kbd = code;
1133
+ var samp = code;
1134
+ var pre = code;
1135
+ var small = [
1136
+ { property: "font-size", value: { type: "unit", unit: "%", value: 80 } },
1137
+ { property: "box-sizing", value: { type: "keyword", value: "border-box" } },
1138
+ {
1139
+ property: "border-top-width",
1140
+ value: { type: "unit", unit: "px", value: 1 }
1141
+ },
1142
+ {
1143
+ property: "border-right-width",
1144
+ value: { type: "unit", unit: "px", value: 1 }
1145
+ },
1146
+ {
1147
+ property: "border-bottom-width",
1148
+ value: { type: "unit", unit: "px", value: 1 }
1149
+ },
1150
+ {
1151
+ property: "border-left-width",
1152
+ value: { type: "unit", unit: "px", value: 1 }
1153
+ }
1154
+ ];
1155
+ var sub = [
1156
+ { property: "font-size", value: { type: "unit", unit: "%", value: 75 } },
1157
+ {
1158
+ property: "line-height",
1159
+ value: { type: "unit", unit: "number", value: 0 }
1160
+ },
1161
+ { property: "position", value: { type: "keyword", value: "relative" } },
1162
+ { property: "vertical-align", value: { type: "keyword", value: "baseline" } },
1163
+ { property: "box-sizing", value: { type: "keyword", value: "border-box" } },
1164
+ {
1165
+ property: "border-top-width",
1166
+ value: { type: "unit", unit: "px", value: 1 }
1167
+ },
1168
+ {
1169
+ property: "border-right-width",
1170
+ value: { type: "unit", unit: "px", value: 1 }
1171
+ },
1172
+ {
1173
+ property: "border-bottom-width",
1174
+ value: { type: "unit", unit: "px", value: 1 }
1175
+ },
1176
+ {
1177
+ property: "border-left-width",
1178
+ value: { type: "unit", unit: "px", value: 1 }
1179
+ },
1180
+ { property: "bottom", value: { type: "unit", unit: "em", value: -0.25 } }
1181
+ ];
1182
+ var sup = [
1183
+ { property: "font-size", value: { type: "unit", unit: "%", value: 75 } },
1184
+ {
1185
+ property: "line-height",
1186
+ value: { type: "unit", unit: "number", value: 0 }
1187
+ },
1188
+ { property: "position", value: { type: "keyword", value: "relative" } },
1189
+ { property: "vertical-align", value: { type: "keyword", value: "baseline" } },
1190
+ { property: "box-sizing", value: { type: "keyword", value: "border-box" } },
1191
+ {
1192
+ property: "border-top-width",
1193
+ value: { type: "unit", unit: "px", value: 1 }
1194
+ },
1195
+ {
1196
+ property: "border-right-width",
1197
+ value: { type: "unit", unit: "px", value: 1 }
1198
+ },
1199
+ {
1200
+ property: "border-bottom-width",
1201
+ value: { type: "unit", unit: "px", value: 1 }
1202
+ },
1203
+ {
1204
+ property: "border-left-width",
1205
+ value: { type: "unit", unit: "px", value: 1 }
1206
+ },
1207
+ { property: "top", value: { type: "unit", unit: "em", value: -0.5 } }
1208
+ ];
1209
+ var table = [
1210
+ {
1211
+ property: "text-indent",
1212
+ value: { type: "unit", unit: "number", value: 0 }
1213
+ },
1214
+ {
1215
+ property: "border-top-width",
1216
+ value: { type: "unit", unit: "px", value: 1 }
1217
+ },
1218
+ {
1219
+ property: "border-right-width",
1220
+ value: { type: "unit", unit: "px", value: 1 }
1221
+ },
1222
+ {
1223
+ property: "border-bottom-width",
1224
+ value: { type: "unit", unit: "px", value: 1 }
1225
+ },
1226
+ {
1227
+ property: "border-left-width",
1228
+ value: { type: "unit", unit: "px", value: 1 }
1229
+ },
1230
+ {
1231
+ property: "border-top-color",
1232
+ value: { type: "keyword", value: "inherit" }
1233
+ },
1234
+ {
1235
+ property: "border-right-color",
1236
+ value: { type: "keyword", value: "inherit" }
1237
+ },
1238
+ {
1239
+ property: "border-bottom-color",
1240
+ value: { type: "keyword", value: "inherit" }
1241
+ },
1242
+ {
1243
+ property: "border-left-color",
1244
+ value: { type: "keyword", value: "inherit" }
1245
+ },
1246
+ { property: "box-sizing", value: { type: "keyword", value: "border-box" } }
1247
+ ];
1248
+ var input = [
1249
+ { property: "font-family", value: { type: "keyword", value: "inherit" } },
1250
+ { property: "font-size", value: { type: "unit", unit: "%", value: 100 } },
1251
+ {
1252
+ property: "line-height",
1253
+ value: { type: "unit", unit: "number", value: 1.15 }
1254
+ },
1255
+ { property: "margin-top", value: { type: "unit", unit: "number", value: 0 } },
1256
+ {
1257
+ property: "margin-right",
1258
+ value: { type: "unit", unit: "number", value: 0 }
1259
+ },
1260
+ {
1261
+ property: "margin-bottom",
1262
+ value: { type: "unit", unit: "number", value: 0 }
1263
+ },
1264
+ {
1265
+ property: "margin-left",
1266
+ value: { type: "unit", unit: "number", value: 0 }
1267
+ },
1268
+ { property: "box-sizing", value: { type: "keyword", value: "border-box" } },
1269
+ {
1270
+ property: "border-top-width",
1271
+ value: { type: "unit", unit: "px", value: 1 }
1272
+ },
1273
+ {
1274
+ property: "border-right-width",
1275
+ value: { type: "unit", unit: "px", value: 1 }
1276
+ },
1277
+ {
1278
+ property: "border-bottom-width",
1279
+ value: { type: "unit", unit: "px", value: 1 }
1280
+ },
1281
+ {
1282
+ property: "border-left-width",
1283
+ value: { type: "unit", unit: "px", value: 1 }
1284
+ },
1285
+ { property: "border-top-style", value: { type: "keyword", value: "solid" } },
1286
+ {
1287
+ property: "border-right-style",
1288
+ value: { type: "keyword", value: "solid" }
1289
+ },
1290
+ {
1291
+ property: "border-bottom-style",
1292
+ value: { type: "keyword", value: "solid" }
1293
+ },
1294
+ { property: "border-left-style", value: { type: "keyword", value: "solid" } }
1295
+ ];
1296
+ var textarea = input;
1297
+ var optgroup = [
1298
+ { property: "font-family", value: { type: "keyword", value: "inherit" } },
1299
+ { property: "font-size", value: { type: "unit", unit: "%", value: 100 } },
1300
+ {
1301
+ property: "line-height",
1302
+ value: { type: "unit", unit: "number", value: 1.15 }
1303
+ },
1304
+ { property: "margin-top", value: { type: "unit", unit: "number", value: 0 } },
1305
+ {
1306
+ property: "margin-right",
1307
+ value: { type: "unit", unit: "number", value: 0 }
1308
+ },
1309
+ {
1310
+ property: "margin-bottom",
1311
+ value: { type: "unit", unit: "number", value: 0 }
1312
+ },
1313
+ {
1314
+ property: "margin-left",
1315
+ value: { type: "unit", unit: "number", value: 0 }
1316
+ },
1317
+ { property: "box-sizing", value: { type: "keyword", value: "border-box" } },
1318
+ {
1319
+ property: "border-top-width",
1320
+ value: { type: "unit", unit: "px", value: 1 }
1321
+ },
1322
+ {
1323
+ property: "border-right-width",
1324
+ value: { type: "unit", unit: "px", value: 1 }
1325
+ },
1326
+ {
1327
+ property: "border-bottom-width",
1328
+ value: { type: "unit", unit: "px", value: 1 }
1329
+ },
1330
+ {
1331
+ property: "border-left-width",
1332
+ value: { type: "unit", unit: "px", value: 1 }
1333
+ }
1334
+ ];
1335
+ var radio = [
1336
+ { property: "font-family", value: { type: "keyword", value: "inherit" } },
1337
+ { property: "font-size", value: { type: "unit", unit: "%", value: 100 } },
1338
+ {
1339
+ property: "line-height",
1340
+ value: { type: "unit", unit: "number", value: 1.15 }
1341
+ },
1342
+ { property: "margin-top", value: { type: "unit", unit: "number", value: 0 } },
1343
+ {
1344
+ property: "margin-right",
1345
+ value: { type: "unit", unit: "number", value: 0 }
1346
+ },
1347
+ {
1348
+ property: "margin-bottom",
1349
+ value: { type: "unit", unit: "number", value: 0 }
1350
+ },
1351
+ {
1352
+ property: "margin-left",
1353
+ value: { type: "unit", unit: "number", value: 0 }
1354
+ },
1355
+ { property: "box-sizing", value: { type: "keyword", value: "border-box" } },
1356
+ {
1357
+ property: "border-top-width",
1358
+ value: { type: "unit", unit: "px", value: 1 }
1359
+ },
1360
+ {
1361
+ property: "border-right-width",
1362
+ value: { type: "unit", unit: "px", value: 1 }
1363
+ },
1364
+ {
1365
+ property: "border-bottom-width",
1366
+ value: { type: "unit", unit: "px", value: 1 }
1367
+ },
1368
+ {
1369
+ property: "border-left-width",
1370
+ value: { type: "unit", unit: "px", value: 1 }
1371
+ },
1372
+ { property: "border-top-style", value: { type: "keyword", value: "none" } },
1373
+ { property: "border-right-style", value: { type: "keyword", value: "none" } },
1374
+ {
1375
+ property: "border-bottom-style",
1376
+ value: { type: "keyword", value: "none" }
1377
+ },
1378
+ { property: "border-left-style", value: { type: "keyword", value: "none" } }
1379
+ ];
1380
+ var checkbox = radio;
1381
+ var button = [
1382
+ { property: "font-family", value: { type: "keyword", value: "inherit" } },
1383
+ { property: "font-size", value: { type: "unit", unit: "%", value: 100 } },
1384
+ {
1385
+ property: "line-height",
1386
+ value: { type: "unit", unit: "number", value: 1.15 }
1387
+ },
1388
+ { property: "margin-top", value: { type: "unit", unit: "number", value: 0 } },
1389
+ {
1390
+ property: "margin-right",
1391
+ value: { type: "unit", unit: "number", value: 0 }
1392
+ },
1393
+ {
1394
+ property: "margin-bottom",
1395
+ value: { type: "unit", unit: "number", value: 0 }
1396
+ },
1397
+ {
1398
+ property: "margin-left",
1399
+ value: { type: "unit", unit: "number", value: 0 }
1400
+ },
1401
+ { property: "box-sizing", value: { type: "keyword", value: "border-box" } },
1402
+ {
1403
+ property: "border-top-width",
1404
+ value: { type: "unit", unit: "px", value: 1 }
1405
+ },
1406
+ {
1407
+ property: "border-right-width",
1408
+ value: { type: "unit", unit: "px", value: 1 }
1409
+ },
1410
+ {
1411
+ property: "border-bottom-width",
1412
+ value: { type: "unit", unit: "px", value: 1 }
1413
+ },
1414
+ {
1415
+ property: "border-left-width",
1416
+ value: { type: "unit", unit: "px", value: 1 }
1417
+ },
1418
+ { property: "border-top-style", value: { type: "keyword", value: "solid" } },
1419
+ {
1420
+ property: "border-right-style",
1421
+ value: { type: "keyword", value: "solid" }
1422
+ },
1423
+ {
1424
+ property: "border-bottom-style",
1425
+ value: { type: "keyword", value: "solid" }
1426
+ },
1427
+ { property: "border-left-style", value: { type: "keyword", value: "solid" } },
1428
+ { property: "text-transform", value: { type: "keyword", value: "none" } }
1429
+ ];
1430
+ var select = button;
1431
+ var legend = [
1432
+ {
1433
+ property: "padding-top",
1434
+ value: { type: "unit", unit: "number", value: 0 }
1435
+ },
1436
+ {
1437
+ property: "padding-right",
1438
+ value: { type: "unit", unit: "number", value: 0 }
1439
+ },
1440
+ {
1441
+ property: "padding-bottom",
1442
+ value: { type: "unit", unit: "number", value: 0 }
1443
+ },
1444
+ {
1445
+ property: "padding-left",
1446
+ value: { type: "unit", unit: "number", value: 0 }
1447
+ },
1448
+ { property: "box-sizing", value: { type: "keyword", value: "border-box" } },
1449
+ {
1450
+ property: "border-top-width",
1451
+ value: { type: "unit", unit: "px", value: 1 }
1452
+ },
1453
+ {
1454
+ property: "border-right-width",
1455
+ value: { type: "unit", unit: "px", value: 1 }
1456
+ },
1457
+ {
1458
+ property: "border-bottom-width",
1459
+ value: { type: "unit", unit: "px", value: 1 }
1460
+ },
1461
+ {
1462
+ property: "border-left-width",
1463
+ value: { type: "unit", unit: "px", value: 1 }
1464
+ }
1465
+ ];
1466
+ var progress = [
1467
+ { property: "vertical-align", value: { type: "keyword", value: "baseline" } },
1468
+ { property: "box-sizing", value: { type: "keyword", value: "border-box" } },
1469
+ {
1470
+ property: "border-top-width",
1471
+ value: { type: "unit", unit: "px", value: 1 }
1472
+ },
1473
+ {
1474
+ property: "border-right-width",
1475
+ value: { type: "unit", unit: "px", value: 1 }
1476
+ },
1477
+ {
1478
+ property: "border-bottom-width",
1479
+ value: { type: "unit", unit: "px", value: 1 }
1480
+ },
1481
+ {
1482
+ property: "border-left-width",
1483
+ value: { type: "unit", unit: "px", value: 1 }
1484
+ }
1485
+ ];
1486
+ var summary = [
1487
+ { property: "display", value: { type: "keyword", value: "list-item" } },
1488
+ { property: "box-sizing", value: { type: "keyword", value: "border-box" } },
1489
+ {
1490
+ property: "border-top-width",
1491
+ value: { type: "unit", unit: "px", value: 1 }
1492
+ },
1493
+ {
1494
+ property: "border-right-width",
1495
+ value: { type: "unit", unit: "px", value: 1 }
1496
+ },
1497
+ {
1498
+ property: "border-bottom-width",
1499
+ value: { type: "unit", unit: "px", value: 1 }
1500
+ },
1501
+ {
1502
+ property: "border-left-width",
1503
+ value: { type: "unit", unit: "px", value: 1 }
1504
+ }
1505
+ ];
1506
+
1507
+ // src/runtime.ts
1508
+ var tagProperty = "data-ws-tag";
1509
+
1510
+ // src/__generated__/tags.ts
1511
+ var tags = [
1512
+ "div",
1513
+ "span",
1514
+ "a",
1515
+ "abbr",
1516
+ "address",
1517
+ "area",
1518
+ "article",
1519
+ "aside",
1520
+ "audio",
1521
+ "b",
1522
+ "bdi",
1523
+ "bdo",
1524
+ "blockquote",
1525
+ "body",
1526
+ "br",
1527
+ "button",
1528
+ "canvas",
1529
+ "caption",
1530
+ "cite",
1531
+ "code",
1532
+ "col",
1533
+ "colgroup",
1534
+ "data",
1535
+ "datalist",
1536
+ "dd",
1537
+ "del",
1538
+ "details",
1539
+ "dfn",
1540
+ "dialog",
1541
+ "dl",
1542
+ "dt",
1543
+ "em",
1544
+ "embed",
1545
+ "fieldset",
1546
+ "figcaption",
1547
+ "figure",
1548
+ "footer",
1549
+ "form",
1550
+ "h1",
1551
+ "h2",
1552
+ "h3",
1553
+ "h4",
1554
+ "h5",
1555
+ "h6",
1556
+ "head",
1557
+ "header",
1558
+ "hgroup",
1559
+ "hr",
1560
+ "html",
1561
+ "i",
1562
+ "iframe",
1563
+ "img",
1564
+ "input",
1565
+ "ins",
1566
+ "kbd",
1567
+ "label",
1568
+ "legend",
1569
+ "li",
1570
+ "main",
1571
+ "map",
1572
+ "mark",
1573
+ "menu",
1574
+ "meter",
1575
+ "nav",
1576
+ "object",
1577
+ "ol",
1578
+ "optgroup",
1579
+ "option",
1580
+ "output",
1581
+ "p",
1582
+ "picture",
1583
+ "pre",
1584
+ "progress",
1585
+ "q",
1586
+ "rp",
1587
+ "rt",
1588
+ "ruby",
1589
+ "s",
1590
+ "samp",
1591
+ "search",
1592
+ "section",
1593
+ "select",
1594
+ "slot",
1595
+ "small",
1596
+ "source",
1597
+ "strong",
1598
+ "sub",
1599
+ "summary",
1600
+ "sup",
1601
+ "table",
1602
+ "tbody",
1603
+ "td",
1604
+ "textarea",
1605
+ "tfoot",
1606
+ "th",
1607
+ "thead",
1608
+ "time",
1609
+ "tr",
1610
+ "track",
1611
+ "u",
1612
+ "ul",
1613
+ "var",
1614
+ "video",
1615
+ "wbr",
1616
+ "svg",
1617
+ "g",
1618
+ "defs",
1619
+ "desc",
1620
+ "symbol",
1621
+ "use",
1622
+ "image",
1623
+ "switch",
1624
+ "path",
1625
+ "rect",
1626
+ "circle",
1627
+ "ellipse",
1628
+ "line",
1629
+ "polyline",
1630
+ "polygon",
1631
+ "text",
1632
+ "tspan",
1633
+ "textPath",
1634
+ "marker",
1635
+ "linearGradient",
1636
+ "radialGradient",
1637
+ "stop",
1638
+ "pattern",
1639
+ "clipPath",
1640
+ "mask",
1641
+ "filter",
1642
+ "feDistantLight",
1643
+ "fePointLight",
1644
+ "feSpotLight",
1645
+ "feBlend",
1646
+ "feColorMatrix",
1647
+ "feComponentTransfer",
1648
+ "feFuncR",
1649
+ "feFuncG",
1650
+ "feFuncB",
1651
+ "feFuncA",
1652
+ "feComposite",
1653
+ "feConvolveMatrix",
1654
+ "feDiffuseLighting",
1655
+ "feDisplacementMap",
1656
+ "feFlood",
1657
+ "feGaussianBlur",
1658
+ "feImage",
1659
+ "feMerge",
1660
+ "feMergeNode",
1661
+ "feMorphology",
1662
+ "feOffset",
1663
+ "feSpecularLighting",
1664
+ "feTile",
1665
+ "feTurbulence",
1666
+ "view",
1667
+ "animate",
1668
+ "set",
1669
+ "animateMotion",
1670
+ "mpath",
1671
+ "animateTransform",
1672
+ "metadata",
1673
+ "foreignObject"
1674
+ ];
1675
+
1676
+ // src/core-metas.ts
1677
+ var rootComponent = "ws:root";
1678
+ var rootMeta = {
1679
+ label: "Global Root",
1680
+ icon: SettingsIcon,
1681
+ presetStyle: {
1682
+ html
1683
+ }
1684
+ };
1685
+ var elementComponent = "ws:element";
1686
+ var elementMeta = {
1687
+ label: "Element",
1688
+ // convert [object Module] to [object Object] to enable structured cloning
1689
+ presetStyle: { ...normalize_css_exports },
1690
+ initialProps: [tagProperty, "id", "class"],
1691
+ props: {
1692
+ [tagProperty]: {
1693
+ type: "string",
1694
+ control: "tag",
1695
+ required: true,
1696
+ options: tags
1697
+ }
1698
+ }
1699
+ };
1700
+ var portalComponent = "Slot";
1701
+ var collectionComponent = "ws:collection";
1702
+ var collectionMeta = {
1703
+ label: "Collection",
1704
+ icon: ListViewIcon,
1705
+ contentModel: {
1706
+ category: "instance",
1707
+ children: ["instance"]
1708
+ },
1709
+ initialProps: ["data"],
1710
+ props: {
1711
+ data: {
1712
+ required: true,
1713
+ control: "json",
1714
+ type: "json"
1715
+ }
1716
+ }
1717
+ };
1718
+ var descendantComponent = "ws:descendant";
1719
+ var descendantMeta = {
1720
+ label: "Descendant",
1721
+ icon: PaintBrushIcon,
1722
+ contentModel: {
1723
+ category: "none",
1724
+ children: []
1725
+ },
1726
+ // @todo infer possible presets
1727
+ presetStyle: {},
1728
+ initialProps: ["selector"],
1729
+ props: {
1730
+ selector: {
1731
+ required: true,
1732
+ type: "string",
1733
+ control: "select",
1734
+ options: [
1735
+ " p",
1736
+ " h1",
1737
+ " h2",
1738
+ " h3",
1739
+ " h4",
1740
+ " h5",
1741
+ " h6",
1742
+ " :where(strong, b)",
1743
+ " :where(em, i)",
1744
+ " a",
1745
+ " img",
1746
+ " blockquote",
1747
+ " code",
1748
+ " :where(ul, ol)",
1749
+ " li",
1750
+ " hr"
1751
+ ]
1752
+ }
1753
+ }
1754
+ };
1755
+ var blockComponent = "ws:block";
1756
+ var blockTemplateComponent = "ws:block-template";
1757
+ var blockTemplateMeta = {
1758
+ icon: AddTemplateInstanceIcon,
1759
+ contentModel: {
1760
+ category: "none",
1761
+ children: ["instance"]
1762
+ }
1763
+ };
1764
+ var blockMeta = {
1765
+ label: "Content Block",
1766
+ icon: ContentBlockIcon,
1767
+ contentModel: {
1768
+ category: "instance",
1769
+ children: [blockTemplateComponent, "instance"]
1770
+ }
1771
+ };
1772
+ var coreMetas = {
1773
+ [rootComponent]: rootMeta,
1774
+ [elementComponent]: elementMeta,
1775
+ [collectionComponent]: collectionMeta,
1776
+ [descendantComponent]: descendantMeta,
1777
+ [blockComponent]: blockMeta,
1778
+ [blockTemplateComponent]: blockTemplateMeta
1779
+ };
1780
+ var isCoreComponent = (component) => component === rootComponent || component === elementComponent || component === collectionComponent || component === descendantComponent || component === blockComponent || component === blockTemplateComponent;
1781
+ var isComponentDetachable = (component) => component !== rootComponent && component !== blockTemplateComponent && component !== descendantComponent;
1782
+
1783
+ // src/instances-utils.ts
1784
+ var ROOT_INSTANCE_ID = ":root";
1785
+ var traverseInstances = (instances, instanceId, callback) => {
1786
+ const instance = instances.get(instanceId);
1787
+ if (instance === void 0) {
1788
+ return;
1789
+ }
1790
+ const skipTraversingChildren = callback(instance);
1791
+ if (skipTraversingChildren === false) {
1792
+ return;
1793
+ }
1794
+ for (const child of instance.children) {
1795
+ if (child.type === "id") {
1796
+ traverseInstances(instances, child.value, callback);
1797
+ }
1798
+ }
1799
+ };
1800
+ var findTreeInstanceIds = (instances, rootInstanceId) => {
1801
+ const ids = /* @__PURE__ */ new Set([rootInstanceId]);
1802
+ traverseInstances(instances, rootInstanceId, (instance) => {
1803
+ ids.add(instance.id);
1804
+ });
1805
+ return ids;
1806
+ };
1807
+ var findTreeInstanceIdsExcludingSlotDescendants = (instances, rootInstanceId) => {
1808
+ const ids = /* @__PURE__ */ new Set([rootInstanceId]);
1809
+ traverseInstances(instances, rootInstanceId, (instance) => {
1810
+ ids.add(instance.id);
1811
+ if (instance.component === "Slot") {
1812
+ return false;
1813
+ }
1814
+ });
1815
+ return ids;
1816
+ };
1817
+ var parseComponentName = (componentName) => {
1818
+ const parts = componentName.split(":");
1819
+ let namespace;
1820
+ let name;
1821
+ if (parts.length === 1) {
1822
+ [name] = parts;
1823
+ } else {
1824
+ [namespace, name] = parts;
1825
+ }
1826
+ return [namespace, name];
1827
+ };
1828
+ var getIndexesWithinAncestors = (metas, instances, rootIds) => {
1829
+ const ancestors = /* @__PURE__ */ new Set();
1830
+ for (const meta of metas.values()) {
1831
+ if (meta.indexWithinAncestor !== void 0) {
1832
+ ancestors.add(meta.indexWithinAncestor);
1833
+ }
1834
+ }
1835
+ const indexes = /* @__PURE__ */ new Map();
1836
+ const traverseInstances2 = (instances2, instanceId, latestIndexes2 = /* @__PURE__ */ new Map()) => {
1837
+ const instance = instances2.get(instanceId);
1838
+ if (instance === void 0) {
1839
+ return;
1840
+ }
1841
+ const meta = metas.get(instance.component);
1842
+ if (ancestors.has(instance.component)) {
1843
+ latestIndexes2 = new Map(latestIndexes2);
1844
+ latestIndexes2.set(instance.component, /* @__PURE__ */ new Map());
1845
+ }
1846
+ if (instance.component === blockTemplateComponent) {
1847
+ latestIndexes2 = new Map(latestIndexes2);
1848
+ for (const key of latestIndexes2.keys()) {
1849
+ latestIndexes2.set(key, /* @__PURE__ */ new Map());
1850
+ }
1851
+ }
1852
+ if (meta?.indexWithinAncestor !== void 0) {
1853
+ const ancestorIndexes = latestIndexes2.get(meta.indexWithinAncestor);
1854
+ if (ancestorIndexes) {
1855
+ let index = ancestorIndexes.get(instance.component) ?? -1;
1856
+ index += 1;
1857
+ ancestorIndexes.set(instance.component, index);
1858
+ indexes.set(instance.id, index);
1859
+ }
1860
+ }
1861
+ for (const child of instance.children) {
1862
+ if (child.type === "id") {
1863
+ traverseInstances2(instances2, child.value, latestIndexes2);
1864
+ }
1865
+ }
1866
+ };
1867
+ const latestIndexes = /* @__PURE__ */ new Map();
1868
+ for (const instanceId of rootIds) {
1869
+ traverseInstances2(instances, instanceId, latestIndexes);
1870
+ }
1871
+ return indexes;
1872
+ };
1873
+
1874
+ // src/expression.ts
1875
+ import {
1876
+ parse,
1877
+ parseExpressionAt
1878
+ } from "acorn";
1879
+ import { simple } from "acorn-walk";
1880
+ var SYSTEM_VARIABLE_ID = ":system";
1881
+ var systemParameter = {
1882
+ id: SYSTEM_VARIABLE_ID,
1883
+ scopeInstanceId: ROOT_INSTANCE_ID,
1884
+ type: "parameter",
1885
+ name: "system"
1886
+ };
1887
+ var lintExpression = ({
1888
+ expression,
1889
+ availableVariables = /* @__PURE__ */ new Set(),
1890
+ allowAssignment = false
1891
+ }) => {
1892
+ const diagnostics = [];
1893
+ const addMessage = (message, severity = "error") => {
1894
+ return (node) => {
1895
+ diagnostics.push({
1896
+ // tune error position after wrapping expression with parentheses
1897
+ from: node.start - 1,
1898
+ to: node.end - 1,
1899
+ severity,
1900
+ message
1901
+ });
1902
+ };
1903
+ };
1904
+ if (expression.trim().length === 0) {
1905
+ diagnostics.push({
1906
+ from: 0,
1907
+ to: 0,
1908
+ severity: "error",
1909
+ message: "Expression cannot be empty"
1910
+ });
1911
+ return diagnostics;
1912
+ }
1913
+ try {
1914
+ const root = parse(`(${expression})`, {
1915
+ ecmaVersion: "latest",
1916
+ // support parsing import to forbid explicitly
1917
+ sourceType: "module"
1918
+ });
1919
+ simple(root, {
1920
+ Identifier(node) {
1921
+ if (availableVariables.has(node.name) === false) {
1922
+ addMessage(
1923
+ `"${node.name}" is not defined in the scope`,
1924
+ "warning"
1925
+ )(node);
1926
+ }
1927
+ },
1928
+ Literal() {
1929
+ },
1930
+ ArrayExpression() {
1931
+ },
1932
+ ObjectExpression() {
1933
+ },
1934
+ UnaryExpression() {
1935
+ },
1936
+ BinaryExpression() {
1937
+ },
1938
+ LogicalExpression() {
1939
+ },
1940
+ MemberExpression() {
1941
+ },
1942
+ ConditionalExpression() {
1943
+ },
1944
+ TemplateLiteral() {
1945
+ },
1946
+ ChainExpression() {
1947
+ },
1948
+ ParenthesizedExpression() {
1949
+ },
1950
+ AssignmentExpression(node) {
1951
+ if (allowAssignment === false) {
1952
+ addMessage("Assignment is supported only inside actions")(node);
1953
+ return;
1954
+ }
1955
+ simple(node.left, {
1956
+ Identifier(node2) {
1957
+ if (availableVariables.has(node2.name) === false) {
1958
+ addMessage(
1959
+ `"${node2.name}" is not defined in the scope`,
1960
+ "warning"
1961
+ )(node2);
1962
+ }
1963
+ }
1964
+ });
1965
+ },
1966
+ // parser forbids to yield inside module
1967
+ YieldExpression() {
1968
+ },
1969
+ ThisExpression: addMessage(`"this" keyword is not supported`),
1970
+ FunctionExpression: addMessage("Functions are not supported"),
1971
+ UpdateExpression: addMessage("Increment and decrement are not supported"),
1972
+ CallExpression: addMessage("Functions are not supported"),
1973
+ NewExpression: addMessage("Classes are not supported"),
1974
+ SequenceExpression: addMessage(`Only single expression is supported`),
1975
+ ArrowFunctionExpression: addMessage("Functions are not supported"),
1976
+ TaggedTemplateExpression: addMessage("Tagged template is not supported"),
1977
+ ClassExpression: addMessage("Classes are not supported"),
1978
+ MetaProperty: addMessage("Imports are not supported"),
1979
+ AwaitExpression: addMessage(`"await" keyword is not supported`),
1980
+ ImportExpression: addMessage("Imports are not supported")
1981
+ });
1982
+ } catch (error) {
1983
+ const castedError = error;
1984
+ diagnostics.push({
1985
+ // tune error position after wrapping expression with parentheses
1986
+ from: castedError.pos - 1,
1987
+ to: castedError.pos - 1,
1988
+ severity: "error",
1989
+ // trim auto generated error location
1990
+ // to not conflict with tuned position
1991
+ message: castedError.message.replaceAll(/\s+\(\d+:\d+\)$/g, "")
1992
+ });
1993
+ }
1994
+ return diagnostics;
1995
+ };
1996
+ var isLiteralNode = (node) => {
1997
+ if (node.type === "Identifier" && node.name === "undefined") {
1998
+ return true;
1999
+ }
2000
+ if (node.type === "Literal") {
2001
+ return true;
2002
+ }
2003
+ if (node.type === "ArrayExpression") {
2004
+ return node.elements.every((node2) => {
2005
+ if (node2 === null || node2.type === "SpreadElement") {
2006
+ return false;
2007
+ }
2008
+ return isLiteralNode(node2);
2009
+ });
2010
+ }
2011
+ if (node.type === "ObjectExpression") {
2012
+ return node.properties.every((property) => {
2013
+ if (property.type === "SpreadElement") {
2014
+ return false;
2015
+ }
2016
+ const key = property.key;
2017
+ const isIdentifierKey = key.type === "Identifier" && property.computed === false;
2018
+ const isLiteralKey = key.type === "Literal";
2019
+ return (isLiteralKey || isIdentifierKey) && isLiteralNode(property.value);
2020
+ });
2021
+ }
2022
+ return false;
2023
+ };
2024
+ var isLiteralExpression = (expression) => {
2025
+ try {
2026
+ const node = parseExpressionAt(expression, 0, { ecmaVersion: "latest" });
2027
+ return isLiteralNode(node);
2028
+ } catch {
2029
+ return false;
2030
+ }
2031
+ };
2032
+ var getExpressionIdentifiers = (expression) => {
2033
+ const identifiers2 = /* @__PURE__ */ new Set();
2034
+ try {
2035
+ const root = parseExpressionAt(expression, 0, { ecmaVersion: "latest" });
2036
+ simple(root, {
2037
+ Identifier: (node) => identifiers2.add(node.name),
2038
+ AssignmentExpression(node) {
2039
+ simple(node.left, {
2040
+ Identifier: (node2) => identifiers2.add(node2.name)
2041
+ });
2042
+ }
2043
+ });
2044
+ } catch {
2045
+ }
2046
+ return identifiers2;
2047
+ };
2048
+ var transpileExpression = ({
2049
+ expression,
2050
+ executable = false,
2051
+ replaceVariable
2052
+ }) => {
2053
+ let root;
2054
+ try {
2055
+ root = parseExpressionAt(expression, 0, { ecmaVersion: "latest" });
2056
+ } catch (error) {
2057
+ const message = error.message;
2058
+ throw Error(`${message} in ${JSON.stringify(expression)}`);
2059
+ }
2060
+ const replacements = [];
2061
+ const replaceIdentifier = (node, assignee) => {
2062
+ const newName = replaceVariable?.(node.name, assignee);
2063
+ if (newName) {
2064
+ replacements.push([node.start, node.end, newName]);
2065
+ }
2066
+ };
2067
+ simple(root, {
2068
+ Identifier: (node) => replaceIdentifier(node, false),
2069
+ AssignmentExpression(node) {
2070
+ simple(node.left, {
2071
+ Identifier: (node2) => replaceIdentifier(node2, true)
2072
+ });
2073
+ },
2074
+ MemberExpression(node) {
2075
+ if (executable === false || node.optional) {
2076
+ return;
2077
+ }
2078
+ if (node.computed === false) {
2079
+ const dotIndex = expression.indexOf(".", node.object.end);
2080
+ replacements.push([dotIndex, dotIndex, "?"]);
2081
+ }
2082
+ if (node.computed === true) {
2083
+ const dotIndex = expression.indexOf("[", node.object.end);
2084
+ replacements.push([dotIndex, dotIndex, "?."]);
2085
+ }
2086
+ }
2087
+ });
2088
+ replacements.sort(([leftStart], [rightStart]) => rightStart - leftStart);
2089
+ for (const [start, end, fragment] of replacements) {
2090
+ const before = expression.slice(0, start);
2091
+ const after = expression.slice(end);
2092
+ expression = before + fragment + after;
2093
+ }
2094
+ return expression;
2095
+ };
2096
+ var parseObjectExpression = (expression) => {
2097
+ const map = /* @__PURE__ */ new Map();
2098
+ let root;
2099
+ try {
2100
+ root = parseExpressionAt(expression, 0, { ecmaVersion: "latest" });
2101
+ } catch (error) {
2102
+ return map;
2103
+ }
2104
+ if (root.type !== "ObjectExpression") {
2105
+ return map;
2106
+ }
2107
+ for (const property of root.properties) {
2108
+ if (property.type === "SpreadElement") {
2109
+ continue;
2110
+ }
2111
+ if (property.computed) {
2112
+ continue;
2113
+ }
2114
+ let key;
2115
+ if (property.key.type === "Identifier") {
2116
+ key = property.key.name;
2117
+ } else if (property.key.type === "Literal" && typeof property.key.value === "string") {
2118
+ key = property.key.value;
2119
+ } else {
2120
+ continue;
2121
+ }
2122
+ const valueExpression = expression.slice(
2123
+ property.value.start,
2124
+ property.value.end
2125
+ );
2126
+ map.set(key, valueExpression);
2127
+ }
2128
+ return map;
2129
+ };
2130
+ var generateObjectExpression = (map) => {
2131
+ let generated = "{\n";
2132
+ for (const [key, valueExpression] of map) {
2133
+ const keyExpression = JSON.stringify(key);
2134
+ generated += ` ${keyExpression}: ${valueExpression},
2135
+ `;
2136
+ }
2137
+ generated += `}`;
2138
+ return generated;
2139
+ };
2140
+ var dataSourceVariablePrefix = "$ws$dataSource$";
2141
+ var encodeDataVariableId = (id) => {
2142
+ if (id === SYSTEM_VARIABLE_ID) {
2143
+ return "$ws$system";
2144
+ }
2145
+ const encoded = id.replaceAll("-", "__DASH__");
2146
+ return `${dataSourceVariablePrefix}${encoded}`;
2147
+ };
2148
+ var decodeDataVariableId = (name) => {
2149
+ if (name === "$ws$system") {
2150
+ return SYSTEM_VARIABLE_ID;
2151
+ }
2152
+ if (name.startsWith(dataSourceVariablePrefix)) {
2153
+ const encoded = name.slice(dataSourceVariablePrefix.length);
2154
+ return encoded.replaceAll("__DASH__", "-");
2155
+ }
2156
+ return;
2157
+ };
2158
+ var generateExpression = ({
2159
+ expression,
2160
+ dataSources,
2161
+ usedDataSources,
2162
+ scope
2163
+ }) => {
2164
+ return transpileExpression({
2165
+ expression,
2166
+ executable: true,
2167
+ replaceVariable: (identifier) => {
2168
+ const depId = decodeDataVariableId(identifier);
2169
+ let dep = depId ? dataSources.get(depId) : void 0;
2170
+ if (depId === SYSTEM_VARIABLE_ID) {
2171
+ dep = systemParameter;
2172
+ }
2173
+ if (dep) {
2174
+ usedDataSources?.set(dep.id, dep);
2175
+ return scope.getName(dep.id, dep.name);
2176
+ }
2177
+ return "undefined";
2178
+ }
2179
+ });
2180
+ };
2181
+ var executeExpression = (expression) => {
2182
+ try {
2183
+ const fn = new Function(`return (${expression})`);
2184
+ return fn();
2185
+ } catch {
2186
+ }
2187
+ };
2188
+
2189
+ // src/url-pattern.ts
2190
+ var tokenRegex = /:(?<name>\w+)(?<modifier>[?*]?)|(?<wildcard>(?<!:\w+)\*)/;
2191
+ var isPathnamePattern = (pathname) => tokenRegex.test(pathname);
2192
+ var tokenRegexGlobal = new RegExp(tokenRegex.source, "g");
2193
+ var matchPathnameParams = (pathname) => {
2194
+ return pathname.matchAll(tokenRegexGlobal);
2195
+ };
2196
+
2197
+ // src/page-utils.ts
2198
+ var ROOT_FOLDER_ID = "root";
2199
+ var isRootFolder = ({ id }) => id === ROOT_FOLDER_ID;
2200
+ var findPageByIdOrPath = (idOrPath, pages) => {
2201
+ if (idOrPath === "" || idOrPath === "/" || idOrPath === pages.homePage.id) {
2202
+ return pages.homePage;
2203
+ }
2204
+ return pages.pages.find(
2205
+ (page) => page.id === idOrPath || getPagePath(page.id, pages) === idOrPath
2206
+ );
2207
+ };
2208
+ var findParentFolderByChildId = (id, folders) => {
2209
+ for (const folder of folders) {
2210
+ if (folder.children.includes(id)) {
2211
+ return folder;
2212
+ }
2213
+ }
2214
+ };
2215
+ var getPagePath = (id, pages) => {
2216
+ const foldersMap = /* @__PURE__ */ new Map();
2217
+ const childParentMap = /* @__PURE__ */ new Map();
2218
+ for (const folder of pages.folders) {
2219
+ foldersMap.set(folder.id, folder);
2220
+ for (const childId of folder.children) {
2221
+ childParentMap.set(childId, folder.id);
2222
+ }
2223
+ }
2224
+ const paths = [];
2225
+ let currentId = id;
2226
+ const allPages = [pages.homePage, ...pages.pages];
2227
+ for (const page of allPages) {
2228
+ if (page.id === id) {
2229
+ paths.push(page.path);
2230
+ currentId = childParentMap.get(page.id);
2231
+ break;
2232
+ }
2233
+ }
2234
+ while (currentId) {
2235
+ const folder = foldersMap.get(currentId);
2236
+ if (folder === void 0) {
2237
+ break;
2238
+ }
2239
+ paths.push(folder.slug);
2240
+ currentId = childParentMap.get(currentId);
2241
+ }
2242
+ return paths.reverse().join("/").replace(/\/+/g, "/");
2243
+ };
2244
+ var getStaticSiteMapXml = (pages, updatedAt) => {
2245
+ const allPages = [pages.homePage, ...pages.pages];
2246
+ return allPages.filter((page) => (page.meta.documentType ?? "html") === "html").filter(
2247
+ (page) => executeExpression(page.meta.excludePageFromSearch) !== true
2248
+ ).filter((page) => false === isPathnamePattern(page.path)).map((page) => ({
2249
+ path: getPagePath(page.id, pages),
2250
+ lastModified: updatedAt.split("T")[0]
2251
+ }));
2252
+ };
2253
+
2254
+ // src/scope.ts
2255
+ import reservedIdentifiers from "reserved-identifiers";
2256
+ var identifiers = reservedIdentifiers({ includeGlobalProperties: true });
2257
+ var isReserved = (identifier) => identifiers.has(identifier);
2258
+ var normalizeJsName = (name) => {
2259
+ name = name.replaceAll(/[^\w$]/g, "");
2260
+ if (name.length === 0) {
2261
+ return "_";
2262
+ }
2263
+ if (/[A-Za-z_$]/.test(name[0]) === false) {
2264
+ name = `_${name}`;
2265
+ }
2266
+ if (isReserved(name)) {
2267
+ return `${name}_`;
2268
+ }
2269
+ return name;
2270
+ };
2271
+ var createScope = (occupiedIdentifiers = [], normalizeName = normalizeJsName, separator = "_") => {
2272
+ const nameById = /* @__PURE__ */ new Map();
2273
+ const usedNames = /* @__PURE__ */ new Set();
2274
+ for (const identifier of occupiedIdentifiers) {
2275
+ usedNames.add(identifier);
2276
+ }
2277
+ const getName = (id, preferredName) => {
2278
+ const cachedName = nameById.get(id);
2279
+ if (cachedName !== void 0) {
2280
+ return cachedName;
2281
+ }
2282
+ preferredName = normalizeName(preferredName);
2283
+ let index = 0;
2284
+ let scopedName = preferredName;
2285
+ while (usedNames.has(scopedName)) {
2286
+ index += 1;
2287
+ scopedName = `${preferredName}${separator}${index}`;
2288
+ }
2289
+ nameById.set(id, scopedName);
2290
+ usedNames.add(scopedName);
2291
+ return scopedName;
2292
+ };
2293
+ return {
2294
+ getName
2295
+ };
2296
+ };
2297
+
2298
+ // src/resources-generator.ts
2299
+ var generateResources = ({
2300
+ scope,
2301
+ page,
2302
+ dataSources,
2303
+ props,
2304
+ resources
2305
+ }) => {
2306
+ const usedDataSources = /* @__PURE__ */ new Map();
2307
+ let generatedRequests = "";
2308
+ for (const resource of resources.values()) {
2309
+ let generatedRequest = "";
2310
+ const resourceName = scope.getName(resource.id, resource.name);
2311
+ generatedRequest += ` const ${resourceName}: ResourceRequest = {
2312
+ `;
2313
+ generatedRequest += ` id: "${resource.id}",
2314
+ `;
2315
+ generatedRequest += ` name: ${JSON.stringify(resource.name)},
2316
+ `;
2317
+ const url = generateExpression({
2318
+ expression: resource.url,
2319
+ dataSources,
2320
+ usedDataSources,
2321
+ scope
2322
+ });
2323
+ generatedRequest += ` url: ${url},
2324
+ `;
2325
+ generatedRequest += ` method: "${resource.method}",
2326
+ `;
2327
+ generatedRequest += ` headers: [
2328
+ `;
2329
+ for (const header2 of resource.headers) {
2330
+ const value = generateExpression({
2331
+ expression: header2.value,
2332
+ dataSources,
2333
+ usedDataSources,
2334
+ scope
2335
+ });
2336
+ generatedRequest += ` { name: "${header2.name}", value: ${value} },
2337
+ `;
2338
+ }
2339
+ generatedRequest += ` ],
2340
+ `;
2341
+ if (resource.body !== void 0 && resource.body.length > 0) {
2342
+ const body2 = generateExpression({
2343
+ expression: resource.body,
2344
+ dataSources,
2345
+ usedDataSources,
2346
+ scope
2347
+ });
2348
+ generatedRequest += ` body: ${body2},
2349
+ `;
2350
+ }
2351
+ generatedRequest += ` }
2352
+ `;
2353
+ generatedRequests += generatedRequest;
2354
+ }
2355
+ let generatedVariables = "";
2356
+ for (const dataSource of usedDataSources.values()) {
2357
+ if (dataSource.type === "variable") {
2358
+ const name = scope.getName(dataSource.id, dataSource.name);
2359
+ const value = JSON.stringify(dataSource.value.value);
2360
+ generatedVariables += ` let ${name} = ${value}
2361
+ `;
2362
+ }
2363
+ if (dataSource.type === "parameter") {
2364
+ if (dataSource.id === page.systemDataSourceId || dataSource.id === SYSTEM_VARIABLE_ID) {
2365
+ const name = scope.getName(dataSource.id, dataSource.name);
2366
+ generatedVariables += ` const ${name} = _props.system
2367
+ `;
2368
+ }
2369
+ }
2370
+ }
2371
+ let generated = "";
2372
+ generated += `import type { System, ResourceRequest } from "@webstudio-is/sdk";
2373
+ `;
2374
+ generated += `export const getResources = (_props: { system: System }) => {
2375
+ `;
2376
+ generated += generatedVariables;
2377
+ generated += generatedRequests;
2378
+ generated += ` const _data = new Map<string, ResourceRequest>([
2379
+ `;
2380
+ for (const dataSource of dataSources.values()) {
2381
+ if (dataSource.type === "resource") {
2382
+ const name = scope.getName(dataSource.resourceId, dataSource.name);
2383
+ generated += ` ["${name}", ${name}],
2384
+ `;
2385
+ }
2386
+ }
2387
+ generated += ` ])
2388
+ `;
2389
+ generated += ` const _action = new Map<string, ResourceRequest>([
2390
+ `;
2391
+ for (const prop of props.values()) {
2392
+ if (prop.type === "resource") {
2393
+ const name = scope.getName(prop.value, prop.name);
2394
+ generated += ` ["${name}", ${name}],
2395
+ `;
2396
+ }
2397
+ }
2398
+ generated += ` ])
2399
+ `;
2400
+ generated += ` return { data: _data, action: _action }
2401
+ `;
2402
+ generated += `}
2403
+ `;
2404
+ return generated;
2405
+ };
2406
+ var getMethod = (value) => {
2407
+ switch (value?.toLowerCase()) {
2408
+ case "get":
2409
+ return "get";
2410
+ case "delete":
2411
+ return "delete";
2412
+ case "put":
2413
+ return "put";
2414
+ default:
2415
+ return "post";
2416
+ }
2417
+ };
2418
+ var replaceFormActionsWithResources = ({
2419
+ props,
2420
+ instances,
2421
+ resources
2422
+ }) => {
2423
+ const formProps = /* @__PURE__ */ new Map();
2424
+ for (const prop of props.values()) {
2425
+ if (prop.name === "method" && prop.type === "string" && instances.get(prop.instanceId)?.component === "Form") {
2426
+ let data = formProps.get(prop.instanceId);
2427
+ if (data === void 0) {
2428
+ data = {};
2429
+ formProps.set(prop.instanceId, data);
2430
+ }
2431
+ data.method = prop.value;
2432
+ props.delete(prop.id);
2433
+ }
2434
+ if (prop.name === "action" && prop.type === "string" && prop.value && instances.get(prop.instanceId)?.component === "Form") {
2435
+ let data = formProps.get(prop.instanceId);
2436
+ if (data === void 0) {
2437
+ data = {};
2438
+ formProps.set(prop.instanceId, data);
2439
+ }
2440
+ data.action = prop.value;
2441
+ props.set(prop.id, {
2442
+ id: prop.id,
2443
+ instanceId: prop.instanceId,
2444
+ name: prop.name,
2445
+ type: "resource",
2446
+ value: prop.instanceId
2447
+ });
2448
+ }
2449
+ }
2450
+ for (const [instanceId, { action, method }] of formProps) {
2451
+ if (action) {
2452
+ resources.set(instanceId, {
2453
+ id: instanceId,
2454
+ name: "action",
2455
+ method: getMethod(method),
2456
+ url: JSON.stringify(action),
2457
+ headers: [
2458
+ { name: "Content-Type", value: JSON.stringify("application/json") }
2459
+ ]
2460
+ });
2461
+ }
2462
+ }
2463
+ };
2464
+
2465
+ // src/page-meta-generator.ts
2466
+ var generatePageMeta = ({
2467
+ globalScope,
2468
+ page,
2469
+ dataSources,
2470
+ assets
2471
+ }) => {
2472
+ const localScope = createScope(["system", "resources"]);
2473
+ const usedDataSources = /* @__PURE__ */ new Map();
2474
+ const titleExpression = generateExpression({
2475
+ expression: page.title,
2476
+ dataSources,
2477
+ usedDataSources,
2478
+ scope: localScope
2479
+ });
2480
+ const descriptionExpression = generateExpression({
2481
+ expression: page.meta.description ?? "undefined",
2482
+ dataSources,
2483
+ usedDataSources,
2484
+ scope: localScope
2485
+ });
2486
+ const excludePageFromSearchExpression = generateExpression({
2487
+ expression: page.meta.excludePageFromSearch ?? "undefined",
2488
+ dataSources,
2489
+ usedDataSources,
2490
+ scope: localScope
2491
+ });
2492
+ const languageExpression = generateExpression({
2493
+ expression: page.meta.language ?? "undefined",
2494
+ dataSources,
2495
+ usedDataSources,
2496
+ scope: localScope
2497
+ });
2498
+ const socialImageAssetNameExpression = JSON.stringify(
2499
+ page.meta.socialImageAssetId ? assets.get(page.meta.socialImageAssetId)?.name : void 0
2500
+ );
2501
+ const socialImageUrlExpression = generateExpression({
2502
+ expression: page.meta.socialImageUrl ?? "undefined",
2503
+ dataSources,
2504
+ usedDataSources,
2505
+ scope: localScope
2506
+ });
2507
+ const statusExpression = generateExpression({
2508
+ expression: page.meta.status ?? "undefined",
2509
+ dataSources,
2510
+ usedDataSources,
2511
+ scope: localScope
2512
+ });
2513
+ const redirectExpression = generateExpression({
2514
+ expression: page.meta.redirect ?? "undefined",
2515
+ dataSources,
2516
+ usedDataSources,
2517
+ scope: localScope
2518
+ });
2519
+ let customExpression = "";
2520
+ customExpression += `[
2521
+ `;
2522
+ for (const customMeta of page.meta.custom ?? []) {
2523
+ if (customMeta.property.trim().length === 0) {
2524
+ continue;
2525
+ }
2526
+ const propertyExpression = JSON.stringify(customMeta.property);
2527
+ const contentExpression = generateExpression({
2528
+ expression: customMeta.content,
2529
+ dataSources,
2530
+ usedDataSources,
2531
+ scope: localScope
2532
+ });
2533
+ customExpression += ` {
2534
+ `;
2535
+ customExpression += ` property: ${propertyExpression},
2536
+ `;
2537
+ customExpression += ` content: ${contentExpression},
2538
+ `;
2539
+ customExpression += ` },
2540
+ `;
2541
+ }
2542
+ customExpression += ` ]`;
2543
+ let generated = "";
2544
+ generated += `export const getPageMeta = ({
2545
+ `;
2546
+ generated += ` system,
2547
+ `;
2548
+ generated += ` resources,
2549
+ `;
2550
+ generated += `}: {
2551
+ `;
2552
+ generated += ` system: System;
2553
+ `;
2554
+ generated += ` resources: Record<string, any>;
2555
+ `;
2556
+ generated += `}): PageMeta => {
2557
+ `;
2558
+ for (const dataSource of usedDataSources.values()) {
2559
+ if (dataSource.type === "variable") {
2560
+ const valueName = localScope.getName(dataSource.id, dataSource.name);
2561
+ const initialValueString = JSON.stringify(dataSource.value.value);
2562
+ generated += ` let ${valueName} = ${initialValueString}
2563
+ `;
2564
+ continue;
2565
+ }
2566
+ if (dataSource.type === "parameter") {
2567
+ if (dataSource.id === page.systemDataSourceId || dataSource.id === SYSTEM_VARIABLE_ID) {
2568
+ const valueName = localScope.getName(dataSource.id, dataSource.name);
2569
+ generated += ` let ${valueName} = system
2570
+ `;
2571
+ }
2572
+ continue;
2573
+ }
2574
+ if (dataSource.type === "resource") {
2575
+ const valueName = localScope.getName(dataSource.id, dataSource.name);
2576
+ const resourceName = globalScope.getName(
2577
+ dataSource.resourceId,
2578
+ dataSource.name
2579
+ );
2580
+ generated += ` let ${valueName} = resources.${resourceName}
2581
+ `;
2582
+ continue;
2583
+ }
2584
+ }
2585
+ generated += ` return {
2586
+ `;
2587
+ generated += ` title: ${titleExpression},
2588
+ `;
2589
+ generated += ` description: ${descriptionExpression},
2590
+ `;
2591
+ generated += ` excludePageFromSearch: ${excludePageFromSearchExpression},
2592
+ `;
2593
+ generated += ` language: ${languageExpression},
2594
+ `;
2595
+ generated += ` socialImageAssetName: ${socialImageAssetNameExpression},
2596
+ `;
2597
+ generated += ` socialImageUrl: ${socialImageUrlExpression},
2598
+ `;
2599
+ generated += ` status: ${statusExpression},
2600
+ `;
2601
+ generated += ` redirect: ${redirectExpression},
2602
+ `;
2603
+ generated += ` custom: ${customExpression},
2604
+ `;
2605
+ generated += ` };
2606
+ `;
2607
+ generated += `};
2608
+ `;
2609
+ return generated;
2610
+ };
2611
+
2612
+ // src/css.ts
2613
+ import { kebabCase } from "change-case";
2614
+ import {
2615
+ createRegularStyleSheet,
2616
+ generateAtomic
2617
+ } from "@webstudio-is/css-engine";
2618
+ import { getFontFaces } from "@webstudio-is/fonts";
2619
+ var addFontRules = ({
2620
+ sheet,
2621
+ assets,
2622
+ assetBaseUrl
2623
+ }) => {
2624
+ const fontAssets = [];
2625
+ for (const asset of assets.values()) {
2626
+ if (asset.type === "font") {
2627
+ fontAssets.push(asset);
2628
+ }
2629
+ }
2630
+ const fontFaces = getFontFaces(fontAssets, { assetBaseUrl });
2631
+ for (const fontFace of fontFaces) {
2632
+ sheet.addFontFaceRule(fontFace);
2633
+ }
2634
+ };
2635
+ var createImageValueTransformer = (assets, { assetBaseUrl }) => (styleValue) => {
2636
+ if (styleValue.type === "image" && styleValue.value.type === "asset") {
2637
+ const asset = assets.get(styleValue.value.value);
2638
+ if (asset === void 0) {
2639
+ return { type: "keyword", value: "none" };
2640
+ }
2641
+ const url = `${assetBaseUrl}${asset.name}`;
2642
+ return {
2643
+ type: "image",
2644
+ value: {
2645
+ type: "url",
2646
+ url
2647
+ },
2648
+ hidden: styleValue.hidden
2649
+ };
2650
+ }
2651
+ };
2652
+ var normalizeClassName = (name) => kebabCase(name);
2653
+ var generateCss = ({
2654
+ assets,
2655
+ instances,
2656
+ props,
2657
+ breakpoints,
2658
+ styles,
2659
+ styleSourceSelections,
2660
+ componentMetas,
2661
+ assetBaseUrl,
2662
+ atomic
2663
+ }) => {
2664
+ const fontSheet = createRegularStyleSheet({ name: "ssr" });
2665
+ const presetSheet = createRegularStyleSheet({ name: "ssr" });
2666
+ const userSheet = createRegularStyleSheet({ name: "ssr" });
2667
+ addFontRules({ sheet: fontSheet, assets, assetBaseUrl });
2668
+ presetSheet.addMediaRule("presets");
2669
+ const presetClasses = /* @__PURE__ */ new Map();
2670
+ const scope = createScope([], normalizeClassName, "-");
2671
+ const tagsByComponent = /* @__PURE__ */ new Map();
2672
+ tagsByComponent.set(rootComponent, /* @__PURE__ */ new Set(["html"]));
2673
+ const tagByInstanceId = /* @__PURE__ */ new Map();
2674
+ for (const prop of props.values()) {
2675
+ if (prop.type === "string" && prop.name === "tag") {
2676
+ tagByInstanceId.set(prop.instanceId, prop.value);
2677
+ }
2678
+ }
2679
+ for (const instance of instances.values()) {
2680
+ const propTag = tagByInstanceId.get(instance.id);
2681
+ const meta = componentMetas.get(instance.component);
2682
+ const metaTag = Object.keys(meta?.presetStyle ?? {}).at(0);
2683
+ let componentTags = tagsByComponent.get(instance.component);
2684
+ if (componentTags === void 0) {
2685
+ componentTags = /* @__PURE__ */ new Set();
2686
+ tagsByComponent.set(instance.component, componentTags);
2687
+ }
2688
+ const tag = instance.tag ?? propTag ?? metaTag;
2689
+ if (tag) {
2690
+ componentTags.add(tag);
2691
+ }
2692
+ }
2693
+ for (const [component, meta] of componentMetas) {
2694
+ const componentTags = tagsByComponent.get(component);
2695
+ const [_namespace, componentName] = parseComponentName(component);
2696
+ const className = `w-${scope.getName(component, meta.label ?? componentName)}`;
2697
+ const presetStyle = Object.entries(meta.presetStyle ?? {});
2698
+ if (presetStyle.length > 0) {
2699
+ presetClasses.set(component, className);
2700
+ }
2701
+ for (const [tag, styles2] of presetStyle) {
2702
+ if (!componentTags?.has(tag)) {
2703
+ continue;
2704
+ }
2705
+ const selector = component === rootComponent ? ":root" : `${tag}.${className}`;
2706
+ const rule = presetSheet.addNestingRule(selector);
2707
+ for (const declaration of styles2) {
2708
+ rule.setDeclaration({
2709
+ breakpoint: "presets",
2710
+ selector: declaration.state ?? "",
2711
+ property: declaration.property,
2712
+ value: declaration.value
2713
+ });
2714
+ }
2715
+ }
2716
+ }
2717
+ for (const breakpoint of breakpoints.values()) {
2718
+ userSheet.addMediaRule(breakpoint.id, breakpoint);
2719
+ }
2720
+ const imageValueTransformer = createImageValueTransformer(assets, {
2721
+ assetBaseUrl
2722
+ });
2723
+ userSheet.setTransformer(imageValueTransformer);
2724
+ for (const styleDecl of styles.values()) {
2725
+ const rule = userSheet.addMixinRule(styleDecl.styleSourceId);
2726
+ rule.setDeclaration({
2727
+ breakpoint: styleDecl.breakpointId,
2728
+ selector: styleDecl.state ?? "",
2729
+ property: styleDecl.property,
2730
+ value: styleDecl.value
2731
+ });
2732
+ }
2733
+ const classes = /* @__PURE__ */ new Map();
2734
+ const parentIdByInstanceId = /* @__PURE__ */ new Map();
2735
+ for (const instance of instances.values()) {
2736
+ const presetClass = presetClasses.get(instance.component);
2737
+ if (presetClass) {
2738
+ classes.set(instance.id, [presetClass]);
2739
+ }
2740
+ for (const child of instance.children) {
2741
+ if (child.type === "id") {
2742
+ parentIdByInstanceId.set(child.value, instance.id);
2743
+ }
2744
+ }
2745
+ }
2746
+ const descendantSelectorByInstanceId = /* @__PURE__ */ new Map();
2747
+ for (const prop of props.values()) {
2748
+ if (prop.name === "selector" && prop.type === "string") {
2749
+ descendantSelectorByInstanceId.set(prop.instanceId, prop.value);
2750
+ }
2751
+ }
2752
+ const instanceByRule = /* @__PURE__ */ new Map();
2753
+ for (const selection of styleSourceSelections.values()) {
2754
+ let { instanceId } = selection;
2755
+ const { values } = selection;
2756
+ if (instanceId === ROOT_INSTANCE_ID) {
2757
+ const rule2 = userSheet.addNestingRule(`:root`);
2758
+ rule2.applyMixins(values);
2759
+ continue;
2760
+ }
2761
+ let descendantSuffix = "";
2762
+ const instance = instances.get(instanceId);
2763
+ if (instance === void 0) {
2764
+ continue;
2765
+ }
2766
+ if (instance.component === descendantComponent) {
2767
+ const parentId = parentIdByInstanceId.get(instanceId);
2768
+ const descendantSelector = descendantSelectorByInstanceId.get(instanceId);
2769
+ if (parentId && descendantSelector) {
2770
+ descendantSuffix = descendantSelector;
2771
+ instanceId = parentId;
2772
+ }
2773
+ }
2774
+ const meta = componentMetas.get(instance.component);
2775
+ const [_namespace, shortName] = parseComponentName(instance.component);
2776
+ const baseName = instance.label ?? meta?.label ?? shortName;
2777
+ const className = `w-${scope.getName(instanceId, baseName)}`;
2778
+ if (atomic === false) {
2779
+ let classList = classes.get(instanceId);
2780
+ if (classList === void 0) {
2781
+ classList = [];
2782
+ classes.set(instanceId, classList);
2783
+ }
2784
+ classList.push(className);
2785
+ }
2786
+ const rule = userSheet.addNestingRule(`.${className}`, descendantSuffix);
2787
+ rule.applyMixins(values);
2788
+ instanceByRule.set(rule, instanceId);
2789
+ }
2790
+ const fontCss = fontSheet.cssText;
2791
+ const presetCss = presetSheet.cssText.replaceAll(
2792
+ "@media all ",
2793
+ "@layer presets "
2794
+ );
2795
+ if (atomic) {
2796
+ const { cssText } = generateAtomic(userSheet, {
2797
+ getKey: (rule) => instanceByRule.get(rule),
2798
+ transformValue: imageValueTransformer,
2799
+ classes
2800
+ });
2801
+ return {
2802
+ cssText: `${fontCss}${presetCss}
2803
+ ${cssText}`,
2804
+ classes
2805
+ };
2806
+ }
2807
+ return {
2808
+ cssText: `${fontCss}${presetCss}
2809
+ ${userSheet.cssText}`,
2810
+ classes
2811
+ };
2812
+ };
2813
+ export {
2814
+ Asset,
2815
+ Assets,
2816
+ Breakpoint,
2817
+ Breakpoints,
2818
+ CompilerSettings,
2819
+ ComponentState,
2820
+ ContentModel,
2821
+ DataSource,
2822
+ DataSourceVariableValue,
2823
+ DataSources,
2824
+ Deployment,
2825
+ ExpressionChild,
2826
+ Folder,
2827
+ FolderName,
2828
+ FontAsset,
2829
+ HomePagePath,
2830
+ IdChild,
2831
+ ImageAsset,
2832
+ ImageMeta,
2833
+ Instance,
2834
+ InstanceChild,
2835
+ Instances,
2836
+ OldPagePath,
2837
+ PageName,
2838
+ PagePath,
2839
+ PageRedirect,
2840
+ PageTitle,
2841
+ Pages,
2842
+ PresetStyleDecl,
2843
+ ProjectNewRedirectPath,
2844
+ Prop,
2845
+ PropMeta,
2846
+ Props,
2847
+ RANGE_UNITS,
2848
+ ROOT_FOLDER_ID,
2849
+ ROOT_INSTANCE_ID,
2850
+ Resource,
2851
+ ResourceRequest,
2852
+ Resources,
2853
+ SYSTEM_VARIABLE_ID,
2854
+ StyleDecl,
2855
+ StyleSource,
2856
+ StyleSourceSelection,
2857
+ StyleSourceSelections,
2858
+ StyleSources,
2859
+ Styles,
2860
+ Templates,
2861
+ TextChild,
2862
+ WebstudioFragment,
2863
+ WsComponentMeta,
2864
+ addFontRules,
2865
+ animationActionSchema,
2866
+ animationKeyframeSchema,
2867
+ blockComponent,
2868
+ blockTemplateComponent,
2869
+ blockTemplateMeta,
2870
+ collectionComponent,
2871
+ componentCategories,
2872
+ coreMetas,
2873
+ createImageValueTransformer,
2874
+ createScope,
2875
+ decodeDataVariableId as decodeDataSourceVariable,
2876
+ decodeDataVariableId,
2877
+ descendantComponent,
2878
+ documentTypes,
2879
+ durationUnitValueSchema,
2880
+ elementComponent,
2881
+ encodeDataVariableId as encodeDataSourceVariable,
2882
+ encodeDataVariableId,
2883
+ executeExpression,
2884
+ findPageByIdOrPath,
2885
+ findParentFolderByChildId,
2886
+ findTreeInstanceIds,
2887
+ findTreeInstanceIdsExcludingSlotDescendants,
2888
+ generateCss,
2889
+ generateExpression,
2890
+ generateObjectExpression,
2891
+ generatePageMeta,
2892
+ generateResources,
2893
+ getExpressionIdentifiers,
2894
+ getIndexesWithinAncestors,
2895
+ getPagePath,
2896
+ getStaticSiteMapXml,
2897
+ getStyleDeclKey,
2898
+ initialBreakpoints,
2899
+ insetUnitValueSchema,
2900
+ isComponentDetachable,
2901
+ isCoreComponent,
2902
+ isLiteralExpression,
2903
+ isPathnamePattern,
2904
+ isRootFolder,
2905
+ lintExpression,
2906
+ matchPathnameParams,
2907
+ parseComponentName,
2908
+ parseObjectExpression,
2909
+ portalComponent,
2910
+ rangeUnitValueSchema,
2911
+ replaceFormActionsWithResources,
2912
+ rootComponent,
2913
+ scrollAnimationSchema,
2914
+ systemParameter,
2915
+ tags,
2916
+ transpileExpression,
2917
+ viewAnimationSchema
2918
+ };