@wordpress/components
Version:
UI components for WordPress.
63 lines (50 loc) • 2.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getBlockPaddings = getBlockPaddings;
exports.getBlockColors = getBlockColors;
exports.BLOCK_STYLE_ATTRIBUTES = void 0;
var _lodash = require("lodash");
/**
* External dependencies
*/
const BLOCK_STYLE_ATTRIBUTES = ['textColor', 'backgroundColor']; // Mapping style properties name to native
exports.BLOCK_STYLE_ATTRIBUTES = BLOCK_STYLE_ATTRIBUTES;
const BLOCK_STYLE_ATTRIBUTES_MAPPING = {
textColor: 'color'
};
const PADDING = 12; // solid-border-space
function getBlockPaddings(mergedStyle, wrapperPropsStyle, blockStyleAttributes) {
const blockPaddings = {};
if (!mergedStyle.padding && (wrapperPropsStyle !== null && wrapperPropsStyle !== void 0 && wrapperPropsStyle.backgroundColor || blockStyleAttributes !== null && blockStyleAttributes !== void 0 && blockStyleAttributes.backgroundColor)) {
blockPaddings.padding = PADDING;
return blockPaddings;
} // Prevent adding extra paddings to inner blocks without background colors
if (mergedStyle !== null && mergedStyle !== void 0 && mergedStyle.padding && !(wrapperPropsStyle !== null && wrapperPropsStyle !== void 0 && wrapperPropsStyle.backgroundColor) && !(blockStyleAttributes !== null && blockStyleAttributes !== void 0 && blockStyleAttributes.backgroundColor)) {
blockPaddings.padding = undefined;
}
return blockPaddings;
}
function getBlockColors(blockStyleAttributes, defaultColors) {
const blockStyles = {};
Object.entries(blockStyleAttributes).forEach(([key, value]) => {
const isCustomColor = (0, _lodash.startsWith)(value, '#');
let styleKey = key;
if (BLOCK_STYLE_ATTRIBUTES_MAPPING[styleKey]) {
styleKey = BLOCK_STYLE_ATTRIBUTES_MAPPING[styleKey];
}
if (!isCustomColor) {
const mappedColor = (0, _lodash.find)(defaultColors, {
slug: value
});
if (mappedColor) {
blockStyles[styleKey] = mappedColor.color;
}
} else {
blockStyles[styleKey] = value;
}
});
return blockStyles;
}
//# sourceMappingURL=utils.native.js.map