@getquick/content 0.3.0 → 0.3.2

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.
@@ -1,528 +0,0 @@
1
- //#region frontend/src/wp-container-layout.ts
2
- const record = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : {};
3
- /** WPGraphQL renders nested blocks independently. Restore the parent's resolved
4
- * variables on direct container children without replacing their own layout. */
5
- function containerChildLayoutHtml(html, parentHtml) {
6
- const parentTag = parentHtml.match(/^\s*<div\b[^>]*>/i)?.[0] ?? "";
7
- if (!/\bgqd-container-layout\b/.test(parentTag)) return html;
8
- const declarations = [...(parentTag.match(/\sstyle="([^"]*)"/)?.[1] ?? "").matchAll(/--gqd-layout-([a-z-]+):([^;"']+)/g)].filter(([, , value]) => value === "auto" || layoutValue(value)).map(([, name, value]) => `--gqd-parent-layout-${name}:${value}`).join(";");
9
- if (!declarations) return html;
10
- return html.replace(/^(\s*<div\b)([^>]*)(>)/i, (_, tag, props, end) => {
11
- const style = /\sstyle="([^"]*)"/;
12
- props = style.test(props) ? props.replace(style, (_match, old) => ` style="${old};${declarations}"`) : `${props} style="${declarations}"`;
13
- return `${tag}${props}${end}`;
14
- });
15
- }
16
- function layoutValue(value) {
17
- if (typeof value !== "string" && typeof value !== "number") return "";
18
- const text = String(value);
19
- const preset = text.match(/^var:preset\|spacing\|([a-z0-9-]+)$/);
20
- if (preset) return `var(--wp--preset--spacing--${preset[1]})`;
21
- return /^(?:none|0|[0-9.]+(?:px|rem|em|%|vw|vh|ch)|(?:var|calc|min|max|clamp)\([a-zA-Z0-9_.,%()+*/ -]+\))$/.test(text) ? text : "";
22
- }
23
- /** Rendered CMS shells already carry resolved theme defaults. Saved shells need
24
- * the same opt-in adapter; absent defaults deliberately fall back to no width.
25
- */
26
- function containerLayoutHtml(html, attributes) {
27
- if (/\bgqd-container-layout\b/.test(html.match(/^\s*<[^>]+>/)?.[0] ?? "")) return html;
28
- const layout = record(attributes.layout);
29
- const spacing = record(record(attributes.style).spacing);
30
- const gap = spacing.blockGap;
31
- if (!Object.keys(layout).length && (gap === void 0 || gap === null || gap === "")) return html;
32
- const type = layout.inherit || layout.contentSize ? "constrained" : layout.type ?? "default";
33
- if (type !== "default" && type !== "constrained") return html;
34
- const content = layoutValue(layout.contentSize);
35
- const wide = layoutValue(layout.wideSize);
36
- const variables = [
37
- `--gqd-layout-content:${content || wide || "var(--wp--style--global--content-size, none)"}`,
38
- `--gqd-layout-wide:${wide || content || "var(--wp--style--global--wide-size, none)"}`,
39
- `--gqd-layout-gap:${layoutValue(typeof gap === "object" ? record(gap).top : gap) || "var(--wp--style--block-gap, 0)"}`
40
- ];
41
- let classes = "gqd-container-layout";
42
- if (type === "constrained") {
43
- classes += " gqd-container-layout--constrained";
44
- variables.push(`--gqd-layout-left:${layout.justifyContent === "left" ? "0" : "auto"}`, `--gqd-layout-right:${layout.justifyContent === "right" ? "0" : "auto"}`);
45
- for (const side of ["left", "right"]) variables.push(`--gqd-layout-padding-${side}:${layoutValue(typeof spacing.padding === "object" ? record(spacing.padding)[side] : spacing.padding) || "0px"}`);
46
- }
47
- return (html || "<div class=\"wp-block-getquick-design-container\"></div>").replace(/^(\s*<div\b)([^>]*)(>)/i, (_, tag, props, end) => {
48
- const add = (name, value, separator) => {
49
- const pattern = new RegExp(`(\\s)${name}="([^"]*)"`);
50
- props = pattern.test(props) ? props.replace(pattern, (_match, space, old) => `${space}${name}="${old}${separator}${value}"`) : `${props} ${name}="${value}"`;
51
- };
52
- add("class", classes, " ");
53
- add("style", variables.join(";"), ";");
54
- return `${tag}${props}${end}`;
55
- });
56
- }
57
- //#endregion
58
- //#region frontend/src/wp-block-renderer.ts
59
- const VIDEO_HERO_BLOCK = "getquick-design/video-hero";
60
- const YOUTUBE_ID_PATTERN = /^[A-Za-z0-9_-]{11}$/;
61
- const BLOCKS_WITH_RENDERED_CHILDREN = /* @__PURE__ */ new Set([
62
- "core/cover",
63
- "core/media-text",
64
- "core/navigation",
65
- "core/navigation-submenu"
66
- ]);
67
- function isRecord$1(value) {
68
- return typeof value === "object" && value !== null && !Array.isArray(value);
69
- }
70
- function normalizeBlock(value) {
71
- if (!isRecord$1(value) || typeof value.name !== "string") return null;
72
- const attributes = isRecord$1(value.attributes) ? value.attributes : void 0;
73
- const innerBlocks = Array.isArray(value.innerBlocks) ? value.innerBlocks.map(normalizeBlock).filter((block) => block !== null) : [];
74
- return {
75
- name: value.name,
76
- attributes,
77
- htmlContent: typeof value.htmlContent === "string" ? value.htmlContent : "",
78
- dynamicContent: typeof value.dynamicContent === "string" ? value.dynamicContent : void 0,
79
- innerBlocks
80
- };
81
- }
82
- function parseWordPressBlocks(value) {
83
- let parsed = value;
84
- for (let attempt = 0; attempt < 2 && typeof parsed === "string"; attempt += 1) try {
85
- parsed = JSON.parse(parsed);
86
- } catch {
87
- return [];
88
- }
89
- if (!Array.isArray(parsed)) return [];
90
- return parsed.map(normalizeBlock).filter((block) => block !== null);
91
- }
92
- function hasVideoHero(blocks) {
93
- return blocks.some((block) => block.name === "getquick-design/video-hero" || hasVideoHero(block.innerBlocks ?? []));
94
- }
95
- function escapeAttribute(value) {
96
- return value.replaceAll("&", "&amp;").replaceAll("\"", "&quot;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
97
- }
98
- function safeMediaUrl(value) {
99
- if (typeof value !== "string") return "";
100
- const url = value.trim();
101
- if (!url || url.startsWith("//")) return "";
102
- if (url.startsWith("/")) return url;
103
- try {
104
- const parsed = new URL(url);
105
- return parsed.protocol === "https:" || parsed.protocol === "http:" ? url : "";
106
- } catch {
107
- return "";
108
- }
109
- }
110
- function youtubeVideoId(value) {
111
- try {
112
- const url = new URL(value);
113
- if (url.protocol !== "https:" && url.protocol !== "http:") return "";
114
- const host = url.hostname.toLowerCase().replace(/^www\./, "");
115
- let id = "";
116
- if (host === "youtu.be") id = url.pathname.split("/").filter(Boolean)[0] ?? "";
117
- else if ([
118
- "youtube.com",
119
- "m.youtube.com",
120
- "youtube-nocookie.com"
121
- ].includes(host)) {
122
- id = url.searchParams.get("v") ?? "";
123
- if (!id) id = url.pathname.match(/^\/(?:embed|shorts|live)\/([^/]+)/)?.[1] ?? "";
124
- }
125
- return YOUTUBE_ID_PATTERN.test(id) ? id : "";
126
- } catch {
127
- return "";
128
- }
129
- }
130
- function videoMarkup(attributes) {
131
- const posterUrl = safeMediaUrl(attributes.posterUrl);
132
- const poster = posterUrl ? `<img class="wp-block-getquick-design-video-hero__poster" src="${escapeAttribute(posterUrl)}" alt="" decoding="async" />` : "";
133
- if (attributes.videoType === "youtube") {
134
- const videoId = typeof attributes.videoUrl === "string" ? youtubeVideoId(attributes.videoUrl) : "";
135
- if (!videoId) return poster;
136
- return `${poster}<iframe class="wp-block-getquick-design-video-hero__video wp-block-getquick-design-video-hero__video--youtube" src="https://www.youtube-nocookie.com/embed/${videoId}?${new URLSearchParams({
137
- autoplay: "1",
138
- mute: "1",
139
- controls: "0",
140
- loop: "1",
141
- playlist: videoId,
142
- playsinline: "1",
143
- rel: "0"
144
- }).toString()}" title="Decorative background video" allow="autoplay; encrypted-media" referrerpolicy="strict-origin-when-cross-origin" tabindex="-1" aria-hidden="true"></iframe>`;
145
- }
146
- const videoUrl = safeMediaUrl(attributes.videoUrl);
147
- if (!videoUrl) return poster;
148
- const posterAttribute = posterUrl ? ` poster="${escapeAttribute(posterUrl)}"` : "";
149
- return `<video class="wp-block-getquick-design-video-hero__video" src="${escapeAttribute(videoUrl)}"${posterAttribute} autoplay muted loop playsinline preload="metadata" aria-hidden="true"></video>`;
150
- }
151
- function rootSectionShell(html) {
152
- return html.match(/^\s*(<section\b[^>]*>)/i)?.[1] ?? "<section class=\"wp-block-getquick-design-video-hero\">";
153
- }
154
- function renderVideoHero(block, children) {
155
- return `${rootSectionShell(block.htmlContent ?? "")}<div class="wp-block-getquick-design-video-hero__media" aria-hidden="true">${videoMarkup(block.attributes ?? {})}</div><div class="wp-block-getquick-design-video-hero__content">${children}</div></section>`;
156
- }
157
- function appendChildren(html, children) {
158
- if (!children) return html;
159
- const closingTag = html.lastIndexOf("</");
160
- if (closingTag < 0) return `${html}${children}`;
161
- return `${html.slice(0, closingTag)}${children}${html.slice(closingTag)}`;
162
- }
163
- function renderBlock(block, parentContainerHtml = "") {
164
- const isContainer = block.name === "getquick-design/container";
165
- let html = isContainer ? containerLayoutHtml(block.htmlContent ?? "", block.attributes ?? {}) : block.htmlContent ?? "";
166
- if (isContainer && parentContainerHtml) html = containerChildLayoutHtml(html, parentContainerHtml);
167
- const children = (block.innerBlocks ?? []).map((child) => renderBlock(child, isContainer ? html : "")).join("");
168
- if (block.name === "getquick-design/video-hero") return renderVideoHero(block, children);
169
- if (!children || BLOCKS_WITH_RENDERED_CHILDREN.has(block.name)) return html;
170
- return appendChildren(html, children);
171
- }
172
- function renderWordPressBlocks(blocks) {
173
- return blocks.map((block) => renderBlock(block)).join("");
174
- }
175
- //#endregion
176
- //#region frontend/src/formatting.ts
177
- function responseStatus(delivery) {
178
- if (delivery.kind === "found") return 200;
179
- return delivery.kind === "missing" ? 404 : 503;
180
- }
181
- /**
182
- * WPGraphQL's GMT time ("2026-10-02T09:00:00", without a zone) in ms, or null
183
- * when it is absent or not a time.
184
- */
185
- function cmsTime(value) {
186
- if (!value) return null;
187
- const time = Date.parse(/(Z|[+-]\d\d:?\d\d)$/.test(value) ? value : `${value}Z`);
188
- return Number.isNaN(time) ? null : time;
189
- }
190
- /**
191
- * An entry's URI as a path. A CMS whose permalinks point at the Frontend gives
192
- * absolute URIs (`https://acme.example/team/`); only the path is the route.
193
- * Percent-encoding and the trailing slash are kept as WordPress gives them.
194
- */
195
- function uriPath(uri) {
196
- try {
197
- return new URL(uri, "https://frontend.invalid").pathname;
198
- } catch {
199
- return uri;
200
- }
201
- }
202
- function menuItemHref(url, internalOrigins) {
203
- try {
204
- const parsed = new URL(url, internalOrigins[0]);
205
- if (!internalOrigins.includes(parsed.origin)) return url;
206
- return `${parsed.pathname}${parsed.search}${parsed.hash}`;
207
- } catch {
208
- return url;
209
- }
210
- }
211
- function stripHtml(value) {
212
- return value.replace(/<[^>]*>/g, "").replace(/\s+/g, " ").trim();
213
- }
214
- /** The named character references WordPress's text commonly has (wptexturize writes most as numbers). */
215
- const NAMED_ENTITIES = {
216
- amp: "&",
217
- lt: "<",
218
- gt: ">",
219
- quot: "\"",
220
- apos: "'",
221
- nbsp: "\xA0",
222
- ndash: "–",
223
- mdash: "—",
224
- lsquo: "‘",
225
- rsquo: "’",
226
- ldquo: "“",
227
- rdquo: "”",
228
- hellip: "…"
229
- };
230
- /**
231
- * Text with its HTML character references decoded: numeric ones, and the
232
- * named ones in NAMED_ENTITIES (any other is left as written).
233
- */
234
- function decodeEntities(value) {
235
- return value.replace(/&(#x[0-9a-f]+|#[0-9]+|[a-z]+);/gi, (reference, name) => {
236
- if (name[0] !== "#") return NAMED_ENTITIES[name.toLowerCase()] ?? reference;
237
- const code = name[1] === "x" || name[1] === "X" ? parseInt(name.slice(2), 16) : Number(name.slice(1));
238
- return code > 0 && code <= 1114111 ? String.fromCodePoint(code) : reference;
239
- });
240
- }
241
- function formatDate(value, lang = "en") {
242
- return new Intl.DateTimeFormat(lang, {
243
- day: "numeric",
244
- month: "long",
245
- year: "numeric"
246
- }).format(new Date(value));
247
- }
248
- function routeOf(path) {
249
- let route = path;
250
- try {
251
- route = decodeURI(path);
252
- } catch {}
253
- if (!route.startsWith("/")) route = `/${route}`;
254
- return route.endsWith("/") ? route : `${route}/`;
255
- }
256
- //#endregion
257
- //#region frontend/src/design-patterns.ts
258
- function isRecord(value) {
259
- return typeof value === "object" && value !== null && !Array.isArray(value);
260
- }
261
- /**
262
- * A complete pattern tree from JSON text or a parsed list. Malformed nodes
263
- * fail the whole read: dropping one could promote a partial header or footer.
264
- * PHP's empty attributes (`[]`) normalize to an object.
265
- */
266
- function parseDesignBlocks(value) {
267
- let parsed = value;
268
- if (typeof parsed === "string") try {
269
- parsed = JSON.parse(parsed);
270
- } catch {
271
- return;
272
- }
273
- let count = 0;
274
- const blocks = (value, depth) => {
275
- if (!Array.isArray(value) || value.length > 0 && depth > 32) return void 0;
276
- const result = [];
277
- for (const item of value) {
278
- if (++count > 1e3 || !isRecord(item) || typeof item.name !== "string" || !item.name) return void 0;
279
- const attributes = isRecord(item.attributes) ? item.attributes : Array.isArray(item.attributes) && item.attributes.length === 0 ? {} : void 0;
280
- if (!attributes || item.content !== null && typeof item.content !== "string") return void 0;
281
- const children = blocks(item.children, depth + 1);
282
- if (!children) return void 0;
283
- result.push({
284
- name: item.name,
285
- attributes,
286
- content: item.content,
287
- children
288
- });
289
- }
290
- return result;
291
- };
292
- return blocks(parsed, 0);
293
- }
294
- function escapeHtml(value) {
295
- return value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("\"", "&quot;").replaceAll("'", "&#39;");
296
- }
297
- /** Inserts children before the HTML's last closing tag, where WordPress's wrappers keep them. */
298
- function insertChildren(html, children) {
299
- if (!children) return html;
300
- const closingTag = html.lastIndexOf("</");
301
- if (closingTag < 0) return `${html}${children}`;
302
- return `${html.slice(0, closingTag)}${children}${html.slice(closingTag)}`;
303
- }
304
- function linkHref(url, internalOrigins) {
305
- if (typeof url !== "string" || !url.trim()) return "#";
306
- const href = internalOrigins.length > 0 ? menuItemHref(url.trim(), internalOrigins) : url.trim();
307
- if (/^\/(?!\/)/.test(href) || href.startsWith("#") || href.startsWith("?")) return href;
308
- try {
309
- const protocol = new URL(href).protocol;
310
- return protocol === "https:" || protocol === "http:" || protocol === "mailto:" || protocol === "tel:" ? href : "#";
311
- } catch {
312
- return "#";
313
- }
314
- }
315
- /** A media URL as an image source: http(s) only, never another scheme. */
316
- function mediaUrl(value) {
317
- if (typeof value !== "string") return null;
318
- try {
319
- const protocol = new URL(value).protocol;
320
- return protocol === "https:" || protocol === "http:" ? value : null;
321
- } catch {
322
- return null;
323
- }
324
- }
325
- function designLogo(value) {
326
- const url = isRecord(value) ? mediaUrl(value.url) : null;
327
- if (!isRecord(value) || !url) return null;
328
- const size = (item) => typeof item === "number" && item > 0 ? item : null;
329
- return {
330
- url,
331
- alt: typeof value.alt === "string" ? value.alt : "",
332
- width: size(value.width),
333
- height: size(value.height)
334
- };
335
- }
336
- /**
337
- * GQ Design's Site Logo node carries the Branding logo itself (`logo`, null
338
- * when unset) and its authored `width`, `isLink` and `linkTarget`, so it
339
- * renders without another read. Without a logo, nothing: the Site's own
340
- * renderer can show its title instead.
341
- */
342
- const renderSiteLogo = (block, context) => {
343
- const logo = designLogo(block.attributes.logo);
344
- if (!logo) return "";
345
- const width = typeof block.attributes.width === "number" ? block.attributes.width : logo.width;
346
- const size = [width ? ` width="${width}"` : "", width && logo.width && logo.height ? ` height="${Math.round(width * logo.height / logo.width)}"` : !width && logo.height ? ` height="${logo.height}"` : ""].join("");
347
- const image = `<img class="custom-logo" src="${escapeHtml(logo.url)}" alt="${escapeHtml(logo.alt)}"${size} decoding="async" />`;
348
- const className = typeof block.attributes.className === "string" ? ` ${block.attributes.className}` : "";
349
- const linked = block.attributes.isLink === false ? image : `<a href="${escapeHtml(context.href(context.home))}" class="custom-logo-link" ${block.attributes.linkTarget === "_blank" ? "target=\"_blank\" rel=\"home noopener\"" : "rel=\"home\""}>${image}</a>`;
350
- return `<div class="wp-block-site-logo${escapeHtml(className)}">${linked}</div>`;
351
- };
352
- const BUILT_IN = { "core/site-logo": renderSiteLogo };
353
- /** The elements a container's `tagName` may choose, as WordPress's Group block offers them. */
354
- const CONTAINER_TAGS = /* @__PURE__ */ new Set([
355
- "div",
356
- "header",
357
- "footer",
358
- "main",
359
- "section",
360
- "article",
361
- "aside",
362
- "nav"
363
- ]);
364
- const SLUG = /^[a-z0-9-]+$/;
365
- /** GQ Design's layout container, whose width, gap and padding content also restores. */
366
- const DESIGN_CONTAINER = "getquick-design/container";
367
- /**
368
- * A container block (one with children) as WordPress wraps it. GQ Design
369
- * sends saved HTML only for blocks without children, so a container's wrapper
370
- * is rebuilt from its name and attributes: its element (`tagName`), its default
371
- * class (`wp-block-group` for `core/group`, `wp-block-acme-hero` for
372
- * `acme/hero`), and the classes WordPress derives from `className`, `align`,
373
- * its preset colours and its layout type. Other styles (custom colours,
374
- * spacing) need a Site renderer. GQ Design's own container
375
- * (`getquick-design/container`) also gets its layout, as in content.
376
- */
377
- function containerHtml(block, children) {
378
- const { tagName, className, align, backgroundColor, textColor, layout } = block.attributes;
379
- const tag = typeof tagName === "string" && CONTAINER_TAGS.has(tagName) ? tagName : "div";
380
- const classes = [`wp-block-${block.name.replace(/^core\//, "").replaceAll("/", "-")}`];
381
- if (typeof className === "string" && className.trim()) classes.push(className.trim());
382
- if (typeof align === "string" && SLUG.test(align)) classes.push(`align${align}`);
383
- if (typeof backgroundColor === "string" && SLUG.test(backgroundColor)) classes.push(`has-${backgroundColor}-background-color`, "has-background");
384
- if (typeof textColor === "string" && SLUG.test(textColor)) classes.push(`has-${textColor}-color`, "has-text-color");
385
- const layoutType = isRecord(layout) ? layout.type : void 0;
386
- if (typeof layoutType === "string" && SLUG.test(layoutType)) classes.push(`is-layout-${layoutType}`);
387
- return `<${tag} class="${escapeHtml(classes.join(" "))}">${children}</${tag}>`;
388
- }
389
- /**
390
- * A pattern (or blocks of one) as HTML. Each block is rendered by the Site's
391
- * renderer for its name, else a built-in one, else as the HTML WordPress saved
392
- * for it, else, with children, as a WordPress container wrapping them. A block
393
- * with none of those (a dynamic block, such as a Site's own) renders nothing
394
- * and is reported to `onUnrendered`. Null renders nothing, so the Site keeps
395
- * its own header or footer.
396
- */
397
- function renderDesignPattern(pattern, options = {}) {
398
- if (!pattern) return "";
399
- const renderers = {
400
- ...BUILT_IN,
401
- ...options.blocks
402
- };
403
- const internalOrigins = options.internalOrigins ?? [];
404
- const href = (url) => linkHref(url, internalOrigins);
405
- const renderAll = (blocks, ancestors, parentContainer = "") => blocks.map((block) => renderOne(block, ancestors, parentContainer)).join("");
406
- function renderOne(block, ancestors, parentContainer) {
407
- const inside = [...ancestors, block];
408
- const renderer = Object.hasOwn(renderers, block.name) ? renderers[block.name] : void 0;
409
- if (renderer) {
410
- let children;
411
- return renderer(block, {
412
- get children() {
413
- return children ??= renderAll(block.children, inside);
414
- },
415
- ancestors,
416
- render: (blocks) => renderAll(blocks, inside),
417
- href,
418
- home: options.home ?? "/"
419
- });
420
- }
421
- if (block.name === DESIGN_CONTAINER && (block.children.length > 0 || block.content !== null)) {
422
- let wrapper = containerLayoutHtml(block.content ?? containerHtml(block, ""), block.attributes);
423
- if (parentContainer) wrapper = containerChildLayoutHtml(wrapper, parentContainer);
424
- return insertChildren(wrapper, renderAll(block.children, inside, wrapper));
425
- }
426
- const children = renderAll(block.children, inside);
427
- if (block.content !== null) return insertChildren(block.content, children);
428
- if (block.children.length > 0) return containerHtml(block, children);
429
- options.onUnrendered?.(block);
430
- return "";
431
- }
432
- return renderAll(Array.isArray(pattern) ? pattern : pattern.blocks, []);
433
- }
434
- /**
435
- * A menu a Site block carries in its attributes (a flat list of `{ id,
436
- * parentId, label, url, target }`, as GQ Design's serializer filter documents
437
- * for `getquick/header-navigation`) as a tree, with each link as the
438
- * Frontend serves it. Items that aren't menu items are left out; one whose
439
- * parent isn't listed, or that is in a cycle of parents, is a top-level item.
440
- */
441
- function designMenuItems(value, href = (url) => linkHref(url, [])) {
442
- if (!Array.isArray(value)) return [];
443
- const id = (item) => typeof item === "number" || typeof item === "string" ? String(item) : "";
444
- const seen = /* @__PURE__ */ new Set();
445
- const items = value.filter(isRecord).filter((item) => {
446
- const key = id(item.id);
447
- if (!key || seen.has(key)) return false;
448
- seen.add(key);
449
- return true;
450
- });
451
- const byId = /* @__PURE__ */ new Map();
452
- const parentOf = /* @__PURE__ */ new Map();
453
- for (const item of items) {
454
- const parentId = id(item.parentId);
455
- if (parentId && parentId !== "0") parentOf.set(id(item.id), parentId);
456
- byId.set(id(item.id), {
457
- id: id(item.id),
458
- label: typeof item.label === "string" ? item.label : "",
459
- href: href(item.url),
460
- target: item.target === "_blank" ? "_blank" : null,
461
- children: []
462
- });
463
- }
464
- const inCycle = (start) => {
465
- const visited = /* @__PURE__ */ new Set();
466
- for (let at = parentOf.get(start); at !== void 0; at = parentOf.get(at)) {
467
- if (at === start) return true;
468
- if (visited.has(at)) return false;
469
- visited.add(at);
470
- }
471
- return false;
472
- };
473
- const roots = [];
474
- for (const [key, node] of byId) {
475
- const parentId = parentOf.get(key);
476
- const parent = parentId !== void 0 && !inCycle(key) ? byId.get(parentId) : void 0;
477
- (parent ? parent.children : roots).push(node);
478
- }
479
- return roots;
480
- }
481
- //#endregion
482
- //#region frontend/src/site-language.ts
483
- /**
484
- * The `<html lang>` for a WordPress locale: its language and region as a
485
- * BCP 47 tag (pt_PT_ao90 → pt-PT). WordPress's variants (ao90, formal) aren't
486
- * BCP 47 subtags, so they are left out; no locale means English.
487
- */
488
- function htmlLang(locale) {
489
- if (!locale) return "en";
490
- return locale.split("_").slice(0, 2).join("-");
491
- }
492
- /**
493
- * configuration's languages: wordpress.locale, the default, served at /, then
494
- * each of wordpress.languages under its slug. A monolingual Site has one.
495
- */
496
- function siteLanguages(wordpress) {
497
- const locale = wordpress?.locale ?? "";
498
- const language = (locale, slug, isDefault) => ({
499
- locale,
500
- slug,
501
- code: slug.toUpperCase().replaceAll("-", "_"),
502
- lang: htmlLang(locale),
503
- isDefault,
504
- home: isDefault ? "/" : `/${slug}/`
505
- });
506
- return [language(locale, locale.split("_")[0] || "en", true), ...(wordpress?.languages ?? []).map(({ locale, slug }) => language(locale, slug, false))];
507
- }
508
- /**
509
- * A route's language: the one whose slug is its first segment, else the
510
- * default language, which has no directory.
511
- */
512
- function routeLanguage(route, among) {
513
- const segment = route.split("/")[1];
514
- return among.find((language) => !language.isDefault && language.slug === segment) ?? among[0];
515
- }
516
- /**
517
- * How logs and reports name something a language has: "the front page" for
518
- * the default language's, "the en front page" for another's.
519
- */
520
- function languageSubject(language, what) {
521
- return language.isDefault ? `the ${what}` : `the ${language.slug} ${what}`;
522
- }
523
- /** Whether a route is a language's home (/, /en/): served as a home, never as an entry. */
524
- function isLanguageHome(route, among) {
525
- return among.some((language) => language.home === route);
526
- }
527
- //#endregion
528
- export { containerChildLayoutHtml as C, youtubeVideoId as S, uriPath as _, siteLanguages as a, parseWordPressBlocks as b, parseDesignBlocks as c, decodeEntities as d, formatDate as f, stripHtml as g, routeOf as h, routeLanguage as i, renderDesignPattern as l, responseStatus as m, isLanguageHome as n, designMenuItems as o, menuItemHref as p, languageSubject as r, escapeHtml as s, htmlLang as t, cmsTime as u, VIDEO_HERO_BLOCK as v, containerLayoutHtml as w, renderWordPressBlocks as x, hasVideoHero as y };