{"_id":"@asamuzakjp/css-color@7.2.0","bugs":{"url":"https://github.com/asamuzaK/cssColor/issues"},"dist":{"shasum":"0342341ee893c0664047f45ab18b99abb3d10447","tarball":"http://registry-npm.ywwl.com/@asamuzakjp/css-color/download/@asamuzakjp/css-color-7.2.0.tgz","fileCount":48,"integrity":"sha512-+JNLVlzePs1XiBT5s9aVkEjOePRoB//tk3bc69BGdzQCz7EICVSQuVPZu6tjc7vAJxBx5fama67LbOltwnXzPQ==","signatures":[{"sig":"MEYCIQDYvCdrcnhBSyv1/L9tWolRVXgCmMsTuHUDlIV1BPqLiQIhAOdC2oebUOmf5xZLKn82ok1AUFP5vK70oenDPggSd3ZL","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIGwHFrGUD12qJJ+CjnC2HBC1iFsVwrdMrMxbABJVsRZRAiEAn8RZjP2wRwxYFsWlBVA51vLcnL7TDL3f8Rys8Pnp5Sk="}],"unpackedSize":480109,"size":88152,"noattachment":false,"key":"/@asamuzakjp/css-color/-/@asamuzakjp/css-color-7.2.0.tgz"},"name":"@asamuzakjp/css-color","type":"module","types":"./dist/esm/index.d.ts","author":{"name":"asamuzaK"},"engines":{"node":"^22.22.2 || ^24.15.0 || >=26.0.0"},"exports":{".":{"types":"./dist/esm/index.d.ts","default":"./dist/esm/index.js"},"./package.json":"./package.json"},"gitHead":"a0fcbccfa840b868606e78157d29684d467c8b4d","license":"MIT","scripts":{"knip":"knip","lint":"eslint . --fix","test":"npm run lint && npm run test:types && npm run test:unit","build":"npm run clean && npm run test && npm run knip && vite build && npm run publint","clean":"rimraf ./coverage ./dist","clone":"node ./scripts/clone-txt.js","publint":"publint --strict","test:unit":"vitest","test:types":"tsc","bench:color":"npx tsx --expose-gc ./benchmark/bench-color.ts"},"version":"7.2.0","_npmUser":{"name":"asamuzakjp","email":"info@asamuzak.jp"},"homepage":"https://github.com/asamuzaK/cssColor#readme","overrides":{"glob":"^14.0.3","minimatch":"^11.0.4"},"repository":{"url":"git+https://github.com/asamuzaK/cssColor.git","type":"git"},"_npmVersion":"12.2.1","description":"CSS color - Resolve and convert CSS colors.","directories":{},"maintainers":[{"name":"asamuzakjp","email":"info@asamuzak.jp"}],"_nodeVersion":"24.18.1","allowScripts":{"esbuild@0.28.2":true},"dependencies":{"lru-cache":"^11.5.3","@csstools/css-calc":"^3.4.3","@csstools/css-tokenizer":"^4.0.2","@csstools/css-color-parser":"^4.2.7","@csstools/css-parser-algorithms":"^4.0.2"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.23.15","knip":"^6.44.2","vite":"^8.3.6","eslint":"^10.14.0","mitata":"^1.0.34","rimraf":"^6.1.4","vitest":"^5.1.0","esbuild":"^0.28.2","globals":"^17.14.0","publint":"^0.3.25","prettier":"^3.9.10","typescript":"^6.0.3","@types/node":"^26.6.6","neostandard":"^0.14.1","eslint-plugin-jsdoc":"^65.4.5","eslint-plugin-regexp":"^3.3.3","eslint-config-prettier":"^10.1.8","eslint-plugin-prettier":"^5.5.7","@vitest/coverage-istanbul":"^5.1.0","prettier-plugin-brace-style":"^0.10.4"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/css-color_7.2.0_1794129340529_0.8538698392709086"},"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\nA robust and modern library to resolve, parse, and convert CSS colors.\nSupports the latest CSS Color Module Level 4 & 5 specifications.\n\n## Features\n\n- **Modern CSS Color Support:** Accurately resolves `color-mix()`, `color()`, modern color spaces (`oklch`, `oklab`, `lch`, `lab`, `hwb`, etc.), and relative colors (`lab(from red l a b)`, `color(from red xyz-d50 x y z)`).\n- **Deep Resolution:** Deeply resolves `var()` and `calc()` functions embedded within color values.\n- **Gradient Resolution & Parsing:** Supports resolving, parsing, and validation for `linear-gradient`, `radial-gradient`, and `conic-gradient`.\n- **Comprehensive Color Conversion:** Highly accurate converters between HEX, HSL, HWB, LAB, LCH, Oklab, Oklch, RGB, and XYZ color spaces.\n- **Bonus Utilities:** Includes convenient functions to validate colors or gradients, extract CSS variables, and safely split CSS values.\n- **Used in jsdom:** Adopted as the CSS color parser and resolver for `jsdom`.\n- **Pure ESM with TypeScript Ready:** Native ESM (`type: \"module\"`) with comprehensive TypeScript definitions.\n\n## Install\n\n```console\nnpm i @asamuzakjp/css-color\n```\n\n## Quick Start\n\n```javascript\nimport {\n  convert,\n  resolve,\n  resolveGradient,\n  utils\n} from '@asamuzakjp/css-color';\n```\n\n### Samples\n\n1. Resolve complex modern CSS colors:\n\n```javascript\nconst resolvedMix = 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```\n\n2. Resolve with Custom Properties and calc():\n\n```javascript\nconst resolvedVar = resolve('hsl(calc(var(--base-hue) * 3) 100% 50% / .5)', {\n  customProperty: { '--base-hue': '210deg' }\n});\n// => 'rgba(128, 0, 255, 0.5)'\n```\n\n3. Resolve gradients:\n\n```javascript\nconst resolvedGradient = resolveGradient(\n  'linear-gradient(to right, red, blue)'\n);\n// => 'linear-gradient(to right, rgb(255 0 0), rgb(0 0 255))'\n```\n\n4. Convert between color spaces:\n\n```javascript\nconst hex = convert.colorToHex('lab(46.2775% -47.5621 48.5837)');\n// => '#008000'\n```\n\n5. Validate colors and gradients:\n\n```javascript\nconst isColor = utils.isColor('light-dark(red, blue)');\n// => true\n\nconst isGradient = utils.isGradient(\n  'conic-gradient(from 0.5turn at 50% 50%, red, blue)'\n);\n// => true\n```\n\n## API Reference\n\n### `resolve(color, opt?)`\n\nResolves a CSS color string into its computed or specified value. System colors are not supported.\n\n- **`color`** `<string>`: The CSS color value to resolve.\n- **`opt`** `<object>` _(optional)_:\n  - `opt.currentColor`: Color to use for the `currentcolor` keyword.\n  - `opt.customProperty`: Object containing `--` prefixed keys and their values, or a `callback(propertyName)` function to dynamically resolve CSS variables.\n  - `opt.dimension`: Object mapping units (e.g., `em`, `rem`, `vw`) to pixel numbers, or a `callback(unit)` function for dynamic length resolution.\n  - `opt.format`: Output format. Options: `computedValue` (default), `specifiedValue`, `hex`, `hexAlpha`.\n  - `opt.colorScheme`: `normal` (default), `light`, or `dark` (useful for `light-dark()` resolution).\n\n### `resolveGradient(gradient, opt?)`\n\nResolves a CSS gradient string (e.g., `linear-gradient`, `radial-gradient`, `conic-gradient`) into its resolved form.\n\n- **`gradient`** `<string>`: The CSS gradient string to resolve.\n- **`opt`** `<object>` _(optional)_: Same options as `resolve`.\n\n### `convert`\n\nA collection of color conversion utilities.\n\n<!-- prettier-ignore -->\n| Function | Returns | Options | Description |\n| :-------------- | :-------------- | :-------------- | :-------------- |\n| `convert.colorToA98Rgb(value, opt?)` | `number[]` | _See `resolve` options_ | Converts to Adobe RGB (1998) channels: `[r, g, b, alpha]`. |\n| `convert.colorToDisplayP3(value, opt?)` | `number[]` | _See `resolve` options_ | Converts to Display P3 channels: `[r, g, b, alpha]`. |\n| `convert.colorToHex(value, opt?)` | `string \\| null` | `opt.alpha` `<boolean>`<br>_(+ see `resolve` options)_ | Returns `#rrggbb` or `#rrggbbaa` (if `opt.alpha` is true). |\n| `convert.colorToHsl(value, opt?)` | `number[]` | _See `resolve` options_ | Converts to HSL channels: `[h, s, l, alpha]`. |\n| `convert.colorToHwb(value, opt?)` | `number[]` | _See `resolve` options_ | Converts to HWB channels: `[h, w, b, alpha]`. |\n| `convert.colorToLab(value, opt?)` | `number[]` | _See `resolve` options_ | Converts to CIE LAB channels: `[l, a, b, alpha]`. |\n| `convert.colorToLch(value, opt?)` | `number[]` | _See `resolve` options_ | Converts to CIE LCH channels: `[l, c, h, alpha]`. |\n| `convert.colorToLinearP3(value, opt?)` | `number[]` | _See `resolve` options_ | Converts to linear Display P3 channels: `[r, g, b, alpha]`. |\n| `convert.colorToOklab(value, opt?)` | `number[]` | _See `resolve` options_ | Converts to Oklab channels: `[l, a, b, alpha]`. |\n| `convert.colorToOklch(value, opt?)` | `number[]` | _See `resolve` options_ | Converts to Oklch channels: `[l, c, h, alpha]`. |\n| `convert.colorToProphotoRgb(value, opt?)` | `number[]` | _See `resolve` options_ | Converts to ProPhoto RGB channels: `[r, g, b, alpha]`. |\n| `convert.colorToRec2020(value, opt?)` | `number[]` | _See `resolve` options_ | Converts to Rec. 2020 channels: `[r, g, b, alpha]`. |\n| `convert.colorToRgb(value, opt?)` | `number[]` | _See `resolve` options_ | Converts to sRGB channels: `[r, g, b, alpha]`. |\n| `convert.colorToXyz(value, opt?)` | `number[]` | _See `resolve` options_ | Converts to CIE XYZ channels (defaults to D65): `[x, y, z, alpha]`. |\n| `convert.colorToXyzD50(value, opt?)` | `number[]` | _See `resolve` options_ | Converts to CIE XYZ channels with D50 white point. |\n| `convert.numberToHex(value)` | `string` | _None_ | Converts a numeric value to a two-digit hexadecimal string. |\n\n### `utils`\n\nInternal tools exposed for advanced usage, parsing, and validation.\n\n<!-- prettier-ignore -->\n| Function | Returns | Options (`opt`) | Description |\n| :-------------- | :-------------- | :-------------- | :-------------- |\n| `utils.cssCalc(value, opt?)` | `string` | `opt.dimension`<br>_(+ see `resolve` options)_ | Resolves CSS `calc()` expressions. |\n| `utils.cssVar(value, opt?)` | `string` | `opt.customProperty`<br>_(+ see `resolve` options)_ | Resolves CSS `var()` expressions. |\n| `utils.extractDashedIdent(value)` | `string[]` | _None_ | Extracts custom property names (dashed-ident tokens) from a value. |\n| `utils.isColor(value, opt?)` | `boolean` | _See `resolve` options_ | Returns `true` if the string is a valid CSS color. |\n| `utils.isGradient(value, opt?)` | `boolean` | _See `resolve` options_ | Returns `true` if the string is a valid CSS gradient. |\n| `utils.resolveGradient(value, opt?)` | `string` | _See `resolve` options_ | **Deprecated:** Use `resolveGradient` directly instead. |\n| `utils.resolveLengthInPixels(value, unit, opt?)` | `number` | `opt.dimension`<br>_(+ see `resolve` options)_ | Converts an absolute or relative CSS length to pixels. |\n| `utils.splitValue(value, opt?)` | `string[]` | `opt.delimiter` `<string>`<br>`opt.preserveComment` `<boolean>` | Safely splits a CSS value by a specified delimiter (` `, `,`, `/`). |\n\n## Acknowledgments\n\nThe following resources have been of great help in the development of this library:\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","publish_time":1794129340623,"_cnpm_publish_time":1794129340623,"dist-tags":{"latest":"7.2.0","legacy":"2.8.3","next":"2.8.3-b.2"}}