{"name":"color2k","version":"0.0.0-bfef7cdc4","description":"a color parsing and manipulation lib served in 2kB or less","main":"./index.js","author":{"name":"Rico Kahler","email":"ricokahler@me.com"},"repository":{"type":"git","url":"git+https://github.com/ricokahler/color2k.git"},"license":"MIT","types":"./src","module":"./index.esm.js","dependencies":{"@color2k/parse-to-rgba":"0.0.0-bfef7cdc4"},"sideEffects":false,"readme":"# [color2k](https://color2k.com) · [![https://badgen.net/bundlephobia/minzip/color2k](https://badgen.net/bundlephobia/minzip/color2k)](https://bundlephobia.com/result?p=color2k)\n\n> a color parsing and manipulation lib served in 2kB or less (1.5kB to be more precise)\n\ncolor2k is a color parsing and manipulation library with the objective of keeping the bundle size as small as possible while still satisfying all of your color manipulation needs in an sRGB space [(wide-gamut is not supported)](https://github.com/ricokahler/color2k/issues/16).\n\nThe bundle size is [currently 1.5kB](https://bundlephobia.com/result?p=color2k)\n\n## Size comparison\n\n| lib                                                       | size                                                  |\n| --------------------------------------------------------- | ----------------------------------------------------- |\n| [polished](https://github.com/styled-components/polished) | [11.2kB](https://bundlephobia.com/result?p=polished)  |\n| [chroma-js](https://github.com/gka/chroma.js)             | [13.7kB](https://bundlephobia.com/result?p=chroma-js) |\n| [color](https://github.com/Qix-/color)                    | [7.6kB](https://bundlephobia.com/result?p=color)      |\n| [tinycolor2](https://github.com/bgrins/TinyColor)         | [5kB](https://bundlephobia.com/result?p=tinycolor2)   |\n| color2k                                                   | [1.5kB](https://bundlephobia.com/result?p=color2k) 😎 |\n\n## Installation\n\n```\nnpm i --save color2k\n```\n\nIf you need to server-side render any colors, you also need to install the node/ssr compatibility package.\n\n```bash\n# only needed in SSR environments (e.g. gatsby, next.js)\nnpm i --save @color2k/compat\n```\n\n## Usage\n\n```js\nimport { darken, transparentize } from 'color2k';\n\n// e.g.\ndarken('blue', 0.1);\ntransparentize('red', 0.5);\n```\n\n## How so small?\n\nThere are two secrets that keep this lib especially small:\n\n1. defer to the browser to [parse colors via `getComputedStyle`](https://github.com/ricokahler/color2k/blob/63905b1ad09312cc4e06f20961c6dfb930a3ceb3/packages/parse-to-rgba/src/index.ts#L63)\n2. only support two color models as outputs, namely `rgba` and `hsla`\n\n### Why `getComputedStyle`?\n\nThe browser already has the ability to parse colors via `getComputedStyle`. Other color libs use javascript to parse and transform colors. The result of making the browser parse the color is the removal of any code related to parsing colors resulting in a significantly smaller bundle.\n\n### Why not `getComputedStyle`?\n\nUsing `getComputedStyle` is slower than parsing via javascript.\n\nOn my 2019 MacBook Pro:\n\n- `getComputedStyle`: 594,499 ops/sec\n- JavaScript: 3,335,123 ops/sec\n\n[See here](https://jsperf.com/polished-vs-canvas/3)\n\nIn order to increase performance, already computed colors are [cached](https://github.com/ricokahler/color2k/blob/22941f75aa9216f2a581a02da41b7fb8f18ffba4/packages/parse-to-rgba/src/index.ts#L41).\n\n### Why only `rgba` and `hsla` as outputs?\n\nThis lib was created with the use case of CSS-in-JS in mind. At the end of the day, all that matters is that the browser can understand the color string you gave it as a `background-color`.\n\nBecause only those two color models are supported, we don't have to add code to deal with optional alpha channels or converting to non-browser supported color models (e.g. CMYK).\n\nWe believe that this lib is sufficient for all of your color manipulation needs. If we're missing a feature, feel free to [open an issue](https://github.com/ricokahler/color2k/issues/new) 😎.\n\n## Credits\n\nHeavy credits goes to polished.js and sass. Much of the implementation of this lib is copied from polished!\n\n<!-- DOCS-END -->\n\n## API and Documentation\n\n[Head over to the docs site](https://color2k.com)\n","readmeFilename":"README.md","bugs":{"url":"https://github.com/ricokahler/color2k/issues"},"homepage":"https://github.com/ricokahler/color2k#readme","_id":"color2k@0.0.0-bfef7cdc4","_nodeVersion":"12.13.1","_npmVersion":"6.13.4","dist":{"integrity":"sha512-MRRsd5ykbKAac52aePFFbPPaWu905z9ZxlEPbCHAE8BAMUuONTYZpOAJrtb7JrLYMLMJjW1t3HoedBuzTlewZA==","shasum":"c0ab0ee1ee30f5a6eba66c53eb09474c8b306e5f","tarball":"http://registry-npm.ywwl.com/color2k/download/color2k-0.0.0-bfef7cdc4.tgz","fileCount":27,"unpackedSize":81294,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJevPdPCRA9TVsSAnZWagAAV1YP/RRDhXPGGsol9oNlDYOS\nvwoPcehldscMogdmxQoi9iMehFnJoKVS2rcmdLi6NfhpDma47Hx5Zo+ZSttW\nodv66Cs29UFUSqMUuHqK2q20f0Y00WFRt/N7kfYB8LkC+fnPMFnZhipFdqLC\nZy9RwOgwtkli0+3k0p3L0cIMncO1GtQT8xBju2tqu4s4d4h96QfNhDmHEmpw\nV52bMCZYmPNgTDTGSPSCOjjqjFylW8DI6NvxsURJtddaObsN51J46rUFVJbn\nR/8vHI5NAWpqmRW2w+zjw1b87OMX0wHQz6DVTRpI/D7SuP2pzU8nTv5o/TB/\nMuuCrnumHJusphqwmjgYEsmpatp2X6Q0R928WXhgjMUgopUa8MQ9DQSNAiQ5\nT+2oV8j1yk+hjAFrgj0ua4fMy1fOn62DEAYWw8F/YWkRYIVkxn9qArtpyToI\nnxWXvtbErTisCHsI8vt5KMmy+6PF6pqXgiVZsN1t/qmatzHPOdoC5jrN6e+c\nwYPwPnmilSPD7vIMIo5mZMIF96pvYIWQk4UWTzep9MOFt5e9bpVo8mzpWP5G\nxq42V1Hc5h2Jou22KOYX2/HwCnfmyqkUZ1f6YjEGCpwUJLJc+cJxrbgB3Ss6\nnQA/BIoZsE6IUVGhAJ5aABX0edvkXPbTKAR5eV9s/Rpa68Oh8UpyMlsbDeXY\nqHc2\r\n=r+lw\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDHpjNqgBJ/6qIwkvoucAgdit7P4Y+eWl/G5Rn+Pap6TAiA02VLFGFGLciAe9y9ZxVN9xQD7Y3h3MrJIxvTBPvkR8Q=="}],"size":15136,"noattachment":false,"key":"/color2k/-/color2k-0.0.0-bfef7cdc4.tgz"},"maintainers":[{"name":"ricokahler","email":"ricokahler@me.com"}],"_npmUser":{"name":"ricokahler","email":"ricokahler@me.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/color2k_0.0.0-bfef7cdc4_1589442382563_0.06373575037286683"},"_hasShrinkwrap":false,"publish_time":1589442382732,"_cnpm_publish_time":1589442382732,"dist-tags":{"alpha":"1.2.0-alpha.3","latest":"2.0.4"}}