Showing preview only (1,324K chars total). Download the full file or copy to clipboard to get everything.
Repository: gka/chroma.js
Branch: main
Commit: 87058d62a50c
Files: 201
Total size: 1.2 MB
Directory structure:
gitextract_vl9uye1t/
├── .changeset/
│ ├── README.md
│ └── config.json
├── .github/
│ ├── CODEOWNERS
│ ├── FUNDING.yml
│ └── workflows/
│ └── ci.yml
├── .gitignore
├── .husky/
│ └── pre-commit
├── .npmignore
├── .travis.yml
├── CHANGELOG.md
├── LICENSE
├── dist/
│ ├── chroma-light.cjs
│ ├── chroma-light.min.cjs
│ ├── chroma.cjs
│ └── chroma.min.cjs
├── docs/
│ ├── Makefile
│ ├── bin/
│ │ └── post-process
│ ├── index.html
│ ├── libs/
│ │ ├── chroma-light.cjs
│ │ ├── chroma-light.min.cjs
│ │ ├── chroma.cjs
│ │ ├── chroma.min.cjs
│ │ └── codemirror/
│ │ ├── lib/
│ │ │ ├── codemirror.css
│ │ │ └── codemirror.js
│ │ └── mode/
│ │ ├── javascript/
│ │ │ ├── index.html
│ │ │ ├── javascript.js
│ │ │ ├── json-ld.html
│ │ │ ├── test.js
│ │ │ └── typescript.html
│ │ └── shell/
│ │ └── shell.js
│ └── src/
│ ├── footer.inc.html
│ ├── index.css
│ └── index.md
├── eslint.config.mjs
├── index-light.js
├── index.js
├── index.umd.js
├── index.umd.light.js
├── package.json
├── prettier.config.js
├── readme.md
├── rollup.config.js
├── src/
│ ├── Color.js
│ ├── chroma.js
│ ├── colors/
│ │ ├── colorbrewer.js
│ │ └── w3cx11.js
│ ├── generator/
│ │ ├── average.js
│ │ ├── bezier.js
│ │ ├── blend.js
│ │ ├── cubehelix.js
│ │ ├── mix.js
│ │ ├── random.js
│ │ └── scale.js
│ ├── interpolator/
│ │ ├── _hsx.js
│ │ ├── hcg.js
│ │ ├── hsi.js
│ │ ├── hsl.js
│ │ ├── hsv.js
│ │ ├── index.js
│ │ ├── lab.js
│ │ ├── lch.js
│ │ ├── lrgb.js
│ │ ├── num.js
│ │ ├── oklab.js
│ │ ├── oklch.js
│ │ └── rgb.js
│ ├── io/
│ │ ├── cmyk/
│ │ │ ├── cmyk2rgb.js
│ │ │ ├── index.js
│ │ │ └── rgb2cmyk.js
│ │ ├── css/
│ │ │ ├── css2rgb.js
│ │ │ ├── hsl2css.js
│ │ │ ├── index.js
│ │ │ ├── lab2css.js
│ │ │ ├── lch2css.js
│ │ │ ├── oklab2css.js
│ │ │ ├── oklch2css.js
│ │ │ └── rgb2css.js
│ │ ├── delta-e.coffee
│ │ ├── distance.coffee
│ │ ├── gl/
│ │ │ └── index.js
│ │ ├── hcg/
│ │ │ ├── hcg2rgb.js
│ │ │ ├── index.js
│ │ │ └── rgb2hcg.js
│ │ ├── hex/
│ │ │ ├── hex2rgb.js
│ │ │ ├── index.js
│ │ │ └── rgb2hex.js
│ │ ├── hsi/
│ │ │ ├── hsi2rgb.js
│ │ │ ├── index.js
│ │ │ └── rgb2hsi.js
│ │ ├── hsl/
│ │ │ ├── hsl2rgb.js
│ │ │ ├── index.js
│ │ │ └── rgb2hsl.js
│ │ ├── hsv/
│ │ │ ├── hsv2rgb.js
│ │ │ ├── index.js
│ │ │ └── rgb2hsv.js
│ │ ├── input.js
│ │ ├── lab/
│ │ │ ├── index.js
│ │ │ ├── lab-constants.js
│ │ │ ├── lab2rgb.js
│ │ │ └── rgb2lab.js
│ │ ├── lch/
│ │ │ ├── hcl2rgb.js
│ │ │ ├── index.js
│ │ │ ├── lab2lch.js
│ │ │ ├── lch2lab.js
│ │ │ ├── lch2rgb.js
│ │ │ └── rgb2lch.js
│ │ ├── named/
│ │ │ └── index.js
│ │ ├── num/
│ │ │ ├── index.js
│ │ │ ├── num2rgb.js
│ │ │ └── rgb2num.js
│ │ ├── oklab/
│ │ │ ├── index.js
│ │ │ ├── oklab2rgb.js
│ │ │ └── rgb2oklab.js
│ │ ├── oklch/
│ │ │ ├── index.js
│ │ │ ├── oklch2rgb.js
│ │ │ └── rgb2oklch.js
│ │ ├── rgb/
│ │ │ └── index.js
│ │ └── temp/
│ │ ├── index.js
│ │ ├── rgb2temperature.js
│ │ └── temperature2rgb.js
│ ├── ops/
│ │ ├── alpha.js
│ │ ├── clipped.js
│ │ ├── darken.js
│ │ ├── get.js
│ │ ├── luminance.js
│ │ ├── mix.js
│ │ ├── premultiply.js
│ │ ├── saturate.js
│ │ ├── set.js
│ │ └── shade.js
│ ├── utils/
│ │ ├── analyze.js
│ │ ├── clip_rgb.js
│ │ ├── contrast.js
│ │ ├── contrastAPCA.js
│ │ ├── delta-e.js
│ │ ├── distance.js
│ │ ├── index.js
│ │ ├── last.js
│ │ ├── limit.js
│ │ ├── multiply-matrices.js
│ │ ├── scales.js
│ │ ├── type.js
│ │ ├── unpack.js
│ │ └── valid.js
│ └── version.js
├── test/
│ ├── alpha.test.js
│ ├── analyze.test.js
│ ├── autodetect.test.js
│ ├── average.test.js
│ ├── bezier.test.js
│ ├── blend.test.js
│ ├── color.test.js
│ ├── colorbrewer.test.js
│ ├── contrast.test.js
│ ├── converters.test.js
│ ├── cubehelix.test.js
│ ├── delta-e.test.js
│ ├── docs/
│ │ └── index.test.js
│ ├── html/
│ │ ├── bezier.html
│ │ ├── blend.html
│ │ ├── colorscales.html
│ │ ├── cubehelix.html
│ │ └── luminance.html
│ ├── io/
│ │ ├── cmyk2rgb.test.js
│ │ ├── css2rgb.test.js
│ │ ├── hcg2rgb.test.js
│ │ ├── hex2rgb.test.js
│ │ ├── hsi2rgb.test.js
│ │ ├── hsl2rgb.test.js
│ │ ├── hsv2rgb.test.js
│ │ ├── lab2lch.test.js
│ │ ├── lab2rgb.test.js
│ │ ├── lch2lab.test.js
│ │ ├── lch2rgb.test.js
│ │ ├── num2rgb.test.js
│ │ ├── oklab2rgb.test.js
│ │ ├── oklch2rgb.test.js
│ │ ├── rgb2cmyk.test.js
│ │ ├── rgb2css.test.js
│ │ ├── rgb2hex.test.js
│ │ ├── rgb2hsi.test.js
│ │ ├── rgb2hsv.test.js
│ │ ├── rgb2lab.test.js
│ │ ├── rgb2lch.test.js
│ │ ├── rgb2oklab.test.js
│ │ └── rgb2oklch.test.js
│ ├── lch.test.js
│ ├── limits.test.js
│ ├── luminance.test.js
│ ├── manipulate.test.js
│ ├── misc.test.js
│ ├── mix.test.js
│ ├── num.test.js
│ ├── premultiply.test.js
│ ├── random.test.js
│ ├── scale.lcorrection.test.js
│ ├── scales.test.js
│ ├── temperature2rgb.test.js
│ ├── unpack.test.js
│ └── valid.test.js
└── vitest.config.mjs
================================================
FILE CONTENTS
================================================
================================================
FILE: .changeset/README.md
================================================
# Changesets
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
================================================
FILE: .changeset/config.json
================================================
{
"$schema": "https://unpkg.com/@changesets/config@3.1.2/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
================================================
FILE: .github/CODEOWNERS
================================================
* @gka
================================================
FILE: .github/FUNDING.yml
================================================
# These are supported funding model platforms
github: gka
patreon: # Replace with a single Patreon username
open_collective: gka
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
polar: # Replace with a single Polar username
buy_me_a_coffee: # Replace with a single Buy Me a Coffee username
thanks_dev: gh/gka
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
================================================
FILE: .github/workflows/ci.yml
================================================
name: CI
on:
pull_request:
branches:
- main
push:
branches:
- main
jobs:
lint-and-test:
runs-on: ubuntu-latest
env:
CI: true
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
version: 10.24.0
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Lint
run: pnpm lint
- name: Test
run: pnpm test -- --run
================================================
FILE: .gitignore
================================================
readme (Autosaved).md
m.txt
.DS_Store
license.coffee
node_modules
================================================
FILE: .husky/pre-commit
================================================
pnpm run lint
pnpm test -- --run
================================================
FILE: .npmignore
================================================
# .gitignore equivelant
.git*
readme (Autosaved).md
m.txt
.DS_Store
license.coffee
node_modules
yarn.lock
# Dev content
test/
docs/
.eslintrc.js
.travis.yml
Gruntfile.js
rollup.config.js
================================================
FILE: .travis.yml
================================================
language: node_js
node_js:
- "20"
before_script: "npm install"
script: "npm test"
================================================
FILE: CHANGELOG.md
================================================
## Changelog
### 3.2.0
- scale.domain now returns the original domain array when called with no arguments
### 3.1.3
- updated dependencies
### 3.1.2
- fixed a bug in Lch interpolation of hue-less colors
### 3.1.1
- fix: allow deep-imports in vite projects
### 3.1.0
- feat: parse `'transparent'` as black with 0% opacity - resolves [#280](https://github.com/gka/chroma.js/issues/280)
- make it easier to access colorbrewer palette names - resolves [#314](https://github.com/gka/chroma.js/issues/314)
- docs: explain differences to official colorbrewer scales - resolves [#316](https://github.com/gka/chroma.js/issues/316)
- fix: correct parsing of modern css colors with percentage alpha - resolves [#297](https://github.com/gka/chroma.js/issues/297)
- fix: css output for hue-less colors in lch() and oklch() - resolves [#357](https://github.com/gka/chroma.js/issues/357)
### 3.0.0
- 🎉 NEW: Add support for modern CSS color spaces. This means you can now export and parse CSS colors in `lab()`, `lch()`, `oklab()`, `oklch()` space.
- 🎉 NEW: you can now control the standard white reference point for the CIE Lab and CIE Lch color spaces via `setLabWhitePoint`.
- Breaking: `color.css()` will no longer return [legacy CSS colors](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/rgb#legacy_syntax_comma-separated_values) like `rgb(255, 255, 0)` but use modern CSS colors like `rgb(255 255 0)` instead.
- fix: you can now use chroma.js both via the default export as well as named exports in ES6.
- fix: switch to W3C implementation of OKLab color space
### 2.6.0
- 🎉 NEW: add [`color.shade()`](#color-shade), [`color.tint()`](#color-shade).
- fix: remove false w3c color cornflower
### 2.5.0
- refactored code base to ES6 modules
### 2.4.0
- add support for Oklab and Oklch color spaces
### 2.3.0
- use binom of degree n in chroma.bezier
### 2.2.0
- use Delta e2000 for chroma.deltaE #269
### 2.0.3
- hsl2rgb will, like other x2rgb conversions now set the default alpha to 1
### 2.0.2
- use a more mangle-safe check for Color class constructor to fix issues with uglifyjs and terser
### 2.0.1
- added `chroma.valid()` for checking if a color can be parsed by chroma.js
### 2.0.0
- chroma.js has been ported from CoffeeScript to ES6! This means you can now import parts of chroma in your projects!
- changed HCG input space from [0..360,0..100,0..100] to [0..360,0..1,0..1] (to be in line with HSL)
- added new object unpacking (e.g. `hsl2rgb({h,s,l})`)
- changed default interpolation to `lrgb` in mix/interpolate and average.
- if colors can't be parsed correctly, chroma will now throw Errors instead of silently failing with console.errors
### 1.4.1
- chroma.scale() now interprets `null` as NaN and returns the fallback color. Before it had interpreted `null` as `0`
- added `scale.nodata()` to allow customizing the previously hard-coded fallback (aka "no data") color #cccccc
### 1.4.0
- color.hex() now automatically sets the mode to 'rgba' if the colors alpha channel is < 1. so `chroma('rgba(255,0,0,.5)').hex()` will now return `"#ff000080"` instead of `"#ff0000"`. if this is not what you want, you must explicitly set the mode to `rgb` using `.hex("rgb")`.
- bugfix in chroma.average in LRGB mode ([#187](https://github.com/gka/chroma.js/issues/187))
- chroma.scale now also works with just one color ([#180](https://github.com/gka/chroma.js/issues/180))
### 1.3.5
- added LRGB interpolation
### 1.3.4
- passing _null_ as mode in scale.colors will return chroma objects
### 1.3.3
- added [color.clipped](https://gka.github.io/chroma.js/#color-clipped)
- added [chroma.distance](https://gka.github.io/chroma.js/#chroma-distance)
- added [chroma.deltaE](https://gka.github.io/chroma.js/#chroma-deltae)
- [color.set](https://gka.github.io/chroma.js/#color-set) now returns a new chroma instance
- chroma.scale now allows [disabling of internal cache](https://gka.github.io/chroma.js/#scale-cache)
- [chroma.average](https://gka.github.io/chroma.js/#chroma-average) now works with any color mode
- added unit tests for color conversions
- use hex colors as default string representation
- RGB channels are now stored as floats internally for higher precision
- bugfix with cubehelix and constant lightness
- bugfix in chroma.limits quantiles
- bugfix when running scale.colors(1)
- bugfix in hsi2rgb color conversion
### 1.2.2
- scale.colors() now returns the original colors instead of just min/max range
### 1.2.0
- added chroma.average for averaging colors
### 1.1.0
- refactored chroma.scale
- changed behaviour of scale.domain
- added scale.classes
- added scale.padding
### 1.0.2
- standardized alpha channel construction
- chroma.bezier automatically returns chroma.scale
### 1.0.1
- added simple color output to chroma.scale().colors()
### 1.0.0
- numeric interpolation does what it should
- refactored and modularized code base
- changed argument order of Color::interpolate
================================================
FILE: LICENSE
================================================
chroma.js - JavaScript library for color conversions
Copyright (c) 2011-2025, Gregor Aisch
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The name Gregor Aisch may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL GREGOR AISCH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-------------------------------------------------------
chroma.js includes colors from colorbrewer2.org, which are released under
the following license:
Copyright (c) 2002 Cynthia Brewer, Mark Harrower,
and The Pennsylvania State University.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
either express or implied. See the License for the specific
language governing permissions and limitations under the License.
------------------------------------------------------
Named colors are taken from X11 Color Names.
http://www.w3.org/TR/css3-color/#svg-color
@preserve
================================================
FILE: dist/chroma-light.cjs
================================================
/**
* chroma.js - JavaScript library for color conversions
*
* Copyright (c) 2011-2025, Gregor Aisch
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The name Gregor Aisch may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL GREGOR AISCH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* -------------------------------------------------------
*
* chroma.js includes colors from colorbrewer2.org, which are released under
* the following license:
*
* Copyright (c) 2002 Cynthia Brewer, Mark Harrower,
* and The Pennsylvania State University.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
* ------------------------------------------------------
*
* Named colors are taken from X11 Color Names.
* http://www.w3.org/TR/css3-color/#svg-color
*
* @preserve
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.chroma = factory());
})(this, (function () { 'use strict';
var min$1 = Math.min;
var max$1 = Math.max;
function limit (x, low, high) {
if ( high === void 0 ) high = 1;
return min$1(max$1(low, x), high);
}
function clip_rgb (rgb) {
rgb._clipped = false;
rgb._unclipped = rgb.slice(0);
for (var i = 0; i <= 3; i++) {
if (i < 3) {
if (rgb[i] < 0 || rgb[i] > 255) { rgb._clipped = true; }
rgb[i] = limit(rgb[i], 0, 255);
} else if (i === 3) {
rgb[i] = limit(rgb[i], 0, 1);
}
}
return rgb;
}
// ported from jQuery's $.type
var classToType = {};
for (var i = 0, list = [
'Boolean',
'Number',
'String',
'Function',
'Array',
'Date',
'RegExp',
'Undefined',
'Null'
]; i < list.length; i += 1) {
var name = list[i];
classToType[("[object " + name + "]")] = name.toLowerCase();
}
function type (obj) {
return classToType[Object.prototype.toString.call(obj)] || 'object';
}
function unpack (args, keyOrder) {
if ( keyOrder === void 0 ) keyOrder = null;
// if called with more than 3 arguments, we return the arguments
if (args.length >= 3) { return Array.prototype.slice.call(args); }
// with less than 3 args we check if first arg is object
// and use the keyOrder string to extract and sort properties
if (type(args[0]) == 'object' && keyOrder) {
return keyOrder
.split('')
.filter(function (k) { return args[0][k] !== undefined; })
.map(function (k) { return args[0][k]; });
}
// otherwise we just return the first argument
// (which we suppose is an array of args)
return args[0].slice(0);
}
function last (args) {
if (args.length < 2) { return null; }
var l = args.length - 1;
if (type(args[l]) == 'string') { return args[l].toLowerCase(); }
return null;
}
var PI = Math.PI;
var min = Math.min;
var max = Math.max;
var rnd2 = function (a) { return Math.round(a * 100) / 100; };
var rnd3 = function (a) { return Math.round(a * 100) / 100; };
var DEG2RAD = PI / 180;
var RAD2DEG = 180 / PI;
var input = {
format: {},
autodetect: []
};
var Color = function Color() {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var me = this;
if (
type(args[0]) === 'object' &&
args[0].constructor &&
args[0].constructor === this.constructor
) {
// the argument is already a Color instance
return args[0];
}
// last argument could be the mode
var mode = last(args);
var autodetect = false;
if (!mode) {
autodetect = true;
if (!input.sorted) {
input.autodetect = input.autodetect.sort(function (a, b) { return b.p - a.p; });
input.sorted = true;
}
// auto-detect format
for (var i = 0, list = input.autodetect; i < list.length; i += 1) {
var chk = list[i];
mode = chk.test.apply(chk, args);
if (mode) { break; }
}
}
if (input.format[mode]) {
var rgb = input.format[mode].apply(
null,
autodetect ? args : args.slice(0, -1)
);
me._rgb = clip_rgb(rgb);
} else {
throw new Error('unknown format: ' + args);
}
// add alpha channel
if (me._rgb.length === 3) { me._rgb.push(1); }
};
Color.prototype.toString = function toString () {
if (type(this.hex) == 'function') { return this.hex(); }
return ("[" + (this._rgb.join(',')) + "]");
};
// this gets updated automatically
var version = '3.2.0';
var chroma = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
return new (Function.prototype.bind.apply( Color, [ null ].concat( args) ));
};
chroma.version = version;
/*
* supported arguments:
* - hsl2css(h,s,l)
* - hsl2css(h,s,l,a)
* - hsl2css([h,s,l], mode)
* - hsl2css([h,s,l,a], mode)
* - hsl2css({h,s,l,a}, mode)
*/
var hsl2css = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var hsla = unpack(args, 'hsla');
var mode = last(args) || 'lsa';
hsla[0] = rnd2(hsla[0] || 0) + 'deg';
hsla[1] = rnd2(hsla[1] * 100) + '%';
hsla[2] = rnd2(hsla[2] * 100) + '%';
if (mode === 'hsla' || (hsla.length > 3 && hsla[3] < 1)) {
hsla[3] = '/ ' + (hsla.length > 3 ? hsla[3] : 1);
mode = 'hsla';
} else {
hsla.length = 3;
}
return ((mode.substr(0, 3)) + "(" + (hsla.join(' ')) + ")");
};
/*
* supported arguments:
* - rgb2hsl(r,g,b)
* - rgb2hsl(r,g,b,a)
* - rgb2hsl([r,g,b])
* - rgb2hsl([r,g,b,a])
* - rgb2hsl({r,g,b,a})
*/
var rgb2hsl = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
args = unpack(args, 'rgba');
var r = args[0];
var g = args[1];
var b = args[2];
r /= 255;
g /= 255;
b /= 255;
var minRgb = min(r, g, b);
var maxRgb = max(r, g, b);
var l = (maxRgb + minRgb) / 2;
var s, h;
if (maxRgb === minRgb) {
s = 0;
h = Number.NaN;
} else {
s =
l < 0.5
? (maxRgb - minRgb) / (maxRgb + minRgb)
: (maxRgb - minRgb) / (2 - maxRgb - minRgb);
}
if (r == maxRgb) { h = (g - b) / (maxRgb - minRgb); }
else if (g == maxRgb) { h = 2 + (b - r) / (maxRgb - minRgb); }
else if (b == maxRgb) { h = 4 + (r - g) / (maxRgb - minRgb); }
h *= 60;
if (h < 0) { h += 360; }
if (args.length > 3 && args[3] !== undefined) { return [h, s, l, args[3]]; }
return [h, s, l];
};
/*
* supported arguments:
* - lab2css(l,a,b)
* - lab2css(l,a,b,alpha)
* - lab2css([l,a,b], mode)
* - lab2css([l,a,b,alpha], mode)
*/
var lab2css = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var laba = unpack(args, 'lab');
var mode = last(args) || 'lab';
laba[0] = rnd2(laba[0]) + '%';
laba[1] = rnd2(laba[1]);
laba[2] = rnd2(laba[2]);
if (mode === 'laba' || (laba.length > 3 && laba[3] < 1)) {
laba[3] = '/ ' + (laba.length > 3 ? laba[3] : 1);
} else {
laba.length = 3;
}
return ("lab(" + (laba.join(' ')) + ")");
};
var labConstants = {
// Corresponds roughly to RGB brighter/darker
Kn: 18,
// D65 standard referent
labWhitePoint: 'd65',
Xn: 0.95047,
Yn: 1,
Zn: 1.08883,
kE: 216.0 / 24389.0,
kKE: 8.0,
kK: 24389.0 / 27.0,
RefWhiteRGB: {
// sRGB
X: 0.95047,
Y: 1,
Z: 1.08883
},
MtxRGB2XYZ: {
m00: 0.4124564390896922,
m01: 0.21267285140562253,
m02: 0.0193338955823293,
m10: 0.357576077643909,
m11: 0.715152155287818,
m12: 0.11919202588130297,
m20: 0.18043748326639894,
m21: 0.07217499330655958,
m22: 0.9503040785363679
},
MtxXYZ2RGB: {
m00: 3.2404541621141045,
m01: -0.9692660305051868,
m02: 0.055643430959114726,
m10: -1.5371385127977166,
m11: 1.8760108454466942,
m12: -0.2040259135167538,
m20: -0.498531409556016,
m21: 0.041556017530349834,
m22: 1.0572251882231791
},
// used in rgb2xyz
As: 0.9414285350000001,
Bs: 1.040417467,
Cs: 1.089532651,
MtxAdaptMa: {
m00: 0.8951,
m01: -0.7502,
m02: 0.0389,
m10: 0.2664,
m11: 1.7135,
m12: -0.0685,
m20: -0.1614,
m21: 0.0367,
m22: 1.0296
},
MtxAdaptMaI: {
m00: 0.9869929054667123,
m01: 0.43230526972339456,
m02: -0.008528664575177328,
m10: -0.14705425642099013,
m11: 0.5183602715367776,
m12: 0.04004282165408487,
m20: 0.15996265166373125,
m21: 0.0492912282128556,
m22: 0.9684866957875502
}
};
// taken from https://de.mathworks.com/help/images/ref/whitepoint.html
var ILLUMINANTS = new Map([
// ASTM E308-01
['a', [1.0985, 0.35585]],
// Wyszecki & Stiles, p. 769
['b', [1.0985, 0.35585]],
// C ASTM E308-01
['c', [0.98074, 1.18232]],
// D50 (ASTM E308-01)
['d50', [0.96422, 0.82521]],
// D55 (ASTM E308-01)
['d55', [0.95682, 0.92149]],
// D65 (ASTM E308-01)
['d65', [0.95047, 1.08883]],
// E (ASTM E308-01)
['e', [1, 1, 1]],
// F2 (ASTM E308-01)
['f2', [0.99186, 0.67393]],
// F7 (ASTM E308-01)
['f7', [0.95041, 1.08747]],
// F11 (ASTM E308-01)
['f11', [1.00962, 0.6435]],
['icc', [0.96422, 0.82521]]
]);
function setLabWhitePoint(name) {
var ill = ILLUMINANTS.get(String(name).toLowerCase());
if (!ill) {
throw new Error('unknown Lab illuminant ' + name);
}
labConstants.labWhitePoint = name;
labConstants.Xn = ill[0];
labConstants.Zn = ill[1];
}
function getLabWhitePoint() {
return labConstants.labWhitePoint;
}
var rgb2lab = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var ref = unpack(args, 'rgb');
var r = ref[0];
var g = ref[1];
var b = ref[2];
var rest = ref.slice(3);
var ref$1 = rgb2xyz(r, g, b);
var x = ref$1[0];
var y = ref$1[1];
var z = ref$1[2];
var ref$2 = xyz2lab(x, y, z);
var L = ref$2[0];
var a = ref$2[1];
var b_ = ref$2[2];
return [L, a, b_ ].concat( (rest.length > 0 && rest[0] < 1 ? [rest[0]] : []));
};
function xyz2lab(x, y, z) {
var Xn = labConstants.Xn;
var Yn = labConstants.Yn;
var Zn = labConstants.Zn;
var kE = labConstants.kE;
var kK = labConstants.kK;
var xr = x / Xn;
var yr = y / Yn;
var zr = z / Zn;
var fx = xr > kE ? Math.pow(xr, 1.0 / 3.0) : (kK * xr + 16.0) / 116.0;
var fy = yr > kE ? Math.pow(yr, 1.0 / 3.0) : (kK * yr + 16.0) / 116.0;
var fz = zr > kE ? Math.pow(zr, 1.0 / 3.0) : (kK * zr + 16.0) / 116.0;
return [116.0 * fy - 16.0, 500.0 * (fx - fy), 200.0 * (fy - fz)];
}
function gammaAdjustSRGB(companded) {
var sign = Math.sign(companded);
companded = Math.abs(companded);
var linear =
companded <= 0.04045
? companded / 12.92
: Math.pow((companded + 0.055) / 1.055, 2.4);
return linear * sign;
}
var rgb2xyz = function (r, g, b) {
// normalize and gamma adjust
r = gammaAdjustSRGB(r / 255);
g = gammaAdjustSRGB(g / 255);
b = gammaAdjustSRGB(b / 255);
var MtxRGB2XYZ = labConstants.MtxRGB2XYZ;
var MtxAdaptMa = labConstants.MtxAdaptMa;
var MtxAdaptMaI = labConstants.MtxAdaptMaI;
var Xn = labConstants.Xn;
var Yn = labConstants.Yn;
var Zn = labConstants.Zn;
var As = labConstants.As;
var Bs = labConstants.Bs;
var Cs = labConstants.Cs;
var x = r * MtxRGB2XYZ.m00 + g * MtxRGB2XYZ.m10 + b * MtxRGB2XYZ.m20;
var y = r * MtxRGB2XYZ.m01 + g * MtxRGB2XYZ.m11 + b * MtxRGB2XYZ.m21;
var z = r * MtxRGB2XYZ.m02 + g * MtxRGB2XYZ.m12 + b * MtxRGB2XYZ.m22;
var Ad = Xn * MtxAdaptMa.m00 + Yn * MtxAdaptMa.m10 + Zn * MtxAdaptMa.m20;
var Bd = Xn * MtxAdaptMa.m01 + Yn * MtxAdaptMa.m11 + Zn * MtxAdaptMa.m21;
var Cd = Xn * MtxAdaptMa.m02 + Yn * MtxAdaptMa.m12 + Zn * MtxAdaptMa.m22;
var X = x * MtxAdaptMa.m00 + y * MtxAdaptMa.m10 + z * MtxAdaptMa.m20;
var Y = x * MtxAdaptMa.m01 + y * MtxAdaptMa.m11 + z * MtxAdaptMa.m21;
var Z = x * MtxAdaptMa.m02 + y * MtxAdaptMa.m12 + z * MtxAdaptMa.m22;
X *= Ad / As;
Y *= Bd / Bs;
Z *= Cd / Cs;
x = X * MtxAdaptMaI.m00 + Y * MtxAdaptMaI.m10 + Z * MtxAdaptMaI.m20;
y = X * MtxAdaptMaI.m01 + Y * MtxAdaptMaI.m11 + Z * MtxAdaptMaI.m21;
z = X * MtxAdaptMaI.m02 + Y * MtxAdaptMaI.m12 + Z * MtxAdaptMaI.m22;
return [x, y, z];
};
/*
* supported arguments:
* - lab2css(l,a,b)
* - lab2css(l,a,b,alpha)
* - lab2css([l,a,b], mode)
* - lab2css([l,a,b,alpha], mode)
*/
var lch2css = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var lcha = unpack(args, 'lch');
var mode = last(args) || 'lab';
lcha[0] = rnd2(lcha[0]) + '%';
lcha[1] = rnd2(lcha[1]);
lcha[2] = isNaN(lcha[2]) ? 'none' : rnd2(lcha[2]) + 'deg'; // add deg unit to hue
if (mode === 'lcha' || (lcha.length > 3 && lcha[3] < 1)) {
lcha[3] = '/ ' + (lcha.length > 3 ? lcha[3] : 1);
} else {
lcha.length = 3;
}
return ("lch(" + (lcha.join(' ')) + ")");
};
var sqrt$1 = Math.sqrt;
var atan2 = Math.atan2;
var round$4 = Math.round;
var lab2lch = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var ref = unpack(args, 'lab');
var l = ref[0];
var a = ref[1];
var b = ref[2];
var c = sqrt$1(a * a + b * b);
var h = (atan2(b, a) * RAD2DEG + 360) % 360;
if (round$4(c * 10000) === 0) { h = Number.NaN; }
return [l, c, h];
};
var rgb2lch = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var ref = unpack(args, 'rgb');
var r = ref[0];
var g = ref[1];
var b = ref[2];
var rest = ref.slice(3);
var ref$1 = rgb2lab(r, g, b);
var l = ref$1[0];
var a = ref$1[1];
var b_ = ref$1[2];
var ref$2 = lab2lch(l, a, b_);
var L = ref$2[0];
var c = ref$2[1];
var h = ref$2[2];
return [L, c, h ].concat( (rest.length > 0 && rest[0] < 1 ? [rest[0]] : []));
};
// from https://www.w3.org/TR/css-color-4/multiply-matrices.js
function multiplyMatrices(A, B) {
var m = A.length;
if (!Array.isArray(A[0])) {
// A is vector, convert to [[a, b, c, ...]]
A = [A];
}
if (!Array.isArray(B[0])) {
// B is vector, convert to [[a], [b], [c], ...]]
B = B.map(function (x) { return [x]; });
}
var p = B[0].length;
var B_cols = B[0].map(function (_, i) { return B.map(function (x) { return x[i]; }); }); // transpose B
var product = A.map(function (row) { return B_cols.map(function (col) {
if (!Array.isArray(row)) {
return col.reduce(function (a, c) { return a + c * row; }, 0);
}
return row.reduce(function (a, c, i) { return a + c * (col[i] || 0); }, 0);
}); }
);
if (m === 1) {
product = product[0]; // Avoid [[a, b, c, ...]]
}
if (p === 1) {
return product.map(function (x) { return x[0]; }); // Avoid [[a], [b], [c], ...]]
}
return product;
}
var rgb2oklab = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var ref = unpack(args, 'rgb');
var r = ref[0];
var g = ref[1];
var b = ref[2];
var rest = ref.slice(3);
var xyz = rgb2xyz(r, g, b);
var oklab = XYZ_to_OKLab(xyz);
return oklab.concat( (rest.length > 0 && rest[0] < 1 ? [rest[0]] : []));
};
// from https://www.w3.org/TR/css-color-4/#color-conversion-code
function XYZ_to_OKLab(XYZ) {
// Given XYZ relative to D65, convert to OKLab
var XYZtoLMS = [
[0.819022437996703, 0.3619062600528904, -0.1288737815209879],
[0.0329836539323885, 0.9292868615863434, 0.0361446663506424],
[0.0481771893596242, 0.2642395317527308, 0.6335478284694309]
];
var LMStoOKLab = [
[0.210454268309314, 0.7936177747023054, -0.0040720430116193],
[1.9779985324311684, -2.42859224204858, 0.450593709617411],
[0.0259040424655478, 0.7827717124575296, -0.8086757549230774]
];
var LMS = multiplyMatrices(XYZtoLMS, XYZ);
// JavaScript Math.cbrt returns a sign-matched cube root
// beware if porting to other languages
// especially if tempted to use a general power function
return multiplyMatrices(
LMStoOKLab,
LMS.map(function (c) { return Math.cbrt(c); })
);
// L in range [0,1]. For use in CSS, multiply by 100 and add a percent
}
var oklab2css = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var laba = unpack(args, 'lab');
laba[0] = rnd2(laba[0] * 100) + '%';
laba[1] = rnd3(laba[1]);
laba[2] = rnd3(laba[2]);
if (laba.length > 3 && laba[3] < 1) {
laba[3] = '/ ' + (laba.length > 3 ? laba[3] : 1);
} else {
laba.length = 3;
}
return ("oklab(" + (laba.join(' ')) + ")");
};
var rgb2oklch = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var ref = unpack(args, 'rgb');
var r = ref[0];
var g = ref[1];
var b = ref[2];
var rest = ref.slice(3);
var ref$1 = rgb2oklab(r, g, b);
var l = ref$1[0];
var a = ref$1[1];
var b_ = ref$1[2];
var ref$2 = lab2lch(l, a, b_);
var L = ref$2[0];
var c = ref$2[1];
var h = ref$2[2];
return [L, c, h ].concat( (rest.length > 0 && rest[0] < 1 ? [rest[0]] : []));
};
var oklch2css = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var lcha = unpack(args, 'lch');
lcha[0] = rnd2(lcha[0] * 100) + '%';
lcha[1] = rnd3(lcha[1]);
lcha[2] = isNaN(lcha[2]) ? 'none' : rnd2(lcha[2]) + 'deg'; // add deg unit to hue
if (lcha.length > 3 && lcha[3] < 1) {
lcha[3] = '/ ' + (lcha.length > 3 ? lcha[3] : 1);
} else {
lcha.length = 3;
}
return ("oklch(" + (lcha.join(' ')) + ")");
};
var round$3 = Math.round;
/*
* supported arguments:
* - rgb2css(r,g,b)
* - rgb2css(r,g,b,a)
* - rgb2css([r,g,b], mode)
* - rgb2css([r,g,b,a], mode)
* - rgb2css({r,g,b,a}, mode)
*/
var rgb2css = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var rgba = unpack(args, 'rgba');
var mode = last(args) || 'rgb';
if (mode.substr(0, 3) === 'hsl') {
return hsl2css(rgb2hsl(rgba), mode);
}
if (mode.substr(0, 3) === 'lab') {
// change to D50 lab whitepoint since this is what W3C is using for CSS Lab colors
var prevWhitePoint = getLabWhitePoint();
setLabWhitePoint('d50');
var cssColor = lab2css(rgb2lab(rgba), mode);
setLabWhitePoint(prevWhitePoint);
return cssColor;
}
if (mode.substr(0, 3) === 'lch') {
// change to D50 lab whitepoint since this is what W3C is using for CSS Lab colors
var prevWhitePoint$1 = getLabWhitePoint();
setLabWhitePoint('d50');
var cssColor$1 = lch2css(rgb2lch(rgba), mode);
setLabWhitePoint(prevWhitePoint$1);
return cssColor$1;
}
if (mode.substr(0, 5) === 'oklab') {
return oklab2css(rgb2oklab(rgba));
}
if (mode.substr(0, 5) === 'oklch') {
return oklch2css(rgb2oklch(rgba));
}
rgba[0] = round$3(rgba[0]);
rgba[1] = round$3(rgba[1]);
rgba[2] = round$3(rgba[2]);
if (mode === 'rgba' || (rgba.length > 3 && rgba[3] < 1)) {
rgba[3] = '/ ' + (rgba.length > 3 ? rgba[3] : 1);
mode = 'rgba';
}
return ((mode.substr(0, 3)) + "(" + (rgba.slice(0, mode === 'rgb' ? 3 : 4).join(' ')) + ")");
};
var hsl2rgb = function () {
var assign;
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
args = unpack(args, 'hsl');
var h = args[0];
var s = args[1];
var l = args[2];
var r, g, b;
if (s === 0) {
r = g = b = l * 255;
} else {
var t3 = [0, 0, 0];
var c = [0, 0, 0];
var t2 = l < 0.5 ? l * (1 + s) : l + s - l * s;
var t1 = 2 * l - t2;
var h_ = h / 360;
t3[0] = h_ + 1 / 3;
t3[1] = h_;
t3[2] = h_ - 1 / 3;
for (var i = 0; i < 3; i++) {
if (t3[i] < 0) { t3[i] += 1; }
if (t3[i] > 1) { t3[i] -= 1; }
if (6 * t3[i] < 1) { c[i] = t1 + (t2 - t1) * 6 * t3[i]; }
else if (2 * t3[i] < 1) { c[i] = t2; }
else if (3 * t3[i] < 2) { c[i] = t1 + (t2 - t1) * (2 / 3 - t3[i]) * 6; }
else { c[i] = t1; }
}
(assign = [c[0] * 255, c[1] * 255, c[2] * 255], r = assign[0], g = assign[1], b = assign[2]);
}
if (args.length > 3) {
// keep alpha channel
return [r, g, b, args[3]];
}
return [r, g, b, 1];
};
/*
* L* [0..100]
* a [-100..100]
* b [-100..100]
*/
var lab2rgb = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
args = unpack(args, 'lab');
var L = args[0];
var a = args[1];
var b = args[2];
var ref = lab2xyz(L, a, b);
var x = ref[0];
var y = ref[1];
var z = ref[2];
var ref$1 = xyz2rgb(x, y, z);
var r = ref$1[0];
var g = ref$1[1];
var b_ = ref$1[2];
return [r, g, b_, args.length > 3 ? args[3] : 1];
};
var lab2xyz = function (L, a, b) {
var kE = labConstants.kE;
var kK = labConstants.kK;
var kKE = labConstants.kKE;
var Xn = labConstants.Xn;
var Yn = labConstants.Yn;
var Zn = labConstants.Zn;
var fy = (L + 16.0) / 116.0;
var fx = 0.002 * a + fy;
var fz = fy - 0.005 * b;
var fx3 = fx * fx * fx;
var fz3 = fz * fz * fz;
var xr = fx3 > kE ? fx3 : (116.0 * fx - 16.0) / kK;
var yr = L > kKE ? Math.pow((L + 16.0) / 116.0, 3.0) : L / kK;
var zr = fz3 > kE ? fz3 : (116.0 * fz - 16.0) / kK;
var x = xr * Xn;
var y = yr * Yn;
var z = zr * Zn;
return [x, y, z];
};
var compand = function (linear) {
/* sRGB */
var sign = Math.sign(linear);
linear = Math.abs(linear);
return (
(linear <= 0.0031308
? linear * 12.92
: 1.055 * Math.pow(linear, 1.0 / 2.4) - 0.055) * sign
);
};
var xyz2rgb = function (x, y, z) {
var MtxAdaptMa = labConstants.MtxAdaptMa;
var MtxAdaptMaI = labConstants.MtxAdaptMaI;
var MtxXYZ2RGB = labConstants.MtxXYZ2RGB;
var RefWhiteRGB = labConstants.RefWhiteRGB;
var Xn = labConstants.Xn;
var Yn = labConstants.Yn;
var Zn = labConstants.Zn;
var As = Xn * MtxAdaptMa.m00 + Yn * MtxAdaptMa.m10 + Zn * MtxAdaptMa.m20;
var Bs = Xn * MtxAdaptMa.m01 + Yn * MtxAdaptMa.m11 + Zn * MtxAdaptMa.m21;
var Cs = Xn * MtxAdaptMa.m02 + Yn * MtxAdaptMa.m12 + Zn * MtxAdaptMa.m22;
var Ad =
RefWhiteRGB.X * MtxAdaptMa.m00 +
RefWhiteRGB.Y * MtxAdaptMa.m10 +
RefWhiteRGB.Z * MtxAdaptMa.m20;
var Bd =
RefWhiteRGB.X * MtxAdaptMa.m01 +
RefWhiteRGB.Y * MtxAdaptMa.m11 +
RefWhiteRGB.Z * MtxAdaptMa.m21;
var Cd =
RefWhiteRGB.X * MtxAdaptMa.m02 +
RefWhiteRGB.Y * MtxAdaptMa.m12 +
RefWhiteRGB.Z * MtxAdaptMa.m22;
var X1 =
(x * MtxAdaptMa.m00 + y * MtxAdaptMa.m10 + z * MtxAdaptMa.m20) *
(Ad / As);
var Y1 =
(x * MtxAdaptMa.m01 + y * MtxAdaptMa.m11 + z * MtxAdaptMa.m21) *
(Bd / Bs);
var Z1 =
(x * MtxAdaptMa.m02 + y * MtxAdaptMa.m12 + z * MtxAdaptMa.m22) *
(Cd / Cs);
var X2 =
X1 * MtxAdaptMaI.m00 + Y1 * MtxAdaptMaI.m10 + Z1 * MtxAdaptMaI.m20;
var Y2 =
X1 * MtxAdaptMaI.m01 + Y1 * MtxAdaptMaI.m11 + Z1 * MtxAdaptMaI.m21;
var Z2 =
X1 * MtxAdaptMaI.m02 + Y1 * MtxAdaptMaI.m12 + Z1 * MtxAdaptMaI.m22;
var r = compand(
X2 * MtxXYZ2RGB.m00 + Y2 * MtxXYZ2RGB.m10 + Z2 * MtxXYZ2RGB.m20
);
var g = compand(
X2 * MtxXYZ2RGB.m01 + Y2 * MtxXYZ2RGB.m11 + Z2 * MtxXYZ2RGB.m21
);
var b = compand(
X2 * MtxXYZ2RGB.m02 + Y2 * MtxXYZ2RGB.m12 + Z2 * MtxXYZ2RGB.m22
);
return [r * 255, g * 255, b * 255];
};
var sin = Math.sin;
var cos = Math.cos;
var lch2lab = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
/*
Convert from a qualitative parameter h and a quantitative parameter l to a 24-bit pixel.
These formulas were invented by David Dalrymple to obtain maximum contrast without going
out of gamut if the parameters are in the range 0-1.
A saturation multiplier was added by Gregor Aisch
*/
var ref = unpack(args, 'lch');
var l = ref[0];
var c = ref[1];
var h = ref[2];
if (isNaN(h)) { h = 0; }
h = h * DEG2RAD;
return [l, cos(h) * c, sin(h) * c];
};
var lch2rgb = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
args = unpack(args, 'lch');
var l = args[0];
var c = args[1];
var h = args[2];
var ref = lch2lab(l, c, h);
var L = ref[0];
var a = ref[1];
var b_ = ref[2];
var ref$1 = lab2rgb(L, a, b_);
var r = ref$1[0];
var g = ref$1[1];
var b = ref$1[2];
return [r, g, b, args.length > 3 ? args[3] : 1];
};
var oklab2rgb = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
args = unpack(args, 'lab');
var L = args[0];
var a = args[1];
var b = args[2];
var rest = args.slice(3);
var ref = OKLab_to_XYZ([L, a, b]);
var X = ref[0];
var Y = ref[1];
var Z = ref[2];
var ref$1 = xyz2rgb(X, Y, Z);
var r = ref$1[0];
var g = ref$1[1];
var b_ = ref$1[2];
return [r, g, b_ ].concat( (rest.length > 0 && rest[0] < 1 ? [rest[0]] : []));
};
// from https://www.w3.org/TR/css-color-4/#color-conversion-code
function OKLab_to_XYZ(OKLab) {
// Given OKLab, convert to XYZ relative to D65
var LMStoXYZ = [
[1.2268798758459243, -0.5578149944602171, 0.2813910456659647],
[-0.0405757452148008, 1.112286803280317, -0.0717110580655164],
[-0.0763729366746601, -0.4214933324022432, 1.5869240198367816]
];
var OKLabtoLMS = [
[1.0, 0.3963377773761749, 0.2158037573099136],
[1.0, -0.1055613458156586, -0.0638541728258133],
[1.0, -0.0894841775298119, -1.2914855480194092]
];
var LMSnl = multiplyMatrices(OKLabtoLMS, OKLab);
return multiplyMatrices(
LMStoXYZ,
LMSnl.map(function (c) { return Math.pow( c, 3 ); })
);
}
var oklch2rgb = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
args = unpack(args, 'lch');
var l = args[0];
var c = args[1];
var h = args[2];
var rest = args.slice(3);
var ref = lch2lab(l, c, h);
var L = ref[0];
var a = ref[1];
var b_ = ref[2];
var ref$1 = oklab2rgb(L, a, b_);
var r = ref$1[0];
var g = ref$1[1];
var b = ref$1[2];
return [r, g, b ].concat( (rest.length > 0 && rest[0] < 1 ? [rest[0]] : []));
};
var INT_OR_PCT = /((?:-?\d+)|(?:-?\d+(?:\.\d+)?)%|none)/.source;
var FLOAT_OR_PCT = /((?:-?(?:\d+(?:\.\d*)?|\.\d+)%?)|none)/.source;
var PCT = /((?:-?(?:\d+(?:\.\d*)?|\.\d+)%)|none)/.source;
var RE_S = /\s*/.source;
var SEP = /\s+/.source;
var COMMA = /\s*,\s*/.source;
var ANLGE = /((?:-?(?:\d+(?:\.\d*)?|\.\d+)(?:deg)?)|none)/.source;
var ALPHA = /\s*(?:\/\s*((?:[01]|[01]?\.\d+)|\d+(?:\.\d+)?%))?/.source;
// e.g. rgb(250 20 0), rgb(100% 50% 20%), rgb(100% 50% 20% / 0.5)
var RE_RGB = new RegExp(
'^rgba?\\(' +
RE_S +
[INT_OR_PCT, INT_OR_PCT, INT_OR_PCT].join(SEP) +
ALPHA +
'\\)$'
);
var RE_RGB_LEGACY = new RegExp(
'^rgb\\(' +
RE_S +
[INT_OR_PCT, INT_OR_PCT, INT_OR_PCT].join(COMMA) +
RE_S +
'\\)$'
);
var RE_RGBA_LEGACY = new RegExp(
'^rgba\\(' +
RE_S +
[INT_OR_PCT, INT_OR_PCT, INT_OR_PCT, FLOAT_OR_PCT].join(COMMA) +
RE_S +
'\\)$'
);
var RE_HSL = new RegExp(
'^hsla?\\(' + RE_S + [ANLGE, PCT, PCT].join(SEP) + ALPHA + '\\)$'
);
var RE_HSL_LEGACY = new RegExp(
'^hsl?\\(' + RE_S + [ANLGE, PCT, PCT].join(COMMA) + RE_S + '\\)$'
);
var RE_HSLA_LEGACY =
/^hsla\(\s*(-?\d+(?:\.\d+)?),\s*(-?\d+(?:\.\d+)?)%\s*,\s*(-?\d+(?:\.\d+)?)%\s*,\s*([01]|[01]?\.\d+)\)$/;
var RE_LAB = new RegExp(
'^lab\\(' +
RE_S +
[FLOAT_OR_PCT, FLOAT_OR_PCT, FLOAT_OR_PCT].join(SEP) +
ALPHA +
'\\)$'
);
var RE_LCH = new RegExp(
'^lch\\(' +
RE_S +
[FLOAT_OR_PCT, FLOAT_OR_PCT, ANLGE].join(SEP) +
ALPHA +
'\\)$'
);
var RE_OKLAB = new RegExp(
'^oklab\\(' +
RE_S +
[FLOAT_OR_PCT, FLOAT_OR_PCT, FLOAT_OR_PCT].join(SEP) +
ALPHA +
'\\)$'
);
var RE_OKLCH = new RegExp(
'^oklch\\(' +
RE_S +
[FLOAT_OR_PCT, FLOAT_OR_PCT, ANLGE].join(SEP) +
ALPHA +
'\\)$'
);
var round$2 = Math.round;
var roundRGB = function (rgb) {
return rgb.map(function (v, i) { return (i <= 2 ? limit(round$2(v), 0, 255) : v); });
};
var percentToAbsolute = function (pct, min, max, signed) {
if ( min === void 0 ) min = 0;
if ( max === void 0 ) max = 100;
if ( signed === void 0 ) signed = false;
if (typeof pct === 'string' && pct.endsWith('%')) {
pct = parseFloat(pct.substring(0, pct.length - 1)) / 100;
if (signed) {
// signed percentages are in the range -100% to 100%
pct = min + (pct + 1) * 0.5 * (max - min);
} else {
pct = min + pct * (max - min);
}
}
return +pct;
};
var noneToValue = function (v, noneValue) {
return v === 'none' ? noneValue : v;
};
var css2rgb = function (css) {
css = css.toLowerCase().trim();
if (css === 'transparent') {
return [0, 0, 0, 0];
}
var m;
if (input.format.named) {
try {
return input.format.named(css);
// eslint-disable-next-line
} catch (e) {}
}
// rgb(250 20 0) or rgb(250,20,0)
if ((m = css.match(RE_RGB)) || (m = css.match(RE_RGB_LEGACY))) {
var rgb = m.slice(1, 4);
for (var i = 0; i < 3; i++) {
rgb[i] = +percentToAbsolute(noneToValue(rgb[i], 0), 0, 255);
}
rgb = roundRGB(rgb);
var alpha = m[4] !== undefined ? +percentToAbsolute(m[4], 0, 1) : 1;
rgb[3] = alpha; // default alpha
return rgb;
}
// rgba(250,20,0,0.4)
if ((m = css.match(RE_RGBA_LEGACY))) {
var rgb$1 = m.slice(1, 5);
for (var i$1 = 0; i$1 < 4; i$1++) {
rgb$1[i$1] = +percentToAbsolute(rgb$1[i$1], 0, 255);
}
return rgb$1;
}
// hsl(0,100%,50%)
if ((m = css.match(RE_HSL)) || (m = css.match(RE_HSL_LEGACY))) {
var hsl = m.slice(1, 4);
hsl[0] = +noneToValue(hsl[0].replace('deg', ''), 0);
hsl[1] = +percentToAbsolute(noneToValue(hsl[1], 0), 0, 100) * 0.01;
hsl[2] = +percentToAbsolute(noneToValue(hsl[2], 0), 0, 100) * 0.01;
var rgb$2 = roundRGB(hsl2rgb(hsl));
var alpha$1 = m[4] !== undefined ? +percentToAbsolute(m[4], 0, 1) : 1;
rgb$2[3] = alpha$1;
return rgb$2;
}
// hsla(0,100%,50%,0.5)
if ((m = css.match(RE_HSLA_LEGACY))) {
var hsl$1 = m.slice(1, 4);
hsl$1[1] *= 0.01;
hsl$1[2] *= 0.01;
var rgb$3 = hsl2rgb(hsl$1);
for (var i$2 = 0; i$2 < 3; i$2++) {
rgb$3[i$2] = round$2(rgb$3[i$2]);
}
rgb$3[3] = +m[4]; // default alpha = 1
return rgb$3;
}
if ((m = css.match(RE_LAB))) {
var lab = m.slice(1, 4);
lab[0] = percentToAbsolute(noneToValue(lab[0], 0), 0, 100);
lab[1] = percentToAbsolute(noneToValue(lab[1], 0), -125, 125, true);
lab[2] = percentToAbsolute(noneToValue(lab[2], 0), -125, 125, true);
// convert to D50 Lab whitepoint
var wp = getLabWhitePoint();
setLabWhitePoint('d50');
var rgb$4 = roundRGB(lab2rgb(lab));
// convert back to original Lab whitepoint
setLabWhitePoint(wp);
var alpha$2 = m[4] !== undefined ? +percentToAbsolute(m[4], 0, 1) : 1;
rgb$4[3] = alpha$2;
return rgb$4;
}
if ((m = css.match(RE_LCH))) {
var lch = m.slice(1, 4);
lch[0] = percentToAbsolute(lch[0], 0, 100);
lch[1] = percentToAbsolute(noneToValue(lch[1], 0), 0, 150, false);
lch[2] = +noneToValue(lch[2].replace('deg', ''), 0);
// convert to D50 Lab whitepoint
var wp$1 = getLabWhitePoint();
setLabWhitePoint('d50');
var rgb$5 = roundRGB(lch2rgb(lch));
// convert back to original Lab whitepoint
setLabWhitePoint(wp$1);
var alpha$3 = m[4] !== undefined ? +percentToAbsolute(m[4], 0, 1) : 1;
rgb$5[3] = alpha$3;
return rgb$5;
}
if ((m = css.match(RE_OKLAB))) {
var oklab = m.slice(1, 4);
oklab[0] = percentToAbsolute(noneToValue(oklab[0], 0), 0, 1);
oklab[1] = percentToAbsolute(noneToValue(oklab[1], 0), -0.4, 0.4, true);
oklab[2] = percentToAbsolute(noneToValue(oklab[2], 0), -0.4, 0.4, true);
var rgb$6 = roundRGB(oklab2rgb(oklab));
var alpha$4 = m[4] !== undefined ? +percentToAbsolute(m[4], 0, 1) : 1;
rgb$6[3] = alpha$4;
return rgb$6;
}
if ((m = css.match(RE_OKLCH))) {
var oklch = m.slice(1, 4);
oklch[0] = percentToAbsolute(noneToValue(oklch[0], 0), 0, 1);
oklch[1] = percentToAbsolute(noneToValue(oklch[1], 0), 0, 0.4, false);
oklch[2] = +noneToValue(oklch[2].replace('deg', ''), 0);
var rgb$7 = roundRGB(oklch2rgb(oklch));
var alpha$5 = m[4] !== undefined ? +percentToAbsolute(m[4], 0, 1) : 1;
rgb$7[3] = alpha$5;
return rgb$7;
}
};
css2rgb.test = function (s) {
return (
// modern
RE_RGB.test(s) ||
RE_HSL.test(s) ||
RE_LAB.test(s) ||
RE_LCH.test(s) ||
RE_OKLAB.test(s) ||
RE_OKLCH.test(s) ||
// legacy
RE_RGB_LEGACY.test(s) ||
RE_RGBA_LEGACY.test(s) ||
RE_HSL_LEGACY.test(s) ||
RE_HSLA_LEGACY.test(s) ||
s === 'transparent'
);
};
Color.prototype.css = function (mode) {
return rgb2css(this._rgb, mode);
};
var css = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
return new (Function.prototype.bind.apply( Color, [ null ].concat( args, ['css']) ));
};
chroma.css = css;
input.format.css = css2rgb;
input.autodetect.push({
p: 5,
test: function (h) {
var rest = [], len = arguments.length - 1;
while ( len-- > 0 ) rest[ len ] = arguments[ len + 1 ];
if (!rest.length && type(h) === 'string' && css2rgb.test(h)) {
return 'css';
}
}
});
var RE_HEX = /^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;
var RE_HEXA = /^#?([A-Fa-f0-9]{8}|[A-Fa-f0-9]{4})$/;
var hex2rgb = function (hex) {
if (hex.match(RE_HEX)) {
// remove optional leading #
if (hex.length === 4 || hex.length === 7) {
hex = hex.substr(1);
}
// expand short-notation to full six-digit
if (hex.length === 3) {
hex = hex.split('');
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
}
var u = parseInt(hex, 16);
var r = u >> 16;
var g = (u >> 8) & 0xff;
var b = u & 0xff;
return [r, g, b, 1];
}
// match rgba hex format, eg #FF000077
if (hex.match(RE_HEXA)) {
if (hex.length === 5 || hex.length === 9) {
// remove optional leading #
hex = hex.substr(1);
}
// expand short-notation to full eight-digit
if (hex.length === 4) {
hex = hex.split('');
hex =
hex[0] +
hex[0] +
hex[1] +
hex[1] +
hex[2] +
hex[2] +
hex[3] +
hex[3];
}
var u$1 = parseInt(hex, 16);
var r$1 = (u$1 >> 24) & 0xff;
var g$1 = (u$1 >> 16) & 0xff;
var b$1 = (u$1 >> 8) & 0xff;
var a = Math.round(((u$1 & 0xff) / 0xff) * 100) / 100;
return [r$1, g$1, b$1, a];
}
// we used to check for css colors here
// if _input.css? and rgb = _input.css hex
// return rgb
throw new Error(("unknown hex color: " + hex));
};
var round$1 = Math.round;
var rgb2hex = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var ref = unpack(args, 'rgba');
var r = ref[0];
var g = ref[1];
var b = ref[2];
var a = ref[3];
var mode = last(args) || 'auto';
if (a === undefined) { a = 1; }
if (mode === 'auto') {
mode = a < 1 ? 'rgba' : 'rgb';
}
r = round$1(r);
g = round$1(g);
b = round$1(b);
var u = (r << 16) | (g << 8) | b;
var str = '000000' + u.toString(16); //#.toUpperCase();
str = str.substr(str.length - 6);
var hxa = '0' + round$1(a * 255).toString(16);
hxa = hxa.substr(hxa.length - 2);
switch (mode.toLowerCase()) {
case 'rgba':
return ("#" + str + hxa);
case 'argb':
return ("#" + hxa + str);
default:
return ("#" + str);
}
};
Color.prototype.hex = function (mode) {
return rgb2hex(this._rgb, mode);
};
var hex = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
return new (Function.prototype.bind.apply( Color, [ null ].concat( args, ['hex']) ));
};
chroma.hex = hex;
input.format.hex = hex2rgb;
input.autodetect.push({
p: 4,
test: function (h) {
var rest = [], len = arguments.length - 1;
while ( len-- > 0 ) rest[ len ] = arguments[ len + 1 ];
if (
!rest.length &&
type(h) === 'string' &&
[3, 4, 5, 6, 7, 8, 9].indexOf(h.length) >= 0
) {
return 'hex';
}
}
});
Color.prototype.hsl = function () {
return rgb2hsl(this._rgb);
};
var hsl = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
return new (Function.prototype.bind.apply( Color, [ null ].concat( args, ['hsl']) ));
};
chroma.hsl = hsl;
input.format.hsl = hsl2rgb;
input.autodetect.push({
p: 2,
test: function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
args = unpack(args, 'hsl');
if (type(args) === 'array' && args.length === 3) {
return 'hsl';
}
}
});
Color.prototype.lab = function () {
return rgb2lab(this._rgb);
};
var lab = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
return new (Function.prototype.bind.apply( Color, [ null ].concat( args, ['lab']) ));
};
Object.assign(chroma, { lab: lab, getLabWhitePoint: getLabWhitePoint, setLabWhitePoint: setLabWhitePoint });
input.format.lab = lab2rgb;
input.autodetect.push({
p: 2,
test: function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
args = unpack(args, 'lab');
if (type(args) === 'array' && args.length === 3) {
return 'lab';
}
}
});
Color.prototype.oklab = function () {
return rgb2oklab(this._rgb);
};
var oklab$1 = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
return new (Function.prototype.bind.apply( Color, [ null ].concat( args, ['oklab']) ));
};
Object.assign(chroma, { oklab: oklab$1 });
input.format.oklab = oklab2rgb;
input.autodetect.push({
p: 2,
test: function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
args = unpack(args, 'oklab');
if (type(args) === 'array' && args.length === 3) {
return 'oklab';
}
}
});
var round = Math.round;
Color.prototype.rgb = function (rnd) {
if ( rnd === void 0 ) rnd = true;
if (rnd === false) { return this._rgb.slice(0, 3); }
return this._rgb.slice(0, 3).map(round);
};
Color.prototype.rgba = function (rnd) {
if ( rnd === void 0 ) rnd = true;
return this._rgb.slice(0, 4).map(function (v, i) {
return i < 3 ? (rnd === false ? v : round(v)) : v;
});
};
var rgb = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
return new (Function.prototype.bind.apply( Color, [ null ].concat( args, ['rgb']) ));
};
Object.assign(chroma, { rgb: rgb });
input.format.rgb = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var rgba = unpack(args, 'rgba');
if (rgba[3] === undefined) { rgba[3] = 1; }
return rgba;
};
input.autodetect.push({
p: 3,
test: function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
args = unpack(args, 'rgba');
if (
type(args) === 'array' &&
(args.length === 3 ||
(args.length === 4 &&
type(args[3]) == 'number' &&
args[3] >= 0 &&
args[3] <= 1))
) {
return 'rgb';
}
}
});
Color.prototype.alpha = function (a, mutate) {
if ( mutate === void 0 ) mutate = false;
if (a !== undefined && type(a) === 'number') {
if (mutate) {
this._rgb[3] = a;
return this;
}
return new Color([this._rgb[0], this._rgb[1], this._rgb[2], a], 'rgb');
}
return this._rgb[3];
};
Color.prototype.darken = function (amount) {
if ( amount === void 0 ) amount = 1;
var me = this;
var lab = me.lab();
lab[0] -= labConstants.Kn * amount;
return new Color(lab, 'lab').alpha(me.alpha(), true);
};
Color.prototype.brighten = function (amount) {
if ( amount === void 0 ) amount = 1;
return this.darken(-amount);
};
Color.prototype.darker = Color.prototype.darken;
Color.prototype.brighter = Color.prototype.brighten;
Color.prototype.get = function (mc) {
var ref = mc.split('.');
var mode = ref[0];
var channel = ref[1];
var src = this[mode]();
if (channel) {
var i = mode.indexOf(channel) - (mode.substr(0, 2) === 'ok' ? 2 : 0);
if (i > -1) { return src[i]; }
throw new Error(("unknown channel " + channel + " in mode " + mode));
} else {
return src;
}
};
var index = {};
function mix (col1, col2, f) {
if ( f === void 0 ) f = 0.5;
var rest = [], len = arguments.length - 3;
while ( len-- > 0 ) rest[ len ] = arguments[ len + 3 ];
var mode = rest[0] || 'lrgb';
if (!index[mode] && !rest.length) {
// fall back to the first supported mode
mode = Object.keys(index)[0];
}
if (!index[mode]) {
throw new Error(("interpolation mode " + mode + " is not defined"));
}
if (type(col1) !== 'object') { col1 = new Color(col1); }
if (type(col2) !== 'object') { col2 = new Color(col2); }
return index[mode](col1, col2, f).alpha(
col1.alpha() + f * (col2.alpha() - col1.alpha())
);
}
Color.prototype.mix = Color.prototype.interpolate = function (
col2,
f
) {
if ( f === void 0 ) f = 0.5;
var rest = [], len = arguments.length - 2;
while ( len-- > 0 ) rest[ len ] = arguments[ len + 2 ];
return mix.apply(void 0, [ this, col2, f ].concat( rest ));
};
Color.prototype.set = function (mc, value, mutate) {
if ( mutate === void 0 ) mutate = false;
var ref = mc.split('.');
var mode = ref[0];
var channel = ref[1];
var src = this[mode]();
if (channel) {
var i = mode.indexOf(channel) - (mode.substr(0, 2) === 'ok' ? 2 : 0);
if (i > -1) {
if (type(value) == 'string') {
switch (value.charAt(0)) {
case '+':
src[i] += +value;
break;
case '-':
src[i] += +value;
break;
case '*':
src[i] *= +value.substr(1);
break;
case '/':
src[i] /= +value.substr(1);
break;
default:
src[i] = +value;
}
} else if (type(value) === 'number') {
src[i] = value;
} else {
throw new Error("unsupported value for Color.set");
}
var out = new Color(src, mode);
if (mutate) {
this._rgb = out._rgb;
return this;
}
return out;
}
throw new Error(("unknown channel " + channel + " in mode " + mode));
} else {
return src;
}
};
Color.prototype.tint = function (f) {
if ( f === void 0 ) f = 0.5;
var rest = [], len = arguments.length - 1;
while ( len-- > 0 ) rest[ len ] = arguments[ len + 1 ];
return mix.apply(void 0, [ this, 'white', f ].concat( rest ));
};
Color.prototype.shade = function (f) {
if ( f === void 0 ) f = 0.5;
var rest = [], len = arguments.length - 1;
while ( len-- > 0 ) rest[ len ] = arguments[ len + 1 ];
return mix.apply(void 0, [ this, 'black', f ].concat( rest ));
};
var sqrt = Math.sqrt;
var pow = Math.pow;
var lrgb = function (col1, col2, f) {
var ref = col1._rgb;
var x1 = ref[0];
var y1 = ref[1];
var z1 = ref[2];
var ref$1 = col2._rgb;
var x2 = ref$1[0];
var y2 = ref$1[1];
var z2 = ref$1[2];
return new Color(
sqrt(pow(x1, 2) * (1 - f) + pow(x2, 2) * f),
sqrt(pow(y1, 2) * (1 - f) + pow(y2, 2) * f),
sqrt(pow(z1, 2) * (1 - f) + pow(z2, 2) * f),
'rgb'
);
};
// register interpolator
index.lrgb = lrgb;
var oklab = function (col1, col2, f) {
var xyz0 = col1.oklab();
var xyz1 = col2.oklab();
return new Color(
xyz0[0] + f * (xyz1[0] - xyz0[0]),
xyz0[1] + f * (xyz1[1] - xyz0[1]),
xyz0[2] + f * (xyz1[2] - xyz0[2]),
'oklab'
);
};
// register interpolator
index.oklab = oklab;
function valid () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
try {
new (Function.prototype.bind.apply( Color, [ null ].concat( args) ));
return true;
// eslint-disable-next-line
} catch (e) {
return false;
}
}
Object.assign(chroma, {
Color: Color,
valid: valid,
css: css,
hex: hex,
hsl: hsl,
lab: lab,
oklab: oklab$1,
rgb: rgb,
mix: mix,
interpolate: mix
});
return chroma;
}));
================================================
FILE: dist/chroma-light.min.cjs
================================================
/**
* chroma.js - JavaScript library for color conversions
*
* Copyright (c) 2011-2025, Gregor Aisch
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The name Gregor Aisch may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL GREGOR AISCH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* -------------------------------------------------------
*
* chroma.js includes colors from colorbrewer2.org, which are released under
* the following license:
*
* Copyright (c) 2002 Cynthia Brewer, Mark Harrower,
* and The Pennsylvania State University.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
* ------------------------------------------------------
*
* Named colors are taken from X11 Color Names.
* http://www.w3.org/TR/css3-color/#svg-color
*
* @preserve
*/
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(t="undefined"!=typeof globalThis?globalThis:t||self).chroma=r()}(this,(function(){"use strict";var t=Math.min,r=Math.max;function n(n,e,o){return void 0===o&&(o=1),t(r(e,n),o)}for(var e={},o=0,a=["Boolean","Number","String","Function","Array","Date","RegExp","Undefined","Null"];o<a.length;o+=1){var i=a[o];e["[object "+i+"]"]=i.toLowerCase()}function u(t){return e[Object.prototype.toString.call(t)]||"object"}function l(t,r){return void 0===r&&(r=null),t.length>=3?Array.prototype.slice.call(t):"object"==u(t[0])&&r?r.split("").filter((function(r){return void 0!==t[0][r]})).map((function(r){return t[0][r]})):t[0].slice(0)}function c(t){if(t.length<2)return null;var r=t.length-1;return"string"==u(t[r])?t[r].toLowerCase():null}var h=Math.PI,s=Math.min,f=Math.max,g=function(t){return Math.round(100*t)/100},p=function(t){return Math.round(100*t)/100},m=h/180,v=180/h,b={format:{},autodetect:[]},d=function(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];var e=this;if("object"===u(t[0])&&t[0].constructor&&t[0].constructor===this.constructor)return t[0];var o=c(t),a=!1;if(!o){a=!0,b.sorted||(b.autodetect=b.autodetect.sort((function(t,r){return r.p-t.p})),b.sorted=!0);for(var i=0,l=b.autodetect;i<l.length;i+=1){var h=l[i];if(o=h.test.apply(h,t))break}}if(!b.format[o])throw new Error("unknown format: "+t);var s=b.format[o].apply(null,a?t:t.slice(0,-1));e._rgb=function(t){t._clipped=!1,t._unclipped=t.slice(0);for(var r=0;r<=3;r++)r<3?((t[r]<0||t[r]>255)&&(t._clipped=!0),t[r]=n(t[r],0,255)):3===r&&(t[r]=n(t[r],0,1));return t}(s),3===e._rgb.length&&e._rgb.push(1)};d.prototype.toString=function(){return"function"==u(this.hex)?this.hex():"["+this._rgb.join(",")+"]"};var y=function(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];return new(Function.prototype.bind.apply(d,[null].concat(t)))};y.version="3.2.0";var w=function(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];var n,e,o=(t=l(t,"rgba"))[0],a=t[1],i=t[2],u=s(o/=255,a/=255,i/=255),c=f(o,a,i),h=(c+u)/2;return c===u?(n=0,e=Number.NaN):n=h<.5?(c-u)/(c+u):(c-u)/(2-c-u),o==c?e=(a-i)/(c-u):a==c?e=2+(i-o)/(c-u):i==c&&(e=4+(o-a)/(c-u)),(e*=60)<0&&(e+=360),t.length>3&&void 0!==t[3]?[e,n,h,t[3]]:[e,n,h]},M={Kn:18,labWhitePoint:"d65",Xn:.95047,Yn:1,Zn:1.08883,kE:216/24389,kKE:8,kK:24389/27,RefWhiteRGB:{X:.95047,Y:1,Z:1.08883},MtxRGB2XYZ:{m00:.4124564390896922,m01:.21267285140562253,m02:.0193338955823293,m10:.357576077643909,m11:.715152155287818,m12:.11919202588130297,m20:.18043748326639894,m21:.07217499330655958,m22:.9503040785363679},MtxXYZ2RGB:{m00:3.2404541621141045,m01:-.9692660305051868,m02:.055643430959114726,m10:-1.5371385127977166,m11:1.8760108454466942,m12:-.2040259135167538,m20:-.498531409556016,m21:.041556017530349834,m22:1.0572251882231791},As:.9414285350000001,Bs:1.040417467,Cs:1.089532651,MtxAdaptMa:{m00:.8951,m01:-.7502,m02:.0389,m10:.2664,m11:1.7135,m12:-.0685,m20:-.1614,m21:.0367,m22:1.0296},MtxAdaptMaI:{m00:.9869929054667123,m01:.43230526972339456,m02:-.008528664575177328,m10:-.14705425642099013,m11:.5183602715367776,m12:.04004282165408487,m20:.15996265166373125,m21:.0492912282128556,m22:.9684866957875502}},k=new Map([["a",[1.0985,.35585]],["b",[1.0985,.35585]],["c",[.98074,1.18232]],["d50",[.96422,.82521]],["d55",[.95682,.92149]],["d65",[.95047,1.08883]],["e",[1,1,1]],["f2",[.99186,.67393]],["f7",[.95041,1.08747]],["f11",[1.00962,.6435]],["icc",[.96422,.82521]]]);function x(t){var r=k.get(String(t).toLowerCase());if(!r)throw new Error("unknown Lab illuminant "+t);M.labWhitePoint=t,M.Xn=r[0],M.Zn=r[1]}function j(){return M.labWhitePoint}var _=function(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];var n=l(t,"rgb"),e=n[0],o=n[1],a=n[2],i=n.slice(3),u=A(e,o,a),c=function(t,r,n){var e=M.Xn,o=M.Yn,a=M.Zn,i=M.kE,u=M.kK,l=t/e,c=r/o,h=n/a,s=l>i?Math.pow(l,1/3):(u*l+16)/116,f=c>i?Math.pow(c,1/3):(u*c+16)/116,g=h>i?Math.pow(h,1/3):(u*h+16)/116;return[116*f-16,500*(s-f),200*(f-g)]}(u[0],u[1],u[2]);return[c[0],c[1],c[2]].concat(i.length>0&&i[0]<1?[i[0]]:[])};function E(t){var r=Math.sign(t);return((t=Math.abs(t))<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4))*r}var A=function(t,r,n){t=E(t/255),r=E(r/255),n=E(n/255);var e=M.MtxRGB2XYZ,o=M.MtxAdaptMa,a=M.MtxAdaptMaI,i=M.Xn,u=M.Yn,l=M.Zn,c=M.As,h=M.Bs,s=M.Cs,f=t*e.m00+r*e.m10+n*e.m20,g=t*e.m01+r*e.m11+n*e.m21,p=t*e.m02+r*e.m12+n*e.m22,m=i*o.m00+u*o.m10+l*o.m20,v=i*o.m01+u*o.m11+l*o.m21,b=i*o.m02+u*o.m12+l*o.m22,d=f*o.m00+g*o.m10+p*o.m20,y=f*o.m01+g*o.m11+p*o.m21,w=f*o.m02+g*o.m12+p*o.m22;return y*=v/h,w*=b/s,[f=(d*=m/c)*a.m00+y*a.m10+w*a.m20,g=d*a.m01+y*a.m11+w*a.m21,p=d*a.m02+y*a.m12+w*a.m22]},R=Math.sqrt,F=Math.atan2,N=Math.round,X=function(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];var n=l(t,"lab"),e=n[0],o=n[1],a=n[2],i=R(o*o+a*a),u=(F(a,o)*v+360)%360;return 0===N(1e4*i)&&(u=Number.NaN),[e,i,u]};function Z(t,r){var n=t.length;Array.isArray(t[0])||(t=[t]),Array.isArray(r[0])||(r=r.map((function(t){return[t]})));var e=r[0].length,o=r[0].map((function(t,n){return r.map((function(t){return t[n]}))})),a=t.map((function(t){return o.map((function(r){return Array.isArray(t)?t.reduce((function(t,n,e){return t+n*(r[e]||0)}),0):r.reduce((function(r,n){return r+n*t}),0)}))}));return 1===n&&(a=a[0]),1===e?a.map((function(t){return t[0]})):a}var Y=function(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];var n,e,o=l(t,"rgb"),a=o[0],i=o[1],u=o[2],c=o.slice(3),h=A(a,i,u);return(n=[[.210454268309314,.7936177747023054,-.0040720430116193],[1.9779985324311684,-2.42859224204858,.450593709617411],[.0259040424655478,.7827717124575296,-.8086757549230774]],e=Z([[.819022437996703,.3619062600528904,-.1288737815209879],[.0329836539323885,.9292868615863434,.0361446663506424],[.0481771893596242,.2642395317527308,.6335478284694309]],h),Z(n,e.map((function(t){return Math.cbrt(t)})))).concat(c.length>0&&c[0]<1?[c[0]]:[])};var $=Math.round,B=function(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];var n=l(t,"rgba"),e=c(t)||"rgb";if("hsl"===e.substr(0,3))return function(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];var n=l(t,"hsla"),e=c(t)||"lsa";return n[0]=g(n[0]||0)+"deg",n[1]=g(100*n[1])+"%",n[2]=g(100*n[2])+"%","hsla"===e||n.length>3&&n[3]<1?(n[3]="/ "+(n.length>3?n[3]:1),e="hsla"):n.length=3,e.substr(0,3)+"("+n.join(" ")+")"}(w(n),e);if("lab"===e.substr(0,3)){var o=j();x("d50");var a=function(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];var n=l(t,"lab"),e=c(t)||"lab";return n[0]=g(n[0])+"%",n[1]=g(n[1]),n[2]=g(n[2]),"laba"===e||n.length>3&&n[3]<1?n[3]="/ "+(n.length>3?n[3]:1):n.length=3,"lab("+n.join(" ")+")"}(_(n),e);return x(o),a}if("lch"===e.substr(0,3)){var i=j();x("d50");var u=function(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];var n=l(t,"lch"),e=c(t)||"lab";return n[0]=g(n[0])+"%",n[1]=g(n[1]),n[2]=isNaN(n[2])?"none":g(n[2])+"deg","lcha"===e||n.length>3&&n[3]<1?n[3]="/ "+(n.length>3?n[3]:1):n.length=3,"lch("+n.join(" ")+")"}(function(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];var n=l(t,"rgb"),e=n[0],o=n[1],a=n[2],i=n.slice(3),u=_(e,o,a),c=u[0],h=u[1],s=u[2],f=X(c,h,s);return[f[0],f[1],f[2]].concat(i.length>0&&i[0]<1?[i[0]]:[])}(n),e);return x(i),u}return"oklab"===e.substr(0,5)?function(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];var n=l(t,"lab");return n[0]=g(100*n[0])+"%",n[1]=p(n[1]),n[2]=p(n[2]),n.length>3&&n[3]<1?n[3]="/ "+(n.length>3?n[3]:1):n.length=3,"oklab("+n.join(" ")+")"}(Y(n)):"oklch"===e.substr(0,5)?function(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];var n=l(t,"lch");return n[0]=g(100*n[0])+"%",n[1]=p(n[1]),n[2]=isNaN(n[2])?"none":g(n[2])+"deg",n.length>3&&n[3]<1?n[3]="/ "+(n.length>3?n[3]:1):n.length=3,"oklch("+n.join(" ")+")"}(function(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];var n=l(t,"rgb"),e=n[0],o=n[1],a=n[2],i=n.slice(3),u=Y(e,o,a),c=u[0],h=u[1],s=u[2],f=X(c,h,s);return[f[0],f[1],f[2]].concat(i.length>0&&i[0]<1?[i[0]]:[])}(n)):(n[0]=$(n[0]),n[1]=$(n[1]),n[2]=$(n[2]),("rgba"===e||n.length>3&&n[3]<1)&&(n[3]="/ "+(n.length>3?n[3]:1),e="rgba"),e.substr(0,3)+"("+n.slice(0,"rgb"===e?3:4).join(" ")+")")},C=function(){for(var t,r=[],n=arguments.length;n--;)r[n]=arguments[n];var e,o,a,i=(r=l(r,"hsl"))[0],u=r[1],c=r[2];if(0===u)e=o=a=255*c;else{var h=[0,0,0],s=[0,0,0],f=c<.5?c*(1+u):c+u-c*u,g=2*c-f,p=i/360;h[0]=p+1/3,h[1]=p,h[2]=p-1/3;for(var m=0;m<3;m++)h[m]<0&&(h[m]+=1),h[m]>1&&(h[m]-=1),6*h[m]<1?s[m]=g+6*(f-g)*h[m]:2*h[m]<1?s[m]=f:3*h[m]<2?s[m]=g+(f-g)*(2/3-h[m])*6:s[m]=g;e=(t=[255*s[0],255*s[1],255*s[2]])[0],o=t[1],a=t[2]}return r.length>3?[e,o,a,r[3]]:[e,o,a,1]},O=function(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];var n=(t=l(t,"lab"))[0],e=t[1],o=t[2],a=L(n,e,o),i=a[0],u=a[1],c=a[2],h=K(i,u,c);return[h[0],h[1],h[2],t.length>3?t[3]:1]},L=function(t,r,n){var e=M.kE,o=M.kK,a=M.kKE,i=M.Xn,u=M.Yn,l=M.Zn,c=(t+16)/116,h=.002*r+c,s=c-.005*n,f=h*h*h,g=s*s*s;return[(f>e?f:(116*h-16)/o)*i,(t>a?Math.pow((t+16)/116,3):t/o)*u,(g>e?g:(116*s-16)/o)*l]},W=function(t){var r=Math.sign(t);return((t=Math.abs(t))<=.0031308?12.92*t:1.055*Math.pow(t,1/2.4)-.055)*r},K=function(t,r,n){var e=M.MtxAdaptMa,o=M.MtxAdaptMaI,a=M.MtxXYZ2RGB,i=M.RefWhiteRGB,u=M.Xn,l=M.Yn,c=M.Zn,h=u*e.m00+l*e.m10+c*e.m20,s=u*e.m01+l*e.m11+c*e.m21,f=u*e.m02+l*e.m12+c*e.m22,g=i.X*e.m00+i.Y*e.m10+i.Z*e.m20,p=i.X*e.m01+i.Y*e.m11+i.Z*e.m21,m=i.X*e.m02+i.Y*e.m12+i.Z*e.m22,v=(t*e.m00+r*e.m10+n*e.m20)*(g/h),b=(t*e.m01+r*e.m11+n*e.m21)*(p/s),d=(t*e.m02+r*e.m12+n*e.m22)*(m/f),y=v*o.m00+b*o.m10+d*o.m20,w=v*o.m01+b*o.m11+d*o.m21,k=v*o.m02+b*o.m12+d*o.m22;return[255*W(y*a.m00+w*a.m10+k*a.m20),255*W(y*a.m01+w*a.m11+k*a.m21),255*W(y*a.m02+w*a.m12+k*a.m22)]},G=Math.sin,I=Math.cos,P=function(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];var n=l(t,"lch"),e=n[0],o=n[1],a=n[2];return isNaN(a)&&(a=0),[e,I(a*=m)*o,G(a)*o]},S=function(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];var n,e,o=(t=l(t,"lab"))[0],a=t[1],i=t[2],u=t.slice(3),c=(n=[[1.2268798758459243,-.5578149944602171,.2813910456659647],[-.0405757452148008,1.112286803280317,-.0717110580655164],[-.0763729366746601,-.4214933324022432,1.5869240198367816]],e=Z([[1,.3963377773761749,.2158037573099136],[1,-.1055613458156586,-.0638541728258133],[1,-.0894841775298119,-1.2914855480194092]],[o,a,i]),Z(n,e.map((function(t){return Math.pow(t,3)})))),h=c[0],s=c[1],f=c[2],g=K(h,s,f);return[g[0],g[1],g[2]].concat(u.length>0&&u[0]<1?[u[0]]:[])};var q=/((?:-?\d+)|(?:-?\d+(?:\.\d+)?)%|none)/.source,T=/((?:-?(?:\d+(?:\.\d*)?|\.\d+)%?)|none)/.source,D=/((?:-?(?:\d+(?:\.\d*)?|\.\d+)%)|none)/.source,U=/\s*/.source,z=/\s+/.source,H=/\s*,\s*/.source,J=/((?:-?(?:\d+(?:\.\d*)?|\.\d+)(?:deg)?)|none)/.source,Q=/\s*(?:\/\s*((?:[01]|[01]?\.\d+)|\d+(?:\.\d+)?%))?/.source,V=new RegExp("^rgba?\\("+U+[q,q,q].join(z)+Q+"\\)$"),tt=new RegExp("^rgb\\("+U+[q,q,q].join(H)+U+"\\)$"),rt=new RegExp("^rgba\\("+U+[q,q,q,T].join(H)+U+"\\)$"),nt=new RegExp("^hsla?\\("+U+[J,D,D].join(z)+Q+"\\)$"),et=new RegExp("^hsl?\\("+U+[J,D,D].join(H)+U+"\\)$"),ot=/^hsla\(\s*(-?\d+(?:\.\d+)?),\s*(-?\d+(?:\.\d+)?)%\s*,\s*(-?\d+(?:\.\d+)?)%\s*,\s*([01]|[01]?\.\d+)\)$/,at=new RegExp("^lab\\("+U+[T,T,T].join(z)+Q+"\\)$"),it=new RegExp("^lch\\("+U+[T,T,J].join(z)+Q+"\\)$"),ut=new RegExp("^oklab\\("+U+[T,T,T].join(z)+Q+"\\)$"),lt=new RegExp("^oklch\\("+U+[T,T,J].join(z)+Q+"\\)$"),ct=Math.round,ht=function(t){return t.map((function(t,r){return r<=2?n(ct(t),0,255):t}))},st=function(t,r,n,e){return void 0===r&&(r=0),void 0===n&&(n=100),void 0===e&&(e=!1),"string"==typeof t&&t.endsWith("%")&&(t=parseFloat(t.substring(0,t.length-1))/100,t=e?r+.5*(t+1)*(n-r):r+t*(n-r)),+t},ft=function(t,r){return"none"===t?r:t},gt=function(t){if("transparent"===(t=t.toLowerCase().trim()))return[0,0,0,0];var r;if(b.format.named)try{return b.format.named(t)}catch(t){}if((r=t.match(V))||(r=t.match(tt))){for(var n=r.slice(1,4),e=0;e<3;e++)n[e]=+st(ft(n[e],0),0,255);n=ht(n);var o=void 0!==r[4]?+st(r[4],0,1):1;return n[3]=o,n}if(r=t.match(rt)){for(var a=r.slice(1,5),i=0;i<4;i++)a[i]=+st(a[i],0,255);return a}if((r=t.match(nt))||(r=t.match(et))){var u=r.slice(1,4);u[0]=+ft(u[0].replace("deg",""),0),u[1]=.01*+st(ft(u[1],0),0,100),u[2]=.01*+st(ft(u[2],0),0,100);var c=ht(C(u)),h=void 0!==r[4]?+st(r[4],0,1):1;return c[3]=h,c}if(r=t.match(ot)){var s=r.slice(1,4);s[1]*=.01,s[2]*=.01;for(var f=C(s),g=0;g<3;g++)f[g]=ct(f[g]);return f[3]=+r[4],f}if(r=t.match(at)){var p=r.slice(1,4);p[0]=st(ft(p[0],0),0,100),p[1]=st(ft(p[1],0),-125,125,!0),p[2]=st(ft(p[2],0),-125,125,!0);var m=j();x("d50");var v=ht(O(p));x(m);var d=void 0!==r[4]?+st(r[4],0,1):1;return v[3]=d,v}if(r=t.match(it)){var y=r.slice(1,4);y[0]=st(y[0],0,100),y[1]=st(ft(y[1],0),0,150,!1),y[2]=+ft(y[2].replace("deg",""),0);var w=j();x("d50");var M=ht(function(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];var n=(t=l(t,"lch"))[0],e=t[1],o=t[2],a=P(n,e,o),i=a[0],u=a[1],c=a[2],h=O(i,u,c);return[h[0],h[1],h[2],t.length>3?t[3]:1]}(y));x(w);var k=void 0!==r[4]?+st(r[4],0,1):1;return M[3]=k,M}if(r=t.match(ut)){var _=r.slice(1,4);_[0]=st(ft(_[0],0),0,1),_[1]=st(ft(_[1],0),-.4,.4,!0),_[2]=st(ft(_[2],0),-.4,.4,!0);var E=ht(S(_)),A=void 0!==r[4]?+st(r[4],0,1):1;return E[3]=A,E}if(r=t.match(lt)){var R=r.slice(1,4);R[0]=st(ft(R[0],0),0,1),R[1]=st(ft(R[1],0),0,.4,!1),R[2]=+ft(R[2].replace("deg",""),0);var F=ht(function(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];var n=(t=l(t,"lch"))[0],e=t[1],o=t[2],a=t.slice(3),i=P(n,e,o),u=i[0],c=i[1],h=i[2],s=S(u,c,h);return[s[0],s[1],s[2]].concat(a.length>0&&a[0]<1?[a[0]]:[])}(R)),N=void 0!==r[4]?+st(r[4],0,1):1;return F[3]=N,F}};gt.test=function(t){return V.test(t)||nt.test(t)||at.test(t)||it.test(t)||ut.test(t)||lt.test(t)||tt.test(t)||rt.test(t)||et.test(t)||ot.test(t)||"transparent"===t},d.prototype.css=function(t){return B(this._rgb,t)};var pt=function(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];return new(Function.prototype.bind.apply(d,[null].concat(t,["css"])))};y.css=pt,b.format.css=gt,b.autodetect.push({p:5,test:function(t){for(var r=[],n=arguments.length-1;n-- >0;)r[n]=arguments[n+1];if(!r.length&&"string"===u(t)&>.test(t))return"css"}});var mt=/^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,vt=/^#?([A-Fa-f0-9]{8}|[A-Fa-f0-9]{4})$/,bt=Math.round;d.prototype.hex=function(t){return function(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];var n=l(t,"rgba"),e=n[0],o=n[1],a=n[2],i=n[3],u=c(t)||"auto";void 0===i&&(i=1),"auto"===u&&(u=i<1?"rgba":"rgb");var h="000000"+((e=bt(e))<<16|(o=bt(o))<<8|(a=bt(a))).toString(16);h=h.substr(h.length-6);var s="0"+bt(255*i).toString(16);switch(s=s.substr(s.length-2),u.toLowerCase()){case"rgba":return"#"+h+s;case"argb":return"#"+s+h;default:return"#"+h}}(this._rgb,t)};var dt=function(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];return new(Function.prototype.bind.apply(d,[null].concat(t,["hex"])))};y.hex=dt,b.format.hex=function(t){if(t.match(mt)){4!==t.length&&7!==t.length||(t=t.substr(1)),3===t.length&&(t=(t=t.split(""))[0]+t[0]+t[1]+t[1]+t[2]+t[2]);var r=parseInt(t,16);return[r>>16,r>>8&255,255&r,1]}if(t.match(vt)){5!==t.length&&9!==t.length||(t=t.substr(1)),4===t.length&&(t=(t=t.split(""))[0]+t[0]+t[1]+t[1]+t[2]+t[2]+t[3]+t[3]);var n=parseInt(t,16);return[n>>24&255,n>>16&255,n>>8&255,Math.round((255&n)/255*100)/100]}throw new Error("unknown hex color: "+t)},b.autodetect.push({p:4,test:function(t){for(var r=[],n=arguments.length-1;n-- >0;)r[n]=arguments[n+1];if(!r.length&&"string"===u(t)&&[3,4,5,6,7,8,9].indexOf(t.length)>=0)return"hex"}}),d.prototype.hsl=function(){return w(this._rgb)};var yt=function(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];return new(Function.prototype.bind.apply(d,[null].concat(t,["hsl"])))};y.hsl=yt,b.format.hsl=C,b.autodetect.push({p:2,test:function(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];if("array"===u(t=l(t,"hsl"))&&3===t.length)return"hsl"}}),d.prototype.lab=function(){return _(this._rgb)};var wt=function(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];return new(Function.prototype.bind.apply(d,[null].concat(t,["lab"])))};Object.assign(y,{lab:wt,getLabWhitePoint:j,setLabWhitePoint:x}),b.format.lab=O,b.autodetect.push({p:2,test:function(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];if("array"===u(t=l(t,"lab"))&&3===t.length)return"lab"}}),d.prototype.oklab=function(){return Y(this._rgb)};var Mt=function(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];return new(Function.prototype.bind.apply(d,[null].concat(t,["oklab"])))};Object.assign(y,{oklab:Mt}),b.format.oklab=S,b.autodetect.push({p:2,test:function(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];if("array"===u(t=l(t,"oklab"))&&3===t.length)return"oklab"}});var kt=Math.round;d.prototype.rgb=function(t){return void 0===t&&(t=!0),!1===t?this._rgb.slice(0,3):this._rgb.slice(0,3).map(kt)},d.prototype.rgba=function(t){return void 0===t&&(t=!0),this._rgb.slice(0,4).map((function(r,n){return n<3?!1===t?r:kt(r):r}))};var xt=function(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];return new(Function.prototype.bind.apply(d,[null].concat(t,["rgb"])))};Object.assign(y,{rgb:xt}),b.format.rgb=function(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];var n=l(t,"rgba");return void 0===n[3]&&(n[3]=1),n},b.autodetect.push({p:3,test:function(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];if("array"===u(t=l(t,"rgba"))&&(3===t.length||4===t.length&&"number"==u(t[3])&&t[3]>=0&&t[3]<=1))return"rgb"}}),d.prototype.alpha=function(t,r){return void 0===r&&(r=!1),void 0!==t&&"number"===u(t)?r?(this._rgb[3]=t,this):new d([this._rgb[0],this._rgb[1],this._rgb[2],t],"rgb"):this._rgb[3]},d.prototype.darken=function(t){void 0===t&&(t=1);var r=this.lab();return r[0]-=M.Kn*t,new d(r,"lab").alpha(this.alpha(),!0)},d.prototype.brighten=function(t){return void 0===t&&(t=1),this.darken(-t)},d.prototype.darker=d.prototype.darken,d.prototype.brighter=d.prototype.brighten,d.prototype.get=function(t){var r=t.split("."),n=r[0],e=r[1],o=this[n]();if(e){var a=n.indexOf(e)-("ok"===n.substr(0,2)?2:0);if(a>-1)return o[a];throw new Error("unknown channel "+e+" in mode "+n)}return o};var jt={};function _t(t,r,n){void 0===n&&(n=.5);for(var e=[],o=arguments.length-3;o-- >0;)e[o]=arguments[o+3];var a=e[0]||"lrgb";if(jt[a]||e.length||(a=Object.keys(jt)[0]),!jt[a])throw new Error("interpolation mode "+a+" is not defined");return"object"!==u(t)&&(t=new d(t)),"object"!==u(r)&&(r=new d(r)),jt[a](t,r,n).alpha(t.alpha()+n*(r.alpha()-t.alpha()))}d.prototype.mix=d.prototype.interpolate=function(t,r){void 0===r&&(r=.5);for(var n=[],e=arguments.length-2;e-- >0;)n[e]=arguments[e+2];return _t.apply(void 0,[this,t,r].concat(n))},d.prototype.set=function(t,r,n){void 0===n&&(n=!1);var e=t.split("."),o=e[0],a=e[1],i=this[o]();if(a){var l=o.indexOf(a)-("ok"===o.substr(0,2)?2:0);if(l>-1){if("string"==u(r))switch(r.charAt(0)){case"+":case"-":i[l]+=+r;break;case"*":i[l]*=+r.substr(1);break;case"/":i[l]/=+r.substr(1);break;default:i[l]=+r}else{if("number"!==u(r))throw new Error("unsupported value for Color.set");i[l]=r}var c=new d(i,o);return n?(this._rgb=c._rgb,this):c}throw new Error("unknown channel "+a+" in mode "+o)}return i},d.prototype.tint=function(t){void 0===t&&(t=.5);for(var r=[],n=arguments.length-1;n-- >0;)r[n]=arguments[n+1];return _t.apply(void 0,[this,"white",t].concat(r))},d.prototype.shade=function(t){void 0===t&&(t=.5);for(var r=[],n=arguments.length-1;n-- >0;)r[n]=arguments[n+1];return _t.apply(void 0,[this,"black",t].concat(r))};var Et=Math.sqrt,At=Math.pow;jt.lrgb=function(t,r,n){var e=t._rgb,o=e[0],a=e[1],i=e[2],u=r._rgb,l=u[0],c=u[1],h=u[2];return new d(Et(At(o,2)*(1-n)+At(l,2)*n),Et(At(a,2)*(1-n)+At(c,2)*n),Et(At(i,2)*(1-n)+At(h,2)*n),"rgb")};return jt.oklab=function(t,r,n){var e=t.oklab(),o=r.oklab();return new d(e[0]+n*(o[0]-e[0]),e[1]+n*(o[1]-e[1]),e[2]+n*(o[2]-e[2]),"oklab")},Object.assign(y,{Color:d,valid:function(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];try{return new(Function.prototype.bind.apply(d,[null].concat(t))),!0}catch(t){return!1}},css:pt,hex:dt,hsl:yt,lab:wt,oklab:Mt,rgb:xt,mix:_t,interpolate:_t}),y}));
================================================
FILE: dist/chroma.cjs
================================================
/**
* chroma.js - JavaScript library for color conversions
*
* Copyright (c) 2011-2025, Gregor Aisch
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The name Gregor Aisch may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL GREGOR AISCH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* -------------------------------------------------------
*
* chroma.js includes colors from colorbrewer2.org, which are released under
* the following license:
*
* Copyright (c) 2002 Cynthia Brewer, Mark Harrower,
* and The Pennsylvania State University.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
* ------------------------------------------------------
*
* Named colors are taken from X11 Color Names.
* http://www.w3.org/TR/css3-color/#svg-color
*
* @preserve
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.chroma = factory());
})(this, (function () { 'use strict';
var min$4 = Math.min;
var max$4 = Math.max;
function limit (x, low, high) {
if ( low === void 0 ) low = 0;
if ( high === void 0 ) high = 1;
return min$4(max$4(low, x), high);
}
function clip_rgb (rgb) {
rgb._clipped = false;
rgb._unclipped = rgb.slice(0);
for (var i = 0; i <= 3; i++) {
if (i < 3) {
if (rgb[i] < 0 || rgb[i] > 255) { rgb._clipped = true; }
rgb[i] = limit(rgb[i], 0, 255);
} else if (i === 3) {
rgb[i] = limit(rgb[i], 0, 1);
}
}
return rgb;
}
// ported from jQuery's $.type
var classToType = {};
for (var i = 0, list = [
'Boolean',
'Number',
'String',
'Function',
'Array',
'Date',
'RegExp',
'Undefined',
'Null'
]; i < list.length; i += 1) {
var name = list[i];
classToType[("[object " + name + "]")] = name.toLowerCase();
}
function type (obj) {
return classToType[Object.prototype.toString.call(obj)] || 'object';
}
function unpack (args, keyOrder) {
if ( keyOrder === void 0 ) keyOrder = null;
// if called with more than 3 arguments, we return the arguments
if (args.length >= 3) { return Array.prototype.slice.call(args); }
// with less than 3 args we check if first arg is object
// and use the keyOrder string to extract and sort properties
if (type(args[0]) == 'object' && keyOrder) {
return keyOrder
.split('')
.filter(function (k) { return args[0][k] !== undefined; })
.map(function (k) { return args[0][k]; });
}
// otherwise we just return the first argument
// (which we suppose is an array of args)
return args[0].slice(0);
}
function last (args) {
if (args.length < 2) { return null; }
var l = args.length - 1;
if (type(args[l]) == 'string') { return args[l].toLowerCase(); }
return null;
}
var PI$2 = Math.PI;
var min$3 = Math.min;
var max$3 = Math.max;
var rnd2 = function (a) { return Math.round(a * 100) / 100; };
var rnd3 = function (a) { return Math.round(a * 100) / 100; };
var TWOPI = PI$2 * 2;
var PITHIRD = PI$2 / 3;
var DEG2RAD = PI$2 / 180;
var RAD2DEG = 180 / PI$2;
/**
* Reverse the first three elements of an array
*
* @param {any[]} arr
* @returns {any[]}
*/
function reverse3(arr) {
return arr.slice(0, 3).reverse().concat( arr.slice(3));
}
var input = {
format: {},
autodetect: []
};
var Color = function Color() {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var me = this;
if (
type(args[0]) === 'object' &&
args[0].constructor &&
args[0].constructor === this.constructor
) {
// the argument is already a Color instance
return args[0];
}
// last argument could be the mode
var mode = last(args);
var autodetect = false;
if (!mode) {
autodetect = true;
if (!input.sorted) {
input.autodetect = input.autodetect.sort(function (a, b) { return b.p - a.p; });
input.sorted = true;
}
// auto-detect format
for (var i = 0, list = input.autodetect; i < list.length; i += 1) {
var chk = list[i];
mode = chk.test.apply(chk, args);
if (mode) { break; }
}
}
if (input.format[mode]) {
var rgb = input.format[mode].apply(
null,
autodetect ? args : args.slice(0, -1)
);
me._rgb = clip_rgb(rgb);
} else {
throw new Error('unknown format: ' + args);
}
// add alpha channel
if (me._rgb.length === 3) { me._rgb.push(1); }
};
Color.prototype.toString = function toString () {
if (type(this.hex) == 'function') { return this.hex(); }
return ("[" + (this._rgb.join(',')) + "]");
};
// this gets updated automatically
var version = '3.2.0';
var chroma = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
return new (Function.prototype.bind.apply( Color, [ null ].concat( args) ));
};
chroma.version = version;
var cmyk2rgb = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
args = unpack(args, 'cmyk');
var c = args[0];
var m = args[1];
var y = args[2];
var k = args[3];
var alpha = args.length > 4 ? args[4] : 1;
if (k === 1) { return [0, 0, 0, alpha]; }
return [
c >= 1 ? 0 : 255 * (1 - c) * (1 - k), // r
m >= 1 ? 0 : 255 * (1 - m) * (1 - k), // g
y >= 1 ? 0 : 255 * (1 - y) * (1 - k), // b
alpha
];
};
var max$2 = Math.max;
var rgb2cmyk = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var ref = unpack(args, 'rgb');
var r = ref[0];
var g = ref[1];
var b = ref[2];
r = r / 255;
g = g / 255;
b = b / 255;
var k = 1 - max$2(r, max$2(g, b));
var f = k < 1 ? 1 / (1 - k) : 0;
var c = (1 - r - k) * f;
var m = (1 - g - k) * f;
var y = (1 - b - k) * f;
return [c, m, y, k];
};
Color.prototype.cmyk = function () {
return rgb2cmyk(this._rgb);
};
var cmyk = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
return new (Function.prototype.bind.apply( Color, [ null ].concat( args, ['cmyk']) ));
};
Object.assign(chroma, { cmyk: cmyk });
input.format.cmyk = cmyk2rgb;
input.autodetect.push({
p: 2,
test: function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
args = unpack(args, 'cmyk');
if (type(args) === 'array' && args.length === 4) {
return 'cmyk';
}
}
});
/*
* supported arguments:
* - hsl2css(h,s,l)
* - hsl2css(h,s,l,a)
* - hsl2css([h,s,l], mode)
* - hsl2css([h,s,l,a], mode)
* - hsl2css({h,s,l,a}, mode)
*/
var hsl2css = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var hsla = unpack(args, 'hsla');
var mode = last(args) || 'lsa';
hsla[0] = rnd2(hsla[0] || 0) + 'deg';
hsla[1] = rnd2(hsla[1] * 100) + '%';
hsla[2] = rnd2(hsla[2] * 100) + '%';
if (mode === 'hsla' || (hsla.length > 3 && hsla[3] < 1)) {
hsla[3] = '/ ' + (hsla.length > 3 ? hsla[3] : 1);
mode = 'hsla';
} else {
hsla.length = 3;
}
return ((mode.substr(0, 3)) + "(" + (hsla.join(' ')) + ")");
};
/*
* supported arguments:
* - rgb2hsl(r,g,b)
* - rgb2hsl(r,g,b,a)
* - rgb2hsl([r,g,b])
* - rgb2hsl([r,g,b,a])
* - rgb2hsl({r,g,b,a})
*/
var rgb2hsl$1 = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
args = unpack(args, 'rgba');
var r = args[0];
var g = args[1];
var b = args[2];
r /= 255;
g /= 255;
b /= 255;
var minRgb = min$3(r, g, b);
var maxRgb = max$3(r, g, b);
var l = (maxRgb + minRgb) / 2;
var s, h;
if (maxRgb === minRgb) {
s = 0;
h = Number.NaN;
} else {
s =
l < 0.5
? (maxRgb - minRgb) / (maxRgb + minRgb)
: (maxRgb - minRgb) / (2 - maxRgb - minRgb);
}
if (r == maxRgb) { h = (g - b) / (maxRgb - minRgb); }
else if (g == maxRgb) { h = 2 + (b - r) / (maxRgb - minRgb); }
else if (b == maxRgb) { h = 4 + (r - g) / (maxRgb - minRgb); }
h *= 60;
if (h < 0) { h += 360; }
if (args.length > 3 && args[3] !== undefined) { return [h, s, l, args[3]]; }
return [h, s, l];
};
/*
* supported arguments:
* - lab2css(l,a,b)
* - lab2css(l,a,b,alpha)
* - lab2css([l,a,b], mode)
* - lab2css([l,a,b,alpha], mode)
*/
var lab2css = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var laba = unpack(args, 'lab');
var mode = last(args) || 'lab';
laba[0] = rnd2(laba[0]) + '%';
laba[1] = rnd2(laba[1]);
laba[2] = rnd2(laba[2]);
if (mode === 'laba' || (laba.length > 3 && laba[3] < 1)) {
laba[3] = '/ ' + (laba.length > 3 ? laba[3] : 1);
} else {
laba.length = 3;
}
return ("lab(" + (laba.join(' ')) + ")");
};
var labConstants = {
// Corresponds roughly to RGB brighter/darker
Kn: 18,
// D65 standard referent
labWhitePoint: 'd65',
Xn: 0.95047,
Yn: 1,
Zn: 1.08883,
kE: 216.0 / 24389.0,
kKE: 8.0,
kK: 24389.0 / 27.0,
RefWhiteRGB: {
// sRGB
X: 0.95047,
Y: 1,
Z: 1.08883
},
MtxRGB2XYZ: {
m00: 0.4124564390896922,
m01: 0.21267285140562253,
m02: 0.0193338955823293,
m10: 0.357576077643909,
m11: 0.715152155287818,
m12: 0.11919202588130297,
m20: 0.18043748326639894,
m21: 0.07217499330655958,
m22: 0.9503040785363679
},
MtxXYZ2RGB: {
m00: 3.2404541621141045,
m01: -0.9692660305051868,
m02: 0.055643430959114726,
m10: -1.5371385127977166,
m11: 1.8760108454466942,
m12: -0.2040259135167538,
m20: -0.498531409556016,
m21: 0.041556017530349834,
m22: 1.0572251882231791
},
// used in rgb2xyz
As: 0.9414285350000001,
Bs: 1.040417467,
Cs: 1.089532651,
MtxAdaptMa: {
m00: 0.8951,
m01: -0.7502,
m02: 0.0389,
m10: 0.2664,
m11: 1.7135,
m12: -0.0685,
m20: -0.1614,
m21: 0.0367,
m22: 1.0296
},
MtxAdaptMaI: {
m00: 0.9869929054667123,
m01: 0.43230526972339456,
m02: -0.008528664575177328,
m10: -0.14705425642099013,
m11: 0.5183602715367776,
m12: 0.04004282165408487,
m20: 0.15996265166373125,
m21: 0.0492912282128556,
m22: 0.9684866957875502
}
};
// taken from https://de.mathworks.com/help/images/ref/whitepoint.html
var ILLUMINANTS = new Map([
// ASTM E308-01
['a', [1.0985, 0.35585]],
// Wyszecki & Stiles, p. 769
['b', [1.0985, 0.35585]],
// C ASTM E308-01
['c', [0.98074, 1.18232]],
// D50 (ASTM E308-01)
['d50', [0.96422, 0.82521]],
// D55 (ASTM E308-01)
['d55', [0.95682, 0.92149]],
// D65 (ASTM E308-01)
['d65', [0.95047, 1.08883]],
// E (ASTM E308-01)
['e', [1, 1, 1]],
// F2 (ASTM E308-01)
['f2', [0.99186, 0.67393]],
// F7 (ASTM E308-01)
['f7', [0.95041, 1.08747]],
// F11 (ASTM E308-01)
['f11', [1.00962, 0.6435]],
['icc', [0.96422, 0.82521]]
]);
function setLabWhitePoint(name) {
var ill = ILLUMINANTS.get(String(name).toLowerCase());
if (!ill) {
throw new Error('unknown Lab illuminant ' + name);
}
labConstants.labWhitePoint = name;
labConstants.Xn = ill[0];
labConstants.Zn = ill[1];
}
function getLabWhitePoint() {
return labConstants.labWhitePoint;
}
var rgb2lab = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var ref = unpack(args, 'rgb');
var r = ref[0];
var g = ref[1];
var b = ref[2];
var rest = ref.slice(3);
var ref$1 = rgb2xyz(r, g, b);
var x = ref$1[0];
var y = ref$1[1];
var z = ref$1[2];
var ref$2 = xyz2lab(x, y, z);
var L = ref$2[0];
var a = ref$2[1];
var b_ = ref$2[2];
return [L, a, b_ ].concat( (rest.length > 0 && rest[0] < 1 ? [rest[0]] : []));
};
function xyz2lab(x, y, z) {
var Xn = labConstants.Xn;
var Yn = labConstants.Yn;
var Zn = labConstants.Zn;
var kE = labConstants.kE;
var kK = labConstants.kK;
var xr = x / Xn;
var yr = y / Yn;
var zr = z / Zn;
var fx = xr > kE ? Math.pow(xr, 1.0 / 3.0) : (kK * xr + 16.0) / 116.0;
var fy = yr > kE ? Math.pow(yr, 1.0 / 3.0) : (kK * yr + 16.0) / 116.0;
var fz = zr > kE ? Math.pow(zr, 1.0 / 3.0) : (kK * zr + 16.0) / 116.0;
return [116.0 * fy - 16.0, 500.0 * (fx - fy), 200.0 * (fy - fz)];
}
function gammaAdjustSRGB(companded) {
var sign = Math.sign(companded);
companded = Math.abs(companded);
var linear =
companded <= 0.04045
? companded / 12.92
: Math.pow((companded + 0.055) / 1.055, 2.4);
return linear * sign;
}
var rgb2xyz = function (r, g, b) {
// normalize and gamma adjust
r = gammaAdjustSRGB(r / 255);
g = gammaAdjustSRGB(g / 255);
b = gammaAdjustSRGB(b / 255);
var MtxRGB2XYZ = labConstants.MtxRGB2XYZ;
var MtxAdaptMa = labConstants.MtxAdaptMa;
var MtxAdaptMaI = labConstants.MtxAdaptMaI;
var Xn = labConstants.Xn;
var Yn = labConstants.Yn;
var Zn = labConstants.Zn;
var As = labConstants.As;
var Bs = labConstants.Bs;
var Cs = labConstants.Cs;
var x = r * MtxRGB2XYZ.m00 + g * MtxRGB2XYZ.m10 + b * MtxRGB2XYZ.m20;
var y = r * MtxRGB2XYZ.m01 + g * MtxRGB2XYZ.m11 + b * MtxRGB2XYZ.m21;
var z = r * MtxRGB2XYZ.m02 + g * MtxRGB2XYZ.m12 + b * MtxRGB2XYZ.m22;
var Ad = Xn * MtxAdaptMa.m00 + Yn * MtxAdaptMa.m10 + Zn * MtxAdaptMa.m20;
var Bd = Xn * MtxAdaptMa.m01 + Yn * MtxAdaptMa.m11 + Zn * MtxAdaptMa.m21;
var Cd = Xn * MtxAdaptMa.m02 + Yn * MtxAdaptMa.m12 + Zn * MtxAdaptMa.m22;
var X = x * MtxAdaptMa.m00 + y * MtxAdaptMa.m10 + z * MtxAdaptMa.m20;
var Y = x * MtxAdaptMa.m01 + y * MtxAdaptMa.m11 + z * MtxAdaptMa.m21;
var Z = x * MtxAdaptMa.m02 + y * MtxAdaptMa.m12 + z * MtxAdaptMa.m22;
X *= Ad / As;
Y *= Bd / Bs;
Z *= Cd / Cs;
x = X * MtxAdaptMaI.m00 + Y * MtxAdaptMaI.m10 + Z * MtxAdaptMaI.m20;
y = X * MtxAdaptMaI.m01 + Y * MtxAdaptMaI.m11 + Z * MtxAdaptMaI.m21;
z = X * MtxAdaptMaI.m02 + Y * MtxAdaptMaI.m12 + Z * MtxAdaptMaI.m22;
return [x, y, z];
};
/*
* supported arguments:
* - lab2css(l,a,b)
* - lab2css(l,a,b,alpha)
* - lab2css([l,a,b], mode)
* - lab2css([l,a,b,alpha], mode)
*/
var lch2css = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var lcha = unpack(args, 'lch');
var mode = last(args) || 'lab';
lcha[0] = rnd2(lcha[0]) + '%';
lcha[1] = rnd2(lcha[1]);
lcha[2] = isNaN(lcha[2]) ? 'none' : rnd2(lcha[2]) + 'deg'; // add deg unit to hue
if (mode === 'lcha' || (lcha.length > 3 && lcha[3] < 1)) {
lcha[3] = '/ ' + (lcha.length > 3 ? lcha[3] : 1);
} else {
lcha.length = 3;
}
return ("lch(" + (lcha.join(' ')) + ")");
};
var sqrt$4 = Math.sqrt;
var atan2$2 = Math.atan2;
var round$5 = Math.round;
var lab2lch = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var ref = unpack(args, 'lab');
var l = ref[0];
var a = ref[1];
var b = ref[2];
var c = sqrt$4(a * a + b * b);
var h = (atan2$2(b, a) * RAD2DEG + 360) % 360;
if (round$5(c * 10000) === 0) { h = Number.NaN; }
return [l, c, h];
};
var rgb2lch = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var ref = unpack(args, 'rgb');
var r = ref[0];
var g = ref[1];
var b = ref[2];
var rest = ref.slice(3);
var ref$1 = rgb2lab(r, g, b);
var l = ref$1[0];
var a = ref$1[1];
var b_ = ref$1[2];
var ref$2 = lab2lch(l, a, b_);
var L = ref$2[0];
var c = ref$2[1];
var h = ref$2[2];
return [L, c, h ].concat( (rest.length > 0 && rest[0] < 1 ? [rest[0]] : []));
};
// from https://www.w3.org/TR/css-color-4/multiply-matrices.js
function multiplyMatrices(A, B) {
var m = A.length;
if (!Array.isArray(A[0])) {
// A is vector, convert to [[a, b, c, ...]]
A = [A];
}
if (!Array.isArray(B[0])) {
// B is vector, convert to [[a], [b], [c], ...]]
B = B.map(function (x) { return [x]; });
}
var p = B[0].length;
var B_cols = B[0].map(function (_, i) { return B.map(function (x) { return x[i]; }); }); // transpose B
var product = A.map(function (row) { return B_cols.map(function (col) {
if (!Array.isArray(row)) {
return col.reduce(function (a, c) { return a + c * row; }, 0);
}
return row.reduce(function (a, c, i) { return a + c * (col[i] || 0); }, 0);
}); }
);
if (m === 1) {
product = product[0]; // Avoid [[a, b, c, ...]]
}
if (p === 1) {
return product.map(function (x) { return x[0]; }); // Avoid [[a], [b], [c], ...]]
}
return product;
}
var rgb2oklab = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var ref = unpack(args, 'rgb');
var r = ref[0];
var g = ref[1];
var b = ref[2];
var rest = ref.slice(3);
var xyz = rgb2xyz(r, g, b);
var oklab = XYZ_to_OKLab(xyz);
return oklab.concat( (rest.length > 0 && rest[0] < 1 ? [rest[0]] : []));
};
// from https://www.w3.org/TR/css-color-4/#color-conversion-code
function XYZ_to_OKLab(XYZ) {
// Given XYZ relative to D65, convert to OKLab
var XYZtoLMS = [
[0.819022437996703, 0.3619062600528904, -0.1288737815209879],
[0.0329836539323885, 0.9292868615863434, 0.0361446663506424],
[0.0481771893596242, 0.2642395317527308, 0.6335478284694309]
];
var LMStoOKLab = [
[0.210454268309314, 0.7936177747023054, -0.0040720430116193],
[1.9779985324311684, -2.42859224204858, 0.450593709617411],
[0.0259040424655478, 0.7827717124575296, -0.8086757549230774]
];
var LMS = multiplyMatrices(XYZtoLMS, XYZ);
// JavaScript Math.cbrt returns a sign-matched cube root
// beware if porting to other languages
// especially if tempted to use a general power function
return multiplyMatrices(
LMStoOKLab,
LMS.map(function (c) { return Math.cbrt(c); })
);
// L in range [0,1]. For use in CSS, multiply by 100 and add a percent
}
var oklab2css = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var laba = unpack(args, 'lab');
laba[0] = rnd2(laba[0] * 100) + '%';
laba[1] = rnd3(laba[1]);
laba[2] = rnd3(laba[2]);
if (laba.length > 3 && laba[3] < 1) {
laba[3] = '/ ' + (laba.length > 3 ? laba[3] : 1);
} else {
laba.length = 3;
}
return ("oklab(" + (laba.join(' ')) + ")");
};
var rgb2oklch = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var ref = unpack(args, 'rgb');
var r = ref[0];
var g = ref[1];
var b = ref[2];
var rest = ref.slice(3);
var ref$1 = rgb2oklab(r, g, b);
var l = ref$1[0];
var a = ref$1[1];
var b_ = ref$1[2];
var ref$2 = lab2lch(l, a, b_);
var L = ref$2[0];
var c = ref$2[1];
var h = ref$2[2];
return [L, c, h ].concat( (rest.length > 0 && rest[0] < 1 ? [rest[0]] : []));
};
var oklch2css = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var lcha = unpack(args, 'lch');
lcha[0] = rnd2(lcha[0] * 100) + '%';
lcha[1] = rnd3(lcha[1]);
lcha[2] = isNaN(lcha[2]) ? 'none' : rnd2(lcha[2]) + 'deg'; // add deg unit to hue
if (lcha.length > 3 && lcha[3] < 1) {
lcha[3] = '/ ' + (lcha.length > 3 ? lcha[3] : 1);
} else {
lcha.length = 3;
}
return ("oklch(" + (lcha.join(' ')) + ")");
};
var round$4 = Math.round;
/*
* supported arguments:
* - rgb2css(r,g,b)
* - rgb2css(r,g,b,a)
* - rgb2css([r,g,b], mode)
* - rgb2css([r,g,b,a], mode)
* - rgb2css({r,g,b,a}, mode)
*/
var rgb2css = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var rgba = unpack(args, 'rgba');
var mode = last(args) || 'rgb';
if (mode.substr(0, 3) === 'hsl') {
return hsl2css(rgb2hsl$1(rgba), mode);
}
if (mode.substr(0, 3) === 'lab') {
// change to D50 lab whitepoint since this is what W3C is using for CSS Lab colors
var prevWhitePoint = getLabWhitePoint();
setLabWhitePoint('d50');
var cssColor = lab2css(rgb2lab(rgba), mode);
setLabWhitePoint(prevWhitePoint);
return cssColor;
}
if (mode.substr(0, 3) === 'lch') {
// change to D50 lab whitepoint since this is what W3C is using for CSS Lab colors
var prevWhitePoint$1 = getLabWhitePoint();
setLabWhitePoint('d50');
var cssColor$1 = lch2css(rgb2lch(rgba), mode);
setLabWhitePoint(prevWhitePoint$1);
return cssColor$1;
}
if (mode.substr(0, 5) === 'oklab') {
return oklab2css(rgb2oklab(rgba));
}
if (mode.substr(0, 5) === 'oklch') {
return oklch2css(rgb2oklch(rgba));
}
rgba[0] = round$4(rgba[0]);
rgba[1] = round$4(rgba[1]);
rgba[2] = round$4(rgba[2]);
if (mode === 'rgba' || (rgba.length > 3 && rgba[3] < 1)) {
rgba[3] = '/ ' + (rgba.length > 3 ? rgba[3] : 1);
mode = 'rgba';
}
return ((mode.substr(0, 3)) + "(" + (rgba.slice(0, mode === 'rgb' ? 3 : 4).join(' ')) + ")");
};
var hsl2rgb = function () {
var assign;
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
args = unpack(args, 'hsl');
var h = args[0];
var s = args[1];
var l = args[2];
var r, g, b;
if (s === 0) {
r = g = b = l * 255;
} else {
var t3 = [0, 0, 0];
var c = [0, 0, 0];
var t2 = l < 0.5 ? l * (1 + s) : l + s - l * s;
var t1 = 2 * l - t2;
var h_ = h / 360;
t3[0] = h_ + 1 / 3;
t3[1] = h_;
t3[2] = h_ - 1 / 3;
for (var i = 0; i < 3; i++) {
if (t3[i] < 0) { t3[i] += 1; }
if (t3[i] > 1) { t3[i] -= 1; }
if (6 * t3[i] < 1) { c[i] = t1 + (t2 - t1) * 6 * t3[i]; }
else if (2 * t3[i] < 1) { c[i] = t2; }
else if (3 * t3[i] < 2) { c[i] = t1 + (t2 - t1) * (2 / 3 - t3[i]) * 6; }
else { c[i] = t1; }
}
(assign = [c[0] * 255, c[1] * 255, c[2] * 255], r = assign[0], g = assign[1], b = assign[2]);
}
if (args.length > 3) {
// keep alpha channel
return [r, g, b, args[3]];
}
return [r, g, b, 1];
};
/*
* L* [0..100]
* a [-100..100]
* b [-100..100]
*/
var lab2rgb = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
args = unpack(args, 'lab');
var L = args[0];
var a = args[1];
var b = args[2];
var ref = lab2xyz(L, a, b);
var x = ref[0];
var y = ref[1];
var z = ref[2];
var ref$1 = xyz2rgb(x, y, z);
var r = ref$1[0];
var g = ref$1[1];
var b_ = ref$1[2];
return [r, g, b_, args.length > 3 ? args[3] : 1];
};
var lab2xyz = function (L, a, b) {
var kE = labConstants.kE;
var kK = labConstants.kK;
var kKE = labConstants.kKE;
var Xn = labConstants.Xn;
var Yn = labConstants.Yn;
var Zn = labConstants.Zn;
var fy = (L + 16.0) / 116.0;
var fx = 0.002 * a + fy;
var fz = fy - 0.005 * b;
var fx3 = fx * fx * fx;
var fz3 = fz * fz * fz;
var xr = fx3 > kE ? fx3 : (116.0 * fx - 16.0) / kK;
var yr = L > kKE ? Math.pow((L + 16.0) / 116.0, 3.0) : L / kK;
var zr = fz3 > kE ? fz3 : (116.0 * fz - 16.0) / kK;
var x = xr * Xn;
var y = yr * Yn;
var z = zr * Zn;
return [x, y, z];
};
var compand = function (linear) {
/* sRGB */
var sign = Math.sign(linear);
linear = Math.abs(linear);
return (
(linear <= 0.0031308
? linear * 12.92
: 1.055 * Math.pow(linear, 1.0 / 2.4) - 0.055) * sign
);
};
var xyz2rgb = function (x, y, z) {
var MtxAdaptMa = labConstants.MtxAdaptMa;
var MtxAdaptMaI = labConstants.MtxAdaptMaI;
var MtxXYZ2RGB = labConstants.MtxXYZ2RGB;
var RefWhiteRGB = labConstants.RefWhiteRGB;
var Xn = labConstants.Xn;
var Yn = labConstants.Yn;
var Zn = labConstants.Zn;
var As = Xn * MtxAdaptMa.m00 + Yn * MtxAdaptMa.m10 + Zn * MtxAdaptMa.m20;
var Bs = Xn * MtxAdaptMa.m01 + Yn * MtxAdaptMa.m11 + Zn * MtxAdaptMa.m21;
var Cs = Xn * MtxAdaptMa.m02 + Yn * MtxAdaptMa.m12 + Zn * MtxAdaptMa.m22;
var Ad =
RefWhiteRGB.X * MtxAdaptMa.m00 +
RefWhiteRGB.Y * MtxAdaptMa.m10 +
RefWhiteRGB.Z * MtxAdaptMa.m20;
var Bd =
RefWhiteRGB.X * MtxAdaptMa.m01 +
RefWhiteRGB.Y * MtxAdaptMa.m11 +
RefWhiteRGB.Z * MtxAdaptMa.m21;
var Cd =
RefWhiteRGB.X * MtxAdaptMa.m02 +
RefWhiteRGB.Y * MtxAdaptMa.m12 +
RefWhiteRGB.Z * MtxAdaptMa.m22;
var X1 =
(x * MtxAdaptMa.m00 + y * MtxAdaptMa.m10 + z * MtxAdaptMa.m20) *
(Ad / As);
var Y1 =
(x * MtxAdaptMa.m01 + y * MtxAdaptMa.m11 + z * MtxAdaptMa.m21) *
(Bd / Bs);
var Z1 =
(x * MtxAdaptMa.m02 + y * MtxAdaptMa.m12 + z * MtxAdaptMa.m22) *
(Cd / Cs);
var X2 =
X1 * MtxAdaptMaI.m00 + Y1 * MtxAdaptMaI.m10 + Z1 * MtxAdaptMaI.m20;
var Y2 =
X1 * MtxAdaptMaI.m01 + Y1 * MtxAdaptMaI.m11 + Z1 * MtxAdaptMaI.m21;
var Z2 =
X1 * MtxAdaptMaI.m02 + Y1 * MtxAdaptMaI.m12 + Z1 * MtxAdaptMaI.m22;
var r = compand(
X2 * MtxXYZ2RGB.m00 + Y2 * MtxXYZ2RGB.m10 + Z2 * MtxXYZ2RGB.m20
);
var g = compand(
X2 * MtxXYZ2RGB.m01 + Y2 * MtxXYZ2RGB.m11 + Z2 * MtxXYZ2RGB.m21
);
var b = compand(
X2 * MtxXYZ2RGB.m02 + Y2 * MtxXYZ2RGB.m12 + Z2 * MtxXYZ2RGB.m22
);
return [r * 255, g * 255, b * 255];
};
var sin$3 = Math.sin;
var cos$4 = Math.cos;
var lch2lab = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
/*
Convert from a qualitative parameter h and a quantitative parameter l to a 24-bit pixel.
These formulas were invented by David Dalrymple to obtain maximum contrast without going
out of gamut if the parameters are in the range 0-1.
A saturation multiplier was added by Gregor Aisch
*/
var ref = unpack(args, 'lch');
var l = ref[0];
var c = ref[1];
var h = ref[2];
if (isNaN(h)) { h = 0; }
h = h * DEG2RAD;
return [l, cos$4(h) * c, sin$3(h) * c];
};
var lch2rgb = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
args = unpack(args, 'lch');
var l = args[0];
var c = args[1];
var h = args[2];
var ref = lch2lab(l, c, h);
var L = ref[0];
var a = ref[1];
var b_ = ref[2];
var ref$1 = lab2rgb(L, a, b_);
var r = ref$1[0];
var g = ref$1[1];
var b = ref$1[2];
return [r, g, b, args.length > 3 ? args[3] : 1];
};
var oklab2rgb = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
args = unpack(args, 'lab');
var L = args[0];
var a = args[1];
var b = args[2];
var rest = args.slice(3);
var ref = OKLab_to_XYZ([L, a, b]);
var X = ref[0];
var Y = ref[1];
var Z = ref[2];
var ref$1 = xyz2rgb(X, Y, Z);
var r = ref$1[0];
var g = ref$1[1];
var b_ = ref$1[2];
return [r, g, b_ ].concat( (rest.length > 0 && rest[0] < 1 ? [rest[0]] : []));
};
// from https://www.w3.org/TR/css-color-4/#color-conversion-code
function OKLab_to_XYZ(OKLab) {
// Given OKLab, convert to XYZ relative to D65
var LMStoXYZ = [
[1.2268798758459243, -0.5578149944602171, 0.2813910456659647],
[-0.0405757452148008, 1.112286803280317, -0.0717110580655164],
[-0.0763729366746601, -0.4214933324022432, 1.5869240198367816]
];
var OKLabtoLMS = [
[1.0, 0.3963377773761749, 0.2158037573099136],
[1.0, -0.1055613458156586, -0.0638541728258133],
[1.0, -0.0894841775298119, -1.2914855480194092]
];
var LMSnl = multiplyMatrices(OKLabtoLMS, OKLab);
return multiplyMatrices(
LMStoXYZ,
LMSnl.map(function (c) { return Math.pow( c, 3 ); })
);
}
var oklch2rgb = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
args = unpack(args, 'lch');
var l = args[0];
var c = args[1];
var h = args[2];
var rest = args.slice(3);
var ref = lch2lab(l, c, h);
var L = ref[0];
var a = ref[1];
var b_ = ref[2];
var ref$1 = oklab2rgb(L, a, b_);
var r = ref$1[0];
var g = ref$1[1];
var b = ref$1[2];
return [r, g, b ].concat( (rest.length > 0 && rest[0] < 1 ? [rest[0]] : []));
};
var INT_OR_PCT = /((?:-?\d+)|(?:-?\d+(?:\.\d+)?)%|none)/.source;
var FLOAT_OR_PCT = /((?:-?(?:\d+(?:\.\d*)?|\.\d+)%?)|none)/.source;
var PCT = /((?:-?(?:\d+(?:\.\d*)?|\.\d+)%)|none)/.source;
var RE_S = /\s*/.source;
var SEP = /\s+/.source;
var COMMA = /\s*,\s*/.source;
var ANLGE = /((?:-?(?:\d+(?:\.\d*)?|\.\d+)(?:deg)?)|none)/.source;
var ALPHA = /\s*(?:\/\s*((?:[01]|[01]?\.\d+)|\d+(?:\.\d+)?%))?/.source;
// e.g. rgb(250 20 0), rgb(100% 50% 20%), rgb(100% 50% 20% / 0.5)
var RE_RGB = new RegExp(
'^rgba?\\(' +
RE_S +
[INT_OR_PCT, INT_OR_PCT, INT_OR_PCT].join(SEP) +
ALPHA +
'\\)$'
);
var RE_RGB_LEGACY = new RegExp(
'^rgb\\(' +
RE_S +
[INT_OR_PCT, INT_OR_PCT, INT_OR_PCT].join(COMMA) +
RE_S +
'\\)$'
);
var RE_RGBA_LEGACY = new RegExp(
'^rgba\\(' +
RE_S +
[INT_OR_PCT, INT_OR_PCT, INT_OR_PCT, FLOAT_OR_PCT].join(COMMA) +
RE_S +
'\\)$'
);
var RE_HSL = new RegExp(
'^hsla?\\(' + RE_S + [ANLGE, PCT, PCT].join(SEP) + ALPHA + '\\)$'
);
var RE_HSL_LEGACY = new RegExp(
'^hsl?\\(' + RE_S + [ANLGE, PCT, PCT].join(COMMA) + RE_S + '\\)$'
);
var RE_HSLA_LEGACY =
/^hsla\(\s*(-?\d+(?:\.\d+)?),\s*(-?\d+(?:\.\d+)?)%\s*,\s*(-?\d+(?:\.\d+)?)%\s*,\s*([01]|[01]?\.\d+)\)$/;
var RE_LAB = new RegExp(
'^lab\\(' +
RE_S +
[FLOAT_OR_PCT, FLOAT_OR_PCT, FLOAT_OR_PCT].join(SEP) +
ALPHA +
'\\)$'
);
var RE_LCH = new RegExp(
'^lch\\(' +
RE_S +
[FLOAT_OR_PCT, FLOAT_OR_PCT, ANLGE].join(SEP) +
ALPHA +
'\\)$'
);
var RE_OKLAB = new RegExp(
'^oklab\\(' +
RE_S +
[FLOAT_OR_PCT, FLOAT_OR_PCT, FLOAT_OR_PCT].join(SEP) +
ALPHA +
'\\)$'
);
var RE_OKLCH = new RegExp(
'^oklch\\(' +
RE_S +
[FLOAT_OR_PCT, FLOAT_OR_PCT, ANLGE].join(SEP) +
ALPHA +
'\\)$'
);
var round$3 = Math.round;
var roundRGB = function (rgb) {
return rgb.map(function (v, i) { return (i <= 2 ? limit(round$3(v), 0, 255) : v); });
};
var percentToAbsolute = function (pct, min, max, signed) {
if ( min === void 0 ) min = 0;
if ( max === void 0 ) max = 100;
if ( signed === void 0 ) signed = false;
if (typeof pct === 'string' && pct.endsWith('%')) {
pct = parseFloat(pct.substring(0, pct.length - 1)) / 100;
if (signed) {
// signed percentages are in the range -100% to 100%
pct = min + (pct + 1) * 0.5 * (max - min);
} else {
pct = min + pct * (max - min);
}
}
return +pct;
};
var noneToValue = function (v, noneValue) {
return v === 'none' ? noneValue : v;
};
var css2rgb = function (css) {
css = css.toLowerCase().trim();
if (css === 'transparent') {
return [0, 0, 0, 0];
}
var m;
if (input.format.named) {
try {
return input.format.named(css);
// eslint-disable-next-line
} catch (e) {}
}
// rgb(250 20 0) or rgb(250,20,0)
if ((m = css.match(RE_RGB)) || (m = css.match(RE_RGB_LEGACY))) {
var rgb = m.slice(1, 4);
for (var i = 0; i < 3; i++) {
rgb[i] = +percentToAbsolute(noneToValue(rgb[i], 0), 0, 255);
}
rgb = roundRGB(rgb);
var alpha = m[4] !== undefined ? +percentToAbsolute(m[4], 0, 1) : 1;
rgb[3] = alpha; // default alpha
return rgb;
}
// rgba(250,20,0,0.4)
if ((m = css.match(RE_RGBA_LEGACY))) {
var rgb$1 = m.slice(1, 5);
for (var i$1 = 0; i$1 < 4; i$1++) {
rgb$1[i$1] = +percentToAbsolute(rgb$1[i$1], 0, 255);
}
return rgb$1;
}
// hsl(0,100%,50%)
if ((m = css.match(RE_HSL)) || (m = css.match(RE_HSL_LEGACY))) {
var hsl = m.slice(1, 4);
hsl[0] = +noneToValue(hsl[0].replace('deg', ''), 0);
hsl[1] = +percentToAbsolute(noneToValue(hsl[1], 0), 0, 100) * 0.01;
hsl[2] = +percentToAbsolute(noneToValue(hsl[2], 0), 0, 100) * 0.01;
var rgb$2 = roundRGB(hsl2rgb(hsl));
var alpha$1 = m[4] !== undefined ? +percentToAbsolute(m[4], 0, 1) : 1;
rgb$2[3] = alpha$1;
return rgb$2;
}
// hsla(0,100%,50%,0.5)
if ((m = css.match(RE_HSLA_LEGACY))) {
var hsl$1 = m.slice(1, 4);
hsl$1[1] *= 0.01;
hsl$1[2] *= 0.01;
var rgb$3 = hsl2rgb(hsl$1);
for (var i$2 = 0; i$2 < 3; i$2++) {
rgb$3[i$2] = round$3(rgb$3[i$2]);
}
rgb$3[3] = +m[4]; // default alpha = 1
return rgb$3;
}
if ((m = css.match(RE_LAB))) {
var lab = m.slice(1, 4);
lab[0] = percentToAbsolute(noneToValue(lab[0], 0), 0, 100);
lab[1] = percentToAbsolute(noneToValue(lab[1], 0), -125, 125, true);
lab[2] = percentToAbsolute(noneToValue(lab[2], 0), -125, 125, true);
// convert to D50 Lab whitepoint
var wp = getLabWhitePoint();
setLabWhitePoint('d50');
var rgb$4 = roundRGB(lab2rgb(lab));
// convert back to original Lab whitepoint
setLabWhitePoint(wp);
var alpha$2 = m[4] !== undefined ? +percentToAbsolute(m[4], 0, 1) : 1;
rgb$4[3] = alpha$2;
return rgb$4;
}
if ((m = css.match(RE_LCH))) {
var lch = m.slice(1, 4);
lch[0] = percentToAbsolute(lch[0], 0, 100);
lch[1] = percentToAbsolute(noneToValue(lch[1], 0), 0, 150, false);
lch[2] = +noneToValue(lch[2].replace('deg', ''), 0);
// convert to D50 Lab whitepoint
var wp$1 = getLabWhitePoint();
setLabWhitePoint('d50');
var rgb$5 = roundRGB(lch2rgb(lch));
// convert back to original Lab whitepoint
setLabWhitePoint(wp$1);
var alpha$3 = m[4] !== undefined ? +percentToAbsolute(m[4], 0, 1) : 1;
rgb$5[3] = alpha$3;
return rgb$5;
}
if ((m = css.match(RE_OKLAB))) {
var oklab = m.slice(1, 4);
oklab[0] = percentToAbsolute(noneToValue(oklab[0], 0), 0, 1);
oklab[1] = percentToAbsolute(noneToValue(oklab[1], 0), -0.4, 0.4, true);
oklab[2] = percentToAbsolute(noneToValue(oklab[2], 0), -0.4, 0.4, true);
var rgb$6 = roundRGB(oklab2rgb(oklab));
var alpha$4 = m[4] !== undefined ? +percentToAbsolute(m[4], 0, 1) : 1;
rgb$6[3] = alpha$4;
return rgb$6;
}
if ((m = css.match(RE_OKLCH))) {
var oklch = m.slice(1, 4);
oklch[0] = percentToAbsolute(noneToValue(oklch[0], 0), 0, 1);
oklch[1] = percentToAbsolute(noneToValue(oklch[1], 0), 0, 0.4, false);
oklch[2] = +noneToValue(oklch[2].replace('deg', ''), 0);
var rgb$7 = roundRGB(oklch2rgb(oklch));
var alpha$5 = m[4] !== undefined ? +percentToAbsolute(m[4], 0, 1) : 1;
rgb$7[3] = alpha$5;
return rgb$7;
}
};
css2rgb.test = function (s) {
return (
// modern
RE_RGB.test(s) ||
RE_HSL.test(s) ||
RE_LAB.test(s) ||
RE_LCH.test(s) ||
RE_OKLAB.test(s) ||
RE_OKLCH.test(s) ||
// legacy
RE_RGB_LEGACY.test(s) ||
RE_RGBA_LEGACY.test(s) ||
RE_HSL_LEGACY.test(s) ||
RE_HSLA_LEGACY.test(s) ||
s === 'transparent'
);
};
Color.prototype.css = function (mode) {
return rgb2css(this._rgb, mode);
};
var css = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
return new (Function.prototype.bind.apply( Color, [ null ].concat( args, ['css']) ));
};
chroma.css = css;
input.format.css = css2rgb;
input.autodetect.push({
p: 5,
test: function (h) {
var rest = [], len = arguments.length - 1;
while ( len-- > 0 ) rest[ len ] = arguments[ len + 1 ];
if (!rest.length && type(h) === 'string' && css2rgb.test(h)) {
return 'css';
}
}
});
input.format.gl = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var rgb = unpack(args, 'rgba');
rgb[0] *= 255;
rgb[1] *= 255;
rgb[2] *= 255;
return rgb;
};
var gl = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
return new (Function.prototype.bind.apply( Color, [ null ].concat( args, ['gl']) ));
};
chroma.gl = gl;
Color.prototype.gl = function () {
var rgb = this._rgb;
return [rgb[0] / 255, rgb[1] / 255, rgb[2] / 255, rgb[3]];
};
var floor$3 = Math.floor;
/*
* this is basically just HSV with some minor tweaks
*
* hue.. [0..360]
* chroma .. [0..1]
* grayness .. [0..1]
*/
var hcg2rgb = function () {
var assign, assign$1, assign$2, assign$3, assign$4, assign$5;
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
args = unpack(args, 'hcg');
var h = args[0];
var c = args[1];
var _g = args[2];
var r, g, b;
_g = _g * 255;
var _c = c * 255;
if (c === 0) {
r = g = b = _g;
} else {
if (h === 360) { h = 0; }
if (h > 360) { h -= 360; }
if (h < 0) { h += 360; }
h /= 60;
var i = floor$3(h);
var f = h - i;
var p = _g * (1 - c);
var q = p + _c * (1 - f);
var t = p + _c * f;
var v = p + _c;
switch (i) {
case 0:
(assign = [v, t, p], r = assign[0], g = assign[1], b = assign[2]);
break;
case 1:
(assign$1 = [q, v, p], r = assign$1[0], g = assign$1[1], b = assign$1[2]);
break;
case 2:
(assign$2 = [p, v, t], r = assign$2[0], g = assign$2[1], b = assign$2[2]);
break;
case 3:
(assign$3 = [p, q, v], r = assign$3[0], g = assign$3[1], b = assign$3[2]);
break;
case 4:
(assign$4 = [t, p, v], r = assign$4[0], g = assign$4[1], b = assign$4[2]);
break;
case 5:
(assign$5 = [v, p, q], r = assign$5[0], g = assign$5[1], b = assign$5[2]);
break;
}
}
return [r, g, b, args.length > 3 ? args[3] : 1];
};
var rgb2hcg = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var ref = unpack(args, 'rgb');
var r = ref[0];
var g = ref[1];
var b = ref[2];
var minRgb = min$3(r, g, b);
var maxRgb = max$3(r, g, b);
var delta = maxRgb - minRgb;
var c = (delta * 100) / 255;
var _g = (minRgb / (255 - delta)) * 100;
var h;
if (delta === 0) {
h = Number.NaN;
} else {
if (r === maxRgb) { h = (g - b) / delta; }
if (g === maxRgb) { h = 2 + (b - r) / delta; }
if (b === maxRgb) { h = 4 + (r - g) / delta; }
h *= 60;
if (h < 0) { h += 360; }
}
return [h, c, _g];
};
Color.prototype.hcg = function () {
return rgb2hcg(this._rgb);
};
var hcg$1 = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
return new (Function.prototype.bind.apply( Color, [ null ].concat( args, ['hcg']) ));
};
chroma.hcg = hcg$1;
input.format.hcg = hcg2rgb;
input.autodetect.push({
p: 1,
test: function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
args = unpack(args, 'hcg');
if (type(args) === 'array' && args.length === 3) {
return 'hcg';
}
}
});
var RE_HEX = /^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;
var RE_HEXA = /^#?([A-Fa-f0-9]{8}|[A-Fa-f0-9]{4})$/;
var hex2rgb = function (hex) {
if (hex.match(RE_HEX)) {
// remove optional leading #
if (hex.length === 4 || hex.length === 7) {
hex = hex.substr(1);
}
// expand short-notation to full six-digit
if (hex.length === 3) {
hex = hex.split('');
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
}
var u = parseInt(hex, 16);
var r = u >> 16;
var g = (u >> 8) & 0xff;
var b = u & 0xff;
return [r, g, b, 1];
}
// match rgba hex format, eg #FF000077
if (hex.match(RE_HEXA)) {
if (hex.length === 5 || hex.length === 9) {
// remove optional leading #
hex = hex.substr(1);
}
// expand short-notation to full eight-digit
if (hex.length === 4) {
hex = hex.split('');
hex =
hex[0] +
hex[0] +
hex[1] +
hex[1] +
hex[2] +
hex[2] +
hex[3] +
hex[3];
}
var u$1 = parseInt(hex, 16);
var r$1 = (u$1 >> 24) & 0xff;
var g$1 = (u$1 >> 16) & 0xff;
var b$1 = (u$1 >> 8) & 0xff;
var a = Math.round(((u$1 & 0xff) / 0xff) * 100) / 100;
return [r$1, g$1, b$1, a];
}
// we used to check for css colors here
// if _input.css? and rgb = _input.css hex
// return rgb
throw new Error(("unknown hex color: " + hex));
};
var round$2 = Math.round;
var rgb2hex = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var ref = unpack(args, 'rgba');
var r = ref[0];
var g = ref[1];
var b = ref[2];
var a = ref[3];
var mode = last(args) || 'auto';
if (a === undefined) { a = 1; }
if (mode === 'auto') {
mode = a < 1 ? 'rgba' : 'rgb';
}
r = round$2(r);
g = round$2(g);
b = round$2(b);
var u = (r << 16) | (g << 8) | b;
var str = '000000' + u.toString(16); //#.toUpperCase();
str = str.substr(str.length - 6);
var hxa = '0' + round$2(a * 255).toString(16);
hxa = hxa.substr(hxa.length - 2);
switch (mode.toLowerCase()) {
case 'rgba':
return ("#" + str + hxa);
case 'argb':
return ("#" + hxa + str);
default:
return ("#" + str);
}
};
Color.prototype.hex = function (mode) {
return rgb2hex(this._rgb, mode);
};
var hex = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
return new (Function.prototype.bind.apply( Color, [ null ].concat( args, ['hex']) ));
};
chroma.hex = hex;
input.format.hex = hex2rgb;
input.autodetect.push({
p: 4,
test: function (h) {
var rest = [], len = arguments.length - 1;
while ( len-- > 0 ) rest[ len ] = arguments[ len + 1 ];
if (
!rest.length &&
type(h) === 'string' &&
[3, 4, 5, 6, 7, 8, 9].indexOf(h.length) >= 0
) {
return 'hex';
}
}
});
var cos$3 = Math.cos;
/*
* hue [0..360]
* saturation [0..1]
* intensity [0..1]
*/
var hsi2rgb = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
/*
borrowed from here:
http://hummer.stanford.edu/museinfo/doc/examples/humdrum/keyscape2/hsi2rgb.cpp
*/
args = unpack(args, 'hsi');
var h = args[0];
var s = args[1];
var i = args[2];
var r, g, b;
if (isNaN(h)) { h = 0; }
if (isNaN(s)) { s = 0; }
// normalize hue
if (h > 360) { h -= 360; }
if (h < 0) { h += 360; }
h /= 360;
if (h < 1 / 3) {
b = (1 - s) / 3;
r = (1 + (s * cos$3(TWOPI * h)) / cos$3(PITHIRD - TWOPI * h)) / 3;
g = 1 - (b + r);
} else if (h < 2 / 3) {
h -= 1 / 3;
r = (1 - s) / 3;
g = (1 + (s * cos$3(TWOPI * h)) / cos$3(PITHIRD - TWOPI * h)) / 3;
b = 1 - (r + g);
} else {
h -= 2 / 3;
g = (1 - s) / 3;
b = (1 + (s * cos$3(TWOPI * h)) / cos$3(PITHIRD - TWOPI * h)) / 3;
r = 1 - (g + b);
}
r = limit(i * r * 3);
g = limit(i * g * 3);
b = limit(i * b * 3);
return [r * 255, g * 255, b * 255, args.length > 3 ? args[3] : 1];
};
var min$2 = Math.min;
var sqrt$3 = Math.sqrt;
var acos = Math.acos;
var rgb2hsi = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
/*
borrowed from here:
http://hummer.stanford.edu/museinfo/doc/examples/humdrum/keyscape2/rgb2hsi.cpp
*/
var ref = unpack(args, 'rgb');
var r = ref[0];
var g = ref[1];
var b = ref[2];
r /= 255;
g /= 255;
b /= 255;
var h;
var min_ = min$2(r, g, b);
var i = (r + g + b) / 3;
var s = i > 0 ? 1 - min_ / i : 0;
if (s === 0) {
h = NaN;
} else {
h = (r - g + (r - b)) / 2;
h /= sqrt$3((r - g) * (r - g) + (r - b) * (g - b));
h = acos(h);
if (b > g) {
h = TWOPI - h;
}
h /= TWOPI;
}
return [h * 360, s, i];
};
Color.prototype.hsi = function () {
return rgb2hsi(this._rgb);
};
var hsi$1 = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
return new (Function.prototype.bind.apply( Color, [ null ].concat( args, ['hsi']) ));
};
chroma.hsi = hsi$1;
input.format.hsi = hsi2rgb;
input.autodetect.push({
p: 2,
test: function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
args = unpack(args, 'hsi');
if (type(args) === 'array' && args.length === 3) {
return 'hsi';
}
}
});
Color.prototype.hsl = function () {
return rgb2hsl$1(this._rgb);
};
var hsl$1 = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
return new (Function.prototype.bind.apply( Color, [ null ].concat( args, ['hsl']) ));
};
chroma.hsl = hsl$1;
input.format.hsl = hsl2rgb;
input.autodetect.push({
p: 2,
test: function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
args = unpack(args, 'hsl');
if (type(args) === 'array' && args.length === 3) {
return 'hsl';
}
}
});
var floor$2 = Math.floor;
var hsv2rgb = function () {
var assign, assign$1, assign$2, assign$3, assign$4, assign$5;
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
args = unpack(args, 'hsv');
var h = args[0];
var s = args[1];
var v = args[2];
var r, g, b;
v *= 255;
if (s === 0) {
r = g = b = v;
} else {
if (h === 360) { h = 0; }
if (h > 360) { h -= 360; }
if (h < 0) { h += 360; }
h /= 60;
var i = floor$2(h);
var f = h - i;
var p = v * (1 - s);
var q = v * (1 - s * f);
var t = v * (1 - s * (1 - f));
switch (i) {
case 0:
(assign = [v, t, p], r = assign[0], g = assign[1], b = assign[2]);
break;
case 1:
(assign$1 = [q, v, p], r = assign$1[0], g = assign$1[1], b = assign$1[2]);
break;
case 2:
(assign$2 = [p, v, t], r = assign$2[0], g = assign$2[1], b = assign$2[2]);
break;
case 3:
(assign$3 = [p, q, v], r = assign$3[0], g = assign$3[1], b = assign$3[2]);
break;
case 4:
(assign$4 = [t, p, v], r = assign$4[0], g = assign$4[1], b = assign$4[2]);
break;
case 5:
(assign$5 = [v, p, q], r = assign$5[0], g = assign$5[1], b = assign$5[2]);
break;
}
}
return [r, g, b, args.length > 3 ? args[3] : 1];
};
var min$1 = Math.min;
var max$1 = Math.max;
/*
* supported arguments:
* - rgb2hsv(r,g,b)
* - rgb2hsv([r,g,b])
* - rgb2hsv({r,g,b})
*/
var rgb2hsl = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
args = unpack(args, 'rgb');
var r = args[0];
var g = args[1];
var b = args[2];
var min_ = min$1(r, g, b);
var max_ = max$1(r, g, b);
var delta = max_ - min_;
var h, s, v;
v = max_ / 255.0;
if (max_ === 0) {
h = Number.NaN;
s = 0;
} else {
s = delta / max_;
if (r === max_) { h = (g - b) / delta; }
if (g === max_) { h = 2 + (b - r) / delta; }
if (b === max_) { h = 4 + (r - g) / delta; }
h *= 60;
if (h < 0) { h += 360; }
}
return [h, s, v];
};
Color.prototype.hsv = function () {
return rgb2hsl(this._rgb);
};
var hsv$1 = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
return new (Function.prototype.bind.apply( Color, [ null ].concat( args, ['hsv']) ));
};
chroma.hsv = hsv$1;
input.format.hsv = hsv2rgb;
input.autodetect.push({
p: 2,
test: function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
args = unpack(args, 'hsv');
if (type(args) === 'array' && args.length === 3) {
return 'hsv';
}
}
});
Color.prototype.lab = function () {
return rgb2lab(this._rgb);
};
var lab$1 = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
return new (Function.prototype.bind.apply( Color, [ null ].concat( args, ['lab']) ));
};
Object.assign(chroma, { lab: lab$1, getLabWhitePoint: getLabWhitePoint, setLabWhitePoint: setLabWhitePoint });
input.format.lab = lab2rgb;
input.autodetect.push({
p: 2,
test: function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
args = unpack(args, 'lab');
if (type(args) === 'array' && args.length === 3) {
return 'lab';
}
}
});
var hcl2rgb = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var hcl = reverse3(unpack(args, 'hcl'));
return lch2rgb.apply(void 0, hcl);
};
Color.prototype.lch = function () {
return rgb2lch(this._rgb);
};
Color.prototype.hcl = function () {
return reverse3(rgb2lch(this._rgb));
};
var lch$1 = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
return new (Function.prototype.bind.apply( Color, [ null ].concat( args, ['lch']) ));
};
var hcl = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
return new (Function.prototype.bind.apply( Color, [ null ].concat( args, ['hcl']) ));
};
Object.assign(chroma, { lch: lch$1, hcl: hcl });
input.format.lch = lch2rgb;
input.format.hcl = hcl2rgb;
['lch', 'hcl'].forEach(function (m) { return input.autodetect.push({
p: 2,
test: function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
args = unpack(args, m);
if (type(args) === 'array' && args.length === 3) {
return m;
}
}
}); }
);
var num2rgb = function (num) {
if (type(num) == 'number' && num >= 0 && num <= 0xffffff) {
var r = num >> 16;
var g = (num >> 8) & 0xff;
var b = num & 0xff;
return [r, g, b, 1];
}
throw new Error('unknown num color: ' + num);
};
var rgb2num = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var ref = unpack(args, 'rgb');
var r = ref[0];
var g = ref[1];
var b = ref[2];
return (r << 16) + (g << 8) + b;
};
Color.prototype.num = function () {
return rgb2num(this._rgb);
};
var num$1 = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
return new (Function.prototype.bind.apply( Color, [ null ].concat( args, ['num']) ));
};
Object.assign(chroma, { num: num$1 });
input.format.num = num2rgb;
input.autodetect.push({
p: 5,
test: function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
if (
args.length === 1 &&
type(args[0]) === 'number' &&
args[0] >= 0 &&
args[0] <= 0xffffff
) {
return 'num';
}
}
});
var round$1 = Math.round;
Color.prototype.rgb = function (rnd) {
if ( rnd === void 0 ) rnd = true;
if (rnd === false) { return this._rgb.slice(0, 3); }
return this._rgb.slice(0, 3).map(round$1);
};
Color.prototype.rgba = function (rnd) {
if ( rnd === void 0 ) rnd = true;
return this._rgb.slice(0, 4).map(function (v, i) {
return i < 3 ? (rnd === false ? v : round$1(v)) : v;
});
};
var rgb$1 = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
return new (Function.prototype.bind.apply( Color, [ null ].concat( args, ['rgb']) ));
};
Object.assign(chroma, { rgb: rgb$1 });
input.format.rgb = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var rgba = unpack(args, 'rgba');
if (rgba[3] === undefined) { rgba[3] = 1; }
return rgba;
};
input.autodetect.push({
p: 3,
test: function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
args = unpack(args, 'rgba');
if (
type(args) === 'array' &&
(args.length === 3 ||
(args.length === 4 &&
type(args[3]) == 'number' &&
args[3] >= 0 &&
args[3] <= 1))
) {
return 'rgb';
}
}
});
/*
* Based on implementation by Neil Bartlett
* https://github.com/neilbartlett/color-temperature
*/
var log$1 = Math.log;
var temperature2rgb = function (kelvin) {
var temp = kelvin / 100;
var r, g, b;
if (temp < 66) {
r = 255;
g =
temp < 6
? 0
: -155.25485562709179 -
0.44596950469579133 * (g = temp - 2) +
104.49216199393888 * log$1(g);
b =
temp < 20
? 0
: -254.76935184120902 +
0.8274096064007395 * (b = temp - 10) +
115.67994401066147 * log$1(b);
} else {
r =
351.97690566805693 +
0.114206453784165 * (r = temp - 55) -
40.25366309332127 * log$1(r);
g =
325.4494125711974 +
0.07943456536662342 * (g = temp - 50) -
28.0852963507957 * log$1(g);
b = 255;
}
return [r, g, b, 1];
};
/*
* Based on implementation by Neil Bartlett
* https://github.com/neilbartlett/color-temperature
**/
var round = Math.round;
var rgb2temperature = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var rgb = unpack(args, 'rgb');
var r = rgb[0],
b = rgb[2];
var minTemp = 1000;
var maxTemp = 40000;
var eps = 0.4;
var temp;
while (maxTemp - minTemp > eps) {
temp = (maxTemp + minTemp) * 0.5;
var rgb$1 = temperature2rgb(temp);
if (rgb$1[2] / rgb$1[0] >= b / r) {
maxTemp = temp;
} else {
minTemp = temp;
}
}
return round(temp);
};
Color.prototype.temp =
Color.prototype.kelvin =
Color.prototype.temperature =
function () {
return rgb2temperature(this._rgb);
};
var temp = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
return new (Function.prototype.bind.apply( Color, [ null ].concat( args, ['temp']) ));
};
Object.assign(chroma, { temp: temp, kelvin: temp, temperature: temp });
input.format.temp =
input.format.kelvin =
input.format.temperature =
temperature2rgb;
Color.prototype.oklab = function () {
return rgb2oklab(this._rgb);
};
var oklab$1 = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
return new (Function.prototype.bind.apply( Color, [ null ].concat( args, ['oklab']) ));
};
Object.assign(chroma, { oklab: oklab$1 });
input.format.oklab = oklab2rgb;
input.autodetect.push({
p: 2,
test: function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
args = unpack(args, 'oklab');
if (type(args) === 'array' && args.length === 3) {
return 'oklab';
}
}
});
Color.prototype.oklch = function () {
return rgb2oklch(this._rgb);
};
var oklch$1 = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
return new (Function.prototype.bind.apply( Color, [ null ].concat( args, ['oklch']) ));
};
Object.assign(chroma, { oklch: oklch$1 });
input.format.oklch = oklch2rgb;
input.autodetect.push({
p: 2,
test: function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
args = unpack(args, 'oklch');
if (type(args) === 'array' && args.length === 3) {
return 'oklch';
}
}
});
/**
X11 color names
http://www.w3.org/TR/css3-color/#svg-color
*/
var w3cx11 = {
aliceblue: '#f0f8ff',
antiquewhite: '#faebd7',
aqua: '#00ffff',
aquamarine: '#7fffd4',
azure: '#f0ffff',
beige: '#f5f5dc',
bisque: '#ffe4c4',
black: '#000000',
blanchedalmond: '#ffebcd',
blue: '#0000ff',
blueviolet: '#8a2be2',
brown: '#a52a2a',
burlywood: '#deb887',
cadetblue: '#5f9ea0',
chartreuse: '#7fff00',
chocolate: '#d2691e',
coral: '#ff7f50',
cornflowerblue: '#6495ed',
cornsilk: '#fff8dc',
crimson: '#dc143c',
cyan: '#00ffff',
darkblue: '#00008b',
darkcyan: '#008b8b',
darkgoldenrod: '#b8860b',
darkgray: '#a9a9a9',
darkgreen: '#006400',
darkgrey: '#a9a9a9',
darkkhaki: '#bdb76b',
darkmagenta: '#8b008b',
darkolivegreen: '#556b2f',
darkorange: '#ff8c00',
darkorchid: '#9932cc',
darkred: '#8b0000',
darksalmon: '#e9967a',
darkseagreen: '#8fbc8f',
darkslateblue: '#483d8b',
darkslategray: '#2f4f4f',
darkslategrey: '#2f4f4f',
darkturquoise: '#00ced1',
darkviolet: '#9400d3',
deeppink: '#ff1493',
deepskyblue: '#00bfff',
dimgray: '#696969',
dimgrey: '#696969',
dodgerblue: '#1e90ff',
firebrick: '#b22222',
floralwhite: '#fffaf0',
forestgreen: '#228b22',
fuchsia: '#ff00ff',
gainsboro: '#dcdcdc',
ghostwhite: '#f8f8ff',
gold: '#ffd700',
goldenrod: '#daa520',
gray: '#808080',
green: '#008000',
greenyellow: '#adff2f',
grey: '#808080',
honeydew: '#f0fff0',
hotpink: '#ff69b4',
indianred: '#cd5c5c',
indigo: '#4b0082',
ivory: '#fffff0',
khaki: '#f0e68c',
laserlemon: '#ffff54',
lavender: '#e6e6fa',
lavenderblush: '#fff0f5',
lawngreen: '#7cfc00',
lemonchiffon: '#fffacd',
lightblue: '#add8e6',
lightcoral: '#f08080',
lightcyan: '#e0ffff',
lightgoldenrod: '#fafad2',
lightgoldenrodyellow: '#fafad2',
lightgray: '#d3d3d3',
lightgreen: '#90ee90',
lightgrey: '#d3d3d3',
lightpink: '#ffb6c1',
lightsalmon: '#ffa07a',
lightseagreen: '#20b2aa',
lightskyblue: '#87cefa',
lightslategray: '#778899',
lightslategrey: '#778899',
lightsteelblue: '#b0c4de',
lightyellow: '#ffffe0',
lime: '#00ff00',
limegreen: '#32cd32',
linen: '#faf0e6',
magenta: '#ff00ff',
maroon: '#800000',
maroon2: '#7f0000',
maroon3: '#b03060',
mediumaquamarine: '#66cdaa',
mediumblue: '#0000cd',
mediumorchid: '#ba55d3',
mediumpurple: '#9370db',
mediumseagreen: '#3cb371',
mediumslateblue: '#7b68ee',
mediumspringgreen: '#00fa9a',
mediumturquoise: '#48d1cc',
mediumvioletred: '#c71585',
midnightblue: '#191970',
mintcream: '#f5fffa',
mistyrose: '#ffe4e1',
moccasin: '#ffe4b5',
navajowhite: '#ffdead',
navy: '#000080',
oldlace: '#fdf5e6',
olive: '#808000',
olivedrab: '#6b8e23',
orange: '#ffa500',
orangered: '#ff4500',
orchid: '#da70d6',
palegoldenrod: '#eee8aa',
palegreen: '#98fb98',
paleturquoise: '#afeeee',
palevioletred: '#db7093',
papayawhip: '#ffefd5',
peachpuff: '#ffdab9',
peru: '#cd853f',
pink: '#ffc0cb',
plum: '#dda0dd',
powderblue: '#b0e0e6',
purple: '#800080',
purple2: '#7f007f',
purple3: '#a020f0',
rebeccapurple: '#663399',
red: '#ff0000',
rosybrown: '#bc8f8f',
royalblue: '#4169e1',
saddlebrown: '#8b4513',
salmon: '#fa8072',
sandybrown: '#f4a460',
seagreen: '#2e8b57',
seashell: '#fff5ee',
sienna: '#a0522d',
silver: '#c0c0c0',
skyblue: '#87ceeb',
slateblue: '#6a5acd',
slategray: '#708090',
slategrey: '#708090',
snow: '#fffafa',
springgreen: '#00ff7f',
steelblue: '#4682b4',
tan: '#d2b48c',
teal: '#008080',
thistle: '#d8bfd8',
tomato: '#ff6347',
turquoise: '#40e0d0',
violet: '#ee82ee',
wheat: '#f5deb3',
white: '#ffffff',
whitesmoke: '#f5f5f5',
yellow: '#ffff00',
yellowgreen: '#9acd32'
};
Color.prototype.name = function () {
var hex = rgb2hex(this._rgb, 'rgb');
for (var i = 0, list = Object.keys(w3cx11); i < list.length; i += 1) {
var n = list[i];
if (w3cx11[n] === hex) { return n.toLowerCase(); }
}
return hex;
};
input.format.named = function (name) {
name = name.toLowerCase();
if (w3cx11[name]) { return hex2rgb(w3cx11[name]); }
throw new Error('unknown color name: ' + name);
};
input.autodetect.push({
p: 5,
test: function (h) {
var rest = [], len = arguments.length - 1;
while ( len-- > 0 ) rest[ len ] = arguments[ len + 1 ];
if (!rest.length && type(h) === 'string' && w3cx11[h.toLowerCase()]) {
return 'named';
}
}
});
Color.prototype.alpha = function (a, mutate) {
if ( mutate === void 0 ) mutate = false;
if (a !== undefined && type(a) === 'number') {
if (mutate) {
this._rgb[3] = a;
return this;
}
return new Color([this._rgb[0], this._rgb[1], this._rgb[2], a], 'rgb');
}
return this._rgb[3];
};
Color.prototype.clipped = function () {
return this._rgb._clipped || false;
};
Color.prototype.darken = function (amount) {
if ( amount === void 0 ) amount = 1;
var me = this;
var lab = me.lab();
lab[0] -= labConstants.Kn * amount;
return new Color(lab, 'lab').alpha(me.alpha(), true);
};
Color.prototype.brighten = function (amount) {
if ( amount === void 0 ) amount = 1;
return this.darken(-amount);
};
Color.prototype.darker = Color.prototype.darken;
Color.prototype.brighter = Color.prototype.brighten;
Color.prototype.get = function (mc) {
var ref = mc.split('.');
var mode = ref[0];
var channel = ref[1];
var src = this[mode]();
if (channel) {
var i = mode.indexOf(channel) - (mode.substr(0, 2) === 'ok' ? 2 : 0);
if (i > -1) { return src[i]; }
throw new Error(("unknown channel " + channel + " in mode " + mode));
} else {
return src;
}
};
var pow$6 = Math.pow;
var EPS = 1e-7;
var MAX_ITER = 20;
Color.prototype.luminance = function (lum, mode) {
if ( mode === void 0 ) mode = 'rgb';
if (lum !== undefined && type(lum) === 'number') {
if (lum === 0) {
// return pure black
return new Color([0, 0, 0, this._rgb[3]], 'rgb');
}
if (lum === 1) {
// return pure white
return new Color([255, 255, 255, this._rgb[3]], 'rgb');
}
// compute new color using...
var cur_lum = this.luminance();
var max_iter = MAX_ITER;
var test = function (low, high) {
var mid = low.interpolate(high, 0.5, mode);
var lm = mid.luminance();
if (Math.abs(lum - lm) < EPS || !max_iter--) {
// close enough
return mid;
}
return lm > lum ? test(low, mid) : test(mid, high);
};
var rgb = (
cur_lum > lum
? test(new Color([0, 0, 0]), this)
: test(this, new Color([255, 255, 255]))
).rgb();
return new Color(rgb.concat( [this._rgb[3]]));
}
return rgb2luminance.apply(void 0, this._rgb.slice(0, 3));
};
var rgb2luminance = function (r, g, b) {
// relative luminance
// see http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
r = luminance_x(r);
g = luminance_x(g);
b = luminance_x(b);
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
};
var luminance_x = function (x) {
x /= 255;
return x <= 0.03928 ? x / 12.92 : pow$6((x + 0.055) / 1.055, 2.4);
};
var index = {};
function mix (col1, col2, f) {
if ( f === void 0 ) f = 0.5;
var rest = [], len = arguments.length - 3;
while ( len-- > 0 ) rest[ len ] = arguments[ len + 3 ];
var mode = rest[0] || 'lrgb';
if (!index[mode] && !rest.length) {
// fall back to the first supported mode
mode = Object.keys(index)[0];
}
if (!index[mode]) {
throw new Error(("interpolation mode " + mode + " is not defined"));
}
if (type(col1) !== 'object') { col1 = new Color(col1); }
if (type(col2) !== 'object') { col2 = new Color(col2); }
return index[mode](col1, col2, f).alpha(
col1.alpha() + f * (col2.alpha() - col1.alpha())
);
}
Color.prototype.mix = Color.prototype.interpolate = function (
col2,
f
) {
if ( f === void 0 ) f = 0.5;
var rest = [], len = arguments.length - 2;
while ( len-- > 0 ) rest[ len ] = arguments[ len + 2 ];
return mix.apply(void 0, [ this, col2, f ].concat( rest ));
};
Color.prototype.premultiply = function (mutate) {
if ( mutate === void 0 ) mutate = false;
var rgb = this._rgb;
var a = rgb[3];
if (mutate) {
this._rgb = [rgb[0] * a, rgb[1] * a, rgb[2] * a, a];
return this;
} else {
return new Color([rgb[0] * a, rgb[1] * a, rgb[2] * a, a], 'rgb');
}
};
Color.prototype.saturate = function (amount) {
if ( amount === void 0 ) amount = 1;
var me = this;
var lch = me.lch();
lch[1] += labConstants.Kn * amount;
if (lch[1] < 0) { lch[1] = 0; }
return new Color(lch, 'lch').alpha(me.alpha(), true);
};
Color.prototype.desaturate = function (amount) {
if ( amount === void 0 ) amount = 1;
return this.saturate(-amount);
};
Color.prototype.set = function (mc, value, mutate) {
if ( mutate === void 0 ) mutate = false;
var ref = mc.split('.');
var mode = ref[0];
var channel = ref[1];
var src = this[mode]();
if (channel) {
var i = mode.indexOf(channel) - (mode.substr(0, 2) === 'ok' ? 2 : 0);
if (i > -1) {
if (type(value) == 'string') {
switch (value.charAt(0)) {
case '+':
src[i] += +value;
break;
case '-':
src[i] += +value;
break;
case '*':
src[i] *= +value.substr(1);
break;
case '/':
src[i] /= +value.substr(1);
break;
default:
src[i] = +value;
}
} else if (type(value) === 'number') {
src[i] = value;
} else {
throw new Error("unsupported value for Color.set");
}
var out = new Color(src, mode);
if (mutate) {
this._rgb = out._rgb;
return this;
}
return out;
}
throw new Error(("unknown channel " + channel + " in mode " + mode));
} else {
return src;
}
};
Color.prototype.tint = function (f) {
if ( f === void 0 ) f = 0.5;
var rest = [], len = arguments.length - 1;
while ( len-- > 0 ) rest[ len ] = arguments[ len + 1 ];
return mix.apply(void 0, [ this, 'white', f ].concat( rest ));
};
Color.prototype.shade = function (f) {
if ( f === void 0 ) f = 0.5;
var rest = [], len = arguments.length - 1;
while ( len-- > 0 ) rest[ len ] = arguments[ len + 1 ];
return mix.apply(void 0, [ this, 'black', f ].concat( rest ));
};
var rgb = function (col1, col2, f) {
var xyz0 = col1._rgb;
var xyz1 = col2._rgb;
return new Color(
xyz0[0] + f * (xyz1[0] - xyz0[0]),
xyz0[1] + f * (xyz1[1] - xyz0[1]),
xyz0[2] + f * (xyz1[2] - xyz0[2]),
'rgb'
);
};
// register interpolator
index.rgb = rgb;
var sqrt$2 = Math.sqrt;
var pow$5 = Math.pow;
var lrgb = function (col1, col2, f) {
var ref = col1._rgb;
var x1 = ref[0];
var y1 = ref[1];
var z1 = ref[2];
var ref$1 = col2._rgb;
var x2 = ref$1[0];
var y2 = ref$1[1];
var z2 = ref$1[2];
return new Color(
sqrt$2(pow$5(x1, 2) * (1 - f) + pow$5(x2, 2) * f),
sqrt$2(pow$5(y1, 2) * (1 - f) + pow$5(y2, 2) * f),
sqrt$2(pow$5(z1, 2) * (1 - f) + pow$5(z2, 2) * f),
'rgb'
);
};
// register interpolator
index.lrgb = lrgb;
var lab = function (col1, col2, f) {
var xyz0 = col1.lab();
var xyz1 = col2.lab();
return new Color(
xyz0[0] + f * (xyz1[0] - xyz0[0]),
xyz0[1] + f * (xyz1[1] - xyz0[1]),
xyz0[2] + f * (xyz1[2] - xyz0[2]),
'lab'
);
};
// register interpolator
index.lab = lab;
function interpolate_hsx (col1, col2, f, m) {
var assign, assign$1;
var xyz0, xyz1;
if (m === 'hsl') {
xyz0 = col1.hsl();
xyz1 = col2.hsl();
} else if (m === 'hsv') {
xyz0 = col1.hsv();
xyz1 = col2.hsv();
} else if (m === 'hcg') {
xyz0 = col1.hcg();
xyz1 = col2.hcg();
} else if (m === 'hsi') {
xyz0 = col1.hsi();
xyz1 = col2.hsi();
} else if (m === 'lch' || m === 'hcl') {
m = 'hcl';
xyz0 = col1.hcl();
xyz1 = col2.hcl();
} else if (m === 'oklch') {
xyz0 = col1.oklch().reverse();
xyz1 = col2.oklch().reverse();
}
var hue0, hue1, sat0, sat1, lbv0, lbv1;
if (m.substr(0, 1) === 'h' || m === 'oklch') {
(assign = xyz0, hue0 = assign[0], sat0 = assign[1], lbv0 = assign[2]);
(assign$1 = xyz1, hue1 = assign$1[0], sat1 = assign$1[1], lbv1 = assign$1[2]);
}
var sat, hue, lbv, dh;
if (!isNaN(hue0) && !isNaN(hue1)) {
// both colors have hue
if (hue1 > hue0 && hue1 - hue0 > 180) {
dh = hue1 - (hue0 + 360);
} else if (hue1 < hue0 && hue0 - hue1 > 180) {
dh = hue1 + 360 - hue0;
} else {
dh = hue1 - hue0;
}
hue = hue0 + f * dh;
} else if (!isNaN(hue0)) {
hue = hue0;
if ((lbv1 == 1 || lbv1 == 0) && m != 'hsv') { sat = sat0; }
} else if (!isNaN(hue1)) {
hue = hue1;
if ((lbv0 == 1 || lbv0 == 0) && m != 'hsv') { sat = sat1; }
} else {
hue = Number.NaN;
}
if (sat === undefined) { sat = sat0 + f * (sat1 - sat0); }
lbv = lbv0 + f * (lbv1 - lbv0);
return m === 'oklch'
? new Color([lbv, sat, hue], m)
: new Color([hue, sat, lbv], m);
}
var lch = function (col1, col2, f) {
return interpolate_hsx(col1, col2, f, 'lch');
};
// register interpolator
index.lch = lch;
index.hcl = lch;
var num = function (col1, col2, f) {
var c1 = col1.num();
var c2 = col2.num();
return new Color(c1 + f * (c2 - c1), 'num');
};
// register interpolator
index.num = num;
var hcg = function (col1, col2, f) {
return interpolate_hsx(col1, col2, f, 'hcg');
};
// register interpolator
index.hcg = hcg;
var hsi = function (col1, col2, f) {
return interpolate_hsx(col1, col2, f, 'hsi');
};
// register interpolator
index.hsi = hsi;
var hsl = function (col1, col2, f) {
return interpolate_hsx(col1, col2, f, 'hsl');
};
// register interpolator
index.hsl = hsl;
var hsv = function (col1, col2, f) {
return interpolate_hsx(col1, col2, f, 'hsv');
};
// register interpolator
index.hsv = hsv;
var oklab = function (col1, col2, f) {
var xyz0 = col1.oklab();
var xyz1 = col2.oklab();
return new Color(
xyz0[0] + f * (xyz1[0] - xyz0[0]),
xyz0[1] + f * (xyz1[1] - xyz0[1]),
xyz0[2] + f * (xyz1[2] - xyz0[2]),
'oklab'
);
};
// register interpolator
index.oklab = oklab;
var oklch = function (col1, col2, f) {
return interpolate_hsx(col1, col2, f, 'oklch');
};
// register interpolator
index.oklch = oklch;
var pow$4 = Math.pow;
var sqrt$1 = Math.sqrt;
var PI$1 = Math.PI;
var cos$2 = Math.cos;
var sin$2 = Math.sin;
var atan2$1 = Math.atan2;
function average (colors, mode, weights) {
if ( mode === void 0 ) mode = 'lrgb';
if ( weights === void 0 ) weights = null;
var l = colors.length;
if (!weights) { weights = Array.from(new Array(l)).map(function () { return 1; }); }
// normalize weights
var k =
l /
weights.reduce(function (a, b) {
return a + b;
});
weights.forEach(function (w, i) {
weights[i] *= k;
});
// convert colors to Color objects
colors = colors.map(function (c) { return new Color(c); });
if (mode === 'lrgb') {
return _average_lrgb(colors, weights);
}
var first = colors.shift();
var xyz = first.get(mode);
var cnt = [];
var dx = 0;
var dy = 0;
// initial color
for (var i = 0; i < xyz.length; i++) {
xyz[i] = (xyz[i] || 0) * weights[0];
cnt.push(isNaN(xyz[i]) ? 0 : weights[0]);
if (mode.charAt(i) === 'h' && !isNaN(xyz[i])) {
var A = (xyz[i] / 180) * PI$1;
dx += cos$2(A) * weights[0];
dy += sin$2(A) * weights[0];
}
}
var alpha = first.alpha() * weights[0];
colors.forEach(function (c, ci) {
var xyz2 = c.get(mode);
alpha += c.alpha() * weights[ci + 1];
for (var i = 0; i < xyz.length; i++) {
if (!isNaN(xyz2[i])) {
cnt[i] += weights[ci + 1];
if (mode.charAt(i) === 'h') {
var A = (xyz2[i] / 180) * PI$1;
dx += cos$2(A) * weights[ci + 1];
dy += sin$2(A) * weights[ci + 1];
} else {
xyz[i] += xyz2[i] * weights[ci + 1];
}
}
}
});
for (var i$1 = 0; i$1 < xyz.length; i$1++) {
if (mode.charAt(i$1) === 'h') {
var A$1 = (atan2$1(dy / cnt[i$1], dx / cnt[i$1]) / PI$1) * 180;
while (A$1 < 0) { A$1 += 360; }
while (A$1 >= 360) { A$1 -= 360; }
xyz[i$1] = A$1;
} else {
xyz[i$1] = xyz[i$1] / cnt[i$1];
}
}
alpha /= l;
return new Color(xyz, mode).alpha(alpha > 0.99999 ? 1 : alpha, true);
}
var _average_lrgb = function (colors, weights) {
var l = colors.length;
var xyz = [0, 0, 0, 0];
for (var i = 0; i < colors.length; i++) {
var col = colors[i];
var f = weights[i] / l;
var rgb = col._rgb;
xyz[0] += pow$4(rgb[0], 2) * f;
xyz[1] += pow$4(rgb[1], 2) * f;
xyz[2] += pow$4(rgb[2], 2) * f;
xyz[3] += rgb[3] * f;
}
xyz[0] = sqrt$1(xyz[0]);
xyz[1] = sqrt$1(xyz[1]);
xyz[2] = sqrt$1(xyz[2]);
if (xyz[3] > 0.9999999) { xyz[3] = 1; }
return new Color(clip_rgb(xyz));
};
// minimal multi-purpose interface
var pow$3 = Math.pow;
function scale (colors) {
// constructor
var _mode = 'rgb';
var _nacol = chroma('#ccc');
var _spread = 0;
// const _fixed = false;
var _positions = [0, 1];
var _domain = [0, 1];
var _pos = [];
var _padding = [0, 0];
var _classes = false;
var _colors = [];
var _out = false;
var _min = 0;
var _max = 1;
var _correctLightness = false;
var _colorCache = {};
var _useCache = true;
var _gamma = 1;
// private methods
var setColors = function (colors) {
colors = colors || ['#fff', '#000'];
if (
colors &&
type(colors) === 'string' &&
chroma.brewer &&
chroma.brewer[colors.toLowerCase()]
) {
colors = chroma.brewer[colors.toLowerCase()];
}
if (type(colors) === 'array') {
// handle single color
if (colors.length === 1) {
colors = [colors[0], colors[0]];
}
// make a copy of the colors
colors = colors.slice(0);
// convert to chroma classes
for (var c = 0; c < colors.length; c++) {
colors[c] = chroma(colors[c]);
}
// auto-fill color position
_pos.length = 0;
for (var c$1 = 0; c$1 < colors.length; c$1++) {
_pos.push(c$1 / (colors.length - 1));
}
}
resetCache();
return (_colors = colors);
};
var getClass = function (value) {
if (_classes != null) {
var n = _classes.length - 1;
var i = 0;
while (i < n && value >= _classes[i]) {
i++;
}
return i - 1;
}
return 0;
};
var tMapLightness = function (t) { return t; };
var tMapDomain = function (t) { return t; };
// const classifyValue = function(value) {
// let val = value;
// if (_classes.length > 2) {
// const n = _classes.length-1;
// const i = getClass(value);
// const minc = _classes[0] + ((_classes[1]-_classes[0]) * (0 + (_spread * 0.5))); // center of 1st class
// const maxc = _classes[n-1] + ((_classes[n]-_classes[n-1]) * (1 - (_spread * 0.5))); // center of last class
// val = _min + ((((_classes[i] + ((_classes[i+1] - _classes[i]) * 0.5)) - minc) / (maxc-minc)) * (_max - _min));
// }
// return val;
// };
var getColor = function (val, bypassMap) {
var col, t;
if (bypassMap == null) {
bypassMap = false;
}
if (isNaN(val) || val === null) {
return _nacol;
}
if (!bypassMap) {
if (_classes && _classes.length > 2) {
// find the class
var c = getClass(val);
t = c / (_classes.length - 2);
} else if (_max !== _min) {
// just interpolate between min/max
t = (val - _min) / (_max - _min);
} else {
t = 1;
}
} else {
t = val;
}
// domain map
t = tMapDomain(t);
if (!bypassMap) {
t = tMapLightness(t); // lightness correction
}
if (_gamma !== 1) {
t = pow$3(t, _gamma);
}
t = _padding[0] + t * (1 - _padding[0] - _padding[1]);
t = limit(t, 0, 1);
var k = Math.floor(t * 10000);
if (_useCache && _colorCache[k]) {
col = _colorCache[k];
} else {
if (type(_colors) === 'array') {
//for i in [0.._pos.length-1]
for (var i = 0; i < _pos.length; i++) {
var p = _pos[i];
if (t <= p) {
col = _colors[i];
break;
}
if (t >= p && i === _pos.length - 1) {
col = _colors[i];
break;
}
if (t > p && t < _pos[i + 1]) {
t = (t - p) / (_pos[i + 1] - p);
col = chroma.interpolate(
_colors[i],
_colors[i + 1],
t,
_mode
);
break;
}
}
} else if (type(_colors) === 'function') {
col = _colors(t);
}
if (_useCache) {
_colorCache[k] = col;
}
}
return col;
};
var resetCache = function () { return (_colorCache = {}); };
setColors(colors);
// public interface
var f = function (v) {
var c = chroma(getColor(v));
if (_out && c[_out]) {
return c[_out]();
} else {
return c;
}
};
f.classes = function (classes) {
if (classes != null) {
if (type(classes) === 'array') {
_classes = classes;
_positions = [classes[0], classes[classes.length - 1]];
} else {
var d = chroma.analyze(_positions);
if (classes === 0) {
_classes = [d.min, d.max];
} else {
_classes = chroma.limits(d, 'e', classes);
}
}
return f;
}
return _classes;
};
f.domain = function (domain) {
if (!arguments.length) {
// return original domain
return _domain;
}
// store original domain so we can return it later
_domain = domain.slice(0);
_min = domain[0];
_max = domain[domain.length - 1];
_pos = [];
var k = _colors.length;
if (domain.length === k && _min !== _max) {
// update positions
for (var i = 0, list = Array.from(domain); i < list.length; i += 1) {
var d = list[i];
_pos.push((d - _min) / (_max - _min));
}
} else {
for (var c = 0; c < k; c++) {
_pos.push(c / (k - 1));
}
if (domain.length > 2) {
// set domain map
var tOut = domain.map(function (d, i) { return i / (domain.length - 1); });
var tBreaks = domain.map(function (d) { return (d - _min) / (_max - _min); });
if (!tBreaks.every(function (val, i) { return tOut[i] === val; })) {
tMapDomain = function (t) {
if (t <= 0 || t >= 1) { return t; }
var i = 0;
while (t >= tBreaks[i + 1]) { i++; }
var f =
(t - tBreaks[i]) / (tBreaks[i + 1] - tBreaks[i]);
var out = tOut[i] + f * (tOut[i + 1] - tOut[i]);
return out;
};
}
}
}
_positions = [_min, _max];
return f;
};
f.mode = function (_m) {
if (!arguments.length) {
return _mode;
}
_mode = _m;
resetCache();
return f;
};
f.range = function (colors, _pos) {
setColors(colors);
return f;
};
f.out = function (_o) {
_out = _o;
return f;
};
f.spread = function (val) {
if (!arguments.length) {
return _spread;
}
_spread = val;
return f;
};
f.correctLightness = function (v) {
if (v == null) {
v = true;
}
_correctLightness = v;
resetCache();
if (_correctLightness) {
tMapLightness = function (t) {
var L0 = getColor(0, true).lab()[0];
var L1 = getColor(1, true).lab()[0];
var pol = L0 > L1;
var L_actual = getColor(t, true).lab()[0];
var L_ideal = L0 + (L1 - L0) * t;
var L_diff = L_actual - L_ideal;
var t0 = 0;
var t1 = 1;
var max_iter = 20;
while (Math.abs(L_diff) > 1e-2 && max_iter-- > 0) {
(function () {
if (pol) {
L_diff *= -1;
}
if (L_diff < 0) {
t0 = t;
t += (t1 - t) * 0.5;
} else {
t1 = t;
t += (t0 - t) * 0.5;
}
L_actual = getColor(t, true).lab()[0];
return (L_diff = L_actual - L_ideal);
})();
}
return t;
};
} else {
tMapLightness = function (t) { return t; };
}
return f;
};
f.padding = function (p) {
if (p != null) {
if (type(p) === 'number') {
p = [p, p];
}
_padding = p;
return f;
} else {
return _padding;
}
};
f.colors = function (numColors, out) {
// If no arguments are given, return the original colors that were provided
if (arguments.length < 2) {
out = 'hex';
}
var result = [];
if (arguments.length === 0) {
result = _colors.slice(0);
} else if (numColors === 1) {
result = [f(0.5)];
} else if (numColors > 1) {
var dm = _positions[0];
var dd = _positions[1] - dm;
result = __range__(0, numColors).map(function (i) { return f(dm + (i / (numColors - 1)) * dd); }
);
} else {
// returns all colors based on the defined classes
colors = [];
var samples = [];
if (_classes && _classes.length > 2) {
for (
var i = 1, end = _classes.length, asc = 1 <= end;
asc ? i < end : i > end;
asc ? i++ : i--
) {
samples.push((_classes[i - 1] + _classes[i]) * 0.5);
}
} else {
samples = _positions;
}
result = samples.map(function (v) { return f(v); });
}
if (chroma[out]) {
result = result.map(function (c) { return c[out](); });
}
return result;
};
f.cache = function (c) {
if (c != null) {
_useCache = c;
return f;
} else {
return _useCache;
}
};
f.gamma = function (g) {
if (g != null) {
_gamma = g;
return f;
} else {
return _gamma;
}
};
f.nodata = function (d) {
if (d != null) {
_nacol = chroma(d);
return f;
} else {
return _nacol;
}
};
return f;
}
function __range__(left, right, inclusive) {
var range = [];
var ascending = left < right;
var end = right ;
for (var i = left; ascending ? i < end : i > end; ascending ? i++ : i--) {
range.push(i);
}
return range;
}
//
// interpolates between a set of colors uzing a bezier spline
//
// nth row of the pascal triangle
var binom_row = function (n) {
var row = [1, 1];
for (var i = 1; i < n; i++) {
var newrow = [1];
for (var j = 1; j <= row.length; j++) {
newrow[j] = (row[j] || 0) + row[j - 1];
}
row = newrow;
}
return row;
};
var bezier = function (colors) {
var assign, assign$1, assign$2;
var I, lab0, lab1, lab2;
colors = colors.map(function (c) { return new Color(c); });
if (colors.length === 2) {
// linear interpolation
(assign = colors.map(function (c) { return c.lab(); }), lab0 = assign[0], lab1 = assign[1]);
I = function (t) {
var lab = [0, 1, 2].map(function (i) { return lab0[i] + t * (lab1[i] - lab0[i]); });
return new Color(lab, 'lab');
};
} else if (colors.length === 3) {
// quadratic bezier interpolation
(assign$1 = colors.map(function (c) { return c.lab(); }), lab0 = assign$1[0], lab1 = assign$1[1], lab2 = assign$1[2]);
I = function (t) {
var lab = [0, 1, 2].map(
function (i) { return (1 - t) * (1 - t) * lab0[i] +
2 * (1 - t) * t * lab1[i] +
t * t * lab2[i]; }
);
return new Color(lab, 'lab');
};
} else if (colors.length === 4) {
// cubic bezier interpolation
var lab3;
(assign$2 = colors.map(function (c) { return c.lab(); }), lab0 = assign$2[0], lab1 = assign$2[1], lab2 = assign$2[2], lab3 = assign$2[3]);
I = function (t) {
var lab = [0, 1, 2].map(
function (i) { return (1 - t) * (1 - t) * (1 - t) * lab0[i] +
3 * (1 - t) * (1 - t) * t * lab1[i] +
3 * (1 - t) * t * t * lab2[i] +
t * t * t * lab3[i]; }
);
return new Color(lab, 'lab');
};
} else if (colors.length >= 5) {
// general case (degree n bezier)
var labs, row, n;
labs = colors.map(function (c) { return c.lab(); });
n = colors.length - 1;
row = binom_row(n);
I = function (t) {
var u = 1 - t;
var lab = [0, 1, 2].map(function (i) { return labs.reduce(
function (sum, el, j) { return sum + row[j] * Math.pow( u, (n - j) ) * Math.pow( t, j ) * el[i]; },
0
); }
);
return new Color(lab, 'lab');
};
} else {
throw new RangeError('No point in running bezier with only one color.');
}
return I;
};
function bezier$1 (colors) {
var f = bezier(colors);
f.scale = function () { return scale(f); };
return f;
}
/*
* interpolates between a set of colors uzing a bezier spline
* blend mode formulas taken from https://web.archive.org/web/20180110014946/http://www.venture-ware.com/kevin/coding/lets-learn-math-photoshop-blend-modes/
*/
var blend = function (bottom, top, mode) {
if (!blend[mode]) {
throw new Error('unknown blend mode ' + mode);
}
return blend[mode](bottom, top);
};
var blend_f = function (f) { return function (bottom, top) {
var c0 = chroma(top).rgb();
var c1 = chroma(bottom).rgb();
return chroma.rgb(f(c0, c1));
}; };
var each = function (f) { return function (c0, c1) {
var out = [];
out[0] = f(c0[0], c1[0]);
out[1] = f(c0[1], c1[1]);
out[2] = f(c0[2], c1[2]);
return out;
}; };
var normal = function (a) { return a; };
var multiply = function (a, b) { return (a * b) / 255; };
var darken = function (a, b) { return (a > b ? b : a); };
var lighten = function (a, b) { return (a > b ? a : b); };
var screen = function (a, b) { return 255 * (1 - (1 - a / 255) * (1 - b / 255)); };
var overlay = function (a, b) { return b < 128 ? (2 * a * b) / 255 : 255 * (1 - 2 * (1 - a / 255) * (1 - b / 255)); };
var burn = function (a, b) { return 255 * (1 - (1 - b / 255) / (a / 255)); };
var dodge = function (a, b) {
if (a === 255) { return 255; }
a = (255 * (b / 255)) / (1 - a / 255);
return a > 255 ? 255 : a;
};
// # add = (a,b) ->
// # if (a + b > 255) then 255 else a + b
blend.normal = blend_f(each(normal));
blend.multiply = blend_f(each(multiply));
blend.screen = blend_f(each(screen));
blend.overlay = blend_f(each(overlay));
blend.darken = blend_f(each(darken));
blend.lighten = blend_f(each(lighten));
blend.dodge = blend_f(each(dodge));
blend.burn = blend_f(each(burn));
// cubehelix interpolation
// based on D.A. Green "A colour scheme for the display of astronomical intensity images"
// http://astron-soc.in/bulletin/11June/289392011.pdf
var pow$2 = Math.pow;
var sin$1 = Math.sin;
var cos$1 = Math.cos;
function cubehelix (
start,
rotations,
hue,
gamma,
lightness
) {
if ( start === void 0 ) start = 300;
if ( rotations === void 0 ) rotations = -1.5;
if ( hue === void 0 ) hue = 1;
if ( gamma === void 0 ) gamma = 1;
if ( lightness === void 0 ) lightness = [0, 1];
var dh = 0,
dl;
if (type(lightness) === 'array') {
dl = lightness[1] - lightness[0];
} else {
dl = 0;
lightness = [lightness, lightness];
}
var f = function (fract) {
var a = TWOPI * ((start + 120) / 360 + rotations * fract);
var l = pow$2(lightness[0] + dl * fract, gamma);
var h = dh !== 0 ? hue[0] + fract * dh : hue;
var amp = (h * l * (1 - l)) / 2;
var cos_a = cos$1(a);
var sin_a = sin$1(a);
var r = l + amp * (-0.14861 * cos_a + 1.78277 * sin_a);
var g = l + amp * (-0.29227 * cos_a - 0.90649 * sin_a);
var b = l + amp * (1.97294 * cos_a);
return chroma(clip_rgb([r * 255, g * 255, b * 255, 1]));
};
f.start = function (s) {
if (s == null) {
return start;
}
start = s;
return f;
};
f.rotations = function (r) {
if (r == null) {
return rotations;
}
rotations = r;
return f;
};
f.gamma = function (g) {
if (g == null) {
return gamma;
}
gamma = g;
return f;
};
f.hue = function (h) {
if (h == null) {
return hue;
}
hue = h;
if (type(hue) === 'array') {
dh = hue[1] - hue[0];
if (dh === 0) {
hue = hue[1];
}
} else {
dh = 0;
}
return f;
};
f.lightness = function (h) {
if (h == null) {
return lightness;
}
if (type(h) === 'array') {
lightness = h;
dl = h[1] - h[0];
} else {
lightness = [h, h];
dl = 0;
}
return f;
};
f.scale = function () { return chroma.scale(f); };
f.hue(hue);
return f;
}
var digits = '0123456789abcdef';
var floor$1 = Math.floor;
var random = Math.random;
/**
* Generates a random color.
* @param {() => number} rng - A random number generator function.
*/
function random$1 (rng) {
gitextract_vl9uye1t/ ├── .changeset/ │ ├── README.md │ └── config.json ├── .github/ │ ├── CODEOWNERS │ ├── FUNDING.yml │ └── workflows/ │ └── ci.yml ├── .gitignore ├── .husky/ │ └── pre-commit ├── .npmignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── dist/ │ ├── chroma-light.cjs │ ├── chroma-light.min.cjs │ ├── chroma.cjs │ └── chroma.min.cjs ├── docs/ │ ├── Makefile │ ├── bin/ │ │ └── post-process │ ├── index.html │ ├── libs/ │ │ ├── chroma-light.cjs │ │ ├── chroma-light.min.cjs │ │ ├── chroma.cjs │ │ ├── chroma.min.cjs │ │ └── codemirror/ │ │ ├── lib/ │ │ │ ├── codemirror.css │ │ │ └── codemirror.js │ │ └── mode/ │ │ ├── javascript/ │ │ │ ├── index.html │ │ │ ├── javascript.js │ │ │ ├── json-ld.html │ │ │ ├── test.js │ │ │ └── typescript.html │ │ └── shell/ │ │ └── shell.js │ └── src/ │ ├── footer.inc.html │ ├── index.css │ └── index.md ├── eslint.config.mjs ├── index-light.js ├── index.js ├── index.umd.js ├── index.umd.light.js ├── package.json ├── prettier.config.js ├── readme.md ├── rollup.config.js ├── src/ │ ├── Color.js │ ├── chroma.js │ ├── colors/ │ │ ├── colorbrewer.js │ │ └── w3cx11.js │ ├── generator/ │ │ ├── average.js │ │ ├── bezier.js │ │ ├── blend.js │ │ ├── cubehelix.js │ │ ├── mix.js │ │ ├── random.js │ │ └── scale.js │ ├── interpolator/ │ │ ├── _hsx.js │ │ ├── hcg.js │ │ ├── hsi.js │ │ ├── hsl.js │ │ ├── hsv.js │ │ ├── index.js │ │ ├── lab.js │ │ ├── lch.js │ │ ├── lrgb.js │ │ ├── num.js │ │ ├── oklab.js │ │ ├── oklch.js │ │ └── rgb.js │ ├── io/ │ │ ├── cmyk/ │ │ │ ├── cmyk2rgb.js │ │ │ ├── index.js │ │ │ └── rgb2cmyk.js │ │ ├── css/ │ │ │ ├── css2rgb.js │ │ │ ├── hsl2css.js │ │ │ ├── index.js │ │ │ ├── lab2css.js │ │ │ ├── lch2css.js │ │ │ ├── oklab2css.js │ │ │ ├── oklch2css.js │ │ │ └── rgb2css.js │ │ ├── delta-e.coffee │ │ ├── distance.coffee │ │ ├── gl/ │ │ │ └── index.js │ │ ├── hcg/ │ │ │ ├── hcg2rgb.js │ │ │ ├── index.js │ │ │ └── rgb2hcg.js │ │ ├── hex/ │ │ │ ├── hex2rgb.js │ │ │ ├── index.js │ │ │ └── rgb2hex.js │ │ ├── hsi/ │ │ │ ├── hsi2rgb.js │ │ │ ├── index.js │ │ │ └── rgb2hsi.js │ │ ├── hsl/ │ │ │ ├── hsl2rgb.js │ │ │ ├── index.js │ │ │ └── rgb2hsl.js │ │ ├── hsv/ │ │ │ ├── hsv2rgb.js │ │ │ ├── index.js │ │ │ └── rgb2hsv.js │ │ ├── input.js │ │ ├── lab/ │ │ │ ├── index.js │ │ │ ├── lab-constants.js │ │ │ ├── lab2rgb.js │ │ │ └── rgb2lab.js │ │ ├── lch/ │ │ │ ├── hcl2rgb.js │ │ │ ├── index.js │ │ │ ├── lab2lch.js │ │ │ ├── lch2lab.js │ │ │ ├── lch2rgb.js │ │ │ └── rgb2lch.js │ │ ├── named/ │ │ │ └── index.js │ │ ├── num/ │ │ │ ├── index.js │ │ │ ├── num2rgb.js │ │ │ └── rgb2num.js │ │ ├── oklab/ │ │ │ ├── index.js │ │ │ ├── oklab2rgb.js │ │ │ └── rgb2oklab.js │ │ ├── oklch/ │ │ │ ├── index.js │ │ │ ├── oklch2rgb.js │ │ │ └── rgb2oklch.js │ │ ├── rgb/ │ │ │ └── index.js │ │ └── temp/ │ │ ├── index.js │ │ ├── rgb2temperature.js │ │ └── temperature2rgb.js │ ├── ops/ │ │ ├── alpha.js │ │ ├── clipped.js │ │ ├── darken.js │ │ ├── get.js │ │ ├── luminance.js │ │ ├── mix.js │ │ ├── premultiply.js │ │ ├── saturate.js │ │ ├── set.js │ │ └── shade.js │ ├── utils/ │ │ ├── analyze.js │ │ ├── clip_rgb.js │ │ ├── contrast.js │ │ ├── contrastAPCA.js │ │ ├── delta-e.js │ │ ├── distance.js │ │ ├── index.js │ │ ├── last.js │ │ ├── limit.js │ │ ├── multiply-matrices.js │ │ ├── scales.js │ │ ├── type.js │ │ ├── unpack.js │ │ └── valid.js │ └── version.js ├── test/ │ ├── alpha.test.js │ ├── analyze.test.js │ ├── autodetect.test.js │ ├── average.test.js │ ├── bezier.test.js │ ├── blend.test.js │ ├── color.test.js │ ├── colorbrewer.test.js │ ├── contrast.test.js │ ├── converters.test.js │ ├── cubehelix.test.js │ ├── delta-e.test.js │ ├── docs/ │ │ └── index.test.js │ ├── html/ │ │ ├── bezier.html │ │ ├── blend.html │ │ ├── colorscales.html │ │ ├── cubehelix.html │ │ └── luminance.html │ ├── io/ │ │ ├── cmyk2rgb.test.js │ │ ├── css2rgb.test.js │ │ ├── hcg2rgb.test.js │ │ ├── hex2rgb.test.js │ │ ├── hsi2rgb.test.js │ │ ├── hsl2rgb.test.js │ │ ├── hsv2rgb.test.js │ │ ├── lab2lch.test.js │ │ ├── lab2rgb.test.js │ │ ├── lch2lab.test.js │ │ ├── lch2rgb.test.js │ │ ├── num2rgb.test.js │ │ ├── oklab2rgb.test.js │ │ ├── oklch2rgb.test.js │ │ ├── rgb2cmyk.test.js │ │ ├── rgb2css.test.js │ │ ├── rgb2hex.test.js │ │ ├── rgb2hsi.test.js │ │ ├── rgb2hsv.test.js │ │ ├── rgb2lab.test.js │ │ ├── rgb2lch.test.js │ │ ├── rgb2oklab.test.js │ │ └── rgb2oklch.test.js │ ├── lch.test.js │ ├── limits.test.js │ ├── luminance.test.js │ ├── manipulate.test.js │ ├── misc.test.js │ ├── mix.test.js │ ├── num.test.js │ ├── premultiply.test.js │ ├── random.test.js │ ├── scale.lcorrection.test.js │ ├── scales.test.js │ ├── temperature2rgb.test.js │ ├── unpack.test.js │ └── valid.test.js └── vitest.config.mjs
SYMBOL INDEX (604 symbols across 29 files)
FILE: dist/chroma-light.cjs
function limit (line 67) | function limit (x, low, high) {
function clip_rgb (line 73) | function clip_rgb (rgb) {
function type (line 104) | function type (obj) {
function unpack (line 108) | function unpack (args, keyOrder) {
function last (line 126) | function last (args) {
function setLabWhitePoint (line 405) | function setLabWhitePoint(name) {
function getLabWhitePoint (line 415) | function getLabWhitePoint() {
function xyz2lab (line 439) | function xyz2lab(x, y, z) {
function gammaAdjustSRGB (line 456) | function gammaAdjustSRGB(companded) {
function multiplyMatrices (line 568) | function multiplyMatrices(A, B) {
function XYZ_to_OKLab (line 618) | function XYZ_to_OKLab(XYZ) {
function OKLab_to_XYZ (line 963) | function OKLab_to_XYZ(OKLab) {
function mix (line 1561) | function mix (col1, col2, f) {
function valid (line 1690) | function valid () {
FILE: dist/chroma-light.min.cjs
function n (line 58) | function n(n,e,o){return void 0===o&&(o=1),t(r(e,n),o)}
function u (line 58) | function u(t){return e[Object.prototype.toString.call(t)]||"object"}
function l (line 58) | function l(t,r){return void 0===r&&(r=null),t.length>=3?Array.prototype....
function c (line 58) | function c(t){if(t.length<2)return null;var r=t.length-1;return"string"=...
function x (line 58) | function x(t){var r=k.get(String(t).toLowerCase());if(!r)throw new Error...
function j (line 58) | function j(){return M.labWhitePoint}
function E (line 58) | function E(t){var r=Math.sign(t);return((t=Math.abs(t))<=.04045?t/12.92:...
function Z (line 58) | function Z(t,r){var n=t.length;Array.isArray(t[0])||(t=[t]),Array.isArra...
function _t (line 58) | function _t(t,r,n){void 0===n&&(n=.5);for(var e=[],o=arguments.length-3;...
FILE: dist/chroma.cjs
function limit (line 67) | function limit (x, low, high) {
function clip_rgb (line 74) | function clip_rgb (rgb) {
function type (line 105) | function type (obj) {
function unpack (line 109) | function unpack (args, keyOrder) {
function last (line 127) | function last (args) {
function reverse3 (line 152) | function reverse3(arr) {
function setLabWhitePoint (line 486) | function setLabWhitePoint(name) {
function getLabWhitePoint (line 496) | function getLabWhitePoint() {
function xyz2lab (line 520) | function xyz2lab(x, y, z) {
function gammaAdjustSRGB (line 537) | function gammaAdjustSRGB(companded) {
function multiplyMatrices (line 649) | function multiplyMatrices(A, B) {
function XYZ_to_OKLab (line 699) | function XYZ_to_OKLab(XYZ) {
function OKLab_to_XYZ (line 1044) | function OKLab_to_XYZ(OKLab) {
function mix (line 2468) | function mix (col1, col2, f) {
function interpolate_hsx (line 2640) | function interpolate_hsx (col1, col2, f, m) {
function average (line 2773) | function average (colors, mode, weights) {
function scale (line 2864) | function scale (colors) {
function __range__ (line 3246) | function __range__(left, right, inclusive) {
function bezier$1 (line 3331) | function bezier$1 (colors) {
function cubehelix (line 3396) | function cubehelix (
function random$1 (line 3492) | function random$1 (rng) {
function analyze (line 3507) | function analyze(data, key) {
function limits (line 3538) | function limits(data, mode, num) {
function contrast (line 3701) | function contrast (a, b) {
function contrastAPCA (line 3733) | function contrastAPCA (text, bg) {
function lum (line 3768) | function lum(r, g, b) {
function deltaE (line 3787) | function deltaE (a, b, Kl, Kc, Kh) {
function distance (line 3858) | function distance (a, b, mode) {
function valid (line 3875) | function valid () {
FILE: dist/chroma.min.cjs
function e (line 58) | function e(e,t,a){return void 0===t&&(t=0),void 0===a&&(a=1),r(n(t,e),a)}
function t (line 58) | function t(r){r._clipped=!1,r._unclipped=r.slice(0);for(var n=0;n<=3;n++...
function c (line 58) | function c(r){return a[Object.prototype.toString.call(r)]||"object"}
function i (line 58) | function i(r,n){return void 0===n&&(n=null),r.length>=3?Array.prototype....
function l (line 58) | function l(r){if(r.length<2)return null;var n=r.length-1;return"string"=...
function w (line 58) | function w(r){return r.slice(0,3).reverse().concat(r.slice(3))}
function R (line 58) | function R(r){var n=E.get(String(r).toLowerCase());if(!n)throw new Error...
function O (line 58) | function O(){return j.labWhitePoint}
function F (line 58) | function F(r){var n=Math.sign(r);return((r=Math.abs(r))<=.04045?r/12.92:...
function X (line 58) | function X(r,n){var e=r.length;Array.isArray(r[0])||(r=[r]),Array.isArra...
function un (line 58) | function un(r,n,e){void 0===e&&(e=.5);for(var t=[],a=arguments.length-3;...
function hn (line 58) | function hn(r,n,e,t){var a,f,o,u,c,i,l,h,s,d,b,g,v;return"hsl"===t?(o=r....
function kn (line 58) | function kn(r){var n="rgb",t=N("#ccc"),a=0,f=[0,1],o=[0,1],u=[],i=[0,0],...
function Bn (line 58) | function Bn(r,n){void 0===n&&(n=null);var e={min:Number.MAX_VALUE,max:-1...
function Gn (line 58) | function Gn(r,n,e){void 0===n&&(n="equal"),void 0===e&&(e=7),"array"==c(...
function qn (line 72) | function qn(r,n,e){return.2126729*Math.pow(r/255,2.4)+.7151522*Math.pow(...
FILE: docs/libs/chroma-light.cjs
function limit (line 67) | function limit (x, low, high) {
function clip_rgb (line 73) | function clip_rgb (rgb) {
function type (line 104) | function type (obj) {
function unpack (line 108) | function unpack (args, keyOrder) {
function last (line 126) | function last (args) {
function setLabWhitePoint (line 405) | function setLabWhitePoint(name) {
function getLabWhitePoint (line 415) | function getLabWhitePoint() {
function xyz2lab (line 439) | function xyz2lab(x, y, z) {
function gammaAdjustSRGB (line 456) | function gammaAdjustSRGB(companded) {
function multiplyMatrices (line 568) | function multiplyMatrices(A, B) {
function XYZ_to_OKLab (line 618) | function XYZ_to_OKLab(XYZ) {
function OKLab_to_XYZ (line 963) | function OKLab_to_XYZ(OKLab) {
function mix (line 1561) | function mix (col1, col2, f) {
function valid (line 1690) | function valid () {
FILE: docs/libs/chroma-light.min.cjs
function n (line 58) | function n(n,e,o){return void 0===o&&(o=1),t(r(e,n),o)}
function u (line 58) | function u(t){return e[Object.prototype.toString.call(t)]||"object"}
function l (line 58) | function l(t,r){return void 0===r&&(r=null),t.length>=3?Array.prototype....
function c (line 58) | function c(t){if(t.length<2)return null;var r=t.length-1;return"string"=...
function x (line 58) | function x(t){var r=k.get(String(t).toLowerCase());if(!r)throw new Error...
function j (line 58) | function j(){return M.labWhitePoint}
function E (line 58) | function E(t){var r=Math.sign(t);return((t=Math.abs(t))<=.04045?t/12.92:...
function Z (line 58) | function Z(t,r){var n=t.length;Array.isArray(t[0])||(t=[t]),Array.isArra...
function _t (line 58) | function _t(t,r,n){void 0===n&&(n=.5);for(var e=[],o=arguments.length-3;...
FILE: docs/libs/chroma.cjs
function limit (line 67) | function limit (x, low, high) {
function clip_rgb (line 74) | function clip_rgb (rgb) {
function type (line 105) | function type (obj) {
function unpack (line 109) | function unpack (args, keyOrder) {
function last (line 127) | function last (args) {
function reverse3 (line 152) | function reverse3(arr) {
function setLabWhitePoint (line 486) | function setLabWhitePoint(name) {
function getLabWhitePoint (line 496) | function getLabWhitePoint() {
function xyz2lab (line 520) | function xyz2lab(x, y, z) {
function gammaAdjustSRGB (line 537) | function gammaAdjustSRGB(companded) {
function multiplyMatrices (line 649) | function multiplyMatrices(A, B) {
function XYZ_to_OKLab (line 699) | function XYZ_to_OKLab(XYZ) {
function OKLab_to_XYZ (line 1044) | function OKLab_to_XYZ(OKLab) {
function mix (line 2468) | function mix (col1, col2, f) {
function interpolate_hsx (line 2640) | function interpolate_hsx (col1, col2, f, m) {
function average (line 2773) | function average (colors, mode, weights) {
function scale (line 2864) | function scale (colors) {
function __range__ (line 3246) | function __range__(left, right, inclusive) {
function bezier$1 (line 3331) | function bezier$1 (colors) {
function cubehelix (line 3396) | function cubehelix (
function random$1 (line 3492) | function random$1 (rng) {
function analyze (line 3507) | function analyze(data, key) {
function limits (line 3538) | function limits(data, mode, num) {
function contrast (line 3701) | function contrast (a, b) {
function contrastAPCA (line 3733) | function contrastAPCA (text, bg) {
function lum (line 3768) | function lum(r, g, b) {
function deltaE (line 3787) | function deltaE (a, b, Kl, Kc, Kh) {
function distance (line 3858) | function distance (a, b, mode) {
function valid (line 3875) | function valid () {
FILE: docs/libs/chroma.min.cjs
function e (line 58) | function e(e,t,a){return void 0===t&&(t=0),void 0===a&&(a=1),r(n(t,e),a)}
function t (line 58) | function t(r){r._clipped=!1,r._unclipped=r.slice(0);for(var n=0;n<=3;n++...
function c (line 58) | function c(r){return a[Object.prototype.toString.call(r)]||"object"}
function i (line 58) | function i(r,n){return void 0===n&&(n=null),r.length>=3?Array.prototype....
function l (line 58) | function l(r){if(r.length<2)return null;var n=r.length-1;return"string"=...
function w (line 58) | function w(r){return r.slice(0,3).reverse().concat(r.slice(3))}
function R (line 58) | function R(r){var n=E.get(String(r).toLowerCase());if(!n)throw new Error...
function O (line 58) | function O(){return j.labWhitePoint}
function F (line 58) | function F(r){var n=Math.sign(r);return((r=Math.abs(r))<=.04045?r/12.92:...
function X (line 58) | function X(r,n){var e=r.length;Array.isArray(r[0])||(r=[r]),Array.isArra...
function un (line 58) | function un(r,n,e){void 0===e&&(e=.5);for(var t=[],a=arguments.length-3;...
function hn (line 58) | function hn(r,n,e,t){var a,f,o,u,c,i,l,h,s,d,b,g,v;return"hsl"===t?(o=r....
function kn (line 58) | function kn(r){var n="rgb",t=N("#ccc"),a=0,f=[0,1],o=[0,1],u=[],i=[0,0],...
function Bn (line 58) | function Bn(r,n){void 0===n&&(n=null);var e={min:Number.MAX_VALUE,max:-1...
function Gn (line 58) | function Gn(r,n,e){void 0===n&&(n="equal"),void 0===e&&(e=7),"array"==c(...
function qn (line 72) | function qn(r,n,e){return.2126729*Math.pow(r/255,2.4)+.7151522*Math.pow(...
FILE: docs/libs/codemirror/lib/codemirror.js
function CodeMirror (line 59) | function CodeMirror(place, options) {
function Display (line 133) | function Display(place, doc, input) {
function loadMode (line 235) | function loadMode(cm) {
function resetModeState (line 240) | function resetModeState(cm) {
function wrappingChanged (line 251) | function wrappingChanged(cm) {
function estimateHeight (line 269) | function estimateHeight(cm) {
function estimateLineHeights (line 287) | function estimateLineHeights(cm) {
function themeChanged (line 295) | function themeChanged(cm) {
function guttersChanged (line 301) | function guttersChanged(cm) {
function updateGutters (line 309) | function updateGutters(cm) {
function updateGutterSpace (line 324) | function updateGutterSpace(cm) {
function lineLength (line 332) | function lineLength(line) {
function findMaxLine (line 351) | function findMaxLine(cm) {
function setGuttersForLineNumbers (line 367) | function setGuttersForLineNumbers(options) {
function measureForScrollbars (line 381) | function measureForScrollbars(cm) {
function NativeScrollbars (line 397) | function NativeScrollbars(place, scroll, cm) {
function NullScrollbars (line 476) | function NullScrollbars() {}
function initScrollbars (line 487) | function initScrollbars(cm) {
function updateScrollbars (line 509) | function updateScrollbars(cm, measure) {
function updateScrollbarsInner (line 523) | function updateScrollbarsInner(cm, measure) {
function visibleLines (line 545) | function visibleLines(display, doc, viewport) {
function alignHorizontally (line 570) | function alignHorizontally(cm) {
function maybeUpdateLineNumberWidth (line 589) | function maybeUpdateLineNumberWidth(cm) {
function lineNumberFor (line 607) | function lineNumberFor(options, i) {
function compensateForHScroll (line 614) | function compensateForHScroll(display) {
function DisplayUpdate (line 620) | function DisplayUpdate(cm, viewport, force) {
function maybeClipScrollbars (line 644) | function maybeClipScrollbars(cm) {
function updateDisplayIfNeeded (line 658) | function updateDisplayIfNeeded(cm, update) {
function postUpdateDisplay (line 730) | function postUpdateDisplay(cm, update) {
function updateDisplaySimple (line 758) | function updateDisplaySimple(cm, viewport) {
function setDocumentHeight (line 771) | function setDocumentHeight(cm, measure) {
function updateHeightsInViewport (line 780) | function updateHeightsInViewport(cm) {
function updateWidgetHeight (line 807) | function updateWidgetHeight(line) {
function getDimensions (line 814) | function getDimensions(cm) {
function patchDisplay (line 832) | function patchDisplay(cm, updateNumbersFrom, dims) {
function updateLineForChanges (line 877) | function updateLineForChanges(cm, lineView, lineN, dims) {
function ensureLineWrapped (line 890) | function ensureLineWrapped(lineView) {
function updateLineBackground (line 901) | function updateLineBackground(lineView) {
function getLineContent (line 915) | function getLineContent(cm, lineView) {
function updateLineText (line 928) | function updateLineText(cm, lineView) {
function updateLineClasses (line 943) | function updateLineClasses(lineView) {
function updateLineGutter (line 953) | function updateLineGutter(cm, lineView, lineN, dims) {
function updateLineWidgets (line 983) | function updateLineWidgets(cm, lineView, dims) {
function buildLineElement (line 994) | function buildLineElement(cm, lineView, lineN, dims) {
function insertLineWidgets (line 1008) | function insertLineWidgets(cm, lineView, dims) {
function insertLineWidgetsFor (line 1014) | function insertLineWidgetsFor(cm, line, lineView, dims, allowAbove) {
function positionLineWidget (line 1030) | function positionLineWidget(widget, node, lineView, dims) {
function copyPos (line 1060) | function copyPos(x) {return Pos(x.line, x.ch);}
function maxPos (line 1061) | function maxPos(a, b) { return cmp(a, b) < 0 ? b : a; }
function minPos (line 1062) | function minPos(a, b) { return cmp(a, b) < 0 ? a : b; }
function ensureFocus (line 1066) | function ensureFocus(cm) {
function isReadOnly (line 1070) | function isReadOnly(cm) {
function applyTextInput (line 1079) | function applyTextInput(cm, inserted, deleted, sel, origin) {
function handlePaste (line 1119) | function handlePaste(e, cm) {
function triggerElectric (line 1128) | function triggerElectric(cm, inserted) {
function copyableRanges (line 1152) | function copyableRanges(cm) {
function disableBrowserMagic (line 1163) | function disableBrowserMagic(field) {
function TextareaInput (line 1171) | function TextareaInput(cm) {
function hiddenTextarea (line 1190) | function hiddenTextarea() {
function prepareCopyCut (line 1231) | function prepareCopyCut(e) {
function p (line 1370) | function p() {
function prepareSelectAllHack (line 1473) | function prepareSelectAllHack() {
function rehide (line 1486) | function rehide() {
function ContentEditableInput (line 1526) | function ContentEditableInput(cm) {
function onCopyCut (line 1582) | function onCopyCut(e) {
function poll (line 1709) | function poll() {
function posToDOM (line 1822) | function posToDOM(cm, pos) {
function badPos (line 1838) | function badPos(pos, bad) { if (bad) pos.bad = true; return pos; }
function domToPos (line 1840) | function domToPos(cm, node, offset) {
function locateNodeInLineView (line 1859) | function locateNodeInLineView(lineView, node, offset) {
function domTextBetween (line 1914) | function domTextBetween(cm, from, to, fromLine, toLine) {
function Selection (line 1964) | function Selection(ranges, primIndex) {
function Range (line 2001) | function Range(anchor, head) {
function normalizeSelection (line 2016) | function normalizeSelection(ranges, primIndex) {
function simpleSelection (line 2032) | function simpleSelection(anchor, head) {
function clipLine (line 2038) | function clipLine(doc, n) {return Math.max(doc.first, Math.min(n, doc.fi...
function clipPos (line 2039) | function clipPos(doc, pos) {
function clipToLen (line 2045) | function clipToLen(pos, linelen) {
function isLine (line 2051) | function isLine(doc, l) {return l >= doc.first && l < doc.first + doc.si...
function clipPosArray (line 2052) | function clipPosArray(doc, array) {
function extendRange (line 2067) | function extendRange(doc, range, head, other) {
function extendSelection (line 2086) | function extendSelection(doc, head, other, options) {
function extendSelections (line 2092) | function extendSelections(doc, heads, options) {
function replaceOneSelection (line 2100) | function replaceOneSelection(doc, i, range, options) {
function setSimpleSelection (line 2107) | function setSimpleSelection(doc, anchor, head, options) {
function filterSelectionChange (line 2113) | function filterSelectionChange(doc, sel) {
function setSelectionReplaceHistory (line 2129) | function setSelectionReplaceHistory(doc, sel, options) {
function setSelection (line 2140) | function setSelection(doc, sel, options) {
function setSelectionNoUndo (line 2145) | function setSelectionNoUndo(doc, sel, options) {
function setSelectionInner (line 2157) | function setSelectionInner(doc, sel) {
function reCheckSelection (line 2171) | function reCheckSelection(doc) {
function skipAtomicInSelection (line 2177) | function skipAtomicInSelection(doc, sel, bias, mayClear) {
function skipAtomic (line 2192) | function skipAtomic(doc, pos, bias, mayClear) {
function updateSelection (line 2244) | function updateSelection(cm) {
function prepareSelection (line 2248) | function prepareSelection(cm, primary) {
function drawSelectionCursor (line 2266) | function drawSelectionCursor(cm, range, output) {
function drawSelectionRange (line 2285) | function drawSelectionRange(cm, range, output) {
function restartBlink (line 2360) | function restartBlink(cm) {
function startWorker (line 2376) | function startWorker(cm, time) {
function highlightWorker (line 2381) | function highlightWorker(cm) {
function findStartLine (line 2423) | function findStartLine(cm, n, precise) {
function getStateBefore (line 2439) | function getStateBefore(cm, n, precise) {
function paddingTop (line 2457) | function paddingTop(display) {return display.lineSpace.offsetTop;}
function paddingVert (line 2458) | function paddingVert(display) {return display.mover.offsetHeight - displ...
function paddingH (line 2459) | function paddingH(display) {
function scrollGap (line 2468) | function scrollGap(cm) { return scrollerGap - cm.display.nativeBarWidth; }
function displayWidth (line 2469) | function displayWidth(cm) {
function displayHeight (line 2472) | function displayHeight(cm) {
function ensureLineHeights (line 2480) | function ensureLineHeights(cm, lineView, rect) {
function mapFromLineView (line 2501) | function mapFromLineView(lineView, line, lineN) {
function updateExternalMeasurement (line 2514) | function updateExternalMeasurement(cm, line) {
function measureChar (line 2527) | function measureChar(cm, line, ch, bias) {
function findViewForLine (line 2532) | function findViewForLine(cm, lineN) {
function prepareMeasureForLine (line 2545) | function prepareMeasureForLine(cm, line) {
function measureCharPrepared (line 2565) | function measureCharPrepared(cm, prepared, ch, bias, varHeight) {
function nodeAndOffsetInLineMap (line 2587) | function nodeAndOffsetInLineMap(map, ch, bias) {
function measureCharInner (line 2624) | function measureCharInner(cm, prepared, ch, bias) {
function maybeUpdateRectForZooming (line 2683) | function maybeUpdateRectForZooming(measure, rect) {
function clearLineMeasurementCacheFor (line 2693) | function clearLineMeasurementCacheFor(lineView) {
function clearLineMeasurementCache (line 2702) | function clearLineMeasurementCache(cm) {
function clearCaches (line 2709) | function clearCaches(cm) {
function pageScrollX (line 2716) | function pageScrollX() { return window.pageXOffset || (document.document...
function pageScrollY (line 2717) | function pageScrollY() { return window.pageYOffset || (document.document...
function intoCoordSystem (line 2723) | function intoCoordSystem(cm, lineObj, rect, context) {
function fromCoordSystem (line 2745) | function fromCoordSystem(cm, coords, context) {
function charCoords (line 2762) | function charCoords(cm, pos, context, lineObj, bias) {
function cursorCoords (line 2770) | function cursorCoords(cm, pos, context, lineObj, preparedMeasure, varHei...
function estimateCoords (line 2802) | function estimateCoords(cm, pos) {
function PosWithInfo (line 2816) | function PosWithInfo(line, ch, outside, xRel) {
function coordsChar (line 2825) | function coordsChar(cm, x, y) {
function coordsCharInner (line 2846) | function coordsCharInner(cm, lineObj, lineNo, x, y) {
function textHeight (line 2888) | function textHeight(display) {
function charWidth (line 2908) | function charWidth(display) {
function startOperation (line 2930) | function startOperation(cm) {
function fireCallbacksForOps (line 2958) | function fireCallbacksForOps(group) {
function endOperation (line 2975) | function endOperation(cm) {
function endOperations (line 2990) | function endOperations(group) {
function endOperation_R1 (line 3004) | function endOperation_R1(op) {
function endOperation_W1 (line 3017) | function endOperation_W1(op) {
function endOperation_R2 (line 3021) | function endOperation_R2(op) {
function endOperation_W2 (line 3042) | function endOperation_W2(op) {
function endOperation_finish (line 3066) | function endOperation_finish(op) {
function runInOp (line 3113) | function runInOp(cm, f) {
function operation (line 3120) | function operation(cm, f) {
function methodOp (line 3130) | function methodOp(f) {
function docMethodOp (line 3138) | function docMethodOp(f) {
function LineView (line 3153) | function LineView(doc, line, lineN) {
function buildViewArray (line 3165) | function buildViewArray(cm, from, to) {
function regChange (line 3181) | function regChange(cm, from, to, lendiff) {
function regLineChange (line 3246) | function regLineChange(cm, line, type) {
function resetView (line 3260) | function resetView(cm) {
function findViewIndex (line 3268) | function findViewIndex(cm, n) {
function viewCuttingPoint (line 3279) | function viewCuttingPoint(cm, oldN, newN, dir) {
function adjustView (line 3305) | function adjustView(cm, from, to) {
function countDirtyView (line 3326) | function countDirtyView(cm) {
function registerEventHandlers (line 3338) | function registerEventHandlers(cm) {
function dragDropChanged (line 3442) | function dragDropChanged(cm, value, old) {
function onResize (line 3455) | function onResize(cm) {
function eventInWidget (line 3468) | function eventInWidget(display, e) {
function posFromMouse (line 3481) | function posFromMouse(cm, e, liberal, forRect) {
function onMouseDown (line 3502) | function onMouseDown(e) {
function leftButtonDown (line 3541) | function leftButtonDown(cm, e, start) {
function leftButtonStartDrag (line 3568) | function leftButtonStartDrag(cm, e, start, modifier) {
function leftButtonSelect (line 3596) | function leftButtonSelect(cm, e, start, type, addNew) {
function gutterEvent (line 3739) | function gutterEvent(cm, e, type, prevent, signalfn) {
function clickInGutter (line 3762) | function clickInGutter(cm, e) {
function onDrop (line 3770) | function onDrop(e) {
function onDragStart (line 3820) | function onDragStart(cm, e) {
function setScrollTop (line 3846) | function setScrollTop(cm, val) {
function setScrollLeft (line 3857) | function setScrollLeft(cm, val, isScroller) {
function onScrollWheel (line 3901) | function onScrollWheel(cm, e) {
function doHandleBinding (line 3973) | function doHandleBinding(cm, bound, dropShift) {
function lookupKeyForEditor (line 3993) | function lookupKeyForEditor(cm, name, handle) {
function dispatchKey (line 4003) | function dispatchKey(cm, name, e, handle) {
function handleKeyBinding (line 4035) | function handleKeyBinding(cm, e) {
function handleCharBinding (line 4054) | function handleCharBinding(cm, e, ch) {
function onKeyDown (line 4060) | function onKeyDown(e) {
function showCrossHair (line 4081) | function showCrossHair(cm) {
function onKeyUp (line 4096) | function onKeyUp(e) {
function onKeyPress (line 4101) | function onKeyPress(e) {
function delayBlurEvent (line 4114) | function delayBlurEvent(cm) {
function onFocus (line 4124) | function onFocus(cm) {
function onBlur (line 4143) | function onBlur(cm) {
function onContextMenu (line 4160) | function onContextMenu(cm, e) {
function contextMenuInGutter (line 4165) | function contextMenuInGutter(cm, e) {
function adjustForChange (line 4182) | function adjustForChange(pos, change) {
function computeSelAfterChange (line 4191) | function computeSelAfterChange(doc, change) {
function offsetPos (line 4201) | function offsetPos(pos, old, nw) {
function computeReplacedSel (line 4210) | function computeReplacedSel(doc, changes, hint) {
function filterChange (line 4230) | function filterChange(doc, change, update) {
function makeChange (line 4254) | function makeChange(doc, change, ignoreReadOnly) {
function makeChangeInner (line 4276) | function makeChangeInner(doc, change) {
function makeChangeFromHistory (line 4294) | function makeChangeFromHistory(doc, type, allowSelectionOnly) {
function shiftDoc (line 4360) | function shiftDoc(doc, distance) {
function makeChangeSingleDoc (line 4376) | function makeChangeSingleDoc(doc, change, selAfter, spans) {
function makeChangeSingleDocInEditor (line 4409) | function makeChangeSingleDocInEditor(cm, change, spans) {
function replaceRange (line 4468) | function replaceRange(doc, code, from, to, origin) {
function maybeScrollWindow (line 4479) | function maybeScrollWindow(cm, coords) {
function scrollPosIntoView (line 4499) | function scrollPosIntoView(cm, pos, end, margin) {
function scrollIntoView (line 4523) | function scrollIntoView(cm, x1, y1, x2, y2) {
function calculateScrollPos (line 4533) | function calculateScrollPos(cm, x1, y1, x2, y2) {
function addToScrollPos (line 4563) | function addToScrollPos(cm, left, top) {
function ensureCursorVisible (line 4573) | function ensureCursorVisible(cm) {
function resolveScrollToPos (line 4587) | function resolveScrollToPos(cm) {
function indentLine (line 4607) | function indentLine(cm, n, how, aggressive) {
function changeLine (line 4669) | function changeLine(doc, handle, changeType, op) {
function deleteNearSelection (line 4680) | function deleteNearSelection(cm, compute) {
function findPosH (line 4712) | function findPosH(doc, pos, dir, unit, visually) {
function findPosV (line 4763) | function findPosV(cm, pos, dir, unit) {
function interpret (line 5183) | function interpret(val) {
function option (line 5239) | function option(name, deflt, handle, notOnInit) {
function normalizeKeyName (line 5686) | function normalizeKeyName(name) {
function getKeyMap (line 5772) | function getKeyMap(val) {
function save (line 5793) | function save() {textarea.value = cm.getValue();}
function markText (line 6043) | function markText(doc, from, to, options, type) {
function markTextShared (line 6136) | function markTextShared(doc, from, to, options, type) {
function findSharedMarkers (line 6151) | function findSharedMarkers(doc) {
function copySharedMarkers (line 6156) | function copySharedMarkers(doc, markers) {
function detachSharedMarkers (line 6168) | function detachSharedMarkers(markers) {
function MarkedSpan (line 6184) | function MarkedSpan(marker, from, to) {
function getMarkedSpanFor (line 6190) | function getMarkedSpanFor(spans, marker) {
function removeMarkedSpan (line 6198) | function removeMarkedSpan(spans, span) {
function addMarkedSpan (line 6204) | function addMarkedSpan(line, span) {
function markedSpansBefore (line 6213) | function markedSpansBefore(old, startCh, isInsert) {
function markedSpansAfter (line 6224) | function markedSpansAfter(old, endCh, isInsert) {
function stretchSpansOverChange (line 6243) | function stretchSpansOverChange(doc, change) {
function clearEmptySpans (line 6305) | function clearEmptySpans(spans) {
function mergeOldSpans (line 6319) | function mergeOldSpans(doc, change) {
function removeReadOnlyRanges (line 6342) | function removeReadOnlyRanges(doc, from, to) {
function detachMarkedSpans (line 6371) | function detachMarkedSpans(line) {
function attachMarkedSpans (line 6378) | function attachMarkedSpans(line, spans) {
function extraLeft (line 6387) | function extraLeft(marker) { return marker.inclusiveLeft ? -1 : 0; }
function extraRight (line 6388) | function extraRight(marker) { return marker.inclusiveRight ? 1 : 0; }
function compareCollapsedMarkers (line 6393) | function compareCollapsedMarkers(a, b) {
function collapsedSpanAtSide (line 6406) | function collapsedSpanAtSide(line, start) {
function collapsedSpanAtStart (line 6416) | function collapsedSpanAtStart(line) { return collapsedSpanAtSide(line, t...
function collapsedSpanAtEnd (line 6417) | function collapsedSpanAtEnd(line) { return collapsedSpanAtSide(line, fal...
function conflictingCollapsedRange (line 6422) | function conflictingCollapsedRange(doc, lineNo, from, to, marker) {
function visualLine (line 6442) | function visualLine(line) {
function visualLineContinued (line 6451) | function visualLineContinued(line) {
function visualLineNo (line 6462) | function visualLineNo(doc, lineN) {
function visualLineEndNo (line 6469) | function visualLineEndNo(doc, lineN) {
function lineIsHidden (line 6481) | function lineIsHidden(doc, line) {
function lineIsHiddenInner (line 6492) | function lineIsHiddenInner(doc, line, span) {
function adjustScrollWhenAboveVisible (line 6520) | function adjustScrollWhenAboveVisible(cm, line, diff) {
function widgetHeight (line 6549) | function widgetHeight(widget) {
function addLineWidget (line 6564) | function addLineWidget(doc, handle, node, options) {
function updateLine (line 6599) | function updateLine(line, text, markedSpans, estimateHeight) {
function cleanUpLine (line 6611) | function cleanUpLine(line) {
function extractLineClasses (line 6616) | function extractLineClasses(type, output) {
function callBlankLine (line 6630) | function callBlankLine(mode, state) {
function readToken (line 6637) | function readToken(mode, stream, state, inner) {
function takeToken (line 6647) | function takeToken(cm, pos, precise, asArray) {
function runMode (line 6669) | function runMode(cm, text, mode, state, f, lineClasses, forceToEnd) {
function highlightLine (line 6710) | function highlightLine(cm, line, state, forceToEnd) {
function getLineStyles (line 6748) | function getLineStyles(cm, line, updateFrontier) {
function processLine (line 6762) | function processLine(cm, text, state, startAt) {
function interpretTokenStyle (line 6777) | function interpretTokenStyle(style, options) {
function buildLineContent (line 6789) | function buildLineContent(cm, lineView) {
function defaultSpecialCharPlaceholder (line 6843) | function defaultSpecialCharPlaceholder(ch) {
function buildToken (line 6852) | function buildToken(builder, text, style, startStyle, endStyle, title, c...
function splitSpaces (line 6906) | function splitSpaces(old) {
function buildTokenBadBidi (line 6915) | function buildTokenBadBidi(inner, order) {
function buildCollapsedSpan (line 6934) | function buildCollapsedSpan(builder, size, marker, ignoreWidget) {
function insertLineContent (line 6951) | function insertLineContent(line, builder, styles) {
function isWholeLineUpdate (line 7021) | function isWholeLineUpdate(doc, change) {
function updateDoc (line 7027) | function updateDoc(doc, change, markedSpans, estimateHeight) {
function LeafChunk (line 7090) | function LeafChunk(lines) {
function BranchChunk (line 7130) | function BranchChunk(children) {
function linkedDocs (line 7589) | function linkedDocs(doc, f, sharedHistOnly) {
function attachDoc (line 7604) | function attachDoc(cm, doc) {
function getLine (line 7618) | function getLine(doc, n) {
function getBetween (line 7633) | function getBetween(doc, start, end) {
function getLines (line 7645) | function getLines(doc, from, to) {
function updateLineHeight (line 7653) | function updateLineHeight(line, height) {
function lineNo (line 7660) | function lineNo(line) {
function lineAtHeight (line 7674) | function lineAtHeight(chunk, h) {
function heightAtLine (line 7695) | function heightAtLine(lineObj) {
function getOrder (line 7717) | function getOrder(line) {
function History (line 7725) | function History(startGen) {
function historyChangeFromChange (line 7742) | function historyChangeFromChange(doc, change) {
function clearSelectionEvents (line 7751) | function clearSelectionEvents(array) {
function lastChangeEvent (line 7761) | function lastChangeEvent(hist, force) {
function addChangeToHistory (line 7776) | function addChangeToHistory(doc, change, selAfter, opId) {
function selectionEventCanBeMerged (line 7818) | function selectionEventCanBeMerged(doc, origin, prev, sel) {
function addSelectionToHistory (line 7831) | function addSelectionToHistory(doc, sel, opId, options) {
function pushSelectionToHistory (line 7853) | function pushSelectionToHistory(sel, dest) {
function attachLocalSpans (line 7860) | function attachLocalSpans(doc, change, from, to) {
function removeClearedSpans (line 7871) | function removeClearedSpans(spans) {
function getOldSpans (line 7881) | function getOldSpans(doc, change) {
function copyHistoryArray (line 7891) | function copyHistoryArray(events, newGroup, instantiateSel) {
function rebaseHistSelSingle (line 7916) | function rebaseHistSelSingle(pos, from, to, diff) {
function rebaseHistArray (line 7932) | function rebaseHistArray(array, from, to, diff) {
function rebaseHist (line 7960) | function rebaseHist(hist, change) {
function e_defaultPrevented (line 7979) | function e_defaultPrevented(e) {
function e_target (line 7984) | function e_target(e) {return e.target || e.srcElement;}
function e_button (line 7985) | function e_button(e) {
function signalLater (line 8042) | function signalLater(emitter, type /*, values...*/) {
function fireOrphanDelayed (line 8059) | function fireOrphanDelayed() {
function signalDOMEvent (line 8068) | function signalDOMEvent(cm, e, override) {
function signalCursorActivity (line 8075) | function signalCursorActivity(cm) {
function hasHandler (line 8083) | function hasHandler(emitter, type) {
function eventMixin (line 8090) | function eventMixin(ctor) {
function Delayed (line 8107) | function Delayed() {this.id = null;}
function findColumn (line 8132) | function findColumn(string, goal, tabSize) {
function spaceStr (line 8147) | function spaceStr(n) {
function lst (line 8153) | function lst(arr) { return arr[arr.length-1]; }
function indexOf (line 8161) | function indexOf(array, elt) {
function map (line 8166) | function map(array, f) {
function nothing (line 8172) | function nothing() {}
function createObj (line 8174) | function createObj(base, props) {
function copyObj (line 8186) | function copyObj(obj, target, overwrite) {
function bind (line 8194) | function bind(f) {
function isWordChar (line 8204) | function isWordChar(ch, helper) {
function isEmpty (line 8210) | function isEmpty(obj) {
function isExtendingChar (line 8221) | function isExtendingChar(ch) { return ch.charCodeAt(0) >= 768 && extendi...
function elt (line 8225) | function elt(tag, content, className, style) {
function removeChildren (line 8251) | function removeChildren(e) {
function removeChildrenAndAdd (line 8257) | function removeChildrenAndAdd(parent, e) {
function activeElt (line 8272) | function activeElt() { return document.activeElement; }
function classTest (line 8280) | function classTest(cls) { return new RegExp("(^|\\s)" + cls + "(?:$|\\s)...
function joinClasses (line 8293) | function joinClasses(a, b) {
function forEachCodeMirror (line 8306) | function forEachCodeMirror(f) {
function ensureGlobalHandlers (line 8316) | function ensureGlobalHandlers() {
function registerGlobalHandlers (line 8321) | function registerGlobalHandlers() {
function zeroWidthElement (line 8348) | function zeroWidthElement(measure) {
function hasBadBidiRects (line 8363) | function hasBadBidiRects(measure) {
function hasBadZoomedRects (line 8410) | function hasBadZoomedRects(measure) {
function iterateBidiSections (line 8439) | function iterateBidiSections(order, from, to, f) {
function bidiLeft (line 8452) | function bidiLeft(part) { return part.level % 2 ? part.to : part.from; }
function bidiRight (line 8453) | function bidiRight(part) { return part.level % 2 ? part.from : part.to; }
function lineLeft (line 8455) | function lineLeft(line) { var order = getOrder(line); return order ? bid...
function lineRight (line 8456) | function lineRight(line) {
function lineStart (line 8462) | function lineStart(cm, lineN) {
function lineEnd (line 8470) | function lineEnd(cm, lineN) {
function lineStartSmart (line 8480) | function lineStartSmart(cm, pos) {
function compareBidiLevel (line 8492) | function compareBidiLevel(order, a, b) {
function getBidiPartAt (line 8499) | function getBidiPartAt(order, pos) {
function moveInLine (line 8519) | function moveInLine(line, pos, dir, byUnit) {
function moveVisually (line 8531) | function moveVisually(line, start, dir, byUnit) {
function moveLogically (line 8554) | function moveLogically(line, start, dir, byUnit) {
function charType (line 8588) | function charType(code) {
function BidiSpan (line 8603) | function BidiSpan(level, from, to) {
FILE: docs/libs/codemirror/mode/javascript/javascript.js
function kw (line 27) | function kw(type) {return {type: type, style: "keyword"};}
function readRegexp (line 73) | function readRegexp(stream) {
function ret (line 88) | function ret(tp, style, cont) {
function tokenBase (line 92) | function tokenBase(stream, state) {
function tokenString (line 144) | function tokenString(quote) {
function tokenComment (line 160) | function tokenComment(stream, state) {
function tokenQuasi (line 172) | function tokenQuasi(stream, state) {
function findFatArrow (line 192) | function findFatArrow(stream, state) {
function JSLexical (line 222) | function JSLexical(indented, column, type, align, prev, info) {
function inScope (line 231) | function inScope(state, varname) {
function parseJS (line 240) | function parseJS(state, style, type, content, stream) {
function pass (line 264) | function pass() {
function cont (line 267) | function cont() {
function register (line 271) | function register(varname) {
function pushcontext (line 292) | function pushcontext() {
function popcontext (line 296) | function popcontext() {
function pushlex (line 300) | function pushlex(type, info) {
function poplex (line 311) | function poplex() {
function expect (line 321) | function expect(wanted) {
function statement (line 330) | function statement(type, value) {
function expression (line 356) | function expression(type) {
function expressionNoComma (line 359) | function expressionNoComma(type) {
function expressionInner (line 362) | function expressionInner(type, noComma) {
function maybeexpression (line 380) | function maybeexpression(type) {
function maybeexpressionNoComma (line 384) | function maybeexpressionNoComma(type) {
function maybeoperatorComma (line 389) | function maybeoperatorComma(type, value) {
function maybeoperatorNoComma (line 393) | function maybeoperatorNoComma(type, value, noComma) {
function quasi (line 408) | function quasi(type, value) {
function continueQuasi (line 413) | function continueQuasi(type) {
function arrowBody (line 420) | function arrowBody(type) {
function arrowBodyNoComma (line 424) | function arrowBodyNoComma(type) {
function maybelabel (line 428) | function maybelabel(type) {
function property (line 432) | function property(type) {
function objprop (line 435) | function objprop(type, value) {
function getterSetter (line 449) | function getterSetter(type) {
function afterprop (line 454) | function afterprop(type) {
function commasep (line 458) | function commasep(what, end) {
function contCommasep (line 473) | function contCommasep(what, end, info) {
function block (line 478) | function block(type) {
function maybetype (line 482) | function maybetype(type) {
function maybedefault (line 485) | function maybedefault(_, value) {
function typedef (line 488) | function typedef(type) {
function vardef (line 491) | function vardef() {
function pattern (line 494) | function pattern(type, value) {
function proppattern (line 499) | function proppattern(type, value) {
function maybeAssign (line 507) | function maybeAssign(_type, value) {
function vardefCont (line 510) | function vardefCont(type) {
function maybeelse (line 513) | function maybeelse(type, value) {
function forspec (line 516) | function forspec(type) {
function forspec1 (line 519) | function forspec1(type) {
function formaybeinof (line 525) | function formaybeinof(_type, value) {
function forspec2 (line 529) | function forspec2(type, value) {
function forspec3 (line 534) | function forspec3(type) {
function functiondef (line 537) | function functiondef(type, value) {
function funarg (line 542) | function funarg(type) {
function className (line 546) | function className(type, value) {
function classNameAfter (line 549) | function classNameAfter(type, value) {
function classBody (line 553) | function classBody(type, value) {
function classGetterSetter (line 570) | function classGetterSetter(type) {
function afterModule (line 575) | function afterModule(type, value) {
function afterExport (line 579) | function afterExport(_type, value) {
function afterImport (line 584) | function afterImport(type) {
function importSpec (line 588) | function importSpec(type, value) {
function maybeAs (line 594) | function maybeAs(_type, value) {
function maybeFrom (line 597) | function maybeFrom(_type, value) {
function arrayLiteral (line 600) | function arrayLiteral(type) {
function maybeArrayComprehension (line 604) | function maybeArrayComprehension(type) {
function comprehension (line 609) | function comprehension(type) {
function isContinuedStatement (line 614) | function isContinuedStatement(state, textAfter) {
FILE: docs/libs/codemirror/mode/javascript/test.js
function MT (line 6) | function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arg...
function LD (line 172) | function LD(name) {
FILE: docs/libs/codemirror/mode/shell/shell.js
function define (line 17) | function define(style, dict) {
function tokenBase (line 39) | function tokenBase(stream, state) {
function tokenString (line 93) | function tokenString(quote, style) {
function tokenStringStart (line 120) | function tokenStringStart(quote, style) {
function tokenHeredoc (line 140) | function tokenHeredoc(delim) {
function tokenize (line 148) | function tokenize(stream, state) {
FILE: rollup.config.js
function bundle (line 19) | function bundle(input, target) {
FILE: src/Color.js
class Color (line 4) | class Color {
method constructor (line 5) | constructor(...args) {
method toString (line 44) | toString() {
FILE: src/colors/colorbrewer.js
method get (line 69) | get(target, prop) {
method getOwnPropertyNames (line 75) | getOwnPropertyNames() {
FILE: src/generator/scale.js
function __range__ (line 390) | function __range__(left, right, inclusive) {
FILE: src/io/css/css2rgb.js
constant INT_OR_PCT (line 10) | const INT_OR_PCT = /((?:-?\d+)|(?:-?\d+(?:\.\d+)?)%|none)/.source;
constant FLOAT_OR_PCT (line 11) | const FLOAT_OR_PCT = /((?:-?(?:\d+(?:\.\d*)?|\.\d+)%?)|none)/.source;
constant PCT (line 12) | const PCT = /((?:-?(?:\d+(?:\.\d*)?|\.\d+)%)|none)/.source;
constant RE_S (line 13) | const RE_S = /\s*/.source;
constant SEP (line 14) | const SEP = /\s+/.source;
constant COMMA (line 15) | const COMMA = /\s*,\s*/.source;
constant ANLGE (line 16) | const ANLGE = /((?:-?(?:\d+(?:\.\d*)?|\.\d+)(?:deg)?)|none)/.source;
constant ALPHA (line 17) | const ALPHA = /\s*(?:\/\s*((?:[01]|[01]?\.\d+)|\d+(?:\.\d+)?%))?/.source;
constant RE_RGB (line 20) | const RE_RGB = new RegExp(
constant RE_RGB_LEGACY (line 27) | const RE_RGB_LEGACY = new RegExp(
constant RE_RGBA_LEGACY (line 34) | const RE_RGBA_LEGACY = new RegExp(
constant RE_HSL (line 42) | const RE_HSL = new RegExp(
constant RE_HSL_LEGACY (line 45) | const RE_HSL_LEGACY = new RegExp(
constant RE_HSLA_LEGACY (line 48) | const RE_HSLA_LEGACY =
constant RE_LAB (line 51) | const RE_LAB = new RegExp(
constant RE_LCH (line 58) | const RE_LCH = new RegExp(
constant RE_OKLAB (line 65) | const RE_OKLAB = new RegExp(
constant RE_OKLCH (line 72) | const RE_OKLCH = new RegExp(
FILE: src/io/hex/hex2rgb.js
constant RE_HEX (line 1) | const RE_HEX = /^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;
constant RE_HEXA (line 2) | const RE_HEXA = /^#?([A-Fa-f0-9]{8}|[A-Fa-f0-9]{4})$/;
FILE: src/io/lab/lab-constants.js
constant ILLUMINANTS (line 84) | const ILLUMINANTS = new Map([
function setLabWhitePoint (line 108) | function setLabWhitePoint(name) {
function getLabWhitePoint (line 118) | function getLabWhitePoint() {
FILE: src/io/lab/rgb2lab.js
function xyz2lab (line 11) | function xyz2lab(x, y, z) {
function gammaAdjustSRGB (line 24) | function gammaAdjustSRGB(companded) {
FILE: src/io/oklab/oklab2rgb.js
function OKLab_to_XYZ (line 14) | function OKLab_to_XYZ(OKLab) {
FILE: src/io/oklab/rgb2oklab.js
function XYZ_to_OKLab (line 13) | function XYZ_to_OKLab(XYZ) {
FILE: src/ops/luminance.js
constant EPS (line 5) | const EPS = 1e-7;
constant MAX_ITER (line 6) | const MAX_ITER = 20;
FILE: src/utils/analyze.js
function analyze (line 5) | function analyze(data, key = null) {
function limits (line 34) | function limits(data, mode = 'equal', num = 7) {
FILE: src/utils/contrastAPCA.js
function lum (line 62) | function lum(r, g, b) {
FILE: src/utils/index.js
constant TWOPI (line 12) | const TWOPI = PI * 2;
constant PITHIRD (line 13) | const PITHIRD = PI / 3;
constant DEG2RAD (line 14) | const DEG2RAD = PI / 180;
constant RAD2DEG (line 15) | const RAD2DEG = 180 / PI;
function reverse3 (line 23) | function reverse3(arr) {
FILE: src/utils/multiply-matrices.js
function multiplyMatrices (line 2) | function multiplyMatrices(A, B) {
FILE: src/utils/scales.js
method cool (line 7) | cool() {
method hot (line 10) | hot() {
FILE: test/docs/index.test.js
constant DOCS (line 8) | const DOCS = fs.readFileSync(docsPath, 'utf-8');
Condensed preview — 201 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (1,347K chars).
[
{
"path": ".changeset/README.md",
"chars": 510,
"preview": "# Changesets\n\nHello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that wo"
},
{
"path": ".changeset/config.json",
"chars": 275,
"preview": "{\n \"$schema\": \"https://unpkg.com/@changesets/config@3.1.2/schema.json\",\n \"changelog\": \"@changesets/cli/changelog\",\n \""
},
{
"path": ".github/CODEOWNERS",
"chars": 7,
"preview": "* @gka\n"
},
{
"path": ".github/FUNDING.yml",
"chars": 765,
"preview": "# These are supported funding model platforms\n\ngithub: gka\npatreon: # Replace with a single Patreon username\nopen_collec"
},
{
"path": ".github/workflows/ci.yml",
"chars": 654,
"preview": "name: CI\n\non:\n pull_request:\n branches:\n - main\n push:\n branches:\n - main\n\njobs:\n lint-and-test:\n "
},
{
"path": ".gitignore",
"chars": 66,
"preview": "readme (Autosaved).md\nm.txt\n.DS_Store\nlicense.coffee\nnode_modules\n"
},
{
"path": ".husky/pre-commit",
"chars": 33,
"preview": "pnpm run lint\npnpm test -- --run\n"
},
{
"path": ".npmignore",
"chars": 188,
"preview": "# .gitignore equivelant\n.git*\nreadme (Autosaved).md\nm.txt\n.DS_Store\nlicense.coffee\nnode_modules\nyarn.lock\n\n# Dev content"
},
{
"path": ".travis.yml",
"chars": 84,
"preview": "language: node_js\nnode_js:\n - \"20\"\nbefore_script: \"npm install\"\nscript: \"npm test\"\n"
},
{
"path": "CHANGELOG.md",
"chars": 4956,
"preview": "## Changelog\n\n### 3.2.0\n\n- scale.domain now returns the original domain array when called with no arguments\n\n### 3.1.3\n\n"
},
{
"path": "LICENSE",
"chars": 2418,
"preview": "chroma.js - JavaScript library for color conversions\n\nCopyright (c) 2011-2025, Gregor Aisch\nAll rights reserved.\n\nRedist"
},
{
"path": "dist/chroma-light.cjs",
"chars": 55291,
"preview": "/**\n * chroma.js - JavaScript library for color conversions\n *\n * Copyright (c) 2011-2025, Gregor Aisch\n * All rights re"
},
{
"path": "dist/chroma-light.min.cjs",
"chars": 22767,
"preview": "/**\n * chroma.js - JavaScript library for color conversions\n *\n * Copyright (c) 2011-2025, Gregor Aisch\n * All rights re"
},
{
"path": "dist/chroma.cjs",
"chars": 131025,
"preview": "/**\n * chroma.js - JavaScript library for color conversions\n *\n * Copyright (c) 2011-2025, Gregor Aisch\n * All rights re"
},
{
"path": "dist/chroma.min.cjs",
"chars": 52299,
"preview": "/**\n * chroma.js - JavaScript library for color conversions\n *\n * Copyright (c) 2011-2025, Gregor Aisch\n * All rights re"
},
{
"path": "docs/Makefile",
"chars": 286,
"preview": "all:\n\tcat src/index.md ../CHANGELOG.md > tmp.md\n\t../node_modules/.bin/markdown -f gfm -s src/index.css tmp.md --title \"c"
},
{
"path": "docs/bin/post-process",
"chars": 770,
"preview": "#!/usr/bin/env node\nimport fs from 'fs';\n\nconst index = fs.readFileSync('index.html', 'utf-8');\nconst footer = fs.readFi"
},
{
"path": "docs/index.html",
"chars": 62680,
"preview": "<!DOCTYPE html>\n<html>\n<head>\n <title>chroma.js api docs!</title>\n <link rel=\"stylesheet\" href=\"src/index.css\">\n <lin"
},
{
"path": "docs/libs/chroma-light.cjs",
"chars": 55291,
"preview": "/**\n * chroma.js - JavaScript library for color conversions\n *\n * Copyright (c) 2011-2025, Gregor Aisch\n * All rights re"
},
{
"path": "docs/libs/chroma-light.min.cjs",
"chars": 22767,
"preview": "/**\n * chroma.js - JavaScript library for color conversions\n *\n * Copyright (c) 2011-2025, Gregor Aisch\n * All rights re"
},
{
"path": "docs/libs/chroma.cjs",
"chars": 131025,
"preview": "/**\n * chroma.js - JavaScript library for color conversions\n *\n * Copyright (c) 2011-2025, Gregor Aisch\n * All rights re"
},
{
"path": "docs/libs/chroma.min.cjs",
"chars": 52299,
"preview": "/**\n * chroma.js - JavaScript library for color conversions\n *\n * Copyright (c) 2011-2025, Gregor Aisch\n * All rights re"
},
{
"path": "docs/libs/codemirror/lib/codemirror.css",
"chars": 7771,
"preview": "/* BASICS */\n\n.CodeMirror {\n /* Set height, width, borders, and global font properties here */\n font-family: monospace"
},
{
"path": "docs/libs/codemirror/lib/codemirror.js",
"chars": 346296,
"preview": "// CodeMirror, copyright (c) by Marijn Haverbeke and others\n// Distributed under an MIT license: http://codemirror.net/L"
},
{
"path": "docs/libs/codemirror/mode/javascript/index.html",
"chars": 4193,
"preview": "<!doctype html>\n\n<title>CodeMirror: JavaScript mode</title>\n<meta charset=\"utf-8\"/>\n<link rel=stylesheet href=\"../../doc"
},
{
"path": "docs/libs/codemirror/mode/javascript/javascript.js",
"chars": 26745,
"preview": "// CodeMirror, copyright (c) by Marijn Haverbeke and others\n// Distributed under an MIT license: http://codemirror.net/L"
},
{
"path": "docs/libs/codemirror/mode/javascript/json-ld.html",
"chars": 2150,
"preview": "<!doctype html>\n\n<title>CodeMirror: JSON-LD mode</title>\n<meta charset=\"utf-8\"/>\n<link rel=stylesheet href=\"../../doc/do"
},
{
"path": "docs/libs/codemirror/mode/javascript/test.js",
"chars": 7637,
"preview": "// CodeMirror, copyright (c) by Marijn Haverbeke and others\n// Distributed under an MIT license: http://codemirror.net/L"
},
{
"path": "docs/libs/codemirror/mode/javascript/typescript.html",
"chars": 1547,
"preview": "<!doctype html>\n\n<title>CodeMirror: TypeScript mode</title>\n<meta charset=\"utf-8\"/>\n<link rel=stylesheet href=\"../../doc"
},
{
"path": "docs/libs/codemirror/mode/shell/shell.js",
"chars": 5713,
"preview": "// CodeMirror, copyright (c) by Marijn Haverbeke and others\n// Distributed under an MIT license: https://codemirror.net/"
},
{
"path": "docs/src/footer.inc.html",
"chars": 11964,
"preview": "<link rel=\"stylesheet\" type=\"text/css\" href=\"libs/codemirror/lib/codemirror.css\" />\n<script type=\"text/javascript\" src="
},
{
"path": "docs/src/index.css",
"chars": 7788,
"preview": "@import 'https://fonts.googleapis.com/css?family=Roboto:100,300,400,700';\n\nbody {\n font-family: -apple-system, Blink"
},
{
"path": "docs/src/index.md",
"chars": 31827,
"preview": "\n# chroma.js\n\n**chroma.js** is a [small-ish](https://bundlephobia.com/result?p=chroma-js) zero-dependency JavaScript lib"
},
{
"path": "eslint.config.mjs",
"chars": 905,
"preview": "import globals from \"globals\";\nimport babelParser from \"@babel/eslint-parser\";\nimport path from \"node:path\";\nimport { fi"
},
{
"path": "index-light.js",
"chars": 979,
"preview": "import chroma from './src/chroma.js';\n\n// feel free to comment out anything to rollup\n// a smaller chroma.js built\n\n// i"
},
{
"path": "index.js",
"chars": 3077,
"preview": "// feel free to comment out anything to rollup\n// a smaller chroma.js bundle\nimport chroma from './src/chroma.js';\n\n// i"
},
{
"path": "index.umd.js",
"chars": 3185,
"preview": "// feel free to comment out anything to rollup\n// a smaller chroma.js bundle\nimport chroma from './src/chroma.js';\n\n// i"
},
{
"path": "index.umd.light.js",
"chars": 1064,
"preview": "import chroma from './src/chroma.js';\n\n// feel free to comment out anything to rollup\n// a smaller chroma.js bundle\n\n// "
},
{
"path": "package.json",
"chars": 2572,
"preview": "{\n \"name\": \"chroma-js\",\n \"description\": \"JavaScript library for color conversions\",\n \"version\": \"3.2.0\",\n \"packageMa"
},
{
"path": "prettier.config.js",
"chars": 609,
"preview": "// prettier.config.js, .prettierrc.js, prettier.config.mjs, or .prettierrc.mjs\n\n/**\n * @see https://prettier.io/docs/en/"
},
{
"path": "readme.md",
"chars": 3705,
"preview": "# Chroma.js\n\n[Chroma.js](https://vis4.net/chromajs/) is a ~~tiny~~ [small-ish](https://bundlejs.com/?q=chroma-js) zero-d"
},
{
"path": "rollup.config.js",
"chars": 1481,
"preview": "import buble from '@rollup/plugin-buble';\nimport license from 'rollup-plugin-license';\nimport path from 'path';\nimport t"
},
{
"path": "src/Color.js",
"chars": 1452,
"preview": "import { last, clip_rgb, type } from './utils/index.js';\nimport _input from './io/input.js';\n\nclass Color {\n construc"
},
{
"path": "src/chroma.js",
"chars": 188,
"preview": "import Color from './Color.js';\nimport { version } from './version.js';\n\nconst chroma = (...args) => {\n return new Co"
},
{
"path": "src/colors/colorbrewer.js",
"chars": 5735,
"preview": "/**\n ColorBrewer colors for chroma.js\n\n Copyright (c) 2002 Cynthia Brewer, Mark Harrower, and The\n Pennsylvania"
},
{
"path": "src/colors/w3cx11.js",
"chars": 4105,
"preview": "/**\n\tX11 color names\n\n\thttp://www.w3.org/TR/css3-color/#svg-color\n*/\n\nconst w3cx11 = {\n aliceblue: '#f0f8ff',\n ant"
},
{
"path": "src/generator/average.js",
"chars": 2701,
"preview": "import Color from '../Color.js';\nimport { clip_rgb } from '../utils/index.js';\n\nconst { pow, sqrt, PI, cos, sin, atan2 }"
},
{
"path": "src/generator/bezier.js",
"chars": 2606,
"preview": "//\n// interpolates between a set of colors uzing a bezier spline\n//\n\n// @requires utils lab\nimport Color from '../Color."
},
{
"path": "src/generator/blend.js",
"chars": 1726,
"preview": "/*\n * interpolates between a set of colors uzing a bezier spline\n * blend mode formulas taken from https://web.archive.o"
},
{
"path": "src/generator/cubehelix.js",
"chars": 2271,
"preview": "// cubehelix interpolation\n// based on D.A. Green \"A colour scheme for the display of astronomical intensity images\"\n// "
},
{
"path": "src/generator/mix.js",
"chars": 701,
"preview": "import Color from '../Color.js';\nimport { type } from '../utils/index.js';\nimport interpolator from '../interpolator/ind"
},
{
"path": "src/generator/random.js",
"chars": 389,
"preview": "import Color from '../Color.js';\nconst digits = '0123456789abcdef';\n\nconst { floor, random } = Math;\n\n/**\n * Generates a"
},
{
"path": "src/generator/scale.js",
"chars": 11497,
"preview": "// minimal multi-purpose interface\n\n// @requires utils color analyze\nimport chroma from '../chroma.js';\nimport { limit, "
},
{
"path": "src/interpolator/_hsx.js",
"chars": 1672,
"preview": "import Color from '../Color.js';\n\nexport default (col1, col2, f, m) => {\n let xyz0, xyz1;\n if (m === 'hsl') {\n "
},
{
"path": "src/interpolator/hcg.js",
"chars": 253,
"preview": "import '../io/hcg/index.js';\nimport interpolate_hsx from './_hsx.js';\nimport index from './index.js';\n\nconst hcg = (col1"
},
{
"path": "src/interpolator/hsi.js",
"chars": 253,
"preview": "import '../io/hsi/index.js';\nimport interpolate_hsx from './_hsx.js';\nimport index from './index.js';\n\nconst hsi = (col1"
},
{
"path": "src/interpolator/hsl.js",
"chars": 253,
"preview": "import '../io/hsl/index.js';\nimport interpolate_hsx from './_hsx.js';\nimport index from './index.js';\n\nconst hsl = (col1"
},
{
"path": "src/interpolator/hsv.js",
"chars": 253,
"preview": "import '../io/hsv/index.js';\nimport interpolate_hsx from './_hsx.js';\nimport index from './index.js';\n\nconst hsv = (col1"
},
{
"path": "src/interpolator/index.js",
"chars": 19,
"preview": "export default {};\n"
},
{
"path": "src/interpolator/lab.js",
"chars": 425,
"preview": "import '../io/lab/index.js';\nimport index from './index.js';\nimport Color from '../Color.js';\n\nconst lab = (col1, col2, "
},
{
"path": "src/interpolator/lch.js",
"chars": 270,
"preview": "import '../io/lch/index.js';\nimport interpolate_hsx from './_hsx.js';\nimport index from './index.js';\n\nconst lch = (col1"
},
{
"path": "src/interpolator/lrgb.js",
"chars": 472,
"preview": "import Color from '../Color.js';\nconst { sqrt, pow } = Math;\nimport index from './index.js';\n\nconst lrgb = (col1, col2, "
},
{
"path": "src/interpolator/num.js",
"chars": 299,
"preview": "import '../io/num/index.js';\nimport index from './index.js';\n\nimport Color from '../Color.js';\n\nconst num = (col1, col2,"
},
{
"path": "src/interpolator/oklab.js",
"chars": 441,
"preview": "import '../io/oklab/index.js';\nimport index from './index.js';\nimport Color from '../Color.js';\n\nconst oklab = (col1, co"
},
{
"path": "src/interpolator/oklch.js",
"chars": 263,
"preview": "import '../io/lch/index.js';\nimport interpolate_hsx from './_hsx.js';\nimport index from './index.js';\n\nconst oklch = (co"
},
{
"path": "src/interpolator/rgb.js",
"chars": 394,
"preview": "import Color from '../Color.js';\nimport index from './index.js';\n\nconst rgb = (col1, col2, f) => {\n const xyz0 = col1"
},
{
"path": "src/io/cmyk/cmyk2rgb.js",
"chars": 451,
"preview": "import { unpack } from '../../utils/index.js';\n\nconst cmyk2rgb = (...args) => {\n args = unpack(args, 'cmyk');\n con"
},
{
"path": "src/io/cmyk/index.js",
"chars": 649,
"preview": "import chroma from '../../chroma.js';\nimport Color from '../../Color.js';\nimport input from '../input.js';\nimport { unpa"
},
{
"path": "src/io/cmyk/rgb2cmyk.js",
"chars": 417,
"preview": "import { unpack } from '../../utils/index.js';\nconst { max } = Math;\n\nconst rgb2cmyk = (...args) => {\n let [r, g, b] "
},
{
"path": "src/io/css/css2rgb.js",
"chars": 7449,
"preview": "import hsl2rgb from '../hsl/hsl2rgb.js';\nimport lab2rgb from '../lab/lab2rgb.js';\nimport lch2rgb from '../lch/lch2rgb.js"
},
{
"path": "src/io/css/hsl2css.js",
"chars": 721,
"preview": "import { unpack, last, rnd2 } from '../../utils/index.js';\n\n/*\n * supported arguments:\n * - hsl2css(h,s,l)\n * - hsl2css("
},
{
"path": "src/io/css/index.js",
"chars": 603,
"preview": "import chroma from '../../chroma.js';\nimport Color from '../../Color.js';\nimport input from '../input.js';\nimport { type"
},
{
"path": "src/io/css/lab2css.js",
"chars": 627,
"preview": "import { unpack, last, rnd2 } from '../../utils/index.js';\n\n/*\n * supported arguments:\n * - lab2css(l,a,b)\n * - lab2css("
},
{
"path": "src/io/css/lch2css.js",
"chars": 684,
"preview": "import { unpack, last, rnd2 } from '../../utils/index.js';\n\n/*\n * supported arguments:\n * - lab2css(l,a,b)\n * - lab2css("
},
{
"path": "src/io/css/oklab2css.js",
"chars": 443,
"preview": "import { unpack, rnd2, rnd3 } from '../../utils/index.js';\n\nconst oklab2css = (...args) => {\n const laba = unpack(arg"
},
{
"path": "src/io/css/oklch2css.js",
"chars": 500,
"preview": "import { unpack, rnd2, rnd3 } from '../../utils/index.js';\n\nconst oklch2css = (...args) => {\n const lcha = unpack(arg"
},
{
"path": "src/io/css/rgb2css.js",
"chars": 2137,
"preview": "import { unpack, last } from '../../utils/index.js';\nimport hsl2css from './hsl2css.js';\nimport rgb2hsl from '../hsl/rgb"
},
{
"path": "src/io/delta-e.coffee",
"chars": 1100,
"preview": "chroma.deltaE = (a, b, L=1, C=1) ->\n # Delta E (CMC)\n # see http://www.brucelindbloom.com/index.html?Eqn_DeltaE_CM"
},
{
"path": "src/io/distance.coffee",
"chars": 423,
"preview": "# simple Euclidean distance\nchroma.distance = (a, b, mode='lab') ->\n # Delta E (CIE 1976)\n # see http://www.brucel"
},
{
"path": "src/io/gl/index.js",
"chars": 514,
"preview": "import Color from '../../Color.js';\nimport chroma from '../../chroma.js';\nimport input from '../input.js';\nimport { unpa"
},
{
"path": "src/io/hcg/hcg2rgb.js",
"chars": 1296,
"preview": "import { unpack } from '../../utils/index.js';\nconst { floor } = Math;\n\n/*\n * this is basically just HSV with some minor"
},
{
"path": "src/io/hcg/index.js",
"chars": 621,
"preview": "import { unpack, type } from '../../utils/index.js';\nimport chroma from '../../chroma.js';\nimport Color from '../../Colo"
},
{
"path": "src/io/hcg/rgb2hcg.js",
"chars": 638,
"preview": "import { unpack, max, min } from '../../utils/index.js';\n\nconst rgb2hcg = (...args) => {\n const [r, g, b] = unpack(ar"
},
{
"path": "src/io/hex/hex2rgb.js",
"chars": 1647,
"preview": "const RE_HEX = /^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;\nconst RE_HEXA = /^#?([A-Fa-f0-9]{8}|[A-Fa-f0-9]{4})$/;\n\nconst hex2"
},
{
"path": "src/io/hex/index.js",
"chars": 676,
"preview": "import Color from '../../Color.js';\nimport chroma from '../../chroma.js';\nimport { type } from '../../utils/index.js';\ni"
},
{
"path": "src/io/hex/rgb2hex.js",
"chars": 803,
"preview": "import { unpack, last } from '../../utils/index.js';\nconst { round } = Math;\n\nconst rgb2hex = (...args) => {\n let [r,"
},
{
"path": "src/io/hsi/hsi2rgb.js",
"chars": 1170,
"preview": "import { unpack, limit, TWOPI, PITHIRD } from '../../utils/index.js';\nconst { cos } = Math;\n\n/*\n * hue [0..360]\n * satur"
},
{
"path": "src/io/hsi/index.js",
"chars": 621,
"preview": "import { unpack, type } from '../../utils/index.js';\nimport chroma from '../../chroma.js';\nimport Color from '../../Colo"
},
{
"path": "src/io/hsi/rgb2hsi.js",
"chars": 740,
"preview": "import { unpack, TWOPI } from '../../utils/index.js';\nconst { min, sqrt, acos } = Math;\n\nconst rgb2hsi = (...args) => {\n"
},
{
"path": "src/io/hsl/hsl2rgb.js",
"chars": 1032,
"preview": "import { unpack } from '../../utils/index.js';\n\nconst hsl2rgb = (...args) => {\n args = unpack(args, 'hsl');\n const"
},
{
"path": "src/io/hsl/index.js",
"chars": 621,
"preview": "import { unpack, type } from '../../utils/index.js';\nimport chroma from '../../chroma.js';\nimport Color from '../../Colo"
},
{
"path": "src/io/hsl/rgb2hsl.js",
"chars": 1037,
"preview": "import { unpack, min, max } from '../../utils/index.js';\n\n/*\n * supported arguments:\n * - rgb2hsl(r,g,b)\n * - rgb2hsl(r,"
},
{
"path": "src/io/hsv/hsv2rgb.js",
"chars": 1126,
"preview": "import { unpack } from '../../utils/index.js';\nconst { floor } = Math;\n\nconst hsv2rgb = (...args) => {\n args = unpack"
},
{
"path": "src/io/hsv/index.js",
"chars": 621,
"preview": "import { unpack, type } from '../../utils/index.js';\nimport chroma from '../../chroma.js';\nimport Color from '../../Colo"
},
{
"path": "src/io/hsv/rgb2hsv.js",
"chars": 736,
"preview": "import { unpack } from '../../utils/index.js';\nconst { min, max } = Math;\n\n/*\n * supported arguments:\n * - rgb2hsv(r,g,b"
},
{
"path": "src/io/input.js",
"chars": 55,
"preview": "export default {\n format: {},\n autodetect: []\n};\n"
},
{
"path": "src/io/lab/index.js",
"chars": 780,
"preview": "import { unpack, type } from '../../utils/index.js';\nimport chroma from '../../chroma.js';\nimport Color from '../../Colo"
},
{
"path": "src/io/lab/lab-constants.js",
"chars": 2872,
"preview": "const labConstants = {\n // Corresponds roughly to RGB brighter/darker\n Kn: 18,\n\n // D65 standard referent\n l"
},
{
"path": "src/io/lab/lab2rgb.js",
"chars": 2946,
"preview": "import LAB_CONSTANTS from './lab-constants.js';\nimport { unpack } from '../../utils/index.js';\n\n/*\n * L* [0..100]\n * a ["
},
{
"path": "src/io/lab/rgb2lab.js",
"chars": 2375,
"preview": "import LAB_CONSTANTS from './lab-constants.js';\nimport { unpack } from '../../utils/index.js';\n\nconst rgb2lab = (...args"
},
{
"path": "src/io/lch/hcl2rgb.js",
"chars": 228,
"preview": "import { unpack, reverse3 } from '../../utils/index.js';\nimport lch2rgb from './lch2rgb.js';\n\nconst hcl2rgb = (...args) "
},
{
"path": "src/io/lch/index.js",
"chars": 911,
"preview": "import { unpack, type, reverse3 } from '../../utils/index.js';\nimport chroma from '../../chroma.js';\nimport Color from '"
},
{
"path": "src/io/lch/lab2lch.js",
"chars": 350,
"preview": "import { unpack, RAD2DEG } from '../../utils/index.js';\nconst { sqrt, atan2, round } = Math;\n\nconst lab2lch = (...args) "
},
{
"path": "src/io/lch/lch2lab.js",
"chars": 582,
"preview": "import { unpack, DEG2RAD } from '../../utils/index.js';\nconst { sin, cos } = Math;\n\nconst lch2lab = (...args) => {\n /"
},
{
"path": "src/io/lch/lch2rgb.js",
"chars": 379,
"preview": "import { unpack } from '../../utils/index.js';\nimport lch2lab from './lch2lab.js';\nimport lab2rgb from '../lab/lab2rgb.j"
},
{
"path": "src/io/lch/rgb2lch.js",
"chars": 394,
"preview": "import { unpack } from '../../utils/index.js';\nimport rgb2lab from '../lab/rgb2lab.js';\nimport lab2lch from './lab2lch.j"
},
{
"path": "src/io/named/index.js",
"chars": 806,
"preview": "import Color from '../../Color.js';\nimport input from '../input.js';\nimport { type } from '../../utils/index.js';\n\nimpor"
},
{
"path": "src/io/num/index.js",
"chars": 693,
"preview": "import chroma from '../../chroma.js';\nimport Color from '../../Color.js';\nimport input from '../input.js';\nimport { type"
},
{
"path": "src/io/num/num2rgb.js",
"chars": 346,
"preview": "import { type } from '../../utils/index.js';\n\nconst num2rgb = (num) => {\n if (type(num) == 'number' && num >= 0 && nu"
},
{
"path": "src/io/num/rgb2num.js",
"chars": 187,
"preview": "import { unpack } from '../../utils/index.js';\n\nconst rgb2num = (...args) => {\n const [r, g, b] = unpack(args, 'rgb')"
},
{
"path": "src/io/oklab/index.js",
"chars": 663,
"preview": "import { unpack, type } from '../../utils/index.js';\nimport chroma from '../../chroma.js';\nimport Color from '../../Colo"
},
{
"path": "src/io/oklab/oklab2rgb.js",
"chars": 1185,
"preview": "import { unpack } from '../../utils/index.js';\nimport multiplyMatrices from '../../utils/multiply-matrices.js';\nimport {"
},
{
"path": "src/io/oklab/rgb2oklab.js",
"chars": 1434,
"preview": "import { unpack } from '../../utils/index.js';\nimport multiplyMatrices from '../../utils/multiply-matrices.js';\nimport {"
},
{
"path": "src/io/oklch/index.js",
"chars": 663,
"preview": "import { unpack, type } from '../../utils/index.js';\nimport chroma from '../../chroma.js';\nimport Color from '../../Colo"
},
{
"path": "src/io/oklch/oklch2rgb.js",
"chars": 428,
"preview": "import { unpack } from '../../utils/index.js';\nimport lch2lab from '../lch/lch2lab.js';\nimport oklab2rgb from '../oklab/"
},
{
"path": "src/io/oklch/rgb2oklch.js",
"chars": 411,
"preview": "import { unpack } from '../../utils/index.js';\nimport rgb2oklab from '../oklab/rgb2oklab.js';\nimport lab2lch from '../lc"
},
{
"path": "src/io/rgb/index.js",
"chars": 1137,
"preview": "import chroma from '../../chroma.js';\nimport Color from '../../Color.js';\nimport input from '../input.js';\nimport { unpa"
},
{
"path": "src/io/temp/index.js",
"chars": 657,
"preview": "import chroma from '../../chroma.js';\nimport Color from '../../Color.js';\nimport input from '../input.js';\nimport temper"
},
{
"path": "src/io/temp/rgb2temperature.js",
"chars": 744,
"preview": "/*\n * Based on implementation by Neil Bartlett\n * https://github.com/neilbartlett/color-temperature\n **/\n\nimport tempera"
},
{
"path": "src/io/temp/temperature2rgb.js",
"chars": 1014,
"preview": "/*\n * Based on implementation by Neil Bartlett\n * https://github.com/neilbartlett/color-temperature\n */\n\nconst { log } ="
},
{
"path": "src/ops/alpha.js",
"chars": 383,
"preview": "import Color from '../Color.js';\nimport { type } from '../utils/index.js';\n\nColor.prototype.alpha = function (a, mutate "
},
{
"path": "src/ops/clipped.js",
"chars": 117,
"preview": "import Color from '../Color.js';\n\nColor.prototype.clipped = function () {\n return this._rgb._clipped || false;\n};\n"
},
{
"path": "src/ops/darken.js",
"chars": 508,
"preview": "import '../io/lab/index.js';\nimport Color from '../Color.js';\nimport LAB_CONSTANTS from '../io/lab/lab-constants.js';\n\nC"
},
{
"path": "src/ops/get.js",
"chars": 392,
"preview": "import Color from '../Color.js';\n\nColor.prototype.get = function (mc) {\n const [mode, channel] = mc.split('.');\n c"
},
{
"path": "src/ops/luminance.js",
"chars": 1642,
"preview": "import Color from '../Color.js';\nimport { type } from '../utils/index.js';\nconst { pow } = Math;\n\nconst EPS = 1e-7;\ncons"
},
{
"path": "src/ops/mix.js",
"chars": 218,
"preview": "import Color from '../Color.js';\nimport mix from '../generator/mix.js';\n\nColor.prototype.mix = Color.prototype.interpola"
},
{
"path": "src/ops/premultiply.js",
"chars": 337,
"preview": "import Color from '../Color.js';\n\nColor.prototype.premultiply = function (mutate = false) {\n const rgb = this._rgb;\n "
},
{
"path": "src/ops/saturate.js",
"chars": 443,
"preview": "import '../io/lch/index.js';\nimport Color from '../Color.js';\nimport LAB_CONSTANTS from '../io/lab/lab-constants.js';\n\nC"
},
{
"path": "src/ops/set.js",
"chars": 1423,
"preview": "import Color from '../Color.js';\nimport { type } from '../utils/index.js';\n\nColor.prototype.set = function (mc, value, m"
},
{
"path": "src/ops/shade.js",
"chars": 302,
"preview": "import '../io/lab/index.js';\nimport Color from '../Color.js';\nimport mix from '../generator/mix.js';\n\nColor.prototype.ti"
},
{
"path": "src/utils/analyze.js",
"chars": 5661,
"preview": "import type from './type.js';\n\nconst { log, pow, floor, abs } = Math;\n\nexport function analyze(data, key = null) {\n c"
},
{
"path": "src/utils/clip_rgb.js",
"chars": 392,
"preview": "import limit from './limit.js';\n\nexport default (rgb) => {\n rgb._clipped = false;\n rgb._unclipped = rgb.slice(0);\n"
},
{
"path": "src/utils/contrast.js",
"chars": 377,
"preview": "import Color from '../Color.js';\nimport '../ops/luminance.js';\n\nexport default (a, b) => {\n // WCAG contrast ratio\n "
},
{
"path": "src/utils/contrastAPCA.js",
"chars": 2101,
"preview": "import Color from '../Color.js';\nimport mix from '../generator/mix.js';\n\n/**\n * @license\n *\n * The APCA contrast predict"
},
{
"path": "src/utils/delta-e.js",
"chars": 2362,
"preview": "import Color from '../Color.js';\nconst { sqrt, pow, min, max, atan2, abs, cos, sin, exp, PI } = Math;\n\nexport default fu"
},
{
"path": "src/utils/distance.js",
"chars": 457,
"preview": "import Color from '../Color.js';\n\n// simple Euclidean distance\nexport default function (a, b, mode = 'lab') {\n // Del"
},
{
"path": "src/utils/index.js",
"chars": 736,
"preview": "const { PI, min, max } = Math;\n\nconst rnd2 = (a) => Math.round(a * 100) / 100;\nconst rnd3 = (a) => Math.round(a * 100) /"
},
{
"path": "src/utils/last.js",
"chars": 212,
"preview": "import type from './type.js';\n\nexport default (args) => {\n if (args.length < 2) return null;\n const l = args.lengt"
},
{
"path": "src/utils/limit.js",
"chars": 109,
"preview": "const { min, max } = Math;\n\nexport default (x, low = 0, high = 1) => {\n return min(max(low, x), high);\n};\n"
},
{
"path": "src/utils/multiply-matrices.js",
"chars": 936,
"preview": "// from https://www.w3.org/TR/css-color-4/multiply-matrices.js\nexport default function multiplyMatrices(A, B) {\n let "
},
{
"path": "src/utils/scales.js",
"chars": 386,
"preview": "// some pre-defined color scales:\nimport chroma from '../chroma.js';\nimport '../io/hsl/index.js';\nimport scale from '../"
},
{
"path": "src/utils/type.js",
"chars": 372,
"preview": "// ported from jQuery's $.type\nconst classToType = {};\nfor (let name of [\n 'Boolean',\n 'Number',\n 'String',\n "
},
{
"path": "src/utils/unpack.js",
"chars": 659,
"preview": "import type from './type.js';\n\nexport default (args, keyOrder = null) => {\n // if called with more than 3 arguments, "
},
{
"path": "src/utils/valid.js",
"chars": 208,
"preview": "import Color from '../Color.js';\n\nexport default (...args) => {\n try {\n new Color(...args);\n return tru"
},
{
"path": "src/version.js",
"chars": 67,
"preview": "// this gets updated automatically\nexport const version = '3.2.0';\n"
},
{
"path": "test/alpha.test.js",
"chars": 4443,
"preview": "import { describe, it, expect } from 'vitest';\nimport chroma from 'chroma-js';\n\ndescribe('Tests for the alpha channel', "
},
{
"path": "test/analyze.test.js",
"chars": 1643,
"preview": "import { describe, it, expect } from 'vitest';\nimport chroma from 'chroma-js';\n\nconst analyze = chroma.analyze;\n\ndescrib"
},
{
"path": "test/autodetect.test.js",
"chars": 1546,
"preview": "import { describe, it, expect } from 'vitest';\nimport chroma from 'chroma-js';\n\ndescribe('autodetect color', () => {\n "
},
{
"path": "test/average.test.js",
"chars": 1829,
"preview": "import { describe, it, expect } from 'vitest';\nimport chroma from 'chroma-js';\n\nconst average = chroma.average;\n\nconst c"
},
{
"path": "test/bezier.test.js",
"chars": 2995,
"preview": "import { describe, it, expect } from 'vitest';\nimport chroma from 'chroma-js';\n\nconst bezier = chroma.bezier;\n\ndescribe("
},
{
"path": "test/blend.test.js",
"chars": 730,
"preview": "import { describe, it, expect } from 'vitest';\nimport chroma from 'chroma-js';\n\nconst blend = chroma.blend;\n\ndescribe('T"
},
{
"path": "test/color.test.js",
"chars": 1754,
"preview": "import { describe, it, expect } from 'vitest';\nimport chroma from 'chroma-js';\n\nconst Color = chroma.Color;\n\nconst hexCo"
},
{
"path": "test/colorbrewer.test.js",
"chars": 808,
"preview": "import { describe, it, expect } from 'vitest';\nimport chroma from 'chroma-js';\n\ndescribe('ColorBrewer palettes', () => {"
},
{
"path": "test/contrast.test.js",
"chars": 2087,
"preview": "import { describe, it, expect } from 'vitest';\nimport contrastAPCA from '../src/utils/contrastAPCA.js';\nimport chroma fr"
},
{
"path": "test/converters.test.js",
"chars": 1807,
"preview": "import { describe, it, expect } from 'vitest';\nimport chroma from 'chroma-js';\n\ndescribe('Testing color conversions', ()"
},
{
"path": "test/cubehelix.test.js",
"chars": 3267,
"preview": "import { describe, it, expect } from 'vitest';\nimport chroma from 'chroma-js';\n\nconst cubehelix = chroma.cubehelix;\n\ndes"
},
{
"path": "test/delta-e.test.js",
"chars": 1068,
"preview": "import { describe, it, expect } from 'vitest';\nimport chroma from 'chroma-js';\n\nconst deltaE = chroma.deltaE;\n\n// due to"
},
{
"path": "test/docs/index.test.js",
"chars": 1011,
"preview": "/* eslint-disable no-unused-vars */\nimport { describe, it, expect } from 'vitest';\nimport fs from 'node:fs';\nimport path"
},
{
"path": "test/html/bezier.html",
"chars": 1954,
"preview": "<!doctype html>\n<html>\n <head>\n <title>Bezier Interpolation</title>\n <script type=\"text/javascript\" src"
},
{
"path": "test/html/blend.html",
"chars": 2433,
"preview": "<!doctype html>\n<html>\n <head>\n <title>Chroma.js</title>\n <script type=\"text/javascript\" src=\"../../chr"
},
{
"path": "test/html/colorscales.html",
"chars": 3935,
"preview": "<!doctype html>\n<html>\n <head>\n <title>Chroma.js</title>\n <script type=\"text/javascript\" src=\"../chroma"
},
{
"path": "test/html/cubehelix.html",
"chars": 2198,
"preview": "<!doctype html>\n<html>\n <head>\n <title>Cubejelix Interpolation</title>\n <script\n type=\"text/"
},
{
"path": "test/html/luminance.html",
"chars": 1764,
"preview": "<!doctype html>\n<html>\n <head>\n <title>Chroma.js</title>\n <script type=\"text/javascript\" src=\"../../chr"
},
{
"path": "test/io/cmyk2rgb.test.js",
"chars": 2377,
"preview": "import { describe, it, expect } from 'vitest';\nimport cmyk2rgb from '../../src/io/cmyk/cmyk2rgb.js';\n\nconst cmykColors ="
},
{
"path": "test/io/css2rgb.test.js",
"chars": 2443,
"preview": "import { describe, it, expect } from 'vitest';\nimport chroma from 'chroma-js';\n\nconst css2rgb = chroma.input.format.css;"
},
{
"path": "test/io/hcg2rgb.test.js",
"chars": 1378,
"preview": "import { describe, it, expect } from 'vitest';\nimport hcg2rgb from '../../src/io/hcg/hcg2rgb.js';\n\ndescribe('Testing HCG"
},
{
"path": "test/io/hex2rgb.test.js",
"chars": 4174,
"preview": "import { describe, it, expect } from 'vitest';\nimport hex2rgb from '../../src/io/hex/hex2rgb.js';\n\ndescribe('Testing HEX"
},
{
"path": "test/io/hsi2rgb.test.js",
"chars": 1664,
"preview": "import { describe, it, expect } from 'vitest';\nimport hsi2rgb from '../../src/io/hsi/hsi2rgb.js';\n\nconst round = (digits"
},
{
"path": "test/io/hsl2rgb.test.js",
"chars": 1423,
"preview": "import { describe, it, expect } from 'vitest';\nimport hsl2rgb from '../../src/io/hsl/hsl2rgb.js';\n\ndescribe('Testing HSL"
},
{
"path": "test/io/hsv2rgb.test.js",
"chars": 969,
"preview": "import { describe, it, expect } from 'vitest';\nimport hsv2rgb from '../../src/io/hsv/hsv2rgb.js';\n\ndescribe('Testing HSV"
},
{
"path": "test/io/lab2lch.test.js",
"chars": 1696,
"preview": "import { describe, it, expect } from 'vitest';\nimport lab2lch from '../../src/io/lch/lab2lch.js';\n\nconst testCases = [\n "
},
{
"path": "test/io/lab2rgb.test.js",
"chars": 2275,
"preview": "import { describe, it, expect } from 'vitest';\nimport chroma from 'chroma-js';\nimport lab2rgb from '../../src/io/lab/lab"
},
{
"path": "test/io/lch2lab.test.js",
"chars": 1701,
"preview": "import { describe, it, expect } from 'vitest';\nimport lch2lab from '../../src/io/lch/lch2lab.js';\n\nconst testCases = [\n "
},
{
"path": "test/io/lch2rgb.test.js",
"chars": 1624,
"preview": "import { describe, it, expect } from 'vitest';\nimport limit from '../../src/utils/limit.js';\nimport lch2rgb from '../../"
},
{
"path": "test/io/num2rgb.test.js",
"chars": 911,
"preview": "import { describe, it, expect } from 'vitest';\nimport num2rgb from '../../src/io/num/num2rgb.js';\n\ndescribe('Testing num"
},
{
"path": "test/io/oklab2rgb.test.js",
"chars": 1648,
"preview": "import { describe, it, expect } from 'vitest';\nimport limit from '../../src/utils/limit.js';\nimport oklab2rgb from '../."
},
{
"path": "test/io/oklch2rgb.test.js",
"chars": 1831,
"preview": "import { describe, it, expect } from 'vitest';\nimport limit from '../../src/utils/limit.js';\nimport oklch2rgb from '../."
},
{
"path": "test/io/rgb2cmyk.test.js",
"chars": 844,
"preview": "import { describe, it, expect } from 'vitest';\nimport rgb2cmyk from '../../src/io/cmyk/rgb2cmyk.js';\n\nconst tests = {\n "
},
{
"path": "test/io/rgb2css.test.js",
"chars": 3078,
"preview": "import { describe, it, expect } from 'vitest';\nimport rgb2css from '../../src/io/css/rgb2css.js';\n\nconst tests = {\n b"
},
{
"path": "test/io/rgb2hex.test.js",
"chars": 1685,
"preview": "import { describe, it, expect } from 'vitest';\nimport rgb2hex from '../../src/io/hex/rgb2hex.js';\n\nconst tests = {\n b"
},
{
"path": "test/io/rgb2hsi.test.js",
"chars": 1433,
"preview": "import { describe, it, expect } from 'vitest';\nimport rgb2hsi from '../../src/io/hsi/rgb2hsi.js';\n\nconst tests = {\n b"
},
{
"path": "test/io/rgb2hsv.test.js",
"chars": 1152,
"preview": "import { describe, it, expect } from 'vitest';\nimport rgb2hsv from '../../src/io/hsv/rgb2hsv.js';\n\nconst tests = {\n b"
},
{
"path": "test/io/rgb2lab.test.js",
"chars": 2064,
"preview": "import { describe, it, expect } from 'vitest';\nimport rgb2lab from '../../src/io/lab/rgb2lab.js';\nimport chroma from 'ch"
},
{
"path": "test/io/rgb2lch.test.js",
"chars": 1415,
"preview": "import { describe, it, expect } from 'vitest';\nimport rgb2lch from '../../src/io/lch/rgb2lch.js';\n\nconst round = (digits"
},
{
"path": "test/io/rgb2oklab.test.js",
"chars": 1509,
"preview": "import { describe, it, expect } from 'vitest';\nimport rgb2oklab from '../../src/io/oklab/rgb2oklab.js';\n\nconst round = ("
},
{
"path": "test/io/rgb2oklch.test.js",
"chars": 1612,
"preview": "import { describe, it, expect } from 'vitest';\nimport rgb2oklch from '../../src/io/oklch/rgb2oklch.js';\n\nconst tests = {"
},
{
"path": "test/lch.test.js",
"chars": 1718,
"preview": "import { describe, it, expect } from 'vitest';\nimport chroma from 'chroma-js';\n\ndescribe('Some tests for chroma.lch()', "
},
{
"path": "test/limits.test.js",
"chars": 1833,
"preview": "import { describe, it, expect } from 'vitest';\nimport { limits } from '../src/utils/analyze.js';\n\ndescribe('Some tests f"
},
{
"path": "test/luminance.test.js",
"chars": 2859,
"preview": "import { describe, it, expect } from 'vitest';\nimport chroma from 'chroma-js';\n\nconst rnd = function (f, d) {\n d = Ma"
},
{
"path": "test/manipulate.test.js",
"chars": 2614,
"preview": "import { describe, it, expect } from 'vitest';\nimport chroma from 'chroma-js';\n\ndescribe('Manipulating colors', () => {\n"
},
{
"path": "test/misc.test.js",
"chars": 4496,
"preview": "import { describe, it, expect } from 'vitest';\nimport chroma from 'chroma-js';\n\nconst round = function (digits) {\n va"
},
{
"path": "test/mix.test.js",
"chars": 3667,
"preview": "import { describe, it, expect } from 'vitest';\nimport chroma from 'chroma-js';\n\ndescribe('Some tests for chroma.color()'"
},
{
"path": "test/num.test.js",
"chars": 856,
"preview": "import { describe, it, expect } from 'vitest';\nimport chroma from 'chroma-js';\n\ndescribe('Some tests for chroma.num()', "
},
{
"path": "test/premultiply.test.js",
"chars": 589,
"preview": "import { describe, it, expect } from 'vitest';\nimport chroma from 'chroma-js';\n\ndescribe('Premultiply colors', () => {\n "
},
{
"path": "test/random.test.js",
"chars": 606,
"preview": "import { describe, it, expect } from 'vitest';\nimport chroma from 'chroma-js';\nimport { vitest } from 'vitest';\n\ndescrib"
},
{
"path": "test/scale.lcorrection.test.js",
"chars": 2081,
"preview": "import { describe, it, expect } from 'vitest';\nimport chroma from 'chroma-js';\n\nconst scale = chroma.scale;\n\ndescribe('T"
},
{
"path": "test/scales.test.js",
"chars": 11516,
"preview": "import { describe, it, expect } from 'vitest';\nimport chroma from 'chroma-js';\n\nconst scale = chroma.scale;\n\ndescribe('S"
},
{
"path": "test/temperature2rgb.test.js",
"chars": 805,
"preview": "import { describe, it, expect } from 'vitest';\nimport temperature2rgb from '../src/io/temp/temperature2rgb.js';\n\nconst {"
},
{
"path": "test/unpack.test.js",
"chars": 517,
"preview": "import { describe, it, expect } from 'vitest';\nimport unpack from '../src/utils/unpack.js';\n\ndescribe('Testing unpack', "
},
{
"path": "test/valid.test.js",
"chars": 464,
"preview": "import { describe, it, expect } from 'vitest';\nimport chroma from 'chroma-js';\n\nconst valid = chroma.valid;\n\ndescribe('S"
}
]
// ... and 1 more files (download for full content)
About this extraction
This page contains the full source code of the gka/chroma.js GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 201 files (1.2 MB), approximately 401.0k tokens, and a symbol index with 604 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.