@wordpress/theme 0.1.0 → 0.1.1-next.2f1c7c01b.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 (142) hide show
  1. package/README.md +69 -9
  2. package/bin/generate-default-ramps/index.ts +49 -0
  3. package/bin/generate-primitive-tokens/index.ts +14 -9
  4. package/bin/terrazzo-plugin-figma-ds-token-manager/index.ts +11 -4
  5. package/build/color-ramps/index.js +21 -39
  6. package/build/color-ramps/index.js.map +3 -3
  7. package/build/color-ramps/lib/color-utils.js +39 -0
  8. package/build/color-ramps/lib/color-utils.js.map +7 -0
  9. package/build/color-ramps/lib/constants.js +18 -25
  10. package/build/color-ramps/lib/constants.js.map +3 -3
  11. package/build/color-ramps/lib/default-ramps.js +220 -0
  12. package/build/color-ramps/lib/default-ramps.js.map +7 -0
  13. package/build/color-ramps/lib/find-color-with-constraints.js +57 -71
  14. package/build/color-ramps/lib/find-color-with-constraints.js.map +3 -3
  15. package/build/color-ramps/lib/index.js +25 -68
  16. package/build/color-ramps/lib/index.js.map +3 -3
  17. package/build/color-ramps/lib/ramp-configs.js +12 -11
  18. package/build/color-ramps/lib/ramp-configs.js.map +1 -1
  19. package/build/color-ramps/lib/register-color-spaces.js +7 -0
  20. package/build/color-ramps/lib/register-color-spaces.js.map +7 -0
  21. package/build/color-ramps/lib/taper-chroma.js +35 -27
  22. package/build/color-ramps/lib/taper-chroma.js.map +3 -3
  23. package/build/color-ramps/lib/types.js +2 -1
  24. package/build/color-ramps/lib/types.js.map +1 -1
  25. package/build/color-ramps/lib/utils.js +12 -9
  26. package/build/color-ramps/lib/utils.js.map +2 -2
  27. package/build/context.js +3 -2
  28. package/build/context.js.map +1 -1
  29. package/build/index.js +2 -1
  30. package/build/index.js.map +1 -1
  31. package/build/lock-unlock.js +3 -2
  32. package/build/lock-unlock.js.map +1 -1
  33. package/build/prebuilt/js/design-tokens.js +14 -1
  34. package/build/prebuilt/js/design-tokens.js.map +2 -2
  35. package/build/prebuilt/json/figma.json +214 -32
  36. package/build/prebuilt/ts/design-tokens.js +38 -1
  37. package/build/prebuilt/ts/design-tokens.js.map +2 -2
  38. package/build/private-apis.js +3 -2
  39. package/build/private-apis.js.map +1 -1
  40. package/build/theme-provider.js +19 -17
  41. package/build/theme-provider.js.map +4 -4
  42. package/build/types/css-modules.d.js +0 -1
  43. package/build/types.js +2 -1
  44. package/build/types.js.map +1 -1
  45. package/build/use-theme-provider-styles.js +50 -36
  46. package/build/use-theme-provider-styles.js.map +3 -3
  47. package/build-module/color-ramps/index.js +20 -28
  48. package/build-module/color-ramps/index.js.map +2 -2
  49. package/build-module/color-ramps/lib/color-utils.js +19 -0
  50. package/build-module/color-ramps/lib/color-utils.js.map +7 -0
  51. package/build-module/color-ramps/lib/constants.js +13 -10
  52. package/build-module/color-ramps/lib/constants.js.map +2 -2
  53. package/build-module/color-ramps/lib/default-ramps.js +196 -0
  54. package/build-module/color-ramps/lib/default-ramps.js.map +7 -0
  55. package/build-module/color-ramps/lib/find-color-with-constraints.js +56 -60
  56. package/build-module/color-ramps/lib/find-color-with-constraints.js.map +2 -2
  57. package/build-module/color-ramps/lib/index.js +28 -55
  58. package/build-module/color-ramps/lib/index.js.map +3 -3
  59. package/build-module/color-ramps/lib/ramp-configs.js +11 -10
  60. package/build-module/color-ramps/lib/ramp-configs.js.map +1 -1
  61. package/build-module/color-ramps/lib/register-color-spaces.js +7 -0
  62. package/build-module/color-ramps/lib/register-color-spaces.js.map +7 -0
  63. package/build-module/color-ramps/lib/taper-chroma.js +40 -16
  64. package/build-module/color-ramps/lib/taper-chroma.js.map +2 -2
  65. package/build-module/color-ramps/lib/utils.js +7 -4
  66. package/build-module/color-ramps/lib/utils.js.map +2 -2
  67. package/build-module/context.js +2 -1
  68. package/build-module/context.js.map +1 -1
  69. package/build-module/index.js +1 -0
  70. package/build-module/index.js.map +1 -1
  71. package/build-module/lock-unlock.js +2 -1
  72. package/build-module/lock-unlock.js.map +1 -1
  73. package/build-module/prebuilt/js/design-tokens.js +13 -0
  74. package/build-module/prebuilt/js/design-tokens.js.map +2 -2
  75. package/build-module/prebuilt/json/figma.json +214 -32
  76. package/build-module/prebuilt/ts/design-tokens.js +37 -0
  77. package/build-module/prebuilt/ts/design-tokens.js.map +2 -2
  78. package/build-module/private-apis.js +2 -1
  79. package/build-module/private-apis.js.map +1 -1
  80. package/build-module/theme-provider.js +18 -6
  81. package/build-module/theme-provider.js.map +3 -3
  82. package/build-module/use-theme-provider-styles.js +52 -31
  83. package/build-module/use-theme-provider-styles.js.map +2 -2
  84. package/build-types/color-ramps/index.d.ts +9 -16
  85. package/build-types/color-ramps/index.d.ts.map +1 -1
  86. package/build-types/color-ramps/lib/color-utils.d.ts +22 -0
  87. package/build-types/color-ramps/lib/color-utils.d.ts.map +1 -0
  88. package/build-types/color-ramps/lib/constants.d.ts +6 -8
  89. package/build-types/color-ramps/lib/constants.d.ts.map +1 -1
  90. package/build-types/color-ramps/lib/default-ramps.d.ts +7 -0
  91. package/build-types/color-ramps/lib/default-ramps.d.ts.map +1 -0
  92. package/build-types/color-ramps/lib/find-color-with-constraints.d.ts +7 -5
  93. package/build-types/color-ramps/lib/find-color-with-constraints.d.ts.map +1 -1
  94. package/build-types/color-ramps/lib/index.d.ts +5 -2
  95. package/build-types/color-ramps/lib/index.d.ts.map +1 -1
  96. package/build-types/color-ramps/lib/register-color-spaces.d.ts +2 -0
  97. package/build-types/color-ramps/lib/register-color-spaces.d.ts.map +1 -0
  98. package/build-types/color-ramps/lib/taper-chroma.d.ts +7 -3
  99. package/build-types/color-ramps/lib/taper-chroma.d.ts.map +1 -1
  100. package/build-types/color-ramps/lib/utils.d.ts +7 -3
  101. package/build-types/color-ramps/lib/utils.d.ts.map +1 -1
  102. package/build-types/color-ramps/stories/index.story.d.ts.map +1 -1
  103. package/build-types/prebuilt/ts/design-tokens.d.ts.map +1 -1
  104. package/build-types/use-theme-provider-styles.d.ts +4 -0
  105. package/build-types/use-theme-provider-styles.d.ts.map +1 -1
  106. package/docs/ds-tokens.md +34 -0
  107. package/package.json +19 -9
  108. package/src/color-ramps/index.ts +24 -41
  109. package/src/color-ramps/lib/color-utils.ts +34 -0
  110. package/src/color-ramps/lib/constants.ts +8 -6
  111. package/src/color-ramps/lib/default-ramps.ts +200 -0
  112. package/src/color-ramps/lib/find-color-with-constraints.ts +70 -79
  113. package/src/color-ramps/lib/index.ts +27 -61
  114. package/src/color-ramps/lib/register-color-spaces.ts +13 -0
  115. package/src/color-ramps/lib/taper-chroma.ts +47 -19
  116. package/src/color-ramps/lib/utils.ts +8 -9
  117. package/src/color-ramps/stories/index.story.tsx +16 -22
  118. package/src/color-ramps/test/__snapshots__/index.test.ts.snap +96 -96
  119. package/src/color-ramps/test/index.test.ts +27 -15
  120. package/src/prebuilt/css/design-tokens.css +90 -32
  121. package/src/prebuilt/js/design-tokens.js +12 -0
  122. package/src/prebuilt/json/figma.json +214 -32
  123. package/src/prebuilt/ts/design-tokens.ts +36 -0
  124. package/src/use-theme-provider-styles.ts +47 -25
  125. package/tokens/color.json +184 -32
  126. package/tsconfig.bin.json +13 -0
  127. package/tsconfig.bin.tsbuildinfo +1 -0
  128. package/tsconfig.json +6 -4
  129. package/tsconfig.src.json +9 -0
  130. package/tsconfig.src.tsbuildinfo +1 -0
  131. package/bin/build-tokens.js +0 -83
  132. package/build/color-ramps/lib/cache-utils.js +0 -57
  133. package/build/color-ramps/lib/cache-utils.js.map +0 -7
  134. package/build/style.module.css.js +0 -2
  135. package/build-module/color-ramps/lib/cache-utils.js +0 -31
  136. package/build-module/color-ramps/lib/cache-utils.js.map +0 -7
  137. package/build-module/style.module.css.js +0 -1
  138. package/build-style/style.css +0 -3
  139. package/build-types/color-ramps/lib/cache-utils.d.ts +0 -22
  140. package/build-types/color-ramps/lib/cache-utils.d.ts.map +0 -1
  141. package/src/color-ramps/lib/cache-utils.ts +0 -56
  142. package/tsconfig.tsbuildinfo +0 -1
@@ -1,9 +1,6 @@
1
- "use strict";
2
- var __create = Object.create;
3
1
  var __defProp = Object.defineProperty;
4
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
5
  var __export = (target, all) => {
9
6
  for (var name in all)
@@ -17,25 +14,30 @@ var __copyProps = (to, from, except, desc) => {
17
14
  }
18
15
  return to;
19
16
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // packages/theme/src/theme-provider.tsx
29
20
  var theme_provider_exports = {};
30
21
  __export(theme_provider_exports, {
31
22
  ThemeProvider: () => ThemeProvider
32
23
  });
33
24
  module.exports = __toCommonJS(theme_provider_exports);
34
- var import_jsx_runtime = require("react/jsx-runtime");
35
25
  var import_element = require("@wordpress/element");
36
26
  var import_context = require("./context");
37
27
  var import_use_theme_provider_styles = require("./use-theme-provider-styles");
38
- var import_style = __toESM(require("./style.module.css"));
28
+
29
+ // packages/theme/src/style.module.css
30
+ var css = `.style-module__root__26kw6 {
31
+ display: contents;
32
+ }
33
+ `;
34
+ document.head.appendChild(document.createElement("style")).appendChild(document.createTextNode(css));
35
+ var style_default = {
36
+ "root": "style-module__root__26kw6"
37
+ };
38
+
39
+ // packages/theme/src/theme-provider.tsx
40
+ var import_jsx_runtime = require("react/jsx-runtime");
39
41
  function cssObjectToText(values) {
40
42
  return Object.entries(values).map(([key, value]) => `${key}: ${value};`).join("");
41
43
  }
@@ -48,13 +50,13 @@ function generateCSSSelector({
48
50
  const selectors = [];
49
51
  if (isRoot) {
50
52
  selectors.push(
51
- `:root:has(.${import_style.default.root}${rootSel}${instanceIdSel})`
53
+ `:root:has(.${style_default.root}${rootSel}${instanceIdSel})`
52
54
  );
53
55
  }
54
- selectors.push(`.${import_style.default.root}.${import_style.default.root}${instanceIdSel}`);
56
+ selectors.push(`.${style_default.root}.${style_default.root}${instanceIdSel}`);
55
57
  return selectors.join(",");
56
58
  }
57
- const ThemeProvider = ({
59
+ var ThemeProvider = ({
58
60
  children,
59
61
  color = {},
60
62
  isRoot = false
@@ -79,7 +81,7 @@ const ThemeProvider = ({
79
81
  {
80
82
  "data-wpds-theme-provider-id": instanceId,
81
83
  "data-wpds-root-provider": isRoot,
82
- className: import_style.default.root,
84
+ className: style_default.root,
83
85
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_context.ThemeContext.Provider, { value: contextValue, children })
84
86
  }
85
87
  )
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/theme-provider.tsx"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\nimport type { CSSProperties } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useMemo, useId } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { ThemeContext } from './context';\nimport { useThemeProviderStyles } from './use-theme-provider-styles';\nimport { type ThemeProviderProps } from './types';\nimport styles from './style.module.css';\n\nfunction cssObjectToText( values: CSSProperties ) {\n\treturn Object.entries( values )\n\t\t.map( ( [ key, value ] ) => `${ key }: ${ value };` )\n\t\t.join( '' );\n}\n\nfunction generateCSSSelector( {\n\tinstanceId,\n\tisRoot,\n}: {\n\tinstanceId: string;\n\tisRoot: boolean;\n} ) {\n\tconst rootSel = `[data-wpds-root-provider=\"true\"]`;\n\tconst instanceIdSel = `[data-wpds-theme-provider-id=\"${ instanceId }\"]`;\n\n\tconst selectors = [];\n\n\tif ( isRoot ) {\n\t\tselectors.push(\n\t\t\t`:root:has(.${ styles.root }${ rootSel }${ instanceIdSel })`\n\t\t);\n\t}\n\n\tselectors.push( `.${ styles.root }.${ styles.root }${ instanceIdSel }` );\n\n\treturn selectors.join( ',' );\n}\n\nexport const ThemeProvider = ( {\n\tchildren,\n\tcolor = {},\n\tisRoot = false,\n}: ThemeProviderProps ) => {\n\tconst instanceId = useId();\n\n\tconst { themeProviderStyles, resolvedSettings } = useThemeProviderStyles( {\n\t\tcolor,\n\t} );\n\n\tconst contextValue = useMemo(\n\t\t() => ( {\n\t\t\tresolvedSettings,\n\t\t} ),\n\t\t[ resolvedSettings ]\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t{ themeProviderStyles ? (\n\t\t\t\t<style>\n\t\t\t\t\t{ `${ generateCSSSelector( {\n\t\t\t\t\t\tinstanceId,\n\t\t\t\t\t\tisRoot,\n\t\t\t\t\t} ) } {${ cssObjectToText( themeProviderStyles ) }}` }\n\t\t\t\t</style>\n\t\t\t) : null }\n\t\t\t<div\n\t\t\t\tdata-wpds-theme-provider-id={ instanceId }\n\t\t\t\tdata-wpds-root-provider={ isRoot }\n\t\t\t\tclassName={ styles.root }\n\t\t\t>\n\t\t\t\t<ThemeContext.Provider value={ contextValue }>\n\t\t\t\t\t{ children }\n\t\t\t\t</ThemeContext.Provider>\n\t\t\t</div>\n\t\t</>\n\t);\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkEE;AA1DF,qBAA+B;AAK/B,qBAA6B;AAC7B,uCAAuC;AAEvC,mBAAmB;AAEnB,SAAS,gBAAiB,QAAwB;AACjD,SAAO,OAAO,QAAS,MAAO,EAC5B,IAAK,CAAE,CAAE,KAAK,KAAM,MAAO,GAAI,GAAI,KAAM,KAAM,GAAI,EACnD,KAAM,EAAG;AACZ;AAEA,SAAS,oBAAqB;AAAA,EAC7B;AAAA,EACA;AACD,GAGI;AACH,QAAM,UAAU;AAChB,QAAM,gBAAgB,iCAAkC,UAAW;AAEnE,QAAM,YAAY,CAAC;AAEnB,MAAK,QAAS;AACb,cAAU;AAAA,MACT,cAAe,aAAAA,QAAO,IAAK,GAAI,OAAQ,GAAI,aAAc;AAAA,IAC1D;AAAA,EACD;AAEA,YAAU,KAAM,IAAK,aAAAA,QAAO,IAAK,IAAK,aAAAA,QAAO,IAAK,GAAI,aAAc,EAAG;AAEvE,SAAO,UAAU,KAAM,GAAI;AAC5B;AAEO,MAAM,gBAAgB,CAAE;AAAA,EAC9B;AAAA,EACA,QAAQ,CAAC;AAAA,EACT,SAAS;AACV,MAA2B;AAC1B,QAAM,iBAAa,sBAAM;AAEzB,QAAM,EAAE,qBAAqB,iBAAiB,QAAI,yDAAwB;AAAA,IACzE;AAAA,EACD,CAAE;AAEF,QAAM,mBAAe;AAAA,IACpB,OAAQ;AAAA,MACP;AAAA,IACD;AAAA,IACA,CAAE,gBAAiB;AAAA,EACpB;AAEA,SACC,4EACG;AAAA,0BACD,4CAAC,WACE,aAAI,oBAAqB;AAAA,MAC1B;AAAA,MACA;AAAA,IACD,CAAE,CAAE,KAAM,gBAAiB,mBAAoB,CAAE,KAClD,IACG;AAAA,IACJ;AAAA,MAAC;AAAA;AAAA,QACA,+BAA8B;AAAA,QAC9B,2BAA0B;AAAA,QAC1B,WAAY,aAAAA,QAAO;AAAA,QAEnB,sDAAC,4BAAa,UAAb,EAAsB,OAAQ,cAC5B,UACH;AAAA;AAAA,IACD;AAAA,KACD;AAEF;",
6
- "names": ["styles"]
3
+ "sources": ["../src/theme-provider.tsx", "../src/style.module.css"],
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport type { CSSProperties } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useMemo, useId } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { ThemeContext } from './context';\nimport { useThemeProviderStyles } from './use-theme-provider-styles';\nimport { type ThemeProviderProps } from './types';\nimport styles from './style.module.css';\n\nfunction cssObjectToText( values: CSSProperties ) {\n\treturn Object.entries( values )\n\t\t.map( ( [ key, value ] ) => `${ key }: ${ value };` )\n\t\t.join( '' );\n}\n\nfunction generateCSSSelector( {\n\tinstanceId,\n\tisRoot,\n}: {\n\tinstanceId: string;\n\tisRoot: boolean;\n} ) {\n\tconst rootSel = `[data-wpds-root-provider=\"true\"]`;\n\tconst instanceIdSel = `[data-wpds-theme-provider-id=\"${ instanceId }\"]`;\n\n\tconst selectors = [];\n\n\tif ( isRoot ) {\n\t\tselectors.push(\n\t\t\t`:root:has(.${ styles.root }${ rootSel }${ instanceIdSel })`\n\t\t);\n\t}\n\n\tselectors.push( `.${ styles.root }.${ styles.root }${ instanceIdSel }` );\n\n\treturn selectors.join( ',' );\n}\n\nexport const ThemeProvider = ( {\n\tchildren,\n\tcolor = {},\n\tisRoot = false,\n}: ThemeProviderProps ) => {\n\tconst instanceId = useId();\n\n\tconst { themeProviderStyles, resolvedSettings } = useThemeProviderStyles( {\n\t\tcolor,\n\t} );\n\n\tconst contextValue = useMemo(\n\t\t() => ( {\n\t\t\tresolvedSettings,\n\t\t} ),\n\t\t[ resolvedSettings ]\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t{ themeProviderStyles ? (\n\t\t\t\t<style>\n\t\t\t\t\t{ `${ generateCSSSelector( {\n\t\t\t\t\t\tinstanceId,\n\t\t\t\t\t\tisRoot,\n\t\t\t\t\t} ) } {${ cssObjectToText( themeProviderStyles ) }}` }\n\t\t\t\t</style>\n\t\t\t) : null }\n\t\t\t<div\n\t\t\t\tdata-wpds-theme-provider-id={ instanceId }\n\t\t\t\tdata-wpds-root-provider={ isRoot }\n\t\t\t\tclassName={ styles.root }\n\t\t\t>\n\t\t\t\t<ThemeContext.Provider value={ contextValue }>\n\t\t\t\t\t{ children }\n\t\t\t\t</ThemeContext.Provider>\n\t\t\t</div>\n\t\t</>\n\t);\n};\n", "const css = `.style-module__root__26kw6 {\n\tdisplay: contents;\n}\n`;\ndocument.head\n .appendChild(document.createElement(\"style\"))\n .appendChild(document.createTextNode(css));\nexport {css};\nexport default {\n \"root\": \"style-module__root__26kw6\"\n};"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,qBAA+B;AAK/B,qBAA6B;AAC7B,uCAAuC;;;ACdvC,IAAM,MAAM;AAAA;AAAA;AAAA;AAIZ,SAAS,KACJ,YAAY,SAAS,cAAc,OAAO,CAAC,EAC3C,YAAY,SAAS,eAAe,GAAG,CAAC;AAE7C,IAAO,gBAAQ;AAAA,EACb,QAAQ;AACV;;;ADwDE;AAhDF,SAAS,gBAAiB,QAAwB;AACjD,SAAO,OAAO,QAAS,MAAO,EAC5B,IAAK,CAAE,CAAE,KAAK,KAAM,MAAO,GAAI,GAAI,KAAM,KAAM,GAAI,EACnD,KAAM,EAAG;AACZ;AAEA,SAAS,oBAAqB;AAAA,EAC7B;AAAA,EACA;AACD,GAGI;AACH,QAAM,UAAU;AAChB,QAAM,gBAAgB,iCAAkC,UAAW;AAEnE,QAAM,YAAY,CAAC;AAEnB,MAAK,QAAS;AACb,cAAU;AAAA,MACT,cAAe,cAAO,IAAK,GAAI,OAAQ,GAAI,aAAc;AAAA,IAC1D;AAAA,EACD;AAEA,YAAU,KAAM,IAAK,cAAO,IAAK,IAAK,cAAO,IAAK,GAAI,aAAc,EAAG;AAEvE,SAAO,UAAU,KAAM,GAAI;AAC5B;AAEO,IAAM,gBAAgB,CAAE;AAAA,EAC9B;AAAA,EACA,QAAQ,CAAC;AAAA,EACT,SAAS;AACV,MAA2B;AAC1B,QAAM,iBAAa,sBAAM;AAEzB,QAAM,EAAE,qBAAqB,iBAAiB,QAAI,yDAAwB;AAAA,IACzE;AAAA,EACD,CAAE;AAEF,QAAM,mBAAe;AAAA,IACpB,OAAQ;AAAA,MACP;AAAA,IACD;AAAA,IACA,CAAE,gBAAiB;AAAA,EACpB;AAEA,SACC,4EACG;AAAA,0BACD,4CAAC,WACE,aAAI,oBAAqB;AAAA,MAC1B;AAAA,MACA;AAAA,IACD,CAAE,CAAE,KAAM,gBAAiB,mBAAoB,CAAE,KAClD,IACG;AAAA,IACJ;AAAA,MAAC;AAAA;AAAA,QACA,+BAA8B;AAAA,QAC9B,2BAA0B;AAAA,QAC1B,WAAY,cAAO;AAAA,QAEnB,sDAAC,4BAAa,UAAb,EAAsB,OAAQ,cAC5B,UACH;AAAA;AAAA,IACD;AAAA,KACD;AAEF;",
6
+ "names": []
7
7
  }
@@ -1,2 +1 @@
1
- "use strict";
2
1
  //# sourceMappingURL=css-modules.d.js.map
package/build/types.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __defProp = Object.defineProperty;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -12,6 +11,8 @@ var __copyProps = (to, from, except, desc) => {
12
11
  return to;
13
12
  };
14
13
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+
15
+ // packages/theme/src/types.ts
15
16
  var types_exports = {};
16
17
  module.exports = __toCommonJS(types_exports);
17
18
  //# sourceMappingURL=types.js.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/types.ts"],
4
4
  "sourcesContent": ["/**\n * External dependencies\n */\nimport { type ReactNode } from 'react';\n\nexport interface ThemeProviderSettings {\n\t/**\n\t * The set of color options to apply to the theme.\n\t */\n\tcolor?: {\n\t\t/**\n\t\t * The primary seed color to use for the theme.\n\t\t *\n\t\t * By default, it inherits from parent `ThemeProvider`,\n\t\t * and fallbacks to statically built CSS.\n\t\t */\n\t\tprimary?: string;\n\t\t/**\n\t\t * The background seed color to use for the theme.\n\t\t *\n\t\t * By default, it inherits from parent `ThemeProvider`,\n\t\t * and fallbacks to statically built CSS.\n\t\t */\n\t\tbg?: string;\n\t};\n}\n\nexport interface ThemeProviderProps extends ThemeProviderSettings {\n\t/**\n\t * The children to render.\n\t */\n\tchildren?: ReactNode;\n\n\t/**\n\t * When a ThemeProvider is the root provider, it will apply its theming\n\t * settings also to the root document element (e.g. the html element).\n\t * This is useful, for example, to make sure that the `html` element can\n\t * consume the right background color, or that overlays rendered inside a\n\t * portal can inherit the correct color scheme.\n\t *\n\t * @default false\n\t */\n\tisRoot?: boolean;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
5
+ "mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;",
6
6
  "names": []
7
7
  }
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -9,13 +8,13 @@ var __export = (target, all) => {
9
8
  for (var name in all)
10
9
  __defProp(target, name, { get: all[name], enumerable: true });
11
10
  };
12
- var __copyProps = (to, from, except, desc) => {
11
+ var __copyProps = (to2, from, except, desc) => {
13
12
  if (from && typeof from === "object" || typeof from === "function") {
14
13
  for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ if (!__hasOwnProp.call(to2, key) && key !== except)
15
+ __defProp(to2, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
16
  }
18
- return to;
17
+ return to2;
19
18
  };
20
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
20
  // If the importer is in node compatibility mode or this is not an ESM
@@ -26,17 +25,23 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
25
  mod
27
26
  ));
28
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // packages/theme/src/use-theme-provider-styles.ts
29
30
  var use_theme_provider_styles_exports = {};
30
31
  __export(use_theme_provider_styles_exports, {
31
32
  useThemeProviderStyles: () => useThemeProviderStyles
32
33
  });
33
34
  module.exports = __toCommonJS(use_theme_provider_styles_exports);
34
- var import_colorjs = __toESM(require("colorjs.io"));
35
+ var import_fn = require("colorjs.io/fn");
36
+ var import_memize = __toESM(require("memize"));
35
37
  var import_element = require("@wordpress/element");
38
+ var import_register_color_spaces = require("./color-ramps/lib/register-color-spaces");
36
39
  var import_context = require("./context");
37
40
  var import_design_tokens = __toESM(require("./prebuilt/ts/design-tokens"));
38
41
  var import_color_ramps = require("./color-ramps");
39
- const legacyWpComponentsOverridesCSS = [
42
+ var getCachedBgRamp = (0, import_memize.default)(import_color_ramps.buildBgRamp, { maxSize: 10 });
43
+ var getCachedAccentRamp = (0, import_memize.default)(import_color_ramps.buildAccentRamp, { maxSize: 10 });
44
+ var legacyWpComponentsOverridesCSS = [
40
45
  ["--wp-components-color-accent", "var(--wp-admin-theme-color)"],
41
46
  [
42
47
  "--wp-components-color-accent-darker-10",
@@ -92,37 +97,49 @@ const legacyWpComponentsOverridesCSS = [
92
97
  ]
93
98
  ];
94
99
  function customRgbFormat(color) {
95
- const rgb = color.to("srgb");
96
- return [rgb.r, rgb.g, rgb.b].map((n) => Math.round(n * 255)).join(", ");
100
+ const rgb = (0, import_fn.to)(color, import_fn.sRGB);
101
+ return [(0, import_fn.get)(rgb, "srgb.r"), (0, import_fn.get)(rgb, "srgb.g"), (0, import_fn.get)(rgb, "srgb.b")].map((n) => Math.round(n * 255)).join(", ");
97
102
  }
98
103
  function legacyWpAdminThemeOverridesCSS(accent) {
99
- const parsedAccent = new import_colorjs.default(accent).to("hsl");
100
- const hsl = parsedAccent.coords;
101
- const darker10 = new import_colorjs.default("hsl", [
102
- hsl[0],
103
- // h
104
- hsl[1],
105
- // s
106
- Math.max(0, Math.min(100, hsl[2] - 5))
107
- // l (reduced by 5%)
108
- ]).to("srgb");
109
- const darker20 = new import_colorjs.default("hsl", [
110
- hsl[0],
111
- // h
112
- hsl[1],
113
- // s
114
- Math.max(0, Math.min(100, hsl[2] - 10))
115
- // l (reduced by 10%)
116
- ]).to("srgb");
104
+ const parsedAccent = (0, import_fn.to)((0, import_fn.parse)(accent), import_fn.HSL);
105
+ const coords = parsedAccent.coords;
106
+ const darker10 = (0, import_fn.to)(
107
+ {
108
+ space: import_fn.HSL,
109
+ coords: [
110
+ coords[0],
111
+ // h
112
+ coords[1],
113
+ // s
114
+ Math.max(0, Math.min(100, coords[2] - 5))
115
+ // l (reduced by 5%)
116
+ ]
117
+ },
118
+ import_fn.sRGB
119
+ );
120
+ const darker20 = (0, import_fn.to)(
121
+ {
122
+ space: import_fn.HSL,
123
+ coords: [
124
+ coords[0],
125
+ // h
126
+ coords[1],
127
+ // s
128
+ Math.max(0, Math.min(100, coords[2] - 10))
129
+ // l (reduced by 10%)
130
+ ]
131
+ },
132
+ import_fn.sRGB
133
+ );
117
134
  return [
118
135
  [
119
136
  "--wp-admin-theme-color",
120
- parsedAccent.to("srgb").toString({ format: "hex" })
137
+ (0, import_fn.serialize)((0, import_fn.to)(parsedAccent, import_fn.sRGB), { format: "hex" })
121
138
  ],
122
139
  ["--wp-admin-theme-color--rgb", customRgbFormat(parsedAccent)],
123
140
  [
124
141
  "--wp-admin-theme-color-darker-10",
125
- darker10.toString({ format: "hex" })
142
+ (0, import_fn.serialize)(darker10, { format: "hex" })
126
143
  ],
127
144
  [
128
145
  "--wp-admin-theme-color-darker-10--rgb",
@@ -130,7 +147,7 @@ function legacyWpAdminThemeOverridesCSS(accent) {
130
147
  ],
131
148
  [
132
149
  "--wp-admin-theme-color-darker-20",
133
- darker20.toString({ format: "hex" })
150
+ (0, import_fn.serialize)(darker20, { format: "hex" })
134
151
  ],
135
152
  [
136
153
  "--wp-admin-theme-color-darker-20--rgb",
@@ -144,7 +161,7 @@ function semanticTokensCSS(filterFn = () => true) {
144
161
  modesAndValues["."]
145
162
  ]);
146
163
  }
147
- const toKebabCase = (str) => str.replace(
164
+ var toKebabCase = (str) => str.replace(
148
165
  /[A-Z]+(?![a-z])|[A-Z]/g,
149
166
  ($, ofs) => (ofs ? "-" : "") + $.toLowerCase()
150
167
  );
@@ -199,17 +216,14 @@ function useThemeProviderStyles({
199
216
  primary
200
217
  };
201
218
  const computedColorRamps = /* @__PURE__ */ new Map();
202
- const bgRamp = (0, import_color_ramps.buildBgRamp)({ seed: seeds.bg });
219
+ const bgRamp = getCachedBgRamp(seeds.bg);
203
220
  Object.entries(seeds).forEach(([rampName, seed]) => {
204
221
  if (rampName === "bg") {
205
222
  computedColorRamps.set(rampName, bgRamp);
206
223
  } else {
207
224
  computedColorRamps.set(
208
225
  rampName,
209
- (0, import_color_ramps.buildAccentRamp)({
210
- seed,
211
- bgRamp
212
- })
226
+ getCachedAccentRamp(seed, bgRamp)
213
227
  );
214
228
  }
215
229
  });
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/use-theme-provider-styles.ts"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\nimport type { CSSProperties } from 'react';\nimport Color from 'colorjs.io';\n\n/**\n * WordPress dependencies\n */\nimport { useMemo, useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { ThemeContext } from './context';\nimport semanticVariables from './prebuilt/ts/design-tokens';\nimport {\n\tbuildBgRamp,\n\tbuildAccentRamp,\n\tDEFAULT_SEED_COLORS,\n\ttype RampResult,\n} from './color-ramps';\nimport type { ThemeProviderProps } from './types';\n\ntype Entry = [ string, string ];\n\nconst legacyWpComponentsOverridesCSS: Entry[] = [\n\t[ '--wp-components-color-accent', 'var(--wp-admin-theme-color)' ],\n\t[\n\t\t'--wp-components-color-accent-darker-10',\n\t\t'var(--wp-admin-theme-color-darker-10)',\n\t],\n\t[\n\t\t'--wp-components-color-accent-darker-20',\n\t\t'var(--wp-admin-theme-color-darker-20)',\n\t],\n\t[\n\t\t'--wp-components-color-accent-inverted',\n\t\t'var(--wpds-color-fg-interactive-brand-strong)',\n\t],\n\t[\n\t\t'--wp-components-color-background',\n\t\t'var(--wpds-color-bg-surface-neutral-strong)',\n\t],\n\t[\n\t\t'--wp-components-color-foreground',\n\t\t'var(--wpds-color-fg-content-neutral)',\n\t],\n\t[\n\t\t'--wp-components-color-foreground-inverted',\n\t\t'var(--wpds-color-bg-surface-neutral)',\n\t],\n\t[\n\t\t'--wp-components-color-gray-100',\n\t\t'var(--wpds-color-bg-surface-neutral)',\n\t],\n\t[\n\t\t'--wp-components-color-gray-200',\n\t\t'var(--wpds-color-stroke-surface-neutral)',\n\t],\n\t[\n\t\t'--wp-components-color-gray-300',\n\t\t'var(--wpds-color-stroke-surface-neutral)',\n\t],\n\t[\n\t\t'--wp-components-color-gray-400',\n\t\t'var(--wpds-color-stroke-interactive-neutral)',\n\t],\n\t[\n\t\t'--wp-components-color-gray-600',\n\t\t'var(--wpds-color-stroke-interactive-neutral)',\n\t],\n\t[\n\t\t'--wp-components-color-gray-700',\n\t\t'var(--wpds-color-fg-content-neutral-weak)',\n\t],\n\t[\n\t\t'--wp-components-color-gray-800',\n\t\t'var(--wpds-color-fg-content-neutral)',\n\t],\n];\n\nfunction customRgbFormat( color: Color ) {\n\tconst rgb = color.to( 'srgb' );\n\treturn [ rgb.r, rgb.g, rgb.b ]\n\t\t.map( ( n ) => Math.round( n * 255 ) )\n\t\t.join( ', ' );\n}\n\nfunction legacyWpAdminThemeOverridesCSS( accent: string ): Entry[] {\n\tconst parsedAccent = new Color( accent ).to( 'hsl' );\n\n\tconst hsl = parsedAccent.coords;\n\tconst darker10 = new Color( 'hsl', [\n\t\thsl[ 0 ], // h\n\t\thsl[ 1 ], // s\n\t\tMath.max( 0, Math.min( 100, hsl[ 2 ] - 5 ) ), // l (reduced by 5%)\n\t] ).to( 'srgb' );\n\tconst darker20 = new Color( 'hsl', [\n\t\thsl[ 0 ], // h\n\t\thsl[ 1 ], // s\n\t\tMath.max( 0, Math.min( 100, hsl[ 2 ] - 10 ) ), // l (reduced by 10%)\n\t] ).to( 'srgb' );\n\n\treturn [\n\t\t[\n\t\t\t'--wp-admin-theme-color',\n\t\t\tparsedAccent.to( 'srgb' ).toString( { format: 'hex' } ),\n\t\t],\n\t\t[ '--wp-admin-theme-color--rgb', customRgbFormat( parsedAccent ) ],\n\t\t[\n\t\t\t'--wp-admin-theme-color-darker-10',\n\t\t\tdarker10.toString( { format: 'hex' } ),\n\t\t],\n\t\t[\n\t\t\t'--wp-admin-theme-color-darker-10--rgb',\n\t\t\tcustomRgbFormat( darker10 ),\n\t\t],\n\t\t[\n\t\t\t'--wp-admin-theme-color-darker-20',\n\t\t\tdarker20.toString( { format: 'hex' } ),\n\t\t],\n\t\t[\n\t\t\t'--wp-admin-theme-color-darker-20--rgb',\n\t\t\tcustomRgbFormat( darker20 ),\n\t\t],\n\t];\n}\n\nfunction semanticTokensCSS(\n\tfilterFn: ( entry: [ string, Record< string, string > ] ) => boolean = () =>\n\t\ttrue\n): Entry[] {\n\treturn Object.entries( semanticVariables )\n\t\t.filter( filterFn )\n\t\t.map( ( [ variableName, modesAndValues ] ) => [\n\t\t\tvariableName,\n\t\t\tmodesAndValues[ '.' ],\n\t\t] );\n}\n\nconst toKebabCase = ( str: string ) =>\n\tstr.replace(\n\t\t/[A-Z]+(?![a-z])|[A-Z]/g,\n\t\t( $, ofs ) => ( ofs ? '-' : '' ) + $.toLowerCase()\n\t);\n\nfunction colorRampCSS( ramp: RampResult, prefix: string ): Entry[] {\n\treturn [ ...Object.entries( ramp.ramp ) ].map(\n\t\t( [ tokenName, tokenValue ] ) => [\n\t\t\t`${ prefix }${ toKebabCase( tokenName ) }`,\n\t\t\ttokenValue.color,\n\t\t]\n\t);\n}\n\nfunction generateStyles( {\n\tprimary,\n\tcomputedColorRamps,\n}: {\n\tprimary: string;\n\tcomputedColorRamps: Map< string, RampResult >;\n} ): CSSProperties {\n\treturn Object.fromEntries(\n\t\t[\n\t\t\t// Primitive tokens\n\t\t\tArray.from( computedColorRamps )\n\t\t\t\t.map( ( [ rampName, computedColorRamp ] ) => [\n\t\t\t\t\tcolorRampCSS(\n\t\t\t\t\t\tcomputedColorRamp,\n\t\t\t\t\t\t`--wpds-color-private-${ rampName }-`\n\t\t\t\t\t),\n\t\t\t\t] )\n\t\t\t\t.flat( 2 ),\n\t\t\t// Semantic color tokens (other semantic tokens for now are static)\n\t\t\tsemanticTokensCSS( ( [ key ] ) => /color/.test( key ) ),\n\t\t\t// Legacy overrides\n\t\t\tlegacyWpAdminThemeOverridesCSS( primary ),\n\t\t\tlegacyWpComponentsOverridesCSS,\n\t\t].flat()\n\t);\n}\n\nexport function useThemeProviderStyles( {\n\tcolor = {},\n}: {\n\tcolor?: ThemeProviderProps[ 'color' ];\n} = {} ) {\n\tconst { resolvedSettings: inheritedSettings } = useContext( ThemeContext );\n\n\t// Compute settings:\n\t// - used provided prop value;\n\t// - otherwise, use inherited value from parent instance;\n\t// - otherwise, use fallback value (where applicable).\n\tconst primary =\n\t\tcolor.primary ??\n\t\tinheritedSettings.color?.primary ??\n\t\tDEFAULT_SEED_COLORS.primary;\n\tconst bg =\n\t\tcolor.bg ?? inheritedSettings.color?.bg ?? DEFAULT_SEED_COLORS.bg;\n\n\tconst resolvedSettings = useMemo(\n\t\t() => ( {\n\t\t\tcolor: {\n\t\t\t\tprimary,\n\t\t\t\tbg,\n\t\t\t},\n\t\t} ),\n\t\t[ primary, bg ]\n\t);\n\n\tconst themeProviderStyles = useMemo( () => {\n\t\t// Determine which seeds are needed for generating ramps.\n\t\tconst seeds = {\n\t\t\t...DEFAULT_SEED_COLORS,\n\t\t\tbg,\n\t\t\tprimary,\n\t\t};\n\n\t\t// Generate ramps.\n\t\tconst computedColorRamps = new Map< string, RampResult >();\n\t\tconst bgRamp = buildBgRamp( { seed: seeds.bg } );\n\t\tObject.entries( seeds ).forEach( ( [ rampName, seed ] ) => {\n\t\t\tif ( rampName === 'bg' ) {\n\t\t\t\tcomputedColorRamps.set( rampName, bgRamp );\n\t\t\t} else {\n\t\t\t\tcomputedColorRamps.set(\n\t\t\t\t\trampName,\n\t\t\t\t\tbuildAccentRamp( {\n\t\t\t\t\t\tseed,\n\t\t\t\t\t\tbgRamp,\n\t\t\t\t\t} )\n\t\t\t\t);\n\t\t\t}\n\t\t} );\n\n\t\treturn generateStyles( {\n\t\t\tprimary: seeds.primary,\n\t\t\tcomputedColorRamps,\n\t\t} );\n\t}, [ primary, bg ] );\n\n\treturn {\n\t\tresolvedSettings,\n\t\tthemeProviderStyles,\n\t};\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,qBAAkB;AAKlB,qBAAoC;AAKpC,qBAA6B;AAC7B,2BAA8B;AAC9B,yBAKO;AAKP,MAAM,iCAA0C;AAAA,EAC/C,CAAE,gCAAgC,6BAA8B;AAAA,EAChE;AAAA,IACC;AAAA,IACA;AAAA,EACD;AAAA,EACA;AAAA,IACC;AAAA,IACA;AAAA,EACD;AAAA,EACA;AAAA,IACC;AAAA,IACA;AAAA,EACD;AAAA,EACA;AAAA,IACC;AAAA,IACA;AAAA,EACD;AAAA,EACA;AAAA,IACC;AAAA,IACA;AAAA,EACD;AAAA,EACA;AAAA,IACC;AAAA,IACA;AAAA,EACD;AAAA,EACA;AAAA,IACC;AAAA,IACA;AAAA,EACD;AAAA,EACA;AAAA,IACC;AAAA,IACA;AAAA,EACD;AAAA,EACA;AAAA,IACC;AAAA,IACA;AAAA,EACD;AAAA,EACA;AAAA,IACC;AAAA,IACA;AAAA,EACD;AAAA,EACA;AAAA,IACC;AAAA,IACA;AAAA,EACD;AAAA,EACA;AAAA,IACC;AAAA,IACA;AAAA,EACD;AAAA,EACA;AAAA,IACC;AAAA,IACA;AAAA,EACD;AACD;AAEA,SAAS,gBAAiB,OAAe;AACxC,QAAM,MAAM,MAAM,GAAI,MAAO;AAC7B,SAAO,CAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAAE,EAC3B,IAAK,CAAE,MAAO,KAAK,MAAO,IAAI,GAAI,CAAE,EACpC,KAAM,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,IACD;AAGA,UAAM,qBAAqB,oBAAI,IAA0B;AACzD,UAAM,aAAS,gCAAa,EAAE,MAAM,MAAM,GAAG,CAAE;AAC/C,WAAO,QAAS,KAAM,EAAE,QAAS,CAAE,CAAE,UAAU,IAAK,MAAO;AAC1D,UAAK,aAAa,MAAO;AACxB,2BAAmB,IAAK,UAAU,MAAO;AAAA,MAC1C,OAAO;AACN,2BAAmB;AAAA,UAClB;AAAA,cACA,oCAAiB;AAAA,YAChB;AAAA,YACA;AAAA,UACD,CAAE;AAAA,QACH;AAAA,MACD;AAAA,IACD,CAAE;AAEF,WAAO,eAAgB;AAAA,MACtB,SAAS,MAAM;AAAA,MACf;AAAA,IACD,CAAE;AAAA,EACH,GAAG,CAAE,SAAS,EAAG,CAAE;AAEnB,SAAO;AAAA,IACN;AAAA,IACA;AAAA,EACD;AACD;",
6
- "names": ["Color", "semanticVariables"]
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport type { CSSProperties } from 'react';\nimport {\n\tparse,\n\tto,\n\tget,\n\tserialize,\n\tsRGB,\n\tHSL,\n\ttype ColorTypes,\n} from 'colorjs.io/fn';\nimport memoize from 'memize';\n\n/**\n * WordPress dependencies\n */\nimport { useMemo, useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport './color-ramps/lib/register-color-spaces';\nimport { ThemeContext } from './context';\nimport semanticVariables from './prebuilt/ts/design-tokens';\nimport {\n\tbuildBgRamp,\n\tbuildAccentRamp,\n\tDEFAULT_SEED_COLORS,\n\ttype RampResult,\n} from './color-ramps';\nimport type { ThemeProviderProps } from './types';\n\ntype Entry = [ string, string ];\n\nconst getCachedBgRamp = memoize( buildBgRamp, { maxSize: 10 } );\nconst getCachedAccentRamp = memoize( buildAccentRamp, { maxSize: 10 } );\n\nconst legacyWpComponentsOverridesCSS: Entry[] = [\n\t[ '--wp-components-color-accent', 'var(--wp-admin-theme-color)' ],\n\t[\n\t\t'--wp-components-color-accent-darker-10',\n\t\t'var(--wp-admin-theme-color-darker-10)',\n\t],\n\t[\n\t\t'--wp-components-color-accent-darker-20',\n\t\t'var(--wp-admin-theme-color-darker-20)',\n\t],\n\t[\n\t\t'--wp-components-color-accent-inverted',\n\t\t'var(--wpds-color-fg-interactive-brand-strong)',\n\t],\n\t[\n\t\t'--wp-components-color-background',\n\t\t'var(--wpds-color-bg-surface-neutral-strong)',\n\t],\n\t[\n\t\t'--wp-components-color-foreground',\n\t\t'var(--wpds-color-fg-content-neutral)',\n\t],\n\t[\n\t\t'--wp-components-color-foreground-inverted',\n\t\t'var(--wpds-color-bg-surface-neutral)',\n\t],\n\t[\n\t\t'--wp-components-color-gray-100',\n\t\t'var(--wpds-color-bg-surface-neutral)',\n\t],\n\t[\n\t\t'--wp-components-color-gray-200',\n\t\t'var(--wpds-color-stroke-surface-neutral)',\n\t],\n\t[\n\t\t'--wp-components-color-gray-300',\n\t\t'var(--wpds-color-stroke-surface-neutral)',\n\t],\n\t[\n\t\t'--wp-components-color-gray-400',\n\t\t'var(--wpds-color-stroke-interactive-neutral)',\n\t],\n\t[\n\t\t'--wp-components-color-gray-600',\n\t\t'var(--wpds-color-stroke-interactive-neutral)',\n\t],\n\t[\n\t\t'--wp-components-color-gray-700',\n\t\t'var(--wpds-color-fg-content-neutral-weak)',\n\t],\n\t[\n\t\t'--wp-components-color-gray-800',\n\t\t'var(--wpds-color-fg-content-neutral)',\n\t],\n];\n\nfunction customRgbFormat( color: ColorTypes ) {\n\tconst rgb = to( color, sRGB );\n\treturn [ get( rgb, 'srgb.r' ), get( rgb, 'srgb.g' ), get( rgb, 'srgb.b' ) ]\n\t\t.map( ( n ) => Math.round( n * 255 ) )\n\t\t.join( ', ' );\n}\n\nfunction legacyWpAdminThemeOverridesCSS( accent: string ): Entry[] {\n\tconst parsedAccent = to( parse( accent ), HSL );\n\n\tconst coords = parsedAccent.coords;\n\tconst darker10 = to(\n\t\t{\n\t\t\tspace: HSL,\n\t\t\tcoords: [\n\t\t\t\tcoords[ 0 ], // h\n\t\t\t\tcoords[ 1 ], // s\n\t\t\t\tMath.max( 0, Math.min( 100, coords[ 2 ] - 5 ) ), // l (reduced by 5%)\n\t\t\t],\n\t\t},\n\t\tsRGB\n\t);\n\tconst darker20 = to(\n\t\t{\n\t\t\tspace: HSL,\n\t\t\tcoords: [\n\t\t\t\tcoords[ 0 ], // h\n\t\t\t\tcoords[ 1 ], // s\n\t\t\t\tMath.max( 0, Math.min( 100, coords[ 2 ] - 10 ) ), // l (reduced by 10%)\n\t\t\t],\n\t\t},\n\t\tsRGB\n\t);\n\n\treturn [\n\t\t[\n\t\t\t'--wp-admin-theme-color',\n\t\t\tserialize( to( parsedAccent, sRGB ), { format: 'hex' } ),\n\t\t],\n\t\t[ '--wp-admin-theme-color--rgb', customRgbFormat( parsedAccent ) ],\n\t\t[\n\t\t\t'--wp-admin-theme-color-darker-10',\n\t\t\tserialize( darker10, { format: 'hex' } ),\n\t\t],\n\t\t[\n\t\t\t'--wp-admin-theme-color-darker-10--rgb',\n\t\t\tcustomRgbFormat( darker10 ),\n\t\t],\n\t\t[\n\t\t\t'--wp-admin-theme-color-darker-20',\n\t\t\tserialize( darker20, { format: 'hex' } ),\n\t\t],\n\t\t[\n\t\t\t'--wp-admin-theme-color-darker-20--rgb',\n\t\t\tcustomRgbFormat( darker20 ),\n\t\t],\n\t];\n}\n\nfunction semanticTokensCSS(\n\tfilterFn: ( entry: [ string, Record< string, string > ] ) => boolean = () =>\n\t\ttrue\n): Entry[] {\n\treturn Object.entries( semanticVariables )\n\t\t.filter( filterFn )\n\t\t.map( ( [ variableName, modesAndValues ] ) => [\n\t\t\tvariableName,\n\t\t\tmodesAndValues[ '.' ],\n\t\t] );\n}\n\nconst toKebabCase = ( str: string ) =>\n\tstr.replace(\n\t\t/[A-Z]+(?![a-z])|[A-Z]/g,\n\t\t( $, ofs ) => ( ofs ? '-' : '' ) + $.toLowerCase()\n\t);\n\nfunction colorRampCSS( ramp: RampResult, prefix: string ): Entry[] {\n\treturn [ ...Object.entries( ramp.ramp ) ].map(\n\t\t( [ tokenName, tokenValue ] ) => [\n\t\t\t`${ prefix }${ toKebabCase( tokenName ) }`,\n\t\t\ttokenValue.color,\n\t\t]\n\t);\n}\n\nfunction generateStyles( {\n\tprimary,\n\tcomputedColorRamps,\n}: {\n\tprimary: string;\n\tcomputedColorRamps: Map< string, RampResult >;\n} ): CSSProperties {\n\treturn Object.fromEntries(\n\t\t[\n\t\t\t// Primitive tokens\n\t\t\tArray.from( computedColorRamps )\n\t\t\t\t.map( ( [ rampName, computedColorRamp ] ) => [\n\t\t\t\t\tcolorRampCSS(\n\t\t\t\t\t\tcomputedColorRamp,\n\t\t\t\t\t\t`--wpds-color-private-${ rampName }-`\n\t\t\t\t\t),\n\t\t\t\t] )\n\t\t\t\t.flat( 2 ),\n\t\t\t// Semantic color tokens (other semantic tokens for now are static)\n\t\t\tsemanticTokensCSS( ( [ key ] ) => /color/.test( key ) ),\n\t\t\t// Legacy overrides\n\t\t\tlegacyWpAdminThemeOverridesCSS( primary ),\n\t\t\tlegacyWpComponentsOverridesCSS,\n\t\t].flat()\n\t);\n}\n\nexport function useThemeProviderStyles( {\n\tcolor = {},\n}: {\n\tcolor?: ThemeProviderProps[ 'color' ];\n} = {} ) {\n\tconst { resolvedSettings: inheritedSettings } = useContext( ThemeContext );\n\n\t// Compute settings:\n\t// - used provided prop value;\n\t// - otherwise, use inherited value from parent instance;\n\t// - otherwise, use fallback value (where applicable).\n\tconst primary =\n\t\tcolor.primary ??\n\t\tinheritedSettings.color?.primary ??\n\t\tDEFAULT_SEED_COLORS.primary;\n\tconst bg =\n\t\tcolor.bg ?? inheritedSettings.color?.bg ?? DEFAULT_SEED_COLORS.bg;\n\n\tconst resolvedSettings = useMemo(\n\t\t() => ( {\n\t\t\tcolor: {\n\t\t\t\tprimary,\n\t\t\t\tbg,\n\t\t\t},\n\t\t} ),\n\t\t[ primary, bg ]\n\t);\n\n\tconst themeProviderStyles = useMemo( () => {\n\t\t// Determine which seeds are needed for generating ramps.\n\t\tconst seeds = {\n\t\t\t...DEFAULT_SEED_COLORS,\n\t\t\tbg,\n\t\t\tprimary,\n\t\t};\n\n\t\t// Generate ramps.\n\t\tconst computedColorRamps = new Map< string, RampResult >();\n\t\tconst bgRamp = getCachedBgRamp( seeds.bg );\n\t\tObject.entries( seeds ).forEach( ( [ rampName, seed ] ) => {\n\t\t\tif ( rampName === 'bg' ) {\n\t\t\t\tcomputedColorRamps.set( rampName, bgRamp );\n\t\t\t} else {\n\t\t\t\tcomputedColorRamps.set(\n\t\t\t\t\trampName,\n\t\t\t\t\tgetCachedAccentRamp( seed, bgRamp )\n\t\t\t\t);\n\t\t\t}\n\t\t} );\n\n\t\treturn generateStyles( {\n\t\t\tprimary: seeds.primary,\n\t\t\tcomputedColorRamps,\n\t\t} );\n\t}, [ primary, bg ] );\n\n\treturn {\n\t\tresolvedSettings,\n\t\tthemeProviderStyles,\n\t};\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,gBAQO;AACP,oBAAoB;AAKpB,qBAAoC;AAKpC,mCAAO;AACP,qBAA6B;AAC7B,2BAA8B;AAC9B,yBAKO;AAKP,IAAM,sBAAkB,cAAAA,SAAS,gCAAa,EAAE,SAAS,GAAG,CAAE;AAC9D,IAAM,0BAAsB,cAAAA,SAAS,oCAAiB,EAAE,SAAS,GAAG,CAAE;AAEtE,IAAM,iCAA0C;AAAA,EAC/C,CAAE,gCAAgC,6BAA8B;AAAA,EAChE;AAAA,IACC;AAAA,IACA;AAAA,EACD;AAAA,EACA;AAAA,IACC;AAAA,IACA;AAAA,EACD;AAAA,EACA;AAAA,IACC;AAAA,IACA;AAAA,EACD;AAAA,EACA;AAAA,IACC;AAAA,IACA;AAAA,EACD;AAAA,EACA;AAAA,IACC;AAAA,IACA;AAAA,EACD;AAAA,EACA;AAAA,IACC;AAAA,IACA;AAAA,EACD;AAAA,EACA;AAAA,IACC;AAA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E;AAAA;AAAA,MAEtD,+BAAgC,OAAQ;AAAA,MACxC;AAAA,IACD,EAAE,KAAK;AAAA,EACR;AACD;AAEO,SAAS,uBAAwB;AAAA,EACvC,QAAQ,CAAC;AACV,IAEI,CAAC,GAAI;AACR,QAAM,EAAE,kBAAkB,kBAAkB,QAAI,2BAAY,2BAAa;AAMzE,QAAM,UACL,MAAM,WACN,kBAAkB,OAAO,WACzB,uCAAoB;AACrB,QAAM,KACL,MAAM,MAAM,kBAAkB,OAAO,MAAM,uCAAoB;AAEhE,QAAM,uBAAmB;AAAA,IACxB,OAAQ;AAAA,MACP,OAAO;AAAA,QACN;AAAA,QACA;AAAA,MACD;AAAA,IACD;AAAA,IACA,CAAE,SAAS,EAAG;AAAA,EACf;AAEA,QAAM,0BAAsB,wBAAS,MAAM;AAE1C,UAAM,QAAQ;AAAA,MACb,GAAG;AAAA,MACH;AAAA,MACA;AAAA,IACD;AAGA,UAAM,qBAAqB,oBAAI,IAA0B;AACzD,UAAM,SAAS,gBAAiB,MAAM,EAAG;AACzC,WAAO,QAAS,KAAM,EAAE,QAAS,CAAE,CAAE,UAAU,IAAK,MAAO;AAC1D,UAAK,aAAa,MAAO;AACxB,2BAAmB,IAAK,UAAU,MAAO;AAAA,MAC1C,OAAO;AACN,2BAAmB;AAAA,UAClB;AAAA,UACA,oBAAqB,MAAM,MAAO;AAAA,QACnC;AAAA,MACD;AAAA,IACD,CAAE;AAEF,WAAO,eAAgB;AAAA,MACtB,SAAS,MAAM;AAAA,MACf;AAAA,IACD,CAAE;AAAA,EACH,GAAG,CAAE,SAAS,EAAG,CAAE;AAEnB,SAAO;AAAA,IACN;AAAA,IACA;AAAA,EACD;AACD;",
6
+ "names": ["memoize", "semanticVariables"]
7
7
  }
@@ -1,45 +1,37 @@
1
- import Color from "colorjs.io";
1
+ // packages/theme/src/color-ramps/index.ts
2
+ import { get, OKLCH, parse, serialize } from "colorjs.io/fn";
3
+ import "./lib/register-color-spaces";
2
4
  import { buildRamp } from "./lib/index";
3
5
  import { clampAccentScaleReferenceLightness } from "./lib/utils";
4
6
  import { BG_RAMP_CONFIG, ACCENT_RAMP_CONFIG } from "./lib/ramp-configs";
5
- import { getCachedContrast } from "./lib/cache-utils";
7
+ import { getContrast } from "./lib/color-utils";
6
8
  import { CONTRAST_COMBINATIONS } from "./lib/constants";
7
9
  import { DEFAULT_SEED_COLORS } from "./lib/constants";
8
- function buildBgRamp({
9
- seed,
10
- debug
11
- }) {
10
+ function buildBgRamp(seed) {
12
11
  if (typeof seed !== "string" || seed.trim() === "") {
13
12
  throw new Error("Seed color must be a non-empty string");
14
13
  }
15
- return buildRamp(seed, BG_RAMP_CONFIG, { debug });
14
+ return buildRamp(seed, BG_RAMP_CONFIG);
16
15
  }
17
- const STEP_TO_PIN = "surface2";
16
+ var STEP_TO_PIN = "surface2";
18
17
  function getBgRampInfo(ramp) {
19
18
  return {
20
19
  mainDirection: ramp.direction,
21
20
  pinLightness: {
22
21
  stepName: STEP_TO_PIN,
23
22
  value: clampAccentScaleReferenceLightness(
24
- new Color(ramp.ramp[STEP_TO_PIN].color).oklch.l,
23
+ get(parse(ramp.ramp[STEP_TO_PIN].color), [OKLCH, "l"]),
25
24
  ramp.direction
26
25
  )
27
26
  }
28
27
  };
29
28
  }
30
- function buildAccentRamp({
31
- seed,
32
- bgRamp,
33
- debug
34
- }) {
29
+ function buildAccentRamp(seed, bgRamp) {
35
30
  if (typeof seed !== "string" || seed.trim() === "") {
36
31
  throw new Error("Seed color must be a non-empty string");
37
32
  }
38
33
  const bgRampInfo = bgRamp ? getBgRampInfo(bgRamp) : void 0;
39
- return buildRamp(seed, ACCENT_RAMP_CONFIG, {
40
- ...bgRampInfo,
41
- debug
42
- });
34
+ return buildRamp(seed, ACCENT_RAMP_CONFIG, bgRampInfo);
43
35
  }
44
36
  function checkAccessibleCombinations({
45
37
  bgRamp,
@@ -50,14 +42,14 @@ function checkAccessibleCombinations({
50
42
  CONTRAST_COMBINATIONS.forEach(({ bgs, fgs, target }) => {
51
43
  for (const bg of bgs) {
52
44
  for (const fg of fgs) {
53
- const bgColor = new Color(ramp.ramp[bg].color);
54
- const fgColor = new Color(ramp.ramp[fg].color);
55
- if (getCachedContrast(bgColor, fgColor) < target) {
45
+ const bgColor = parse(ramp.ramp[bg].color);
46
+ const fgColor = parse(ramp.ramp[fg].color);
47
+ if (getContrast(bgColor, fgColor) < target) {
56
48
  unmetTargets.push({
57
49
  bgName: bg,
58
- bgColor: bgColor.toString(),
50
+ bgColor: serialize(bgColor),
59
51
  fgName: fg,
60
- fgColor: fgColor.toString(),
52
+ fgColor: serialize(fgColor),
61
53
  unmetContrast: target
62
54
  });
63
55
  }
@@ -69,14 +61,14 @@ function checkAccessibleCombinations({
69
61
  CONTRAST_COMBINATIONS.forEach(({ bgs, fgs, target }) => {
70
62
  for (const bg of bgs) {
71
63
  for (const fg of fgs) {
72
- const bgColor = new Color(bgRamp.ramp[bg].color);
73
- const fgColor = new Color(ramp.ramp[fg].color);
74
- if (getCachedContrast(bgColor, fgColor) < target) {
64
+ const bgColor = parse(bgRamp.ramp[bg].color);
65
+ const fgColor = parse(ramp.ramp[fg].color);
66
+ if (getContrast(bgColor, fgColor) < target) {
75
67
  unmetTargets.push({
76
68
  bgName: bg,
77
- bgColor: bgColor.toString(),
69
+ bgColor: serialize(bgColor),
78
70
  fgName: fg,
79
- fgColor: fgColor.toString(),
71
+ fgColor: serialize(fgColor),
80
72
  unmetContrast: target
81
73
  });
82
74
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/color-ramps/index.ts"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\nimport Color from 'colorjs.io';\n\n/**\n * Internal dependencies\n */\nimport { buildRamp } from './lib/index';\nimport { clampAccentScaleReferenceLightness } from './lib/utils';\nimport { BG_RAMP_CONFIG, ACCENT_RAMP_CONFIG } from './lib/ramp-configs';\nimport type {\n\tRampResult as InternalRampResult,\n\tRampDirection,\n\tRamp,\n} from './lib/types';\nimport { getCachedContrast } from './lib/cache-utils';\nimport { CONTRAST_COMBINATIONS } from './lib/constants';\nexport { DEFAULT_SEED_COLORS } from './lib/constants';\n\n/**\n * Creates a background ramp.\n * @param params\n * @param params.seed\n * @param params.debug\n */\nexport function buildBgRamp( {\n\tseed,\n\tdebug,\n}: {\n\tseed: string;\n\tdebug?: boolean;\n} ): InternalRampResult {\n\tif ( typeof seed !== 'string' || seed.trim() === '' ) {\n\t\tthrow new Error( 'Seed color must be a non-empty string' );\n\t}\n\n\treturn buildRamp( seed, BG_RAMP_CONFIG, { debug } );\n}\n\nconst STEP_TO_PIN = 'surface2';\nfunction getBgRampInfo( ramp: InternalRampResult ): {\n\tmainDirection: RampDirection;\n\tpinLightness: {\n\t\tstepName: keyof Ramp;\n\t\tvalue: number;\n\t};\n} {\n\treturn {\n\t\tmainDirection: ramp.direction,\n\t\tpinLightness: {\n\t\t\tstepName: STEP_TO_PIN,\n\t\t\tvalue: clampAccentScaleReferenceLightness(\n\t\t\t\tnew Color( ramp.ramp[ STEP_TO_PIN ].color ).oklch.l,\n\t\t\t\tramp.direction\n\t\t\t),\n\t\t},\n\t};\n}\n\n/**\n * Creates an accent ramp (ie used by primary, success, info, warning and error\n * ramps).\n * @param params\n * @param params.seed\n * @param params.bgRamp\n * @param params.debug\n */\nexport function buildAccentRamp( {\n\tseed,\n\tbgRamp,\n\tdebug,\n}: {\n\tseed: string;\n\tbgRamp?: InternalRampResult;\n\tdebug?: boolean;\n} ): InternalRampResult {\n\tif ( typeof seed !== 'string' || seed.trim() === '' ) {\n\t\tthrow new Error( 'Seed color must be a non-empty string' );\n\t}\n\n\tconst bgRampInfo = bgRamp ? getBgRampInfo( bgRamp ) : undefined;\n\treturn buildRamp( seed, ACCENT_RAMP_CONFIG, {\n\t\t...bgRampInfo,\n\t\tdebug,\n\t} );\n}\n\n/**\n * Checks that all bg/fg combinations generated by the ramps meet contrast\n * targets.\n * @param params\n * @param params.bgRamp\n * @param params.accentRamps\n */\nexport function checkAccessibleCombinations( {\n\tbgRamp,\n\taccentRamps = [],\n}: {\n\tbgRamp: InternalRampResult;\n\taccentRamps?: InternalRampResult[];\n} ) {\n\tconst unmetTargets: {\n\t\tbgName: keyof Ramp;\n\t\tbgColor: string;\n\t\tfgName: keyof Ramp;\n\t\tfgColor: string;\n\t\tunmetContrast: number;\n\t}[] = [];\n\n\t// Assess combinations within each ramp\n\t[ bgRamp, ...accentRamps ].forEach( ( ramp ) => {\n\t\tCONTRAST_COMBINATIONS.forEach( ( { bgs, fgs, target } ) => {\n\t\t\tfor ( const bg of bgs ) {\n\t\t\t\tfor ( const fg of fgs ) {\n\t\t\t\t\tconst bgColor = new Color( ramp.ramp[ bg ].color );\n\t\t\t\t\tconst fgColor = new Color( ramp.ramp[ fg ].color );\n\t\t\t\t\tif ( getCachedContrast( bgColor, fgColor ) < target ) {\n\t\t\t\t\t\tunmetTargets.push( {\n\t\t\t\t\t\t\tbgName: bg,\n\t\t\t\t\t\t\tbgColor: bgColor.toString(),\n\t\t\t\t\t\t\tfgName: fg,\n\t\t\t\t\t\t\tfgColor: fgColor.toString(),\n\t\t\t\t\t\t\tunmetContrast: target,\n\t\t\t\t\t\t} );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} );\n\t} );\n\t// Assess each accent ramp's fg color against bg ramp\n\taccentRamps.forEach( ( ramp ) => {\n\t\tCONTRAST_COMBINATIONS.forEach( ( { bgs, fgs, target } ) => {\n\t\t\tfor ( const bg of bgs ) {\n\t\t\t\tfor ( const fg of fgs ) {\n\t\t\t\t\tconst bgColor = new Color( bgRamp.ramp[ bg ].color );\n\t\t\t\t\tconst fgColor = new Color( ramp.ramp[ fg ].color );\n\t\t\t\t\tif ( getCachedContrast( bgColor, fgColor ) < target ) {\n\t\t\t\t\t\tunmetTargets.push( {\n\t\t\t\t\t\t\tbgName: bg,\n\t\t\t\t\t\t\tbgColor: bgColor.toString(),\n\t\t\t\t\t\t\tfgName: fg,\n\t\t\t\t\t\t\tfgColor: fgColor.toString(),\n\t\t\t\t\t\t\tunmetContrast: target,\n\t\t\t\t\t\t} );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} );\n\t} );\n\n\treturn unmetTargets;\n}\n\nexport type RampResult = InternalRampResult;\n"],
5
- "mappings": "AAGA,OAAO,WAAW;AAKlB,SAAS,iBAAiB;AAC1B,SAAS,0CAA0C;AACnD,SAAS,gBAAgB,0BAA0B;AAMnD,SAAS,yBAAyB;AAClC,SAAS,6BAA6B;AACtC,SAAS,2BAA2B;AAQ7B,SAAS,YAAa;AAAA,EAC5B;AAAA,EACA;AACD,GAGwB;AACvB,MAAK,OAAO,SAAS,YAAY,KAAK,KAAK,MAAM,IAAK;AACrD,UAAM,IAAI,MAAO,uCAAwC;AAAA,EAC1D;AAEA,SAAO,UAAW,MAAM,gBAAgB,EAAE,MAAM,CAAE;AACnD;AAEA,MAAM,cAAc;AACpB,SAAS,cAAe,MAMtB;AACD,SAAO;AAAA,IACN,eAAe,KAAK;AAAA,IACpB,cAAc;AAAA,MACb,UAAU;AAAA,MACV,OAAO;AAAA,QACN,IAAI,MAAO,KAAK,KAAM,WAAY,EAAE,KAAM,EAAE,MAAM;AAAA,QAClD,KAAK;AAAA,MACN;AAAA,IACD;AAAA,EACD;AACD;AAUO,SAAS,gBAAiB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AACD,GAIwB;AACvB,MAAK,OAAO,SAAS,YAAY,KAAK,KAAK,MAAM,IAAK;AACrD,UAAM,IAAI,MAAO,uCAAwC;AAAA,EAC1D;AAEA,QAAM,aAAa,SAAS,cAAe,MAAO,IAAI;AACtD,SAAO,UAAW,MAAM,oBAAoB;AAAA,IAC3C,GAAG;AAAA,IACH;AAAA,EACD,CAAE;AACH;AASO,SAAS,4BAA6B;AAAA,EAC5C;AAAA,EACA,cAAc,CAAC;AAChB,GAGI;AACH,QAAM,eAMA,CAAC;AAGP,GAAE,QAAQ,GAAG,WAAY,EAAE,QAAS,CAAE,SAAU;AAC/C,0BAAsB,QAAS,CAAE,EAAE,KAAK,KAAK,OAAO,MAAO;AAC1D,iBAAY,MAAM,KAAM;AACvB,mBAAY,MAAM,KAAM;AACvB,gBAAM,UAAU,IAAI,MAAO,KAAK,KAAM,EAAG,EAAE,KAAM;AACjD,gBAAM,UAAU,IAAI,MAAO,KAAK,KAAM,EAAG,EAAE,KAAM;AACjD,cAAK,kBAAmB,SAAS,OAAQ,IAAI,QAAS;AACrD,yBAAa,KAAM;AAAA,cAClB,QAAQ;AAAA,cACR,SAAS,QAAQ,SAAS;AAAA,cAC1B,QAAQ;AAAA,cACR,SAAS,QAAQ,SAAS;AAAA,cAC1B,eAAe;AAAA,YAChB,CAAE;AAAA,UACH;AAAA,QACD;AAAA,MACD;AAAA,IACD,CAAE;AAAA,EACH,CAAE;AAEF,cAAY,QAAS,CAAE,SAAU;AAChC,0BAAsB,QAAS,CAAE,EAAE,KAAK,KAAK,OAAO,MAAO;AAC1D,iBAAY,MAAM,KAAM;AACvB,mBAAY,MAAM,KAAM;AACvB,gBAAM,UAAU,IAAI,MAAO,OAAO,KAAM,EAAG,EAAE,KAAM;AACnD,gBAAM,UAAU,IAAI,MAAO,KAAK,KAAM,EAAG,EAAE,KAAM;AACjD,cAAK,kBAAmB,SAAS,OAAQ,IAAI,QAAS;AACrD,yBAAa,KAAM;AAAA,cAClB,QAAQ;AAAA,cACR,SAAS,QAAQ,SAAS;AAAA,cAC1B,QAAQ;AAAA,cACR,SAAS,QAAQ,SAAS;AAAA,cAC1B,eAAe;AAAA,YAChB,CAAE;AAAA,UACH;AAAA,QACD;AAAA,MACD;AAAA,IACD,CAAE;AAAA,EACH,CAAE;AAEF,SAAO;AACR;",
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport { get, OKLCH, parse, serialize } from 'colorjs.io/fn';\n\n/**\n * Internal dependencies\n */\nimport './lib/register-color-spaces';\nimport { buildRamp } from './lib/index';\nimport { clampAccentScaleReferenceLightness } from './lib/utils';\nimport { BG_RAMP_CONFIG, ACCENT_RAMP_CONFIG } from './lib/ramp-configs';\nimport type {\n\tRampResult as InternalRampResult,\n\tRampDirection,\n\tRamp,\n} from './lib/types';\nimport { getContrast } from './lib/color-utils';\nimport { CONTRAST_COMBINATIONS } from './lib/constants';\nexport { DEFAULT_SEED_COLORS } from './lib/constants';\n\n/**\n * Creates a background ramp.\n * @param seed The seed color for the background ramp.\n */\nexport function buildBgRamp( seed: string ) {\n\tif ( typeof seed !== 'string' || seed.trim() === '' ) {\n\t\tthrow new Error( 'Seed color must be a non-empty string' );\n\t}\n\n\treturn buildRamp( seed, BG_RAMP_CONFIG );\n}\n\nconst STEP_TO_PIN = 'surface2';\nfunction getBgRampInfo( ramp: InternalRampResult ): {\n\tmainDirection: RampDirection;\n\tpinLightness: {\n\t\tstepName: keyof Ramp;\n\t\tvalue: number;\n\t};\n} {\n\treturn {\n\t\tmainDirection: ramp.direction,\n\t\tpinLightness: {\n\t\t\tstepName: STEP_TO_PIN,\n\t\t\tvalue: clampAccentScaleReferenceLightness(\n\t\t\t\tget( parse( ramp.ramp[ STEP_TO_PIN ].color ), [ OKLCH, 'l' ] ),\n\t\t\t\tramp.direction\n\t\t\t),\n\t\t},\n\t};\n}\n\n/**\n * Creates an accent ramp (ie used by primary, success, info, warning and error\n * ramps).\n * @param seed The seed color for the accent ramp.\n * @param bgRamp The ramp of the background on which the accent is shown.\n */\nexport function buildAccentRamp(\n\tseed: string,\n\tbgRamp?: InternalRampResult\n): InternalRampResult {\n\tif ( typeof seed !== 'string' || seed.trim() === '' ) {\n\t\tthrow new Error( 'Seed color must be a non-empty string' );\n\t}\n\n\tconst bgRampInfo = bgRamp ? getBgRampInfo( bgRamp ) : undefined;\n\treturn buildRamp( seed, ACCENT_RAMP_CONFIG, bgRampInfo );\n}\n\n/**\n * Checks that all bg/fg combinations generated by the ramps meet contrast\n * targets.\n * @param params\n * @param params.bgRamp\n * @param params.accentRamps\n */\nexport function checkAccessibleCombinations( {\n\tbgRamp,\n\taccentRamps = [],\n}: {\n\tbgRamp: InternalRampResult;\n\taccentRamps?: InternalRampResult[];\n} ) {\n\tconst unmetTargets: {\n\t\tbgName: keyof Ramp;\n\t\tbgColor: string;\n\t\tfgName: keyof Ramp;\n\t\tfgColor: string;\n\t\tunmetContrast: number;\n\t}[] = [];\n\n\t// Assess combinations within each ramp\n\t[ bgRamp, ...accentRamps ].forEach( ( ramp ) => {\n\t\tCONTRAST_COMBINATIONS.forEach( ( { bgs, fgs, target } ) => {\n\t\t\tfor ( const bg of bgs ) {\n\t\t\t\tfor ( const fg of fgs ) {\n\t\t\t\t\tconst bgColor = parse( ramp.ramp[ bg ].color );\n\t\t\t\t\tconst fgColor = parse( ramp.ramp[ fg ].color );\n\t\t\t\t\tif ( getContrast( bgColor, fgColor ) < target ) {\n\t\t\t\t\t\tunmetTargets.push( {\n\t\t\t\t\t\t\tbgName: bg,\n\t\t\t\t\t\t\tbgColor: serialize( bgColor ),\n\t\t\t\t\t\t\tfgName: fg,\n\t\t\t\t\t\t\tfgColor: serialize( fgColor ),\n\t\t\t\t\t\t\tunmetContrast: target,\n\t\t\t\t\t\t} );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} );\n\t} );\n\t// Assess each accent ramp's fg color against bg ramp\n\taccentRamps.forEach( ( ramp ) => {\n\t\tCONTRAST_COMBINATIONS.forEach( ( { bgs, fgs, target } ) => {\n\t\t\tfor ( const bg of bgs ) {\n\t\t\t\tfor ( const fg of fgs ) {\n\t\t\t\t\tconst bgColor = parse( bgRamp.ramp[ bg ].color );\n\t\t\t\t\tconst fgColor = parse( ramp.ramp[ fg ].color );\n\t\t\t\t\tif ( getContrast( bgColor, fgColor ) < target ) {\n\t\t\t\t\t\tunmetTargets.push( {\n\t\t\t\t\t\t\tbgName: bg,\n\t\t\t\t\t\t\tbgColor: serialize( bgColor ),\n\t\t\t\t\t\t\tfgName: fg,\n\t\t\t\t\t\t\tfgColor: serialize( fgColor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M;AACvB,mBAAY,MAAM,KAAM;AACvB,gBAAM,UAAU,MAAO,KAAK,KAAM,EAAG,EAAE,KAAM;AAC7C,gBAAM,UAAU,MAAO,KAAK,KAAM,EAAG,EAAE,KAAM;AAC7C,cAAK,YAAa,SAAS,OAAQ,IAAI,QAAS;AAC/C,yBAAa,KAAM;AAAA,cAClB,QAAQ;AAAA,cACR,SAAS,UAAW,OAAQ;AAAA,cAC5B,QAAQ;AAAA,cACR,SAAS,UAAW,OAAQ;AAAA,cAC5B,eAAe;AAAA,YAChB,CAAE;AAAA,UACH;AAAA,QACD;AAAA,MACD;AAAA,IACD,CAAE;AAAA,EACH,CAAE;AAEF,cAAY,QAAS,CAAE,SAAU;AAChC,0BAAsB,QAAS,CAAE,EAAE,KAAK,KAAK,OAAO,MAAO;AAC1D,iBAAY,MAAM,KAAM;AACvB,mBAAY,MAAM,KAAM;AACvB,gBAAM,UAAU,MAAO,OAAO,KAAM,EAAG,EAAE,KAAM;AAC/C,gBAAM,UAAU,MAAO,KAAK,KAAM,EAAG,EAAE,KAAM;AAC7C,cAAK,YAAa,SAAS,OAAQ,IAAI,QAAS;AAC/C,yBAAa,KAAM;AAAA,cAClB,QAAQ;AAAA,cACR,SAAS,UAAW,OAAQ;AAAA,cAC5B,QAAQ;AAAA,cACR,SAAS,UAAW,OAAQ;AAAA,cAC5B,eAAe;AAAA,YAChB,CAAE;AAAA,UACH;AAAA,QACD;AAAA,MACD;AAAA,IACD,CAAE;AAAA,EACH,CAAE;AAEF,SAAO;AACR;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,19 @@
1
+ // packages/theme/src/color-ramps/lib/color-utils.ts
2
+ import {
3
+ to,
4
+ serialize,
5
+ contrastWCAG21,
6
+ sRGB
7
+ } from "colorjs.io/fn";
8
+ import "./register-color-spaces";
9
+ function getColorString(color) {
10
+ return serialize(to(color, sRGB), { format: "hex", inGamut: true });
11
+ }
12
+ function getContrast(colorA, colorB) {
13
+ return contrastWCAG21(colorA, colorB);
14
+ }
15
+ export {
16
+ getColorString,
17
+ getContrast
18
+ };
19
+ //# sourceMappingURL=color-utils.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/color-ramps/lib/color-utils.ts"],
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport {\n\tto,\n\tserialize,\n\tcontrastWCAG21,\n\tsRGB,\n\ttype ColorTypes,\n} from 'colorjs.io/fn';\n\n/**\n * Internal dependencies\n */\nimport './register-color-spaces';\n\n/**\n * Get string representation of a color\n * @param color Color object to stringify\n * @return String representation\n */\nexport function getColorString( color: ColorTypes ): string {\n\treturn serialize( to( color, sRGB ), { format: 'hex', inGamut: true } );\n}\n\n/**\n * Get contrast value between two colors\n * @param colorA First color\n * @param colorB Second color\n * @return WCAG 2.1 contrast ratio\n */\nexport function getContrast( colorA: ColorTypes, colorB: ColorTypes ): number {\n\treturn contrastWCAG21( colorA, colorB );\n}\n"],
5
+ "mappings": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEM;AAKP,OAAO;AAOA,SAAS,eAAgB,OAA4B;AAC3D,SAAO,UAAW,GAAI,OAAO,IAAK,GAAG,EAAE,QAAQ,OAAO,SAAS,KAAK,CAAE;AACvE;AAQO,SAAS,YAAa,QAAoB,QAA6B;AAC7E,SAAO,eAAgB,QAAQ,MAAO;AACvC;",
6
+ "names": []
7
+ }
@@ -1,15 +1,17 @@
1
- import Color from "colorjs.io";
2
- const WHITE = new Color("#fff").to("oklch");
3
- const BLACK = new Color("#000").to("oklch");
4
- const UNIVERSAL_CONTRAST_TOPUP = 0.05;
5
- const WHITE_TEXT_CONTRAST_MARGIN = 3.1;
6
- const ACCENT_SCALE_BASE_LIGHTNESS_THRESHOLDS = {
1
+ // packages/theme/src/color-ramps/lib/constants.ts
2
+ import { to, OKLCH } from "colorjs.io/fn";
3
+ import "./register-color-spaces";
4
+ var WHITE = to("white", OKLCH);
5
+ var BLACK = to("black", OKLCH);
6
+ var UNIVERSAL_CONTRAST_TOPUP = 0.05;
7
+ var WHITE_TEXT_CONTRAST_MARGIN = 3.1;
8
+ var ACCENT_SCALE_BASE_LIGHTNESS_THRESHOLDS = {
7
9
  lighter: { min: 0.2, max: 0.4 },
8
10
  darker: { min: 0.75, max: 0.98 }
9
11
  };
10
- const LIGHTNESS_EPSILON = 1e-3;
11
- const MAX_BISECTION_ITERATIONS = 25;
12
- const CONTRAST_COMBINATIONS = [
12
+ var LIGHTNESS_EPSILON = 4e-3;
13
+ var MAX_BISECTION_ITERATIONS = 10;
14
+ var CONTRAST_COMBINATIONS = [
13
15
  {
14
16
  bgs: ["surface1", "surface2", "surface3"],
15
17
  fgs: ["fgSurface3", "fgSurface4"],
@@ -41,11 +43,12 @@ const CONTRAST_COMBINATIONS = [
41
43
  target: 3
42
44
  }
43
45
  ];
44
- const DEFAULT_SEED_COLORS = {
46
+ var DEFAULT_SEED_COLORS = {
45
47
  bg: "#f8f8f8",
46
48
  primary: "#3858e9",
47
49
  info: "#0090ff",
48
50
  success: "#4ab866",
51
+ caution: "#f0d149",
49
52
  warning: "#f0b849",
50
53
  error: "#cc1818"
51
54
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/color-ramps/lib/constants.ts"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\nimport Color from 'colorjs.io';\n\n/**\n * Internal dependencies\n */\nimport type { Ramp } from './types';\n\nexport const WHITE = new Color( '#fff' ).to( 'oklch' );\nexport const BLACK = new Color( '#000' ).to( 'oklch' );\n\n// Margin added to target contrasts to counter for algorithm approximations\n// and rounding errors.\nexport const UNIVERSAL_CONTRAST_TOPUP = 0.05;\n\n// When enabling \"lighter direction\" bias, this is the amount by which\n// black text contrast needs to be greater than white text contrast.\n// The higher the value, the stronger the preference for white text.\n// The current value has been determined empirically as the highest value\n// that won't cause the algo not to be able to correctly solve all contrasts.\nexport const WHITE_TEXT_CONTRAST_MARGIN = 3.1;\n\n// These values are used as thresholds when trying to match the background\n// ramp's lightness while calculating an accent ramp. They prevent the accent\n// scale from being pinned to lightness values in the middle of the range,\n// which would cause the algorithm to struggle to satisfy the accent scale\n// constraints and therefore produce unexpected results.\nexport const ACCENT_SCALE_BASE_LIGHTNESS_THRESHOLDS = {\n\tlighter: { min: 0.2, max: 0.4 },\n\tdarker: { min: 0.75, max: 0.98 },\n} as const;\n\n// Minimum lightness difference noticed by the algorithm.\nexport const LIGHTNESS_EPSILON = 1e-3;\n\nexport const MAX_BISECTION_ITERATIONS = 25;\n\nexport const CONTRAST_COMBINATIONS: {\n\tbgs: ( keyof Ramp )[];\n\tfgs: ( keyof Ramp )[];\n\ttarget: number;\n}[] = [\n\t{\n\t\tbgs: [ 'surface1', 'surface2', 'surface3' ],\n\t\tfgs: [ 'fgSurface3', 'fgSurface4' ],\n\t\ttarget: 4.5,\n\t},\n\t{\n\t\tbgs: [ 'surface4', 'surface5' ],\n\t\tfgs: [ 'fgSurface4' ],\n\t\ttarget: 4.5,\n\t},\n\t{\n\t\tbgs: [ 'bgFill1' ],\n\t\tfgs: [ 'fgFill' ],\n\t\ttarget: 4.5,\n\t},\n\t{\n\t\tbgs: [ 'bgFillInverted1' ],\n\t\tfgs: [ 'fgFillInverted' ],\n\t\ttarget: 4.5,\n\t},\n\t{\n\t\tbgs: [ 'bgFillInverted1' ],\n\t\tfgs: [ 'fgFillInverted' ],\n\t\ttarget: 4.5,\n\t},\n\t{\n\t\tbgs: [ 'surface1', 'surface2', 'surface3' ],\n\t\tfgs: [ 'stroke3' ],\n\t\ttarget: 3,\n\t},\n];\n\n// Used when generating the DTCG tokens and the static color ramps.\nexport const DEFAULT_SEED_COLORS = {\n\tbg: '#f8f8f8',\n\tprimary: '#3858e9',\n\tinfo: '#0090ff',\n\tsuccess: '#4ab866',\n\twarning: '#f0b849',\n\terror: '#cc1818',\n};\n"],
5
- "mappings": "AAGA,OAAO,WAAW;AAOX,MAAM,QAAQ,IAAI,MAAO,MAAO,EAAE,GAAI,OAAQ;AAC9C,MAAM,QAAQ,IAAI,MAAO,MAAO,EAAE,GAAI,OAAQ;AAI9C,MAAM,2BAA2B;AAOjC,MAAM,6BAA6B;AAOnC,MAAM,yCAAyC;AAAA,EACrD,SAAS,EAAE,KAAK,KAAK,KAAK,IAAI;AAAA,EAC9B,QAAQ,EAAE,KAAK,MAAM,KAAK,KAAK;AAChC;AAGO,MAAM,oBAAoB;AAE1B,MAAM,2BAA2B;AAEjC,MAAM,wBAIP;AAAA,EACL;AAAA,IACC,KAAK,CAAE,YAAY,YAAY,UAAW;AAAA,IAC1C,KAAK,CAAE,cAAc,YAAa;AAAA,IAClC,QAAQ;AAAA,EACT;AAAA,EACA;AAAA,IACC,KAAK,CAAE,YAAY,UAAW;AAAA,IAC9B,KAAK,CAAE,YAAa;AAAA,IACpB,QAAQ;AAAA,EACT;AAAA,EACA;AAAA,IACC,KAAK,CAAE,SAAU;AAAA,IACjB,KAAK,CAAE,QAAS;AAAA,IAChB,QAAQ;AAAA,EACT;AAAA,EACA;AAAA,IACC,KAAK,CAAE,iBAAkB;AAAA,IACzB,KAAK,CAAE,gBAAiB;AAAA,IACxB,QAAQ;AAAA,EACT;AAAA,EACA;AAAA,IACC,KAAK,CAAE,iBAAkB;AAAA,IACzB,KAAK,CAAE,gBAAiB;AAAA,IACxB,QAAQ;AAAA,EACT;AAAA,EACA;AAAA,IACC,KAAK,CAAE,YAAY,YAAY,UAAW;AAAA,IAC1C,KAAK,CAAE,SAAU;AAAA,IACjB,QAAQ;AAAA,EACT;AACD;AAGO,MAAM,sBAAsB;AAAA,EAClC,IAAI;AAAA,EACJ,SAAS;AAAA,EACT,MAAM;AAAA,EACN,SAAS;AAAA,EACT,SAAS;AAAA,EACT,OAAO;AACR;",
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport { to, OKLCH } from 'colorjs.io/fn';\n\n/**\n * Internal dependencies\n */\nimport './register-color-spaces';\nimport type { Ramp } from './types';\n\nexport const WHITE = to( 'white', OKLCH );\nexport const BLACK = to( 'black', OKLCH );\n\n// Margin added to target contrasts to counter for algorithm approximations\n// and rounding errors.\nexport const UNIVERSAL_CONTRAST_TOPUP = 0.05;\n\n// When enabling \"lighter direction\" bias, this is the amount by which\n// black text contrast needs to be greater than white text contrast.\n// The higher the value, the stronger the preference for white text.\n// The current value has been determined empirically as the highest value\n// that won't cause the algo not to be able to correctly solve all contrasts.\nexport const WHITE_TEXT_CONTRAST_MARGIN = 3.1;\n\n// These values are used as thresholds when trying to match the background\n// ramp's lightness while calculating an accent ramp. They prevent the accent\n// scale from being pinned to lightness values in the middle of the range,\n// which would cause the algorithm to struggle to satisfy the accent scale\n// constraints and therefore produce unexpected results.\nexport const ACCENT_SCALE_BASE_LIGHTNESS_THRESHOLDS = {\n\tlighter: { min: 0.2, max: 0.4 },\n\tdarker: { min: 0.75, max: 0.98 },\n} as const;\n\n// Lightness precision we aim for. Approximately 1/256, resolution of an 8-bit number.\nexport const LIGHTNESS_EPSILON = 4e-3;\n\nexport const MAX_BISECTION_ITERATIONS = 10;\n\nexport const CONTRAST_COMBINATIONS: {\n\tbgs: ( keyof Ramp )[];\n\tfgs: ( keyof Ramp )[];\n\ttarget: number;\n}[] = [\n\t{\n\t\tbgs: [ 'surface1', 'surface2', 'surface3' ],\n\t\tfgs: [ 'fgSurface3', 'fgSurface4' ],\n\t\ttarget: 4.5,\n\t},\n\t{\n\t\tbgs: [ 'surface4', 'surface5' ],\n\t\tfgs: [ 'fgSurface4' ],\n\t\ttarget: 4.5,\n\t},\n\t{\n\t\tbgs: [ 'bgFill1' ],\n\t\tfgs: [ 'fgFill' ],\n\t\ttarget: 4.5,\n\t},\n\t{\n\t\tbgs: [ 'bgFillInverted1' ],\n\t\tfgs: [ 'fgFillInverted' ],\n\t\ttarget: 4.5,\n\t},\n\t{\n\t\tbgs: [ 'bgFillInverted1' ],\n\t\tfgs: [ 'fgFillInverted' ],\n\t\ttarget: 4.5,\n\t},\n\t{\n\t\tbgs: [ 'surface1', 'surface2', 'surface3' ],\n\t\tfgs: [ 'stroke3' ],\n\t\ttarget: 3,\n\t},\n];\n\n// Used when generating the DTCG tokens and the static color ramps.\nexport const DEFAULT_SEED_COLORS = {\n\tbg: '#f8f8f8',\n\tprimary: '#3858e9',\n\tinfo: '#0090ff',\n\tsuccess: '#4ab866',\n\tcaution: '#f0d149',\n\twarning: '#f0b849',\n\terror: '#cc1818',\n};\n"],
5
+ "mappings": ";AAGA,SAAS,IAAI,aAAa;AAK1B,OAAO;AAGA,IAAM,QAAQ,GAAI,SAAS,KAAM;AACjC,IAAM,QAAQ,GAAI,SAAS,KAAM;AAIjC,IAAM,2BAA2B;AAOjC,IAAM,6BAA6B;AAOnC,IAAM,yCAAyC;AAAA,EACrD,SAAS,EAAE,KAAK,KAAK,KAAK,IAAI;AAAA,EAC9B,QAAQ,EAAE,KAAK,MAAM,KAAK,KAAK;AAChC;AAGO,IAAM,oBAAoB;AAE1B,IAAM,2BAA2B;AAEjC,IAAM,wBAIP;AAAA,EACL;AAAA,IACC,KAAK,CAAE,YAAY,YAAY,UAAW;AAAA,IAC1C,KAAK,CAAE,cAAc,YAAa;AAAA,IAClC,QAAQ;AAAA,EACT;AAAA,EACA;AAAA,IACC,KAAK,CAAE,YAAY,UAAW;AAAA,IAC9B,KAAK,CAAE,YAAa;AAAA,IACpB,QAAQ;AAAA,EACT;AAAA,EACA;AAAA,IACC,KAAK,CAAE,SAAU;AAAA,IACjB,KAAK,CAAE,QAAS;AAAA,IAChB,QAAQ;AAAA,EACT;AAAA,EACA;AAAA,IACC,KAAK,CAAE,iBAAkB;AAAA,IACzB,KAAK,CAAE,gBAAiB;AAAA,IACxB,QAAQ;AAAA,EACT;AAAA,EACA;AAAA,IACC,KAAK,CAAE,iBAAkB;AAAA,IACzB,KAAK,CAAE,gBAAiB;AAAA,IACxB,QAAQ;AAAA,EACT;AAAA,EACA;AAAA,IACC,KAAK,CAAE,YAAY,YAAY,UAAW;AAAA,IAC1C,KAA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