webstudio 0.271.0 → 0.273.0

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.
@@ -8,7 +8,7 @@ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot
8
8
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
9
9
  var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
10
10
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
11
- var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
11
+ var __privateMethod = (obj, member, method2) => (__accessCheck(obj, member, "access private method"), method2);
12
12
  var _declarations, _dirtyBreakpoints, _selector, _descendantSuffix, _mixinRules, _mixins, _declarations2, _cache, _NestingRule_instances, getDeclarations_fn, _name, _cached, _options, _element, _name2, _cssText, _mediaRules, _plainRules, _mixinRules2, _fontFaceRules, _transformValue, _element2;
13
13
  import { exit, cwd, stdin, stdout, chdir, argv } from "node:process";
14
14
  import { hideBin } from "yargs/helpers";
@@ -18,6 +18,7 @@ import { z } from "zod";
18
18
  import { access, constants, writeFile, readFile, mkdir, rm, rename, copyFile, readdir, cp } from "node:fs/promises";
19
19
  import { text, isCancel, cancel, log, spinner, confirm, select as select$1 } from "@clack/prompts";
20
20
  import { createTRPCUntypedClient, httpBatchLink } from "@trpc/client";
21
+ import { Upload } from "tus-js-client";
21
22
  import { parseExpressionAt } from "acorn";
22
23
  import { simple } from "acorn-walk";
23
24
  import pc from "picocolors";
@@ -395,12 +396,12 @@ const FONT_FORMATS = /* @__PURE__ */ new Map([
395
396
  Array.from(FONT_FORMATS.keys()).map((format) => `.${format}`).join(", ");
396
397
  const FONT_STYLES = ["normal", "italic", "oblique"];
397
398
  const sanitizeCssUrl$1 = (str) => JSON.stringify(str);
398
- const formatFace = (asset, format, url) => {
399
+ const formatFace = (asset2, format, url) => {
399
400
  var _a;
400
- if ("variationAxes" in asset.meta) {
401
- const { wght, wdth } = ((_a = asset.meta) == null ? void 0 : _a.variationAxes) ?? {};
401
+ if ("variationAxes" in asset2.meta) {
402
+ const { wght, wdth } = ((_a = asset2.meta) == null ? void 0 : _a.variationAxes) ?? {};
402
403
  return {
403
- fontFamily: asset.meta.family,
404
+ fontFamily: asset2.meta.family,
404
405
  fontStyle: "normal",
405
406
  fontDisplay: "swap",
406
407
  src: `url(${sanitizeCssUrl$1(url)}) format("${format}")`,
@@ -409,32 +410,32 @@ const formatFace = (asset, format, url) => {
409
410
  };
410
411
  }
411
412
  return {
412
- fontFamily: asset.meta.family,
413
- fontStyle: asset.meta.style,
414
- fontWeight: asset.meta.weight,
413
+ fontFamily: asset2.meta.family,
414
+ fontStyle: asset2.meta.style,
415
+ fontWeight: asset2.meta.weight,
415
416
  fontDisplay: "swap",
416
417
  src: `url(${sanitizeCssUrl$1(url)}) format("${format}")`
417
418
  };
418
419
  };
419
- const getKey = (asset) => {
420
- if ("variationAxes" in asset.meta) {
421
- return asset.meta.family + Object.values(asset.meta.variationAxes).join("");
420
+ const getKey = (asset2) => {
421
+ if ("variationAxes" in asset2.meta) {
422
+ return asset2.meta.family + Object.values(asset2.meta.variationAxes).join("");
422
423
  }
423
- return asset.meta.family + asset.meta.style + asset.meta.weight;
424
+ return asset2.meta.family + asset2.meta.style + asset2.meta.weight;
424
425
  };
425
426
  const getFontFaces = (assets, options) => {
426
427
  const { assetBaseUrl } = options;
427
428
  const faces = /* @__PURE__ */ new Map();
428
- for (const asset of assets) {
429
- const url = `${assetBaseUrl}${asset.name}`;
430
- const assetKey = getKey(asset);
429
+ for (const asset2 of assets) {
430
+ const url = `${assetBaseUrl}${asset2.name}`;
431
+ const assetKey = getKey(asset2);
431
432
  const face = faces.get(assetKey);
432
- const format = FONT_FORMATS.get(asset.format);
433
+ const format = FONT_FORMATS.get(asset2.format);
433
434
  if (format === void 0) {
434
435
  continue;
435
436
  }
436
437
  if (face === void 0) {
437
- const face2 = formatFace(asset, format, url);
438
+ const face2 = formatFace(asset2, format, url);
438
439
  faces.set(assetKey, face2);
439
440
  continue;
440
441
  }
@@ -442,12 +443,12 @@ const getFontFaces = (assets, options) => {
442
443
  }
443
444
  return Array.from(faces.values());
444
445
  };
445
- const FontFormat = z.union([
446
+ const fontFormat = z.union([
446
447
  z.literal("ttf"),
447
448
  z.literal("woff"),
448
449
  z.literal("woff2")
449
450
  ]);
450
- const AxisName = z.enum([
451
+ const axisName = z.enum([
451
452
  "wght",
452
453
  "wdth",
453
454
  "slnt",
@@ -463,8 +464,8 @@ const AxisName = z.enum([
463
464
  "YTDE",
464
465
  "YTFI"
465
466
  ]);
466
- const VariationAxes = z.record(
467
- AxisName,
467
+ const variationAxes = z.record(
468
+ axisName,
468
469
  z.object({
469
470
  name: z.string(),
470
471
  min: z.number(),
@@ -472,19 +473,19 @@ const VariationAxes = z.record(
472
473
  max: z.number()
473
474
  })
474
475
  );
475
- const FontMetaStatic = z.object({
476
+ const fontMetaStatic = z.object({
476
477
  family: z.string(),
477
478
  style: z.enum(FONT_STYLES),
478
479
  weight: z.number()
479
480
  });
480
- const FontMetaVariable = z.object({
481
+ const fontMetaVariable = z.object({
481
482
  family: z.string(),
482
- variationAxes: VariationAxes
483
+ variationAxes
483
484
  });
484
- const FontMeta = z.union([FontMetaStatic, FontMetaVariable]);
485
- const AssetId = z.string();
485
+ const fontMeta = z.union([fontMetaStatic, fontMetaVariable]);
486
+ const assetId = z.string();
486
487
  const baseAsset = {
487
- id: AssetId,
488
+ id: assetId,
488
489
  projectId: z.string(),
489
490
  size: z.number(),
490
491
  name: z.string(),
@@ -492,33 +493,34 @@ const baseAsset = {
492
493
  description: z.union([z.string().optional(), z.null()]),
493
494
  createdAt: z.string()
494
495
  };
495
- const FontAsset = z.object({
496
+ const assetType = z.enum(["font", "image", "file"]);
497
+ const fontAsset = z.object({
496
498
  ...baseAsset,
497
- format: FontFormat,
498
- meta: FontMeta,
499
- type: z.literal("font")
499
+ format: fontFormat,
500
+ meta: fontMeta,
501
+ type: z.literal(assetType.enum.font)
500
502
  });
501
- const ImageMeta = z.object({
503
+ const imageMeta = z.object({
502
504
  width: z.number(),
503
505
  height: z.number()
504
506
  });
505
- const ImageAsset = z.object({
507
+ const imageAsset = z.object({
506
508
  ...baseAsset,
507
509
  format: z.string(),
508
- meta: ImageMeta,
509
- type: z.literal("image")
510
+ meta: imageMeta,
511
+ type: z.literal(assetType.enum.image)
510
512
  });
511
- const FileAsset = z.object({
513
+ const fileAsset = z.object({
512
514
  ...baseAsset,
513
515
  format: z.string(),
514
516
  meta: z.object({}),
515
- type: z.literal("file")
517
+ type: z.literal(assetType.enum.file)
516
518
  });
517
- const Asset = z.union([FontAsset, ImageAsset, FileAsset]);
518
- z.map(AssetId, Asset);
519
- const BreakpointId = z.string();
520
- const Breakpoint = z.object({
521
- id: BreakpointId,
519
+ const asset = z.union([fontAsset, imageAsset, fileAsset]);
520
+ z.map(assetId, asset);
521
+ const breakpointId = z.string();
522
+ const breakpoint = z.object({
523
+ id: breakpointId,
522
524
  label: z.string(),
523
525
  minWidth: z.number().optional(),
524
526
  maxWidth: z.number().optional(),
@@ -537,9 +539,9 @@ const Breakpoint = z.object({
537
539
  }
538
540
  return true;
539
541
  }, "Width-based (minWidth/maxWidth) and condition are mutually exclusive, and minWidth must be less than maxWidth");
540
- z.map(BreakpointId, Breakpoint);
541
- const DataSourceId = z.string();
542
- const DataSourceVariableValue = z.union([
542
+ z.map(breakpointId, breakpoint);
543
+ const dataSourceId = z.string();
544
+ const dataSourceVariableValue = z.union([
543
545
  z.object({
544
546
  type: z.literal("number"),
545
547
  // initial value of variable store
@@ -562,10 +564,10 @@ const DataSourceVariableValue = z.union([
562
564
  value: z.unknown()
563
565
  })
564
566
  ]);
565
- const DataSource = z.union([
567
+ const dataSource = z.union([
566
568
  z.object({
567
569
  type: z.literal("variable"),
568
- id: DataSourceId,
570
+ id: dataSourceId,
569
571
  // The instance should always be specified for variables,
570
572
  // however, there was a bug in the embed template
571
573
  // which produced variables without an instance
@@ -573,24 +575,24 @@ const DataSource = z.union([
573
575
  // if we make it required
574
576
  scopeInstanceId: z.string().optional(),
575
577
  name: z.string(),
576
- value: DataSourceVariableValue
578
+ value: dataSourceVariableValue
577
579
  }),
578
580
  z.object({
579
581
  type: z.literal("parameter"),
580
- id: DataSourceId,
582
+ id: dataSourceId,
581
583
  scopeInstanceId: z.string().optional(),
582
584
  name: z.string()
583
585
  }),
584
586
  z.object({
585
587
  type: z.literal("resource"),
586
- id: DataSourceId,
588
+ id: dataSourceId,
587
589
  scopeInstanceId: z.string().optional(),
588
590
  name: z.string(),
589
591
  resourceId: z.string()
590
592
  })
591
593
  ]);
592
- z.map(DataSourceId, DataSource);
593
- const Templates = z.enum([
594
+ z.map(dataSourceId, dataSource);
595
+ const templates = z.enum([
594
596
  "docker",
595
597
  "vercel",
596
598
  "netlify",
@@ -598,13 +600,13 @@ const Templates = z.enum([
598
600
  "ssg-netlify",
599
601
  "ssg-vercel"
600
602
  ]);
601
- const Deployment = z.union([
603
+ const deployment = z.union([
602
604
  z.object({
603
605
  destination: z.literal("static"),
604
606
  name: z.string(),
605
607
  assetsDomain: z.string(),
606
608
  // Must be validated very strictly
607
- templates: z.array(Templates)
609
+ templates: z.array(templates)
608
610
  }),
609
611
  z.object({
610
612
  destination: z.literal("saas").optional(),
@@ -617,30 +619,30 @@ const Deployment = z.union([
617
619
  excludeWstdDomainFromSearch: z.boolean().optional()
618
620
  })
619
621
  ]);
620
- const TextChild = z.object({
622
+ const textChild = z.object({
621
623
  type: z.literal("text"),
622
624
  value: z.string(),
623
625
  placeholder: z.boolean().optional()
624
626
  });
625
- const InstanceId$1 = z.string();
626
- const IdChild = z.object({
627
+ const instanceId$1 = z.string();
628
+ const idChild = z.object({
627
629
  type: z.literal("id"),
628
- value: InstanceId$1
630
+ value: instanceId$1
629
631
  });
630
- const ExpressionChild = z.object({
632
+ const expressionChild = z.object({
631
633
  type: z.literal("expression"),
632
634
  value: z.string()
633
635
  });
634
- const InstanceChild = z.union([IdChild, TextChild, ExpressionChild]);
635
- const Instance = z.object({
636
+ const instanceChild = z.union([idChild, textChild, expressionChild]);
637
+ const instance = z.object({
636
638
  type: z.literal("instance"),
637
- id: InstanceId$1,
639
+ id: instanceId$1,
638
640
  component: z.string(),
639
641
  tag: z.string().optional(),
640
642
  label: z.string().optional(),
641
- children: z.array(InstanceChild)
643
+ children: z.array(instanceChild)
642
644
  });
643
- z.map(InstanceId$1, Instance);
645
+ z.map(instanceId$1, instance);
644
646
  const basicLoginErrors = (login) => {
645
647
  const issues = [];
646
648
  if (login.length === 0) {
@@ -892,12 +894,12 @@ const buildWsAuth = (sources) => {
892
894
  };
893
895
  const createWsAuthResources = ({
894
896
  projectContent = "",
895
- pages,
897
+ pages: pages2,
896
898
  projectSourceName = "Auth",
897
899
  generatedSourceName = "Generated page auth"
898
900
  }) => {
899
- const generatedRoutes = pages.flatMap((page) => {
900
- const route = createWsAuthRouteFromPage(page);
901
+ const generatedRoutes = pages2.flatMap((page2) => {
902
+ const route = createWsAuthRouteFromPage(page2);
901
903
  return route === void 0 ? [] : [route];
902
904
  });
903
905
  const result = buildWsAuth([
@@ -919,26 +921,26 @@ const createWsAuthResources = ({
919
921
  };
920
922
  };
921
923
  const MIN_TITLE_LENGTH = 2;
922
- const PageId = z.string();
923
- const FolderId = z.string();
924
- const FolderName = z.string().refine((value) => value.trim() !== "", "Can't be empty");
925
- const Slug = z.string().refine(
924
+ const pageId = z.string();
925
+ const folderId = z.string();
926
+ const folderName = z.string().refine((value) => value.trim() !== "", "Can't be empty");
927
+ const slug = z.string().refine(
926
928
  (path) => /^[-a-z0-9]*$/.test(path),
927
929
  "Only a-z, 0-9 and - are allowed"
928
930
  );
929
- const Folder = z.object({
930
- id: FolderId,
931
- name: FolderName,
932
- slug: Slug,
933
- children: z.array(z.union([FolderId, PageId]))
931
+ const folder = z.object({
932
+ id: folderId,
933
+ name: folderName,
934
+ slug,
935
+ children: z.array(z.union([folderId, pageId]))
934
936
  });
935
- const PageName = z.string().refine((value) => value.trim() !== "", "Can't be empty");
936
- const PageTitle = z.string().refine(
937
+ const pageName = z.string().refine((value) => value.trim() !== "", "Can't be empty");
938
+ const pageTitle = z.string().refine(
937
939
  (val) => val.length >= MIN_TITLE_LENGTH,
938
940
  `Minimum ${MIN_TITLE_LENGTH} characters required`
939
941
  );
940
942
  const documentTypes = ["html", "xml", "text"];
941
- const BasicAuthFields = {
943
+ const basicAuthFields = {
942
944
  login: z.string(),
943
945
  password: z.string()
944
946
  };
@@ -954,23 +956,23 @@ const validateBasicAuthFields = ({
954
956
  });
955
957
  }
956
958
  };
957
- const PageBasicAuth = z.object({
959
+ const pageBasicAuth = z.object({
958
960
  method: z.literal("basic"),
959
- ...BasicAuthFields
961
+ ...basicAuthFields
960
962
  }).superRefine(validateBasicAuthFields);
961
- const LegacyPageBasicAuth = z.object({
963
+ const legacyPageBasicAuth = z.object({
962
964
  type: z.literal("basic"),
963
- ...BasicAuthFields
965
+ ...basicAuthFields
964
966
  }).superRefine(validateBasicAuthFields).transform(({ login, password }) => ({
965
967
  method: "basic",
966
968
  login,
967
969
  password
968
970
  }));
969
- const PageAuth = z.union([PageBasicAuth, LegacyPageBasicAuth]);
971
+ const pageAuth = z.union([pageBasicAuth, legacyPageBasicAuth]);
970
972
  const commonPageFields = {
971
- id: PageId,
972
- name: PageName,
973
- title: PageTitle,
973
+ id: pageId,
974
+ name: pageName,
975
+ title: pageTitle,
974
976
  history: z.optional(z.array(z.string())),
975
977
  rootInstanceId: z.string(),
976
978
  systemDataSourceId: z.string().optional(),
@@ -985,7 +987,7 @@ const commonPageFields = {
985
987
  redirect: z.string().optional(),
986
988
  documentType: z.optional(z.enum(documentTypes)),
987
989
  content: z.string().optional(),
988
- auth: PageAuth.optional(),
990
+ auth: pageAuth.optional(),
989
991
  custom: z.array(
990
992
  z.object({
991
993
  property: z.string(),
@@ -1001,8 +1003,8 @@ const commonPageFields = {
1001
1003
  })
1002
1004
  )
1003
1005
  };
1004
- const HomePagePath = z.string().refine((path) => path === "", "Home page path must be empty");
1005
- const DefaultPagePage = z.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(
1006
+ const homePagePath = z.string().refine((path) => path === "", "Home page path must be empty");
1007
+ const defaultPagePath = z.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(
1006
1008
  (path) => /^[-_a-z0-9*:?\\/.]*$/.test(path),
1007
1009
  "Only a-z, 0-9, -, _, /, :, ?, . and * are allowed"
1008
1010
  ).refine(
@@ -1015,7 +1017,7 @@ const DefaultPagePage = z.string().refine((path) => path !== "", "Can't be empty
1015
1017
  (path) => path !== "/build" && path.startsWith("/build/") === false,
1016
1018
  "/build prefix is reserved for the system"
1017
1019
  ).refine((path) => path.length <= 255, "Path can't exceed 255 characters");
1018
- const RedirectSourcePath = z.string().refine((path) => path !== "", "Can't be empty").refine((path) => path !== "/", "Can't be just a /").refine(
1020
+ const redirectSourcePath = z.string().refine((path) => path !== "", "Can't be empty").refine((path) => path !== "/", "Can't be just a /").refine(
1019
1021
  (path) => path.startsWith("/") && path.startsWith("//") === false,
1020
1022
  "Must start with a /"
1021
1023
  ).refine((path) => {
@@ -1035,23 +1037,23 @@ const RedirectSourcePath = z.string().refine((path) => path !== "", "Can't be em
1035
1037
  (path) => path !== "/build" && path.startsWith("/build/") === false,
1036
1038
  "/build prefix is reserved for the system"
1037
1039
  );
1038
- const PagePath = DefaultPagePage.refine(
1040
+ const pagePath = defaultPagePath.refine(
1039
1041
  (path) => path === "" || path.startsWith("/"),
1040
1042
  "Must start with a / or a full URL e.g. https://website.org"
1041
1043
  );
1042
- const Page = z.object({
1044
+ const page = z.object({
1043
1045
  ...commonPageFields,
1044
- path: z.union([HomePagePath, PagePath])
1046
+ path: z.union([homePagePath, pagePath])
1045
1047
  });
1046
- const PageTemplate = z.object({
1047
- id: PageId,
1048
- name: PageName,
1049
- title: PageTitle,
1048
+ const pageTemplate = z.object({
1049
+ id: pageId,
1050
+ name: pageName,
1051
+ title: pageTitle,
1050
1052
  rootInstanceId: z.string(),
1051
1053
  systemDataSourceId: z.string().optional(),
1052
1054
  meta: commonPageFields.meta
1053
1055
  });
1054
- const ProjectMeta = z.object({
1056
+ const projectMeta = z.object({
1055
1057
  // All fields are optional to ensure consistency and allow for the addition of new fields without requiring migration
1056
1058
  siteName: z.string().optional(),
1057
1059
  contactEmail: z.string().optional(),
@@ -1059,7 +1061,7 @@ const ProjectMeta = z.object({
1059
1061
  code: z.string().optional(),
1060
1062
  auth: z.string().optional()
1061
1063
  });
1062
- const ProjectNewRedirectPath = z.string().min(1, "Path is required").refine((data) => {
1064
+ const projectNewRedirectPath = z.string().min(1, "Path is required").refine((data) => {
1063
1065
  try {
1064
1066
  new URL(data, "http://url.com");
1065
1067
  return true;
@@ -1067,27 +1069,27 @@ const ProjectNewRedirectPath = z.string().min(1, "Path is required").refine((dat
1067
1069
  return false;
1068
1070
  }
1069
1071
  }, "Must be a valid URL");
1070
- const PageRedirect = z.object({
1071
- old: RedirectSourcePath,
1072
- new: ProjectNewRedirectPath,
1072
+ const pageRedirect = z.object({
1073
+ old: redirectSourcePath,
1074
+ new: projectNewRedirectPath,
1073
1075
  status: z.enum(["301", "302"]).optional()
1074
1076
  });
1075
- const CompilerSettings = z.object({
1077
+ const compilerSettings = z.object({
1076
1078
  // All fields are optional to ensure consistency and allow for the addition of new fields without requiring migration
1077
1079
  atomicStyles: z.boolean().optional()
1078
1080
  });
1079
- const Pages = z.object({
1080
- meta: ProjectMeta.optional(),
1081
- compiler: CompilerSettings.optional(),
1082
- redirects: z.array(PageRedirect).optional(),
1083
- homePageId: PageId,
1084
- rootFolderId: FolderId,
1085
- pages: z.map(PageId, Page),
1086
- pageTemplates: z.map(PageId, PageTemplate).optional(),
1087
- folders: z.map(FolderId, Folder).refine((folders) => folders.size > 0, "Folders can't be empty")
1088
- }).superRefine((pages, context) => {
1089
- const homePage = pages.pages.get(pages.homePageId);
1090
- const rootFolder = pages.folders.get(pages.rootFolderId);
1081
+ const pages = z.object({
1082
+ meta: projectMeta.optional(),
1083
+ compiler: compilerSettings.optional(),
1084
+ redirects: z.array(pageRedirect).optional(),
1085
+ homePageId: pageId,
1086
+ rootFolderId: folderId,
1087
+ pages: z.map(pageId, page),
1088
+ pageTemplates: z.map(pageId, pageTemplate).optional(),
1089
+ folders: z.map(folderId, folder).refine((folders) => folders.size > 0, "Folders can't be empty")
1090
+ }).superRefine((pages2, context) => {
1091
+ const homePage = pages2.pages.get(pages2.homePageId);
1092
+ const rootFolder = pages2.folders.get(pages2.rootFolderId);
1091
1093
  if (homePage === void 0) {
1092
1094
  context.addIssue({
1093
1095
  code: z.ZodIssueCode.custom,
@@ -1105,27 +1107,27 @@ const Pages = z.object({
1105
1107
  if (homePage !== void 0 && homePage.path !== "") {
1106
1108
  context.addIssue({
1107
1109
  code: z.ZodIssueCode.custom,
1108
- path: ["pages", pages.homePageId, "path"],
1110
+ path: ["pages", pages2.homePageId, "path"],
1109
1111
  message: "Home page path must be empty"
1110
1112
  });
1111
1113
  }
1112
- for (const [pageId, page] of pages.pages) {
1113
- if (page.id !== pageId) {
1114
+ for (const [pageId2, page2] of pages2.pages) {
1115
+ if (page2.id !== pageId2) {
1114
1116
  context.addIssue({
1115
1117
  code: z.ZodIssueCode.custom,
1116
- path: ["pages", pageId, "id"],
1118
+ path: ["pages", pageId2, "id"],
1117
1119
  message: "Page id must match its record key"
1118
1120
  });
1119
1121
  }
1120
- if (pageId !== pages.homePageId && page.path === "") {
1122
+ if (pageId2 !== pages2.homePageId && page2.path === "") {
1121
1123
  context.addIssue({
1122
1124
  code: z.ZodIssueCode.custom,
1123
- path: ["pages", pageId, "path"],
1125
+ path: ["pages", pageId2, "path"],
1124
1126
  message: "Page path can't be empty"
1125
1127
  });
1126
1128
  }
1127
1129
  }
1128
- for (const [templateId, template] of pages.pageTemplates ?? []) {
1130
+ for (const [templateId, template] of pages2.pageTemplates ?? []) {
1129
1131
  if (template.id !== templateId) {
1130
1132
  context.addIssue({
1131
1133
  code: z.ZodIssueCode.custom,
@@ -1133,7 +1135,7 @@ const Pages = z.object({
1133
1135
  message: "Page template id must match its record key"
1134
1136
  });
1135
1137
  }
1136
- if (pages.pages.has(templateId)) {
1138
+ if (pages2.pages.has(templateId)) {
1137
1139
  context.addIssue({
1138
1140
  code: z.ZodIssueCode.custom,
1139
1141
  path: ["pageTemplates", templateId, "id"],
@@ -1141,75 +1143,75 @@ const Pages = z.object({
1141
1143
  });
1142
1144
  }
1143
1145
  }
1144
- for (const [folderId, folder] of pages.folders) {
1145
- if (folder.id !== folderId) {
1146
+ for (const [folderId2, folder2] of pages2.folders) {
1147
+ if (folder2.id !== folderId2) {
1146
1148
  context.addIssue({
1147
1149
  code: z.ZodIssueCode.custom,
1148
- path: ["folders", folderId, "id"],
1150
+ path: ["folders", folderId2, "id"],
1149
1151
  message: "Folder id must match its record key"
1150
1152
  });
1151
1153
  }
1152
- for (const [index, childId] of folder.children.entries()) {
1153
- if (pages.pages.has(childId) === false && pages.folders.has(childId) === false) {
1154
+ for (const [index, childId] of folder2.children.entries()) {
1155
+ if (pages2.pages.has(childId) === false && pages2.folders.has(childId) === false) {
1154
1156
  context.addIssue({
1155
1157
  code: z.ZodIssueCode.custom,
1156
- path: ["folders", folderId, "children", index],
1158
+ path: ["folders", folderId2, "children", index],
1157
1159
  message: "Folder child must reference an existing page or folder"
1158
1160
  });
1159
1161
  }
1160
- if (childId === pages.rootFolderId) {
1162
+ if (childId === pages2.rootFolderId) {
1161
1163
  context.addIssue({
1162
1164
  code: z.ZodIssueCode.custom,
1163
- path: ["folders", folderId, "children", index],
1165
+ path: ["folders", folderId2, "children", index],
1164
1166
  message: "Root folder can't be nested"
1165
1167
  });
1166
1168
  }
1167
1169
  }
1168
1170
  }
1169
- if (rootFolder !== void 0 && rootFolder.children[0] !== pages.homePageId) {
1171
+ if (rootFolder !== void 0 && rootFolder.children[0] !== pages2.homePageId) {
1170
1172
  context.addIssue({
1171
1173
  code: z.ZodIssueCode.custom,
1172
- path: ["folders", pages.rootFolderId, "children"],
1174
+ path: ["folders", pages2.rootFolderId, "children"],
1173
1175
  message: "Root folder must start with the home page"
1174
1176
  });
1175
1177
  }
1176
1178
  const childParents = /* @__PURE__ */ new Map();
1177
- for (const [folderId, folder] of pages.folders) {
1178
- for (const [index, childId] of folder.children.entries()) {
1179
+ for (const [folderId2, folder2] of pages2.folders) {
1180
+ for (const [index, childId] of folder2.children.entries()) {
1179
1181
  const parentId = childParents.get(childId);
1180
1182
  if (parentId !== void 0) {
1181
1183
  context.addIssue({
1182
1184
  code: z.ZodIssueCode.custom,
1183
- path: ["folders", folderId, "children", index],
1185
+ path: ["folders", folderId2, "children", index],
1184
1186
  message: `Child is already registered in folder "${parentId}"`
1185
1187
  });
1186
1188
  continue;
1187
1189
  }
1188
- childParents.set(childId, folderId);
1190
+ childParents.set(childId, folderId2);
1189
1191
  }
1190
1192
  }
1191
- const hasFolderCycle = (folderId, path = /* @__PURE__ */ new Set()) => {
1192
- if (path.has(folderId)) {
1193
+ const hasFolderCycle = (folderId2, path = /* @__PURE__ */ new Set()) => {
1194
+ if (path.has(folderId2)) {
1193
1195
  return true;
1194
1196
  }
1195
- const folder = pages.folders.get(folderId);
1196
- if (folder === void 0) {
1197
+ const folder2 = pages2.folders.get(folderId2);
1198
+ if (folder2 === void 0) {
1197
1199
  return false;
1198
1200
  }
1199
- path.add(folderId);
1200
- for (const childId of folder.children) {
1201
- if (pages.folders.has(childId) && hasFolderCycle(childId, path)) {
1201
+ path.add(folderId2);
1202
+ for (const childId of folder2.children) {
1203
+ if (pages2.folders.has(childId) && hasFolderCycle(childId, path)) {
1202
1204
  return true;
1203
1205
  }
1204
1206
  }
1205
- path.delete(folderId);
1207
+ path.delete(folderId2);
1206
1208
  return false;
1207
1209
  };
1208
- for (const folderId of pages.folders.keys()) {
1209
- if (hasFolderCycle(folderId)) {
1210
+ for (const folderId2 of pages2.folders.keys()) {
1211
+ if (hasFolderCycle(folderId2)) {
1210
1212
  context.addIssue({
1211
1213
  code: z.ZodIssueCode.custom,
1212
- path: ["folders", folderId, "children"],
1214
+ path: ["folders", folderId2, "children"],
1213
1215
  message: "Folders can't contain cycles"
1214
1216
  });
1215
1217
  }
@@ -1251,12 +1253,19 @@ const prefixStyles = (styleMap) => {
1251
1253
  }
1252
1254
  return newStyleMap;
1253
1255
  };
1254
- const fallbackTransform = (styleValue) => {
1256
+ const cssWideKeywords = /* @__PURE__ */ new Set([
1257
+ "initial",
1258
+ "inherit",
1259
+ "unset",
1260
+ "revert",
1261
+ "revert-layer"
1262
+ ]);
1263
+ const fallbackTransform = (styleValue2) => {
1255
1264
  var _a;
1256
- if (styleValue.type !== "fontFamily") {
1265
+ if (styleValue2.type !== "fontFamily") {
1257
1266
  return;
1258
1267
  }
1259
- let { value } = styleValue;
1268
+ let { value } = styleValue2;
1260
1269
  if (value.length === 0) {
1261
1270
  value = [DEFAULT_FONT_FALLBACK];
1262
1271
  }
@@ -1270,12 +1279,12 @@ const fallbackTransform = (styleValue) => {
1270
1279
  };
1271
1280
  };
1272
1281
  const sanitizeCssUrl = (str) => JSON.stringify(str);
1273
- const toValue = (styleValue, transformValue) => {
1274
- if (styleValue === void 0) {
1282
+ const toValue = (styleValue2, transformValue) => {
1283
+ if (styleValue2 === void 0) {
1275
1284
  return "";
1276
1285
  }
1277
- const transformedValue = (transformValue == null ? void 0 : transformValue(styleValue)) ?? fallbackTransform(styleValue);
1278
- const value = transformedValue ?? styleValue;
1286
+ const transformedValue = (transformValue == null ? void 0 : transformValue(styleValue2)) ?? fallbackTransform(styleValue2);
1287
+ const value = transformedValue ?? styleValue2;
1279
1288
  if (value.type === "unit") {
1280
1289
  return value.value + (value.unit === "number" ? "" : value.unit);
1281
1290
  }
@@ -1404,173 +1413,6 @@ const toValue = (styleValue, transformValue) => {
1404
1413
  }
1405
1414
  return "";
1406
1415
  };
1407
- const Unit = z.string();
1408
- const UnitValue = z.object({
1409
- type: z.literal("unit"),
1410
- unit: Unit,
1411
- value: z.number(),
1412
- hidden: z.boolean().optional()
1413
- });
1414
- const KeywordValue = z.object({
1415
- type: z.literal("keyword"),
1416
- // @todo use exact type
1417
- value: z.string(),
1418
- hidden: z.boolean().optional()
1419
- });
1420
- const UnparsedValue = z.object({
1421
- type: z.literal("unparsed"),
1422
- value: z.string(),
1423
- // For the builder we want to be able to hide background-image
1424
- hidden: z.boolean().optional()
1425
- });
1426
- const FontFamilyValue = z.object({
1427
- type: z.literal("fontFamily"),
1428
- value: z.array(z.string()),
1429
- hidden: z.boolean().optional()
1430
- });
1431
- const RgbValue = z.object({
1432
- type: z.literal("rgb"),
1433
- r: z.number(),
1434
- g: z.number(),
1435
- b: z.number(),
1436
- alpha: z.number(),
1437
- hidden: z.boolean().optional()
1438
- });
1439
- const ColorValue = z.object({
1440
- type: z.literal("color"),
1441
- // all these color spaces are defined by design tokens specification
1442
- colorSpace: z.union([
1443
- z.literal("hex"),
1444
- z.literal("srgb"),
1445
- z.literal("p3"),
1446
- z.literal("srgb-linear"),
1447
- z.literal("hsl"),
1448
- z.literal("hwb"),
1449
- z.literal("lab"),
1450
- z.literal("lch"),
1451
- z.literal("oklab"),
1452
- z.literal("oklch"),
1453
- z.literal("a98rgb"),
1454
- z.literal("prophoto"),
1455
- z.literal("rec2020"),
1456
- z.literal("xyz-d65"),
1457
- z.literal("xyz-d50")
1458
- ]),
1459
- components: z.tuple([z.number(), z.number(), z.number()]),
1460
- alpha: z.union([z.number(), z.lazy(() => VarValue)]),
1461
- hidden: z.boolean().optional()
1462
- });
1463
- const FunctionValue = z.object({
1464
- type: z.literal("function"),
1465
- name: z.string(),
1466
- args: z.lazy(() => StyleValue),
1467
- hidden: z.boolean().optional()
1468
- });
1469
- const ImageValue = z.object({
1470
- type: z.literal("image"),
1471
- value: z.union([
1472
- z.object({ type: z.literal("asset"), value: z.string() }),
1473
- // url is not stored in db and only used by css-engine transformValue
1474
- // to prepare image value for rendering
1475
- z.object({ type: z.literal("url"), url: z.string() })
1476
- ]),
1477
- // For the builder we want to be able to hide images
1478
- hidden: z.boolean().optional()
1479
- });
1480
- const GuaranteedInvalidValue = z.object({
1481
- type: z.literal("guaranteedInvalid"),
1482
- hidden: z.boolean().optional()
1483
- });
1484
- const InvalidValue = z.object({
1485
- type: z.literal("invalid"),
1486
- value: z.string(),
1487
- hidden: z.boolean().optional()
1488
- });
1489
- const UnsetValue = z.object({
1490
- type: z.literal("unset"),
1491
- value: z.literal(""),
1492
- hidden: z.boolean().optional()
1493
- });
1494
- const VarFallback = z.union([
1495
- UnparsedValue,
1496
- KeywordValue,
1497
- UnitValue,
1498
- ColorValue,
1499
- RgbValue
1500
- ]);
1501
- const VarValue = z.object({
1502
- type: z.literal("var"),
1503
- value: z.string(),
1504
- fallback: VarFallback.optional(),
1505
- hidden: z.boolean().optional()
1506
- });
1507
- const TupleValueItem = z.union([
1508
- UnitValue,
1509
- KeywordValue,
1510
- UnparsedValue,
1511
- ImageValue,
1512
- ColorValue,
1513
- RgbValue,
1514
- FunctionValue,
1515
- VarValue
1516
- ]);
1517
- const TupleValue = z.object({
1518
- type: z.literal("tuple"),
1519
- value: z.array(TupleValueItem),
1520
- hidden: z.boolean().optional()
1521
- });
1522
- const ShadowValue = z.object({
1523
- type: z.literal("shadow"),
1524
- hidden: z.boolean().optional(),
1525
- position: z.union([z.literal("inset"), z.literal("outset")]),
1526
- offsetX: z.union([UnitValue, VarValue]),
1527
- offsetY: z.union([UnitValue, VarValue]),
1528
- blur: z.union([UnitValue, VarValue]).optional(),
1529
- spread: z.union([UnitValue, VarValue]).optional(),
1530
- color: z.union([ColorValue, RgbValue, KeywordValue, VarValue]).optional()
1531
- });
1532
- const LayerValueItem = z.union([
1533
- UnitValue,
1534
- KeywordValue,
1535
- UnparsedValue,
1536
- ImageValue,
1537
- TupleValue,
1538
- ShadowValue,
1539
- ColorValue,
1540
- RgbValue,
1541
- InvalidValue,
1542
- FunctionValue,
1543
- VarValue
1544
- ]);
1545
- const LayersValue = z.object({
1546
- type: z.literal("layers"),
1547
- value: z.array(LayerValueItem),
1548
- hidden: z.boolean().optional()
1549
- });
1550
- const StyleValue = z.union([
1551
- ImageValue,
1552
- LayersValue,
1553
- UnitValue,
1554
- KeywordValue,
1555
- FontFamilyValue,
1556
- ColorValue,
1557
- RgbValue,
1558
- UnparsedValue,
1559
- TupleValue,
1560
- FunctionValue,
1561
- GuaranteedInvalidValue,
1562
- InvalidValue,
1563
- UnsetValue,
1564
- VarValue,
1565
- ShadowValue
1566
- ]);
1567
- const cssWideKeywords = /* @__PURE__ */ new Set([
1568
- "initial",
1569
- "inherit",
1570
- "unset",
1571
- "revert",
1572
- "revert-layer"
1573
- ]);
1574
1416
  const isLonghandValue = (value) => {
1575
1417
  if (value === void 0) {
1576
1418
  return false;
@@ -1616,8 +1458,8 @@ const mergeWhiteSpaceAndTextWrap = (styleMap) => {
1616
1458
  const collapse = toValue(collapseValue);
1617
1459
  const modeValue = styleMap.get("text-wrap-mode");
1618
1460
  const mode = toValue(modeValue);
1619
- const styleValue = styleMap.get("text-wrap-style");
1620
- const style = toValue(styleValue);
1461
+ const styleValue2 = styleMap.get("text-wrap-style");
1462
+ const style = toValue(styleValue2);
1621
1463
  styleMap.delete("text-wrap-mode");
1622
1464
  styleMap.delete("text-wrap-style");
1623
1465
  if (collapse === "collapse" || collapse === "initial" || mode === "wrap" || mode === "initial") {
@@ -1645,7 +1487,7 @@ const mergeWhiteSpaceAndTextWrap = (styleMap) => {
1645
1487
  if (style === "balance" || style === "stable" || style === "pretty") {
1646
1488
  styleMap.set("text-wrap", { type: "keyword", value: style });
1647
1489
  }
1648
- const textWrap = ((styleValue == null ? void 0 : styleValue.type) !== "keyword" ? styleValue : void 0) ?? ((modeValue == null ? void 0 : modeValue.type) !== "keyword" ? modeValue : void 0);
1490
+ const textWrap = ((styleValue2 == null ? void 0 : styleValue2.type) !== "keyword" ? styleValue2 : void 0) ?? ((modeValue == null ? void 0 : modeValue.type) !== "keyword" ? modeValue : void 0);
1649
1491
  if (textWrap) {
1650
1492
  styleMap.set("text-wrap", textWrap);
1651
1493
  }
@@ -1712,7 +1554,7 @@ const mergeDeclarations = (declarations) => {
1712
1554
  (declaration) => declaration.breakpoint + declaration.selector
1713
1555
  );
1714
1556
  for (const groupDeclarations of groups.values()) {
1715
- const { breakpoint, selector } = groupDeclarations[0];
1557
+ const { breakpoint: breakpoint2, selector } = groupDeclarations[0];
1716
1558
  const merged = mergeStyles(
1717
1559
  new Map(
1718
1560
  groupDeclarations.map((item) => [item.property, item.value])
@@ -1720,7 +1562,7 @@ const mergeDeclarations = (declarations) => {
1720
1562
  );
1721
1563
  for (const [property, value] of merged) {
1722
1564
  newDeclarations.push({
1723
- breakpoint,
1565
+ breakpoint: breakpoint2,
1724
1566
  selector,
1725
1567
  property,
1726
1568
  value
@@ -1749,8 +1591,8 @@ const normalizeDeclaration = (declaration) => ({
1749
1591
  property: hyphenateProperty(declaration.property)
1750
1592
  });
1751
1593
  const getDeclarationKey = (declaraionKey) => {
1752
- const { breakpoint, selector, property } = declaraionKey;
1753
- return `${breakpoint}:${selector}:${property}`;
1594
+ const { breakpoint: breakpoint2, selector, property } = declaraionKey;
1595
+ return `${breakpoint2}:${selector}:${property}`;
1754
1596
  };
1755
1597
  class MixinRule {
1756
1598
  constructor() {
@@ -1761,8 +1603,8 @@ class MixinRule {
1761
1603
  /*
1762
1604
  * check if breakpoint was updated
1763
1605
  */
1764
- isDirtyBreakpoint(breakpoint) {
1765
- return __privateGet(this, _dirtyBreakpoints).has(breakpoint);
1606
+ isDirtyBreakpoint(breakpoint2) {
1607
+ return __privateGet(this, _dirtyBreakpoints).has(breakpoint2);
1766
1608
  }
1767
1609
  /**
1768
1610
  * reset breakpoints invalidation
@@ -1833,23 +1675,23 @@ class NestingRule {
1833
1675
  return mergeDeclarations(__privateMethod(this, _NestingRule_instances, getDeclarations_fn).call(this));
1834
1676
  }
1835
1677
  toString({
1836
- breakpoint,
1678
+ breakpoint: breakpoint2,
1837
1679
  indent = 0,
1838
1680
  transformValue
1839
1681
  }) {
1840
1682
  for (const mixin of __privateGet(this, _mixins)) {
1841
1683
  const rule = __privateGet(this, _mixinRules).get(mixin);
1842
- if (rule == null ? void 0 : rule.isDirtyBreakpoint(breakpoint)) {
1843
- __privateGet(this, _cache).delete(breakpoint);
1684
+ if (rule == null ? void 0 : rule.isDirtyBreakpoint(breakpoint2)) {
1685
+ __privateGet(this, _cache).delete(breakpoint2);
1844
1686
  }
1845
1687
  }
1846
- const cached = __privateGet(this, _cache).get(breakpoint);
1688
+ const cached = __privateGet(this, _cache).get(breakpoint2);
1847
1689
  if (cached && cached.indent === indent && cached.transformValue === transformValue) {
1848
1690
  return cached.generated;
1849
1691
  }
1850
1692
  const styleBySelector = /* @__PURE__ */ new Map();
1851
1693
  for (const declaration of this.getMergedDeclarations()) {
1852
- if (declaration.breakpoint !== breakpoint) {
1694
+ if (declaration.breakpoint !== breakpoint2) {
1853
1695
  continue;
1854
1696
  }
1855
1697
  let nestedSelector = declaration.selector;
@@ -1877,7 +1719,7 @@ ${content}
1877
1719
  ${spaces}}
1878
1720
  `;
1879
1721
  }).join("").trimEnd();
1880
- __privateGet(this, _cache).set(breakpoint, { generated, indent, transformValue });
1722
+ __privateGet(this, _cache).set(breakpoint2, { generated, indent, transformValue });
1881
1723
  return generated;
1882
1724
  }
1883
1725
  }
@@ -2247,6 +2089,166 @@ const generateAtomic = (sheet, options) => {
2247
2089
  });
2248
2090
  return { cssText, classes };
2249
2091
  };
2092
+ const unit = z.string();
2093
+ const unitValue = z.object({
2094
+ type: z.literal("unit"),
2095
+ unit,
2096
+ value: z.number(),
2097
+ hidden: z.boolean().optional()
2098
+ });
2099
+ const keywordValue = z.object({
2100
+ type: z.literal("keyword"),
2101
+ // @todo use exact type
2102
+ value: z.string(),
2103
+ hidden: z.boolean().optional()
2104
+ });
2105
+ const unparsedValue = z.object({
2106
+ type: z.literal("unparsed"),
2107
+ value: z.string(),
2108
+ // For the builder we want to be able to hide background-image
2109
+ hidden: z.boolean().optional()
2110
+ });
2111
+ const fontFamilyValue = z.object({
2112
+ type: z.literal("fontFamily"),
2113
+ value: z.array(z.string()),
2114
+ hidden: z.boolean().optional()
2115
+ });
2116
+ const rgbValue = z.object({
2117
+ type: z.literal("rgb"),
2118
+ r: z.number(),
2119
+ g: z.number(),
2120
+ b: z.number(),
2121
+ alpha: z.number(),
2122
+ hidden: z.boolean().optional()
2123
+ });
2124
+ const colorValue = z.object({
2125
+ type: z.literal("color"),
2126
+ // all these color spaces are defined by design tokens specification
2127
+ colorSpace: z.union([
2128
+ z.literal("hex"),
2129
+ z.literal("srgb"),
2130
+ z.literal("p3"),
2131
+ z.literal("srgb-linear"),
2132
+ z.literal("hsl"),
2133
+ z.literal("hwb"),
2134
+ z.literal("lab"),
2135
+ z.literal("lch"),
2136
+ z.literal("oklab"),
2137
+ z.literal("oklch"),
2138
+ z.literal("a98rgb"),
2139
+ z.literal("prophoto"),
2140
+ z.literal("rec2020"),
2141
+ z.literal("xyz-d65"),
2142
+ z.literal("xyz-d50")
2143
+ ]),
2144
+ components: z.tuple([z.number(), z.number(), z.number()]),
2145
+ alpha: z.union([z.number(), z.lazy(() => varValue)]),
2146
+ hidden: z.boolean().optional()
2147
+ });
2148
+ const functionValue = z.object({
2149
+ type: z.literal("function"),
2150
+ name: z.string(),
2151
+ args: z.lazy(() => styleValue),
2152
+ hidden: z.boolean().optional()
2153
+ });
2154
+ const imageValue = z.object({
2155
+ type: z.literal("image"),
2156
+ value: z.union([
2157
+ z.object({ type: z.literal("asset"), value: z.string() }),
2158
+ // url is not stored in db and only used by css-engine transformValue
2159
+ // to prepare image value for rendering
2160
+ z.object({ type: z.literal("url"), url: z.string() })
2161
+ ]),
2162
+ // For the builder we want to be able to hide images
2163
+ hidden: z.boolean().optional()
2164
+ });
2165
+ const guaranteedInvalidValue = z.object({
2166
+ type: z.literal("guaranteedInvalid"),
2167
+ hidden: z.boolean().optional()
2168
+ });
2169
+ const invalidValue = z.object({
2170
+ type: z.literal("invalid"),
2171
+ value: z.string(),
2172
+ hidden: z.boolean().optional()
2173
+ });
2174
+ const unsetValue = z.object({
2175
+ type: z.literal("unset"),
2176
+ value: z.literal(""),
2177
+ hidden: z.boolean().optional()
2178
+ });
2179
+ const varFallback = z.union([
2180
+ unparsedValue,
2181
+ keywordValue,
2182
+ unitValue,
2183
+ colorValue,
2184
+ rgbValue
2185
+ ]);
2186
+ const varValue = z.object({
2187
+ type: z.literal("var"),
2188
+ value: z.string(),
2189
+ fallback: varFallback.optional(),
2190
+ hidden: z.boolean().optional()
2191
+ });
2192
+ const tupleValueItem = z.union([
2193
+ unitValue,
2194
+ keywordValue,
2195
+ unparsedValue,
2196
+ imageValue,
2197
+ colorValue,
2198
+ rgbValue,
2199
+ functionValue,
2200
+ varValue
2201
+ ]);
2202
+ const tupleValue = z.object({
2203
+ type: z.literal("tuple"),
2204
+ value: z.array(tupleValueItem),
2205
+ hidden: z.boolean().optional()
2206
+ });
2207
+ const shadowValue = z.object({
2208
+ type: z.literal("shadow"),
2209
+ hidden: z.boolean().optional(),
2210
+ position: z.union([z.literal("inset"), z.literal("outset")]),
2211
+ offsetX: z.union([unitValue, varValue]),
2212
+ offsetY: z.union([unitValue, varValue]),
2213
+ blur: z.union([unitValue, varValue]).optional(),
2214
+ spread: z.union([unitValue, varValue]).optional(),
2215
+ color: z.union([colorValue, rgbValue, keywordValue, varValue]).optional()
2216
+ });
2217
+ const layerValueItem = z.union([
2218
+ unitValue,
2219
+ keywordValue,
2220
+ unparsedValue,
2221
+ imageValue,
2222
+ tupleValue,
2223
+ shadowValue,
2224
+ colorValue,
2225
+ rgbValue,
2226
+ invalidValue,
2227
+ functionValue,
2228
+ varValue
2229
+ ]);
2230
+ const layersValue = z.object({
2231
+ type: z.literal("layers"),
2232
+ value: z.array(layerValueItem),
2233
+ hidden: z.boolean().optional()
2234
+ });
2235
+ const styleValue = z.union([
2236
+ imageValue,
2237
+ layersValue,
2238
+ unitValue,
2239
+ keywordValue,
2240
+ fontFamilyValue,
2241
+ colorValue,
2242
+ rgbValue,
2243
+ unparsedValue,
2244
+ tupleValue,
2245
+ functionValue,
2246
+ guaranteedInvalidValue,
2247
+ invalidValue,
2248
+ unsetValue,
2249
+ varValue,
2250
+ shadowValue
2251
+ ]);
2250
2252
  const literalUnion = (arr) => z.union(
2251
2253
  arr.map((val) => z.literal(val))
2252
2254
  );
@@ -2294,12 +2296,12 @@ const RANGE_UNITS = [
2294
2296
  "lvmax",
2295
2297
  "dvmax"
2296
2298
  ];
2297
- const rangeUnitSchema = literalUnion(RANGE_UNITS);
2298
- const rangeUnitValueSchema = z.union([
2299
+ const rangeUnit = literalUnion(RANGE_UNITS);
2300
+ const rangeUnitValue = z.union([
2299
2301
  z.object({
2300
2302
  type: z.literal("unit"),
2301
2303
  value: z.number(),
2302
- unit: rangeUnitSchema
2304
+ unit: rangeUnit
2303
2305
  }),
2304
2306
  z.object({
2305
2307
  type: z.literal("unparsed"),
@@ -2311,32 +2313,32 @@ const rangeUnitValueSchema = z.union([
2311
2313
  })
2312
2314
  ]);
2313
2315
  const TIME_UNITS = ["ms", "s"];
2314
- const timeUnitSchema = literalUnion(TIME_UNITS);
2315
- const durationUnitValueSchema = z.union([
2316
+ const timeUnit = literalUnion(TIME_UNITS);
2317
+ const durationUnitValue = z.union([
2316
2318
  z.object({
2317
2319
  type: z.literal("unit"),
2318
2320
  value: z.number(),
2319
- unit: timeUnitSchema
2321
+ unit: timeUnit
2320
2322
  }),
2321
2323
  z.object({
2322
2324
  type: z.literal("var"),
2323
2325
  value: z.string()
2324
2326
  })
2325
2327
  ]);
2326
- const iterationsUnitValueSchema = z.union([z.number(), z.literal("infinite")]);
2327
- const insetUnitValueSchema = z.union([
2328
- rangeUnitValueSchema,
2328
+ const iterationsUnitValue = z.union([z.number(), z.literal("infinite")]);
2329
+ const insetUnitValue = z.union([
2330
+ rangeUnitValue,
2329
2331
  z.object({
2330
2332
  type: z.literal("keyword"),
2331
2333
  value: z.literal("auto")
2332
2334
  })
2333
2335
  ]);
2334
- const keyframeStylesSchema = z.record(StyleValue);
2335
- const animationKeyframeSchema = z.object({
2336
+ const keyframeStyles = z.record(styleValue);
2337
+ const animationKeyframe = z.object({
2336
2338
  offset: z.number().optional(),
2337
- styles: keyframeStylesSchema
2339
+ styles: keyframeStyles
2338
2340
  });
2339
- const keyframeEffectOptionsSchema = z.object({
2341
+ const keyframeEffectOptions = z.object({
2340
2342
  easing: z.string().optional(),
2341
2343
  fill: z.union([
2342
2344
  z.literal("none"),
@@ -2345,29 +2347,23 @@ const keyframeEffectOptionsSchema = z.object({
2345
2347
  z.literal("both")
2346
2348
  ]).optional(),
2347
2349
  // FillMode
2348
- duration: durationUnitValueSchema.optional(),
2349
- delay: durationUnitValueSchema.optional(),
2350
- iterations: iterationsUnitValueSchema.optional()
2350
+ duration: durationUnitValue.optional(),
2351
+ delay: durationUnitValue.optional(),
2352
+ iterations: iterationsUnitValue.optional()
2351
2353
  });
2352
- const scrollNamedRangeSchema = z.union([
2353
- z.literal("start"),
2354
- z.literal("end")
2355
- ]);
2356
- const scrollRangeValueSchema = z.tuple([
2357
- scrollNamedRangeSchema,
2358
- rangeUnitValueSchema
2359
- ]);
2360
- const scrollRangeOptionsSchema = z.object({
2361
- rangeStart: scrollRangeValueSchema.optional(),
2362
- rangeEnd: scrollRangeValueSchema.optional()
2354
+ const scrollNamedRange = z.union([z.literal("start"), z.literal("end")]);
2355
+ const scrollRangeValue = z.tuple([scrollNamedRange, rangeUnitValue]);
2356
+ const scrollRangeOptions = z.object({
2357
+ rangeStart: scrollRangeValue.optional(),
2358
+ rangeEnd: scrollRangeValue.optional()
2363
2359
  });
2364
- const animationAxisSchema = z.union([
2360
+ const animationAxis = z.union([
2365
2361
  z.literal("block"),
2366
2362
  z.literal("inline"),
2367
2363
  z.literal("x"),
2368
2364
  z.literal("y")
2369
2365
  ]);
2370
- const viewNamedRangeSchema = z.union([
2366
+ const viewNamedRange = z.union([
2371
2367
  z.literal("contain"),
2372
2368
  z.literal("cover"),
2373
2369
  z.literal("entry"),
@@ -2375,60 +2371,57 @@ const viewNamedRangeSchema = z.union([
2375
2371
  z.literal("entry-crossing"),
2376
2372
  z.literal("exit-crossing")
2377
2373
  ]);
2378
- const viewRangeValueSchema = z.tuple([
2379
- viewNamedRangeSchema,
2380
- rangeUnitValueSchema
2381
- ]);
2382
- const viewRangeOptionsSchema = z.object({
2383
- rangeStart: viewRangeValueSchema.optional(),
2384
- rangeEnd: viewRangeValueSchema.optional()
2374
+ const viewRangeValue = z.tuple([viewNamedRange, rangeUnitValue]);
2375
+ const viewRangeOptions = z.object({
2376
+ rangeStart: viewRangeValue.optional(),
2377
+ rangeEnd: viewRangeValue.optional()
2385
2378
  });
2386
2379
  const baseAnimation = z.object({
2387
2380
  name: z.string().optional(),
2388
2381
  description: z.string().optional(),
2389
2382
  enabled: z.array(z.tuple([z.string().describe("breakpointId"), z.boolean()])).optional(),
2390
- keyframes: z.array(animationKeyframeSchema)
2383
+ keyframes: z.array(animationKeyframe)
2391
2384
  });
2392
- const scrollAnimationSchema = baseAnimation.merge(
2385
+ const scrollAnimation = baseAnimation.merge(
2393
2386
  z.object({
2394
- timing: keyframeEffectOptionsSchema.merge(scrollRangeOptionsSchema)
2387
+ timing: keyframeEffectOptions.merge(scrollRangeOptions)
2395
2388
  })
2396
2389
  );
2397
- const scrollActionSchema = z.object({
2390
+ const scrollAction = z.object({
2398
2391
  type: z.literal("scroll"),
2399
2392
  source: z.union([z.literal("closest"), z.literal("nearest"), z.literal("root")]).optional(),
2400
- axis: animationAxisSchema.optional(),
2401
- animations: z.array(scrollAnimationSchema),
2393
+ axis: animationAxis.optional(),
2394
+ animations: z.array(scrollAnimation),
2402
2395
  isPinned: z.boolean().optional(),
2403
2396
  debug: z.boolean().optional()
2404
2397
  });
2405
- const viewAnimationSchema = baseAnimation.merge(
2398
+ const viewAnimation = baseAnimation.merge(
2406
2399
  z.object({
2407
- timing: keyframeEffectOptionsSchema.merge(viewRangeOptionsSchema)
2400
+ timing: keyframeEffectOptions.merge(viewRangeOptions)
2408
2401
  })
2409
2402
  );
2410
- const viewActionSchema = z.object({
2403
+ const viewAction = z.object({
2411
2404
  type: z.literal("view"),
2412
2405
  subject: z.string().optional(),
2413
- axis: animationAxisSchema.optional(),
2414
- animations: z.array(viewAnimationSchema),
2415
- insetStart: insetUnitValueSchema.optional(),
2416
- insetEnd: insetUnitValueSchema.optional(),
2406
+ axis: animationAxis.optional(),
2407
+ animations: z.array(viewAnimation),
2408
+ insetStart: insetUnitValue.optional(),
2409
+ insetEnd: insetUnitValue.optional(),
2417
2410
  isPinned: z.boolean().optional(),
2418
2411
  debug: z.boolean().optional()
2419
2412
  });
2420
- const animationActionSchema = z.discriminatedUnion("type", [
2421
- scrollActionSchema,
2422
- viewActionSchema
2413
+ const animationAction = z.discriminatedUnion("type", [
2414
+ scrollAction,
2415
+ viewAction
2423
2416
  ]);
2424
- const PropId = z.string();
2417
+ const propId = z.string();
2425
2418
  const baseProp = {
2426
- id: PropId,
2419
+ id: propId,
2427
2420
  instanceId: z.string(),
2428
2421
  name: z.string(),
2429
2422
  required: z.optional(z.boolean())
2430
2423
  };
2431
- const Prop = z.union([
2424
+ const prop = z.union([
2432
2425
  z.object({
2433
2426
  ...baseProp,
2434
2427
  type: z.literal("number"),
@@ -2504,22 +2497,22 @@ const Prop = z.union([
2504
2497
  z.object({
2505
2498
  ...baseProp,
2506
2499
  type: z.literal("animationAction"),
2507
- value: animationActionSchema
2500
+ value: animationAction
2508
2501
  })
2509
2502
  ]);
2510
- z.map(PropId, Prop);
2511
- const ResourceId = z.string();
2512
- const Method = z.union([
2503
+ z.map(propId, prop);
2504
+ const resourceId = z.string();
2505
+ const method = z.union([
2513
2506
  z.literal("get"),
2514
2507
  z.literal("post"),
2515
2508
  z.literal("put"),
2516
2509
  z.literal("delete")
2517
2510
  ]);
2518
- const Resource = z.object({
2519
- id: ResourceId,
2511
+ const resource = z.object({
2512
+ id: resourceId,
2520
2513
  name: z.string(),
2521
2514
  control: z.optional(z.union([z.literal("system"), z.literal("graphql")])),
2522
- method: Method,
2515
+ method,
2523
2516
  // expression
2524
2517
  url: z.string(),
2525
2518
  searchParams: z.array(
@@ -2541,7 +2534,7 @@ const Resource = z.object({
2541
2534
  });
2542
2535
  z.object({
2543
2536
  name: z.string(),
2544
- method: Method,
2537
+ method,
2545
2538
  url: z.string(),
2546
2539
  searchParams: z.array(
2547
2540
  z.object({
@@ -2559,38 +2552,38 @@ z.object({
2559
2552
  ),
2560
2553
  body: z.optional(z.unknown())
2561
2554
  });
2562
- z.map(ResourceId, Resource);
2563
- const InstanceId = z.string();
2564
- const StyleSourceId$1 = z.string();
2565
- const StyleSourceSelection = z.object({
2566
- instanceId: InstanceId,
2567
- values: z.array(StyleSourceId$1)
2555
+ z.map(resourceId, resource);
2556
+ const instanceId = z.string();
2557
+ const styleSourceId$1 = z.string();
2558
+ const styleSourceSelection = z.object({
2559
+ instanceId,
2560
+ values: z.array(styleSourceId$1)
2568
2561
  });
2569
- z.map(InstanceId, StyleSourceSelection);
2570
- const StyleSourceId = z.string();
2571
- const StyleSourceToken = z.object({
2562
+ z.map(instanceId, styleSourceSelection);
2563
+ const styleSourceId = z.string();
2564
+ const styleSourceToken = z.object({
2572
2565
  type: z.literal("token"),
2573
- id: StyleSourceId,
2566
+ id: styleSourceId,
2574
2567
  name: z.string(),
2575
2568
  locked: z.boolean().optional()
2576
2569
  });
2577
- const StyleSourceLocal = z.object({
2570
+ const styleSourceLocal = z.object({
2578
2571
  type: z.literal("local"),
2579
- id: StyleSourceId
2572
+ id: styleSourceId
2580
2573
  });
2581
- const StyleSource = z.union([StyleSourceToken, StyleSourceLocal]);
2582
- z.map(StyleSourceId, StyleSource);
2583
- const StyleDeclRaw = z.object({
2574
+ const styleSource = z.union([styleSourceToken, styleSourceLocal]);
2575
+ z.map(styleSourceId, styleSource);
2576
+ const styleDeclRaw = z.object({
2584
2577
  styleSourceId: z.string(),
2585
2578
  breakpointId: z.string(),
2586
2579
  state: z.optional(z.string()),
2587
2580
  // @todo can't figure out how to make property to be enum
2588
2581
  property: z.string(),
2589
- value: StyleValue,
2582
+ value: styleValue,
2590
2583
  listed: z.boolean().optional().describe("Whether the style is from the Advanced panel")
2591
2584
  });
2592
- const StyleDecl = StyleDeclRaw;
2593
- z.map(z.string(), StyleDecl);
2585
+ const styleDecl = styleDeclRaw;
2586
+ z.map(z.string(), styleDecl);
2594
2587
  const ALLOWED_FILE_TYPES = {
2595
2588
  // Documents
2596
2589
  pdf: "application/pdf",
@@ -2703,37 +2696,37 @@ const detectAssetType = (fileName) => {
2703
2696
  }
2704
2697
  return "file";
2705
2698
  };
2706
- const getAssetUrl = (asset, origin) => {
2699
+ const getAssetUrl = (asset2, origin) => {
2707
2700
  let path;
2708
- const assetType = detectAssetType(asset.name);
2709
- if (assetType === "image") {
2710
- path = `/cgi/image/${asset.name}?format=raw`;
2701
+ const assetType2 = detectAssetType(asset2.name);
2702
+ if (assetType2 === "image") {
2703
+ path = `/cgi/image/${asset2.name}?format=raw`;
2711
2704
  } else {
2712
- path = `/cgi/asset/${asset.name}?format=raw`;
2705
+ path = `/cgi/asset/${asset2.name}?format=raw`;
2713
2706
  }
2714
2707
  return new URL(path, origin);
2715
2708
  };
2716
- const extractImageMetadata = (asset) => {
2717
- if (asset.type !== "image") {
2709
+ const extractImageMetadata = (asset2) => {
2710
+ if (asset2.type !== "image") {
2718
2711
  return;
2719
2712
  }
2720
- if (asset.meta.width && asset.meta.height) {
2713
+ if (asset2.meta.width && asset2.meta.height) {
2721
2714
  return {
2722
- width: asset.meta.width,
2723
- height: asset.meta.height
2715
+ width: asset2.meta.width,
2716
+ height: asset2.meta.height
2724
2717
  };
2725
2718
  }
2726
2719
  };
2727
- const extractFontMetadata = (asset) => {
2728
- if (asset.type !== "font") {
2720
+ const extractFontMetadata = (asset2) => {
2721
+ if (asset2.type !== "font") {
2729
2722
  return;
2730
2723
  }
2731
2724
  const metadata = {
2732
- family: asset.meta.family
2725
+ family: asset2.meta.family
2733
2726
  };
2734
- if ("style" in asset.meta) {
2735
- metadata.style = asset.meta.style;
2736
- metadata.weight = asset.meta.weight;
2727
+ if ("style" in asset2.meta) {
2728
+ metadata.style = asset2.meta.style;
2729
+ metadata.weight = asset2.meta.weight;
2737
2730
  }
2738
2731
  return metadata;
2739
2732
  };
@@ -2745,10 +2738,10 @@ const metadataExtractors = {
2745
2738
  font: extractFontMetadata,
2746
2739
  file: extractFileMetadata
2747
2740
  };
2748
- const toRuntimeAsset = (asset, origin) => {
2749
- const extractor = metadataExtractors[asset.type];
2750
- const metadata = extractor(asset);
2751
- const url = getAssetUrl(asset, origin);
2741
+ const toRuntimeAsset = (asset2, origin) => {
2742
+ const extractor = metadataExtractors[asset2.type];
2743
+ const metadata = extractor(asset2);
2744
+ const url = getAssetUrl(asset2, origin);
2752
2745
  const relativeUrl = url.pathname + url.search;
2753
2746
  return {
2754
2747
  url: relativeUrl,
@@ -3441,16 +3434,16 @@ const coreMetas = {
3441
3434
  };
3442
3435
  const isCoreComponent = (component) => component === rootComponent || component === elementComponent || component === collectionComponent || component === descendantComponent || component === blockComponent || component === blockTemplateComponent;
3443
3436
  const ROOT_INSTANCE_ID = ":root";
3444
- const traverseInstances = (instances, instanceId, callback) => {
3445
- const instance = instances.get(instanceId);
3446
- if (instance === void 0) {
3437
+ const traverseInstances = (instances, instanceId2, callback) => {
3438
+ const instance2 = instances.get(instanceId2);
3439
+ if (instance2 === void 0) {
3447
3440
  return;
3448
3441
  }
3449
- const skipTraversingChildren = callback(instance);
3442
+ const skipTraversingChildren = callback(instance2);
3450
3443
  if (skipTraversingChildren === false) {
3451
3444
  return;
3452
3445
  }
3453
- for (const child of instance.children) {
3446
+ for (const child of instance2.children) {
3454
3447
  if (child.type === "id") {
3455
3448
  traverseInstances(instances, child.value, callback);
3456
3449
  }
@@ -3458,8 +3451,8 @@ const traverseInstances = (instances, instanceId, callback) => {
3458
3451
  };
3459
3452
  const findTreeInstanceIds = (instances, rootInstanceId) => {
3460
3453
  const ids = /* @__PURE__ */ new Set([rootInstanceId]);
3461
- traverseInstances(instances, rootInstanceId, (instance) => {
3462
- ids.add(instance.id);
3454
+ traverseInstances(instances, rootInstanceId, (instance2) => {
3455
+ ids.add(instance2.id);
3463
3456
  });
3464
3457
  return ids;
3465
3458
  };
@@ -3476,30 +3469,30 @@ const parseComponentName = (componentName) => {
3476
3469
  };
3477
3470
  const getHtmlTagsFromProps = (props) => {
3478
3471
  const tags2 = /* @__PURE__ */ new Map();
3479
- for (const prop of props.values()) {
3480
- if (prop.type === "string" && prop.name === "tag") {
3481
- tags2.set(prop.instanceId, prop.value);
3472
+ for (const prop2 of props.values()) {
3473
+ if (prop2.type === "string" && prop2.name === "tag") {
3474
+ tags2.set(prop2.instanceId, prop2.value);
3482
3475
  }
3483
3476
  }
3484
3477
  return tags2;
3485
3478
  };
3486
3479
  const getHtmlTagFromInstance = ({
3487
- instance,
3480
+ instance: instance2,
3488
3481
  metas,
3489
3482
  props,
3490
3483
  htmlTagsByInstanceId
3491
3484
  }) => {
3492
- if (instance.component === "XmlNode") {
3485
+ if (instance2.component === "XmlNode") {
3493
3486
  return;
3494
3487
  }
3495
- if (instance.tag !== void 0) {
3496
- return instance.tag;
3488
+ if (instance2.tag !== void 0) {
3489
+ return instance2.tag;
3497
3490
  }
3498
- const propTag = htmlTagsByInstanceId === void 0 ? props === void 0 ? void 0 : getHtmlTagsFromProps(props).get(instance.id) : htmlTagsByInstanceId.get(instance.id);
3491
+ const propTag = htmlTagsByInstanceId === void 0 ? props === void 0 ? void 0 : getHtmlTagsFromProps(props).get(instance2.id) : htmlTagsByInstanceId.get(instance2.id);
3499
3492
  if (propTag !== void 0) {
3500
3493
  return propTag;
3501
3494
  }
3502
- const meta = metas.get(instance.component);
3495
+ const meta = metas.get(instance2.component);
3503
3496
  const metaTag = Object.keys((meta == null ? void 0 : meta.presetStyle) ?? {}).at(0);
3504
3497
  return metaTag;
3505
3498
  };
@@ -3511,17 +3504,17 @@ const getIndexesWithinAncestors = (metas, instances, rootIds) => {
3511
3504
  }
3512
3505
  }
3513
3506
  const indexes = /* @__PURE__ */ new Map();
3514
- const traverseInstances2 = (instances2, instanceId, latestIndexes2 = /* @__PURE__ */ new Map()) => {
3515
- const instance = instances2.get(instanceId);
3516
- if (instance === void 0) {
3507
+ const traverseInstances2 = (instances2, instanceId2, latestIndexes2 = /* @__PURE__ */ new Map()) => {
3508
+ const instance2 = instances2.get(instanceId2);
3509
+ if (instance2 === void 0) {
3517
3510
  return;
3518
3511
  }
3519
- const meta = metas.get(instance.component);
3520
- if (ancestors.has(instance.component)) {
3512
+ const meta = metas.get(instance2.component);
3513
+ if (ancestors.has(instance2.component)) {
3521
3514
  latestIndexes2 = new Map(latestIndexes2);
3522
- latestIndexes2.set(instance.component, /* @__PURE__ */ new Map());
3515
+ latestIndexes2.set(instance2.component, /* @__PURE__ */ new Map());
3523
3516
  }
3524
- if (instance.component === blockTemplateComponent) {
3517
+ if (instance2.component === blockTemplateComponent) {
3525
3518
  latestIndexes2 = new Map(latestIndexes2);
3526
3519
  for (const key of latestIndexes2.keys()) {
3527
3520
  latestIndexes2.set(key, /* @__PURE__ */ new Map());
@@ -3530,21 +3523,21 @@ const getIndexesWithinAncestors = (metas, instances, rootIds) => {
3530
3523
  if ((meta == null ? void 0 : meta.indexWithinAncestor) !== void 0) {
3531
3524
  const ancestorIndexes = latestIndexes2.get(meta.indexWithinAncestor);
3532
3525
  if (ancestorIndexes) {
3533
- let index = ancestorIndexes.get(instance.component) ?? -1;
3526
+ let index = ancestorIndexes.get(instance2.component) ?? -1;
3534
3527
  index += 1;
3535
- ancestorIndexes.set(instance.component, index);
3536
- indexes.set(instance.id, index);
3528
+ ancestorIndexes.set(instance2.component, index);
3529
+ indexes.set(instance2.id, index);
3537
3530
  }
3538
3531
  }
3539
- for (const child of instance.children) {
3532
+ for (const child of instance2.children) {
3540
3533
  if (child.type === "id") {
3541
3534
  traverseInstances2(instances2, child.value, latestIndexes2);
3542
3535
  }
3543
3536
  }
3544
3537
  };
3545
3538
  const latestIndexes = /* @__PURE__ */ new Map();
3546
- for (const instanceId of rootIds) {
3547
- traverseInstances2(instances, instanceId, latestIndexes);
3539
+ for (const instanceId2 of rootIds) {
3540
+ traverseInstances2(instances, instanceId2, latestIndexes);
3548
3541
  }
3549
3542
  return indexes;
3550
3543
  };
@@ -3734,72 +3727,72 @@ const tokenRegex = new RegExp(":(?<name>\\w+)(?<modifier>[?*]?)|(?<wildcard>(?<!
3734
3727
  const isPathnamePattern = (pathname) => tokenRegex.test(pathname);
3735
3728
  const ROOT_FOLDER_ID = "root";
3736
3729
  const isRootFolder = ({ id }) => id === ROOT_FOLDER_ID;
3737
- const getPageById = (pages, pageId) => {
3738
- return pages.pages.get(pageId);
3730
+ const getPageById = (pages2, pageId2) => {
3731
+ return pages2.pages.get(pageId2);
3739
3732
  };
3740
- const getAllPages = (pages) => {
3741
- return Array.from(pages.pages.values());
3733
+ const getAllPages = (pages2) => {
3734
+ return Array.from(pages2.pages.values());
3742
3735
  };
3743
- const getAllFolders = (pages) => {
3744
- return Array.from(pages.folders.values());
3736
+ const getAllFolders = (pages2) => {
3737
+ return Array.from(pages2.folders.values());
3745
3738
  };
3746
- const getHomePage = (pages) => {
3747
- const homePage = getPageById(pages, pages.homePageId);
3739
+ const getHomePage = (pages2) => {
3740
+ const homePage = getPageById(pages2, pages2.homePageId);
3748
3741
  if (homePage === void 0) {
3749
- throw new Error(`Home page "${pages.homePageId}" was not found.`);
3742
+ throw new Error(`Home page "${pages2.homePageId}" was not found.`);
3750
3743
  }
3751
3744
  return homePage;
3752
3745
  };
3753
- function findPageByIdOrPath(idOrPath, pages, options = {}) {
3746
+ function findPageByIdOrPath(idOrPath, pages2, options = {}) {
3754
3747
  var _a;
3755
- if (idOrPath === "" || idOrPath === "/" || idOrPath === pages.homePageId) {
3756
- return getHomePage(pages);
3748
+ if (idOrPath === "" || idOrPath === "/" || idOrPath === pages2.homePageId) {
3749
+ return getHomePage(pages2);
3757
3750
  }
3758
- const found = getAllPages(pages).find(
3759
- (page) => page.id === idOrPath || getPagePath(page.id, pages) === idOrPath
3751
+ const found = getAllPages(pages2).find(
3752
+ (page2) => page2.id === idOrPath || getPagePath(page2.id, pages2) === idOrPath
3760
3753
  );
3761
3754
  if (found) {
3762
3755
  return found;
3763
3756
  }
3764
3757
  if (options.includeTemplates) {
3765
- return (_a = pages.pageTemplates) == null ? void 0 : _a.get(idOrPath);
3758
+ return (_a = pages2.pageTemplates) == null ? void 0 : _a.get(idOrPath);
3766
3759
  }
3767
3760
  }
3768
- const getPagePath = (id, pages) => {
3761
+ const getPagePath = (id, pages2) => {
3769
3762
  const foldersMap = /* @__PURE__ */ new Map();
3770
3763
  const childParentMap = /* @__PURE__ */ new Map();
3771
- for (const folder of getAllFolders(pages)) {
3772
- foldersMap.set(folder.id, folder);
3773
- for (const childId of folder.children) {
3774
- childParentMap.set(childId, folder.id);
3764
+ for (const folder2 of getAllFolders(pages2)) {
3765
+ foldersMap.set(folder2.id, folder2);
3766
+ for (const childId of folder2.children) {
3767
+ childParentMap.set(childId, folder2.id);
3775
3768
  }
3776
3769
  }
3777
3770
  const paths = [];
3778
3771
  let currentId = id;
3779
- const allPages = getAllPages(pages);
3780
- for (const page of allPages) {
3781
- if (page.id === id) {
3782
- paths.push(page.path);
3783
- currentId = childParentMap.get(page.id);
3772
+ const allPages = getAllPages(pages2);
3773
+ for (const page2 of allPages) {
3774
+ if (page2.id === id) {
3775
+ paths.push(page2.path);
3776
+ currentId = childParentMap.get(page2.id);
3784
3777
  break;
3785
3778
  }
3786
3779
  }
3787
3780
  while (currentId) {
3788
- const folder = foldersMap.get(currentId);
3789
- if (folder === void 0) {
3781
+ const folder2 = foldersMap.get(currentId);
3782
+ if (folder2 === void 0) {
3790
3783
  break;
3791
3784
  }
3792
- paths.push(folder.slug);
3785
+ paths.push(folder2.slug);
3793
3786
  currentId = childParentMap.get(currentId);
3794
3787
  }
3795
3788
  return paths.reverse().join("/").replace(/\/+/g, "/");
3796
3789
  };
3797
- const getStaticSiteMapXml = (pages, updatedAt) => {
3798
- const allPages = getAllPages(pages);
3799
- return allPages.filter((page) => (page.meta.documentType ?? "html") === "html").filter(
3800
- (page) => executeExpression(page.meta.excludePageFromSearch) !== true
3801
- ).filter((page) => false === isPathnamePattern(page.path)).map((page) => ({
3802
- path: getPagePath(page.id, pages),
3790
+ const getStaticSiteMapXml = (pages2, updatedAt) => {
3791
+ const allPages = getAllPages(pages2);
3792
+ return allPages.filter((page2) => (page2.meta.documentType ?? "html") === "html").filter(
3793
+ (page2) => executeExpression(page2.meta.excludePageFromSearch) !== true
3794
+ ).filter((page2) => false === isPathnamePattern(page2.path)).map((page2) => ({
3795
+ path: getPagePath(page2.id, pages2),
3803
3796
  lastModified: updatedAt.split("T")[0]
3804
3797
  }));
3805
3798
  };
@@ -3846,22 +3839,22 @@ const createScope = (occupiedIdentifiers = [], normalizeName = normalizeJsName,
3846
3839
  };
3847
3840
  const generateResources = ({
3848
3841
  scope,
3849
- page,
3842
+ page: page2,
3850
3843
  dataSources,
3851
3844
  props,
3852
3845
  resources
3853
3846
  }) => {
3854
3847
  const usedDataSources = /* @__PURE__ */ new Map();
3855
3848
  let generatedRequests = "";
3856
- for (const resource of resources.values()) {
3849
+ for (const resource2 of resources.values()) {
3857
3850
  let generatedRequest = "";
3858
- const resourceName = scope.getName(resource.id, resource.name);
3851
+ const resourceName = scope.getName(resource2.id, resource2.name);
3859
3852
  generatedRequest += ` const ${resourceName}: ResourceRequest = {
3860
3853
  `;
3861
- generatedRequest += ` name: ${JSON.stringify(resource.name)},
3854
+ generatedRequest += ` name: ${JSON.stringify(resource2.name)},
3862
3855
  `;
3863
3856
  const url = generateExpression({
3864
- expression: resource.url,
3857
+ expression: resource2.url,
3865
3858
  dataSources,
3866
3859
  usedDataSources,
3867
3860
  scope
@@ -3870,7 +3863,7 @@ const generateResources = ({
3870
3863
  `;
3871
3864
  generatedRequest += ` searchParams: [
3872
3865
  `;
3873
- for (const searchParam of resource.searchParams ?? []) {
3866
+ for (const searchParam of resource2.searchParams ?? []) {
3874
3867
  const value = generateExpression({
3875
3868
  expression: searchParam.value,
3876
3869
  dataSources,
@@ -3882,11 +3875,11 @@ const generateResources = ({
3882
3875
  }
3883
3876
  generatedRequest += ` ],
3884
3877
  `;
3885
- generatedRequest += ` method: "${resource.method}",
3878
+ generatedRequest += ` method: "${resource2.method}",
3886
3879
  `;
3887
3880
  generatedRequest += ` headers: [
3888
3881
  `;
3889
- for (const header2 of resource.headers) {
3882
+ for (const header2 of resource2.headers) {
3890
3883
  const value = generateExpression({
3891
3884
  expression: header2.value,
3892
3885
  dataSources,
@@ -3898,9 +3891,9 @@ const generateResources = ({
3898
3891
  }
3899
3892
  generatedRequest += ` ],
3900
3893
  `;
3901
- if (resource.body !== void 0 && resource.body.length > 0) {
3894
+ if (resource2.body !== void 0 && resource2.body.length > 0) {
3902
3895
  const body2 = generateExpression({
3903
- expression: resource.body,
3896
+ expression: resource2.body,
3904
3897
  dataSources,
3905
3898
  usedDataSources,
3906
3899
  scope
@@ -3913,16 +3906,16 @@ const generateResources = ({
3913
3906
  generatedRequests += generatedRequest;
3914
3907
  }
3915
3908
  let generatedVariables = "";
3916
- for (const dataSource of usedDataSources.values()) {
3917
- if (dataSource.type === "variable") {
3918
- const name2 = scope.getName(dataSource.id, dataSource.name);
3919
- const value = JSON.stringify(dataSource.value.value);
3909
+ for (const dataSource2 of usedDataSources.values()) {
3910
+ if (dataSource2.type === "variable") {
3911
+ const name2 = scope.getName(dataSource2.id, dataSource2.name);
3912
+ const value = JSON.stringify(dataSource2.value.value);
3920
3913
  generatedVariables += ` let ${name2} = ${value}
3921
3914
  `;
3922
3915
  }
3923
- if (dataSource.type === "parameter") {
3924
- if (dataSource.id === page.systemDataSourceId || dataSource.id === SYSTEM_VARIABLE_ID) {
3925
- const name2 = scope.getName(dataSource.id, dataSource.name);
3916
+ if (dataSource2.type === "parameter") {
3917
+ if (dataSource2.id === page2.systemDataSourceId || dataSource2.id === SYSTEM_VARIABLE_ID) {
3918
+ const name2 = scope.getName(dataSource2.id, dataSource2.name);
3926
3919
  generatedVariables += ` const ${name2} = _props.system
3927
3920
  `;
3928
3921
  }
@@ -3937,9 +3930,9 @@ const generateResources = ({
3937
3930
  generated += generatedRequests;
3938
3931
  generated += ` const _data = new Map<string, ResourceRequest>([
3939
3932
  `;
3940
- for (const dataSource of dataSources.values()) {
3941
- if (dataSource.type === "resource") {
3942
- const name2 = scope.getName(dataSource.resourceId, dataSource.name);
3933
+ for (const dataSource2 of dataSources.values()) {
3934
+ if (dataSource2.type === "resource") {
3935
+ const name2 = scope.getName(dataSource2.resourceId, dataSource2.name);
3943
3936
  generated += ` ["${name2}", ${name2}],
3944
3937
  `;
3945
3938
  }
@@ -3948,9 +3941,9 @@ const generateResources = ({
3948
3941
  `;
3949
3942
  generated += ` const _action = new Map<string, ResourceRequest>([
3950
3943
  `;
3951
- for (const prop of props.values()) {
3952
- if (prop.type === "resource") {
3953
- const name2 = scope.getName(prop.value, prop.name);
3944
+ for (const prop2 of props.values()) {
3945
+ if (prop2.type === "resource") {
3946
+ const name2 = scope.getName(prop2.value, prop2.name);
3954
3947
  generated += ` ["${name2}", ${name2}],
3955
3948
  `;
3956
3949
  }
@@ -3982,38 +3975,38 @@ const replaceFormActionsWithResources = ({
3982
3975
  }) => {
3983
3976
  var _a, _b;
3984
3977
  const formProps = /* @__PURE__ */ new Map();
3985
- for (const prop of props.values()) {
3986
- if (prop.name === "method" && prop.type === "string" && ((_a = instances.get(prop.instanceId)) == null ? void 0 : _a.component) === "Form") {
3987
- let data = formProps.get(prop.instanceId);
3978
+ for (const prop2 of props.values()) {
3979
+ if (prop2.name === "method" && prop2.type === "string" && ((_a = instances.get(prop2.instanceId)) == null ? void 0 : _a.component) === "Form") {
3980
+ let data = formProps.get(prop2.instanceId);
3988
3981
  if (data === void 0) {
3989
3982
  data = {};
3990
- formProps.set(prop.instanceId, data);
3983
+ formProps.set(prop2.instanceId, data);
3991
3984
  }
3992
- data.method = prop.value;
3993
- props.delete(prop.id);
3985
+ data.method = prop2.value;
3986
+ props.delete(prop2.id);
3994
3987
  }
3995
- if (prop.name === "action" && prop.type === "string" && prop.value && ((_b = instances.get(prop.instanceId)) == null ? void 0 : _b.component) === "Form") {
3996
- let data = formProps.get(prop.instanceId);
3988
+ if (prop2.name === "action" && prop2.type === "string" && prop2.value && ((_b = instances.get(prop2.instanceId)) == null ? void 0 : _b.component) === "Form") {
3989
+ let data = formProps.get(prop2.instanceId);
3997
3990
  if (data === void 0) {
3998
3991
  data = {};
3999
- formProps.set(prop.instanceId, data);
3992
+ formProps.set(prop2.instanceId, data);
4000
3993
  }
4001
- data.action = prop.value;
4002
- props.set(prop.id, {
4003
- id: prop.id,
4004
- instanceId: prop.instanceId,
4005
- name: prop.name,
3994
+ data.action = prop2.value;
3995
+ props.set(prop2.id, {
3996
+ id: prop2.id,
3997
+ instanceId: prop2.instanceId,
3998
+ name: prop2.name,
4006
3999
  type: "resource",
4007
- value: prop.instanceId
4000
+ value: prop2.instanceId
4008
4001
  });
4009
4002
  }
4010
4003
  }
4011
- for (const [instanceId, { action, method }] of formProps) {
4004
+ for (const [instanceId2, { action, method: method2 }] of formProps) {
4012
4005
  if (action) {
4013
- resources.set(instanceId, {
4014
- id: instanceId,
4006
+ resources.set(instanceId2, {
4007
+ id: instanceId2,
4015
4008
  name: "action",
4016
- method: getMethod(method),
4009
+ method: getMethod(method2),
4017
4010
  url: JSON.stringify(action),
4018
4011
  headers: [
4019
4012
  { name: "Content-Type", value: JSON.stringify("application/json") }
@@ -4024,7 +4017,7 @@ const replaceFormActionsWithResources = ({
4024
4017
  };
4025
4018
  const generatePageMeta = ({
4026
4019
  globalScope,
4027
- page,
4020
+ page: page2,
4028
4021
  dataSources,
4029
4022
  assets
4030
4023
  }) => {
@@ -4032,52 +4025,52 @@ const generatePageMeta = ({
4032
4025
  const localScope = createScope(["system", "resources"]);
4033
4026
  const usedDataSources = /* @__PURE__ */ new Map();
4034
4027
  const titleExpression = generateExpression({
4035
- expression: page.title,
4028
+ expression: page2.title,
4036
4029
  dataSources,
4037
4030
  usedDataSources,
4038
4031
  scope: localScope
4039
4032
  });
4040
4033
  const descriptionExpression = generateExpression({
4041
- expression: page.meta.description ?? "undefined",
4034
+ expression: page2.meta.description ?? "undefined",
4042
4035
  dataSources,
4043
4036
  usedDataSources,
4044
4037
  scope: localScope
4045
4038
  });
4046
4039
  const excludePageFromSearchExpression = generateExpression({
4047
- expression: page.meta.excludePageFromSearch ?? "undefined",
4040
+ expression: page2.meta.excludePageFromSearch ?? "undefined",
4048
4041
  dataSources,
4049
4042
  usedDataSources,
4050
4043
  scope: localScope
4051
4044
  });
4052
4045
  const languageExpression = generateExpression({
4053
- expression: page.meta.language ?? "undefined",
4046
+ expression: page2.meta.language ?? "undefined",
4054
4047
  dataSources,
4055
4048
  usedDataSources,
4056
4049
  scope: localScope
4057
4050
  });
4058
4051
  const socialImageAssetNameExpression = JSON.stringify(
4059
- page.meta.socialImageAssetId ? (_a = assets.get(page.meta.socialImageAssetId)) == null ? void 0 : _a.name : void 0
4052
+ page2.meta.socialImageAssetId ? (_a = assets.get(page2.meta.socialImageAssetId)) == null ? void 0 : _a.name : void 0
4060
4053
  );
4061
4054
  const socialImageUrlExpression = generateExpression({
4062
- expression: page.meta.socialImageUrl ?? "undefined",
4055
+ expression: page2.meta.socialImageUrl ?? "undefined",
4063
4056
  dataSources,
4064
4057
  usedDataSources,
4065
4058
  scope: localScope
4066
4059
  });
4067
4060
  const statusExpression = generateExpression({
4068
- expression: page.meta.status ?? "undefined",
4061
+ expression: page2.meta.status ?? "undefined",
4069
4062
  dataSources,
4070
4063
  usedDataSources,
4071
4064
  scope: localScope
4072
4065
  });
4073
4066
  const redirectExpression = generateExpression({
4074
- expression: page.meta.redirect ?? "undefined",
4067
+ expression: page2.meta.redirect ?? "undefined",
4075
4068
  dataSources,
4076
4069
  usedDataSources,
4077
4070
  scope: localScope
4078
4071
  });
4079
4072
  const contentExpression = generateExpression({
4080
- expression: page.meta.content ?? "undefined",
4073
+ expression: page2.meta.content ?? "undefined",
4081
4074
  dataSources,
4082
4075
  usedDataSources,
4083
4076
  scope: localScope
@@ -4085,7 +4078,7 @@ const generatePageMeta = ({
4085
4078
  let customExpression = "";
4086
4079
  customExpression += `[
4087
4080
  `;
4088
- for (const customMeta of page.meta.custom ?? []) {
4081
+ for (const customMeta of page2.meta.custom ?? []) {
4089
4082
  if (customMeta.property.trim().length === 0) {
4090
4083
  continue;
4091
4084
  }
@@ -4121,27 +4114,27 @@ const generatePageMeta = ({
4121
4114
  `;
4122
4115
  generated += `}): PageMeta => {
4123
4116
  `;
4124
- for (const dataSource of usedDataSources.values()) {
4125
- if (dataSource.type === "variable") {
4126
- const valueName = localScope.getName(dataSource.id, dataSource.name);
4127
- const initialValueString = JSON.stringify(dataSource.value.value);
4117
+ for (const dataSource2 of usedDataSources.values()) {
4118
+ if (dataSource2.type === "variable") {
4119
+ const valueName = localScope.getName(dataSource2.id, dataSource2.name);
4120
+ const initialValueString = JSON.stringify(dataSource2.value.value);
4128
4121
  generated += ` let ${valueName} = ${initialValueString}
4129
4122
  `;
4130
4123
  continue;
4131
4124
  }
4132
- if (dataSource.type === "parameter") {
4133
- if (dataSource.id === page.systemDataSourceId || dataSource.id === SYSTEM_VARIABLE_ID) {
4134
- const valueName = localScope.getName(dataSource.id, dataSource.name);
4125
+ if (dataSource2.type === "parameter") {
4126
+ if (dataSource2.id === page2.systemDataSourceId || dataSource2.id === SYSTEM_VARIABLE_ID) {
4127
+ const valueName = localScope.getName(dataSource2.id, dataSource2.name);
4135
4128
  generated += ` let ${valueName} = system
4136
4129
  `;
4137
4130
  }
4138
4131
  continue;
4139
4132
  }
4140
- if (dataSource.type === "resource") {
4141
- const valueName = localScope.getName(dataSource.id, dataSource.name);
4133
+ if (dataSource2.type === "resource") {
4134
+ const valueName = localScope.getName(dataSource2.id, dataSource2.name);
4142
4135
  const resourceName = globalScope.getName(
4143
- dataSource.resourceId,
4144
- dataSource.name
4136
+ dataSource2.resourceId,
4137
+ dataSource2.name
4145
4138
  );
4146
4139
  generated += ` let ${valueName} = resources.${resourceName}
4147
4140
  `;
@@ -4182,9 +4175,9 @@ const addFontRules = ({
4182
4175
  assetBaseUrl
4183
4176
  }) => {
4184
4177
  const fontAssets = [];
4185
- for (const asset of assets.values()) {
4186
- if (asset.type === "font") {
4187
- fontAssets.push(asset);
4178
+ for (const asset2 of assets.values()) {
4179
+ if (asset2.type === "font") {
4180
+ fontAssets.push(asset2);
4188
4181
  }
4189
4182
  }
4190
4183
  const fontFaces = getFontFaces(fontAssets, { assetBaseUrl });
@@ -4192,20 +4185,20 @@ const addFontRules = ({
4192
4185
  sheet.addFontFaceRule(fontFace);
4193
4186
  }
4194
4187
  };
4195
- const createImageValueTransformer = (assets, { assetBaseUrl }) => (styleValue) => {
4196
- if (styleValue.type === "image" && styleValue.value.type === "asset") {
4197
- const asset = assets.get(styleValue.value.value);
4198
- if (asset === void 0) {
4188
+ const createImageValueTransformer = (assets, { assetBaseUrl }) => (styleValue2) => {
4189
+ if (styleValue2.type === "image" && styleValue2.value.type === "asset") {
4190
+ const asset2 = assets.get(styleValue2.value.value);
4191
+ if (asset2 === void 0) {
4199
4192
  return { type: "keyword", value: "none" };
4200
4193
  }
4201
- const url = `${assetBaseUrl}${asset.name}`;
4194
+ const url = `${assetBaseUrl}${asset2.name}`;
4202
4195
  return {
4203
4196
  type: "image",
4204
4197
  value: {
4205
4198
  type: "url",
4206
4199
  url
4207
4200
  },
4208
- hidden: styleValue.hidden
4201
+ hidden: styleValue2.hidden
4209
4202
  };
4210
4203
  }
4211
4204
  };
@@ -4231,14 +4224,14 @@ const generateCss = ({
4231
4224
  const tagsByComponent = /* @__PURE__ */ new Map();
4232
4225
  tagsByComponent.set(rootComponent, /* @__PURE__ */ new Set(["html"]));
4233
4226
  const htmlTagsByInstanceId = getHtmlTagsFromProps(props);
4234
- for (const instance of instances.values()) {
4235
- let componentTags = tagsByComponent.get(instance.component);
4227
+ for (const instance2 of instances.values()) {
4228
+ let componentTags = tagsByComponent.get(instance2.component);
4236
4229
  if (componentTags === void 0) {
4237
4230
  componentTags = /* @__PURE__ */ new Set();
4238
- tagsByComponent.set(instance.component, componentTags);
4231
+ tagsByComponent.set(instance2.component, componentTags);
4239
4232
  }
4240
4233
  const tag = getHtmlTagFromInstance({
4241
- instance,
4234
+ instance: instance2,
4242
4235
  metas: componentMetas,
4243
4236
  props,
4244
4237
  htmlTagsByInstanceId
@@ -4271,78 +4264,78 @@ const generateCss = ({
4271
4264
  }
4272
4265
  }
4273
4266
  }
4274
- for (const breakpoint of breakpoints.values()) {
4275
- userSheet.addMediaRule(breakpoint.id, breakpoint);
4267
+ for (const breakpoint2 of breakpoints.values()) {
4268
+ userSheet.addMediaRule(breakpoint2.id, breakpoint2);
4276
4269
  }
4277
4270
  const imageValueTransformer = createImageValueTransformer(assets, {
4278
4271
  assetBaseUrl
4279
4272
  });
4280
4273
  userSheet.setTransformer(imageValueTransformer);
4281
- for (const styleDecl of styles.values()) {
4282
- const rule = userSheet.addMixinRule(styleDecl.styleSourceId);
4274
+ for (const styleDecl2 of styles.values()) {
4275
+ const rule = userSheet.addMixinRule(styleDecl2.styleSourceId);
4283
4276
  rule.setDeclaration({
4284
- breakpoint: styleDecl.breakpointId,
4285
- selector: styleDecl.state ?? "",
4286
- property: styleDecl.property,
4287
- value: styleDecl.value
4277
+ breakpoint: styleDecl2.breakpointId,
4278
+ selector: styleDecl2.state ?? "",
4279
+ property: styleDecl2.property,
4280
+ value: styleDecl2.value
4288
4281
  });
4289
4282
  }
4290
4283
  const classes = /* @__PURE__ */ new Map();
4291
4284
  const parentIdByInstanceId = /* @__PURE__ */ new Map();
4292
- for (const instance of instances.values()) {
4293
- const presetClass = presetClasses.get(instance.component);
4285
+ for (const instance2 of instances.values()) {
4286
+ const presetClass = presetClasses.get(instance2.component);
4294
4287
  if (presetClass) {
4295
- classes.set(instance.id, [presetClass]);
4288
+ classes.set(instance2.id, [presetClass]);
4296
4289
  }
4297
- for (const child of instance.children) {
4290
+ for (const child of instance2.children) {
4298
4291
  if (child.type === "id") {
4299
- parentIdByInstanceId.set(child.value, instance.id);
4292
+ parentIdByInstanceId.set(child.value, instance2.id);
4300
4293
  }
4301
4294
  }
4302
4295
  }
4303
4296
  const descendantSelectorByInstanceId = /* @__PURE__ */ new Map();
4304
- for (const prop of props.values()) {
4305
- if (prop.name === "selector" && prop.type === "string") {
4306
- descendantSelectorByInstanceId.set(prop.instanceId, prop.value);
4297
+ for (const prop2 of props.values()) {
4298
+ if (prop2.name === "selector" && prop2.type === "string") {
4299
+ descendantSelectorByInstanceId.set(prop2.instanceId, prop2.value);
4307
4300
  }
4308
4301
  }
4309
4302
  const instanceByRule = /* @__PURE__ */ new Map();
4310
4303
  for (const selection of styleSourceSelections.values()) {
4311
- let { instanceId } = selection;
4304
+ let { instanceId: instanceId2 } = selection;
4312
4305
  const { values } = selection;
4313
- if (instanceId === ROOT_INSTANCE_ID) {
4306
+ if (instanceId2 === ROOT_INSTANCE_ID) {
4314
4307
  const rule2 = userSheet.addNestingRule(`:root`);
4315
4308
  rule2.applyMixins(values);
4316
4309
  continue;
4317
4310
  }
4318
4311
  let descendantSuffix = "";
4319
- const instance = instances.get(instanceId);
4320
- if (instance === void 0) {
4312
+ const instance2 = instances.get(instanceId2);
4313
+ if (instance2 === void 0) {
4321
4314
  continue;
4322
4315
  }
4323
- if (instance.component === descendantComponent) {
4324
- const parentId = parentIdByInstanceId.get(instanceId);
4325
- const descendantSelector = descendantSelectorByInstanceId.get(instanceId);
4316
+ if (instance2.component === descendantComponent) {
4317
+ const parentId = parentIdByInstanceId.get(instanceId2);
4318
+ const descendantSelector = descendantSelectorByInstanceId.get(instanceId2);
4326
4319
  if (parentId && descendantSelector) {
4327
4320
  descendantSuffix = descendantSelector;
4328
- instanceId = parentId;
4321
+ instanceId2 = parentId;
4329
4322
  }
4330
4323
  }
4331
- const meta = componentMetas.get(instance.component);
4332
- const [_namespace, shortName] = parseComponentName(instance.component);
4333
- const baseName = instance.label ?? (meta == null ? void 0 : meta.label) ?? shortName;
4334
- const className = `w-${scope.getName(instanceId, baseName)}`;
4324
+ const meta = componentMetas.get(instance2.component);
4325
+ const [_namespace, shortName] = parseComponentName(instance2.component);
4326
+ const baseName = instance2.label ?? (meta == null ? void 0 : meta.label) ?? shortName;
4327
+ const className = `w-${scope.getName(instanceId2, baseName)}`;
4335
4328
  if (atomic === false) {
4336
- let classList = classes.get(instanceId);
4329
+ let classList = classes.get(instanceId2);
4337
4330
  if (classList === void 0) {
4338
4331
  classList = [];
4339
- classes.set(instanceId, classList);
4332
+ classes.set(instanceId2, classList);
4340
4333
  }
4341
4334
  classList.push(className);
4342
4335
  }
4343
4336
  const rule = userSheet.addNestingRule(`.${className}`, descendantSuffix);
4344
4337
  rule.applyMixins(values);
4345
- instanceByRule.set(rule, instanceId);
4338
+ instanceByRule.set(rule, instanceId2);
4346
4339
  }
4347
4340
  const fontCss = fontSheet.cssText;
4348
4341
  const presetCss = presetSheet.cssText.replaceAll(
@@ -4367,15 +4360,15 @@ ${userSheet.cssText}`,
4367
4360
  classes
4368
4361
  };
4369
4362
  };
4370
- const SerializedPagesSchema = z.object({
4371
- meta: ProjectMeta.optional(),
4372
- compiler: CompilerSettings.optional(),
4373
- redirects: z.array(PageRedirect).optional(),
4363
+ const serializedPages = z.object({
4364
+ meta: projectMeta.optional(),
4365
+ compiler: compilerSettings.optional(),
4366
+ redirects: z.array(pageRedirect).optional(),
4374
4367
  homePageId: z.string(),
4375
4368
  rootFolderId: z.string(),
4376
- pages: z.array(Page),
4377
- pageTemplates: z.union([z.array(PageTemplate), z.record(PageTemplate)]).optional(),
4378
- folders: z.array(Folder)
4369
+ pages: z.array(page),
4370
+ pageTemplates: z.union([z.array(pageTemplate), z.record(pageTemplate)]).optional(),
4371
+ folders: z.array(folder)
4379
4372
  });
4380
4373
  const toMap = (items, normalizeItem = (item) => item) => {
4381
4374
  if (items instanceof Map) {
@@ -4386,40 +4379,40 @@ const toMap = (items, normalizeItem = (item) => item) => {
4386
4379
  const list = Array.isArray(items) ? items : Object.values(items);
4387
4380
  return new Map(list.map((item) => [item.id, normalizeItem(item)]));
4388
4381
  };
4389
- const normalizePage = (page) => ({
4390
- ...page,
4391
- meta: page.meta ?? {}
4382
+ const normalizePage = (page2) => ({
4383
+ ...page2,
4384
+ meta: page2.meta ?? {}
4392
4385
  });
4393
- const isLegacyPages = (pages) => {
4394
- if (typeof pages !== "object" || pages === null) {
4386
+ const isLegacyPages = (pages2) => {
4387
+ if (typeof pages2 !== "object" || pages2 === null) {
4395
4388
  return false;
4396
4389
  }
4397
- return "homePage" in pages && Array.isArray(pages.pages);
4390
+ return "homePage" in pages2 && Array.isArray(pages2.pages);
4398
4391
  };
4399
- const isSerializedPages = (pages) => {
4400
- if (typeof pages !== "object" || pages === null) {
4392
+ const isSerializedPages = (pages2) => {
4393
+ if (typeof pages2 !== "object" || pages2 === null) {
4401
4394
  return false;
4402
4395
  }
4403
- const candidate = pages;
4396
+ const candidate = pages2;
4404
4397
  return typeof candidate.homePageId === "string" && typeof candidate.rootFolderId === "string" && candidate.pages !== void 0 && candidate.folders !== void 0;
4405
4398
  };
4406
- const removeOrphanFolderChildren = (pages, folders) => {
4399
+ const removeOrphanFolderChildren = (pages2, folders) => {
4407
4400
  const nextFolders = /* @__PURE__ */ new Map();
4408
- for (const [folderId, folder] of folders) {
4409
- nextFolders.set(folderId, {
4410
- ...folder,
4411
- children: folder.children.filter(
4412
- (childId) => pages.has(childId) || folders.has(childId)
4401
+ for (const [folderId2, folder2] of folders) {
4402
+ nextFolders.set(folderId2, {
4403
+ ...folder2,
4404
+ children: folder2.children.filter(
4405
+ (childId) => pages2.has(childId) || folders.has(childId)
4413
4406
  )
4414
4407
  });
4415
4408
  }
4416
4409
  return nextFolders;
4417
4410
  };
4418
- const migratePages = (pages) => {
4411
+ const migratePages = (pagesData) => {
4419
4412
  var _a;
4420
- if (isSerializedPages(pages) && pages.pages instanceof Map && pages.folders instanceof Map) {
4421
- const currentPages = pages;
4422
- const result = Pages.safeParse(currentPages);
4413
+ if (isSerializedPages(pagesData) && pagesData.pages instanceof Map && pagesData.folders instanceof Map) {
4414
+ const currentPages = pagesData;
4415
+ const result = pages.safeParse(currentPages);
4423
4416
  if (result.success && currentPages.pageTemplates !== void 0) {
4424
4417
  return currentPages;
4425
4418
  }
@@ -4432,39 +4425,39 @@ const migratePages = (pages) => {
4432
4425
  )
4433
4426
  };
4434
4427
  }
4435
- if (isSerializedPages(pages)) {
4436
- const nextPages2 = toMap(pages.pages, normalizePage);
4437
- const nextFolders2 = toMap(pages.folders);
4428
+ if (isSerializedPages(pagesData)) {
4429
+ const nextPages2 = toMap(pagesData.pages, normalizePage);
4430
+ const nextFolders2 = toMap(pagesData.folders);
4438
4431
  return {
4439
- meta: pages.meta,
4440
- compiler: pages.compiler,
4441
- redirects: pages.redirects,
4442
- homePageId: pages.homePageId,
4443
- rootFolderId: pages.rootFolderId,
4432
+ meta: pagesData.meta,
4433
+ compiler: pagesData.compiler,
4434
+ redirects: pagesData.redirects,
4435
+ homePageId: pagesData.homePageId,
4436
+ rootFolderId: pagesData.rootFolderId,
4444
4437
  pages: nextPages2,
4445
- pageTemplates: pages.pageTemplates === void 0 ? /* @__PURE__ */ new Map() : toMap(pages.pageTemplates),
4438
+ pageTemplates: pagesData.pageTemplates === void 0 ? /* @__PURE__ */ new Map() : toMap(pagesData.pageTemplates),
4446
4439
  folders: removeOrphanFolderChildren(nextPages2, nextFolders2)
4447
4440
  };
4448
4441
  }
4449
- if (isLegacyPages(pages) === false) {
4442
+ if (isLegacyPages(pagesData) === false) {
4450
4443
  throw new Error("Pages data has unsupported shape.");
4451
4444
  }
4452
4445
  const homePage = {
4453
- ...normalizePage(pages.homePage),
4446
+ ...normalizePage(pagesData.homePage),
4454
4447
  path: ""
4455
4448
  };
4456
4449
  const nextPages = /* @__PURE__ */ new Map([[homePage.id, homePage]]);
4457
- for (const page of pages.pages) {
4458
- if (page.id === homePage.id) {
4450
+ for (const page2 of pagesData.pages) {
4451
+ if (page2.id === homePage.id) {
4459
4452
  continue;
4460
4453
  }
4461
- nextPages.set(page.id, normalizePage(page));
4454
+ nextPages.set(page2.id, normalizePage(page2));
4462
4455
  }
4463
4456
  const nextFolders = /* @__PURE__ */ new Map();
4464
- for (const folder of pages.folders ?? []) {
4465
- nextFolders.set(folder.id, { ...folder, children: [...folder.children] });
4457
+ for (const folder2 of pagesData.folders ?? []) {
4458
+ nextFolders.set(folder2.id, { ...folder2, children: [...folder2.children] });
4466
4459
  }
4467
- const rootFolder = Array.from(nextFolders.values()).find(isRootFolder) ?? ((_a = pages.folders) == null ? void 0 : _a[0]) ?? {
4460
+ const rootFolder = Array.from(nextFolders.values()).find(isRootFolder) ?? ((_a = pagesData.folders) == null ? void 0 : _a[0]) ?? {
4468
4461
  id: ROOT_FOLDER_ID,
4469
4462
  name: "Root",
4470
4463
  slug: "",
@@ -4477,25 +4470,25 @@ const migratePages = (pages) => {
4477
4470
  if (nextRootFolder === void 0) {
4478
4471
  throw new Error("Pages must include a root folder.");
4479
4472
  }
4480
- for (const folder of nextFolders.values()) {
4481
- folder.children = folder.children.filter(
4473
+ for (const folder2 of nextFolders.values()) {
4474
+ folder2.children = folder2.children.filter(
4482
4475
  (childId) => childId !== homePage.id && (nextPages.has(childId) || nextFolders.has(childId))
4483
4476
  );
4484
4477
  }
4485
4478
  nextRootFolder.children.unshift(homePage.id);
4486
4479
  const referencedIds = new Set(
4487
- Array.from(nextFolders.values()).flatMap((folder) => folder.children)
4480
+ Array.from(nextFolders.values()).flatMap((folder2) => folder2.children)
4488
4481
  );
4489
- for (const page of pages.pages) {
4490
- if (page.id !== homePage.id && referencedIds.has(page.id) === false) {
4491
- nextRootFolder.children.push(page.id);
4492
- referencedIds.add(page.id);
4482
+ for (const page2 of pagesData.pages) {
4483
+ if (page2.id !== homePage.id && referencedIds.has(page2.id) === false) {
4484
+ nextRootFolder.children.push(page2.id);
4485
+ referencedIds.add(page2.id);
4493
4486
  }
4494
4487
  }
4495
4488
  return {
4496
- meta: pages.meta,
4497
- compiler: pages.compiler,
4498
- redirects: pages.redirects,
4489
+ meta: pagesData.meta,
4490
+ compiler: pagesData.compiler,
4491
+ redirects: pagesData.redirects,
4499
4492
  homePageId: homePage.id,
4500
4493
  rootFolderId: rootFolder.id,
4501
4494
  pages: nextPages,
@@ -4503,26 +4496,26 @@ const migratePages = (pages) => {
4503
4496
  folders: nextFolders
4504
4497
  };
4505
4498
  };
4506
- const entrySchema = (value) => z.tuple([z.string(), value]);
4499
+ const entry = (value) => z.tuple([z.string(), value]);
4507
4500
  const serializedBuildShape = {
4508
4501
  id: z.string(),
4509
4502
  projectId: z.string(),
4510
4503
  version: z.number(),
4511
4504
  createdAt: z.string(),
4512
4505
  updatedAt: z.string(),
4513
- pages: SerializedPagesSchema,
4514
- breakpoints: z.array(entrySchema(Breakpoint)),
4515
- styles: z.array(entrySchema(StyleDecl)),
4516
- styleSources: z.array(entrySchema(StyleSource)),
4517
- styleSourceSelections: z.array(entrySchema(StyleSourceSelection)),
4518
- props: z.array(entrySchema(Prop)),
4519
- instances: z.array(entrySchema(Instance)),
4520
- dataSources: z.array(entrySchema(DataSource)),
4521
- resources: z.array(entrySchema(Resource)),
4522
- deployment: Deployment.optional()
4523
- };
4524
- const SerializedBuildSchema = z.object(serializedBuildShape);
4525
- const basicAuthInputSchema = z.union([
4506
+ pages: serializedPages,
4507
+ breakpoints: z.array(entry(breakpoint)),
4508
+ styles: z.array(entry(styleDecl)),
4509
+ styleSources: z.array(entry(styleSource)),
4510
+ styleSourceSelections: z.array(entry(styleSourceSelection)),
4511
+ props: z.array(entry(prop)),
4512
+ instances: z.array(entry(instance)),
4513
+ dataSources: z.array(entry(dataSource)),
4514
+ resources: z.array(entry(resource)),
4515
+ deployment: deployment.optional()
4516
+ };
4517
+ const serializedBuild = z.object(serializedBuildShape);
4518
+ const basicAuthInput = z.union([
4526
4519
  z.object({
4527
4520
  method: z.literal("basic"),
4528
4521
  login: z.string(),
@@ -4534,14 +4527,10 @@ const basicAuthInputSchema = z.union([
4534
4527
  password: z.string()
4535
4528
  })
4536
4529
  ]);
4537
- const wsAuthConfigSchema = z.object({
4530
+ const wsAuthConfig = z.object({
4538
4531
  version: z.literal(1),
4539
- routes: z.record(basicAuthInputSchema)
4532
+ routes: z.record(basicAuthInput)
4540
4533
  });
4541
- const version$1 = "0.271.0";
4542
- const packageJson$1 = {
4543
- version: version$1
4544
- };
4545
4534
  const getFunctionContract = (value) => {
4546
4535
  if (typeof value !== "function") {
4547
4536
  return;
@@ -4715,8 +4704,7 @@ const stableStringify = (value) => {
4715
4704
  }
4716
4705
  return JSON.stringify(value);
4717
4706
  };
4718
- const createContractVersion = (schema, version2, additionalSchemas = []) => {
4719
- const bundlePackageVersion = version2.replace(/-webstudio-version$/, "");
4707
+ const createContractVersion = (schema, additionalSchemas = []) => {
4720
4708
  let hash2 = 2166136261;
4721
4709
  for (const char of stableStringify({
4722
4710
  additionalSchemas: additionalSchemas.map(
@@ -4727,74 +4715,64 @@ const createContractVersion = (schema, version2, additionalSchemas = []) => {
4727
4715
  hash2 ^= char.charCodeAt(0);
4728
4716
  hash2 = Math.imul(hash2, 16777619);
4729
4717
  }
4730
- return `bundle-${bundlePackageVersion}-${(hash2 >>> 0).toString(16).padStart(8, "0")}`;
4731
- };
4732
- const assetFileDataPattern = /^[A-Za-z0-9+/]*={0,2}$/;
4733
- const isAssetFileDataString = (value) => {
4734
- if (value.length % 4 !== 0) {
4735
- return false;
4736
- }
4737
- if (assetFileDataPattern.test(value) === false) {
4738
- return false;
4718
+ return `bundle-${(hash2 >>> 0).toString(16).padStart(8, "0")}`;
4719
+ };
4720
+ const maxProjectBundleSize = 20 * 1024 * 1024;
4721
+ const stagedUploadPath = "/rest/staged-upload";
4722
+ const stagedUploadProjectIdHeader = "x-webstudio-project-id";
4723
+ const assetFileName = z.string().min(1).regex(/^(?!\.{1,2}$)[^/\\]+$/);
4724
+ const isAssetFileName = (value) => assetFileName.safeParse(value).success;
4725
+ const missingImportedAssetFilesPrefix = "Imported asset files are missing: ";
4726
+ const parseMissingImportedAssetFilesMessage = (error) => {
4727
+ const message = error instanceof Error ? error.message : String(error);
4728
+ const start = message.indexOf(missingImportedAssetFilesPrefix);
4729
+ if (start === -1) {
4730
+ return;
4739
4731
  }
4740
- const paddingIndex = value.indexOf("=");
4741
- return paddingIndex === -1 || paddingIndex >= value.length - 2;
4742
- };
4743
- const assertAssetFileDataString = Object.assign(
4744
- (value, context) => {
4745
- if (isAssetFileDataString(value)) {
4746
- return;
4747
- }
4748
- context.addIssue({
4749
- code: z.ZodIssueCode.custom,
4750
- message: "Invalid asset file data"
4751
- });
4752
- },
4753
- {
4754
- contract: {
4755
- encoding: "base64",
4756
- length: "multiple-of-4",
4757
- padding: "only-last-two-characters",
4758
- pattern: assetFileDataPattern
4732
+ const data = message.slice(start + missingImportedAssetFilesPrefix.length);
4733
+ try {
4734
+ const names = JSON.parse(data);
4735
+ if (Array.isArray(names) && names.every((name2) => typeof name2 === "string")) {
4736
+ return names;
4759
4737
  }
4738
+ } catch {
4760
4739
  }
4761
- );
4762
- const assetFileNameSchema = z.string().min(1).regex(/^(?!\.{1,2}$)[^/\\]+$/);
4763
- const isAssetFileName = (value) => assetFileNameSchema.safeParse(value).success;
4764
- const assetFileDataSchema = z.object({
4765
- name: assetFileNameSchema,
4766
- data: z.string().superRefine(assertAssetFileDataString)
4767
- });
4768
- const projectBundleSchema = z.object({
4769
- page: Page,
4770
- pages: z.array(Page),
4771
- build: SerializedBuildSchema,
4772
- assets: z.array(Asset),
4740
+ return data.split(",").map((name2) => name2.trim()).filter((name2) => name2 !== "");
4741
+ };
4742
+ const projectBundle = z.object({
4743
+ page,
4744
+ pages: z.array(page),
4745
+ build: serializedBuild,
4746
+ assets: z.array(asset),
4773
4747
  origin: z.string().optional()
4774
4748
  });
4775
- const publishedProjectBundleSchema = projectBundleSchema.extend({
4749
+ const publishedProjectBundle = projectBundle.extend({
4776
4750
  bundleVersion: z.union([z.string(), z.number()]).optional(),
4777
4751
  user: z.object({ email: z.string().nullable() }).optional(),
4778
4752
  projectDomain: z.string(),
4779
4753
  projectTitle: z.string()
4780
4754
  });
4781
4755
  z.object({
4782
- projectId: z.string(),
4783
- data: publishedProjectBundleSchema,
4784
- assetFiles: z.array(assetFileDataSchema).optional(),
4756
+ projectId: z.string().min(1),
4757
+ data: publishedProjectBundle.optional(),
4758
+ uploadId: z.string().min(1).optional(),
4785
4759
  ignoreVersionCheck: z.boolean().optional()
4786
- });
4787
- const importProjectBundleResultSchema = z.object({
4760
+ }).refine(
4761
+ ({ data, uploadId }) => data === void 0 !== (uploadId === void 0),
4762
+ {
4763
+ message: "Provide either project bundle data or an upload id",
4764
+ path: ["data"]
4765
+ }
4766
+ );
4767
+ const importProjectBundleResult = z.object({
4788
4768
  version: z.number()
4789
4769
  });
4790
4770
  z.object({
4791
- projectId: z.string()
4771
+ projectId: z.string().min(1)
4792
4772
  });
4793
- const bundleVersion = createContractVersion(
4794
- publishedProjectBundleSchema,
4795
- packageJson$1.version,
4796
- [wsAuthConfigSchema]
4797
- );
4773
+ const bundleVersion = createContractVersion(publishedProjectBundle, [
4774
+ wsAuthConfig
4775
+ ]);
4798
4776
  const getBundleVersion = (data) => {
4799
4777
  if (typeof data !== "object" || data === null) {
4800
4778
  return;
@@ -4806,6 +4784,48 @@ const getBundleVersionMismatchMessage = ({
4806
4784
  ignoreVersionCheckHint,
4807
4785
  receivedVersion
4808
4786
  }) => `Project bundle format is incompatible. Expected version ${bundleVersion}, received ${receivedVersion ?? "missing"}. Sync with a compatible API/CLI version and retry, or ${ignoreVersionCheckHint}.`;
4787
+ const maxResponsePreviewLength = 500;
4788
+ const getResponsePreview = async (response) => {
4789
+ try {
4790
+ const text2 = await response.clone().text();
4791
+ return text2.replace(/\s+/g, " ").trim().slice(0, maxResponsePreviewLength);
4792
+ } catch {
4793
+ return "";
4794
+ }
4795
+ };
4796
+ const createApiResponseErrorMessage = async (request, response) => {
4797
+ const contentType = response.headers.get("content-type") ?? "unknown";
4798
+ const status = `${response.status} ${response.statusText}`.trim();
4799
+ const url = typeof request === "string" || request instanceof URL ? request.toString() : request.url;
4800
+ const preview = await getResponsePreview(response);
4801
+ const hint = response.status === 413 ? "The request may be too large for the API." : void 0;
4802
+ return [
4803
+ `API returned ${contentType} instead of JSON from ${url}.`,
4804
+ `HTTP status: ${status}.`,
4805
+ preview === "" ? void 0 : `Response preview: ${preview}`,
4806
+ hint
4807
+ ].filter(Boolean).join("\n");
4808
+ };
4809
+ const fetchJsonResponse = async (request, init) => {
4810
+ const response = await fetch(request, init);
4811
+ const contentType = response.headers.get("content-type");
4812
+ if ((contentType == null ? void 0 : contentType.includes("json")) !== true) {
4813
+ throw new Error(await createApiResponseErrorMessage(request, response));
4814
+ }
4815
+ return response;
4816
+ };
4817
+ const createHeaders = (headers) => {
4818
+ return new Headers(createHeadersObject(headers));
4819
+ };
4820
+ const createHeadersObject = (headers) => {
4821
+ const result = {};
4822
+ for (const [name2, value] of Object.entries(headers)) {
4823
+ if (value !== void 0) {
4824
+ result[name2] = value;
4825
+ }
4826
+ }
4827
+ return result;
4828
+ };
4809
4829
  const createTrpcClient = (origin, headers) => {
4810
4830
  const { sourceOrigin } = parseBuilderUrl(origin);
4811
4831
  const url = new URL("/trpc", sourceOrigin);
@@ -4813,7 +4833,8 @@ const createTrpcClient = (origin, headers) => {
4813
4833
  links: [
4814
4834
  httpBatchLink({
4815
4835
  url: url.href,
4816
- headers
4836
+ headers,
4837
+ fetch: fetchJsonResponse
4817
4838
  })
4818
4839
  ]
4819
4840
  });
@@ -4822,6 +4843,50 @@ const createAuthTrpcClient = (params) => createTrpcClient(params.origin, {
4822
4843
  ...params.headers,
4823
4844
  "x-auth-token": params.authToken
4824
4845
  });
4846
+ const stagedUploadChunkSize = 3 * 1024 * 1024;
4847
+ const formatMebibytes = (bytes) => `${Math.round(bytes / 1024 / 1024)} MiB`;
4848
+ const getAssetUploadUrl = ({
4849
+ asset: asset2,
4850
+ origin,
4851
+ projectId
4852
+ }) => {
4853
+ const { sourceOrigin } = parseBuilderUrl(origin);
4854
+ const url = new URL(
4855
+ `/rest/assets/${encodeURIComponent(asset2.name)}`,
4856
+ sourceOrigin
4857
+ );
4858
+ url.searchParams.set("projectId", projectId);
4859
+ url.searchParams.set("type", asset2.type);
4860
+ if (asset2.type === "image") {
4861
+ url.searchParams.set("width", String(asset2.meta.width));
4862
+ url.searchParams.set("height", String(asset2.meta.height));
4863
+ url.searchParams.set("format", asset2.format);
4864
+ }
4865
+ return url;
4866
+ };
4867
+ const uploadAsset = async (params) => {
4868
+ const { authToken, headers, origin, projectId, upload } = params;
4869
+ const response = await fetchJsonResponse(
4870
+ getAssetUploadUrl({
4871
+ asset: upload.asset,
4872
+ origin,
4873
+ projectId
4874
+ }),
4875
+ {
4876
+ method: "POST",
4877
+ body: upload.data,
4878
+ headers: createHeaders({
4879
+ ...headers,
4880
+ "x-auth-token": authToken,
4881
+ "content-type": "application/octet-stream"
4882
+ })
4883
+ }
4884
+ );
4885
+ const result = await response.json();
4886
+ if (typeof result === "object" && result !== null && "errors" in result && typeof result.errors === "string") {
4887
+ throw new Error(result.errors);
4888
+ }
4889
+ };
4825
4890
  const loadProjectBundleByBuildId = async (params) => {
4826
4891
  const headers = "serviceToken" in params ? { Authorization: params.serviceToken } : { "x-auth-token": params.authToken };
4827
4892
  const data = await createTrpcClient(params.origin, {
@@ -4830,7 +4895,7 @@ const loadProjectBundleByBuildId = async (params) => {
4830
4895
  }).query("build.loadProjectBundleByBuildId", {
4831
4896
  buildId: params.buildId
4832
4897
  });
4833
- return publishedProjectBundleSchema.parse(data);
4898
+ return publishedProjectBundle.parse(data);
4834
4899
  };
4835
4900
  const loadProjectBundleByProjectId = async (params) => {
4836
4901
  const data = await createAuthTrpcClient(params).query(
@@ -4839,7 +4904,7 @@ const loadProjectBundleByProjectId = async (params) => {
4839
4904
  projectId: params.projectId
4840
4905
  }
4841
4906
  );
4842
- return publishedProjectBundleSchema.parse(data);
4907
+ return publishedProjectBundle.parse(data);
4843
4908
  };
4844
4909
  const checkProjectBuildPermission = async (params) => {
4845
4910
  await createAuthTrpcClient(params).query(
@@ -4849,17 +4914,59 @@ const checkProjectBuildPermission = async (params) => {
4849
4914
  }
4850
4915
  );
4851
4916
  };
4917
+ const getUploadIdFromUrl = (uploadUrl) => {
4918
+ if (uploadUrl === null) {
4919
+ throw new Error("Project bundle upload did not return an upload URL.");
4920
+ }
4921
+ const { pathname } = new URL(uploadUrl);
4922
+ const uploadId = pathname.split("/").filter(Boolean).at(-1);
4923
+ if (uploadId === void 0) {
4924
+ throw new Error("Project bundle upload did not return an upload id.");
4925
+ }
4926
+ return decodeURIComponent(uploadId);
4927
+ };
4928
+ const uploadProjectBundleData = async (params) => {
4929
+ const { sourceOrigin } = parseBuilderUrl(params.origin);
4930
+ const endpoint = new URL(stagedUploadPath, sourceOrigin);
4931
+ const data = JSON.stringify(params.data);
4932
+ if (new TextEncoder().encode(data).byteLength > maxProjectBundleSize) {
4933
+ throw new Error(
4934
+ `Project bundle is too large to import. Maximum size is ${formatMebibytes(maxProjectBundleSize)}.`
4935
+ );
4936
+ }
4937
+ const file = typeof Buffer === "undefined" ? new Blob([data], { type: "application/json" }) : Buffer.from(data);
4938
+ return await new Promise((resolve2, reject) => {
4939
+ const upload = new Upload(file, {
4940
+ endpoint: endpoint.href,
4941
+ chunkSize: stagedUploadChunkSize,
4942
+ retryDelays: [0, 1e3],
4943
+ removeFingerprintOnSuccess: true,
4944
+ storeFingerprintForResuming: false,
4945
+ headers: createHeadersObject({
4946
+ ...params.headers,
4947
+ "x-auth-token": params.authToken,
4948
+ [stagedUploadProjectIdHeader]: params.projectId
4949
+ }),
4950
+ metadata: {
4951
+ projectId: params.projectId
4952
+ },
4953
+ onError: reject,
4954
+ onSuccess: () => resolve2(getUploadIdFromUrl(upload.url))
4955
+ });
4956
+ upload.start();
4957
+ });
4958
+ };
4852
4959
  const importProjectBundle = async (params) => {
4960
+ const uploadId = await uploadProjectBundleData(params);
4853
4961
  const result = await createAuthTrpcClient(params).mutation(
4854
4962
  "build.importProjectBundle",
4855
4963
  {
4856
4964
  projectId: params.projectId,
4857
- data: params.data,
4858
- assetFiles: params.assetFiles,
4965
+ uploadId,
4859
4966
  ignoreVersionCheck: params.ignoreVersionCheck
4860
4967
  }
4861
4968
  );
4862
- return importProjectBundleResultSchema.parse(result);
4969
+ return importProjectBundleResult.parse(result);
4863
4970
  };
4864
4971
  const buildProjectDomainPrefix = "p-";
4865
4972
  const parseBuilderUrl = (urlStr) => {
@@ -5008,9 +5115,9 @@ const isHandledCliError = (error) => error instanceof HandledCliError;
5008
5115
  const apiCompatibilityErrorType = "webstudioApiCompatibilityError";
5009
5116
  const apiClientHeader = "x-webstudio-client";
5010
5117
  const apiClientVersionHeader = "x-webstudio-client-version";
5011
- const ApiCompatibilityTarget = z.enum(["browser", "cli"]);
5118
+ const apiCompatibilityTarget = z.enum(["browser", "cli"]);
5012
5119
  z.enum(["browser", "cli", "service"]);
5013
- const ApiCompatibilityAction = z.discriminatedUnion("type", [
5120
+ const apiCompatibilityAction = z.discriminatedUnion("type", [
5014
5121
  z.object({
5015
5122
  type: z.literal("reloadBrowser")
5016
5123
  }),
@@ -5018,17 +5125,17 @@ const ApiCompatibilityAction = z.discriminatedUnion("type", [
5018
5125
  type: z.literal("updateCli")
5019
5126
  })
5020
5127
  ]);
5021
- const ApiCompatibilityPayload = z.object({
5128
+ const apiCompatibilityPayload = z.object({
5022
5129
  type: z.literal(apiCompatibilityErrorType),
5023
5130
  reason: z.enum(["apiRouteNotFound", "apiProcedureNotFound"]),
5024
- target: ApiCompatibilityTarget,
5131
+ target: apiCompatibilityTarget,
5025
5132
  message: z.string(),
5026
- action: ApiCompatibilityAction
5133
+ action: apiCompatibilityAction
5027
5134
  });
5028
5135
  const isObject = (value) => typeof value === "object" && value !== null;
5029
5136
  const getApiCompatibilityPayload = (value) => {
5030
5137
  const findPayload = (value2, seen) => {
5031
- const parsed = ApiCompatibilityPayload.safeParse(value2);
5138
+ const parsed = apiCompatibilityPayload.safeParse(value2);
5032
5139
  if (parsed.success) {
5033
5140
  return parsed.data;
5034
5141
  }
@@ -5067,7 +5174,7 @@ const getApiCompatibilityPayload = (value) => {
5067
5174
  return findPayload(value, /* @__PURE__ */ new WeakSet());
5068
5175
  };
5069
5176
  const name = "webstudio";
5070
- const version = "0.271.0";
5177
+ const version = "0.273.0";
5071
5178
  const description = "Webstudio CLI";
5072
5179
  const author = "Webstudio <github@webstudio.is>";
5073
5180
  const homepage = "https://webstudio.is";
@@ -5078,8 +5185,8 @@ const files = ["lib/*", "templates/*", "bin.js", "!*.{test,stories}.*"];
5078
5185
  const scripts = { "typecheck": "tsgo --noEmit", "build": "rm -rf lib && vite build", "test": "vitest run" };
5079
5186
  const license = "AGPL-3.0-or-later";
5080
5187
  const engines = { "node": ">=22" };
5081
- const dependencies = { "@clack/prompts": "^0.10.0", "@emotion/hash": "^0.9.2", "@trpc/client": "^10.45.2", "@webstudio-is/protocol": "workspace:*", "@webstudio-is/project-migrations": "workspace:*", "@webstudio-is/trpc-interface": "workspace:*", "acorn": "^8.14.1", "acorn-walk": "^8.3.4", "change-case": "^5.4.4", "deepmerge": "^4.3.1", "env-paths": "^3.0.0", "nanoid": "^5.1.5", "p-limit": "^6.2.0", "parse5": "7.3.0", "picocolors": "^1.1.1", "reserved-identifiers": "^1.0.0", "tinyexec": "^0.3.2", "warn-once": "^0.1.1", "yargs": "^17.7.2", "zod": "^3.24.2" };
5082
- const devDependencies = { "@cloudflare/vite-plugin": "^1.1.0", "@netlify/vite-plugin-react-router": "^1.0.1", "@react-router/dev": "^7.5.3", "@react-router/fs-routes": "^7.5.3", "@remix-run/cloudflare": "^2.16.5", "@remix-run/cloudflare-pages": "^2.16.5", "@remix-run/dev": "^2.16.5", "@remix-run/node": "^2.16.5", "@remix-run/react": "^2.16.5", "@remix-run/server-runtime": "^2.16.5", "@types/react": "^18.2.70", "@types/react-dom": "^18.2.25", "@types/yargs": "^17.0.33", "@vercel/react-router": "^1.1.0", "@vitejs/plugin-react": "^4.4.1", "@webstudio-is/css-engine": "workspace:*", "@webstudio-is/http-client": "workspace:*", "@webstudio-is/image": "workspace:*", "@webstudio-is/react-sdk": "workspace:*", "@webstudio-is/sdk": "workspace:*", "@webstudio-is/sdk-components-animation": "workspace:*", "@webstudio-is/sdk-components-react": "workspace:*", "@webstudio-is/sdk-components-react-radix": "workspace:*", "@webstudio-is/sdk-components-react-remix": "workspace:*", "@webstudio-is/sdk-components-react-router": "workspace:*", "@webstudio-is/tsconfig": "workspace:*", "@webstudio-is/wsauth": "workspace:*", "h3": "^1.15.1", "ipx": "^3.0.3", "isbot": "^5.1.25", "prettier": "3.5.3", "react": "18.3.0-canary-14898b6a9-20240318", "react-dom": "18.3.0-canary-14898b6a9-20240318", "react-router": "^7.5.3", "ts-expect": "^1.3.0", "vike": "^0.4.229", "vite": "^6.3.4", "vitest": "^3.1.2", "wrangler": "^3.63.2" };
5188
+ const dependencies = { "@clack/prompts": "^0.10.0", "@emotion/hash": "^0.9.2", "@trpc/client": "^10.45.2", "@webstudio-is/project-migrations": "workspace:*", "@webstudio-is/trpc-interface": "workspace:*", "acorn": "^8.14.1", "acorn-walk": "^8.3.4", "change-case": "^5.4.4", "deepmerge": "^4.3.1", "env-paths": "^3.0.0", "nanoid": "^5.1.5", "p-limit": "^6.2.0", "parse5": "7.3.0", "picocolors": "^1.1.1", "reserved-identifiers": "^1.0.0", "tinyexec": "^0.3.2", "tus-js-client": "^4.3.1", "warn-once": "^0.1.1", "yargs": "^17.7.2", "zod": "^3.24.2" };
5189
+ const devDependencies = { "@cloudflare/vite-plugin": "^1.1.0", "@netlify/vite-plugin-react-router": "^1.0.1", "@react-router/dev": "^7.5.3", "@react-router/fs-routes": "^7.5.3", "@remix-run/cloudflare": "^2.16.5", "@remix-run/cloudflare-pages": "^2.16.5", "@remix-run/dev": "^2.16.5", "@remix-run/node": "^2.16.5", "@remix-run/react": "^2.16.5", "@remix-run/server-runtime": "^2.16.5", "@types/react": "^18.2.70", "@types/react-dom": "^18.2.25", "@types/yargs": "^17.0.33", "@vercel/react-router": "^1.1.0", "@vitejs/plugin-react": "^4.4.1", "@webstudio-is/css-engine": "workspace:*", "@webstudio-is/http-client": "workspace:*", "@webstudio-is/image": "workspace:*", "@webstudio-is/protocol": "workspace:*", "@webstudio-is/react-sdk": "workspace:*", "@webstudio-is/sdk": "workspace:*", "@webstudio-is/sdk-components-animation": "workspace:*", "@webstudio-is/sdk-components-react": "workspace:*", "@webstudio-is/sdk-components-react-radix": "workspace:*", "@webstudio-is/sdk-components-react-remix": "workspace:*", "@webstudio-is/sdk-components-react-router": "workspace:*", "@webstudio-is/tsconfig": "workspace:*", "@webstudio-is/wsauth": "workspace:*", "h3": "^1.15.1", "ipx": "^3.0.3", "isbot": "^5.1.25", "prettier": "3.5.3", "react": "18.3.0-canary-14898b6a9-20240318", "react-dom": "18.3.0-canary-14898b6a9-20240318", "react-router": "^7.5.3", "ts-expect": "^1.3.0", "vike": "^0.4.229", "vite": "^6.3.4", "vitest": "^3.1.2", "wrangler": "^3.63.2" };
5083
5190
  const packageJson = {
5084
5191
  name,
5085
5192
  version,
@@ -5130,12 +5237,12 @@ const runAssetTasks = async ({
5130
5237
  }) => {
5131
5238
  await Promise.all(
5132
5239
  assets.map(
5133
- (asset) => limit(async () => {
5240
+ (asset2) => limit(async () => {
5134
5241
  try {
5135
- await task(asset);
5242
+ await task(asset2);
5136
5243
  } catch (error) {
5137
5244
  if (continueOnError) {
5138
- console.error(`Error ${operation} file ${asset.name}
5245
+ console.error(`Error ${operation} file ${asset2.name}
5139
5246
  ${error}`);
5140
5247
  return;
5141
5248
  }
@@ -5145,6 +5252,14 @@ const runAssetTasks = async ({
5145
5252
  )
5146
5253
  );
5147
5254
  };
5255
+ const formatError = (error) => error instanceof Error ? error.message : String(error);
5256
+ const retryOnce = async (task) => {
5257
+ try {
5258
+ await task();
5259
+ } catch {
5260
+ await task();
5261
+ }
5262
+ };
5148
5263
  const getLocalAssetPath = (assetName, assetsDirectory = LOCAL_ASSETS_DIR) => {
5149
5264
  if (isAssetFileName(assetName) === false) {
5150
5265
  throw new Error(`Asset path escapes ${assetsDirectory}: ${assetName}`);
@@ -5182,13 +5297,13 @@ const downloadUrlToFile = async (url, filePath) => {
5182
5297
  }
5183
5298
  };
5184
5299
  const downloadAssetFile = async ({
5185
- asset,
5300
+ asset: asset2,
5186
5301
  assetsDirectory = LOCAL_ASSETS_DIR,
5187
5302
  origin
5188
5303
  }) => {
5189
5304
  await downloadUrlToFile(
5190
- getAssetUrl(asset, origin).href,
5191
- getLocalAssetPath(asset.name, assetsDirectory)
5305
+ getAssetUrl(asset2, origin).href,
5306
+ getLocalAssetPath(asset2.name, assetsDirectory)
5192
5307
  );
5193
5308
  };
5194
5309
  const downloadAssetFiles = async ({
@@ -5201,21 +5316,21 @@ const downloadAssetFiles = async ({
5201
5316
  assets,
5202
5317
  continueOnError,
5203
5318
  operation: "downloading",
5204
- task: (asset) => downloadAssetFile({ asset, assetsDirectory, origin })
5319
+ task: (asset2) => downloadAssetFile({ asset: asset2, assetsDirectory, origin })
5205
5320
  });
5206
5321
  };
5207
5322
  const materializeAssetFile = async ({
5208
- asset,
5323
+ asset: asset2,
5209
5324
  origin,
5210
5325
  sourceAssetsDirectory = LOCAL_ASSETS_DIR,
5211
5326
  targetAssetsDirectory
5212
5327
  }) => {
5213
- const targetPath = getLocalAssetPath(asset.name, targetAssetsDirectory);
5328
+ const targetPath = getLocalAssetPath(asset2.name, targetAssetsDirectory);
5214
5329
  if (await isFileExists(targetPath)) {
5215
5330
  return;
5216
5331
  }
5217
5332
  await createFolderIfNotExists(dirname(targetPath));
5218
- const sourcePath = getLocalAssetPath(asset.name, sourceAssetsDirectory);
5333
+ const sourcePath = getLocalAssetPath(asset2.name, sourceAssetsDirectory);
5219
5334
  if (await isFileExists(sourcePath)) {
5220
5335
  try {
5221
5336
  await copyFile(sourcePath, targetPath, constants$1.COPYFILE_FICLONE);
@@ -5225,7 +5340,7 @@ const materializeAssetFile = async ({
5225
5340
  return;
5226
5341
  }
5227
5342
  await downloadAssetFile({
5228
- asset,
5343
+ asset: asset2,
5229
5344
  assetsDirectory: targetAssetsDirectory,
5230
5345
  origin
5231
5346
  });
@@ -5241,27 +5356,54 @@ const materializeAssetFiles = async ({
5241
5356
  assets,
5242
5357
  continueOnError,
5243
5358
  operation: "materializing",
5244
- task: (asset) => materializeAssetFile({
5245
- asset,
5359
+ task: (asset2) => materializeAssetFile({
5360
+ asset: asset2,
5246
5361
  origin,
5247
5362
  sourceAssetsDirectory,
5248
5363
  targetAssetsDirectory
5249
5364
  })
5250
5365
  });
5251
5366
  };
5252
- const loadAssetFiles = async ({
5367
+ const uploadAssetFiles = async ({
5253
5368
  assets,
5254
- assetsDirectory = LOCAL_ASSETS_DIR
5369
+ assetsDirectory = LOCAL_ASSETS_DIR,
5370
+ authToken,
5371
+ headers,
5372
+ origin,
5373
+ projectId
5255
5374
  }) => {
5256
- const files2 = [];
5257
- for (const asset of assets) {
5258
- const data = await readFile(
5259
- getLocalAssetPath(asset.name, assetsDirectory),
5260
- "base64"
5375
+ const failedUploads = [];
5376
+ await runAssetTasks({
5377
+ assets,
5378
+ operation: "uploading",
5379
+ task: async (asset2) => {
5380
+ try {
5381
+ const file = await readFile(
5382
+ getLocalAssetPath(asset2.name, assetsDirectory)
5383
+ );
5384
+ const upload = async () => {
5385
+ await uploadAsset({
5386
+ authToken,
5387
+ headers,
5388
+ origin,
5389
+ projectId,
5390
+ upload: {
5391
+ asset: asset2,
5392
+ data: new Blob([new Uint8Array(file)])
5393
+ }
5394
+ });
5395
+ };
5396
+ await retryOnce(upload);
5397
+ } catch (error) {
5398
+ failedUploads.push({ asset: asset2, error });
5399
+ }
5400
+ }
5401
+ });
5402
+ if (failedUploads.length > 0) {
5403
+ throw new Error(
5404
+ `Failed to upload assets: ${failedUploads.map(({ asset: asset2, error }) => `${asset2.name}: ${formatError(error)}`).join("; ")}`
5261
5405
  );
5262
- files2.push({ name: asset.name, data });
5263
5406
  }
5264
- return files2;
5265
5407
  };
5266
5408
  const defaultDependencies$1 = {
5267
5409
  createFileIfNotExists,
@@ -5274,14 +5416,14 @@ const defaultDependencies$1 = {
5274
5416
  writeFile
5275
5417
  };
5276
5418
  const toLocalProjectBundle = (project) => {
5277
- const normalizedProject = publishedProjectBundleSchema.parse(project);
5419
+ const normalizedProject = publishedProjectBundle.parse(project);
5278
5420
  const {
5279
5421
  assets,
5280
5422
  build: build2,
5281
5423
  bundleVersion: synchronizedBundleVersion,
5282
5424
  origin,
5283
- page,
5284
- pages,
5425
+ page: page2,
5426
+ pages: pages2,
5285
5427
  projectDomain,
5286
5428
  projectTitle,
5287
5429
  user
@@ -5289,8 +5431,8 @@ const toLocalProjectBundle = (project) => {
5289
5431
  return {
5290
5432
  bundleVersion: synchronizedBundleVersion ?? bundleVersion,
5291
5433
  build: build2,
5292
- page,
5293
- pages,
5434
+ page: page2,
5435
+ pages: pages2,
5294
5436
  assets,
5295
5437
  user,
5296
5438
  projectDomain,
@@ -5419,13 +5561,13 @@ const sync = async (options, dependencies2 = defaultDependencies$1) => {
5419
5561
  syncing.stop("Project bundle synchronized successfully");
5420
5562
  };
5421
5563
  const LOCAL_AUTH_FILE = ".webstudio/auth.json";
5422
- const createAuthConfigResources = (pages) => {
5564
+ const createAuthConfigResources = (pages2) => {
5423
5565
  var _a;
5424
5566
  return createWsAuthResources({
5425
- projectContent: (_a = pages.meta) == null ? void 0 : _a.auth,
5426
- pages: getAllPages(pages).filter((page) => page.meta.auth !== void 0).map((page) => ({
5427
- route: getPagePath(page.id, pages),
5428
- auth: page.meta.auth
5567
+ projectContent: (_a = pages2.meta) == null ? void 0 : _a.auth,
5568
+ pages: getAllPages(pages2).filter((page2) => page2.meta.auth !== void 0).map((page2) => ({
5569
+ route: getPagePath(page2.id, pages2),
5570
+ auth: page2.meta.auth
5429
5571
  }))
5430
5572
  });
5431
5573
  };
@@ -5469,7 +5611,7 @@ const isInteractiveTerminal = () => stdin.isTTY === true && stdout.isTTY === tru
5469
5611
  const defaultDependencies = {
5470
5612
  checkProjectBuildPermission,
5471
5613
  importProjectBundle,
5472
- loadAssetFiles,
5614
+ uploadAssetFiles,
5473
5615
  loadJSONFile,
5474
5616
  text,
5475
5617
  isInteractive: isInteractiveTerminal(),
@@ -5481,12 +5623,16 @@ const missingProjectBundleMessage = "Project bundle is missing. Please run webst
5481
5623
  const invalidProjectBundleMessage = "Project bundle is invalid. Please run webstudio sync before importing.";
5482
5624
  const invalidAuthConfigMessage = "Project bundle auth config is invalid. Please run webstudio prebuild before importing.";
5483
5625
  const invalidDestinationMessage = "Destination share link is invalid.";
5626
+ const maxMissingAssetImportRetries = 5;
5484
5627
  const importOptions = (yargs) => yargs.option("to", {
5485
5628
  type: "string",
5486
5629
  describe: "Share link with build permissions to import synced data into"
5487
5630
  }).option("ignore-version-check", {
5488
5631
  type: "boolean",
5489
5632
  describe: "Import data without a compatible data version; import may fail if source and target API data formats differ"
5633
+ }).option("skip-assets", {
5634
+ type: "boolean",
5635
+ describe: "Import project data without uploading or importing asset files; referenced assets may be missing in the target project"
5490
5636
  }).check((options) => {
5491
5637
  if (options.to === void 0 && isInteractiveTerminal() === false) {
5492
5638
  return missingDestinationMessage;
@@ -5525,7 +5671,7 @@ const importProject = async (options, dependencies2 = defaultDependencies) => {
5525
5671
  );
5526
5672
  throw new HandledCliError();
5527
5673
  }
5528
- const parsedData = publishedProjectBundleSchema.safeParse(data);
5674
+ const parsedData = publishedProjectBundle.safeParse(data);
5529
5675
  if (parsedData.success === false) {
5530
5676
  importing.stop(
5531
5677
  `${invalidProjectBundleMessage} Invalid fields: ${formatZodIssues(
@@ -5597,30 +5743,25 @@ const importProject = async (options, dependencies2 = defaultDependencies) => {
5597
5743
  );
5598
5744
  throw new HandledCliError();
5599
5745
  }
5600
- importing.message(`Reading ${importData.assets.length} local asset files`);
5601
- let assetFiles;
5602
- try {
5603
- assetFiles = await dependencies2.loadAssetFiles({
5604
- assets: importData.assets
5605
- });
5606
- } catch (error) {
5607
- importing.stop(
5608
- error instanceof Error ? `Unable to read project bundle asset files: ${error.message}` : "Unable to read project bundle asset files",
5609
- 2
5610
- );
5611
- throw new HandledCliError();
5746
+ if (options.skipAssets === true) {
5747
+ dependencies2.log.info("Skipped asset upload and asset rows");
5748
+ } else {
5749
+ importing.message(`Uploading ${importData.assets.length} assets`);
5750
+ try {
5751
+ await dependencies2.uploadAssetFiles({
5752
+ assets: importData.assets,
5753
+ ...destinationRequest
5754
+ });
5755
+ } catch (error) {
5756
+ importing.stop(
5757
+ error instanceof Error ? `Unable to upload assets: ${error.message}` : "Unable to upload assets",
5758
+ 2
5759
+ );
5760
+ throw new HandledCliError();
5761
+ }
5612
5762
  }
5613
- importing.message(
5614
- `Waiting for API response while importing into ${destination.projectId}`
5615
- );
5616
- try {
5617
- await dependencies2.importProjectBundle({
5618
- ...destinationRequest,
5619
- data: importData,
5620
- assetFiles,
5621
- ignoreVersionCheck: options.ignoreVersionCheck
5622
- });
5623
- } catch (error) {
5763
+ const dataToImport = options.skipAssets === true ? { ...importData, assets: [] } : importData;
5764
+ const stopImportWithError = (error) => {
5624
5765
  stopSpinnerWithError(
5625
5766
  importing,
5626
5767
  error,
@@ -5628,8 +5769,46 @@ const importProject = async (options, dependencies2 = defaultDependencies) => {
5628
5769
  "import"
5629
5770
  );
5630
5771
  throw new HandledCliError();
5772
+ };
5773
+ for (let attempt = 0; attempt <= maxMissingAssetImportRetries; attempt += 1) {
5774
+ importing.message(
5775
+ `Waiting for API response while importing into ${destination.projectId}`
5776
+ );
5777
+ try {
5778
+ await dependencies2.importProjectBundle({
5779
+ ...destinationRequest,
5780
+ data: dataToImport,
5781
+ ignoreVersionCheck: options.ignoreVersionCheck
5782
+ });
5783
+ importing.stop("Project imported successfully");
5784
+ return;
5785
+ } catch (error) {
5786
+ const missingAssetNames = options.skipAssets === true ? void 0 : parseMissingImportedAssetFilesMessage(error);
5787
+ const assetNames = missingAssetNames ?? [];
5788
+ if (assetNames.length === 0 || attempt === maxMissingAssetImportRetries) {
5789
+ stopImportWithError(error);
5790
+ }
5791
+ const missingAssets = importData.assets.filter(
5792
+ (asset2) => assetNames.includes(asset2.name)
5793
+ );
5794
+ if (missingAssets.length !== assetNames.length) {
5795
+ stopImportWithError(error);
5796
+ }
5797
+ importing.message(`Re-uploading ${missingAssets.length} missing assets`);
5798
+ try {
5799
+ await dependencies2.uploadAssetFiles({
5800
+ assets: missingAssets,
5801
+ ...destinationRequest
5802
+ });
5803
+ } catch (uploadError) {
5804
+ importing.stop(
5805
+ uploadError instanceof Error ? `Unable to upload missing assets: ${uploadError.message}` : "Unable to upload missing assets",
5806
+ 2
5807
+ );
5808
+ throw new HandledCliError();
5809
+ }
5810
+ }
5631
5811
  }
5632
- importing.stop("Project bundle imported successfully");
5633
5812
  };
5634
5813
  const getRemixSegment = (segment) => {
5635
5814
  var _a, _b;
@@ -5692,68 +5871,68 @@ const normalizeProps = ({
5692
5871
  assetBaseUrl,
5693
5872
  assets,
5694
5873
  uploadingImageAssets,
5695
- pages,
5874
+ pages: pages2,
5696
5875
  source
5697
5876
  }) => {
5698
5877
  const newProps = [];
5699
- for (const prop of props) {
5700
- if (prop.type === "asset") {
5701
- const assetId = prop.value;
5702
- const asset = assets.get(assetId) ?? uploadingImageAssets.find((asset2) => asset2.id === assetId);
5703
- if (asset === void 0) {
5878
+ for (const prop2 of props) {
5879
+ if (prop2.type === "asset") {
5880
+ const assetId2 = prop2.value;
5881
+ const asset2 = assets.get(assetId2) ?? uploadingImageAssets.find((asset22) => asset22.id === assetId2);
5882
+ if (asset2 === void 0) {
5704
5883
  continue;
5705
5884
  }
5706
5885
  const propBase = {
5707
- id: prop.id,
5708
- name: prop.name,
5709
- required: prop.required,
5710
- instanceId: prop.instanceId
5886
+ id: prop2.id,
5887
+ name: prop2.name,
5888
+ required: prop2.required,
5889
+ instanceId: prop2.instanceId
5711
5890
  };
5712
- if (prop.name === "width" && asset.type === "image") {
5891
+ if (prop2.name === "width" && asset2.type === "image") {
5713
5892
  newProps.push({
5714
5893
  ...propBase,
5715
5894
  type: "number",
5716
- value: asset.meta.width
5895
+ value: asset2.meta.width
5717
5896
  });
5718
5897
  continue;
5719
5898
  }
5720
- if (prop.name === "height" && asset.type === "image") {
5899
+ if (prop2.name === "height" && asset2.type === "image") {
5721
5900
  newProps.push({
5722
5901
  ...propBase,
5723
5902
  type: "number",
5724
- value: asset.meta.height
5903
+ value: asset2.meta.height
5725
5904
  });
5726
5905
  continue;
5727
5906
  }
5728
- if (prop.name === "alt" && asset.type === "image") {
5907
+ if (prop2.name === "alt" && asset2.type === "image") {
5729
5908
  newProps.push({
5730
5909
  ...propBase,
5731
5910
  type: "string",
5732
- value: asset.description ?? ""
5911
+ value: asset2.description ?? ""
5733
5912
  });
5734
5913
  continue;
5735
5914
  }
5736
5915
  newProps.push({
5737
5916
  ...propBase,
5738
5917
  type: "string",
5739
- value: `${assetBaseUrl}${asset.name}`
5918
+ value: `${assetBaseUrl}${asset2.name}`
5740
5919
  });
5741
5920
  continue;
5742
5921
  }
5743
- if (prop.type === "page") {
5922
+ if (prop2.type === "page") {
5744
5923
  let idProp;
5745
- const pageId = typeof prop.value === "string" ? prop.value : prop.value.pageId;
5746
- const page = findPageByIdOrPath(pageId, pages);
5747
- if (page === void 0) {
5924
+ const pageId2 = typeof prop2.value === "string" ? prop2.value : prop2.value.pageId;
5925
+ const page2 = findPageByIdOrPath(pageId2, pages2);
5926
+ if (page2 === void 0) {
5748
5927
  continue;
5749
5928
  }
5750
- if (typeof prop.value !== "string") {
5751
- const { instanceId } = prop.value;
5929
+ if (typeof prop2.value !== "string") {
5930
+ const { instanceId: instanceId2 } = prop2.value;
5752
5931
  idProp = props.find(
5753
- (prop2) => prop2.instanceId === instanceId && prop2.name === "id"
5932
+ (prop22) => prop22.instanceId === instanceId2 && prop22.name === "id"
5754
5933
  );
5755
5934
  }
5756
- const path = getPagePath(page.id, pages);
5935
+ const path = getPagePath(page2.id, pages2);
5757
5936
  const url = new URL(path, "https://any-valid.url");
5758
5937
  let value = url.pathname;
5759
5938
  if ((idProp == null ? void 0 : idProp.type) === "string") {
@@ -5762,16 +5941,16 @@ const normalizeProps = ({
5762
5941
  value = `${url.pathname}${url.hash}`;
5763
5942
  }
5764
5943
  newProps.push({
5765
- id: prop.id,
5766
- name: prop.name,
5767
- required: prop.required,
5768
- instanceId: prop.instanceId,
5944
+ id: prop2.id,
5945
+ name: prop2.name,
5946
+ required: prop2.required,
5947
+ instanceId: prop2.instanceId,
5769
5948
  type: "string",
5770
5949
  value
5771
5950
  });
5772
5951
  continue;
5773
5952
  }
5774
- newProps.push(prop);
5953
+ newProps.push(prop2);
5775
5954
  }
5776
5955
  return newProps;
5777
5956
  };
@@ -5920,14 +6099,14 @@ const standardAttributesToReactProps = {
5920
6099
  };
5921
6100
  const generateAction = ({
5922
6101
  scope,
5923
- prop,
6102
+ prop: prop2,
5924
6103
  dataSources,
5925
6104
  usedDataSources
5926
6105
  }) => {
5927
6106
  const setters = /* @__PURE__ */ new Set();
5928
6107
  let args = [];
5929
6108
  let assignersCode = "";
5930
- for (const value of prop.value) {
6109
+ for (const value of prop2.value) {
5931
6110
  args = value.args;
5932
6111
  assignersCode += transpileExpression({
5933
6112
  expression: value.code,
@@ -5953,11 +6132,11 @@ const generateAction = ({
5953
6132
  `;
5954
6133
  }
5955
6134
  let settersCode = "";
5956
- for (const dataSource of setters) {
5957
- const valueName = scope.getName(dataSource.id, dataSource.name);
6135
+ for (const dataSource2 of setters) {
6136
+ const valueName = scope.getName(dataSource2.id, dataSource2.name);
5958
6137
  const setterName = scope.getName(
5959
- `set$${dataSource.id}`,
5960
- `set$${dataSource.name}`
6138
+ `set$${dataSource2.id}`,
6139
+ `set$${dataSource2.name}`
5961
6140
  );
5962
6141
  settersCode += `${setterName}(${valueName})
5963
6142
  `;
@@ -5973,37 +6152,37 @@ const generateAction = ({
5973
6152
  };
5974
6153
  const generatePropValue = ({
5975
6154
  scope,
5976
- prop,
6155
+ prop: prop2,
5977
6156
  dataSources,
5978
6157
  usedDataSources
5979
6158
  }) => {
5980
- if (prop.type === "asset" || prop.type === "page") {
6159
+ if (prop2.type === "asset" || prop2.type === "page") {
5981
6160
  return;
5982
6161
  }
5983
- if (prop.type === "string" || prop.type === "number" || prop.type === "boolean" || prop.type === "string[]" || prop.type === "json" || prop.type === "animationAction") {
5984
- return JSON.stringify(prop.value);
6162
+ if (prop2.type === "string" || prop2.type === "number" || prop2.type === "boolean" || prop2.type === "string[]" || prop2.type === "json" || prop2.type === "animationAction") {
6163
+ return JSON.stringify(prop2.value);
5985
6164
  }
5986
- if (prop.type === "parameter") {
5987
- const dataSource = dataSources.get(prop.value);
5988
- if (dataSource === void 0) {
6165
+ if (prop2.type === "parameter") {
6166
+ const dataSource2 = dataSources.get(prop2.value);
6167
+ if (dataSource2 === void 0) {
5989
6168
  return;
5990
6169
  }
5991
- usedDataSources.set(dataSource.id, dataSource);
5992
- return scope.getName(dataSource.id, dataSource.name);
6170
+ usedDataSources.set(dataSource2.id, dataSource2);
6171
+ return scope.getName(dataSource2.id, dataSource2.name);
5993
6172
  }
5994
- if (prop.type === "expression") {
6173
+ if (prop2.type === "expression") {
5995
6174
  return generateExpression({
5996
- expression: prop.value,
6175
+ expression: prop2.value,
5997
6176
  dataSources,
5998
6177
  usedDataSources,
5999
6178
  scope
6000
6179
  });
6001
6180
  }
6002
- if (prop.type === "action") {
6003
- return generateAction({ scope, prop, dataSources, usedDataSources });
6181
+ if (prop2.type === "action") {
6182
+ return generateAction({ scope, prop: prop2, dataSources, usedDataSources });
6004
6183
  }
6005
- if (prop.type === "resource") {
6006
- return JSON.stringify(scope.getName(prop.value, prop.name));
6184
+ if (prop2.type === "resource") {
6185
+ return JSON.stringify(scope.getName(prop2.value, prop2.name));
6007
6186
  }
6008
6187
  };
6009
6188
  const generateJsxElement = ({
@@ -6011,7 +6190,7 @@ const generateJsxElement = ({
6011
6190
  scope,
6012
6191
  metas,
6013
6192
  tagsOverrides,
6014
- instance,
6193
+ instance: instance2,
6015
6194
  props,
6016
6195
  dataSources,
6017
6196
  usedDataSources,
@@ -6020,44 +6199,44 @@ const generateJsxElement = ({
6020
6199
  classesMap
6021
6200
  }) => {
6022
6201
  var _a;
6023
- if (instance.component === descendantComponent) {
6202
+ if (instance2.component === descendantComponent) {
6024
6203
  return "";
6025
6204
  }
6026
- const meta = metas.get(instance.component);
6205
+ const meta = metas.get(instance2.component);
6027
6206
  const hasTags = Object.keys((meta == null ? void 0 : meta.presetStyle) ?? {}).length > 0;
6028
6207
  let generatedProps = "";
6029
- const index = indexesWithinAncestors.get(instance.id);
6208
+ const index = indexesWithinAncestors.get(instance2.id);
6030
6209
  if (index !== void 0) {
6031
6210
  generatedProps += `
6032
6211
  ${indexProperty}="${index}"`;
6033
6212
  }
6034
- if (instance.tag !== void 0 && instance.component !== elementComponent) {
6213
+ if (instance2.tag !== void 0 && instance2.component !== elementComponent) {
6035
6214
  generatedProps += `
6036
- ${tagProperty}=${JSON.stringify(instance.tag)}`;
6215
+ ${tagProperty}=${JSON.stringify(instance2.tag)}`;
6037
6216
  }
6038
6217
  let conditionValue;
6039
6218
  let collectionDataValue;
6040
6219
  let collectionItemValue;
6041
6220
  let collectionItemKeyValue;
6042
6221
  let classNameValue;
6043
- for (const prop of props.values()) {
6044
- if (prop.instanceId !== instance.id) {
6222
+ for (const prop2 of props.values()) {
6223
+ if (prop2.instanceId !== instance2.id) {
6045
6224
  continue;
6046
6225
  }
6047
6226
  const propValue = generatePropValue({
6048
6227
  scope,
6049
- prop,
6228
+ prop: prop2,
6050
6229
  dataSources,
6051
6230
  usedDataSources
6052
6231
  });
6053
- if (isAttributeNameSafe(prop.name) === false) {
6232
+ if (isAttributeNameSafe(prop2.name) === false) {
6054
6233
  continue;
6055
6234
  }
6056
- let name2 = prop.name;
6057
- if (hasTags && !((_a = meta == null ? void 0 : meta.props) == null ? void 0 : _a[prop.name])) {
6058
- name2 = standardAttributesToReactProps[prop.name] ?? prop.name;
6235
+ let name2 = prop2.name;
6236
+ if (hasTags && !((_a = meta == null ? void 0 : meta.props) == null ? void 0 : _a[prop2.name])) {
6237
+ name2 = standardAttributesToReactProps[prop2.name] ?? prop2.name;
6059
6238
  }
6060
- if (prop.name === showAttribute) {
6239
+ if (prop2.name === showAttribute) {
6061
6240
  if (propValue === "true") {
6062
6241
  continue;
6063
6242
  }
@@ -6067,14 +6246,14 @@ ${tagProperty}=${JSON.stringify(instance.tag)}`;
6067
6246
  conditionValue = propValue;
6068
6247
  continue;
6069
6248
  }
6070
- if (instance.component === collectionComponent) {
6071
- if (prop.name === "data") {
6249
+ if (instance2.component === collectionComponent) {
6250
+ if (prop2.name === "data") {
6072
6251
  collectionDataValue = propValue;
6073
6252
  }
6074
- if (prop.name === "item") {
6253
+ if (prop2.name === "item") {
6075
6254
  collectionItemValue = propValue;
6076
6255
  }
6077
- if (prop.name === "itemKey") {
6256
+ if (prop2.name === "itemKey") {
6078
6257
  collectionItemKeyValue = propValue;
6079
6258
  }
6080
6259
  continue;
@@ -6088,7 +6267,7 @@ ${tagProperty}=${JSON.stringify(instance.tag)}`;
6088
6267
  ${name2}={${propValue}}`;
6089
6268
  }
6090
6269
  }
6091
- const classMapArray = classesMap == null ? void 0 : classesMap.get(instance.id);
6270
+ const classMapArray = classesMap == null ? void 0 : classesMap.get(instance2.id);
6092
6271
  if (classMapArray || classNameValue) {
6093
6272
  let classNameTemplate = classMapArray ? classMapArray.join(" ") : "";
6094
6273
  if (classNameValue) {
@@ -6100,14 +6279,14 @@ ${name2}={${propValue}}`;
6100
6279
  generatedProps += "\nclassName={`" + classNameTemplate + "`}";
6101
6280
  }
6102
6281
  let generatedElement = "";
6103
- if (instance.component === blockTemplateComponent) {
6282
+ if (instance2.component === blockTemplateComponent) {
6104
6283
  return "";
6105
6284
  }
6106
- if (instance.component === collectionComponent) {
6285
+ if (instance2.component === collectionComponent) {
6107
6286
  if (collectionDataValue === void 0 || collectionItemValue === void 0) {
6108
6287
  return "";
6109
6288
  }
6110
- const indexVariable = scope.getName(`${instance.id}-index`, "index");
6289
+ const indexVariable = scope.getName(`${instance2.id}-index`, "index");
6111
6290
  const keyVariable = collectionItemKeyValue ?? indexVariable;
6112
6291
  generatedElement += `{${generateCollectionIterationCode({
6113
6292
  dataExpression: collectionDataValue,
@@ -6126,22 +6305,22 @@ ${name2}={${propValue}}`;
6126
6305
  `;
6127
6306
  generatedElement += `}
6128
6307
  `;
6129
- } else if (instance.component === blockComponent) {
6308
+ } else if (instance2.component === blockComponent) {
6130
6309
  generatedElement += children;
6131
6310
  } else {
6132
6311
  let componentVariable;
6133
- if (instance.component === elementComponent) {
6134
- componentVariable = instance.tag ?? "div";
6312
+ if (instance2.component === elementComponent) {
6313
+ componentVariable = instance2.tag ?? "div";
6135
6314
  const componentDescriptor = tagsOverrides == null ? void 0 : tagsOverrides[componentVariable];
6136
6315
  if (componentDescriptor !== void 0) {
6137
6316
  const [_importSource, importSpecifier] = componentDescriptor.split(":");
6138
6317
  componentVariable = scope.getName(componentDescriptor, importSpecifier);
6139
6318
  }
6140
6319
  } else {
6141
- const [_namespace, shortName] = parseComponentName(instance.component);
6142
- componentVariable = scope.getName(instance.component, shortName);
6320
+ const [_namespace, shortName] = parseComponentName(instance2.component);
6321
+ componentVariable = scope.getName(instance2.component, shortName);
6143
6322
  }
6144
- if (instance.children.length === 0) {
6323
+ if (instance2.children.length === 0) {
6145
6324
  generatedElement += `<${componentVariable}${generatedProps} />
6146
6325
  `;
6147
6326
  } else {
@@ -6162,7 +6341,7 @@ ${name2}={${propValue}}`;
6162
6341
  }
6163
6342
  conditionalElement += `${before}(${conditionValue}) &&
6164
6343
  `;
6165
- if (instance.component === collectionComponent) {
6344
+ if (instance2.component === collectionComponent) {
6166
6345
  conditionalElement += "<>\n";
6167
6346
  conditionalElement += generatedElement;
6168
6347
  conditionalElement += "</>\n";
@@ -6211,9 +6390,9 @@ const generateJsxChildren = ({
6211
6390
  continue;
6212
6391
  }
6213
6392
  if (child.type === "id") {
6214
- const instanceId = child.value;
6215
- const instance = instances.get(instanceId);
6216
- if (instance === void 0) {
6393
+ const instanceId2 = child.value;
6394
+ const instance2 = instances.get(instanceId2);
6395
+ if (instance2 === void 0) {
6217
6396
  continue;
6218
6397
  }
6219
6398
  generatedChildren += generateJsxElement({
@@ -6221,7 +6400,7 @@ const generateJsxChildren = ({
6221
6400
  scope,
6222
6401
  metas,
6223
6402
  tagsOverrides,
6224
- instance,
6403
+ instance: instance2,
6225
6404
  props,
6226
6405
  dataSources,
6227
6406
  usedDataSources,
@@ -6232,7 +6411,7 @@ const generateJsxChildren = ({
6232
6411
  scope,
6233
6412
  metas,
6234
6413
  tagsOverrides,
6235
- children: instance.children,
6414
+ children: instance2.children,
6236
6415
  instances,
6237
6416
  props,
6238
6417
  dataSources,
@@ -6258,19 +6437,19 @@ const generateWebstudioComponent = ({
6258
6437
  tagsOverrides,
6259
6438
  classesMap
6260
6439
  }) => {
6261
- const instance = instances.get(rootInstanceId);
6440
+ const instance2 = instances.get(rootInstanceId);
6262
6441
  const indexesWithinAncestors = getIndexesWithinAncestors(metas, instances, [
6263
6442
  rootInstanceId
6264
6443
  ]);
6265
6444
  const usedDataSources = /* @__PURE__ */ new Map();
6266
6445
  let generatedJsx = "<></>\n";
6267
- if (instance) {
6446
+ if (instance2) {
6268
6447
  generatedJsx = generateJsxElement({
6269
6448
  context: "expression",
6270
6449
  scope,
6271
6450
  metas,
6272
6451
  tagsOverrides,
6273
- instance,
6452
+ instance: instance2,
6274
6453
  props,
6275
6454
  dataSources,
6276
6455
  usedDataSources,
@@ -6280,7 +6459,7 @@ const generateWebstudioComponent = ({
6280
6459
  scope,
6281
6460
  metas,
6282
6461
  tagsOverrides,
6283
- children: instance.children,
6462
+ children: instance2.children,
6284
6463
  instances,
6285
6464
  props,
6286
6465
  dataSources,
@@ -6302,32 +6481,32 @@ const generateWebstudioComponent = ({
6302
6481
  }
6303
6482
  generatedProps = `_props: { ${generatedPropsType}}`;
6304
6483
  for (const parameter of parameters) {
6305
- const dataSource = usedDataSources.get(parameter.value);
6306
- if (dataSource) {
6307
- const valueName = scope.getName(dataSource.id, dataSource.name);
6484
+ const dataSource2 = usedDataSources.get(parameter.value);
6485
+ if (dataSource2) {
6486
+ const valueName = scope.getName(dataSource2.id, dataSource2.name);
6308
6487
  generatedParameters += `const ${valueName} = _props.${parameter.name};
6309
6488
  `;
6310
6489
  }
6311
6490
  }
6312
6491
  }
6313
6492
  let generatedDataSources = "";
6314
- for (const dataSource of usedDataSources.values()) {
6315
- if (dataSource.type === "variable") {
6316
- const valueName = scope.getName(dataSource.id, dataSource.name);
6493
+ for (const dataSource2 of usedDataSources.values()) {
6494
+ if (dataSource2.type === "variable") {
6495
+ const valueName = scope.getName(dataSource2.id, dataSource2.name);
6317
6496
  const setterName = scope.getName(
6318
- `set$${dataSource.id}`,
6319
- `set$${dataSource.name}`
6497
+ `set$${dataSource2.id}`,
6498
+ `set$${dataSource2.name}`
6320
6499
  );
6321
- const initialValue = dataSource.value.value;
6500
+ const initialValue = dataSource2.value.value;
6322
6501
  const initialValueString = JSON.stringify(initialValue);
6323
6502
  generatedDataSources += `let [${valueName}, ${setterName}] = useVariableState<any>(${initialValueString})
6324
6503
  `;
6325
6504
  }
6326
- if (dataSource.type === "resource") {
6327
- const valueName = scope.getName(dataSource.id, dataSource.name);
6505
+ if (dataSource2.type === "resource") {
6506
+ const valueName = scope.getName(dataSource2.id, dataSource2.name);
6328
6507
  const resourceName = scope.getName(
6329
- dataSource.resourceId,
6330
- dataSource.name
6508
+ dataSource2.resourceId,
6509
+ dataSource2.name
6331
6510
  );
6332
6511
  const resourceNameString = JSON.stringify(resourceName);
6333
6512
  generatedDataSources += `let ${valueName} = useResource(${resourceNameString})
@@ -6455,9 +6634,9 @@ const htmlToJsx = (html2) => {
6455
6634
  }
6456
6635
  return result;
6457
6636
  };
6458
- const createRemixFramework = async () => (await import("./framework-remix-DxrMLfhi.js")).createFramework();
6459
- const createReactRouterFramework = async () => (await import("./framework-react-router-DM99uwVO.js")).createFramework();
6460
- const createVikeSsgFramework = async () => (await import("./framework-vike-ssg-rsZDP045.js")).createFramework();
6637
+ const createRemixFramework = async () => (await import("./framework-remix-DWec4bEd.js")).createFramework();
6638
+ const createReactRouterFramework = async () => (await import("./framework-react-router-UzYgymrh.js")).createFramework();
6639
+ const createVikeSsgFramework = async () => (await import("./framework-vike-ssg-yIhvBUQn.js")).createFramework();
6461
6640
  const mergeJsonInto = async (sourcePath, destinationPath) => {
6462
6641
  const sourceJson = await readFile(sourcePath, "utf8");
6463
6642
  const destinationJson = await readFile(destinationPath, "utf8").catch(
@@ -6477,8 +6656,8 @@ const mergeJsonInto = async (sourcePath, destinationPath) => {
6477
6656
  );
6478
6657
  await writeFile(destinationPath, content, "utf8");
6479
6658
  };
6480
- const writeWsAuthResources = async (generatedDir, pages) => {
6481
- const { content, module } = createAuthConfigResources(pages);
6659
+ const writeWsAuthResources = async (generatedDir, pages2) => {
6660
+ const { content, module } = createAuthConfigResources(pages2);
6482
6661
  await createFolderIfNotExists(dirname(LOCAL_AUTH_FILE));
6483
6662
  await writeFile(LOCAL_AUTH_FILE, content);
6484
6663
  await createFileIfNotExists(
@@ -6591,7 +6770,7 @@ Please check webstudio --help for more details`
6591
6770
  `Project bundle is missing, please make sure the project is synced.`
6592
6771
  );
6593
6772
  }
6594
- const parsedSiteData = publishedProjectBundleSchema.safeParse(loadedSiteData);
6773
+ const parsedSiteData = publishedProjectBundle.safeParse(loadedSiteData);
6595
6774
  if (parsedSiteData.success === false) {
6596
6775
  throw new Error(
6597
6776
  `Project bundle is invalid, please make sure the project is synced. Invalid fields: ${formatZodIssues(parsedSiteData.error.issues)}`
@@ -6601,63 +6780,63 @@ Please check webstudio --help for more details`
6601
6780
  const usedMetas = new Map(
6602
6781
  Object.entries(coreMetas)
6603
6782
  );
6604
- const pages = migratePages(siteData.build.pages);
6605
- const allPages = getAllPages(pages);
6606
- await writeWsAuthResources(generatedDir, pages);
6783
+ const pages2 = migratePages(siteData.build.pages);
6784
+ const allPages = getAllPages(pages2);
6785
+ await writeWsAuthResources(generatedDir, pages2);
6607
6786
  const siteDataByPage = {};
6608
6787
  const fontAssetsByPage = {};
6609
6788
  const backgroundImageAssetsByPage = {};
6610
6789
  const normalizedProps = normalizeProps({
6611
- props: siteData.build.props.map(([_id, prop]) => prop),
6790
+ props: siteData.build.props.map(([_id, prop2]) => prop2),
6612
6791
  assetBaseUrl,
6613
- assets: new Map(siteData.assets.map((asset) => [asset.id, asset])),
6792
+ assets: new Map(siteData.assets.map((asset2) => [asset2.id, asset2])),
6614
6793
  uploadingImageAssets: [],
6615
- pages,
6794
+ pages: pages2,
6616
6795
  source: "prebuild"
6617
6796
  });
6618
- for (const page of allPages) {
6797
+ for (const page2 of allPages) {
6619
6798
  const instanceMap = new Map(siteData.build.instances);
6620
6799
  const pageInstanceSet = findTreeInstanceIds(
6621
6800
  instanceMap,
6622
- page.rootInstanceId
6801
+ page2.rootInstanceId
6623
6802
  );
6624
6803
  pageInstanceSet.add(ROOT_INSTANCE_ID);
6625
6804
  const instances = [];
6626
- for (const [_instanceId, instance] of siteData.build.instances) {
6627
- if (pageInstanceSet.has(instance.id)) {
6628
- instances.push([instance.id, instance]);
6629
- const meta = framework.metas[instance.component];
6805
+ for (const [_instanceId, instance2] of siteData.build.instances) {
6806
+ if (pageInstanceSet.has(instance2.id)) {
6807
+ instances.push([instance2.id, instance2]);
6808
+ const meta = framework.metas[instance2.component];
6630
6809
  if (meta) {
6631
- usedMetas.set(instance.component, meta);
6810
+ usedMetas.set(instance2.component, meta);
6632
6811
  }
6633
6812
  }
6634
6813
  }
6635
6814
  const resourceIds = /* @__PURE__ */ new Set();
6636
6815
  const props = [];
6637
- for (const prop of normalizedProps) {
6638
- if (pageInstanceSet.has(prop.instanceId)) {
6639
- props.push([prop.id, prop]);
6640
- if (prop.type === "resource") {
6641
- resourceIds.add(prop.value);
6816
+ for (const prop2 of normalizedProps) {
6817
+ if (pageInstanceSet.has(prop2.instanceId)) {
6818
+ props.push([prop2.id, prop2]);
6819
+ if (prop2.type === "resource") {
6820
+ resourceIds.add(prop2.value);
6642
6821
  }
6643
6822
  }
6644
6823
  }
6645
6824
  const dataSources = [];
6646
- for (const [dataSourceId, dataSource] of siteData.build.dataSources) {
6647
- if (pageInstanceSet.has(dataSource.scopeInstanceId ?? "")) {
6648
- dataSources.push([dataSourceId, dataSource]);
6649
- if (dataSource.type === "resource") {
6650
- resourceIds.add(dataSource.resourceId);
6825
+ for (const [dataSourceId2, dataSource2] of siteData.build.dataSources) {
6826
+ if (pageInstanceSet.has(dataSource2.scopeInstanceId ?? "")) {
6827
+ dataSources.push([dataSourceId2, dataSource2]);
6828
+ if (dataSource2.type === "resource") {
6829
+ resourceIds.add(dataSource2.resourceId);
6651
6830
  }
6652
6831
  }
6653
6832
  }
6654
6833
  const resources = [];
6655
- for (const [resourceId, resource] of siteData.build.resources ?? []) {
6656
- if (resourceIds.has(resourceId)) {
6657
- resources.push([resourceId, resource]);
6834
+ for (const [resourceId2, resource2] of siteData.build.resources ?? []) {
6835
+ if (resourceIds.has(resourceId2)) {
6836
+ resources.push([resourceId2, resource2]);
6658
6837
  }
6659
6838
  }
6660
- siteDataByPage[page.id] = {
6839
+ siteDataByPage[page2.id] = {
6661
6840
  build: {
6662
6841
  props,
6663
6842
  instances,
@@ -6665,23 +6844,23 @@ Please check webstudio --help for more details`
6665
6844
  resources
6666
6845
  },
6667
6846
  pages: allPages,
6668
- page,
6847
+ page: page2,
6669
6848
  assets: siteData.assets
6670
6849
  };
6671
6850
  const styleSourceSelections = ((_a = siteData.build) == null ? void 0 : _a.styleSourceSelections) ?? [];
6672
6851
  const pageStyleSourceIds = new Set(
6673
- styleSourceSelections.filter(([, { instanceId }]) => pageInstanceSet.has(instanceId)).map(([, { values }]) => values).flat()
6852
+ styleSourceSelections.filter(([, { instanceId: instanceId2 }]) => pageInstanceSet.has(instanceId2)).map(([, { values }]) => values).flat()
6674
6853
  );
6675
6854
  const pageStyles = (_c = (_b = siteData.build) == null ? void 0 : _b.styles) == null ? void 0 : _c.filter(
6676
- ([, { styleSourceId }]) => pageStyleSourceIds.has(styleSourceId)
6855
+ ([, { styleSourceId: styleSourceId2 }]) => pageStyleSourceIds.has(styleSourceId2)
6677
6856
  );
6678
6857
  const pageFontFamilySet = new Set(
6679
6858
  pageStyles.filter(([, { property }]) => property === "fontFamily").map(
6680
6859
  ([, { value }]) => value.type === "fontFamily" ? value.value : void 0
6681
6860
  ).flat().filter((value) => value !== void 0)
6682
6861
  );
6683
- const pageFontAssets = siteData.assets.filter((asset) => asset.type === "font").filter((fontAsset) => pageFontFamilySet.has(fontAsset.meta.family)).map((asset) => asset.name);
6684
- fontAssetsByPage[page.id] = pageFontAssets;
6862
+ const pageFontAssets = siteData.assets.filter((asset2) => asset2.type === "font").filter((fontAsset2) => pageFontFamilySet.has(fontAsset2.meta.family)).map((asset2) => asset2.name);
6863
+ fontAssetsByPage[page2.id] = pageFontAssets;
6685
6864
  const backgroundImageAssetIdSet = new Set(
6686
6865
  pageStyles.filter(([, { property }]) => property === "backgroundImage").map(
6687
6866
  ([, { value }]) => value.type === "layers" ? value.value.map(
@@ -6689,8 +6868,8 @@ Please check webstudio --help for more details`
6689
6868
  ) : void 0
6690
6869
  ).flat().filter((value) => value !== void 0)
6691
6870
  );
6692
- const backgroundImageAssets = siteData.assets.filter((asset) => asset.type === "image").filter((imageAsset) => backgroundImageAssetIdSet.has(imageAsset.id)).map((asset) => asset.name);
6693
- backgroundImageAssetsByPage[page.id] = backgroundImageAssets;
6871
+ const backgroundImageAssets = siteData.assets.filter((asset2) => asset2.type === "image").filter((imageAsset2) => backgroundImageAssetIdSet.has(imageAsset2.id)).map((asset2) => asset2.name);
6872
+ backgroundImageAssetsByPage[page2.id] = backgroundImageAssets;
6694
6873
  }
6695
6874
  if (options.assets === true) {
6696
6875
  const assetOrigin = siteData.origin;
@@ -6698,7 +6877,7 @@ Please check webstudio --help for more details`
6698
6877
  console.warn("Warning: Asset origin is not defined in project bundle.");
6699
6878
  }
6700
6879
  }
6701
- const assets = new Map(siteData.assets.map((asset) => [asset.id, asset]));
6880
+ const assets = new Map(siteData.assets.map((asset2) => [asset2.id, asset2]));
6702
6881
  const { cssText, classes } = generateCss({
6703
6882
  instances: new Map(siteData.build.instances),
6704
6883
  props: new Map(siteData.build.props),
@@ -6709,10 +6888,10 @@ Please check webstudio --help for more details`
6709
6888
  // pass only used metas to not generate unused preset styles
6710
6889
  componentMetas: usedMetas,
6711
6890
  assetBaseUrl,
6712
- atomic: ((_g = pages.compiler) == null ? void 0 : _g.atomicStyles) ?? true
6891
+ atomic: ((_g = pages2.compiler) == null ? void 0 : _g.atomicStyles) ?? true
6713
6892
  });
6714
6893
  await createFileIfNotExists(join(generatedDir, "index.css"), cssText);
6715
- for (const page of allPages) {
6894
+ for (const page2 of allPages) {
6716
6895
  const scope = createScope([
6717
6896
  // manually maintained list of occupied identifiers
6718
6897
  "useState",
@@ -6722,32 +6901,32 @@ Please check webstudio --help for more details`
6722
6901
  "Page",
6723
6902
  "_props"
6724
6903
  ]);
6725
- const pageData = siteDataByPage[page.id];
6904
+ const pageData = siteDataByPage[page2.id];
6726
6905
  const instances = new Map(pageData.build.instances);
6727
- const documentType = page.meta.documentType ?? "html";
6728
- let rootInstanceId = page.rootInstanceId;
6906
+ const documentType = page2.meta.documentType ?? "html";
6907
+ let rootInstanceId = page2.rootInstanceId;
6729
6908
  if (documentType === "xml") {
6730
6909
  const bodyInstance = instances.get(rootInstanceId);
6731
6910
  const firstChild = bodyInstance == null ? void 0 : bodyInstance.children.at(0);
6732
6911
  if ((firstChild == null ? void 0 : firstChild.type) === "id") {
6733
6912
  rootInstanceId = firstChild.value;
6734
6913
  }
6735
- for (const instance of instances.values()) {
6736
- if (isCoreComponent(instance.component)) {
6914
+ for (const instance2 of instances.values()) {
6915
+ if (isCoreComponent(instance2.component)) {
6737
6916
  continue;
6738
6917
  }
6739
- if (((_h = usedMetas.get(instance.component)) == null ? void 0 : _h.category) === "xml") {
6918
+ if (((_h = usedMetas.get(instance2.component)) == null ? void 0 : _h.category) === "xml") {
6740
6919
  continue;
6741
6920
  }
6742
- instances.delete(instance.id);
6921
+ instances.delete(instance2.id);
6743
6922
  }
6744
6923
  }
6745
6924
  const imports2 = /* @__PURE__ */ new Map();
6746
- for (const instance of instances.values()) {
6747
- let descriptor = framework.components[instance.component];
6748
- let id = instance.component;
6749
- if (instance.component === elementComponent && instance.tag) {
6750
- descriptor = framework.tags[instance.tag];
6925
+ for (const instance2 of instances.values()) {
6926
+ let descriptor = framework.components[instance2.component];
6927
+ let id = instance2.component;
6928
+ if (instance2.component === elementComponent && instance2.tag) {
6929
+ descriptor = framework.tags[instance2.tag];
6751
6930
  id = descriptor;
6752
6931
  }
6753
6932
  if (descriptor === void 0) {
@@ -6769,8 +6948,8 @@ Please check webstudio --help for more details`
6769
6948
  importsString += `import { ${specifiersString} } from "${importSource}";
6770
6949
  `;
6771
6950
  }
6772
- const pageFontAssets = fontAssetsByPage[page.id];
6773
- const pageBackgroundImageAssets = backgroundImageAssetsByPage[page.id];
6951
+ const pageFontAssets = fontAssetsByPage[page2.id];
6952
+ const pageBackgroundImageAssets = backgroundImageAssetsByPage[page2.id];
6774
6953
  const props = new Map(pageData.build.props);
6775
6954
  const dataSources = new Map(pageData.build.dataSources);
6776
6955
  const resources = new Map(pageData.build.resources);
@@ -6789,7 +6968,7 @@ Please check webstudio --help for more details`
6789
6968
  instanceId: "",
6790
6969
  name: "system",
6791
6970
  type: "parameter",
6792
- value: page.systemDataSourceId ?? ""
6971
+ value: page2.systemDataSourceId ?? ""
6793
6972
  },
6794
6973
  {
6795
6974
  id: "global-system",
@@ -6806,13 +6985,13 @@ Please check webstudio --help for more details`
6806
6985
  metas: usedMetas,
6807
6986
  tagsOverrides: framework.tags
6808
6987
  });
6809
- const projectMeta = pages.meta;
6988
+ const projectMeta2 = pages2.meta;
6810
6989
  const contactEmail = (
6811
6990
  // fallback to user email when contact email is empty string
6812
- (projectMeta == null ? void 0 : projectMeta.contactEmail) || ((_i = siteData.user) == null ? void 0 : _i.email) || void 0
6991
+ (projectMeta2 == null ? void 0 : projectMeta2.contactEmail) || ((_i = siteData.user) == null ? void 0 : _i.email) || void 0
6813
6992
  );
6814
- const favIconAsset = (_j = assets.get((projectMeta == null ? void 0 : projectMeta.faviconAssetId) ?? "")) == null ? void 0 : _j.name;
6815
- const pagePath = getPagePath(page.id, pages);
6993
+ const favIconAsset = (_j = assets.get((projectMeta2 == null ? void 0 : projectMeta2.faviconAssetId) ?? "")) == null ? void 0 : _j.name;
6994
+ const pagePath2 = getPagePath(page2.id, pages2);
6816
6995
  const breakpoints = siteData.build.breakpoints.map(([_, value]) => ({
6817
6996
  id: value.id,
6818
6997
  minWidth: value.minWidth,
@@ -6832,7 +7011,7 @@ Please check webstudio --help for more details`
6832
7011
 
6833
7012
  export const lastPublished = "${new Date(siteData.build.createdAt).toISOString()}";
6834
7013
 
6835
- export const siteName = ${JSON.stringify(projectMeta == null ? void 0 : projectMeta.siteName)};
7014
+ export const siteName = ${JSON.stringify(projectMeta2 == null ? void 0 : projectMeta2.siteName)};
6836
7015
 
6837
7016
  export const breakpoints = ${JSON.stringify(breakpoints)};
6838
7017
 
@@ -6846,8 +7025,8 @@ Please check webstudio --help for more details`
6846
7025
  export const pageBackgroundImageAssets: string[] =
6847
7026
  ${JSON.stringify(pageBackgroundImageAssets)}
6848
7027
 
6849
- ${pagePath === "/" ? `
6850
- ${(projectMeta == null ? void 0 : projectMeta.code) ? `
7028
+ ${pagePath2 === "/" ? `
7029
+ ${(projectMeta2 == null ? void 0 : projectMeta2.code) ? `
6851
7030
  const Script = ({children, ...props}: Record<string, string | boolean>) => {
6852
7031
  if (children == null) {
6853
7032
  return <script {...props} />;
@@ -6865,7 +7044,7 @@ Please check webstudio --help for more details`
6865
7044
  ` : ""}
6866
7045
 
6867
7046
  export const CustomCode = () => {
6868
- return (<>${(projectMeta == null ? void 0 : projectMeta.code) ? htmlToJsx(projectMeta.code) : ""}</>);
7047
+ return (<>${(projectMeta2 == null ? void 0 : projectMeta2.code) ? htmlToJsx(projectMeta2.code) : ""}</>);
6869
7048
  }
6870
7049
  ` : ""}
6871
7050
 
@@ -6880,7 +7059,7 @@ Please check webstudio --help for more details`
6880
7059
  import type { PageMeta } from "@webstudio-is/sdk";
6881
7060
  ${generateResources({
6882
7061
  scope,
6883
- page,
7062
+ page: page2,
6884
7063
  dataSources,
6885
7064
  props,
6886
7065
  resources
@@ -6888,22 +7067,22 @@ Please check webstudio --help for more details`
6888
7067
 
6889
7068
  ${generatePageMeta({
6890
7069
  globalScope: scope,
6891
- page,
7070
+ page: page2,
6892
7071
  dataSources,
6893
7072
  assets
6894
7073
  })}
6895
7074
 
6896
- ${generateRemixParams(page.path)}
7075
+ ${generateRemixParams(page2.path)}
6897
7076
 
6898
7077
  export const contactEmail = ${JSON.stringify(contactEmail)};
6899
7078
  `;
6900
- const generatedBasename = generateRemixRoute(pagePath);
7079
+ const generatedBasename = generateRemixRoute(pagePath2);
6901
7080
  const clientFile = join(generatedDir, `${generatedBasename}.tsx`);
6902
7081
  await createFileIfNotExists(clientFile, pageExports);
6903
7082
  const serverFile = join(generatedDir, `${generatedBasename}.server.tsx`);
6904
7083
  await createFileIfNotExists(serverFile, serverExports);
6905
7084
  const getTemplates = framework[documentType];
6906
- for (const { file, template } of getTemplates({ pagePath })) {
7085
+ for (const { file, template } of getTemplates({ pagePath: pagePath2 })) {
6907
7086
  const content = template.replaceAll("__CONSTANTS__", importFrom("./app/constants.mjs", file)).replaceAll(
6908
7087
  "__SITEMAP__",
6909
7088
  importFrom(`./app/__generated__/$resources.sitemap.xml`, file)
@@ -6937,16 +7116,16 @@ Please check webstudio --help for more details`
6937
7116
  join(generatedDir, "$resources.sitemap.xml.ts"),
6938
7117
  `
6939
7118
  export const sitemap = ${JSON.stringify(
6940
- getStaticSiteMapXml(pages, siteData.build.updatedAt),
7119
+ getStaticSiteMapXml(pages2, siteData.build.updatedAt),
6941
7120
  null,
6942
7121
  2
6943
7122
  )};
6944
7123
  `
6945
7124
  );
6946
7125
  const assetsById = Object.fromEntries(
6947
- siteData.assets.map((asset) => [
6948
- asset.id,
6949
- toRuntimeAsset(asset, "https://placeholder.local")
7126
+ siteData.assets.map((asset2) => [
7127
+ asset2.id,
7128
+ toRuntimeAsset(asset2, "https://placeholder.local")
6950
7129
  ])
6951
7130
  );
6952
7131
  await createFileIfNotExists(
@@ -6957,7 +7136,7 @@ Please check webstudio --help for more details`
6957
7136
  );
6958
7137
  await createFileIfNotExists(
6959
7138
  join(generatedDir, "$resources.redirects.ts"),
6960
- generateRedirectsModule(pages.redirects)
7139
+ generateRedirectsModule(pages2.redirects)
6961
7140
  );
6962
7141
  if (options.assets === true && siteData.assets.length > 0) {
6963
7142
  const downloading = spinner();
@@ -6973,20 +7152,20 @@ Please check webstudio --help for more details`
6973
7152
  log.step("Build finished");
6974
7153
  };
6975
7154
  const mapToTemplatesFromOptions = (values) => {
6976
- const templates = [];
7155
+ const templates2 = [];
6977
7156
  for (const value of values) {
6978
7157
  const template = PROJECT_TEMPLATES.find((item) => item.value === value) ?? INTERNAL_TEMPLATES.find((item) => item.value === value);
6979
7158
  if (template == null) {
6980
- templates.push(value);
7159
+ templates2.push(value);
6981
7160
  continue;
6982
7161
  }
6983
7162
  if ("expand" in template && template.expand != null) {
6984
- templates.push(...template.expand);
7163
+ templates2.push(...template.expand);
6985
7164
  continue;
6986
7165
  }
6987
- templates.push(value);
7166
+ templates2.push(value);
6988
7167
  }
6989
- return templates;
7168
+ return templates2;
6990
7169
  };
6991
7170
  const buildOptions = (yargs) => yargs.option("assets", {
6992
7171
  type: "boolean",
@@ -7025,7 +7204,7 @@ const exitIfCancelled = (value) => {
7025
7204
  const initFlow = async (options) => {
7026
7205
  const isProjectConfigured = await isFileExists(".webstudio/config.json");
7027
7206
  let shouldInstallDeps = false;
7028
- let folderName;
7207
+ let folderName2;
7029
7208
  let projectTemplate;
7030
7209
  if (isProjectConfigured === false) {
7031
7210
  const shouldCreateFolder = exitIfCancelled(
@@ -7035,7 +7214,7 @@ const initFlow = async (options) => {
7035
7214
  })
7036
7215
  );
7037
7216
  if (shouldCreateFolder === true) {
7038
- folderName = exitIfCancelled(
7217
+ folderName2 = exitIfCancelled(
7039
7218
  await text({
7040
7219
  message: "Please enter a project name",
7041
7220
  validate(value) {
@@ -7045,8 +7224,8 @@ const initFlow = async (options) => {
7045
7224
  }
7046
7225
  })
7047
7226
  );
7048
- await createFolderIfNotExists(join(cwd(), folderName));
7049
- chdir(join(cwd(), folderName));
7227
+ await createFolderIfNotExists(join(cwd(), folderName2));
7228
+ chdir(join(cwd(), folderName2));
7050
7229
  }
7051
7230
  const shareLink = exitIfCancelled(
7052
7231
  await text({
@@ -7094,7 +7273,7 @@ const initFlow = async (options) => {
7094
7273
  log.message(
7095
7274
  [
7096
7275
  "Now you can:",
7097
- folderName && `Go to your project: ${pc.dim(`cd ${folderName}`)}`,
7276
+ folderName2 && `Go to your project: ${pc.dim(`cd ${folderName2}`)}`,
7098
7277
  `Run ${pc.dim("npm run dev")} to preview your project on a local server.`,
7099
7278
  projectTemplate && getDeploymentInstructions(projectTemplate)
7100
7279
  ].filter(Boolean).join("\n")