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
@@ -90,6 +90,15 @@ const NECESSARY: readonly CookieUse[] = [
90
90
  },
91
91
  ];
92
92
 
93
+ /** The members' sign-in (the Ferst Members module): on a site where members sign in. */
94
+ const MEMBERS_SESSION: CookieUse = {
95
+ id: 'members-session',
96
+ category: 'necessary',
97
+ name: 'Members’ sign-in',
98
+ purpose: 'Keeps you signed in to your account on this site after you sign in with a code sent to your email. Set only when you sign in, and removed when you sign out.',
99
+ storage: 'A cookie set by this site (__Host-ferst_member), kept for 30 days from your last visit. Only this site reads it; it is never shared.',
100
+ };
101
+
93
102
  /** Third-party embeds — listed only when a site actually uses them. */
94
103
  const ADDITIONAL: readonly AdditionalUse[] = [
95
104
  {
@@ -157,6 +166,9 @@ export interface CookieScanInput {
157
166
  blockTypes?: Iterable<string>;
158
167
  /** True when the site has a Google Calendar configured (dedicated calendar page). */
159
168
  calendarConfigured?: boolean;
169
+ /** True when members sign in on the site (the Ferst Members module): its sign-in cookie is listed.
170
+ * A members' page block on the site lists it too. */
171
+ members?: boolean;
160
172
  }
161
173
 
162
174
  export interface CookiePolicyModel {
@@ -186,6 +198,8 @@ const BY_TYPE: Record<string, string[]> = {
186
198
  /** Report the cookie uses actually active on a site, grouped by category. */
187
199
  export function scanCookieUses(input: CookieScanInput): CookiePolicyModel {
188
200
  const necessary = NECESSARY.map((u) => ({ ...u }));
201
+ const signsIn = input.members === true || (input.blocks ? allBlocks(input.blocks).some((b) => b.type === 'membersContent') : false);
202
+ if (signsIn) necessary.push({ ...MEMBERS_SESSION });
189
203
  if (!input.blocks && input.blockTypes) {
190
204
  const types = new Set(input.blockTypes);
191
205
  const additional = ADDITIONAL.filter(
@@ -0,0 +1,542 @@
1
+ /**
2
+ * Image slots: every place a block or a setting shows a picture, and what that place expects.
3
+ * It sits next to the schema (content/blocks.ts, content/schemas.ts, content/posts.ts) because
4
+ * it's the engine's own layout knowledge: the numbers below are read off each component's CSS,
5
+ * and each slot names the component it mirrors (`mirrors`), so a CSS change has a visible place
6
+ * to update. A coverage test (tests/image-slots.test.ts) walks the Zod schemas and fails when
7
+ * an image field has no slot here, or when a slot ignores a `ratio` field its block has.
8
+ *
9
+ * Plain JavaScript (with JSDoc types), not TypeScript, so the `ferst-media` bin can read it
10
+ * with plain Node in a client site, where nothing compiles TypeScript.
11
+ *
12
+ * A slot's key is the block type (or `page`, `post`, or a settings collection such as
13
+ * `logoSettings`) and the path to the field, `[]` marking a list: `tiles.tiles[].image.src`.
14
+ * A key maps to one spec, or to a list of modes when one field shows differently by its
15
+ * block's settings (the first mode whose `when` matches is the one on the page; none
16
+ * matching means the block doesn't show that picture).
17
+ *
18
+ * Sizes assume the page's content column on a desktop: `.site-main` is 72rem with up to
19
+ * 2.5rem padding a side (layouts/Base.astro), so 1072px of content, and a full-width band
20
+ * is the screen (1440px on a typical laptop). `recommended` is about twice the CSS size (sharp
21
+ * on high-density screens), `min` about once (soft below it). Nothing needs more than 2400px.
22
+ */
23
+
24
+ /** No picture needs to be wider than this: anything wider only slows the page. */
25
+ export const MAX_WIDTH = 2400;
26
+
27
+ /**
28
+ * @typedef {{ width?: number, height?: number }} Px
29
+ * @typedef {{ block: Record<string, any>, item: Record<string, any> }} SlotContext
30
+ * `block`: the block (or page, post, settings file); `item`: the list entry the picture is in
31
+ * (a tile, a card), or the block itself when it isn't in a list.
32
+ * @typedef {{
33
+ * label: string,
34
+ * ratio: string,
35
+ * ratioDefault?: string,
36
+ * shapes?: Record<string, string>,
37
+ * recommended: Px,
38
+ * min: Px,
39
+ * max: { width: number },
40
+ * fit: 'cover' | 'contain',
41
+ * focus: boolean,
42
+ * safe: string,
43
+ * text: boolean,
44
+ * textNote?: string,
45
+ * alpha: boolean,
46
+ * when?: (ctx: SlotContext) => boolean,
47
+ * mirrors: string,
48
+ * }} ImageSlot
49
+ * - `label`: what the place is, in plain words (the asset brief's heading).
50
+ * - `ratio`: the shape: fixed (`'16/9'`), `'any'` (the picture keeps its own), or the field that
51
+ * sets it (`'mediaCards.ratio'`, `'bento.items[].size'`); `ratioDefault` is that field's
52
+ * default, and `shapes` turns its values into shapes when they aren't shapes themselves.
53
+ * - `recommended` / `min`: pixels; a missing side follows from the shape.
54
+ * - `fit`: `cover` (cropped to fill the shape; `focus` says the block's `focus` is honoured)
55
+ * or `contain` (never cropped).
56
+ * - `safe`: where subjects and words stay in view. `text`: whether words in the picture are
57
+ * fine. `alpha`: whether it needs a see-through background.
58
+ */
59
+
60
+ const max = { width: MAX_WIDTH };
61
+ const isMediaHero = ({ block }) => (block.layout ?? 'centered') === 'media';
62
+ /** A tile with a picture and no words is a picture tile, shown whole (Tiles.astro `plain`). */
63
+ const isPictureTile = ({ block, item }) =>
64
+ (block.variant ?? 'elevated') === 'image' && !item.title && !item.text && !item.eyebrow;
65
+
66
+ /** The opening band's background, a picture, a slide or a video's still (all the same place). */
67
+ const heroBackground = (label, when = isMediaHero) => ({
68
+ label,
69
+ // Hero.astro: .b-hero__img / .b-hero__slide cover the band, object-position --hero-focus.
70
+ // The band's height by `size` (desktop, 1440x900 screen, 1072px column): compact
71
+ // clamp(8rem, 18vw, 16rem) = 256px (about 9:2); standard min(68vh, 38rem) = 608px (about
72
+ // 2:1); tall min(85vh, 52rem) = 765px (about 3:2); screen fills the screen under the header
73
+ // (1440 x 836, about 16:9). Full bleed makes a band wider still; phones show a tall slice.
74
+ ratio: 'hero.size',
75
+ ratioDefault: 'standard',
76
+ shapes: { compact: '9/2', standard: '2/1', tall: '3/2', screen: '16/9' },
77
+ recommended: { width: 2400 },
78
+ min: { width: 1280 },
79
+ max,
80
+ fit: 'cover',
81
+ focus: true,
82
+ safe: 'Keep the subject in the middle third. Wide screens crop the top and bottom, and phones show a tall slice from the middle (or around the focus point).',
83
+ text: false,
84
+ textNote: 'The title and button sit on top of it, so words in the picture would clash.',
85
+ alpha: false,
86
+ when,
87
+ mirrors: 'components/recipes/Hero.astro (.b-hero[data-size] min-height, .b-hero__img object-fit: cover)',
88
+ });
89
+
90
+ /** The opening band's picture shown whole (`media.fit: "contain"`), e.g. a designed poster. */
91
+ const isPosterHero = ({ block }) => isMediaHero({ block }) && block.media?.fit === 'contain' && !block.media?.video;
92
+ const heroPoster = (label) => ({
93
+ label,
94
+ // Hero.astro [data-fit='contain']: the band takes the picture's own shape (aspect-ratio from
95
+ // its size), edge to edge with `screen` or full bleed (1440px wide on the 1440x900 desktop);
96
+ // the picture is object-fit: contain, never cropped, with no shade over it.
97
+ ratio: 'any',
98
+ recommended: { width: 2400 },
99
+ min: { width: 1280 },
100
+ max,
101
+ fit: 'contain',
102
+ focus: false,
103
+ safe: 'Shown whole, never cropped, as wide as the screen: on a phone it is small, so keep lettering large.',
104
+ text: true,
105
+ alpha: false,
106
+ when: isPosterHero,
107
+ mirrors: "components/recipes/Hero.astro ([data-fit='contain'] .b-hero__img object-fit: contain)",
108
+ });
109
+
110
+ /** @type {Record<string, ImageSlot | ImageSlot[]>} */
111
+ export const IMAGE_SLOTS = {
112
+ // ── Primitives ──
113
+ 'image.src': {
114
+ label: 'Picture',
115
+ // ImageBlock.astro: width 100% of its column (up to 1072px), height auto; a `ratio` sets
116
+ // aspect-ratio with object-fit: cover, cropped around `focus`.
117
+ ratio: 'image.ratio',
118
+ ratioDefault: 'auto',
119
+ recommended: { width: 2000 },
120
+ min: { width: 800 },
121
+ max,
122
+ fit: 'cover',
123
+ focus: true,
124
+ safe: 'Shown whole unless the block sets a shape; then it is cropped from the middle (or around the focus point).',
125
+ text: true,
126
+ alpha: false,
127
+ mirrors: 'components/blocks/ImageBlock.astro (width: 100%; aspect-ratio from `ratio`, object-fit: cover)',
128
+ },
129
+
130
+ // ── Recipes ──
131
+ 'hero.image.src': {
132
+ label: 'Picture beside the opening words',
133
+ // Hero.astro split layout: two equal columns from 48em, (1072 - 2rem gap) / 2 = 520px;
134
+ // .b-hero__media img is width 100%, height auto (shown whole).
135
+ ratio: 'any',
136
+ recommended: { width: 1100 },
137
+ min: { width: 550 },
138
+ max,
139
+ fit: 'contain',
140
+ focus: false,
141
+ safe: 'Shown whole, beside the title. A landscape or square picture sits best next to the words.',
142
+ text: true,
143
+ alpha: false,
144
+ when: ({ block }) => block.layout === 'split',
145
+ mirrors: 'components/recipes/Hero.astro (split: grid 1fr 1fr, .b-hero__media img width: 100%)',
146
+ },
147
+ 'hero.media.image': [heroPoster('Opening poster (shown whole)'), heroBackground('Opening band background')],
148
+ 'hero.media.images[]': [heroPoster('Opening poster slideshow picture (shown whole)'), heroBackground('Opening band slideshow picture')],
149
+ 'hero.titleImage.src': {
150
+ label: 'Title picture (a wordmark)',
151
+ // Hero.astro .b-hero__title-image: in the h1, width by `width` (20 / 32.5 / 47.5rem = 320 /
152
+ // 520 / 760px, at most 85vw and its column), height auto: shown whole over the opener.
153
+ ratio: 'any',
154
+ recommended: { width: 1520 },
155
+ min: { width: 760 },
156
+ max,
157
+ fit: 'contain',
158
+ focus: false,
159
+ safe: 'Shown whole in place of the title, over the opening picture: trim it close to the lettering.',
160
+ text: true,
161
+ alpha: true,
162
+ mirrors: 'components/recipes/Hero.astro (.b-hero__title-image width --title-image-w, height auto)',
163
+ },
164
+ 'hero.media.poster': heroBackground('Opening band video still', ({ block }) => isMediaHero({ block }) && !!block.media?.video),
165
+
166
+ 'gallery.images[].src': {
167
+ label: 'Gallery picture',
168
+ // Gallery.astro: img aspect-ratio 4 / 3, object-fit: cover; two columns of (1072 - gap) / 2
169
+ // = 525px, a single picture 34rem = 544px.
170
+ ratio: '4/3',
171
+ recommended: { width: 1100 },
172
+ min: { width: 550 },
173
+ max,
174
+ fit: 'cover',
175
+ focus: false,
176
+ safe: 'Cropped to 4:3 from the middle: keep the subject centred.',
177
+ text: false,
178
+ textNote: 'The edges are cropped, so words near them can be cut.',
179
+ alpha: false,
180
+ mirrors: 'components/recipes/Gallery.astro (img aspect-ratio: 4 / 3, object-fit: cover)',
181
+ },
182
+
183
+ 'testimonial.avatar.src': {
184
+ label: 'Portrait beside a quote',
185
+ // Testimonial.astro: .b-testimonial__avatar 44 x 44px, border-radius 999px, object-fit: cover.
186
+ ratio: '1/1',
187
+ recommended: { width: 200, height: 200 },
188
+ min: { width: 88, height: 88 },
189
+ max,
190
+ fit: 'cover',
191
+ focus: false,
192
+ safe: 'Shown as a small circle: the face in the centre, filling most of the picture.',
193
+ text: false,
194
+ alpha: false,
195
+ mirrors: 'components/recipes/Testimonial.astro (.b-testimonial__avatar 44px circle, object-fit: cover)',
196
+ },
197
+
198
+ 'tiles.tiles[].image.src': [
199
+ {
200
+ label: 'Picture tile, filling its tile',
201
+ // Tiles.astro `fit: "bleed"` with a set `ratio`: the picture is the tile (no padding),
202
+ // aspect-ratio --tile-ratio, object-fit: cover round the tile image's focus. Three
203
+ // columns are (1072 - 2 gaps) / 3 = 340px; two are 520px.
204
+ ratio: 'tiles.ratio',
205
+ ratioDefault: 'auto',
206
+ recommended: { width: 1000 },
207
+ min: { width: 500 },
208
+ max,
209
+ fit: 'cover',
210
+ focus: true,
211
+ safe: 'Cropped to the tiles’ shape from the middle (or around the focus point): keep the subject and any lettering away from the edges.',
212
+ text: true,
213
+ alpha: false,
214
+ when: (ctx) => isPictureTile(ctx) && ctx.block.fit === 'bleed' && (ctx.block.ratio ?? 'auto') !== 'auto',
215
+ mirrors: "components/recipes/Tiles.astro ([data-fit='bleed'] .b-tile__picture: aspect-ratio --tile-ratio, object-fit: cover)",
216
+ },
217
+ {
218
+ label: 'Picture tile',
219
+ // Tiles.astro: a tile with a picture and no words (`plain`): .b-tile__picture width 100%,
220
+ // max-height 18rem (288px) in a frame (none with `bleed`), object-fit: contain, never
221
+ // cropped; a set `ratio` gives the frame that shape. Three columns are
222
+ // (1072 - 2 gaps) / 3 = 340px less 0.75rem padding; two are 520px.
223
+ ratio: 'tiles.ratio',
224
+ ratioDefault: 'auto',
225
+ recommended: { width: 1000 },
226
+ min: { width: 500 },
227
+ max,
228
+ fit: 'contain',
229
+ focus: false,
230
+ safe: 'Shown whole, never cropped. Pictures in one row look tidiest when they share one shape.',
231
+ text: true,
232
+ alpha: false,
233
+ when: isPictureTile,
234
+ mirrors: 'components/recipes/Tiles.astro ([data-plain] .b-tile__picture: max-height 18rem, object-fit: contain)',
235
+ },
236
+ {
237
+ label: 'Picture behind a tile’s words',
238
+ // Tiles.astro variant `image`: the picture is the tile's background (background-size:
239
+ // cover, position --tile-focus) under a dark shade; the tile is min-height 15rem (240px)
240
+ // and 340px wide in three columns (about 3:2), 520px in two.
241
+ ratio: '3/2',
242
+ recommended: { width: 1100 },
243
+ min: { width: 550 },
244
+ max,
245
+ fit: 'cover',
246
+ focus: true,
247
+ safe: 'Keep the subject in the upper half: the tile’s words sit over the bottom on a dark shade.',
248
+ text: false,
249
+ textNote: 'The tile’s own words sit on top of it.',
250
+ alpha: false,
251
+ when: ({ block }) => (block.variant ?? 'elevated') === 'image',
252
+ mirrors: 'components/recipes/Tiles.astro ([data-variant=image] .b-tile::before background-size: cover, min-height 15rem)',
253
+ },
254
+ ],
255
+
256
+ 'banner.image': {
257
+ label: 'Feature band background',
258
+ // Banner.astro: background-size: cover behind a card of words. With parallax (the default)
259
+ // the background is pinned to the screen (background-attachment: fixed), so it is sized to
260
+ // the screen (16:10 on a laptop); without it, the band is 1072px by min(60vh, 34rem) =
261
+ // 540px (about 2:1). 16:9 sits between the two.
262
+ ratio: '16/9',
263
+ recommended: { width: 2400, height: 1350 },
264
+ min: { width: 1280, height: 720 },
265
+ max,
266
+ fit: 'cover',
267
+ focus: false,
268
+ safe: 'Keep the subject clear of the side the words card sits on, and away from the very top and bottom.',
269
+ text: false,
270
+ textNote: 'A card of words floats over it.',
271
+ alpha: false,
272
+ mirrors: 'components/recipes/Banner.astro (background-size: cover; fixed under parallax; min-height min(60vh, 34rem))',
273
+ },
274
+
275
+ 'logos.items[].src': {
276
+ label: 'Logo in a logo wall',
277
+ // Logos.astro: img height clamp(1.75rem, 4vw, 2.5rem) = up to 40px, width auto (whole).
278
+ ratio: 'any',
279
+ recommended: { height: 80 },
280
+ min: { height: 40 },
281
+ max,
282
+ fit: 'contain',
283
+ focus: false,
284
+ safe: 'Shown about 40 pixels tall, in grey until pointed at. Trim empty space around the logo so it shows at the right size.',
285
+ text: true,
286
+ alpha: true,
287
+ mirrors: 'components/recipes/Logos.astro (img height: clamp(1.75rem, 4vw, 2.5rem), width: auto)',
288
+ },
289
+
290
+ 'tabs.items[].image.src': {
291
+ label: 'Picture in a tab',
292
+ // Tabs.astro: max-width 60rem (960px); a panel with a picture is two columns from 48em,
293
+ // so about 460px; .b-tabs__img width 100%, height auto (whole).
294
+ ratio: 'any',
295
+ recommended: { width: 1000 },
296
+ min: { width: 500 },
297
+ max,
298
+ fit: 'contain',
299
+ focus: false,
300
+ safe: 'Shown whole, beside the tab’s words.',
301
+ text: true,
302
+ alpha: false,
303
+ mirrors: 'components/recipes/Tabs.astro (.b-tabs__img width: 100%, height: auto; panel grid 1fr 1fr)',
304
+ },
305
+
306
+ 'bento.items[].image.src': {
307
+ label: 'Picture behind a mosaic tile',
308
+ // Bento.astro: four columns from 64em, (1072 - 3rem of gaps) / 4 = 256px, rows at least
309
+ // 11rem (176px), background-size: cover at --bento-focus. By `size`: sm 256x176 (about
310
+ // 3:2), wide 528x176 (3:1), tall 256x368 (3:4), lg 528x368 (3:2).
311
+ ratio: 'bento.items[].size',
312
+ ratioDefault: 'sm',
313
+ shapes: { sm: '3/2', wide: '3/1', tall: '3/4', lg: '3/2' },
314
+ recommended: { width: 1100 },
315
+ min: { width: 550 },
316
+ max,
317
+ fit: 'cover',
318
+ focus: true,
319
+ safe: 'Keep the subject in the upper half: the tile’s words sit over the bottom on a dark shade.',
320
+ text: false,
321
+ textNote: 'The tile’s own words sit on top of it.',
322
+ alpha: false,
323
+ when: ({ item }) => (item.variant ?? 'surface') === 'image',
324
+ mirrors: 'components/recipes/Bento.astro ([data-variant=image]::before background-size: cover; grid-auto-rows minmax(11rem, auto))',
325
+ },
326
+
327
+ 'mediaCards.cards[].image.src': {
328
+ label: 'Card picture',
329
+ // MediaCards.astro: .b-media-cards__media aspect-ratio from the block's `ratio`, img
330
+ // object-fit: cover at the card's focus; two columns 520px, one card 28rem = 448px.
331
+ ratio: 'mediaCards.ratio',
332
+ ratioDefault: '16/9',
333
+ recommended: { width: 1100 },
334
+ min: { width: 550 },
335
+ max,
336
+ fit: 'cover',
337
+ focus: true,
338
+ safe: 'Cropped to the cards’ shape from the middle (or around the focus point): keep the subject centred.',
339
+ text: false,
340
+ textNote: 'The picture is cropped to the card’s shape, so words in it can be cut.',
341
+ alpha: false,
342
+ mirrors: 'components/recipes/MediaCards.astro (.b-media-cards__media aspect-ratio from `ratio`, img object-fit: cover)',
343
+ },
344
+
345
+ 'mediaText.image.src': {
346
+ label: 'Picture beside text',
347
+ // MediaText.astro: two equal columns from 48em, (1072 - 3rem gap) / 2 = 512px; img width
348
+ // 100%, height auto, or aspect-ratio from `ratio` with object-fit: cover at `focus`.
349
+ ratio: 'mediaText.ratio',
350
+ ratioDefault: 'auto',
351
+ recommended: { width: 1100 },
352
+ min: { width: 550 },
353
+ max,
354
+ fit: 'cover',
355
+ focus: true,
356
+ safe: 'Shown whole unless the block sets a shape; then it is cropped from the middle (or around the focus point).',
357
+ text: true,
358
+ alpha: false,
359
+ mirrors: 'components/recipes/MediaText.astro (img width: 100%; aspect-ratio from `ratio`, object-fit: cover)',
360
+ },
361
+
362
+ // ── A page and a post ──
363
+ 'page.heroImage': {
364
+ label: 'Page’s sharing picture',
365
+ // layouts/Base.astro: preloaded, and the page's og:image (lib/seo.mjs previewTags), which
366
+ // social sites show at 1200 x 630 (1.91:1), cropping other shapes.
367
+ ratio: '40/21',
368
+ recommended: { width: 1200, height: 630 },
369
+ min: { width: 600, height: 315 },
370
+ max,
371
+ fit: 'cover',
372
+ focus: false,
373
+ safe: 'Shown when the page is shared. Social sites crop the edges: keep the subject and any words in the middle.',
374
+ text: true,
375
+ textNote: 'Keep them large and in the middle.',
376
+ alpha: false,
377
+ mirrors: 'layouts/Base.astro (heroImage preload; og:image via lib/seo.mjs previewTags)',
378
+ },
379
+ 'post.heroImage': {
380
+ label: 'News post picture',
381
+ // PostArticle.astro shows it whole across the column (1072px); PostCard.astro crops it to
382
+ // aspect-ratio 16 / 9 with object-fit: cover; LatestPosts.astro's list to a 3.25rem square.
383
+ ratio: '16/9',
384
+ recommended: { width: 1600, height: 900 },
385
+ min: { width: 800, height: 450 },
386
+ max,
387
+ fit: 'cover',
388
+ focus: false,
389
+ safe: 'Keep the subject in the middle: news cards crop it to 16:9, and the short list to a small square.',
390
+ text: false,
391
+ textNote: 'Cards crop it, so words in it can be cut.',
392
+ alpha: false,
393
+ mirrors: 'components/PostCard.astro (aspect-ratio: 16 / 9, object-fit: cover); components/PostArticle.astro',
394
+ },
395
+
396
+ // ── Settings: logos and the browser icon ──
397
+ 'logoSettings.primaryLogoLight': {
398
+ label: 'Header logo',
399
+ // SiteHeader.astro: .primary-logo height --header-logo-h (44px phones, 56px desktops;
400
+ // `large` 112px, `xl` 216px on desktops), width auto (whole).
401
+ ratio: 'any',
402
+ recommended: { height: 432 },
403
+ min: { height: 112 },
404
+ max,
405
+ fit: 'contain',
406
+ focus: false,
407
+ safe: 'Shown whole in the header. Trim empty space around it so it shows at the right size. An SVG stays sharp at every size.',
408
+ text: true,
409
+ alpha: true,
410
+ mirrors: 'components/SiteHeader.astro (.primary-logo height: var(--header-logo-h), 56px to 216px)',
411
+ },
412
+ 'logoSettings.primaryLogoDark': {
413
+ label: 'Header logo for dark mode',
414
+ // SiteHeader.astro: the same place as the light logo, swapped in dark mode.
415
+ ratio: 'any',
416
+ recommended: { height: 432 },
417
+ min: { height: 112 },
418
+ max,
419
+ fit: 'contain',
420
+ focus: false,
421
+ safe: 'The same as the header logo, in colours that read on a dark background.',
422
+ text: true,
423
+ alpha: true,
424
+ mirrors: 'components/SiteHeader.astro (.primary-logo height: var(--header-logo-h), 56px to 216px)',
425
+ },
426
+ 'logoSettings.secondaryLogoLight': {
427
+ label: 'Footer logo',
428
+ // SecondaryLogo.astro + layouts/Base.astro: .secondary-logo__img max-width min(150px, 100%).
429
+ ratio: 'any',
430
+ recommended: { width: 300 },
431
+ min: { width: 150 },
432
+ max,
433
+ fit: 'contain',
434
+ focus: false,
435
+ safe: 'Shown whole, up to 150 pixels wide.',
436
+ text: true,
437
+ alpha: true,
438
+ mirrors: 'components/SecondaryLogo.astro (.secondary-logo__img max-width: min(150px, 100%), in layouts/Base.astro)',
439
+ },
440
+ 'logoSettings.secondaryLogoDark': {
441
+ label: 'Footer logo for dark mode',
442
+ ratio: 'any',
443
+ recommended: { width: 300 },
444
+ min: { width: 150 },
445
+ max,
446
+ fit: 'contain',
447
+ focus: false,
448
+ safe: 'The same as the footer logo, in colours that read on a dark background.',
449
+ text: true,
450
+ alpha: true,
451
+ mirrors: 'components/SecondaryLogo.astro (.secondary-logo__img max-width: min(150px, 100%), in layouts/Base.astro)',
452
+ },
453
+ 'logoSettings.favicon': {
454
+ label: 'Browser icon',
455
+ // lib/site-icon.mjs draws /favicon.ico at 32 and 48px and /apple-touch-icon.png at 180px.
456
+ ratio: '1/1',
457
+ recommended: { width: 512, height: 512 },
458
+ min: { width: 48, height: 48 },
459
+ max,
460
+ fit: 'contain',
461
+ focus: false,
462
+ safe: 'A square mark that fills most of the square: it shows as small as 16 pixels in a browser tab.',
463
+ text: false,
464
+ textNote: 'Words can’t be read that small: use a mark or a single letter.',
465
+ alpha: true,
466
+ mirrors: 'lib/site-icon.mjs (favicon.ico 32 + 48px, apple-touch-icon 180px)',
467
+ },
468
+ };
469
+
470
+ /** A slot's modes, always a list. */
471
+ export function slotModes(key) {
472
+ const s = IMAGE_SLOTS[key];
473
+ return !s ? [] : Array.isArray(s) ? s : [s];
474
+ }
475
+
476
+ const SHAPE = /^(\d+(?:\.\d+)?)\/(\d+(?:\.\d+)?)$/;
477
+
478
+ /** A shape's width over height (`'16/9'` gives 1.777…), or null for `'any'` / not a shape. */
479
+ export function shapeValue(shape) {
480
+ const m = SHAPE.exec(String(shape ?? '').replace(/\s+/g, ''));
481
+ return m && Number(m[2]) > 0 ? Number(m[1]) / Number(m[2]) : null;
482
+ }
483
+
484
+ /** Whether a slot's `ratio` names a field (`'mediaCards.ratio'`) rather than a shape. */
485
+ export const isFieldRef = (ratio) => ratio !== 'any' && shapeValue(ratio) === null;
486
+
487
+ /**
488
+ * The shape a field value means for a slot: a shape itself (`'4/3'`), `square`, `auto` (the
489
+ * picture keeps its own, `'any'`), or a value the slot's `shapes` maps. Null when unknown.
490
+ */
491
+ export function shapeForValue(slot, value) {
492
+ const v = String(value);
493
+ if (slot.shapes) return slot.shapes[v] ?? null;
494
+ if (v === 'auto' || v === 'any') return 'any';
495
+ if (v === 'square') return '1/1';
496
+ return shapeValue(v) !== null ? v.replace(/\s+/g, '') : null;
497
+ }
498
+
499
+ /**
500
+ * Read the value a field reference points at, from the objects a picture sits in. `refPath`
501
+ * and `imagePath` are a key's path after its block type (`['items[]', 'size']`,
502
+ * `['items[]', 'image', 'src']`); `ancestors[i]` is the object after `i` steps of the image path.
503
+ */
504
+ export function readRef(refPath, imagePath, ancestors) {
505
+ let k = 0;
506
+ while (k < refPath.length - 1 && k < imagePath.length && refPath[k] === imagePath[k]) k++;
507
+ let obj = ancestors[Math.min(k, ancestors.length - 1)];
508
+ for (const seg of refPath.slice(k)) {
509
+ if (obj == null || typeof obj !== 'object') return undefined;
510
+ obj = obj[seg.replace(/\[\]$/, '')];
511
+ }
512
+ return obj;
513
+ }
514
+
515
+ /** Split a key or a ratio reference into its block type and path: `'a.b[].c'` → ['a', ['b[]', 'c']]. */
516
+ export function splitKey(key) {
517
+ const [head, ...path] = key.split('.');
518
+ return [head, path];
519
+ }
520
+
521
+ /**
522
+ * The shape a slot has where a picture is used: fixed, `'any'`, or read from the field the
523
+ * slot names (its default when the block leaves it out).
524
+ * @param {ImageSlot} slot
525
+ * @param {string} key the slot's key
526
+ * @param {Record<string, any>[]} ancestors the objects along the key's path, block first
527
+ */
528
+ export function resolveShape(slot, key, ancestors) {
529
+ if (!isFieldRef(slot.ratio)) return slot.ratio;
530
+ const [, imagePath] = splitKey(key);
531
+ const [, refPath] = splitKey(slot.ratio);
532
+ const value = readRef(refPath, imagePath, ancestors) ?? slot.ratioDefault;
533
+ return (value === undefined ? null : shapeForValue(slot, value)) ?? 'any';
534
+ }
535
+
536
+ /** Recommended (or minimum) pixel size for a shape: fills in the side the slot leaves out. */
537
+ export function sizeFor(px, shape) {
538
+ const r = shapeValue(shape);
539
+ const width = px.width ?? (r && px.height ? Math.round(px.height * r) : undefined);
540
+ const height = px.height ?? (r && px.width ? Math.round(px.width / r) : undefined);
541
+ return { width, height };
542
+ }