UNPKG

@wordpress/block-library

Version:
110 lines (109 loc) • 4.97 kB
"use strict"; 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 __shared_js = require("./shared.cjs"); let react_jsx_runtime = require("react/jsx-runtime"); // packages/block-library/src/cover/save.jsx function save({ attributes }) { const { backgroundType, gradient, contentPosition, customGradient, customOverlayColor, dimRatio, focalPoint, useFeaturedImage, hasParallax, isDark, isRepeated, overlayColor, url, alt, id, tagName: Tag, sizeSlug, poster } = attributes; const overlayColorClass = (0, _wordpress_block_editor.getColorClassName)("background-color", overlayColor); const gradientClass = (0, _wordpress_block_editor.__experimentalGetGradientClass)(gradient); const isImageBackground = __shared_js.IMAGE_BACKGROUND_TYPE === backgroundType; const isVideoBackground = __shared_js.VIDEO_BACKGROUND_TYPE === backgroundType; const isEmbedVideoBackground = __shared_js.EMBED_VIDEO_BACKGROUND_TYPE === backgroundType; const isImgElement = !(hasParallax || isRepeated); const bgStyle = { backgroundColor: !overlayColorClass ? customOverlayColor : void 0, background: customGradient ? customGradient : void 0 }; const objectPosition = focalPoint && isImgElement ? (0, __shared_js.mediaPosition)(focalPoint) : void 0; const backgroundImage = url ? `url(${url})` : void 0; const backgroundPosition = (0, __shared_js.mediaPosition)(focalPoint); const classes = (0, clsx.default)({ "is-light": !isDark, "has-parallax": hasParallax, "is-repeated": isRepeated, "has-custom-content-position": !(0, __shared_js.isContentPositionCenter)(contentPosition) }, (0, __shared_js.getPositionClassName)(contentPosition)); const imgClasses = (0, clsx.default)("wp-block-cover__image-background", id ? `wp-image-${id}` : null, { [`size-${sizeSlug}`]: sizeSlug, "has-parallax": hasParallax, "is-repeated": isRepeated }); const gradientValue = gradient || customGradient; return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Tag, { ..._wordpress_block_editor.useBlockProps.save({ className: classes }), children: [ !useFeaturedImage && isImageBackground && url && (isImgElement ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", { className: imgClasses, alt, src: url, style: { objectPosition } }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { role: alt ? "img" : void 0, "aria-label": alt ? alt : void 0, className: imgClasses, style: { backgroundPosition, backgroundImage } })), isVideoBackground && url && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("video", { className: (0, clsx.default)("wp-block-cover__video-background", "intrinsic-ignore"), autoPlay: true, muted: true, loop: true, playsInline: true, src: url, poster, style: { objectPosition } }), isEmbedVideoBackground && url && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("figure", { className: (0, clsx.default)("wp-block-cover__video-background", "wp-block-cover__embed-background", "wp-block-embed"), children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { className: "wp-block-embed__wrapper", children: url }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { "aria-hidden": "true", className: (0, clsx.default)("wp-block-cover__background", overlayColorClass, (0, __shared_js.dimRatioToClass)(dimRatio), { "has-background-dim": dimRatio !== void 0, "wp-block-cover__gradient-background": url && gradientValue && dimRatio !== 0, "has-background-gradient": gradientValue, [gradientClass]: gradientClass }), style: bgStyle }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { ..._wordpress_block_editor.useInnerBlocksProps.save({ className: "wp-block-cover__inner-container" }) }) ] }); } exports.default = save; //# sourceMappingURL=save.cjs.map