@wordpress/style-engine 2.32.0 → 2.32.1-next.b8c8708f3.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 (73) hide show
  1. package/build/index.js +62 -69
  2. package/build/index.js.map +7 -1
  3. package/build/styles/background/index.js +76 -34
  4. package/build/styles/background/index.js.map +7 -1
  5. package/build/styles/border/index.js +61 -48
  6. package/build/styles/border/index.js.map +7 -1
  7. package/build/styles/color/background.js +31 -13
  8. package/build/styles/color/background.js.map +7 -1
  9. package/build/styles/color/gradient.js +31 -13
  10. package/build/styles/color/gradient.js.map +7 -1
  11. package/build/styles/color/index.js +36 -13
  12. package/build/styles/color/index.js.map +7 -1
  13. package/build/styles/color/text.js +26 -13
  14. package/build/styles/color/text.js.map +7 -1
  15. package/build/styles/constants.js +33 -8
  16. package/build/styles/constants.js.map +7 -1
  17. package/build/styles/dimensions/index.js +38 -15
  18. package/build/styles/dimensions/index.js.map +7 -1
  19. package/build/styles/index.js +54 -19
  20. package/build/styles/index.js.map +7 -1
  21. package/build/styles/outline/index.js +36 -23
  22. package/build/styles/outline/index.js.map +7 -1
  23. package/build/styles/shadow/index.js +26 -13
  24. package/build/styles/shadow/index.js.map +7 -1
  25. package/build/styles/spacing/index.js +35 -12
  26. package/build/styles/spacing/index.js.map +7 -1
  27. package/build/styles/spacing/margin.js +28 -15
  28. package/build/styles/spacing/margin.js.map +7 -1
  29. package/build/styles/spacing/padding.js +28 -15
  30. package/build/styles/spacing/padding.js.map +7 -1
  31. package/build/styles/typography/index.js +105 -31
  32. package/build/styles/typography/index.js.map +7 -1
  33. package/build/styles/utils.js +90 -132
  34. package/build/styles/utils.js.map +7 -1
  35. package/build/types.js +16 -5
  36. package/build/types.js.map +7 -1
  37. package/build-module/index.js +40 -61
  38. package/build-module/index.js.map +7 -1
  39. package/build-module/styles/background/index.js +58 -30
  40. package/build-module/styles/background/index.js.map +7 -1
  41. package/build-module/styles/border/index.js +42 -44
  42. package/build-module/styles/border/index.js.map +7 -1
  43. package/build-module/styles/color/background.js +13 -9
  44. package/build-module/styles/color/background.js.map +7 -1
  45. package/build-module/styles/color/gradient.js +13 -9
  46. package/build-module/styles/color/gradient.js.map +7 -1
  47. package/build-module/styles/color/index.js +8 -8
  48. package/build-module/styles/color/index.js.map +7 -1
  49. package/build-module/styles/color/text.js +8 -9
  50. package/build-module/styles/color/text.js.map +7 -1
  51. package/build-module/styles/constants.js +9 -4
  52. package/build-module/styles/constants.js.map +7 -1
  53. package/build-module/styles/dimensions/index.js +20 -11
  54. package/build-module/styles/dimensions/index.js.map +7 -1
  55. package/build-module/styles/index.js +22 -13
  56. package/build-module/styles/index.js.map +7 -1
  57. package/build-module/styles/outline/index.js +14 -15
  58. package/build-module/styles/outline/index.js.map +7 -1
  59. package/build-module/styles/shadow/index.js +8 -9
  60. package/build-module/styles/shadow/index.js.map +7 -1
  61. package/build-module/styles/spacing/index.js +7 -7
  62. package/build-module/styles/spacing/index.js.map +7 -1
  63. package/build-module/styles/spacing/margin.js +10 -11
  64. package/build-module/styles/spacing/margin.js.map +7 -1
  65. package/build-module/styles/spacing/padding.js +10 -11
  66. package/build-module/styles/spacing/padding.js.map +7 -1
  67. package/build-module/styles/typography/index.js +87 -27
  68. package/build-module/styles/typography/index.js.map +7 -1
  69. package/build-module/styles/utils.js +72 -128
  70. package/build-module/styles/utils.js.map +7 -1
  71. package/build-module/types.js +1 -2
  72. package/build-module/types.js.map +7 -1
  73. package/package.json +10 -3
@@ -1,163 +1,107 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { paramCase as kebabCase } from 'change-case';
5
-
6
- /**
7
- * Internal dependencies
8
- */
9
-
10
- import { VARIABLE_REFERENCE_PREFIX, VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE, VARIABLE_PATH_SEPARATOR_TOKEN_STYLE } from './constants';
11
-
12
- /**
13
- * Helper util to return a value from a certain path of the object.
14
- * Path is specified as an array of properties, like `[ 'x', 'y' ]`.
15
- *
16
- * @param object Input object.
17
- * @param path Path to the object property.
18
- * @return Value of the object property at the specified path.
19
- */
20
- export const getStyleValueByPath = (object, path) => {
1
+ import { paramCase as kebabCase } from "change-case";
2
+ import {
3
+ VARIABLE_REFERENCE_PREFIX,
4
+ VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE,
5
+ VARIABLE_PATH_SEPARATOR_TOKEN_STYLE
6
+ } from "./constants";
7
+ const getStyleValueByPath = (object, path) => {
21
8
  let value = object;
22
- path.forEach(fieldName => {
9
+ path.forEach((fieldName) => {
23
10
  value = value?.[fieldName];
24
11
  });
25
12
  return value;
26
13
  };
27
-
28
- /**
29
- * Returns a JSON representation of the generated CSS rules.
30
- *
31
- * @param style Style object.
32
- * @param options Options object with settings to adjust how the styles are generated.
33
- * @param path An array of strings representing the path to the style value in the style object.
34
- * @param ruleKey A CSS property key.
35
- *
36
- * @return GeneratedCSSRule[] CSS rules.
37
- */
38
- export function generateRule(style, options, path, ruleKey) {
14
+ function generateRule(style, options, path, ruleKey) {
39
15
  const styleValue = getStyleValueByPath(style, path);
40
- return styleValue ? [{
41
- selector: options?.selector,
42
- key: ruleKey,
43
- value: getCSSValueFromRawStyle(styleValue)
44
- }] : [];
16
+ return styleValue ? [
17
+ {
18
+ selector: options?.selector,
19
+ key: ruleKey,
20
+ value: getCSSValueFromRawStyle(styleValue)
21
+ }
22
+ ] : [];
45
23
  }
46
-
47
- /**
48
- * Returns a JSON representation of the generated CSS rules taking into account box model properties, top, right, bottom, left.
49
- *
50
- * @param style Style object.
51
- * @param options Options object with settings to adjust how the styles are generated.
52
- * @param path An array of strings representing the path to the style value in the style object.
53
- * @param ruleKeys An array of CSS property keys and patterns.
54
- * @param individualProperties The "sides" or individual properties for which to generate rules.
55
- *
56
- * @return GeneratedCSSRule[] CSS rules.
57
- */
58
- export function generateBoxRules(style, options, path, ruleKeys, individualProperties = ['top', 'right', 'bottom', 'left']) {
59
- const boxStyle = getStyleValueByPath(style, path);
24
+ function generateBoxRules(style, options, path, ruleKeys, individualProperties = ["top", "right", "bottom", "left"]) {
25
+ const boxStyle = getStyleValueByPath(
26
+ style,
27
+ path
28
+ );
60
29
  if (!boxStyle) {
61
30
  return [];
62
31
  }
63
32
  const rules = [];
64
- if (typeof boxStyle === 'string') {
33
+ if (typeof boxStyle === "string") {
65
34
  rules.push({
66
35
  selector: options?.selector,
67
36
  key: ruleKeys.default,
68
37
  value: getCSSValueFromRawStyle(boxStyle)
69
38
  });
70
39
  } else {
71
- const sideRules = individualProperties.reduce((acc, side) => {
72
- const value = getCSSValueFromRawStyle(getStyleValueByPath(boxStyle, [side]));
73
- if (value) {
74
- acc.push({
75
- selector: options?.selector,
76
- key: ruleKeys?.individual.replace('%s', upperFirst(side)),
77
- value
78
- });
79
- }
80
- return acc;
81
- }, []);
40
+ const sideRules = individualProperties.reduce(
41
+ (acc, side) => {
42
+ const value = getCSSValueFromRawStyle(
43
+ getStyleValueByPath(boxStyle, [side])
44
+ );
45
+ if (value) {
46
+ acc.push({
47
+ selector: options?.selector,
48
+ key: ruleKeys?.individual.replace(
49
+ "%s",
50
+ upperFirst(side)
51
+ ),
52
+ value
53
+ });
54
+ }
55
+ return acc;
56
+ },
57
+ []
58
+ );
82
59
  rules.push(...sideRules);
83
60
  }
84
61
  return rules;
85
62
  }
86
-
87
- /**
88
- * Returns a WordPress CSS custom var value from incoming style preset value,
89
- * if one is detected.
90
- *
91
- * The preset value is a string and follows the pattern `var:description|context|slug`.
92
- *
93
- * Example:
94
- *
95
- * `getCSSValueFromRawStyle( 'var:preset|color|heavenlyBlue' )` // returns 'var(--wp--preset--color--heavenly-blue)'
96
- *
97
- * @param styleValue A string representing a raw CSS value. Non-strings won't be processed.
98
- *
99
- * @return A CSS custom var value if the incoming style value is a preset value.
100
- */
101
-
102
- export function getCSSValueFromRawStyle(styleValue) {
103
- if (typeof styleValue === 'string' && styleValue.startsWith(VARIABLE_REFERENCE_PREFIX)) {
104
- const variable = styleValue.slice(VARIABLE_REFERENCE_PREFIX.length).split(VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE).map(presetVariable => kebabCase(presetVariable, {
105
- splitRegexp: [/([a-z0-9])([A-Z])/g,
106
- // fooBar => foo-bar, 3Bar => 3-bar
107
- /([0-9])([a-z])/g,
108
- // 3bar => 3-bar
109
- /([A-Za-z])([0-9])/g,
110
- // Foo3 => foo-3, foo3 => foo-3
111
- /([A-Z])([A-Z][a-z])/g // FOOBar => foo-bar
112
- ]
113
- })).join(VARIABLE_PATH_SEPARATOR_TOKEN_STYLE);
63
+ function getCSSValueFromRawStyle(styleValue) {
64
+ if (typeof styleValue === "string" && styleValue.startsWith(VARIABLE_REFERENCE_PREFIX)) {
65
+ const variable = styleValue.slice(VARIABLE_REFERENCE_PREFIX.length).split(VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE).map(
66
+ (presetVariable) => kebabCase(presetVariable, {
67
+ splitRegexp: [
68
+ /([a-z0-9])([A-Z])/g,
69
+ // fooBar => foo-bar, 3Bar => 3-bar
70
+ /([0-9])([a-z])/g,
71
+ // 3bar => 3-bar
72
+ /([A-Za-z])([0-9])/g,
73
+ // Foo3 => foo-3, foo3 => foo-3
74
+ /([A-Z])([A-Z][a-z])/g
75
+ // FOOBar => foo-bar
76
+ ]
77
+ })
78
+ ).join(VARIABLE_PATH_SEPARATOR_TOKEN_STYLE);
114
79
  return `var(--wp--${variable})`;
115
80
  }
116
81
  return styleValue;
117
82
  }
118
-
119
- /**
120
- * Capitalizes the first letter in a string.
121
- *
122
- * @param string The string whose first letter the function will capitalize.
123
- *
124
- * @return String with the first letter capitalized.
125
- */
126
- export function upperFirst(string) {
83
+ function upperFirst(string) {
127
84
  const [firstLetter, ...rest] = string;
128
- return firstLetter.toUpperCase() + rest.join('');
85
+ return firstLetter.toUpperCase() + rest.join("");
129
86
  }
130
-
131
- /**
132
- * Converts an array of strings into a camelCase string.
133
- *
134
- * @param strings The strings to join into a camelCase string.
135
- *
136
- * @return camelCase string.
137
- */
138
- export function camelCaseJoin(strings) {
87
+ function camelCaseJoin(strings) {
139
88
  const [firstItem, ...rest] = strings;
140
- return firstItem.toLowerCase() + rest.map(upperFirst).join('');
89
+ return firstItem.toLowerCase() + rest.map(upperFirst).join("");
141
90
  }
142
-
143
- /**
144
- * Safely decodes a URI with `decodeURI`. Returns the URI unmodified if
145
- * `decodeURI` throws an error.
146
- *
147
- * @param {string} uri URI to decode.
148
- *
149
- * @example
150
- * ```js
151
- * const badUri = safeDecodeURI( '%z' ); // does not throw an Error, simply returns '%z'
152
- * ```
153
- *
154
- * @return {string} Decoded URI if possible.
155
- */
156
- export function safeDecodeURI(uri) {
91
+ function safeDecodeURI(uri) {
157
92
  try {
158
93
  return decodeURI(uri);
159
94
  } catch (uriError) {
160
95
  return uri;
161
96
  }
162
97
  }
163
- //# sourceMappingURL=utils.js.map
98
+ export {
99
+ camelCaseJoin,
100
+ generateBoxRules,
101
+ generateRule,
102
+ getCSSValueFromRawStyle,
103
+ getStyleValueByPath,
104
+ safeDecodeURI,
105
+ upperFirst
106
+ };
107
+ //# sourceMappingURL=utils.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["paramCase","kebabCase","VARIABLE_REFERENCE_PREFIX","VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE","VARIABLE_PATH_SEPARATOR_TOKEN_STYLE","getStyleValueByPath","object","path","value","forEach","fieldName","generateRule","style","options","ruleKey","styleValue","selector","key","getCSSValueFromRawStyle","generateBoxRules","ruleKeys","individualProperties","boxStyle","rules","push","default","sideRules","reduce","acc","side","individual","replace","upperFirst","startsWith","variable","slice","length","split","map","presetVariable","splitRegexp","join","string","firstLetter","rest","toUpperCase","camelCaseJoin","strings","firstItem","toLowerCase","safeDecodeURI","uri","decodeURI","uriError"],"sources":["@wordpress/style-engine/src/styles/utils.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport { paramCase as kebabCase } from 'change-case';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tCssRulesKeys,\n\tGeneratedCSSRule,\n\tStyle,\n\tBox,\n\tStyleOptions,\n} from '../types';\nimport {\n\tVARIABLE_REFERENCE_PREFIX,\n\tVARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE,\n\tVARIABLE_PATH_SEPARATOR_TOKEN_STYLE,\n} from './constants';\n\n/**\n * Helper util to return a value from a certain path of the object.\n * Path is specified as an array of properties, like `[ 'x', 'y' ]`.\n *\n * @param object Input object.\n * @param path Path to the object property.\n * @return Value of the object property at the specified path.\n */\nexport const getStyleValueByPath = (\n\tobject: Record< any, any >,\n\tpath: string[]\n) => {\n\tlet value: any = object;\n\tpath.forEach( ( fieldName: string ) => {\n\t\tvalue = value?.[ fieldName ];\n\t} );\n\treturn value;\n};\n\n/**\n * Returns a JSON representation of the generated CSS rules.\n *\n * @param style Style object.\n * @param options Options object with settings to adjust how the styles are generated.\n * @param path An array of strings representing the path to the style value in the style object.\n * @param ruleKey A CSS property key.\n *\n * @return GeneratedCSSRule[] CSS rules.\n */\nexport function generateRule(\n\tstyle: Style,\n\toptions: StyleOptions,\n\tpath: string[],\n\truleKey: string\n): GeneratedCSSRule[] {\n\tconst styleValue: string | undefined = getStyleValueByPath( style, path );\n\n\treturn styleValue\n\t\t? [\n\t\t\t\t{\n\t\t\t\t\tselector: options?.selector,\n\t\t\t\t\tkey: ruleKey,\n\t\t\t\t\tvalue: getCSSValueFromRawStyle( styleValue ),\n\t\t\t\t},\n\t\t ]\n\t\t: [];\n}\n\n/**\n * Returns a JSON representation of the generated CSS rules taking into account box model properties, top, right, bottom, left.\n *\n * @param style Style object.\n * @param options Options object with settings to adjust how the styles are generated.\n * @param path An array of strings representing the path to the style value in the style object.\n * @param ruleKeys An array of CSS property keys and patterns.\n * @param individualProperties The \"sides\" or individual properties for which to generate rules.\n *\n * @return GeneratedCSSRule[] CSS rules.\n */\nexport function generateBoxRules(\n\tstyle: Style,\n\toptions: StyleOptions,\n\tpath: string[],\n\truleKeys: CssRulesKeys,\n\tindividualProperties: string[] = [ 'top', 'right', 'bottom', 'left' ]\n): GeneratedCSSRule[] {\n\tconst boxStyle: Box | string | undefined = getStyleValueByPath(\n\t\tstyle,\n\t\tpath\n\t);\n\tif ( ! boxStyle ) {\n\t\treturn [];\n\t}\n\n\tconst rules: GeneratedCSSRule[] = [];\n\tif ( typeof boxStyle === 'string' ) {\n\t\trules.push( {\n\t\t\tselector: options?.selector,\n\t\t\tkey: ruleKeys.default,\n\t\t\tvalue: getCSSValueFromRawStyle( boxStyle ),\n\t\t} );\n\t} else {\n\t\tconst sideRules = individualProperties.reduce(\n\t\t\t( acc: GeneratedCSSRule[], side: string ) => {\n\t\t\t\tconst value = getCSSValueFromRawStyle(\n\t\t\t\t\tgetStyleValueByPath( boxStyle, [ side ] )\n\t\t\t\t);\n\t\t\t\tif ( value ) {\n\t\t\t\t\tacc.push( {\n\t\t\t\t\t\tselector: options?.selector,\n\t\t\t\t\t\tkey: ruleKeys?.individual.replace(\n\t\t\t\t\t\t\t'%s',\n\t\t\t\t\t\t\tupperFirst( side )\n\t\t\t\t\t\t),\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t\treturn acc;\n\t\t\t},\n\t\t\t[]\n\t\t);\n\t\trules.push( ...sideRules );\n\t}\n\n\treturn rules;\n}\n\n/**\n * Returns a WordPress CSS custom var value from incoming style preset value,\n * if one is detected.\n *\n * The preset value is a string and follows the pattern `var:description|context|slug`.\n *\n * Example:\n *\n * `getCSSValueFromRawStyle( 'var:preset|color|heavenlyBlue' )` // returns 'var(--wp--preset--color--heavenly-blue)'\n *\n * @param styleValue A string representing a raw CSS value. Non-strings won't be processed.\n *\n * @return A CSS custom var value if the incoming style value is a preset value.\n */\n\nexport function getCSSValueFromRawStyle< StyleValue = string >(\n\tstyleValue: StyleValue\n): StyleValue {\n\tif (\n\t\ttypeof styleValue === 'string' &&\n\t\tstyleValue.startsWith( VARIABLE_REFERENCE_PREFIX )\n\t) {\n\t\tconst variable = styleValue\n\t\t\t.slice( VARIABLE_REFERENCE_PREFIX.length )\n\t\t\t.split( VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE )\n\t\t\t.map( ( presetVariable ) =>\n\t\t\t\tkebabCase( presetVariable, {\n\t\t\t\t\tsplitRegexp: [\n\t\t\t\t\t\t/([a-z0-9])([A-Z])/g, // fooBar => foo-bar, 3Bar => 3-bar\n\t\t\t\t\t\t/([0-9])([a-z])/g, // 3bar => 3-bar\n\t\t\t\t\t\t/([A-Za-z])([0-9])/g, // Foo3 => foo-3, foo3 => foo-3\n\t\t\t\t\t\t/([A-Z])([A-Z][a-z])/g, // FOOBar => foo-bar\n\t\t\t\t\t],\n\t\t\t\t} )\n\t\t\t)\n\t\t\t.join( VARIABLE_PATH_SEPARATOR_TOKEN_STYLE );\n\t\treturn `var(--wp--${ variable })` as StyleValue;\n\t}\n\treturn styleValue;\n}\n\n/**\n * Capitalizes the first letter in a string.\n *\n * @param string The string whose first letter the function will capitalize.\n *\n * @return String with the first letter capitalized.\n */\nexport function upperFirst( string: string ): string {\n\tconst [ firstLetter, ...rest ] = string;\n\treturn firstLetter.toUpperCase() + rest.join( '' );\n}\n\n/**\n * Converts an array of strings into a camelCase string.\n *\n * @param strings The strings to join into a camelCase string.\n *\n * @return camelCase string.\n */\nexport function camelCaseJoin( strings: string[] ): string {\n\tconst [ firstItem, ...rest ] = strings;\n\treturn firstItem.toLowerCase() + rest.map( upperFirst ).join( '' );\n}\n\n/**\n * Safely decodes a URI with `decodeURI`. Returns the URI unmodified if\n * `decodeURI` throws an error.\n *\n * @param {string} uri URI to decode.\n *\n * @example\n * ```js\n * const badUri = safeDecodeURI( '%z' ); // does not throw an Error, simply returns '%z'\n * ```\n *\n * @return {string} Decoded URI if possible.\n */\nexport function safeDecodeURI( uri: string ): string {\n\ttry {\n\t\treturn decodeURI( uri );\n\t} catch ( uriError ) {\n\t\treturn uri;\n\t}\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,S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C,CACAC,IAAI,CAAErC,mCAAoC,CAAC;IAC7C,OAAO,aAAc8B,QAAQ,GAAI;EAClC;EACA,OAAOnB,UAAU;AAClB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASiB,UAAUA,CAAEU,MAAc,EAAW;EACpD,MAAM,CAAEC,WAAW,EAAE,GAAGC,IAAI,CAAE,GAAGF,MAAM;EACvC,OAAOC,WAAW,CAACE,WAAW,CAAC,CAAC,GAAGD,IAAI,CAACH,IAAI,CAAE,EAAG,CAAC;AACnD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASK,aAAaA,CAAEC,OAAiB,EAAW;EAC1D,MAAM,CAAEC,SAAS,EAAE,GAAGJ,IAAI,CAAE,GAAGG,OAAO;EACtC,OAAOC,SAAS,CAACC,WAAW,CAAC,CAAC,GAAGL,IAAI,CAACN,GAAG,CAAEN,UAAW,CAAC,CAACS,IAAI,CAAE,EAAG,CAAC;AACnE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASS,aAAaA,CAAEC,GAAW,EAAW;EACpD,IAAI;IACH,OAAOC,SAAS,CAAED,GAAI,CAAC;EACxB,CAAC,CAAC,OAAQE,QAAQ,EAAG;IACpB,OAAOF,GAAG;EACX;AACD","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/styles/utils.ts"],
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport { paramCase as kebabCase } from 'change-case';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tCssRulesKeys,\n\tGeneratedCSSRule,\n\tStyle,\n\tBox,\n\tStyleOptions,\n} from '../types';\nimport {\n\tVARIABLE_REFERENCE_PREFIX,\n\tVARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE,\n\tVARIABLE_PATH_SEPARATOR_TOKEN_STYLE,\n} from './constants';\n\n/**\n * Helper util to return a value from a certain path of the object.\n * Path is specified as an array of properties, like `[ 'x', 'y' ]`.\n *\n * @param object Input object.\n * @param path Path to the object property.\n * @return Value of the object property at the specified path.\n */\nexport const getStyleValueByPath = (\n\tobject: Record< any, any >,\n\tpath: string[]\n) => {\n\tlet value: any = object;\n\tpath.forEach( ( fieldName: string ) => {\n\t\tvalue = value?.[ fieldName ];\n\t} );\n\treturn value;\n};\n\n/**\n * Returns a JSON representation of the generated CSS rules.\n *\n * @param style Style object.\n * @param options Options object with settings to adjust how the styles are generated.\n * @param path An array of strings representing the path to the style value in the style object.\n * @param ruleKey A CSS property key.\n *\n * @return GeneratedCSSRule[] CSS rules.\n */\nexport function generateRule(\n\tstyle: Style,\n\toptions: StyleOptions,\n\tpath: string[],\n\truleKey: string\n): GeneratedCSSRule[] {\n\tconst styleValue: string | undefined = getStyleValueByPath( style, path );\n\n\treturn styleValue\n\t\t? [\n\t\t\t\t{\n\t\t\t\t\tselector: options?.selector,\n\t\t\t\t\tkey: ruleKey,\n\t\t\t\t\tvalue: getCSSValueFromRawStyle( styleValue ),\n\t\t\t\t},\n\t\t ]\n\t\t: [];\n}\n\n/**\n * Returns a JSON representation of the generated CSS rules taking into account box model properties, top, right, bottom, left.\n *\n * @param style Style object.\n * @param options Options object with settings to adjust how the styles are generated.\n * @param path An array of strings representing the path to the style value in the style object.\n * @param ruleKeys An array of CSS property keys and patterns.\n * @param individualProperties The \"sides\" or individual properties for which to generate rules.\n *\n * @return GeneratedCSSRule[] CSS rules.\n */\nexport function generateBoxRules(\n\tstyle: Style,\n\toptions: StyleOptions,\n\tpath: string[],\n\truleKeys: CssRulesKeys,\n\tindividualProperties: string[] = [ 'top', 'right', 'bottom', 'left' ]\n): GeneratedCSSRule[] {\n\tconst boxStyle: Box | string | undefined = getStyleValueByPath(\n\t\tstyle,\n\t\tpath\n\t);\n\tif ( ! boxStyle ) {\n\t\treturn [];\n\t}\n\n\tconst rules: GeneratedCSSRule[] = [];\n\tif ( typeof boxStyle === 'string' ) {\n\t\trules.push( {\n\t\t\tselector: options?.selector,\n\t\t\tkey: ruleKeys.default,\n\t\t\tvalue: getCSSValueFromRawStyle( boxStyle ),\n\t\t} );\n\t} else {\n\t\tconst sideRules = individualProperties.reduce(\n\t\t\t( acc: GeneratedCSSRule[], side: string ) => {\n\t\t\t\tconst value = getCSSValueFromRawStyle(\n\t\t\t\t\tgetStyleValueByPath( boxStyle, [ side ] )\n\t\t\t\t);\n\t\t\t\tif ( value ) {\n\t\t\t\t\tacc.push( {\n\t\t\t\t\t\tselector: options?.selector,\n\t\t\t\t\t\tkey: ruleKeys?.individual.replace(\n\t\t\t\t\t\t\t'%s',\n\t\t\t\t\t\t\tupperFirst( side )\n\t\t\t\t\t\t),\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t\treturn acc;\n\t\t\t},\n\t\t\t[]\n\t\t);\n\t\trules.push( ...sideRules );\n\t}\n\n\treturn rules;\n}\n\n/**\n * Returns a WordPress CSS custom var value from incoming style preset value,\n * if one is detected.\n *\n * The preset value is a string and follows the pattern `var:description|context|slug`.\n *\n * Example:\n *\n * `getCSSValueFromRawStyle( 'var:preset|color|heavenlyBlue' )` // returns 'var(--wp--preset--color--heavenly-blue)'\n *\n * @param styleValue A string representing a raw CSS value. Non-strings won't be processed.\n *\n * @return A CSS custom var value if the incoming style value is a preset value.\n */\n\nexport function getCSSValueFromRawStyle< StyleValue = string >(\n\tstyleValue: StyleValue\n): StyleValue {\n\tif (\n\t\ttypeof styleValue === 'string' &&\n\t\tstyleValue.startsWith( VARIABLE_REFERENCE_PREFIX )\n\t) {\n\t\tconst variable = styleValue\n\t\t\t.slice( VARIABLE_REFERENCE_PREFIX.length )\n\t\t\t.split( VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE )\n\t\t\t.map( ( presetVariable ) =>\n\t\t\t\tkebabCase( presetVariable, {\n\t\t\t\t\tsplitRegexp: [\n\t\t\t\t\t\t/([a-z0-9])([A-Z])/g, // fooBar => foo-bar, 3Bar => 3-bar\n\t\t\t\t\t\t/([0-9])([a-z])/g, // 3bar => 3-bar\n\t\t\t\t\t\t/([A-Za-z])([0-9])/g, // Foo3 => foo-3, foo3 => foo-3\n\t\t\t\t\t\t/([A-Z])([A-Z][a-z])/g, // FOOBar => foo-bar\n\t\t\t\t\t],\n\t\t\t\t} )\n\t\t\t)\n\t\t\t.join( VARIABLE_PATH_SEPARATOR_TOKEN_STYLE );\n\t\treturn `var(--wp--${ variable })` as StyleValue;\n\t}\n\treturn styleValue;\n}\n\n/**\n * Capitalizes the first letter in a string.\n *\n * @param string The string whose first letter the function will capitalize.\n *\n * @return String with the first letter capitalized.\n */\nexport function upperFirst( string: string ): string {\n\tconst [ firstLetter, ...rest ] = string;\n\treturn firstLetter.toUpperCase() + rest.join( '' );\n}\n\n/**\n * Converts an array of strings into a camelCase string.\n *\n * @param strings The strings to join into a camelCase string.\n *\n * @return camelCase string.\n */\nexport function camelCaseJoin( strings: string[] ): string {\n\tconst [ firstItem, ...rest ] = strings;\n\treturn firstItem.toLowerCase() + rest.map( upperFirst ).join( '' );\n}\n\n/**\n * Safely decodes a URI with `decodeURI`. Returns the URI unmodified if\n * `decodeURI` throws an error.\n *\n * @param {string} uri URI to decode.\n *\n * @example\n * ```js\n * const badUri = safeDecodeURI( '%z' ); // does not throw an Error, simply returns '%z'\n * ```\n *\n * @return {string} Decoded URI if possible.\n */\nexport function safeDecodeURI( uri: string ): string {\n\ttry {\n\t\treturn decodeURI( uri );\n\t} catch ( uriError ) {\n\t\treturn uri;\n\t}\n}\n"],
5
+ "mappings": "AAGA,SAAS,aAAa,iBAAiB;AAYvC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAUA,MAAM,sBAAsB,CAClC,QACA,SACI;AACJ,MAAI,QAAa;AACjB,OAAK,QAAS,CAAE,cAAuB;AACtC,YAAQ,QAAS,SAAU;AAAA,EAC5B,CAAE;AACF,SAAO;AACR;AAYO,SAAS,aACf,OACA,SACA,MACA,SAC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A;AAAA,UACA;AAAA;AAAA,QACD;AAAA,MACD,CAAE;AAAA,IACH,EACC,KAAM,mCAAoC;AAC5C,WAAO,aAAc,QAAS;AAAA,EAC/B;AACA,SAAO;AACR;AASO,SAAS,WAAY,QAAyB;AACpD,QAAM,CAAE,aAAa,GAAG,IAAK,IAAI;AACjC,SAAO,YAAY,YAAY,IAAI,KAAK,KAAM,EAAG;AAClD;AASO,SAAS,cAAe,SAA4B;AAC1D,QAAM,CAAE,WAAW,GAAG,IAAK,IAAI;AAC/B,SAAO,UAAU,YAAY,IAAI,KAAK,IAAK,UAAW,EAAE,KAAM,EAAG;AAClE;AAeO,SAAS,cAAe,KAAsB;AACpD,MAAI;AACH,WAAO,UAAW,GAAI;AAAA,EACvB,SAAU,UAAW;AACpB,WAAO;AAAA,EACR;AACD;",
6
+ "names": []
7
+ }
@@ -1,2 +1 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
1
+ //# sourceMappingURL=types.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":[],"sources":["@wordpress/style-engine/src/types.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { CSSProperties } from 'react';\n\ntype BoxVariant = 'margin' | 'padding';\nexport interface Box< T extends BoxVariant | undefined = undefined > {\n\ttop?: CSSProperties[ T extends undefined ? 'top' : `${ T }Top` ];\n\tright?: CSSProperties[ T extends undefined ? 'right' : `${ T }Right` ];\n\tbottom?: CSSProperties[ T extends undefined ? 'bottom' : `${ T }Bottom` ];\n\tleft?: CSSProperties[ T extends undefined ? 'left' : `${ T }Left` ];\n}\n\nexport type BoxEdge = 'top' | 'right' | 'bottom' | 'left';\n\n// `T` is one of the values in `BorderIndividualProperty`. The expected CSSProperties key is something like `borderTopColor`.\nexport interface BorderIndividualStyles< T extends BoxEdge > {\n\tcolor?: CSSProperties[ `border${ Capitalize< T > }Color` ];\n\tstyle?: CSSProperties[ `border${ Capitalize< T > }Style` ];\n\twidth?: CSSProperties[ `border${ Capitalize< T > }Width` ];\n}\n\nexport interface Style {\n\tbackground?: {\n\t\tbackgroundImage?:\n\t\t\t| { url?: CSSProperties[ 'backgroundImage' ]; source?: string }\n\t\t\t| CSSProperties[ 'backgroundImage' ];\n\t\tbackgroundPosition?: CSSProperties[ 'backgroundPosition' ];\n\t\tbackgroundRepeat?: CSSProperties[ 'backgroundRepeat' ];\n\t\tbackgroundSize?: CSSProperties[ 'backgroundSize' ];\n\t};\n\tborder?: {\n\t\tcolor?: CSSProperties[ 'borderColor' ];\n\t\tradius?:\n\t\t\t| CSSProperties[ 'borderRadius' ]\n\t\t\t| {\n\t\t\t\t\ttopLeft?: CSSProperties[ 'borderTopLeftRadius' ];\n\t\t\t\t\ttopRight?: CSSProperties[ 'borderTopRightRadius' ];\n\t\t\t\t\tbottomLeft?: CSSProperties[ 'borderBottomLeftRadius' ];\n\t\t\t\t\tbottomRight?: CSSProperties[ 'borderBottomLeftRadius' ];\n\t\t\t };\n\t\tstyle?: CSSProperties[ 'borderStyle' ];\n\t\twidth?: CSSProperties[ 'borderWidth' ];\n\t\ttop?: BorderIndividualStyles< 'top' >;\n\t\tright?: BorderIndividualStyles< 'right' >;\n\t\tbottom?: BorderIndividualStyles< 'bottom' >;\n\t\tleft?: BorderIndividualStyles< 'left' >;\n\t};\n\tdimensions?: {\n\t\taspectRatio?: CSSProperties[ 'aspectRatio' ];\n\t\tminHeight?: CSSProperties[ 'minHeight' ];\n\t};\n\tspacing?: {\n\t\tmargin?: CSSProperties[ 'margin' ] | Box< 'margin' >;\n\t\tpadding?: CSSProperties[ 'padding' ] | Box< 'padding' >;\n\t};\n\ttypography?: {\n\t\tfontSize?: CSSProperties[ 'fontSize' ];\n\t\tfontFamily?: CSSProperties[ 'fontFamily' ];\n\t\tfontWeight?: CSSProperties[ 'fontWeight' ];\n\t\tfontStyle?: CSSProperties[ 'fontStyle' ];\n\t\tletterSpacing?: CSSProperties[ 'letterSpacing' ];\n\t\tlineHeight?: CSSProperties[ 'lineHeight' ];\n\t\ttextColumns?: CSSProperties[ 'columnCount' ];\n\t\ttextDecoration?: CSSProperties[ 'textDecoration' ];\n\t\ttextTransform?: CSSProperties[ 'textTransform' ];\n\t\twritingMode?: CSSProperties[ 'writingMode' ];\n\t};\n\tcolor?: {\n\t\ttext?: CSSProperties[ 'color' ];\n\t\tbackground?: CSSProperties[ 'backgroundColor' ];\n\t\tgradient?: CSSProperties[ 'background' ];\n\t};\n\telements?: {\n\t\tlink?: {\n\t\t\tcolor?: {\n\t\t\t\ttext?: CSSProperties[ 'color' ];\n\t\t\t};\n\t\t};\n\t};\n}\n\nexport interface CssRulesKeys {\n\tdefault: string;\n\tindividual: string;\n}\n\nexport interface StyleOptions {\n\t/**\n\t * CSS selector for the generated style.\n\t */\n\tselector?: string;\n}\n\nexport interface GeneratedCSSRule {\n\tselector?: string;\n\tvalue: string | unknown;\n\t/**\n\t * The CSS key in JS style attribute format, compatible with React.\n\t * E.g. `paddingTop` instead of `padding-top`.\n\t */\n\tkey: string;\n}\n\nexport interface GenerateFunction {\n\t( style: Style, options: StyleOptions ): GeneratedCSSRule[];\n}\n\nexport interface StyleDefinition {\n\tname: string;\n\tgenerate?: GenerateFunction;\n}\n"],"mappings":"","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/style-engine",
3
- "version": "2.32.0",
3
+ "version": "2.32.1-next.b8c8708f3.0",
4
4
  "description": "A suite of parsers and compilers for WordPress styles.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -26,16 +26,23 @@
26
26
  },
27
27
  "main": "build/index.js",
28
28
  "module": "build-module/index.js",
29
+ "exports": {
30
+ ".": {
31
+ "types": "./build-types/index.d.ts",
32
+ "import": "./build-module/index.js",
33
+ "require": "./build/index.js"
34
+ },
35
+ "./package.json": "./package.json"
36
+ },
29
37
  "react-native": "src/index",
30
38
  "wpScript": true,
31
39
  "types": "build-types",
32
40
  "sideEffects": false,
33
41
  "dependencies": {
34
- "@babel/runtime": "7.25.7",
35
42
  "change-case": "^4.1.2"
36
43
  },
37
44
  "publishConfig": {
38
45
  "access": "public"
39
46
  },
40
- "gitHead": "a030b4c0e0695239b942c7dc18511782b64f10ed"
47
+ "gitHead": "67cfd7e661931aeb0d06bec894599d287a4f8d0f"
41
48
  }