@all-the.rest/astro-image-cdn 0.2.1 → 0.2.2

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/README.md CHANGED
@@ -154,7 +154,7 @@ ratchet check
154
154
 
155
155
  The tests include real Astro static builds using `Image`, `Picture`, and `getImage()`, a real dev-server request served from local output, unrequested-image checks, a repeated warm build, and assertions that optimized variants remain outside `dist/`.
156
156
 
157
- The npm workflow publishes only pushed `vMAJOR.MINOR.PATCH` version tags whose version matches `package.json`; verification and packaging use pnpm in a separate job without OIDC, while the minimal publishing job downloads the verified tarball and uses npm CLI only for OIDC publishing. The package's npm Trusted Publisher is configured for this repository's `.github/workflows/publish.yml` and the `npm publish` action.
157
+ To release, update `package.json`, commit and push the change, then create and push a matching `vMAJOR.MINOR.PATCH` tag. Pushing that tag is the release trigger; `.github/workflows/publish.yml` validates it against `package.json`, runs `pnpm check`, and packs the package in a verification job. A separate publishing job downloads that verified tarball and publishes it with npm Trusted Publishing (GitHub Actions OIDC) and provenance. The npm Trusted Publisher must be configured for this repository and `.github/workflows/publish.yml`. Do not run `pnpm publish` locally: releases go through the tagged GitHub Actions workflow, not a local OTP-based publish.
158
158
 
159
159
  Version 0.1.0 was bootstrapped manually because npm requires a package to exist before a trusted publisher can be configured ([`npm trust` prerequisites](https://docs.npmjs.com/cli/v12/commands/npm-trust/#prerequisites)). Subsequent version-tag releases use GitHub Actions OIDC and npm provenance, without a long-lived publish token. A new trusted-publisher configuration must complete its first successful publish within two days or it expires.
160
160
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@all-the.rest/astro-image-cdn",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Persistent, incremental image variants for Astro's native image components",
5
5
  "type": "module",
6
6
  "license": "ISC",
package/src/service.js CHANGED
@@ -326,11 +326,27 @@ function validateStaticTransform(options, config) {
326
326
  throw new Error(`astro-image-cdn does not support fit="${options.fit}".`);
327
327
  }
328
328
 
329
- const width = Number(options.width ?? options.src.width);
330
- const height = Number(options.height ?? (width * options.src.height / options.src.width));
331
- const targetRatio = width / height;
332
- const sourceRatio = options.src.width / options.src.height;
333
- if (Number.isFinite(targetRatio) && Math.abs(targetRatio - sourceRatio) > 0.005) {
329
+ const sourceWidth = Number(options.src.width);
330
+ const sourceHeight = Number(options.src.height);
331
+ let width = options.width == null ? undefined : Number(options.width);
332
+ let height = options.height == null ? undefined : Number(options.height);
333
+ if (width != null && height == null) {
334
+ height = Math.round(width * sourceHeight / sourceWidth);
335
+ } else if (height != null && width == null) {
336
+ width = Math.round(height * sourceWidth / sourceHeight);
337
+ } else if (width == null && height == null) {
338
+ width = sourceWidth;
339
+ height = sourceHeight;
340
+ }
341
+
342
+ width = Math.round(width);
343
+ height = Math.round(height);
344
+ const expectedHeight = Math.round(width * sourceHeight / sourceWidth);
345
+ const expectedWidth = Math.round(height * sourceWidth / sourceHeight);
346
+ const isAspectPreserving = (Number.isSafeInteger(width) && width > 0)
347
+ && (Number.isSafeInteger(height) && height > 0)
348
+ && (height === expectedHeight || width === expectedWidth);
349
+ if (!isAspectPreserving) {
334
350
  throw new Error("astro-image-cdn generates aspect-preserving variants only; per-image cropping is not supported.");
335
351
  }
336
352