{
  "version": 3,
  "sources": ["../../src/gallery/responsive-styles.js"],
  "sourcesContent": ["import { MAX_COLUMNS } from './constants';\n\nfunction isObject( value ) {\n\treturn !! value && typeof value === 'object' && ! Array.isArray( value );\n}\n\nexport function isValidGalleryColumns( value ) {\n\treturn Number.isInteger( value ) && value >= 1 && value <= MAX_COLUMNS;\n}\n\n/*\n * Aspect ratios are interpolated into a generated stylesheet instead of being\n * set as an inline style, so only the numeric forms produced by aspect ratio\n * presets (and `auto`) are accepted. A value from saved content that isn't one\n * of those is ignored rather than emitted, so it can't close the rule early and\n * inject declarations of its own. The frontend applies the same restriction in\n * `block_core_gallery_is_valid_aspect_ratio()`.\n */\nconst ASPECT_RATIO_PATTERN = /^(auto|\\d+(\\.\\d+)?(\\s*\\/\\s*\\d+(\\.\\d+)?)?)$/;\n\n/**\n * Returns whether a value can be used as a Gallery aspect ratio.\n *\n * @param {*} value Value to check.\n * @return {boolean} Whether the value is a valid aspect ratio.\n */\nexport function isValidGalleryAspectRatio( value ) {\n\treturn (\n\t\ttypeof value === 'string' && ASPECT_RATIO_PATTERN.test( value.trim() )\n\t);\n}\n\n/**\n * Returns Gallery styles for a viewport.\n *\n * @param {Object} style    Gallery block style attribute.\n * @param {string} viewport Viewport state.\n * @return {Object} Gallery viewport styles, or an empty object when unavailable.\n */\nexport function getViewportGalleryStyle( style, viewport ) {\n\tif ( ! isObject( style ) || ! isObject( style[ viewport ] ) ) {\n\t\treturn {};\n\t}\n\n\treturn style[ viewport ];\n}\n\nfunction cleanObject( value ) {\n\tif ( ! isObject( value ) ) {\n\t\treturn value;\n\t}\n\n\tconst entries = Object.entries( value ).filter(\n\t\t( [ , entryValue ] ) => entryValue !== undefined\n\t);\n\treturn entries.length ? Object.fromEntries( entries ) : undefined;\n}\n\n/**\n * Updates Gallery layout settings for a viewport without changing base values.\n *\n * @param {Object} options              Options.\n * @param {Object} options.style        Gallery block style attribute.\n * @param {string} options.viewport     Selected viewport state.\n * @param {Object} options.baseSettings Gallery base layout settings.\n * @param {Object} options.settings     Gallery layout settings to update.\n * @return {Object|undefined} Updated Gallery style attribute.\n */\nexport function getUpdatedGalleryStyle( {\n\tstyle,\n\tviewport,\n\tbaseSettings,\n\tsettings,\n} ) {\n\tconst currentStyle = isObject( style ) ? style : {};\n\tconst nextViewportStyle = {\n\t\t...getViewportGalleryStyle( currentStyle, viewport ),\n\t};\n\n\tObject.entries( settings ).forEach( ( [ key, value ] ) => {\n\t\tif ( value === undefined || value === baseSettings[ key ] ) {\n\t\t\tdelete nextViewportStyle[ key ];\n\t\t} else {\n\t\t\tnextViewportStyle[ key ] = value;\n\t\t}\n\t} );\n\n\tconst cleanedViewportStyle = cleanObject( nextViewportStyle );\n\tconst nextStyle = { ...currentStyle };\n\tif ( cleanedViewportStyle ) {\n\t\tnextStyle[ viewport ] = cleanedViewportStyle;\n\t} else {\n\t\tdelete nextStyle[ viewport ];\n\t}\n\n\treturn cleanObject( nextStyle );\n}\n\nfunction getGallerySelector( selector ) {\n\treturn `${ selector }.wp-block-gallery.has-nested-images`;\n}\n\nfunction getFlexGallerySelector( selector ) {\n\treturn `${ getGallerySelector( selector ) }:where(.is-layout-flex)`;\n}\n\nfunction getImageSelector( selector ) {\n\treturn `${ getFlexGallerySelector(\n\t\tselector\n\t) } figure.wp-block-image:not(#individual-image)`;\n}\n\nfunction getColumnsCSS( selector, columns ) {\n\t// Match the fallback used by the Gallery's existing column-width CSS and\n\t// server-rendered responsive styles when the gap custom property is unavailable.\n\tconst width =\n\t\tcolumns === 1\n\t\t\t? '100%'\n\t\t\t: `calc((100% - (var(--wp--style--unstable-gallery-gap, 16px) * ${\n\t\t\t\t\tcolumns - 1\n\t\t\t\t})) / ${ columns })`;\n\n\treturn `${ getImageSelector( selector ) }{width:${ width } !important;}`;\n}\n\nfunction getImageCropCSS( selector, imageCrop ) {\n\tconst imageSelector = getImageSelector( selector );\n\tconst wrapperSelector = `${ imageSelector } > div:not(.components-drop-zone)`;\n\tconst linkSelector = `${ imageSelector } > a`;\n\tconst mediaSelector = `${ imageSelector } a,${ imageSelector } img`;\n\n\tif ( imageCrop ) {\n\t\treturn `${ imageSelector }{align-self:inherit !important;margin-bottom:0 !important;}${ wrapperSelector },${ linkSelector }{display:flex !important;}${ mediaSelector }{width:100% !important;flex:1 0 0% !important;height:100% !important;object-fit:cover !important;}`;\n\t}\n\n\treturn `${ imageSelector }{align-self:auto !important;margin-top:0 !important;margin-bottom:auto !important;}${ wrapperSelector }{display:block !important;}${ linkSelector }{display:inline-block !important;}${ mediaSelector }{width:auto !important;flex:0 1 auto !important;height:auto !important;object-fit:fill !important;}`;\n}\n\nfunction getAspectRatioCSS( selector, aspectRatio ) {\n\tconst imageSelector = `${ getGallerySelector(\n\t\tselector\n\t) } figure.wp-block-image:not(#individual-image) img`;\n\tconst ratio = aspectRatio.trim();\n\n\tif ( ratio === 'auto' ) {\n\t\t/*\n\t\t * We need an explicit value here to cancel out the base aspect ratio. `auto` — and\n\t\t * `initial`, `unset` and `revert`, which all compute to it — would\n\t\t * override the `width`/`height` presentational hint that gives a\n\t\t * lazy-loaded image its placeholder ratio, collapsing the image to zero\n\t\t * height until it loads.\n\t\t * `revert-layer` drops the declaration instead, so the image falls back\n\t\t * to that hint while loading, to its natural ratio once loaded, and to\n\t\t * any ratio a theme set in a lower cascade layer. `object-fit` is left\n\t\t * as the base set it, so a cropped Gallery still crops.\n\t\t */\n\t\treturn `${ imageSelector }{aspect-ratio:revert-layer !important;}`;\n\t}\n\n\treturn `${ imageSelector }{aspect-ratio:${ ratio } !important;object-fit:cover !important;}`;\n}\n\n/**\n * Generates Gallery-specific responsive CSS.\n *\n * @param {string} selector     Gallery block selector.\n * @param {Object} style        Gallery block style attribute.\n * @param {Object} mediaQueries Map of viewport keys to media queries.\n * @return {string} Responsive Gallery CSS.\n */\nexport function getGalleryResponsiveCSS( selector, style, mediaQueries ) {\n\tif ( ! isObject( mediaQueries ) ) {\n\t\treturn '';\n\t}\n\n\treturn Object.entries( mediaQueries )\n\t\t.map( ( [ viewport, mediaQuery ] ) => {\n\t\t\tif ( typeof mediaQuery !== 'string' ) {\n\t\t\t\treturn '';\n\t\t\t}\n\n\t\t\tconst viewportStyle = getViewportGalleryStyle( style, viewport );\n\t\t\tlet css = '';\n\n\t\t\tif ( isValidGalleryColumns( viewportStyle.columns ) ) {\n\t\t\t\tcss += getColumnsCSS( selector, viewportStyle.columns );\n\t\t\t}\n\n\t\t\tif ( typeof viewportStyle.imageCrop === 'boolean' ) {\n\t\t\t\tcss += getImageCropCSS( selector, viewportStyle.imageCrop );\n\t\t\t}\n\n\t\t\tif ( isValidGalleryAspectRatio( viewportStyle.aspectRatio ) ) {\n\t\t\t\tcss += getAspectRatioCSS( selector, viewportStyle.aspectRatio );\n\t\t\t}\n\n\t\t\treturn css ? `${ mediaQuery }{${ css }}` : '';\n\t\t} )\n\t\t.join( '' );\n}\n"],
  "mappings": ";AAAA,SAAS,mBAAmB;AAE5B,SAAS,SAAU,OAAQ;AAC1B,SAAO,CAAC,CAAE,SAAS,OAAO,UAAU,YAAY,CAAE,MAAM,QAAS,KAAM;AACxE;AAEO,SAAS,sBAAuB,OAAQ;AAC9C,SAAO,OAAO,UAAW,KAAM,KAAK,SAAS,KAAK,SAAS;AAC5D;AAUA,IAAM,uBAAuB;AAQtB,SAAS,0BAA2B,OAAQ;AAClD,SACC,OAAO,UAAU,YAAY,qBAAqB,KAAM,MAAM,KAAK,CAAE;AAEvE;AASO,SAAS,wBAAyB,OAAO,UAAW;AAC1D,MAAK,CAAE,SAAU,KAAM,KAAK,CAAE,SAAU,MAAO,QAAS,CAAE,GAAI;AAC7D,WAAO,CAAC;AAAA,EACT;AAEA,SAAO,MAAO,QAAS;AACxB;AAEA,SAAS,YAAa,OAAQ;AAC7B,MAAK,CAAE,SAAU,KAAM,GAAI;AAC1B,WAAO;AAAA,EACR;AAEA,QAAM,UAAU,OAAO,QAAS,KAAM,EAAE;AAAA,IACvC,CAAE,CAAE,EAAE,UAAW,MAAO,eAAe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