maverick-wave-astro 1.28.0 → 1.30.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.
@@ -0,0 +1,42 @@
1
+ ---
2
+ // What the letters at the dishes mean. Given the allergens of every dish, it
3
+ // names only those that occur; without, all fourteen.
4
+ import '../styles/allergens.css';
5
+
6
+ import { allergenName, ALLERGENS, usedAllergens } from '../dist/allergens.js';
7
+ import { siteLocale } from '../dist/config.js';
8
+
9
+ interface Props {
10
+ // One list per dish, as the werkbank stores them.
11
+ used?: readonly (readonly string[] | undefined)[];
12
+ // Above the legend, e.g. "Allergene".
13
+ title?: string;
14
+ locale?: string;
15
+ class?: string;
16
+ }
17
+
18
+ const { used, title, locale = siteLocale, class: className } = Astro.props;
19
+
20
+ const list = used ? usedAllergens(used) : ALLERGENS;
21
+ ---
22
+
23
+ {
24
+ list.length > 0 && (
25
+ <div class={className}>
26
+ {title && <p class="mw-text-sm mw-text-bold mw-mb-2">{title}</p>}
27
+ <dl class="mwa-allergen-legend">
28
+ {list.map(allergen => (
29
+ <div>
30
+ <dt>
31
+ <span class="mwa-allergen" aria-hidden="true">
32
+ {allergen.code}
33
+ </span>
34
+ <span class="mw-sr-only">{allergen.code}</span>
35
+ </dt>
36
+ <dd>{allergenName(allergen, locale)}</dd>
37
+ </div>
38
+ ))}
39
+ </dl>
40
+ </div>
41
+ )
42
+ }
@@ -0,0 +1,47 @@
1
+ ---
2
+ // The allergens of one dish as letters, read out by name for screen readers.
3
+ // Their meaning stands in the AllergenLegend below the menu.
4
+ import '../styles/allergens.css';
5
+
6
+ import { allergenName, allergensOf } from '../dist/allergens.js';
7
+ import { siteLocale } from '../dist/config.js';
8
+
9
+ interface Props {
10
+ // Ids of schemas/allergens.field.json, in any order.
11
+ allergens?: readonly string[];
12
+ // The page's language on a site with several.
13
+ locale?: string;
14
+ // Read before the names: "Allergene: Eier, Milch".
15
+ label?: string;
16
+ class?: string;
17
+ }
18
+
19
+ const {
20
+ allergens,
21
+ locale = siteLocale,
22
+ label = locale.startsWith('de') ? 'Allergene' : 'Allergens',
23
+ class: className,
24
+ } = Astro.props;
25
+
26
+ const list = allergensOf(allergens);
27
+ ---
28
+
29
+ {
30
+ list.length > 0 && (
31
+ <span class:list={['mwa-allergens', className]}>
32
+ <span class="mw-sr-only">
33
+ {label}:{' '}
34
+ {list.map(allergen => allergenName(allergen, locale)).join(', ')}
35
+ </span>
36
+ {list.map(allergen => (
37
+ <abbr
38
+ class="mwa-allergen"
39
+ title={allergenName(allergen, locale)}
40
+ aria-hidden="true"
41
+ >
42
+ {allergen.code}
43
+ </abbr>
44
+ ))}
45
+ </span>
46
+ )
47
+ }
@@ -28,9 +28,11 @@ type Props = {
28
28
  // The page brings its own body: no skip link, no <main>, no header or
29
29
  // footer slot - a presentation is one.
30
30
  bare?: boolean;
31
+ // false keeps the occasion of the day off, e.g. on a TV or a menu sheet.
32
+ occasion?: boolean;
31
33
  };
32
34
 
33
- const { site, ogImage: OG_IMAGE, htmlClasses, designCss, occasion } = config;
35
+ const { site, ogImage: OG_IMAGE, htmlClasses, designCss } = config;
34
36
 
35
37
  const {
36
38
  title,
@@ -48,8 +50,11 @@ const {
48
50
  htmlData = {},
49
51
  bodyClass,
50
52
  bare = false,
53
+ occasion: withOccasion = true,
51
54
  } = Astro.props;
52
55
 
56
+ const occasion = withOccasion ? config.occasion : null;
57
+
53
58
  const canonicalUrl = new URL(
54
59
  withoutTrailingSlash(Astro.url.pathname),
55
60
  Astro.site
@@ -0,0 +1,99 @@
1
+ ---
2
+ // The menu on one page for paper: the browser prints it or saves it as a PDF,
3
+ // no file to keep up to date next to the site. Meant for a page of its own
4
+ // with noIndex, bare in BaseLayout. The button stays off the paper.
5
+ import '../styles/menu-sheet.css';
6
+
7
+ import { config, siteLocale } from '../dist/config.js';
8
+ import AllergenLegend from './AllergenLegend.astro';
9
+ import ValueList from './ValueList.astro';
10
+
11
+ interface Props {
12
+ title: string;
13
+ // Under the title, e.g. the name and address of the place.
14
+ subtitle?: string;
15
+ intro?: string;
16
+ groups: readonly {
17
+ title: string;
18
+ items: readonly {
19
+ name: string;
20
+ description?: string;
21
+ // Already formatted, "12,50 €".
22
+ price?: string;
23
+ allergens?: readonly string[];
24
+ }[];
25
+ }[];
26
+ // Below the dishes, e.g. "Alle Preise inklusive Mehrwertsteuer".
27
+ note?: string;
28
+ legendTitle?: string;
29
+ printLabel?: string;
30
+ locale?: string;
31
+ }
32
+
33
+ const german = config.site.lang.startsWith('de');
34
+
35
+ const {
36
+ title,
37
+ subtitle,
38
+ intro,
39
+ groups,
40
+ note,
41
+ legendTitle = german ? 'Allergene' : 'Allergens',
42
+ printLabel = german
43
+ ? 'Drucken oder als PDF speichern'
44
+ : 'Print or save as PDF',
45
+ locale = siteLocale,
46
+ } = Astro.props;
47
+
48
+ const shown = groups.filter(group => group.items.length > 0);
49
+ const used = shown.flatMap(group => group.items.map(item => item.allergens));
50
+ ---
51
+
52
+ <div class="mwa-menu-sheet">
53
+ <div class="mwa-menu-sheet-toolbar">
54
+ <button type="button" class="mw-btn mw-btn-primary" data-menu-sheet-print>
55
+ {printLabel}
56
+ </button>
57
+ </div>
58
+
59
+ <header class="mwa-menu-sheet-head">
60
+ <h1 class="mwa-menu-sheet-title">{title}</h1>
61
+ {subtitle && <p class="mw-text-muted mw-m-0">{subtitle}</p>}
62
+ {intro && <p class="mwa-menu-sheet-intro">{intro}</p>}
63
+ </header>
64
+
65
+ {
66
+ shown.map(group => (
67
+ <section class="mwa-menu-sheet-group">
68
+ <h2 class="mwa-menu-sheet-group-title">{group.title}</h2>
69
+ <ValueList
70
+ top
71
+ locale={locale}
72
+ items={group.items.map(item => ({
73
+ label: item.name,
74
+ note: item.description,
75
+ allergens: item.allergens,
76
+ value: item.price ?? '',
77
+ }))}
78
+ />
79
+ </section>
80
+ ))
81
+ }
82
+
83
+ {note && <p class="mwa-menu-sheet-note">{note}</p>}
84
+
85
+ <AllergenLegend
86
+ class="mwa-menu-sheet-legend"
87
+ used={used}
88
+ title={legendTitle}
89
+ locale={locale}
90
+ />
91
+ </div>
92
+
93
+ <script>
94
+ for (const button of document.querySelectorAll<HTMLButtonElement>(
95
+ '[data-menu-sheet-print]'
96
+ )) {
97
+ button.addEventListener('click', () => print());
98
+ }
99
+ </script>
@@ -0,0 +1,138 @@
1
+ ---
2
+ // "Do you come to me?" answered on the spot: the visitor types a postcode, the
3
+ // page says yes or no - nothing is sent anywhere. The area comes from the
4
+ // werkbank (schemas/service-area.schema.json) as the owner typed it.
5
+ import '../styles/service-area.css';
6
+
7
+ import { config } from '../dist/config.js';
8
+ import { parsePostcodes, serializeRanges } from '../dist/service-area.js';
9
+
10
+ interface Props {
11
+ postcodes: string;
12
+ inside?: string;
13
+ outside?: string;
14
+ // Below either answer, e.g. "Knapp daneben? Ruf an."
15
+ note?: string;
16
+ label?: string;
17
+ placeholder?: string;
18
+ button?: string;
19
+ invalid?: string;
20
+ // One per page is the usual case - a second one needs its own.
21
+ id?: string;
22
+ class?: string;
23
+ }
24
+
25
+ const german = config.site.lang.startsWith('de');
26
+
27
+ const {
28
+ postcodes,
29
+ inside,
30
+ outside,
31
+ note,
32
+ label = german ? 'Deine Postleitzahl' : 'Your postcode',
33
+ placeholder = german ? 'z. B. 73240' : 'e.g. 73240',
34
+ button = german ? 'Prüfen' : 'Check',
35
+ invalid = german
36
+ ? 'Bitte gib eine Postleitzahl mit fünf Ziffern ein.'
37
+ : 'Please enter a postcode with five digits.',
38
+ id = 'mwa-service-area-postcode',
39
+ class: className,
40
+ } = Astro.props;
41
+
42
+ const { ranges, invalid: unread } = parsePostcodes(postcodes);
43
+ if (unread.length > 0) {
44
+ console.warn(`ServiceArea: not a postcode, left out: ${unread.join(', ')}`);
45
+ }
46
+ ---
47
+
48
+ <form
49
+ class:list={['mwa-service-area', className]}
50
+ data-service-area={serializeRanges(ranges)}
51
+ data-inside={inside?.trim() ||
52
+ (german ? 'Wir kommen zu dir.' : 'We come to you.')}
53
+ data-outside={outside?.trim() ||
54
+ (german
55
+ ? 'Leider außerhalb unseres Gebiets.'
56
+ : 'Sorry, that is outside our area.')}
57
+ data-invalid={invalid}
58
+ novalidate
59
+ >
60
+ <label class="mwa-service-area-label" for={id}>{label}</label>
61
+ <div class="mwa-service-area-row">
62
+ <input
63
+ id={id}
64
+ class="mw-input"
65
+ type="text"
66
+ inputmode="numeric"
67
+ autocomplete="postal-code"
68
+ maxlength="5"
69
+ placeholder={placeholder}
70
+ data-service-area-input
71
+ />
72
+ <button type="submit" class="mw-btn mw-btn-primary">{button}</button>
73
+ </div>
74
+ <div
75
+ class="mwa-service-area-answer"
76
+ aria-live="polite"
77
+ data-service-area-answer
78
+ >
79
+ </div>
80
+ {
81
+ note?.trim() && (
82
+ <p class="mwa-service-area-note" hidden data-service-area-note>
83
+ {note}
84
+ </p>
85
+ )
86
+ }
87
+ </form>
88
+
89
+ <script>
90
+ import { checkPostcode, readRanges } from '../dist/service-area.js';
91
+
92
+ const TONES = {
93
+ inside: 'mw-alert-success',
94
+ outside: 'mw-alert-warning',
95
+ invalid: 'mw-alert-danger',
96
+ } as const;
97
+
98
+ for (const form of document.querySelectorAll<HTMLFormElement>(
99
+ '[data-service-area]'
100
+ )) {
101
+ const ranges = readRanges(form.dataset.serviceArea ?? '');
102
+ const input = form.querySelector<HTMLInputElement>(
103
+ '[data-service-area-input]'
104
+ );
105
+ const answer = form.querySelector<HTMLElement>(
106
+ '[data-service-area-answer]'
107
+ );
108
+ const note = form.querySelector<HTMLElement>('[data-service-area-note]');
109
+ if (!input || !answer) continue;
110
+
111
+ const show = (complete: boolean) => {
112
+ const value = input.value.trim();
113
+ const result = checkPostcode(ranges, value);
114
+ // While typing, only a full postcode gets an answer - "7" is no mistake yet.
115
+ if (!complete && result === 'invalid') {
116
+ answer.replaceChildren();
117
+ if (note) note.hidden = true;
118
+ return;
119
+ }
120
+ const box = document.createElement('div');
121
+ box.className = `mw-alert ${TONES[result]}`;
122
+ const content = document.createElement('div');
123
+ content.className = 'mw-alert-content';
124
+ const text = document.createElement('p');
125
+ text.textContent = form.dataset[result] ?? '';
126
+ content.append(text);
127
+ box.append(content);
128
+ answer.replaceChildren(box);
129
+ if (note) note.hidden = result === 'invalid';
130
+ };
131
+
132
+ input.addEventListener('input', () => show(false));
133
+ form.addEventListener('submit', event => {
134
+ event.preventDefault();
135
+ show(true);
136
+ });
137
+ }
138
+ </script>
@@ -0,0 +1,215 @@
1
+ ---
2
+ // The screen in a shop or waiting room: one slide after the other, big enough
3
+ // to read across the room, on any TV with a browser. Meant for the page /tv
4
+ // with noIndex, bare in BaseLayout. The slides come from signageSlides() -
5
+ // what they show is decided by the build, so the screen asks for the page
6
+ // every few minutes and reloads once a newer build is out.
7
+ import '../styles/signage.css';
8
+
9
+ import { isUpload } from '../dist/bio.js';
10
+ import { config, siteLocale } from '../dist/config.js';
11
+ import { withBase } from '../dist/path.js';
12
+ import type { SignageSlide } from '../dist/signage.js';
13
+ import Picture from './Picture.astro';
14
+
15
+ interface Props {
16
+ slides: readonly SignageSlide[];
17
+ seconds: number;
18
+ theme?: 'dark' | 'light';
19
+ clock?: boolean;
20
+ // From public/, the light variant on the dark theme.
21
+ logo?: string;
22
+ name?: string;
23
+ // Shows when no slide has anything today.
24
+ empty?: string;
25
+ hint?: string;
26
+ locale?: string;
27
+ }
28
+
29
+ const german = config.site.lang.startsWith('de');
30
+
31
+ const {
32
+ slides,
33
+ seconds,
34
+ theme = 'dark',
35
+ clock = true,
36
+ logo,
37
+ name = config.site.name,
38
+ empty = german ? 'Schön, dass du da bist.' : 'Good to see you.',
39
+ hint = german
40
+ ? 'Einmal tippen oder F11 drücken für Vollbild'
41
+ : 'Tap once or press F11 for full screen',
42
+ locale = siteLocale,
43
+ } = Astro.props;
44
+
45
+ const shown: readonly SignageSlide[] =
46
+ slides.length > 0 ? slides : [{ kind: 'custom', title: empty }];
47
+ ---
48
+
49
+ <div
50
+ class:list={['mwa-signage', `mwa-signage-${theme}`]}
51
+ data-signage
52
+ data-seconds={seconds}
53
+ data-build={new Date().toISOString()}
54
+ data-locale={locale}
55
+ >
56
+ <header class="mwa-signage-bar">
57
+ {
58
+ logo ? (
59
+ <img class="mwa-signage-logo" src={withBase(logo)} alt={name} />
60
+ ) : (
61
+ <span class="mwa-signage-name">{name}</span>
62
+ )
63
+ }
64
+ {clock && <time class="mwa-signage-clock" data-signage-clock />}
65
+ </header>
66
+
67
+ <div class="mwa-signage-stage">
68
+ {
69
+ shown.map((slide, index) => (
70
+ <section
71
+ class:list={[
72
+ 'mwa-signage-slide',
73
+ `mwa-signage-slide-${slide.kind}`,
74
+ index === 0 && 'mwa-signage-slide-active',
75
+ slide.image && 'mwa-signage-slide-media',
76
+ ]}
77
+ aria-hidden={index === 0 ? undefined : 'true'}
78
+ data-signage-slide
79
+ >
80
+ <div class="mwa-signage-content">
81
+ {slide.kicker && <p class="mwa-signage-kicker">{slide.kicker}</p>}
82
+ {slide.big && <p class="mwa-signage-big">{slide.big}</p>}
83
+ {slide.title && <h2 class="mwa-signage-title">{slide.title}</h2>}
84
+ {slide.text && <p class="mwa-signage-text">{slide.text}</p>}
85
+ {slide.items && slide.items.length > 0 && (
86
+ <dl class="mwa-signage-items">
87
+ {slide.items.map(item => (
88
+ <div class="mwa-signage-item">
89
+ <dt>{item.label}</dt>
90
+ <dd>{item.text}</dd>
91
+ {item.value && (
92
+ <dd class="mwa-signage-value">{item.value}</dd>
93
+ )}
94
+ </div>
95
+ ))}
96
+ </dl>
97
+ )}
98
+ </div>
99
+ {slide.image && (
100
+ <div class="mwa-signage-picture">
101
+ {isUpload(slide.image) ? (
102
+ <Picture
103
+ src={slide.image}
104
+ alt={slide.imageAlt ?? ''}
105
+ sizes="50vw"
106
+ widths={[1000, 1600]}
107
+ eager={index === 0}
108
+ />
109
+ ) : (
110
+ <img src={withBase(slide.image)} alt={slide.imageAlt ?? ''} />
111
+ )}
112
+ </div>
113
+ )}
114
+ </section>
115
+ ))
116
+ }
117
+ </div>
118
+
119
+ {
120
+ shown.length > 1 && (
121
+ <ol class="mwa-signage-dots" aria-hidden="true">
122
+ {shown.map((_, index) => (
123
+ <li
124
+ class:list={[index === 0 && 'mwa-signage-dot-active']}
125
+ data-signage-dot
126
+ />
127
+ ))}
128
+ </ol>
129
+ )
130
+ }
131
+
132
+ <p class="mwa-signage-hint" data-signage-hint>{hint}</p>
133
+ </div>
134
+
135
+ <script>
136
+ const root = document.querySelector<HTMLElement>('[data-signage]');
137
+
138
+ if (root) {
139
+ const slides = [
140
+ ...root.querySelectorAll<HTMLElement>('[data-signage-slide]'),
141
+ ];
142
+ const dots = [...root.querySelectorAll<HTMLElement>('[data-signage-dot]')];
143
+ const seconds = Number(root.dataset.seconds) || 12;
144
+ let current = 0;
145
+
146
+ const show = (index: number) => {
147
+ slides.forEach((slide, at) => {
148
+ const active = at === index;
149
+ slide.classList.toggle('mwa-signage-slide-active', active);
150
+ if (active) slide.removeAttribute('aria-hidden');
151
+ else slide.setAttribute('aria-hidden', 'true');
152
+ });
153
+ dots.forEach((dot, at) =>
154
+ dot.classList.toggle('mwa-signage-dot-active', at === index)
155
+ );
156
+ current = index;
157
+ };
158
+ if (slides.length > 1) {
159
+ setInterval(() => show((current + 1) % slides.length), seconds * 1000);
160
+ }
161
+
162
+ const clock = root.querySelector<HTMLElement>('[data-signage-clock]');
163
+ const tick = () => {
164
+ if (!clock) return;
165
+ const now = new Date();
166
+ clock.textContent = now.toLocaleTimeString(root.dataset.locale, {
167
+ hour: '2-digit',
168
+ minute: '2-digit',
169
+ });
170
+ clock.setAttribute('datetime', now.toISOString());
171
+ };
172
+ tick();
173
+ setInterval(tick, 15_000);
174
+
175
+ // The nightly build brings the new day. A failed request keeps the
176
+ // screen as it is - a TV in a shop must not turn into an error page.
177
+ const CHECK_EVERY = 5 * 60_000;
178
+ setInterval(async () => {
179
+ try {
180
+ const response = await fetch(location.href, { cache: 'no-store' });
181
+ if (!response.ok) return;
182
+ const build = /data-build="([^"]+)"/.exec(await response.text())?.[1];
183
+ if (build && build !== root.dataset.build) location.reload();
184
+ } catch {
185
+ // Offline for a moment - the next check tries again.
186
+ }
187
+ }, CHECK_EVERY);
188
+
189
+ const hint = root.querySelector<HTMLElement>('[data-signage-hint]');
190
+ const hideHint = () => hint?.setAttribute('hidden', '');
191
+ setTimeout(hideHint, 20_000);
192
+ root.addEventListener('click', () => {
193
+ if (!document.fullscreenElement) {
194
+ document.documentElement.requestFullscreen?.().catch(() => {});
195
+ }
196
+ hideHint();
197
+ });
198
+
199
+ let idle: ReturnType<typeof setTimeout> | undefined;
200
+ root.addEventListener('pointermove', () => {
201
+ root.classList.remove('mwa-signage-idle');
202
+ clearTimeout(idle);
203
+ idle = setTimeout(() => root.classList.add('mwa-signage-idle'), 3000);
204
+ });
205
+ root.classList.add('mwa-signage-idle');
206
+
207
+ // Without it many TVs dim or start their own screensaver after a while.
208
+ const stayAwake = () =>
209
+ navigator.wakeLock?.request('screen').catch(() => {});
210
+ stayAwake();
211
+ document.addEventListener('visibilitychange', () => {
212
+ if (document.visibilityState === 'visible') stayAwake();
213
+ });
214
+ }
215
+ </script>