@wordpress/global-styles-engine 1.11.0 → 1.12.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.
@@ -58,6 +58,7 @@ var VALID_SETTINGS = [
58
58
  "dimensions.aspectRatio",
59
59
  "dimensions.height",
60
60
  "dimensions.minHeight",
61
+ "dimensions.minWidth",
61
62
  "dimensions.width",
62
63
  "dimensions.dimensionSizes",
63
64
  "layout.contentSize",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/settings/get-setting.ts"],
4
- "sourcesContent": ["/**\n * Internal dependencies\n */\nimport { getValueFromObjectPath, setImmutably } from '../utils/object';\nimport type { GlobalStylesConfig } from '../types';\n\nconst VALID_SETTINGS = [\n\t'appearanceTools',\n\t'useRootPaddingAwareAlignments',\n\t'background.backgroundImage',\n\t'background.backgroundRepeat',\n\t'background.backgroundSize',\n\t'background.backgroundPosition',\n\t'background.gradient',\n\t'border.color',\n\t'border.radius',\n\t'border.radiusSizes',\n\t'border.style',\n\t'border.width',\n\t'shadow.presets',\n\t'shadow.defaultPresets',\n\t'color.background',\n\t'color.button',\n\t'color.caption',\n\t'color.custom',\n\t'color.customDuotone',\n\t'color.customGradient',\n\t'color.defaultDuotone',\n\t'color.defaultGradients',\n\t'color.defaultPalette',\n\t'color.duotone',\n\t'color.gradients',\n\t'color.heading',\n\t'color.link',\n\t'color.palette',\n\t'color.text',\n\t'custom',\n\t'dimensions.aspectRatio',\n\t'dimensions.height',\n\t'dimensions.minHeight',\n\t'dimensions.width',\n\t'dimensions.dimensionSizes',\n\t'layout.contentSize',\n\t'layout.definitions',\n\t'layout.wideSize',\n\t'lightbox.enabled',\n\t'lightbox.allowEditing',\n\t'position.fixed',\n\t'position.sticky',\n\t'spacing.customSpacingSize',\n\t'spacing.defaultSpacingSizes',\n\t'spacing.spacingSizes',\n\t'spacing.spacingScale',\n\t'spacing.blockGap',\n\t'spacing.margin',\n\t'spacing.padding',\n\t'spacing.units',\n\t'typography.fluid',\n\t'typography.customFontSize',\n\t'typography.defaultFontSizes',\n\t'typography.dropCap',\n\t'typography.fontFamilies',\n\t'typography.fontSizes',\n\t'typography.fontStyle',\n\t'typography.fontWeight',\n\t'typography.letterSpacing',\n\t'typography.lineHeight',\n\t'typography.textAlign',\n\t'typography.textColumns',\n\t'typography.textDecoration',\n\t'typography.textIndent',\n\t'typography.textTransform',\n\t'typography.writingMode',\n];\n\nexport function getSetting< T = any >(\n\tglobalStyles: GlobalStylesConfig,\n\tpath: string,\n\tblockName?: string\n): T {\n\tconst appendedBlockPath = blockName ? '.blocks.' + blockName : '';\n\tconst appendedPropertyPath = path ? '.' + path : '';\n\tconst contextualPath = `settings${ appendedBlockPath }${ appendedPropertyPath }`;\n\tconst globalPath = `settings${ appendedPropertyPath }`;\n\n\tif ( path ) {\n\t\treturn ( getValueFromObjectPath( globalStyles, contextualPath ) ??\n\t\t\tgetValueFromObjectPath( globalStyles, globalPath ) ) as T;\n\t}\n\n\tlet result = {};\n\tVALID_SETTINGS.forEach( ( setting ) => {\n\t\tconst value =\n\t\t\tgetValueFromObjectPath(\n\t\t\t\tglobalStyles,\n\t\t\t\t`settings${ appendedBlockPath }.${ setting }`\n\t\t\t) ??\n\t\t\tgetValueFromObjectPath( globalStyles, `settings.${ setting }` );\n\t\tif ( value !== undefined ) {\n\t\t\tresult = setImmutably( result, setting.split( '.' ), value );\n\t\t}\n\t} );\n\treturn result as T;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAAqD;AAGrD,IAAM,iBAAiB;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AAEO,SAAS,WACf,cACA,MACA,WACI;AACJ,QAAM,oBAAoB,YAAY,aAAa,YAAY;AAC/D,QAAM,uBAAuB,OAAO,MAAM,OAAO;AACjD,QAAM,iBAAiB,WAAY,iBAAkB,GAAI,oBAAqB;AAC9E,QAAM,aAAa,WAAY,oBAAqB;AAEpD,MAAK,MAAO;AACX,eAAS,sCAAwB,cAAc,cAAe,SAC7D,sCAAwB,cAAc,UAAW;AAAA,EACnD;AAEA,MAAI,SAAS,CAAC;AACd,iBAAe,QAAS,CAAE,YAAa;AACtC,UAAM,YACL;AAAA,MACC;AAAA,MACA,WAAY,iBAAkB,IAAK,OAAQ;AAAA,IAC5C,SACA,sCAAwB,cAAc,YAAa,OAAQ,EAAG;AAC/D,QAAK,UAAU,QAAY;AAC1B,mBAAS,4BAAc,QAAQ,QAAQ,MAAO,GAAI,GAAG,KAAM;AAAA,IAC5D;AAAA,EACD,CAAE;AACF,SAAO;AACR;",
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport { getValueFromObjectPath, setImmutably } from '../utils/object';\nimport type { GlobalStylesConfig } from '../types';\n\nconst VALID_SETTINGS = [\n\t'appearanceTools',\n\t'useRootPaddingAwareAlignments',\n\t'background.backgroundImage',\n\t'background.backgroundRepeat',\n\t'background.backgroundSize',\n\t'background.backgroundPosition',\n\t'background.gradient',\n\t'border.color',\n\t'border.radius',\n\t'border.radiusSizes',\n\t'border.style',\n\t'border.width',\n\t'shadow.presets',\n\t'shadow.defaultPresets',\n\t'color.background',\n\t'color.button',\n\t'color.caption',\n\t'color.custom',\n\t'color.customDuotone',\n\t'color.customGradient',\n\t'color.defaultDuotone',\n\t'color.defaultGradients',\n\t'color.defaultPalette',\n\t'color.duotone',\n\t'color.gradients',\n\t'color.heading',\n\t'color.link',\n\t'color.palette',\n\t'color.text',\n\t'custom',\n\t'dimensions.aspectRatio',\n\t'dimensions.height',\n\t'dimensions.minHeight',\n\t'dimensions.minWidth',\n\t'dimensions.width',\n\t'dimensions.dimensionSizes',\n\t'layout.contentSize',\n\t'layout.definitions',\n\t'layout.wideSize',\n\t'lightbox.enabled',\n\t'lightbox.allowEditing',\n\t'position.fixed',\n\t'position.sticky',\n\t'spacing.customSpacingSize',\n\t'spacing.defaultSpacingSizes',\n\t'spacing.spacingSizes',\n\t'spacing.spacingScale',\n\t'spacing.blockGap',\n\t'spacing.margin',\n\t'spacing.padding',\n\t'spacing.units',\n\t'typography.fluid',\n\t'typography.customFontSize',\n\t'typography.defaultFontSizes',\n\t'typography.dropCap',\n\t'typography.fontFamilies',\n\t'typography.fontSizes',\n\t'typography.fontStyle',\n\t'typography.fontWeight',\n\t'typography.letterSpacing',\n\t'typography.lineHeight',\n\t'typography.textAlign',\n\t'typography.textColumns',\n\t'typography.textDecoration',\n\t'typography.textIndent',\n\t'typography.textTransform',\n\t'typography.writingMode',\n];\n\nexport function getSetting< T = any >(\n\tglobalStyles: GlobalStylesConfig,\n\tpath: string,\n\tblockName?: string\n): T {\n\tconst appendedBlockPath = blockName ? '.blocks.' + blockName : '';\n\tconst appendedPropertyPath = path ? '.' + path : '';\n\tconst contextualPath = `settings${ appendedBlockPath }${ appendedPropertyPath }`;\n\tconst globalPath = `settings${ appendedPropertyPath }`;\n\n\tif ( path ) {\n\t\treturn ( getValueFromObjectPath( globalStyles, contextualPath ) ??\n\t\t\tgetValueFromObjectPath( globalStyles, globalPath ) ) as T;\n\t}\n\n\tlet result = {};\n\tVALID_SETTINGS.forEach( ( setting ) => {\n\t\tconst value =\n\t\t\tgetValueFromObjectPath(\n\t\t\t\tglobalStyles,\n\t\t\t\t`settings${ appendedBlockPath }.${ setting }`\n\t\t\t) ??\n\t\t\tgetValueFromObjectPath( globalStyles, `settings.${ setting }` );\n\t\tif ( value !== undefined ) {\n\t\t\tresult = setImmutably( result, setting.split( '.' ), value );\n\t\t}\n\t} );\n\treturn result as T;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAAqD;AAGrD,IAAM,iBAAiB;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AAEO,SAAS,WACf,cACA,MACA,WACI;AACJ,QAAM,oBAAoB,YAAY,aAAa,YAAY;AAC/D,QAAM,uBAAuB,OAAO,MAAM,OAAO;AACjD,QAAM,iBAAiB,WAAY,iBAAkB,GAAI,oBAAqB;AAC9E,QAAM,aAAa,WAAY,oBAAqB;AAEpD,MAAK,MAAO;AACX,eAAS,sCAAwB,cAAc,cAAe,SAC7D,sCAAwB,cAAc,UAAW;AAAA,EACnD;AAEA,MAAI,SAAS,CAAC;AACd,iBAAe,QAAS,CAAE,YAAa;AACtC,UAAM,YACL;AAAA,MACC;AAAA,MACA,WAAY,iBAAkB,IAAK,OAAQ;AAAA,IAC5C,SACA,sCAAwB,cAAc,YAAa,OAAQ,EAAG;AAC/D,QAAK,UAAU,QAAY;AAC1B,mBAAS,4BAAc,QAAQ,QAAQ,MAAO,GAAI,GAAG,KAAM;AAAA,IAC5D;AAAA,EACD,CAAE;AACF,SAAO;AACR;",
6
6
  "names": []
7
7
  }
@@ -38,6 +38,10 @@ var BLOCK_SUPPORT_FEATURE_LEVEL_SELECTORS = {
38
38
  spacing: "spacing",
39
39
  typography: "typography"
40
40
  };
41
+ var VALID_BLOCK_PSEUDO_SELECTORS = {
42
+ "core/button": [":hover", ":focus", ":focus-visible", ":active"],
43
+ "core/navigation-link": [":hover", ":focus", ":focus-visible", ":active"]
44
+ };
41
45
  function getPresetsClasses(blockSelector = "*", blockPresets = {}) {
42
46
  return PRESET_METADATA.reduce(
43
47
  (declarations, { path, cssVarInfix, classes }) => {
@@ -410,12 +414,16 @@ var STYLE_KEYS = [
410
414
  "background"
411
415
  ];
412
416
  function pickStyleKeys(treeToPickFrom) {
417
+ return pickStyleAndPseudoKeys(treeToPickFrom);
418
+ }
419
+ function pickStyleAndPseudoKeys(treeToPickFrom, blockName) {
413
420
  if (!treeToPickFrom) {
414
421
  return {};
415
422
  }
416
423
  const entries = Object.entries(treeToPickFrom);
424
+ const allowedPseudoSelectors = blockName ? VALID_BLOCK_PSEUDO_SELECTORS[blockName] ?? [] : [];
417
425
  const pickedEntries = entries.filter(
418
- ([key]) => STYLE_KEYS.includes(key)
426
+ ([key]) => STYLE_KEYS.includes(key) || allowedPseudoSelectors.includes(key)
419
427
  );
420
428
  const clonedEntries = pickedEntries.map(([key, style]) => [
421
429
  key,
@@ -423,6 +431,66 @@ function pickStyleKeys(treeToPickFrom) {
423
431
  ]);
424
432
  return Object.fromEntries(clonedEntries);
425
433
  }
434
+ function appendPseudoSelectorStyles(styles, selector, ruleset, featureSelectors, treeSettings, blockName, styleVariationSelector) {
435
+ const pseudoSelectorStyles = Object.entries(styles).filter(
436
+ ([key]) => key.startsWith(":")
437
+ );
438
+ if (!pseudoSelectorStyles.length) {
439
+ return ruleset;
440
+ }
441
+ pseudoSelectorStyles.forEach(([pseudoKey, pseudoStyle]) => {
442
+ if (!pseudoStyle || typeof pseudoStyle !== "object") {
443
+ return;
444
+ }
445
+ const remainingPseudoStyles = JSON.parse(
446
+ JSON.stringify(pseudoStyle)
447
+ );
448
+ if (featureSelectors && typeof featureSelectors !== "string") {
449
+ let pseudoFeatureDeclarations = getFeatureDeclarations(
450
+ featureSelectors,
451
+ remainingPseudoStyles
452
+ );
453
+ pseudoFeatureDeclarations = updateParagraphTextIndentSelector(
454
+ pseudoFeatureDeclarations,
455
+ treeSettings,
456
+ blockName
457
+ );
458
+ pseudoFeatureDeclarations = updateButtonWidthDeclarations(
459
+ pseudoFeatureDeclarations,
460
+ treeSettings
461
+ );
462
+ Object.entries(pseudoFeatureDeclarations).forEach(
463
+ ([baseSelector, declarations]) => {
464
+ if (!declarations.length) {
465
+ return;
466
+ }
467
+ const pseudoFeatureSelector = appendToSelector(
468
+ baseSelector,
469
+ pseudoKey
470
+ );
471
+ const cssSelector = styleVariationSelector ? concatFeatureVariationSelectorString(
472
+ pseudoFeatureSelector,
473
+ styleVariationSelector
474
+ ) : pseudoFeatureSelector;
475
+ const rules = declarations.join(";");
476
+ ruleset += `:root :where(${cssSelector}){${rules};}`;
477
+ }
478
+ );
479
+ }
480
+ const pseudoDeclarations = getStylesDeclarations(
481
+ remainingPseudoStyles
482
+ );
483
+ if (!pseudoDeclarations.length) {
484
+ return;
485
+ }
486
+ const pseudoSelector = appendToSelector(selector, pseudoKey);
487
+ const pseudoRule = `:root :where(${pseudoSelector}){${pseudoDeclarations.join(
488
+ ";"
489
+ )};}`;
490
+ ruleset += pseudoRule;
491
+ });
492
+ return ruleset;
493
+ }
426
494
  var getNodesWithStyles = (tree, blockSelectors) => {
427
495
  const nodes = [];
428
496
  if (!tree?.styles) {
@@ -451,7 +519,7 @@ var getNodesWithStyles = (tree, blockSelectors) => {
451
519
  });
452
520
  Object.entries(tree.styles?.blocks ?? {}).forEach(
453
521
  ([blockName, node]) => {
454
- const blockStyles = pickStyleKeys(node);
522
+ const blockStyles = pickStyleAndPseudoKeys(node, blockName);
455
523
  const typedNode = node;
456
524
  const variationNodesToAdd = [];
457
525
  if (typedNode?.variations) {
@@ -459,7 +527,10 @@ var getNodesWithStyles = (tree, blockSelectors) => {
459
527
  Object.entries(typedNode.variations).forEach(
460
528
  ([variationName, variation]) => {
461
529
  const typedVariation = variation;
462
- variations[variationName] = pickStyleKeys(typedVariation);
530
+ variations[variationName] = pickStyleAndPseudoKeys(
531
+ typedVariation,
532
+ blockName
533
+ );
463
534
  if (typedVariation?.css) {
464
535
  variations[variationName].css = typedVariation.css;
465
536
  }
@@ -494,7 +565,10 @@ var getNodesWithStyles = (tree, blockSelectors) => {
494
565
  variationSelector,
495
566
  blockSelectors[variationBlockName]?.featureSelectors ?? {}
496
567
  ) : void 0;
497
- const variationBlockStyleNodes = pickStyleKeys(variationBlockStyles);
568
+ const variationBlockStyleNodes = pickStyleAndPseudoKeys(
569
+ variationBlockStyles,
570
+ variationBlockName
571
+ );
498
572
  if (variationBlockStyles?.css) {
499
573
  variationBlockStyleNodes.css = variationBlockStyles.css;
500
574
  }
@@ -856,6 +930,15 @@ var transformToStyles = (tree, blockSelectors, hasBlockGapSupport, hasFallbackGa
856
930
  `:root :where(${styleVariationSelector})`
857
931
  );
858
932
  }
933
+ ruleset = appendPseudoSelectorStyles(
934
+ styleVariations,
935
+ styleVariationSelector,
936
+ ruleset,
937
+ featureSelectors,
938
+ tree.settings,
939
+ name,
940
+ styleVariationSelector
941
+ );
859
942
  if (hasLayoutSupport && styleVariations?.spacing?.blockGap) {
860
943
  const variationSelectorWithBlock = styleVariationSelector + selector;
861
944
  ruleset += getLayoutStyles({
@@ -870,24 +953,14 @@ var transformToStyles = (tree, blockSelectors, hasBlockGapSupport, hasFallbackGa
870
953
  }
871
954
  );
872
955
  }
873
- const pseudoSelectorStyles = Object.entries(styles).filter(
874
- ([key]) => key.startsWith(":")
956
+ ruleset = appendPseudoSelectorStyles(
957
+ styles,
958
+ selector,
959
+ ruleset,
960
+ featureSelectors,
961
+ tree.settings,
962
+ name
875
963
  );
876
- if (pseudoSelectorStyles?.length) {
877
- pseudoSelectorStyles.forEach(
878
- ([pseudoKey, pseudoStyle]) => {
879
- const pseudoDeclarations = getStylesDeclarations(pseudoStyle);
880
- if (!pseudoDeclarations?.length) {
881
- return;
882
- }
883
- const _selector = selector.split(",").map((sel) => sel + pseudoKey).join(",");
884
- const pseudoRule = `:root :where(${_selector}){${pseudoDeclarations.join(
885
- ";"
886
- )};}`;
887
- ruleset += pseudoRule;
888
- }
889
- );
890
- }
891
964
  }
892
965
  );
893
966
  }