feat(auth): implement user authentication system
This commit is contained in:
parent
4847ab793a
commit
25cea4fbe8
12051 changed files with 1462377 additions and 0 deletions
21
backend/node_modules/color/LICENSE
generated
vendored
Normal file
21
backend/node_modules/color/LICENSE
generated
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
Copyright (c) 2012 Heather Arthur
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
183
backend/node_modules/color/README.md
generated
vendored
Normal file
183
backend/node_modules/color/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,183 @@
|
|||
# color
|
||||
|
||||
> JavaScript library for immutable color conversion and manipulation with support for CSS color strings.
|
||||
|
||||
```js
|
||||
const color = Color('#7743CE').alpha(0.5).lighten(0.5);
|
||||
console.log(color.hsl().string()); // 'hsla(262, 59%, 81%, 0.5)'
|
||||
|
||||
console.log(color.cmyk().round().array()); // [ 16, 25, 0, 8, 0.5 ]
|
||||
|
||||
console.log(color.ansi256().object()); // { ansi256: 183, alpha: 0.5 }
|
||||
```
|
||||
|
||||
## Install
|
||||
```shell
|
||||
npm install color
|
||||
```
|
||||
|
||||
## Usage
|
||||
```js
|
||||
import Color from 'color';
|
||||
```
|
||||
|
||||
### Constructors
|
||||
```js
|
||||
// string constructor
|
||||
const color = Color('rgb(255, 255, 255)') // { model: 'rgb', color: [ 255, 255, 255 ], valpha: 1 }
|
||||
const color = Color('hsl(194, 53%, 79%)') // { model: 'hsl', color: [ 195, 53, 79 ], valpha: 1 }
|
||||
const color = Color('hsl(194, 53%, 79%, 0.5)') // { model: 'hsl', color: [ 195, 53, 79 ], valpha: 0.5 }
|
||||
const color = Color('#FF0000') // { model: 'rgb', color: [ 255, 0, 0 ], valpha: 1 }
|
||||
const color = Color('#FF000033') // { model: 'rgb', color: [ 255, 0, 0 ], valpha: 0.2 }
|
||||
const color = Color('lightblue') // { model: 'rgb', color: [ 173, 216, 230 ], valpha: 1 }
|
||||
const color = Color('purple') // { model: 'rgb', color: [ 128, 0, 128 ], valpha: 1 }
|
||||
|
||||
// rgb
|
||||
const color = Color({r: 255, g: 255, b: 255}) // { model: 'rgb', color: [ 255, 255, 255 ], valpha: 1 }
|
||||
const color = Color({r: 255, g: 255, b: 255, alpha: 0.5}) // { model: 'rgb', color: [ 255, 255, 255 ], valpha: 0.5 }
|
||||
const color = Color.rgb(255, 255, 255) // { model: 'rgb', color: [ 255, 255, 255 ], valpha: 1 }
|
||||
const color = Color.rgb(255, 255, 255, 0.5) // { model: 'rgb', color: [ 255, 255, 255 ], valpha: 0.5 }
|
||||
const color = Color.rgb(0xFF, 0x00, 0x00, 0.5) // { model: 'rgb', color: [ 255, 0, 0 ], valpha: 0.5 }
|
||||
const color = Color.rgb([255, 255, 255]) // { model: 'rgb', color: [ 255, 255, 255 ], valpha: 1 }
|
||||
const color = Color.rgb([0xFF, 0x00, 0x00, 0.5]) // { model: 'rgb', color: [ 255, 0, 0 ], valpha: 0.5 }
|
||||
|
||||
// hsl
|
||||
const color = Color({h: 194, s: 53, l: 79}) // { model: 'hsl', color: [ 195, 53, 79 ], valpha: 1 }
|
||||
const color = Color({h: 194, s: 53, l: 79, alpha: 0.5}) // { model: 'hsl', color: [ 195, 53, 79 ], valpha: 0.5 }
|
||||
const color = Color.hsl(194, 53, 79) // { model: 'hsl', color: [ 195, 53, 79 ], valpha: 1 }
|
||||
|
||||
// hsv
|
||||
const color = Color({h: 195, s: 25, v: 99}) // { model: 'hsv', color: [ 195, 25, 99 ], valpha: 1 }
|
||||
const color = Color({h: 195, s: 25, v: 99, alpha: 0.5}) // { model: 'hsv', color: [ 195, 25, 99 ], valpha: 0.5 }
|
||||
const color = Color.hsv(195, 25, 99) // { model: 'hsv', color: [ 195, 25, 99 ], valpha: 1 }
|
||||
const color = Color.hsv([195, 25, 99]) // { model: 'hsv', color: [ 195, 25, 99 ], valpha: 1 }
|
||||
|
||||
// cmyk
|
||||
const color = Color({c: 0, m: 100, y: 100, k: 0}) // { model: 'cmyk', color: [ 0, 100, 100, 0 ], valpha: 1 }
|
||||
const color = Color({c: 0, m: 100, y: 100, k: 0, alpha: 0.5}) // { model: 'cmyk', color: [ 0, 100, 100, 0 ], valpha: 0.5 }
|
||||
const color = Color.cmyk(0, 100, 100, 0) // { model: 'cmyk', color: [ 0, 100, 100, 0 ], valpha: 1 }
|
||||
const color = Color.cmyk(0, 100, 100, 0, 0.5) // { model: 'cmyk', color: [ 0, 100, 100, 0 ], valpha: 0.5 }
|
||||
|
||||
// hwb
|
||||
const color = Color({h: 180, w: 0, b: 0}) // { model: 'hwb', color: [ 180, 0, 0 ], valpha: 1 }
|
||||
const color = Color.hwb(180, 0, 0) // { model: 'hwb', color: [ 180, 0, 0 ], valpha: 1 }
|
||||
|
||||
// lch
|
||||
const color = Color({l: 53, c: 105, h: 40}) // { model: 'lch', color: [ 53, 105, 40 ], valpha: 1 }
|
||||
const color = Color.lch(53, 105, 40) // { model: 'lch', color: [ 53, 105, 40 ], valpha: 1 }
|
||||
|
||||
// lab
|
||||
const color = Color({l: 53, a: 80, b: 67}) // { model: 'lab', color: [ 53, 80, 67 ], valpha: 1 }
|
||||
const color = Color.lab(53, 80, 67) // { model: 'lab', color: [ 53, 80, 67 ], valpha: 1 }
|
||||
|
||||
// hcg
|
||||
const color = Color({h: 0, c: 100, g: 0}) // { model: 'hcg', color: [ 0, 100, 0 ], valpha: 1 }
|
||||
const color = Color.hcg(0, 100, 0) // { model: 'hcg', color: [ 0, 100, 0 ], valpha: 1 }
|
||||
|
||||
// ansi16
|
||||
const color = Color.ansi16(91) // { model: 'ansi16', color: [ 91 ], valpha: 1 }
|
||||
const color = Color.ansi16(91, 0.5) // { model: 'ansi16', color: [ 91 ], valpha: 0.5 }
|
||||
|
||||
// ansi256
|
||||
const color = Color.ansi256(196) // { model: 'ansi256', color: [ 196 ], valpha: 1 }
|
||||
const color = Color.ansi256(196, 0.5) // { model: 'ansi256', color: [ 196 ], valpha: 0.5 }
|
||||
|
||||
// apple
|
||||
const color = Color.apple(65535, 65535, 65535) // { model: 'apple', color: [ 65535, 65535, 65535 ], valpha: 1 }
|
||||
const color = Color.apple([65535, 65535, 65535]) // { model: 'apple', color: [ 65535, 65535, 65535 ], valpha: 1 }
|
||||
|
||||
|
||||
```
|
||||
|
||||
Set the values for individual channels with `alpha`, `red`, `green`, `blue`, `hue`, `saturationl` (hsl), `saturationv` (hsv), `lightness`, `whiteness`, `blackness`, `cyan`, `magenta`, `yellow`, `black`
|
||||
|
||||
String constructors are handled by [color-string](https://www.npmjs.com/package/color-string)
|
||||
|
||||
### Getters
|
||||
```js
|
||||
color.hsl()
|
||||
```
|
||||
Convert a color to a different space (`hsl()`, `cmyk()`, etc.).
|
||||
|
||||
```js
|
||||
color.object() // {r: 255, g: 255, b: 255}
|
||||
```
|
||||
Get a hash of the color value. Reflects the color's current model (see above).
|
||||
|
||||
```js
|
||||
color.rgb().array() // [255, 255, 255]
|
||||
```
|
||||
Get an array of the values with `array()`. Reflects the color's current model (see above).
|
||||
|
||||
```js
|
||||
color.rgbNumber() // 16777215 (0xffffff)
|
||||
```
|
||||
Get the rgb number value.
|
||||
|
||||
```js
|
||||
color.hex() // #ffffff
|
||||
```
|
||||
Get the hex value. (**NOTE:** `.hex()` does not return alpha values; use `.hexa()` for an RGBA representation)
|
||||
|
||||
```js
|
||||
color.red() // 255
|
||||
```
|
||||
Get the value for an individual channel.
|
||||
|
||||
### CSS Strings
|
||||
```js
|
||||
color.hsl().string() // 'hsl(320, 50%, 100%)'
|
||||
```
|
||||
|
||||
Calling `.string()` with a number rounds the numbers to that decimal place. It defaults to 1.
|
||||
|
||||
### Luminosity
|
||||
```js
|
||||
color.luminosity(); // 0.412
|
||||
```
|
||||
The [WCAG luminosity](http://www.w3.org/TR/WCAG20/#relativeluminancedef) of the color. 0 is black, 1 is white.
|
||||
|
||||
```js
|
||||
color.contrast(Color("blue")) // 12
|
||||
```
|
||||
The [WCAG contrast ratio](http://www.w3.org/TR/WCAG20/#contrast-ratiodef) to another color, from 1 (same color) to 21 (contrast b/w white and black).
|
||||
|
||||
```js
|
||||
color.isLight() // true
|
||||
color.isDark() // false
|
||||
```
|
||||
Get whether the color is "light" or "dark", useful for deciding text color.
|
||||
|
||||
### Manipulation
|
||||
```js
|
||||
color.negate() // rgb(0, 100, 255) -> rgb(255, 155, 0)
|
||||
|
||||
color.lighten(0.5) // hsl(100, 50%, 50%) -> hsl(100, 50%, 75%)
|
||||
color.lighten(0.5) // hsl(100, 50%, 0) -> hsl(100, 50%, 0)
|
||||
color.darken(0.5) // hsl(100, 50%, 50%) -> hsl(100, 50%, 25%)
|
||||
color.darken(0.5) // hsl(100, 50%, 0) -> hsl(100, 50%, 0)
|
||||
|
||||
color.lightness(50) // hsl(100, 50%, 10%) -> hsl(100, 50%, 50%)
|
||||
|
||||
color.saturate(0.5) // hsl(100, 50%, 50%) -> hsl(100, 75%, 50%)
|
||||
color.desaturate(0.5) // hsl(100, 50%, 50%) -> hsl(100, 25%, 50%)
|
||||
color.grayscale() // #5CBF54 -> #969696
|
||||
|
||||
color.whiten(0.5) // hwb(100, 50%, 50%) -> hwb(100, 75%, 50%)
|
||||
color.blacken(0.5) // hwb(100, 50%, 50%) -> hwb(100, 50%, 75%)
|
||||
|
||||
color.fade(0.5) // rgba(10, 10, 10, 0.8) -> rgba(10, 10, 10, 0.4)
|
||||
color.opaquer(0.5) // rgba(10, 10, 10, 0.8) -> rgba(10, 10, 10, 1.0)
|
||||
|
||||
color.rotate(180) // hsl(60, 20%, 20%) -> hsl(240, 20%, 20%)
|
||||
color.rotate(-90) // hsl(60, 20%, 20%) -> hsl(330, 20%, 20%)
|
||||
|
||||
color.mix(Color("yellow")) // cyan -> rgb(128, 255, 128)
|
||||
color.mix(Color("yellow"), 0.3) // cyan -> rgb(77, 255, 179)
|
||||
|
||||
// chaining
|
||||
color.green(100).grayscale().lighten(0.6)
|
||||
```
|
||||
|
||||
## Propers
|
||||
The API was inspired by [color-js](https://github.com/brehaut/color-js). Manipulation functions by CSS tools like Sass, LESS, and Stylus.
|
||||
135
backend/node_modules/color/index.d.ts
generated
vendored
Normal file
135
backend/node_modules/color/index.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
import type convert from 'color-convert';
|
||||
|
||||
export type ColorLike = ColorInstance | string | ArrayLike<number> | number | Record<string, any>;
|
||||
export type ColorJson = {model: string; color: number[]; valpha: number};
|
||||
export type ColorObject = {alpha?: number | undefined} & Record<string, number>;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
||||
export interface ColorInstance {
|
||||
toString(): string;
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
toJSON(): ColorJson;
|
||||
string(places?: number): string;
|
||||
percentString(places?: number): string;
|
||||
array(): number[];
|
||||
object(): ColorObject;
|
||||
unitArray(): number[];
|
||||
unitObject(): {r: number; g: number; b: number; alpha?: number | undefined};
|
||||
round(places?: number): ColorInstance;
|
||||
alpha(): number;
|
||||
alpha(value: number): ColorInstance;
|
||||
red(): number;
|
||||
red(value: number): ColorInstance;
|
||||
green(): number;
|
||||
green(value: number): ColorInstance;
|
||||
blue(): number;
|
||||
blue(value: number): ColorInstance;
|
||||
hue(): number;
|
||||
hue(value: number): ColorInstance;
|
||||
saturationl(): number;
|
||||
saturationl(value: number): ColorInstance;
|
||||
lightness(): number;
|
||||
lightness(value: number): ColorInstance;
|
||||
saturationv(): number;
|
||||
saturationv(value: number): ColorInstance;
|
||||
value(): number;
|
||||
value(value: number): ColorInstance;
|
||||
chroma(): number;
|
||||
chroma(value: number): ColorInstance;
|
||||
gray(): number;
|
||||
gray(value: number): ColorInstance;
|
||||
white(): number;
|
||||
white(value: number): ColorInstance;
|
||||
wblack(): number;
|
||||
wblack(value: number): ColorInstance;
|
||||
cyan(): number;
|
||||
cyan(value: number): ColorInstance;
|
||||
magenta(): number;
|
||||
magenta(value: number): ColorInstance;
|
||||
yellow(): number;
|
||||
yellow(value: number): ColorInstance;
|
||||
black(): number;
|
||||
black(value: number): ColorInstance;
|
||||
x(): number;
|
||||
x(value: number): ColorInstance;
|
||||
y(): number;
|
||||
y(value: number): ColorInstance;
|
||||
z(): number;
|
||||
z(value: number): ColorInstance;
|
||||
l(): number;
|
||||
l(value: number): ColorInstance;
|
||||
a(): number;
|
||||
a(value: number): ColorInstance;
|
||||
b(): number;
|
||||
b(value: number): ColorInstance;
|
||||
keyword(): string;
|
||||
keyword<V extends string>(value: V): ColorInstance;
|
||||
hex(): string;
|
||||
hex<V extends string>(value: V): ColorInstance;
|
||||
hexa(): string;
|
||||
hexa<V extends string>(value: V): ColorInstance;
|
||||
rgbNumber(): number;
|
||||
luminosity(): number;
|
||||
contrast(color2: ColorInstance): number;
|
||||
level(color2: ColorInstance): 'AAA' | 'AA' | '';
|
||||
isDark(): boolean;
|
||||
isLight(): boolean;
|
||||
negate(): ColorInstance;
|
||||
lighten(ratio: number): ColorInstance;
|
||||
darken(ratio: number): ColorInstance;
|
||||
saturate(ratio: number): ColorInstance;
|
||||
desaturate(ratio: number): ColorInstance;
|
||||
whiten(ratio: number): ColorInstance;
|
||||
blacken(ratio: number): ColorInstance;
|
||||
grayscale(): ColorInstance;
|
||||
fade(ratio: number): ColorInstance;
|
||||
opaquer(ratio: number): ColorInstance;
|
||||
rotate(degrees: number): ColorInstance;
|
||||
mix(mixinColor: ColorInstance, weight?: number): ColorInstance;
|
||||
rgb(...arguments_: number[]): ColorInstance;
|
||||
hsl(...arguments_: number[]): ColorInstance;
|
||||
hsv(...arguments_: number[]): ColorInstance;
|
||||
hwb(...arguments_: number[]): ColorInstance;
|
||||
cmyk(...arguments_: number[]): ColorInstance;
|
||||
xyz(...arguments_: number[]): ColorInstance;
|
||||
lab(...arguments_: number[]): ColorInstance;
|
||||
lch(...arguments_: number[]): ColorInstance;
|
||||
ansi16(...arguments_: number[]): ColorInstance;
|
||||
ansi256(...arguments_: number[]): ColorInstance;
|
||||
hcg(...arguments_: number[]): ColorInstance;
|
||||
apple(...arguments_: number[]): ColorInstance;
|
||||
}
|
||||
|
||||
export type ColorConstructor = {
|
||||
(object?: ColorLike, model?: keyof (typeof convert)): ColorInstance;
|
||||
new(object?: ColorLike, model?: keyof (typeof convert)): ColorInstance;
|
||||
rgb(...value: number[]): ColorInstance;
|
||||
rgb(color: ColorLike): ColorInstance;
|
||||
hsl(...value: number[]): ColorInstance;
|
||||
hsl(color: ColorLike): ColorInstance;
|
||||
hsv(...value: number[]): ColorInstance;
|
||||
hsv(color: ColorLike): ColorInstance;
|
||||
hwb(...value: number[]): ColorInstance;
|
||||
hwb(color: ColorLike): ColorInstance;
|
||||
cmyk(...value: number[]): ColorInstance;
|
||||
cmyk(color: ColorLike): ColorInstance;
|
||||
xyz(...value: number[]): ColorInstance;
|
||||
xyz(color: ColorLike): ColorInstance;
|
||||
lab(...value: number[]): ColorInstance;
|
||||
lab(color: ColorLike): ColorInstance;
|
||||
lch(...value: number[]): ColorInstance;
|
||||
lch(color: ColorLike): ColorInstance;
|
||||
ansi16(...value: number[]): ColorInstance;
|
||||
ansi16(color: ColorLike): ColorInstance;
|
||||
ansi256(...value: number[]): ColorInstance;
|
||||
ansi256(color: ColorLike): ColorInstance;
|
||||
hcg(...value: number[]): ColorInstance;
|
||||
hcg(color: ColorLike): ColorInstance;
|
||||
apple(...value: number[]): ColorInstance;
|
||||
apple(color: ColorLike): ColorInstance;
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
declare const Color: ColorConstructor;
|
||||
|
||||
export default Color;
|
||||
496
backend/node_modules/color/index.js
generated
vendored
Normal file
496
backend/node_modules/color/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,496 @@
|
|||
import colorString from 'color-string';
|
||||
import convert from 'color-convert';
|
||||
|
||||
const skippedModels = [
|
||||
// To be honest, I don't really feel like keyword belongs in color convert, but eh.
|
||||
'keyword',
|
||||
|
||||
// Gray conflicts with some method names, and has its own method defined.
|
||||
'gray',
|
||||
|
||||
// Shouldn't really be in color-convert either...
|
||||
'hex',
|
||||
];
|
||||
|
||||
const hashedModelKeys = {};
|
||||
for (const model of Object.keys(convert)) {
|
||||
hashedModelKeys[[...convert[model].labels].sort().join('')] = model;
|
||||
}
|
||||
|
||||
const limiters = {};
|
||||
|
||||
function Color(object, model) {
|
||||
if (!(this instanceof Color)) {
|
||||
return new Color(object, model);
|
||||
}
|
||||
|
||||
if (model && model in skippedModels) {
|
||||
model = null;
|
||||
}
|
||||
|
||||
if (model && !(model in convert)) {
|
||||
throw new Error('Unknown model: ' + model);
|
||||
}
|
||||
|
||||
let i;
|
||||
let channels;
|
||||
|
||||
if (object == null) { // eslint-disable-line no-eq-null,eqeqeq
|
||||
this.model = 'rgb';
|
||||
this.color = [0, 0, 0];
|
||||
this.valpha = 1;
|
||||
} else if (object instanceof Color) {
|
||||
this.model = object.model;
|
||||
this.color = [...object.color];
|
||||
this.valpha = object.valpha;
|
||||
} else if (typeof object === 'string') {
|
||||
const result = colorString.get(object);
|
||||
if (result === null) {
|
||||
throw new Error('Unable to parse color from string: ' + object);
|
||||
}
|
||||
|
||||
this.model = result.model;
|
||||
channels = convert[this.model].channels;
|
||||
this.color = result.value.slice(0, channels);
|
||||
this.valpha = typeof result.value[channels] === 'number' ? result.value[channels] : 1;
|
||||
} else if (object.length > 0) {
|
||||
this.model = model || 'rgb';
|
||||
channels = convert[this.model].channels;
|
||||
const newArray = Array.prototype.slice.call(object, 0, channels);
|
||||
this.color = zeroArray(newArray, channels);
|
||||
this.valpha = typeof object[channels] === 'number' ? object[channels] : 1;
|
||||
} else if (typeof object === 'number') {
|
||||
// This is always RGB - can be converted later on.
|
||||
this.model = 'rgb';
|
||||
this.color = [
|
||||
(object >> 16) & 0xFF,
|
||||
(object >> 8) & 0xFF,
|
||||
object & 0xFF,
|
||||
];
|
||||
this.valpha = 1;
|
||||
} else {
|
||||
this.valpha = 1;
|
||||
|
||||
const keys = Object.keys(object);
|
||||
if ('alpha' in object) {
|
||||
keys.splice(keys.indexOf('alpha'), 1);
|
||||
this.valpha = typeof object.alpha === 'number' ? object.alpha : 0;
|
||||
}
|
||||
|
||||
const hashedKeys = keys.sort().join('');
|
||||
if (!(hashedKeys in hashedModelKeys)) {
|
||||
throw new Error('Unable to parse color from object: ' + JSON.stringify(object));
|
||||
}
|
||||
|
||||
this.model = hashedModelKeys[hashedKeys];
|
||||
|
||||
const {labels} = convert[this.model];
|
||||
const color = [];
|
||||
for (i = 0; i < labels.length; i++) {
|
||||
color.push(object[labels[i]]);
|
||||
}
|
||||
|
||||
this.color = zeroArray(color);
|
||||
}
|
||||
|
||||
// Perform limitations (clamping, etc.)
|
||||
if (limiters[this.model]) {
|
||||
channels = convert[this.model].channels;
|
||||
for (i = 0; i < channels; i++) {
|
||||
const limit = limiters[this.model][i];
|
||||
if (limit) {
|
||||
this.color[i] = limit(this.color[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.valpha = Math.max(0, Math.min(1, this.valpha));
|
||||
|
||||
if (Object.freeze) {
|
||||
Object.freeze(this);
|
||||
}
|
||||
}
|
||||
|
||||
Color.prototype = {
|
||||
toString() {
|
||||
return this.string();
|
||||
},
|
||||
|
||||
toJSON() {
|
||||
return this[this.model]();
|
||||
},
|
||||
|
||||
string(places) {
|
||||
let self = this.model in colorString.to ? this : this.rgb();
|
||||
self = self.round(typeof places === 'number' ? places : 1);
|
||||
const arguments_ = self.valpha === 1 ? self.color : [...self.color, this.valpha];
|
||||
return colorString.to[self.model](...arguments_);
|
||||
},
|
||||
|
||||
percentString(places) {
|
||||
const self = this.rgb().round(typeof places === 'number' ? places : 1);
|
||||
const arguments_ = self.valpha === 1 ? self.color : [...self.color, this.valpha];
|
||||
return colorString.to.rgb.percent(...arguments_);
|
||||
},
|
||||
|
||||
array() {
|
||||
return this.valpha === 1 ? [...this.color] : [...this.color, this.valpha];
|
||||
},
|
||||
|
||||
object() {
|
||||
const result = {};
|
||||
const {channels} = convert[this.model];
|
||||
const {labels} = convert[this.model];
|
||||
|
||||
for (let i = 0; i < channels; i++) {
|
||||
result[labels[i]] = this.color[i];
|
||||
}
|
||||
|
||||
if (this.valpha !== 1) {
|
||||
result.alpha = this.valpha;
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
unitArray() {
|
||||
const rgb = this.rgb().color;
|
||||
rgb[0] /= 255;
|
||||
rgb[1] /= 255;
|
||||
rgb[2] /= 255;
|
||||
|
||||
if (this.valpha !== 1) {
|
||||
rgb.push(this.valpha);
|
||||
}
|
||||
|
||||
return rgb;
|
||||
},
|
||||
|
||||
unitObject() {
|
||||
const rgb = this.rgb().object();
|
||||
rgb.r /= 255;
|
||||
rgb.g /= 255;
|
||||
rgb.b /= 255;
|
||||
|
||||
if (this.valpha !== 1) {
|
||||
rgb.alpha = this.valpha;
|
||||
}
|
||||
|
||||
return rgb;
|
||||
},
|
||||
|
||||
round(places) {
|
||||
places = Math.max(places || 0, 0);
|
||||
return new Color([...this.color.map(roundToPlace(places)), this.valpha], this.model);
|
||||
},
|
||||
|
||||
alpha(value) {
|
||||
if (value !== undefined) {
|
||||
return new Color([...this.color, Math.max(0, Math.min(1, value))], this.model);
|
||||
}
|
||||
|
||||
return this.valpha;
|
||||
},
|
||||
|
||||
// Rgb
|
||||
red: getset('rgb', 0, maxfn(255)),
|
||||
green: getset('rgb', 1, maxfn(255)),
|
||||
blue: getset('rgb', 2, maxfn(255)),
|
||||
|
||||
hue: getset(['hsl', 'hsv', 'hsl', 'hwb', 'hcg'], 0, value => ((value % 360) + 360) % 360),
|
||||
|
||||
saturationl: getset('hsl', 1, maxfn(100)),
|
||||
lightness: getset('hsl', 2, maxfn(100)),
|
||||
|
||||
saturationv: getset('hsv', 1, maxfn(100)),
|
||||
value: getset('hsv', 2, maxfn(100)),
|
||||
|
||||
chroma: getset('hcg', 1, maxfn(100)),
|
||||
gray: getset('hcg', 2, maxfn(100)),
|
||||
|
||||
white: getset('hwb', 1, maxfn(100)),
|
||||
wblack: getset('hwb', 2, maxfn(100)),
|
||||
|
||||
cyan: getset('cmyk', 0, maxfn(100)),
|
||||
magenta: getset('cmyk', 1, maxfn(100)),
|
||||
yellow: getset('cmyk', 2, maxfn(100)),
|
||||
black: getset('cmyk', 3, maxfn(100)),
|
||||
|
||||
x: getset('xyz', 0, maxfn(95.047)),
|
||||
y: getset('xyz', 1, maxfn(100)),
|
||||
z: getset('xyz', 2, maxfn(108.833)),
|
||||
|
||||
l: getset('lab', 0, maxfn(100)),
|
||||
a: getset('lab', 1),
|
||||
b: getset('lab', 2),
|
||||
|
||||
keyword(value) {
|
||||
if (value !== undefined) {
|
||||
return new Color(value);
|
||||
}
|
||||
|
||||
return convert[this.model].keyword(this.color);
|
||||
},
|
||||
|
||||
hex(value) {
|
||||
if (value !== undefined) {
|
||||
return new Color(value);
|
||||
}
|
||||
|
||||
return colorString.to.hex(...this.rgb().round().color);
|
||||
},
|
||||
|
||||
hexa(value) {
|
||||
if (value !== undefined) {
|
||||
return new Color(value);
|
||||
}
|
||||
|
||||
const rgbArray = this.rgb().round().color;
|
||||
|
||||
let alphaHex = Math.round(this.valpha * 255).toString(16).toUpperCase();
|
||||
if (alphaHex.length === 1) {
|
||||
alphaHex = '0' + alphaHex;
|
||||
}
|
||||
|
||||
return colorString.to.hex(...rgbArray) + alphaHex;
|
||||
},
|
||||
|
||||
rgbNumber() {
|
||||
const rgb = this.rgb().color;
|
||||
return ((rgb[0] & 0xFF) << 16) | ((rgb[1] & 0xFF) << 8) | (rgb[2] & 0xFF);
|
||||
},
|
||||
|
||||
luminosity() {
|
||||
// http://www.w3.org/TR/WCAG20/#relativeluminancedef
|
||||
const rgb = this.rgb().color;
|
||||
|
||||
const lum = [];
|
||||
for (const [i, element] of rgb.entries()) {
|
||||
const chan = element / 255;
|
||||
lum[i] = (chan <= 0.04045) ? chan / 12.92 : ((chan + 0.055) / 1.055) ** 2.4;
|
||||
}
|
||||
|
||||
return 0.2126 * lum[0] + 0.7152 * lum[1] + 0.0722 * lum[2];
|
||||
},
|
||||
|
||||
contrast(color2) {
|
||||
// http://www.w3.org/TR/WCAG20/#contrast-ratiodef
|
||||
const lum1 = this.luminosity();
|
||||
const lum2 = color2.luminosity();
|
||||
|
||||
if (lum1 > lum2) {
|
||||
return (lum1 + 0.05) / (lum2 + 0.05);
|
||||
}
|
||||
|
||||
return (lum2 + 0.05) / (lum1 + 0.05);
|
||||
},
|
||||
|
||||
level(color2) {
|
||||
// https://www.w3.org/TR/WCAG/#contrast-enhanced
|
||||
const contrastRatio = this.contrast(color2);
|
||||
if (contrastRatio >= 7) {
|
||||
return 'AAA';
|
||||
}
|
||||
|
||||
return (contrastRatio >= 4.5) ? 'AA' : '';
|
||||
},
|
||||
|
||||
isDark() {
|
||||
// YIQ equation from http://24ways.org/2010/calculating-color-contrast
|
||||
const rgb = this.rgb().color;
|
||||
const yiq = (rgb[0] * 2126 + rgb[1] * 7152 + rgb[2] * 722) / 10000;
|
||||
return yiq < 128;
|
||||
},
|
||||
|
||||
isLight() {
|
||||
return !this.isDark();
|
||||
},
|
||||
|
||||
negate() {
|
||||
const rgb = this.rgb();
|
||||
for (let i = 0; i < 3; i++) {
|
||||
rgb.color[i] = 255 - rgb.color[i];
|
||||
}
|
||||
|
||||
return rgb;
|
||||
},
|
||||
|
||||
lighten(ratio) {
|
||||
const hsl = this.hsl();
|
||||
hsl.color[2] += hsl.color[2] * ratio;
|
||||
return hsl;
|
||||
},
|
||||
|
||||
darken(ratio) {
|
||||
const hsl = this.hsl();
|
||||
hsl.color[2] -= hsl.color[2] * ratio;
|
||||
return hsl;
|
||||
},
|
||||
|
||||
saturate(ratio) {
|
||||
const hsl = this.hsl();
|
||||
hsl.color[1] += hsl.color[1] * ratio;
|
||||
return hsl;
|
||||
},
|
||||
|
||||
desaturate(ratio) {
|
||||
const hsl = this.hsl();
|
||||
hsl.color[1] -= hsl.color[1] * ratio;
|
||||
return hsl;
|
||||
},
|
||||
|
||||
whiten(ratio) {
|
||||
const hwb = this.hwb();
|
||||
hwb.color[1] += hwb.color[1] * ratio;
|
||||
return hwb;
|
||||
},
|
||||
|
||||
blacken(ratio) {
|
||||
const hwb = this.hwb();
|
||||
hwb.color[2] += hwb.color[2] * ratio;
|
||||
return hwb;
|
||||
},
|
||||
|
||||
grayscale() {
|
||||
// http://en.wikipedia.org/wiki/Grayscale#Converting_colour_to_grayscale
|
||||
const rgb = this.rgb().color;
|
||||
const value = rgb[0] * 0.3 + rgb[1] * 0.59 + rgb[2] * 0.11;
|
||||
return Color.rgb(value, value, value);
|
||||
},
|
||||
|
||||
fade(ratio) {
|
||||
return this.alpha(this.valpha - (this.valpha * ratio));
|
||||
},
|
||||
|
||||
opaquer(ratio) {
|
||||
return this.alpha(this.valpha + (this.valpha * ratio));
|
||||
},
|
||||
|
||||
rotate(degrees) {
|
||||
const hsl = this.hsl();
|
||||
let hue = hsl.color[0];
|
||||
hue = (hue + degrees) % 360;
|
||||
hue = hue < 0 ? 360 + hue : hue;
|
||||
hsl.color[0] = hue;
|
||||
return hsl;
|
||||
},
|
||||
|
||||
mix(mixinColor, weight) {
|
||||
// Ported from sass implementation in C
|
||||
// https://github.com/sass/libsass/blob/0e6b4a2850092356aa3ece07c6b249f0221caced/functions.cpp#L209
|
||||
if (!mixinColor || !mixinColor.rgb) {
|
||||
throw new Error('Argument to "mix" was not a Color instance, but rather an instance of ' + typeof mixinColor);
|
||||
}
|
||||
|
||||
const color1 = mixinColor.rgb();
|
||||
const color2 = this.rgb();
|
||||
const p = weight === undefined ? 0.5 : weight;
|
||||
|
||||
const w = 2 * p - 1;
|
||||
const a = color1.alpha() - color2.alpha();
|
||||
|
||||
const w1 = (((w * a === -1) ? w : (w + a) / (1 + w * a)) + 1) / 2;
|
||||
const w2 = 1 - w1;
|
||||
|
||||
return Color.rgb(
|
||||
w1 * color1.red() + w2 * color2.red(),
|
||||
w1 * color1.green() + w2 * color2.green(),
|
||||
w1 * color1.blue() + w2 * color2.blue(),
|
||||
color1.alpha() * p + color2.alpha() * (1 - p));
|
||||
},
|
||||
};
|
||||
|
||||
// Model conversion methods and static constructors
|
||||
for (const model of Object.keys(convert)) {
|
||||
if (skippedModels.includes(model)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const {channels} = convert[model];
|
||||
|
||||
// Conversion methods
|
||||
Color.prototype[model] = function (...arguments_) {
|
||||
if (this.model === model) {
|
||||
return new Color(this);
|
||||
}
|
||||
|
||||
if (arguments_.length > 0) {
|
||||
return new Color(arguments_, model);
|
||||
}
|
||||
|
||||
return new Color([...assertArray(convert[this.model][model].raw(this.color)), this.valpha], model);
|
||||
};
|
||||
|
||||
// 'static' construction methods
|
||||
Color[model] = function (...arguments_) {
|
||||
let color = arguments_[0];
|
||||
if (typeof color === 'number') {
|
||||
color = zeroArray(arguments_, channels);
|
||||
}
|
||||
|
||||
return new Color(color, model);
|
||||
};
|
||||
}
|
||||
|
||||
function roundTo(number, places) {
|
||||
return Number(number.toFixed(places));
|
||||
}
|
||||
|
||||
function roundToPlace(places) {
|
||||
return function (number) {
|
||||
return roundTo(number, places);
|
||||
};
|
||||
}
|
||||
|
||||
function getset(model, channel, modifier) {
|
||||
model = Array.isArray(model) ? model : [model];
|
||||
|
||||
for (const m of model) {
|
||||
(limiters[m] ||= [])[channel] = modifier;
|
||||
}
|
||||
|
||||
model = model[0];
|
||||
|
||||
return function (value) {
|
||||
let result;
|
||||
|
||||
if (value !== undefined) {
|
||||
if (modifier) {
|
||||
value = modifier(value);
|
||||
}
|
||||
|
||||
result = this[model]();
|
||||
result.color[channel] = value;
|
||||
return result;
|
||||
}
|
||||
|
||||
result = this[model]().color[channel];
|
||||
if (modifier) {
|
||||
result = modifier(result);
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
function maxfn(max) {
|
||||
return function (v) {
|
||||
return Math.max(0, Math.min(max, v));
|
||||
};
|
||||
}
|
||||
|
||||
function assertArray(value) {
|
||||
return Array.isArray(value) ? value : [value];
|
||||
}
|
||||
|
||||
function zeroArray(array, length) {
|
||||
for (let i = 0; i < length; i++) {
|
||||
if (typeof array[i] !== 'number') {
|
||||
array[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
export default Color;
|
||||
52
backend/node_modules/color/package.json
generated
vendored
Normal file
52
backend/node_modules/color/package.json
generated
vendored
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
{
|
||||
"name": "color",
|
||||
"version": "5.0.3",
|
||||
"description": "Color conversion and manipulation with CSS string support",
|
||||
"type": "module",
|
||||
"exports": "./index.js",
|
||||
"types": "./index.d.ts",
|
||||
"sideEffects": false,
|
||||
"keywords": [
|
||||
"color",
|
||||
"colour",
|
||||
"css"
|
||||
],
|
||||
"authors": [
|
||||
"Josh Junon <josh@junon.me>",
|
||||
"Heather Arthur <fayearthur@gmail.com>",
|
||||
"Maxime Thirouin"
|
||||
],
|
||||
"license": "MIT",
|
||||
"repository": "Qix-/color",
|
||||
"xo": {
|
||||
"rules": {
|
||||
"no-bitwise": 0,
|
||||
"no-cond-assign": 0,
|
||||
"new-cap": 0,
|
||||
"unicorn/prefer-module": 0,
|
||||
"no-mixed-operators": 0,
|
||||
"complexity": 0,
|
||||
"unicorn/numeric-separators-style": 0
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"LICENSE",
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "xo && tsd && mocha"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"dependencies": {
|
||||
"color-convert": "^3.1.3",
|
||||
"color-string": "^2.1.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "11.1.0",
|
||||
"tsd": "0.31.2",
|
||||
"xo": "0.60.0"
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue