@n1kname/components 0.20.0 → 0.22.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@n1kname/components",
3
- "version": "0.20.0",
3
+ "version": "0.22.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -24,13 +24,15 @@
24
24
  "./legend.js": "./src/legend.js",
25
25
  "./sidepanel.js": "./src/sidepanel.js",
26
26
  "./mapstage.js": "./src/mapstage.js",
27
- "./match.css": "./src/match.css"
27
+ "./match.css": "./src/match.css",
28
+ "./loadfailed.js": "./src/loadfailed.js",
29
+ "./hexmap.js": "./src/hexmap.js"
28
30
  },
29
31
  "dependencies": {
30
- "@n1kname/charts": "0.11.0"
32
+ "@n1kname/charts": "0.12.0"
31
33
  },
32
34
  "peerDependencies": {
33
- "@n1kname/tokens": "^0.5.0",
35
+ "@n1kname/tokens": "^0.6.0",
34
36
  "astro": "^7.4.4"
35
37
  },
36
38
  "publishConfig": {
@@ -462,7 +462,7 @@ const lines = (label: string) => {
462
462
  }
463
463
 
464
464
  .in [data-step] {
465
- animation: settle 560ms var(--ease-spring) var(--d, 0ms) both;
465
+ animation: settle calc(var(--motion-grow, 700ms) * 0.8) var(--ease-spring) var(--d, 0ms) both;
466
466
  }
467
467
 
468
468
  .in .node,
@@ -477,17 +477,17 @@ const lines = (label: string) => {
477
477
  }
478
478
 
479
479
  .in .edge .line {
480
- animation: draw 700ms cubic-bezier(0.3, 0, 0.2, 1) var(--d, 0ms) both;
480
+ animation: draw var(--motion-grow, 700ms) cubic-bezier(0.3, 0, 0.2, 1) var(--d, 0ms) both;
481
481
  }
482
482
 
483
483
  .in .edge .head,
484
484
  .in .edge .edge-label {
485
- animation: land 320ms var(--ease-out) calc(var(--d, 0ms) + 560ms) both;
485
+ animation: land calc(var(--motion-grow, 700ms) * 0.45) var(--ease-out) calc(var(--d, 0ms) + var(--motion-grow, 700ms) * 0.8) both;
486
486
  }
487
487
 
488
488
  .in .ring {
489
489
  animation-name: grow;
490
- animation-duration: 900ms;
490
+ animation-duration: var(--motion-reveal);
491
491
  }
492
492
 
493
493
  @keyframes settle {
@@ -0,0 +1,32 @@
1
+ ---
2
+ /**
3
+ * What a page says when it could not read its figures: an error empty state with a way to try
4
+ * again, hidden until a script shows it with showFailed() from ./loadfailed.js, which also hides
5
+ * the page's content so no half-drawn chart stays behind it.
6
+ *
7
+ * "Try again" is a link to the page itself (its path, so Button draws a link: an empty href would
8
+ * make it a button that does nothing), so it works without script and reads the figures from the
9
+ * start.
10
+ */
11
+ import Button from './Button.astro';
12
+ import EmptyState from './EmptyState.astro';
13
+
14
+ interface Props {
15
+ id?: string;
16
+ title?: string;
17
+ text?: string;
18
+ retry?: string;
19
+ }
20
+ const {
21
+ id = 'failed',
22
+ title = "There's nothing to show right now",
23
+ text = 'The page reads its figures when it opens, so trying again usually works.',
24
+ retry = 'Try again',
25
+ } = Astro.props;
26
+ ---
27
+
28
+ <div id={id} class="load-failed" hidden data-load-failed>
29
+ <EmptyState kind="error" title={title} text={text}>
30
+ <Button href={Astro.url.pathname}>{retry}</Button>
31
+ </EmptyState>
32
+ </div>
package/src/Reveal.astro CHANGED
@@ -26,8 +26,8 @@ const { as: Element = 'div', class: className, ...rest } = Astro.props;
26
26
  opacity: 0;
27
27
  translate: 0 24px;
28
28
  transition:
29
- opacity 600ms var(--ease-out),
30
- translate 900ms var(--ease-soft);
29
+ opacity calc(var(--motion-reveal) * 2 / 3) var(--ease-out),
30
+ translate var(--motion-reveal) var(--ease-soft);
31
31
  transition-delay: var(--reveal-delay, 0ms);
32
32
  }
33
33
 
@@ -81,7 +81,7 @@ const titleId = `${id}-title`;
81
81
 
82
82
  @media (prefers-reduced-motion: no-preference) {
83
83
  .side-panel :global(.panel-loading span) {
84
- animation: panel-wait 1.2s ease-in-out infinite;
84
+ animation: panel-wait 1.2s var(--ease-standard) infinite;
85
85
  }
86
86
 
87
87
  .side-panel :global(.panel-arrived) {
@@ -0,0 +1,372 @@
1
+ ---
2
+ /**
3
+ * The page in front of something private: one field, one button, and what to do without them.
4
+ * It is the whole <main>, centred in the window, so a sign-in page is its head and this.
5
+ *
6
+ * card an app's sign-in: its mark and name above a card holding the form
7
+ * page a door with a reason: a heading in the display face, a sentence on why, the field and
8
+ * the button on one line
9
+ *
10
+ * The form posts wherever `action` says; nothing here reads or checks what was typed. The error
11
+ * is in the page from the start, hidden. It shows when the server says so (`error` true), when
12
+ * the address carries `errorParam` (a redirect back with ?error=1), or when a server removes its
13
+ * `hidden` attribute ([data-sign-in-error]) on the way out. Once shown, the field is marked
14
+ * invalid and takes focus, so typing again needs no click.
15
+ */
16
+ interface Props {
17
+ variant?: 'card' | 'page';
18
+ /** The h1: an app's name, or what the door is in front of. */
19
+ title: string;
20
+ /** One sentence under the title: why it's closed, or whose it is. */
21
+ lead?: string;
22
+ /** card: an image above the title, such as the app's icon. Decorative. */
23
+ mark?: string;
24
+ /** card: a heading inside the card, such as "Sign in". */
25
+ heading?: string;
26
+ action: string;
27
+ method?: 'post' | 'get';
28
+ /** The one field. A password by default; `code` for an access code, which isn't secret. */
29
+ field?: {
30
+ name?: string;
31
+ label?: string;
32
+ kind?: 'password' | 'code';
33
+ placeholder?: string;
34
+ };
35
+ submit?: string;
36
+ /** What the error says. Shown as described above. */
37
+ errorText?: string;
38
+ error?: boolean;
39
+ /** A query parameter that means the last try failed, such as `error`. */
40
+ errorParam?: string;
41
+ /** The main's id, for a skip link. */
42
+ id?: string;
43
+ class?: string;
44
+ }
45
+
46
+ const {
47
+ variant = 'card',
48
+ title,
49
+ lead,
50
+ mark,
51
+ heading,
52
+ action,
53
+ method = 'post',
54
+ field = {},
55
+ submit = 'Sign in',
56
+ errorText = 'That did not work. Try again.',
57
+ error = false,
58
+ errorParam,
59
+ id: mainId,
60
+ class: className,
61
+ } = Astro.props;
62
+
63
+ const { name = 'password', label = 'Password', kind = 'password', placeholder } = field;
64
+ const id = `sign-in-${name}`;
65
+ const errorId = `${id}-error`;
66
+ // A password lets the password manager fill it; a code is read off a CV, so nothing should
67
+ // correct it, capitalise it or offer to save it.
68
+ const input =
69
+ kind === 'password'
70
+ ? { type: 'password', autocomplete: 'current-password' }
71
+ : { type: 'text', autocomplete: 'off', autocapitalize: 'off', spellcheck: 'false', inputmode: 'text' };
72
+ ---
73
+
74
+ <main id={mainId} class:list={['sign-in', variant, className]} data-sign-in data-error-param={errorParam}>
75
+ <div class="inner">
76
+ <header class="head">
77
+ {variant === 'card' && mark && <img class="mark" src={mark} alt="" width="48" height="48" />}
78
+ <h1 class="title">{title}</h1>
79
+ {variant === 'page' && <span class="rule" aria-hidden="true"></span>}
80
+ {lead && <p class="lead">{lead}</p>}
81
+ </header>
82
+
83
+ <form class="form" method={method} action={action}>
84
+ {heading && <h2 class="heading">{heading}</h2>}
85
+ <p class="error" id={errorId} role="alert" hidden={!error} data-sign-in-error>{errorText}</p>
86
+ <label class:list={['label', { sr: variant === 'page' }]} for={id}>{label}</label>
87
+ <div class="row">
88
+ <input
89
+ class="field"
90
+ id={id}
91
+ name={name}
92
+ required
93
+ autofocus
94
+ placeholder={placeholder}
95
+ aria-describedby={errorId}
96
+ aria-invalid={error ? 'true' : undefined}
97
+ {...input}
98
+ />
99
+ <button class="submit" type="submit"><span class="submit-label">{submit}</span></button>
100
+ </div>
101
+ </form>
102
+
103
+ {Astro.slots.has('footer') && <footer class="foot"><slot name="footer" /></footer>}
104
+ </div>
105
+ </main>
106
+
107
+ <script>
108
+ // Shows the error the address asks for, marks the field and puts the cursor back in it. Marks
109
+ // the button busy once the form goes, so a second press doesn't send it twice.
110
+ document.querySelectorAll<HTMLElement>('[data-sign-in]').forEach((root) => {
111
+ const error = root.querySelector<HTMLElement>('[data-sign-in-error]')!;
112
+ const field = root.querySelector<HTMLInputElement>('.field')!;
113
+ const form = root.querySelector<HTMLFormElement>('form')!;
114
+ const param = root.dataset.errorParam;
115
+ if (param && new URLSearchParams(location.search).has(param)) error.hidden = false;
116
+ if (!error.hidden) {
117
+ field.setAttribute('aria-invalid', 'true');
118
+ field.focus();
119
+ }
120
+ field.addEventListener('input', () => field.removeAttribute('aria-invalid'), { once: true });
121
+ form.addEventListener('submit', () => {
122
+ const button = form.querySelector<HTMLButtonElement>('.submit')!;
123
+ if (button.dataset.busy) return;
124
+ button.dataset.busy = 'true';
125
+ button.setAttribute('aria-disabled', 'true');
126
+ });
127
+ // Back from the next page (the browser's cache): ready again.
128
+ addEventListener('pageshow', () => {
129
+ const button = form.querySelector<HTMLButtonElement>('.submit')!;
130
+ delete button.dataset.busy;
131
+ button.removeAttribute('aria-disabled');
132
+ });
133
+ });
134
+ </script>
135
+
136
+ <style>
137
+ .sign-in {
138
+ min-height: var(--sign-in-height, 100dvh);
139
+ display: grid;
140
+ place-items: center;
141
+ padding: var(--sp-6) var(--sp-4);
142
+ }
143
+
144
+ .inner {
145
+ width: 100%;
146
+ display: grid;
147
+ gap: var(--sp-6);
148
+ }
149
+
150
+ .card .inner {
151
+ max-width: 24rem;
152
+ }
153
+
154
+ .page .inner {
155
+ max-width: 30rem;
156
+ }
157
+
158
+ .head {
159
+ display: grid;
160
+ gap: var(--sp-2);
161
+ }
162
+
163
+ .card .head {
164
+ justify-items: center;
165
+ text-align: center;
166
+ }
167
+
168
+ .mark {
169
+ margin-bottom: var(--sp-2);
170
+ }
171
+
172
+ .title {
173
+ margin: 0;
174
+ font-family: var(--font-display, var(--font-body));
175
+ font-size: var(--text-h2);
176
+ line-height: var(--leading-h2, 1.2);
177
+ font-weight: 600;
178
+ text-wrap: balance;
179
+ }
180
+
181
+ .rule {
182
+ width: 44px;
183
+ height: 5px;
184
+ margin: var(--sp-2) 0 var(--sp-3);
185
+ border-radius: 2px;
186
+ background: var(--c-accent);
187
+ }
188
+
189
+ .lead {
190
+ margin: 0;
191
+ color: var(--c-text-secondary);
192
+ text-wrap: pretty;
193
+ }
194
+
195
+ .card .lead {
196
+ font-size: var(--text-body-sm);
197
+ }
198
+
199
+ .form {
200
+ display: grid;
201
+ gap: var(--sp-3);
202
+ }
203
+
204
+ .card .form {
205
+ box-sizing: border-box;
206
+ padding: var(--sp-6);
207
+ border: 1px solid var(--c-border);
208
+ border-radius: var(--radius-lg);
209
+ background: var(--c-surface);
210
+ }
211
+
212
+ .heading {
213
+ margin: 0 0 var(--sp-2);
214
+ font-size: var(--text-body);
215
+ font-weight: 600;
216
+ }
217
+
218
+ .label {
219
+ font-size: var(--text-body-sm);
220
+ font-weight: 600;
221
+ color: var(--c-text-secondary);
222
+ }
223
+
224
+ .sr {
225
+ position: absolute;
226
+ width: 1px;
227
+ height: 1px;
228
+ overflow: hidden;
229
+ clip-path: inset(50%);
230
+ white-space: nowrap;
231
+ }
232
+
233
+ .row {
234
+ display: grid;
235
+ gap: var(--sp-3);
236
+ }
237
+
238
+ .page .row {
239
+ grid-template-columns: minmax(0, 1fr) auto;
240
+ gap: var(--sp-2);
241
+ }
242
+
243
+ .field {
244
+ box-sizing: border-box;
245
+ width: 100%;
246
+ min-width: 0;
247
+ min-height: 44px;
248
+ padding: 0 var(--sp-3);
249
+ border: 1px solid var(--c-border-strong);
250
+ border-radius: var(--radius-md);
251
+ background: var(--c-bg);
252
+ color: var(--c-text);
253
+ font: inherit;
254
+ font-size: max(16px, var(--text-body-sm));
255
+ transition: border-color var(--motion-hover) var(--ease-hover);
256
+ }
257
+
258
+ .page .field {
259
+ background: var(--c-surface);
260
+ }
261
+
262
+ .field::placeholder {
263
+ color: var(--c-text-muted);
264
+ }
265
+
266
+ .field:hover {
267
+ border-color: var(--c-text-muted);
268
+ }
269
+
270
+ .field:focus-visible {
271
+ outline: 2px solid var(--c-focus);
272
+ outline-offset: 1px;
273
+ border-color: transparent;
274
+ }
275
+
276
+ .field[aria-invalid='true'] {
277
+ border-color: var(--c-status-critical);
278
+ }
279
+
280
+ .submit {
281
+ box-sizing: border-box;
282
+ display: inline-flex;
283
+ align-items: center;
284
+ justify-content: center;
285
+ min-height: 44px;
286
+ padding: 0 var(--sp-5);
287
+ border: 0;
288
+ border-radius: var(--radius-md);
289
+ background: var(--c-accent);
290
+ color: var(--c-on-accent);
291
+ font: inherit;
292
+ font-size: var(--text-body-sm);
293
+ font-weight: 600;
294
+ cursor: pointer;
295
+ touch-action: manipulation;
296
+ transition:
297
+ background-color var(--motion-hover) var(--ease-hover),
298
+ scale var(--motion-fast) var(--ease-out);
299
+ }
300
+
301
+ .card .submit {
302
+ width: 100%;
303
+ margin-top: var(--sp-2);
304
+ }
305
+
306
+ .submit:hover {
307
+ background: color-mix(in oklab, var(--c-accent) 88%, var(--c-text));
308
+ }
309
+
310
+ .submit:active {
311
+ scale: 0.98;
312
+ }
313
+
314
+ .submit:focus-visible {
315
+ outline: 2px solid var(--c-focus);
316
+ outline-offset: 2px;
317
+ }
318
+
319
+ /* Sent: the words fade back while the next page loads. No spinner: it's usually under a
320
+ second, and a spinner that flashes reads as a fault. */
321
+ .submit[data-busy] {
322
+ cursor: progress;
323
+ }
324
+
325
+ .submit[data-busy] .submit-label {
326
+ opacity: 0.6;
327
+ transition: opacity var(--motion-base) var(--ease-out) 300ms;
328
+ }
329
+
330
+ .error {
331
+ margin: 0;
332
+ padding: var(--sp-2) var(--sp-3);
333
+ border-radius: var(--radius-md);
334
+ background: color-mix(in oklab, var(--c-status-critical) 12%, var(--c-surface));
335
+ color: color-mix(in oklab, var(--c-status-critical) 70%, var(--c-text));
336
+ font-size: var(--text-body-sm);
337
+ }
338
+
339
+ .page .error {
340
+ order: 3;
341
+ }
342
+
343
+ .error[hidden] {
344
+ display: none;
345
+ }
346
+
347
+ .foot {
348
+ display: flex;
349
+ flex-wrap: wrap;
350
+ align-items: center;
351
+ justify-content: space-between;
352
+ gap: var(--sp-3);
353
+ color: var(--c-text-muted);
354
+ font-size: var(--text-caption);
355
+ }
356
+
357
+ .foot :global(p) {
358
+ margin: 0;
359
+ }
360
+
361
+ .foot :global(a) {
362
+ color: var(--c-text-accent);
363
+ }
364
+
365
+ @media (prefers-reduced-motion: reduce) {
366
+ .field,
367
+ .submit,
368
+ .submit[data-busy] .submit-label {
369
+ transition: none;
370
+ }
371
+ }
372
+ </style>
@@ -1,134 +1,298 @@
1
1
  ---
2
2
  /**
3
- * A project timeline: mono period in a left column, content on the right. The column
4
- * fits the longest period, so every entry lines up, and wraps past 200px.
5
- * Needs type.css for its t-meta and t-sub classes.
3
+ * A project timeline: a marker and a line down the left, and each entry's period, title and text
4
+ * beside it. The period sits above the title, small, so a year, a phase or a name all read the
5
+ * same, and the text keeps the width.
6
6
  *
7
- * The final entry is the current state, so its marker is filled.
7
+ * Entries up to `current` are done (filled markers on a solid line); `current` is now (a marker
8
+ * with a halo); any after it are still to come (hollow markers on a dashed line). By default the
9
+ * last entry is now. An entry can carry an icon, shown in a soft disc of the accent.
10
+ *
11
+ * Once, as each entry comes into view, its marker settles in, its text rises and its line draws on
12
+ * to the next. Nothing moves under reduced motion, and without script everything is simply there.
8
13
  */
14
+ import type { IconName } from './icons';
15
+ import Icon from './Icon.astro';
16
+
9
17
  interface Entry {
10
18
  period: string;
11
19
  label: string;
12
20
  body: string;
21
+ /** What the step was, from the icon set: users, search, route, … */
22
+ icon?: IconName;
13
23
  }
14
24
 
15
25
  interface Props {
16
26
  entries: Entry[];
27
+ /** Which entry is now, 0 first. The last by default; false for a history that is over. */
28
+ current?: number | false;
17
29
  }
18
30
 
19
- const { entries } = Astro.props;
31
+ const { entries, current = entries.length - 1 } = Astro.props;
32
+ const icons = entries.some((e) => e.icon);
33
+ const state = (i: number) => (current === false || i < current ? 'done' : i === current ? 'current' : 'next');
20
34
  ---
21
35
 
22
- <ol class="timeline">
36
+ <ol class="timeline" data-icons={icons ? '' : undefined} data-timeline>
23
37
  {
24
38
  entries.map((e, i) => (
25
- <li class={i === entries.length - 1 ? 'last' : ''}>
26
- <span class="rail" aria-hidden="true" />
27
- <span class="period t-meta">{e.period}</span>
28
- <div class="body">
29
- <p class="t-sub">{e.label}</p>
39
+ <li data-state={state(i)} aria-current={state(i) === 'current' ? 'step' : undefined} data-to={i < entries.length - 1 ? state(i + 1) : undefined}>
40
+ <span class="marker" aria-hidden="true">
41
+ {e.icon && <Icon name={e.icon} size={16} />}
42
+ </span>
43
+ <div class="content">
44
+ <p class="period">{e.period}</p>
45
+ <p class="label">{e.label}</p>
30
46
  <p class="text">{e.body}</p>
31
47
  </div>
32
48
  </li>
33
49
  ))
34
50
  }
35
51
  </ol>
52
+ <script is:inline>
53
+ // Before the first paint, so entries waiting to arrive never show and then vanish.
54
+ (function (list) {
55
+ if (list && 'IntersectionObserver' in window && !matchMedia('(prefers-reduced-motion: reduce)').matches) list.classList.add('arrive');
56
+ })(document.currentScript && document.currentScript.previousElementSibling);
57
+ </script>
58
+
59
+ <script>
60
+ // Each entry arrives once, as it comes into view. Entries that come into view together follow
61
+ // one another a beat apart.
62
+ document.querySelectorAll<HTMLElement>('[data-timeline].arrive').forEach((list) => {
63
+ const seen = new IntersectionObserver(
64
+ (entries) => {
65
+ entries
66
+ .filter((e) => e.isIntersecting)
67
+ .forEach((e, k) => {
68
+ const li = e.target as HTMLElement;
69
+ li.style.setProperty('--d', `${k * 110}ms`);
70
+ li.classList.add('in');
71
+ seen.unobserve(li);
72
+ });
73
+ },
74
+ { threshold: 0.25, rootMargin: '0px 0px -8% 0px' },
75
+ );
76
+ list.querySelectorAll('li').forEach((li) => seen.observe(li));
77
+ });
78
+ </script>
36
79
 
37
80
  <style>
38
81
  .timeline {
39
- display: grid;
40
- grid-template-columns: 20px fit-content(200px) minmax(0, 1fr);
41
- column-gap: var(--sp-4);
82
+ /* The marker's size and how far it sits down the first line, so the line can meet it. */
83
+ --m: 12px;
84
+ --mt: 4px;
85
+ --col: 16px;
86
+ --gap: var(--sp-6);
87
+ --done: var(--c-accent);
88
+ --rail-done: color-mix(in oklab, var(--c-accent) 45%, var(--c-border));
89
+ --rail-next: var(--c-border-strong);
42
90
  list-style: none;
43
91
  margin: var(--sp-5) 0 var(--sp-7);
44
92
  padding: 0;
45
93
  }
46
94
 
47
- /* Each entry shares the list's columns, so the periods all take the same width. */
95
+ .timeline[data-icons] {
96
+ --m: 32px;
97
+ --mt: 0px;
98
+ --col: 32px;
99
+ }
100
+
48
101
  li {
49
- display: grid;
50
- grid-column: 1 / -1;
51
- grid-template-columns: subgrid;
52
- padding-bottom: var(--sp-6);
53
102
  position: relative;
103
+ display: grid;
104
+ grid-template-columns: var(--col) minmax(0, 1fr);
105
+ column-gap: var(--sp-4);
106
+ padding-bottom: var(--gap);
54
107
  }
55
108
 
56
109
  li:last-child {
57
110
  padding-bottom: 0;
58
111
  }
59
112
 
60
- /* Marker plus the connecting line, drawn as one element. */
61
- .rail {
62
- position: relative;
63
- width: 20px;
64
- margin-top: 3px;
65
- }
66
-
67
- .rail::before {
113
+ /* The line from this marker to the next, a small gap clear of each. */
114
+ li:not(:last-child)::before {
68
115
  content: '';
69
116
  position: absolute;
70
- inset-inline-start: 0;
71
- top: 0;
72
- width: 14px;
73
- height: 14px;
117
+ inset-inline-start: calc(var(--col) / 2 - 1px);
118
+ top: calc(var(--mt) + var(--m) + 6px);
119
+ bottom: calc(6px - var(--mt));
120
+ width: 2px;
121
+ border-radius: 1px;
122
+ background: var(--rail-done);
123
+ transform-origin: top;
124
+ }
125
+
126
+ /* On to what's still to come: dashed, and quieter. */
127
+ li[data-to='next']::before {
128
+ background: repeating-linear-gradient(to bottom, var(--rail-next) 0 4px, transparent 4px 9px);
129
+ opacity: 0.7;
130
+ }
131
+
132
+ /* ── Markers ─────────────────────────────────────────────────────────────── */
133
+ .marker {
134
+ position: relative;
135
+ display: grid;
136
+ place-items: center;
137
+ width: var(--m);
138
+ height: var(--m);
139
+ margin-top: var(--mt);
140
+ justify-self: center;
74
141
  border-radius: var(--radius-full);
75
- border: 3px solid var(--c-accent);
142
+ background: var(--done);
143
+ color: var(--c-text-accent);
144
+ }
145
+
146
+ .marker :global(svg) {
147
+ display: block;
148
+ }
149
+
150
+ /* Now: a halo round it, so it reads as where things stand. */
151
+ [data-state='current'] .marker {
152
+ box-shadow: 0 0 0 4px color-mix(in oklab, var(--c-accent) 28%, transparent);
153
+ }
154
+
155
+ /* Still to come: hollow. */
156
+ [data-state='next'] .marker {
76
157
  background: var(--c-bg);
158
+ box-shadow: inset 0 0 0 2px var(--c-border-strong);
77
159
  }
78
160
 
79
- .last .rail::before {
80
- border-color: var(--c-text);
161
+ /* With icons: a soft disc of the accent for what's done, the accent itself for now. */
162
+ [data-icons] [data-state='done'] .marker {
163
+ background: color-mix(in oklab, var(--c-accent) 16%, var(--c-surface));
81
164
  }
82
165
 
83
- .rail::after {
84
- content: '';
85
- position: absolute;
86
- inset-inline-start: 6px;
87
- top: 18px;
88
- bottom: calc(var(--sp-6) * -1);
89
- width: 2px;
90
- background: var(--c-border);
166
+ [data-icons] [data-state='current'] .marker {
167
+ background: var(--c-accent);
168
+ color: var(--c-on-accent);
169
+ }
170
+
171
+ [data-icons] [data-state='next'] .marker {
172
+ color: var(--c-text-muted);
173
+ box-shadow: inset 0 0 0 1.5px var(--c-border-strong);
91
174
  }
92
175
 
93
- .last .rail::after {
94
- display: none;
176
+ /* ── Text ────────────────────────────────────────────────────────────────── */
177
+ .content {
178
+ min-width: 0;
95
179
  }
96
180
 
97
- .period {
98
- min-width: 84px;
99
- padding-top: 1px;
181
+ /* With icons, the period sits level with the middle of the disc. */
182
+ [data-icons] .content {
183
+ padding-top: calc((var(--m) - var(--text-caption) * 1.5) / 2);
100
184
  }
101
185
 
102
- .body p {
186
+ .content p {
103
187
  max-width: none;
188
+ margin: 0;
189
+ }
190
+
191
+ .period {
192
+ font-family: var(--font-body);
193
+ font-size: var(--text-caption);
194
+ line-height: 1.5;
195
+ font-weight: 600;
196
+ letter-spacing: 0.02em;
197
+ font-variant-numeric: tabular-nums;
198
+ color: var(--c-text-muted);
104
199
  }
105
200
 
106
- .t-sub {
107
- margin-bottom: var(--sp-1);
201
+ [data-state='current'] .period {
202
+ color: var(--c-text-accent);
203
+ }
204
+
205
+ .label {
206
+ margin-top: 2px;
207
+ font-family: var(--font-body);
208
+ font-size: var(--text-sub);
209
+ line-height: var(--leading-sub);
210
+ letter-spacing: var(--tracking-sub);
211
+ font-weight: 600;
212
+ color: var(--c-text);
108
213
  }
109
214
 
110
215
  .text {
216
+ margin-top: var(--sp-1);
217
+ color: var(--c-text-secondary);
218
+ text-wrap: pretty;
219
+ }
220
+
221
+ [data-state='next'] .text {
111
222
  color: var(--c-text-muted);
112
223
  }
113
224
 
114
- /* Below the fold of a phone the three columns stop earning their keep. */
115
- @media (max-width: 560px) {
116
- .timeline {
117
- grid-template-columns: 20px minmax(0, 1fr);
225
+ /* ── Arriving, once ─────────────────────────────────────────────────────────
226
+ Only on a page whose script has run and that allows motion, so the timeline is never hidden
227
+ without it. The marker settles on the spring, the text rises a little, then the line draws on
228
+ to the next entry. Now's halo ripples out once. */
229
+ .arrive li:not(.in) .marker {
230
+ opacity: 0;
231
+ transform: scale(0.4);
232
+ }
233
+
234
+ .arrive li:not(.in) .content {
235
+ opacity: 0;
236
+ transform: translateY(6px);
237
+ }
238
+
239
+ .arrive li:not(.in)::before {
240
+ transform: scaleY(0);
241
+ }
242
+
243
+ /* The transitions belong to arriving only: going back to waiting is instant. */
244
+ .arrive li.in .marker {
245
+ transition:
246
+ opacity var(--motion-base) var(--ease-out) var(--d, 0ms),
247
+ transform var(--motion-spring) var(--ease-spring) var(--d, 0ms);
248
+ }
249
+
250
+ .arrive li.in .content {
251
+ transition:
252
+ opacity var(--motion-gentle) var(--ease-out) calc(var(--d, 0ms) + 60ms),
253
+ transform var(--motion-gentle) var(--ease-out) calc(var(--d, 0ms) + 60ms);
254
+ }
255
+
256
+ .arrive li.in::before {
257
+ transition: transform calc(var(--motion-grow, 700ms) * 0.75) var(--ease-soft) calc(var(--d, 0ms) + 200ms);
258
+ }
259
+
260
+ .arrive [data-state='current'].in .marker::after {
261
+ content: '';
262
+ position: absolute;
263
+ inset: 0;
264
+ border-radius: inherit;
265
+ box-shadow: 0 0 0 2px var(--c-accent);
266
+ opacity: 0;
267
+ animation: ripple var(--motion-reveal) var(--ease-out) calc(var(--d, 0ms) + 260ms);
268
+ }
269
+
270
+ @keyframes ripple {
271
+ from {
272
+ opacity: 0.6;
273
+ transform: scale(1);
118
274
  }
119
275
 
120
- li {
121
- row-gap: var(--sp-1);
276
+ to {
277
+ opacity: 0;
278
+ transform: scale(2);
279
+ }
280
+ }
281
+
282
+ @media (forced-colors: active) {
283
+ .marker {
284
+ forced-color-adjust: none;
285
+ background: CanvasText;
286
+ color: Canvas;
122
287
  }
123
288
 
124
- /* Spans both rows so the connecting line still reaches the next marker. */
125
- .rail {
126
- grid-row: span 2;
289
+ [data-state='next'] .marker {
290
+ background: Canvas;
291
+ box-shadow: inset 0 0 0 2px CanvasText;
127
292
  }
128
293
 
129
- .period,
130
- .body {
131
- grid-column: 2;
294
+ li:not(:last-child)::before {
295
+ background: CanvasText;
132
296
  }
133
297
  }
134
298
  </style>
package/src/hexmap.js ADDED
@@ -0,0 +1,149 @@
1
+ // Hexagons of counts on a MapLibre map: flat and coloured along the heat ramp by rank, or raised in
2
+ // 3D by height, from @n1kname/charts/hexbin's features. It adds its layers again after every
3
+ // setStyle (a theme or basemap change), resolves its colours for the canvas each time, and says the
4
+ // count under the pointer in the charts' pointer card.
5
+ //
6
+ // It never imports MapLibre: pass the map, and the Popup class for the pointer card.
7
+ //
8
+ // import maplibregl from 'maplibre-gl';
9
+ // import { hexbin, hexFeatures } from '@n1kname/charts/hexbin';
10
+ // import { hexLayers } from '@n1kname/components/hexmap.js';
11
+ //
12
+ // const hexes = hexLayers(map, { Popup: maplibregl.Popup, card: (p) => `<strong>${p.count}</strong> points` });
13
+ // hexes.setData(hexFeatures(hexbin(points, { origin })));
14
+ // view.addEventListener('segment-change', (e) => hexes.setTall(e.detail.value === '3d'));
15
+
16
+ import { HEAT, onTheme, ramp } from './mapstage.js';
17
+
18
+ const reduced = () => matchMedia('(prefers-reduced-motion: reduce)').matches;
19
+
20
+ // Rising takes the tokens' grow; settling 70% of it, as leaving is quicker than arriving. The
21
+ // camera tilts over the same time as the rise, so the two land together. Read when the view
22
+ // changes, so a site that tunes the token is followed.
23
+ const RISE = () => {
24
+ const v = getComputedStyle(document.documentElement).getPropertyValue('--motion-grow').trim();
25
+ const n = parseFloat(v);
26
+ return Number.isNaN(n) ? 700 : v.endsWith('ms') ? n : v.endsWith('s') ? n * 1000 : n;
27
+ };
28
+ const SETTLE = () => Math.round(RISE() * 0.7);
29
+ // Ease-out (cubic): most of the travel early, a soft landing.
30
+ const out = (t) => 1 - (1 - t) ** 3;
31
+
32
+ /**
33
+ * map: a MapLibre map. Options:
34
+ * id the source's name, and the layers' prefix ('hexes')
35
+ * colours the ramp, low to high (the heat tokens)
36
+ * tall metres the busiest hexagon rises to (10,000 for a city at zoom 11)
37
+ * opacity ({ tall }) => a fill opacity: see-through enough for the streets under it
38
+ * pitch, bearing the camera in 3D
39
+ * Popup, card the Popup class and (properties) => HTML, for a card under the pointer
40
+ * onDrawn called once the map has drawn new data (tests and "ready" wait for it)
41
+ * Returns { setData, setTall, restyle, isTall }.
42
+ */
43
+ export const hexLayers = (
44
+ map,
45
+ {
46
+ id = 'hexes',
47
+ colours = HEAT,
48
+ tall: tallMetres = 10_000,
49
+ opacity = ({ tall }) => (tall ? 0.7 : 0.5),
50
+ pitch = 55,
51
+ bearing = -15,
52
+ Popup,
53
+ card,
54
+ onDrawn,
55
+ } = {},
56
+ ) => {
57
+ const FLAT = `${id}-flat`;
58
+ const TALL = `${id}-tall`;
59
+ let data = { type: 'FeatureCollection', features: [] };
60
+ let tall = false;
61
+ let rise = 0;
62
+ let frame = 0;
63
+
64
+ const colour = () => ramp('rank', colours);
65
+ const height = () => ['*', ['get', 'height'], tallMetres * rise];
66
+
67
+ const add = () => {
68
+ if (map.getSource(id)) return;
69
+ map.addSource(id, { type: 'geojson', data });
70
+ map.addLayer({ id: FLAT, type: 'fill', source: id, layout: { visibility: tall ? 'none' : 'visible' }, paint: { 'fill-color': colour(), 'fill-opacity': opacity({ tall: false }) } });
71
+ map.addLayer({
72
+ id: TALL,
73
+ type: 'fill-extrusion',
74
+ source: id,
75
+ layout: { visibility: tall ? 'visible' : 'none' },
76
+ paint: { 'fill-extrusion-color': colour(), 'fill-extrusion-opacity': opacity({ tall: true }), 'fill-extrusion-height': height() },
77
+ });
78
+ };
79
+
80
+ // A style still loading can't take changes: its layers come in as they should once it is.
81
+ const restyle = () => {
82
+ try {
83
+ if (!map.getLayer(FLAT)) return;
84
+ map.setLayoutProperty(TALL, 'visibility', tall ? 'visible' : 'none');
85
+ map.setLayoutProperty(FLAT, 'visibility', tall ? 'none' : 'visible');
86
+ map.setPaintProperty(FLAT, 'fill-color', colour());
87
+ map.setPaintProperty(FLAT, 'fill-opacity', opacity({ tall: false }));
88
+ map.setPaintProperty(TALL, 'fill-extrusion-color', colour());
89
+ map.setPaintProperty(TALL, 'fill-extrusion-opacity', opacity({ tall: true }));
90
+ } catch {
91
+ map.once('idle', restyle);
92
+ }
93
+ };
94
+
95
+ const animate = (to, duration, done) => {
96
+ cancelAnimationFrame(frame);
97
+ const from = rise;
98
+ const span = reduced() ? 0 : duration;
99
+ const start = performance.now();
100
+ const tick = (now) => {
101
+ const t = span ? Math.min((now - start) / span, 1) : 1;
102
+ rise = from + (to - from) * out(t);
103
+ try {
104
+ if (map.getLayer(TALL)) map.setPaintProperty(TALL, 'fill-extrusion-height', height());
105
+ } catch {}
106
+ if (t < 1) frame = requestAnimationFrame(tick);
107
+ else done?.();
108
+ };
109
+ frame = requestAnimationFrame(tick);
110
+ };
111
+
112
+ const setTall = (on) => {
113
+ tall = on;
114
+ map.easeTo({ pitch: on ? pitch : 0, bearing: on ? bearing : 0, duration: reduced() ? 0 : on ? RISE() : SETTLE() });
115
+ if (on) {
116
+ restyle();
117
+ animate(1, RISE());
118
+ } else {
119
+ // Settle first, then swap to the flat layer, so they don't drop through the floor.
120
+ animate(0, SETTLE(), restyle);
121
+ }
122
+ };
123
+
124
+ const setData = (next) => {
125
+ data = next;
126
+ map.getSource(id)?.setData(data);
127
+ if (onDrawn) map.once('idle', onDrawn);
128
+ };
129
+
130
+ if (map.isStyleLoaded?.()) add();
131
+ map.on('style.load', add);
132
+ onTheme(restyle);
133
+
134
+ if (Popup && card) {
135
+ const popup = new Popup({ closeButton: false, closeOnClick: false, offset: 12, className: 'place-card' });
136
+ for (const layer of [FLAT, TALL]) {
137
+ map.on('mousemove', layer, (e) => {
138
+ map.getCanvas().style.cursor = 'pointer';
139
+ popup.setLngLat(e.lngLat).setHTML(`<div class="chart-pointer-card"><p class="chart-pointer-one">${card(e.features[0].properties)}</p></div>`).addTo(map);
140
+ });
141
+ map.on('mouseleave', layer, () => {
142
+ map.getCanvas().style.cursor = '';
143
+ popup.remove();
144
+ });
145
+ }
146
+ }
147
+
148
+ return { setData, setTall, restyle, isTall: () => tall };
149
+ };
package/src/highlight.css CHANGED
@@ -24,7 +24,7 @@
24
24
 
25
25
  @media (prefers-reduced-motion: no-preference) {
26
26
  :where(mark.highlight, .page-header .text mark) {
27
- animation: highlight 700ms var(--ease-out)
27
+ animation: highlight calc(var(--motion-draw, 1000ms) * 0.7) var(--ease-out)
28
28
  calc(var(--highlight-delay, 300ms) + var(--n, 0) * var(--highlight-step, 450ms)) both;
29
29
  }
30
30
  }
package/src/legend.js CHANGED
@@ -3,6 +3,8 @@
3
3
  //
4
4
  // import { setKeys } from '@n1kname/components/legend.js';
5
5
  // setKeys(legend, [{ label: 'Walking', color: 'var(--c-chart-5)' }, …]);
6
+ // The system's curves, so a key leaves and arrives as everything else does.
7
+ const token = (name, fallback) => getComputedStyle(document.documentElement).getPropertyValue(name).trim() || fallback;
6
8
  const reduced = () => matchMedia('(prefers-reduced-motion: reduce)').matches;
7
9
  const esc = (s) => String(s).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
8
10
 
@@ -17,7 +19,7 @@ export const setKeys = (ul, keys) => {
17
19
  if (want.has(key)) continue;
18
20
  li.setAttribute('data-leaving', '');
19
21
  if (reduced()) li.remove();
20
- else li.animate([{ opacity: 1 }, { opacity: 0, transform: 'scale(0.9)' }], { duration: 140, easing: 'ease-in' }).finished.then(() => li.remove());
22
+ else li.animate([{ opacity: 1 }, { opacity: 0, transform: 'scale(0.9)' }], { duration: 140, easing: token('--ease-exit', 'ease-in') }).finished.then(() => li.remove());
21
23
  }
22
24
  // In the order given: each key moved to the end in turn, so they end up in order after any
23
25
  // that are still fading out.
@@ -31,7 +33,7 @@ export const setKeys = (ul, keys) => {
31
33
  li.setAttribute(scope, '');
32
34
  li.firstElementChild.setAttribute(scope, '');
33
35
  }
34
- if (!reduced()) li.animate([{ opacity: 0, transform: 'translateY(3px)' }, { opacity: 1, transform: 'none' }], { duration: 220, delay: 120, easing: 'ease-out', fill: 'backwards' });
36
+ if (!reduced()) li.animate([{ opacity: 0, transform: 'translateY(3px)' }, { opacity: 1, transform: 'none' }], { duration: 220, delay: 120, easing: token('--ease-out', 'ease-out'), fill: 'backwards' });
35
37
  }
36
38
  ul.append(li);
37
39
  }
@@ -0,0 +1,18 @@
1
+ // Shows and hides a LoadFailed and the content it stands in for. `hide` is what goes away while it
2
+ // shows: a page's #content, or on a map page the panels over the map ([data-content]), so the
3
+ // title and the map stay.
4
+
5
+ const CONTENT = '#content, [data-content]';
6
+
7
+ export const showFailed = ({ id = 'failed', hide = CONTENT } = {}) => {
8
+ const el = document.getElementById(id);
9
+ // Try again opens this very address, with its query (a year, a filter), not just the page.
10
+ el.querySelector('a')?.setAttribute('href', location.href);
11
+ el.hidden = false;
12
+ document.querySelectorAll(hide).forEach((el) => (el.hidden = true));
13
+ };
14
+
15
+ export const hideFailed = ({ id = 'failed', hide = CONTENT } = {}) => {
16
+ document.getElementById(id).hidden = true;
17
+ document.querySelectorAll(hide).forEach((el) => (el.hidden = false));
18
+ };
@@ -228,10 +228,15 @@ export const setYearCalendar = (box, opts) => {
228
228
  const cy = top - ch - 8 >= 0 ? top - ch - 8 : top + c.height + 8;
229
229
  card.style.transform = `translate(${cx}px, ${cy}px)`;
230
230
 
231
- const first = !layer.classList.contains('is-on');
232
- layer.classList.toggle('is-jump', first);
231
+ // In place the first time and on every key press, as the charts' pointer does; gliding only
232
+ // after the pointer.
233
+ const jump = !layer.classList.contains('is-on') || fromKeys;
234
+ layer.classList.toggle('is-jump', jump);
233
235
  layer.classList.add('is-on');
234
- if (first) requestAnimationFrame(() => layer.classList.remove('is-jump'));
236
+ if (jump) {
237
+ void layer.offsetWidth;
238
+ requestAnimationFrame(() => layer.classList.remove('is-jump'));
239
+ }
235
240
  if (fromKeys) {
236
241
  const said = [line, ...more.map((e) => (Array.isArray(e) ? e.join(' ') : e))].filter(Boolean);
237
242
  live.textContent = `${date(d)}${said.length ? `: ${said.join(', ')}` : ''}`;