@yoot/yoot
Version:
The core library for yoot, providing a CDN-agnostic, chainable API for image URL transformations and adapter integration.
41 lines (40 loc) • 1.33 kB
JavaScript
import { _getConfig as i } from "./config.js";
import { adapterStore as n } from "./store.js";
import { invariant as e } from "./utils.js";
const m = (...t) => {
t.forEach(p);
const r = t.map(Object.freeze);
n.register(...r);
}, o = (t) => ({ ...t }), u = o;
function p(t) {
e(typeof t.supports == "function", "Adapter must implement `supports` function"), e(typeof t.generateUrl == "function", "Adapter must implement `generateUrl` function"), e(typeof t.normalizeUrl == "function", "Adapter must implement `normalizeUrl` function"), "primeState" in t && e(typeof t.primeState == "function", "Adapter `primeState` must be a function");
}
function g(t) {
e(t instanceof URL, "Expected `url` be an instance of URL");
const r = n.get(t);
if (!r) {
const { onMissingAdapter: a } = i();
return a?.(t) ?? s(
new Error(
`[yoot] No adapter found for URL: ${t.href}
Did you forget to register an adapter via adapterStore.register(...) or set adapterStore.onMissingAdapter?`
)
);
}
return r;
}
const s = (t) => {
throw t;
}, A = o({
supports: () => !0,
generateUrl: ({ src: t }) => t,
normalizeUrl: (t) => t.href
});
export {
g as _getAdapter,
u as createAdapter,
o as defineAdapter,
A as passThroughAdapter,
m as registerAdapters
};
//# sourceMappingURL=adapter.js.map