@absolutejs/absolute 0.19.0-beta.961 → 0.19.0-beta.963

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/dist/build.js CHANGED
@@ -10415,17 +10415,12 @@ var DEFAULT_DEVICE_SIZES, DEFAULT_IMAGE_SIZES, DEFAULT_QUALITY, OPTIMIZATION_END
10415
10415
  return actual.startsWith(prefix);
10416
10416
  }
10417
10417
  return actual === pattern;
10418
- }, MIME_MAP, isSharpFactory = (value) => typeof value === "function", callSharp = (sharpRef, input) => {
10419
- if (!isSharpFactory(sharpRef)) {
10420
- throw new Error("Loaded sharp module is not callable.");
10421
- }
10422
- return sharpRef(input);
10423
- }, toBuffer = (input) => {
10418
+ }, MIME_MAP, isSharpFactory = (value) => typeof value === "function", toBuffer = (input) => {
10424
10419
  if (Buffer.isBuffer(input))
10425
10420
  return input;
10426
10421
  return Buffer.from(input);
10427
- }, buildOptimizedUrl = (src, width, quality, basePath = OPTIMIZATION_ENDPOINT) => `${basePath}?url=${encodeURIComponent(src)}&w=${width}&q=${quality}`, formatToMime = (format) => MIME_MAP[format], generateBlurSvg = (base64Thumbnail) => {
10428
- const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 320"><filter id="b" color-interpolation-filters="sRGB"><feGaussianBlur stdDeviation="${BLUR_DEVIATION}"/><feColorMatrix values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 100 -1"/></filter><image filter="url(#b)" x="0" y="0" width="100%" height="100%" href="${base64Thumbnail}"/></svg>`;
10422
+ }, isUnsupportedFormatError = (err) => typeof err === "object" && err !== null && ("code" in err) && err.code === "ERR_IMAGE_FORMAT_UNSUPPORTED", buildOptimizedUrl = (src, width, quality, basePath = OPTIMIZATION_ENDPOINT) => `${basePath}?url=${encodeURIComponent(src)}&w=${width}&q=${quality}`, formatToMime = (format) => MIME_MAP[format], generateBlurSvg = (base64Thumbnail) => {
10423
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 320"><filter id="b" color-interpolation-filters="sRGB"><feGaussianBlur stdDeviation="${BLUR_DEVIATION}"/><feColorMatrix values="1 0 0 0 0 0 1 0 0 0 0 0 100 -1"/></filter><image filter="url(#b)" x="0" y="0" width="100%" height="100%" href="${base64Thumbnail}"/></svg>`;
10429
10424
  const encoded = encodeURIComponent(svg);
10430
10425
  return `url("data:image/svg+xml,${encoded}")`;
10431
10426
  }, generateSrcSet = (src, width, sizes, config, loader) => {
@@ -10485,11 +10480,24 @@ var DEFAULT_DEVICE_SIZES, DEFAULT_IMAGE_SIZES, DEFAULT_QUALITY, OPTIMIZATION_END
10485
10480
  return "webp";
10486
10481
  }
10487
10482
  return "jpeg";
10488
- }, AVIF_QUALITY_OFFSET = 20, AVIF_EFFORT = 3, optimizeImage = async (buffer, width, quality, format) => {
10489
- const sharp = await tryLoadSharp();
10490
- if (!sharp)
10491
- return toBuffer(buffer);
10492
- const pipeline = callSharp(sharp, toBuffer(buffer)).rotate().resize(width, undefined, { withoutEnlargement: true });
10483
+ }, AVIF_QUALITY_OFFSET = 20, AVIF_EFFORT = 3, PNG_COMPRESSION_LEVEL = 9, optimizeWithBunImage = async (buffer, width, quality, format) => {
10484
+ const pipeline = new Bun.Image(buffer).resize(width, undefined, {
10485
+ withoutEnlargement: true
10486
+ });
10487
+ switch (format) {
10488
+ case "avif":
10489
+ return pipeline.avif({
10490
+ quality: Math.max(1, quality - AVIF_QUALITY_OFFSET)
10491
+ }).toBuffer();
10492
+ case "jpeg":
10493
+ return pipeline.jpeg({ quality }).toBuffer();
10494
+ case "png":
10495
+ return pipeline.png({ compressionLevel: PNG_COMPRESSION_LEVEL }).toBuffer();
10496
+ case "webp":
10497
+ return pipeline.webp({ quality }).toBuffer();
10498
+ }
10499
+ }, optimizeWithSharp = async (sharpRef, buffer, width, quality, format) => {
10500
+ const pipeline = sharpRef(buffer).rotate().resize(width, undefined, { withoutEnlargement: true });
10493
10501
  switch (format) {
10494
10502
  case "avif":
10495
10503
  return pipeline.avif({
@@ -10502,8 +10510,19 @@ var DEFAULT_DEVICE_SIZES, DEFAULT_IMAGE_SIZES, DEFAULT_QUALITY, OPTIMIZATION_END
10502
10510
  return pipeline.png({ quality }).toBuffer();
10503
10511
  case "webp":
10504
10512
  return pipeline.webp({ quality }).toBuffer();
10505
- default:
10506
- return toBuffer(buffer);
10513
+ }
10514
+ }, optimizeImage = async (buffer, width, quality, format) => {
10515
+ const input = toBuffer(buffer);
10516
+ try {
10517
+ return await optimizeWithBunImage(input, width, quality, format);
10518
+ } catch (err) {
10519
+ if (format === "avif" && isUnsupportedFormatError(err)) {
10520
+ const sharp = await tryLoadSharp();
10521
+ if (sharp && isSharpFactory(sharp)) {
10522
+ return optimizeWithSharp(sharp, input, width, quality, format);
10523
+ }
10524
+ }
10525
+ throw err;
10507
10526
  }
10508
10527
  }, readFromCache = (cacheDir, cacheKey) => {
10509
10528
  const metaPath = join14(cacheDir, `${cacheKey}.meta`);
@@ -10530,7 +10549,7 @@ var DEFAULT_DEVICE_SIZES, DEFAULT_IMAGE_SIZES, DEFAULT_QUALITY, OPTIMIZATION_END
10530
10549
  if (sharpWarned)
10531
10550
  return null;
10532
10551
  sharpWarned = true;
10533
- console.warn("[image] sharp not installed \u2014 serving unoptimized images. Install with: bun add sharp");
10552
+ console.warn('[image] AVIF requested but sharp not installed and Bun.Image cannot encode AVIF on this platform. Install sharp (`bun add sharp`) to enable AVIF, or remove "avif" from your image formats config. See docs/SHARP_REMOVAL.md for context.');
10534
10553
  return null;
10535
10554
  }
10536
10555
  }, writeToCache = (cacheDir, cacheKey, buffer, meta) => {
@@ -26299,5 +26318,5 @@ export {
26299
26318
  build
26300
26319
  };
26301
26320
 
26302
- //# debugId=6B1C49D345A8485C64756E2164756E21
26321
+ //# debugId=A92228156E225CEE64756E2164756E21
26303
26322
  //# sourceMappingURL=build.js.map