@n1kname/components 0.21.0 → 0.23.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 +6 -4
- package/src/Diamonds.astro +385 -0
- package/src/FlowDiagram.astro +4 -4
- package/src/LoadFailed.astro +32 -0
- package/src/Phases.astro +363 -0
- package/src/Reveal.astro +2 -2
- package/src/SectionNav.astro +149 -0
- package/src/SidePanel.astro +1 -1
- package/src/SignIn.astro +372 -0
- package/src/Timeline.astro +4 -4
- package/src/hexmap.js +149 -0
- package/src/highlight.css +1 -1
- package/src/legend.js +4 -2
- package/src/loadfailed.js +18 -0
- package/src/yearcalendar.js +8 -3
package/src/SignIn.astro
ADDED
|
@@ -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>
|
package/src/Timeline.astro
CHANGED
|
@@ -225,7 +225,7 @@ const state = (i: number) => (current === false || i < current ? 'done' : i ===
|
|
|
225
225
|
/* ── Arriving, once ─────────────────────────────────────────────────────────
|
|
226
226
|
Only on a page whose script has run and that allows motion, so the timeline is never hidden
|
|
227
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
|
|
228
|
+
to the next entry. Now's halo ripples out once. */
|
|
229
229
|
.arrive li:not(.in) .marker {
|
|
230
230
|
opacity: 0;
|
|
231
231
|
transform: scale(0.4);
|
|
@@ -254,7 +254,7 @@ const state = (i: number) => (current === false || i < current ? 'done' : i ===
|
|
|
254
254
|
}
|
|
255
255
|
|
|
256
256
|
.arrive li.in::before {
|
|
257
|
-
transition: transform
|
|
257
|
+
transition: transform calc(var(--motion-grow, 700ms) * 0.75) var(--ease-soft) calc(var(--d, 0ms) + 200ms);
|
|
258
258
|
}
|
|
259
259
|
|
|
260
260
|
.arrive [data-state='current'].in .marker::after {
|
|
@@ -264,7 +264,7 @@ const state = (i: number) => (current === false || i < current ? 'done' : i ===
|
|
|
264
264
|
border-radius: inherit;
|
|
265
265
|
box-shadow: 0 0 0 2px var(--c-accent);
|
|
266
266
|
opacity: 0;
|
|
267
|
-
animation: ripple
|
|
267
|
+
animation: ripple var(--motion-reveal) var(--ease-out) calc(var(--d, 0ms) + 260ms);
|
|
268
268
|
}
|
|
269
269
|
|
|
270
270
|
@keyframes ripple {
|
|
@@ -275,7 +275,7 @@ const state = (i: number) => (current === false || i < current ? 'done' : i ===
|
|
|
275
275
|
|
|
276
276
|
to {
|
|
277
277
|
opacity: 0;
|
|
278
|
-
transform: scale(2
|
|
278
|
+
transform: scale(2);
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
281
|
|
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
|
|
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, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
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
|
+
};
|
package/src/yearcalendar.js
CHANGED
|
@@ -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
|
-
|
|
232
|
-
|
|
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 (
|
|
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(', ')}` : ''}`;
|