maverick-wave-astro 1.9.0 → 1.11.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 +6 -0
- package/components/StoryCards.astro +270 -0
- package/dist/icons.d.ts +1 -0
- package/dist/icons.js +1 -0
- package/dist/integration.d.ts +1 -1
- package/dist/story/base.d.ts +77 -0
- package/dist/story/base.js +330 -0
- package/dist/story/cards.d.ts +42 -0
- package/dist/story/cards.js +28 -0
- package/dist/story/event.d.ts +3 -0
- package/dist/story/event.js +114 -0
- package/dist/story/promo.d.ts +3 -0
- package/dist/story/promo.js +131 -0
- package/dist/types.d.ts +4 -0
- package/package.json +3 -3
- package/styles/story-cards.css +80 -0
package/README.md
CHANGED
|
@@ -26,6 +26,12 @@ The integration sets the CSP-safe build options, the `@` alias, the sitemap,
|
|
|
26
26
|
`satisfies Site` (`src/types.ts`). Colours and fonts stay in the site's
|
|
27
27
|
`main.scss`.
|
|
28
28
|
|
|
29
|
+
After the build it writes `robots.txt` (`site.aiCrawlers`), `llms.txt` and, with
|
|
30
|
+
`site.email`, `/.well-known/security.txt` - only for a site at the root of its
|
|
31
|
+
host, a file in `public/` wins. It warns about titles over 60 characters,
|
|
32
|
+
descriptions outside 140-160, pages without exactly one `<h1>` and images over
|
|
33
|
+
200 KB.
|
|
34
|
+
|
|
29
35
|
## Design
|
|
30
36
|
|
|
31
37
|
`design` in `site.ts` takes the semantic values from `src/design.ts`, e.g.
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
---
|
|
2
|
+
// Story images in 9:16 for Instagram Story and WhatsApp Status, drawn in the
|
|
3
|
+
// browser from what the site keeps anyway: the upcoming events and the running
|
|
4
|
+
// promotion. Meant for a page of its own with noIndex and no link to it - the
|
|
5
|
+
// owner's tool, not a page of the homepage.
|
|
6
|
+
import '../styles/story-cards.css';
|
|
7
|
+
|
|
8
|
+
import { config } from '../dist/config.js';
|
|
9
|
+
import { PACKAGE_ICONS } from '../dist/icons.js';
|
|
10
|
+
import { withBase } from '../dist/path.js';
|
|
11
|
+
import {
|
|
12
|
+
discountText,
|
|
13
|
+
eventDateText,
|
|
14
|
+
eventExpiry,
|
|
15
|
+
type Promo,
|
|
16
|
+
promoEndDate,
|
|
17
|
+
promoExpiry,
|
|
18
|
+
promoInHtml,
|
|
19
|
+
promoStart,
|
|
20
|
+
promoText,
|
|
21
|
+
upcomingEvents,
|
|
22
|
+
} from '../dist/schedule.js';
|
|
23
|
+
import type { LookOptions, StoryIcon } from '../dist/story/base.js';
|
|
24
|
+
import {
|
|
25
|
+
promoOffers,
|
|
26
|
+
type StoryCard,
|
|
27
|
+
type StoryEvent,
|
|
28
|
+
storyFileName,
|
|
29
|
+
type StoryOffer,
|
|
30
|
+
} from '../dist/story/cards.js';
|
|
31
|
+
import type { StoryLook } from '../dist/types.js';
|
|
32
|
+
|
|
33
|
+
interface Props extends StoryLook {
|
|
34
|
+
events?: readonly StoryEvent[];
|
|
35
|
+
promo?: Promo | null;
|
|
36
|
+
// The prices the promotion applies to - as in Price, only those with an
|
|
37
|
+
// amount.
|
|
38
|
+
offers?: readonly StoryOffer[];
|
|
39
|
+
// Path data from the site's own icon set, so the story matches the page.
|
|
40
|
+
icons?: Partial<Record<StoryIcon, string>>;
|
|
41
|
+
texts?: {
|
|
42
|
+
share?: string;
|
|
43
|
+
save?: string;
|
|
44
|
+
empty?: string;
|
|
45
|
+
soldOut?: string;
|
|
46
|
+
free?: string;
|
|
47
|
+
currency?: string;
|
|
48
|
+
until?: string;
|
|
49
|
+
// The line below the card, e.g. where to sign up or book.
|
|
50
|
+
eventFooter?: string;
|
|
51
|
+
promoFooter?: string;
|
|
52
|
+
// A second line below both, e.g. an invitation to reply to the story.
|
|
53
|
+
reply?: string;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const german = config.site.lang.startsWith('de');
|
|
58
|
+
|
|
59
|
+
const {
|
|
60
|
+
logo,
|
|
61
|
+
background,
|
|
62
|
+
events = [],
|
|
63
|
+
promo,
|
|
64
|
+
offers = [],
|
|
65
|
+
icons = {},
|
|
66
|
+
texts = {},
|
|
67
|
+
} = Astro.props;
|
|
68
|
+
|
|
69
|
+
const {
|
|
70
|
+
share = german ? 'Bild teilen' : 'Share image',
|
|
71
|
+
save = german ? 'Bild speichern' : 'Save image',
|
|
72
|
+
empty = german
|
|
73
|
+
? 'Gerade gibt es nichts zu teilen.'
|
|
74
|
+
: 'Nothing to share right now.',
|
|
75
|
+
soldOut = german ? 'Ausgebucht' : 'Sold out',
|
|
76
|
+
free = german ? 'kostenlos' : 'free',
|
|
77
|
+
currency = 'Euro',
|
|
78
|
+
until = german ? 'Nur noch bis' : 'Only until',
|
|
79
|
+
eventFooter,
|
|
80
|
+
promoFooter,
|
|
81
|
+
reply,
|
|
82
|
+
} = texts;
|
|
83
|
+
|
|
84
|
+
const site = config.site.name;
|
|
85
|
+
|
|
86
|
+
interface Story {
|
|
87
|
+
card: StoryCard;
|
|
88
|
+
label: string;
|
|
89
|
+
file: string;
|
|
90
|
+
starts?: string | null;
|
|
91
|
+
expires?: string | null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const eventStories = upcomingEvents(events).map((entry): Story => ({
|
|
95
|
+
card: {
|
|
96
|
+
kind: 'event',
|
|
97
|
+
title: entry.title,
|
|
98
|
+
date: eventDateText(entry),
|
|
99
|
+
time: entry.time,
|
|
100
|
+
location: entry.location,
|
|
101
|
+
price: entry.price !== undefined ? String(entry.price) : undefined,
|
|
102
|
+
text: entry.text,
|
|
103
|
+
soldOut: entry.soldOut,
|
|
104
|
+
},
|
|
105
|
+
label: entry.title,
|
|
106
|
+
file: storyFileName(site, entry.title, entry.date),
|
|
107
|
+
expires: eventExpiry(entry),
|
|
108
|
+
}));
|
|
109
|
+
|
|
110
|
+
const discounted =
|
|
111
|
+
promo && promoInHtml(promo) ? promoOffers(promo, offers) : [];
|
|
112
|
+
|
|
113
|
+
const promoStories: Story[] =
|
|
114
|
+
promo && discounted.length > 0
|
|
115
|
+
? [
|
|
116
|
+
{
|
|
117
|
+
card: {
|
|
118
|
+
kind: 'promo',
|
|
119
|
+
percent: discountText(promo),
|
|
120
|
+
title: promo.text,
|
|
121
|
+
until: promoEndDate(promo),
|
|
122
|
+
offers: discounted,
|
|
123
|
+
},
|
|
124
|
+
label: promoText(promo),
|
|
125
|
+
file: storyFileName(
|
|
126
|
+
site,
|
|
127
|
+
german ? 'rabatt' : 'promo',
|
|
128
|
+
promo.until ?? ''
|
|
129
|
+
),
|
|
130
|
+
starts: promoStart(promo),
|
|
131
|
+
expires: promoExpiry(promo),
|
|
132
|
+
},
|
|
133
|
+
]
|
|
134
|
+
: [];
|
|
135
|
+
|
|
136
|
+
const look: LookOptions = {
|
|
137
|
+
logo: withBase(logo),
|
|
138
|
+
background,
|
|
139
|
+
icons: {
|
|
140
|
+
calendar: icons.calendar ?? PACKAGE_ICONS.calendar,
|
|
141
|
+
clock: icons.clock ?? PACKAGE_ICONS.clock,
|
|
142
|
+
location: icons.location ?? PACKAGE_ICONS['map-pin'],
|
|
143
|
+
sparkle: icons.sparkle ?? PACKAGE_ICONS.sparkle,
|
|
144
|
+
},
|
|
145
|
+
texts: { soldOut, free, currency, until, eventFooter, promoFooter, reply },
|
|
146
|
+
};
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
<div
|
|
150
|
+
class="mwa-story-cards"
|
|
151
|
+
data-story-cards={JSON.stringify(look)}
|
|
152
|
+
data-share={share}
|
|
153
|
+
data-save={save}
|
|
154
|
+
>
|
|
155
|
+
{
|
|
156
|
+
[...eventStories, ...promoStories].map(story => (
|
|
157
|
+
<article
|
|
158
|
+
class="mwa-story-card"
|
|
159
|
+
data-story={JSON.stringify(story.card)}
|
|
160
|
+
data-file={story.file}
|
|
161
|
+
data-starts={story.starts}
|
|
162
|
+
data-expires={story.expires}
|
|
163
|
+
>
|
|
164
|
+
<div class="mwa-story-card-stage">
|
|
165
|
+
<canvas
|
|
166
|
+
class="mwa-story-card-image"
|
|
167
|
+
role="img"
|
|
168
|
+
aria-label={story.label}
|
|
169
|
+
/>
|
|
170
|
+
<button
|
|
171
|
+
type="button"
|
|
172
|
+
class="mw-btn mw-btn-primary mw-btn-lg mwa-story-card-btn"
|
|
173
|
+
data-story-save
|
|
174
|
+
/>
|
|
175
|
+
</div>
|
|
176
|
+
</article>
|
|
177
|
+
))
|
|
178
|
+
}
|
|
179
|
+
<p class="mwa-story-cards-empty" data-story-empty hidden>{empty}</p>
|
|
180
|
+
</div>
|
|
181
|
+
|
|
182
|
+
<script>
|
|
183
|
+
import {
|
|
184
|
+
HEIGHT,
|
|
185
|
+
loadLook,
|
|
186
|
+
type LookOptions,
|
|
187
|
+
WIDTH,
|
|
188
|
+
} from '../dist/story/base.js';
|
|
189
|
+
import type { StoryCard } from '../dist/story/cards.js';
|
|
190
|
+
import { drawEvent } from '../dist/story/event.js';
|
|
191
|
+
import { drawPromo } from '../dist/story/promo.js';
|
|
192
|
+
|
|
193
|
+
const root = document.querySelector<HTMLElement>('[data-story-cards]');
|
|
194
|
+
const now = new Date();
|
|
195
|
+
const stories = [
|
|
196
|
+
...document.querySelectorAll<HTMLElement>('[data-story]'),
|
|
197
|
+
].filter(el => {
|
|
198
|
+
// As on the start page: expired events and promotions drop out in the
|
|
199
|
+
// browser, promotions that have not started yet as well - no deployment
|
|
200
|
+
// needed for that.
|
|
201
|
+
const { starts, expires } = el.dataset;
|
|
202
|
+
if (
|
|
203
|
+
(expires && new Date(expires) < now) ||
|
|
204
|
+
(starts && new Date(starts) > now)
|
|
205
|
+
) {
|
|
206
|
+
el.remove();
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
return true;
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
if (root && stories.length === 0) {
|
|
213
|
+
root.querySelector('[data-story-empty]')?.removeAttribute('hidden');
|
|
214
|
+
} else if (root) {
|
|
215
|
+
// On the phone sharing leads straight to Instagram or WhatsApp, the detour
|
|
216
|
+
// through the gallery goes away. On the desktop there is no such thing.
|
|
217
|
+
const canShare =
|
|
218
|
+
navigator.canShare?.({
|
|
219
|
+
files: [new File([], 'test.png', { type: 'image/png' })],
|
|
220
|
+
}) ?? false;
|
|
221
|
+
|
|
222
|
+
const save = async (canvas: HTMLCanvasElement, name: string) => {
|
|
223
|
+
const blob = await new Promise<Blob | null>(done =>
|
|
224
|
+
canvas.toBlob(done, 'image/png')
|
|
225
|
+
);
|
|
226
|
+
const file = blob && new File([blob], name, { type: 'image/png' });
|
|
227
|
+
|
|
228
|
+
if (file && canShare) {
|
|
229
|
+
try {
|
|
230
|
+
await navigator.share({ files: [file] });
|
|
231
|
+
return;
|
|
232
|
+
} catch {
|
|
233
|
+
// Cancelled or refused - then download it instead.
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const link = document.createElement('a');
|
|
238
|
+
// data: instead of blob: - the CSP of the page only lets data: through.
|
|
239
|
+
link.href = canvas.toDataURL('image/png');
|
|
240
|
+
link.download = name;
|
|
241
|
+
link.click();
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
const look = await loadLook(
|
|
245
|
+
JSON.parse(root.dataset.storyCards ?? '{}') as LookOptions
|
|
246
|
+
);
|
|
247
|
+
const label = (canShare ? root.dataset.share : root.dataset.save) ?? '';
|
|
248
|
+
|
|
249
|
+
for (const el of stories) {
|
|
250
|
+
const canvas = el.querySelector('canvas');
|
|
251
|
+
const button = el.querySelector<HTMLButtonElement>('[data-story-save]');
|
|
252
|
+
const ctx = canvas?.getContext('2d');
|
|
253
|
+
if (!canvas || !button || !ctx) continue;
|
|
254
|
+
|
|
255
|
+
canvas.width = WIDTH;
|
|
256
|
+
canvas.height = HEIGHT;
|
|
257
|
+
const card = JSON.parse(el.dataset.story ?? '{}') as StoryCard;
|
|
258
|
+
if (card.kind === 'promo') {
|
|
259
|
+
drawPromo(ctx, card, look);
|
|
260
|
+
} else {
|
|
261
|
+
drawEvent(ctx, card, look);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
button.textContent = label;
|
|
265
|
+
button.addEventListener('click', () =>
|
|
266
|
+
save(canvas, `${el.dataset.file}.png`)
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
</script>
|
package/dist/icons.d.ts
CHANGED
|
@@ -15,5 +15,6 @@ export declare const PACKAGE_ICONS: {
|
|
|
15
15
|
readonly 'map-pin': "<path d=\"M12 21s-6.5-5.6-6.5-11a6.5 6.5 0 0 1 13 0c0 5.4-6.5 11-6.5 11Z\"/><circle cx=\"12\" cy=\"10\" r=\"2.4\"/>";
|
|
16
16
|
readonly mail: "<rect x=\"3\" y=\"5\" width=\"18\" height=\"14\" rx=\"2.4\"/><path d=\"m3.5 6.5 8.5 6.5 8.5-6.5\"/>";
|
|
17
17
|
readonly 'calendar-check': "<rect x=\"3\" y=\"5\" width=\"18\" height=\"16\" rx=\"2.4\"/><path d=\"M3 10h18M8 3v4M16 3v4M9 15.5l2 2 4-4\"/>";
|
|
18
|
+
readonly sparkle: "<path d=\"M12 2.8 13.9 9l6.2 1.9-6.2 1.9L12 19l-1.9-6.2L3.9 10.9 10.1 9 12 2.8Z\"/><path d=\"M19 16.5l.7 2.2 2.2.7-2.2.7-.7 2.2-.7-2.2-2.2-.7 2.2-.7.7-2.2Z\"/>";
|
|
18
19
|
readonly 'panel-right': "<rect x=\"3\" y=\"4\" width=\"18\" height=\"16\" rx=\"2.4\"/><path d=\"M15 4v16\"/>";
|
|
19
20
|
};
|
package/dist/icons.js
CHANGED
|
@@ -17,5 +17,6 @@ export const PACKAGE_ICONS = {
|
|
|
17
17
|
'map-pin': '<path d="M12 21s-6.5-5.6-6.5-11a6.5 6.5 0 0 1 13 0c0 5.4-6.5 11-6.5 11Z"/><circle cx="12" cy="10" r="2.4"/>',
|
|
18
18
|
mail: '<rect x="3" y="5" width="18" height="14" rx="2.4"/><path d="m3.5 6.5 8.5 6.5 8.5-6.5"/>',
|
|
19
19
|
'calendar-check': '<rect x="3" y="5" width="18" height="16" rx="2.4"/><path d="M3 10h18M8 3v4M16 3v4M9 15.5l2 2 4-4"/>',
|
|
20
|
+
sparkle: '<path d="M12 2.8 13.9 9l6.2 1.9-6.2 1.9L12 19l-1.9-6.2L3.9 10.9 10.1 9 12 2.8Z"/><path d="M19 16.5l.7 2.2 2.2.7-2.2.7-.7 2.2-.7-2.2-2.2-.7 2.2-.7.7-2.2Z"/>',
|
|
20
21
|
'panel-right': '<rect x="3" y="4" width="18" height="16" rx="2.4"/><path d="M15 4v16"/>',
|
|
21
22
|
};
|
package/dist/integration.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { AstroIntegration } from 'astro';
|
|
|
3
3
|
import { type Werkbank } from './content.ts';
|
|
4
4
|
import type { Config, OgImage, Site } from './types.ts';
|
|
5
5
|
export type { Design } from './design.ts';
|
|
6
|
-
export type { OgImage, Site } from './types.ts';
|
|
6
|
+
export type { OgImage, Site, StoryLook } from './types.ts';
|
|
7
7
|
export type Options = {
|
|
8
8
|
site: Site;
|
|
9
9
|
ogImage: OgImage;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { StoryLook } from '../types.ts';
|
|
2
|
+
export declare const WIDTH = 1080;
|
|
3
|
+
export declare const HEIGHT = 1920;
|
|
4
|
+
export declare const mw: (value: number) => number;
|
|
5
|
+
export declare const MARGIN = 66;
|
|
6
|
+
export declare const PADDING = 76;
|
|
7
|
+
export declare const CONTENT_WIDTH: number;
|
|
8
|
+
export type StoryIcon = 'calendar' | 'clock' | 'location' | 'sparkle';
|
|
9
|
+
export interface StoryTexts {
|
|
10
|
+
soldOut: string;
|
|
11
|
+
free: string;
|
|
12
|
+
currency: string;
|
|
13
|
+
until: string;
|
|
14
|
+
eventFooter?: string;
|
|
15
|
+
promoFooter?: string;
|
|
16
|
+
reply?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface LookOptions extends StoryLook {
|
|
19
|
+
icons: Record<StoryIcon, string>;
|
|
20
|
+
texts: StoryTexts;
|
|
21
|
+
}
|
|
22
|
+
export type Look = Awaited<ReturnType<typeof loadLook>>;
|
|
23
|
+
export declare const loadLook: (options: LookOptions) => Promise<{
|
|
24
|
+
colors: {
|
|
25
|
+
grayClear: string;
|
|
26
|
+
primary: string;
|
|
27
|
+
secondary: string;
|
|
28
|
+
text: string;
|
|
29
|
+
muted: string;
|
|
30
|
+
graySurface: string;
|
|
31
|
+
secondarySurface: string;
|
|
32
|
+
accent: string;
|
|
33
|
+
shadowNear: string;
|
|
34
|
+
shadowFar: string;
|
|
35
|
+
};
|
|
36
|
+
font: (size: number, weight?: number) => string;
|
|
37
|
+
radii: number[];
|
|
38
|
+
logo: {
|
|
39
|
+
width: number;
|
|
40
|
+
height: number;
|
|
41
|
+
image: HTMLImageElement;
|
|
42
|
+
};
|
|
43
|
+
icons: {
|
|
44
|
+
calendar: HTMLImageElement;
|
|
45
|
+
clock: HTMLImageElement;
|
|
46
|
+
location: HTMLImageElement;
|
|
47
|
+
sparkle: HTMLImageElement;
|
|
48
|
+
};
|
|
49
|
+
background: readonly [string, string];
|
|
50
|
+
texts: StoryTexts;
|
|
51
|
+
}>;
|
|
52
|
+
export interface Block {
|
|
53
|
+
height: number;
|
|
54
|
+
gap: number;
|
|
55
|
+
paint: (y: number) => void;
|
|
56
|
+
}
|
|
57
|
+
export declare const textBlock: (ctx: CanvasRenderingContext2D, look: Look, text: string, { size, weight, color, lineHeight, gap, maxLines, }: {
|
|
58
|
+
size: number;
|
|
59
|
+
weight: number;
|
|
60
|
+
color: string;
|
|
61
|
+
lineHeight: number;
|
|
62
|
+
gap: number;
|
|
63
|
+
maxLines?: number;
|
|
64
|
+
}) => Block;
|
|
65
|
+
export declare const iconRow: (ctx: CanvasRenderingContext2D, look: Look, image: HTMLImageElement, text: string, { size, weight, color, gap, }: {
|
|
66
|
+
size: number;
|
|
67
|
+
weight: number;
|
|
68
|
+
color: string;
|
|
69
|
+
gap: number;
|
|
70
|
+
}) => Block;
|
|
71
|
+
export declare const divider: (ctx: CanvasRenderingContext2D, look: Look, gap: number) => Block;
|
|
72
|
+
export declare const totalHeight: (blocks: Block[]) => number;
|
|
73
|
+
export declare const stage: (look: Look) => {
|
|
74
|
+
top: number;
|
|
75
|
+
height: number;
|
|
76
|
+
};
|
|
77
|
+
export declare const drawStory: (ctx: CanvasRenderingContext2D, look: Look, blocks: Block[], footer?: string) => void;
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
export const WIDTH = 1080;
|
|
2
|
+
export const HEIGHT = 1920;
|
|
3
|
+
// Instagram and WhatsApp put their own controls over the top and bottom of the
|
|
4
|
+
// image. Everything readable stays in between.
|
|
5
|
+
const SAFE_TOP = 190;
|
|
6
|
+
const SAFE_BOTTOM = 250;
|
|
7
|
+
// The framework values apply to the card on a 390px wide phone; here we draw
|
|
8
|
+
// into the 1080px of the file, so larger in the same ratio.
|
|
9
|
+
export const mw = (value) => (value * WIDTH) / 390;
|
|
10
|
+
export const MARGIN = 66;
|
|
11
|
+
export const PADDING = 76;
|
|
12
|
+
const CARD_WIDTH = WIDTH - MARGIN * 2;
|
|
13
|
+
export const CONTENT_WIDTH = CARD_WIDTH - PADDING * 2;
|
|
14
|
+
const LOGO_MAX_WIDTH = 440;
|
|
15
|
+
// A square logo at the full width would push the card off the bottom.
|
|
16
|
+
const LOGO_MAX_HEIGHT = 180;
|
|
17
|
+
const ICON = 44;
|
|
18
|
+
const WHITE = '#ffffff';
|
|
19
|
+
const ACCENT_STROKE = mw(2);
|
|
20
|
+
const ACCENT_STRETCH = 1.5;
|
|
21
|
+
const ACCENT_OPAQUE = 0.55;
|
|
22
|
+
// The same colour with alpha 0, as the end of a gradient: against
|
|
23
|
+
// 'transparent' the canvas interpolates through black and turns grey. Read
|
|
24
|
+
// back from a pixel, since the page may hand out any colour syntax.
|
|
25
|
+
const clear = (color) => {
|
|
26
|
+
const ctx = document.createElement('canvas').getContext('2d');
|
|
27
|
+
if (!ctx)
|
|
28
|
+
return 'rgba(0, 0, 0, 0)';
|
|
29
|
+
ctx.fillStyle = color;
|
|
30
|
+
ctx.fillRect(0, 0, 1, 1);
|
|
31
|
+
const [r, g, b] = ctx.getImageData(0, 0, 1, 1).data;
|
|
32
|
+
return `rgba(${r}, ${g}, ${b}, 0)`;
|
|
33
|
+
};
|
|
34
|
+
// Inside a light theme box: the image is seen on other phones and does not
|
|
35
|
+
// follow the dark mode of the one it was made on.
|
|
36
|
+
const readColors = () => {
|
|
37
|
+
const box = document.createElement('div');
|
|
38
|
+
box.className = 'mw-theme-light';
|
|
39
|
+
box.hidden = true;
|
|
40
|
+
const probe = document.createElement('span');
|
|
41
|
+
box.append(probe);
|
|
42
|
+
document.body.append(box);
|
|
43
|
+
const color = (token) => {
|
|
44
|
+
probe.style.color = `var(${token})`;
|
|
45
|
+
return getComputedStyle(probe).color;
|
|
46
|
+
};
|
|
47
|
+
const colors = {
|
|
48
|
+
primary: color('--mw-primary-color'),
|
|
49
|
+
secondary: color('--mw-secondary-color'),
|
|
50
|
+
text: color('--mw-text-color'),
|
|
51
|
+
muted: color('--mw-gray-color'),
|
|
52
|
+
graySurface: color('--mw-gray-background'),
|
|
53
|
+
secondarySurface: color('--mw-secondary-background'),
|
|
54
|
+
accent: color('--mw-corner-accent'),
|
|
55
|
+
shadowNear: color('--mw-shadow-near'),
|
|
56
|
+
shadowFar: color('--mw-shadow-far'),
|
|
57
|
+
};
|
|
58
|
+
box.remove();
|
|
59
|
+
return { ...colors, grayClear: clear(colors.muted) };
|
|
60
|
+
};
|
|
61
|
+
// MaverickWave draws its surfaces with sharp corners on one diagonal and round
|
|
62
|
+
// ones with an accent arc on the other. On the website mw-corners-even may turn
|
|
63
|
+
// that off, in the story the silhouette stays on purpose. As in the framework:
|
|
64
|
+
// radius-sharp() takes the scale squared, radius('xl') linearly, both with
|
|
65
|
+
// radius('xs') as the floor.
|
|
66
|
+
const cardRadii = () => {
|
|
67
|
+
const raw = getComputedStyle(document.documentElement)
|
|
68
|
+
.getPropertyValue('--mw-radius-scale')
|
|
69
|
+
.trim();
|
|
70
|
+
const scale = raw === '' || !Number.isFinite(Number(raw)) ? 1 : Number(raw);
|
|
71
|
+
const sharp = mw(Math.max(2, 5 * scale * scale));
|
|
72
|
+
const round = mw(Math.max(2, 20 * scale));
|
|
73
|
+
// Order as in CSS: top left, top right, bottom right, bottom left.
|
|
74
|
+
return [sharp, round, sharp, round];
|
|
75
|
+
};
|
|
76
|
+
const svgImage = async (markup) => {
|
|
77
|
+
const image = new Image();
|
|
78
|
+
// data: instead of blob: - the CSP of the page only lets data: through.
|
|
79
|
+
image.src = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(markup)}`;
|
|
80
|
+
await image.decode();
|
|
81
|
+
return image;
|
|
82
|
+
};
|
|
83
|
+
const iconImage = (paths, color) => svgImage(`<svg xmlns="http://www.w3.org/2000/svg" width="${ICON}" height="${ICON}" viewBox="0 0 24 24" fill="none" stroke="${color}" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">${paths}</svg>`);
|
|
84
|
+
const fit = (width, height) => {
|
|
85
|
+
const scale = Math.min(LOGO_MAX_WIDTH / width, LOGO_MAX_HEIGHT / height);
|
|
86
|
+
return {
|
|
87
|
+
width: Math.round(width * scale),
|
|
88
|
+
height: Math.round(height * scale),
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
const logoImage = async (path) => {
|
|
92
|
+
if (!path.endsWith('.svg')) {
|
|
93
|
+
const image = new Image();
|
|
94
|
+
image.src = path;
|
|
95
|
+
await image.decode();
|
|
96
|
+
return { image, ...fit(image.naturalWidth, image.naturalHeight) };
|
|
97
|
+
}
|
|
98
|
+
const source = await fetch(path).then(response => response.text());
|
|
99
|
+
const svg = new DOMParser().parseFromString(source, 'image/svg+xml').documentElement;
|
|
100
|
+
const viewBox = svg
|
|
101
|
+
.getAttribute('viewBox')
|
|
102
|
+
?.split(/[\s,]+/)
|
|
103
|
+
.map(Number);
|
|
104
|
+
const size = fit(viewBox?.[2] ?? parseFloat(svg.getAttribute('width') ?? ''), viewBox?.[3] ?? parseFloat(svg.getAttribute('height') ?? ''));
|
|
105
|
+
// Without width/height the browser guesses the size of the SVG in the <img>.
|
|
106
|
+
// Set through the DOM and not replaced in the text: an export sometimes
|
|
107
|
+
// brings the two along and sometimes not, and twice in the same tag the SVG
|
|
108
|
+
// no longer parses.
|
|
109
|
+
svg.setAttribute('width', String(size.width));
|
|
110
|
+
svg.setAttribute('height', String(size.height));
|
|
111
|
+
const image = await svgImage(new XMLSerializer().serializeToString(svg));
|
|
112
|
+
return { image, ...size };
|
|
113
|
+
};
|
|
114
|
+
export const loadLook = async (options) => {
|
|
115
|
+
const family = getComputedStyle(document.body).fontFamily;
|
|
116
|
+
const font = (size, weight = 400) => `${weight} ${size}px ${family}`;
|
|
117
|
+
// Without the wait the canvas draws the fallback font - it knows no
|
|
118
|
+
// re-render when the real font arrives later.
|
|
119
|
+
await Promise.all([400, 500, 700].map(weight => document.fonts.load(font(100, weight))));
|
|
120
|
+
const colors = readColors();
|
|
121
|
+
const icon = (name) => iconImage(options.icons[name], colors.primary);
|
|
122
|
+
const [logo, calendar, clock, location, sparkle] = await Promise.all([
|
|
123
|
+
logoImage(options.logo),
|
|
124
|
+
icon('calendar'),
|
|
125
|
+
icon('clock'),
|
|
126
|
+
icon('location'),
|
|
127
|
+
icon('sparkle'),
|
|
128
|
+
]);
|
|
129
|
+
return {
|
|
130
|
+
colors,
|
|
131
|
+
font,
|
|
132
|
+
radii: cardRadii(),
|
|
133
|
+
logo,
|
|
134
|
+
icons: { calendar, clock, location, sparkle },
|
|
135
|
+
background: options.background,
|
|
136
|
+
texts: options.texts,
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
const wrapLines = (ctx, text, maxWidth) => {
|
|
140
|
+
const lines = [];
|
|
141
|
+
let line = '';
|
|
142
|
+
for (const word of text.split(/\s+/).filter(Boolean)) {
|
|
143
|
+
const attempt = line ? `${line} ${word}` : word;
|
|
144
|
+
if (line && ctx.measureText(attempt).width > maxWidth) {
|
|
145
|
+
lines.push(line);
|
|
146
|
+
line = word;
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
line = attempt;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (line)
|
|
153
|
+
lines.push(line);
|
|
154
|
+
return lines;
|
|
155
|
+
};
|
|
156
|
+
export const textBlock = (ctx, look, text, { size, weight, color, lineHeight, gap, maxLines = Infinity, }) => {
|
|
157
|
+
ctx.font = look.font(size, weight);
|
|
158
|
+
let lines = wrapLines(ctx, text, CONTENT_WIDTH);
|
|
159
|
+
if (lines.length > maxLines) {
|
|
160
|
+
lines = lines.slice(0, maxLines);
|
|
161
|
+
lines[maxLines - 1] = `${lines[maxLines - 1].replace(/[\s.,;:]+$/, '')} …`;
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
height: lines.length * lineHeight,
|
|
165
|
+
gap,
|
|
166
|
+
paint: y => {
|
|
167
|
+
ctx.font = look.font(size, weight);
|
|
168
|
+
ctx.fillStyle = color;
|
|
169
|
+
ctx.textBaseline = 'top';
|
|
170
|
+
lines.forEach((line, i) => {
|
|
171
|
+
ctx.fillText(line, MARGIN + PADDING, y + i * lineHeight);
|
|
172
|
+
});
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
export const iconRow = (ctx, look, image, text, { size, weight, color, gap, }) => {
|
|
177
|
+
const height = Math.max(ICON, size * 1.2);
|
|
178
|
+
return {
|
|
179
|
+
height,
|
|
180
|
+
gap,
|
|
181
|
+
paint: y => {
|
|
182
|
+
const middle = y + height / 2;
|
|
183
|
+
ctx.drawImage(image, MARGIN + PADDING, middle - ICON / 2, ICON, ICON);
|
|
184
|
+
ctx.font = look.font(size, weight);
|
|
185
|
+
ctx.fillStyle = color;
|
|
186
|
+
ctx.textBaseline = 'middle';
|
|
187
|
+
ctx.fillText(text, MARGIN + PADDING + ICON + 22, middle);
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
// The stops of mw-card-title-divider, which stands under the same title on the
|
|
192
|
+
// website. There an opacity of 75% dims it - not here, a story is read out of
|
|
193
|
+
// the corner of the eye.
|
|
194
|
+
export const divider = (ctx, look, gap) => {
|
|
195
|
+
const x = MARGIN + PADDING;
|
|
196
|
+
const width = CONTENT_WIDTH * 0.7;
|
|
197
|
+
const height = mw(4);
|
|
198
|
+
return {
|
|
199
|
+
height,
|
|
200
|
+
gap,
|
|
201
|
+
paint: y => {
|
|
202
|
+
const gradient = ctx.createLinearGradient(x, 0, x + width, 0);
|
|
203
|
+
gradient.addColorStop(0, look.colors.secondary);
|
|
204
|
+
gradient.addColorStop(1 / 3, look.colors.secondary);
|
|
205
|
+
gradient.addColorStop(2 / 3, look.colors.graySurface);
|
|
206
|
+
gradient.addColorStop(1, look.colors.grayClear);
|
|
207
|
+
ctx.fillStyle = gradient;
|
|
208
|
+
ctx.beginPath();
|
|
209
|
+
ctx.roundRect(x, y, width, height, height / 2);
|
|
210
|
+
ctx.fill();
|
|
211
|
+
},
|
|
212
|
+
};
|
|
213
|
+
};
|
|
214
|
+
export const totalHeight = (blocks) => blocks.reduce((sum, b) => sum + b.height + b.gap, 0) -
|
|
215
|
+
(blocks.at(-1)?.gap ?? 0);
|
|
216
|
+
// The card always fills the space between logo and footer: several stories
|
|
217
|
+
// posted one after another look the same that way, instead of jumping
|
|
218
|
+
// depending on the text length.
|
|
219
|
+
export const stage = (look) => {
|
|
220
|
+
const top = SAFE_TOP + look.logo.height + 66;
|
|
221
|
+
// Two lines stand below the card, they need more room than one.
|
|
222
|
+
const bottom = HEIGHT - SAFE_BOTTOM - 196;
|
|
223
|
+
return { top, height: bottom - top };
|
|
224
|
+
};
|
|
225
|
+
// Vertical and not diagonal: that way every horizontal line is a single colour
|
|
226
|
+
// and the strip the page shows above and below the image can hit the same
|
|
227
|
+
// colour - on the phone the edge does not stand out.
|
|
228
|
+
const drawBackground = (ctx, look) => {
|
|
229
|
+
ctx.clearRect(0, 0, WIDTH, HEIGHT);
|
|
230
|
+
const gradient = ctx.createLinearGradient(0, 0, 0, HEIGHT);
|
|
231
|
+
gradient.addColorStop(0, look.background[0]);
|
|
232
|
+
gradient.addColorStop(1, look.background[1]);
|
|
233
|
+
ctx.fillStyle = gradient;
|
|
234
|
+
ctx.fillRect(0, 0, WIDTH, HEIGHT);
|
|
235
|
+
};
|
|
236
|
+
const drawLogo = (ctx, look) => {
|
|
237
|
+
const { image, width, height } = look.logo;
|
|
238
|
+
ctx.drawImage(image, WIDTH - MARGIN - width, SAFE_TOP, width, height);
|
|
239
|
+
};
|
|
240
|
+
// Two shadow layers like --mw-elevation-3: a tight one that sets the surface
|
|
241
|
+
// down, and a wide one that tells how high it floats. The canvas only knows
|
|
242
|
+
// one shadow per fill, so it fills twice.
|
|
243
|
+
const drawSurface = (ctx, look, x, y, width, height) => {
|
|
244
|
+
ctx.save();
|
|
245
|
+
ctx.fillStyle = WHITE;
|
|
246
|
+
for (const [offset, blur, color] of [
|
|
247
|
+
[mw(10), mw(24), look.colors.shadowFar],
|
|
248
|
+
[mw(3), mw(6), look.colors.shadowNear],
|
|
249
|
+
]) {
|
|
250
|
+
ctx.shadowOffsetY = offset;
|
|
251
|
+
ctx.shadowBlur = blur;
|
|
252
|
+
ctx.shadowColor = color;
|
|
253
|
+
ctx.beginPath();
|
|
254
|
+
ctx.roundRect(x, y, width, height, look.radii);
|
|
255
|
+
ctx.fill();
|
|
256
|
+
}
|
|
257
|
+
ctx.restore();
|
|
258
|
+
};
|
|
259
|
+
// The accent arc of the surface mixin: a frame around the surface that two
|
|
260
|
+
// elliptical gradients limit to the two round corners. Through a second
|
|
261
|
+
// canvas, because a mask with a soft edge cannot be had any other way.
|
|
262
|
+
const drawAccent = (ctx, look, x, y, width, height) => {
|
|
263
|
+
const helper = document.createElement('canvas');
|
|
264
|
+
helper.width = WIDTH;
|
|
265
|
+
helper.height = HEIGHT;
|
|
266
|
+
const h = helper.getContext('2d');
|
|
267
|
+
if (!h)
|
|
268
|
+
return;
|
|
269
|
+
// The arc runs up to where the curve ends and fades from there - so it meets
|
|
270
|
+
// the straight edge instead of breaking off at the tangent.
|
|
271
|
+
const reach = (look.radii[1] - ACCENT_STROKE) * 1.8;
|
|
272
|
+
for (const [cornerX, cornerY] of [
|
|
273
|
+
[x + width, y],
|
|
274
|
+
[x, y + height],
|
|
275
|
+
]) {
|
|
276
|
+
h.clearRect(0, 0, WIDTH, HEIGHT);
|
|
277
|
+
h.globalCompositeOperation = 'source-over';
|
|
278
|
+
h.strokeStyle = look.colors.accent;
|
|
279
|
+
h.lineWidth = ACCENT_STROKE;
|
|
280
|
+
h.beginPath();
|
|
281
|
+
// The frame sits inside on the edge, like a border in CSS - hence half the
|
|
282
|
+
// stroke inwards and the radius smaller by the whole one.
|
|
283
|
+
h.roundRect(x + ACCENT_STROKE / 2, y + ACCENT_STROKE / 2, width - ACCENT_STROKE, height - ACCENT_STROKE, look.radii.map(radius => Math.max(0, radius - ACCENT_STROKE)));
|
|
284
|
+
h.stroke();
|
|
285
|
+
h.globalCompositeOperation = 'destination-in';
|
|
286
|
+
h.save();
|
|
287
|
+
h.translate(cornerX, cornerY);
|
|
288
|
+
// An ellipse and not a circle: the arc should lie along the edge and have
|
|
289
|
+
// a direction instead of rounding off the corner.
|
|
290
|
+
h.scale(ACCENT_STRETCH, 1);
|
|
291
|
+
const mask = h.createRadialGradient(0, 0, 0, 0, 0, reach);
|
|
292
|
+
mask.addColorStop(ACCENT_OPAQUE, 'rgba(0, 0, 0, 1)');
|
|
293
|
+
mask.addColorStop(1, 'rgba(0, 0, 0, 0)');
|
|
294
|
+
h.fillStyle = mask;
|
|
295
|
+
h.fillRect(-WIDTH, -HEIGHT, WIDTH * 2, HEIGHT * 2);
|
|
296
|
+
h.restore();
|
|
297
|
+
ctx.drawImage(helper, 0, 0);
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
const drawFooter = (ctx, look, firstLine) => {
|
|
301
|
+
ctx.textAlign = 'center';
|
|
302
|
+
ctx.textBaseline = 'middle';
|
|
303
|
+
const footerY = HEIGHT - SAFE_BOTTOM - 88;
|
|
304
|
+
if (firstLine) {
|
|
305
|
+
ctx.font = look.font(36, 500);
|
|
306
|
+
ctx.fillStyle = 'rgba(255, 255, 255, 0.92)';
|
|
307
|
+
ctx.fillText(firstLine, WIDTH / 2, footerY);
|
|
308
|
+
}
|
|
309
|
+
if (look.texts.reply) {
|
|
310
|
+
ctx.font = look.font(32, 400);
|
|
311
|
+
ctx.fillStyle = 'rgba(255, 255, 255, 0.78)';
|
|
312
|
+
ctx.fillText(look.texts.reply, WIDTH / 2, footerY + 50);
|
|
313
|
+
}
|
|
314
|
+
ctx.textAlign = 'left';
|
|
315
|
+
};
|
|
316
|
+
// Measured blocks in, finished image out. The content sits centred in the
|
|
317
|
+
// card.
|
|
318
|
+
export const drawStory = (ctx, look, blocks, footer) => {
|
|
319
|
+
const { top, height } = stage(look);
|
|
320
|
+
drawBackground(ctx, look);
|
|
321
|
+
drawLogo(ctx, look);
|
|
322
|
+
drawSurface(ctx, look, MARGIN, top, CARD_WIDTH, height);
|
|
323
|
+
drawAccent(ctx, look, MARGIN, top, CARD_WIDTH, height);
|
|
324
|
+
let y = top + Math.max(PADDING, (height - totalHeight(blocks)) / 2);
|
|
325
|
+
for (const block of blocks) {
|
|
326
|
+
block.paint(y);
|
|
327
|
+
y += block.height + block.gap;
|
|
328
|
+
}
|
|
329
|
+
drawFooter(ctx, look, footer);
|
|
330
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type Promo, type ScheduledEvent } from '../schedule.ts';
|
|
2
|
+
export interface StoryEvent extends ScheduledEvent {
|
|
3
|
+
title: string;
|
|
4
|
+
location?: string;
|
|
5
|
+
/** As in Price: only the number, 0 reads as free, other text stays a word. */
|
|
6
|
+
price?: string | number;
|
|
7
|
+
text?: string;
|
|
8
|
+
soldOut?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface StoryOffer {
|
|
11
|
+
name: string;
|
|
12
|
+
price: string | number;
|
|
13
|
+
features?: readonly string[];
|
|
14
|
+
}
|
|
15
|
+
export interface PromoOffer {
|
|
16
|
+
name: string;
|
|
17
|
+
features: string;
|
|
18
|
+
regular: number;
|
|
19
|
+
discounted: number;
|
|
20
|
+
}
|
|
21
|
+
export interface EventCard {
|
|
22
|
+
kind: 'event';
|
|
23
|
+
title: string;
|
|
24
|
+
/** Already formatted for display. */
|
|
25
|
+
date: string;
|
|
26
|
+
time?: string;
|
|
27
|
+
location?: string;
|
|
28
|
+
price?: string;
|
|
29
|
+
text?: string;
|
|
30
|
+
soldOut?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface PromoCard {
|
|
33
|
+
kind: 'promo';
|
|
34
|
+
percent: string;
|
|
35
|
+
title: string;
|
|
36
|
+
/** Last day, already formatted for display. Empty means open-ended. */
|
|
37
|
+
until?: string;
|
|
38
|
+
offers: PromoOffer[];
|
|
39
|
+
}
|
|
40
|
+
export type StoryCard = EventCard | PromoCard;
|
|
41
|
+
export declare const promoOffers: (promo: Promo, offers: readonly StoryOffer[]) => PromoOffer[];
|
|
42
|
+
export declare const storyFileName: (...parts: string[]) => string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// The build side of StoryCards: what the page hands the browser to draw. The
|
|
2
|
+
// cards come from the entries the owner keeps anyway - an event or a running
|
|
3
|
+
// promotion turns into a story without a field of its own.
|
|
4
|
+
import { discountedPrice, } from "../schedule.js";
|
|
5
|
+
// As in Price: only where there is an amount does the discount apply - "Auf
|
|
6
|
+
// Anfrage" has no old price that could be struck through.
|
|
7
|
+
export const promoOffers = (promo, offers) => offers
|
|
8
|
+
.map(offer => ({
|
|
9
|
+
name: offer.name,
|
|
10
|
+
features: (offer.features ?? []).slice(0, 2).join(' · '),
|
|
11
|
+
regular: Number(offer.price),
|
|
12
|
+
}))
|
|
13
|
+
.filter(offer => Number.isFinite(offer.regular) && offer.regular > 0)
|
|
14
|
+
.map(offer => ({
|
|
15
|
+
...offer,
|
|
16
|
+
discounted: discountedPrice(promo, offer.regular),
|
|
17
|
+
}));
|
|
18
|
+
// The name the image gets on the phone - it ends up in the gallery or in a
|
|
19
|
+
// chat, so it says whose it is and what it shows.
|
|
20
|
+
export const storyFileName = (...parts) => parts
|
|
21
|
+
.join('-')
|
|
22
|
+
.toLowerCase()
|
|
23
|
+
.replace(/ä/g, 'ae')
|
|
24
|
+
.replace(/ö/g, 'oe')
|
|
25
|
+
.replace(/ü/g, 'ue')
|
|
26
|
+
.replace(/ß/g, 'ss')
|
|
27
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
28
|
+
.replace(/^-|-$/g, '');
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// Story image for an event: a card like on the start page, only in portrait
|
|
2
|
+
// format and as a finished file.
|
|
3
|
+
import { divider, drawStory, iconRow, MARGIN, PADDING, stage, textBlock, totalHeight, } from "./base.js";
|
|
4
|
+
// Like Price: only the number is in the file, the 0 becomes "free".
|
|
5
|
+
const priceRow = (ctx, look, card) => {
|
|
6
|
+
const { colors, font, texts } = look;
|
|
7
|
+
if (card.soldOut) {
|
|
8
|
+
return {
|
|
9
|
+
height: 74,
|
|
10
|
+
gap: 0,
|
|
11
|
+
paint: y => {
|
|
12
|
+
ctx.font = font(38, 500);
|
|
13
|
+
const width = ctx.measureText(texts.soldOut).width + 64;
|
|
14
|
+
ctx.fillStyle = colors.graySurface;
|
|
15
|
+
ctx.beginPath();
|
|
16
|
+
ctx.roundRect(MARGIN + PADDING, y, width, 74, 37);
|
|
17
|
+
ctx.fill();
|
|
18
|
+
ctx.fillStyle = colors.muted;
|
|
19
|
+
ctx.textBaseline = 'middle';
|
|
20
|
+
ctx.fillText(texts.soldOut, MARGIN + PADDING + 32, y + 37);
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const raw = String(card.price ?? '').trim();
|
|
25
|
+
if (raw === '')
|
|
26
|
+
return null;
|
|
27
|
+
const value = Number(raw);
|
|
28
|
+
const isNumber = Number.isFinite(value);
|
|
29
|
+
return {
|
|
30
|
+
height: 76,
|
|
31
|
+
gap: 0,
|
|
32
|
+
paint: y => {
|
|
33
|
+
ctx.textBaseline = 'middle';
|
|
34
|
+
const middle = y + 38;
|
|
35
|
+
if (isNumber && value === 0) {
|
|
36
|
+
ctx.font = font(62, 700);
|
|
37
|
+
ctx.fillStyle = colors.primary;
|
|
38
|
+
ctx.fillText(texts.free, MARGIN + PADDING, middle);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const amount = isNumber ? String(value) : raw;
|
|
42
|
+
ctx.font = font(74, 700);
|
|
43
|
+
ctx.fillStyle = colors.primary;
|
|
44
|
+
ctx.fillText(amount, MARGIN + PADDING, middle);
|
|
45
|
+
const width = ctx.measureText(amount).width;
|
|
46
|
+
ctx.font = font(44, 400);
|
|
47
|
+
ctx.fillStyle = colors.muted;
|
|
48
|
+
ctx.fillText(texts.currency, MARGIN + PADDING + width + 16, middle + 4);
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
const TEXT_LINE = 64;
|
|
53
|
+
const TEXT_GAP = 44;
|
|
54
|
+
export const drawEvent = (ctx, card, look) => {
|
|
55
|
+
const { colors, icons } = look;
|
|
56
|
+
const lead = [
|
|
57
|
+
iconRow(ctx, look, icons.calendar, card.date.toUpperCase(), {
|
|
58
|
+
size: 38,
|
|
59
|
+
weight: 700,
|
|
60
|
+
color: colors.primary,
|
|
61
|
+
gap: 34,
|
|
62
|
+
}),
|
|
63
|
+
textBlock(ctx, look, card.title, {
|
|
64
|
+
size: 74,
|
|
65
|
+
weight: 700,
|
|
66
|
+
color: colors.text,
|
|
67
|
+
lineHeight: 92,
|
|
68
|
+
// None: the line height already carries a good 40px below the last title
|
|
69
|
+
// line, and the stroke should hang on the title like its margin-top of
|
|
70
|
+
// .2rem on mw-card-title-divider.
|
|
71
|
+
gap: 0,
|
|
72
|
+
}),
|
|
73
|
+
divider(ctx, look, 76),
|
|
74
|
+
];
|
|
75
|
+
if (card.time) {
|
|
76
|
+
lead.push(iconRow(ctx, look, icons.clock, card.time, {
|
|
77
|
+
size: 42,
|
|
78
|
+
weight: 400,
|
|
79
|
+
color: colors.muted,
|
|
80
|
+
gap: 18,
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
if (card.location) {
|
|
84
|
+
lead.push(iconRow(ctx, look, icons.location, card.location, {
|
|
85
|
+
size: 42,
|
|
86
|
+
weight: 400,
|
|
87
|
+
color: colors.muted,
|
|
88
|
+
gap: 18,
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
lead[lead.length - 1].gap = 48;
|
|
92
|
+
const price = priceRow(ctx, look, card);
|
|
93
|
+
// The description gets whatever is left after everything else - it is the
|
|
94
|
+
// only thing whose length varies a lot from event to event.
|
|
95
|
+
const blocks = [...lead];
|
|
96
|
+
if (card.text) {
|
|
97
|
+
const used = totalHeight(lead) +
|
|
98
|
+
TEXT_GAP +
|
|
99
|
+
(price ? price.height + TEXT_GAP : 0) +
|
|
100
|
+
PADDING * 2;
|
|
101
|
+
const maxLines = Math.max(1, Math.floor((stage(look).height - used) / TEXT_LINE));
|
|
102
|
+
blocks.push(textBlock(ctx, look, card.text, {
|
|
103
|
+
size: 42,
|
|
104
|
+
weight: 400,
|
|
105
|
+
color: colors.text,
|
|
106
|
+
lineHeight: TEXT_LINE,
|
|
107
|
+
gap: TEXT_GAP,
|
|
108
|
+
maxLines,
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
if (price)
|
|
112
|
+
blocks.push(price);
|
|
113
|
+
drawStory(ctx, look, blocks, look.texts.eventFooter);
|
|
114
|
+
};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// Story image for the running promotion: the same layout as the event story,
|
|
2
|
+
// the prices take the place of an event - each one struck through once and
|
|
3
|
+
// once with the discount.
|
|
4
|
+
import { CONTENT_WIDTH, divider, drawStory, iconRow, MARGIN, mw, PADDING, stage, textBlock, totalHeight, } from "./base.js";
|
|
5
|
+
// mw-tag mw-tag-secondary, resolved from the tokens: the surface is the
|
|
6
|
+
// secondary colour at 30%, plus a stroke in the full colour and dark text.
|
|
7
|
+
// Only on a light surface - on the gradient the tag drowns, which is why it
|
|
8
|
+
// stands in the card and not next to it.
|
|
9
|
+
const TAG_FONT_SIZE = 54;
|
|
10
|
+
// The proportions of the tag on the website: 22px high and 3.2/8px padding at
|
|
11
|
+
// 12.8px font size.
|
|
12
|
+
const TAG_HEIGHT = Math.round(TAG_FONT_SIZE * 1.72);
|
|
13
|
+
const TAG_PADDING = Math.round(TAG_FONT_SIZE * 0.625);
|
|
14
|
+
const TAG_STROKE = mw(1);
|
|
15
|
+
const MINI_GAP = 26;
|
|
16
|
+
const MINI_PADDING = 40;
|
|
17
|
+
const MINI_MIN = 118;
|
|
18
|
+
const MINI_MAX = 172;
|
|
19
|
+
const GAP_AFTER_HEAD = 70;
|
|
20
|
+
const truncate = (ctx, text, maxWidth) => {
|
|
21
|
+
if (ctx.measureText(text).width <= maxWidth)
|
|
22
|
+
return text;
|
|
23
|
+
let short = text;
|
|
24
|
+
while (short && ctx.measureText(`${short} …`).width > maxWidth) {
|
|
25
|
+
short = short.slice(0, -1);
|
|
26
|
+
}
|
|
27
|
+
return `${short.trimEnd()} …`;
|
|
28
|
+
};
|
|
29
|
+
const tagRow = (ctx, look, text, gap) => {
|
|
30
|
+
ctx.font = look.font(TAG_FONT_SIZE, 500);
|
|
31
|
+
const width = ctx.measureText(text).width + TAG_PADDING * 2;
|
|
32
|
+
return {
|
|
33
|
+
height: TAG_HEIGHT,
|
|
34
|
+
gap,
|
|
35
|
+
paint: y => {
|
|
36
|
+
const x = MARGIN + PADDING;
|
|
37
|
+
// radius('xl') is larger than the tag is high - in CSS that makes the
|
|
38
|
+
// pill, here the radius has to be limited by hand.
|
|
39
|
+
ctx.beginPath();
|
|
40
|
+
ctx.roundRect(x + TAG_STROKE / 2, y + TAG_STROKE / 2, width - TAG_STROKE, TAG_HEIGHT - TAG_STROKE, TAG_HEIGHT / 2);
|
|
41
|
+
ctx.fillStyle = look.colors.secondarySurface;
|
|
42
|
+
ctx.fill();
|
|
43
|
+
ctx.lineWidth = TAG_STROKE;
|
|
44
|
+
ctx.strokeStyle = look.colors.secondary;
|
|
45
|
+
ctx.stroke();
|
|
46
|
+
ctx.font = look.font(TAG_FONT_SIZE, 500);
|
|
47
|
+
ctx.fillStyle = look.colors.text;
|
|
48
|
+
ctx.textBaseline = 'middle';
|
|
49
|
+
ctx.fillText(text, x + TAG_PADDING, y + TAG_HEIGHT / 2);
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
// A price row in small: the offer on the left, the old price above the new
|
|
54
|
+
// one on the right. The silhouette is that of the large card, only rounded
|
|
55
|
+
// half as much.
|
|
56
|
+
const miniCard = (ctx, look, offer, height) => ({
|
|
57
|
+
height,
|
|
58
|
+
gap: MINI_GAP,
|
|
59
|
+
paint: y => {
|
|
60
|
+
const { colors, font, texts } = look;
|
|
61
|
+
const x = MARGIN + PADDING;
|
|
62
|
+
ctx.fillStyle = colors.graySurface;
|
|
63
|
+
ctx.beginPath();
|
|
64
|
+
ctx.roundRect(x, y, CONTENT_WIDTH, height, look.radii.map(radius => radius / 2));
|
|
65
|
+
ctx.fill();
|
|
66
|
+
const right = x + CONTENT_WIDTH - MINI_PADDING;
|
|
67
|
+
const regular = `${offer.regular} ${texts.currency}`;
|
|
68
|
+
const discounted = String(offer.discounted);
|
|
69
|
+
ctx.font = font(34, 400);
|
|
70
|
+
const regularWidth = ctx.measureText(regular).width;
|
|
71
|
+
ctx.font = font(58, 700);
|
|
72
|
+
const discountedWidth = ctx.measureText(discounted).width;
|
|
73
|
+
ctx.font = font(32, 400);
|
|
74
|
+
const currencyWidth = ctx.measureText(texts.currency).width;
|
|
75
|
+
ctx.textBaseline = 'middle';
|
|
76
|
+
const regularY = Math.round(y + height * 0.32);
|
|
77
|
+
ctx.font = font(34, 400);
|
|
78
|
+
ctx.fillStyle = colors.muted;
|
|
79
|
+
ctx.fillText(regular, right - regularWidth, regularY);
|
|
80
|
+
// The stroke lies on the middle of the line, exactly where the middle
|
|
81
|
+
// baseline is.
|
|
82
|
+
ctx.fillRect(right - regularWidth, regularY - 1, regularWidth, 3);
|
|
83
|
+
const discountedBlock = discountedWidth + 14 + currencyWidth;
|
|
84
|
+
const discountedY = y + height * 0.68;
|
|
85
|
+
const discountedX = right - discountedBlock;
|
|
86
|
+
ctx.font = font(58, 700);
|
|
87
|
+
ctx.fillStyle = colors.primary;
|
|
88
|
+
ctx.fillText(discounted, discountedX, discountedY);
|
|
89
|
+
ctx.font = font(32, 400);
|
|
90
|
+
ctx.fillStyle = colors.muted;
|
|
91
|
+
ctx.fillText(texts.currency, discountedX + discountedWidth + 14, discountedY + 4);
|
|
92
|
+
// Whatever is left to the left of the price block is shared by name and
|
|
93
|
+
// features.
|
|
94
|
+
const space = right - x - MINI_PADDING - Math.max(regularWidth, discountedBlock) - 36;
|
|
95
|
+
ctx.font = font(40, 700);
|
|
96
|
+
ctx.fillStyle = colors.text;
|
|
97
|
+
ctx.fillText(truncate(ctx, offer.name, space), x + MINI_PADDING, y + height * 0.34);
|
|
98
|
+
ctx.font = font(30, 400);
|
|
99
|
+
ctx.fillStyle = colors.muted;
|
|
100
|
+
ctx.fillText(truncate(ctx, offer.features, space), x + MINI_PADDING, y + height * 0.7);
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
export const drawPromo = (ctx, card, look) => {
|
|
104
|
+
const head = [tagRow(ctx, look, card.percent, 30)];
|
|
105
|
+
if (card.until) {
|
|
106
|
+
head.push(iconRow(ctx, look, look.icons.sparkle, `${look.texts.until} ${card.until}`.toUpperCase(), { size: 38, weight: 700, color: look.colors.primary, gap: 34 }));
|
|
107
|
+
}
|
|
108
|
+
head.push(textBlock(ctx, look, card.title, {
|
|
109
|
+
size: 74,
|
|
110
|
+
weight: 700,
|
|
111
|
+
color: look.colors.text,
|
|
112
|
+
lineHeight: 92,
|
|
113
|
+
gap: 0,
|
|
114
|
+
// More title would mean fewer prices - and they are the reason for the
|
|
115
|
+
// image.
|
|
116
|
+
maxLines: 2,
|
|
117
|
+
}), divider(ctx, look, GAP_AFTER_HEAD));
|
|
118
|
+
// Whatever is left after the head is shared by the offers. If they no longer
|
|
119
|
+
// all fit even at the smallest height, one drops off at the end. The gap
|
|
120
|
+
// after the divider counts extra, because totalHeight leaves out that of the
|
|
121
|
+
// last block - here something still follows, though.
|
|
122
|
+
const remaining = stage(look).height - PADDING * 2 - totalHeight(head) - GAP_AFTER_HEAD;
|
|
123
|
+
const fitting = Math.max(1, Math.floor((remaining + MINI_GAP) / (MINI_MIN + MINI_GAP)));
|
|
124
|
+
const offers = card.offers.slice(0, fitting);
|
|
125
|
+
const miniHeight = Math.min(MINI_MAX, Math.max(MINI_MIN, (remaining - MINI_GAP * (offers.length - 1)) / offers.length));
|
|
126
|
+
const blocks = [
|
|
127
|
+
...head,
|
|
128
|
+
...offers.map(offer => miniCard(ctx, look, offer, miniHeight)),
|
|
129
|
+
];
|
|
130
|
+
drawStory(ctx, look, blocks, look.texts.promoFooter);
|
|
131
|
+
};
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "maverick-wave-astro",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.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",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"astro": "^7.2.0",
|
|
55
|
-
"maverick-wave": "^6.
|
|
55
|
+
"maverick-wave": "^6.6.0"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"@astrojs/sitemap": "^3.7.3",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"eslint-plugin-astro": "^1.5.0",
|
|
68
68
|
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
69
69
|
"globals": "^16.5.0",
|
|
70
|
-
"maverick-wave": "^6.
|
|
70
|
+
"maverick-wave": "^6.6.0",
|
|
71
71
|
"prettier": "^3.6.2",
|
|
72
72
|
"prettier-plugin-astro": "^0.14.1",
|
|
73
73
|
"typescript": "^6.0.3",
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/* The document itself snaps - a scroll container of its own takes away the
|
|
2
|
+
phone's showing and hiding of the browser bar. */
|
|
3
|
+
html:has(.mwa-story-cards) {
|
|
4
|
+
scroll-snap-type: y mandatory;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/* A block of its own keeps the stories out of the flex layout of .mw-main -
|
|
8
|
+
there they would squeeze each other. */
|
|
9
|
+
.mwa-story-cards {
|
|
10
|
+
background: var(--mw-page-background);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.mwa-story-card {
|
|
14
|
+
display: grid;
|
|
15
|
+
/* Without the 0 as lower bound the canvas stretches the column with its
|
|
16
|
+
1080px and the page overflows sideways on the phone. */
|
|
17
|
+
grid-template-columns: minmax(0, 1fr);
|
|
18
|
+
place-items: center;
|
|
19
|
+
min-height: 100svh;
|
|
20
|
+
padding: 0.75rem;
|
|
21
|
+
scroll-snap-align: center;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/* Width instead of max-height, otherwise the canvas would have to compute its
|
|
25
|
+
height against a parent that only gets its size from the canvas. */
|
|
26
|
+
.mwa-story-card-stage {
|
|
27
|
+
--mwa-story-height: calc(100svh - 1.5rem);
|
|
28
|
+
|
|
29
|
+
position: relative;
|
|
30
|
+
width: min(100%, calc(var(--mwa-story-height) * 9 / 16));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.mwa-story-card-image {
|
|
34
|
+
display: block;
|
|
35
|
+
width: 100%;
|
|
36
|
+
height: auto;
|
|
37
|
+
border-radius: 0.75rem;
|
|
38
|
+
box-shadow: var(--mw-elevation-3);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@media (min-width: 700px) {
|
|
42
|
+
.mwa-story-card {
|
|
43
|
+
padding: 1.5rem;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.mwa-story-card-stage {
|
|
47
|
+
--mwa-story-height: calc(100svh - 3rem);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/* Sits in the lower area that Instagram and WhatsApp cover with their own
|
|
52
|
+
controls - so the button does not get in the way in a screenshot either. */
|
|
53
|
+
.mwa-story-card-btn {
|
|
54
|
+
position: absolute;
|
|
55
|
+
bottom: 4%;
|
|
56
|
+
left: 50%;
|
|
57
|
+
/* translate instead of transform: mw-btn puts a translateY on transform when
|
|
58
|
+
pressed, and that would drag the centre along here. */
|
|
59
|
+
translate: -50%;
|
|
60
|
+
padding-inline: 1.35rem;
|
|
61
|
+
font-size: 1.3rem;
|
|
62
|
+
white-space: nowrap;
|
|
63
|
+
/* The button sits on the image and not on the page: ring and shadow set it
|
|
64
|
+
apart from a gradient that may come close to the primary colour. */
|
|
65
|
+
border: 2px solid rgb(255 255 255 / 0.85);
|
|
66
|
+
box-shadow: 0 8px 26px rgb(0 0 0 / 0.4);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.mwa-story-cards-empty {
|
|
70
|
+
display: grid;
|
|
71
|
+
place-items: center;
|
|
72
|
+
min-height: 100svh;
|
|
73
|
+
margin: 0;
|
|
74
|
+
text-align: center;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/* Otherwise the display above beats the hidden from the browser stylesheet. */
|
|
78
|
+
.mwa-story-cards-empty[hidden] {
|
|
79
|
+
display: none;
|
|
80
|
+
}
|