maverick-wave 5.32.0 → 5.34.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,107 @@
1
+ // Picks today's occasion before the first paint. A classic script in <head>,
2
+ // so the decoration arrives with the page instead of shifting it a moment
3
+ // later; main.js then plays what this decided - the intro and the particles.
4
+ //
5
+ // <html data-mw-occasions='[{"effect": "snow", "from": "2026-12-05",
6
+ // "until": "2027-02-05", "yearly": true, "scroll": true, "size": "sm"}]'>
7
+ // <script src="maverick-wave/src/js/occasions.js"></script>
8
+ (function () {
9
+ 'use strict';
10
+
11
+ const EFFECTS = [
12
+ 'snow',
13
+ 'christmas',
14
+ 'newyear',
15
+ 'spring',
16
+ 'easter',
17
+ 'summer',
18
+ 'autumn',
19
+ 'football',
20
+ 'birthday',
21
+ 'anniversary',
22
+ ];
23
+
24
+ const html = document.documentElement;
25
+ const params = new URLSearchParams(location.search);
26
+ // ?mw-occasion=snow&mw-occasion-size=lg&mw-occasion-scroll&mw-occasion-intro
27
+ // shows an occasion on the live page before anyone books it
28
+ const preview = params.get('mw-occasion');
29
+ let entry = null;
30
+
31
+ if (preview !== null) {
32
+ entry = {
33
+ effect: preview,
34
+ size: params.get('mw-occasion-size'),
35
+ scroll: params.has('mw-occasion-scroll'),
36
+ intro: params.has('mw-occasion-intro') && 'preview',
37
+ };
38
+ } else if (html.dataset.mwOccasions) {
39
+ try {
40
+ entry = activeOccasion(JSON.parse(html.dataset.mwOccasions), new Date());
41
+ } catch (error) {
42
+ console.warn('MaverickWave: data-mw-occasions is not valid JSON', error);
43
+ }
44
+ }
45
+
46
+ if (!entry || !EFFECTS.includes(entry.effect)) return;
47
+
48
+ EFFECTS.forEach((name) => html.classList.remove('mw-occasion-' + name));
49
+ html.classList.add('mw-occasion-' + entry.effect);
50
+ html.classList.toggle('mw-occasion-scroll', !!entry.scroll);
51
+ html.classList.toggle('mw-occasion-sm', entry.size === 'sm');
52
+ html.classList.toggle('mw-occasion-lg', entry.size === 'lg');
53
+ // 'preview' plays on every load, an empty value once per visit
54
+ if (entry.intro) {
55
+ html.setAttribute(
56
+ 'data-mw-occasion-intro',
57
+ entry.intro === 'preview' ? 'preview' : ''
58
+ );
59
+ }
60
+
61
+ // The shortest window that contains today wins, so Christmas beats the snow
62
+ // season around it without anyone having to order the list
63
+ function activeOccasion(entries, now) {
64
+ let best = null;
65
+
66
+ (Array.isArray(entries) ? entries : []).forEach((candidate) => {
67
+ // An effect this version does not draw must not win the day for nothing
68
+ if (!EFFECTS.includes(candidate.effect)) return;
69
+ const span = occasionWindow(candidate, now);
70
+ if (span && (!best || span.end - span.start < best.length)) {
71
+ best = { entry: candidate, length: span.end - span.start };
72
+ }
73
+ });
74
+
75
+ return best && best.entry;
76
+ }
77
+
78
+ // Local days, the last one included. A yearly window keeps month and day and
79
+ // may run over New Year - 5 December to 5 February.
80
+ function occasionWindow(candidate, now) {
81
+ const from = localDay(candidate.from);
82
+ const until = localDay(candidate.until);
83
+ if (!from || !until || until < from) return null;
84
+
85
+ const years = candidate.yearly
86
+ ? [now.getFullYear() - 1, now.getFullYear()]
87
+ : [from.getFullYear()];
88
+
89
+ for (const year of years) {
90
+ const shift = year - from.getFullYear();
91
+ const start = new Date(year, from.getMonth(), from.getDate());
92
+ const end = new Date(
93
+ until.getFullYear() + shift,
94
+ until.getMonth(),
95
+ until.getDate() + 1
96
+ );
97
+ if (start <= now && now < end) return { start, end };
98
+ }
99
+
100
+ return null;
101
+ }
102
+
103
+ function localDay(value) {
104
+ const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value || '');
105
+ return match ? new Date(+match[1], match[2] - 1, +match[3]) : null;
106
+ }
107
+ })();
@@ -536,6 +536,8 @@ $z-index: (
536
536
  'modal': 500,
537
537
  'tooltip': 700,
538
538
  'alert': 900,
539
+ // The intro overlay of an occasion - five seconds, above everything
540
+ 'occasion': 1000,
539
541
  );
540
542
 
541
543
  // Native select arrow, drawn as a background layer because `appearance: none`