WordPress/wp-includes/js/dist/style-engine.js
hellofromTonya cce69f5098 Editor: Update packages for 6.1 Beta 2.
Package updates for bug and regression fixes:

* @wordpress/block-directory: 3.15.3
* @wordpress/block-editor: 10.0.3
* @wordpress/block-library: 7.14.3
* @wordpress/block-serialization-default-parser: 4.17.1
* @wordpress/blocks: 11.16.3
* @wordpress/components: 21.0.3
* @wordpress/compose: 5.15.2
* @wordpress/core-data: 5.0.3
* @wordpress/customize-widgets: 3.14.3
* @wordpress/edit-post: 6.14.3
* @wordpress/edit-site: 4.14.4
* @wordpress/edit-widgets: 4.14.3
* @wordpress/editor: 12.16.3
* @wordpress/format-library: 3.15.3
* @wordpress/interface: 4.16.3
* @wordpress/list-reusable-blocks: 3.15.3
* @wordpress/nux: 5.15.3
* @wordpress/preferences: 2.9.3
* @wordpress/reusable-blocks: 3.15.3
* @wordpress/server-side-render: 3.15.3
* @wordpress/style-engine: 1.0.2
* @wordpress/widgets: 2.15.3

References:
* [https://github.com/WordPress/gutenberg/pull/44233 Gutenberg PR 44233] – Blocks: Fix searching of blocks when description is non-string
* [https://github.com/WordPress/gutenberg/pull/44301 Gutenberg PR 44301] – Block Toolbar: update position when moving blocks
* [https://github.com/WordPress/gutenberg/pull/44334 Gutenberg PR 44334] – Global Styles: Re-add styles that were removed, for classic themes
* [https://github.com/WordPress/gutenberg/pull/44351 Gutenberg PR 44351] – Comments block: Support nested comments settings in the comments blocks
* [https://github.com/WordPress/gutenberg/pull/44448 Gutenberg PR 44448] – Add a correct TS signature for useEntityRecords
* [https://github.com/WordPress/gutenberg/pull/44315 Gutenberg PR 44315] – Pullquote: fix transform to quote crash
* [https://github.com/WordPress/gutenberg/pull/44446 Gutenberg PR 44446] – Fix spacing property generation in flow layout type.
* [https://github.com/WordPress/gutenberg/pull/44408 Gutenberg PR 44408] – Upgrade react-easy-crop to bring in fix for site editor iframe
* [https://github.com/WordPress/gutenberg/pull/44406 Gutenberg PR 44406] – Style engine: kebab case preset slugs in the editor
* [https://github.com/WordPress/gutenberg/pull/44209 Gutenberg PR 44209] – Fixing padding on the post editor when RootPaddingAwareAlignments setting is enabled
* [https://github.com/WordPress/gutenberg/pull/42950 Gutenberg PR 42950] – Popover: fix limitShift logic by adding iframe offset correctly (and a custom shift limiter)
* [https://github.com/WordPress/gutenberg/pull/44337 Gutenberg PR 44337] – Submenu block href only if url is not empty
* [https://github.com/WordPress/gutenberg/pull/44291 Gutenberg PR 44291] – Add role=application to list view to prevent browse mode triggering in NVDA
* [https://github.com/WordPress/gutenberg/pull/44283 Gutenberg PR 44283] – Navigation block: Fix submenu colors for imported classic menus
* [https://github.com/WordPress/gutenberg/pull/44282 Gutenberg PR 44282] – Fix popover stacking in the customize widgets editor
* [https://github.com/WordPress/gutenberg/pull/44247 Gutenberg PR 44247] – Spacing presets: switch to using numbers instead of t-shirt sizes for labels
* [https://github.com/WordPress/gutenberg/pull/44299 Gutenberg PR 44299] – Backport template creation changes from core
* [https://github.com/WordPress/gutenberg/pull/44294 Gutenberg PR 44294] – [Block Library - Query Loop]: Fix broken preview in specific category template
* [https://github.com/WordPress/gutenberg/pull/44287 Gutenberg PR 44287] – [Block Library]: Rename Comments pagination inner blocks
* [https://github.com/WordPress/gutenberg/pull/44256 Gutenberg PR 44256] – Avoid showing the recursion warning in previews when replacing template parts
* [https://github.com/WordPress/gutenberg/pull/44265 Gutenberg PR 44265] – Blocks: officially deprecated the children and node matchers
* [https://github.com/WordPress/gutenberg/pull/44251 Gutenberg PR 44251] – Global styles: Remove the beta label from global styles header

Props bernhard-reiter, cbravobernal.
See #56467.
Built from https://develop.svn.wordpress.org/trunk@54335


git-svn-id: http://core.svn.wordpress.org/trunk@53894 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-27 17:32:52 +00:00

515 lines
17 KiB
JavaScript

/******/ (function() { // webpackBootstrap
/******/ "use strict";
/******/ // The require scope
/******/ var __webpack_require__ = {};
/******/
/************************************************************************/
/******/ /* webpack/runtime/define property getters */
/******/ !function() {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = function(exports, definition) {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ }();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ !function() {
/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
/******/ }();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ !function() {
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ }();
/******/
/************************************************************************/
var __webpack_exports__ = {};
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);
// EXPORTS
__webpack_require__.d(__webpack_exports__, {
"compileCSS": function() { return /* binding */ compileCSS; },
"getCSSRules": function() { return /* binding */ getCSSRules; }
});
;// CONCATENATED MODULE: external "lodash"
var external_lodash_namespaceObject = window["lodash"];
;// CONCATENATED MODULE: ./node_modules/@wordpress/style-engine/build-module/styles/constants.js
const VARIABLE_REFERENCE_PREFIX = 'var:';
const VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE = '|';
const VARIABLE_PATH_SEPARATOR_TOKEN_STYLE = '--';
;// CONCATENATED MODULE: ./node_modules/@wordpress/style-engine/build-module/styles/utils.js
/**
* External dependencies
*/
/**
* Internal dependencies
*/
/**
* Returns a JSON representation of the generated CSS rules.
*
* @param style Style object.
* @param options Options object with settings to adjust how the styles are generated.
* @param path An array of strings representing the path to the style value in the style object.
* @param ruleKey A CSS property key.
*
* @return GeneratedCSSRule[] CSS rules.
*/
function generateRule(style, options, path, ruleKey) {
const styleValue = (0,external_lodash_namespaceObject.get)(style, path);
return styleValue ? [{
selector: options === null || options === void 0 ? void 0 : options.selector,
key: ruleKey,
value: getCSSVarFromStyleValue(styleValue)
}] : [];
}
/**
* Returns a JSON representation of the generated CSS rules taking into account box model properties, top, right, bottom, left.
*
* @param style Style object.
* @param options Options object with settings to adjust how the styles are generated.
* @param path An array of strings representing the path to the style value in the style object.
* @param ruleKeys An array of CSS property keys and patterns.
* @param individualProperties The "sides" or individual properties for which to generate rules.
*
* @return GeneratedCSSRule[] CSS rules.
*/
function generateBoxRules(style, options, path, ruleKeys) {
let individualProperties = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : ['top', 'right', 'bottom', 'left'];
const boxStyle = (0,external_lodash_namespaceObject.get)(style, path);
if (!boxStyle) {
return [];
}
const rules = [];
if (typeof boxStyle === 'string') {
rules.push({
selector: options === null || options === void 0 ? void 0 : options.selector,
key: ruleKeys.default,
value: boxStyle
});
} else {
const sideRules = individualProperties.reduce((acc, side) => {
const value = getCSSVarFromStyleValue((0,external_lodash_namespaceObject.get)(boxStyle, [side]));
if (value) {
acc.push({
selector: options === null || options === void 0 ? void 0 : options.selector,
key: ruleKeys === null || ruleKeys === void 0 ? void 0 : ruleKeys.individual.replace('%s', upperFirst(side)),
value
});
}
return acc;
}, []);
rules.push(...sideRules);
}
return rules;
}
/**
* Returns a CSS var value from incoming style value following the pattern `var:description|context|slug`.
*
* @param styleValue A raw style value.
*
* @return string A CSS var value.
*/
function getCSSVarFromStyleValue(styleValue) {
if (typeof styleValue === 'string' && styleValue.startsWith(VARIABLE_REFERENCE_PREFIX)) {
const variable = styleValue.slice(VARIABLE_REFERENCE_PREFIX.length).split(VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE).map(presetVariable => (0,external_lodash_namespaceObject.kebabCase)(presetVariable)).join(VARIABLE_PATH_SEPARATOR_TOKEN_STYLE);
return `var(--wp--${variable})`;
}
return styleValue;
}
/**
* Capitalizes the first letter in a string.
*
* @param {string} str The string whose first letter the function will capitalize.
*
* @return string A CSS var value.
*/
function upperFirst(_ref) {
let [firstLetter, ...rest] = _ref;
return firstLetter.toUpperCase() + rest.join('');
}
;// CONCATENATED MODULE: ./node_modules/@wordpress/style-engine/build-module/styles/border/index.js
/**
* Internal dependencies
*/
const color = {
name: 'color',
generate: function (style, options) {
let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ['border', 'color'];
let ruleKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'borderColor';
return generateRule(style, options, path, ruleKey);
}
};
const radius = {
name: 'radius',
generate: (style, options) => {
return generateBoxRules(style, options, ['border', 'radius'], {
default: 'borderRadius',
individual: 'border%sRadius'
}, ['topLeft', 'topRight', 'bottomLeft', 'bottomRight']);
}
};
const borderStyle = {
name: 'style',
generate: function (style, options) {
let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ['border', 'style'];
let ruleKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'borderStyle';
return generateRule(style, options, path, ruleKey);
}
};
const width = {
name: 'width',
generate: function (style, options) {
let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ['border', 'width'];
let ruleKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'borderWidth';
return generateRule(style, options, path, ruleKey);
}
};
const borderDefinitionsWithIndividualStyles = [color, borderStyle, width];
/**
* Returns a curried generator function with the individual border property ('top' | 'right' | 'bottom' | 'left') baked in.
*
* @param individualProperty Individual border property ('top' | 'right' | 'bottom' | 'left').
*
* @return StyleDefinition[ 'generate' ]
*/
const createBorderGenerateFunction = individualProperty => (style, options) => {
var _style$border;
const styleValue = style === null || style === void 0 ? void 0 : (_style$border = style.border) === null || _style$border === void 0 ? void 0 : _style$border[individualProperty];
if (!styleValue) {
return [];
}
return borderDefinitionsWithIndividualStyles.reduce((acc, borderDefinition) => {
const key = borderDefinition.name;
if (styleValue.hasOwnProperty(key) && typeof borderDefinition.generate === 'function') {
const ruleKey = `border${upperFirst(individualProperty)}${upperFirst(key)}`;
acc.push(...borderDefinition.generate(style, options, ['border', individualProperty, key], ruleKey));
}
return acc;
}, []);
};
const borderTop = {
name: 'borderTop',
generate: createBorderGenerateFunction('top')
};
const borderRight = {
name: 'borderRight',
generate: createBorderGenerateFunction('right')
};
const borderBottom = {
name: 'borderBottom',
generate: createBorderGenerateFunction('bottom')
};
const borderLeft = {
name: 'borderLeft',
generate: createBorderGenerateFunction('left')
};
/* harmony default export */ var border = ([...borderDefinitionsWithIndividualStyles, radius, borderTop, borderRight, borderBottom, borderLeft]);
;// CONCATENATED MODULE: ./node_modules/@wordpress/style-engine/build-module/styles/color/background.js
/**
* Internal dependencies
*/
const background = {
name: 'background',
generate: (style, options) => {
return generateRule(style, options, ['color', 'background'], 'backgroundColor');
}
};
/* harmony default export */ var color_background = (background);
;// CONCATENATED MODULE: ./node_modules/@wordpress/style-engine/build-module/styles/color/gradient.js
/**
* Internal dependencies
*/
const gradient = {
name: 'gradient',
generate: (style, options) => {
return generateRule(style, options, ['color', 'gradient'], 'background');
}
};
/* harmony default export */ var color_gradient = (gradient);
;// CONCATENATED MODULE: ./node_modules/@wordpress/style-engine/build-module/styles/color/text.js
/**
* Internal dependencies
*/
const text_text = {
name: 'text',
generate: (style, options) => {
return generateRule(style, options, ['color', 'text'], 'color');
}
};
/* harmony default export */ var color_text = (text_text);
;// CONCATENATED MODULE: ./node_modules/@wordpress/style-engine/build-module/styles/color/index.js
/**
* Internal dependencies
*/
/* harmony default export */ var styles_color = ([color_text, color_gradient, color_background]);
;// CONCATENATED MODULE: ./node_modules/@wordpress/style-engine/build-module/styles/shadow/index.js
/**
* Internal dependencies
*/
const shadow = {
name: 'shadow',
generate: (style, options) => {
return generateRule(style, options, ['shadow'], 'boxShadow');
}
};
/* harmony default export */ var styles_shadow = ([shadow]);
;// CONCATENATED MODULE: ./node_modules/@wordpress/style-engine/build-module/styles/outline/index.js
/**
* Internal dependencies
*/
const outline_color = {
name: 'color',
generate: function (style, options) {
let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ['outline', 'color'];
let ruleKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'outlineColor';
return generateRule(style, options, path, ruleKey);
}
};
const offset = {
name: 'offset',
generate: function (style, options) {
let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ['outline', 'offset'];
let ruleKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'outlineColor';
return generateRule(style, options, path, ruleKey);
}
};
const outlineStyle = {
name: 'style',
generate: function (style, options) {
let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ['outline', 'style'];
let ruleKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'outlineStyle';
return generateRule(style, options, path, ruleKey);
}
};
const outline_width = {
name: 'width',
generate: function (style, options) {
let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ['outline', 'width'];
let ruleKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'outlineWidth';
return generateRule(style, options, path, ruleKey);
}
};
/* harmony default export */ var outline = ([outline_color, outlineStyle, offset, outline_width]);
;// CONCATENATED MODULE: ./node_modules/@wordpress/style-engine/build-module/styles/spacing/padding.js
/**
* Internal dependencies
*/
const padding = {
name: 'padding',
generate: (style, options) => {
return generateBoxRules(style, options, ['spacing', 'padding'], {
default: 'padding',
individual: 'padding%s'
});
}
};
/* harmony default export */ var spacing_padding = (padding);
;// CONCATENATED MODULE: ./node_modules/@wordpress/style-engine/build-module/styles/spacing/margin.js
/**
* Internal dependencies
*/
const margin = {
name: 'margin',
generate: (style, options) => {
return generateBoxRules(style, options, ['spacing', 'margin'], {
default: 'margin',
individual: 'margin%s'
});
}
};
/* harmony default export */ var spacing_margin = (margin);
;// CONCATENATED MODULE: ./node_modules/@wordpress/style-engine/build-module/styles/spacing/index.js
/**
* Internal dependencies
*/
/* harmony default export */ var spacing = ([spacing_margin, spacing_padding]);
;// CONCATENATED MODULE: ./node_modules/@wordpress/style-engine/build-module/styles/typography/index.js
/**
* Internal dependencies
*/
const fontSize = {
name: 'fontSize',
generate: (style, options) => {
return generateRule(style, options, ['typography', 'fontSize'], 'fontSize');
}
};
const fontStyle = {
name: 'fontStyle',
generate: (style, options) => {
return generateRule(style, options, ['typography', 'fontStyle'], 'fontStyle');
}
};
const fontWeight = {
name: 'fontWeight',
generate: (style, options) => {
return generateRule(style, options, ['typography', 'fontWeight'], 'fontWeight');
}
};
const fontFamily = {
name: 'fontFamily',
generate: (style, options) => {
return generateRule(style, options, ['typography', 'fontFamily'], 'fontFamily');
}
};
const letterSpacing = {
name: 'letterSpacing',
generate: (style, options) => {
return generateRule(style, options, ['typography', 'letterSpacing'], 'letterSpacing');
}
};
const lineHeight = {
name: 'letterSpacing',
generate: (style, options) => {
return generateRule(style, options, ['typography', 'lineHeight'], 'lineHeight');
}
};
const textDecoration = {
name: 'textDecoration',
generate: (style, options) => {
return generateRule(style, options, ['typography', 'textDecoration'], 'textDecoration');
}
};
const textTransform = {
name: 'textTransform',
generate: (style, options) => {
return generateRule(style, options, ['typography', 'textTransform'], 'textTransform');
}
};
/* harmony default export */ var typography = ([fontFamily, fontSize, fontStyle, fontWeight, letterSpacing, lineHeight, textDecoration, textTransform]);
;// CONCATENATED MODULE: ./node_modules/@wordpress/style-engine/build-module/styles/index.js
/**
* Internal dependencies
*/
const styleDefinitions = [...border, ...styles_color, ...outline, ...spacing, ...typography, ...styles_shadow];
;// CONCATENATED MODULE: ./node_modules/@wordpress/style-engine/build-module/index.js
/**
* External dependencies
*/
/**
* Internal dependencies
*/
/**
* Generates a stylesheet for a given style object and selector.
*
* @since 6.1.0 Introduced in WordPress core.
*
* @param style Style object, for example, the value of a block's attributes.style object or the top level styles in theme.json
* @param options Options object with settings to adjust how the styles are generated.
*
* @return A generated stylesheet or inline style declarations.
*/
function compileCSS(style) {
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
const rules = getCSSRules(style, options); // If no selector is provided, treat generated rules as inline styles to be returned as a single string.
if (!(options !== null && options !== void 0 && options.selector)) {
const inlineRules = [];
rules.forEach(rule => {
inlineRules.push(`${(0,external_lodash_namespaceObject.kebabCase)(rule.key)}: ${rule.value};`);
});
return inlineRules.join(' ');
}
const groupedRules = (0,external_lodash_namespaceObject.groupBy)(rules, 'selector');
const selectorRules = Object.keys(groupedRules).reduce((acc, subSelector) => {
acc.push(`${subSelector} { ${groupedRules[subSelector].map(rule => `${(0,external_lodash_namespaceObject.kebabCase)(rule.key)}: ${rule.value};`).join(' ')} }`);
return acc;
}, []);
return selectorRules.join('\n');
}
/**
* Returns a JSON representation of the generated CSS rules.
*
* @since 6.1.0 Introduced in WordPress core.
*
* @param style Style object, for example, the value of a block's attributes.style object or the top level styles in theme.json
* @param options Options object with settings to adjust how the styles are generated.
*
* @return A collection of objects containing the selector, if any, the CSS property key (camelcase) and parsed CSS value.
*/
function getCSSRules(style) {
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
const rules = [];
styleDefinitions.forEach(definition => {
if (typeof definition.generate === 'function') {
rules.push(...definition.generate(style, options));
}
});
return rules;
}
(window.wp = window.wp || {}).styleEngine = __webpack_exports__;
/******/ })()
;