@chipmobilesdk/rn-theme 1.1.0 → 1.3.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 (263) hide show
  1. package/CHANGELOG.md +124 -1
  2. package/README.md +17 -12
  3. package/lib/commonjs/color/categorical.js +35 -0
  4. package/lib/commonjs/color/categorical.js.map +1 -0
  5. package/lib/commonjs/color/contrast.js +199 -0
  6. package/lib/commonjs/color/contrast.js.map +1 -0
  7. package/lib/commonjs/color/parse.js +110 -0
  8. package/lib/commonjs/color/parse.js.map +1 -0
  9. package/lib/commonjs/color/roles.js +235 -0
  10. package/lib/commonjs/color/roles.js.map +1 -0
  11. package/lib/commonjs/index.js +94 -0
  12. package/lib/commonjs/index.js.map +1 -0
  13. package/lib/commonjs/integration/navigationTheme.js +43 -0
  14. package/lib/commonjs/integration/navigationTheme.js.map +1 -0
  15. package/lib/commonjs/package.json +1 -0
  16. package/lib/commonjs/presets/byTone.js +28 -0
  17. package/lib/commonjs/presets/byTone.js.map +1 -0
  18. package/lib/commonjs/presets/layout.js +67 -0
  19. package/lib/commonjs/presets/layout.js.map +1 -0
  20. package/lib/commonjs/presets/themePresets.js +115 -0
  21. package/lib/commonjs/presets/themePresets.js.map +1 -0
  22. package/lib/commonjs/theme/buildThemes.js +211 -0
  23. package/lib/commonjs/theme/buildThemes.js.map +1 -0
  24. package/lib/commonjs/theme/errors.js +49 -0
  25. package/lib/commonjs/theme/errors.js.map +1 -0
  26. package/lib/commonjs/theme/overrides.js +125 -0
  27. package/lib/commonjs/theme/overrides.js.map +1 -0
  28. package/lib/commonjs/theme/validateThemeConfig.js +157 -0
  29. package/lib/commonjs/theme/validateThemeConfig.js.map +1 -0
  30. package/lib/commonjs/tokens/defaults.js +132 -0
  31. package/lib/commonjs/tokens/defaults.js.map +1 -0
  32. package/lib/commonjs/tokens/typography.js +136 -0
  33. package/lib/commonjs/tokens/typography.js.map +1 -0
  34. package/lib/commonjs/types/brand.js +2 -0
  35. package/lib/commonjs/types/brand.js.map +1 -0
  36. package/lib/commonjs/types/colors.js +2 -0
  37. package/lib/commonjs/types/colors.js.map +1 -0
  38. package/lib/commonjs/types/index.js +2 -0
  39. package/lib/commonjs/types/index.js.map +1 -0
  40. package/lib/commonjs/types/theme.js +6 -0
  41. package/lib/commonjs/types/theme.js.map +1 -0
  42. package/lib/commonjs/types/tokens.js +2 -0
  43. package/lib/commonjs/types/tokens.js.map +1 -0
  44. package/lib/commonjs/types/typography.js +2 -0
  45. package/lib/commonjs/types/typography.js.map +1 -0
  46. package/lib/commonjs/unistyles/createUnistylesConfig.js +113 -0
  47. package/lib/commonjs/unistyles/createUnistylesConfig.js.map +1 -0
  48. package/lib/commonjs/unistyles/themeMode.js +39 -0
  49. package/lib/commonjs/unistyles/themeMode.js.map +1 -0
  50. package/lib/commonjs/vendor/mcu/LICENSE +191 -0
  51. package/lib/commonjs/vendor/mcu/hct/cam16.js +362 -0
  52. package/lib/commonjs/vendor/mcu/hct/cam16.js.map +1 -0
  53. package/lib/commonjs/vendor/mcu/hct/hct.js +183 -0
  54. package/lib/commonjs/vendor/mcu/hct/hct.js.map +1 -0
  55. package/lib/commonjs/vendor/mcu/hct/hct_solver.js +401 -0
  56. package/lib/commonjs/vendor/mcu/hct/hct_solver.js.map +1 -0
  57. package/lib/commonjs/vendor/mcu/hct/viewing_conditions.js +116 -0
  58. package/lib/commonjs/vendor/mcu/hct/viewing_conditions.js.map +1 -0
  59. package/lib/commonjs/vendor/mcu/index.js +27 -0
  60. package/lib/commonjs/vendor/mcu/index.js.map +1 -0
  61. package/lib/commonjs/vendor/mcu/palettes/tonal_palette.js +177 -0
  62. package/lib/commonjs/vendor/mcu/palettes/tonal_palette.js.map +1 -0
  63. package/lib/commonjs/vendor/mcu/utils/color_utils.js +298 -0
  64. package/lib/commonjs/vendor/mcu/utils/color_utils.js.map +1 -0
  65. package/lib/commonjs/vendor/mcu/utils/math_utils.js +158 -0
  66. package/lib/commonjs/vendor/mcu/utils/math_utils.js.map +1 -0
  67. package/lib/module/color/categorical.js +31 -0
  68. package/lib/module/color/categorical.js.map +1 -0
  69. package/lib/module/color/contrast.js +194 -0
  70. package/lib/module/color/contrast.js.map +1 -0
  71. package/lib/module/color/parse.js +101 -0
  72. package/lib/module/color/parse.js.map +1 -0
  73. package/lib/module/color/roles.js +229 -0
  74. package/lib/module/color/roles.js.map +1 -0
  75. package/lib/module/index.js +23 -0
  76. package/lib/module/index.js.map +1 -0
  77. package/lib/module/integration/navigationTheme.js +39 -0
  78. package/lib/module/integration/navigationTheme.js.map +1 -0
  79. package/lib/module/package.json +1 -0
  80. package/lib/module/presets/byTone.js +24 -0
  81. package/lib/module/presets/byTone.js.map +1 -0
  82. package/lib/module/presets/layout.js +63 -0
  83. package/lib/module/presets/layout.js.map +1 -0
  84. package/lib/module/presets/themePresets.js +110 -0
  85. package/lib/module/presets/themePresets.js.map +1 -0
  86. package/lib/module/theme/buildThemes.js +208 -0
  87. package/lib/module/theme/buildThemes.js.map +1 -0
  88. package/lib/module/theme/errors.js +43 -0
  89. package/lib/module/theme/errors.js.map +1 -0
  90. package/lib/module/theme/overrides.js +119 -0
  91. package/lib/module/theme/overrides.js.map +1 -0
  92. package/lib/module/theme/validateThemeConfig.js +152 -0
  93. package/lib/module/theme/validateThemeConfig.js.map +1 -0
  94. package/lib/module/tokens/defaults.js +120 -0
  95. package/lib/module/tokens/defaults.js.map +1 -0
  96. package/lib/module/tokens/typography.js +129 -0
  97. package/lib/module/tokens/typography.js.map +1 -0
  98. package/lib/module/types/brand.js +2 -0
  99. package/lib/module/types/brand.js.map +1 -0
  100. package/lib/module/types/colors.js +2 -0
  101. package/lib/module/types/colors.js.map +1 -0
  102. package/lib/module/types/index.js +2 -0
  103. package/lib/module/types/index.js.map +1 -0
  104. package/lib/module/types/theme.js +4 -0
  105. package/lib/module/types/theme.js.map +1 -0
  106. package/lib/module/types/tokens.js +2 -0
  107. package/lib/module/types/tokens.js.map +1 -0
  108. package/lib/module/types/typography.js +2 -0
  109. package/lib/module/types/typography.js.map +1 -0
  110. package/lib/module/unistyles/createUnistylesConfig.js +109 -0
  111. package/lib/module/unistyles/createUnistylesConfig.js.map +1 -0
  112. package/lib/module/unistyles/themeMode.js +36 -0
  113. package/lib/module/unistyles/themeMode.js.map +1 -0
  114. package/lib/module/vendor/mcu/LICENSE +191 -0
  115. package/lib/module/vendor/mcu/hct/cam16.js +356 -0
  116. package/lib/module/vendor/mcu/hct/cam16.js.map +1 -0
  117. package/lib/module/vendor/mcu/hct/hct.js +178 -0
  118. package/lib/module/vendor/mcu/hct/hct.js.map +1 -0
  119. package/lib/module/vendor/mcu/hct/hct_solver.js +396 -0
  120. package/lib/module/vendor/mcu/hct/hct_solver.js.map +1 -0
  121. package/lib/module/vendor/mcu/hct/viewing_conditions.js +110 -0
  122. package/lib/module/vendor/mcu/hct/viewing_conditions.js.map +1 -0
  123. package/lib/module/vendor/mcu/index.js +8 -0
  124. package/lib/module/vendor/mcu/index.js.map +1 -0
  125. package/lib/module/vendor/mcu/palettes/tonal_palette.js +172 -0
  126. package/lib/module/vendor/mcu/palettes/tonal_palette.js.map +1 -0
  127. package/lib/module/vendor/mcu/utils/color_utils.js +277 -0
  128. package/lib/module/vendor/mcu/utils/color_utils.js.map +1 -0
  129. package/lib/module/vendor/mcu/utils/math_utils.js +146 -0
  130. package/lib/module/vendor/mcu/utils/math_utils.js.map +1 -0
  131. package/lib/typescript/commonjs/color/categorical.d.ts +7 -0
  132. package/lib/typescript/commonjs/color/categorical.d.ts.map +1 -0
  133. package/lib/typescript/commonjs/color/contrast.d.ts +26 -0
  134. package/lib/typescript/commonjs/color/contrast.d.ts.map +1 -0
  135. package/lib/typescript/commonjs/color/parse.d.ts +25 -0
  136. package/lib/typescript/commonjs/color/parse.d.ts.map +1 -0
  137. package/lib/typescript/commonjs/color/roles.d.ts +26 -0
  138. package/lib/typescript/commonjs/color/roles.d.ts.map +1 -0
  139. package/lib/typescript/commonjs/index.d.ts +18 -0
  140. package/lib/typescript/commonjs/index.d.ts.map +1 -0
  141. package/lib/typescript/commonjs/integration/navigationTheme.d.ts +30 -0
  142. package/lib/typescript/commonjs/integration/navigationTheme.d.ts.map +1 -0
  143. package/lib/typescript/commonjs/package.json +1 -0
  144. package/lib/typescript/commonjs/presets/byTone.d.ts +19 -0
  145. package/lib/typescript/commonjs/presets/byTone.d.ts.map +1 -0
  146. package/lib/typescript/commonjs/presets/layout.d.ts +63 -0
  147. package/lib/typescript/commonjs/presets/layout.d.ts.map +1 -0
  148. package/lib/typescript/commonjs/presets/themePresets.d.ts +11 -0
  149. package/lib/typescript/commonjs/presets/themePresets.d.ts.map +1 -0
  150. package/lib/typescript/commonjs/theme/buildThemes.d.ts +18 -0
  151. package/lib/typescript/commonjs/theme/buildThemes.d.ts.map +1 -0
  152. package/lib/typescript/commonjs/theme/errors.d.ts +23 -0
  153. package/lib/typescript/commonjs/theme/errors.d.ts.map +1 -0
  154. package/lib/typescript/commonjs/theme/overrides.d.ts +11 -0
  155. package/lib/typescript/commonjs/theme/overrides.d.ts.map +1 -0
  156. package/lib/typescript/commonjs/theme/validateThemeConfig.d.ts +6 -0
  157. package/lib/typescript/commonjs/theme/validateThemeConfig.d.ts.map +1 -0
  158. package/lib/typescript/commonjs/tokens/defaults.d.ts +23 -0
  159. package/lib/typescript/commonjs/tokens/defaults.d.ts.map +1 -0
  160. package/lib/typescript/commonjs/tokens/typography.d.ts +14 -0
  161. package/lib/typescript/commonjs/tokens/typography.d.ts.map +1 -0
  162. package/lib/typescript/commonjs/types/brand.d.ts +21 -0
  163. package/lib/typescript/commonjs/types/brand.d.ts.map +1 -0
  164. package/lib/typescript/commonjs/types/colors.d.ts +76 -0
  165. package/lib/typescript/commonjs/types/colors.d.ts.map +1 -0
  166. package/lib/typescript/commonjs/types/index.d.ts +6 -0
  167. package/lib/typescript/commonjs/types/index.d.ts.map +1 -0
  168. package/lib/typescript/commonjs/types/theme.d.ts +140 -0
  169. package/lib/typescript/commonjs/types/theme.d.ts.map +1 -0
  170. package/lib/typescript/commonjs/types/tokens.d.ts +79 -0
  171. package/lib/typescript/commonjs/types/tokens.d.ts.map +1 -0
  172. package/lib/typescript/commonjs/types/typography.d.ts +53 -0
  173. package/lib/typescript/commonjs/types/typography.d.ts.map +1 -0
  174. package/lib/typescript/commonjs/unistyles/createUnistylesConfig.d.ts +52 -0
  175. package/lib/typescript/commonjs/unistyles/createUnistylesConfig.d.ts.map +1 -0
  176. package/lib/typescript/commonjs/unistyles/themeMode.d.ts +13 -0
  177. package/lib/typescript/commonjs/unistyles/themeMode.d.ts.map +1 -0
  178. package/lib/typescript/commonjs/vendor/mcu/hct/cam16.d.ts +132 -0
  179. package/lib/typescript/commonjs/vendor/mcu/hct/cam16.d.ts.map +1 -0
  180. package/lib/typescript/commonjs/vendor/mcu/hct/hct.d.ts +93 -0
  181. package/lib/typescript/commonjs/vendor/mcu/hct/hct.d.ts.map +1 -0
  182. package/lib/typescript/commonjs/vendor/mcu/hct/hct_solver.d.ts +147 -0
  183. package/lib/typescript/commonjs/vendor/mcu/hct/hct_solver.d.ts.map +1 -0
  184. package/lib/typescript/commonjs/vendor/mcu/hct/viewing_conditions.d.ts +75 -0
  185. package/lib/typescript/commonjs/vendor/mcu/hct/viewing_conditions.d.ts.map +1 -0
  186. package/lib/typescript/commonjs/vendor/mcu/index.d.ts +4 -0
  187. package/lib/typescript/commonjs/vendor/mcu/index.d.ts.map +1 -0
  188. package/lib/typescript/commonjs/vendor/mcu/palettes/tonal_palette.d.ts +56 -0
  189. package/lib/typescript/commonjs/vendor/mcu/palettes/tonal_palette.d.ts.map +1 -0
  190. package/lib/typescript/commonjs/vendor/mcu/utils/color_utils.d.ts +129 -0
  191. package/lib/typescript/commonjs/vendor/mcu/utils/color_utils.d.ts.map +1 -0
  192. package/lib/typescript/commonjs/vendor/mcu/utils/math_utils.d.ts +83 -0
  193. package/lib/typescript/commonjs/vendor/mcu/utils/math_utils.d.ts.map +1 -0
  194. package/lib/typescript/module/color/categorical.d.ts +7 -0
  195. package/lib/typescript/module/color/categorical.d.ts.map +1 -0
  196. package/lib/typescript/module/color/contrast.d.ts +26 -0
  197. package/lib/typescript/module/color/contrast.d.ts.map +1 -0
  198. package/lib/typescript/module/color/parse.d.ts +25 -0
  199. package/lib/typescript/module/color/parse.d.ts.map +1 -0
  200. package/lib/typescript/module/color/roles.d.ts +26 -0
  201. package/lib/typescript/module/color/roles.d.ts.map +1 -0
  202. package/lib/typescript/module/index.d.ts +18 -0
  203. package/lib/typescript/module/index.d.ts.map +1 -0
  204. package/lib/typescript/module/integration/navigationTheme.d.ts +30 -0
  205. package/lib/typescript/module/integration/navigationTheme.d.ts.map +1 -0
  206. package/lib/typescript/module/package.json +1 -0
  207. package/lib/typescript/module/presets/byTone.d.ts +19 -0
  208. package/lib/typescript/module/presets/byTone.d.ts.map +1 -0
  209. package/lib/typescript/module/presets/layout.d.ts +63 -0
  210. package/lib/typescript/module/presets/layout.d.ts.map +1 -0
  211. package/lib/typescript/module/presets/themePresets.d.ts +11 -0
  212. package/lib/typescript/module/presets/themePresets.d.ts.map +1 -0
  213. package/lib/typescript/module/theme/buildThemes.d.ts +18 -0
  214. package/lib/typescript/module/theme/buildThemes.d.ts.map +1 -0
  215. package/lib/typescript/module/theme/errors.d.ts +23 -0
  216. package/lib/typescript/module/theme/errors.d.ts.map +1 -0
  217. package/lib/typescript/module/theme/overrides.d.ts +11 -0
  218. package/lib/typescript/module/theme/overrides.d.ts.map +1 -0
  219. package/lib/typescript/module/theme/validateThemeConfig.d.ts +6 -0
  220. package/lib/typescript/module/theme/validateThemeConfig.d.ts.map +1 -0
  221. package/lib/typescript/module/tokens/defaults.d.ts +23 -0
  222. package/lib/typescript/module/tokens/defaults.d.ts.map +1 -0
  223. package/lib/typescript/module/tokens/typography.d.ts +14 -0
  224. package/lib/typescript/module/tokens/typography.d.ts.map +1 -0
  225. package/lib/typescript/module/types/brand.d.ts +21 -0
  226. package/lib/typescript/module/types/brand.d.ts.map +1 -0
  227. package/lib/typescript/module/types/colors.d.ts +76 -0
  228. package/lib/typescript/module/types/colors.d.ts.map +1 -0
  229. package/lib/typescript/module/types/index.d.ts +6 -0
  230. package/lib/typescript/module/types/index.d.ts.map +1 -0
  231. package/lib/typescript/module/types/theme.d.ts +140 -0
  232. package/lib/typescript/module/types/theme.d.ts.map +1 -0
  233. package/lib/typescript/module/types/tokens.d.ts +79 -0
  234. package/lib/typescript/module/types/tokens.d.ts.map +1 -0
  235. package/lib/typescript/module/types/typography.d.ts +53 -0
  236. package/lib/typescript/module/types/typography.d.ts.map +1 -0
  237. package/lib/typescript/module/unistyles/createUnistylesConfig.d.ts +52 -0
  238. package/lib/typescript/module/unistyles/createUnistylesConfig.d.ts.map +1 -0
  239. package/lib/typescript/module/unistyles/themeMode.d.ts +13 -0
  240. package/lib/typescript/module/unistyles/themeMode.d.ts.map +1 -0
  241. package/lib/typescript/module/vendor/mcu/hct/cam16.d.ts +132 -0
  242. package/lib/typescript/module/vendor/mcu/hct/cam16.d.ts.map +1 -0
  243. package/lib/typescript/module/vendor/mcu/hct/hct.d.ts +93 -0
  244. package/lib/typescript/module/vendor/mcu/hct/hct.d.ts.map +1 -0
  245. package/lib/typescript/module/vendor/mcu/hct/hct_solver.d.ts +147 -0
  246. package/lib/typescript/module/vendor/mcu/hct/hct_solver.d.ts.map +1 -0
  247. package/lib/typescript/module/vendor/mcu/hct/viewing_conditions.d.ts +75 -0
  248. package/lib/typescript/module/vendor/mcu/hct/viewing_conditions.d.ts.map +1 -0
  249. package/lib/typescript/module/vendor/mcu/index.d.ts +4 -0
  250. package/lib/typescript/module/vendor/mcu/index.d.ts.map +1 -0
  251. package/lib/typescript/module/vendor/mcu/palettes/tonal_palette.d.ts +56 -0
  252. package/lib/typescript/module/vendor/mcu/palettes/tonal_palette.d.ts.map +1 -0
  253. package/lib/typescript/module/vendor/mcu/utils/color_utils.d.ts +129 -0
  254. package/lib/typescript/module/vendor/mcu/utils/color_utils.d.ts.map +1 -0
  255. package/lib/typescript/module/vendor/mcu/utils/math_utils.d.ts +83 -0
  256. package/lib/typescript/module/vendor/mcu/utils/math_utils.d.ts.map +1 -0
  257. package/package.json +40 -16
  258. package/src/color/roles.ts +3 -1
  259. package/src/theme/buildThemes.ts +84 -26
  260. package/src/theme/validateThemeConfig.ts +28 -2
  261. package/src/tokens/defaults.ts +14 -8
  262. package/src/unistyles/createUnistylesConfig.ts +4 -1
  263. package/src/vendor/mcu/index.ts +1 -1
@@ -0,0 +1,75 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2021 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ /**
18
+ * In traditional color spaces, a color can be identified solely by the
19
+ * observer's measurement of the color. Color appearance models such as CAM16
20
+ * also use information about the environment where the color was
21
+ * observed, known as the viewing conditions.
22
+ *
23
+ * For example, white under the traditional assumption of a midday sun white
24
+ * point is accurately measured as a slightly chromatic blue by CAM16. (roughly,
25
+ * hue 203, chroma 3, lightness 100)
26
+ *
27
+ * This class caches intermediate values of the CAM16 conversion process that
28
+ * depend only on viewing conditions, enabling speed ups.
29
+ */
30
+ export declare class ViewingConditions {
31
+ n: number;
32
+ aw: number;
33
+ nbb: number;
34
+ ncb: number;
35
+ c: number;
36
+ nc: number;
37
+ rgbD: number[];
38
+ fl: number;
39
+ fLRoot: number;
40
+ z: number;
41
+ /** sRGB-like viewing conditions. */
42
+ static DEFAULT: ViewingConditions;
43
+ /**
44
+ * Create ViewingConditions from a simple, physically relevant, set of
45
+ * parameters.
46
+ *
47
+ * @param whitePoint White point, measured in the XYZ color space.
48
+ * default = D65, or sunny day afternoon
49
+ * @param adaptingLuminance The luminance of the adapting field. Informally,
50
+ * how bright it is in the room where the color is viewed. Can be
51
+ * calculated from lux by multiplying lux by 0.0586. default = 11.72,
52
+ * or 200 lux.
53
+ * @param backgroundLstar The lightness of the area surrounding the color.
54
+ * measured by L* in L*a*b*. default = 50.0
55
+ * @param surround A general description of the lighting surrounding the
56
+ * color. 0 is pitch dark, like watching a movie in a theater. 1.0 is a
57
+ * dimly light room, like watching TV at home at night. 2.0 means there
58
+ * is no difference between the lighting on the color and around it.
59
+ * default = 2.0
60
+ * @param discountingIlluminant Whether the eye accounts for the tint of the
61
+ * ambient lighting, such as knowing an apple is still red in green light.
62
+ * default = false, the eye does not perform this process on
63
+ * self-luminous objects like displays.
64
+ */
65
+ static make(whitePoint?: number[], adaptingLuminance?: number, backgroundLstar?: number, surround?: number, discountingIlluminant?: boolean): ViewingConditions;
66
+ /**
67
+ * Parameters are intermediate values of the CAM16 conversion process. Their
68
+ * names are shorthand for technical color science terminology, this class
69
+ * would not benefit from documenting them individually. A brief overview
70
+ * is available in the CAM16 specification, and a complete overview requires
71
+ * a color science textbook, such as Fairchild's Color Appearance Models.
72
+ */
73
+ private constructor();
74
+ }
75
+ //# sourceMappingURL=viewing_conditions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"viewing_conditions.d.ts","sourceRoot":"","sources":["../../../../../../src/vendor/mcu/hct/viewing_conditions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAQH;;;;;;;;;;;;GAYG;AACH,qBAAa,iBAAiB;IAgFjB,CAAC,EAAE,MAAM;IAAS,EAAE,EAAE,MAAM;IAAS,GAAG,EAAE,MAAM;IAChD,GAAG,EAAE,MAAM;IAAS,CAAC,EAAE,MAAM;IAAS,EAAE,EAAE,MAAM;IAChD,IAAI,EAAE,MAAM,EAAE;IAAS,EAAE,EAAE,MAAM;IAAS,MAAM,EAAE,MAAM;IACxD,CAAC,EAAE,MAAM;IAlFpB,qCAAqC;IACrC,MAAM,CAAC,OAAO,oBAA4B;IAE1C;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,MAAM,CAAC,IAAI,CACP,UAAU,WAAwB,EAClC,iBAAiB,SAAqD,EACtE,eAAe,SAAO,EAAE,QAAQ,SAAM,EACtC,qBAAqB,UAAQ,GAAG,iBAAiB;IA0CrD;;;;;;OAMG;IACH,OAAO;CAKR"}
@@ -0,0 +1,4 @@
1
+ export { Hct } from './hct/hct.js';
2
+ export { TonalPalette } from './palettes/tonal_palette.js';
3
+ export { argbFromRgb } from './utils/color_utils.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/vendor/mcu/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAW,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA0B,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAqB,CAAC"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2021 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { Hct } from '../hct/hct.js';
18
+ /**
19
+ * A convenience class for retrieving colors that are constant in hue and
20
+ * chroma, but vary in tone.
21
+ */
22
+ export declare class TonalPalette {
23
+ readonly hue: number;
24
+ readonly chroma: number;
25
+ readonly keyColor: Hct;
26
+ private readonly cache;
27
+ /**
28
+ * @param argb ARGB representation of a color
29
+ * @return Tones matching that color's hue and chroma.
30
+ */
31
+ static fromInt(argb: number): TonalPalette;
32
+ /**
33
+ * @param hct Hct
34
+ * @return Tones matching that color's hue and chroma.
35
+ */
36
+ static fromHct(hct: Hct): TonalPalette;
37
+ /**
38
+ * @param hue HCT hue
39
+ * @param chroma HCT chroma
40
+ * @return Tones matching hue and chroma.
41
+ */
42
+ static fromHueAndChroma(hue: number, chroma: number): TonalPalette;
43
+ private constructor();
44
+ /**
45
+ * @param tone HCT tone, measured from 0 to 100.
46
+ * @return ARGB representation of a color with that tone.
47
+ */
48
+ tone(tone: number): number;
49
+ /**
50
+ * @param tone HCT tone.
51
+ * @return HCT representation of a color with that tone.
52
+ */
53
+ getHct(tone: number): Hct;
54
+ private averageArgb;
55
+ }
56
+ //# sourceMappingURL=tonal_palette.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tonal_palette.d.ts","sourceRoot":"","sources":["../../../../../../src/vendor/mcu/palettes/tonal_palette.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH,OAAO,EAAC,GAAG,EAAC,MAAM,eAAY,CAAC;AAE/B;;;GAGG;AACH,qBAAa,YAAY;IA+BnB,QAAQ,CAAC,GAAG,EAAE,MAAM;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM;IAAE,QAAQ,CAAC,QAAQ,EAAE,GAAG;IA9BzE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA6B;IAEnD;;;OAGG;IACH,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY;IAK1C;;;OAGG;IACH,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG;IAIvB;;;;OAIG;IACH,MAAM,CAAC,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,YAAY;IAKlE,OAAO;IAGP;;;OAGG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAa1B;;;OAGG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG;IAIzB,OAAO,CAAC,WAAW;CAcpB"}
@@ -0,0 +1,129 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2021 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ /**
18
+ * Converts a color from RGB components to ARGB format.
19
+ */
20
+ export declare function argbFromRgb(red: number, green: number, blue: number): number;
21
+ /**
22
+ * Converts a color from linear RGB components to ARGB format.
23
+ */
24
+ export declare function argbFromLinrgb(linrgb: number[]): number;
25
+ /**
26
+ * Returns the alpha component of a color in ARGB format.
27
+ */
28
+ export declare function alphaFromArgb(argb: number): number;
29
+ /**
30
+ * Returns the red component of a color in ARGB format.
31
+ */
32
+ export declare function redFromArgb(argb: number): number;
33
+ /**
34
+ * Returns the green component of a color in ARGB format.
35
+ */
36
+ export declare function greenFromArgb(argb: number): number;
37
+ /**
38
+ * Returns the blue component of a color in ARGB format.
39
+ */
40
+ export declare function blueFromArgb(argb: number): number;
41
+ /**
42
+ * Returns whether a color in ARGB format is opaque.
43
+ */
44
+ export declare function isOpaque(argb: number): boolean;
45
+ /**
46
+ * Converts a color from ARGB to XYZ.
47
+ */
48
+ export declare function argbFromXyz(x: number, y: number, z: number): number;
49
+ /**
50
+ * Converts a color from XYZ to ARGB.
51
+ */
52
+ export declare function xyzFromArgb(argb: number): number[];
53
+ /**
54
+ * Converts a color represented in Lab color space into an ARGB
55
+ * integer.
56
+ */
57
+ export declare function argbFromLab(l: number, a: number, b: number): number;
58
+ /**
59
+ * Converts a color from ARGB representation to L*a*b*
60
+ * representation.
61
+ *
62
+ * @param argb the ARGB representation of a color
63
+ * @return a Lab object representing the color
64
+ */
65
+ export declare function labFromArgb(argb: number): number[];
66
+ /**
67
+ * Converts an L* value to an ARGB representation.
68
+ *
69
+ * @param lstar L* in L*a*b*
70
+ * @return ARGB representation of grayscale color with lightness
71
+ * matching L*
72
+ */
73
+ export declare function argbFromLstar(lstar: number): number;
74
+ /**
75
+ * Computes the L* value of a color in ARGB representation.
76
+ *
77
+ * @param argb ARGB representation of a color
78
+ * @return L*, from L*a*b*, coordinate of the color
79
+ */
80
+ export declare function lstarFromArgb(argb: number): number;
81
+ /**
82
+ * Converts an L* value to a Y value.
83
+ *
84
+ * L* in L*a*b* and Y in XYZ measure the same quantity, luminance.
85
+ *
86
+ * L* measures perceptual luminance, a linear scale. Y in XYZ
87
+ * measures relative luminance, a logarithmic scale.
88
+ *
89
+ * @param lstar L* in L*a*b*
90
+ * @return Y in XYZ
91
+ */
92
+ export declare function yFromLstar(lstar: number): number;
93
+ /**
94
+ * Converts a Y value to an L* value.
95
+ *
96
+ * L* in L*a*b* and Y in XYZ measure the same quantity, luminance.
97
+ *
98
+ * L* measures perceptual luminance, a linear scale. Y in XYZ
99
+ * measures relative luminance, a logarithmic scale.
100
+ *
101
+ * @param y Y in XYZ
102
+ * @return L* in L*a*b*
103
+ */
104
+ export declare function lstarFromY(y: number): number;
105
+ /**
106
+ * Linearizes an RGB component.
107
+ *
108
+ * @param rgbComponent 0 <= rgb_component <= 255, represents R/G/B
109
+ * channel
110
+ * @return 0.0 <= output <= 100.0, color channel converted to
111
+ * linear RGB space
112
+ */
113
+ export declare function linearized(rgbComponent: number): number;
114
+ /**
115
+ * Delinearizes an RGB component.
116
+ *
117
+ * @param rgbComponent 0.0 <= rgb_component <= 100.0, represents
118
+ * linear R/G/B channel
119
+ * @return 0 <= output <= 255, color channel converted to regular
120
+ * RGB space
121
+ */
122
+ export declare function delinearized(rgbComponent: number): number;
123
+ /**
124
+ * Returns the standard white point; white on a sunny day.
125
+ *
126
+ * @return The white point
127
+ */
128
+ export declare function whitePointD65(): number[];
129
+ //# sourceMappingURL=color_utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"color_utils.d.ts","sourceRoot":"","sources":["../../../../../../src/vendor/mcu/utils/color_utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AA0CH;;GAEG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAG5E;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAKvD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAElD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAElD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE9C;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CASnE;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAKlD;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAYnE;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAsBlD;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAInD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGlD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE5C;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAOvD;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CASzD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,MAAM,EAAE,CAExC"}
@@ -0,0 +1,83 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2021 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ /**
18
+ * Utility methods for mathematical operations.
19
+ */
20
+ /**
21
+ * The signum function.
22
+ *
23
+ * @return 1 if num > 0, -1 if num < 0, and 0 if num = 0
24
+ */
25
+ export declare function signum(num: number): number;
26
+ /**
27
+ * The linear interpolation function.
28
+ *
29
+ * @return start if amount = 0 and stop if amount = 1
30
+ */
31
+ export declare function lerp(start: number, stop: number, amount: number): number;
32
+ /**
33
+ * Clamps an integer between two integers.
34
+ *
35
+ * @return input when min <= input <= max, and either min or max
36
+ * otherwise.
37
+ */
38
+ export declare function clampInt(min: number, max: number, input: number): number;
39
+ /**
40
+ * Clamps an integer between two floating-point numbers.
41
+ *
42
+ * @return input when min <= input <= max, and either min or max
43
+ * otherwise.
44
+ */
45
+ export declare function clampDouble(min: number, max: number, input: number): number;
46
+ /**
47
+ * Sanitizes a degree measure as an integer.
48
+ *
49
+ * @return a degree measure between 0 (inclusive) and 360
50
+ * (exclusive).
51
+ */
52
+ export declare function sanitizeDegreesInt(degrees: number): number;
53
+ /**
54
+ * Sanitizes a degree measure as a floating-point number.
55
+ *
56
+ * @return a degree measure between 0.0 (inclusive) and 360.0
57
+ * (exclusive).
58
+ */
59
+ export declare function sanitizeDegreesDouble(degrees: number): number;
60
+ /**
61
+ * Sign of direction change needed to travel from one angle to
62
+ * another.
63
+ *
64
+ * For angles that are 180 degrees apart from each other, both
65
+ * directions have the same travel distance, so either direction is
66
+ * shortest. The value 1.0 is returned in this case.
67
+ *
68
+ * @param from The angle travel starts from, in degrees.
69
+ * @param to The angle travel ends at, in degrees.
70
+ * @return -1 if decreasing from leads to the shortest travel
71
+ * distance, 1 if increasing from leads to the shortest travel
72
+ * distance.
73
+ */
74
+ export declare function rotationDirection(from: number, to: number): number;
75
+ /**
76
+ * Distance of two points on a circle, represented using degrees.
77
+ */
78
+ export declare function differenceDegrees(a: number, b: number): number;
79
+ /**
80
+ * Multiplies a 1x3 row vector with a 3x3 matrix.
81
+ */
82
+ export declare function matrixMultiply(row: number[], matrix: number[][]): number[];
83
+ //# sourceMappingURL=math_utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"math_utils.d.ts","sourceRoot":"","sources":["../../../../../../src/vendor/mcu/utils/math_utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAOH;;GAEG;AAEH;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAQ1C;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAExE;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAQxE;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAQ3E;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAM1D;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAM7D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAGlE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAE9D;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,CAQ1E"}
package/package.json CHANGED
@@ -1,15 +1,23 @@
1
1
  {
2
2
  "name": "@chipmobilesdk/rn-theme",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "private": false,
5
5
  "license": "UNLICENSED",
6
- "main": "src/index.ts",
7
- "types": "src/index.ts",
6
+ "source": "./src/index.ts",
7
+ "main": "./lib/commonjs/index.js",
8
+ "module": "./lib/module/index.js",
9
+ "types": "./lib/typescript/commonjs/index.d.ts",
8
10
  "exports": {
9
11
  ".": {
10
- "types": "./src/index.ts",
11
- "react-native": "./src/index.ts",
12
- "default": "./src/index.ts"
12
+ "chipmobilesdk-source": "./src/index.ts",
13
+ "import": {
14
+ "types": "./lib/typescript/module/index.d.ts",
15
+ "default": "./lib/module/index.js"
16
+ },
17
+ "require": {
18
+ "types": "./lib/typescript/commonjs/index.d.ts",
19
+ "default": "./lib/commonjs/index.js"
20
+ }
13
21
  }
14
22
  },
15
23
  "files": [
@@ -25,28 +33,44 @@
25
33
  "skills",
26
34
  "README.md",
27
35
  "CHANGELOG.md",
28
- "NOTICE"
36
+ "NOTICE",
37
+ "lib"
29
38
  ],
30
39
  "sideEffects": false,
31
40
  "scripts": {
41
+ "build": "bob build",
32
42
  "typecheck": "tsc -p tsconfig.json && tsc -p tsconfig.test.json",
33
- "pack:check": "npm pack --dry-run"
43
+ "pack:check": "npm pack --dry-run",
44
+ "prepack": "npm run build"
34
45
  },
35
46
  "dependencies": {
36
- "@chipmobilesdk/rn-core": "^0.1.0"
47
+ "@chipmobilesdk/rn-core": "^0.2.0"
37
48
  },
38
49
  "peerDependencies": {
39
- "react": ">=19",
40
50
  "react-native": ">=0.85",
41
- "react-native-unistyles": ">=3.2"
42
- },
43
- "peerDependenciesMeta": {
44
- "react-native-unistyles": {
45
- "optional": false
46
- }
51
+ "react-native-unistyles": "^3.2.0"
47
52
  },
48
53
  "publishConfig": {
49
54
  "access": "public",
50
55
  "registry": "https://registry.npmjs.org/"
56
+ },
57
+ "react-native-builder-bob": {
58
+ "source": "src",
59
+ "output": "lib",
60
+ "targets": [
61
+ [
62
+ "commonjs",
63
+ {
64
+ "esm": true
65
+ }
66
+ ],
67
+ [
68
+ "module",
69
+ {
70
+ "esm": true
71
+ }
72
+ ],
73
+ "typescript"
74
+ ]
51
75
  }
52
76
  }
@@ -7,6 +7,7 @@ import type {
7
7
  StandardToneName,
8
8
  ToneColors,
9
9
  } from '../types/colors';
10
+ import { DEFAULT_OPACITY } from '../tokens/defaults';
10
11
  import { argbFromColor, hexFromArgb, withAlpha } from './parse';
11
12
 
12
13
  /**
@@ -27,7 +28,8 @@ const MAX_NEUTRAL_SEED_CHROMA = 16;
27
28
  const NEUTRAL_VARIANT_EXTRA_CHROMA = 4;
28
29
 
29
30
  /** Material 3 opacities applied to `onSurface` and the scrim. */
30
- export const DISABLED_CONTENT_OPACITY = 0.38;
31
+ /** The same figure as `opacity.disabledContent`, from its one definition (THM-07). */
32
+ export const DISABLED_CONTENT_OPACITY = DEFAULT_OPACITY.disabledContent;
31
33
  const SCRIM_OPACITY = 0.32;
32
34
 
33
35
  /**
@@ -27,8 +27,8 @@ import type {
27
27
  Themes,
28
28
  } from '../types/theme';
29
29
  import type { FontToken, FontWeightName } from '../types/typography';
30
- import { describeFailures, ThemeContrastError } from './errors';
31
- import { mergeOverrides, pick } from './overrides';
30
+ import { describeFailures, ThemeConfigError, ThemeContrastError } from './errors';
31
+ import { isPlainObject, mergeOverrides, pick } from './overrides';
32
32
  import { validateThemeConfig } from './validateThemeConfig';
33
33
 
34
34
  export interface BuildThemesOptions {
@@ -56,23 +56,15 @@ function deviceHairlineWidth(): number {
56
56
  return (result.ok ? result.module.StyleSheet?.hairlineWidth : undefined) ?? 1;
57
57
  }
58
58
 
59
- /** Groups that come straight from tokens (presets and tones are derived after). */
60
- const TOKEN_KEYS = [
61
- 'color',
62
- 'typography',
63
- 'font',
64
- 'fontWeight',
65
- 'spacing',
66
- 'radius',
67
- 'borderWidth',
68
- 'size',
69
- 'opacity',
70
- 'motion',
71
- 'shadow',
72
- 'zIndex',
73
- 'maxFontScale',
74
- 'categorical',
75
- ] as const;
59
+ /** The standard tone names an app's own tone may not take over (THM-03). */
60
+ const STANDARD_TONES: ReadonlySet<string> = new Set([
61
+ 'neutral',
62
+ 'primary',
63
+ 'info',
64
+ 'success',
65
+ 'warning',
66
+ 'error',
67
+ ]);
76
68
 
77
69
  interface ThemeSource {
78
70
  name: string;
@@ -92,6 +84,35 @@ function cloneFonts(font: Record<FontWeightName, FontToken>): Record<FontWeightN
92
84
  return copy;
93
85
  }
94
86
 
87
+ /**
88
+ * Every top-level group an override may name, and nothing else.
89
+ *
90
+ * An override naming a group that does not exist — `radii` for `radius`,
91
+ * `colors` for `color` — used to be dropped without a word, so the override
92
+ * simply had no effect (THM-01). The list is derived from what was generated
93
+ * rather than written out by hand, so a new token group cannot be forgotten
94
+ * (THM-06).
95
+ */
96
+ function assertKnownOverrideGroups(
97
+ overrides: unknown,
98
+ known: Iterable<string>,
99
+ path: string,
100
+ ): void {
101
+ if (!isPlainObject(overrides)) {
102
+ return;
103
+ }
104
+ const allowed = new Set(known);
105
+ for (const key of Object.keys(overrides)) {
106
+ if (overrides[key] === undefined || allowed.has(key)) {
107
+ continue;
108
+ }
109
+ throw new ThemeConfigError(
110
+ `${path}.${key}`,
111
+ 'does not exist on the theme. Add new tokens through `extend`.',
112
+ );
113
+ }
114
+ }
115
+
95
116
  function buildOne(
96
117
  source: ThemeSource,
97
118
  fonts: ReturnType<typeof buildFonts>,
@@ -100,9 +121,15 @@ function buildOne(
100
121
  ): object {
101
122
  const { name, scheme, config, palettes } = source;
102
123
  const path = `overrides.${name}`;
103
- const color = buildColorRoles(palettes, scheme);
124
+ const generatedColor = buildColorRoles(palettes, scheme);
125
+
126
+ // Colour is merged first, because what follows is derived from it: an
127
+ // override of `color.shadow` or `color.onSurface` used to leave `shadow` and
128
+ // `tone.neutral` built from the generated value, so a theme that pinned a
129
+ // colour disagreed with itself (THM-02).
130
+ const color = mergeOverrides(generatedColor, pick(overrides, ['color'])?.color, `${path}.color`);
104
131
 
105
- const generated = {
132
+ const tokenGroups = {
106
133
  color,
107
134
  typography: buildTypography(config.typography, fonts.font, fonts.family),
108
135
  font: cloneFonts(fonts.font),
@@ -117,21 +144,41 @@ function buildOne(
117
144
  zIndex: buildZIndex(),
118
145
  maxFontScale: config.typography?.maxFontScale ?? DEFAULT_MAX_FONT_SCALE,
119
146
  categorical: buildCategorical(config.brandColors.primary, scheme),
120
- };
121
- const tokens = mergeOverrides(generated, pick(overrides, TOKEN_KEYS), path);
147
+ } satisfies Omit<BaseTheme<string>, 'tone' | (typeof PRESET_KEYS)[number]>;
148
+
149
+ const tokenKeys = Object.keys(tokenGroups);
150
+ const tokens = mergeOverrides(tokenGroups, pick(overrides, tokenKeys), path);
122
151
  const tone = mergeOverrides(
123
- buildTones<string>(palettes, color, scheme),
152
+ // From the merged colour, so `tone.neutral` follows an override of
153
+ // `color.onSurface` as the text presets already did.
154
+ buildTones<string>(palettes, tokens.color, scheme),
124
155
  pick(overrides, ['tone'])?.tone,
125
156
  `${path}.tone`,
126
157
  );
127
158
  const presets = mergeOverrides(buildPresets(tokens), pick(overrides, PRESET_KEYS), path);
128
- const base = { ...tokens, tone, ...presets } as BaseTheme<string>;
159
+ const base = { ...tokens, tone, ...presets } satisfies BaseTheme<string>;
129
160
 
130
161
  if (!config.extend) {
162
+ assertKnownOverrideGroups(overrides, [...tokenKeys, 'tone', ...PRESET_KEYS], path);
131
163
  return base;
132
164
  }
133
165
 
134
166
  const extension = config.extend({ name, scheme, theme: base });
167
+ for (const key of Object.keys(extension)) {
168
+ if (key in base) {
169
+ // `extend` returning `{ spacing: … }` replaced the whole spacing scale
170
+ // with whatever it held, unvalidated (THM-03).
171
+ throw new ThemeConfigError(
172
+ `extend.${key}`,
173
+ 'is already a theme group. Give the extension token a name of its own.',
174
+ );
175
+ }
176
+ }
177
+ assertKnownOverrideGroups(
178
+ overrides,
179
+ [...tokenKeys, 'tone', ...PRESET_KEYS, ...Object.keys(extension)],
180
+ path,
181
+ );
135
182
  const extensionOverrides = pick(overrides, Object.keys(extension));
136
183
 
137
184
  return { ...base, ...mergeOverrides(extension, extensionOverrides, path) };
@@ -186,11 +233,22 @@ export function buildThemes<
186
233
  { name: 'light', scheme: 'light', config: loose, palettes: basePalettes },
187
234
  { name: 'dark', scheme: 'dark', config: loose, palettes: basePalettes },
188
235
  ...Object.entries(loose.themes ?? {}).map(([name, named]) => {
236
+ const tones = { ...loose.tones, ...named.tones } as Record<string, string>;
237
+ for (const tone of Object.keys(tones)) {
238
+ if (STANDARD_TONES.has(tone)) {
239
+ // A custom tone named `primary` silently replaced the standard
240
+ // one, contrast guarantees and all (THM-03).
241
+ throw new ThemeConfigError(
242
+ `themes.${name}.tones.${tone}`,
243
+ 'is a standard tone. Override it through `overrides` instead.',
244
+ );
245
+ }
246
+ }
189
247
  const namedConfig = {
190
248
  ...loose,
191
249
  brandColors: named.brandColors ?? loose.brandColors,
192
250
  seeds: { ...loose.seeds, ...named.seeds },
193
- tones: { ...loose.tones, ...named.tones } as Record<string, string>,
251
+ tones,
194
252
  };
195
253
 
196
254
  return {