maverick-wave-astro 1.0.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 (94) hide show
  1. package/README.md +83 -0
  2. package/bin/check.mjs +53 -0
  3. package/components/Accordion.astro +47 -0
  4. package/components/Address.astro +36 -0
  5. package/components/Announcement.astro +27 -0
  6. package/components/Avatar.astro +34 -0
  7. package/components/BaseLayout.astro +142 -0
  8. package/components/BlogPost.astro +144 -0
  9. package/components/Breadcrumbs.astro +69 -0
  10. package/components/Calendar.astro +104 -0
  11. package/components/CalendarLegend.astro +34 -0
  12. package/components/ComingSoon.astro +21 -0
  13. package/components/DateStamp.astro +24 -0
  14. package/components/EmptyState.astro +24 -0
  15. package/components/Favicons.astro +42 -0
  16. package/components/Feed.astro +85 -0
  17. package/components/Footer.astro +162 -0
  18. package/components/Gallery.astro +55 -0
  19. package/components/Header.astro +107 -0
  20. package/components/Hero.astro +158 -0
  21. package/components/Icon.astro +27 -0
  22. package/components/IconCard.astro +36 -0
  23. package/components/ImageSlider.astro +64 -0
  24. package/components/ImprintCard.astro +52 -0
  25. package/components/JsonLd.astro +11 -0
  26. package/components/LanguageSwitch.astro +53 -0
  27. package/components/LegalPage.astro +19 -0
  28. package/components/Media.astro +40 -0
  29. package/components/MetaInfo.astro +24 -0
  30. package/components/Modal.astro +47 -0
  31. package/components/Mosaic.astro +38 -0
  32. package/components/NotFound.astro +34 -0
  33. package/components/Offer.astro +79 -0
  34. package/components/OpeningHours.astro +14 -0
  35. package/components/PageHeader.astro +38 -0
  36. package/components/Picture.astro +50 -0
  37. package/components/PortraitGallery.astro +68 -0
  38. package/components/PostalAddress.astro +20 -0
  39. package/components/Price.astro +84 -0
  40. package/components/PrivacyCard.astro +65 -0
  41. package/components/Progress.astro +53 -0
  42. package/components/PromoBar.astro +25 -0
  43. package/components/Schedule.astro +60 -0
  44. package/components/SectionHead.astro +18 -0
  45. package/components/SocialLinks.astro +47 -0
  46. package/components/Stepper.astro +76 -0
  47. package/components/Stories.astro +80 -0
  48. package/components/TabPanel.astro +15 -0
  49. package/components/Table.astro +115 -0
  50. package/components/Tabs.astro +38 -0
  51. package/components/Testimonial.astro +61 -0
  52. package/components/ThemeToggle.astro +30 -0
  53. package/components/Tiles.astro +63 -0
  54. package/components/Timeline.astro +64 -0
  55. package/components/ValueList.astro +42 -0
  56. package/config/eslint.js +58 -0
  57. package/config/prettier.mjs +30 -0
  58. package/dist/config.d.ts +3 -0
  59. package/dist/config.js +6 -0
  60. package/dist/contact.d.ts +2 -0
  61. package/dist/contact.js +8 -0
  62. package/dist/date.d.ts +26 -0
  63. package/dist/date.js +72 -0
  64. package/dist/design.d.ts +166 -0
  65. package/dist/design.js +175 -0
  66. package/dist/icons.d.ts +13 -0
  67. package/dist/icons.js +15 -0
  68. package/dist/image-size.d.ts +10 -0
  69. package/dist/image-size.js +70 -0
  70. package/dist/integration.d.ts +13 -0
  71. package/dist/integration.js +90 -0
  72. package/dist/path.d.ts +1 -0
  73. package/dist/path.js +5 -0
  74. package/dist/schedule.d.ts +30 -0
  75. package/dist/schedule.js +117 -0
  76. package/dist/social.d.ts +35 -0
  77. package/dist/social.js +37 -0
  78. package/dist/structured-data.d.ts +1 -0
  79. package/dist/structured-data.js +2 -0
  80. package/dist/text.d.ts +3 -0
  81. package/dist/text.js +30 -0
  82. package/dist/types.d.ts +35 -0
  83. package/dist/types.js +1 -0
  84. package/dist/uploads.d.ts +7 -0
  85. package/dist/uploads.js +64 -0
  86. package/package.json +75 -0
  87. package/routes/design.css.ts +7 -0
  88. package/routes/theme.js.ts +28 -0
  89. package/routes/virtual.d.ts +6 -0
  90. package/schemas/design.schema.json +214 -0
  91. package/schemas/promo.schema.json +37 -0
  92. package/styles/schedule.css +17 -0
  93. package/styles/table.css +8 -0
  94. package/styles/theme-toggle.css +13 -0
package/dist/date.js ADDED
@@ -0,0 +1,72 @@
1
+ export const pad2 = (value) => String(value).padStart(2, '0');
2
+ // Split by hand instead of new Date('2026-09-06'): the latter parses as UTC
3
+ // midnight and shifts the day for everyone west of UTC.
4
+ export const parseIsoDate = (value) => {
5
+ const [year, month, day] = value.split('-').map(Number);
6
+ return new Date(year, month - 1, day);
7
+ };
8
+ export const isoDate = (date) => `${date.getFullYear()}-${pad2(date.getMonth() + 1)}-${pad2(date.getDate())}`;
9
+ export const addDays = (date, days) => {
10
+ const result = new Date(date);
11
+ result.setDate(result.getDate() + days);
12
+ return result;
13
+ };
14
+ // For the date stamp on a card: "Sa" and "12.09."
15
+ export const dateStamp = (date, locale = 'de-DE') => ({
16
+ weekday: date
17
+ .toLocaleDateString(locale, { weekday: 'short' })
18
+ .replace('.', ''),
19
+ short: `${pad2(date.getDate())}.${pad2(date.getMonth() + 1)}.`,
20
+ iso: isoDate(date),
21
+ });
22
+ export const longDate = (date, locale = 'de-DE') => date.toLocaleDateString(locale, {
23
+ day: 'numeric',
24
+ month: 'long',
25
+ year: 'numeric',
26
+ });
27
+ export const yearsSince = (date, now = new Date()) => {
28
+ const start = parseIsoDate(date);
29
+ let years = now.getFullYear() - start.getFullYear();
30
+ const notYet = now.getMonth() < start.getMonth() ||
31
+ (now.getMonth() === start.getMonth() && now.getDate() < start.getDate());
32
+ if (notYet)
33
+ years -= 1;
34
+ return years;
35
+ };
36
+ // Always six rows, even when five would do - otherwise the page jumps when
37
+ // calendars side by side end up with different heights.
38
+ const ROWS = 6;
39
+ export const monthGrid = (from, count, extra = () => ({}), now = new Date()) => {
40
+ const today = new Date(now);
41
+ today.setHours(0, 0, 0, 0);
42
+ return Array.from({ length: count }, (_, offset) => {
43
+ const first = new Date(from.getFullYear(), from.getMonth() + offset, 1);
44
+ // Monday as first column: getDay() counts from Sunday.
45
+ const lead = (first.getDay() + 6) % 7;
46
+ const start = addDays(first, -lead);
47
+ return {
48
+ year: first.getFullYear(),
49
+ month: first.getMonth(),
50
+ days: Array.from({ length: ROWS * 7 }, (_, index) => {
51
+ const date = addDays(start, index);
52
+ const weekday = date.getDay();
53
+ return {
54
+ iso: isoDate(date),
55
+ day: date.getDate(),
56
+ inMonth: date.getMonth() === first.getMonth(),
57
+ weekend: weekday === 0 || weekday === 6,
58
+ past: date < today,
59
+ today: date.getTime() === today.getTime(),
60
+ ...extra(isoDate(date)),
61
+ };
62
+ }),
63
+ };
64
+ });
65
+ };
66
+ // "Samstag, 12. September 2026" - for aria labels and mail texts.
67
+ export const fullDate = (iso, locale = 'de-DE') => parseIsoDate(iso).toLocaleDateString(locale, {
68
+ weekday: 'long',
69
+ day: 'numeric',
70
+ month: 'long',
71
+ year: 'numeric',
72
+ });
@@ -0,0 +1,166 @@
1
+ export declare const VARIANTS: {
2
+ readonly corners: {
3
+ readonly even: {
4
+ readonly className: "mw-corners-even";
5
+ };
6
+ };
7
+ readonly radius: {
8
+ readonly square: {
9
+ readonly property: "--mw-radius-scale";
10
+ readonly value: "0";
11
+ };
12
+ readonly round: {
13
+ readonly property: "--mw-radius-scale";
14
+ readonly value: "1.7";
15
+ };
16
+ };
17
+ readonly buttonShape: {
18
+ readonly square: {
19
+ readonly className: "mw-btn-square";
20
+ };
21
+ readonly pill: {
22
+ readonly className: "mw-btn-pill";
23
+ };
24
+ };
25
+ readonly buttonStyle: {
26
+ readonly glass: {
27
+ readonly className: "mw-btn-glass";
28
+ };
29
+ readonly tactile: {
30
+ readonly className: "mw-btn-tactile";
31
+ };
32
+ };
33
+ readonly accent: {
34
+ readonly single: {
35
+ readonly className: "mw-accent-single";
36
+ };
37
+ };
38
+ readonly shadows: {
39
+ readonly flat: {
40
+ readonly className: "mw-shadows-flat";
41
+ };
42
+ };
43
+ readonly surfaces: {
44
+ readonly flush: {
45
+ readonly className: "mw-surfaces-flush";
46
+ };
47
+ };
48
+ readonly headings: {
49
+ readonly caps: {
50
+ readonly className: "mw-headings-caps";
51
+ };
52
+ };
53
+ readonly links: {
54
+ readonly underline: {
55
+ readonly className: "mw-links-underline";
56
+ };
57
+ };
58
+ readonly density: {
59
+ readonly compact: {
60
+ readonly className: "mw-density-compact";
61
+ };
62
+ readonly roomy: {
63
+ readonly className: "mw-density-roomy";
64
+ };
65
+ };
66
+ readonly fontSize: {
67
+ readonly small: {
68
+ readonly property: "--mw-root-font-size";
69
+ readonly value: "93.75%";
70
+ };
71
+ readonly large: {
72
+ readonly property: "--mw-root-font-size";
73
+ readonly value: "106.25%";
74
+ };
75
+ };
76
+ readonly width: {
77
+ readonly narrow: {
78
+ readonly property: "--mw-container-width";
79
+ readonly value: string;
80
+ };
81
+ readonly medium: {
82
+ readonly property: "--mw-container-width";
83
+ readonly value: string;
84
+ };
85
+ readonly wide: {
86
+ readonly property: "--mw-container-width";
87
+ readonly value: string;
88
+ };
89
+ readonly full: {
90
+ readonly property: "--mw-container-width";
91
+ readonly value: "calc(100% - 2 * var(--mw-container-gutter))";
92
+ };
93
+ };
94
+ readonly hover: {
95
+ readonly static: {
96
+ readonly className: "mw-hover-static";
97
+ };
98
+ };
99
+ readonly motion: {
100
+ readonly brisk: {
101
+ readonly property: "--mw-motion-scale";
102
+ readonly value: "0.6";
103
+ };
104
+ readonly relaxed: {
105
+ readonly property: "--mw-motion-scale";
106
+ readonly value: "1.6";
107
+ };
108
+ };
109
+ readonly sections: {
110
+ readonly plain: {
111
+ readonly className: "mw-sections-plain";
112
+ };
113
+ };
114
+ readonly scrollEffects: {
115
+ readonly off: {
116
+ readonly className: "mw-scroll-static";
117
+ };
118
+ };
119
+ readonly spacing: {
120
+ readonly compact: {
121
+ readonly property: "--mw-section-padding-block";
122
+ readonly value: "var(--mw-section-padding-compact)";
123
+ };
124
+ readonly airy: {
125
+ readonly property: "--mw-section-padding-block";
126
+ readonly value: "var(--mw-section-padding-airy)";
127
+ };
128
+ readonly fluid: {
129
+ readonly property: "--mw-section-padding-block";
130
+ readonly value: "var(--mw-section-padding-fluid)";
131
+ };
132
+ };
133
+ };
134
+ export declare const DEFAULTS: {
135
+ readonly corners: "signature";
136
+ readonly radius: "default";
137
+ readonly buttonShape: "default";
138
+ readonly buttonStyle: "default";
139
+ readonly accent: "dual";
140
+ readonly shadows: "default";
141
+ readonly surfaces: "raised";
142
+ readonly headings: "default";
143
+ readonly links: "default";
144
+ readonly density: "default";
145
+ readonly fontSize: "default";
146
+ readonly width: "default";
147
+ readonly hover: "animated";
148
+ readonly motion: "default";
149
+ readonly sections: "patterned";
150
+ readonly scrollEffects: "on";
151
+ readonly spacing: "default";
152
+ };
153
+ type Variants = typeof VARIANTS;
154
+ export type Design = {
155
+ -readonly [Key in keyof Variants]?: keyof Variants[Key] | (typeof DEFAULTS)[Key];
156
+ } & {
157
+ header?: 'reveal' | 'sticky';
158
+ customProperties?: Record<string, string>;
159
+ };
160
+ export declare const designClasses: (design: Design) => string[];
161
+ export declare const designCss: (design: Design) => string;
162
+ export declare const headerReveals: (design: Design) => boolean;
163
+ export declare const mergeDesigns: (...layers: (Design | undefined)[]) => Design;
164
+ export declare const validateDesign: (design: Design) => Design;
165
+ export declare const designFromSetup: (setup: string) => Design;
166
+ export {};
package/dist/design.js ADDED
@@ -0,0 +1,175 @@
1
+ // The variants from the overlay on maverick-wave.m1well.com, named after what
2
+ // they do. design.json stores these names instead of class names, so it stays
3
+ // readable and survives a rename in the framework.
4
+ const containerWidth = (pixels) => `min(${pixels}, calc(100% - 2 * var(--mw-container-gutter)))`;
5
+ export const VARIANTS = {
6
+ corners: { even: { className: 'mw-corners-even' } },
7
+ radius: {
8
+ square: { property: '--mw-radius-scale', value: '0' },
9
+ round: { property: '--mw-radius-scale', value: '1.7' },
10
+ },
11
+ buttonShape: {
12
+ square: { className: 'mw-btn-square' },
13
+ pill: { className: 'mw-btn-pill' },
14
+ },
15
+ buttonStyle: {
16
+ glass: { className: 'mw-btn-glass' },
17
+ tactile: { className: 'mw-btn-tactile' },
18
+ },
19
+ accent: { single: { className: 'mw-accent-single' } },
20
+ shadows: { flat: { className: 'mw-shadows-flat' } },
21
+ surfaces: { flush: { className: 'mw-surfaces-flush' } },
22
+ headings: { caps: { className: 'mw-headings-caps' } },
23
+ links: { underline: { className: 'mw-links-underline' } },
24
+ density: {
25
+ compact: { className: 'mw-density-compact' },
26
+ roomy: { className: 'mw-density-roomy' },
27
+ },
28
+ fontSize: {
29
+ small: { property: '--mw-root-font-size', value: '93.75%' },
30
+ large: { property: '--mw-root-font-size', value: '106.25%' },
31
+ },
32
+ width: {
33
+ narrow: {
34
+ property: '--mw-container-width',
35
+ value: containerWidth('800px'),
36
+ },
37
+ medium: {
38
+ property: '--mw-container-width',
39
+ value: containerWidth('960px'),
40
+ },
41
+ wide: { property: '--mw-container-width', value: containerWidth('1440px') },
42
+ full: {
43
+ property: '--mw-container-width',
44
+ value: 'calc(100% - 2 * var(--mw-container-gutter))',
45
+ },
46
+ },
47
+ hover: { static: { className: 'mw-hover-static' } },
48
+ motion: {
49
+ brisk: { property: '--mw-motion-scale', value: '0.6' },
50
+ relaxed: { property: '--mw-motion-scale', value: '1.6' },
51
+ },
52
+ sections: { plain: { className: 'mw-sections-plain' } },
53
+ scrollEffects: { off: { className: 'mw-scroll-static' } },
54
+ spacing: {
55
+ compact: {
56
+ property: '--mw-section-padding-block',
57
+ value: 'var(--mw-section-padding-compact)',
58
+ },
59
+ airy: {
60
+ property: '--mw-section-padding-block',
61
+ value: 'var(--mw-section-padding-airy)',
62
+ },
63
+ fluid: {
64
+ property: '--mw-section-padding-block',
65
+ value: 'var(--mw-section-padding-fluid)',
66
+ },
67
+ },
68
+ };
69
+ // The value that sets nothing - what MaverickWave does by itself.
70
+ export const DEFAULTS = {
71
+ corners: 'signature',
72
+ radius: 'default',
73
+ buttonShape: 'default',
74
+ buttonStyle: 'default',
75
+ accent: 'dual',
76
+ shadows: 'default',
77
+ surfaces: 'raised',
78
+ headings: 'default',
79
+ links: 'default',
80
+ density: 'default',
81
+ fontSize: 'default',
82
+ width: 'default',
83
+ hover: 'animated',
84
+ motion: 'default',
85
+ sections: 'patterned',
86
+ scrollEffects: 'on',
87
+ spacing: 'default',
88
+ };
89
+ const effects = (design) => Object.entries(VARIANTS).flatMap(([key, values]) => {
90
+ const value = design[key];
91
+ return value && Object.hasOwn(values, value)
92
+ ? [values[value]]
93
+ : [];
94
+ });
95
+ export const designClasses = (design) => effects(design).flatMap(effect => 'className' in effect ? [effect.className] : []);
96
+ // Doubled selector on purpose: design.css comes before the site CSS, a plain
97
+ // :root would lose against the :root block in main.scss.
98
+ export const designCss = (design) => {
99
+ const properties = [
100
+ ...effects(design).flatMap(effect => 'property' in effect ? [[effect.property, effect.value]] : []),
101
+ ...Object.entries(design.customProperties ?? {}),
102
+ ];
103
+ return properties.length
104
+ ? `:root:root{${properties.map(([name, value]) => `${name}:${value};`).join('')}}`
105
+ : '';
106
+ };
107
+ export const headerReveals = (design) => design.header !== 'sticky';
108
+ // Later layers win - Michael's base first, then what the customer changed in
109
+ // design.json.
110
+ export const mergeDesigns = (...layers) => layers.reduce((merged, layer) => ({
111
+ ...merged,
112
+ ...layer,
113
+ customProperties: {
114
+ ...merged.customProperties,
115
+ ...layer?.customProperties,
116
+ },
117
+ }), {});
118
+ export const validateDesign = (design) => {
119
+ for (const [key, value] of Object.entries(design)) {
120
+ if (key === 'customProperties')
121
+ continue;
122
+ if (key === 'header') {
123
+ if (value !== 'reveal' && value !== 'sticky') {
124
+ throw new Error(`Design: header has no value "${value}"`);
125
+ }
126
+ continue;
127
+ }
128
+ const values = VARIANTS[key];
129
+ if (!values)
130
+ throw new Error(`Design: unknown key "${key}"`);
131
+ if (value !== DEFAULTS[key] &&
132
+ !Object.hasOwn(values, String(value))) {
133
+ throw new Error(`Design: ${key} has no value "${value}"`);
134
+ }
135
+ }
136
+ return design;
137
+ };
138
+ // Class names never contain a colon - one table serves both kinds of effect.
139
+ const REVERSE = new Map(Object.entries(VARIANTS).flatMap(([key, values]) => Object.entries(values).map(([value, effect]) => [
140
+ 'className' in effect
141
+ ? effect.className
142
+ : `${effect.property}:${effect.value}`,
143
+ [key, value],
144
+ ])));
145
+ // Reads the text from the setup box of the overlay: `html class="..."`, a line
146
+ // `.mw-header: no mw-header-reveal` and a :root block.
147
+ export const designFromSetup = (setup) => {
148
+ const design = {};
149
+ const customProperties = {};
150
+ const classes = setup.match(/class\s*=\s*"([^"]*)"/)?.[1] ?? '';
151
+ for (const className of classes.split(/\s+/).filter(Boolean)) {
152
+ const match = REVERSE.get(className);
153
+ if (!match)
154
+ throw new Error(`Setup: unknown class "${className}"`);
155
+ design[match[0]] = match[1];
156
+ }
157
+ for (const [, className] of setup.matchAll(/:\s*no\s+([\w-]+)/g)) {
158
+ if (className !== 'mw-header-reveal') {
159
+ throw new Error(`Setup: "no ${className}" is not supported`);
160
+ }
161
+ design.header = 'sticky';
162
+ }
163
+ for (const [, name, raw] of setup.matchAll(/(--[\w-]+)\s*:\s*([^;\n}]+)/g)) {
164
+ const value = raw.trim();
165
+ const match = REVERSE.get(`${name}:${value}`);
166
+ if (match)
167
+ design[match[0]] = match[1];
168
+ else
169
+ customProperties[name] = value;
170
+ }
171
+ if (Object.keys(customProperties).length) {
172
+ design.customProperties = customProperties;
173
+ }
174
+ return design;
175
+ };
@@ -0,0 +1,13 @@
1
+ export declare const PACKAGE_ICONS: {
2
+ readonly 'chevron-down': "<path d=\"m6 9 6 6 6-6\"/>";
3
+ readonly check: "<path d=\"m5 12.5 4.5 4.5L19 7.5\"/>";
4
+ readonly 'arrow-down': "<path d=\"M12 4v15M6 13.5 12 20l6-6.5\"/>";
5
+ readonly house: "<path d=\"M3.5 11.5 12 4l8.5 7.5\"/><path d=\"M6 10v10h12V10\"/>";
6
+ readonly 'arrow-left': "<path d=\"M20 12H5M11 5.5 4.5 12l6.5 6.5\"/>";
7
+ readonly 'arrow-right': "<path d=\"M4 12h15M13 5.5l6.5 6.5-6.5 6.5\"/>";
8
+ readonly calendar: "<rect x=\"3\" y=\"5\" width=\"18\" height=\"16\" rx=\"2.4\"/><path d=\"M3 10h18M8 3v4M16 3v4\"/>";
9
+ readonly clock: "<circle cx=\"12\" cy=\"12\" r=\"8.5\"/><path d=\"M12 7.5V12l3 2\"/>";
10
+ readonly person: "<circle cx=\"12\" cy=\"8\" r=\"4\"/><path d=\"M4.5 20.5a7.5 7.5 0 0 1 15 0\"/>";
11
+ readonly moon: "<path d=\"M20 14.2A8.3 8.3 0 0 1 9.8 4a8.3 8.3 0 1 0 10.2 10.2Z\"/>";
12
+ readonly sun: "<circle cx=\"12\" cy=\"12\" r=\"4\"/><path d=\"M12 2.5v2.4M12 19.1v2.4M2.5 12h2.4M19.1 12h2.4M5.3 5.3l1.7 1.7M17 17l1.7 1.7M5.3 18.7 7 17M17 7l1.7-1.7\"/>";
13
+ };
package/dist/icons.js ADDED
@@ -0,0 +1,15 @@
1
+ // Stroke icons the package components draw themselves. Sites keep their own
2
+ // collection in src/components/icons.ts.
3
+ export const PACKAGE_ICONS = {
4
+ 'chevron-down': '<path d="m6 9 6 6 6-6"/>',
5
+ check: '<path d="m5 12.5 4.5 4.5L19 7.5"/>',
6
+ 'arrow-down': '<path d="M12 4v15M6 13.5 12 20l6-6.5"/>',
7
+ house: '<path d="M3.5 11.5 12 4l8.5 7.5"/><path d="M6 10v10h12V10"/>',
8
+ 'arrow-left': '<path d="M20 12H5M11 5.5 4.5 12l6.5 6.5"/>',
9
+ 'arrow-right': '<path d="M4 12h15M13 5.5l6.5 6.5-6.5 6.5"/>',
10
+ calendar: '<rect x="3" y="5" width="18" height="16" rx="2.4"/><path d="M3 10h18M8 3v4M16 3v4"/>',
11
+ clock: '<circle cx="12" cy="12" r="8.5"/><path d="M12 7.5V12l3 2"/>',
12
+ person: '<circle cx="12" cy="8" r="4"/><path d="M4.5 20.5a7.5 7.5 0 0 1 15 0"/>',
13
+ moon: '<path d="M20 14.2A8.3 8.3 0 0 1 9.8 4a8.3 8.3 0 1 0 10.2 10.2Z"/>',
14
+ sun: '<circle cx="12" cy="12" r="4"/><path d="M12 2.5v2.4M12 19.1v2.4M2.5 12h2.4M19.1 12h2.4M5.3 5.3l1.7 1.7M17 17l1.7 1.7M5.3 18.7 7 17M17 7l1.7-1.7"/>',
15
+ };
@@ -0,0 +1,10 @@
1
+ export type ImageSize = {
2
+ width: number;
3
+ height: number;
4
+ };
5
+ export declare const imageSize: (publicPath: string) => ImageSize | null;
6
+ export declare const publicImage: (path: string) => {
7
+ width?: number | undefined;
8
+ height?: number | undefined;
9
+ src: string;
10
+ };
@@ -0,0 +1,70 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { withBase } from "./path.js";
4
+ // Intrinsic size of a file in public/, read at build time so every <img> can
5
+ // declare width and height and the browser can reserve the box.
6
+ const cache = new Map();
7
+ const readPng = (buffer) => {
8
+ // Signature, then the IHDR chunk carries width and height as big-endian u32.
9
+ if (buffer.length < 24 || buffer.readUInt32BE(0) !== 0x89504e47)
10
+ return null;
11
+ return { width: buffer.readUInt32BE(16), height: buffer.readUInt32BE(20) };
12
+ };
13
+ const readJpeg = (buffer) => {
14
+ if (buffer.length < 4 || buffer.readUInt16BE(0) !== 0xffd8)
15
+ return null;
16
+ let offset = 2;
17
+ while (offset + 9 < buffer.length) {
18
+ if (buffer[offset] !== 0xff)
19
+ return null;
20
+ const marker = buffer[offset + 1];
21
+ const length = buffer.readUInt16BE(offset + 2);
22
+ // SOF0 to SOF15, minus the four markers in that range that carry no frame.
23
+ const isFrame = marker >= 0xc0 && marker <= 0xcf && ![0xc4, 0xc8, 0xcc].includes(marker);
24
+ if (isFrame) {
25
+ return {
26
+ height: buffer.readUInt16BE(offset + 5),
27
+ width: buffer.readUInt16BE(offset + 7),
28
+ };
29
+ }
30
+ offset += 2 + length;
31
+ }
32
+ return null;
33
+ };
34
+ const readSvg = (buffer) => {
35
+ const head = buffer.subarray(0, 2048).toString('utf-8');
36
+ const viewBox = head.match(/viewBox=["']\s*[\d.-]+\s+[\d.-]+\s+([\d.]+)\s+([\d.]+)/);
37
+ if (viewBox) {
38
+ return { width: Math.round(+viewBox[1]), height: Math.round(+viewBox[2]) };
39
+ }
40
+ const width = head.match(/\bwidth=["'](\d+)/);
41
+ const height = head.match(/\bheight=["'](\d+)/);
42
+ return width && height ? { width: +width[1], height: +height[1] } : null;
43
+ };
44
+ export const imageSize = (publicPath) => {
45
+ const cached = cache.get(publicPath);
46
+ if (cached !== undefined)
47
+ return cached;
48
+ let size = null;
49
+ try {
50
+ const buffer = readFileSync(join('public', publicPath.replace(/^\//, '')));
51
+ if (publicPath.endsWith('.svg'))
52
+ size = readSvg(buffer);
53
+ else if (/\.jpe?g$/.test(publicPath))
54
+ size = readJpeg(buffer);
55
+ else
56
+ size = readPng(buffer);
57
+ }
58
+ catch {
59
+ size = null;
60
+ }
61
+ if (!size)
62
+ console.warn(`[imageSize] no dimensions for ${publicPath}`);
63
+ cache.set(publicPath, size);
64
+ return size;
65
+ };
66
+ // An <img> from public/: the URL with the base in front and the box to reserve.
67
+ export const publicImage = (path) => ({
68
+ src: withBase(path),
69
+ ...imageSize(path),
70
+ });
@@ -0,0 +1,13 @@
1
+ import { type SitemapOptions } from '@astrojs/sitemap';
2
+ import type { AstroIntegration } from 'astro';
3
+ import type { Config, OgImage, Site } from './types.ts';
4
+ export type { Design } from './design.ts';
5
+ export type { OgImage, Site } from './types.ts';
6
+ export type Options = {
7
+ site: Site;
8
+ ogImage: OgImage;
9
+ sitemap?: SitemapOptions | false;
10
+ designFile?: string;
11
+ };
12
+ export declare const buildConfig: (options: Options, root: string) => Config;
13
+ export default function homepage(options: Options): AstroIntegration;
@@ -0,0 +1,90 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import sitemap, {} from '@astrojs/sitemap';
5
+ import { designClasses, designCss, designFromSetup, mergeDesigns, validateDesign, } from "./design.js";
6
+ import { prepareUploads, removeOriginals } from "./uploads.js";
7
+ const MODULE = 'virtual:maverick-wave-astro/config';
8
+ // Page counter: same origin to nginx, which passes it on to vestigia
9
+ // internally. No cookie, no identifier, no IP, no third party.
10
+ const COUNTER = `const isLocal = ['localhost', '127.0.0.1'].includes(window.location.hostname);
11
+ if (!isLocal && navigator.sendBeacon) {
12
+ const page = window.location.pathname.replace(/^\\/+|\\/+$/g, '') || 'home';
13
+ navigator.sendBeacon(\`/_c/\${page}\`);
14
+ }`;
15
+ const readDesign = (file) => existsSync(file) ? JSON.parse(readFileSync(file, 'utf8')) : undefined;
16
+ export const buildConfig = (options, root) => {
17
+ const { site, ogImage } = options;
18
+ const base = typeof site.design === 'string'
19
+ ? designFromSetup(site.design)
20
+ : site.design;
21
+ const design = validateDesign(mergeDesigns(base, readDesign(path.join(root, options.designFile ?? 'src/content/design.json'))));
22
+ return {
23
+ site: { ...site, lang: site.lang ?? 'de', locale: site.locale ?? 'de_DE' },
24
+ ogImage,
25
+ design,
26
+ htmlClasses: designClasses(design),
27
+ designCss: designCss(design),
28
+ };
29
+ };
30
+ export default function homepage(options) {
31
+ return {
32
+ name: 'maverick-wave-astro',
33
+ hooks: {
34
+ 'astro:config:setup': async ({ config: astroConfig, updateConfig, injectRoute, injectScript, addWatchFile, logger, }) => {
35
+ const root = fileURLToPath(astroConfig.root);
36
+ // Before any page renders: Picture reads the sizes from public/.
37
+ const uploads = await prepareUploads(fileURLToPath(astroConfig.publicDir));
38
+ if (uploads.written > 0)
39
+ logger.info(`${uploads.written} image sizes for uploads written`);
40
+ for (const file of uploads.skipped)
41
+ logger.warn(`uploads/${file} is not a readable image, it gets no sizes`);
42
+ const config = buildConfig(options, root);
43
+ const designFile = path.join(root, options.designFile ?? 'src/content/design.json');
44
+ if (existsSync(designFile))
45
+ addWatchFile(designFile);
46
+ updateConfig({
47
+ output: 'static',
48
+ // The CSP has no 'unsafe-inline' and would drop inlined CSS and JS.
49
+ build: { inlineStylesheets: 'never' },
50
+ integrations: options.sitemap === false ? [] : [sitemap(options.sitemap)],
51
+ vite: {
52
+ build: { assetsInlineLimit: 0 },
53
+ resolve: { alias: { '@': path.join(root, 'src') } },
54
+ plugins: [
55
+ {
56
+ name: 'maverick-wave-astro:config',
57
+ resolveId: (id) => id === MODULE ? `\0${MODULE}` : undefined,
58
+ load: (id) => id === `\0${MODULE}`
59
+ ? `export default ${JSON.stringify(config)};`
60
+ : undefined,
61
+ },
62
+ ],
63
+ },
64
+ });
65
+ // Injected rather than rendered by a component: only what the site
66
+ // actually uses ends up in the build.
67
+ if (config.site.mwScript !== false) {
68
+ injectScript('page', `import 'maverick-wave';`);
69
+ }
70
+ if (config.site.counter)
71
+ injectScript('page', COUNTER);
72
+ if (config.designCss) {
73
+ injectRoute({
74
+ pattern: '/design.css',
75
+ entrypoint: new URL('../routes/design.css.ts', import.meta.url),
76
+ prerender: true,
77
+ });
78
+ }
79
+ if (config.site.themeToggle) {
80
+ injectRoute({
81
+ pattern: '/theme.js',
82
+ entrypoint: new URL('../routes/theme.js.ts', import.meta.url),
83
+ prerender: true,
84
+ });
85
+ }
86
+ },
87
+ 'astro:build:done': ({ dir }) => removeOriginals(fileURLToPath(dir)),
88
+ },
89
+ };
90
+ }
package/dist/path.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const withBase: (target: string) => string;
package/dist/path.js ADDED
@@ -0,0 +1,5 @@
1
+ // Astro only prefixes "base" to the links it generates itself. Everything from
2
+ // public/ and every hand-written href has to go through here, otherwise a site
3
+ // under beispiel.formatwerke.de/<name>/ points at the root of the host.
4
+ const base = (import.meta.env?.BASE_URL ?? '/').replace(/\/$/, '');
5
+ export const withBase = (target) => `${base}/${target.replace(/^\//, '')}`;
@@ -0,0 +1,30 @@
1
+ export declare const endOfDay: (date: string) => Date | null;
2
+ export declare const GRACE_HOURS = 12;
3
+ export declare const visibleUntil: (date: string) => Date | null;
4
+ export type ScheduledEvent = {
5
+ date: string;
6
+ time?: string;
7
+ };
8
+ export declare const upcomingEvents: <T extends ScheduledEvent>(entries: readonly T[], now?: Date) => T[];
9
+ export declare const eventExpiry: (entry: ScheduledEvent) => string;
10
+ export declare const eventDateText: (entry: ScheduledEvent, locale?: string) => string;
11
+ export type Promo = {
12
+ percent: number;
13
+ text: string;
14
+ from?: string;
15
+ until?: string;
16
+ };
17
+ export declare const promoInHtml: (promo: Promo | null | undefined, now?: Date) => promo is Promo;
18
+ export declare const promoExpiry: (promo: Promo | null | undefined, now?: Date) => string | null;
19
+ export declare const promoStart: (promo: Promo | null | undefined, now?: Date) => string | null;
20
+ export declare const discountText: (promo: Promo) => string;
21
+ export declare const discountedPrice: (promo: Promo, amount: number) => number;
22
+ export declare const promoEndDate: (promo: Promo, locale?: string) => string | null;
23
+ export declare const promoText: (promo: Promo, { locale, untilWord }?: {
24
+ locale?: string | undefined;
25
+ untilWord?: string | undefined;
26
+ }) => string;
27
+ export declare const eventTimeRange: (entry: ScheduledEvent) => {
28
+ start: string;
29
+ end: string | null;
30
+ } | null;