@wordpress/global-styles-engine 1.7.1-next.v.202602271551.0 → 1.8.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/render.cjs +134 -40
- package/build/core/render.cjs.map +2 -2
- package/build-module/core/render.mjs +134 -40
- package/build-module/core/render.mjs.map +2 -2
- package/build-types/core/render.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/core/render.tsx +238 -61
- package/src/test/render.test.ts +123 -0
package/build/core/render.cjs
CHANGED
|
@@ -56,38 +56,6 @@ var BLOCK_SUPPORT_FEATURE_LEVEL_SELECTORS = {
|
|
|
56
56
|
spacing: "spacing",
|
|
57
57
|
typography: "typography"
|
|
58
58
|
};
|
|
59
|
-
function getPresetsDeclarations(blockPresets = {}, mergedSettings) {
|
|
60
|
-
return import_common.PRESET_METADATA.reduce(
|
|
61
|
-
(declarations, { path, valueKey, valueFunc, cssVarInfix }) => {
|
|
62
|
-
const presetByOrigin = (0, import_object.getValueFromObjectPath)(
|
|
63
|
-
blockPresets,
|
|
64
|
-
path,
|
|
65
|
-
[]
|
|
66
|
-
);
|
|
67
|
-
["default", "theme", "custom"].forEach((origin) => {
|
|
68
|
-
if (presetByOrigin[origin]) {
|
|
69
|
-
presetByOrigin[origin].forEach((value) => {
|
|
70
|
-
if (valueKey && !valueFunc) {
|
|
71
|
-
declarations.push(
|
|
72
|
-
`--wp--preset--${cssVarInfix}--${(0, import_string.kebabCase)(
|
|
73
|
-
value.slug
|
|
74
|
-
)}: ${value[valueKey]}`
|
|
75
|
-
);
|
|
76
|
-
} else if (valueFunc && typeof valueFunc === "function") {
|
|
77
|
-
declarations.push(
|
|
78
|
-
`--wp--preset--${cssVarInfix}--${(0, import_string.kebabCase)(
|
|
79
|
-
value.slug
|
|
80
|
-
)}: ${valueFunc(value, mergedSettings)}`
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
return declarations;
|
|
87
|
-
},
|
|
88
|
-
[]
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
59
|
function getPresetsClasses(blockSelector = "*", blockPresets = {}) {
|
|
92
60
|
return import_common.PRESET_METADATA.reduce(
|
|
93
61
|
(declarations, { path, cssVarInfix, classes }) => {
|
|
@@ -193,6 +161,53 @@ var updateParagraphTextIndentSelector = (featureDeclarations, settings, blockNam
|
|
|
193
161
|
}
|
|
194
162
|
return featureDeclarations;
|
|
195
163
|
};
|
|
164
|
+
var updateButtonWidthDeclarations = (featureDeclarations, settings) => {
|
|
165
|
+
const buttonSelector = ".wp-block-button";
|
|
166
|
+
if (!(buttonSelector in featureDeclarations)) {
|
|
167
|
+
return featureDeclarations;
|
|
168
|
+
}
|
|
169
|
+
const updated = { ...featureDeclarations };
|
|
170
|
+
updated[buttonSelector] = updated[buttonSelector].map(
|
|
171
|
+
(declaration) => {
|
|
172
|
+
const match = declaration.match(/^width:\s*(.+)$/);
|
|
173
|
+
if (!match) {
|
|
174
|
+
return declaration;
|
|
175
|
+
}
|
|
176
|
+
const value = match[1];
|
|
177
|
+
let percentage = null;
|
|
178
|
+
if (value.endsWith("%")) {
|
|
179
|
+
percentage = parseFloat(value);
|
|
180
|
+
}
|
|
181
|
+
const presetPrefix = "var(--wp--preset--dimension--";
|
|
182
|
+
if (percentage === null && value.startsWith(presetPrefix) && value.endsWith(")")) {
|
|
183
|
+
const slug = value.slice(presetPrefix.length, -1);
|
|
184
|
+
const dimensionSizes = {
|
|
185
|
+
...settings?.dimensions?.dimensionSizes ?? {},
|
|
186
|
+
...settings?.blocks?.["core/button"]?.dimensions?.dimensionSizes ?? {}
|
|
187
|
+
};
|
|
188
|
+
for (const origin of Object.values(dimensionSizes)) {
|
|
189
|
+
if (!Array.isArray(origin)) {
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
for (const preset of origin) {
|
|
193
|
+
if (preset.slug === slug && typeof preset.size === "string" && preset.size.endsWith("%")) {
|
|
194
|
+
percentage = parseFloat(preset.size);
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (percentage !== null) {
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
if (percentage === null || isNaN(percentage)) {
|
|
204
|
+
return declaration;
|
|
205
|
+
}
|
|
206
|
+
return `width: calc(${percentage} * 1% - (var(--wp--style--block-gap, 0.5em) * (1 - ${percentage} / 100)))`;
|
|
207
|
+
}
|
|
208
|
+
);
|
|
209
|
+
return updated;
|
|
210
|
+
};
|
|
196
211
|
var getFeatureDeclarations = (selectors, styles) => {
|
|
197
212
|
const declarations = {};
|
|
198
213
|
Object.entries(selectors).forEach(([feature, selector]) => {
|
|
@@ -603,26 +618,97 @@ var getNodesWithSettings = (tree, blockSelectors) => {
|
|
|
603
618
|
nodes.push({
|
|
604
619
|
presets: blockPresets,
|
|
605
620
|
custom: blockCustom,
|
|
606
|
-
selector: blockSelectors[blockName]?.selector
|
|
621
|
+
selector: blockSelectors[blockName]?.selector,
|
|
622
|
+
featureSelectors: blockSelectors[blockName]?.featureSelectors
|
|
607
623
|
});
|
|
608
624
|
}
|
|
609
625
|
}
|
|
610
626
|
);
|
|
611
627
|
return nodes;
|
|
612
628
|
};
|
|
629
|
+
function resolveFeatureSelector(featureSelectors, featureKey, fallback) {
|
|
630
|
+
if (!featureSelectors || typeof featureSelectors === "string") {
|
|
631
|
+
return fallback;
|
|
632
|
+
}
|
|
633
|
+
const feature = featureSelectors[featureKey];
|
|
634
|
+
if (typeof feature === "string") {
|
|
635
|
+
return feature;
|
|
636
|
+
}
|
|
637
|
+
if (typeof feature === "object" && feature.root) {
|
|
638
|
+
return feature.root;
|
|
639
|
+
}
|
|
640
|
+
return fallback;
|
|
641
|
+
}
|
|
642
|
+
function getPresetVarDeclarations(presets, mergedSettings, { path, valueKey, valueFunc, cssVarInfix }) {
|
|
643
|
+
const presetByOrigin = (0, import_object.getValueFromObjectPath)(
|
|
644
|
+
presets,
|
|
645
|
+
path,
|
|
646
|
+
[]
|
|
647
|
+
);
|
|
648
|
+
const declarations = [];
|
|
649
|
+
for (const origin of ["default", "theme", "custom"]) {
|
|
650
|
+
if (!presetByOrigin[origin]) {
|
|
651
|
+
continue;
|
|
652
|
+
}
|
|
653
|
+
for (const value of presetByOrigin[origin]) {
|
|
654
|
+
const slug = (0, import_string.kebabCase)(value.slug);
|
|
655
|
+
if (valueKey && !valueFunc) {
|
|
656
|
+
declarations.push(
|
|
657
|
+
`--wp--preset--${cssVarInfix}--${slug}: ${value[valueKey]}`
|
|
658
|
+
);
|
|
659
|
+
} else if (valueFunc && typeof valueFunc === "function") {
|
|
660
|
+
declarations.push(
|
|
661
|
+
`--wp--preset--${cssVarInfix}--${slug}: ${valueFunc(
|
|
662
|
+
value,
|
|
663
|
+
mergedSettings
|
|
664
|
+
)}`
|
|
665
|
+
);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
return declarations;
|
|
670
|
+
}
|
|
613
671
|
var generateCustomProperties = (tree, blockSelectors) => {
|
|
614
|
-
const
|
|
672
|
+
const nodes = getNodesWithSettings(tree, blockSelectors);
|
|
615
673
|
let ruleset = "";
|
|
616
|
-
|
|
617
|
-
const
|
|
674
|
+
for (const { presets, custom, selector, featureSelectors } of nodes) {
|
|
675
|
+
const defaultSelector = selector;
|
|
676
|
+
const varsBySelector = {
|
|
677
|
+
[defaultSelector]: []
|
|
678
|
+
};
|
|
679
|
+
if (tree?.settings) {
|
|
680
|
+
for (const metadata of import_common.PRESET_METADATA) {
|
|
681
|
+
const declarations = getPresetVarDeclarations(
|
|
682
|
+
presets,
|
|
683
|
+
tree.settings,
|
|
684
|
+
metadata
|
|
685
|
+
);
|
|
686
|
+
if (declarations.length === 0) {
|
|
687
|
+
continue;
|
|
688
|
+
}
|
|
689
|
+
const target = resolveFeatureSelector(
|
|
690
|
+
featureSelectors,
|
|
691
|
+
metadata.path[0],
|
|
692
|
+
defaultSelector
|
|
693
|
+
);
|
|
694
|
+
if (!varsBySelector[target]) {
|
|
695
|
+
varsBySelector[target] = [];
|
|
696
|
+
}
|
|
697
|
+
varsBySelector[target].push(...declarations);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
618
700
|
const customProps = flattenTree(custom, "--wp--custom--", "--");
|
|
619
701
|
if (customProps.length > 0) {
|
|
620
|
-
|
|
702
|
+
varsBySelector[defaultSelector].push(...customProps);
|
|
621
703
|
}
|
|
622
|
-
|
|
623
|
-
|
|
704
|
+
for (const [ruleSelector, declarations] of Object.entries(
|
|
705
|
+
varsBySelector
|
|
706
|
+
)) {
|
|
707
|
+
if (declarations.length > 0) {
|
|
708
|
+
ruleset += `${ruleSelector}{${declarations.join(";")};}`;
|
|
709
|
+
}
|
|
624
710
|
}
|
|
625
|
-
}
|
|
711
|
+
}
|
|
626
712
|
return ruleset;
|
|
627
713
|
};
|
|
628
714
|
var transformToStyles = (tree, blockSelectors, hasBlockGapSupport, hasFallbackGapSupport, disableLayoutStyles = false, disableRootPadding = false, styleOptions = {}) => {
|
|
@@ -683,6 +769,10 @@ var transformToStyles = (tree, blockSelectors, hasBlockGapSupport, hasFallbackGa
|
|
|
683
769
|
tree.settings,
|
|
684
770
|
name
|
|
685
771
|
);
|
|
772
|
+
featureDeclarations = updateButtonWidthDeclarations(
|
|
773
|
+
featureDeclarations,
|
|
774
|
+
tree.settings
|
|
775
|
+
);
|
|
686
776
|
Object.entries(featureDeclarations).forEach(
|
|
687
777
|
([cssSelector, declarations]) => {
|
|
688
778
|
if (declarations.length) {
|
|
@@ -748,6 +838,10 @@ var transformToStyles = (tree, blockSelectors, hasBlockGapSupport, hasFallbackGa
|
|
|
748
838
|
tree.settings,
|
|
749
839
|
name
|
|
750
840
|
);
|
|
841
|
+
featureDeclarations = updateButtonWidthDeclarations(
|
|
842
|
+
featureDeclarations,
|
|
843
|
+
tree.settings
|
|
844
|
+
);
|
|
751
845
|
Object.entries(
|
|
752
846
|
featureDeclarations
|
|
753
847
|
).forEach(
|