@n1kname/components 0.25.0 → 0.27.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.25.0",
3
+ "version": "0.27.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -67,12 +67,12 @@ const rounded = (pts: [number, number][], radii: number[]) =>
67
67
  return `${i ? 'L' : 'M'}${a[0]} ${a[1]} Q${p[0]} ${p[1]} ${b[0]} ${b[1]}`;
68
68
  })
69
69
  .join(' ') + ' Z';
70
- const big = rounded([[1, 60], [100, 1], [199, 60], [100, 119]], [5, 16, 5, 16]);
70
+ const big = rounded([[1, 70], [100, 1], [199, 70], [100, 139]], [5, 16, 5, 16]);
71
71
  const small = (x: number) => rounded([[x + 4, 50], [x + 50, 18], [x + 96, 50], [x + 50, 82]], [3, 9, 3, 9]);
72
72
  let hash = 0;
73
73
  for (const c of title) hash = (hash * 31 + c.charCodeAt(0)) | 0;
74
74
  const uid = `dia-${(hash >>> 0).toString(36)}`;
75
- const columns = items.map((it) => (it.kind === 'moment' ? 'auto' : it.phase.repeat ? 'minmax(0, 0.75fr)' : 'minmax(0, 1fr)')).join(' ');
75
+ const columns = items.map((it) => (it.kind === 'moment' ? 'minmax(4.5rem, auto)' : it.phase.repeat ? 'minmax(0, 0.75fr)' : 'minmax(0, 1fr)')).join(' ');
76
76
  ---
77
77
 
78
78
  <figure class:list={['diamonds', className]} data-diamonds>
@@ -102,27 +102,28 @@ const columns = items.map((it) => (it.kind === 'moment' ? 'auto' : it.phase.repe
102
102
  <rect class="close" x={k * 100 + 50} y="0" width="50" height="100" />
103
103
  </g>
104
104
  <path class="edge" d={small(k * 100)} vector-effect="non-scaling-stroke" />
105
+ {k < 2 && <line class="link" x1={k * 100 + 97} y1="50" x2={k * 100 + 103} y2="50" vector-effect="non-scaling-stroke" />}
105
106
  </g>
106
107
  ))}
107
108
  </svg>
108
109
  ) : (
109
110
  <>
110
- <svg viewBox="0 0 200 120" aria-hidden="true">
111
+ <svg viewBox="0 0 200 140" aria-hidden="true">
111
112
  <clipPath id={`${uid}-${i}`}>
112
113
  <path d={big} />
113
114
  </clipPath>
114
115
  <g clip-path={`url(#${uid}-${i})`}>
115
- <rect class="open" x="0" y="0" width="100" height="120" />
116
- <rect class="close" x="100" y="0" width="100" height="120" />
117
- <line class="split" x1="100" y1="0" x2="100" y2="120" vector-effect="non-scaling-stroke" />
116
+ <rect class="open" x="0" y="0" width="100" height="140" />
117
+ <rect class="close" x="100" y="0" width="100" height="140" />
118
+ <line class="split" x1="100" y1="0" x2="100" y2="140" vector-effect="non-scaling-stroke" />
118
119
  </g>
119
120
  <path class="edge" d={big} vector-effect="non-scaling-stroke" />
120
121
  </svg>
121
- <p class="halves">
122
+ <div class="halves">
122
123
  {it.phase.halves?.map((h) => (
123
124
  <span>{h.label}</span>
124
125
  ))}
125
- </p>
126
+ </div>
126
127
  </>
127
128
  )}
128
129
  </div>
@@ -215,7 +216,9 @@ const columns = items.map((it) => (it.kind === 'moment' ? 'auto' : it.phase.repe
215
216
  min-width: 0;
216
217
  }
217
218
 
218
- /* A moment: a stop level with the diamonds' points, its name just under it. */
219
+ /* A moment: a stop level with the diamonds' points, its name just under it, and a short line
220
+ * from the point before to the point after, ending in an arrowhead. It never crosses a diamond:
221
+ * the diamonds are drawn over its ends. */
219
222
  .stop-cell {
220
223
  position: relative;
221
224
  grid-row: 1;
@@ -223,7 +226,36 @@ const columns = items.map((it) => (it.kind === 'moment' ? 'auto' : it.phase.repe
223
226
  place-items: center;
224
227
  }
225
228
 
229
+ .stop-cell::before {
230
+ content: '';
231
+ position: absolute;
232
+ top: calc(50% - 0.75px);
233
+ left: calc(var(--sp-2) / -2 - 8px);
234
+ right: calc(var(--sp-2) / -2 - 8px);
235
+ height: 1.5px;
236
+ background: var(--c-diagram-line);
237
+ }
238
+
239
+ .row > li:first-child .stop-cell::before {
240
+ left: 50%;
241
+ }
242
+
243
+ .stop-cell::after {
244
+ content: '';
245
+ position: absolute;
246
+ top: 50%;
247
+ right: 4px;
248
+ width: 7px;
249
+ height: 7px;
250
+ border-top: 1.5px solid var(--c-diagram-line);
251
+ border-right: 1.5px solid var(--c-diagram-line);
252
+ translate: 0 -50%;
253
+ rotate: 45deg;
254
+ }
255
+
226
256
  .stop {
257
+ position: relative;
258
+ z-index: 1;
227
259
  width: 12px;
228
260
  height: 12px;
229
261
  border-radius: 50%;
@@ -245,7 +277,7 @@ const columns = items.map((it) => (it.kind === 'moment' ? 'auto' : it.phase.repe
245
277
  align-self: center;
246
278
  position: relative;
247
279
  width: 100%;
248
- aspect-ratio: 5 / 3;
280
+ aspect-ratio: 10 / 7;
249
281
  }
250
282
 
251
283
  .repeat .shape {
@@ -253,6 +285,8 @@ const columns = items.map((it) => (it.kind === 'moment' ? 'auto' : it.phase.repe
253
285
  }
254
286
 
255
287
  .shape svg {
288
+ position: relative;
289
+ z-index: 1;
256
290
  display: block;
257
291
  width: 100%;
258
292
  height: 100%;
@@ -285,10 +319,17 @@ const columns = items.map((it) => (it.kind === 'moment' ? 'auto' : it.phase.repe
285
319
  stroke-dasharray: 3 4;
286
320
  }
287
321
 
288
- /* Each label centred on its half's own middle, a third of the way in from its point, at one
289
- * size wherever the diamond is drawn. */
322
+ .link {
323
+ stroke: var(--c-diagram-line);
324
+ stroke-width: 1.5;
325
+ }
326
+
327
+ /* Each label centred on the middle of its half along the line through the points, where the
328
+ * half is widest at the label's height, at one size wherever the diamond is drawn. A label too
329
+ * long for its half wraps. */
290
330
  .halves {
291
331
  position: absolute;
332
+ z-index: 2;
292
333
  inset: 0;
293
334
  margin: 0;
294
335
  color: var(--c-text);
@@ -301,17 +342,17 @@ const columns = items.map((it) => (it.kind === 'moment' ? 'auto' : it.phase.repe
301
342
  .halves span {
302
343
  position: absolute;
303
344
  top: 50%;
304
- width: 30%;
345
+ width: 40%;
305
346
  translate: -50% -50%;
306
347
  text-wrap: balance;
307
348
  }
308
349
 
309
350
  .halves span:first-child {
310
- left: 34%;
351
+ left: 27%;
311
352
  }
312
353
 
313
354
  .halves span:last-child {
314
- left: 66%;
355
+ left: 73%;
315
356
  }
316
357
 
317
358
  .name {
@@ -349,6 +390,13 @@ const columns = items.map((it) => (it.kind === 'moment' ? 'auto' : it.phase.repe
349
390
  text-align: center;
350
391
  }
351
392
 
393
+ /* Where a phase is too narrow for its two notes side by side, they stack. */
394
+ @container (max-width: 960px) {
395
+ .notes {
396
+ grid-template-columns: 1fr;
397
+ }
398
+ }
399
+
352
400
  .note {
353
401
  margin: 0;
354
402
  font-size: var(--text-caption);
@@ -389,6 +437,11 @@ const columns = items.map((it) => (it.kind === 'moment' ? 'auto' : it.phase.repe
389
437
  gap: var(--sp-3);
390
438
  }
391
439
 
440
+ .stop-cell::before,
441
+ .stop-cell::after {
442
+ display: none;
443
+ }
444
+
392
445
  .moment-label {
393
446
  position: static;
394
447
  }
@@ -66,11 +66,28 @@ interface Props {
66
66
  /** A short legend in the corner: lines of text, the first one bold. */
67
67
  note?: { x: number; y: number; lines: { text: string; tone?: Tone }[] };
68
68
  caption?: string;
69
- /** Narrowest the drawing may get before it scrolls instead. */
69
+ /**
70
+ * Narrowest the drawing reads well at. Narrower, it still fits the width, smaller, and an
71
+ * Enlarge button opens it full size in a dialog.
72
+ */
70
73
  minWidth?: number;
74
+ /**
75
+ * A second drawing of the same diagram for a narrow screen, below 560px wide: its own size, where
76
+ * each node sits (by id; label, shape and tone come from `nodes`), and its own edges, rings and
77
+ * note. It fits the width instead of scrolling, so draw it about 360 to 420 wide.
78
+ */
79
+ narrow?: {
80
+ width: number;
81
+ height: number;
82
+ /** `icon: false` leaves a pill's icon out where the narrow pill is too short for it. */
83
+ nodes: { id: string; x: number; y: number; w?: number; h?: number; icon?: IconName | false }[];
84
+ edges: Edge[];
85
+ rings?: Ring[];
86
+ note?: { x: number; y: number; lines: { text: string; tone?: Tone }[] };
87
+ };
71
88
  }
72
89
 
73
- const { title, desc, width, height, nodes, edges, rings = [], note, caption, minWidth = 640 } = Astro.props;
90
+ const { title, desc, width, height, nodes, edges, rings = [], note, caption, minWidth = 640, narrow } = Astro.props;
74
91
  // Ids from the title, so two diagrams on a page don't collide and a build stays the same.
75
92
  let hash = 0;
76
93
  for (const c of title) hash = (hash * 31 + c.charCodeAt(0)) | 0;
@@ -81,7 +98,6 @@ const size = (n: Node) => {
81
98
  if (n.shape === 'icon') return { w: n.w ?? 64, h: n.w ?? 64 };
82
99
  return { w: n.w ?? 200, h: n.h ?? 44 };
83
100
  };
84
- const byId = new Map(nodes.map((n) => [n.id, n]));
85
101
 
86
102
  const anchor = (n: Node, side: Side, shift = 0): [number, number] => {
87
103
  const { w, h } = size(n);
@@ -152,7 +168,9 @@ const longest = (pts: [number, number][]): [number, number] => {
152
168
  return at;
153
169
  };
154
170
 
155
- const drawn = edges.map((e) => {
171
+ const draw = (ns: Node[], es: Edge[]) => {
172
+ const byId = new Map(ns.map((n) => [n.id, n]));
173
+ return es.map((e) => {
156
174
  const a = anchor(byId.get(e.from)!, e.fromSide, e.fromShift);
157
175
  // Stop short of the target so the arrowhead does not sit on its border.
158
176
  const t = anchor(byId.get(e.to)!, e.toSide, e.toShift);
@@ -161,7 +179,23 @@ const drawn = edges.map((e) => {
161
179
  e.toSide === 'left' ? [t[0] - gap, t[1]] : e.toSide === 'right' ? [t[0] + gap, t[1]] : e.toSide === 'top' ? [t[0], t[1] - gap] : [t[0], t[1] + gap];
162
180
  const pts = route(e, a, b);
163
181
  return { ...e, d: rounded(pts), head: head(pts), at: e.labelAt ?? longest(pts), tone: e.tone ?? 'quiet', step: e.step ?? 1 };
164
- });
182
+ });
183
+ };
184
+
185
+ // The drawings: the diagram as given, and its narrow one where there is one.
186
+ const narrowNodes = narrow
187
+ ? narrow.nodes.map((p) => {
188
+ const n = nodes.find((m) => m.id === p.id);
189
+ if (!n) throw new Error(`FlowDiagram "${title}": narrow node "${p.id}" is not in nodes.`);
190
+ return { ...n, ...p, icon: p.icon === false ? undefined : (p.icon ?? n.icon) };
191
+ })
192
+ : [];
193
+ const views = [
194
+ { kind: 'wide', width, height, nodes, drawn: draw(nodes, edges), rings, note, minWidth },
195
+ ...(narrow
196
+ ? [{ kind: 'narrow', width: narrow.width, height: narrow.height, nodes: narrowNodes, drawn: draw(narrowNodes, narrow.edges), rings: narrow.rings ?? [], note: narrow.note, minWidth: 0 }]
197
+ : []),
198
+ ];
165
199
 
166
200
  // Label lines for a circle: break at the space nearest the middle when it is long.
167
201
  const lines = (label: string) => {
@@ -181,11 +215,20 @@ const lines = (label: string) => {
181
215
  };
182
216
  ---
183
217
 
184
- <figure class="flow" data-flow>
185
- <div class="scroll" tabindex="0" role="region" aria-label={title}>
186
- <svg viewBox={`0 0 ${width} ${height}`} role="img" aria-labelledby={`${uid}-t ${uid}-d`} style={`min-width: ${minWidth}px`}>
187
- <title id={`${uid}-t`}>{title}</title>
188
- <desc id={`${uid}-d`}>{desc}</desc>
218
+ <figure class:list={['flow', { 'has-narrow': narrow }]} data-flow data-min={minWidth}>
219
+ {views.map(({ kind, width, height, nodes, drawn, rings, note }) => (
220
+ <div class:list={['scroll', kind]}>
221
+ {kind === 'wide' && (
222
+ <button type="button" class="enlarge" data-enlarge hidden>
223
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
224
+ <path d="M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7" />
225
+ </svg>
226
+ Enlarge<span class="visually-hidden">: {title}</span>
227
+ </button>
228
+ )}
229
+ <svg class="drawing" viewBox={`0 0 ${width} ${height}`} role="img" aria-labelledby={`${uid}-${kind}-t ${uid}-${kind}-d`}>
230
+ <title id={`${uid}-${kind}-t`}>{title}</title>
231
+ <desc id={`${uid}-${kind}-d`}>{desc}</desc>
189
232
 
190
233
  {rings.map((r) => <circle class="ring" data-step={r.step ?? 0} cx={r.cx} cy={r.cy} r={r.r} />)}
191
234
 
@@ -263,10 +306,51 @@ const lines = (label: string) => {
263
306
  }
264
307
  </svg>
265
308
  </div>
309
+ ))}
310
+ <dialog class="zoom" aria-labelledby={`${uid}-zoom`}>
311
+ <div class="zoom-bar">
312
+ <p class="zoom-title" id={`${uid}-zoom`}>{title}</p>
313
+ <button type="button" class="close" data-close>Close</button>
314
+ </div>
315
+ <div class="zoom-scroll" tabindex="0" role="region" aria-label={`${title}, full size`} data-zoom-body></div>
316
+ </dialog>
266
317
  {caption && <figcaption>{caption}</figcaption>}
267
318
  </figure>
268
319
 
269
320
  <script>
321
+ // Narrower than it reads well at, it fits, smaller, with an Enlarge button that opens a copy
322
+ // full size in a dialog.
323
+ document.querySelectorAll<HTMLElement>('[data-flow]').forEach((fig) => {
324
+ const min = Number(fig.dataset.min) || 0;
325
+ const wide = fig.querySelector<HTMLElement>('.scroll.wide');
326
+ const button = fig.querySelector<HTMLButtonElement>('[data-enlarge]');
327
+ const dialog = fig.querySelector<HTMLDialogElement>('dialog.zoom');
328
+ const body = fig.querySelector<HTMLElement>('[data-zoom-body]');
329
+ if (!wide || !button || !dialog || !body) return;
330
+ const fit = () => {
331
+ const small = wide.offsetParent !== null && wide.clientWidth < min;
332
+ button.hidden = !small;
333
+ fig.classList.toggle('is-small', small);
334
+ };
335
+ new ResizeObserver(fit).observe(fig);
336
+ fit();
337
+ button.addEventListener('click', () => {
338
+ const copy = wide.querySelector('svg.drawing')!.cloneNode(true) as SVGSVGElement;
339
+ copy.removeAttribute('aria-labelledby');
340
+ copy.setAttribute('aria-hidden', 'true');
341
+ copy.querySelectorAll('[id]').forEach((el) => el.removeAttribute('id'));
342
+ copy.style.setProperty('--full', `${Math.max(min, 640)}px`);
343
+ body.replaceChildren(copy);
344
+ dialog.showModal();
345
+ // Open on the middle of the drawing, where its point usually is.
346
+ body.scrollLeft = (body.scrollWidth - body.clientWidth) / 2;
347
+ });
348
+ dialog.querySelector('[data-close]')?.addEventListener('click', () => dialog.close());
349
+ dialog.addEventListener('click', (e) => {
350
+ if (e.target === dialog) dialog.close();
351
+ });
352
+ });
353
+
270
354
  // One step is a beat. Arm only what is below the fold, so a diagram already on screen
271
355
  // never blinks out, and start the pulses once their line has drawn.
272
356
  const STEP = 220;
@@ -303,10 +387,146 @@ const lines = (label: string) => {
303
387
  <style>
304
388
  .flow {
305
389
  margin-block: var(--sp-7);
390
+ container-type: inline-size;
391
+ }
392
+
393
+ /* With a narrow drawing, it takes over below 560px, fitting the width instead of scrolling. */
394
+ .scroll.narrow {
395
+ display: none;
396
+ }
397
+
398
+ @container (max-width: 560px) {
399
+ .has-narrow .scroll.wide {
400
+ display: none;
401
+ }
402
+
403
+ .has-narrow .scroll.narrow {
404
+ display: block;
405
+ padding: var(--sp-5) var(--sp-3);
406
+ }
407
+ }
408
+
409
+ /* Narrower than it reads well at: it fits, smaller, and offers itself full size. */
410
+ .enlarge {
411
+ position: absolute;
412
+ top: var(--sp-3);
413
+ right: var(--sp-3);
414
+ z-index: 1;
415
+ display: inline-flex;
416
+ align-items: center;
417
+ gap: var(--sp-1);
418
+ padding: var(--sp-1) var(--sp-3);
419
+ border: 1px solid var(--c-border);
420
+ border-radius: var(--radius-full);
421
+ background: var(--c-surface);
422
+ color: var(--c-text);
423
+ font: inherit;
424
+ font-size: var(--text-caption);
425
+ font-weight: 600;
426
+ cursor: pointer;
427
+ transition: border-color var(--motion-hover) var(--ease-hover);
428
+ }
429
+
430
+ .enlarge[hidden] {
431
+ display: none;
432
+ }
433
+
434
+ .enlarge svg {
435
+ display: inline-block;
436
+ width: 16px;
437
+ height: 16px;
438
+ }
439
+
440
+ .enlarge:hover {
441
+ border-color: var(--c-border-strong);
442
+ }
443
+
444
+ .is-small .scroll.wide {
445
+ padding-top: calc(var(--sp-3) * 2 + 28px);
446
+ }
447
+
448
+ .enlarge:focus-visible,
449
+ .close:focus-visible,
450
+ .zoom-scroll:focus-visible {
451
+ outline: 2px solid var(--c-focus);
452
+ outline-offset: 2px;
453
+ }
454
+
455
+ .visually-hidden {
456
+ position: absolute;
457
+ width: 1px;
458
+ height: 1px;
459
+ overflow: hidden;
460
+ clip-path: inset(50%);
461
+ white-space: nowrap;
462
+ }
463
+
464
+ .zoom {
465
+ width: calc(100vw - var(--sp-4));
466
+ max-width: none;
467
+ height: calc(100dvh - var(--sp-4));
468
+ max-height: none;
469
+ padding: 0;
470
+ border: 1px solid var(--c-border);
471
+ border-radius: var(--radius-lg);
472
+ background: var(--c-bg);
473
+ color: var(--c-text);
474
+ }
475
+
476
+ .zoom[open] {
477
+ display: flex;
478
+ flex-direction: column;
479
+ }
480
+
481
+ .zoom::backdrop {
482
+ background: color-mix(in oklab, var(--c-bg) 70%, transparent);
483
+ }
484
+
485
+ .zoom-bar {
486
+ display: flex;
487
+ align-items: center;
488
+ justify-content: space-between;
489
+ gap: var(--sp-3);
490
+ padding: var(--sp-3) var(--sp-4);
491
+ border-bottom: 1px solid var(--c-border);
492
+ }
493
+
494
+ .zoom-title {
495
+ margin: 0;
496
+ font-weight: 600;
497
+ font-size: var(--text-body-sm);
498
+ }
499
+
500
+ .close {
501
+ padding: var(--sp-1) var(--sp-3);
502
+ border: 1px solid var(--c-border);
503
+ border-radius: var(--radius-full);
504
+ background: var(--c-surface);
505
+ color: var(--c-text);
506
+ font: inherit;
507
+ font-size: var(--text-caption);
508
+ font-weight: 600;
509
+ cursor: pointer;
510
+ }
511
+
512
+ /* Full size, so the words read; it pans where the screen is smaller. */
513
+ .zoom-scroll {
514
+ flex: 1;
515
+ overflow: auto;
516
+ padding: var(--sp-5);
517
+ background: var(--c-surface-sunken);
518
+ }
519
+
520
+ .zoom-scroll > svg {
521
+ display: block;
522
+ width: var(--full);
523
+ max-width: none;
524
+ height: auto;
525
+ overflow: visible;
306
526
  }
307
527
 
308
528
  .scroll {
309
- overflow-x: auto;
529
+ position: relative;
310
530
  background: var(--c-surface-sunken);
311
531
  border: 1px solid var(--c-border);
312
532
  border-radius: var(--radius-lg);
package/src/Phases.astro CHANGED
@@ -168,8 +168,8 @@ const last = phases.length - 1;
168
168
 
169
169
  .row > li:first-child .band {
170
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);
171
+ border-radius: var(--radius-lg) 0 0 var(--radius-lg);
172
+ padding-left: var(--sp-4);
173
173
  }
174
174
 
175
175
  .row > li:last-child .band {
@@ -286,7 +286,7 @@ const last = phases.length - 1;
286
286
  .row {
287
287
  grid-template-columns: 1fr;
288
288
  grid-template-rows: none;
289
- row-gap: var(--sp-6);
289
+ row-gap: var(--sp-3);
290
290
  }
291
291
 
292
292
  .row > li {
@@ -303,6 +303,17 @@ const last = phases.length - 1;
303
303
  padding-inline: var(--sp-4);
304
304
  }
305
305
 
306
+ /* Stacked, an arrow down from each phase to the next says they follow on. */
307
+ .row > li:not(:last-child)::after {
308
+ content: '';
309
+ justify-self: center;
310
+ width: 14px;
311
+ height: 32px;
312
+ margin-top: var(--sp-2);
313
+ background: var(--c-diagram-line);
314
+ mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 32'%3E%3Cpath d='M7 1V30M1.5 24.5 7 30l5.5-5.5' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
315
+ }
316
+
306
317
  .spans {
307
318
  grid-template-columns: 1fr;
308
319
  }
@@ -347,6 +358,11 @@ const last = phases.length - 1;
347
358
  }
348
359
 
349
360
  @media (forced-colors: active) {
361
+ .row > li::after {
362
+ forced-color-adjust: none;
363
+ background: CanvasText;
364
+ }
365
+
350
366
  .band {
351
367
  border: 1px solid CanvasText;
352
368
  clip-path: none;