File tree Expand file tree Collapse file tree 3 files changed +47
-1
lines changed
packages/global-styles-engine/src/utils Expand file tree Collapse file tree 3 files changed +47
-1
lines changed Original file line number Diff line number Diff line change @@ -524,6 +524,20 @@ function getValueFromCustomVariable(
524524 return getValueFromVariable ( features , blockName , result as string ) ;
525525}
526526
527+ /**
528+ * Attempts to fetch the value of a theme.json CSS variable.
529+ *
530+ * This function resolves CSS variable references in two formats:
531+ * - User format: `var:preset|color|red` or `var:custom|spacing|small`
532+ * - Theme format: `var(--wp--preset--color--red)` or `var(--wp--custom--spacing--small)`
533+ *
534+ * It also handles ref-style variables in the format `{ ref: "path.to.value" }`.
535+ *
536+ * @param features GlobalStylesContext config (user, base, or merged). Represents the theme.json tree.
537+ * @param blockName The name of a block as represented in the styles property. E.g., 'root' for root-level, and 'core/block-name' for blocks.
538+ * @param variable An incoming style value. A CSS var value is expected, but it could be any value.
539+ * @return The value of the CSS var, if found. If not found, returns the original variable argument.
540+ */
527541export function getValueFromVariable (
528542 features : GlobalStylesConfig ,
529543 blockName ?: string ,
Original file line number Diff line number Diff line change @@ -35,6 +35,20 @@ export function setImmutably(
3535 return object ;
3636}
3737
38+ /**
39+ * Helper util to return a value from a certain path of the object.
40+ *
41+ * Path is specified as either:
42+ * - a string of properties, separated by dots, for example: "x.y".
43+ * - an array of properties, for example `[ 'x', 'y' ]`.
44+ *
45+ * You can also specify a default value in case the result is nullish.
46+ *
47+ * @param object Input object.
48+ * @param path Path to the object property.
49+ * @param defaultValue Default value if the value at the specified path is nullish.
50+ * @return Value of the object property at the specified path.
51+ */
3852export const getValueFromObjectPath = (
3953 object : Object ,
4054 path : string | string [ ] ,
Original file line number Diff line number Diff line change @@ -5,13 +5,31 @@ import type {
55 TypographyPreset ,
66 GlobalStylesSettings ,
77 FluidTypographySettings ,
8+ TypographySettings ,
89} from '../types' ;
910import {
1011 getTypographyValueAndUnit ,
1112 getComputedFluidTypographyValue ,
1213} from './fluid' ;
1314
14- function isFluidTypographyEnabled ( typographySettings ?: { fluid ?: any } ) {
15+ /**
16+ * Checks if fluid typography is enabled in the given typography settings.
17+ *
18+ * Fluid typography is considered enabled if the fluid setting is explicitly set to true,
19+ * or if it's an object with properties (which would contain fluid typography configuration
20+ * like minViewportWidth, maxViewportWidth, etc.).
21+ *
22+ * @param typographySettings Typography settings object that may contain fluid typography configuration.
23+ * @param typographySettings.fluid Fluid typography configuration. Can be:
24+ * - `true` to enable with default settings
25+ * - An object with fluid settings (minViewportWidth, maxViewportWidth, etc.)
26+ * - `false` or `undefined` to disable
27+ *
28+ * @return True if fluid typography is enabled, false otherwise.
29+ */
30+ function isFluidTypographyEnabled (
31+ typographySettings ?: TypographySettings | TypographyPreset
32+ ) {
1533 const fluidSettings = typographySettings ?. fluid ;
1634 return (
1735 true === fluidSettings ||
You can’t perform that action at this time.
0 commit comments