@n1kname/components 0.22.0 → 0.24.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 +1 -1
- package/src/CareerMap.astro +537 -0
- package/src/Diamonds.astro +446 -0
- package/src/Phases.astro +376 -0
- package/src/SectionNav.astro +149 -0
package/src/Phases.astro
ADDED
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* A way of working in phases: each phase a band that points on to the next, its steps as rings
|
|
4
|
+
* under it, and a short text on what happens in it. Below them, spans for what runs across
|
|
5
|
+
* phases, such as discovery that never quite stops.
|
|
6
|
+
*
|
|
7
|
+
* Drawn in the diagrams' own style, on a sunken plate with tinted bands and hairline rings, as in
|
|
8
|
+
* Flow diagram and Diamonds. HTML, so the words are text that wraps and is read out in order.
|
|
9
|
+
* Below 640px wide the phases stack and each span says which phases it runs across in words.
|
|
10
|
+
*
|
|
11
|
+
* Once, as it comes into view, the phases arrive left to right. Nothing moves under reduced
|
|
12
|
+
* motion, and without script it is simply there.
|
|
13
|
+
*/
|
|
14
|
+
type Tone = 'cool' | 'accent' | 'quiet';
|
|
15
|
+
|
|
16
|
+
interface Phase {
|
|
17
|
+
/** On the band, such as "Define & validate". */
|
|
18
|
+
title: string;
|
|
19
|
+
/** Under the title on the band: what the phase is for. */
|
|
20
|
+
sub?: string;
|
|
21
|
+
/** The steps in it, as rings under the band. */
|
|
22
|
+
steps?: string[];
|
|
23
|
+
/** What happens in it, under the rings. */
|
|
24
|
+
text?: string;
|
|
25
|
+
tone?: Tone;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface Span {
|
|
29
|
+
label: string;
|
|
30
|
+
/** The first and last phase it runs across, 0 first. To the last phase by default. */
|
|
31
|
+
from: number;
|
|
32
|
+
to?: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface Props {
|
|
36
|
+
/** What the diagram is, for a screen reader: the list is named by it. */
|
|
37
|
+
title: string;
|
|
38
|
+
phases: Phase[];
|
|
39
|
+
spans?: Span[];
|
|
40
|
+
caption?: string;
|
|
41
|
+
class?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const { title, phases, spans = [], caption, class: className } = Astro.props;
|
|
45
|
+
const tones: Tone[] = ['cool', 'accent', 'quiet'];
|
|
46
|
+
const last = phases.length - 1;
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
<figure class:list={['phases', className]} data-phases>
|
|
50
|
+
<div class="plate">
|
|
51
|
+
<ol class="row" aria-label={title} style={`--n: ${phases.length}`}>
|
|
52
|
+
{
|
|
53
|
+
phases.map((p, i) => (
|
|
54
|
+
<li data-tone={p.tone ?? tones[i % tones.length]} style={`--i: ${i}`}>
|
|
55
|
+
<p class="band">
|
|
56
|
+
<strong>{p.title}</strong>
|
|
57
|
+
{p.sub && <span>{p.sub}</span>}
|
|
58
|
+
</p>
|
|
59
|
+
{p.steps && p.steps.length > 0 ? (
|
|
60
|
+
<ol class="steps">
|
|
61
|
+
{p.steps.map((s) => (
|
|
62
|
+
<li>
|
|
63
|
+
<span>{s}</span>
|
|
64
|
+
</li>
|
|
65
|
+
))}
|
|
66
|
+
</ol>
|
|
67
|
+
) : (
|
|
68
|
+
<span />
|
|
69
|
+
)}
|
|
70
|
+
{p.text ? <p class="text">{p.text}</p> : <span />}
|
|
71
|
+
</li>
|
|
72
|
+
))
|
|
73
|
+
}
|
|
74
|
+
</ol>
|
|
75
|
+
{
|
|
76
|
+
spans.length > 0 && (
|
|
77
|
+
<ul class="spans" style={`--n: ${phases.length}`}>
|
|
78
|
+
{spans.map((s) => {
|
|
79
|
+
const to = Math.min(s.to ?? last, last);
|
|
80
|
+
return (
|
|
81
|
+
<li style={`grid-column: ${s.from + 1} / ${to + 2}`}>
|
|
82
|
+
<span class="label">
|
|
83
|
+
{s.label}<span class="range">{`: ${phases[s.from].title}${to !== s.from ? ` to ${phases[to].title}` : ''}`}</span>
|
|
84
|
+
</span>
|
|
85
|
+
</li>
|
|
86
|
+
);
|
|
87
|
+
})}
|
|
88
|
+
</ul>
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
</div>
|
|
92
|
+
{caption && <figcaption>{caption}</figcaption>}
|
|
93
|
+
</figure>
|
|
94
|
+
|
|
95
|
+
<script is:inline>
|
|
96
|
+
// Before the first paint, so phases waiting to arrive never show and then vanish.
|
|
97
|
+
(() => {
|
|
98
|
+
const all = document.querySelectorAll('[data-phases]:not(.arrive):not(.seen)');
|
|
99
|
+
const fig = all[all.length - 1];
|
|
100
|
+
if (fig && 'IntersectionObserver' in window && !matchMedia('(prefers-reduced-motion: reduce)').matches) fig.classList.add('arrive');
|
|
101
|
+
})();
|
|
102
|
+
</script>
|
|
103
|
+
|
|
104
|
+
<style>
|
|
105
|
+
.phases {
|
|
106
|
+
--notch: 20px;
|
|
107
|
+
min-width: 0;
|
|
108
|
+
margin: 0;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.plate {
|
|
112
|
+
container-type: inline-size;
|
|
113
|
+
background: var(--c-surface-sunken);
|
|
114
|
+
border: 1px solid var(--c-border);
|
|
115
|
+
border-radius: var(--radius-lg);
|
|
116
|
+
padding: var(--sp-6) var(--sp-5) var(--sp-5);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/* The diagrams' tones: a tint for the band, the edge colour for the rings. */
|
|
120
|
+
[data-tone='cool'] {
|
|
121
|
+
--fill: var(--c-tag-cool-bg);
|
|
122
|
+
--mark: color-mix(in oklab, var(--c-tag-cool-text) 70%, transparent);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
[data-tone='accent'] {
|
|
126
|
+
--fill: color-mix(in oklab, var(--c-accent) 16%, var(--c-surface));
|
|
127
|
+
--mark: var(--c-accent-edge);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
[data-tone='quiet'] {
|
|
131
|
+
--fill: var(--c-surface);
|
|
132
|
+
--mark: var(--c-diagram-edge);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.row {
|
|
136
|
+
display: grid;
|
|
137
|
+
grid-template-columns: repeat(var(--n), minmax(0, 1fr));
|
|
138
|
+
grid-template-rows: auto auto auto;
|
|
139
|
+
row-gap: var(--sp-4);
|
|
140
|
+
list-style: none;
|
|
141
|
+
margin: 0;
|
|
142
|
+
padding: 0;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.row > li {
|
|
146
|
+
display: grid;
|
|
147
|
+
grid-row: span 3;
|
|
148
|
+
grid-template-rows: subgrid;
|
|
149
|
+
min-width: 0;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/* The band points on to the next; the next is cut to take the point, a hairline apart. */
|
|
153
|
+
.band {
|
|
154
|
+
display: flex;
|
|
155
|
+
flex-direction: column;
|
|
156
|
+
justify-content: center;
|
|
157
|
+
gap: 2px;
|
|
158
|
+
min-height: 64px;
|
|
159
|
+
margin: 0 calc(var(--notch) * -1 + 3px) 0 0;
|
|
160
|
+
padding: var(--sp-3) calc(var(--notch) + var(--sp-3));
|
|
161
|
+
background: var(--fill);
|
|
162
|
+
color: var(--c-text-secondary);
|
|
163
|
+
text-align: center;
|
|
164
|
+
clip-path: polygon(0 0, calc(100% - var(--notch)) 0, 100% 50%, calc(100% - var(--notch)) 100%, 0 100%, var(--notch) 50%);
|
|
165
|
+
font-size: var(--text-body-sm);
|
|
166
|
+
line-height: var(--leading-body-sm);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.row > li:first-child .band {
|
|
170
|
+
clip-path: polygon(0 0, calc(100% - var(--notch)) 0, 100% 50%, calc(100% - var(--notch)) 100%, 0 100%);
|
|
171
|
+
border-radius: 999px 0 0 999px;
|
|
172
|
+
padding-left: var(--sp-5);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.row > li:last-child .band {
|
|
176
|
+
margin-right: 0;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
.band strong {
|
|
180
|
+
color: var(--c-text);
|
|
181
|
+
font-family: var(--font-display);
|
|
182
|
+
font-weight: 600;
|
|
183
|
+
font-size: var(--text-body);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
.steps {
|
|
187
|
+
display: flex;
|
|
188
|
+
justify-content: center;
|
|
189
|
+
gap: var(--sp-3);
|
|
190
|
+
list-style: none;
|
|
191
|
+
margin: 0;
|
|
192
|
+
padding: 0 var(--sp-3);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
.steps li {
|
|
196
|
+
flex: 0 1 132px;
|
|
197
|
+
min-width: 0;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
.steps span {
|
|
201
|
+
display: grid;
|
|
202
|
+
place-items: center;
|
|
203
|
+
aspect-ratio: 1;
|
|
204
|
+
padding: var(--sp-3);
|
|
205
|
+
border: 2px solid var(--mark);
|
|
206
|
+
border-radius: 50%;
|
|
207
|
+
background: var(--c-surface);
|
|
208
|
+
color: var(--c-text);
|
|
209
|
+
font-size: var(--text-caption);
|
|
210
|
+
font-weight: 600;
|
|
211
|
+
line-height: 1.3;
|
|
212
|
+
text-align: center;
|
|
213
|
+
text-wrap: balance;
|
|
214
|
+
overflow-wrap: anywhere;
|
|
215
|
+
hyphens: auto;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
.text {
|
|
219
|
+
margin: 0;
|
|
220
|
+
padding-inline: var(--sp-3) var(--sp-4);
|
|
221
|
+
font-size: var(--text-body-sm);
|
|
222
|
+
line-height: var(--leading-body-sm);
|
|
223
|
+
color: var(--c-text-secondary);
|
|
224
|
+
text-wrap: pretty;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/* What runs across phases: a dashed line from the first to the last, the label in the middle. */
|
|
228
|
+
.spans {
|
|
229
|
+
display: grid;
|
|
230
|
+
grid-template-columns: repeat(var(--n), minmax(0, 1fr));
|
|
231
|
+
gap: var(--sp-2) 0;
|
|
232
|
+
list-style: none;
|
|
233
|
+
margin: var(--sp-5) 0 0;
|
|
234
|
+
padding: 0;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
.spans li {
|
|
238
|
+
display: flex;
|
|
239
|
+
align-items: center;
|
|
240
|
+
gap: var(--sp-3);
|
|
241
|
+
padding-inline: var(--sp-3);
|
|
242
|
+
font-size: var(--text-caption);
|
|
243
|
+
color: var(--c-text-muted);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
.spans li::before,
|
|
247
|
+
.spans li::after {
|
|
248
|
+
content: '';
|
|
249
|
+
flex: 1;
|
|
250
|
+
border-top: 1.5px dashed var(--c-diagram-line);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
.spans li::before {
|
|
254
|
+
border-left: 1.5px solid var(--c-diagram-line);
|
|
255
|
+
height: 8px;
|
|
256
|
+
margin-top: 8px;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
.spans li::after {
|
|
260
|
+
border-right: 1.5px solid var(--c-diagram-line);
|
|
261
|
+
height: 8px;
|
|
262
|
+
margin-top: 8px;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
.label {
|
|
266
|
+
white-space: nowrap;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
.range {
|
|
270
|
+
position: absolute;
|
|
271
|
+
width: 1px;
|
|
272
|
+
height: 1px;
|
|
273
|
+
overflow: hidden;
|
|
274
|
+
clip-path: inset(50%);
|
|
275
|
+
white-space: nowrap;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
figcaption {
|
|
279
|
+
margin-top: var(--sp-3);
|
|
280
|
+
font-size: var(--text-caption);
|
|
281
|
+
line-height: var(--leading-caption);
|
|
282
|
+
color: var(--c-text-muted);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
@container (max-width: 640px) {
|
|
286
|
+
.row {
|
|
287
|
+
grid-template-columns: 1fr;
|
|
288
|
+
grid-template-rows: none;
|
|
289
|
+
row-gap: var(--sp-6);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
.row > li {
|
|
293
|
+
grid-row: auto;
|
|
294
|
+
grid-template-rows: none;
|
|
295
|
+
row-gap: var(--sp-4);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
.band,
|
|
299
|
+
.row > li:first-child .band {
|
|
300
|
+
margin-right: 0;
|
|
301
|
+
clip-path: none;
|
|
302
|
+
border-radius: var(--radius-md);
|
|
303
|
+
padding-inline: var(--sp-4);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
.spans {
|
|
307
|
+
grid-template-columns: 1fr;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
.spans li {
|
|
311
|
+
grid-column: 1 !important;
|
|
312
|
+
padding: 0;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
.spans li::before,
|
|
316
|
+
.spans li::after {
|
|
317
|
+
display: none;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
.label {
|
|
321
|
+
white-space: normal;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
.range {
|
|
325
|
+
position: static;
|
|
326
|
+
width: auto;
|
|
327
|
+
height: auto;
|
|
328
|
+
overflow: visible;
|
|
329
|
+
clip-path: none;
|
|
330
|
+
white-space: normal;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
335
|
+
.arrive .row > li {
|
|
336
|
+
opacity: 0;
|
|
337
|
+
translate: 0 8px;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
.arrive.seen .row > li {
|
|
341
|
+
opacity: 1;
|
|
342
|
+
translate: 0 0;
|
|
343
|
+
transition:
|
|
344
|
+
opacity var(--motion-base) var(--ease-out) calc(var(--i) * 110ms),
|
|
345
|
+
translate var(--motion-spring) var(--ease-spring) calc(var(--i) * 110ms);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
@media (forced-colors: active) {
|
|
350
|
+
.band {
|
|
351
|
+
border: 1px solid CanvasText;
|
|
352
|
+
clip-path: none;
|
|
353
|
+
margin-right: 0;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
.steps span {
|
|
357
|
+
border-color: CanvasText;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
</style>
|
|
361
|
+
|
|
362
|
+
<script>
|
|
363
|
+
// Once, as it comes into view, the phases arrive left to right.
|
|
364
|
+
const seen = new IntersectionObserver(
|
|
365
|
+
(entries) => {
|
|
366
|
+
entries
|
|
367
|
+
.filter((e) => e.isIntersecting)
|
|
368
|
+
.forEach((e) => {
|
|
369
|
+
e.target.classList.add('seen');
|
|
370
|
+
seen.unobserve(e.target);
|
|
371
|
+
});
|
|
372
|
+
},
|
|
373
|
+
{ threshold: 0.3 },
|
|
374
|
+
);
|
|
375
|
+
document.querySelectorAll('[data-phases].arrive').forEach((fig) => seen.observe(fig));
|
|
376
|
+
</script>
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* The sections of one long page, as a list that stays in view beside the text: where you are is
|
|
4
|
+
* marked, and any section is one click or one Tab away. For a case study or a long read, in the
|
|
5
|
+
* margin beside the reading column.
|
|
6
|
+
*
|
|
7
|
+
* It finds where you are from the headings its links point to: the last one above the top third of
|
|
8
|
+
* the window is current, and its link gets `aria-current="location"`. That changes as you scroll,
|
|
9
|
+
* many times a minute, so it changes at once rather than gliding. Before the first heading nothing
|
|
10
|
+
* is current. Without script it is a plain list of links.
|
|
11
|
+
*
|
|
12
|
+
* The page places it: it is sticky inside whatever holds it, so give it a column or a margin that
|
|
13
|
+
* runs the length of the text. It never hides itself, so it is always in the tab order.
|
|
14
|
+
*/
|
|
15
|
+
interface Item {
|
|
16
|
+
/** The heading's id, with or without the #. */
|
|
17
|
+
href: string;
|
|
18
|
+
text: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface Props {
|
|
22
|
+
items: Item[];
|
|
23
|
+
/** Names the navigation for a screen reader. */
|
|
24
|
+
label?: string;
|
|
25
|
+
/** A short visible title above the list, such as "Contents". None by default. */
|
|
26
|
+
title?: string;
|
|
27
|
+
id?: string;
|
|
28
|
+
class?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const { items, label = 'Sections', title, id, class: className } = Astro.props;
|
|
32
|
+
const hash = (h: string) => (h.startsWith('#') ? h : `#${h}`);
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
<nav id={id} class:list={['section-nav', className]} aria-label={label} data-section-nav>
|
|
36
|
+
{title && <p class="title" aria-hidden="true">{title}</p>}
|
|
37
|
+
<ol>
|
|
38
|
+
{
|
|
39
|
+
items.map((item) => (
|
|
40
|
+
<li>
|
|
41
|
+
<a href={hash(item.href)}>{item.text}</a>
|
|
42
|
+
</li>
|
|
43
|
+
))
|
|
44
|
+
}
|
|
45
|
+
</ol>
|
|
46
|
+
</nav>
|
|
47
|
+
|
|
48
|
+
<style>
|
|
49
|
+
.section-nav {
|
|
50
|
+
position: sticky;
|
|
51
|
+
top: var(--section-nav-top, var(--sp-8));
|
|
52
|
+
max-height: calc(100dvh - var(--section-nav-top, var(--sp-8)) - var(--sp-5));
|
|
53
|
+
overflow-y: auto;
|
|
54
|
+
overscroll-behavior: contain;
|
|
55
|
+
font-size: var(--text-body-sm);
|
|
56
|
+
line-height: var(--leading-body-sm);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.title {
|
|
60
|
+
margin: 0 0 var(--sp-3);
|
|
61
|
+
font-size: var(--text-overline);
|
|
62
|
+
line-height: var(--leading-overline);
|
|
63
|
+
letter-spacing: var(--tracking-overline);
|
|
64
|
+
text-transform: uppercase;
|
|
65
|
+
color: var(--c-text-muted);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
ol {
|
|
69
|
+
list-style: none;
|
|
70
|
+
margin: 0;
|
|
71
|
+
padding: 0;
|
|
72
|
+
border-left: 1px solid var(--c-border);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
a {
|
|
76
|
+
display: block;
|
|
77
|
+
margin-left: -1px;
|
|
78
|
+
padding: var(--sp-1) 0 var(--sp-1) var(--sp-4);
|
|
79
|
+
border-left: 2px solid transparent;
|
|
80
|
+
background: none;
|
|
81
|
+
color: var(--c-text-muted);
|
|
82
|
+
text-decoration: none;
|
|
83
|
+
text-wrap: pretty;
|
|
84
|
+
transition: color var(--motion-hover) var(--ease-hover);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
a:hover {
|
|
88
|
+
color: var(--c-text);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/* Where you are: the text at full strength and the accent bar on the rule. */
|
|
92
|
+
a[aria-current] {
|
|
93
|
+
color: var(--c-text);
|
|
94
|
+
font-weight: 600;
|
|
95
|
+
border-left-color: var(--c-accent);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
a:focus-visible {
|
|
99
|
+
outline: 2px solid var(--c-focus);
|
|
100
|
+
outline-offset: 2px;
|
|
101
|
+
border-radius: var(--radius-sm);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
@media (forced-colors: active) {
|
|
105
|
+
a[aria-current] {
|
|
106
|
+
border-left-color: CanvasText;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
</style>
|
|
110
|
+
|
|
111
|
+
<script>
|
|
112
|
+
document.querySelectorAll<HTMLElement>('[data-section-nav]').forEach((nav) => {
|
|
113
|
+
const links = [...nav.querySelectorAll<HTMLAnchorElement>('a[href^="#"]')];
|
|
114
|
+
const heads = links.map((a) => document.getElementById(decodeURIComponent(a.hash.slice(1))));
|
|
115
|
+
let current = -2;
|
|
116
|
+
const update = () => {
|
|
117
|
+
let now = -1;
|
|
118
|
+
heads.forEach((h, i) => {
|
|
119
|
+
if (h && h.getBoundingClientRect().top < innerHeight * 0.3) now = i;
|
|
120
|
+
});
|
|
121
|
+
if (now === current) return;
|
|
122
|
+
current = now;
|
|
123
|
+
links.forEach((a, i) => (i === now ? a.setAttribute('aria-current', 'location') : a.removeAttribute('aria-current')));
|
|
124
|
+
// Keep the current link in view when the list is taller than the window. The list scrolls
|
|
125
|
+
// itself; the page never moves for it.
|
|
126
|
+
const a = links[now];
|
|
127
|
+
if (a && nav.scrollHeight > nav.clientHeight) {
|
|
128
|
+
if (a.offsetTop < nav.scrollTop) nav.scrollTop = a.offsetTop - 8;
|
|
129
|
+
else if (a.offsetTop + a.offsetHeight > nav.scrollTop + nav.clientHeight) nav.scrollTop = a.offsetTop + a.offsetHeight - nav.clientHeight + 8;
|
|
130
|
+
}
|
|
131
|
+
nav.dispatchEvent(new CustomEvent('section-change', { detail: { index: now }, bubbles: true }));
|
|
132
|
+
};
|
|
133
|
+
let queued = false;
|
|
134
|
+
addEventListener(
|
|
135
|
+
'scroll',
|
|
136
|
+
() => {
|
|
137
|
+
if (queued) return;
|
|
138
|
+
queued = true;
|
|
139
|
+
requestAnimationFrame(() => {
|
|
140
|
+
queued = false;
|
|
141
|
+
update();
|
|
142
|
+
});
|
|
143
|
+
},
|
|
144
|
+
{ passive: true },
|
|
145
|
+
);
|
|
146
|
+
addEventListener('resize', update, { passive: true });
|
|
147
|
+
update();
|
|
148
|
+
});
|
|
149
|
+
</script>
|