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.
Files changed (74) hide show
  1. package/NOTICE +63 -31
  2. package/README.md +13 -4
  3. package/bin/ferst-media.mjs +96 -0
  4. package/bin/ferst-modules.mjs +17 -2
  5. package/components/BlockRenderer.astro +131 -129
  6. package/components/Card.astro +53 -51
  7. package/components/MembersAccount.astro +370 -0
  8. package/components/PostCard.astro +138 -136
  9. package/components/SiteHeader.astro +32 -14
  10. package/components/blocks/Grid.astro +49 -48
  11. package/components/blocks/Heading.astro +4 -1
  12. package/components/islands/BookMonth.tsx +95 -0
  13. package/components/islands/MembersAccount.tsx +392 -0
  14. package/components/recipes/Banner.astro +146 -146
  15. package/components/recipes/Book.astro +1147 -926
  16. package/components/recipes/FeatureCards.astro +112 -118
  17. package/components/recipes/Gallery.astro +57 -59
  18. package/components/recipes/Hero.astro +112 -10
  19. package/components/recipes/LatestPosts.astro +295 -292
  20. package/components/recipes/Locations.astro +146 -143
  21. package/components/recipes/Marquee.astro +75 -75
  22. package/components/recipes/MediaCards.astro +213 -219
  23. package/components/recipes/MembersContent.astro +176 -0
  24. package/components/recipes/Pricing.astro +149 -150
  25. package/components/recipes/Stats.astro +150 -157
  26. package/components/recipes/Tiles.astro +342 -296
  27. package/content/blocks.ts +1091 -1024
  28. package/content/cookies.ts +14 -0
  29. package/content/imageSlots.mjs +542 -0
  30. package/content/recipe-questions.ts +81 -80
  31. package/content/schemas.ts +13 -11
  32. package/examples/recipes.ts +5 -0
  33. package/fonts/OFL.txt +1332 -287
  34. package/fonts/anton-latin-400-normal.woff2 +0 -0
  35. package/fonts/bangers-latin-400-normal.woff2 +0 -0
  36. package/fonts/bebas-neue-latin-400-normal.woff2 +0 -0
  37. package/fonts/bowlby-one-latin-400-normal.woff2 +0 -0
  38. package/fonts/fredoka-latin-400-normal.woff2 +0 -0
  39. package/fonts/fredoka-latin-600-normal.woff2 +0 -0
  40. package/fonts/fredoka-latin-700-normal.woff2 +0 -0
  41. package/fonts/knewave-latin-400-normal.woff2 +0 -0
  42. package/fonts/lora-latin-400-normal.woff2 +0 -0
  43. package/fonts/lora-latin-600-normal.woff2 +0 -0
  44. package/fonts/lora-latin-700-normal.woff2 +0 -0
  45. package/fonts/merriweather-latin-400-normal.woff2 +0 -0
  46. package/fonts/merriweather-latin-600-normal.woff2 +0 -0
  47. package/fonts/merriweather-latin-700-normal.woff2 +0 -0
  48. package/fonts/nunito-latin-400-normal.woff2 +0 -0
  49. package/fonts/nunito-latin-600-normal.woff2 +0 -0
  50. package/fonts/nunito-latin-700-normal.woff2 +0 -0
  51. package/fonts/oswald-latin-400-normal.woff2 +0 -0
  52. package/fonts/oswald-latin-600-normal.woff2 +0 -0
  53. package/fonts/oswald-latin-700-normal.woff2 +0 -0
  54. package/fonts/rubik-dirt-latin-400-normal.woff2 +0 -0
  55. package/integration.mjs +319 -263
  56. package/layouts/Base.astro +8 -16
  57. package/lib/book.ts +416 -378
  58. package/lib/fonts.ts +130 -0
  59. package/lib/gridRows.ts +197 -0
  60. package/lib/image-fields.ts +140 -0
  61. package/lib/image-size.mjs +108 -73
  62. package/lib/image-sizes.ts +16 -0
  63. package/lib/logo-header.ts +46 -0
  64. package/lib/media-check.mjs +524 -0
  65. package/lib/members-account.ts +276 -0
  66. package/lib/members.ts +115 -0
  67. package/lib/theme-preview.ts +203 -140
  68. package/lib/themeTokens.ts +235 -220
  69. package/package.json +80 -71
  70. package/routes/account.astro +16 -0
  71. package/routes/cookie-policy.astro +28 -28
  72. package/styles/fonts.css +239 -76
  73. package/styles/theme.css +228 -160
  74. package/lib/gridColumns.ts +0 -22
@@ -1,220 +1,235 @@
1
- /**
2
- * The theming engine: turn the structured `themeSettings` (three brand colours +
3
- * a font pairing + four surface knobs) into the CSS that drives the whole site.
4
- *
5
- * The design premise is that a brand needs only THREE source colours — `--brand`
6
- * (interactive accent), `--ink` (text) and `--surface` (background). Every other
7
- * working token (`--muted`, `--border`, `--bg-surface`, `--gold`, …) is DERIVED:
8
- * • Light — `color-mix()` tints between ink/brand and the surface.
9
- * • Dark — a scientific OKLCH translation of the SAME three colours: lightness
10
- * is flipped to dark-surface / light-text targets while HUE is
11
- * preserved and chroma is DAMPED, because a naïve hex inversion
12
- * yields harsh neon tones that vibrate and fail contrast on dark
13
- * grounds. Surfaces are deep, desaturated and faintly brand-tinted;
14
- * text lands at OKLCH L≈0.74–0.94 for comfortable legibility.
15
- * (Refs: Material dark theme; OKLCH accessible-palette guidance.)
16
- *
17
- * This lives in the CORE (not the showcase) so a real client site, the CMS, and
18
- * the showcase's live playground all derive a palette the SAME way. `Base.astro`
19
- * emits the result at doubled `:root:root` specificity so it beats the neutral
20
- * literal defaults in `styles/theme.css` regardless of stylesheet order; the
21
- * showcase playground then overrides `--brand/--ink/--surface` inline on <html>
22
- * for per-visitor re-theming, and because the derivations read `var(--brand)`
23
- * etc. the whole palette re-resolves live.
24
- *
25
- * Pure + framework-free so it is unit-testable without a render.
26
- */
27
- import type { ThemeSettings } from '../content/schemas';
28
- import { DARK_DEFAULTS, NEUTRAL_SOURCE } from './themeDefaults';
29
- import { onBrandColour } from './contrast';
30
-
31
- export { DARK_DEFAULTS, NEUTRAL_SOURCE };
32
-
33
-
34
- /** Corner-knob vocabulary → the `--radius` value every surface reads. */
35
- export const CORNERS_PX: Record<ThemeSettings['corners'], string> = {
36
- sharp: '0px',
37
- rounded: '12px',
38
- soft: '22px',
39
- };
40
-
41
- /**
42
- * Light-mode derivations — read the three source vars, tint via color-mix.
43
- * Secondary-text mixes sit at ~72% ink so body copy (which uses `--muted`) keeps
44
- * a comfortable AA contrast on the surface, rather than the trendy-but-faint
45
- * light grey that fails it.
46
- */
47
- const LIGHT_DERIVATION = [
48
- '--gold:var(--brand)',
49
- '--gold-light:color-mix(in srgb, var(--brand) 14%, var(--surface))',
50
- '--accent-2:oklch(from var(--brand) 0.58 c calc(h + 26))',
51
- '--fg:var(--ink)',
52
- '--accent:color-mix(in srgb, var(--ink) 84%, var(--surface))',
53
- '--muted:color-mix(in srgb, var(--ink) 72%, var(--surface))',
54
- '--brown:color-mix(in srgb, var(--ink) 72%, var(--surface))',
55
- '--bg:var(--surface)',
56
- '--bg-surface:color-mix(in srgb, #fff 62%, var(--surface))',
57
- '--bg-section:color-mix(in srgb, var(--ink) 7%, var(--surface))',
58
- '--bg-tag:color-mix(in srgb, var(--ink) 6%, var(--surface))',
59
- '--border:color-mix(in srgb, var(--ink) 16%, var(--surface))',
60
- '--text-footer:color-mix(in srgb, var(--ink) 72%, var(--surface))',
61
- '--text-footer-link:var(--brand)',
62
- '--news-card-body:var(--ink)',
63
- '--news-card-meta:color-mix(in srgb, var(--ink) 72%, var(--surface))',
64
- ].join(';');
65
-
66
- /**
67
- * Dark mode uses a ROOT-DERIVATION model that mirrors light's three sources, so an
68
- * editor can only ever change coherent roots — never a lone downstream token that
69
- * would then clash with the rest.
70
- *
71
- * Three dark ROOTS, one per role:
72
- * --dark-ground (surfaces) ← surface, chroma BOOSTED as it darkens so a pale
73
- * tint survives instead of collapsing to grey/black;
74
- * lightness = --dark-bg-l (the depth knob).
75
- * --dark-text (text) ← ink, lightened for a dark ground.
76
- * --dark-accent (accents) ← brand, brightened for a dark ground.
77
- * Each defaults to this formula but can be OVERRIDDEN with an explicit colour (see
78
- * buildThemeStyle); either way EVERY dark token below derives from the three roots,
79
- * so the palette stays internally consistent whether automatic or hand-set.
80
- */
81
- const DARK_ROOTS_AUTO = [
82
- '--dark-ground:oklch(from var(--surface) var(--dark-bg-l) clamp(0, calc(c * 3.5), var(--dark-chroma-cap)) h)',
83
- '--dark-text:oklch(from var(--ink) 0.94 calc(c * 0.3) h)',
84
- '--dark-accent:oklch(from var(--brand) 0.78 calc(c * 0.9) h)',
85
- ].join(';');
86
-
87
- /** Every working dark token, derived from the three roots (offsets in OKLCH L). */
88
- const DARK_DOWNSTREAM = [
89
- // Grounds ← --dark-ground
90
- '--bg:var(--dark-ground)',
91
- '--bg-surface:oklch(from var(--dark-ground) calc(l + 0.05) c h)',
92
- '--bg-section:oklch(from var(--dark-ground) calc(l + 0.025) c h)',
93
- '--bg-tag:oklch(from var(--dark-ground) calc(l - 0.03) c h)',
94
- '--dark-bg:oklch(from var(--dark-ground) calc(l - 0.05) c h)',
95
- '--border:oklch(from var(--dark-ground) calc(l + 0.19) c h)',
96
- '--divider-dark:oklch(from var(--dark-ground) calc(l + 0.19) c h)',
97
- // Text ← --dark-text
98
- '--fg:var(--dark-text)',
99
- '--muted:oklch(from var(--dark-text) calc(l - 0.20) c h)',
100
- '--accent:oklch(from var(--dark-text) calc(l - 0.08) c h)',
101
- '--brown:oklch(from var(--dark-text) calc(l - 0.20) c h)',
102
- '--text-footer:oklch(from var(--dark-text) calc(l - 0.20) c h)',
103
- '--text-copyright:oklch(from var(--dark-text) calc(l - 0.39) c h)',
104
- '--text-subtle:oklch(from var(--dark-text) calc(l - 0.39) c h)',
105
- '--news-card-meta:oklch(from var(--dark-text) calc(l - 0.20) c h)',
106
- // Accents ← --dark-accent
107
- '--gold:var(--dark-accent)',
108
- '--gold-light:oklch(from var(--dark-accent) calc(l - 0.46) calc(c * 0.6) h)',
109
- '--accent-2:oklch(from var(--dark-accent) calc(l - 0.08) c calc(h + 26))',
110
- '--text-footer-link:var(--dark-accent)',
111
- // Text on brand fills: the accent is light in dark mode, so its text is the dark ground
112
- // (light text on it fell to ~1.9:1; lib/contrast.ts checks it).
113
- '--on-brand:var(--dark-ground)',
114
- ].join(';');
115
-
116
-
117
- /** Clamp a numeric knob to a range, falling back to `fallback` when absent/NaN. */
118
- function clampNum(v: unknown, min: number, max: number, fallback: number): number {
119
- const n = typeof v === 'number' && Number.isFinite(v) ? v : fallback;
120
- return Math.min(max, Math.max(min, n));
121
- }
122
-
123
- /**
124
- * Compose the dark block: the depth/chroma knobs, the three auto roots, any
125
- * explicit root overrides (which win over the auto value), then the downstream
126
- * derivations that read whichever root value ended up winning.
127
- */
128
- function darkDeclarations(theme: ThemeSettings): string {
129
- const depth = clampNum(theme.darkDepth, 0.12, 0.4, DARK_DEFAULTS.depth);
130
- const chroma = clampNum(theme.darkChroma, 0, 0.15, DARK_DEFAULTS.chroma);
131
- const ov = theme.darkOverrides ?? {};
132
- const overrides: string[] = [];
133
- if (clean(ov.ground)) overrides.push(`--dark-ground:${clean(ov.ground)}`);
134
- if (clean(ov.text)) overrides.push(`--dark-text:${clean(ov.text)}`);
135
- if (clean(ov.accent)) overrides.push(`--dark-accent:${clean(ov.accent)}`);
136
- return [
137
- `--dark-bg-l:${depth}`,
138
- `--dark-chroma-cap:${chroma}`,
139
- DARK_ROOTS_AUTO,
140
- ...overrides,
141
- DARK_DOWNSTREAM,
142
- ].join(';');
143
- }
144
-
145
- /** Drop a value that could break out of a CSS declaration. The source is trusted
146
- * repo JSON, but this keeps a stray value honest (defence in depth). */
147
- function clean(v: unknown): string {
148
- return typeof v === 'string' && v.trim() !== '' && !/[<>{};]/.test(v) ? v.trim() : '';
149
- }
150
-
151
- /** A raw `{ '--token': 'value' }` record → one CSS rule (the advanced escape hatch). */
152
- function rawBlock(selector: string, tokens: Record<string, string> | undefined): string {
153
- const decls = Object.entries(tokens ?? {})
154
- .filter(([k, v]) => /^--?[a-zA-Z0-9-]+$/.test(k) && clean(v) !== '')
155
- .map(([k, v]) => `${k.startsWith('--') ? k : `--${k}`}:${clean(v)}`)
156
- .join(';');
157
- return decls ? `${selector}{${decls}}` : '';
158
- }
159
-
160
- export interface ThemeStyle {
161
- /** CSS to inline in <head> (may be an empty string when nothing is overridden). */
162
- css: string;
163
- /** Value for `<html data-field="…">`, or undefined for the `boxed` default. */
164
- field: string | undefined;
165
- }
166
-
167
- /**
168
- * Build the inline <style> body + the `data-field` attribute for a theme.
169
- *
170
- * When a client sets any of brand/ink/surface the full derivation is emitted
171
- * (source colours — blanks filled from NEUTRAL_SOURCE — plus the light and dark
172
- * derivations). When they set none, no colour CSS is emitted at all and the
173
- * core's neutral literals in `styles/theme.css` stand. Fonts and knobs are
174
- * emitted independently of colour; `advanced.*` raw tokens are layered last.
175
- */
176
- export function buildThemeStyle(theme: ThemeSettings): ThemeStyle {
177
- const brand = clean(theme.brand);
178
- const ink = clean(theme.ink);
179
- const surface = clean(theme.surface);
180
- const themed = !!(brand || ink || surface);
181
-
182
- // Block A — source colours + fonts + knobs (both modes). `:root:root` beats the
183
- // theme.css `:root` / `[data-theme=dark]` literals; inline <html> beats this.
184
- const rootDecls: string[] = [];
185
- if (themed) {
186
- rootDecls.push(`--brand:${brand || NEUTRAL_SOURCE.brand}`);
187
- rootDecls.push(`--ink:${ink || NEUTRAL_SOURCE.ink}`);
188
- rootDecls.push(`--surface:${surface || NEUTRAL_SOURCE.surface}`);
189
- // Text on brand fills: white or the ink, whichever reads better on the brand (dark mode
190
- // overrides it with the dark ground). A colour it can't read leaves theme.css's white.
191
- const onBrand = onBrandColour(brand || NEUTRAL_SOURCE.brand, ink || NEUTRAL_SOURCE.ink);
192
- if (onBrand) rootDecls.push(`--on-brand:${onBrand}`);
193
- }
194
- const fh = clean(theme.fonts?.heading);
195
- const fb = clean(theme.fonts?.body);
196
- const fd = clean(theme.fonts?.display);
197
- if (fh) rootDecls.push(`--font-heading:${fh}`);
198
- if (fb) rootDecls.push(`--font-body:${fb}`);
199
- if (fd) rootDecls.push(`--font-display:${fd}`);
200
- // Corners always resolves to a radius; only emit when it differs from the
201
- // core default (`rounded` = 12px) to keep the payload minimal.
202
- if (theme.corners && theme.corners !== 'rounded') {
203
- rootDecls.push(`--radius:${CORNERS_PX[theme.corners]}`);
204
- }
205
- if (theme.elevation === 'flat') rootDecls.push('--shadow-md:none');
206
- if (theme.stroke === 'off') rootDecls.push('--card-border:none');
207
-
208
- const css = [
209
- rootDecls.length ? `:root:root{${rootDecls.join(';')}}` : '',
210
- themed ? `:root:root:not([data-theme="dark"]){${LIGHT_DERIVATION}}` : '',
211
- themed ? `:root:root[data-theme="dark"]{${darkDeclarations(theme)}}` : '',
212
- rawBlock(':root:root', theme.advanced?.light),
213
- rawBlock(':root:root[data-theme="dark"]', theme.advanced?.dark),
214
- ]
215
- .filter(Boolean)
216
- .join('');
217
-
218
- const field = theme.fields && theme.fields !== 'boxed' ? theme.fields : undefined;
219
- return { css, field };
220
- }
1
+ /**
2
+ * The theming engine: turn the structured `themeSettings` (three brand colours +
3
+ * a font pairing + four surface knobs) into the CSS that drives the whole site.
4
+ *
5
+ * The design premise is that a brand needs only THREE source colours — `--brand`
6
+ * (interactive accent), `--ink` (text) and `--surface` (background). Every other
7
+ * working token (`--muted`, `--border`, `--bg-surface`, `--gold`, …) is DERIVED:
8
+ * • Light — `color-mix()` tints between ink/brand and the surface.
9
+ * • Dark — a scientific OKLCH translation of the SAME three colours: lightness
10
+ * is flipped to dark-surface / light-text targets while HUE is
11
+ * preserved and chroma is DAMPED, because a naïve hex inversion
12
+ * yields harsh neon tones that vibrate and fail contrast on dark
13
+ * grounds. Surfaces are deep, desaturated and faintly brand-tinted;
14
+ * text lands at OKLCH L≈0.74–0.94 for comfortable legibility.
15
+ * (Refs: Material dark theme; OKLCH accessible-palette guidance.)
16
+ *
17
+ * This lives in the CORE (not the showcase) so a real client site, the CMS, and
18
+ * the showcase's live playground all derive a palette the SAME way. `Base.astro`
19
+ * emits the result at doubled `:root:root` specificity so it beats the neutral
20
+ * literal defaults in `styles/theme.css` regardless of stylesheet order; the
21
+ * showcase playground then overrides `--brand/--ink/--surface` inline on <html>
22
+ * for per-visitor re-theming, and because the derivations read `var(--brand)`
23
+ * etc. the whole palette re-resolves live.
24
+ *
25
+ * Pure + framework-free so it is unit-testable without a render.
26
+ */
27
+ import { TITLE_EFFECTS, type ThemeSettings } from '../content/schemas';
28
+ import { DARK_DEFAULTS, NEUTRAL_SOURCE } from './themeDefaults';
29
+ import { onBrandColour } from './contrast';
30
+ import { fontSuitsRole } from './fonts';
31
+
32
+ export { DARK_DEFAULTS, NEUTRAL_SOURCE };
33
+
34
+
35
+ /** Corner-knob vocabulary → the `--radius` value every surface reads. */
36
+ export const CORNERS_PX: Record<ThemeSettings['corners'], string> = {
37
+ sharp: '0px',
38
+ rounded: '12px',
39
+ soft: '22px',
40
+ };
41
+
42
+ /**
43
+ * Light-mode derivations — read the three source vars, tint via color-mix.
44
+ * Secondary-text mixes sit at ~72% ink so body copy (which uses `--muted`) keeps
45
+ * a comfortable AA contrast on the surface, rather than the trendy-but-faint
46
+ * light grey that fails it.
47
+ */
48
+ const LIGHT_DERIVATION = [
49
+ '--gold:var(--brand)',
50
+ '--gold-light:color-mix(in srgb, var(--brand) 14%, var(--surface))',
51
+ '--accent-2:oklch(from var(--brand) 0.58 c calc(h + 26))',
52
+ '--fg:var(--ink)',
53
+ '--accent:color-mix(in srgb, var(--ink) 84%, var(--surface))',
54
+ '--muted:color-mix(in srgb, var(--ink) 72%, var(--surface))',
55
+ '--brown:color-mix(in srgb, var(--ink) 72%, var(--surface))',
56
+ '--bg:var(--surface)',
57
+ '--bg-surface:color-mix(in srgb, #fff 62%, var(--surface))',
58
+ '--bg-section:color-mix(in srgb, var(--ink) 7%, var(--surface))',
59
+ '--bg-tag:color-mix(in srgb, var(--ink) 6%, var(--surface))',
60
+ '--border:color-mix(in srgb, var(--ink) 16%, var(--surface))',
61
+ '--text-footer:color-mix(in srgb, var(--ink) 72%, var(--surface))',
62
+ '--text-footer-link:var(--brand)',
63
+ '--news-card-body:var(--ink)',
64
+ '--news-card-meta:color-mix(in srgb, var(--ink) 72%, var(--surface))',
65
+ ].join(';');
66
+
67
+ /**
68
+ * Dark mode uses a ROOT-DERIVATION model that mirrors light's three sources, so an
69
+ * editor can only ever change coherent roots — never a lone downstream token that
70
+ * would then clash with the rest.
71
+ *
72
+ * Three dark ROOTS, one per role:
73
+ * --dark-ground (surfaces) ← surface, chroma BOOSTED as it darkens so a pale
74
+ * tint survives instead of collapsing to grey/black;
75
+ * lightness = --dark-bg-l (the depth knob).
76
+ * --dark-text (text) ← ink, lightened for a dark ground.
77
+ * --dark-accent (accents) ← brand, brightened for a dark ground.
78
+ * Each defaults to this formula but can be OVERRIDDEN with an explicit colour (see
79
+ * buildThemeStyle); either way EVERY dark token below derives from the three roots,
80
+ * so the palette stays internally consistent whether automatic or hand-set.
81
+ */
82
+ const DARK_ROOTS_AUTO = [
83
+ '--dark-ground:oklch(from var(--surface) var(--dark-bg-l) clamp(0, calc(c * 3.5), var(--dark-chroma-cap)) h)',
84
+ '--dark-text:oklch(from var(--ink) 0.94 calc(c * 0.3) h)',
85
+ '--dark-accent:oklch(from var(--brand) 0.78 calc(c * 0.9) h)',
86
+ ].join(';');
87
+
88
+ /** Every working dark token, derived from the three roots (offsets in OKLCH L). */
89
+ const DARK_DOWNSTREAM = [
90
+ // Grounds ← --dark-ground
91
+ '--bg:var(--dark-ground)',
92
+ '--bg-surface:oklch(from var(--dark-ground) calc(l + 0.05) c h)',
93
+ '--bg-section:oklch(from var(--dark-ground) calc(l + 0.025) c h)',
94
+ '--bg-tag:oklch(from var(--dark-ground) calc(l - 0.03) c h)',
95
+ '--dark-bg:oklch(from var(--dark-ground) calc(l - 0.05) c h)',
96
+ '--border:oklch(from var(--dark-ground) calc(l + 0.19) c h)',
97
+ '--divider-dark:oklch(from var(--dark-ground) calc(l + 0.19) c h)',
98
+ // Text ← --dark-text
99
+ '--fg:var(--dark-text)',
100
+ '--muted:oklch(from var(--dark-text) calc(l - 0.20) c h)',
101
+ '--accent:oklch(from var(--dark-text) calc(l - 0.08) c h)',
102
+ '--brown:oklch(from var(--dark-text) calc(l - 0.20) c h)',
103
+ '--text-footer:oklch(from var(--dark-text) calc(l - 0.20) c h)',
104
+ '--text-copyright:oklch(from var(--dark-text) calc(l - 0.39) c h)',
105
+ '--text-subtle:oklch(from var(--dark-text) calc(l - 0.39) c h)',
106
+ '--news-card-meta:oklch(from var(--dark-text) calc(l - 0.20) c h)',
107
+ // Accents ← --dark-accent
108
+ '--gold:var(--dark-accent)',
109
+ '--gold-light:oklch(from var(--dark-accent) calc(l - 0.46) calc(c * 0.6) h)',
110
+ '--accent-2:oklch(from var(--dark-accent) calc(l - 0.08) c calc(h + 26))',
111
+ '--text-footer-link:var(--dark-accent)',
112
+ // Text on brand fills: the accent is light in dark mode, so its text is the dark ground
113
+ // (light text on it fell to ~1.9:1; lib/contrast.ts checks it).
114
+ '--on-brand:var(--dark-ground)',
115
+ ].join(';');
116
+
117
+
118
+ /** Clamp a numeric knob to a range, falling back to `fallback` when absent/NaN. */
119
+ function clampNum(v: unknown, min: number, max: number, fallback: number): number {
120
+ const n = typeof v === 'number' && Number.isFinite(v) ? v : fallback;
121
+ return Math.min(max, Math.max(min, n));
122
+ }
123
+
124
+ /**
125
+ * Compose the dark block: the depth/chroma knobs, the three auto roots, any
126
+ * explicit root overrides (which win over the auto value), then the downstream
127
+ * derivations that read whichever root value ended up winning.
128
+ */
129
+ function darkDeclarations(theme: ThemeSettings): string {
130
+ const depth = clampNum(theme.darkDepth, 0.12, 0.4, DARK_DEFAULTS.depth);
131
+ const chroma = clampNum(theme.darkChroma, 0, 0.15, DARK_DEFAULTS.chroma);
132
+ const ov = theme.darkOverrides ?? {};
133
+ const overrides: string[] = [];
134
+ if (clean(ov.ground)) overrides.push(`--dark-ground:${clean(ov.ground)}`);
135
+ if (clean(ov.text)) overrides.push(`--dark-text:${clean(ov.text)}`);
136
+ if (clean(ov.accent)) overrides.push(`--dark-accent:${clean(ov.accent)}`);
137
+ return [
138
+ `--dark-bg-l:${depth}`,
139
+ `--dark-chroma-cap:${chroma}`,
140
+ DARK_ROOTS_AUTO,
141
+ ...overrides,
142
+ DARK_DOWNSTREAM,
143
+ ].join(';');
144
+ }
145
+
146
+ /** Drop a value that could break out of a CSS declaration. The source is trusted
147
+ * repo JSON, but this keeps a stray value honest (defence in depth). */
148
+ function clean(v: unknown): string {
149
+ return typeof v === 'string' && v.trim() !== '' && !/[<>{};]/.test(v) ? v.trim() : '';
150
+ }
151
+
152
+ /** A raw `{ '--token': 'value' }` record → one CSS rule (the advanced escape hatch). */
153
+ function rawBlock(selector: string, tokens: Record<string, string> | undefined): string {
154
+ const decls = Object.entries(tokens ?? {})
155
+ .filter(([k, v]) => /^--?[a-zA-Z0-9-]+$/.test(k) && clean(v) !== '')
156
+ .map(([k, v]) => `${k.startsWith('--') ? k : `--${k}`}:${clean(v)}`)
157
+ .join(';');
158
+ return decls ? `${selector}{${decls}}` : '';
159
+ }
160
+
161
+ export interface ThemeStyle {
162
+ /** CSS to inline in <head> (may be an empty string when nothing is overridden). */
163
+ css: string;
164
+ /** Value for `<html data-field="…">`, or undefined for the `boxed` default. */
165
+ field: string | undefined;
166
+ /** Value for `<html data-title-effect="…">`, or undefined for `none` (the default). */
167
+ titleEffect: string | undefined;
168
+ }
169
+
170
+ /**
171
+ * Build the inline <style> body + the `data-field` and `data-title-effect` attributes
172
+ * for a theme.
173
+ *
174
+ * When a client sets any of brand/ink/surface the full derivation is emitted
175
+ * (source colours — blanks filled from NEUTRAL_SOURCE — plus the light and dark
176
+ * derivations). When they set none, no colour CSS is emitted at all and the
177
+ * core's neutral literals in `styles/theme.css` stand. Fonts and knobs are
178
+ * emitted independently of colour; `advanced.*` raw tokens are layered last.
179
+ */
180
+ export function buildThemeStyle(theme: ThemeSettings): ThemeStyle {
181
+ const brand = clean(theme.brand);
182
+ const ink = clean(theme.ink);
183
+ const surface = clean(theme.surface);
184
+ const themed = !!(brand || ink || surface);
185
+
186
+ // Block A — source colours + fonts + knobs (both modes). `:root:root` beats the
187
+ // theme.css `:root` / `[data-theme=dark]` literals; inline <html> beats this.
188
+ const rootDecls: string[] = [];
189
+ if (themed) {
190
+ rootDecls.push(`--brand:${brand || NEUTRAL_SOURCE.brand}`);
191
+ rootDecls.push(`--ink:${ink || NEUTRAL_SOURCE.ink}`);
192
+ rootDecls.push(`--surface:${surface || NEUTRAL_SOURCE.surface}`);
193
+ // Text on brand fills: white or the ink, whichever reads better on the brand (dark mode
194
+ // overrides it with the dark ground). A colour it can't read leaves theme.css's white.
195
+ const onBrand = onBrandColour(brand || NEUTRAL_SOURCE.brand, ink || NEUTRAL_SOURCE.ink);
196
+ if (onBrand) rootDecls.push(`--on-brand:${onBrand}`);
197
+ }
198
+ // Fonts by role (lib/fonts.ts). A curated face set for a role it doesn't suit (a poster
199
+ // face for body text) is ignored, so the role keeps its default and pages stay readable.
200
+ const font = (stack: unknown, role: 'heading' | 'body' | 'display') => {
201
+ const v = clean(stack);
202
+ return v && fontSuitsRole(v, role) ? v : '';
203
+ };
204
+ const fh = font(theme.fonts?.heading, 'heading');
205
+ const fb = font(theme.fonts?.body, 'body');
206
+ const fd = font(theme.fonts?.display, 'display');
207
+ if (fh) rootDecls.push(`--font-heading:${fh}`);
208
+ if (fb) rootDecls.push(`--font-body:${fb}`);
209
+ // A display face the site chose also sets its display titles (the opener's title, the
210
+ // marquee); without one they keep the heading face (`--font-title` in styles/theme.css).
211
+ if (fd) rootDecls.push(`--font-display:${fd}`, '--font-title:var(--font-display)');
212
+ // Corners always resolves to a radius; only emit when it differs from the
213
+ // core default (`rounded` = 12px) to keep the payload minimal.
214
+ if (theme.corners && theme.corners !== 'rounded') {
215
+ rootDecls.push(`--radius:${CORNERS_PX[theme.corners]}`);
216
+ }
217
+ if (theme.elevation === 'flat') rootDecls.push('--shadow-md:none');
218
+ if (theme.stroke === 'off') rootDecls.push('--card-border:none');
219
+
220
+ const css = [
221
+ rootDecls.length ? `:root:root{${rootDecls.join(';')}}` : '',
222
+ themed ? `:root:root:not([data-theme="dark"]){${LIGHT_DERIVATION}}` : '',
223
+ themed ? `:root:root[data-theme="dark"]{${darkDeclarations(theme)}}` : '',
224
+ rawBlock(':root:root', theme.advanced?.light),
225
+ rawBlock(':root:root[data-theme="dark"]', theme.advanced?.dark),
226
+ ]
227
+ .filter(Boolean)
228
+ .join('');
229
+
230
+ const field = theme.fields && theme.fields !== 'boxed' ? theme.fields : undefined;
231
+ // A draft from a preview surface isn't schema-parsed, so an unknown value means none.
232
+ const effect = theme.titleEffect;
233
+ const titleEffect = effect && effect !== 'none' && TITLE_EFFECTS.includes(effect) ? effect : undefined;
234
+ return { css, field, titleEffect };
235
+ }
package/package.json CHANGED
@@ -1,71 +1,80 @@
1
- {
2
- "name": "ferst-core",
3
- "version": "0.15.0",
4
- "type": "module",
5
- "description": "Ferst Core — the shared, brand-agnostic client-site system: Astro components, layouts, content schemas, the layered config resolver, and a neutral styling architecture that every client overrides.",
6
- "license": "BUSL-1.1",
7
- "author": "MyAI4 Ltd (https://ferst.co.uk)",
8
- "homepage": "https://ferst.co.uk",
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://github.com/MyAI4WebDev/myai4-ferst-core.git",
12
- "directory": "packages/core"
13
- },
14
- "bugs": {
15
- "url": "https://github.com/MyAI4WebDev/myai4-ferst-core/issues"
16
- },
17
- "keywords": [
18
- "astro",
19
- "astro-component",
20
- "cms",
21
- "sveltia",
22
- "website",
23
- "design-tokens",
24
- "ferst"
25
- ],
26
- "scripts": {
27
- "test": "vitest run",
28
- "test:watch": "vitest"
29
- },
30
- "sideEffects": [
31
- "**/*.css"
32
- ],
33
- "files": [
34
- "bin",
35
- "cms",
36
- "components",
37
- "integration.mjs",
38
- "layouts",
39
- "content",
40
- "examples",
41
- "lib",
42
- "routes",
43
- "utils",
44
- "styles",
45
- "fonts",
46
- "README.md",
47
- "NOTICE",
48
- "LICENSE",
49
- "LICENSE-Apache-2.0"
50
- ],
51
- "bin": {
52
- "ferst-check-thin": "bin/check-thin.mjs",
53
- "ferst-check-pages": "bin/check-pages.mjs",
54
- "ferst-set-cms-branch": "bin/set-cms-branch.mjs",
55
- "ferst-cms-config": "bin/cms-config.mjs",
56
- "ferst-update": "bin/ferst-update.mjs",
57
- "ferst-modules": "bin/ferst-modules.mjs"
58
- },
59
- "dependencies": {
60
- "zod": "^3.25.0"
61
- },
62
- "devDependencies": {
63
- "vitest": "^3.0.0"
64
- },
65
- "peerDependencies": {
66
- "astro": "^5.0.0"
67
- },
68
- "publishConfig": {
69
- "access": "public"
70
- }
71
- }
1
+ {
2
+ "name": "ferst-core",
3
+ "version": "0.17.0",
4
+ "type": "module",
5
+ "description": "Ferst Core — the shared, brand-agnostic client-site system: Astro components, layouts, content schemas, the layered config resolver, and a neutral styling architecture that every client overrides.",
6
+ "license": "BUSL-1.1",
7
+ "author": "MyAI4 Ltd (https://ferst.co.uk)",
8
+ "homepage": "https://ferst.co.uk",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/MyAI4WebDev/myai4-ferst-core.git",
12
+ "directory": "packages/core"
13
+ },
14
+ "bugs": {
15
+ "url": "https://github.com/MyAI4WebDev/myai4-ferst-core/issues"
16
+ },
17
+ "keywords": [
18
+ "astro",
19
+ "astro-component",
20
+ "cms",
21
+ "sveltia",
22
+ "website",
23
+ "design-tokens",
24
+ "ferst"
25
+ ],
26
+ "scripts": {
27
+ "test": "vitest run",
28
+ "test:watch": "vitest"
29
+ },
30
+ "sideEffects": [
31
+ "**/*.css"
32
+ ],
33
+ "files": [
34
+ "bin",
35
+ "cms",
36
+ "components",
37
+ "integration.mjs",
38
+ "layouts",
39
+ "content",
40
+ "examples",
41
+ "lib",
42
+ "routes",
43
+ "utils",
44
+ "styles",
45
+ "fonts",
46
+ "README.md",
47
+ "NOTICE",
48
+ "LICENSE",
49
+ "LICENSE-Apache-2.0"
50
+ ],
51
+ "bin": {
52
+ "ferst-check-thin": "bin/check-thin.mjs",
53
+ "ferst-check-pages": "bin/check-pages.mjs",
54
+ "ferst-set-cms-branch": "bin/set-cms-branch.mjs",
55
+ "ferst-cms-config": "bin/cms-config.mjs",
56
+ "ferst-update": "bin/ferst-update.mjs",
57
+ "ferst-modules": "bin/ferst-modules.mjs",
58
+ "ferst-media": "bin/ferst-media.mjs"
59
+ },
60
+ "dependencies": {
61
+ "@astrojs/react": "^4.4.2",
62
+ "@internationalized/date": "^3.12.4",
63
+ "react": "^19.3.1",
64
+ "react-aria": "^3.53.1",
65
+ "react-aria-components": "^1.22.1",
66
+ "react-dom": "^19.3.1",
67
+ "zod": "^3.25.0"
68
+ },
69
+ "devDependencies": {
70
+ "@types/react": "^19.3.3",
71
+ "@types/react-dom": "^19.3.0",
72
+ "vitest": "^3.0.0"
73
+ },
74
+ "peerDependencies": {
75
+ "astro": "^5.0.0"
76
+ },
77
+ "publishConfig": {
78
+ "access": "public"
79
+ }
80
+ }