@wordpress/block-editor
Version:
8 lines (7 loc) • 4.17 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../src/layouts/utils.js"],
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { LAYOUT_DEFINITIONS } from './definitions';\n\n/**\n * Utility to generate the proper CSS selector for layout styles.\n *\n * @param {string} selectors CSS selector, also supports multiple comma-separated selectors.\n * @param {string} append The string to append.\n *\n * @return {string} - CSS selector.\n */\nexport function appendSelectors( selectors, append = '' ) {\n\treturn selectors\n\t\t.split( ',' )\n\t\t.map(\n\t\t\t( subselector ) =>\n\t\t\t\t`${ subselector }${ append ? ` ${ append }` : '' }`\n\t\t)\n\t\t.join( ',' );\n}\n\n/**\n * Get generated blockGap CSS rules based on layout definitions provided in theme.json\n * Falsy values in the layout definition's spacingStyles rules will be swapped out\n * with the provided `blockGapValue`.\n *\n * @param {string} selector The CSS selector to target for the generated rules.\n * @param {Object} layoutDefinitions Layout definitions object.\n * @param {string} layoutType The layout type (e.g. `default` or `flex`).\n * @param {string} blockGapValue The current blockGap value to be applied.\n * @return {string} The generated CSS rules.\n */\nexport function getBlockGapCSS(\n\tselector,\n\tlayoutDefinitions = LAYOUT_DEFINITIONS,\n\tlayoutType,\n\tblockGapValue\n) {\n\tlet output = '';\n\tif (\n\t\tlayoutDefinitions?.[ layoutType ]?.spacingStyles?.length &&\n\t\tblockGapValue\n\t) {\n\t\tlayoutDefinitions[ layoutType ].spacingStyles.forEach( ( gapStyle ) => {\n\t\t\toutput += `${ appendSelectors(\n\t\t\t\tselector,\n\t\t\t\tgapStyle.selector.trim()\n\t\t\t) } { `;\n\t\t\toutput += Object.entries( gapStyle.rules )\n\t\t\t\t.map(\n\t\t\t\t\t( [ cssProperty, value ] ) =>\n\t\t\t\t\t\t`${ cssProperty }: ${ value ? value : blockGapValue }`\n\t\t\t\t)\n\t\t\t\t.join( '; ' );\n\t\t\toutput += '; }';\n\t\t} );\n\t}\n\treturn output;\n}\n\n/**\n * Helper method to assign contextual info to clarify\n * alignment settings.\n *\n * Besides checking if `contentSize` and `wideSize` have a\n * value, we now show this information only if their values\n * are not a `css var`. This needs to change when parsing\n * css variables land.\n *\n * @see https://github.com/WordPress/gutenberg/pull/34710#issuecomment-918000752\n *\n * @param {Object} layout The layout object.\n * @return {Object} An object with contextual info per alignment.\n */\nexport function getAlignmentsInfo( layout ) {\n\tconst { contentSize, wideSize, type = 'default' } = layout;\n\tconst alignmentInfo = {};\n\tconst sizeRegex =\n\t\t/^(?!0)\\d+(px|em|rem|vw|vh|%|svw|lvw|dvw|svh|lvh|dvh|vi|svi|lvi|dvi|vb|svb|lvb|dvb|vmin|svmin|lvmin|dvmin|vmax|svmax|lvmax|dvmax)?$/i;\n\tif ( sizeRegex.test( contentSize ) && type === 'constrained' ) {\n\t\t// translators: %s: container size (i.e. 600px etc)\n\t\talignmentInfo.none = sprintf( __( 'Max %s wide' ), contentSize );\n\t}\n\tif ( sizeRegex.test( wideSize ) ) {\n\t\t// translators: %s: container size (i.e. 600px etc)\n\t\talignmentInfo.wide = sprintf( __( 'Max %s wide' ), wideSize );\n\t}\n\treturn alignmentInfo;\n}\n"],
"mappings": ";AAGA,SAAS,IAAI,eAAe;AAK5B,SAAS,0BAA0B;AAU5B,SAAS,gBAAiB,WAAW,SAAS,IAAK;AACzD,SAAO,UACL,MAAO,GAAI,EACX;AAAA,IACA,CAAE,gBACD,GAAI,WAAY,GAAI,SAAS,IAAK,MAAO,KAAK,EAAG;AAAA,EACnD,EACC,KAAM,GAAI;AACb;AAaO,SAAS,eACf,UACA,oBAAoB,oBACpB,YACA,eACC;AACD,MAAI,SAAS;AACb,MACC,oBAAqB,UAAW,GAAG,eAAe,UAClD,eACC;AACD,sBAAmB,UAAW,EAAE,cAAc,QAAS,CAAE,aAAc;AACtE,gBAAU,GAAI;AAAA,QACb;AAAA,QACA,SAAS,SAAS,KAAK;AAAA,MACxB,CAAE;AACF,gBAAU,OAAO,QAAS,SAAS,KAAM,EACvC;AAAA,QACA,CAAE,CAAE,aAAa,KAAM,MACtB,GAAI,WAAY,KAAM,QAAQ,QAAQ,aAAc;AAAA,MACtD,EACC,KAAM,IAAK;AACb,gBAAU;AAAA,IACX,CAAE;AAAA,EACH;AACA,SAAO;AACR;AAgBO,SAAS,kBAAmB,QAAS;AAC3C,QAAM,EAAE,aAAa,UAAU,OAAO,UAAU,IAAI;AACpD,QAAM,gBAAgB,CAAC;AACvB,QAAM,YACL;AACD,MAAK,UAAU,KAAM,WAAY,KAAK,SAAS,eAAgB;AAE9D,kBAAc,OAAO,QAAS,GAAI,aAAc,GAAG,WAAY;AAAA,EAChE;AACA,MAAK,UAAU,KAAM,QAAS,GAAI;AAEjC,kBAAc,OAAO,QAAS,GAAI,aAAc,GAAG,QAAS;AAAA,EAC7D;AACA,SAAO;AACR;",
"names": []
}