import { defineComponent as W, inject as C, computed as a, useAttrs as M, openBlock as B, createElementBlock as k, mergeProps as L, unref as $ } from "vue";
import { IMAGE_PROVIDER_URLS as N, SCREEN_SIZES as j } from "./constants.js";
import { merge as q } from "es-toolkit/compat";
const w = {
  xs: 160,
  sm: 338,
  md: 676,
  lg: 1352,
  xl: 2704
};
var z = /* @__PURE__ */ ((t) => (t.None = "none", t.Rounded = "rounded", t.Circle = "circle", t))(z || {}), b = /* @__PURE__ */ ((t) => (t.Cloudinary = "cloudinary", t.Static = "static", t))(b || {});
function P(t) {
  return (s) => t[s] || s;
}
function G({
  formatter: t = (m, c) => `${m}=${c}`,
  keyMap: s,
  joinWith: i = "/",
  valueMap: e = {}
} = {}) {
  const m = typeof s == "function" ? s : P(s || {});
  return Object.keys(e).forEach((c) => {
    typeof e[c] != "function" && (e[c] = P(e[c]));
  }), (c = {}) => Object.entries(c).map(([l, d]) => {
    const p = e[l], g = m(l);
    let v = d;
    return typeof p == "function" && (v = p(c[l])), t(g, v);
  }).join(i);
}
const Q = N.CLOUDINARY, T = (t) => t.startsWith("#") ? t.replace("#", "rgb_") : t, E = G({
  keyMap: {
    fit: "c",
    width: "w",
    height: "h",
    format: "f",
    quality: "q",
    background: "b",
    dpr: "dpr"
  },
  valueMap: {
    fit: {
      fill: "fill",
      inside: "pad",
      outside: "lpad",
      cover: "fit",
      contain: "scale"
    },
    format: {
      jpeg: "jpg"
    },
    background(t) {
      return T(t);
    }
  },
  joinWith: ",",
  formatter: (t, s) => `${t}_${s}`
}), D = {
  format: "auto",
  quality: "auto:best"
};
function F(t, s = {}) {
  const i = q(D, s), e = E(i);
  return `${Q}/${e}/${t}`;
}
const V = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  getImageUrl: F,
  operationsGenerator: E
}, Symbol.toStringTag, { value: "Module" }));
function H(t = "") {
  return t;
}
const Y = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  getImageUrl: H
}, Symbol.toStringTag, { value: "Module" })), Z = {
  cloudinary: V,
  static: Y
}, J = ["src"], et = /* @__PURE__ */ W({
  inheritAttrs: !1,
  __name: "Image",
  props: {
    src: {},
    srcset: { default: void 0 },
    sizes: { default: void 0 },
    provider: { default: void 0 },
    radius: { default: "none" },
    staticPath: { default: void 0 }
  },
  setup(t) {
    const s = {
      md: j.md,
      lg: j.lg
    }, i = C("stashOptions"), e = t, m = a(() => {
      const { src: r, ...n } = M();
      return n.sizes = v.value, n.srcset = I.value, n;
    }), c = a(() => {
      try {
        return new URL(e.src), !0;
      } catch {
        return !1;
      }
    }), S = a(() => {
      var r;
      return e.provider || ((r = i == null ? void 0 : i.images) == null ? void 0 : r.provider) || b.Static;
    }), l = a(() => e.staticPath ?? (i == null ? void 0 : i.staticPath)), d = a(() => S.value === b.Static), p = a(() => Z[S.value]), g = a(() => d.value ? _() : _({ width: w.md })), v = a(() => e.sizes ? O() : e.sizes), I = a(() => e.sizes && !e.srcset && !d.value ? R() : e.srcset), U = a(() => e.sizes ? x(e.sizes) : []);
    function _(r = {}) {
      if (d.value && c.value)
        return e.src;
      const n = d.value && l.value ? `${l.value}/${e.src}` : e.src;
      return p.value.getImageUrl(n, r);
    }
    function R() {
      return Object.values(w).map((r) => `${_({ width: r })} ${r}w`).join(", ");
    }
    function O() {
      var r;
      return (r = e.sizes) != null && r.includes("(") ? e.sizes : U.value.map((n) => `${n.mediaQuery ? n.mediaQuery + " " : ""}${n.size}`).join(", ");
    }
    function x(r = "") {
      const n = [], h = {
        default: "100vw"
      };
      if (typeof r == "string") {
        const f = r.split(/[\s]+/).filter((u) => u);
        for (const u of f) {
          const o = u.split(":");
          if (o.length !== 2) {
            h.default = o[0].trim();
            continue;
          }
          h[o[0].trim()] = o[1].trim();
        }
      } else
        throw new Error("`sizes` needs to be a string");
      for (const f in h) {
        const u = parseInt(s[f] || 0);
        let o = String(h[f]);
        const y = o.endsWith("vw");
        if (!y && /^\d+$/.test(o) && (o = `${o}px`), !y && o.endsWith("%"))
          throw new Error("Image: `sizes` does not support percentage values");
        const A = {
          mediaQuery: u ? `(min-width: ${u}px)` : "",
          screenMinWidth: u,
          size: o
        };
        n.push(A);
      }
      return n.sort((f, u) => f.screenMinWidth > u.screenMinWidth ? -1 : 1), n;
    }
    return (r, n) => (B(), k("img", L({
      ref: "img",
      key: g.value,
      "data-test": "stash-image",
      class: ["stash-image", {
        rounded: e.radius === $(z).Rounded,
        "rounded-full": e.radius === $(z).Circle
      }],
      src: g.value
    }, m.value), null, 16, J));
  }
});
export {
  b as I,
  w as S,
  et as _,
  z as a
};
//# sourceMappingURL=Image.vue_vue_type_script_setup_true_lang-BZnhM2bg.js.map
