@wordpress/global-styles-engine 1.12.0 → 1.12.1-next.v.202605131006.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 +260 -222
- package/build/core/render.cjs.map +2 -2
- package/build-module/core/render.mjs +260 -222
- package/build-module/core/render.mjs.map +2 -2
- package/build-types/core/render.d.ts +1 -1
- package/build-types/core/render.d.ts.map +1 -1
- package/build-types/utils/background.d.ts +3 -3
- package/build-types/utils/background.d.ts.map +1 -1
- package/build-types/utils/fluid.d.ts +1 -1
- package/build-types/utils/fluid.d.ts.map +1 -1
- package/build-types/utils/layout.d.ts +13 -13
- package/build-types/utils/layout.d.ts.map +1 -1
- package/build-types/utils/object.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/core/render.tsx +415 -301
- package/src/test/render.test.ts +437 -0
package/src/test/render.test.ts
CHANGED
|
@@ -168,6 +168,7 @@ describe( 'global styles renderer', () => {
|
|
|
168
168
|
},
|
|
169
169
|
},
|
|
170
170
|
selector: ELEMENTS.link,
|
|
171
|
+
elementName: 'link',
|
|
171
172
|
skipSelectorWrapper: true,
|
|
172
173
|
},
|
|
173
174
|
{
|
|
@@ -187,6 +188,7 @@ describe( 'global styles renderer', () => {
|
|
|
187
188
|
},
|
|
188
189
|
},
|
|
189
190
|
selector: '.my-heading1 h1, .my-heading2 h1',
|
|
191
|
+
elementName: 'h1',
|
|
190
192
|
},
|
|
191
193
|
{
|
|
192
194
|
styles: {
|
|
@@ -195,6 +197,7 @@ describe( 'global styles renderer', () => {
|
|
|
195
197
|
},
|
|
196
198
|
},
|
|
197
199
|
selector: '.my-heading1 h2, .my-heading2 h2',
|
|
200
|
+
elementName: 'h2',
|
|
198
201
|
},
|
|
199
202
|
{
|
|
200
203
|
styles: {
|
|
@@ -213,6 +216,7 @@ describe( 'global styles renderer', () => {
|
|
|
213
216
|
},
|
|
214
217
|
selector:
|
|
215
218
|
'.my-heading1 a:where(:not(.wp-element-button)), .my-heading2 a:where(:not(.wp-element-button))',
|
|
219
|
+
elementName: 'link',
|
|
216
220
|
},
|
|
217
221
|
{
|
|
218
222
|
styles: {
|
|
@@ -392,6 +396,15 @@ describe( 'global styles renderer', () => {
|
|
|
392
396
|
} );
|
|
393
397
|
|
|
394
398
|
describe( 'transformToStyles', () => {
|
|
399
|
+
const minimalStyleOptions = {
|
|
400
|
+
blockGap: false,
|
|
401
|
+
blockStyles: true,
|
|
402
|
+
layoutStyles: false,
|
|
403
|
+
marginReset: false,
|
|
404
|
+
presets: false,
|
|
405
|
+
rootPadding: false,
|
|
406
|
+
};
|
|
407
|
+
|
|
395
408
|
it( 'should return a ruleset', () => {
|
|
396
409
|
const tree = {
|
|
397
410
|
settings: {
|
|
@@ -652,6 +665,72 @@ describe( 'global styles renderer', () => {
|
|
|
652
665
|
);
|
|
653
666
|
} );
|
|
654
667
|
|
|
668
|
+
it( 'handles variation inner block states', () => {
|
|
669
|
+
const tree = {
|
|
670
|
+
styles: {
|
|
671
|
+
blocks: {
|
|
672
|
+
'core/group': {
|
|
673
|
+
variations: {
|
|
674
|
+
foo: {
|
|
675
|
+
blocks: {
|
|
676
|
+
'core/button': {
|
|
677
|
+
color: {
|
|
678
|
+
text: 'red',
|
|
679
|
+
},
|
|
680
|
+
':hover': {
|
|
681
|
+
color: {
|
|
682
|
+
text: 'blue',
|
|
683
|
+
},
|
|
684
|
+
},
|
|
685
|
+
mobile: {
|
|
686
|
+
color: {
|
|
687
|
+
text: 'green',
|
|
688
|
+
},
|
|
689
|
+
':hover': {
|
|
690
|
+
color: {
|
|
691
|
+
text: 'yellow',
|
|
692
|
+
},
|
|
693
|
+
},
|
|
694
|
+
},
|
|
695
|
+
},
|
|
696
|
+
},
|
|
697
|
+
},
|
|
698
|
+
},
|
|
699
|
+
},
|
|
700
|
+
},
|
|
701
|
+
},
|
|
702
|
+
} as unknown as GlobalStylesConfig;
|
|
703
|
+
|
|
704
|
+
const blockSelectors = {
|
|
705
|
+
'core/group': {
|
|
706
|
+
selector: '.wp-block-group',
|
|
707
|
+
styleVariationSelectors: {
|
|
708
|
+
foo: '.is-style-foo.wp-block-group',
|
|
709
|
+
},
|
|
710
|
+
},
|
|
711
|
+
'core/button': {
|
|
712
|
+
selector: '.wp-block-button',
|
|
713
|
+
},
|
|
714
|
+
};
|
|
715
|
+
|
|
716
|
+
const result = transformToStyles(
|
|
717
|
+
Object.freeze( tree ),
|
|
718
|
+
blockSelectors,
|
|
719
|
+
false,
|
|
720
|
+
false,
|
|
721
|
+
true,
|
|
722
|
+
true,
|
|
723
|
+
{
|
|
724
|
+
...minimalStyleOptions,
|
|
725
|
+
variationStyles: true,
|
|
726
|
+
}
|
|
727
|
+
);
|
|
728
|
+
|
|
729
|
+
expect( result ).toEqual(
|
|
730
|
+
':root :where(.is-style-foo.wp-block-group .wp-block-button){color: red;}@media (width <= 480px){:root :where(.is-style-foo.wp-block-group .wp-block-button){color: green;}}:root :where(.is-style-foo.wp-block-group .wp-block-button:hover){color: blue;}@media (width <= 480px){:root :where(.is-style-foo.wp-block-group .wp-block-button:hover){color: yellow;}}'
|
|
731
|
+
);
|
|
732
|
+
} );
|
|
733
|
+
|
|
655
734
|
it( 'should handle block pseudo selectors', () => {
|
|
656
735
|
const tree = {
|
|
657
736
|
styles: {
|
|
@@ -698,6 +777,87 @@ describe( 'global styles renderer', () => {
|
|
|
698
777
|
);
|
|
699
778
|
} );
|
|
700
779
|
|
|
780
|
+
it( 'outputs default pseudo styles after responsive base styles', () => {
|
|
781
|
+
const tree = {
|
|
782
|
+
styles: {
|
|
783
|
+
blocks: {
|
|
784
|
+
'core/button': {
|
|
785
|
+
color: {
|
|
786
|
+
text: 'black',
|
|
787
|
+
},
|
|
788
|
+
':hover': {
|
|
789
|
+
color: {
|
|
790
|
+
text: 'blue',
|
|
791
|
+
},
|
|
792
|
+
},
|
|
793
|
+
mobile: {
|
|
794
|
+
color: {
|
|
795
|
+
text: 'red',
|
|
796
|
+
},
|
|
797
|
+
},
|
|
798
|
+
},
|
|
799
|
+
},
|
|
800
|
+
},
|
|
801
|
+
} as unknown as GlobalStylesConfig;
|
|
802
|
+
|
|
803
|
+
const blockSelectors = {
|
|
804
|
+
'core/button': {
|
|
805
|
+
selector: '.wp-block-button',
|
|
806
|
+
},
|
|
807
|
+
};
|
|
808
|
+
|
|
809
|
+
const result = transformToStyles(
|
|
810
|
+
Object.freeze( tree ),
|
|
811
|
+
blockSelectors,
|
|
812
|
+
false,
|
|
813
|
+
false,
|
|
814
|
+
true,
|
|
815
|
+
true,
|
|
816
|
+
minimalStyleOptions
|
|
817
|
+
);
|
|
818
|
+
|
|
819
|
+
expect( result ).toEqual(
|
|
820
|
+
':root :where(.wp-block-button){color: black;}@media (width <= 480px){:root :where(.wp-block-button){color: red;}}:root :where(.wp-block-button:hover){color: blue;}'
|
|
821
|
+
);
|
|
822
|
+
} );
|
|
823
|
+
|
|
824
|
+
it( 'ignores root-level state styles', () => {
|
|
825
|
+
const tree = {
|
|
826
|
+
styles: {
|
|
827
|
+
color: {
|
|
828
|
+
text: 'red',
|
|
829
|
+
},
|
|
830
|
+
':hover': {
|
|
831
|
+
color: {
|
|
832
|
+
text: 'blue',
|
|
833
|
+
},
|
|
834
|
+
},
|
|
835
|
+
mobile: {
|
|
836
|
+
color: {
|
|
837
|
+
text: 'green',
|
|
838
|
+
},
|
|
839
|
+
':hover': {
|
|
840
|
+
color: {
|
|
841
|
+
text: 'yellow',
|
|
842
|
+
},
|
|
843
|
+
},
|
|
844
|
+
},
|
|
845
|
+
},
|
|
846
|
+
} as unknown as GlobalStylesConfig;
|
|
847
|
+
|
|
848
|
+
const result = transformToStyles(
|
|
849
|
+
Object.freeze( tree ),
|
|
850
|
+
{},
|
|
851
|
+
false,
|
|
852
|
+
false,
|
|
853
|
+
true,
|
|
854
|
+
true,
|
|
855
|
+
minimalStyleOptions
|
|
856
|
+
);
|
|
857
|
+
|
|
858
|
+
expect( result ).toEqual( 'body{color: red;}' );
|
|
859
|
+
} );
|
|
860
|
+
|
|
701
861
|
it( 'should handle style variation pseudo selectors', () => {
|
|
702
862
|
const tree = {
|
|
703
863
|
styles: {
|
|
@@ -752,6 +912,283 @@ describe( 'global styles renderer', () => {
|
|
|
752
912
|
);
|
|
753
913
|
} );
|
|
754
914
|
|
|
915
|
+
it( 'outputs variation pseudo styles after variation responsive base styles', () => {
|
|
916
|
+
const tree = {
|
|
917
|
+
styles: {
|
|
918
|
+
blocks: {
|
|
919
|
+
'core/button': {
|
|
920
|
+
variations: {
|
|
921
|
+
foo: {
|
|
922
|
+
color: {
|
|
923
|
+
text: 'green',
|
|
924
|
+
},
|
|
925
|
+
':hover': {
|
|
926
|
+
color: {
|
|
927
|
+
text: 'blue',
|
|
928
|
+
},
|
|
929
|
+
},
|
|
930
|
+
mobile: {
|
|
931
|
+
color: {
|
|
932
|
+
text: 'red',
|
|
933
|
+
},
|
|
934
|
+
':hover': {
|
|
935
|
+
color: {
|
|
936
|
+
text: 'orange',
|
|
937
|
+
},
|
|
938
|
+
},
|
|
939
|
+
},
|
|
940
|
+
},
|
|
941
|
+
},
|
|
942
|
+
},
|
|
943
|
+
},
|
|
944
|
+
},
|
|
945
|
+
} as unknown as GlobalStylesConfig;
|
|
946
|
+
|
|
947
|
+
const blockSelectors = {
|
|
948
|
+
'core/button': {
|
|
949
|
+
selector: '.wp-block-button',
|
|
950
|
+
styleVariationSelectors: {
|
|
951
|
+
foo: '.is-style-foo.wp-block-button',
|
|
952
|
+
},
|
|
953
|
+
},
|
|
954
|
+
};
|
|
955
|
+
|
|
956
|
+
const result = transformToStyles(
|
|
957
|
+
Object.freeze( tree ),
|
|
958
|
+
blockSelectors,
|
|
959
|
+
false,
|
|
960
|
+
false,
|
|
961
|
+
true,
|
|
962
|
+
true,
|
|
963
|
+
{
|
|
964
|
+
...minimalStyleOptions,
|
|
965
|
+
variationStyles: true,
|
|
966
|
+
}
|
|
967
|
+
);
|
|
968
|
+
|
|
969
|
+
expect( result ).toEqual(
|
|
970
|
+
':root :where(.is-style-foo.wp-block-button){color: green;}@media (width <= 480px){:root :where(.is-style-foo.wp-block-button){color: red;}}:root :where(.is-style-foo.wp-block-button:hover){color: blue;}@media (width <= 480px){:root :where(.is-style-foo.wp-block-button:hover){color: orange;}}'
|
|
971
|
+
);
|
|
972
|
+
} );
|
|
973
|
+
|
|
974
|
+
it( 'handles responsive block styles', () => {
|
|
975
|
+
const tree = {
|
|
976
|
+
styles: {
|
|
977
|
+
blocks: {
|
|
978
|
+
'core/button': {
|
|
979
|
+
color: {
|
|
980
|
+
text: 'red',
|
|
981
|
+
},
|
|
982
|
+
mobile: {
|
|
983
|
+
color: {
|
|
984
|
+
text: 'blue',
|
|
985
|
+
},
|
|
986
|
+
},
|
|
987
|
+
},
|
|
988
|
+
},
|
|
989
|
+
},
|
|
990
|
+
} as unknown as GlobalStylesConfig;
|
|
991
|
+
|
|
992
|
+
const blockSelectors = {
|
|
993
|
+
'core/button': {
|
|
994
|
+
selector: '.wp-block-button',
|
|
995
|
+
},
|
|
996
|
+
};
|
|
997
|
+
|
|
998
|
+
const result = transformToStyles(
|
|
999
|
+
Object.freeze( tree ),
|
|
1000
|
+
blockSelectors,
|
|
1001
|
+
false,
|
|
1002
|
+
false,
|
|
1003
|
+
true,
|
|
1004
|
+
true,
|
|
1005
|
+
minimalStyleOptions
|
|
1006
|
+
);
|
|
1007
|
+
|
|
1008
|
+
expect( result ).toEqual(
|
|
1009
|
+
':root :where(.wp-block-button){color: red;}@media (width <= 480px){:root :where(.wp-block-button){color: blue;}}'
|
|
1010
|
+
);
|
|
1011
|
+
} );
|
|
1012
|
+
|
|
1013
|
+
it( 'handles responsive pseudo selector styles', () => {
|
|
1014
|
+
const tree = {
|
|
1015
|
+
styles: {
|
|
1016
|
+
blocks: {
|
|
1017
|
+
'core/button': {
|
|
1018
|
+
':hover': {
|
|
1019
|
+
color: {
|
|
1020
|
+
text: 'blue',
|
|
1021
|
+
},
|
|
1022
|
+
},
|
|
1023
|
+
mobile: {
|
|
1024
|
+
color: {
|
|
1025
|
+
text: 'red',
|
|
1026
|
+
},
|
|
1027
|
+
':hover': {
|
|
1028
|
+
color: {
|
|
1029
|
+
text: 'orange',
|
|
1030
|
+
},
|
|
1031
|
+
},
|
|
1032
|
+
},
|
|
1033
|
+
},
|
|
1034
|
+
},
|
|
1035
|
+
},
|
|
1036
|
+
} as unknown as GlobalStylesConfig;
|
|
1037
|
+
|
|
1038
|
+
const blockSelectors = {
|
|
1039
|
+
'core/button': {
|
|
1040
|
+
selector: '.wp-block-button',
|
|
1041
|
+
},
|
|
1042
|
+
};
|
|
1043
|
+
|
|
1044
|
+
const result = transformToStyles(
|
|
1045
|
+
Object.freeze( tree ),
|
|
1046
|
+
blockSelectors,
|
|
1047
|
+
false,
|
|
1048
|
+
false,
|
|
1049
|
+
true,
|
|
1050
|
+
true,
|
|
1051
|
+
minimalStyleOptions
|
|
1052
|
+
);
|
|
1053
|
+
|
|
1054
|
+
expect( result ).toEqual(
|
|
1055
|
+
'@media (width <= 480px){:root :where(.wp-block-button){color: red;}}:root :where(.wp-block-button:hover){color: blue;}@media (width <= 480px){:root :where(.wp-block-button:hover){color: orange;}}'
|
|
1056
|
+
);
|
|
1057
|
+
} );
|
|
1058
|
+
|
|
1059
|
+
it( 'handles responsive feature selector styles', () => {
|
|
1060
|
+
const tree = {
|
|
1061
|
+
settings: {},
|
|
1062
|
+
styles: {
|
|
1063
|
+
blocks: {
|
|
1064
|
+
'core/button': {
|
|
1065
|
+
dimensions: {
|
|
1066
|
+
width: '25%',
|
|
1067
|
+
},
|
|
1068
|
+
mobile: {
|
|
1069
|
+
dimensions: {
|
|
1070
|
+
width: '50%',
|
|
1071
|
+
},
|
|
1072
|
+
},
|
|
1073
|
+
},
|
|
1074
|
+
},
|
|
1075
|
+
},
|
|
1076
|
+
} as unknown as GlobalStylesConfig;
|
|
1077
|
+
|
|
1078
|
+
const blockSelectors = {
|
|
1079
|
+
'core/button': {
|
|
1080
|
+
selector: '.wp-block-button .wp-block-button__link',
|
|
1081
|
+
featureSelectors: {
|
|
1082
|
+
dimensions: {
|
|
1083
|
+
root: '.wp-block-button',
|
|
1084
|
+
width: '.wp-block-button',
|
|
1085
|
+
},
|
|
1086
|
+
},
|
|
1087
|
+
},
|
|
1088
|
+
};
|
|
1089
|
+
|
|
1090
|
+
const result = transformToStyles(
|
|
1091
|
+
Object.freeze( tree ),
|
|
1092
|
+
blockSelectors,
|
|
1093
|
+
false,
|
|
1094
|
+
false,
|
|
1095
|
+
true,
|
|
1096
|
+
true,
|
|
1097
|
+
minimalStyleOptions
|
|
1098
|
+
);
|
|
1099
|
+
|
|
1100
|
+
expect( result ).toEqual(
|
|
1101
|
+
':root :where(.wp-block-button){width: calc(25 * 1% - (var(--wp--style--block-gap, 0.5em) * (1 - 25 / 100)));}@media (width <= 480px){:root :where(.wp-block-button){width: calc(50 * 1% - (var(--wp--style--block-gap, 0.5em) * (1 - 50 / 100)));}}'
|
|
1102
|
+
);
|
|
1103
|
+
} );
|
|
1104
|
+
|
|
1105
|
+
it( 'handles responsive element styles', () => {
|
|
1106
|
+
const tree = {
|
|
1107
|
+
styles: {
|
|
1108
|
+
elements: {
|
|
1109
|
+
link: {
|
|
1110
|
+
color: {
|
|
1111
|
+
text: 'blue',
|
|
1112
|
+
},
|
|
1113
|
+
mobile: {
|
|
1114
|
+
color: {
|
|
1115
|
+
text: 'red',
|
|
1116
|
+
},
|
|
1117
|
+
':hover': {
|
|
1118
|
+
color: {
|
|
1119
|
+
text: 'orange',
|
|
1120
|
+
},
|
|
1121
|
+
},
|
|
1122
|
+
},
|
|
1123
|
+
},
|
|
1124
|
+
},
|
|
1125
|
+
},
|
|
1126
|
+
} as unknown as GlobalStylesConfig;
|
|
1127
|
+
|
|
1128
|
+
const result = transformToStyles(
|
|
1129
|
+
Object.freeze( tree ),
|
|
1130
|
+
{},
|
|
1131
|
+
false,
|
|
1132
|
+
false,
|
|
1133
|
+
true,
|
|
1134
|
+
true,
|
|
1135
|
+
minimalStyleOptions
|
|
1136
|
+
);
|
|
1137
|
+
|
|
1138
|
+
expect( result ).toEqual(
|
|
1139
|
+
'a:where(:not(.wp-element-button)){color: blue;}@media (width <= 480px){:root :where(a:where(:not(.wp-element-button))){color: red;}}@media (width <= 480px){:root :where(a:where(:not(.wp-element-button)):hover){color: orange;}}'
|
|
1140
|
+
);
|
|
1141
|
+
} );
|
|
1142
|
+
|
|
1143
|
+
it( 'handles responsive style variation styles', () => {
|
|
1144
|
+
const tree = {
|
|
1145
|
+
styles: {
|
|
1146
|
+
blocks: {
|
|
1147
|
+
'core/button': {
|
|
1148
|
+
variations: {
|
|
1149
|
+
foo: {
|
|
1150
|
+
color: {
|
|
1151
|
+
text: 'green',
|
|
1152
|
+
},
|
|
1153
|
+
mobile: {
|
|
1154
|
+
color: {
|
|
1155
|
+
text: 'yellow',
|
|
1156
|
+
},
|
|
1157
|
+
},
|
|
1158
|
+
},
|
|
1159
|
+
},
|
|
1160
|
+
},
|
|
1161
|
+
},
|
|
1162
|
+
},
|
|
1163
|
+
} as unknown as GlobalStylesConfig;
|
|
1164
|
+
|
|
1165
|
+
const blockSelectors = {
|
|
1166
|
+
'core/button': {
|
|
1167
|
+
selector: '.wp-block-button',
|
|
1168
|
+
styleVariationSelectors: {
|
|
1169
|
+
foo: '.is-style-foo.wp-block-button',
|
|
1170
|
+
},
|
|
1171
|
+
},
|
|
1172
|
+
};
|
|
1173
|
+
|
|
1174
|
+
const result = transformToStyles(
|
|
1175
|
+
Object.freeze( tree ),
|
|
1176
|
+
blockSelectors,
|
|
1177
|
+
false,
|
|
1178
|
+
false,
|
|
1179
|
+
true,
|
|
1180
|
+
true,
|
|
1181
|
+
{
|
|
1182
|
+
...minimalStyleOptions,
|
|
1183
|
+
variationStyles: true,
|
|
1184
|
+
}
|
|
1185
|
+
);
|
|
1186
|
+
|
|
1187
|
+
expect( result ).toEqual(
|
|
1188
|
+
':root :where(.is-style-foo.wp-block-button){color: green;}@media (width <= 480px){:root :where(.is-style-foo.wp-block-button){color: yellow;}}'
|
|
1189
|
+
);
|
|
1190
|
+
} );
|
|
1191
|
+
|
|
755
1192
|
it( 'should handle duotone filter', () => {
|
|
756
1193
|
const tree = {
|
|
757
1194
|
styles: {
|