@lukso/web-components 1.6.3 → 1.7.4

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 (329) hide show
  1. package/dist/color-palette.cjs +1363 -0
  2. package/dist/{shared/utils/color-palette.d.ts → color-palette.d.ts} +1 -2
  3. package/dist/color-palette.d.ts.map +1 -0
  4. package/dist/color-palette.js +1356 -0
  5. package/dist/components/index.cjs +74 -0
  6. package/dist/components/index.d.ts +2 -1
  7. package/dist/components/index.d.ts.map +1 -1
  8. package/dist/components/index.js +17 -7354
  9. package/dist/components/lukso-button/index.cjs +144 -0
  10. package/dist/components/lukso-button/index.js +95 -1190
  11. package/dist/components/lukso-card/index.cjs +143 -0
  12. package/dist/components/lukso-card/index.js +61 -1487
  13. package/dist/components/lukso-icon/index.cjs +4366 -0
  14. package/dist/components/lukso-icon/index.js +1713 -2410
  15. package/dist/components/lukso-input/index.cjs +219 -0
  16. package/dist/components/lukso-input/index.d.ts +1 -2
  17. package/dist/components/lukso-input/index.d.ts.map +1 -1
  18. package/dist/components/lukso-input/index.js +128 -1229
  19. package/dist/components/lukso-modal/index.cjs +70 -0
  20. package/dist/components/lukso-modal/index.d.ts +18 -0
  21. package/dist/components/lukso-modal/index.d.ts.map +1 -0
  22. package/dist/components/lukso-modal/index.js +68 -0
  23. package/dist/components/lukso-navbar/index.cjs +75 -0
  24. package/dist/components/lukso-navbar/index.d.ts.map +1 -1
  25. package/dist/components/lukso-navbar/index.js +45 -1155
  26. package/dist/components/lukso-profile/index.cjs +547 -0
  27. package/dist/components/lukso-profile/index.js +483 -1370
  28. package/dist/components/lukso-sanitize/index.cjs +1730 -0
  29. package/dist/components/lukso-sanitize/index.js +1643 -1544
  30. package/dist/components/lukso-tag/index.cjs +78 -0
  31. package/dist/components/lukso-tag/index.js +52 -1189
  32. package/dist/components/lukso-test/index.cjs +120 -0
  33. package/dist/components/lukso-test/index.js +65 -1767
  34. package/dist/components/lukso-username/index.cjs +126 -0
  35. package/dist/components/lukso-username/index.js +75 -1206
  36. package/dist/components/lukso-wizard/index.cjs +93 -0
  37. package/dist/components/lukso-wizard/index.js +47 -1253
  38. package/dist/directive-9ec64c08.js +28 -0
  39. package/dist/directive-db00f5fb.cjs +34 -0
  40. package/dist/index-3a24432e.js +59 -0
  41. package/dist/index-4a1ee696.cjs +67 -0
  42. package/dist/index-714323c9.js +18 -0
  43. package/dist/index-7dc05ee5.cjs +20 -0
  44. package/dist/index.cjs +74 -0
  45. package/dist/index.js +17 -7354
  46. package/dist/shared/tailwind-element/index.cjs +10 -0
  47. package/dist/shared/tailwind-element/index.js +1 -1064
  48. package/dist/state-7fde94d1.js +9 -0
  49. package/dist/state-a62a7d5d.cjs +11 -0
  50. package/dist/style-map-17d4829d.cjs +12 -0
  51. package/dist/style-map-52bada0b.js +10 -0
  52. package/dist/styles/main.css.map +1 -1
  53. package/package.json +85 -147
  54. package/tools/assets/fonts/index.cjs +10 -0
  55. package/tools/assets/fonts/index.d.ts +2 -0
  56. package/tools/assets/fonts/index.d.ts.map +1 -0
  57. package/tools/assets/fonts/index.js +6 -0
  58. package/tools/assets/images/index.cjs +10 -0
  59. package/tools/assets/images/index.d.ts +2 -0
  60. package/tools/assets/images/index.d.ts.map +1 -0
  61. package/tools/assets/images/index.js +6 -0
  62. package/tools/assets/index.cjs +15 -0
  63. package/tools/assets/index.d.ts +4 -0
  64. package/tools/assets/index.d.ts.map +1 -0
  65. package/tools/assets/index.js +9 -0
  66. package/tools/color-palette-a34f5d09.js +1356 -0
  67. package/tools/color-palette-bf5780ed.cjs +1362 -0
  68. package/tools/color-palette.cjs +11 -146
  69. package/tools/color-palette.d.ts +39 -52
  70. package/tools/color-palette.d.ts.map +1 -1
  71. package/tools/color-palette.js +1 -0
  72. package/tools/copy-assets.cjs +50 -136
  73. package/tools/copy-assets.d.ts +7 -9
  74. package/tools/copy-assets.d.ts.map +1 -1
  75. package/tools/copy-assets.js +49 -0
  76. package/tools/index.cjs +35 -0
  77. package/tools/index.d.ts +6 -0
  78. package/tools/index.d.ts.map +1 -0
  79. package/tools/index.js +22 -0
  80. package/tools/sass/index.cjs +7 -0
  81. package/tools/sass/index.js +1 -0
  82. package/tools/styles/index.cjs +5 -0
  83. package/tools/styles/index.js +3 -0
  84. package/tools/styles/main.css +287 -0
  85. package/CHANGELOG.md +0 -287
  86. package/dist/assets/fonts/index.js +0 -4
  87. package/dist/assets/fonts/index.ts +0 -1
  88. package/dist/assets/fonts/index.umd.cjs +0 -1
  89. package/dist/assets/images/index.js +0 -4
  90. package/dist/assets/images/index.ts +0 -1
  91. package/dist/assets/images/index.umd.cjs +0 -1
  92. package/dist/assets/index.js +0 -4
  93. package/dist/assets/index.ts +0 -1
  94. package/dist/assets/index.umd.cjs +0 -1
  95. package/dist/color-palette/index.js +0 -705
  96. package/dist/color-palette/index.umd.cjs +0 -1
  97. package/dist/components/index.umd.cjs +0 -3756
  98. package/dist/components/lukso-button/index.umd.cjs +0 -88
  99. package/dist/components/lukso-card/index.umd.cjs +0 -145
  100. package/dist/components/lukso-icon/index.umd.cjs +0 -3465
  101. package/dist/components/lukso-input/index.umd.cjs +0 -109
  102. package/dist/components/lukso-navbar/index.umd.cjs +0 -73
  103. package/dist/components/lukso-profile/index.umd.cjs +0 -90
  104. package/dist/components/lukso-sanitize/index.umd.cjs +0 -61
  105. package/dist/components/lukso-tag/index.umd.cjs +0 -67
  106. package/dist/components/lukso-test/index.umd.cjs +0 -95
  107. package/dist/components/lukso-username/index.umd.cjs +0 -75
  108. package/dist/components/lukso-wizard/index.umd.cjs +0 -89
  109. package/dist/index.umd.cjs +0 -3756
  110. package/dist/sass/index.js +0 -4
  111. package/dist/sass/index.ts +0 -1
  112. package/dist/sass/index.umd.cjs +0 -1
  113. package/dist/shared/assets/index.d.ts +0 -3
  114. package/dist/shared/assets/index.d.ts.map +0 -1
  115. package/dist/shared/directives/custom-class-map/index.d.ts +0 -26
  116. package/dist/shared/directives/custom-class-map/index.d.ts.map +0 -1
  117. package/dist/shared/directives/index.d.ts +0 -2
  118. package/dist/shared/directives/index.d.ts.map +0 -1
  119. package/dist/shared/styles/index.d.ts +0 -3
  120. package/dist/shared/styles/index.d.ts.map +0 -1
  121. package/dist/shared/tailwind-element/index.umd.cjs +0 -39
  122. package/dist/shared/tailwind-element.js +0 -1064
  123. package/dist/shared/tailwind-element.umd.cjs +0 -39
  124. package/dist/shared/utils/color-palette.d.ts.map +0 -1
  125. package/dist/styles/index.js +0 -4
  126. package/dist/styles/index.umd.cjs +0 -1
  127. package/src/components/index.ts +0 -13
  128. package/src/components/lukso-button/index.ts +0 -145
  129. package/src/components/lukso-button/lukso-button.stories.ts +0 -216
  130. package/src/components/lukso-card/index.ts +0 -131
  131. package/src/components/lukso-card/lukso-card.stories.ts +0 -191
  132. package/src/components/lukso-card/style.scss +0 -7
  133. package/src/components/lukso-icon/icons/add-photo.ts +0 -46
  134. package/src/components/lukso-icon/icons/arrow-down-lg.ts +0 -26
  135. package/src/components/lukso-icon/icons/arrow-down-sm.ts +0 -26
  136. package/src/components/lukso-icon/icons/arrow-left-lg.ts +0 -26
  137. package/src/components/lukso-icon/icons/arrow-left-sm.ts +0 -26
  138. package/src/components/lukso-icon/icons/arrow-right-lg.ts +0 -26
  139. package/src/components/lukso-icon/icons/arrow-right-sm.ts +0 -26
  140. package/src/components/lukso-icon/icons/arrow-up-lg.ts +0 -26
  141. package/src/components/lukso-icon/icons/arrow-up-sm.ts +0 -26
  142. package/src/components/lukso-icon/icons/barbell-outline.ts +0 -54
  143. package/src/components/lukso-icon/icons/bulb-outline.ts +0 -54
  144. package/src/components/lukso-icon/icons/camera.ts +0 -40
  145. package/src/components/lukso-icon/icons/clipboard.ts +0 -59
  146. package/src/components/lukso-icon/icons/clock.ts +0 -31
  147. package/src/components/lukso-icon/icons/close-lg.ts +0 -33
  148. package/src/components/lukso-icon/icons/close-sm.ts +0 -33
  149. package/src/components/lukso-icon/icons/cloud.ts +0 -25
  150. package/src/components/lukso-icon/icons/compass-outline.ts +0 -29
  151. package/src/components/lukso-icon/icons/complete-filled-fade-in.ts +0 -34
  152. package/src/components/lukso-icon/icons/complete-filled.ts +0 -32
  153. package/src/components/lukso-icon/icons/complete-outline.ts +0 -31
  154. package/src/components/lukso-icon/icons/connect.ts +0 -33
  155. package/src/components/lukso-icon/icons/connections.ts +0 -34
  156. package/src/components/lukso-icon/icons/contract-lock.ts +0 -43
  157. package/src/components/lukso-icon/icons/controller.ts +0 -55
  158. package/src/components/lukso-icon/icons/copy.ts +0 -31
  159. package/src/components/lukso-icon/icons/cross-outline.ts +0 -38
  160. package/src/components/lukso-icon/icons/dots.ts +0 -22
  161. package/src/components/lukso-icon/icons/edit.ts +0 -30
  162. package/src/components/lukso-icon/icons/error.ts +0 -31
  163. package/src/components/lukso-icon/icons/eth-logo.ts +0 -50
  164. package/src/components/lukso-icon/icons/expand.ts +0 -31
  165. package/src/components/lukso-icon/icons/extension.ts +0 -31
  166. package/src/components/lukso-icon/icons/eye-hide.ts +0 -47
  167. package/src/components/lukso-icon/icons/eye-show.ts +0 -37
  168. package/src/components/lukso-icon/icons/filter.ts +0 -43
  169. package/src/components/lukso-icon/icons/fish-outline.ts +0 -36
  170. package/src/components/lukso-icon/icons/flip.ts +0 -45
  171. package/src/components/lukso-icon/icons/globe.ts +0 -61
  172. package/src/components/lukso-icon/icons/google-color.ts +0 -35
  173. package/src/components/lukso-icon/icons/hamburger.ts +0 -40
  174. package/src/components/lukso-icon/icons/infinite.ts +0 -33
  175. package/src/components/lukso-icon/icons/information.ts +0 -38
  176. package/src/components/lukso-icon/icons/key-outline.ts +0 -25
  177. package/src/components/lukso-icon/icons/link.ts +0 -33
  178. package/src/components/lukso-icon/icons/link1.ts +0 -39
  179. package/src/components/lukso-icon/icons/link2.ts +0 -46
  180. package/src/components/lukso-icon/icons/link3.ts +0 -32
  181. package/src/components/lukso-icon/icons/link4.ts +0 -52
  182. package/src/components/lukso-icon/icons/loading.ts +0 -50
  183. package/src/components/lukso-icon/icons/location.ts +0 -33
  184. package/src/components/lukso-icon/icons/locked.ts +0 -44
  185. package/src/components/lukso-icon/icons/login-2.ts +0 -55
  186. package/src/components/lukso-icon/icons/login-3.ts +0 -53
  187. package/src/components/lukso-icon/icons/login.ts +0 -39
  188. package/src/components/lukso-icon/icons/logo-chrome.ts +0 -35
  189. package/src/components/lukso-icon/icons/lyx-logo.ts +0 -41
  190. package/src/components/lukso-icon/icons/mail.ts +0 -33
  191. package/src/components/lukso-icon/icons/menu-1.ts +0 -71
  192. package/src/components/lukso-icon/icons/menu-2.ts +0 -61
  193. package/src/components/lukso-icon/icons/migrate.ts +0 -47
  194. package/src/components/lukso-icon/icons/minimize.ts +0 -53
  195. package/src/components/lukso-icon/icons/network.ts +0 -49
  196. package/src/components/lukso-icon/icons/notifications.ts +0 -33
  197. package/src/components/lukso-icon/icons/phone-portrait-outline.ts +0 -33
  198. package/src/components/lukso-icon/icons/pin.ts +0 -25
  199. package/src/components/lukso-icon/icons/play-filled.ts +0 -23
  200. package/src/components/lukso-icon/icons/play-outline.ts +0 -24
  201. package/src/components/lukso-icon/icons/plus.ts +0 -33
  202. package/src/components/lukso-icon/icons/profile-add.ts +0 -43
  203. package/src/components/lukso-icon/icons/profile-export.ts +0 -42
  204. package/src/components/lukso-icon/icons/profile-import.ts +0 -42
  205. package/src/components/lukso-icon/icons/profile-recovery-2.ts +0 -62
  206. package/src/components/lukso-icon/icons/profile-recovery.ts +0 -55
  207. package/src/components/lukso-icon/icons/profile-restore.ts +0 -50
  208. package/src/components/lukso-icon/icons/profile.ts +0 -29
  209. package/src/components/lukso-icon/icons/progress-complete.ts +0 -289
  210. package/src/components/lukso-icon/icons/progress-indicator.ts +0 -236
  211. package/src/components/lukso-icon/icons/pulse-dot.ts +0 -22
  212. package/src/components/lukso-icon/icons/qr-code.ts +0 -122
  213. package/src/components/lukso-icon/icons/relayer.ts +0 -40
  214. package/src/components/lukso-icon/icons/reload.ts +0 -32
  215. package/src/components/lukso-icon/icons/return-down.ts +0 -33
  216. package/src/components/lukso-icon/icons/return-left.ts +0 -33
  217. package/src/components/lukso-icon/icons/return-right.ts +0 -33
  218. package/src/components/lukso-icon/icons/return-up.ts +0 -33
  219. package/src/components/lukso-icon/icons/search.ts +0 -28
  220. package/src/components/lukso-icon/icons/settings.ts +0 -33
  221. package/src/components/lukso-icon/icons/smart-contract-doc.ts +0 -40
  222. package/src/components/lukso-icon/icons/smart-contract.ts +0 -31
  223. package/src/components/lukso-icon/icons/star-filled.ts +0 -23
  224. package/src/components/lukso-icon/icons/star-outline.ts +0 -24
  225. package/src/components/lukso-icon/icons/step-dot.ts +0 -34
  226. package/src/components/lukso-icon/icons/step-progress.ts +0 -31
  227. package/src/components/lukso-icon/icons/steps.ts +0 -40
  228. package/src/components/lukso-icon/icons/tick.ts +0 -26
  229. package/src/components/lukso-icon/icons/timer-outline.ts +0 -47
  230. package/src/components/lukso-icon/icons/transaction-receive.ts +0 -39
  231. package/src/components/lukso-icon/icons/transaction-send.ts +0 -39
  232. package/src/components/lukso-icon/icons/transfer.ts +0 -47
  233. package/src/components/lukso-icon/icons/trash.ts +0 -40
  234. package/src/components/lukso-icon/icons/turn-down.ts +0 -33
  235. package/src/components/lukso-icon/icons/turn-left.ts +0 -33
  236. package/src/components/lukso-icon/icons/turn-right.ts +0 -33
  237. package/src/components/lukso-icon/icons/turn-up.ts +0 -33
  238. package/src/components/lukso-icon/icons/unlocked.ts +0 -41
  239. package/src/components/lukso-icon/icons/wallet-outline.ts +0 -35
  240. package/src/components/lukso-icon/icons/warning-round.ts +0 -32
  241. package/src/components/lukso-icon/icons/warning-triangle.ts +0 -32
  242. package/src/components/lukso-icon/index.ts +0 -310
  243. package/src/components/lukso-icon/lukso-icon.stories.ts +0 -116
  244. package/src/components/lukso-icon/style.scss +0 -3
  245. package/src/components/lukso-input/index.ts +0 -211
  246. package/src/components/lukso-input/lukso-input.stories.ts +0 -184
  247. package/src/components/lukso-navbar/index.ts +0 -63
  248. package/src/components/lukso-navbar/lukso-navbar.stories.ts +0 -70
  249. package/src/components/lukso-profile/index.ts +0 -106
  250. package/src/components/lukso-profile/lukso-profile.stories.ts +0 -104
  251. package/src/components/lukso-sanitize/index.ts +0 -28
  252. package/src/components/lukso-sanitize/lukso-sanitize.stories.ts +0 -30
  253. package/src/components/lukso-tag/index.ts +0 -68
  254. package/src/components/lukso-tag/lukso-tag.stories.ts +0 -129
  255. package/src/components/lukso-test/index.ts +0 -72
  256. package/src/components/lukso-test/test.component.scss +0 -7
  257. package/src/components/lukso-test/test.stories.ts +0 -31
  258. package/src/components/lukso-username/index.ts +0 -105
  259. package/src/components/lukso-username/lukso-username.stories.ts +0 -98
  260. package/src/components/lukso-wizard/index.ts +0 -74
  261. package/src/components/lukso-wizard/lukso-wizard.stories.ts +0 -52
  262. package/src/docs/animations.stories.mdx +0 -83
  263. package/src/docs/colors.stories.mdx +0 -77
  264. package/src/docs/drop-shadows.stories.mdx +0 -108
  265. package/src/docs/icons.stories.mdx +0 -1590
  266. package/src/docs/typography.stories.mdx +0 -253
  267. package/src/index.ts +0 -1
  268. package/src/postcss.config.ts +0 -8
  269. package/src/shared/assets/fonts/Apax-Bold.woff2 +0 -0
  270. package/src/shared/assets/fonts/Apax-Light.woff2 +0 -0
  271. package/src/shared/assets/fonts/Apax-Medium.woff2 +0 -0
  272. package/src/shared/assets/fonts/Apax-Regular.woff2 +0 -0
  273. package/src/shared/assets/fonts/Inter-Bold.woff2 +0 -0
  274. package/src/shared/assets/fonts/Inter-ExtraBold.woff2 +0 -0
  275. package/src/shared/assets/fonts/Inter-Medium.woff2 +0 -0
  276. package/src/shared/assets/fonts/Inter-Regular.woff2 +0 -0
  277. package/src/shared/assets/fonts/Inter-SemiBold.woff2 +0 -0
  278. package/src/shared/assets/fonts/Inter-Thin.woff2 +0 -0
  279. package/src/shared/assets/fonts/PT-Mono-Bold.woff2 +0 -0
  280. package/src/shared/assets/fonts/PT-Mono-Regular.woff2 +0 -0
  281. package/src/shared/assets/fonts/index.ts +0 -1
  282. package/src/shared/assets/images/index.ts +0 -1
  283. package/src/shared/assets/images/lukso-logo.svg +0 -3
  284. package/src/shared/assets/images/profile-default.png +0 -0
  285. package/src/shared/assets/index.ts +0 -1
  286. package/src/shared/directives/custom-class-map/index.ts +0 -49
  287. package/src/shared/directives/index.ts +0 -1
  288. package/src/shared/globals.d.ts +0 -5
  289. package/src/shared/styles/colors.scss +0 -91
  290. package/src/shared/styles/component.scss +0 -13
  291. package/src/shared/styles/fonts.scss +0 -97
  292. package/src/shared/styles/index.ts +0 -1
  293. package/src/shared/styles/main.scss +0 -13
  294. package/src/shared/styles/typography.scss +0 -142
  295. package/src/shared/styles/variables.scss +0 -5
  296. package/src/shared/tailwind-element/index.ts +0 -16
  297. package/src/shared/utils/__tests__/slice-address.spec.ts +0 -15
  298. package/src/shared/utils/color-palette.ts +0 -76
  299. package/src/shared/utils/copy-assets.ts +0 -80
  300. package/src/shared/utils/hsl-color-map.ts +0 -20
  301. package/src/shared/utils/slice-address.ts +0 -30
  302. /package/{dist → tools}/assets/fonts/Apax-Bold.woff2 +0 -0
  303. /package/{dist → tools}/assets/fonts/Apax-Light.woff2 +0 -0
  304. /package/{dist → tools}/assets/fonts/Apax-Medium.woff2 +0 -0
  305. /package/{dist → tools}/assets/fonts/Apax-Regular.woff2 +0 -0
  306. /package/{dist → tools}/assets/fonts/Inter-Bold.woff2 +0 -0
  307. /package/{dist → tools}/assets/fonts/Inter-ExtraBold.woff2 +0 -0
  308. /package/{dist → tools}/assets/fonts/Inter-Medium.woff2 +0 -0
  309. /package/{dist → tools}/assets/fonts/Inter-Regular.woff2 +0 -0
  310. /package/{dist → tools}/assets/fonts/Inter-SemiBold.woff2 +0 -0
  311. /package/{dist → tools}/assets/fonts/Inter-Thin.woff2 +0 -0
  312. /package/{dist → tools}/assets/fonts/PT-Mono-Bold.woff2 +0 -0
  313. /package/{dist → tools}/assets/fonts/PT-Mono-Regular.woff2 +0 -0
  314. /package/{dist → tools}/assets/images/lukso-logo.svg +0 -0
  315. /package/{dist → tools}/assets/images/profile-default.png +0 -0
  316. /package/{dist/shared/utils → tools}/hsl-color-map.d.ts +0 -0
  317. /package/{dist/shared/utils → tools}/hsl-color-map.d.ts.map +0 -0
  318. /package/{dist → tools}/sass/colors.scss +0 -0
  319. /package/{dist → tools}/sass/component.scss +0 -0
  320. /package/{dist → tools}/sass/fonts.scss +0 -0
  321. /package/{dist/shared/assets/fonts → tools/sass}/index.d.ts +0 -0
  322. /package/{dist/shared/assets/fonts → tools/sass}/index.d.ts.map +0 -0
  323. /package/{dist → tools}/sass/main.scss +0 -0
  324. /package/{dist → tools}/sass/typography.scss +0 -0
  325. /package/{dist → tools}/sass/variables.scss +0 -0
  326. /package/{dist/shared/utils → tools}/slice-address.d.ts +0 -0
  327. /package/{dist/shared/utils → tools}/slice-address.d.ts.map +0 -0
  328. /package/{dist/shared/assets/images → tools/styles}/index.d.ts +0 -0
  329. /package/{dist/shared/assets/images → tools/styles}/index.d.ts.map +0 -0
@@ -0,0 +1,1362 @@
1
+ 'use strict';
2
+
3
+ // This file is autogenerated. It's used to publish ESM to npm.
4
+ // https://github.com/bgrins/TinyColor
5
+ // Brian Grinstead, MIT License
6
+
7
+ const trimLeft = /^\s+/;
8
+ const trimRight = /\s+$/;
9
+
10
+ function tinycolor(color, opts) {
11
+ color = color ? color : "";
12
+ opts = opts || {};
13
+
14
+ // If input is already a tinycolor, return itself
15
+ if (color instanceof tinycolor) {
16
+ return color;
17
+ }
18
+ // If we are called as a function, call using new instead
19
+ if (!(this instanceof tinycolor)) {
20
+ return new tinycolor(color, opts);
21
+ }
22
+
23
+ var rgb = inputToRGB(color);
24
+ (this._originalInput = color),
25
+ (this._r = rgb.r),
26
+ (this._g = rgb.g),
27
+ (this._b = rgb.b),
28
+ (this._a = rgb.a),
29
+ (this._roundA = Math.round(100 * this._a) / 100),
30
+ (this._format = opts.format || rgb.format);
31
+ this._gradientType = opts.gradientType;
32
+
33
+ // Don't let the range of [0,255] come back in [0,1].
34
+ // Potentially lose a little bit of precision here, but will fix issues where
35
+ // .5 gets interpreted as half of the total, instead of half of 1
36
+ // If it was supposed to be 128, this was already taken care of by `inputToRgb`
37
+ if (this._r < 1) this._r = Math.round(this._r);
38
+ if (this._g < 1) this._g = Math.round(this._g);
39
+ if (this._b < 1) this._b = Math.round(this._b);
40
+
41
+ this._ok = rgb.ok;
42
+ }
43
+
44
+ tinycolor.prototype = {
45
+ isDark: function () {
46
+ return this.getBrightness() < 128;
47
+ },
48
+ isLight: function () {
49
+ return !this.isDark();
50
+ },
51
+ isValid: function () {
52
+ return this._ok;
53
+ },
54
+ getOriginalInput: function () {
55
+ return this._originalInput;
56
+ },
57
+ getFormat: function () {
58
+ return this._format;
59
+ },
60
+ getAlpha: function () {
61
+ return this._a;
62
+ },
63
+ getBrightness: function () {
64
+ //http://www.w3.org/TR/AERT#color-contrast
65
+ var rgb = this.toRgb();
66
+ return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;
67
+ },
68
+ getLuminance: function () {
69
+ //http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
70
+ var rgb = this.toRgb();
71
+ var RsRGB, GsRGB, BsRGB, R, G, B;
72
+ RsRGB = rgb.r / 255;
73
+ GsRGB = rgb.g / 255;
74
+ BsRGB = rgb.b / 255;
75
+
76
+ if (RsRGB <= 0.03928) R = RsRGB / 12.92;
77
+ else R = Math.pow((RsRGB + 0.055) / 1.055, 2.4);
78
+ if (GsRGB <= 0.03928) G = GsRGB / 12.92;
79
+ else G = Math.pow((GsRGB + 0.055) / 1.055, 2.4);
80
+ if (BsRGB <= 0.03928) B = BsRGB / 12.92;
81
+ else B = Math.pow((BsRGB + 0.055) / 1.055, 2.4);
82
+ return 0.2126 * R + 0.7152 * G + 0.0722 * B;
83
+ },
84
+ setAlpha: function (value) {
85
+ this._a = boundAlpha(value);
86
+ this._roundA = Math.round(100 * this._a) / 100;
87
+ return this;
88
+ },
89
+ toHsv: function () {
90
+ var hsv = rgbToHsv(this._r, this._g, this._b);
91
+ return { h: hsv.h * 360, s: hsv.s, v: hsv.v, a: this._a };
92
+ },
93
+ toHsvString: function () {
94
+ var hsv = rgbToHsv(this._r, this._g, this._b);
95
+ var h = Math.round(hsv.h * 360),
96
+ s = Math.round(hsv.s * 100),
97
+ v = Math.round(hsv.v * 100);
98
+ return this._a == 1
99
+ ? "hsv(" + h + ", " + s + "%, " + v + "%)"
100
+ : "hsva(" + h + ", " + s + "%, " + v + "%, " + this._roundA + ")";
101
+ },
102
+ toHsl: function () {
103
+ var hsl = rgbToHsl(this._r, this._g, this._b);
104
+ return { h: hsl.h * 360, s: hsl.s, l: hsl.l, a: this._a };
105
+ },
106
+ toHslString: function () {
107
+ var hsl = rgbToHsl(this._r, this._g, this._b);
108
+ var h = Math.round(hsl.h * 360),
109
+ s = Math.round(hsl.s * 100),
110
+ l = Math.round(hsl.l * 100);
111
+ return this._a == 1
112
+ ? "hsl(" + h + ", " + s + "%, " + l + "%)"
113
+ : "hsla(" + h + ", " + s + "%, " + l + "%, " + this._roundA + ")";
114
+ },
115
+ toHex: function (allow3Char) {
116
+ return rgbToHex(this._r, this._g, this._b, allow3Char);
117
+ },
118
+ toHexString: function (allow3Char) {
119
+ return "#" + this.toHex(allow3Char);
120
+ },
121
+ toHex8: function (allow4Char) {
122
+ return rgbaToHex(this._r, this._g, this._b, this._a, allow4Char);
123
+ },
124
+ toHex8String: function (allow4Char) {
125
+ return "#" + this.toHex8(allow4Char);
126
+ },
127
+ toRgb: function () {
128
+ return {
129
+ r: Math.round(this._r),
130
+ g: Math.round(this._g),
131
+ b: Math.round(this._b),
132
+ a: this._a,
133
+ };
134
+ },
135
+ toRgbString: function () {
136
+ return this._a == 1
137
+ ? "rgb(" +
138
+ Math.round(this._r) +
139
+ ", " +
140
+ Math.round(this._g) +
141
+ ", " +
142
+ Math.round(this._b) +
143
+ ")"
144
+ : "rgba(" +
145
+ Math.round(this._r) +
146
+ ", " +
147
+ Math.round(this._g) +
148
+ ", " +
149
+ Math.round(this._b) +
150
+ ", " +
151
+ this._roundA +
152
+ ")";
153
+ },
154
+ toPercentageRgb: function () {
155
+ return {
156
+ r: Math.round(bound01(this._r, 255) * 100) + "%",
157
+ g: Math.round(bound01(this._g, 255) * 100) + "%",
158
+ b: Math.round(bound01(this._b, 255) * 100) + "%",
159
+ a: this._a,
160
+ };
161
+ },
162
+ toPercentageRgbString: function () {
163
+ return this._a == 1
164
+ ? "rgb(" +
165
+ Math.round(bound01(this._r, 255) * 100) +
166
+ "%, " +
167
+ Math.round(bound01(this._g, 255) * 100) +
168
+ "%, " +
169
+ Math.round(bound01(this._b, 255) * 100) +
170
+ "%)"
171
+ : "rgba(" +
172
+ Math.round(bound01(this._r, 255) * 100) +
173
+ "%, " +
174
+ Math.round(bound01(this._g, 255) * 100) +
175
+ "%, " +
176
+ Math.round(bound01(this._b, 255) * 100) +
177
+ "%, " +
178
+ this._roundA +
179
+ ")";
180
+ },
181
+ toName: function () {
182
+ if (this._a === 0) {
183
+ return "transparent";
184
+ }
185
+
186
+ if (this._a < 1) {
187
+ return false;
188
+ }
189
+
190
+ return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false;
191
+ },
192
+ toFilter: function (secondColor) {
193
+ var hex8String = "#" + rgbaToArgbHex(this._r, this._g, this._b, this._a);
194
+ var secondHex8String = hex8String;
195
+ var gradientType = this._gradientType ? "GradientType = 1, " : "";
196
+
197
+ if (secondColor) {
198
+ var s = tinycolor(secondColor);
199
+ secondHex8String = "#" + rgbaToArgbHex(s._r, s._g, s._b, s._a);
200
+ }
201
+
202
+ return (
203
+ "progid:DXImageTransform.Microsoft.gradient(" +
204
+ gradientType +
205
+ "startColorstr=" +
206
+ hex8String +
207
+ ",endColorstr=" +
208
+ secondHex8String +
209
+ ")"
210
+ );
211
+ },
212
+ toString: function (format) {
213
+ var formatSet = !!format;
214
+ format = format || this._format;
215
+
216
+ var formattedString = false;
217
+ var hasAlpha = this._a < 1 && this._a >= 0;
218
+ var needsAlphaFormat =
219
+ !formatSet &&
220
+ hasAlpha &&
221
+ (format === "hex" ||
222
+ format === "hex6" ||
223
+ format === "hex3" ||
224
+ format === "hex4" ||
225
+ format === "hex8" ||
226
+ format === "name");
227
+
228
+ if (needsAlphaFormat) {
229
+ // Special case for "transparent", all other non-alpha formats
230
+ // will return rgba when there is transparency.
231
+ if (format === "name" && this._a === 0) {
232
+ return this.toName();
233
+ }
234
+ return this.toRgbString();
235
+ }
236
+ if (format === "rgb") {
237
+ formattedString = this.toRgbString();
238
+ }
239
+ if (format === "prgb") {
240
+ formattedString = this.toPercentageRgbString();
241
+ }
242
+ if (format === "hex" || format === "hex6") {
243
+ formattedString = this.toHexString();
244
+ }
245
+ if (format === "hex3") {
246
+ formattedString = this.toHexString(true);
247
+ }
248
+ if (format === "hex4") {
249
+ formattedString = this.toHex8String(true);
250
+ }
251
+ if (format === "hex8") {
252
+ formattedString = this.toHex8String();
253
+ }
254
+ if (format === "name") {
255
+ formattedString = this.toName();
256
+ }
257
+ if (format === "hsl") {
258
+ formattedString = this.toHslString();
259
+ }
260
+ if (format === "hsv") {
261
+ formattedString = this.toHsvString();
262
+ }
263
+
264
+ return formattedString || this.toHexString();
265
+ },
266
+ clone: function () {
267
+ return tinycolor(this.toString());
268
+ },
269
+
270
+ _applyModification: function (fn, args) {
271
+ var color = fn.apply(null, [this].concat([].slice.call(args)));
272
+ this._r = color._r;
273
+ this._g = color._g;
274
+ this._b = color._b;
275
+ this.setAlpha(color._a);
276
+ return this;
277
+ },
278
+ lighten: function () {
279
+ return this._applyModification(lighten, arguments);
280
+ },
281
+ brighten: function () {
282
+ return this._applyModification(brighten, arguments);
283
+ },
284
+ darken: function () {
285
+ return this._applyModification(darken, arguments);
286
+ },
287
+ desaturate: function () {
288
+ return this._applyModification(desaturate, arguments);
289
+ },
290
+ saturate: function () {
291
+ return this._applyModification(saturate, arguments);
292
+ },
293
+ greyscale: function () {
294
+ return this._applyModification(greyscale, arguments);
295
+ },
296
+ spin: function () {
297
+ return this._applyModification(spin, arguments);
298
+ },
299
+
300
+ _applyCombination: function (fn, args) {
301
+ return fn.apply(null, [this].concat([].slice.call(args)));
302
+ },
303
+ analogous: function () {
304
+ return this._applyCombination(analogous, arguments);
305
+ },
306
+ complement: function () {
307
+ return this._applyCombination(complement, arguments);
308
+ },
309
+ monochromatic: function () {
310
+ return this._applyCombination(monochromatic, arguments);
311
+ },
312
+ splitcomplement: function () {
313
+ return this._applyCombination(splitcomplement, arguments);
314
+ },
315
+ // Disabled until https://github.com/bgrins/TinyColor/issues/254
316
+ // polyad: function (number) {
317
+ // return this._applyCombination(polyad, [number]);
318
+ // },
319
+ triad: function () {
320
+ return this._applyCombination(polyad, [3]);
321
+ },
322
+ tetrad: function () {
323
+ return this._applyCombination(polyad, [4]);
324
+ },
325
+ };
326
+
327
+ // If input is an object, force 1 into "1.0" to handle ratios properly
328
+ // String input requires "1.0" as input, so 1 will be treated as 1
329
+ tinycolor.fromRatio = function (color, opts) {
330
+ if (typeof color == "object") {
331
+ var newColor = {};
332
+ for (var i in color) {
333
+ if (color.hasOwnProperty(i)) {
334
+ if (i === "a") {
335
+ newColor[i] = color[i];
336
+ } else {
337
+ newColor[i] = convertToPercentage(color[i]);
338
+ }
339
+ }
340
+ }
341
+ color = newColor;
342
+ }
343
+
344
+ return tinycolor(color, opts);
345
+ };
346
+
347
+ // Given a string or object, convert that input to RGB
348
+ // Possible string inputs:
349
+ //
350
+ // "red"
351
+ // "#f00" or "f00"
352
+ // "#ff0000" or "ff0000"
353
+ // "#ff000000" or "ff000000"
354
+ // "rgb 255 0 0" or "rgb (255, 0, 0)"
355
+ // "rgb 1.0 0 0" or "rgb (1, 0, 0)"
356
+ // "rgba (255, 0, 0, 1)" or "rgba 255, 0, 0, 1"
357
+ // "rgba (1.0, 0, 0, 1)" or "rgba 1.0, 0, 0, 1"
358
+ // "hsl(0, 100%, 50%)" or "hsl 0 100% 50%"
359
+ // "hsla(0, 100%, 50%, 1)" or "hsla 0 100% 50%, 1"
360
+ // "hsv(0, 100%, 100%)" or "hsv 0 100% 100%"
361
+ //
362
+ function inputToRGB(color) {
363
+ var rgb = { r: 0, g: 0, b: 0 };
364
+ var a = 1;
365
+ var s = null;
366
+ var v = null;
367
+ var l = null;
368
+ var ok = false;
369
+ var format = false;
370
+
371
+ if (typeof color == "string") {
372
+ color = stringInputToObject(color);
373
+ }
374
+
375
+ if (typeof color == "object") {
376
+ if (
377
+ isValidCSSUnit(color.r) &&
378
+ isValidCSSUnit(color.g) &&
379
+ isValidCSSUnit(color.b)
380
+ ) {
381
+ rgb = rgbToRgb(color.r, color.g, color.b);
382
+ ok = true;
383
+ format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb";
384
+ } else if (
385
+ isValidCSSUnit(color.h) &&
386
+ isValidCSSUnit(color.s) &&
387
+ isValidCSSUnit(color.v)
388
+ ) {
389
+ s = convertToPercentage(color.s);
390
+ v = convertToPercentage(color.v);
391
+ rgb = hsvToRgb(color.h, s, v);
392
+ ok = true;
393
+ format = "hsv";
394
+ } else if (
395
+ isValidCSSUnit(color.h) &&
396
+ isValidCSSUnit(color.s) &&
397
+ isValidCSSUnit(color.l)
398
+ ) {
399
+ s = convertToPercentage(color.s);
400
+ l = convertToPercentage(color.l);
401
+ rgb = hslToRgb(color.h, s, l);
402
+ ok = true;
403
+ format = "hsl";
404
+ }
405
+
406
+ if (color.hasOwnProperty("a")) {
407
+ a = color.a;
408
+ }
409
+ }
410
+
411
+ a = boundAlpha(a);
412
+
413
+ return {
414
+ ok: ok,
415
+ format: color.format || format,
416
+ r: Math.min(255, Math.max(rgb.r, 0)),
417
+ g: Math.min(255, Math.max(rgb.g, 0)),
418
+ b: Math.min(255, Math.max(rgb.b, 0)),
419
+ a: a,
420
+ };
421
+ }
422
+
423
+ // Conversion Functions
424
+ // --------------------
425
+
426
+ // `rgbToHsl`, `rgbToHsv`, `hslToRgb`, `hsvToRgb` modified from:
427
+ // <http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript>
428
+
429
+ // `rgbToRgb`
430
+ // Handle bounds / percentage checking to conform to CSS color spec
431
+ // <http://www.w3.org/TR/css3-color/>
432
+ // *Assumes:* r, g, b in [0, 255] or [0, 1]
433
+ // *Returns:* { r, g, b } in [0, 255]
434
+ function rgbToRgb(r, g, b) {
435
+ return {
436
+ r: bound01(r, 255) * 255,
437
+ g: bound01(g, 255) * 255,
438
+ b: bound01(b, 255) * 255,
439
+ };
440
+ }
441
+
442
+ // `rgbToHsl`
443
+ // Converts an RGB color value to HSL.
444
+ // *Assumes:* r, g, and b are contained in [0, 255] or [0, 1]
445
+ // *Returns:* { h, s, l } in [0,1]
446
+ function rgbToHsl(r, g, b) {
447
+ r = bound01(r, 255);
448
+ g = bound01(g, 255);
449
+ b = bound01(b, 255);
450
+
451
+ var max = Math.max(r, g, b),
452
+ min = Math.min(r, g, b);
453
+ var h,
454
+ s,
455
+ l = (max + min) / 2;
456
+
457
+ if (max == min) {
458
+ h = s = 0; // achromatic
459
+ } else {
460
+ var d = max - min;
461
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
462
+ switch (max) {
463
+ case r:
464
+ h = (g - b) / d + (g < b ? 6 : 0);
465
+ break;
466
+ case g:
467
+ h = (b - r) / d + 2;
468
+ break;
469
+ case b:
470
+ h = (r - g) / d + 4;
471
+ break;
472
+ }
473
+
474
+ h /= 6;
475
+ }
476
+
477
+ return { h: h, s: s, l: l };
478
+ }
479
+
480
+ // `hslToRgb`
481
+ // Converts an HSL color value to RGB.
482
+ // *Assumes:* h is contained in [0, 1] or [0, 360] and s and l are contained [0, 1] or [0, 100]
483
+ // *Returns:* { r, g, b } in the set [0, 255]
484
+ function hslToRgb(h, s, l) {
485
+ var r, g, b;
486
+
487
+ h = bound01(h, 360);
488
+ s = bound01(s, 100);
489
+ l = bound01(l, 100);
490
+
491
+ function hue2rgb(p, q, t) {
492
+ if (t < 0) t += 1;
493
+ if (t > 1) t -= 1;
494
+ if (t < 1 / 6) return p + (q - p) * 6 * t;
495
+ if (t < 1 / 2) return q;
496
+ if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
497
+ return p;
498
+ }
499
+
500
+ if (s === 0) {
501
+ r = g = b = l; // achromatic
502
+ } else {
503
+ var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
504
+ var p = 2 * l - q;
505
+ r = hue2rgb(p, q, h + 1 / 3);
506
+ g = hue2rgb(p, q, h);
507
+ b = hue2rgb(p, q, h - 1 / 3);
508
+ }
509
+
510
+ return { r: r * 255, g: g * 255, b: b * 255 };
511
+ }
512
+
513
+ // `rgbToHsv`
514
+ // Converts an RGB color value to HSV
515
+ // *Assumes:* r, g, and b are contained in the set [0, 255] or [0, 1]
516
+ // *Returns:* { h, s, v } in [0,1]
517
+ function rgbToHsv(r, g, b) {
518
+ r = bound01(r, 255);
519
+ g = bound01(g, 255);
520
+ b = bound01(b, 255);
521
+
522
+ var max = Math.max(r, g, b),
523
+ min = Math.min(r, g, b);
524
+ var h,
525
+ s,
526
+ v = max;
527
+
528
+ var d = max - min;
529
+ s = max === 0 ? 0 : d / max;
530
+
531
+ if (max == min) {
532
+ h = 0; // achromatic
533
+ } else {
534
+ switch (max) {
535
+ case r:
536
+ h = (g - b) / d + (g < b ? 6 : 0);
537
+ break;
538
+ case g:
539
+ h = (b - r) / d + 2;
540
+ break;
541
+ case b:
542
+ h = (r - g) / d + 4;
543
+ break;
544
+ }
545
+ h /= 6;
546
+ }
547
+ return { h: h, s: s, v: v };
548
+ }
549
+
550
+ // `hsvToRgb`
551
+ // Converts an HSV color value to RGB.
552
+ // *Assumes:* h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100]
553
+ // *Returns:* { r, g, b } in the set [0, 255]
554
+ function hsvToRgb(h, s, v) {
555
+ h = bound01(h, 360) * 6;
556
+ s = bound01(s, 100);
557
+ v = bound01(v, 100);
558
+
559
+ var i = Math.floor(h),
560
+ f = h - i,
561
+ p = v * (1 - s),
562
+ q = v * (1 - f * s),
563
+ t = v * (1 - (1 - f) * s),
564
+ mod = i % 6,
565
+ r = [v, q, p, p, t, v][mod],
566
+ g = [t, v, v, q, p, p][mod],
567
+ b = [p, p, t, v, v, q][mod];
568
+
569
+ return { r: r * 255, g: g * 255, b: b * 255 };
570
+ }
571
+
572
+ // `rgbToHex`
573
+ // Converts an RGB color to hex
574
+ // Assumes r, g, and b are contained in the set [0, 255]
575
+ // Returns a 3 or 6 character hex
576
+ function rgbToHex(r, g, b, allow3Char) {
577
+ var hex = [
578
+ pad2(Math.round(r).toString(16)),
579
+ pad2(Math.round(g).toString(16)),
580
+ pad2(Math.round(b).toString(16)),
581
+ ];
582
+
583
+ // Return a 3 character hex if possible
584
+ if (
585
+ allow3Char &&
586
+ hex[0].charAt(0) == hex[0].charAt(1) &&
587
+ hex[1].charAt(0) == hex[1].charAt(1) &&
588
+ hex[2].charAt(0) == hex[2].charAt(1)
589
+ ) {
590
+ return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);
591
+ }
592
+
593
+ return hex.join("");
594
+ }
595
+
596
+ // `rgbaToHex`
597
+ // Converts an RGBA color plus alpha transparency to hex
598
+ // Assumes r, g, b are contained in the set [0, 255] and
599
+ // a in [0, 1]. Returns a 4 or 8 character rgba hex
600
+ function rgbaToHex(r, g, b, a, allow4Char) {
601
+ var hex = [
602
+ pad2(Math.round(r).toString(16)),
603
+ pad2(Math.round(g).toString(16)),
604
+ pad2(Math.round(b).toString(16)),
605
+ pad2(convertDecimalToHex(a)),
606
+ ];
607
+
608
+ // Return a 4 character hex if possible
609
+ if (
610
+ allow4Char &&
611
+ hex[0].charAt(0) == hex[0].charAt(1) &&
612
+ hex[1].charAt(0) == hex[1].charAt(1) &&
613
+ hex[2].charAt(0) == hex[2].charAt(1) &&
614
+ hex[3].charAt(0) == hex[3].charAt(1)
615
+ ) {
616
+ return (
617
+ hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0) + hex[3].charAt(0)
618
+ );
619
+ }
620
+
621
+ return hex.join("");
622
+ }
623
+
624
+ // `rgbaToArgbHex`
625
+ // Converts an RGBA color to an ARGB Hex8 string
626
+ // Rarely used, but required for "toFilter()"
627
+ function rgbaToArgbHex(r, g, b, a) {
628
+ var hex = [
629
+ pad2(convertDecimalToHex(a)),
630
+ pad2(Math.round(r).toString(16)),
631
+ pad2(Math.round(g).toString(16)),
632
+ pad2(Math.round(b).toString(16)),
633
+ ];
634
+
635
+ return hex.join("");
636
+ }
637
+
638
+ // `equals`
639
+ // Can be called with any tinycolor input
640
+ tinycolor.equals = function (color1, color2) {
641
+ if (!color1 || !color2) return false;
642
+ return tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString();
643
+ };
644
+
645
+ tinycolor.random = function () {
646
+ return tinycolor.fromRatio({
647
+ r: Math.random(),
648
+ g: Math.random(),
649
+ b: Math.random(),
650
+ });
651
+ };
652
+
653
+ // Modification Functions
654
+ // ----------------------
655
+ // Thanks to less.js for some of the basics here
656
+ // <https://github.com/cloudhead/less.js/blob/master/lib/less/functions.js>
657
+
658
+ function desaturate(color, amount) {
659
+ amount = amount === 0 ? 0 : amount || 10;
660
+ var hsl = tinycolor(color).toHsl();
661
+ hsl.s -= amount / 100;
662
+ hsl.s = clamp01(hsl.s);
663
+ return tinycolor(hsl);
664
+ }
665
+
666
+ function saturate(color, amount) {
667
+ amount = amount === 0 ? 0 : amount || 10;
668
+ var hsl = tinycolor(color).toHsl();
669
+ hsl.s += amount / 100;
670
+ hsl.s = clamp01(hsl.s);
671
+ return tinycolor(hsl);
672
+ }
673
+
674
+ function greyscale(color) {
675
+ return tinycolor(color).desaturate(100);
676
+ }
677
+
678
+ function lighten(color, amount) {
679
+ amount = amount === 0 ? 0 : amount || 10;
680
+ var hsl = tinycolor(color).toHsl();
681
+ hsl.l += amount / 100;
682
+ hsl.l = clamp01(hsl.l);
683
+ return tinycolor(hsl);
684
+ }
685
+
686
+ function brighten(color, amount) {
687
+ amount = amount === 0 ? 0 : amount || 10;
688
+ var rgb = tinycolor(color).toRgb();
689
+ rgb.r = Math.max(0, Math.min(255, rgb.r - Math.round(255 * -(amount / 100))));
690
+ rgb.g = Math.max(0, Math.min(255, rgb.g - Math.round(255 * -(amount / 100))));
691
+ rgb.b = Math.max(0, Math.min(255, rgb.b - Math.round(255 * -(amount / 100))));
692
+ return tinycolor(rgb);
693
+ }
694
+
695
+ function darken(color, amount) {
696
+ amount = amount === 0 ? 0 : amount || 10;
697
+ var hsl = tinycolor(color).toHsl();
698
+ hsl.l -= amount / 100;
699
+ hsl.l = clamp01(hsl.l);
700
+ return tinycolor(hsl);
701
+ }
702
+
703
+ // Spin takes a positive or negative amount within [-360, 360] indicating the change of hue.
704
+ // Values outside of this range will be wrapped into this range.
705
+ function spin(color, amount) {
706
+ var hsl = tinycolor(color).toHsl();
707
+ var hue = (hsl.h + amount) % 360;
708
+ hsl.h = hue < 0 ? 360 + hue : hue;
709
+ return tinycolor(hsl);
710
+ }
711
+
712
+ // Combination Functions
713
+ // ---------------------
714
+ // Thanks to jQuery xColor for some of the ideas behind these
715
+ // <https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js>
716
+
717
+ function complement(color) {
718
+ var hsl = tinycolor(color).toHsl();
719
+ hsl.h = (hsl.h + 180) % 360;
720
+ return tinycolor(hsl);
721
+ }
722
+
723
+ function polyad(color, number) {
724
+ if (isNaN(number) || number <= 0) {
725
+ throw new Error("Argument to polyad must be a positive number");
726
+ }
727
+ var hsl = tinycolor(color).toHsl();
728
+ var result = [tinycolor(color)];
729
+ var step = 360 / number;
730
+ for (var i = 1; i < number; i++) {
731
+ result.push(tinycolor({ h: (hsl.h + i * step) % 360, s: hsl.s, l: hsl.l }));
732
+ }
733
+
734
+ return result;
735
+ }
736
+
737
+ function splitcomplement(color) {
738
+ var hsl = tinycolor(color).toHsl();
739
+ var h = hsl.h;
740
+ return [
741
+ tinycolor(color),
742
+ tinycolor({ h: (h + 72) % 360, s: hsl.s, l: hsl.l }),
743
+ tinycolor({ h: (h + 216) % 360, s: hsl.s, l: hsl.l }),
744
+ ];
745
+ }
746
+
747
+ function analogous(color, results, slices) {
748
+ results = results || 6;
749
+ slices = slices || 30;
750
+
751
+ var hsl = tinycolor(color).toHsl();
752
+ var part = 360 / slices;
753
+ var ret = [tinycolor(color)];
754
+
755
+ for (hsl.h = (hsl.h - ((part * results) >> 1) + 720) % 360; --results; ) {
756
+ hsl.h = (hsl.h + part) % 360;
757
+ ret.push(tinycolor(hsl));
758
+ }
759
+ return ret;
760
+ }
761
+
762
+ function monochromatic(color, results) {
763
+ results = results || 6;
764
+ var hsv = tinycolor(color).toHsv();
765
+ var h = hsv.h,
766
+ s = hsv.s,
767
+ v = hsv.v;
768
+ var ret = [];
769
+ var modification = 1 / results;
770
+
771
+ while (results--) {
772
+ ret.push(tinycolor({ h: h, s: s, v: v }));
773
+ v = (v + modification) % 1;
774
+ }
775
+
776
+ return ret;
777
+ }
778
+
779
+ // Utility Functions
780
+ // ---------------------
781
+
782
+ tinycolor.mix = function (color1, color2, amount) {
783
+ amount = amount === 0 ? 0 : amount || 50;
784
+
785
+ var rgb1 = tinycolor(color1).toRgb();
786
+ var rgb2 = tinycolor(color2).toRgb();
787
+
788
+ var p = amount / 100;
789
+
790
+ var rgba = {
791
+ r: (rgb2.r - rgb1.r) * p + rgb1.r,
792
+ g: (rgb2.g - rgb1.g) * p + rgb1.g,
793
+ b: (rgb2.b - rgb1.b) * p + rgb1.b,
794
+ a: (rgb2.a - rgb1.a) * p + rgb1.a,
795
+ };
796
+
797
+ return tinycolor(rgba);
798
+ };
799
+
800
+ // Readability Functions
801
+ // ---------------------
802
+ // <http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef (WCAG Version 2)
803
+
804
+ // `contrast`
805
+ // Analyze the 2 colors and returns the color contrast defined by (WCAG Version 2)
806
+ tinycolor.readability = function (color1, color2) {
807
+ var c1 = tinycolor(color1);
808
+ var c2 = tinycolor(color2);
809
+ return (
810
+ (Math.max(c1.getLuminance(), c2.getLuminance()) + 0.05) /
811
+ (Math.min(c1.getLuminance(), c2.getLuminance()) + 0.05)
812
+ );
813
+ };
814
+
815
+ // `isReadable`
816
+ // Ensure that foreground and background color combinations meet WCAG2 guidelines.
817
+ // The third argument is an optional Object.
818
+ // the 'level' property states 'AA' or 'AAA' - if missing or invalid, it defaults to 'AA';
819
+ // the 'size' property states 'large' or 'small' - if missing or invalid, it defaults to 'small'.
820
+ // If the entire object is absent, isReadable defaults to {level:"AA",size:"small"}.
821
+
822
+ // *Example*
823
+ // tinycolor.isReadable("#000", "#111") => false
824
+ // tinycolor.isReadable("#000", "#111",{level:"AA",size:"large"}) => false
825
+ tinycolor.isReadable = function (color1, color2, wcag2) {
826
+ var readability = tinycolor.readability(color1, color2);
827
+ var wcag2Parms, out;
828
+
829
+ out = false;
830
+
831
+ wcag2Parms = validateWCAG2Parms(wcag2);
832
+ switch (wcag2Parms.level + wcag2Parms.size) {
833
+ case "AAsmall":
834
+ case "AAAlarge":
835
+ out = readability >= 4.5;
836
+ break;
837
+ case "AAlarge":
838
+ out = readability >= 3;
839
+ break;
840
+ case "AAAsmall":
841
+ out = readability >= 7;
842
+ break;
843
+ }
844
+ return out;
845
+ };
846
+
847
+ // `mostReadable`
848
+ // Given a base color and a list of possible foreground or background
849
+ // colors for that base, returns the most readable color.
850
+ // Optionally returns Black or White if the most readable color is unreadable.
851
+ // *Example*
852
+ // tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:false}).toHexString(); // "#112255"
853
+ // tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:true}).toHexString(); // "#ffffff"
854
+ // tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"large"}).toHexString(); // "#faf3f3"
855
+ // tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"small"}).toHexString(); // "#ffffff"
856
+ tinycolor.mostReadable = function (baseColor, colorList, args) {
857
+ var bestColor = null;
858
+ var bestScore = 0;
859
+ var readability;
860
+ var includeFallbackColors, level, size;
861
+ args = args || {};
862
+ includeFallbackColors = args.includeFallbackColors;
863
+ level = args.level;
864
+ size = args.size;
865
+
866
+ for (var i = 0; i < colorList.length; i++) {
867
+ readability = tinycolor.readability(baseColor, colorList[i]);
868
+ if (readability > bestScore) {
869
+ bestScore = readability;
870
+ bestColor = tinycolor(colorList[i]);
871
+ }
872
+ }
873
+
874
+ if (
875
+ tinycolor.isReadable(baseColor, bestColor, {
876
+ level: level,
877
+ size: size,
878
+ }) ||
879
+ !includeFallbackColors
880
+ ) {
881
+ return bestColor;
882
+ } else {
883
+ args.includeFallbackColors = false;
884
+ return tinycolor.mostReadable(baseColor, ["#fff", "#000"], args);
885
+ }
886
+ };
887
+
888
+ // Big List of Colors
889
+ // ------------------
890
+ // <https://www.w3.org/TR/css-color-4/#named-colors>
891
+ var names = (tinycolor.names = {
892
+ aliceblue: "f0f8ff",
893
+ antiquewhite: "faebd7",
894
+ aqua: "0ff",
895
+ aquamarine: "7fffd4",
896
+ azure: "f0ffff",
897
+ beige: "f5f5dc",
898
+ bisque: "ffe4c4",
899
+ black: "000",
900
+ blanchedalmond: "ffebcd",
901
+ blue: "00f",
902
+ blueviolet: "8a2be2",
903
+ brown: "a52a2a",
904
+ burlywood: "deb887",
905
+ burntsienna: "ea7e5d",
906
+ cadetblue: "5f9ea0",
907
+ chartreuse: "7fff00",
908
+ chocolate: "d2691e",
909
+ coral: "ff7f50",
910
+ cornflowerblue: "6495ed",
911
+ cornsilk: "fff8dc",
912
+ crimson: "dc143c",
913
+ cyan: "0ff",
914
+ darkblue: "00008b",
915
+ darkcyan: "008b8b",
916
+ darkgoldenrod: "b8860b",
917
+ darkgray: "a9a9a9",
918
+ darkgreen: "006400",
919
+ darkgrey: "a9a9a9",
920
+ darkkhaki: "bdb76b",
921
+ darkmagenta: "8b008b",
922
+ darkolivegreen: "556b2f",
923
+ darkorange: "ff8c00",
924
+ darkorchid: "9932cc",
925
+ darkred: "8b0000",
926
+ darksalmon: "e9967a",
927
+ darkseagreen: "8fbc8f",
928
+ darkslateblue: "483d8b",
929
+ darkslategray: "2f4f4f",
930
+ darkslategrey: "2f4f4f",
931
+ darkturquoise: "00ced1",
932
+ darkviolet: "9400d3",
933
+ deeppink: "ff1493",
934
+ deepskyblue: "00bfff",
935
+ dimgray: "696969",
936
+ dimgrey: "696969",
937
+ dodgerblue: "1e90ff",
938
+ firebrick: "b22222",
939
+ floralwhite: "fffaf0",
940
+ forestgreen: "228b22",
941
+ fuchsia: "f0f",
942
+ gainsboro: "dcdcdc",
943
+ ghostwhite: "f8f8ff",
944
+ gold: "ffd700",
945
+ goldenrod: "daa520",
946
+ gray: "808080",
947
+ green: "008000",
948
+ greenyellow: "adff2f",
949
+ grey: "808080",
950
+ honeydew: "f0fff0",
951
+ hotpink: "ff69b4",
952
+ indianred: "cd5c5c",
953
+ indigo: "4b0082",
954
+ ivory: "fffff0",
955
+ khaki: "f0e68c",
956
+ lavender: "e6e6fa",
957
+ lavenderblush: "fff0f5",
958
+ lawngreen: "7cfc00",
959
+ lemonchiffon: "fffacd",
960
+ lightblue: "add8e6",
961
+ lightcoral: "f08080",
962
+ lightcyan: "e0ffff",
963
+ lightgoldenrodyellow: "fafad2",
964
+ lightgray: "d3d3d3",
965
+ lightgreen: "90ee90",
966
+ lightgrey: "d3d3d3",
967
+ lightpink: "ffb6c1",
968
+ lightsalmon: "ffa07a",
969
+ lightseagreen: "20b2aa",
970
+ lightskyblue: "87cefa",
971
+ lightslategray: "789",
972
+ lightslategrey: "789",
973
+ lightsteelblue: "b0c4de",
974
+ lightyellow: "ffffe0",
975
+ lime: "0f0",
976
+ limegreen: "32cd32",
977
+ linen: "faf0e6",
978
+ magenta: "f0f",
979
+ maroon: "800000",
980
+ mediumaquamarine: "66cdaa",
981
+ mediumblue: "0000cd",
982
+ mediumorchid: "ba55d3",
983
+ mediumpurple: "9370db",
984
+ mediumseagreen: "3cb371",
985
+ mediumslateblue: "7b68ee",
986
+ mediumspringgreen: "00fa9a",
987
+ mediumturquoise: "48d1cc",
988
+ mediumvioletred: "c71585",
989
+ midnightblue: "191970",
990
+ mintcream: "f5fffa",
991
+ mistyrose: "ffe4e1",
992
+ moccasin: "ffe4b5",
993
+ navajowhite: "ffdead",
994
+ navy: "000080",
995
+ oldlace: "fdf5e6",
996
+ olive: "808000",
997
+ olivedrab: "6b8e23",
998
+ orange: "ffa500",
999
+ orangered: "ff4500",
1000
+ orchid: "da70d6",
1001
+ palegoldenrod: "eee8aa",
1002
+ palegreen: "98fb98",
1003
+ paleturquoise: "afeeee",
1004
+ palevioletred: "db7093",
1005
+ papayawhip: "ffefd5",
1006
+ peachpuff: "ffdab9",
1007
+ peru: "cd853f",
1008
+ pink: "ffc0cb",
1009
+ plum: "dda0dd",
1010
+ powderblue: "b0e0e6",
1011
+ purple: "800080",
1012
+ rebeccapurple: "663399",
1013
+ red: "f00",
1014
+ rosybrown: "bc8f8f",
1015
+ royalblue: "4169e1",
1016
+ saddlebrown: "8b4513",
1017
+ salmon: "fa8072",
1018
+ sandybrown: "f4a460",
1019
+ seagreen: "2e8b57",
1020
+ seashell: "fff5ee",
1021
+ sienna: "a0522d",
1022
+ silver: "c0c0c0",
1023
+ skyblue: "87ceeb",
1024
+ slateblue: "6a5acd",
1025
+ slategray: "708090",
1026
+ slategrey: "708090",
1027
+ snow: "fffafa",
1028
+ springgreen: "00ff7f",
1029
+ steelblue: "4682b4",
1030
+ tan: "d2b48c",
1031
+ teal: "008080",
1032
+ thistle: "d8bfd8",
1033
+ tomato: "ff6347",
1034
+ turquoise: "40e0d0",
1035
+ violet: "ee82ee",
1036
+ wheat: "f5deb3",
1037
+ white: "fff",
1038
+ whitesmoke: "f5f5f5",
1039
+ yellow: "ff0",
1040
+ yellowgreen: "9acd32",
1041
+ });
1042
+
1043
+ // Make it easy to access colors via `hexNames[hex]`
1044
+ var hexNames = (tinycolor.hexNames = flip(names));
1045
+
1046
+ // Utilities
1047
+ // ---------
1048
+
1049
+ // `{ 'name1': 'val1' }` becomes `{ 'val1': 'name1' }`
1050
+ function flip(o) {
1051
+ var flipped = {};
1052
+ for (var i in o) {
1053
+ if (o.hasOwnProperty(i)) {
1054
+ flipped[o[i]] = i;
1055
+ }
1056
+ }
1057
+ return flipped;
1058
+ }
1059
+
1060
+ // Return a valid alpha value [0,1] with all invalid values being set to 1
1061
+ function boundAlpha(a) {
1062
+ a = parseFloat(a);
1063
+
1064
+ if (isNaN(a) || a < 0 || a > 1) {
1065
+ a = 1;
1066
+ }
1067
+
1068
+ return a;
1069
+ }
1070
+
1071
+ // Take input from [0, n] and return it as [0, 1]
1072
+ function bound01(n, max) {
1073
+ if (isOnePointZero(n)) n = "100%";
1074
+
1075
+ var processPercent = isPercentage(n);
1076
+ n = Math.min(max, Math.max(0, parseFloat(n)));
1077
+
1078
+ // Automatically convert percentage into number
1079
+ if (processPercent) {
1080
+ n = parseInt(n * max, 10) / 100;
1081
+ }
1082
+
1083
+ // Handle floating point rounding errors
1084
+ if (Math.abs(n - max) < 0.000001) {
1085
+ return 1;
1086
+ }
1087
+
1088
+ // Convert into [0, 1] range if it isn't already
1089
+ return (n % max) / parseFloat(max);
1090
+ }
1091
+
1092
+ // Force a number between 0 and 1
1093
+ function clamp01(val) {
1094
+ return Math.min(1, Math.max(0, val));
1095
+ }
1096
+
1097
+ // Parse a base-16 hex value into a base-10 integer
1098
+ function parseIntFromHex(val) {
1099
+ return parseInt(val, 16);
1100
+ }
1101
+
1102
+ // Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1
1103
+ // <http://stackoverflow.com/questions/7422072/javascript-how-to-detect-number-as-a-decimal-including-1-0>
1104
+ function isOnePointZero(n) {
1105
+ return typeof n == "string" && n.indexOf(".") != -1 && parseFloat(n) === 1;
1106
+ }
1107
+
1108
+ // Check to see if string passed in is a percentage
1109
+ function isPercentage(n) {
1110
+ return typeof n === "string" && n.indexOf("%") != -1;
1111
+ }
1112
+
1113
+ // Force a hex value to have 2 characters
1114
+ function pad2(c) {
1115
+ return c.length == 1 ? "0" + c : "" + c;
1116
+ }
1117
+
1118
+ // Replace a decimal with it's percentage value
1119
+ function convertToPercentage(n) {
1120
+ if (n <= 1) {
1121
+ n = n * 100 + "%";
1122
+ }
1123
+
1124
+ return n;
1125
+ }
1126
+
1127
+ // Converts a decimal to a hex value
1128
+ function convertDecimalToHex(d) {
1129
+ return Math.round(parseFloat(d) * 255).toString(16);
1130
+ }
1131
+ // Converts a hex value to a decimal
1132
+ function convertHexToDecimal(h) {
1133
+ return parseIntFromHex(h) / 255;
1134
+ }
1135
+
1136
+ var matchers = (function () {
1137
+ // <http://www.w3.org/TR/css3-values/#integers>
1138
+ var CSS_INTEGER = "[-\\+]?\\d+%?";
1139
+
1140
+ // <http://www.w3.org/TR/css3-values/#number-value>
1141
+ var CSS_NUMBER = "[-\\+]?\\d*\\.\\d+%?";
1142
+
1143
+ // Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome.
1144
+ var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")";
1145
+
1146
+ // Actual matching.
1147
+ // Parentheses and commas are optional, but not required.
1148
+ // Whitespace can take the place of commas or opening paren
1149
+ var PERMISSIVE_MATCH3 =
1150
+ "[\\s|\\(]+(" +
1151
+ CSS_UNIT +
1152
+ ")[,|\\s]+(" +
1153
+ CSS_UNIT +
1154
+ ")[,|\\s]+(" +
1155
+ CSS_UNIT +
1156
+ ")\\s*\\)?";
1157
+ var PERMISSIVE_MATCH4 =
1158
+ "[\\s|\\(]+(" +
1159
+ CSS_UNIT +
1160
+ ")[,|\\s]+(" +
1161
+ CSS_UNIT +
1162
+ ")[,|\\s]+(" +
1163
+ CSS_UNIT +
1164
+ ")[,|\\s]+(" +
1165
+ CSS_UNIT +
1166
+ ")\\s*\\)?";
1167
+
1168
+ return {
1169
+ CSS_UNIT: new RegExp(CSS_UNIT),
1170
+ rgb: new RegExp("rgb" + PERMISSIVE_MATCH3),
1171
+ rgba: new RegExp("rgba" + PERMISSIVE_MATCH4),
1172
+ hsl: new RegExp("hsl" + PERMISSIVE_MATCH3),
1173
+ hsla: new RegExp("hsla" + PERMISSIVE_MATCH4),
1174
+ hsv: new RegExp("hsv" + PERMISSIVE_MATCH3),
1175
+ hsva: new RegExp("hsva" + PERMISSIVE_MATCH4),
1176
+ hex3: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
1177
+ hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
1178
+ hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
1179
+ hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
1180
+ };
1181
+ })();
1182
+
1183
+ // `isValidCSSUnit`
1184
+ // Take in a single string / number and check to see if it looks like a CSS unit
1185
+ // (see `matchers` above for definition).
1186
+ function isValidCSSUnit(color) {
1187
+ return !!matchers.CSS_UNIT.exec(color);
1188
+ }
1189
+
1190
+ // `stringInputToObject`
1191
+ // Permissive string parsing. Take in a number of formats, and output an object
1192
+ // based on detected format. Returns `{ r, g, b }` or `{ h, s, l }` or `{ h, s, v}`
1193
+ function stringInputToObject(color) {
1194
+ color = color.replace(trimLeft, "").replace(trimRight, "").toLowerCase();
1195
+ var named = false;
1196
+ if (names[color]) {
1197
+ color = names[color];
1198
+ named = true;
1199
+ } else if (color == "transparent") {
1200
+ return { r: 0, g: 0, b: 0, a: 0, format: "name" };
1201
+ }
1202
+
1203
+ // Try to match string input using regular expressions.
1204
+ // Keep most of the number bounding out of this function - don't worry about [0,1] or [0,100] or [0,360]
1205
+ // Just return an object and let the conversion functions handle that.
1206
+ // This way the result will be the same whether the tinycolor is initialized with string or object.
1207
+ var match;
1208
+ if ((match = matchers.rgb.exec(color))) {
1209
+ return { r: match[1], g: match[2], b: match[3] };
1210
+ }
1211
+ if ((match = matchers.rgba.exec(color))) {
1212
+ return { r: match[1], g: match[2], b: match[3], a: match[4] };
1213
+ }
1214
+ if ((match = matchers.hsl.exec(color))) {
1215
+ return { h: match[1], s: match[2], l: match[3] };
1216
+ }
1217
+ if ((match = matchers.hsla.exec(color))) {
1218
+ return { h: match[1], s: match[2], l: match[3], a: match[4] };
1219
+ }
1220
+ if ((match = matchers.hsv.exec(color))) {
1221
+ return { h: match[1], s: match[2], v: match[3] };
1222
+ }
1223
+ if ((match = matchers.hsva.exec(color))) {
1224
+ return { h: match[1], s: match[2], v: match[3], a: match[4] };
1225
+ }
1226
+ if ((match = matchers.hex8.exec(color))) {
1227
+ return {
1228
+ r: parseIntFromHex(match[1]),
1229
+ g: parseIntFromHex(match[2]),
1230
+ b: parseIntFromHex(match[3]),
1231
+ a: convertHexToDecimal(match[4]),
1232
+ format: named ? "name" : "hex8",
1233
+ };
1234
+ }
1235
+ if ((match = matchers.hex6.exec(color))) {
1236
+ return {
1237
+ r: parseIntFromHex(match[1]),
1238
+ g: parseIntFromHex(match[2]),
1239
+ b: parseIntFromHex(match[3]),
1240
+ format: named ? "name" : "hex",
1241
+ };
1242
+ }
1243
+ if ((match = matchers.hex4.exec(color))) {
1244
+ return {
1245
+ r: parseIntFromHex(match[1] + "" + match[1]),
1246
+ g: parseIntFromHex(match[2] + "" + match[2]),
1247
+ b: parseIntFromHex(match[3] + "" + match[3]),
1248
+ a: convertHexToDecimal(match[4] + "" + match[4]),
1249
+ format: named ? "name" : "hex8",
1250
+ };
1251
+ }
1252
+ if ((match = matchers.hex3.exec(color))) {
1253
+ return {
1254
+ r: parseIntFromHex(match[1] + "" + match[1]),
1255
+ g: parseIntFromHex(match[2] + "" + match[2]),
1256
+ b: parseIntFromHex(match[3] + "" + match[3]),
1257
+ format: named ? "name" : "hex",
1258
+ };
1259
+ }
1260
+
1261
+ return false;
1262
+ }
1263
+
1264
+ function validateWCAG2Parms(parms) {
1265
+ // return valid WCAG2 parms for isReadable.
1266
+ // If input parms are invalid, return {"level":"AA", "size":"small"}
1267
+ var level, size;
1268
+ parms = parms || { level: "AA", size: "small" };
1269
+ level = (parms.level || "AA").toUpperCase();
1270
+ size = (parms.size || "small").toLowerCase();
1271
+ if (level !== "AA" && level !== "AAA") {
1272
+ level = "AA";
1273
+ }
1274
+ if (size !== "small" && size !== "large") {
1275
+ size = "small";
1276
+ }
1277
+ return { level: level, size: size };
1278
+ }
1279
+
1280
+ const hslColorMap = (h, s, l) => {
1281
+ const colors = {};
1282
+ for (let i = 0; i < l.length; i++) {
1283
+ const lightness = l[i];
1284
+ colors[lightness] = tinycolor({ h, s, l: lightness }).toHexString();
1285
+ }
1286
+ return colors;
1287
+ };
1288
+
1289
+ const colorPalette = {
1290
+ neutral: hslColorMap(
1291
+ 206,
1292
+ 30,
1293
+ [
1294
+ 10,
1295
+ 15,
1296
+ 20,
1297
+ 25,
1298
+ 30,
1299
+ 35,
1300
+ 40,
1301
+ 45,
1302
+ 50,
1303
+ 55,
1304
+ 60,
1305
+ 65,
1306
+ 70,
1307
+ 75,
1308
+ 80,
1309
+ 85,
1310
+ 90,
1311
+ 95,
1312
+ 97,
1313
+ 98,
1314
+ 100
1315
+ ]
1316
+ ),
1317
+ honey: hslColorMap(42, 93, [72, 75, 82, 85, 92]),
1318
+ coral: hslColorMap(14, 87, [65, 74, 75, 84, 85, 94]),
1319
+ warm: hslColorMap(25, 100, [77, 87, 97]),
1320
+ "sea-salt": hslColorMap(180, 17, [57, 67, 88]),
1321
+ cloud: hslColorMap(200, 38, [43, 75, 88]),
1322
+ ocean: hslColorMap(209, 38, [38, 75, 88]),
1323
+ sky: hslColorMap(209, 64, [64, 75, 85]),
1324
+ lukso: hslColorMap(335, 33, [70, 80, 90]),
1325
+ yellow: hslColorMap(36, 100, [55, 65, 75, 85]),
1326
+ green: hslColorMap(135, 57, [45, 54, 75, 85]),
1327
+ blue: hslColorMap(216, 96, [50, 60, 75, 85]),
1328
+ red: hslColorMap(0, 75, [55, 65, 75, 85]),
1329
+ purple: hslColorMap(230, 24, [94, 82, 63, 58, 51, 41, 31, 15]),
1330
+ pink: hslColorMap(11, 73, [97, 96, 95, 94, 93, 92, 91, 90]),
1331
+ "gradient-1": {
1332
+ start: "#D39B9D",
1333
+ end: "#9071D1"
1334
+ },
1335
+ "gradient-2": {
1336
+ start: "#F8DAD3",
1337
+ end: "#CC99AE"
1338
+ },
1339
+ "gradient-3": {
1340
+ start: tinycolor({ h: 230, s: 20, l: 28 }).toHexString(),
1341
+ end: tinycolor({ h: 230, s: 24, l: 51 }).toHexString()
1342
+ }
1343
+ };
1344
+ const splitColor = (colors, from, to) => {
1345
+ return Object.keys(colors).slice(from, to).reduce((result, key) => {
1346
+ result[key] = colors[key];
1347
+ return result;
1348
+ }, {});
1349
+ };
1350
+ const neutral1 = splitColor(colorPalette.neutral, 0, 8);
1351
+ const neutral2 = splitColor(colorPalette.neutral, 8, 16);
1352
+ const neutral3 = splitColor(
1353
+ colorPalette.neutral,
1354
+ 16,
1355
+ Object.keys(colorPalette.neutral).length
1356
+ );
1357
+
1358
+ exports.colorPalette = colorPalette;
1359
+ exports.hslColorMap = hslColorMap;
1360
+ exports.neutral1 = neutral1;
1361
+ exports.neutral2 = neutral2;
1362
+ exports.neutral3 = neutral3;