{"name":"@asamuzakjp/css-color","version":"6.0.2","author":{"name":"asamuzaK"},"license":"MIT","_id":"@asamuzakjp/css-color@6.0.2","maintainers":[{"name":"asamuzakjp","email":"info@asamuzak.jp"}],"homepage":"https://github.com/asamuzaK/cssColor#readme","bugs":{"url":"https://github.com/asamuzaK/cssColor/issues"},"dist":{"shasum":"258c91498485aa816c62f9e932eb73fb9fefdf8b","tarball":"http://registry-npm.ywwl.com/@asamuzakjp/css-color/download/@asamuzakjp/css-color-6.0.2.tgz","fileCount":49,"integrity":"sha512-wILU0WYd7n1ifXmpYhuVxrB2zzzoFuqBH6E7fz3gApKAL9GH4am68dWOftY+uJS6pe9RVx1UX3lPNRjJMeSCgA==","signatures":[{"sig":"MEYCIQClpOp7SCvy3IPoPSK7IuLzh5Ej9rywxcXvXJDpEbehMAIhALKhR/WBx8BAWF28HSqjET1pm34ifuKhwn56tPdP61tK","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":716900,"size":130158,"noattachment":false,"key":"/@asamuzakjp/css-color/-/@asamuzakjp/css-color-6.0.2.tgz"},"pnpm":{"overrides":{"ajv":"^8.18.0","minimatch":"^3.1.5","eslint>ajv":"^6.14.0","glob>minimatch":"^10.2.4","brace-expansion":"^5.0.4","lodash@<=4.17.23":">=4.18.0","@eslint/eslintrc>ajv":"^6.14.0","lodash@>=4.0.0 <=4.17.23":">=4.18.0","@vue/language-core>minimatch":"^9.0.9","eslint-plugin-import-x>minimatch":"^10.2.4","@typescript-eslint/typescript-estree>minimatch":"^9.0.9"},"onlyBuiltDependencies":["esbuild","oxc-resolver","unrs-resolver"]},"type":"module","types":"./dist/esm/index.d.ts","engines":{"node":"^22.13.0 || >=24.0.0"},"exports":{".":{"types":"./dist/esm/index.d.ts","default":"./dist/esm/index.js"},"./package.json":"./package.json"},"gitHead":"4cd5ef458e3384eb4065cd541679b20f8b324723","scripts":{"knip":"knip","test":"pnpm run prettier && pnpm run --stream \"/^test:.*/\"","build":"pnpm run clean && pnpm run test && pnpm run knip && vite build && pnpm run publint","clean":"rimraf ./coverage ./dist","publint":"publint --strict","prettier":"prettier . --ignore-unknown --write","test:unit":"vitest","test:types":"tsc","bench:color":"npx tsx --expose-gc ./benchmark/bench-color.ts","test:eslint":"eslint ./src ./test --fix"},"_npmUser":{"name":"asamuzakjp","email":"info@asamuzak.jp"},"repository":{"url":"git+https://github.com/asamuzaK/cssColor.git","type":"git"},"_npmVersion":"11.14.1","description":"CSS color - Resolve and convert CSS colors.","directories":{},"_nodeVersion":"24.15.0","dependencies":{"@csstools/css-calc":"^3.2.1","@csstools/css-tokenizer":"^4.0.0","@csstools/css-color-parser":"^4.1.1","@asamuzakjp/generational-cache":"^2.0.2","@csstools/css-parser-algorithms":"^4.0.0"},"_hasShrinkwrap":false,"packageManager":"pnpm@10.33.2","devDependencies":{"tsx":"^4.22.3","knip":"^6.14.1","vite":"^8.0.13","eslint":"^9.39.4","mitata":"^1.0.34","rimraf":"^6.1.3","vitest":"^4.1.7","esbuild":"^0.28.0","globals":"^17.6.0","publint":"^0.3.21","prettier":"^3.8.3","typescript":"^5.9.3","@types/node":"^25.9.1","neostandard":"^0.13.0","eslint-plugin-regexp":"^3.1.0","@tanstack/vite-config":"^0.5.2","@vitest/coverage-istanbul":"^4.1.7"},"_npmOperationalInternal":{"tmp":"tmp/css-color_6.0.2_1779292277022_0.6828311996944998","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\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 Parsing:** Supports 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 { convert, resolve, utils } 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. Convert between color spaces:\n\n```javascript\nconst hex = convert.colorToHex('lab(46.2775% -47.5621 48.5837)');\n// => '#008000'\n```\n\n4. 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### `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_ | Resolves CSS gradient strings. |\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":1779292277162,"_cnpm_publish_time":1779292277162,"dist-tags":{"latest":"7.2.0","legacy":"2.8.3","next":"2.8.3-b.2"}}