@usethrottle/builder-react 0.4.3 → 0.5.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.
@@ -2,6 +2,76 @@ var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
4
 
5
+ // src/server/jsonld.ts
6
+ var CONTEXT = "https://schema.org";
7
+ var isHttp = (value) => typeof value === "string" && /^https?:\/\/[^\s]+$/iu.test(value);
8
+ function organizationJsonLd(input) {
9
+ const sameAs = (input.sameAs ?? []).filter(isHttp).slice(0, 10);
10
+ return {
11
+ "@context": CONTEXT,
12
+ "@type": "Organization",
13
+ name: input.name,
14
+ url: input.url,
15
+ ...isHttp(input.logo) ? { logo: input.logo } : {},
16
+ ...sameAs.length === 0 ? {} : { sameAs }
17
+ };
18
+ }
19
+ function webSiteJsonLd(input) {
20
+ const base = input.url.replace(/\/+$/u, "");
21
+ return {
22
+ "@context": CONTEXT,
23
+ "@type": "WebSite",
24
+ name: input.name,
25
+ url: input.url,
26
+ potentialAction: {
27
+ "@type": "SearchAction",
28
+ target: {
29
+ "@type": "EntryPoint",
30
+ urlTemplate: `${base}${input.searchPath ?? "/search"}?q={search_term_string}`
31
+ },
32
+ "query-input": "required name=search_term_string"
33
+ }
34
+ };
35
+ }
36
+ function breadcrumbJsonLd(items) {
37
+ return {
38
+ "@context": CONTEXT,
39
+ "@type": "BreadcrumbList",
40
+ itemListElement: items.map((item, index) => ({
41
+ "@type": "ListItem",
42
+ position: index + 1,
43
+ name: item.name,
44
+ item: item.url
45
+ }))
46
+ };
47
+ }
48
+ function faqJsonLd(items) {
49
+ return {
50
+ "@context": CONTEXT,
51
+ "@type": "FAQPage",
52
+ mainEntity: items.map((item) => ({
53
+ "@type": "Question",
54
+ name: item.question,
55
+ acceptedAnswer: { "@type": "Answer", text: item.answer }
56
+ }))
57
+ };
58
+ }
59
+ function localBusinessJsonLd(input) {
60
+ const hours = (input.openingHours ?? []).filter((line) => line !== "");
61
+ return {
62
+ "@context": CONTEXT,
63
+ "@type": input.type ?? "LocalBusiness",
64
+ name: input.name,
65
+ url: input.url,
66
+ address: input.address,
67
+ ...input.phone === void 0 || input.phone === "" ? {} : { telephone: input.phone },
68
+ ...hours.length === 0 ? {} : { openingHours: hours }
69
+ };
70
+ }
71
+ function jsonLdString(value) {
72
+ return JSON.stringify(value).replaceAll("<", "\\u003c");
73
+ }
74
+
5
75
  // src/data.ts
6
76
  import { walkNodes } from "@usethrottle/builder-schema";
7
77
 
@@ -75,7 +145,7 @@ async function resolveBindings(bindings, registry, ctx, options) {
75
145
  import { ANCHOR_RE as ANCHOR_RE2, anyCustomWidgetSnapshotSchema, sectionNodeSchema, walkNodes as walkNodes2 } from "@usethrottle/builder-schema";
76
146
 
77
147
  // src/node-wrapper.tsx
78
- import { ANCHOR_RE } from "@usethrottle/builder-schema";
148
+ import { ANCHOR_RE, cssClassSchema } from "@usethrottle/builder-schema";
79
149
  import { jsx } from "react/jsx-runtime";
80
150
  var CUSTOM_WIDGET_CONTAINMENT = {
81
151
  contain: "layout paint",
@@ -88,12 +158,14 @@ var PART_NAME = {
88
158
  widget: "builder-widget"
89
159
  };
90
160
  function NodeWrapper(props) {
91
- const { id, part, type, className, anchor, copyAnchor, custom, missing, attributes, edit, entrance, children } = props;
161
+ const { id, part: part2, type, anchor, copyAnchor, custom, missing, attributes, edit, entrance, children } = props;
92
162
  const Tag = props.as ?? "div";
163
+ const tokens = props.cssClass !== void 0 && cssClassSchema.safeParse(props.cssClass).success ? props.cssClass : [];
164
+ const className = tokens.length === 0 ? props.className : `${props.className} ${tokens.join(" ")}`;
93
165
  const handlers = edit === void 0 ? {} : {
94
166
  onClickCapture: (event) => {
95
- const target = event.target;
96
- if (target?.closest?.("a[href]") != null) event.preventDefault();
167
+ const target2 = event.target;
168
+ if (target2?.closest?.("a[href]") != null) event.preventDefault();
97
169
  },
98
170
  onClick: (event) => {
99
171
  event.stopPropagation();
@@ -114,7 +186,7 @@ function NodeWrapper(props) {
114
186
  {
115
187
  className,
116
188
  "data-b-id": id,
117
- "data-throttle-part": PART_NAME[part],
189
+ "data-throttle-part": PART_NAME[part2],
118
190
  ...type === void 0 ? {} : { "data-b-type": type },
119
191
  ...custom === true && type !== void 0 ? { "data-b-w": type } : {},
120
192
  ...missing === true ? { "data-b-missing": "" } : {},
@@ -243,10 +315,10 @@ function MissingSavedSection({ node }) {
243
315
 
244
316
  // src/load.ts
245
317
  function pageOf(raw, initialData) {
246
- const { document: document2, id: _id, slug, title, path, generation, pageType: _type, updatedAt: _updated, savedSections, code, ...meta } = raw;
318
+ const { document: document2, id: _id, slug: slug2, title, path, generation, pageType: _type, updatedAt: _updated, savedSections, code, ...meta } = raw;
247
319
  return {
248
320
  kind: "page",
249
- slug,
321
+ slug: slug2,
250
322
  title,
251
323
  path,
252
324
  generation,
@@ -340,7 +412,7 @@ function clientOf(options) {
340
412
  import { createRegistry } from "@usethrottle/builder-schema";
341
413
 
342
414
  // src/basics/index.ts
343
- import { BASIC_WIDGET_DEFINITIONS as BASIC_WIDGET_DEFINITIONS2 } from "@usethrottle/builder-schema";
415
+ import { BASIC_WIDGET_DEFINITIONS as BASIC_WIDGET_DEFINITIONS3 } from "@usethrottle/builder-schema";
344
416
 
345
417
  // src/basics/announcement.tsx
346
418
  import { useEffect, useState } from "react";
@@ -432,7 +504,7 @@ function Placeholder({ editMode, children }) {
432
504
  var ID_RE = /^[a-z0-9]{8,24}(-[a-z0-9]{8,24})?$/;
433
505
  var DEVICES = ["desktop", "tablet", "phone"];
434
506
  function defaultOf(type, key) {
435
- const def = BASIC_WIDGET_DEFINITIONS.find((d) => d.type === type);
507
+ const def = BASIC_WIDGET_DEFINITIONS.filter((d) => d.type === type).sort((a, b) => b.v - a.v)[0];
436
508
  return def?.settings.find((f) => f.key === key)?.default ?? null;
437
509
  }
438
510
  function enumCss(node, rules) {
@@ -586,8 +658,8 @@ var seen2 = /* @__PURE__ */ new WeakSet();
586
658
  var autoplay = /* @__PURE__ */ new Map();
587
659
  var all = (selector) => Array.from(document.querySelectorAll(selector));
588
660
  var reduced = () => window.matchMedia?.("(prefers-reduced-motion: reduce)").matches === true;
589
- function selectTab(list, index, focus = false) {
590
- const tabs = Array.from(list.querySelectorAll("[role=tab]"));
661
+ function selectTab(list2, index, focus = false) {
662
+ const tabs = Array.from(list2.querySelectorAll("[role=tab]"));
591
663
  tabs.forEach((tab, i) => {
592
664
  const on = i === index;
593
665
  tab.setAttribute("aria-selected", String(on));
@@ -661,7 +733,7 @@ function scan() {
661
733
  });
662
734
  document.documentElement.setAttribute("data-b-js", "");
663
735
  const fresh = (selector) => all(selector).filter((el) => !seen2.has(el) && seen2.add(el));
664
- fresh("[data-b-tabs]").forEach((list) => selectTab(list, 0));
736
+ fresh("[data-b-tabs]").forEach((list2) => selectTab(list2, 0));
665
737
  fresh("[data-b-car]").forEach((root) => setupCarousel(root));
666
738
  const counts = fresh("[data-b-cd]");
667
739
  counts.forEach((el) => tick(el, true));
@@ -695,30 +767,30 @@ var decoded = (hash) => {
695
767
  };
696
768
  var onHash = () => void goAnchor(decoded(location.hash));
697
769
  function onClick(event) {
698
- const target = event.target;
699
- const href = target?.closest('a[href^="#"]')?.getAttribute("href");
770
+ const target2 = event.target;
771
+ const href = target2?.closest('a[href^="#"]')?.getAttribute("href");
700
772
  if (href && !event.defaultPrevented && !event.button && !(event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) && goAnchor(decoded(href))) {
701
773
  event.preventDefault();
702
774
  history.pushState(null, "", href);
703
775
  }
704
- const tab = target?.closest("[role=tab]");
705
- const list = tab?.closest("[data-b-tabs]");
706
- if (tab && list) return selectTab(list, Array.from(list.querySelectorAll("[role=tab]")).indexOf(tab));
707
- const button = target?.closest("[data-b-act]");
776
+ const tab = target2?.closest("[role=tab]");
777
+ const list2 = tab?.closest("[data-b-tabs]");
778
+ if (tab && list2) return selectTab(list2, Array.from(list2.querySelectorAll("[role=tab]")).indexOf(tab));
779
+ const button = target2?.closest("[data-b-act]");
708
780
  const act = button?.getAttribute("data-b-act");
709
781
  const root = button?.closest("[data-b-car]");
710
782
  if (root && (act === "prev" || act === "next")) slideTo(root, act === "next" ? 1 : -1);
711
783
  }
712
784
  function onKey(event) {
713
785
  const tab = event.target?.closest("[role=tab]");
714
- const list = tab?.closest("[data-b-tabs]");
715
- if (!tab || !list) return;
716
- const count = list.querySelectorAll("[role=tab]").length;
717
- const at = Array.from(list.querySelectorAll("[role=tab]")).indexOf(tab);
786
+ const list2 = tab?.closest("[data-b-tabs]");
787
+ if (!tab || !list2) return;
788
+ const count = list2.querySelectorAll("[role=tab]").length;
789
+ const at = Array.from(list2.querySelectorAll("[role=tab]")).indexOf(tab);
718
790
  const to = event.key === "ArrowRight" ? (at + 1) % count : event.key === "ArrowLeft" ? (at + count - 1) % count : event.key === "Home" ? 0 : event.key === "End" ? count - 1 : -1;
719
791
  if (to < 0) return;
720
792
  event.preventDefault();
721
- selectTab(list, to, true);
793
+ selectTab(list2, to, true);
722
794
  }
723
795
  function startRuntime() {
724
796
  if (typeof document === "undefined") return () => void 0;
@@ -800,8 +872,8 @@ function targetText(date) {
800
872
  }
801
873
  function Countdown({ props, editMode, interactive, locale }) {
802
874
  void locale;
803
- const target = str(props.target);
804
- const when = target === void 0 ? null : new Date(target);
875
+ const target2 = str(props.target);
876
+ const when = target2 === void 0 ? null : new Date(target2);
805
877
  if (when === null || Number.isNaN(when.getTime())) {
806
878
  return /* @__PURE__ */ jsx8(Placeholder, { editMode, children: "Set the date and time the countdown ends" });
807
879
  }
@@ -857,14 +929,87 @@ function Divider({ node }) {
857
929
  ] });
858
930
  }
859
931
 
860
- // src/basics/heading.tsx
932
+ // src/basics/v2/styles.tsx
861
933
  import { Fragment as Fragment6, jsx as jsx11, jsxs as jsxs6 } from "react/jsx-runtime";
934
+ var BASICS_V2_CSS = `@layer throttle{
935
+ .tb-b-faq{color:var(--b-color,inherit);font-size:var(--b-size,var(--tb-text-m));line-height:1.6}
936
+ .tb-b-faq-item{border-block-end:1px solid var(--tb-color-border,currentColor)}
937
+ .tb-b-faq-q{margin:0;padding:var(--tb-space-s) 0;font-weight:600;cursor:pointer}
938
+ h3.tb-b-faq-q{cursor:auto;font-size:inherit}
939
+ .tb-b-faq-a{padding-block-end:var(--tb-space-s)}
940
+ .tb-b-faq-a>:first-child{margin-block-start:0}
941
+ .tb-b-faq-all{margin-block-end:var(--tb-space-s);padding:.4rem .9rem;border:1px solid var(--tb-color-border-control,currentColor);border-radius:var(--throttle-radius,8px);background:transparent;color:inherit;font:inherit;cursor:pointer}
942
+ .tb-b-faq summary:focus-visible,.tb-b-faq-all:focus-visible{outline:2px solid var(--tb-color-primary,currentColor);outline-offset:2px}
943
+ .tb-b-rich{text-align:var(--b-align,left);color:var(--b-color,inherit);font-size:var(--b-size,var(--tb-text-m));line-height:1.7;overflow-wrap:anywhere}
944
+ .tb-b-rich>:first-child{margin-block-start:0}
945
+ .tb-b-rich h1,.tb-b-rich h2,.tb-b-rich h3,.tb-b-rich h4,.tb-b-rich h5,.tb-b-rich h6{font-family:var(--throttle-font-family-heading,inherit);line-height:1.25;scroll-margin-block-start:var(--tb-space-l)}
946
+ .tb-b-rich table{border-collapse:collapse;max-inline-size:100%;display:block;overflow-x:auto}
947
+ .tb-b-rich th,.tb-b-rich td{padding:var(--tb-space-xs) var(--tb-space-s);border:1px solid var(--tb-color-border,currentColor);text-align:start}
948
+ .tb-b-rich figure{margin-inline:0}
949
+ .tb-b-rich img{max-inline-size:100%;block-size:auto}
950
+ .tb-b-rich pre{overflow-x:auto;padding:var(--tb-space-s);background:var(--tb-color-muted,#eee)}
951
+ .tb-b-rich code{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:.9em}
952
+ .tb-b-rich blockquote{margin-inline:0;padding-inline-start:var(--tb-space-m);border-inline-start:3px solid var(--tb-color-border,currentColor)}
953
+ .tb-b-toc{margin-block-end:var(--tb-space-m);padding:var(--tb-space-s) var(--tb-space-m);border:1px solid var(--tb-color-border,currentColor);border-radius:var(--throttle-radius,8px)}
954
+ .tb-b-toc-title{margin:0 0 var(--tb-space-xs);font-weight:600}
955
+ .tb-b-toc ol{margin:0;padding:0;list-style:none}
956
+ .tb-b-toc-l3{padding-inline-start:var(--tb-space-m)}
957
+ .tb-b-toc a{color:inherit}
958
+ .tb-b-svg{display:block;text-align:var(--b-align,left);color:var(--b-color,inherit);line-height:0}
959
+ .tb-b-svg>svg,.tb-b-svg>img{display:inline-block;max-inline-size:100%;block-size:auto;inline-size:calc(var(--b-width)*1px)}
960
+ .tb-b-icons{margin:0;padding:0;list-style:none;color:var(--b-color,inherit);font-size:var(--b-size,var(--tb-text-m));line-height:1.5}
961
+ .tb-b-icons li{display:flex;gap:var(--tb-space-s);align-items:flex-start;padding-block:var(--tb-space-xs)}
962
+ .tb-b-icons-icon{flex:0 0 auto;display:inline-flex;color:var(--b-iconColor,var(--tb-color-primary,currentColor))}
963
+ .tb-b-icons-icon svg,.tb-b-icons-icon img{inline-size:calc(var(--b-iconSize,20)*1px);block-size:calc(var(--b-iconSize,20)*1px)}
964
+ .tb-b-quote{margin:0;text-align:var(--b-align,left);color:var(--b-color,inherit);font-size:var(--b-size,var(--tb-text-l))}
965
+ .tb-b-quote blockquote{margin:0;font-family:var(--throttle-font-family-heading,inherit);line-height:1.4}
966
+ .tb-b-quote figcaption{display:flex;align-items:center;gap:var(--tb-space-s);margin-block-start:var(--tb-space-s);font-size:var(--tb-text-s)}
967
+ .tb-b-quote-photo{inline-size:48px;block-size:48px;border-radius:50%;object-fit:cover}
968
+ .tb-b-quote-by{display:flex;flex-direction:column}
969
+ .tb-b-quote-name{font-weight:600}
970
+ .tb-b-quote-role{color:var(--tb-color-muted-foreground,inherit)}
971
+ .tb-b-heading-wrap{text-align:var(--b-align,left)}
972
+ .tb-b-kicker{display:flex;align-items:center;gap:var(--tb-space-s);margin:0 0 var(--tb-space-xs);justify-content:var(--b-align,flex-start);font-size:var(--tb-text-s);letter-spacing:.08em;text-transform:uppercase;color:var(--b-color,var(--tb-color-muted-foreground,inherit))}
973
+ .tb-b-kicker-rule{flex:0 0 auto;inline-size:2rem;block-size:1px;background:currentColor}
974
+ .tb-b-crumbs{text-align:var(--b-align,left);color:var(--b-color,inherit);font-size:var(--b-size,var(--tb-text-s))}
975
+ .tb-b-crumbs ol{display:flex;flex-wrap:wrap;gap:var(--tb-space-xs);margin:0;padding:0;list-style:none}
976
+ .tb-b-crumbs li{display:inline-flex;align-items:center;gap:var(--tb-space-xs)}
977
+ .tb-b-crumbs a{color:inherit;text-decoration:none}
978
+ .tb-b-crumbs a:hover{text-decoration:underline}
979
+ .tb-b-crumbs a:focus-visible{outline:2px solid var(--tb-color-primary,currentColor);outline-offset:2px}
980
+ .tb-b-crumbs [aria-current]{font-weight:600}
981
+ }`;
982
+ function BasicV2Styles() {
983
+ return /* @__PURE__ */ jsxs6(Fragment6, { children: [
984
+ /* @__PURE__ */ jsx11(BasicStyles, {}),
985
+ /* @__PURE__ */ jsx11("style", { href: "tb-basics-v2", precedence: "throttle", children: BASICS_V2_CSS })
986
+ ] });
987
+ }
988
+
989
+ // src/basics/heading.tsx
990
+ import { Fragment as Fragment7, jsx as jsx12, jsxs as jsxs7 } from "react/jsx-runtime";
862
991
  var LEVELS = ["h1", "h2", "h3", "h4", "h5", "h6"];
863
992
  function Heading({ props, inlineEdit }) {
864
993
  const Tag = oneOf(props.level, LEVELS, "h2");
865
- return /* @__PURE__ */ jsxs6(Fragment6, { children: [
866
- /* @__PURE__ */ jsx11(BasicStyles, {}),
867
- /* @__PURE__ */ jsx11(Tag, { className: "tb-b-heading", children: inlineEdit?.("text") ?? str(props.text) ?? "" })
994
+ const heading = /* @__PURE__ */ jsx12(Tag, { className: "tb-b-heading", children: inlineEdit?.("text") ?? str(props.text) ?? "" });
995
+ const kicker = inlineEdit?.("kicker") ?? str(props.kicker);
996
+ const rule = props.rule === true;
997
+ if (kicker === void 0 && !rule) {
998
+ return /* @__PURE__ */ jsxs7(Fragment7, { children: [
999
+ /* @__PURE__ */ jsx12(BasicStyles, {}),
1000
+ heading
1001
+ ] });
1002
+ }
1003
+ return /* @__PURE__ */ jsxs7(Fragment7, { children: [
1004
+ /* @__PURE__ */ jsx12(BasicStyles, {}),
1005
+ /* @__PURE__ */ jsx12(BasicV2Styles, {}),
1006
+ /* @__PURE__ */ jsxs7("div", { className: "tb-b-heading-wrap", children: [
1007
+ /* @__PURE__ */ jsxs7("p", { className: "tb-b-kicker", children: [
1008
+ rule && /* @__PURE__ */ jsx12("span", { className: "tb-b-kicker-rule", "aria-hidden": "true" }),
1009
+ kicker
1010
+ ] }),
1011
+ heading
1012
+ ] })
868
1013
  ] });
869
1014
  }
870
1015
 
@@ -873,7 +1018,7 @@ import { safeUrl as safeUrl4 } from "@usethrottle/builder-schema";
873
1018
 
874
1019
  // src/asset-image.tsx
875
1020
  import { safeUrl as safeUrl3 } from "@usethrottle/builder-schema";
876
- import { jsx as jsx12 } from "react/jsx-runtime";
1021
+ import { jsx as jsx13 } from "react/jsx-runtime";
877
1022
  function isFrozenAsset(value) {
878
1023
  if (typeof value !== "object" || value === null) return false;
879
1024
  const v = value;
@@ -889,7 +1034,7 @@ function AssetImage(props) {
889
1034
  const url = href(variant.url);
890
1035
  return url === null || url.includes(",") ? [] : [`${url} ${String(variant.width)}w`];
891
1036
  }).join(", ");
892
- return /* @__PURE__ */ jsx12(
1037
+ return /* @__PURE__ */ jsx13(
893
1038
  "img",
894
1039
  {
895
1040
  src,
@@ -906,7 +1051,7 @@ function AssetImage(props) {
906
1051
  }
907
1052
 
908
1053
  // src/basics/image.tsx
909
- import { Fragment as Fragment7, jsx as jsx13, jsxs as jsxs7 } from "react/jsx-runtime";
1054
+ import { Fragment as Fragment8, jsx as jsx14, jsxs as jsxs8 } from "react/jsx-runtime";
910
1055
  var RULES2 = [
911
1056
  { key: "radius", property: "--bx-radius", values: { none: "0", s: "4px", m: "8px", l: "16px", full: "9999px" } },
912
1057
  { key: "fit", property: "--bx-fit", values: { cover: "cover", contain: "contain" } }
@@ -916,19 +1061,19 @@ function Image({ node, props, mediaOrigin, editMode }) {
916
1061
  const decorative = props.decorative === true;
917
1062
  const alt = decorative ? "" : typeof props.alt === "string" ? props.alt : "";
918
1063
  const asset = isFrozenAsset(props.image) ? props.image : void 0;
919
- const image = /* @__PURE__ */ jsx13(AssetImage, { asset, mediaOrigin, alt, className: "tb-b-img", sizes: "(max-width: 767px) 100vw, 50vw" });
1064
+ const image = /* @__PURE__ */ jsx14(AssetImage, { asset, mediaOrigin, alt, className: "tb-b-img", sizes: "(max-width: 767px) 100vw, 50vw" });
920
1065
  const shown2 = asset !== void 0 && safeUrl4(asset.url, "src", { mediaOrigin }) !== null;
921
- return /* @__PURE__ */ jsxs7(Fragment7, { children: [
922
- /* @__PURE__ */ jsx13(BasicStyles, {}),
923
- /* @__PURE__ */ jsx13(WidgetStyle, { css: enumCss(node, RULES2) }),
924
- shown2 ? /* @__PURE__ */ jsx13("div", { className: "tb-b-image", children: /* @__PURE__ */ jsx13("div", { className: "tb-b-image-box", children: href === null ? image : /* @__PURE__ */ jsx13("a", { href, children: image }) }) }) : /* @__PURE__ */ jsx13(Placeholder, { editMode, children: asset === void 0 ? "Choose an image" : "Image unavailable" })
1066
+ return /* @__PURE__ */ jsxs8(Fragment8, { children: [
1067
+ /* @__PURE__ */ jsx14(BasicStyles, {}),
1068
+ /* @__PURE__ */ jsx14(WidgetStyle, { css: enumCss(node, RULES2) }),
1069
+ shown2 ? /* @__PURE__ */ jsx14("div", { className: "tb-b-image", children: /* @__PURE__ */ jsx14("div", { className: "tb-b-image-box", children: href === null ? image : /* @__PURE__ */ jsx14("a", { href, children: image }) }) }) : /* @__PURE__ */ jsx14(Placeholder, { editMode, children: asset === void 0 ? "Choose an image" : "Image unavailable" })
925
1070
  ] });
926
1071
  }
927
1072
 
928
1073
  // src/basics/logo.tsx
929
1074
  import { useSiteDesign as useSiteDesign3 } from "@usethrottle/ui";
930
1075
  import { safeUrl as safeUrl5 } from "@usethrottle/builder-schema";
931
- import { Fragment as Fragment8, jsx as jsx14, jsxs as jsxs8 } from "react/jsx-runtime";
1076
+ import { Fragment as Fragment9, jsx as jsx15, jsxs as jsxs9 } from "react/jsx-runtime";
932
1077
  function Logo({ props, mediaOrigin, editMode }) {
933
1078
  const design = useSiteDesign3();
934
1079
  const scheme = design?.theme?.colorScheme ?? "auto";
@@ -941,17 +1086,17 @@ function Logo({ props, mediaOrigin, editMode }) {
941
1086
  const alt = name ?? "";
942
1087
  let content = null;
943
1088
  if (main !== void 0) {
944
- const img = /* @__PURE__ */ jsx14("img", { src: main, alt, decoding: "async" });
945
- content = scheme === "auto" && light !== void 0 && dark !== void 0 ? /* @__PURE__ */ jsxs8("picture", { children: [
946
- /* @__PURE__ */ jsx14("source", { media: "(prefers-color-scheme: dark)", srcSet: dark }),
1089
+ const img = /* @__PURE__ */ jsx15("img", { src: main, alt, decoding: "async" });
1090
+ content = scheme === "auto" && light !== void 0 && dark !== void 0 ? /* @__PURE__ */ jsxs9("picture", { children: [
1091
+ /* @__PURE__ */ jsx15("source", { media: "(prefers-color-scheme: dark)", srcSet: dark }),
947
1092
  img
948
1093
  ] }) : img;
949
1094
  } else if (name !== void 0) {
950
- content = /* @__PURE__ */ jsx14("span", { className: "tb-b-logo-name", children: name });
1095
+ content = /* @__PURE__ */ jsx15("span", { className: "tb-b-logo-name", children: name });
951
1096
  }
952
- return /* @__PURE__ */ jsxs8(Fragment8, { children: [
953
- /* @__PURE__ */ jsx14(BasicStyles, {}),
954
- content === null ? /* @__PURE__ */ jsx14(Placeholder, { editMode, children: "Logo: add one in Site settings" }) : /* @__PURE__ */ jsx14("div", { className: "tb-b-logo", children: /* @__PURE__ */ jsx14("a", { href, children: content }) })
1097
+ return /* @__PURE__ */ jsxs9(Fragment9, { children: [
1098
+ /* @__PURE__ */ jsx15(BasicStyles, {}),
1099
+ content === null ? /* @__PURE__ */ jsx15(Placeholder, { editMode, children: "Logo: add one in Site settings" }) : /* @__PURE__ */ jsx15("div", { className: "tb-b-logo", children: /* @__PURE__ */ jsx15("a", { href, children: content }) })
955
1100
  ] });
956
1101
  }
957
1102
 
@@ -959,7 +1104,7 @@ function Logo({ props, mediaOrigin, editMode }) {
959
1104
  import { useId, useRef, useState as useState2 } from "react";
960
1105
  import { Icon as Icon2, useSiteDesign as useSiteDesign4 } from "@usethrottle/ui";
961
1106
  import { SITE_STRING_DEFAULTS as SITE_STRING_DEFAULTS3, safeUrl as safeUrl6 } from "@usethrottle/builder-schema";
962
- import { Fragment as Fragment9, jsx as jsx15, jsxs as jsxs9 } from "react/jsx-runtime";
1107
+ import { Fragment as Fragment10, jsx as jsx16, jsxs as jsxs10 } from "react/jsx-runtime";
963
1108
  var LAYOUTS = ["horizontal", "vertical", "drawer-on-phone"];
964
1109
  var MAX_DEPTH = 3;
965
1110
  function List({ items, mediaOrigin, depth = 0, id, onNavigate }) {
@@ -968,16 +1113,16 @@ function List({ items, mediaOrigin, depth = 0, id, onNavigate }) {
968
1113
  return href === null ? [] : [{ item, href }];
969
1114
  });
970
1115
  if (shown2.length === 0) return null;
971
- return /* @__PURE__ */ jsx15("ul", { ...id === void 0 ? {} : { id }, ...onNavigate === void 0 ? {} : { onClick: onNavigate }, children: shown2.map(({ item, href }, index) => /* @__PURE__ */ jsxs9("li", { children: [
972
- /* @__PURE__ */ jsx15("a", { href, children: item.label }),
973
- depth + 1 < MAX_DEPTH && item.children !== void 0 && /* @__PURE__ */ jsx15(List, { items: item.children, mediaOrigin, depth: depth + 1 })
1116
+ return /* @__PURE__ */ jsx16("ul", { ...id === void 0 ? {} : { id }, ...onNavigate === void 0 ? {} : { onClick: onNavigate }, children: shown2.map(({ item, href }, index) => /* @__PURE__ */ jsxs10("li", { children: [
1117
+ /* @__PURE__ */ jsx16("a", { href, children: item.label }),
1118
+ depth + 1 < MAX_DEPTH && item.children !== void 0 && /* @__PURE__ */ jsx16(List, { items: item.children, mediaOrigin, depth: depth + 1 })
974
1119
  ] }, `${String(index)}:${href}`)) });
975
1120
  }
976
1121
  function Menu({ props, mediaOrigin, editMode }) {
977
1122
  const design = useSiteDesign4();
978
1123
  const listId = useId();
979
1124
  const toggle = useRef(null);
980
- const [open, setOpen] = useState2(false);
1125
+ const [open, setOpen2] = useState2(false);
981
1126
  const name = str(props.menu) ?? "header";
982
1127
  const layout = oneOf(props.layout, LAYOUTS, "horizontal");
983
1128
  const menus = design?.menus;
@@ -985,21 +1130,21 @@ function Menu({ props, mediaOrigin, editMode }) {
985
1130
  const strings = design?.strings;
986
1131
  const label = (strings !== void 0 && Object.hasOwn(strings, "nav.menu") ? str(strings["nav.menu"]) : void 0) ?? SITE_STRING_DEFAULTS3["nav.menu"];
987
1132
  if (items === void 0 || items.length === 0) {
988
- return /* @__PURE__ */ jsxs9(Fragment9, { children: [
989
- /* @__PURE__ */ jsx15(BasicStyles, {}),
990
- /* @__PURE__ */ jsx15(Placeholder, { editMode, children: `Menu "${name}" is empty: add links in Site settings` })
1133
+ return /* @__PURE__ */ jsxs10(Fragment10, { children: [
1134
+ /* @__PURE__ */ jsx16(BasicStyles, {}),
1135
+ /* @__PURE__ */ jsx16(Placeholder, { editMode, children: `Menu "${name}" is empty: add links in Site settings` })
991
1136
  ] });
992
1137
  }
993
1138
  const drawer = layout === "drawer-on-phone";
994
1139
  const onKeyDown = (event) => {
995
1140
  if (event.key === "Escape" && open) {
996
- setOpen(false);
1141
+ setOpen2(false);
997
1142
  toggle.current?.focus();
998
1143
  }
999
1144
  };
1000
- return /* @__PURE__ */ jsxs9(Fragment9, { children: [
1001
- /* @__PURE__ */ jsx15(BasicStyles, {}),
1002
- /* @__PURE__ */ jsxs9(
1145
+ return /* @__PURE__ */ jsxs10(Fragment10, { children: [
1146
+ /* @__PURE__ */ jsx16(BasicStyles, {}),
1147
+ /* @__PURE__ */ jsxs10(
1003
1148
  "nav",
1004
1149
  {
1005
1150
  className: `tb-b-menu tb-b-menu--${layout}${layout === "vertical" ? "" : " tb-b-menu--h"}`,
@@ -1007,7 +1152,7 @@ function Menu({ props, mediaOrigin, editMode }) {
1007
1152
  "data-open": drawer ? String(open) : void 0,
1008
1153
  onKeyDown: drawer ? onKeyDown : void 0,
1009
1154
  children: [
1010
- drawer && /* @__PURE__ */ jsx15(
1155
+ drawer && /* @__PURE__ */ jsx16(
1011
1156
  "button",
1012
1157
  {
1013
1158
  ref: toggle,
@@ -1015,11 +1160,11 @@ function Menu({ props, mediaOrigin, editMode }) {
1015
1160
  className: "tb-b-menu-toggle",
1016
1161
  "aria-expanded": open,
1017
1162
  "aria-controls": listId,
1018
- onClick: () => setOpen((value) => !value),
1019
- children: /* @__PURE__ */ jsx15(Icon2, { name: open ? "close" : "menu", size: 24, label })
1163
+ onClick: () => setOpen2((value) => !value),
1164
+ children: /* @__PURE__ */ jsx16(Icon2, { name: open ? "close" : "menu", size: 24, label })
1020
1165
  }
1021
1166
  ),
1022
- /* @__PURE__ */ jsx15(List, { items, mediaOrigin, id: listId, ...drawer ? { onNavigate: () => setOpen(false) } : {} })
1167
+ /* @__PURE__ */ jsx16(List, { items, mediaOrigin, id: listId, ...drawer ? { onNavigate: () => setOpen2(false) } : {} })
1023
1168
  ]
1024
1169
  }
1025
1170
  )
@@ -1027,18 +1172,18 @@ function Menu({ props, mediaOrigin, editMode }) {
1027
1172
  }
1028
1173
 
1029
1174
  // src/basics/spacer.tsx
1030
- import { Fragment as Fragment10, jsx as jsx16, jsxs as jsxs10 } from "react/jsx-runtime";
1175
+ import { Fragment as Fragment11, jsx as jsx17, jsxs as jsxs11 } from "react/jsx-runtime";
1031
1176
  function Spacer() {
1032
- return /* @__PURE__ */ jsxs10(Fragment10, { children: [
1033
- /* @__PURE__ */ jsx16(BasicStyles, {}),
1034
- /* @__PURE__ */ jsx16("div", { className: "tb-b-spacer", "aria-hidden": "true" })
1177
+ return /* @__PURE__ */ jsxs11(Fragment11, { children: [
1178
+ /* @__PURE__ */ jsx17(BasicStyles, {}),
1179
+ /* @__PURE__ */ jsx17("div", { className: "tb-b-spacer", "aria-hidden": "true" })
1035
1180
  ] });
1036
1181
  }
1037
1182
 
1038
1183
  // src/basics/rich-text.tsx
1039
- import { Fragment as Fragment11, createElement } from "react";
1184
+ import { Fragment as Fragment12, createElement } from "react";
1040
1185
  import { safeUrl as safeUrl7 } from "@usethrottle/builder-schema";
1041
- import { jsx as jsx17, jsxs as jsxs11 } from "react/jsx-runtime";
1186
+ import { jsx as jsx18, jsxs as jsxs12 } from "react/jsx-runtime";
1042
1187
  var ALLOWED = /* @__PURE__ */ new Set(["p", "br", "strong", "em", "u", "s", "a", "ul", "ol", "li", "h2", "h3", "h4", "blockquote", "code"]);
1043
1188
  var ALIAS = { b: "strong", i: "em", strike: "s", del: "s" };
1044
1189
  var DROP_WITH_CONTENT = /* @__PURE__ */ new Set([
@@ -1197,11 +1342,11 @@ function parseRichText(source, mediaOrigin) {
1197
1342
  }
1198
1343
  }
1199
1344
  if (name === "li") {
1200
- let list = stack.length - 1;
1201
- while (list > 0 && stack[list].tag !== "ul" && stack[list].tag !== "ol") list -= 1;
1202
- if (list === 0) list = -1;
1203
- if (list === -1) continue;
1204
- stack.length = list + 1;
1345
+ let list2 = stack.length - 1;
1346
+ while (list2 > 0 && stack[list2].tag !== "ul" && stack[list2].tag !== "ol") list2 -= 1;
1347
+ if (list2 === 0) list2 = -1;
1348
+ if (list2 === -1) continue;
1349
+ stack.length = list2 + 1;
1205
1350
  }
1206
1351
  if (name === "a") closeTo("a");
1207
1352
  const el = { tag: name, children: [] };
@@ -1218,10 +1363,10 @@ function parseRichText(source, mediaOrigin) {
1218
1363
  }
1219
1364
  function toReact(el, key) {
1220
1365
  const children = el.children.map((child, index) => typeof child === "string" ? child : toReact(child, index));
1221
- if (el.tag === "br") return /* @__PURE__ */ jsx17("br", {}, key);
1366
+ if (el.tag === "br") return /* @__PURE__ */ jsx18("br", {}, key);
1222
1367
  if (el.tag === "a") {
1223
- if (el.href === null || el.href === void 0) return /* @__PURE__ */ jsx17(Fragment11, { children }, key);
1224
- return /* @__PURE__ */ jsx17("a", { href: el.href, rel: "noopener noreferrer", className: "tb-b-link", children }, key);
1368
+ if (el.href === null || el.href === void 0) return /* @__PURE__ */ jsx18(Fragment12, { children }, key);
1369
+ return /* @__PURE__ */ jsx18("a", { href: el.href, rel: "noopener noreferrer", className: "tb-b-link", children }, key);
1225
1370
  }
1226
1371
  return createElement(el.tag, { key }, ...children);
1227
1372
  }
@@ -1232,26 +1377,26 @@ function RichText({
1232
1377
  editMode = false
1233
1378
  }) {
1234
1379
  const tree = parseRichText(html, mediaOrigin);
1235
- return /* @__PURE__ */ jsxs11("div", { className, children: [
1380
+ return /* @__PURE__ */ jsxs12("div", { className, children: [
1236
1381
  tree.children.map((child, index) => typeof child === "string" ? child : toReact(child, index)),
1237
- editMode && tree.truncated === true && /* @__PURE__ */ jsx17("div", { className: "tb-b-empty", role: "alert", children: "Part of this text was not shown: a tag is not closed (check the quotes in links), or the text is too long." })
1382
+ editMode && tree.truncated === true && /* @__PURE__ */ jsx18("div", { className: "tb-b-empty", role: "alert", children: "Part of this text was not shown: a tag is not closed (check the quotes in links), or the text is too long." })
1238
1383
  ] });
1239
1384
  }
1240
1385
 
1241
1386
  // src/basics/text.tsx
1242
- import { Fragment as Fragment12, jsx as jsx18, jsxs as jsxs12 } from "react/jsx-runtime";
1387
+ import { Fragment as Fragment13, jsx as jsx19, jsxs as jsxs13 } from "react/jsx-runtime";
1243
1388
  function Text({ props, mediaOrigin, editMode, inlineEdit }) {
1244
1389
  const editor = inlineEdit?.("html") ?? null;
1245
- return /* @__PURE__ */ jsxs12(Fragment12, { children: [
1246
- /* @__PURE__ */ jsx18(BasicStyles, {}),
1247
- editor === null ? /* @__PURE__ */ jsx18(RichText, { html: str(props.html) ?? "", mediaOrigin, className: "tb-b-text", editMode }) : /* @__PURE__ */ jsx18("div", { className: "tb-b-text", children: editor })
1390
+ return /* @__PURE__ */ jsxs13(Fragment13, { children: [
1391
+ /* @__PURE__ */ jsx19(BasicStyles, {}),
1392
+ editor === null ? /* @__PURE__ */ jsx19(RichText, { html: str(props.html) ?? "", mediaOrigin, className: "tb-b-text", editMode }) : /* @__PURE__ */ jsx19("div", { className: "tb-b-text", children: editor })
1248
1393
  ] });
1249
1394
  }
1250
1395
 
1251
1396
  // src/basics/video.tsx
1252
1397
  import { useState as useState3 } from "react";
1253
1398
  import { Icon as Icon3 } from "@usethrottle/ui";
1254
- import { Fragment as Fragment13, jsx as jsx19, jsxs as jsxs13 } from "react/jsx-runtime";
1399
+ import { Fragment as Fragment14, jsx as jsx20, jsxs as jsxs14 } from "react/jsx-runtime";
1255
1400
  var RULES3 = [
1256
1401
  { key: "ratio", property: "--bx-ratio", values: { "16:9": "16 / 9", "4:3": "4 / 3", "1:1": "1 / 1", "9:16": "9 / 16" } }
1257
1402
  ];
@@ -1268,7 +1413,7 @@ function parseVideoUrl(input) {
1268
1413
  }
1269
1414
  if (url.protocol !== "https:" || url.username !== "" || url.password !== "" || url.port !== "" && url.port !== "443") return null;
1270
1415
  const host = url.hostname.toLowerCase();
1271
- const parts = url.pathname.split("/").filter((part) => part !== "");
1416
+ const parts = url.pathname.split("/").filter((part2) => part2 !== "");
1272
1417
  if (host === "youtu.be") {
1273
1418
  const id = parts[0];
1274
1419
  return parts.length === 1 && id !== void 0 && YOUTUBE_ID.test(id) ? { provider: "youtube", id } : null;
@@ -1293,10 +1438,10 @@ function embedSrc(video, muted) {
1293
1438
  function Video({ node, props, editMode }) {
1294
1439
  const [loaded, setLoaded] = useState3(false);
1295
1440
  const video = parseVideoUrl(str(props.url) ?? "");
1296
- return /* @__PURE__ */ jsxs13(Fragment13, { children: [
1297
- /* @__PURE__ */ jsx19(BasicStyles, {}),
1298
- /* @__PURE__ */ jsx19(WidgetStyle, { css: enumCss(node, RULES3) }),
1299
- video === null ? /* @__PURE__ */ jsx19(Placeholder, { editMode, children: "Paste a YouTube or Vimeo link" }) : /* @__PURE__ */ jsx19("div", { className: "tb-b-video", "data-provider": video.provider, children: loaded && !editMode ? /* @__PURE__ */ jsx19(
1441
+ return /* @__PURE__ */ jsxs14(Fragment14, { children: [
1442
+ /* @__PURE__ */ jsx20(BasicStyles, {}),
1443
+ /* @__PURE__ */ jsx20(WidgetStyle, { css: enumCss(node, RULES3) }),
1444
+ video === null ? /* @__PURE__ */ jsx20(Placeholder, { editMode, children: "Paste a YouTube or Vimeo link" }) : /* @__PURE__ */ jsx20("div", { className: "tb-b-video", "data-provider": video.provider, children: loaded && !editMode ? /* @__PURE__ */ jsx20(
1300
1445
  "iframe",
1301
1446
  {
1302
1447
  src: embedSrc(video, props.autoplayMuted === true),
@@ -1305,84 +1450,268 @@ function Video({ node, props, editMode }) {
1305
1450
  referrerPolicy: "strict-origin-when-cross-origin",
1306
1451
  sandbox: "allow-scripts allow-same-origin allow-presentation allow-popups"
1307
1452
  }
1308
- ) : /* @__PURE__ */ jsx19("button", { type: "button", className: "tb-b-play", "aria-label": "Play video", onClick: () => setLoaded(true), children: /* @__PURE__ */ jsx19("span", { children: /* @__PURE__ */ jsx19(Icon3, { name: "play", size: 28 }) }) }) })
1453
+ ) : /* @__PURE__ */ jsx20("button", { type: "button", className: "tb-b-play", "aria-label": "Play video", onClick: () => setLoaded(true), children: /* @__PURE__ */ jsx20("span", { children: /* @__PURE__ */ jsx20(Icon3, { name: "play", size: 28 }) }) }) })
1309
1454
  ] });
1310
1455
  }
1311
1456
 
1312
1457
  // src/basics/v2/announcement-v2.tsx
1313
- var announcementV2Widgets = [];
1314
-
1315
- // src/basics/v2/breadcrumbs.tsx
1316
- var breadcrumbsWidgets = [];
1458
+ import { Fragment as Fragment21, createElement as createElement3, useEffect as useEffect7, useMemo, useRef as useRef3, useState as useState5 } from "react";
1459
+ import { Icon as Icon5, useSiteDesign as useSiteDesign6 } from "@usethrottle/ui";
1460
+ import { BASIC_WIDGET_DEFINITIONS as BASIC_WIDGET_DEFINITIONS2, SITE_STRING_DEFAULTS as SITE_STRING_DEFAULTS6 } from "@usethrottle/builder-schema";
1317
1461
 
1318
- // src/basics/v2/faq.tsx
1319
- var faqWidgets = [];
1320
-
1321
- // src/basics/v2/icon-list.tsx
1322
- var iconListWidgets = [];
1462
+ // src/context.ts
1463
+ import { createContext, useContext } from "react";
1464
+ var BuilderContext = typeof createContext === "function" ? createContext(null) : null;
1465
+ var useBuilder = () => useContext(BuilderContext);
1323
1466
 
1324
- // src/basics/v2/merge.ts
1325
- function mergeV2Widgets(v1, v2) {
1326
- const replacement = /* @__PURE__ */ new Map();
1327
- for (const widget of v2) {
1328
- if (replacement.has(widget.type)) throw new Error(`Two v2 widgets of type ${widget.type}`);
1329
- replacement.set(widget.type, widget);
1330
- }
1331
- const v1Types = new Set(v1.map((widget) => widget.type));
1332
- return [
1333
- ...v1.map((widget) => replacement.get(widget.type) ?? widget),
1334
- ...[...replacement.values()].filter((widget) => !v1Types.has(widget.type))
1335
- ];
1467
+ // src/theme.ts
1468
+ import { SITE_FONTS, eligibleMessages, safeUrl as safeUrl8, sanitizeSiteCss } from "@usethrottle/builder-schema";
1469
+ import { PRESET_NAMES, PRESET_TOKENS } from "@usethrottle/ui/presets";
1470
+ var isRecord2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
1471
+ var str2 = (v) => typeof v === "string" && v !== "" ? v : void 0;
1472
+ var PALETTE_KEYS = Object.keys(PRESET_TOKENS.clean.light);
1473
+ var DEVICES2 = ["desktop", "tablet", "phone"];
1474
+ function normalizeMessages(messages) {
1475
+ const out = [];
1476
+ messages.forEach((m, index) => {
1477
+ if (!isRecord2(m)) return;
1478
+ const pages = isRecord2(m.pages) ? m.pages : {};
1479
+ out.push({
1480
+ ...m,
1481
+ id: str2(m.id) ?? `m${String(index)}`,
1482
+ target: isRecord2(m.target) ? m.target : null,
1483
+ startsAt: str2(m.startsAt) ?? null,
1484
+ endsAt: str2(m.endsAt) ?? null,
1485
+ audience: m.audience === "guest" || m.audience === "signed-in" ? m.audience : "all",
1486
+ devices: Array.isArray(m.devices) ? m.devices.filter((d) => DEVICES2.some((x) => x === d)) : [...DEVICES2],
1487
+ pages: {
1488
+ mode: pages.mode === "include" || pages.mode === "exclude" ? pages.mode : "all",
1489
+ list: Array.isArray(pages.list) ? pages.list.filter((p) => typeof p === "string") : []
1490
+ }
1491
+ });
1492
+ });
1493
+ return out;
1494
+ }
1495
+ function eligibleOnAnyDevice(messages, now, audience, page) {
1496
+ const ids = /* @__PURE__ */ new Set();
1497
+ for (const device of DEVICES2) for (const m of eligibleMessages(messages, { now, device, audience, page })) ids.add(m.id);
1498
+ return messages.filter((m) => ids.has(m.id));
1336
1499
  }
1337
1500
 
1338
- // src/basics/v2/menu-v2.tsx
1339
- var menuV2Widgets = [];
1340
-
1341
- // src/basics/v2/quote.tsx
1342
- var quoteWidgets = [];
1343
-
1344
- // src/basics/v2/rich-content.tsx
1345
- var richContentWidgets = [];
1501
+ // src/viewer.ts
1502
+ import { createContext as createContext2, useContext as useContext2 } from "react";
1503
+ var ViewerContext = typeof createContext2 === "function" ? createContext2(void 0) : null;
1504
+ var useViewer = () => useContext2(ViewerContext);
1346
1505
 
1347
- // src/basics/v2/svg.tsx
1348
- var svgWidgets = [];
1506
+ // src/basics/v2/menu-v2.tsx
1507
+ import { useEffect as useEffect6, useId as useId2 } from "react";
1508
+ import { Icon as Icon4, useSiteDesign as useSiteDesign5 } from "@usethrottle/ui";
1509
+ import { MB_BASIC_WIDGET_DEFINITIONS, SITE_STRING_DEFAULTS as SITE_STRING_DEFAULTS5, expandMenu, safeUrl as safeUrl12, sectionNodeSchema as sectionNodeSchema2 } from "@usethrottle/builder-schema";
1349
1510
 
1350
- // src/basics/index.ts
1351
- var BASIC_COMPONENTS = {
1352
- "basic.heading": Heading,
1353
- "basic.text": Text,
1354
- "basic.image": Image,
1355
- "basic.button": Button,
1356
- "basic.spacer": Spacer,
1357
- "basic.divider": Divider,
1358
- "basic.video": Video,
1359
- "basic.logo": Logo,
1360
- "basic.menu": Menu,
1361
- "basic.announcement": Announcement,
1362
- "basic.copyright": Copyright,
1363
- "basic.countdown": Countdown
1364
- };
1365
- var v1Widgets = BASIC_WIDGET_DEFINITIONS2.flatMap(
1366
- (definition) => Object.hasOwn(BASIC_COMPONENTS, definition.type) ? [{ ...definition, Component: BASIC_COMPONENTS[definition.type] }] : []
1367
- );
1368
- var widgets = mergeV2Widgets(v1Widgets, [
1369
- ...faqWidgets,
1370
- ...richContentWidgets,
1371
- ...breadcrumbsWidgets,
1372
- ...svgWidgets,
1373
- ...iconListWidgets,
1374
- ...quoteWidgets,
1375
- ...menuV2Widgets,
1376
- ...announcementV2Widgets
1377
- ]);
1378
- var basicPack = { id: "basic", version: "0.0.0", widgets, dataSources: [] };
1511
+ // src/interactions/focus-trap.ts
1512
+ var FOCUSABLE = 'a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])';
1513
+ var focusablesOf = (root) => Array.from(root.querySelectorAll(FOCUSABLE));
1514
+ function trapTab(event, items) {
1515
+ if (event.key !== "Tab") return false;
1516
+ const first = items[0];
1517
+ const last = items[items.length - 1];
1518
+ if (first === void 0 || last === void 0) return false;
1519
+ const active = document.activeElement;
1520
+ const inside = active !== null && items.includes(active);
1521
+ if (event.shiftKey && (active === first || !inside)) {
1522
+ event.preventDefault();
1523
+ last.focus();
1524
+ return true;
1525
+ }
1526
+ if (!event.shiftKey && (active === last || !inside)) {
1527
+ event.preventDefault();
1528
+ first.focus();
1529
+ return true;
1530
+ }
1531
+ return false;
1532
+ }
1379
1533
 
1380
- // src/custom/factory.ts
1381
- import { createElement as createElement3 } from "react";
1534
+ // src/interactions/menu-runtime.ts
1535
+ var holds2 = 0;
1536
+ var release;
1537
+ var ITEM = "[data-tb-i]";
1538
+ var hovers = () => window.matchMedia?.("(hover:none)").matches !== true;
1539
+ function toggleOf(item) {
1540
+ return item.querySelector(":scope > [data-tb-t]");
1541
+ }
1542
+ function setItem(item, open) {
1543
+ if (open) item.setAttribute("data-open", "true");
1544
+ else item.removeAttribute("data-open");
1545
+ toggleOf(item)?.setAttribute("aria-expanded", String(open));
1546
+ item.querySelector(":scope > [data-nav-panel]")?.toggleAttribute("hidden", !open);
1547
+ }
1548
+ function closeOthers(keep) {
1549
+ for (const item of document.querySelectorAll(`${ITEM}[data-open]`)) {
1550
+ if (keep === null || !item.contains(keep)) setItem(item, false);
1551
+ }
1552
+ }
1553
+ var NAV_TOP = "[data-nav-top]";
1554
+ var PANEL = "[data-nav-panel]";
1555
+ function navKey(event, el) {
1556
+ const entry = el.closest(NAV_TOP);
1557
+ if (entry === null) return false;
1558
+ const focus = (links, at2) => links[(at2 + links.length) % links.length]?.focus();
1559
+ const top = entry.querySelector(":scope > a");
1560
+ if (event.key === "Escape" && entry.hasAttribute("data-open")) {
1561
+ event.preventDefault();
1562
+ setItem(entry, false);
1563
+ top?.focus();
1564
+ return true;
1565
+ }
1566
+ const panel = el.closest(PANEL);
1567
+ if (panel !== null) {
1568
+ if (event.key !== "ArrowDown" && event.key !== "ArrowUp") return false;
1569
+ event.preventDefault();
1570
+ const links = [...panel.querySelectorAll("a")];
1571
+ focus(links, links.indexOf(el) + (event.key === "ArrowDown" ? 1 : -1));
1572
+ return true;
1573
+ }
1574
+ if (el !== top) return false;
1575
+ const list2 = entry.parentElement;
1576
+ const tops = [...list2?.querySelectorAll(":scope > li > a") ?? []];
1577
+ const at = tops.indexOf(el);
1578
+ const rtl = list2 !== null && getComputedStyle(list2).direction === "rtl";
1579
+ const forward = rtl ? "ArrowLeft" : "ArrowRight";
1580
+ const back = rtl ? "ArrowRight" : "ArrowLeft";
1581
+ if (event.key === forward || event.key === back) focus(tops, at + (event.key === forward ? 1 : -1));
1582
+ else if (event.key === "Home") focus(tops, 0);
1583
+ else if (event.key === "End") focus(tops, -1);
1584
+ else if (event.key === "ArrowDown" && entry.querySelector(":scope > " + PANEL) !== null) {
1585
+ if (!entry.hasAttribute("data-open")) setItem(entry, true);
1586
+ entry.querySelector(":scope > " + PANEL + " a")?.focus();
1587
+ } else return false;
1588
+ event.preventDefault();
1589
+ return true;
1590
+ }
1591
+ var drawerToggle = (nav) => nav.querySelector(":scope > [data-tb-drawer]");
1592
+ function setDrawer(nav, open) {
1593
+ nav.setAttribute("data-open", String(open));
1594
+ drawerToggle(nav)?.setAttribute("aria-expanded", String(open));
1595
+ const list2 = nav.querySelector(":scope > ul");
1596
+ if (list2 === null) return;
1597
+ if (open) {
1598
+ list2.setAttribute("role", "dialog");
1599
+ list2.setAttribute("aria-modal", "true");
1600
+ const label = nav.getAttribute("aria-label");
1601
+ if (label !== null) list2.setAttribute("aria-label", label);
1602
+ focusablesOf(list2)[0]?.focus();
1603
+ } else {
1604
+ list2.removeAttribute("role");
1605
+ list2.removeAttribute("aria-modal");
1606
+ list2.removeAttribute("aria-label");
1607
+ }
1608
+ }
1609
+ var target = (event) => event.target instanceof Element ? event.target : null;
1610
+ function install() {
1611
+ const over = (event) => {
1612
+ const el = target(event);
1613
+ if (el === null || !hovers()) return;
1614
+ closeOthers(el);
1615
+ for (let item = el.closest(ITEM); item !== null; item = item.parentElement?.closest(ITEM) ?? null) setItem(item, true);
1616
+ };
1617
+ const out = (event) => {
1618
+ if (!hovers()) return;
1619
+ const to = event.relatedTarget instanceof Node ? event.relatedTarget : null;
1620
+ closeOthers(to);
1621
+ };
1622
+ const focusin = (event) => {
1623
+ const el = target(event);
1624
+ if (el === null) return;
1625
+ closeOthers(el);
1626
+ if (el.closest("[data-tb-t]") !== null || el.closest(NAV_TOP) !== null) return;
1627
+ for (let item = el.closest(ITEM); item !== null; item = item.parentElement?.closest(ITEM) ?? null) setItem(item, true);
1628
+ };
1629
+ const click = (event) => {
1630
+ const el = target(event);
1631
+ if (el === null) return;
1632
+ const opener = el.closest("[data-tb-drawer]");
1633
+ if (opener !== null) {
1634
+ const nav2 = opener.closest("nav");
1635
+ if (nav2 !== null) setDrawer(nav2, nav2.getAttribute("data-open") !== "true");
1636
+ return;
1637
+ }
1638
+ const toggle = el.closest("[data-tb-t]");
1639
+ const item = toggle?.closest(ITEM) ?? null;
1640
+ if (item !== null) {
1641
+ closeOthers(item);
1642
+ setItem(item, item.getAttribute("data-open") !== "true");
1643
+ return;
1644
+ }
1645
+ closeOthers(el);
1646
+ const nav = el.closest("nav[data-open=true]");
1647
+ if (nav !== null && el.closest("a") !== null) setDrawer(nav, false);
1648
+ };
1649
+ const keydown = (event) => {
1650
+ const el = target(event);
1651
+ const drawer = document.querySelector("nav[data-open=true]");
1652
+ if (event.key === "Tab" && drawer !== null) {
1653
+ const toggle = drawerToggle(drawer);
1654
+ const list2 = drawer.querySelector(":scope > ul");
1655
+ if (list2 !== null) trapTab(event, [...toggle === null ? [] : [toggle], ...focusablesOf(list2)]);
1656
+ return;
1657
+ }
1658
+ if (drawer === null && el !== null && navKey(event, el)) return;
1659
+ if (event.key !== "Escape") return;
1660
+ if (drawer !== null) {
1661
+ closeOthers(null);
1662
+ setDrawer(drawer, false);
1663
+ drawerToggle(drawer)?.focus();
1664
+ return;
1665
+ }
1666
+ const open = document.querySelector(`${ITEM}[data-open]`);
1667
+ if (open !== null) {
1668
+ const focusInside = el !== null && open.contains(el);
1669
+ const back = toggleOf(open);
1670
+ closeOthers(null);
1671
+ if (focusInside) back?.focus();
1672
+ }
1673
+ };
1674
+ document.addEventListener("mouseover", over);
1675
+ document.addEventListener("mouseout", out);
1676
+ document.addEventListener("focusin", focusin);
1677
+ document.addEventListener("click", click);
1678
+ document.addEventListener("keydown", keydown);
1679
+ return () => {
1680
+ document.removeEventListener("mouseover", over);
1681
+ document.removeEventListener("mouseout", out);
1682
+ document.removeEventListener("focusin", focusin);
1683
+ document.removeEventListener("click", click);
1684
+ document.removeEventListener("keydown", keydown);
1685
+ };
1686
+ }
1687
+ function startMenuRuntime() {
1688
+ if (holds2++ === 0) release = install();
1689
+ let done = false;
1690
+ return () => {
1691
+ if (done) return;
1692
+ done = true;
1693
+ if (--holds2 === 0) {
1694
+ release?.();
1695
+ release = void 0;
1696
+ }
1697
+ };
1698
+ }
1382
1699
 
1383
- // src/custom/composite-widget.tsx
1384
- import { Suspense as Suspense3 } from "react";
1385
- import { pageDocumentSchema, validateSettingValue as validateSettingValue3 } from "@usethrottle/builder-schema";
1700
+ // src/renderer.tsx
1701
+ import { Fragment as Fragment19 } from "react";
1702
+ import {
1703
+ ANCHOR_RE as ANCHOR_RE3,
1704
+ COMMON_WIDGET_SETTINGS as COMMON_WIDGET_SETTINGS2,
1705
+ SITE_STRING_DEFAULTS as SITE_STRING_DEFAULTS4,
1706
+ resolveEntrance,
1707
+ resolveInteraction,
1708
+ codeWidgetSnapshotSchema,
1709
+ resolveResponsive as resolveResponsive4,
1710
+ safeUrl as safeUrl11,
1711
+ upgradeNodes,
1712
+ validateSettingValue as validateSettingValue2,
1713
+ walkNodes as walkNodes3
1714
+ } from "@usethrottle/builder-schema";
1386
1715
 
1387
1716
  // src/budget.ts
1388
1717
  import { MAX_TEMPLATE_WEIGHT, templateWeight } from "@usethrottle/builder-schema";
@@ -1407,31 +1736,13 @@ var RenderBudget = class {
1407
1736
  };
1408
1737
  var fitsBudget = (ast, limit = MAX_RENDERED_NODES) => templateWeight(ast) <= limit;
1409
1738
 
1410
- // src/part-view.tsx
1411
- import { Component } from "react";
1412
-
1413
- // src/renderer.tsx
1414
- import { Fragment as Fragment16 } from "react";
1415
- import {
1416
- ANCHOR_RE as ANCHOR_RE3,
1417
- COMMON_WIDGET_SETTINGS as COMMON_WIDGET_SETTINGS2,
1418
- resolveEntrance,
1419
- resolveInteraction,
1420
- codeWidgetSnapshotSchema,
1421
- resolveResponsive as resolveResponsive3,
1422
- safeUrl as safeUrl10,
1423
- upgradeNodes,
1424
- validateSettingValue as validateSettingValue2,
1425
- walkNodes as walkNodes3
1426
- } from "@usethrottle/builder-schema";
1427
-
1428
1739
  // src/code/code-widget.tsx
1429
1740
  import { Suspense as Suspense2 } from "react";
1430
1741
  import { LIMITS } from "@usethrottle/builder-schema";
1431
1742
 
1432
1743
  // src/custom/custom-css.tsx
1433
1744
  import { sanitizeWidgetCss } from "@usethrottle/builder-schema";
1434
- import { jsx as jsx20 } from "react/jsx-runtime";
1745
+ import { jsx as jsx21 } from "react/jsx-runtime";
1435
1746
  function scopedCss(source, type) {
1436
1747
  if (source === void 0 || source === "") return "";
1437
1748
  if (typeof source !== "string") return null;
@@ -1439,11 +1750,11 @@ function scopedCss(source, type) {
1439
1750
  return result.ok ? result.css : null;
1440
1751
  }
1441
1752
  function CustomCss({ css }) {
1442
- return /* @__PURE__ */ jsx20(WidgetStyle, { css });
1753
+ return /* @__PURE__ */ jsx21(WidgetStyle, { css });
1443
1754
  }
1444
1755
 
1445
1756
  // src/custom/interpreter.tsx
1446
- import { Fragment as Fragment14, createElement as createElement2 } from "react";
1757
+ import { Fragment as Fragment15, createElement as createElement2 } from "react";
1447
1758
  import {
1448
1759
  ALLOWED_ATTRS,
1449
1760
  ALLOWED_ELEMENTS,
@@ -1454,9 +1765,9 @@ import {
1454
1765
  RESERVED_DATA_PREFIX,
1455
1766
  VOID_ELEMENTS,
1456
1767
  isReservedClass,
1457
- safeUrl as safeUrl8
1768
+ safeUrl as safeUrl9
1458
1769
  } from "@usethrottle/builder-schema";
1459
- import { jsx as jsx21 } from "react/jsx-runtime";
1770
+ import { jsx as jsx22 } from "react/jsx-runtime";
1460
1771
  var MAX_OUTPUT_CHARS = 1e6;
1461
1772
  var MAX_ATTR_CHARS = 2e3;
1462
1773
  var MAX_DEPTH3 = 24;
@@ -1539,7 +1850,7 @@ function attrAllowed(tag, name) {
1539
1850
  return (ALLOWED_ATTRS["*"]?.includes(name) ?? false) || (own?.includes(name) ?? false);
1540
1851
  }
1541
1852
  function attrText(attr, env, scope) {
1542
- return attr.value.map((part) => part.type === "text" ? part.value : filtered(lookup(part.path, env, scope), part.filters)).join("");
1853
+ return attr.value.map((part2) => part2.type === "text" ? part2.value : filtered(lookup(part2.path, env, scope), part2.filters)).join("");
1543
1854
  }
1544
1855
  function urlSource(attr, env, scope) {
1545
1856
  const [only] = attr.value;
@@ -1556,7 +1867,7 @@ function attrProp(tag, attr, env, scope) {
1556
1867
  const { name } = attr;
1557
1868
  if (!attrAllowed(tag, name)) return null;
1558
1869
  if (name === "href" || name === "src") {
1559
- const safe = safeUrl8(urlSource(attr, env, scope), name, { mediaOrigin: env.mediaOrigin });
1870
+ const safe = safeUrl9(urlSource(attr, env, scope), name, { mediaOrigin: env.mediaOrigin });
1560
1871
  return safe === null || !spend(env, safe.length) ? null : [name, safe];
1561
1872
  }
1562
1873
  const text2 = attrText(attr, env, scope);
@@ -1605,21 +1916,21 @@ function renderNodes(nodes, env, scope, depth) {
1605
1916
  }
1606
1917
  case "if": {
1607
1918
  const branch = truthy(lookup(node.path, env, scope)) ? node.then : node.else;
1608
- out.push(/* @__PURE__ */ jsx21(Fragment14, { children: renderNodes(branch, env, scope, depth + 1) }, out.length));
1919
+ out.push(/* @__PURE__ */ jsx22(Fragment15, { children: renderNodes(branch, env, scope, depth + 1) }, out.length));
1609
1920
  break;
1610
1921
  }
1611
1922
  case "unless":
1612
1923
  if (!truthy(lookup(node.path, env, scope))) {
1613
- out.push(/* @__PURE__ */ jsx21(Fragment14, { children: renderNodes(node.body, env, scope, depth + 1) }, out.length));
1924
+ out.push(/* @__PURE__ */ jsx22(Fragment15, { children: renderNodes(node.body, env, scope, depth + 1) }, out.length));
1614
1925
  }
1615
1926
  break;
1616
1927
  case "each": {
1617
- const list = lookup(node.path, env, scope);
1618
- if (!Array.isArray(list)) break;
1619
- const count = Math.min(list.length, EACH_ITERATION_CAP);
1928
+ const list2 = lookup(node.path, env, scope);
1929
+ if (!Array.isArray(list2)) break;
1930
+ const count = Math.min(list2.length, EACH_ITERATION_CAP);
1620
1931
  for (let i = 0; i < count && !env.stopped; i += 1) {
1621
- const inner = new Map(scope).set(node.as, list[i]);
1622
- out.push(/* @__PURE__ */ jsx21(Fragment14, { children: renderNodes(node.body, env, inner, depth + 1) }, out.length));
1932
+ const inner = new Map(scope).set(node.as, list2[i]);
1933
+ out.push(/* @__PURE__ */ jsx22(Fragment15, { children: renderNodes(node.body, env, inner, depth + 1) }, out.length));
1623
1934
  }
1624
1935
  break;
1625
1936
  }
@@ -1637,7 +1948,46 @@ function renderTemplate(ast, env) {
1637
1948
  // src/custom/template-widget.tsx
1638
1949
  import { Suspense } from "react";
1639
1950
  import { MAX_TEMPLATE_WEIGHT as MAX_TEMPLATE_WEIGHT2, parseTemplate, templateWeight as templateWeight2, validateTemplate } from "@usethrottle/builder-schema";
1640
- import { Fragment as Fragment15, jsx as jsx22, jsxs as jsxs14 } from "react/jsx-runtime";
1951
+
1952
+ // src/part-view.tsx
1953
+ import { Component } from "react";
1954
+ import { jsx as jsx23 } from "react/jsx-runtime";
1955
+ var BoundaryBase = Component ?? class {
1956
+ };
1957
+ var Boundary = class extends BoundaryBase {
1958
+ constructor() {
1959
+ super(...arguments);
1960
+ __publicField(this, "state", { failed: false });
1961
+ }
1962
+ static getDerivedStateFromError() {
1963
+ return { failed: true };
1964
+ }
1965
+ componentDidCatch(error, _info) {
1966
+ warnOnce(`part:${this.props.label}`, `${this.props.label} failed to render (${String(error)}); rendering nothing for it`);
1967
+ try {
1968
+ this.props.onError?.(error, { part: this.props.label });
1969
+ } catch {
1970
+ }
1971
+ }
1972
+ componentDidUpdate(previous) {
1973
+ const moved = previous.resetKeys.length !== this.props.resetKeys.length || previous.resetKeys.some((key, i) => !Object.is(key, this.props.resetKeys[i]));
1974
+ if (moved && this.state.failed) this.setState({ failed: false });
1975
+ }
1976
+ render() {
1977
+ return this.state.failed ? null : this.props.children;
1978
+ }
1979
+ };
1980
+ function PartBoundary({
1981
+ label,
1982
+ resetKey,
1983
+ children
1984
+ }) {
1985
+ const builder = useBuilder();
1986
+ return /* @__PURE__ */ jsx23(Boundary, { label, resetKeys: [builder?.site, resetKey], onError: builder?.onError, children });
1987
+ }
1988
+
1989
+ // src/custom/template-widget.tsx
1990
+ import { Fragment as Fragment16, jsx as jsx24, jsxs as jsxs15 } from "react/jsx-runtime";
1641
1991
  var componentWeights = /* @__PURE__ */ new WeakMap();
1642
1992
  var compiled = /* @__PURE__ */ new WeakMap();
1643
1993
  function compileTemplate(snapshot, registry) {
@@ -1678,19 +2028,20 @@ function TemplateBody({ snapshot, registry, props, data, locale, mediaOrigin, bu
1678
2028
  const template = compileTemplate(snapshot, registry);
1679
2029
  if (template === null) return null;
1680
2030
  const env = newEnv({ settings: props, data, locale, mediaOrigin, budget: budget ?? new RenderBudget() });
1681
- return /* @__PURE__ */ jsxs14(Fragment15, { children: [
1682
- template.css === "" ? null : /* @__PURE__ */ jsx22(CustomCss, { css: template.css }),
2031
+ return /* @__PURE__ */ jsxs15(Fragment16, { children: [
2032
+ template.css === "" ? null : /* @__PURE__ */ jsx24(CustomCss, { css: template.css }),
1683
2033
  renderTemplate(template.ast, env)
1684
2034
  ] });
1685
2035
  }
1686
2036
  function TemplateWidget(props) {
1687
- return /* @__PURE__ */ jsx22(PartBoundary, { label: `${props.snapshot.type}@${String(props.snapshot.v)}`, children: /* @__PURE__ */ jsx22(Suspense, { fallback: null, children: /* @__PURE__ */ jsx22(TemplateBody, { ...props }) }) });
2037
+ return /* @__PURE__ */ jsx24(PartBoundary, { label: `${props.snapshot.type}@${String(props.snapshot.v)}`, children: /* @__PURE__ */ jsx24(Suspense, { fallback: null, children: /* @__PURE__ */ jsx24(TemplateBody, { ...props }) }) });
1688
2038
  }
1689
2039
 
1690
2040
  // src/code/leave.ts
1691
2041
  import { useEffect as useEffect3, useRef as useRef2 } from "react";
1692
2042
 
1693
2043
  // src/code/routes.ts
2044
+ import { CODE_TEMPLATE_DENY } from "@usethrottle/builder-schema";
1694
2045
  var CODE_ROUTE_DENY = /^(checkout|cart|basket|bag|account|my-?account|sign[-_]?in|sign[-_]?up|log[-_]?in|log[-_]?out|register|orders?|pay|payments?|password|wallet)([;.\s].*)?$|^(confirm|thank|receipt|invoice|quote).*$|^order[-_].*$/i;
1695
2046
  var DEFAULT_CATALOG_ROUTES = [
1696
2047
  "/p/{handle}",
@@ -1737,7 +2088,7 @@ function matcherOf(template) {
1737
2088
  if (known !== void 0) return known;
1738
2089
  let regex = null;
1739
2090
  if (template.startsWith("/")) {
1740
- const pattern = template.split(/(\{[A-Za-z][A-Za-z0-9]*\})/).map((part) => /^\{[A-Za-z][A-Za-z0-9]*\}$/.test(part) ? "[^/]+" : escapeRegExp(part)).join("").replace(/\/+$/, "");
2091
+ const pattern = template.split(/(\{[A-Za-z][A-Za-z0-9]*\})/).map((part2) => /^\{[A-Za-z][A-Za-z0-9]*\}$/.test(part2) ? "[^/]+" : escapeRegExp(part2)).join("").replace(/\/+$/, "");
1741
2092
  regex = new RegExp(`^${pattern === "" ? "/" : pattern}$`);
1742
2093
  }
1743
2094
  if (compiled2.size >= MAX_COMPILED) compiled2.clear();
@@ -1745,13 +2096,27 @@ function matcherOf(template) {
1745
2096
  return regex;
1746
2097
  }
1747
2098
  var matchesTemplate = (path, template) => matcherOf(template)?.test(path) ?? false;
2099
+ function buildRouteTable(store, catalog = {}) {
2100
+ return { ...catalog, ...store };
2101
+ }
2102
+ var isDeniedTemplate = (name) => CODE_TEMPLATE_DENY.includes(name);
2103
+ function isDeniedByRouteTable(path, routeTable) {
2104
+ if (routeTable === void 0) return false;
2105
+ return Object.entries(routeTable).some(([name, template]) => {
2106
+ if (!isDeniedTemplate(name) || typeof template !== "string") return false;
2107
+ const base = template.replace(/\/+$/, "");
2108
+ return matchesTemplate(path, template) || path.startsWith(`${base}/`);
2109
+ });
2110
+ }
1748
2111
  function isCodeRoute(pathname, routes) {
1749
2112
  if (pathname === void 0) return false;
2113
+ if (routes.templateName !== void 0 && isDeniedTemplate(routes.templateName)) return false;
1750
2114
  const path = normalizePath(pathname);
1751
2115
  if (path === null) return false;
2116
+ if (isDeniedByRouteTable(path, routes.routeTable)) return false;
1752
2117
  if (path.split("/").some((segment) => CODE_ROUTE_DENY.test(segment))) return false;
1753
2118
  if (path === "/") return true;
1754
- return [routes.page, ...routes.catalog ?? DEFAULT_CATALOG_ROUTES].some(
2119
+ return [routes.page, ...routes.catalog ?? DEFAULT_CATALOG_ROUTES, ...routes.allow ?? []].some(
1755
2120
  (template) => matchesTemplate(path, template)
1756
2121
  );
1757
2122
  }
@@ -1763,13 +2128,13 @@ function markCodeEmitted() {
1763
2128
  }
1764
2129
 
1765
2130
  // src/code/code-widget.tsx
1766
- import { jsx as jsx23, jsxs as jsxs15 } from "react/jsx-runtime";
2131
+ import { jsx as jsx25, jsxs as jsxs16 } from "react/jsx-runtime";
1767
2132
  var SHA256_HEX = /^[0-9a-f]{64}$/;
1768
2133
  var CUSTOM_TYPE = /^custom\.[a-z][a-z0-9-]{0,63}$/;
1769
2134
  var SCRIPT_ORIGIN = /^https:\/\/[a-z0-9]([a-z0-9.-]*[a-z0-9])?(:[0-9]{1,5})?$/i;
1770
2135
  var SITE_ID = /^[A-Za-z0-9_-]{1,64}$/;
1771
2136
  var MAX_INPUT_CHARS = 2e5;
1772
- var isRecord2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
2137
+ var isRecord3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
1773
2138
  var checked = /* @__PURE__ */ new WeakMap();
1774
2139
  function check(raw, registry) {
1775
2140
  let perRegistry = checked.get(raw);
@@ -1803,7 +2168,7 @@ function verify(raw, registry) {
1803
2168
  return { status: "ok", snapshot: raw, template };
1804
2169
  }
1805
2170
  function codeScriptUrl(runtime, jsHash) {
1806
- if (!isRecord2(runtime) || runtime.enabled !== true) return null;
2171
+ if (!isRecord3(runtime) || runtime.enabled !== true) return null;
1807
2172
  const { scriptOrigin, codeSiteId } = runtime;
1808
2173
  if (typeof scriptOrigin !== "string" || !SCRIPT_ORIGIN.test(scriptOrigin)) return null;
1809
2174
  if (typeof codeSiteId !== "string" || !SITE_ID.test(codeSiteId)) return null;
@@ -1826,21 +2191,21 @@ var BADGE = {
1826
2191
  function runs(props, jsHash) {
1827
2192
  const { code, edit, interactive } = props;
1828
2193
  if (edit !== void 0 || interactive === false || code === void 0 || code.preview === true) return null;
1829
- if (!isCodeRoute(code.pathname, code.routes)) return null;
2194
+ if (!isCodeRoute(code.pathname, { ...code.routes, templateName: code.templateName })) return null;
1830
2195
  return codeScriptUrl(code.runtime, jsHash);
1831
2196
  }
1832
2197
  function CodeWidget(props) {
1833
2198
  const { node, snapshot, registry, edit, anchor, copyAnchor, entrance } = props;
1834
2199
  const result = check(snapshot, registry);
1835
2200
  if (result.status !== "ok") {
1836
- return result.status === "disabled" && edit !== void 0 ? /* @__PURE__ */ jsx23(NodeWrapper, { id: node.id, part: "widget", type: node.type, className: "tb-w", edit, children: /* @__PURE__ */ jsx23("div", { className: "tb-missing", children: "This code widget is disabled" }) }) : null;
2201
+ return result.status === "disabled" && edit !== void 0 ? /* @__PURE__ */ jsx25(NodeWrapper, { id: node.id, part: "widget", type: node.type, className: "tb-w", edit, children: /* @__PURE__ */ jsx25("div", { className: "tb-missing", children: "This code widget is disabled" }) }) : null;
1837
2202
  }
1838
2203
  const template = compileTemplate(result.template, registry);
1839
2204
  const src = runs(props, result.snapshot.jsHash);
1840
2205
  if (src !== null) markCodeEmitted();
1841
2206
  const env = newEnv({ settings: props.props, data: props.data, locale: props.locale, mediaOrigin: props.mediaOrigin, budget: new RenderBudget() });
1842
2207
  const label = `${node.type}@${String(node.v)}`;
1843
- return /* @__PURE__ */ jsxs15(
2208
+ return /* @__PURE__ */ jsxs16(
1844
2209
  NodeWrapper,
1845
2210
  {
1846
2211
  id: node.id,
@@ -1854,13 +2219,13 @@ function CodeWidget(props) {
1854
2219
  entrance,
1855
2220
  attributes: src === null ? { "data-b-code-inert": "" } : { "data-b-code": result.snapshot.jsHash },
1856
2221
  children: [
1857
- /* @__PURE__ */ jsx23(PartBoundary, { label, children: /* @__PURE__ */ jsxs15(Suspense2, { fallback: null, children: [
1858
- template.css === "" ? null : /* @__PURE__ */ jsx23(CustomCss, { css: template.css }),
2222
+ /* @__PURE__ */ jsx25(PartBoundary, { label, children: /* @__PURE__ */ jsxs16(Suspense2, { fallback: null, children: [
2223
+ template.css === "" ? null : /* @__PURE__ */ jsx25(CustomCss, { css: template.css }),
1859
2224
  renderTemplate(template.ast, env)
1860
2225
  ] }) }),
1861
- src === null && (edit !== void 0 || props.code?.preview === true) ? /* @__PURE__ */ jsx23("div", { "data-b-code-badge": "", style: BADGE, children: "Runs on your store" }) : null,
1862
- src === null ? null : /* @__PURE__ */ jsx23(CodeInput, { props: props.props, data: props.data, label }),
1863
- src === null ? null : /* @__PURE__ */ jsx23("script", { async: true, src })
2226
+ src === null && (edit !== void 0 || props.code?.preview === true) ? /* @__PURE__ */ jsx25("div", { "data-b-code-badge": "", style: BADGE, children: "Runs on your store" }) : null,
2227
+ src === null ? null : /* @__PURE__ */ jsx25(CodeInput, { props: props.props, data: props.data, label }),
2228
+ src === null ? null : /* @__PURE__ */ jsx25("script", { async: true, src })
1864
2229
  ]
1865
2230
  }
1866
2231
  );
@@ -1877,7 +2242,7 @@ function CodeInput({ props, data, label }) {
1877
2242
  warnOnce(`code-input:${label}`, `The input of ${label} cannot be written as JSON; it gets none`);
1878
2243
  json = jsonForScript({ props: {}, data: {} });
1879
2244
  }
1880
- return /* @__PURE__ */ jsx23("script", { type: "application/json", "data-b-code-input": "", children: json });
2245
+ return /* @__PURE__ */ jsx25("script", { type: "application/json", "data-b-code-input": "", children: json });
1881
2246
  }
1882
2247
 
1883
2248
  // src/css-compiler.ts
@@ -1886,7 +2251,7 @@ import {
1886
2251
  resolveColumnProps,
1887
2252
  resolveColumnWidths,
1888
2253
  resolveResponsive as resolveResponsive2,
1889
- safeUrl as safeUrl9,
2254
+ safeUrl as safeUrl10,
1890
2255
  validateSettingValue,
1891
2256
  wrapColumnRows
1892
2257
  } from "@usethrottle/builder-schema";
@@ -1995,7 +2360,7 @@ function backgroundDecls(out, bg, assets, mediaOrigin) {
1995
2360
  if (bg.position !== void 0 && BG_POSITION.has(bg.position)) put(out, "--tb-bgpos", bg.position);
1996
2361
  if (bg.size !== void 0 && BG_SIZE.has(bg.size)) put(out, "--tb-bgsize", bg.size);
1997
2362
  const asset = bg.image === void 0 || assets === void 0 || !Object.hasOwn(assets, bg.image) ? void 0 : assets[bg.image];
1998
- if (asset !== void 0 && safeUrl9(asset.url, "src", { mediaOrigin }) !== null && URL_QUOTE_SAFE.test(asset.url)) {
2363
+ if (asset !== void 0 && safeUrl10(asset.url, "src", { mediaOrigin }) !== null && URL_QUOTE_SAFE.test(asset.url)) {
1999
2364
  out.set("--tb-bgimg", `url("${asset.url}")`);
2000
2365
  }
2001
2366
  }
@@ -2103,22 +2468,22 @@ function compileResponsiveCss(doc, registry, assets = doc.assets, mediaOrigin =
2103
2468
  }
2104
2469
 
2105
2470
  // src/interactions/accordion.tsx
2106
- import { jsx as jsx24, jsxs as jsxs16 } from "react/jsx-runtime";
2471
+ import { jsx as jsx26, jsxs as jsxs17 } from "react/jsx-runtime";
2107
2472
  function Accordion({
2108
2473
  id,
2109
2474
  panels,
2110
2475
  multiple,
2111
2476
  openFirst
2112
2477
  }) {
2113
- return /* @__PURE__ */ jsx24("div", { className: "tb-accordion", children: panels.map((panel, i) => /* @__PURE__ */ jsxs16(
2478
+ return /* @__PURE__ */ jsx26("div", { className: "tb-accordion", children: panels.map((panel, i) => /* @__PURE__ */ jsxs17(
2114
2479
  "details",
2115
2480
  {
2116
2481
  className: "tb-acc-item",
2117
2482
  ...multiple ? {} : { name: `${id}-acc` },
2118
2483
  ...openFirst && i === 0 ? { open: true } : {},
2119
2484
  children: [
2120
- /* @__PURE__ */ jsx24("summary", { className: "tb-acc-sum", children: panel.title }),
2121
- /* @__PURE__ */ jsx24("div", { className: "tb-acc-body", children: panel.node })
2485
+ /* @__PURE__ */ jsx26("summary", { className: "tb-acc-sum", children: panel.title }),
2486
+ /* @__PURE__ */ jsx26("div", { className: "tb-acc-body", children: panel.node })
2122
2487
  ]
2123
2488
  },
2124
2489
  panel.key
@@ -2126,13 +2491,13 @@ function Accordion({
2126
2491
  }
2127
2492
 
2128
2493
  // src/interactions/carousel.tsx
2129
- import { jsx as jsx25, jsxs as jsxs17 } from "react/jsx-runtime";
2494
+ import { jsx as jsx27, jsxs as jsxs18 } from "react/jsx-runtime";
2130
2495
  function Carousel({
2131
2496
  panels,
2132
2497
  autoplayMs,
2133
2498
  loop
2134
2499
  }) {
2135
- return /* @__PURE__ */ jsxs17(
2500
+ return /* @__PURE__ */ jsxs18(
2136
2501
  "div",
2137
2502
  {
2138
2503
  className: "tb-car",
@@ -2143,7 +2508,7 @@ function Carousel({
2143
2508
  ...loop ? { "data-b-loop": "" } : {},
2144
2509
  ...autoplayMs === null ? {} : { "data-b-autoplay": String(autoplayMs) },
2145
2510
  children: [
2146
- /* @__PURE__ */ jsx25("div", { className: "tb-car-track", tabIndex: 0, children: panels.map((panel, i) => /* @__PURE__ */ jsx25(
2511
+ /* @__PURE__ */ jsx27("div", { className: "tb-car-track", tabIndex: 0, children: panels.map((panel, i) => /* @__PURE__ */ jsx27(
2147
2512
  "div",
2148
2513
  {
2149
2514
  className: "tb-slide",
@@ -2154,44 +2519,160 @@ function Carousel({
2154
2519
  },
2155
2520
  panel.key
2156
2521
  )) }),
2157
- /* @__PURE__ */ jsxs17("div", { className: "tb-car-ctrl", children: [
2158
- /* @__PURE__ */ jsx25("button", { type: "button", className: "tb-car-btn", "data-b-act": "prev", "aria-label": "Previous slide", children: "\u2039" }),
2159
- autoplayMs === null ? null : /* @__PURE__ */ jsx25("button", { type: "button", className: "tb-car-btn tb-car-pause", "data-b-act": "pause", hidden: true, children: "Pause" }),
2160
- /* @__PURE__ */ jsx25("button", { type: "button", className: "tb-car-btn", "data-b-act": "next", "aria-label": "Next slide", children: "\u203A" })
2522
+ /* @__PURE__ */ jsxs18("div", { className: "tb-car-ctrl", children: [
2523
+ /* @__PURE__ */ jsx27("button", { type: "button", className: "tb-car-btn", "data-b-act": "prev", "aria-label": "Previous slide", children: "\u2039" }),
2524
+ autoplayMs === null ? null : /* @__PURE__ */ jsx27("button", { type: "button", className: "tb-car-btn tb-car-pause", "data-b-act": "pause", hidden: true, children: "Pause" }),
2525
+ /* @__PURE__ */ jsx27("button", { type: "button", className: "tb-car-btn", "data-b-act": "next", "aria-label": "Next slide", children: "\u203A" })
2161
2526
  ] })
2162
2527
  ]
2163
2528
  }
2164
2529
  );
2165
2530
  }
2166
2531
 
2167
- // src/interactions/tabs.tsx
2168
- import { jsx as jsx26, jsxs as jsxs18 } from "react/jsx-runtime";
2169
- function Tabs({ id, panels }) {
2170
- return /* @__PURE__ */ jsxs18("div", { className: "tb-tabs", children: [
2171
- /* @__PURE__ */ jsx26("div", { role: "tablist", className: "tb-tablist", "data-b-tabs": "", children: panels.map((panel, i) => /* @__PURE__ */ jsx26(
2172
- "button",
2173
- {
2174
- type: "button",
2175
- role: "tab",
2176
- className: "tb-tab",
2177
- id: `${id}-t${String(i)}`,
2178
- "aria-controls": `${id}-p${String(i)}`,
2179
- "aria-selected": i === 0,
2180
- tabIndex: i === 0 ? 0 : -1,
2181
- children: panel.title
2182
- },
2183
- panel.key
2184
- )) }),
2185
- panels.map((panel, i) => /* @__PURE__ */ jsxs18(
2186
- "div",
2187
- {
2188
- role: "tabpanel",
2189
- className: "tb-panel",
2190
- id: `${id}-p${String(i)}`,
2532
+ // src/interactions/frame.tsx
2533
+ import { useEffect as useEffect4 } from "react";
2534
+
2535
+ // src/interactions/drawer.ts
2536
+ var holds3 = 0;
2537
+ var release2;
2538
+ var rootOf = (el) => el?.closest("[data-tb-collapse]") ?? null;
2539
+ function setOpen(root, open) {
2540
+ const opener = root.querySelector("[data-tb-drawer-open]");
2541
+ const body = root.querySelector(".tb-fr-body");
2542
+ if (open) root.setAttribute("data-open", "true");
2543
+ else root.removeAttribute("data-open");
2544
+ opener?.setAttribute("aria-expanded", String(open));
2545
+ if (body !== null) {
2546
+ if (open) {
2547
+ body.setAttribute("role", "dialog");
2548
+ body.setAttribute("aria-modal", "true");
2549
+ const name = opener?.textContent?.trim();
2550
+ if (name !== void 0 && name !== "") body.setAttribute("aria-label", name);
2551
+ } else {
2552
+ body.removeAttribute("role");
2553
+ body.removeAttribute("aria-modal");
2554
+ body.removeAttribute("aria-label");
2555
+ }
2556
+ }
2557
+ if (open) root.querySelector("[data-tb-drawer-close]")?.focus();
2558
+ else opener?.focus();
2559
+ }
2560
+ var openRoot = () => document.querySelector("[data-tb-collapse][data-open=true]");
2561
+ function install2() {
2562
+ const click = (event) => {
2563
+ const el = event.target instanceof Element ? event.target : null;
2564
+ if (el === null) return;
2565
+ const root = rootOf(el);
2566
+ if (root === null) return;
2567
+ if (el.closest("[data-tb-drawer-open]") !== null) setOpen(root, root.getAttribute("data-open") !== "true");
2568
+ else if (el.closest("[data-tb-drawer-close]") !== null) setOpen(root, false);
2569
+ else if (root.getAttribute("data-open") === "true" && el.closest(".tb-fr-body a[href]") !== null) setOpen(root, false);
2570
+ };
2571
+ const keydown = (event) => {
2572
+ const root = openRoot();
2573
+ if (root === null) return;
2574
+ if (event.key === "Escape") {
2575
+ setOpen(root, false);
2576
+ return;
2577
+ }
2578
+ const body = root.querySelector(".tb-fr-body");
2579
+ if (body !== null) trapTab(event, focusablesOf(body));
2580
+ };
2581
+ document.addEventListener("click", click);
2582
+ document.addEventListener("keydown", keydown);
2583
+ return () => {
2584
+ document.removeEventListener("click", click);
2585
+ document.removeEventListener("keydown", keydown);
2586
+ };
2587
+ }
2588
+ function startDrawer() {
2589
+ if (holds3++ === 0) release2 = install2();
2590
+ let done = false;
2591
+ return () => {
2592
+ if (done) return;
2593
+ done = true;
2594
+ if (--holds3 === 0) {
2595
+ release2?.();
2596
+ release2 = void 0;
2597
+ }
2598
+ };
2599
+ }
2600
+
2601
+ // src/interactions/frame.tsx
2602
+ import { Fragment as Fragment17, jsx as jsx28, jsxs as jsxs19 } from "react/jsx-runtime";
2603
+ var SECTION_ID_RE = /^[A-Za-z0-9_-]{1,64}$/;
2604
+ var TABLET_PX = 1024;
2605
+ var PHONE_PX = 768;
2606
+ var isRecord4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
2607
+ function frameOf(section) {
2608
+ const raw = section.frame;
2609
+ if (!isRecord4(raw)) return null;
2610
+ const sticky = raw.sticky === "top";
2611
+ const c = raw.collapse;
2612
+ let collapse = null;
2613
+ if (isRecord4(c) && SECTION_ID_RE.test(section.id)) {
2614
+ const at = typeof c.belowPx === "number" && Number.isInteger(c.belowPx) && c.belowPx >= 768 && c.belowPx <= 1280 ? c.belowPx : c.below === "tablet" ? TABLET_PX : c.below === "phone" ? PHONE_PX : null;
2615
+ if (at !== null) collapse = { px: (at - 0.02).toFixed(2), label: isRecord4(c.label) ? c.label : {} };
2616
+ }
2617
+ return sticky || collapse !== null ? { sticky, collapse } : null;
2618
+ }
2619
+ var FRAME_CSS = `@layer throttle{
2620
+ .tb-sticky{position:sticky;inset-block-start:0;z-index:40}
2621
+ [data-throttle-part=builder-header]:has(.tb-sticky){position:sticky;inset-block-start:0;z-index:40}
2622
+ .tb-fr-open,.tb-fr-close{display:none;align-items:center;justify-content:center;min-inline-size:44px;min-block-size:44px;padding:0 var(--tb-space-s);border:0;background:transparent;color:inherit;font:inherit;cursor:pointer}
2623
+ .tb-fr-open:focus-visible,.tb-fr-close:focus-visible{outline:2px solid var(--tb-color-primary,currentColor);outline-offset:2px}
2624
+ }`;
2625
+ function collapseCss(sectionId, px2) {
2626
+ const s = `[data-b-id="${sectionId}"]`;
2627
+ return `@layer throttle{@media (max-width: ${px2}px){@media (scripting: enabled){${s} .tb-fr-open{display:inline-flex}${s} .tb-fr-body{display:none}${s} .tb-fr[data-open=true] .tb-fr-body{display:block;position:fixed;inset:0;z-index:60;overflow:auto;padding:4.5rem var(--tb-space-m) var(--tb-space-m);background:var(--tb-color-background,#fff);color:var(--tb-color-foreground,#111)}${s} .tb-fr[data-open=true] .tb-fr-close{display:inline-flex;position:fixed;inset-block-start:var(--tb-space-s);inset-inline-end:var(--tb-space-s);z-index:61}}}}`;
2628
+ }
2629
+ function DrawerRuntime() {
2630
+ useEffect4(() => startDrawer(), []);
2631
+ return null;
2632
+ }
2633
+ function Collapse(props) {
2634
+ const { sectionId, id, px: px2, label, children } = props;
2635
+ return /* @__PURE__ */ jsxs19(Fragment17, { children: [
2636
+ /* @__PURE__ */ jsx28("style", { href: `tb-fr-${sectionId}`, precedence: "throttle", children: collapseCss(sectionId, px2) }),
2637
+ /* @__PURE__ */ jsxs19("div", { className: "tb-fr", "data-tb-collapse": "", children: [
2638
+ /* @__PURE__ */ jsx28("button", { type: "button", className: "tb-fr-open", "data-tb-drawer-open": "", "aria-expanded": "false", "aria-controls": id, children: label }),
2639
+ /* @__PURE__ */ jsxs19("div", { id, className: "tb-fr-body", children: [
2640
+ /* @__PURE__ */ jsx28("button", { type: "button", className: "tb-fr-close", "data-tb-drawer-close": "", "aria-label": "Close", children: /* @__PURE__ */ jsx28("span", { "aria-hidden": "true", children: "\xD7" }) }),
2641
+ children
2642
+ ] }),
2643
+ /* @__PURE__ */ jsx28(DrawerRuntime, {})
2644
+ ] })
2645
+ ] });
2646
+ }
2647
+
2648
+ // src/interactions/tabs.tsx
2649
+ import { jsx as jsx29, jsxs as jsxs20 } from "react/jsx-runtime";
2650
+ function Tabs({ id, panels }) {
2651
+ return /* @__PURE__ */ jsxs20("div", { className: "tb-tabs", children: [
2652
+ /* @__PURE__ */ jsx29("div", { role: "tablist", className: "tb-tablist", "data-b-tabs": "", children: panels.map((panel, i) => /* @__PURE__ */ jsx29(
2653
+ "button",
2654
+ {
2655
+ type: "button",
2656
+ role: "tab",
2657
+ className: "tb-tab",
2658
+ id: `${id}-t${String(i)}`,
2659
+ "aria-controls": `${id}-p${String(i)}`,
2660
+ "aria-selected": i === 0,
2661
+ tabIndex: i === 0 ? 0 : -1,
2662
+ children: panel.title
2663
+ },
2664
+ panel.key
2665
+ )) }),
2666
+ panels.map((panel, i) => /* @__PURE__ */ jsxs20(
2667
+ "div",
2668
+ {
2669
+ role: "tabpanel",
2670
+ className: "tb-panel",
2671
+ id: `${id}-p${String(i)}`,
2191
2672
  "aria-labelledby": `${id}-t${String(i)}`,
2192
2673
  tabIndex: 0,
2193
2674
  children: [
2194
- /* @__PURE__ */ jsx26("p", { className: "tb-panel-title", children: panel.title }),
2675
+ /* @__PURE__ */ jsx29("p", { className: "tb-panel-title", children: panel.title }),
2195
2676
  panel.node
2196
2677
  ]
2197
2678
  },
@@ -2201,19 +2682,94 @@ function Tabs({ id, panels }) {
2201
2682
  }
2202
2683
 
2203
2684
  // src/interactions/toggle.tsx
2204
- import { jsx as jsx27, jsxs as jsxs19 } from "react/jsx-runtime";
2685
+ import { jsx as jsx30, jsxs as jsxs21 } from "react/jsx-runtime";
2205
2686
  function Toggle({
2206
2687
  labelOpen,
2207
2688
  labelClosed,
2208
2689
  startOpen,
2209
2690
  children
2210
2691
  }) {
2211
- return /* @__PURE__ */ jsxs19("details", { className: "tb-toggle", ...startOpen ? { open: true } : {}, children: [
2212
- /* @__PURE__ */ jsxs19("summary", { className: "tb-toggle-sum", children: [
2213
- /* @__PURE__ */ jsx27("span", { className: "tb-toggle-closed", children: labelClosed }),
2214
- /* @__PURE__ */ jsx27("span", { className: "tb-toggle-open", children: labelOpen })
2692
+ return /* @__PURE__ */ jsxs21("details", { className: "tb-toggle", ...startOpen ? { open: true } : {}, children: [
2693
+ /* @__PURE__ */ jsxs21("summary", { className: "tb-toggle-sum", children: [
2694
+ /* @__PURE__ */ jsx30("span", { className: "tb-toggle-closed", children: labelClosed }),
2695
+ /* @__PURE__ */ jsx30("span", { className: "tb-toggle-open", children: labelOpen })
2215
2696
  ] }),
2216
- /* @__PURE__ */ jsx27("div", { className: "tb-row", children })
2697
+ /* @__PURE__ */ jsx30("div", { className: "tb-row", children })
2698
+ ] });
2699
+ }
2700
+
2701
+ // src/show-when.tsx
2702
+ import { useEffect as useEffect5, useState as useState4 } from "react";
2703
+ import { SPACING_TOKENS, resolveResponsive as resolveResponsive3, showWhenSchema } from "@usethrottle/builder-schema";
2704
+ import { Fragment as Fragment18, jsx as jsx31, jsxs as jsxs22 } from "react/jsx-runtime";
2705
+ function parseShowWhen(value) {
2706
+ if (value === void 0) return null;
2707
+ const parsed2 = showWhenSchema.safeParse(value);
2708
+ if (!parsed2.success) return null;
2709
+ return parsed2.data.audience === "all" && parsed2.data.cart === "any" ? null : parsed2.data;
2710
+ }
2711
+ function showWhenState(when, viewer, mounted) {
2712
+ if (!mounted) return when.audience === "signed-in" || when.cart === "has-items" ? "placeholder" : "show";
2713
+ const known = viewer === null ? { signedIn: null, cartItemCount: null } : viewer ?? { signedIn: false, cartItemCount: 0 };
2714
+ let pending = false;
2715
+ if (when.audience !== "all") {
2716
+ if (known.signedIn === null) pending = pending || when.audience === "signed-in";
2717
+ else if ((known.signedIn ? "signed-in" : "guest") !== when.audience) return "hide";
2718
+ }
2719
+ if (when.cart !== "any") {
2720
+ if (known.cartItemCount === null) pending = pending || when.cart === "has-items";
2721
+ else if ((known.cartItemCount > 0 ? "has-items" : "empty") !== when.cart) return "hide";
2722
+ }
2723
+ return pending ? "placeholder" : "show";
2724
+ }
2725
+ var DEVICES3 = ["desktop", "tablet", "phone"];
2726
+ var isRec = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
2727
+ var list = (v) => Array.isArray(v) ? v.filter(isRec) : [];
2728
+ function lengthOf(value) {
2729
+ if (typeof value === "number") return Number.isFinite(value) && value > 0 ? `${String(Math.min(Math.round(value), 2e3))}px` : null;
2730
+ if (typeof value === "string" && value !== "none" && SPACING_TOKENS.includes(value)) return `var(--tb-space-${value})`;
2731
+ return null;
2732
+ }
2733
+ function heightAt(node, device) {
2734
+ const resolved = resolveResponsive3(isRec(node.props) ? node.props : {}, node.responsive, device);
2735
+ if (resolved.hidden === true) return null;
2736
+ const own = lengthOf(resolved.minHeight) ?? lengthOf(resolved.height);
2737
+ if (own !== null) return own;
2738
+ const columns = list(node.columns).map((c) => heightAt(c, device)).filter((h) => h !== null);
2739
+ if (columns.length > 0) return columns.length === 1 ? columns[0] : `max(${columns.join(",")})`;
2740
+ const stacked = list(node.children).map((c) => heightAt(c, device)).filter((h) => h !== null);
2741
+ if (stacked.length > 0) return stacked.length === 1 ? stacked[0] : `calc(${stacked.join(" + ")})`;
2742
+ return null;
2743
+ }
2744
+ function reservedHeights(node) {
2745
+ const found = DEVICES3.map((device) => [device, heightAt(node, device)]);
2746
+ if (found.every(([, h]) => h === null)) return {};
2747
+ return Object.fromEntries(found.map(([device, h]) => [device, h ?? "0px"]));
2748
+ }
2749
+ var SHOW_WHEN_CSS = "@layer throttle{.tb-sw{visibility:hidden;pointer-events:none;min-block-size:var(--tb-sw-h,0)}@media (max-width:1024px){.tb-sw{min-block-size:var(--tb-sw-ht,var(--tb-sw-h,0))}}@media (max-width:767px){.tb-sw{min-block-size:var(--tb-sw-hp,var(--tb-sw-ht,var(--tb-sw-h,0)))}}}";
2750
+ function ShowWhen({ when, heights, children }) {
2751
+ const viewer = useViewer();
2752
+ const [mounted, setMounted] = useState4(false);
2753
+ useEffect5(() => setMounted(true), []);
2754
+ const state = showWhenState(when, viewer, mounted);
2755
+ if (state === "show") return children;
2756
+ if (state === "hide") return null;
2757
+ const style = {
2758
+ ...heights.desktop === void 0 ? {} : { "--tb-sw-h": heights.desktop },
2759
+ ...heights.tablet === void 0 ? {} : { "--tb-sw-ht": heights.tablet },
2760
+ ...heights.phone === void 0 ? {} : { "--tb-sw-hp": heights.phone }
2761
+ };
2762
+ return /* @__PURE__ */ jsxs22(Fragment18, { children: [
2763
+ /* @__PURE__ */ jsx31("style", { href: "tb-showwhen", precedence: "throttle", children: SHOW_WHEN_CSS }),
2764
+ /* @__PURE__ */ jsx31(
2765
+ "div",
2766
+ {
2767
+ className: "tb-sw",
2768
+ "aria-hidden": "true",
2769
+ "data-b-showwhen": when.audience === "signed-in" ? "signed-in" : "has-items",
2770
+ ...Object.keys(style).length === 0 ? {} : { style }
2771
+ }
2772
+ )
2217
2773
  ] });
2218
2774
  }
2219
2775
 
@@ -2239,8 +2795,8 @@ var BASE_CSS = `@layer throttle{
2239
2795
  }`;
2240
2796
 
2241
2797
  // src/renderer.tsx
2242
- import { jsx as jsx28, jsxs as jsxs20 } from "react/jsx-runtime";
2243
- var DEVICES2 = ["desktop", "tablet", "phone"];
2798
+ import { jsx as jsx32, jsxs as jsxs23 } from "react/jsx-runtime";
2799
+ var DEVICES4 = ["desktop", "tablet", "phone"];
2244
2800
  var COMMON_BY_KEY2 = new Map(COMMON_WIDGET_SETTINGS2.map((f) => [f.key, f]));
2245
2801
  var withCustomCache = /* @__PURE__ */ new WeakMap();
2246
2802
  function registryFor(doc, base) {
@@ -2267,7 +2823,7 @@ function registryFor(doc, base) {
2267
2823
  }
2268
2824
  return registry;
2269
2825
  }
2270
- var isRecord3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
2826
+ var isRecord5 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
2271
2827
  function pickLocale(value, locale) {
2272
2828
  const lang = locale.split("-")[0] ?? locale;
2273
2829
  for (const key of [locale, lang, "en"]) {
@@ -2278,25 +2834,36 @@ function pickLocale(value, locale) {
2278
2834
  return "";
2279
2835
  }
2280
2836
  function onOrigin(asset, mediaOrigin) {
2281
- if (safeUrl10(asset.url, "src", { mediaOrigin }) === null) return null;
2282
- return { ...asset, variants: asset.variants.filter((v) => safeUrl10(v.url, "src", { mediaOrigin }) !== null) };
2837
+ if (safeUrl11(asset.url, "src", { mediaOrigin }) === null) return null;
2838
+ return { ...asset, variants: asset.variants.filter((v) => safeUrl11(v.url, "src", { mediaOrigin }) !== null) };
2839
+ }
2840
+ function prepareItem(field, item, ctx) {
2841
+ if (!isRecord5(item)) return item;
2842
+ const out = { ...item };
2843
+ for (const itemField of field.itemFields ?? []) {
2844
+ if (!Object.hasOwn(out, itemField.key)) continue;
2845
+ const prepared = prepare(itemField, out[itemField.key], ctx);
2846
+ out[itemField.key] = prepared;
2847
+ }
2848
+ return out;
2283
2849
  }
2284
2850
  function prepare(field, value, ctx) {
2285
2851
  if (field === void 0 || value === null) return value;
2286
- if (field.translatable === true && isRecord3(value)) return pickLocale(value, ctx.locale);
2852
+ if (field.control === "list" && Array.isArray(value)) return value.map((item) => prepareItem(field, item, ctx));
2853
+ if (field.translatable === true && isRecord5(value)) return pickLocale(value, ctx.locale);
2287
2854
  if (field.control === "image" && typeof value === "string") {
2288
2855
  const asset = Object.hasOwn(ctx.assets, value) ? ctx.assets[value] : void 0;
2289
2856
  return asset === void 0 ? null : onOrigin(asset, ctx.mediaOrigin);
2290
2857
  }
2291
- if (field.control === "link" && isRecord3(value) && typeof value.kind === "string") {
2292
- const target = value;
2293
- const raw = ctx.resolveLink?.(target) ?? (target.kind === "url" ? target.href : null);
2294
- return { ...value, href: safeUrl10(raw, "href", { mediaOrigin: ctx.mediaOrigin }) };
2858
+ if (field.control === "link" && isRecord5(value) && typeof value.kind === "string") {
2859
+ const target2 = value;
2860
+ const raw = ctx.resolveLink?.(target2) ?? (target2.kind === "url" ? target2.href : null);
2861
+ return { ...value, href: safeUrl11(raw, "href", { mediaOrigin: ctx.mediaOrigin }) };
2295
2862
  }
2296
2863
  return value;
2297
2864
  }
2298
2865
  function storedLinkPart(value) {
2299
- if (!isRecord3(value) || value.kind !== "page") return value;
2866
+ if (!isRecord5(value) || value.kind !== "page") return value;
2300
2867
  const { slug: _slug, href: _href, ...stored } = value;
2301
2868
  void _slug;
2302
2869
  void _href;
@@ -2305,7 +2872,7 @@ function storedLinkPart(value) {
2305
2872
  function settingsAt(node, fields, device, ctx) {
2306
2873
  const base = {};
2307
2874
  for (const field of fields.values()) base[field.key] = field.default;
2308
- const resolved = resolveResponsive3({ ...base, ...node.props }, node.responsive, device);
2875
+ const resolved = resolveResponsive4({ ...base, ...node.props }, node.responsive, device);
2309
2876
  const out = {};
2310
2877
  for (const [key, value] of Object.entries(resolved)) {
2311
2878
  const field = fields.get(key);
@@ -2319,7 +2886,7 @@ function settingsAt(node, fields, device, ctx) {
2319
2886
  function variantsOf(node, def, fields, ctx) {
2320
2887
  const markup = [...fields.values()].filter((f) => f.output === "markup").map((f) => f.key);
2321
2888
  const groups = /* @__PURE__ */ new Map();
2322
- for (const device of DEVICES2) {
2889
+ for (const device of DEVICES4) {
2323
2890
  const props = settingsAt(node, fields, device, ctx);
2324
2891
  const signature = stable(markup.map((key) => props[key] ?? null));
2325
2892
  const group = groups.get(signature);
@@ -2330,8 +2897,8 @@ function variantsOf(node, def, fields, ctx) {
2330
2897
  return [...groups.values()];
2331
2898
  }
2332
2899
  function hiddenEverywhere(props, responsive) {
2333
- return DEVICES2.every(
2334
- (device) => resolveResponsive3({ hidden: props.hidden ?? false }, responsive, device).hidden === true
2900
+ return DEVICES4.every(
2901
+ (device) => resolveResponsive4({ hidden: props.hidden ?? false }, responsive, device).hidden === true
2335
2902
  );
2336
2903
  }
2337
2904
  var variantClass = (variant) => `tb-v ${variant.devices.map((d) => `tb-only-${d}`).join(" ")}`;
@@ -2347,7 +2914,7 @@ function renderCodeWidget(node, snapshot, ctx, registry) {
2347
2914
  }
2348
2915
  const props = settingsAt(node, fields, "desktop", ctx);
2349
2916
  const anchor = props.anchor;
2350
- return /* @__PURE__ */ jsx28(
2917
+ return /* @__PURE__ */ jsx32(
2351
2918
  CodeWidget,
2352
2919
  {
2353
2920
  node,
@@ -2376,7 +2943,7 @@ function renderWidget(node, ctx, registry) {
2376
2943
  if (isDevelopment()) {
2377
2944
  warnOnce(`missing:${node.type}@${String(node.v)}`, `Unknown widget ${node.type} v${String(node.v)}; rendering nothing for it`);
2378
2945
  }
2379
- return /* @__PURE__ */ jsx28(NodeWrapper, { id: node.id, part: "widget", type: node.type, className: "tb-w", missing: true, children: ctx.edit !== void 0 && /* @__PURE__ */ jsx28("div", { className: "tb-missing", children: "Widget unavailable: update @usethrottle/storefront-react" }) });
2946
+ return /* @__PURE__ */ jsx32(NodeWrapper, { id: node.id, part: "widget", type: node.type, className: "tb-w", missing: true, children: ctx.edit !== void 0 && /* @__PURE__ */ jsx32("div", { className: "tb-missing", children: "Widget unavailable: update @usethrottle/storefront-react" }) });
2380
2947
  }
2381
2948
  if (ctx.edit === void 0 && hiddenEverywhere(node.props, node.responsive)) return null;
2382
2949
  const fields = new Map([...COMMON_BY_KEY2, ...def.settings.map((f) => [f.key, f])]);
@@ -2389,21 +2956,22 @@ function renderWidget(node, ctx, registry) {
2389
2956
  }
2390
2957
  const custom = node.type.startsWith("custom.");
2391
2958
  const edit = ctx.edit;
2392
- return variants.map((variant, index) => {
2959
+ const copies = variants.map((variant, index) => {
2393
2960
  const anchor = variant.props.anchor;
2394
- return /* @__PURE__ */ jsx28(
2961
+ return /* @__PURE__ */ jsx32(
2395
2962
  NodeWrapper,
2396
2963
  {
2397
2964
  id: node.id,
2398
2965
  part: "widget",
2399
2966
  type: node.type,
2400
2967
  custom,
2968
+ cssClass: node.cssClass,
2401
2969
  edit,
2402
2970
  className: variants.length > 1 ? `tb-w ${variantClass(variant)}` : "tb-w",
2403
2971
  anchor: index === 0 && !ctx.dupe && typeof anchor === "string" && anchor !== "" ? anchor : void 0,
2404
2972
  copyAnchor: ctx.vpath !== "" && typeof anchor === "string" && anchor !== "" ? anchor : void 0,
2405
2973
  entrance: entranceOf(variant.props.entrance, variant.props.entranceDelayMs, ctx.interactive),
2406
- children: /* @__PURE__ */ jsx28(
2974
+ children: /* @__PURE__ */ jsx32(
2407
2975
  Component2,
2408
2976
  {
2409
2977
  node,
@@ -2423,15 +2991,23 @@ function renderWidget(node, ctx, registry) {
2423
2991
  variant.devices.join("-")
2424
2992
  );
2425
2993
  });
2994
+ return gated(node, ctx, copies);
2995
+ }
2996
+ function gated(node, ctx, content) {
2997
+ if (ctx.edit !== void 0) return content;
2998
+ const when = parseShowWhen(node.showWhen);
2999
+ if (when === null) return content;
3000
+ return /* @__PURE__ */ jsx32(ShowWhen, { when, heights: reservedHeights(node), children: content });
2426
3001
  }
2427
3002
  function renderColumn(column, ctx, registry) {
2428
3003
  if (ctx.edit === void 0 && hiddenEverywhere(column.props, column.responsive)) return null;
2429
- return /* @__PURE__ */ jsx28(
3004
+ const drawn = /* @__PURE__ */ jsx32(
2430
3005
  NodeWrapper,
2431
3006
  {
2432
3007
  id: column.id,
2433
3008
  part: "column",
2434
3009
  className: "tb-col",
3010
+ cssClass: column.cssClass,
2435
3011
  anchor: ctx.dupe ? void 0 : column.props.anchor,
2436
3012
  copyAnchor: ctx.vpath === "" ? void 0 : column.props.anchor,
2437
3013
  edit: ctx.edit,
@@ -2441,16 +3017,17 @@ function renderColumn(column, ctx, registry) {
2441
3017
  ctx.interactive
2442
3018
  ),
2443
3019
  children: column.children.map(
2444
- (child) => child.type === "inner-section" ? /* @__PURE__ */ jsx28(Fragment16, { children: renderSection(child, ctx, registry, true) }, child.id) : /* @__PURE__ */ jsx28(Fragment16, { children: renderWidget(child, ctx, registry) }, child.id)
3020
+ (child) => child.type === "inner-section" ? /* @__PURE__ */ jsx32(Fragment19, { children: renderSection(child, ctx, registry, true) }, child.id) : /* @__PURE__ */ jsx32(Fragment19, { children: renderWidget(child, ctx, registry) }, child.id)
2445
3021
  )
2446
3022
  },
2447
3023
  column.id
2448
3024
  );
3025
+ return gated(column, ctx, drawn);
2449
3026
  }
2450
3027
  var PLAIN = resolveInteraction({ props: {}, responsive: void 0 }, "desktop");
2451
3028
  function sectionVariants(section, ctx) {
2452
3029
  const groups = /* @__PURE__ */ new Map();
2453
- for (const device of DEVICES2) {
3030
+ for (const device of DEVICES4) {
2454
3031
  const interaction = ctx.interactive ? resolveInteraction(section, device) : PLAIN;
2455
3032
  const entrance = ctx.interactive ? resolveEntrance(section, device) : { entrance: "none", entranceDelayMs: 0 };
2456
3033
  const signature = stable([interaction, entrance]);
@@ -2470,7 +3047,8 @@ function panelsOf(section, ctx, registry, fallback) {
2470
3047
  function renderSection(section, ctx, registry, nested = false) {
2471
3048
  if (ctx.edit === void 0 && hiddenEverywhere(section.props, section.responsive)) return null;
2472
3049
  const variants = sectionVariants(section, ctx);
2473
- const marker = variants.length > 1 && !ctx.dupe && section.props.anchor !== void 0 && ANCHOR_RE3.test(section.props.anchor) ? /* @__PURE__ */ jsx28("div", { id: section.props.anchor, className: "tb-anchor" }, "anchor") : null;
3050
+ const frame = nested || !ctx.interactive || ctx.edit !== void 0 ? null : frameOf(section);
3051
+ const marker = variants.length > 1 && !ctx.dupe && section.props.anchor !== void 0 && ANCHOR_RE3.test(section.props.anchor) ? /* @__PURE__ */ jsx32("div", { id: section.props.anchor, className: "tb-anchor" }, "anchor") : null;
2474
3052
  const copies = variants.map((variant, index) => {
2475
3053
  const { interaction } = variant;
2476
3054
  const id = `ix-${section.id}-${ctx.vpath}${String(index)}`;
@@ -2478,9 +3056,9 @@ function renderSection(section, ctx, registry, nested = false) {
2478
3056
  const columns = () => section.columns.map((column) => renderColumn(column, own, registry));
2479
3057
  let body;
2480
3058
  if (interaction.interaction === "tabs") {
2481
- body = /* @__PURE__ */ jsx28(Tabs, { id, panels: panelsOf(section, own, registry, (n) => `Tab ${String(n)}`) });
3059
+ body = /* @__PURE__ */ jsx32(Tabs, { id, panels: panelsOf(section, own, registry, (n) => `Tab ${String(n)}`) });
2482
3060
  } else if (interaction.interaction === "accordion") {
2483
- body = /* @__PURE__ */ jsx28(
3061
+ body = /* @__PURE__ */ jsx32(
2484
3062
  Accordion,
2485
3063
  {
2486
3064
  id,
@@ -2490,7 +3068,7 @@ function renderSection(section, ctx, registry, nested = false) {
2490
3068
  }
2491
3069
  );
2492
3070
  } else if (interaction.interaction === "carousel") {
2493
- body = /* @__PURE__ */ jsx28(
3071
+ body = /* @__PURE__ */ jsx32(
2494
3072
  Carousel,
2495
3073
  {
2496
3074
  panels: panelsOf(section, own, registry, () => ""),
@@ -2499,7 +3077,7 @@ function renderSection(section, ctx, registry, nested = false) {
2499
3077
  }
2500
3078
  );
2501
3079
  } else if (interaction.interaction === "toggle") {
2502
- body = /* @__PURE__ */ jsx28(
3080
+ body = /* @__PURE__ */ jsx32(
2503
3081
  Toggle,
2504
3082
  {
2505
3083
  labelOpen: pickLocale(interaction.toggleLabelOpen, ctx.locale),
@@ -2509,39 +3087,55 @@ function renderSection(section, ctx, registry, nested = false) {
2509
3087
  }
2510
3088
  );
2511
3089
  } else {
2512
- body = /* @__PURE__ */ jsx28("div", { className: "tb-row", children: columns() });
3090
+ body = /* @__PURE__ */ jsx32("div", { className: "tb-row", children: columns() });
3091
+ }
3092
+ if (frame?.collapse != null) {
3093
+ body = /* @__PURE__ */ jsx32(
3094
+ Collapse,
3095
+ {
3096
+ sectionId: section.id,
3097
+ id: `fr-${section.id}-${ctx.vpath}${String(index)}`,
3098
+ px: frame.collapse.px,
3099
+ label: pickLocale(frame.collapse.label, ctx.locale) || SITE_STRING_DEFAULTS4["nav.menu"],
3100
+ children: body
3101
+ }
3102
+ );
2513
3103
  }
2514
- return /* @__PURE__ */ jsx28(
3104
+ return /* @__PURE__ */ jsxs23(
2515
3105
  NodeWrapper,
2516
3106
  {
2517
3107
  id: section.id,
2518
3108
  part: "section",
3109
+ cssClass: section.cssClass,
2519
3110
  as: nested ? "div" : "section",
2520
- className: `${nested ? "tb-section tb-nested" : "tb-section"}${variants.length > 1 ? ` ${variantClass({ devices: variant.devices, props: {} })}` : ""}`,
3111
+ className: `${nested ? "tb-section tb-nested" : "tb-section"}${frame?.sticky === true ? " tb-sticky" : ""}${variants.length > 1 ? ` ${variantClass({ devices: variant.devices, props: {} })}` : ""}`,
2521
3112
  anchor: variants.length === 1 && !ctx.dupe ? section.props.anchor : void 0,
2522
3113
  copyAnchor: variants.length > 1 || ctx.vpath !== "" ? section.props.anchor : void 0,
2523
3114
  edit: ctx.edit,
2524
3115
  entrance: entranceOf(variant.entrance.entrance, variant.entrance.entranceDelayMs, ctx.interactive),
2525
- children: /* @__PURE__ */ jsx28("div", { className: "tb-inner", children: body })
3116
+ children: [
3117
+ frame !== null ? /* @__PURE__ */ jsx32("style", { href: "tb-frame", precedence: "throttle", children: FRAME_CSS }) : null,
3118
+ /* @__PURE__ */ jsx32("div", { className: "tb-inner", children: body })
3119
+ ]
2526
3120
  },
2527
3121
  variant.devices.join("-")
2528
3122
  );
2529
3123
  });
2530
- return marker === null ? copies : [marker, ...copies];
3124
+ return gated(section, ctx, marker === null ? copies : [marker, ...copies]);
2531
3125
  }
2532
3126
  function needsRuntime(doc) {
2533
3127
  let found = false;
2534
3128
  walkNodes3(doc, (node) => {
2535
3129
  if (found || node.type === "saved-section") return;
2536
3130
  if (node.type === "section" || node.type === "inner-section") {
2537
- found = DEVICES2.some(
3131
+ found = DEVICES4.some(
2538
3132
  (device) => resolveInteraction(node, device).interaction !== "none" || resolveEntrance(node, device).entrance !== "none"
2539
3133
  );
2540
3134
  } else if (node.type === "column") {
2541
- found = DEVICES2.some((device) => resolveEntrance(node, device).entrance !== "none");
3135
+ found = DEVICES4.some((device) => resolveEntrance(node, device).entrance !== "none");
2542
3136
  } else {
2543
- found = DEVICES2.some((device) => {
2544
- const entrance = resolveResponsive3(node.props, node.responsive, device).entrance;
3137
+ found = DEVICES4.some((device) => {
3138
+ const entrance = resolveResponsive4(node.props, node.responsive, device).entrance;
2545
3139
  return entrance !== void 0 && entrance !== "none";
2546
3140
  });
2547
3141
  }
@@ -2559,79 +3153,1084 @@ function BuilderRenderer(props) {
2559
3153
  const ctx = { registry, data, locale, assets, mediaOrigin, resolveLink, code, edit: editMode, interactive, vpath: props.idScope?.vpath ?? "", dupe: props.idScope?.dupe ?? false, snapshots: source.customWidgets };
2560
3154
  const css = compileResponsiveCss(doc, registry, assets, mediaOrigin);
2561
3155
  const upgraded = new Map(doc.sections.map((section) => [section.id, section]));
2562
- return /* @__PURE__ */ jsxs20("div", { className: "tb-root", "data-throttle-part": "builder-root", ...props.scopeCustomCss === true ? { "data-b-root": "" } : {}, children: [
2563
- interactive && needsRuntime(doc) ? /* @__PURE__ */ jsx28(InteractionRuntime, {}) : null,
2564
- /* @__PURE__ */ jsx28("style", { href: "tb-base", precedence: "throttle", children: BASE_CSS }),
2565
- css === "" ? null : /* @__PURE__ */ jsx28("style", { children: css }),
3156
+ return /* @__PURE__ */ jsxs23("div", { className: "tb-root", "data-throttle-part": "builder-root", ...props.scopeCustomCss === true ? { "data-b-root": "" } : {}, children: [
3157
+ interactive && needsRuntime(doc) ? /* @__PURE__ */ jsx32(InteractionRuntime, {}) : null,
3158
+ /* @__PURE__ */ jsx32("style", { href: "tb-base", precedence: "throttle", children: BASE_CSS }),
3159
+ css === "" ? null : /* @__PURE__ */ jsx32("style", { children: css }),
2566
3160
  (expansion.roots ?? doc.sections.map((section) => ({ kind: "section", id: section.id }))).map((root) => {
2567
3161
  if (root.kind === "section") {
2568
3162
  const section2 = upgraded.get(root.id);
2569
- return section2?.type === "section" ? /* @__PURE__ */ jsx28(Fragment16, { children: renderSection(section2, ctx, registry) }, root.id) : null;
3163
+ return section2?.type === "section" ? /* @__PURE__ */ jsx32(Fragment19, { children: renderSection(section2, ctx, registry) }, root.id) : null;
2570
3164
  }
2571
3165
  const section = root.sectionId === null ? void 0 : upgraded.get(root.sectionId);
2572
3166
  if (section?.type === "section") {
2573
- return root.ref.props.hidden === true && ctx.edit === void 0 ? null : /* @__PURE__ */ jsx28(Fragment16, { children: renderSection(section, ctx, registry) }, root.ref.id);
3167
+ return root.ref.props.hidden === true && ctx.edit === void 0 ? null : /* @__PURE__ */ jsx32(Fragment19, { children: renderSection(section, ctx, registry) }, root.ref.id);
2574
3168
  }
2575
- return /* @__PURE__ */ jsx28(MissingSavedSection, { node: root.ref }, root.ref.id);
3169
+ return /* @__PURE__ */ jsx32(MissingSavedSection, { node: root.ref }, root.ref.id);
2576
3170
  })
2577
3171
  ] });
2578
3172
  }
2579
3173
 
2580
- // src/context.ts
2581
- import { createContext, useContext } from "react";
2582
- var BuilderContext = typeof createContext === "function" ? createContext(null) : null;
2583
- var useBuilder = () => useContext(BuilderContext);
2584
-
2585
- // src/part-view.tsx
2586
- import { jsx as jsx29 } from "react/jsx-runtime";
2587
- var BoundaryBase = Component ?? class {
2588
- };
2589
- var Boundary = class extends BoundaryBase {
2590
- constructor() {
2591
- super(...arguments);
2592
- __publicField(this, "state", { failed: false });
3174
+ // src/basics/v2/menu-v2.tsx
3175
+ import { Fragment as Fragment20, jsx as jsx33, jsxs as jsxs24 } from "react/jsx-runtime";
3176
+ var MODES = ["horizontal", "vertical", "drawer", "mega"];
3177
+ var MAX_LEVEL = 3;
3178
+ var CLASS_RE = /^[A-Za-z_][A-Za-z0-9_-]{0,63}$/;
3179
+ var SUBMENU_DEFAULT = "Show submenu for {label}";
3180
+ function localized(value, locale) {
3181
+ if (!isRecord(value)) return str(value);
3182
+ for (const key of [locale, "en"]) {
3183
+ if (Object.hasOwn(value, key)) {
3184
+ const own = str(value[key]);
3185
+ if (own !== void 0) return own;
3186
+ }
2593
3187
  }
2594
- static getDerivedStateFromError() {
2595
- return { failed: true };
3188
+ return Object.values(value).map(str).find((s) => s !== void 0);
3189
+ }
3190
+ function makeLink(builder, own, mediaOrigin) {
3191
+ const targets = builder?.linkTargets;
3192
+ const fallback = own ?? builder?.resolveLink;
3193
+ return (target2) => {
3194
+ if (target2.kind === "url") return safeUrl12(target2.href, "href", { mediaOrigin });
3195
+ if (targets !== void 0 && typeof target2.id === "string") {
3196
+ const key = `${String(target2.kind)}:${target2.id}`;
3197
+ if (Object.hasOwn(targets, key)) {
3198
+ const known = targets[key];
3199
+ return typeof known === "string" ? safeUrl12(known, "href", { mediaOrigin }) : null;
3200
+ }
3201
+ }
3202
+ const raw = fallback?.(target2) ?? null;
3203
+ return raw === null ? null : safeUrl12(raw, "href", { mediaOrigin });
3204
+ };
3205
+ }
3206
+ function megaOf(value, locale) {
3207
+ if (!isRecord(value) || value.enabled !== true) return void 0;
3208
+ const columns = typeof value.columns === "number" ? Math.min(6, Math.max(2, Math.round(value.columns))) : 3;
3209
+ const f = value.featured;
3210
+ let featured = null;
3211
+ if (isRecord(f) && f.kind === "section" && typeof f.id === "string") featured = { kind: "section", id: f.id };
3212
+ else if (isRecord(f) && f.kind === "image" && typeof f.asset === "string") {
3213
+ featured = { kind: "image", asset: f.asset, link: isRecord(f.link) ? f.link : null, caption: localized(f.caption, locale) ?? "" };
2596
3214
  }
2597
- componentDidCatch(error, _info) {
2598
- warnOnce(`part:${this.props.label}`, `${this.props.label} failed to render (${String(error)}); rendering nothing for it`);
3215
+ return { columns, featured };
3216
+ }
3217
+ function build(raw, level, b) {
3218
+ if (!Array.isArray(raw)) return [];
3219
+ const out = [];
3220
+ raw.forEach((entry, index) => {
3221
+ if (!isRecord(entry) || !isRecord(entry.target)) return;
3222
+ const target2 = entry.target;
3223
+ const label = localized(entry.label, b.r.locale);
3224
+ if (label === void 0) return;
3225
+ out.push({
3226
+ key: typeof entry.id === "string" ? entry.id : String(index),
3227
+ label,
3228
+ href: target2.kind === "category" && typeof entry.url === "string" ? safeUrl12(entry.url, "href", { mediaOrigin: b.r.mediaOrigin }) : b.r.link(target2),
3229
+ newTab: entry.newTab === true,
3230
+ classes: Array.isArray(entry.cssClass) ? entry.cssClass.filter((c) => typeof c === "string" && CLASS_RE.test(c)) : [],
3231
+ description: localized(entry.description, b.r.locale),
3232
+ badge: localized(entry.badge, b.r.locale),
3233
+ // Mega is only for a top-level item of the header menu, in mega mode.
3234
+ mega: b.mega && level === 1 && b.menu === "header" ? megaOf(entry.mega, b.r.locale) : void 0,
3235
+ children: level < MAX_LEVEL ? build(entry.children, level + 1, b) : [],
3236
+ ...target2.kind === "category" && typeof entry.handle === "string" ? { handle: entry.handle } : {}
3237
+ });
3238
+ });
3239
+ return out;
3240
+ }
3241
+ function fromDesign(items, level, r) {
3242
+ return items.map((item, index) => ({
3243
+ key: String(index),
3244
+ label: item.label,
3245
+ href: safeUrl12(item.href, "href", { mediaOrigin: r.mediaOrigin }),
3246
+ newTab: false,
3247
+ classes: [],
3248
+ description: void 0,
3249
+ badge: void 0,
3250
+ mega: void 0,
3251
+ children: level < MAX_LEVEL && item.children !== void 0 ? fromDesign(item.children, level + 1, r) : []
3252
+ }));
3253
+ }
3254
+ function Anchor({ item }) {
3255
+ return item.href === null ? /* @__PURE__ */ jsx33("span", { className: "tb-mm-text", children: item.label }) : /* @__PURE__ */ jsx33("a", { href: item.href, ...item.newTab ? { target: "_blank", rel: "noopener noreferrer" } : {}, children: item.label });
3256
+ }
3257
+ var Extras = ({ item, describe }) => /* @__PURE__ */ jsxs24(Fragment20, { children: [
3258
+ item.badge === void 0 ? null : /* @__PURE__ */ jsx33("span", { className: "tb-mm-badge", children: item.badge }),
3259
+ describe && item.description !== void 0 ? /* @__PURE__ */ jsx33("span", { className: "tb-mm-desc", children: item.description }) : null
3260
+ ] });
3261
+ function FeaturedPanel({ featured, label, ctx }) {
3262
+ const { builder, props } = ctx;
3263
+ const site = builder?.site;
3264
+ if (builder === null || site === void 0 || site.status !== "ok") return null;
3265
+ const parts = [site.header, site.footer];
3266
+ if (featured.kind === "section") {
3267
+ let answer;
3268
+ for (const part2 of parts) {
3269
+ const all2 = part2.savedSections;
3270
+ if (answer === void 0 && all2 !== void 0 && Object.hasOwn(all2, featured.id)) answer = all2[featured.id];
3271
+ }
3272
+ const parsed2 = answer === void 0 ? null : sectionNodeSchema2.safeParse(answer.section);
3273
+ if (answer === void 0 || parsed2 === null || !parsed2.success) return null;
3274
+ const assets = { ...site.footer.assets, ...site.header.assets };
3275
+ return /* @__PURE__ */ jsx33("div", { className: "tb-mm-feat", children: /* @__PURE__ */ jsx33(
3276
+ BuilderRenderer,
3277
+ {
3278
+ document: { schemaVersion: 1, sections: [parsed2.data] },
3279
+ registry: builder.registry,
3280
+ data: {},
3281
+ locale: props.locale,
3282
+ assets,
3283
+ mediaOrigin: props.mediaOrigin,
3284
+ interactive: props.interactive,
3285
+ resolveLink: props.resolveLink ?? builder.resolveLink
3286
+ }
3287
+ ) });
3288
+ }
3289
+ let asset;
3290
+ for (const part2 of parts) {
3291
+ if (asset === void 0 && Object.hasOwn(part2.assets, featured.asset)) asset = part2.assets[featured.asset];
3292
+ }
3293
+ if (!isFrozenAsset(asset)) return null;
3294
+ const href = featured.link === null ? null : makeLink(builder, props.resolveLink, props.mediaOrigin)(featured.link);
3295
+ const image = /* @__PURE__ */ jsx33(AssetImage, { asset, mediaOrigin: props.mediaOrigin, alt: href === null ? featured.caption : featured.caption || label });
3296
+ return /* @__PURE__ */ jsxs24("figure", { className: "tb-mm-feat", children: [
3297
+ href === null ? image : /* @__PURE__ */ jsx33("a", { href, children: image }),
3298
+ featured.caption === "" ? null : /* @__PURE__ */ jsx33("figcaption", { children: featured.caption })
3299
+ ] });
3300
+ }
3301
+ function List2({ items, top, ctx }) {
3302
+ if (items.length === 0) return null;
3303
+ return /* @__PURE__ */ jsx33("ul", { ...top === void 0 ? { className: "tb-mm-sub" } : { id: top.id, className: "tb-mm-list" }, children: items.map((item) => /* @__PURE__ */ jsx33(Entry, { item, level: top === void 0 ? 2 : 1, ctx }, item.key)) });
3304
+ }
3305
+ function Entry({ item, level, ctx }) {
3306
+ const hasPanel = item.mega !== void 0 && (item.children.length > 0 || item.mega.featured !== null);
3307
+ const sub = item.children.length > 0 || hasPanel;
3308
+ const toggle = sub && level === 1 && ctx.mode !== "vertical";
3309
+ const cls = ["tb-mm-i", ...item.classes].join(" ");
3310
+ const subId = `${ctx.listId}-${item.key.replace(/[^A-Za-z0-9_-]/g, "_")}`;
3311
+ let below = null;
3312
+ if (hasPanel && item.mega !== void 0) {
3313
+ below = /* @__PURE__ */ jsxs24("div", { id: subId, className: "tb-mm-panel", style: { "--tb-mm-cols": item.mega.columns }, children: [
3314
+ item.children.length === 0 ? null : /* @__PURE__ */ jsx33("ul", { className: "tb-mm-cols", children: item.children.map((child) => /* @__PURE__ */ jsxs24("li", { className: "tb-mm-col", children: [
3315
+ /* @__PURE__ */ jsx33(Anchor, { item: child }),
3316
+ /* @__PURE__ */ jsx33(Extras, { item: child, describe: true }),
3317
+ /* @__PURE__ */ jsx33(List2, { items: child.children, ctx })
3318
+ ] }, child.key)) }),
3319
+ item.mega.featured === null ? null : /* @__PURE__ */ jsx33(FeaturedPanel, { featured: item.mega.featured, label: item.label, ctx })
3320
+ ] });
3321
+ } else if (sub) {
3322
+ below = /* @__PURE__ */ jsx33("ul", { id: subId, className: "tb-mm-sub", children: item.children.map((child) => /* @__PURE__ */ jsx33(Entry, { item: child, level: 2, ctx }, child.key)) });
3323
+ }
3324
+ return /* @__PURE__ */ jsxs24("li", { className: cls, ...sub && level === 1 ? { "data-tb-i": "" } : {}, children: [
3325
+ /* @__PURE__ */ jsx33(Anchor, { item }),
3326
+ /* @__PURE__ */ jsx33(Extras, { item, describe: false }),
3327
+ toggle ? /* @__PURE__ */ jsx33(
3328
+ "button",
3329
+ {
3330
+ type: "button",
3331
+ className: "tb-mm-t",
3332
+ "data-tb-t": "",
3333
+ "aria-expanded": "false",
3334
+ "aria-controls": subId,
3335
+ "aria-label": ctx.submenu.replace("{label}", () => item.label),
3336
+ children: /* @__PURE__ */ jsx33("svg", { viewBox: "0 0 24 24", width: "16", height: "16", "aria-hidden": "true", focusable: "false", children: /* @__PURE__ */ jsx33("path", { d: "M6 9l6 6 6-6", fill: "none", stroke: "currentColor", strokeWidth: "2" }) })
3337
+ }
3338
+ ) : null,
3339
+ below
3340
+ ] });
3341
+ }
3342
+ function MenuRuntime() {
3343
+ useEffect6(() => startMenuRuntime(), []);
3344
+ return null;
3345
+ }
3346
+ var part = (key, extra) => ({
3347
+ className: [`tsf-${key}`, extra].filter(Boolean).join(" "),
3348
+ "data-throttle-part": key
3349
+ });
3350
+ function StorefrontNav({ items, label, listId, ctx, className, menu }) {
3351
+ const categories = items.some((item) => item.handle !== void 0);
3352
+ const handle = (item, parent) => item.handle === void 0 ? {} : { "data-category-handle": item.handle, ...categories ? { "data-category-parent": parent } : {} };
3353
+ const link = (item) => item.href === null ? /* @__PURE__ */ jsx33("span", { ...part("category-nav-link", "tb-mm-text"), children: item.label }) : /* @__PURE__ */ jsx33("a", { ...part("category-nav-link"), href: item.href, ...item.newTab ? { target: "_blank", rel: "noopener noreferrer" } : {}, children: item.label });
3354
+ return /* @__PURE__ */ jsx33("nav", { ...part("category-nav", className), "aria-label": label, ...categories ? {} : { "data-menu": menu }, children: /* @__PURE__ */ jsx33("ul", { ...part("category-nav-list"), children: items.map((item) => {
3355
+ const sub = item.children.length > 0;
3356
+ const panelId = `${listId}-${item.key.replace(/[^A-Za-z0-9_-]/g, "_")}`;
3357
+ return /* @__PURE__ */ jsxs24("li", { ...part("category-nav-item", item.classes.join(" ")), "data-nav-top": "", ...sub ? { "data-tb-i": "" } : {}, ...handle(item, ""), children: [
3358
+ link(item),
3359
+ sub ? /* @__PURE__ */ jsx33(
3360
+ "button",
3361
+ {
3362
+ type: "button",
3363
+ ...part("category-nav-toggle"),
3364
+ "data-tb-t": "",
3365
+ "aria-expanded": "false",
3366
+ "aria-controls": panelId,
3367
+ "aria-label": ctx.submenu.replace("{label}", () => item.label),
3368
+ children: /* @__PURE__ */ jsx33(Icon4, { name: "chevron-down", size: 14 })
3369
+ }
3370
+ ) : null,
3371
+ sub ? /* @__PURE__ */ jsx33("ul", { ...part("category-nav-panel"), id: panelId, "data-nav-panel": "", hidden: true, children: item.children.map((child) => /* @__PURE__ */ jsx33("li", { ...part("category-nav-child", child.classes.join(" ")), ...handle(child, item.handle ?? ""), children: link(child) }, child.key)) }) : null
3372
+ ] }, item.key);
3373
+ }) }) });
3374
+ }
3375
+ function Nav({ items, label, listId, ctx, className, menu }) {
3376
+ if (ctx.variant === "storefront") return /* @__PURE__ */ jsx33(StorefrontNav, { items, label, listId, ctx, menu, ...className === void 0 ? {} : { className } });
3377
+ const full = { ...ctx, listId };
3378
+ return /* @__PURE__ */ jsxs24("nav", { className: `tb-mm tb-mm--${ctx.mode}${className === void 0 ? "" : ` ${className}`}`, "aria-label": label, children: [
3379
+ ctx.mode === "drawer" && /* @__PURE__ */ jsx33("button", { type: "button", className: "tb-mm-drawer", "data-tb-drawer": "", "aria-expanded": "false", "aria-controls": listId, children: /* @__PURE__ */ jsx33(Icon4, { name: "menu", size: 24, label }) }),
3380
+ /* @__PURE__ */ jsx33(List2, { items, top: { id: listId }, ctx: full })
3381
+ ] });
3382
+ }
3383
+ function MenuV2(props) {
3384
+ const { props: settings, data, mediaOrigin, editMode, locale } = props;
3385
+ const builder = useBuilder();
3386
+ const design = useSiteDesign5();
3387
+ const listId = useId2();
3388
+ const mobileId = useId2();
3389
+ const name = str(settings.menu) ?? "header";
3390
+ const mode = oneOf(settings.mode, MODES, "horizontal");
3391
+ const r = { mediaOrigin, locale, link: makeLink(builder, props.resolveLink, mediaOrigin) };
3392
+ const categories = Array.isArray(data.categories) ? data.categories : [];
3393
+ const forMenu = (menu, raw) => build(expandMenu(Array.isArray(raw) ? raw : [], categories).menu, 1, { r, menu, mega: mode === "mega" });
3394
+ let items = [];
3395
+ let mobile = [];
3396
+ const site = builder?.site;
3397
+ const menus = site?.status === "ok" && isRecord(site.settings.menus) ? site.settings.menus : void 0;
3398
+ if (menus !== void 0) {
3399
+ items = Object.hasOwn(menus, name) ? forMenu(name, menus[name]) : [];
3400
+ if (name === "header" && Object.hasOwn(menus, "mobile")) mobile = forMenu("mobile", menus.mobile);
3401
+ } else if (design?.menus !== void 0 && Object.hasOwn(design.menus, name)) {
3402
+ items = fromDesign(design.menus[name] ?? [], 1, r);
3403
+ }
3404
+ const word = (key, fallback) => {
3405
+ for (const strings of [site?.status === "ok" ? site.settings.strings : void 0, design?.strings]) {
3406
+ if (isRecord(strings) && Object.hasOwn(strings, key) && str(strings[key]) !== void 0) return strings[key];
3407
+ }
3408
+ return fallback;
3409
+ };
3410
+ const label = word("nav.menu", SITE_STRING_DEFAULTS5["nav.menu"]);
3411
+ if (items.length === 0 && mobile.length === 0) {
3412
+ return /* @__PURE__ */ jsxs24(Fragment20, { children: [
3413
+ /* @__PURE__ */ jsx33(BasicStyles, {}),
3414
+ /* @__PURE__ */ jsx33(Placeholder, { editMode, children: `Menu "${name}" is empty: add links in Site settings` })
3415
+ ] });
3416
+ }
3417
+ const ctx = { builder, props, mode, variant: oneOf(settings.variant, ["default", "storefront"], "default"), submenu: word("nav.submenu", SUBMENU_DEFAULT) };
3418
+ const nameOf = (menu) => menu === "header" ? label : `${label} (${menu})`;
3419
+ return /* @__PURE__ */ jsxs24(Fragment20, { children: [
3420
+ /* @__PURE__ */ jsx33(BasicStyles, {}),
3421
+ /* @__PURE__ */ jsx33("style", { href: "tb-menu-v2", precedence: "throttle", children: MENU_V2_CSS }),
3422
+ items.length === 0 ? null : /* @__PURE__ */ jsx33(Nav, { items, menu: name, label: nameOf(name), listId, ctx, ...mobile.length > 0 ? { className: "tb-mm-hide-phone" } : {} }),
3423
+ mobile.length === 0 ? null : /* @__PURE__ */ jsx33(Nav, { items: mobile, menu: "mobile", label: nameOf("mobile"), listId: mobileId, ctx, className: "tb-mm-only-phone" }),
3424
+ props.interactive === false ? null : /* @__PURE__ */ jsx33(MenuRuntime, {})
3425
+ ] });
3426
+ }
3427
+ var MENU_V2_CSS = `@layer throttle{
3428
+ .tb-mm{position:relative;color:var(--b-color,inherit);font-size:var(--b-size,var(--tb-text-m));text-align:var(--b-align,start)}
3429
+ .tb-mm ul{margin:0;padding:0;list-style:none}
3430
+ .tb-mm li{position:relative;min-inline-size:0}
3431
+ .tb-mm a,.tb-mm-text{display:block;min-inline-size:0;padding:var(--tb-space-xs) var(--tb-space-s);color:inherit;text-decoration:none;overflow-wrap:anywhere}
3432
+ .tb-mm a:hover{text-decoration:underline}
3433
+ .tb-mm a:focus-visible,.tb-mm-t:focus-visible,.tb-mm-drawer:focus-visible{outline:2px solid var(--tb-color-primary,currentColor);outline-offset:2px}
3434
+ .tb-mm-badge{display:inline-block;margin-inline-start:var(--tb-space-xs);padding-inline:.5em;border-radius:99px;font-size:.75em;background:var(--tb-color-primary,#111);color:var(--tb-color-primary-foreground,#fff)}
3435
+ .tb-mm-desc{display:block;padding-inline:var(--tb-space-s);font-size:.85em;opacity:.75;overflow-wrap:anywhere}
3436
+ .tb-mm-t{display:inline-flex;align-items:center;justify-content:center;min-inline-size:32px;min-block-size:32px;padding:0;border:0;background:transparent;color:inherit;cursor:pointer}
3437
+ .tb-mm-t svg{transition:transform .15s}
3438
+ .tb-mm-i[data-open]>.tb-mm-t svg{transform:rotate(180deg)}
3439
+ .tb-mm-drawer{display:none;align-items:center;justify-content:center;min-inline-size:44px;min-block-size:44px;padding:0;border:0;background:transparent;color:inherit;cursor:pointer}
3440
+ .tb-mm-only-phone{display:none}
3441
+ .tb-mm--horizontal>ul,.tb-mm--drawer>ul,.tb-mm--mega>ul{display:flex;flex-wrap:wrap;align-items:center}
3442
+ .tb-mm--horizontal>ul>li,.tb-mm--drawer>ul>li,.tb-mm--mega>ul>li{display:inline-flex;align-items:center}
3443
+ .tb-mm-sub,.tb-mm-panel{display:none}
3444
+ .tb-mm-i>.tb-mm-sub{position:absolute;inset-block-start:100%;inset-inline-start:0;z-index:20;min-inline-size:12rem;padding:var(--tb-space-xs);text-align:start;background:var(--tb-color-background,#fff);color:var(--tb-color-foreground,#111);border:1px solid var(--tb-color-border,#ddd);border-radius:var(--throttle-radius,8px)}
3445
+ .tb-mm-sub .tb-mm-sub{position:static;min-inline-size:0;padding:0;padding-inline-start:var(--tb-space-m);border:0}
3446
+ .tb-mm-sub>li{display:block}
3447
+ .tb-mm-i[data-open]>.tb-mm-sub{display:block}
3448
+ .tb-mm-sub .tb-mm-sub{display:block}
3449
+ .tb-mm--vertical .tb-mm-t{display:none}
3450
+ .tb-mm--vertical .tb-mm-sub{display:block;position:static;min-inline-size:0;padding:0;padding-inline-start:var(--tb-space-m);border:0}
3451
+ .tb-mm--mega>ul>li{position:static}
3452
+ .tb-mm--mega>ul>li>.tb-mm-panel{position:absolute;inset-inline:0;inset-block-start:100%;z-index:20;padding:var(--tb-space-m);text-align:start;background:var(--tb-color-background,#fff);color:var(--tb-color-foreground,#111);border:1px solid var(--tb-color-border,#ddd);border-radius:var(--throttle-radius,8px)}
3453
+ .tb-mm-i[data-open]>.tb-mm-panel{display:flex;gap:var(--tb-space-m)}
3454
+ .tb-mm-cols{display:grid;grid-template-columns:repeat(var(--tb-mm-cols,3),minmax(0,1fr));gap:var(--tb-space-m);flex:1 1 0;min-inline-size:0}
3455
+ .tb-mm-col>.tb-mm-sub{display:block;position:static;min-inline-size:0;padding:0;border:0}
3456
+ .tb-mm-feat{flex:0 1 16rem;min-inline-size:0;margin:0}
3457
+ .tb-mm-feat img{display:block;max-inline-size:100%;block-size:auto}
3458
+ @media (max-width:767.98px){
3459
+ .tb-mm-hide-phone{display:none}
3460
+ .tb-mm-only-phone{display:block}
3461
+ .tb-mm--mega>ul{display:block}
3462
+ .tb-mm--mega>ul>li{display:flex;flex-wrap:wrap;align-items:center}
3463
+ .tb-mm--mega>ul>li>a,.tb-mm--mega>ul>li>.tb-mm-text{flex:1 1 0}
3464
+ .tb-mm--mega>ul>li>.tb-mm-sub,.tb-mm--mega>ul>li>.tb-mm-panel{flex:1 0 100%}
3465
+ .tb-mm-panel{position:static;inset:auto;border:0;padding:0;background:transparent}
3466
+ .tb-mm-cols{display:block}
3467
+ .tb-mm-feat{display:none}
3468
+ .tb-mm--mega>ul>li>.tb-mm-panel{position:static;border:0;padding:0}
3469
+ .tb-mm-i>.tb-mm-sub{position:static;min-inline-size:0;border:0;padding:0;padding-inline-start:var(--tb-space-m)}
3470
+ .tb-mm--drawer>.tb-mm-drawer{display:inline-flex;position:relative;z-index:61}
3471
+ .tb-mm--drawer[data-open=true]>.tb-mm-drawer{position:fixed;inset-block-start:var(--tb-space-s);inset-inline-end:var(--tb-space-s)}
3472
+ .tb-mm--drawer>ul{display:none}
3473
+ .tb-mm--drawer[data-open=true]>ul{display:block;position:fixed;inset:0;z-index:60;overflow:auto;padding:4.5rem var(--tb-space-m) var(--tb-space-m);text-align:start;background:var(--tb-color-background,#fff);color:var(--tb-color-foreground,#111);font-size:var(--tb-text-l)}
3474
+ .tb-mm--drawer[data-open=true]>ul>li{display:flex;flex-wrap:wrap}
3475
+ .tb-mm--drawer[data-open=true] .tb-mm-sub{display:block;position:static;border:0}
3476
+ }
3477
+ @media (scripting: none){
3478
+ .tb-mm-t{display:none}
3479
+ .tb-mm-i:hover>.tb-mm-sub,.tb-mm-i:focus-within>.tb-mm-sub{display:block}
3480
+ .tb-mm-i:hover>.tb-mm-panel,.tb-mm-i:focus-within>.tb-mm-panel{display:flex;gap:var(--tb-space-m)}
3481
+ @media (max-width:767.98px){
3482
+ .tb-mm-sub,.tb-mm-panel{display:block}
3483
+ .tb-mm--drawer>.tb-mm-drawer{display:none}
3484
+ .tb-mm--drawer>ul{display:block}
3485
+ }
3486
+ }
3487
+ }`;
3488
+ var definition = MB_BASIC_WIDGET_DEFINITIONS.find((d) => d.type === "basic.menu" && d.v === 2);
3489
+ if (definition === void 0) throw new Error("builder-schema has no basic.menu v2 definition");
3490
+ var menuV2Widgets = [{ ...definition, Component: MenuV2 }];
3491
+
3492
+ // src/basics/v2/announcement-v2.tsx
3493
+ import { Fragment as Fragment22, jsx as jsx34, jsxs as jsxs25 } from "react/jsx-runtime";
3494
+ var DEVICES5 = ["desktop", "tablet", "phone"];
3495
+ var DISMISS_PREFIX = "tb-an-dismissed:";
3496
+ var COLOR_HEX = /^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;
3497
+ var COLOR_TOKEN2 = /^token:([a-z][a-z-]{0,30})$/;
3498
+ var REDUCED = "(prefers-reduced-motion: reduce)";
3499
+ function readDismissed(ids) {
3500
+ const out = [];
3501
+ for (const id of ids) {
2599
3502
  try {
2600
- this.props.onError?.(error, { part: this.props.label });
3503
+ if (window.localStorage.getItem(`${DISMISS_PREFIX}${id}`) === "1") out.push(id);
2601
3504
  } catch {
2602
3505
  }
2603
3506
  }
2604
- componentDidUpdate(previous) {
2605
- const moved = previous.resetKeys.length !== this.props.resetKeys.length || previous.resetKeys.some((key, i) => !Object.is(key, this.props.resetKeys[i]));
2606
- if (moved && this.state.failed) this.setState({ failed: false });
3507
+ return out;
3508
+ }
3509
+ function writeDismissed(id) {
3510
+ try {
3511
+ window.localStorage.setItem(`${DISMISS_PREFIX}${id}`, "1");
3512
+ } catch {
2607
3513
  }
2608
- render() {
2609
- return this.state.failed ? null : this.props.children;
3514
+ }
3515
+ var matches = (query) => window.matchMedia?.(query).matches === true;
3516
+ function deviceNow() {
3517
+ return matches("(max-width:767.98px)") ? "phone" : matches("(max-width:1024.98px)") ? "tablet" : "desktop";
3518
+ }
3519
+ function colorOf(value) {
3520
+ if (typeof value !== "string") return void 0;
3521
+ if (COLOR_HEX.test(value)) return value;
3522
+ const token = COLOR_TOKEN2.exec(value);
3523
+ return token === null ? void 0 : `var(--tb-color-${token[1]})`;
3524
+ }
3525
+ var textOf = (tree) => tree.children.map((child) => typeof child === "string" ? child : textOf(child)).join("");
3526
+ function inline(children) {
3527
+ return children.map((child, index) => {
3528
+ if (typeof child === "string") return child;
3529
+ const inner = inline(child.children);
3530
+ if (child.tag === "strong" || child.tag === "em") return createElement3(child.tag, { key: index }, ...inner);
3531
+ if (child.tag === "a" && typeof child.href === "string") {
3532
+ return /* @__PURE__ */ jsx34("a", { href: child.href, rel: "noopener noreferrer", children: inner }, index);
3533
+ }
3534
+ return /* @__PURE__ */ jsx34(Fragment21, { children: inner }, index);
3535
+ });
3536
+ }
3537
+ function MessageText({ message, locale, mediaOrigin, href }) {
3538
+ const tree = parseRichText(localized(message.text, locale) ?? "", mediaOrigin);
3539
+ if (href !== null) return /* @__PURE__ */ jsx34("a", { href, children: textOf(tree) });
3540
+ return /* @__PURE__ */ jsx34("span", { className: "tb-an-text", children: inline(tree.children) });
3541
+ }
3542
+ function pageOf2(builder) {
3543
+ const given = builder?.page;
3544
+ if (given !== void 0) return given;
3545
+ return { home: builder?.pathname === "/" };
3546
+ }
3547
+ function audienceOf(ready, viewer) {
3548
+ if (!ready || viewer === null || viewer?.signedIn === null) return "all";
3549
+ return viewer?.signedIn === true ? "signed-in" : "guest";
3550
+ }
3551
+ function Bar({ raw, props, builder }) {
3552
+ const { props: settings, mediaOrigin, locale, editMode } = props;
3553
+ const design = useSiteDesign6();
3554
+ const viewer = useViewer();
3555
+ const all2 = useMemo(() => normalizeMessages(Array.isArray(raw.messages) ? raw.messages : []), [raw]);
3556
+ const style = isRecord(raw.style) ? raw.style : {};
3557
+ const rotate = isRecord(raw.rotate) ? raw.rotate : {};
3558
+ const [ready, setReady] = useState5(false);
3559
+ const [dismissed, setDismissed] = useState5(() => /* @__PURE__ */ new Set());
3560
+ const [at, setAt] = useState5(0);
3561
+ const [hover, setHover] = useState5(false);
3562
+ const [focus, setFocus] = useState5(false);
3563
+ const [reduced2, setReduced] = useState5(false);
3564
+ const site = builder?.site;
3565
+ const loadedAt = site?.status === "ok" && site.loadedAt !== void 0 ? Date.parse(site.loadedAt) : Number.NaN;
3566
+ const now = ready || Number.isNaN(loadedAt) ? Date.now() : loadedAt;
3567
+ const page = pageOf2(builder);
3568
+ const eligible = eligibleOnAnyDevice(all2, now, audienceOf(ready, viewer), page);
3569
+ const shown2 = eligible.filter((m) => editMode || !dismissed.has(m.id));
3570
+ const forEveryone = new Set(eligibleOnAnyDevice(all2, now, "all", page).map((m) => m.id));
3571
+ const waiting = [...eligibleOnAnyDevice(all2, now, "guest", page), ...eligibleOnAnyDevice(all2, now, "signed-in", page)].some(
3572
+ (m) => !forEveryone.has(m.id)
3573
+ );
3574
+ const interactive = props.interactive !== false && !editMode;
3575
+ const rotating = interactive && rotate.enabled === true && shown2.length > 1;
3576
+ const current = Math.min(at, Math.max(0, shown2.length - 1));
3577
+ const intervalS = typeof rotate.intervalS === "number" ? Math.min(15, Math.max(3, rotate.intervalS)) : 6;
3578
+ const shownRef = useRef3(shown2);
3579
+ shownRef.current = shown2;
3580
+ useEffect7(() => {
3581
+ setReady(true);
3582
+ setDismissed(new Set(readDismissed(all2.map((m) => m.id))));
3583
+ }, [all2]);
3584
+ useEffect7(() => {
3585
+ const query = window.matchMedia?.(REDUCED);
3586
+ if (query === void 0) return void 0;
3587
+ const sync = () => setReduced(query.matches);
3588
+ sync();
3589
+ query.addEventListener?.("change", sync);
3590
+ return () => query.removeEventListener?.("change", sync);
3591
+ }, []);
3592
+ const step2 = (direction) => setAt((from) => {
3593
+ const list2 = shownRef.current;
3594
+ const device = deviceNow();
3595
+ let i = Math.min(from, list2.length - 1);
3596
+ for (let tries = 0; tries < list2.length; tries += 1) {
3597
+ i = (i + direction + list2.length) % list2.length;
3598
+ if (list2[i].devices.includes(device)) return i;
3599
+ }
3600
+ return from;
3601
+ });
3602
+ useEffect7(() => {
3603
+ const list2 = shownRef.current;
3604
+ if (list2.length > 1 && list2[0] !== void 0 && !list2[0].devices.includes(deviceNow())) step2(1);
3605
+ }, [ready]);
3606
+ useEffect7(() => {
3607
+ if (!rotating || hover || focus || reduced2) return void 0;
3608
+ const timer = setInterval(() => step2(1), intervalS * 1e3);
3609
+ return () => clearInterval(timer);
3610
+ }, [rotating, hover, focus, reduced2, intervalS]);
3611
+ if (raw.enabled !== true) return /* @__PURE__ */ jsx34(Placeholder, { editMode, children: "No announcement: turn one on in Site settings" });
3612
+ const reserve = eligible.length === 0 && waiting;
3613
+ if (shown2.length === 0 && !reserve) return /* @__PURE__ */ jsx34(Placeholder, { editMode, children: "No announcement is showing now" });
3614
+ const link = makeLink(builder, props.resolveLink, mediaOrigin);
3615
+ const word = (key, fallback) => {
3616
+ for (const strings of [site?.status === "ok" ? site.settings.strings : void 0, design?.strings]) {
3617
+ if (isRecord(strings) && Object.hasOwn(strings, key) && str(strings[key]) !== void 0) return strings[key];
3618
+ }
3619
+ return fallback;
3620
+ };
3621
+ const dismissLabel = word("announcement.dismiss", SITE_STRING_DEFAULTS6["announcement.dismiss"]);
3622
+ const dismissible = interactive && style.dismissible === true && settings.dismissible !== false;
3623
+ const dismiss = (id) => {
3624
+ writeDismissed(id);
3625
+ setDismissed((previous) => new Set(previous).add(id));
3626
+ };
3627
+ const height = isRecord(style.height) ? style.height : {};
3628
+ const vars = {};
3629
+ for (const [device, key] of [["desktop", "--tb-an-hd"], ["tablet", "--tb-an-ht"], ["phone", "--tb-an-hp"]]) {
3630
+ const value = Object.hasOwn(height, device) ? height[device] : null;
3631
+ if (typeof value === "number" && Number.isInteger(value) && value >= 0 && value <= 200) vars[key] = `${String(value)}px`;
2610
3632
  }
3633
+ const background = colorOf(style.background);
3634
+ const foreground = colorOf(style.text);
3635
+ if (background !== void 0) vars["--tb-an-bg"] = background;
3636
+ if (foreground !== void 0) vars["--tb-an-fg"] = foreground;
3637
+ const align = style.align === "left" || style.align === "right" ? style.align : "center";
3638
+ const size = style.size === "m" ? "m" : "s";
3639
+ const transition = rotate.transition === "slide" ? "slide" : "fade";
3640
+ const activeMessage = shown2[current];
3641
+ const live = rotating && !hover && !focus && !reduced2 ? "off" : "polite";
3642
+ const dismissButton = (id) => /* @__PURE__ */ jsx34("button", { type: "button", className: "tb-b-dismiss", onClick: () => dismiss(id), children: /* @__PURE__ */ jsx34(Icon5, { name: "close", size: 16, label: dismissLabel }) });
3643
+ return /* @__PURE__ */ jsxs25(Fragment22, { children: [
3644
+ /* @__PURE__ */ jsx34(BasicStyles, {}),
3645
+ /* @__PURE__ */ jsx34("style", { href: "tb-an", precedence: "throttle", children: ANNOUNCEMENT_V2_CSS }),
3646
+ /* @__PURE__ */ jsxs25(
3647
+ "div",
3648
+ {
3649
+ className: `tb-an tb-an--${size} tb-an--${transition}${rotating ? " tb-an--rot" : ""}${reserve ? " tb-an--reserve" : ""}`,
3650
+ role: "region",
3651
+ "aria-label": word("announcement.label", "Announcement"),
3652
+ "data-align": align,
3653
+ style: vars,
3654
+ onMouseEnter: () => setHover(true),
3655
+ onMouseLeave: () => setHover(false),
3656
+ onFocus: () => setFocus(true),
3657
+ onBlur: () => setFocus(false),
3658
+ children: [
3659
+ rotating && /* @__PURE__ */ jsx34("button", { type: "button", className: "tb-an-step", "data-tb-an-prev": "", "aria-label": word("announcement.previous", "Previous announcement"), onClick: () => step2(-1), children: /* @__PURE__ */ jsx34("span", { "aria-hidden": "true", children: "\u2039" }) }),
3660
+ /* @__PURE__ */ jsx34("div", { className: "tb-an-track", ...rotating ? { "aria-live": live } : {}, children: shown2.map((m, index) => {
3661
+ const target2 = isRecord(m.target) ? m.target : null;
3662
+ const hidden = DEVICES5.filter((d) => !m.devices.includes(d)).map((d) => ` tb-an-hide-${d}`).join("");
3663
+ return /* @__PURE__ */ jsxs25(
3664
+ "div",
3665
+ {
3666
+ className: `tb-b-announcement tb-an-msg${hidden}`,
3667
+ ...rotating && index === current ? { "data-active": "" } : {},
3668
+ children: [
3669
+ /* @__PURE__ */ jsx34("span", { className: "tb-b-announcement-text", children: /* @__PURE__ */ jsx34(MessageText, { message: m, locale, mediaOrigin, href: target2 === null ? null : link(target2) }) }),
3670
+ !rotating && dismissible && dismissButton(m.id)
3671
+ ]
3672
+ },
3673
+ m.id
3674
+ );
3675
+ }) }),
3676
+ rotating && /* @__PURE__ */ jsx34("button", { type: "button", className: "tb-an-step", "data-tb-an-next": "", "aria-label": word("announcement.next", "Next announcement"), onClick: () => step2(1), children: /* @__PURE__ */ jsx34("span", { "aria-hidden": "true", children: "\u203A" }) }),
3677
+ rotating && dismissible && activeMessage !== void 0 && dismissButton(activeMessage.id)
3678
+ ]
3679
+ }
3680
+ )
3681
+ ] });
3682
+ }
3683
+ function AnnouncementV2(props) {
3684
+ const builder = useBuilder();
3685
+ const site = builder?.site;
3686
+ const raw = site?.status === "ok" && isRecord(site.settings.announcement) ? site.settings.announcement : null;
3687
+ if (raw === null || !Array.isArray(raw.messages)) return /* @__PURE__ */ jsx34(Announcement, { ...props });
3688
+ return /* @__PURE__ */ jsx34(Bar, { raw, props, builder });
3689
+ }
3690
+ var ANNOUNCEMENT_V2_CSS = `@layer throttle{
3691
+ .tb-an{--tb-an-rf:0px;display:flex;align-items:stretch;box-sizing:border-box;min-block-size:var(--tb-an-hd,var(--tb-an-rf));background:var(--b-background,var(--tb-an-bg,var(--tb-color-primary,#111)))}
3692
+ .tb-an--reserve,.tb-an--rot{--tb-an-rf:2.5rem}
3693
+ .tb-an-track{flex:1 1 auto;min-inline-size:0}
3694
+ .tb-an .tb-b-announcement{background:var(--b-background,var(--tb-an-bg,var(--tb-color-primary,#111)));color:var(--b-color,var(--tb-an-fg,var(--tb-color-primary-foreground,#fff)));text-align:var(--b-align,center);overflow-wrap:anywhere}
3695
+ .tb-an[data-align=left] .tb-b-announcement{text-align:var(--b-align,start);justify-content:flex-start}
3696
+ .tb-an[data-align=right] .tb-b-announcement{text-align:var(--b-align,end);justify-content:flex-end}
3697
+ .tb-an--m .tb-b-announcement{font-size:var(--tb-text-m)}
3698
+ .tb-an-text{display:inline}
3699
+ .tb-an-step{flex:0 0 auto;min-inline-size:32px;padding:0;border:0;background:transparent;color:var(--b-color,var(--tb-an-fg,var(--tb-color-primary-foreground,#fff)));font:inherit;cursor:pointer}
3700
+ .tb-an-step:focus-visible{outline:2px solid currentColor;outline-offset:-2px}
3701
+ [dir=rtl] .tb-an-step span{display:inline-block;transform:scaleX(-1)}
3702
+ .tb-an--rot .tb-an-track{display:grid}
3703
+ .tb-an--rot .tb-an-msg{grid-area:1/1}
3704
+ .tb-an--rot .tb-an-msg:not([data-active]){visibility:hidden}
3705
+ @media (prefers-reduced-motion:no-preference){.tb-an--fade .tb-an-msg[data-active]{animation:tb-an-fade .4s ease}.tb-an--slide .tb-an-msg[data-active]{animation:tb-an-slide .4s ease}}
3706
+ @keyframes tb-an-fade{from{opacity:0}to{opacity:1}}
3707
+ @keyframes tb-an-slide{from{opacity:0;transform:translateY(-.75rem)}to{opacity:1;transform:none}}
3708
+ @media (max-width:1024.98px){.tb-an{min-block-size:var(--tb-an-ht,var(--tb-an-hd,var(--tb-an-rf)))}}
3709
+ @media (max-width:767.98px){.tb-an{min-block-size:var(--tb-an-hp,var(--tb-an-ht,var(--tb-an-hd,var(--tb-an-rf))))}}
3710
+ @media (min-width:1024.99px){.tb-an-hide-desktop{display:none}}
3711
+ @media (min-width:767.99px) and (max-width:1024.98px){.tb-an-hide-tablet{display:none}}
3712
+ @media (max-width:767.98px){.tb-an-hide-phone{display:none}}
3713
+ }`;
3714
+ var definition2 = BASIC_WIDGET_DEFINITIONS2.find((d) => d.type === "basic.announcement");
3715
+ if (definition2 === void 0) throw new Error("builder-schema has no basic.announcement definition");
3716
+ var announcementV2Widgets = [{ ...definition2, Component: AnnouncementV2 }];
3717
+
3718
+ // src/basics/v2/breadcrumbs.tsx
3719
+ import { useSiteDesign as useSiteDesign7 } from "@usethrottle/ui";
3720
+ import { safeUrl as safeUrl13 } from "@usethrottle/builder-schema";
3721
+
3722
+ // src/basics/v2/definitions.ts
3723
+ import { MB_BASIC_WIDGET_DEFINITIONS as MB_BASIC_WIDGET_DEFINITIONS2 } from "@usethrottle/builder-schema";
3724
+ function mbDefinition(type) {
3725
+ const found = MB_BASIC_WIDGET_DEFINITIONS2.filter((d) => d.type === type).sort((a, b) => b.v - a.v)[0];
3726
+ if (found === void 0) throw new Error(`No MB definition of ${type}`);
3727
+ return found;
3728
+ }
3729
+
3730
+ // src/basics/v2/breadcrumbs.tsx
3731
+ import { Fragment as Fragment23, jsx as jsx35, jsxs as jsxs26 } from "react/jsx-runtime";
3732
+ var SEPARATORS = { slash: "/", chevron: "\u203A", dot: "\xB7", arrow: "\u2192" };
3733
+ function jsonLdOn(settings) {
3734
+ if (!isRecord(settings) || !isRecord(settings.seo) || !isRecord(settings.seo.structuredData)) return false;
3735
+ return settings.seo.structuredData.breadcrumbs === true;
3736
+ }
3737
+ function Breadcrumbs({ props, data, mediaOrigin, resolveLink, editMode }) {
3738
+ const design = useSiteDesign7();
3739
+ const builder = useBuilder();
3740
+ const product = isRecord(data.product) ? data.product : null;
3741
+ const title = product === null ? void 0 : str(product.title) ?? str(product.handle);
3742
+ if (product === null || title === void 0) {
3743
+ return /* @__PURE__ */ jsxs26(Fragment23, { children: [
3744
+ /* @__PURE__ */ jsx35(BasicV2Styles, {}),
3745
+ /* @__PURE__ */ jsx35(Placeholder, { editMode, children: "The trail appears on a product page" })
3746
+ ] });
3747
+ }
3748
+ const href = (target2) => safeUrl13(resolveLink?.(target2), "href", { mediaOrigin });
3749
+ const trail = [{ name: str(design?.brand?.storeName?.trim()) ?? "Home", href: "/" }];
3750
+ for (const step2 of Array.isArray(product.breadcrumbs) ? product.breadcrumbs : []) {
3751
+ if (!isRecord(step2) || str(step2.name) === void 0) continue;
3752
+ const handle2 = str(step2.handle);
3753
+ trail.push({ name: step2.name, href: handle2 === void 0 ? null : href({ kind: "category", handle: handle2 }) });
3754
+ }
3755
+ const handle = str(product.handle);
3756
+ const current = { name: title, href: handle === void 0 ? null : href({ kind: "product", handle }) };
3757
+ const shown2 = props.showCurrent === false ? trail : [...trail, current];
3758
+ const separator = SEPARATORS[oneOf(props.separator, ["slash", "chevron", "dot", "arrow"], "slash")];
3759
+ const jsonLd = builder !== null && builder.site.status === "ok" && jsonLdOn(builder.site.settings) ? jsonLdString(breadcrumbJsonLd(shown2.flatMap((crumb) => crumb.href === null ? [] : [{ name: crumb.name, url: crumb.href }]))) : null;
3760
+ return /* @__PURE__ */ jsxs26(Fragment23, { children: [
3761
+ /* @__PURE__ */ jsx35(BasicV2Styles, {}),
3762
+ /* @__PURE__ */ jsxs26("nav", { className: "tb-b-crumbs", "aria-label": "Breadcrumb", children: [
3763
+ /* @__PURE__ */ jsx35("ol", { children: shown2.map((crumb, index) => {
3764
+ const last = index === shown2.length - 1 && props.showCurrent !== false;
3765
+ return /* @__PURE__ */ jsxs26("li", { children: [
3766
+ index > 0 && /* @__PURE__ */ jsx35("span", { className: "tb-b-crumbs-sep", "aria-hidden": "true", children: separator }),
3767
+ last ? /* @__PURE__ */ jsx35("span", { "aria-current": "page", children: crumb.name }) : crumb.href === null ? /* @__PURE__ */ jsx35("span", { children: crumb.name }) : /* @__PURE__ */ jsx35("a", { href: crumb.href, children: crumb.name })
3768
+ ] }, `${String(index)}:${crumb.name}`);
3769
+ }) }),
3770
+ jsonLd !== null && /* @__PURE__ */ jsx35("script", { type: "application/ld+json", children: jsonLd })
3771
+ ] })
3772
+ ] });
3773
+ }
3774
+ var breadcrumbsWidgets = [{ ...mbDefinition("basic.breadcrumbs"), Component: Breadcrumbs }];
3775
+
3776
+ // src/basics/v2/faq.tsx
3777
+ import { useId as useId3, useRef as useRef4, useState as useState7 } from "react";
3778
+ import { sanitizeRichContent } from "@usethrottle/builder-schema";
3779
+
3780
+ // src/basics/v2/markup.tsx
3781
+ import { createElement as createElement4, useEffect as useEffect8, useState as useState6 } from "react";
3782
+ import { RICH_CONTENT_ALLOWED_TAGS, SVG_ALLOWED_TAGS, SVG_MAX_BYTES, safeUrl as safeUrl14, sanitizeSvg } from "@usethrottle/builder-schema";
3783
+ import { jsx as jsx36 } from "react/jsx-runtime";
3784
+ var RICH = new Set(RICH_CONTENT_ALLOWED_TAGS);
3785
+ var SVG = new Set(SVG_ALLOWED_TAGS);
3786
+ var VOID2 = /* @__PURE__ */ new Set(["br", "hr", "img"]);
3787
+ var MAX_DEPTH4 = 24;
3788
+ var TOKEN = /<(\/?)([A-Za-z][A-Za-z0-9]*)((?:\s+[^\s="'<>/]+(?:="[^"]*")?)*)\s*(\/?)>|([^<]+)|</gu;
3789
+ var ATTR = /\s+([^\s="'<>/]+)(?:="([^"]*)")?/gu;
3790
+ var ENTITIES = { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'", nbsp: "\xA0" };
3791
+ function decode2(value) {
3792
+ return value.replace(/&(?:#x([0-9a-f]{1,6})|#(\d{1,7})|([a-z]{2,6}));/giu, (whole, hex, dec, name) => {
3793
+ if (name !== void 0) return Object.hasOwn(ENTITIES, name.toLowerCase()) ? ENTITIES[name.toLowerCase()] : whole;
3794
+ const code = hex !== void 0 ? Number.parseInt(hex, 16) : Number.parseInt(dec ?? "", 10);
3795
+ return code > 0 && code <= 1114111 && !(code >= 55296 && code <= 57343) ? String.fromCodePoint(code) : "";
3796
+ });
3797
+ }
3798
+ function parseMarkup(markup, kind) {
3799
+ const allowed = kind === "rich" ? RICH : SVG;
3800
+ const root = { tag: "#root", attrs: [], children: [] };
3801
+ const stack = [root];
3802
+ let skipping = 0;
3803
+ for (const match of markup.matchAll(TOKEN)) {
3804
+ const [, closing, name, attrText2, selfClose, text2] = match;
3805
+ const top = stack[stack.length - 1];
3806
+ if (name === void 0) {
3807
+ if (skipping === 0 && text2 !== void 0) top.children.push(decode2(text2));
3808
+ continue;
3809
+ }
3810
+ const tag = [...allowed].find((candidate) => candidate.toLowerCase() === name.toLowerCase());
3811
+ if (closing === "/") {
3812
+ if (skipping > 0) skipping -= 1;
3813
+ else if (tag !== void 0 && stack.length > 1 && top.tag === tag) stack.pop();
3814
+ continue;
3815
+ }
3816
+ const isVoid = VOID2.has(name.toLowerCase());
3817
+ if (tag === void 0 || stack.length > MAX_DEPTH4) {
3818
+ if (selfClose !== "/" && !isVoid) skipping += 1;
3819
+ continue;
3820
+ }
3821
+ if (skipping > 0) {
3822
+ if (selfClose !== "/" && !isVoid) skipping += 1;
3823
+ continue;
3824
+ }
3825
+ const attrs = [];
3826
+ for (const a of (attrText2 ?? "").matchAll(ATTR)) attrs.push([a[1], decode2(a[2] ?? "")]);
3827
+ const element = { tag, attrs, children: [] };
3828
+ top.children.push(element);
3829
+ if (selfClose !== "/" && !isVoid) stack.push(element);
3830
+ }
3831
+ return root.children;
3832
+ }
3833
+ function textOf2(nodes) {
3834
+ return nodes.map((n) => typeof n === "string" ? n : n.tag === "br" ? " " : textOf2(n.children)).join("");
3835
+ }
3836
+ var SPECIAL = {
3837
+ class: "className",
3838
+ colspan: "colSpan",
3839
+ rowspan: "rowSpan",
3840
+ "xlink:href": "xlinkHref",
3841
+ "xml:space": "xmlSpace",
3842
+ "xmlns:xlink": "xmlnsXlink"
2611
3843
  };
2612
- function PartBoundary({
2613
- label,
2614
- resetKey,
2615
- children
2616
- }) {
3844
+ var camel = (name) => name.replace(/-([a-z])/gu, (_m, c) => c.toUpperCase());
3845
+ function styleOf(value) {
3846
+ const out = {};
3847
+ for (const declaration of value.split(";")) {
3848
+ const colon = declaration.indexOf(":");
3849
+ if (colon === -1) continue;
3850
+ const property = declaration.slice(0, colon).trim();
3851
+ const v = declaration.slice(colon + 1).trim();
3852
+ if (/^[a-z][a-z-]*$/u.test(property) && v !== "") out[camel(property)] = v;
3853
+ }
3854
+ return out;
3855
+ }
3856
+ var HYPHENATED = /* @__PURE__ */ new Set([
3857
+ "alignment-baseline",
3858
+ "baseline-shift",
3859
+ "clip-path",
3860
+ "clip-rule",
3861
+ "color-interpolation",
3862
+ "color-interpolation-filters",
3863
+ "dominant-baseline",
3864
+ "fill-opacity",
3865
+ "fill-rule",
3866
+ "flood-color",
3867
+ "flood-opacity",
3868
+ "font-family",
3869
+ "font-size",
3870
+ "font-size-adjust",
3871
+ "font-stretch",
3872
+ "font-style",
3873
+ "font-variant",
3874
+ "font-weight",
3875
+ "letter-spacing",
3876
+ "lighting-color",
3877
+ "marker-end",
3878
+ "marker-mid",
3879
+ "marker-start",
3880
+ "paint-order",
3881
+ "shape-rendering",
3882
+ "stop-color",
3883
+ "stop-opacity",
3884
+ "stroke-dasharray",
3885
+ "stroke-dashoffset",
3886
+ "stroke-linecap",
3887
+ "stroke-linejoin",
3888
+ "stroke-miterlimit",
3889
+ "stroke-opacity",
3890
+ "stroke-width",
3891
+ "text-anchor",
3892
+ "text-decoration",
3893
+ "text-rendering",
3894
+ "vector-effect",
3895
+ "word-spacing",
3896
+ "writing-mode"
3897
+ ]);
3898
+ var DENIED_PROP = /^(?:children|key|ref|dangerously|innerhtml|outerhtml|suppress|on)/iu;
3899
+ function propName(name) {
3900
+ if (Object.hasOwn(SPECIAL, name)) return SPECIAL[name];
3901
+ if (/^(?:aria|data)-[a-z0-9-]{1,60}$/u.test(name)) return name;
3902
+ const prop = HYPHENATED.has(name) ? camel(name) : name;
3903
+ if (!/^[a-z][a-zA-Z0-9]*$/u.test(prop) || DENIED_PROP.test(prop)) return null;
3904
+ return prop;
3905
+ }
3906
+ function propsOf(element, key) {
3907
+ const props = { key };
3908
+ for (const [name, value] of element.attrs) {
3909
+ if (name === "style") {
3910
+ props.style = styleOf(value);
3911
+ continue;
3912
+ }
3913
+ const prop = propName(name);
3914
+ if (prop !== null) props[prop] = value;
3915
+ }
3916
+ return props;
3917
+ }
3918
+ var FRAGMENT = /^#[A-Za-z_][\w:.-]{0,99}$/u;
3919
+ function checkUrls(tag, props, mediaOrigin) {
3920
+ for (const key of ["href", "xlinkHref", "src"]) {
3921
+ if (!Object.hasOwn(props, key)) continue;
3922
+ const value = props[key];
3923
+ const safe = SVG.has(tag) ? typeof value === "string" && FRAGMENT.test(value) ? value : null : safeUrl14(value, key === "src" ? "src" : "href", { mediaOrigin });
3924
+ if (safe !== null) {
3925
+ props[key] = safe;
3926
+ continue;
3927
+ }
3928
+ if (tag === "a" || tag === "img") return false;
3929
+ delete props[key];
3930
+ }
3931
+ return true;
3932
+ }
3933
+ function renderMarkup(nodes, options = {}) {
3934
+ return nodes.map((node, index) => {
3935
+ if (typeof node === "string") return node;
3936
+ const props = { ...propsOf(node, index), ...options.extra?.(node) ?? {} };
3937
+ if (!checkUrls(node.tag, props, options.mediaOrigin ?? "")) return null;
3938
+ if (VOID2.has(node.tag)) return createElement4(node.tag, props);
3939
+ return createElement4(node.tag, props, ...renderMarkup(node.children, options));
3940
+ });
3941
+ }
3942
+ function svgElement(svg) {
3943
+ const clean = sanitizeSvg(svg).svg;
3944
+ if (clean === "") return null;
3945
+ const root = parseMarkup(clean, "svg")[0];
3946
+ if (root === void 0 || typeof root === "string" || root.tag !== "svg") return null;
3947
+ const withFill = root.attrs.some(([name]) => name === "fill") ? root : { ...root, attrs: [...root.attrs, ["fill", "currentColor"]] };
3948
+ return renderMarkup([withFill])[0] ?? null;
3949
+ }
3950
+ async function readSvg(response, mediaOrigin) {
3951
+ if (!response.ok || safeUrl14(response.url, "src", { mediaOrigin }) === null) return null;
3952
+ if (!/^image\/svg\+xml(?:\s*;|$)/iu.test(response.headers.get("content-type") ?? "")) return null;
3953
+ const reader = response.body?.getReader();
3954
+ if (reader === void 0) {
3955
+ const text3 = await response.text();
3956
+ return new TextEncoder().encode(text3).length > SVG_MAX_BYTES ? null : text3;
3957
+ }
3958
+ const decoder = new TextDecoder();
3959
+ let total = 0;
3960
+ let text2 = "";
3961
+ for (; ; ) {
3962
+ const { done, value } = await reader.read();
3963
+ if (done) return text2 + decoder.decode();
3964
+ total += value.length;
3965
+ if (total > SVG_MAX_BYTES) {
3966
+ await reader.cancel();
3967
+ return null;
3968
+ }
3969
+ text2 += decoder.decode(value, { stream: true });
3970
+ }
3971
+ }
3972
+ function SvgFromAsset({ asset, mediaOrigin, label }) {
3973
+ const src = isFrozenAsset(asset) ? safeUrl14(asset.url, "src", { mediaOrigin }) : null;
3974
+ const [source, setSource] = useState6(null);
3975
+ useEffect8(() => {
3976
+ if (src === null) return;
3977
+ const controller = new AbortController();
3978
+ fetch(src, { credentials: "omit", redirect: "error", signal: controller.signal }).then((response) => readSvg(response, mediaOrigin)).then((text2) => {
3979
+ if (text2 !== null && !controller.signal.aborted) setSource(text2);
3980
+ }).catch(() => void 0);
3981
+ return () => controller.abort();
3982
+ }, [src]);
3983
+ if (src === null) return null;
3984
+ const inline2 = source === null ? null : svgElement(source);
3985
+ if (inline2 !== null) return inline2;
3986
+ return /* @__PURE__ */ jsx36(AssetImage, { asset, mediaOrigin, alt: label ?? "", loading: "eager" });
3987
+ }
3988
+
3989
+ // src/basics/v2/faq.tsx
3990
+ import { Fragment as Fragment24, jsx as jsx37, jsxs as jsxs27 } from "react/jsx-runtime";
3991
+ function itemsOf(value) {
3992
+ if (!Array.isArray(value)) return [];
3993
+ return value.flatMap((row) => {
3994
+ if (!isRecord(row)) return [];
3995
+ const question = str(row.question);
3996
+ return question === void 0 ? [] : [{ question, answer: typeof row.answer === "string" ? row.answer : "" }];
3997
+ });
3998
+ }
3999
+ function faqJsonLdOn(settings) {
4000
+ if (!isRecord(settings) || !isRecord(settings.seo) || !isRecord(settings.seo.structuredData)) return false;
4001
+ return settings.seo.structuredData.faq === true;
4002
+ }
4003
+ function Faq({ props, mediaOrigin, editMode }) {
2617
4004
  const builder = useBuilder();
2618
- return /* @__PURE__ */ jsx29(Boundary, { label, resetKeys: [builder?.site, resetKey], onError: builder?.onError, children });
4005
+ const group = useId3();
4006
+ const root = useRef4(null);
4007
+ const [all2, setAll] = useState7(false);
4008
+ const items = itemsOf(props.items);
4009
+ if (items.length === 0) {
4010
+ return /* @__PURE__ */ jsxs27(Fragment24, { children: [
4011
+ /* @__PURE__ */ jsx37(BasicV2Styles, {}),
4012
+ /* @__PURE__ */ jsx37(Placeholder, { editMode, children: "Add questions in the settings" })
4013
+ ] });
4014
+ }
4015
+ const answers = items.map((item) => parseMarkup(sanitizeRichContent(item.answer, mediaOrigin).html, "rich"));
4016
+ const open = props.mode === "open";
4017
+ const oneOpen = props.oneOpen === true;
4018
+ const showAll = !open && props.expandAll === true && !oneOpen;
4019
+ const jsonLd = builder !== null && builder.site.status === "ok" && faqJsonLdOn(builder.site.settings) ? jsonLdString(faqJsonLd(items.map((item, index) => ({ question: item.question, answer: textOf2(answers[index] ?? []).trim() })))) : null;
4020
+ const toggleAll = () => {
4021
+ const next = !all2;
4022
+ for (const details of root.current?.querySelectorAll("details") ?? []) details.open = next;
4023
+ setAll(next);
4024
+ };
4025
+ return /* @__PURE__ */ jsxs27(Fragment24, { children: [
4026
+ /* @__PURE__ */ jsx37(BasicV2Styles, {}),
4027
+ /* @__PURE__ */ jsxs27("div", { className: "tb-b-faq", ref: root, children: [
4028
+ showAll && /* @__PURE__ */ jsx37("button", { type: "button", className: "tb-b-faq-all", "aria-expanded": all2, onClick: toggleAll, children: all2 ? "Collapse all" : "Expand all" }),
4029
+ items.map(
4030
+ (item, index) => open ? /* @__PURE__ */ jsxs27("div", { className: "tb-b-faq-item", children: [
4031
+ /* @__PURE__ */ jsx37("h3", { className: "tb-b-faq-q", children: item.question }),
4032
+ /* @__PURE__ */ jsx37("div", { className: "tb-b-faq-a", children: renderMarkup(answers[index] ?? [], { mediaOrigin }) })
4033
+ ] }, `${String(index)}:${item.question}`) : /* @__PURE__ */ jsxs27("details", { className: "tb-b-faq-item", ...oneOpen ? { name: `faq-${group}` } : {}, children: [
4034
+ /* @__PURE__ */ jsx37("summary", { className: "tb-b-faq-q", children: item.question }),
4035
+ /* @__PURE__ */ jsx37("div", { className: "tb-b-faq-a", children: renderMarkup(answers[index] ?? [], { mediaOrigin }) })
4036
+ ] }, `${String(index)}:${item.question}`)
4037
+ ),
4038
+ jsonLd !== null && /* @__PURE__ */ jsx37("script", { type: "application/ld+json", children: jsonLd })
4039
+ ] })
4040
+ ] });
4041
+ }
4042
+ var faqWidgets = [{ ...mbDefinition("basic.faq"), Component: Faq }];
4043
+
4044
+ // src/basics/v2/heading-v2.tsx
4045
+ var headingV2Widgets = [{ ...mbDefinition("basic.heading"), Component: Heading }];
4046
+
4047
+ // src/basics/v2/icon-list.tsx
4048
+ import { ICON_NAMES, Icon as Icon6 } from "@usethrottle/ui";
4049
+ import { Fragment as Fragment25, jsx as jsx38, jsxs as jsxs28 } from "react/jsx-runtime";
4050
+ var isIconName = (name) => typeof name === "string" && ICON_NAMES.includes(name);
4051
+ function IconList({ props, mediaOrigin, editMode }) {
4052
+ const rows = Array.isArray(props.items) ? props.items.flatMap((row) => isRecord(row) ? [row] : []) : [];
4053
+ if (rows.length === 0) {
4054
+ return /* @__PURE__ */ jsxs28(Fragment25, { children: [
4055
+ /* @__PURE__ */ jsx38(BasicV2Styles, {}),
4056
+ /* @__PURE__ */ jsx38(Placeholder, { editMode, children: "Add rows in the settings" })
4057
+ ] });
4058
+ }
4059
+ return /* @__PURE__ */ jsxs28(Fragment25, { children: [
4060
+ /* @__PURE__ */ jsx38(BasicV2Styles, {}),
4061
+ /* @__PURE__ */ jsx38("ul", { className: "tb-b-icons", children: rows.map((row, index) => /* @__PURE__ */ jsxs28("li", { children: [
4062
+ /* @__PURE__ */ jsx38("span", { className: "tb-b-icons-icon", "aria-hidden": "true", children: isFrozenAsset(row.svgAsset) ? /* @__PURE__ */ jsx38(SvgFromAsset, { asset: row.svgAsset, mediaOrigin }) : isIconName(row.icon) ? /* @__PURE__ */ jsx38(Icon6, { name: row.icon }) : null }),
4063
+ /* @__PURE__ */ jsx38("span", { className: "tb-b-icons-text", children: str(row.text) ?? "" })
4064
+ ] }, `${String(index)}:${str(row.text) ?? ""}`)) })
4065
+ ] });
4066
+ }
4067
+ var iconListWidgets = [{ ...mbDefinition("basic.icon-list"), Component: IconList }];
4068
+
4069
+ // src/basics/v2/merge.ts
4070
+ function mergeV2Widgets(v1, v2) {
4071
+ const replacement = /* @__PURE__ */ new Map();
4072
+ for (const widget of v2) {
4073
+ if (replacement.has(widget.type)) throw new Error(`Two v2 widgets of type ${widget.type}`);
4074
+ replacement.set(widget.type, widget);
4075
+ }
4076
+ const v1Types = new Set(v1.map((widget) => widget.type));
4077
+ return [
4078
+ ...v1.map((widget) => replacement.get(widget.type) ?? widget),
4079
+ ...[...replacement.values()].filter((widget) => !v1Types.has(widget.type))
4080
+ ];
2619
4081
  }
2620
4082
 
4083
+ // src/basics/v2/quote.tsx
4084
+ import { Fragment as Fragment26, jsx as jsx39, jsxs as jsxs29 } from "react/jsx-runtime";
4085
+ function Quote({ props, mediaOrigin, editMode, inlineEdit }) {
4086
+ const quote = inlineEdit?.("quote") ?? str(props.quote);
4087
+ if (quote === void 0) {
4088
+ return /* @__PURE__ */ jsxs29(Fragment26, { children: [
4089
+ /* @__PURE__ */ jsx39(BasicV2Styles, {}),
4090
+ /* @__PURE__ */ jsx39(Placeholder, { editMode, children: "Write the quote in the settings" })
4091
+ ] });
4092
+ }
4093
+ const name = str(props.name);
4094
+ const role = str(props.role);
4095
+ const image = isFrozenAsset(props.image) ? props.image : null;
4096
+ return /* @__PURE__ */ jsxs29(Fragment26, { children: [
4097
+ /* @__PURE__ */ jsx39(BasicV2Styles, {}),
4098
+ /* @__PURE__ */ jsxs29("figure", { className: "tb-b-quote", children: [
4099
+ /* @__PURE__ */ jsx39("blockquote", { children: quote }),
4100
+ (name !== void 0 || role !== void 0 || image !== null) && /* @__PURE__ */ jsxs29("figcaption", { children: [
4101
+ image !== null && /* @__PURE__ */ jsx39(AssetImage, { asset: image, mediaOrigin, alt: "", className: "tb-b-quote-photo" }),
4102
+ /* @__PURE__ */ jsxs29("span", { className: "tb-b-quote-by", children: [
4103
+ name !== void 0 && /* @__PURE__ */ jsx39("span", { className: "tb-b-quote-name", children: name }),
4104
+ role !== void 0 && /* @__PURE__ */ jsx39("span", { className: "tb-b-quote-role", children: role })
4105
+ ] })
4106
+ ] })
4107
+ ] })
4108
+ ] });
4109
+ }
4110
+ var quoteWidgets = [{ ...mbDefinition("basic.quote"), Component: Quote }];
4111
+
4112
+ // src/basics/v2/rich-content.tsx
4113
+ import { sanitizeRichContent as sanitizeRichContent2 } from "@usethrottle/builder-schema";
4114
+ import { Fragment as Fragment27, jsx as jsx40, jsxs as jsxs30 } from "react/jsx-runtime";
4115
+ var slug = (text2) => text2.toLowerCase().normalize("NFKD").replace(/[^a-z0-9]+/gu, "-").replace(/^-+|-+$/gu, "").slice(0, 40);
4116
+ function headings(nodes, nodeId) {
4117
+ const found = /* @__PURE__ */ new Map();
4118
+ const visit = (list2) => {
4119
+ for (const node of list2) {
4120
+ if (typeof node === "string") continue;
4121
+ if (node.tag === "h2" || node.tag === "h3") {
4122
+ const label = textOf2(node.children).replace(/\s+/gu, " ").trim();
4123
+ const n = found.size + 1;
4124
+ found.set(node, { id: `${nodeId}-${String(n)}${slug(label) === "" ? "" : `-${slug(label)}`}`, level: node.tag === "h2" ? 2 : 3, label });
4125
+ }
4126
+ visit(node.children);
4127
+ }
4128
+ };
4129
+ visit(nodes);
4130
+ return found;
4131
+ }
4132
+ function RichContent({ node, props, mediaOrigin, editMode }) {
4133
+ const html = str(props.html);
4134
+ if (html === void 0) {
4135
+ return /* @__PURE__ */ jsxs30(Fragment27, { children: [
4136
+ /* @__PURE__ */ jsx40(BasicV2Styles, {}),
4137
+ /* @__PURE__ */ jsx40(Placeholder, { editMode, children: "Add content in the settings" })
4138
+ ] });
4139
+ }
4140
+ const tree = parseMarkup(sanitizeRichContent2(html, mediaOrigin).html, "rich");
4141
+ const entries = headings(tree, node.id);
4142
+ const toc = props.toc === true ? [...entries.values()].filter((e) => e.label !== "") : [];
4143
+ return /* @__PURE__ */ jsxs30(Fragment27, { children: [
4144
+ /* @__PURE__ */ jsx40(BasicV2Styles, {}),
4145
+ /* @__PURE__ */ jsxs30("div", { className: "tb-b-rich", children: [
4146
+ toc.length > 0 && /* @__PURE__ */ jsxs30("nav", { className: "tb-b-toc", "aria-label": str(props.tocTitle) ?? "Contents", children: [
4147
+ /* @__PURE__ */ jsx40("p", { className: "tb-b-toc-title", children: str(props.tocTitle) ?? "Contents" }),
4148
+ /* @__PURE__ */ jsx40("ol", { children: toc.map((entry) => /* @__PURE__ */ jsx40("li", { className: `tb-b-toc-l${String(entry.level)}`, children: /* @__PURE__ */ jsx40("a", { href: `#${entry.id}`, children: entry.label }) }, entry.id)) })
4149
+ ] }),
4150
+ renderMarkup(tree, {
4151
+ mediaOrigin,
4152
+ extra: (element) => {
4153
+ const entry = entries.get(element);
4154
+ return entry === void 0 ? void 0 : { id: entry.id };
4155
+ }
4156
+ })
4157
+ ] })
4158
+ ] });
4159
+ }
4160
+ var richContentWidgets = [{ ...mbDefinition("basic.rich-content"), Component: RichContent }];
4161
+
4162
+ // src/basics/v2/svg.tsx
4163
+ import { Fragment as Fragment28, jsx as jsx41, jsxs as jsxs31 } from "react/jsx-runtime";
4164
+ function Svg({ props, mediaOrigin, editMode }) {
4165
+ const pasted = str(props.svg);
4166
+ const label = str(props.label);
4167
+ const inline2 = pasted === void 0 ? null : svgElement(pasted);
4168
+ const asset = pasted === void 0 && props.asset !== null && props.asset !== void 0 ? props.asset : null;
4169
+ if (inline2 === null && asset === null) {
4170
+ return /* @__PURE__ */ jsxs31(Fragment28, { children: [
4171
+ /* @__PURE__ */ jsx41(BasicV2Styles, {}),
4172
+ /* @__PURE__ */ jsx41(Placeholder, { editMode, children: "Paste an SVG or pick one from the media library" })
4173
+ ] });
4174
+ }
4175
+ const decorative = props.decorative !== false;
4176
+ const access = decorative ? { "aria-hidden": true } : label === void 0 ? {} : { role: "img", "aria-label": label };
4177
+ return /* @__PURE__ */ jsxs31(Fragment28, { children: [
4178
+ /* @__PURE__ */ jsx41(BasicV2Styles, {}),
4179
+ /* @__PURE__ */ jsx41("div", { className: "tb-b-svg", ...access, children: inline2 ?? /* @__PURE__ */ jsx41(SvgFromAsset, { asset, mediaOrigin, ...label === void 0 || decorative ? {} : { label } }) })
4180
+ ] });
4181
+ }
4182
+ var svgWidgets = [{ ...mbDefinition("basic.svg"), Component: Svg }];
4183
+
4184
+ // src/basics/index.ts
4185
+ var BASIC_COMPONENTS = {
4186
+ "basic.heading": Heading,
4187
+ "basic.text": Text,
4188
+ "basic.image": Image,
4189
+ "basic.button": Button,
4190
+ "basic.spacer": Spacer,
4191
+ "basic.divider": Divider,
4192
+ "basic.video": Video,
4193
+ "basic.logo": Logo,
4194
+ "basic.menu": Menu,
4195
+ "basic.announcement": Announcement,
4196
+ "basic.copyright": Copyright,
4197
+ "basic.countdown": Countdown
4198
+ };
4199
+ var v1Widgets = BASIC_WIDGET_DEFINITIONS3.flatMap(
4200
+ (definition3) => definition3.v === 1 && Object.hasOwn(BASIC_COMPONENTS, definition3.type) ? [{ ...definition3, Component: BASIC_COMPONENTS[definition3.type] }] : []
4201
+ );
4202
+ var widgets = mergeV2Widgets(v1Widgets, [
4203
+ ...faqWidgets,
4204
+ ...richContentWidgets,
4205
+ ...breadcrumbsWidgets,
4206
+ ...svgWidgets,
4207
+ ...iconListWidgets,
4208
+ ...quoteWidgets,
4209
+ ...menuV2Widgets,
4210
+ ...announcementV2Widgets,
4211
+ ...headingV2Widgets
4212
+ ]);
4213
+ var basicPack = { id: "basic", version: "0.0.0", widgets, dataSources: [] };
4214
+
4215
+ // src/custom/factory.ts
4216
+ import { createElement as createElement5 } from "react";
4217
+
2621
4218
  // src/custom/composite-widget.tsx
2622
- import { jsx as jsx30 } from "react/jsx-runtime";
4219
+ import { Suspense as Suspense3 } from "react";
4220
+ import { pageDocumentSchema, validateSettingValue as validateSettingValue3 } from "@usethrottle/builder-schema";
4221
+ import { jsx as jsx42 } from "react/jsx-runtime";
2623
4222
  var SETTING_KEY_RE = /^[a-z][A-Za-z0-9]{0,39}$/;
2624
4223
  var NODE_ID_RE = /^[a-z0-9]{8,24}$/;
2625
4224
  var WRAP = { section: "zzcompsec001", column: "zzcompcol001", inner: "zzcompinr001" };
2626
- var isRecord4 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
4225
+ var isRecord6 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
2627
4226
  var compiled3 = /* @__PURE__ */ new WeakMap();
2628
4227
  function parseBody(raw) {
2629
- if (!isRecord4(raw)) return null;
4228
+ if (!isRecord6(raw)) return null;
2630
4229
  const columns = Array.isArray(raw.columns) ? raw.columns : void 0;
2631
4230
  const stack = Array.isArray(raw.stack) ? raw.stack : void 0;
2632
4231
  if (columns === void 0 === (stack === void 0)) return null;
2633
4232
  const children = columns !== void 0 ? [{ id: WRAP.inner, type: "inner-section", props: {}, columns }] : stack ?? [];
2634
- if (stack?.some((node) => isRecord4(node) && node.type === "inner-section")) return null;
4233
+ if (stack?.some((node) => isRecord6(node) && node.type === "inner-section")) return null;
2635
4234
  const parsed2 = pageDocumentSchema.safeParse({
2636
4235
  schemaVersion: 1,
2637
4236
  sections: [{ id: WRAP.section, type: "section", props: {}, columns: [{ id: WRAP.column, type: "column", props: { width: 100 }, children }] }]
@@ -2664,38 +4263,38 @@ function compile2(snapshot) {
2664
4263
  const bindings = [];
2665
4264
  if (extra.bindings !== void 0 && !Array.isArray(extra.bindings)) return refuse("bindings is not a list");
2666
4265
  for (const raw of extra.bindings ?? []) {
2667
- if (!isRecord4(raw) || typeof raw.setting !== "string" || !SETTING_KEY_RE.test(raw.setting) || !Array.isArray(raw.targets)) {
4266
+ if (!isRecord6(raw) || typeof raw.setting !== "string" || !SETTING_KEY_RE.test(raw.setting) || !Array.isArray(raw.targets)) {
2668
4267
  return refuse("a binding is malformed");
2669
4268
  }
2670
4269
  const targets = [];
2671
- for (const target of raw.targets) {
2672
- if (!isRecord4(target) || typeof target.node !== "string" || !NODE_ID_RE.test(target.node) || typeof target.prop !== "string" || !SETTING_KEY_RE.test(target.prop)) {
4270
+ for (const target2 of raw.targets) {
4271
+ if (!isRecord6(target2) || typeof target2.node !== "string" || !NODE_ID_RE.test(target2.node) || typeof target2.prop !== "string" || !SETTING_KEY_RE.test(target2.prop)) {
2673
4272
  return refuse("a binding target is malformed");
2674
4273
  }
2675
- targets.push({ node: target.node, prop: target.prop });
4274
+ targets.push({ node: target2.node, prop: target2.prop });
2676
4275
  }
2677
4276
  bindings.push({ setting: raw.setting, targets });
2678
4277
  }
2679
4278
  const data = [];
2680
- if (extra.data !== void 0 && !isRecord4(extra.data)) return refuse("data is not a record");
4279
+ if (extra.data !== void 0 && !isRecord6(extra.data)) return refuse("data is not a record");
2681
4280
  for (const [name, raw] of Object.entries(extra.data ?? {})) {
2682
- if (!SETTING_KEY_RE.test(name) || !isRecord4(raw) || !Array.isArray(raw.targets)) return refuse("a data input is malformed");
4281
+ if (!SETTING_KEY_RE.test(name) || !isRecord6(raw) || !Array.isArray(raw.targets)) return refuse("a data input is malformed");
2683
4282
  const targets = [];
2684
- for (const target of raw.targets) {
2685
- if (!isRecord4(target) || typeof target.node !== "string" || !NODE_ID_RE.test(target.node) || typeof target.input !== "string" || !SETTING_KEY_RE.test(target.input)) {
4283
+ for (const target2 of raw.targets) {
4284
+ if (!isRecord6(target2) || typeof target2.node !== "string" || !NODE_ID_RE.test(target2.node) || typeof target2.input !== "string" || !SETTING_KEY_RE.test(target2.input)) {
2686
4285
  return refuse("a data target is malformed");
2687
4286
  }
2688
- targets.push({ node: target.node, input: target.input });
4287
+ targets.push({ node: target2.node, input: target2.input });
2689
4288
  }
2690
4289
  data.push([name, { targets }]);
2691
4290
  }
2692
4291
  return { body, bindings, data };
2693
4292
  }
2694
- var DEVICES3 = ["tablet", "phone"];
4293
+ var DEVICES6 = ["tablet", "phone"];
2695
4294
  function withoutAnchor(node) {
2696
4295
  delete node.props.anchor;
2697
4296
  const responsive = node.responsive;
2698
- for (const device of DEVICES3) if (responsive?.[device] !== void 0) delete responsive[device].anchor;
4297
+ for (const device of DEVICES6) if (responsive?.[device] !== void 0) delete responsive[device].anchor;
2699
4298
  }
2700
4299
  function instanceId(outer, inner) {
2701
4300
  let a = 3735928559;
@@ -2709,7 +4308,7 @@ function instanceId(outer, inner) {
2709
4308
  b = Math.imul(b ^ b >>> 16, 2246822507) ^ Math.imul(a ^ a >>> 13, 3266489909);
2710
4309
  return `i${(a >>> 0).toString(36).padStart(7, "0")}${(b >>> 0).toString(36).padStart(7, "0")}${(outer.length + inner.length).toString(36)}`;
2711
4310
  }
2712
- function build(input) {
4311
+ function build2(input) {
2713
4312
  const { snapshot, registry, node: outer, props, data } = input;
2714
4313
  const body = structuredClone(input.compiled.body);
2715
4314
  const assets = {};
@@ -2738,11 +4337,11 @@ function build(input) {
2738
4337
  return id;
2739
4338
  }
2740
4339
  if (field.control === "link") {
2741
- if (!isRecord4(value) || typeof value.kind !== "string") return null;
2742
- const { href, ...target } = value;
2743
- if (target.kind === "url") return typeof href === "string" ? { kind: "url", href } : null;
2744
- hrefs.set(JSON.stringify(target), typeof href === "string" ? href : null);
2745
- return target;
4340
+ if (!isRecord6(value) || typeof value.kind !== "string") return null;
4341
+ const { href, ...target2 } = value;
4342
+ if (target2.kind === "url") return typeof href === "string" ? { kind: "url", href } : null;
4343
+ hrefs.set(JSON.stringify(target2), typeof href === "string" ? href : null);
4344
+ return target2;
2746
4345
  }
2747
4346
  return value;
2748
4347
  };
@@ -2750,21 +4349,21 @@ function build(input) {
2750
4349
  const field = fields.get(binding.setting);
2751
4350
  if (field === void 0 || !Object.hasOwn(props, binding.setting)) continue;
2752
4351
  const value = props[binding.setting];
2753
- for (const target of binding.targets) {
2754
- const inner = byId.get(target.node);
2755
- const innerField = inner === void 0 ? void 0 : registry.widget(inner.type, inner.v)?.settings.find((f) => f.key === target.prop);
4352
+ for (const target2 of binding.targets) {
4353
+ const inner = byId.get(target2.node);
4354
+ const innerField = inner === void 0 ? void 0 : registry.widget(inner.type, inner.v)?.settings.find((f) => f.key === target2.prop);
2756
4355
  if (inner === void 0 || innerField === void 0 || innerField.control !== field.control) continue;
2757
4356
  const converted = convert(field, value);
2758
4357
  if (validateSettingValue3(innerField, converted) !== null) continue;
2759
- inner.props[target.prop] = converted;
4358
+ inner.props[target2.prop] = converted;
2760
4359
  const responsive = inner.responsive;
2761
- for (const device of DEVICES3) {
2762
- if (responsive?.[device] !== void 0) delete responsive[device][target.prop];
4360
+ for (const device of DEVICES6) {
4361
+ if (responsive?.[device] !== void 0) delete responsive[device][target2.prop];
2763
4362
  const raw = outer.responsive?.[device];
2764
4363
  const plain = field.output === "css" && field.translatable !== true && field.control !== "image" && field.control !== "link";
2765
4364
  if (plain && raw !== void 0 && Object.hasOwn(raw, binding.setting) && validateSettingValue3(innerField, raw[binding.setting]) === null) {
2766
4365
  const target$ = inner.responsive ?? (inner.responsive = {});
2767
- (target$[device] ?? (target$[device] = {}))[target.prop] = raw[binding.setting];
4366
+ (target$[device] ?? (target$[device] = {}))[target2.prop] = raw[binding.setting];
2768
4367
  }
2769
4368
  }
2770
4369
  }
@@ -2772,11 +4371,11 @@ function build(input) {
2772
4371
  for (const [name, input$] of input.compiled.data) {
2773
4372
  if (!Object.hasOwn(data, name) || data[name] === void 0) continue;
2774
4373
  const key = `composite.${name}`;
2775
- for (const target of input$.targets) {
2776
- const inner = byId.get(target.node);
4374
+ for (const target2 of input$.targets) {
4375
+ const inner = byId.get(target2.node);
2777
4376
  const def = inner === void 0 ? void 0 : registry.widget(inner.type, inner.v);
2778
- if (inner === void 0 || def?.data === void 0 || !Object.hasOwn(def.data, target.input)) continue;
2779
- inner.data = { ...inner.data ?? {}, [target.input]: { source: key } };
4377
+ if (inner === void 0 || def?.data === void 0 || !Object.hasOwn(def.data, target2.input)) continue;
4378
+ inner.data = { ...inner.data ?? {}, [target2.input]: { source: key } };
2780
4379
  innerData[key] = data[name];
2781
4380
  }
2782
4381
  }
@@ -2804,12 +4403,12 @@ function CompositeBody(props) {
2804
4403
  const { snapshot, registry, node, data, locale, mediaOrigin, budget, resolveLink, interactive, idScope } = props;
2805
4404
  const composite = compileComposite(snapshot);
2806
4405
  if (composite === null) return null;
2807
- const built = build({ snapshot, compiled: composite, registry, node, props: props.props, data });
4406
+ const built = build2({ snapshot, compiled: composite, registry, node, props: props.props, data });
2808
4407
  if (!(budget ?? new RenderBudget()).take(built.weight)) {
2809
4408
  warnOnce(`composite-weight:${snapshot.type}@${String(snapshot.v)}`, `${snapshot.type} would render too many nodes; rendering nothing for it`);
2810
4409
  return null;
2811
4410
  }
2812
- return /* @__PURE__ */ jsx30(
4411
+ return /* @__PURE__ */ jsx42(
2813
4412
  BuilderRenderer,
2814
4413
  {
2815
4414
  document: built.document,
@@ -2820,28 +4419,28 @@ function CompositeBody(props) {
2820
4419
  mediaOrigin,
2821
4420
  interactive,
2822
4421
  idScope,
2823
- resolveLink: (target) => built.hrefs.get(JSON.stringify(target)) ?? resolveLink?.(target) ?? null
4422
+ resolveLink: (target2) => built.hrefs.get(JSON.stringify(target2)) ?? resolveLink?.(target2) ?? null
2824
4423
  }
2825
4424
  );
2826
4425
  }
2827
4426
  function CompositeWidget(props) {
2828
- return /* @__PURE__ */ jsx30(PartBoundary, { label: `${props.snapshot.type}@${String(props.snapshot.v)}`, children: /* @__PURE__ */ jsx30(Suspense3, { fallback: null, children: /* @__PURE__ */ jsx30(CompositeBody, { ...props }) }) });
4427
+ return /* @__PURE__ */ jsx42(PartBoundary, { label: `${props.snapshot.type}@${String(props.snapshot.v)}`, children: /* @__PURE__ */ jsx42(Suspense3, { fallback: null, children: /* @__PURE__ */ jsx42(CompositeBody, { ...props }) }) });
2829
4428
  }
2830
4429
 
2831
4430
  // src/custom/factory.ts
2832
4431
  var isDisabled = (snapshot) => snapshot.status === "disabled";
2833
- var Disabled = ({ editMode }) => editMode ? createElement3("div", { className: "tb-missing" }, "This custom widget is disabled") : null;
4432
+ var Disabled = ({ editMode }) => editMode ? createElement5("div", { className: "tb-missing" }, "This custom widget is disabled") : null;
2834
4433
  var customWidgetFactory = (snapshot, registry) => {
2835
4434
  if (isDisabled(snapshot)) return Disabled;
2836
4435
  if (snapshot.kind === "template") {
2837
4436
  const template = compileTemplate(snapshot, registry);
2838
4437
  if (template === null) return null;
2839
- const Component2 = (props) => createElement3(TemplateWidget, { ...props, snapshot, registry });
4438
+ const Component2 = (props) => createElement5(TemplateWidget, { ...props, snapshot, registry });
2840
4439
  componentWeights.set(Component2, template.weight);
2841
4440
  return Component2;
2842
4441
  }
2843
4442
  if (compileComposite(snapshot) === null) return null;
2844
- return (props) => createElement3(CompositeWidget, { ...props, snapshot, registry });
4443
+ return (props) => createElement5(CompositeWidget, { ...props, snapshot, registry });
2845
4444
  };
2846
4445
 
2847
4446
  // src/registry.ts
@@ -2855,11 +4454,11 @@ function createRendererRegistry(packs, options = {}) {
2855
4454
  const sources = [];
2856
4455
  const resolvers = /* @__PURE__ */ new Map();
2857
4456
  for (const pack of all2) {
2858
- for (const { Component: Component2, ...definition } of pack.widgets) {
2859
- const key = customKey(definition.type, definition.v);
4457
+ for (const { Component: Component2, ...definition3 } of pack.widgets) {
4458
+ const key = customKey(definition3.type, definition3.v);
2860
4459
  if (components.has(key)) continue;
2861
4460
  components.set(key, Component2);
2862
- definitions.push(definition);
4461
+ definitions.push(definition3);
2863
4462
  }
2864
4463
  for (const { resolve, ...descriptor } of pack.dataSources) {
2865
4464
  if (resolvers.has(descriptor.id)) continue;
@@ -2868,7 +4467,7 @@ function createRendererRegistry(packs, options = {}) {
2868
4467
  }
2869
4468
  }
2870
4469
  const factory = options.customWidget ?? DEFAULT_CUSTOM_WIDGET;
2871
- const build2 = (custom) => {
4470
+ const build3 = (custom) => {
2872
4471
  const schema = createRegistry(definitions, sources, custom);
2873
4472
  const snapshots = new Map(custom.map((snapshot) => [customKey(snapshot.type, snapshot.v), snapshot]));
2874
4473
  const built = /* @__PURE__ */ new Map();
@@ -2889,49 +4488,102 @@ function createRendererRegistry(packs, options = {}) {
2889
4488
  if (!built.has(key)) built.set(key, factory(snapshot, registry));
2890
4489
  return built.get(key) ?? void 0;
2891
4490
  },
2892
- withCustom: (more) => build2([...custom, ...more])
4491
+ withCustom: (more) => build3([...custom, ...more])
2893
4492
  };
2894
4493
  return registry;
2895
4494
  };
2896
- return build2([]);
4495
+ return build3([]);
2897
4496
  }
2898
4497
 
2899
4498
  // src/server/load-page.ts
2900
4499
  import { BuilderNotFoundError } from "@usethrottle/builder";
4500
+ var isOwnPath = (path) => typeof path === "string" && path !== "/" && path.startsWith("/") && !path.startsWith("/pages/");
4501
+ async function loadBuilderPageByPath(options) {
4502
+ const { path, locale } = options;
4503
+ const client = clientOf(options);
4504
+ if (client.pages.getByPath !== void 0) {
4505
+ const found = await client.pages.getByPath(path, { locale });
4506
+ if (isRedirect(found)) return { kind: "redirect", redirectTo: found.redirectTo };
4507
+ return loadBuilderPage({ ...options, slug: found.slug });
4508
+ }
4509
+ const summaries = await client.pages.list();
4510
+ const summary = summaries.find((entry) => entry.path === path && isOwnPath(entry.path));
4511
+ if (summary !== void 0) return loadBuilderPage({ ...options, slug: summary.slug });
4512
+ const bySlug = summaries.find((entry) => `/${entry.slug}` === path);
4513
+ if (bySlug !== void 0 && isOwnPath(bySlug.path) && bySlug.path !== path)
4514
+ return { kind: "redirect", redirectTo: bySlug.path };
4515
+ throw new BuilderNotFoundError(path);
4516
+ }
4517
+ async function loadOwnPagePaths(options) {
4518
+ return (await clientOf(options).pages.list()).map((entry) => entry.path).filter(isOwnPath);
4519
+ }
2901
4520
  async function loadBuilderPage(options) {
2902
- const { slug, locale, packs = [], slots, currency } = options;
2903
- const bundle = await getBundle({ client: clientOf(options), locale, page: slug, slots });
4521
+ const { slug: slug2, locale, packs = [], slots, currency } = options;
4522
+ const bundle = await getBundle({ client: clientOf(options), locale, page: slug2, slots });
2904
4523
  const found = bundle.page;
2905
- if (found === void 0) throw new BuilderNotFoundError(slug);
4524
+ if (found === void 0) throw new BuilderNotFoundError(slug2);
2906
4525
  if (isRedirect(found)) return { kind: "redirect", redirectTo: found.redirectTo };
2907
4526
  const shared = { ...found, savedSections: found.savedSections ?? bundle.savedSections, code: found.code ?? bundle.code };
2908
4527
  const data = await staticDataFor([shared], createRendererRegistry(packs), locale, currency);
2909
4528
  return pageOf(shared, data);
2910
4529
  }
2911
4530
 
4531
+ // src/server/load-template.ts
4532
+ function templateRootOf(packs, name) {
4533
+ for (const pack of packs ?? []) {
4534
+ const found = pack.templates?.find((entry) => entry.name === name);
4535
+ if (found !== void 0) return found.Root;
4536
+ }
4537
+ return void 0;
4538
+ }
4539
+ async function loadBuilderTemplate(options) {
4540
+ const { name, locale, packs = [], currency, shared } = options;
4541
+ const answer = await clientOf(options).getTemplate(name, { locale });
4542
+ const document2 = answer.customWidgets === void 0 ? answer.document : {
4543
+ ...answer.document,
4544
+ customWidgets: { ...answer.customWidgets, ...answer.document.customWidgets }
4545
+ };
4546
+ const loaded = { ...answer, generation: answer.generation ?? 0, document: document2 };
4547
+ const data = await staticDataFor([loaded], createRendererRegistry(packs), locale, currency);
4548
+ return { part: partOf(loaded, data, shared), meta: answer.meta };
4549
+ }
4550
+
2912
4551
  // src/next/seo.ts
2913
- import { safeUrl as safeUrl11 } from "@usethrottle/builder-schema";
2914
- var isRec = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
4552
+ import { TEMPLATE_NOINDEX_DEFAULT, safeUrl as safeUrl15 } from "@usethrottle/builder-schema";
4553
+ var isRec2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
2915
4554
  var text = (value) => typeof value === "string" && value.trim() !== "" ? value : void 0;
2916
4555
  var ORIGIN_RE = /^https?:\/\/[^\s/\\]+$/iu;
2917
4556
  var DEFAULT_PAGE_ROUTE = "/pages/{handle}";
2918
4557
  var LOCALE_SEGMENT_RE = /^[A-Za-z0-9-]+$/u;
2919
4558
  function pageSeoOf(page) {
2920
- const seo = isRec(page.seo) ? page.seo : {};
4559
+ const seo = isRec2(page.seo) ? page.seo : {};
2921
4560
  const title = text(seo.title);
2922
4561
  const description = text(seo.description);
4562
+ const canonical = text(seo.canonical);
2923
4563
  return {
2924
4564
  ...title === void 0 ? {} : { title },
2925
4565
  ...description === void 0 ? {} : { description },
4566
+ ...canonical === void 0 ? {} : { canonical },
2926
4567
  shareImage: seo.shareImage,
2927
4568
  noindex: seo.noindex === true
2928
4569
  };
2929
4570
  }
4571
+ function canonicalOverrideOf(value) {
4572
+ return value !== void 0 && /^https?:\/\/[^\s\\]+$/iu.test(value) ? value : void 0;
4573
+ }
4574
+ function canonicalFor(url, kind) {
4575
+ const parsed2 = new URL(url);
4576
+ const page = kind === "listing" ? parsed2.searchParams.get("page") : null;
4577
+ parsed2.hash = "";
4578
+ parsed2.search = "";
4579
+ if (page !== null && /^\d{1,6}$/u.test(page)) parsed2.searchParams.set("page", page);
4580
+ return parsed2.toString();
4581
+ }
2930
4582
  function imageOf(value, mediaOrigin) {
2931
- const raw = isRec(value) ? value.url : value;
2932
- const url = safeUrl11(raw, "src", { mediaOrigin });
4583
+ const raw = isRec2(value) ? value.url : value;
4584
+ const url = safeUrl15(raw, "src", { mediaOrigin });
2933
4585
  if (url === null) return void 0;
2934
- const frozen = isRec(value) ? value : {};
4586
+ const frozen = isRec2(value) ? value : {};
2935
4587
  return {
2936
4588
  url,
2937
4589
  ...typeof frozen.width === "number" ? { width: frozen.width } : {},
@@ -2939,51 +4591,113 @@ function imageOf(value, mediaOrigin) {
2939
4591
  };
2940
4592
  }
2941
4593
  function pagePathOf(settings, page, resolve) {
2942
- const routes = isRec(settings.routes) ? settings.routes : {};
4594
+ const routes = isRec2(settings.routes) ? settings.routes : {};
2943
4595
  const pattern = text(routes.page) ?? DEFAULT_PAGE_ROUTE;
2944
- const path = safeUrl11(pattern.replaceAll("{handle}", () => page.slug), "href", { mediaOrigin: "" });
4596
+ const own = page.path !== void 0 && page.path !== "/" && !page.path.startsWith("/pages/") ? safeUrl15(page.path, "href", { mediaOrigin: "" }) : null;
4597
+ const path = own ?? safeUrl15(pattern.replaceAll("{handle}", () => page.slug), "href", { mediaOrigin: "" });
2945
4598
  if (path === null || resolve === void 0) return path;
2946
- return safeUrl11(resolve({ ...page, path }), "href", { mediaOrigin: "" }) ?? path;
4599
+ return safeUrl15(resolve({ ...page, path }), "href", { mediaOrigin: "" }) ?? path;
2947
4600
  }
2948
4601
  function originOf(storeUrl) {
2949
4602
  const origin = storeUrl?.replace(/\/+$/u, "");
2950
4603
  return origin !== void 0 && ORIGIN_RE.test(origin) ? origin : void 0;
2951
4604
  }
2952
4605
  function siteLocales(settings) {
2953
- const locales = isRec(settings.locales) ? settings.locales : {};
2954
- const list = Array.isArray(locales.list) ? locales.list.filter((locale) => typeof locale === "string" && LOCALE_SEGMENT_RE.test(locale)) : [];
2955
- return { list, fallback: typeof locales.default === "string" && list.includes(locales.default) ? locales.default : void 0 };
4606
+ const locales = isRec2(settings.locales) ? settings.locales : {};
4607
+ const list2 = Array.isArray(locales.list) ? locales.list.filter((locale) => typeof locale === "string" && LOCALE_SEGMENT_RE.test(locale)) : [];
4608
+ return { list: list2, fallback: typeof locales.default === "string" && list2.includes(locales.default) ? locales.default : void 0 };
4609
+ }
4610
+ var localized2 = (path, locale) => locale === void 0 ? path : path === "/" ? `/${locale}` : `/${locale}${path}`;
4611
+ var LISTING_TEMPLATES = ["shop", "collection", "category", "tag"];
4612
+ var DEFAULT_TITLE = {
4613
+ product: "{product.title} \u2013 {store}",
4614
+ shop: "{listing.title} \u2013 {store}",
4615
+ collection: "{listing.title} \u2013 {store}",
4616
+ category: "{listing.title} \u2013 {store}",
4617
+ tag: "{listing.title} \u2013 {store}"
4618
+ };
4619
+ var titleOf = (value) => isRec2(value) ? text(value.title) ?? "" : "";
4620
+ function localizedOf(value) {
4621
+ if (typeof value === "string") return text(value);
4622
+ if (!isRec2(value)) return void 0;
4623
+ return text(value.en) ?? Object.values(value).map(text).find((entry) => entry !== void 0);
4624
+ }
4625
+ function templateMetadataOf(name, input) {
4626
+ const { settings, context } = input;
4627
+ const site = isRec2(settings.seo) ? settings.seo : {};
4628
+ const brand = isRec2(settings.brand) ? settings.brand : {};
4629
+ const store = text(brand.storeName) ?? "";
4630
+ const query = context?.route?.query?.q;
4631
+ const tokens = {
4632
+ "{product.title}": titleOf(context?.product),
4633
+ "{listing.title}": titleOf(context?.listing),
4634
+ "{query}": (Array.isArray(query) ? query[0] : query) ?? "",
4635
+ "{store}": store
4636
+ };
4637
+ const pattern = text(input.meta?.seo?.titleTemplate) ?? DEFAULT_TITLE[name] ?? "{store}";
4638
+ let title = pattern;
4639
+ for (const [token, value] of Object.entries(tokens)) title = title.replaceAll(token, () => value);
4640
+ title = title.replace(/^[\s–—|·:-]+|[\s–—|·:-]+$/gu, "");
4641
+ if (title === "") title = store;
4642
+ const description = localizedOf(input.meta?.seo?.description) ?? localizedOf(site.defaultDescription);
4643
+ const mediaOrigin = input.mediaOrigin ?? "";
4644
+ const image = imageOf(input.meta?.seo?.shareImage, mediaOrigin) ?? imageOf(site.shareImage, mediaOrigin);
4645
+ const noindex = input.noindex === true || name === "search" || (input.meta?.noindex ?? TEMPLATE_NOINDEX_DEFAULT[name]) || site.noindex === true;
4646
+ const origin = originOf(text(site.canonicalBase)) ?? originOf(input.storeUrl);
4647
+ const kind = name === "product" ? "product" : name === "search" ? "search" : LISTING_TEMPLATES.includes(name) ? "listing" : "page";
4648
+ const canonical = noindex || origin === void 0 ? void 0 : canonicalFor(`${origin}${input.path}${input.search ?? ""}`, kind);
4649
+ return {
4650
+ title,
4651
+ ...description === void 0 ? {} : { description },
4652
+ ...noindex ? { robots: name === "search" ? { index: false, follow: true } : { index: false } } : {},
4653
+ ...canonical === void 0 ? {} : { alternates: { canonical } },
4654
+ openGraph: {
4655
+ type: "website",
4656
+ ...store === "" ? {} : { siteName: store },
4657
+ title,
4658
+ ...description === void 0 ? {} : { description },
4659
+ ...image === void 0 ? {} : { images: [image] }
4660
+ },
4661
+ twitter: {
4662
+ card: image === void 0 ? "summary" : "summary_large_image",
4663
+ title,
4664
+ ...description === void 0 ? {} : { description },
4665
+ ...image === void 0 ? {} : { images: [image.url] }
4666
+ }
4667
+ };
2956
4668
  }
2957
- var localized = (path, locale) => locale === void 0 ? path : path === "/" ? `/${locale}` : `/${locale}${path}`;
2958
4669
  function metadataOf(page, context) {
2959
4670
  const { settings, mediaOrigin, routeLocale } = context;
2960
- const site = isRec(settings.seo) ? settings.seo : {};
2961
- const brand = isRec(settings.brand) ? settings.brand : {};
4671
+ const site = isRec2(settings.seo) ? settings.seo : {};
4672
+ const brand = isRec2(settings.brand) ? settings.brand : {};
2962
4673
  const own = pageSeoOf(page);
2963
4674
  const template = text(site.titleTemplate) ?? "{page}";
2964
4675
  const store = text(brand.storeName) ?? "";
2965
4676
  const title = template.replaceAll("{page}", () => own.title ?? page.title).replaceAll("{store}", () => store);
2966
4677
  const description = own.description ?? text(site.defaultDescription);
2967
4678
  const image = imageOf(own.shareImage, mediaOrigin) ?? imageOf(site.shareImage, mediaOrigin);
2968
- if (image === void 0 && mediaOrigin === "" && (isRec(own.shareImage) || isRec(site.shareImage)))
4679
+ if (image === void 0 && mediaOrigin === "" && (isRec2(own.shareImage) || isRec2(site.shareImage)))
2969
4680
  warnOnce("share-image-origin", "A share image is set but createBuilderPage has no mediaOrigin, so the page has no og:image: pass the same mediaOrigin as loadSite");
2970
- const origin = originOf(context.storeUrl);
4681
+ const origin = originOf(text(site.canonicalBase)) ?? originOf(context.storeUrl);
2971
4682
  if (origin === void 0)
2972
4683
  warnOnce("canonical-origin", "No canonical link: pass storeUrl (https://shop.example.com) to createBuilderPage. The Builder does not publish the store URL.");
2973
- const path = pagePathOf(settings, { slug: page.slug, pageType: page.pageType }, context.pagePath);
2974
- const canonical = origin === void 0 || path === null ? void 0 : `${origin}${localized(path, routeLocale)}`;
2975
- const { list, fallback } = siteLocales(settings);
2976
- const languages = origin !== void 0 && path !== null && routeLocale !== void 0 && list.length > 1 ? {
2977
- ...Object.fromEntries(list.map((locale) => [locale, `${origin}${localized(path, locale)}`])),
2978
- ...fallback === void 0 ? {} : { "x-default": `${origin}${localized(path, fallback)}` }
4684
+ const path = pagePathOf(settings, { slug: page.slug, pageType: page.pageType, path: text(page.path) }, context.pagePath);
4685
+ const override = canonicalOverrideOf(own.canonical);
4686
+ const canonical = override ?? (origin === void 0 || path === null ? void 0 : `${origin}${localized2(path, routeLocale)}`);
4687
+ const { list: list2, fallback } = siteLocales(settings);
4688
+ const languages = origin !== void 0 && path !== null && routeLocale !== void 0 && list2.length > 1 ? {
4689
+ ...Object.fromEntries(list2.map((locale) => [locale, `${origin}${localized2(path, locale)}`])),
4690
+ ...fallback === void 0 ? {} : { "x-default": `${origin}${localized2(path, fallback)}` }
2979
4691
  } : void 0;
2980
4692
  return {
2981
4693
  title,
2982
4694
  ...description === void 0 ? {} : { description },
2983
- ...own.noindex ? { robots: { index: false } } : {},
4695
+ // Site-wide noindex (v2 `seo.noindex`, for staging) is on every page, as the page's own is.
4696
+ ...own.noindex || site.noindex === true ? { robots: { index: false } } : {},
2984
4697
  ...canonical === void 0 ? {} : { alternates: { canonical, ...languages === void 0 ? {} : { languages } } },
2985
4698
  openGraph: {
2986
4699
  type: "website",
4700
+ ...store === "" ? {} : { siteName: store },
2987
4701
  title,
2988
4702
  ...description === void 0 ? {} : { description },
2989
4703
  ...canonical === void 0 ? {} : { url: canonical },
@@ -2999,18 +4713,33 @@ function metadataOf(page, context) {
2999
4713
  }
3000
4714
 
3001
4715
  export {
4716
+ __publicField,
3002
4717
  warnOnce,
4718
+ buildRouteTable,
4719
+ organizationJsonLd,
4720
+ webSiteJsonLd,
4721
+ breadcrumbJsonLd,
4722
+ faqJsonLd,
4723
+ localBusinessJsonLd,
4724
+ jsonLdString,
3003
4725
  createRendererRegistry,
3004
4726
  staticDataFor,
3005
4727
  partOf,
3006
4728
  isRedirect,
3007
4729
  getBundle,
3008
4730
  clientOf,
4731
+ isOwnPath,
4732
+ loadBuilderPageByPath,
4733
+ loadOwnPagePaths,
3009
4734
  loadBuilderPage,
4735
+ templateRootOf,
4736
+ loadBuilderTemplate,
3010
4737
  pageSeoOf,
4738
+ canonicalFor,
3011
4739
  pagePathOf,
3012
4740
  originOf,
3013
4741
  siteLocales,
3014
- localized,
4742
+ localized2 as localized,
4743
+ templateMetadataOf,
3015
4744
  metadataOf
3016
4745
  };