useColor.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. import { colorToRgba, hexToRgb, hexToRgbAlpha } from '../utils/color.js'
  2. function useHook() {
  3. const colors = {
  4. slate: {
  5. '50': '#f8fafc',
  6. '100': '#f1f5f9',
  7. '200': '#e2e8f0',
  8. '300': '#cbd5e1',
  9. '400': '#94a3b8',
  10. '500': '#64748b',
  11. '600': '#475569',
  12. '700': '#334155',
  13. '800': '#1e293b',
  14. '900': '#0f172a',
  15. '950': '#020617'
  16. },
  17. gray: {
  18. '50': '#f9fafb',
  19. '100': '#f3f4f6',
  20. '200': '#e5e7eb',
  21. '300': '#d1d5db',
  22. '400': '#9ca3af',
  23. '500': '#6b7280',
  24. '600': '#4b5563',
  25. '700': '#374151',
  26. '800': '#1f2937',
  27. '900': '#111827',
  28. '950': '#030712'
  29. },
  30. zinc: {
  31. '50': '#fafafa',
  32. '100': '#f4f4f5',
  33. '200': '#e4e4e7',
  34. '300': '#d4d4d8',
  35. '400': '#a1a1aa',
  36. '500': '#71717a',
  37. '600': '#52525b',
  38. '700': '#3f3f46',
  39. '800': '#27272a',
  40. '900': '#18181b',
  41. '950': '#09090b'
  42. },
  43. neutral: {
  44. '50': '#fafafa',
  45. '100': '#f5f5f5',
  46. '200': '#e5e5e5',
  47. '300': '#d4d4d4',
  48. '400': '#a3a3a3',
  49. '500': '#737373',
  50. '600': '#525252',
  51. '700': '#404040',
  52. '800': '#262626',
  53. '900': '#171717',
  54. '950': '#0a0a0a'
  55. },
  56. stone: {
  57. '50': '#fafaf9',
  58. '100': '#f5f5f4',
  59. '200': '#e7e5e4',
  60. '300': '#d6d3d1',
  61. '400': '#a8a29e',
  62. '500': '#78716c',
  63. '600': '#57534e',
  64. '700': '#44403c',
  65. '800': '#292524',
  66. '900': '#1c1917',
  67. '950': '#0c0a09'
  68. },
  69. red: {
  70. '50': '#fef2f2',
  71. '100': '#fee2e2',
  72. '200': '#fecaca',
  73. '300': '#fca5a5',
  74. '400': '#f87171',
  75. '500': '#ef4444',
  76. '600': '#dc2626',
  77. '700': '#b91c1c',
  78. '800': '#991b1b',
  79. '900': '#7f1d1d',
  80. '950': '#450a0a'
  81. },
  82. orange: {
  83. '50': '#fff7ed',
  84. '100': '#ffedd5',
  85. '200': '#fed7aa',
  86. '300': '#fdba74',
  87. '400': '#fb923c',
  88. '500': '#f97316',
  89. '600': '#ea580c',
  90. '700': '#c2410c',
  91. '800': '#9a3412',
  92. '900': '#7c2d12',
  93. '950': '#431407'
  94. },
  95. amber: {
  96. '50': '#fffbeb',
  97. '100': '#fef3c7',
  98. '200': '#fde68a',
  99. '300': '#fcd34d',
  100. '400': '#fbbf24',
  101. '500': '#f59e0b',
  102. '600': '#d97706',
  103. '700': '#b45309',
  104. '800': '#92400e',
  105. '900': '#78350f',
  106. '950': '#451a03'
  107. },
  108. yellow: {
  109. '50': '#fefce8',
  110. '100': '#fef9c3',
  111. '200': '#fef08a',
  112. '300': '#fde047',
  113. '400': '#facc15',
  114. '500': '#eab308',
  115. '600': '#ca8a04',
  116. '700': '#a16207',
  117. '800': '#854d0e',
  118. '900': '#713f12',
  119. '950': '#422006'
  120. },
  121. lime: {
  122. '50': '#f7fee7',
  123. '100': '#ecfccb',
  124. '200': '#d9f99d',
  125. '300': '#bef264',
  126. '400': '#a3e635',
  127. '500': '#84cc16',
  128. '600': '#65a30d',
  129. '700': '#4d7c0f',
  130. '800': '#3f6212',
  131. '900': '#365314',
  132. '950': '#1a2e05'
  133. },
  134. green: {
  135. '50': '#f0fdf4',
  136. '100': '#dcfce7',
  137. '200': '#bbf7d0',
  138. '300': '#86efac',
  139. '400': '#4ade80',
  140. '500': '#22c55e',
  141. '600': '#16a34a',
  142. '700': '#15803d',
  143. '800': '#166534',
  144. '900': '#14532d',
  145. '950': '#052e16'
  146. },
  147. emerald: {
  148. '50': '#ecfdf5',
  149. '100': '#d1fae5',
  150. '200': '#a7f3d0',
  151. '300': '#6ee7b7',
  152. '400': '#34d399',
  153. '500': '#10b981',
  154. '600': '#059669',
  155. '700': '#047857',
  156. '800': '#065f46',
  157. '900': '#064e3b',
  158. '950': '#022c22'
  159. },
  160. teal: {
  161. '50': '#f0fdfa',
  162. '100': '#ccfbf1',
  163. '200': '#99f6e4',
  164. '300': '#5eead4',
  165. '400': '#2dd4bf',
  166. '500': '#14b8a6',
  167. '600': '#0d9488',
  168. '700': '#0f766e',
  169. '800': '#115e59',
  170. '900': '#134e4a',
  171. '950': '#042f2e'
  172. },
  173. cyan: {
  174. '50': '#ecfeff',
  175. '100': '#cffafe',
  176. '200': '#a5f3fc',
  177. '300': '#67e8f9',
  178. '400': '#22d3ee',
  179. '500': '#06b6d4',
  180. '600': '#0891b2',
  181. '700': '#0e7490',
  182. '800': '#155e75',
  183. '900': '#164e63',
  184. '950': '#083344'
  185. },
  186. sky: {
  187. '50': '#f0f9ff',
  188. '100': '#e0f2fe',
  189. '200': '#bae6fd',
  190. '300': '#7dd3fc',
  191. '400': '#38bdf8',
  192. '500': '#0ea5e9',
  193. '600': '#0284c7',
  194. '700': '#0369a1',
  195. '800': '#075985',
  196. '900': '#0c4a6e',
  197. '950': '#082f49'
  198. },
  199. blue: {
  200. '50': '#eff6ff',
  201. '100': '#dbeafe',
  202. '200': '#bfdbfe',
  203. '300': '#93c5fd',
  204. '400': '#60a5fa',
  205. '500': '#3b82f6',
  206. '600': '#2563eb',
  207. '700': '#1d4ed8',
  208. '800': '#1e40af',
  209. '900': '#1e3a8a',
  210. '950': '#172554'
  211. },
  212. indigo: {
  213. '50': '#eef2ff',
  214. '100': '#e0e7ff',
  215. '200': '#c7d2fe',
  216. '300': '#a5b4fc',
  217. '400': '#818cf8',
  218. '500': '#6366f1',
  219. '600': '#4f46e5',
  220. '700': '#4338ca',
  221. '800': '#3730a3',
  222. '900': '#312e81',
  223. '950': '#1e1b4b'
  224. },
  225. violet: {
  226. '50': '#f5f3ff',
  227. '100': '#ede9fe',
  228. '200': '#ddd6fe',
  229. '300': '#c4b5fd',
  230. '400': '#a78bfa',
  231. '500': '#8b5cf6',
  232. '600': '#7c3aed',
  233. '700': '#6d28d9',
  234. '800': '#5b21b6',
  235. '900': '#4c1d95',
  236. '950': '#2e1065'
  237. },
  238. purple: {
  239. '50': '#faf5ff',
  240. '100': '#f3e8ff',
  241. '200': '#e9d5ff',
  242. '300': '#d8b4fe',
  243. '400': '#c084fc',
  244. '500': '#a855f7',
  245. '600': '#9333ea',
  246. '700': '#7e22ce',
  247. '800': '#6b21a8',
  248. '900': '#581c87',
  249. '950': '#3b0764'
  250. },
  251. fuchsia: {
  252. '50': '#fdf4ff',
  253. '100': '#fae8ff',
  254. '200': '#f5d0fe',
  255. '300': '#f0abfc',
  256. '400': '#e879f9',
  257. '500': '#d946ef',
  258. '600': '#c026d3',
  259. '700': '#a21caf',
  260. '800': '#86198f',
  261. '900': '#701a75',
  262. '950': '#4a044e'
  263. },
  264. pink: {
  265. '50': '#fdf2f8',
  266. '100': '#fce7f3',
  267. '200': '#fbcfe8',
  268. '300': '#f9a8d4',
  269. '400': '#f472b6',
  270. '500': '#ec4899',
  271. '600': '#db2777',
  272. '700': '#be185d',
  273. '800': '#9d174d',
  274. '900': '#831843',
  275. '950': '#500724'
  276. },
  277. rose: {
  278. '50': '#fff1f2',
  279. '100': '#ffe4e6',
  280. '200': '#fecdd3',
  281. '300': '#fda4af',
  282. '400': '#fb7185',
  283. '500': '#f43f5e',
  284. '600': '#e11d48',
  285. '700': '#be123c',
  286. '800': '#9f1239',
  287. '900': '#881337',
  288. '950': '#4c0519'
  289. },
  290. }
  291. function getRgba(color) {
  292. return [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9].map(alpha => ({
  293. alpha,
  294. value: colorToRgba(color, alpha)
  295. }))
  296. }
  297. let _arr = [
  298. {name: 'inherit', value: 'inherit', color: 'inherit'},
  299. {name: 'current', value: 'currentColor', color: 'currentColor'},
  300. {name: 'transparent', value: 'transparent', color: 'transparent'},
  301. {name: 'black', value: 'black', color: '#000', rgb: hexToRgb('#000'),rgbAlpha: hexToRgbAlpha('#000'), rgbas: getRgba('#000')},
  302. {name: 'white', value: 'white', color: '#fff', rgb: hexToRgb('#fff'),rgbAlpha: hexToRgbAlpha('#fff'), rgbas: getRgba('#fff')},
  303. ]
  304. for(let name in colors) {
  305. for(let i in colors[name]) {
  306. _arr.push({
  307. name: `${name}-${i}`,
  308. value: `var(--color-${name}-${i})`,
  309. color: colors[name][i],
  310. rgb: hexToRgb(colors[name][i]),
  311. rgbAlpha: hexToRgbAlpha(colors[name][i]),
  312. rgbas: getRgba(colors[name][i]),
  313. var: 1,
  314. })
  315. }
  316. }
  317. // console.log(11, colors);
  318. // $roses: '#fff1f2','#ffe4e6','#fecdd3','#fda4af','#fb7185','#f43f5e','#e11d48','#be123c','#9f1239','#881337','#4c0519';
  319. // $colorNames: ('slate': $slates,'gray': $grays,'zinc': $zincs,'neutral': $neutrals,'stone': $stones,'red': $reds,'orange': $oranges,'amber': $ambers,'yellow': $yellows,'lime': $limes,'green': $greens,'emerald': $emeralds,'teal': $teals,'cyan': $cyans,'sky': $skys,'blue': $blues,'indigo': $indigos,'violet': $violets,'purple': $purples,'fuchsia': $fuchsias,'pink': $pinks,'rose': $roses);
  320. // $colorIndexes: 50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950;
  321. function getScssColors() {
  322. let _colors = {}
  323. let colorIndexes = []
  324. for(let name in colors) {
  325. let cArr = []
  326. for(let num in colors[name]) {
  327. const val = colors[name][num]
  328. cArr.push(hexToRgbAlpha(val))
  329. if(name == 'red') {
  330. colorIndexes.push(num - 0)
  331. }
  332. }
  333. _colors[name] = cArr
  334. }
  335. return {_colors, colorIndexes}
  336. }
  337. function getScss() {
  338. const {_colors, colorIndexes} = getScssColors()
  339. console.log(_colors);
  340. console.log(`$indexes: ${colorIndexes.join(',')};`)
  341. let colorStr = ``;
  342. let names = `$names:(`
  343. for(let name in _colors) {
  344. let val = _colors[name]
  345. colorStr += `$${name}: ${val.map(v => `'${v}'`).join(',')};\n`
  346. names += `'${name}': $${name},`
  347. }
  348. names += `);`
  349. console.log(colorStr, names)
  350. }
  351. // getScss()
  352. return {
  353. colors, color: _arr
  354. }
  355. }
  356. export default useHook