WordPress/wp-includes/js/dist/style-engine.js
davidbaumwald 4de88db482 Editor: Update packages for 6.1 Beta 3.
Package updates for bug and regression fixes:

* @wordpress/annotations: 2.17.3
* @wordpress/block-directory: 3.15.4
* @wordpress/block-editor: 10.0.4
* @wordpress/block-library: 7.14.4
* @wordpress/blocks: 11.16.4
* @wordpress/components: 21.0.4
* @wordpress/core-data: 5.0.4
* @wordpress/customize-widgets: 3.14.4
* @wordpress/data: 7.1.3
* @wordpress/data-controls: 2.17.3
* @wordpress/edit-post: 6.14.4
* @wordpress/edit-site: 4.14.5
* @wordpress/edit-widgets: 4.14.4
* @wordpress/editor: 12.16.4
* @wordpress/format-library: 3.15.4
* @wordpress/interface: 4.16.3
* @wordpress/keyboard-shortcuts: 3.15.3
* @wordpress/list-reusable-blocks: 3.15.4
* @wordpress/notices: 3.17.3
* @wordpress/nux: 5.15.4
* @wordpress/preferences: 2.9.4
* @wordpress/reusable-blocks: 3.15.4
* @wordpress/rich-text: 5.15.3
* @wordpress/server-side-render: 3.15.4
* @wordpress/style-engine: 1.0.3
* @wordpress/viewport: 4.15.3
* @wordpress/widgets: 2.15.4

References:
* [https://github.com/WordPress/gutenberg/pull/44634 Gutenberg PR 44634] – Quote block: stop slash inserter popup showing in citation
* [https://github.com/WordPress/gutenberg/pull/44630 Gutenberg PR 44630] – Query Loop: Fix condition for displaying 'parents' control
* [https://github.com/WordPress/gutenberg/pull/44554 Gutenberg PR 44554] – Hide the Classic block in the Site Editor
* [https://github.com/WordPress/gutenberg/pull/44594 Gutenberg PR 44594] – Fix navigation block console error
* [https://github.com/WordPress/gutenberg/pull/44555 Gutenberg PR 44555] – Theme export: Fix broken spacingScale export
* [https://github.com/WordPress/gutenberg/pull/44580 Gutenberg PR 44580] – Code Block: Add box-sizing to fix inconsistent layout
* [https://github.com/WordPress/gutenberg/pull/44556 Gutenberg PR 44556] – Remove border from Global Styles previews
* [https://github.com/WordPress/gutenberg/pull/44141 Gutenberg PR 44141] – Spacing presets: Modify the styling of the input controls when in unlinked mode in order to better differentiate sides
* [https://github.com/WordPress/gutenberg/pull/44453 Gutenberg PR 44453] – Preserve the generic signature of getEntityRecord and getEntityRecords through currying
* [https://github.com/WordPress/gutenberg/pull/44504 Gutenberg PR 44504] – Theme.json: fix some outline properties doesn't work properly on the editor
* [https://github.com/WordPress/gutenberg/pull/44516 Gutenberg PR 44516] – Add style engine to editor tsconfig references
* [https://github.com/WordPress/gutenberg/pull/44523 Gutenberg PR 44523] – Query Loop Block: Rename Query Loop variations allowControls to allowedControls
* [https://github.com/WordPress/gutenberg/pull/44520 Gutenberg PR 44520] – Post Featured Image: Fix application of default border style in editor
* [https://github.com/WordPress/gutenberg/pull/44286 Gutenberg PR 44286] – Post Featured Image: Fix borders after addition of overlay feature
* [https://github.com/WordPress/gutenberg/pull/44482 Gutenberg PR 44482] – Template Editor: Fix crashes due to undefined variables
* [https://github.com/WordPress/gutenberg/pull/44480 Gutenberg PR 44480] – Template Parts: Prevent adding block in post editor or inside post template or content blocks
* [https://github.com/WordPress/gutenberg/pull/44425 Gutenberg PR 44425] – Fix rotated image crop area aspect ratio
* [https://github.com/WordPress/gutenberg/pull/44485 Gutenberg PR 44485] – Fix padding/margin visualizer accuracy
* [https://github.com/WordPress/gutenberg/pull/44569 Gutenberg PR 44569] – Theme.json: Fix some shadow properties that do not work properly in the site editor
* [https://github.com/WordPress/gutenberg/pull/44575 Gutenberg PR 44575] – ToggleGroupControl: Fix unselected icon color
* [https://github.com/WordPress/gutenberg/pull/44526 Gutenberg PR 44526] – TokenInput Field: Try alternative approach to fix screen reader focus issue
* [https://github.com/WordPress/gutenberg/pull/44506 Gutenberg PR 44506] – Edit Post: Optimize legacy post content layout
* [https://github.com/WordPress/gutenberg/pull/44258 Gutenberg PR 44258] – Add layout styles from Post Content block to post editor

Follow-up to [54257] and [54335].

Props czapla, isabel_brison, wildworks, bernhard-reiter, hellofromTonya.
See #56467.
Built from https://develop.svn.wordpress.org/trunk@54383


git-svn-id: http://core.svn.wordpress.org/trunk@53942 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-10-04 15:06: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] : 'outlineOffset';
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__;
/******/ })()
;