ferst-core 0.15.0 → 0.17.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/NOTICE +63 -31
- package/README.md +13 -4
- package/bin/ferst-media.mjs +96 -0
- package/bin/ferst-modules.mjs +17 -2
- package/components/BlockRenderer.astro +131 -129
- package/components/Card.astro +53 -51
- package/components/MembersAccount.astro +370 -0
- package/components/PostCard.astro +138 -136
- package/components/SiteHeader.astro +32 -14
- package/components/blocks/Grid.astro +49 -48
- package/components/blocks/Heading.astro +4 -1
- package/components/islands/BookMonth.tsx +95 -0
- package/components/islands/MembersAccount.tsx +392 -0
- package/components/recipes/Banner.astro +146 -146
- package/components/recipes/Book.astro +1147 -926
- package/components/recipes/FeatureCards.astro +112 -118
- package/components/recipes/Gallery.astro +57 -59
- package/components/recipes/Hero.astro +112 -10
- package/components/recipes/LatestPosts.astro +295 -292
- package/components/recipes/Locations.astro +146 -143
- package/components/recipes/Marquee.astro +75 -75
- package/components/recipes/MediaCards.astro +213 -219
- package/components/recipes/MembersContent.astro +176 -0
- package/components/recipes/Pricing.astro +149 -150
- package/components/recipes/Stats.astro +150 -157
- package/components/recipes/Tiles.astro +342 -296
- package/content/blocks.ts +1091 -1024
- package/content/cookies.ts +14 -0
- package/content/imageSlots.mjs +542 -0
- package/content/recipe-questions.ts +81 -80
- package/content/schemas.ts +13 -11
- package/examples/recipes.ts +5 -0
- package/fonts/OFL.txt +1332 -287
- package/fonts/anton-latin-400-normal.woff2 +0 -0
- package/fonts/bangers-latin-400-normal.woff2 +0 -0
- package/fonts/bebas-neue-latin-400-normal.woff2 +0 -0
- package/fonts/bowlby-one-latin-400-normal.woff2 +0 -0
- package/fonts/fredoka-latin-400-normal.woff2 +0 -0
- package/fonts/fredoka-latin-600-normal.woff2 +0 -0
- package/fonts/fredoka-latin-700-normal.woff2 +0 -0
- package/fonts/knewave-latin-400-normal.woff2 +0 -0
- package/fonts/lora-latin-400-normal.woff2 +0 -0
- package/fonts/lora-latin-600-normal.woff2 +0 -0
- package/fonts/lora-latin-700-normal.woff2 +0 -0
- package/fonts/merriweather-latin-400-normal.woff2 +0 -0
- package/fonts/merriweather-latin-600-normal.woff2 +0 -0
- package/fonts/merriweather-latin-700-normal.woff2 +0 -0
- package/fonts/nunito-latin-400-normal.woff2 +0 -0
- package/fonts/nunito-latin-600-normal.woff2 +0 -0
- package/fonts/nunito-latin-700-normal.woff2 +0 -0
- package/fonts/oswald-latin-400-normal.woff2 +0 -0
- package/fonts/oswald-latin-600-normal.woff2 +0 -0
- package/fonts/oswald-latin-700-normal.woff2 +0 -0
- package/fonts/rubik-dirt-latin-400-normal.woff2 +0 -0
- package/integration.mjs +319 -263
- package/layouts/Base.astro +8 -16
- package/lib/book.ts +416 -378
- package/lib/fonts.ts +130 -0
- package/lib/gridRows.ts +197 -0
- package/lib/image-fields.ts +140 -0
- package/lib/image-size.mjs +108 -73
- package/lib/image-sizes.ts +16 -0
- package/lib/logo-header.ts +46 -0
- package/lib/media-check.mjs +524 -0
- package/lib/members-account.ts +276 -0
- package/lib/members.ts +115 -0
- package/lib/theme-preview.ts +203 -140
- package/lib/themeTokens.ts +235 -220
- package/package.json +80 -71
- package/routes/account.astro +16 -0
- package/routes/cookie-policy.astro +28 -28
- package/styles/fonts.css +239 -76
- package/styles/theme.css +228 -160
- package/lib/gridColumns.ts +0 -22
package/lib/theme-preview.ts
CHANGED
|
@@ -1,140 +1,203 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Live theme preview (client-side). Lets an external editing surface — the portal
|
|
3
|
-
* Theme Studio, or the CMS design-tokens pane — push DRAFT theme settings
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
import
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
/**
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Live theme preview (client-side). Lets an external editing surface — the portal
|
|
3
|
+
* Theme Studio, or the CMS design-tokens pane — push DRAFT theme settings (and a draft
|
|
4
|
+
* header logo: its images, size and placement) into a
|
|
5
|
+
* loaded page over `postMessage`, so the whole site re-themes instantly with no
|
|
6
|
+
* rebuild. This is the "instant" preview lane of the Change-Request loop (see
|
|
7
|
+
* myai4-webdev/docs/PDLC-PREVIEW-ARCHITECTURE.md).
|
|
8
|
+
*
|
|
9
|
+
* Robust for ANY site: it re-runs the core's own `buildThemeStyle(draft)` in the
|
|
10
|
+
* browser and swaps a dedicated `<style id="ferst-preview">` — the same output the
|
|
11
|
+
* server emits at build time — instead of only setting inline `--brand/--ink/
|
|
12
|
+
* --surface` (which re-derive nothing on a not-yet-themed site). Injected late in
|
|
13
|
+
* <head>, it out-specifies the server theme block (`:root:root`), so the draft wins.
|
|
14
|
+
*
|
|
15
|
+
* Import ONLY from a component <script> (touches window/document). Gated by the
|
|
16
|
+
* caller to preview mode so it never runs for normal visitors.
|
|
17
|
+
*/
|
|
18
|
+
import { buildThemeStyle } from './themeTokens';
|
|
19
|
+
import { LOGO_HEADER_ATTRIBUTES, logoHeaderLayout } from './logo-header';
|
|
20
|
+
import type { LogoHeader, ThemeSettings } from '../content/schemas';
|
|
21
|
+
|
|
22
|
+
/** A draft of the header logo (logoSettings): its images, and its size and placement. */
|
|
23
|
+
export interface LogoDraft {
|
|
24
|
+
primaryLogoLight?: string;
|
|
25
|
+
primaryLogoDark?: string;
|
|
26
|
+
header?: Partial<LogoHeader>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** postMessage protocol shared with the portal / CMS preview surfaces. */
|
|
30
|
+
export const PREVIEW_MESSAGES = {
|
|
31
|
+
/** surface → page: apply this draft theme */
|
|
32
|
+
theme: 'ferst:preview:theme',
|
|
33
|
+
/** surface → page: apply this draft header logo (images, size, placement) */
|
|
34
|
+
logo: 'ferst:preview:logo',
|
|
35
|
+
/** surface → page: switch light/dark */
|
|
36
|
+
mode: 'ferst:preview:mode',
|
|
37
|
+
/** page → surface: listener is live, send the current draft */
|
|
38
|
+
ready: 'ferst:preview:ready',
|
|
39
|
+
} as const;
|
|
40
|
+
|
|
41
|
+
const STYLE_ID = 'ferst-preview';
|
|
42
|
+
/** Marks a live preview session so the draft survives navigation WITHIN the frame
|
|
43
|
+
* (internal links drop ?preview=1). Base.astro's gate also checks this flag. */
|
|
44
|
+
export const PREVIEW_SESSION_FLAG = 'ferst-preview-on';
|
|
45
|
+
const PREVIEW_DRAFT_KEY = 'ferst-preview-draft';
|
|
46
|
+
const PREVIEW_LOGO_KEY = 'ferst-preview-logo';
|
|
47
|
+
|
|
48
|
+
function rememberDraft(key: string, draft: unknown): void {
|
|
49
|
+
try {
|
|
50
|
+
sessionStorage.setItem(key, JSON.stringify(draft));
|
|
51
|
+
} catch {
|
|
52
|
+
/* storage blocked — the page still previews from the live postMessage */
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function recallDraft<T>(key: string): T | null {
|
|
57
|
+
try {
|
|
58
|
+
const raw = sessionStorage.getItem(key);
|
|
59
|
+
return raw ? (JSON.parse(raw) as T) : null;
|
|
60
|
+
} catch {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Origins allowed to drive the preview (besides same-origin, i.e. the CMS pane).
|
|
66
|
+
* The Ferst portal — both its custom domains and the bare Cloudflare Pages URLs
|
|
67
|
+
* it's actually served from (dev has no custom domain today). */
|
|
68
|
+
const PORTAL_ORIGINS = [
|
|
69
|
+
'https://portal.ferst.co.uk',
|
|
70
|
+
'https://portal-dev.ferst.co.uk',
|
|
71
|
+
'https://myai4-portal.pages.dev',
|
|
72
|
+
'https://myai4-portal-dev.pages.dev',
|
|
73
|
+
];
|
|
74
|
+
|
|
75
|
+
/** True for same-origin (CMS design-tokens pane) or a known Ferst portal origin. */
|
|
76
|
+
export function isAllowedPreviewOrigin(origin: string): boolean {
|
|
77
|
+
try {
|
|
78
|
+
if (origin === window.location.origin) return true;
|
|
79
|
+
} catch {
|
|
80
|
+
/* no window (SSR/tests) — fall through to the allowlist */
|
|
81
|
+
}
|
|
82
|
+
return PORTAL_ORIGINS.includes(origin);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Re-theme the current document from a draft, via the core's own derivation. */
|
|
86
|
+
export function applyPreviewTheme(theme: ThemeSettings): void {
|
|
87
|
+
const { css, field, titleEffect } = buildThemeStyle(theme);
|
|
88
|
+
const head = document.head;
|
|
89
|
+
let style = document.getElementById(STYLE_ID) as HTMLStyleElement | null;
|
|
90
|
+
if (!style) {
|
|
91
|
+
style = document.createElement('style');
|
|
92
|
+
style.id = STYLE_ID;
|
|
93
|
+
head.appendChild(style);
|
|
94
|
+
} else if (style !== head.lastElementChild) {
|
|
95
|
+
head.appendChild(style); // keep it last so it always wins over the server block
|
|
96
|
+
}
|
|
97
|
+
style.textContent = css;
|
|
98
|
+
const root = document.documentElement;
|
|
99
|
+
if (field) root.dataset.field = field;
|
|
100
|
+
else delete root.dataset.field;
|
|
101
|
+
if (titleEffect) root.dataset.titleEffect = titleEffect;
|
|
102
|
+
else delete root.dataset.titleEffect;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Show a draft header logo on the current page: its image (in place of the site's name
|
|
107
|
+
* when the site has none yet), and its size and placement, through the same
|
|
108
|
+
* logoHeaderLayout() the build uses, so the preview is exactly what the site will show.
|
|
109
|
+
*/
|
|
110
|
+
export function applyPreviewLogo(draft: LogoDraft): void {
|
|
111
|
+
const header = document.querySelector<HTMLElement>('.site-header');
|
|
112
|
+
const brand = header?.querySelector<HTMLElement>('.brand');
|
|
113
|
+
if (!header || !brand) return;
|
|
114
|
+
let img = header.querySelector<HTMLImageElement>('#primary-logo');
|
|
115
|
+
if (draft.primaryLogoLight) {
|
|
116
|
+
if (!img) {
|
|
117
|
+
img = document.createElement('img');
|
|
118
|
+
img.id = 'primary-logo';
|
|
119
|
+
img.className = 'primary-logo';
|
|
120
|
+
img.alt = brand.textContent?.trim() ?? '';
|
|
121
|
+
brand.replaceChildren(img);
|
|
122
|
+
}
|
|
123
|
+
img.dataset.srcLight = draft.primaryLogoLight;
|
|
124
|
+
img.dataset.srcDark = draft.primaryLogoDark || draft.primaryLogoLight;
|
|
125
|
+
const src = document.documentElement.dataset.theme === 'dark' ? img.dataset.srcDark : img.dataset.srcLight;
|
|
126
|
+
if (img.getAttribute('src') !== src) {
|
|
127
|
+
// A different picture: its box comes from the picture itself once it has loaded.
|
|
128
|
+
img.removeAttribute('width');
|
|
129
|
+
img.removeAttribute('height');
|
|
130
|
+
img.src = src;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const logo = img;
|
|
134
|
+
const layout = () => {
|
|
135
|
+
const size = logo?.naturalWidth ? { width: logo.naturalWidth, height: logo.naturalHeight } : undefined;
|
|
136
|
+
const { attributes, ratio } = logoHeaderLayout({ header: draft.header, hasLogo: !!logo, size });
|
|
137
|
+
for (const name of LOGO_HEADER_ATTRIBUTES) header.removeAttribute(name);
|
|
138
|
+
for (const [name, value] of Object.entries(attributes)) header.setAttribute(name, value);
|
|
139
|
+
if (ratio) header.style.setProperty('--logo-ratio', String(ratio));
|
|
140
|
+
else header.style.removeProperty('--logo-ratio');
|
|
141
|
+
};
|
|
142
|
+
layout();
|
|
143
|
+
if (logo && !logo.complete) logo.addEventListener('load', layout, { once: true });
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** Wire the page to receive drafts from an allowed surface, and announce readiness.
|
|
147
|
+
* Persists the draft for the session so it survives navigation inside the frame. */
|
|
148
|
+
export function initThemePreviewListener(): void {
|
|
149
|
+
try {
|
|
150
|
+
sessionStorage.setItem(PREVIEW_SESSION_FLAG, '1'); // keep previewing across in-frame nav
|
|
151
|
+
} catch {
|
|
152
|
+
/* storage blocked — the portal re-push on ready still re-themes each new page */
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const reapply = () => {
|
|
156
|
+
const draft = recallDraft<ThemeSettings>(PREVIEW_DRAFT_KEY);
|
|
157
|
+
const logo = recallDraft<LogoDraft>(PREVIEW_LOGO_KEY);
|
|
158
|
+
try {
|
|
159
|
+
if (draft) applyPreviewTheme(draft);
|
|
160
|
+
if (logo) applyPreviewLogo(logo);
|
|
161
|
+
} catch {
|
|
162
|
+
/* ignore a bad stored draft */
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
// A freshly-navigated page in the session: re-theme immediately from the stored
|
|
167
|
+
// draft (before the portal re-pushes), so tokens don't drop on link clicks.
|
|
168
|
+
reapply();
|
|
169
|
+
|
|
170
|
+
window.addEventListener('message', (event: MessageEvent) => {
|
|
171
|
+
if (!isAllowedPreviewOrigin(event.origin)) return;
|
|
172
|
+
const data = event.data as { type?: string; theme?: ThemeSettings; logo?: LogoDraft; mode?: string } | null;
|
|
173
|
+
if (!data || typeof data !== 'object') return;
|
|
174
|
+
if (data.type === PREVIEW_MESSAGES.theme && data.theme) {
|
|
175
|
+
try {
|
|
176
|
+
applyPreviewTheme(data.theme);
|
|
177
|
+
rememberDraft(PREVIEW_DRAFT_KEY, data.theme);
|
|
178
|
+
} catch {
|
|
179
|
+
/* a malformed draft must never break the preview page */
|
|
180
|
+
}
|
|
181
|
+
} else if (data.type === PREVIEW_MESSAGES.logo && data.logo && typeof data.logo === 'object') {
|
|
182
|
+
try {
|
|
183
|
+
applyPreviewLogo(data.logo);
|
|
184
|
+
rememberDraft(PREVIEW_LOGO_KEY, data.logo);
|
|
185
|
+
} catch {
|
|
186
|
+
/* a malformed draft must never break the preview page */
|
|
187
|
+
}
|
|
188
|
+
} else if (data.type === PREVIEW_MESSAGES.mode) {
|
|
189
|
+
document.documentElement.dataset.theme = data.mode === 'dark' ? 'dark' : 'light';
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
// View-transition (ClientRouter) pages swap the DOM without a full load, which
|
|
194
|
+
// drops the injected <style> — re-apply after each swap.
|
|
195
|
+
document.addEventListener('astro:page-load', reapply);
|
|
196
|
+
|
|
197
|
+
// Tell whoever framed us that we're listening, so it can push the latest draft.
|
|
198
|
+
try {
|
|
199
|
+
window.parent?.postMessage({ type: PREVIEW_MESSAGES.ready }, '*');
|
|
200
|
+
} catch {
|
|
201
|
+
/* no parent / blocked — the stored draft already re-themed this page */
|
|
202
|
+
}
|
|
203
|
+
}
|