@nichoth/image
Version:
An image component
61 lines (60 loc) • 2.22 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var cloudinary_exports = {};
__export(cloudinary_exports, {
CloudinaryImage: () => CloudinaryImage
});
module.exports = __toCommonJS(cloudinary_exports);
var import_url_gen = require("@cloudinary/url-gen");
var import_srcset = require("./srcset.js");
function CloudinaryImage(cloudName) {
const cld = new import_url_gen.Cloudinary({
cloud: { cloudName },
url: { secure: true }
});
return { Image };
function Image(props) {
const {
className,
sizes,
filename,
decoding,
loading,
fetchpriority,
alt,
srcset
} = props;
const _class = props.class || className;
const { defaultSrcset, getSrcset } = (0, import_srcset.CloudinarySrcset)(cld);
return `<div class="${"image" + (_class ? ` ${_class}` : "")}">
<img
alt="${alt}"
srcset: ${srcset ? getSrcset(filename, srcset).join(", ") : defaultSrcset(filename)}
sizes="${sizes?.join(", ") || "100vw"}"
src="${cld.image(filename).format("auto").quality("auto").toURL()}"
decoding="${decoding || "auto"}"
loading="${loading || "lazy"}"
fetchpriority="${fetchpriority || "low"}"
>
</div>`;
}
__name(Image, "Image");
}
__name(CloudinaryImage, "CloudinaryImage");