UNPKG

@wordpress/block-library

Version:
1 lines • 2.41 kB
{"version":3,"file":"shared.cjs","names":[],"sources":["../../src/gallery/shared.js"],"sourcesContent":["export function defaultColumnsNumber( imageCount ) {\n\treturn imageCount ? Math.min( 3, imageCount ) : 3;\n}\n\n/**\n * Whether a value is a plain object (and not an array).\n *\n * @param {*} value The value to check.\n * @return {boolean} Whether the value is a plain object.\n */\nexport function isObject( value ) {\n\treturn !! value && typeof value === 'object' && ! Array.isArray( value );\n}\n\n/**\n * Whether the Gallery should use its default Flex layout behavior.\n *\n * Gallery blocks created before layout variations existed do not have an\n * explicit layout attribute. Treat missing and malformed layout data as Flex\n * so existing galleries keep their current appearance.\n *\n * @param {*} layout The Gallery layout attribute.\n * @return {boolean} Whether the Gallery uses its Flex layout.\n */\nexport function isGalleryFlexLayout( layout ) {\n\tconst layoutType = isObject( layout ) ? layout.type : undefined;\n\n\treturn (\n\t\ttypeof layoutType !== 'string' ||\n\t\tlayoutType === '' ||\n\t\tlayoutType === 'flex'\n\t);\n}\n\nexport const pickRelevantMediaFiles = ( image, sizeSlug = 'large' ) => {\n\tconst imageProps = Object.fromEntries(\n\t\tObject.entries( image ?? {} ).filter( ( [ key ] ) =>\n\t\t\t[ 'alt', 'id', 'link' ].includes( key )\n\t\t)\n\t);\n\n\timageProps.url =\n\t\timage?.sizes?.[ sizeSlug ]?.url ||\n\t\timage?.media_details?.sizes?.[ sizeSlug ]?.source_url ||\n\t\timage?.url ||\n\t\timage?.source_url;\n\tconst fullUrl =\n\t\timage?.sizes?.full?.url ||\n\t\timage?.media_details?.sizes?.full?.source_url;\n\tif ( fullUrl ) {\n\t\timageProps.fullUrl = fullUrl;\n\t}\n\treturn imageProps;\n};\n"],"mappings":";;;;;;AAAA,SAAgB,qBAAsB,YAAa;CAClD,OAAO,aAAa,KAAK,IAAK,GAAG,UAAW,IAAI;AACjD;;;;;;;AAQA,SAAgB,SAAU,OAAQ;CACjC,OAAO,CAAC,CAAE,SAAS,OAAO,UAAU,YAAY,CAAE,MAAM,QAAS,KAAM;AACxE;;;;;;;;;;;AAYA,SAAgB,oBAAqB,QAAS;CAC7C,MAAM,aAAa,SAAU,MAAO,IAAI,OAAO,OAAO,KAAA;CAEtD,OACC,OAAO,eAAe,YACtB,eAAe,MACf,eAAe;AAEjB;AAEA,MAAa,0BAA2B,OAAO,WAAW,YAAa;CACtE,MAAM,aAAa,OAAO,YACzB,OAAO,QAAS,SAAS,CAAC,CAAE,CAAC,CAAC,QAAU,CAAE,SACzC;EAAE;EAAO;EAAM;CAAO,CAAC,CAAC,SAAU,GAAI,CACvC,CACD;CAEA,WAAW,MACV,OAAO,QAAS,SAAU,EAAE,OAC5B,OAAO,eAAe,QAAS,SAAU,EAAE,cAC3C,OAAO,OACP,OAAO;CACR,MAAM,UACL,OAAO,OAAO,MAAM,OACpB,OAAO,eAAe,OAAO,MAAM;CACpC,IAAK,SACJ,WAAW,UAAU;CAEtB,OAAO;AACR"}