@uniweb/build 1.14.2 → 1.14.3

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": "@uniweb/build",
3
- "version": "1.14.2",
3
+ "version": "1.14.3",
4
4
  "description": "Build tooling for the Uniweb Component Web Platform",
5
5
  "type": "module",
6
6
  "exports": {
@@ -64,7 +64,7 @@
64
64
  "@uniweb/projections": "~1.2.10"
65
65
  },
66
66
  "optionalDependencies": {
67
- "@uniweb/runtime": "~1.3.12"
67
+ "@uniweb/runtime": "~1.3.13"
68
68
  },
69
69
  "peerDependencies": {
70
70
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0",
@@ -74,7 +74,7 @@
74
74
  "@vitejs/plugin-react": "^4.0.0 || ^5.0.0",
75
75
  "vite-plugin-svgr": "^4.0.0",
76
76
  "@uniweb/core": "~1.6.1",
77
- "@uniweb/runtime": "~1.3.12"
77
+ "@uniweb/runtime": "~1.3.13"
78
78
  },
79
79
  "peerDependenciesMeta": {
80
80
  "vite": {
@@ -374,7 +374,7 @@ function validateDeployConfig(deployConfig, distDir) {
374
374
  `One-time setup walkthrough (S3 bucket, CloudFront distribution,`,
375
375
  `IAM user, directory-index Function, custom error responses):`,
376
376
  ``,
377
- ` https://docs.uniweb.app/docs/reference/aws-s3-cloudfront-setup`,
377
+ ` https://uniweb.io/docs/reference/aws-s3-cloudfront-setup`,
378
378
  ``,
379
379
  `When done, fill these in deploy.yml next to site.yml:`,
380
380
  ``,
@@ -58,11 +58,34 @@ async function getFileHash(filePath) {
58
58
  async function convertToWebp(input, options = {}) {
59
59
  const { quality = 80 } = options
60
60
 
61
- return sharp(input)
61
+ // ⭐ The picture as the author saw it. The conversion drops the tag saying how to turn a phone's
62
+ // photo, so it's turned first, and sharp reads one frame unless told otherwise. ⛔ Until 2026-11-02
63
+ // a portrait photo was drawn on its side, and an animated GIF was its first frame.
64
+ return sharp(input, { animated: true })
65
+ .autoOrient()
62
66
  .webp({ quality })
63
67
  .toBuffer()
64
68
  }
65
69
 
70
+ /**
71
+ * The size an image draws at, read from the bytes the site serves, or null where the file has none
72
+ * to give: a browser sizes a vector by its own rules, whatever size sharp would rasterize it at, and
73
+ * sharp can't read every format (`.ico`). Quiet, because a file with no size is still copied.
74
+ *
75
+ * @param {Buffer} bytes
76
+ * @param {string} ext - the extension of the file the site serves
77
+ * @returns {Promise<{ width: number, height: number } | null>}
78
+ */
79
+ async function drawnSize(bytes, ext) {
80
+ if (ext === '.svg') return null
81
+ try {
82
+ const { autoOrient } = await sharp(bytes).metadata()
83
+ return autoOrient?.width && autoOrient?.height ? { width: autoOrient.width, height: autoOrient.height } : null
84
+ } catch {
85
+ return null
86
+ }
87
+ }
88
+
66
89
  /**
67
90
  * Process a single asset
68
91
  *
@@ -139,7 +162,8 @@ export async function processAsset(asset, options = {}) {
139
162
  outputPath,
140
163
  processed: true,
141
164
  converted,
142
- size: outputBuffer.length
165
+ size: outputBuffer.length,
166
+ ...(isImage ? await drawnSize(outputBuffer, outputExt) : null)
143
167
  }
144
168
  } catch (error) {
145
169
  console.warn(`[asset-processor] Failed to process ${resolved}:`, error.message)
@@ -159,7 +183,8 @@ export async function processAsset(asset, options = {}) {
159
183
  * @param {Object} options - Processing options
160
184
  * @param {string} [options.basePath='/'] - Site base path for subdirectory deployments
161
185
  * @returns {Promise<Object>} `pathMapping` — original paths to output URLs — `results`, and
162
- * `files`: what the build knows of each file it copied, by original path (`name`, `size`, `mime`)
186
+ * `files`: what the build knows of each file it copied, by original path (`name`, `size`, `mime`,
187
+ * and an image's `width` and `height`)
163
188
  */
164
189
  export async function processAssets(assetManifest, options = {}) {
165
190
  const pathMapping = {}
@@ -181,7 +206,12 @@ export async function processAssets(assetManifest, options = {}) {
181
206
  pathMapping[originalPath] = result.output
182
207
 
183
208
  if (result.processed) {
184
- files[originalPath] = { name: basename(asset.resolved), size: result.size, mime: mimeFor(result.outputPath) }
209
+ files[originalPath] = {
210
+ name: basename(asset.resolved),
211
+ size: result.size,
212
+ mime: mimeFor(result.outputPath),
213
+ ...(result.width ? { width: result.width, height: result.height } : {})
214
+ }
185
215
  results.processed++
186
216
  results.totalSize += result.size || 0
187
217
  if (result.converted) {
@@ -268,6 +298,16 @@ export function rewriteContentPaths(content, pathMapping, files = null, made = n
268
298
  if (node.attrs[key] === undefined && file[key] !== undefined) node.attrs[key] = file[key]
269
299
  }
270
300
  }
301
+ // An image the build copied, with no size from its author: its file's, which holds its place
302
+ // on the page while the file loads, so nothing under it jumps when it arrives (2026-11-02).
303
+ // Also only on the built output, and never for an icon, which its own `size` sizes. ⚠️ These
304
+ // reach the `<img>` as attributes, and a stylesheet that sets only the height then leaves the
305
+ // width at this one: a foundation drawing an image at `h-8` adds `w-auto`.
306
+ const picture = node.attrs.role === 'icon' ? null : files?.[original]
307
+ if (picture?.width && node.attrs.width == null && node.attrs.height == null) {
308
+ node.attrs.width = picture.width
309
+ node.attrs.height = picture.height
310
+ }
271
311
  }
272
312
 
273
313
  // Rewrite paths in data blocks (structured data parsed at build time)
@@ -190,7 +190,7 @@ function refuseVersionsKey(folderYml, pageYml, dirPath) {
190
190
  `version's pages up beside the folders, and delete this key. A foundation that draws versions needs ` +
191
191
  `the new \`useVersion\` too: \`versions\`, \`currentVersion\` and \`hierarchy\` are what it reads now, and ` +
192
192
  `\`versionedScopes\` and \`getVersionUrl\` are gone, so a section still reading those fails to render. ` +
193
- `See https://docs.uniweb.app/docs/reference/versioning`
193
+ `See https://uniweb.io/docs/reference/versioning`
194
194
  )
195
195
  }
196
196