@wunderweb/react 0.0.0-stage → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/bridge-script-DeloNmTd.mjs +352 -0
- package/dist/bridge.d.mts +8 -0
- package/dist/bridge.mjs +2 -0
- package/dist/index.d.mts +743 -0
- package/dist/index.mjs +912 -0
- package/package.json +44 -3
- package/README.md +0 -3
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,912 @@
|
|
|
1
|
+
import { t as mountBridge } from "./bridge-script-DeloNmTd.mjs";
|
|
2
|
+
import { BASE, Classes, Classes as Classes$1, at, tw, tw as tw$1 } from "@wunderweb/core/tailwind";
|
|
3
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { clientConsent, gateOf } from "@wunderweb/core/consent";
|
|
5
|
+
import { Suspense } from "react";
|
|
6
|
+
//#region src/html.tsx
|
|
7
|
+
const RICH = "wc-rich";
|
|
8
|
+
function RichText({ html, className }) {
|
|
9
|
+
if (!html) return null;
|
|
10
|
+
return /* @__PURE__ */ jsx("div", {
|
|
11
|
+
className: `${RICH} ${className ?? ""}`,
|
|
12
|
+
dangerouslySetInnerHTML: { __html: html }
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function Svg({ svg, className, style }) {
|
|
16
|
+
if (!svg) return null;
|
|
17
|
+
return /* @__PURE__ */ jsx("span", {
|
|
18
|
+
className,
|
|
19
|
+
style,
|
|
20
|
+
"aria-hidden": "true",
|
|
21
|
+
dangerouslySetInnerHTML: { __html: svg }
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/images.ts
|
|
26
|
+
/**
|
|
27
|
+
* The url for a video's `poster` attribute: the loader's `posterSrc` (e.g.
|
|
28
|
+
* an image server's converted, width-capped copy), else the original.
|
|
29
|
+
*/
|
|
30
|
+
function posterOf(asset) {
|
|
31
|
+
if (asset.kind !== "video") return;
|
|
32
|
+
const resolved = asset.posterSrc;
|
|
33
|
+
return typeof resolved === "string" ? resolved : asset.poster;
|
|
34
|
+
}
|
|
35
|
+
/** Where a cover background shows its `portrait` crop: phones held upright, whose hero box is tall. */
|
|
36
|
+
const PORTRAIT_MEDIA = "(orientation: portrait) and (max-width: 767px)";
|
|
37
|
+
/** Device pixel ratios a fixed-width image keeps one candidate for. */
|
|
38
|
+
const DENSITIES = [
|
|
39
|
+
1,
|
|
40
|
+
1.5,
|
|
41
|
+
2,
|
|
42
|
+
3
|
|
43
|
+
];
|
|
44
|
+
/** CSS px per rem at the default font size, and a larger default (20px) rem boxes also pick for. */
|
|
45
|
+
const REM_PX = 16;
|
|
46
|
+
const LARGE_FONT = 20 / REM_PX;
|
|
47
|
+
/** Width / height. */
|
|
48
|
+
function ratioOf(size) {
|
|
49
|
+
return size.width / size.height;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* How much wider than its box `object-fit: cover` draws an image of `size`
|
|
53
|
+
* in a box of `boxRatio` (width / height): 1 if the height limits it.
|
|
54
|
+
*/
|
|
55
|
+
function coverScale(size, boxRatio) {
|
|
56
|
+
return Math.max(1, ratioOf(size) / boxRatio);
|
|
57
|
+
}
|
|
58
|
+
/** Real pixel size of an image Asset: its original (last srcset entry), else its width / height. */
|
|
59
|
+
function imageSize(asset) {
|
|
60
|
+
const original = asset.srcset?.at(-1);
|
|
61
|
+
if (original) return {
|
|
62
|
+
width: original.width,
|
|
63
|
+
height: original.height
|
|
64
|
+
};
|
|
65
|
+
return asset.width && asset.height ? {
|
|
66
|
+
width: asset.width,
|
|
67
|
+
height: asset.height
|
|
68
|
+
} : void 0;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* `srcSet` of only the full-size candidate (the original's pixels, e.g. as
|
|
72
|
+
* AVIF / WebP from an image server), for an image whose drawn width is
|
|
73
|
+
* unknown: the browser takes it over `src` at every density. Empty when it
|
|
74
|
+
* is the original itself.
|
|
75
|
+
*/
|
|
76
|
+
function fullSrcSet(asset) {
|
|
77
|
+
const full = asset.srcset?.at(-1);
|
|
78
|
+
if (!full || asset.kind !== "image" || full.url === asset.url) return {};
|
|
79
|
+
return { srcSet: `${full.url} 1x` };
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* `srcSet` and `sizes` for an image drawn in `box`; empty when the asset
|
|
83
|
+
* has no copies or none is safe to offer (the img keeps its `src`).
|
|
84
|
+
*/
|
|
85
|
+
function imageSrcSet(asset, box = {}, opts = {}) {
|
|
86
|
+
const list = asset.srcset;
|
|
87
|
+
const original = list?.at(-1);
|
|
88
|
+
if (!list || !original || list.length < 2 || asset.kind !== "image") return {};
|
|
89
|
+
const natural = !box.fit;
|
|
90
|
+
const boxRatio = box.ratio ?? (box.width && box.height ? box.width / box.height : void 0);
|
|
91
|
+
if (box.fit === "cover" && !boxRatio) return /\.webp$/i.test(asset.url.replace(/[?#].*$/, "")) ? {} : fullSrcSet(asset);
|
|
92
|
+
const effective = (c) => Math.floor(box.fit === "cover" && boxRatio ? c.width / coverScale(c, boxRatio) : c.width);
|
|
93
|
+
const copies = list.slice(0, -1).filter((c) => !natural || c.width * original.height === c.height * original.width);
|
|
94
|
+
const width = box.width ?? (box.height ? box.height * (natural ? ratioOf(original) : boxRatio ?? NaN) : void 0);
|
|
95
|
+
let chosen;
|
|
96
|
+
let sizes;
|
|
97
|
+
if (width === void 0 || !Number.isFinite(width)) {
|
|
98
|
+
chosen = [...copies, original];
|
|
99
|
+
sizes = opts.eager ? "100vw" : "auto, 100vw";
|
|
100
|
+
} else {
|
|
101
|
+
const rem = box.unit === "rem";
|
|
102
|
+
const px = rem ? width * REM_PX : width;
|
|
103
|
+
const scales = rem ? [1, LARGE_FONT] : [1];
|
|
104
|
+
const picked = /* @__PURE__ */ new Set();
|
|
105
|
+
for (const f of scales) for (const d of DENSITIES) {
|
|
106
|
+
const c = copies.find((x) => effective(x) >= px * f * d);
|
|
107
|
+
if (c) picked.add(c);
|
|
108
|
+
}
|
|
109
|
+
chosen = [...copies.filter((c) => picked.has(c)), original];
|
|
110
|
+
sizes = rem ? `${Math.ceil(width * 1e4) / 1e4}rem` : `${Math.ceil(width * 100) / 100}px`;
|
|
111
|
+
}
|
|
112
|
+
if (chosen.length < 2) return {};
|
|
113
|
+
return {
|
|
114
|
+
srcSet: chosen.map((c) => `${c.url} ${effective(c)}w`).join(", "),
|
|
115
|
+
sizes
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
//#endregion
|
|
119
|
+
//#region src/box.tsx
|
|
120
|
+
const SIDES = [
|
|
121
|
+
"top",
|
|
122
|
+
"right",
|
|
123
|
+
"bottom",
|
|
124
|
+
"left"
|
|
125
|
+
];
|
|
126
|
+
const EDGE_HEIGHT = "clamp(24px, 4vw, 64px)";
|
|
127
|
+
const EDGE_PATH = {
|
|
128
|
+
wave: (b) => b ? "M0 0 H100 V60 Q75 100 50 80 T0 80 Z" : "M0 100 H100 V40 Q75 0 50 20 T0 20 Z",
|
|
129
|
+
slant: (b) => b ? "M0 0 H100 V60 L0 100 Z" : "M0 40 L100 0 V100 H0 Z",
|
|
130
|
+
curve: (b) => b ? "M0 0 H100 V60 Q50 120 0 60 Z" : "M0 40 Q50 -20 100 40 V100 H0 Z"
|
|
131
|
+
};
|
|
132
|
+
/** Renders a block's box (Box, Surround and Linkable traits) around its content. */
|
|
133
|
+
function BoxFrame({ block, ctx, children, innerClass, innerStyle, outerClass, as = "div", flat }) {
|
|
134
|
+
const breakpoints = ctx.breakpoints;
|
|
135
|
+
const outer = new Classes$1(breakpoints).add("wc-block", `wc-${block.type}`, "relative", outerClass);
|
|
136
|
+
const inner = new Classes$1(breakpoints).add("wc-inner", "relative", "flex", "flex-col");
|
|
137
|
+
placement(outer, block.place);
|
|
138
|
+
appearance(outer, block.appearance, block.background);
|
|
139
|
+
visibility(outer, block.visible);
|
|
140
|
+
layout(outer, inner, block.layout);
|
|
141
|
+
const bg = background(block.background, ctx.priority === true);
|
|
142
|
+
const edges = edgeStyle(block.edges);
|
|
143
|
+
const Tag = as;
|
|
144
|
+
const before = block.before?.length ? ctx.render(block.before, "before") : null;
|
|
145
|
+
const after = block.after?.length ? ctx.render(block.after, "after") : null;
|
|
146
|
+
const content = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
147
|
+
before,
|
|
148
|
+
children,
|
|
149
|
+
after
|
|
150
|
+
] });
|
|
151
|
+
const link = block.link ? /* @__PURE__ */ jsx("a", {
|
|
152
|
+
className: "absolute inset-0 z-20",
|
|
153
|
+
href: block.link.url,
|
|
154
|
+
target: block.link.target,
|
|
155
|
+
rel: block.link.rel,
|
|
156
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
157
|
+
className: "sr-only",
|
|
158
|
+
children: block.link.label ?? block.link.url
|
|
159
|
+
})
|
|
160
|
+
}) : null;
|
|
161
|
+
return /* @__PURE__ */ jsxs(Tag, {
|
|
162
|
+
id: block.anchor,
|
|
163
|
+
className: outer.className,
|
|
164
|
+
style: {
|
|
165
|
+
...outer.style,
|
|
166
|
+
...edges
|
|
167
|
+
},
|
|
168
|
+
"data-block": block.type,
|
|
169
|
+
...ctx.path === void 0 ? {} : { "data-wc-path": ctx.path },
|
|
170
|
+
children: [
|
|
171
|
+
bg,
|
|
172
|
+
block.decorations?.map((d, i) => /* @__PURE__ */ jsx(DecorationEl, {
|
|
173
|
+
d,
|
|
174
|
+
breakpoints
|
|
175
|
+
}, i)),
|
|
176
|
+
flat && !hasLayout(block.layout) ? content : /* @__PURE__ */ jsx("div", {
|
|
177
|
+
className: `${inner.className} ${innerClass ?? ""}`,
|
|
178
|
+
style: {
|
|
179
|
+
...inner.style,
|
|
180
|
+
...innerStyle
|
|
181
|
+
},
|
|
182
|
+
children: content
|
|
183
|
+
}),
|
|
184
|
+
link
|
|
185
|
+
]
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
/** Default box: wraps a component that renders only the inside. */
|
|
189
|
+
function withBox(Inner) {
|
|
190
|
+
return function Boxed({ block, ctx }) {
|
|
191
|
+
return /* @__PURE__ */ jsx(BoxFrame, {
|
|
192
|
+
block,
|
|
193
|
+
ctx,
|
|
194
|
+
children: /* @__PURE__ */ jsx(Inner, {
|
|
195
|
+
block,
|
|
196
|
+
ctx
|
|
197
|
+
})
|
|
198
|
+
});
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
function hasLayout(l) {
|
|
202
|
+
return Boolean(l && Object.keys(l).length);
|
|
203
|
+
}
|
|
204
|
+
function placement(c, p) {
|
|
205
|
+
if (!p) return;
|
|
206
|
+
c.resp(p.maxWidth, (v, bp) => {
|
|
207
|
+
if (typeof v === "number") c.var(`--wc-mw-${bp}`, `${v}px`);
|
|
208
|
+
return [tw$1.maxWidth(v, bp), "w-full"];
|
|
209
|
+
});
|
|
210
|
+
c.resp(p.x, (v) => tw$1.placeX(v));
|
|
211
|
+
c.resp(p.y, (v) => tw$1.self(v));
|
|
212
|
+
c.resp(p.margin, (m) => SIDES.filter((s) => m[s] !== void 0).map((s) => tw$1.margin(s, m[s])));
|
|
213
|
+
c.resp(p.colSpan, (v) => tw$1.colSpan(v));
|
|
214
|
+
c.resp(p.rowSpan, (v) => tw$1.rowSpan(v));
|
|
215
|
+
}
|
|
216
|
+
function appearance(c, a, bg) {
|
|
217
|
+
if (bg?.color && !bg.asset && !bg.gradients?.length && bg.opacity === void 0) paint(c, "bg", bg.color);
|
|
218
|
+
if (!a) return;
|
|
219
|
+
if (a.textColor) c.add(tw$1.text(a.textColor));
|
|
220
|
+
if (a.rounded) c.add(tw$1.rounded(a.rounded), "overflow-hidden");
|
|
221
|
+
if (a.shadow) c.add(tw$1.shadow(a.shadow));
|
|
222
|
+
if (a.border) {
|
|
223
|
+
c.add(tw$1.borderWidth(a.border.width), tw$1.borderStyle(a.border.style ?? "solid"));
|
|
224
|
+
paint(c, "border", a.border.color);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
/** Token → class, hex → inline style. */
|
|
228
|
+
function paint(c, kind, v) {
|
|
229
|
+
if (!v) return;
|
|
230
|
+
if (v.startsWith("#")) {
|
|
231
|
+
c.style[kind === "bg" ? "backgroundColor" : kind === "text" ? "color" : "borderColor"] = v;
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
c.add(kind === "bg" ? tw$1.bg(v) : kind === "text" ? tw$1.text(v) : tw$1.borderColor(v));
|
|
235
|
+
}
|
|
236
|
+
/** CSS color value of a Paint (token → theme variable). */
|
|
237
|
+
function cssColor(v, opacity) {
|
|
238
|
+
if (!v) return;
|
|
239
|
+
const base = v.startsWith("#") ? v : `var(--color-${v})`;
|
|
240
|
+
return opacity === void 0 ? base : `color-mix(in srgb, ${base} ${Math.round(opacity * 100)}%, transparent)`;
|
|
241
|
+
}
|
|
242
|
+
function visibility(c, v) {
|
|
243
|
+
c.resp(v, (shown) => shown ? "block" : "hidden");
|
|
244
|
+
}
|
|
245
|
+
function layout(outer, inner, l) {
|
|
246
|
+
if (!l) return;
|
|
247
|
+
if (l.container) inner.add(`wc-container-${l.container}`);
|
|
248
|
+
if (l.alignX) inner.add(tw$1.alignItems(l.alignX));
|
|
249
|
+
if (l.alignY) inner.add(tw$1.justify(l.alignY));
|
|
250
|
+
if (l.clip) outer.add("overflow-hidden");
|
|
251
|
+
inner.resp(l.padding, (p) => SIDES.filter((s) => p[s] !== void 0).map((s) => tw$1.padding(s, p[s])));
|
|
252
|
+
inner.resp(l.gap, (g) => tw$1.gap(g));
|
|
253
|
+
inner.resp(l.textAlign, (t) => tw$1.textAlign(t));
|
|
254
|
+
outer.resp(l.minHeight, (v, bp) => {
|
|
255
|
+
if (typeof v === "number") outer.var(`--wc-mh-${bp}`, `${v}px`);
|
|
256
|
+
return [
|
|
257
|
+
tw$1.minHeight(v, bp),
|
|
258
|
+
"flex",
|
|
259
|
+
"flex-col"
|
|
260
|
+
];
|
|
261
|
+
});
|
|
262
|
+
if (l.minHeight) inner.add("flex-1", "w-full");
|
|
263
|
+
}
|
|
264
|
+
/** `priority`: the page's first block; its image loads at once, with high priority. */
|
|
265
|
+
function background(b, priority) {
|
|
266
|
+
if (!b) return null;
|
|
267
|
+
if (!(b.asset || b.gradients?.length || b.opacity !== void 0)) return null;
|
|
268
|
+
const position = b.position ?? "cover";
|
|
269
|
+
const fit = position === "cover" || position === "contain" || position === "fill" ? position : "none";
|
|
270
|
+
const assetStyle = {
|
|
271
|
+
objectFit: fit,
|
|
272
|
+
objectPosition: fit === "none" ? (b.position ?? "center").replace("-", " ") : "center",
|
|
273
|
+
opacity: b.color ? void 0 : b.opacity,
|
|
274
|
+
filter: b.blur ? `blur(${b.blur}px)` : void 0,
|
|
275
|
+
transform: b.blur ? "scale(1.05)" : void 0
|
|
276
|
+
};
|
|
277
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
278
|
+
className: "wc-bg absolute inset-0 -z-0 overflow-hidden",
|
|
279
|
+
"aria-hidden": "true",
|
|
280
|
+
"data-parallax": b.parallax ? "" : void 0,
|
|
281
|
+
children: [
|
|
282
|
+
b.base && /* @__PURE__ */ jsx("div", {
|
|
283
|
+
className: "absolute inset-0",
|
|
284
|
+
style: { backgroundColor: cssColor(b.base) }
|
|
285
|
+
}),
|
|
286
|
+
b.asset && /* @__PURE__ */ jsx(BackgroundAsset, {
|
|
287
|
+
asset: b.asset,
|
|
288
|
+
style: assetStyle,
|
|
289
|
+
parallax: b.parallax ?? false,
|
|
290
|
+
fit,
|
|
291
|
+
priority
|
|
292
|
+
}),
|
|
293
|
+
b.color && /* @__PURE__ */ jsx("div", {
|
|
294
|
+
className: "absolute inset-0",
|
|
295
|
+
style: {
|
|
296
|
+
backgroundColor: cssColor(b.color),
|
|
297
|
+
opacity: b.opacity
|
|
298
|
+
}
|
|
299
|
+
}),
|
|
300
|
+
[...b.gradients ?? []].reverse().map((g, i) => /* @__PURE__ */ jsx("div", {
|
|
301
|
+
className: "absolute inset-0",
|
|
302
|
+
style: { backgroundImage: gradientCss(g) }
|
|
303
|
+
}, i))
|
|
304
|
+
]
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
function BackgroundAsset({ asset, style, parallax, fit, priority }) {
|
|
308
|
+
const cls = parallax ? "wc-parallax absolute inset-x-0 -top-[20%] h-[140%] w-full" : "absolute inset-0 h-full w-full";
|
|
309
|
+
if (asset.kind === "video") return /* @__PURE__ */ jsx("video", {
|
|
310
|
+
className: cls,
|
|
311
|
+
style,
|
|
312
|
+
src: asset.url,
|
|
313
|
+
poster: posterOf(asset),
|
|
314
|
+
autoPlay: true,
|
|
315
|
+
muted: true,
|
|
316
|
+
loop: true,
|
|
317
|
+
playsInline: true
|
|
318
|
+
});
|
|
319
|
+
if (asset.kind === "remote-video") return null;
|
|
320
|
+
const img = /* @__PURE__ */ jsx("img", {
|
|
321
|
+
className: cls,
|
|
322
|
+
style,
|
|
323
|
+
src: asset.url,
|
|
324
|
+
...fit === "contain" || fit === "fill" ? imageSrcSet(asset, { fit }, { eager: priority }) : fullSrcSet(asset),
|
|
325
|
+
alt: asset.alt ?? "",
|
|
326
|
+
width: asset.width,
|
|
327
|
+
height: asset.height,
|
|
328
|
+
...priority ? { fetchPriority: "high" } : { loading: "lazy" },
|
|
329
|
+
decoding: "async"
|
|
330
|
+
});
|
|
331
|
+
const portrait = asset.portrait;
|
|
332
|
+
if (fit !== "cover" || !portrait || parallax) return img;
|
|
333
|
+
return /* @__PURE__ */ jsxs("picture", { children: [/* @__PURE__ */ jsx("source", {
|
|
334
|
+
media: PORTRAIT_MEDIA,
|
|
335
|
+
srcSet: `${portrait.url} 1x`
|
|
336
|
+
}), img] });
|
|
337
|
+
}
|
|
338
|
+
function gradientCss(g) {
|
|
339
|
+
const stops = g.stops.map((s) => `${cssColor(s.color, s.opacity)}${s.at !== void 0 ? ` ${s.at}%` : ""}`).join(", ");
|
|
340
|
+
if (g.kind === "linear") return `linear-gradient(${g.angle ?? 180}deg, ${stops})`;
|
|
341
|
+
return `radial-gradient(circle at ${(g.center ?? "center").replace("-", " ")}, ${stops})`;
|
|
342
|
+
}
|
|
343
|
+
function edgeStyle(e) {
|
|
344
|
+
const top = e?.top && e.top !== "straight" ? EDGE_PATH[e.top] : void 0;
|
|
345
|
+
const bottom = e?.bottom && e.bottom !== "straight" ? EDGE_PATH[e.bottom] : void 0;
|
|
346
|
+
if (!top && !bottom) return {};
|
|
347
|
+
const svg = (d) => `url("data:image/svg+xml,${encodeURIComponent(`<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' preserveAspectRatio='none'><path d='${d}'/></svg>`)}")`;
|
|
348
|
+
const layers = [];
|
|
349
|
+
const sizes = [];
|
|
350
|
+
const positions = [];
|
|
351
|
+
const repeat = [];
|
|
352
|
+
if (top) {
|
|
353
|
+
layers.push(svg(top(false)));
|
|
354
|
+
sizes.push(`100% ${EDGE_HEIGHT}`);
|
|
355
|
+
positions.push("top");
|
|
356
|
+
repeat.push("no-repeat");
|
|
357
|
+
}
|
|
358
|
+
if (bottom) {
|
|
359
|
+
layers.push(svg(bottom(true)));
|
|
360
|
+
sizes.push(`100% ${EDGE_HEIGHT}`);
|
|
361
|
+
positions.push("bottom");
|
|
362
|
+
repeat.push("no-repeat");
|
|
363
|
+
}
|
|
364
|
+
layers.push("linear-gradient(#000, #000)");
|
|
365
|
+
sizes.push(`100% calc(100% - ${top ? EDGE_HEIGHT : "0px"} - ${bottom ? EDGE_HEIGHT : "0px"} + 2px)`);
|
|
366
|
+
positions.push(`0 calc(${top ? EDGE_HEIGHT : "0px"} - 1px)`);
|
|
367
|
+
repeat.push("no-repeat");
|
|
368
|
+
const mask = {
|
|
369
|
+
maskImage: layers.join(", "),
|
|
370
|
+
maskSize: sizes.join(", "),
|
|
371
|
+
maskPosition: positions.join(", "),
|
|
372
|
+
maskRepeat: repeat.join(", ")
|
|
373
|
+
};
|
|
374
|
+
return {
|
|
375
|
+
...mask,
|
|
376
|
+
WebkitMaskImage: mask.maskImage,
|
|
377
|
+
WebkitMaskSize: mask.maskSize,
|
|
378
|
+
WebkitMaskPosition: mask.maskPosition,
|
|
379
|
+
WebkitMaskRepeat: mask.maskRepeat
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
function DecorationEl({ d, breakpoints }) {
|
|
383
|
+
const [v, h] = d.anchor.includes("-") ? d.anchor.split("-") : [
|
|
384
|
+
"center",
|
|
385
|
+
"top",
|
|
386
|
+
"bottom"
|
|
387
|
+
].includes(d.anchor) ? [d.anchor, "center"] : ["center", d.anchor];
|
|
388
|
+
const style = { width: d.width };
|
|
389
|
+
const transform = [];
|
|
390
|
+
if (v === "top" || v === "bottom") style[v] = d.offsetY ?? 0;
|
|
391
|
+
else {
|
|
392
|
+
style.top = "50%";
|
|
393
|
+
transform.push("translateY(-50%)");
|
|
394
|
+
}
|
|
395
|
+
if (h === "left" || h === "right") style[h] = d.offsetX ?? 0;
|
|
396
|
+
else {
|
|
397
|
+
style.left = "50%";
|
|
398
|
+
transform.push("translateX(-50%)");
|
|
399
|
+
}
|
|
400
|
+
style.transform = transform.join(" ") || void 0;
|
|
401
|
+
const c = new Classes$1(breakpoints).add("wc-deco", "pointer-events-none", "absolute", "z-0", "[&>svg]:block", "[&>svg]:h-auto", "[&>svg]:w-full");
|
|
402
|
+
c.resp(d.visible, (shown) => shown ? "block" : "hidden");
|
|
403
|
+
return /* @__PURE__ */ jsx(Svg, {
|
|
404
|
+
className: c.className,
|
|
405
|
+
style,
|
|
406
|
+
svg: d.svg
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
//#endregion
|
|
410
|
+
//#region src/consent-script.min.ts
|
|
411
|
+
/** `consentHead`, minified: `(${consentHeadSource})(…)`. */
|
|
412
|
+
const consentHeadSource = "function(a){const t=window;t.dataLayer=t.dataLayer||[],t.gtag||(t.gtag=function(){t.dataLayer.push(arguments)});const g=Object.keys(a.categories),l=g.flatMap(e=>a.categories[e]),r=e=>{const o={};for(const s of g)for(const u of a.categories[s])o[u]=e?.[s]?\"granted\":\"denied\";return o};let n=null;try{const e=JSON.parse(localStorage.getItem(a.key)||\"null\"),o=Date.now();if(e?.v===a.version&&e.c&&typeof e.t==\"number\"&&e.t<=o&&o-e.t<a.maxAgeDays*864e5){n={};for(const s of g)n[s]=e.c[s]===!0}}catch{}const d=a.google?.ids??[];(l.length||d.length)&&(t.gtag(\"consent\",\"default\",{ad_storage:\"denied\",ad_user_data:\"denied\",ad_personalization:\"denied\",analytics_storage:\"denied\",...r(null),wait_for_update:500}),t.gtag(\"set\",\"ads_data_redaction\",!0),t.gtag(\"set\",\"url_passthrough\",!0),n&&t.gtag(\"consent\",\"update\",r(n)));const c=e=>{if(a.load===\"eager\"){e();return}const o=()=>{t.requestIdleCallback?t.requestIdleCallback(e,{timeout:2e3}):setTimeout(e,1)};document.readyState===\"complete\"?o():t.addEventListener(\"load\",o,{once:!0})},i=a.hosts.includes(location.hostname);if(t.__wcConsent={config:a,choice:n,allowed:i,later:c},i&&d.length){t.gtag(\"js\",new Date);for(const e of d)t.gtag(\"config\",e);c(()=>{const e=document.createElement(\"script\");e.async=!0,e.src=`https://www.googletagmanager.com/gtag/js?id=${encodeURIComponent(d[0])}`,document.head.appendChild(e)})}}";
|
|
413
|
+
/** `mountConsent`, minified: `(${mountConsentSource})(…)`. */
|
|
414
|
+
const mountConsentSource = "function(){const l=window,o=document,f=l.__wcConsent;if(!f||l.wcConsent)return;const s=f.config,d=Object.keys(s.categories),h=o.getElementById(\"wc-consent-banner\"),i=o.getElementById(\"wc-consent-settings\"),m=new Set;let c=f.choice,u=null;const g=t=>t?{...t}:null,v=t=>Object.fromEntries(d.map(e=>[e,t?.[e]===!0])),C=t=>Object.fromEntries(d.flatMap(e=>s.categories[e].map(n=>[n,t[e]?\"granted\":\"denied\"]))),S=t=>{const e=[],n=s.categories[t]||[];return n.includes(\"analytics_storage\")&&e.push(/^_ga($|_)/),n.includes(\"ad_storage\")&&e.push(/^_gcl_/),s.meta?.category===t&&e.push(/^_fb[pc]$/),e},M=t=>{const e=t.flatMap(S),n=location.hostname.split(\".\"),a=[\"\"];for(let r=0;r<n.length-1;r++)a.push(`; domain=.${n.slice(r).join(\".\")}`);for(const r of o.cookie.split(\";\")){const w=r.split(\"=\")[0].trim();if(w&&e.some(b=>b.test(w)))for(const b of a)o.cookie=`${w}=; Max-Age=0; path=/${b}`}},E=()=>{if(!s.meta||!f.allowed||l.fbq)return;const t=function e(){const n=arguments;e.callMethod?e.callMethod.apply(e,n):e.queue.push(n)};l.fbq=t,l._fbq=l._fbq||t,t.push=t,t.loaded=!0,t.version=\"2.0\",t.queue=[],f.later(()=>{const e=o.createElement(\"script\");e.async=!0,e.src=\"https://connect.facebook.net/en_US/fbevents.js\",o.head.appendChild(e)}),t(\"init\",s.meta.id),t(\"track\",\"PageView\")},q=t=>{const e=t.querySelector(\"template[data-wc-consent-content]\");e&&t.replaceWith(e.content.cloneNode(!0))},k=()=>{for(const t of o.querySelectorAll(\"[data-wc-consent-gate]\"))c?.[t.getAttribute(\"data-wc-consent-gate\")]&&q(t)},j=()=>{d.some(t=>s.categories[t].length)&&l.gtag(\"consent\",\"update\",C(c)),s.meta&&c[s.meta.category]&&E(),k()},p=t=>{const e=c;c=v(t);try{localStorage.setItem(s.key,JSON.stringify({v:s.version,t:Date.now(),c}))}catch{}h&&(h.hidden=!0),j();const n={choice:g(c),previous:g(e)};o.dispatchEvent(new CustomEvent(\"wc-consent\",{detail:n}));for(const r of m)try{r(g(c),g(e))}catch(w){console.error(w)}const a=e?d.filter(r=>e[r]&&!c[r]):[];a.length&&(M(a),location.reload())},y=()=>{if(i){for(const t of i.querySelectorAll(\"input[data-wc-consent-category]\"))t.checked=c?.[t.getAttribute(\"data-wc-consent-category\")]===!0;u=o.activeElement,i.open||i.showModal()}},O=()=>{i?.open&&i.close()};i?.addEventListener(\"keydown\",t=>{if(t.key!==\"Tab\")return;const e=[...i.querySelectorAll(\"a[href], button, input:not([disabled])\")],n=e[0],a=e[e.length-1];t.shiftKey&&o.activeElement===n?(t.preventDefault(),a.focus()):!t.shiftKey&&o.activeElement===a&&(t.preventDefault(),n.focus())}),i?.addEventListener(\"close\",()=>{u?.isConnected&&u.offsetParent!==null&&u.focus(),u=null});const _=t=>Object.fromEntries(d.map(e=>[e,t])),D={accept:()=>p(_(!0)),reject:()=>p(_(!1)),save:()=>{const t={};for(const e of i.querySelectorAll(\"input[data-wc-consent-category]\"))t[e.getAttribute(\"data-wc-consent-category\")]=e.checked;p(t)},settings:y,close:()=>{}};o.addEventListener(\"click\",t=>{const e=t.target instanceof Element?t.target:null,n=e?.closest(\"[data-wc-consent-action]\");if(n){t.preventDefault();const r=D[n.getAttribute(\"data-wc-consent-action\")];n.closest(\"#wc-consent-settings\")&&O(),r?.();return}if(e?.closest('[data-wc-consent-open], a[href=\"#wc-consent-settings\"]')){t.preventDefault(),y();return}const a=e?.closest(\"[data-wc-consent-gate]\");a&&e.closest(\"[data-wc-consent-load]\")?q(a):a&&e.closest(\"[data-wc-consent-allow]\")&&l.wcConsent.grant(a.getAttribute(\"data-wc-consent-gate\"))}),l.wcConsent={get:()=>g(c),set:p,grant:t=>p({...v(c),[t]:!0}),open:y,onChange:t=>(m.add(t),()=>m.delete(t))},!c&&h&&(h.hidden=!1);const A=()=>{for(const t of o.querySelectorAll(\"[data-wc-consent-actions]\"))t.hidden=!1;c&&(s.meta&&c[s.meta.category]&&E(),k())};o.readyState===\"loading\"?o.addEventListener(\"DOMContentLoaded\",A):A()}";
|
|
415
|
+
//#endregion
|
|
416
|
+
//#region src/consent.tsx
|
|
417
|
+
/** DOM event fired on document on every consent change. */
|
|
418
|
+
const CONSENT_EVENT = "wc-consent";
|
|
419
|
+
/** The gate's markup (see the header). */
|
|
420
|
+
function Gate({ gate, fallback, className, children }) {
|
|
421
|
+
const image = gate.poster;
|
|
422
|
+
const t = gate.text;
|
|
423
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
424
|
+
className: `wc-consent-gate ${className ?? ""}`,
|
|
425
|
+
"data-wc-consent-gate": gate.category,
|
|
426
|
+
"data-vendor": gate.vendor,
|
|
427
|
+
style: {
|
|
428
|
+
background: `var(--color-${gate.style.surface})`,
|
|
429
|
+
color: `var(--color-${gate.style.text})`
|
|
430
|
+
},
|
|
431
|
+
children: [/* @__PURE__ */ jsx("template", {
|
|
432
|
+
"data-wc-consent-content": "",
|
|
433
|
+
children
|
|
434
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
435
|
+
className: "relative flex h-full w-full flex-col items-center justify-center gap-3 overflow-hidden p-6 text-center",
|
|
436
|
+
children: [
|
|
437
|
+
image && /* @__PURE__ */ jsx("img", {
|
|
438
|
+
src: image,
|
|
439
|
+
alt: "",
|
|
440
|
+
loading: "lazy",
|
|
441
|
+
className: "absolute inset-0 h-full w-full object-cover opacity-25"
|
|
442
|
+
}),
|
|
443
|
+
/* @__PURE__ */ jsxs("p", {
|
|
444
|
+
className: "relative m-0 max-w-prose text-sm",
|
|
445
|
+
children: [t.notice, gate.privacy && /* @__PURE__ */ jsxs(Fragment, { children: [" ", /* @__PURE__ */ jsx("a", {
|
|
446
|
+
href: gate.privacy,
|
|
447
|
+
className: "underline",
|
|
448
|
+
children: t.privacy
|
|
449
|
+
})] })]
|
|
450
|
+
}),
|
|
451
|
+
/* @__PURE__ */ jsxs("div", {
|
|
452
|
+
className: "relative flex flex-wrap items-center justify-center gap-2",
|
|
453
|
+
"data-wc-consent-actions": "",
|
|
454
|
+
hidden: true,
|
|
455
|
+
children: [/* @__PURE__ */ jsx("button", {
|
|
456
|
+
type: "button",
|
|
457
|
+
className: "wc-button inline-flex items-center justify-center gap-2",
|
|
458
|
+
"data-variant": gate.style.choice,
|
|
459
|
+
"data-size": "sm",
|
|
460
|
+
"data-wc-consent-load": "",
|
|
461
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
462
|
+
className: "wc-button-label",
|
|
463
|
+
children: t.loadOnce
|
|
464
|
+
})
|
|
465
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
466
|
+
type: "button",
|
|
467
|
+
className: "wc-button inline-flex items-center justify-center gap-2",
|
|
468
|
+
"data-variant": gate.style.quiet,
|
|
469
|
+
"data-size": "sm",
|
|
470
|
+
"data-wc-consent-allow": "",
|
|
471
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
472
|
+
className: "wc-button-label",
|
|
473
|
+
children: t.allow
|
|
474
|
+
})
|
|
475
|
+
})]
|
|
476
|
+
}),
|
|
477
|
+
/* @__PURE__ */ jsx("a", {
|
|
478
|
+
href: fallback,
|
|
479
|
+
target: "_blank",
|
|
480
|
+
rel: "noopener noreferrer",
|
|
481
|
+
className: "relative text-sm underline",
|
|
482
|
+
children: t.open
|
|
483
|
+
})
|
|
484
|
+
]
|
|
485
|
+
})]
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Third-party content behind consent, for project blocks (e.g. an iframe
|
|
490
|
+
* Embed). Without a consent config the content renders directly.
|
|
491
|
+
*/
|
|
492
|
+
function ConsentGate({ ctx, category, vendor, fallback, labels, poster, className, children }) {
|
|
493
|
+
if (!ctx.consent) return /* @__PURE__ */ jsx(Fragment, { children });
|
|
494
|
+
const gate = gateOf(ctx.consent, category, vendor, labels);
|
|
495
|
+
if (poster && /^\/(?!\/)/.test(poster)) gate.poster = poster;
|
|
496
|
+
return /* @__PURE__ */ jsx(Gate, {
|
|
497
|
+
gate,
|
|
498
|
+
fallback,
|
|
499
|
+
className,
|
|
500
|
+
children
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
/** JSON for an inline script: `<` escaped so content cannot close it. */
|
|
504
|
+
function scriptJson$1(value) {
|
|
505
|
+
return JSON.stringify(value).replace(/</g, "\\u003c");
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Head part of the consent script for a page: first in <head>, before any
|
|
509
|
+
* other script. `extraHosts` extend the hosts where tags load (tests:
|
|
510
|
+
* localhost; never production).
|
|
511
|
+
*/
|
|
512
|
+
function consentHeadScript(consent, extraHosts = []) {
|
|
513
|
+
return `(${consentHeadSource})(${scriptJson$1(clientConsent(consent, extraHosts))})`;
|
|
514
|
+
}
|
|
515
|
+
/** Body part of the consent script, after the banner and the settings dialog. */
|
|
516
|
+
const consentScript = `(${mountConsentSource})()`;
|
|
517
|
+
//#endregion
|
|
518
|
+
//#region src/elements.tsx
|
|
519
|
+
/** Image, video or remote video (YouTube / Vimeo) of an Asset. */
|
|
520
|
+
function MediaElement({ block }) {
|
|
521
|
+
const a = block.asset;
|
|
522
|
+
const c = new Classes$1([]).add("wc-media", "relative", "overflow-hidden", "w-full");
|
|
523
|
+
if (block.rounded) c.add(tw$1.rounded(block.rounded));
|
|
524
|
+
if (block.shadow) c.add(tw$1.shadow(block.shadow));
|
|
525
|
+
if (block.fill) c.add("h-full");
|
|
526
|
+
const crop = Boolean(block.aspectRatio || block.fill);
|
|
527
|
+
const style = block.aspectRatio ? { aspectRatio: block.aspectRatio.replace(":", " / ") } : {};
|
|
528
|
+
const fit = block.fit ?? "cover";
|
|
529
|
+
const inner = crop ? `absolute inset-0 h-full w-full ${fit === "contain" ? "object-contain" : "object-cover"}` : "block h-auto w-full";
|
|
530
|
+
const box = crop ? {
|
|
531
|
+
fit,
|
|
532
|
+
ratio: block.aspectRatio ? aspectRatio(block.aspectRatio) : void 0
|
|
533
|
+
} : {};
|
|
534
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
535
|
+
className: c.className,
|
|
536
|
+
style,
|
|
537
|
+
children: [
|
|
538
|
+
a.kind === "image" && /* @__PURE__ */ jsx("img", {
|
|
539
|
+
className: inner,
|
|
540
|
+
src: a.url,
|
|
541
|
+
...imageSrcSet(a, box),
|
|
542
|
+
alt: a.alt ?? "",
|
|
543
|
+
width: a.width,
|
|
544
|
+
height: a.height,
|
|
545
|
+
loading: "lazy",
|
|
546
|
+
decoding: "async"
|
|
547
|
+
}),
|
|
548
|
+
a.kind === "video" && /* @__PURE__ */ jsx("video", {
|
|
549
|
+
className: inner,
|
|
550
|
+
src: a.url,
|
|
551
|
+
poster: posterOf(a),
|
|
552
|
+
controls: block.controls !== false,
|
|
553
|
+
autoPlay: block.controls === false,
|
|
554
|
+
muted: block.controls === false || block.muted,
|
|
555
|
+
loop: block.controls === false || block.loop,
|
|
556
|
+
playsInline: true
|
|
557
|
+
}),
|
|
558
|
+
a.kind === "remote-video" && /* @__PURE__ */ jsx(RemoteVideo, {
|
|
559
|
+
url: a.url,
|
|
560
|
+
title: a.alt,
|
|
561
|
+
consent: a.consent,
|
|
562
|
+
className: crop ? inner : "block aspect-video h-auto w-full"
|
|
563
|
+
})
|
|
564
|
+
]
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
/** "16:9" → 16 / 9 (undefined if malformed). */
|
|
568
|
+
function aspectRatio(value) {
|
|
569
|
+
const [w, h] = value.split(":").map(Number);
|
|
570
|
+
return w && h ? w / h : void 0;
|
|
571
|
+
}
|
|
572
|
+
const YOUTUBE = /(?:youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/embed\/)([\w-]{6,})/;
|
|
573
|
+
const VIMEO = /vimeo\.com\/(?:video\/)?(\d+)/;
|
|
574
|
+
/**
|
|
575
|
+
* YouTube / Vimeo embed (privacy-enhanced YouTube host). With `consent`
|
|
576
|
+
* (the loader sets it on remote videos of a site with consent) a consent
|
|
577
|
+
* gate stands in until the media category is granted.
|
|
578
|
+
*/
|
|
579
|
+
function RemoteVideo({ url, title, className, consent }) {
|
|
580
|
+
const yt = url.match(YOUTUBE)?.[1];
|
|
581
|
+
const vimeo = url.match(VIMEO)?.[1];
|
|
582
|
+
const src = yt ? `https://www.youtube-nocookie.com/embed/${yt}` : vimeo ? `https://player.vimeo.com/video/${vimeo}` : url;
|
|
583
|
+
const frame = /* @__PURE__ */ jsx("iframe", {
|
|
584
|
+
className,
|
|
585
|
+
src,
|
|
586
|
+
title: title ?? "Video",
|
|
587
|
+
loading: "lazy",
|
|
588
|
+
allow: "autoplay; fullscreen; picture-in-picture",
|
|
589
|
+
allowFullScreen: true
|
|
590
|
+
});
|
|
591
|
+
if (!consent) return frame;
|
|
592
|
+
return /* @__PURE__ */ jsx(Gate, {
|
|
593
|
+
gate: consent,
|
|
594
|
+
fallback: url,
|
|
595
|
+
className,
|
|
596
|
+
children: frame
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* Button: a link styled by theme CSS via `.wc-button[data-variant]`.
|
|
601
|
+
* `opens` toggles the page's popover with the fragment (no client JS). The
|
|
602
|
+
* page renders each dialog once (see Page); the loader has already decided
|
|
603
|
+
* between an #anchor url and its dialog (Button.opens as fallback).
|
|
604
|
+
* `url: consent:settings` renders a button the consent script answers by
|
|
605
|
+
* opening the consent settings (same look as the other buttons).
|
|
606
|
+
* Theme extensions of Button render through `children` (extra label
|
|
607
|
+
* content, e.g. a subtitle) and `attrs` (e.g. data-* for analytics).
|
|
608
|
+
*/
|
|
609
|
+
function ButtonEl({ button: b, className, children, attrs }) {
|
|
610
|
+
const content = /* @__PURE__ */ jsxs(Fragment, { children: [b.icon && /* @__PURE__ */ jsx(Svg, {
|
|
611
|
+
svg: b.icon,
|
|
612
|
+
className: "wc-button-icon inline-block h-[1.2em] w-[1.2em] shrink-0 [&>svg]:h-full [&>svg]:w-full"
|
|
613
|
+
}), !b.iconOnly && /* @__PURE__ */ jsxs("span", {
|
|
614
|
+
className: "wc-button-label flex flex-col",
|
|
615
|
+
children: [/* @__PURE__ */ jsx("span", { children: b.label }), children]
|
|
616
|
+
})] });
|
|
617
|
+
const common = {
|
|
618
|
+
className: `wc-button inline-flex items-center justify-center gap-2 ${className ?? ""}`,
|
|
619
|
+
"data-variant": b.variant ?? "primary",
|
|
620
|
+
"data-size": b.size ?? "md",
|
|
621
|
+
"data-icon-only": b.iconOnly ? "" : void 0,
|
|
622
|
+
title: b.title ?? (b.iconOnly ? b.label : void 0),
|
|
623
|
+
"aria-label": b.iconOnly ? b.label : void 0,
|
|
624
|
+
...attrs
|
|
625
|
+
};
|
|
626
|
+
if (b.url === CONSENT_SETTINGS) return /* @__PURE__ */ jsx("button", {
|
|
627
|
+
type: "button",
|
|
628
|
+
"aria-haspopup": "dialog",
|
|
629
|
+
"data-wc-consent-open": "",
|
|
630
|
+
...common,
|
|
631
|
+
children: content
|
|
632
|
+
});
|
|
633
|
+
if (b.opens && !b.url) return /* @__PURE__ */ jsx("button", {
|
|
634
|
+
type: "button",
|
|
635
|
+
popoverTarget: dialogId(b.opens),
|
|
636
|
+
...common,
|
|
637
|
+
children: content
|
|
638
|
+
});
|
|
639
|
+
return /* @__PURE__ */ jsx("a", {
|
|
640
|
+
href: b.url,
|
|
641
|
+
target: b.target,
|
|
642
|
+
rel: b.rel,
|
|
643
|
+
...common,
|
|
644
|
+
children: content
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
/** Url of a Button opening the consent settings. */
|
|
648
|
+
const CONSENT_SETTINGS = "consent:settings";
|
|
649
|
+
/** Element id of the dialog showing a fragment. */
|
|
650
|
+
function dialogId(ref) {
|
|
651
|
+
return `wc-dialog-${ref}`;
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* Popover dialog with a fragment's blocks (Button.opens). Page renders one
|
|
655
|
+
* per dialog the page opens; block components never render dialogs.
|
|
656
|
+
*/
|
|
657
|
+
function Dialog({ fragment, blocks, ctx }) {
|
|
658
|
+
const id = dialogId(fragment);
|
|
659
|
+
return /* @__PURE__ */ jsx("div", {
|
|
660
|
+
id,
|
|
661
|
+
popover: "auto",
|
|
662
|
+
className: "wc-dialog m-auto max-h-[90vh] w-[min(64rem,95vw)] overflow-auto rounded-xl p-0 backdrop:bg-black/60",
|
|
663
|
+
children: ctx.render(blocks, id)
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
const ICON_SIZE = {
|
|
667
|
+
sm: "size-6",
|
|
668
|
+
md: "size-10",
|
|
669
|
+
lg: "size-14",
|
|
670
|
+
xl: "size-18"
|
|
671
|
+
};
|
|
672
|
+
/** Icon: SVG or text glyph, sized by Icon.size, optional shape behind it. */
|
|
673
|
+
function IconEl({ icon }) {
|
|
674
|
+
const c = new Classes$1([]).add("wc-icon", "inline-flex", "items-center", "justify-center", "shrink-0", ICON_SIZE[icon.size ?? "md"], "[&>svg]:h-full", "[&>svg]:w-full");
|
|
675
|
+
paint(c, "text", icon.color);
|
|
676
|
+
if (icon.background) {
|
|
677
|
+
paint(c, "bg", icon.background);
|
|
678
|
+
c.add("p-2", icon.shape === "circle" ? "rounded-full" : icon.shape === "rounded" ? "rounded-lg" : "");
|
|
679
|
+
}
|
|
680
|
+
if (icon.svg) return /* @__PURE__ */ jsx(Svg, {
|
|
681
|
+
svg: icon.svg,
|
|
682
|
+
className: c.className,
|
|
683
|
+
style: c.style
|
|
684
|
+
});
|
|
685
|
+
return /* @__PURE__ */ jsx("span", {
|
|
686
|
+
className: `${c.className} font-bold`,
|
|
687
|
+
style: c.style,
|
|
688
|
+
children: icon.text
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
//#endregion
|
|
692
|
+
//#region src/registry.ts
|
|
693
|
+
/** Property marking a component that renders its own box (plain string: survives duplicate package copies). */
|
|
694
|
+
const OWN_BOX = "wcOwnBox";
|
|
695
|
+
/**
|
|
696
|
+
* Marks a block component that renders its box itself:
|
|
697
|
+
*
|
|
698
|
+
* export const Buttons = ownBox(function Buttons({ block, ctx }) {
|
|
699
|
+
* return <BoxFrame block={block} ctx={ctx} flat>…</BoxFrame>;
|
|
700
|
+
* });
|
|
701
|
+
*/
|
|
702
|
+
function ownBox(component) {
|
|
703
|
+
Object.defineProperty(component, OWN_BOX, { value: true });
|
|
704
|
+
return component;
|
|
705
|
+
}
|
|
706
|
+
function hasOwnBox(component) {
|
|
707
|
+
return component[OWN_BOX] === true;
|
|
708
|
+
}
|
|
709
|
+
/** Registry from a component map (usually the generated one, possibly with overrides). */
|
|
710
|
+
function createRegistry(components) {
|
|
711
|
+
return { components: Object.fromEntries(Object.entries(components).map(([type, c]) => [type, hasOwnBox(c) ? c : withBox(c)])) };
|
|
712
|
+
}
|
|
713
|
+
//#endregion
|
|
714
|
+
//#region src/render.tsx
|
|
715
|
+
/** Script element with the page data in annotate mode. */
|
|
716
|
+
const PAGE_DATA_ID = "wc-page";
|
|
717
|
+
/** @deprecated Use PAGE_DATA_ID. */
|
|
718
|
+
const INSPECT_ID = PAGE_DATA_ID;
|
|
719
|
+
/** Context for a page: render() resolves blocks through the registry. */
|
|
720
|
+
function createContext(page, opts) {
|
|
721
|
+
const ctx = {
|
|
722
|
+
...page.consent ? { consent: page.consent } : {},
|
|
723
|
+
locale: page.locale,
|
|
724
|
+
alternates: page.alternates,
|
|
725
|
+
homes: page.homes,
|
|
726
|
+
registry: opts.registry,
|
|
727
|
+
breakpoints: opts.breakpoints,
|
|
728
|
+
render: (blocks, key) => /* @__PURE__ */ jsx(Blocks, {
|
|
729
|
+
blocks,
|
|
730
|
+
ctx,
|
|
731
|
+
keyPrefix: key
|
|
732
|
+
})
|
|
733
|
+
};
|
|
734
|
+
return ctx;
|
|
735
|
+
}
|
|
736
|
+
function Blocks({ blocks, ctx, keyPrefix = "b", priority = false }) {
|
|
737
|
+
if (!blocks) return null;
|
|
738
|
+
return (Array.isArray(blocks) ? blocks : [blocks]).map((b, i) => /* @__PURE__ */ jsx(Block, {
|
|
739
|
+
block: b,
|
|
740
|
+
ctx: priority && i === 0 && !hiddenSomewhere(b) ? {
|
|
741
|
+
...ctx,
|
|
742
|
+
priority
|
|
743
|
+
} : ctx
|
|
744
|
+
}, keyOf(ctx, b) ?? `${keyPrefix}-${i}-${b.type}`));
|
|
745
|
+
}
|
|
746
|
+
/** Whether a block's `visible` hides it at any breakpoint. */
|
|
747
|
+
function hiddenSomewhere(b) {
|
|
748
|
+
const v = b.visible;
|
|
749
|
+
return v !== null && typeof v === "object" && Object.values(v).some((x) => x === false);
|
|
750
|
+
}
|
|
751
|
+
/** Annotate mode: the source path (with the Includes it came through), else the rendered path. */
|
|
752
|
+
function keyOf(ctx, b) {
|
|
753
|
+
const path = ctx.paths?.get(b);
|
|
754
|
+
if (path === void 0) return;
|
|
755
|
+
const s = ctx.annotation?.sources?.[path];
|
|
756
|
+
if (!s) return `@${path}`;
|
|
757
|
+
return [...s.via ?? [], s].map((x) => `${x.file}#${x.path}`).join(">");
|
|
758
|
+
}
|
|
759
|
+
function Block({ block, ctx }) {
|
|
760
|
+
const Component = ctx.registry.components[block.type];
|
|
761
|
+
const path = ctx.paths?.get(block);
|
|
762
|
+
if (path === void 0) {
|
|
763
|
+
if (!Component) throw new Error(`wunderweb: no component registered for block type "${block.type}"`);
|
|
764
|
+
return /* @__PURE__ */ jsx(Component, {
|
|
765
|
+
block,
|
|
766
|
+
ctx
|
|
767
|
+
});
|
|
768
|
+
}
|
|
769
|
+
const a = ctx.annotation ?? {};
|
|
770
|
+
const error = a.findings?.[path]?.find((f) => f.level === "error");
|
|
771
|
+
if (error || !Component) return /* @__PURE__ */ jsx(Placeholder, {
|
|
772
|
+
type: block.type,
|
|
773
|
+
path,
|
|
774
|
+
message: error?.message ?? "no component registered"
|
|
775
|
+
});
|
|
776
|
+
const fallback = /* @__PURE__ */ jsx(Placeholder, {
|
|
777
|
+
type: block.type,
|
|
778
|
+
path,
|
|
779
|
+
message: "failed to render"
|
|
780
|
+
});
|
|
781
|
+
const content = /* @__PURE__ */ jsx(Suspense, {
|
|
782
|
+
fallback,
|
|
783
|
+
children: /* @__PURE__ */ jsx(Component, {
|
|
784
|
+
block,
|
|
785
|
+
ctx: {
|
|
786
|
+
...ctx,
|
|
787
|
+
path
|
|
788
|
+
}
|
|
789
|
+
})
|
|
790
|
+
});
|
|
791
|
+
const Boundary = a.boundary;
|
|
792
|
+
return Boundary ? /* @__PURE__ */ jsx(Boundary, {
|
|
793
|
+
type: block.type,
|
|
794
|
+
path,
|
|
795
|
+
revision: a.revision,
|
|
796
|
+
fallback,
|
|
797
|
+
children: content
|
|
798
|
+
}) : content;
|
|
799
|
+
}
|
|
800
|
+
/** Stands in for a block that cannot render: its type and the finding. */
|
|
801
|
+
function Placeholder({ type, path, message }) {
|
|
802
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
803
|
+
"data-wc-error": "",
|
|
804
|
+
"data-block": type,
|
|
805
|
+
"data-wc-path": path,
|
|
806
|
+
role: "alert",
|
|
807
|
+
style: {
|
|
808
|
+
margin: "8px",
|
|
809
|
+
padding: "12px 16px",
|
|
810
|
+
border: "2px dashed #dc2626",
|
|
811
|
+
borderRadius: "6px",
|
|
812
|
+
background: "#fef2f2",
|
|
813
|
+
color: "#991b1b",
|
|
814
|
+
font: "13px/1.4 system-ui, sans-serif"
|
|
815
|
+
},
|
|
816
|
+
children: [
|
|
817
|
+
/* @__PURE__ */ jsx("strong", { children: type }),
|
|
818
|
+
": ",
|
|
819
|
+
message
|
|
820
|
+
]
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
/**
|
|
824
|
+
* Rendered path of every block in a tree, e.g.
|
|
825
|
+
* { blocks: [{ type: "SideBySide", start: { type: "Text" } }] }
|
|
826
|
+
* → SideBySide: "blocks/0", Text: "blocks/0/start"
|
|
827
|
+
*/
|
|
828
|
+
function blockPaths(node, path, out) {
|
|
829
|
+
if (!node || typeof node !== "object") return out;
|
|
830
|
+
if (BLOCK_TYPE.test(String(node.type))) out.set(node, path);
|
|
831
|
+
for (const [k, v] of Object.entries(node)) blockPaths(v, path ? `${path}/${k}` : k, out);
|
|
832
|
+
return out;
|
|
833
|
+
}
|
|
834
|
+
/** Block types are PascalCase; lower-case `type` keys are values, e.g. inputs. */
|
|
835
|
+
const BLOCK_TYPE = /^[A-Z]/;
|
|
836
|
+
/** Language switch data: locale → url of the translation, else the locale home. */
|
|
837
|
+
function languageLinks(ctx) {
|
|
838
|
+
return Object.fromEntries(Object.entries(ctx.homes).map(([l, home]) => [l, {
|
|
839
|
+
url: ctx.alternates[l] ?? home,
|
|
840
|
+
translated: l in ctx.alternates
|
|
841
|
+
}]));
|
|
842
|
+
}
|
|
843
|
+
/** JSON for an inline script: `<` escaped so content cannot close it. */
|
|
844
|
+
function scriptJson(value) {
|
|
845
|
+
return JSON.stringify(value).replace(/</g, "\\u003c");
|
|
846
|
+
}
|
|
847
|
+
/** Annotate options; `inspect` is the deprecated alias of `annotate: true`. */
|
|
848
|
+
function annotation(opts) {
|
|
849
|
+
if (opts.annotate === true || !opts.annotate && opts.inspect) return {};
|
|
850
|
+
return opts.annotate || void 0;
|
|
851
|
+
}
|
|
852
|
+
/** A full page: header, main content, footer. */
|
|
853
|
+
function Page({ page, ...opts }) {
|
|
854
|
+
const ctx = createContext(page, opts);
|
|
855
|
+
const { dialogs = {}, ...rest } = page;
|
|
856
|
+
const annotate = annotation(opts);
|
|
857
|
+
if (annotate) {
|
|
858
|
+
ctx.annotation = annotate;
|
|
859
|
+
ctx.paths = blockPaths({
|
|
860
|
+
header: page.header,
|
|
861
|
+
blocks: page.blocks,
|
|
862
|
+
footer: page.footer,
|
|
863
|
+
dialogs
|
|
864
|
+
}, "", /* @__PURE__ */ new WeakMap());
|
|
865
|
+
}
|
|
866
|
+
const origins = annotate?.editorOrigins ?? [];
|
|
867
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
868
|
+
page.header.length > 0 && /* @__PURE__ */ jsx("header", {
|
|
869
|
+
className: "wc-header",
|
|
870
|
+
children: /* @__PURE__ */ jsx(Blocks, {
|
|
871
|
+
blocks: page.header,
|
|
872
|
+
ctx,
|
|
873
|
+
keyPrefix: "h"
|
|
874
|
+
})
|
|
875
|
+
}),
|
|
876
|
+
/* @__PURE__ */ jsx("main", {
|
|
877
|
+
className: "wc-main",
|
|
878
|
+
"data-wc-revision": annotate?.revision,
|
|
879
|
+
children: /* @__PURE__ */ jsx(Blocks, {
|
|
880
|
+
blocks: page.blocks,
|
|
881
|
+
ctx,
|
|
882
|
+
priority: true
|
|
883
|
+
})
|
|
884
|
+
}),
|
|
885
|
+
page.footer.length > 0 && /* @__PURE__ */ jsx("footer", {
|
|
886
|
+
className: "wc-footer",
|
|
887
|
+
children: /* @__PURE__ */ jsx(Blocks, {
|
|
888
|
+
blocks: page.footer,
|
|
889
|
+
ctx,
|
|
890
|
+
keyPrefix: "f"
|
|
891
|
+
})
|
|
892
|
+
}),
|
|
893
|
+
Object.entries(dialogs).map(([ref, blocks]) => /* @__PURE__ */ jsx(Dialog, {
|
|
894
|
+
fragment: ref,
|
|
895
|
+
blocks,
|
|
896
|
+
ctx
|
|
897
|
+
}, ref)),
|
|
898
|
+
annotate && /* @__PURE__ */ jsx("script", {
|
|
899
|
+
id: "wc-page",
|
|
900
|
+
type: "application/json",
|
|
901
|
+
dangerouslySetInnerHTML: { __html: scriptJson({
|
|
902
|
+
revision: annotate.revision,
|
|
903
|
+
page: rest,
|
|
904
|
+
dialogs,
|
|
905
|
+
breakpoints: opts.breakpoints
|
|
906
|
+
}) }
|
|
907
|
+
}),
|
|
908
|
+
origins.length > 0 && /* @__PURE__ */ jsx("script", { dangerouslySetInnerHTML: { __html: `(${mountBridge})(${scriptJson({ origins })})` } })
|
|
909
|
+
] });
|
|
910
|
+
}
|
|
911
|
+
//#endregion
|
|
912
|
+
export { BASE, Block, Blocks, BoxFrame, ButtonEl, CONSENT_EVENT, Classes, ConsentGate, INSPECT_ID, IconEl, MediaElement, PAGE_DATA_ID, PORTRAIT_MEDIA, Page, RemoteVideo, RichText, Svg, at, consentHeadScript, consentScript, coverScale, createContext, createRegistry, cssColor, dialogId, fullSrcSet, gradientCss, hasOwnBox, imageSize, imageSrcSet, languageLinks, ownBox, paint, posterOf, ratioOf, tw, withBox };
|