@nuxt/image
Version:
Nuxt Image Module
51 lines (50 loc) • 1.15 kB
JavaScript
import { joinURL, encodePath, withBase } from "ufo";
import { createOperationsGenerator } from "../utils/index.js";
import { defineProvider } from "../utils/provider.js";
const operationsGenerator = createOperationsGenerator({
keyMap: {
orientation: "or",
flip: "flip",
crop: "crop",
width: "w",
height: "h",
fit: "fit",
dpr: "dpr",
bri: "bri",
con: "con",
gam: "gam",
sharp: "sharp",
blur: "blur",
pixel: "pixel",
filt: "filt",
mark: "mark",
markw: "markw",
markh: "markh",
markx: "markx",
marky: "marky",
markpad: "markpad",
markpos: "markpos",
markalpha: "markalpha",
background: "bg",
border: "border",
quality: "q",
format: "fm"
},
valueMap: {
fit: {
fill: "fill",
inside: "max",
outside: "stretch",
cover: "crop",
contain: "contain"
}
}
});
export default defineProvider({
getImage: (src, { modifiers, baseURL = "/" }) => {
const params = operationsGenerator(modifiers);
return {
url: withBase(joinURL(encodePath(src) + (params ? "?" + params : "")), baseURL)
};
}
});