{"name":"@asamuzakjp/css-color","version":"3.0.2","author":{"name":"asamuzaK"},"license":"MIT","_id":"@asamuzakjp/css-color@3.0.2","homepage":"https://github.com/asamuzaK/cssColor#readme","bugs":{"url":"https://github.com/asamuzaK/cssColor/issues"},"dist":{"shasum":"96a2c03467342fefe78654439b2151db64615ccb","tarball":"http://registry-npm.ywwl.com/@asamuzakjp/css-color/download/@asamuzakjp/css-color-3.0.2.tgz","fileCount":78,"integrity":"sha512-a8puD5V+O2iGfm/Y9Ow+6kGLfdGB5Y32Mg7LRLdhLTk7fhTdBlRJzN4kSMZtytjywVgZxH9IInJjQ0aVT7L3xg==","signatures":[{"sig":"MEUCIAHHRLv6hA1mcikqYrPxGvxGSUHwukeo1yOo4tO+GlpaAiEA2g7L0p02uD2SLur2zVgaGH08fvBRMvN19jdd9UKTRfA=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":2000375,"size":349640,"noattachment":false,"key":"/@asamuzakjp/css-color/-/@asamuzakjp/css-color-3.0.2.tgz"},"main":"dist/cjs/index.cjs","type":"module","types":"dist/esm/index.d.ts","module":"dist/esm/index.js","exports":{".":{"import":{"types":"./dist/esm/index.d.ts","default":"./dist/esm/index.js"},"require":{"types":"./dist/cjs/index.d.cts","default":"./dist/cjs/index.cjs"}},"./package.json":"./package.json"},"gitHead":"8a969744a3eee54166516000fc05f25c95c48e42","scripts":{"test":"pnpm run prettier && pnpm run --stream \"/^test:.*/\" && pnpm run build && pnpm run publint","build":"pnpm run build:prod && pnpm run build:browser","clean":"rimraf ./dist && rimraf ./coverage","publint":"publint --strict","prettier":"prettier . --ignore-unknown --write","test:knip":"knip","test:unit":"vitest","build:prod":"vite build","test:types":"tsc","test:eslint":"eslint ./src ./test --fix","build:browser":"vite build -c vite.browser.config.ts"},"_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.13.1","dependencies":{"lru-cache":"^10.4.3","@csstools/css-calc":"^2.1.1","@csstools/css-tokenizer":"^3.0.3","@csstools/css-color-parser":"^3.0.7","@csstools/css-parser-algorithms":"^3.0.4"},"_hasShrinkwrap":false,"packageManager":"pnpm@9.15.3","devDependencies":{"knip":"^5.43.3","vite":"^6.0.11","eslint":"^9.19.0","rimraf":"^6.0.1","vitest":"^3.0.4","esbuild":"^0.24.2","globals":"^15.14.0","publint":"^0.3.2","prettier":"^3.4.2","typescript":"^5.7.3","neostandard":"^0.12.0","@tanstack/config":"^0.16.0","eslint-plugin-regexp":"^2.7.0","eslint-plugin-import-x":"^4.6.1","@vitest/coverage-istanbul":"^3.0.4"},"_npmOperationalInternal":{"tmp":"tmp/css-color_3.0.2_1737779329105_0.09079185296407077","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":1737779329366,"maintainers":[{"name":"asamuzakjp","email":"info@asamuzak.jp"}],"_cnpm_publish_time":1737779329366,"dist-tags":{"latest":"7.2.0","legacy":"2.8.3","next":"2.8.3-b.2"}}