@wordpress/global-styles-engine 1.15.2-next.v.202606191442.0 → 1.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/core/merge.cjs +22 -17
- package/build/core/merge.cjs.map +2 -2
- package/build/core/render.cjs +16 -8
- package/build/core/render.cjs.map +2 -2
- package/build/settings/get-style.cjs +17 -1
- package/build/settings/get-style.cjs.map +2 -2
- package/build/settings/set-style.cjs +2 -1
- package/build/settings/set-style.cjs.map +2 -2
- package/build/style-state-back-compat.cjs +94 -0
- package/build/style-state-back-compat.cjs.map +7 -0
- package/build-module/core/merge.mjs +22 -17
- package/build-module/core/merge.mjs.map +2 -2
- package/build-module/core/render.mjs +16 -8
- package/build-module/core/render.mjs.map +2 -2
- package/build-module/settings/get-style.mjs +17 -1
- package/build-module/settings/get-style.mjs.map +2 -2
- package/build-module/settings/set-style.mjs +2 -1
- package/build-module/settings/set-style.mjs.map +2 -2
- package/build-module/style-state-back-compat.mjs +68 -0
- package/build-module/style-state-back-compat.mjs.map +7 -0
- package/build-types/core/merge.d.ts.map +1 -1
- package/build-types/core/render.d.ts.map +1 -1
- package/build-types/settings/get-style.d.ts.map +1 -1
- package/build-types/settings/set-style.d.ts.map +1 -1
- package/build-types/style-state-back-compat.d.ts +28 -0
- package/build-types/style-state-back-compat.d.ts.map +1 -0
- package/package.json +6 -6
- package/src/core/merge.ts +25 -19
- package/src/core/render.tsx +18 -8
- package/src/settings/get-style.ts +23 -1
- package/src/settings/set-style.ts +2 -1
- package/src/style-state-back-compat.ts +137 -0
- package/src/test/render.test.ts +47 -8
- package/src/test/style-state-back-compat.test.ts +170 -0
|
@@ -25,13 +25,29 @@ __export(get_style_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(get_style_exports);
|
|
26
26
|
var import_object = require("../utils/object.cjs");
|
|
27
27
|
var import_common = require("../utils/common.cjs");
|
|
28
|
+
var import_style_state_back_compat = require("../style-state-back-compat.cjs");
|
|
28
29
|
function getStyle(globalStyles, path, blockName, shouldDecodeEncode = true) {
|
|
29
30
|
const appendedPath = path ? "." + path : "";
|
|
30
31
|
const finalPath = !blockName ? `styles${appendedPath}` : `styles.blocks.${blockName}${appendedPath}`;
|
|
31
32
|
if (!globalStyles) {
|
|
32
33
|
return void 0;
|
|
33
34
|
}
|
|
34
|
-
|
|
35
|
+
let rawResult = (0, import_object.getValueFromObjectPath)(globalStyles, finalPath);
|
|
36
|
+
const legacyPath = (0, import_style_state_back_compat.getLegacyStyleStatePath)(finalPath);
|
|
37
|
+
if (rawResult === void 0 && legacyPath) {
|
|
38
|
+
let hasCanonicalPath = true;
|
|
39
|
+
let currentValue = globalStyles;
|
|
40
|
+
for (const pathPart of finalPath.split(".")) {
|
|
41
|
+
if (!currentValue || typeof currentValue !== "object" || !Object.hasOwn(currentValue, pathPart)) {
|
|
42
|
+
hasCanonicalPath = false;
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
currentValue = currentValue[pathPart];
|
|
46
|
+
}
|
|
47
|
+
if (!hasCanonicalPath) {
|
|
48
|
+
rawResult = (0, import_object.getValueFromObjectPath)(globalStyles, legacyPath);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
35
51
|
const result = shouldDecodeEncode ? (0, import_common.getValueFromVariable)(globalStyles, blockName, rawResult) : rawResult;
|
|
36
52
|
return result;
|
|
37
53
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/settings/get-style.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport { getValueFromObjectPath } from '../utils/object';\nimport { getValueFromVariable } from '../utils/common';\nimport type { GlobalStylesConfig, UnresolvedValue } from '../types';\n\nexport function getStyle< T = any >(\n\tglobalStyles?: GlobalStylesConfig,\n\tpath?: string,\n\tblockName?: string,\n\tshouldDecodeEncode = true\n): T | undefined {\n\tconst appendedPath = path ? '.' + path : '';\n\tconst finalPath = ! blockName\n\t\t? `styles${ appendedPath }`\n\t\t: `styles.blocks.${ blockName }${ appendedPath }`;\n\tif ( ! globalStyles ) {\n\t\treturn undefined;\n\t}\n\n\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAAuC;AACvC,oBAAqC;
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport { getValueFromObjectPath } from '../utils/object';\nimport { getValueFromVariable } from '../utils/common';\nimport type { GlobalStylesConfig, UnresolvedValue } from '../types';\nimport { getLegacyStyleStatePath } from '../style-state-back-compat';\n\nexport function getStyle< T = any >(\n\tglobalStyles?: GlobalStylesConfig,\n\tpath?: string,\n\tblockName?: string,\n\tshouldDecodeEncode = true\n): T | undefined {\n\tconst appendedPath = path ? '.' + path : '';\n\tconst finalPath = ! blockName\n\t\t? `styles${ appendedPath }`\n\t\t: `styles.blocks.${ blockName }${ appendedPath }`;\n\tif ( ! globalStyles ) {\n\t\treturn undefined;\n\t}\n\n\tlet rawResult = getValueFromObjectPath( globalStyles, finalPath ) as\n\t\t| string\n\t\t| UnresolvedValue;\n\tconst legacyPath = getLegacyStyleStatePath( finalPath );\n\tif ( rawResult === undefined && legacyPath ) {\n\t\tlet hasCanonicalPath = true;\n\t\tlet currentValue: any = globalStyles;\n\t\tfor ( const pathPart of finalPath.split( '.' ) ) {\n\t\t\tif (\n\t\t\t\t! currentValue ||\n\t\t\t\ttypeof currentValue !== 'object' ||\n\t\t\t\t! Object.hasOwn( currentValue, pathPart )\n\t\t\t) {\n\t\t\t\thasCanonicalPath = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcurrentValue = currentValue[ pathPart ];\n\t\t}\n\t\tif ( ! hasCanonicalPath ) {\n\t\t\trawResult = getValueFromObjectPath( globalStyles, legacyPath ) as\n\t\t\t\t| string\n\t\t\t\t| UnresolvedValue;\n\t\t}\n\t}\n\tconst result = shouldDecodeEncode\n\t\t? getValueFromVariable( globalStyles, blockName, rawResult )\n\t\t: rawResult;\n\treturn result as T | undefined;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAAuC;AACvC,oBAAqC;AAErC,qCAAwC;AAEjC,SAAS,SACf,cACA,MACA,WACA,qBAAqB,MACL;AAChB,QAAM,eAAe,OAAO,MAAM,OAAO;AACzC,QAAM,YAAY,CAAE,YACjB,SAAU,YAAa,KACvB,iBAAkB,SAAU,GAAI,YAAa;AAChD,MAAK,CAAE,cAAe;AACrB,WAAO;AAAA,EACR;AAEA,MAAI,gBAAY,sCAAwB,cAAc,SAAU;AAGhE,QAAM,iBAAa,wDAAyB,SAAU;AACtD,MAAK,cAAc,UAAa,YAAa;AAC5C,QAAI,mBAAmB;AACvB,QAAI,eAAoB;AACxB,eAAY,YAAY,UAAU,MAAO,GAAI,GAAI;AAChD,UACC,CAAE,gBACF,OAAO,iBAAiB,YACxB,CAAE,OAAO,OAAQ,cAAc,QAAS,GACvC;AACD,2BAAmB;AACnB;AAAA,MACD;AACA,qBAAe,aAAc,QAAS;AAAA,IACvC;AACA,QAAK,CAAE,kBAAmB;AACzB,sBAAY,sCAAwB,cAAc,UAAW;AAAA,IAG9D;AAAA,EACD;AACA,QAAM,SAAS,yBACZ,oCAAsB,cAAc,WAAW,SAAU,IACzD;AACH,SAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -24,11 +24,12 @@ __export(set_style_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(set_style_exports);
|
|
26
26
|
var import_object = require("../utils/object.cjs");
|
|
27
|
+
var import_style_state_back_compat = require("../style-state-back-compat.cjs");
|
|
27
28
|
function setStyle(globalStyles, path, newValue, blockName) {
|
|
28
29
|
const appendedPath = path ? "." + path : "";
|
|
29
30
|
const finalPath = !blockName ? `styles${appendedPath}` : `styles.blocks.${blockName}${appendedPath}`;
|
|
30
31
|
return (0, import_object.setImmutably)(
|
|
31
|
-
globalStyles,
|
|
32
|
+
(0, import_style_state_back_compat.normalizeStyleStateAliases)(globalStyles),
|
|
32
33
|
finalPath.split("."),
|
|
33
34
|
newValue
|
|
34
35
|
);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/settings/set-style.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport { setImmutably } from '../utils/object';\nimport type { GlobalStylesConfig } from '../types';\n\nexport function setStyle< T = any >(\n\tglobalStyles: GlobalStylesConfig,\n\tpath: string,\n\tnewValue: T | undefined,\n\tblockName?: string\n): GlobalStylesConfig {\n\tconst appendedPath = path ? '.' + path : '';\n\tconst finalPath = ! blockName\n\t\t? `styles${ appendedPath }`\n\t\t: `styles.blocks.${ blockName }${ appendedPath }`;\n\n\treturn setImmutably(\n\t\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAA6B;
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport { setImmutably } from '../utils/object';\nimport type { GlobalStylesConfig } from '../types';\nimport { normalizeStyleStateAliases } from '../style-state-back-compat';\n\nexport function setStyle< T = any >(\n\tglobalStyles: GlobalStylesConfig,\n\tpath: string,\n\tnewValue: T | undefined,\n\tblockName?: string\n): GlobalStylesConfig {\n\tconst appendedPath = path ? '.' + path : '';\n\tconst finalPath = ! blockName\n\t\t? `styles${ appendedPath }`\n\t\t: `styles.blocks.${ blockName }${ appendedPath }`;\n\n\treturn setImmutably(\n\t\tnormalizeStyleStateAliases( globalStyles ),\n\t\tfinalPath.split( '.' ),\n\t\tnewValue\n\t) as GlobalStylesConfig;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAA6B;AAE7B,qCAA2C;AAEpC,SAAS,SACf,cACA,MACA,UACA,WACqB;AACrB,QAAM,eAAe,OAAO,MAAM,OAAO;AACzC,QAAM,YAAY,CAAE,YACjB,SAAU,YAAa,KACvB,iBAAkB,SAAU,GAAI,YAAa;AAEhD,aAAO;AAAA,QACN,2DAA4B,YAAa;AAAA,IACzC,UAAU,MAAO,GAAI;AAAA,IACrB;AAAA,EACD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/global-styles-engine/src/style-state-back-compat.ts
|
|
21
|
+
var style_state_back_compat_exports = {};
|
|
22
|
+
__export(style_state_back_compat_exports, {
|
|
23
|
+
getLegacyStyleStatePath: () => getLegacyStyleStatePath,
|
|
24
|
+
normalizeStyleStateAliases: () => normalizeStyleStateAliases
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(style_state_back_compat_exports);
|
|
27
|
+
var LEGACY_STYLE_STATE_ALIASES = {
|
|
28
|
+
"@mobile": "mobile",
|
|
29
|
+
"@tablet": "tablet",
|
|
30
|
+
"-current": "@current"
|
|
31
|
+
};
|
|
32
|
+
function isObjectRecord(value) {
|
|
33
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
34
|
+
}
|
|
35
|
+
function normalizeStyleStateNode(node) {
|
|
36
|
+
if (!isObjectRecord(node)) {
|
|
37
|
+
return node;
|
|
38
|
+
}
|
|
39
|
+
let normalized = node;
|
|
40
|
+
Object.entries(LEGACY_STYLE_STATE_ALIASES).forEach(
|
|
41
|
+
([state, legacyState]) => {
|
|
42
|
+
if (Object.hasOwn(node, legacyState)) {
|
|
43
|
+
if (normalized === node) {
|
|
44
|
+
normalized = { ...node };
|
|
45
|
+
}
|
|
46
|
+
if (!Object.hasOwn(node, state)) {
|
|
47
|
+
normalized[state] = node[legacyState];
|
|
48
|
+
}
|
|
49
|
+
delete normalized[legacyState];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
Object.entries(normalized).forEach(([key, value]) => {
|
|
54
|
+
if (!isObjectRecord(value)) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const normalizedValue = normalizeStyleStateNode(value);
|
|
58
|
+
if (normalizedValue !== value) {
|
|
59
|
+
if (normalized === node) {
|
|
60
|
+
normalized = { ...node };
|
|
61
|
+
}
|
|
62
|
+
normalized[key] = normalizedValue;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
return normalized;
|
|
66
|
+
}
|
|
67
|
+
function normalizeStyleStateAliases(globalStyles) {
|
|
68
|
+
if (!globalThis.IS_GUTENBERG_PLUGIN) {
|
|
69
|
+
return globalStyles;
|
|
70
|
+
}
|
|
71
|
+
if (!globalStyles?.styles) {
|
|
72
|
+
return globalStyles;
|
|
73
|
+
}
|
|
74
|
+
const styles = normalizeStyleStateNode(globalStyles.styles);
|
|
75
|
+
return styles === globalStyles.styles ? globalStyles : { ...globalStyles, styles };
|
|
76
|
+
}
|
|
77
|
+
function getLegacyStyleStatePath(path) {
|
|
78
|
+
if (!globalThis.IS_GUTENBERG_PLUGIN) {
|
|
79
|
+
return void 0;
|
|
80
|
+
}
|
|
81
|
+
const pathParts = path.split(".");
|
|
82
|
+
const legacyPathParts = pathParts.map(
|
|
83
|
+
(part) => LEGACY_STYLE_STATE_ALIASES[part] ?? part
|
|
84
|
+
);
|
|
85
|
+
return legacyPathParts.some(
|
|
86
|
+
(part, index) => part !== pathParts[index]
|
|
87
|
+
) ? legacyPathParts.join(".") : void 0;
|
|
88
|
+
}
|
|
89
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
90
|
+
0 && (module.exports = {
|
|
91
|
+
getLegacyStyleStatePath,
|
|
92
|
+
normalizeStyleStateAliases
|
|
93
|
+
});
|
|
94
|
+
//# sourceMappingURL=style-state-back-compat.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/style-state-back-compat.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { GlobalStylesConfig } from './types';\n\n/**\n * Temporary aliases for persisted style state keys shipped before breakpoint\n * states used the `@` prefix and custom states used the `-` prefix.\n *\n * Gutenberg plugin back compat for data saved before state keys were prefixed.\n * Guarded by `IS_GUTENBERG_PLUGIN` so synced Core package code does not apply it.\n */\nconst LEGACY_STYLE_STATE_ALIASES: Record< string, string > = {\n\t'@mobile': 'mobile',\n\t'@tablet': 'tablet',\n\t'-current': '@current',\n};\n\n/* eslint-disable @wordpress/wp-global-usage */\ndeclare global {\n\tvar IS_GUTENBERG_PLUGIN: boolean | undefined;\n}\n/* eslint-enable @wordpress/wp-global-usage */\n\n/**\n * Returns whether a value is a non-array object.\n *\n * @param value Value to check.\n * @return Whether the value is a non-array object.\n */\nfunction isObjectRecord( value: unknown ): value is Record< string, any > {\n\treturn !! value && typeof value === 'object' && ! Array.isArray( value );\n}\n\n/**\n * Normalizes legacy persisted style state aliases within a style node.\n *\n * For example, `{ mobile: { color: ... } }` becomes\n * `{ '@mobile': { color: ... } }`, and `{ '@current': { color: ... } }`\n * becomes `{ '-current': { color: ... } }`.\n *\n * @param node Style node or nested value.\n * @return Normalized style node or original value.\n */\nfunction normalizeStyleStateNode( node: any ): any {\n\tif ( ! isObjectRecord( node ) ) {\n\t\treturn node;\n\t}\n\n\tlet normalized = node;\n\n\t// Normalize legacy keys at the current style node before walking children.\n\tObject.entries( LEGACY_STYLE_STATE_ALIASES ).forEach(\n\t\t( [ state, legacyState ] ) => {\n\t\t\tif ( Object.hasOwn( node, legacyState ) ) {\n\t\t\t\t// Clone lazily before mutating this node.\n\t\t\t\tif ( normalized === node ) {\n\t\t\t\t\tnormalized = { ...node };\n\t\t\t\t}\n\t\t\t\tif ( ! Object.hasOwn( node, state ) ) {\n\t\t\t\t\tnormalized[ state ] = node[ legacyState ];\n\t\t\t\t}\n\t\t\t\tdelete normalized[ legacyState ];\n\t\t\t}\n\t\t}\n\t);\n\n\t// Recurse into nested style nodes, such as blocks, elements, and variations.\n\tObject.entries( normalized ).forEach( ( [ key, value ] ) => {\n\t\tif ( ! isObjectRecord( value ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst normalizedValue = normalizeStyleStateNode( value );\n\t\tif ( normalizedValue !== value ) {\n\t\t\t// Clone lazily before mutating this node.\n\t\t\tif ( normalized === node ) {\n\t\t\t\tnormalized = { ...node };\n\t\t\t}\n\t\t\tnormalized[ key ] = normalizedValue;\n\t\t}\n\t} );\n\n\treturn normalized;\n}\n\n/**\n * Normalizes legacy persisted style state aliases in a global styles config.\n *\n * For example, `styles.blocks['core/button'].mobile` becomes\n * `styles.blocks['core/button']['@mobile']`.\n *\n * @param globalStyles Global styles config to normalize.\n * @return Global styles config with canonical style state keys.\n */\nexport function normalizeStyleStateAliases(\n\tglobalStyles: GlobalStylesConfig\n): GlobalStylesConfig {\n\tif ( ! globalThis.IS_GUTENBERG_PLUGIN ) {\n\t\treturn globalStyles;\n\t}\n\n\tif ( ! globalStyles?.styles ) {\n\t\treturn globalStyles;\n\t}\n\n\tconst styles = normalizeStyleStateNode( globalStyles.styles );\n\treturn styles === globalStyles.styles\n\t\t? globalStyles\n\t\t: { ...globalStyles, styles };\n}\n\n/**\n * Returns the legacy equivalent of a canonical style state path.\n *\n * For example, `styles.blocks.core/button.@mobile.color.text` maps to\n * `styles.blocks.core/button.mobile.color.text`.\n *\n * @param path Canonical dot-separated object path.\n * @return Legacy path when one differs, otherwise undefined.\n */\nexport function getLegacyStyleStatePath( path: string ): string | undefined {\n\tif ( ! globalThis.IS_GUTENBERG_PLUGIN ) {\n\t\treturn undefined;\n\t}\n\n\tconst pathParts = path.split( '.' );\n\tconst legacyPathParts = pathParts.map(\n\t\t( part ) => LEGACY_STYLE_STATE_ALIASES[ part ] ?? part\n\t);\n\n\treturn legacyPathParts.some(\n\t\t( part, index ) => part !== pathParts[ index ]\n\t)\n\t\t? legacyPathParts.join( '.' )\n\t\t: undefined;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYA,IAAM,6BAAuD;AAAA,EAC5D,WAAW;AAAA,EACX,WAAW;AAAA,EACX,YAAY;AACb;AAcA,SAAS,eAAgB,OAAiD;AACzE,SAAO,CAAC,CAAE,SAAS,OAAO,UAAU,YAAY,CAAE,MAAM,QAAS,KAAM;AACxE;AAYA,SAAS,wBAAyB,MAAiB;AAClD,MAAK,CAAE,eAAgB,IAAK,GAAI;AAC/B,WAAO;AAAA,EACR;AAEA,MAAI,aAAa;AAGjB,SAAO,QAAS,0BAA2B,EAAE;AAAA,IAC5C,CAAE,CAAE,OAAO,WAAY,MAAO;AAC7B,UAAK,OAAO,OAAQ,MAAM,WAAY,GAAI;AAEzC,YAAK,eAAe,MAAO;AAC1B,uBAAa,EAAE,GAAG,KAAK;AAAA,QACxB;AACA,YAAK,CAAE,OAAO,OAAQ,MAAM,KAAM,GAAI;AACrC,qBAAY,KAAM,IAAI,KAAM,WAAY;AAAA,QACzC;AACA,eAAO,WAAY,WAAY;AAAA,MAChC;AAAA,IACD;AAAA,EACD;AAGA,SAAO,QAAS,UAAW,EAAE,QAAS,CAAE,CAAE,KAAK,KAAM,MAAO;AAC3D,QAAK,CAAE,eAAgB,KAAM,GAAI;AAChC;AAAA,IACD;AAEA,UAAM,kBAAkB,wBAAyB,KAAM;AACvD,QAAK,oBAAoB,OAAQ;AAEhC,UAAK,eAAe,MAAO;AAC1B,qBAAa,EAAE,GAAG,KAAK;AAAA,MACxB;AACA,iBAAY,GAAI,IAAI;AAAA,IACrB;AAAA,EACD,CAAE;AAEF,SAAO;AACR;AAWO,SAAS,2BACf,cACqB;AACrB,MAAK,CAAE,WAAW,qBAAsB;AACvC,WAAO;AAAA,EACR;AAEA,MAAK,CAAE,cAAc,QAAS;AAC7B,WAAO;AAAA,EACR;AAEA,QAAM,SAAS,wBAAyB,aAAa,MAAO;AAC5D,SAAO,WAAW,aAAa,SAC5B,eACA,EAAE,GAAG,cAAc,OAAO;AAC9B;AAWO,SAAS,wBAAyB,MAAmC;AAC3E,MAAK,CAAE,WAAW,qBAAsB;AACvC,WAAO;AAAA,EACR;AAEA,QAAM,YAAY,KAAK,MAAO,GAAI;AAClC,QAAM,kBAAkB,UAAU;AAAA,IACjC,CAAE,SAAU,2BAA4B,IAAK,KAAK;AAAA,EACnD;AAEA,SAAO,gBAAgB;AAAA,IACtB,CAAE,MAAM,UAAW,SAAS,UAAW,KAAM;AAAA,EAC9C,IACG,gBAAgB,KAAM,GAAI,IAC1B;AACJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,26 +1,31 @@
|
|
|
1
1
|
// packages/global-styles-engine/src/core/merge.ts
|
|
2
2
|
import deepmerge from "deepmerge";
|
|
3
3
|
import { isPlainObject } from "is-plain-object";
|
|
4
|
+
import { normalizeStyleStateAliases } from "../style-state-back-compat.mjs";
|
|
4
5
|
function mergeGlobalStyles(base, user) {
|
|
5
|
-
return deepmerge(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
6
|
+
return deepmerge(
|
|
7
|
+
normalizeStyleStateAliases(base),
|
|
8
|
+
normalizeStyleStateAliases(user),
|
|
9
|
+
{
|
|
10
|
+
/*
|
|
11
|
+
* We only pass as arrays the presets,
|
|
12
|
+
* in which case we want the new array of values
|
|
13
|
+
* to override the old array (no merging).
|
|
14
|
+
*/
|
|
15
|
+
isMergeableObject: isPlainObject,
|
|
16
|
+
/*
|
|
17
|
+
* Exceptions to the above rule.
|
|
18
|
+
* Background images should be replaced, not merged,
|
|
19
|
+
* as they themselves are specific object definitions for the style.
|
|
20
|
+
*/
|
|
21
|
+
customMerge: (key) => {
|
|
22
|
+
if (key === "backgroundImage") {
|
|
23
|
+
return (baseConfig, userConfig) => userConfig ?? baseConfig;
|
|
24
|
+
}
|
|
25
|
+
return void 0;
|
|
20
26
|
}
|
|
21
|
-
return void 0;
|
|
22
27
|
}
|
|
23
|
-
|
|
28
|
+
);
|
|
24
29
|
}
|
|
25
30
|
export {
|
|
26
31
|
mergeGlobalStyles
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/core/merge.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport deepmerge from 'deepmerge';\n// @ts-ignore - is-plain-object doesn't have proper types\nimport { isPlainObject } from 'is-plain-object';\n\n/**\n * Internal dependencies\n */\nimport type { GlobalStylesConfig } from '../types';\n\n/**\n * Merges base and user global styles configurations\n *\n * @param base Base global styles (theme + WordPress defaults)\n * @param user User customizations\n * @return Merged global styles configuration\n */\nexport function mergeGlobalStyles(\n\tbase: GlobalStylesConfig,\n\tuser: GlobalStylesConfig\n): GlobalStylesConfig {\n\treturn deepmerge( base
|
|
5
|
-
"mappings": ";AAGA,OAAO,eAAe;AAEtB,SAAS,qBAAqB;
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport deepmerge from 'deepmerge';\n// @ts-ignore - is-plain-object doesn't have proper types\nimport { isPlainObject } from 'is-plain-object';\n\n/**\n * Internal dependencies\n */\nimport type { GlobalStylesConfig } from '../types';\nimport { normalizeStyleStateAliases } from '../style-state-back-compat';\n\n/**\n * Merges base and user global styles configurations\n *\n * @param base Base global styles (theme + WordPress defaults)\n * @param user User customizations\n * @return Merged global styles configuration\n */\nexport function mergeGlobalStyles(\n\tbase: GlobalStylesConfig,\n\tuser: GlobalStylesConfig\n): GlobalStylesConfig {\n\treturn deepmerge(\n\t\tnormalizeStyleStateAliases( base ),\n\t\tnormalizeStyleStateAliases( user ),\n\t\t{\n\t\t\t/*\n\t\t\t * We only pass as arrays the presets,\n\t\t\t * in which case we want the new array of values\n\t\t\t * to override the old array (no merging).\n\t\t\t */\n\t\t\tisMergeableObject: isPlainObject,\n\t\t\t/*\n\t\t\t * Exceptions to the above rule.\n\t\t\t * Background images should be replaced, not merged,\n\t\t\t * as they themselves are specific object definitions for the style.\n\t\t\t */\n\t\t\tcustomMerge: ( key ) => {\n\t\t\t\tif ( key === 'backgroundImage' ) {\n\t\t\t\t\treturn ( baseConfig, userConfig ) =>\n\t\t\t\t\t\tuserConfig ?? baseConfig;\n\t\t\t\t}\n\t\t\t\treturn undefined;\n\t\t\t},\n\t\t}\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,OAAO,eAAe;AAEtB,SAAS,qBAAqB;AAM9B,SAAS,kCAAkC;AASpC,SAAS,kBACf,MACA,MACqB;AACrB,SAAO;AAAA,IACN,2BAA4B,IAAK;AAAA,IACjC,2BAA4B,IAAK;AAAA,IACjC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAMC,mBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAMnB,aAAa,CAAE,QAAS;AACvB,YAAK,QAAQ,mBAAoB;AAChC,iBAAO,CAAE,YAAY,eACpB,cAAc;AAAA,QAChB;AACA,eAAO;AAAA,MACR;AAAA,IACD;AAAA,EACD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -28,6 +28,7 @@ import { setBackgroundStyleDefaults } from "../utils/background.mjs";
|
|
|
28
28
|
import { LAYOUT_DEFINITIONS } from "../utils/layout.mjs";
|
|
29
29
|
import { getValueFromObjectPath, setImmutably } from "../utils/object.mjs";
|
|
30
30
|
import { getSetting } from "../settings/get-setting.mjs";
|
|
31
|
+
import { normalizeStyleStateAliases } from "../style-state-back-compat.mjs";
|
|
31
32
|
var ELEMENT_CLASS_NAMES = {
|
|
32
33
|
button: "wp-element-button",
|
|
33
34
|
caption: "wp-element-caption"
|
|
@@ -64,8 +65,8 @@ var VALID_ELEMENT_PSEUDO_SELECTORS = {
|
|
|
64
65
|
]
|
|
65
66
|
};
|
|
66
67
|
var RESPONSIVE_BREAKPOINTS = {
|
|
67
|
-
mobile: "@media (width <= 480px)",
|
|
68
|
-
tablet: "@media (480px < width <= 782px)"
|
|
68
|
+
"@mobile": "@media (width <= 480px)",
|
|
69
|
+
"@tablet": "@media (480px < width <= 782px)"
|
|
69
70
|
};
|
|
70
71
|
function getPresetsClasses(blockSelector = "*", blockPresets = {}) {
|
|
71
72
|
return PRESET_METADATA.reduce(
|
|
@@ -921,10 +922,17 @@ var transformToStyles = (tree, blockSelectors, hasBlockGapSupport, hasFallbackGa
|
|
|
921
922
|
variationStyles: false,
|
|
922
923
|
...styleOptions
|
|
923
924
|
};
|
|
924
|
-
const
|
|
925
|
-
const
|
|
926
|
-
|
|
927
|
-
|
|
925
|
+
const normalizedTree = normalizeStyleStateAliases(tree);
|
|
926
|
+
const nodesWithStyles = getNodesWithStyles(
|
|
927
|
+
normalizedTree,
|
|
928
|
+
blockSelectors
|
|
929
|
+
);
|
|
930
|
+
const nodesWithSettings = getNodesWithSettings(
|
|
931
|
+
normalizedTree,
|
|
932
|
+
blockSelectors
|
|
933
|
+
);
|
|
934
|
+
const useRootPaddingAlign = normalizedTree?.settings?.useRootPaddingAwareAlignments;
|
|
935
|
+
const { contentSize, wideSize } = normalizedTree?.settings?.layout || {};
|
|
928
936
|
const hasBodyStyles = options.marginReset || options.rootPadding || options.layoutStyles;
|
|
929
937
|
let ruleset = "";
|
|
930
938
|
if (options.presets && (contentSize || wideSize)) {
|
|
@@ -958,7 +966,7 @@ var transformToStyles = (tree, blockSelectors, hasBlockGapSupport, hasFallbackGa
|
|
|
958
966
|
...responsiveNodes.flatMap(getPseudoStyleNodes)
|
|
959
967
|
].forEach((expandedNode) => {
|
|
960
968
|
ruleset += renderStylesNode(expandedNode, {
|
|
961
|
-
tree,
|
|
969
|
+
tree: normalizedTree,
|
|
962
970
|
useRootPaddingAlign,
|
|
963
971
|
disableLayoutStyles,
|
|
964
972
|
hasBlockGapSupport,
|
|
@@ -974,7 +982,7 @@ var transformToStyles = (tree, blockSelectors, hasBlockGapSupport, hasFallbackGa
|
|
|
974
982
|
ruleset = ruleset + ".wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }";
|
|
975
983
|
}
|
|
976
984
|
if (options.blockGap && hasBlockGapSupport) {
|
|
977
|
-
const gapValue = getGapCSSValue(
|
|
985
|
+
const gapValue = getGapCSSValue(normalizedTree?.styles?.spacing?.blockGap) || "0.5em";
|
|
978
986
|
ruleset = ruleset + `:root :where(.wp-site-blocks) > * { margin-block-start: ${gapValue}; margin-block-end: 0; }`;
|
|
979
987
|
ruleset = ruleset + ":root :where(.wp-site-blocks) > :first-child { margin-block-start: 0; }";
|
|
980
988
|
ruleset = ruleset + ":root :where(.wp-site-blocks) > :last-child { margin-block-end: 0; }";
|