maverick-wave-astro 1.44.0 → 1.46.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.
@@ -31,6 +31,34 @@ const readJpeg = (buffer) => {
31
31
  }
32
32
  return null;
33
33
  };
34
+ const readWebp = (buffer) => {
35
+ if (buffer.length < 30 ||
36
+ buffer.toString('latin1', 0, 4) !== 'RIFF' ||
37
+ buffer.toString('latin1', 8, 12) !== 'WEBP')
38
+ return null;
39
+ // VP8X and VP8L store the size minus one, VP8 keeps scale bits above 14.
40
+ switch (buffer.toString('latin1', 12, 16)) {
41
+ case 'VP8X':
42
+ return {
43
+ width: buffer.readUIntLE(24, 3) + 1,
44
+ height: buffer.readUIntLE(27, 3) + 1,
45
+ };
46
+ case 'VP8 ':
47
+ return {
48
+ width: buffer.readUInt16LE(26) & 0x3fff,
49
+ height: buffer.readUInt16LE(28) & 0x3fff,
50
+ };
51
+ case 'VP8L': {
52
+ const bits = buffer.readUInt32LE(21);
53
+ return {
54
+ width: (bits & 0x3fff) + 1,
55
+ height: ((bits >> 14) & 0x3fff) + 1,
56
+ };
57
+ }
58
+ default:
59
+ return null;
60
+ }
61
+ };
34
62
  const readSvg = (buffer) => {
35
63
  const head = buffer.subarray(0, 2048).toString('utf-8');
36
64
  const viewBox = head.match(/viewBox=["']\s*[\d.-]+\s+[\d.-]+\s+([\d.]+)\s+([\d.]+)/);
@@ -52,6 +80,8 @@ export const imageSize = (publicPath) => {
52
80
  size = readSvg(buffer);
53
81
  else if (/\.jpe?g$/.test(publicPath))
54
82
  size = readJpeg(buffer);
83
+ else if (publicPath.endsWith('.webp'))
84
+ size = readWebp(buffer);
55
85
  else
56
86
  size = readPng(buffer);
57
87
  }
@@ -360,6 +360,11 @@ const settled = async (promise) => {
360
360
  }
361
361
  };
362
362
  export const loadLook = async (options) => {
363
+ // Safari runs module scripts before slow stylesheets have arrived - read
364
+ // that early, the brand colours come out black and the fonts as Times.
365
+ if (document.readyState !== 'complete') {
366
+ await new Promise(resolve => addEventListener('load', resolve, { once: true }));
367
+ }
363
368
  const page = readPage();
364
369
  const font = (size, weight = 400) => `${weight} ${size}px ${page.bodyFamily}`;
365
370
  const heading = (size, weight = 700) => `${weight} ${size}px ${page.headingFamily}`;
@@ -304,8 +304,12 @@ export const seriesCards = (series, site, locale = 'de-DE', now = new Date()) =>
304
304
  items = items.slice(0, config.limit);
305
305
  return items
306
306
  .map(item => {
307
+ const written = new Set(Object.entries(series.standIns ?? {})
308
+ .filter(([from]) => textOf(item[from]))
309
+ .map(([, to]) => to));
307
310
  const rendered = blockList(config).map(({ block, slot }) => {
308
- const shown = renderBlock(item, block, fields, locale);
311
+ // Written for the story, so shown whole - the sentence limit is for the long text.
312
+ const shown = renderBlock(item, written.has(block.source) ? { ...block, sentences: 0 } : block, fields, locale);
309
313
  return { source: block.source, block: shown && { ...shown, slot } };
310
314
  });
311
315
  const blocks = rendered.flatMap(({ block }) => (block ? [block] : []));
@@ -1,5 +1,6 @@
1
1
  import { type Frame, type Look, type Piece } from './base.ts';
2
2
  import { type BlocksCard, type EventCard } from './cards.ts';
3
+ export declare const textSizes: (text: string) => number[];
3
4
  export interface SeriesTexts {
4
5
  kicker?: string;
5
6
  footer?: string;
@@ -17,10 +17,19 @@ const WEEKDAY_SIZES = [
17
17
  ];
18
18
  const TILE_HEIGHT = 262;
19
19
  const BAND = 70;
20
- // The text at its full size, then smaller before a line has to be cut.
21
- const TEXT_SIZES = [40, 36, 32];
22
20
  const TEXT_LEADING = 1.5;
23
- const TEXT_LINE = TEXT_SIZES[0] * TEXT_LEADING;
21
+ const TEXT_LINE = 40 * TEXT_LEADING;
22
+ const TEXT_SMALLEST = 32;
23
+ // A short text starts a little larger, a long one a little smaller, then all
24
+ // get smaller before a line has to be cut.
25
+ export const textSizes = (text) => {
26
+ const long = Math.min(1, Math.max(0, (text.length - 120) / 140));
27
+ const sizes = [];
28
+ for (let size = Math.round(44 - 8 * long); size >= TEXT_SMALLEST; size -= 2) {
29
+ sizes.push(size);
30
+ }
31
+ return sizes;
32
+ };
24
33
  const TEXT_GAP = 28;
25
34
  // Below a run of rows, before the next block.
26
35
  const AFTER_ROWS = 48;
@@ -238,12 +247,12 @@ const column = (ctx, look, frame, ink, blocks, space, minLead) => {
238
247
  totalHeight(rows.map(row => rowBlock(ctx, look, ink, row, room)))
239
248
  : 0;
240
249
  const maxHeight = free - reserved >= 2 * TEXT_LINE ? free - reserved : free;
241
- if (maxHeight < Math.round(TEXT_SIZES.at(-1) * TEXT_LEADING))
250
+ if (maxHeight < Math.round(TEXT_SMALLEST * TEXT_LEADING))
242
251
  break;
243
252
  add(textBlock(ctx, block.text, {
244
253
  font: size => look.font(size, 400),
245
254
  color: inkOf(ink, block.color),
246
- sizes: TEXT_SIZES,
255
+ sizes: textSizes(block.text),
247
256
  lineHeight: TEXT_LEADING,
248
257
  maxHeight,
249
258
  }, TEXT_GAP, room), 'text', [block], block.above, block.below);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "maverick-wave-astro",
3
- "version": "1.44.0",
3
+ "version": "1.46.0",
4
4
  "description": "Shared frame for static Astro homepages built with MaverickWave: layout, SEO, design variants, schedule, building blocks.",
5
5
  "type": "module",
6
6
  "license": "MIT",