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