@chipmobilesdk/rn-theme 1.2.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 (257) hide show
  1. package/CHANGELOG.md +111 -0
  2. package/README.md +3 -1
  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
package/CHANGELOG.md CHANGED
@@ -1,5 +1,116 @@
1
1
  # @chipmobilesdk/rn-theme
2
2
 
3
+ ## 1.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Every peer range has an upper bound, and no package declares a peer it does not use. ([#21](https://github.com/operationd8979/chip-mobile-sdk/pull/21))
8
+
9
+ A peer range is now a caret, a tilde or an explicit `<`, except for `react` and
10
+ `react-native`: an app brings exactly one of each, so a floor is the only useful thing
11
+ to say about them. Every other peer is a library the app installs beside us, and an
12
+ open `>=` was a promise about versions nobody had run — mmkv 3→4 lost entitlements and
13
+ pending purchases exactly that way.
14
+
15
+ **Four of the new ceilings exclude a version that is already published**, so an app
16
+ that took the open range at its word may now see a peer warning. The new bound is the
17
+ major this release is tested against, which is the thing the old range failed to say:
18
+
19
+ | Peer | Was | Now | Published above the ceiling |
20
+ |---|---|---|---|
21
+ | `react-native-app-auth` (rn-auth) | `>=8` | `^8.0.0` | 9.0.0 |
22
+ | `react-native-keychain` (rn-auth) | `>=10` | `^10.0.0` | 11.0.0 |
23
+ | `@op-engineering/op-sqlite` (rn-local-db) | `>=17.1.0` | `^17.1.0` | 18.x, 19.x |
24
+ | `@react-native-firebase/messaging` (rn-notification) | `>=26.0.0` | `^26.0.0` | 27.x |
25
+
26
+ The others — `react-native-vision-camera` `^5.1.1`, `react-native-svg` `^15.15.0`,
27
+ `react-native-unistyles` `^3.2.0`, `@dr.pogodin/react-native-fs` `^2.39.2`,
28
+ `react-native-quick-crypto` `^1.0.0`, `react-native-notify-kit` `^10.5.0`,
29
+ `react-native-localize` `^3.7.0`, `react-native-mmkv` `^4.0.0` — exclude nothing that
30
+ exists today. rn-payment's mmkv range was already bounded (`>=4.0.0 <5`) and is now
31
+ written as the caret that means the same thing.
32
+
33
+ Peers nothing imports are gone. `rn-theme`, `rn-local-db` and `rn-notification` asked
34
+ for `react` without having a component or a hook between them; `rn-auth`, `rn-ai` and
35
+ `rn-i18n` asked for `react-native` without touching a React Native API (rn-auth reaches
36
+ both native modules through `lazyPeer`, rn-i18n formats on `Intl`); `rn-notification`
37
+ asked for `@react-native-firebase/app`, which messaging declares itself. `rn-ai` no
38
+ longer peers on `@chipmobilesdk/rn-auth` at all — it asks for a `TokenProvider`, a
39
+ two-method interface rn-auth's `auth` satisfies, so an app with its own token source
40
+ installs nothing extra. An app that enables push or signs in through rn-auth installs
41
+ the same packages as before; it is the manifest that stopped overstating.
42
+
43
+ `react-native-localize` is declared optional, which is what the code already did: the
44
+ time-zone reader goes through `lazyPeer` and falls back to `Intl` without it. The
45
+ `peerDependenciesMeta` entries that said `optional: false` are gone — that is npm's
46
+ default, and writing it down only invited the question of which peers were undecided.
47
+
48
+ `npm run check:manifests` now fails on an unbounded peer range, a peer nothing in
49
+ `src/` imports, and a `peerDependenciesMeta` entry for either, so the policy holds
50
+ without anyone remembering it.
51
+
52
+ - Every package now ships built JavaScript with declaration files, instead of asking the
53
+ app to compile its TypeScript. ([#22](https://github.com/operationd8979/chip-mobile-sdk/pull/22))
54
+
55
+ Each tarball carries `lib/commonjs`, `lib/module` and `lib/typescript` (built with
56
+ `react-native-builder-bob`), and `src/` alongside them. What that changes for a
57
+ consumer:
58
+
59
+ - **Nothing to add to `transformIgnorePatterns`.** `require` resolves to the CommonJS
60
+ build, so an app's Jest loads this package without being told to transform it. That
61
+ was the one thing every consuming app had to know about us (DEP-04).
62
+ - **Typechecking reads our `.d.ts`** rather than compiling our source under our
63
+ `tsconfig`. A consumer's stricter — or looser — settings no longer meet our code.
64
+ - **`import` resolves to ESM**, so a bundler can tree-shake what it does not use.
65
+
66
+ No exported name changed, and no subpath moved: `.`, `./testing`, `./push`,
67
+ `./advanced`, `./app-auth`, `./keychain` and rn-core's twelve subpaths resolve exactly
68
+ as before, each now with its own declarations for both module systems. publint and
69
+ `attw --profile node16` pass on all twelve packages, which they could not before.
70
+
71
+ Inside the monorepo nothing changed either, and that is deliberate: every subpath also
72
+ declares a private `chipmobilesdk-source` condition pointing at its TypeScript, and
73
+ Metro, Jest and `tsc` here ask for that condition first. The demo app bundles 371
74
+ modules straight from `packages/*/src`, so editing a package still changes the app with
75
+ no build step, and coverage is still measured on the source. The condition is named for
76
+ this organization rather than using the conventional `source` because third-party
77
+ packages declare that one too — `@dr.pogodin/react-native-fs` does — and asking for it
78
+ pulled their sources into our stricter compile.
79
+
80
+ `npm run build:packages` builds everything, `prepack` rebuilds before any `npm pack`,
81
+ and `lib/` is git-ignored: the published bytes are produced by the release, never
82
+ committed. `npm run check:manifests` now fails a package whose `main`, `module`,
83
+ `types`, `source` condition, `files`, build script or `prepack` do not match this shape.
84
+
85
+ ### Patch Changes
86
+
87
+ - Each package's public API and its weight are now recorded in the repository, so a change
88
+ to either is reviewed rather than discovered. ([#23](https://github.com/operationd8979/chip-mobile-sdk/pull/23))
89
+
90
+ `packages/<pkg>/etc/*.api.md` is an api-extractor report per entrypoint — twenty-seven
91
+ of them, generated from the declarations the package publishes and committed. A renamed
92
+ type, a widened union, one more optional field: all of it shows up in a pull request's
93
+ diff. `npm run check:api` fails when a report is out of date and `npm run api:update`
94
+ rewrites them.
95
+
96
+ A report that moves now needs a **minor or major** changeset for that package.
97
+ `check:changesets` enforces it, because the report is generated from what the package
98
+ publishes, and a patch release that moves the public surface is how a consumer's build
99
+ breaks on `npm update`. A report added for the first time is a baseline, not a change.
100
+ `./testing` deliberately has no report: test doubles are not a surface a release is
101
+ gated on.
102
+
103
+ `npm run check:size` holds every entrypoint to a budget in `.size-limit.json`, measured
104
+ on the ESM build with peers and rn-core treated as external — they are what an app
105
+ installs beside us, not our weight. Each budget started at today's measurement plus five
106
+ per cent, so growth becomes a decision someone makes instead of a drift nobody sees. The
107
+ current figures run from 500 B (`rn-core/lazy`) to 19 kB (rn-notification).
108
+
109
+ No behaviour or API changed in this release; the entry is here so the changelog records
110
+ when the reports and the budgets began.
111
+ - Updated dependencies ([#22](https://github.com/operationd8979/chip-mobile-sdk/pull/22), [#23](https://github.com/operationd8979/chip-mobile-sdk/pull/23)):
112
+ - @chipmobilesdk/rn-core@0.2.0
113
+
3
114
  ## 1.2.0
4
115
 
5
116
  ### Minor Changes
package/README.md CHANGED
@@ -269,7 +269,9 @@ override colours and numbers, Unistyles options and breakpoints.
269
269
  ## Dependency Classification
270
270
 
271
271
  - `dependencies`: none. HCT colour maths is vendored under `src/vendor/mcu` (Apache-2.0).
272
- - `peerDependencies`: `react`, `react-native`, `react-native-unistyles`.
272
+ - `peerDependencies`: `react-native` (for its style types) and `react-native-unistyles`
273
+ `^3.2.0`. No `react` peer: there is no component and no hook here, only tokens,
274
+ presets and the Unistyles configuration.
273
275
 
274
276
  ## Unistyles 3 Style Authoring and TypeScript Diagnostics
275
277
 
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.buildCategorical = buildCategorical;
7
+ var _index = require("../vendor/mcu/index.js");
8
+ var _parse = require("./parse.js");
9
+ const SERIES_COUNT = 8;
10
+ const SERIES_CHROMA = 48;
11
+ /** 3 × 45°: consecutive series land far apart on the hue wheel. */
12
+ const HUE_STEP = 135;
13
+
14
+ /**
15
+ * Alternating tones. Every tone clears 3:1 against `surface` (98 / 6), and the
16
+ * 15-unit L* step keeps neighbours apart even when colour vision cannot
17
+ * separate their hues.
18
+ */
19
+ const SERIES_TONES = {
20
+ light: [40, 55],
21
+ dark: [80, 60]
22
+ };
23
+
24
+ /**
25
+ * Categorical series colours for charts, starting at the primary hue
26
+ * (spec US-11). Status colours stay free for status.
27
+ */
28
+ function buildCategorical(primary, scheme) {
29
+ const startHue = _index.Hct.fromInt((0, _parse.argbFromColor)(primary)).hue;
30
+ const tones = SERIES_TONES[scheme];
31
+ return Array.from({
32
+ length: SERIES_COUNT
33
+ }, (_, index) => (0, _parse.hexFromArgb)(_index.Hct.from((startHue + index * HUE_STEP) % 360, SERIES_CHROMA, tones[index % 2]).toInt()));
34
+ }
35
+ //# sourceMappingURL=categorical.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_index","require","_parse","SERIES_COUNT","SERIES_CHROMA","HUE_STEP","SERIES_TONES","light","dark","buildCategorical","primary","scheme","startHue","Hct","fromInt","argbFromColor","hue","tones","Array","from","length","_","index","hexFromArgb","toInt"],"sourceRoot":"../../../src","sources":["color/categorical.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAEA,MAAME,YAAY,GAAG,CAAC;AACtB,MAAMC,aAAa,GAAG,EAAE;AACxB;AACA,MAAMC,QAAQ,GAAG,GAAG;;AAEpB;AACA;AACA;AACA;AACA;AACA,MAAMC,YAAmD,GAAG;EAC3DC,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;EACfC,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE;AACd,CAAC;;AAED;AACA;AACA;AACA;AACO,SAASC,gBAAgBA,CAACC,OAAe,EAAEC,MAAmB,EAAY;EAChF,MAAMC,QAAQ,GAAGC,UAAG,CAACC,OAAO,CAAC,IAAAC,oBAAa,EAACL,OAAO,CAAC,CAAC,CAACM,GAAG;EACxD,MAAMC,KAAK,GAAGX,YAAY,CAACK,MAAM,CAAC;EAElC,OAAOO,KAAK,CAACC,IAAI,CAAC;IAAEC,MAAM,EAAEjB;EAAa,CAAC,EAAE,CAACkB,CAAC,EAAEC,KAAK,KACpD,IAAAC,kBAAW,EACVV,UAAG,CAACM,IAAI,CAAC,CAACP,QAAQ,GAAGU,KAAK,GAAGjB,QAAQ,IAAI,GAAG,EAAED,aAAa,EAAEa,KAAK,CAACK,KAAK,GAAG,CAAC,CAAC,CAAC,CAACE,KAAK,CAAC,CACtF,CACD,CAAC;AACF","ignoreList":[]}
@@ -0,0 +1,199 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.TEXT_CONTRAST = exports.NON_TEXT_CONTRAST = void 0;
7
+ exports.auditTheme = auditTheme;
8
+ exports.contrastRatio = contrastRatio;
9
+ var _parse = require("./parse.js");
10
+ /** WCAG 2.x minimum ratio for text (1.4.3). */
11
+ const TEXT_CONTRAST = exports.TEXT_CONTRAST = 4.5;
12
+ /** WCAG 2.x minimum ratio for non-text boundaries (1.4.11). */
13
+ const NON_TEXT_CONTRAST = exports.NON_TEXT_CONTRAST = 3;
14
+ const WHITE = {
15
+ r: 255,
16
+ g: 255,
17
+ b: 255,
18
+ a: 1
19
+ };
20
+ const LUMINANCE_OFFSET = 0.05;
21
+ const ACCENT_ROLES = ['primary', 'secondary', 'tertiary', 'error', 'success', 'warning', 'info'];
22
+ const SEMANTIC_ROLES = ['error', 'success', 'warning', 'info'];
23
+ const BASE_BACKGROUNDS = ['color.background', 'color.surface'];
24
+ const SURFACE_TIERS = ['surfaceContainerLowest', 'surfaceContainerLow', 'surfaceContainer', 'surfaceContainerHigh', 'surfaceContainerHighest'];
25
+ function capitalize(value) {
26
+ return value.charAt(0).toUpperCase() + value.slice(1);
27
+ }
28
+ function onBase(foreground, target = TEXT_CONTRAST) {
29
+ return BASE_BACKGROUNDS.map(background => ({
30
+ foreground,
31
+ background,
32
+ target
33
+ }));
34
+ }
35
+
36
+ /**
37
+ * Every pair the package guarantees, expressed as theme paths. Paths missing
38
+ * from a theme (e.g. presets an older theme does not have) are skipped.
39
+ */
40
+ function guaranteedPairs(theme) {
41
+ const pairs = [];
42
+ for (const role of SEMANTIC_ROLES) {
43
+ pairs.push(...onBase(`color.${role}`));
44
+ }
45
+ for (const role of ACCENT_ROLES) {
46
+ const on = `on${capitalize(role)}`;
47
+ pairs.push({
48
+ foreground: `color.${on}`,
49
+ background: `color.${role}`,
50
+ target: TEXT_CONTRAST
51
+ }, {
52
+ foreground: `color.${on}Container`,
53
+ background: `color.${role}Container`,
54
+ target: TEXT_CONTRAST
55
+ });
56
+ }
57
+ pairs.push({
58
+ foreground: 'color.onBackground',
59
+ background: 'color.background',
60
+ target: TEXT_CONTRAST
61
+ }, {
62
+ foreground: 'color.onSurface',
63
+ background: 'color.surface',
64
+ target: TEXT_CONTRAST
65
+ }, {
66
+ foreground: 'color.onSurfaceVariant',
67
+ background: 'color.surfaceVariant',
68
+ target: TEXT_CONTRAST
69
+ }, ...onBase('color.onSurfaceVariant'), {
70
+ foreground: 'color.inverseOnSurface',
71
+ background: 'color.inverseSurface',
72
+ target: TEXT_CONTRAST
73
+ }, {
74
+ foreground: 'color.inversePrimary',
75
+ background: 'color.inverseSurface',
76
+ target: TEXT_CONTRAST
77
+ }, ...SURFACE_TIERS.map(tier => ({
78
+ foreground: 'color.onSurface',
79
+ background: `color.${tier}`,
80
+ target: TEXT_CONTRAST
81
+ })), ...onBase('color.outline', NON_TEXT_CONTRAST));
82
+ const tones = readPath(theme, 'tone');
83
+ if (isRecord(tones)) {
84
+ for (const name of Object.keys(tones)) {
85
+ const tone = `tone.${name}`;
86
+ pairs.push(...onBase(`${tone}.fg`), {
87
+ foreground: `${tone}.onContainer`,
88
+ background: `${tone}.container`,
89
+ target: TEXT_CONTRAST
90
+ }, {
91
+ foreground: `${tone}.onFill`,
92
+ background: `${tone}.fill`,
93
+ target: TEXT_CONTRAST
94
+ }, {
95
+ foreground: `${tone}.border`,
96
+ background: 'color.background',
97
+ target: NON_TEXT_CONTRAST
98
+ });
99
+ }
100
+ }
101
+ const text = readPath(theme, 'text');
102
+ if (isRecord(text)) {
103
+ for (const name of Object.keys(text)) {
104
+ // `text.disabled` deliberately uses the contrast-exempt disabled colour.
105
+ if (name !== 'disabled') {
106
+ pairs.push(...onBase(`text.${name}.color`));
107
+ }
108
+ }
109
+ }
110
+ const categorical = readPath(theme, 'categorical');
111
+ if (Array.isArray(categorical)) {
112
+ categorical.forEach((_, index) => {
113
+ pairs.push({
114
+ foreground: `categorical.${index}`,
115
+ background: 'color.surface',
116
+ target: NON_TEXT_CONTRAST
117
+ });
118
+ });
119
+ }
120
+ return pairs;
121
+ }
122
+ function isRecord(value) {
123
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
124
+ }
125
+ function readPath(source, path) {
126
+ return path.split('.').reduce((node, key) => {
127
+ if (Array.isArray(node)) {
128
+ return node[Number(key)];
129
+ }
130
+ return isRecord(node) ? node[key] : undefined;
131
+ }, source);
132
+ }
133
+ function channelLuminance(channel) {
134
+ const value = channel / 255;
135
+ return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
136
+ }
137
+ function relativeLuminance({
138
+ r,
139
+ g,
140
+ b
141
+ }) {
142
+ return 0.2126 * channelLuminance(r) + 0.7152 * channelLuminance(g) + 0.0722 * channelLuminance(b);
143
+ }
144
+ function composite(top, bottom) {
145
+ const mix = (upper, lower) => upper * top.a + lower * (1 - top.a);
146
+ return {
147
+ r: mix(top.r, bottom.r),
148
+ g: mix(top.g, bottom.g),
149
+ b: mix(top.b, bottom.b),
150
+ a: 1
151
+ };
152
+ }
153
+
154
+ /**
155
+ * WCAG contrast ratio of two colour strings. Translucent colours are
156
+ * composited first: the background over `base` (default white), then the
157
+ * foreground over the result.
158
+ */
159
+ function contrastRatio(foreground, background, base) {
160
+ const fg = (0, _parse.parseColor)(foreground);
161
+ const bg = (0, _parse.parseColor)(background);
162
+ const baseColor = (base != null ? (0, _parse.parseColor)(base) : null) ?? WHITE;
163
+ if (!fg || !bg) {
164
+ throw new Error(`contrastRatio: unsupported colour "${!fg ? foreground : background}".`);
165
+ }
166
+ const opaqueBackground = composite(bg, composite(baseColor, WHITE));
167
+ const opaqueForeground = composite(fg, opaqueBackground);
168
+ const lighter = Math.max(relativeLuminance(opaqueForeground), relativeLuminance(opaqueBackground));
169
+ const darker = Math.min(relativeLuminance(opaqueForeground), relativeLuminance(opaqueBackground));
170
+ return (lighter + LUMINANCE_OFFSET) / (darker + LUMINANCE_OFFSET);
171
+ }
172
+
173
+ /**
174
+ * Checks every contrast pair the package guarantees against the given theme
175
+ * and returns the ones below target. An empty list means the theme passes.
176
+ * `color.disabled` is never audited: inactive components are exempt from
177
+ * WCAG 1.4.3.
178
+ */
179
+ function auditTheme(theme) {
180
+ const base = readPath(theme, 'color.background');
181
+ const failures = [];
182
+ for (const pair of guaranteedPairs(theme)) {
183
+ const foreground = readPath(theme, pair.foreground);
184
+ const background = readPath(theme, pair.background);
185
+ if (typeof foreground !== 'string' || typeof background !== 'string') {
186
+ continue;
187
+ }
188
+ const ratio = contrastRatio(foreground, background, typeof base === 'string' ? base : undefined);
189
+ if (ratio < pair.target) {
190
+ // Floored so a reported ratio never reads as passing (4.499 → 4.49).
191
+ failures.push({
192
+ ...pair,
193
+ ratio: Math.floor(ratio * 100) / 100
194
+ });
195
+ }
196
+ }
197
+ return failures;
198
+ }
199
+ //# sourceMappingURL=contrast.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_parse","require","TEXT_CONTRAST","exports","NON_TEXT_CONTRAST","WHITE","r","g","b","a","LUMINANCE_OFFSET","ACCENT_ROLES","SEMANTIC_ROLES","BASE_BACKGROUNDS","SURFACE_TIERS","capitalize","value","charAt","toUpperCase","slice","onBase","foreground","target","map","background","guaranteedPairs","theme","pairs","role","push","on","tier","tones","readPath","isRecord","name","Object","keys","tone","text","categorical","Array","isArray","forEach","_","index","source","path","split","reduce","node","key","Number","undefined","channelLuminance","channel","relativeLuminance","composite","top","bottom","mix","upper","lower","contrastRatio","base","fg","parseColor","bg","baseColor","Error","opaqueBackground","opaqueForeground","lighter","Math","max","darker","min","auditTheme","failures","pair","ratio","floor"],"sourceRoot":"../../../src","sources":["color/contrast.ts"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA;AACO,MAAMC,aAAa,GAAAC,OAAA,CAAAD,aAAA,GAAG,GAAG;AAChC;AACO,MAAME,iBAAiB,GAAAD,OAAA,CAAAC,iBAAA,GAAG,CAAC;AAElC,MAAMC,KAAW,GAAG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/B,QAAQ,CAACP,KAAK,EAAE,kBAAkB,CAAC;EAChD,MAAMoD,QAA2B,GAAG,EAAE;EAEtC,KAAK,MAAMC,IAAI,IAAItD,eAAe,CAACC,KAAK,CAAC,EAAE;IAC1C,MAAML,UAAU,GAAGY,QAAQ,CAACP,KAAK,EAAEqD,IAAI,CAAC1D,UAAU,CAAC;IACnD,MAAMG,UAAU,GAAGS,QAAQ,CAACP,KAAK,EAAEqD,IAAI,CAACvD,UAAU,CAAC;IAEnD,IAAI,OAAOH,UAAU,KAAK,QAAQ,IAAI,OAAOG,UAAU,KAAK,QAAQ,EAAE;MACrE;IACD;IAEA,MAAMwD,KAAK,GAAGjB,aAAa,CAC1B1C,UAAU,EACVG,UAAU,EACV,OAAOwC,IAAI,KAAK,QAAQ,GAAGA,IAAI,GAAGX,SACnC,CAAC;IAED,IAAI2B,KAAK,GAAGD,IAAI,CAACzD,MAAM,EAAE;MACxB;MACAwD,QAAQ,CAACjD,IAAI,CAAC;QAAE,GAAGkD,IAAI;QAAEC,KAAK,EAAEP,IAAI,CAACQ,KAAK,CAACD,KAAK,GAAG,GAAG,CAAC,GAAG;MAAI,CAAC,CAAC;IACjE;EACD;EAEA,OAAOF,QAAQ;AAChB","ignoreList":[]}
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.argbFromColor = argbFromColor;
7
+ exports.formatColor = formatColor;
8
+ exports.hexFromArgb = hexFromArgb;
9
+ exports.isOpaqueColor = isOpaqueColor;
10
+ exports.isValidColor = isValidColor;
11
+ exports.parseColor = parseColor;
12
+ exports.withAlpha = withAlpha;
13
+ var _index = require("../vendor/mcu/index.js");
14
+ /** A colour channel set: red/green/blue 0–255, alpha 0–1. */
15
+
16
+ const HEX_PATTERN = /^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
17
+ const RGB_PATTERN = /^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(\d*\.?\d+)\s*)?\)$/i;
18
+ const CHANNEL_MAX = 255;
19
+
20
+ /**
21
+ * Parses the colour formats the package accepts: `#RGB`, `#RGBA`, `#RRGGBB`,
22
+ * `#RRGGBBAA`, `rgb(r, g, b)` and `rgba(r, g, b, a)`. Returns `null` for
23
+ * anything else, including named colours and `hsl()`.
24
+ */
25
+ function parseColor(value) {
26
+ if (typeof value !== 'string') {
27
+ return null;
28
+ }
29
+ const color = value.trim();
30
+ const hex = HEX_PATTERN.exec(color);
31
+ if (hex) {
32
+ return parseHex(hex[1]);
33
+ }
34
+ const rgb = RGB_PATTERN.exec(color);
35
+ if (!rgb) {
36
+ return null;
37
+ }
38
+ const [r, g, b] = [rgb[1], rgb[2], rgb[3]].map(Number);
39
+ const a = rgb[4] == null ? 1 : Number(rgb[4]);
40
+ if ([r, g, b].some(channel => channel > CHANNEL_MAX) || a > 1) {
41
+ return null;
42
+ }
43
+ return {
44
+ r,
45
+ g,
46
+ b,
47
+ a
48
+ };
49
+ }
50
+ function parseHex(digits) {
51
+ const full = digits.length <= 4 ? digits.split('').map(digit => digit + digit).join('') : digits;
52
+ const channel = index => parseInt(full.slice(index * 2, index * 2 + 2), 16);
53
+ return {
54
+ r: channel(0),
55
+ g: channel(1),
56
+ b: channel(2),
57
+ a: full.length === 8 ? channel(3) / CHANNEL_MAX : 1
58
+ };
59
+ }
60
+ function isValidColor(value) {
61
+ return parseColor(value) !== null;
62
+ }
63
+ function isOpaqueColor(value) {
64
+ return parseColor(value)?.a === 1;
65
+ }
66
+
67
+ /** ARGB integer of an opaque colour string; throws for anything else. */
68
+ function argbFromColor(value) {
69
+ const rgba = parseColor(value);
70
+ if (!rgba || rgba.a !== 1) {
71
+ throw new Error(`Expected an opaque colour, received "${value}".`);
72
+ }
73
+ return (0, _index.argbFromRgb)(rgba.r, rgba.g, rgba.b);
74
+ }
75
+ function toHexPair(channel) {
76
+ return Math.round(channel).toString(16).padStart(2, '0').toUpperCase();
77
+ }
78
+ function hexFromArgb(argb) {
79
+ // eslint-disable-next-line no-bitwise -- unpacking the ARGB integer's channels
80
+ const [r, g, b] = [argb >> 16 & 0xff, argb >> 8 & 0xff, argb & 0xff];
81
+ return `#${toHexPair(r)}${toHexPair(g)}${toHexPair(b)}`;
82
+ }
83
+ function formatColor({
84
+ r,
85
+ g,
86
+ b,
87
+ a
88
+ }) {
89
+ const rgb = `#${toHexPair(r)}${toHexPair(g)}${toHexPair(b)}`;
90
+ return a >= 1 ? rgb : `${rgb}${toHexPair(a * CHANNEL_MAX)}`;
91
+ }
92
+
93
+ /**
94
+ * Applies an opacity to a colour, multiplying any alpha it already has.
95
+ * Returns `#RRGGBBAA` (or `#RRGGBB` when the result is opaque).
96
+ */
97
+ function withAlpha(color, alpha) {
98
+ const rgba = parseColor(color);
99
+ if (!rgba) {
100
+ throw new Error(`withAlpha: "${color}" is not a supported colour.`);
101
+ }
102
+ if (!Number.isFinite(alpha) || alpha < 0 || alpha > 1) {
103
+ throw new Error(`withAlpha: alpha must be between 0 and 1, received ${alpha}.`);
104
+ }
105
+ return formatColor({
106
+ ...rgba,
107
+ a: rgba.a * alpha
108
+ });
109
+ }
110
+ //# sourceMappingURL=parse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_index","require","HEX_PATTERN","RGB_PATTERN","CHANNEL_MAX","parseColor","value","color","trim","hex","exec","parseHex","rgb","r","g","b","map","Number","a","some","channel","digits","full","length","split","digit","join","index","parseInt","slice","isValidColor","isOpaqueColor","argbFromColor","rgba","Error","argbFromRgb","toHexPair","Math","round","toString","padStart","toUpperCase","hexFromArgb","argb","formatColor","withAlpha","alpha","isFinite"],"sourceRoot":"../../../src","sources":["color/parse.ts"],"mappings":";;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA;;AAQA,MAAMC,WAAW,GAAG,uDAAuD;AAC3E,MAAMC,WAAW,GAChB,oFAAoF;AACrF,MA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