ferst-core 0.15.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.
Files changed (59) hide show
  1. package/README.md +13 -4
  2. package/bin/ferst-media.mjs +96 -0
  3. package/components/Card.astro +53 -51
  4. package/components/PostCard.astro +138 -136
  5. package/components/SiteHeader.astro +10 -14
  6. package/components/blocks/Grid.astro +49 -48
  7. package/components/blocks/Heading.astro +4 -1
  8. package/components/recipes/Banner.astro +146 -146
  9. package/components/recipes/FeatureCards.astro +112 -118
  10. package/components/recipes/Gallery.astro +57 -59
  11. package/components/recipes/Hero.astro +112 -10
  12. package/components/recipes/LatestPosts.astro +295 -292
  13. package/components/recipes/Locations.astro +146 -143
  14. package/components/recipes/Marquee.astro +75 -75
  15. package/components/recipes/MediaCards.astro +213 -219
  16. package/components/recipes/Pricing.astro +149 -150
  17. package/components/recipes/Stats.astro +150 -157
  18. package/components/recipes/Tiles.astro +342 -296
  19. package/content/blocks.ts +1072 -1024
  20. package/content/imageSlots.mjs +542 -0
  21. package/content/schemas.ts +13 -11
  22. package/examples/recipes.ts +4 -0
  23. package/fonts/OFL.txt +1332 -287
  24. package/fonts/anton-latin-400-normal.woff2 +0 -0
  25. package/fonts/bangers-latin-400-normal.woff2 +0 -0
  26. package/fonts/bebas-neue-latin-400-normal.woff2 +0 -0
  27. package/fonts/bowlby-one-latin-400-normal.woff2 +0 -0
  28. package/fonts/fredoka-latin-400-normal.woff2 +0 -0
  29. package/fonts/fredoka-latin-600-normal.woff2 +0 -0
  30. package/fonts/fredoka-latin-700-normal.woff2 +0 -0
  31. package/fonts/knewave-latin-400-normal.woff2 +0 -0
  32. package/fonts/lora-latin-400-normal.woff2 +0 -0
  33. package/fonts/lora-latin-600-normal.woff2 +0 -0
  34. package/fonts/lora-latin-700-normal.woff2 +0 -0
  35. package/fonts/merriweather-latin-400-normal.woff2 +0 -0
  36. package/fonts/merriweather-latin-600-normal.woff2 +0 -0
  37. package/fonts/merriweather-latin-700-normal.woff2 +0 -0
  38. package/fonts/nunito-latin-400-normal.woff2 +0 -0
  39. package/fonts/nunito-latin-600-normal.woff2 +0 -0
  40. package/fonts/nunito-latin-700-normal.woff2 +0 -0
  41. package/fonts/oswald-latin-400-normal.woff2 +0 -0
  42. package/fonts/oswald-latin-600-normal.woff2 +0 -0
  43. package/fonts/oswald-latin-700-normal.woff2 +0 -0
  44. package/fonts/rubik-dirt-latin-400-normal.woff2 +0 -0
  45. package/integration.mjs +4 -14
  46. package/layouts/Base.astro +7 -16
  47. package/lib/fonts.ts +130 -0
  48. package/lib/gridRows.ts +197 -0
  49. package/lib/image-fields.ts +140 -0
  50. package/lib/image-size.mjs +108 -73
  51. package/lib/image-sizes.ts +16 -0
  52. package/lib/logo-header.ts +46 -0
  53. package/lib/media-check.mjs +524 -0
  54. package/lib/theme-preview.ts +203 -140
  55. package/lib/themeTokens.ts +235 -220
  56. package/package.json +3 -2
  57. package/styles/fonts.css +239 -76
  58. package/styles/theme.css +228 -160
  59. package/lib/gridColumns.ts +0 -22
@@ -1,150 +1,149 @@
1
- ---
2
- /** Pricing — a Level-2 recipe: a row of plan cards (name, price, period,
3
- * feature list, CTA). One plan may be `featured`. Composes Heading + Button +
4
- * the check icon. Token-driven, so it recolours + restyles with the theme. */
5
- import Heading from '../blocks/Heading.astro';
6
- import Button from '../Button.astro';
7
- import Icon from '../Icon.astro';
8
-
9
- interface Plan {
10
- name: string;
11
- price: string;
12
- period?: string;
13
- description?: string;
14
- features?: string[];
15
- cta?: { label: string; href: string };
16
- featured?: boolean;
17
- }
18
- interface Props {
19
- title?: string;
20
- intro?: string;
21
- plans?: Plan[];
22
- }
23
- const { title, intro, plans = [] } = Astro.props;
24
- // Alignment overrides (BlockLayout): the title + intro default to centred; the block's
25
- // own `align`, or `headingAlign` for the title alone, overrides it from the page data.
26
- const { align: blockAlign, headingAlign } = Astro.props as { align?: 'start' | 'center' | 'end'; headingAlign?: 'start' | 'center' | 'end' };
27
- const headAlign = headingAlign ?? blockAlign ?? 'center';
28
- ---
29
-
30
- <section class="b-pricing">
31
- {(title || intro) && (
32
- <div class="b-pricing__head" data-recipe-head data-content-align={headAlign}>
33
- {title && <Heading text={title} level={2} />}
34
- {intro && <p class="b-pricing__intro">{intro}</p>}
35
- </div>
36
- )}
37
- <div class="b-pricing__grid" data-count={plans.length}>
38
- {plans.map((plan) => (
39
- <div class="b-pricing__plan ferst-tile" data-featured={plan.featured ? 'true' : 'false'}>
40
- {plan.featured && <span class="b-pricing__badge">Most popular</span>}
41
- <p class="b-pricing__name">{plan.name}</p>
42
- <p class="b-pricing__price">
43
- <span class="b-pricing__amount">{plan.price}</span>
44
- {plan.period && <span class="b-pricing__period">{plan.period}</span>}
45
- </p>
46
- {plan.description && <p class="b-pricing__desc">{plan.description}</p>}
47
- {plan.features && plan.features.length > 0 && (
48
- <ul class="b-pricing__features">
49
- {plan.features.map((f) => (
50
- <li><span class="b-pricing__check" aria-hidden="true"><Icon name="check" size={16} /></span>{f}</li>
51
- ))}
52
- </ul>
53
- )}
54
- {plan.cta && (
55
- <div class="b-pricing__cta">
56
- <Button href={plan.cta.href} variant={plan.featured ? 'cta' : 'secondary'}>{plan.cta.label}</Button>
57
- </div>
58
- )}
59
- </div>
60
- ))}
61
- </div>
62
- </section>
63
-
64
- <style>
65
- .b-pricing {
66
- display: flex;
67
- flex-direction: column;
68
- gap: 2rem;
69
- max-width: 72rem;
70
- margin-inline: auto;
71
- padding-inline: 1rem;
72
- }
73
- .b-pricing__head {
74
- max-width: var(--max);
75
- margin-inline: auto;
76
- display: flex;
77
- flex-direction: column;
78
- gap: 0.75rem;
79
- }
80
- .b-pricing__intro { margin: 0; color: var(--muted); line-height: 1.6; }
81
- .b-pricing__grid {
82
- display: grid;
83
- grid-template-columns: 1fr;
84
- gap: 1.5rem;
85
- align-items: start;
86
- }
87
- @media (min-width: 48em) {
88
- .b-pricing__grid[data-count='2'] { grid-template-columns: repeat(2, 1fr); }
89
- .b-pricing__grid[data-count='3'] { grid-template-columns: repeat(3, 1fr); }
90
- .b-pricing__grid[data-count='4'] { grid-template-columns: repeat(2, 1fr); }
91
- }
92
- @media (min-width: 64em) {
93
- .b-pricing__grid[data-count='4'] { grid-template-columns: repeat(4, 1fr); }
94
- }
95
- .b-pricing__plan {
96
- display: flex;
97
- flex-direction: column;
98
- gap: 0.75rem;
99
- padding: 1.75rem;
100
- /* surface (bg/border/radius/shadow) comes from .ferst-tile; the featured
101
- variant below overrides border-colour + shadow at higher specificity. */
102
- }
103
- .b-pricing__plan[data-featured='true'] {
104
- border-color: var(--gold);
105
- box-shadow: var(--shadow-lg);
106
- position: relative;
107
- }
108
- .b-pricing__badge {
109
- align-self: var(--content-self, flex-start);
110
- font-size: 0.7rem;
111
- font-weight: 700;
112
- letter-spacing: 0.08em;
113
- text-transform: uppercase;
114
- color: var(--on-brand);
115
- background: var(--gold);
116
- padding: 0.2rem 0.6rem;
117
- border-radius: var(--radius-pill);
118
- }
119
- .b-pricing__name {
120
- margin: 0;
121
- font-family: var(--font-heading);
122
- font-weight: 600;
123
- font-size: 1.1rem;
124
- color: var(--fg);
125
- }
126
- .b-pricing__price { margin: 0; display: flex; align-items: baseline; gap: 0.35rem; }
127
- .b-pricing__amount {
128
- font-family: var(--font-heading);
129
- font-weight: 700;
130
- font-size: clamp(2rem, 1.6rem + 1.4vw, 2.6rem);
131
- line-height: 1;
132
- color: var(--fg);
133
- }
134
- .b-pricing__period { color: var(--muted); font-size: 0.9rem; }
135
- .b-pricing__desc { margin: 0; color: var(--muted); line-height: 1.5; }
136
- .b-pricing__features {
137
- list-style: none;
138
- margin: 0.5rem 0;
139
- padding: 0;
140
- display: flex;
141
- flex-direction: column;
142
- gap: 0.5rem;
143
- color: var(--muted);
144
- line-height: 1.5;
145
- }
146
- .b-pricing__features li { display: flex; gap: 0.5rem; align-items: flex-start; }
147
- .b-pricing__check { color: var(--gold); display: inline-flex; margin-top: 0.1rem; flex-shrink: 0; }
148
- .b-pricing__cta { margin-top: auto; padding-top: 0.5rem; }
149
- .b-pricing__cta :global(.btn) { width: 100%; }
150
- </style>
1
+ ---
2
+ /** Pricing — a Level-2 recipe: a row of plan cards (name, price, period,
3
+ * feature list, CTA). One plan may be `featured`. Composes Heading + Button +
4
+ * the check icon. Token-driven, so it recolours + restyles with the theme. */
5
+ import Heading from '../blocks/Heading.astro';
6
+ import Button from '../Button.astro';
7
+ import Icon from '../Icon.astro';
8
+ import { planGrid } from '../../lib/gridRows';
9
+
10
+ interface Plan {
11
+ name: string;
12
+ price: string;
13
+ period?: string;
14
+ description?: string;
15
+ features?: string[];
16
+ cta?: { label: string; href: string };
17
+ featured?: boolean;
18
+ }
19
+ interface Props {
20
+ title?: string;
21
+ intro?: string;
22
+ plans?: Plan[];
23
+ /** How the ragged last row lays out (lib/gridRows). */
24
+ lastRow?: 'auto' | 'fill' | 'center';
25
+ }
26
+ const { title, intro, plans = [], lastRow = 'auto' } = Astro.props;
27
+ // Alignment overrides (BlockLayout): the title + intro default to centred; the block's
28
+ // own `align`, or `headingAlign` for the title alone, overrides it from the page data.
29
+ const { align: blockAlign, headingAlign } = Astro.props as { align?: 'start' | 'center' | 'end'; headingAlign?: 'start' | 'center' | 'end' };
30
+ const headAlign = headingAlign ?? blockAlign ?? 'center';
31
+ // Rows planned per screen (lib/gridRows): up to four plans to a row on desktops.
32
+ const rows = planGrid(plans.length, { columns: 4, item: 'pricing', lastRow });
33
+ ---
34
+
35
+ <section class="b-pricing">
36
+ {(title || intro) && (
37
+ <div class="b-pricing__head" data-recipe-head data-content-align={headAlign}>
38
+ {title && <Heading text={title} level={2} />}
39
+ {intro && <p class="b-pricing__intro">{intro}</p>}
40
+ </div>
41
+ )}
42
+ <div class="b-pricing__grid ferst-rows" data-count={plans.length} data-cols={rows.cols} style={rows.gridStyle}>
43
+ {plans.map((plan, i) => (
44
+ <div class="b-pricing__plan ferst-tile" data-featured={plan.featured ? 'true' : 'false'} style={rows.itemStyles[i]}>
45
+ {plan.featured && <span class="b-pricing__badge">Most popular</span>}
46
+ <p class="b-pricing__name">{plan.name}</p>
47
+ <p class="b-pricing__price">
48
+ <span class="b-pricing__amount">{plan.price}</span>
49
+ {plan.period && <span class="b-pricing__period">{plan.period}</span>}
50
+ </p>
51
+ {plan.description && <p class="b-pricing__desc">{plan.description}</p>}
52
+ {plan.features && plan.features.length > 0 && (
53
+ <ul class="b-pricing__features">
54
+ {plan.features.map((f) => (
55
+ <li><span class="b-pricing__check" aria-hidden="true"><Icon name="check" size={16} /></span>{f}</li>
56
+ ))}
57
+ </ul>
58
+ )}
59
+ {plan.cta && (
60
+ <div class="b-pricing__cta">
61
+ <Button href={plan.cta.href} variant={plan.featured ? 'cta' : 'secondary'}>{plan.cta.label}</Button>
62
+ </div>
63
+ )}
64
+ </div>
65
+ ))}
66
+ </div>
67
+ </section>
68
+
69
+ <style>
70
+ .b-pricing {
71
+ display: flex;
72
+ flex-direction: column;
73
+ gap: 2rem;
74
+ width: 100%; /* the full content width, whatever its items hold (lib/gridRows) */
75
+ max-width: 72rem;
76
+ margin-inline: auto;
77
+ padding-inline: 1rem;
78
+ }
79
+ .b-pricing__head {
80
+ max-width: var(--max);
81
+ margin-inline: auto;
82
+ display: flex;
83
+ flex-direction: column;
84
+ gap: 0.75rem;
85
+ }
86
+ .b-pricing__intro { margin: 0; color: var(--muted); line-height: 1.6; }
87
+ .b-pricing__grid {
88
+ display: grid;
89
+ gap: 1.5rem;
90
+ align-items: start;
91
+ }
92
+ /* Rows come from lib/gridRows (the global .ferst-rows rules): even rows where the
93
+ count allows by using fewer columns, else full rows and a tidied last row. */
94
+ .b-pricing__plan {
95
+ display: flex;
96
+ flex-direction: column;
97
+ gap: 0.75rem;
98
+ padding: 1.75rem;
99
+ /* surface (bg/border/radius/shadow) comes from .ferst-tile; the featured
100
+ variant below overrides border-colour + shadow at higher specificity. */
101
+ }
102
+ .b-pricing__plan[data-featured='true'] {
103
+ border-color: var(--gold);
104
+ box-shadow: var(--shadow-lg);
105
+ position: relative;
106
+ }
107
+ .b-pricing__badge {
108
+ align-self: var(--content-self, flex-start);
109
+ font-size: 0.7rem;
110
+ font-weight: 700;
111
+ letter-spacing: 0.08em;
112
+ text-transform: uppercase;
113
+ color: var(--on-brand);
114
+ background: var(--gold);
115
+ padding: 0.2rem 0.6rem;
116
+ border-radius: var(--radius-pill);
117
+ }
118
+ .b-pricing__name {
119
+ margin: 0;
120
+ font-family: var(--font-heading);
121
+ font-weight: 600;
122
+ font-size: 1.1rem;
123
+ color: var(--fg);
124
+ }
125
+ .b-pricing__price { margin: 0; display: flex; align-items: baseline; gap: 0.35rem; }
126
+ .b-pricing__amount {
127
+ font-family: var(--font-heading);
128
+ font-weight: 700;
129
+ font-size: clamp(2rem, 1.6rem + 1.4vw, 2.6rem);
130
+ line-height: 1;
131
+ color: var(--fg);
132
+ }
133
+ .b-pricing__period { color: var(--muted); font-size: 0.9rem; }
134
+ .b-pricing__desc { margin: 0; color: var(--muted); line-height: 1.5; }
135
+ .b-pricing__features {
136
+ list-style: none;
137
+ margin: 0.5rem 0;
138
+ padding: 0;
139
+ display: flex;
140
+ flex-direction: column;
141
+ gap: 0.5rem;
142
+ color: var(--muted);
143
+ line-height: 1.5;
144
+ }
145
+ .b-pricing__features li { display: flex; gap: 0.5rem; align-items: flex-start; }
146
+ .b-pricing__check { color: var(--gold); display: inline-flex; margin-top: 0.1rem; flex-shrink: 0; }
147
+ .b-pricing__cta { margin-top: auto; padding-top: 0.5rem; }
148
+ .b-pricing__cta :global(.btn) { width: 100%; }
149
+ </style>
@@ -1,157 +1,150 @@
1
- ---
2
- /** Stats — a Level-2 recipe: a band of headline numbers over an optional
3
- * heading/intro. Composes the Heading primitive; numbers use the brand accent.
4
- *
5
- * Self-composing: the grid never reserves more columns than there are stats, so
6
- * a single item centres as a feature instead of stranding an empty half-band
7
- * (the "£10 pinned to one side" bug); each stat is a token-driven tile (radius/
8
- * surface/stroke/shadow knobs, like every Card), so it reads as a designed unit
9
- * at any count and in either theme. Labels are width-capped so a long caption
10
- * wraps to a tidy block rather than a full-width line. */
11
- import Heading from '../blocks/Heading.astro';
12
- import { gridColumns } from '../../lib/gridColumns';
13
-
14
- interface Item { value: string; label: string; description?: string }
15
- interface Props {
16
- title?: string;
17
- intro?: string;
18
- background?: 'none' | 'muted' | 'accent';
19
- columns?: 2 | 3 | 4;
20
- items?: Item[];
21
- }
22
- const { title, intro, background = 'muted', columns = 3, items = [] } = Astro.props;
23
- // Alignment overrides (BlockLayout): the title + intro default to centred; the block's
24
- // own `align`, or `headingAlign` for the title alone, overrides it from the page data.
25
- const { align: blockAlign, headingAlign } = Astro.props as { align?: 'start' | 'center' | 'end'; headingAlign?: 'start' | 'center' | 'end' };
26
- const headAlign = headingAlign ?? blockAlign ?? 'center';
27
- // Cap the column count at the item count — one stat should never sit in a
28
- // two-column grid (half empty). Falls back to 1 for an empty list.
29
- const { tablet, desktop: cols } = gridColumns(items.length, columns); // never a short last row
30
- ---
31
-
32
- <section class="b-stats" data-bg={background}>
33
- <div class="b-stats__inner">
34
- {(title || intro) && (
35
- <div class="b-stats__head" data-recipe-head data-content-align={headAlign}>
36
- {title && <Heading text={title} level={2} />}
37
- {intro && <p class="b-stats__intro">{intro}</p>}
38
- </div>
39
- )}
40
- <div class="b-stats__grid" data-cols={cols} data-tablet={tablet}>
41
- {items.map((item) => (
42
- <div class="b-stats__item ferst-tile">
43
- <span class="b-stats__value">{item.value}</span>
44
- {item.label && <span class="b-stats__label">{item.label}</span>}
45
- {item.description && <span class="b-stats__desc">{item.description}</span>}
46
- </div>
47
- ))}
48
- </div>
49
- </div>
50
- </section>
51
-
52
- <style>
53
- .b-stats { padding-block: clamp(2.5rem, 6vw, 4rem); }
54
- .b-stats[data-bg='muted'] { background: var(--bg-section); }
55
- .b-stats[data-bg='accent'] { background: var(--gold-light); }
56
- .b-stats__inner {
57
- max-width: 72rem;
58
- margin-inline: auto;
59
- padding-inline: 1rem;
60
- display: flex;
61
- flex-direction: column;
62
- gap: 2rem;
63
- }
64
- .b-stats__head {
65
- max-width: var(--max);
66
- margin-inline: auto;
67
- display: flex;
68
- flex-direction: column;
69
- gap: 0.75rem;
70
- }
71
- .b-stats__intro { margin: 0; color: var(--muted); line-height: 1.6; }
72
- .b-stats__grid {
73
- display: grid;
74
- grid-template-columns: 1fr;
75
- gap: 1.25rem;
76
- width: 100%;
77
- margin-inline: auto;
78
- }
79
- /* Never a short last row (lib/gridColumns): twos on tablet for an even count; on desktop
80
- everything in one row, or even rows. Phones stay one column. */
81
- @media (min-width: 40em) {
82
- .b-stats__grid[data-tablet='2'] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
83
- }
84
- @media (min-width: 60em) {
85
- .b-stats__grid[data-cols='2'] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
86
- .b-stats__grid[data-cols='3'] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
87
- .b-stats__grid[data-cols='4'] { grid-template-columns: repeat(4, minmax(0, 1fr)); }
88
- }
89
- /* A lone stat is a centred feature, not a full-width slab. */
90
- .b-stats__grid[data-cols='1'] { max-width: 30rem; }
91
- /* Token-driven tile: the same radius / surface / stroke / shadow knobs as every
92
- Card, so it stays consistent and theme-correct. On the muted band the tile's
93
- --bg-surface sits a step above --bg-section, giving depth in both themes. */
94
- .b-stats__item {
95
- display: flex;
96
- flex-direction: column;
97
- align-items: center;
98
- text-align: center;
99
- gap: 0.5rem;
100
- padding: clamp(1.5rem, 3vw, 2.25rem) clamp(1.25rem, 3vw, 1.75rem);
101
- /* surface (bg/border/radius/shadow) comes from .ferst-tile */
102
- }
103
- .b-stats__value {
104
- font-family: var(--font-heading);
105
- font-weight: 700;
106
- font-size: clamp(2.25rem, 1.6rem + 2.6vw, 3.25rem);
107
- line-height: 1;
108
- color: var(--gold);
109
- }
110
- .b-stats__label { font-weight: 600; color: var(--fg); line-height: 1.4; max-width: 30ch; }
111
- .b-stats__desc { font-size: 0.875rem; color: var(--muted); line-height: 1.5; max-width: 32ch; }
112
- /* One key figure: centred, not stranded at the start of a wide row. */
113
- .b-stats__grid[data-cols='1'] {
114
- max-width: 28rem;
115
- margin-inline: auto;
116
- text-align: center;
117
- justify-items: center;
118
- }
119
- </style>
120
-
121
- <script>
122
- // Count-up: numbers tick from 0 to their value when they scroll into view.
123
- // Progressive — the final value is server-rendered, so with no JS (or under
124
- // reduced-motion) it just shows the number. Non-numeric values (One, Any…) are
125
- // left untouched; a leading sign / trailing suffix (+, %, " day") is preserved.
126
- const reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
127
- const values = document.querySelectorAll<HTMLElement>('.b-stats__value');
128
- if (!reduce && 'IntersectionObserver' in window && values.length) {
129
- const parse = (t: string) => {
130
- const m = t.match(/^(\D*)(\d[\d,]*(?:\.\d+)?)(.*)$/);
131
- if (!m) return null;
132
- const decimals = (m[2].split('.')[1] || '').length;
133
- return { pre: m[1], num: parseFloat(m[2].replace(/,/g, '')), suf: m[3], decimals };
134
- };
135
- const fmt = (n: number, d: number) => (d > 0 ? n.toFixed(d) : Math.round(n).toLocaleString());
136
- const run = (el: HTMLElement) => {
137
- const final = (el.textContent || '').trim();
138
- const p = parse(final);
139
- if (!p) return;
140
- const dur = 1100;
141
- const t0 = performance.now();
142
- const tick = (now: number) => {
143
- const t = Math.min(1, (now - t0) / dur);
144
- const eased = 1 - Math.pow(1 - t, 3);
145
- el.textContent = p.pre + fmt(p.num * eased, p.decimals) + p.suf;
146
- if (t < 1) requestAnimationFrame(tick);
147
- else el.textContent = final;
148
- };
149
- requestAnimationFrame(tick);
150
- };
151
- const io = new IntersectionObserver(
152
- (entries) => entries.forEach((e) => { if (e.isIntersecting) { run(e.target as HTMLElement); io.unobserve(e.target); } }),
153
- { threshold: 0.4 }
154
- );
155
- values.forEach((v) => io.observe(v));
156
- }
157
- </script>
1
+ ---
2
+ /** Stats — a Level-2 recipe: a band of headline numbers over an optional
3
+ * heading/intro. Composes the Heading primitive; numbers use the brand accent.
4
+ *
5
+ * Self-composing: the grid never reserves more columns than there are stats, so
6
+ * a single item centres as a feature instead of stranding an empty half-band
7
+ * (the "£10 pinned to one side" bug); each stat is a token-driven tile (radius/
8
+ * surface/stroke/shadow knobs, like every Card), so it reads as a designed unit
9
+ * at any count and in either theme. Labels are width-capped so a long caption
10
+ * wraps to a tidy block rather than a full-width line. */
11
+ import Heading from '../blocks/Heading.astro';
12
+ import { planGrid } from '../../lib/gridRows';
13
+
14
+ interface Item { value: string; label: string; description?: string }
15
+ interface Props {
16
+ title?: string;
17
+ intro?: string;
18
+ background?: 'none' | 'muted' | 'accent';
19
+ columns?: 2 | 3 | 4;
20
+ items?: Item[];
21
+ /** How the ragged last row lays out (lib/gridRows). */
22
+ lastRow?: 'auto' | 'fill' | 'center';
23
+ }
24
+ const { title, intro, background = 'muted', columns = 3, items = [], lastRow = 'auto' } = Astro.props;
25
+ // Alignment overrides (BlockLayout): the title + intro default to centred; the block's
26
+ // own `align`, or `headingAlign` for the title alone, overrides it from the page data.
27
+ const { align: blockAlign, headingAlign } = Astro.props as { align?: 'start' | 'center' | 'end'; headingAlign?: 'start' | 'center' | 'end' };
28
+ const headAlign = headingAlign ?? blockAlign ?? 'center';
29
+ // Rows planned per screen (lib/gridRows). Numbers are small items, so tablets fit three;
30
+ // a lone one is centred (`data-cols="1"`).
31
+ const plan = planGrid(items.length, { columns, item: 'stats', lastRow });
32
+ ---
33
+
34
+ <section class="b-stats" data-bg={background}>
35
+ <div class="b-stats__inner">
36
+ {(title || intro) && (
37
+ <div class="b-stats__head" data-recipe-head data-content-align={headAlign}>
38
+ {title && <Heading text={title} level={2} />}
39
+ {intro && <p class="b-stats__intro">{intro}</p>}
40
+ </div>
41
+ )}
42
+ <div class="b-stats__grid ferst-rows" data-cols={plan.cols} style={plan.gridStyle}>
43
+ {items.map((item, i) => (
44
+ <div class="b-stats__item ferst-tile" style={plan.itemStyles[i]}>
45
+ <span class="b-stats__value">{item.value}</span>
46
+ {item.label && <span class="b-stats__label">{item.label}</span>}
47
+ {item.description && <span class="b-stats__desc">{item.description}</span>}
48
+ </div>
49
+ ))}
50
+ </div>
51
+ </div>
52
+ </section>
53
+
54
+ <style>
55
+ .b-stats { padding-block: clamp(2.5rem, 6vw, 4rem); }
56
+ .b-stats[data-bg='muted'] { background: var(--bg-section); }
57
+ .b-stats[data-bg='accent'] { background: var(--gold-light); }
58
+ .b-stats__inner {
59
+ max-width: 72rem;
60
+ margin-inline: auto;
61
+ padding-inline: 1rem;
62
+ display: flex;
63
+ flex-direction: column;
64
+ gap: 2rem;
65
+ }
66
+ .b-stats__head {
67
+ max-width: var(--max);
68
+ margin-inline: auto;
69
+ display: flex;
70
+ flex-direction: column;
71
+ gap: 0.75rem;
72
+ }
73
+ .b-stats__intro { margin: 0; color: var(--muted); line-height: 1.6; }
74
+ .b-stats__grid {
75
+ display: grid;
76
+ gap: 1.25rem;
77
+ width: 100%;
78
+ margin-inline: auto;
79
+ }
80
+ /* Rows come from lib/gridRows (the global .ferst-rows rules): even rows where the
81
+ count allows by using fewer columns, else full rows and a tidied last row. */
82
+ /* A lone stat is a centred feature, not a full-width slab. */
83
+ .b-stats__grid[data-cols='1'] { max-width: 30rem; }
84
+ /* Token-driven tile: the same radius / surface / stroke / shadow knobs as every
85
+ Card, so it stays consistent and theme-correct. On the muted band the tile's
86
+ --bg-surface sits a step above --bg-section, giving depth in both themes. */
87
+ .b-stats__item {
88
+ display: flex;
89
+ flex-direction: column;
90
+ align-items: center;
91
+ text-align: center;
92
+ gap: 0.5rem;
93
+ padding: clamp(1.5rem, 3vw, 2.25rem) clamp(1.25rem, 3vw, 1.75rem);
94
+ /* surface (bg/border/radius/shadow) comes from .ferst-tile */
95
+ }
96
+ .b-stats__value {
97
+ font-family: var(--font-heading);
98
+ font-weight: 700;
99
+ font-size: clamp(2.25rem, 1.6rem + 2.6vw, 3.25rem);
100
+ line-height: 1;
101
+ color: var(--gold);
102
+ }
103
+ .b-stats__label { font-weight: 600; color: var(--fg); line-height: 1.4; max-width: 30ch; }
104
+ .b-stats__desc { font-size: 0.875rem; color: var(--muted); line-height: 1.5; max-width: 32ch; }
105
+ /* One key figure: centred, not stranded at the start of a wide row. */
106
+ .b-stats__grid[data-cols='1'] {
107
+ max-width: 28rem;
108
+ margin-inline: auto;
109
+ text-align: center;
110
+ justify-items: center;
111
+ }
112
+ </style>
113
+
114
+ <script>
115
+ // Count-up: numbers tick from 0 to their value when they scroll into view.
116
+ // Progressive — the final value is server-rendered, so with no JS (or under
117
+ // reduced-motion) it just shows the number. Non-numeric values (One, Any…) are
118
+ // left untouched; a leading sign / trailing suffix (+, %, " day") is preserved.
119
+ const reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
120
+ const values = document.querySelectorAll<HTMLElement>('.b-stats__value');
121
+ if (!reduce && 'IntersectionObserver' in window && values.length) {
122
+ const parse = (t: string) => {
123
+ const m = t.match(/^(\D*)(\d[\d,]*(?:\.\d+)?)(.*)$/);
124
+ if (!m) return null;
125
+ const decimals = (m[2].split('.')[1] || '').length;
126
+ return { pre: m[1], num: parseFloat(m[2].replace(/,/g, '')), suf: m[3], decimals };
127
+ };
128
+ const fmt = (n: number, d: number) => (d > 0 ? n.toFixed(d) : Math.round(n).toLocaleString());
129
+ const run = (el: HTMLElement) => {
130
+ const final = (el.textContent || '').trim();
131
+ const p = parse(final);
132
+ if (!p) return;
133
+ const dur = 1100;
134
+ const t0 = performance.now();
135
+ const tick = (now: number) => {
136
+ const t = Math.min(1, (now - t0) / dur);
137
+ const eased = 1 - Math.pow(1 - t, 3);
138
+ el.textContent = p.pre + fmt(p.num * eased, p.decimals) + p.suf;
139
+ if (t < 1) requestAnimationFrame(tick);
140
+ else el.textContent = final;
141
+ };
142
+ requestAnimationFrame(tick);
143
+ };
144
+ const io = new IntersectionObserver(
145
+ (entries) => entries.forEach((e) => { if (e.isIntersecting) { run(e.target as HTMLElement); io.unobserve(e.target); } }),
146
+ { threshold: 0.4 }
147
+ );
148
+ values.forEach((v) => io.observe(v));
149
+ }
150
+ </script>