@n1kname/components 0.46.0 → 0.47.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.46.0",
3
+ "version": "0.47.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -0,0 +1,108 @@
1
+ ---
2
+ /**
3
+ * A chart drawn at build time, two or three times, on a panel that shows whichever drawing fits
4
+ * its width: the narrow one on a phone, the wide one in a column, and an optional full one from
5
+ * 960px. Each is drawn for its width and never scaled up, so the text stays one size and the chart
6
+ * still fills a wide screen. No script draws it; the charts' `enter` plays it in once when it comes
7
+ * into view.
8
+ *
9
+ * Draw the three with `renderPlot` and pass the SVG strings. `alt` speaks for the chart. A
10
+ * `legend` slot sits under it, inside the panel.
11
+ *
12
+ * `as="div"` makes it one panel of a larger figure, such as two charts side by side under one
13
+ * legend and caption: no outer margin and no caption of its own.
14
+ */
15
+ interface Props {
16
+ /** The drawings, as SVG strings: `narrow` (320), `wide` (about 720) and optionally `full` (960). */
17
+ chart: { narrow: string; wide: string; full?: string };
18
+ alt: string;
19
+ /** A small title at the top of the panel. */
20
+ title?: string;
21
+ caption?: string;
22
+ /** The panel width under which the narrow drawing shows. 560 by default; 420 for a half-width panel. */
23
+ narrowBelow?: 420 | 560;
24
+ as?: 'figure' | 'div';
25
+ class?: string;
26
+ }
27
+
28
+ const { chart, alt, title, caption, narrowBelow = 560, as = 'figure', class: className } = Astro.props;
29
+ const Tag = as;
30
+ ---
31
+
32
+ <Tag class:list={['chart-figure', { panel: as === 'div' }, className]}>
33
+ <div class:list={['frame', `nb-${narrowBelow}`, { 'has-full': chart.full }]} data-chart-figure>
34
+ {title && <p class="title">{title}</p>}
35
+ <div role="img" aria-label={alt}>
36
+ <div class="narrow" set:html={chart.narrow} />
37
+ <div class="wide" set:html={chart.wide} />
38
+ {chart.full && <div class="full" set:html={chart.full} />}
39
+ </div>
40
+ <slot name="legend" />
41
+ </div>
42
+ {as === 'figure' && caption && <figcaption>{caption}</figcaption>}
43
+ </Tag>
44
+
45
+ <script>
46
+ import { enterAll } from '@n1kname/charts/enter';
47
+ enterAll('[data-chart-figure]');
48
+ </script>
49
+
50
+ <style>
51
+ .chart-figure {
52
+ margin-block: var(--sp-6) var(--sp-7);
53
+ }
54
+ .chart-figure.panel {
55
+ margin: 0;
56
+ }
57
+
58
+ .frame {
59
+ container-type: inline-size;
60
+ height: 100%;
61
+ padding: var(--sp-5);
62
+ background: var(--c-surface);
63
+ border: 1px solid var(--c-border);
64
+ border-radius: var(--radius-lg);
65
+ }
66
+
67
+ .title {
68
+ margin: 0 0 var(--sp-3);
69
+ font-size: var(--text-body-sm);
70
+ font-weight: 600;
71
+ color: var(--c-text);
72
+ }
73
+
74
+ .narrow,
75
+ .full {
76
+ display: none;
77
+ }
78
+
79
+ @container (max-width: 560px) {
80
+ .nb-560 .wide { display: none; }
81
+ .nb-560 .narrow { display: block; }
82
+ }
83
+
84
+ @container (max-width: 420px) {
85
+ .nb-420 .wide { display: none; }
86
+ .nb-420 .narrow { display: block; }
87
+ }
88
+
89
+ @container (min-width: 960px) {
90
+ .has-full .wide { display: none; }
91
+ .has-full .full { display: block; }
92
+ }
93
+
94
+ /* Never scaled up, so the text stays its size; centred when the panel is wider. */
95
+ .frame :global(svg) {
96
+ display: block;
97
+ max-width: 100%;
98
+ height: auto;
99
+ margin-inline: auto;
100
+ }
101
+
102
+ figcaption {
103
+ max-width: var(--layout-measure);
104
+ margin-top: var(--sp-4);
105
+ font-size: var(--text-body-sm);
106
+ color: var(--c-text-muted);
107
+ }
108
+ </style>
@@ -0,0 +1,166 @@
1
+ ---
2
+ /**
3
+ * A product screenshot on a sunken plate, with a caption. For long reads such as case studies:
4
+ * the plate gives a light-UI capture a frame of its own, so it doesn't float on the page.
5
+ *
6
+ * An imported image goes through astro:assets: it is drawn at most `maxWidth` wide and served at
7
+ * that width and twice it for sharp screens, never upscaled past what the source holds. An SVG or
8
+ * a plain URL is used as it is.
9
+ *
10
+ * Leave `image` off and a labelled placeholder holds the place at the shot's size, so a page can
11
+ * be written and reviewed before the screenshots exist, and a missing picture is visibly missing
12
+ * rather than a broken icon. `alt` still describes the intended shot: it becomes the placeholder's
13
+ * brief, so writing it is never wasted work.
14
+ *
15
+ * `lightPlate` keeps the light plate in dark mode, for transparent artwork with dark labels.
16
+ */
17
+ import type { ImageMetadata } from 'astro';
18
+ import { Image } from 'astro:assets';
19
+
20
+ interface Props {
21
+ /** The screenshot: an imported image or a URL. Leave off for a placeholder. */
22
+ image?: ImageMetadata | string;
23
+ /** What the shot shows, for a screen reader, and on the placeholder. */
24
+ alt: string;
25
+ caption?: string;
26
+ /** Widest the shot is drawn, in px. Keep it well under the source's width. */
27
+ maxWidth?: number;
28
+ /** The placeholder's size. An image reports its own. */
29
+ width?: number;
30
+ height?: number;
31
+ /** Keep the light plate in dark mode, for transparent artwork with dark labels. */
32
+ lightPlate?: boolean;
33
+ /** The placeholder's label. */
34
+ placeholder?: string;
35
+ class?: string;
36
+ }
37
+
38
+ const {
39
+ image,
40
+ alt,
41
+ caption,
42
+ maxWidth = 680,
43
+ width = 1600,
44
+ height = 1000,
45
+ lightPlate = false,
46
+ placeholder = 'Screenshot to add',
47
+ class: className,
48
+ } = Astro.props;
49
+
50
+ const asset = image && typeof image !== 'string' && image.format !== 'svg' ? image : undefined;
51
+ const url = typeof image === 'string' ? image : image && !asset ? image.src : undefined;
52
+
53
+ // The cap and its 2x for sharp screens, never past what the source holds.
54
+ const widths = asset ? [...new Set([maxWidth, maxWidth * 2].filter((w) => w <= asset.width))] : [];
55
+ if (asset && widths.length === 0) widths.push(asset.width);
56
+ ---
57
+
58
+ <figure class:list={['screenshot', className]}>
59
+ <div class:list={['plate', { 'light-plate': lightPlate }]}>
60
+ {
61
+ asset ? (
62
+ <Image
63
+ src={asset}
64
+ alt={alt}
65
+ widths={widths}
66
+ sizes={`(max-width: ${maxWidth}px) 100vw, ${maxWidth}px`}
67
+ format="webp"
68
+ quality={80}
69
+ loading="lazy"
70
+ style={`max-width: ${maxWidth}px`}
71
+ />
72
+ ) : url ? (
73
+ <img src={url} alt={alt} loading="lazy" style={`max-width: ${maxWidth}px`} />
74
+ ) : (
75
+ <div class="placeholder" role="img" aria-label={`Placeholder. ${alt}`} style={`max-width: ${maxWidth}px; aspect-ratio: ${width} / ${height}`}>
76
+ <span class="label">{placeholder}</span>
77
+ <span class="spec">
78
+ {width} × {height}
79
+ </span>
80
+ <span class="brief">{alt}</span>
81
+ </div>
82
+ )
83
+ }
84
+ </div>
85
+ {caption && <figcaption>{caption}</figcaption>}
86
+ </figure>
87
+
88
+ <style>
89
+ .screenshot {
90
+ margin-block: var(--sp-6) var(--sp-7);
91
+ }
92
+
93
+ .plate {
94
+ display: flex;
95
+ justify-content: center;
96
+ padding: var(--sp-6);
97
+ background: var(--c-surface-sunken);
98
+ border: 1px solid var(--c-border);
99
+ border-radius: var(--radius-lg);
100
+ }
101
+
102
+ /* Screenshots are light-UI captures: kept as they are in dark mode, not inverted or dimmed. */
103
+ img {
104
+ width: 100%;
105
+ height: auto;
106
+ border: 1px solid var(--c-border);
107
+ border-radius: var(--radius-sm);
108
+ }
109
+
110
+ /* The light theme's --c-surface-sunken and --c-border, fixed, so the plate is the same in both
111
+ * themes. */
112
+ .light-plate {
113
+ background: #fcf1ec;
114
+ }
115
+ .light-plate img {
116
+ border-color: #f1dacf;
117
+ }
118
+
119
+ .placeholder {
120
+ display: grid;
121
+ place-content: center;
122
+ justify-items: center;
123
+ gap: var(--sp-2);
124
+ width: 100%;
125
+ padding: var(--sp-6);
126
+ text-align: center;
127
+ background: var(--c-surface);
128
+ border: 1px dashed var(--c-border-strong);
129
+ border-radius: var(--radius-sm);
130
+ }
131
+
132
+ .label {
133
+ font-family: var(--font-body);
134
+ font-size: var(--text-body-sm);
135
+ font-weight: 600;
136
+ color: var(--c-text);
137
+ }
138
+
139
+ .spec {
140
+ font-family: var(--font-mono);
141
+ font-size: var(--text-caption);
142
+ color: var(--c-text-muted);
143
+ }
144
+
145
+ /* The brief is the alt text, capped to a readable measure. */
146
+ .brief {
147
+ max-width: 46ch;
148
+ margin-top: var(--sp-2);
149
+ font-size: var(--text-caption);
150
+ line-height: 1.5;
151
+ color: var(--c-text-muted);
152
+ }
153
+
154
+ figcaption {
155
+ max-width: var(--layout-measure);
156
+ margin-top: var(--sp-4);
157
+ font-size: var(--text-body-sm);
158
+ color: var(--c-text-muted);
159
+ }
160
+
161
+ @media (max-width: 640px) {
162
+ .plate {
163
+ padding: var(--sp-4);
164
+ }
165
+ }
166
+ </style>