@hanzogui/themes 2.0.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 (324) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cjs/componentThemeDefinitions.cjs +124 -0
  3. package/dist/cjs/componentThemeDefinitions.native.js +127 -0
  4. package/dist/cjs/componentThemeDefinitions.native.js.map +1 -0
  5. package/dist/cjs/generated-new.cjs +2021 -0
  6. package/dist/cjs/generated-new.native.js +2040 -0
  7. package/dist/cjs/generated-new.native.js.map +1 -0
  8. package/dist/cjs/generated-v3.cjs +1099 -0
  9. package/dist/cjs/generated-v3.native.js +1118 -0
  10. package/dist/cjs/generated-v3.native.js.map +1 -0
  11. package/dist/cjs/generated-v4-gui.cjs +933 -0
  12. package/dist/cjs/generated-v4-gui.native.js +952 -0
  13. package/dist/cjs/generated-v4-gui.native.js.map +1 -0
  14. package/dist/cjs/generated-v4.cjs +391 -0
  15. package/dist/cjs/generated-v4.native.js +410 -0
  16. package/dist/cjs/generated-v4.native.js.map +1 -0
  17. package/dist/cjs/generated-v5-subtle.cjs +549 -0
  18. package/dist/cjs/generated-v5-subtle.native.js +568 -0
  19. package/dist/cjs/generated-v5-subtle.native.js.map +1 -0
  20. package/dist/cjs/generated-v5.cjs +549 -0
  21. package/dist/cjs/generated-v5.native.js +568 -0
  22. package/dist/cjs/generated-v5.native.js.map +1 -0
  23. package/dist/cjs/helpers.cjs +34 -0
  24. package/dist/cjs/helpers.native.js +39 -0
  25. package/dist/cjs/helpers.native.js.map +1 -0
  26. package/dist/cjs/index.cjs +25 -0
  27. package/dist/cjs/index.native.js +28 -0
  28. package/dist/cjs/index.native.js.map +1 -0
  29. package/dist/cjs/opacify.cjs +96 -0
  30. package/dist/cjs/opacify.native.js +106 -0
  31. package/dist/cjs/opacify.native.js.map +1 -0
  32. package/dist/cjs/palettes.cjs +52 -0
  33. package/dist/cjs/palettes.native.js +63 -0
  34. package/dist/cjs/palettes.native.js.map +1 -0
  35. package/dist/cjs/shadows.cjs +43 -0
  36. package/dist/cjs/shadows.native.js +46 -0
  37. package/dist/cjs/shadows.native.js.map +1 -0
  38. package/dist/cjs/subtleChildrenThemes.cjs +65 -0
  39. package/dist/cjs/subtleChildrenThemes.native.js +74 -0
  40. package/dist/cjs/subtleChildrenThemes.native.js.map +1 -0
  41. package/dist/cjs/templates.cjs +118 -0
  42. package/dist/cjs/templates.native.js +121 -0
  43. package/dist/cjs/templates.native.js.map +1 -0
  44. package/dist/cjs/themes-new.cjs +86 -0
  45. package/dist/cjs/themes-new.native.js +88 -0
  46. package/dist/cjs/themes-new.native.js.map +1 -0
  47. package/dist/cjs/themes-old.cjs +284 -0
  48. package/dist/cjs/themes-old.native.js +303 -0
  49. package/dist/cjs/themes-old.native.js.map +1 -0
  50. package/dist/cjs/themes.cjs +26 -0
  51. package/dist/cjs/themes.native.js +29 -0
  52. package/dist/cjs/themes.native.js.map +1 -0
  53. package/dist/cjs/tokens.cjs +155 -0
  54. package/dist/cjs/tokens.native.js +167 -0
  55. package/dist/cjs/tokens.native.js.map +1 -0
  56. package/dist/cjs/utils.cjs +40 -0
  57. package/dist/cjs/utils.native.js +46 -0
  58. package/dist/cjs/utils.native.js.map +1 -0
  59. package/dist/cjs/v3-themes.cjs +472 -0
  60. package/dist/cjs/v3-themes.native.js +487 -0
  61. package/dist/cjs/v3-themes.native.js.map +1 -0
  62. package/dist/cjs/v3-tokens.cjs +99 -0
  63. package/dist/cjs/v3-tokens.native.js +108 -0
  64. package/dist/cjs/v3-tokens.native.js.map +1 -0
  65. package/dist/cjs/v3.cjs +52 -0
  66. package/dist/cjs/v3.native.js +55 -0
  67. package/dist/cjs/v3.native.js.map +1 -0
  68. package/dist/cjs/v4-default.cjs +167 -0
  69. package/dist/cjs/v4-default.native.js +170 -0
  70. package/dist/cjs/v4-default.native.js.map +1 -0
  71. package/dist/cjs/v4-gui.cjs +235 -0
  72. package/dist/cjs/v4-gui.native.js +243 -0
  73. package/dist/cjs/v4-gui.native.js.map +1 -0
  74. package/dist/cjs/v4-tokens.cjs +99 -0
  75. package/dist/cjs/v4-tokens.native.js +108 -0
  76. package/dist/cjs/v4-tokens.native.js.map +1 -0
  77. package/dist/cjs/v4.cjs +32 -0
  78. package/dist/cjs/v4.native.js +35 -0
  79. package/dist/cjs/v4.native.js.map +1 -0
  80. package/dist/cjs/v5-subtle.cjs +34 -0
  81. package/dist/cjs/v5-subtle.native.js +37 -0
  82. package/dist/cjs/v5-subtle.native.js.map +1 -0
  83. package/dist/cjs/v5-templates.cjs +110 -0
  84. package/dist/cjs/v5-templates.native.js +126 -0
  85. package/dist/cjs/v5-templates.native.js.map +1 -0
  86. package/dist/cjs/v5-themes-subtle.cjs +37 -0
  87. package/dist/cjs/v5-themes-subtle.native.js +40 -0
  88. package/dist/cjs/v5-themes-subtle.native.js.map +1 -0
  89. package/dist/cjs/v5-themes.cjs +400 -0
  90. package/dist/cjs/v5-themes.native.js +445 -0
  91. package/dist/cjs/v5-themes.native.js.map +1 -0
  92. package/dist/cjs/v5-tokens.cjs +99 -0
  93. package/dist/cjs/v5-tokens.native.js +108 -0
  94. package/dist/cjs/v5-tokens.native.js.map +1 -0
  95. package/dist/cjs/v5.cjs +34 -0
  96. package/dist/cjs/v5.native.js +37 -0
  97. package/dist/cjs/v5.native.js.map +1 -0
  98. package/dist/esm/componentThemeDefinitions.mjs +100 -0
  99. package/dist/esm/componentThemeDefinitions.mjs.map +1 -0
  100. package/dist/esm/componentThemeDefinitions.native.js +100 -0
  101. package/dist/esm/componentThemeDefinitions.native.js.map +1 -0
  102. package/dist/esm/generated-new.mjs +1997 -0
  103. package/dist/esm/generated-new.mjs.map +1 -0
  104. package/dist/esm/generated-new.native.js +2013 -0
  105. package/dist/esm/generated-new.native.js.map +1 -0
  106. package/dist/esm/generated-v3.mjs +1075 -0
  107. package/dist/esm/generated-v3.mjs.map +1 -0
  108. package/dist/esm/generated-v3.native.js +1091 -0
  109. package/dist/esm/generated-v3.native.js.map +1 -0
  110. package/dist/esm/generated-v4-gui.mjs +909 -0
  111. package/dist/esm/generated-v4-gui.mjs.map +1 -0
  112. package/dist/esm/generated-v4-gui.native.js +925 -0
  113. package/dist/esm/generated-v4-gui.native.js.map +1 -0
  114. package/dist/esm/generated-v4.mjs +367 -0
  115. package/dist/esm/generated-v4.mjs.map +1 -0
  116. package/dist/esm/generated-v4.native.js +383 -0
  117. package/dist/esm/generated-v4.native.js.map +1 -0
  118. package/dist/esm/generated-v5-subtle.mjs +525 -0
  119. package/dist/esm/generated-v5-subtle.mjs.map +1 -0
  120. package/dist/esm/generated-v5-subtle.native.js +541 -0
  121. package/dist/esm/generated-v5-subtle.native.js.map +1 -0
  122. package/dist/esm/generated-v5.mjs +525 -0
  123. package/dist/esm/generated-v5.mjs.map +1 -0
  124. package/dist/esm/generated-v5.native.js +541 -0
  125. package/dist/esm/generated-v5.native.js.map +1 -0
  126. package/dist/esm/helpers.mjs +9 -0
  127. package/dist/esm/helpers.mjs.map +1 -0
  128. package/dist/esm/helpers.native.js +11 -0
  129. package/dist/esm/helpers.native.js.map +1 -0
  130. package/dist/esm/index.js +9 -0
  131. package/dist/esm/index.js.map +1 -0
  132. package/dist/esm/index.mjs +9 -0
  133. package/dist/esm/index.mjs.map +1 -0
  134. package/dist/esm/index.native.js +9 -0
  135. package/dist/esm/index.native.js.map +1 -0
  136. package/dist/esm/opacify.mjs +72 -0
  137. package/dist/esm/opacify.mjs.map +1 -0
  138. package/dist/esm/opacify.native.js +79 -0
  139. package/dist/esm/opacify.native.js.map +1 -0
  140. package/dist/esm/palettes.mjs +29 -0
  141. package/dist/esm/palettes.mjs.map +1 -0
  142. package/dist/esm/palettes.native.js +37 -0
  143. package/dist/esm/palettes.native.js.map +1 -0
  144. package/dist/esm/shadows.mjs +20 -0
  145. package/dist/esm/shadows.mjs.map +1 -0
  146. package/dist/esm/shadows.native.js +20 -0
  147. package/dist/esm/shadows.native.js.map +1 -0
  148. package/dist/esm/subtleChildrenThemes.mjs +41 -0
  149. package/dist/esm/subtleChildrenThemes.mjs.map +1 -0
  150. package/dist/esm/subtleChildrenThemes.native.js +47 -0
  151. package/dist/esm/subtleChildrenThemes.native.js.map +1 -0
  152. package/dist/esm/templates.mjs +94 -0
  153. package/dist/esm/templates.mjs.map +1 -0
  154. package/dist/esm/templates.native.js +94 -0
  155. package/dist/esm/templates.native.js.map +1 -0
  156. package/dist/esm/themes-new.mjs +63 -0
  157. package/dist/esm/themes-new.mjs.map +1 -0
  158. package/dist/esm/themes-new.native.js +62 -0
  159. package/dist/esm/themes-new.native.js.map +1 -0
  160. package/dist/esm/themes-old.mjs +261 -0
  161. package/dist/esm/themes-old.mjs.map +1 -0
  162. package/dist/esm/themes-old.native.js +277 -0
  163. package/dist/esm/themes-old.native.js.map +1 -0
  164. package/dist/esm/themes.mjs +3 -0
  165. package/dist/esm/themes.mjs.map +1 -0
  166. package/dist/esm/themes.native.js +3 -0
  167. package/dist/esm/themes.native.js.map +1 -0
  168. package/dist/esm/tokens.mjs +124 -0
  169. package/dist/esm/tokens.mjs.map +1 -0
  170. package/dist/esm/tokens.native.js +133 -0
  171. package/dist/esm/tokens.native.js.map +1 -0
  172. package/dist/esm/utils.mjs +14 -0
  173. package/dist/esm/utils.mjs.map +1 -0
  174. package/dist/esm/utils.native.js +17 -0
  175. package/dist/esm/utils.native.js.map +1 -0
  176. package/dist/esm/v3-themes.mjs +444 -0
  177. package/dist/esm/v3-themes.mjs.map +1 -0
  178. package/dist/esm/v3-themes.native.js +456 -0
  179. package/dist/esm/v3-themes.native.js.map +1 -0
  180. package/dist/esm/v3-tokens.mjs +70 -0
  181. package/dist/esm/v3-tokens.mjs.map +1 -0
  182. package/dist/esm/v3-tokens.native.js +76 -0
  183. package/dist/esm/v3-tokens.native.js.map +1 -0
  184. package/dist/esm/v3.mjs +12 -0
  185. package/dist/esm/v3.mjs.map +1 -0
  186. package/dist/esm/v3.native.js +12 -0
  187. package/dist/esm/v3.native.js.map +1 -0
  188. package/dist/esm/v4-default.mjs +133 -0
  189. package/dist/esm/v4-default.mjs.map +1 -0
  190. package/dist/esm/v4-default.native.js +133 -0
  191. package/dist/esm/v4-default.native.js.map +1 -0
  192. package/dist/esm/v4-gui.mjs +201 -0
  193. package/dist/esm/v4-gui.mjs.map +1 -0
  194. package/dist/esm/v4-gui.native.js +206 -0
  195. package/dist/esm/v4-gui.native.js.map +1 -0
  196. package/dist/esm/v4-tokens.mjs +70 -0
  197. package/dist/esm/v4-tokens.mjs.map +1 -0
  198. package/dist/esm/v4-tokens.native.js +76 -0
  199. package/dist/esm/v4-tokens.native.js.map +1 -0
  200. package/dist/esm/v4.mjs +6 -0
  201. package/dist/esm/v4.mjs.map +1 -0
  202. package/dist/esm/v4.native.js +6 -0
  203. package/dist/esm/v4.native.js.map +1 -0
  204. package/dist/esm/v5-subtle.mjs +7 -0
  205. package/dist/esm/v5-subtle.mjs.map +1 -0
  206. package/dist/esm/v5-subtle.native.js +7 -0
  207. package/dist/esm/v5-subtle.native.js.map +1 -0
  208. package/dist/esm/v5-templates.mjs +87 -0
  209. package/dist/esm/v5-templates.mjs.map +1 -0
  210. package/dist/esm/v5-templates.native.js +100 -0
  211. package/dist/esm/v5-templates.native.js.map +1 -0
  212. package/dist/esm/v5-themes-subtle.mjs +13 -0
  213. package/dist/esm/v5-themes-subtle.mjs.map +1 -0
  214. package/dist/esm/v5-themes-subtle.native.js +13 -0
  215. package/dist/esm/v5-themes-subtle.native.js.map +1 -0
  216. package/dist/esm/v5-themes.mjs +361 -0
  217. package/dist/esm/v5-themes.mjs.map +1 -0
  218. package/dist/esm/v5-themes.native.js +403 -0
  219. package/dist/esm/v5-themes.native.js.map +1 -0
  220. package/dist/esm/v5-tokens.mjs +70 -0
  221. package/dist/esm/v5-tokens.mjs.map +1 -0
  222. package/dist/esm/v5-tokens.native.js +76 -0
  223. package/dist/esm/v5-tokens.native.js.map +1 -0
  224. package/dist/esm/v5.mjs +7 -0
  225. package/dist/esm/v5.mjs.map +1 -0
  226. package/dist/esm/v5.native.js +7 -0
  227. package/dist/esm/v5.native.js.map +1 -0
  228. package/package.json +95 -0
  229. package/src/componentThemeDefinitions.tsx +129 -0
  230. package/src/generated-new.ts +2571 -0
  231. package/src/generated-v3.ts +1826 -0
  232. package/src/generated-v4-gui.ts +2200 -0
  233. package/src/generated-v4.ts +1004 -0
  234. package/src/generated-v5-subtle.ts +2170 -0
  235. package/src/generated-v5.ts +2188 -0
  236. package/src/helpers.ts +44 -0
  237. package/src/index.tsx +8 -0
  238. package/src/opacify.ts +125 -0
  239. package/src/palettes.tsx +91 -0
  240. package/src/shadows.tsx +19 -0
  241. package/src/subtleChildrenThemes.ts +54 -0
  242. package/src/templates.tsx +104 -0
  243. package/src/themes-new.ts +74 -0
  244. package/src/themes-old.tsx +378 -0
  245. package/src/themes.tsx +1 -0
  246. package/src/tokens.tsx +199 -0
  247. package/src/utils.ts +51 -0
  248. package/src/v3-themes.ts +650 -0
  249. package/src/v3-tokens.ts +103 -0
  250. package/src/v3.tsx +12 -0
  251. package/src/v4-default.ts +191 -0
  252. package/src/v4-gui.ts +287 -0
  253. package/src/v4-tokens.ts +105 -0
  254. package/src/v4.tsx +4 -0
  255. package/src/v5-subtle.tsx +11 -0
  256. package/src/v5-templates.ts +126 -0
  257. package/src/v5-themes-subtle.ts +18 -0
  258. package/src/v5-themes.ts +626 -0
  259. package/src/v5-tokens.ts +107 -0
  260. package/src/v5.tsx +11 -0
  261. package/tests/v5-themes.test.ts +215 -0
  262. package/tsconfig.json +43 -0
  263. package/types/componentThemeDefinitions.d.ts +771 -0
  264. package/types/generated-new.d.ts +135 -0
  265. package/types/generated-v3.d.ts +144 -0
  266. package/types/generated-v4-gui.d.ts +190 -0
  267. package/types/generated-v4.d.ts +137 -0
  268. package/types/generated-v5-subtle.d.ts +244 -0
  269. package/types/generated-v5.d.ts +244 -0
  270. package/types/helpers.d.ts +24 -0
  271. package/types/index.d.ts +9 -0
  272. package/types/opacify.d.ts +9 -0
  273. package/types/palettes.d.ts +21 -0
  274. package/types/shadows.d.ts +15 -0
  275. package/types/subtleChildrenThemes.d.ts +305 -0
  276. package/types/templates.d.ts +155 -0
  277. package/types/themes-new.d.ts +42243 -0
  278. package/types/themes-old.d.ts +51411 -0
  279. package/types/themes.d.ts +2 -0
  280. package/types/tokens.d.ts +1308 -0
  281. package/types/utils.d.ts +21 -0
  282. package/types/v3-themes.d.ts +16304 -0
  283. package/types/v3-tokens.d.ts +184 -0
  284. package/types/v3.d.ts +11 -0
  285. package/types/v4-default.d.ts +274 -0
  286. package/types/v4-gui.d.ts +195 -0
  287. package/types/v4-tokens.d.ts +184 -0
  288. package/types/v4.d.ts +5 -0
  289. package/types/v5-subtle.d.ts +8 -0
  290. package/types/v5-templates.d.ts +42 -0
  291. package/types/v5-themes-subtle.d.ts +250 -0
  292. package/types/v5-themes.d.ts +752 -0
  293. package/types/v5-tokens.d.ts +185 -0
  294. package/types/v5.d.ts +8 -0
  295. package/v3/index.cjs +2 -0
  296. package/v3/index.js +2 -0
  297. package/v3/index.native.cjs +2 -0
  298. package/v3/index.native.js +2 -0
  299. package/v3-themes/index.cjs +2 -0
  300. package/v3-themes/index.js +2 -0
  301. package/v3-themes/index.native.cjs +2 -0
  302. package/v3-themes/index.native.js +2 -0
  303. package/v3-themes.cjs +1 -0
  304. package/v3-themes.d.ts +1 -0
  305. package/v3.cjs +1 -0
  306. package/v3.d.ts +1 -0
  307. package/v4/index.cjs +2 -0
  308. package/v4/index.js +2 -0
  309. package/v4/index.native.cjs +2 -0
  310. package/v4/index.native.js +2 -0
  311. package/v4.cjs +1 -0
  312. package/v4.d.ts +1 -0
  313. package/v5/index.cjs +2 -0
  314. package/v5/index.js +2 -0
  315. package/v5/index.native.cjs +2 -0
  316. package/v5/index.native.js +2 -0
  317. package/v5-subtle/index.cjs +2 -0
  318. package/v5-subtle/index.js +2 -0
  319. package/v5-subtle/index.native.cjs +2 -0
  320. package/v5-subtle/index.native.js +2 -0
  321. package/v5-subtle.cjs +1 -0
  322. package/v5-subtle.d.ts +1 -0
  323. package/v5.cjs +1 -0
  324. package/v5.d.ts +1 -0
package/src/helpers.ts ADDED
@@ -0,0 +1,44 @@
1
+ type ObjectType = Record<PropertyKey, unknown>
2
+
3
+ type PickByValue<OBJ_T, VALUE_T> = // From https://stackoverflow.com/a/55153000
4
+ Pick<OBJ_T, { [K in keyof OBJ_T]: OBJ_T[K] extends VALUE_T ? K : never }[keyof OBJ_T]>
5
+
6
+ type ObjectEntries<OBJ_T> = // From https://stackoverflow.com/a/60142095
7
+ { [K in keyof OBJ_T]: [keyof PickByValue<OBJ_T, OBJ_T[K]>, OBJ_T[K]] }[keyof OBJ_T][]
8
+
9
+ export const objectKeys = <O extends object>(obj: O) => Object.keys(obj) as Array<keyof O>
10
+
11
+ export function objectEntries<OBJ_T extends ObjectType>(
12
+ obj: OBJ_T
13
+ ): ObjectEntries<OBJ_T> {
14
+ return Object.entries(obj) as ObjectEntries<OBJ_T>
15
+ }
16
+
17
+ type EntriesType =
18
+ | [PropertyKey, unknown][]
19
+ | ReadonlyArray<readonly [PropertyKey, unknown]>
20
+
21
+ // Existing Utils
22
+ type DeepWritable<OBJ_T> = { -readonly [P in keyof OBJ_T]: DeepWritable<OBJ_T[P]> }
23
+ type UnionToIntersection<UNION_T> = // From https://stackoverflow.com/a/50375286
24
+ (UNION_T extends any ? (k: UNION_T) => void : never) extends (k: infer I) => void
25
+ ? I
26
+ : never
27
+
28
+ // New Utils
29
+ type UnionObjectFromArrayOfPairs<ARR_T extends EntriesType> =
30
+ DeepWritable<ARR_T> extends (infer R)[]
31
+ ? R extends [infer key, infer val]
32
+ ? { [prop in key & PropertyKey]: val }
33
+ : never
34
+ : never
35
+ type MergeIntersectingObjects<ObjT> = { [key in keyof ObjT]: ObjT[key] }
36
+ type EntriesToObject<ARR_T extends EntriesType> = MergeIntersectingObjects<
37
+ UnionToIntersection<UnionObjectFromArrayOfPairs<ARR_T>>
38
+ >
39
+
40
+ export function objectFromEntries<ARR_T extends EntriesType>(
41
+ arr: ARR_T
42
+ ): EntriesToObject<ARR_T> {
43
+ return Object.fromEntries(arr) as EntriesToObject<ARR_T>
44
+ }
package/src/index.tsx ADDED
@@ -0,0 +1,8 @@
1
+ export * from './themes'
2
+ export * from './tokens'
3
+ export * from './componentThemeDefinitions'
4
+ export * from './palettes'
5
+ export * from '@hanzogui/colors/legacy'
6
+ export * from './templates'
7
+ export * from './shadows'
8
+ export * from '@hanzogui/theme-builder'
package/src/opacify.ts ADDED
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Interpolate between two colors
3
+ * @param color1 - First color (hex or hsl)
4
+ * @param color2 - Second color (hex or hsl)
5
+ * @param amount - 0 = color1, 1 = color2, 0.5 = middle
6
+ */
7
+ export function interpolateColor(color1: string, color2: string, amount: number): string {
8
+ const rgb1 = parseToRgb(color1)
9
+ const rgb2 = parseToRgb(color2)
10
+ if (!rgb1 || !rgb2) return color1
11
+
12
+ const r = Math.round(rgb1.r + (rgb2.r - rgb1.r) * amount)
13
+ const g = Math.round(rgb1.g + (rgb2.g - rgb1.g) * amount)
14
+ const b = Math.round(rgb1.b + (rgb2.b - rgb1.b) * amount)
15
+
16
+ return `rgb(${r}, ${g}, ${b})`
17
+ }
18
+
19
+ function parseToRgb(color: string): { r: number; g: number; b: number } | null {
20
+ if (typeof color !== 'string') return null
21
+
22
+ // Handle hex
23
+ if (color.startsWith('#')) {
24
+ let hex = color.slice(1)
25
+ if (hex.length === 3) {
26
+ hex = hex
27
+ .split('')
28
+ .map((c) => c + c)
29
+ .join('')
30
+ }
31
+ if (hex.length >= 6) {
32
+ return {
33
+ r: Number.parseInt(hex.slice(0, 2), 16),
34
+ g: Number.parseInt(hex.slice(2, 4), 16),
35
+ b: Number.parseInt(hex.slice(4, 6), 16),
36
+ }
37
+ }
38
+ }
39
+
40
+ // Handle rgb/rgba
41
+ if (color.startsWith('rgb')) {
42
+ const match = color.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/)
43
+ if (match) {
44
+ return {
45
+ r: Number.parseInt(match[1], 10),
46
+ g: Number.parseInt(match[2], 10),
47
+ b: Number.parseInt(match[3], 10),
48
+ }
49
+ }
50
+ }
51
+
52
+ // Handle hsl/hsla
53
+ if (color.startsWith('hsl')) {
54
+ const match = color.match(/hsla?\((\d+),\s*(\d+)%,\s*(\d+)%/)
55
+ if (match) {
56
+ const h = Number.parseInt(match[1], 10)
57
+ const s = Number.parseInt(match[2], 10) / 100
58
+ const l = Number.parseInt(match[3], 10) / 100
59
+ return hslToRgb(h, s, l)
60
+ }
61
+ }
62
+
63
+ return null
64
+ }
65
+
66
+ function hslToRgb(h: number, s: number, l: number): { r: number; g: number; b: number } {
67
+ let r: number
68
+ let g: number
69
+ let b: number
70
+ if (s === 0) {
71
+ r = g = b = l
72
+ } else {
73
+ const hue2rgb = (p: number, q: number, t: number) => {
74
+ if (t < 0) t += 1
75
+ if (t > 1) t -= 1
76
+ if (t < 1 / 6) return p + (q - p) * 6 * t
77
+ if (t < 1 / 2) return q
78
+ if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6
79
+ return p
80
+ }
81
+ const q = l < 0.5 ? l * (1 + s) : l + s - l * s
82
+ const p = 2 * l - q
83
+ r = hue2rgb(p, q, h / 360 + 1 / 3)
84
+ g = hue2rgb(p, q, h / 360)
85
+ b = hue2rgb(p, q, h / 360 - 1 / 3)
86
+ }
87
+ return { r: Math.round(r * 255), g: Math.round(g * 255), b: Math.round(b * 255) }
88
+ }
89
+
90
+ export function opacify(color: string, opacity = 0.1): string {
91
+ // Handle dynamic color objects (from $theme-dark/$theme-light)
92
+ if (typeof color !== 'string') return color
93
+
94
+ // handle hsl/hsla
95
+ if (color.startsWith('hsl')) {
96
+ const match = color.match(/hsla?\((\d+),\s*(\d+)%,\s*(\d+)%(?:,\s*([\d.]+))?\)/)
97
+ if (match) {
98
+ const [, h, s, l] = match
99
+ return `hsla(${h}, ${s}%, ${l}%, ${opacity})`
100
+ }
101
+ }
102
+
103
+ // handle hex
104
+ if (color.startsWith('#')) {
105
+ let hex = color.slice(1)
106
+
107
+ // expand shorthand hex
108
+ if (hex.length === 3) {
109
+ hex = hex
110
+ .split('')
111
+ .map((c) => c + c)
112
+ .join('')
113
+ }
114
+
115
+ // set alpha channel to specified opacity
116
+ if (hex.length === 6 || hex.length === 8) {
117
+ const alphaHex = Math.round(opacity * 255)
118
+ .toString(16)
119
+ .padStart(2, '0')
120
+ return `#${hex.slice(0, 6)}${alphaHex}`
121
+ }
122
+ }
123
+
124
+ return color
125
+ }
@@ -0,0 +1,91 @@
1
+ import { objectFromEntries, objectKeys } from './helpers'
2
+ import { colorTokens } from './tokens'
3
+
4
+ export const palettes = (() => {
5
+ const lightTransparent = 'rgba(255,255,255,0)'
6
+ const darkTransparent = 'rgba(10,10,10,0)'
7
+
8
+ const transparent = (hsl: string, opacity = 0) =>
9
+ hsl.replace(`%)`, `%, ${opacity})`).replace(`hsl(`, `hsla(`)
10
+
11
+ const getColorPalette = (colors: object, color = colors[0]): string[] => {
12
+ const colorPalette = Object.values(colors)
13
+
14
+ // were re-ordering these
15
+ const [head, tail] = [
16
+ colorPalette.slice(0, 6),
17
+ colorPalette.slice(colorPalette.length - 5),
18
+ ]
19
+
20
+ // add our transparent colors first/last
21
+ // and make sure the last (foreground) color is white/black rather than colorful
22
+ // this is mostly for consistency with the older theme-base
23
+ return [
24
+ transparent(colorPalette[0]),
25
+ ...head,
26
+ ...tail,
27
+ color,
28
+ transparent(colorPalette[colorPalette.length - 1]),
29
+ ]
30
+ }
31
+
32
+ const lightColor = 'hsl(0, 0%, 9.0%)'
33
+ const lightPalette = [
34
+ lightTransparent,
35
+ '#fff',
36
+ '#f8f8f8',
37
+ 'hsl(0, 0%, 96.3%)',
38
+ 'hsl(0, 0%, 94.1%)',
39
+ 'hsl(0, 0%, 92.0%)',
40
+ 'hsl(0, 0%, 90.0%)',
41
+ 'hsl(0, 0%, 88.5%)',
42
+ 'hsl(0, 0%, 81.0%)',
43
+ 'hsl(0, 0%, 56.1%)',
44
+ 'hsl(0, 0%, 50.3%)',
45
+ 'hsl(0, 0%, 42.5%)',
46
+ lightColor,
47
+ darkTransparent,
48
+ ]
49
+
50
+ const darkColor = '#fff'
51
+ const darkPalette = [
52
+ darkTransparent,
53
+ '#050505',
54
+ '#151515',
55
+ '#191919',
56
+ '#232323',
57
+ '#282828',
58
+ '#323232',
59
+ '#424242',
60
+ '#494949',
61
+ '#545454',
62
+ '#626262',
63
+ '#a5a5a5',
64
+ darkColor,
65
+ lightTransparent,
66
+ ]
67
+
68
+ const lightPalettes = objectFromEntries(
69
+ objectKeys(colorTokens.light).map(
70
+ (key) =>
71
+ [`light_${key}`, getColorPalette(colorTokens.light[key], lightColor)] as const
72
+ )
73
+ )
74
+
75
+ const darkPalettes = objectFromEntries(
76
+ objectKeys(colorTokens.dark).map(
77
+ (key) => [`dark_${key}`, getColorPalette(colorTokens.dark[key], darkColor)] as const
78
+ )
79
+ )
80
+
81
+ const colorPalettes = {
82
+ ...lightPalettes,
83
+ ...darkPalettes,
84
+ }
85
+
86
+ return {
87
+ light: lightPalette,
88
+ dark: darkPalette,
89
+ ...colorPalettes,
90
+ }
91
+ })()
@@ -0,0 +1,19 @@
1
+ const lightShadowColor = 'rgba(0,0,0,0.04)'
2
+ const lightShadowColorStrong = 'rgba(0,0,0,0.085)'
3
+ const darkShadowColor = 'rgba(0,0,0,0.2)'
4
+ const darkShadowColorStrong = 'rgba(0,0,0,0.3)'
5
+
6
+ export const shadows = {
7
+ light: {
8
+ shadowColor: lightShadowColorStrong,
9
+ shadowColorHover: lightShadowColorStrong,
10
+ shadowColorPress: lightShadowColor,
11
+ shadowColorFocus: lightShadowColor,
12
+ },
13
+ dark: {
14
+ shadowColor: darkShadowColorStrong,
15
+ shadowColorHover: darkShadowColorStrong,
16
+ shadowColorPress: darkShadowColor,
17
+ shadowColorFocus: darkShadowColor,
18
+ },
19
+ }
@@ -0,0 +1,54 @@
1
+ import {
2
+ type PaletteAdjustments,
3
+ defaultChildrenThemes,
4
+ adjustPalettes,
5
+ } from './v5-themes'
6
+
7
+ export const v5SubtlePaletteAdjustments: PaletteAdjustments<
8
+ typeof defaultChildrenThemes
9
+ > = {
10
+ default: {
11
+ light: (hsl) => ({
12
+ ...hsl,
13
+ s: hsl.s * 0.9,
14
+ }),
15
+ dark: (hsl, i) => ({
16
+ ...hsl,
17
+ s: hsl.s * (i <= 4 ? 0.7 : 0.9),
18
+ }),
19
+ },
20
+ // yellow palette in radix is especially off from the rest
21
+ yellow: {
22
+ light: (hsl, i) => {
23
+ // progressively darken and desaturate toward text colors for better contrast
24
+ // i=1 is lightest bg, i=12 is darkest text
25
+ const t = (i - 1) / 11 // 0 to 1
26
+
27
+ // saturation: starts at sStart, ends at sEnd
28
+ const sStart = 0.65
29
+ const sEnd = 0.4
30
+
31
+ // lightness: starts at lStart, ends at lEnd
32
+ const lStart = 1.08
33
+ const lEnd = 0.8
34
+
35
+ return {
36
+ ...hsl,
37
+ s: hsl.s * (sStart + t * (sEnd - sStart)),
38
+ l: hsl.l * (lStart + t * (lEnd - lStart)),
39
+ }
40
+ },
41
+
42
+ dark: (hsl, i) => ({
43
+ ...hsl,
44
+ s: hsl.s * (i <= 7 ? 0.45 : 0.55),
45
+ l: hsl.l * (i <= 4 ? 0.8 : 1),
46
+ }),
47
+ },
48
+ }
49
+
50
+ export const subtleChildrenThemes = adjustPalettes(defaultChildrenThemes, {
51
+ ...v5SubtlePaletteAdjustments,
52
+ gray: undefined, // skip
53
+ neutral: undefined, // skip
54
+ })
@@ -0,0 +1,104 @@
1
+ import type { MaskOptions } from '@hanzogui/create-theme'
2
+
3
+ import { palettes } from './palettes'
4
+
5
+ const templateColorsSpecific = {
6
+ color1: 1,
7
+ color2: 2,
8
+ color3: 3,
9
+ color4: 4,
10
+ color5: 5,
11
+ color6: 6,
12
+ color7: 7,
13
+ color8: 8,
14
+ color9: 9,
15
+ color10: 10,
16
+ color11: 11,
17
+ color12: 12,
18
+ }
19
+
20
+ // templates use the palette and specify index
21
+ // negative goes backwards from end so -1 is the last item
22
+ const template = {
23
+ ...templateColorsSpecific,
24
+ // the background, color, etc keys here work like generics - they make it so you
25
+ // can publish components for others to use without mandating a specific color scale
26
+ // the @hanzogui/button Button component looks for `$background`, so you set the
27
+ // dark_red_Button theme to have a stronger background than the dark_red theme.
28
+ background: 2,
29
+ backgroundHover: 3,
30
+ backgroundPress: 4,
31
+ backgroundFocus: 5,
32
+ backgroundStrong: 1,
33
+ backgroundTransparent: 0,
34
+ color: -1,
35
+ colorHover: -2,
36
+ colorPress: -1,
37
+ colorFocus: -2,
38
+ colorTransparent: -0,
39
+ borderColor: 5,
40
+ borderColorHover: 6,
41
+ borderColorFocus: 4,
42
+ borderColorPress: 5,
43
+ placeholderColor: -4,
44
+ }
45
+
46
+ export const templates = {
47
+ base: template,
48
+ colorLight: {
49
+ ...template,
50
+ // light color themes are a bit less sensitive
51
+ borderColor: 4,
52
+ borderColorHover: 5,
53
+ borderColorFocus: 4,
54
+ borderColorPress: 4,
55
+ },
56
+ }
57
+
58
+ const shadows = {
59
+ shadowColor: 0,
60
+ shadowColorHover: 0,
61
+ shadowColorPress: 0,
62
+ shadowColorFocus: 0,
63
+ }
64
+
65
+ const colors = {
66
+ ...shadows,
67
+ color: 0,
68
+ colorHover: 0,
69
+ colorFocus: 0,
70
+ colorPress: 0,
71
+ }
72
+
73
+ const baseMaskOptions: MaskOptions = {
74
+ override: shadows,
75
+ skip: shadows,
76
+ // avoids the transparent ends
77
+ max: palettes.light.length - 2,
78
+ min: 1,
79
+ }
80
+
81
+ const skipShadowsAndSpecificColors = {
82
+ ...shadows,
83
+ ...templateColorsSpecific,
84
+ }
85
+
86
+ export const maskOptions = {
87
+ component: {
88
+ ...baseMaskOptions,
89
+ override: colors,
90
+ skip: skipShadowsAndSpecificColors,
91
+ },
92
+ alt: {
93
+ ...baseMaskOptions,
94
+ },
95
+ button: {
96
+ ...baseMaskOptions,
97
+ override: {
98
+ ...colors,
99
+ borderColor: 'transparent',
100
+ borderColorHover: 'transparent',
101
+ },
102
+ skip: skipShadowsAndSpecificColors,
103
+ },
104
+ } satisfies Record<string, MaskOptions>
@@ -0,0 +1,74 @@
1
+ import { createThemeBuilder } from '@hanzogui/theme-builder'
2
+ import { componentThemeDefinitions } from './componentThemeDefinitions'
3
+ import { masks } from '@hanzogui/theme-builder'
4
+ import { palettes } from './palettes'
5
+ import { shadows } from './shadows'
6
+ import { maskOptions, templates } from './templates'
7
+ import { darkColors, lightColors } from './tokens'
8
+
9
+ const colorThemeDefinition = (colorName: string) => [
10
+ {
11
+ parent: 'light',
12
+ palette: colorName,
13
+ template: 'colorLight',
14
+ },
15
+ {
16
+ parent: 'dark',
17
+ palette: colorName,
18
+ template: 'base',
19
+ },
20
+ ]
21
+
22
+ const themesBuilder = createThemeBuilder()
23
+ .addPalettes(palettes)
24
+ .addTemplates(templates)
25
+ .addMasks(masks)
26
+ .addThemes({
27
+ light: {
28
+ template: 'base',
29
+ palette: 'light',
30
+ nonInheritedValues: {
31
+ ...lightColors,
32
+ ...shadows.light,
33
+ },
34
+ },
35
+ dark: {
36
+ template: 'base',
37
+ palette: 'dark',
38
+ nonInheritedValues: {
39
+ ...darkColors,
40
+ ...shadows.dark,
41
+ },
42
+ },
43
+ })
44
+ .addChildThemes({
45
+ orange: colorThemeDefinition('orange'),
46
+ yellow: colorThemeDefinition('yellow'),
47
+ green: colorThemeDefinition('green'),
48
+ blue: colorThemeDefinition('blue'),
49
+ purple: colorThemeDefinition('purple'),
50
+ pink: colorThemeDefinition('pink'),
51
+ red: colorThemeDefinition('red'),
52
+ })
53
+ .addChildThemes({
54
+ alt1: {
55
+ mask: 'soften',
56
+ ...maskOptions.alt,
57
+ },
58
+ alt2: {
59
+ mask: 'soften2',
60
+ ...maskOptions.alt,
61
+ },
62
+ active: {
63
+ mask: 'soften3',
64
+ skip: {
65
+ color: 1,
66
+ },
67
+ },
68
+ })
69
+ .addChildThemes(componentThemeDefinitions, {
70
+ // to save bundle size but make alt themes not work on components
71
+ // avoidNestingWithin: ['alt1', 'alt2'],
72
+ })
73
+
74
+ export const themes = themesBuilder.build()