// src/utils/imageClient.ts
var DEFAULT_DEVICE_SIZES = [
  640,
  750,
  828,
  1080,
  1200,
  1920,
  2048,
  3840
];
var DEFAULT_IMAGE_SIZES = [16, 32, 48, 64, 96, 128, 256, 384];
var DEFAULT_QUALITY = 75;
var OPTIMIZATION_ENDPOINT = "/_absolute/image";
var buildOptimizedUrl = (src, width, quality, basePath = OPTIMIZATION_ENDPOINT) => `${basePath}?url=${encodeURIComponent(src)}&w=${width}&q=${quality}`;
var getAllSizes = (deviceSizes, imageSizes) => {
  const device = deviceSizes ?? DEFAULT_DEVICE_SIZES;
  const image = imageSizes ?? DEFAULT_IMAGE_SIZES;
  return [...device, ...image].sort((left, right) => left - right);
};
var snapToSize = (target, sizes) => {
  for (const size of sizes) {
    if (size >= target)
      return size;
  }
  return sizes[sizes.length - 1] ?? target;
};
var generateBlurSvg = (base64Thumbnail) => {
  const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 320"><filter id="b" color-interpolation-filters="sRGB"><feGaussianBlur stdDeviation="20"/><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>`;
  const encoded = encodeURIComponent(svg);
  return `url("data:image/svg+xml,${encoded}")`;
};
var generateSrcSet = (src, width, sizes, deviceSizes, imageSizes) => {
  const quality = DEFAULT_QUALITY;
  if (sizes) {
    const allSizes = getAllSizes(deviceSizes, imageSizes);
    return allSizes.map((sizeWidth) => `${buildOptimizedUrl(src, sizeWidth, quality)} ${sizeWidth}w`).join(", ");
  }
  if (width) {
    const allSizes = getAllSizes(deviceSizes, imageSizes);
    const w1x = snapToSize(width, allSizes);
    const w2x = snapToSize(width * 2, allSizes);
    return `${buildOptimizedUrl(src, w1x, quality)} 1x, ${buildOptimizedUrl(src, w2x, quality)} 2x`;
  }
  const devSizes = deviceSizes ?? DEFAULT_DEVICE_SIZES;
  return devSizes.map((sizeWidth) => `${buildOptimizedUrl(src, sizeWidth, quality)} ${sizeWidth}w`).join(", ");
};
export {
  getAllSizes,
  generateSrcSet,
  generateBlurSvg,
  buildOptimizedUrl,
  OPTIMIZATION_ENDPOINT,
  DEFAULT_QUALITY,
  DEFAULT_IMAGE_SIZES,
  DEFAULT_DEVICE_SIZES
};
