@wordpress/block-editor 15.6.0 → 15.6.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.
Files changed (101) hide show
  1. package/build/components/background-image-control/index.js +2 -2
  2. package/build/components/background-image-control/index.js.map +2 -2
  3. package/build/components/block-quick-navigation/index.js +1 -0
  4. package/build/components/block-quick-navigation/index.js.map +2 -2
  5. package/build/components/global-styles/border-panel.js +2 -1
  6. package/build/components/global-styles/border-panel.js.map +2 -2
  7. package/build/components/global-styles/color-panel.js +2 -1
  8. package/build/components/global-styles/color-panel.js.map +2 -2
  9. package/build/components/global-styles/dimensions-panel.js +3 -2
  10. package/build/components/global-styles/dimensions-panel.js.map +2 -2
  11. package/build/components/global-styles/filters-panel.js +2 -1
  12. package/build/components/global-styles/filters-panel.js.map +2 -2
  13. package/build/components/global-styles/hooks.js +23 -95
  14. package/build/components/global-styles/hooks.js.map +2 -2
  15. package/build/components/global-styles/index.js +0 -14
  16. package/build/components/global-styles/index.js.map +2 -2
  17. package/build/components/global-styles/typography-panel.js +2 -1
  18. package/build/components/global-styles/typography-panel.js.map +2 -2
  19. package/build/components/global-styles/typography-utils.js +2 -49
  20. package/build/components/global-styles/typography-utils.js.map +2 -2
  21. package/build/components/global-styles/utils.js +0 -377
  22. package/build/components/global-styles/utils.js.map +2 -2
  23. package/build/hooks/block-style-variation.js +6 -10
  24. package/build/hooks/block-style-variation.js.map +2 -2
  25. package/build/hooks/duotone.js +3 -3
  26. package/build/hooks/duotone.js.map +2 -2
  27. package/build/hooks/font-size.js +2 -2
  28. package/build/hooks/font-size.js.map +2 -2
  29. package/build/hooks/use-typography-props.js +2 -2
  30. package/build/hooks/use-typography-props.js.map +2 -2
  31. package/build-module/components/background-image-control/index.js +1 -1
  32. package/build-module/components/background-image-control/index.js.map +2 -2
  33. package/build-module/components/block-quick-navigation/index.js +1 -0
  34. package/build-module/components/block-quick-navigation/index.js.map +2 -2
  35. package/build-module/components/global-styles/border-panel.js +2 -1
  36. package/build-module/components/global-styles/border-panel.js.map +2 -2
  37. package/build-module/components/global-styles/color-panel.js +2 -1
  38. package/build-module/components/global-styles/color-panel.js.map +2 -2
  39. package/build-module/components/global-styles/dimensions-panel.js +2 -1
  40. package/build-module/components/global-styles/dimensions-panel.js.map +2 -2
  41. package/build-module/components/global-styles/filters-panel.js +2 -1
  42. package/build-module/components/global-styles/filters-panel.js.map +2 -2
  43. package/build-module/components/global-styles/hooks.js +27 -95
  44. package/build-module/components/global-styles/hooks.js.map +2 -2
  45. package/build-module/components/global-styles/index.js +0 -14
  46. package/build-module/components/global-styles/index.js.map +2 -2
  47. package/build-module/components/global-styles/typography-panel.js +2 -1
  48. package/build-module/components/global-styles/typography-panel.js.map +2 -2
  49. package/build-module/components/global-styles/typography-utils.js +1 -49
  50. package/build-module/components/global-styles/typography-utils.js.map +2 -2
  51. package/build-module/components/global-styles/utils.js +0 -364
  52. package/build-module/components/global-styles/utils.js.map +2 -2
  53. package/build-module/hooks/block-style-variation.js +4 -12
  54. package/build-module/hooks/block-style-variation.js.map +2 -2
  55. package/build-module/hooks/duotone.js +3 -3
  56. package/build-module/hooks/duotone.js.map +2 -2
  57. package/build-module/hooks/font-size.js +1 -1
  58. package/build-module/hooks/font-size.js.map +2 -2
  59. package/build-module/hooks/use-typography-props.js +1 -1
  60. package/build-module/hooks/use-typography-props.js.map +2 -2
  61. package/build-style/style-rtl.css +10 -6
  62. package/build-style/style.css +10 -6
  63. package/package.json +36 -35
  64. package/src/components/background-image-control/index.js +1 -1
  65. package/src/components/block-card/style.scss +1 -1
  66. package/src/components/block-navigation/style.scss +1 -1
  67. package/src/components/block-quick-navigation/index.js +1 -0
  68. package/src/components/block-quick-navigation/style.scss +5 -0
  69. package/src/components/block-switcher/style.scss +1 -1
  70. package/src/components/color-palette/test/__snapshots__/control.js.snap +1 -1
  71. package/src/components/global-styles/border-panel.js +2 -1
  72. package/src/components/global-styles/color-panel.js +2 -1
  73. package/src/components/global-styles/color-panel.native.js +1 -1
  74. package/src/components/global-styles/dimensions-panel.js +2 -1
  75. package/src/components/global-styles/filters-panel.js +2 -1
  76. package/src/components/global-styles/hooks.js +29 -108
  77. package/src/components/global-styles/index.js +0 -8
  78. package/src/components/global-styles/test/typography-utils.js +0 -806
  79. package/src/components/global-styles/test/utils.js +1 -442
  80. package/src/components/global-styles/typography-panel.js +2 -1
  81. package/src/components/global-styles/typography-utils.js +0 -133
  82. package/src/components/global-styles/utils.js +0 -537
  83. package/src/components/inserter/style.scss +2 -2
  84. package/src/components/multi-selection-inspector/style.scss +1 -1
  85. package/src/hooks/block-style-variation.js +4 -12
  86. package/src/hooks/duotone.js +3 -3
  87. package/src/hooks/font-size.js +1 -1
  88. package/src/hooks/use-typography-props.js +1 -1
  89. package/src/style.scss +1 -0
  90. package/tsconfig.json +1 -0
  91. package/build/components/global-styles/get-block-css-selector.js +0 -78
  92. package/build/components/global-styles/get-block-css-selector.js.map +0 -7
  93. package/build/components/global-styles/use-global-styles-output.js +0 -998
  94. package/build/components/global-styles/use-global-styles-output.js.map +0 -7
  95. package/build-module/components/global-styles/get-block-css-selector.js +0 -54
  96. package/build-module/components/global-styles/get-block-css-selector.js.map +0 -7
  97. package/build-module/components/global-styles/use-global-styles-output.js +0 -979
  98. package/build-module/components/global-styles/use-global-styles-output.js.map +0 -7
  99. package/src/components/global-styles/get-block-css-selector.js +0 -114
  100. package/src/components/global-styles/test/use-global-styles-output.js +0 -1131
  101. package/src/components/global-styles/use-global-styles-output.js +0 -1487
@@ -1,998 +0,0 @@
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
- var use_global_styles_output_exports = {};
20
- __export(use_global_styles_output_exports, {
21
- getBlockSelectors: () => getBlockSelectors,
22
- getLayoutStyles: () => getLayoutStyles,
23
- getNodesWithSettings: () => getNodesWithSettings,
24
- getNodesWithStyles: () => getNodesWithStyles,
25
- getStylesDeclarations: () => getStylesDeclarations,
26
- processCSSNesting: () => processCSSNesting,
27
- toCustomProperties: () => toCustomProperties,
28
- toStyles: () => toStyles,
29
- toSvgFilters: () => toSvgFilters,
30
- useGlobalStylesOutput: () => useGlobalStylesOutput,
31
- useGlobalStylesOutputWithConfig: () => useGlobalStylesOutputWithConfig
32
- });
33
- module.exports = __toCommonJS(use_global_styles_output_exports);
34
- var import_blocks = require("@wordpress/blocks");
35
- var import_data = require("@wordpress/data");
36
- var import_element = require("@wordpress/element");
37
- var import_style_engine = require("@wordpress/style-engine");
38
- var import_components = require("@wordpress/components");
39
- var import_utils = require("./utils");
40
- var import_get_block_css_selector = require("./get-block-css-selector");
41
- var import_typography_utils = require("./typography-utils");
42
- var import_context = require("./context");
43
- var import_hooks = require("./hooks");
44
- var import_utils2 = require("../duotone/utils");
45
- var import_gap = require("../../hooks/gap");
46
- var import_background = require("../../hooks/background");
47
- var import_store = require("../../store");
48
- var import_definitions = require("../../layouts/definitions");
49
- var import_object = require("../../utils/object");
50
- var import_lock_unlock = require("../../lock-unlock");
51
- const ELEMENT_CLASS_NAMES = {
52
- button: "wp-element-button",
53
- caption: "wp-element-caption"
54
- };
55
- const BLOCK_SUPPORT_FEATURE_LEVEL_SELECTORS = {
56
- __experimentalBorder: "border",
57
- color: "color",
58
- spacing: "spacing",
59
- typography: "typography"
60
- };
61
- const { kebabCase } = (0, import_lock_unlock.unlock)(import_components.privateApis);
62
- function getPresetsDeclarations(blockPresets = {}, mergedSettings) {
63
- return import_utils.PRESET_METADATA.reduce(
64
- (declarations, { path, valueKey, valueFunc, cssVarInfix }) => {
65
- const presetByOrigin = (0, import_object.getValueFromObjectPath)(
66
- blockPresets,
67
- path,
68
- []
69
- );
70
- ["default", "theme", "custom"].forEach((origin) => {
71
- if (presetByOrigin[origin]) {
72
- presetByOrigin[origin].forEach((value) => {
73
- if (valueKey && !valueFunc) {
74
- declarations.push(
75
- `--wp--preset--${cssVarInfix}--${kebabCase(
76
- value.slug
77
- )}: ${value[valueKey]}`
78
- );
79
- } else if (valueFunc && typeof valueFunc === "function") {
80
- declarations.push(
81
- `--wp--preset--${cssVarInfix}--${kebabCase(
82
- value.slug
83
- )}: ${valueFunc(value, mergedSettings)}`
84
- );
85
- }
86
- });
87
- }
88
- });
89
- return declarations;
90
- },
91
- []
92
- );
93
- }
94
- function getPresetsClasses(blockSelector = "*", blockPresets = {}) {
95
- return import_utils.PRESET_METADATA.reduce(
96
- (declarations, { path, cssVarInfix, classes }) => {
97
- if (!classes) {
98
- return declarations;
99
- }
100
- const presetByOrigin = (0, import_object.getValueFromObjectPath)(
101
- blockPresets,
102
- path,
103
- []
104
- );
105
- ["default", "theme", "custom"].forEach((origin) => {
106
- if (presetByOrigin[origin]) {
107
- presetByOrigin[origin].forEach(({ slug }) => {
108
- classes.forEach(({ classSuffix, propertyName }) => {
109
- const classSelectorToUse = `.has-${kebabCase(
110
- slug
111
- )}-${classSuffix}`;
112
- const selectorToUse = blockSelector.split(",").map(
113
- (selector) => `${selector}${classSelectorToUse}`
114
- ).join(",");
115
- const value = `var(--wp--preset--${cssVarInfix}--${kebabCase(
116
- slug
117
- )})`;
118
- declarations += `${selectorToUse}{${propertyName}: ${value} !important;}`;
119
- });
120
- });
121
- }
122
- });
123
- return declarations;
124
- },
125
- ""
126
- );
127
- }
128
- function getPresetsSvgFilters(blockPresets = {}) {
129
- return import_utils.PRESET_METADATA.filter(
130
- // Duotone are the only type of filters for now.
131
- (metadata) => metadata.path.at(-1) === "duotone"
132
- ).flatMap((metadata) => {
133
- const presetByOrigin = (0, import_object.getValueFromObjectPath)(
134
- blockPresets,
135
- metadata.path,
136
- {}
137
- );
138
- return ["default", "theme"].filter((origin) => presetByOrigin[origin]).flatMap(
139
- (origin) => presetByOrigin[origin].map(
140
- (preset) => (0, import_utils2.getDuotoneFilter)(
141
- `wp-duotone-${preset.slug}`,
142
- preset.colors
143
- )
144
- )
145
- ).join("");
146
- });
147
- }
148
- function flattenTree(input = {}, prefix, token) {
149
- let result = [];
150
- Object.keys(input).forEach((key) => {
151
- const newKey = prefix + kebabCase(key.replace("/", "-"));
152
- const newLeaf = input[key];
153
- if (newLeaf instanceof Object) {
154
- const newPrefix = newKey + token;
155
- result = [...result, ...flattenTree(newLeaf, newPrefix, token)];
156
- } else {
157
- result.push(`${newKey}: ${newLeaf}`);
158
- }
159
- });
160
- return result;
161
- }
162
- function concatFeatureVariationSelectorString(featureSelector, styleVariationSelector) {
163
- const featureSelectors = featureSelector.split(",");
164
- const combinedSelectors = [];
165
- featureSelectors.forEach((selector) => {
166
- combinedSelectors.push(
167
- `${styleVariationSelector.trim()}${selector.trim()}`
168
- );
169
- });
170
- return combinedSelectors.join(", ");
171
- }
172
- const getFeatureDeclarations = (selectors, styles) => {
173
- const declarations = {};
174
- Object.entries(selectors).forEach(([feature, selector]) => {
175
- if (feature === "root" || !styles?.[feature]) {
176
- return;
177
- }
178
- const isShorthand = typeof selector === "string";
179
- if (!isShorthand) {
180
- Object.entries(selector).forEach(
181
- ([subfeature, subfeatureSelector]) => {
182
- if (subfeature === "root" || !styles?.[feature][subfeature]) {
183
- return;
184
- }
185
- const subfeatureStyles = {
186
- [feature]: {
187
- [subfeature]: styles[feature][subfeature]
188
- }
189
- };
190
- const newDeclarations = getStylesDeclarations(subfeatureStyles);
191
- declarations[subfeatureSelector] = [
192
- ...declarations[subfeatureSelector] || [],
193
- ...newDeclarations
194
- ];
195
- delete styles[feature][subfeature];
196
- }
197
- );
198
- }
199
- if (isShorthand || selector.root) {
200
- const featureSelector = isShorthand ? selector : selector.root;
201
- const featureStyles = { [feature]: styles[feature] };
202
- const newDeclarations = getStylesDeclarations(featureStyles);
203
- declarations[featureSelector] = [
204
- ...declarations[featureSelector] || [],
205
- ...newDeclarations
206
- ];
207
- delete styles[feature];
208
- }
209
- });
210
- return declarations;
211
- };
212
- function getStylesDeclarations(blockStyles = {}, selector = "", useRootPaddingAlign, tree = {}, disableRootPadding = false) {
213
- const isRoot = import_utils.ROOT_BLOCK_SELECTOR === selector;
214
- const output = Object.entries(import_blocks.__EXPERIMENTAL_STYLE_PROPERTY).reduce(
215
- (declarations, [key, { value, properties, useEngine, rootOnly }]) => {
216
- if (rootOnly && !isRoot) {
217
- return declarations;
218
- }
219
- const pathToValue = value;
220
- if (pathToValue[0] === "elements" || useEngine) {
221
- return declarations;
222
- }
223
- const styleValue = (0, import_object.getValueFromObjectPath)(
224
- blockStyles,
225
- pathToValue
226
- );
227
- if (key === "--wp--style--root--padding" && (typeof styleValue === "string" || !useRootPaddingAlign)) {
228
- return declarations;
229
- }
230
- if (properties && typeof styleValue !== "string") {
231
- Object.entries(properties).forEach((entry) => {
232
- const [name, prop] = entry;
233
- if (!(0, import_object.getValueFromObjectPath)(styleValue, [prop], false)) {
234
- return;
235
- }
236
- const cssProperty = name.startsWith("--") ? name : kebabCase(name);
237
- declarations.push(
238
- `${cssProperty}: ${(0, import_style_engine.getCSSValueFromRawStyle)(
239
- (0, import_object.getValueFromObjectPath)(styleValue, [prop])
240
- )}`
241
- );
242
- });
243
- } else if ((0, import_object.getValueFromObjectPath)(blockStyles, pathToValue, false)) {
244
- const cssProperty = key.startsWith("--") ? key : kebabCase(key);
245
- declarations.push(
246
- `${cssProperty}: ${(0, import_style_engine.getCSSValueFromRawStyle)(
247
- (0, import_object.getValueFromObjectPath)(blockStyles, pathToValue)
248
- )}`
249
- );
250
- }
251
- return declarations;
252
- },
253
- []
254
- );
255
- if (!!blockStyles.background) {
256
- if (blockStyles.background?.backgroundImage) {
257
- blockStyles.background.backgroundImage = (0, import_utils.getResolvedValue)(
258
- blockStyles.background.backgroundImage,
259
- tree
260
- );
261
- }
262
- if (!isRoot && !!blockStyles.background?.backgroundImage?.id) {
263
- blockStyles = {
264
- ...blockStyles,
265
- background: {
266
- ...blockStyles.background,
267
- ...(0, import_background.setBackgroundStyleDefaults)(blockStyles.background)
268
- }
269
- };
270
- }
271
- }
272
- const extraRules = (0, import_style_engine.getCSSRules)(blockStyles);
273
- extraRules.forEach((rule) => {
274
- if (isRoot && (useRootPaddingAlign || disableRootPadding) && rule.key.startsWith("padding")) {
275
- return;
276
- }
277
- const cssProperty = rule.key.startsWith("--") ? rule.key : kebabCase(rule.key);
278
- let ruleValue = (0, import_utils.getResolvedValue)(rule.value, tree, null);
279
- if (cssProperty === "font-size") {
280
- ruleValue = (0, import_typography_utils.getTypographyFontSizeValue)(
281
- { size: ruleValue },
282
- tree?.settings
283
- );
284
- }
285
- if (cssProperty === "aspect-ratio") {
286
- output.push("min-height: unset");
287
- }
288
- output.push(`${cssProperty}: ${ruleValue}`);
289
- });
290
- return output;
291
- }
292
- function getLayoutStyles({
293
- layoutDefinitions = import_definitions.LAYOUT_DEFINITIONS,
294
- style,
295
- selector,
296
- hasBlockGapSupport,
297
- hasFallbackGapSupport,
298
- fallbackGapValue
299
- }) {
300
- let ruleset = "";
301
- let gapValue = hasBlockGapSupport ? (0, import_gap.getGapCSSValue)(style?.spacing?.blockGap) : "";
302
- if (hasFallbackGapSupport) {
303
- if (selector === import_utils.ROOT_BLOCK_SELECTOR) {
304
- gapValue = !gapValue ? "0.5em" : gapValue;
305
- } else if (!hasBlockGapSupport && fallbackGapValue) {
306
- gapValue = fallbackGapValue;
307
- }
308
- }
309
- if (gapValue && layoutDefinitions) {
310
- Object.values(layoutDefinitions).forEach(
311
- ({ className, name, spacingStyles }) => {
312
- if (!hasBlockGapSupport && "flex" !== name && "grid" !== name) {
313
- return;
314
- }
315
- if (spacingStyles?.length) {
316
- spacingStyles.forEach((spacingStyle) => {
317
- const declarations = [];
318
- if (spacingStyle.rules) {
319
- Object.entries(spacingStyle.rules).forEach(
320
- ([cssProperty, cssValue]) => {
321
- declarations.push(
322
- `${cssProperty}: ${cssValue ? cssValue : gapValue}`
323
- );
324
- }
325
- );
326
- }
327
- if (declarations.length) {
328
- let combinedSelector = "";
329
- if (!hasBlockGapSupport) {
330
- combinedSelector = selector === import_utils.ROOT_BLOCK_SELECTOR ? `:where(.${className}${spacingStyle?.selector || ""})` : `:where(${selector}.${className}${spacingStyle?.selector || ""})`;
331
- } else {
332
- combinedSelector = selector === import_utils.ROOT_BLOCK_SELECTOR ? `:root :where(.${className})${spacingStyle?.selector || ""}` : `:root :where(${selector}-${className})${spacingStyle?.selector || ""}`;
333
- }
334
- ruleset += `${combinedSelector} { ${declarations.join(
335
- "; "
336
- )}; }`;
337
- }
338
- });
339
- }
340
- }
341
- );
342
- if (selector === import_utils.ROOT_BLOCK_SELECTOR && hasBlockGapSupport) {
343
- ruleset += `${import_utils.ROOT_CSS_PROPERTIES_SELECTOR} { --wp--style--block-gap: ${gapValue}; }`;
344
- }
345
- }
346
- if (selector === import_utils.ROOT_BLOCK_SELECTOR && layoutDefinitions) {
347
- const validDisplayModes = ["block", "flex", "grid"];
348
- Object.values(layoutDefinitions).forEach(
349
- ({ className, displayMode, baseStyles }) => {
350
- if (displayMode && validDisplayModes.includes(displayMode)) {
351
- ruleset += `${selector} .${className} { display:${displayMode}; }`;
352
- }
353
- if (baseStyles?.length) {
354
- baseStyles.forEach((baseStyle) => {
355
- const declarations = [];
356
- if (baseStyle.rules) {
357
- Object.entries(baseStyle.rules).forEach(
358
- ([cssProperty, cssValue]) => {
359
- declarations.push(
360
- `${cssProperty}: ${cssValue}`
361
- );
362
- }
363
- );
364
- }
365
- if (declarations.length) {
366
- const combinedSelector = `.${className}${baseStyle?.selector || ""}`;
367
- ruleset += `${combinedSelector} { ${declarations.join(
368
- "; "
369
- )}; }`;
370
- }
371
- });
372
- }
373
- }
374
- );
375
- }
376
- return ruleset;
377
- }
378
- const STYLE_KEYS = [
379
- "border",
380
- "color",
381
- "dimensions",
382
- "spacing",
383
- "typography",
384
- "filter",
385
- "outline",
386
- "shadow",
387
- "background"
388
- ];
389
- function pickStyleKeys(treeToPickFrom) {
390
- if (!treeToPickFrom) {
391
- return {};
392
- }
393
- const entries = Object.entries(treeToPickFrom);
394
- const pickedEntries = entries.filter(
395
- ([key]) => STYLE_KEYS.includes(key)
396
- );
397
- const clonedEntries = pickedEntries.map(([key, style]) => [
398
- key,
399
- JSON.parse(JSON.stringify(style))
400
- ]);
401
- return Object.fromEntries(clonedEntries);
402
- }
403
- const getNodesWithStyles = (tree, blockSelectors) => {
404
- const nodes = [];
405
- if (!tree?.styles) {
406
- return nodes;
407
- }
408
- const styles = pickStyleKeys(tree.styles);
409
- if (styles) {
410
- nodes.push({
411
- styles,
412
- selector: import_utils.ROOT_BLOCK_SELECTOR,
413
- // Root selector (body) styles should not be wrapped in `:root where()` to keep
414
- // specificity at (0,0,1) and maintain backwards compatibility.
415
- skipSelectorWrapper: true
416
- });
417
- }
418
- Object.entries(import_blocks.__EXPERIMENTAL_ELEMENTS).forEach(([name, selector]) => {
419
- if (tree.styles?.elements?.[name]) {
420
- nodes.push({
421
- styles: tree.styles?.elements?.[name],
422
- selector,
423
- // Top level elements that don't use a class name should not receive the
424
- // `:root :where()` wrapper to maintain backwards compatibility.
425
- skipSelectorWrapper: !ELEMENT_CLASS_NAMES[name]
426
- });
427
- }
428
- });
429
- Object.entries(tree.styles?.blocks ?? {}).forEach(
430
- ([blockName, node]) => {
431
- const blockStyles = pickStyleKeys(node);
432
- if (node?.variations) {
433
- const variations = {};
434
- Object.entries(node.variations).forEach(
435
- ([variationName, variation]) => {
436
- variations[variationName] = pickStyleKeys(variation);
437
- if (variation?.css) {
438
- variations[variationName].css = variation.css;
439
- }
440
- const variationSelector = blockSelectors[blockName]?.styleVariationSelectors?.[variationName];
441
- Object.entries(variation?.elements ?? {}).forEach(
442
- ([element, elementStyles]) => {
443
- if (elementStyles && import_blocks.__EXPERIMENTAL_ELEMENTS[element]) {
444
- nodes.push({
445
- styles: elementStyles,
446
- selector: (0, import_utils.scopeSelector)(
447
- variationSelector,
448
- import_blocks.__EXPERIMENTAL_ELEMENTS[element]
449
- )
450
- });
451
- }
452
- }
453
- );
454
- Object.entries(variation?.blocks ?? {}).forEach(
455
- ([
456
- variationBlockName,
457
- variationBlockStyles
458
- ]) => {
459
- const variationBlockSelector = (0, import_utils.scopeSelector)(
460
- variationSelector,
461
- blockSelectors[variationBlockName]?.selector
462
- );
463
- const variationDuotoneSelector = (0, import_utils.scopeSelector)(
464
- variationSelector,
465
- blockSelectors[variationBlockName]?.duotoneSelector
466
- );
467
- const variationFeatureSelectors = (0, import_utils.scopeFeatureSelectors)(
468
- variationSelector,
469
- blockSelectors[variationBlockName]?.featureSelectors
470
- );
471
- const variationBlockStyleNodes = pickStyleKeys(variationBlockStyles);
472
- if (variationBlockStyles?.css) {
473
- variationBlockStyleNodes.css = variationBlockStyles.css;
474
- }
475
- nodes.push({
476
- selector: variationBlockSelector,
477
- duotoneSelector: variationDuotoneSelector,
478
- featureSelectors: variationFeatureSelectors,
479
- fallbackGapValue: blockSelectors[variationBlockName]?.fallbackGapValue,
480
- hasLayoutSupport: blockSelectors[variationBlockName]?.hasLayoutSupport,
481
- styles: variationBlockStyleNodes
482
- });
483
- Object.entries(
484
- variationBlockStyles.elements ?? {}
485
- ).forEach(
486
- ([
487
- variationBlockElement,
488
- variationBlockElementStyles
489
- ]) => {
490
- if (variationBlockElementStyles && import_blocks.__EXPERIMENTAL_ELEMENTS[variationBlockElement]) {
491
- nodes.push({
492
- styles: variationBlockElementStyles,
493
- selector: (0, import_utils.scopeSelector)(
494
- variationBlockSelector,
495
- import_blocks.__EXPERIMENTAL_ELEMENTS[variationBlockElement]
496
- )
497
- });
498
- }
499
- }
500
- );
501
- }
502
- );
503
- }
504
- );
505
- blockStyles.variations = variations;
506
- }
507
- if (blockSelectors?.[blockName]?.selector) {
508
- nodes.push({
509
- duotoneSelector: blockSelectors[blockName].duotoneSelector,
510
- fallbackGapValue: blockSelectors[blockName].fallbackGapValue,
511
- hasLayoutSupport: blockSelectors[blockName].hasLayoutSupport,
512
- selector: blockSelectors[blockName].selector,
513
- styles: blockStyles,
514
- featureSelectors: blockSelectors[blockName].featureSelectors,
515
- styleVariationSelectors: blockSelectors[blockName].styleVariationSelectors
516
- });
517
- }
518
- Object.entries(node?.elements ?? {}).forEach(
519
- ([elementName, value]) => {
520
- if (value && blockSelectors?.[blockName] && import_blocks.__EXPERIMENTAL_ELEMENTS[elementName]) {
521
- nodes.push({
522
- styles: value,
523
- selector: blockSelectors[blockName]?.selector.split(",").map((sel) => {
524
- const elementSelectors = import_blocks.__EXPERIMENTAL_ELEMENTS[elementName].split(",");
525
- return elementSelectors.map(
526
- (elementSelector) => sel + " " + elementSelector
527
- );
528
- }).join(",")
529
- });
530
- }
531
- }
532
- );
533
- }
534
- );
535
- return nodes;
536
- };
537
- const getNodesWithSettings = (tree, blockSelectors) => {
538
- const nodes = [];
539
- if (!tree?.settings) {
540
- return nodes;
541
- }
542
- const pickPresets = (treeToPickFrom) => {
543
- let presets2 = {};
544
- import_utils.PRESET_METADATA.forEach(({ path }) => {
545
- const value = (0, import_object.getValueFromObjectPath)(treeToPickFrom, path, false);
546
- if (value !== false) {
547
- presets2 = (0, import_object.setImmutably)(presets2, path, value);
548
- }
549
- });
550
- return presets2;
551
- };
552
- const presets = pickPresets(tree.settings);
553
- const custom = tree.settings?.custom;
554
- if (Object.keys(presets).length > 0 || custom) {
555
- nodes.push({
556
- presets,
557
- custom,
558
- selector: import_utils.ROOT_CSS_PROPERTIES_SELECTOR
559
- });
560
- }
561
- Object.entries(tree.settings?.blocks ?? {}).forEach(
562
- ([blockName, node]) => {
563
- const blockPresets = pickPresets(node);
564
- const blockCustom = node.custom;
565
- if (Object.keys(blockPresets).length > 0 || blockCustom) {
566
- nodes.push({
567
- presets: blockPresets,
568
- custom: blockCustom,
569
- selector: blockSelectors[blockName]?.selector
570
- });
571
- }
572
- }
573
- );
574
- return nodes;
575
- };
576
- const toCustomProperties = (tree, blockSelectors) => {
577
- const settings = getNodesWithSettings(tree, blockSelectors);
578
- let ruleset = "";
579
- settings.forEach(({ presets, custom, selector }) => {
580
- const declarations = getPresetsDeclarations(presets, tree?.settings);
581
- const customProps = flattenTree(custom, "--wp--custom--", "--");
582
- if (customProps.length > 0) {
583
- declarations.push(...customProps);
584
- }
585
- if (declarations.length > 0) {
586
- ruleset += `${selector}{${declarations.join(";")};}`;
587
- }
588
- });
589
- return ruleset;
590
- };
591
- const toStyles = (tree, blockSelectors, hasBlockGapSupport, hasFallbackGapSupport, disableLayoutStyles = false, disableRootPadding = false, styleOptions = void 0) => {
592
- const options = {
593
- blockGap: true,
594
- blockStyles: true,
595
- layoutStyles: true,
596
- marginReset: true,
597
- presets: true,
598
- rootPadding: true,
599
- variationStyles: false,
600
- ...styleOptions
601
- };
602
- const nodesWithStyles = getNodesWithStyles(tree, blockSelectors);
603
- const nodesWithSettings = getNodesWithSettings(tree, blockSelectors);
604
- const useRootPaddingAlign = tree?.settings?.useRootPaddingAwareAlignments;
605
- const { contentSize, wideSize } = tree?.settings?.layout || {};
606
- const hasBodyStyles = options.marginReset || options.rootPadding || options.layoutStyles;
607
- let ruleset = "";
608
- if (options.presets && (contentSize || wideSize)) {
609
- ruleset += `${import_utils.ROOT_CSS_PROPERTIES_SELECTOR} {`;
610
- ruleset = contentSize ? ruleset + ` --wp--style--global--content-size: ${contentSize};` : ruleset;
611
- ruleset = wideSize ? ruleset + ` --wp--style--global--wide-size: ${wideSize};` : ruleset;
612
- ruleset += "}";
613
- }
614
- if (hasBodyStyles) {
615
- ruleset += ":where(body) {margin: 0;";
616
- if (options.rootPadding && useRootPaddingAlign) {
617
- ruleset += `padding-right: 0; padding-left: 0; padding-top: var(--wp--style--root--padding-top); padding-bottom: var(--wp--style--root--padding-bottom) }
618
- .has-global-padding { padding-right: var(--wp--style--root--padding-right); padding-left: var(--wp--style--root--padding-left); }
619
- .has-global-padding > .alignfull { margin-right: calc(var(--wp--style--root--padding-right) * -1); margin-left: calc(var(--wp--style--root--padding-left) * -1); }
620
- .has-global-padding :where(:not(.alignfull.is-layout-flow) > .has-global-padding:not(.wp-block-block, .alignfull)) { padding-right: 0; padding-left: 0; }
621
- .has-global-padding :where(:not(.alignfull.is-layout-flow) > .has-global-padding:not(.wp-block-block, .alignfull)) > .alignfull { margin-left: 0; margin-right: 0;
622
- `;
623
- }
624
- ruleset += "}";
625
- }
626
- if (options.blockStyles) {
627
- nodesWithStyles.forEach(
628
- ({
629
- selector,
630
- duotoneSelector,
631
- styles,
632
- fallbackGapValue,
633
- hasLayoutSupport,
634
- featureSelectors,
635
- styleVariationSelectors,
636
- skipSelectorWrapper
637
- }) => {
638
- if (featureSelectors) {
639
- const featureDeclarations = getFeatureDeclarations(
640
- featureSelectors,
641
- styles
642
- );
643
- Object.entries(featureDeclarations).forEach(
644
- ([cssSelector, declarations]) => {
645
- if (declarations.length) {
646
- const rules = declarations.join(";");
647
- ruleset += `:root :where(${cssSelector}){${rules};}`;
648
- }
649
- }
650
- );
651
- }
652
- if (duotoneSelector) {
653
- const duotoneStyles = {};
654
- if (styles?.filter) {
655
- duotoneStyles.filter = styles.filter;
656
- delete styles.filter;
657
- }
658
- const duotoneDeclarations = getStylesDeclarations(duotoneStyles);
659
- if (duotoneDeclarations.length) {
660
- ruleset += `${duotoneSelector}{${duotoneDeclarations.join(
661
- ";"
662
- )};}`;
663
- }
664
- }
665
- if (!disableLayoutStyles && (import_utils.ROOT_BLOCK_SELECTOR === selector || hasLayoutSupport)) {
666
- ruleset += getLayoutStyles({
667
- style: styles,
668
- selector,
669
- hasBlockGapSupport,
670
- hasFallbackGapSupport,
671
- fallbackGapValue
672
- });
673
- }
674
- const styleDeclarations = getStylesDeclarations(
675
- styles,
676
- selector,
677
- useRootPaddingAlign,
678
- tree,
679
- disableRootPadding
680
- );
681
- if (styleDeclarations?.length) {
682
- const generalSelector = skipSelectorWrapper ? selector : `:root :where(${selector})`;
683
- ruleset += `${generalSelector}{${styleDeclarations.join(
684
- ";"
685
- )};}`;
686
- }
687
- if (styles?.css) {
688
- ruleset += processCSSNesting(
689
- styles.css,
690
- `:root :where(${selector})`
691
- );
692
- }
693
- if (options.variationStyles && styleVariationSelectors) {
694
- Object.entries(styleVariationSelectors).forEach(
695
- ([styleVariationName, styleVariationSelector]) => {
696
- const styleVariations = styles?.variations?.[styleVariationName];
697
- if (styleVariations) {
698
- if (featureSelectors) {
699
- const featureDeclarations = getFeatureDeclarations(
700
- featureSelectors,
701
- styleVariations
702
- );
703
- Object.entries(
704
- featureDeclarations
705
- ).forEach(
706
- ([baseSelector, declarations]) => {
707
- if (declarations.length) {
708
- const cssSelector = concatFeatureVariationSelectorString(
709
- baseSelector,
710
- styleVariationSelector
711
- );
712
- const rules = declarations.join(";");
713
- ruleset += `:root :where(${cssSelector}){${rules};}`;
714
- }
715
- }
716
- );
717
- }
718
- const styleVariationDeclarations = getStylesDeclarations(
719
- styleVariations,
720
- styleVariationSelector,
721
- useRootPaddingAlign,
722
- tree
723
- );
724
- if (styleVariationDeclarations.length) {
725
- ruleset += `:root :where(${styleVariationSelector}){${styleVariationDeclarations.join(
726
- ";"
727
- )};}`;
728
- }
729
- if (styleVariations?.css) {
730
- ruleset += processCSSNesting(
731
- styleVariations.css,
732
- `:root :where(${styleVariationSelector})`
733
- );
734
- }
735
- }
736
- }
737
- );
738
- }
739
- const pseudoSelectorStyles = Object.entries(styles).filter(
740
- ([key]) => key.startsWith(":")
741
- );
742
- if (pseudoSelectorStyles?.length) {
743
- pseudoSelectorStyles.forEach(
744
- ([pseudoKey, pseudoStyle]) => {
745
- const pseudoDeclarations = getStylesDeclarations(pseudoStyle);
746
- if (!pseudoDeclarations?.length) {
747
- return;
748
- }
749
- const _selector = selector.split(",").map((sel) => sel + pseudoKey).join(",");
750
- const pseudoRule = `:root :where(${_selector}){${pseudoDeclarations.join(
751
- ";"
752
- )};}`;
753
- ruleset += pseudoRule;
754
- }
755
- );
756
- }
757
- }
758
- );
759
- }
760
- if (options.layoutStyles) {
761
- ruleset = ruleset + ".wp-site-blocks > .alignleft { float: left; margin-right: 2em; }";
762
- ruleset = ruleset + ".wp-site-blocks > .alignright { float: right; margin-left: 2em; }";
763
- ruleset = ruleset + ".wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }";
764
- }
765
- if (options.blockGap && hasBlockGapSupport) {
766
- const gapValue = (0, import_gap.getGapCSSValue)(tree?.styles?.spacing?.blockGap) || "0.5em";
767
- ruleset = ruleset + `:root :where(.wp-site-blocks) > * { margin-block-start: ${gapValue}; margin-block-end: 0; }`;
768
- ruleset = ruleset + ":root :where(.wp-site-blocks) > :first-child { margin-block-start: 0; }";
769
- ruleset = ruleset + ":root :where(.wp-site-blocks) > :last-child { margin-block-end: 0; }";
770
- }
771
- if (options.presets) {
772
- nodesWithSettings.forEach(({ selector, presets }) => {
773
- if (import_utils.ROOT_BLOCK_SELECTOR === selector || import_utils.ROOT_CSS_PROPERTIES_SELECTOR === selector) {
774
- selector = "";
775
- }
776
- const classes = getPresetsClasses(selector, presets);
777
- if (classes.length > 0) {
778
- ruleset += classes;
779
- }
780
- });
781
- }
782
- return ruleset;
783
- };
784
- function toSvgFilters(tree, blockSelectors) {
785
- const nodesWithSettings = getNodesWithSettings(tree, blockSelectors);
786
- return nodesWithSettings.flatMap(({ presets }) => {
787
- return getPresetsSvgFilters(presets);
788
- });
789
- }
790
- const getSelectorsConfig = (blockType, rootSelector) => {
791
- if (blockType?.selectors && Object.keys(blockType.selectors).length > 0) {
792
- return blockType.selectors;
793
- }
794
- const config = { root: rootSelector };
795
- Object.entries(BLOCK_SUPPORT_FEATURE_LEVEL_SELECTORS).forEach(
796
- ([featureKey, featureName]) => {
797
- const featureSelector = (0, import_get_block_css_selector.getBlockCSSSelector)(
798
- blockType,
799
- featureKey
800
- );
801
- if (featureSelector) {
802
- config[featureName] = featureSelector;
803
- }
804
- }
805
- );
806
- return config;
807
- };
808
- const getBlockSelectors = (blockTypes, getBlockStyles, variationInstanceId) => {
809
- const result = {};
810
- blockTypes.forEach((blockType) => {
811
- const name = blockType.name;
812
- const selector = (0, import_get_block_css_selector.getBlockCSSSelector)(blockType);
813
- let duotoneSelector = (0, import_get_block_css_selector.getBlockCSSSelector)(
814
- blockType,
815
- "filter.duotone"
816
- );
817
- if (!duotoneSelector) {
818
- const rootSelector = (0, import_get_block_css_selector.getBlockCSSSelector)(blockType);
819
- const duotoneSupport = (0, import_blocks.getBlockSupport)(
820
- blockType,
821
- "color.__experimentalDuotone",
822
- false
823
- );
824
- duotoneSelector = duotoneSupport && (0, import_utils.scopeSelector)(rootSelector, duotoneSupport);
825
- }
826
- const hasLayoutSupport = !!blockType?.supports?.layout || !!blockType?.supports?.__experimentalLayout;
827
- const fallbackGapValue = blockType?.supports?.spacing?.blockGap?.__experimentalDefault;
828
- const blockStyleVariations = getBlockStyles(name);
829
- const styleVariationSelectors = {};
830
- blockStyleVariations?.forEach((variation) => {
831
- const variationSuffix = variationInstanceId ? `-${variationInstanceId}` : "";
832
- const variationName = `${variation.name}${variationSuffix}`;
833
- const styleVariationSelector = (0, import_utils.getBlockStyleVariationSelector)(
834
- variationName,
835
- selector
836
- );
837
- styleVariationSelectors[variationName] = styleVariationSelector;
838
- });
839
- const featureSelectors = getSelectorsConfig(blockType, selector);
840
- result[name] = {
841
- duotoneSelector,
842
- fallbackGapValue,
843
- featureSelectors: Object.keys(featureSelectors).length ? featureSelectors : void 0,
844
- hasLayoutSupport,
845
- name,
846
- selector,
847
- styleVariationSelectors: blockStyleVariations?.length ? styleVariationSelectors : void 0
848
- };
849
- });
850
- return result;
851
- };
852
- function updateConfigWithSeparator(config) {
853
- const needsSeparatorStyleUpdate = config.styles?.blocks?.["core/separator"] && config.styles?.blocks?.["core/separator"].color?.background && !config.styles?.blocks?.["core/separator"].color?.text && !config.styles?.blocks?.["core/separator"].border?.color;
854
- if (needsSeparatorStyleUpdate) {
855
- return {
856
- ...config,
857
- styles: {
858
- ...config.styles,
859
- blocks: {
860
- ...config.styles.blocks,
861
- "core/separator": {
862
- ...config.styles.blocks["core/separator"],
863
- color: {
864
- ...config.styles.blocks["core/separator"].color,
865
- text: config.styles?.blocks["core/separator"].color.background
866
- }
867
- }
868
- }
869
- }
870
- };
871
- }
872
- return config;
873
- }
874
- function processCSSNesting(css, blockSelector) {
875
- let processedCSS = "";
876
- if (!css || css.trim() === "") {
877
- return processedCSS;
878
- }
879
- const parts = css.split("&");
880
- parts.forEach((part) => {
881
- if (!part || part.trim() === "") {
882
- return;
883
- }
884
- const isRootCss = !part.includes("{");
885
- if (isRootCss) {
886
- processedCSS += `:root :where(${blockSelector}){${part.trim()}}`;
887
- } else {
888
- const splitPart = part.replace("}", "").split("{");
889
- if (splitPart.length !== 2) {
890
- return;
891
- }
892
- const [nestedSelector, cssValue] = splitPart;
893
- const matches = nestedSelector.match(/([>+~\s]*::[a-zA-Z-]+)/);
894
- const pseudoPart = matches ? matches[1] : "";
895
- const withoutPseudoElement = matches ? nestedSelector.replace(pseudoPart, "").trim() : nestedSelector.trim();
896
- let combinedSelector;
897
- if (withoutPseudoElement === "") {
898
- combinedSelector = blockSelector;
899
- } else {
900
- combinedSelector = nestedSelector.startsWith(" ") ? (0, import_utils.scopeSelector)(blockSelector, withoutPseudoElement) : (0, import_utils.appendToSelector)(blockSelector, withoutPseudoElement);
901
- }
902
- processedCSS += `:root :where(${combinedSelector})${pseudoPart}{${cssValue.trim()}}`;
903
- }
904
- });
905
- return processedCSS;
906
- }
907
- function useGlobalStylesOutputWithConfig(mergedConfig = {}, disableRootPadding) {
908
- const [blockGap] = (0, import_hooks.useGlobalSetting)("spacing.blockGap");
909
- const hasBlockGapSupport = blockGap !== null;
910
- const hasFallbackGapSupport = !hasBlockGapSupport;
911
- const disableLayoutStyles = (0, import_data.useSelect)((select) => {
912
- const { getSettings } = select(import_store.store);
913
- return !!getSettings().disableLayoutStyles;
914
- });
915
- const { getBlockStyles } = (0, import_data.useSelect)(import_blocks.store);
916
- return (0, import_element.useMemo)(() => {
917
- if (!mergedConfig?.styles || !mergedConfig?.settings) {
918
- return [];
919
- }
920
- const updatedConfig = updateConfigWithSeparator(mergedConfig);
921
- const blockSelectors = getBlockSelectors(
922
- (0, import_blocks.getBlockTypes)(),
923
- getBlockStyles
924
- );
925
- const customProperties = toCustomProperties(
926
- updatedConfig,
927
- blockSelectors
928
- );
929
- const globalStyles = toStyles(
930
- updatedConfig,
931
- blockSelectors,
932
- hasBlockGapSupport,
933
- hasFallbackGapSupport,
934
- disableLayoutStyles,
935
- disableRootPadding
936
- );
937
- const svgs = toSvgFilters(updatedConfig, blockSelectors);
938
- const styles = [
939
- {
940
- css: customProperties,
941
- isGlobalStyles: true
942
- },
943
- {
944
- css: globalStyles,
945
- isGlobalStyles: true
946
- },
947
- // Load custom CSS in own stylesheet so that any invalid CSS entered in the input won't break all the global styles in the editor.
948
- {
949
- css: updatedConfig.styles.css ?? "",
950
- isGlobalStyles: true
951
- },
952
- {
953
- assets: svgs,
954
- __unstableType: "svg",
955
- isGlobalStyles: true
956
- }
957
- ];
958
- (0, import_blocks.getBlockTypes)().forEach((blockType) => {
959
- if (updatedConfig.styles.blocks[blockType.name]?.css) {
960
- const selector = blockSelectors[blockType.name].selector;
961
- styles.push({
962
- css: processCSSNesting(
963
- updatedConfig.styles.blocks[blockType.name]?.css,
964
- selector
965
- ),
966
- isGlobalStyles: true
967
- });
968
- }
969
- });
970
- return [styles, updatedConfig.settings];
971
- }, [
972
- hasBlockGapSupport,
973
- hasFallbackGapSupport,
974
- mergedConfig,
975
- disableLayoutStyles,
976
- disableRootPadding,
977
- getBlockStyles
978
- ]);
979
- }
980
- function useGlobalStylesOutput(disableRootPadding = false) {
981
- const { merged: mergedConfig } = (0, import_element.useContext)(import_context.GlobalStylesContext);
982
- return useGlobalStylesOutputWithConfig(mergedConfig, disableRootPadding);
983
- }
984
- // Annotate the CommonJS export names for ESM import in node:
985
- 0 && (module.exports = {
986
- getBlockSelectors,
987
- getLayoutStyles,
988
- getNodesWithSettings,
989
- getNodesWithStyles,
990
- getStylesDeclarations,
991
- processCSSNesting,
992
- toCustomProperties,
993
- toStyles,
994
- toSvgFilters,
995
- useGlobalStylesOutput,
996
- useGlobalStylesOutputWithConfig
997
- });
998
- //# sourceMappingURL=use-global-styles-output.js.map