UNPKG

@yoot/imgix

Version:

Imgix adapter for @yoot/yoot

58 lines (57 loc) 1.28 kB
import { defineAdapter as f } from "@yoot/yoot"; import { _isEmpty as a, _isKeyOf as o } from "@yoot/yoot/internal"; const g = f({ supports: (r) => r.hostname.endsWith(".imgix.net"), generateUrl: u, normalizeUrl: s }); function s(r) { const t = new URL(r.href); return t.search = "", t.hash = "", t.href; } function u(r) { const t = Object.entries(r.directives).reduce(p, new URLSearchParams()), e = new URL(r.src); return e.search = String(t), e.href; } const i = { aspectRatio: h, crop: m, fit: d, format: l }; function p(r, [t, e]) { return a(e) ? r : o(t, i) ? i[t](e, r) : (o(t, n) && r.set(n[t], String(e)), r); } function h(r, t) { return t.set(n.aspectRatio, String(r)), t; } function m(r, t) { const e = String(r); return e === "center" || t.set(n.crop, e.replace(" ", ",")), t; } const c = { cover: "crop", contain: "clip" }; function d(r, t) { const e = String(r); return o(e, c) && t.set(n.fit, c[e]), t; } function l(r, t) { const e = String(r); return e === "auto" ? (t.set("auto", "format"), t) : (t.set(n.format, e), t); } const n = { aspectRatio: "ar", crop: "crop", dpr: "dpr", format: "fm", fit: "fit", height: "h", quality: "q", width: "w" }; export { g as adapter }; //# sourceMappingURL=adapter.js.map