@n1kname/components 0.48.0 → 0.49.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.48.0",
3
+ "version": "0.49.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -33,6 +33,8 @@ interface Screen {
33
33
  image: ImageMetadata | string;
34
34
  /** Empty by default: the tile is one link, named by its words. */
35
35
  alt?: string;
36
+ /** A plain URL's own size in px, so the space is kept while it loads. An import knows its own. */
37
+ size?: { width: number; height: number };
36
38
  }
37
39
 
38
40
  interface Layer {
@@ -46,6 +48,8 @@ interface Layer {
46
48
  /** Bobs slowly on its own, down and back, so a card cut out of a page floats above it. */
47
49
  float?: boolean;
48
50
  alt?: string;
51
+ /** A plain URL's own size in px, so the space is kept while it loads. An import knows its own. */
52
+ size?: { width: number; height: number };
49
53
  }
50
54
 
51
55
  interface Props {
@@ -61,6 +65,8 @@ interface Props {
61
65
  screens?: Screen[];
62
66
  /** One picture instead of screens, such as a photo. */
63
67
  image?: ImageMetadata | string;
68
+ /** A plain-URL `image`'s own size in px, so the space is kept while it loads. */
69
+ imageSize?: { width: number; height: number };
64
70
  /** Separate pictures on a stage, in place of screens. */
65
71
  layers?: Layer[];
66
72
  /** The stage's width over its height. */
@@ -92,6 +98,7 @@ const {
92
98
  metrics = [],
93
99
  screens = [],
94
100
  image,
101
+ imageSize,
95
102
  layers = [],
96
103
  stage = 4 / 3,
97
104
  ink = 'light',
@@ -165,7 +172,7 @@ const labelledby = [`${uid}-title`, text && `${uid}-text`, overline && `${uid}-o
165
172
  {layers.map((l, i) => (
166
173
  <div class:list={['layer', { float: l.float }]} style={`left: ${l.x}%; top: ${l.y}%; width: ${l.width}%; --depth: ${l.depth ?? 0}; --i: ${i}`}>
167
174
  {typeof l.image === 'string' ? (
168
- <img src={l.image} alt={l.alt ?? ''} loading="lazy" />
175
+ <img src={l.image} alt={l.alt ?? ''} width={l.size?.width} height={l.size?.height} loading="lazy" />
169
176
  ) : (
170
177
  <Image src={l.image} alt={l.alt ?? ''} widths={layerWidths(l.image)} sizes={layerSizes(l.width)} format="webp" quality={80} loading="lazy" />
171
178
  )}
@@ -183,7 +190,7 @@ const labelledby = [`${uid}-title`, text && `${uid}-text`, overline && `${uid}-o
183
190
  return (
184
191
  <div class={`screen s${i}`}>
185
192
  {typeof s.image === 'string' ? (
186
- <img src={s.image} alt={s.alt ?? ''} loading="lazy" />
193
+ <img src={s.image} alt={s.alt ?? ''} width={s.size?.width} height={s.size?.height} loading="lazy" />
187
194
  ) : (
188
195
  <Image src={s.image} alt={s.alt ?? ''} widths={fit(s.image)} sizes={sizes} format="webp" quality={80} loading="lazy" />
189
196
  )}
@@ -193,7 +200,7 @@ const labelledby = [`${uid}-title`, text && `${uid}-text`, overline && `${uid}-o
193
200
  : image && (
194
201
  <div class="screen picture s0">
195
202
  {typeof image === 'string' ? (
196
- <img src={image} alt="" loading="lazy" />
203
+ <img src={image} alt="" width={imageSize?.width} height={imageSize?.height} loading="lazy" />
197
204
  ) : (
198
205
  <Image src={image} alt="" widths={fit(image)} sizes="(max-width: 760px) 90vw, 700px" format="webp" quality={78} loading="lazy" />
199
206
  )}
@@ -33,6 +33,8 @@ import { patternStyle, type Pattern } from './patterns';
33
33
  interface Screen {
34
34
  image: ImageMetadata | string;
35
35
  alt: string;
36
+ /** A plain URL's own size in px, so the space is kept while it loads. An import knows its own. */
37
+ size?: { width: number; height: number };
36
38
  }
37
39
 
38
40
  interface Layer {
@@ -46,6 +48,8 @@ interface Layer {
46
48
  /** Bobs slowly on its own, down and back, so a card cut out of a page floats above it. */
47
49
  float?: boolean;
48
50
  alt?: string;
51
+ /** A plain URL's own size in px, so the space is kept while it loads. An import knows its own. */
52
+ size?: { width: number; height: number };
49
53
  }
50
54
 
51
55
  interface Props {
@@ -111,7 +115,7 @@ const fit = (img: ImageMetadata) => [...new Set(widths.filter((w) => w <= img.wi
111
115
  {layers.map((l, i) => (
112
116
  <div class:list={['layer', { float: l.float }]} style={`left: ${l.x}%; top: ${l.y}%; width: ${l.width}%; --depth: ${l.depth ?? 0}; --i: ${i}`}>
113
117
  {typeof l.image === 'string' ? (
114
- <img src={l.image} alt={l.alt ?? ''} loading={eager ? 'eager' : 'lazy'} />
118
+ <img src={l.image} alt={l.alt ?? ''} width={l.size?.width} height={l.size?.height} loading={eager ? 'eager' : 'lazy'} />
115
119
  ) : (
116
120
  <Image
117
121
  src={l.image}
@@ -135,7 +139,7 @@ const fit = (img: ImageMetadata) => [...new Set(widths.filter((w) => w <= img.wi
135
139
  return (
136
140
  <div class={`screen s${i}`}>
137
141
  {typeof s.image === 'string' ? (
138
- <img src={s.image} alt={s.alt} loading={eager && first ? 'eager' : 'lazy'} />
142
+ <img src={s.image} alt={s.alt} width={s.size?.width} height={s.size?.height} loading={eager && first ? 'eager' : 'lazy'} />
139
143
  ) : (
140
144
  <Image
141
145
  src={s.image}
@@ -25,7 +25,8 @@ interface Props {
25
25
  caption?: string;
26
26
  /** Widest the shot is drawn, in px. Keep it well under the source's width. */
27
27
  maxWidth?: number;
28
- /** The placeholder's size. An image reports its own. */
28
+ /** The shot's size in px: the placeholder's size, and a plain URL's, so the space is kept while it
29
+ * loads. An import reports its own. */
29
30
  width?: number;
30
31
  height?: number;
31
32
  /** Keep the light plate in dark mode, for transparent artwork with dark labels. */
@@ -40,8 +41,8 @@ const {
40
41
  alt,
41
42
  caption,
42
43
  maxWidth = 680,
43
- width = 1600,
44
- height = 1000,
44
+ width,
45
+ height,
45
46
  lightPlate = false,
46
47
  placeholder = 'Screenshot to add',
47
48
  class: className,
@@ -49,6 +50,10 @@ const {
49
50
 
50
51
  const asset = image && typeof image !== 'string' && image.format !== 'svg' ? image : undefined;
51
52
  const url = typeof image === 'string' ? image : image && !asset ? image.src : undefined;
53
+ // A plain URL's size comes from the props; an imported SVG knows its own.
54
+ const urlSize = typeof image === 'string' ? { width, height } : image && !asset ? { width: image.width, height: image.height } : { width: undefined, height: undefined };
55
+ // The placeholder needs a shape even when none is given.
56
+ const box = { width: width ?? 1600, height: height ?? 1000 };
52
57
 
53
58
  // The cap and its 2x for sharp screens, never past what the source holds.
54
59
  const widths = asset ? [...new Set([maxWidth, maxWidth * 2].filter((w) => w <= asset.width))] : [];
@@ -70,12 +75,12 @@ if (asset && widths.length === 0) widths.push(asset.width);
70
75
  style={`max-width: ${maxWidth}px`}
71
76
  />
72
77
  ) : url ? (
73
- <img src={url} alt={alt} loading="lazy" style={`max-width: ${maxWidth}px`} />
78
+ <img src={url} alt={alt} width={urlSize.width} height={urlSize.height} loading="lazy" style={`max-width: ${maxWidth}px`} />
74
79
  ) : (
75
- <div class="placeholder" role="img" aria-label={`Placeholder. ${alt}`} style={`max-width: ${maxWidth}px; aspect-ratio: ${width} / ${height}`}>
80
+ <div class="placeholder" role="img" aria-label={`Placeholder. ${alt}`} style={`max-width: ${maxWidth}px; aspect-ratio: ${box.width} / ${box.height}`}>
76
81
  <span class="label">{placeholder}</span>
77
82
  <span class="spec">
78
- {width} × {height}
83
+ {box.width} × {box.height}
79
84
  </span>
80
85
  <span class="brief">{alt}</span>
81
86
  </div>
package/src/Steps.astro CHANGED
@@ -20,6 +20,8 @@ interface Step {
20
20
  image?: ImageMetadata | string;
21
21
  /** What the picture shows. */
22
22
  alt?: string;
23
+ /** A plain URL's own size in px, so the space is kept while it loads. An import knows its own. */
24
+ size?: { width: number; height: number };
23
25
  }
24
26
 
25
27
  interface Props {
@@ -54,7 +56,7 @@ const { steps, caption, phone = false, class: className } = Astro.props;
54
56
  loading="lazy"
55
57
  />
56
58
  ) : s.image ? (
57
- <img src={s.image} alt={s.alt ?? ''} loading="lazy" />
59
+ <img src={s.image} alt={s.alt ?? ''} width={s.size?.width} height={s.size?.height} loading="lazy" />
58
60
  ) : (
59
61
  <div class="placeholder" role="img" aria-label={`Placeholder. ${s.alt ?? s.label}`}>
60
62
  <span>{s.label}</span>