@lucrex/storefront-blocks 0.0.0-stage → 0.2.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,2538 @@
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
+ function checkoutData(data) {
414
+ if (!data.funnel || !data.product || !data.landingPage || !data.geo || !data.api) {
415
+ throw new Error("This block needs the product and checkout data of a product page");
416
+ }
417
+ return data;
418
+ }
419
+ function useCheckoutData() {
420
+ return checkoutData(usePageData());
421
+ }
422
+ function storeData(data) {
423
+ if (!data.store) {
424
+ throw new Error("This block needs the data of an online store page");
425
+ }
426
+ return data.store;
427
+ }
428
+ function useStoreData() {
429
+ return storeData(usePageData());
430
+ }
431
+
432
+ // src/blocks/product.tsx
433
+ import { Fragment, jsx as jsx4, jsxs } from "react/jsx-runtime";
434
+ function galleryImages(data) {
435
+ return data.landingPage.leadImages.length ? data.landingPage.leadImages : data.product.images;
436
+ }
437
+ var ProductTitle = defineBlock({
438
+ type: "ProductTitle",
439
+ label: "Product name",
440
+ description: "The product name, read from the product.",
441
+ category: "product",
442
+ schema: z5.object({
443
+ level: z5.enum(["h1", "h2", "h3"]).default("h1")
444
+ }),
445
+ fields: {
446
+ level: {
447
+ type: "select",
448
+ label: "Level",
449
+ options: ["h1", "h2", "h3"].map((level) => ({
450
+ label: level.toUpperCase(),
451
+ value: level
452
+ }))
453
+ }
454
+ },
455
+ render: function ProductTitle2(props) {
456
+ const data = useCheckoutData();
457
+ return createElement3(
458
+ props.level,
459
+ { ...blockRoot(props, "cs-title"), "data-funnel": "product-name" },
460
+ data.product.name
461
+ );
462
+ }
463
+ });
464
+ var ProductPrice = defineBlock({
465
+ type: "ProductPrice",
466
+ label: "Price",
467
+ description: "The live price and the compare-at price. The storefront script fills them from the selected offer or variant.",
468
+ category: "product",
469
+ schema: z5.object({}),
470
+ fields: {},
471
+ render: (props) => /* @__PURE__ */ jsxs("div", { ...blockRoot(props, "cs-price"), "data-funnel": "price", children: [
472
+ /* @__PURE__ */ jsx4("span", { className: "cs-price__current", "data-display-price": "" }),
473
+ /* @__PURE__ */ jsx4("span", { className: "cs-price__compare", "data-compare-price": "" })
474
+ ] })
475
+ });
476
+ var ProductTagline = defineBlock({
477
+ type: "ProductTagline",
478
+ label: "Tagline",
479
+ description: "The product tagline. Renders nothing when the product has none.",
480
+ category: "product",
481
+ schema: z5.object({}),
482
+ fields: {},
483
+ render: function ProductTagline2(props) {
484
+ const { product: product2 } = useCheckoutData();
485
+ if (!product2.tagline) return null;
486
+ return /* @__PURE__ */ jsx4("p", { ...blockRoot(props, "cs-tagline"), "data-funnel": "tagline", children: product2.tagline });
487
+ }
488
+ });
489
+ var ProductGallery = defineBlock({
490
+ type: "ProductGallery",
491
+ label: "Gallery",
492
+ description: "The main product image with clickable thumbnails. Uses the landing page lead images, or the product images when there are none.",
493
+ category: "product",
494
+ schema: z5.object({}),
495
+ fields: {},
496
+ preload: (_props, data) => galleryImages(checkoutData(data)).slice(0, 1),
497
+ render: function ProductGallery2(props) {
498
+ const data = useCheckoutData();
499
+ const images = galleryImages(data);
500
+ return /* @__PURE__ */ jsx4("div", { ...blockRoot(props, "cs-gallery"), "data-funnel": "lead-images", children: images.length ? /* @__PURE__ */ jsxs(Fragment, { children: [
501
+ /* @__PURE__ */ jsx4(
502
+ "img",
503
+ {
504
+ className: "cs-gallery__main",
505
+ "data-gallery-main": "",
506
+ src: images[0],
507
+ alt: data.product.name,
508
+ fetchPriority: "high",
509
+ decoding: "async"
510
+ }
511
+ ),
512
+ /* @__PURE__ */ jsx4("div", { className: "cs-gallery__thumbs", children: images.map((image, index) => /* @__PURE__ */ jsx4(
513
+ "img",
514
+ {
515
+ src: image,
516
+ alt: data.product.name,
517
+ "data-gallery-thumb": "",
518
+ className: index === 0 ? "is-active" : void 0,
519
+ loading: index === 0 ? void 0 : "lazy",
520
+ decoding: "async"
521
+ },
522
+ index
523
+ )) })
524
+ ] }) : null });
525
+ }
526
+ });
527
+ var LandingImages = defineBlock({
528
+ type: "LandingImages",
529
+ label: "Landing images",
530
+ description: "The landing page images stacked one under the other. Set eagerFirstImage when they are the first thing a visitor sees.",
531
+ category: "product",
532
+ schema: z5.object({
533
+ eagerFirstImage: z5.boolean().default(false)
534
+ }),
535
+ fields: {
536
+ eagerFirstImage: {
537
+ type: "radio",
538
+ label: "Load the first image first",
539
+ options: [
540
+ { label: "Yes", value: true },
541
+ { label: "No", value: false }
542
+ ]
543
+ }
544
+ },
545
+ preload: (props, data) => props.eagerFirstImage ? checkoutData(data).landingPage.images.slice(0, 1) : [],
546
+ render: function LandingImages2(props) {
547
+ const data = useCheckoutData();
548
+ const images = data.landingPage.images;
549
+ if (!images.length) return null;
550
+ return /* @__PURE__ */ jsx4(
551
+ "section",
552
+ {
553
+ ...blockRoot(props, "cs-landing-images", "cs-landing-images--flush"),
554
+ "data-funnel": "description",
555
+ children: images.map(
556
+ (image, index) => props.eagerFirstImage && index === 0 ? /* @__PURE__ */ jsx4(
557
+ "img",
558
+ {
559
+ src: image,
560
+ alt: data.product.name,
561
+ fetchPriority: "high",
562
+ decoding: "async"
563
+ },
564
+ index
565
+ ) : /* @__PURE__ */ jsx4(
566
+ "img",
567
+ {
568
+ src: image,
569
+ alt: data.product.name,
570
+ loading: "lazy",
571
+ decoding: "async"
572
+ },
573
+ index
574
+ )
575
+ )
576
+ }
577
+ );
578
+ }
579
+ });
580
+ var ProductDescription = defineBlock({
581
+ type: "ProductDescription",
582
+ label: "Description",
583
+ description: "The product description text. With onlyWithoutLandingImages it shows only when the landing page has no images.",
584
+ category: "product",
585
+ schema: z5.object({
586
+ onlyWithoutLandingImages: z5.boolean().default(true)
587
+ }),
588
+ fields: {
589
+ onlyWithoutLandingImages: {
590
+ type: "radio",
591
+ label: "Only without landing images",
592
+ options: [
593
+ { label: "Yes", value: true },
594
+ { label: "No", value: false }
595
+ ]
596
+ }
597
+ },
598
+ render: function ProductDescription2(props) {
599
+ const data = useCheckoutData();
600
+ if (!data.product.description) return null;
601
+ if (props.onlyWithoutLandingImages && data.landingPage.images.length) return null;
602
+ return /* @__PURE__ */ jsx4("section", { ...blockRoot(props, "cs-card", "cs-desc"), "data-funnel": "description", children: data.product.description });
603
+ }
604
+ });
605
+ var ProductFaq = defineBlock({
606
+ type: "ProductFaq",
607
+ label: "FAQ",
608
+ description: "The product questions and answers. Renders nothing when there are none.",
609
+ category: "product",
610
+ schema: z5.object({}),
611
+ fields: {},
612
+ render: function ProductFaq2(props) {
613
+ const { product: product2 } = useCheckoutData();
614
+ if (!product2.faq.length) return null;
615
+ return /* @__PURE__ */ jsx4("section", { ...blockRoot(props, "cs-card", "cs-faq"), "data-funnel": "faq", children: product2.faq.map((item, index) => /* @__PURE__ */ jsxs("details", { children: [
616
+ /* @__PURE__ */ jsx4("summary", { children: item.question }),
617
+ /* @__PURE__ */ jsx4("p", { children: item.answer })
618
+ ] }, index)) });
619
+ }
620
+ });
621
+
622
+ // src/blocks/checkout.tsx
623
+ import { z as z6 } from "zod";
624
+ import { Fragment as Fragment2, jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
625
+ function offerUnitCount(products2) {
626
+ return products2.reduce((sum, item) => sum + (item.quantity || 0), 0);
627
+ }
628
+ function offerUnitNumber(products2, productIndex, unitIndex) {
629
+ var _a;
630
+ let start = 0;
631
+ for (let i = 0; i < productIndex; i += 1) {
632
+ start += ((_a = products2[i]) == null ? void 0 : _a.quantity) || 0;
633
+ }
634
+ return start + unitIndex + 1;
635
+ }
636
+ function placeLabel(place) {
637
+ return place.name !== place.nameAr ? `${place.name} - ${place.nameAr}` : place.name;
638
+ }
639
+ function VariantSelects({ definitions: definitions2 }) {
640
+ 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)) });
641
+ }
642
+ function VariantChips({ definitions: definitions2 }) {
643
+ return /* @__PURE__ */ jsx5(Fragment2, { children: definitions2.map((definition) => /* @__PURE__ */ jsxs2(
644
+ "div",
645
+ {
646
+ className: "cs-variants",
647
+ "data-variant-def": definition.name,
648
+ children: [
649
+ /* @__PURE__ */ jsx5("p", { className: "cs-section-title", children: definition.name }),
650
+ /* @__PURE__ */ jsx5("div", { className: "cs-chips", children: definition.values.map((value) => /* @__PURE__ */ jsx5(
651
+ "button",
652
+ {
653
+ type: "button",
654
+ className: "cs-chip",
655
+ "data-variant-value": value,
656
+ children: value
657
+ },
658
+ value
659
+ )) })
660
+ ]
661
+ },
662
+ definition.name
663
+ )) });
664
+ }
665
+ function OfferUnitVariants({ data, offer }) {
666
+ const { product: product2 } = data;
667
+ return /* @__PURE__ */ jsx5("div", { className: "cs-offer__variants", "data-offer-variants": "", children: offer.products.map(
668
+ (item, productIndex) => Array.from({ length: item.quantity }, (_unused, unit) => /* @__PURE__ */ jsxs2(
669
+ "div",
670
+ {
671
+ className: "cs-offer__unit",
672
+ "data-offer-unit": "",
673
+ "data-product-id": item.trackingId,
674
+ "data-unit-index": unit,
675
+ children: [
676
+ offerUnitCount(offer.products) > 1 ? /* @__PURE__ */ jsx5("span", { className: "cs-offer__unit-label", children: `#${offerUnitNumber(offer.products, productIndex, unit)}` }) : null,
677
+ /* @__PURE__ */ jsx5("div", { className: "cs-offer__fields", children: product2.isBundle ? product2.bundleProducts.filter(
678
+ (bundleProduct) => bundleProduct.trackingId === item.trackingId
679
+ ).map((bundleProduct) => /* @__PURE__ */ jsx5(
680
+ VariantSelects,
681
+ {
682
+ definitions: bundleProduct.variantDefinitions
683
+ },
684
+ bundleProduct.trackingId
685
+ )) : /* @__PURE__ */ jsx5(VariantSelects, { definitions: product2.variantDefinitions }) })
686
+ ]
687
+ },
688
+ `${item.trackingId}-${productIndex}-${unit}`
689
+ ))
690
+ ) });
691
+ }
692
+ function Catalog({ data }) {
693
+ const { product: product2, offers } = data;
694
+ return /* @__PURE__ */ jsxs2(Fragment2, { children: [
695
+ /* @__PURE__ */ jsxs2("section", { className: "cs-offers", "data-funnel": "offers", hidden: !offers.length, children: [
696
+ /* @__PURE__ */ jsx5("p", { className: "cs-section-title", "data-i18n": "offers" }),
697
+ offers.map((offer, index) => /* @__PURE__ */ jsxs2(
698
+ "div",
699
+ {
700
+ className: [
701
+ "cs-offer",
702
+ index === 0 && "is-active",
703
+ offer.notes && "has-note"
704
+ ].filter(Boolean).join(" "),
705
+ "data-offer-id": offer.trackingId,
706
+ children: [
707
+ offer.notes ? /* @__PURE__ */ jsx5("span", { className: "cs-offer__sticker", children: offer.notes }) : null,
708
+ /* @__PURE__ */ jsx5("button", { type: "button", className: "cs-offer__pick", "data-offer-pick": "", children: /* @__PURE__ */ jsxs2("div", { className: "cs-offer__head", children: [
709
+ /* @__PURE__ */ jsxs2("div", { className: "cs-offer__copy", children: [
710
+ /* @__PURE__ */ jsx5("div", { className: "cs-offer__name", children: offer.name }),
711
+ offer.freeShipping ? /* @__PURE__ */ jsx5("span", { className: "cs-offer__ship", "data-i18n": "freeShipping" }) : null
712
+ ] }),
713
+ /* @__PURE__ */ jsxs2("div", { className: "cs-offer__price", children: [
714
+ /* @__PURE__ */ jsx5(
715
+ "span",
716
+ {
717
+ className: "cs-price__compare",
718
+ "data-offer-compare": "",
719
+ hidden: true
720
+ }
721
+ ),
722
+ /* @__PURE__ */ jsx5(
723
+ "span",
724
+ {
725
+ className: "cs-offer__price-value",
726
+ "data-price": offer.price
727
+ }
728
+ )
729
+ ] })
730
+ ] }) }),
731
+ product2.isBundle || product2.variantDefinitions.length ? /* @__PURE__ */ jsx5(OfferUnitVariants, { data, offer }) : null
732
+ ]
733
+ },
734
+ offer.trackingId
735
+ ))
736
+ ] }),
737
+ offers.length ? null : /* @__PURE__ */ jsxs2(Fragment2, { children: [
738
+ product2.isBundle ? /* @__PURE__ */ jsx5("section", { "data-funnel": "bundle-products", children: product2.bundleProducts.map((item) => /* @__PURE__ */ jsxs2(
739
+ "div",
740
+ {
741
+ className: "cs-bundle",
742
+ "data-bundle-product": item.trackingId,
743
+ children: [
744
+ /* @__PURE__ */ jsx5("p", { className: "cs-section-title", children: item.name }),
745
+ /* @__PURE__ */ jsx5(VariantChips, { definitions: item.variantDefinitions })
746
+ ]
747
+ },
748
+ item.trackingId
749
+ )) }) : /* @__PURE__ */ jsx5("section", { "data-funnel": "variants", hidden: !product2.variantDefinitions.length, children: /* @__PURE__ */ jsx5(VariantChips, { definitions: product2.variantDefinitions }) }),
750
+ /* @__PURE__ */ jsxs2("section", { className: "cs-qty", "data-funnel": "qty", children: [
751
+ /* @__PURE__ */ jsx5("button", { type: "button", "data-qty": "-1", children: "-" }),
752
+ /* @__PURE__ */ jsx5("span", { className: "cs-qty__value", "data-qty-value": "", children: "1" }),
753
+ /* @__PURE__ */ jsx5("button", { type: "button", "data-qty": "1", children: "+" })
754
+ ] })
755
+ ] })
756
+ ] });
757
+ }
758
+ function Totals() {
759
+ return /* @__PURE__ */ jsxs2("div", { className: "cs-totals", "data-funnel": "totals", children: [
760
+ /* @__PURE__ */ jsx5("p", { className: "cs-section-title", "data-i18n": "orderSummary" }),
761
+ /* @__PURE__ */ jsxs2("div", { className: "cs-totals__row", children: [
762
+ /* @__PURE__ */ jsx5("span", { "data-i18n": "productsPrice" }),
763
+ /* @__PURE__ */ jsx5("strong", { "data-total": "products" })
764
+ ] }),
765
+ /* @__PURE__ */ jsxs2("div", { className: "cs-totals__row", children: [
766
+ /* @__PURE__ */ jsx5("span", { "data-i18n": "shippingPrice" }),
767
+ /* @__PURE__ */ jsx5("strong", { "data-total": "shipping" })
768
+ ] }),
769
+ /* @__PURE__ */ jsxs2("div", { className: "cs-totals__row cs-totals__row--total", children: [
770
+ /* @__PURE__ */ jsx5("span", { "data-i18n": "total" }),
771
+ /* @__PURE__ */ jsx5("strong", { "data-total": "grand" })
772
+ ] })
773
+ ] });
774
+ }
775
+ function fieldAutocomplete(type) {
776
+ if (type === "phone") return "tel";
777
+ if (type === "name") return "name";
778
+ if (type === "address") return "street-address";
779
+ return "on";
780
+ }
781
+ function FormField({ data, type }) {
782
+ if (type === "state") {
783
+ return /* @__PURE__ */ jsxs2("select", { name: "state", "data-field": "state", children: [
784
+ /* @__PURE__ */ jsx5("option", { value: "" }),
785
+ data.geo.states.map((state) => /* @__PURE__ */ jsx5(
786
+ "option",
787
+ {
788
+ value: state.id,
789
+ "data-code": state.code,
790
+ "data-name": state.name,
791
+ "data-name-ar": state.nameAr,
792
+ children: placeLabel(state)
793
+ },
794
+ state.id
795
+ ))
796
+ ] });
797
+ }
798
+ if (type === "city") {
799
+ return /* @__PURE__ */ jsxs2("select", { name: "city", "data-field": "city", children: [
800
+ /* @__PURE__ */ jsx5("option", { value: "" }),
801
+ (data.lazyCities ? [] : data.geo.cities).map((city) => /* @__PURE__ */ jsx5(
802
+ "option",
803
+ {
804
+ value: city.id,
805
+ "data-code": city.code,
806
+ "data-state": city.stateId,
807
+ "data-name": city.name,
808
+ "data-name-ar": city.nameAr,
809
+ children: placeLabel(city)
810
+ },
811
+ city.id
812
+ ))
813
+ ] });
814
+ }
815
+ return /* @__PURE__ */ jsx5(
816
+ "input",
817
+ {
818
+ type: type === "phone" ? "tel" : "text",
819
+ name: type,
820
+ "data-field": type,
821
+ autoComplete: fieldAutocomplete(type)
822
+ }
823
+ );
824
+ }
825
+ var PrivacyLink = "https://policies.google.com/privacy";
826
+ var TermsLink = "https://policies.google.com/terms";
827
+ function RecaptchaNotice({ language }) {
828
+ const link = (href, label) => /* @__PURE__ */ jsx5("a", { href, target: "_blank", rel: "noopener noreferrer", children: label });
829
+ if (language === "ar") {
830
+ return /* @__PURE__ */ jsxs2("p", { className: "cs-recaptcha", children: [
831
+ "\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 ",
832
+ link(PrivacyLink, "\u0633\u064A\u0627\u0633\u0629 \u0627\u0644\u062E\u0635\u0648\u0635\u064A\u0629"),
833
+ " \u0648",
834
+ " ",
835
+ link(TermsLink, "\u0634\u0631\u0648\u0637 \u0627\u0644\u062E\u062F\u0645\u0629"),
836
+ " \u0627\u0644\u062E\u0627\u0635\u0629 \u0628\u0640 Google."
837
+ ] });
838
+ }
839
+ if (language === "fr") {
840
+ return /* @__PURE__ */ jsxs2("p", { className: "cs-recaptcha", children: [
841
+ "Ce site est prot\xE9g\xE9 par reCAPTCHA et les",
842
+ " ",
843
+ link(PrivacyLink, "r\xE8gles de confidentialit\xE9"),
844
+ " et",
845
+ " ",
846
+ link(TermsLink, "conditions d'utilisation"),
847
+ " de Google s'appliquent."
848
+ ] });
849
+ }
850
+ return /* @__PURE__ */ jsxs2("p", { className: "cs-recaptcha", children: [
851
+ "This site is protected by reCAPTCHA and the Google ",
852
+ link(PrivacyLink, "Privacy Policy"),
853
+ " ",
854
+ "and ",
855
+ link(TermsLink, "Terms of Service"),
856
+ " apply."
857
+ ] });
858
+ }
859
+ function OrderFormView(props) {
860
+ var _a;
861
+ const data = useCheckoutData();
862
+ return /* @__PURE__ */ jsxs2("form", { ...blockRoot(props, "cs-form"), "data-funnel": "form", children: [
863
+ props.includeCatalog ? /* @__PURE__ */ jsx5(Catalog, { data }) : null,
864
+ data.funnel.form.fields.filter((field) => field.enabled).map((field) => /* @__PURE__ */ jsxs2(
865
+ "div",
866
+ {
867
+ className: "cs-field",
868
+ "data-funnel-field": field.type,
869
+ "data-required": String(field.required),
870
+ children: [
871
+ /* @__PURE__ */ jsx5("label", { "data-i18n": field.type }),
872
+ /* @__PURE__ */ jsx5(FormField, { data, type: field.type }),
873
+ /* @__PURE__ */ jsx5("div", { className: "cs-field__error", "data-error": "" })
874
+ ]
875
+ },
876
+ field.type
877
+ )),
878
+ ((_a = data.deliveryPrices) == null ? void 0 : _a.stopdeskEnabled) ? /* @__PURE__ */ jsxs2("div", { className: "cs-ship", "data-funnel": "shipping-method", children: [
879
+ /* @__PURE__ */ jsx5(
880
+ "button",
881
+ {
882
+ type: "button",
883
+ className: "cs-chip is-active",
884
+ "data-ship": "home",
885
+ "data-i18n": "homeDelivery"
886
+ }
887
+ ),
888
+ /* @__PURE__ */ jsx5(
889
+ "button",
890
+ {
891
+ type: "button",
892
+ className: "cs-chip",
893
+ "data-ship": "stopdesk",
894
+ "data-i18n": "stopDesk"
895
+ }
896
+ )
897
+ ] }) : null,
898
+ /* @__PURE__ */ jsx5(Totals, {}),
899
+ /* @__PURE__ */ jsx5("button", { type: "submit", className: "cs-submit", "data-i18n": "orderNow" }),
900
+ data.api.recaptchaSiteKey ? /* @__PURE__ */ jsx5(RecaptchaNotice, { language: data.funnel.language }) : null
901
+ ] });
902
+ }
903
+ var ProductCatalog = defineBlock({
904
+ type: "ProductCatalog",
905
+ label: "Offers and variants",
906
+ 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.",
907
+ category: "checkout",
908
+ schema: z6.object({}),
909
+ fields: {},
910
+ render: function ProductCatalog2(props) {
911
+ const data = useCheckoutData();
912
+ return /* @__PURE__ */ jsx5("div", { ...blockRoot(props), children: /* @__PURE__ */ jsx5(Catalog, { data }) });
913
+ }
914
+ });
915
+ var OrderForm = defineBlock({
916
+ type: "OrderForm",
917
+ label: "Order form",
918
+ 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.",
919
+ category: "checkout",
920
+ schema: z6.object({
921
+ includeCatalog: z6.boolean().default(true)
922
+ }),
923
+ fields: {
924
+ includeCatalog: {
925
+ type: "radio",
926
+ label: "Show offers and variants in the form",
927
+ options: [
928
+ { label: "Yes", value: true },
929
+ { label: "No", value: false }
930
+ ]
931
+ }
932
+ },
933
+ render: (props) => /* @__PURE__ */ jsx5(OrderFormView, { ...props })
934
+ });
935
+
936
+ // src/blocks/store.tsx
937
+ import { z as z7 } from "zod";
938
+
939
+ // src/money.ts
940
+ function moneyFormatter({
941
+ language,
942
+ iso2,
943
+ currency
944
+ }) {
945
+ const options = {
946
+ style: "currency",
947
+ currency,
948
+ currencyDisplay: "symbol",
949
+ minimumFractionDigits: 0,
950
+ maximumFractionDigits: 2
951
+ };
952
+ const country = iso2.toUpperCase();
953
+ const part = (locale2) => {
954
+ var _a, _b;
955
+ return (_b = (_a = new Intl.NumberFormat(locale2, options).formatToParts(0).find((p) => p.type === "currency")) == null ? void 0 : _a.value) != null ? _b : "";
956
+ };
957
+ const isCode = (symbol2) => symbol2.replace(/\./g, "").toUpperCase() === currency.toUpperCase();
958
+ const locale = `${language}-${country}`;
959
+ const formatter = new Intl.NumberFormat(locale, options);
960
+ const symbol = [locale, `fr-${country}`, `ar-${country}`].map(part).find((item) => !isCode(item));
961
+ return (value) => formatter.formatToParts(value).map((item) => item.type === "currency" ? symbol != null ? symbol : item.value : item.value).join("");
962
+ }
963
+
964
+ // src/blocks/store.tsx
965
+ import { jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
966
+ var LabelKeys = [
967
+ "bestSellers",
968
+ "newArrivals",
969
+ "shopByCategory",
970
+ "youMayAlsoLike",
971
+ "categories",
972
+ "allProducts",
973
+ "cod"
974
+ ];
975
+ var LabelKeySchema = z7.enum(LabelKeys);
976
+ var labelOptions = LabelKeys.map((key) => ({ label: key, value: key }));
977
+ var TextSchema = z7.string().max(300);
978
+ function heading(store, text, label) {
979
+ return text || store.labels[label];
980
+ }
981
+ var MenuIcon = /* @__PURE__ */ jsx6(
982
+ "svg",
983
+ {
984
+ viewBox: "0 0 24 24",
985
+ width: "22",
986
+ height: "22",
987
+ fill: "none",
988
+ stroke: "currentColor",
989
+ strokeWidth: "1.8",
990
+ strokeLinecap: "round",
991
+ "aria-hidden": "true",
992
+ children: /* @__PURE__ */ jsx6("path", { d: "M3 6h18M3 12h18M3 18h18" })
993
+ }
994
+ );
995
+ var SearchIcon = /* @__PURE__ */ jsxs3(
996
+ "svg",
997
+ {
998
+ viewBox: "0 0 24 24",
999
+ width: "22",
1000
+ height: "22",
1001
+ fill: "none",
1002
+ stroke: "currentColor",
1003
+ strokeWidth: "1.8",
1004
+ strokeLinecap: "round",
1005
+ "aria-hidden": "true",
1006
+ children: [
1007
+ /* @__PURE__ */ jsx6("circle", { cx: "11", cy: "11", r: "7" }),
1008
+ /* @__PURE__ */ jsx6("path", { d: "m20 20-3.5-3.5" })
1009
+ ]
1010
+ }
1011
+ );
1012
+ function ProductCard({
1013
+ item,
1014
+ position,
1015
+ list,
1016
+ money
1017
+ }) {
1018
+ var _a;
1019
+ return /* @__PURE__ */ jsxs3(
1020
+ "a",
1021
+ {
1022
+ className: "card",
1023
+ href: item.url,
1024
+ "data-product-card": "",
1025
+ "data-category": (_a = item.categoryId) != null ? _a : "",
1026
+ "data-price": item.fromPrice,
1027
+ "data-name": item.product.name,
1028
+ "data-position": position,
1029
+ "data-track": "product",
1030
+ "data-product-id": item.product.trackingId,
1031
+ "data-list": list,
1032
+ children: [
1033
+ /* @__PURE__ */ jsxs3("div", { className: "card__media", children: [
1034
+ item.cardImage ? /* @__PURE__ */ jsx6(
1035
+ "img",
1036
+ {
1037
+ className: "card__image",
1038
+ src: item.cardImage,
1039
+ alt: item.product.name,
1040
+ loading: "lazy",
1041
+ decoding: "async"
1042
+ }
1043
+ ) : null,
1044
+ item.cardHoverImage ? /* @__PURE__ */ jsx6(
1045
+ "img",
1046
+ {
1047
+ className: "card__hover",
1048
+ src: item.cardHoverImage,
1049
+ alt: "",
1050
+ loading: "lazy",
1051
+ decoding: "async"
1052
+ }
1053
+ ) : null,
1054
+ item.discountPercent ? /* @__PURE__ */ jsx6("span", { className: "card__badge", children: `-${item.discountPercent}%` }) : null
1055
+ ] }),
1056
+ /* @__PURE__ */ jsxs3("div", { className: "card__body", children: [
1057
+ /* @__PURE__ */ jsx6("h3", { className: "card__name", children: item.product.name }),
1058
+ /* @__PURE__ */ jsxs3("p", { className: "card__price", children: [
1059
+ /* @__PURE__ */ jsx6("span", { children: money(item.fromPrice) }),
1060
+ item.compareAtPrice ? /* @__PURE__ */ jsx6("s", { children: money(item.compareAtPrice) }) : null
1061
+ ] })
1062
+ ] })
1063
+ ]
1064
+ }
1065
+ );
1066
+ }
1067
+ function SectionHead({ title, viewAll }) {
1068
+ return /* @__PURE__ */ jsxs3("div", { className: "section-head", children: [
1069
+ /* @__PURE__ */ jsx6("h2", { children: title }),
1070
+ viewAll ? /* @__PURE__ */ jsx6("a", { href: "/products", children: viewAll }) : null
1071
+ ] });
1072
+ }
1073
+ var CategoryItemStyles = ["card", "pill", "tag", "chip", "link", "room"];
1074
+ function CategoryItem({
1075
+ entry,
1076
+ itemStyle
1077
+ }) {
1078
+ const track = { "data-track": "category", "data-category-id": entry.trackingId };
1079
+ if (itemStyle === "card") {
1080
+ return /* @__PURE__ */ jsxs3("a", { className: "category", href: entry.url, ...track, children: [
1081
+ /* @__PURE__ */ jsx6("span", { className: "category__media", children: /* @__PURE__ */ jsx6("img", { src: entry.imageUrl, alt: entry.name, loading: "lazy", decoding: "async" }) }),
1082
+ /* @__PURE__ */ jsx6("span", { className: "category__name", children: entry.name })
1083
+ ] });
1084
+ }
1085
+ if (itemStyle === "chip") {
1086
+ return /* @__PURE__ */ jsxs3("a", { className: "chip-link", href: entry.url, ...track, children: [
1087
+ /* @__PURE__ */ jsx6("img", { src: entry.imageUrl, alt: "", loading: "lazy", decoding: "async" }),
1088
+ entry.name
1089
+ ] });
1090
+ }
1091
+ if (itemStyle === "room") {
1092
+ return /* @__PURE__ */ jsxs3("a", { className: "room", href: entry.url, ...track, children: [
1093
+ /* @__PURE__ */ jsx6("img", { src: entry.imageUrl, alt: entry.name, loading: "lazy", decoding: "async" }),
1094
+ /* @__PURE__ */ jsx6("span", { children: entry.name })
1095
+ ] });
1096
+ }
1097
+ return /* @__PURE__ */ jsx6("a", { className: itemStyle === "link" ? void 0 : itemStyle, href: entry.url, ...track, children: entry.name });
1098
+ }
1099
+ function trimmed(value, characters) {
1100
+ return (value != null ? value : "").split("").filter((character) => !characters.includes(character)).join("");
1101
+ }
1102
+ var AnnouncementBar = defineBlock({
1103
+ type: "AnnouncementBar",
1104
+ label: "Announcement bar",
1105
+ description: "The thin bar above the header with the announcement text from the store settings. Renders nothing when the announcement is off.",
1106
+ category: "store",
1107
+ schema: z7.object({}),
1108
+ fields: {},
1109
+ render: function AnnouncementBar2(props) {
1110
+ const { onlineStore } = useStoreData();
1111
+ if (!onlineStore.announcementBarEnabled || !onlineStore.announcementBarText) return null;
1112
+ return /* @__PURE__ */ jsx6("div", { ...blockRoot(props, "announcement"), children: onlineStore.announcementBarText });
1113
+ }
1114
+ });
1115
+ var StoreHeader = defineBlock({
1116
+ type: "StoreHeader",
1117
+ label: "Header",
1118
+ description: "The store navbar: menu button, logo, links to home, all products, the first categories and contact, the search link, and the mobile menu.",
1119
+ category: "store",
1120
+ schema: z7.object({
1121
+ navCategories: z7.number().int().min(0).max(12).default(4)
1122
+ }),
1123
+ fields: {
1124
+ navCategories: { type: "number", label: "Categories in the navbar" }
1125
+ },
1126
+ render: function StoreHeader2(props) {
1127
+ const { labels: t, onlineStore, categories: categories2 } = useStoreData();
1128
+ return /* @__PURE__ */ jsxs3("header", { ...blockRoot(props, "head"), children: [
1129
+ /* @__PURE__ */ jsxs3("div", { className: "head__bar", children: [
1130
+ /* @__PURE__ */ jsx6(
1131
+ "button",
1132
+ {
1133
+ className: "head__icon head__menu",
1134
+ type: "button",
1135
+ "data-store": "menu-toggle",
1136
+ "aria-label": t.menu,
1137
+ "aria-expanded": "false",
1138
+ children: MenuIcon
1139
+ }
1140
+ ),
1141
+ /* @__PURE__ */ jsx6("a", { className: "logo", href: "/", children: onlineStore.logoUrl ? /* @__PURE__ */ jsx6("img", { src: onlineStore.logoUrl, alt: onlineStore.name }) : onlineStore.name }),
1142
+ /* @__PURE__ */ jsxs3("nav", { className: "head__nav", "aria-label": t.menu, children: [
1143
+ /* @__PURE__ */ jsx6("a", { href: "/", children: t.home }),
1144
+ /* @__PURE__ */ jsx6("a", { href: "/products", children: t.allProducts }),
1145
+ categories2.slice(0, props.navCategories).map((entry) => /* @__PURE__ */ jsx6("a", { href: entry.url, children: entry.name }, entry.trackingId)),
1146
+ /* @__PURE__ */ jsx6("a", { href: "/contact", children: t.contact })
1147
+ ] }),
1148
+ /* @__PURE__ */ jsx6("a", { className: "head__icon head__search", href: "/products", "aria-label": t.search, children: SearchIcon })
1149
+ ] }),
1150
+ /* @__PURE__ */ jsxs3("nav", { className: "menu", "data-store": "menu", hidden: true, "aria-label": t.menu, children: [
1151
+ /* @__PURE__ */ jsx6("a", { href: "/", children: t.home }),
1152
+ /* @__PURE__ */ jsx6("a", { href: "/products", children: t.allProducts }),
1153
+ categories2.map((entry) => /* @__PURE__ */ jsx6("a", { href: entry.url, children: entry.name }, entry.trackingId)),
1154
+ /* @__PURE__ */ jsx6("a", { href: "/about", children: t.about }),
1155
+ /* @__PURE__ */ jsx6("a", { href: "/contact", children: t.contact })
1156
+ ] })
1157
+ ] });
1158
+ }
1159
+ });
1160
+ var StoreFooter = defineBlock({
1161
+ type: "StoreFooter",
1162
+ label: "Footer",
1163
+ description: "The store footer: name and tagline, shop links with the first categories, help and policy links, social links, and the copyright line.",
1164
+ category: "store",
1165
+ schema: z7.object({
1166
+ footerCategories: z7.number().int().min(0).max(12).default(5)
1167
+ }),
1168
+ fields: {
1169
+ footerCategories: { type: "number", label: "Categories in the footer" }
1170
+ },
1171
+ render: function StoreFooter2(props) {
1172
+ const { labels: t, onlineStore, categories: categories2 } = useStoreData();
1173
+ const { contact: contact2 } = onlineStore;
1174
+ const social = { rel: "noopener noreferrer", target: "_blank" };
1175
+ return /* @__PURE__ */ jsxs3("footer", { ...blockRoot(props, "foot"), children: [
1176
+ /* @__PURE__ */ jsxs3("div", { className: "foot__inner", children: [
1177
+ /* @__PURE__ */ jsxs3("div", { className: "foot__brand", children: [
1178
+ /* @__PURE__ */ jsx6("a", { className: "logo", href: "/", children: onlineStore.name }),
1179
+ onlineStore.tagline ? /* @__PURE__ */ jsx6("p", { children: onlineStore.tagline }) : null
1180
+ ] }),
1181
+ /* @__PURE__ */ jsxs3("div", { children: [
1182
+ /* @__PURE__ */ jsx6("h4", { children: t.shop }),
1183
+ /* @__PURE__ */ jsx6("a", { href: "/products", children: t.allProducts }),
1184
+ categories2.slice(0, props.footerCategories).map((entry) => /* @__PURE__ */ jsx6("a", { href: entry.url, children: entry.name }, entry.trackingId))
1185
+ ] }),
1186
+ /* @__PURE__ */ jsxs3("div", { children: [
1187
+ /* @__PURE__ */ jsx6("h4", { children: t.help }),
1188
+ /* @__PURE__ */ jsx6("a", { href: "/about", children: t.about }),
1189
+ /* @__PURE__ */ jsx6("a", { href: "/contact", children: t.contact }),
1190
+ /* @__PURE__ */ jsx6("a", { href: "/privacy-policy", children: t.privacyPolicy }),
1191
+ /* @__PURE__ */ jsx6("a", { href: "/refund-policy", children: t.refundPolicy }),
1192
+ /* @__PURE__ */ jsx6("a", { href: "/terms-of-service", children: t.termsOfService })
1193
+ ] }),
1194
+ contact2.facebook || contact2.instagram || contact2.tiktok ? /* @__PURE__ */ jsxs3("div", { children: [
1195
+ /* @__PURE__ */ jsx6("h4", { children: t.followUs }),
1196
+ contact2.facebook ? /* @__PURE__ */ jsx6("a", { href: contact2.facebook, ...social, children: "Facebook" }) : null,
1197
+ contact2.instagram ? /* @__PURE__ */ jsx6("a", { href: contact2.instagram, ...social, children: "Instagram" }) : null,
1198
+ contact2.tiktok ? /* @__PURE__ */ jsx6("a", { href: contact2.tiktok, ...social, children: "TikTok" }) : null
1199
+ ] }) : null
1200
+ ] }),
1201
+ /* @__PURE__ */ jsx6("p", { className: "foot__legal", children: `\xA9 ${onlineStore.name}. ${t.rights}` })
1202
+ ] });
1203
+ }
1204
+ });
1205
+ var StoreHeroTitle = defineBlock({
1206
+ type: "StoreHeroTitle",
1207
+ label: "Hero title",
1208
+ description: "The home page headline. Uses text when set, otherwise the hero title from the store settings, otherwise a default for the store language.",
1209
+ category: "store",
1210
+ schema: z7.object({ text: TextSchema.default("") }),
1211
+ fields: { text: { type: "text", label: "Text" } },
1212
+ render: function StoreHeroTitle2(props) {
1213
+ const { labels: t, onlineStore } = useStoreData();
1214
+ return /* @__PURE__ */ jsx6("h1", { ...blockRoot(props, "hero__title"), children: props.text || onlineStore.hero.title || t.heroTitle });
1215
+ }
1216
+ });
1217
+ var StoreHeroSubtitle = defineBlock({
1218
+ type: "StoreHeroSubtitle",
1219
+ label: "Hero subtitle",
1220
+ description: "The line under the home page headline. Uses text when set, otherwise the hero subtitle from the store settings, otherwise a default.",
1221
+ category: "store",
1222
+ schema: z7.object({ text: TextSchema.default("") }),
1223
+ fields: { text: { type: "textarea", label: "Text" } },
1224
+ render: function StoreHeroSubtitle2(props) {
1225
+ const { labels: t, onlineStore } = useStoreData();
1226
+ return /* @__PURE__ */ jsx6("p", { ...blockRoot(props, "hero__subtitle"), children: props.text || onlineStore.hero.subtitle || t.heroSubtitle });
1227
+ }
1228
+ });
1229
+ var StoreHeroButton = defineBlock({
1230
+ type: "StoreHeroButton",
1231
+ label: "Hero button",
1232
+ description: "The home page call to action. Links to all products. Uses label when set, otherwise the hero button label from the store settings.",
1233
+ category: "store",
1234
+ schema: z7.object({
1235
+ label: TextSchema.default(""),
1236
+ href: z7.string().max(500).regex(/^(https?:\/\/|\/|#)/, "A link must start with https://, / or #").default("/products")
1237
+ }),
1238
+ fields: {
1239
+ label: { type: "text", label: "Label" },
1240
+ href: { type: "text", label: "Link" }
1241
+ },
1242
+ render: function StoreHeroButton2(props) {
1243
+ const { labels: t, onlineStore } = useStoreData();
1244
+ return /* @__PURE__ */ jsx6("a", { ...blockRoot(props, "btn"), href: props.href, children: props.label || onlineStore.hero.ctaLabel || t.shopNow });
1245
+ }
1246
+ });
1247
+ var StoreHeroImage = defineBlock({
1248
+ type: "StoreHeroImage",
1249
+ label: "Hero image",
1250
+ description: "The hero image from the store settings, loaded first. Set frameClassName to wrap it in a div. Renders nothing when the store has no hero image.",
1251
+ category: "store",
1252
+ schema: z7.object({ frameClassName: ClassNameSchema.default("") }),
1253
+ fields: { frameClassName: { type: "text", label: "Frame class" } },
1254
+ preload: (_props, data) => {
1255
+ const imageUrl = storeData(data).onlineStore.hero.imageUrl;
1256
+ return imageUrl ? [imageUrl] : [];
1257
+ },
1258
+ render: function StoreHeroImage2(props) {
1259
+ const { onlineStore } = useStoreData();
1260
+ if (!onlineStore.hero.imageUrl) return null;
1261
+ const image = (attributes) => /* @__PURE__ */ jsx6(
1262
+ "img",
1263
+ {
1264
+ ...attributes,
1265
+ src: onlineStore.hero.imageUrl,
1266
+ alt: onlineStore.name,
1267
+ fetchPriority: "high",
1268
+ decoding: "async"
1269
+ }
1270
+ );
1271
+ if (props.frameClassName) {
1272
+ return /* @__PURE__ */ jsx6("div", { ...blockRoot(props, props.frameClassName), children: image({}) });
1273
+ }
1274
+ return image(blockRoot(props));
1275
+ }
1276
+ });
1277
+ var StoreCategories = defineBlock({
1278
+ type: "StoreCategories",
1279
+ label: "Categories",
1280
+ description: "The store categories as links. layout nav renders a nav list, layout section renders a titled section. Renders nothing when the store has no categories.",
1281
+ category: "store",
1282
+ schema: z7.object({
1283
+ layout: z7.enum(["nav", "section"]).default("section"),
1284
+ listClassName: ClassNameSchema.default("categories"),
1285
+ itemStyle: z7.enum(CategoryItemStyles).default("card"),
1286
+ title: TextSchema.default(""),
1287
+ titleLabel: LabelKeySchema.default("shopByCategory")
1288
+ }),
1289
+ fields: {
1290
+ layout: {
1291
+ type: "radio",
1292
+ label: "Layout",
1293
+ options: [
1294
+ { label: "List", value: "nav" },
1295
+ { label: "Titled section", value: "section" }
1296
+ ]
1297
+ },
1298
+ listClassName: { type: "text", label: "List class" },
1299
+ itemStyle: {
1300
+ type: "select",
1301
+ label: "Item style",
1302
+ options: CategoryItemStyles.map((style) => ({ label: style, value: style }))
1303
+ },
1304
+ title: { type: "text", label: "Title" },
1305
+ titleLabel: { type: "select", label: "Default title", options: labelOptions }
1306
+ },
1307
+ render: function StoreCategories2(props) {
1308
+ const store = useStoreData();
1309
+ if (!store.categories.length) return null;
1310
+ const items = store.categories.map((entry) => /* @__PURE__ */ jsx6(CategoryItem, { entry, itemStyle: props.itemStyle }, entry.trackingId));
1311
+ if (props.layout === "nav") {
1312
+ return /* @__PURE__ */ jsx6(
1313
+ "nav",
1314
+ {
1315
+ ...blockRoot(props, props.listClassName),
1316
+ "aria-label": store.labels.categories,
1317
+ children: items
1318
+ }
1319
+ );
1320
+ }
1321
+ return /* @__PURE__ */ jsxs3("section", { ...blockRoot(props, "section"), children: [
1322
+ /* @__PURE__ */ jsx6(SectionHead, { title: heading(store, props.title, props.titleLabel), viewAll: null }),
1323
+ /* @__PURE__ */ jsx6("div", { className: props.listClassName, children: items })
1324
+ ] });
1325
+ }
1326
+ });
1327
+ var StoreProductGrid = defineBlock({
1328
+ type: "StoreProductGrid",
1329
+ label: "Product grid",
1330
+ description: "A titled section of product cards. source home shows the featured products first, related shows products from the same category on a product page.",
1331
+ category: "store",
1332
+ schema: z7.object({
1333
+ source: z7.enum(["home", "related"]).default("home"),
1334
+ gridClassName: ClassNameSchema.default(""),
1335
+ title: TextSchema.default(""),
1336
+ titleLabel: LabelKeySchema.default("bestSellers"),
1337
+ viewAll: z7.boolean().default(true),
1338
+ hideWhenEmpty: z7.boolean().default(true)
1339
+ }),
1340
+ fields: {
1341
+ source: {
1342
+ type: "radio",
1343
+ label: "Products",
1344
+ options: [
1345
+ { label: "Home products", value: "home" },
1346
+ { label: "Related products", value: "related" }
1347
+ ]
1348
+ },
1349
+ gridClassName: { type: "text", label: "Grid class" },
1350
+ title: { type: "text", label: "Title" },
1351
+ titleLabel: { type: "select", label: "Default title", options: labelOptions },
1352
+ viewAll: {
1353
+ type: "radio",
1354
+ label: "View all link",
1355
+ options: [
1356
+ { label: "Yes", value: true },
1357
+ { label: "No", value: false }
1358
+ ]
1359
+ },
1360
+ hideWhenEmpty: {
1361
+ type: "radio",
1362
+ label: "Hide when empty",
1363
+ options: [
1364
+ { label: "Yes", value: true },
1365
+ { label: "No", value: false }
1366
+ ]
1367
+ }
1368
+ },
1369
+ render: function StoreProductGrid2(props) {
1370
+ var _a, _b;
1371
+ const store = useStoreData();
1372
+ const products2 = props.source === "related" ? (_b = (_a = store.productPage) == null ? void 0 : _a.related) != null ? _b : [] : store.homeProducts;
1373
+ if (props.hideWhenEmpty && !products2.length) return null;
1374
+ const money = moneyFormatter(store.money);
1375
+ return /* @__PURE__ */ jsxs3("section", { ...blockRoot(props, "section"), children: [
1376
+ /* @__PURE__ */ jsx6(
1377
+ SectionHead,
1378
+ {
1379
+ title: heading(store, props.title, props.titleLabel),
1380
+ viewAll: props.viewAll ? store.labels.viewAll : null
1381
+ }
1382
+ ),
1383
+ /* @__PURE__ */ jsx6("div", { className: `grid ${props.gridClassName}`, children: products2.map((item, index) => /* @__PURE__ */ jsx6(
1384
+ ProductCard,
1385
+ {
1386
+ item,
1387
+ position: index,
1388
+ list: props.source,
1389
+ money
1390
+ },
1391
+ item.url
1392
+ )) })
1393
+ ] });
1394
+ }
1395
+ });
1396
+ var TrustItems = [
1397
+ ["cod", "codText"],
1398
+ ["fastDelivery", "fastDeliveryText"],
1399
+ ["confirmed", "confirmedText"],
1400
+ ["easyReturns", "easyReturnsText"]
1401
+ ];
1402
+ var StoreTrust = defineBlock({
1403
+ type: "StoreTrust",
1404
+ label: "Trust badges",
1405
+ description: "Cash on delivery, fast delivery, phone confirmation and easy returns, in the store language. variant bento shows them as tiles.",
1406
+ category: "store",
1407
+ schema: z7.object({ variant: z7.enum(["list", "bento"]).default("list") }),
1408
+ fields: {
1409
+ variant: {
1410
+ type: "radio",
1411
+ label: "Style",
1412
+ options: [
1413
+ { label: "List", value: "list" },
1414
+ { label: "Tiles", value: "bento" }
1415
+ ]
1416
+ }
1417
+ },
1418
+ render: function StoreTrust2(props) {
1419
+ const { labels: t } = useStoreData();
1420
+ if (props.variant === "bento") {
1421
+ return /* @__PURE__ */ jsx6("section", { ...blockRoot(props, "bento"), style: { marginBlockStart: "8px" }, children: TrustItems.map(([title, text]) => /* @__PURE__ */ jsxs3("div", { className: "bento__tile", children: [
1422
+ /* @__PURE__ */ jsx6("strong", { children: t[title] }),
1423
+ t[text]
1424
+ ] }, title)) });
1425
+ }
1426
+ return /* @__PURE__ */ jsx6("section", { ...blockRoot(props, "trust"), children: TrustItems.map(([title, text]) => /* @__PURE__ */ jsxs3("div", { className: "trust__item", children: [
1427
+ /* @__PURE__ */ jsx6("strong", { children: t[title] }),
1428
+ /* @__PURE__ */ jsx6("span", { children: t[text] })
1429
+ ] }, title)) });
1430
+ }
1431
+ });
1432
+ var StoreTagline = defineBlock({
1433
+ type: "StoreTagline",
1434
+ label: "Tagline",
1435
+ description: "The store tagline from the settings, as a quote section. Renders nothing when the store has no tagline.",
1436
+ category: "store",
1437
+ schema: z7.object({}),
1438
+ fields: {},
1439
+ render: function StoreTagline2(props) {
1440
+ const { onlineStore } = useStoreData();
1441
+ if (!onlineStore.tagline) return null;
1442
+ return /* @__PURE__ */ jsx6("section", { ...blockRoot(props), children: /* @__PURE__ */ jsx6("p", { children: onlineStore.tagline }) });
1443
+ }
1444
+ });
1445
+ var StoreTicker = defineBlock({
1446
+ type: "StoreTicker",
1447
+ label: "Ticker",
1448
+ description: "A scrolling strip that repeats the given labels.",
1449
+ category: "store",
1450
+ schema: z7.object({
1451
+ labels: z7.array(LabelKeySchema).max(4).default(["newArrivals", "cod"]),
1452
+ repeat: z7.number().int().min(1).max(20).default(8)
1453
+ }),
1454
+ fields: {
1455
+ repeat: { type: "number", label: "Repeat" }
1456
+ },
1457
+ render: function StoreTicker2(props) {
1458
+ const { labels: t } = useStoreData();
1459
+ return /* @__PURE__ */ jsx6("div", { ...blockRoot(props, "ticker"), "aria-hidden": "true", children: /* @__PURE__ */ jsx6("div", { className: "ticker__track", children: Array.from(
1460
+ { length: props.repeat },
1461
+ (_, index) => props.labels.map((label) => /* @__PURE__ */ jsx6("span", { children: t[label] }, `${index}-${label}`))
1462
+ ) }) });
1463
+ }
1464
+ });
1465
+ var StoreSearch = defineBlock({
1466
+ type: "StoreSearch",
1467
+ label: "Search box",
1468
+ description: "A search field that opens all products filtered by the query.",
1469
+ category: "store",
1470
+ schema: z7.object({}),
1471
+ fields: {},
1472
+ render: function StoreSearch2(props) {
1473
+ const { labels: t } = useStoreData();
1474
+ return /* @__PURE__ */ jsx6("form", { ...blockRoot(props, "home-search"), action: "/products", role: "search", children: /* @__PURE__ */ jsx6("input", { type: "search", name: "q", placeholder: t.search, "aria-label": t.search }) });
1475
+ }
1476
+ });
1477
+ var Ornament = defineBlock({
1478
+ type: "Ornament",
1479
+ label: "Ornament",
1480
+ description: "An empty decorative element, drawn by its class and css.",
1481
+ category: "store",
1482
+ schema: z7.object({}),
1483
+ fields: {},
1484
+ render: (props) => /* @__PURE__ */ jsx6("div", { ...blockRoot(props), children: /* @__PURE__ */ jsx6("span", {}) })
1485
+ });
1486
+ var StorePageHeading = defineBlock({
1487
+ type: "StorePageHeading",
1488
+ label: "Page heading",
1489
+ description: "The page title. source listing shows the category or all products with the product count, contact shows the contact title and intro, article shows the page title.",
1490
+ category: "store",
1491
+ schema: z7.object({
1492
+ source: z7.enum(["listing", "contact", "article"]).default("listing"),
1493
+ title: TextSchema.default(""),
1494
+ text: TextSchema.default("")
1495
+ }),
1496
+ fields: {
1497
+ source: {
1498
+ type: "select",
1499
+ label: "Page",
1500
+ options: [
1501
+ { label: "Listing", value: "listing" },
1502
+ { label: "Contact", value: "contact" },
1503
+ { label: "Article", value: "article" }
1504
+ ]
1505
+ },
1506
+ title: { type: "text", label: "Title" },
1507
+ text: { type: "textarea", label: "Text" }
1508
+ },
1509
+ render: function StorePageHeading2(props) {
1510
+ var _a, _b;
1511
+ const store = useStoreData();
1512
+ const t = store.labels;
1513
+ if (props.source === "listing") {
1514
+ const listing2 = store.listing;
1515
+ const title = props.title || ((listing2 == null ? void 0 : listing2.category) ? listing2.category.name : t.allProducts);
1516
+ return /* @__PURE__ */ jsxs3("header", { ...blockRoot(props, "page-head"), children: [
1517
+ /* @__PURE__ */ jsx6("h1", { children: title }),
1518
+ /* @__PURE__ */ jsx6("p", { children: props.text || `${(_a = listing2 == null ? void 0 : listing2.products.length) != null ? _a : 0} ${t.productsCount}` })
1519
+ ] });
1520
+ }
1521
+ if (props.source === "contact") {
1522
+ return /* @__PURE__ */ jsxs3("header", { ...blockRoot(props, "page-head"), children: [
1523
+ /* @__PURE__ */ jsx6("h1", { children: props.title || t.contact }),
1524
+ /* @__PURE__ */ jsx6("p", { children: props.text || t.contactIntro })
1525
+ ] });
1526
+ }
1527
+ return /* @__PURE__ */ jsxs3("header", { ...blockRoot(props, "page-head"), children: [
1528
+ /* @__PURE__ */ jsx6("h1", { children: props.title || ((_b = store.article) == null ? void 0 : _b.title) }),
1529
+ props.text ? /* @__PURE__ */ jsx6("p", { children: props.text }) : null
1530
+ ] });
1531
+ }
1532
+ });
1533
+ var ListingToolbar = defineBlock({
1534
+ type: "ListingToolbar",
1535
+ label: "Listing toolbar",
1536
+ description: "Category filters (on all products only), the search field and the sort menu of a product listing.",
1537
+ category: "store",
1538
+ schema: z7.object({}),
1539
+ fields: {},
1540
+ render: function ListingToolbar2(props) {
1541
+ const { labels: t, categories: categories2, listing: listing2 } = useStoreData();
1542
+ return /* @__PURE__ */ jsxs3("div", { ...blockRoot(props, "toolbar"), children: [
1543
+ !(listing2 == null ? void 0 : listing2.category) && categories2.length ? /* @__PURE__ */ jsxs3("div", { className: "toolbar__filters", children: [
1544
+ /* @__PURE__ */ jsx6("button", { type: "button", className: "chip is-active", "data-filter-category": "", children: t.all }),
1545
+ categories2.map((entry) => /* @__PURE__ */ jsx6(
1546
+ "button",
1547
+ {
1548
+ type: "button",
1549
+ className: "chip",
1550
+ "data-filter-category": entry.trackingId,
1551
+ children: entry.name
1552
+ },
1553
+ entry.trackingId
1554
+ ))
1555
+ ] }) : null,
1556
+ /* @__PURE__ */ jsx6(
1557
+ "input",
1558
+ {
1559
+ className: "search-input",
1560
+ type: "search",
1561
+ "data-store": "search",
1562
+ placeholder: t.search,
1563
+ "aria-label": t.search
1564
+ }
1565
+ ),
1566
+ /* @__PURE__ */ jsxs3("select", { "data-store": "sort", "aria-label": t.sortBy, children: [
1567
+ /* @__PURE__ */ jsx6("option", { value: "position", children: t.sortFeatured }),
1568
+ /* @__PURE__ */ jsx6("option", { value: "price-asc", children: t.sortPriceAsc }),
1569
+ /* @__PURE__ */ jsx6("option", { value: "price-desc", children: t.sortPriceDesc })
1570
+ ] })
1571
+ ] });
1572
+ }
1573
+ });
1574
+ var ListingGrid = defineBlock({
1575
+ type: "ListingGrid",
1576
+ label: "Listing products",
1577
+ description: "The product cards of a listing page, filtered and sorted in the browser.",
1578
+ category: "store",
1579
+ schema: z7.object({}),
1580
+ fields: {},
1581
+ render: function ListingGrid2(props) {
1582
+ var _a, _b;
1583
+ const store = useStoreData();
1584
+ const money = moneyFormatter(store.money);
1585
+ return /* @__PURE__ */ jsx6("div", { ...blockRoot(props, "grid"), "data-store": "listing", children: ((_b = (_a = store.listing) == null ? void 0 : _a.products) != null ? _b : []).map((item, index) => /* @__PURE__ */ jsx6(
1586
+ ProductCard,
1587
+ {
1588
+ item,
1589
+ position: index,
1590
+ list: "listing",
1591
+ money
1592
+ },
1593
+ item.url
1594
+ )) });
1595
+ }
1596
+ });
1597
+ var ListingEmpty = defineBlock({
1598
+ type: "ListingEmpty",
1599
+ label: "No results",
1600
+ description: "The message shown when the listing filters match no product.",
1601
+ category: "store",
1602
+ schema: z7.object({ text: TextSchema.default("") }),
1603
+ fields: { text: { type: "text", label: "Text" } },
1604
+ render: function ListingEmpty2(props) {
1605
+ const { labels: t } = useStoreData();
1606
+ return /* @__PURE__ */ jsx6("p", { ...blockRoot(props, "empty"), "data-store": "empty", hidden: true, children: props.text || t.noProducts });
1607
+ }
1608
+ });
1609
+ var ListingLoadMore = defineBlock({
1610
+ type: "ListingLoadMore",
1611
+ label: "Load more",
1612
+ description: "The button that shows the next products of a long listing.",
1613
+ category: "store",
1614
+ schema: z7.object({ label: TextSchema.default("") }),
1615
+ fields: { label: { type: "text", label: "Label" } },
1616
+ render: function ListingLoadMore2(props) {
1617
+ const { labels: t } = useStoreData();
1618
+ return /* @__PURE__ */ jsx6("div", { ...blockRoot(props, "more"), "data-store": "load-more", hidden: true, children: /* @__PURE__ */ jsx6("button", { type: "button", className: "btn btn--ghost", children: props.label || t.loadMore }) });
1619
+ }
1620
+ });
1621
+ var StoreProductGallery = defineBlock({
1622
+ type: "StoreProductGallery",
1623
+ label: "Product gallery",
1624
+ description: "The product page images with thumbnails. The first image loads first.",
1625
+ category: "store",
1626
+ schema: z7.object({}),
1627
+ fields: {},
1628
+ preload: (_props, data) => {
1629
+ var _a, _b;
1630
+ return ((_b = (_a = storeData(data).productPage) == null ? void 0 : _a.gallery) != null ? _b : []).slice(0, 1);
1631
+ },
1632
+ render: function StoreProductGallery2(props) {
1633
+ var _a, _b;
1634
+ const store = useStoreData();
1635
+ const { product: product2 } = useCheckoutData();
1636
+ const gallery = (_b = (_a = store.productPage) == null ? void 0 : _a.gallery) != null ? _b : [];
1637
+ const name = product2.name;
1638
+ return /* @__PURE__ */ jsxs3("section", { ...blockRoot(props, "pdp__media"), "data-funnel": "lead-images", children: [
1639
+ gallery.length ? /* @__PURE__ */ jsx6(
1640
+ "img",
1641
+ {
1642
+ className: "pdp__main",
1643
+ "data-gallery-main": "",
1644
+ src: gallery[0],
1645
+ alt: name,
1646
+ fetchPriority: "high",
1647
+ decoding: "async"
1648
+ }
1649
+ ) : null,
1650
+ gallery.length > 1 ? /* @__PURE__ */ jsx6("div", { className: "pdp__thumbs", children: gallery.map((image, index) => /* @__PURE__ */ jsx6(
1651
+ "img",
1652
+ {
1653
+ src: image,
1654
+ alt: name,
1655
+ "data-gallery-thumb": "",
1656
+ className: index === 0 ? "is-active" : void 0,
1657
+ loading: index === 0 ? void 0 : "lazy",
1658
+ decoding: "async"
1659
+ },
1660
+ `${index}-${image}`
1661
+ )) }) : null
1662
+ ] });
1663
+ }
1664
+ });
1665
+ var StoreBreadcrumbs = defineBlock({
1666
+ type: "StoreBreadcrumbs",
1667
+ label: "Breadcrumbs",
1668
+ description: "Home and the product category above the product name.",
1669
+ category: "store",
1670
+ schema: z7.object({}),
1671
+ fields: {},
1672
+ render: function StoreBreadcrumbs2(props) {
1673
+ const { labels: t, productPage } = useStoreData();
1674
+ return /* @__PURE__ */ jsxs3("nav", { ...blockRoot(props, "crumbs"), "aria-label": t.menu, children: [
1675
+ /* @__PURE__ */ jsx6("a", { href: "/", children: t.home }),
1676
+ /* @__PURE__ */ jsx6("span", { children: "/" }),
1677
+ /* @__PURE__ */ jsx6("a", { href: "/products", children: (productPage == null ? void 0 : productPage.categoryName) || t.allProducts })
1678
+ ] });
1679
+ }
1680
+ });
1681
+ var StoreProductTitle = defineBlock({
1682
+ type: "StoreProductTitle",
1683
+ label: "Product name",
1684
+ description: "The product name on a store product page.",
1685
+ category: "store",
1686
+ schema: z7.object({}),
1687
+ fields: {},
1688
+ render: function StoreProductTitle2(props) {
1689
+ const { product: product2 } = useCheckoutData();
1690
+ return /* @__PURE__ */ jsx6("h1", { ...blockRoot(props, "pdp__title"), "data-funnel": "product-name", children: product2.name });
1691
+ }
1692
+ });
1693
+ var StoreProductPrice = defineBlock({
1694
+ type: "StoreProductPrice",
1695
+ label: "Product price",
1696
+ description: "The product price on a store product page. The checkout replaces it with the price of the chosen offer.",
1697
+ category: "store",
1698
+ schema: z7.object({}),
1699
+ fields: {},
1700
+ render: function StoreProductPrice2(props) {
1701
+ var _a, _b;
1702
+ const store = useStoreData();
1703
+ const money = moneyFormatter(store.money);
1704
+ return /* @__PURE__ */ jsxs3("div", { ...blockRoot(props, "cs-price"), "data-funnel": "price", children: [
1705
+ /* @__PURE__ */ jsx6("span", { className: "cs-price__current", "data-display-price": "", children: money((_b = (_a = store.productPage) == null ? void 0 : _a.price) != null ? _b : 0) }),
1706
+ /* @__PURE__ */ jsx6("span", { className: "cs-price__compare", "data-compare-price": "" })
1707
+ ] });
1708
+ }
1709
+ });
1710
+ var StoreProductDescription = defineBlock({
1711
+ type: "StoreProductDescription",
1712
+ label: "Product description",
1713
+ description: "The landing page images of the product, or its text description when it has no images. Renders nothing when it has neither.",
1714
+ category: "store",
1715
+ schema: z7.object({}),
1716
+ fields: {},
1717
+ render: function StoreProductDescription2(props) {
1718
+ const { product: product2, landingPage } = useCheckoutData();
1719
+ if (landingPage.images.length) {
1720
+ return /* @__PURE__ */ jsx6("section", { ...blockRoot(props, "pdp-images"), "data-funnel": "description", children: landingPage.images.map((image, index) => /* @__PURE__ */ jsx6(
1721
+ "img",
1722
+ {
1723
+ src: image,
1724
+ alt: product2.name,
1725
+ loading: "lazy",
1726
+ decoding: "async"
1727
+ },
1728
+ `${index}-${image}`
1729
+ )) });
1730
+ }
1731
+ if (!product2.description) return null;
1732
+ return /* @__PURE__ */ jsx6("section", { ...blockRoot(props, "pdp-text"), "data-funnel": "description", children: product2.description });
1733
+ }
1734
+ });
1735
+ var StoreProductFaq = defineBlock({
1736
+ type: "StoreProductFaq",
1737
+ label: "Product FAQ",
1738
+ description: "The product questions and answers. Renders nothing when there are none.",
1739
+ category: "store",
1740
+ schema: z7.object({}),
1741
+ fields: {},
1742
+ render: function StoreProductFaq2(props) {
1743
+ const { product: product2 } = useCheckoutData();
1744
+ if (!product2.faq.length) return null;
1745
+ return /* @__PURE__ */ jsx6("section", { ...blockRoot(props, "pdp-faq"), "data-funnel": "faq", children: product2.faq.map((entry, index) => /* @__PURE__ */ jsxs3("details", { children: [
1746
+ /* @__PURE__ */ jsx6("summary", { children: entry.question }),
1747
+ /* @__PURE__ */ jsx6("p", { children: entry.answer })
1748
+ ] }, index)) });
1749
+ }
1750
+ });
1751
+ var ContactDetails = defineBlock({
1752
+ type: "ContactDetails",
1753
+ label: "Contact details",
1754
+ description: "WhatsApp, phone, email and address from the store settings, each when set.",
1755
+ category: "store",
1756
+ schema: z7.object({}),
1757
+ fields: {},
1758
+ render: function ContactDetails2(props) {
1759
+ const { labels: t, onlineStore } = useStoreData();
1760
+ const { contact: contact2 } = onlineStore;
1761
+ return /* @__PURE__ */ jsxs3("div", { ...blockRoot(props, "contact__info"), children: [
1762
+ contact2.whatsapp ? /* @__PURE__ */ jsxs3("div", { className: "contact__row", children: [
1763
+ /* @__PURE__ */ jsx6("span", { children: t.whatsapp }),
1764
+ /* @__PURE__ */ jsx6(
1765
+ "a",
1766
+ {
1767
+ dir: "ltr",
1768
+ href: `https://wa.me/${trimmed(contact2.whatsapp, ["+", " "])}`,
1769
+ rel: "noopener noreferrer",
1770
+ target: "_blank",
1771
+ "data-track": "contact",
1772
+ "data-channel": "whatsapp",
1773
+ children: contact2.whatsapp
1774
+ }
1775
+ )
1776
+ ] }) : null,
1777
+ contact2.phone ? /* @__PURE__ */ jsxs3("div", { className: "contact__row", children: [
1778
+ /* @__PURE__ */ jsx6("span", { children: t.phone }),
1779
+ /* @__PURE__ */ jsx6(
1780
+ "a",
1781
+ {
1782
+ dir: "ltr",
1783
+ href: `tel:${trimmed(contact2.phone, [" "])}`,
1784
+ "data-track": "contact",
1785
+ "data-channel": "phone",
1786
+ children: contact2.phone
1787
+ }
1788
+ )
1789
+ ] }) : null,
1790
+ contact2.email ? /* @__PURE__ */ jsxs3("div", { className: "contact__row", children: [
1791
+ /* @__PURE__ */ jsx6("span", { children: t.email }),
1792
+ /* @__PURE__ */ jsx6(
1793
+ "a",
1794
+ {
1795
+ href: `mailto:${contact2.email}`,
1796
+ "data-track": "contact",
1797
+ "data-channel": "email",
1798
+ children: contact2.email
1799
+ }
1800
+ )
1801
+ ] }) : null,
1802
+ contact2.address ? /* @__PURE__ */ jsxs3("div", { className: "contact__row", children: [
1803
+ /* @__PURE__ */ jsx6("span", { children: t.address }),
1804
+ /* @__PURE__ */ jsx6("strong", { children: contact2.address })
1805
+ ] }) : null
1806
+ ] });
1807
+ }
1808
+ });
1809
+ var ContactFields = [
1810
+ { name: "name", label: "yourName", type: "text", autoComplete: "name" },
1811
+ { name: "phone", label: "yourPhone", type: "tel", autoComplete: "tel" },
1812
+ { name: "email", label: "yourEmail", type: "email", autoComplete: "email" }
1813
+ ];
1814
+ var ContactForm = defineBlock({
1815
+ type: "ContactForm",
1816
+ label: "Contact form",
1817
+ description: "The contact form (name, phone, optional email, message) with its success message. Messages reach the merchant inbox.",
1818
+ category: "store",
1819
+ schema: z7.object({}),
1820
+ fields: {},
1821
+ render: function ContactForm2(props) {
1822
+ const { labels: t } = useStoreData();
1823
+ return /* @__PURE__ */ jsxs3("div", { ...blockRoot(props), children: [
1824
+ /* @__PURE__ */ jsxs3("form", { className: "form", "data-store": "contact-form", noValidate: true, children: [
1825
+ ContactFields.map((field) => /* @__PURE__ */ jsxs3("div", { className: "field", "data-contact-wrap": "", children: [
1826
+ /* @__PURE__ */ jsx6("label", { htmlFor: `contact-${field.name}`, children: t[field.label] }),
1827
+ /* @__PURE__ */ jsx6(
1828
+ "input",
1829
+ {
1830
+ id: `contact-${field.name}`,
1831
+ name: field.name,
1832
+ type: field.type === "text" ? void 0 : field.type,
1833
+ autoComplete: field.autoComplete,
1834
+ "data-contact-field": field.name
1835
+ }
1836
+ ),
1837
+ /* @__PURE__ */ jsx6("p", { className: "field__error", "data-error": "" })
1838
+ ] }, field.name)),
1839
+ /* @__PURE__ */ jsxs3("div", { className: "field", "data-contact-wrap": "", children: [
1840
+ /* @__PURE__ */ jsx6("label", { htmlFor: "contact-message", children: t.yourMessage }),
1841
+ /* @__PURE__ */ jsx6(
1842
+ "textarea",
1843
+ {
1844
+ id: "contact-message",
1845
+ name: "message",
1846
+ "data-contact-field": "message"
1847
+ }
1848
+ ),
1849
+ /* @__PURE__ */ jsx6("p", { className: "field__error", "data-error": "" })
1850
+ ] }),
1851
+ /* @__PURE__ */ jsx6("p", { className: "form__error", "data-store": "contact-error", hidden: true }),
1852
+ /* @__PURE__ */ jsx6("button", { className: "btn", type: "submit", children: t.send })
1853
+ ] }),
1854
+ /* @__PURE__ */ jsxs3("div", { className: "notice", "data-store": "contact-success", hidden: true, children: [
1855
+ /* @__PURE__ */ jsx6("strong", { children: t.messageSent }),
1856
+ /* @__PURE__ */ jsx6("span", { children: t.messageSentText })
1857
+ ] })
1858
+ ] });
1859
+ }
1860
+ });
1861
+ var OrderRows = [
1862
+ ["offer", "offer", false],
1863
+ ["customer", "customer", false],
1864
+ ["phone", "phone", true],
1865
+ ["delivery", "state", false],
1866
+ ["city", "city", false],
1867
+ ["deliveryAddress", "address", false]
1868
+ ];
1869
+ var StoreThankYou = defineBlock({
1870
+ type: "StoreThankYou",
1871
+ label: "Thank you",
1872
+ description: "The thank-you message and the order summary the checkout fills in from the browser, with a link back to the products.",
1873
+ category: "store",
1874
+ schema: z7.object({
1875
+ title: TextSchema.default(""),
1876
+ text: TextSchema.default("")
1877
+ }),
1878
+ fields: {
1879
+ title: { type: "text", label: "Title" },
1880
+ text: { type: "textarea", label: "Text" }
1881
+ },
1882
+ render: function StoreThankYou2(props) {
1883
+ const { labels: t } = useStoreData();
1884
+ return /* @__PURE__ */ jsxs3("div", { ...blockRoot(props, "wrap"), "data-store": "thank-you", children: [
1885
+ /* @__PURE__ */ jsxs3("div", { className: "center", children: [
1886
+ /* @__PURE__ */ jsx6("h1", { children: props.title || t.thankYouTitle }),
1887
+ /* @__PURE__ */ jsx6("p", { children: props.text || t.thankYouText })
1888
+ ] }),
1889
+ /* @__PURE__ */ jsxs3("section", { className: "order", "data-store": "order-details", hidden: true, children: [
1890
+ /* @__PURE__ */ jsx6("h2", { children: t.orderDetails }),
1891
+ /* @__PURE__ */ jsxs3("div", { className: "order__product", children: [
1892
+ /* @__PURE__ */ jsx6("img", { "data-order-image": "", alt: "", hidden: true }),
1893
+ /* @__PURE__ */ jsx6("strong", { "data-order": "product" })
1894
+ ] }),
1895
+ OrderRows.map(([label, field, ltr]) => /* @__PURE__ */ jsxs3("div", { className: "order__row", "data-order-row": "", children: [
1896
+ /* @__PURE__ */ jsx6("span", { children: t[label] }),
1897
+ /* @__PURE__ */ jsx6("span", { "data-order": field, dir: ltr ? "ltr" : void 0 })
1898
+ ] }, field)),
1899
+ /* @__PURE__ */ jsxs3("div", { className: "order__row", children: [
1900
+ /* @__PURE__ */ jsx6("span", { children: t.productsPrice }),
1901
+ /* @__PURE__ */ jsx6("span", { "data-order": "products" })
1902
+ ] }),
1903
+ /* @__PURE__ */ jsxs3("div", { className: "order__row", children: [
1904
+ /* @__PURE__ */ jsx6("span", { children: t.delivery }),
1905
+ /* @__PURE__ */ jsx6("span", { "data-order": "shipping" })
1906
+ ] }),
1907
+ /* @__PURE__ */ jsxs3("div", { className: "order__row order__row--total", children: [
1908
+ /* @__PURE__ */ jsx6("span", { children: t.total }),
1909
+ /* @__PURE__ */ jsx6("span", { "data-order": "total" })
1910
+ ] })
1911
+ ] }),
1912
+ /* @__PURE__ */ jsx6("div", { className: "center", children: /* @__PURE__ */ jsx6("a", { className: "btn", href: "/products", children: t.keepShopping }) })
1913
+ ] });
1914
+ }
1915
+ });
1916
+ var StoreNotFound = defineBlock({
1917
+ type: "StoreNotFound",
1918
+ label: "Not found",
1919
+ description: "The message of the 404 page with a link back home.",
1920
+ category: "store",
1921
+ schema: z7.object({
1922
+ title: TextSchema.default(""),
1923
+ text: TextSchema.default("")
1924
+ }),
1925
+ fields: {
1926
+ title: { type: "text", label: "Title" },
1927
+ text: { type: "textarea", label: "Text" }
1928
+ },
1929
+ render: function StoreNotFound2(props) {
1930
+ const { labels: t } = useStoreData();
1931
+ return /* @__PURE__ */ jsxs3("div", { ...blockRoot(props, "center"), children: [
1932
+ /* @__PURE__ */ jsx6("h1", { children: props.title || t.notFoundTitle }),
1933
+ /* @__PURE__ */ jsx6("p", { children: props.text || t.notFoundText }),
1934
+ /* @__PURE__ */ jsx6("a", { className: "btn", href: "/", children: t.backHome })
1935
+ ] });
1936
+ }
1937
+ });
1938
+ var StoreArticle = defineBlock({
1939
+ type: "StoreArticle",
1940
+ label: "Page text",
1941
+ description: "The text of an about or policy page, written in the store settings. Headings and lists come from the settings text.",
1942
+ category: "store",
1943
+ schema: z7.object({}),
1944
+ fields: {},
1945
+ render: function StoreArticle2(props) {
1946
+ var _a;
1947
+ const { article: article2 } = useStoreData();
1948
+ return /* @__PURE__ */ jsx6(
1949
+ "article",
1950
+ {
1951
+ ...blockRoot(props, "article"),
1952
+ dangerouslySetInnerHTML: { __html: (_a = article2 == null ? void 0 : article2.html) != null ? _a : "" }
1953
+ }
1954
+ );
1955
+ }
1956
+ });
1957
+
1958
+ // src/blocks/index.ts
1959
+ var definitions = [
1960
+ Section,
1961
+ Stack,
1962
+ Columns,
1963
+ Heading,
1964
+ Text,
1965
+ Image,
1966
+ Button,
1967
+ Spacer,
1968
+ ProductTitle,
1969
+ ProductPrice,
1970
+ ProductTagline,
1971
+ ProductGallery,
1972
+ LandingImages,
1973
+ ProductDescription,
1974
+ ProductFaq,
1975
+ ProductCatalog,
1976
+ OrderForm,
1977
+ AnnouncementBar,
1978
+ StoreHeader,
1979
+ StoreFooter,
1980
+ StoreHeroTitle,
1981
+ StoreHeroSubtitle,
1982
+ StoreHeroButton,
1983
+ StoreHeroImage,
1984
+ StoreCategories,
1985
+ StoreProductGrid,
1986
+ StoreTrust,
1987
+ StoreTagline,
1988
+ StoreTicker,
1989
+ StoreSearch,
1990
+ Ornament,
1991
+ StorePageHeading,
1992
+ ListingToolbar,
1993
+ ListingGrid,
1994
+ ListingEmpty,
1995
+ ListingLoadMore,
1996
+ StoreProductGallery,
1997
+ StoreBreadcrumbs,
1998
+ StoreProductTitle,
1999
+ StoreProductPrice,
2000
+ StoreProductDescription,
2001
+ StoreProductFaq,
2002
+ ContactDetails,
2003
+ ContactForm,
2004
+ StoreThankYou,
2005
+ StoreNotFound,
2006
+ StoreArticle
2007
+ ];
2008
+ var blocks = Object.fromEntries(
2009
+ definitions.map((definition) => [definition.type, definition])
2010
+ );
2011
+
2012
+ // src/page.ts
2013
+ import { createElement as createElement4, Fragment as Fragment3 } from "react";
2014
+
2015
+ // src/validate.ts
2016
+ import { z as z8 } from "zod";
2017
+ var FontSchema = z8.object({
2018
+ family: z8.string().min(1).max(60).regex(/^[A-Za-z0-9 ]+$/, "A font family can only contain letters, digits and spaces"),
2019
+ weights: z8.array(z8.number().int().min(100).max(900)).max(9).default([400, 700])
2020
+ });
2021
+ var PageRootPropsSchema = z8.object({
2022
+ css: CssSchema.optional(),
2023
+ fonts: z8.array(FontSchema).max(4).optional()
2024
+ });
2025
+ var DocumentShapeSchema = z8.object({
2026
+ root: z8.object({ props: z8.unknown() }).default({ props: {} }),
2027
+ content: z8.array(z8.unknown())
2028
+ });
2029
+ function blockPropsSchema(definition) {
2030
+ return BaseBlockPropsSchema.extend(definition.schema.shape).extend(
2031
+ Object.fromEntries(
2032
+ definition.slots.map((slot) => [slot, z8.array(BlockNodeSchema).default([])])
2033
+ )
2034
+ );
2035
+ }
2036
+ function parsePageDocument(input) {
2037
+ var _a;
2038
+ const issues = [];
2039
+ const shape = DocumentShapeSchema.safeParse(input);
2040
+ if (!shape.success) {
2041
+ throw new PageDocumentError(toIssues(shape.error, ""));
2042
+ }
2043
+ const root = PageRootPropsSchema.safeParse((_a = shape.data.root.props) != null ? _a : {});
2044
+ if (!root.success) {
2045
+ issues.push(...toIssues(root.error, "root.props"));
2046
+ }
2047
+ const ids = /* @__PURE__ */ new Set();
2048
+ const content = parseNodes(shape.data.content, "content", ids, issues);
2049
+ if (issues.length) {
2050
+ throw new PageDocumentError(issues);
2051
+ }
2052
+ return { root: { props: root.data }, content };
2053
+ }
2054
+ function parseNodes(nodes, path, ids, issues) {
2055
+ const parsed = [];
2056
+ nodes.forEach((raw, index) => {
2057
+ const nodePath = `${path}[${index}]`;
2058
+ const node = BlockNodeSchema.safeParse(raw);
2059
+ if (!node.success) {
2060
+ issues.push(...toIssues(node.error, nodePath));
2061
+ return;
2062
+ }
2063
+ const definition = blocks[node.data.type];
2064
+ if (!definition) {
2065
+ issues.push({
2066
+ path: `${nodePath}.type`,
2067
+ message: `Unknown block type ${node.data.type}`
2068
+ });
2069
+ return;
2070
+ }
2071
+ if (ids.has(node.data.props.id)) {
2072
+ issues.push({
2073
+ path: `${nodePath}.props.id`,
2074
+ message: `The block id ${node.data.props.id} is used more than once`
2075
+ });
2076
+ }
2077
+ ids.add(node.data.props.id);
2078
+ const props = blockPropsSchema(definition).safeParse(node.data.props);
2079
+ if (!props.success) {
2080
+ issues.push(...toIssues(props.error, `${nodePath}.props`));
2081
+ return;
2082
+ }
2083
+ const values = props.data;
2084
+ for (const slot of definition.slots) {
2085
+ values[slot] = parseNodes(
2086
+ values[slot],
2087
+ `${nodePath}.props.${slot}`,
2088
+ ids,
2089
+ issues
2090
+ );
2091
+ }
2092
+ parsed.push({ type: definition.type, props: values });
2093
+ });
2094
+ return parsed;
2095
+ }
2096
+ function toIssues(error, prefix) {
2097
+ return error.issues.map((issue) => ({
2098
+ path: [prefix, ...issue.path.map(String)].filter(Boolean).join("."),
2099
+ message: issue.message
2100
+ }));
2101
+ }
2102
+ function walkBlocks(nodes, visit) {
2103
+ var _a, _b, _c;
2104
+ for (const node of nodes) {
2105
+ visit(node);
2106
+ for (const slot of (_b = (_a = blocks[node.type]) == null ? void 0 : _a.slots) != null ? _b : []) {
2107
+ walkBlocks((_c = node.props[slot]) != null ? _c : [], visit);
2108
+ }
2109
+ }
2110
+ }
2111
+ function countBlocks(document, type) {
2112
+ let count = 0;
2113
+ walkBlocks(document.content, (node) => {
2114
+ if (node.type === type) count += 1;
2115
+ });
2116
+ return count;
2117
+ }
2118
+
2119
+ // src/page.ts
2120
+ function BlockList({ nodes }) {
2121
+ return createElement4(
2122
+ Fragment3,
2123
+ null,
2124
+ nodes.map((node) => createElement4(BlockView, { key: node.props.id, node }))
2125
+ );
2126
+ }
2127
+ function BlockView({ node }) {
2128
+ const definition = blocks[node.type];
2129
+ if (!definition) return null;
2130
+ const slots = Object.fromEntries(
2131
+ definition.slots.map((slot) => {
2132
+ var _a;
2133
+ return [
2134
+ slot,
2135
+ createElement4(BlockList, { nodes: (_a = node.props[slot]) != null ? _a : [] })
2136
+ ];
2137
+ })
2138
+ );
2139
+ return createElement4(definition.render, { ...definition.defaultProps, ...node.props, slots });
2140
+ }
2141
+ function PageContent({
2142
+ document,
2143
+ data
2144
+ }) {
2145
+ return createElement4(PageDataProvider, {
2146
+ data,
2147
+ children: createElement4(BlockList, { nodes: document.content })
2148
+ });
2149
+ }
2150
+ function blockSelector(id) {
2151
+ return `[data-block="${id}"]`;
2152
+ }
2153
+ function pageCss(document) {
2154
+ var _a;
2155
+ const base = /* @__PURE__ */ new Set();
2156
+ const scoped = [];
2157
+ walkBlocks(document.content, (node) => {
2158
+ const definition = blocks[node.type];
2159
+ if (definition == null ? void 0 : definition.baseCss) base.add(definition.baseCss);
2160
+ const selector = blockSelector(node.props.id);
2161
+ scoped.push(styleToCss(selector, node.props.style));
2162
+ if (typeof node.props.css === "string" && node.props.css.trim()) {
2163
+ scoped.push(`${selector} { ${node.props.css} }`);
2164
+ }
2165
+ });
2166
+ return [...base, (_a = document.root.props.css) != null ? _a : "", ...scoped].filter(Boolean).join("\n");
2167
+ }
2168
+ function pagePreloadImages(document, data) {
2169
+ const images = [];
2170
+ walkBlocks(document.content, (node) => {
2171
+ const definition = blocks[node.type];
2172
+ if (definition == null ? void 0 : definition.preload) {
2173
+ images.push(...definition.preload({ ...definition.defaultProps, ...node.props }, data));
2174
+ }
2175
+ });
2176
+ return [...new Set(images)];
2177
+ }
2178
+ function pageFontStylesheets(document) {
2179
+ var _a;
2180
+ return ((_a = document.root.props.fonts) != null ? _a : []).map((font) => {
2181
+ var _a2;
2182
+ const family = encodeURIComponent(font.family).replace(/%20/g, "+");
2183
+ const weights = [...new Set((_a2 = font.weights) != null ? _a2 : [400, 700])].sort((a, b) => a - b).join(";");
2184
+ return `https://fonts.googleapis.com/css2?family=${family}:wght@${weights}&display=swap`;
2185
+ });
2186
+ }
2187
+
2188
+ // src/json-schema.ts
2189
+ import { z as z9 } from "zod";
2190
+ function pageJsonSchema() {
2191
+ return {
2192
+ 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).",
2193
+ root: z9.toJSONSchema(PageRootPropsSchema, { io: "input" }),
2194
+ blocks: Object.values(blocks).map((definition) => ({
2195
+ type: definition.type,
2196
+ label: definition.label,
2197
+ description: definition.description,
2198
+ category: definition.category,
2199
+ slots: definition.slots,
2200
+ props: z9.toJSONSchema(blockPropsSchema(definition), { io: "input" })
2201
+ }))
2202
+ };
2203
+ }
2204
+
2205
+ // src/templates/funnels.ts
2206
+ var FunnelTemplateIds = ["classic-product", "classic-landing"];
2207
+ function block(type, id, props = {}) {
2208
+ return { type, props: { id, ...props } };
2209
+ }
2210
+ function page(content) {
2211
+ return { root: { props: {} }, content };
2212
+ }
2213
+ function classicProduct() {
2214
+ return page([
2215
+ block("Section", "hero", {
2216
+ tag: "section",
2217
+ className: "cs-hero",
2218
+ content: [
2219
+ block("ProductGallery", "gallery"),
2220
+ block("Stack", "buy-box", {
2221
+ content: [
2222
+ block("ProductTitle", "product-name", { level: "h1" }),
2223
+ block("ProductPrice", "price"),
2224
+ block("ProductTagline", "tagline"),
2225
+ block("ProductCatalog", "catalog"),
2226
+ block("OrderForm", "order-form", { includeCatalog: false })
2227
+ ]
2228
+ })
2229
+ ]
2230
+ }),
2231
+ block("LandingImages", "landing-images", { eagerFirstImage: false }),
2232
+ block("ProductDescription", "description", { onlyWithoutLandingImages: true }),
2233
+ block("ProductFaq", "faq")
2234
+ ]);
2235
+ }
2236
+ function classicLanding(options) {
2237
+ const formOnTop = options.formPosition === "top";
2238
+ const order = block("Section", "order", {
2239
+ tag: "section",
2240
+ className: "cs-card",
2241
+ anchorId: "order",
2242
+ content: [
2243
+ block("ProductTitle", "product-name", { level: "h1" }),
2244
+ block("ProductPrice", "price"),
2245
+ block("OrderForm", "order-form", { includeCatalog: true })
2246
+ ]
2247
+ });
2248
+ const images = block("LandingImages", "landing-images", { eagerFirstImage: !formOnTop });
2249
+ const description = block("ProductDescription", "description", {
2250
+ onlyWithoutLandingImages: true
2251
+ });
2252
+ return page(formOnTop ? [order, images, description] : [images, order, description]);
2253
+ }
2254
+ function funnelTemplate(templateId, options) {
2255
+ if (templateId === "classic-product") return classicProduct();
2256
+ if (templateId === "classic-landing") return classicLanding(options);
2257
+ throw new Error(`Unknown funnel template ${templateId}`);
2258
+ }
2259
+
2260
+ // src/templates/online-stores.ts
2261
+ var OnlineStoreTemplateIds = [
2262
+ "maison",
2263
+ "atelier",
2264
+ "noor",
2265
+ "block",
2266
+ "glow",
2267
+ "oud",
2268
+ "circuit",
2269
+ "hearth",
2270
+ "pebble",
2271
+ "souq"
2272
+ ];
2273
+ var OnlineStorePageTypes = [
2274
+ "header",
2275
+ "footer",
2276
+ "home",
2277
+ "all-products",
2278
+ "category",
2279
+ "product",
2280
+ "thank-you",
2281
+ "contact",
2282
+ "about",
2283
+ "privacy-policy",
2284
+ "refund-policy",
2285
+ "terms-of-service",
2286
+ "not-found"
2287
+ ];
2288
+ function block2(type, id, props = {}) {
2289
+ return { type, props: { id, ...props } };
2290
+ }
2291
+ function page2(content) {
2292
+ return { root: { props: {} }, content };
2293
+ }
2294
+ function stack(id, className, content) {
2295
+ return block2("Stack", id, { className, content });
2296
+ }
2297
+ function section(id, className, content) {
2298
+ return block2("Section", id, { tag: "section", className, content });
2299
+ }
2300
+ function heroText() {
2301
+ return [
2302
+ block2("StoreHeroTitle", "hero-title"),
2303
+ block2("StoreHeroSubtitle", "hero-subtitle"),
2304
+ block2("StoreHeroButton", "hero-button")
2305
+ ];
2306
+ }
2307
+ function heroImage(className = "") {
2308
+ return block2("StoreHeroImage", "hero-image", className ? { className } : {});
2309
+ }
2310
+ function categories(props = {}) {
2311
+ return block2("StoreCategories", "categories", props);
2312
+ }
2313
+ function categoryNav(listClassName, itemStyle) {
2314
+ return categories({ layout: "nav", listClassName, itemStyle });
2315
+ }
2316
+ function products(titleLabel, gridClassName = "") {
2317
+ return block2("StoreProductGrid", "products", {
2318
+ source: "home",
2319
+ titleLabel,
2320
+ gridClassName,
2321
+ hideWhenEmpty: false
2322
+ });
2323
+ }
2324
+ function trust() {
2325
+ return block2("StoreTrust", "trust");
2326
+ }
2327
+ var homes = {
2328
+ maison: () => [
2329
+ section("hero", "hero", [
2330
+ heroImage("hero__image"),
2331
+ stack("hero-text", "hero__text", heroText())
2332
+ ]),
2333
+ stack("main", "wrap", [
2334
+ categories(),
2335
+ block2("StoreTagline", "story", { className: "story" }),
2336
+ products("bestSellers"),
2337
+ trust()
2338
+ ])
2339
+ ],
2340
+ atelier: () => [
2341
+ section("hero", "split", [
2342
+ stack("hero-text", "split__text", heroText()),
2343
+ stack("hero-media", "split__media", [heroImage()])
2344
+ ]),
2345
+ stack("main", "wrap", [
2346
+ categoryNav("pills", "pill"),
2347
+ products("newArrivals", "editorial"),
2348
+ block2("StoreTagline", "quote", { className: "quote" }),
2349
+ trust()
2350
+ ])
2351
+ ],
2352
+ noor: () => [
2353
+ section("hero", "arch-hero", [
2354
+ stack("hero-media", "arch", [heroImage()]),
2355
+ stack("hero-text", "arch-hero__text", heroText())
2356
+ ]),
2357
+ stack("main", "wrap", [categories(), products("newArrivals"), trust()])
2358
+ ],
2359
+ block: () => [
2360
+ block2("StoreTicker", "ticker", { labels: ["newArrivals", "cod"], repeat: 8 }),
2361
+ section("hero", "poster", [heroImage(), stack("hero-text", "poster__text", heroText())]),
2362
+ categoryNav("tags", "tag"),
2363
+ products("newArrivals", "wall"),
2364
+ trust()
2365
+ ],
2366
+ glow: () => [
2367
+ section("hero", "glow-hero", [
2368
+ heroImage(),
2369
+ stack("hero-text", "glow-hero__text", heroText())
2370
+ ]),
2371
+ stack("main", "wrap", [categoryNav("chips", "chip"), products("bestSellers"), trust()])
2372
+ ],
2373
+ oud: () => [
2374
+ section("hero", "oud-hero", [
2375
+ block2("StoreHeroImage", "hero-image", { frameClassName: "oud-hero__frame" }),
2376
+ ...heroText()
2377
+ ]),
2378
+ block2("Ornament", "rule", { className: "oud-rule" }),
2379
+ stack("main", "wrap", [categories(), products("bestSellers"), trust()])
2380
+ ],
2381
+ circuit: () => [
2382
+ section("hero", "stage", [
2383
+ stack("hero-text", "stage__text", heroText()),
2384
+ stack("hero-media", "stage__media", [heroImage()])
2385
+ ]),
2386
+ block2("StoreTrust", "trust", { variant: "bento" }),
2387
+ stack("main", "wrap", [categoryNav("chip-row", "link"), products("bestSellers")])
2388
+ ],
2389
+ hearth: () => [
2390
+ section("hero", "room-hero", [
2391
+ heroImage(),
2392
+ stack("hero-text", "room-hero__card", heroText())
2393
+ ]),
2394
+ stack("main", "wrap", [
2395
+ categories({ listClassName: "rooms", itemStyle: "room" }),
2396
+ products("bestSellers"),
2397
+ trust()
2398
+ ])
2399
+ ],
2400
+ pebble: () => [
2401
+ section("hero", "play-hero", [
2402
+ stack("hero-text", "play-hero__text", heroText()),
2403
+ stack("hero-media", "play-hero__media", [heroImage()])
2404
+ ]),
2405
+ stack("main", "wrap", [categories(), products("bestSellers"), trust()])
2406
+ ],
2407
+ souq: () => [
2408
+ stack("main", "wrap", [
2409
+ block2("StoreSearch", "search"),
2410
+ categoryNav("rail", "card"),
2411
+ section("promo", "promo", [
2412
+ heroImage("promo__image"),
2413
+ stack("promo-text", "promo__text", heroText())
2414
+ ]),
2415
+ products("bestSellers"),
2416
+ trust()
2417
+ ])
2418
+ ]
2419
+ };
2420
+ function listing() {
2421
+ return page2([
2422
+ stack("main", "wrap", [
2423
+ block2("StorePageHeading", "heading", { source: "listing" }),
2424
+ block2("ListingToolbar", "toolbar"),
2425
+ block2("ListingGrid", "products"),
2426
+ block2("ListingEmpty", "empty"),
2427
+ block2("ListingLoadMore", "load-more")
2428
+ ])
2429
+ ]);
2430
+ }
2431
+ function product() {
2432
+ return page2([
2433
+ stack("main", "wrap", [
2434
+ stack("product", "pdp", [
2435
+ block2("StoreProductGallery", "gallery"),
2436
+ section("buy-box", "pdp__info", [
2437
+ block2("StoreBreadcrumbs", "breadcrumbs"),
2438
+ block2("StoreProductTitle", "product-name"),
2439
+ block2("StoreProductPrice", "price"),
2440
+ block2("ProductTagline", "tagline"),
2441
+ block2("ProductCatalog", "catalog"),
2442
+ block2("OrderForm", "order-form", { includeCatalog: false })
2443
+ ])
2444
+ ]),
2445
+ block2("StoreProductDescription", "description"),
2446
+ block2("StoreProductFaq", "faq"),
2447
+ block2("StoreProductGrid", "related", {
2448
+ source: "related",
2449
+ titleLabel: "youMayAlsoLike"
2450
+ })
2451
+ ])
2452
+ ]);
2453
+ }
2454
+ function contact() {
2455
+ return page2([
2456
+ stack("main", "wrap", [
2457
+ block2("StorePageHeading", "heading", { source: "contact" }),
2458
+ stack("contact", "contact", [
2459
+ block2("ContactDetails", "details"),
2460
+ block2("ContactForm", "form")
2461
+ ])
2462
+ ])
2463
+ ]);
2464
+ }
2465
+ function article() {
2466
+ return page2([
2467
+ stack("main", "wrap", [
2468
+ block2("StorePageHeading", "heading", { source: "article" }),
2469
+ block2("StoreArticle", "text")
2470
+ ])
2471
+ ]);
2472
+ }
2473
+ function onlineStoreTemplate(templateId, pageType) {
2474
+ if (!OnlineStoreTemplateIds.includes(templateId)) {
2475
+ throw new Error(`Unknown online store template: ${templateId}`);
2476
+ }
2477
+ switch (pageType) {
2478
+ case "header":
2479
+ return page2([block2("AnnouncementBar", "announcement"), block2("StoreHeader", "header")]);
2480
+ case "footer":
2481
+ return page2([block2("StoreFooter", "footer")]);
2482
+ case "home":
2483
+ return page2(homes[templateId]());
2484
+ case "all-products":
2485
+ case "category":
2486
+ return listing();
2487
+ case "product":
2488
+ return product();
2489
+ case "thank-you":
2490
+ return page2([block2("StoreThankYou", "thank-you")]);
2491
+ case "contact":
2492
+ return contact();
2493
+ case "about":
2494
+ case "privacy-policy":
2495
+ case "refund-policy":
2496
+ case "terms-of-service":
2497
+ return article();
2498
+ case "not-found":
2499
+ return page2([stack("main", "wrap", [block2("StoreNotFound", "not-found")])]);
2500
+ default:
2501
+ throw new Error(`Unknown online store page type: ${pageType}`);
2502
+ }
2503
+ }
2504
+ function onlineStorePages(templateId) {
2505
+ return OnlineStorePageTypes.map((pageType) => ({
2506
+ pageType,
2507
+ document: onlineStoreTemplate(templateId, pageType)
2508
+ }));
2509
+ }
2510
+ export {
2511
+ BlockList,
2512
+ Breakpoints,
2513
+ FunnelTemplateIds,
2514
+ OnlineStorePageTypes,
2515
+ OnlineStoreTemplateIds,
2516
+ PageContent,
2517
+ PageDataProvider,
2518
+ PageDocumentError,
2519
+ StyleProperties,
2520
+ blockSelector,
2521
+ blocks,
2522
+ checkoutData,
2523
+ countBlocks,
2524
+ funnelTemplate,
2525
+ moneyFormatter,
2526
+ onlineStorePages,
2527
+ onlineStoreTemplate,
2528
+ pageCss,
2529
+ pageFontStylesheets,
2530
+ pageJsonSchema,
2531
+ pagePreloadImages,
2532
+ parsePageDocument,
2533
+ storeData,
2534
+ useCheckoutData,
2535
+ usePageData,
2536
+ useStoreData,
2537
+ walkBlocks
2538
+ };