@n1kname/components 0.25.0 → 0.26.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.26.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -72,7 +72,7 @@ const small = (x: number) => rounded([[x + 4, 50], [x + 50, 18], [x + 96, 50], [
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,6 +102,7 @@ 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>
@@ -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%;
@@ -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,16 @@ const columns = items.map((it) => (it.kind === 'moment' ? 'auto' : it.phase.repe
285
319
  stroke-dasharray: 3 4;
286
320
  }
287
321
 
322
+ .link {
323
+ stroke: var(--c-diagram-line);
324
+ stroke-width: 1.5;
325
+ }
326
+
288
327
  /* Each label centred on its half's own middle, a third of the way in from its point, at one
289
328
  * size wherever the diamond is drawn. */
290
329
  .halves {
291
330
  position: absolute;
331
+ z-index: 2;
292
332
  inset: 0;
293
333
  margin: 0;
294
334
  color: var(--c-text);
@@ -389,6 +429,11 @@ const columns = items.map((it) => (it.kind === 'moment' ? 'auto' : it.phase.repe
389
429
  gap: var(--sp-3);
390
430
  }
391
431
 
432
+ .stop-cell::before,
433
+ .stop-cell::after {
434
+ display: none;
435
+ }
436
+
392
437
  .moment-label {
393
438
  position: static;
394
439
  }
@@ -68,9 +68,23 @@ interface Props {
68
68
  caption?: string;
69
69
  /** Narrowest the drawing may get before it scrolls instead. */
70
70
  minWidth?: number;
71
+ /**
72
+ * A second drawing of the same diagram for a narrow screen, below 560px wide: its own size, where
73
+ * each node sits (by id; label, shape and tone come from `nodes`), and its own edges, rings and
74
+ * note. It fits the width instead of scrolling, so draw it about 360 to 420 wide.
75
+ */
76
+ narrow?: {
77
+ width: number;
78
+ height: number;
79
+ /** `icon: false` leaves a pill's icon out where the narrow pill is too short for it. */
80
+ nodes: { id: string; x: number; y: number; w?: number; h?: number; icon?: IconName | false }[];
81
+ edges: Edge[];
82
+ rings?: Ring[];
83
+ note?: { x: number; y: number; lines: { text: string; tone?: Tone }[] };
84
+ };
71
85
  }
72
86
 
73
- const { title, desc, width, height, nodes, edges, rings = [], note, caption, minWidth = 640 } = Astro.props;
87
+ const { title, desc, width, height, nodes, edges, rings = [], note, caption, minWidth = 640, narrow } = Astro.props;
74
88
  // Ids from the title, so two diagrams on a page don't collide and a build stays the same.
75
89
  let hash = 0;
76
90
  for (const c of title) hash = (hash * 31 + c.charCodeAt(0)) | 0;
@@ -81,7 +95,6 @@ const size = (n: Node) => {
81
95
  if (n.shape === 'icon') return { w: n.w ?? 64, h: n.w ?? 64 };
82
96
  return { w: n.w ?? 200, h: n.h ?? 44 };
83
97
  };
84
- const byId = new Map(nodes.map((n) => [n.id, n]));
85
98
 
86
99
  const anchor = (n: Node, side: Side, shift = 0): [number, number] => {
87
100
  const { w, h } = size(n);
@@ -152,7 +165,9 @@ const longest = (pts: [number, number][]): [number, number] => {
152
165
  return at;
153
166
  };
154
167
 
155
- const drawn = edges.map((e) => {
168
+ const draw = (ns: Node[], es: Edge[]) => {
169
+ const byId = new Map(ns.map((n) => [n.id, n]));
170
+ return es.map((e) => {
156
171
  const a = anchor(byId.get(e.from)!, e.fromSide, e.fromShift);
157
172
  // Stop short of the target so the arrowhead does not sit on its border.
158
173
  const t = anchor(byId.get(e.to)!, e.toSide, e.toShift);
@@ -161,7 +176,23 @@ const drawn = edges.map((e) => {
161
176
  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
177
  const pts = route(e, a, b);
163
178
  return { ...e, d: rounded(pts), head: head(pts), at: e.labelAt ?? longest(pts), tone: e.tone ?? 'quiet', step: e.step ?? 1 };
164
- });
179
+ });
180
+ };
181
+
182
+ // The drawings: the diagram as given, and its narrow one where there is one.
183
+ const narrowNodes = narrow
184
+ ? narrow.nodes.map((p) => {
185
+ const n = nodes.find((m) => m.id === p.id);
186
+ if (!n) throw new Error(`FlowDiagram "${title}": narrow node "${p.id}" is not in nodes.`);
187
+ return { ...n, ...p, icon: p.icon === false ? undefined : (p.icon ?? n.icon) };
188
+ })
189
+ : [];
190
+ const views = [
191
+ { kind: 'wide', width, height, nodes, drawn: draw(nodes, edges), rings, note, minWidth },
192
+ ...(narrow
193
+ ? [{ kind: 'narrow', width: narrow.width, height: narrow.height, nodes: narrowNodes, drawn: draw(narrowNodes, narrow.edges), rings: narrow.rings ?? [], note: narrow.note, minWidth: 0 }]
194
+ : []),
195
+ ];
165
196
 
166
197
  // Label lines for a circle: break at the space nearest the middle when it is long.
167
198
  const lines = (label: string) => {
@@ -181,11 +212,12 @@ const lines = (label: string) => {
181
212
  };
182
213
  ---
183
214
 
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>
215
+ <figure class:list={['flow', { 'has-narrow': narrow }]} data-flow>
216
+ {views.map(({ kind, width, height, nodes, drawn, rings, note, minWidth }) => (
217
+ <div class:list={['scroll', kind]} tabindex={kind === 'wide' ? '0' : undefined} role={kind === 'wide' ? 'region' : undefined} aria-label={kind === 'wide' ? title : undefined}>
218
+ <svg viewBox={`0 0 ${width} ${height}`} role="img" aria-labelledby={`${uid}-${kind}-t ${uid}-${kind}-d`} style={minWidth ? `min-width: ${minWidth}px` : undefined}>
219
+ <title id={`${uid}-${kind}-t`}>{title}</title>
220
+ <desc id={`${uid}-${kind}-d`}>{desc}</desc>
189
221
 
190
222
  {rings.map((r) => <circle class="ring" data-step={r.step ?? 0} cx={r.cx} cy={r.cy} r={r.r} />)}
191
223
 
@@ -263,6 +295,7 @@ const lines = (label: string) => {
263
295
  }
264
296
  </svg>
265
297
  </div>
298
+ ))}
266
299
  {caption && <figcaption>{caption}</figcaption>}
267
300
  </figure>
268
301
 
@@ -303,6 +336,24 @@ const lines = (label: string) => {
303
336
  <style>
304
337
  .flow {
305
338
  margin-block: var(--sp-7);
339
+ container-type: inline-size;
340
+ }
341
+
342
+ /* With a narrow drawing, it takes over below 560px, fitting the width instead of scrolling. */
343
+ .scroll.narrow {
344
+ display: none;
345
+ }
346
+
347
+ @container (max-width: 560px) {
348
+ .has-narrow .scroll.wide {
349
+ display: none;
350
+ }
351
+
352
+ .has-narrow .scroll.narrow {
353
+ display: block;
354
+ overflow: visible;
355
+ padding: var(--sp-5) var(--sp-3);
356
+ }
306
357
  }
307
358
 
308
359
  .scroll {
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;