@usethrottle/builder-react 0.3.1 → 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");
@@ -82,33 +90,836 @@ var RenderBudget = class {
82
90
  this.spent += count;
83
91
  return true;
84
92
  }
85
- get used() {
86
- return this.spent;
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 };
595
+ }
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));
@@ -316,110 +1127,354 @@ function compileResponsiveCss(doc, registry, assets = doc.assets, mediaOrigin =
316
1127
  return base + (tablet === "" ? "" : `@media ${TABLET_QUERY}{${tablet}}`) + (phone === "" ? "" : `@media ${PHONE_QUERY}{${phone}}`);
317
1128
  }
318
1129
 
319
- // src/data.ts
320
- var import_builder_schema3 = require("@usethrottle/builder-schema");
321
- function stable(value) {
322
- if (Array.isArray(value)) return `[${value.map(stable).join(",")}]`;
323
- if (typeof value === "object" && value !== null) {
324
- const entries2 = Object.entries(value).filter(([, item]) => item !== void 0).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
325
- return `{${entries2.map(([k, v]) => `${JSON.stringify(k)}:${stable(v)}`).join(",")}}`;
326
- }
327
- return JSON.stringify(value) ?? "null";
328
- }
329
- function bindingKey(binding) {
330
- return "params" in binding ? `${binding.source}?${stable(binding.params)}` : binding.source;
331
- }
332
- var isContextBinding = (binding) => binding.source.startsWith("context.");
333
- function bindingsOf(node, registry) {
334
- const def = registry.widget(node.type, node.v);
335
- const out = {};
336
- for (const [name, input] of Object.entries(def?.data ?? {})) {
337
- if (input.default !== void 0) out[name] = input.default;
338
- }
339
- 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
+ )) });
340
1151
  }
341
- function collectBindings(doc, registry) {
342
- const found = /* @__PURE__ */ new Map();
343
- (0, import_builder_schema3.walkNodes)(doc, (node) => {
344
- if (node.type === "section" || node.type === "inner-section" || node.type === "column" || node.type === "saved-section") {
345
- return;
346
- }
347
- for (const binding of Object.values(bindingsOf(node, registry))) {
348
- const key = bindingKey(binding);
349
- 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
+ ]
350
1188
  }
351
- });
352
- return found;
353
- }
354
- async function resolveBindings(bindings, registry, ctx, options) {
355
- const jobs = [];
356
- for (const [key, binding] of bindings) {
357
- if (isContextBinding(binding) || !("params" in binding)) continue;
358
- const descriptor = registry.source(binding.source);
359
- const resolve = registry.resolver(binding.source);
360
- if (descriptor === void 0 || resolve === void 0) continue;
361
- if (options.include === "static" && descriptor.perShopper) continue;
362
- if (options.include === "shopper" && !descriptor.perShopper) continue;
363
- jobs.push(
364
- resolve(binding.params, ctx).then(
365
- (value) => [key, value],
366
- (error) => {
367
- warnOnce(`resolve:${binding.source}`, `Data source ${binding.source} failed (${String(error)}); its widgets render without data`);
368
- return null;
369
- }
370
- )
371
- );
372
- }
373
- const settled = await Promise.all(jobs);
374
- return Object.fromEntries(settled.filter((entry) => entry !== null));
1189
+ );
375
1190
  }
376
1191
 
377
- // src/node-wrapper.tsx
378
- var import_builder_schema4 = require("@usethrottle/builder-schema");
379
- var import_jsx_runtime = require("react/jsx-runtime");
380
- var CUSTOM_WIDGET_CONTAINMENT = {
381
- contain: "layout paint",
382
- isolation: "isolate",
383
- overflow: "clip"
384
- };
385
- var PART_NAME = {
386
- section: "builder-section",
387
- column: "builder-column",
388
- widget: "builder-widget"
389
- };
390
- function NodeWrapper(props) {
391
- const { id, part, type, className, anchor, custom, missing, edit, children } = props;
392
- const Tag = props.as ?? "div";
393
- const handlers = edit === void 0 ? {} : {
394
- onClickCapture: (event) => {
395
- const target = event.target;
396
- if (target?.closest?.("a[href]") != null) event.preventDefault();
397
- },
398
- onClick: (event) => {
399
- event.stopPropagation();
400
- edit.onSelect(id);
401
- },
402
- onMouseOver: (event) => {
403
- event.stopPropagation();
404
- edit.onHover(id);
405
- },
406
- onMouseLeave: () => edit.onHover(null)
407
- };
408
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
409
- Tag,
410
- {
411
- className,
412
- "data-b-id": id,
413
- "data-throttle-part": PART_NAME[part],
414
- ...type === void 0 ? {} : { "data-b-type": type },
415
- ...custom === true && type !== void 0 ? { "data-b-w": type } : {},
416
- ...missing === true ? { "data-b-missing": "" } : {},
417
- ...typeof anchor === "string" && import_builder_schema4.ANCHOR_RE.test(anchor) ? { id: anchor } : {},
418
- ...custom === true ? { style: CUSTOM_WIDGET_CONTAINMENT } : {},
419
- ...handlers,
420
- 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);
421
1311
  }
422
- );
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
+ ] });
423
1478
  }
424
1479
 
425
1480
  // src/styles.ts
@@ -444,9 +1499,9 @@ var BASE_CSS = `@layer throttle{
444
1499
  }`;
445
1500
 
446
1501
  // src/renderer.tsx
447
- var import_jsx_runtime2 = require("react/jsx-runtime");
1502
+ var import_jsx_runtime14 = require("react/jsx-runtime");
448
1503
  var DEVICES = ["desktop", "tablet", "phone"];
449
- 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]));
450
1505
  var withCustomCache = /* @__PURE__ */ new WeakMap();
451
1506
  function registryFor(doc, base) {
452
1507
  const snapshots = doc.customWidgets;
@@ -461,7 +1516,7 @@ function registryFor(doc, base) {
461
1516
  try {
462
1517
  registry = base.withCustom(
463
1518
  Object.values(snapshots).filter(
464
- (snapshot) => snapshot.kind !== "code"
1519
+ (snapshot) => snapshot.kind !== "code" || import_builder_schema11.codeWidgetSnapshotSchema.safeParse(snapshot).success
465
1520
  )
466
1521
  );
467
1522
  } catch (error) {
@@ -472,7 +1527,7 @@ function registryFor(doc, base) {
472
1527
  }
473
1528
  return registry;
474
1529
  }
475
- var isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
1530
+ var isRecord2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
476
1531
  function pickLocale(value, locale) {
477
1532
  const lang = locale.split("-")[0] ?? locale;
478
1533
  for (const key of [locale, lang, "en"]) {
@@ -483,25 +1538,25 @@ function pickLocale(value, locale) {
483
1538
  return "";
484
1539
  }
485
1540
  function onOrigin(asset, mediaOrigin) {
486
- if ((0, import_builder_schema5.safeUrl)(asset.url, "src", { mediaOrigin }) === null) return null;
487
- 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) };
488
1543
  }
489
1544
  function prepare(field, value, ctx) {
490
1545
  if (field === void 0 || value === null) return value;
491
- if (field.translatable === true && isRecord(value)) return pickLocale(value, ctx.locale);
1546
+ if (field.translatable === true && isRecord2(value)) return pickLocale(value, ctx.locale);
492
1547
  if (field.control === "image" && typeof value === "string") {
493
1548
  const asset = Object.hasOwn(ctx.assets, value) ? ctx.assets[value] : void 0;
494
1549
  return asset === void 0 ? null : onOrigin(asset, ctx.mediaOrigin);
495
1550
  }
496
- if (field.control === "link" && isRecord(value) && typeof value.kind === "string") {
1551
+ if (field.control === "link" && isRecord2(value) && typeof value.kind === "string") {
497
1552
  const target = value;
498
1553
  const raw = ctx.resolveLink?.(target) ?? (target.kind === "url" ? target.href : null);
499
- 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 }) };
500
1555
  }
501
1556
  return value;
502
1557
  }
503
1558
  function storedLinkPart(value) {
504
- if (!isRecord(value) || value.kind !== "page") return value;
1559
+ if (!isRecord2(value) || value.kind !== "page") return value;
505
1560
  const { slug: _slug, href: _href, ...stored } = value;
506
1561
  void _slug;
507
1562
  void _href;
@@ -510,13 +1565,13 @@ function storedLinkPart(value) {
510
1565
  function settingsAt(node, fields, device, ctx) {
511
1566
  const base = {};
512
1567
  for (const field of fields.values()) base[field.key] = field.default;
513
- 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);
514
1569
  const out = {};
515
1570
  for (const [key, value] of Object.entries(resolved)) {
516
1571
  const field = fields.get(key);
517
1572
  const freeText = field?.control === "text" || field?.control === "richtext";
518
- const checked = field?.control === "link" ? storedLinkPart(value) : value;
519
- 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;
520
1575
  out[key] = prepare(field, usable, ctx);
521
1576
  }
522
1577
  return out;
@@ -536,33 +1591,67 @@ function variantsOf(node, def, fields, ctx) {
536
1591
  }
537
1592
  function hiddenEverywhere(props, responsive) {
538
1593
  return DEVICES.every(
539
- (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
540
1595
  );
541
1596
  }
542
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
+ }
543
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);
544
1633
  const def = registry.widget(node.type, node.v);
545
1634
  const Component2 = def === void 0 ? void 0 : registry.component(node);
546
1635
  if (def === void 0 || Component2 === void 0) {
547
1636
  if (isDevelopment()) {
548
1637
  warnOnce(`missing:${node.type}@${String(node.v)}`, `Unknown widget ${node.type} v${String(node.v)}; rendering nothing for it`);
549
1638
  }
550
- 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" }) });
551
1640
  }
552
1641
  if (ctx.edit === void 0 && hiddenEverywhere(node.props, node.responsive)) return null;
553
1642
  const fields = new Map([...COMMON_BY_KEY2, ...def.settings.map((f) => [f.key, f])]);
554
1643
  const variants = variantsOf(node, def, fields, ctx);
555
1644
  const data = {};
556
1645
  for (const [name, binding] of Object.entries(bindingsOf(node, registry))) {
557
- const key = bindingKey(binding);
558
- 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;
559
1648
  if (value !== void 0) data[name] = value;
560
1649
  }
561
1650
  const custom = node.type.startsWith("custom.");
562
1651
  const edit = ctx.edit;
563
1652
  return variants.map((variant, index) => {
564
1653
  const anchor = variant.props.anchor;
565
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1654
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
566
1655
  NodeWrapper,
567
1656
  {
568
1657
  id: node.id,
@@ -571,18 +1660,22 @@ function renderWidget(node, ctx, registry) {
571
1660
  custom,
572
1661
  edit,
573
1662
  className: variants.length > 1 ? `tb-w ${variantClass(variant)}` : "tb-w",
574
- anchor: index === 0 && typeof anchor === "string" && anchor !== "" ? anchor : void 0,
575
- 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)(
576
1667
  Component2,
577
1668
  {
578
1669
  node,
579
1670
  props: variant.props,
580
1671
  data,
581
1672
  editMode: edit !== void 0,
1673
+ interactive: ctx.interactive,
1674
+ idScope: ctx.vpath === "" && !ctx.dupe ? void 0 : { vpath: ctx.vpath, dupe: ctx.dupe },
582
1675
  locale: ctx.locale,
583
1676
  mediaOrigin: ctx.mediaOrigin,
584
1677
  resolveLink: ctx.resolveLink,
585
- 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),
586
1679
  budget: custom ? new RenderBudget() : void 0
587
1680
  }
588
1681
  )
@@ -593,62 +1686,167 @@ function renderWidget(node, ctx, registry) {
593
1686
  }
594
1687
  function renderColumn(column, ctx, registry) {
595
1688
  if (ctx.edit === void 0 && hiddenEverywhere(column.props, column.responsive)) return null;
596
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1689
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
597
1690
  NodeWrapper,
598
1691
  {
599
1692
  id: column.id,
600
1693
  part: "column",
601
1694
  className: "tb-col",
602
- anchor: column.props.anchor,
1695
+ anchor: ctx.dupe ? void 0 : column.props.anchor,
1696
+ copyAnchor: ctx.vpath === "" ? void 0 : column.props.anchor,
603
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
+ ),
604
1703
  children: column.children.map(
605
- (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)
606
1705
  )
607
1706
  },
608
1707
  column.id
609
1708
  );
610
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
+ }
611
1730
  function renderSection(section, ctx, registry, nested = false) {
612
1731
  if (ctx.edit === void 0 && hiddenEverywhere(section.props, section.responsive)) return null;
613
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
614
- NodeWrapper,
615
- {
616
- id: section.id,
617
- part: "section",
618
- as: nested ? "div" : "section",
619
- className: nested ? "tb-section tb-nested" : "tb-section",
620
- anchor: section.props.anchor,
621
- edit: ctx.edit,
622
- 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() });
623
1773
  }
624
- );
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;
625
1810
  }
626
1811
  function BuilderRenderer(props) {
627
- 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;
628
1815
  const registry = registryFor(source, base);
629
- const { doc } = (0, import_builder_schema5.upgradeNodes)(source, registry);
1816
+ const { doc } = (0, import_builder_schema11.upgradeNodes)(source, registry);
630
1817
  const mediaOrigin = props.mediaOrigin ?? "";
631
- 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 };
632
1820
  const css = compileResponsiveCss(doc, registry, assets, mediaOrigin);
633
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "tb-root", "data-throttle-part": "builder-root", children: [
634
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("style", { href: "tb-base", precedence: "throttle", children: BASE_CSS }),
635
- css === "" ? null : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("style", { children: css }),
636
- doc.sections.map(
637
- (section) => section.type === "section" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react.Fragment, { children: renderSection(section, ctx, registry) }, section.id) : null
638
- )
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
+ })
639
1837
  ] });
640
1838
  }
641
1839
  function validateRender(doc) {
642
1840
  const h1 = [];
643
- (0, import_builder_schema5.walkNodes)(doc, (node) => {
1841
+ (0, import_builder_schema11.walkNodes)(doc, (node) => {
644
1842
  if (node.type === "basic.heading" && node.props.level === "h1") h1.push(node.id);
645
1843
  });
646
1844
  return h1.length > 1 ? [{ code: "MULTIPLE_H1", message: `The page has ${String(h1.length)} level 1 headings; use one`, nodeIds: h1 }] : [];
647
1845
  }
648
1846
 
649
1847
  // src/asset-image.tsx
650
- var import_builder_schema6 = require("@usethrottle/builder-schema");
651
- 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");
652
1850
  function isFrozenAsset(value) {
653
1851
  if (typeof value !== "object" || value === null) return false;
654
1852
  const v = value;
@@ -656,7 +1854,7 @@ function isFrozenAsset(value) {
656
1854
  }
657
1855
  function AssetImage(props) {
658
1856
  const { asset, alt, sizes, className, loading = "lazy", style, mediaOrigin } = props;
659
- const href = (url) => (0, import_builder_schema6.safeUrl)(url, "src", { mediaOrigin });
1857
+ const href = (url) => (0, import_builder_schema12.safeUrl)(url, "src", { mediaOrigin });
660
1858
  if (!isFrozenAsset(asset)) return null;
661
1859
  const src = href(asset.url);
662
1860
  if (src === null) return null;
@@ -664,7 +1862,7 @@ function AssetImage(props) {
664
1862
  const url = href(variant.url);
665
1863
  return url === null || url.includes(",") ? [] : [`${url} ${String(variant.width)}w`];
666
1864
  }).join(", ");
667
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1865
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
668
1866
  "img",
669
1867
  {
670
1868
  src,
@@ -680,46 +1878,36 @@ function AssetImage(props) {
680
1878
  );
681
1879
  }
682
1880
 
683
- // src/widget-style.tsx
684
- var import_jsx_runtime4 = require("react/jsx-runtime");
685
- function WidgetStyle({ css }) {
686
- if (css === "" || css.includes("<")) return null;
687
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("style", { children: css });
688
- }
689
-
690
1881
  // src/provider.tsx
691
- var import_react15 = require("react");
1882
+ var import_react18 = require("react");
692
1883
  var import_builder2 = require("@usethrottle/builder");
693
1884
  var import_ui6 = require("@usethrottle/ui");
694
1885
 
695
- // src/context.ts
696
- var import_react2 = require("react");
697
- var BuilderContext = typeof import_react2.createContext === "function" ? (0, import_react2.createContext)(null) : null;
698
- var useBuilder = () => (0, import_react2.useContext)(BuilderContext);
699
-
700
1886
  // src/page.tsx
701
- var import_react4 = require("react");
1887
+ var import_react10 = require("react");
702
1888
  var import_builder = require("@usethrottle/builder");
703
1889
 
704
1890
  // src/load.ts
705
1891
  function pageOf(raw, initialData) {
706
- 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;
707
1893
  return {
708
1894
  kind: "page",
709
1895
  slug,
710
1896
  title,
711
1897
  path,
712
1898
  generation,
713
- document,
714
- assets: document.assets ?? {},
1899
+ document: document2,
1900
+ assets: document2.assets ?? {},
715
1901
  initialData,
716
- meta
1902
+ meta,
1903
+ ...savedSections === void 0 ? {} : { savedSections },
1904
+ ...code === void 0 ? {} : { code }
717
1905
  };
718
1906
  }
719
1907
  var isRedirect = (raw) => typeof raw.redirectTo === "string";
720
1908
 
721
1909
  // src/safe-path.ts
722
- var import_builder_schema7 = require("@usethrottle/builder-schema");
1910
+ var import_builder_schema13 = require("@usethrottle/builder-schema");
723
1911
  var UNSAFE = /[\x00-\x20\x7f-\xa0\\\u1680\u2000-\u200f\u2028\u2029\u202f\u205f\u3000\ufeff]/;
724
1912
  var LEADING = /^\/(?![/\\])/;
725
1913
  function plainPath(path) {
@@ -727,51 +1915,31 @@ function plainPath(path) {
727
1915
  }
728
1916
  function sitePath(to) {
729
1917
  if (typeof to !== "string" || !plainPath(to)) return null;
730
- let decoded;
1918
+ let decoded2;
731
1919
  try {
732
- decoded = decodeURIComponent(to);
1920
+ decoded2 = decodeURIComponent(to);
733
1921
  } catch {
734
1922
  return null;
735
1923
  }
736
- if (!plainPath(decoded)) return null;
737
- return (0, import_builder_schema7.safeUrl)(to, "href", { mediaOrigin: "" });
738
- }
739
-
740
- // src/shopper-data.ts
741
- var import_react3 = require("react");
742
- function useResolvedData(document, registry, locale, include, context) {
743
- const [data, setData] = (0, import_react3.useState)({});
744
- (0, import_react3.useEffect)(() => {
745
- const controller = new AbortController();
746
- const bindings = collectBindings(document, registry);
747
- if (bindings.size === 0) return void 0;
748
- void resolveBindings(
749
- bindings,
750
- registry,
751
- { locale, preview: false, context, signal: controller.signal },
752
- { include }
753
- ).then((resolved) => {
754
- if (!controller.signal.aborted && Object.keys(resolved).length > 0) setData(resolved);
755
- });
756
- return () => controller.abort();
757
- }, [document, registry, locale, include, context]);
758
- return data;
1924
+ if (!plainPath(decoded2)) return null;
1925
+ return (0, import_builder_schema13.safeUrl)(to, "href", { mediaOrigin: "" });
759
1926
  }
760
1927
 
761
1928
  // src/page.tsx
762
- var import_jsx_runtime5 = require("react/jsx-runtime");
1929
+ var import_jsx_runtime16 = require("react/jsx-runtime");
763
1930
  function BuilderPageView({ page, resolve = "shopper" }) {
764
1931
  const builder = useBuilder();
765
1932
  if (builder === null) throw new Error("A Builder page needs a BuilderProvider above it");
766
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(PageBody, { page, resolve, builder });
1933
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(PageBody, { page, resolve, builder });
767
1934
  }
768
1935
  function PageBody({
769
1936
  page,
770
1937
  resolve,
771
1938
  builder
772
1939
  }) {
773
- const resolved = useResolvedData(page.document, builder.registry, builder.locale, resolve);
774
- 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)(
775
1943
  BuilderRenderer,
776
1944
  {
777
1945
  document: page.document,
@@ -780,7 +1948,11 @@ function PageBody({
780
1948
  locale: builder.locale,
781
1949
  assets: page.assets,
782
1950
  mediaOrigin: builder.mediaOrigin,
783
- 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)
784
1956
  }
785
1957
  );
786
1958
  }
@@ -819,7 +1991,7 @@ function read(client, slug, locale) {
819
1991
  function BuilderPage({ slug, initial }) {
820
1992
  const builder = useBuilder();
821
1993
  if (builder === null) throw new Error("BuilderPage needs a BuilderProvider above it");
822
- 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 });
823
1995
  if (builder.site.status === "unavailable") {
824
1996
  throw new import_builder.BuilderUnavailableError("network", "The Builder is unavailable and has no last good answer");
825
1997
  }
@@ -827,95 +1999,30 @@ function BuilderPage({ slug, initial }) {
827
1999
  throw new Error("BuilderPage reads the page itself: give BuilderProvider a builderKey or a client, or pass `initial`");
828
2000
  }
829
2001
  const found = read(builder.client, slug, builder.locale);
830
- if ("redirectTo" in found) return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Redirect, { to: found.redirectTo });
831
- 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" });
832
2004
  }
833
2005
  function Redirect({ to }) {
834
- (0, import_react4.useEffect)(() => {
2006
+ (0, import_react10.useEffect)(() => {
835
2007
  const path = sitePath(to);
836
2008
  if (path !== null) window.location.replace(path);
837
2009
  }, [to]);
838
2010
  return null;
839
2011
  }
840
2012
 
841
- // src/part-view.tsx
842
- var import_react5 = require("react");
843
- var import_jsx_runtime6 = require("react/jsx-runtime");
844
- var BoundaryBase = import_react5.Component ?? class {
845
- };
846
- var Boundary = class extends BoundaryBase {
847
- constructor() {
848
- super(...arguments);
849
- __publicField(this, "state", { failed: false });
850
- }
851
- static getDerivedStateFromError() {
852
- return { failed: true };
853
- }
854
- componentDidCatch(error, _info) {
855
- warnOnce(`part:${this.props.label}`, `${this.props.label} failed to render (${String(error)}); rendering nothing for it`);
856
- try {
857
- this.props.onError?.(error, { part: this.props.label });
858
- } catch {
859
- }
860
- }
861
- componentDidUpdate(previous) {
862
- const moved = previous.resetKeys.length !== this.props.resetKeys.length || previous.resetKeys.some((key, i) => !Object.is(key, this.props.resetKeys[i]));
863
- if (moved && this.state.failed) this.setState({ failed: false });
864
- }
865
- render() {
866
- return this.state.failed ? null : this.props.children;
867
- }
868
- };
869
- function PartBoundary({
870
- label,
871
- resetKey,
872
- children
873
- }) {
874
- const builder = useBuilder();
875
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Boundary, { label, resetKeys: [builder?.site, resetKey], onError: builder?.onError, children });
876
- }
877
- function contextData(context) {
878
- if (typeof context !== "object" || context === null) return {};
879
- return Object.fromEntries(Object.entries(context).map(([key, value]) => [`context.${key}`, value]));
880
- }
881
- function PartView({ part, context }) {
882
- const builder = useBuilder();
883
- if (builder === null) return null;
884
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(PartBody, { part, context, builder });
885
- }
886
- function PartBody({
887
- part,
888
- context,
889
- builder
890
- }) {
891
- const shopper = useResolvedData(part.document, builder.registry, builder.locale, "shopper", context);
892
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
893
- BuilderRenderer,
894
- {
895
- document: part.document,
896
- registry: builder.registry,
897
- data: { ...part.initialData, ...contextData(context), ...shopper },
898
- locale: builder.locale,
899
- assets: part.assets,
900
- mediaOrigin: builder.mediaOrigin,
901
- resolveLink: builder.resolveLink
902
- }
903
- );
904
- }
905
-
906
2013
  // src/registry.ts
907
- var import_builder_schema20 = require("@usethrottle/builder-schema");
2014
+ var import_builder_schema23 = require("@usethrottle/builder-schema");
908
2015
 
909
2016
  // src/basics/index.ts
910
- var import_builder_schema15 = require("@usethrottle/builder-schema");
2017
+ var import_builder_schema21 = require("@usethrottle/builder-schema");
911
2018
 
912
2019
  // src/basics/announcement.tsx
913
- var import_react6 = require("react");
2020
+ var import_react11 = require("react");
914
2021
  var import_ui = require("@usethrottle/ui");
915
- var import_builder_schema9 = require("@usethrottle/builder-schema");
2022
+ var import_builder_schema15 = require("@usethrottle/builder-schema");
916
2023
 
917
2024
  // src/basics/util.tsx
918
- var import_builder_schema8 = require("@usethrottle/builder-schema");
2025
+ var import_builder_schema14 = require("@usethrottle/builder-schema");
919
2026
 
920
2027
  // src/basics/styles.ts
921
2028
  var BASICS_CSS = `@layer throttle{
@@ -980,26 +2087,26 @@ var BASICS_CSS = `@layer throttle{
980
2087
  }`;
981
2088
 
982
2089
  // src/basics/util.tsx
983
- var import_jsx_runtime7 = require("react/jsx-runtime");
2090
+ var import_jsx_runtime17 = require("react/jsx-runtime");
984
2091
  function BasicStyles() {
985
- 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 });
986
2093
  }
987
- var isRecord2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
2094
+ var isRecord3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
988
2095
  var str = (v) => typeof v === "string" && v !== "" ? v : void 0;
989
2096
  function oneOf(value, allowed, fallback) {
990
2097
  return allowed.find((candidate) => candidate === value) ?? fallback;
991
2098
  }
992
2099
  function hrefOf(link, mediaOrigin) {
993
- if (!isRecord2(link)) return null;
994
- 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 });
995
2102
  }
996
2103
  function Placeholder({ editMode, children }) {
997
- 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;
998
2105
  }
999
- var ID_RE2 = /^[a-z0-9]{8,24}$/;
2106
+ var ID_RE2 = /^[a-z0-9]{8,24}(-[a-z0-9]{8,24})?$/;
1000
2107
  var DEVICES2 = ["desktop", "tablet", "phone"];
1001
2108
  function defaultOf(type, key) {
1002
- 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);
1003
2110
  return def?.settings.find((f) => f.key === key)?.default ?? null;
1004
2111
  }
1005
2112
  function enumCss(node, rules) {
@@ -1007,7 +2114,7 @@ function enumCss(node, rules) {
1007
2114
  const per = { desktop: /* @__PURE__ */ new Map(), tablet: /* @__PURE__ */ new Map(), phone: /* @__PURE__ */ new Map() };
1008
2115
  for (const device of DEVICES2) {
1009
2116
  const settings = { ...Object.fromEntries(rules.map((r) => [r.key, defaultOf(node.type, r.key)])), ...node.props };
1010
- const resolved = (0, import_builder_schema8.resolveResponsive)(settings, node.responsive, device);
2117
+ const resolved = (0, import_builder_schema14.resolveResponsive)(settings, node.responsive, device);
1011
2118
  for (const rule of rules) {
1012
2119
  const value = resolved[rule.key];
1013
2120
  const fallback = defaultOf(node.type, rule.key);
@@ -1024,7 +2131,7 @@ function enumCss(node, rules) {
1024
2131
  }
1025
2132
 
1026
2133
  // src/basics/announcement.tsx
1027
- var import_jsx_runtime8 = require("react/jsx-runtime");
2134
+ var import_jsx_runtime18 = require("react/jsx-runtime");
1028
2135
  var KEY = "tb-announcement-dismissed";
1029
2136
  function read2(message) {
1030
2137
  try {
@@ -1042,25 +2149,25 @@ function write(message) {
1042
2149
  function Announcement({ props, mediaOrigin, editMode }) {
1043
2150
  const design = (0, import_ui.useSiteDesign)();
1044
2151
  const message = design?.announcement?.message;
1045
- const [dismissed, setDismissed] = (0, import_react6.useState)(false);
1046
- (0, import_react6.useEffect)(() => {
2152
+ const [dismissed, setDismissed] = (0, import_react11.useState)(false);
2153
+ (0, import_react11.useEffect)(() => {
1047
2154
  if (message !== void 0 && read2(message)) setDismissed(true);
1048
2155
  }, [message]);
1049
2156
  if (message === void 0) {
1050
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
1051
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(BasicStyles, {}),
1052
- /* @__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" })
1053
2160
  ] });
1054
2161
  }
1055
2162
  if (dismissed && !editMode) return null;
1056
- 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 });
1057
2164
  const strings = design?.strings;
1058
- const dismissLabel = (strings !== void 0 && Object.hasOwn(strings, "announcement.dismiss") ? str(strings["announcement.dismiss"]) : void 0) ?? import_builder_schema9.SITE_STRING_DEFAULTS["announcement.dismiss"];
1059
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
1060
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(BasicStyles, {}),
1061
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "tb-b-announcement", role: "region", "aria-label": message, children: [
1062
- /* @__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 }) }),
1063
- 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)(
1064
2171
  "button",
1065
2172
  {
1066
2173
  type: "button",
@@ -1069,7 +2176,7 @@ function Announcement({ props, mediaOrigin, editMode }) {
1069
2176
  write(message);
1070
2177
  setDismissed(true);
1071
2178
  },
1072
- 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 })
1073
2180
  }
1074
2181
  )
1075
2182
  ] })
@@ -1077,59 +2184,125 @@ function Announcement({ props, mediaOrigin, editMode }) {
1077
2184
  }
1078
2185
 
1079
2186
  // src/basics/button.tsx
1080
- var import_jsx_runtime9 = require("react/jsx-runtime");
2187
+ var import_jsx_runtime19 = require("react/jsx-runtime");
1081
2188
  var STYLES = ["primary", "secondary", "outline", "link"];
1082
2189
  var SIZES = ["s", "m", "l"];
1083
2190
  function Button({ props, mediaOrigin, inlineEdit }) {
1084
2191
  const href = hrefOf(props.link, mediaOrigin);
1085
2192
  const className = `tb-b-button tb-b-button--${oneOf(props.style, STYLES, "primary")} tb-b-button--${oneOf(props.size, SIZES, "m")}`;
1086
2193
  const label = inlineEdit?.("label") ?? str(props.label) ?? "";
1087
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
1088
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(BasicStyles, {}),
1089
- /* @__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 }) })
1090
2197
  ] });
1091
2198
  }
1092
2199
 
1093
2200
  // src/basics/copyright.tsx
1094
2201
  var import_ui2 = require("@usethrottle/ui");
1095
- var import_builder_schema10 = require("@usethrottle/builder-schema");
1096
- 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");
1097
2204
  function Copyright(_) {
1098
2205
  const design = (0, import_ui2.useSiteDesign)();
1099
2206
  const strings = design?.strings;
1100
2207
  const template = strings !== void 0 && Object.hasOwn(strings, "footer.copyright") ? str(strings["footer.copyright"]) : void 0;
1101
- 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");
1102
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
1103
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(BasicStyles, {}),
1104
- /* @__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
+ )
1105
2278
  ] });
1106
2279
  }
1107
2280
 
1108
2281
  // src/basics/divider.tsx
1109
- var import_jsx_runtime11 = require("react/jsx-runtime");
2282
+ var import_jsx_runtime22 = require("react/jsx-runtime");
1110
2283
  var RULES = [{ key: "style", property: "--bx-style", values: { solid: "solid", dashed: "dashed", dotted: "dotted" } }];
1111
2284
  function Divider({ node }) {
1112
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [
1113
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(BasicStyles, {}),
1114
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(WidgetStyle, { css: enumCss(node, RULES) }),
1115
- /* @__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" })
1116
2289
  ] });
1117
2290
  }
1118
2291
 
1119
2292
  // src/basics/heading.tsx
1120
- var import_jsx_runtime12 = require("react/jsx-runtime");
2293
+ var import_jsx_runtime23 = require("react/jsx-runtime");
1121
2294
  var LEVELS = ["h1", "h2", "h3", "h4", "h5", "h6"];
1122
2295
  function Heading({ props, inlineEdit }) {
1123
2296
  const Tag = oneOf(props.level, LEVELS, "h2");
1124
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [
1125
- /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(BasicStyles, {}),
1126
- /* @__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) ?? "" })
1127
2300
  ] });
1128
2301
  }
1129
2302
 
1130
2303
  // src/basics/image.tsx
1131
- var import_builder_schema11 = require("@usethrottle/builder-schema");
1132
- 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");
1133
2306
  var RULES2 = [
1134
2307
  { key: "radius", property: "--bx-radius", values: { none: "0", s: "4px", m: "8px", l: "16px", full: "9999px" } },
1135
2308
  { key: "fit", property: "--bx-fit", values: { cover: "cover", contain: "contain" } }
@@ -1139,23 +2312,23 @@ function Image({ node, props, mediaOrigin, editMode }) {
1139
2312
  const decorative = props.decorative === true;
1140
2313
  const alt = decorative ? "" : typeof props.alt === "string" ? props.alt : "";
1141
2314
  const asset = isFrozenAsset(props.image) ? props.image : void 0;
1142
- const image = /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(AssetImage, { asset, mediaOrigin, alt, className: "tb-b-img", sizes: "(max-width: 767px) 100vw, 50vw" });
1143
- const shown = asset !== void 0 && (0, import_builder_schema11.safeUrl)(asset.url, "src", { mediaOrigin }) !== null;
1144
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
1145
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(BasicStyles, {}),
1146
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(WidgetStyle, { css: enumCss(node, RULES2) }),
1147
- 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" })
1148
2321
  ] });
1149
2322
  }
1150
2323
 
1151
2324
  // src/basics/logo.tsx
1152
2325
  var import_ui3 = require("@usethrottle/ui");
1153
- var import_builder_schema12 = require("@usethrottle/builder-schema");
1154
- 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");
1155
2328
  function Logo({ props, mediaOrigin, editMode }) {
1156
2329
  const design = (0, import_ui3.useSiteDesign)();
1157
2330
  const scheme = design?.theme?.colorScheme ?? "auto";
1158
- 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;
1159
2332
  const light = src(design?.brand?.logo?.light);
1160
2333
  const dark = src(design?.brand?.logo?.dark);
1161
2334
  const main = scheme === "dark" ? dark ?? light : light ?? dark;
@@ -1164,53 +2337,53 @@ function Logo({ props, mediaOrigin, editMode }) {
1164
2337
  const alt = name ?? "";
1165
2338
  let content = null;
1166
2339
  if (main !== void 0) {
1167
- const img = /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("img", { src: main, alt, decoding: "async" });
1168
- content = scheme === "auto" && light !== void 0 && dark !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("picture", { children: [
1169
- /* @__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 }),
1170
2343
  img
1171
2344
  ] }) : img;
1172
2345
  } else if (name !== void 0) {
1173
- 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 });
1174
2347
  }
1175
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
1176
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(BasicStyles, {}),
1177
- 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 }) })
1178
2351
  ] });
1179
2352
  }
1180
2353
 
1181
2354
  // src/basics/menu.tsx
1182
- var import_react7 = require("react");
2355
+ var import_react12 = require("react");
1183
2356
  var import_ui4 = require("@usethrottle/ui");
1184
- var import_builder_schema13 = require("@usethrottle/builder-schema");
1185
- 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");
1186
2359
  var LAYOUTS = ["horizontal", "vertical", "drawer-on-phone"];
1187
- var MAX_DEPTH = 3;
2360
+ var MAX_DEPTH2 = 3;
1188
2361
  function List({ items, mediaOrigin, depth = 0, id, onNavigate }) {
1189
- const shown = items.flatMap((item) => {
1190
- 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 });
1191
2364
  return href === null ? [] : [{ item, href }];
1192
2365
  });
1193
- if (shown.length === 0) return null;
1194
- 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: [
1195
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("a", { href, children: item.label }),
1196
- 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 })
1197
2370
  ] }, `${String(index)}:${href}`)) });
1198
2371
  }
1199
2372
  function Menu({ props, mediaOrigin, editMode }) {
1200
2373
  const design = (0, import_ui4.useSiteDesign)();
1201
- const listId = (0, import_react7.useId)();
1202
- const toggle = (0, import_react7.useRef)(null);
1203
- 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);
1204
2377
  const name = str(props.menu) ?? "header";
1205
2378
  const layout = oneOf(props.layout, LAYOUTS, "horizontal");
1206
2379
  const menus = design?.menus;
1207
2380
  const items = menus !== void 0 && Object.hasOwn(menus, name) ? menus[name] : void 0;
1208
2381
  const strings = design?.strings;
1209
- 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"];
1210
2383
  if (items === void 0 || items.length === 0) {
1211
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_jsx_runtime15.Fragment, { children: [
1212
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(BasicStyles, {}),
1213
- /* @__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` })
1214
2387
  ] });
1215
2388
  }
1216
2389
  const drawer = layout === "drawer-on-phone";
@@ -1220,9 +2393,9 @@ function Menu({ props, mediaOrigin, editMode }) {
1220
2393
  toggle.current?.focus();
1221
2394
  }
1222
2395
  };
1223
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_jsx_runtime15.Fragment, { children: [
1224
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(BasicStyles, {}),
1225
- /* @__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)(
1226
2399
  "nav",
1227
2400
  {
1228
2401
  className: `tb-b-menu tb-b-menu--${layout}${layout === "vertical" ? "" : " tb-b-menu--h"}`,
@@ -1230,7 +2403,7 @@ function Menu({ props, mediaOrigin, editMode }) {
1230
2403
  "data-open": drawer ? String(open) : void 0,
1231
2404
  onKeyDown: drawer ? onKeyDown : void 0,
1232
2405
  children: [
1233
- drawer && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
2406
+ drawer && /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
1234
2407
  "button",
1235
2408
  {
1236
2409
  ref: toggle,
@@ -1239,10 +2412,10 @@ function Menu({ props, mediaOrigin, editMode }) {
1239
2412
  "aria-expanded": open,
1240
2413
  "aria-controls": listId,
1241
2414
  onClick: () => setOpen((value) => !value),
1242
- 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 })
1243
2416
  }
1244
2417
  ),
1245
- /* @__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) } : {} })
1246
2419
  ]
1247
2420
  }
1248
2421
  )
@@ -1250,18 +2423,18 @@ function Menu({ props, mediaOrigin, editMode }) {
1250
2423
  }
1251
2424
 
1252
2425
  // src/basics/spacer.tsx
1253
- var import_jsx_runtime16 = require("react/jsx-runtime");
2426
+ var import_jsx_runtime27 = require("react/jsx-runtime");
1254
2427
  function Spacer() {
1255
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_jsx_runtime16.Fragment, { children: [
1256
- /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(BasicStyles, {}),
1257
- /* @__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" })
1258
2431
  ] });
1259
2432
  }
1260
2433
 
1261
2434
  // src/basics/rich-text.tsx
1262
- var import_react8 = require("react");
1263
- var import_builder_schema14 = require("@usethrottle/builder-schema");
1264
- 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");
1265
2438
  var ALLOWED = /* @__PURE__ */ new Set(["p", "br", "strong", "em", "u", "s", "a", "ul", "ol", "li", "h2", "h3", "h4", "blockquote", "code"]);
1266
2439
  var ALIAS = { b: "strong", i: "em", strike: "s", del: "s" };
1267
2440
  var DROP_WITH_CONTENT = /* @__PURE__ */ new Set([
@@ -1286,7 +2459,7 @@ var VOID = /* @__PURE__ */ new Set(["br"]);
1286
2459
  var BLOCK = /* @__PURE__ */ new Set(["p", "h2", "h3", "h4", "ul", "ol", "blockquote"]);
1287
2460
  var TEXT_BLOCK = /* @__PURE__ */ new Set(["p", "h2", "h3", "h4"]);
1288
2461
  var MAX_LENGTH = 2e4;
1289
- var MAX_DEPTH2 = 24;
2462
+ var MAX_DEPTH3 = 24;
1290
2463
  var MAX_NODES = 4e3;
1291
2464
  var NAMED = {
1292
2465
  amp: "&",
@@ -1430,23 +2603,23 @@ function parseRichText(source, mediaOrigin) {
1430
2603
  const el = { tag: name, children: [] };
1431
2604
  if (name === "a") {
1432
2605
  const href = tag.attrs.get("href");
1433
- 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 });
1434
2607
  }
1435
2608
  nodes += 1;
1436
2609
  top().children.push(el);
1437
- if (!VOID.has(name) && stack.length < MAX_DEPTH2) stack.push(el);
2610
+ if (!VOID.has(name) && stack.length < MAX_DEPTH3) stack.push(el);
1438
2611
  }
1439
2612
  if (nodes > MAX_NODES) root.truncated = true;
1440
2613
  return root;
1441
2614
  }
1442
2615
  function toReact(el, key) {
1443
2616
  const children = el.children.map((child, index) => typeof child === "string" ? child : toReact(child, index));
1444
- 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);
1445
2618
  if (el.tag === "a") {
1446
- if (el.href === null || el.href === void 0) return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_react8.Fragment, { children }, key);
1447
- 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);
1448
2621
  }
1449
- return (0, import_react8.createElement)(el.tag, { key }, ...children);
2622
+ return (0, import_react13.createElement)(el.tag, { key }, ...children);
1450
2623
  }
1451
2624
  function RichText({
1452
2625
  html,
@@ -1455,26 +2628,26 @@ function RichText({
1455
2628
  editMode = false
1456
2629
  }) {
1457
2630
  const tree = parseRichText(html, mediaOrigin);
1458
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className, children: [
2631
+ return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("div", { className, children: [
1459
2632
  tree.children.map((child, index) => typeof child === "string" ? child : toReact(child, index)),
1460
- 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." })
1461
2634
  ] });
1462
2635
  }
1463
2636
 
1464
2637
  // src/basics/text.tsx
1465
- var import_jsx_runtime18 = require("react/jsx-runtime");
2638
+ var import_jsx_runtime29 = require("react/jsx-runtime");
1466
2639
  function Text({ props, mediaOrigin, editMode, inlineEdit }) {
1467
2640
  const editor = inlineEdit?.("html") ?? null;
1468
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_jsx_runtime18.Fragment, { children: [
1469
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(BasicStyles, {}),
1470
- 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 })
1471
2644
  ] });
1472
2645
  }
1473
2646
 
1474
2647
  // src/basics/video.tsx
1475
- var import_react9 = require("react");
2648
+ var import_react14 = require("react");
1476
2649
  var import_ui5 = require("@usethrottle/ui");
1477
- var import_jsx_runtime19 = require("react/jsx-runtime");
2650
+ var import_jsx_runtime30 = require("react/jsx-runtime");
1478
2651
  var RULES3 = [
1479
2652
  { key: "ratio", property: "--bx-ratio", values: { "16:9": "16 / 9", "4:3": "4 / 3", "1:1": "1 / 1", "9:16": "9 / 16" } }
1480
2653
  ];
@@ -1514,12 +2687,12 @@ function embedSrc(video, muted) {
1514
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" : ""}`;
1515
2688
  }
1516
2689
  function Video({ node, props, editMode }) {
1517
- const [loaded, setLoaded] = (0, import_react9.useState)(false);
2690
+ const [loaded, setLoaded] = (0, import_react14.useState)(false);
1518
2691
  const video = parseVideoUrl(str(props.url) ?? "");
1519
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_jsx_runtime19.Fragment, { children: [
1520
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(BasicStyles, {}),
1521
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(WidgetStyle, { css: enumCss(node, RULES3) }),
1522
- 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)(
1523
2696
  "iframe",
1524
2697
  {
1525
2698
  src: embedSrc(video, props.autoplayMuted === true),
@@ -1528,7 +2701,7 @@ function Video({ node, props, editMode }) {
1528
2701
  referrerPolicy: "strict-origin-when-cross-origin",
1529
2702
  sandbox: "allow-scripts allow-same-origin allow-presentation allow-popups"
1530
2703
  }
1531
- ) : /* @__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 }) }) }) })
1532
2705
  ] });
1533
2706
  }
1534
2707
 
@@ -1544,289 +2717,39 @@ var BASIC_COMPONENTS = {
1544
2717
  "basic.logo": Logo,
1545
2718
  "basic.menu": Menu,
1546
2719
  "basic.announcement": Announcement,
1547
- "basic.copyright": Copyright
2720
+ "basic.copyright": Copyright,
2721
+ "basic.countdown": Countdown
1548
2722
  };
1549
- var widgets = import_builder_schema15.BASIC_WIDGET_DEFINITIONS.flatMap(
2723
+ var widgets = import_builder_schema21.BASIC_WIDGET_DEFINITIONS.flatMap(
1550
2724
  (definition) => Object.hasOwn(BASIC_COMPONENTS, definition.type) ? [{ ...definition, Component: BASIC_COMPONENTS[definition.type] }] : []
1551
2725
  );
1552
2726
  var basicPack = { id: "basic", version: "0.0.0", widgets, dataSources: [] };
1553
2727
 
1554
2728
  // src/custom/factory.ts
1555
- var import_react13 = require("react");
1556
-
1557
- // src/custom/composite-widget.tsx
1558
- var import_react12 = require("react");
1559
- var import_builder_schema19 = require("@usethrottle/builder-schema");
1560
-
1561
- // src/custom/template-widget.tsx
1562
- var import_react11 = require("react");
1563
- var import_builder_schema18 = require("@usethrottle/builder-schema");
1564
-
1565
- // src/custom/custom-css.tsx
1566
- var import_builder_schema16 = require("@usethrottle/builder-schema");
1567
- var import_jsx_runtime20 = require("react/jsx-runtime");
1568
- function scopedCss(source, type) {
1569
- if (source === void 0 || source === "") return "";
1570
- if (typeof source !== "string") return null;
1571
- const result = (0, import_builder_schema16.sanitizeWidgetCss)(source, type);
1572
- return result.ok ? result.css : null;
1573
- }
1574
- function CustomCss({ css }) {
1575
- return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(WidgetStyle, { css });
1576
- }
1577
-
1578
- // src/custom/interpreter.tsx
1579
- var import_react10 = require("react");
1580
- var import_builder_schema17 = require("@usethrottle/builder-schema");
1581
- var import_jsx_runtime21 = require("react/jsx-runtime");
1582
- var MAX_OUTPUT_CHARS = 1e6;
1583
- var MAX_ATTR_CHARS = 2e3;
1584
- var MAX_DEPTH3 = 24;
1585
- function newEnv(env) {
1586
- return { ...env, charsLeft: MAX_OUTPUT_CHARS, stopped: false };
1587
- }
1588
- var BLOCKED = /* @__PURE__ */ new Set([
1589
- "__proto__",
1590
- "constructor",
1591
- "prototype",
1592
- ...Object.getOwnPropertyNames(Object.prototype)
1593
- ]);
1594
- var isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
1595
- function step(value, key) {
1596
- if (BLOCKED.has(key) || !isPlainObject(value) || !Object.hasOwn(value, key)) return void 0;
1597
- return value[key];
1598
- }
1599
- function lookup(path, env, scope) {
1600
- const [root, ...rest] = path;
1601
- if (root === void 0) return void 0;
1602
- if (root === "locale") return rest.length === 0 ? env.locale : void 0;
1603
- let value;
1604
- if (root === "settings") value = rest.length === 0 ? void 0 : env.settings;
1605
- else if (root === "data") value = rest.length === 0 ? void 0 : env.data;
1606
- else if (scope.has(root)) value = scope.get(root);
1607
- else return void 0;
1608
- for (const key of rest) {
1609
- value = step(value, key);
1610
- if (value === void 0) return void 0;
1611
- }
1612
- return value;
1613
- }
1614
- function truthy(value) {
1615
- if (value === null || value === void 0 || value === false || value === "") return false;
1616
- if (typeof value === "number") return value !== 0 && !Number.isNaN(value);
1617
- if (Array.isArray(value)) return value.length > 0;
1618
- return true;
1619
- }
1620
- function asText(value) {
1621
- if (typeof value === "string") return value;
1622
- if (typeof value === "number" && Number.isFinite(value)) return String(value);
1623
- return "";
1624
- }
1625
- function filtered(value, filters) {
1626
- let text = asText(value);
1627
- for (const filter of filters) {
1628
- switch (filter.name) {
1629
- case "upper":
1630
- text = text.toUpperCase();
1631
- break;
1632
- case "lower":
1633
- text = text.toLowerCase();
1634
- break;
1635
- case "truncate": {
1636
- const chars = Array.from(text);
1637
- if (chars.length > filter.n) text = `${chars.slice(0, filter.n).join("")}\u2026`;
1638
- break;
1639
- }
1640
- case "default":
1641
- if (text === "") text = filter.text;
1642
- break;
1643
- }
1644
- }
1645
- return text;
1646
- }
1647
- function spend(env, count) {
1648
- if (count > env.charsLeft) {
1649
- env.stopped = true;
1650
- return false;
1651
- }
1652
- env.charsLeft -= count;
1653
- return true;
1654
- }
1655
- var ELEMENTS = new Set(import_builder_schema17.ALLOWED_ELEMENTS);
1656
- var VOIDS = new Set(import_builder_schema17.VOID_ELEMENTS);
1657
- var ROLES = new Set(import_builder_schema17.ALLOWED_ROLES);
1658
- function attrAllowed(tag, name) {
1659
- if (import_builder_schema17.DATA_ATTR_RE.test(name)) return !name.startsWith(import_builder_schema17.RESERVED_DATA_PREFIX);
1660
- const own = Object.hasOwn(import_builder_schema17.ALLOWED_ATTRS, tag) ? import_builder_schema17.ALLOWED_ATTRS[tag] : void 0;
1661
- return (import_builder_schema17.ALLOWED_ATTRS["*"]?.includes(name) ?? false) || (own?.includes(name) ?? false);
1662
- }
1663
- function attrText(attr, env, scope) {
1664
- return attr.value.map((part) => part.type === "text" ? part.value : filtered(lookup(part.path, env, scope), part.filters)).join("");
1665
- }
1666
- function urlSource(attr, env, scope) {
1667
- const [only] = attr.value;
1668
- if (attr.value.length !== 1 || only === void 0 || only.type !== "output") return attrText(attr, env, scope);
1669
- const value = lookup(only.path, env, scope);
1670
- if (isPlainObject(value)) {
1671
- if (typeof value.href === "string") return value.href;
1672
- if (typeof value.url === "string") return value.url;
1673
- return null;
1674
- }
1675
- return value;
1676
- }
1677
- function attrProp(tag, attr, env, scope) {
1678
- const { name } = attr;
1679
- if (!attrAllowed(tag, name)) return null;
1680
- if (name === "href" || name === "src") {
1681
- const safe = (0, import_builder_schema17.safeUrl)(urlSource(attr, env, scope), name, { mediaOrigin: env.mediaOrigin });
1682
- return safe === null || !spend(env, safe.length) ? null : [name, safe];
1683
- }
1684
- const text = attrText(attr, env, scope);
1685
- if (text === "" || text.length > MAX_ATTR_CHARS) return null;
1686
- let value = text;
1687
- if (name === "class") {
1688
- const tokens = text.split(/\s+/).filter((token) => import_builder_schema17.CLASS_TOKEN_RE.test(token) && !(0, import_builder_schema17.isReservedClass)(token));
1689
- if (tokens.length === 0) return null;
1690
- value = tokens.join(" ");
1691
- } else if (name === "role") {
1692
- if (!ROLES.has(text)) return null;
1693
- } else if (name === "aria-hidden") {
1694
- if (text !== "true" && text !== "false") return null;
1695
- }
1696
- if (!spend(env, value.length)) return null;
1697
- return [name === "class" ? "className" : name, value];
1698
- }
1699
- function renderElement(node, env, scope, depth, key) {
1700
- const tag = node.tag;
1701
- if (!ELEMENTS.has(tag)) return null;
1702
- const props = { key };
1703
- for (const attr of node.attrs) {
1704
- const prop = attrProp(tag, attr, env, scope);
1705
- if (prop !== null) props[prop[0]] = prop[1];
1706
- }
1707
- if (VOIDS.has(tag)) return (0, import_react10.createElement)(tag, props);
1708
- return (0, import_react10.createElement)(tag, props, renderNodes(node.children, env, scope, depth + 1));
1709
- }
1710
- function renderNodes(nodes, env, scope, depth) {
1711
- const out = [];
1712
- if (depth > MAX_DEPTH3) return out;
1713
- for (const node of nodes) {
1714
- if (env.stopped) break;
1715
- if (!env.budget.take(1) || node.type === "element" && !env.budget.take(node.attrs.reduce((n, a) => n + a.value.length, 0))) {
1716
- env.stopped = true;
1717
- break;
1718
- }
1719
- switch (node.type) {
1720
- case "text":
1721
- if (spend(env, node.value.length)) out.push(node.value);
1722
- break;
1723
- case "output": {
1724
- const text = filtered(lookup(node.path, env, scope), node.filters);
1725
- if (text !== "" && spend(env, text.length)) out.push(text);
1726
- break;
1727
- }
1728
- case "if": {
1729
- const branch = truthy(lookup(node.path, env, scope)) ? node.then : node.else;
1730
- out.push(/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_react10.Fragment, { children: renderNodes(branch, env, scope, depth + 1) }, out.length));
1731
- break;
1732
- }
1733
- case "unless":
1734
- if (!truthy(lookup(node.path, env, scope))) {
1735
- out.push(/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_react10.Fragment, { children: renderNodes(node.body, env, scope, depth + 1) }, out.length));
1736
- }
1737
- break;
1738
- case "each": {
1739
- const list = lookup(node.path, env, scope);
1740
- if (!Array.isArray(list)) break;
1741
- const count = Math.min(list.length, import_builder_schema17.EACH_ITERATION_CAP);
1742
- for (let i = 0; i < count && !env.stopped; i += 1) {
1743
- const inner = new Map(scope).set(node.as, list[i]);
1744
- out.push(/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_react10.Fragment, { children: renderNodes(node.body, env, inner, depth + 1) }, out.length));
1745
- }
1746
- break;
1747
- }
1748
- case "element":
1749
- out.push(renderElement(node, env, scope, depth, out.length));
1750
- break;
1751
- }
1752
- }
1753
- return out;
1754
- }
1755
- function renderTemplate(ast, env) {
1756
- return renderNodes(ast, env, /* @__PURE__ */ new Map(), 0);
1757
- }
1758
-
1759
- // src/custom/template-widget.tsx
1760
- var import_jsx_runtime22 = require("react/jsx-runtime");
1761
- var componentWeights = /* @__PURE__ */ new WeakMap();
1762
- var compiled = /* @__PURE__ */ new WeakMap();
1763
- function compileTemplate(snapshot, registry) {
1764
- let perRegistry = compiled.get(snapshot);
1765
- if (perRegistry === void 0) {
1766
- perRegistry = /* @__PURE__ */ new WeakMap();
1767
- compiled.set(snapshot, perRegistry);
1768
- }
1769
- if (perRegistry.has(registry)) return perRegistry.get(registry) ?? null;
1770
- const result = compile(snapshot, registry);
1771
- perRegistry.set(registry, result);
1772
- return result;
1773
- }
1774
- function compile(snapshot, registry) {
1775
- const label = `${snapshot.type}@${String(snapshot.v)}`;
1776
- const refuse = (why) => {
1777
- warnOnce(`template:${label}`, `${label} was refused (${why}); rendering nothing for it`);
1778
- return null;
1779
- };
1780
- if (snapshot.kind !== "template") return refuse("not a template widget");
1781
- const source = snapshot.template;
1782
- if (typeof source !== "string") return refuse("no template source");
1783
- const parsed = (0, import_builder_schema18.parseTemplate)(source);
1784
- if (!parsed.ok) return refuse(`template does not parse: ${parsed.issues[0]?.message ?? "invalid"}`);
1785
- const data = snapshot.data;
1786
- const issues = (0, import_builder_schema18.validateTemplate)(parsed.ast, {
1787
- settings: snapshot.settings,
1788
- data: typeof data === "object" && data !== null ? data : {},
1789
- sources: registry.sources()
1790
- });
1791
- if (issues.length > 0) return refuse(`template does not validate: ${issues[0]?.message ?? "invalid"}`);
1792
- if (!fitsBudget(parsed.ast)) return refuse(`it can render more than ${String(import_builder_schema18.MAX_TEMPLATE_WEIGHT)} nodes`);
1793
- const css = scopedCss(snapshot.css, snapshot.type);
1794
- if (css === null) return refuse("its css does not pass the sanitiser");
1795
- return { ast: parsed.ast, css, weight: (0, import_builder_schema18.templateWeight)(parsed.ast) };
1796
- }
1797
- function TemplateBody({ snapshot, registry, props, data, locale, mediaOrigin, budget }) {
1798
- const template = compileTemplate(snapshot, registry);
1799
- if (template === null) return null;
1800
- const env = newEnv({ settings: props, data, locale, mediaOrigin, budget: budget ?? new RenderBudget() });
1801
- return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(import_jsx_runtime22.Fragment, { children: [
1802
- template.css === "" ? null : /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(CustomCss, { css: template.css }),
1803
- renderTemplate(template.ast, env)
1804
- ] });
1805
- }
1806
- function TemplateWidget(props) {
1807
- 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 }) }) });
1808
- }
2729
+ var import_react16 = require("react");
1809
2730
 
1810
2731
  // src/custom/composite-widget.tsx
1811
- 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");
1812
2735
  var SETTING_KEY_RE = /^[a-z][A-Za-z0-9]{0,39}$/;
1813
2736
  var NODE_ID_RE = /^[a-z0-9]{8,24}$/;
1814
2737
  var WRAP = { section: "zzcompsec001", column: "zzcompcol001", inner: "zzcompinr001" };
1815
- var isRecord3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
1816
- var compiled2 = /* @__PURE__ */ new WeakMap();
2738
+ var isRecord4 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
2739
+ var compiled3 = /* @__PURE__ */ new WeakMap();
1817
2740
  function parseBody(raw) {
1818
- if (!isRecord3(raw)) return null;
2741
+ if (!isRecord4(raw)) return null;
1819
2742
  const columns = Array.isArray(raw.columns) ? raw.columns : void 0;
1820
2743
  const stack = Array.isArray(raw.stack) ? raw.stack : void 0;
1821
2744
  if (columns === void 0 === (stack === void 0)) return null;
1822
2745
  const children = columns !== void 0 ? [{ id: WRAP.inner, type: "inner-section", props: {}, columns }] : stack ?? [];
1823
- if (stack?.some((node) => isRecord3(node) && node.type === "inner-section")) return null;
1824
- 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({
1825
2748
  schemaVersion: 1,
1826
2749
  sections: [{ id: WRAP.section, type: "section", props: {}, columns: [{ id: WRAP.column, type: "column", props: { width: 100 }, children }] }]
1827
2750
  });
1828
- if (!parsed.success) return null;
1829
- const wrapper = parsed.data.sections[0];
2751
+ if (!parsed2.success) return null;
2752
+ const wrapper = parsed2.data.sections[0];
1830
2753
  const first = (wrapper?.type === "section" ? wrapper.columns[0]?.children : void 0) ?? [];
1831
2754
  if (columns !== void 0) {
1832
2755
  const inner = first[0];
@@ -1835,9 +2758,9 @@ function parseBody(raw) {
1835
2758
  return { stack: first.filter((node) => node.type !== "inner-section") };
1836
2759
  }
1837
2760
  function compileComposite(snapshot) {
1838
- if (compiled2.has(snapshot)) return compiled2.get(snapshot) ?? null;
2761
+ if (compiled3.has(snapshot)) return compiled3.get(snapshot) ?? null;
1839
2762
  const result = compile2(snapshot);
1840
- compiled2.set(snapshot, result);
2763
+ compiled3.set(snapshot, result);
1841
2764
  return result;
1842
2765
  }
1843
2766
  function compile2(snapshot) {
@@ -1853,12 +2776,12 @@ function compile2(snapshot) {
1853
2776
  const bindings = [];
1854
2777
  if (extra.bindings !== void 0 && !Array.isArray(extra.bindings)) return refuse("bindings is not a list");
1855
2778
  for (const raw of extra.bindings ?? []) {
1856
- 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)) {
1857
2780
  return refuse("a binding is malformed");
1858
2781
  }
1859
2782
  const targets = [];
1860
2783
  for (const target of raw.targets) {
1861
- 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)) {
1862
2785
  return refuse("a binding target is malformed");
1863
2786
  }
1864
2787
  targets.push({ node: target.node, prop: target.prop });
@@ -1866,12 +2789,12 @@ function compile2(snapshot) {
1866
2789
  bindings.push({ setting: raw.setting, targets });
1867
2790
  }
1868
2791
  const data = [];
1869
- 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");
1870
2793
  for (const [name, raw] of Object.entries(extra.data ?? {})) {
1871
- 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");
1872
2795
  const targets = [];
1873
2796
  for (const target of raw.targets) {
1874
- 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)) {
1875
2798
  return refuse("a data target is malformed");
1876
2799
  }
1877
2800
  targets.push({ node: target.node, input: target.input });
@@ -1927,7 +2850,7 @@ function build(input) {
1927
2850
  return id;
1928
2851
  }
1929
2852
  if (field.control === "link") {
1930
- if (!isRecord3(value) || typeof value.kind !== "string") return null;
2853
+ if (!isRecord4(value) || typeof value.kind !== "string") return null;
1931
2854
  const { href, ...target } = value;
1932
2855
  if (target.kind === "url") return typeof href === "string" ? { kind: "url", href } : null;
1933
2856
  hrefs.set(JSON.stringify(target), typeof href === "string" ? href : null);
@@ -1944,14 +2867,14 @@ function build(input) {
1944
2867
  const innerField = inner === void 0 ? void 0 : registry.widget(inner.type, inner.v)?.settings.find((f) => f.key === target.prop);
1945
2868
  if (inner === void 0 || innerField === void 0 || innerField.control !== field.control) continue;
1946
2869
  const converted = convert(field, value);
1947
- if ((0, import_builder_schema19.validateSettingValue)(innerField, converted) !== null) continue;
2870
+ if ((0, import_builder_schema22.validateSettingValue)(innerField, converted) !== null) continue;
1948
2871
  inner.props[target.prop] = converted;
1949
2872
  const responsive = inner.responsive;
1950
2873
  for (const device of DEVICES3) {
1951
2874
  if (responsive?.[device] !== void 0) delete responsive[device][target.prop];
1952
2875
  const raw = outer.responsive?.[device];
1953
2876
  const plain = field.output === "css" && field.translatable !== true && field.control !== "image" && field.control !== "link";
1954
- 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) {
1955
2878
  const target$ = inner.responsive ?? (inner.responsive = {});
1956
2879
  (target$[device] ?? (target$[device] = {}))[target.prop] = raw[binding.setting];
1957
2880
  }
@@ -1978,7 +2901,7 @@ function build(input) {
1978
2901
  props: { width: 100 },
1979
2902
  children: columns !== void 0 ? [{ id: ids.inner, type: "inner-section", props: { width: "full" }, columns }] : stack ?? []
1980
2903
  };
1981
- const document = {
2904
+ const document2 = {
1982
2905
  schemaVersion: 1,
1983
2906
  sections: [{ id: ids.section, type: "section", props: { width: "full" }, columns: [column] }]
1984
2907
  };
@@ -1987,10 +2910,10 @@ function build(input) {
1987
2910
  const component = registry.component(widget);
1988
2911
  weight += 1 + (component === void 0 ? 0 : componentWeights.get(component) ?? 0);
1989
2912
  }
1990
- return { document, assets, data: innerData, hrefs, weight };
2913
+ return { document: document2, assets, data: innerData, hrefs, weight };
1991
2914
  }
1992
2915
  function CompositeBody(props) {
1993
- const { snapshot, registry, node, data, locale, mediaOrigin, budget, resolveLink } = props;
2916
+ const { snapshot, registry, node, data, locale, mediaOrigin, budget, resolveLink, interactive, idScope } = props;
1994
2917
  const composite = compileComposite(snapshot);
1995
2918
  if (composite === null) return null;
1996
2919
  const built = build({ snapshot, compiled: composite, registry, node, props: props.props, data });
@@ -1998,7 +2921,7 @@ function CompositeBody(props) {
1998
2921
  warnOnce(`composite-weight:${snapshot.type}@${String(snapshot.v)}`, `${snapshot.type} would render too many nodes; rendering nothing for it`);
1999
2922
  return null;
2000
2923
  }
2001
- return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
2924
+ return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
2002
2925
  BuilderRenderer,
2003
2926
  {
2004
2927
  document: built.document,
@@ -2007,28 +2930,30 @@ function CompositeBody(props) {
2007
2930
  locale,
2008
2931
  assets: built.assets,
2009
2932
  mediaOrigin,
2933
+ interactive,
2934
+ idScope,
2010
2935
  resolveLink: (target) => built.hrefs.get(JSON.stringify(target)) ?? resolveLink?.(target) ?? null
2011
2936
  }
2012
2937
  );
2013
2938
  }
2014
2939
  function CompositeWidget(props) {
2015
- 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 }) }) });
2016
2941
  }
2017
2942
 
2018
2943
  // src/custom/factory.ts
2019
2944
  var isDisabled = (snapshot) => snapshot.status === "disabled";
2020
- 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;
2021
2946
  var customWidgetFactory = (snapshot, registry) => {
2022
2947
  if (isDisabled(snapshot)) return Disabled;
2023
2948
  if (snapshot.kind === "template") {
2024
2949
  const template = compileTemplate(snapshot, registry);
2025
2950
  if (template === null) return null;
2026
- const Component2 = (props) => (0, import_react13.createElement)(TemplateWidget, { ...props, snapshot, registry });
2951
+ const Component2 = (props) => (0, import_react16.createElement)(TemplateWidget, { ...props, snapshot, registry });
2027
2952
  componentWeights.set(Component2, template.weight);
2028
2953
  return Component2;
2029
2954
  }
2030
2955
  if (compileComposite(snapshot) === null) return null;
2031
- return (props) => (0, import_react13.createElement)(CompositeWidget, { ...props, snapshot, registry });
2956
+ return (props) => (0, import_react16.createElement)(CompositeWidget, { ...props, snapshot, registry });
2032
2957
  };
2033
2958
 
2034
2959
  // src/registry.ts
@@ -2036,12 +2961,12 @@ var BUILTIN_PACKS = [basicPack];
2036
2961
  var DEFAULT_CUSTOM_WIDGET = customWidgetFactory;
2037
2962
  var customKey = (type, v) => `${type}@${String(v)}`;
2038
2963
  function createRendererRegistry(packs, options = {}) {
2039
- const all = [...BUILTIN_PACKS, ...packs];
2964
+ const all2 = [...BUILTIN_PACKS, ...packs];
2040
2965
  const components = /* @__PURE__ */ new Map();
2041
2966
  const definitions = [];
2042
2967
  const sources = [];
2043
2968
  const resolvers = /* @__PURE__ */ new Map();
2044
- for (const pack of all) {
2969
+ for (const pack of all2) {
2045
2970
  for (const { Component: Component2, ...definition } of pack.widgets) {
2046
2971
  const key = customKey(definition.type, definition.v);
2047
2972
  if (components.has(key)) continue;
@@ -2056,7 +2981,7 @@ function createRendererRegistry(packs, options = {}) {
2056
2981
  }
2057
2982
  const factory = options.customWidget ?? DEFAULT_CUSTOM_WIDGET;
2058
2983
  const build2 = (custom) => {
2059
- const schema = (0, import_builder_schema20.createRegistry)(definitions, sources, custom);
2984
+ const schema = (0, import_builder_schema23.createRegistry)(definitions, sources, custom);
2060
2985
  const snapshots = new Map(custom.map((snapshot) => [customKey(snapshot.type, snapshot.v), snapshot]));
2061
2986
  const built = /* @__PURE__ */ new Map();
2062
2987
  const registry = {
@@ -2072,7 +2997,7 @@ function createRendererRegistry(packs, options = {}) {
2072
2997
  if (own !== void 0) return own;
2073
2998
  if (!node.type.startsWith("custom.") || factory === void 0) return void 0;
2074
2999
  const snapshot = snapshots.get(key);
2075
- if (snapshot === void 0) return void 0;
3000
+ if (snapshot === void 0 || snapshot.kind === "code") return void 0;
2076
3001
  if (!built.has(key)) built.set(key, factory(snapshot, registry));
2077
3002
  return built.get(key) ?? void 0;
2078
3003
  },
@@ -2084,8 +3009,8 @@ function createRendererRegistry(packs, options = {}) {
2084
3009
  }
2085
3010
 
2086
3011
  // src/slot.tsx
2087
- var import_react14 = require("react");
2088
- var import_jsx_runtime24 = require("react/jsx-runtime");
3012
+ var import_react17 = require("react");
3013
+ var import_jsx_runtime32 = require("react/jsx-runtime");
2089
3014
  function contextKey(context) {
2090
3015
  if (typeof context !== "object" || context === null) return "";
2091
3016
  return Object.values(context).map((value) => {
@@ -2101,20 +3026,20 @@ function BuilderSlot({ name, context }) {
2101
3026
  if (part === void 0 || part.document.sections.length === 0) return null;
2102
3027
  return (
2103
3028
  // Suspense inside the boundary: see parts.tsx.
2104
- /* @__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 }) }) }) })
2105
3030
  );
2106
3031
  }
2107
3032
 
2108
3033
  // src/theme.ts
2109
- var import_builder_schema21 = require("@usethrottle/builder-schema");
3034
+ var import_builder_schema24 = require("@usethrottle/builder-schema");
2110
3035
  var import_presets = require("@usethrottle/ui/presets");
2111
- var isRecord4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
3036
+ var isRecord5 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
2112
3037
  var str2 = (v) => typeof v === "string" && v !== "" ? v : void 0;
2113
3038
  var HEX = /^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;
2114
3039
  var SCALE = { compact: 0.85, comfortable: 1, roomy: 1.25 };
2115
3040
  var PALETTE_KEYS = Object.keys(import_presets.PRESET_TOKENS.clean.light);
2116
3041
  function palette(base, over) {
2117
- if (!isRecord4(over)) return base;
3042
+ if (!isRecord5(over)) return base;
2118
3043
  const out = { ...base };
2119
3044
  for (const key of PALETTE_KEYS) {
2120
3045
  const value = over[key];
@@ -2123,13 +3048,13 @@ function palette(base, over) {
2123
3048
  return out;
2124
3049
  }
2125
3050
  function themeTokens(settings) {
2126
- const theme = isRecord4(settings.theme) ? settings.theme : {};
3051
+ const theme = isRecord5(settings.theme) ? settings.theme : {};
2127
3052
  const preset = import_presets.PRESET_NAMES.includes(theme.preset) ? theme.preset : "clean";
2128
3053
  const customized = theme.customized === true;
2129
3054
  const base = import_presets.PRESET_TOKENS[preset];
2130
3055
  const colorScheme = theme.colorScheme === "light" || theme.colorScheme === "dark" ? theme.colorScheme : "auto";
2131
3056
  if (!customized) return { preset, customized, tokens: base, colorScheme };
2132
- const fonts = isRecord4(theme.fonts) ? theme.fonts : {};
3057
+ const fonts = isRecord5(theme.fonts) ? theme.fonts : {};
2133
3058
  return {
2134
3059
  preset,
2135
3060
  customized,
@@ -2155,7 +3080,7 @@ var SYSTEM_STACK = {
2155
3080
  };
2156
3081
  function fontStack(family) {
2157
3082
  if (Object.hasOwn(SYSTEM_STACK, family)) return SYSTEM_STACK[family];
2158
- 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);
2159
3084
  if (known === void 0 || !/^[A-Za-z0-9 ]{1,60}$/.test(family)) return SYSTEM_STACK["system-sans"];
2160
3085
  return `"${family}", ${Object.hasOwn(GENERIC, known.category) ? GENERIC[known.category] : "sans-serif"}`;
2161
3086
  }
@@ -2199,20 +3124,30 @@ function themeCss(settings) {
2199
3124
  if (colorScheme === "dark") return `${light}:root{${dark}}`;
2200
3125
  return `${light}@media (prefers-color-scheme:dark){:root{${dark}}}`;
2201
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
+ }
2202
3137
  function makeResolveLink(settings, packs) {
2203
- const routes = isRecord4(settings.routes) ? settings.routes : {};
3138
+ const routes = isRecord5(settings.routes) ? settings.routes : {};
2204
3139
  const pageRoute = str2(routes.page) ?? "/pages/{handle}";
2205
3140
  return (target) => {
2206
3141
  for (const pack of packs) {
2207
3142
  const href = pack.linkTargets?.resolve(target) ?? null;
2208
- 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: "" });
2209
3144
  }
2210
- if (target.kind === "url") return (0, import_builder_schema21.safeUrl)(target.href, "href", { mediaOrigin: "" });
2211
- 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: "" });
2212
3147
  if (target.kind === "page") {
2213
3148
  const slug = str2(target.slug) ?? str2(target.handle);
2214
3149
  if (slug !== void 0 && /^[A-Za-z0-9._~-]{1,200}$/.test(slug)) {
2215
- 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: "" });
2216
3151
  }
2217
3152
  }
2218
3153
  return null;
@@ -2223,7 +3158,7 @@ function menuItems(items, resolve, depth = 0) {
2223
3158
  if (!Array.isArray(items) || depth > 3) return [];
2224
3159
  const out = [];
2225
3160
  for (const item of items) {
2226
- 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;
2227
3162
  const label = str2(item.label);
2228
3163
  const href = resolve(item.target);
2229
3164
  if (label === void 0 || href === null) continue;
@@ -2239,24 +3174,24 @@ function menuItems(items, resolve, depth = 0) {
2239
3174
  return out;
2240
3175
  }
2241
3176
  var assetUrl = (v, mediaOrigin) => {
2242
- const raw = typeof v === "string" ? v : isRecord4(v) ? v.url : void 0;
2243
- 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;
2244
3179
  };
2245
3180
  function siteDesignOf(settings, resolve, pageOutlet, mediaOrigin) {
2246
3181
  const { preset, customized, tokens, colorScheme } = themeTokens(settings);
2247
- const brand = isRecord4(settings.brand) ? settings.brand : {};
2248
- const logo = isRecord4(brand.logo) ? brand.logo : {};
3182
+ const brand = isRecord5(settings.brand) ? settings.brand : {};
3183
+ const logo = isRecord5(brand.logo) ? brand.logo : {};
2249
3184
  const light = assetUrl(logo.light, mediaOrigin);
2250
3185
  const dark = assetUrl(logo.dark, mediaOrigin);
2251
3186
  const favicon = assetUrl(brand.favicon, mediaOrigin);
2252
- const menus = isRecord4(settings.menus) ? Object.fromEntries(Object.entries(settings.menus).map(([name, items]) => [name, menuItems(items, resolve)])) : {};
2253
- 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;
2254
3189
  const message = announcement === null ? void 0 : str2(announcement.message);
2255
- const announcementHref = announcement !== null && isRecord4(announcement.target) && typeof announcement.target.kind === "string" ? resolve(announcement.target) : null;
2256
- const strings = isRecord4(settings.strings) ? Object.fromEntries(Object.entries(settings.strings).filter((entry) => typeof entry[1] === "string")) : {};
2257
- const seo = isRecord4(settings.seo) ? settings.seo : {};
2258
- const routes = isRecord4(settings.routes) ? settings.routes : {};
2259
- 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 : {};
2260
3195
  const shareImage = assetUrl(seo.shareImage, mediaOrigin);
2261
3196
  const titleTemplate = str2(seo.titleTemplate);
2262
3197
  const defaultDescription = str2(seo.defaultDescription);
@@ -2286,45 +3221,45 @@ function siteDesignOf(settings, resolve, pageOutlet, mediaOrigin) {
2286
3221
  }
2287
3222
 
2288
3223
  // src/provider.tsx
2289
- var import_jsx_runtime25 = require("react/jsx-runtime");
3224
+ var import_jsx_runtime33 = require("react/jsx-runtime");
2290
3225
  var EMPTY = {};
2291
3226
  function useParentFont() {
2292
- return (0, import_react15.useContext)(import_ui6.AppearanceContext)?.variables?.fontFamily;
3227
+ return (0, import_react18.useContext)(import_ui6.AppearanceContext)?.variables?.fontFamily;
2293
3228
  }
2294
- function BuilderProvider({ builderKey, client, packs, site, onError, children }) {
3229
+ function BuilderProvider({ builderKey, client, packs, site, onError, interactive = true, pathname, catalogRoutes, mode = "live", children }) {
2295
3230
  const packsKey = packs.map((pack) => `${pack.id}@${pack.version}`).join("|");
2296
- const registryRef = (0, import_react15.useRef)(null);
3231
+ const registryRef = (0, import_react18.useRef)(null);
2297
3232
  if (registryRef.current?.key !== packsKey) {
2298
3233
  registryRef.current = { key: packsKey, registry: createRendererRegistry(packs) };
2299
3234
  }
2300
3235
  const registry = registryRef.current.registry;
2301
- const builder = (0, import_react15.useMemo)(
3236
+ const builder = (0, import_react18.useMemo)(
2302
3237
  () => client ?? (builderKey === void 0 ? null : (0, import_builder2.createBuilderClient)({ builderKey })),
2303
3238
  [client, builderKey]
2304
3239
  );
2305
3240
  const mediaOrigin = site.status === "ok" ? site.mediaOrigin : "";
2306
3241
  const settings = site.status === "ok" ? site.settings : EMPTY;
2307
- const resolveLink = (0, import_react15.useMemo)(() => makeResolveLink(settings, packs), [settings, packs]);
2308
- const outlets = (0, import_react15.useRef)(/* @__PURE__ */ new Map());
2309
- const renderers = (0, import_react15.useRef)(/* @__PURE__ */ new Map());
2310
- 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) => {
2311
3246
  let outlet = outlets.current.get(handle);
2312
3247
  if (outlet === void 0) {
2313
3248
  outlet = function PageOutlet() {
2314
- 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 }) }) });
2315
3250
  };
2316
3251
  outlets.current.set(handle, outlet);
2317
3252
  }
2318
3253
  return outlet;
2319
3254
  }, []);
2320
- const resolveSlot = (0, import_react15.useCallback)(
3255
+ const resolveSlot = (0, import_react18.useCallback)(
2321
3256
  (name) => {
2322
3257
  const part = site.status === "ok" && Object.hasOwn(site.slots, name) ? site.slots[name] : void 0;
2323
3258
  if (part === void 0 || part.document.sections.length === 0) return null;
2324
3259
  let renderer = renderers.current.get(name);
2325
3260
  if (renderer === void 0) {
2326
3261
  renderer = function SlotRenderer({ context }) {
2327
- return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(BuilderSlot, { name, context });
3262
+ return /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(BuilderSlot, { name, context });
2328
3263
  };
2329
3264
  renderers.current.set(name, renderer);
2330
3265
  }
@@ -2332,30 +3267,42 @@ function BuilderProvider({ builderKey, client, packs, site, onError, children })
2332
3267
  },
2333
3268
  [site]
2334
3269
  );
2335
- const value = (0, import_react15.useMemo)(
2336
- () => ({ client: builder, packs, registry, site, locale: site.locale, mediaOrigin, onError, resolveLink }),
2337
- [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]
2338
3284
  );
2339
- const design = (0, import_react15.useMemo)(
3285
+ const design = (0, import_react18.useMemo)(
2340
3286
  () => site.status === "ok" ? siteDesignOf(site.settings, resolveLink, pageOutlet, mediaOrigin) : null,
2341
3287
  [site, resolveLink, pageOutlet, mediaOrigin]
2342
3288
  );
2343
- 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]);
2344
3290
  const merged = (0, import_ui6.useAppearanceProviderValue)(own);
2345
3291
  const parentFont = useParentFont();
2346
- const appearance = (0, import_react15.useMemo)(() => {
3292
+ const appearance = (0, import_react18.useMemo)(() => {
2347
3293
  if (own === void 0) return void 0;
2348
3294
  return parentFont === void 0 ? merged : { ...merged, variables: { ...merged.variables, fontFamily: parentFont } };
2349
3295
  }, [own, merged, parentFont]);
2350
- 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: [
2351
- site.status === "ok" ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("style", { children: themeCss(site.settings) }) : null,
2352
- 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
2353
3300
  ] }) }) }) });
2354
3301
  }
2355
3302
 
2356
3303
  // src/parts.tsx
2357
- var import_react16 = require("react");
2358
- var import_jsx_runtime26 = require("react/jsx-runtime");
3304
+ var import_react19 = require("react");
3305
+ var import_jsx_runtime34 = require("react/jsx-runtime");
2359
3306
  function Part({ name, tag }) {
2360
3307
  const builder = useBuilder();
2361
3308
  if (builder === null || builder.site.status !== "ok") return null;
@@ -2365,11 +3312,11 @@ function Part({ name, tag }) {
2365
3312
  return (
2366
3313
  // Error boundaries do not catch on the server: the Suspense inside turns a throw
2367
3314
  // during SSR into "render nothing here" and the client retries under the boundary.
2368
- /* @__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 }) }) }) })
2369
3316
  );
2370
3317
  }
2371
- var BuilderHeader = () => /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(Part, { name: "header", tag: "header" });
2372
- 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" });
2373
3320
 
2374
3321
  // src/index.ts
2375
3322
  var import_builder3 = require("@usethrottle/builder");