@usethrottle/builder-react 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -5,9 +5,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
8
+ var __export = (target, all2) => {
9
+ for (var name in all2)
10
+ __defProp(target, name, { get: all2[name], enumerable: true });
11
11
  };
12
12
  var __copyProps = (to, from, except, desc) => {
13
13
  if (from && typeof from === "object" || typeof from === "function") {
@@ -36,9 +36,13 @@ __export(src_exports, {
36
36
  BuilderRenderer: () => BuilderRenderer,
37
37
  BuilderSlot: () => BuilderSlot,
38
38
  BuilderUnavailableError: () => import_builder3.BuilderUnavailableError,
39
+ CODE_ROUTE_DENY: () => CODE_ROUTE_DENY,
39
40
  CUSTOM_WIDGET_CONTAINMENT: () => CUSTOM_WIDGET_CONTAINMENT,
41
+ CodeWidget: () => CodeWidget,
40
42
  CompositeWidget: () => CompositeWidget,
43
+ DEFAULT_CATALOG_ROUTES: () => DEFAULT_CATALOG_ROUTES,
41
44
  MAX_RENDERED_NODES: () => MAX_RENDERED_NODES,
45
+ MissingSavedSection: () => MissingSavedSection,
42
46
  NodeWrapper: () => NodeWrapper,
43
47
  RenderBudget: () => RenderBudget,
44
48
  RichText: () => RichText,
@@ -47,14 +51,18 @@ __export(src_exports, {
47
51
  basicPack: () => basicPack,
48
52
  bindingKey: () => bindingKey,
49
53
  bindingsOf: () => bindingsOf,
54
+ codeScriptUrl: () => codeScriptUrl,
50
55
  collectBindings: () => collectBindings,
51
56
  compileResponsiveCss: () => compileResponsiveCss,
52
57
  createRendererRegistry: () => createRendererRegistry,
53
58
  cssValue: () => cssValue,
54
59
  customWidgetFactory: () => customWidgetFactory,
55
60
  embedSrc: () => embedSrc,
61
+ expandSavedSections: () => expandSavedSections,
56
62
  fitsBudget: () => fitsBudget,
63
+ isCodeRoute: () => isCodeRoute,
57
64
  isFrozenAsset: () => isFrozenAsset,
65
+ jsonForScript: () => jsonForScript,
58
66
  parseRichText: () => parseRichText,
59
67
  parseVideoUrl: () => parseVideoUrl,
60
68
  pickLocale: () => pickLocale,
@@ -65,8 +73,8 @@ __export(src_exports, {
65
73
  module.exports = __toCommonJS(src_exports);
66
74
 
67
75
  // src/renderer.tsx
68
- var import_react = require("react");
69
- var import_builder_schema5 = require("@usethrottle/builder-schema");
76
+ var import_react9 = require("react");
77
+ var import_builder_schema11 = require("@usethrottle/builder-schema");
70
78
 
71
79
  // src/budget.ts
72
80
  var import_builder_schema = require("@usethrottle/builder-schema");
@@ -76,39 +84,842 @@ var RenderBudget = class {
76
84
  this.limit = limit;
77
85
  __publicField(this, "spent", 0);
78
86
  }
79
- /** Takes `count` nodes. False, and nothing taken, when that would pass the limit. */
80
- take(count = 1) {
81
- if (this.spent + count > this.limit) return false;
82
- this.spent += count;
83
- return true;
87
+ /** Takes `count` nodes. False, and nothing taken, when that would pass the limit. */
88
+ take(count = 1) {
89
+ if (this.spent + count > this.limit) return false;
90
+ this.spent += count;
91
+ return true;
92
+ }
93
+ get used() {
94
+ return this.spent;
95
+ }
96
+ get exhausted() {
97
+ return this.spent >= this.limit;
98
+ }
99
+ };
100
+ var fitsBudget = (ast, limit = MAX_RENDERED_NODES) => (0, import_builder_schema.templateWeight)(ast) <= limit;
101
+
102
+ // src/code/code-widget.tsx
103
+ var import_react7 = require("react");
104
+ var import_builder_schema8 = require("@usethrottle/builder-schema");
105
+
106
+ // src/custom/custom-css.tsx
107
+ var import_builder_schema2 = require("@usethrottle/builder-schema");
108
+
109
+ // src/widget-style.tsx
110
+ var import_jsx_runtime = require("react/jsx-runtime");
111
+ function WidgetStyle({ css }) {
112
+ if (css === "" || css.includes("<")) return null;
113
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", { children: css });
114
+ }
115
+
116
+ // src/custom/custom-css.tsx
117
+ var import_jsx_runtime2 = require("react/jsx-runtime");
118
+ function scopedCss(source, type) {
119
+ if (source === void 0 || source === "") return "";
120
+ if (typeof source !== "string") return null;
121
+ const result = (0, import_builder_schema2.sanitizeWidgetCss)(source, type);
122
+ return result.ok ? result.css : null;
123
+ }
124
+ function CustomCss({ css }) {
125
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(WidgetStyle, { css });
126
+ }
127
+
128
+ // src/custom/interpreter.tsx
129
+ var import_react = require("react");
130
+ var import_builder_schema3 = require("@usethrottle/builder-schema");
131
+ var import_jsx_runtime3 = require("react/jsx-runtime");
132
+ var MAX_OUTPUT_CHARS = 1e6;
133
+ var MAX_ATTR_CHARS = 2e3;
134
+ var MAX_DEPTH = 24;
135
+ function newEnv(env) {
136
+ return { ...env, charsLeft: MAX_OUTPUT_CHARS, stopped: false };
137
+ }
138
+ var BLOCKED = /* @__PURE__ */ new Set([
139
+ "__proto__",
140
+ "constructor",
141
+ "prototype",
142
+ ...Object.getOwnPropertyNames(Object.prototype)
143
+ ]);
144
+ var isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
145
+ function step(value, key) {
146
+ if (BLOCKED.has(key) || !isPlainObject(value) || !Object.hasOwn(value, key)) return void 0;
147
+ return value[key];
148
+ }
149
+ function lookup(path, env, scope) {
150
+ const [root, ...rest] = path;
151
+ if (root === void 0) return void 0;
152
+ if (root === "locale") return rest.length === 0 ? env.locale : void 0;
153
+ let value;
154
+ if (root === "settings") value = rest.length === 0 ? void 0 : env.settings;
155
+ else if (root === "data") value = rest.length === 0 ? void 0 : env.data;
156
+ else if (scope.has(root)) value = scope.get(root);
157
+ else return void 0;
158
+ for (const key of rest) {
159
+ value = step(value, key);
160
+ if (value === void 0) return void 0;
161
+ }
162
+ return value;
163
+ }
164
+ function truthy(value) {
165
+ if (value === null || value === void 0 || value === false || value === "") return false;
166
+ if (typeof value === "number") return value !== 0 && !Number.isNaN(value);
167
+ if (Array.isArray(value)) return value.length > 0;
168
+ return true;
169
+ }
170
+ function asText(value) {
171
+ if (typeof value === "string") return value;
172
+ if (typeof value === "number" && Number.isFinite(value)) return String(value);
173
+ return "";
174
+ }
175
+ function filtered(value, filters) {
176
+ let text = asText(value);
177
+ for (const filter of filters) {
178
+ switch (filter.name) {
179
+ case "upper":
180
+ text = text.toUpperCase();
181
+ break;
182
+ case "lower":
183
+ text = text.toLowerCase();
184
+ break;
185
+ case "truncate": {
186
+ const chars = Array.from(text);
187
+ if (chars.length > filter.n) text = `${chars.slice(0, filter.n).join("")}\u2026`;
188
+ break;
189
+ }
190
+ case "default":
191
+ if (text === "") text = filter.text;
192
+ break;
193
+ }
194
+ }
195
+ return text;
196
+ }
197
+ function spend(env, count) {
198
+ if (count > env.charsLeft) {
199
+ env.stopped = true;
200
+ return false;
201
+ }
202
+ env.charsLeft -= count;
203
+ return true;
204
+ }
205
+ var ELEMENTS = new Set(import_builder_schema3.ALLOWED_ELEMENTS);
206
+ var VOIDS = new Set(import_builder_schema3.VOID_ELEMENTS);
207
+ var ROLES = new Set(import_builder_schema3.ALLOWED_ROLES);
208
+ function attrAllowed(tag, name) {
209
+ if (import_builder_schema3.DATA_ATTR_RE.test(name)) return !name.startsWith(import_builder_schema3.RESERVED_DATA_PREFIX);
210
+ const own = Object.hasOwn(import_builder_schema3.ALLOWED_ATTRS, tag) ? import_builder_schema3.ALLOWED_ATTRS[tag] : void 0;
211
+ return (import_builder_schema3.ALLOWED_ATTRS["*"]?.includes(name) ?? false) || (own?.includes(name) ?? false);
212
+ }
213
+ function attrText(attr, env, scope) {
214
+ return attr.value.map((part) => part.type === "text" ? part.value : filtered(lookup(part.path, env, scope), part.filters)).join("");
215
+ }
216
+ function urlSource(attr, env, scope) {
217
+ const [only] = attr.value;
218
+ if (attr.value.length !== 1 || only === void 0 || only.type !== "output") return attrText(attr, env, scope);
219
+ const value = lookup(only.path, env, scope);
220
+ if (isPlainObject(value)) {
221
+ if (typeof value.href === "string") return value.href;
222
+ if (typeof value.url === "string") return value.url;
223
+ return null;
224
+ }
225
+ return value;
226
+ }
227
+ function attrProp(tag, attr, env, scope) {
228
+ const { name } = attr;
229
+ if (!attrAllowed(tag, name)) return null;
230
+ if (name === "href" || name === "src") {
231
+ const safe = (0, import_builder_schema3.safeUrl)(urlSource(attr, env, scope), name, { mediaOrigin: env.mediaOrigin });
232
+ return safe === null || !spend(env, safe.length) ? null : [name, safe];
233
+ }
234
+ const text = attrText(attr, env, scope);
235
+ if (text === "" || text.length > MAX_ATTR_CHARS) return null;
236
+ let value = text;
237
+ if (name === "class") {
238
+ const tokens = text.split(/\s+/).filter((token) => import_builder_schema3.CLASS_TOKEN_RE.test(token) && !(0, import_builder_schema3.isReservedClass)(token));
239
+ if (tokens.length === 0) return null;
240
+ value = tokens.join(" ");
241
+ } else if (name === "role") {
242
+ if (!ROLES.has(text)) return null;
243
+ } else if (name === "aria-hidden") {
244
+ if (text !== "true" && text !== "false") return null;
245
+ }
246
+ if (!spend(env, value.length)) return null;
247
+ return [name === "class" ? "className" : name, value];
248
+ }
249
+ function renderElement(node, env, scope, depth, key) {
250
+ const tag = node.tag;
251
+ if (!ELEMENTS.has(tag)) return null;
252
+ const props = { key };
253
+ for (const attr of node.attrs) {
254
+ const prop = attrProp(tag, attr, env, scope);
255
+ if (prop !== null) props[prop[0]] = prop[1];
256
+ }
257
+ if (VOIDS.has(tag)) return (0, import_react.createElement)(tag, props);
258
+ return (0, import_react.createElement)(tag, props, renderNodes(node.children, env, scope, depth + 1));
259
+ }
260
+ function renderNodes(nodes, env, scope, depth) {
261
+ const out = [];
262
+ if (depth > MAX_DEPTH) return out;
263
+ for (const node of nodes) {
264
+ if (env.stopped) break;
265
+ if (!env.budget.take(1) || node.type === "element" && !env.budget.take(node.attrs.reduce((n, a) => n + a.value.length, 0))) {
266
+ env.stopped = true;
267
+ break;
268
+ }
269
+ switch (node.type) {
270
+ case "text":
271
+ if (spend(env, node.value.length)) out.push(node.value);
272
+ break;
273
+ case "output": {
274
+ const text = filtered(lookup(node.path, env, scope), node.filters);
275
+ if (text !== "" && spend(env, text.length)) out.push(text);
276
+ break;
277
+ }
278
+ case "if": {
279
+ const branch = truthy(lookup(node.path, env, scope)) ? node.then : node.else;
280
+ out.push(/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react.Fragment, { children: renderNodes(branch, env, scope, depth + 1) }, out.length));
281
+ break;
282
+ }
283
+ case "unless":
284
+ if (!truthy(lookup(node.path, env, scope))) {
285
+ out.push(/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react.Fragment, { children: renderNodes(node.body, env, scope, depth + 1) }, out.length));
286
+ }
287
+ break;
288
+ case "each": {
289
+ const list = lookup(node.path, env, scope);
290
+ if (!Array.isArray(list)) break;
291
+ const count = Math.min(list.length, import_builder_schema3.EACH_ITERATION_CAP);
292
+ for (let i = 0; i < count && !env.stopped; i += 1) {
293
+ const inner = new Map(scope).set(node.as, list[i]);
294
+ out.push(/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react.Fragment, { children: renderNodes(node.body, env, inner, depth + 1) }, out.length));
295
+ }
296
+ break;
297
+ }
298
+ case "element":
299
+ out.push(renderElement(node, env, scope, depth, out.length));
300
+ break;
301
+ }
302
+ }
303
+ return out;
304
+ }
305
+ function renderTemplate(ast, env) {
306
+ return renderNodes(ast, env, /* @__PURE__ */ new Map(), 0);
307
+ }
308
+
309
+ // src/custom/template-widget.tsx
310
+ var import_react5 = require("react");
311
+ var import_builder_schema7 = require("@usethrottle/builder-schema");
312
+
313
+ // src/part-view.tsx
314
+ var import_react4 = require("react");
315
+
316
+ // src/context.ts
317
+ var import_react2 = require("react");
318
+ function codeRenderOf(builder, runtime) {
319
+ return { runtime, pathname: builder.pathname, routes: builder.codeRoutes, preview: builder.mode === "preview" };
320
+ }
321
+ var BuilderContext = typeof import_react2.createContext === "function" ? (0, import_react2.createContext)(null) : null;
322
+ var useBuilder = () => (0, import_react2.useContext)(BuilderContext);
323
+
324
+ // src/saved-section.tsx
325
+ var import_builder_schema5 = require("@usethrottle/builder-schema");
326
+
327
+ // src/node-wrapper.tsx
328
+ var import_builder_schema4 = require("@usethrottle/builder-schema");
329
+ var import_jsx_runtime4 = require("react/jsx-runtime");
330
+ var CUSTOM_WIDGET_CONTAINMENT = {
331
+ contain: "layout paint",
332
+ isolation: "isolate",
333
+ overflow: "clip"
334
+ };
335
+ var PART_NAME = {
336
+ section: "builder-section",
337
+ column: "builder-column",
338
+ widget: "builder-widget"
339
+ };
340
+ function NodeWrapper(props) {
341
+ const { id, part, type, className, anchor, copyAnchor, custom, missing, attributes, edit, entrance, children } = props;
342
+ const Tag = props.as ?? "div";
343
+ const handlers = edit === void 0 ? {} : {
344
+ onClickCapture: (event) => {
345
+ const target = event.target;
346
+ if (target?.closest?.("a[href]") != null) event.preventDefault();
347
+ },
348
+ onClick: (event) => {
349
+ event.stopPropagation();
350
+ edit.onSelect(id);
351
+ },
352
+ onMouseOver: (event) => {
353
+ event.stopPropagation();
354
+ edit.onHover(id);
355
+ },
356
+ onMouseLeave: () => edit.onHover(null)
357
+ };
358
+ const style = custom === true || entrance !== void 0 ? {
359
+ ...custom === true ? CUSTOM_WIDGET_CONTAINMENT : {},
360
+ ...entrance !== void 0 && entrance.delayMs > 0 ? { "--tb-ed": `${String(entrance.delayMs)}ms` } : {}
361
+ } : void 0;
362
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
363
+ Tag,
364
+ {
365
+ className,
366
+ "data-b-id": id,
367
+ "data-throttle-part": PART_NAME[part],
368
+ ...type === void 0 ? {} : { "data-b-type": type },
369
+ ...custom === true && type !== void 0 ? { "data-b-w": type } : {},
370
+ ...missing === true ? { "data-b-missing": "" } : {},
371
+ ...attributes,
372
+ ...typeof anchor === "string" && import_builder_schema4.ANCHOR_RE.test(anchor) ? { id: anchor } : {},
373
+ ...typeof copyAnchor === "string" && import_builder_schema4.ANCHOR_RE.test(copyAnchor) ? { "data-b-anchor": copyAnchor } : {},
374
+ ...entrance === void 0 ? {} : { "data-b-entrance": entrance.name },
375
+ ...style === void 0 || Object.keys(style).length === 0 ? {} : { style },
376
+ ...handlers,
377
+ children
378
+ }
379
+ );
380
+ }
381
+
382
+ // src/warn.ts
383
+ var seen = /* @__PURE__ */ new Set();
384
+ function warnOnce(key, message) {
385
+ if (seen.has(key)) return;
386
+ seen.add(key);
387
+ console.warn(`[throttle-builder] ${message}`);
388
+ }
389
+ var isDevelopment = () => typeof process === "undefined" || process.env?.NODE_ENV !== "production";
390
+
391
+ // src/saved-section.tsx
392
+ var import_jsx_runtime5 = require("react/jsx-runtime");
393
+ var pid = (refId, id) => `${refId}-${id}`;
394
+ var MAX_EXPANDED_NODES = 2e4;
395
+ function prefixAnchor(refId, props) {
396
+ const anchor = props.anchor;
397
+ if (typeof anchor !== "string") return props;
398
+ const prefixed = pid(refId, anchor);
399
+ const { anchor: _drop, ...rest } = props;
400
+ void _drop;
401
+ return import_builder_schema5.ANCHOR_RE.test(prefixed) ? { ...rest, anchor: prefixed } : rest;
402
+ }
403
+ function prefixColumn(refId, column) {
404
+ return {
405
+ ...column,
406
+ id: pid(refId, column.id),
407
+ props: prefixAnchor(refId, column.props),
408
+ children: column.children.map(
409
+ (child) => child.type === "inner-section" ? prefixSection(refId, child) : { ...child, id: pid(refId, child.id), props: prefixAnchor(refId, child.props) }
410
+ )
411
+ };
412
+ }
413
+ function prefixSection(refId, section) {
414
+ return {
415
+ ...section,
416
+ id: pid(refId, section.id),
417
+ props: prefixAnchor(refId, section.props),
418
+ columns: section.columns.map((column) => prefixColumn(refId, column))
419
+ };
420
+ }
421
+ var parsed = /* @__PURE__ */ new WeakMap();
422
+ function sectionOf(entry) {
423
+ const cached = parsed.get(entry);
424
+ if (cached !== void 0) return cached;
425
+ const result = import_builder_schema5.sectionNodeSchema.safeParse(entry.section);
426
+ const section = result.success ? result.data : null;
427
+ parsed.set(entry, section);
428
+ return section;
429
+ }
430
+ var sized = /* @__PURE__ */ new WeakMap();
431
+ function sizeOf(section) {
432
+ const known = sized.get(section);
433
+ if (known !== void 0) return known;
434
+ let size = 0;
435
+ (0, import_builder_schema5.walkNodes)({ sections: [section] }, () => {
436
+ size += 1;
437
+ });
438
+ sized.set(section, size);
439
+ return size;
440
+ }
441
+ var cache = /* @__PURE__ */ new WeakMap();
442
+ var NONE = {};
443
+ function expandSavedSections(source, answer) {
444
+ if (!source.sections.some((root) => root.type === "saved-section")) return { doc: source, roots: null };
445
+ let perAnswer = cache.get(source);
446
+ if (perAnswer === void 0) {
447
+ perAnswer = /* @__PURE__ */ new WeakMap();
448
+ cache.set(source, perAnswer);
449
+ }
450
+ const key = answer ?? NONE;
451
+ const known = perAnswer.get(key);
452
+ if (known !== void 0) return known;
453
+ const made = expand(source, answer);
454
+ perAnswer.set(key, made);
455
+ return made;
456
+ }
457
+ function expand(source, answer) {
458
+ const sections = [];
459
+ const roots = [];
460
+ const snapshots = {};
461
+ let nodes = 0;
462
+ (0, import_builder_schema5.walkNodes)({ sections: source.sections.filter((root) => root.type === "section") }, () => {
463
+ nodes += 1;
464
+ });
465
+ for (const root of source.sections) {
466
+ if (root.type === "section") {
467
+ sections.push(root);
468
+ roots.push({ kind: "section", id: root.id });
469
+ continue;
470
+ }
471
+ const entry = answer !== void 0 && Object.hasOwn(answer, root.ref) ? answer[root.ref] : void 0;
472
+ const section = entry === void 0 ? null : sectionOf(entry);
473
+ if (entry !== void 0 && section !== null && nodes + sizeOf(section) > MAX_EXPANDED_NODES) {
474
+ warnOnce("saved-section-cap", `A page holds more than ${String(MAX_EXPANDED_NODES)} nodes with its saved sections; the rest are left out`);
475
+ roots.push({ kind: "ref", ref: root, sectionId: null });
476
+ continue;
477
+ }
478
+ if (entry === void 0 || section === null) {
479
+ roots.push({ kind: "ref", ref: root, sectionId: null });
480
+ continue;
481
+ }
482
+ nodes += sizeOf(section);
483
+ const prefixed = prefixSection(root.id, section);
484
+ const anchor = root.props.anchor;
485
+ const placed = anchor !== void 0 ? { ...prefixed, props: { ...prefixed.props, anchor } } : prefixed;
486
+ sections.push(placed);
487
+ roots.push({ kind: "ref", ref: root, sectionId: placed.id });
488
+ for (const [snapshotKey, snapshot] of Object.entries(entry.customWidgets ?? {})) {
489
+ if (import_builder_schema5.anyCustomWidgetSnapshotSchema.safeParse(snapshot).success) snapshots[snapshotKey] = snapshot;
490
+ }
491
+ }
492
+ const customWidgets = { ...snapshots, ...source.customWidgets };
493
+ return {
494
+ doc: { ...source, sections, ...Object.keys(customWidgets).length === 0 ? {} : { customWidgets } },
495
+ roots
496
+ };
497
+ }
498
+ function MissingSavedSection({ node }) {
499
+ warnOnce(`saved-section:${node.ref}`, `Saved section ${node.ref} has no published section; rendering nothing for it`);
500
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(NodeWrapper, { id: node.id, part: "section", as: "section", className: "tb-section", missing: true });
501
+ }
502
+
503
+ // src/shopper-data.ts
504
+ var import_react3 = require("react");
505
+
506
+ // src/data.ts
507
+ var import_builder_schema6 = require("@usethrottle/builder-schema");
508
+ function stable(value) {
509
+ if (Array.isArray(value)) return `[${value.map(stable).join(",")}]`;
510
+ if (typeof value === "object" && value !== null) {
511
+ const entries2 = Object.entries(value).filter(([, item]) => item !== void 0).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
512
+ return `{${entries2.map(([k, v]) => `${JSON.stringify(k)}:${stable(v)}`).join(",")}}`;
513
+ }
514
+ return JSON.stringify(value) ?? "null";
515
+ }
516
+ function bindingKey(binding) {
517
+ return "params" in binding ? `${binding.source}?${stable(binding.params)}` : binding.source;
518
+ }
519
+ var isContextBinding = (binding) => binding.source.startsWith("context.");
520
+ function bindingsOf(node, registry) {
521
+ const def = registry.widget(node.type, node.v);
522
+ const out = {};
523
+ for (const [name, input] of Object.entries(def?.data ?? {})) {
524
+ if (input.default !== void 0) out[name] = input.default;
525
+ }
526
+ return { ...out, ...node.data ?? {} };
527
+ }
528
+ function collectBindings(doc, registry) {
529
+ const found = /* @__PURE__ */ new Map();
530
+ (0, import_builder_schema6.walkNodes)(doc, (node) => {
531
+ if (node.type === "section" || node.type === "inner-section" || node.type === "column" || node.type === "saved-section") {
532
+ return;
533
+ }
534
+ for (const binding of Object.values(bindingsOf(node, registry))) {
535
+ const key = bindingKey(binding);
536
+ if (!found.has(key)) found.set(key, binding);
537
+ }
538
+ });
539
+ return found;
540
+ }
541
+ async function resolveBindings(bindings, registry, ctx, options) {
542
+ const jobs = [];
543
+ for (const [key, binding] of bindings) {
544
+ if (isContextBinding(binding) || !("params" in binding)) continue;
545
+ const descriptor = registry.source(binding.source);
546
+ const resolve = registry.resolver(binding.source);
547
+ if (descriptor === void 0 || resolve === void 0) continue;
548
+ if (options.include === "static" && descriptor.perShopper) continue;
549
+ if (options.include === "shopper" && !descriptor.perShopper) continue;
550
+ jobs.push(
551
+ resolve(binding.params, ctx).then(
552
+ (value) => [key, value],
553
+ (error) => {
554
+ warnOnce(`resolve:${binding.source}`, `Data source ${binding.source} failed (${String(error)}); its widgets render without data`);
555
+ return null;
556
+ }
557
+ )
558
+ );
559
+ }
560
+ const settled = await Promise.all(jobs);
561
+ return Object.fromEntries(settled.filter((entry) => entry !== null));
562
+ }
563
+
564
+ // src/shopper-data.ts
565
+ function useResolvedData(document2, registry, locale, include, context) {
566
+ const [data, setData] = (0, import_react3.useState)({});
567
+ (0, import_react3.useEffect)(() => {
568
+ const controller = new AbortController();
569
+ const bindings = collectBindings(document2, registry);
570
+ if (bindings.size === 0) return void 0;
571
+ void resolveBindings(
572
+ bindings,
573
+ registry,
574
+ { locale, preview: false, context, signal: controller.signal },
575
+ { include }
576
+ ).then((resolved) => {
577
+ if (!controller.signal.aborted && Object.keys(resolved).length > 0) setData(resolved);
578
+ });
579
+ return () => controller.abort();
580
+ }, [document2, registry, locale, include, context]);
581
+ return data;
582
+ }
583
+
584
+ // src/part-view.tsx
585
+ var import_jsx_runtime6 = require("react/jsx-runtime");
586
+ var BoundaryBase = import_react4.Component ?? class {
587
+ };
588
+ var Boundary = class extends BoundaryBase {
589
+ constructor() {
590
+ super(...arguments);
591
+ __publicField(this, "state", { failed: false });
592
+ }
593
+ static getDerivedStateFromError() {
594
+ return { failed: true };
84
595
  }
85
- get used() {
86
- return this.spent;
596
+ componentDidCatch(error, _info) {
597
+ warnOnce(`part:${this.props.label}`, `${this.props.label} failed to render (${String(error)}); rendering nothing for it`);
598
+ try {
599
+ this.props.onError?.(error, { part: this.props.label });
600
+ } catch {
601
+ }
87
602
  }
88
- get exhausted() {
89
- return this.spent >= this.limit;
603
+ componentDidUpdate(previous) {
604
+ const moved = previous.resetKeys.length !== this.props.resetKeys.length || previous.resetKeys.some((key, i) => !Object.is(key, this.props.resetKeys[i]));
605
+ if (moved && this.state.failed) this.setState({ failed: false });
606
+ }
607
+ render() {
608
+ return this.state.failed ? null : this.props.children;
90
609
  }
91
610
  };
92
- var fitsBudget = (ast, limit = MAX_RENDERED_NODES) => (0, import_builder_schema.templateWeight)(ast) <= limit;
611
+ function PartBoundary({
612
+ label,
613
+ resetKey,
614
+ children
615
+ }) {
616
+ const builder = useBuilder();
617
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Boundary, { label, resetKeys: [builder?.site, resetKey], onError: builder?.onError, children });
618
+ }
619
+ function contextData(context) {
620
+ if (typeof context !== "object" || context === null) return {};
621
+ return Object.fromEntries(Object.entries(context).map(([key, value]) => [`context.${key}`, value]));
622
+ }
623
+ function PartView({ part, context }) {
624
+ const builder = useBuilder();
625
+ if (builder === null) return null;
626
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(PartBody, { part, context, builder });
627
+ }
628
+ function PartBody({
629
+ part,
630
+ context,
631
+ builder
632
+ }) {
633
+ const expanded = expandSavedSections(part.document, part.savedSections).doc;
634
+ const shopper = useResolvedData(expanded, builder.registry, builder.locale, "shopper", context);
635
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
636
+ BuilderRenderer,
637
+ {
638
+ document: part.document,
639
+ registry: builder.registry,
640
+ data: { ...part.initialData, ...contextData(context), ...shopper },
641
+ locale: builder.locale,
642
+ assets: part.assets,
643
+ mediaOrigin: builder.mediaOrigin,
644
+ resolveLink: builder.resolveLink,
645
+ interactive: builder.interactive,
646
+ scopeCustomCss: builder.customCss !== "",
647
+ savedSections: part.savedSections,
648
+ code: codeRenderOf(builder, part.code)
649
+ }
650
+ );
651
+ }
93
652
 
94
- // src/css-compiler.ts
95
- var import_builder_schema2 = require("@usethrottle/builder-schema");
653
+ // src/custom/template-widget.tsx
654
+ var import_jsx_runtime7 = require("react/jsx-runtime");
655
+ var componentWeights = /* @__PURE__ */ new WeakMap();
656
+ var compiled = /* @__PURE__ */ new WeakMap();
657
+ function compileTemplate(snapshot, registry) {
658
+ let perRegistry = compiled.get(snapshot);
659
+ if (perRegistry === void 0) {
660
+ perRegistry = /* @__PURE__ */ new WeakMap();
661
+ compiled.set(snapshot, perRegistry);
662
+ }
663
+ if (perRegistry.has(registry)) return perRegistry.get(registry) ?? null;
664
+ const result = compile(snapshot, registry);
665
+ perRegistry.set(registry, result);
666
+ return result;
667
+ }
668
+ function compile(snapshot, registry) {
669
+ const label = `${snapshot.type}@${String(snapshot.v)}`;
670
+ const refuse = (why) => {
671
+ warnOnce(`template:${label}`, `${label} was refused (${why}); rendering nothing for it`);
672
+ return null;
673
+ };
674
+ if (snapshot.kind !== "template") return refuse("not a template widget");
675
+ const source = snapshot.template;
676
+ if (typeof source !== "string") return refuse("no template source");
677
+ const parsed2 = (0, import_builder_schema7.parseTemplate)(source);
678
+ if (!parsed2.ok) return refuse(`template does not parse: ${parsed2.issues[0]?.message ?? "invalid"}`);
679
+ const data = snapshot.data;
680
+ const issues = (0, import_builder_schema7.validateTemplate)(parsed2.ast, {
681
+ settings: snapshot.settings,
682
+ data: typeof data === "object" && data !== null ? data : {},
683
+ sources: registry.sources()
684
+ });
685
+ if (issues.length > 0) return refuse(`template does not validate: ${issues[0]?.message ?? "invalid"}`);
686
+ if (!fitsBudget(parsed2.ast)) return refuse(`it can render more than ${String(import_builder_schema7.MAX_TEMPLATE_WEIGHT)} nodes`);
687
+ const css = scopedCss(snapshot.css, snapshot.type);
688
+ if (css === null) return refuse("its css does not pass the sanitiser");
689
+ return { ast: parsed2.ast, css, weight: (0, import_builder_schema7.templateWeight)(parsed2.ast) };
690
+ }
691
+ function TemplateBody({ snapshot, registry, props, data, locale, mediaOrigin, budget }) {
692
+ const template = compileTemplate(snapshot, registry);
693
+ if (template === null) return null;
694
+ const env = newEnv({ settings: props, data, locale, mediaOrigin, budget: budget ?? new RenderBudget() });
695
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
696
+ template.css === "" ? null : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CustomCss, { css: template.css }),
697
+ renderTemplate(template.ast, env)
698
+ ] });
699
+ }
700
+ function TemplateWidget(props) {
701
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(PartBoundary, { label: `${props.snapshot.type}@${String(props.snapshot.v)}`, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react5.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(TemplateBody, { ...props }) }) });
702
+ }
96
703
 
97
- // src/warn.ts
98
- var seen = /* @__PURE__ */ new Set();
99
- function warnOnce(key, message) {
100
- if (seen.has(key)) return;
101
- seen.add(key);
102
- console.warn(`[throttle-builder] ${message}`);
704
+ // src/code/leave.ts
705
+ var import_react6 = require("react");
706
+
707
+ // src/code/reload.ts
708
+ function reloadHere() {
709
+ window.location.assign(window.location.href);
710
+ }
711
+
712
+ // src/code/routes.ts
713
+ 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].*)?$/i;
714
+ var DEFAULT_CATALOG_ROUTES = [
715
+ "/p/{handle}",
716
+ "/c/{handle}",
717
+ "/collections/{handle}",
718
+ "/tags/{tag}",
719
+ "/search",
720
+ "/shop"
721
+ ];
722
+ function normalizePath(pathname) {
723
+ const bare = pathname.split(/[?#]/, 1)[0] ?? "";
724
+ let decoded2 = bare;
725
+ try {
726
+ for (let i = 0; i < 3; i++) {
727
+ let next;
728
+ try {
729
+ next = decodeURIComponent(decoded2);
730
+ } catch (error) {
731
+ if (i === 0) throw error;
732
+ break;
733
+ }
734
+ if (next === decoded2) break;
735
+ decoded2 = next;
736
+ }
737
+ } catch {
738
+ return null;
739
+ }
740
+ if (decoded2.includes("\0")) return null;
741
+ const flat = decoded2.replace(/\\/g, "/");
742
+ if (!flat.startsWith("/")) return null;
743
+ const out = [];
744
+ for (const segment of flat.split("/")) {
745
+ if (segment === "" || segment === ".") continue;
746
+ if (segment === "..") out.pop();
747
+ else out.push(segment);
748
+ }
749
+ return `/${out.join("/")}`;
750
+ }
751
+ var escapeRegExp = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
752
+ var compiled2 = /* @__PURE__ */ new Map();
753
+ var MAX_COMPILED = 64;
754
+ function matcherOf(template) {
755
+ const known = compiled2.get(template);
756
+ if (known !== void 0) return known;
757
+ let regex = null;
758
+ if (template.startsWith("/")) {
759
+ 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(/\/+$/, "");
760
+ regex = new RegExp(`^${pattern === "" ? "/" : pattern}$`);
761
+ }
762
+ if (compiled2.size >= MAX_COMPILED) compiled2.clear();
763
+ compiled2.set(template, regex);
764
+ return regex;
765
+ }
766
+ var matchesTemplate = (path, template) => matcherOf(template)?.test(path) ?? false;
767
+ function isCodeRoute(pathname, routes) {
768
+ if (pathname === void 0) return false;
769
+ const path = normalizePath(pathname);
770
+ if (path === null) return false;
771
+ if (path.split("/").some((segment) => CODE_ROUTE_DENY.test(segment))) return false;
772
+ if (path === "/") return true;
773
+ return [routes.page, ...routes.catalog ?? DEFAULT_CATALOG_ROUTES].some((template) => matchesTemplate(path, template));
774
+ }
775
+
776
+ // src/code/leave.ts
777
+ var emitted = false;
778
+ function markCodeEmitted() {
779
+ emitted = true;
780
+ }
781
+ function mustLeave(pathname, routes) {
782
+ return emitted && typeof window !== "undefined" && pathname !== void 0 && !isCodeRoute(pathname, routes);
783
+ }
784
+ function useLeaveCodeRoutes(pathname, routes) {
785
+ (0, import_react6.useEffect)(() => {
786
+ if (mustLeave(pathname, routes)) reloadHere();
787
+ }, [pathname, routes]);
788
+ const latest = (0, import_react6.useRef)(routes);
789
+ latest.current = routes;
790
+ (0, import_react6.useEffect)(
791
+ () => () => {
792
+ if (mustLeave(window.location.pathname, latest.current)) reloadHere();
793
+ },
794
+ []
795
+ );
796
+ }
797
+
798
+ // src/code/code-widget.tsx
799
+ var import_jsx_runtime8 = require("react/jsx-runtime");
800
+ var SHA256_HEX = /^[0-9a-f]{64}$/;
801
+ var CUSTOM_TYPE = /^custom\.[a-z][a-z0-9-]{0,63}$/;
802
+ var SCRIPT_ORIGIN = /^https:\/\/[a-z0-9]([a-z0-9.-]*[a-z0-9])?(:[0-9]{1,5})?$/i;
803
+ var SITE_ID = /^[A-Za-z0-9_-]{1,64}$/;
804
+ var MAX_INPUT_CHARS = 2e5;
805
+ var isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
806
+ var checked = /* @__PURE__ */ new WeakMap();
807
+ function check(raw, registry) {
808
+ let perRegistry = checked.get(raw);
809
+ if (perRegistry === void 0) {
810
+ perRegistry = /* @__PURE__ */ new WeakMap();
811
+ checked.set(raw, perRegistry);
812
+ }
813
+ const known = perRegistry.get(registry);
814
+ if (known !== void 0) return known;
815
+ const result = verify(raw, registry);
816
+ perRegistry.set(registry, result);
817
+ return result;
818
+ }
819
+ function verify(raw, registry) {
820
+ const snapshot = raw;
821
+ const label = `${String(snapshot.type)}@${String(snapshot.v)}`;
822
+ if (snapshot.disabled === true) return { status: "disabled" };
823
+ const refuse = (why) => {
824
+ warnOnce(`code:${label}`, `Code widget ${label} was refused (${why}); rendering nothing for it`);
825
+ return { status: "invalid" };
826
+ };
827
+ if (snapshot.kind !== "code") return refuse("not a code widget");
828
+ if (typeof snapshot.type !== "string" || !CUSTOM_TYPE.test(snapshot.type)) return refuse("bad type");
829
+ if (snapshot.disabled !== void 0) return refuse("bad disabled flag");
830
+ if ("js" in snapshot) return refuse("it carries a script");
831
+ if (typeof snapshot.jsHash !== "string" || !SHA256_HEX.test(snapshot.jsHash)) return refuse("bad script hash");
832
+ if (typeof snapshot.html !== "string" || snapshot.html.length > import_builder_schema8.LIMITS.codeHtmlBytes) return refuse("bad html");
833
+ if (typeof snapshot.css !== "string" || snapshot.css.length > import_builder_schema8.LIMITS.codeCssBytes) return refuse("bad css");
834
+ const template = { ...snapshot, kind: "template", template: snapshot.html };
835
+ if (compileTemplate(template, registry) === null) return refuse("its markup or css does not validate");
836
+ return { status: "ok", snapshot: raw, template };
837
+ }
838
+ function codeScriptUrl(runtime, jsHash) {
839
+ if (!isRecord(runtime) || runtime.enabled !== true) return null;
840
+ const { scriptOrigin, codeSiteId } = runtime;
841
+ if (typeof scriptOrigin !== "string" || !SCRIPT_ORIGIN.test(scriptOrigin)) return null;
842
+ if (typeof codeSiteId !== "string" || !SITE_ID.test(codeSiteId)) return null;
843
+ if (!SHA256_HEX.test(jsHash)) return null;
844
+ return `${scriptOrigin}/v1/code/${codeSiteId}/${jsHash}.js`;
845
+ }
846
+ function jsonForScript(value) {
847
+ return JSON.stringify(value).replace(/[<>&\u2028\u2029]/g, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`);
848
+ }
849
+ var BADGE = {
850
+ display: "inline-block",
851
+ margin: 4,
852
+ padding: "2px 8px",
853
+ borderRadius: 4,
854
+ font: "600 11px/1.5 system-ui, sans-serif",
855
+ letterSpacing: "0.02em",
856
+ background: "#1f2937",
857
+ color: "#fff"
858
+ };
859
+ function runs(props, jsHash) {
860
+ const { code, edit, interactive } = props;
861
+ if (edit !== void 0 || interactive === false || code === void 0 || code.preview === true) return null;
862
+ if (!isCodeRoute(code.pathname, code.routes)) return null;
863
+ return codeScriptUrl(code.runtime, jsHash);
864
+ }
865
+ function CodeWidget(props) {
866
+ const { node, snapshot, registry, edit, anchor, copyAnchor, entrance } = props;
867
+ const result = check(snapshot, registry);
868
+ if (result.status !== "ok") {
869
+ return result.status === "disabled" && edit !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(NodeWrapper, { id: node.id, part: "widget", type: node.type, className: "tb-w", edit, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "tb-missing", children: "This code widget is disabled" }) }) : null;
870
+ }
871
+ const template = compileTemplate(result.template, registry);
872
+ const src = runs(props, result.snapshot.jsHash);
873
+ if (src !== null) markCodeEmitted();
874
+ const env = newEnv({ settings: props.props, data: props.data, locale: props.locale, mediaOrigin: props.mediaOrigin, budget: new RenderBudget() });
875
+ const label = `${node.type}@${String(node.v)}`;
876
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
877
+ NodeWrapper,
878
+ {
879
+ id: node.id,
880
+ part: "widget",
881
+ type: node.type,
882
+ custom: true,
883
+ edit,
884
+ className: "tb-w",
885
+ anchor,
886
+ copyAnchor,
887
+ entrance,
888
+ attributes: src === null ? { "data-b-code-inert": "" } : { "data-b-code": result.snapshot.jsHash },
889
+ children: [
890
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(PartBoundary, { label, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_react7.Suspense, { fallback: null, children: [
891
+ template.css === "" ? null : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(CustomCss, { css: template.css }),
892
+ renderTemplate(template.ast, env)
893
+ ] }) }),
894
+ src === null && (edit !== void 0 || props.code?.preview === true) ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { "data-b-code-badge": "", style: BADGE, children: "Runs on your store" }) : null,
895
+ src === null ? null : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(CodeInput, { props: props.props, data: props.data, label }),
896
+ src === null ? null : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("script", { async: true, src })
897
+ ]
898
+ }
899
+ );
900
+ }
901
+ function CodeInput({ props, data, label }) {
902
+ let json = "";
903
+ try {
904
+ json = jsonForScript({ props, data });
905
+ if (json.length > MAX_INPUT_CHARS) {
906
+ warnOnce(`code-input:${label}`, `The data of ${label} is too large for its code input; it gets its props only`);
907
+ json = jsonForScript({ props, data: {} });
908
+ }
909
+ } catch {
910
+ warnOnce(`code-input:${label}`, `The input of ${label} cannot be written as JSON; it gets none`);
911
+ json = jsonForScript({ props: {}, data: {} });
912
+ }
913
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("script", { type: "application/json", "data-b-code-input": "", children: json });
103
914
  }
104
- var isDevelopment = () => typeof process === "undefined" || process.env?.NODE_ENV !== "production";
105
915
 
106
916
  // src/css-compiler.ts
917
+ var import_builder_schema9 = require("@usethrottle/builder-schema");
107
918
  var TABLET_QUERY = "(max-width:1024px)";
108
919
  var PHONE_QUERY = "(max-width:767px)";
109
920
  var SAFE_VALUE = /^[A-Za-z0-9#%.,()\-+*/_: ]{1,200}$/;
110
921
  var URL_QUOTE_SAFE = /^[^\s"'\\()<>{};]+$/;
111
- var ID_RE = /^[a-z0-9]{8,24}$/;
922
+ var ID_RE = /^[a-z0-9]{8,24}(-[a-z0-9]{8,24})?$/;
112
923
  var PROPERTY_RE = /^--(?:b|w|tb)-[A-Za-z][A-Za-z0-9-]{0,39}$/;
113
924
  var COLOR_TOKEN = /* @__PURE__ */ new Set([
114
925
  "primary",
@@ -176,7 +987,7 @@ function put(out, property, value) {
176
987
  }
177
988
  out.set(property, value);
178
989
  }
179
- var COMMON_BY_KEY = new Map(import_builder_schema2.COMMON_WIDGET_SETTINGS.map((field) => [field.key, field]));
990
+ var COMMON_BY_KEY = new Map(import_builder_schema9.COMMON_WIDGET_SETTINGS.map((field) => [field.key, field]));
180
991
  function widgetDecls(node, device, registry) {
181
992
  const out = /* @__PURE__ */ new Map();
182
993
  const def = registry.widget(node.type, node.v);
@@ -184,12 +995,12 @@ function widgetDecls(node, device, registry) {
184
995
  const fields = new Map([...COMMON_BY_KEY, ...def.settings.map((f) => [f.key, f])]);
185
996
  const defaults = {};
186
997
  for (const field of fields.values()) if (field.output === "css") defaults[field.key] = field.default;
187
- const resolved = (0, import_builder_schema2.resolveResponsive)({ ...defaults, ...node.props }, node.responsive, device);
998
+ const resolved = (0, import_builder_schema9.resolveResponsive)({ ...defaults, ...node.props }, node.responsive, device);
188
999
  const prefix = node.type.startsWith("custom.") ? "--w-" : "--b-";
189
1000
  for (const field of fields.values()) {
190
1001
  if (field.output !== "css") continue;
191
1002
  const raw = resolved[field.key];
192
- const value = raw === void 0 || (0, import_builder_schema2.validateSettingValue)(field, raw) === null ? raw : field.default;
1003
+ const value = raw === void 0 || (0, import_builder_schema9.validateSettingValue)(field, raw) === null ? raw : field.default;
193
1004
  if (value === null || value === void 0) continue;
194
1005
  if (field.key === "hidden") {
195
1006
  if (value === true) put(out, "--tb-hide", "none");
@@ -209,13 +1020,13 @@ function backgroundDecls(out, bg, assets, mediaOrigin) {
209
1020
  if (bg.position !== void 0 && BG_POSITION.has(bg.position)) put(out, "--tb-bgpos", bg.position);
210
1021
  if (bg.size !== void 0 && BG_SIZE.has(bg.size)) put(out, "--tb-bgsize", bg.size);
211
1022
  const asset = bg.image === void 0 || assets === void 0 || !Object.hasOwn(assets, bg.image) ? void 0 : assets[bg.image];
212
- if (asset !== void 0 && (0, import_builder_schema2.safeUrl)(asset.url, "src", { mediaOrigin }) !== null && URL_QUOTE_SAFE.test(asset.url)) {
1023
+ if (asset !== void 0 && (0, import_builder_schema9.safeUrl)(asset.url, "src", { mediaOrigin }) !== null && URL_QUOTE_SAFE.test(asset.url)) {
213
1024
  out.set("--tb-bgimg", `url("${asset.url}")`);
214
1025
  }
215
1026
  }
216
1027
  function sectionDecls(section, device, assets, mediaOrigin) {
217
1028
  const out = /* @__PURE__ */ new Map();
218
- const p = (0, import_builder_schema2.resolveResponsive)(section.props, section.responsive, device);
1029
+ const p = (0, import_builder_schema9.resolveResponsive)(section.props, section.responsive, device);
219
1030
  if (p.hidden === true) put(out, "--tb-hide", "none");
220
1031
  const full = p.width === "full";
221
1032
  put(out, "--tb-maxw", full ? "none" : px(typeof p.contentWidth === "number" ? p.contentWidth : 1200));
@@ -225,16 +1036,16 @@ function sectionDecls(section, device, assets, mediaOrigin) {
225
1036
  if (typeof p.minHeight === "number" && p.minHeight > 0 && p.minHeight <= 2e3) put(out, "--tb-minh", px(p.minHeight));
226
1037
  if (typeof p.verticalAlign === "string" && Object.hasOwn(ALIGN_ITEMS, p.verticalAlign)) put(out, "--tb-valign", ALIGN_ITEMS[p.verticalAlign]);
227
1038
  backgroundDecls(out, p.background, assets, mediaOrigin);
228
- const widths = (0, import_builder_schema2.resolveColumnWidths)(section, device);
229
- const rows = (0, import_builder_schema2.wrapColumnRows)(widths);
1039
+ const widths = (0, import_builder_schema9.resolveColumnWidths)(section, device);
1040
+ const rows = (0, import_builder_schema9.wrapColumnRows)(widths);
230
1041
  const stacked = rows.every((row) => row.length === 1);
231
1042
  put(out, "--tb-flow", stacked && p.stackOrder === "reverse" ? "column-reverse nowrap" : "row wrap");
232
1043
  return out;
233
1044
  }
234
1045
  function columnWidthDecls(section, device) {
235
- const widths = (0, import_builder_schema2.resolveColumnWidths)(section, device);
1046
+ const widths = (0, import_builder_schema9.resolveColumnWidths)(section, device);
236
1047
  const result = section.columns.map(() => /* @__PURE__ */ new Map());
237
- for (const row of (0, import_builder_schema2.wrapColumnRows)(widths)) {
1048
+ for (const row of (0, import_builder_schema9.wrapColumnRows)(widths)) {
238
1049
  for (const index of row) {
239
1050
  put(result[index], "--tb-cw", String(Math.round(widths[index] / 100 * 1e4) / 1e4));
240
1051
  put(result[index], "--tb-cn", String(row.length - 1));
@@ -245,7 +1056,7 @@ function columnWidthDecls(section, device) {
245
1056
  function columnDecls(section, index, device, assets, mediaOrigin, widths) {
246
1057
  const column = section.columns[index];
247
1058
  const out = new Map(widths);
248
- const p = (0, import_builder_schema2.resolveColumnProps)(column.props, column.responsive, device);
1059
+ const p = (0, import_builder_schema9.resolveColumnProps)(column.props, column.responsive, device);
249
1060
  if (p.hidden === true) put(out, "--tb-hide", "none");
250
1061
  if (typeof p.verticalAlign === "string" && Object.hasOwn(ALIGN_ITEMS, p.verticalAlign)) put(out, "--tb-self", ALIGN_ITEMS[p.verticalAlign]);
251
1062
  put(out, "--tb-pad", p.padding === void 0 ? null : spacing(p.padding));
@@ -294,7 +1105,9 @@ function collect(doc, registry, assets, mediaOrigin) {
294
1105
  }
295
1106
  });
296
1107
  };
297
- doc.sections.forEach(section);
1108
+ for (const root of doc.sections) {
1109
+ if (root.type === "section") section(root);
1110
+ }
298
1111
  return nodes;
299
1112
  }
300
1113
  var block = (id, decls) => {
@@ -314,108 +1127,354 @@ function compileResponsiveCss(doc, registry, assets = doc.assets, mediaOrigin =
314
1127
  return base + (tablet === "" ? "" : `@media ${TABLET_QUERY}{${tablet}}`) + (phone === "" ? "" : `@media ${PHONE_QUERY}{${phone}}`);
315
1128
  }
316
1129
 
317
- // src/data.ts
318
- var import_builder_schema3 = require("@usethrottle/builder-schema");
319
- function stable(value) {
320
- if (Array.isArray(value)) return `[${value.map(stable).join(",")}]`;
321
- if (typeof value === "object" && value !== null) {
322
- const entries2 = Object.entries(value).filter(([, item]) => item !== void 0).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
323
- return `{${entries2.map(([k, v]) => `${JSON.stringify(k)}:${stable(v)}`).join(",")}}`;
324
- }
325
- return JSON.stringify(value) ?? "null";
326
- }
327
- function bindingKey(binding) {
328
- return "params" in binding ? `${binding.source}?${stable(binding.params)}` : binding.source;
329
- }
330
- var isContextBinding = (binding) => binding.source.startsWith("context.");
331
- function bindingsOf(node, registry) {
332
- const def = registry.widget(node.type, node.v);
333
- const out = {};
334
- for (const [name, input] of Object.entries(def?.data ?? {})) {
335
- if (input.default !== void 0) out[name] = input.default;
336
- }
337
- return { ...out, ...node.data ?? {} };
1130
+ // src/interactions/accordion.tsx
1131
+ var import_jsx_runtime9 = require("react/jsx-runtime");
1132
+ function Accordion({
1133
+ id,
1134
+ panels,
1135
+ multiple,
1136
+ openFirst
1137
+ }) {
1138
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "tb-accordion", children: panels.map((panel, i) => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
1139
+ "details",
1140
+ {
1141
+ className: "tb-acc-item",
1142
+ ...multiple ? {} : { name: `${id}-acc` },
1143
+ ...openFirst && i === 0 ? { open: true } : {},
1144
+ children: [
1145
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("summary", { className: "tb-acc-sum", children: panel.title }),
1146
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "tb-acc-body", children: panel.node })
1147
+ ]
1148
+ },
1149
+ panel.key
1150
+ )) });
338
1151
  }
339
- function collectBindings(doc, registry) {
340
- const found = /* @__PURE__ */ new Map();
341
- (0, import_builder_schema3.walkNodes)(doc, (node) => {
342
- if (node.type === "section" || node.type === "inner-section" || node.type === "column") return;
343
- for (const binding of Object.values(bindingsOf(node, registry))) {
344
- const key = bindingKey(binding);
345
- if (!found.has(key)) found.set(key, binding);
1152
+
1153
+ // src/interactions/carousel.tsx
1154
+ var import_jsx_runtime10 = require("react/jsx-runtime");
1155
+ function Carousel({
1156
+ panels,
1157
+ autoplayMs,
1158
+ loop
1159
+ }) {
1160
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
1161
+ "div",
1162
+ {
1163
+ className: "tb-car",
1164
+ role: "region",
1165
+ "aria-roledescription": "carousel",
1166
+ "aria-label": "Carousel",
1167
+ "data-b-car": "",
1168
+ ...loop ? { "data-b-loop": "" } : {},
1169
+ ...autoplayMs === null ? {} : { "data-b-autoplay": String(autoplayMs) },
1170
+ children: [
1171
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "tb-car-track", tabIndex: 0, children: panels.map((panel, i) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1172
+ "div",
1173
+ {
1174
+ className: "tb-slide",
1175
+ role: "group",
1176
+ "aria-roledescription": "slide",
1177
+ "aria-label": panel.title === "" ? `${String(i + 1)} of ${String(panels.length)}` : panel.title,
1178
+ children: panel.node
1179
+ },
1180
+ panel.key
1181
+ )) }),
1182
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "tb-car-ctrl", children: [
1183
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { type: "button", className: "tb-car-btn", "data-b-act": "prev", "aria-label": "Previous slide", children: "\u2039" }),
1184
+ autoplayMs === null ? null : /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { type: "button", className: "tb-car-btn tb-car-pause", "data-b-act": "pause", hidden: true, children: "Pause" }),
1185
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { type: "button", className: "tb-car-btn", "data-b-act": "next", "aria-label": "Next slide", children: "\u203A" })
1186
+ ] })
1187
+ ]
346
1188
  }
347
- });
348
- return found;
349
- }
350
- async function resolveBindings(bindings, registry, ctx, options) {
351
- const jobs = [];
352
- for (const [key, binding] of bindings) {
353
- if (isContextBinding(binding) || !("params" in binding)) continue;
354
- const descriptor = registry.source(binding.source);
355
- const resolve = registry.resolver(binding.source);
356
- if (descriptor === void 0 || resolve === void 0) continue;
357
- if (options.include === "static" && descriptor.perShopper) continue;
358
- if (options.include === "shopper" && !descriptor.perShopper) continue;
359
- jobs.push(
360
- resolve(binding.params, ctx).then(
361
- (value) => [key, value],
362
- (error) => {
363
- warnOnce(`resolve:${binding.source}`, `Data source ${binding.source} failed (${String(error)}); its widgets render without data`);
364
- return null;
365
- }
366
- )
367
- );
368
- }
369
- const settled = await Promise.all(jobs);
370
- return Object.fromEntries(settled.filter((entry) => entry !== null));
1189
+ );
371
1190
  }
372
1191
 
373
- // src/node-wrapper.tsx
374
- var import_builder_schema4 = require("@usethrottle/builder-schema");
375
- var import_jsx_runtime = require("react/jsx-runtime");
376
- var CUSTOM_WIDGET_CONTAINMENT = {
377
- contain: "layout paint",
378
- isolation: "isolate",
379
- overflow: "clip"
380
- };
381
- var PART_NAME = {
382
- section: "builder-section",
383
- column: "builder-column",
384
- widget: "builder-widget"
385
- };
386
- function NodeWrapper(props) {
387
- const { id, part, type, className, anchor, custom, missing, edit, children } = props;
388
- const Tag = props.as ?? "div";
389
- const handlers = edit === void 0 ? {} : {
390
- onClickCapture: (event) => {
391
- const target = event.target;
392
- if (target?.closest?.("a[href]") != null) event.preventDefault();
393
- },
394
- onClick: (event) => {
395
- event.stopPropagation();
396
- edit.onSelect(id);
397
- },
398
- onMouseOver: (event) => {
399
- event.stopPropagation();
400
- edit.onHover(id);
401
- },
402
- onMouseLeave: () => edit.onHover(null)
403
- };
404
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
405
- Tag,
406
- {
407
- className,
408
- "data-b-id": id,
409
- "data-throttle-part": PART_NAME[part],
410
- ...type === void 0 ? {} : { "data-b-type": type },
411
- ...custom === true && type !== void 0 ? { "data-b-w": type } : {},
412
- ...missing === true ? { "data-b-missing": "" } : {},
413
- ...typeof anchor === "string" && import_builder_schema4.ANCHOR_RE.test(anchor) ? { id: anchor } : {},
414
- ...custom === true ? { style: CUSTOM_WIDGET_CONTAINMENT } : {},
415
- ...handlers,
416
- children
1192
+ // src/interactions/entrance.tsx
1193
+ var import_react8 = require("react");
1194
+ var import_builder_schema10 = require("@usethrottle/builder-schema");
1195
+
1196
+ // src/interactions/styles.ts
1197
+ var INTERACTIONS_CSS = `@layer throttle{
1198
+ .tb-panel>.tb-col,.tb-acc-body>.tb-col,.tb-slide>.tb-col{inline-size:100%}
1199
+ .tb-tablist{display:none;flex-wrap:wrap;gap:var(--tb-space-xs);border-block-end:1px solid var(--tb-color-border,currentColor);margin-block-end:var(--tb-space-m)}
1200
+ html[data-b-js] .tb-tablist{display:flex}
1201
+ html[data-b-js] .tb-panel-title{display:none}
1202
+ .tb-panel-title{margin:0 0 var(--tb-space-s);font-weight:600}
1203
+ .tb-panel[hidden]{display:none}
1204
+ .tb-tab{appearance:none;cursor:pointer;font:inherit;color:inherit;background:none;border:0;border-block-end:2px solid transparent;padding:var(--tb-space-s) var(--tb-space-m)}
1205
+ .tb-tab[aria-selected=true]{border-block-end-color:var(--tb-color-primary,currentColor);font-weight:600}
1206
+ .tb-tab:focus-visible,.tb-car-btn:focus-visible,.tb-acc-sum:focus-visible,.tb-toggle-sum:focus-visible,.tb-car-track:focus-visible{outline:2px solid var(--tb-color-primary,currentColor);outline-offset:2px}
1207
+ .tb-acc-item{border-block-end:1px solid var(--tb-color-border,currentColor)}
1208
+ .tb-acc-sum,.tb-toggle-sum{cursor:pointer;padding:var(--tb-space-s) 0;font-weight:600}
1209
+ .tb-acc-body{padding-block-end:var(--tb-space-m)}
1210
+ .tb-toggle-open,.tb-toggle[open] .tb-toggle-closed{display:none}
1211
+ .tb-toggle[open] .tb-toggle-open{display:inline}
1212
+ .tb-toggle .tb-row{margin-block-start:var(--tb-space-m)}
1213
+ .tb-car{position:relative}
1214
+ .tb-car-track{display:flex;overflow-x:auto;scroll-snap-type:x mandatory;scrollbar-width:thin}
1215
+ .tb-slide{flex:0 0 100%;min-inline-size:0;scroll-snap-align:start}
1216
+ .tb-car-ctrl{display:none;justify-content:center;gap:var(--tb-space-s);margin-block-start:var(--tb-space-s)}
1217
+ html[data-b-js] .tb-car-ctrl{display:flex}
1218
+ .tb-car-btn{appearance:none;cursor:pointer;font:inherit;color:inherit;background:var(--tb-color-surface,transparent);border:1px solid var(--tb-color-border-control,currentColor);border-radius:999px;min-inline-size:2.5rem;min-block-size:2.5rem;padding:0 var(--tb-space-m)}
1219
+ .tb-car-btn[hidden]{display:none}
1220
+ @media (prefers-reduced-motion:no-preference){
1221
+ html[data-b-js] [data-b-entrance]{transition:opacity .6s ease var(--tb-ed,0ms),transform .6s ease var(--tb-ed,0ms)}
1222
+ html[data-b-js] [data-b-entrance]:not([data-b-in]){opacity:0}
1223
+ html[data-b-js] [data-b-entrance=slide-up]:not([data-b-in]){transform:translateY(1.5rem)}
1224
+ html[data-b-js] [data-b-entrance=slide-left]:not([data-b-in]){transform:translateX(-1.5rem)}
1225
+ html[data-b-js] [data-b-entrance=zoom]:not([data-b-in]){transform:scale(.94)}
1226
+ }
1227
+ @media (prefers-reduced-motion:reduce){.tb-car-track{scroll-behavior:auto}}
1228
+ }`;
1229
+
1230
+ // src/interactions/runtime.ts
1231
+ var UNITS = [86400, 3600, 60, 1];
1232
+ var KEYS = ["d", "h", "m", "s"];
1233
+ var NAMES = ["days", "hours", "minutes", "seconds"];
1234
+ var holds = 0;
1235
+ var stop;
1236
+ var seen2 = /* @__PURE__ */ new WeakSet();
1237
+ var autoplay = /* @__PURE__ */ new Map();
1238
+ var all = (selector) => Array.from(document.querySelectorAll(selector));
1239
+ var reduced = () => window.matchMedia?.("(prefers-reduced-motion: reduce)").matches === true;
1240
+ function selectTab(list, index, focus = false) {
1241
+ const tabs = Array.from(list.querySelectorAll("[role=tab]"));
1242
+ tabs.forEach((tab, i) => {
1243
+ const on = i === index;
1244
+ tab.setAttribute("aria-selected", String(on));
1245
+ tab.tabIndex = on ? 0 : -1;
1246
+ const panel = document.getElementById(tab.getAttribute("aria-controls") ?? "");
1247
+ if (panel !== null) panel.hidden = !on;
1248
+ if (on && focus) tab.focus();
1249
+ });
1250
+ }
1251
+ function slideTo(root, step2) {
1252
+ const track = root.querySelector(".tb-car-track");
1253
+ if (track === null || track.clientWidth === 0) return;
1254
+ const count = track.children.length;
1255
+ const at = Math.round(track.scrollLeft / track.clientWidth) + step2;
1256
+ const loop = root.hasAttribute("data-b-loop");
1257
+ const to = at >= count ? loop ? 0 : count - 1 : at < 0 ? loop ? count - 1 : 0 : at;
1258
+ track.scrollTo?.({ left: to * track.clientWidth, behavior: reduced() ? "auto" : "smooth" });
1259
+ }
1260
+ var carousels = /* @__PURE__ */ new WeakMap();
1261
+ function setupCarousel(root) {
1262
+ const every = Number(root.getAttribute("data-b-autoplay"));
1263
+ const pause = root.querySelector("[data-b-act=pause]");
1264
+ if (!(every > 0) || reduced() || pause === null) return;
1265
+ pause.hidden = false;
1266
+ let state = carousels.get(root);
1267
+ if (state === void 0) {
1268
+ const own = state = { hold: 0 };
1269
+ carousels.set(root, own);
1270
+ const set = (bit, on) => void (own.hold = on ? own.hold | bit : own.hold & ~bit);
1271
+ root.addEventListener("mouseenter", () => set(1, true));
1272
+ root.addEventListener("mouseleave", () => set(1, false));
1273
+ root.addEventListener("focusin", () => set(2, true));
1274
+ root.addEventListener("focusout", () => set(2, false));
1275
+ pause.addEventListener("click", () => {
1276
+ set(4, (own.hold & 4) === 0);
1277
+ pause.textContent = own.hold & 4 ? "Play" : "Pause";
1278
+ });
1279
+ }
1280
+ const shared = state;
1281
+ autoplay.set(root, window.setInterval(() => shared.hold === 0 && slideTo(root, 1), every));
1282
+ }
1283
+ function remaining(el) {
1284
+ return Math.max(0, Math.floor((Number(el.getAttribute("data-b-cd")) - Date.now()) / 1e3));
1285
+ }
1286
+ function tick(el, minute) {
1287
+ let left = remaining(el);
1288
+ const parts = [];
1289
+ KEYS.forEach((key, i) => {
1290
+ const out = el.querySelector(`[data-u=${key}]`);
1291
+ if (out === null) return;
1292
+ const value = Math.floor(left / UNITS[i]);
1293
+ left -= value * UNITS[i];
1294
+ out.textContent = String(value).padStart(2, "0");
1295
+ parts.push(`${String(value)} ${out.nextElementSibling?.textContent || NAMES[i]}`);
1296
+ });
1297
+ const live = el.querySelector("[data-b-live]");
1298
+ if (live !== null && minute) live.textContent = parts.join(", ");
1299
+ if (remaining(el) === 0) {
1300
+ el.setAttribute("data-b-ended", "");
1301
+ const text = el.querySelector(".tb-b-cd-ended");
1302
+ if (text !== null) text.hidden = false;
1303
+ if (el.getAttribute("data-b-expired") === "hide") el.hidden = true;
1304
+ }
1305
+ }
1306
+ function scan() {
1307
+ autoplay.forEach((id, root) => {
1308
+ if (!root.isConnected) {
1309
+ window.clearInterval(id);
1310
+ autoplay.delete(root);
417
1311
  }
418
- );
1312
+ });
1313
+ document.documentElement.setAttribute("data-b-js", "");
1314
+ const fresh = (selector) => all(selector).filter((el) => !seen2.has(el) && seen2.add(el));
1315
+ fresh("[data-b-tabs]").forEach((list) => selectTab(list, 0));
1316
+ fresh("[data-b-car]").forEach((root) => setupCarousel(root));
1317
+ const counts = fresh("[data-b-cd]");
1318
+ counts.forEach((el) => tick(el, true));
1319
+ const targets = fresh("[data-b-entrance]");
1320
+ if (targets.length === 0) return;
1321
+ if (typeof IntersectionObserver === "undefined") targets.forEach((el) => el.setAttribute("data-b-in", ""));
1322
+ else {
1323
+ const watch = new IntersectionObserver(
1324
+ (entries2) => entries2.forEach((entry) => {
1325
+ if (!entry.isIntersecting) return;
1326
+ entry.target.setAttribute("data-b-in", "");
1327
+ watch.unobserve(entry.target);
1328
+ })
1329
+ );
1330
+ targets.forEach((el) => watch.observe(el));
1331
+ }
1332
+ }
1333
+ var shown = (el) => el !== null && el.getClientRects().length > 0;
1334
+ function goAnchor(name) {
1335
+ if (name === "" || shown(document.getElementById(name))) return false;
1336
+ const copy = all("[data-b-anchor]").find((el) => el.getAttribute("data-b-anchor") === name && shown(el));
1337
+ copy?.scrollIntoView();
1338
+ return copy !== void 0;
1339
+ }
1340
+ var decoded = (hash) => {
1341
+ try {
1342
+ return decodeURIComponent(hash.slice(1));
1343
+ } catch {
1344
+ return "";
1345
+ }
1346
+ };
1347
+ var onHash = () => void goAnchor(decoded(location.hash));
1348
+ function onClick(event) {
1349
+ const target = event.target;
1350
+ const href = target?.closest('a[href^="#"]')?.getAttribute("href");
1351
+ if (href && !event.defaultPrevented && !event.button && !(event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) && goAnchor(decoded(href))) {
1352
+ event.preventDefault();
1353
+ history.pushState(null, "", href);
1354
+ }
1355
+ const tab = target?.closest("[role=tab]");
1356
+ const list = tab?.closest("[data-b-tabs]");
1357
+ if (tab && list) return selectTab(list, Array.from(list.querySelectorAll("[role=tab]")).indexOf(tab));
1358
+ const button = target?.closest("[data-b-act]");
1359
+ const act = button?.getAttribute("data-b-act");
1360
+ const root = button?.closest("[data-b-car]");
1361
+ if (root && (act === "prev" || act === "next")) slideTo(root, act === "next" ? 1 : -1);
1362
+ }
1363
+ function onKey(event) {
1364
+ const tab = event.target?.closest("[role=tab]");
1365
+ const list = tab?.closest("[data-b-tabs]");
1366
+ if (!tab || !list) return;
1367
+ const count = list.querySelectorAll("[role=tab]").length;
1368
+ const at = Array.from(list.querySelectorAll("[role=tab]")).indexOf(tab);
1369
+ 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;
1370
+ if (to < 0) return;
1371
+ event.preventDefault();
1372
+ selectTab(list, to, true);
1373
+ }
1374
+ function startRuntime() {
1375
+ if (typeof document === "undefined") return () => void 0;
1376
+ const first = holds++ === 0;
1377
+ if (first) {
1378
+ document.addEventListener("click", onClick);
1379
+ document.addEventListener("keydown", onKey);
1380
+ window.addEventListener("hashchange", onHash);
1381
+ let beat = 0;
1382
+ const clock = window.setInterval(() => {
1383
+ const minute = ++beat % 60 === 0;
1384
+ all("[data-b-cd]:not([data-b-ended])").forEach((el) => tick(el, minute));
1385
+ }, 1e3);
1386
+ let queued = false;
1387
+ const watcher = new MutationObserver(() => {
1388
+ if (queued) return;
1389
+ queued = true;
1390
+ void Promise.resolve().then(() => {
1391
+ queued = false;
1392
+ if (holds > 0) scan();
1393
+ });
1394
+ });
1395
+ watcher.observe(document.documentElement, { childList: true, subtree: true });
1396
+ stop = () => {
1397
+ document.removeEventListener("click", onClick);
1398
+ document.removeEventListener("keydown", onKey);
1399
+ window.removeEventListener("hashchange", onHash);
1400
+ window.clearInterval(clock);
1401
+ watcher.disconnect();
1402
+ autoplay.forEach((id) => window.clearInterval(id));
1403
+ autoplay.clear();
1404
+ seen2 = /* @__PURE__ */ new WeakSet();
1405
+ };
1406
+ }
1407
+ scan();
1408
+ if (first) onHash();
1409
+ return () => {
1410
+ if (--holds === 0) stop?.();
1411
+ };
1412
+ }
1413
+
1414
+ // src/interactions/entrance.tsx
1415
+ var import_jsx_runtime11 = require("react/jsx-runtime");
1416
+ function entranceOf(entrance, delayMs, interactive) {
1417
+ if (!interactive || typeof entrance !== "string" || entrance === "none") return void 0;
1418
+ if (!import_builder_schema10.ENTRANCES.includes(entrance)) return void 0;
1419
+ const delay = typeof delayMs === "number" && Number.isFinite(delayMs) ? Math.min(2e3, Math.max(0, Math.round(delayMs))) : 0;
1420
+ return { name: entrance, delayMs: delay };
1421
+ }
1422
+ function InteractionRuntime() {
1423
+ (0, import_react8.useEffect)(() => startRuntime(), []);
1424
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("style", { href: "tb-interactions", precedence: "throttle", children: INTERACTIONS_CSS });
1425
+ }
1426
+
1427
+ // src/interactions/tabs.tsx
1428
+ var import_jsx_runtime12 = require("react/jsx-runtime");
1429
+ function Tabs({ id, panels }) {
1430
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "tb-tabs", children: [
1431
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { role: "tablist", className: "tb-tablist", "data-b-tabs": "", children: panels.map((panel, i) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1432
+ "button",
1433
+ {
1434
+ type: "button",
1435
+ role: "tab",
1436
+ className: "tb-tab",
1437
+ id: `${id}-t${String(i)}`,
1438
+ "aria-controls": `${id}-p${String(i)}`,
1439
+ "aria-selected": i === 0,
1440
+ tabIndex: i === 0 ? 0 : -1,
1441
+ children: panel.title
1442
+ },
1443
+ panel.key
1444
+ )) }),
1445
+ panels.map((panel, i) => /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
1446
+ "div",
1447
+ {
1448
+ role: "tabpanel",
1449
+ className: "tb-panel",
1450
+ id: `${id}-p${String(i)}`,
1451
+ "aria-labelledby": `${id}-t${String(i)}`,
1452
+ tabIndex: 0,
1453
+ children: [
1454
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("p", { className: "tb-panel-title", children: panel.title }),
1455
+ panel.node
1456
+ ]
1457
+ },
1458
+ panel.key
1459
+ ))
1460
+ ] });
1461
+ }
1462
+
1463
+ // src/interactions/toggle.tsx
1464
+ var import_jsx_runtime13 = require("react/jsx-runtime");
1465
+ function Toggle({
1466
+ labelOpen,
1467
+ labelClosed,
1468
+ startOpen,
1469
+ children
1470
+ }) {
1471
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("details", { className: "tb-toggle", ...startOpen ? { open: true } : {}, children: [
1472
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("summary", { className: "tb-toggle-sum", children: [
1473
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "tb-toggle-closed", children: labelClosed }),
1474
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "tb-toggle-open", children: labelOpen })
1475
+ ] }),
1476
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "tb-row", children })
1477
+ ] });
419
1478
  }
420
1479
 
421
1480
  // src/styles.ts
@@ -440,9 +1499,9 @@ var BASE_CSS = `@layer throttle{
440
1499
  }`;
441
1500
 
442
1501
  // src/renderer.tsx
443
- var import_jsx_runtime2 = require("react/jsx-runtime");
1502
+ var import_jsx_runtime14 = require("react/jsx-runtime");
444
1503
  var DEVICES = ["desktop", "tablet", "phone"];
445
- var COMMON_BY_KEY2 = new Map(import_builder_schema5.COMMON_WIDGET_SETTINGS.map((f) => [f.key, f]));
1504
+ var COMMON_BY_KEY2 = new Map(import_builder_schema11.COMMON_WIDGET_SETTINGS.map((f) => [f.key, f]));
446
1505
  var withCustomCache = /* @__PURE__ */ new WeakMap();
447
1506
  function registryFor(doc, base) {
448
1507
  const snapshots = doc.customWidgets;
@@ -455,7 +1514,11 @@ function registryFor(doc, base) {
455
1514
  let registry = perDocument.get(snapshots);
456
1515
  if (registry === void 0) {
457
1516
  try {
458
- registry = base.withCustom(Object.values(snapshots));
1517
+ registry = base.withCustom(
1518
+ Object.values(snapshots).filter(
1519
+ (snapshot) => snapshot.kind !== "code" || import_builder_schema11.codeWidgetSnapshotSchema.safeParse(snapshot).success
1520
+ )
1521
+ );
459
1522
  } catch (error) {
460
1523
  warnOnce("custom-registry", `Could not register the document's custom widgets: ${String(error)}`);
461
1524
  registry = base;
@@ -464,7 +1527,7 @@ function registryFor(doc, base) {
464
1527
  }
465
1528
  return registry;
466
1529
  }
467
- var isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
1530
+ var isRecord2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
468
1531
  function pickLocale(value, locale) {
469
1532
  const lang = locale.split("-")[0] ?? locale;
470
1533
  for (const key of [locale, lang, "en"]) {
@@ -475,25 +1538,25 @@ function pickLocale(value, locale) {
475
1538
  return "";
476
1539
  }
477
1540
  function onOrigin(asset, mediaOrigin) {
478
- if ((0, import_builder_schema5.safeUrl)(asset.url, "src", { mediaOrigin }) === null) return null;
479
- return { ...asset, variants: asset.variants.filter((v) => (0, import_builder_schema5.safeUrl)(v.url, "src", { mediaOrigin }) !== null) };
1541
+ if ((0, import_builder_schema11.safeUrl)(asset.url, "src", { mediaOrigin }) === null) return null;
1542
+ return { ...asset, variants: asset.variants.filter((v) => (0, import_builder_schema11.safeUrl)(v.url, "src", { mediaOrigin }) !== null) };
480
1543
  }
481
1544
  function prepare(field, value, ctx) {
482
1545
  if (field === void 0 || value === null) return value;
483
- if (field.translatable === true && isRecord(value)) return pickLocale(value, ctx.locale);
1546
+ if (field.translatable === true && isRecord2(value)) return pickLocale(value, ctx.locale);
484
1547
  if (field.control === "image" && typeof value === "string") {
485
1548
  const asset = Object.hasOwn(ctx.assets, value) ? ctx.assets[value] : void 0;
486
1549
  return asset === void 0 ? null : onOrigin(asset, ctx.mediaOrigin);
487
1550
  }
488
- if (field.control === "link" && isRecord(value) && typeof value.kind === "string") {
1551
+ if (field.control === "link" && isRecord2(value) && typeof value.kind === "string") {
489
1552
  const target = value;
490
1553
  const raw = ctx.resolveLink?.(target) ?? (target.kind === "url" ? target.href : null);
491
- return { ...value, href: (0, import_builder_schema5.safeUrl)(raw, "href", { mediaOrigin: ctx.mediaOrigin }) };
1554
+ return { ...value, href: (0, import_builder_schema11.safeUrl)(raw, "href", { mediaOrigin: ctx.mediaOrigin }) };
492
1555
  }
493
1556
  return value;
494
1557
  }
495
1558
  function storedLinkPart(value) {
496
- if (!isRecord(value) || value.kind !== "page") return value;
1559
+ if (!isRecord2(value) || value.kind !== "page") return value;
497
1560
  const { slug: _slug, href: _href, ...stored } = value;
498
1561
  void _slug;
499
1562
  void _href;
@@ -502,13 +1565,13 @@ function storedLinkPart(value) {
502
1565
  function settingsAt(node, fields, device, ctx) {
503
1566
  const base = {};
504
1567
  for (const field of fields.values()) base[field.key] = field.default;
505
- const resolved = (0, import_builder_schema5.resolveResponsive)({ ...base, ...node.props }, node.responsive, device);
1568
+ const resolved = (0, import_builder_schema11.resolveResponsive)({ ...base, ...node.props }, node.responsive, device);
506
1569
  const out = {};
507
1570
  for (const [key, value] of Object.entries(resolved)) {
508
1571
  const field = fields.get(key);
509
1572
  const freeText = field?.control === "text" || field?.control === "richtext";
510
- const checked = field?.control === "link" ? storedLinkPart(value) : value;
511
- const usable = field === void 0 || (freeText ? value !== null : (0, import_builder_schema5.validateSettingValue)(field, checked) === null) ? value : field.default;
1573
+ const checked2 = field?.control === "link" ? storedLinkPart(value) : value;
1574
+ const usable = field === void 0 || (freeText ? value !== null : (0, import_builder_schema11.validateSettingValue)(field, checked2) === null) ? value : field.default;
512
1575
  out[key] = prepare(field, usable, ctx);
513
1576
  }
514
1577
  return out;
@@ -528,33 +1591,67 @@ function variantsOf(node, def, fields, ctx) {
528
1591
  }
529
1592
  function hiddenEverywhere(props, responsive) {
530
1593
  return DEVICES.every(
531
- (device) => (0, import_builder_schema5.resolveResponsive)({ hidden: props.hidden ?? false }, responsive, device).hidden === true
1594
+ (device) => (0, import_builder_schema11.resolveResponsive)({ hidden: props.hidden ?? false }, responsive, device).hidden === true
532
1595
  );
533
1596
  }
534
1597
  var variantClass = (variant) => `tb-v ${variant.devices.map((d) => `tb-only-${d}`).join(" ")}`;
1598
+ function renderCodeWidget(node, snapshot, ctx, registry) {
1599
+ if (ctx.edit === void 0 && hiddenEverywhere(node.props, node.responsive)) return null;
1600
+ const def = registry.widget(node.type, node.v);
1601
+ const fields = new Map([...COMMON_BY_KEY2, ...(def?.settings ?? []).map((f) => [f.key, f])]);
1602
+ const data = {};
1603
+ for (const [name, binding] of Object.entries(bindingsOf(node, registry))) {
1604
+ const key = bindingKey(binding);
1605
+ const value = Object.hasOwn(ctx.data, key) ? ctx.data[key] : void 0;
1606
+ if (value !== void 0) data[name] = value;
1607
+ }
1608
+ const props = settingsAt(node, fields, "desktop", ctx);
1609
+ const anchor = props.anchor;
1610
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1611
+ CodeWidget,
1612
+ {
1613
+ node,
1614
+ snapshot,
1615
+ registry,
1616
+ props,
1617
+ data,
1618
+ locale: ctx.locale,
1619
+ mediaOrigin: ctx.mediaOrigin,
1620
+ edit: ctx.edit,
1621
+ code: ctx.code,
1622
+ interactive: ctx.interactive,
1623
+ anchor: !ctx.dupe && typeof anchor === "string" && anchor !== "" ? anchor : void 0,
1624
+ copyAnchor: ctx.vpath !== "" && typeof anchor === "string" && anchor !== "" ? anchor : void 0,
1625
+ entrance: entranceOf(props.entrance, props.entranceDelayMs, ctx.interactive)
1626
+ }
1627
+ );
1628
+ }
535
1629
  function renderWidget(node, ctx, registry) {
1630
+ const key = `${node.type}@${String(node.v)}`;
1631
+ const frozen = ctx.snapshots !== void 0 && Object.hasOwn(ctx.snapshots, key) ? ctx.snapshots[key] : void 0;
1632
+ if (frozen?.kind === "code") return renderCodeWidget(node, frozen, ctx, registry);
536
1633
  const def = registry.widget(node.type, node.v);
537
1634
  const Component2 = def === void 0 ? void 0 : registry.component(node);
538
1635
  if (def === void 0 || Component2 === void 0) {
539
1636
  if (isDevelopment()) {
540
1637
  warnOnce(`missing:${node.type}@${String(node.v)}`, `Unknown widget ${node.type} v${String(node.v)}; rendering nothing for it`);
541
1638
  }
542
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(NodeWrapper, { id: node.id, part: "widget", type: node.type, className: "tb-w", missing: true, children: ctx.edit !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "tb-missing", children: "Widget unavailable: update @usethrottle/storefront-react" }) });
1639
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(NodeWrapper, { id: node.id, part: "widget", type: node.type, className: "tb-w", missing: true, children: ctx.edit !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "tb-missing", children: "Widget unavailable: update @usethrottle/storefront-react" }) });
543
1640
  }
544
1641
  if (ctx.edit === void 0 && hiddenEverywhere(node.props, node.responsive)) return null;
545
1642
  const fields = new Map([...COMMON_BY_KEY2, ...def.settings.map((f) => [f.key, f])]);
546
1643
  const variants = variantsOf(node, def, fields, ctx);
547
1644
  const data = {};
548
1645
  for (const [name, binding] of Object.entries(bindingsOf(node, registry))) {
549
- const key = bindingKey(binding);
550
- const value = Object.hasOwn(ctx.data, key) ? ctx.data[key] : void 0;
1646
+ const key2 = bindingKey(binding);
1647
+ const value = Object.hasOwn(ctx.data, key2) ? ctx.data[key2] : void 0;
551
1648
  if (value !== void 0) data[name] = value;
552
1649
  }
553
1650
  const custom = node.type.startsWith("custom.");
554
1651
  const edit = ctx.edit;
555
1652
  return variants.map((variant, index) => {
556
1653
  const anchor = variant.props.anchor;
557
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1654
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
558
1655
  NodeWrapper,
559
1656
  {
560
1657
  id: node.id,
@@ -563,18 +1660,22 @@ function renderWidget(node, ctx, registry) {
563
1660
  custom,
564
1661
  edit,
565
1662
  className: variants.length > 1 ? `tb-w ${variantClass(variant)}` : "tb-w",
566
- anchor: index === 0 && typeof anchor === "string" && anchor !== "" ? anchor : void 0,
567
- children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1663
+ anchor: index === 0 && !ctx.dupe && typeof anchor === "string" && anchor !== "" ? anchor : void 0,
1664
+ copyAnchor: ctx.vpath !== "" && typeof anchor === "string" && anchor !== "" ? anchor : void 0,
1665
+ entrance: entranceOf(variant.props.entrance, variant.props.entranceDelayMs, ctx.interactive),
1666
+ children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
568
1667
  Component2,
569
1668
  {
570
1669
  node,
571
1670
  props: variant.props,
572
1671
  data,
573
1672
  editMode: edit !== void 0,
1673
+ interactive: ctx.interactive,
1674
+ idScope: ctx.vpath === "" && !ctx.dupe ? void 0 : { vpath: ctx.vpath, dupe: ctx.dupe },
574
1675
  locale: ctx.locale,
575
1676
  mediaOrigin: ctx.mediaOrigin,
576
1677
  resolveLink: ctx.resolveLink,
577
- inlineEdit: edit === void 0 ? void 0 : (key) => edit.inlineEdit(node.id, key),
1678
+ inlineEdit: edit === void 0 ? void 0 : (key2) => edit.inlineEdit(node.id, key2),
578
1679
  budget: custom ? new RenderBudget() : void 0
579
1680
  }
580
1681
  )
@@ -585,60 +1686,167 @@ function renderWidget(node, ctx, registry) {
585
1686
  }
586
1687
  function renderColumn(column, ctx, registry) {
587
1688
  if (ctx.edit === void 0 && hiddenEverywhere(column.props, column.responsive)) return null;
588
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1689
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
589
1690
  NodeWrapper,
590
1691
  {
591
1692
  id: column.id,
592
1693
  part: "column",
593
1694
  className: "tb-col",
594
- anchor: column.props.anchor,
1695
+ anchor: ctx.dupe ? void 0 : column.props.anchor,
1696
+ copyAnchor: ctx.vpath === "" ? void 0 : column.props.anchor,
595
1697
  edit: ctx.edit,
1698
+ entrance: entranceOf(
1699
+ (0, import_builder_schema11.resolveEntrance)(column, "desktop").entrance,
1700
+ (0, import_builder_schema11.resolveEntrance)(column, "desktop").entranceDelayMs,
1701
+ ctx.interactive
1702
+ ),
596
1703
  children: column.children.map(
597
- (child) => child.type === "inner-section" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react.Fragment, { children: renderSection(child, ctx, registry, true) }, child.id) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react.Fragment, { children: renderWidget(child, ctx, registry) }, child.id)
1704
+ (child) => child.type === "inner-section" ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react9.Fragment, { children: renderSection(child, ctx, registry, true) }, child.id) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react9.Fragment, { children: renderWidget(child, ctx, registry) }, child.id)
598
1705
  )
599
1706
  },
600
1707
  column.id
601
1708
  );
602
1709
  }
1710
+ var PLAIN = (0, import_builder_schema11.resolveInteraction)({ props: {}, responsive: void 0 }, "desktop");
1711
+ function sectionVariants(section, ctx) {
1712
+ const groups = /* @__PURE__ */ new Map();
1713
+ for (const device of DEVICES) {
1714
+ const interaction = ctx.interactive ? (0, import_builder_schema11.resolveInteraction)(section, device) : PLAIN;
1715
+ const entrance = ctx.interactive ? (0, import_builder_schema11.resolveEntrance)(section, device) : { entrance: "none", entranceDelayMs: 0 };
1716
+ const signature = stable([interaction, entrance]);
1717
+ const group = groups.get(signature);
1718
+ if (group === void 0) groups.set(signature, { devices: [device], interaction, entrance });
1719
+ else group.devices.push(device);
1720
+ }
1721
+ return [...groups.values()];
1722
+ }
1723
+ function panelsOf(section, ctx, registry, fallback) {
1724
+ const rendered = section.columns.map((column) => ({ column, node: renderColumn(column, ctx, registry) })).filter((entry) => entry.node !== null);
1725
+ return rendered.map(({ column, node }, i) => {
1726
+ const title = pickLocale(column.props.panelTitle ?? {}, ctx.locale).trim();
1727
+ return { key: column.id, title: title === "" ? fallback(i + 1, rendered.length) : title, node };
1728
+ });
1729
+ }
603
1730
  function renderSection(section, ctx, registry, nested = false) {
604
1731
  if (ctx.edit === void 0 && hiddenEverywhere(section.props, section.responsive)) return null;
605
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
606
- NodeWrapper,
607
- {
608
- id: section.id,
609
- part: "section",
610
- as: nested ? "div" : "section",
611
- className: nested ? "tb-section tb-nested" : "tb-section",
612
- anchor: section.props.anchor,
613
- edit: ctx.edit,
614
- children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "tb-inner", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "tb-row", children: section.columns.map((column) => renderColumn(column, ctx, registry)) }) })
1732
+ const variants = sectionVariants(section, ctx);
1733
+ const marker = variants.length > 1 && !ctx.dupe && section.props.anchor !== void 0 && import_builder_schema11.ANCHOR_RE.test(section.props.anchor) ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { id: section.props.anchor, className: "tb-anchor" }, "anchor") : null;
1734
+ const copies = variants.map((variant, index) => {
1735
+ const { interaction } = variant;
1736
+ const id = `ix-${section.id}-${ctx.vpath}${String(index)}`;
1737
+ const own = variants.length > 1 ? { ...ctx, vpath: `${ctx.vpath}${String(index)}-`, dupe: ctx.dupe || index > 0 } : ctx;
1738
+ const columns = () => section.columns.map((column) => renderColumn(column, own, registry));
1739
+ let body;
1740
+ if (interaction.interaction === "tabs") {
1741
+ body = /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Tabs, { id, panels: panelsOf(section, own, registry, (n) => `Tab ${String(n)}`) });
1742
+ } else if (interaction.interaction === "accordion") {
1743
+ body = /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1744
+ Accordion,
1745
+ {
1746
+ id,
1747
+ panels: panelsOf(section, own, registry, (n) => `Section ${String(n)}`),
1748
+ multiple: interaction.accordionMultiple,
1749
+ openFirst: interaction.accordionOpenFirst
1750
+ }
1751
+ );
1752
+ } else if (interaction.interaction === "carousel") {
1753
+ body = /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1754
+ Carousel,
1755
+ {
1756
+ panels: panelsOf(section, own, registry, () => ""),
1757
+ autoplayMs: interaction.carouselAutoplay ? interaction.carouselIntervalMs : null,
1758
+ loop: interaction.carouselLoop
1759
+ }
1760
+ );
1761
+ } else if (interaction.interaction === "toggle") {
1762
+ body = /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1763
+ Toggle,
1764
+ {
1765
+ labelOpen: pickLocale(interaction.toggleLabelOpen, ctx.locale),
1766
+ labelClosed: pickLocale(interaction.toggleLabelClosed, ctx.locale),
1767
+ startOpen: interaction.toggleStartOpen,
1768
+ children: columns()
1769
+ }
1770
+ );
1771
+ } else {
1772
+ body = /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "tb-row", children: columns() });
615
1773
  }
616
- );
1774
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1775
+ NodeWrapper,
1776
+ {
1777
+ id: section.id,
1778
+ part: "section",
1779
+ as: nested ? "div" : "section",
1780
+ className: `${nested ? "tb-section tb-nested" : "tb-section"}${variants.length > 1 ? ` ${variantClass({ devices: variant.devices, props: {} })}` : ""}`,
1781
+ anchor: variants.length === 1 && !ctx.dupe ? section.props.anchor : void 0,
1782
+ copyAnchor: variants.length > 1 || ctx.vpath !== "" ? section.props.anchor : void 0,
1783
+ edit: ctx.edit,
1784
+ entrance: entranceOf(variant.entrance.entrance, variant.entrance.entranceDelayMs, ctx.interactive),
1785
+ children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "tb-inner", children: body })
1786
+ },
1787
+ variant.devices.join("-")
1788
+ );
1789
+ });
1790
+ return marker === null ? copies : [marker, ...copies];
1791
+ }
1792
+ function needsRuntime(doc) {
1793
+ let found = false;
1794
+ (0, import_builder_schema11.walkNodes)(doc, (node) => {
1795
+ if (found || node.type === "saved-section") return;
1796
+ if (node.type === "section" || node.type === "inner-section") {
1797
+ found = DEVICES.some(
1798
+ (device) => (0, import_builder_schema11.resolveInteraction)(node, device).interaction !== "none" || (0, import_builder_schema11.resolveEntrance)(node, device).entrance !== "none"
1799
+ );
1800
+ } else if (node.type === "column") {
1801
+ found = DEVICES.some((device) => (0, import_builder_schema11.resolveEntrance)(node, device).entrance !== "none");
1802
+ } else {
1803
+ found = DEVICES.some((device) => {
1804
+ const entrance = (0, import_builder_schema11.resolveResponsive)(node.props, node.responsive, device).entrance;
1805
+ return entrance !== void 0 && entrance !== "none";
1806
+ });
1807
+ }
1808
+ });
1809
+ return found;
617
1810
  }
618
1811
  function BuilderRenderer(props) {
619
- const { document: source, registry: base, data, editMode, locale, assets, resolveLink } = props;
1812
+ const { document: raw, registry: base, data, editMode, locale, assets, resolveLink, code } = props;
1813
+ const expansion = expandSavedSections(raw, props.savedSections);
1814
+ const source = expansion.doc;
620
1815
  const registry = registryFor(source, base);
621
- const { doc } = (0, import_builder_schema5.upgradeNodes)(source, registry);
1816
+ const { doc } = (0, import_builder_schema11.upgradeNodes)(source, registry);
622
1817
  const mediaOrigin = props.mediaOrigin ?? "";
623
- const ctx = { registry, data, locale, assets, mediaOrigin, resolveLink, edit: editMode };
1818
+ const interactive = props.interactive !== false;
1819
+ const ctx = { registry, data, locale, assets, mediaOrigin, resolveLink, code, edit: editMode, interactive, vpath: props.idScope?.vpath ?? "", dupe: props.idScope?.dupe ?? false, snapshots: source.customWidgets };
624
1820
  const css = compileResponsiveCss(doc, registry, assets, mediaOrigin);
625
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "tb-root", "data-throttle-part": "builder-root", children: [
626
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("style", { href: "tb-base", precedence: "throttle", children: BASE_CSS }),
627
- css === "" ? null : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("style", { children: css }),
628
- doc.sections.map((section) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react.Fragment, { children: renderSection(section, ctx, registry) }, section.id))
1821
+ const upgraded = new Map(doc.sections.map((section) => [section.id, section]));
1822
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: "tb-root", "data-throttle-part": "builder-root", ...props.scopeCustomCss === true ? { "data-b-root": "" } : {}, children: [
1823
+ interactive && needsRuntime(doc) ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(InteractionRuntime, {}) : null,
1824
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("style", { href: "tb-base", precedence: "throttle", children: BASE_CSS }),
1825
+ css === "" ? null : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("style", { children: css }),
1826
+ (expansion.roots ?? doc.sections.map((section) => ({ kind: "section", id: section.id }))).map((root) => {
1827
+ if (root.kind === "section") {
1828
+ const section2 = upgraded.get(root.id);
1829
+ return section2?.type === "section" ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react9.Fragment, { children: renderSection(section2, ctx, registry) }, root.id) : null;
1830
+ }
1831
+ const section = root.sectionId === null ? void 0 : upgraded.get(root.sectionId);
1832
+ if (section?.type === "section") {
1833
+ return root.ref.props.hidden === true && ctx.edit === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react9.Fragment, { children: renderSection(section, ctx, registry) }, root.ref.id);
1834
+ }
1835
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MissingSavedSection, { node: root.ref }, root.ref.id);
1836
+ })
629
1837
  ] });
630
1838
  }
631
1839
  function validateRender(doc) {
632
1840
  const h1 = [];
633
- (0, import_builder_schema5.walkNodes)(doc, (node) => {
1841
+ (0, import_builder_schema11.walkNodes)(doc, (node) => {
634
1842
  if (node.type === "basic.heading" && node.props.level === "h1") h1.push(node.id);
635
1843
  });
636
1844
  return h1.length > 1 ? [{ code: "MULTIPLE_H1", message: `The page has ${String(h1.length)} level 1 headings; use one`, nodeIds: h1 }] : [];
637
1845
  }
638
1846
 
639
1847
  // src/asset-image.tsx
640
- var import_builder_schema6 = require("@usethrottle/builder-schema");
641
- var import_jsx_runtime3 = require("react/jsx-runtime");
1848
+ var import_builder_schema12 = require("@usethrottle/builder-schema");
1849
+ var import_jsx_runtime15 = require("react/jsx-runtime");
642
1850
  function isFrozenAsset(value) {
643
1851
  if (typeof value !== "object" || value === null) return false;
644
1852
  const v = value;
@@ -646,7 +1854,7 @@ function isFrozenAsset(value) {
646
1854
  }
647
1855
  function AssetImage(props) {
648
1856
  const { asset, alt, sizes, className, loading = "lazy", style, mediaOrigin } = props;
649
- const href = (url) => (0, import_builder_schema6.safeUrl)(url, "src", { mediaOrigin });
1857
+ const href = (url) => (0, import_builder_schema12.safeUrl)(url, "src", { mediaOrigin });
650
1858
  if (!isFrozenAsset(asset)) return null;
651
1859
  const src = href(asset.url);
652
1860
  if (src === null) return null;
@@ -654,7 +1862,7 @@ function AssetImage(props) {
654
1862
  const url = href(variant.url);
655
1863
  return url === null || url.includes(",") ? [] : [`${url} ${String(variant.width)}w`];
656
1864
  }).join(", ");
657
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1865
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
658
1866
  "img",
659
1867
  {
660
1868
  src,
@@ -670,46 +1878,36 @@ function AssetImage(props) {
670
1878
  );
671
1879
  }
672
1880
 
673
- // src/widget-style.tsx
674
- var import_jsx_runtime4 = require("react/jsx-runtime");
675
- function WidgetStyle({ css }) {
676
- if (css === "" || css.includes("<")) return null;
677
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("style", { children: css });
678
- }
679
-
680
1881
  // src/provider.tsx
681
- var import_react15 = require("react");
1882
+ var import_react18 = require("react");
682
1883
  var import_builder2 = require("@usethrottle/builder");
683
1884
  var import_ui6 = require("@usethrottle/ui");
684
1885
 
685
- // src/context.ts
686
- var import_react2 = require("react");
687
- var BuilderContext = typeof import_react2.createContext === "function" ? (0, import_react2.createContext)(null) : null;
688
- var useBuilder = () => (0, import_react2.useContext)(BuilderContext);
689
-
690
1886
  // src/page.tsx
691
- var import_react4 = require("react");
1887
+ var import_react10 = require("react");
692
1888
  var import_builder = require("@usethrottle/builder");
693
1889
 
694
1890
  // src/load.ts
695
1891
  function pageOf(raw, initialData) {
696
- const { document, id: _id, slug, title, path, generation, pageType: _type, updatedAt: _updated, ...meta } = raw;
1892
+ const { document: document2, id: _id, slug, title, path, generation, pageType: _type, updatedAt: _updated, savedSections, code, ...meta } = raw;
697
1893
  return {
698
1894
  kind: "page",
699
1895
  slug,
700
1896
  title,
701
1897
  path,
702
1898
  generation,
703
- document,
704
- assets: document.assets ?? {},
1899
+ document: document2,
1900
+ assets: document2.assets ?? {},
705
1901
  initialData,
706
- meta
1902
+ meta,
1903
+ ...savedSections === void 0 ? {} : { savedSections },
1904
+ ...code === void 0 ? {} : { code }
707
1905
  };
708
1906
  }
709
1907
  var isRedirect = (raw) => typeof raw.redirectTo === "string";
710
1908
 
711
1909
  // src/safe-path.ts
712
- var import_builder_schema7 = require("@usethrottle/builder-schema");
1910
+ var import_builder_schema13 = require("@usethrottle/builder-schema");
713
1911
  var UNSAFE = /[\x00-\x20\x7f-\xa0\\\u1680\u2000-\u200f\u2028\u2029\u202f\u205f\u3000\ufeff]/;
714
1912
  var LEADING = /^\/(?![/\\])/;
715
1913
  function plainPath(path) {
@@ -717,51 +1915,31 @@ function plainPath(path) {
717
1915
  }
718
1916
  function sitePath(to) {
719
1917
  if (typeof to !== "string" || !plainPath(to)) return null;
720
- let decoded;
1918
+ let decoded2;
721
1919
  try {
722
- decoded = decodeURIComponent(to);
1920
+ decoded2 = decodeURIComponent(to);
723
1921
  } catch {
724
1922
  return null;
725
1923
  }
726
- if (!plainPath(decoded)) return null;
727
- return (0, import_builder_schema7.safeUrl)(to, "href", { mediaOrigin: "" });
728
- }
729
-
730
- // src/shopper-data.ts
731
- var import_react3 = require("react");
732
- function useResolvedData(document, registry, locale, include, context) {
733
- const [data, setData] = (0, import_react3.useState)({});
734
- (0, import_react3.useEffect)(() => {
735
- const controller = new AbortController();
736
- const bindings = collectBindings(document, registry);
737
- if (bindings.size === 0) return void 0;
738
- void resolveBindings(
739
- bindings,
740
- registry,
741
- { locale, preview: false, context, signal: controller.signal },
742
- { include }
743
- ).then((resolved) => {
744
- if (!controller.signal.aborted && Object.keys(resolved).length > 0) setData(resolved);
745
- });
746
- return () => controller.abort();
747
- }, [document, registry, locale, include, context]);
748
- return data;
1924
+ if (!plainPath(decoded2)) return null;
1925
+ return (0, import_builder_schema13.safeUrl)(to, "href", { mediaOrigin: "" });
749
1926
  }
750
1927
 
751
1928
  // src/page.tsx
752
- var import_jsx_runtime5 = require("react/jsx-runtime");
1929
+ var import_jsx_runtime16 = require("react/jsx-runtime");
753
1930
  function BuilderPageView({ page, resolve = "shopper" }) {
754
1931
  const builder = useBuilder();
755
1932
  if (builder === null) throw new Error("A Builder page needs a BuilderProvider above it");
756
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(PageBody, { page, resolve, builder });
1933
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(PageBody, { page, resolve, builder });
757
1934
  }
758
1935
  function PageBody({
759
1936
  page,
760
1937
  resolve,
761
1938
  builder
762
1939
  }) {
763
- const resolved = useResolvedData(page.document, builder.registry, builder.locale, resolve);
764
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1940
+ const expanded = expandSavedSections(page.document, page.savedSections).doc;
1941
+ const resolved = useResolvedData(expanded, builder.registry, builder.locale, resolve);
1942
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
765
1943
  BuilderRenderer,
766
1944
  {
767
1945
  document: page.document,
@@ -770,7 +1948,11 @@ function PageBody({
770
1948
  locale: builder.locale,
771
1949
  assets: page.assets,
772
1950
  mediaOrigin: builder.mediaOrigin,
773
- resolveLink: builder.resolveLink
1951
+ resolveLink: builder.resolveLink,
1952
+ interactive: builder.interactive,
1953
+ scopeCustomCss: builder.customCss !== "",
1954
+ savedSections: page.savedSections,
1955
+ code: codeRenderOf(builder, page.code)
774
1956
  }
775
1957
  );
776
1958
  }
@@ -809,7 +1991,7 @@ function read(client, slug, locale) {
809
1991
  function BuilderPage({ slug, initial }) {
810
1992
  const builder = useBuilder();
811
1993
  if (builder === null) throw new Error("BuilderPage needs a BuilderProvider above it");
812
- if (initial !== void 0) return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(BuilderPageView, { page: initial });
1994
+ if (initial !== void 0) return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(BuilderPageView, { page: initial });
813
1995
  if (builder.site.status === "unavailable") {
814
1996
  throw new import_builder.BuilderUnavailableError("network", "The Builder is unavailable and has no last good answer");
815
1997
  }
@@ -817,95 +1999,30 @@ function BuilderPage({ slug, initial }) {
817
1999
  throw new Error("BuilderPage reads the page itself: give BuilderProvider a builderKey or a client, or pass `initial`");
818
2000
  }
819
2001
  const found = read(builder.client, slug, builder.locale);
820
- if ("redirectTo" in found) return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Redirect, { to: found.redirectTo });
821
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(BuilderPageView, { page: found, resolve: "all" });
2002
+ if ("redirectTo" in found) return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(Redirect, { to: found.redirectTo });
2003
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(BuilderPageView, { page: found, resolve: "all" });
822
2004
  }
823
2005
  function Redirect({ to }) {
824
- (0, import_react4.useEffect)(() => {
2006
+ (0, import_react10.useEffect)(() => {
825
2007
  const path = sitePath(to);
826
2008
  if (path !== null) window.location.replace(path);
827
2009
  }, [to]);
828
2010
  return null;
829
2011
  }
830
2012
 
831
- // src/part-view.tsx
832
- var import_react5 = require("react");
833
- var import_jsx_runtime6 = require("react/jsx-runtime");
834
- var BoundaryBase = import_react5.Component ?? class {
835
- };
836
- var Boundary = class extends BoundaryBase {
837
- constructor() {
838
- super(...arguments);
839
- __publicField(this, "state", { failed: false });
840
- }
841
- static getDerivedStateFromError() {
842
- return { failed: true };
843
- }
844
- componentDidCatch(error, _info) {
845
- warnOnce(`part:${this.props.label}`, `${this.props.label} failed to render (${String(error)}); rendering nothing for it`);
846
- try {
847
- this.props.onError?.(error, { part: this.props.label });
848
- } catch {
849
- }
850
- }
851
- componentDidUpdate(previous) {
852
- const moved = previous.resetKeys.length !== this.props.resetKeys.length || previous.resetKeys.some((key, i) => !Object.is(key, this.props.resetKeys[i]));
853
- if (moved && this.state.failed) this.setState({ failed: false });
854
- }
855
- render() {
856
- return this.state.failed ? null : this.props.children;
857
- }
858
- };
859
- function PartBoundary({
860
- label,
861
- resetKey,
862
- children
863
- }) {
864
- const builder = useBuilder();
865
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Boundary, { label, resetKeys: [builder?.site, resetKey], onError: builder?.onError, children });
866
- }
867
- function contextData(context) {
868
- if (typeof context !== "object" || context === null) return {};
869
- return Object.fromEntries(Object.entries(context).map(([key, value]) => [`context.${key}`, value]));
870
- }
871
- function PartView({ part, context }) {
872
- const builder = useBuilder();
873
- if (builder === null) return null;
874
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(PartBody, { part, context, builder });
875
- }
876
- function PartBody({
877
- part,
878
- context,
879
- builder
880
- }) {
881
- const shopper = useResolvedData(part.document, builder.registry, builder.locale, "shopper", context);
882
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
883
- BuilderRenderer,
884
- {
885
- document: part.document,
886
- registry: builder.registry,
887
- data: { ...part.initialData, ...contextData(context), ...shopper },
888
- locale: builder.locale,
889
- assets: part.assets,
890
- mediaOrigin: builder.mediaOrigin,
891
- resolveLink: builder.resolveLink
892
- }
893
- );
894
- }
895
-
896
2013
  // src/registry.ts
897
- var import_builder_schema20 = require("@usethrottle/builder-schema");
2014
+ var import_builder_schema23 = require("@usethrottle/builder-schema");
898
2015
 
899
2016
  // src/basics/index.ts
900
- var import_builder_schema15 = require("@usethrottle/builder-schema");
2017
+ var import_builder_schema21 = require("@usethrottle/builder-schema");
901
2018
 
902
2019
  // src/basics/announcement.tsx
903
- var import_react6 = require("react");
2020
+ var import_react11 = require("react");
904
2021
  var import_ui = require("@usethrottle/ui");
905
- var import_builder_schema9 = require("@usethrottle/builder-schema");
2022
+ var import_builder_schema15 = require("@usethrottle/builder-schema");
906
2023
 
907
2024
  // src/basics/util.tsx
908
- var import_builder_schema8 = require("@usethrottle/builder-schema");
2025
+ var import_builder_schema14 = require("@usethrottle/builder-schema");
909
2026
 
910
2027
  // src/basics/styles.ts
911
2028
  var BASICS_CSS = `@layer throttle{
@@ -970,26 +2087,26 @@ var BASICS_CSS = `@layer throttle{
970
2087
  }`;
971
2088
 
972
2089
  // src/basics/util.tsx
973
- var import_jsx_runtime7 = require("react/jsx-runtime");
2090
+ var import_jsx_runtime17 = require("react/jsx-runtime");
974
2091
  function BasicStyles() {
975
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("style", { href: "tb-basics", precedence: "throttle", children: BASICS_CSS });
2092
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("style", { href: "tb-basics", precedence: "throttle", children: BASICS_CSS });
976
2093
  }
977
- var isRecord2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
2094
+ var isRecord3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
978
2095
  var str = (v) => typeof v === "string" && v !== "" ? v : void 0;
979
2096
  function oneOf(value, allowed, fallback) {
980
2097
  return allowed.find((candidate) => candidate === value) ?? fallback;
981
2098
  }
982
2099
  function hrefOf(link, mediaOrigin) {
983
- if (!isRecord2(link)) return null;
984
- return (0, import_builder_schema8.safeUrl)(link.href, "href", { mediaOrigin });
2100
+ if (!isRecord3(link)) return null;
2101
+ return (0, import_builder_schema14.safeUrl)(link.href, "href", { mediaOrigin });
985
2102
  }
986
2103
  function Placeholder({ editMode, children }) {
987
- return editMode ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "tb-b-empty", children }) : null;
2104
+ return editMode ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "tb-b-empty", children }) : null;
988
2105
  }
989
- var ID_RE2 = /^[a-z0-9]{8,24}$/;
2106
+ var ID_RE2 = /^[a-z0-9]{8,24}(-[a-z0-9]{8,24})?$/;
990
2107
  var DEVICES2 = ["desktop", "tablet", "phone"];
991
2108
  function defaultOf(type, key) {
992
- const def = import_builder_schema8.BASIC_WIDGET_DEFINITIONS.find((d) => d.type === type);
2109
+ const def = import_builder_schema14.BASIC_WIDGET_DEFINITIONS.find((d) => d.type === type);
993
2110
  return def?.settings.find((f) => f.key === key)?.default ?? null;
994
2111
  }
995
2112
  function enumCss(node, rules) {
@@ -997,7 +2114,7 @@ function enumCss(node, rules) {
997
2114
  const per = { desktop: /* @__PURE__ */ new Map(), tablet: /* @__PURE__ */ new Map(), phone: /* @__PURE__ */ new Map() };
998
2115
  for (const device of DEVICES2) {
999
2116
  const settings = { ...Object.fromEntries(rules.map((r) => [r.key, defaultOf(node.type, r.key)])), ...node.props };
1000
- const resolved = (0, import_builder_schema8.resolveResponsive)(settings, node.responsive, device);
2117
+ const resolved = (0, import_builder_schema14.resolveResponsive)(settings, node.responsive, device);
1001
2118
  for (const rule of rules) {
1002
2119
  const value = resolved[rule.key];
1003
2120
  const fallback = defaultOf(node.type, rule.key);
@@ -1014,7 +2131,7 @@ function enumCss(node, rules) {
1014
2131
  }
1015
2132
 
1016
2133
  // src/basics/announcement.tsx
1017
- var import_jsx_runtime8 = require("react/jsx-runtime");
2134
+ var import_jsx_runtime18 = require("react/jsx-runtime");
1018
2135
  var KEY = "tb-announcement-dismissed";
1019
2136
  function read2(message) {
1020
2137
  try {
@@ -1032,25 +2149,25 @@ function write(message) {
1032
2149
  function Announcement({ props, mediaOrigin, editMode }) {
1033
2150
  const design = (0, import_ui.useSiteDesign)();
1034
2151
  const message = design?.announcement?.message;
1035
- const [dismissed, setDismissed] = (0, import_react6.useState)(false);
1036
- (0, import_react6.useEffect)(() => {
2152
+ const [dismissed, setDismissed] = (0, import_react11.useState)(false);
2153
+ (0, import_react11.useEffect)(() => {
1037
2154
  if (message !== void 0 && read2(message)) setDismissed(true);
1038
2155
  }, [message]);
1039
2156
  if (message === void 0) {
1040
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
1041
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(BasicStyles, {}),
1042
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Placeholder, { editMode, children: "No announcement: turn one on in Site settings" })
2157
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_jsx_runtime18.Fragment, { children: [
2158
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(BasicStyles, {}),
2159
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(Placeholder, { editMode, children: "No announcement: turn one on in Site settings" })
1043
2160
  ] });
1044
2161
  }
1045
2162
  if (dismissed && !editMode) return null;
1046
- const href = (0, import_builder_schema9.safeUrl)(design?.announcement?.href, "href", { mediaOrigin });
2163
+ const href = (0, import_builder_schema15.safeUrl)(design?.announcement?.href, "href", { mediaOrigin });
1047
2164
  const strings = design?.strings;
1048
- const dismissLabel = (strings !== void 0 && Object.hasOwn(strings, "announcement.dismiss") ? str(strings["announcement.dismiss"]) : void 0) ?? import_builder_schema9.SITE_STRING_DEFAULTS["announcement.dismiss"];
1049
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
1050
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(BasicStyles, {}),
1051
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "tb-b-announcement", role: "region", "aria-label": message, children: [
1052
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "tb-b-announcement-text", children: href === null ? message : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("a", { href, children: message }) }),
1053
- props.dismissible === true && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2165
+ const dismissLabel = (strings !== void 0 && Object.hasOwn(strings, "announcement.dismiss") ? str(strings["announcement.dismiss"]) : void 0) ?? import_builder_schema15.SITE_STRING_DEFAULTS["announcement.dismiss"];
2166
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_jsx_runtime18.Fragment, { children: [
2167
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(BasicStyles, {}),
2168
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: "tb-b-announcement", role: "region", "aria-label": message, children: [
2169
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("span", { className: "tb-b-announcement-text", children: href === null ? message : /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("a", { href, children: message }) }),
2170
+ props.dismissible === true && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
1054
2171
  "button",
1055
2172
  {
1056
2173
  type: "button",
@@ -1059,7 +2176,7 @@ function Announcement({ props, mediaOrigin, editMode }) {
1059
2176
  write(message);
1060
2177
  setDismissed(true);
1061
2178
  },
1062
- children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui.Icon, { name: "close", size: 16, label: dismissLabel })
2179
+ children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_ui.Icon, { name: "close", size: 16, label: dismissLabel })
1063
2180
  }
1064
2181
  )
1065
2182
  ] })
@@ -1067,59 +2184,125 @@ function Announcement({ props, mediaOrigin, editMode }) {
1067
2184
  }
1068
2185
 
1069
2186
  // src/basics/button.tsx
1070
- var import_jsx_runtime9 = require("react/jsx-runtime");
2187
+ var import_jsx_runtime19 = require("react/jsx-runtime");
1071
2188
  var STYLES = ["primary", "secondary", "outline", "link"];
1072
2189
  var SIZES = ["s", "m", "l"];
1073
2190
  function Button({ props, mediaOrigin, inlineEdit }) {
1074
2191
  const href = hrefOf(props.link, mediaOrigin);
1075
2192
  const className = `tb-b-button tb-b-button--${oneOf(props.style, STYLES, "primary")} tb-b-button--${oneOf(props.size, SIZES, "m")}`;
1076
2193
  const label = inlineEdit?.("label") ?? str(props.label) ?? "";
1077
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
1078
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(BasicStyles, {}),
1079
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "tb-b-button-wrap", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("a", { className, ...href === null ? {} : { href }, children: label }) })
2194
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_jsx_runtime19.Fragment, { children: [
2195
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(BasicStyles, {}),
2196
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: "tb-b-button-wrap", children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("a", { className, ...href === null ? {} : { href }, children: label }) })
1080
2197
  ] });
1081
2198
  }
1082
2199
 
1083
2200
  // src/basics/copyright.tsx
1084
2201
  var import_ui2 = require("@usethrottle/ui");
1085
- var import_builder_schema10 = require("@usethrottle/builder-schema");
1086
- var import_jsx_runtime10 = require("react/jsx-runtime");
2202
+ var import_builder_schema16 = require("@usethrottle/builder-schema");
2203
+ var import_jsx_runtime20 = require("react/jsx-runtime");
1087
2204
  function Copyright(_) {
1088
2205
  const design = (0, import_ui2.useSiteDesign)();
1089
2206
  const strings = design?.strings;
1090
2207
  const template = strings !== void 0 && Object.hasOwn(strings, "footer.copyright") ? str(strings["footer.copyright"]) : void 0;
1091
- const line = (template ?? import_builder_schema10.SITE_STRING_DEFAULTS["footer.copyright"]).replace("{year}", () => String((/* @__PURE__ */ new Date()).getFullYear())).replace("{store}", () => str(design?.brand?.storeName) ?? "").replace(/\s{2,}/g, " ").replace(/\s+([.,])/g, "$1");
1092
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
1093
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(BasicStyles, {}),
1094
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { className: "tb-b-copyright", children: line })
2208
+ const line = (template ?? import_builder_schema16.SITE_STRING_DEFAULTS["footer.copyright"]).replace("{year}", () => String((/* @__PURE__ */ new Date()).getFullYear())).replace("{store}", () => str(design?.brand?.storeName) ?? "").replace(/\s{2,}/g, " ").replace(/\s+([.,])/g, "$1");
2209
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(import_jsx_runtime20.Fragment, { children: [
2210
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(BasicStyles, {}),
2211
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("p", { className: "tb-b-copyright", children: line })
2212
+ ] });
2213
+ }
2214
+
2215
+ // src/basics/countdown.tsx
2216
+ var import_jsx_runtime21 = require("react/jsx-runtime");
2217
+ var UNITS2 = [
2218
+ { key: "d", show: "showDays", label: "labelDays", seconds: 86400 },
2219
+ { key: "h", show: "showHours", label: "labelHours", seconds: 3600 },
2220
+ { key: "m", show: "showMinutes", label: "labelMinutes", seconds: 60 },
2221
+ { key: "s", show: "showSeconds", label: "labelSeconds", seconds: 1 }
2222
+ ];
2223
+ var COUNTDOWN_CSS = `@layer throttle{
2224
+ .tb-b-cd{text-align:var(--b-align,center);color:var(--b-color,inherit);font-size:var(--b-size,var(--tb-text-l))}
2225
+ .tb-b-cd-date{margin:0}
2226
+ .tb-b-cd-units{display:none;justify-content:var(--b-align,center);gap:var(--tb-space-m);flex-wrap:wrap}
2227
+ html[data-b-js] .tb-b-cd-units{display:flex}
2228
+ html[data-b-js] .tb-b-cd-date{font-size:.5em;opacity:.7}
2229
+ .tb-b-cd-unit{display:flex;flex-direction:column;align-items:center;min-inline-size:3ch}
2230
+ .tb-b-cd-num{font-variant-numeric:tabular-nums;font-weight:700;line-height:1.1}
2231
+ .tb-b-cd-label{font-size:.45em;opacity:.8}
2232
+ .tb-b-cd-ended{margin:0}
2233
+ .tb-b-cd[data-b-ended] .tb-b-cd-units,.tb-b-cd[data-b-ended] .tb-b-cd-date{display:none}
2234
+ .tb-b-sr{position:absolute;inline-size:1px;block-size:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
2235
+ }`;
2236
+ var two = (n) => String(n).padStart(2, "0");
2237
+ function targetText(date) {
2238
+ return `${date.toISOString().slice(0, 10)} ${date.toISOString().slice(11, 16)} UTC`;
2239
+ }
2240
+ function Countdown({ props, editMode, interactive, locale }) {
2241
+ void locale;
2242
+ const target = str(props.target);
2243
+ const when = target === void 0 ? null : new Date(target);
2244
+ if (when === null || Number.isNaN(when.getTime())) {
2245
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Placeholder, { editMode, children: "Set the date and time the countdown ends" });
2246
+ }
2247
+ const live = interactive !== false;
2248
+ const behavior = oneOf(props.expiredBehavior, ["text", "hide"], "text");
2249
+ const shown2 = UNITS2.filter((unit) => props[unit.show] !== false);
2250
+ let left = live ? 0 : Math.max(0, Math.floor((when.getTime() - Date.now()) / 1e3));
2251
+ const units = shown2.map((unit) => {
2252
+ const value = live ? null : Math.floor(left / unit.seconds);
2253
+ if (value !== null) left -= value * unit.seconds;
2254
+ return { ...unit, text: value === null ? "--" : two(value), name: str(props[unit.label]) ?? "" };
2255
+ });
2256
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(import_jsx_runtime21.Fragment, { children: [
2257
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(BasicStyles, {}),
2258
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("style", { href: "tb-countdown", precedence: "throttle", children: COUNTDOWN_CSS }),
2259
+ live ? /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(InteractionRuntime, {}) : null,
2260
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(
2261
+ "div",
2262
+ {
2263
+ className: "tb-b-cd",
2264
+ role: "timer",
2265
+ "aria-live": "off",
2266
+ ...live ? { "data-b-cd": String(when.getTime()), "data-b-expired": behavior } : {},
2267
+ children: [
2268
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("p", { className: "tb-b-cd-date", children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("time", { dateTime: when.toISOString(), children: targetText(when) }) }),
2269
+ units.length === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "tb-b-cd-units", children: units.map((unit) => /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "tb-b-cd-unit", children: [
2270
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("span", { className: "tb-b-cd-num", "data-u": unit.key, "aria-hidden": "true", children: unit.text }),
2271
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("span", { className: "tb-b-cd-label", children: unit.name })
2272
+ ] }, unit.key)) }),
2273
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("p", { className: "tb-b-cd-ended", hidden: live || when.getTime() > Date.now(), children: str(props.expiredText) ?? "" }),
2274
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("span", { className: "tb-b-sr", "data-b-live": "", "aria-live": "polite" })
2275
+ ]
2276
+ }
2277
+ )
1095
2278
  ] });
1096
2279
  }
1097
2280
 
1098
2281
  // src/basics/divider.tsx
1099
- var import_jsx_runtime11 = require("react/jsx-runtime");
2282
+ var import_jsx_runtime22 = require("react/jsx-runtime");
1100
2283
  var RULES = [{ key: "style", property: "--bx-style", values: { solid: "solid", dashed: "dashed", dotted: "dotted" } }];
1101
2284
  function Divider({ node }) {
1102
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [
1103
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(BasicStyles, {}),
1104
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(WidgetStyle, { css: enumCss(node, RULES) }),
1105
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("hr", { className: "tb-b-divider" })
2285
+ return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(import_jsx_runtime22.Fragment, { children: [
2286
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(BasicStyles, {}),
2287
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(WidgetStyle, { css: enumCss(node, RULES) }),
2288
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("hr", { className: "tb-b-divider" })
1106
2289
  ] });
1107
2290
  }
1108
2291
 
1109
2292
  // src/basics/heading.tsx
1110
- var import_jsx_runtime12 = require("react/jsx-runtime");
2293
+ var import_jsx_runtime23 = require("react/jsx-runtime");
1111
2294
  var LEVELS = ["h1", "h2", "h3", "h4", "h5", "h6"];
1112
2295
  function Heading({ props, inlineEdit }) {
1113
2296
  const Tag = oneOf(props.level, LEVELS, "h2");
1114
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [
1115
- /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(BasicStyles, {}),
1116
- /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Tag, { className: "tb-b-heading", children: inlineEdit?.("text") ?? str(props.text) ?? "" })
2297
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(import_jsx_runtime23.Fragment, { children: [
2298
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(BasicStyles, {}),
2299
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(Tag, { className: "tb-b-heading", children: inlineEdit?.("text") ?? str(props.text) ?? "" })
1117
2300
  ] });
1118
2301
  }
1119
2302
 
1120
2303
  // src/basics/image.tsx
1121
- var import_builder_schema11 = require("@usethrottle/builder-schema");
1122
- var import_jsx_runtime13 = require("react/jsx-runtime");
2304
+ var import_builder_schema17 = require("@usethrottle/builder-schema");
2305
+ var import_jsx_runtime24 = require("react/jsx-runtime");
1123
2306
  var RULES2 = [
1124
2307
  { key: "radius", property: "--bx-radius", values: { none: "0", s: "4px", m: "8px", l: "16px", full: "9999px" } },
1125
2308
  { key: "fit", property: "--bx-fit", values: { cover: "cover", contain: "contain" } }
@@ -1129,23 +2312,23 @@ function Image({ node, props, mediaOrigin, editMode }) {
1129
2312
  const decorative = props.decorative === true;
1130
2313
  const alt = decorative ? "" : typeof props.alt === "string" ? props.alt : "";
1131
2314
  const asset = isFrozenAsset(props.image) ? props.image : void 0;
1132
- const image = /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(AssetImage, { asset, mediaOrigin, alt, className: "tb-b-img", sizes: "(max-width: 767px) 100vw, 50vw" });
1133
- const shown = asset !== void 0 && (0, import_builder_schema11.safeUrl)(asset.url, "src", { mediaOrigin }) !== null;
1134
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
1135
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(BasicStyles, {}),
1136
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(WidgetStyle, { css: enumCss(node, RULES2) }),
1137
- shown ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "tb-b-image", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "tb-b-image-box", children: href === null ? image : /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("a", { href, children: image }) }) }) : /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Placeholder, { editMode, children: asset === void 0 ? "Choose an image" : "Image unavailable" })
2315
+ const image = /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(AssetImage, { asset, mediaOrigin, alt, className: "tb-b-img", sizes: "(max-width: 767px) 100vw, 50vw" });
2316
+ const shown2 = asset !== void 0 && (0, import_builder_schema17.safeUrl)(asset.url, "src", { mediaOrigin }) !== null;
2317
+ return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(import_jsx_runtime24.Fragment, { children: [
2318
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(BasicStyles, {}),
2319
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(WidgetStyle, { css: enumCss(node, RULES2) }),
2320
+ shown2 ? /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: "tb-b-image", children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: "tb-b-image-box", children: href === null ? image : /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("a", { href, children: image }) }) }) : /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(Placeholder, { editMode, children: asset === void 0 ? "Choose an image" : "Image unavailable" })
1138
2321
  ] });
1139
2322
  }
1140
2323
 
1141
2324
  // src/basics/logo.tsx
1142
2325
  var import_ui3 = require("@usethrottle/ui");
1143
- var import_builder_schema12 = require("@usethrottle/builder-schema");
1144
- var import_jsx_runtime14 = require("react/jsx-runtime");
2326
+ var import_builder_schema18 = require("@usethrottle/builder-schema");
2327
+ var import_jsx_runtime25 = require("react/jsx-runtime");
1145
2328
  function Logo({ props, mediaOrigin, editMode }) {
1146
2329
  const design = (0, import_ui3.useSiteDesign)();
1147
2330
  const scheme = design?.theme?.colorScheme ?? "auto";
1148
- const src = (url) => url === void 0 ? void 0 : (0, import_builder_schema12.safeUrl)(url, "src", { mediaOrigin }) ?? void 0;
2331
+ const src = (url) => url === void 0 ? void 0 : (0, import_builder_schema18.safeUrl)(url, "src", { mediaOrigin }) ?? void 0;
1149
2332
  const light = src(design?.brand?.logo?.light);
1150
2333
  const dark = src(design?.brand?.logo?.dark);
1151
2334
  const main = scheme === "dark" ? dark ?? light : light ?? dark;
@@ -1154,53 +2337,53 @@ function Logo({ props, mediaOrigin, editMode }) {
1154
2337
  const alt = name ?? "";
1155
2338
  let content = null;
1156
2339
  if (main !== void 0) {
1157
- const img = /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("img", { src: main, alt, decoding: "async" });
1158
- content = scheme === "auto" && light !== void 0 && dark !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("picture", { children: [
1159
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("source", { media: "(prefers-color-scheme: dark)", srcSet: dark }),
2340
+ const img = /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("img", { src: main, alt, decoding: "async" });
2341
+ content = scheme === "auto" && light !== void 0 && dark !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("picture", { children: [
2342
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("source", { media: "(prefers-color-scheme: dark)", srcSet: dark }),
1160
2343
  img
1161
2344
  ] }) : img;
1162
2345
  } else if (name !== void 0) {
1163
- content = /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "tb-b-logo-name", children: name });
2346
+ content = /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "tb-b-logo-name", children: name });
1164
2347
  }
1165
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
1166
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(BasicStyles, {}),
1167
- content === null ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Placeholder, { editMode, children: "Logo: add one in Site settings" }) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "tb-b-logo", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("a", { href, children: content }) })
2348
+ return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(import_jsx_runtime25.Fragment, { children: [
2349
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(BasicStyles, {}),
2350
+ content === null ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(Placeholder, { editMode, children: "Logo: add one in Site settings" }) : /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "tb-b-logo", children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("a", { href, children: content }) })
1168
2351
  ] });
1169
2352
  }
1170
2353
 
1171
2354
  // src/basics/menu.tsx
1172
- var import_react7 = require("react");
2355
+ var import_react12 = require("react");
1173
2356
  var import_ui4 = require("@usethrottle/ui");
1174
- var import_builder_schema13 = require("@usethrottle/builder-schema");
1175
- var import_jsx_runtime15 = require("react/jsx-runtime");
2357
+ var import_builder_schema19 = require("@usethrottle/builder-schema");
2358
+ var import_jsx_runtime26 = require("react/jsx-runtime");
1176
2359
  var LAYOUTS = ["horizontal", "vertical", "drawer-on-phone"];
1177
- var MAX_DEPTH = 3;
2360
+ var MAX_DEPTH2 = 3;
1178
2361
  function List({ items, mediaOrigin, depth = 0, id, onNavigate }) {
1179
- const shown = items.flatMap((item) => {
1180
- const href = (0, import_builder_schema13.safeUrl)(item.href, "href", { mediaOrigin });
2362
+ const shown2 = items.flatMap((item) => {
2363
+ const href = (0, import_builder_schema19.safeUrl)(item.href, "href", { mediaOrigin });
1181
2364
  return href === null ? [] : [{ item, href }];
1182
2365
  });
1183
- if (shown.length === 0) return null;
1184
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("ul", { ...id === void 0 ? {} : { id }, ...onNavigate === void 0 ? {} : { onClick: onNavigate }, children: shown.map(({ item, href }, index) => /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("li", { children: [
1185
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("a", { href, children: item.label }),
1186
- depth + 1 < MAX_DEPTH && item.children !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(List, { items: item.children, mediaOrigin, depth: depth + 1 })
2366
+ if (shown2.length === 0) return null;
2367
+ return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("ul", { ...id === void 0 ? {} : { id }, ...onNavigate === void 0 ? {} : { onClick: onNavigate }, children: shown2.map(({ item, href }, index) => /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)("li", { children: [
2368
+ /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("a", { href, children: item.label }),
2369
+ depth + 1 < MAX_DEPTH2 && item.children !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(List, { items: item.children, mediaOrigin, depth: depth + 1 })
1187
2370
  ] }, `${String(index)}:${href}`)) });
1188
2371
  }
1189
2372
  function Menu({ props, mediaOrigin, editMode }) {
1190
2373
  const design = (0, import_ui4.useSiteDesign)();
1191
- const listId = (0, import_react7.useId)();
1192
- const toggle = (0, import_react7.useRef)(null);
1193
- const [open, setOpen] = (0, import_react7.useState)(false);
2374
+ const listId = (0, import_react12.useId)();
2375
+ const toggle = (0, import_react12.useRef)(null);
2376
+ const [open, setOpen] = (0, import_react12.useState)(false);
1194
2377
  const name = str(props.menu) ?? "header";
1195
2378
  const layout = oneOf(props.layout, LAYOUTS, "horizontal");
1196
2379
  const menus = design?.menus;
1197
2380
  const items = menus !== void 0 && Object.hasOwn(menus, name) ? menus[name] : void 0;
1198
2381
  const strings = design?.strings;
1199
- const label = (strings !== void 0 && Object.hasOwn(strings, "nav.menu") ? str(strings["nav.menu"]) : void 0) ?? import_builder_schema13.SITE_STRING_DEFAULTS["nav.menu"];
2382
+ const label = (strings !== void 0 && Object.hasOwn(strings, "nav.menu") ? str(strings["nav.menu"]) : void 0) ?? import_builder_schema19.SITE_STRING_DEFAULTS["nav.menu"];
1200
2383
  if (items === void 0 || items.length === 0) {
1201
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_jsx_runtime15.Fragment, { children: [
1202
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(BasicStyles, {}),
1203
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Placeholder, { editMode, children: `Menu "${name}" is empty: add links in Site settings` })
2384
+ return /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(import_jsx_runtime26.Fragment, { children: [
2385
+ /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(BasicStyles, {}),
2386
+ /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(Placeholder, { editMode, children: `Menu "${name}" is empty: add links in Site settings` })
1204
2387
  ] });
1205
2388
  }
1206
2389
  const drawer = layout === "drawer-on-phone";
@@ -1210,9 +2393,9 @@ function Menu({ props, mediaOrigin, editMode }) {
1210
2393
  toggle.current?.focus();
1211
2394
  }
1212
2395
  };
1213
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_jsx_runtime15.Fragment, { children: [
1214
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(BasicStyles, {}),
1215
- /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
2396
+ return /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(import_jsx_runtime26.Fragment, { children: [
2397
+ /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(BasicStyles, {}),
2398
+ /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(
1216
2399
  "nav",
1217
2400
  {
1218
2401
  className: `tb-b-menu tb-b-menu--${layout}${layout === "vertical" ? "" : " tb-b-menu--h"}`,
@@ -1220,7 +2403,7 @@ function Menu({ props, mediaOrigin, editMode }) {
1220
2403
  "data-open": drawer ? String(open) : void 0,
1221
2404
  onKeyDown: drawer ? onKeyDown : void 0,
1222
2405
  children: [
1223
- drawer && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
2406
+ drawer && /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
1224
2407
  "button",
1225
2408
  {
1226
2409
  ref: toggle,
@@ -1229,10 +2412,10 @@ function Menu({ props, mediaOrigin, editMode }) {
1229
2412
  "aria-expanded": open,
1230
2413
  "aria-controls": listId,
1231
2414
  onClick: () => setOpen((value) => !value),
1232
- children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_ui4.Icon, { name: open ? "close" : "menu", size: 24, label })
2415
+ children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(import_ui4.Icon, { name: open ? "close" : "menu", size: 24, label })
1233
2416
  }
1234
2417
  ),
1235
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(List, { items, mediaOrigin, id: listId, ...drawer ? { onNavigate: () => setOpen(false) } : {} })
2418
+ /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(List, { items, mediaOrigin, id: listId, ...drawer ? { onNavigate: () => setOpen(false) } : {} })
1236
2419
  ]
1237
2420
  }
1238
2421
  )
@@ -1240,18 +2423,18 @@ function Menu({ props, mediaOrigin, editMode }) {
1240
2423
  }
1241
2424
 
1242
2425
  // src/basics/spacer.tsx
1243
- var import_jsx_runtime16 = require("react/jsx-runtime");
2426
+ var import_jsx_runtime27 = require("react/jsx-runtime");
1244
2427
  function Spacer() {
1245
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_jsx_runtime16.Fragment, { children: [
1246
- /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(BasicStyles, {}),
1247
- /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: "tb-b-spacer", "aria-hidden": "true" })
2428
+ return /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)(import_jsx_runtime27.Fragment, { children: [
2429
+ /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(BasicStyles, {}),
2430
+ /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("div", { className: "tb-b-spacer", "aria-hidden": "true" })
1248
2431
  ] });
1249
2432
  }
1250
2433
 
1251
2434
  // src/basics/rich-text.tsx
1252
- var import_react8 = require("react");
1253
- var import_builder_schema14 = require("@usethrottle/builder-schema");
1254
- var import_jsx_runtime17 = require("react/jsx-runtime");
2435
+ var import_react13 = require("react");
2436
+ var import_builder_schema20 = require("@usethrottle/builder-schema");
2437
+ var import_jsx_runtime28 = require("react/jsx-runtime");
1255
2438
  var ALLOWED = /* @__PURE__ */ new Set(["p", "br", "strong", "em", "u", "s", "a", "ul", "ol", "li", "h2", "h3", "h4", "blockquote", "code"]);
1256
2439
  var ALIAS = { b: "strong", i: "em", strike: "s", del: "s" };
1257
2440
  var DROP_WITH_CONTENT = /* @__PURE__ */ new Set([
@@ -1276,7 +2459,7 @@ var VOID = /* @__PURE__ */ new Set(["br"]);
1276
2459
  var BLOCK = /* @__PURE__ */ new Set(["p", "h2", "h3", "h4", "ul", "ol", "blockquote"]);
1277
2460
  var TEXT_BLOCK = /* @__PURE__ */ new Set(["p", "h2", "h3", "h4"]);
1278
2461
  var MAX_LENGTH = 2e4;
1279
- var MAX_DEPTH2 = 24;
2462
+ var MAX_DEPTH3 = 24;
1280
2463
  var MAX_NODES = 4e3;
1281
2464
  var NAMED = {
1282
2465
  amp: "&",
@@ -1420,23 +2603,23 @@ function parseRichText(source, mediaOrigin) {
1420
2603
  const el = { tag: name, children: [] };
1421
2604
  if (name === "a") {
1422
2605
  const href = tag.attrs.get("href");
1423
- el.href = href === void 0 ? null : (0, import_builder_schema14.safeUrl)(decode(href).trim(), "href", { mediaOrigin });
2606
+ el.href = href === void 0 ? null : (0, import_builder_schema20.safeUrl)(decode(href).trim(), "href", { mediaOrigin });
1424
2607
  }
1425
2608
  nodes += 1;
1426
2609
  top().children.push(el);
1427
- if (!VOID.has(name) && stack.length < MAX_DEPTH2) stack.push(el);
2610
+ if (!VOID.has(name) && stack.length < MAX_DEPTH3) stack.push(el);
1428
2611
  }
1429
2612
  if (nodes > MAX_NODES) root.truncated = true;
1430
2613
  return root;
1431
2614
  }
1432
2615
  function toReact(el, key) {
1433
2616
  const children = el.children.map((child, index) => typeof child === "string" ? child : toReact(child, index));
1434
- if (el.tag === "br") return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("br", {}, key);
2617
+ if (el.tag === "br") return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("br", {}, key);
1435
2618
  if (el.tag === "a") {
1436
- if (el.href === null || el.href === void 0) return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_react8.Fragment, { children }, key);
1437
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("a", { href: el.href, rel: "noopener noreferrer", className: "tb-b-link", children }, key);
2619
+ if (el.href === null || el.href === void 0) return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(import_react13.Fragment, { children }, key);
2620
+ return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("a", { href: el.href, rel: "noopener noreferrer", className: "tb-b-link", children }, key);
1438
2621
  }
1439
- return (0, import_react8.createElement)(el.tag, { key }, ...children);
2622
+ return (0, import_react13.createElement)(el.tag, { key }, ...children);
1440
2623
  }
1441
2624
  function RichText({
1442
2625
  html,
@@ -1445,26 +2628,26 @@ function RichText({
1445
2628
  editMode = false
1446
2629
  }) {
1447
2630
  const tree = parseRichText(html, mediaOrigin);
1448
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className, children: [
2631
+ return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("div", { className, children: [
1449
2632
  tree.children.map((child, index) => typeof child === "string" ? child : toReact(child, index)),
1450
- editMode && tree.truncated === true && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("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." })
2633
+ editMode && tree.truncated === true && /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("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." })
1451
2634
  ] });
1452
2635
  }
1453
2636
 
1454
2637
  // src/basics/text.tsx
1455
- var import_jsx_runtime18 = require("react/jsx-runtime");
2638
+ var import_jsx_runtime29 = require("react/jsx-runtime");
1456
2639
  function Text({ props, mediaOrigin, editMode, inlineEdit }) {
1457
2640
  const editor = inlineEdit?.("html") ?? null;
1458
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_jsx_runtime18.Fragment, { children: [
1459
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(BasicStyles, {}),
1460
- editor === null ? /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(RichText, { html: str(props.html) ?? "", mediaOrigin, className: "tb-b-text", editMode }) : /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "tb-b-text", children: editor })
2641
+ return /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)(import_jsx_runtime29.Fragment, { children: [
2642
+ /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(BasicStyles, {}),
2643
+ editor === null ? /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(RichText, { html: str(props.html) ?? "", mediaOrigin, className: "tb-b-text", editMode }) : /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("div", { className: "tb-b-text", children: editor })
1461
2644
  ] });
1462
2645
  }
1463
2646
 
1464
2647
  // src/basics/video.tsx
1465
- var import_react9 = require("react");
2648
+ var import_react14 = require("react");
1466
2649
  var import_ui5 = require("@usethrottle/ui");
1467
- var import_jsx_runtime19 = require("react/jsx-runtime");
2650
+ var import_jsx_runtime30 = require("react/jsx-runtime");
1468
2651
  var RULES3 = [
1469
2652
  { key: "ratio", property: "--bx-ratio", values: { "16:9": "16 / 9", "4:3": "4 / 3", "1:1": "1 / 1", "9:16": "9 / 16" } }
1470
2653
  ];
@@ -1504,12 +2687,12 @@ function embedSrc(video, muted) {
1504
2687
  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" : ""}`;
1505
2688
  }
1506
2689
  function Video({ node, props, editMode }) {
1507
- const [loaded, setLoaded] = (0, import_react9.useState)(false);
2690
+ const [loaded, setLoaded] = (0, import_react14.useState)(false);
1508
2691
  const video = parseVideoUrl(str(props.url) ?? "");
1509
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_jsx_runtime19.Fragment, { children: [
1510
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(BasicStyles, {}),
1511
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(WidgetStyle, { css: enumCss(node, RULES3) }),
1512
- video === null ? /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Placeholder, { editMode, children: "Paste a YouTube or Vimeo link" }) : /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: "tb-b-video", "data-provider": video.provider, children: loaded && !editMode ? /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
2692
+ return /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)(import_jsx_runtime30.Fragment, { children: [
2693
+ /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(BasicStyles, {}),
2694
+ /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(WidgetStyle, { css: enumCss(node, RULES3) }),
2695
+ video === null ? /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(Placeholder, { editMode, children: "Paste a YouTube or Vimeo link" }) : /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("div", { className: "tb-b-video", "data-provider": video.provider, children: loaded && !editMode ? /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
1513
2696
  "iframe",
1514
2697
  {
1515
2698
  src: embedSrc(video, props.autoplayMuted === true),
@@ -1518,7 +2701,7 @@ function Video({ node, props, editMode }) {
1518
2701
  referrerPolicy: "strict-origin-when-cross-origin",
1519
2702
  sandbox: "allow-scripts allow-same-origin allow-presentation allow-popups"
1520
2703
  }
1521
- ) : /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("button", { type: "button", className: "tb-b-play", "aria-label": "Play video", onClick: () => setLoaded(true), children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("span", { children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ui5.Icon, { name: "play", size: 28 }) }) }) })
2704
+ ) : /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("button", { type: "button", className: "tb-b-play", "aria-label": "Play video", onClick: () => setLoaded(true), children: /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("span", { children: /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(import_ui5.Icon, { name: "play", size: 28 }) }) }) })
1522
2705
  ] });
1523
2706
  }
1524
2707
 
@@ -1534,289 +2717,40 @@ var BASIC_COMPONENTS = {
1534
2717
  "basic.logo": Logo,
1535
2718
  "basic.menu": Menu,
1536
2719
  "basic.announcement": Announcement,
1537
- "basic.copyright": Copyright
2720
+ "basic.copyright": Copyright,
2721
+ "basic.countdown": Countdown
1538
2722
  };
1539
- var widgets = import_builder_schema15.BASIC_WIDGET_DEFINITIONS.flatMap(
2723
+ var widgets = import_builder_schema21.BASIC_WIDGET_DEFINITIONS.flatMap(
1540
2724
  (definition) => Object.hasOwn(BASIC_COMPONENTS, definition.type) ? [{ ...definition, Component: BASIC_COMPONENTS[definition.type] }] : []
1541
2725
  );
1542
2726
  var basicPack = { id: "basic", version: "0.0.0", widgets, dataSources: [] };
1543
2727
 
1544
2728
  // src/custom/factory.ts
1545
- var import_react13 = require("react");
1546
-
1547
- // src/custom/composite-widget.tsx
1548
- var import_react12 = require("react");
1549
- var import_builder_schema19 = require("@usethrottle/builder-schema");
1550
-
1551
- // src/custom/template-widget.tsx
1552
- var import_react11 = require("react");
1553
- var import_builder_schema18 = require("@usethrottle/builder-schema");
1554
-
1555
- // src/custom/custom-css.tsx
1556
- var import_builder_schema16 = require("@usethrottle/builder-schema");
1557
- var import_jsx_runtime20 = require("react/jsx-runtime");
1558
- function scopedCss(source, type) {
1559
- if (source === void 0 || source === "") return "";
1560
- if (typeof source !== "string") return null;
1561
- const result = (0, import_builder_schema16.sanitizeWidgetCss)(source, type);
1562
- return result.ok ? result.css : null;
1563
- }
1564
- function CustomCss({ css }) {
1565
- return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(WidgetStyle, { css });
1566
- }
1567
-
1568
- // src/custom/interpreter.tsx
1569
- var import_react10 = require("react");
1570
- var import_builder_schema17 = require("@usethrottle/builder-schema");
1571
- var import_jsx_runtime21 = require("react/jsx-runtime");
1572
- var MAX_OUTPUT_CHARS = 1e6;
1573
- var MAX_ATTR_CHARS = 2e3;
1574
- var MAX_DEPTH3 = 24;
1575
- function newEnv(env) {
1576
- return { ...env, charsLeft: MAX_OUTPUT_CHARS, stopped: false };
1577
- }
1578
- var BLOCKED = /* @__PURE__ */ new Set([
1579
- "__proto__",
1580
- "constructor",
1581
- "prototype",
1582
- ...Object.getOwnPropertyNames(Object.prototype)
1583
- ]);
1584
- var isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
1585
- function step(value, key) {
1586
- if (BLOCKED.has(key) || !isPlainObject(value) || !Object.hasOwn(value, key)) return void 0;
1587
- return value[key];
1588
- }
1589
- function lookup(path, env, scope) {
1590
- const [root, ...rest] = path;
1591
- if (root === void 0) return void 0;
1592
- if (root === "locale") return rest.length === 0 ? env.locale : void 0;
1593
- let value;
1594
- if (root === "settings") value = rest.length === 0 ? void 0 : env.settings;
1595
- else if (root === "data") value = rest.length === 0 ? void 0 : env.data;
1596
- else if (scope.has(root)) value = scope.get(root);
1597
- else return void 0;
1598
- for (const key of rest) {
1599
- value = step(value, key);
1600
- if (value === void 0) return void 0;
1601
- }
1602
- return value;
1603
- }
1604
- function truthy(value) {
1605
- if (value === null || value === void 0 || value === false || value === "") return false;
1606
- if (typeof value === "number") return value !== 0 && !Number.isNaN(value);
1607
- if (Array.isArray(value)) return value.length > 0;
1608
- return true;
1609
- }
1610
- function asText(value) {
1611
- if (typeof value === "string") return value;
1612
- if (typeof value === "number" && Number.isFinite(value)) return String(value);
1613
- return "";
1614
- }
1615
- function filtered(value, filters) {
1616
- let text = asText(value);
1617
- for (const filter of filters) {
1618
- switch (filter.name) {
1619
- case "upper":
1620
- text = text.toUpperCase();
1621
- break;
1622
- case "lower":
1623
- text = text.toLowerCase();
1624
- break;
1625
- case "truncate": {
1626
- const chars = Array.from(text);
1627
- if (chars.length > filter.n) text = `${chars.slice(0, filter.n).join("")}\u2026`;
1628
- break;
1629
- }
1630
- case "default":
1631
- if (text === "") text = filter.text;
1632
- break;
1633
- }
1634
- }
1635
- return text;
1636
- }
1637
- function spend(env, count) {
1638
- if (count > env.charsLeft) {
1639
- env.stopped = true;
1640
- return false;
1641
- }
1642
- env.charsLeft -= count;
1643
- return true;
1644
- }
1645
- var ELEMENTS = new Set(import_builder_schema17.ALLOWED_ELEMENTS);
1646
- var VOIDS = new Set(import_builder_schema17.VOID_ELEMENTS);
1647
- var ROLES = new Set(import_builder_schema17.ALLOWED_ROLES);
1648
- function attrAllowed(tag, name) {
1649
- if (import_builder_schema17.DATA_ATTR_RE.test(name)) return !name.startsWith(import_builder_schema17.RESERVED_DATA_PREFIX);
1650
- const own = Object.hasOwn(import_builder_schema17.ALLOWED_ATTRS, tag) ? import_builder_schema17.ALLOWED_ATTRS[tag] : void 0;
1651
- return (import_builder_schema17.ALLOWED_ATTRS["*"]?.includes(name) ?? false) || (own?.includes(name) ?? false);
1652
- }
1653
- function attrText(attr, env, scope) {
1654
- return attr.value.map((part) => part.type === "text" ? part.value : filtered(lookup(part.path, env, scope), part.filters)).join("");
1655
- }
1656
- function urlSource(attr, env, scope) {
1657
- const [only] = attr.value;
1658
- if (attr.value.length !== 1 || only === void 0 || only.type !== "output") return attrText(attr, env, scope);
1659
- const value = lookup(only.path, env, scope);
1660
- if (isPlainObject(value)) {
1661
- if (typeof value.href === "string") return value.href;
1662
- if (typeof value.url === "string") return value.url;
1663
- return null;
1664
- }
1665
- return value;
1666
- }
1667
- function attrProp(tag, attr, env, scope) {
1668
- const { name } = attr;
1669
- if (!attrAllowed(tag, name)) return null;
1670
- if (name === "href" || name === "src") {
1671
- const safe = (0, import_builder_schema17.safeUrl)(urlSource(attr, env, scope), name, { mediaOrigin: env.mediaOrigin });
1672
- return safe === null || !spend(env, safe.length) ? null : [name, safe];
1673
- }
1674
- const text = attrText(attr, env, scope);
1675
- if (text === "" || text.length > MAX_ATTR_CHARS) return null;
1676
- let value = text;
1677
- if (name === "class") {
1678
- const tokens = text.split(/\s+/).filter((token) => import_builder_schema17.CLASS_TOKEN_RE.test(token) && !(0, import_builder_schema17.isReservedClass)(token));
1679
- if (tokens.length === 0) return null;
1680
- value = tokens.join(" ");
1681
- } else if (name === "role") {
1682
- if (!ROLES.has(text)) return null;
1683
- } else if (name === "aria-hidden") {
1684
- if (text !== "true" && text !== "false") return null;
1685
- }
1686
- if (!spend(env, value.length)) return null;
1687
- return [name === "class" ? "className" : name, value];
1688
- }
1689
- function renderElement(node, env, scope, depth, key) {
1690
- const tag = node.tag;
1691
- if (!ELEMENTS.has(tag)) return null;
1692
- const props = { key };
1693
- for (const attr of node.attrs) {
1694
- const prop = attrProp(tag, attr, env, scope);
1695
- if (prop !== null) props[prop[0]] = prop[1];
1696
- }
1697
- if (VOIDS.has(tag)) return (0, import_react10.createElement)(tag, props);
1698
- return (0, import_react10.createElement)(tag, props, renderNodes(node.children, env, scope, depth + 1));
1699
- }
1700
- function renderNodes(nodes, env, scope, depth) {
1701
- const out = [];
1702
- if (depth > MAX_DEPTH3) return out;
1703
- for (const node of nodes) {
1704
- if (env.stopped) break;
1705
- if (!env.budget.take(1) || node.type === "element" && !env.budget.take(node.attrs.reduce((n, a) => n + a.value.length, 0))) {
1706
- env.stopped = true;
1707
- break;
1708
- }
1709
- switch (node.type) {
1710
- case "text":
1711
- if (spend(env, node.value.length)) out.push(node.value);
1712
- break;
1713
- case "output": {
1714
- const text = filtered(lookup(node.path, env, scope), node.filters);
1715
- if (text !== "" && spend(env, text.length)) out.push(text);
1716
- break;
1717
- }
1718
- case "if": {
1719
- const branch = truthy(lookup(node.path, env, scope)) ? node.then : node.else;
1720
- out.push(/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_react10.Fragment, { children: renderNodes(branch, env, scope, depth + 1) }, out.length));
1721
- break;
1722
- }
1723
- case "unless":
1724
- if (!truthy(lookup(node.path, env, scope))) {
1725
- out.push(/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_react10.Fragment, { children: renderNodes(node.body, env, scope, depth + 1) }, out.length));
1726
- }
1727
- break;
1728
- case "each": {
1729
- const list = lookup(node.path, env, scope);
1730
- if (!Array.isArray(list)) break;
1731
- const count = Math.min(list.length, import_builder_schema17.EACH_ITERATION_CAP);
1732
- for (let i = 0; i < count && !env.stopped; i += 1) {
1733
- const inner = new Map(scope).set(node.as, list[i]);
1734
- out.push(/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_react10.Fragment, { children: renderNodes(node.body, env, inner, depth + 1) }, out.length));
1735
- }
1736
- break;
1737
- }
1738
- case "element":
1739
- out.push(renderElement(node, env, scope, depth, out.length));
1740
- break;
1741
- }
1742
- }
1743
- return out;
1744
- }
1745
- function renderTemplate(ast, env) {
1746
- return renderNodes(ast, env, /* @__PURE__ */ new Map(), 0);
1747
- }
1748
-
1749
- // src/custom/template-widget.tsx
1750
- var import_jsx_runtime22 = require("react/jsx-runtime");
1751
- var componentWeights = /* @__PURE__ */ new WeakMap();
1752
- var compiled = /* @__PURE__ */ new WeakMap();
1753
- function compileTemplate(snapshot, registry) {
1754
- let perRegistry = compiled.get(snapshot);
1755
- if (perRegistry === void 0) {
1756
- perRegistry = /* @__PURE__ */ new WeakMap();
1757
- compiled.set(snapshot, perRegistry);
1758
- }
1759
- if (perRegistry.has(registry)) return perRegistry.get(registry) ?? null;
1760
- const result = compile(snapshot, registry);
1761
- perRegistry.set(registry, result);
1762
- return result;
1763
- }
1764
- function compile(snapshot, registry) {
1765
- const label = `${snapshot.type}@${String(snapshot.v)}`;
1766
- const refuse = (why) => {
1767
- warnOnce(`template:${label}`, `${label} was refused (${why}); rendering nothing for it`);
1768
- return null;
1769
- };
1770
- if (snapshot.kind !== "template") return refuse("not a template widget");
1771
- const source = snapshot.template;
1772
- if (typeof source !== "string") return refuse("no template source");
1773
- const parsed = (0, import_builder_schema18.parseTemplate)(source);
1774
- if (!parsed.ok) return refuse(`template does not parse: ${parsed.issues[0]?.message ?? "invalid"}`);
1775
- const data = snapshot.data;
1776
- const issues = (0, import_builder_schema18.validateTemplate)(parsed.ast, {
1777
- settings: snapshot.settings,
1778
- data: typeof data === "object" && data !== null ? data : {},
1779
- sources: registry.sources()
1780
- });
1781
- if (issues.length > 0) return refuse(`template does not validate: ${issues[0]?.message ?? "invalid"}`);
1782
- if (!fitsBudget(parsed.ast)) return refuse(`it can render more than ${String(import_builder_schema18.MAX_TEMPLATE_WEIGHT)} nodes`);
1783
- const css = scopedCss(snapshot.css, snapshot.type);
1784
- if (css === null) return refuse("its css does not pass the sanitiser");
1785
- return { ast: parsed.ast, css, weight: (0, import_builder_schema18.templateWeight)(parsed.ast) };
1786
- }
1787
- function TemplateBody({ snapshot, registry, props, data, locale, mediaOrigin, budget }) {
1788
- const template = compileTemplate(snapshot, registry);
1789
- if (template === null) return null;
1790
- const env = newEnv({ settings: props, data, locale, mediaOrigin, budget: budget ?? new RenderBudget() });
1791
- return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(import_jsx_runtime22.Fragment, { children: [
1792
- template.css === "" ? null : /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(CustomCss, { css: template.css }),
1793
- renderTemplate(template.ast, env)
1794
- ] });
1795
- }
1796
- function TemplateWidget(props) {
1797
- return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(PartBoundary, { label: `${props.snapshot.type}@${String(props.snapshot.v)}`, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(import_react11.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(TemplateBody, { ...props }) }) });
1798
- }
2729
+ var import_react16 = require("react");
1799
2730
 
1800
2731
  // src/custom/composite-widget.tsx
1801
- var import_jsx_runtime23 = require("react/jsx-runtime");
2732
+ var import_react15 = require("react");
2733
+ var import_builder_schema22 = require("@usethrottle/builder-schema");
2734
+ var import_jsx_runtime31 = require("react/jsx-runtime");
1802
2735
  var SETTING_KEY_RE = /^[a-z][A-Za-z0-9]{0,39}$/;
1803
2736
  var NODE_ID_RE = /^[a-z0-9]{8,24}$/;
1804
2737
  var WRAP = { section: "zzcompsec001", column: "zzcompcol001", inner: "zzcompinr001" };
1805
- var isRecord3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
1806
- var compiled2 = /* @__PURE__ */ new WeakMap();
2738
+ var isRecord4 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
2739
+ var compiled3 = /* @__PURE__ */ new WeakMap();
1807
2740
  function parseBody(raw) {
1808
- if (!isRecord3(raw)) return null;
2741
+ if (!isRecord4(raw)) return null;
1809
2742
  const columns = Array.isArray(raw.columns) ? raw.columns : void 0;
1810
2743
  const stack = Array.isArray(raw.stack) ? raw.stack : void 0;
1811
2744
  if (columns === void 0 === (stack === void 0)) return null;
1812
2745
  const children = columns !== void 0 ? [{ id: WRAP.inner, type: "inner-section", props: {}, columns }] : stack ?? [];
1813
- if (stack?.some((node) => isRecord3(node) && node.type === "inner-section")) return null;
1814
- const parsed = import_builder_schema19.pageDocumentSchema.safeParse({
2746
+ if (stack?.some((node) => isRecord4(node) && node.type === "inner-section")) return null;
2747
+ const parsed2 = import_builder_schema22.pageDocumentSchema.safeParse({
1815
2748
  schemaVersion: 1,
1816
2749
  sections: [{ id: WRAP.section, type: "section", props: {}, columns: [{ id: WRAP.column, type: "column", props: { width: 100 }, children }] }]
1817
2750
  });
1818
- if (!parsed.success) return null;
1819
- const first = parsed.data.sections[0]?.columns[0]?.children ?? [];
2751
+ if (!parsed2.success) return null;
2752
+ const wrapper = parsed2.data.sections[0];
2753
+ const first = (wrapper?.type === "section" ? wrapper.columns[0]?.children : void 0) ?? [];
1820
2754
  if (columns !== void 0) {
1821
2755
  const inner = first[0];
1822
2756
  return inner?.type === "inner-section" ? { columns: inner.columns } : null;
@@ -1824,9 +2758,9 @@ function parseBody(raw) {
1824
2758
  return { stack: first.filter((node) => node.type !== "inner-section") };
1825
2759
  }
1826
2760
  function compileComposite(snapshot) {
1827
- if (compiled2.has(snapshot)) return compiled2.get(snapshot) ?? null;
2761
+ if (compiled3.has(snapshot)) return compiled3.get(snapshot) ?? null;
1828
2762
  const result = compile2(snapshot);
1829
- compiled2.set(snapshot, result);
2763
+ compiled3.set(snapshot, result);
1830
2764
  return result;
1831
2765
  }
1832
2766
  function compile2(snapshot) {
@@ -1842,12 +2776,12 @@ function compile2(snapshot) {
1842
2776
  const bindings = [];
1843
2777
  if (extra.bindings !== void 0 && !Array.isArray(extra.bindings)) return refuse("bindings is not a list");
1844
2778
  for (const raw of extra.bindings ?? []) {
1845
- if (!isRecord3(raw) || typeof raw.setting !== "string" || !SETTING_KEY_RE.test(raw.setting) || !Array.isArray(raw.targets)) {
2779
+ if (!isRecord4(raw) || typeof raw.setting !== "string" || !SETTING_KEY_RE.test(raw.setting) || !Array.isArray(raw.targets)) {
1846
2780
  return refuse("a binding is malformed");
1847
2781
  }
1848
2782
  const targets = [];
1849
2783
  for (const target of raw.targets) {
1850
- if (!isRecord3(target) || typeof target.node !== "string" || !NODE_ID_RE.test(target.node) || typeof target.prop !== "string" || !SETTING_KEY_RE.test(target.prop)) {
2784
+ if (!isRecord4(target) || typeof target.node !== "string" || !NODE_ID_RE.test(target.node) || typeof target.prop !== "string" || !SETTING_KEY_RE.test(target.prop)) {
1851
2785
  return refuse("a binding target is malformed");
1852
2786
  }
1853
2787
  targets.push({ node: target.node, prop: target.prop });
@@ -1855,12 +2789,12 @@ function compile2(snapshot) {
1855
2789
  bindings.push({ setting: raw.setting, targets });
1856
2790
  }
1857
2791
  const data = [];
1858
- if (extra.data !== void 0 && !isRecord3(extra.data)) return refuse("data is not a record");
2792
+ if (extra.data !== void 0 && !isRecord4(extra.data)) return refuse("data is not a record");
1859
2793
  for (const [name, raw] of Object.entries(extra.data ?? {})) {
1860
- if (!SETTING_KEY_RE.test(name) || !isRecord3(raw) || !Array.isArray(raw.targets)) return refuse("a data input is malformed");
2794
+ if (!SETTING_KEY_RE.test(name) || !isRecord4(raw) || !Array.isArray(raw.targets)) return refuse("a data input is malformed");
1861
2795
  const targets = [];
1862
2796
  for (const target of raw.targets) {
1863
- if (!isRecord3(target) || typeof target.node !== "string" || !NODE_ID_RE.test(target.node) || typeof target.input !== "string" || !SETTING_KEY_RE.test(target.input)) {
2797
+ if (!isRecord4(target) || typeof target.node !== "string" || !NODE_ID_RE.test(target.node) || typeof target.input !== "string" || !SETTING_KEY_RE.test(target.input)) {
1864
2798
  return refuse("a data target is malformed");
1865
2799
  }
1866
2800
  targets.push({ node: target.node, input: target.input });
@@ -1916,7 +2850,7 @@ function build(input) {
1916
2850
  return id;
1917
2851
  }
1918
2852
  if (field.control === "link") {
1919
- if (!isRecord3(value) || typeof value.kind !== "string") return null;
2853
+ if (!isRecord4(value) || typeof value.kind !== "string") return null;
1920
2854
  const { href, ...target } = value;
1921
2855
  if (target.kind === "url") return typeof href === "string" ? { kind: "url", href } : null;
1922
2856
  hrefs.set(JSON.stringify(target), typeof href === "string" ? href : null);
@@ -1933,14 +2867,14 @@ function build(input) {
1933
2867
  const innerField = inner === void 0 ? void 0 : registry.widget(inner.type, inner.v)?.settings.find((f) => f.key === target.prop);
1934
2868
  if (inner === void 0 || innerField === void 0 || innerField.control !== field.control) continue;
1935
2869
  const converted = convert(field, value);
1936
- if ((0, import_builder_schema19.validateSettingValue)(innerField, converted) !== null) continue;
2870
+ if ((0, import_builder_schema22.validateSettingValue)(innerField, converted) !== null) continue;
1937
2871
  inner.props[target.prop] = converted;
1938
2872
  const responsive = inner.responsive;
1939
2873
  for (const device of DEVICES3) {
1940
2874
  if (responsive?.[device] !== void 0) delete responsive[device][target.prop];
1941
2875
  const raw = outer.responsive?.[device];
1942
2876
  const plain = field.output === "css" && field.translatable !== true && field.control !== "image" && field.control !== "link";
1943
- if (plain && raw !== void 0 && Object.hasOwn(raw, binding.setting) && (0, import_builder_schema19.validateSettingValue)(innerField, raw[binding.setting]) === null) {
2877
+ if (plain && raw !== void 0 && Object.hasOwn(raw, binding.setting) && (0, import_builder_schema22.validateSettingValue)(innerField, raw[binding.setting]) === null) {
1944
2878
  const target$ = inner.responsive ?? (inner.responsive = {});
1945
2879
  (target$[device] ?? (target$[device] = {}))[target.prop] = raw[binding.setting];
1946
2880
  }
@@ -1967,7 +2901,7 @@ function build(input) {
1967
2901
  props: { width: 100 },
1968
2902
  children: columns !== void 0 ? [{ id: ids.inner, type: "inner-section", props: { width: "full" }, columns }] : stack ?? []
1969
2903
  };
1970
- const document = {
2904
+ const document2 = {
1971
2905
  schemaVersion: 1,
1972
2906
  sections: [{ id: ids.section, type: "section", props: { width: "full" }, columns: [column] }]
1973
2907
  };
@@ -1976,10 +2910,10 @@ function build(input) {
1976
2910
  const component = registry.component(widget);
1977
2911
  weight += 1 + (component === void 0 ? 0 : componentWeights.get(component) ?? 0);
1978
2912
  }
1979
- return { document, assets, data: innerData, hrefs, weight };
2913
+ return { document: document2, assets, data: innerData, hrefs, weight };
1980
2914
  }
1981
2915
  function CompositeBody(props) {
1982
- const { snapshot, registry, node, data, locale, mediaOrigin, budget, resolveLink } = props;
2916
+ const { snapshot, registry, node, data, locale, mediaOrigin, budget, resolveLink, interactive, idScope } = props;
1983
2917
  const composite = compileComposite(snapshot);
1984
2918
  if (composite === null) return null;
1985
2919
  const built = build({ snapshot, compiled: composite, registry, node, props: props.props, data });
@@ -1987,7 +2921,7 @@ function CompositeBody(props) {
1987
2921
  warnOnce(`composite-weight:${snapshot.type}@${String(snapshot.v)}`, `${snapshot.type} would render too many nodes; rendering nothing for it`);
1988
2922
  return null;
1989
2923
  }
1990
- return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
2924
+ return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
1991
2925
  BuilderRenderer,
1992
2926
  {
1993
2927
  document: built.document,
@@ -1996,28 +2930,30 @@ function CompositeBody(props) {
1996
2930
  locale,
1997
2931
  assets: built.assets,
1998
2932
  mediaOrigin,
2933
+ interactive,
2934
+ idScope,
1999
2935
  resolveLink: (target) => built.hrefs.get(JSON.stringify(target)) ?? resolveLink?.(target) ?? null
2000
2936
  }
2001
2937
  );
2002
2938
  }
2003
2939
  function CompositeWidget(props) {
2004
- return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(PartBoundary, { label: `${props.snapshot.type}@${String(props.snapshot.v)}`, children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(import_react12.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(CompositeBody, { ...props }) }) });
2940
+ return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(PartBoundary, { label: `${props.snapshot.type}@${String(props.snapshot.v)}`, children: /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(import_react15.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(CompositeBody, { ...props }) }) });
2005
2941
  }
2006
2942
 
2007
2943
  // src/custom/factory.ts
2008
2944
  var isDisabled = (snapshot) => snapshot.status === "disabled";
2009
- var Disabled = ({ editMode }) => editMode ? (0, import_react13.createElement)("div", { className: "tb-missing" }, "This custom widget is disabled") : null;
2945
+ var Disabled = ({ editMode }) => editMode ? (0, import_react16.createElement)("div", { className: "tb-missing" }, "This custom widget is disabled") : null;
2010
2946
  var customWidgetFactory = (snapshot, registry) => {
2011
2947
  if (isDisabled(snapshot)) return Disabled;
2012
2948
  if (snapshot.kind === "template") {
2013
2949
  const template = compileTemplate(snapshot, registry);
2014
2950
  if (template === null) return null;
2015
- const Component2 = (props) => (0, import_react13.createElement)(TemplateWidget, { ...props, snapshot, registry });
2951
+ const Component2 = (props) => (0, import_react16.createElement)(TemplateWidget, { ...props, snapshot, registry });
2016
2952
  componentWeights.set(Component2, template.weight);
2017
2953
  return Component2;
2018
2954
  }
2019
2955
  if (compileComposite(snapshot) === null) return null;
2020
- return (props) => (0, import_react13.createElement)(CompositeWidget, { ...props, snapshot, registry });
2956
+ return (props) => (0, import_react16.createElement)(CompositeWidget, { ...props, snapshot, registry });
2021
2957
  };
2022
2958
 
2023
2959
  // src/registry.ts
@@ -2025,12 +2961,12 @@ var BUILTIN_PACKS = [basicPack];
2025
2961
  var DEFAULT_CUSTOM_WIDGET = customWidgetFactory;
2026
2962
  var customKey = (type, v) => `${type}@${String(v)}`;
2027
2963
  function createRendererRegistry(packs, options = {}) {
2028
- const all = [...BUILTIN_PACKS, ...packs];
2964
+ const all2 = [...BUILTIN_PACKS, ...packs];
2029
2965
  const components = /* @__PURE__ */ new Map();
2030
2966
  const definitions = [];
2031
2967
  const sources = [];
2032
2968
  const resolvers = /* @__PURE__ */ new Map();
2033
- for (const pack of all) {
2969
+ for (const pack of all2) {
2034
2970
  for (const { Component: Component2, ...definition } of pack.widgets) {
2035
2971
  const key = customKey(definition.type, definition.v);
2036
2972
  if (components.has(key)) continue;
@@ -2045,7 +2981,7 @@ function createRendererRegistry(packs, options = {}) {
2045
2981
  }
2046
2982
  const factory = options.customWidget ?? DEFAULT_CUSTOM_WIDGET;
2047
2983
  const build2 = (custom) => {
2048
- const schema = (0, import_builder_schema20.createRegistry)(definitions, sources, custom);
2984
+ const schema = (0, import_builder_schema23.createRegistry)(definitions, sources, custom);
2049
2985
  const snapshots = new Map(custom.map((snapshot) => [customKey(snapshot.type, snapshot.v), snapshot]));
2050
2986
  const built = /* @__PURE__ */ new Map();
2051
2987
  const registry = {
@@ -2061,7 +2997,7 @@ function createRendererRegistry(packs, options = {}) {
2061
2997
  if (own !== void 0) return own;
2062
2998
  if (!node.type.startsWith("custom.") || factory === void 0) return void 0;
2063
2999
  const snapshot = snapshots.get(key);
2064
- if (snapshot === void 0) return void 0;
3000
+ if (snapshot === void 0 || snapshot.kind === "code") return void 0;
2065
3001
  if (!built.has(key)) built.set(key, factory(snapshot, registry));
2066
3002
  return built.get(key) ?? void 0;
2067
3003
  },
@@ -2073,8 +3009,8 @@ function createRendererRegistry(packs, options = {}) {
2073
3009
  }
2074
3010
 
2075
3011
  // src/slot.tsx
2076
- var import_react14 = require("react");
2077
- var import_jsx_runtime24 = require("react/jsx-runtime");
3012
+ var import_react17 = require("react");
3013
+ var import_jsx_runtime32 = require("react/jsx-runtime");
2078
3014
  function contextKey(context) {
2079
3015
  if (typeof context !== "object" || context === null) return "";
2080
3016
  return Object.values(context).map((value) => {
@@ -2090,20 +3026,20 @@ function BuilderSlot({ name, context }) {
2090
3026
  if (part === void 0 || part.document.sections.length === 0) return null;
2091
3027
  return (
2092
3028
  // Suspense inside the boundary: see parts.tsx.
2093
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(PartBoundary, { label: `Builder slot ${name}`, resetKey: contextKey(context), children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { "data-throttle-part": "builder-slot", "data-b-slot": name, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_react14.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(PartView, { part, context }) }) }) })
3029
+ /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(PartBoundary, { label: `Builder slot ${name}`, resetKey: contextKey(context), children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("div", { "data-throttle-part": "builder-slot", "data-b-slot": name, children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(import_react17.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(PartView, { part, context }) }) }) })
2094
3030
  );
2095
3031
  }
2096
3032
 
2097
3033
  // src/theme.ts
2098
- var import_builder_schema21 = require("@usethrottle/builder-schema");
3034
+ var import_builder_schema24 = require("@usethrottle/builder-schema");
2099
3035
  var import_presets = require("@usethrottle/ui/presets");
2100
- var isRecord4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
3036
+ var isRecord5 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
2101
3037
  var str2 = (v) => typeof v === "string" && v !== "" ? v : void 0;
2102
3038
  var HEX = /^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;
2103
3039
  var SCALE = { compact: 0.85, comfortable: 1, roomy: 1.25 };
2104
3040
  var PALETTE_KEYS = Object.keys(import_presets.PRESET_TOKENS.clean.light);
2105
3041
  function palette(base, over) {
2106
- if (!isRecord4(over)) return base;
3042
+ if (!isRecord5(over)) return base;
2107
3043
  const out = { ...base };
2108
3044
  for (const key of PALETTE_KEYS) {
2109
3045
  const value = over[key];
@@ -2112,13 +3048,13 @@ function palette(base, over) {
2112
3048
  return out;
2113
3049
  }
2114
3050
  function themeTokens(settings) {
2115
- const theme = isRecord4(settings.theme) ? settings.theme : {};
3051
+ const theme = isRecord5(settings.theme) ? settings.theme : {};
2116
3052
  const preset = import_presets.PRESET_NAMES.includes(theme.preset) ? theme.preset : "clean";
2117
3053
  const customized = theme.customized === true;
2118
3054
  const base = import_presets.PRESET_TOKENS[preset];
2119
3055
  const colorScheme = theme.colorScheme === "light" || theme.colorScheme === "dark" ? theme.colorScheme : "auto";
2120
3056
  if (!customized) return { preset, customized, tokens: base, colorScheme };
2121
- const fonts = isRecord4(theme.fonts) ? theme.fonts : {};
3057
+ const fonts = isRecord5(theme.fonts) ? theme.fonts : {};
2122
3058
  return {
2123
3059
  preset,
2124
3060
  customized,
@@ -2144,7 +3080,7 @@ var SYSTEM_STACK = {
2144
3080
  };
2145
3081
  function fontStack(family) {
2146
3082
  if (Object.hasOwn(SYSTEM_STACK, family)) return SYSTEM_STACK[family];
2147
- const known = import_builder_schema21.SITE_FONTS.find((f) => f.family === family);
3083
+ const known = import_builder_schema24.SITE_FONTS.find((f) => f.family === family);
2148
3084
  if (known === void 0 || !/^[A-Za-z0-9 ]{1,60}$/.test(family)) return SYSTEM_STACK["system-sans"];
2149
3085
  return `"${family}", ${Object.hasOwn(GENERIC, known.category) ? GENERIC[known.category] : "sans-serif"}`;
2150
3086
  }
@@ -2188,20 +3124,30 @@ function themeCss(settings) {
2188
3124
  if (colorScheme === "dark") return `${light}:root{${dark}}`;
2189
3125
  return `${light}@media (prefers-color-scheme:dark){:root{${dark}}}`;
2190
3126
  }
3127
+ function customCssOf(settings) {
3128
+ const theme = isRecord5(settings.theme) ? settings.theme : {};
3129
+ const css = theme.customCss;
3130
+ if (typeof css !== "string" || css.trim() === "" || css.length > import_builder_schema24.THEME_CSS_MAX_CHARS) return "";
3131
+ const result = (0, import_builder_schema24.sanitizeThemeCss)(css);
3132
+ return result.ok ? result.css : "";
3133
+ }
3134
+ function customCssSheet(css) {
3135
+ return css === "" ? "" : `@layer throttle,throttle-custom;@layer throttle-custom{${css}}`;
3136
+ }
2191
3137
  function makeResolveLink(settings, packs) {
2192
- const routes = isRecord4(settings.routes) ? settings.routes : {};
3138
+ const routes = isRecord5(settings.routes) ? settings.routes : {};
2193
3139
  const pageRoute = str2(routes.page) ?? "/pages/{handle}";
2194
3140
  return (target) => {
2195
3141
  for (const pack of packs) {
2196
3142
  const href = pack.linkTargets?.resolve(target) ?? null;
2197
- if (href !== null) return (0, import_builder_schema21.safeUrl)(href, "href", { mediaOrigin: "" });
3143
+ if (href !== null) return (0, import_builder_schema24.safeUrl)(href, "href", { mediaOrigin: "" });
2198
3144
  }
2199
- if (target.kind === "url") return (0, import_builder_schema21.safeUrl)(target.href, "href", { mediaOrigin: "" });
2200
- if (typeof target.href === "string") return (0, import_builder_schema21.safeUrl)(target.href, "href", { mediaOrigin: "" });
3145
+ if (target.kind === "url") return (0, import_builder_schema24.safeUrl)(target.href, "href", { mediaOrigin: "" });
3146
+ if (typeof target.href === "string") return (0, import_builder_schema24.safeUrl)(target.href, "href", { mediaOrigin: "" });
2201
3147
  if (target.kind === "page") {
2202
3148
  const slug = str2(target.slug) ?? str2(target.handle);
2203
3149
  if (slug !== void 0 && /^[A-Za-z0-9._~-]{1,200}$/.test(slug)) {
2204
- return (0, import_builder_schema21.safeUrl)(pageRoute.replace("{handle}", slug), "href", { mediaOrigin: "" });
3150
+ return (0, import_builder_schema24.safeUrl)(pageRoute.replace("{handle}", slug), "href", { mediaOrigin: "" });
2205
3151
  }
2206
3152
  }
2207
3153
  return null;
@@ -2212,7 +3158,7 @@ function menuItems(items, resolve, depth = 0) {
2212
3158
  if (!Array.isArray(items) || depth > 3) return [];
2213
3159
  const out = [];
2214
3160
  for (const item of items) {
2215
- if (!isRecord4(item) || !isRecord4(item.target) || typeof item.target.kind !== "string") continue;
3161
+ if (!isRecord5(item) || !isRecord5(item.target) || typeof item.target.kind !== "string") continue;
2216
3162
  const label = str2(item.label);
2217
3163
  const href = resolve(item.target);
2218
3164
  if (label === void 0 || href === null) continue;
@@ -2228,24 +3174,24 @@ function menuItems(items, resolve, depth = 0) {
2228
3174
  return out;
2229
3175
  }
2230
3176
  var assetUrl = (v, mediaOrigin) => {
2231
- const raw = typeof v === "string" ? v : isRecord4(v) ? v.url : void 0;
2232
- return typeof raw === "string" ? (0, import_builder_schema21.safeUrl)(raw, "src", { mediaOrigin }) ?? void 0 : void 0;
3177
+ const raw = typeof v === "string" ? v : isRecord5(v) ? v.url : void 0;
3178
+ return typeof raw === "string" ? (0, import_builder_schema24.safeUrl)(raw, "src", { mediaOrigin }) ?? void 0 : void 0;
2233
3179
  };
2234
3180
  function siteDesignOf(settings, resolve, pageOutlet, mediaOrigin) {
2235
3181
  const { preset, customized, tokens, colorScheme } = themeTokens(settings);
2236
- const brand = isRecord4(settings.brand) ? settings.brand : {};
2237
- const logo = isRecord4(brand.logo) ? brand.logo : {};
3182
+ const brand = isRecord5(settings.brand) ? settings.brand : {};
3183
+ const logo = isRecord5(brand.logo) ? brand.logo : {};
2238
3184
  const light = assetUrl(logo.light, mediaOrigin);
2239
3185
  const dark = assetUrl(logo.dark, mediaOrigin);
2240
3186
  const favicon = assetUrl(brand.favicon, mediaOrigin);
2241
- const menus = isRecord4(settings.menus) ? Object.fromEntries(Object.entries(settings.menus).map(([name, items]) => [name, menuItems(items, resolve)])) : {};
2242
- const announcement = isRecord4(settings.announcement) ? settings.announcement : null;
3187
+ const menus = isRecord5(settings.menus) ? Object.fromEntries(Object.entries(settings.menus).map(([name, items]) => [name, menuItems(items, resolve)])) : {};
3188
+ const announcement = isRecord5(settings.announcement) ? settings.announcement : null;
2243
3189
  const message = announcement === null ? void 0 : str2(announcement.message);
2244
- const announcementHref = announcement !== null && isRecord4(announcement.target) && typeof announcement.target.kind === "string" ? resolve(announcement.target) : null;
2245
- const strings = isRecord4(settings.strings) ? Object.fromEntries(Object.entries(settings.strings).filter((entry) => typeof entry[1] === "string")) : {};
2246
- const seo = isRecord4(settings.seo) ? settings.seo : {};
2247
- const routes = isRecord4(settings.routes) ? settings.routes : {};
2248
- const connections = isRecord4(settings.connections) ? settings.connections : {};
3190
+ const announcementHref = announcement !== null && isRecord5(announcement.target) && typeof announcement.target.kind === "string" ? resolve(announcement.target) : null;
3191
+ const strings = isRecord5(settings.strings) ? Object.fromEntries(Object.entries(settings.strings).filter((entry) => typeof entry[1] === "string")) : {};
3192
+ const seo = isRecord5(settings.seo) ? settings.seo : {};
3193
+ const routes = isRecord5(settings.routes) ? settings.routes : {};
3194
+ const connections = isRecord5(settings.connections) ? settings.connections : {};
2249
3195
  const shareImage = assetUrl(seo.shareImage, mediaOrigin);
2250
3196
  const titleTemplate = str2(seo.titleTemplate);
2251
3197
  const defaultDescription = str2(seo.defaultDescription);
@@ -2275,45 +3221,45 @@ function siteDesignOf(settings, resolve, pageOutlet, mediaOrigin) {
2275
3221
  }
2276
3222
 
2277
3223
  // src/provider.tsx
2278
- var import_jsx_runtime25 = require("react/jsx-runtime");
3224
+ var import_jsx_runtime33 = require("react/jsx-runtime");
2279
3225
  var EMPTY = {};
2280
3226
  function useParentFont() {
2281
- return (0, import_react15.useContext)(import_ui6.AppearanceContext)?.variables?.fontFamily;
3227
+ return (0, import_react18.useContext)(import_ui6.AppearanceContext)?.variables?.fontFamily;
2282
3228
  }
2283
- function BuilderProvider({ builderKey, client, packs, site, onError, children }) {
3229
+ function BuilderProvider({ builderKey, client, packs, site, onError, interactive = true, pathname, catalogRoutes, mode = "live", children }) {
2284
3230
  const packsKey = packs.map((pack) => `${pack.id}@${pack.version}`).join("|");
2285
- const registryRef = (0, import_react15.useRef)(null);
3231
+ const registryRef = (0, import_react18.useRef)(null);
2286
3232
  if (registryRef.current?.key !== packsKey) {
2287
3233
  registryRef.current = { key: packsKey, registry: createRendererRegistry(packs) };
2288
3234
  }
2289
3235
  const registry = registryRef.current.registry;
2290
- const builder = (0, import_react15.useMemo)(
3236
+ const builder = (0, import_react18.useMemo)(
2291
3237
  () => client ?? (builderKey === void 0 ? null : (0, import_builder2.createBuilderClient)({ builderKey })),
2292
3238
  [client, builderKey]
2293
3239
  );
2294
3240
  const mediaOrigin = site.status === "ok" ? site.mediaOrigin : "";
2295
3241
  const settings = site.status === "ok" ? site.settings : EMPTY;
2296
- const resolveLink = (0, import_react15.useMemo)(() => makeResolveLink(settings, packs), [settings, packs]);
2297
- const outlets = (0, import_react15.useRef)(/* @__PURE__ */ new Map());
2298
- const renderers = (0, import_react15.useRef)(/* @__PURE__ */ new Map());
2299
- const pageOutlet = (0, import_react15.useCallback)((handle) => {
3242
+ const resolveLink = (0, import_react18.useMemo)(() => makeResolveLink(settings, packs), [settings, packs]);
3243
+ const outlets = (0, import_react18.useRef)(/* @__PURE__ */ new Map());
3244
+ const renderers = (0, import_react18.useRef)(/* @__PURE__ */ new Map());
3245
+ const pageOutlet = (0, import_react18.useCallback)((handle) => {
2300
3246
  let outlet = outlets.current.get(handle);
2301
3247
  if (outlet === void 0) {
2302
3248
  outlet = function PageOutlet() {
2303
- return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(PartBoundary, { label: `Builder page ${handle}`, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(import_react15.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(BuilderPage, { slug: handle }) }) });
3249
+ return /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(PartBoundary, { label: `Builder page ${handle}`, children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(import_react18.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(BuilderPage, { slug: handle }) }) });
2304
3250
  };
2305
3251
  outlets.current.set(handle, outlet);
2306
3252
  }
2307
3253
  return outlet;
2308
3254
  }, []);
2309
- const resolveSlot = (0, import_react15.useCallback)(
3255
+ const resolveSlot = (0, import_react18.useCallback)(
2310
3256
  (name) => {
2311
3257
  const part = site.status === "ok" && Object.hasOwn(site.slots, name) ? site.slots[name] : void 0;
2312
3258
  if (part === void 0 || part.document.sections.length === 0) return null;
2313
3259
  let renderer = renderers.current.get(name);
2314
3260
  if (renderer === void 0) {
2315
3261
  renderer = function SlotRenderer({ context }) {
2316
- return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(BuilderSlot, { name, context });
3262
+ return /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(BuilderSlot, { name, context });
2317
3263
  };
2318
3264
  renderers.current.set(name, renderer);
2319
3265
  }
@@ -2321,30 +3267,42 @@ function BuilderProvider({ builderKey, client, packs, site, onError, children })
2321
3267
  },
2322
3268
  [site]
2323
3269
  );
2324
- const value = (0, import_react15.useMemo)(
2325
- () => ({ client: builder, packs, registry, site, locale: site.locale, mediaOrigin, onError, resolveLink }),
2326
- [builder, packs, registry, site, mediaOrigin, onError, resolveLink]
3270
+ const customCss = (0, import_react18.useMemo)(() => site.status === "ok" ? customCssOf(site.settings) : "", [site]);
3271
+ const configured = settings.routes?.page;
3272
+ const pageRoute = typeof configured === "string" ? configured : "/pages/{handle}";
3273
+ const catalogKey = catalogRoutes?.join("\n");
3274
+ const codeRoutes = (0, import_react18.useMemo)(
3275
+ () => ({ page: pageRoute, ...catalogRoutes === void 0 ? {} : { catalog: catalogRoutes } }),
3276
+ // `catalogRoutes` is compared by value: a store passes a fresh array each render.
3277
+ [pageRoute, catalogKey]
3278
+ );
3279
+ useLeaveCodeRoutes(pathname, codeRoutes);
3280
+ const leaving = mustLeave(pathname, codeRoutes);
3281
+ const value = (0, import_react18.useMemo)(
3282
+ () => ({ client: builder, packs, registry, site, locale: site.locale, mediaOrigin, onError, resolveLink, interactive, customCss, mode, pathname, codeRoutes }),
3283
+ [builder, packs, registry, site, mediaOrigin, onError, resolveLink, interactive, customCss, mode, pathname, codeRoutes]
2327
3284
  );
2328
- const design = (0, import_react15.useMemo)(
3285
+ const design = (0, import_react18.useMemo)(
2329
3286
  () => site.status === "ok" ? siteDesignOf(site.settings, resolveLink, pageOutlet, mediaOrigin) : null,
2330
3287
  [site, resolveLink, pageOutlet, mediaOrigin]
2331
3288
  );
2332
- const own = (0, import_react15.useMemo)(() => site.status === "ok" ? appearanceOf(site.settings) : void 0, [site]);
3289
+ const own = (0, import_react18.useMemo)(() => site.status === "ok" ? appearanceOf(site.settings) : void 0, [site]);
2333
3290
  const merged = (0, import_ui6.useAppearanceProviderValue)(own);
2334
3291
  const parentFont = useParentFont();
2335
- const appearance = (0, import_react15.useMemo)(() => {
3292
+ const appearance = (0, import_react18.useMemo)(() => {
2336
3293
  if (own === void 0) return void 0;
2337
3294
  return parentFont === void 0 ? merged : { ...merged, variables: { ...merged.variables, fontFamily: parentFont } };
2338
3295
  }, [own, merged, parentFont]);
2339
- return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(BuilderContext.Provider, { value, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(import_ui6.ThrottleUIProvider, { ...appearance === void 0 ? {} : { appearance }, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(import_ui6.SiteDesignProvider, { value: design, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(import_ui6.SlotOutletProvider, { resolve: resolveSlot, children: [
2340
- site.status === "ok" ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("style", { children: themeCss(site.settings) }) : null,
2341
- children
3296
+ return /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(BuilderContext.Provider, { value, children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(import_ui6.ThrottleUIProvider, { ...appearance === void 0 ? {} : { appearance }, children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(import_ui6.SiteDesignProvider, { value: design, children: /* @__PURE__ */ (0, import_jsx_runtime33.jsxs)(import_ui6.SlotOutletProvider, { resolve: resolveSlot, children: [
3297
+ site.status === "ok" ? /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("style", { children: themeCss(site.settings) }) : null,
3298
+ customCss === "" ? null : /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("style", { children: customCssSheet(customCss) }),
3299
+ leaving ? /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("div", { "data-b-leaving": "", hidden: true }) : children
2342
3300
  ] }) }) }) });
2343
3301
  }
2344
3302
 
2345
3303
  // src/parts.tsx
2346
- var import_react16 = require("react");
2347
- var import_jsx_runtime26 = require("react/jsx-runtime");
3304
+ var import_react19 = require("react");
3305
+ var import_jsx_runtime34 = require("react/jsx-runtime");
2348
3306
  function Part({ name, tag }) {
2349
3307
  const builder = useBuilder();
2350
3308
  if (builder === null || builder.site.status !== "ok") return null;
@@ -2354,11 +3312,11 @@ function Part({ name, tag }) {
2354
3312
  return (
2355
3313
  // Error boundaries do not catch on the server: the Suspense inside turns a throw
2356
3314
  // during SSR into "render nothing here" and the client retries under the boundary.
2357
- /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(PartBoundary, { label: `Builder ${name}`, children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(Tag, { "data-throttle-part": `builder-${name}`, children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(import_react16.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(PartView, { part }) }) }) })
3315
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(PartBoundary, { label: `Builder ${name}`, children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Tag, { "data-throttle-part": `builder-${name}`, children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(import_react19.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(PartView, { part }) }) }) })
2358
3316
  );
2359
3317
  }
2360
- var BuilderHeader = () => /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(Part, { name: "header", tag: "header" });
2361
- var BuilderFooter = () => /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(Part, { name: "footer", tag: "footer" });
3318
+ var BuilderHeader = () => /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Part, { name: "header", tag: "header" });
3319
+ var BuilderFooter = () => /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Part, { name: "footer", tag: "footer" });
2362
3320
 
2363
3321
  // src/index.ts
2364
3322
  var import_builder3 = require("@usethrottle/builder");