@usethrottle/builder-react 0.4.3 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -4,14 +4,15 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
4
4
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
5
 
6
6
  // src/renderer.tsx
7
- import { Fragment as Fragment3 } from "react";
7
+ import { Fragment as Fragment5 } from "react";
8
8
  import {
9
9
  ANCHOR_RE as ANCHOR_RE3,
10
10
  COMMON_WIDGET_SETTINGS as COMMON_WIDGET_SETTINGS2,
11
+ SITE_STRING_DEFAULTS,
11
12
  resolveEntrance,
12
13
  resolveInteraction,
13
14
  codeWidgetSnapshotSchema,
14
- resolveResponsive as resolveResponsive2,
15
+ resolveResponsive as resolveResponsive3,
15
16
  safeUrl as safeUrl3,
16
17
  upgradeNodes,
17
18
  validateSettingValue as validateSettingValue2,
@@ -164,7 +165,7 @@ function attrAllowed(tag, name) {
164
165
  return (ALLOWED_ATTRS["*"]?.includes(name) ?? false) || (own?.includes(name) ?? false);
165
166
  }
166
167
  function attrText(attr, env, scope) {
167
- return attr.value.map((part) => part.type === "text" ? part.value : filtered(lookup(part.path, env, scope), part.filters)).join("");
168
+ return attr.value.map((part2) => part2.type === "text" ? part2.value : filtered(lookup(part2.path, env, scope), part2.filters)).join("");
168
169
  }
169
170
  function urlSource(attr, env, scope) {
170
171
  const [only] = attr.value;
@@ -239,11 +240,11 @@ function renderNodes(nodes, env, scope, depth) {
239
240
  }
240
241
  break;
241
242
  case "each": {
242
- const list = lookup(node.path, env, scope);
243
- if (!Array.isArray(list)) break;
244
- const count = Math.min(list.length, EACH_ITERATION_CAP);
243
+ const list2 = lookup(node.path, env, scope);
244
+ if (!Array.isArray(list2)) break;
245
+ const count = Math.min(list2.length, EACH_ITERATION_CAP);
245
246
  for (let i = 0; i < count && !env.stopped; i += 1) {
246
- const inner = new Map(scope).set(node.as, list[i]);
247
+ const inner = new Map(scope).set(node.as, list2[i]);
247
248
  out.push(/* @__PURE__ */ jsx3(Fragment, { children: renderNodes(node.body, env, inner, depth + 1) }, out.length));
248
249
  }
249
250
  break;
@@ -269,7 +270,7 @@ import { Component } from "react";
269
270
  // src/context.ts
270
271
  import { createContext, useContext } from "react";
271
272
  function codeRenderOf(builder, runtime) {
272
- return { runtime, pathname: builder.pathname, routes: builder.codeRoutes, preview: builder.mode === "preview" };
273
+ return { runtime, pathname: builder.pathname, routes: builder.codeRoutes, templateName: builder.templateName, preview: builder.mode === "preview" };
273
274
  }
274
275
  var BuilderContext = typeof createContext === "function" ? createContext(null) : null;
275
276
  var useBuilder = () => useContext(BuilderContext);
@@ -278,7 +279,7 @@ var useBuilder = () => useContext(BuilderContext);
278
279
  import { ANCHOR_RE as ANCHOR_RE2, anyCustomWidgetSnapshotSchema, sectionNodeSchema, walkNodes } from "@usethrottle/builder-schema";
279
280
 
280
281
  // src/node-wrapper.tsx
281
- import { ANCHOR_RE } from "@usethrottle/builder-schema";
282
+ import { ANCHOR_RE, cssClassSchema } from "@usethrottle/builder-schema";
282
283
  import { jsx as jsx4 } from "react/jsx-runtime";
283
284
  var CUSTOM_WIDGET_CONTAINMENT = {
284
285
  contain: "layout paint",
@@ -291,12 +292,14 @@ var PART_NAME = {
291
292
  widget: "builder-widget"
292
293
  };
293
294
  function NodeWrapper(props) {
294
- const { id, part, type, className, anchor, copyAnchor, custom, missing, attributes, edit, entrance, children } = props;
295
+ const { id, part: part2, type, anchor, copyAnchor, custom, missing, attributes, edit, entrance, children } = props;
295
296
  const Tag = props.as ?? "div";
297
+ const tokens = props.cssClass !== void 0 && cssClassSchema.safeParse(props.cssClass).success ? props.cssClass : [];
298
+ const className = tokens.length === 0 ? props.className : `${props.className} ${tokens.join(" ")}`;
296
299
  const handlers = edit === void 0 ? {} : {
297
300
  onClickCapture: (event) => {
298
- const target = event.target;
299
- if (target?.closest?.("a[href]") != null) event.preventDefault();
301
+ const target2 = event.target;
302
+ if (target2?.closest?.("a[href]") != null) event.preventDefault();
300
303
  },
301
304
  onClick: (event) => {
302
305
  event.stopPropagation();
@@ -317,7 +320,7 @@ function NodeWrapper(props) {
317
320
  {
318
321
  className,
319
322
  "data-b-id": id,
320
- "data-throttle-part": PART_NAME[part],
323
+ "data-throttle-part": PART_NAME[part2],
321
324
  ...type === void 0 ? {} : { "data-b-type": type },
322
325
  ...custom === true && type !== void 0 ? { "data-b-w": type } : {},
323
326
  ...missing === true ? { "data-b-missing": "" } : {},
@@ -573,32 +576,32 @@ function contextData(context) {
573
576
  if (typeof context !== "object" || context === null) return {};
574
577
  return Object.fromEntries(Object.entries(context).map(([key, value]) => [`context.${key}`, value]));
575
578
  }
576
- function PartView({ part, context }) {
579
+ function PartView({ part: part2, context }) {
577
580
  const builder = useBuilder();
578
581
  if (builder === null) return null;
579
- return /* @__PURE__ */ jsx6(PartBody, { part, context, builder });
582
+ return /* @__PURE__ */ jsx6(PartBody, { part: part2, context, builder });
580
583
  }
581
584
  function PartBody({
582
- part,
585
+ part: part2,
583
586
  context,
584
587
  builder
585
588
  }) {
586
- const expanded = expandSavedSections(part.document, part.savedSections).doc;
589
+ const expanded = expandSavedSections(part2.document, part2.savedSections).doc;
587
590
  const shopper = useResolvedData(expanded, builder.registry, builder.locale, "shopper", context);
588
591
  return /* @__PURE__ */ jsx6(
589
592
  BuilderRenderer,
590
593
  {
591
- document: part.document,
594
+ document: part2.document,
592
595
  registry: builder.registry,
593
- data: { ...part.initialData, ...contextData(context), ...shopper },
596
+ data: { ...part2.initialData, ...contextData(context), ...shopper },
594
597
  locale: builder.locale,
595
- assets: part.assets,
598
+ assets: part2.assets,
596
599
  mediaOrigin: builder.mediaOrigin,
597
600
  resolveLink: builder.resolveLink,
598
601
  interactive: builder.interactive,
599
602
  scopeCustomCss: builder.customCss !== "",
600
- savedSections: part.savedSections,
601
- code: codeRenderOf(builder, part.code)
603
+ savedSections: part2.savedSections,
604
+ code: codeRenderOf(builder, part2.code)
602
605
  }
603
606
  );
604
607
  }
@@ -663,6 +666,7 @@ function reloadHere() {
663
666
  }
664
667
 
665
668
  // src/code/routes.ts
669
+ import { CODE_TEMPLATE_DENY } from "@usethrottle/builder-schema";
666
670
  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;
667
671
  var DEFAULT_CATALOG_ROUTES = [
668
672
  "/p/{handle}",
@@ -709,7 +713,7 @@ function matcherOf(template) {
709
713
  if (known !== void 0) return known;
710
714
  let regex = null;
711
715
  if (template.startsWith("/")) {
712
- 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(/\/+$/, "");
716
+ 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(/\/+$/, "");
713
717
  regex = new RegExp(`^${pattern === "" ? "/" : pattern}$`);
714
718
  }
715
719
  if (compiled2.size >= MAX_COMPILED) compiled2.clear();
@@ -717,24 +721,43 @@ function matcherOf(template) {
717
721
  return regex;
718
722
  }
719
723
  var matchesTemplate = (path, template) => matcherOf(template)?.test(path) ?? false;
724
+ function buildRouteTable(store, catalog = {}) {
725
+ return { ...catalog, ...store };
726
+ }
727
+ var isDeniedTemplate = (name) => CODE_TEMPLATE_DENY.includes(name);
728
+ function isDeniedByRouteTable(path, routeTable) {
729
+ if (routeTable === void 0) return false;
730
+ return Object.entries(routeTable).some(([name, template]) => {
731
+ if (!isDeniedTemplate(name) || typeof template !== "string") return false;
732
+ const base = template.replace(/\/+$/, "");
733
+ return matchesTemplate(path, template) || path.startsWith(`${base}/`);
734
+ });
735
+ }
720
736
  function isCodeRoute(pathname, routes) {
721
737
  if (pathname === void 0) return false;
738
+ if (routes.templateName !== void 0 && isDeniedTemplate(routes.templateName)) return false;
722
739
  const path = normalizePath(pathname);
723
740
  if (path === null) return false;
741
+ if (isDeniedByRouteTable(path, routes.routeTable)) return false;
724
742
  if (path.split("/").some((segment) => CODE_ROUTE_DENY.test(segment))) return false;
725
743
  if (path === "/") return true;
726
- return [routes.page, ...routes.catalog ?? DEFAULT_CATALOG_ROUTES].some(
744
+ return [routes.page, ...routes.catalog ?? DEFAULT_CATALOG_ROUTES, ...routes.allow ?? []].some(
727
745
  (template) => matchesTemplate(path, template)
728
746
  );
729
747
  }
730
748
 
731
749
  // src/code/leave.ts
750
+ var ownPages = /* @__PURE__ */ new Set();
751
+ function allowCodePath(path) {
752
+ if (typeof window !== "undefined") ownPages.add(path);
753
+ }
732
754
  var emitted = false;
733
755
  function markCodeEmitted() {
734
756
  emitted = true;
735
757
  }
736
758
  function mustLeave(pathname, routes) {
737
- return emitted && typeof window !== "undefined" && pathname !== void 0 && !isCodeRoute(pathname, routes);
759
+ if (!emitted || typeof window === "undefined" || pathname === void 0) return false;
760
+ return !isCodeRoute(pathname, ownPages.size === 0 ? routes : { ...routes, allow: [...routes.allow ?? [], ...ownPages] });
738
761
  }
739
762
  function useLeaveCodeRoutes(pathname, routes) {
740
763
  useEffect2(() => {
@@ -814,7 +837,7 @@ var BADGE = {
814
837
  function runs(props, jsHash) {
815
838
  const { code, edit, interactive } = props;
816
839
  if (edit !== void 0 || interactive === false || code === void 0 || code.preview === true) return null;
817
- if (!isCodeRoute(code.pathname, code.routes)) return null;
840
+ if (!isCodeRoute(code.pathname, { ...code.routes, templateName: code.templateName })) return null;
818
841
  return codeScriptUrl(code.runtime, jsHash);
819
842
  }
820
843
  function CodeWidget(props) {
@@ -1200,8 +1223,8 @@ var seen2 = /* @__PURE__ */ new WeakSet();
1200
1223
  var autoplay = /* @__PURE__ */ new Map();
1201
1224
  var all = (selector) => Array.from(document.querySelectorAll(selector));
1202
1225
  var reduced = () => window.matchMedia?.("(prefers-reduced-motion: reduce)").matches === true;
1203
- function selectTab(list, index, focus = false) {
1204
- const tabs = Array.from(list.querySelectorAll("[role=tab]"));
1226
+ function selectTab(list2, index, focus = false) {
1227
+ const tabs = Array.from(list2.querySelectorAll("[role=tab]"));
1205
1228
  tabs.forEach((tab, i) => {
1206
1229
  const on = i === index;
1207
1230
  tab.setAttribute("aria-selected", String(on));
@@ -1275,7 +1298,7 @@ function scan() {
1275
1298
  });
1276
1299
  document.documentElement.setAttribute("data-b-js", "");
1277
1300
  const fresh = (selector) => all(selector).filter((el) => !seen2.has(el) && seen2.add(el));
1278
- fresh("[data-b-tabs]").forEach((list) => selectTab(list, 0));
1301
+ fresh("[data-b-tabs]").forEach((list2) => selectTab(list2, 0));
1279
1302
  fresh("[data-b-car]").forEach((root) => setupCarousel(root));
1280
1303
  const counts = fresh("[data-b-cd]");
1281
1304
  counts.forEach((el) => tick(el, true));
@@ -1309,30 +1332,30 @@ var decoded = (hash) => {
1309
1332
  };
1310
1333
  var onHash = () => void goAnchor(decoded(location.hash));
1311
1334
  function onClick(event) {
1312
- const target = event.target;
1313
- const href = target?.closest('a[href^="#"]')?.getAttribute("href");
1335
+ const target2 = event.target;
1336
+ const href = target2?.closest('a[href^="#"]')?.getAttribute("href");
1314
1337
  if (href && !event.defaultPrevented && !event.button && !(event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) && goAnchor(decoded(href))) {
1315
1338
  event.preventDefault();
1316
1339
  history.pushState(null, "", href);
1317
1340
  }
1318
- const tab = target?.closest("[role=tab]");
1319
- const list = tab?.closest("[data-b-tabs]");
1320
- if (tab && list) return selectTab(list, Array.from(list.querySelectorAll("[role=tab]")).indexOf(tab));
1321
- const button = target?.closest("[data-b-act]");
1341
+ const tab = target2?.closest("[role=tab]");
1342
+ const list2 = tab?.closest("[data-b-tabs]");
1343
+ if (tab && list2) return selectTab(list2, Array.from(list2.querySelectorAll("[role=tab]")).indexOf(tab));
1344
+ const button = target2?.closest("[data-b-act]");
1322
1345
  const act = button?.getAttribute("data-b-act");
1323
1346
  const root = button?.closest("[data-b-car]");
1324
1347
  if (root && (act === "prev" || act === "next")) slideTo(root, act === "next" ? 1 : -1);
1325
1348
  }
1326
1349
  function onKey(event) {
1327
1350
  const tab = event.target?.closest("[role=tab]");
1328
- const list = tab?.closest("[data-b-tabs]");
1329
- if (!tab || !list) return;
1330
- const count = list.querySelectorAll("[role=tab]").length;
1331
- const at = Array.from(list.querySelectorAll("[role=tab]")).indexOf(tab);
1351
+ const list2 = tab?.closest("[data-b-tabs]");
1352
+ if (!tab || !list2) return;
1353
+ const count = list2.querySelectorAll("[role=tab]").length;
1354
+ const at = Array.from(list2.querySelectorAll("[role=tab]")).indexOf(tab);
1332
1355
  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;
1333
1356
  if (to < 0) return;
1334
1357
  event.preventDefault();
1335
- selectTab(list, to, true);
1358
+ selectTab(list2, to, true);
1336
1359
  }
1337
1360
  function startRuntime() {
1338
1361
  if (typeof document === "undefined") return () => void 0;
@@ -1387,11 +1410,150 @@ function InteractionRuntime() {
1387
1410
  return /* @__PURE__ */ jsx11("style", { href: "tb-interactions", precedence: "throttle", children: INTERACTIONS_CSS });
1388
1411
  }
1389
1412
 
1413
+ // src/interactions/frame.tsx
1414
+ import { useEffect as useEffect4 } from "react";
1415
+
1416
+ // src/interactions/focus-trap.ts
1417
+ var FOCUSABLE = 'a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])';
1418
+ var focusablesOf = (root) => Array.from(root.querySelectorAll(FOCUSABLE));
1419
+ function trapTab(event, items) {
1420
+ if (event.key !== "Tab") return false;
1421
+ const first = items[0];
1422
+ const last = items[items.length - 1];
1423
+ if (first === void 0 || last === void 0) return false;
1424
+ const active = document.activeElement;
1425
+ const inside = active !== null && items.includes(active);
1426
+ if (event.shiftKey && (active === first || !inside)) {
1427
+ event.preventDefault();
1428
+ last.focus();
1429
+ return true;
1430
+ }
1431
+ if (!event.shiftKey && (active === last || !inside)) {
1432
+ event.preventDefault();
1433
+ first.focus();
1434
+ return true;
1435
+ }
1436
+ return false;
1437
+ }
1438
+
1439
+ // src/interactions/drawer.ts
1440
+ var holds2 = 0;
1441
+ var release;
1442
+ var rootOf = (el) => el?.closest("[data-tb-collapse]") ?? null;
1443
+ function setOpen(root, open) {
1444
+ const opener = root.querySelector("[data-tb-drawer-open]");
1445
+ const body = root.querySelector(".tb-fr-body");
1446
+ if (open) root.setAttribute("data-open", "true");
1447
+ else root.removeAttribute("data-open");
1448
+ opener?.setAttribute("aria-expanded", String(open));
1449
+ if (body !== null) {
1450
+ if (open) {
1451
+ body.setAttribute("role", "dialog");
1452
+ body.setAttribute("aria-modal", "true");
1453
+ const name = opener?.textContent?.trim();
1454
+ if (name !== void 0 && name !== "") body.setAttribute("aria-label", name);
1455
+ } else {
1456
+ body.removeAttribute("role");
1457
+ body.removeAttribute("aria-modal");
1458
+ body.removeAttribute("aria-label");
1459
+ }
1460
+ }
1461
+ if (open) root.querySelector("[data-tb-drawer-close]")?.focus();
1462
+ else opener?.focus();
1463
+ }
1464
+ var openRoot = () => document.querySelector("[data-tb-collapse][data-open=true]");
1465
+ function install() {
1466
+ const click = (event) => {
1467
+ const el = event.target instanceof Element ? event.target : null;
1468
+ if (el === null) return;
1469
+ const root = rootOf(el);
1470
+ if (root === null) return;
1471
+ if (el.closest("[data-tb-drawer-open]") !== null) setOpen(root, root.getAttribute("data-open") !== "true");
1472
+ else if (el.closest("[data-tb-drawer-close]") !== null) setOpen(root, false);
1473
+ else if (root.getAttribute("data-open") === "true" && el.closest(".tb-fr-body a[href]") !== null) setOpen(root, false);
1474
+ };
1475
+ const keydown = (event) => {
1476
+ const root = openRoot();
1477
+ if (root === null) return;
1478
+ if (event.key === "Escape") {
1479
+ setOpen(root, false);
1480
+ return;
1481
+ }
1482
+ const body = root.querySelector(".tb-fr-body");
1483
+ if (body !== null) trapTab(event, focusablesOf(body));
1484
+ };
1485
+ document.addEventListener("click", click);
1486
+ document.addEventListener("keydown", keydown);
1487
+ return () => {
1488
+ document.removeEventListener("click", click);
1489
+ document.removeEventListener("keydown", keydown);
1490
+ };
1491
+ }
1492
+ function startDrawer() {
1493
+ if (holds2++ === 0) release = install();
1494
+ let done = false;
1495
+ return () => {
1496
+ if (done) return;
1497
+ done = true;
1498
+ if (--holds2 === 0) {
1499
+ release?.();
1500
+ release = void 0;
1501
+ }
1502
+ };
1503
+ }
1504
+
1505
+ // src/interactions/frame.tsx
1506
+ import { Fragment as Fragment3, jsx as jsx12, jsxs as jsxs5 } from "react/jsx-runtime";
1507
+ var SECTION_ID_RE = /^[A-Za-z0-9_-]{1,64}$/;
1508
+ var TABLET_PX = 1024;
1509
+ var PHONE_PX = 768;
1510
+ var isRecord2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
1511
+ function frameOf(section) {
1512
+ const raw = section.frame;
1513
+ if (!isRecord2(raw)) return null;
1514
+ const sticky = raw.sticky === "top";
1515
+ const c = raw.collapse;
1516
+ let collapse = null;
1517
+ if (isRecord2(c) && SECTION_ID_RE.test(section.id)) {
1518
+ 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;
1519
+ if (at !== null) collapse = { px: (at - 0.02).toFixed(2), label: isRecord2(c.label) ? c.label : {} };
1520
+ }
1521
+ return sticky || collapse !== null ? { sticky, collapse } : null;
1522
+ }
1523
+ var FRAME_CSS = `@layer throttle{
1524
+ .tb-sticky{position:sticky;inset-block-start:0;z-index:40}
1525
+ [data-throttle-part=builder-header]:has(.tb-sticky){position:sticky;inset-block-start:0;z-index:40}
1526
+ .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}
1527
+ .tb-fr-open:focus-visible,.tb-fr-close:focus-visible{outline:2px solid var(--tb-color-primary,currentColor);outline-offset:2px}
1528
+ }`;
1529
+ function collapseCss(sectionId, px2) {
1530
+ const s = `[data-b-id="${sectionId}"]`;
1531
+ 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}}}}`;
1532
+ }
1533
+ function DrawerRuntime() {
1534
+ useEffect4(() => startDrawer(), []);
1535
+ return null;
1536
+ }
1537
+ function Collapse(props) {
1538
+ const { sectionId, id, px: px2, label, children } = props;
1539
+ return /* @__PURE__ */ jsxs5(Fragment3, { children: [
1540
+ /* @__PURE__ */ jsx12("style", { href: `tb-fr-${sectionId}`, precedence: "throttle", children: collapseCss(sectionId, px2) }),
1541
+ /* @__PURE__ */ jsxs5("div", { className: "tb-fr", "data-tb-collapse": "", children: [
1542
+ /* @__PURE__ */ jsx12("button", { type: "button", className: "tb-fr-open", "data-tb-drawer-open": "", "aria-expanded": "false", "aria-controls": id, children: label }),
1543
+ /* @__PURE__ */ jsxs5("div", { id, className: "tb-fr-body", children: [
1544
+ /* @__PURE__ */ jsx12("button", { type: "button", className: "tb-fr-close", "data-tb-drawer-close": "", "aria-label": "Close", children: /* @__PURE__ */ jsx12("span", { "aria-hidden": "true", children: "\xD7" }) }),
1545
+ children
1546
+ ] }),
1547
+ /* @__PURE__ */ jsx12(DrawerRuntime, {})
1548
+ ] })
1549
+ ] });
1550
+ }
1551
+
1390
1552
  // src/interactions/tabs.tsx
1391
- import { jsx as jsx12, jsxs as jsxs5 } from "react/jsx-runtime";
1553
+ import { jsx as jsx13, jsxs as jsxs6 } from "react/jsx-runtime";
1392
1554
  function Tabs({ id, panels }) {
1393
- return /* @__PURE__ */ jsxs5("div", { className: "tb-tabs", children: [
1394
- /* @__PURE__ */ jsx12("div", { role: "tablist", className: "tb-tablist", "data-b-tabs": "", children: panels.map((panel, i) => /* @__PURE__ */ jsx12(
1555
+ return /* @__PURE__ */ jsxs6("div", { className: "tb-tabs", children: [
1556
+ /* @__PURE__ */ jsx13("div", { role: "tablist", className: "tb-tablist", "data-b-tabs": "", children: panels.map((panel, i) => /* @__PURE__ */ jsx13(
1395
1557
  "button",
1396
1558
  {
1397
1559
  type: "button",
@@ -1405,7 +1567,7 @@ function Tabs({ id, panels }) {
1405
1567
  },
1406
1568
  panel.key
1407
1569
  )) }),
1408
- panels.map((panel, i) => /* @__PURE__ */ jsxs5(
1570
+ panels.map((panel, i) => /* @__PURE__ */ jsxs6(
1409
1571
  "div",
1410
1572
  {
1411
1573
  role: "tabpanel",
@@ -1414,7 +1576,7 @@ function Tabs({ id, panels }) {
1414
1576
  "aria-labelledby": `${id}-t${String(i)}`,
1415
1577
  tabIndex: 0,
1416
1578
  children: [
1417
- /* @__PURE__ */ jsx12("p", { className: "tb-panel-title", children: panel.title }),
1579
+ /* @__PURE__ */ jsx13("p", { className: "tb-panel-title", children: panel.title }),
1418
1580
  panel.node
1419
1581
  ]
1420
1582
  },
@@ -1424,19 +1586,101 @@ function Tabs({ id, panels }) {
1424
1586
  }
1425
1587
 
1426
1588
  // src/interactions/toggle.tsx
1427
- import { jsx as jsx13, jsxs as jsxs6 } from "react/jsx-runtime";
1589
+ import { jsx as jsx14, jsxs as jsxs7 } from "react/jsx-runtime";
1428
1590
  function Toggle({
1429
1591
  labelOpen,
1430
1592
  labelClosed,
1431
1593
  startOpen,
1432
1594
  children
1433
1595
  }) {
1434
- return /* @__PURE__ */ jsxs6("details", { className: "tb-toggle", ...startOpen ? { open: true } : {}, children: [
1435
- /* @__PURE__ */ jsxs6("summary", { className: "tb-toggle-sum", children: [
1436
- /* @__PURE__ */ jsx13("span", { className: "tb-toggle-closed", children: labelClosed }),
1437
- /* @__PURE__ */ jsx13("span", { className: "tb-toggle-open", children: labelOpen })
1596
+ return /* @__PURE__ */ jsxs7("details", { className: "tb-toggle", ...startOpen ? { open: true } : {}, children: [
1597
+ /* @__PURE__ */ jsxs7("summary", { className: "tb-toggle-sum", children: [
1598
+ /* @__PURE__ */ jsx14("span", { className: "tb-toggle-closed", children: labelClosed }),
1599
+ /* @__PURE__ */ jsx14("span", { className: "tb-toggle-open", children: labelOpen })
1438
1600
  ] }),
1439
- /* @__PURE__ */ jsx13("div", { className: "tb-row", children })
1601
+ /* @__PURE__ */ jsx14("div", { className: "tb-row", children })
1602
+ ] });
1603
+ }
1604
+
1605
+ // src/show-when.tsx
1606
+ import { useEffect as useEffect5, useState as useState2 } from "react";
1607
+ import { SPACING_TOKENS, resolveResponsive as resolveResponsive2, showWhenSchema } from "@usethrottle/builder-schema";
1608
+
1609
+ // src/viewer.ts
1610
+ import { createContext as createContext2, useContext as useContext2 } from "react";
1611
+ var ViewerContext = typeof createContext2 === "function" ? createContext2(void 0) : null;
1612
+ var useViewer = () => useContext2(ViewerContext);
1613
+
1614
+ // src/show-when.tsx
1615
+ import { Fragment as Fragment4, jsx as jsx15, jsxs as jsxs8 } from "react/jsx-runtime";
1616
+ function parseShowWhen(value) {
1617
+ if (value === void 0) return null;
1618
+ const parsed2 = showWhenSchema.safeParse(value);
1619
+ if (!parsed2.success) return null;
1620
+ return parsed2.data.audience === "all" && parsed2.data.cart === "any" ? null : parsed2.data;
1621
+ }
1622
+ function showWhenState(when, viewer, mounted) {
1623
+ if (!mounted) return when.audience === "signed-in" || when.cart === "has-items" ? "placeholder" : "show";
1624
+ const known = viewer === null ? { signedIn: null, cartItemCount: null } : viewer ?? { signedIn: false, cartItemCount: 0 };
1625
+ let pending = false;
1626
+ if (when.audience !== "all") {
1627
+ if (known.signedIn === null) pending = pending || when.audience === "signed-in";
1628
+ else if ((known.signedIn ? "signed-in" : "guest") !== when.audience) return "hide";
1629
+ }
1630
+ if (when.cart !== "any") {
1631
+ if (known.cartItemCount === null) pending = pending || when.cart === "has-items";
1632
+ else if ((known.cartItemCount > 0 ? "has-items" : "empty") !== when.cart) return "hide";
1633
+ }
1634
+ return pending ? "placeholder" : "show";
1635
+ }
1636
+ var DEVICES = ["desktop", "tablet", "phone"];
1637
+ var isRec = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
1638
+ var list = (v) => Array.isArray(v) ? v.filter(isRec) : [];
1639
+ function lengthOf(value) {
1640
+ if (typeof value === "number") return Number.isFinite(value) && value > 0 ? `${String(Math.min(Math.round(value), 2e3))}px` : null;
1641
+ if (typeof value === "string" && value !== "none" && SPACING_TOKENS.includes(value)) return `var(--tb-space-${value})`;
1642
+ return null;
1643
+ }
1644
+ function heightAt(node, device) {
1645
+ const resolved = resolveResponsive2(isRec(node.props) ? node.props : {}, node.responsive, device);
1646
+ if (resolved.hidden === true) return null;
1647
+ const own = lengthOf(resolved.minHeight) ?? lengthOf(resolved.height);
1648
+ if (own !== null) return own;
1649
+ const columns = list(node.columns).map((c) => heightAt(c, device)).filter((h) => h !== null);
1650
+ if (columns.length > 0) return columns.length === 1 ? columns[0] : `max(${columns.join(",")})`;
1651
+ const stacked = list(node.children).map((c) => heightAt(c, device)).filter((h) => h !== null);
1652
+ if (stacked.length > 0) return stacked.length === 1 ? stacked[0] : `calc(${stacked.join(" + ")})`;
1653
+ return null;
1654
+ }
1655
+ function reservedHeights(node) {
1656
+ const found = DEVICES.map((device) => [device, heightAt(node, device)]);
1657
+ if (found.every(([, h]) => h === null)) return {};
1658
+ return Object.fromEntries(found.map(([device, h]) => [device, h ?? "0px"]));
1659
+ }
1660
+ 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)))}}}";
1661
+ function ShowWhen({ when, heights, children }) {
1662
+ const viewer = useViewer();
1663
+ const [mounted, setMounted] = useState2(false);
1664
+ useEffect5(() => setMounted(true), []);
1665
+ const state = showWhenState(when, viewer, mounted);
1666
+ if (state === "show") return children;
1667
+ if (state === "hide") return null;
1668
+ const style = {
1669
+ ...heights.desktop === void 0 ? {} : { "--tb-sw-h": heights.desktop },
1670
+ ...heights.tablet === void 0 ? {} : { "--tb-sw-ht": heights.tablet },
1671
+ ...heights.phone === void 0 ? {} : { "--tb-sw-hp": heights.phone }
1672
+ };
1673
+ return /* @__PURE__ */ jsxs8(Fragment4, { children: [
1674
+ /* @__PURE__ */ jsx15("style", { href: "tb-showwhen", precedence: "throttle", children: SHOW_WHEN_CSS }),
1675
+ /* @__PURE__ */ jsx15(
1676
+ "div",
1677
+ {
1678
+ className: "tb-sw",
1679
+ "aria-hidden": "true",
1680
+ "data-b-showwhen": when.audience === "signed-in" ? "signed-in" : "has-items",
1681
+ ...Object.keys(style).length === 0 ? {} : { style }
1682
+ }
1683
+ )
1440
1684
  ] });
1441
1685
  }
1442
1686
 
@@ -1462,8 +1706,8 @@ var BASE_CSS = `@layer throttle{
1462
1706
  }`;
1463
1707
 
1464
1708
  // src/renderer.tsx
1465
- import { jsx as jsx14, jsxs as jsxs7 } from "react/jsx-runtime";
1466
- var DEVICES = ["desktop", "tablet", "phone"];
1709
+ import { jsx as jsx16, jsxs as jsxs9 } from "react/jsx-runtime";
1710
+ var DEVICES2 = ["desktop", "tablet", "phone"];
1467
1711
  var COMMON_BY_KEY2 = new Map(COMMON_WIDGET_SETTINGS2.map((f) => [f.key, f]));
1468
1712
  var withCustomCache = /* @__PURE__ */ new WeakMap();
1469
1713
  function registryFor(doc, base) {
@@ -1490,7 +1734,7 @@ function registryFor(doc, base) {
1490
1734
  }
1491
1735
  return registry;
1492
1736
  }
1493
- var isRecord2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
1737
+ var isRecord3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
1494
1738
  function pickLocale(value, locale) {
1495
1739
  const lang = locale.split("-")[0] ?? locale;
1496
1740
  for (const key of [locale, lang, "en"]) {
@@ -1504,22 +1748,33 @@ function onOrigin(asset, mediaOrigin) {
1504
1748
  if (safeUrl3(asset.url, "src", { mediaOrigin }) === null) return null;
1505
1749
  return { ...asset, variants: asset.variants.filter((v) => safeUrl3(v.url, "src", { mediaOrigin }) !== null) };
1506
1750
  }
1751
+ function prepareItem(field, item, ctx) {
1752
+ if (!isRecord3(item)) return item;
1753
+ const out = { ...item };
1754
+ for (const itemField of field.itemFields ?? []) {
1755
+ if (!Object.hasOwn(out, itemField.key)) continue;
1756
+ const prepared = prepare(itemField, out[itemField.key], ctx);
1757
+ out[itemField.key] = prepared;
1758
+ }
1759
+ return out;
1760
+ }
1507
1761
  function prepare(field, value, ctx) {
1508
1762
  if (field === void 0 || value === null) return value;
1509
- if (field.translatable === true && isRecord2(value)) return pickLocale(value, ctx.locale);
1763
+ if (field.control === "list" && Array.isArray(value)) return value.map((item) => prepareItem(field, item, ctx));
1764
+ if (field.translatable === true && isRecord3(value)) return pickLocale(value, ctx.locale);
1510
1765
  if (field.control === "image" && typeof value === "string") {
1511
1766
  const asset = Object.hasOwn(ctx.assets, value) ? ctx.assets[value] : void 0;
1512
1767
  return asset === void 0 ? null : onOrigin(asset, ctx.mediaOrigin);
1513
1768
  }
1514
- if (field.control === "link" && isRecord2(value) && typeof value.kind === "string") {
1515
- const target = value;
1516
- const raw = ctx.resolveLink?.(target) ?? (target.kind === "url" ? target.href : null);
1769
+ if (field.control === "link" && isRecord3(value) && typeof value.kind === "string") {
1770
+ const target2 = value;
1771
+ const raw = ctx.resolveLink?.(target2) ?? (target2.kind === "url" ? target2.href : null);
1517
1772
  return { ...value, href: safeUrl3(raw, "href", { mediaOrigin: ctx.mediaOrigin }) };
1518
1773
  }
1519
1774
  return value;
1520
1775
  }
1521
1776
  function storedLinkPart(value) {
1522
- if (!isRecord2(value) || value.kind !== "page") return value;
1777
+ if (!isRecord3(value) || value.kind !== "page") return value;
1523
1778
  const { slug: _slug, href: _href, ...stored } = value;
1524
1779
  void _slug;
1525
1780
  void _href;
@@ -1528,7 +1783,7 @@ function storedLinkPart(value) {
1528
1783
  function settingsAt(node, fields, device, ctx) {
1529
1784
  const base = {};
1530
1785
  for (const field of fields.values()) base[field.key] = field.default;
1531
- const resolved = resolveResponsive2({ ...base, ...node.props }, node.responsive, device);
1786
+ const resolved = resolveResponsive3({ ...base, ...node.props }, node.responsive, device);
1532
1787
  const out = {};
1533
1788
  for (const [key, value] of Object.entries(resolved)) {
1534
1789
  const field = fields.get(key);
@@ -1542,7 +1797,7 @@ function settingsAt(node, fields, device, ctx) {
1542
1797
  function variantsOf(node, def, fields, ctx) {
1543
1798
  const markup = [...fields.values()].filter((f) => f.output === "markup").map((f) => f.key);
1544
1799
  const groups = /* @__PURE__ */ new Map();
1545
- for (const device of DEVICES) {
1800
+ for (const device of DEVICES2) {
1546
1801
  const props = settingsAt(node, fields, device, ctx);
1547
1802
  const signature = stable(markup.map((key) => props[key] ?? null));
1548
1803
  const group = groups.get(signature);
@@ -1553,8 +1808,8 @@ function variantsOf(node, def, fields, ctx) {
1553
1808
  return [...groups.values()];
1554
1809
  }
1555
1810
  function hiddenEverywhere(props, responsive) {
1556
- return DEVICES.every(
1557
- (device) => resolveResponsive2({ hidden: props.hidden ?? false }, responsive, device).hidden === true
1811
+ return DEVICES2.every(
1812
+ (device) => resolveResponsive3({ hidden: props.hidden ?? false }, responsive, device).hidden === true
1558
1813
  );
1559
1814
  }
1560
1815
  var variantClass = (variant) => `tb-v ${variant.devices.map((d) => `tb-only-${d}`).join(" ")}`;
@@ -1570,7 +1825,7 @@ function renderCodeWidget(node, snapshot, ctx, registry) {
1570
1825
  }
1571
1826
  const props = settingsAt(node, fields, "desktop", ctx);
1572
1827
  const anchor = props.anchor;
1573
- return /* @__PURE__ */ jsx14(
1828
+ return /* @__PURE__ */ jsx16(
1574
1829
  CodeWidget,
1575
1830
  {
1576
1831
  node,
@@ -1599,7 +1854,7 @@ function renderWidget(node, ctx, registry) {
1599
1854
  if (isDevelopment()) {
1600
1855
  warnOnce(`missing:${node.type}@${String(node.v)}`, `Unknown widget ${node.type} v${String(node.v)}; rendering nothing for it`);
1601
1856
  }
1602
- return /* @__PURE__ */ jsx14(NodeWrapper, { id: node.id, part: "widget", type: node.type, className: "tb-w", missing: true, children: ctx.edit !== void 0 && /* @__PURE__ */ jsx14("div", { className: "tb-missing", children: "Widget unavailable: update @usethrottle/storefront-react" }) });
1857
+ return /* @__PURE__ */ jsx16(NodeWrapper, { id: node.id, part: "widget", type: node.type, className: "tb-w", missing: true, children: ctx.edit !== void 0 && /* @__PURE__ */ jsx16("div", { className: "tb-missing", children: "Widget unavailable: update @usethrottle/storefront-react" }) });
1603
1858
  }
1604
1859
  if (ctx.edit === void 0 && hiddenEverywhere(node.props, node.responsive)) return null;
1605
1860
  const fields = new Map([...COMMON_BY_KEY2, ...def.settings.map((f) => [f.key, f])]);
@@ -1612,21 +1867,22 @@ function renderWidget(node, ctx, registry) {
1612
1867
  }
1613
1868
  const custom = node.type.startsWith("custom.");
1614
1869
  const edit = ctx.edit;
1615
- return variants.map((variant, index) => {
1870
+ const copies = variants.map((variant, index) => {
1616
1871
  const anchor = variant.props.anchor;
1617
- return /* @__PURE__ */ jsx14(
1872
+ return /* @__PURE__ */ jsx16(
1618
1873
  NodeWrapper,
1619
1874
  {
1620
1875
  id: node.id,
1621
1876
  part: "widget",
1622
1877
  type: node.type,
1623
1878
  custom,
1879
+ cssClass: node.cssClass,
1624
1880
  edit,
1625
1881
  className: variants.length > 1 ? `tb-w ${variantClass(variant)}` : "tb-w",
1626
1882
  anchor: index === 0 && !ctx.dupe && typeof anchor === "string" && anchor !== "" ? anchor : void 0,
1627
1883
  copyAnchor: ctx.vpath !== "" && typeof anchor === "string" && anchor !== "" ? anchor : void 0,
1628
1884
  entrance: entranceOf(variant.props.entrance, variant.props.entranceDelayMs, ctx.interactive),
1629
- children: /* @__PURE__ */ jsx14(
1885
+ children: /* @__PURE__ */ jsx16(
1630
1886
  Component2,
1631
1887
  {
1632
1888
  node,
@@ -1646,15 +1902,23 @@ function renderWidget(node, ctx, registry) {
1646
1902
  variant.devices.join("-")
1647
1903
  );
1648
1904
  });
1905
+ return gated(node, ctx, copies);
1906
+ }
1907
+ function gated(node, ctx, content) {
1908
+ if (ctx.edit !== void 0) return content;
1909
+ const when = parseShowWhen(node.showWhen);
1910
+ if (when === null) return content;
1911
+ return /* @__PURE__ */ jsx16(ShowWhen, { when, heights: reservedHeights(node), children: content });
1649
1912
  }
1650
1913
  function renderColumn(column, ctx, registry) {
1651
1914
  if (ctx.edit === void 0 && hiddenEverywhere(column.props, column.responsive)) return null;
1652
- return /* @__PURE__ */ jsx14(
1915
+ const drawn = /* @__PURE__ */ jsx16(
1653
1916
  NodeWrapper,
1654
1917
  {
1655
1918
  id: column.id,
1656
1919
  part: "column",
1657
1920
  className: "tb-col",
1921
+ cssClass: column.cssClass,
1658
1922
  anchor: ctx.dupe ? void 0 : column.props.anchor,
1659
1923
  copyAnchor: ctx.vpath === "" ? void 0 : column.props.anchor,
1660
1924
  edit: ctx.edit,
@@ -1664,16 +1928,17 @@ function renderColumn(column, ctx, registry) {
1664
1928
  ctx.interactive
1665
1929
  ),
1666
1930
  children: column.children.map(
1667
- (child) => child.type === "inner-section" ? /* @__PURE__ */ jsx14(Fragment3, { children: renderSection(child, ctx, registry, true) }, child.id) : /* @__PURE__ */ jsx14(Fragment3, { children: renderWidget(child, ctx, registry) }, child.id)
1931
+ (child) => child.type === "inner-section" ? /* @__PURE__ */ jsx16(Fragment5, { children: renderSection(child, ctx, registry, true) }, child.id) : /* @__PURE__ */ jsx16(Fragment5, { children: renderWidget(child, ctx, registry) }, child.id)
1668
1932
  )
1669
1933
  },
1670
1934
  column.id
1671
1935
  );
1936
+ return gated(column, ctx, drawn);
1672
1937
  }
1673
1938
  var PLAIN = resolveInteraction({ props: {}, responsive: void 0 }, "desktop");
1674
1939
  function sectionVariants(section, ctx) {
1675
1940
  const groups = /* @__PURE__ */ new Map();
1676
- for (const device of DEVICES) {
1941
+ for (const device of DEVICES2) {
1677
1942
  const interaction = ctx.interactive ? resolveInteraction(section, device) : PLAIN;
1678
1943
  const entrance = ctx.interactive ? resolveEntrance(section, device) : { entrance: "none", entranceDelayMs: 0 };
1679
1944
  const signature = stable([interaction, entrance]);
@@ -1693,7 +1958,8 @@ function panelsOf(section, ctx, registry, fallback) {
1693
1958
  function renderSection(section, ctx, registry, nested = false) {
1694
1959
  if (ctx.edit === void 0 && hiddenEverywhere(section.props, section.responsive)) return null;
1695
1960
  const variants = sectionVariants(section, ctx);
1696
- const marker = variants.length > 1 && !ctx.dupe && section.props.anchor !== void 0 && ANCHOR_RE3.test(section.props.anchor) ? /* @__PURE__ */ jsx14("div", { id: section.props.anchor, className: "tb-anchor" }, "anchor") : null;
1961
+ const frame = nested || !ctx.interactive || ctx.edit !== void 0 ? null : frameOf(section);
1962
+ const marker = variants.length > 1 && !ctx.dupe && section.props.anchor !== void 0 && ANCHOR_RE3.test(section.props.anchor) ? /* @__PURE__ */ jsx16("div", { id: section.props.anchor, className: "tb-anchor" }, "anchor") : null;
1697
1963
  const copies = variants.map((variant, index) => {
1698
1964
  const { interaction } = variant;
1699
1965
  const id = `ix-${section.id}-${ctx.vpath}${String(index)}`;
@@ -1701,9 +1967,9 @@ function renderSection(section, ctx, registry, nested = false) {
1701
1967
  const columns = () => section.columns.map((column) => renderColumn(column, own, registry));
1702
1968
  let body;
1703
1969
  if (interaction.interaction === "tabs") {
1704
- body = /* @__PURE__ */ jsx14(Tabs, { id, panels: panelsOf(section, own, registry, (n) => `Tab ${String(n)}`) });
1970
+ body = /* @__PURE__ */ jsx16(Tabs, { id, panels: panelsOf(section, own, registry, (n) => `Tab ${String(n)}`) });
1705
1971
  } else if (interaction.interaction === "accordion") {
1706
- body = /* @__PURE__ */ jsx14(
1972
+ body = /* @__PURE__ */ jsx16(
1707
1973
  Accordion,
1708
1974
  {
1709
1975
  id,
@@ -1713,7 +1979,7 @@ function renderSection(section, ctx, registry, nested = false) {
1713
1979
  }
1714
1980
  );
1715
1981
  } else if (interaction.interaction === "carousel") {
1716
- body = /* @__PURE__ */ jsx14(
1982
+ body = /* @__PURE__ */ jsx16(
1717
1983
  Carousel,
1718
1984
  {
1719
1985
  panels: panelsOf(section, own, registry, () => ""),
@@ -1722,7 +1988,7 @@ function renderSection(section, ctx, registry, nested = false) {
1722
1988
  }
1723
1989
  );
1724
1990
  } else if (interaction.interaction === "toggle") {
1725
- body = /* @__PURE__ */ jsx14(
1991
+ body = /* @__PURE__ */ jsx16(
1726
1992
  Toggle,
1727
1993
  {
1728
1994
  labelOpen: pickLocale(interaction.toggleLabelOpen, ctx.locale),
@@ -1732,39 +1998,55 @@ function renderSection(section, ctx, registry, nested = false) {
1732
1998
  }
1733
1999
  );
1734
2000
  } else {
1735
- body = /* @__PURE__ */ jsx14("div", { className: "tb-row", children: columns() });
2001
+ body = /* @__PURE__ */ jsx16("div", { className: "tb-row", children: columns() });
2002
+ }
2003
+ if (frame?.collapse != null) {
2004
+ body = /* @__PURE__ */ jsx16(
2005
+ Collapse,
2006
+ {
2007
+ sectionId: section.id,
2008
+ id: `fr-${section.id}-${ctx.vpath}${String(index)}`,
2009
+ px: frame.collapse.px,
2010
+ label: pickLocale(frame.collapse.label, ctx.locale) || SITE_STRING_DEFAULTS["nav.menu"],
2011
+ children: body
2012
+ }
2013
+ );
1736
2014
  }
1737
- return /* @__PURE__ */ jsx14(
2015
+ return /* @__PURE__ */ jsxs9(
1738
2016
  NodeWrapper,
1739
2017
  {
1740
2018
  id: section.id,
1741
2019
  part: "section",
2020
+ cssClass: section.cssClass,
1742
2021
  as: nested ? "div" : "section",
1743
- className: `${nested ? "tb-section tb-nested" : "tb-section"}${variants.length > 1 ? ` ${variantClass({ devices: variant.devices, props: {} })}` : ""}`,
2022
+ className: `${nested ? "tb-section tb-nested" : "tb-section"}${frame?.sticky === true ? " tb-sticky" : ""}${variants.length > 1 ? ` ${variantClass({ devices: variant.devices, props: {} })}` : ""}`,
1744
2023
  anchor: variants.length === 1 && !ctx.dupe ? section.props.anchor : void 0,
1745
2024
  copyAnchor: variants.length > 1 || ctx.vpath !== "" ? section.props.anchor : void 0,
1746
2025
  edit: ctx.edit,
1747
2026
  entrance: entranceOf(variant.entrance.entrance, variant.entrance.entranceDelayMs, ctx.interactive),
1748
- children: /* @__PURE__ */ jsx14("div", { className: "tb-inner", children: body })
2027
+ children: [
2028
+ frame !== null ? /* @__PURE__ */ jsx16("style", { href: "tb-frame", precedence: "throttle", children: FRAME_CSS }) : null,
2029
+ /* @__PURE__ */ jsx16("div", { className: "tb-inner", children: body })
2030
+ ]
1749
2031
  },
1750
2032
  variant.devices.join("-")
1751
2033
  );
1752
2034
  });
1753
- return marker === null ? copies : [marker, ...copies];
2035
+ return gated(section, ctx, marker === null ? copies : [marker, ...copies]);
1754
2036
  }
1755
2037
  function needsRuntime(doc) {
1756
2038
  let found = false;
1757
2039
  walkNodes3(doc, (node) => {
1758
2040
  if (found || node.type === "saved-section") return;
1759
2041
  if (node.type === "section" || node.type === "inner-section") {
1760
- found = DEVICES.some(
2042
+ found = DEVICES2.some(
1761
2043
  (device) => resolveInteraction(node, device).interaction !== "none" || resolveEntrance(node, device).entrance !== "none"
1762
2044
  );
1763
2045
  } else if (node.type === "column") {
1764
- found = DEVICES.some((device) => resolveEntrance(node, device).entrance !== "none");
2046
+ found = DEVICES2.some((device) => resolveEntrance(node, device).entrance !== "none");
1765
2047
  } else {
1766
- found = DEVICES.some((device) => {
1767
- const entrance = resolveResponsive2(node.props, node.responsive, device).entrance;
2048
+ found = DEVICES2.some((device) => {
2049
+ const entrance = resolveResponsive3(node.props, node.responsive, device).entrance;
1768
2050
  return entrance !== void 0 && entrance !== "none";
1769
2051
  });
1770
2052
  }
@@ -1782,20 +2064,20 @@ function BuilderRenderer(props) {
1782
2064
  const ctx = { registry, data, locale, assets, mediaOrigin, resolveLink, code, edit: editMode, interactive, vpath: props.idScope?.vpath ?? "", dupe: props.idScope?.dupe ?? false, snapshots: source.customWidgets };
1783
2065
  const css = compileResponsiveCss(doc, registry, assets, mediaOrigin);
1784
2066
  const upgraded = new Map(doc.sections.map((section) => [section.id, section]));
1785
- return /* @__PURE__ */ jsxs7("div", { className: "tb-root", "data-throttle-part": "builder-root", ...props.scopeCustomCss === true ? { "data-b-root": "" } : {}, children: [
1786
- interactive && needsRuntime(doc) ? /* @__PURE__ */ jsx14(InteractionRuntime, {}) : null,
1787
- /* @__PURE__ */ jsx14("style", { href: "tb-base", precedence: "throttle", children: BASE_CSS }),
1788
- css === "" ? null : /* @__PURE__ */ jsx14("style", { children: css }),
2067
+ return /* @__PURE__ */ jsxs9("div", { className: "tb-root", "data-throttle-part": "builder-root", ...props.scopeCustomCss === true ? { "data-b-root": "" } : {}, children: [
2068
+ interactive && needsRuntime(doc) ? /* @__PURE__ */ jsx16(InteractionRuntime, {}) : null,
2069
+ /* @__PURE__ */ jsx16("style", { href: "tb-base", precedence: "throttle", children: BASE_CSS }),
2070
+ css === "" ? null : /* @__PURE__ */ jsx16("style", { children: css }),
1789
2071
  (expansion.roots ?? doc.sections.map((section) => ({ kind: "section", id: section.id }))).map((root) => {
1790
2072
  if (root.kind === "section") {
1791
2073
  const section2 = upgraded.get(root.id);
1792
- return section2?.type === "section" ? /* @__PURE__ */ jsx14(Fragment3, { children: renderSection(section2, ctx, registry) }, root.id) : null;
2074
+ return section2?.type === "section" ? /* @__PURE__ */ jsx16(Fragment5, { children: renderSection(section2, ctx, registry) }, root.id) : null;
1793
2075
  }
1794
2076
  const section = root.sectionId === null ? void 0 : upgraded.get(root.sectionId);
1795
2077
  if (section?.type === "section") {
1796
- return root.ref.props.hidden === true && ctx.edit === void 0 ? null : /* @__PURE__ */ jsx14(Fragment3, { children: renderSection(section, ctx, registry) }, root.ref.id);
2078
+ return root.ref.props.hidden === true && ctx.edit === void 0 ? null : /* @__PURE__ */ jsx16(Fragment5, { children: renderSection(section, ctx, registry) }, root.ref.id);
1797
2079
  }
1798
- return /* @__PURE__ */ jsx14(MissingSavedSection, { node: root.ref }, root.ref.id);
2080
+ return /* @__PURE__ */ jsx16(MissingSavedSection, { node: root.ref }, root.ref.id);
1799
2081
  })
1800
2082
  ] });
1801
2083
  }
@@ -1809,7 +2091,7 @@ function validateRender(doc) {
1809
2091
 
1810
2092
  // src/asset-image.tsx
1811
2093
  import { safeUrl as safeUrl4 } from "@usethrottle/builder-schema";
1812
- import { jsx as jsx15 } from "react/jsx-runtime";
2094
+ import { jsx as jsx17 } from "react/jsx-runtime";
1813
2095
  function isFrozenAsset(value) {
1814
2096
  if (typeof value !== "object" || value === null) return false;
1815
2097
  const v = value;
@@ -1825,7 +2107,7 @@ function AssetImage(props) {
1825
2107
  const url = href(variant.url);
1826
2108
  return url === null || url.includes(",") ? [] : [`${url} ${String(variant.width)}w`];
1827
2109
  }).join(", ");
1828
- return /* @__PURE__ */ jsx15(
2110
+ return /* @__PURE__ */ jsx17(
1829
2111
  "img",
1830
2112
  {
1831
2113
  src,
@@ -1842,20 +2124,20 @@ function AssetImage(props) {
1842
2124
  }
1843
2125
 
1844
2126
  // src/provider.tsx
1845
- import { Suspense as Suspense5, useCallback, useContext as useContext2, useMemo, useRef as useRef3 } from "react";
2127
+ import { Suspense as Suspense5, useCallback, useContext as useContext3, useMemo as useMemo2, useRef as useRef5 } from "react";
1846
2128
  import { createBuilderClient } from "@usethrottle/builder";
1847
2129
  import { AppearanceContext, SiteDesignProvider, SlotOutletProvider, ThrottleUIProvider, useAppearanceProviderValue } from "@usethrottle/ui";
1848
2130
 
1849
2131
  // src/page.tsx
1850
- import { useEffect as useEffect4 } from "react";
2132
+ import { useEffect as useEffect6 } from "react";
1851
2133
  import { BuilderUnavailableError } from "@usethrottle/builder";
1852
2134
 
1853
2135
  // src/load.ts
1854
2136
  function pageOf(raw, initialData) {
1855
- const { document: document2, id: _id, slug, title, path, generation, pageType: _type, updatedAt: _updated, savedSections, code, ...meta } = raw;
2137
+ const { document: document2, id: _id, slug: slug2, title, path, generation, pageType: _type, updatedAt: _updated, savedSections, code, ...meta } = raw;
1856
2138
  return {
1857
2139
  kind: "page",
1858
- slug,
2140
+ slug: slug2,
1859
2141
  title,
1860
2142
  path,
1861
2143
  generation,
@@ -1889,11 +2171,11 @@ function sitePath(to) {
1889
2171
  }
1890
2172
 
1891
2173
  // src/page.tsx
1892
- import { jsx as jsx16 } from "react/jsx-runtime";
2174
+ import { jsx as jsx18 } from "react/jsx-runtime";
1893
2175
  function BuilderPageView({ page, resolve = "shopper" }) {
1894
2176
  const builder = useBuilder();
1895
2177
  if (builder === null) throw new Error("A Builder page needs a BuilderProvider above it");
1896
- return /* @__PURE__ */ jsx16(PageBody, { page, resolve, builder });
2178
+ return /* @__PURE__ */ jsx18(PageBody, { page, resolve, builder });
1897
2179
  }
1898
2180
  function PageBody({
1899
2181
  page,
@@ -1902,7 +2184,7 @@ function PageBody({
1902
2184
  }) {
1903
2185
  const expanded = expandSavedSections(page.document, page.savedSections).doc;
1904
2186
  const resolved = useResolvedData(expanded, builder.registry, builder.locale, resolve);
1905
- return /* @__PURE__ */ jsx16(
2187
+ return /* @__PURE__ */ jsx18(
1906
2188
  BuilderRenderer,
1907
2189
  {
1908
2190
  document: page.document,
@@ -1921,17 +2203,17 @@ function PageBody({
1921
2203
  }
1922
2204
  var entries = /* @__PURE__ */ new WeakMap();
1923
2205
  var ENTRY_MS = 5e3;
1924
- function read(client, slug, locale) {
2206
+ function read(client, slug2, locale) {
1925
2207
  let perClient = entries.get(client);
1926
2208
  if (perClient === void 0) {
1927
2209
  perClient = /* @__PURE__ */ new Map();
1928
2210
  entries.set(client, perClient);
1929
2211
  }
1930
- const key = `${locale}|${slug}`;
2212
+ const key = `${locale}|${slug2}`;
1931
2213
  let entry = perClient.get(key);
1932
2214
  if (entry === void 0) {
1933
2215
  const made = { status: "pending", promise: Promise.resolve() };
1934
- made.promise = client.pages.get(slug, { locale }).then(
2216
+ made.promise = client.pages.get(slug2, { locale }).then(
1935
2217
  (raw) => {
1936
2218
  made.status = "done";
1937
2219
  made.value = isRedirect(raw) ? raw : pageOf(raw, {});
@@ -1951,22 +2233,22 @@ function read(client, slug, locale) {
1951
2233
  if (entry.status === "failed") throw entry.error;
1952
2234
  return entry.value;
1953
2235
  }
1954
- function BuilderPage({ slug, initial }) {
2236
+ function BuilderPage({ slug: slug2, initial }) {
1955
2237
  const builder = useBuilder();
1956
2238
  if (builder === null) throw new Error("BuilderPage needs a BuilderProvider above it");
1957
- if (initial !== void 0) return /* @__PURE__ */ jsx16(BuilderPageView, { page: initial });
2239
+ if (initial !== void 0) return /* @__PURE__ */ jsx18(BuilderPageView, { page: initial });
1958
2240
  if (builder.site.status === "unavailable") {
1959
2241
  throw new BuilderUnavailableError("network", "The Builder is unavailable and has no last good answer");
1960
2242
  }
1961
2243
  if (builder.client === null) {
1962
2244
  throw new Error("BuilderPage reads the page itself: give BuilderProvider a builderKey or a client, or pass `initial`");
1963
2245
  }
1964
- const found = read(builder.client, slug, builder.locale);
1965
- if ("redirectTo" in found) return /* @__PURE__ */ jsx16(Redirect, { to: found.redirectTo });
1966
- return /* @__PURE__ */ jsx16(BuilderPageView, { page: found, resolve: "all" });
2246
+ const found = read(builder.client, slug2, builder.locale);
2247
+ if ("redirectTo" in found) return /* @__PURE__ */ jsx18(Redirect, { to: found.redirectTo });
2248
+ return /* @__PURE__ */ jsx18(BuilderPageView, { page: found, resolve: "all" });
1967
2249
  }
1968
2250
  function Redirect({ to }) {
1969
- useEffect4(() => {
2251
+ useEffect6(() => {
1970
2252
  const path = sitePath(to);
1971
2253
  if (path !== null) window.location.replace(path);
1972
2254
  }, [to]);
@@ -1977,15 +2259,15 @@ function Redirect({ to }) {
1977
2259
  import { createRegistry } from "@usethrottle/builder-schema";
1978
2260
 
1979
2261
  // src/basics/index.ts
1980
- import { BASIC_WIDGET_DEFINITIONS as BASIC_WIDGET_DEFINITIONS2 } from "@usethrottle/builder-schema";
2262
+ import { BASIC_WIDGET_DEFINITIONS as BASIC_WIDGET_DEFINITIONS3 } from "@usethrottle/builder-schema";
1981
2263
 
1982
2264
  // src/basics/announcement.tsx
1983
- import { useEffect as useEffect5, useState as useState2 } from "react";
2265
+ import { useEffect as useEffect7, useState as useState3 } from "react";
1984
2266
  import { Icon, useSiteDesign } from "@usethrottle/ui";
1985
- import { SITE_STRING_DEFAULTS, safeUrl as safeUrl7 } from "@usethrottle/builder-schema";
2267
+ import { SITE_STRING_DEFAULTS as SITE_STRING_DEFAULTS2, safeUrl as safeUrl7 } from "@usethrottle/builder-schema";
1986
2268
 
1987
2269
  // src/basics/util.tsx
1988
- import { BASIC_WIDGET_DEFINITIONS, resolveResponsive as resolveResponsive3, safeUrl as safeUrl6 } from "@usethrottle/builder-schema";
2270
+ import { BASIC_WIDGET_DEFINITIONS, resolveResponsive as resolveResponsive4, safeUrl as safeUrl6 } from "@usethrottle/builder-schema";
1989
2271
 
1990
2272
  // src/basics/styles.ts
1991
2273
  var BASICS_CSS = `@layer throttle{
@@ -2050,34 +2332,34 @@ var BASICS_CSS = `@layer throttle{
2050
2332
  }`;
2051
2333
 
2052
2334
  // src/basics/util.tsx
2053
- import { jsx as jsx17 } from "react/jsx-runtime";
2335
+ import { jsx as jsx19 } from "react/jsx-runtime";
2054
2336
  function BasicStyles() {
2055
- return /* @__PURE__ */ jsx17("style", { href: "tb-basics", precedence: "throttle", children: BASICS_CSS });
2337
+ return /* @__PURE__ */ jsx19("style", { href: "tb-basics", precedence: "throttle", children: BASICS_CSS });
2056
2338
  }
2057
- var isRecord3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
2339
+ var isRecord4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
2058
2340
  var str = (v) => typeof v === "string" && v !== "" ? v : void 0;
2059
2341
  function oneOf(value, allowed, fallback) {
2060
2342
  return allowed.find((candidate) => candidate === value) ?? fallback;
2061
2343
  }
2062
2344
  function hrefOf(link, mediaOrigin) {
2063
- if (!isRecord3(link)) return null;
2345
+ if (!isRecord4(link)) return null;
2064
2346
  return safeUrl6(link.href, "href", { mediaOrigin });
2065
2347
  }
2066
2348
  function Placeholder({ editMode, children }) {
2067
- return editMode ? /* @__PURE__ */ jsx17("div", { className: "tb-b-empty", children }) : null;
2349
+ return editMode ? /* @__PURE__ */ jsx19("div", { className: "tb-b-empty", children }) : null;
2068
2350
  }
2069
2351
  var ID_RE2 = /^[a-z0-9]{8,24}(-[a-z0-9]{8,24})?$/;
2070
- var DEVICES2 = ["desktop", "tablet", "phone"];
2352
+ var DEVICES3 = ["desktop", "tablet", "phone"];
2071
2353
  function defaultOf(type, key) {
2072
- const def = BASIC_WIDGET_DEFINITIONS.find((d) => d.type === type);
2354
+ const def = BASIC_WIDGET_DEFINITIONS.filter((d) => d.type === type).sort((a, b) => b.v - a.v)[0];
2073
2355
  return def?.settings.find((f) => f.key === key)?.default ?? null;
2074
2356
  }
2075
2357
  function enumCss(node, rules) {
2076
2358
  if (!ID_RE2.test(node.id)) return "";
2077
2359
  const per = { desktop: /* @__PURE__ */ new Map(), tablet: /* @__PURE__ */ new Map(), phone: /* @__PURE__ */ new Map() };
2078
- for (const device of DEVICES2) {
2360
+ for (const device of DEVICES3) {
2079
2361
  const settings = { ...Object.fromEntries(rules.map((r) => [r.key, defaultOf(node.type, r.key)])), ...node.props };
2080
- const resolved = resolveResponsive3(settings, node.responsive, device);
2362
+ const resolved = resolveResponsive4(settings, node.responsive, device);
2081
2363
  for (const rule of rules) {
2082
2364
  const value = resolved[rule.key];
2083
2365
  const fallback = defaultOf(node.type, rule.key);
@@ -2094,7 +2376,7 @@ function enumCss(node, rules) {
2094
2376
  }
2095
2377
 
2096
2378
  // src/basics/announcement.tsx
2097
- import { Fragment as Fragment4, jsx as jsx18, jsxs as jsxs8 } from "react/jsx-runtime";
2379
+ import { Fragment as Fragment6, jsx as jsx20, jsxs as jsxs10 } from "react/jsx-runtime";
2098
2380
  var KEY = "tb-announcement-dismissed";
2099
2381
  function read2(message) {
2100
2382
  try {
@@ -2112,25 +2394,25 @@ function write(message) {
2112
2394
  function Announcement({ props, mediaOrigin, editMode }) {
2113
2395
  const design = useSiteDesign();
2114
2396
  const message = design?.announcement?.message;
2115
- const [dismissed, setDismissed] = useState2(false);
2116
- useEffect5(() => {
2397
+ const [dismissed, setDismissed] = useState3(false);
2398
+ useEffect7(() => {
2117
2399
  if (message !== void 0 && read2(message)) setDismissed(true);
2118
2400
  }, [message]);
2119
2401
  if (message === void 0) {
2120
- return /* @__PURE__ */ jsxs8(Fragment4, { children: [
2121
- /* @__PURE__ */ jsx18(BasicStyles, {}),
2122
- /* @__PURE__ */ jsx18(Placeholder, { editMode, children: "No announcement: turn one on in Site settings" })
2402
+ return /* @__PURE__ */ jsxs10(Fragment6, { children: [
2403
+ /* @__PURE__ */ jsx20(BasicStyles, {}),
2404
+ /* @__PURE__ */ jsx20(Placeholder, { editMode, children: "No announcement: turn one on in Site settings" })
2123
2405
  ] });
2124
2406
  }
2125
2407
  if (dismissed && !editMode) return null;
2126
2408
  const href = safeUrl7(design?.announcement?.href, "href", { mediaOrigin });
2127
2409
  const strings = design?.strings;
2128
- const dismissLabel = (strings !== void 0 && Object.hasOwn(strings, "announcement.dismiss") ? str(strings["announcement.dismiss"]) : void 0) ?? SITE_STRING_DEFAULTS["announcement.dismiss"];
2129
- return /* @__PURE__ */ jsxs8(Fragment4, { children: [
2130
- /* @__PURE__ */ jsx18(BasicStyles, {}),
2131
- /* @__PURE__ */ jsxs8("div", { className: "tb-b-announcement", role: "region", "aria-label": message, children: [
2132
- /* @__PURE__ */ jsx18("span", { className: "tb-b-announcement-text", children: href === null ? message : /* @__PURE__ */ jsx18("a", { href, children: message }) }),
2133
- props.dismissible === true && /* @__PURE__ */ jsx18(
2410
+ const dismissLabel = (strings !== void 0 && Object.hasOwn(strings, "announcement.dismiss") ? str(strings["announcement.dismiss"]) : void 0) ?? SITE_STRING_DEFAULTS2["announcement.dismiss"];
2411
+ return /* @__PURE__ */ jsxs10(Fragment6, { children: [
2412
+ /* @__PURE__ */ jsx20(BasicStyles, {}),
2413
+ /* @__PURE__ */ jsxs10("div", { className: "tb-b-announcement", role: "region", "aria-label": message, children: [
2414
+ /* @__PURE__ */ jsx20("span", { className: "tb-b-announcement-text", children: href === null ? message : /* @__PURE__ */ jsx20("a", { href, children: message }) }),
2415
+ props.dismissible === true && /* @__PURE__ */ jsx20(
2134
2416
  "button",
2135
2417
  {
2136
2418
  type: "button",
@@ -2139,7 +2421,7 @@ function Announcement({ props, mediaOrigin, editMode }) {
2139
2421
  write(message);
2140
2422
  setDismissed(true);
2141
2423
  },
2142
- children: /* @__PURE__ */ jsx18(Icon, { name: "close", size: 16, label: dismissLabel })
2424
+ children: /* @__PURE__ */ jsx20(Icon, { name: "close", size: 16, label: dismissLabel })
2143
2425
  }
2144
2426
  )
2145
2427
  ] })
@@ -2147,36 +2429,36 @@ function Announcement({ props, mediaOrigin, editMode }) {
2147
2429
  }
2148
2430
 
2149
2431
  // src/basics/button.tsx
2150
- import { Fragment as Fragment5, jsx as jsx19, jsxs as jsxs9 } from "react/jsx-runtime";
2432
+ import { Fragment as Fragment7, jsx as jsx21, jsxs as jsxs11 } from "react/jsx-runtime";
2151
2433
  var STYLES = ["primary", "secondary", "outline", "link"];
2152
2434
  var SIZES = ["s", "m", "l"];
2153
2435
  function Button({ props, mediaOrigin, inlineEdit }) {
2154
2436
  const href = hrefOf(props.link, mediaOrigin);
2155
2437
  const className = `tb-b-button tb-b-button--${oneOf(props.style, STYLES, "primary")} tb-b-button--${oneOf(props.size, SIZES, "m")}`;
2156
2438
  const label = inlineEdit?.("label") ?? str(props.label) ?? "";
2157
- return /* @__PURE__ */ jsxs9(Fragment5, { children: [
2158
- /* @__PURE__ */ jsx19(BasicStyles, {}),
2159
- /* @__PURE__ */ jsx19("div", { className: "tb-b-button-wrap", children: /* @__PURE__ */ jsx19("a", { className, ...href === null ? {} : { href }, children: label }) })
2439
+ return /* @__PURE__ */ jsxs11(Fragment7, { children: [
2440
+ /* @__PURE__ */ jsx21(BasicStyles, {}),
2441
+ /* @__PURE__ */ jsx21("div", { className: "tb-b-button-wrap", children: /* @__PURE__ */ jsx21("a", { className, ...href === null ? {} : { href }, children: label }) })
2160
2442
  ] });
2161
2443
  }
2162
2444
 
2163
2445
  // src/basics/copyright.tsx
2164
2446
  import { useSiteDesign as useSiteDesign2 } from "@usethrottle/ui";
2165
- import { SITE_STRING_DEFAULTS as SITE_STRING_DEFAULTS2 } from "@usethrottle/builder-schema";
2166
- import { Fragment as Fragment6, jsx as jsx20, jsxs as jsxs10 } from "react/jsx-runtime";
2447
+ import { SITE_STRING_DEFAULTS as SITE_STRING_DEFAULTS3 } from "@usethrottle/builder-schema";
2448
+ import { Fragment as Fragment8, jsx as jsx22, jsxs as jsxs12 } from "react/jsx-runtime";
2167
2449
  function Copyright(_) {
2168
2450
  const design = useSiteDesign2();
2169
2451
  const strings = design?.strings;
2170
2452
  const template = strings !== void 0 && Object.hasOwn(strings, "footer.copyright") ? str(strings["footer.copyright"]) : void 0;
2171
- const line = (template ?? SITE_STRING_DEFAULTS2["footer.copyright"]).replace("{year}", () => String((/* @__PURE__ */ new Date()).getFullYear())).replace("{store}", () => str(design?.brand?.storeName) ?? "").replace(/\s{2,}/g, " ").replace(/\s+([.,])/g, "$1");
2172
- return /* @__PURE__ */ jsxs10(Fragment6, { children: [
2173
- /* @__PURE__ */ jsx20(BasicStyles, {}),
2174
- /* @__PURE__ */ jsx20("p", { className: "tb-b-copyright", children: line })
2453
+ const line = (template ?? SITE_STRING_DEFAULTS3["footer.copyright"]).replace("{year}", () => String((/* @__PURE__ */ new Date()).getFullYear())).replace("{store}", () => str(design?.brand?.storeName) ?? "").replace(/\s{2,}/g, " ").replace(/\s+([.,])/g, "$1");
2454
+ return /* @__PURE__ */ jsxs12(Fragment8, { children: [
2455
+ /* @__PURE__ */ jsx22(BasicStyles, {}),
2456
+ /* @__PURE__ */ jsx22("p", { className: "tb-b-copyright", children: line })
2175
2457
  ] });
2176
2458
  }
2177
2459
 
2178
2460
  // src/basics/countdown.tsx
2179
- import { Fragment as Fragment7, jsx as jsx21, jsxs as jsxs11 } from "react/jsx-runtime";
2461
+ import { Fragment as Fragment9, jsx as jsx23, jsxs as jsxs13 } from "react/jsx-runtime";
2180
2462
  var UNITS2 = [
2181
2463
  { key: "d", show: "showDays", label: "labelDays", seconds: 86400 },
2182
2464
  { key: "h", show: "showHours", label: "labelHours", seconds: 3600 },
@@ -2202,10 +2484,10 @@ function targetText(date) {
2202
2484
  }
2203
2485
  function Countdown({ props, editMode, interactive, locale }) {
2204
2486
  void locale;
2205
- const target = str(props.target);
2206
- const when = target === void 0 ? null : new Date(target);
2487
+ const target2 = str(props.target);
2488
+ const when = target2 === void 0 ? null : new Date(target2);
2207
2489
  if (when === null || Number.isNaN(when.getTime())) {
2208
- return /* @__PURE__ */ jsx21(Placeholder, { editMode, children: "Set the date and time the countdown ends" });
2490
+ return /* @__PURE__ */ jsx23(Placeholder, { editMode, children: "Set the date and time the countdown ends" });
2209
2491
  }
2210
2492
  const live = interactive !== false;
2211
2493
  const behavior = oneOf(props.expiredBehavior, ["text", "hide"], "text");
@@ -2216,11 +2498,11 @@ function Countdown({ props, editMode, interactive, locale }) {
2216
2498
  if (value !== null) left -= value * unit.seconds;
2217
2499
  return { ...unit, text: value === null ? "--" : two(value), name: str(props[unit.label]) ?? "" };
2218
2500
  });
2219
- return /* @__PURE__ */ jsxs11(Fragment7, { children: [
2220
- /* @__PURE__ */ jsx21(BasicStyles, {}),
2221
- /* @__PURE__ */ jsx21("style", { href: "tb-countdown", precedence: "throttle", children: COUNTDOWN_CSS }),
2222
- live ? /* @__PURE__ */ jsx21(InteractionRuntime, {}) : null,
2223
- /* @__PURE__ */ jsxs11(
2501
+ return /* @__PURE__ */ jsxs13(Fragment9, { children: [
2502
+ /* @__PURE__ */ jsx23(BasicStyles, {}),
2503
+ /* @__PURE__ */ jsx23("style", { href: "tb-countdown", precedence: "throttle", children: COUNTDOWN_CSS }),
2504
+ live ? /* @__PURE__ */ jsx23(InteractionRuntime, {}) : null,
2505
+ /* @__PURE__ */ jsxs13(
2224
2506
  "div",
2225
2507
  {
2226
2508
  className: "tb-b-cd",
@@ -2228,13 +2510,13 @@ function Countdown({ props, editMode, interactive, locale }) {
2228
2510
  "aria-live": "off",
2229
2511
  ...live ? { "data-b-cd": String(when.getTime()), "data-b-expired": behavior } : {},
2230
2512
  children: [
2231
- /* @__PURE__ */ jsx21("p", { className: "tb-b-cd-date", children: /* @__PURE__ */ jsx21("time", { dateTime: when.toISOString(), children: targetText(when) }) }),
2232
- units.length === 0 ? null : /* @__PURE__ */ jsx21("div", { className: "tb-b-cd-units", children: units.map((unit) => /* @__PURE__ */ jsxs11("div", { className: "tb-b-cd-unit", children: [
2233
- /* @__PURE__ */ jsx21("span", { className: "tb-b-cd-num", "data-u": unit.key, "aria-hidden": "true", children: unit.text }),
2234
- /* @__PURE__ */ jsx21("span", { className: "tb-b-cd-label", children: unit.name })
2513
+ /* @__PURE__ */ jsx23("p", { className: "tb-b-cd-date", children: /* @__PURE__ */ jsx23("time", { dateTime: when.toISOString(), children: targetText(when) }) }),
2514
+ units.length === 0 ? null : /* @__PURE__ */ jsx23("div", { className: "tb-b-cd-units", children: units.map((unit) => /* @__PURE__ */ jsxs13("div", { className: "tb-b-cd-unit", children: [
2515
+ /* @__PURE__ */ jsx23("span", { className: "tb-b-cd-num", "data-u": unit.key, "aria-hidden": "true", children: unit.text }),
2516
+ /* @__PURE__ */ jsx23("span", { className: "tb-b-cd-label", children: unit.name })
2235
2517
  ] }, unit.key)) }),
2236
- /* @__PURE__ */ jsx21("p", { className: "tb-b-cd-ended", hidden: live || when.getTime() > Date.now(), children: str(props.expiredText) ?? "" }),
2237
- /* @__PURE__ */ jsx21("span", { className: "tb-b-sr", "data-b-live": "", "aria-live": "polite" })
2518
+ /* @__PURE__ */ jsx23("p", { className: "tb-b-cd-ended", hidden: live || when.getTime() > Date.now(), children: str(props.expiredText) ?? "" }),
2519
+ /* @__PURE__ */ jsx23("span", { className: "tb-b-sr", "data-b-live": "", "aria-live": "polite" })
2238
2520
  ]
2239
2521
  }
2240
2522
  )
@@ -2242,30 +2524,103 @@ function Countdown({ props, editMode, interactive, locale }) {
2242
2524
  }
2243
2525
 
2244
2526
  // src/basics/divider.tsx
2245
- import { Fragment as Fragment8, jsx as jsx22, jsxs as jsxs12 } from "react/jsx-runtime";
2527
+ import { Fragment as Fragment10, jsx as jsx24, jsxs as jsxs14 } from "react/jsx-runtime";
2246
2528
  var RULES = [{ key: "style", property: "--bx-style", values: { solid: "solid", dashed: "dashed", dotted: "dotted" } }];
2247
2529
  function Divider({ node }) {
2248
- return /* @__PURE__ */ jsxs12(Fragment8, { children: [
2249
- /* @__PURE__ */ jsx22(BasicStyles, {}),
2250
- /* @__PURE__ */ jsx22(WidgetStyle, { css: enumCss(node, RULES) }),
2251
- /* @__PURE__ */ jsx22("hr", { className: "tb-b-divider" })
2530
+ return /* @__PURE__ */ jsxs14(Fragment10, { children: [
2531
+ /* @__PURE__ */ jsx24(BasicStyles, {}),
2532
+ /* @__PURE__ */ jsx24(WidgetStyle, { css: enumCss(node, RULES) }),
2533
+ /* @__PURE__ */ jsx24("hr", { className: "tb-b-divider" })
2534
+ ] });
2535
+ }
2536
+
2537
+ // src/basics/v2/styles.tsx
2538
+ import { Fragment as Fragment11, jsx as jsx25, jsxs as jsxs15 } from "react/jsx-runtime";
2539
+ var BASICS_V2_CSS = `@layer throttle{
2540
+ .tb-b-faq{color:var(--b-color,inherit);font-size:var(--b-size,var(--tb-text-m));line-height:1.6}
2541
+ .tb-b-faq-item{border-block-end:1px solid var(--tb-color-border,currentColor)}
2542
+ .tb-b-faq-q{margin:0;padding:var(--tb-space-s) 0;font-weight:600;cursor:pointer}
2543
+ h3.tb-b-faq-q{cursor:auto;font-size:inherit}
2544
+ .tb-b-faq-a{padding-block-end:var(--tb-space-s)}
2545
+ .tb-b-faq-a>:first-child{margin-block-start:0}
2546
+ .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}
2547
+ .tb-b-faq summary:focus-visible,.tb-b-faq-all:focus-visible{outline:2px solid var(--tb-color-primary,currentColor);outline-offset:2px}
2548
+ .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}
2549
+ .tb-b-rich>:first-child{margin-block-start:0}
2550
+ .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)}
2551
+ .tb-b-rich table{border-collapse:collapse;max-inline-size:100%;display:block;overflow-x:auto}
2552
+ .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}
2553
+ .tb-b-rich figure{margin-inline:0}
2554
+ .tb-b-rich img{max-inline-size:100%;block-size:auto}
2555
+ .tb-b-rich pre{overflow-x:auto;padding:var(--tb-space-s);background:var(--tb-color-muted,#eee)}
2556
+ .tb-b-rich code{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:.9em}
2557
+ .tb-b-rich blockquote{margin-inline:0;padding-inline-start:var(--tb-space-m);border-inline-start:3px solid var(--tb-color-border,currentColor)}
2558
+ .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)}
2559
+ .tb-b-toc-title{margin:0 0 var(--tb-space-xs);font-weight:600}
2560
+ .tb-b-toc ol{margin:0;padding:0;list-style:none}
2561
+ .tb-b-toc-l3{padding-inline-start:var(--tb-space-m)}
2562
+ .tb-b-toc a{color:inherit}
2563
+ .tb-b-svg{display:block;text-align:var(--b-align,left);color:var(--b-color,inherit);line-height:0}
2564
+ .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)}
2565
+ .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}
2566
+ .tb-b-icons li{display:flex;gap:var(--tb-space-s);align-items:flex-start;padding-block:var(--tb-space-xs)}
2567
+ .tb-b-icons-icon{flex:0 0 auto;display:inline-flex;color:var(--b-iconColor,var(--tb-color-primary,currentColor))}
2568
+ .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)}
2569
+ .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))}
2570
+ .tb-b-quote blockquote{margin:0;font-family:var(--throttle-font-family-heading,inherit);line-height:1.4}
2571
+ .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)}
2572
+ .tb-b-quote-photo{inline-size:48px;block-size:48px;border-radius:50%;object-fit:cover}
2573
+ .tb-b-quote-by{display:flex;flex-direction:column}
2574
+ .tb-b-quote-name{font-weight:600}
2575
+ .tb-b-quote-role{color:var(--tb-color-muted-foreground,inherit)}
2576
+ .tb-b-heading-wrap{text-align:var(--b-align,left)}
2577
+ .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))}
2578
+ .tb-b-kicker-rule{flex:0 0 auto;inline-size:2rem;block-size:1px;background:currentColor}
2579
+ .tb-b-crumbs{text-align:var(--b-align,left);color:var(--b-color,inherit);font-size:var(--b-size,var(--tb-text-s))}
2580
+ .tb-b-crumbs ol{display:flex;flex-wrap:wrap;gap:var(--tb-space-xs);margin:0;padding:0;list-style:none}
2581
+ .tb-b-crumbs li{display:inline-flex;align-items:center;gap:var(--tb-space-xs)}
2582
+ .tb-b-crumbs a{color:inherit;text-decoration:none}
2583
+ .tb-b-crumbs a:hover{text-decoration:underline}
2584
+ .tb-b-crumbs a:focus-visible{outline:2px solid var(--tb-color-primary,currentColor);outline-offset:2px}
2585
+ .tb-b-crumbs [aria-current]{font-weight:600}
2586
+ }`;
2587
+ function BasicV2Styles() {
2588
+ return /* @__PURE__ */ jsxs15(Fragment11, { children: [
2589
+ /* @__PURE__ */ jsx25(BasicStyles, {}),
2590
+ /* @__PURE__ */ jsx25("style", { href: "tb-basics-v2", precedence: "throttle", children: BASICS_V2_CSS })
2252
2591
  ] });
2253
2592
  }
2254
2593
 
2255
2594
  // src/basics/heading.tsx
2256
- import { Fragment as Fragment9, jsx as jsx23, jsxs as jsxs13 } from "react/jsx-runtime";
2595
+ import { Fragment as Fragment12, jsx as jsx26, jsxs as jsxs16 } from "react/jsx-runtime";
2257
2596
  var LEVELS = ["h1", "h2", "h3", "h4", "h5", "h6"];
2258
2597
  function Heading({ props, inlineEdit }) {
2259
2598
  const Tag = oneOf(props.level, LEVELS, "h2");
2260
- return /* @__PURE__ */ jsxs13(Fragment9, { children: [
2261
- /* @__PURE__ */ jsx23(BasicStyles, {}),
2262
- /* @__PURE__ */ jsx23(Tag, { className: "tb-b-heading", children: inlineEdit?.("text") ?? str(props.text) ?? "" })
2599
+ const heading = /* @__PURE__ */ jsx26(Tag, { className: "tb-b-heading", children: inlineEdit?.("text") ?? str(props.text) ?? "" });
2600
+ const kicker = inlineEdit?.("kicker") ?? str(props.kicker);
2601
+ const rule = props.rule === true;
2602
+ if (kicker === void 0 && !rule) {
2603
+ return /* @__PURE__ */ jsxs16(Fragment12, { children: [
2604
+ /* @__PURE__ */ jsx26(BasicStyles, {}),
2605
+ heading
2606
+ ] });
2607
+ }
2608
+ return /* @__PURE__ */ jsxs16(Fragment12, { children: [
2609
+ /* @__PURE__ */ jsx26(BasicStyles, {}),
2610
+ /* @__PURE__ */ jsx26(BasicV2Styles, {}),
2611
+ /* @__PURE__ */ jsxs16("div", { className: "tb-b-heading-wrap", children: [
2612
+ /* @__PURE__ */ jsxs16("p", { className: "tb-b-kicker", children: [
2613
+ rule && /* @__PURE__ */ jsx26("span", { className: "tb-b-kicker-rule", "aria-hidden": "true" }),
2614
+ kicker
2615
+ ] }),
2616
+ heading
2617
+ ] })
2263
2618
  ] });
2264
2619
  }
2265
2620
 
2266
2621
  // src/basics/image.tsx
2267
2622
  import { safeUrl as safeUrl8 } from "@usethrottle/builder-schema";
2268
- import { Fragment as Fragment10, jsx as jsx24, jsxs as jsxs14 } from "react/jsx-runtime";
2623
+ import { Fragment as Fragment13, jsx as jsx27, jsxs as jsxs17 } from "react/jsx-runtime";
2269
2624
  var RULES2 = [
2270
2625
  { key: "radius", property: "--bx-radius", values: { none: "0", s: "4px", m: "8px", l: "16px", full: "9999px" } },
2271
2626
  { key: "fit", property: "--bx-fit", values: { cover: "cover", contain: "contain" } }
@@ -2275,19 +2630,19 @@ function Image({ node, props, mediaOrigin, editMode }) {
2275
2630
  const decorative = props.decorative === true;
2276
2631
  const alt = decorative ? "" : typeof props.alt === "string" ? props.alt : "";
2277
2632
  const asset = isFrozenAsset(props.image) ? props.image : void 0;
2278
- const image = /* @__PURE__ */ jsx24(AssetImage, { asset, mediaOrigin, alt, className: "tb-b-img", sizes: "(max-width: 767px) 100vw, 50vw" });
2633
+ const image = /* @__PURE__ */ jsx27(AssetImage, { asset, mediaOrigin, alt, className: "tb-b-img", sizes: "(max-width: 767px) 100vw, 50vw" });
2279
2634
  const shown2 = asset !== void 0 && safeUrl8(asset.url, "src", { mediaOrigin }) !== null;
2280
- return /* @__PURE__ */ jsxs14(Fragment10, { children: [
2281
- /* @__PURE__ */ jsx24(BasicStyles, {}),
2282
- /* @__PURE__ */ jsx24(WidgetStyle, { css: enumCss(node, RULES2) }),
2283
- shown2 ? /* @__PURE__ */ jsx24("div", { className: "tb-b-image", children: /* @__PURE__ */ jsx24("div", { className: "tb-b-image-box", children: href === null ? image : /* @__PURE__ */ jsx24("a", { href, children: image }) }) }) : /* @__PURE__ */ jsx24(Placeholder, { editMode, children: asset === void 0 ? "Choose an image" : "Image unavailable" })
2635
+ return /* @__PURE__ */ jsxs17(Fragment13, { children: [
2636
+ /* @__PURE__ */ jsx27(BasicStyles, {}),
2637
+ /* @__PURE__ */ jsx27(WidgetStyle, { css: enumCss(node, RULES2) }),
2638
+ shown2 ? /* @__PURE__ */ jsx27("div", { className: "tb-b-image", children: /* @__PURE__ */ jsx27("div", { className: "tb-b-image-box", children: href === null ? image : /* @__PURE__ */ jsx27("a", { href, children: image }) }) }) : /* @__PURE__ */ jsx27(Placeholder, { editMode, children: asset === void 0 ? "Choose an image" : "Image unavailable" })
2284
2639
  ] });
2285
2640
  }
2286
2641
 
2287
2642
  // src/basics/logo.tsx
2288
2643
  import { useSiteDesign as useSiteDesign3 } from "@usethrottle/ui";
2289
2644
  import { safeUrl as safeUrl9 } from "@usethrottle/builder-schema";
2290
- import { Fragment as Fragment11, jsx as jsx25, jsxs as jsxs15 } from "react/jsx-runtime";
2645
+ import { Fragment as Fragment14, jsx as jsx28, jsxs as jsxs18 } from "react/jsx-runtime";
2291
2646
  function Logo({ props, mediaOrigin, editMode }) {
2292
2647
  const design = useSiteDesign3();
2293
2648
  const scheme = design?.theme?.colorScheme ?? "auto";
@@ -2300,25 +2655,25 @@ function Logo({ props, mediaOrigin, editMode }) {
2300
2655
  const alt = name ?? "";
2301
2656
  let content = null;
2302
2657
  if (main !== void 0) {
2303
- const img = /* @__PURE__ */ jsx25("img", { src: main, alt, decoding: "async" });
2304
- content = scheme === "auto" && light !== void 0 && dark !== void 0 ? /* @__PURE__ */ jsxs15("picture", { children: [
2305
- /* @__PURE__ */ jsx25("source", { media: "(prefers-color-scheme: dark)", srcSet: dark }),
2658
+ const img = /* @__PURE__ */ jsx28("img", { src: main, alt, decoding: "async" });
2659
+ content = scheme === "auto" && light !== void 0 && dark !== void 0 ? /* @__PURE__ */ jsxs18("picture", { children: [
2660
+ /* @__PURE__ */ jsx28("source", { media: "(prefers-color-scheme: dark)", srcSet: dark }),
2306
2661
  img
2307
2662
  ] }) : img;
2308
2663
  } else if (name !== void 0) {
2309
- content = /* @__PURE__ */ jsx25("span", { className: "tb-b-logo-name", children: name });
2664
+ content = /* @__PURE__ */ jsx28("span", { className: "tb-b-logo-name", children: name });
2310
2665
  }
2311
- return /* @__PURE__ */ jsxs15(Fragment11, { children: [
2312
- /* @__PURE__ */ jsx25(BasicStyles, {}),
2313
- content === null ? /* @__PURE__ */ jsx25(Placeholder, { editMode, children: "Logo: add one in Site settings" }) : /* @__PURE__ */ jsx25("div", { className: "tb-b-logo", children: /* @__PURE__ */ jsx25("a", { href, children: content }) })
2666
+ return /* @__PURE__ */ jsxs18(Fragment14, { children: [
2667
+ /* @__PURE__ */ jsx28(BasicStyles, {}),
2668
+ content === null ? /* @__PURE__ */ jsx28(Placeholder, { editMode, children: "Logo: add one in Site settings" }) : /* @__PURE__ */ jsx28("div", { className: "tb-b-logo", children: /* @__PURE__ */ jsx28("a", { href, children: content }) })
2314
2669
  ] });
2315
2670
  }
2316
2671
 
2317
2672
  // src/basics/menu.tsx
2318
- import { useId, useRef as useRef2, useState as useState3 } from "react";
2673
+ import { useId, useRef as useRef2, useState as useState4 } from "react";
2319
2674
  import { Icon as Icon2, useSiteDesign as useSiteDesign4 } from "@usethrottle/ui";
2320
- import { SITE_STRING_DEFAULTS as SITE_STRING_DEFAULTS3, safeUrl as safeUrl10 } from "@usethrottle/builder-schema";
2321
- import { Fragment as Fragment12, jsx as jsx26, jsxs as jsxs16 } from "react/jsx-runtime";
2675
+ import { SITE_STRING_DEFAULTS as SITE_STRING_DEFAULTS4, safeUrl as safeUrl10 } from "@usethrottle/builder-schema";
2676
+ import { Fragment as Fragment15, jsx as jsx29, jsxs as jsxs19 } from "react/jsx-runtime";
2322
2677
  var LAYOUTS = ["horizontal", "vertical", "drawer-on-phone"];
2323
2678
  var MAX_DEPTH2 = 3;
2324
2679
  function List({ items, mediaOrigin, depth = 0, id, onNavigate }) {
@@ -2327,38 +2682,38 @@ function List({ items, mediaOrigin, depth = 0, id, onNavigate }) {
2327
2682
  return href === null ? [] : [{ item, href }];
2328
2683
  });
2329
2684
  if (shown2.length === 0) return null;
2330
- return /* @__PURE__ */ jsx26("ul", { ...id === void 0 ? {} : { id }, ...onNavigate === void 0 ? {} : { onClick: onNavigate }, children: shown2.map(({ item, href }, index) => /* @__PURE__ */ jsxs16("li", { children: [
2331
- /* @__PURE__ */ jsx26("a", { href, children: item.label }),
2332
- depth + 1 < MAX_DEPTH2 && item.children !== void 0 && /* @__PURE__ */ jsx26(List, { items: item.children, mediaOrigin, depth: depth + 1 })
2685
+ return /* @__PURE__ */ jsx29("ul", { ...id === void 0 ? {} : { id }, ...onNavigate === void 0 ? {} : { onClick: onNavigate }, children: shown2.map(({ item, href }, index) => /* @__PURE__ */ jsxs19("li", { children: [
2686
+ /* @__PURE__ */ jsx29("a", { href, children: item.label }),
2687
+ depth + 1 < MAX_DEPTH2 && item.children !== void 0 && /* @__PURE__ */ jsx29(List, { items: item.children, mediaOrigin, depth: depth + 1 })
2333
2688
  ] }, `${String(index)}:${href}`)) });
2334
2689
  }
2335
2690
  function Menu({ props, mediaOrigin, editMode }) {
2336
2691
  const design = useSiteDesign4();
2337
2692
  const listId = useId();
2338
2693
  const toggle = useRef2(null);
2339
- const [open, setOpen] = useState3(false);
2694
+ const [open, setOpen2] = useState4(false);
2340
2695
  const name = str(props.menu) ?? "header";
2341
2696
  const layout = oneOf(props.layout, LAYOUTS, "horizontal");
2342
2697
  const menus = design?.menus;
2343
2698
  const items = menus !== void 0 && Object.hasOwn(menus, name) ? menus[name] : void 0;
2344
2699
  const strings = design?.strings;
2345
- const label = (strings !== void 0 && Object.hasOwn(strings, "nav.menu") ? str(strings["nav.menu"]) : void 0) ?? SITE_STRING_DEFAULTS3["nav.menu"];
2700
+ const label = (strings !== void 0 && Object.hasOwn(strings, "nav.menu") ? str(strings["nav.menu"]) : void 0) ?? SITE_STRING_DEFAULTS4["nav.menu"];
2346
2701
  if (items === void 0 || items.length === 0) {
2347
- return /* @__PURE__ */ jsxs16(Fragment12, { children: [
2348
- /* @__PURE__ */ jsx26(BasicStyles, {}),
2349
- /* @__PURE__ */ jsx26(Placeholder, { editMode, children: `Menu "${name}" is empty: add links in Site settings` })
2702
+ return /* @__PURE__ */ jsxs19(Fragment15, { children: [
2703
+ /* @__PURE__ */ jsx29(BasicStyles, {}),
2704
+ /* @__PURE__ */ jsx29(Placeholder, { editMode, children: `Menu "${name}" is empty: add links in Site settings` })
2350
2705
  ] });
2351
2706
  }
2352
2707
  const drawer = layout === "drawer-on-phone";
2353
2708
  const onKeyDown = (event) => {
2354
2709
  if (event.key === "Escape" && open) {
2355
- setOpen(false);
2710
+ setOpen2(false);
2356
2711
  toggle.current?.focus();
2357
2712
  }
2358
2713
  };
2359
- return /* @__PURE__ */ jsxs16(Fragment12, { children: [
2360
- /* @__PURE__ */ jsx26(BasicStyles, {}),
2361
- /* @__PURE__ */ jsxs16(
2714
+ return /* @__PURE__ */ jsxs19(Fragment15, { children: [
2715
+ /* @__PURE__ */ jsx29(BasicStyles, {}),
2716
+ /* @__PURE__ */ jsxs19(
2362
2717
  "nav",
2363
2718
  {
2364
2719
  className: `tb-b-menu tb-b-menu--${layout}${layout === "vertical" ? "" : " tb-b-menu--h"}`,
@@ -2366,7 +2721,7 @@ function Menu({ props, mediaOrigin, editMode }) {
2366
2721
  "data-open": drawer ? String(open) : void 0,
2367
2722
  onKeyDown: drawer ? onKeyDown : void 0,
2368
2723
  children: [
2369
- drawer && /* @__PURE__ */ jsx26(
2724
+ drawer && /* @__PURE__ */ jsx29(
2370
2725
  "button",
2371
2726
  {
2372
2727
  ref: toggle,
@@ -2374,11 +2729,11 @@ function Menu({ props, mediaOrigin, editMode }) {
2374
2729
  className: "tb-b-menu-toggle",
2375
2730
  "aria-expanded": open,
2376
2731
  "aria-controls": listId,
2377
- onClick: () => setOpen((value) => !value),
2378
- children: /* @__PURE__ */ jsx26(Icon2, { name: open ? "close" : "menu", size: 24, label })
2732
+ onClick: () => setOpen2((value) => !value),
2733
+ children: /* @__PURE__ */ jsx29(Icon2, { name: open ? "close" : "menu", size: 24, label })
2379
2734
  }
2380
2735
  ),
2381
- /* @__PURE__ */ jsx26(List, { items, mediaOrigin, id: listId, ...drawer ? { onNavigate: () => setOpen(false) } : {} })
2736
+ /* @__PURE__ */ jsx29(List, { items, mediaOrigin, id: listId, ...drawer ? { onNavigate: () => setOpen2(false) } : {} })
2382
2737
  ]
2383
2738
  }
2384
2739
  )
@@ -2386,18 +2741,18 @@ function Menu({ props, mediaOrigin, editMode }) {
2386
2741
  }
2387
2742
 
2388
2743
  // src/basics/spacer.tsx
2389
- import { Fragment as Fragment13, jsx as jsx27, jsxs as jsxs17 } from "react/jsx-runtime";
2744
+ import { Fragment as Fragment16, jsx as jsx30, jsxs as jsxs20 } from "react/jsx-runtime";
2390
2745
  function Spacer() {
2391
- return /* @__PURE__ */ jsxs17(Fragment13, { children: [
2392
- /* @__PURE__ */ jsx27(BasicStyles, {}),
2393
- /* @__PURE__ */ jsx27("div", { className: "tb-b-spacer", "aria-hidden": "true" })
2746
+ return /* @__PURE__ */ jsxs20(Fragment16, { children: [
2747
+ /* @__PURE__ */ jsx30(BasicStyles, {}),
2748
+ /* @__PURE__ */ jsx30("div", { className: "tb-b-spacer", "aria-hidden": "true" })
2394
2749
  ] });
2395
2750
  }
2396
2751
 
2397
2752
  // src/basics/rich-text.tsx
2398
- import { Fragment as Fragment14, createElement as createElement2 } from "react";
2753
+ import { Fragment as Fragment17, createElement as createElement2 } from "react";
2399
2754
  import { safeUrl as safeUrl11 } from "@usethrottle/builder-schema";
2400
- import { jsx as jsx28, jsxs as jsxs18 } from "react/jsx-runtime";
2755
+ import { jsx as jsx31, jsxs as jsxs21 } from "react/jsx-runtime";
2401
2756
  var ALLOWED = /* @__PURE__ */ new Set(["p", "br", "strong", "em", "u", "s", "a", "ul", "ol", "li", "h2", "h3", "h4", "blockquote", "code"]);
2402
2757
  var ALIAS = { b: "strong", i: "em", strike: "s", del: "s" };
2403
2758
  var DROP_WITH_CONTENT = /* @__PURE__ */ new Set([
@@ -2556,11 +2911,11 @@ function parseRichText(source, mediaOrigin) {
2556
2911
  }
2557
2912
  }
2558
2913
  if (name === "li") {
2559
- let list = stack.length - 1;
2560
- while (list > 0 && stack[list].tag !== "ul" && stack[list].tag !== "ol") list -= 1;
2561
- if (list === 0) list = -1;
2562
- if (list === -1) continue;
2563
- stack.length = list + 1;
2914
+ let list2 = stack.length - 1;
2915
+ while (list2 > 0 && stack[list2].tag !== "ul" && stack[list2].tag !== "ol") list2 -= 1;
2916
+ if (list2 === 0) list2 = -1;
2917
+ if (list2 === -1) continue;
2918
+ stack.length = list2 + 1;
2564
2919
  }
2565
2920
  if (name === "a") closeTo("a");
2566
2921
  const el = { tag: name, children: [] };
@@ -2577,10 +2932,10 @@ function parseRichText(source, mediaOrigin) {
2577
2932
  }
2578
2933
  function toReact(el, key) {
2579
2934
  const children = el.children.map((child, index) => typeof child === "string" ? child : toReact(child, index));
2580
- if (el.tag === "br") return /* @__PURE__ */ jsx28("br", {}, key);
2935
+ if (el.tag === "br") return /* @__PURE__ */ jsx31("br", {}, key);
2581
2936
  if (el.tag === "a") {
2582
- if (el.href === null || el.href === void 0) return /* @__PURE__ */ jsx28(Fragment14, { children }, key);
2583
- return /* @__PURE__ */ jsx28("a", { href: el.href, rel: "noopener noreferrer", className: "tb-b-link", children }, key);
2937
+ if (el.href === null || el.href === void 0) return /* @__PURE__ */ jsx31(Fragment17, { children }, key);
2938
+ return /* @__PURE__ */ jsx31("a", { href: el.href, rel: "noopener noreferrer", className: "tb-b-link", children }, key);
2584
2939
  }
2585
2940
  return createElement2(el.tag, { key }, ...children);
2586
2941
  }
@@ -2591,26 +2946,26 @@ function RichText({
2591
2946
  editMode = false
2592
2947
  }) {
2593
2948
  const tree = parseRichText(html, mediaOrigin);
2594
- return /* @__PURE__ */ jsxs18("div", { className, children: [
2949
+ return /* @__PURE__ */ jsxs21("div", { className, children: [
2595
2950
  tree.children.map((child, index) => typeof child === "string" ? child : toReact(child, index)),
2596
- editMode && tree.truncated === true && /* @__PURE__ */ jsx28("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." })
2951
+ editMode && tree.truncated === true && /* @__PURE__ */ jsx31("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." })
2597
2952
  ] });
2598
2953
  }
2599
2954
 
2600
2955
  // src/basics/text.tsx
2601
- import { Fragment as Fragment15, jsx as jsx29, jsxs as jsxs19 } from "react/jsx-runtime";
2956
+ import { Fragment as Fragment18, jsx as jsx32, jsxs as jsxs22 } from "react/jsx-runtime";
2602
2957
  function Text({ props, mediaOrigin, editMode, inlineEdit }) {
2603
2958
  const editor = inlineEdit?.("html") ?? null;
2604
- return /* @__PURE__ */ jsxs19(Fragment15, { children: [
2605
- /* @__PURE__ */ jsx29(BasicStyles, {}),
2606
- editor === null ? /* @__PURE__ */ jsx29(RichText, { html: str(props.html) ?? "", mediaOrigin, className: "tb-b-text", editMode }) : /* @__PURE__ */ jsx29("div", { className: "tb-b-text", children: editor })
2959
+ return /* @__PURE__ */ jsxs22(Fragment18, { children: [
2960
+ /* @__PURE__ */ jsx32(BasicStyles, {}),
2961
+ editor === null ? /* @__PURE__ */ jsx32(RichText, { html: str(props.html) ?? "", mediaOrigin, className: "tb-b-text", editMode }) : /* @__PURE__ */ jsx32("div", { className: "tb-b-text", children: editor })
2607
2962
  ] });
2608
2963
  }
2609
2964
 
2610
2965
  // src/basics/video.tsx
2611
- import { useState as useState4 } from "react";
2966
+ import { useState as useState5 } from "react";
2612
2967
  import { Icon as Icon3 } from "@usethrottle/ui";
2613
- import { Fragment as Fragment16, jsx as jsx30, jsxs as jsxs20 } from "react/jsx-runtime";
2968
+ import { Fragment as Fragment19, jsx as jsx33, jsxs as jsxs23 } from "react/jsx-runtime";
2614
2969
  var RULES3 = [
2615
2970
  { key: "ratio", property: "--bx-ratio", values: { "16:9": "16 / 9", "4:3": "4 / 3", "1:1": "1 / 1", "9:16": "9 / 16" } }
2616
2971
  ];
@@ -2627,7 +2982,7 @@ function parseVideoUrl(input) {
2627
2982
  }
2628
2983
  if (url.protocol !== "https:" || url.username !== "" || url.password !== "" || url.port !== "" && url.port !== "443") return null;
2629
2984
  const host = url.hostname.toLowerCase();
2630
- const parts = url.pathname.split("/").filter((part) => part !== "");
2985
+ const parts = url.pathname.split("/").filter((part2) => part2 !== "");
2631
2986
  if (host === "youtu.be") {
2632
2987
  const id = parts[0];
2633
2988
  return parts.length === 1 && id !== void 0 && YOUTUBE_ID.test(id) ? { provider: "youtube", id } : null;
@@ -2650,12 +3005,12 @@ function embedSrc(video, muted) {
2650
3005
  return video.provider === "youtube" ? `https://www.youtube-nocookie.com/embed/${video.id}?autoplay=1&rel=0&playsinline=1${muted ? "&mute=1" : ""}` : `https://player.vimeo.com/video/${video.id}?autoplay=1&dnt=1${muted ? "&muted=1" : ""}`;
2651
3006
  }
2652
3007
  function Video({ node, props, editMode }) {
2653
- const [loaded, setLoaded] = useState4(false);
3008
+ const [loaded, setLoaded] = useState5(false);
2654
3009
  const video = parseVideoUrl(str(props.url) ?? "");
2655
- return /* @__PURE__ */ jsxs20(Fragment16, { children: [
2656
- /* @__PURE__ */ jsx30(BasicStyles, {}),
2657
- /* @__PURE__ */ jsx30(WidgetStyle, { css: enumCss(node, RULES3) }),
2658
- video === null ? /* @__PURE__ */ jsx30(Placeholder, { editMode, children: "Paste a YouTube or Vimeo link" }) : /* @__PURE__ */ jsx30("div", { className: "tb-b-video", "data-provider": video.provider, children: loaded && !editMode ? /* @__PURE__ */ jsx30(
3010
+ return /* @__PURE__ */ jsxs23(Fragment19, { children: [
3011
+ /* @__PURE__ */ jsx33(BasicStyles, {}),
3012
+ /* @__PURE__ */ jsx33(WidgetStyle, { css: enumCss(node, RULES3) }),
3013
+ video === null ? /* @__PURE__ */ jsx33(Placeholder, { editMode, children: "Paste a YouTube or Vimeo link" }) : /* @__PURE__ */ jsx33("div", { className: "tb-b-video", "data-provider": video.provider, children: loaded && !editMode ? /* @__PURE__ */ jsx33(
2659
3014
  "iframe",
2660
3015
  {
2661
3016
  src: embedSrc(video, props.autoplayMuted === true),
@@ -2664,97 +3019,1525 @@ function Video({ node, props, editMode }) {
2664
3019
  referrerPolicy: "strict-origin-when-cross-origin",
2665
3020
  sandbox: "allow-scripts allow-same-origin allow-presentation allow-popups"
2666
3021
  }
2667
- ) : /* @__PURE__ */ jsx30("button", { type: "button", className: "tb-b-play", "aria-label": "Play video", onClick: () => setLoaded(true), children: /* @__PURE__ */ jsx30("span", { children: /* @__PURE__ */ jsx30(Icon3, { name: "play", size: 28 }) }) }) })
3022
+ ) : /* @__PURE__ */ jsx33("button", { type: "button", className: "tb-b-play", "aria-label": "Play video", onClick: () => setLoaded(true), children: /* @__PURE__ */ jsx33("span", { children: /* @__PURE__ */ jsx33(Icon3, { name: "play", size: 28 }) }) }) })
2668
3023
  ] });
2669
3024
  }
2670
3025
 
2671
3026
  // src/basics/v2/announcement-v2.tsx
2672
- var announcementV2Widgets = [];
2673
-
2674
- // src/basics/v2/breadcrumbs.tsx
2675
- var breadcrumbsWidgets = [];
2676
-
2677
- // src/basics/v2/faq.tsx
2678
- var faqWidgets = [];
2679
-
2680
- // src/basics/v2/icon-list.tsx
2681
- var iconListWidgets = [];
3027
+ import { Fragment as Fragment21, createElement as createElement3, useEffect as useEffect9, useMemo, useRef as useRef3, useState as useState6 } from "react";
3028
+ import { Icon as Icon5, useSiteDesign as useSiteDesign6 } from "@usethrottle/ui";
3029
+ import { BASIC_WIDGET_DEFINITIONS as BASIC_WIDGET_DEFINITIONS2, SITE_STRING_DEFAULTS as SITE_STRING_DEFAULTS6 } from "@usethrottle/builder-schema";
2682
3030
 
2683
- // src/basics/v2/merge.ts
2684
- function mergeV2Widgets(v1, v2) {
2685
- const replacement = /* @__PURE__ */ new Map();
2686
- for (const widget of v2) {
2687
- if (replacement.has(widget.type)) throw new Error(`Two v2 widgets of type ${widget.type}`);
2688
- replacement.set(widget.type, widget);
3031
+ // src/theme.ts
3032
+ import { SITE_FONTS, eligibleMessages, safeUrl as safeUrl12, sanitizeSiteCss } from "@usethrottle/builder-schema";
3033
+ import { PRESET_NAMES, PRESET_TOKENS } from "@usethrottle/ui/presets";
3034
+ var isRecord5 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
3035
+ var str2 = (v) => typeof v === "string" && v !== "" ? v : void 0;
3036
+ var HEX = /^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;
3037
+ var SCALE = { compact: 0.85, comfortable: 1, roomy: 1.25 };
3038
+ var PALETTE_KEYS = Object.keys(PRESET_TOKENS.clean.light);
3039
+ function palette(base, over) {
3040
+ if (!isRecord5(over)) return base;
3041
+ const out = { ...base };
3042
+ for (const key of PALETTE_KEYS) {
3043
+ const value = over[key];
3044
+ if (typeof value === "string" && HEX.test(value)) out[key] = value;
2689
3045
  }
2690
- const v1Types = new Set(v1.map((widget) => widget.type));
2691
- return [
2692
- ...v1.map((widget) => replacement.get(widget.type) ?? widget),
2693
- ...[...replacement.values()].filter((widget) => !v1Types.has(widget.type))
2694
- ];
3046
+ return out;
2695
3047
  }
2696
-
2697
- // src/basics/v2/menu-v2.tsx
2698
- var menuV2Widgets = [];
2699
-
2700
- // src/basics/v2/quote.tsx
2701
- var quoteWidgets = [];
2702
-
2703
- // src/basics/v2/rich-content.tsx
2704
- var richContentWidgets = [];
2705
-
2706
- // src/basics/v2/svg.tsx
2707
- var svgWidgets = [];
2708
-
2709
- // src/basics/index.ts
2710
- var BASIC_COMPONENTS = {
2711
- "basic.heading": Heading,
2712
- "basic.text": Text,
2713
- "basic.image": Image,
2714
- "basic.button": Button,
2715
- "basic.spacer": Spacer,
2716
- "basic.divider": Divider,
2717
- "basic.video": Video,
2718
- "basic.logo": Logo,
2719
- "basic.menu": Menu,
2720
- "basic.announcement": Announcement,
2721
- "basic.copyright": Copyright,
2722
- "basic.countdown": Countdown
3048
+ function themeTokens(settings) {
3049
+ const theme = isRecord5(settings.theme) ? settings.theme : {};
3050
+ const preset = PRESET_NAMES.includes(theme.preset) ? theme.preset : "clean";
3051
+ const customized = theme.customized === true;
3052
+ const base = PRESET_TOKENS[preset];
3053
+ const colorScheme = theme.colorScheme === "light" || theme.colorScheme === "dark" ? theme.colorScheme : "auto";
3054
+ if (!customized) return { preset, customized, tokens: base, colorScheme };
3055
+ const fonts = isRecord5(theme.fonts) ? theme.fonts : {};
3056
+ return {
3057
+ preset,
3058
+ customized,
3059
+ colorScheme,
3060
+ tokens: {
3061
+ light: palette(base.light, theme.light),
3062
+ dark: palette(base.dark, theme.dark),
3063
+ fonts: {
3064
+ heading: str2(fonts.heading) ?? base.fonts.heading,
3065
+ body: str2(fonts.body) ?? base.fonts.body,
3066
+ mono: str2(fonts.mono) ?? base.fonts.mono
3067
+ },
3068
+ radius: typeof theme.radius === "number" && theme.radius >= 0 && theme.radius <= 32 ? theme.radius : base.radius,
3069
+ spacingScale: theme.spacingScale === "compact" || theme.spacingScale === "roomy" ? theme.spacingScale : base.spacingScale
3070
+ }
3071
+ };
3072
+ }
3073
+ var GENERIC = { serif: "serif", sans: "sans-serif", mono: "monospace", display: "sans-serif" };
3074
+ var SYSTEM_STACK = {
3075
+ "system-sans": 'system-ui, -apple-system, "Segoe UI", sans-serif',
3076
+ "system-serif": 'Georgia, "Times New Roman", serif',
3077
+ "system-mono": "ui-monospace, SFMono-Regular, Menlo, monospace"
2723
3078
  };
2724
- var v1Widgets = BASIC_WIDGET_DEFINITIONS2.flatMap(
2725
- (definition) => Object.hasOwn(BASIC_COMPONENTS, definition.type) ? [{ ...definition, Component: BASIC_COMPONENTS[definition.type] }] : []
2726
- );
2727
- var widgets = mergeV2Widgets(v1Widgets, [
2728
- ...faqWidgets,
2729
- ...richContentWidgets,
2730
- ...breadcrumbsWidgets,
2731
- ...svgWidgets,
2732
- ...iconListWidgets,
2733
- ...quoteWidgets,
2734
- ...menuV2Widgets,
2735
- ...announcementV2Widgets
2736
- ]);
3079
+ function fontStack(family) {
3080
+ if (Object.hasOwn(SYSTEM_STACK, family)) return SYSTEM_STACK[family];
3081
+ const known = SITE_FONTS.find((f) => f.family === family);
3082
+ if (known === void 0 || !/^[A-Za-z0-9 ]{1,60}$/.test(family)) return SYSTEM_STACK["system-sans"];
3083
+ return `"${family}", ${Object.hasOwn(GENERIC, known.category) ? GENERIC[known.category] : "sans-serif"}`;
3084
+ }
3085
+ function variables(p) {
3086
+ return {
3087
+ colorPrimary: p.colorPrimary,
3088
+ colorPrimaryForeground: p.colorPrimaryForeground,
3089
+ colorBackground: p.colorBackground,
3090
+ colorSurface: p.colorSurface,
3091
+ colorForeground: p.colorForeground,
3092
+ colorMuted: p.colorMuted,
3093
+ colorMutedForeground: p.colorMutedForeground,
3094
+ colorBorder: p.colorBorder,
3095
+ colorBorderControl: p.colorBorderControl,
3096
+ colorSuccess: p.colorSuccess,
3097
+ colorWarning: p.colorWarning,
3098
+ colorDanger: p.colorDanger
3099
+ };
3100
+ }
3101
+ function appearanceOf(settings) {
3102
+ const { tokens, colorScheme } = themeTokens(settings);
3103
+ return {
3104
+ theme: colorScheme,
3105
+ variables: {
3106
+ ...variables(tokens.light),
3107
+ fontFamily: fontStack(tokens.fonts.body),
3108
+ borderRadius: `${String(tokens.radius)}px`
3109
+ },
3110
+ darkVariables: variables(tokens.dark)
3111
+ };
3112
+ }
3113
+ var kebab = (key) => key.replace(/^color/, "").replace(/([a-z])([A-Z])/g, "$1-$2").replace(/^([A-Z])/, (c) => c.toLowerCase()).toLowerCase();
3114
+ function colourDecls(p) {
3115
+ return PALETTE_KEYS.map((key) => `--tb-color-${kebab(key)}:${p[key]}`).join(";");
3116
+ }
3117
+ function themeCss(settings, options = {}) {
3118
+ const { tokens, colorScheme } = themeTokens(settings);
3119
+ const heading = options.hostFont === true ? "" : `--throttle-font-family-heading:${fontStack(tokens.fonts.heading)};`;
3120
+ const light = `:root{--tb-scale:${String(SCALE[tokens.spacingScale])};${heading}${colourDecls(tokens.light)}}`;
3121
+ const dark = colourDecls(tokens.dark);
3122
+ if (colorScheme === "light") return light;
3123
+ if (colorScheme === "dark") return `${light}:root{${dark}}`;
3124
+ return `${light}@media (prefers-color-scheme:dark){:root{${dark}}}`;
3125
+ }
3126
+ function customCssOf(settings, mediaOrigin = "") {
3127
+ const theme = isRecord5(settings.theme) ? settings.theme : {};
3128
+ const css = theme.customCss;
3129
+ if (typeof css !== "string" || css.trim() === "") return "";
3130
+ return sanitizeSiteCss(css, { mediaOrigin }).css;
3131
+ }
3132
+ var CUSTOM_CSS_INLINE_MAX_BYTES = 4096;
3133
+ function customCssDeliveryOf(settings, answerTheme, mediaOrigin = "") {
3134
+ const theme = isRecord5(settings.theme) ? settings.theme : {};
3135
+ const raw = typeof theme.customCss === "string" ? theme.customCss : "";
3136
+ const candidate = isRecord5(answerTheme) ? answerTheme.customCssHref : void 0;
3137
+ const href = typeof candidate === "string" && /^https:\/\/[^\s/\\]+\/[^\s\\]*$/iu.test(candidate) && safeUrl12(candidate, "href", { mediaOrigin: "" }) !== null && new URL(candidate).pathname.includes("/v1/css/") ? candidate : void 0;
3138
+ const inline2 = customCssOf(settings, mediaOrigin);
3139
+ const small = new TextEncoder().encode(inline2).length <= CUSTOM_CSS_INLINE_MAX_BYTES;
3140
+ if (href !== void 0 && raw.trim() === "") return { inline: "", href };
3141
+ if (href !== void 0 && inline2 !== "" && !small) return { inline: "", href };
3142
+ return { inline: inline2 };
3143
+ }
3144
+ function customCssSheet(css) {
3145
+ return css === "" ? "" : `@layer throttle,throttle-custom;@layer throttle-custom{${css}}`;
3146
+ }
3147
+ function makeResolveLink(settings, packs) {
3148
+ const routes = isRecord5(settings.routes) ? settings.routes : {};
3149
+ const pageRoute = str2(routes.page) ?? "/pages/{handle}";
3150
+ return (target2) => {
3151
+ for (const pack of packs) {
3152
+ const href = pack.linkTargets?.resolve(target2) ?? null;
3153
+ if (href !== null) return safeUrl12(href, "href", { mediaOrigin: "" });
3154
+ }
3155
+ if (target2.kind === "url") return safeUrl12(target2.href, "href", { mediaOrigin: "" });
3156
+ if (typeof target2.href === "string") return safeUrl12(target2.href, "href", { mediaOrigin: "" });
3157
+ if (target2.kind === "page") {
3158
+ const slug2 = str2(target2.slug) ?? str2(target2.handle);
3159
+ if (slug2 !== void 0 && /^[A-Za-z0-9._~-]{1,200}$/.test(slug2)) {
3160
+ return safeUrl12(pageRoute.replace("{handle}", slug2), "href", { mediaOrigin: "" });
3161
+ }
3162
+ }
3163
+ return null;
3164
+ };
3165
+ }
3166
+ var MENU_KINDS = /* @__PURE__ */ new Set(["category", "collection", "product", "page", "search", "url"]);
3167
+ function menuItems(items, resolve, depth = 0) {
3168
+ if (!Array.isArray(items) || depth > 3) return [];
3169
+ const out = [];
3170
+ for (const item of items) {
3171
+ if (!isRecord5(item) || !isRecord5(item.target) || typeof item.target.kind !== "string") continue;
3172
+ const label = str2(item.label);
3173
+ const href = resolve(item.target);
3174
+ if (label === void 0 || href === null) continue;
3175
+ const kind = MENU_KINDS.has(item.target.kind) ? item.target.kind : void 0;
3176
+ const children = menuItems(item.children, resolve, depth + 1);
3177
+ out.push({
3178
+ label,
3179
+ href,
3180
+ ...kind === void 0 ? {} : { kind },
3181
+ ...children.length === 0 ? {} : { children }
3182
+ });
3183
+ }
3184
+ return out;
3185
+ }
3186
+ function localizedText(v, locale) {
3187
+ if (!isRecord5(v)) return str2(v);
3188
+ if (locale !== void 0 && Object.prototype.hasOwnProperty.call(v, locale)) {
3189
+ const own = str2(v[locale]);
3190
+ if (own !== void 0) return own;
3191
+ }
3192
+ return Object.values(v).map(str2).find((s) => s !== void 0);
3193
+ }
3194
+ var DEVICES4 = ["desktop", "tablet", "phone"];
3195
+ function normalizeMessages(messages) {
3196
+ const out = [];
3197
+ messages.forEach((m, index) => {
3198
+ if (!isRecord5(m)) return;
3199
+ const pages = isRecord5(m.pages) ? m.pages : {};
3200
+ out.push({
3201
+ ...m,
3202
+ id: str2(m.id) ?? `m${String(index)}`,
3203
+ target: isRecord5(m.target) ? m.target : null,
3204
+ startsAt: str2(m.startsAt) ?? null,
3205
+ endsAt: str2(m.endsAt) ?? null,
3206
+ audience: m.audience === "guest" || m.audience === "signed-in" ? m.audience : "all",
3207
+ devices: Array.isArray(m.devices) ? m.devices.filter((d) => DEVICES4.some((x) => x === d)) : [...DEVICES4],
3208
+ pages: {
3209
+ mode: pages.mode === "include" || pages.mode === "exclude" ? pages.mode : "all",
3210
+ list: Array.isArray(pages.list) ? pages.list.filter((p) => typeof p === "string") : []
3211
+ }
3212
+ });
3213
+ });
3214
+ return out;
3215
+ }
3216
+ function eligibleOnAnyDevice(messages, now, audience, page) {
3217
+ const ids = /* @__PURE__ */ new Set();
3218
+ for (const device of DEVICES4) for (const m of eligibleMessages(messages, { now, device, audience, page })) ids.add(m.id);
3219
+ return messages.filter((m) => ids.has(m.id));
3220
+ }
3221
+ function serverMessages(messages, now, page) {
3222
+ return eligibleOnAnyDevice(messages, now, "all", page);
3223
+ }
3224
+ var assetUrl = (v, mediaOrigin) => {
3225
+ const raw = typeof v === "string" ? v : isRecord5(v) ? v.url : void 0;
3226
+ return typeof raw === "string" ? safeUrl12(raw, "src", { mediaOrigin }) ?? void 0 : void 0;
3227
+ };
3228
+ function partClassesOf(settings) {
3229
+ const theme = isRecord5(settings.theme) ? settings.theme : {};
3230
+ const advanced = isRecord5(theme.advanced) ? theme.advanced : {};
3231
+ if (!isRecord5(advanced.partClasses)) return {};
3232
+ const entries2 = Object.entries(advanced.partClasses).filter((e) => typeof e[1] === "string" && e[1] !== "");
3233
+ return entries2.length === 0 ? {} : { partClasses: Object.fromEntries(entries2) };
3234
+ }
3235
+ function siteDesignOf(settings, resolve, pageOutlet, mediaOrigin, locale, now = Date.now()) {
3236
+ const { preset, customized, tokens, colorScheme } = themeTokens(settings);
3237
+ const brand = isRecord5(settings.brand) ? settings.brand : {};
3238
+ const logo = isRecord5(brand.logo) ? brand.logo : {};
3239
+ const light = assetUrl(logo.light, mediaOrigin);
3240
+ const dark = assetUrl(logo.dark, mediaOrigin);
3241
+ const favicon = assetUrl(brand.favicon, mediaOrigin);
3242
+ const menus = isRecord5(settings.menus) ? Object.fromEntries(Object.entries(settings.menus).map(([name, items]) => [name, menuItems(items, resolve)])) : {};
3243
+ const rawAnnouncement = isRecord5(settings.announcement) ? settings.announcement : null;
3244
+ const messages = rawAnnouncement !== null && Array.isArray(rawAnnouncement.messages) ? rawAnnouncement.messages : null;
3245
+ const currentMessage = messages === null ? null : serverMessages(normalizeMessages(messages), now, {})[0] ?? null;
3246
+ const announcement = rawAnnouncement === null || messages === null ? rawAnnouncement : { ...rawAnnouncement, message: currentMessage?.text, target: currentMessage?.target };
3247
+ const message = announcement === null ? void 0 : localizedText(announcement.message, locale);
3248
+ const announcementHref = announcement !== null && isRecord5(announcement.target) && typeof announcement.target.kind === "string" ? resolve(announcement.target) : null;
3249
+ const strings = isRecord5(settings.strings) ? Object.fromEntries(Object.entries(settings.strings).filter((entry) => typeof entry[1] === "string")) : {};
3250
+ const seo = isRecord5(settings.seo) ? settings.seo : {};
3251
+ const routes = isRecord5(settings.routes) ? settings.routes : {};
3252
+ const connections = isRecord5(settings.connections) ? settings.connections : {};
3253
+ const shareImage = assetUrl(seo.shareImage, mediaOrigin);
3254
+ const titleTemplate = str2(seo.titleTemplate);
3255
+ const defaultDescription = str2(seo.defaultDescription);
3256
+ const pageRoute = str2(routes.page);
3257
+ return {
3258
+ source: "builder",
3259
+ theme: { preset, customized, colorScheme, ...customized ? { values: tokens } : {}, ...partClassesOf(settings) },
3260
+ brand: {
3261
+ ...str2(brand.storeName) === void 0 ? {} : { storeName: str2(brand.storeName) },
3262
+ logo: light === void 0 && dark === void 0 ? null : { ...light === void 0 ? {} : { light }, ...dark === void 0 ? {} : { dark } },
3263
+ favicon: favicon ?? null
3264
+ },
3265
+ menus,
3266
+ announcement: announcement !== null && announcement.enabled === true && message !== void 0 ? { message, ...announcementHref === null ? {} : { href: announcementHref } } : null,
3267
+ strings,
3268
+ seo: {
3269
+ ...titleTemplate === void 0 ? {} : { titleTemplate },
3270
+ ...defaultDescription === void 0 ? {} : { defaultDescription },
3271
+ ...shareImage === void 0 ? {} : { shareImage }
3272
+ },
3273
+ ...pageRoute === void 0 ? {} : { routes: { page: pageRoute } },
3274
+ connections: {
3275
+ throttlePublishableKey: typeof connections.throttlePublishableKey === "string" ? connections.throttlePublishableKey : null
3276
+ },
3277
+ ...pageOutlet === void 0 ? {} : { pageOutlet }
3278
+ };
3279
+ }
3280
+
3281
+ // src/basics/v2/menu-v2.tsx
3282
+ import { useEffect as useEffect8, useId as useId2 } from "react";
3283
+ import { Icon as Icon4, useSiteDesign as useSiteDesign5 } from "@usethrottle/ui";
3284
+ import { MB_BASIC_WIDGET_DEFINITIONS, SITE_STRING_DEFAULTS as SITE_STRING_DEFAULTS5, expandMenu, safeUrl as safeUrl13, sectionNodeSchema as sectionNodeSchema2 } from "@usethrottle/builder-schema";
3285
+
3286
+ // src/interactions/menu-runtime.ts
3287
+ var holds3 = 0;
3288
+ var release2;
3289
+ var ITEM = "[data-tb-i]";
3290
+ var hovers = () => window.matchMedia?.("(hover:none)").matches !== true;
3291
+ function toggleOf(item) {
3292
+ return item.querySelector(":scope > [data-tb-t]");
3293
+ }
3294
+ function setItem(item, open) {
3295
+ if (open) item.setAttribute("data-open", "true");
3296
+ else item.removeAttribute("data-open");
3297
+ toggleOf(item)?.setAttribute("aria-expanded", String(open));
3298
+ item.querySelector(":scope > [data-nav-panel]")?.toggleAttribute("hidden", !open);
3299
+ }
3300
+ function closeOthers(keep) {
3301
+ for (const item of document.querySelectorAll(`${ITEM}[data-open]`)) {
3302
+ if (keep === null || !item.contains(keep)) setItem(item, false);
3303
+ }
3304
+ }
3305
+ var NAV_TOP = "[data-nav-top]";
3306
+ var PANEL = "[data-nav-panel]";
3307
+ function navKey(event, el) {
3308
+ const entry = el.closest(NAV_TOP);
3309
+ if (entry === null) return false;
3310
+ const focus = (links, at2) => links[(at2 + links.length) % links.length]?.focus();
3311
+ const top = entry.querySelector(":scope > a");
3312
+ if (event.key === "Escape" && entry.hasAttribute("data-open")) {
3313
+ event.preventDefault();
3314
+ setItem(entry, false);
3315
+ top?.focus();
3316
+ return true;
3317
+ }
3318
+ const panel = el.closest(PANEL);
3319
+ if (panel !== null) {
3320
+ if (event.key !== "ArrowDown" && event.key !== "ArrowUp") return false;
3321
+ event.preventDefault();
3322
+ const links = [...panel.querySelectorAll("a")];
3323
+ focus(links, links.indexOf(el) + (event.key === "ArrowDown" ? 1 : -1));
3324
+ return true;
3325
+ }
3326
+ if (el !== top) return false;
3327
+ const list2 = entry.parentElement;
3328
+ const tops = [...list2?.querySelectorAll(":scope > li > a") ?? []];
3329
+ const at = tops.indexOf(el);
3330
+ const rtl = list2 !== null && getComputedStyle(list2).direction === "rtl";
3331
+ const forward = rtl ? "ArrowLeft" : "ArrowRight";
3332
+ const back = rtl ? "ArrowRight" : "ArrowLeft";
3333
+ if (event.key === forward || event.key === back) focus(tops, at + (event.key === forward ? 1 : -1));
3334
+ else if (event.key === "Home") focus(tops, 0);
3335
+ else if (event.key === "End") focus(tops, -1);
3336
+ else if (event.key === "ArrowDown" && entry.querySelector(":scope > " + PANEL) !== null) {
3337
+ if (!entry.hasAttribute("data-open")) setItem(entry, true);
3338
+ entry.querySelector(":scope > " + PANEL + " a")?.focus();
3339
+ } else return false;
3340
+ event.preventDefault();
3341
+ return true;
3342
+ }
3343
+ var drawerToggle = (nav) => nav.querySelector(":scope > [data-tb-drawer]");
3344
+ function setDrawer(nav, open) {
3345
+ nav.setAttribute("data-open", String(open));
3346
+ drawerToggle(nav)?.setAttribute("aria-expanded", String(open));
3347
+ const list2 = nav.querySelector(":scope > ul");
3348
+ if (list2 === null) return;
3349
+ if (open) {
3350
+ list2.setAttribute("role", "dialog");
3351
+ list2.setAttribute("aria-modal", "true");
3352
+ const label = nav.getAttribute("aria-label");
3353
+ if (label !== null) list2.setAttribute("aria-label", label);
3354
+ focusablesOf(list2)[0]?.focus();
3355
+ } else {
3356
+ list2.removeAttribute("role");
3357
+ list2.removeAttribute("aria-modal");
3358
+ list2.removeAttribute("aria-label");
3359
+ }
3360
+ }
3361
+ var target = (event) => event.target instanceof Element ? event.target : null;
3362
+ function install2() {
3363
+ const over = (event) => {
3364
+ const el = target(event);
3365
+ if (el === null || !hovers()) return;
3366
+ closeOthers(el);
3367
+ for (let item = el.closest(ITEM); item !== null; item = item.parentElement?.closest(ITEM) ?? null) setItem(item, true);
3368
+ };
3369
+ const out = (event) => {
3370
+ if (!hovers()) return;
3371
+ const to = event.relatedTarget instanceof Node ? event.relatedTarget : null;
3372
+ closeOthers(to);
3373
+ };
3374
+ const focusin = (event) => {
3375
+ const el = target(event);
3376
+ if (el === null) return;
3377
+ closeOthers(el);
3378
+ if (el.closest("[data-tb-t]") !== null || el.closest(NAV_TOP) !== null) return;
3379
+ for (let item = el.closest(ITEM); item !== null; item = item.parentElement?.closest(ITEM) ?? null) setItem(item, true);
3380
+ };
3381
+ const click = (event) => {
3382
+ const el = target(event);
3383
+ if (el === null) return;
3384
+ const opener = el.closest("[data-tb-drawer]");
3385
+ if (opener !== null) {
3386
+ const nav2 = opener.closest("nav");
3387
+ if (nav2 !== null) setDrawer(nav2, nav2.getAttribute("data-open") !== "true");
3388
+ return;
3389
+ }
3390
+ const toggle = el.closest("[data-tb-t]");
3391
+ const item = toggle?.closest(ITEM) ?? null;
3392
+ if (item !== null) {
3393
+ closeOthers(item);
3394
+ setItem(item, item.getAttribute("data-open") !== "true");
3395
+ return;
3396
+ }
3397
+ closeOthers(el);
3398
+ const nav = el.closest("nav[data-open=true]");
3399
+ if (nav !== null && el.closest("a") !== null) setDrawer(nav, false);
3400
+ };
3401
+ const keydown = (event) => {
3402
+ const el = target(event);
3403
+ const drawer = document.querySelector("nav[data-open=true]");
3404
+ if (event.key === "Tab" && drawer !== null) {
3405
+ const toggle = drawerToggle(drawer);
3406
+ const list2 = drawer.querySelector(":scope > ul");
3407
+ if (list2 !== null) trapTab(event, [...toggle === null ? [] : [toggle], ...focusablesOf(list2)]);
3408
+ return;
3409
+ }
3410
+ if (drawer === null && el !== null && navKey(event, el)) return;
3411
+ if (event.key !== "Escape") return;
3412
+ if (drawer !== null) {
3413
+ closeOthers(null);
3414
+ setDrawer(drawer, false);
3415
+ drawerToggle(drawer)?.focus();
3416
+ return;
3417
+ }
3418
+ const open = document.querySelector(`${ITEM}[data-open]`);
3419
+ if (open !== null) {
3420
+ const focusInside = el !== null && open.contains(el);
3421
+ const back = toggleOf(open);
3422
+ closeOthers(null);
3423
+ if (focusInside) back?.focus();
3424
+ }
3425
+ };
3426
+ document.addEventListener("mouseover", over);
3427
+ document.addEventListener("mouseout", out);
3428
+ document.addEventListener("focusin", focusin);
3429
+ document.addEventListener("click", click);
3430
+ document.addEventListener("keydown", keydown);
3431
+ return () => {
3432
+ document.removeEventListener("mouseover", over);
3433
+ document.removeEventListener("mouseout", out);
3434
+ document.removeEventListener("focusin", focusin);
3435
+ document.removeEventListener("click", click);
3436
+ document.removeEventListener("keydown", keydown);
3437
+ };
3438
+ }
3439
+ function startMenuRuntime() {
3440
+ if (holds3++ === 0) release2 = install2();
3441
+ let done = false;
3442
+ return () => {
3443
+ if (done) return;
3444
+ done = true;
3445
+ if (--holds3 === 0) {
3446
+ release2?.();
3447
+ release2 = void 0;
3448
+ }
3449
+ };
3450
+ }
3451
+
3452
+ // src/basics/v2/menu-v2.tsx
3453
+ import { Fragment as Fragment20, jsx as jsx34, jsxs as jsxs24 } from "react/jsx-runtime";
3454
+ var MODES = ["horizontal", "vertical", "drawer", "mega"];
3455
+ var MAX_LEVEL = 3;
3456
+ var CLASS_RE = /^[A-Za-z_][A-Za-z0-9_-]{0,63}$/;
3457
+ var SUBMENU_DEFAULT = "Show submenu for {label}";
3458
+ function localized(value, locale) {
3459
+ if (!isRecord4(value)) return str(value);
3460
+ for (const key of [locale, "en"]) {
3461
+ if (Object.hasOwn(value, key)) {
3462
+ const own = str(value[key]);
3463
+ if (own !== void 0) return own;
3464
+ }
3465
+ }
3466
+ return Object.values(value).map(str).find((s) => s !== void 0);
3467
+ }
3468
+ function makeLink(builder, own, mediaOrigin) {
3469
+ const targets = builder?.linkTargets;
3470
+ const fallback = own ?? builder?.resolveLink;
3471
+ return (target2) => {
3472
+ if (target2.kind === "url") return safeUrl13(target2.href, "href", { mediaOrigin });
3473
+ if (targets !== void 0 && typeof target2.id === "string") {
3474
+ const key = `${String(target2.kind)}:${target2.id}`;
3475
+ if (Object.hasOwn(targets, key)) {
3476
+ const known = targets[key];
3477
+ return typeof known === "string" ? safeUrl13(known, "href", { mediaOrigin }) : null;
3478
+ }
3479
+ }
3480
+ const raw = fallback?.(target2) ?? null;
3481
+ return raw === null ? null : safeUrl13(raw, "href", { mediaOrigin });
3482
+ };
3483
+ }
3484
+ function megaOf(value, locale) {
3485
+ if (!isRecord4(value) || value.enabled !== true) return void 0;
3486
+ const columns = typeof value.columns === "number" ? Math.min(6, Math.max(2, Math.round(value.columns))) : 3;
3487
+ const f = value.featured;
3488
+ let featured = null;
3489
+ if (isRecord4(f) && f.kind === "section" && typeof f.id === "string") featured = { kind: "section", id: f.id };
3490
+ else if (isRecord4(f) && f.kind === "image" && typeof f.asset === "string") {
3491
+ featured = { kind: "image", asset: f.asset, link: isRecord4(f.link) ? f.link : null, caption: localized(f.caption, locale) ?? "" };
3492
+ }
3493
+ return { columns, featured };
3494
+ }
3495
+ function build(raw, level, b) {
3496
+ if (!Array.isArray(raw)) return [];
3497
+ const out = [];
3498
+ raw.forEach((entry, index) => {
3499
+ if (!isRecord4(entry) || !isRecord4(entry.target)) return;
3500
+ const target2 = entry.target;
3501
+ const label = localized(entry.label, b.r.locale);
3502
+ if (label === void 0) return;
3503
+ out.push({
3504
+ key: typeof entry.id === "string" ? entry.id : String(index),
3505
+ label,
3506
+ href: target2.kind === "category" && typeof entry.url === "string" ? safeUrl13(entry.url, "href", { mediaOrigin: b.r.mediaOrigin }) : b.r.link(target2),
3507
+ newTab: entry.newTab === true,
3508
+ classes: Array.isArray(entry.cssClass) ? entry.cssClass.filter((c) => typeof c === "string" && CLASS_RE.test(c)) : [],
3509
+ description: localized(entry.description, b.r.locale),
3510
+ badge: localized(entry.badge, b.r.locale),
3511
+ // Mega is only for a top-level item of the header menu, in mega mode.
3512
+ mega: b.mega && level === 1 && b.menu === "header" ? megaOf(entry.mega, b.r.locale) : void 0,
3513
+ children: level < MAX_LEVEL ? build(entry.children, level + 1, b) : [],
3514
+ ...target2.kind === "category" && typeof entry.handle === "string" ? { handle: entry.handle } : {}
3515
+ });
3516
+ });
3517
+ return out;
3518
+ }
3519
+ function fromDesign(items, level, r) {
3520
+ return items.map((item, index) => ({
3521
+ key: String(index),
3522
+ label: item.label,
3523
+ href: safeUrl13(item.href, "href", { mediaOrigin: r.mediaOrigin }),
3524
+ newTab: false,
3525
+ classes: [],
3526
+ description: void 0,
3527
+ badge: void 0,
3528
+ mega: void 0,
3529
+ children: level < MAX_LEVEL && item.children !== void 0 ? fromDesign(item.children, level + 1, r) : []
3530
+ }));
3531
+ }
3532
+ function Anchor({ item }) {
3533
+ return item.href === null ? /* @__PURE__ */ jsx34("span", { className: "tb-mm-text", children: item.label }) : /* @__PURE__ */ jsx34("a", { href: item.href, ...item.newTab ? { target: "_blank", rel: "noopener noreferrer" } : {}, children: item.label });
3534
+ }
3535
+ var Extras = ({ item, describe }) => /* @__PURE__ */ jsxs24(Fragment20, { children: [
3536
+ item.badge === void 0 ? null : /* @__PURE__ */ jsx34("span", { className: "tb-mm-badge", children: item.badge }),
3537
+ describe && item.description !== void 0 ? /* @__PURE__ */ jsx34("span", { className: "tb-mm-desc", children: item.description }) : null
3538
+ ] });
3539
+ function FeaturedPanel({ featured, label, ctx }) {
3540
+ const { builder, props } = ctx;
3541
+ const site = builder?.site;
3542
+ if (builder === null || site === void 0 || site.status !== "ok") return null;
3543
+ const parts = [site.header, site.footer];
3544
+ if (featured.kind === "section") {
3545
+ let answer;
3546
+ for (const part2 of parts) {
3547
+ const all2 = part2.savedSections;
3548
+ if (answer === void 0 && all2 !== void 0 && Object.hasOwn(all2, featured.id)) answer = all2[featured.id];
3549
+ }
3550
+ const parsed2 = answer === void 0 ? null : sectionNodeSchema2.safeParse(answer.section);
3551
+ if (answer === void 0 || parsed2 === null || !parsed2.success) return null;
3552
+ const assets = { ...site.footer.assets, ...site.header.assets };
3553
+ return /* @__PURE__ */ jsx34("div", { className: "tb-mm-feat", children: /* @__PURE__ */ jsx34(
3554
+ BuilderRenderer,
3555
+ {
3556
+ document: { schemaVersion: 1, sections: [parsed2.data] },
3557
+ registry: builder.registry,
3558
+ data: {},
3559
+ locale: props.locale,
3560
+ assets,
3561
+ mediaOrigin: props.mediaOrigin,
3562
+ interactive: props.interactive,
3563
+ resolveLink: props.resolveLink ?? builder.resolveLink
3564
+ }
3565
+ ) });
3566
+ }
3567
+ let asset;
3568
+ for (const part2 of parts) {
3569
+ if (asset === void 0 && Object.hasOwn(part2.assets, featured.asset)) asset = part2.assets[featured.asset];
3570
+ }
3571
+ if (!isFrozenAsset(asset)) return null;
3572
+ const href = featured.link === null ? null : makeLink(builder, props.resolveLink, props.mediaOrigin)(featured.link);
3573
+ const image = /* @__PURE__ */ jsx34(AssetImage, { asset, mediaOrigin: props.mediaOrigin, alt: href === null ? featured.caption : featured.caption || label });
3574
+ return /* @__PURE__ */ jsxs24("figure", { className: "tb-mm-feat", children: [
3575
+ href === null ? image : /* @__PURE__ */ jsx34("a", { href, children: image }),
3576
+ featured.caption === "" ? null : /* @__PURE__ */ jsx34("figcaption", { children: featured.caption })
3577
+ ] });
3578
+ }
3579
+ function List2({ items, top, ctx }) {
3580
+ if (items.length === 0) return null;
3581
+ return /* @__PURE__ */ jsx34("ul", { ...top === void 0 ? { className: "tb-mm-sub" } : { id: top.id, className: "tb-mm-list" }, children: items.map((item) => /* @__PURE__ */ jsx34(Entry, { item, level: top === void 0 ? 2 : 1, ctx }, item.key)) });
3582
+ }
3583
+ function Entry({ item, level, ctx }) {
3584
+ const hasPanel = item.mega !== void 0 && (item.children.length > 0 || item.mega.featured !== null);
3585
+ const sub = item.children.length > 0 || hasPanel;
3586
+ const toggle = sub && level === 1 && ctx.mode !== "vertical";
3587
+ const cls = ["tb-mm-i", ...item.classes].join(" ");
3588
+ const subId = `${ctx.listId}-${item.key.replace(/[^A-Za-z0-9_-]/g, "_")}`;
3589
+ let below = null;
3590
+ if (hasPanel && item.mega !== void 0) {
3591
+ below = /* @__PURE__ */ jsxs24("div", { id: subId, className: "tb-mm-panel", style: { "--tb-mm-cols": item.mega.columns }, children: [
3592
+ item.children.length === 0 ? null : /* @__PURE__ */ jsx34("ul", { className: "tb-mm-cols", children: item.children.map((child) => /* @__PURE__ */ jsxs24("li", { className: "tb-mm-col", children: [
3593
+ /* @__PURE__ */ jsx34(Anchor, { item: child }),
3594
+ /* @__PURE__ */ jsx34(Extras, { item: child, describe: true }),
3595
+ /* @__PURE__ */ jsx34(List2, { items: child.children, ctx })
3596
+ ] }, child.key)) }),
3597
+ item.mega.featured === null ? null : /* @__PURE__ */ jsx34(FeaturedPanel, { featured: item.mega.featured, label: item.label, ctx })
3598
+ ] });
3599
+ } else if (sub) {
3600
+ below = /* @__PURE__ */ jsx34("ul", { id: subId, className: "tb-mm-sub", children: item.children.map((child) => /* @__PURE__ */ jsx34(Entry, { item: child, level: 2, ctx }, child.key)) });
3601
+ }
3602
+ return /* @__PURE__ */ jsxs24("li", { className: cls, ...sub && level === 1 ? { "data-tb-i": "" } : {}, children: [
3603
+ /* @__PURE__ */ jsx34(Anchor, { item }),
3604
+ /* @__PURE__ */ jsx34(Extras, { item, describe: false }),
3605
+ toggle ? /* @__PURE__ */ jsx34(
3606
+ "button",
3607
+ {
3608
+ type: "button",
3609
+ className: "tb-mm-t",
3610
+ "data-tb-t": "",
3611
+ "aria-expanded": "false",
3612
+ "aria-controls": subId,
3613
+ "aria-label": ctx.submenu.replace("{label}", () => item.label),
3614
+ children: /* @__PURE__ */ jsx34("svg", { viewBox: "0 0 24 24", width: "16", height: "16", "aria-hidden": "true", focusable: "false", children: /* @__PURE__ */ jsx34("path", { d: "M6 9l6 6 6-6", fill: "none", stroke: "currentColor", strokeWidth: "2" }) })
3615
+ }
3616
+ ) : null,
3617
+ below
3618
+ ] });
3619
+ }
3620
+ function MenuRuntime() {
3621
+ useEffect8(() => startMenuRuntime(), []);
3622
+ return null;
3623
+ }
3624
+ var part = (key, extra) => ({
3625
+ className: [`tsf-${key}`, extra].filter(Boolean).join(" "),
3626
+ "data-throttle-part": key
3627
+ });
3628
+ function StorefrontNav({ items, label, listId, ctx, className, menu }) {
3629
+ const categories = items.some((item) => item.handle !== void 0);
3630
+ const handle = (item, parent) => item.handle === void 0 ? {} : { "data-category-handle": item.handle, ...categories ? { "data-category-parent": parent } : {} };
3631
+ const link = (item) => item.href === null ? /* @__PURE__ */ jsx34("span", { ...part("category-nav-link", "tb-mm-text"), children: item.label }) : /* @__PURE__ */ jsx34("a", { ...part("category-nav-link"), href: item.href, ...item.newTab ? { target: "_blank", rel: "noopener noreferrer" } : {}, children: item.label });
3632
+ return /* @__PURE__ */ jsx34("nav", { ...part("category-nav", className), "aria-label": label, ...categories ? {} : { "data-menu": menu }, children: /* @__PURE__ */ jsx34("ul", { ...part("category-nav-list"), children: items.map((item) => {
3633
+ const sub = item.children.length > 0;
3634
+ const panelId = `${listId}-${item.key.replace(/[^A-Za-z0-9_-]/g, "_")}`;
3635
+ return /* @__PURE__ */ jsxs24("li", { ...part("category-nav-item", item.classes.join(" ")), "data-nav-top": "", ...sub ? { "data-tb-i": "" } : {}, ...handle(item, ""), children: [
3636
+ link(item),
3637
+ sub ? /* @__PURE__ */ jsx34(
3638
+ "button",
3639
+ {
3640
+ type: "button",
3641
+ ...part("category-nav-toggle"),
3642
+ "data-tb-t": "",
3643
+ "aria-expanded": "false",
3644
+ "aria-controls": panelId,
3645
+ "aria-label": ctx.submenu.replace("{label}", () => item.label),
3646
+ children: /* @__PURE__ */ jsx34(Icon4, { name: "chevron-down", size: 14 })
3647
+ }
3648
+ ) : null,
3649
+ sub ? /* @__PURE__ */ jsx34("ul", { ...part("category-nav-panel"), id: panelId, "data-nav-panel": "", hidden: true, children: item.children.map((child) => /* @__PURE__ */ jsx34("li", { ...part("category-nav-child", child.classes.join(" ")), ...handle(child, item.handle ?? ""), children: link(child) }, child.key)) }) : null
3650
+ ] }, item.key);
3651
+ }) }) });
3652
+ }
3653
+ function Nav({ items, label, listId, ctx, className, menu }) {
3654
+ if (ctx.variant === "storefront") return /* @__PURE__ */ jsx34(StorefrontNav, { items, label, listId, ctx, menu, ...className === void 0 ? {} : { className } });
3655
+ const full = { ...ctx, listId };
3656
+ return /* @__PURE__ */ jsxs24("nav", { className: `tb-mm tb-mm--${ctx.mode}${className === void 0 ? "" : ` ${className}`}`, "aria-label": label, children: [
3657
+ ctx.mode === "drawer" && /* @__PURE__ */ jsx34("button", { type: "button", className: "tb-mm-drawer", "data-tb-drawer": "", "aria-expanded": "false", "aria-controls": listId, children: /* @__PURE__ */ jsx34(Icon4, { name: "menu", size: 24, label }) }),
3658
+ /* @__PURE__ */ jsx34(List2, { items, top: { id: listId }, ctx: full })
3659
+ ] });
3660
+ }
3661
+ function MenuV2(props) {
3662
+ const { props: settings, data, mediaOrigin, editMode, locale } = props;
3663
+ const builder = useBuilder();
3664
+ const design = useSiteDesign5();
3665
+ const listId = useId2();
3666
+ const mobileId = useId2();
3667
+ const name = str(settings.menu) ?? "header";
3668
+ const mode = oneOf(settings.mode, MODES, "horizontal");
3669
+ const r = { mediaOrigin, locale, link: makeLink(builder, props.resolveLink, mediaOrigin) };
3670
+ const categories = Array.isArray(data.categories) ? data.categories : [];
3671
+ const forMenu = (menu, raw) => build(expandMenu(Array.isArray(raw) ? raw : [], categories).menu, 1, { r, menu, mega: mode === "mega" });
3672
+ let items = [];
3673
+ let mobile = [];
3674
+ const site = builder?.site;
3675
+ const menus = site?.status === "ok" && isRecord4(site.settings.menus) ? site.settings.menus : void 0;
3676
+ if (menus !== void 0) {
3677
+ items = Object.hasOwn(menus, name) ? forMenu(name, menus[name]) : [];
3678
+ if (name === "header" && Object.hasOwn(menus, "mobile")) mobile = forMenu("mobile", menus.mobile);
3679
+ } else if (design?.menus !== void 0 && Object.hasOwn(design.menus, name)) {
3680
+ items = fromDesign(design.menus[name] ?? [], 1, r);
3681
+ }
3682
+ const word = (key, fallback) => {
3683
+ for (const strings of [site?.status === "ok" ? site.settings.strings : void 0, design?.strings]) {
3684
+ if (isRecord4(strings) && Object.hasOwn(strings, key) && str(strings[key]) !== void 0) return strings[key];
3685
+ }
3686
+ return fallback;
3687
+ };
3688
+ const label = word("nav.menu", SITE_STRING_DEFAULTS5["nav.menu"]);
3689
+ if (items.length === 0 && mobile.length === 0) {
3690
+ return /* @__PURE__ */ jsxs24(Fragment20, { children: [
3691
+ /* @__PURE__ */ jsx34(BasicStyles, {}),
3692
+ /* @__PURE__ */ jsx34(Placeholder, { editMode, children: `Menu "${name}" is empty: add links in Site settings` })
3693
+ ] });
3694
+ }
3695
+ const ctx = { builder, props, mode, variant: oneOf(settings.variant, ["default", "storefront"], "default"), submenu: word("nav.submenu", SUBMENU_DEFAULT) };
3696
+ const nameOf = (menu) => menu === "header" ? label : `${label} (${menu})`;
3697
+ return /* @__PURE__ */ jsxs24(Fragment20, { children: [
3698
+ /* @__PURE__ */ jsx34(BasicStyles, {}),
3699
+ /* @__PURE__ */ jsx34("style", { href: "tb-menu-v2", precedence: "throttle", children: MENU_V2_CSS }),
3700
+ items.length === 0 ? null : /* @__PURE__ */ jsx34(Nav, { items, menu: name, label: nameOf(name), listId, ctx, ...mobile.length > 0 ? { className: "tb-mm-hide-phone" } : {} }),
3701
+ mobile.length === 0 ? null : /* @__PURE__ */ jsx34(Nav, { items: mobile, menu: "mobile", label: nameOf("mobile"), listId: mobileId, ctx, className: "tb-mm-only-phone" }),
3702
+ props.interactive === false ? null : /* @__PURE__ */ jsx34(MenuRuntime, {})
3703
+ ] });
3704
+ }
3705
+ var MENU_V2_CSS = `@layer throttle{
3706
+ .tb-mm{position:relative;color:var(--b-color,inherit);font-size:var(--b-size,var(--tb-text-m));text-align:var(--b-align,start)}
3707
+ .tb-mm ul{margin:0;padding:0;list-style:none}
3708
+ .tb-mm li{position:relative;min-inline-size:0}
3709
+ .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}
3710
+ .tb-mm a:hover{text-decoration:underline}
3711
+ .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}
3712
+ .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)}
3713
+ .tb-mm-desc{display:block;padding-inline:var(--tb-space-s);font-size:.85em;opacity:.75;overflow-wrap:anywhere}
3714
+ .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}
3715
+ .tb-mm-t svg{transition:transform .15s}
3716
+ .tb-mm-i[data-open]>.tb-mm-t svg{transform:rotate(180deg)}
3717
+ .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}
3718
+ .tb-mm-only-phone{display:none}
3719
+ .tb-mm--horizontal>ul,.tb-mm--drawer>ul,.tb-mm--mega>ul{display:flex;flex-wrap:wrap;align-items:center}
3720
+ .tb-mm--horizontal>ul>li,.tb-mm--drawer>ul>li,.tb-mm--mega>ul>li{display:inline-flex;align-items:center}
3721
+ .tb-mm-sub,.tb-mm-panel{display:none}
3722
+ .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)}
3723
+ .tb-mm-sub .tb-mm-sub{position:static;min-inline-size:0;padding:0;padding-inline-start:var(--tb-space-m);border:0}
3724
+ .tb-mm-sub>li{display:block}
3725
+ .tb-mm-i[data-open]>.tb-mm-sub{display:block}
3726
+ .tb-mm-sub .tb-mm-sub{display:block}
3727
+ .tb-mm--vertical .tb-mm-t{display:none}
3728
+ .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}
3729
+ .tb-mm--mega>ul>li{position:static}
3730
+ .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)}
3731
+ .tb-mm-i[data-open]>.tb-mm-panel{display:flex;gap:var(--tb-space-m)}
3732
+ .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}
3733
+ .tb-mm-col>.tb-mm-sub{display:block;position:static;min-inline-size:0;padding:0;border:0}
3734
+ .tb-mm-feat{flex:0 1 16rem;min-inline-size:0;margin:0}
3735
+ .tb-mm-feat img{display:block;max-inline-size:100%;block-size:auto}
3736
+ @media (max-width:767.98px){
3737
+ .tb-mm-hide-phone{display:none}
3738
+ .tb-mm-only-phone{display:block}
3739
+ .tb-mm--mega>ul{display:block}
3740
+ .tb-mm--mega>ul>li{display:flex;flex-wrap:wrap;align-items:center}
3741
+ .tb-mm--mega>ul>li>a,.tb-mm--mega>ul>li>.tb-mm-text{flex:1 1 0}
3742
+ .tb-mm--mega>ul>li>.tb-mm-sub,.tb-mm--mega>ul>li>.tb-mm-panel{flex:1 0 100%}
3743
+ .tb-mm-panel{position:static;inset:auto;border:0;padding:0;background:transparent}
3744
+ .tb-mm-cols{display:block}
3745
+ .tb-mm-feat{display:none}
3746
+ .tb-mm--mega>ul>li>.tb-mm-panel{position:static;border:0;padding:0}
3747
+ .tb-mm-i>.tb-mm-sub{position:static;min-inline-size:0;border:0;padding:0;padding-inline-start:var(--tb-space-m)}
3748
+ .tb-mm--drawer>.tb-mm-drawer{display:inline-flex;position:relative;z-index:61}
3749
+ .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)}
3750
+ .tb-mm--drawer>ul{display:none}
3751
+ .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)}
3752
+ .tb-mm--drawer[data-open=true]>ul>li{display:flex;flex-wrap:wrap}
3753
+ .tb-mm--drawer[data-open=true] .tb-mm-sub{display:block;position:static;border:0}
3754
+ }
3755
+ @media (scripting: none){
3756
+ .tb-mm-t{display:none}
3757
+ .tb-mm-i:hover>.tb-mm-sub,.tb-mm-i:focus-within>.tb-mm-sub{display:block}
3758
+ .tb-mm-i:hover>.tb-mm-panel,.tb-mm-i:focus-within>.tb-mm-panel{display:flex;gap:var(--tb-space-m)}
3759
+ @media (max-width:767.98px){
3760
+ .tb-mm-sub,.tb-mm-panel{display:block}
3761
+ .tb-mm--drawer>.tb-mm-drawer{display:none}
3762
+ .tb-mm--drawer>ul{display:block}
3763
+ }
3764
+ }
3765
+ }`;
3766
+ var definition = MB_BASIC_WIDGET_DEFINITIONS.find((d) => d.type === "basic.menu" && d.v === 2);
3767
+ if (definition === void 0) throw new Error("builder-schema has no basic.menu v2 definition");
3768
+ var menuV2Widgets = [{ ...definition, Component: MenuV2 }];
3769
+
3770
+ // src/basics/v2/announcement-v2.tsx
3771
+ import { Fragment as Fragment22, jsx as jsx35, jsxs as jsxs25 } from "react/jsx-runtime";
3772
+ var DEVICES5 = ["desktop", "tablet", "phone"];
3773
+ var DISMISS_PREFIX = "tb-an-dismissed:";
3774
+ var COLOR_HEX = /^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;
3775
+ var COLOR_TOKEN2 = /^token:([a-z][a-z-]{0,30})$/;
3776
+ var REDUCED = "(prefers-reduced-motion: reduce)";
3777
+ function readDismissed(ids) {
3778
+ const out = [];
3779
+ for (const id of ids) {
3780
+ try {
3781
+ if (window.localStorage.getItem(`${DISMISS_PREFIX}${id}`) === "1") out.push(id);
3782
+ } catch {
3783
+ }
3784
+ }
3785
+ return out;
3786
+ }
3787
+ function writeDismissed(id) {
3788
+ try {
3789
+ window.localStorage.setItem(`${DISMISS_PREFIX}${id}`, "1");
3790
+ } catch {
3791
+ }
3792
+ }
3793
+ var matches = (query) => window.matchMedia?.(query).matches === true;
3794
+ function deviceNow() {
3795
+ return matches("(max-width:767.98px)") ? "phone" : matches("(max-width:1024.98px)") ? "tablet" : "desktop";
3796
+ }
3797
+ function colorOf(value) {
3798
+ if (typeof value !== "string") return void 0;
3799
+ if (COLOR_HEX.test(value)) return value;
3800
+ const token = COLOR_TOKEN2.exec(value);
3801
+ return token === null ? void 0 : `var(--tb-color-${token[1]})`;
3802
+ }
3803
+ var textOf = (tree) => tree.children.map((child) => typeof child === "string" ? child : textOf(child)).join("");
3804
+ function inline(children) {
3805
+ return children.map((child, index) => {
3806
+ if (typeof child === "string") return child;
3807
+ const inner = inline(child.children);
3808
+ if (child.tag === "strong" || child.tag === "em") return createElement3(child.tag, { key: index }, ...inner);
3809
+ if (child.tag === "a" && typeof child.href === "string") {
3810
+ return /* @__PURE__ */ jsx35("a", { href: child.href, rel: "noopener noreferrer", children: inner }, index);
3811
+ }
3812
+ return /* @__PURE__ */ jsx35(Fragment21, { children: inner }, index);
3813
+ });
3814
+ }
3815
+ function MessageText({ message, locale, mediaOrigin, href }) {
3816
+ const tree = parseRichText(localized(message.text, locale) ?? "", mediaOrigin);
3817
+ if (href !== null) return /* @__PURE__ */ jsx35("a", { href, children: textOf(tree) });
3818
+ return /* @__PURE__ */ jsx35("span", { className: "tb-an-text", children: inline(tree.children) });
3819
+ }
3820
+ function pageOf2(builder) {
3821
+ const given = builder?.page;
3822
+ if (given !== void 0) return given;
3823
+ return { home: builder?.pathname === "/" };
3824
+ }
3825
+ function audienceOf(ready, viewer) {
3826
+ if (!ready || viewer === null || viewer?.signedIn === null) return "all";
3827
+ return viewer?.signedIn === true ? "signed-in" : "guest";
3828
+ }
3829
+ function Bar({ raw, props, builder }) {
3830
+ const { props: settings, mediaOrigin, locale, editMode } = props;
3831
+ const design = useSiteDesign6();
3832
+ const viewer = useViewer();
3833
+ const all2 = useMemo(() => normalizeMessages(Array.isArray(raw.messages) ? raw.messages : []), [raw]);
3834
+ const style = isRecord4(raw.style) ? raw.style : {};
3835
+ const rotate = isRecord4(raw.rotate) ? raw.rotate : {};
3836
+ const [ready, setReady] = useState6(false);
3837
+ const [dismissed, setDismissed] = useState6(() => /* @__PURE__ */ new Set());
3838
+ const [at, setAt] = useState6(0);
3839
+ const [hover, setHover] = useState6(false);
3840
+ const [focus, setFocus] = useState6(false);
3841
+ const [reduced2, setReduced] = useState6(false);
3842
+ const site = builder?.site;
3843
+ const loadedAt = site?.status === "ok" && site.loadedAt !== void 0 ? Date.parse(site.loadedAt) : Number.NaN;
3844
+ const now = ready || Number.isNaN(loadedAt) ? Date.now() : loadedAt;
3845
+ const page = pageOf2(builder);
3846
+ const eligible = eligibleOnAnyDevice(all2, now, audienceOf(ready, viewer), page);
3847
+ const shown2 = eligible.filter((m) => editMode || !dismissed.has(m.id));
3848
+ const forEveryone = new Set(eligibleOnAnyDevice(all2, now, "all", page).map((m) => m.id));
3849
+ const waiting = [...eligibleOnAnyDevice(all2, now, "guest", page), ...eligibleOnAnyDevice(all2, now, "signed-in", page)].some(
3850
+ (m) => !forEveryone.has(m.id)
3851
+ );
3852
+ const interactive = props.interactive !== false && !editMode;
3853
+ const rotating = interactive && rotate.enabled === true && shown2.length > 1;
3854
+ const current = Math.min(at, Math.max(0, shown2.length - 1));
3855
+ const intervalS = typeof rotate.intervalS === "number" ? Math.min(15, Math.max(3, rotate.intervalS)) : 6;
3856
+ const shownRef = useRef3(shown2);
3857
+ shownRef.current = shown2;
3858
+ useEffect9(() => {
3859
+ setReady(true);
3860
+ setDismissed(new Set(readDismissed(all2.map((m) => m.id))));
3861
+ }, [all2]);
3862
+ useEffect9(() => {
3863
+ const query = window.matchMedia?.(REDUCED);
3864
+ if (query === void 0) return void 0;
3865
+ const sync = () => setReduced(query.matches);
3866
+ sync();
3867
+ query.addEventListener?.("change", sync);
3868
+ return () => query.removeEventListener?.("change", sync);
3869
+ }, []);
3870
+ const step2 = (direction) => setAt((from) => {
3871
+ const list2 = shownRef.current;
3872
+ const device = deviceNow();
3873
+ let i = Math.min(from, list2.length - 1);
3874
+ for (let tries = 0; tries < list2.length; tries += 1) {
3875
+ i = (i + direction + list2.length) % list2.length;
3876
+ if (list2[i].devices.includes(device)) return i;
3877
+ }
3878
+ return from;
3879
+ });
3880
+ useEffect9(() => {
3881
+ const list2 = shownRef.current;
3882
+ if (list2.length > 1 && list2[0] !== void 0 && !list2[0].devices.includes(deviceNow())) step2(1);
3883
+ }, [ready]);
3884
+ useEffect9(() => {
3885
+ if (!rotating || hover || focus || reduced2) return void 0;
3886
+ const timer = setInterval(() => step2(1), intervalS * 1e3);
3887
+ return () => clearInterval(timer);
3888
+ }, [rotating, hover, focus, reduced2, intervalS]);
3889
+ if (raw.enabled !== true) return /* @__PURE__ */ jsx35(Placeholder, { editMode, children: "No announcement: turn one on in Site settings" });
3890
+ const reserve = eligible.length === 0 && waiting;
3891
+ if (shown2.length === 0 && !reserve) return /* @__PURE__ */ jsx35(Placeholder, { editMode, children: "No announcement is showing now" });
3892
+ const link = makeLink(builder, props.resolveLink, mediaOrigin);
3893
+ const word = (key, fallback) => {
3894
+ for (const strings of [site?.status === "ok" ? site.settings.strings : void 0, design?.strings]) {
3895
+ if (isRecord4(strings) && Object.hasOwn(strings, key) && str(strings[key]) !== void 0) return strings[key];
3896
+ }
3897
+ return fallback;
3898
+ };
3899
+ const dismissLabel = word("announcement.dismiss", SITE_STRING_DEFAULTS6["announcement.dismiss"]);
3900
+ const dismissible = interactive && style.dismissible === true && settings.dismissible !== false;
3901
+ const dismiss = (id) => {
3902
+ writeDismissed(id);
3903
+ setDismissed((previous) => new Set(previous).add(id));
3904
+ };
3905
+ const height = isRecord4(style.height) ? style.height : {};
3906
+ const vars = {};
3907
+ for (const [device, key] of [["desktop", "--tb-an-hd"], ["tablet", "--tb-an-ht"], ["phone", "--tb-an-hp"]]) {
3908
+ const value = Object.hasOwn(height, device) ? height[device] : null;
3909
+ if (typeof value === "number" && Number.isInteger(value) && value >= 0 && value <= 200) vars[key] = `${String(value)}px`;
3910
+ }
3911
+ const background = colorOf(style.background);
3912
+ const foreground = colorOf(style.text);
3913
+ if (background !== void 0) vars["--tb-an-bg"] = background;
3914
+ if (foreground !== void 0) vars["--tb-an-fg"] = foreground;
3915
+ const align = style.align === "left" || style.align === "right" ? style.align : "center";
3916
+ const size = style.size === "m" ? "m" : "s";
3917
+ const transition = rotate.transition === "slide" ? "slide" : "fade";
3918
+ const activeMessage = shown2[current];
3919
+ const live = rotating && !hover && !focus && !reduced2 ? "off" : "polite";
3920
+ const dismissButton = (id) => /* @__PURE__ */ jsx35("button", { type: "button", className: "tb-b-dismiss", onClick: () => dismiss(id), children: /* @__PURE__ */ jsx35(Icon5, { name: "close", size: 16, label: dismissLabel }) });
3921
+ return /* @__PURE__ */ jsxs25(Fragment22, { children: [
3922
+ /* @__PURE__ */ jsx35(BasicStyles, {}),
3923
+ /* @__PURE__ */ jsx35("style", { href: "tb-an", precedence: "throttle", children: ANNOUNCEMENT_V2_CSS }),
3924
+ /* @__PURE__ */ jsxs25(
3925
+ "div",
3926
+ {
3927
+ className: `tb-an tb-an--${size} tb-an--${transition}${rotating ? " tb-an--rot" : ""}${reserve ? " tb-an--reserve" : ""}`,
3928
+ role: "region",
3929
+ "aria-label": word("announcement.label", "Announcement"),
3930
+ "data-align": align,
3931
+ style: vars,
3932
+ onMouseEnter: () => setHover(true),
3933
+ onMouseLeave: () => setHover(false),
3934
+ onFocus: () => setFocus(true),
3935
+ onBlur: () => setFocus(false),
3936
+ children: [
3937
+ rotating && /* @__PURE__ */ jsx35("button", { type: "button", className: "tb-an-step", "data-tb-an-prev": "", "aria-label": word("announcement.previous", "Previous announcement"), onClick: () => step2(-1), children: /* @__PURE__ */ jsx35("span", { "aria-hidden": "true", children: "\u2039" }) }),
3938
+ /* @__PURE__ */ jsx35("div", { className: "tb-an-track", ...rotating ? { "aria-live": live } : {}, children: shown2.map((m, index) => {
3939
+ const target2 = isRecord4(m.target) ? m.target : null;
3940
+ const hidden = DEVICES5.filter((d) => !m.devices.includes(d)).map((d) => ` tb-an-hide-${d}`).join("");
3941
+ return /* @__PURE__ */ jsxs25(
3942
+ "div",
3943
+ {
3944
+ className: `tb-b-announcement tb-an-msg${hidden}`,
3945
+ ...rotating && index === current ? { "data-active": "" } : {},
3946
+ children: [
3947
+ /* @__PURE__ */ jsx35("span", { className: "tb-b-announcement-text", children: /* @__PURE__ */ jsx35(MessageText, { message: m, locale, mediaOrigin, href: target2 === null ? null : link(target2) }) }),
3948
+ !rotating && dismissible && dismissButton(m.id)
3949
+ ]
3950
+ },
3951
+ m.id
3952
+ );
3953
+ }) }),
3954
+ rotating && /* @__PURE__ */ jsx35("button", { type: "button", className: "tb-an-step", "data-tb-an-next": "", "aria-label": word("announcement.next", "Next announcement"), onClick: () => step2(1), children: /* @__PURE__ */ jsx35("span", { "aria-hidden": "true", children: "\u203A" }) }),
3955
+ rotating && dismissible && activeMessage !== void 0 && dismissButton(activeMessage.id)
3956
+ ]
3957
+ }
3958
+ )
3959
+ ] });
3960
+ }
3961
+ function AnnouncementV2(props) {
3962
+ const builder = useBuilder();
3963
+ const site = builder?.site;
3964
+ const raw = site?.status === "ok" && isRecord4(site.settings.announcement) ? site.settings.announcement : null;
3965
+ if (raw === null || !Array.isArray(raw.messages)) return /* @__PURE__ */ jsx35(Announcement, { ...props });
3966
+ return /* @__PURE__ */ jsx35(Bar, { raw, props, builder });
3967
+ }
3968
+ var ANNOUNCEMENT_V2_CSS = `@layer throttle{
3969
+ .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)))}
3970
+ .tb-an--reserve,.tb-an--rot{--tb-an-rf:2.5rem}
3971
+ .tb-an-track{flex:1 1 auto;min-inline-size:0}
3972
+ .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}
3973
+ .tb-an[data-align=left] .tb-b-announcement{text-align:var(--b-align,start);justify-content:flex-start}
3974
+ .tb-an[data-align=right] .tb-b-announcement{text-align:var(--b-align,end);justify-content:flex-end}
3975
+ .tb-an--m .tb-b-announcement{font-size:var(--tb-text-m)}
3976
+ .tb-an-text{display:inline}
3977
+ .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}
3978
+ .tb-an-step:focus-visible{outline:2px solid currentColor;outline-offset:-2px}
3979
+ [dir=rtl] .tb-an-step span{display:inline-block;transform:scaleX(-1)}
3980
+ .tb-an--rot .tb-an-track{display:grid}
3981
+ .tb-an--rot .tb-an-msg{grid-area:1/1}
3982
+ .tb-an--rot .tb-an-msg:not([data-active]){visibility:hidden}
3983
+ @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}}
3984
+ @keyframes tb-an-fade{from{opacity:0}to{opacity:1}}
3985
+ @keyframes tb-an-slide{from{opacity:0;transform:translateY(-.75rem)}to{opacity:1;transform:none}}
3986
+ @media (max-width:1024.98px){.tb-an{min-block-size:var(--tb-an-ht,var(--tb-an-hd,var(--tb-an-rf)))}}
3987
+ @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))))}}
3988
+ @media (min-width:1024.99px){.tb-an-hide-desktop{display:none}}
3989
+ @media (min-width:767.99px) and (max-width:1024.98px){.tb-an-hide-tablet{display:none}}
3990
+ @media (max-width:767.98px){.tb-an-hide-phone{display:none}}
3991
+ }`;
3992
+ var definition2 = BASIC_WIDGET_DEFINITIONS2.find((d) => d.type === "basic.announcement");
3993
+ if (definition2 === void 0) throw new Error("builder-schema has no basic.announcement definition");
3994
+ var announcementV2Widgets = [{ ...definition2, Component: AnnouncementV2 }];
3995
+
3996
+ // src/basics/v2/breadcrumbs.tsx
3997
+ import { useSiteDesign as useSiteDesign7 } from "@usethrottle/ui";
3998
+ import { safeUrl as safeUrl14 } from "@usethrottle/builder-schema";
3999
+
4000
+ // src/server/jsonld.ts
4001
+ var CONTEXT = "https://schema.org";
4002
+ function breadcrumbJsonLd(items) {
4003
+ return {
4004
+ "@context": CONTEXT,
4005
+ "@type": "BreadcrumbList",
4006
+ itemListElement: items.map((item, index) => ({
4007
+ "@type": "ListItem",
4008
+ position: index + 1,
4009
+ name: item.name,
4010
+ item: item.url
4011
+ }))
4012
+ };
4013
+ }
4014
+ function faqJsonLd(items) {
4015
+ return {
4016
+ "@context": CONTEXT,
4017
+ "@type": "FAQPage",
4018
+ mainEntity: items.map((item) => ({
4019
+ "@type": "Question",
4020
+ name: item.question,
4021
+ acceptedAnswer: { "@type": "Answer", text: item.answer }
4022
+ }))
4023
+ };
4024
+ }
4025
+ function jsonLdString(value) {
4026
+ return JSON.stringify(value).replaceAll("<", "\\u003c");
4027
+ }
4028
+
4029
+ // src/basics/v2/definitions.ts
4030
+ import { MB_BASIC_WIDGET_DEFINITIONS as MB_BASIC_WIDGET_DEFINITIONS2 } from "@usethrottle/builder-schema";
4031
+ function mbDefinition(type) {
4032
+ const found = MB_BASIC_WIDGET_DEFINITIONS2.filter((d) => d.type === type).sort((a, b) => b.v - a.v)[0];
4033
+ if (found === void 0) throw new Error(`No MB definition of ${type}`);
4034
+ return found;
4035
+ }
4036
+
4037
+ // src/basics/v2/breadcrumbs.tsx
4038
+ import { Fragment as Fragment23, jsx as jsx36, jsxs as jsxs26 } from "react/jsx-runtime";
4039
+ var SEPARATORS = { slash: "/", chevron: "\u203A", dot: "\xB7", arrow: "\u2192" };
4040
+ function jsonLdOn(settings) {
4041
+ if (!isRecord4(settings) || !isRecord4(settings.seo) || !isRecord4(settings.seo.structuredData)) return false;
4042
+ return settings.seo.structuredData.breadcrumbs === true;
4043
+ }
4044
+ function Breadcrumbs({ props, data, mediaOrigin, resolveLink, editMode }) {
4045
+ const design = useSiteDesign7();
4046
+ const builder = useBuilder();
4047
+ const product = isRecord4(data.product) ? data.product : null;
4048
+ const title = product === null ? void 0 : str(product.title) ?? str(product.handle);
4049
+ if (product === null || title === void 0) {
4050
+ return /* @__PURE__ */ jsxs26(Fragment23, { children: [
4051
+ /* @__PURE__ */ jsx36(BasicV2Styles, {}),
4052
+ /* @__PURE__ */ jsx36(Placeholder, { editMode, children: "The trail appears on a product page" })
4053
+ ] });
4054
+ }
4055
+ const href = (target2) => safeUrl14(resolveLink?.(target2), "href", { mediaOrigin });
4056
+ const trail = [{ name: str(design?.brand?.storeName?.trim()) ?? "Home", href: "/" }];
4057
+ for (const step2 of Array.isArray(product.breadcrumbs) ? product.breadcrumbs : []) {
4058
+ if (!isRecord4(step2) || str(step2.name) === void 0) continue;
4059
+ const handle2 = str(step2.handle);
4060
+ trail.push({ name: step2.name, href: handle2 === void 0 ? null : href({ kind: "category", handle: handle2 }) });
4061
+ }
4062
+ const handle = str(product.handle);
4063
+ const current = { name: title, href: handle === void 0 ? null : href({ kind: "product", handle }) };
4064
+ const shown2 = props.showCurrent === false ? trail : [...trail, current];
4065
+ const separator = SEPARATORS[oneOf(props.separator, ["slash", "chevron", "dot", "arrow"], "slash")];
4066
+ 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;
4067
+ return /* @__PURE__ */ jsxs26(Fragment23, { children: [
4068
+ /* @__PURE__ */ jsx36(BasicV2Styles, {}),
4069
+ /* @__PURE__ */ jsxs26("nav", { className: "tb-b-crumbs", "aria-label": "Breadcrumb", children: [
4070
+ /* @__PURE__ */ jsx36("ol", { children: shown2.map((crumb, index) => {
4071
+ const last = index === shown2.length - 1 && props.showCurrent !== false;
4072
+ return /* @__PURE__ */ jsxs26("li", { children: [
4073
+ index > 0 && /* @__PURE__ */ jsx36("span", { className: "tb-b-crumbs-sep", "aria-hidden": "true", children: separator }),
4074
+ last ? /* @__PURE__ */ jsx36("span", { "aria-current": "page", children: crumb.name }) : crumb.href === null ? /* @__PURE__ */ jsx36("span", { children: crumb.name }) : /* @__PURE__ */ jsx36("a", { href: crumb.href, children: crumb.name })
4075
+ ] }, `${String(index)}:${crumb.name}`);
4076
+ }) }),
4077
+ jsonLd !== null && /* @__PURE__ */ jsx36("script", { type: "application/ld+json", children: jsonLd })
4078
+ ] })
4079
+ ] });
4080
+ }
4081
+ var breadcrumbsWidgets = [{ ...mbDefinition("basic.breadcrumbs"), Component: Breadcrumbs }];
4082
+
4083
+ // src/basics/v2/faq.tsx
4084
+ import { useId as useId3, useRef as useRef4, useState as useState8 } from "react";
4085
+ import { sanitizeRichContent } from "@usethrottle/builder-schema";
4086
+
4087
+ // src/basics/v2/markup.tsx
4088
+ import { createElement as createElement4, useEffect as useEffect10, useState as useState7 } from "react";
4089
+ import { RICH_CONTENT_ALLOWED_TAGS, SVG_ALLOWED_TAGS, SVG_MAX_BYTES, safeUrl as safeUrl15, sanitizeSvg } from "@usethrottle/builder-schema";
4090
+ import { jsx as jsx37 } from "react/jsx-runtime";
4091
+ var RICH = new Set(RICH_CONTENT_ALLOWED_TAGS);
4092
+ var SVG = new Set(SVG_ALLOWED_TAGS);
4093
+ var VOID2 = /* @__PURE__ */ new Set(["br", "hr", "img"]);
4094
+ var MAX_DEPTH4 = 24;
4095
+ var TOKEN = /<(\/?)([A-Za-z][A-Za-z0-9]*)((?:\s+[^\s="'<>/]+(?:="[^"]*")?)*)\s*(\/?)>|([^<]+)|</gu;
4096
+ var ATTR = /\s+([^\s="'<>/]+)(?:="([^"]*)")?/gu;
4097
+ var ENTITIES = { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'", nbsp: "\xA0" };
4098
+ function decode2(value) {
4099
+ return value.replace(/&(?:#x([0-9a-f]{1,6})|#(\d{1,7})|([a-z]{2,6}));/giu, (whole, hex, dec, name) => {
4100
+ if (name !== void 0) return Object.hasOwn(ENTITIES, name.toLowerCase()) ? ENTITIES[name.toLowerCase()] : whole;
4101
+ const code = hex !== void 0 ? Number.parseInt(hex, 16) : Number.parseInt(dec ?? "", 10);
4102
+ return code > 0 && code <= 1114111 && !(code >= 55296 && code <= 57343) ? String.fromCodePoint(code) : "";
4103
+ });
4104
+ }
4105
+ function parseMarkup(markup, kind) {
4106
+ const allowed = kind === "rich" ? RICH : SVG;
4107
+ const root = { tag: "#root", attrs: [], children: [] };
4108
+ const stack = [root];
4109
+ let skipping = 0;
4110
+ for (const match of markup.matchAll(TOKEN)) {
4111
+ const [, closing, name, attrText2, selfClose, text] = match;
4112
+ const top = stack[stack.length - 1];
4113
+ if (name === void 0) {
4114
+ if (skipping === 0 && text !== void 0) top.children.push(decode2(text));
4115
+ continue;
4116
+ }
4117
+ const tag = [...allowed].find((candidate) => candidate.toLowerCase() === name.toLowerCase());
4118
+ if (closing === "/") {
4119
+ if (skipping > 0) skipping -= 1;
4120
+ else if (tag !== void 0 && stack.length > 1 && top.tag === tag) stack.pop();
4121
+ continue;
4122
+ }
4123
+ const isVoid = VOID2.has(name.toLowerCase());
4124
+ if (tag === void 0 || stack.length > MAX_DEPTH4) {
4125
+ if (selfClose !== "/" && !isVoid) skipping += 1;
4126
+ continue;
4127
+ }
4128
+ if (skipping > 0) {
4129
+ if (selfClose !== "/" && !isVoid) skipping += 1;
4130
+ continue;
4131
+ }
4132
+ const attrs = [];
4133
+ for (const a of (attrText2 ?? "").matchAll(ATTR)) attrs.push([a[1], decode2(a[2] ?? "")]);
4134
+ const element = { tag, attrs, children: [] };
4135
+ top.children.push(element);
4136
+ if (selfClose !== "/" && !isVoid) stack.push(element);
4137
+ }
4138
+ return root.children;
4139
+ }
4140
+ function textOf2(nodes) {
4141
+ return nodes.map((n) => typeof n === "string" ? n : n.tag === "br" ? " " : textOf2(n.children)).join("");
4142
+ }
4143
+ var SPECIAL = {
4144
+ class: "className",
4145
+ colspan: "colSpan",
4146
+ rowspan: "rowSpan",
4147
+ "xlink:href": "xlinkHref",
4148
+ "xml:space": "xmlSpace",
4149
+ "xmlns:xlink": "xmlnsXlink"
4150
+ };
4151
+ var camel = (name) => name.replace(/-([a-z])/gu, (_m, c) => c.toUpperCase());
4152
+ function styleOf(value) {
4153
+ const out = {};
4154
+ for (const declaration of value.split(";")) {
4155
+ const colon = declaration.indexOf(":");
4156
+ if (colon === -1) continue;
4157
+ const property = declaration.slice(0, colon).trim();
4158
+ const v = declaration.slice(colon + 1).trim();
4159
+ if (/^[a-z][a-z-]*$/u.test(property) && v !== "") out[camel(property)] = v;
4160
+ }
4161
+ return out;
4162
+ }
4163
+ var HYPHENATED = /* @__PURE__ */ new Set([
4164
+ "alignment-baseline",
4165
+ "baseline-shift",
4166
+ "clip-path",
4167
+ "clip-rule",
4168
+ "color-interpolation",
4169
+ "color-interpolation-filters",
4170
+ "dominant-baseline",
4171
+ "fill-opacity",
4172
+ "fill-rule",
4173
+ "flood-color",
4174
+ "flood-opacity",
4175
+ "font-family",
4176
+ "font-size",
4177
+ "font-size-adjust",
4178
+ "font-stretch",
4179
+ "font-style",
4180
+ "font-variant",
4181
+ "font-weight",
4182
+ "letter-spacing",
4183
+ "lighting-color",
4184
+ "marker-end",
4185
+ "marker-mid",
4186
+ "marker-start",
4187
+ "paint-order",
4188
+ "shape-rendering",
4189
+ "stop-color",
4190
+ "stop-opacity",
4191
+ "stroke-dasharray",
4192
+ "stroke-dashoffset",
4193
+ "stroke-linecap",
4194
+ "stroke-linejoin",
4195
+ "stroke-miterlimit",
4196
+ "stroke-opacity",
4197
+ "stroke-width",
4198
+ "text-anchor",
4199
+ "text-decoration",
4200
+ "text-rendering",
4201
+ "vector-effect",
4202
+ "word-spacing",
4203
+ "writing-mode"
4204
+ ]);
4205
+ var DENIED_PROP = /^(?:children|key|ref|dangerously|innerhtml|outerhtml|suppress|on)/iu;
4206
+ function propName(name) {
4207
+ if (Object.hasOwn(SPECIAL, name)) return SPECIAL[name];
4208
+ if (/^(?:aria|data)-[a-z0-9-]{1,60}$/u.test(name)) return name;
4209
+ const prop = HYPHENATED.has(name) ? camel(name) : name;
4210
+ if (!/^[a-z][a-zA-Z0-9]*$/u.test(prop) || DENIED_PROP.test(prop)) return null;
4211
+ return prop;
4212
+ }
4213
+ function propsOf(element, key) {
4214
+ const props = { key };
4215
+ for (const [name, value] of element.attrs) {
4216
+ if (name === "style") {
4217
+ props.style = styleOf(value);
4218
+ continue;
4219
+ }
4220
+ const prop = propName(name);
4221
+ if (prop !== null) props[prop] = value;
4222
+ }
4223
+ return props;
4224
+ }
4225
+ var FRAGMENT = /^#[A-Za-z_][\w:.-]{0,99}$/u;
4226
+ function checkUrls(tag, props, mediaOrigin) {
4227
+ for (const key of ["href", "xlinkHref", "src"]) {
4228
+ if (!Object.hasOwn(props, key)) continue;
4229
+ const value = props[key];
4230
+ const safe = SVG.has(tag) ? typeof value === "string" && FRAGMENT.test(value) ? value : null : safeUrl15(value, key === "src" ? "src" : "href", { mediaOrigin });
4231
+ if (safe !== null) {
4232
+ props[key] = safe;
4233
+ continue;
4234
+ }
4235
+ if (tag === "a" || tag === "img") return false;
4236
+ delete props[key];
4237
+ }
4238
+ return true;
4239
+ }
4240
+ function renderMarkup(nodes, options = {}) {
4241
+ return nodes.map((node, index) => {
4242
+ if (typeof node === "string") return node;
4243
+ const props = { ...propsOf(node, index), ...options.extra?.(node) ?? {} };
4244
+ if (!checkUrls(node.tag, props, options.mediaOrigin ?? "")) return null;
4245
+ if (VOID2.has(node.tag)) return createElement4(node.tag, props);
4246
+ return createElement4(node.tag, props, ...renderMarkup(node.children, options));
4247
+ });
4248
+ }
4249
+ function svgElement(svg) {
4250
+ const clean = sanitizeSvg(svg).svg;
4251
+ if (clean === "") return null;
4252
+ const root = parseMarkup(clean, "svg")[0];
4253
+ if (root === void 0 || typeof root === "string" || root.tag !== "svg") return null;
4254
+ const withFill = root.attrs.some(([name]) => name === "fill") ? root : { ...root, attrs: [...root.attrs, ["fill", "currentColor"]] };
4255
+ return renderMarkup([withFill])[0] ?? null;
4256
+ }
4257
+ async function readSvg(response, mediaOrigin) {
4258
+ if (!response.ok || safeUrl15(response.url, "src", { mediaOrigin }) === null) return null;
4259
+ if (!/^image\/svg\+xml(?:\s*;|$)/iu.test(response.headers.get("content-type") ?? "")) return null;
4260
+ const reader = response.body?.getReader();
4261
+ if (reader === void 0) {
4262
+ const text2 = await response.text();
4263
+ return new TextEncoder().encode(text2).length > SVG_MAX_BYTES ? null : text2;
4264
+ }
4265
+ const decoder = new TextDecoder();
4266
+ let total = 0;
4267
+ let text = "";
4268
+ for (; ; ) {
4269
+ const { done, value } = await reader.read();
4270
+ if (done) return text + decoder.decode();
4271
+ total += value.length;
4272
+ if (total > SVG_MAX_BYTES) {
4273
+ await reader.cancel();
4274
+ return null;
4275
+ }
4276
+ text += decoder.decode(value, { stream: true });
4277
+ }
4278
+ }
4279
+ function SvgFromAsset({ asset, mediaOrigin, label }) {
4280
+ const src = isFrozenAsset(asset) ? safeUrl15(asset.url, "src", { mediaOrigin }) : null;
4281
+ const [source, setSource] = useState7(null);
4282
+ useEffect10(() => {
4283
+ if (src === null) return;
4284
+ const controller = new AbortController();
4285
+ fetch(src, { credentials: "omit", redirect: "error", signal: controller.signal }).then((response) => readSvg(response, mediaOrigin)).then((text) => {
4286
+ if (text !== null && !controller.signal.aborted) setSource(text);
4287
+ }).catch(() => void 0);
4288
+ return () => controller.abort();
4289
+ }, [src]);
4290
+ if (src === null) return null;
4291
+ const inline2 = source === null ? null : svgElement(source);
4292
+ if (inline2 !== null) return inline2;
4293
+ return /* @__PURE__ */ jsx37(AssetImage, { asset, mediaOrigin, alt: label ?? "", loading: "eager" });
4294
+ }
4295
+
4296
+ // src/basics/v2/faq.tsx
4297
+ import { Fragment as Fragment24, jsx as jsx38, jsxs as jsxs27 } from "react/jsx-runtime";
4298
+ function itemsOf(value) {
4299
+ if (!Array.isArray(value)) return [];
4300
+ return value.flatMap((row) => {
4301
+ if (!isRecord4(row)) return [];
4302
+ const question = str(row.question);
4303
+ return question === void 0 ? [] : [{ question, answer: typeof row.answer === "string" ? row.answer : "" }];
4304
+ });
4305
+ }
4306
+ function faqJsonLdOn(settings) {
4307
+ if (!isRecord4(settings) || !isRecord4(settings.seo) || !isRecord4(settings.seo.structuredData)) return false;
4308
+ return settings.seo.structuredData.faq === true;
4309
+ }
4310
+ function Faq({ props, mediaOrigin, editMode }) {
4311
+ const builder = useBuilder();
4312
+ const group = useId3();
4313
+ const root = useRef4(null);
4314
+ const [all2, setAll] = useState8(false);
4315
+ const items = itemsOf(props.items);
4316
+ if (items.length === 0) {
4317
+ return /* @__PURE__ */ jsxs27(Fragment24, { children: [
4318
+ /* @__PURE__ */ jsx38(BasicV2Styles, {}),
4319
+ /* @__PURE__ */ jsx38(Placeholder, { editMode, children: "Add questions in the settings" })
4320
+ ] });
4321
+ }
4322
+ const answers = items.map((item) => parseMarkup(sanitizeRichContent(item.answer, mediaOrigin).html, "rich"));
4323
+ const open = props.mode === "open";
4324
+ const oneOpen = props.oneOpen === true;
4325
+ const showAll = !open && props.expandAll === true && !oneOpen;
4326
+ 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;
4327
+ const toggleAll = () => {
4328
+ const next = !all2;
4329
+ for (const details of root.current?.querySelectorAll("details") ?? []) details.open = next;
4330
+ setAll(next);
4331
+ };
4332
+ return /* @__PURE__ */ jsxs27(Fragment24, { children: [
4333
+ /* @__PURE__ */ jsx38(BasicV2Styles, {}),
4334
+ /* @__PURE__ */ jsxs27("div", { className: "tb-b-faq", ref: root, children: [
4335
+ showAll && /* @__PURE__ */ jsx38("button", { type: "button", className: "tb-b-faq-all", "aria-expanded": all2, onClick: toggleAll, children: all2 ? "Collapse all" : "Expand all" }),
4336
+ items.map(
4337
+ (item, index) => open ? /* @__PURE__ */ jsxs27("div", { className: "tb-b-faq-item", children: [
4338
+ /* @__PURE__ */ jsx38("h3", { className: "tb-b-faq-q", children: item.question }),
4339
+ /* @__PURE__ */ jsx38("div", { className: "tb-b-faq-a", children: renderMarkup(answers[index] ?? [], { mediaOrigin }) })
4340
+ ] }, `${String(index)}:${item.question}`) : /* @__PURE__ */ jsxs27("details", { className: "tb-b-faq-item", ...oneOpen ? { name: `faq-${group}` } : {}, children: [
4341
+ /* @__PURE__ */ jsx38("summary", { className: "tb-b-faq-q", children: item.question }),
4342
+ /* @__PURE__ */ jsx38("div", { className: "tb-b-faq-a", children: renderMarkup(answers[index] ?? [], { mediaOrigin }) })
4343
+ ] }, `${String(index)}:${item.question}`)
4344
+ ),
4345
+ jsonLd !== null && /* @__PURE__ */ jsx38("script", { type: "application/ld+json", children: jsonLd })
4346
+ ] })
4347
+ ] });
4348
+ }
4349
+ var faqWidgets = [{ ...mbDefinition("basic.faq"), Component: Faq }];
4350
+
4351
+ // src/basics/v2/heading-v2.tsx
4352
+ var headingV2Widgets = [{ ...mbDefinition("basic.heading"), Component: Heading }];
4353
+
4354
+ // src/basics/v2/icon-list.tsx
4355
+ import { ICON_NAMES, Icon as Icon6 } from "@usethrottle/ui";
4356
+ import { Fragment as Fragment25, jsx as jsx39, jsxs as jsxs28 } from "react/jsx-runtime";
4357
+ var isIconName = (name) => typeof name === "string" && ICON_NAMES.includes(name);
4358
+ function IconList({ props, mediaOrigin, editMode }) {
4359
+ const rows = Array.isArray(props.items) ? props.items.flatMap((row) => isRecord4(row) ? [row] : []) : [];
4360
+ if (rows.length === 0) {
4361
+ return /* @__PURE__ */ jsxs28(Fragment25, { children: [
4362
+ /* @__PURE__ */ jsx39(BasicV2Styles, {}),
4363
+ /* @__PURE__ */ jsx39(Placeholder, { editMode, children: "Add rows in the settings" })
4364
+ ] });
4365
+ }
4366
+ return /* @__PURE__ */ jsxs28(Fragment25, { children: [
4367
+ /* @__PURE__ */ jsx39(BasicV2Styles, {}),
4368
+ /* @__PURE__ */ jsx39("ul", { className: "tb-b-icons", children: rows.map((row, index) => /* @__PURE__ */ jsxs28("li", { children: [
4369
+ /* @__PURE__ */ jsx39("span", { className: "tb-b-icons-icon", "aria-hidden": "true", children: isFrozenAsset(row.svgAsset) ? /* @__PURE__ */ jsx39(SvgFromAsset, { asset: row.svgAsset, mediaOrigin }) : isIconName(row.icon) ? /* @__PURE__ */ jsx39(Icon6, { name: row.icon }) : null }),
4370
+ /* @__PURE__ */ jsx39("span", { className: "tb-b-icons-text", children: str(row.text) ?? "" })
4371
+ ] }, `${String(index)}:${str(row.text) ?? ""}`)) })
4372
+ ] });
4373
+ }
4374
+ var iconListWidgets = [{ ...mbDefinition("basic.icon-list"), Component: IconList }];
4375
+
4376
+ // src/basics/v2/merge.ts
4377
+ function mergeV2Widgets(v1, v2) {
4378
+ const replacement = /* @__PURE__ */ new Map();
4379
+ for (const widget of v2) {
4380
+ if (replacement.has(widget.type)) throw new Error(`Two v2 widgets of type ${widget.type}`);
4381
+ replacement.set(widget.type, widget);
4382
+ }
4383
+ const v1Types = new Set(v1.map((widget) => widget.type));
4384
+ return [
4385
+ ...v1.map((widget) => replacement.get(widget.type) ?? widget),
4386
+ ...[...replacement.values()].filter((widget) => !v1Types.has(widget.type))
4387
+ ];
4388
+ }
4389
+
4390
+ // src/basics/v2/quote.tsx
4391
+ import { Fragment as Fragment26, jsx as jsx40, jsxs as jsxs29 } from "react/jsx-runtime";
4392
+ function Quote({ props, mediaOrigin, editMode, inlineEdit }) {
4393
+ const quote = inlineEdit?.("quote") ?? str(props.quote);
4394
+ if (quote === void 0) {
4395
+ return /* @__PURE__ */ jsxs29(Fragment26, { children: [
4396
+ /* @__PURE__ */ jsx40(BasicV2Styles, {}),
4397
+ /* @__PURE__ */ jsx40(Placeholder, { editMode, children: "Write the quote in the settings" })
4398
+ ] });
4399
+ }
4400
+ const name = str(props.name);
4401
+ const role = str(props.role);
4402
+ const image = isFrozenAsset(props.image) ? props.image : null;
4403
+ return /* @__PURE__ */ jsxs29(Fragment26, { children: [
4404
+ /* @__PURE__ */ jsx40(BasicV2Styles, {}),
4405
+ /* @__PURE__ */ jsxs29("figure", { className: "tb-b-quote", children: [
4406
+ /* @__PURE__ */ jsx40("blockquote", { children: quote }),
4407
+ (name !== void 0 || role !== void 0 || image !== null) && /* @__PURE__ */ jsxs29("figcaption", { children: [
4408
+ image !== null && /* @__PURE__ */ jsx40(AssetImage, { asset: image, mediaOrigin, alt: "", className: "tb-b-quote-photo" }),
4409
+ /* @__PURE__ */ jsxs29("span", { className: "tb-b-quote-by", children: [
4410
+ name !== void 0 && /* @__PURE__ */ jsx40("span", { className: "tb-b-quote-name", children: name }),
4411
+ role !== void 0 && /* @__PURE__ */ jsx40("span", { className: "tb-b-quote-role", children: role })
4412
+ ] })
4413
+ ] })
4414
+ ] })
4415
+ ] });
4416
+ }
4417
+ var quoteWidgets = [{ ...mbDefinition("basic.quote"), Component: Quote }];
4418
+
4419
+ // src/basics/v2/rich-content.tsx
4420
+ import { sanitizeRichContent as sanitizeRichContent2 } from "@usethrottle/builder-schema";
4421
+ import { Fragment as Fragment27, jsx as jsx41, jsxs as jsxs30 } from "react/jsx-runtime";
4422
+ var slug = (text) => text.toLowerCase().normalize("NFKD").replace(/[^a-z0-9]+/gu, "-").replace(/^-+|-+$/gu, "").slice(0, 40);
4423
+ function headings(nodes, nodeId) {
4424
+ const found = /* @__PURE__ */ new Map();
4425
+ const visit = (list2) => {
4426
+ for (const node of list2) {
4427
+ if (typeof node === "string") continue;
4428
+ if (node.tag === "h2" || node.tag === "h3") {
4429
+ const label = textOf2(node.children).replace(/\s+/gu, " ").trim();
4430
+ const n = found.size + 1;
4431
+ found.set(node, { id: `${nodeId}-${String(n)}${slug(label) === "" ? "" : `-${slug(label)}`}`, level: node.tag === "h2" ? 2 : 3, label });
4432
+ }
4433
+ visit(node.children);
4434
+ }
4435
+ };
4436
+ visit(nodes);
4437
+ return found;
4438
+ }
4439
+ function RichContent({ node, props, mediaOrigin, editMode }) {
4440
+ const html = str(props.html);
4441
+ if (html === void 0) {
4442
+ return /* @__PURE__ */ jsxs30(Fragment27, { children: [
4443
+ /* @__PURE__ */ jsx41(BasicV2Styles, {}),
4444
+ /* @__PURE__ */ jsx41(Placeholder, { editMode, children: "Add content in the settings" })
4445
+ ] });
4446
+ }
4447
+ const tree = parseMarkup(sanitizeRichContent2(html, mediaOrigin).html, "rich");
4448
+ const entries2 = headings(tree, node.id);
4449
+ const toc = props.toc === true ? [...entries2.values()].filter((e) => e.label !== "") : [];
4450
+ return /* @__PURE__ */ jsxs30(Fragment27, { children: [
4451
+ /* @__PURE__ */ jsx41(BasicV2Styles, {}),
4452
+ /* @__PURE__ */ jsxs30("div", { className: "tb-b-rich", children: [
4453
+ toc.length > 0 && /* @__PURE__ */ jsxs30("nav", { className: "tb-b-toc", "aria-label": str(props.tocTitle) ?? "Contents", children: [
4454
+ /* @__PURE__ */ jsx41("p", { className: "tb-b-toc-title", children: str(props.tocTitle) ?? "Contents" }),
4455
+ /* @__PURE__ */ jsx41("ol", { children: toc.map((entry) => /* @__PURE__ */ jsx41("li", { className: `tb-b-toc-l${String(entry.level)}`, children: /* @__PURE__ */ jsx41("a", { href: `#${entry.id}`, children: entry.label }) }, entry.id)) })
4456
+ ] }),
4457
+ renderMarkup(tree, {
4458
+ mediaOrigin,
4459
+ extra: (element) => {
4460
+ const entry = entries2.get(element);
4461
+ return entry === void 0 ? void 0 : { id: entry.id };
4462
+ }
4463
+ })
4464
+ ] })
4465
+ ] });
4466
+ }
4467
+ var richContentWidgets = [{ ...mbDefinition("basic.rich-content"), Component: RichContent }];
4468
+
4469
+ // src/basics/v2/svg.tsx
4470
+ import { Fragment as Fragment28, jsx as jsx42, jsxs as jsxs31 } from "react/jsx-runtime";
4471
+ function Svg({ props, mediaOrigin, editMode }) {
4472
+ const pasted = str(props.svg);
4473
+ const label = str(props.label);
4474
+ const inline2 = pasted === void 0 ? null : svgElement(pasted);
4475
+ const asset = pasted === void 0 && props.asset !== null && props.asset !== void 0 ? props.asset : null;
4476
+ if (inline2 === null && asset === null) {
4477
+ return /* @__PURE__ */ jsxs31(Fragment28, { children: [
4478
+ /* @__PURE__ */ jsx42(BasicV2Styles, {}),
4479
+ /* @__PURE__ */ jsx42(Placeholder, { editMode, children: "Paste an SVG or pick one from the media library" })
4480
+ ] });
4481
+ }
4482
+ const decorative = props.decorative !== false;
4483
+ const access = decorative ? { "aria-hidden": true } : label === void 0 ? {} : { role: "img", "aria-label": label };
4484
+ return /* @__PURE__ */ jsxs31(Fragment28, { children: [
4485
+ /* @__PURE__ */ jsx42(BasicV2Styles, {}),
4486
+ /* @__PURE__ */ jsx42("div", { className: "tb-b-svg", ...access, children: inline2 ?? /* @__PURE__ */ jsx42(SvgFromAsset, { asset, mediaOrigin, ...label === void 0 || decorative ? {} : { label } }) })
4487
+ ] });
4488
+ }
4489
+ var svgWidgets = [{ ...mbDefinition("basic.svg"), Component: Svg }];
4490
+
4491
+ // src/basics/index.ts
4492
+ var BASIC_COMPONENTS = {
4493
+ "basic.heading": Heading,
4494
+ "basic.text": Text,
4495
+ "basic.image": Image,
4496
+ "basic.button": Button,
4497
+ "basic.spacer": Spacer,
4498
+ "basic.divider": Divider,
4499
+ "basic.video": Video,
4500
+ "basic.logo": Logo,
4501
+ "basic.menu": Menu,
4502
+ "basic.announcement": Announcement,
4503
+ "basic.copyright": Copyright,
4504
+ "basic.countdown": Countdown
4505
+ };
4506
+ var v1Widgets = BASIC_WIDGET_DEFINITIONS3.flatMap(
4507
+ (definition3) => definition3.v === 1 && Object.hasOwn(BASIC_COMPONENTS, definition3.type) ? [{ ...definition3, Component: BASIC_COMPONENTS[definition3.type] }] : []
4508
+ );
4509
+ var widgets = mergeV2Widgets(v1Widgets, [
4510
+ ...faqWidgets,
4511
+ ...richContentWidgets,
4512
+ ...breadcrumbsWidgets,
4513
+ ...svgWidgets,
4514
+ ...iconListWidgets,
4515
+ ...quoteWidgets,
4516
+ ...menuV2Widgets,
4517
+ ...announcementV2Widgets,
4518
+ ...headingV2Widgets
4519
+ ]);
2737
4520
  var basicPack = { id: "basic", version: "0.0.0", widgets, dataSources: [] };
2738
4521
 
2739
4522
  // src/custom/factory.ts
2740
- import { createElement as createElement3 } from "react";
4523
+ import { createElement as createElement5 } from "react";
2741
4524
 
2742
4525
  // src/custom/composite-widget.tsx
2743
4526
  import { Suspense as Suspense3 } from "react";
2744
4527
  import { pageDocumentSchema, validateSettingValue as validateSettingValue3 } from "@usethrottle/builder-schema";
2745
- import { jsx as jsx31 } from "react/jsx-runtime";
4528
+ import { jsx as jsx43 } from "react/jsx-runtime";
2746
4529
  var SETTING_KEY_RE = /^[a-z][A-Za-z0-9]{0,39}$/;
2747
4530
  var NODE_ID_RE = /^[a-z0-9]{8,24}$/;
2748
4531
  var WRAP = { section: "zzcompsec001", column: "zzcompcol001", inner: "zzcompinr001" };
2749
- var isRecord4 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
4532
+ var isRecord6 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
2750
4533
  var compiled3 = /* @__PURE__ */ new WeakMap();
2751
4534
  function parseBody(raw) {
2752
- if (!isRecord4(raw)) return null;
4535
+ if (!isRecord6(raw)) return null;
2753
4536
  const columns = Array.isArray(raw.columns) ? raw.columns : void 0;
2754
4537
  const stack = Array.isArray(raw.stack) ? raw.stack : void 0;
2755
4538
  if (columns === void 0 === (stack === void 0)) return null;
2756
4539
  const children = columns !== void 0 ? [{ id: WRAP.inner, type: "inner-section", props: {}, columns }] : stack ?? [];
2757
- if (stack?.some((node) => isRecord4(node) && node.type === "inner-section")) return null;
4540
+ if (stack?.some((node) => isRecord6(node) && node.type === "inner-section")) return null;
2758
4541
  const parsed2 = pageDocumentSchema.safeParse({
2759
4542
  schemaVersion: 1,
2760
4543
  sections: [{ id: WRAP.section, type: "section", props: {}, columns: [{ id: WRAP.column, type: "column", props: { width: 100 }, children }] }]
@@ -2787,38 +4570,38 @@ function compile2(snapshot) {
2787
4570
  const bindings = [];
2788
4571
  if (extra.bindings !== void 0 && !Array.isArray(extra.bindings)) return refuse("bindings is not a list");
2789
4572
  for (const raw of extra.bindings ?? []) {
2790
- if (!isRecord4(raw) || typeof raw.setting !== "string" || !SETTING_KEY_RE.test(raw.setting) || !Array.isArray(raw.targets)) {
4573
+ if (!isRecord6(raw) || typeof raw.setting !== "string" || !SETTING_KEY_RE.test(raw.setting) || !Array.isArray(raw.targets)) {
2791
4574
  return refuse("a binding is malformed");
2792
4575
  }
2793
4576
  const targets = [];
2794
- for (const target of raw.targets) {
2795
- if (!isRecord4(target) || typeof target.node !== "string" || !NODE_ID_RE.test(target.node) || typeof target.prop !== "string" || !SETTING_KEY_RE.test(target.prop)) {
4577
+ for (const target2 of raw.targets) {
4578
+ if (!isRecord6(target2) || typeof target2.node !== "string" || !NODE_ID_RE.test(target2.node) || typeof target2.prop !== "string" || !SETTING_KEY_RE.test(target2.prop)) {
2796
4579
  return refuse("a binding target is malformed");
2797
4580
  }
2798
- targets.push({ node: target.node, prop: target.prop });
4581
+ targets.push({ node: target2.node, prop: target2.prop });
2799
4582
  }
2800
4583
  bindings.push({ setting: raw.setting, targets });
2801
4584
  }
2802
4585
  const data = [];
2803
- if (extra.data !== void 0 && !isRecord4(extra.data)) return refuse("data is not a record");
4586
+ if (extra.data !== void 0 && !isRecord6(extra.data)) return refuse("data is not a record");
2804
4587
  for (const [name, raw] of Object.entries(extra.data ?? {})) {
2805
- if (!SETTING_KEY_RE.test(name) || !isRecord4(raw) || !Array.isArray(raw.targets)) return refuse("a data input is malformed");
4588
+ if (!SETTING_KEY_RE.test(name) || !isRecord6(raw) || !Array.isArray(raw.targets)) return refuse("a data input is malformed");
2806
4589
  const targets = [];
2807
- for (const target of raw.targets) {
2808
- if (!isRecord4(target) || typeof target.node !== "string" || !NODE_ID_RE.test(target.node) || typeof target.input !== "string" || !SETTING_KEY_RE.test(target.input)) {
4590
+ for (const target2 of raw.targets) {
4591
+ if (!isRecord6(target2) || typeof target2.node !== "string" || !NODE_ID_RE.test(target2.node) || typeof target2.input !== "string" || !SETTING_KEY_RE.test(target2.input)) {
2809
4592
  return refuse("a data target is malformed");
2810
4593
  }
2811
- targets.push({ node: target.node, input: target.input });
4594
+ targets.push({ node: target2.node, input: target2.input });
2812
4595
  }
2813
4596
  data.push([name, { targets }]);
2814
4597
  }
2815
4598
  return { body, bindings, data };
2816
4599
  }
2817
- var DEVICES3 = ["tablet", "phone"];
4600
+ var DEVICES6 = ["tablet", "phone"];
2818
4601
  function withoutAnchor(node) {
2819
4602
  delete node.props.anchor;
2820
4603
  const responsive = node.responsive;
2821
- for (const device of DEVICES3) if (responsive?.[device] !== void 0) delete responsive[device].anchor;
4604
+ for (const device of DEVICES6) if (responsive?.[device] !== void 0) delete responsive[device].anchor;
2822
4605
  }
2823
4606
  function instanceId(outer, inner) {
2824
4607
  let a = 3735928559;
@@ -2832,7 +4615,7 @@ function instanceId(outer, inner) {
2832
4615
  b = Math.imul(b ^ b >>> 16, 2246822507) ^ Math.imul(a ^ a >>> 13, 3266489909);
2833
4616
  return `i${(a >>> 0).toString(36).padStart(7, "0")}${(b >>> 0).toString(36).padStart(7, "0")}${(outer.length + inner.length).toString(36)}`;
2834
4617
  }
2835
- function build(input) {
4618
+ function build2(input) {
2836
4619
  const { snapshot, registry, node: outer, props, data } = input;
2837
4620
  const body = structuredClone(input.compiled.body);
2838
4621
  const assets = {};
@@ -2861,11 +4644,11 @@ function build(input) {
2861
4644
  return id;
2862
4645
  }
2863
4646
  if (field.control === "link") {
2864
- if (!isRecord4(value) || typeof value.kind !== "string") return null;
2865
- const { href, ...target } = value;
2866
- if (target.kind === "url") return typeof href === "string" ? { kind: "url", href } : null;
2867
- hrefs.set(JSON.stringify(target), typeof href === "string" ? href : null);
2868
- return target;
4647
+ if (!isRecord6(value) || typeof value.kind !== "string") return null;
4648
+ const { href, ...target2 } = value;
4649
+ if (target2.kind === "url") return typeof href === "string" ? { kind: "url", href } : null;
4650
+ hrefs.set(JSON.stringify(target2), typeof href === "string" ? href : null);
4651
+ return target2;
2869
4652
  }
2870
4653
  return value;
2871
4654
  };
@@ -2873,21 +4656,21 @@ function build(input) {
2873
4656
  const field = fields.get(binding.setting);
2874
4657
  if (field === void 0 || !Object.hasOwn(props, binding.setting)) continue;
2875
4658
  const value = props[binding.setting];
2876
- for (const target of binding.targets) {
2877
- const inner = byId.get(target.node);
2878
- const innerField = inner === void 0 ? void 0 : registry.widget(inner.type, inner.v)?.settings.find((f) => f.key === target.prop);
4659
+ for (const target2 of binding.targets) {
4660
+ const inner = byId.get(target2.node);
4661
+ const innerField = inner === void 0 ? void 0 : registry.widget(inner.type, inner.v)?.settings.find((f) => f.key === target2.prop);
2879
4662
  if (inner === void 0 || innerField === void 0 || innerField.control !== field.control) continue;
2880
4663
  const converted = convert(field, value);
2881
4664
  if (validateSettingValue3(innerField, converted) !== null) continue;
2882
- inner.props[target.prop] = converted;
4665
+ inner.props[target2.prop] = converted;
2883
4666
  const responsive = inner.responsive;
2884
- for (const device of DEVICES3) {
2885
- if (responsive?.[device] !== void 0) delete responsive[device][target.prop];
4667
+ for (const device of DEVICES6) {
4668
+ if (responsive?.[device] !== void 0) delete responsive[device][target2.prop];
2886
4669
  const raw = outer.responsive?.[device];
2887
4670
  const plain = field.output === "css" && field.translatable !== true && field.control !== "image" && field.control !== "link";
2888
4671
  if (plain && raw !== void 0 && Object.hasOwn(raw, binding.setting) && validateSettingValue3(innerField, raw[binding.setting]) === null) {
2889
4672
  const target$ = inner.responsive ?? (inner.responsive = {});
2890
- (target$[device] ?? (target$[device] = {}))[target.prop] = raw[binding.setting];
4673
+ (target$[device] ?? (target$[device] = {}))[target2.prop] = raw[binding.setting];
2891
4674
  }
2892
4675
  }
2893
4676
  }
@@ -2895,11 +4678,11 @@ function build(input) {
2895
4678
  for (const [name, input$] of input.compiled.data) {
2896
4679
  if (!Object.hasOwn(data, name) || data[name] === void 0) continue;
2897
4680
  const key = `composite.${name}`;
2898
- for (const target of input$.targets) {
2899
- const inner = byId.get(target.node);
4681
+ for (const target2 of input$.targets) {
4682
+ const inner = byId.get(target2.node);
2900
4683
  const def = inner === void 0 ? void 0 : registry.widget(inner.type, inner.v);
2901
- if (inner === void 0 || def?.data === void 0 || !Object.hasOwn(def.data, target.input)) continue;
2902
- inner.data = { ...inner.data ?? {}, [target.input]: { source: key } };
4684
+ if (inner === void 0 || def?.data === void 0 || !Object.hasOwn(def.data, target2.input)) continue;
4685
+ inner.data = { ...inner.data ?? {}, [target2.input]: { source: key } };
2903
4686
  innerData[key] = data[name];
2904
4687
  }
2905
4688
  }
@@ -2927,12 +4710,12 @@ function CompositeBody(props) {
2927
4710
  const { snapshot, registry, node, data, locale, mediaOrigin, budget, resolveLink, interactive, idScope } = props;
2928
4711
  const composite = compileComposite(snapshot);
2929
4712
  if (composite === null) return null;
2930
- const built = build({ snapshot, compiled: composite, registry, node, props: props.props, data });
4713
+ const built = build2({ snapshot, compiled: composite, registry, node, props: props.props, data });
2931
4714
  if (!(budget ?? new RenderBudget()).take(built.weight)) {
2932
4715
  warnOnce(`composite-weight:${snapshot.type}@${String(snapshot.v)}`, `${snapshot.type} would render too many nodes; rendering nothing for it`);
2933
4716
  return null;
2934
4717
  }
2935
- return /* @__PURE__ */ jsx31(
4718
+ return /* @__PURE__ */ jsx43(
2936
4719
  BuilderRenderer,
2937
4720
  {
2938
4721
  document: built.document,
@@ -2943,28 +4726,28 @@ function CompositeBody(props) {
2943
4726
  mediaOrigin,
2944
4727
  interactive,
2945
4728
  idScope,
2946
- resolveLink: (target) => built.hrefs.get(JSON.stringify(target)) ?? resolveLink?.(target) ?? null
4729
+ resolveLink: (target2) => built.hrefs.get(JSON.stringify(target2)) ?? resolveLink?.(target2) ?? null
2947
4730
  }
2948
4731
  );
2949
4732
  }
2950
4733
  function CompositeWidget(props) {
2951
- return /* @__PURE__ */ jsx31(PartBoundary, { label: `${props.snapshot.type}@${String(props.snapshot.v)}`, children: /* @__PURE__ */ jsx31(Suspense3, { fallback: null, children: /* @__PURE__ */ jsx31(CompositeBody, { ...props }) }) });
4734
+ return /* @__PURE__ */ jsx43(PartBoundary, { label: `${props.snapshot.type}@${String(props.snapshot.v)}`, children: /* @__PURE__ */ jsx43(Suspense3, { fallback: null, children: /* @__PURE__ */ jsx43(CompositeBody, { ...props }) }) });
2952
4735
  }
2953
4736
 
2954
4737
  // src/custom/factory.ts
2955
4738
  var isDisabled = (snapshot) => snapshot.status === "disabled";
2956
- var Disabled = ({ editMode }) => editMode ? createElement3("div", { className: "tb-missing" }, "This custom widget is disabled") : null;
4739
+ var Disabled = ({ editMode }) => editMode ? createElement5("div", { className: "tb-missing" }, "This custom widget is disabled") : null;
2957
4740
  var customWidgetFactory = (snapshot, registry) => {
2958
4741
  if (isDisabled(snapshot)) return Disabled;
2959
4742
  if (snapshot.kind === "template") {
2960
4743
  const template = compileTemplate(snapshot, registry);
2961
4744
  if (template === null) return null;
2962
- const Component2 = (props) => createElement3(TemplateWidget, { ...props, snapshot, registry });
4745
+ const Component2 = (props) => createElement5(TemplateWidget, { ...props, snapshot, registry });
2963
4746
  componentWeights.set(Component2, template.weight);
2964
4747
  return Component2;
2965
4748
  }
2966
4749
  if (compileComposite(snapshot) === null) return null;
2967
- return (props) => createElement3(CompositeWidget, { ...props, snapshot, registry });
4750
+ return (props) => createElement5(CompositeWidget, { ...props, snapshot, registry });
2968
4751
  };
2969
4752
 
2970
4753
  // src/registry.ts
@@ -2978,11 +4761,11 @@ function createRendererRegistry(packs, options = {}) {
2978
4761
  const sources = [];
2979
4762
  const resolvers = /* @__PURE__ */ new Map();
2980
4763
  for (const pack of all2) {
2981
- for (const { Component: Component2, ...definition } of pack.widgets) {
2982
- const key = customKey(definition.type, definition.v);
4764
+ for (const { Component: Component2, ...definition3 } of pack.widgets) {
4765
+ const key = customKey(definition3.type, definition3.v);
2983
4766
  if (components.has(key)) continue;
2984
4767
  components.set(key, Component2);
2985
- definitions.push(definition);
4768
+ definitions.push(definition3);
2986
4769
  }
2987
4770
  for (const { resolve, ...descriptor } of pack.dataSources) {
2988
4771
  if (resolvers.has(descriptor.id)) continue;
@@ -2991,7 +4774,7 @@ function createRendererRegistry(packs, options = {}) {
2991
4774
  }
2992
4775
  }
2993
4776
  const factory = options.customWidget ?? DEFAULT_CUSTOM_WIDGET;
2994
- const build2 = (custom) => {
4777
+ const build3 = (custom) => {
2995
4778
  const schema = createRegistry(definitions, sources, custom);
2996
4779
  const snapshots = new Map(custom.map((snapshot) => [customKey(snapshot.type, snapshot.v), snapshot]));
2997
4780
  const built = /* @__PURE__ */ new Map();
@@ -3012,16 +4795,16 @@ function createRendererRegistry(packs, options = {}) {
3012
4795
  if (!built.has(key)) built.set(key, factory(snapshot, registry));
3013
4796
  return built.get(key) ?? void 0;
3014
4797
  },
3015
- withCustom: (more) => build2([...custom, ...more])
4798
+ withCustom: (more) => build3([...custom, ...more])
3016
4799
  };
3017
4800
  return registry;
3018
4801
  };
3019
- return build2([]);
4802
+ return build3([]);
3020
4803
  }
3021
4804
 
3022
4805
  // src/slot.tsx
3023
4806
  import { Suspense as Suspense4 } from "react";
3024
- import { jsx as jsx32 } from "react/jsx-runtime";
4807
+ import { jsx as jsx44 } from "react/jsx-runtime";
3025
4808
  function contextKey(context) {
3026
4809
  if (typeof context !== "object" || context === null) return "";
3027
4810
  return Object.values(context).map((value) => {
@@ -3033,232 +4816,46 @@ function contextKey(context) {
3033
4816
  function BuilderSlot({ name, context }) {
3034
4817
  const builder = useBuilder();
3035
4818
  if (builder === null || builder.site.status !== "ok") return null;
3036
- const part = Object.hasOwn(builder.site.slots, name) ? builder.site.slots[name] : void 0;
3037
- if (part === void 0 || part.document.sections.length === 0) return null;
4819
+ const part2 = Object.hasOwn(builder.site.slots, name) ? builder.site.slots[name] : void 0;
4820
+ if (part2 === void 0 || part2.document.sections.length === 0) return null;
3038
4821
  return (
3039
4822
  // Suspense inside the boundary: see parts.tsx.
3040
- /* @__PURE__ */ jsx32(PartBoundary, { label: `Builder slot ${name}`, resetKey: contextKey(context), children: /* @__PURE__ */ jsx32("div", { "data-throttle-part": "builder-slot", "data-b-slot": name, children: /* @__PURE__ */ jsx32(Suspense4, { fallback: null, children: /* @__PURE__ */ jsx32(PartView, { part, context }) }) }) })
4823
+ /* @__PURE__ */ jsx44(PartBoundary, { label: `Builder slot ${name}`, resetKey: contextKey(context), children: /* @__PURE__ */ jsx44("div", { "data-throttle-part": "builder-slot", "data-b-slot": name, children: /* @__PURE__ */ jsx44(Suspense4, { fallback: null, children: /* @__PURE__ */ jsx44(PartView, { part: part2, context }) }) }) })
3041
4824
  );
3042
4825
  }
3043
4826
 
3044
- // src/theme.ts
3045
- import { SITE_FONTS, THEME_CSS_MAX_CHARS, safeUrl as safeUrl12, sanitizeThemeCss } from "@usethrottle/builder-schema";
3046
- import { PRESET_NAMES, PRESET_TOKENS } from "@usethrottle/ui/presets";
3047
- var isRecord5 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
3048
- var str2 = (v) => typeof v === "string" && v !== "" ? v : void 0;
3049
- var HEX = /^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;
3050
- var SCALE = { compact: 0.85, comfortable: 1, roomy: 1.25 };
3051
- var PALETTE_KEYS = Object.keys(PRESET_TOKENS.clean.light);
3052
- function palette(base, over) {
3053
- if (!isRecord5(over)) return base;
3054
- const out = { ...base };
3055
- for (const key of PALETTE_KEYS) {
3056
- const value = over[key];
3057
- if (typeof value === "string" && HEX.test(value)) out[key] = value;
3058
- }
3059
- return out;
3060
- }
3061
- function themeTokens(settings) {
3062
- const theme = isRecord5(settings.theme) ? settings.theme : {};
3063
- const preset = PRESET_NAMES.includes(theme.preset) ? theme.preset : "clean";
3064
- const customized = theme.customized === true;
3065
- const base = PRESET_TOKENS[preset];
3066
- const colorScheme = theme.colorScheme === "light" || theme.colorScheme === "dark" ? theme.colorScheme : "auto";
3067
- if (!customized) return { preset, customized, tokens: base, colorScheme };
3068
- const fonts = isRecord5(theme.fonts) ? theme.fonts : {};
3069
- return {
3070
- preset,
3071
- customized,
3072
- colorScheme,
3073
- tokens: {
3074
- light: palette(base.light, theme.light),
3075
- dark: palette(base.dark, theme.dark),
3076
- fonts: {
3077
- heading: str2(fonts.heading) ?? base.fonts.heading,
3078
- body: str2(fonts.body) ?? base.fonts.body,
3079
- mono: str2(fonts.mono) ?? base.fonts.mono
3080
- },
3081
- radius: typeof theme.radius === "number" && theme.radius >= 0 && theme.radius <= 32 ? theme.radius : base.radius,
3082
- spacingScale: theme.spacingScale === "compact" || theme.spacingScale === "roomy" ? theme.spacingScale : base.spacingScale
3083
- }
3084
- };
3085
- }
3086
- var GENERIC = { serif: "serif", sans: "sans-serif", mono: "monospace", display: "sans-serif" };
3087
- var SYSTEM_STACK = {
3088
- "system-sans": 'system-ui, -apple-system, "Segoe UI", sans-serif',
3089
- "system-serif": 'Georgia, "Times New Roman", serif',
3090
- "system-mono": "ui-monospace, SFMono-Regular, Menlo, monospace"
3091
- };
3092
- function fontStack(family) {
3093
- if (Object.hasOwn(SYSTEM_STACK, family)) return SYSTEM_STACK[family];
3094
- const known = SITE_FONTS.find((f) => f.family === family);
3095
- if (known === void 0 || !/^[A-Za-z0-9 ]{1,60}$/.test(family)) return SYSTEM_STACK["system-sans"];
3096
- return `"${family}", ${Object.hasOwn(GENERIC, known.category) ? GENERIC[known.category] : "sans-serif"}`;
3097
- }
3098
- function variables(p) {
3099
- return {
3100
- colorPrimary: p.colorPrimary,
3101
- colorPrimaryForeground: p.colorPrimaryForeground,
3102
- colorBackground: p.colorBackground,
3103
- colorSurface: p.colorSurface,
3104
- colorForeground: p.colorForeground,
3105
- colorMuted: p.colorMuted,
3106
- colorMutedForeground: p.colorMutedForeground,
3107
- colorBorder: p.colorBorder,
3108
- colorBorderControl: p.colorBorderControl,
3109
- colorSuccess: p.colorSuccess,
3110
- colorWarning: p.colorWarning,
3111
- colorDanger: p.colorDanger
3112
- };
3113
- }
3114
- function appearanceOf(settings) {
3115
- const { tokens, colorScheme } = themeTokens(settings);
3116
- return {
3117
- theme: colorScheme,
3118
- variables: {
3119
- ...variables(tokens.light),
3120
- fontFamily: fontStack(tokens.fonts.body),
3121
- borderRadius: `${String(tokens.radius)}px`
3122
- },
3123
- darkVariables: variables(tokens.dark)
3124
- };
3125
- }
3126
- var kebab = (key) => key.replace(/^color/, "").replace(/([a-z])([A-Z])/g, "$1-$2").replace(/^([A-Z])/, (c) => c.toLowerCase()).toLowerCase();
3127
- function colourDecls(p) {
3128
- return PALETTE_KEYS.map((key) => `--tb-color-${kebab(key)}:${p[key]}`).join(";");
3129
- }
3130
- function themeCss(settings, options = {}) {
3131
- const { tokens, colorScheme } = themeTokens(settings);
3132
- const heading = options.hostFont === true ? "" : `--throttle-font-family-heading:${fontStack(tokens.fonts.heading)};`;
3133
- const light = `:root{--tb-scale:${String(SCALE[tokens.spacingScale])};${heading}${colourDecls(tokens.light)}}`;
3134
- const dark = colourDecls(tokens.dark);
3135
- if (colorScheme === "light") return light;
3136
- if (colorScheme === "dark") return `${light}:root{${dark}}`;
3137
- return `${light}@media (prefers-color-scheme:dark){:root{${dark}}}`;
3138
- }
3139
- function customCssOf(settings) {
3140
- const theme = isRecord5(settings.theme) ? settings.theme : {};
3141
- const css = theme.customCss;
3142
- if (typeof css !== "string" || css.trim() === "" || css.length > THEME_CSS_MAX_CHARS) return "";
3143
- const result = sanitizeThemeCss(css);
3144
- return result.ok ? result.css : "";
3145
- }
3146
- function customCssSheet(css) {
3147
- return css === "" ? "" : `@layer throttle,throttle-custom;@layer throttle-custom{${css}}`;
3148
- }
3149
- function makeResolveLink(settings, packs) {
3150
- const routes = isRecord5(settings.routes) ? settings.routes : {};
3151
- const pageRoute = str2(routes.page) ?? "/pages/{handle}";
3152
- return (target) => {
3153
- for (const pack of packs) {
3154
- const href = pack.linkTargets?.resolve(target) ?? null;
3155
- if (href !== null) return safeUrl12(href, "href", { mediaOrigin: "" });
3156
- }
3157
- if (target.kind === "url") return safeUrl12(target.href, "href", { mediaOrigin: "" });
3158
- if (typeof target.href === "string") return safeUrl12(target.href, "href", { mediaOrigin: "" });
3159
- if (target.kind === "page") {
3160
- const slug = str2(target.slug) ?? str2(target.handle);
3161
- if (slug !== void 0 && /^[A-Za-z0-9._~-]{1,200}$/.test(slug)) {
3162
- return safeUrl12(pageRoute.replace("{handle}", slug), "href", { mediaOrigin: "" });
3163
- }
3164
- }
3165
- return null;
3166
- };
3167
- }
3168
- var MENU_KINDS = /* @__PURE__ */ new Set(["category", "collection", "product", "page", "search", "url"]);
3169
- function menuItems(items, resolve, depth = 0) {
3170
- if (!Array.isArray(items) || depth > 3) return [];
3171
- const out = [];
3172
- for (const item of items) {
3173
- if (!isRecord5(item) || !isRecord5(item.target) || typeof item.target.kind !== "string") continue;
3174
- const label = str2(item.label);
3175
- const href = resolve(item.target);
3176
- if (label === void 0 || href === null) continue;
3177
- const kind = MENU_KINDS.has(item.target.kind) ? item.target.kind : void 0;
3178
- const children = menuItems(item.children, resolve, depth + 1);
3179
- out.push({
3180
- label,
3181
- href,
3182
- ...kind === void 0 ? {} : { kind },
3183
- ...children.length === 0 ? {} : { children }
3184
- });
3185
- }
3186
- return out;
3187
- }
3188
- var assetUrl = (v, mediaOrigin) => {
3189
- const raw = typeof v === "string" ? v : isRecord5(v) ? v.url : void 0;
3190
- return typeof raw === "string" ? safeUrl12(raw, "src", { mediaOrigin }) ?? void 0 : void 0;
3191
- };
3192
- function siteDesignOf(settings, resolve, pageOutlet, mediaOrigin) {
3193
- const { preset, customized, tokens, colorScheme } = themeTokens(settings);
3194
- const brand = isRecord5(settings.brand) ? settings.brand : {};
3195
- const logo = isRecord5(brand.logo) ? brand.logo : {};
3196
- const light = assetUrl(logo.light, mediaOrigin);
3197
- const dark = assetUrl(logo.dark, mediaOrigin);
3198
- const favicon = assetUrl(brand.favicon, mediaOrigin);
3199
- const menus = isRecord5(settings.menus) ? Object.fromEntries(Object.entries(settings.menus).map(([name, items]) => [name, menuItems(items, resolve)])) : {};
3200
- const announcement = isRecord5(settings.announcement) ? settings.announcement : null;
3201
- const message = announcement === null ? void 0 : str2(announcement.message);
3202
- const announcementHref = announcement !== null && isRecord5(announcement.target) && typeof announcement.target.kind === "string" ? resolve(announcement.target) : null;
3203
- const strings = isRecord5(settings.strings) ? Object.fromEntries(Object.entries(settings.strings).filter((entry) => typeof entry[1] === "string")) : {};
3204
- const seo = isRecord5(settings.seo) ? settings.seo : {};
3205
- const routes = isRecord5(settings.routes) ? settings.routes : {};
3206
- const connections = isRecord5(settings.connections) ? settings.connections : {};
3207
- const shareImage = assetUrl(seo.shareImage, mediaOrigin);
3208
- const titleTemplate = str2(seo.titleTemplate);
3209
- const defaultDescription = str2(seo.defaultDescription);
3210
- const pageRoute = str2(routes.page);
3211
- return {
3212
- source: "builder",
3213
- theme: { preset, customized, colorScheme, ...customized ? { values: tokens } : {} },
3214
- brand: {
3215
- ...str2(brand.storeName) === void 0 ? {} : { storeName: str2(brand.storeName) },
3216
- logo: light === void 0 && dark === void 0 ? null : { ...light === void 0 ? {} : { light }, ...dark === void 0 ? {} : { dark } },
3217
- favicon: favicon ?? null
3218
- },
3219
- menus,
3220
- announcement: announcement !== null && announcement.enabled === true && message !== void 0 ? { message, ...announcementHref === null ? {} : { href: announcementHref } } : null,
3221
- strings,
3222
- seo: {
3223
- ...titleTemplate === void 0 ? {} : { titleTemplate },
3224
- ...defaultDescription === void 0 ? {} : { defaultDescription },
3225
- ...shareImage === void 0 ? {} : { shareImage }
3226
- },
3227
- ...pageRoute === void 0 ? {} : { routes: { page: pageRoute } },
3228
- connections: {
3229
- throttlePublishableKey: typeof connections.throttlePublishableKey === "string" ? connections.throttlePublishableKey : null
3230
- },
3231
- ...pageOutlet === void 0 ? {} : { pageOutlet }
3232
- };
3233
- }
3234
-
3235
4827
  // src/provider.tsx
3236
- import { jsx as jsx33, jsxs as jsxs21 } from "react/jsx-runtime";
4828
+ import { jsx as jsx45, jsxs as jsxs32 } from "react/jsx-runtime";
3237
4829
  var EMPTY = {};
4830
+ function loadedAtOf(site) {
4831
+ if (site.status !== "ok" || site.loadedAt === void 0) return void 0;
4832
+ const at = Date.parse(site.loadedAt);
4833
+ return Number.isNaN(at) ? void 0 : at;
4834
+ }
3238
4835
  function useParentFont() {
3239
- return useContext2(AppearanceContext)?.variables?.fontFamily;
4836
+ return useContext3(AppearanceContext)?.variables?.fontFamily;
3240
4837
  }
3241
- function BuilderProvider({ builderKey, client, packs, site, onError, interactive = true, pathname, catalogRoutes, mode = "live", children }) {
4838
+ function BuilderProvider({ builderKey, client, packs, site, onError, interactive = true, pathname, catalogRoutes, routeTable, templateName, ownPagePaths, mode = "live", viewer, page, linkTargets, children }) {
3242
4839
  const packsKey = packs.map((pack) => `${pack.id}@${pack.version}`).join("|");
3243
- const registryRef = useRef3(null);
4840
+ const registryRef = useRef5(null);
3244
4841
  if (registryRef.current?.key !== packsKey) {
3245
4842
  registryRef.current = { key: packsKey, registry: createRendererRegistry(packs) };
3246
4843
  }
3247
4844
  const registry = registryRef.current.registry;
3248
- const builder = useMemo(
4845
+ const builder = useMemo2(
3249
4846
  () => client ?? (builderKey === void 0 ? null : createBuilderClient({ builderKey })),
3250
4847
  [client, builderKey]
3251
4848
  );
3252
4849
  const mediaOrigin = site.status === "ok" ? site.mediaOrigin : "";
3253
4850
  const settings = site.status === "ok" ? site.settings : EMPTY;
3254
- const resolveLink = useMemo(() => makeResolveLink(settings, packs), [settings, packs]);
3255
- const outlets = useRef3(/* @__PURE__ */ new Map());
3256
- const renderers = useRef3(/* @__PURE__ */ new Map());
4851
+ const resolveLink = useMemo2(() => makeResolveLink(settings, packs), [settings, packs]);
4852
+ const outlets = useRef5(/* @__PURE__ */ new Map());
4853
+ const renderers = useRef5(/* @__PURE__ */ new Map());
3257
4854
  const pageOutlet = useCallback((handle) => {
3258
4855
  let outlet = outlets.current.get(handle);
3259
4856
  if (outlet === void 0) {
3260
4857
  outlet = function PageOutlet() {
3261
- return /* @__PURE__ */ jsx33(PartBoundary, { label: `Builder page ${handle}`, children: /* @__PURE__ */ jsx33(Suspense5, { fallback: null, children: /* @__PURE__ */ jsx33(BuilderPage, { slug: handle }) }) });
4858
+ return /* @__PURE__ */ jsx45(PartBoundary, { label: `Builder page ${handle}`, children: /* @__PURE__ */ jsx45(Suspense5, { fallback: null, children: /* @__PURE__ */ jsx45(BuilderPage, { slug: handle }) }) });
3262
4859
  };
3263
4860
  outlets.current.set(handle, outlet);
3264
4861
  }
@@ -3266,12 +4863,12 @@ function BuilderProvider({ builderKey, client, packs, site, onError, interactive
3266
4863
  }, []);
3267
4864
  const resolveSlot = useCallback(
3268
4865
  (name) => {
3269
- const part = site.status === "ok" && Object.hasOwn(site.slots, name) ? site.slots[name] : void 0;
3270
- if (part === void 0 || part.document.sections.length === 0) return null;
4866
+ const part2 = site.status === "ok" && Object.hasOwn(site.slots, name) ? site.slots[name] : void 0;
4867
+ if (part2 === void 0 || part2.document.sections.length === 0) return null;
3271
4868
  let renderer = renderers.current.get(name);
3272
4869
  if (renderer === void 0) {
3273
4870
  renderer = function SlotRenderer({ context }) {
3274
- return /* @__PURE__ */ jsx33(BuilderSlot, { name, context });
4871
+ return /* @__PURE__ */ jsx45(BuilderSlot, { name, context });
3275
4872
  };
3276
4873
  renderers.current.set(name, renderer);
3277
4874
  }
@@ -3279,56 +4876,104 @@ function BuilderProvider({ builderKey, client, packs, site, onError, interactive
3279
4876
  },
3280
4877
  [site]
3281
4878
  );
3282
- const customCss = useMemo(() => site.status === "ok" ? customCssOf(site.settings) : "", [site]);
4879
+ const delivery = useMemo2(() => site.status === "ok" ? customCssDeliveryOf(site.settings, site.theme, mediaOrigin) : { inline: "" }, [site, mediaOrigin]);
4880
+ const customCss = delivery.inline;
4881
+ const customCssHref = delivery.href;
3283
4882
  const configured = settings.routes?.page;
3284
4883
  const pageRoute = typeof configured === "string" ? configured : "/pages/{handle}";
3285
4884
  const catalogKey = catalogRoutes?.join("\n");
3286
- const codeRoutes = useMemo(
3287
- () => ({ page: pageRoute, ...catalogRoutes === void 0 ? {} : { catalog: catalogRoutes } }),
3288
- // `catalogRoutes` is compared by value: a store passes a fresh array each render.
3289
- [pageRoute, catalogKey]
3290
- );
4885
+ const storeRoutes = settings.routes?.store;
4886
+ const tableKey = JSON.stringify(routeTable ?? storeRoutes ?? null);
4887
+ const codeRoutes = useMemo2(() => {
4888
+ const table = routeTable ?? (storeRoutes === void 0 ? void 0 : buildRouteTable(storeRoutes));
4889
+ return {
4890
+ page: pageRoute,
4891
+ ...catalogRoutes === void 0 ? {} : { catalog: catalogRoutes },
4892
+ ...table === void 0 ? {} : { routeTable: table },
4893
+ ...ownPagePaths === void 0 ? {} : { allow: ownPagePaths }
4894
+ };
4895
+ }, [pageRoute, catalogKey, tableKey, ownPagePaths?.join("\n")]);
3291
4896
  useLeaveCodeRoutes(pathname, codeRoutes);
3292
4897
  const leaving = mustLeave(pathname, codeRoutes);
3293
- const value = useMemo(
3294
- () => ({ client: builder, packs, registry, site, locale: site.locale, mediaOrigin, onError, resolveLink, interactive, customCss, mode, pathname, codeRoutes }),
3295
- [builder, packs, registry, site, mediaOrigin, onError, resolveLink, interactive, customCss, mode, pathname, codeRoutes]
4898
+ const pageId = page?.id;
4899
+ const pageTemplate = page?.template;
4900
+ const pageHome = page?.home;
4901
+ const stablePage = useMemo2(
4902
+ () => page === void 0 ? void 0 : { id: pageId, template: pageTemplate, home: pageHome },
4903
+ // eslint-disable-next-line react-hooks/exhaustive-deps
4904
+ [page === void 0, pageId, pageTemplate, pageHome]
4905
+ );
4906
+ const value = useMemo2(
4907
+ () => ({ client: builder, packs, registry, site, locale: site.locale, mediaOrigin, onError, resolveLink, interactive, customCss, mode, pathname, codeRoutes, templateName, page: stablePage, linkTargets }),
4908
+ [builder, packs, registry, site, mediaOrigin, onError, resolveLink, interactive, customCss, mode, pathname, codeRoutes, templateName, stablePage, linkTargets]
3296
4909
  );
3297
- const design = useMemo(
3298
- () => site.status === "ok" ? siteDesignOf(site.settings, resolveLink, pageOutlet, mediaOrigin) : null,
4910
+ const design = useMemo2(
4911
+ () => site.status === "ok" ? siteDesignOf(site.settings, resolveLink, pageOutlet, mediaOrigin, site.locale, loadedAtOf(site)) : null,
3299
4912
  [site, resolveLink, pageOutlet, mediaOrigin]
3300
4913
  );
3301
- const own = useMemo(() => site.status === "ok" ? appearanceOf(site.settings) : void 0, [site]);
4914
+ const own = useMemo2(() => site.status === "ok" ? appearanceOf(site.settings) : void 0, [site]);
3302
4915
  const merged = useAppearanceProviderValue(own);
3303
4916
  const parentFont = useParentFont();
3304
- const appearance = useMemo(() => {
4917
+ const appearance = useMemo2(() => {
3305
4918
  if (own === void 0) return void 0;
3306
4919
  return parentFont === void 0 ? merged : { ...merged, variables: { ...merged.variables, fontFamily: parentFont } };
3307
4920
  }, [own, merged, parentFont]);
3308
- return /* @__PURE__ */ jsx33(BuilderContext.Provider, { value, children: /* @__PURE__ */ jsx33(ThrottleUIProvider, { ...appearance === void 0 ? {} : { appearance }, children: /* @__PURE__ */ jsx33(SiteDesignProvider, { value: design, children: /* @__PURE__ */ jsxs21(SlotOutletProvider, { resolve: resolveSlot, children: [
3309
- site.status === "ok" ? /* @__PURE__ */ jsx33("style", { children: themeCss(site.settings, { hostFont: parentFont !== void 0 }) }) : null,
3310
- customCss === "" ? null : /* @__PURE__ */ jsx33("style", { children: customCssSheet(customCss) }),
3311
- leaving ? /* @__PURE__ */ jsx33("div", { "data-b-leaving": "", hidden: true }) : children
4921
+ return /* @__PURE__ */ jsx45(BuilderContext.Provider, { value, children: /* @__PURE__ */ jsx45(ThrottleUIProvider, { ...appearance === void 0 ? {} : { appearance }, children: /* @__PURE__ */ jsx45(SiteDesignProvider, { value: design, children: /* @__PURE__ */ jsxs32(SlotOutletProvider, { resolve: resolveSlot, children: [
4922
+ site.status === "ok" ? /* @__PURE__ */ jsx45("style", { children: themeCss(site.settings, { hostFont: parentFont !== void 0 }) }) : null,
4923
+ customCss === "" ? null : /* @__PURE__ */ jsx45("style", { children: customCssSheet(customCss) }),
4924
+ customCssHref === void 0 ? null : /* @__PURE__ */ jsx45("link", { rel: "stylesheet", href: customCssHref }),
4925
+ /* @__PURE__ */ jsx45(ViewerContext.Provider, { value: viewer, children: leaving ? /* @__PURE__ */ jsx45("div", { "data-b-leaving": "", hidden: true }) : children })
3312
4926
  ] }) }) }) });
3313
4927
  }
3314
4928
 
3315
4929
  // src/parts.tsx
3316
4930
  import { Suspense as Suspense6 } from "react";
3317
- import { jsx as jsx34 } from "react/jsx-runtime";
4931
+ import { jsx as jsx46 } from "react/jsx-runtime";
3318
4932
  function Part({ name, tag }) {
3319
4933
  const builder = useBuilder();
3320
4934
  if (builder === null || builder.site.status !== "ok") return null;
3321
- const part = builder.site[name];
3322
- if (part.document.sections.length === 0) return null;
4935
+ const part2 = builder.site[name];
4936
+ if (part2.document.sections.length === 0) return null;
3323
4937
  const Tag = tag;
3324
4938
  return (
3325
4939
  // Error boundaries do not catch on the server: the Suspense inside turns a throw
3326
4940
  // during SSR into "render nothing here" and the client retries under the boundary.
3327
- /* @__PURE__ */ jsx34(PartBoundary, { label: `Builder ${name}`, children: /* @__PURE__ */ jsx34(Tag, { "data-throttle-part": `builder-${name}`, children: /* @__PURE__ */ jsx34(Suspense6, { fallback: null, children: /* @__PURE__ */ jsx34(PartView, { part }) }) }) })
4941
+ /* @__PURE__ */ jsx46(PartBoundary, { label: `Builder ${name}`, children: /* @__PURE__ */ jsx46(Tag, { "data-throttle-part": `builder-${name}`, children: /* @__PURE__ */ jsx46(Suspense6, { fallback: null, children: /* @__PURE__ */ jsx46(PartView, { part: part2 }) }) }) })
3328
4942
  );
3329
4943
  }
3330
- var BuilderHeader = () => /* @__PURE__ */ jsx34(Part, { name: "header", tag: "header" });
3331
- var BuilderFooter = () => /* @__PURE__ */ jsx34(Part, { name: "footer", tag: "footer" });
4944
+ var BuilderHeader = () => /* @__PURE__ */ jsx46(Part, { name: "header", tag: "header" });
4945
+ var BuilderFooter = () => /* @__PURE__ */ jsx46(Part, { name: "footer", tag: "footer" });
4946
+
4947
+ // src/template-view.tsx
4948
+ import { Suspense as Suspense7, useMemo as useMemo3 } from "react";
4949
+ import { jsx as jsx47 } from "react/jsx-runtime";
4950
+ function BuilderTemplateView({
4951
+ name,
4952
+ part: part2,
4953
+ context
4954
+ }) {
4955
+ return /* @__PURE__ */ jsx47(PartBoundary, { label: `Builder template ${name}`, children: /* @__PURE__ */ jsx47("div", { "data-throttle-part": "builder-template", "data-b-template": name, children: /* @__PURE__ */ jsx47(Suspense7, { fallback: null, children: /* @__PURE__ */ jsx47(PartView, { part: part2, context }) }) }) });
4956
+ }
4957
+ function BuilderRouteScope({
4958
+ templateName,
4959
+ routeTable,
4960
+ allowPath,
4961
+ children
4962
+ }) {
4963
+ const builder = useBuilder();
4964
+ const tableKey = JSON.stringify(routeTable ?? null);
4965
+ const value = useMemo3(() => {
4966
+ if (builder === null) return null;
4967
+ const codeRoutes = {
4968
+ ...builder.codeRoutes,
4969
+ ...routeTable === void 0 ? {} : { routeTable: { ...builder.codeRoutes.routeTable, ...routeTable } },
4970
+ ...allowPath === void 0 ? {} : { allow: [...builder.codeRoutes.allow ?? [], allowPath] }
4971
+ };
4972
+ return { ...builder, codeRoutes, templateName };
4973
+ }, [builder, templateName, tableKey, allowPath]);
4974
+ if (allowPath !== void 0) allowCodePath(allowPath);
4975
+ return /* @__PURE__ */ jsx47(BuilderContext.Provider, { value, children });
4976
+ }
3332
4977
 
3333
4978
  // src/index.ts
3334
4979
  import { BuilderNotFoundError, BuilderUnavailableError as BuilderUnavailableError2 } from "@usethrottle/builder";
@@ -3344,7 +4989,9 @@ export {
3344
4989
  BuilderPageView,
3345
4990
  BuilderProvider,
3346
4991
  BuilderRenderer,
4992
+ BuilderRouteScope,
3347
4993
  BuilderSlot,
4994
+ BuilderTemplateView,
3348
4995
  BuilderUnavailableError2 as BuilderUnavailableError,
3349
4996
  CODE_ROUTE_DENY,
3350
4997
  CUSTOM_WIDGET_CONTAINMENT,
@@ -3361,6 +5008,7 @@ export {
3361
5008
  basicPack,
3362
5009
  bindingKey,
3363
5010
  bindingsOf,
5011
+ buildRouteTable,
3364
5012
  codeScriptUrl,
3365
5013
  collectBindings,
3366
5014
  compileResponsiveCss,
@@ -3378,5 +5026,6 @@ export {
3378
5026
  pickLocale,
3379
5027
  resolveBindings,
3380
5028
  useBuilder,
5029
+ useViewer,
3381
5030
  validateRender
3382
5031
  };