@wordpress/block-library
Version:
Block library for the WordPress editor.
87 lines (86 loc) • 3.85 kB
JavaScript
;
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
// \0rolldown/runtime.js
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
key = keys[i];
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: ((k) => from[k]).bind(null, key),
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
value: mod,
enumerable: true
}) : target, mod));
let clsx = require("clsx");
clsx = __toESM(clsx);
let _wordpress_block_editor = require("@wordpress/block-editor");
let __utils_js = require("./utils.cjs");
let react_jsx_runtime = require("react/jsx-runtime");
// packages/block-library/src/image/save.jsx
function save({ attributes }) {
const { url, alt, caption, align, href, rel, linkClass, width, height, aspectRatio, scale, focalPoint, id, linkTarget, sizeSlug, title, isDecorative, metadata: { bindings = {} } = {} } = attributes;
const newRel = !rel ? void 0 : rel;
const borderProps = (0, _wordpress_block_editor.__experimentalGetBorderClassesAndStyles)(attributes);
const shadowProps = (0, _wordpress_block_editor.__experimentalGetShadowClassesAndStyles)(attributes);
const classes = (0, clsx.default)({
alignnone: "none" === align,
[`size-${sizeSlug}`]: sizeSlug,
"is-resized": width || height,
"has-custom-border": !!borderProps.className || borderProps.style && Object.keys(borderProps.style).length > 0
});
const imageClasses = (0, clsx.default)(borderProps.className, { [`wp-image-${id}`]: !!id });
const image = /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
src: url,
alt,
className: imageClasses || void 0,
style: (() => {
const style = {
...borderProps.style,
...shadowProps.style,
aspectRatio,
objectFit: scale,
objectPosition: focalPoint && scale ? (0, __utils_js.mediaPosition)(focalPoint) : void 0
};
if (width !== void 0 || height !== void 0) {
if (width === "auto") style.width = "auto";
else if (width !== void 0 && width !== null) style.width = typeof width === "number" ? `${width}px` : width;
if (height === "auto" || height === void 0 || height === null) style.height = "auto";
else style.height = typeof height === "number" ? `${height}px` : height;
}
return style;
})(),
title,
role: isDecorative ? "none" : void 0
});
const displayCaption = !_wordpress_block_editor.RichText.isEmpty(caption) || bindings.caption || bindings?.__default?.source === "core/pattern-overrides";
const figure = /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [href ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
className: linkClass,
href,
target: linkTarget,
rel: newRel,
children: image
}) : image, displayCaption && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.RichText.Content, {
className: (0, _wordpress_block_editor.__experimentalGetElementClassName)("caption"),
tagName: "figcaption",
value: caption
})] });
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("figure", {
..._wordpress_block_editor.useBlockProps.save({ className: classes }),
children: figure
});
}
exports.default = save;
//# sourceMappingURL=save.cjs.map