@n1kname/components 0.56.0 → 0.57.1

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.56.0",
3
+ "version": "0.57.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -0,0 +1,329 @@
1
+ ---
2
+ /**
3
+ * A few things side by side as cards, each with an icon disc and a name, and short labelled notes
4
+ * under it. A note can say what something gives (a check), what it misses (a crossed-out eye, in a
5
+ * dashed box), or a before and an after with an arrow between them. For the comparisons a table
6
+ * would otherwise carry: sources of evidence, a problem and the rule it became, one thing split in
7
+ * three.
8
+ *
9
+ * Drawn in the diagrams' style: tinted icon discs with an edge, as in Flow diagram, on surface
10
+ * cards. A list of cards, each a description list, so it reads in order. Two columns by default;
11
+ * below 560px wide the cards stack.
12
+ *
13
+ * Once, as it comes into view, the cards rise in one after another. Nothing moves under reduced
14
+ * motion, and without script it is simply there.
15
+ */
16
+ import Icon from './Icon.astro';
17
+ import type { IconName } from './icons';
18
+
19
+ type Tone = 'accent' | 'cool' | 'quiet';
20
+ type Mark = 'gain' | 'gap' | 'before' | 'after' | 'plain';
21
+
22
+ interface Note {
23
+ /** "What it gave us". */
24
+ label: string;
25
+ text: string;
26
+ /** How the note is drawn. Plain by default. */
27
+ mark?: Mark;
28
+ }
29
+
30
+ interface Card {
31
+ title: string;
32
+ /** Under the title, a few words. */
33
+ kicker?: string;
34
+ icon?: IconName;
35
+ tone?: Tone;
36
+ notes: Note[];
37
+ }
38
+
39
+ interface Props {
40
+ /** What the cards compare, for a screen reader: the list is named by it. */
41
+ title: string;
42
+ cards: Card[];
43
+ /** Cards per row where there is room: 1 to 4. */
44
+ columns?: number;
45
+ caption?: string;
46
+ class?: string;
47
+ }
48
+
49
+ const { title, cards, columns = 2, caption, class: className } = Astro.props;
50
+ const tones: Tone[] = ['accent', 'cool'];
51
+ const markIcon: Partial<Record<Mark, IconName>> = { gain: 'circle-check', gap: 'eye-off' };
52
+ ---
53
+
54
+ <figure class:list={['compare-cards', className]} data-compare-cards>
55
+ <ul class="cards" aria-label={title} style={`--cols: ${Math.min(4, Math.max(1, columns))}`}>
56
+ {
57
+ cards.map((card, i) => (
58
+ <li class="card" data-tone={card.tone ?? tones[i % tones.length]} style={`--i: ${i}`}>
59
+ <div class="head">
60
+ <span class="disc" aria-hidden="true">
61
+ {card.icon ? <Icon name={card.icon} size={22} /> : <span class="num">{i + 1}</span>}
62
+ </span>
63
+ <div>
64
+ <h3 class="title">{card.title}</h3>
65
+ {card.kicker && <p class="kicker">{card.kicker}</p>}
66
+ </div>
67
+ </div>
68
+ <dl>
69
+ {card.notes.map((n, k) => {
70
+ const mark = n.mark ?? 'plain';
71
+ const icon = markIcon[mark];
72
+ const turn = mark === 'after' && card.notes[k - 1]?.mark === 'before';
73
+ return (
74
+ <div class:list={['note', mark, { turn }]}>
75
+ <dt>
76
+ {icon && <Icon name={icon} size={15} />}
77
+ {n.label}
78
+ </dt>
79
+ <dd>{n.text}</dd>
80
+ </div>
81
+ );
82
+ })}
83
+ </dl>
84
+ </li>
85
+ ))
86
+ }
87
+ </ul>
88
+ {caption && <figcaption>{caption}</figcaption>}
89
+ </figure>
90
+
91
+ <script is:inline>
92
+ // Before the first paint, so cards waiting to arrive never show and then vanish.
93
+ (() => {
94
+ const all = document.querySelectorAll('[data-compare-cards]:not(.arrive)');
95
+ const fig = all[all.length - 1];
96
+ if (!fig || !('IntersectionObserver' in window) || matchMedia('(prefers-reduced-motion: reduce)').matches) return;
97
+ fig.classList.add('arrive');
98
+ const io = new IntersectionObserver(
99
+ (entries) => {
100
+ for (const e of entries) {
101
+ if (!e.isIntersecting) continue;
102
+ e.target.classList.add('in');
103
+ io.unobserve(e.target);
104
+ }
105
+ },
106
+ { rootMargin: '0px 0px -15% 0px' },
107
+ );
108
+ io.observe(fig);
109
+ })();
110
+ </script>
111
+
112
+ <style>
113
+ .compare-cards {
114
+ min-width: 0;
115
+ margin: var(--sp-7) 0;
116
+ container-type: inline-size;
117
+ }
118
+
119
+ [data-tone='accent'] {
120
+ --edge: var(--c-accent-edge);
121
+ --soft: var(--c-surface-tint);
122
+ --mark: var(--c-accent);
123
+ }
124
+
125
+ [data-tone='cool'] {
126
+ --edge: color-mix(in oklab, var(--c-tag-cool-text) 55%, transparent);
127
+ --soft: var(--c-tag-cool-bg);
128
+ --mark: var(--c-tag-cool-text);
129
+ }
130
+
131
+ [data-tone='quiet'] {
132
+ --edge: var(--c-diagram-edge);
133
+ --soft: var(--c-surface);
134
+ --mark: var(--c-text-secondary);
135
+ }
136
+
137
+ .cards {
138
+ display: grid;
139
+ grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
140
+ gap: var(--sp-4);
141
+ margin: 0;
142
+ padding: 0;
143
+ list-style: none;
144
+ }
145
+
146
+ @container (max-width: 560px) {
147
+ .cards {
148
+ grid-template-columns: minmax(0, 1fr);
149
+ }
150
+ }
151
+
152
+ .card {
153
+ display: flex;
154
+ flex-direction: column;
155
+ gap: var(--sp-4);
156
+ min-width: 0;
157
+ margin: 0;
158
+ padding: var(--sp-5);
159
+ background: var(--c-surface);
160
+ border: 1px solid var(--c-border);
161
+ border-radius: var(--radius-lg);
162
+ }
163
+
164
+ .head {
165
+ display: flex;
166
+ gap: var(--sp-3);
167
+ align-items: center;
168
+ }
169
+
170
+ .disc {
171
+ flex: none;
172
+ display: grid;
173
+ place-items: center;
174
+ width: 44px;
175
+ height: 44px;
176
+ border-radius: 50%;
177
+ background: var(--soft);
178
+ border: 1.5px solid var(--edge);
179
+ color: var(--mark);
180
+ }
181
+
182
+ .num {
183
+ font-weight: 600;
184
+ font-size: var(--text-body);
185
+ }
186
+
187
+ .title {
188
+ margin: 0;
189
+ font-family: var(--font-display);
190
+ font-weight: 600;
191
+ font-size: var(--text-sub);
192
+ line-height: var(--leading-sub);
193
+ color: var(--c-text);
194
+ }
195
+
196
+ .kicker {
197
+ margin: 0;
198
+ font-size: var(--text-caption);
199
+ color: var(--c-text-muted);
200
+ }
201
+
202
+ dl {
203
+ display: flex;
204
+ flex-direction: column;
205
+ gap: var(--sp-3);
206
+ margin: 0;
207
+ }
208
+
209
+ .note {
210
+ position: relative;
211
+ }
212
+
213
+ dt {
214
+ display: flex;
215
+ gap: 6px;
216
+ align-items: center;
217
+ margin-bottom: 2px;
218
+ font-size: var(--text-caption);
219
+ font-weight: 600;
220
+ color: var(--c-text-secondary);
221
+ }
222
+
223
+ dd {
224
+ margin: 0;
225
+ font-size: var(--text-body-sm);
226
+ line-height: var(--leading-body-sm);
227
+ color: var(--c-text);
228
+ text-wrap: pretty;
229
+ }
230
+
231
+ /* What a source gives: a tinted box with a check, against the dashed box of what it misses. */
232
+ .gain {
233
+ padding: var(--sp-2) var(--sp-3);
234
+ background: color-mix(in oklab, var(--soft) 60%, var(--c-surface));
235
+ border: 1px solid var(--edge);
236
+ border-radius: var(--radius-md);
237
+ }
238
+
239
+ .gain dt :global(svg) {
240
+ color: var(--mark);
241
+ }
242
+
243
+ /* What a source can't see: a dashed box, the text a step quieter. */
244
+ .gap {
245
+ padding: var(--sp-2) var(--sp-3);
246
+ border: 1px dashed var(--c-border-strong);
247
+ border-radius: var(--radius-md);
248
+ }
249
+
250
+ .gap dd {
251
+ color: var(--c-text-secondary);
252
+ }
253
+
254
+ /* A before and an after: two tinted boxes with an arrow down between them, centred. */
255
+ .before,
256
+ .after {
257
+ padding: var(--sp-2) var(--sp-3);
258
+ border-radius: var(--radius-md);
259
+ }
260
+
261
+ .before {
262
+ background: color-mix(in oklab, var(--c-status-critical) 10%, var(--c-surface));
263
+ border: 1px solid color-mix(in oklab, var(--c-status-critical) 40%, transparent);
264
+ }
265
+
266
+ .after {
267
+ background: var(--soft);
268
+ border: 1px solid var(--edge);
269
+ }
270
+
271
+ .turn {
272
+ margin-top: var(--sp-3);
273
+ }
274
+
275
+ .turn::before {
276
+ content: '';
277
+ position: absolute;
278
+ left: calc(50% - 0.75px);
279
+ top: calc(-1 * var(--sp-3) - var(--sp-3));
280
+ width: 1.5px;
281
+ height: calc(var(--sp-3) * 2);
282
+ background: var(--c-diagram-line);
283
+ }
284
+
285
+ .turn::after {
286
+ content: '';
287
+ position: absolute;
288
+ left: calc(50% - 3.5px);
289
+ top: -10px;
290
+ width: 7px;
291
+ height: 7px;
292
+ border-right: 1.5px solid var(--c-diagram-line);
293
+ border-bottom: 1.5px solid var(--c-diagram-line);
294
+ rotate: 45deg;
295
+ }
296
+
297
+ figcaption {
298
+ margin-top: var(--sp-3);
299
+ font-size: var(--text-caption);
300
+ line-height: var(--leading-caption);
301
+ color: var(--c-text-muted);
302
+ }
303
+
304
+ /* Arriving: the cards rise in, 90ms apart. */
305
+ .arrive .card {
306
+ opacity: 0;
307
+ translate: 0 12px;
308
+ }
309
+
310
+ .arrive.in .card {
311
+ opacity: 1;
312
+ translate: 0 0;
313
+ transition:
314
+ opacity var(--motion-reveal, 500ms) var(--ease-out),
315
+ translate var(--motion-reveal, 500ms) var(--ease-out);
316
+ transition-delay: calc(var(--i) * 90ms);
317
+ }
318
+
319
+ @media (forced-colors: active) {
320
+ .disc,
321
+ .card,
322
+ .before,
323
+ .after,
324
+ .gain,
325
+ .gap {
326
+ border-color: CanvasText;
327
+ }
328
+ }
329
+ </style>
@@ -170,7 +170,8 @@ const longest = (pts: [number, number][]): [number, number] => {
170
170
  const len = Math.hypot(pts[i][0] - pts[i - 1][0], pts[i][1] - pts[i - 1][1]);
171
171
  if (len > best) {
172
172
  best = len;
173
- at = [(pts[i][0] + pts[i - 1][0]) / 2, (pts[i][1] + pts[i - 1][1]) / 2 - 10];
173
+ // On the line: the label's pill is centred on it (the text's baseline sits 4.5px below).
174
+ at = [(pts[i][0] + pts[i - 1][0]) / 2, (pts[i][1] + pts[i - 1][1]) / 2 + 4.5];
174
175
  }
175
176
  }
176
177
  return at;
@@ -205,6 +206,10 @@ const views = [
205
206
  : []),
206
207
  ];
207
208
 
209
+ // A label's pill: wide enough for its text at 13px semibold, with room either side. Measured
210
+ // from the font's average glyph, so it never needs the page to lay out first.
211
+ const chipWidth = (label: string) => Math.round(label.length * 7.1 + 20);
212
+
208
213
  // Label lines for a circle: break at the space nearest the middle when it is long.
209
214
  const lines = (label: string) => {
210
215
  if (label.length <= 10 || !label.includes(' ')) return [label];
@@ -238,11 +243,6 @@ const lines = (label: string) => {
238
243
  <g class:list={['edge', e.tone]} data-step={e.step}>
239
244
  <path class="line" d={e.d} pathLength="1" />
240
245
  <path class="head" d={e.head} />
241
- {e.label && (
242
- <text class="edge-label" x={e.at[0]} y={e.at[1]}>
243
- {e.label}
244
- </text>
245
- )}
246
246
  {e.flow && (
247
247
  <circle class="pulse" r="3.5">
248
248
  <animateMotion dur="2.8s" begin="indefinite" repeatCount="indefinite" keyPoints="0;1;1" keyTimes="0;0.7;1" calcMode="linear" path={e.d} />
@@ -253,6 +253,23 @@ const lines = (label: string) => {
253
253
  }
254
254
  </g>
255
255
 
256
+ {/* Labels above every line, so no line or pulse crosses a label's pill. */}
257
+ <g class="labels">
258
+ {
259
+ drawn.map(
260
+ (e) =>
261
+ e.label && (
262
+ <g class:list={['edge-label', e.tone]} data-step={e.step}>
263
+ <rect class="chip" x={e.at[0] - chipWidth(e.label) / 2} y={e.at[1] - 15.5} width={chipWidth(e.label)} height="22" rx="11" />
264
+ <text x={e.at[0]} y={e.at[1]}>
265
+ {e.label}
266
+ </text>
267
+ </g>
268
+ ),
269
+ )
270
+ }
271
+ </g>
272
+
256
273
  {
257
274
  nodes.map((n) => {
258
275
  const { w, h } = size(n);
@@ -475,20 +492,38 @@ const lines = (label: string) => {
475
492
  stroke: var(--c-tag-cool-text);
476
493
  }
477
494
 
478
- .edge-label {
495
+ /* An edge's label sits in a pill on its line, so the line runs under it, never through the
496
+ * words. The pill is the page's background with a little of the line's colour in it. */
497
+ .edge-label text {
479
498
  font-size: 13px;
480
499
  font-weight: 600;
481
500
  fill: var(--c-text-muted);
482
501
  }
483
502
 
484
- .edge.accent .edge-label {
503
+ .chip {
504
+ fill: color-mix(in oklab, var(--c-diagram-line) 10%, var(--c-bg));
505
+ stroke: color-mix(in oklab, var(--c-diagram-line) 45%, transparent);
506
+ stroke-width: 1;
507
+ }
508
+
509
+ .edge-label.accent text {
485
510
  fill: var(--c-text-accent);
486
511
  }
487
512
 
488
- .edge.cool .edge-label {
513
+ .edge-label.accent .chip {
514
+ fill: color-mix(in oklab, var(--c-accent) 12%, var(--c-bg));
515
+ stroke: var(--c-accent-edge);
516
+ }
517
+
518
+ .edge-label.cool text {
489
519
  fill: var(--c-tag-cool-text);
490
520
  }
491
521
 
522
+ .edge-label.cool .chip {
523
+ fill: color-mix(in oklab, var(--c-tag-cool-text) 12%, var(--c-bg));
524
+ stroke: color-mix(in oklab, var(--c-tag-cool-text) 45%, transparent);
525
+ }
526
+
492
527
  .pulse {
493
528
  fill: var(--c-diagram-line);
494
529
  opacity: 0;
@@ -551,7 +586,7 @@ const lines = (label: string) => {
551
586
  }
552
587
 
553
588
  .in .edge .head,
554
- .in .edge .edge-label {
589
+ .in .edge-label {
555
590
  animation: land calc(var(--motion-grow, 700ms) * 0.45) var(--ease-out) calc(var(--d, 0ms) + var(--motion-grow, 700ms) * 0.8) both;
556
591
  }
557
592
 
@@ -603,4 +638,11 @@ const lines = (label: string) => {
603
638
  color: var(--c-text-muted);
604
639
  max-width: var(--layout-measure);
605
640
  }
641
+
642
+ @media (forced-colors: active) {
643
+ .chip {
644
+ fill: Canvas;
645
+ stroke: CanvasText;
646
+ }
647
+ }
606
648
  </style>
package/src/icons.ts CHANGED
@@ -29,6 +29,9 @@ export const ICONS = {
29
29
  headphones:
30
30
  '<path d="M3 14h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-7a9 9 0 0 1 18 0v7a2 2 0 0 1-2 2h-1a2 2 0 0 1-2-2v-3a2 2 0 0 1 2-2h3"/>',
31
31
  search: '<circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/>',
32
+ // What a source can't see, in Compare cards.
33
+ 'eye-off':
34
+ '<path d="M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49"/><path d="M14.084 14.158a3 3 0 0 1-4.242-4.242"/><path d="M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143"/><path d="m2 2 20 20"/>',
32
35
  'trending-up':
33
36
  '<polyline points="22 7 13.5 15.5 8.5 10.5 2 17"/><polyline points="16 7 22 7 22 13"/>',
34
37
  'shield-check':