{"name":"@asamuzakjp/css-color","version":"2.7.1","author":{"name":"asamuzaK"},"license":"MIT","_id":"@asamuzakjp/css-color@2.7.1","homepage":"https://github.com/asamuzaK/cssColor#readme","bugs":{"url":"https://github.com/asamuzaK/cssColor/issues"},"dist":{"shasum":"ee1a577530c377cc9fe565cbfb44d200f8b8a5c2","tarball":"http://registry-npm.ywwl.com/@asamuzakjp/css-color/download/@asamuzakjp/css-color-2.7.1.tgz","fileCount":25,"integrity":"sha512-FrLFymoHF4ygxluMLQFH6TNaOFvVaMj28//YmfQBrDieEc4gvcCF6mJyI4Bdw7ggKWbD3o/vlo4aCI8I5NEtgQ==","signatures":[{"sig":"MEYCIQDOiKs63CEGgt48wy83tsMfbj8NoyhYjAvzH9ffN4IkxAIhAM7RA5WmaS9XBtMC7SflfrhPi+IRb0EKdSEaTr+lhP77","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1352875,"size":283457,"noattachment":false,"key":"/@asamuzakjp/css-color/-/@asamuzakjp/css-color-2.7.1.tgz"},"type":"module","types":"types/index.d.ts","exports":{"import":"./src/index.js","browser":"./dist/esm/css-color.min.js","require":"./dist/cjs/css-color.min.cjs"},"gitHead":"d8607c5a737f9539e676f51d168991787e324c7d","scripts":{"tsc":"node -e \"fs.rmSync('types',{recursive:true,force:true})\" && npx tsc","lint":"eslint --fix .","test":"c8 --reporter=text mocha --exit test/**/*.test.js","build":"npm run tsc && npm run lint && npm test && npm run bundle","bundle":"npm-run-all -s bundle-*","bundle-cjs":"esbuild --format=cjs --platform=node --outfile=dist/cjs/css-color.min.cjs --bundle --minify --sourcemap src/index.js","bundle-browser":"esbuild --format=esm --platform=browser --outfile=dist/esm/css-color.min.js --bundle --minify --sourcemap src/index.js"},"_npmUser":{"name":"asamuzakjp","email":"info@asamuzak.jp"},"repository":{"url":"git+https://github.com/asamuzaK/cssColor.git","type":"git"},"_npmVersion":"11.0.0","description":"CSS color - Resolve and convert CSS colors.","directories":{},"_nodeVersion":"22.12.0","dependencies":{"lru-cache":"^11.0.2","@csstools/css-calc":"^2.1.1","@csstools/css-tokenizer":"^3.0.3"},"_hasShrinkwrap":false,"devDependencies":{"c8":"^10.1.3","mocha":"^11.0.1","sinon":"^19.0.2","eslint":"^9.17.0","esbuild":"^0.24.2","globals":"^15.14.0","typescript":"^5.7.2","neostandard":"^0.12.0","npm-run-all2":"^7.0.2","eslint-plugin-jsdoc":"^50.6.1","eslint-plugin-regexp":"^2.7.0","eslint-plugin-import-x":"^4.6.1"},"_npmOperationalInternal":{"tmp":"tmp/css-color_2.7.1_1735346531386_0.8699185686691513","host":"s3://npm-registry-packages-npm-production"},"readme":"# CSS color\n\n[![build](https://github.com/asamuzaK/cssColor/actions/workflows/node.js.yml/badge.svg)](https://github.com/asamuzaK/cssColor/actions/workflows/node.js.yml)\n[![CodeQL](https://github.com/asamuzaK/cssColor/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/asamuzaK/cssColor/actions/workflows/github-code-scanning/codeql)\n[![npm (scoped)](https://img.shields.io/npm/v/@asamuzakjp/css-color)](https://www.npmjs.com/package/@asamuzakjp/css-color)\n\nResolve and convert CSS colors.\n\n## Install\n\n```console\nnpm i @asamuzakjp/css-color\n```\n\n## Usage\n\n```javascript\nimport { convert, resolve, utils } from '@asamuzakjp/css-color';\n\nconst resolvedValue = resolve(\n  'color-mix(in oklab, lch(67.5345 42.5 258.2), color(srgb 0 0.5 0))'\n);\n// 'oklab(0.620754 -0.0931934 -0.00374881)'\n\nconst convertedValue = covert.colorToHex('lab(46.2775% -47.5621 48.5837)');\n// '#008000'\n\nconst result = utils.isColor('green');\n// true\n```\n\n<!-- Generated by documentation.js. Update this documentation by updating the source code. -->\n\n### resolve(color, opt)\n\nresolves CSS color\n\n#### Parameters\n\n- `color` **[string][133]** color value\n  - system colors are not supported\n- `opt` **[object][135]?** options (optional, default `{}`)\n  - `opt.currentColor` **[string][133]?**\n    - color to use for `currentcolor` keyword\n    - if omitted, it will be treated as a missing color,\n      i.e. `rgb(none none none / none)`\n  - `opt.customProperty` **[object][135]?**\n    - custom properties\n    - pair of `--` prefixed property name as a key and it's value,\n      e.g.\n      ```javascript\n      const opt = {\n        customProperty: {\n          '--some-color': '#008000',\n          '--some-length': '16px'\n        }\n      };\n      ```\n    - and/or `callback` function to get the value of the custom property,\n      e.g.\n      ```javascript\n      const node = document.getElementById('foo');\n      const opt = {\n        customProperty: {\n          callback: node.style.getPropertyValue\n        }\n      };\n      ```\n  - `opt.dimension` **[object][135]?**\n    - dimension, e.g. for converting relative length to pixels\n    - pair of unit as a key and number in pixels as it's value,\n      e.g. suppose `1em === 12px`, `1rem === 16px` and `100vw === 1024px`, then\n      ```javascript\n      const opt = {\n        dimension: {\n          em: 12,\n          rem: 16,\n          vw: 10.24\n        }\n      };\n      ```\n    - and/or `callback` function to get the value as a number in pixels,\n      e.g.\n      ```javascript\n      const opt = {\n        dimension: {\n          callback: unit => {\n            switch (unit) {\n              case 'em':\n                return 12;\n              case 'rem':\n                return 16;\n              case 'vw':\n                return 10.24;\n              default:\n                return;\n            }\n          }\n        }\n      };\n      ```\n  - `opt.format` **[string][133]?**\n    - output format, one of below\n      - `computedValue` (default), [computed value][139] of the color\n      - `specifiedValue`, [specified value][140] of the color\n      - `hex`, hex color notation, i.e. `#rrggbb`\n      - `hexAlpha`, hex color notation with alpha channel, i.e. `#rrggbbaa`\n\nReturns **[string][133]?** one of `rgba?()`, `#rrggbb(aa)?`, `color-name`, `color(color-space r g b / alpha)`, `color(color-space x y z / alpha)`, `(ok)?lab(l a b / alpha)`, `(ok)?lch(l c h / alpha)`, `'(empty-string)'`, `null`\n\n- in `computedValue`, values are numbers, however `rgb()` values are integers\n- in `specifiedValue`, returns `empty string` for unknown and/or invalid color\n- in `hex`, returns `null` for `transparent`, and also returns `null` if any of `r`, `g`, `b`, `alpha` is not a number\n- in `hexAlpha`, returns `#00000000` for `transparent`, however returns `null` if any of `r`, `g`, `b`, `alpha` is not a number\n\n### convert\n\nContains various color conversion functions.\n\n### convert.numberToHex(value)\n\nconvert number to hex string\n\n#### Parameters\n\n- `value` **[number][134]** color value\n\nReturns **[string][133]** hex string: 00..ff\n\n### convert.colorToHex(value, opt)\n\nconvert color to hex\n\n#### Parameters\n\n- `value` **[string][133]** color value\n- `opt` **[object][135]?** options (optional, default `{}`)\n  - `opt.alpha` **[boolean][136]?** return in #rrggbbaa notation\n  - `opt.customProperty` **[object][135]?**\n    - custom properties, see `resolve()` function above\n  - `opt.dimension` **[object][135]?**\n    - dimension, see `resolve()` function above\n\nReturns **[string][133]** #rrggbb(aa)?\n\n### convert.colorToHsl(value, opt)\n\nconvert color to hsl\n\n#### Parameters\n\n- `value` **[string][133]** color value\n- `opt` **[object][135]?** options (optional, default `{}`)\n  - `opt.customProperty` **[object][135]?**\n    - custom properties, see `resolve()` function above\n  - `opt.dimension` **[object][135]?**\n    - dimension, see `resolve()` function above\n\nReturns **[Array][137]<[number][134]>** \\[h, s, l, alpha]\n\n### convert.colorToHwb(value, opt)\n\nconvert color to hwb\n\n#### Parameters\n\n- `value` **[string][133]** color value\n- `opt` **[object][135]?** options (optional, default `{}`)\n  - `opt.customProperty` **[object][135]?**\n    - custom properties, see `resolve()` function above\n  - `opt.dimension` **[object][135]?**\n    - dimension, see `resolve()` function above\n\nReturns **[Array][137]<[number][134]>** \\[h, w, b, alpha]\n\n### convert.colorToLab(value, opt)\n\nconvert color to lab\n\n#### Parameters\n\n- `value` **[string][133]** color value\n- `opt` **[object][135]?** options (optional, default `{}`)\n  - `opt.customProperty` **[object][135]?**\n    - custom properties, see `resolve()` function above\n  - `opt.dimension` **[object][135]?**\n    - dimension, see `resolve()` function above\n\nReturns **[Array][137]<[number][134]>** \\[l, a, b, alpha]\n\n### convert.colorToLch(value, opt)\n\nconvert color to lch\n\n#### Parameters\n\n- `value` **[string][133]** color value\n- `opt` **[object][135]?** options (optional, default `{}`)\n  - `opt.customProperty` **[object][135]?**\n    - custom properties, see `resolve()` function above\n  - `opt.dimension` **[object][135]?**\n    - dimension, see `resolve()` function above\n\nReturns **[Array][137]<[number][134]>** \\[l, c, h, alpha]\n\n### convert.colorToOklab(value, opt)\n\nconvert color to oklab\n\n#### Parameters\n\n- `value` **[string][133]** color value\n- `opt` **[object][135]?** options (optional, default `{}`)\n  - `opt.customProperty` **[object][135]?**\n    - custom properties, see `resolve()` function above\n  - `opt.dimension` **[object][135]?**\n    - dimension, see `resolve()` function above\n\nReturns **[Array][137]<[number][134]>** \\[l, a, b, alpha]\n\n### convert.colorToOklch(value, opt)\n\nconvert color to oklch\n\n#### Parameters\n\n- `value` **[string][133]** color value\n- `opt` **[object][135]?** options (optional, default `{}`)\n  - `opt.customProperty` **[object][135]?**\n    - custom properties, see `resolve()` function above\n  - `opt.dimension` **[object][135]?**\n    - dimension, see `resolve()` function above\n\nReturns **[Array][137]<[number][134]>** \\[l, c, h, alpha]\n\n### convert.colorToRgb(value, opt)\n\nconvert color to rgb\n\n#### Parameters\n\n- `value` **[string][133]** color value\n- `opt` **[object][135]?** options (optional, default `{}`)\n  - `opt.customProperty` **[object][135]?**\n    - custom properties, see `resolve()` function above\n  - `opt.dimension` **[object][135]?**\n    - dimension, see `resolve()` function above\n\nReturns **[Array][137]<[number][134]>** \\[r, g, b, alpha]\n\n### convert.colorToXyz(value, opt)\n\nconvert color to xyz\n\n#### Parameters\n\n- `value` **[string][133]** color value\n- `opt` **[object][135]?** options (optional, default `{}`)\n  - `opt.customProperty` **[object][135]?**\n    - custom properties, see `resolve()` function above\n  - `opt.dimension` **[object][135]?**\n    - dimension, see `resolve()` function above\n  - `opt.d50` **[boolean][136]?** xyz in d50 white point\n\nReturns **[Array][137]<[number][134]>** \\[x, y, z, alpha]\n\n### convert.colorToXyzD50(value, opt)\n\nconvert color to xyz-d50\n\n#### Parameters\n\n- `value` **[string][133]** color value\n- `opt` **[object][135]?** options (optional, default `{}`)\n  - `opt.customProperty` **[object][135]?**\n    - custom properties, see `resolve()` function above\n  - `opt.dimension` **[object][135]?**\n    - dimension, see `resolve()` function above\n\nReturns **[Array][137]<[number][134]>** \\[x, y, z, alpha]\n\n### utils\n\nContains utility functions.\n\n### utils.isColor(color)\n\nis valid color type\n\n#### Parameters\n\n- `color` **[string][133]** color value\n  - system colors are not supported\n\nReturns **[boolean][136]**\n\n## Acknowledgments\n\nThe following resources have been of great help in the development of the CSS color.\n\n- [csstools/postcss-plugins](https://github.com/csstools/postcss-plugins)\n- [lru-cache](https://github.com/isaacs/node-lru-cache)\n\n---\n\nCopyright (c) 2024 [asamuzaK (Kazz)](https://github.com/asamuzaK/)\n\n[133]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String\n[134]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number\n[135]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object\n[136]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean\n[137]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array\n[138]: https://w3c.github.io/csswg-drafts/css-color-4/#color-conversion-code\n[139]: https://developer.mozilla.org/en-US/docs/Web/CSS/computed_value\n[140]: https://developer.mozilla.org/en-US/docs/Web/CSS/specified_value\n[141]: https://www.npmjs.com/package/@csstools/css-calc\n","publish_time":1735346531608,"maintainers":[{"name":"asamuzakjp","email":"info@asamuzak.jp"}],"_cnpm_publish_time":1735346531608,"dist-tags":{"latest":"7.2.0","legacy":"2.8.3","next":"2.8.3-b.2"}}