@n1kname/components 0.26.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 +1 -1
- package/src/Diamonds.astro +21 -13
- package/src/FlowDiagram.astro +176 -7
package/package.json
CHANGED
package/src/Diamonds.astro
CHANGED
|
@@ -67,7 +67,7 @@ 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,
|
|
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;
|
|
@@ -108,22 +108,22 @@ const columns = items.map((it) => (it.kind === 'moment' ? 'minmax(4.5rem, auto)'
|
|
|
108
108
|
</svg>
|
|
109
109
|
) : (
|
|
110
110
|
<>
|
|
111
|
-
<svg viewBox="0 0 200
|
|
111
|
+
<svg viewBox="0 0 200 140" aria-hidden="true">
|
|
112
112
|
<clipPath id={`${uid}-${i}`}>
|
|
113
113
|
<path d={big} />
|
|
114
114
|
</clipPath>
|
|
115
115
|
<g clip-path={`url(#${uid}-${i})`}>
|
|
116
|
-
<rect class="open" x="0" y="0" width="100" height="
|
|
117
|
-
<rect class="close" x="100" y="0" width="100" height="
|
|
118
|
-
<line class="split" x1="100" y1="0" x2="100" y2="
|
|
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" />
|
|
119
119
|
</g>
|
|
120
120
|
<path class="edge" d={big} vector-effect="non-scaling-stroke" />
|
|
121
121
|
</svg>
|
|
122
|
-
<
|
|
122
|
+
<div class="halves">
|
|
123
123
|
{it.phase.halves?.map((h) => (
|
|
124
124
|
<span>{h.label}</span>
|
|
125
125
|
))}
|
|
126
|
-
</
|
|
126
|
+
</div>
|
|
127
127
|
</>
|
|
128
128
|
)}
|
|
129
129
|
</div>
|
|
@@ -277,7 +277,7 @@ const columns = items.map((it) => (it.kind === 'moment' ? 'minmax(4.5rem, auto)'
|
|
|
277
277
|
align-self: center;
|
|
278
278
|
position: relative;
|
|
279
279
|
width: 100%;
|
|
280
|
-
aspect-ratio:
|
|
280
|
+
aspect-ratio: 10 / 7;
|
|
281
281
|
}
|
|
282
282
|
|
|
283
283
|
.repeat .shape {
|
|
@@ -324,8 +324,9 @@ const columns = items.map((it) => (it.kind === 'moment' ? 'minmax(4.5rem, auto)'
|
|
|
324
324
|
stroke-width: 1.5;
|
|
325
325
|
}
|
|
326
326
|
|
|
327
|
-
/* Each label centred on
|
|
328
|
-
* size wherever the diamond is drawn.
|
|
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. */
|
|
329
330
|
.halves {
|
|
330
331
|
position: absolute;
|
|
331
332
|
z-index: 2;
|
|
@@ -341,17 +342,17 @@ const columns = items.map((it) => (it.kind === 'moment' ? 'minmax(4.5rem, auto)'
|
|
|
341
342
|
.halves span {
|
|
342
343
|
position: absolute;
|
|
343
344
|
top: 50%;
|
|
344
|
-
width:
|
|
345
|
+
width: 40%;
|
|
345
346
|
translate: -50% -50%;
|
|
346
347
|
text-wrap: balance;
|
|
347
348
|
}
|
|
348
349
|
|
|
349
350
|
.halves span:first-child {
|
|
350
|
-
left:
|
|
351
|
+
left: 27%;
|
|
351
352
|
}
|
|
352
353
|
|
|
353
354
|
.halves span:last-child {
|
|
354
|
-
left:
|
|
355
|
+
left: 73%;
|
|
355
356
|
}
|
|
356
357
|
|
|
357
358
|
.name {
|
|
@@ -389,6 +390,13 @@ const columns = items.map((it) => (it.kind === 'moment' ? 'minmax(4.5rem, auto)'
|
|
|
389
390
|
text-align: center;
|
|
390
391
|
}
|
|
391
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
|
+
|
|
392
400
|
.note {
|
|
393
401
|
margin: 0;
|
|
394
402
|
font-size: var(--text-caption);
|
package/src/FlowDiagram.astro
CHANGED
|
@@ -66,7 +66,10 @@ 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
|
-
/**
|
|
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;
|
|
71
74
|
/**
|
|
72
75
|
* A second drawing of the same diagram for a narrow screen, below 560px wide: its own size, where
|
|
@@ -212,10 +215,18 @@ const lines = (label: string) => {
|
|
|
212
215
|
};
|
|
213
216
|
---
|
|
214
217
|
|
|
215
|
-
<figure class:list={['flow', { 'has-narrow': narrow }]} data-flow>
|
|
216
|
-
{views.map(({ kind, width, height, nodes, drawn, rings, note
|
|
217
|
-
<div class:list={['scroll', kind]}
|
|
218
|
-
|
|
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`}>
|
|
219
230
|
<title id={`${uid}-${kind}-t`}>{title}</title>
|
|
220
231
|
<desc id={`${uid}-${kind}-d`}>{desc}</desc>
|
|
221
232
|
|
|
@@ -296,10 +307,50 @@ const lines = (label: string) => {
|
|
|
296
307
|
</svg>
|
|
297
308
|
</div>
|
|
298
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>
|
|
299
317
|
{caption && <figcaption>{caption}</figcaption>}
|
|
300
318
|
</figure>
|
|
301
319
|
|
|
302
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
|
+
|
|
303
354
|
// One step is a beat. Arm only what is below the fold, so a diagram already on screen
|
|
304
355
|
// never blinks out, and start the pulses once their line has drawn.
|
|
305
356
|
const STEP = 220;
|
|
@@ -351,13 +402,131 @@ const lines = (label: string) => {
|
|
|
351
402
|
|
|
352
403
|
.has-narrow .scroll.narrow {
|
|
353
404
|
display: block;
|
|
354
|
-
overflow: visible;
|
|
355
405
|
padding: var(--sp-5) var(--sp-3);
|
|
356
406
|
}
|
|
357
407
|
}
|
|
358
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;
|
|
526
|
+
}
|
|
527
|
+
|
|
359
528
|
.scroll {
|
|
360
|
-
|
|
529
|
+
position: relative;
|
|
361
530
|
background: var(--c-surface-sunken);
|
|
362
531
|
border: 1px solid var(--c-border);
|
|
363
532
|
border-radius: var(--radius-lg);
|