@n1kname/components 0.38.0 → 0.40.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.38.0",
3
+ "version": "0.40.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -33,7 +33,7 @@
33
33
  "./cardlist.js": "./src/cardlist.js"
34
34
  },
35
35
  "dependencies": {
36
- "@n1kname/charts": "0.12.0"
36
+ "@n1kname/charts": "0.14.0"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "@n1kname/tokens": "^0.7.0",
@@ -0,0 +1,280 @@
1
+ ---
2
+ /**
3
+ * Two or three screens overlapping on a tinted panel: a case cover, or the same picture small on
4
+ * an index card. Built in code rather than flattened into one image, so each screen stays sharp,
5
+ * goes through astro:assets, and can move on its own.
6
+ *
7
+ * The first screen sits in front, low and left; the others step up and right behind it.
8
+ *
9
+ * Motion, all of it off under reduced motion:
10
+ * - The screens play in once, front first, rising a little as they fade in.
11
+ * - `size="cover"`: under a real pointer, the screens follow it a few pixels, the front one most,
12
+ * so the stack reads as layers. Leaves no listener behind when there is no fine pointer.
13
+ * - `size="card"`: when the link around it is hovered or focused (a LinkCard), the screens fan
14
+ * out a little, as if the stack were picked up.
15
+ *
16
+ * `device="phone"` lays tall phone screens side by side instead, stepping up and right, each in a
17
+ * thin dark bezel with rounded corners. Give it the screen alone, without a device frame.
18
+ *
19
+ * A picture is an imported image (it goes through astro:assets, sized and converted to webp) or a
20
+ * plain URL. `note` labels the panel, such as "Concepts, made-up data", for screens that are not
21
+ * shipped work: keep it short on a card.
22
+ */
23
+ import type { ImageMetadata } from 'astro';
24
+ import { Image } from 'astro:assets';
25
+
26
+ interface Screen {
27
+ image: ImageMetadata | string;
28
+ alt: string;
29
+ }
30
+
31
+ interface Props {
32
+ /** Two or three; any more are left out. The first sits in front. */
33
+ screens: Screen[];
34
+ /** The panel colour: a CSS colour, deep enough for white text, such as a client's brand blue. */
35
+ tone?: string;
36
+ note?: string;
37
+ /** `cover` is a 20:9 header band; `card` a 16:9 picture for a LinkCard's media slot. */
38
+ size?: 'cover' | 'card';
39
+ /** `laptop` for wide screens (the default), `phone` for tall ones. */
40
+ device?: 'laptop' | 'phone';
41
+ /** A view-transition-name, so a card's stack can grow into the cover on the page it opens. */
42
+ transition?: string;
43
+ /** Load the front screen first, for a cover above the fold. */
44
+ eager?: boolean;
45
+ /** Follow the pointer. On by default for a cover; a card fans out on hover instead. */
46
+ parallax?: boolean;
47
+ class?: string;
48
+ }
49
+
50
+ const { screens, tone = 'var(--c-accent)', note, size = 'cover', device = 'laptop', transition, eager = size === 'cover', parallax = size === 'cover', class: className } = Astro.props;
51
+ const shots = screens.slice(0, 3);
52
+ // Back to front, so the first screen paints last and sits on top.
53
+ const order = [...shots.keys()].reverse();
54
+ const phone = device === 'phone';
55
+ const widths = phone ? (size === 'cover' ? [240, 480, 720] : [160, 320]) : size === 'cover' ? [480, 900, 1400] : [400, 800];
56
+ const sizes = phone
57
+ ? size === 'cover' ? '(max-width: 640px) 30vw, 230px' : '(max-width: 640px) 22vw, 70px'
58
+ : size === 'cover' ? '(max-width: 900px) 80vw, 760px' : '(max-width: 640px) 70vw, 220px';
59
+ const fit = (img: ImageMetadata) => [...new Set(widths.filter((w) => w <= img.width))];
60
+ ---
61
+
62
+ <div
63
+ class:list={['screen-stack', size, device, `n${shots.length}`, className]}
64
+ style={`--stack-tone: ${tone};${transition ? ` view-transition-name: ${transition}; view-transition-class: media;` : ''}`}
65
+ data-screen-stack-parallax={parallax ? '' : undefined}
66
+ >
67
+ {note && <p class="note">{note}</p>}
68
+ {
69
+ order.map((i) => {
70
+ const s = shots[i];
71
+ const first = i === 0;
72
+ return (
73
+ <div class={`screen s${i}`}>
74
+ {typeof s.image === 'string' ? (
75
+ <img src={s.image} alt={s.alt} loading={eager && first ? 'eager' : 'lazy'} />
76
+ ) : (
77
+ <Image
78
+ src={s.image}
79
+ alt={s.alt}
80
+ widths={fit(s.image).length ? fit(s.image) : [s.image.width]}
81
+ sizes={sizes}
82
+ format="webp"
83
+ quality={82}
84
+ loading={eager && first ? 'eager' : 'lazy'}
85
+ fetchpriority={eager && first ? 'high' : 'auto'}
86
+ />
87
+ )}
88
+ </div>
89
+ );
90
+ })
91
+ }
92
+ </div>
93
+
94
+ <script>
95
+ // The cover's layers follow the pointer: a fraction of the way, eased by a CSS transition, the
96
+ // front screen most. Only where there is a fine pointer and motion is welcome.
97
+ const fine = matchMedia('(hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference)');
98
+ const stacks = document.querySelectorAll<HTMLElement>('[data-screen-stack-parallax]');
99
+ if (fine.matches) {
100
+ for (const el of stacks) {
101
+ let frame = 0;
102
+ el.addEventListener('pointermove', (e) => {
103
+ cancelAnimationFrame(frame);
104
+ frame = requestAnimationFrame(() => {
105
+ const r = el.getBoundingClientRect();
106
+ el.style.setProperty('--px', (((e.clientX - r.left) / r.width) * 2 - 1).toFixed(3));
107
+ el.style.setProperty('--py', (((e.clientY - r.top) / r.height) * 2 - 1).toFixed(3));
108
+ });
109
+ });
110
+ el.addEventListener('pointerleave', () => {
111
+ cancelAnimationFrame(frame);
112
+ el.style.setProperty('--px', '0');
113
+ el.style.setProperty('--py', '0');
114
+ });
115
+ }
116
+ }
117
+ </script>
118
+
119
+ <style>
120
+ .screen-stack {
121
+ --px: 0;
122
+ --py: 0;
123
+ position: relative;
124
+ overflow: hidden;
125
+ container-type: inline-size;
126
+ aspect-ratio: 20 / 9;
127
+ border-radius: var(--radius-lg);
128
+ background:
129
+ radial-gradient(circle at 1px 1px, rgb(255 255 255 / 0.14) 1px, transparent 0) 0 0 / 22px 22px,
130
+ linear-gradient(
131
+ 140deg,
132
+ color-mix(in oklab, var(--stack-tone), white 12%),
133
+ var(--stack-tone) 55%,
134
+ color-mix(in oklab, var(--stack-tone), black 28%)
135
+ );
136
+ }
137
+
138
+ .card {
139
+ aspect-ratio: 16 / 9;
140
+ border-radius: var(--radius-sm);
141
+ background-size: 14px 14px, auto;
142
+ }
143
+
144
+ .note {
145
+ position: absolute;
146
+ top: var(--sp-5);
147
+ left: var(--sp-6);
148
+ z-index: 4;
149
+ margin: 0;
150
+ padding: 4px var(--sp-3);
151
+ border-radius: var(--radius-full);
152
+ background: rgb(255 255 255 / 0.16);
153
+ color: #fff;
154
+ font-size: var(--text-caption);
155
+ line-height: 1.4;
156
+ letter-spacing: 0.02em;
157
+ }
158
+
159
+ .card .note {
160
+ top: var(--sp-2);
161
+ left: var(--sp-2);
162
+ padding: 1px var(--sp-2);
163
+ font-size: 11px;
164
+ }
165
+
166
+ .screen {
167
+ position: absolute;
168
+ width: 58%;
169
+ border-radius: 10px;
170
+ overflow: hidden;
171
+ box-shadow:
172
+ 0 1px 2px rgb(0 0 0 / 0.18),
173
+ 0 24px 60px -12px rgb(0 0 0 / 0.45);
174
+ transition: transform 700ms var(--ease-soft, cubic-bezier(0.16, 1, 0.3, 1));
175
+ }
176
+
177
+ .screen :global(img) {
178
+ display: block;
179
+ width: 100%;
180
+ height: auto;
181
+ }
182
+
183
+ /* Front screen low and left, the others stepping up and right behind it. */
184
+ .s0 { left: 8%; top: 30%; z-index: 3; }
185
+ .s1 { left: 25%; top: 18%; z-index: 2; }
186
+ .s2 { left: 42%; top: 8%; z-index: 1; }
187
+ .n2 .s0 { left: 12%; }
188
+ .n2 .s1 { left: 36%; top: 12%; }
189
+
190
+ .card .screen {
191
+ width: 66%;
192
+ border-radius: 4px;
193
+ box-shadow:
194
+ 0 1px 2px rgb(0 0 0 / 0.2),
195
+ 0 10px 24px -8px rgb(0 0 0 / 0.5);
196
+ }
197
+ .card .s0 { left: 6%; top: 34%; }
198
+ .card .s1 { left: 18%; top: 21%; }
199
+ .card .s2 { left: 30%; top: 8%; }
200
+ .card.n2 .s0 { left: 8%; top: 30%; }
201
+ .card.n2 .s1 { left: 28%; top: 12%; }
202
+
203
+ /* Phones: tall screens stepping up and right, in a thin bezel. */
204
+ .phone .screen {
205
+ width: 19%;
206
+ border-radius: 11% / 5%;
207
+ box-shadow:
208
+ 0 0 0 3px rgb(18 18 20),
209
+ 0 1px 2px rgb(0 0 0 / 0.2),
210
+ 0 24px 50px -10px rgb(0 0 0 / 0.5);
211
+ }
212
+ .phone .s0 { left: 27%; top: 14%; }
213
+ .phone .s1 { left: 41%; top: 8%; }
214
+ .phone .s2 { left: 55%; top: 2%; }
215
+ .phone.n2 .s0 { left: 34%; }
216
+ .phone.n2 .s1 { left: 48%; top: 6%; }
217
+
218
+ .card.phone .screen {
219
+ width: 22%;
220
+ box-shadow:
221
+ 0 0 0 2px rgb(18 18 20),
222
+ 0 8px 18px -6px rgb(0 0 0 / 0.5);
223
+ }
224
+ .card.phone .s0 { left: 23%; top: 18%; }
225
+ .card.phone .s1 { left: 39%; top: 10%; }
226
+ .card.phone .s2 { left: 55%; top: 2%; }
227
+
228
+ @media (prefers-reduced-motion: no-preference) {
229
+ .screen {
230
+ animation: stack-in var(--motion-reveal, 900ms) var(--ease-soft, cubic-bezier(0.16, 1, 0.3, 1)) both;
231
+ }
232
+ .s1 { animation-delay: 90ms; }
233
+ .s2 { animation-delay: 180ms; }
234
+
235
+ /* The cover's layers follow the pointer, the front one most. */
236
+ [data-screen-stack-parallax] .s0 { transform: translate(calc(var(--px) * 10px), calc(var(--py) * 8px)); }
237
+ [data-screen-stack-parallax] .s1 { transform: translate(calc(var(--px) * 6px), calc(var(--py) * 5px)); }
238
+ [data-screen-stack-parallax] .s2 { transform: translate(calc(var(--px) * 3px), calc(var(--py) * 2px)); }
239
+
240
+ /* A card's stack fans out when the link around it is hovered or focused. */
241
+ :global(a:is(:hover, :focus-visible)) .card .s0 { transform: translate(-4%, 3%) rotate(-1deg); }
242
+ :global(a:is(:hover, :focus-visible)) .card .s1 { transform: translate(0, -2%); }
243
+ :global(a:is(:hover, :focus-visible)) .card .s2 { transform: translate(5%, -6%) rotate(1deg); }
244
+ }
245
+
246
+ @keyframes stack-in {
247
+ from {
248
+ opacity: 0;
249
+ translate: 0 24px;
250
+ }
251
+ }
252
+
253
+ /* A cover in a narrow column: taller, two screens, larger. */
254
+ @container (max-width: 560px) {
255
+ .cover .note {
256
+ top: var(--sp-3);
257
+ left: var(--sp-3);
258
+ }
259
+ }
260
+
261
+ @media (max-width: 640px) {
262
+ .cover {
263
+ aspect-ratio: 4 / 3;
264
+ }
265
+ .cover.laptop .screen {
266
+ width: 78%;
267
+ }
268
+ .cover.laptop .s0 { left: 6%; top: 34%; }
269
+ .cover.laptop .s1 { left: 16%; top: 20%; }
270
+ .cover.laptop .s2 { display: none; }
271
+
272
+ /* Phones keep all three, larger, overlapping more. */
273
+ .cover.phone .screen {
274
+ width: 30%;
275
+ }
276
+ .cover.phone .s0 { left: 12%; top: 14%; }
277
+ .cover.phone .s1 { left: 35%; top: 9%; }
278
+ .cover.phone .s2 { left: 58%; top: 4%; }
279
+ }
280
+ </style>