@yoot/cloudinary
Version:
Cloudinary adapter for @yoot/yoot
78 lines (77 loc) • 1.69 kB
JavaScript
import { defineAdapter as s } from "@yoot/yoot";
import { _isEmpty as h, _isKeyOf as c } from "@yoot/yoot/internal";
const D = s({
supports: (r) => r.hostname === "res.cloudinary.com" || r.hostname === "cloudinary-a.akamaihd.net",
generateUrl: m,
normalizeUrl: l
});
function l(r) {
const [t, n] = u(r.href), o = new URL(`${t}${n}`);
return o.search = "", o.hash = "", o.href;
}
function m(r) {
const { src: t, directives: n } = r, o = Object.entries(n).reduce(R, []).join(",");
return _(t, o);
}
const a = {
aspectRatio: d,
crop: y,
fit: A,
format: P
};
function R(r, [t, n]) {
return h(n) ? r : c(t, a) ? a[t](n, r) : (c(t, e) && r.push(i(e[t], n)), r);
}
function _(r, t) {
t && (t = t.concat("/"));
const [n, o] = u(r);
return `${n}${t}${o}`;
}
const g = /(^.+(upload|fetch|private|authenticated|sprite|facebook|twitter|youtube|vimeo)\/)((?:[^_/]+_[^,/]+,?)*\/)?(.+)/;
function u(r) {
const [, t, , , n] = r.split(g);
return [t, n];
}
function i(r, t) {
return `${r}_${t}`;
}
function d(r, t) {
return t.push(i(e.aspectRatio, r)), t;
}
const f = {
center: "center",
top: "north",
bottom: "south",
left: "west",
right: "east"
};
function y(r, t) {
const n = String(r);
return c(n, f) && t.push(i(e.crop, f[n])), t;
}
const p = {
cover: "fill",
contain: "fit"
};
function A(r, t) {
const n = String(r);
return c(n, p) && t.push(i(e.fit, p[n])), t;
}
function P(r, t) {
return t.push(i(e.format, String(r))), t;
}
const e = {
aspectRatio: "ar",
dpr: "dpr",
crop: "g",
fit: "c",
format: "f",
height: "h",
quality: "q",
width: "w"
};
export {
D as adapter,
u as urlParts
};
//# sourceMappingURL=adapter.js.map