UNPKG

@wordpress/block-library

Version:
1 lines • 5.47 kB
{"version":3,"file":"save.cjs","names":["getBorderClassesAndStyles","getShadowClassesAndStyles","mediaPosition","RichText","__experimentalGetElementClassName","useBlockProps"],"sources":["../../src/image/save.jsx"],"sourcesContent":["import clsx from 'clsx';\nimport {\n\tRichText,\n\tuseBlockProps,\n\t__experimentalGetElementClassName,\n\t__experimentalGetBorderClassesAndStyles as getBorderClassesAndStyles,\n\t__experimentalGetShadowClassesAndStyles as getShadowClassesAndStyles,\n} from '@wordpress/block-editor';\nimport { mediaPosition } from './utils';\n\nexport default function save( { attributes } ) {\n\tconst {\n\t\turl,\n\t\talt,\n\t\tcaption,\n\t\talign,\n\t\thref,\n\t\trel,\n\t\tlinkClass,\n\t\twidth,\n\t\theight,\n\t\taspectRatio,\n\t\tscale,\n\t\tfocalPoint,\n\t\tid,\n\t\tlinkTarget,\n\t\tsizeSlug,\n\t\ttitle,\n\t\tisDecorative,\n\t\tmetadata: { bindings = {} } = {},\n\t} = attributes;\n\n\tconst newRel = ! rel ? undefined : rel;\n\tconst borderProps = getBorderClassesAndStyles( attributes );\n\tconst shadowProps = getShadowClassesAndStyles( attributes );\n\n\tconst classes = clsx( {\n\t\t// All other align classes are handled by block supports.\n\t\t// `{ align: 'none' }` is unique to transforms for the image block.\n\t\talignnone: 'none' === align,\n\t\t[ `size-${ sizeSlug }` ]: sizeSlug,\n\t\t'is-resized': width || height,\n\t\t'has-custom-border':\n\t\t\t!! borderProps.className ||\n\t\t\t( borderProps.style &&\n\t\t\t\tObject.keys( borderProps.style ).length > 0 ),\n\t} );\n\n\tconst imageClasses = clsx( borderProps.className, {\n\t\t[ `wp-image-${ id }` ]: !! id,\n\t} );\n\n\tconst image = (\n\t\t<img\n\t\t\tsrc={ url }\n\t\t\talt={ alt }\n\t\t\tclassName={ imageClasses || undefined }\n\t\t\tstyle={ ( () => {\n\t\t\t\tconst style = {\n\t\t\t\t\t...borderProps.style,\n\t\t\t\t\t...shadowProps.style,\n\t\t\t\t\taspectRatio,\n\t\t\t\t\tobjectFit: scale,\n\t\t\t\t\tobjectPosition:\n\t\t\t\t\t\tfocalPoint && scale\n\t\t\t\t\t\t\t? mediaPosition( focalPoint )\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t};\n\t\t\t\t// Only apply dimension styles when a width or height is provided.\n\t\t\t\tif ( width !== undefined || height !== undefined ) {\n\t\t\t\t\t// Only apply width when explicitly provided.\n\t\t\t\t\tif ( width === 'auto' ) {\n\t\t\t\t\t\tstyle.width = 'auto';\n\t\t\t\t\t} else if ( width !== undefined && width !== null ) {\n\t\t\t\t\t\tstyle.width =\n\t\t\t\t\t\t\ttypeof width === 'number' ? `${ width }px` : width;\n\t\t\t\t\t}\n\t\t\t\t\t// Force height to auto when unspecified to prevent\n\t\t\t\t\t// theme CSS from squishing the image.\n\t\t\t\t\tif (\n\t\t\t\t\t\theight === 'auto' ||\n\t\t\t\t\t\theight === undefined ||\n\t\t\t\t\t\theight === null\n\t\t\t\t\t) {\n\t\t\t\t\t\tstyle.height = 'auto';\n\t\t\t\t\t} else {\n\t\t\t\t\t\tstyle.height =\n\t\t\t\t\t\t\ttypeof height === 'number'\n\t\t\t\t\t\t\t\t? `${ height }px`\n\t\t\t\t\t\t\t\t: height;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn style;\n\t\t\t} )() }\n\t\t\ttitle={ title }\n\t\t\trole={ isDecorative ? 'none' : undefined }\n\t\t/>\n\t);\n\n\tconst displayCaption =\n\t\t! RichText.isEmpty( caption ) ||\n\t\tbindings.caption ||\n\t\tbindings?.__default?.source === 'core/pattern-overrides';\n\n\tconst figure = (\n\t\t<>\n\t\t\t{ href ? (\n\t\t\t\t<a\n\t\t\t\t\tclassName={ linkClass }\n\t\t\t\t\thref={ href }\n\t\t\t\t\ttarget={ linkTarget }\n\t\t\t\t\trel={ newRel }\n\t\t\t\t>\n\t\t\t\t\t{ image }\n\t\t\t\t</a>\n\t\t\t) : (\n\t\t\t\timage\n\t\t\t) }\n\t\t\t{ displayCaption && (\n\t\t\t\t<RichText.Content\n\t\t\t\t\tclassName={ __experimentalGetElementClassName( 'caption' ) }\n\t\t\t\t\ttagName=\"figcaption\"\n\t\t\t\t\tvalue={ caption }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n\n\treturn (\n\t\t<figure { ...useBlockProps.save( { className: classes } ) }>\n\t\t\t{ figure }\n\t\t</figure>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,SAAwB,KAAM,EAAE,cAAe;CAC9C,MAAM,EACL,KACA,KACA,SACA,OACA,MACA,KACA,WACA,OACA,QACA,aACA,OACA,YACA,IACA,YACA,UACA,OACA,cACA,UAAU,EAAE,WAAW,CAAC,MAAM,CAAC,MAC5B;CAEJ,MAAM,SAAS,CAAE,MAAM,KAAA,IAAY;CACnC,MAAM,eAAA,GAAcA,wBAAAA,wCAAAA,CAA2B,UAAW;CAC1D,MAAM,eAAA,GAAcC,wBAAAA,wCAAAA,CAA2B,UAAW;CAE1D,MAAM,WAAA,GAAU,KAAA,QAAA,CAAM;EAGrB,WAAW,WAAW;GACpB,QAAS,aAAe;EAC1B,cAAc,SAAS;EACvB,qBACC,CAAC,CAAE,YAAY,aACb,YAAY,SACb,OAAO,KAAM,YAAY,KAAM,CAAC,CAAC,SAAS;CAC7C,CAAE;CAEF,MAAM,gBAAA,GAAe,KAAA,QAAA,CAAM,YAAY,WAAW,GAC/C,YAAa,OAAS,CAAC,CAAE,GAC5B,CAAE;CAEF,MAAM,QACL,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;EACC,KAAM;EACA;EACN,WAAY,gBAAgB,KAAA;EAC5B,cAAgB;GACf,MAAM,QAAQ;IACb,GAAG,YAAY;IACf,GAAG,YAAY;IACf;IACA,WAAW;IACX,gBACC,cAAc,SAAA,GACXC,WAAAA,cAAAA,CAAe,UAAW,IAC1B,KAAA;GACL;GAEA,IAAK,UAAU,K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