@n1kname/components 0.13.0 → 0.15.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 +2 -1
- package/src/CopyTag.astro +160 -0
- package/src/FlowDiagram.astro +536 -0
- package/src/Highlight.astro +16 -0
- package/src/LinkCard.astro +116 -0
- package/src/PageHeader.astro +6 -35
- package/src/Reveal.astro +68 -0
- package/src/Tag.astro +28 -3
- package/src/highlight.css +44 -0
- package/src/icons.ts +7 -0
- package/src/page-change.css +22 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@n1kname/components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
"./type.css": "./src/type.css",
|
|
9
9
|
"./marks.css": "./src/marks.css",
|
|
10
10
|
"./page-change.css": "./src/page-change.css",
|
|
11
|
+
"./highlight.css": "./src/highlight.css",
|
|
11
12
|
"./icons": "./src/icons.ts",
|
|
12
13
|
"./datatable.js": "./src/datatable.js",
|
|
13
14
|
"./dotrows.js": "./src/dotrows.js",
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* One pill, two actions: the link half opens it (a mail client, say), the half on the right
|
|
4
|
+
* copies the value, because a recruiter often wants the address rather than an app opening. Each
|
|
5
|
+
* half is its own control with its own focus ring; a hairline marks where one ends. The pill
|
|
6
|
+
* lifts and presses as one, so it never comes apart at the seam.
|
|
7
|
+
*
|
|
8
|
+
* The copy half is rendered hidden and shown from script only where the clipboard is there to
|
|
9
|
+
* use, so nobody sees a button that does nothing. The check arrives on the spring; "Copied" is
|
|
10
|
+
* read out from a separate live region, since a changing button label is not announced reliably.
|
|
11
|
+
*/
|
|
12
|
+
import Tag from './Tag.astro';
|
|
13
|
+
import type { IconName } from './icons';
|
|
14
|
+
|
|
15
|
+
interface Props {
|
|
16
|
+
href: string;
|
|
17
|
+
/** What gets copied, such as the email address. */
|
|
18
|
+
value: string;
|
|
19
|
+
/** What is copied, for the accessible name: "Copy email address". */
|
|
20
|
+
what: string;
|
|
21
|
+
icon?: IconName;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const { href, value, what, icon } = Astro.props;
|
|
25
|
+
// Lucide's copy and check, drawn the way Icon draws at 15px.
|
|
26
|
+
const svg = { width: 15, height: 15, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', 'stroke-width': 1.75, 'stroke-linecap': 'round', 'stroke-linejoin': 'round', 'aria-hidden': 'true' } as const;
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
<span class="copy-tag">
|
|
30
|
+
<Tag href={href} icon={icon} tone="accent" still><slot /></Tag>
|
|
31
|
+
<button class="copy" type="button" data-copy={value} aria-label={`Copy ${what}`} hidden>
|
|
32
|
+
<span class="ico">
|
|
33
|
+
<svg class="c1" {...svg}><rect width="14" height="14" x="8" y="8" rx="2" ry="2" /><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" /></svg>
|
|
34
|
+
<svg class="c2" {...svg}><path d="M20 6 9 17l-5-5" /></svg>
|
|
35
|
+
</span>
|
|
36
|
+
<span class="sr-only" role="status"></span>
|
|
37
|
+
</button>
|
|
38
|
+
</span>
|
|
39
|
+
|
|
40
|
+
<style>
|
|
41
|
+
.copy-tag {
|
|
42
|
+
display: inline-flex;
|
|
43
|
+
transition:
|
|
44
|
+
translate var(--motion-spring) var(--ease-spring),
|
|
45
|
+
scale var(--motion-base) var(--ease-out);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@media (hover: hover) {
|
|
49
|
+
.copy-tag:hover {
|
|
50
|
+
translate: 0 -2px;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.copy-tag:has(:active) {
|
|
55
|
+
scale: 0.97;
|
|
56
|
+
transition-duration: var(--motion-spring), 80ms;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@media (prefers-reduced-motion: reduce) {
|
|
60
|
+
.copy-tag {
|
|
61
|
+
translate: none !important;
|
|
62
|
+
scale: none !important;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/* Square inner corners only once the copy half is there to meet. */
|
|
67
|
+
.copy-tag:has(.copy:not([hidden])) :global(a.tag) {
|
|
68
|
+
border-start-end-radius: 0;
|
|
69
|
+
border-end-end-radius: 0;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.copy {
|
|
73
|
+
display: inline-flex;
|
|
74
|
+
align-items: center;
|
|
75
|
+
padding: 5px var(--sp-3);
|
|
76
|
+
border-radius: var(--radius-full);
|
|
77
|
+
border-start-start-radius: 0;
|
|
78
|
+
border-end-start-radius: 0;
|
|
79
|
+
border: 1px solid transparent;
|
|
80
|
+
background: var(--c-surface-tint);
|
|
81
|
+
color: var(--c-text-accent);
|
|
82
|
+
box-shadow: inset 1px 0 0 color-mix(in oklab, var(--c-text-accent) 22%, transparent);
|
|
83
|
+
cursor: pointer;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.copy[hidden] {
|
|
87
|
+
display: none;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.copy-tag :global(a.tag),
|
|
91
|
+
.copy {
|
|
92
|
+
transition: background-color var(--motion-hover) var(--ease-hover);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.copy-tag :global(a.tag:hover),
|
|
96
|
+
.copy:hover {
|
|
97
|
+
border-color: transparent;
|
|
98
|
+
background: color-mix(in oklab, var(--c-surface-tint), var(--c-accent) 14%);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.ico {
|
|
102
|
+
position: relative;
|
|
103
|
+
width: 15px;
|
|
104
|
+
height: 15px;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.ico svg {
|
|
108
|
+
position: absolute;
|
|
109
|
+
inset: 0;
|
|
110
|
+
transition:
|
|
111
|
+
opacity var(--motion-fast) var(--ease-out),
|
|
112
|
+
scale var(--motion-fast) var(--ease-out);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.c2,
|
|
116
|
+
.done .c1 {
|
|
117
|
+
opacity: 0;
|
|
118
|
+
scale: 0.6;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.done .c2 {
|
|
122
|
+
opacity: 1;
|
|
123
|
+
scale: 1;
|
|
124
|
+
transition:
|
|
125
|
+
opacity var(--motion-fast) var(--ease-out),
|
|
126
|
+
scale var(--motion-spring) var(--ease-spring);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.sr-only {
|
|
130
|
+
position: absolute;
|
|
131
|
+
width: 1px;
|
|
132
|
+
height: 1px;
|
|
133
|
+
overflow: hidden;
|
|
134
|
+
clip-path: inset(50%);
|
|
135
|
+
white-space: nowrap;
|
|
136
|
+
}
|
|
137
|
+
</style>
|
|
138
|
+
|
|
139
|
+
<script>
|
|
140
|
+
document.querySelectorAll<HTMLButtonElement>('.copy-tag button[data-copy]').forEach((button) => {
|
|
141
|
+
if (!navigator.clipboard) return;
|
|
142
|
+
button.hidden = false;
|
|
143
|
+
const status = button.querySelector('[role="status"]')!;
|
|
144
|
+
let timer = 0;
|
|
145
|
+
button.addEventListener('click', async () => {
|
|
146
|
+
try {
|
|
147
|
+
await navigator.clipboard.writeText(button.dataset.copy!);
|
|
148
|
+
} catch {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
button.classList.add('done');
|
|
152
|
+
status.textContent = 'Copied';
|
|
153
|
+
clearTimeout(timer);
|
|
154
|
+
timer = window.setTimeout(() => {
|
|
155
|
+
button.classList.remove('done');
|
|
156
|
+
status.textContent = '';
|
|
157
|
+
}, 2000);
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
</script>
|
|
@@ -0,0 +1,536 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* A drawn diagram: nodes placed by hand on a viewBox, edges routed between their sides with
|
|
4
|
+
* rounded elbows, Lucide icons inside the nodes. For a diagram that makes an argument through
|
|
5
|
+
* its shape, where a layout engine would put things in the wrong place.
|
|
6
|
+
*
|
|
7
|
+
* It builds itself once as it comes into view, in `step` order: nodes settle in, edges draw
|
|
8
|
+
* from their source, the arrowhead and label land as the line arrives. An edge with `flow`
|
|
9
|
+
* then carries a small pulse along itself, so a loop reads as a loop. Without script, or with
|
|
10
|
+
* reduced motion, the diagram is simply there and nothing moves.
|
|
11
|
+
*/
|
|
12
|
+
import { ICONS, type IconName } from './icons';
|
|
13
|
+
|
|
14
|
+
type Side = 'top' | 'right' | 'bottom' | 'left';
|
|
15
|
+
type Tone = 'accent' | 'cool' | 'quiet' | 'solid';
|
|
16
|
+
|
|
17
|
+
interface Node {
|
|
18
|
+
id: string;
|
|
19
|
+
/** Centre. */
|
|
20
|
+
x: number;
|
|
21
|
+
y: number;
|
|
22
|
+
w?: number;
|
|
23
|
+
h?: number;
|
|
24
|
+
shape?: 'pill' | 'circle' | 'icon';
|
|
25
|
+
icon?: IconName;
|
|
26
|
+
label: string;
|
|
27
|
+
/** Up to two lines under an icon node; break them with \\n. */
|
|
28
|
+
sub?: string;
|
|
29
|
+
tone?: Tone;
|
|
30
|
+
step?: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface Edge {
|
|
34
|
+
from: string;
|
|
35
|
+
to: string;
|
|
36
|
+
fromSide: Side;
|
|
37
|
+
toSide: Side;
|
|
38
|
+
/** Shift the anchor along its side, in px from the side's middle. */
|
|
39
|
+
fromShift?: number;
|
|
40
|
+
toShift?: number;
|
|
41
|
+
/** Where a horizontal-to-horizontal edge turns, as an x; vertical-to-vertical, as a y. */
|
|
42
|
+
turn?: number;
|
|
43
|
+
label?: string;
|
|
44
|
+
/** Label position, defaults to the middle of the longest segment, above it. */
|
|
45
|
+
labelAt?: [number, number];
|
|
46
|
+
tone?: Tone;
|
|
47
|
+
step?: number;
|
|
48
|
+
flow?: boolean;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface Ring {
|
|
52
|
+
cx: number;
|
|
53
|
+
cy: number;
|
|
54
|
+
r: number;
|
|
55
|
+
step?: number;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
interface Props {
|
|
59
|
+
title: string;
|
|
60
|
+
desc: string;
|
|
61
|
+
width: number;
|
|
62
|
+
height: number;
|
|
63
|
+
nodes: Node[];
|
|
64
|
+
edges: Edge[];
|
|
65
|
+
rings?: Ring[];
|
|
66
|
+
/** A short legend in the corner: lines of text, the first one bold. */
|
|
67
|
+
note?: { x: number; y: number; lines: { text: string; tone?: Tone }[] };
|
|
68
|
+
caption?: string;
|
|
69
|
+
/** Narrowest the drawing may get before it scrolls instead. */
|
|
70
|
+
minWidth?: number;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const { title, desc, width, height, nodes, edges, rings = [], note, caption, minWidth = 640 } = Astro.props;
|
|
74
|
+
// Ids from the title, so two diagrams on a page don't collide and a build stays the same.
|
|
75
|
+
let hash = 0;
|
|
76
|
+
for (const c of title) hash = (hash * 31 + c.charCodeAt(0)) | 0;
|
|
77
|
+
const uid = `flow-${(hash >>> 0).toString(36)}`;
|
|
78
|
+
|
|
79
|
+
const size = (n: Node) => {
|
|
80
|
+
if (n.shape === 'circle') return { w: n.w ?? 88, h: n.w ?? 88 };
|
|
81
|
+
if (n.shape === 'icon') return { w: n.w ?? 64, h: n.w ?? 64 };
|
|
82
|
+
return { w: n.w ?? 200, h: n.h ?? 44 };
|
|
83
|
+
};
|
|
84
|
+
const byId = new Map(nodes.map((n) => [n.id, n]));
|
|
85
|
+
|
|
86
|
+
const anchor = (n: Node, side: Side, shift = 0): [number, number] => {
|
|
87
|
+
const { w, h } = size(n);
|
|
88
|
+
if (side === 'top') return [n.x + shift, n.y - h / 2];
|
|
89
|
+
if (side === 'bottom') return [n.x + shift, n.y + h / 2];
|
|
90
|
+
if (side === 'left') return [n.x - w / 2, n.y + shift];
|
|
91
|
+
return [n.x + w / 2, n.y + shift];
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const horizontal = (s: Side) => s === 'left' || s === 'right';
|
|
95
|
+
|
|
96
|
+
// The corner points of an orthogonal route between two anchors.
|
|
97
|
+
const route = (e: Edge, a: [number, number], b: [number, number]): [number, number][] => {
|
|
98
|
+
const [ax, ay] = a;
|
|
99
|
+
const [bx, by] = b;
|
|
100
|
+
if (horizontal(e.fromSide) && horizontal(e.toSide)) {
|
|
101
|
+
if (ay === by) return [a, b];
|
|
102
|
+
const tx = e.turn ?? (ax + bx) / 2;
|
|
103
|
+
return [a, [tx, ay], [tx, by], b];
|
|
104
|
+
}
|
|
105
|
+
if (!horizontal(e.fromSide) && !horizontal(e.toSide)) {
|
|
106
|
+
if (ax === bx) return [a, b];
|
|
107
|
+
const ty = e.turn ?? (ay + by) / 2;
|
|
108
|
+
return [a, [ax, ty], [bx, ty], b];
|
|
109
|
+
}
|
|
110
|
+
return horizontal(e.fromSide) ? [a, [bx, ay], b] : [a, [ax, by], b];
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// A path through the points with each corner rounded, never by more than half a segment.
|
|
114
|
+
const R = 12;
|
|
115
|
+
const rounded = (pts: [number, number][]) => {
|
|
116
|
+
let d = `M${pts[0][0]} ${pts[0][1]}`;
|
|
117
|
+
for (let i = 1; i < pts.length - 1; i++) {
|
|
118
|
+
const [px, py] = pts[i - 1];
|
|
119
|
+
const [cx, cy] = pts[i];
|
|
120
|
+
const [nx, ny] = pts[i + 1];
|
|
121
|
+
const r = Math.min(R, Math.hypot(cx - px, cy - py) / 2, Math.hypot(nx - cx, ny - cy) / 2);
|
|
122
|
+
const inX = cx - Math.sign(cx - px) * r;
|
|
123
|
+
const inY = cy - Math.sign(cy - py) * r;
|
|
124
|
+
const outX = cx + Math.sign(nx - cx) * r;
|
|
125
|
+
const outY = cy + Math.sign(ny - cy) * r;
|
|
126
|
+
d += ` L${inX} ${inY} Q${cx} ${cy} ${outX} ${outY}`;
|
|
127
|
+
}
|
|
128
|
+
const [lx, ly] = pts[pts.length - 1];
|
|
129
|
+
return `${d} L${lx} ${ly}`;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// A small open chevron at the end, pointing along the last segment.
|
|
133
|
+
const head = (pts: [number, number][]) => {
|
|
134
|
+
const [x, y] = pts[pts.length - 1];
|
|
135
|
+
const [px, py] = pts[pts.length - 2];
|
|
136
|
+
const dx = Math.sign(x - px);
|
|
137
|
+
const dy = Math.sign(y - py);
|
|
138
|
+
const s = 6;
|
|
139
|
+
return `M${x - dx * s - dy * s} ${y - dy * s - dx * s} L${x} ${y} L${x - dx * s + dy * s} ${y - dy * s + dx * s}`;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const longest = (pts: [number, number][]): [number, number] => {
|
|
143
|
+
let best = 0;
|
|
144
|
+
let at: [number, number] = pts[0];
|
|
145
|
+
for (let i = 1; i < pts.length; i++) {
|
|
146
|
+
const len = Math.hypot(pts[i][0] - pts[i - 1][0], pts[i][1] - pts[i - 1][1]);
|
|
147
|
+
if (len > best) {
|
|
148
|
+
best = len;
|
|
149
|
+
at = [(pts[i][0] + pts[i - 1][0]) / 2, (pts[i][1] + pts[i - 1][1]) / 2 - 10];
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return at;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const drawn = edges.map((e) => {
|
|
156
|
+
const a = anchor(byId.get(e.from)!, e.fromSide, e.fromShift);
|
|
157
|
+
// Stop short of the target so the arrowhead does not sit on its border.
|
|
158
|
+
const t = anchor(byId.get(e.to)!, e.toSide, e.toShift);
|
|
159
|
+
const gap = 4;
|
|
160
|
+
const b: [number, number] =
|
|
161
|
+
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
|
+
const pts = route(e, a, b);
|
|
163
|
+
return { ...e, d: rounded(pts), head: head(pts), at: e.labelAt ?? longest(pts), tone: e.tone ?? 'quiet', step: e.step ?? 1 };
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// Label lines for a circle: break at the space nearest the middle when it is long.
|
|
167
|
+
const lines = (label: string) => {
|
|
168
|
+
if (label.length <= 10 || !label.includes(' ')) return [label];
|
|
169
|
+
const words = label.split(' ');
|
|
170
|
+
// Three or more words: keep short words with their neighbour ("UI and motion" / "designer").
|
|
171
|
+
if (words.length >= 3 && label.length > 14) {
|
|
172
|
+
const last = words.pop()!;
|
|
173
|
+
const head = words.join(' ');
|
|
174
|
+
return head.length > 10 ? [words.slice(0, -1).join(' '), words.at(-1)!, last] : [head, last];
|
|
175
|
+
}
|
|
176
|
+
const mid = label.length / 2;
|
|
177
|
+
let cut = 0;
|
|
178
|
+
let best = Infinity;
|
|
179
|
+
for (let i = 0; i < label.length; i++) if (label[i] === ' ' && Math.abs(i - mid) < best) (best = Math.abs(i - mid)), (cut = i);
|
|
180
|
+
return [label.slice(0, cut), label.slice(cut + 1)];
|
|
181
|
+
};
|
|
182
|
+
---
|
|
183
|
+
|
|
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>
|
|
189
|
+
|
|
190
|
+
{rings.map((r) => <circle class="ring" data-step={r.step ?? 0} cx={r.cx} cy={r.cy} r={r.r} />)}
|
|
191
|
+
|
|
192
|
+
<g class="edges">
|
|
193
|
+
{
|
|
194
|
+
drawn.map((e) => (
|
|
195
|
+
<g class:list={['edge', e.tone]} data-step={e.step}>
|
|
196
|
+
<path class="line" d={e.d} pathLength="1" />
|
|
197
|
+
<path class="head" d={e.head} />
|
|
198
|
+
{e.label && (
|
|
199
|
+
<text class="edge-label" x={e.at[0]} y={e.at[1]}>
|
|
200
|
+
{e.label}
|
|
201
|
+
</text>
|
|
202
|
+
)}
|
|
203
|
+
{e.flow && (
|
|
204
|
+
<circle class="pulse" r="3.5">
|
|
205
|
+
<animateMotion dur="2.8s" begin="indefinite" repeatCount="indefinite" keyPoints="0;1;1" keyTimes="0;0.7;1" calcMode="linear" path={e.d} />
|
|
206
|
+
</circle>
|
|
207
|
+
)}
|
|
208
|
+
</g>
|
|
209
|
+
))
|
|
210
|
+
}
|
|
211
|
+
</g>
|
|
212
|
+
|
|
213
|
+
{
|
|
214
|
+
nodes.map((n) => {
|
|
215
|
+
const { w, h } = size(n);
|
|
216
|
+
const tone = n.tone ?? 'quiet';
|
|
217
|
+
const step = n.step ?? 0;
|
|
218
|
+
if (n.shape === 'icon') {
|
|
219
|
+
return (
|
|
220
|
+
<g class:list={['node', 'icon-node', tone]} data-step={step}>
|
|
221
|
+
<circle class="disc" cx={n.x} cy={n.y} r={w / 2} />
|
|
222
|
+
{n.icon && (
|
|
223
|
+
<svg x={n.x - 15} y={n.y - 15} width="30" height="30" viewBox="0 0 24 24" class="glyph" set:html={ICONS[n.icon]} />
|
|
224
|
+
)}
|
|
225
|
+
<text class="name" x={n.x} y={n.y + w / 2 + 24}>{n.label}</text>
|
|
226
|
+
{n.sub?.split('\n').map((s, i) => <text class="sub" x={n.x} y={n.y + w / 2 + 44 + i * 18}>{s}</text>)}
|
|
227
|
+
</g>
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
if (n.shape === 'circle') {
|
|
231
|
+
const ls = lines(n.label);
|
|
232
|
+
return (
|
|
233
|
+
<g class:list={['node', 'circle-node', tone]} data-step={step}>
|
|
234
|
+
<circle class="disc" cx={n.x} cy={n.y} r={w / 2} />
|
|
235
|
+
{ls.map((l, i) => (
|
|
236
|
+
<text class="name" x={n.x} y={n.y + (i - (ls.length - 1) / 2) * 19 + 5}>
|
|
237
|
+
{l}
|
|
238
|
+
</text>
|
|
239
|
+
))}
|
|
240
|
+
</g>
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
return (
|
|
244
|
+
<g class:list={['node', 'pill-node', tone]} data-step={step}>
|
|
245
|
+
<rect class="disc" x={n.x - w / 2} y={n.y - h / 2} width={w} height={h} rx={h / 2} />
|
|
246
|
+
{n.icon && <svg x={n.x - w / 2 + 16} y={n.y - 10} width="20" height="20" viewBox="0 0 24 24" class="glyph" set:html={ICONS[n.icon]} />}
|
|
247
|
+
<text class="name" x={n.icon ? n.x + 12 : n.x} y={n.y + 5}>{n.label}</text>
|
|
248
|
+
</g>
|
|
249
|
+
);
|
|
250
|
+
})
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
{
|
|
254
|
+
note && (
|
|
255
|
+
<g class="note" data-step={Math.max(...drawn.map((e) => e.step), 0) + 1}>
|
|
256
|
+
{note.lines.map((l, i) => (
|
|
257
|
+
<text x={note.x} y={note.y + i * 22} class:list={[i === 0 && 'note-head', l.tone]}>
|
|
258
|
+
{l.text}
|
|
259
|
+
</text>
|
|
260
|
+
))}
|
|
261
|
+
</g>
|
|
262
|
+
)
|
|
263
|
+
}
|
|
264
|
+
</svg>
|
|
265
|
+
</div>
|
|
266
|
+
{caption && <figcaption>{caption}</figcaption>}
|
|
267
|
+
</figure>
|
|
268
|
+
|
|
269
|
+
<script>
|
|
270
|
+
// One step is a beat. Arm only what is below the fold, so a diagram already on screen
|
|
271
|
+
// never blinks out, and start the pulses once their line has drawn.
|
|
272
|
+
const STEP = 220;
|
|
273
|
+
if (matchMedia('(prefers-reduced-motion: no-preference)').matches) {
|
|
274
|
+
document.querySelectorAll<HTMLElement>('[data-flow]').forEach((fig) => {
|
|
275
|
+
if (fig.getBoundingClientRect().top < innerHeight * 0.85) return;
|
|
276
|
+
fig.classList.add('armed');
|
|
277
|
+
const io = new IntersectionObserver(
|
|
278
|
+
(entries) => {
|
|
279
|
+
if (!entries.some((e) => e.isIntersecting)) return;
|
|
280
|
+
io.disconnect();
|
|
281
|
+
fig.querySelectorAll<SVGElement>('[data-step]').forEach((el) => el.style.setProperty('--d', `${Number(el.dataset.step) * STEP}ms`));
|
|
282
|
+
fig.classList.replace('armed', 'in');
|
|
283
|
+
let last = 0;
|
|
284
|
+
fig.querySelectorAll<SVGGElement>('.edge').forEach((g) => {
|
|
285
|
+
const at = Number(g.dataset.step) * STEP + 900;
|
|
286
|
+
last = Math.max(last, at);
|
|
287
|
+
const m = g.querySelector<SVGAnimationElement>('animateMotion');
|
|
288
|
+
if (m) setTimeout(() => (g.classList.add('flowing'), m.beginElement()), at);
|
|
289
|
+
});
|
|
290
|
+
},
|
|
291
|
+
{ rootMargin: '0px 0px -15% 0px' },
|
|
292
|
+
);
|
|
293
|
+
io.observe(fig);
|
|
294
|
+
});
|
|
295
|
+
// On screen from the start: the pulses still run, a beat after load.
|
|
296
|
+
document.querySelectorAll<HTMLElement>('[data-flow]:not(.armed) .edge').forEach((g) => {
|
|
297
|
+
const m = g.querySelector<SVGAnimationElement>('animateMotion');
|
|
298
|
+
if (m) setTimeout(() => (g.classList.add('flowing'), m.beginElement()), 600);
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
</script>
|
|
302
|
+
|
|
303
|
+
<style>
|
|
304
|
+
.flow {
|
|
305
|
+
margin-block: var(--sp-7);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
.scroll {
|
|
309
|
+
overflow-x: auto;
|
|
310
|
+
background: var(--c-surface-sunken);
|
|
311
|
+
border: 1px solid var(--c-border);
|
|
312
|
+
border-radius: var(--radius-lg);
|
|
313
|
+
padding: var(--sp-6) var(--sp-5);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
svg {
|
|
317
|
+
display: block;
|
|
318
|
+
width: 100%;
|
|
319
|
+
height: auto;
|
|
320
|
+
overflow: visible;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
text {
|
|
324
|
+
font-family: var(--font-body);
|
|
325
|
+
text-anchor: middle;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
.name {
|
|
329
|
+
font-weight: 600;
|
|
330
|
+
font-size: 15px;
|
|
331
|
+
fill: var(--c-text);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
.sub {
|
|
335
|
+
font-size: 13px;
|
|
336
|
+
fill: var(--c-text-muted);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/* Nodes. Tint and border carry the tone, never a saturated slab, except `solid`, the one
|
|
340
|
+
* node a diagram is about. */
|
|
341
|
+
.disc {
|
|
342
|
+
fill: var(--c-surface);
|
|
343
|
+
stroke: var(--c-diagram-edge);
|
|
344
|
+
stroke-width: 1.5;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
.accent .disc {
|
|
348
|
+
fill: var(--c-surface-tint);
|
|
349
|
+
stroke: var(--c-accent-edge);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
.cool .disc {
|
|
353
|
+
fill: var(--c-tag-cool-bg);
|
|
354
|
+
stroke: color-mix(in oklab, var(--c-tag-cool-text) 45%, transparent);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
.solid .disc {
|
|
358
|
+
fill: var(--c-accent);
|
|
359
|
+
stroke: var(--c-accent);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
.solid .name {
|
|
363
|
+
fill: var(--c-on-accent);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
.glyph {
|
|
367
|
+
fill: none;
|
|
368
|
+
stroke: currentColor;
|
|
369
|
+
stroke-width: 1.75;
|
|
370
|
+
stroke-linecap: round;
|
|
371
|
+
stroke-linejoin: round;
|
|
372
|
+
color: var(--c-text-accent);
|
|
373
|
+
overflow: visible;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
.cool .glyph {
|
|
377
|
+
color: var(--c-tag-cool-text);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
.ring {
|
|
381
|
+
fill: color-mix(in oklab, var(--c-accent) 5%, transparent);
|
|
382
|
+
stroke: var(--c-accent-edge);
|
|
383
|
+
stroke-width: 1.5;
|
|
384
|
+
stroke-dasharray: 2 5;
|
|
385
|
+
stroke-linecap: round;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/* Edges. */
|
|
389
|
+
.line,
|
|
390
|
+
.head {
|
|
391
|
+
fill: none;
|
|
392
|
+
stroke: var(--c-diagram-line);
|
|
393
|
+
stroke-width: 1.75;
|
|
394
|
+
stroke-linecap: round;
|
|
395
|
+
stroke-linejoin: round;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
.edge.accent .line,
|
|
399
|
+
.edge.accent .head {
|
|
400
|
+
stroke: var(--c-accent);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
.edge.cool .line,
|
|
404
|
+
.edge.cool .head {
|
|
405
|
+
stroke: var(--c-tag-cool-text);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
.edge-label {
|
|
409
|
+
font-size: 13px;
|
|
410
|
+
font-weight: 600;
|
|
411
|
+
fill: var(--c-text-muted);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
.edge.accent .edge-label {
|
|
415
|
+
fill: var(--c-text-accent);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
.edge.cool .edge-label {
|
|
419
|
+
fill: var(--c-tag-cool-text);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
.pulse {
|
|
423
|
+
fill: var(--c-diagram-line);
|
|
424
|
+
opacity: 0;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
.edge.accent .pulse {
|
|
428
|
+
fill: var(--c-accent);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
.edge.cool .pulse {
|
|
432
|
+
fill: var(--c-tag-cool-text);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
.flowing .pulse {
|
|
436
|
+
opacity: 1;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
.note text {
|
|
440
|
+
text-anchor: start;
|
|
441
|
+
font-size: 14px;
|
|
442
|
+
fill: var(--c-text-muted);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
.note .note-head {
|
|
446
|
+
font-weight: 600;
|
|
447
|
+
fill: var(--c-text);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
.note .accent {
|
|
451
|
+
fill: var(--c-text-accent);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/* The build. Armed: everything waits. In: each part plays at its own beat. */
|
|
455
|
+
.armed [data-step] {
|
|
456
|
+
opacity: 0;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
.armed .line {
|
|
460
|
+
stroke-dasharray: 1 1;
|
|
461
|
+
stroke-dashoffset: 1;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
.in [data-step] {
|
|
465
|
+
animation: settle 560ms var(--ease-spring) var(--d, 0ms) both;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
.in .node,
|
|
469
|
+
.in .ring {
|
|
470
|
+
transform-box: fill-box;
|
|
471
|
+
transform-origin: center;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
.in .edge {
|
|
475
|
+
animation: none;
|
|
476
|
+
opacity: 1;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
.in .edge .line {
|
|
480
|
+
animation: draw 700ms cubic-bezier(0.3, 0, 0.2, 1) var(--d, 0ms) both;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
.in .edge .head,
|
|
484
|
+
.in .edge .edge-label {
|
|
485
|
+
animation: land 320ms var(--ease-out) calc(var(--d, 0ms) + 560ms) both;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
.in .ring {
|
|
489
|
+
animation-name: grow;
|
|
490
|
+
animation-duration: 900ms;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
@keyframes settle {
|
|
494
|
+
from {
|
|
495
|
+
opacity: 0;
|
|
496
|
+
scale: 0.92;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
@keyframes grow {
|
|
501
|
+
from {
|
|
502
|
+
opacity: 0;
|
|
503
|
+
scale: 0.8;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
@keyframes draw {
|
|
508
|
+
from {
|
|
509
|
+
stroke-dasharray: 1 1;
|
|
510
|
+
stroke-dashoffset: 1;
|
|
511
|
+
}
|
|
512
|
+
to {
|
|
513
|
+
stroke-dasharray: 1 1;
|
|
514
|
+
stroke-dashoffset: 0;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
@keyframes land {
|
|
519
|
+
from {
|
|
520
|
+
opacity: 0;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
@media (prefers-reduced-motion: reduce) {
|
|
525
|
+
.pulse {
|
|
526
|
+
display: none;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
figcaption {
|
|
531
|
+
margin-top: var(--sp-4);
|
|
532
|
+
font-size: var(--text-body-sm);
|
|
533
|
+
color: var(--c-text-muted);
|
|
534
|
+
max-width: var(--layout-measure);
|
|
535
|
+
}
|
|
536
|
+
</style>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* Highlights the words a heading or lede is about, with a band that sweeps in once. Give each
|
|
4
|
+
* mark its place with `n` when there are several, so they sweep one after the other. The look and
|
|
5
|
+
* the timing live in highlight.css, shared with PageHeader.
|
|
6
|
+
*/
|
|
7
|
+
import './highlight.css';
|
|
8
|
+
|
|
9
|
+
interface Props {
|
|
10
|
+
/** This mark's place among the marks on the page, from 0. */
|
|
11
|
+
n?: number;
|
|
12
|
+
}
|
|
13
|
+
const { n = 0 } = Astro.props;
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
<mark class="highlight" style={`--n: ${n}`}><slot /></mark>
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* A card that is one link, such as a case on an index: a picture in the "media" slot and the
|
|
4
|
+
* argument beside it, or above it once the card is narrow. The whole card is the target.
|
|
5
|
+
*
|
|
6
|
+
* Under a real pointer the card lifts 2px and its picture leans in 2% inside its frame; a press
|
|
7
|
+
* gives a little; the spring brings both back. `transition` names the picture for a
|
|
8
|
+
* cross-document view transition, so it can grow into the same picture on the page it opens
|
|
9
|
+
* (give that one the same name, with view-transition-class: media; page-change.css animates it).
|
|
10
|
+
* Under reduced motion nothing moves, and only the edge and the fill answer the hover.
|
|
11
|
+
*/
|
|
12
|
+
interface Props {
|
|
13
|
+
href: string;
|
|
14
|
+
/** A view-transition-name for the picture, unique on the page. */
|
|
15
|
+
transition?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const { href, transition } = Astro.props;
|
|
19
|
+
const hasMedia = Astro.slots.has('media');
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
<a class="link-card" href={href}>
|
|
23
|
+
<div class:list={['layout', { 'has-media': hasMedia }]}>
|
|
24
|
+
{
|
|
25
|
+
hasMedia && (
|
|
26
|
+
<div class="media" style={transition ? `view-transition-name: ${transition}; view-transition-class: media` : undefined}>
|
|
27
|
+
<slot name="media" />
|
|
28
|
+
</div>
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
<div class="body"><slot /></div>
|
|
32
|
+
</div>
|
|
33
|
+
</a>
|
|
34
|
+
|
|
35
|
+
<style>
|
|
36
|
+
.link-card {
|
|
37
|
+
container-type: inline-size;
|
|
38
|
+
display: block;
|
|
39
|
+
padding: var(--sp-6) var(--sp-7);
|
|
40
|
+
background: var(--c-surface);
|
|
41
|
+
border: 1px solid var(--c-border);
|
|
42
|
+
border-radius: var(--radius-lg);
|
|
43
|
+
color: inherit;
|
|
44
|
+
text-decoration: none;
|
|
45
|
+
transition:
|
|
46
|
+
border-color var(--motion-hover) var(--ease-hover),
|
|
47
|
+
background-color var(--motion-hover) var(--ease-hover),
|
|
48
|
+
translate var(--motion-spring) var(--ease-spring),
|
|
49
|
+
scale var(--motion-base) var(--ease-out);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/* Picture left, argument right. The picture's column is fixed rather than fractional, so the
|
|
53
|
+
* text measure does not shift between cards. Below 640px of card it stacks; the card is the
|
|
54
|
+
* container, so the layout inside it can ask. */
|
|
55
|
+
.has-media {
|
|
56
|
+
display: grid;
|
|
57
|
+
gap: var(--sp-5);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
@container (min-width: 640px) {
|
|
61
|
+
.has-media {
|
|
62
|
+
grid-template-columns: 280px minmax(0, 1fr);
|
|
63
|
+
gap: var(--sp-6);
|
|
64
|
+
align-items: start;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.media {
|
|
69
|
+
overflow: hidden;
|
|
70
|
+
border-radius: var(--radius-sm);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.media > :global(*) {
|
|
74
|
+
display: block;
|
|
75
|
+
width: 100%;
|
|
76
|
+
transition: scale var(--motion-spring) var(--ease-spring);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.body {
|
|
80
|
+
min-width: 0;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.link-card:hover {
|
|
84
|
+
border-color: var(--c-accent-edge);
|
|
85
|
+
background: var(--c-surface-tint);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
@media (hover: hover) {
|
|
89
|
+
.link-card:hover {
|
|
90
|
+
translate: 0 -2px;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.link-card:hover .media > :global(*) {
|
|
94
|
+
scale: 1.02;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.link-card:active {
|
|
99
|
+
scale: 0.99;
|
|
100
|
+
transition-duration: var(--motion-hover), var(--motion-hover), var(--motion-spring), 80ms;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
@media (prefers-reduced-motion: reduce) {
|
|
104
|
+
.link-card,
|
|
105
|
+
.media > :global(*) {
|
|
106
|
+
translate: none !important;
|
|
107
|
+
scale: none !important;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
@media (max-width: 560px) {
|
|
112
|
+
.link-card {
|
|
113
|
+
padding: var(--sp-5);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
</style>
|
package/src/PageHeader.astro
CHANGED
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
* or lede once its data arrives wraps those words in <mark> itself; the sweep plays as they
|
|
10
10
|
* land.
|
|
11
11
|
*/
|
|
12
|
+
import './highlight.css';
|
|
13
|
+
|
|
12
14
|
interface Props {
|
|
13
15
|
eyebrow?: string;
|
|
14
16
|
title: string;
|
|
@@ -103,50 +105,19 @@ const inLede = inTitle ? null : split(lede);
|
|
|
103
105
|
background: var(--c-accent);
|
|
104
106
|
}
|
|
105
107
|
|
|
106
|
-
/*
|
|
107
|
-
*
|
|
108
|
-
* dark. It sweeps in once, a moment after the words land. */
|
|
109
|
-
.text :global(mark) {
|
|
110
|
-
--sweep: color-mix(in oklab, var(--c-accent) 32%, var(--c-bg));
|
|
111
|
-
--band: 0.42em;
|
|
112
|
-
padding-inline: 0.08em;
|
|
113
|
-
margin-inline: -0.08em;
|
|
114
|
-
background: linear-gradient(var(--sweep), var(--sweep)) no-repeat 0 88% / 100% var(--band);
|
|
115
|
-
color: inherit;
|
|
116
|
-
box-decoration-break: clone;
|
|
117
|
-
-webkit-box-decoration-break: clone;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/* In the smaller lede the band is wider and stronger, and the figure takes the body colour,
|
|
121
|
-
* so it reads as clearly as it does in a headline. */
|
|
108
|
+
/* The highlighter itself is highlight.css. In the smaller lede the band is wider and stronger,
|
|
109
|
+
* and the figure takes the body colour, so it reads as clearly as it does in a headline. */
|
|
122
110
|
.lede :global(mark) {
|
|
123
|
-
--
|
|
124
|
-
--band: 0.6em;
|
|
111
|
+
--highlight: color-mix(in oklab, var(--c-accent) 42%, var(--c-bg));
|
|
112
|
+
--highlight-band: 0.6em;
|
|
125
113
|
color: var(--c-text);
|
|
126
114
|
}
|
|
127
115
|
|
|
128
|
-
@media (prefers-reduced-motion: no-preference) {
|
|
129
|
-
.text :global(mark) {
|
|
130
|
-
animation: sweep 700ms var(--ease-out) 300ms both;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
@keyframes sweep {
|
|
135
|
-
from {
|
|
136
|
-
background-size: 0% var(--band);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
116
|
@media (forced-colors: active) {
|
|
141
117
|
.rule {
|
|
142
118
|
background: CanvasText;
|
|
143
119
|
}
|
|
144
120
|
|
|
145
|
-
.text :global(mark) {
|
|
146
|
-
background: none;
|
|
147
|
-
text-decoration: underline 0.2em;
|
|
148
|
-
text-underline-offset: 0.1em;
|
|
149
|
-
}
|
|
150
121
|
}
|
|
151
122
|
|
|
152
123
|
.actions {
|
package/src/Reveal.astro
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* Lets something settle in once, as it comes a little way into view: it rises 24px and fades in.
|
|
4
|
+
* Only what starts below the fold is held back, so nothing on screen at load ever disappears.
|
|
5
|
+
* Items that arrive together go 90ms apart. A jump past items (an anchor, a fast fling) shows the
|
|
6
|
+
* ones it skipped at once, so nothing is left hidden above.
|
|
7
|
+
*
|
|
8
|
+
* Hidden only once the script has armed it, so without script, or with reduced motion, it is
|
|
9
|
+
* simply there. Each item fires `reveal` with its delay in `detail`, for a page that wants to
|
|
10
|
+
* start something of its own as it arrives.
|
|
11
|
+
*/
|
|
12
|
+
interface Props {
|
|
13
|
+
/** The element to render, such as "li" for a row of a list. */
|
|
14
|
+
as?: string;
|
|
15
|
+
class?: string;
|
|
16
|
+
[attr: string]: unknown;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const { as: Element = 'div', class: className, ...rest } = Astro.props;
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
<Element class:list={[className]} data-reveal {...rest}><slot /></Element>
|
|
23
|
+
|
|
24
|
+
<style is:global>
|
|
25
|
+
[data-reveal].reveal-armed {
|
|
26
|
+
opacity: 0;
|
|
27
|
+
translate: 0 24px;
|
|
28
|
+
transition:
|
|
29
|
+
opacity 600ms var(--ease-out),
|
|
30
|
+
translate 900ms var(--ease-soft);
|
|
31
|
+
transition-delay: var(--reveal-delay, 0ms);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
[data-reveal].reveal-armed.reveal-in {
|
|
35
|
+
opacity: 1;
|
|
36
|
+
translate: 0 0;
|
|
37
|
+
}
|
|
38
|
+
</style>
|
|
39
|
+
|
|
40
|
+
<script>
|
|
41
|
+
if (matchMedia('(prefers-reduced-motion: no-preference)').matches) {
|
|
42
|
+
const items = [...document.querySelectorAll<HTMLElement>('[data-reveal]')].filter(
|
|
43
|
+
(el) => el.getBoundingClientRect().top > innerHeight,
|
|
44
|
+
);
|
|
45
|
+
const show = (el: HTMLElement, delay: number) => {
|
|
46
|
+
el.style.setProperty('--reveal-delay', `${delay}ms`);
|
|
47
|
+
el.classList.add('reveal-in');
|
|
48
|
+
el.dispatchEvent(new CustomEvent('reveal', { detail: { delay } }));
|
|
49
|
+
io.unobserve(el);
|
|
50
|
+
};
|
|
51
|
+
const io = new IntersectionObserver(
|
|
52
|
+
(entries) => {
|
|
53
|
+
entries
|
|
54
|
+
.filter((e) => e.isIntersecting)
|
|
55
|
+
.forEach((e, i) => {
|
|
56
|
+
const el = e.target as HTMLElement;
|
|
57
|
+
items.slice(0, items.indexOf(el)).filter((s) => !s.classList.contains('reveal-in')).forEach((s) => show(s, 0));
|
|
58
|
+
show(el, i * 90);
|
|
59
|
+
});
|
|
60
|
+
},
|
|
61
|
+
{ rootMargin: '0px 0px -12% 0px' },
|
|
62
|
+
);
|
|
63
|
+
items.forEach((el) => {
|
|
64
|
+
el.classList.add('reveal-armed');
|
|
65
|
+
io.observe(el);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
</script>
|
package/src/Tag.astro
CHANGED
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
* quiet → this is a descriptor, not something to click
|
|
9
9
|
* warm → a warm tag: how something was done
|
|
10
10
|
* cool → the cool tag: what something was about
|
|
11
|
+
*
|
|
12
|
+
* A linked tag lifts 2px under a real pointer and gives under a press, and the spring brings it
|
|
13
|
+
* back. `still` turns that off, for a tag inside something that moves as a whole (CopyTag).
|
|
11
14
|
*/
|
|
12
15
|
import Icon from './Icon.astro';
|
|
13
16
|
import type { IconName } from './icons';
|
|
@@ -17,13 +20,15 @@ interface Props {
|
|
|
17
20
|
href?: string;
|
|
18
21
|
tone?: 'accent' | 'quiet' | 'warm' | 'cool';
|
|
19
22
|
small?: boolean;
|
|
23
|
+
/** No lift or press, for a linked tag inside something that moves as a whole. */
|
|
24
|
+
still?: boolean;
|
|
20
25
|
}
|
|
21
26
|
|
|
22
|
-
const { icon, href, tone = 'quiet', small = false } = Astro.props;
|
|
27
|
+
const { icon, href, tone = 'quiet', small = false, still = false } = Astro.props;
|
|
23
28
|
const Tag = href ? 'a' : 'span';
|
|
24
29
|
---
|
|
25
30
|
|
|
26
|
-
<Tag class:list={['tag', tone, { small }]} href={href}>
|
|
31
|
+
<Tag class:list={['tag', tone, { small, still }]} href={href}>
|
|
27
32
|
{icon && <Icon name={icon} size={15} />}
|
|
28
33
|
<slot />
|
|
29
34
|
</Tag>
|
|
@@ -72,7 +77,27 @@ const Tag = href ? 'a' : 'span';
|
|
|
72
77
|
a.tag {
|
|
73
78
|
transition:
|
|
74
79
|
border-color var(--motion-hover) var(--ease-hover),
|
|
75
|
-
background-color var(--motion-hover) var(--ease-hover)
|
|
80
|
+
background-color var(--motion-hover) var(--ease-hover),
|
|
81
|
+
translate var(--motion-spring) var(--ease-spring),
|
|
82
|
+
scale var(--motion-base) var(--ease-out);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@media (hover: hover) {
|
|
86
|
+
a.tag:not(.still):hover {
|
|
87
|
+
translate: 0 -2px;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
a.tag:not(.still):active {
|
|
92
|
+
scale: 0.97;
|
|
93
|
+
transition-duration: var(--motion-hover), var(--motion-hover), var(--motion-spring), 80ms;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
@media (prefers-reduced-motion: reduce) {
|
|
97
|
+
a.tag {
|
|
98
|
+
translate: none !important;
|
|
99
|
+
scale: none !important;
|
|
100
|
+
}
|
|
76
101
|
}
|
|
77
102
|
|
|
78
103
|
a.quiet:hover {
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The highlighter: a band behind the words a page is about. It sits low, like a pen, wraps line
|
|
3
|
+
* by line, and is mixed into the page colour rather than see-through, so it holds up in dark. It
|
|
4
|
+
* sweeps in once, a moment after the words land; several marks go one after the other, by --n.
|
|
5
|
+
*
|
|
6
|
+
* Used by Highlight and PageHeader. A page that writes its words once its data arrives can wrap
|
|
7
|
+
* them in <mark class="highlight"> itself, and the sweep plays as they land.
|
|
8
|
+
*
|
|
9
|
+
* --highlight the band colour
|
|
10
|
+
* --highlight-band its height
|
|
11
|
+
* --highlight-delay before the first mark sweeps (300ms)
|
|
12
|
+
* --highlight-step between one mark and the next (450ms)
|
|
13
|
+
*/
|
|
14
|
+
:where(mark.highlight, .page-header .text mark) {
|
|
15
|
+
--highlight: color-mix(in oklab, var(--c-accent) 32%, var(--c-bg));
|
|
16
|
+
--highlight-band: 0.42em;
|
|
17
|
+
padding-inline: 0.08em;
|
|
18
|
+
margin-inline: -0.08em;
|
|
19
|
+
background: linear-gradient(var(--highlight), var(--highlight)) no-repeat 0 88% / 100% var(--highlight-band);
|
|
20
|
+
color: inherit;
|
|
21
|
+
box-decoration-break: clone;
|
|
22
|
+
-webkit-box-decoration-break: clone;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
26
|
+
:where(mark.highlight, .page-header .text mark) {
|
|
27
|
+
animation: highlight 700ms var(--ease-out)
|
|
28
|
+
calc(var(--highlight-delay, 300ms) + var(--n, 0) * var(--highlight-step, 450ms)) both;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@keyframes highlight {
|
|
33
|
+
from {
|
|
34
|
+
background-size: 0% var(--highlight-band);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@media (forced-colors: active) {
|
|
39
|
+
:where(mark.highlight, .page-header .text mark) {
|
|
40
|
+
background: none;
|
|
41
|
+
text-decoration: underline 0.2em;
|
|
42
|
+
text-underline-offset: 0.1em;
|
|
43
|
+
}
|
|
44
|
+
}
|
package/src/icons.ts
CHANGED
|
@@ -64,6 +64,13 @@ export const ICONS = {
|
|
|
64
64
|
'<path d="M16 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2h1a1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z"/><path d="M5 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2h1a1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z"/>',
|
|
65
65
|
'message-square':
|
|
66
66
|
'<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/>',
|
|
67
|
+
'utility-pole':
|
|
68
|
+
'<path d="M12 2v20"/><path d="M2 5h20"/><path d="M3 3v2"/><path d="M7 3v2"/><path d="M17 3v2"/><path d="M21 3v2"/><path d="m19 5-7 7-7-7"/>',
|
|
69
|
+
'house-plug':
|
|
70
|
+
'<path d="M10 12V8.964"/><path d="M14 12V8.964"/><path d="M15 12a1 1 0 0 1 1 1v2a2 2 0 0 1-2 2h-4a2 2 0 0 1-2-2v-2a1 1 0 0 1 1-1z"/><path d="M8.5 21H5a2 2 0 0 1-2-2v-9a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2h-5a2 2 0 0 1-2-2v-2"/>',
|
|
71
|
+
'building-2':
|
|
72
|
+
'<path d="M10 12h4"/><path d="M10 8h4"/><path d="M14 21v-3a2 2 0 0 0-4 0v3"/><path d="M6 10H4a2 2 0 0 0-2 2v7a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-2"/><path d="M6 21V5a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v16"/>',
|
|
73
|
+
car: '<path d="M19 17h2c.6 0 1-.4 1-1v-3c0-.9-.7-1.7-1.5-1.9C18.7 10.6 16 10 16 10s-1.3-1.4-2.2-2.3c-.5-.4-1.1-.7-1.8-.7H5c-.6 0-1.1.4-1.4.9l-1.4 2.9A3.7 3.7 0 0 0 2 12v4c0 .6.4 1 1 1h2"/><circle cx="7" cy="17" r="2"/><path d="M9 17h6"/><circle cx="17" cy="17" r="2"/>',
|
|
67
74
|
} as const;
|
|
68
75
|
|
|
69
76
|
export type IconName = keyof typeof ICONS;
|
package/src/page-change.css
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Moving between pages: a short cross-fade of the whole page,
|
|
3
|
-
*
|
|
2
|
+
* Moving between pages: a short cross-fade of the whole page, PageNav's pill gliding from the
|
|
3
|
+
* link you left to the one you arrived at, and a picture with view-transition-class: media (a
|
|
4
|
+
* LinkCard's, say) growing into the picture of the same name on the next page, all on the spring. For a site whose pages are
|
|
4
5
|
* separate documents. Import once, per site, on every page: both pages must opt in.
|
|
5
6
|
*
|
|
6
7
|
* A browser without cross-document view transitions simply changes the page, and under
|
|
@@ -34,4 +35,23 @@
|
|
|
34
35
|
width: 100%;
|
|
35
36
|
height: 100%;
|
|
36
37
|
}
|
|
38
|
+
|
|
39
|
+
/* A picture that carries over, such as a case thumbnail becoming that case's header image. */
|
|
40
|
+
::view-transition-group(*.media) {
|
|
41
|
+
animation-duration: var(--motion-spring);
|
|
42
|
+
animation-timing-function: var(--ease-spring);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/* The two pictures rarely share a shape (a 16:9 thumbnail, a 20:9 header), so each fills the
|
|
46
|
+
* moving frame and is cropped to it, rather than stretched. */
|
|
47
|
+
::view-transition-image-pair(*.media) {
|
|
48
|
+
overflow: hidden;
|
|
49
|
+
border-radius: var(--radius-lg);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
::view-transition-old(*.media),
|
|
53
|
+
::view-transition-new(*.media) {
|
|
54
|
+
height: 100%;
|
|
55
|
+
object-fit: cover;
|
|
56
|
+
}
|
|
37
57
|
}
|