import { toUint8Array as s } from "../shop-minis-react/node_modules/.pnpm/js-base64@3.7.7/node_modules/js-base64/base64.js";
import { thumbHashToDataURL as i } from "../shop-minis-react/node_modules/.pnpm/thumbhash@0.1.1/node_modules/thumbhash/thumbhash.js";
function U(t) {
  if (t)
    try {
      const e = s(t);
      return i(e);
    } catch (e) {
      console.warn("Failed to decode thumbhash to data URL", e);
      return;
    }
}
function u(t) {
  return new Promise((e, n) => {
    const r = new FileReader();
    r.onloadend = () => e(r.result), r.onerror = n, r.readAsDataURL(t);
  });
}
const o = {
  xxsUrl: 32,
  xsUrl: 64,
  sUrl: 128,
  xxsmUrl: 256,
  xsmUrl: 384,
  smUrl: 512,
  mUrl: 640,
  lUrl: 1080,
  xlUrl: 2048
}, a = 0.05, c = Object.entries(o).sort(
  ([, t], [, e]) => t - e
), d = (t) => {
  for (const [e, n] of c) {
    const r = n + n * a;
    if (t <= r) return e;
  }
  return "xlUrl";
}, m = (t, e) => {
  const r = new RegExp(/\?+/g).test(t) ? "&" : "?";
  return `${t}${r}width=${e}`;
}, f = (t) => {
  if (!t) return "";
  if (!t.startsWith("https://cdn.shopify.com"))
    return t;
  const e = window.innerWidth ?? screen.width, n = d(e);
  return m(t, o[n]);
};
export {
  u as fileToDataUri,
  f as getResizedImageUrl,
  U as getThumbhashDataURL
};
//# sourceMappingURL=image.js.map
