@usethrottle/builder-react 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +228 -0
- package/dist/chunk-NUE2KNT2.js +2026 -0
- package/dist/chunk-S2XR224A.cjs +2026 -0
- package/dist/index.cjs +2317 -0
- package/dist/index.d.cts +452 -0
- package/dist/index.d.ts +452 -0
- package/dist/index.js +2320 -0
- package/dist/next.cjs +93 -0
- package/dist/next.d.cts +52 -0
- package/dist/next.d.ts +52 -0
- package/dist/next.js +93 -0
- package/dist/seo-Dz439Jlk.d.cts +149 -0
- package/dist/seo-Dz439Jlk.d.ts +149 -0
- package/dist/server.cjs +118 -0
- package/dist/server.d.cts +88 -0
- package/dist/server.d.ts +88 -0
- package/dist/server.js +118 -0
- package/package.json +96 -3
- package/README.md +0 -3
|
@@ -0,0 +1,2026 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
|
|
5
|
+
// src/data.ts
|
|
6
|
+
var _builderschema = require('@usethrottle/builder-schema');
|
|
7
|
+
|
|
8
|
+
// src/warn.ts
|
|
9
|
+
var seen = /* @__PURE__ */ new Set();
|
|
10
|
+
function warnOnce(key, message) {
|
|
11
|
+
if (seen.has(key)) return;
|
|
12
|
+
seen.add(key);
|
|
13
|
+
console.warn(`[throttle-builder] ${message}`);
|
|
14
|
+
}
|
|
15
|
+
var isDevelopment = () => typeof process === "undefined" || _optionalChain([process, 'access', _2 => _2.env, 'optionalAccess', _3 => _3.NODE_ENV]) !== "production";
|
|
16
|
+
|
|
17
|
+
// src/data.ts
|
|
18
|
+
function stable(value) {
|
|
19
|
+
if (Array.isArray(value)) return `[${value.map(stable).join(",")}]`;
|
|
20
|
+
if (typeof value === "object" && value !== null) {
|
|
21
|
+
const entries = Object.entries(value).filter(([, item]) => item !== void 0).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
22
|
+
return `{${entries.map(([k, v]) => `${JSON.stringify(k)}:${stable(v)}`).join(",")}}`;
|
|
23
|
+
}
|
|
24
|
+
return _nullishCoalesce(JSON.stringify(value), () => ( "null"));
|
|
25
|
+
}
|
|
26
|
+
function bindingKey(binding) {
|
|
27
|
+
return "params" in binding ? `${binding.source}?${stable(binding.params)}` : binding.source;
|
|
28
|
+
}
|
|
29
|
+
var isContextBinding = (binding) => binding.source.startsWith("context.");
|
|
30
|
+
function bindingsOf(node, registry) {
|
|
31
|
+
const def = registry.widget(node.type, node.v);
|
|
32
|
+
const out = {};
|
|
33
|
+
for (const [name, input] of Object.entries(_nullishCoalesce(_optionalChain([def, 'optionalAccess', _4 => _4.data]), () => ( {})))) {
|
|
34
|
+
if (input.default !== void 0) out[name] = input.default;
|
|
35
|
+
}
|
|
36
|
+
return { ...out, ..._nullishCoalesce(node.data, () => ( {})) };
|
|
37
|
+
}
|
|
38
|
+
function collectBindings(doc, registry) {
|
|
39
|
+
const found = /* @__PURE__ */ new Map();
|
|
40
|
+
_builderschema.walkNodes.call(void 0, doc, (node) => {
|
|
41
|
+
if (node.type === "section" || node.type === "inner-section" || node.type === "column") return;
|
|
42
|
+
for (const binding of Object.values(bindingsOf(node, registry))) {
|
|
43
|
+
const key = bindingKey(binding);
|
|
44
|
+
if (!found.has(key)) found.set(key, binding);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return found;
|
|
48
|
+
}
|
|
49
|
+
async function resolveBindings(bindings, registry, ctx, options) {
|
|
50
|
+
const jobs = [];
|
|
51
|
+
for (const [key, binding] of bindings) {
|
|
52
|
+
if (isContextBinding(binding) || !("params" in binding)) continue;
|
|
53
|
+
const descriptor = registry.source(binding.source);
|
|
54
|
+
const resolve = registry.resolver(binding.source);
|
|
55
|
+
if (descriptor === void 0 || resolve === void 0) continue;
|
|
56
|
+
if (options.include === "static" && descriptor.perShopper) continue;
|
|
57
|
+
if (options.include === "shopper" && !descriptor.perShopper) continue;
|
|
58
|
+
jobs.push(
|
|
59
|
+
resolve(binding.params, ctx).then(
|
|
60
|
+
(value) => [key, value],
|
|
61
|
+
(error) => {
|
|
62
|
+
warnOnce(`resolve:${binding.source}`, `Data source ${binding.source} failed (${String(error)}); its widgets render without data`);
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
)
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
const settled = await Promise.all(jobs);
|
|
69
|
+
return Object.fromEntries(settled.filter((entry) => entry !== null));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// src/load.ts
|
|
73
|
+
function pageOf(raw, initialData) {
|
|
74
|
+
const { document, id: _id, slug, title, path, generation, pageType: _type, updatedAt: _updated, ...meta } = raw;
|
|
75
|
+
return {
|
|
76
|
+
kind: "page",
|
|
77
|
+
slug,
|
|
78
|
+
title,
|
|
79
|
+
path,
|
|
80
|
+
generation,
|
|
81
|
+
document,
|
|
82
|
+
assets: _nullishCoalesce(document.assets, () => ( {})),
|
|
83
|
+
initialData,
|
|
84
|
+
meta
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
async function staticDataFor(documents, registry, locale) {
|
|
88
|
+
const bindings = /* @__PURE__ */ new Map();
|
|
89
|
+
for (const document of documents) {
|
|
90
|
+
for (const [key, binding] of collectBindings(document, registry)) bindings.set(key, binding);
|
|
91
|
+
}
|
|
92
|
+
if (bindings.size === 0) return {};
|
|
93
|
+
return resolveBindings(
|
|
94
|
+
bindings,
|
|
95
|
+
registry,
|
|
96
|
+
{ locale, preview: false, signal: new AbortController().signal },
|
|
97
|
+
{ include: "static" }
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
function partOf(loaded, initialData) {
|
|
101
|
+
return { document: loaded.document, assets: _nullishCoalesce(loaded.document.assets, () => ( {})), initialData };
|
|
102
|
+
}
|
|
103
|
+
var isRedirect = (raw) => typeof raw.redirectTo === "string";
|
|
104
|
+
|
|
105
|
+
// src/server/bundle.ts
|
|
106
|
+
var _react = require('react'); var React = _interopRequireWildcard(_react);
|
|
107
|
+
var _builder = require('@usethrottle/builder');
|
|
108
|
+
var cache2 = _nullishCoalesce(React.cache, () => ( ((fn) => fn)));
|
|
109
|
+
var requestBatches = cache2(() => []);
|
|
110
|
+
function getBundle(ask) {
|
|
111
|
+
const batches = requestBatches();
|
|
112
|
+
const slots = new Set(_nullishCoalesce(ask.slots, () => ( [])));
|
|
113
|
+
const sameClient = (batch2) => batch2.client === ask.client && batch2.locale === ask.locale;
|
|
114
|
+
const pageFits = (batch2) => ask.page === void 0 || batch2.page === ask.page;
|
|
115
|
+
for (const batch2 of batches) {
|
|
116
|
+
if (!sameClient(batch2)) continue;
|
|
117
|
+
if (batch2.dispatched) {
|
|
118
|
+
if (pageFits(batch2) && [...slots].every((slot) => batch2.slots.has(slot))) return batch2.promise;
|
|
119
|
+
} else if (ask.page === void 0 || batch2.page === void 0 || batch2.page === ask.page) {
|
|
120
|
+
_nullishCoalesce(batch2.page, () => ( (batch2.page = ask.page)));
|
|
121
|
+
for (const slot of slots) batch2.slots.add(slot);
|
|
122
|
+
return batch2.promise;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const batch = {
|
|
126
|
+
client: ask.client,
|
|
127
|
+
locale: ask.locale,
|
|
128
|
+
page: ask.page,
|
|
129
|
+
slots,
|
|
130
|
+
dispatched: false,
|
|
131
|
+
promise: Promise.resolve()
|
|
132
|
+
};
|
|
133
|
+
batch.promise = Promise.resolve().then(() => {
|
|
134
|
+
batch.dispatched = true;
|
|
135
|
+
return ask.client.bundle({
|
|
136
|
+
locale: ask.locale,
|
|
137
|
+
...batch.page === void 0 ? {} : { page: batch.page },
|
|
138
|
+
slots: [...batch.slots].sort()
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
batches.push(batch);
|
|
142
|
+
return batch.promise;
|
|
143
|
+
}
|
|
144
|
+
var clients = /* @__PURE__ */ new Map();
|
|
145
|
+
function clientOf(options) {
|
|
146
|
+
if (options.client !== void 0) return options.client;
|
|
147
|
+
const key = options.builderKey;
|
|
148
|
+
if (key === void 0 || key === "") throw new TypeError("Give the Builder loaders a client or a builderKey");
|
|
149
|
+
let client = clients.get(key);
|
|
150
|
+
if (client === void 0) {
|
|
151
|
+
client = _builder.createBuilderClient.call(void 0, { builderKey: key });
|
|
152
|
+
clients.set(key, client);
|
|
153
|
+
}
|
|
154
|
+
return client;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// src/registry.ts
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
// src/basics/index.ts
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
// src/basics/announcement.tsx
|
|
164
|
+
|
|
165
|
+
var _ui = require('@usethrottle/ui');
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
// src/basics/util.tsx
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
// src/basics/styles.ts
|
|
172
|
+
var BASICS_CSS = `@layer throttle{
|
|
173
|
+
.tb-b-heading{margin:0;text-align:var(--b-align,left);color:var(--b-color,inherit);font-size:var(--b-size,var(--tb-text-l));line-height:1.2;overflow-wrap:anywhere}
|
|
174
|
+
.tb-b-text{text-align:var(--b-align,left);color:var(--b-color,inherit);font-size:var(--b-size,var(--tb-text-m));line-height:1.6;overflow-wrap:anywhere}
|
|
175
|
+
.tb-b-text>:first-child{margin-block-start:0}
|
|
176
|
+
.tb-b-text>:last-child{margin-block-end:0}
|
|
177
|
+
.tb-b-text h2,.tb-b-text h3,.tb-b-text h4{line-height:1.25}
|
|
178
|
+
.tb-b-text blockquote{margin-inline:0;padding-inline-start:var(--tb-space-m);border-inline-start:3px solid var(--tb-color-border,currentColor)}
|
|
179
|
+
.tb-b-text code{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:.9em}
|
|
180
|
+
.tb-b-link{color:var(--tb-color-primary,currentColor);text-decoration:underline}
|
|
181
|
+
.tb-b-image{text-align:var(--b-align,left);line-height:0}
|
|
182
|
+
.tb-b-image-box{display:inline-block;max-inline-size:100%;inline-size:calc(var(--b-width,100)*1%);vertical-align:top}
|
|
183
|
+
.tb-b-image-box a{display:block}
|
|
184
|
+
.tb-b-img{display:block;inline-size:100%;max-inline-size:100%;block-size:calc(var(--b-height)*1px);object-fit:var(--bx-fit,cover);border-radius:var(--bx-radius,0)}
|
|
185
|
+
.tb-b-empty{padding:var(--tb-space-m);border:1px dashed var(--tb-color-border-control,currentColor);color:var(--tb-color-muted-foreground,inherit);font-size:var(--tb-text-s);line-height:1.4;text-align:center}
|
|
186
|
+
.tb-b-button-wrap{text-align:var(--b-align,left)}
|
|
187
|
+
.tb-b-button{display:inline-block;box-sizing:border-box;min-inline-size:calc(100%*var(--b-fullWidth,0));max-inline-size:100%;border:1px solid transparent;border-radius:var(--throttle-radius,8px);font:inherit;font-weight:600;line-height:1.2;text-align:center;text-decoration:none;cursor:pointer}
|
|
188
|
+
.tb-b-button--s{padding:.4rem .9rem;font-size:var(--tb-text-s)}
|
|
189
|
+
.tb-b-button--m{padding:.65rem 1.25rem;font-size:var(--tb-text-m)}
|
|
190
|
+
.tb-b-button--l{padding:.9rem 1.75rem;font-size:var(--tb-text-l)}
|
|
191
|
+
.tb-b-button--primary{background:var(--tb-color-primary,#111);color:var(--tb-color-primary-foreground,#fff)}
|
|
192
|
+
.tb-b-button--secondary{background:var(--tb-color-muted,#eee);color:var(--tb-color-foreground,#111)}
|
|
193
|
+
.tb-b-button--outline{background:transparent;border-color:var(--tb-color-border-control,currentColor);color:var(--tb-color-foreground,#111)}
|
|
194
|
+
.tb-b-button--link{padding-inline:0;background:transparent;color:var(--tb-color-primary,#111);text-decoration:underline}
|
|
195
|
+
.tb-b-button:hover{filter:brightness(.92)}
|
|
196
|
+
.tb-b-button:focus-visible,.tb-b-menu a:focus-visible,.tb-b-menu-toggle:focus-visible,.tb-b-play:focus-visible,.tb-b-dismiss:focus-visible{outline:2px solid var(--tb-color-primary,currentColor);outline-offset:2px}
|
|
197
|
+
.tb-b-spacer{block-size:var(--b-height,var(--tb-space-l))}
|
|
198
|
+
.tb-b-divider{box-sizing:border-box;inline-size:calc(var(--b-width,100)*1%);margin:0 auto;border:0;border-block-start:calc(var(--b-thickness,1)*1px) var(--bx-style,solid) var(--b-color,var(--tb-color-border,currentColor))}
|
|
199
|
+
.tb-b-video{position:relative;inline-size:100%;aspect-ratio:var(--bx-ratio,16/9);background:var(--tb-color-foreground,#111);border-radius:var(--throttle-radius,8px);overflow:hidden}
|
|
200
|
+
.tb-b-video iframe,.tb-b-play{position:absolute;inset:0;inline-size:100%;block-size:100%;border:0}
|
|
201
|
+
.tb-b-play{display:flex;align-items:center;justify-content:center;padding:0;background:transparent;color:var(--tb-color-background,#fff);cursor:pointer}
|
|
202
|
+
.tb-b-play span{display:grid;place-items:center;inline-size:4rem;block-size:4rem;border-radius:50%;background:rgba(0,0,0,.55)}
|
|
203
|
+
.tb-b-play:hover span{background:rgba(0,0,0,.75)}
|
|
204
|
+
.tb-b-logo{text-align:var(--b-align,left);line-height:0}
|
|
205
|
+
.tb-b-logo a{display:inline-block;color:inherit;text-decoration:none}
|
|
206
|
+
.tb-b-logo img{display:block;block-size:calc(var(--b-height,40)*1px);inline-size:auto;max-inline-size:100%}
|
|
207
|
+
.tb-b-logo-name{display:inline-block;font-size:var(--tb-text-xl);font-weight:700;line-height:calc(var(--b-height,40)*1px)}
|
|
208
|
+
.tb-b-menu{position:relative;text-align:var(--b-align,left);color:var(--b-color,inherit);font-size:var(--b-size,var(--tb-text-m))}
|
|
209
|
+
.tb-b-menu ul{margin:0;padding:0;list-style:none}
|
|
210
|
+
.tb-b-menu a{display:block;padding:var(--tb-space-xs) var(--tb-space-s);color:inherit;text-decoration:none}
|
|
211
|
+
.tb-b-menu a:hover{text-decoration:underline}
|
|
212
|
+
.tb-b-menu li{position:relative}
|
|
213
|
+
.tb-b-menu--vertical li li{padding-inline-start:var(--tb-space-m)}
|
|
214
|
+
.tb-b-menu--h>ul>li{display:inline-block}
|
|
215
|
+
.tb-b-menu--h li>ul{display:none;position:absolute;inset-block-start:100%;inset-inline-start:0;z-index:20;min-inline-size:12rem;padding:var(--tb-space-xs);text-align:start;background:var(--tb-color-background,#fff);color:var(--tb-color-foreground,#111);border:1px solid var(--tb-color-border,#ddd);border-radius:var(--throttle-radius,8px)}
|
|
216
|
+
.tb-b-menu--h li:hover>ul,.tb-b-menu--h li:focus-within>ul{display:block}
|
|
217
|
+
.tb-b-menu-toggle{display:none;align-items:center;justify-content:center;min-inline-size:44px;min-block-size:44px;padding:0;border:0;background:transparent;color:inherit;cursor:pointer}
|
|
218
|
+
@media (max-width:767px){
|
|
219
|
+
.tb-b-menu--drawer-on-phone .tb-b-menu-toggle{display:inline-flex;position:relative;z-index:61}
|
|
220
|
+
.tb-b-menu--drawer-on-phone[data-open=true] .tb-b-menu-toggle{position:fixed;inset-block-start:var(--tb-space-s);inset-inline-end:var(--tb-space-s)}
|
|
221
|
+
.tb-b-menu--drawer-on-phone>ul{display:none}
|
|
222
|
+
.tb-b-menu--drawer-on-phone[data-open=true]>ul{display:block;position:fixed;inset:0;z-index:60;overflow:auto;padding:4.5rem var(--tb-space-m) var(--tb-space-m);text-align:start;background:var(--tb-color-background,#fff);color:var(--tb-color-foreground,#111);font-size:var(--tb-text-l)}
|
|
223
|
+
.tb-b-menu--drawer-on-phone>ul>li{display:block}
|
|
224
|
+
.tb-b-menu--drawer-on-phone li>ul{display:block;position:static;min-inline-size:0;padding:0;border:0;padding-inline-start:var(--tb-space-m)}
|
|
225
|
+
}
|
|
226
|
+
.tb-b-announcement{display:flex;align-items:center;justify-content:center;gap:var(--tb-space-s);box-sizing:border-box;padding:var(--tb-space-s) var(--tb-space-m);text-align:var(--b-align,center);background:var(--b-background,var(--tb-color-primary,#111));color:var(--b-color,var(--tb-color-primary-foreground,#fff));font-size:var(--tb-text-s)}
|
|
227
|
+
.tb-b-announcement-text{flex:1 1 auto}
|
|
228
|
+
.tb-b-announcement a{color:inherit;text-decoration:underline}
|
|
229
|
+
.tb-b-dismiss{display:inline-grid;place-items:center;flex:0 0 auto;min-inline-size:32px;min-block-size:32px;padding:0;border:0;background:transparent;color:inherit;cursor:pointer}
|
|
230
|
+
.tb-b-copyright{margin:0;text-align:var(--b-align,center);color:var(--b-color,var(--tb-color-muted-foreground,inherit));font-size:var(--b-size,var(--tb-text-s))}
|
|
231
|
+
}`;
|
|
232
|
+
|
|
233
|
+
// src/basics/util.tsx
|
|
234
|
+
var _jsxruntime = require('react/jsx-runtime');
|
|
235
|
+
function BasicStyles() {
|
|
236
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "style", { href: "tb-basics", precedence: "throttle", children: BASICS_CSS });
|
|
237
|
+
}
|
|
238
|
+
var isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
239
|
+
var str = (v) => typeof v === "string" && v !== "" ? v : void 0;
|
|
240
|
+
function oneOf(value, allowed, fallback) {
|
|
241
|
+
return _nullishCoalesce(allowed.find((candidate) => candidate === value), () => ( fallback));
|
|
242
|
+
}
|
|
243
|
+
function hrefOf(link, mediaOrigin) {
|
|
244
|
+
if (!isRecord(link)) return null;
|
|
245
|
+
return _builderschema.safeUrl.call(void 0, link.href, "href", { mediaOrigin });
|
|
246
|
+
}
|
|
247
|
+
function Placeholder({ editMode, children }) {
|
|
248
|
+
return editMode ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "tb-b-empty", children }) : null;
|
|
249
|
+
}
|
|
250
|
+
var ID_RE = /^[a-z0-9]{8,24}$/;
|
|
251
|
+
var DEVICES = ["desktop", "tablet", "phone"];
|
|
252
|
+
function defaultOf(type, key) {
|
|
253
|
+
const def = _builderschema.BASIC_WIDGET_DEFINITIONS.find((d) => d.type === type);
|
|
254
|
+
return _nullishCoalesce(_optionalChain([def, 'optionalAccess', _5 => _5.settings, 'access', _6 => _6.find, 'call', _7 => _7((f) => f.key === key), 'optionalAccess', _8 => _8.default]), () => ( null));
|
|
255
|
+
}
|
|
256
|
+
function enumCss(node, rules) {
|
|
257
|
+
if (!ID_RE.test(node.id)) return "";
|
|
258
|
+
const per = { desktop: /* @__PURE__ */ new Map(), tablet: /* @__PURE__ */ new Map(), phone: /* @__PURE__ */ new Map() };
|
|
259
|
+
for (const device of DEVICES) {
|
|
260
|
+
const settings = { ...Object.fromEntries(rules.map((r) => [r.key, defaultOf(node.type, r.key)])), ...node.props };
|
|
261
|
+
const resolved = _builderschema.resolveResponsive.call(void 0, settings, node.responsive, device);
|
|
262
|
+
for (const rule of rules) {
|
|
263
|
+
const value = resolved[rule.key];
|
|
264
|
+
const fallback = defaultOf(node.type, rule.key);
|
|
265
|
+
const pick = typeof value === "string" && Object.hasOwn(rule.values, value) ? value : String(fallback);
|
|
266
|
+
const css = Object.hasOwn(rule.values, pick) ? rule.values[pick] : void 0;
|
|
267
|
+
if (css !== void 0) per[device].set(rule.property, css);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
const block2 = (decls) => decls.length === 0 ? "" : `[data-b-id="${node.id}"]{${decls.map(([p, v]) => `${p}:${v}`).join(";")}}`;
|
|
271
|
+
const diff = (prev, next) => [...next].filter(([p, v]) => prev.get(p) !== v);
|
|
272
|
+
const tablet = block2(diff(per.desktop, per.tablet));
|
|
273
|
+
const phone = block2(diff(per.tablet, per.phone));
|
|
274
|
+
return block2([...per.desktop]) + (tablet === "" ? "" : `@media (max-width:1024px){${tablet}}`) + (phone === "" ? "" : `@media (max-width:767px){${phone}}`);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// src/basics/announcement.tsx
|
|
278
|
+
|
|
279
|
+
var KEY = "tb-announcement-dismissed";
|
|
280
|
+
function read(message) {
|
|
281
|
+
try {
|
|
282
|
+
return window.sessionStorage.getItem(KEY) === message;
|
|
283
|
+
} catch (e2) {
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
function write(message) {
|
|
288
|
+
try {
|
|
289
|
+
window.sessionStorage.setItem(KEY, message);
|
|
290
|
+
} catch (e3) {
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
function Announcement({ props, mediaOrigin, editMode }) {
|
|
294
|
+
const design = _ui.useSiteDesign.call(void 0, );
|
|
295
|
+
const message = _optionalChain([design, 'optionalAccess', _9 => _9.announcement, 'optionalAccess', _10 => _10.message]);
|
|
296
|
+
const [dismissed, setDismissed] = _react.useState.call(void 0, false);
|
|
297
|
+
_react.useEffect.call(void 0, () => {
|
|
298
|
+
if (message !== void 0 && read(message)) setDismissed(true);
|
|
299
|
+
}, [message]);
|
|
300
|
+
if (message === void 0) {
|
|
301
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
302
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, BasicStyles, {}),
|
|
303
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, Placeholder, { editMode, children: "No announcement: turn one on in Site settings" })
|
|
304
|
+
] });
|
|
305
|
+
}
|
|
306
|
+
if (dismissed && !editMode) return null;
|
|
307
|
+
const href = _builderschema.safeUrl.call(void 0, _optionalChain([design, 'optionalAccess', _11 => _11.announcement, 'optionalAccess', _12 => _12.href]), "href", { mediaOrigin });
|
|
308
|
+
const strings = _optionalChain([design, 'optionalAccess', _13 => _13.strings]);
|
|
309
|
+
const dismissLabel = _nullishCoalesce((strings !== void 0 && Object.hasOwn(strings, "announcement.dismiss") ? str(strings["announcement.dismiss"]) : void 0), () => ( _builderschema.SITE_STRING_DEFAULTS["announcement.dismiss"]));
|
|
310
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
311
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, BasicStyles, {}),
|
|
312
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "tb-b-announcement", role: "region", "aria-label": message, children: [
|
|
313
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "tb-b-announcement-text", children: href === null ? message : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "a", { href, children: message }) }),
|
|
314
|
+
props.dismissible === true && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
315
|
+
"button",
|
|
316
|
+
{
|
|
317
|
+
type: "button",
|
|
318
|
+
className: "tb-b-dismiss",
|
|
319
|
+
onClick: () => {
|
|
320
|
+
write(message);
|
|
321
|
+
setDismissed(true);
|
|
322
|
+
},
|
|
323
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _ui.Icon, { name: "close", size: 16, label: dismissLabel })
|
|
324
|
+
}
|
|
325
|
+
)
|
|
326
|
+
] })
|
|
327
|
+
] });
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// src/basics/button.tsx
|
|
331
|
+
|
|
332
|
+
var STYLES = ["primary", "secondary", "outline", "link"];
|
|
333
|
+
var SIZES = ["s", "m", "l"];
|
|
334
|
+
function Button({ props, mediaOrigin, inlineEdit }) {
|
|
335
|
+
const href = hrefOf(props.link, mediaOrigin);
|
|
336
|
+
const className = `tb-b-button tb-b-button--${oneOf(props.style, STYLES, "primary")} tb-b-button--${oneOf(props.size, SIZES, "m")}`;
|
|
337
|
+
const label = _nullishCoalesce(_nullishCoalesce(_optionalChain([inlineEdit, 'optionalCall', _14 => _14("label")]), () => ( str(props.label))), () => ( ""));
|
|
338
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
339
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, BasicStyles, {}),
|
|
340
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "tb-b-button-wrap", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "a", { className, ...href === null ? {} : { href }, children: label }) })
|
|
341
|
+
] });
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// src/basics/copyright.tsx
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
function Copyright(_) {
|
|
349
|
+
const design = _ui.useSiteDesign.call(void 0, );
|
|
350
|
+
const strings = _optionalChain([design, 'optionalAccess', _15 => _15.strings]);
|
|
351
|
+
const template = strings !== void 0 && Object.hasOwn(strings, "footer.copyright") ? str(strings["footer.copyright"]) : void 0;
|
|
352
|
+
const line = (_nullishCoalesce(template, () => ( _builderschema.SITE_STRING_DEFAULTS["footer.copyright"]))).replace("{year}", () => String((/* @__PURE__ */ new Date()).getFullYear())).replace("{store}", () => _nullishCoalesce(str(_optionalChain([design, 'optionalAccess', _16 => _16.brand, 'optionalAccess', _17 => _17.storeName])), () => ( ""))).replace(/\s{2,}/g, " ").replace(/\s+([.,])/g, "$1");
|
|
353
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
354
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, BasicStyles, {}),
|
|
355
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "tb-b-copyright", children: line })
|
|
356
|
+
] });
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// src/widget-style.tsx
|
|
360
|
+
|
|
361
|
+
function WidgetStyle({ css }) {
|
|
362
|
+
if (css === "" || css.includes("<")) return null;
|
|
363
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "style", { children: css });
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// src/basics/divider.tsx
|
|
367
|
+
|
|
368
|
+
var RULES = [{ key: "style", property: "--bx-style", values: { solid: "solid", dashed: "dashed", dotted: "dotted" } }];
|
|
369
|
+
function Divider({ node }) {
|
|
370
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
371
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, BasicStyles, {}),
|
|
372
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, WidgetStyle, { css: enumCss(node, RULES) }),
|
|
373
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "hr", { className: "tb-b-divider" })
|
|
374
|
+
] });
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// src/basics/heading.tsx
|
|
378
|
+
|
|
379
|
+
var LEVELS = ["h1", "h2", "h3", "h4", "h5", "h6"];
|
|
380
|
+
function Heading({ props, inlineEdit }) {
|
|
381
|
+
const Tag = oneOf(props.level, LEVELS, "h2");
|
|
382
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
383
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, BasicStyles, {}),
|
|
384
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, Tag, { className: "tb-b-heading", children: _nullishCoalesce(_nullishCoalesce(_optionalChain([inlineEdit, 'optionalCall', _18 => _18("text")]), () => ( str(props.text))), () => ( "")) })
|
|
385
|
+
] });
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// src/basics/image.tsx
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
// src/asset-image.tsx
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
function isFrozenAsset(value) {
|
|
395
|
+
if (typeof value !== "object" || value === null) return false;
|
|
396
|
+
const v = value;
|
|
397
|
+
return typeof v.url === "string" && typeof v.width === "number" && typeof v.height === "number" && Array.isArray(v.variants);
|
|
398
|
+
}
|
|
399
|
+
function AssetImage(props) {
|
|
400
|
+
const { asset, alt, sizes, className, loading = "lazy", style, mediaOrigin } = props;
|
|
401
|
+
const href = (url) => _builderschema.safeUrl.call(void 0, url, "src", { mediaOrigin });
|
|
402
|
+
if (!isFrozenAsset(asset)) return null;
|
|
403
|
+
const src = href(asset.url);
|
|
404
|
+
if (src === null) return null;
|
|
405
|
+
const srcSet = asset.variants.flatMap((variant) => {
|
|
406
|
+
const url = href(variant.url);
|
|
407
|
+
return url === null || url.includes(",") ? [] : [`${url} ${String(variant.width)}w`];
|
|
408
|
+
}).join(", ");
|
|
409
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
410
|
+
"img",
|
|
411
|
+
{
|
|
412
|
+
src,
|
|
413
|
+
...srcSet === "" ? {} : { srcSet, sizes: _nullishCoalesce(sizes, () => ( "100vw")) },
|
|
414
|
+
width: asset.width,
|
|
415
|
+
height: asset.height,
|
|
416
|
+
alt,
|
|
417
|
+
loading,
|
|
418
|
+
decoding: "async",
|
|
419
|
+
...className === void 0 ? {} : { className },
|
|
420
|
+
style: { aspectRatio: `${String(asset.width)} / ${String(asset.height)}`, ...style }
|
|
421
|
+
}
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
// src/basics/image.tsx
|
|
426
|
+
|
|
427
|
+
var RULES2 = [
|
|
428
|
+
{ key: "radius", property: "--bx-radius", values: { none: "0", s: "4px", m: "8px", l: "16px", full: "9999px" } },
|
|
429
|
+
{ key: "fit", property: "--bx-fit", values: { cover: "cover", contain: "contain" } }
|
|
430
|
+
];
|
|
431
|
+
function Image({ node, props, mediaOrigin, editMode }) {
|
|
432
|
+
const href = hrefOf(props.link, mediaOrigin);
|
|
433
|
+
const decorative = props.decorative === true;
|
|
434
|
+
const alt = decorative ? "" : typeof props.alt === "string" ? props.alt : "";
|
|
435
|
+
const asset = isFrozenAsset(props.image) ? props.image : void 0;
|
|
436
|
+
const image = /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AssetImage, { asset, mediaOrigin, alt, className: "tb-b-img", sizes: "(max-width: 767px) 100vw, 50vw" });
|
|
437
|
+
const shown = asset !== void 0 && _builderschema.safeUrl.call(void 0, asset.url, "src", { mediaOrigin }) !== null;
|
|
438
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
439
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, BasicStyles, {}),
|
|
440
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, WidgetStyle, { css: enumCss(node, RULES2) }),
|
|
441
|
+
shown ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "tb-b-image", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "tb-b-image-box", children: href === null ? image : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "a", { href, children: image }) }) }) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Placeholder, { editMode, children: asset === void 0 ? "Choose an image" : "Image unavailable" })
|
|
442
|
+
] });
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// src/basics/logo.tsx
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
function Logo({ props, mediaOrigin, editMode }) {
|
|
450
|
+
const design = _ui.useSiteDesign.call(void 0, );
|
|
451
|
+
const scheme = _nullishCoalesce(_optionalChain([design, 'optionalAccess', _19 => _19.theme, 'optionalAccess', _20 => _20.colorScheme]), () => ( "auto"));
|
|
452
|
+
const src = (url) => url === void 0 ? void 0 : _nullishCoalesce(_builderschema.safeUrl.call(void 0, url, "src", { mediaOrigin }), () => ( void 0));
|
|
453
|
+
const light = src(_optionalChain([design, 'optionalAccess', _21 => _21.brand, 'optionalAccess', _22 => _22.logo, 'optionalAccess', _23 => _23.light]));
|
|
454
|
+
const dark = src(_optionalChain([design, 'optionalAccess', _24 => _24.brand, 'optionalAccess', _25 => _25.logo, 'optionalAccess', _26 => _26.dark]));
|
|
455
|
+
const main = scheme === "dark" ? _nullishCoalesce(dark, () => ( light)) : _nullishCoalesce(light, () => ( dark));
|
|
456
|
+
const name = str(_optionalChain([design, 'optionalAccess', _27 => _27.brand, 'optionalAccess', _28 => _28.storeName]));
|
|
457
|
+
const href = _nullishCoalesce(hrefOf(props.link, mediaOrigin), () => ( "/"));
|
|
458
|
+
const alt = _nullishCoalesce(name, () => ( ""));
|
|
459
|
+
let content = null;
|
|
460
|
+
if (main !== void 0) {
|
|
461
|
+
const img = /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "img", { src: main, alt, decoding: "async" });
|
|
462
|
+
content = scheme === "auto" && light !== void 0 && dark !== void 0 ? /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "picture", { children: [
|
|
463
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "source", { media: "(prefers-color-scheme: dark)", srcSet: dark }),
|
|
464
|
+
img
|
|
465
|
+
] }) : img;
|
|
466
|
+
} else if (name !== void 0) {
|
|
467
|
+
content = /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "tb-b-logo-name", children: name });
|
|
468
|
+
}
|
|
469
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
470
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, BasicStyles, {}),
|
|
471
|
+
content === null ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Placeholder, { editMode, children: "Logo: add one in Site settings" }) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "tb-b-logo", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "a", { href, children: content }) })
|
|
472
|
+
] });
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// src/basics/menu.tsx
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
var LAYOUTS = ["horizontal", "vertical", "drawer-on-phone"];
|
|
481
|
+
var MAX_DEPTH = 3;
|
|
482
|
+
function List({ items, mediaOrigin, depth = 0, id, onNavigate }) {
|
|
483
|
+
const shown = items.flatMap((item) => {
|
|
484
|
+
const href = _builderschema.safeUrl.call(void 0, item.href, "href", { mediaOrigin });
|
|
485
|
+
return href === null ? [] : [{ item, href }];
|
|
486
|
+
});
|
|
487
|
+
if (shown.length === 0) return null;
|
|
488
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "ul", { ...id === void 0 ? {} : { id }, ...onNavigate === void 0 ? {} : { onClick: onNavigate }, children: shown.map(({ item, href }, index) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "li", { children: [
|
|
489
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "a", { href, children: item.label }),
|
|
490
|
+
depth + 1 < MAX_DEPTH && item.children !== void 0 && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, List, { items: item.children, mediaOrigin, depth: depth + 1 })
|
|
491
|
+
] }, `${String(index)}:${href}`)) });
|
|
492
|
+
}
|
|
493
|
+
function Menu({ props, mediaOrigin, editMode }) {
|
|
494
|
+
const design = _ui.useSiteDesign.call(void 0, );
|
|
495
|
+
const listId = _react.useId.call(void 0, );
|
|
496
|
+
const toggle = _react.useRef.call(void 0, null);
|
|
497
|
+
const [open, setOpen] = _react.useState.call(void 0, false);
|
|
498
|
+
const name = _nullishCoalesce(str(props.menu), () => ( "header"));
|
|
499
|
+
const layout = oneOf(props.layout, LAYOUTS, "horizontal");
|
|
500
|
+
const menus = _optionalChain([design, 'optionalAccess', _29 => _29.menus]);
|
|
501
|
+
const items = menus !== void 0 && Object.hasOwn(menus, name) ? menus[name] : void 0;
|
|
502
|
+
const strings = _optionalChain([design, 'optionalAccess', _30 => _30.strings]);
|
|
503
|
+
const label = _nullishCoalesce((strings !== void 0 && Object.hasOwn(strings, "nav.menu") ? str(strings["nav.menu"]) : void 0), () => ( _builderschema.SITE_STRING_DEFAULTS["nav.menu"]));
|
|
504
|
+
if (items === void 0 || items.length === 0) {
|
|
505
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
506
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, BasicStyles, {}),
|
|
507
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, Placeholder, { editMode, children: `Menu "${name}" is empty: add links in Site settings` })
|
|
508
|
+
] });
|
|
509
|
+
}
|
|
510
|
+
const drawer = layout === "drawer-on-phone";
|
|
511
|
+
const onKeyDown = (event) => {
|
|
512
|
+
if (event.key === "Escape" && open) {
|
|
513
|
+
setOpen(false);
|
|
514
|
+
_optionalChain([toggle, 'access', _31 => _31.current, 'optionalAccess', _32 => _32.focus, 'call', _33 => _33()]);
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
518
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, BasicStyles, {}),
|
|
519
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
520
|
+
"nav",
|
|
521
|
+
{
|
|
522
|
+
className: `tb-b-menu tb-b-menu--${layout}${layout === "vertical" ? "" : " tb-b-menu--h"}`,
|
|
523
|
+
"aria-label": label,
|
|
524
|
+
"data-open": drawer ? String(open) : void 0,
|
|
525
|
+
onKeyDown: drawer ? onKeyDown : void 0,
|
|
526
|
+
children: [
|
|
527
|
+
drawer && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
528
|
+
"button",
|
|
529
|
+
{
|
|
530
|
+
ref: toggle,
|
|
531
|
+
type: "button",
|
|
532
|
+
className: "tb-b-menu-toggle",
|
|
533
|
+
"aria-expanded": open,
|
|
534
|
+
"aria-controls": listId,
|
|
535
|
+
onClick: () => setOpen((value) => !value),
|
|
536
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _ui.Icon, { name: open ? "close" : "menu", size: 24, label })
|
|
537
|
+
}
|
|
538
|
+
),
|
|
539
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, List, { items, mediaOrigin, id: listId, ...drawer ? { onNavigate: () => setOpen(false) } : {} })
|
|
540
|
+
]
|
|
541
|
+
}
|
|
542
|
+
)
|
|
543
|
+
] });
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
// src/basics/spacer.tsx
|
|
547
|
+
|
|
548
|
+
function Spacer() {
|
|
549
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
550
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, BasicStyles, {}),
|
|
551
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "tb-b-spacer", "aria-hidden": "true" })
|
|
552
|
+
] });
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
// src/basics/rich-text.tsx
|
|
556
|
+
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
var ALLOWED = /* @__PURE__ */ new Set(["p", "br", "strong", "em", "u", "s", "a", "ul", "ol", "li", "h2", "h3", "h4", "blockquote", "code"]);
|
|
560
|
+
var ALIAS = { b: "strong", i: "em", strike: "s", del: "s" };
|
|
561
|
+
var DROP_WITH_CONTENT = /* @__PURE__ */ new Set([
|
|
562
|
+
"script",
|
|
563
|
+
"style",
|
|
564
|
+
"iframe",
|
|
565
|
+
"object",
|
|
566
|
+
"embed",
|
|
567
|
+
"noscript",
|
|
568
|
+
"template",
|
|
569
|
+
"textarea",
|
|
570
|
+
"title",
|
|
571
|
+
"head",
|
|
572
|
+
"xml",
|
|
573
|
+
"svg",
|
|
574
|
+
"math",
|
|
575
|
+
"noembed",
|
|
576
|
+
"noframes",
|
|
577
|
+
"xmp"
|
|
578
|
+
]);
|
|
579
|
+
var VOID = /* @__PURE__ */ new Set(["br"]);
|
|
580
|
+
var BLOCK = /* @__PURE__ */ new Set(["p", "h2", "h3", "h4", "ul", "ol", "blockquote"]);
|
|
581
|
+
var TEXT_BLOCK = /* @__PURE__ */ new Set(["p", "h2", "h3", "h4"]);
|
|
582
|
+
var MAX_LENGTH = 2e4;
|
|
583
|
+
var MAX_DEPTH2 = 24;
|
|
584
|
+
var MAX_NODES = 4e3;
|
|
585
|
+
var NAMED = {
|
|
586
|
+
amp: "&",
|
|
587
|
+
lt: "<",
|
|
588
|
+
gt: ">",
|
|
589
|
+
quot: '"',
|
|
590
|
+
apos: "'",
|
|
591
|
+
nbsp: "\xA0",
|
|
592
|
+
copy: "\xA9",
|
|
593
|
+
reg: "\xAE",
|
|
594
|
+
trade: "\u2122",
|
|
595
|
+
mdash: "\u2014",
|
|
596
|
+
ndash: "\u2013",
|
|
597
|
+
hellip: "\u2026",
|
|
598
|
+
lsquo: "\u2018",
|
|
599
|
+
rsquo: "\u2019",
|
|
600
|
+
ldquo: "\u201C",
|
|
601
|
+
rdquo: "\u201D",
|
|
602
|
+
euro: "\u20AC",
|
|
603
|
+
pound: "\xA3"
|
|
604
|
+
};
|
|
605
|
+
function decode(value) {
|
|
606
|
+
return value.replace(/&(?:#x([0-9a-f]{1,6})|#(\d{1,7})|([a-z]{2,8}));/gi, (whole, hex, dec, name) => {
|
|
607
|
+
if (name !== void 0) return Object.hasOwn(NAMED, name.toLowerCase()) ? NAMED[name.toLowerCase()] : whole;
|
|
608
|
+
const code = hex !== void 0 ? Number.parseInt(hex, 16) : Number.parseInt(_nullishCoalesce(dec, () => ( "")), 10);
|
|
609
|
+
return code > 0 && code <= 1114111 && !(code >= 55296 && code <= 57343) ? String.fromCodePoint(code) : "";
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
var TAG_NAME = /[a-z][a-z0-9:_-]*/iy;
|
|
613
|
+
function readTag(html, start) {
|
|
614
|
+
const attrs = /* @__PURE__ */ new Map();
|
|
615
|
+
let i = start;
|
|
616
|
+
for (; ; ) {
|
|
617
|
+
while (i < html.length && /[\s/]/.test(html[i])) i += 1;
|
|
618
|
+
if (i >= html.length) return null;
|
|
619
|
+
if (html[i] === ">") return { attrs, end: i + 1, selfClosing: /\/\s*$/.test(html.slice(start, i)) };
|
|
620
|
+
let name = "";
|
|
621
|
+
while (i < html.length && !/[\s=/>]/.test(html[i])) name += html[i++];
|
|
622
|
+
while (i < html.length && /\s/.test(html[i])) i += 1;
|
|
623
|
+
let value = "";
|
|
624
|
+
if (html[i] === "=") {
|
|
625
|
+
i += 1;
|
|
626
|
+
while (i < html.length && /\s/.test(html[i])) i += 1;
|
|
627
|
+
const quote = html[i];
|
|
628
|
+
if (quote === '"' || quote === "'") {
|
|
629
|
+
const close = html.indexOf(quote, i + 1);
|
|
630
|
+
if (close === -1) return null;
|
|
631
|
+
value = html.slice(i + 1, close);
|
|
632
|
+
i = close + 1;
|
|
633
|
+
} else {
|
|
634
|
+
while (i < html.length && !/[\s>]/.test(html[i])) value += html[i++];
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
const key = name.toLowerCase();
|
|
638
|
+
if (key !== "" && !attrs.has(key)) attrs.set(key, value);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
function parseRichText(source, mediaOrigin) {
|
|
642
|
+
const html = source.slice(0, MAX_LENGTH);
|
|
643
|
+
const root = { tag: "#root", children: [], ...source.length > MAX_LENGTH ? { truncated: true } : {} };
|
|
644
|
+
const stack = [root];
|
|
645
|
+
const top = () => stack[stack.length - 1];
|
|
646
|
+
let nodes = 0;
|
|
647
|
+
const text2 = (value) => {
|
|
648
|
+
if (value === "" || nodes > MAX_NODES) return;
|
|
649
|
+
nodes += 1;
|
|
650
|
+
const parent = top();
|
|
651
|
+
const last = parent.children[parent.children.length - 1];
|
|
652
|
+
if (typeof last === "string") parent.children[parent.children.length - 1] = last + value;
|
|
653
|
+
else parent.children.push(value);
|
|
654
|
+
};
|
|
655
|
+
const closeTo = (tag) => {
|
|
656
|
+
const at = stack.map((e) => e.tag).lastIndexOf(tag);
|
|
657
|
+
if (at > 0) stack.length = at;
|
|
658
|
+
};
|
|
659
|
+
let i = 0;
|
|
660
|
+
while (i < html.length && nodes <= MAX_NODES) {
|
|
661
|
+
const lt = html.indexOf("<", i);
|
|
662
|
+
if (lt === -1) {
|
|
663
|
+
text2(decode(html.slice(i)));
|
|
664
|
+
break;
|
|
665
|
+
}
|
|
666
|
+
text2(decode(html.slice(i, lt)));
|
|
667
|
+
i = lt;
|
|
668
|
+
if (html.startsWith("<!--", i)) {
|
|
669
|
+
const close = html.indexOf("-->", i + 4);
|
|
670
|
+
i = close === -1 ? html.length : close + 3;
|
|
671
|
+
continue;
|
|
672
|
+
}
|
|
673
|
+
const closing = html[i + 1] === "/";
|
|
674
|
+
const nameStart = i + (closing ? 2 : 1);
|
|
675
|
+
TAG_NAME.lastIndex = nameStart;
|
|
676
|
+
const raw = _optionalChain([TAG_NAME, 'access', _34 => _34.exec, 'call', _35 => _35(html), 'optionalAccess', _36 => _36[0], 'optionalAccess', _37 => _37.toLowerCase, 'call', _38 => _38()]);
|
|
677
|
+
if (raw === void 0) {
|
|
678
|
+
if (html[i + 1] === "!" || html[i + 1] === "?") {
|
|
679
|
+
const close = html.indexOf(">", i);
|
|
680
|
+
i = close === -1 ? html.length : close + 1;
|
|
681
|
+
} else {
|
|
682
|
+
text2("<");
|
|
683
|
+
i += 1;
|
|
684
|
+
}
|
|
685
|
+
continue;
|
|
686
|
+
}
|
|
687
|
+
const tag = readTag(html, nameStart + raw.length);
|
|
688
|
+
if (tag === null) {
|
|
689
|
+
root.truncated = true;
|
|
690
|
+
break;
|
|
691
|
+
}
|
|
692
|
+
i = tag.end;
|
|
693
|
+
const name = Object.hasOwn(ALIAS, raw) ? ALIAS[raw] : raw;
|
|
694
|
+
if (closing) {
|
|
695
|
+
if (ALLOWED.has(name)) closeTo(name);
|
|
696
|
+
continue;
|
|
697
|
+
}
|
|
698
|
+
if (DROP_WITH_CONTENT.has(raw)) {
|
|
699
|
+
if (!tag.selfClosing) {
|
|
700
|
+
const close = new RegExp(`</${raw}\\s*>`, "ig");
|
|
701
|
+
close.lastIndex = i;
|
|
702
|
+
const found = close.exec(html);
|
|
703
|
+
i = found === null ? html.length : found.index + found[0].length;
|
|
704
|
+
}
|
|
705
|
+
continue;
|
|
706
|
+
}
|
|
707
|
+
if (!ALLOWED.has(name)) continue;
|
|
708
|
+
if (BLOCK.has(name)) {
|
|
709
|
+
for (let at = stack.length - 1; at > 0; at -= 1) {
|
|
710
|
+
if (TEXT_BLOCK.has(stack[at].tag)) {
|
|
711
|
+
stack.length = at;
|
|
712
|
+
break;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
if (name === "li") {
|
|
717
|
+
let list = stack.length - 1;
|
|
718
|
+
while (list > 0 && stack[list].tag !== "ul" && stack[list].tag !== "ol") list -= 1;
|
|
719
|
+
if (list === 0) list = -1;
|
|
720
|
+
if (list === -1) continue;
|
|
721
|
+
stack.length = list + 1;
|
|
722
|
+
}
|
|
723
|
+
if (name === "a") closeTo("a");
|
|
724
|
+
const el = { tag: name, children: [] };
|
|
725
|
+
if (name === "a") {
|
|
726
|
+
const href = tag.attrs.get("href");
|
|
727
|
+
el.href = href === void 0 ? null : _builderschema.safeUrl.call(void 0, decode(href).trim(), "href", { mediaOrigin });
|
|
728
|
+
}
|
|
729
|
+
nodes += 1;
|
|
730
|
+
top().children.push(el);
|
|
731
|
+
if (!VOID.has(name) && stack.length < MAX_DEPTH2) stack.push(el);
|
|
732
|
+
}
|
|
733
|
+
if (nodes > MAX_NODES) root.truncated = true;
|
|
734
|
+
return root;
|
|
735
|
+
}
|
|
736
|
+
function toReact(el, key) {
|
|
737
|
+
const children = el.children.map((child, index) => typeof child === "string" ? child : toReact(child, index));
|
|
738
|
+
if (el.tag === "br") return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "br", {}, key);
|
|
739
|
+
if (el.tag === "a") {
|
|
740
|
+
if (el.href === null || el.href === void 0) return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Fragment, { children }, key);
|
|
741
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "a", { href: el.href, rel: "noopener noreferrer", className: "tb-b-link", children }, key);
|
|
742
|
+
}
|
|
743
|
+
return _react.createElement.call(void 0, el.tag, { key }, ...children);
|
|
744
|
+
}
|
|
745
|
+
function RichText({
|
|
746
|
+
html,
|
|
747
|
+
mediaOrigin,
|
|
748
|
+
className,
|
|
749
|
+
editMode = false
|
|
750
|
+
}) {
|
|
751
|
+
const tree = parseRichText(html, mediaOrigin);
|
|
752
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className, children: [
|
|
753
|
+
tree.children.map((child, index) => typeof child === "string" ? child : toReact(child, index)),
|
|
754
|
+
editMode && tree.truncated === true && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "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." })
|
|
755
|
+
] });
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
// src/basics/text.tsx
|
|
759
|
+
|
|
760
|
+
function Text({ props, mediaOrigin, editMode, inlineEdit }) {
|
|
761
|
+
const editor = _nullishCoalesce(_optionalChain([inlineEdit, 'optionalCall', _39 => _39("html")]), () => ( null));
|
|
762
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
763
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, BasicStyles, {}),
|
|
764
|
+
editor === null ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, RichText, { html: _nullishCoalesce(str(props.html), () => ( "")), mediaOrigin, className: "tb-b-text", editMode }) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "tb-b-text", children: editor })
|
|
765
|
+
] });
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
// src/basics/video.tsx
|
|
769
|
+
|
|
770
|
+
|
|
771
|
+
|
|
772
|
+
var RULES3 = [
|
|
773
|
+
{ key: "ratio", property: "--bx-ratio", values: { "16:9": "16 / 9", "4:3": "4 / 3", "1:1": "1 / 1", "9:16": "9 / 16" } }
|
|
774
|
+
];
|
|
775
|
+
var YOUTUBE_ID = /^[A-Za-z0-9_-]{11}$/;
|
|
776
|
+
var VIMEO_ID = /^\d{5,12}$/;
|
|
777
|
+
var YOUTUBE_HOSTS = /* @__PURE__ */ new Set(["youtube.com", "www.youtube.com", "m.youtube.com", "youtube-nocookie.com", "www.youtube-nocookie.com"]);
|
|
778
|
+
var VIMEO_HOSTS = /* @__PURE__ */ new Set(["vimeo.com", "www.vimeo.com", "player.vimeo.com"]);
|
|
779
|
+
function parseVideoUrl(input) {
|
|
780
|
+
let url;
|
|
781
|
+
try {
|
|
782
|
+
url = new URL(input.trim());
|
|
783
|
+
} catch (e4) {
|
|
784
|
+
return null;
|
|
785
|
+
}
|
|
786
|
+
if (url.protocol !== "https:" || url.username !== "" || url.password !== "" || url.port !== "" && url.port !== "443") return null;
|
|
787
|
+
const host = url.hostname.toLowerCase();
|
|
788
|
+
const parts = url.pathname.split("/").filter((part) => part !== "");
|
|
789
|
+
if (host === "youtu.be") {
|
|
790
|
+
const id = parts[0];
|
|
791
|
+
return parts.length === 1 && id !== void 0 && YOUTUBE_ID.test(id) ? { provider: "youtube", id } : null;
|
|
792
|
+
}
|
|
793
|
+
if (YOUTUBE_HOSTS.has(host)) {
|
|
794
|
+
if (parts[0] === "watch" && parts.length === 1) {
|
|
795
|
+
const id2 = url.searchParams.get("v");
|
|
796
|
+
return id2 !== null && YOUTUBE_ID.test(id2) ? { provider: "youtube", id: id2 } : null;
|
|
797
|
+
}
|
|
798
|
+
const id = parts[1];
|
|
799
|
+
return (parts[0] === "embed" || parts[0] === "shorts" || parts[0] === "live") && parts.length === 2 && id !== void 0 && YOUTUBE_ID.test(id) ? { provider: "youtube", id } : null;
|
|
800
|
+
}
|
|
801
|
+
if (VIMEO_HOSTS.has(host)) {
|
|
802
|
+
const id = host === "player.vimeo.com" ? parts[0] === "video" && parts.length === 2 ? parts[1] : void 0 : parts.length === 1 ? parts[0] : void 0;
|
|
803
|
+
return id !== void 0 && VIMEO_ID.test(id) ? { provider: "vimeo", id } : null;
|
|
804
|
+
}
|
|
805
|
+
return null;
|
|
806
|
+
}
|
|
807
|
+
function embedSrc(video, muted) {
|
|
808
|
+
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" : ""}`;
|
|
809
|
+
}
|
|
810
|
+
function Video({ node, props, editMode }) {
|
|
811
|
+
const [loaded, setLoaded] = _react.useState.call(void 0, false);
|
|
812
|
+
const video = parseVideoUrl(_nullishCoalesce(str(props.url), () => ( "")));
|
|
813
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
814
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, BasicStyles, {}),
|
|
815
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, WidgetStyle, { css: enumCss(node, RULES3) }),
|
|
816
|
+
video === null ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Placeholder, { editMode, children: "Paste a YouTube or Vimeo link" }) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "tb-b-video", "data-provider": video.provider, children: loaded && !editMode ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
817
|
+
"iframe",
|
|
818
|
+
{
|
|
819
|
+
src: embedSrc(video, props.autoplayMuted === true),
|
|
820
|
+
title: "Video",
|
|
821
|
+
allow: "autoplay; encrypted-media; picture-in-picture; fullscreen",
|
|
822
|
+
referrerPolicy: "strict-origin-when-cross-origin",
|
|
823
|
+
sandbox: "allow-scripts allow-same-origin allow-presentation allow-popups"
|
|
824
|
+
}
|
|
825
|
+
) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "button", { type: "button", className: "tb-b-play", "aria-label": "Play video", onClick: () => setLoaded(true), children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _ui.Icon, { name: "play", size: 28 }) }) }) })
|
|
826
|
+
] });
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
// src/basics/index.ts
|
|
830
|
+
var BASIC_COMPONENTS = {
|
|
831
|
+
"basic.heading": Heading,
|
|
832
|
+
"basic.text": Text,
|
|
833
|
+
"basic.image": Image,
|
|
834
|
+
"basic.button": Button,
|
|
835
|
+
"basic.spacer": Spacer,
|
|
836
|
+
"basic.divider": Divider,
|
|
837
|
+
"basic.video": Video,
|
|
838
|
+
"basic.logo": Logo,
|
|
839
|
+
"basic.menu": Menu,
|
|
840
|
+
"basic.announcement": Announcement,
|
|
841
|
+
"basic.copyright": Copyright
|
|
842
|
+
};
|
|
843
|
+
var widgets = _builderschema.BASIC_WIDGET_DEFINITIONS.flatMap(
|
|
844
|
+
(definition) => Object.hasOwn(BASIC_COMPONENTS, definition.type) ? [{ ...definition, Component: BASIC_COMPONENTS[definition.type] }] : []
|
|
845
|
+
);
|
|
846
|
+
var basicPack = { id: "basic", version: "0.0.0", widgets, dataSources: [] };
|
|
847
|
+
|
|
848
|
+
// src/custom/factory.ts
|
|
849
|
+
|
|
850
|
+
|
|
851
|
+
// src/custom/composite-widget.tsx
|
|
852
|
+
|
|
853
|
+
|
|
854
|
+
|
|
855
|
+
// src/budget.ts
|
|
856
|
+
|
|
857
|
+
var MAX_RENDERED_NODES = _builderschema.MAX_TEMPLATE_WEIGHT;
|
|
858
|
+
var RenderBudget = class {
|
|
859
|
+
constructor(limit = MAX_RENDERED_NODES) {
|
|
860
|
+
this.limit = limit;
|
|
861
|
+
__publicField(this, "spent", 0);
|
|
862
|
+
}
|
|
863
|
+
/** Takes `count` nodes. False, and nothing taken, when that would pass the limit. */
|
|
864
|
+
take(count = 1) {
|
|
865
|
+
if (this.spent + count > this.limit) return false;
|
|
866
|
+
this.spent += count;
|
|
867
|
+
return true;
|
|
868
|
+
}
|
|
869
|
+
get used() {
|
|
870
|
+
return this.spent;
|
|
871
|
+
}
|
|
872
|
+
get exhausted() {
|
|
873
|
+
return this.spent >= this.limit;
|
|
874
|
+
}
|
|
875
|
+
};
|
|
876
|
+
var fitsBudget = (ast, limit = MAX_RENDERED_NODES) => _builderschema.templateWeight.call(void 0, ast) <= limit;
|
|
877
|
+
|
|
878
|
+
// src/part-view.tsx
|
|
879
|
+
|
|
880
|
+
|
|
881
|
+
// src/renderer.tsx
|
|
882
|
+
|
|
883
|
+
|
|
884
|
+
|
|
885
|
+
|
|
886
|
+
|
|
887
|
+
|
|
888
|
+
|
|
889
|
+
|
|
890
|
+
|
|
891
|
+
// src/css-compiler.ts
|
|
892
|
+
|
|
893
|
+
|
|
894
|
+
|
|
895
|
+
|
|
896
|
+
|
|
897
|
+
|
|
898
|
+
|
|
899
|
+
|
|
900
|
+
var TABLET_QUERY = "(max-width:1024px)";
|
|
901
|
+
var PHONE_QUERY = "(max-width:767px)";
|
|
902
|
+
var SAFE_VALUE = /^[A-Za-z0-9#%.,()\-+*/_: ]{1,200}$/;
|
|
903
|
+
var URL_QUOTE_SAFE = /^[^\s"'\\()<>{};]+$/;
|
|
904
|
+
var ID_RE2 = /^[a-z0-9]{8,24}$/;
|
|
905
|
+
var PROPERTY_RE = /^--(?:b|w|tb)-[A-Za-z][A-Za-z0-9-]{0,39}$/;
|
|
906
|
+
var COLOR_TOKEN = /* @__PURE__ */ new Set([
|
|
907
|
+
"primary",
|
|
908
|
+
"primary-foreground",
|
|
909
|
+
"background",
|
|
910
|
+
"surface",
|
|
911
|
+
"foreground",
|
|
912
|
+
"muted",
|
|
913
|
+
"muted-foreground",
|
|
914
|
+
"border",
|
|
915
|
+
"border-control",
|
|
916
|
+
"accent",
|
|
917
|
+
"sale",
|
|
918
|
+
"success",
|
|
919
|
+
"warning",
|
|
920
|
+
"danger"
|
|
921
|
+
]);
|
|
922
|
+
var SPACING_TOKEN = /* @__PURE__ */ new Set(["xs", "s", "m", "l", "xl", "2xl"]);
|
|
923
|
+
var SIZE_TOKEN = /* @__PURE__ */ new Set(["xs", "s", "m", "l", "xl", "2xl", "3xl"]);
|
|
924
|
+
var ALIGN = /* @__PURE__ */ new Set(["left", "center", "right", "justify"]);
|
|
925
|
+
var SELECT_OPTION = /^[a-z0-9][a-z0-9:-]{0,39}$/;
|
|
926
|
+
var px = (value) => `${String(Math.round(value * 100) / 100)}px`;
|
|
927
|
+
function colour(value) {
|
|
928
|
+
if (typeof value !== "string") return null;
|
|
929
|
+
if (value.startsWith("token:")) {
|
|
930
|
+
const name = value.slice(6);
|
|
931
|
+
return COLOR_TOKEN.has(name) ? `var(--tb-color-${name})` : null;
|
|
932
|
+
}
|
|
933
|
+
return /^#[0-9a-fA-F]{6}(?:[0-9a-fA-F]{2})?$/.test(value) ? value : null;
|
|
934
|
+
}
|
|
935
|
+
function spacing(value) {
|
|
936
|
+
if (value === "none") return "0px";
|
|
937
|
+
if (typeof value === "string") return SPACING_TOKEN.has(value) ? `var(--tb-space-${value})` : null;
|
|
938
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0 && value <= 400 ? px(value) : null;
|
|
939
|
+
}
|
|
940
|
+
function fontSize(value) {
|
|
941
|
+
if (typeof value === "string") return SIZE_TOKEN.has(value) ? `var(--tb-text-${value})` : null;
|
|
942
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 8 && value <= 200 ? px(value) : null;
|
|
943
|
+
}
|
|
944
|
+
function cssValue(control, value) {
|
|
945
|
+
switch (control) {
|
|
946
|
+
case "color":
|
|
947
|
+
return colour(value);
|
|
948
|
+
case "spacing":
|
|
949
|
+
return spacing(value);
|
|
950
|
+
case "font-size":
|
|
951
|
+
return fontSize(value);
|
|
952
|
+
case "alignment":
|
|
953
|
+
return typeof value === "string" && ALIGN.has(value) ? value : null;
|
|
954
|
+
case "number":
|
|
955
|
+
return typeof value === "number" && Number.isFinite(value) ? String(value) : null;
|
|
956
|
+
case "toggle":
|
|
957
|
+
return typeof value === "boolean" ? value ? "1" : "0" : null;
|
|
958
|
+
case "select":
|
|
959
|
+
return typeof value === "string" && SELECT_OPTION.test(value) ? value : null;
|
|
960
|
+
default:
|
|
961
|
+
return null;
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
function put(out, property, value) {
|
|
965
|
+
if (value === null) return;
|
|
966
|
+
if (!PROPERTY_RE.test(property) || !SAFE_VALUE.test(value)) {
|
|
967
|
+
if (isDevelopment()) warnOnce(`css:${property}`, `Dropped an unsafe value for ${property}`);
|
|
968
|
+
return;
|
|
969
|
+
}
|
|
970
|
+
out.set(property, value);
|
|
971
|
+
}
|
|
972
|
+
var COMMON_BY_KEY = new Map(_builderschema.COMMON_WIDGET_SETTINGS.map((field) => [field.key, field]));
|
|
973
|
+
function widgetDecls(node, device, registry) {
|
|
974
|
+
const out = /* @__PURE__ */ new Map();
|
|
975
|
+
const def = registry.widget(node.type, node.v);
|
|
976
|
+
if (def === void 0) return out;
|
|
977
|
+
const fields = new Map([...COMMON_BY_KEY, ...def.settings.map((f) => [f.key, f])]);
|
|
978
|
+
const defaults = {};
|
|
979
|
+
for (const field of fields.values()) if (field.output === "css") defaults[field.key] = field.default;
|
|
980
|
+
const resolved = _builderschema.resolveResponsive.call(void 0, { ...defaults, ...node.props }, node.responsive, device);
|
|
981
|
+
const prefix = node.type.startsWith("custom.") ? "--w-" : "--b-";
|
|
982
|
+
for (const field of fields.values()) {
|
|
983
|
+
if (field.output !== "css") continue;
|
|
984
|
+
const value = resolved[field.key];
|
|
985
|
+
if (value === null || value === void 0) continue;
|
|
986
|
+
if (field.key === "hidden") {
|
|
987
|
+
if (value === true) put(out, "--tb-hide", "none");
|
|
988
|
+
continue;
|
|
989
|
+
}
|
|
990
|
+
put(out, `${prefix}${field.key}`, cssValue(field.control, value));
|
|
991
|
+
}
|
|
992
|
+
return out;
|
|
993
|
+
}
|
|
994
|
+
var ALIGN_ITEMS = { top: "flex-start", center: "center", bottom: "flex-end", stretch: "stretch" };
|
|
995
|
+
var BG_POSITION = /* @__PURE__ */ new Set(["center", "top", "bottom", "left", "right", "top left", "top right", "bottom left", "bottom right"]);
|
|
996
|
+
var BG_SIZE = /* @__PURE__ */ new Set(["cover", "contain", "auto"]);
|
|
997
|
+
function backgroundDecls(out, bg, assets, mediaOrigin) {
|
|
998
|
+
if (bg === void 0) return;
|
|
999
|
+
put(out, "--tb-bg", bg.color === void 0 ? null : colour(bg.color));
|
|
1000
|
+
put(out, "--tb-overlay", bg.overlay === void 0 ? null : colour(bg.overlay));
|
|
1001
|
+
if (bg.position !== void 0 && BG_POSITION.has(bg.position)) put(out, "--tb-bgpos", bg.position);
|
|
1002
|
+
if (bg.size !== void 0 && BG_SIZE.has(bg.size)) put(out, "--tb-bgsize", bg.size);
|
|
1003
|
+
const asset = bg.image === void 0 || assets === void 0 || !Object.hasOwn(assets, bg.image) ? void 0 : assets[bg.image];
|
|
1004
|
+
if (asset !== void 0 && _builderschema.safeUrl.call(void 0, asset.url, "src", { mediaOrigin }) !== null && URL_QUOTE_SAFE.test(asset.url)) {
|
|
1005
|
+
out.set("--tb-bgimg", `url("${asset.url}")`);
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
function sectionDecls(section, device, assets, mediaOrigin) {
|
|
1009
|
+
const out = /* @__PURE__ */ new Map();
|
|
1010
|
+
const p = _builderschema.resolveResponsive.call(void 0, section.props, section.responsive, device);
|
|
1011
|
+
if (p.hidden === true) put(out, "--tb-hide", "none");
|
|
1012
|
+
const full = p.width === "full";
|
|
1013
|
+
put(out, "--tb-maxw", full ? "none" : px(typeof p.contentWidth === "number" ? p.contentWidth : 1200));
|
|
1014
|
+
put(out, "--tb-gap", p.gap === void 0 ? null : spacing(p.gap));
|
|
1015
|
+
put(out, "--tb-pady", p.paddingY === void 0 ? null : spacing(p.paddingY));
|
|
1016
|
+
put(out, "--tb-padx", p.paddingX === void 0 ? null : spacing(p.paddingX));
|
|
1017
|
+
if (typeof p.minHeight === "number" && p.minHeight > 0 && p.minHeight <= 2e3) put(out, "--tb-minh", px(p.minHeight));
|
|
1018
|
+
if (typeof p.verticalAlign === "string" && Object.hasOwn(ALIGN_ITEMS, p.verticalAlign)) put(out, "--tb-valign", ALIGN_ITEMS[p.verticalAlign]);
|
|
1019
|
+
backgroundDecls(out, p.background, assets, mediaOrigin);
|
|
1020
|
+
const widths = _builderschema.resolveColumnWidths.call(void 0, section, device);
|
|
1021
|
+
const rows = _builderschema.wrapColumnRows.call(void 0, widths);
|
|
1022
|
+
const stacked = rows.every((row) => row.length === 1);
|
|
1023
|
+
put(out, "--tb-flow", stacked && p.stackOrder === "reverse" ? "column-reverse nowrap" : "row wrap");
|
|
1024
|
+
return out;
|
|
1025
|
+
}
|
|
1026
|
+
function columnWidthDecls(section, device) {
|
|
1027
|
+
const widths = _builderschema.resolveColumnWidths.call(void 0, section, device);
|
|
1028
|
+
const result = section.columns.map(() => /* @__PURE__ */ new Map());
|
|
1029
|
+
for (const row of _builderschema.wrapColumnRows.call(void 0, widths)) {
|
|
1030
|
+
for (const index of row) {
|
|
1031
|
+
put(result[index], "--tb-cw", String(Math.round(widths[index] / 100 * 1e4) / 1e4));
|
|
1032
|
+
put(result[index], "--tb-cn", String(row.length - 1));
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
return result;
|
|
1036
|
+
}
|
|
1037
|
+
function columnDecls(section, index, device, assets, mediaOrigin, widths) {
|
|
1038
|
+
const column = section.columns[index];
|
|
1039
|
+
const out = new Map(widths);
|
|
1040
|
+
const p = _builderschema.resolveColumnProps.call(void 0, column.props, column.responsive, device);
|
|
1041
|
+
if (p.hidden === true) put(out, "--tb-hide", "none");
|
|
1042
|
+
if (typeof p.verticalAlign === "string" && Object.hasOwn(ALIGN_ITEMS, p.verticalAlign)) put(out, "--tb-self", ALIGN_ITEMS[p.verticalAlign]);
|
|
1043
|
+
put(out, "--tb-pad", p.padding === void 0 ? null : spacing(p.padding));
|
|
1044
|
+
backgroundDecls(out, p.background, assets, mediaOrigin);
|
|
1045
|
+
return out;
|
|
1046
|
+
}
|
|
1047
|
+
function collect(doc, registry, assets, mediaOrigin) {
|
|
1048
|
+
const nodes = [];
|
|
1049
|
+
const widget = (node) => {
|
|
1050
|
+
if (!ID_RE2.test(node.id)) return;
|
|
1051
|
+
nodes.push({
|
|
1052
|
+
id: node.id,
|
|
1053
|
+
decls: {
|
|
1054
|
+
desktop: widgetDecls(node, "desktop", registry),
|
|
1055
|
+
tablet: widgetDecls(node, "tablet", registry),
|
|
1056
|
+
phone: widgetDecls(node, "phone", registry)
|
|
1057
|
+
}
|
|
1058
|
+
});
|
|
1059
|
+
};
|
|
1060
|
+
const section = (node) => {
|
|
1061
|
+
if (ID_RE2.test(node.id)) {
|
|
1062
|
+
nodes.push({
|
|
1063
|
+
id: node.id,
|
|
1064
|
+
decls: {
|
|
1065
|
+
desktop: sectionDecls(node, "desktop", assets, mediaOrigin),
|
|
1066
|
+
tablet: sectionDecls(node, "tablet", assets, mediaOrigin),
|
|
1067
|
+
phone: sectionDecls(node, "phone", assets, mediaOrigin)
|
|
1068
|
+
}
|
|
1069
|
+
});
|
|
1070
|
+
}
|
|
1071
|
+
const widths = { desktop: columnWidthDecls(node, "desktop"), tablet: columnWidthDecls(node, "tablet"), phone: columnWidthDecls(node, "phone") };
|
|
1072
|
+
node.columns.forEach((column, index) => {
|
|
1073
|
+
if (ID_RE2.test(column.id)) {
|
|
1074
|
+
nodes.push({
|
|
1075
|
+
id: column.id,
|
|
1076
|
+
decls: {
|
|
1077
|
+
desktop: columnDecls(node, index, "desktop", assets, mediaOrigin, widths.desktop[index]),
|
|
1078
|
+
tablet: columnDecls(node, index, "tablet", assets, mediaOrigin, widths.tablet[index]),
|
|
1079
|
+
phone: columnDecls(node, index, "phone", assets, mediaOrigin, widths.phone[index])
|
|
1080
|
+
}
|
|
1081
|
+
});
|
|
1082
|
+
}
|
|
1083
|
+
for (const child of column.children) {
|
|
1084
|
+
if (child.type === "inner-section") section(child);
|
|
1085
|
+
else widget(child);
|
|
1086
|
+
}
|
|
1087
|
+
});
|
|
1088
|
+
};
|
|
1089
|
+
doc.sections.forEach(section);
|
|
1090
|
+
return nodes;
|
|
1091
|
+
}
|
|
1092
|
+
var block = (id, decls) => {
|
|
1093
|
+
const body = [...decls].map(([property, value]) => `${property}:${value}`).join(";");
|
|
1094
|
+
return body === "" ? "" : `[data-b-id="${id}"]{${body}}`;
|
|
1095
|
+
};
|
|
1096
|
+
function changed(prev, next) {
|
|
1097
|
+
const out = [...next].filter(([property, value]) => prev.get(property) !== value);
|
|
1098
|
+
for (const property of prev.keys()) if (!next.has(property)) out.push([property, "initial"]);
|
|
1099
|
+
return out;
|
|
1100
|
+
}
|
|
1101
|
+
function compileResponsiveCss(doc, registry, assets = doc.assets, mediaOrigin = "") {
|
|
1102
|
+
const nodes = collect(doc, registry, assets, mediaOrigin);
|
|
1103
|
+
const base = nodes.map((n) => block(n.id, n.decls.desktop)).join("");
|
|
1104
|
+
const tablet = nodes.map((n) => block(n.id, changed(n.decls.desktop, n.decls.tablet))).join("");
|
|
1105
|
+
const phone = nodes.map((n) => block(n.id, changed(n.decls.tablet, n.decls.phone))).join("");
|
|
1106
|
+
return base + (tablet === "" ? "" : `@media ${TABLET_QUERY}{${tablet}}`) + (phone === "" ? "" : `@media ${PHONE_QUERY}{${phone}}`);
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
// src/node-wrapper.tsx
|
|
1110
|
+
|
|
1111
|
+
|
|
1112
|
+
var CUSTOM_WIDGET_CONTAINMENT = {
|
|
1113
|
+
contain: "layout paint",
|
|
1114
|
+
isolation: "isolate",
|
|
1115
|
+
overflow: "clip"
|
|
1116
|
+
};
|
|
1117
|
+
var PART_NAME = {
|
|
1118
|
+
section: "builder-section",
|
|
1119
|
+
column: "builder-column",
|
|
1120
|
+
widget: "builder-widget"
|
|
1121
|
+
};
|
|
1122
|
+
function NodeWrapper(props) {
|
|
1123
|
+
const { id, part, type, className, anchor, custom, missing, edit, children } = props;
|
|
1124
|
+
const Tag = _nullishCoalesce(props.as, () => ( "div"));
|
|
1125
|
+
const handlers = edit === void 0 ? {} : {
|
|
1126
|
+
onClickCapture: (event) => {
|
|
1127
|
+
const target = event.target;
|
|
1128
|
+
if (_optionalChain([target, 'optionalAccess', _40 => _40.closest, 'optionalCall', _41 => _41("a[href]")]) != null) event.preventDefault();
|
|
1129
|
+
},
|
|
1130
|
+
onClick: (event) => {
|
|
1131
|
+
event.stopPropagation();
|
|
1132
|
+
edit.onSelect(id);
|
|
1133
|
+
},
|
|
1134
|
+
onMouseOver: (event) => {
|
|
1135
|
+
event.stopPropagation();
|
|
1136
|
+
edit.onHover(id);
|
|
1137
|
+
},
|
|
1138
|
+
onMouseLeave: () => edit.onHover(null)
|
|
1139
|
+
};
|
|
1140
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1141
|
+
Tag,
|
|
1142
|
+
{
|
|
1143
|
+
className,
|
|
1144
|
+
"data-b-id": id,
|
|
1145
|
+
"data-throttle-part": PART_NAME[part],
|
|
1146
|
+
...type === void 0 ? {} : { "data-b-type": type },
|
|
1147
|
+
...custom === true && type !== void 0 ? { "data-b-w": type } : {},
|
|
1148
|
+
...missing === true ? { "data-b-missing": "" } : {},
|
|
1149
|
+
...typeof anchor === "string" && _builderschema.ANCHOR_RE.test(anchor) ? { id: anchor } : {},
|
|
1150
|
+
...custom === true ? { style: CUSTOM_WIDGET_CONTAINMENT } : {},
|
|
1151
|
+
...handlers,
|
|
1152
|
+
children
|
|
1153
|
+
}
|
|
1154
|
+
);
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
// src/styles.ts
|
|
1158
|
+
var BASE_CSS = `@layer throttle{
|
|
1159
|
+
:root{--tb-scale:1;--tb-space-xs:calc(.25rem*var(--tb-scale));--tb-space-s:calc(.5rem*var(--tb-scale));--tb-space-m:calc(1rem*var(--tb-scale));--tb-space-l:calc(1.5rem*var(--tb-scale));--tb-space-xl:calc(2.5rem*var(--tb-scale));--tb-space-2xl:calc(4rem*var(--tb-scale));
|
|
1160
|
+
--tb-text-xs:.75rem;--tb-text-s:.875rem;--tb-text-m:1rem;--tb-text-l:1.25rem;--tb-text-xl:1.5rem;--tb-text-2xl:2rem;--tb-text-3xl:2.75rem}
|
|
1161
|
+
.tb-root{display:block;inline-size:100%}
|
|
1162
|
+
.tb-section,.tb-col,.tb-w{--tb-hide:initial}
|
|
1163
|
+
.tb-section,.tb-col{--tb-bg:initial;--tb-bgimg:initial;--tb-bgpos:initial;--tb-bgsize:initial;--tb-overlay:initial}
|
|
1164
|
+
.tb-section{--tb-valign:initial;--tb-minh:initial;--tb-pady:initial;--tb-padx:initial;--tb-gap:initial;--tb-maxw:initial;--tb-flow:initial}
|
|
1165
|
+
.tb-col{--tb-pad:initial;--tb-self:initial}
|
|
1166
|
+
.tb-section{box-sizing:border-box;position:relative;display:var(--tb-hide,flex);flex-direction:column;justify-content:var(--tb-valign,flex-start);min-block-size:var(--tb-minh,0px);padding-block:var(--tb-pady,0px);padding-inline:var(--tb-padx,0px);background-color:var(--tb-bg,transparent);background-image:var(--tb-bgimg,none);background-position:var(--tb-bgpos,center);background-size:var(--tb-bgsize,cover);background-repeat:no-repeat}
|
|
1167
|
+
.tb-section::before{content:"";position:absolute;inset:0;background:var(--tb-overlay,transparent);pointer-events:none}
|
|
1168
|
+
.tb-inner{box-sizing:border-box;position:relative;inline-size:100%;max-inline-size:var(--tb-maxw,1200px);margin-inline:auto}
|
|
1169
|
+
.tb-row{display:flex;flex-flow:var(--tb-flow,row wrap);gap:var(--tb-gap,0px);align-items:stretch}
|
|
1170
|
+
.tb-col{box-sizing:border-box;display:var(--tb-hide,flex);flex-direction:column;flex:0 0 auto;inline-size:calc((100% - var(--tb-cn,0)*var(--tb-gap,0px))*var(--tb-cw,1));min-inline-size:0;align-self:var(--tb-self,stretch);padding:var(--tb-pad,0px);background-color:var(--tb-bg,transparent);background-image:var(--tb-bgimg,none);background-position:var(--tb-bgpos,center);background-size:var(--tb-bgsize,cover);background-repeat:no-repeat}
|
|
1171
|
+
.tb-w{display:var(--tb-hide,block);min-inline-size:0;margin-block-start:var(--b-spacingTop,var(--w-spacingTop,0px));margin-block-end:var(--b-spacingBottom,var(--w-spacingBottom,0px))}
|
|
1172
|
+
.tb-missing{padding:var(--tb-space-s);border:1px dashed var(--tb-color-border-control,currentColor);font-size:var(--tb-text-s)}
|
|
1173
|
+
@media (min-width:1025px){.tb-v:not(.tb-only-desktop){display:none!important}}
|
|
1174
|
+
@media (min-width:768px) and (max-width:1024px){.tb-v:not(.tb-only-tablet){display:none!important}}
|
|
1175
|
+
@media (max-width:767px){.tb-v:not(.tb-only-phone){display:none!important}}
|
|
1176
|
+
}`;
|
|
1177
|
+
|
|
1178
|
+
// src/renderer.tsx
|
|
1179
|
+
|
|
1180
|
+
var DEVICES2 = ["desktop", "tablet", "phone"];
|
|
1181
|
+
var COMMON_BY_KEY2 = new Map(_builderschema.COMMON_WIDGET_SETTINGS.map((f) => [f.key, f]));
|
|
1182
|
+
var withCustomCache = /* @__PURE__ */ new WeakMap();
|
|
1183
|
+
function registryFor(doc, base) {
|
|
1184
|
+
const snapshots = doc.customWidgets;
|
|
1185
|
+
if (snapshots === void 0) return base;
|
|
1186
|
+
let perDocument = withCustomCache.get(base);
|
|
1187
|
+
if (perDocument === void 0) {
|
|
1188
|
+
perDocument = /* @__PURE__ */ new WeakMap();
|
|
1189
|
+
withCustomCache.set(base, perDocument);
|
|
1190
|
+
}
|
|
1191
|
+
let registry = perDocument.get(snapshots);
|
|
1192
|
+
if (registry === void 0) {
|
|
1193
|
+
try {
|
|
1194
|
+
registry = base.withCustom(Object.values(snapshots));
|
|
1195
|
+
} catch (error) {
|
|
1196
|
+
warnOnce("custom-registry", `Could not register the document's custom widgets: ${String(error)}`);
|
|
1197
|
+
registry = base;
|
|
1198
|
+
}
|
|
1199
|
+
perDocument.set(snapshots, registry);
|
|
1200
|
+
}
|
|
1201
|
+
return registry;
|
|
1202
|
+
}
|
|
1203
|
+
var isRecord2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1204
|
+
function pickLocale(value, locale) {
|
|
1205
|
+
const lang = _nullishCoalesce(locale.split("-")[0], () => ( locale));
|
|
1206
|
+
for (const key of [locale, lang, "en"]) {
|
|
1207
|
+
const text2 = Object.hasOwn(value, key) ? value[key] : void 0;
|
|
1208
|
+
if (typeof text2 === "string" && text2 !== "") return text2;
|
|
1209
|
+
}
|
|
1210
|
+
for (const text2 of Object.values(value)) if (typeof text2 === "string" && text2 !== "") return text2;
|
|
1211
|
+
return "";
|
|
1212
|
+
}
|
|
1213
|
+
function onOrigin(asset, mediaOrigin) {
|
|
1214
|
+
if (_builderschema.safeUrl.call(void 0, asset.url, "src", { mediaOrigin }) === null) return null;
|
|
1215
|
+
return { ...asset, variants: asset.variants.filter((v) => _builderschema.safeUrl.call(void 0, v.url, "src", { mediaOrigin }) !== null) };
|
|
1216
|
+
}
|
|
1217
|
+
function prepare(field, value, ctx) {
|
|
1218
|
+
if (field === void 0 || value === null) return value;
|
|
1219
|
+
if (field.translatable === true && isRecord2(value)) return pickLocale(value, ctx.locale);
|
|
1220
|
+
if (field.control === "image" && typeof value === "string") {
|
|
1221
|
+
const asset = Object.hasOwn(ctx.assets, value) ? ctx.assets[value] : void 0;
|
|
1222
|
+
return asset === void 0 ? null : onOrigin(asset, ctx.mediaOrigin);
|
|
1223
|
+
}
|
|
1224
|
+
if (field.control === "link" && isRecord2(value) && typeof value.kind === "string") {
|
|
1225
|
+
const target = value;
|
|
1226
|
+
const raw = _nullishCoalesce(_optionalChain([ctx, 'access', _42 => _42.resolveLink, 'optionalCall', _43 => _43(target)]), () => ( (target.kind === "url" ? target.href : null)));
|
|
1227
|
+
return { ...value, href: _builderschema.safeUrl.call(void 0, raw, "href", { mediaOrigin: ctx.mediaOrigin }) };
|
|
1228
|
+
}
|
|
1229
|
+
return value;
|
|
1230
|
+
}
|
|
1231
|
+
function settingsAt(node, fields, device, ctx) {
|
|
1232
|
+
const base = {};
|
|
1233
|
+
for (const field of fields.values()) base[field.key] = field.default;
|
|
1234
|
+
const resolved = _builderschema.resolveResponsive.call(void 0, { ...base, ...node.props }, node.responsive, device);
|
|
1235
|
+
const out = {};
|
|
1236
|
+
for (const [key, value] of Object.entries(resolved)) out[key] = prepare(fields.get(key), value, ctx);
|
|
1237
|
+
return out;
|
|
1238
|
+
}
|
|
1239
|
+
function variantsOf(node, def, fields, ctx) {
|
|
1240
|
+
const markup = [...fields.values()].filter((f) => f.output === "markup").map((f) => f.key);
|
|
1241
|
+
const groups = /* @__PURE__ */ new Map();
|
|
1242
|
+
for (const device of DEVICES2) {
|
|
1243
|
+
const props = settingsAt(node, fields, device, ctx);
|
|
1244
|
+
const signature = stable(markup.map((key) => _nullishCoalesce(props[key], () => ( null))));
|
|
1245
|
+
const group = groups.get(signature);
|
|
1246
|
+
if (group === void 0) groups.set(signature, { devices: [device], props });
|
|
1247
|
+
else group.devices.push(device);
|
|
1248
|
+
}
|
|
1249
|
+
void def;
|
|
1250
|
+
return [...groups.values()];
|
|
1251
|
+
}
|
|
1252
|
+
function hiddenEverywhere(props, responsive) {
|
|
1253
|
+
return DEVICES2.every(
|
|
1254
|
+
(device) => _builderschema.resolveResponsive.call(void 0, { hidden: _nullishCoalesce(props.hidden, () => ( false)) }, responsive, device).hidden === true
|
|
1255
|
+
);
|
|
1256
|
+
}
|
|
1257
|
+
var variantClass = (variant) => `tb-v ${variant.devices.map((d) => `tb-only-${d}`).join(" ")}`;
|
|
1258
|
+
function renderWidget(node, ctx, registry) {
|
|
1259
|
+
const def = registry.widget(node.type, node.v);
|
|
1260
|
+
const Component2 = def === void 0 ? void 0 : registry.component(node);
|
|
1261
|
+
if (def === void 0 || Component2 === void 0) {
|
|
1262
|
+
if (isDevelopment()) {
|
|
1263
|
+
warnOnce(`missing:${node.type}@${String(node.v)}`, `Unknown widget ${node.type} v${String(node.v)}; rendering nothing for it`);
|
|
1264
|
+
}
|
|
1265
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, NodeWrapper, { id: node.id, part: "widget", type: node.type, className: "tb-w", missing: true, children: ctx.edit !== void 0 && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "tb-missing", children: "Widget unavailable: update @usethrottle/storefront-react" }) });
|
|
1266
|
+
}
|
|
1267
|
+
if (ctx.edit === void 0 && hiddenEverywhere(node.props, node.responsive)) return null;
|
|
1268
|
+
const fields = new Map([...COMMON_BY_KEY2, ...def.settings.map((f) => [f.key, f])]);
|
|
1269
|
+
const variants = variantsOf(node, def, fields, ctx);
|
|
1270
|
+
const data = {};
|
|
1271
|
+
for (const [name, binding] of Object.entries(bindingsOf(node, registry))) {
|
|
1272
|
+
const key = bindingKey(binding);
|
|
1273
|
+
const value = Object.hasOwn(ctx.data, key) ? ctx.data[key] : void 0;
|
|
1274
|
+
if (value !== void 0) data[name] = value;
|
|
1275
|
+
}
|
|
1276
|
+
const custom = node.type.startsWith("custom.");
|
|
1277
|
+
const edit = ctx.edit;
|
|
1278
|
+
return variants.map((variant, index) => {
|
|
1279
|
+
const anchor = variant.props.anchor;
|
|
1280
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1281
|
+
NodeWrapper,
|
|
1282
|
+
{
|
|
1283
|
+
id: node.id,
|
|
1284
|
+
part: "widget",
|
|
1285
|
+
type: node.type,
|
|
1286
|
+
custom,
|
|
1287
|
+
edit,
|
|
1288
|
+
className: variants.length > 1 ? `tb-w ${variantClass(variant)}` : "tb-w",
|
|
1289
|
+
anchor: index === 0 && typeof anchor === "string" && anchor !== "" ? anchor : void 0,
|
|
1290
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1291
|
+
Component2,
|
|
1292
|
+
{
|
|
1293
|
+
node,
|
|
1294
|
+
props: variant.props,
|
|
1295
|
+
data,
|
|
1296
|
+
editMode: edit !== void 0,
|
|
1297
|
+
locale: ctx.locale,
|
|
1298
|
+
mediaOrigin: ctx.mediaOrigin,
|
|
1299
|
+
resolveLink: ctx.resolveLink,
|
|
1300
|
+
inlineEdit: edit === void 0 ? void 0 : (key) => edit.inlineEdit(node.id, key),
|
|
1301
|
+
budget: custom ? new RenderBudget() : void 0
|
|
1302
|
+
}
|
|
1303
|
+
)
|
|
1304
|
+
},
|
|
1305
|
+
variant.devices.join("-")
|
|
1306
|
+
);
|
|
1307
|
+
});
|
|
1308
|
+
}
|
|
1309
|
+
function renderColumn(column, ctx, registry) {
|
|
1310
|
+
if (ctx.edit === void 0 && hiddenEverywhere(column.props, column.responsive)) return null;
|
|
1311
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1312
|
+
NodeWrapper,
|
|
1313
|
+
{
|
|
1314
|
+
id: column.id,
|
|
1315
|
+
part: "column",
|
|
1316
|
+
className: "tb-col",
|
|
1317
|
+
anchor: column.props.anchor,
|
|
1318
|
+
edit: ctx.edit,
|
|
1319
|
+
children: column.children.map(
|
|
1320
|
+
(child) => child.type === "inner-section" ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Fragment, { children: renderSection(child, ctx, registry, true) }, child.id) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Fragment, { children: renderWidget(child, ctx, registry) }, child.id)
|
|
1321
|
+
)
|
|
1322
|
+
},
|
|
1323
|
+
column.id
|
|
1324
|
+
);
|
|
1325
|
+
}
|
|
1326
|
+
function renderSection(section, ctx, registry, nested = false) {
|
|
1327
|
+
if (ctx.edit === void 0 && hiddenEverywhere(section.props, section.responsive)) return null;
|
|
1328
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1329
|
+
NodeWrapper,
|
|
1330
|
+
{
|
|
1331
|
+
id: section.id,
|
|
1332
|
+
part: "section",
|
|
1333
|
+
as: nested ? "div" : "section",
|
|
1334
|
+
className: nested ? "tb-section tb-nested" : "tb-section",
|
|
1335
|
+
anchor: section.props.anchor,
|
|
1336
|
+
edit: ctx.edit,
|
|
1337
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "tb-inner", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "tb-row", children: section.columns.map((column) => renderColumn(column, ctx, registry)) }) })
|
|
1338
|
+
}
|
|
1339
|
+
);
|
|
1340
|
+
}
|
|
1341
|
+
function BuilderRenderer(props) {
|
|
1342
|
+
const { document: source, registry: base, data, editMode, locale, assets, resolveLink } = props;
|
|
1343
|
+
const registry = registryFor(source, base);
|
|
1344
|
+
const { doc } = _builderschema.upgradeNodes.call(void 0, source, registry);
|
|
1345
|
+
const mediaOrigin = _nullishCoalesce(props.mediaOrigin, () => ( ""));
|
|
1346
|
+
const ctx = { registry, data, locale, assets, mediaOrigin, resolveLink, edit: editMode };
|
|
1347
|
+
const css = compileResponsiveCss(doc, registry, assets, mediaOrigin);
|
|
1348
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "tb-root", "data-throttle-part": "builder-root", children: [
|
|
1349
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "style", { href: "tb-base", precedence: "throttle", children: BASE_CSS }),
|
|
1350
|
+
css === "" ? null : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "style", { children: css }),
|
|
1351
|
+
doc.sections.map((section) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Fragment, { children: renderSection(section, ctx, registry) }, section.id))
|
|
1352
|
+
] });
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
// src/part-view.tsx
|
|
1356
|
+
|
|
1357
|
+
var BoundaryBase = _nullishCoalesce(_react.Component, () => ( class {
|
|
1358
|
+
}));
|
|
1359
|
+
var PartBoundary = class extends BoundaryBase {
|
|
1360
|
+
constructor() {
|
|
1361
|
+
super(...arguments);
|
|
1362
|
+
__publicField(this, "state", { failed: false });
|
|
1363
|
+
}
|
|
1364
|
+
static getDerivedStateFromError() {
|
|
1365
|
+
return { failed: true };
|
|
1366
|
+
}
|
|
1367
|
+
componentDidCatch(error, _info) {
|
|
1368
|
+
warnOnce(`part:${this.props.label}`, `${this.props.label} failed to render (${String(error)}); rendering nothing for it`);
|
|
1369
|
+
}
|
|
1370
|
+
render() {
|
|
1371
|
+
return this.state.failed ? null : this.props.children;
|
|
1372
|
+
}
|
|
1373
|
+
};
|
|
1374
|
+
|
|
1375
|
+
// src/custom/template-widget.tsx
|
|
1376
|
+
|
|
1377
|
+
|
|
1378
|
+
|
|
1379
|
+
// src/custom/custom-css.tsx
|
|
1380
|
+
|
|
1381
|
+
|
|
1382
|
+
function scopedCss(source, type) {
|
|
1383
|
+
if (source === void 0 || source === "") return "";
|
|
1384
|
+
if (typeof source !== "string") return null;
|
|
1385
|
+
const result = _builderschema.sanitizeWidgetCss.call(void 0, source, type);
|
|
1386
|
+
return result.ok ? result.css : null;
|
|
1387
|
+
}
|
|
1388
|
+
function CustomCss({ css }) {
|
|
1389
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, WidgetStyle, { css });
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
// src/custom/interpreter.tsx
|
|
1393
|
+
|
|
1394
|
+
|
|
1395
|
+
|
|
1396
|
+
|
|
1397
|
+
|
|
1398
|
+
|
|
1399
|
+
|
|
1400
|
+
|
|
1401
|
+
|
|
1402
|
+
|
|
1403
|
+
|
|
1404
|
+
|
|
1405
|
+
|
|
1406
|
+
|
|
1407
|
+
var MAX_OUTPUT_CHARS = 1e6;
|
|
1408
|
+
var MAX_ATTR_CHARS = 2e3;
|
|
1409
|
+
var MAX_DEPTH3 = 24;
|
|
1410
|
+
function newEnv(env) {
|
|
1411
|
+
return { ...env, charsLeft: MAX_OUTPUT_CHARS, stopped: false };
|
|
1412
|
+
}
|
|
1413
|
+
var BLOCKED = /* @__PURE__ */ new Set([
|
|
1414
|
+
"__proto__",
|
|
1415
|
+
"constructor",
|
|
1416
|
+
"prototype",
|
|
1417
|
+
...Object.getOwnPropertyNames(Object.prototype)
|
|
1418
|
+
]);
|
|
1419
|
+
var isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1420
|
+
function step(value, key) {
|
|
1421
|
+
if (BLOCKED.has(key) || !isPlainObject(value) || !Object.hasOwn(value, key)) return void 0;
|
|
1422
|
+
return value[key];
|
|
1423
|
+
}
|
|
1424
|
+
function lookup(path, env, scope) {
|
|
1425
|
+
const [root, ...rest] = path;
|
|
1426
|
+
if (root === void 0) return void 0;
|
|
1427
|
+
if (root === "locale") return rest.length === 0 ? env.locale : void 0;
|
|
1428
|
+
let value;
|
|
1429
|
+
if (root === "settings") value = rest.length === 0 ? void 0 : env.settings;
|
|
1430
|
+
else if (root === "data") value = rest.length === 0 ? void 0 : env.data;
|
|
1431
|
+
else if (scope.has(root)) value = scope.get(root);
|
|
1432
|
+
else return void 0;
|
|
1433
|
+
for (const key of rest) {
|
|
1434
|
+
value = step(value, key);
|
|
1435
|
+
if (value === void 0) return void 0;
|
|
1436
|
+
}
|
|
1437
|
+
return value;
|
|
1438
|
+
}
|
|
1439
|
+
function truthy(value) {
|
|
1440
|
+
if (value === null || value === void 0 || value === false || value === "") return false;
|
|
1441
|
+
if (typeof value === "number") return value !== 0 && !Number.isNaN(value);
|
|
1442
|
+
if (Array.isArray(value)) return value.length > 0;
|
|
1443
|
+
return true;
|
|
1444
|
+
}
|
|
1445
|
+
function asText(value) {
|
|
1446
|
+
if (typeof value === "string") return value;
|
|
1447
|
+
if (typeof value === "number" && Number.isFinite(value)) return String(value);
|
|
1448
|
+
return "";
|
|
1449
|
+
}
|
|
1450
|
+
function filtered(value, filters) {
|
|
1451
|
+
let text2 = asText(value);
|
|
1452
|
+
for (const filter of filters) {
|
|
1453
|
+
switch (filter.name) {
|
|
1454
|
+
case "upper":
|
|
1455
|
+
text2 = text2.toUpperCase();
|
|
1456
|
+
break;
|
|
1457
|
+
case "lower":
|
|
1458
|
+
text2 = text2.toLowerCase();
|
|
1459
|
+
break;
|
|
1460
|
+
case "truncate": {
|
|
1461
|
+
const chars = Array.from(text2);
|
|
1462
|
+
if (chars.length > filter.n) text2 = `${chars.slice(0, filter.n).join("")}\u2026`;
|
|
1463
|
+
break;
|
|
1464
|
+
}
|
|
1465
|
+
case "default":
|
|
1466
|
+
if (text2 === "") text2 = filter.text;
|
|
1467
|
+
break;
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
return text2;
|
|
1471
|
+
}
|
|
1472
|
+
function spend(env, count) {
|
|
1473
|
+
if (count > env.charsLeft) {
|
|
1474
|
+
env.stopped = true;
|
|
1475
|
+
return false;
|
|
1476
|
+
}
|
|
1477
|
+
env.charsLeft -= count;
|
|
1478
|
+
return true;
|
|
1479
|
+
}
|
|
1480
|
+
var ELEMENTS = new Set(_builderschema.ALLOWED_ELEMENTS);
|
|
1481
|
+
var VOIDS = new Set(_builderschema.VOID_ELEMENTS);
|
|
1482
|
+
var ROLES = new Set(_builderschema.ALLOWED_ROLES);
|
|
1483
|
+
function attrAllowed(tag, name) {
|
|
1484
|
+
if (_builderschema.DATA_ATTR_RE.test(name)) return !name.startsWith(_builderschema.RESERVED_DATA_PREFIX);
|
|
1485
|
+
const own = Object.hasOwn(_builderschema.ALLOWED_ATTRS, tag) ? _builderschema.ALLOWED_ATTRS[tag] : void 0;
|
|
1486
|
+
return (_nullishCoalesce(_optionalChain([_builderschema.ALLOWED_ATTRS, 'access', _44 => _44["*"], 'optionalAccess', _45 => _45.includes, 'call', _46 => _46(name)]), () => ( false))) || (_nullishCoalesce(_optionalChain([own, 'optionalAccess', _47 => _47.includes, 'call', _48 => _48(name)]), () => ( false)));
|
|
1487
|
+
}
|
|
1488
|
+
function attrText(attr, env, scope) {
|
|
1489
|
+
return attr.value.map((part) => part.type === "text" ? part.value : filtered(lookup(part.path, env, scope), part.filters)).join("");
|
|
1490
|
+
}
|
|
1491
|
+
function urlSource(attr, env, scope) {
|
|
1492
|
+
const [only] = attr.value;
|
|
1493
|
+
if (attr.value.length !== 1 || only === void 0 || only.type !== "output") return attrText(attr, env, scope);
|
|
1494
|
+
const value = lookup(only.path, env, scope);
|
|
1495
|
+
if (isPlainObject(value)) {
|
|
1496
|
+
if (typeof value.href === "string") return value.href;
|
|
1497
|
+
if (typeof value.url === "string") return value.url;
|
|
1498
|
+
return null;
|
|
1499
|
+
}
|
|
1500
|
+
return value;
|
|
1501
|
+
}
|
|
1502
|
+
function attrProp(tag, attr, env, scope) {
|
|
1503
|
+
const { name } = attr;
|
|
1504
|
+
if (!attrAllowed(tag, name)) return null;
|
|
1505
|
+
if (name === "href" || name === "src") {
|
|
1506
|
+
const safe = _builderschema.safeUrl.call(void 0, urlSource(attr, env, scope), name, { mediaOrigin: env.mediaOrigin });
|
|
1507
|
+
return safe === null || !spend(env, safe.length) ? null : [name, safe];
|
|
1508
|
+
}
|
|
1509
|
+
const text2 = attrText(attr, env, scope);
|
|
1510
|
+
if (text2 === "" || text2.length > MAX_ATTR_CHARS) return null;
|
|
1511
|
+
let value = text2;
|
|
1512
|
+
if (name === "class") {
|
|
1513
|
+
const tokens = text2.split(/\s+/).filter((token) => _builderschema.CLASS_TOKEN_RE.test(token) && !_builderschema.isReservedClass.call(void 0, token));
|
|
1514
|
+
if (tokens.length === 0) return null;
|
|
1515
|
+
value = tokens.join(" ");
|
|
1516
|
+
} else if (name === "role") {
|
|
1517
|
+
if (!ROLES.has(text2)) return null;
|
|
1518
|
+
} else if (name === "aria-hidden") {
|
|
1519
|
+
if (text2 !== "true" && text2 !== "false") return null;
|
|
1520
|
+
}
|
|
1521
|
+
if (!spend(env, value.length)) return null;
|
|
1522
|
+
return [name === "class" ? "className" : name, value];
|
|
1523
|
+
}
|
|
1524
|
+
function renderElement(node, env, scope, depth, key) {
|
|
1525
|
+
const tag = node.tag;
|
|
1526
|
+
if (!ELEMENTS.has(tag)) return null;
|
|
1527
|
+
const props = { key };
|
|
1528
|
+
for (const attr of node.attrs) {
|
|
1529
|
+
const prop = attrProp(tag, attr, env, scope);
|
|
1530
|
+
if (prop !== null) props[prop[0]] = prop[1];
|
|
1531
|
+
}
|
|
1532
|
+
if (VOIDS.has(tag)) return _react.createElement.call(void 0, tag, props);
|
|
1533
|
+
return _react.createElement.call(void 0, tag, props, renderNodes(node.children, env, scope, depth + 1));
|
|
1534
|
+
}
|
|
1535
|
+
function renderNodes(nodes, env, scope, depth) {
|
|
1536
|
+
const out = [];
|
|
1537
|
+
if (depth > MAX_DEPTH3) return out;
|
|
1538
|
+
for (const node of nodes) {
|
|
1539
|
+
if (env.stopped) break;
|
|
1540
|
+
if (!env.budget.take(1) || node.type === "element" && !env.budget.take(node.attrs.reduce((n, a) => n + a.value.length, 0))) {
|
|
1541
|
+
env.stopped = true;
|
|
1542
|
+
break;
|
|
1543
|
+
}
|
|
1544
|
+
switch (node.type) {
|
|
1545
|
+
case "text":
|
|
1546
|
+
if (spend(env, node.value.length)) out.push(node.value);
|
|
1547
|
+
break;
|
|
1548
|
+
case "output": {
|
|
1549
|
+
const text2 = filtered(lookup(node.path, env, scope), node.filters);
|
|
1550
|
+
if (text2 !== "" && spend(env, text2.length)) out.push(text2);
|
|
1551
|
+
break;
|
|
1552
|
+
}
|
|
1553
|
+
case "if": {
|
|
1554
|
+
const branch = truthy(lookup(node.path, env, scope)) ? node.then : node.else;
|
|
1555
|
+
out.push(/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Fragment, { children: renderNodes(branch, env, scope, depth + 1) }, out.length));
|
|
1556
|
+
break;
|
|
1557
|
+
}
|
|
1558
|
+
case "unless":
|
|
1559
|
+
if (!truthy(lookup(node.path, env, scope))) {
|
|
1560
|
+
out.push(/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Fragment, { children: renderNodes(node.body, env, scope, depth + 1) }, out.length));
|
|
1561
|
+
}
|
|
1562
|
+
break;
|
|
1563
|
+
case "each": {
|
|
1564
|
+
const list = lookup(node.path, env, scope);
|
|
1565
|
+
if (!Array.isArray(list)) break;
|
|
1566
|
+
const count = Math.min(list.length, _builderschema.EACH_ITERATION_CAP);
|
|
1567
|
+
for (let i = 0; i < count && !env.stopped; i += 1) {
|
|
1568
|
+
const inner = new Map(scope).set(node.as, list[i]);
|
|
1569
|
+
out.push(/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Fragment, { children: renderNodes(node.body, env, inner, depth + 1) }, out.length));
|
|
1570
|
+
}
|
|
1571
|
+
break;
|
|
1572
|
+
}
|
|
1573
|
+
case "element":
|
|
1574
|
+
out.push(renderElement(node, env, scope, depth, out.length));
|
|
1575
|
+
break;
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
return out;
|
|
1579
|
+
}
|
|
1580
|
+
function renderTemplate(ast, env) {
|
|
1581
|
+
return renderNodes(ast, env, /* @__PURE__ */ new Map(), 0);
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
// src/custom/template-widget.tsx
|
|
1585
|
+
|
|
1586
|
+
var componentWeights = /* @__PURE__ */ new WeakMap();
|
|
1587
|
+
var compiled = /* @__PURE__ */ new WeakMap();
|
|
1588
|
+
function compileTemplate(snapshot, registry) {
|
|
1589
|
+
let perRegistry = compiled.get(snapshot);
|
|
1590
|
+
if (perRegistry === void 0) {
|
|
1591
|
+
perRegistry = /* @__PURE__ */ new WeakMap();
|
|
1592
|
+
compiled.set(snapshot, perRegistry);
|
|
1593
|
+
}
|
|
1594
|
+
if (perRegistry.has(registry)) return _nullishCoalesce(perRegistry.get(registry), () => ( null));
|
|
1595
|
+
const result = compile(snapshot, registry);
|
|
1596
|
+
perRegistry.set(registry, result);
|
|
1597
|
+
return result;
|
|
1598
|
+
}
|
|
1599
|
+
function compile(snapshot, registry) {
|
|
1600
|
+
const label = `${snapshot.type}@${String(snapshot.v)}`;
|
|
1601
|
+
const refuse = (why) => {
|
|
1602
|
+
warnOnce(`template:${label}`, `${label} was refused (${why}); rendering nothing for it`);
|
|
1603
|
+
return null;
|
|
1604
|
+
};
|
|
1605
|
+
if (snapshot.kind !== "template") return refuse("not a template widget");
|
|
1606
|
+
const source = snapshot.template;
|
|
1607
|
+
if (typeof source !== "string") return refuse("no template source");
|
|
1608
|
+
const parsed = _builderschema.parseTemplate.call(void 0, source);
|
|
1609
|
+
if (!parsed.ok) return refuse(`template does not parse: ${_nullishCoalesce(_optionalChain([parsed, 'access', _49 => _49.issues, 'access', _50 => _50[0], 'optionalAccess', _51 => _51.message]), () => ( "invalid"))}`);
|
|
1610
|
+
const data = snapshot.data;
|
|
1611
|
+
const issues = _builderschema.validateTemplate.call(void 0, parsed.ast, {
|
|
1612
|
+
settings: snapshot.settings,
|
|
1613
|
+
data: typeof data === "object" && data !== null ? data : {},
|
|
1614
|
+
sources: registry.sources()
|
|
1615
|
+
});
|
|
1616
|
+
if (issues.length > 0) return refuse(`template does not validate: ${_nullishCoalesce(_optionalChain([issues, 'access', _52 => _52[0], 'optionalAccess', _53 => _53.message]), () => ( "invalid"))}`);
|
|
1617
|
+
if (!fitsBudget(parsed.ast)) return refuse(`it can render more than ${String(_builderschema.MAX_TEMPLATE_WEIGHT)} nodes`);
|
|
1618
|
+
const css = scopedCss(snapshot.css, snapshot.type);
|
|
1619
|
+
if (css === null) return refuse("its css does not pass the sanitiser");
|
|
1620
|
+
return { ast: parsed.ast, css, weight: _builderschema.templateWeight.call(void 0, parsed.ast) };
|
|
1621
|
+
}
|
|
1622
|
+
function TemplateBody({ snapshot, registry, props, data, locale, mediaOrigin, budget }) {
|
|
1623
|
+
const template = compileTemplate(snapshot, registry);
|
|
1624
|
+
if (template === null) return null;
|
|
1625
|
+
const env = newEnv({ settings: props, data, locale, mediaOrigin, budget: _nullishCoalesce(budget, () => ( new RenderBudget())) });
|
|
1626
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
1627
|
+
template.css === "" ? null : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, CustomCss, { css: template.css }),
|
|
1628
|
+
renderTemplate(template.ast, env)
|
|
1629
|
+
] });
|
|
1630
|
+
}
|
|
1631
|
+
function TemplateWidget(props) {
|
|
1632
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, PartBoundary, { label: `${props.snapshot.type}@${String(props.snapshot.v)}`, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Suspense, { fallback: null, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, TemplateBody, { ...props }) }) });
|
|
1633
|
+
}
|
|
1634
|
+
|
|
1635
|
+
// src/custom/composite-widget.tsx
|
|
1636
|
+
|
|
1637
|
+
var SETTING_KEY_RE = /^[a-z][A-Za-z0-9]{0,39}$/;
|
|
1638
|
+
var NODE_ID_RE = /^[a-z0-9]{8,24}$/;
|
|
1639
|
+
var WRAP = { section: "zzcompsec001", column: "zzcompcol001", inner: "zzcompinr001" };
|
|
1640
|
+
var isRecord3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1641
|
+
var compiled2 = /* @__PURE__ */ new WeakMap();
|
|
1642
|
+
function parseBody(raw) {
|
|
1643
|
+
if (!isRecord3(raw)) return null;
|
|
1644
|
+
const columns = Array.isArray(raw.columns) ? raw.columns : void 0;
|
|
1645
|
+
const stack = Array.isArray(raw.stack) ? raw.stack : void 0;
|
|
1646
|
+
if (columns === void 0 === (stack === void 0)) return null;
|
|
1647
|
+
const children = columns !== void 0 ? [{ id: WRAP.inner, type: "inner-section", props: {}, columns }] : _nullishCoalesce(stack, () => ( []));
|
|
1648
|
+
if (_optionalChain([stack, 'optionalAccess', _54 => _54.some, 'call', _55 => _55((node) => isRecord3(node) && node.type === "inner-section")])) return null;
|
|
1649
|
+
const parsed = _builderschema.pageDocumentSchema.safeParse({
|
|
1650
|
+
schemaVersion: 1,
|
|
1651
|
+
sections: [{ id: WRAP.section, type: "section", props: {}, columns: [{ id: WRAP.column, type: "column", props: { width: 100 }, children }] }]
|
|
1652
|
+
});
|
|
1653
|
+
if (!parsed.success) return null;
|
|
1654
|
+
const first = _nullishCoalesce(_optionalChain([parsed, 'access', _56 => _56.data, 'access', _57 => _57.sections, 'access', _58 => _58[0], 'optionalAccess', _59 => _59.columns, 'access', _60 => _60[0], 'optionalAccess', _61 => _61.children]), () => ( []));
|
|
1655
|
+
if (columns !== void 0) {
|
|
1656
|
+
const inner = first[0];
|
|
1657
|
+
return _optionalChain([inner, 'optionalAccess', _62 => _62.type]) === "inner-section" ? { columns: inner.columns } : null;
|
|
1658
|
+
}
|
|
1659
|
+
return { stack: first.filter((node) => node.type !== "inner-section") };
|
|
1660
|
+
}
|
|
1661
|
+
function compileComposite(snapshot) {
|
|
1662
|
+
if (compiled2.has(snapshot)) return _nullishCoalesce(compiled2.get(snapshot), () => ( null));
|
|
1663
|
+
const result = compile2(snapshot);
|
|
1664
|
+
compiled2.set(snapshot, result);
|
|
1665
|
+
return result;
|
|
1666
|
+
}
|
|
1667
|
+
function compile2(snapshot) {
|
|
1668
|
+
const label = `${snapshot.type}@${String(snapshot.v)}`;
|
|
1669
|
+
const refuse = (why) => {
|
|
1670
|
+
warnOnce(`composite:${label}`, `${label} was refused (${why}); rendering nothing for it`);
|
|
1671
|
+
return null;
|
|
1672
|
+
};
|
|
1673
|
+
if (snapshot.kind !== "composite") return refuse("not a composite widget");
|
|
1674
|
+
const extra = snapshot;
|
|
1675
|
+
const body = parseBody(extra.body);
|
|
1676
|
+
if (body === null) return refuse("its body does not pass the document grammar");
|
|
1677
|
+
const bindings = [];
|
|
1678
|
+
if (extra.bindings !== void 0 && !Array.isArray(extra.bindings)) return refuse("bindings is not a list");
|
|
1679
|
+
for (const raw of _nullishCoalesce(extra.bindings, () => ( []))) {
|
|
1680
|
+
if (!isRecord3(raw) || typeof raw.setting !== "string" || !SETTING_KEY_RE.test(raw.setting) || !Array.isArray(raw.targets)) {
|
|
1681
|
+
return refuse("a binding is malformed");
|
|
1682
|
+
}
|
|
1683
|
+
const targets = [];
|
|
1684
|
+
for (const target of raw.targets) {
|
|
1685
|
+
if (!isRecord3(target) || typeof target.node !== "string" || !NODE_ID_RE.test(target.node) || typeof target.prop !== "string" || !SETTING_KEY_RE.test(target.prop)) {
|
|
1686
|
+
return refuse("a binding target is malformed");
|
|
1687
|
+
}
|
|
1688
|
+
targets.push({ node: target.node, prop: target.prop });
|
|
1689
|
+
}
|
|
1690
|
+
bindings.push({ setting: raw.setting, targets });
|
|
1691
|
+
}
|
|
1692
|
+
const data = [];
|
|
1693
|
+
if (extra.data !== void 0 && !isRecord3(extra.data)) return refuse("data is not a record");
|
|
1694
|
+
for (const [name, raw] of Object.entries(_nullishCoalesce(extra.data, () => ( {})))) {
|
|
1695
|
+
if (!SETTING_KEY_RE.test(name) || !isRecord3(raw) || !Array.isArray(raw.targets)) return refuse("a data input is malformed");
|
|
1696
|
+
const targets = [];
|
|
1697
|
+
for (const target of raw.targets) {
|
|
1698
|
+
if (!isRecord3(target) || typeof target.node !== "string" || !NODE_ID_RE.test(target.node) || typeof target.input !== "string" || !SETTING_KEY_RE.test(target.input)) {
|
|
1699
|
+
return refuse("a data target is malformed");
|
|
1700
|
+
}
|
|
1701
|
+
targets.push({ node: target.node, input: target.input });
|
|
1702
|
+
}
|
|
1703
|
+
data.push([name, { targets }]);
|
|
1704
|
+
}
|
|
1705
|
+
return { body, bindings, data };
|
|
1706
|
+
}
|
|
1707
|
+
var DEVICES3 = ["tablet", "phone"];
|
|
1708
|
+
function withoutAnchor(node) {
|
|
1709
|
+
delete node.props.anchor;
|
|
1710
|
+
const responsive = node.responsive;
|
|
1711
|
+
for (const device of DEVICES3) if (_optionalChain([responsive, 'optionalAccess', _63 => _63[device]]) !== void 0) delete responsive[device].anchor;
|
|
1712
|
+
}
|
|
1713
|
+
function instanceId(outer, inner) {
|
|
1714
|
+
let a = 3735928559;
|
|
1715
|
+
let b = 1103547991;
|
|
1716
|
+
for (const char of `${outer}:${inner}`) {
|
|
1717
|
+
const code = char.charCodeAt(0);
|
|
1718
|
+
a = Math.imul(a ^ code, 2654435761);
|
|
1719
|
+
b = Math.imul(b ^ code, 1597334677);
|
|
1720
|
+
}
|
|
1721
|
+
a = Math.imul(a ^ a >>> 16, 2246822507) ^ Math.imul(b ^ b >>> 13, 3266489909);
|
|
1722
|
+
b = Math.imul(b ^ b >>> 16, 2246822507) ^ Math.imul(a ^ a >>> 13, 3266489909);
|
|
1723
|
+
return `i${(a >>> 0).toString(36).padStart(7, "0")}${(b >>> 0).toString(36).padStart(7, "0")}${(outer.length + inner.length).toString(36)}`;
|
|
1724
|
+
}
|
|
1725
|
+
function build(input) {
|
|
1726
|
+
const { snapshot, registry, node: outer, props, data } = input;
|
|
1727
|
+
const body = structuredClone(input.compiled.body);
|
|
1728
|
+
const assets = {};
|
|
1729
|
+
const hrefs = /* @__PURE__ */ new Map();
|
|
1730
|
+
const innerData = {};
|
|
1731
|
+
const keep = (child) => _optionalChain([registry, 'access', _64 => _64.widget, 'call', _65 => _65(child.type, child.v), 'optionalAccess', _66 => _66.kind]) !== "composite";
|
|
1732
|
+
const columns = _optionalChain([body, 'access', _67 => _67.columns, 'optionalAccess', _68 => _68.map, 'call', _69 => _69((column2) => ({ ...column2, children: column2.children.filter(keep) }))]);
|
|
1733
|
+
const stack = _optionalChain([body, 'access', _70 => _70.stack, 'optionalAccess', _71 => _71.filter, 'call', _72 => _72(keep)]);
|
|
1734
|
+
const widgets2 = columns !== void 0 ? columns.flatMap((column2) => column2.children) : _nullishCoalesce(stack, () => ( []));
|
|
1735
|
+
for (const widget of widgets2) {
|
|
1736
|
+
withoutAnchor(widget);
|
|
1737
|
+
delete widget.data;
|
|
1738
|
+
}
|
|
1739
|
+
for (const column2 of _nullishCoalesce(columns, () => ( []))) withoutAnchor(column2);
|
|
1740
|
+
const byId = new Map(widgets2.map((widget) => [widget.id, widget]));
|
|
1741
|
+
const fields = new Map(snapshot.settings.map((field) => [field.key, field]));
|
|
1742
|
+
let assetCount = 0;
|
|
1743
|
+
const convert = (field, value) => {
|
|
1744
|
+
if (value === null) return null;
|
|
1745
|
+
if (field.translatable === true) return typeof value === "string" ? { en: value } : null;
|
|
1746
|
+
if (field.control === "image") {
|
|
1747
|
+
if (!isFrozenAsset(value)) return null;
|
|
1748
|
+
assetCount += 1;
|
|
1749
|
+
const id = `bound${String(assetCount)}`;
|
|
1750
|
+
assets[id] = value;
|
|
1751
|
+
return id;
|
|
1752
|
+
}
|
|
1753
|
+
if (field.control === "link") {
|
|
1754
|
+
if (!isRecord3(value) || typeof value.kind !== "string") return null;
|
|
1755
|
+
const { href, ...target } = value;
|
|
1756
|
+
if (target.kind === "url") return typeof href === "string" ? { kind: "url", href } : null;
|
|
1757
|
+
hrefs.set(JSON.stringify(target), typeof href === "string" ? href : null);
|
|
1758
|
+
return target;
|
|
1759
|
+
}
|
|
1760
|
+
return value;
|
|
1761
|
+
};
|
|
1762
|
+
for (const binding of input.compiled.bindings) {
|
|
1763
|
+
const field = fields.get(binding.setting);
|
|
1764
|
+
if (field === void 0 || !Object.hasOwn(props, binding.setting)) continue;
|
|
1765
|
+
const value = props[binding.setting];
|
|
1766
|
+
for (const target of binding.targets) {
|
|
1767
|
+
const inner = byId.get(target.node);
|
|
1768
|
+
const innerField = inner === void 0 ? void 0 : _optionalChain([registry, 'access', _73 => _73.widget, 'call', _74 => _74(inner.type, inner.v), 'optionalAccess', _75 => _75.settings, 'access', _76 => _76.find, 'call', _77 => _77((f) => f.key === target.prop)]);
|
|
1769
|
+
if (inner === void 0 || innerField === void 0 || innerField.control !== field.control) continue;
|
|
1770
|
+
const converted = convert(field, value);
|
|
1771
|
+
if (_builderschema.validateSettingValue.call(void 0, innerField, converted) !== null) continue;
|
|
1772
|
+
inner.props[target.prop] = converted;
|
|
1773
|
+
const responsive = inner.responsive;
|
|
1774
|
+
for (const device of DEVICES3) {
|
|
1775
|
+
if (_optionalChain([responsive, 'optionalAccess', _78 => _78[device]]) !== void 0) delete responsive[device][target.prop];
|
|
1776
|
+
const raw = _optionalChain([outer, 'access', _79 => _79.responsive, 'optionalAccess', _80 => _80[device]]);
|
|
1777
|
+
const plain = field.output === "css" && field.translatable !== true && field.control !== "image" && field.control !== "link";
|
|
1778
|
+
if (plain && raw !== void 0 && Object.hasOwn(raw, binding.setting) && _builderschema.validateSettingValue.call(void 0, innerField, raw[binding.setting]) === null) {
|
|
1779
|
+
const target$ = _nullishCoalesce(inner.responsive, () => ( (inner.responsive = {})));
|
|
1780
|
+
(_nullishCoalesce(target$[device], () => ( (target$[device] = {}))))[target.prop] = raw[binding.setting];
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
for (const [name, input$] of input.compiled.data) {
|
|
1786
|
+
if (!Object.hasOwn(data, name) || data[name] === void 0) continue;
|
|
1787
|
+
const key = `composite.${name}`;
|
|
1788
|
+
for (const target of input$.targets) {
|
|
1789
|
+
const inner = byId.get(target.node);
|
|
1790
|
+
const def = inner === void 0 ? void 0 : registry.widget(inner.type, inner.v);
|
|
1791
|
+
if (inner === void 0 || _optionalChain([def, 'optionalAccess', _81 => _81.data]) === void 0 || !Object.hasOwn(def.data, target.input)) continue;
|
|
1792
|
+
inner.data = { ..._nullishCoalesce(inner.data, () => ( {})), [target.input]: { source: key } };
|
|
1793
|
+
innerData[key] = data[name];
|
|
1794
|
+
}
|
|
1795
|
+
}
|
|
1796
|
+
for (const widget of widgets2) widget.id = instanceId(outer.id, widget.id);
|
|
1797
|
+
for (const column2 of _nullishCoalesce(columns, () => ( []))) column2.id = instanceId(outer.id, column2.id);
|
|
1798
|
+
const ids = { section: instanceId(outer.id, WRAP.section), column: instanceId(outer.id, WRAP.column), inner: instanceId(outer.id, WRAP.inner) };
|
|
1799
|
+
const column = {
|
|
1800
|
+
id: ids.column,
|
|
1801
|
+
type: "column",
|
|
1802
|
+
props: { width: 100 },
|
|
1803
|
+
children: columns !== void 0 ? [{ id: ids.inner, type: "inner-section", props: { width: "full" }, columns }] : _nullishCoalesce(stack, () => ( []))
|
|
1804
|
+
};
|
|
1805
|
+
const document = {
|
|
1806
|
+
schemaVersion: 1,
|
|
1807
|
+
sections: [{ id: ids.section, type: "section", props: { width: "full" }, columns: [column] }]
|
|
1808
|
+
};
|
|
1809
|
+
let weight = 2 + (_nullishCoalesce(_optionalChain([columns, 'optionalAccess', _82 => _82.length]), () => ( 0))) + (columns === void 0 ? 0 : 1);
|
|
1810
|
+
for (const widget of widgets2) {
|
|
1811
|
+
const component = registry.component(widget);
|
|
1812
|
+
weight += 1 + (component === void 0 ? 0 : _nullishCoalesce(componentWeights.get(component), () => ( 0)));
|
|
1813
|
+
}
|
|
1814
|
+
return { document, assets, data: innerData, hrefs, weight };
|
|
1815
|
+
}
|
|
1816
|
+
function CompositeBody(props) {
|
|
1817
|
+
const { snapshot, registry, node, data, locale, mediaOrigin, budget, resolveLink } = props;
|
|
1818
|
+
const composite = compileComposite(snapshot);
|
|
1819
|
+
if (composite === null) return null;
|
|
1820
|
+
const built = build({ snapshot, compiled: composite, registry, node, props: props.props, data });
|
|
1821
|
+
if (!(_nullishCoalesce(budget, () => ( new RenderBudget()))).take(built.weight)) {
|
|
1822
|
+
warnOnce(`composite-weight:${snapshot.type}@${String(snapshot.v)}`, `${snapshot.type} would render too many nodes; rendering nothing for it`);
|
|
1823
|
+
return null;
|
|
1824
|
+
}
|
|
1825
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1826
|
+
BuilderRenderer,
|
|
1827
|
+
{
|
|
1828
|
+
document: built.document,
|
|
1829
|
+
registry,
|
|
1830
|
+
data: built.data,
|
|
1831
|
+
locale,
|
|
1832
|
+
assets: built.assets,
|
|
1833
|
+
mediaOrigin,
|
|
1834
|
+
resolveLink: (target) => _nullishCoalesce(_nullishCoalesce(built.hrefs.get(JSON.stringify(target)), () => ( _optionalChain([resolveLink, 'optionalCall', _83 => _83(target)]))), () => ( null))
|
|
1835
|
+
}
|
|
1836
|
+
);
|
|
1837
|
+
}
|
|
1838
|
+
function CompositeWidget(props) {
|
|
1839
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, PartBoundary, { label: `${props.snapshot.type}@${String(props.snapshot.v)}`, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Suspense, { fallback: null, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, CompositeBody, { ...props }) }) });
|
|
1840
|
+
}
|
|
1841
|
+
|
|
1842
|
+
// src/custom/factory.ts
|
|
1843
|
+
var isDisabled = (snapshot) => snapshot.status === "disabled";
|
|
1844
|
+
var Disabled = ({ editMode }) => editMode ? _react.createElement.call(void 0, "div", { className: "tb-missing" }, "This custom widget is disabled") : null;
|
|
1845
|
+
var customWidgetFactory = (snapshot, registry) => {
|
|
1846
|
+
if (isDisabled(snapshot)) return Disabled;
|
|
1847
|
+
if (snapshot.kind === "template") {
|
|
1848
|
+
const template = compileTemplate(snapshot, registry);
|
|
1849
|
+
if (template === null) return null;
|
|
1850
|
+
const Component2 = (props) => _react.createElement.call(void 0, TemplateWidget, { ...props, snapshot, registry });
|
|
1851
|
+
componentWeights.set(Component2, template.weight);
|
|
1852
|
+
return Component2;
|
|
1853
|
+
}
|
|
1854
|
+
if (compileComposite(snapshot) === null) return null;
|
|
1855
|
+
return (props) => _react.createElement.call(void 0, CompositeWidget, { ...props, snapshot, registry });
|
|
1856
|
+
};
|
|
1857
|
+
|
|
1858
|
+
// src/registry.ts
|
|
1859
|
+
var BUILTIN_PACKS = [basicPack];
|
|
1860
|
+
var DEFAULT_CUSTOM_WIDGET = customWidgetFactory;
|
|
1861
|
+
var customKey = (type, v) => `${type}@${String(v)}`;
|
|
1862
|
+
function createRendererRegistry(packs, options = {}) {
|
|
1863
|
+
const all = [...BUILTIN_PACKS, ...packs];
|
|
1864
|
+
const components = /* @__PURE__ */ new Map();
|
|
1865
|
+
const definitions = [];
|
|
1866
|
+
const sources = [];
|
|
1867
|
+
const resolvers = /* @__PURE__ */ new Map();
|
|
1868
|
+
for (const pack of all) {
|
|
1869
|
+
for (const { Component: Component2, ...definition } of pack.widgets) {
|
|
1870
|
+
const key = customKey(definition.type, definition.v);
|
|
1871
|
+
if (components.has(key)) continue;
|
|
1872
|
+
components.set(key, Component2);
|
|
1873
|
+
definitions.push(definition);
|
|
1874
|
+
}
|
|
1875
|
+
for (const { resolve, ...descriptor } of pack.dataSources) {
|
|
1876
|
+
if (resolvers.has(descriptor.id)) continue;
|
|
1877
|
+
resolvers.set(descriptor.id, resolve);
|
|
1878
|
+
sources.push(descriptor);
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
const factory = _nullishCoalesce(options.customWidget, () => ( DEFAULT_CUSTOM_WIDGET));
|
|
1882
|
+
const build2 = (custom) => {
|
|
1883
|
+
const schema = _builderschema.createRegistry.call(void 0, definitions, sources, custom);
|
|
1884
|
+
const snapshots = new Map(custom.map((snapshot) => [customKey(snapshot.type, snapshot.v), snapshot]));
|
|
1885
|
+
const built = /* @__PURE__ */ new Map();
|
|
1886
|
+
const registry = {
|
|
1887
|
+
widget: schema.widget,
|
|
1888
|
+
latest: schema.latest,
|
|
1889
|
+
source: schema.source,
|
|
1890
|
+
sources: schema.sources,
|
|
1891
|
+
all: schema.all,
|
|
1892
|
+
resolver: (id) => resolvers.get(id),
|
|
1893
|
+
component: (node) => {
|
|
1894
|
+
const key = customKey(node.type, node.v);
|
|
1895
|
+
const own = components.get(key);
|
|
1896
|
+
if (own !== void 0) return own;
|
|
1897
|
+
if (!node.type.startsWith("custom.") || factory === void 0) return void 0;
|
|
1898
|
+
const snapshot = snapshots.get(key);
|
|
1899
|
+
if (snapshot === void 0) return void 0;
|
|
1900
|
+
if (!built.has(key)) built.set(key, factory(snapshot, registry));
|
|
1901
|
+
return _nullishCoalesce(built.get(key), () => ( void 0));
|
|
1902
|
+
},
|
|
1903
|
+
withCustom: (more) => build2([...custom, ...more])
|
|
1904
|
+
};
|
|
1905
|
+
return registry;
|
|
1906
|
+
};
|
|
1907
|
+
return build2([]);
|
|
1908
|
+
}
|
|
1909
|
+
|
|
1910
|
+
// src/server/load-page.ts
|
|
1911
|
+
|
|
1912
|
+
async function loadBuilderPage(options) {
|
|
1913
|
+
const { slug, locale, packs = [], slots } = options;
|
|
1914
|
+
const bundle = await getBundle({ client: clientOf(options), locale, page: slug, slots });
|
|
1915
|
+
const found = bundle.page;
|
|
1916
|
+
if (found === void 0) throw new (0, _builder.BuilderNotFoundError)(slug);
|
|
1917
|
+
if (isRedirect(found)) return { kind: "redirect", redirectTo: found.redirectTo };
|
|
1918
|
+
const data = await staticDataFor([found.document], createRendererRegistry(packs), locale);
|
|
1919
|
+
return pageOf(found, data);
|
|
1920
|
+
}
|
|
1921
|
+
|
|
1922
|
+
// src/next/seo.ts
|
|
1923
|
+
|
|
1924
|
+
var isRec = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1925
|
+
var text = (value) => typeof value === "string" && value.trim() !== "" ? value : void 0;
|
|
1926
|
+
var ORIGIN_RE = /^https?:\/\/[^\s/\\]+$/iu;
|
|
1927
|
+
var DEFAULT_PAGE_ROUTE = "/pages/{handle}";
|
|
1928
|
+
var LOCALE_SEGMENT_RE = /^[A-Za-z0-9-]+$/u;
|
|
1929
|
+
function pageSeoOf(page) {
|
|
1930
|
+
const seo = isRec(page.seo) ? page.seo : {};
|
|
1931
|
+
const title = text(seo.title);
|
|
1932
|
+
const description = text(seo.description);
|
|
1933
|
+
return {
|
|
1934
|
+
...title === void 0 ? {} : { title },
|
|
1935
|
+
...description === void 0 ? {} : { description },
|
|
1936
|
+
shareImage: seo.shareImage,
|
|
1937
|
+
noindex: seo.noindex === true
|
|
1938
|
+
};
|
|
1939
|
+
}
|
|
1940
|
+
function imageOf(value, mediaOrigin) {
|
|
1941
|
+
const raw = isRec(value) ? value.url : value;
|
|
1942
|
+
const url = _builderschema.safeUrl.call(void 0, raw, "src", { mediaOrigin });
|
|
1943
|
+
if (url === null) return void 0;
|
|
1944
|
+
const frozen = isRec(value) ? value : {};
|
|
1945
|
+
return {
|
|
1946
|
+
url,
|
|
1947
|
+
...typeof frozen.width === "number" ? { width: frozen.width } : {},
|
|
1948
|
+
...typeof frozen.height === "number" ? { height: frozen.height } : {}
|
|
1949
|
+
};
|
|
1950
|
+
}
|
|
1951
|
+
function pagePathOf(settings, page, resolve) {
|
|
1952
|
+
const routes = isRec(settings.routes) ? settings.routes : {};
|
|
1953
|
+
const pattern = _nullishCoalesce(text(routes.page), () => ( DEFAULT_PAGE_ROUTE));
|
|
1954
|
+
const path = _builderschema.safeUrl.call(void 0, pattern.replaceAll("{handle}", () => page.slug), "href", { mediaOrigin: "" });
|
|
1955
|
+
if (path === null || resolve === void 0) return path;
|
|
1956
|
+
return _nullishCoalesce(_builderschema.safeUrl.call(void 0, resolve({ ...page, path }), "href", { mediaOrigin: "" }), () => ( path));
|
|
1957
|
+
}
|
|
1958
|
+
function originOf(storeUrl) {
|
|
1959
|
+
const origin = _optionalChain([storeUrl, 'optionalAccess', _84 => _84.replace, 'call', _85 => _85(/\/+$/u, "")]);
|
|
1960
|
+
return origin !== void 0 && ORIGIN_RE.test(origin) ? origin : void 0;
|
|
1961
|
+
}
|
|
1962
|
+
function siteLocales(settings) {
|
|
1963
|
+
const locales = isRec(settings.locales) ? settings.locales : {};
|
|
1964
|
+
const list = Array.isArray(locales.list) ? locales.list.filter((locale) => typeof locale === "string" && LOCALE_SEGMENT_RE.test(locale)) : [];
|
|
1965
|
+
return { list, fallback: typeof locales.default === "string" && list.includes(locales.default) ? locales.default : void 0 };
|
|
1966
|
+
}
|
|
1967
|
+
var localized = (path, locale) => locale === void 0 ? path : path === "/" ? `/${locale}` : `/${locale}${path}`;
|
|
1968
|
+
function metadataOf(page, context) {
|
|
1969
|
+
const { settings, mediaOrigin, routeLocale } = context;
|
|
1970
|
+
const site = isRec(settings.seo) ? settings.seo : {};
|
|
1971
|
+
const brand = isRec(settings.brand) ? settings.brand : {};
|
|
1972
|
+
const own = pageSeoOf(page);
|
|
1973
|
+
const template = _nullishCoalesce(text(site.titleTemplate), () => ( "{page}"));
|
|
1974
|
+
const store = _nullishCoalesce(text(brand.storeName), () => ( ""));
|
|
1975
|
+
const title = template.replaceAll("{page}", () => _nullishCoalesce(own.title, () => ( page.title))).replaceAll("{store}", () => store);
|
|
1976
|
+
const description = _nullishCoalesce(own.description, () => ( text(site.defaultDescription)));
|
|
1977
|
+
const image = _nullishCoalesce(imageOf(own.shareImage, mediaOrigin), () => ( imageOf(site.shareImage, mediaOrigin)));
|
|
1978
|
+
if (image === void 0 && mediaOrigin === "" && (isRec(own.shareImage) || isRec(site.shareImage)))
|
|
1979
|
+
warnOnce("share-image-origin", "A share image is set but createBuilderPage has no mediaOrigin, so the page has no og:image: pass the same mediaOrigin as loadSite");
|
|
1980
|
+
const origin = originOf(context.storeUrl);
|
|
1981
|
+
if (origin === void 0)
|
|
1982
|
+
warnOnce("canonical-origin", "No canonical link: pass storeUrl (https://shop.example.com) to createBuilderPage. The Builder does not publish the store URL.");
|
|
1983
|
+
const path = pagePathOf(settings, { slug: page.slug, pageType: page.pageType }, context.pagePath);
|
|
1984
|
+
const canonical = origin === void 0 || path === null ? void 0 : `${origin}${localized(path, routeLocale)}`;
|
|
1985
|
+
const { list, fallback } = siteLocales(settings);
|
|
1986
|
+
const languages = origin !== void 0 && path !== null && routeLocale !== void 0 && list.length > 1 ? {
|
|
1987
|
+
...Object.fromEntries(list.map((locale) => [locale, `${origin}${localized(path, locale)}`])),
|
|
1988
|
+
...fallback === void 0 ? {} : { "x-default": `${origin}${localized(path, fallback)}` }
|
|
1989
|
+
} : void 0;
|
|
1990
|
+
return {
|
|
1991
|
+
title,
|
|
1992
|
+
...description === void 0 ? {} : { description },
|
|
1993
|
+
...own.noindex ? { robots: { index: false } } : {},
|
|
1994
|
+
...canonical === void 0 ? {} : { alternates: { canonical, ...languages === void 0 ? {} : { languages } } },
|
|
1995
|
+
openGraph: {
|
|
1996
|
+
type: "website",
|
|
1997
|
+
title,
|
|
1998
|
+
...description === void 0 ? {} : { description },
|
|
1999
|
+
...canonical === void 0 ? {} : { url: canonical },
|
|
2000
|
+
...image === void 0 ? {} : { images: [image] }
|
|
2001
|
+
},
|
|
2002
|
+
twitter: {
|
|
2003
|
+
card: image === void 0 ? "summary" : "summary_large_image",
|
|
2004
|
+
title,
|
|
2005
|
+
...description === void 0 ? {} : { description },
|
|
2006
|
+
...image === void 0 ? {} : { images: [image.url] }
|
|
2007
|
+
}
|
|
2008
|
+
};
|
|
2009
|
+
}
|
|
2010
|
+
|
|
2011
|
+
|
|
2012
|
+
|
|
2013
|
+
|
|
2014
|
+
|
|
2015
|
+
|
|
2016
|
+
|
|
2017
|
+
|
|
2018
|
+
|
|
2019
|
+
|
|
2020
|
+
|
|
2021
|
+
|
|
2022
|
+
|
|
2023
|
+
|
|
2024
|
+
|
|
2025
|
+
|
|
2026
|
+
exports.warnOnce = warnOnce; exports.createRendererRegistry = createRendererRegistry; exports.staticDataFor = staticDataFor; exports.partOf = partOf; exports.isRedirect = isRedirect; exports.getBundle = getBundle; exports.clientOf = clientOf; exports.loadBuilderPage = loadBuilderPage; exports.pageSeoOf = pageSeoOf; exports.pagePathOf = pagePathOf; exports.originOf = originOf; exports.siteLocales = siteLocales; exports.localized = localized; exports.metadataOf = metadataOf;
|