@nichoth/image
Version:
An image component
41 lines (40 loc) • 1.72 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 srcset_exports = {};
__export(srcset_exports, {
CloudinarySrcset: () => CloudinarySrcset
});
module.exports = __toCommonJS(srcset_exports);
var import_resize = require("@cloudinary/url-gen/actions/resize");
function CloudinarySrcset(cld) {
function defaultSrcset(filename) {
const URIs = [cld.image(filename).format("auto").quality("auto").toURL() + " 1025w"].concat(getSrcset(filename, [1024, 768, 480]));
return URIs.join(", ");
}
__name(defaultSrcset, "defaultSrcset");
function getSrcset(filename, widths) {
return widths.map((n) => {
return cld.image(filename).format("auto").quality("auto").resize((0, import_resize.scale)().width(n)).toURL() + ` ${n}w`;
});
}
__name(getSrcset, "getSrcset");
return { defaultSrcset, getSrcset };
}
__name(CloudinarySrcset, "CloudinarySrcset");