@lucrex/storefront-blocks 0.0.0-stage → 0.1.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.
package/dist/index.cjs ADDED
@@ -0,0 +1,1231 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ BlockList: () => BlockList,
24
+ Breakpoints: () => Breakpoints,
25
+ FunnelTemplateIds: () => FunnelTemplateIds,
26
+ PageContent: () => PageContent,
27
+ PageDataProvider: () => PageDataProvider,
28
+ PageDocumentError: () => PageDocumentError,
29
+ StyleProperties: () => StyleProperties,
30
+ blockSelector: () => blockSelector,
31
+ blocks: () => blocks,
32
+ countBlocks: () => countBlocks,
33
+ funnelTemplate: () => funnelTemplate,
34
+ pageCss: () => pageCss,
35
+ pageFontStylesheets: () => pageFontStylesheets,
36
+ pageJsonSchema: () => pageJsonSchema,
37
+ pagePreloadImages: () => pagePreloadImages,
38
+ parsePageDocument: () => parsePageDocument,
39
+ usePageData: () => usePageData,
40
+ walkBlocks: () => walkBlocks
41
+ });
42
+ module.exports = __toCommonJS(index_exports);
43
+
44
+ // src/document.ts
45
+ var PageDocumentError = class extends Error {
46
+ constructor(issues) {
47
+ super(
48
+ `Invalid page document: ${issues.map((issue) => `${issue.path || "document"}: ${issue.message}`).join("; ")}`
49
+ );
50
+ this.issues = issues;
51
+ this.name = "PageDocumentError";
52
+ }
53
+ };
54
+
55
+ // src/style.ts
56
+ var import_zod = require("zod");
57
+ var StyleProperties = [
58
+ "display",
59
+ "position",
60
+ "top",
61
+ "right",
62
+ "bottom",
63
+ "left",
64
+ "zIndex",
65
+ "width",
66
+ "minWidth",
67
+ "maxWidth",
68
+ "height",
69
+ "minHeight",
70
+ "maxHeight",
71
+ "margin",
72
+ "marginTop",
73
+ "marginRight",
74
+ "marginBottom",
75
+ "marginLeft",
76
+ "padding",
77
+ "paddingTop",
78
+ "paddingRight",
79
+ "paddingBottom",
80
+ "paddingLeft",
81
+ "flexDirection",
82
+ "flexWrap",
83
+ "alignItems",
84
+ "justifyContent",
85
+ "gap",
86
+ "gridTemplateColumns",
87
+ "color",
88
+ "background",
89
+ "backgroundColor",
90
+ "backgroundImage",
91
+ "backgroundSize",
92
+ "backgroundPosition",
93
+ "fontFamily",
94
+ "fontSize",
95
+ "fontWeight",
96
+ "fontStyle",
97
+ "lineHeight",
98
+ "letterSpacing",
99
+ "textAlign",
100
+ "textTransform",
101
+ "textDecoration",
102
+ "border",
103
+ "borderTop",
104
+ "borderBottom",
105
+ "borderColor",
106
+ "borderRadius",
107
+ "boxShadow",
108
+ "opacity",
109
+ "overflow",
110
+ "objectFit",
111
+ "aspectRatio",
112
+ "transition",
113
+ "transform"
114
+ ];
115
+ var Breakpoints = {
116
+ tablet: "(max-width: 1023px)",
117
+ mobile: "(max-width: 767px)"
118
+ };
119
+ var StyleValueSchema = import_zod.z.string().max(500).regex(/^[^;{}<]*$/, "A style value cannot contain ; { } or <").refine((value) => !/(expression\s*\(|javascript:|@import)/i.test(value), {
120
+ message: "A style value cannot contain expression(), javascript: or @import"
121
+ }).refine((value) => !findUrls(value).some((url) => !isAllowedUrl(url)), {
122
+ message: "A style url() must be https:// or a data: image"
123
+ });
124
+ var DeclarationsSchema = import_zod.z.object(
125
+ Object.fromEntries(
126
+ StyleProperties.map((property) => [property, StyleValueSchema.optional()])
127
+ )
128
+ );
129
+ var BlockStyleSchema = DeclarationsSchema.extend({
130
+ tablet: DeclarationsSchema.optional(),
131
+ mobile: DeclarationsSchema.optional()
132
+ });
133
+ var CssSchema = import_zod.z.string().max(2e4).refine((value) => !value.includes("<"), { message: "CSS cannot contain <" }).refine((value) => !/(@import|expression\s*\(|javascript:|behavior\s*:)/i.test(value), {
134
+ message: "CSS cannot contain @import, expression(), javascript: or behavior"
135
+ }).refine((value) => !findUrls(value).some((url) => !isAllowedUrl(url)), {
136
+ message: "CSS url() must be https:// or a data: image"
137
+ });
138
+ function styleToCss(selector, style) {
139
+ if (!style) return "";
140
+ const { tablet, mobile, ...base } = style;
141
+ return [
142
+ rule(selector, base),
143
+ media(Breakpoints.tablet, rule(selector, tablet)),
144
+ media(Breakpoints.mobile, rule(selector, mobile))
145
+ ].filter(Boolean).join("\n");
146
+ }
147
+ function rule(selector, declarations) {
148
+ const body = Object.entries(declarations != null ? declarations : {}).filter(([, value]) => typeof value === "string" && value.trim() !== "").map(([property, value]) => `${kebab(property)}: ${value};`).join(" ");
149
+ return body ? `${selector} { ${body} }` : "";
150
+ }
151
+ function media(query, body) {
152
+ return body ? `@media ${query} { ${body} }` : "";
153
+ }
154
+ function kebab(property) {
155
+ return property.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
156
+ }
157
+ function findUrls(value) {
158
+ return [...value.matchAll(/url\(\s*(['"]?)([^'")]*)\1\s*\)/gi)].map((match) => match[2].trim());
159
+ }
160
+ function isAllowedUrl(url) {
161
+ return /^https:\/\//i.test(url) || /^data:image\//i.test(url);
162
+ }
163
+
164
+ // src/blocks/layout.tsx
165
+ var import_react = require("react");
166
+ var import_zod3 = require("zod");
167
+
168
+ // src/block.ts
169
+ var import_zod2 = require("zod");
170
+ var BlockIdSchema = import_zod2.z.string().min(1).max(100).regex(/^[A-Za-z0-9_-]+$/, "A block id can only contain letters, digits, _ and -");
171
+ var ClassNameSchema = import_zod2.z.string().max(200).regex(/^[A-Za-z0-9_\- ]*$/, "A class name can only contain letters, digits, _, - and spaces");
172
+ var BlockNodeSchema = import_zod2.z.object({
173
+ type: import_zod2.z.string().min(1),
174
+ props: import_zod2.z.looseObject({ id: BlockIdSchema })
175
+ });
176
+ var BaseBlockPropsSchema = import_zod2.z.object({
177
+ id: BlockIdSchema,
178
+ className: ClassNameSchema.optional(),
179
+ style: BlockStyleSchema.optional(),
180
+ css: CssSchema.optional()
181
+ });
182
+ function defineBlock(definition) {
183
+ var _a;
184
+ const slots = (_a = definition.slots) != null ? _a : [];
185
+ return {
186
+ ...definition,
187
+ slots,
188
+ defaultProps: {
189
+ ...definition.schema.parse({}),
190
+ ...Object.fromEntries(slots.map((slot) => [slot, []]))
191
+ }
192
+ };
193
+ }
194
+ function blockRoot(props, ...classNames) {
195
+ const className = [...classNames, props.className].filter(Boolean).join(" ");
196
+ return { "data-block": props.id, className: className || void 0 };
197
+ }
198
+
199
+ // src/blocks/layout.tsx
200
+ var import_jsx_runtime = require("react/jsx-runtime");
201
+ var AnchorIdSchema = import_zod3.z.string().max(60).regex(/^[A-Za-z0-9_-]*$/, "An anchor id can only contain letters, digits, _ and -");
202
+ var Section = defineBlock({
203
+ type: "Section",
204
+ label: "Section",
205
+ description: "A full-width page section that holds other blocks. Give it an anchorId so buttons can link to it with #anchorId.",
206
+ category: "layout",
207
+ schema: import_zod3.z.object({
208
+ tag: import_zod3.z.enum(["section", "div", "header", "footer", "aside", "nav"]).default("section"),
209
+ anchorId: AnchorIdSchema.default("")
210
+ }),
211
+ slots: ["content"],
212
+ fields: {
213
+ tag: {
214
+ type: "select",
215
+ label: "HTML tag",
216
+ options: ["section", "div", "header", "footer", "aside", "nav"].map((tag) => ({
217
+ label: tag,
218
+ value: tag
219
+ }))
220
+ },
221
+ anchorId: { type: "text", label: "Anchor id" }
222
+ },
223
+ render: (props) => (0, import_react.createElement)(
224
+ props.tag,
225
+ { ...blockRoot(props), id: props.anchorId || void 0 },
226
+ props.slots.content
227
+ )
228
+ });
229
+ var Stack = defineBlock({
230
+ type: "Stack",
231
+ label: "Stack",
232
+ description: "A plain container that groups blocks. Use style (display, flexDirection, gap) to lay them out.",
233
+ category: "layout",
234
+ schema: import_zod3.z.object({}),
235
+ slots: ["content"],
236
+ fields: {},
237
+ render: (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ...blockRoot(props), children: props.slots.content })
238
+ });
239
+ var Columns = defineBlock({
240
+ type: "Columns",
241
+ label: "Columns",
242
+ description: "Puts up to four columns side by side on desktop and stacks them on mobile. Fill column1 to columnN, where N is count.",
243
+ category: "layout",
244
+ schema: import_zod3.z.object({
245
+ count: import_zod3.z.union([import_zod3.z.literal(2), import_zod3.z.literal(3), import_zod3.z.literal(4)]).default(2),
246
+ stackOnMobile: import_zod3.z.boolean().default(true)
247
+ }),
248
+ slots: ["column1", "column2", "column3", "column4"],
249
+ fields: {
250
+ count: {
251
+ type: "select",
252
+ label: "Columns",
253
+ options: [2, 3, 4].map((count) => ({ label: String(count), value: count }))
254
+ },
255
+ stackOnMobile: {
256
+ type: "radio",
257
+ label: "Stack on mobile",
258
+ options: [
259
+ { label: "Yes", value: true },
260
+ { label: "No", value: false }
261
+ ]
262
+ }
263
+ },
264
+ render: (props) => {
265
+ const columns = [
266
+ props.slots.column1,
267
+ props.slots.column2,
268
+ props.slots.column3,
269
+ props.slots.column4
270
+ ];
271
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
272
+ "div",
273
+ {
274
+ ...blockRoot(
275
+ props,
276
+ "lx-columns",
277
+ `lx-columns--${props.count}`,
278
+ props.stackOnMobile && "lx-columns--stack"
279
+ ),
280
+ children: columns.slice(0, props.count).map((column, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "lx-columns__column", children: column }, index))
281
+ }
282
+ );
283
+ },
284
+ baseCss: `
285
+ .lx-columns { display: grid; gap: 24px; }
286
+ .lx-columns--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
287
+ .lx-columns--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
288
+ .lx-columns--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
289
+ @media (max-width: 767px) { .lx-columns--stack { grid-template-columns: minmax(0, 1fr); } }
290
+ `
291
+ });
292
+
293
+ // src/blocks/content.tsx
294
+ var import_react2 = require("react");
295
+ var import_zod4 = require("zod");
296
+ var import_jsx_runtime2 = require("react/jsx-runtime");
297
+ var LinkSchema = import_zod4.z.string().max(2e3).regex(
298
+ /^(https?:\/\/|\/|#|tel:|mailto:)/,
299
+ "A link must start with https://, http://, /, #, tel: or mailto:"
300
+ );
301
+ var ImageSourceSchema = import_zod4.z.string().max(2e3).regex(/^(https:\/\/|\/|$)/, "An image must be an https:// or / url");
302
+ var Heading = defineBlock({
303
+ type: "Heading",
304
+ label: "Heading",
305
+ description: "A title. Use level h1 once per page.",
306
+ category: "content",
307
+ schema: import_zod4.z.object({
308
+ text: import_zod4.z.string().max(500).default("Heading"),
309
+ level: import_zod4.z.enum(["h1", "h2", "h3", "h4", "h5", "h6"]).default("h2")
310
+ }),
311
+ fields: {
312
+ text: { type: "text", label: "Text" },
313
+ level: {
314
+ type: "select",
315
+ label: "Level",
316
+ options: ["h1", "h2", "h3", "h4", "h5", "h6"].map((level) => ({
317
+ label: level.toUpperCase(),
318
+ value: level
319
+ }))
320
+ }
321
+ },
322
+ render: (props) => (0, import_react2.createElement)(props.level, blockRoot(props, "lx-heading"), props.text),
323
+ baseCss: `.lx-heading { margin: 0; }`
324
+ });
325
+ var Text = defineBlock({
326
+ type: "Text",
327
+ label: "Text",
328
+ description: "A paragraph. Line breaks in text are kept.",
329
+ category: "content",
330
+ schema: import_zod4.z.object({
331
+ text: import_zod4.z.string().max(1e4).default("Text")
332
+ }),
333
+ fields: {
334
+ text: { type: "textarea", label: "Text" }
335
+ },
336
+ render: (props) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { ...blockRoot(props, "lx-text"), children: props.text }),
337
+ baseCss: `.lx-text { margin: 0; white-space: pre-line; }`
338
+ });
339
+ var Image = defineBlock({
340
+ type: "Image",
341
+ label: "Image",
342
+ description: "An image, optionally wrapped in a link. Set loading to eager for the first image a visitor sees.",
343
+ category: "content",
344
+ schema: import_zod4.z.object({
345
+ src: ImageSourceSchema.default(""),
346
+ alt: import_zod4.z.string().max(300).default(""),
347
+ href: LinkSchema.or(import_zod4.z.literal("")).default(""),
348
+ loading: import_zod4.z.enum(["lazy", "eager"]).default("lazy")
349
+ }),
350
+ fields: {
351
+ src: { type: "text", label: "Image url" },
352
+ alt: { type: "text", label: "Alternative text" },
353
+ href: { type: "text", label: "Link" },
354
+ loading: {
355
+ type: "radio",
356
+ label: "Loading",
357
+ options: [
358
+ { label: "Lazy", value: "lazy" },
359
+ { label: "Eager", value: "eager" }
360
+ ]
361
+ }
362
+ },
363
+ preload: (props) => props.loading === "eager" && props.src ? [props.src] : [],
364
+ render: (props) => {
365
+ if (!props.src) return null;
366
+ const image = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
367
+ "img",
368
+ {
369
+ ...props.href ? {} : blockRoot(props, "lx-image"),
370
+ src: props.src,
371
+ alt: props.alt,
372
+ loading: props.loading === "lazy" ? "lazy" : void 0,
373
+ fetchPriority: props.loading === "eager" ? "high" : void 0,
374
+ decoding: "async"
375
+ }
376
+ );
377
+ return props.href ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("a", { ...blockRoot(props, "lx-image"), href: props.href, children: image }) : image;
378
+ },
379
+ baseCss: `.lx-image { display: block; max-width: 100%; }`
380
+ });
381
+ var Button = defineBlock({
382
+ type: "Button",
383
+ label: "Button",
384
+ description: "A call-to-action link styled as a button. Link to #order to scroll to the order form.",
385
+ category: "content",
386
+ schema: import_zod4.z.object({
387
+ label: import_zod4.z.string().max(200).default("Order now"),
388
+ href: LinkSchema.default("#order"),
389
+ newTab: import_zod4.z.boolean().default(false)
390
+ }),
391
+ fields: {
392
+ label: { type: "text", label: "Label" },
393
+ href: { type: "text", label: "Link" },
394
+ newTab: {
395
+ type: "radio",
396
+ label: "Open in a new tab",
397
+ options: [
398
+ { label: "Yes", value: true },
399
+ { label: "No", value: false }
400
+ ]
401
+ }
402
+ },
403
+ render: (props) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
404
+ "a",
405
+ {
406
+ ...blockRoot(props, "lx-button"),
407
+ href: props.href,
408
+ target: props.newTab ? "_blank" : void 0,
409
+ rel: props.newTab ? "noopener noreferrer" : void 0,
410
+ children: props.label
411
+ }
412
+ ),
413
+ baseCss: `
414
+ .lx-button {
415
+ display: inline-flex;
416
+ align-items: center;
417
+ justify-content: center;
418
+ padding: 14px 24px;
419
+ border-radius: 12px;
420
+ background: var(--cs-accent);
421
+ color: var(--cs-accent-ink);
422
+ font-weight: 700;
423
+ text-decoration: none;
424
+ }
425
+ `
426
+ });
427
+ var Spacer = defineBlock({
428
+ type: "Spacer",
429
+ label: "Spacer",
430
+ description: "Empty vertical space. Set its height with style.height.",
431
+ category: "content",
432
+ schema: import_zod4.z.object({}),
433
+ fields: {},
434
+ render: (props) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { ...blockRoot(props, "lx-spacer"), "aria-hidden": "true" }),
435
+ baseCss: `.lx-spacer { height: 32px; }`
436
+ });
437
+
438
+ // src/blocks/product.tsx
439
+ var import_react4 = require("react");
440
+ var import_zod5 = require("zod");
441
+
442
+ // src/context.tsx
443
+ var import_react3 = require("react");
444
+ var import_jsx_runtime3 = require("react/jsx-runtime");
445
+ var PageDataContext = (0, import_react3.createContext)(null);
446
+ function PageDataProvider({ data, children }) {
447
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(PageDataContext.Provider, { value: data, children });
448
+ }
449
+ function usePageData() {
450
+ const data = (0, import_react3.useContext)(PageDataContext);
451
+ if (!data) {
452
+ throw new Error("Blocks must be rendered inside a PageDataProvider");
453
+ }
454
+ return data;
455
+ }
456
+
457
+ // src/blocks/product.tsx
458
+ var import_jsx_runtime4 = require("react/jsx-runtime");
459
+ function galleryImages(data) {
460
+ return data.landingPage.leadImages.length ? data.landingPage.leadImages : data.product.images;
461
+ }
462
+ var ProductTitle = defineBlock({
463
+ type: "ProductTitle",
464
+ label: "Product name",
465
+ description: "The product name, read from the product.",
466
+ category: "product",
467
+ schema: import_zod5.z.object({
468
+ level: import_zod5.z.enum(["h1", "h2", "h3"]).default("h1")
469
+ }),
470
+ fields: {
471
+ level: {
472
+ type: "select",
473
+ label: "Level",
474
+ options: ["h1", "h2", "h3"].map((level) => ({
475
+ label: level.toUpperCase(),
476
+ value: level
477
+ }))
478
+ }
479
+ },
480
+ render: function ProductTitle2(props) {
481
+ const data = usePageData();
482
+ return (0, import_react4.createElement)(
483
+ props.level,
484
+ { ...blockRoot(props, "cs-title"), "data-funnel": "product-name" },
485
+ data.product.name
486
+ );
487
+ }
488
+ });
489
+ var ProductPrice = defineBlock({
490
+ type: "ProductPrice",
491
+ label: "Price",
492
+ description: "The live price and the compare-at price. The storefront script fills them from the selected offer or variant.",
493
+ category: "product",
494
+ schema: import_zod5.z.object({}),
495
+ fields: {},
496
+ render: (props) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { ...blockRoot(props, "cs-price"), "data-funnel": "price", children: [
497
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "cs-price__current", "data-display-price": "" }),
498
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "cs-price__compare", "data-compare-price": "" })
499
+ ] })
500
+ });
501
+ var ProductTagline = defineBlock({
502
+ type: "ProductTagline",
503
+ label: "Tagline",
504
+ description: "The product tagline. Renders nothing when the product has none.",
505
+ category: "product",
506
+ schema: import_zod5.z.object({}),
507
+ fields: {},
508
+ render: function ProductTagline2(props) {
509
+ const { product } = usePageData();
510
+ if (!product.tagline) return null;
511
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { ...blockRoot(props, "cs-tagline"), "data-funnel": "tagline", children: product.tagline });
512
+ }
513
+ });
514
+ var ProductGallery = defineBlock({
515
+ type: "ProductGallery",
516
+ label: "Gallery",
517
+ description: "The main product image with clickable thumbnails. Uses the landing page lead images, or the product images when there are none.",
518
+ category: "product",
519
+ schema: import_zod5.z.object({}),
520
+ fields: {},
521
+ preload: (_props, data) => galleryImages(data).slice(0, 1),
522
+ render: function ProductGallery2(props) {
523
+ const data = usePageData();
524
+ const images = galleryImages(data);
525
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { ...blockRoot(props, "cs-gallery"), "data-funnel": "lead-images", children: images.length ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
526
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
527
+ "img",
528
+ {
529
+ className: "cs-gallery__main",
530
+ "data-gallery-main": "",
531
+ src: images[0],
532
+ alt: data.product.name,
533
+ fetchPriority: "high",
534
+ decoding: "async"
535
+ }
536
+ ),
537
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "cs-gallery__thumbs", children: images.map((image, index) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
538
+ "img",
539
+ {
540
+ src: image,
541
+ alt: data.product.name,
542
+ "data-gallery-thumb": "",
543
+ className: index === 0 ? "is-active" : void 0,
544
+ loading: index === 0 ? void 0 : "lazy",
545
+ decoding: "async"
546
+ },
547
+ index
548
+ )) })
549
+ ] }) : null });
550
+ }
551
+ });
552
+ var LandingImages = defineBlock({
553
+ type: "LandingImages",
554
+ label: "Landing images",
555
+ description: "The landing page images stacked one under the other. Set eagerFirstImage when they are the first thing a visitor sees.",
556
+ category: "product",
557
+ schema: import_zod5.z.object({
558
+ eagerFirstImage: import_zod5.z.boolean().default(false)
559
+ }),
560
+ fields: {
561
+ eagerFirstImage: {
562
+ type: "radio",
563
+ label: "Load the first image first",
564
+ options: [
565
+ { label: "Yes", value: true },
566
+ { label: "No", value: false }
567
+ ]
568
+ }
569
+ },
570
+ preload: (props, data) => props.eagerFirstImage ? data.landingPage.images.slice(0, 1) : [],
571
+ render: function LandingImages2(props) {
572
+ const data = usePageData();
573
+ const images = data.landingPage.images;
574
+ if (!images.length) return null;
575
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
576
+ "section",
577
+ {
578
+ ...blockRoot(props, "cs-landing-images", "cs-landing-images--flush"),
579
+ "data-funnel": "description",
580
+ children: images.map(
581
+ (image, index) => props.eagerFirstImage && index === 0 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
582
+ "img",
583
+ {
584
+ src: image,
585
+ alt: data.product.name,
586
+ fetchPriority: "high",
587
+ decoding: "async"
588
+ },
589
+ index
590
+ ) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
591
+ "img",
592
+ {
593
+ src: image,
594
+ alt: data.product.name,
595
+ loading: "lazy",
596
+ decoding: "async"
597
+ },
598
+ index
599
+ )
600
+ )
601
+ }
602
+ );
603
+ }
604
+ });
605
+ var ProductDescription = defineBlock({
606
+ type: "ProductDescription",
607
+ label: "Description",
608
+ description: "The product description text. With onlyWithoutLandingImages it shows only when the landing page has no images.",
609
+ category: "product",
610
+ schema: import_zod5.z.object({
611
+ onlyWithoutLandingImages: import_zod5.z.boolean().default(true)
612
+ }),
613
+ fields: {
614
+ onlyWithoutLandingImages: {
615
+ type: "radio",
616
+ label: "Only without landing images",
617
+ options: [
618
+ { label: "Yes", value: true },
619
+ { label: "No", value: false }
620
+ ]
621
+ }
622
+ },
623
+ render: function ProductDescription2(props) {
624
+ const data = usePageData();
625
+ if (!data.product.description) return null;
626
+ if (props.onlyWithoutLandingImages && data.landingPage.images.length) return null;
627
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("section", { ...blockRoot(props, "cs-card", "cs-desc"), "data-funnel": "description", children: data.product.description });
628
+ }
629
+ });
630
+ var ProductFaq = defineBlock({
631
+ type: "ProductFaq",
632
+ label: "FAQ",
633
+ description: "The product questions and answers. Renders nothing when there are none.",
634
+ category: "product",
635
+ schema: import_zod5.z.object({}),
636
+ fields: {},
637
+ render: function ProductFaq2(props) {
638
+ const { product } = usePageData();
639
+ if (!product.faq.length) return null;
640
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("section", { ...blockRoot(props, "cs-card", "cs-faq"), "data-funnel": "faq", children: product.faq.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("details", { children: [
641
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("summary", { children: item.question }),
642
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { children: item.answer })
643
+ ] }, index)) });
644
+ }
645
+ });
646
+
647
+ // src/blocks/checkout.tsx
648
+ var import_zod6 = require("zod");
649
+ var import_jsx_runtime5 = require("react/jsx-runtime");
650
+ function offerUnitCount(products) {
651
+ return products.reduce((sum, item) => sum + (item.quantity || 0), 0);
652
+ }
653
+ function offerUnitNumber(products, productIndex, unitIndex) {
654
+ var _a;
655
+ let start = 0;
656
+ for (let i = 0; i < productIndex; i += 1) {
657
+ start += ((_a = products[i]) == null ? void 0 : _a.quantity) || 0;
658
+ }
659
+ return start + unitIndex + 1;
660
+ }
661
+ function placeLabel(place) {
662
+ return place.name !== place.nameAr ? `${place.name} - ${place.nameAr}` : place.name;
663
+ }
664
+ function VariantSelects({ definitions: definitions2 }) {
665
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_jsx_runtime5.Fragment, { children: definitions2.map((definition) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { className: "cs-offer__field", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("select", { "data-variant-def": definition.name, "aria-label": definition.name, children: definition.values.map((value) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value, children: value }, value)) }) }, definition.name)) });
666
+ }
667
+ function VariantChips({ definitions: definitions2 }) {
668
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_jsx_runtime5.Fragment, { children: definitions2.map((definition) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
669
+ "div",
670
+ {
671
+ className: "cs-variants",
672
+ "data-variant-def": definition.name,
673
+ children: [
674
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "cs-section-title", children: definition.name }),
675
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "cs-chips", children: definition.values.map((value) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
676
+ "button",
677
+ {
678
+ type: "button",
679
+ className: "cs-chip",
680
+ "data-variant-value": value,
681
+ children: value
682
+ },
683
+ value
684
+ )) })
685
+ ]
686
+ },
687
+ definition.name
688
+ )) });
689
+ }
690
+ function OfferUnitVariants({ data, offer }) {
691
+ const { product } = data;
692
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "cs-offer__variants", "data-offer-variants": "", children: offer.products.map(
693
+ (item, productIndex) => Array.from({ length: item.quantity }, (_unused, unit) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
694
+ "div",
695
+ {
696
+ className: "cs-offer__unit",
697
+ "data-offer-unit": "",
698
+ "data-product-id": item.trackingId,
699
+ "data-unit-index": unit,
700
+ children: [
701
+ offerUnitCount(offer.products) > 1 ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "cs-offer__unit-label", children: `#${offerUnitNumber(offer.products, productIndex, unit)}` }) : null,
702
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "cs-offer__fields", children: product.isBundle ? product.bundleProducts.filter(
703
+ (bundleProduct) => bundleProduct.trackingId === item.trackingId
704
+ ).map((bundleProduct) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
705
+ VariantSelects,
706
+ {
707
+ definitions: bundleProduct.variantDefinitions
708
+ },
709
+ bundleProduct.trackingId
710
+ )) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(VariantSelects, { definitions: product.variantDefinitions }) })
711
+ ]
712
+ },
713
+ `${item.trackingId}-${productIndex}-${unit}`
714
+ ))
715
+ ) });
716
+ }
717
+ function Catalog({ data }) {
718
+ const { product, offers } = data;
719
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
720
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("section", { className: "cs-offers", "data-funnel": "offers", hidden: !offers.length, children: [
721
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "cs-section-title", "data-i18n": "offers" }),
722
+ offers.map((offer, index) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
723
+ "div",
724
+ {
725
+ className: [
726
+ "cs-offer",
727
+ index === 0 && "is-active",
728
+ offer.notes && "has-note"
729
+ ].filter(Boolean).join(" "),
730
+ "data-offer-id": offer.trackingId,
731
+ children: [
732
+ offer.notes ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "cs-offer__sticker", children: offer.notes }) : null,
733
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { type: "button", className: "cs-offer__pick", "data-offer-pick": "", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "cs-offer__head", children: [
734
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "cs-offer__copy", children: [
735
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "cs-offer__name", children: offer.name }),
736
+ offer.freeShipping ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "cs-offer__ship", "data-i18n": "freeShipping" }) : null
737
+ ] }),
738
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "cs-offer__price", children: [
739
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
740
+ "span",
741
+ {
742
+ className: "cs-price__compare",
743
+ "data-offer-compare": "",
744
+ hidden: true
745
+ }
746
+ ),
747
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
748
+ "span",
749
+ {
750
+ className: "cs-offer__price-value",
751
+ "data-price": offer.price
752
+ }
753
+ )
754
+ ] })
755
+ ] }) }),
756
+ product.isBundle || product.variantDefinitions.length ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(OfferUnitVariants, { data, offer }) : null
757
+ ]
758
+ },
759
+ offer.trackingId
760
+ ))
761
+ ] }),
762
+ offers.length ? null : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
763
+ product.isBundle ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("section", { "data-funnel": "bundle-products", children: product.bundleProducts.map((item) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
764
+ "div",
765
+ {
766
+ className: "cs-bundle",
767
+ "data-bundle-product": item.trackingId,
768
+ children: [
769
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "cs-section-title", children: item.name }),
770
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(VariantChips, { definitions: item.variantDefinitions })
771
+ ]
772
+ },
773
+ item.trackingId
774
+ )) }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("section", { "data-funnel": "variants", hidden: !product.variantDefinitions.length, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(VariantChips, { definitions: product.variantDefinitions }) }),
775
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("section", { className: "cs-qty", "data-funnel": "qty", children: [
776
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { type: "button", "data-qty": "-1", children: "-" }),
777
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "cs-qty__value", "data-qty-value": "", children: "1" }),
778
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { type: "button", "data-qty": "1", children: "+" })
779
+ ] })
780
+ ] })
781
+ ] });
782
+ }
783
+ function Totals() {
784
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "cs-totals", "data-funnel": "totals", children: [
785
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "cs-section-title", "data-i18n": "orderSummary" }),
786
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "cs-totals__row", children: [
787
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { "data-i18n": "productsPrice" }),
788
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("strong", { "data-total": "products" })
789
+ ] }),
790
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "cs-totals__row", children: [
791
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { "data-i18n": "shippingPrice" }),
792
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("strong", { "data-total": "shipping" })
793
+ ] }),
794
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "cs-totals__row cs-totals__row--total", children: [
795
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { "data-i18n": "total" }),
796
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("strong", { "data-total": "grand" })
797
+ ] })
798
+ ] });
799
+ }
800
+ function fieldAutocomplete(type) {
801
+ if (type === "phone") return "tel";
802
+ if (type === "name") return "name";
803
+ if (type === "address") return "street-address";
804
+ return "on";
805
+ }
806
+ function FormField({ data, type }) {
807
+ if (type === "state") {
808
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("select", { name: "state", "data-field": "state", children: [
809
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "" }),
810
+ data.geo.states.map((state) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
811
+ "option",
812
+ {
813
+ value: state.id,
814
+ "data-code": state.code,
815
+ "data-name": state.name,
816
+ "data-name-ar": state.nameAr,
817
+ children: placeLabel(state)
818
+ },
819
+ state.id
820
+ ))
821
+ ] });
822
+ }
823
+ if (type === "city") {
824
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("select", { name: "city", "data-field": "city", children: [
825
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "" }),
826
+ data.geo.cities.map((city) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
827
+ "option",
828
+ {
829
+ value: city.id,
830
+ "data-code": city.code,
831
+ "data-state": city.stateId,
832
+ "data-name": city.name,
833
+ "data-name-ar": city.nameAr,
834
+ children: placeLabel(city)
835
+ },
836
+ city.id
837
+ ))
838
+ ] });
839
+ }
840
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
841
+ "input",
842
+ {
843
+ type: type === "phone" ? "tel" : "text",
844
+ name: type,
845
+ "data-field": type,
846
+ autoComplete: fieldAutocomplete(type)
847
+ }
848
+ );
849
+ }
850
+ var PrivacyLink = "https://policies.google.com/privacy";
851
+ var TermsLink = "https://policies.google.com/terms";
852
+ function RecaptchaNotice({ language }) {
853
+ const link = (href, label) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("a", { href, target: "_blank", rel: "noopener noreferrer", children: label });
854
+ if (language === "ar") {
855
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("p", { className: "cs-recaptcha", children: [
856
+ "\u0647\u0630\u0627 \u0627\u0644\u0645\u0648\u0642\u0639 \u0645\u062D\u0645\u064A \u0628\u0648\u0627\u0633\u0637\u0629 reCAPTCHA \u0648\u062A\u0633\u0631\u064A ",
857
+ link(PrivacyLink, "\u0633\u064A\u0627\u0633\u0629 \u0627\u0644\u062E\u0635\u0648\u0635\u064A\u0629"),
858
+ " \u0648",
859
+ " ",
860
+ link(TermsLink, "\u0634\u0631\u0648\u0637 \u0627\u0644\u062E\u062F\u0645\u0629"),
861
+ " \u0627\u0644\u062E\u0627\u0635\u0629 \u0628\u0640 Google."
862
+ ] });
863
+ }
864
+ if (language === "fr") {
865
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("p", { className: "cs-recaptcha", children: [
866
+ "Ce site est prot\xE9g\xE9 par reCAPTCHA et les",
867
+ " ",
868
+ link(PrivacyLink, "r\xE8gles de confidentialit\xE9"),
869
+ " et",
870
+ " ",
871
+ link(TermsLink, "conditions d'utilisation"),
872
+ " de Google s'appliquent."
873
+ ] });
874
+ }
875
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("p", { className: "cs-recaptcha", children: [
876
+ "This site is protected by reCAPTCHA and the Google ",
877
+ link(PrivacyLink, "Privacy Policy"),
878
+ " ",
879
+ "and ",
880
+ link(TermsLink, "Terms of Service"),
881
+ " apply."
882
+ ] });
883
+ }
884
+ function OrderFormView(props) {
885
+ var _a;
886
+ const data = usePageData();
887
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("form", { ...blockRoot(props, "cs-form"), "data-funnel": "form", children: [
888
+ props.includeCatalog ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Catalog, { data }) : null,
889
+ data.funnel.form.fields.filter((field) => field.enabled).map((field) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
890
+ "div",
891
+ {
892
+ className: "cs-field",
893
+ "data-funnel-field": field.type,
894
+ "data-required": String(field.required),
895
+ children: [
896
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { "data-i18n": field.type }),
897
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(FormField, { data, type: field.type }),
898
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "cs-field__error", "data-error": "" })
899
+ ]
900
+ },
901
+ field.type
902
+ )),
903
+ ((_a = data.deliveryPrices) == null ? void 0 : _a.stopdeskEnabled) ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "cs-ship", "data-funnel": "shipping-method", children: [
904
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
905
+ "button",
906
+ {
907
+ type: "button",
908
+ className: "cs-chip is-active",
909
+ "data-ship": "home",
910
+ "data-i18n": "homeDelivery"
911
+ }
912
+ ),
913
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
914
+ "button",
915
+ {
916
+ type: "button",
917
+ className: "cs-chip",
918
+ "data-ship": "stopdesk",
919
+ "data-i18n": "stopDesk"
920
+ }
921
+ )
922
+ ] }) : null,
923
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Totals, {}),
924
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { type: "submit", className: "cs-submit", "data-i18n": "orderNow" }),
925
+ data.api.recaptchaSiteKey ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(RecaptchaNotice, { language: data.funnel.language }) : null
926
+ ] });
927
+ }
928
+ var ProductCatalog = defineBlock({
929
+ type: "ProductCatalog",
930
+ label: "Offers and variants",
931
+ description: "The offer picker, or the variant chips and quantity when the product has no offers. Use it only when the order form does not include the catalog.",
932
+ category: "checkout",
933
+ schema: import_zod6.z.object({}),
934
+ fields: {},
935
+ render: function ProductCatalog2(props) {
936
+ const data = usePageData();
937
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { ...blockRoot(props), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Catalog, { data }) });
938
+ }
939
+ });
940
+ var OrderForm = defineBlock({
941
+ type: "OrderForm",
942
+ label: "Order form",
943
+ description: "The checkout form: customer fields, shipping method, totals and the order button. Every funnel page needs exactly one. Set includeCatalog to show the offers and variants inside the form.",
944
+ category: "checkout",
945
+ schema: import_zod6.z.object({
946
+ includeCatalog: import_zod6.z.boolean().default(true)
947
+ }),
948
+ fields: {
949
+ includeCatalog: {
950
+ type: "radio",
951
+ label: "Show offers and variants in the form",
952
+ options: [
953
+ { label: "Yes", value: true },
954
+ { label: "No", value: false }
955
+ ]
956
+ }
957
+ },
958
+ render: (props) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(OrderFormView, { ...props })
959
+ });
960
+
961
+ // src/blocks/index.ts
962
+ var definitions = [
963
+ Section,
964
+ Stack,
965
+ Columns,
966
+ Heading,
967
+ Text,
968
+ Image,
969
+ Button,
970
+ Spacer,
971
+ ProductTitle,
972
+ ProductPrice,
973
+ ProductTagline,
974
+ ProductGallery,
975
+ LandingImages,
976
+ ProductDescription,
977
+ ProductFaq,
978
+ ProductCatalog,
979
+ OrderForm
980
+ ];
981
+ var blocks = Object.fromEntries(
982
+ definitions.map((definition) => [definition.type, definition])
983
+ );
984
+
985
+ // src/page.ts
986
+ var import_react5 = require("react");
987
+
988
+ // src/validate.ts
989
+ var import_zod7 = require("zod");
990
+ var FontSchema = import_zod7.z.object({
991
+ family: import_zod7.z.string().min(1).max(60).regex(/^[A-Za-z0-9 ]+$/, "A font family can only contain letters, digits and spaces"),
992
+ weights: import_zod7.z.array(import_zod7.z.number().int().min(100).max(900)).max(9).default([400, 700])
993
+ });
994
+ var PageRootPropsSchema = import_zod7.z.object({
995
+ css: CssSchema.optional(),
996
+ fonts: import_zod7.z.array(FontSchema).max(4).optional()
997
+ });
998
+ var DocumentShapeSchema = import_zod7.z.object({
999
+ root: import_zod7.z.object({ props: import_zod7.z.unknown() }).default({ props: {} }),
1000
+ content: import_zod7.z.array(import_zod7.z.unknown())
1001
+ });
1002
+ function blockPropsSchema(definition) {
1003
+ return BaseBlockPropsSchema.extend(definition.schema.shape).extend(
1004
+ Object.fromEntries(
1005
+ definition.slots.map((slot) => [slot, import_zod7.z.array(BlockNodeSchema).default([])])
1006
+ )
1007
+ );
1008
+ }
1009
+ function parsePageDocument(input) {
1010
+ var _a;
1011
+ const issues = [];
1012
+ const shape = DocumentShapeSchema.safeParse(input);
1013
+ if (!shape.success) {
1014
+ throw new PageDocumentError(toIssues(shape.error, ""));
1015
+ }
1016
+ const root = PageRootPropsSchema.safeParse((_a = shape.data.root.props) != null ? _a : {});
1017
+ if (!root.success) {
1018
+ issues.push(...toIssues(root.error, "root.props"));
1019
+ }
1020
+ const ids = /* @__PURE__ */ new Set();
1021
+ const content = parseNodes(shape.data.content, "content", ids, issues);
1022
+ if (issues.length) {
1023
+ throw new PageDocumentError(issues);
1024
+ }
1025
+ return { root: { props: root.data }, content };
1026
+ }
1027
+ function parseNodes(nodes, path, ids, issues) {
1028
+ const parsed = [];
1029
+ nodes.forEach((raw, index) => {
1030
+ const nodePath = `${path}[${index}]`;
1031
+ const node = BlockNodeSchema.safeParse(raw);
1032
+ if (!node.success) {
1033
+ issues.push(...toIssues(node.error, nodePath));
1034
+ return;
1035
+ }
1036
+ const definition = blocks[node.data.type];
1037
+ if (!definition) {
1038
+ issues.push({
1039
+ path: `${nodePath}.type`,
1040
+ message: `Unknown block type ${node.data.type}`
1041
+ });
1042
+ return;
1043
+ }
1044
+ if (ids.has(node.data.props.id)) {
1045
+ issues.push({
1046
+ path: `${nodePath}.props.id`,
1047
+ message: `The block id ${node.data.props.id} is used more than once`
1048
+ });
1049
+ }
1050
+ ids.add(node.data.props.id);
1051
+ const props = blockPropsSchema(definition).safeParse(node.data.props);
1052
+ if (!props.success) {
1053
+ issues.push(...toIssues(props.error, `${nodePath}.props`));
1054
+ return;
1055
+ }
1056
+ const values = props.data;
1057
+ for (const slot of definition.slots) {
1058
+ values[slot] = parseNodes(
1059
+ values[slot],
1060
+ `${nodePath}.props.${slot}`,
1061
+ ids,
1062
+ issues
1063
+ );
1064
+ }
1065
+ parsed.push({ type: definition.type, props: values });
1066
+ });
1067
+ return parsed;
1068
+ }
1069
+ function toIssues(error, prefix) {
1070
+ return error.issues.map((issue) => ({
1071
+ path: [prefix, ...issue.path.map(String)].filter(Boolean).join("."),
1072
+ message: issue.message
1073
+ }));
1074
+ }
1075
+ function walkBlocks(nodes, visit) {
1076
+ var _a, _b, _c;
1077
+ for (const node of nodes) {
1078
+ visit(node);
1079
+ for (const slot of (_b = (_a = blocks[node.type]) == null ? void 0 : _a.slots) != null ? _b : []) {
1080
+ walkBlocks((_c = node.props[slot]) != null ? _c : [], visit);
1081
+ }
1082
+ }
1083
+ }
1084
+ function countBlocks(document, type) {
1085
+ let count = 0;
1086
+ walkBlocks(document.content, (node) => {
1087
+ if (node.type === type) count += 1;
1088
+ });
1089
+ return count;
1090
+ }
1091
+
1092
+ // src/page.ts
1093
+ function BlockList({ nodes }) {
1094
+ return (0, import_react5.createElement)(
1095
+ import_react5.Fragment,
1096
+ null,
1097
+ nodes.map((node) => (0, import_react5.createElement)(BlockView, { key: node.props.id, node }))
1098
+ );
1099
+ }
1100
+ function BlockView({ node }) {
1101
+ const definition = blocks[node.type];
1102
+ if (!definition) return null;
1103
+ const slots = Object.fromEntries(
1104
+ definition.slots.map((slot) => {
1105
+ var _a;
1106
+ return [
1107
+ slot,
1108
+ (0, import_react5.createElement)(BlockList, { nodes: (_a = node.props[slot]) != null ? _a : [] })
1109
+ ];
1110
+ })
1111
+ );
1112
+ return (0, import_react5.createElement)(definition.render, { ...definition.defaultProps, ...node.props, slots });
1113
+ }
1114
+ function PageContent({
1115
+ document,
1116
+ data
1117
+ }) {
1118
+ return (0, import_react5.createElement)(PageDataProvider, {
1119
+ data,
1120
+ children: (0, import_react5.createElement)(BlockList, { nodes: document.content })
1121
+ });
1122
+ }
1123
+ function blockSelector(id) {
1124
+ return `[data-block="${id}"]`;
1125
+ }
1126
+ function pageCss(document) {
1127
+ var _a;
1128
+ const base = /* @__PURE__ */ new Set();
1129
+ const scoped = [];
1130
+ walkBlocks(document.content, (node) => {
1131
+ const definition = blocks[node.type];
1132
+ if (definition == null ? void 0 : definition.baseCss) base.add(definition.baseCss);
1133
+ const selector = blockSelector(node.props.id);
1134
+ scoped.push(styleToCss(selector, node.props.style));
1135
+ if (typeof node.props.css === "string" && node.props.css.trim()) {
1136
+ scoped.push(`${selector} { ${node.props.css} }`);
1137
+ }
1138
+ });
1139
+ return [...base, (_a = document.root.props.css) != null ? _a : "", ...scoped].filter(Boolean).join("\n");
1140
+ }
1141
+ function pagePreloadImages(document, data) {
1142
+ const images = [];
1143
+ walkBlocks(document.content, (node) => {
1144
+ const definition = blocks[node.type];
1145
+ if (definition == null ? void 0 : definition.preload) {
1146
+ images.push(...definition.preload({ ...definition.defaultProps, ...node.props }, data));
1147
+ }
1148
+ });
1149
+ return [...new Set(images)];
1150
+ }
1151
+ function pageFontStylesheets(document) {
1152
+ var _a;
1153
+ return ((_a = document.root.props.fonts) != null ? _a : []).map((font) => {
1154
+ var _a2;
1155
+ const family = encodeURIComponent(font.family).replace(/%20/g, "+");
1156
+ const weights = [...new Set((_a2 = font.weights) != null ? _a2 : [400, 700])].sort((a, b) => a - b).join(";");
1157
+ return `https://fonts.googleapis.com/css2?family=${family}:wght@${weights}&display=swap`;
1158
+ });
1159
+ }
1160
+
1161
+ // src/json-schema.ts
1162
+ var import_zod8 = require("zod");
1163
+ function pageJsonSchema() {
1164
+ return {
1165
+ format: "A page is { root: { props }, content: Block[] }. A block is { type, props: { id, ...props } }. Ids are unique on the page. Slot props hold Block[]. Every block accepts style (CSS properties in camelCase, with tablet and mobile overrides) and css (CSS scoped to the block, nesting allowed, & is the block).",
1166
+ root: import_zod8.z.toJSONSchema(PageRootPropsSchema, { io: "input" }),
1167
+ blocks: Object.values(blocks).map((definition) => ({
1168
+ type: definition.type,
1169
+ label: definition.label,
1170
+ description: definition.description,
1171
+ category: definition.category,
1172
+ slots: definition.slots,
1173
+ props: import_zod8.z.toJSONSchema(blockPropsSchema(definition), { io: "input" })
1174
+ }))
1175
+ };
1176
+ }
1177
+
1178
+ // src/templates/funnels.ts
1179
+ var FunnelTemplateIds = ["classic-product", "classic-landing"];
1180
+ function block(type, id, props = {}) {
1181
+ return { type, props: { id, ...props } };
1182
+ }
1183
+ function page(content) {
1184
+ return { root: { props: {} }, content };
1185
+ }
1186
+ function classicProduct() {
1187
+ return page([
1188
+ block("Section", "hero", {
1189
+ tag: "section",
1190
+ className: "cs-hero",
1191
+ content: [
1192
+ block("ProductGallery", "gallery"),
1193
+ block("Stack", "buy-box", {
1194
+ content: [
1195
+ block("ProductTitle", "product-name", { level: "h1" }),
1196
+ block("ProductPrice", "price"),
1197
+ block("ProductTagline", "tagline"),
1198
+ block("ProductCatalog", "catalog"),
1199
+ block("OrderForm", "order-form", { includeCatalog: false })
1200
+ ]
1201
+ })
1202
+ ]
1203
+ }),
1204
+ block("LandingImages", "landing-images", { eagerFirstImage: false }),
1205
+ block("ProductDescription", "description", { onlyWithoutLandingImages: true }),
1206
+ block("ProductFaq", "faq")
1207
+ ]);
1208
+ }
1209
+ function classicLanding(options) {
1210
+ const formOnTop = options.formPosition === "top";
1211
+ const order = block("Section", "order", {
1212
+ tag: "section",
1213
+ className: "cs-card",
1214
+ anchorId: "order",
1215
+ content: [
1216
+ block("ProductTitle", "product-name", { level: "h1" }),
1217
+ block("ProductPrice", "price"),
1218
+ block("OrderForm", "order-form", { includeCatalog: true })
1219
+ ]
1220
+ });
1221
+ const images = block("LandingImages", "landing-images", { eagerFirstImage: !formOnTop });
1222
+ const description = block("ProductDescription", "description", {
1223
+ onlyWithoutLandingImages: true
1224
+ });
1225
+ return page(formOnTop ? [order, images, description] : [images, order, description]);
1226
+ }
1227
+ function funnelTemplate(templateId, options) {
1228
+ if (templateId === "classic-product") return classicProduct();
1229
+ if (templateId === "classic-landing") return classicLanding(options);
1230
+ throw new Error(`Unknown funnel template ${templateId}`);
1231
+ }