ferst-core 0.14.0 → 0.16.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/README.md +13 -4
- package/bin/ferst-media.mjs +96 -0
- package/cms/config.template.yml +11 -0
- package/components/Card.astro +53 -51
- package/components/PostCard.astro +138 -136
- package/components/SiteHeader.astro +1356 -1273
- package/components/blocks/Grid.astro +49 -48
- package/components/blocks/Heading.astro +4 -1
- package/components/recipes/Banner.astro +146 -146
- package/components/recipes/Book.astro +39 -4
- package/components/recipes/FeatureCards.astro +112 -118
- package/components/recipes/Gallery.astro +57 -59
- package/components/recipes/Hero.astro +638 -533
- 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/Pricing.astro +149 -150
- package/components/recipes/Stats.astro +150 -157
- package/components/recipes/Tiles.astro +342 -296
- package/content/blocks.ts +1072 -1024
- package/content/imageSlots.mjs +542 -0
- package/content/schemas.ts +35 -2
- package/examples/recipes.ts +4 -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 +253 -249
- package/layouts/Base.astro +13 -3
- package/lib/book.ts +94 -1
- 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 -0
- package/lib/image-sizes.ts +16 -0
- package/lib/logo-header.ts +46 -0
- package/lib/media-check.mjs +524 -0
- package/lib/theme-preview.ts +203 -140
- package/lib/themeTokens.ts +235 -220
- package/package.json +3 -2
- package/styles/fonts.css +239 -76
- package/styles/theme.css +228 -160
- package/lib/gridColumns.ts +0 -22
package/lib/themeTokens.ts
CHANGED
|
@@ -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
|
|
28
|
-
import { DARK_DEFAULTS, NEUTRAL_SOURCE } from './themeDefaults';
|
|
29
|
-
import { onBrandColour } from './contrast';
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
'--gold
|
|
50
|
-
'--
|
|
51
|
-
'--
|
|
52
|
-
'--
|
|
53
|
-
'--
|
|
54
|
-
'--
|
|
55
|
-
'--
|
|
56
|
-
'--bg
|
|
57
|
-
'--bg-
|
|
58
|
-
'--bg-
|
|
59
|
-
'--
|
|
60
|
-
'--
|
|
61
|
-
'--text-footer-
|
|
62
|
-
'--
|
|
63
|
-
'--news-card-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* --dark-
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
'--dark-
|
|
84
|
-
'--dark-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
'--bg
|
|
92
|
-
'--bg-
|
|
93
|
-
'--bg-
|
|
94
|
-
'--
|
|
95
|
-
'--
|
|
96
|
-
'--
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
'--
|
|
100
|
-
'--
|
|
101
|
-
'--
|
|
102
|
-
'--
|
|
103
|
-
'--text-
|
|
104
|
-
'--text-
|
|
105
|
-
'--
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
'--gold
|
|
109
|
-
'--
|
|
110
|
-
'--
|
|
111
|
-
|
|
112
|
-
//
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const
|
|
131
|
-
const
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
if (clean(ov.
|
|
135
|
-
if (clean(ov.
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
`--dark-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
.
|
|
156
|
-
.
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
field
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
.
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ferst-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"type": "module",
|
|
5
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
6
|
"license": "BUSL-1.1",
|
|
@@ -54,7 +54,8 @@
|
|
|
54
54
|
"ferst-set-cms-branch": "bin/set-cms-branch.mjs",
|
|
55
55
|
"ferst-cms-config": "bin/cms-config.mjs",
|
|
56
56
|
"ferst-update": "bin/ferst-update.mjs",
|
|
57
|
-
"ferst-modules": "bin/ferst-modules.mjs"
|
|
57
|
+
"ferst-modules": "bin/ferst-modules.mjs",
|
|
58
|
+
"ferst-media": "bin/ferst-media.mjs"
|
|
58
59
|
},
|
|
59
60
|
"dependencies": {
|
|
60
61
|
"zod": "^3.25.0"
|