{"_id":"@asamuzakjp/css-color@7.1.2","bugs":{"url":"https://github.com/asamuzaK/cssColor/issues"},"dist":{"shasum":"940f4936061633c33b78aa5703c7dfd6e0ae0b86","tarball":"http://registry-npm.ywwl.com/@asamuzakjp/css-color/download/@asamuzakjp/css-color-7.1.2.tgz","fileCount":46,"integrity":"sha512-99DHAnXDB5z6EEK+9GMpVI7Mw4oxj97dY5bpOzMnjADQWxI8rN6TvTduuFLUhUMlS7/CfVZ06tcZsus6cltnNw==","signatures":[{"sig":"MEYCIQCHhgrcdo7Qa9jBi4Wfs6sfpuk4Tf4ka1DkCw4xjDtEOwIhAOHarsM5IVao3apRHT5shyt057Cxk5EuVM8AZ0yfyUZj","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIGVK0UggqVMdoIjcf07sijAP+9GgaMXpEbkyWLbKi9BiAiBC5S2RkIKX1HxDvZaDHK7+592xGQK5N+irqSekFmUXUQ=="}],"unpackedSize":383274,"size":75428,"noattachment":false,"key":"/@asamuzakjp/css-color/-/@asamuzakjp/css-color-7.1.2.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":"0e10c739ecc87da447feb82e8abb31d01af1ed94","license":"MIT","scripts":{"knip":"knip","lint":"eslint ./src ./test --fix","test":"npm run prettier && 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","prettier":"prettier . --ignore-unknown --write","test:unit":"vitest","test:types":"tsc","bench:color":"npx tsx --expose-gc ./benchmark/bench-color.ts"},"version":"7.1.2","_npmUser":{"name":"asamuzakjp","email":"info@asamuzak.jp"},"homepage":"https://github.com/asamuzaK/cssColor#readme","repository":{"url":"git+https://github.com/asamuzaK/cssColor.git","type":"git"},"_npmVersion":"12.0.2","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.1","@csstools/css-tokenizer":"^4.0.2","@csstools/css-color-parser":"^4.2.4","@csstools/css-parser-algorithms":"^4.0.1"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.23.15","knip":"^6.38.0","vite":"^8.3.1","eslint":"^10.11.0","mitata":"^1.0.34","rimraf":"^6.1.3","vitest":"^5.0.2","esbuild":"^0.28.2","globals":"^17.12.0","publint":"^0.3.24","prettier":"^3.9.9","typescript":"^6.0.3","@types/node":"^26.6.3","neostandard":"^0.14.0-next.1","eslint-plugin-regexp":"^3.3.1","@vitest/coverage-istanbul":"^5.0.2"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/css-color_7.1.2_1790467548739_0.013211966329458757"},"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.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.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.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\n### `utils`\n\nHelpful internal 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":1790467548818,"_cnpm_publish_time":1790467548818,"dist-tags":{"latest":"7.2.0","legacy":"2.8.3","next":"2.8.3-b.2"}}