{"name":"@asamuzakjp/css-color","version":"4.0.2","author":{"name":"asamuzaK"},"license":"MIT","_id":"@asamuzakjp/css-color@4.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":"3d0b3b69864f9fbaa8c8b63e52beb771322cdb19","tarball":"http://registry-npm.ywwl.com/@asamuzakjp/css-color/download/@asamuzakjp/css-color-4.0.2.tgz","fileCount":58,"integrity":"sha512-6yXf6j6s9Lz0l+yQZhHtsdqinhy0eQe69lGsow9fhULDUgglaUbsKr7+wqZ+zREcG0EzshYlTwEjqaNj9VKNMw==","signatures":[{"sig":"MEQCIBKqid+gOtKlvLJi/y0QVkmeD9FQKjuH7uwNIh2YilsuAiAouKe5XZxZ9sg59zuJjRI3USK4b/4Vm3gnQLWCiW9S4Q==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":2153246,"size":396675,"noattachment":false,"key":"/@asamuzakjp/css-color/-/@asamuzakjp/css-color-4.0.2.tgz"},"main":"dist/cjs/index.cjs","pnpm":{"onlyBuiltDependencies":["esbuild","oxc-resolver","unrs-resolver"]},"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":"ebaeb9696a94d732578b1a442a123bc12474928a","scripts":{"knip":"knip","test":"pnpm run prettier && pnpm run --stream \"/^test:.*/\"","build":"pnpm run clean && pnpm run test && pnpm run knip && pnpm run build:prod && pnpm run build:cjs && pnpm run build:browser && pnpm run publint","clean":"rimraf ./coverage ./dist","publint":"publint --strict","prettier":"prettier . --ignore-unknown --write","build:cjs":"tsup ./src/index.ts --format=cjs --platform=node --outDir=./dist/cjs/ --sourcemap --dts","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.4.2","description":"CSS color - Resolve and convert CSS colors.","directories":{},"_nodeVersion":"22.16.0","dependencies":{"lru-cache":"^11.1.0","@csstools/css-calc":"^2.1.4","@csstools/css-tokenizer":"^3.0.4","@csstools/css-color-parser":"^3.0.10","@csstools/css-parser-algorithms":"^3.0.5"},"_hasShrinkwrap":false,"packageManager":"pnpm@10.13.1","devDependencies":{"knip":"^5.61.3","tsup":"^8.5.0","vite":"^6.3.5","eslint":"^9.31.0","rimraf":"^6.0.1","vitest":"^3.2.4","esbuild":"^0.25.6","globals":"^16.3.0","publint":"^0.3.12","prettier":"^3.6.2","typescript":"^5.8.3","neostandard":"^0.12.2","eslint-plugin-regexp":"^2.9.0","@tanstack/vite-config":"^0.2.0","@vitest/coverage-istanbul":"^3.2.4"},"_npmOperationalInternal":{"tmp":"tmp/css-color_4.0.2_1752533875439_0.4876405076217454","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":1752533875685,"_cnpm_publish_time":1752533875685,"dist-tags":{"latest":"7.2.0","legacy":"2.8.3","next":"2.8.3-b.2"}}