@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.
@@ -0,0 +1,363 @@
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 HTML, so the words are text that wraps and is read out in order. Below 640px wide the
8
+ * phases stack and each span says which phases it runs across in words. The bands use three
9
+ * fixed tones with the dark text on them, so they read the same in either theme.
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' | 'sun';
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', 'sun'];
46
+ const last = phases.length - 1;
47
+ ---
48
+
49
+ <figure class:list={['phases', className]} data-phases>
50
+ <ol class="row" aria-label={title} style={`--n: ${phases.length}`}>
51
+ {
52
+ phases.map((p, i) => (
53
+ <li data-tone={p.tone ?? tones[i % tones.length]} style={`--i: ${i}`}>
54
+ <p class="band">
55
+ <strong>{p.title}</strong>
56
+ {p.sub && <span>{p.sub}</span>}
57
+ </p>
58
+ {p.steps && p.steps.length > 0 ? (
59
+ <ol class="steps">
60
+ {p.steps.map((s) => (
61
+ <li>
62
+ <span>{s}</span>
63
+ </li>
64
+ ))}
65
+ </ol>
66
+ ) : (
67
+ <span />
68
+ )}
69
+ {p.text ? <p class="text">{p.text}</p> : <span />}
70
+ </li>
71
+ ))
72
+ }
73
+ </ol>
74
+ {
75
+ spans.length > 0 && (
76
+ <ul class="spans" style={`--n: ${phases.length}`}>
77
+ {spans.map((s) => {
78
+ const to = Math.min(s.to ?? last, last);
79
+ return (
80
+ <li style={`grid-column: ${s.from + 1} / ${to + 2}`}>
81
+ <span class="label">
82
+ {s.label}<span class="range">{`: ${phases[s.from].title}${to !== s.from ? ` to ${phases[to].title}` : ''}`}</span>
83
+ </span>
84
+ </li>
85
+ );
86
+ })}
87
+ </ul>
88
+ )
89
+ }
90
+ {caption && <figcaption>{caption}</figcaption>}
91
+ </figure>
92
+
93
+ <script is:inline>
94
+ // Before the first paint, so phases waiting to arrive never show and then vanish.
95
+ (() => {
96
+ const all = document.querySelectorAll('[data-phases]:not(.arrive):not(.seen)');
97
+ const fig = all[all.length - 1];
98
+ if (fig && 'IntersectionObserver' in window && !matchMedia('(prefers-reduced-motion: reduce)').matches) fig.classList.add('arrive');
99
+ })();
100
+ </script>
101
+
102
+ <style>
103
+ .phases {
104
+ --notch: 22px;
105
+ min-width: 0;
106
+ margin: 0;
107
+ container-type: inline-size;
108
+ }
109
+
110
+ [data-tone='cool'] {
111
+ --tone: var(--c-seq2-4);
112
+ }
113
+
114
+ [data-tone='accent'] {
115
+ --tone: var(--c-accent);
116
+ }
117
+
118
+ [data-tone='sun'] {
119
+ --tone: var(--c-heat-4);
120
+ }
121
+
122
+ .row {
123
+ display: grid;
124
+ grid-template-columns: repeat(var(--n), minmax(0, 1fr));
125
+ grid-template-rows: auto auto auto;
126
+ row-gap: var(--sp-4);
127
+ list-style: none;
128
+ margin: 0;
129
+ padding: 0;
130
+ }
131
+
132
+ .row > li {
133
+ display: grid;
134
+ grid-row: span 3;
135
+ grid-template-rows: subgrid;
136
+ min-width: 0;
137
+ }
138
+
139
+ /* The band points on to the next; the next is cut to take the point, a hairline apart. */
140
+ .band {
141
+ display: flex;
142
+ flex-direction: column;
143
+ justify-content: center;
144
+ gap: 2px;
145
+ min-height: 64px;
146
+ margin: 0 calc(var(--notch) * -1 + 3px) 0 0;
147
+ padding: var(--sp-3) calc(var(--notch) + var(--sp-3));
148
+ background: var(--tone);
149
+ color: var(--c-on-accent);
150
+ text-align: center;
151
+ clip-path: polygon(0 0, calc(100% - var(--notch)) 0, 100% 50%, calc(100% - var(--notch)) 100%, 0 100%, var(--notch) 50%);
152
+ font-size: var(--text-body-sm);
153
+ line-height: var(--leading-body-sm);
154
+ }
155
+
156
+ .row > li:first-child .band {
157
+ clip-path: polygon(0 0, calc(100% - var(--notch)) 0, 100% 50%, calc(100% - var(--notch)) 100%, 0 100%);
158
+ border-radius: 999px 0 0 999px;
159
+ padding-left: var(--sp-5);
160
+ }
161
+
162
+ .row > li:last-child .band {
163
+ margin-right: 0;
164
+ }
165
+
166
+ .band strong {
167
+ color: inherit;
168
+ font-family: var(--font-display);
169
+ font-weight: 600;
170
+ font-size: var(--text-body);
171
+ }
172
+
173
+ .steps {
174
+ display: flex;
175
+ justify-content: center;
176
+ gap: var(--sp-3);
177
+ list-style: none;
178
+ margin: 0;
179
+ padding: 0 var(--sp-3);
180
+ }
181
+
182
+ .steps li {
183
+ flex: 0 1 132px;
184
+ min-width: 0;
185
+ }
186
+
187
+ .steps span {
188
+ display: grid;
189
+ place-items: center;
190
+ aspect-ratio: 1;
191
+ padding: var(--sp-3);
192
+ border: 5px solid var(--tone);
193
+ border-radius: 50%;
194
+ background: var(--c-surface);
195
+ color: var(--c-text);
196
+ font-size: var(--text-caption);
197
+ font-weight: 600;
198
+ line-height: 1.3;
199
+ text-align: center;
200
+ text-wrap: balance;
201
+ overflow-wrap: anywhere;
202
+ hyphens: auto;
203
+ }
204
+
205
+ .text {
206
+ margin: 0;
207
+ padding-inline: var(--sp-3) var(--sp-4);
208
+ font-size: var(--text-body-sm);
209
+ line-height: var(--leading-body-sm);
210
+ color: var(--c-text-secondary);
211
+ text-wrap: pretty;
212
+ }
213
+
214
+ /* What runs across phases: a dashed line from the first to the last, the label in the middle. */
215
+ .spans {
216
+ display: grid;
217
+ grid-template-columns: repeat(var(--n), minmax(0, 1fr));
218
+ gap: var(--sp-2) 0;
219
+ list-style: none;
220
+ margin: var(--sp-5) 0 0;
221
+ padding: 0;
222
+ }
223
+
224
+ .spans li {
225
+ display: flex;
226
+ align-items: center;
227
+ gap: var(--sp-3);
228
+ padding-inline: var(--sp-3);
229
+ font-size: var(--text-caption);
230
+ color: var(--c-text-muted);
231
+ }
232
+
233
+ .spans li::before,
234
+ .spans li::after {
235
+ content: '';
236
+ flex: 1;
237
+ border-top: 1.5px dashed var(--c-border-strong);
238
+ }
239
+
240
+ .spans li::before {
241
+ border-left: 1.5px solid var(--c-border-strong);
242
+ height: 8px;
243
+ margin-top: 8px;
244
+ }
245
+
246
+ .spans li::after {
247
+ border-right: 1.5px solid var(--c-border-strong);
248
+ height: 8px;
249
+ margin-top: 8px;
250
+ }
251
+
252
+ .label {
253
+ white-space: nowrap;
254
+ }
255
+
256
+ .range {
257
+ position: absolute;
258
+ width: 1px;
259
+ height: 1px;
260
+ overflow: hidden;
261
+ clip-path: inset(50%);
262
+ white-space: nowrap;
263
+ }
264
+
265
+ figcaption {
266
+ margin-top: var(--sp-5);
267
+ font-size: var(--text-caption);
268
+ line-height: var(--leading-caption);
269
+ color: var(--c-text-muted);
270
+ }
271
+
272
+ @container (max-width: 640px) {
273
+ .row {
274
+ grid-template-columns: 1fr;
275
+ grid-template-rows: none;
276
+ row-gap: var(--sp-6);
277
+ }
278
+
279
+ .row > li {
280
+ grid-row: auto;
281
+ grid-template-rows: none;
282
+ row-gap: var(--sp-4);
283
+ }
284
+
285
+ .band,
286
+ .row > li:first-child .band {
287
+ margin-right: 0;
288
+ clip-path: none;
289
+ border-radius: var(--radius-md);
290
+ padding-inline: var(--sp-4);
291
+ }
292
+
293
+ .spans {
294
+ grid-template-columns: 1fr;
295
+ }
296
+
297
+ .spans li {
298
+ grid-column: 1 !important;
299
+ padding: 0;
300
+ }
301
+
302
+ .spans li::before,
303
+ .spans li::after {
304
+ display: none;
305
+ }
306
+
307
+ .label {
308
+ white-space: normal;
309
+ }
310
+
311
+ .range {
312
+ position: static;
313
+ width: auto;
314
+ height: auto;
315
+ overflow: visible;
316
+ clip-path: none;
317
+ white-space: normal;
318
+ }
319
+ }
320
+
321
+ @media (prefers-reduced-motion: no-preference) {
322
+ .arrive .row > li {
323
+ opacity: 0;
324
+ translate: 0 8px;
325
+ }
326
+
327
+ .arrive.seen .row > li {
328
+ opacity: 1;
329
+ translate: 0 0;
330
+ transition:
331
+ opacity var(--motion-base) var(--ease-out) calc(var(--i) * 110ms),
332
+ translate var(--motion-spring) var(--ease-spring) calc(var(--i) * 110ms);
333
+ }
334
+ }
335
+
336
+ @media (forced-colors: active) {
337
+ .band {
338
+ border: 1px solid CanvasText;
339
+ clip-path: none;
340
+ margin-right: 0;
341
+ }
342
+
343
+ .steps span {
344
+ border-color: CanvasText;
345
+ }
346
+ }
347
+ </style>
348
+
349
+ <script>
350
+ // Once, as it comes into view, the phases arrive left to right.
351
+ const seen = new IntersectionObserver(
352
+ (entries) => {
353
+ entries
354
+ .filter((e) => e.isIntersecting)
355
+ .forEach((e) => {
356
+ e.target.classList.add('seen');
357
+ seen.unobserve(e.target);
358
+ });
359
+ },
360
+ { threshold: 0.3 },
361
+ );
362
+ document.querySelectorAll('[data-phases].arrive').forEach((fig) => seen.observe(fig));
363
+ </script>
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
 
@@ -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>
@@ -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) {