@wordpress/global-styles-engine 1.0.1-next.36001005c.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/LICENSE.md +788 -0
- package/README.md +133 -0
- package/build/core/merge.js +61 -0
- package/build/core/merge.js.map +7 -0
- package/build/core/render.js +997 -0
- package/build/core/render.js.map +7 -0
- package/build/core/selectors.js +82 -0
- package/build/core/selectors.js.map +7 -0
- package/build/index.js +77 -0
- package/build/index.js.map +7 -0
- package/build/settings/get-palette.js +163 -0
- package/build/settings/get-palette.js.map +7 -0
- package/build/settings/get-setting.js +112 -0
- package/build/settings/get-setting.js.map +7 -0
- package/build/settings/get-style.js +40 -0
- package/build/settings/get-style.js.map +7 -0
- package/build/settings/set-setting.js +39 -0
- package/build/settings/set-setting.js.map +7 -0
- package/build/settings/set-style.js +38 -0
- package/build/settings/set-style.js.map +7 -0
- package/build/types.js +17 -0
- package/build/types.js.map +7 -0
- package/build/utils/background.js +53 -0
- package/build/utils/background.js.map +7 -0
- package/build/utils/common.js +418 -0
- package/build/utils/common.js.map +7 -0
- package/build/utils/duotone.js +90 -0
- package/build/utils/duotone.js.map +7 -0
- package/build/utils/fluid.js +173 -0
- package/build/utils/fluid.js.map +7 -0
- package/build/utils/gap.js +50 -0
- package/build/utils/gap.js.map +7 -0
- package/build/utils/layout.js +199 -0
- package/build/utils/layout.js.map +7 -0
- package/build/utils/object.js +50 -0
- package/build/utils/object.js.map +7 -0
- package/build/utils/spacing.js +38 -0
- package/build/utils/spacing.js.map +7 -0
- package/build/utils/string.js +31 -0
- package/build/utils/string.js.map +7 -0
- package/build/utils/typography.js +72 -0
- package/build/utils/typography.js.map +7 -0
- package/build-module/core/merge.js +27 -0
- package/build-module/core/merge.js.map +7 -0
- package/build-module/core/render.js +979 -0
- package/build-module/core/render.js.map +7 -0
- package/build-module/core/selectors.js +58 -0
- package/build-module/core/selectors.js.map +7 -0
- package/build-module/index.js +37 -0
- package/build-module/index.js.map +7 -0
- package/build-module/settings/get-palette.js +143 -0
- package/build-module/settings/get-palette.js.map +7 -0
- package/build-module/settings/get-setting.js +88 -0
- package/build-module/settings/get-setting.js.map +7 -0
- package/build-module/settings/get-style.js +16 -0
- package/build-module/settings/get-style.js.map +7 -0
- package/build-module/settings/set-setting.js +15 -0
- package/build-module/settings/set-setting.js.map +7 -0
- package/build-module/settings/set-style.js +14 -0
- package/build-module/settings/set-style.js.map +7 -0
- package/build-module/types.js +1 -0
- package/build-module/types.js.map +7 -0
- package/build-module/utils/background.js +28 -0
- package/build-module/utils/background.js.map +7 -0
- package/build-module/utils/common.js +382 -0
- package/build-module/utils/common.js.map +7 -0
- package/build-module/utils/duotone.js +63 -0
- package/build-module/utils/duotone.js.map +7 -0
- package/build-module/utils/fluid.js +147 -0
- package/build-module/utils/fluid.js.map +7 -0
- package/build-module/utils/gap.js +25 -0
- package/build-module/utils/gap.js.map +7 -0
- package/build-module/utils/layout.js +175 -0
- package/build-module/utils/layout.js.map +7 -0
- package/build-module/utils/object.js +25 -0
- package/build-module/utils/object.js.map +7 -0
- package/build-module/utils/spacing.js +14 -0
- package/build-module/utils/spacing.js.map +7 -0
- package/build-module/utils/string.js +7 -0
- package/build-module/utils/string.js.map +7 -0
- package/build-module/utils/typography.js +50 -0
- package/build-module/utils/typography.js.map +7 -0
- package/build-types/core/merge.d.ts +13 -0
- package/build-types/core/merge.d.ts.map +1 -0
- package/build-types/core/render.d.ts +84 -0
- package/build-types/core/render.d.ts.map +1 -0
- package/build-types/core/selectors.d.ts +19 -0
- package/build-types/core/selectors.d.ts.map +1 -0
- package/build-types/index.d.ts +13 -0
- package/build-types/index.d.ts.map +1 -0
- package/build-types/settings/get-palette.d.ts +13 -0
- package/build-types/settings/get-palette.d.ts.map +1 -0
- package/build-types/settings/get-setting.d.ts +3 -0
- package/build-types/settings/get-setting.d.ts.map +1 -0
- package/build-types/settings/get-style.d.ts +3 -0
- package/build-types/settings/get-style.d.ts.map +1 -0
- package/build-types/settings/set-setting.d.ts +3 -0
- package/build-types/settings/set-setting.d.ts.map +1 -0
- package/build-types/settings/set-style.d.ts +3 -0
- package/build-types/settings/set-style.d.ts.map +1 -0
- package/build-types/types.d.ts +333 -0
- package/build-types/types.d.ts.map +1 -0
- package/build-types/utils/background.d.ts +16 -0
- package/build-types/utils/background.d.ts.map +1 -0
- package/build-types/utils/common.d.ts +169 -0
- package/build-types/utils/common.d.ts.map +1 -0
- package/build-types/utils/duotone.d.ts +40 -0
- package/build-types/utils/duotone.d.ts.map +1 -0
- package/build-types/utils/fluid.d.ts +68 -0
- package/build-types/utils/fluid.d.ts.map +1 -0
- package/build-types/utils/gap.d.ts +27 -0
- package/build-types/utils/gap.d.ts.map +1 -0
- package/build-types/utils/layout.d.ts +156 -0
- package/build-types/utils/layout.d.ts.map +1 -0
- package/build-types/utils/object.d.ts +27 -0
- package/build-types/utils/object.d.ts.map +1 -0
- package/build-types/utils/spacing.d.ts +2 -0
- package/build-types/utils/spacing.d.ts.map +1 -0
- package/build-types/utils/string.d.ts +9 -0
- package/build-types/utils/string.d.ts.map +1 -0
- package/build-types/utils/typography.d.ts +28 -0
- package/build-types/utils/typography.d.ts.map +1 -0
- package/package.json +50 -0
- package/src/core/merge.ts +43 -0
- package/src/core/render.tsx +1696 -0
- package/src/core/selectors.ts +121 -0
- package/src/index.ts +29 -0
- package/src/settings/get-palette.ts +187 -0
- package/src/settings/get-setting.ts +99 -0
- package/src/settings/get-style.ts +29 -0
- package/src/settings/set-setting.ts +22 -0
- package/src/settings/set-style.ts +23 -0
- package/src/test/render.test.ts +792 -0
- package/src/test/typography-utils.test.ts +354 -0
- package/src/test/utils.test.ts +451 -0
- package/src/types.ts +408 -0
- package/src/utils/background.ts +39 -0
- package/src/utils/common.ts +671 -0
- package/src/utils/duotone.ts +95 -0
- package/src/utils/fluid.ts +311 -0
- package/src/utils/gap.ts +56 -0
- package/src/utils/layout.ts +174 -0
- package/src/utils/object.ts +64 -0
- package/src/utils/spacing.ts +13 -0
- package/src/utils/string.ts +15 -0
- package/src/utils/typography.ts +142 -0
- package/tsconfig.json +18 -0
- package/tsconfig.tsbuildinfo +1 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
// =============================================================================
|
|
2
|
+
// CORE PRIMITIVE TYPES
|
|
3
|
+
// =============================================================================
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Value that can be resolved from various sources (direct value, reference, or URL)
|
|
7
|
+
*/
|
|
8
|
+
export type UnresolvedValue =
|
|
9
|
+
| string
|
|
10
|
+
| number
|
|
11
|
+
| { ref: string }
|
|
12
|
+
| { url: string }
|
|
13
|
+
| undefined
|
|
14
|
+
| null;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Origin of a preset (theme, user customizations, or WordPress defaults)
|
|
18
|
+
*/
|
|
19
|
+
export type PresetOrigin = 'theme' | 'custom' | 'default';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Common properties for all preset types
|
|
23
|
+
*/
|
|
24
|
+
export interface BasePreset {
|
|
25
|
+
name: string;
|
|
26
|
+
slug: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// =============================================================================
|
|
30
|
+
// COLOR SYSTEM TYPES
|
|
31
|
+
// =============================================================================
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Color preset definition
|
|
35
|
+
*/
|
|
36
|
+
export interface Color extends BasePreset {
|
|
37
|
+
color: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Gradient preset definition
|
|
42
|
+
*/
|
|
43
|
+
export interface Gradient extends BasePreset {
|
|
44
|
+
gradient: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Duotone filter preset definition
|
|
49
|
+
*/
|
|
50
|
+
export interface Duotone extends BasePreset {
|
|
51
|
+
colors: string[];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Palette collection for a specific origin (theme, custom, default)
|
|
56
|
+
*/
|
|
57
|
+
export interface Palette {
|
|
58
|
+
name: string;
|
|
59
|
+
slug: PresetOrigin;
|
|
60
|
+
colors?: Color[];
|
|
61
|
+
gradients?: Gradient[];
|
|
62
|
+
duotones?: Duotone[];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Multi-origin palette structure used by StyleBook
|
|
67
|
+
*/
|
|
68
|
+
export interface MultiOriginPalettes {
|
|
69
|
+
colors?: Palette[];
|
|
70
|
+
gradients?: Palette[];
|
|
71
|
+
duotones?: Palette[];
|
|
72
|
+
disableCustomColors?: boolean;
|
|
73
|
+
disableCustomGradients?: boolean;
|
|
74
|
+
hasColorsOrGradients?: boolean;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Background style properties
|
|
79
|
+
*/
|
|
80
|
+
export interface BackgroundStyle {
|
|
81
|
+
backgroundColor?: UnresolvedValue;
|
|
82
|
+
backgroundImage?:
|
|
83
|
+
| {
|
|
84
|
+
url: string;
|
|
85
|
+
id?: number;
|
|
86
|
+
}
|
|
87
|
+
| UnresolvedValue;
|
|
88
|
+
backgroundSize?: UnresolvedValue;
|
|
89
|
+
backgroundPosition?: UnresolvedValue;
|
|
90
|
+
backgroundRepeat?: UnresolvedValue;
|
|
91
|
+
backgroundAttachment?: UnresolvedValue;
|
|
92
|
+
backgroundBlendMode?: UnresolvedValue;
|
|
93
|
+
backgroundOpacity?: UnresolvedValue;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// =============================================================================
|
|
97
|
+
// TYPOGRAPHY SYSTEM TYPES
|
|
98
|
+
// =============================================================================
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Fluid typography settings for responsive font sizes
|
|
102
|
+
*/
|
|
103
|
+
export interface FluidTypographyConfig {
|
|
104
|
+
min?: string;
|
|
105
|
+
max?: string;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Typography preset (font size) definition
|
|
110
|
+
*/
|
|
111
|
+
export interface TypographyPreset extends BasePreset {
|
|
112
|
+
size: string | number | null;
|
|
113
|
+
previewFontSize?: string;
|
|
114
|
+
fluid?: boolean | FluidTypographyConfig;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Font size preset definition (alias for TypographyPreset for clarity)
|
|
119
|
+
*/
|
|
120
|
+
export interface FontSizePreset extends TypographyPreset {}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Convenience type alias for font size data
|
|
124
|
+
*/
|
|
125
|
+
export type FontSize = FontSizePreset;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Font face definition as found in theme.json
|
|
129
|
+
*/
|
|
130
|
+
export interface FontFace {
|
|
131
|
+
fontFamily: string;
|
|
132
|
+
fontWeight?: string | number;
|
|
133
|
+
fontStyle?: string;
|
|
134
|
+
fontStretch?: string;
|
|
135
|
+
fontDisplay?: string;
|
|
136
|
+
src?: string | string[];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Font family preset definition as found in theme.json
|
|
141
|
+
*/
|
|
142
|
+
export interface FontFamilyPreset extends BasePreset {
|
|
143
|
+
fontFamily: string;
|
|
144
|
+
fontFace?: FontFace[];
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Global fluid typography settings
|
|
149
|
+
*/
|
|
150
|
+
export interface FluidTypographySettings {
|
|
151
|
+
maxViewportWidth?: string;
|
|
152
|
+
minFontSize?: string;
|
|
153
|
+
minViewportWidth?: string;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Typography settings collection
|
|
158
|
+
*/
|
|
159
|
+
export interface TypographySettings {
|
|
160
|
+
fluid?: boolean | FluidTypographySettings;
|
|
161
|
+
fontSizes?: TypographyPreset[] | Record< string, TypographyPreset[] >;
|
|
162
|
+
fontFamilies?: Record< string, FontFamilyPreset[] >;
|
|
163
|
+
defaultFontSizes?: boolean;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// =============================================================================
|
|
167
|
+
// LAYOUT SYSTEM TYPES
|
|
168
|
+
// =============================================================================
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Layout constraint settings
|
|
172
|
+
*/
|
|
173
|
+
export interface LayoutSettings {
|
|
174
|
+
wideSize?: string;
|
|
175
|
+
contentSize?: string;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Spacing settings
|
|
180
|
+
*/
|
|
181
|
+
export interface SpacingSettings {
|
|
182
|
+
padding?: string | Record< string, string >;
|
|
183
|
+
margin?: string | Record< string, string >;
|
|
184
|
+
blockGap?: string;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// =============================================================================
|
|
188
|
+
// BLOCK SYSTEM TYPES (need to move to the blocks package eventually)
|
|
189
|
+
// =============================================================================
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Block type definition with global styles support
|
|
193
|
+
*/
|
|
194
|
+
export interface BlockType {
|
|
195
|
+
name: string;
|
|
196
|
+
title: string;
|
|
197
|
+
category: string;
|
|
198
|
+
example?: any;
|
|
199
|
+
attributes?: Record< string, unknown >;
|
|
200
|
+
supports?: {
|
|
201
|
+
__experimentalSelector?: string;
|
|
202
|
+
inserter?: boolean;
|
|
203
|
+
spacing?:
|
|
204
|
+
| boolean
|
|
205
|
+
| {
|
|
206
|
+
blockGap?:
|
|
207
|
+
| boolean
|
|
208
|
+
| string[]
|
|
209
|
+
| {
|
|
210
|
+
__experimentalDefault?: string;
|
|
211
|
+
sides: string[];
|
|
212
|
+
};
|
|
213
|
+
};
|
|
214
|
+
[ key: string ]: unknown;
|
|
215
|
+
};
|
|
216
|
+
selectors?: Record< string, string | Record< string, string > >;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Block style variation
|
|
221
|
+
*/
|
|
222
|
+
export interface BlockStyleVariation {
|
|
223
|
+
name: string;
|
|
224
|
+
label: string;
|
|
225
|
+
styles?: Record< string, any >;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// =============================================================================
|
|
229
|
+
// GLOBAL STYLES STRUCTURE TYPES
|
|
230
|
+
// =============================================================================
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Global styles settings node
|
|
234
|
+
*/
|
|
235
|
+
export interface GlobalStylesSettings {
|
|
236
|
+
useRootPaddingAwareAlignments?: boolean;
|
|
237
|
+
typography?: TypographySettings;
|
|
238
|
+
layout?: LayoutSettings;
|
|
239
|
+
spacing?: SpacingSettings;
|
|
240
|
+
color?: {
|
|
241
|
+
palette?:
|
|
242
|
+
| Color[]
|
|
243
|
+
| {
|
|
244
|
+
theme?: Color[];
|
|
245
|
+
custom?: Color[];
|
|
246
|
+
default?: Color[];
|
|
247
|
+
};
|
|
248
|
+
gradients?: {
|
|
249
|
+
theme?: Gradient[];
|
|
250
|
+
custom?: Gradient[];
|
|
251
|
+
default?: Gradient[];
|
|
252
|
+
};
|
|
253
|
+
duotone?: {
|
|
254
|
+
theme?: Duotone[];
|
|
255
|
+
custom?: Duotone[];
|
|
256
|
+
default?: Duotone[];
|
|
257
|
+
};
|
|
258
|
+
link?: boolean;
|
|
259
|
+
custom?: boolean;
|
|
260
|
+
customGradient?: boolean;
|
|
261
|
+
customDuotone?: boolean;
|
|
262
|
+
defaultPalette?: boolean;
|
|
263
|
+
defaultGradients?: boolean;
|
|
264
|
+
defaultDuotone?: boolean;
|
|
265
|
+
};
|
|
266
|
+
custom?: Record<
|
|
267
|
+
string,
|
|
268
|
+
string | number | Record< string, string | number >
|
|
269
|
+
>;
|
|
270
|
+
blocks?: Record< string, Omit< GlobalStylesSettings, 'blocks' > >;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Global styles values node
|
|
275
|
+
*/
|
|
276
|
+
export interface GlobalStylesStyles {
|
|
277
|
+
color?: {
|
|
278
|
+
background?: UnresolvedValue;
|
|
279
|
+
text?: UnresolvedValue;
|
|
280
|
+
};
|
|
281
|
+
typography?: {
|
|
282
|
+
fontFamily?: UnresolvedValue;
|
|
283
|
+
fontSize?: UnresolvedValue;
|
|
284
|
+
fontWeight?: UnresolvedValue;
|
|
285
|
+
lineHeight?: UnresolvedValue;
|
|
286
|
+
letterSpacing?: UnresolvedValue;
|
|
287
|
+
textTransform?: UnresolvedValue;
|
|
288
|
+
};
|
|
289
|
+
spacing?: {
|
|
290
|
+
padding?: UnresolvedValue | Record< string, UnresolvedValue >;
|
|
291
|
+
margin?: UnresolvedValue | Record< string, UnresolvedValue >;
|
|
292
|
+
blockGap?: string;
|
|
293
|
+
};
|
|
294
|
+
background?: BackgroundStyle;
|
|
295
|
+
border?: {
|
|
296
|
+
color?: UnresolvedValue;
|
|
297
|
+
width?: UnresolvedValue;
|
|
298
|
+
style?: UnresolvedValue;
|
|
299
|
+
radius?:
|
|
300
|
+
| UnresolvedValue
|
|
301
|
+
| {
|
|
302
|
+
topLeft?: UnresolvedValue;
|
|
303
|
+
topRight?: UnresolvedValue;
|
|
304
|
+
bottomRight?: UnresolvedValue;
|
|
305
|
+
bottomLeft?: UnresolvedValue;
|
|
306
|
+
};
|
|
307
|
+
top?: {
|
|
308
|
+
color?: UnresolvedValue;
|
|
309
|
+
width?: UnresolvedValue;
|
|
310
|
+
style?: UnresolvedValue;
|
|
311
|
+
};
|
|
312
|
+
right?: {
|
|
313
|
+
color?: UnresolvedValue;
|
|
314
|
+
width?: UnresolvedValue;
|
|
315
|
+
style?: UnresolvedValue;
|
|
316
|
+
};
|
|
317
|
+
bottom?: {
|
|
318
|
+
color?: UnresolvedValue;
|
|
319
|
+
width?: UnresolvedValue;
|
|
320
|
+
style?: UnresolvedValue;
|
|
321
|
+
};
|
|
322
|
+
left?: {
|
|
323
|
+
color?: UnresolvedValue;
|
|
324
|
+
width?: UnresolvedValue;
|
|
325
|
+
style?: UnresolvedValue;
|
|
326
|
+
};
|
|
327
|
+
};
|
|
328
|
+
filter?: {
|
|
329
|
+
duotone?: UnresolvedValue;
|
|
330
|
+
opacity?: UnresolvedValue;
|
|
331
|
+
};
|
|
332
|
+
dimensions?: {
|
|
333
|
+
width?: UnresolvedValue;
|
|
334
|
+
height?: UnresolvedValue;
|
|
335
|
+
minWidth?: UnresolvedValue;
|
|
336
|
+
minHeight?: UnresolvedValue;
|
|
337
|
+
maxWidth?: UnresolvedValue;
|
|
338
|
+
maxHeight?: UnresolvedValue;
|
|
339
|
+
};
|
|
340
|
+
elements?: Record<
|
|
341
|
+
string,
|
|
342
|
+
Omit< GlobalStylesStyles, 'blocks' | 'elements' | 'variations' > & {
|
|
343
|
+
':hover'?: Omit<
|
|
344
|
+
GlobalStylesStyles,
|
|
345
|
+
'blocks' | 'elements' | 'variations'
|
|
346
|
+
>;
|
|
347
|
+
}
|
|
348
|
+
>;
|
|
349
|
+
blocks?: Record< string, Omit< GlobalStylesStyles, 'blocks' > >;
|
|
350
|
+
variations?: Record< string, Omit< GlobalStylesStyles, 'blocks' > >;
|
|
351
|
+
css?: string;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Complete global styles configuration
|
|
356
|
+
*/
|
|
357
|
+
export interface GlobalStylesConfig {
|
|
358
|
+
version?: number;
|
|
359
|
+
settings?: GlobalStylesSettings;
|
|
360
|
+
styles?: GlobalStylesStyles;
|
|
361
|
+
_links?: {
|
|
362
|
+
[ 'wp:theme-file' ]?: ThemeFileLink[];
|
|
363
|
+
[ 'wp:action-edit-css' ]?: Array< { href: string } >;
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Style variation (extends GlobalStylesConfig with metadata)
|
|
369
|
+
*/
|
|
370
|
+
export interface StyleVariation extends GlobalStylesConfig {
|
|
371
|
+
title?: string;
|
|
372
|
+
description?: string;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* WordPress theme file link
|
|
377
|
+
*/
|
|
378
|
+
export interface ThemeFileLink {
|
|
379
|
+
name: string;
|
|
380
|
+
href: string;
|
|
381
|
+
target?: string;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// =============================================================================
|
|
385
|
+
// UTILITY TYPES
|
|
386
|
+
// =============================================================================
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Deep partial type for global styles merging
|
|
390
|
+
*/
|
|
391
|
+
export type DeepPartial< T > = {
|
|
392
|
+
[ P in keyof T ]?: T[ P ] extends object ? DeepPartial< T[ P ] > : T[ P ];
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* CSS selector string
|
|
397
|
+
*/
|
|
398
|
+
export type CSSSelector = string;
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* CSS property value
|
|
402
|
+
*/
|
|
403
|
+
export type CSSValue = string | number | undefined;
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* CSS rules object
|
|
407
|
+
*/
|
|
408
|
+
export type CSSRules = Record< string, CSSValue >;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { BackgroundStyle } from '../types';
|
|
5
|
+
|
|
6
|
+
export const BACKGROUND_BLOCK_DEFAULT_VALUES = {
|
|
7
|
+
backgroundSize: 'cover',
|
|
8
|
+
backgroundPosition: '50% 50%', // used only when backgroundSize is 'contain'.
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export function setBackgroundStyleDefaults( backgroundStyle: BackgroundStyle ) {
|
|
12
|
+
if (
|
|
13
|
+
! backgroundStyle ||
|
|
14
|
+
// @ts-expect-error
|
|
15
|
+
! backgroundStyle?.backgroundImage?.url
|
|
16
|
+
) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let backgroundStylesWithDefaults;
|
|
21
|
+
|
|
22
|
+
// Set block background defaults.
|
|
23
|
+
if ( ! backgroundStyle?.backgroundSize ) {
|
|
24
|
+
backgroundStylesWithDefaults = {
|
|
25
|
+
backgroundSize: BACKGROUND_BLOCK_DEFAULT_VALUES.backgroundSize,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (
|
|
30
|
+
'contain' === backgroundStyle?.backgroundSize &&
|
|
31
|
+
! backgroundStyle?.backgroundPosition
|
|
32
|
+
) {
|
|
33
|
+
backgroundStylesWithDefaults = {
|
|
34
|
+
backgroundPosition:
|
|
35
|
+
BACKGROUND_BLOCK_DEFAULT_VALUES.backgroundPosition,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return backgroundStylesWithDefaults;
|
|
39
|
+
}
|