@salty-css/react 0.0.1-alpha.21 → 0.0.1-alpha.210

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,15 +1,132 @@
1
- # Salty Css
1
+ ![Salty CSS Banner](https://salty-css.dev/assets/banners/dvd.svg)
2
2
 
3
- ## Basic usage example with Button
3
+ # Salty CSS - CSS-in-JS library that is kinda sweet
4
4
 
5
- ### Initial requirements
5
+ Is there anything saltier than CSS in frontend web development? Salty CSS is built to provide better developer experience for developers looking for performant and feature rich CSS-in-JS solutions.
6
6
 
7
- 1. Add `saltyPlugin` to vite or webpack config from `@salty-css/vite` or `@salty-css/webpack`
8
- 2. Create `salty.config.ts` to the root of your project
9
- 3. Import global styles to any regular .css file from `saltygen/index.css` (does not exist during first run, cli command coming later)
10
- 4. Create salty components with styled only inside files that end with `.css.ts`, `.salty.ts` `.styled.ts` or `.styles.ts`
7
+ ## Features
11
8
 
12
- ### Code examples
9
+ - Build time compilation to achieve awesome runtime performance and minimal size
10
+ - Next.js, React Server Components, Vite and Webpack support
11
+ - Type safety with out of the box TypeScript and ESLint plugin
12
+ - Advanced CSS variables configuration to allow smooth token usage
13
+ - Style templates to create reusable styles easily
14
+
15
+ ## Get started
16
+
17
+ Fastest way to get started with any framework is `npx salty-css init [directory]` command
18
+
19
+ - Next.js → [Next.js guide](#nextjs) + [Next.js example app](https://github.com/margarita-form/salty-css-website)
20
+ - React + Vite → [React + Vite guide](#react--vite) + [React example code](#code-examples)
21
+ - React + Webpack → Guide coming soon
22
+
23
+ ## Useful commands
24
+
25
+ - Create component: `npx salty-css generate [filePath]`
26
+ - Build: `npx salty-css build [directory]`
27
+ - Update Salty CSS packages: `npx salty-css up`
28
+
29
+ ## Salty CSS styled function
30
+
31
+ ```ts
32
+ // components/wrapper.css.ts
33
+ import { styled } from '@salty-css/react/styled';
34
+
35
+ // Define a component with styled function. First argument is the component name or existing component to extend and second argument is the object containing the styles and other options
36
+ export const Component = styled('div', {
37
+ className: 'wrapper', // Define custom class name that will be included for this component
38
+ element: 'section', // Define the html element that will be rendered for this component, overrides the first 'div' argument
39
+ base: {
40
+ // 👉 Add your CSS-in-JS base styles here! 👈
41
+ },
42
+ variants: {
43
+ // Define conditional styles that will be applied to the component based on the variant prop values
44
+ },
45
+ compoundVariants: [
46
+ // Define conditional styles that will be applied to the component based on the combination of variant prop values
47
+ ],
48
+ defaultVariants: {
49
+ // Set default variant prop values
50
+ },
51
+ defaultProps: {
52
+ // Add additional default props for the component (eg, id and other html element attributes)
53
+ },
54
+ passProps: true, // Pass variant props to the rendered element / parent component (default: false)
55
+ });
56
+ ```
57
+
58
+ ## Salty CSS CLI
59
+
60
+ In your existing repository you can use `npx salty-css [command]` to initialize a project, generate components, update related packages and build required files.
61
+
62
+ - Initialize project → `npx salty-css init [directory]` - Installs required packages, detects framework in use and creates project files to the provided directory. Directory can be left blank if you want files to be created to the current directory.
63
+ - Generate component → `npx salty-css update [version]` - Update @salty-css packages in your repository. Default version is "latest". Additional options like `--dir`, `--tag`, `--name` and `--className` are also supported.
64
+ - Build files → `npx salty-css build [directory]` - Compile Salty CSS related files in your project. This should not be needed if you are using tools like Next.js or Vite
65
+
66
+ ## Usage
67
+
68
+ ### Next.js
69
+
70
+ ![salty-next](https://github.com/user-attachments/assets/2cf6a93f-cdd5-4f5f-ab2e-3bc8bcfb83e8)
71
+
72
+ Salty CSS provides Next.js App & Pages router support with full React Server Components support.
73
+
74
+ ### Add Salty CSS to Next.js
75
+
76
+ 1. In your existing Next.js repository you can run `npx salty-css init` to automatically configure Salty CSS.
77
+ 2. Create your first Salty CSS component with `npx salty-css generate [filePath]` (e.g. src/custom-wrapper)
78
+ 3. Import your component for example to `page.tsx` and see it working!
79
+
80
+ And note: steps 2 & 3 are just to show how get new components up and running, step 1 does all of the important stuff 🤯
81
+
82
+ #### Manual configuration
83
+
84
+ 1. For Next.js support install `npm i @salty-css/next @salty-css/core @salty-css/react`
85
+ 2. Create `salty.config.ts` to your app directory
86
+ 3. Add Salty CSS plugin to next.js config
87
+
88
+ - **Next.js 15:** In `next.config.ts` add import for salty plugin `import { withSaltyCss } from '@salty-css/next';` and then add `withSaltyCss` to wrap your nextConfig export like so `export default withSaltyCss(nextConfig);`
89
+ - **Next.js 14 and older:** In `next.config.js` add import for salty plugin `const { withSaltyCss } = require('@salty-css/next');` and then add `withSaltyCss` to wrap your nextConfig export like so `module.exports = withSaltyCss(nextConfig);`
90
+
91
+ 4. Make sure that `salty.config.ts` and `next.config.ts` are in the same folder!
92
+ 5. Build `saltygen` directory by running your app once or with cli `npx salty-css build [directory]`
93
+ 6. Import global styles from `saltygen/index.css` to some global css file with `@import 'insert_path_to_index_css';`.
94
+
95
+ [Check out Next.js demo project](https://github.com/margarita-form/salty-css-website) or [react example code](#code-examples)
96
+
97
+ ---
98
+
99
+ ### React + Vite
100
+
101
+ ![salty-vite-react](https://github.com/user-attachments/assets/12ec5b6a-0dcc-48fa-afc1-d337fc8f800c)
102
+
103
+ ### Add Salty CSS to your React + Vite app
104
+
105
+ 1. In your existing Vite repository you can run `npx salty-css init` to automatically configure Salty CSS.
106
+ 2. Create your first Salty CSS component with `npx salty-css generate [filePath]` (e.g. src/custom-wrapper)
107
+ 3. Import your component for example to `main.tsx` and see it working!
108
+
109
+ And note: steps 2 & 3 are just to show how get new components up and running, step 1 does all of the important stuff 🤯
110
+
111
+ #### Manual configuration
112
+
113
+ 1. For Vite support install `npm i @salty-css/vite @salty-css/core`
114
+ 2. In `vite.config` add import for salty plugin `import { saltyPlugin } from '@salty-css/vite';` and then add `saltyPlugin(__dirname)` to your vite configuration plugins
115
+ 3. Make sure that `salty.config.ts` and `vite.config.ts` are in the same folder!
116
+ 4. Build `saltygen` directory by running your app once or with cli `npx salty-css build [directory]`
117
+ 5. Import global styles from `saltygen/index.css` to some global css file with `@import 'insert_path_to_index_css';`.
118
+
119
+ [Check out react example code](#code-examples)
120
+
121
+ ---
122
+
123
+ ### Create components
124
+
125
+ 1. Create salty components with styled only inside files that end with `.css.ts`, `.salty.ts` `.styled.ts` or `.styles.ts`
126
+
127
+ ## Code examples
128
+
129
+ ### Basic usage example with Button
13
130
 
14
131
  **Salty config**
15
132
 
@@ -31,23 +148,6 @@ export const config = defineConfig({
31
148
  });
32
149
  ```
33
150
 
34
- **Your React component file**
35
-
36
- ```tsx
37
- import { Wrapper } from '../components/wrapper/wrapper.css';
38
- import { Button } from '../components/button/button.css';
39
-
40
- export const IndexPage = () => {
41
- return (
42
- <Wrapper>
43
- <Button variant="solid" onClick={() => alert('It is a button.')}>
44
- Outlined
45
- </Button>
46
- </Wrapper>
47
- );
48
- };
49
- ```
50
-
51
151
  **Wrapper** (`components/wrapper/wrapper.css.ts`)
52
152
 
53
153
  ```tsx
@@ -72,7 +172,7 @@ export const Button = styled('button', {
72
172
  padding: `0.6em 1.2em`,
73
173
  border: '1px solid currentColor',
74
174
  background: 'transparent',
75
- color: 'currentColor/40',
175
+ color: 'currentColor',
76
176
  cursor: 'pointer',
77
177
  transition: '200ms',
78
178
  textDecoration: 'none',
@@ -108,4 +208,21 @@ export const Button = styled('button', {
108
208
  });
109
209
  ```
110
210
 
211
+ **Your React component file**
212
+
213
+ ```tsx
214
+ import { Wrapper } from '../components/wrapper/wrapper.css';
215
+ import { Button } from '../components/button/button.css';
216
+
217
+ export const IndexPage = () => {
218
+ return (
219
+ <Wrapper>
220
+ <Button variant="solid" onClick={() => alert('It is a button.')}>
221
+ Outlined
222
+ </Button>
223
+ </Wrapper>
224
+ );
225
+ };
226
+ ```
227
+
111
228
  More examples coming soon
package/class-name.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./styles-generator-kgxoBbAI.cjs");class a extends r.StylesGenerator{constructor(e){super(e),this._params=e}}const n=s=>{const e=new a(s),t=new String(e.cssClassName);return Object.assign(t,{get isClassName(){return!0},generator:e}),t};exports.className=n;
@@ -0,0 +1,6 @@
1
+ import { StyledParams } from '@salty-css/core/types';
2
+ import { ClassNameGenerator } from '@salty-css/core/generators';
3
+ export declare const className: <const STYLE_PARAMS extends StyledParams>(params: STYLE_PARAMS) => string & {
4
+ isClassName: boolean;
5
+ generator: ClassNameGenerator<STYLE_PARAMS>;
6
+ };
package/class-name.js ADDED
@@ -0,0 +1,18 @@
1
+ import { S as r } from "./styles-generator-B6o2r_I5.js";
2
+ class a extends r {
3
+ constructor(s) {
4
+ super(s), this._params = s;
5
+ }
6
+ }
7
+ const o = (e) => {
8
+ const s = new a(e), t = new String(s.cssClassName);
9
+ return Object.assign(t, {
10
+ get isClassName() {
11
+ return !0;
12
+ },
13
+ generator: s
14
+ }), t;
15
+ };
16
+ export {
17
+ o as className
18
+ };
package/config.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";var o=Object.defineProperty;var u=(t,e,r)=>e in t?o(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var s=(t,e,r)=>u(t,typeof e!="symbol"?e+"":e,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("./media.cjs"),m=t=>t;class a{constructor(e){this._current=e}get isGlobalDefine(){return!0}}const p=t=>new a(t),f=t=>t(h.media);class n{constructor(e){this._current=e}get isDefineVariables(){return!0}}const d=t=>new n(t);class i{constructor(e){s(this,"_path");this.params=e}get _current(){return this.params.template}get isDefineTemplate(){return!0}_setPath(e){return this._path=e,this}}class l{constructor(e){s(this,"_path");s(this,"templates",[]);this.params=e,Object.entries(e).forEach(([r,c])=>{this.templates.push(new i({name:r,template:c}))})}get _current(){return this.params}get _children(){return Object.fromEntries(this.templates.map(e=>[e.params.name,e]))}get isDefineTemplates(){return!0}_setPath(e){return this._path=e,this.templates.forEach(r=>r._setPath(e)),this}}const y=t=>new l(t);exports.GlobalStylesFactory=a;exports.TemplateFactory=i;exports.TemplatesFactory=l;exports.VariablesFactory=n;exports.defineConfig=m;exports.defineGlobalStyles=p;exports.defineMediaQuery=f;exports.defineTemplates=y;exports.defineVariables=d;
package/config.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from '@salty-css/core/config';
package/config.js ADDED
@@ -0,0 +1,78 @@
1
+ var n = Object.defineProperty;
2
+ var i = (e, t, r) => t in e ? n(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
+ var s = (e, t, r) => i(e, typeof t != "symbol" ? t + "" : t, r);
4
+ import { media as c } from "./media.js";
5
+ const f = (e) => e;
6
+ class u {
7
+ constructor(t) {
8
+ this._current = t;
9
+ }
10
+ get isGlobalDefine() {
11
+ return !0;
12
+ }
13
+ }
14
+ const _ = (e) => new u(e), b = (e) => e(c);
15
+ class o {
16
+ constructor(t) {
17
+ this._current = t;
18
+ }
19
+ get isDefineVariables() {
20
+ return !0;
21
+ }
22
+ }
23
+ const d = (e) => new o(e);
24
+ class l {
25
+ constructor(t) {
26
+ s(this, "_path");
27
+ this.params = t;
28
+ }
29
+ get _current() {
30
+ return this.params.template;
31
+ }
32
+ get isDefineTemplate() {
33
+ return !0;
34
+ }
35
+ _setPath(t) {
36
+ return this._path = t, this;
37
+ }
38
+ }
39
+ class h {
40
+ constructor(t) {
41
+ s(this, "_path");
42
+ s(this, "templates", []);
43
+ this.params = t, Object.entries(t).forEach(([r, a]) => {
44
+ this.templates.push(
45
+ new l({
46
+ name: r,
47
+ template: a
48
+ })
49
+ );
50
+ });
51
+ }
52
+ get _current() {
53
+ return this.params;
54
+ }
55
+ get _children() {
56
+ return Object.fromEntries(
57
+ this.templates.map((t) => [t.params.name, t])
58
+ );
59
+ }
60
+ get isDefineTemplates() {
61
+ return !0;
62
+ }
63
+ _setPath(t) {
64
+ return this._path = t, this.templates.forEach((r) => r._setPath(t)), this;
65
+ }
66
+ }
67
+ const g = (e) => new h(e);
68
+ export {
69
+ u as GlobalStylesFactory,
70
+ l as TemplateFactory,
71
+ h as TemplatesFactory,
72
+ o as VariablesFactory,
73
+ f as defineConfig,
74
+ _ as defineGlobalStyles,
75
+ b as defineMediaQuery,
76
+ g as defineTemplates,
77
+ d as defineVariables
78
+ };
@@ -0,0 +1,67 @@
1
+ import { forwardRef as C, createElement as g } from "react";
2
+ import { p as N, d as A } from "./parse-tokens-CssTiO78.js";
3
+ function K(n) {
4
+ var s, e, t = "";
5
+ if (typeof n == "string" || typeof n == "number") t += n;
6
+ else if (typeof n == "object") if (Array.isArray(n)) {
7
+ var o = n.length;
8
+ for (s = 0; s < o; s++) n[s] && (e = K(n[s])) && (t && (t += " "), t += e);
9
+ } else for (e in n) n[e] && (t && (t += " "), t += e);
10
+ return t;
11
+ }
12
+ function R() {
13
+ for (var n, s, e = 0, t = "", o = arguments.length; e < o; e++) (n = arguments[e]) && (s = K(n)) && (t && (t += " "), t += s);
14
+ return t;
15
+ }
16
+ const q = ["passProps"], x = (n, s = "", e = {}, t) => {
17
+ const j = C(({
18
+ extend: d = n,
19
+ element: S = e.element,
20
+ className: O = "",
21
+ children: $,
22
+ passProps: u = e.passProps,
23
+ _vks: l = /* @__PURE__ */ new Set(),
24
+ ...r
25
+ }, w) => {
26
+ const f = { passProps: u };
27
+ e.attr && Object.assign(f, e.attr), t && Object.assign(f, t), e.defaultProps && Object.assign(r, e.defaultProps), r && Object.assign(f, r);
28
+ const b = /* @__PURE__ */ new Set([...s.split(" "), ...O.split(" ")]), y = typeof d == "function" || typeof d == "object", h = y && "isStyled" in d, E = y ? d : S || d;
29
+ if (!E) throw new Error("No element provided");
30
+ const m = f.style || {};
31
+ f.style || (f.style = m), Object.entries(m).forEach(([i, a]) => {
32
+ const c = N(a);
33
+ c && (m[i] = c.transformed);
34
+ }), e.propValueKeys && e.propValueKeys.forEach((i) => {
35
+ const a = `css-${i}`, c = r[a];
36
+ if (c === void 0) return;
37
+ const p = `--props-${A(i)}`;
38
+ m[p] = c, l && l.add(a);
39
+ }), e.variantKeys && e.variantKeys.forEach((i) => {
40
+ const [a, c] = i.split("=");
41
+ r[a] !== void 0 ? (b.add(`${a}-${r[a]}`), l && l.add(a)) : c !== void 0 && b.add(`${a}-${c}`);
42
+ }), l && (!y || !h) ? l.forEach((i) => {
43
+ if (!u) return delete f[i];
44
+ if (u !== !0 && !u.includes(i))
45
+ return delete f[i];
46
+ }) : h && Object.assign(f, { _vks: l }), h || q.forEach((i) => delete f[i]);
47
+ const V = R(...b);
48
+ return g(
49
+ E,
50
+ {
51
+ element: y ? S : void 0,
52
+ className: V,
53
+ ref: w,
54
+ ...f
55
+ },
56
+ $
57
+ );
58
+ });
59
+ return Object.assign(j, {
60
+ isStyled: !0,
61
+ className: s,
62
+ toString: () => `.${s}`
63
+ }), j;
64
+ };
65
+ export {
66
+ x as e
67
+ };
@@ -0,0 +1 @@
1
+ "use strict";const K=require("react"),O=require("./parse-tokens-DfRKmjt1.cjs");function $(n){var s,e,t="";if(typeof n=="string"||typeof n=="number")t+=n;else if(typeof n=="object")if(Array.isArray(n)){var u=n.length;for(s=0;s<u;s++)n[s]&&(e=$(n[s]))&&(t&&(t+=" "),t+=e)}else for(e in n)n[e]&&(t&&(t+=" "),t+=e);return t}function N(){for(var n,s,e=0,t="",u=arguments.length;e<u;e++)(n=arguments[e])&&(s=$(n))&&(t&&(t+=" "),t+=s);return t}const A=["passProps"],F=(n,s="",e={},t)=>{const u=({extend:d=n,element:S=e.element,className:w="",children:V,passProps:o=e.passProps,_vks:r=new Set,...l},C)=>{const f={passProps:o};e.attr&&Object.assign(f,e.attr),t&&Object.assign(f,t),e.defaultProps&&Object.assign(l,e.defaultProps),l&&Object.assign(f,l);const b=new Set([...s.split(" "),...w.split(" ")]),y=typeof d=="function"||typeof d=="object",h=y&&"isStyled"in d,E=y?d:S||d;if(!E)throw new Error("No element provided");const m=f.style||{};f.style||(f.style=m),Object.entries(m).forEach(([i,a])=>{const c=O.parseVariableTokens(a);c&&(m[i]=c.transformed)}),e.propValueKeys&&e.propValueKeys.forEach(i=>{const a=`css-${i}`,c=l[a];if(c===void 0)return;const q=`--props-${O.dashCase(i)}`;m[q]=c,r&&r.add(a)}),e.variantKeys&&e.variantKeys.forEach(i=>{const[a,c]=i.split("=");l[a]!==void 0?(b.add(`${a}-${l[a]}`),r&&r.add(a)):c!==void 0&&b.add(`${a}-${c}`)}),r&&(!y||!h)?r.forEach(i=>{if(!o)return delete f[i];if(o!==!0&&!o.includes(i))return delete f[i]}):h&&Object.assign(f,{_vks:r}),h||A.forEach(i=>delete f[i]);const g=N(...b);return K.createElement(E,{element:y?S:void 0,className:g,ref:C,...f},V)},j=K.forwardRef(u);return Object.assign(j,{isStyled:!0,className:s,toString:()=>`.${s}`}),j};exports.elementFactory=F;
@@ -1,3 +1,3 @@
1
- import { GeneratorProps } from '../../core/src/generator';
2
- import { StyledComponentProps, Tag } from '../../core/src/types';
3
- export declare const elementFactory: (tagName: Tag<any>, _className: string, _generatorProps: GeneratorProps, _additionalProps?: Record<PropertyKey, any>) => import('react').ForwardRefExoticComponent<Omit<StyledComponentProps, "ref"> & import('react').RefAttributes<any>>;
1
+ import { StyledComponentProps, Tag } from '@salty-css/core/types';
2
+ import { StyledGeneratorClientProps } from '@salty-css/core/generators';
3
+ export declare const elementFactory: (tagName: Tag<any>, _className?: string, _generatorProps?: StyledGeneratorClientProps, _additionalProps?: Record<PropertyKey, any>) => import('react').ForwardRefExoticComponent<Omit<StyledComponentProps, "ref"> & import('react').RefAttributes<any>>;
package/helpers.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";var A=Object.defineProperty;var S=(e,t,n)=>t in e?A(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var _=(e,t,n)=>S(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]},O=Object.create(null);for(const e in w)Object.hasOwn(w,e)&&(O[w[e]]=e);const d={to:{},get:{}};d.get=function(e){const t=e.slice(0,3).toLowerCase();let n,r;switch(t){case"hsl":{n=d.get.hsl(e),r="hsl";break}case"hwb":{n=d.get.hwb(e),r="hwb";break}default:{n=d.get.rgb(e),r="rgb";break}}return n?{model:r,value:n}:null};d.get.rgb=function(e){if(!e)return null;const t=/^#([a-f\d]{3,4})$/i,n=/^#([a-f\d]{6})([a-f\d]{2})?$/i,r=/^rgba?\(\s*([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)\s*(?:[,|/]\s*([+-]?[\d.]+)(%?)\s*)?\)$/,o=/^rgba?\(\s*([+-]?[\d.]+)%\s*,?\s*([+-]?[\d.]+)%\s*,?\s*([+-]?[\d.]+)%\s*(?:[,|/]\s*([+-]?[\d.]+)(%?)\s*)?\)$/,l=/^(\w+)$/;let s=[0,0,0,1],a,i,u;if(a=e.match(n)){for(u=a[2],a=a[1],i=0;i<3;i++){const m=i*2;s[i]=Number.parseInt(a.slice(m,m+2),16)}u&&(s[3]=Number.parseInt(u,16)/255)}else if(a=e.match(t)){for(a=a[1],u=a[3],i=0;i<3;i++)s[i]=Number.parseInt(a[i]+a[i],16);u&&(s[3]=Number.parseInt(u+u,16)/255)}else if(a=e.match(r)){for(i=0;i<3;i++)s[i]=Number.parseInt(a[i+1],10);a[4]&&(s[3]=a[5]?Number.parseFloat(a[4])*.01:Number.parseFloat(a[4]))}else if(a=e.match(o)){for(i=0;i<3;i++)s[i]=Math.round(Number.parseFloat(a[i+1])*2.55);a[4]&&(s[3]=a[5]?Number.parseFloat(a[4])*.01:Number.parseFloat(a[4]))}else return(a=e.match(l))?a[1]==="transparent"?[0,0,0,0]:Object.hasOwn(w,a[1])?(s=w[a[1]],s[3]=1,s):null:null;for(i=0;i<3;i++)s[i]=k(s[i],0,255);return s[3]=k(s[3],0,1),s};d.get.hsl=function(e){if(!e)return null;const t=/^hsla?\(\s*([+-]?(?:\d{0,3}\.)?\d+)(?:deg)?\s*,?\s*([+-]?[\d.]+)%\s*,?\s*([+-]?[\d.]+)%\s*(?:[,|/]\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/,n=e.match(t);if(n){const r=Number.parseFloat(n[4]),o=(Number.parseFloat(n[1])%360+360)%360,l=k(Number.parseFloat(n[2]),0,100),s=k(Number.parseFloat(n[3]),0,100),a=k(Number.isNaN(r)?1:r,0,1);return[o,l,s,a]}return null};d.get.hwb=function(e){if(!e)return null;const t=/^hwb\(\s*([+-]?\d{0,3}(?:\.\d+)?)(?:deg)?\s*,\s*([+-]?[\d.]+)%\s*,\s*([+-]?[\d.]+)%\s*(?:,\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/,n=e.match(t);if(n){const r=Number.parseFloat(n[4]),o=(Number.parseFloat(n[1])%360+360)%360,l=k(Number.parseFloat(n[2]),0,100),s=k(Number.parseFloat(n[3]),0,100),a=k(Number.isNaN(r)?1:r,0,1);return[o,l,s,a]}return null};d.to.hex=function(...e){return"#"+x(e[0])+x(e[1])+x(e[2])+(e[3]<1?x(Math.round(e[3]*255)):"")};d.to.rgb=function(...e){return e.length<4||e[3]===1?"rgb("+Math.round(e[0])+", "+Math.round(e[1])+", "+Math.round(e[2])+")":"rgba("+Math.round(e[0])+", "+Math.round(e[1])+", "+Math.round(e[2])+", "+e[3]+")"};d.to.rgb.percent=function(...e){const t=Math.round(e[0]/255*100),n=Math.round(e[1]/255*100),r=Math.round(e[2]/255*100);return e.length<4||e[3]===1?"rgb("+t+"%, "+n+"%, "+r+"%)":"rgba("+t+"%, "+n+"%, "+r+"%, "+e[3]+")"};d.to.hsl=function(...e){return e.length<4||e[3]===1?"hsl("+e[0]+", "+e[1]+"%, "+e[2]+"%)":"hsla("+e[0]+", "+e[1]+"%, "+e[2]+"%, "+e[3]+")"};d.to.hwb=function(...e){let t="";return e.length>=4&&e[3]!==1&&(t=", "+e[3]),"hwb("+e[0]+", "+e[1]+"%, "+e[2]+"%"+t+")"};d.to.keyword=function(...e){return O[e.slice(0,3)]};function k(e,t,n){return Math.min(Math.max(t,e),n)}function x(e){const t=Math.round(e).toString(16).toUpperCase();return t.length<2?"0"+t:t}const M={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]},q={};for(const e of Object.keys(M))q[M[e]]=e;const c={rgb:{channels:3,labels:"rgb"},hsl:{channels:3,labels:"hsl"},hsv:{channels:3,labels:"hsv"},hwb:{channels:3,labels:"hwb"},cmyk:{channels:4,labels:"cmyk"},xyz:{channels:3,labels:"xyz"},lab:{channels:3,labels:"lab"},lch:{channels:3,labels:"lch"},hex:{channels:1,labels:["hex"]},keyword:{channels:1,labels:["keyword"]},ansi16:{channels:1,labels:["ansi16"]},ansi256:{channels:1,labels:["ansi256"]},hcg:{channels:3,labels:["h","c","g"]},apple:{channels:3,labels:["r16","g16","b16"]},gray:{channels:1,labels:["gray"]}},y=(6/29)**3;for(const e of Object.keys(c)){if(!("channels"in c[e]))throw new Error("missing channels property: "+e);if(!("labels"in c[e]))throw new Error("missing channel labels property: "+e);if(c[e].labels.length!==c[e].channels)throw new Error("channel and label counts mismatch: "+e);const{channels:t,labels:n}=c[e];delete c[e].channels,delete c[e].labels,Object.defineProperty(c[e],"channels",{value:t}),Object.defineProperty(c[e],"labels",{value:n})}c.rgb.hsl=function(e){const t=e[0]/255,n=e[1]/255,r=e[2]/255,o=Math.min(t,n,r),l=Math.max(t,n,r),s=l-o;let a,i;switch(l){case o:{a=0;break}case t:{a=(n-r)/s;break}case n:{a=2+(r-t)/s;break}case r:{a=4+(t-n)/s;break}}a=Math.min(a*60,360),a<0&&(a+=360);const u=(o+l)/2;return l===o?i=0:u<=.5?i=s/(l+o):i=s/(2-l-o),[a,i*100,u*100]};c.rgb.hsv=function(e){let t,n,r,o,l;const s=e[0]/255,a=e[1]/255,i=e[2]/255,u=Math.max(s,a,i),m=u-Math.min(s,a,i),p=function(z){return(u-z)/6/m+1/2};if(m===0)o=0,l=0;else{switch(l=m/u,t=p(s),n=p(a),r=p(i),u){case s:{o=r-n;break}case a:{o=1/3+t-r;break}case i:{o=2/3+n-t;break}}o<0?o+=1:o>1&&(o-=1)}return[o*360,l*100,u*100]};c.rgb.hwb=function(e){const t=e[0],n=e[1];let r=e[2];const o=c.rgb.hsl(e)[0],l=1/255*Math.min(t,Math.min(n,r));return r=1-1/255*Math.max(t,Math.max(n,r)),[o,l*100,r*100]};c.rgb.cmyk=function(e){const t=e[0]/255,n=e[1]/255,r=e[2]/255,o=Math.min(1-t,1-n,1-r),l=(1-t-o)/(1-o)||0,s=(1-n-o)/(1-o)||0,a=(1-r-o)/(1-o)||0;return[l*100,s*100,a*100,o*100]};function P(e,t){return(e[0]-t[0])**2+(e[1]-t[1])**2+(e[2]-t[2])**2}c.rgb.keyword=function(e){const t=q[e];if(t)return t;let n=Number.POSITIVE_INFINITY,r;for(const o of Object.keys(M)){const l=M[o],s=P(e,l);s<n&&(n=s,r=o)}return r};c.keyword.rgb=function(e){return M[e]};c.rgb.xyz=function(e){let t=e[0]/255,n=e[1]/255,r=e[2]/255;t=t>.04045?((t+.055)/1.055)**2.4:t/12.92,n=n>.04045?((n+.055)/1.055)**2.4:n/12.92,r=r>.04045?((r+.055)/1.055)**2.4:r/12.92;const o=t*.4124564+n*.3575761+r*.1804375,l=t*.2126729+n*.7151522+r*.072175,s=t*.0193339+n*.119192+r*.9503041;return[o*100,l*100,s*100]};c.rgb.lab=function(e){const t=c.rgb.xyz(e);let n=t[0],r=t[1],o=t[2];n/=95.047,r/=100,o/=108.883,n=n>y?n**(1/3):7.787*n+16/116,r=r>y?r**(1/3):7.787*r+16/116,o=o>y?o**(1/3):7.787*o+16/116;const l=116*r-16,s=500*(n-r),a=200*(r-o);return[l,s,a]};c.hsl.rgb=function(e){const t=e[0]/360,n=e[1]/100,r=e[2]/100;let o,l;if(n===0)return l=r*255,[l,l,l];const s=r<.5?r*(1+n):r+n-r*n,a=2*r-s,i=[0,0,0];for(let u=0;u<3;u++)o=t+1/3*-(u-1),o<0&&o++,o>1&&o--,6*o<1?l=a+(s-a)*6*o:2*o<1?l=s:3*o<2?l=a+(s-a)*(2/3-o)*6:l=a,i[u]=l*255;return i};c.hsl.hsv=function(e){const t=e[0];let n=e[1]/100,r=e[2]/100,o=n;const l=Math.max(r,.01);r*=2,n*=r<=1?r:2-r,o*=l<=1?l:2-l;const s=(r+n)/2,a=r===0?2*o/(l+o):2*n/(r+n);return[t,a*100,s*100]};c.hsv.rgb=function(e){const t=e[0]/60,n=e[1]/100;let r=e[2]/100;const o=Math.floor(t)%6,l=t-Math.floor(t),s=255*r*(1-n),a=255*r*(1-n*l),i=255*r*(1-n*(1-l));switch(r*=255,o){case 0:return[r,i,s];case 1:return[a,r,s];case 2:return[s,r,i];case 3:return[s,a,r];case 4:return[i,s,r];case 5:return[r,s,a]}};c.hsv.hsl=function(e){const t=e[0],n=e[1]/100,r=e[2]/100,o=Math.max(r,.01);let l,s;s=(2-n)*r;const a=(2-n)*o;return l=n*o,l/=a<=1?a:2-a,l=l||0,s/=2,[t,l*100,s*100]};c.hwb.rgb=function(e){const t=e[0]/360;let n=e[1]/100,r=e[2]/100;const o=n+r;let l;o>1&&(n/=o,r/=o);const s=Math.floor(6*t),a=1-r;l=6*t-s,(s&1)!==0&&(l=1-l);const i=n+l*(a-n);let u,m,p;switch(s){default:case 6:case 0:{u=a,m=i,p=n;break}case 1:{u=i,m=a,p=n;break}case 2:{u=n,m=a,p=i;break}case 3:{u=n,m=i,p=a;break}case 4:{u=i,m=n,p=a;break}case 5:{u=a,m=n,p=i;break}}return[u*255,m*255,p*255]};c.cmyk.rgb=function(e){const t=e[0]/100,n=e[1]/100,r=e[2]/100,o=e[3]/100,l=1-Math.min(1,t*(1-o)+o),s=1-Math.min(1,n*(1-o)+o),a=1-Math.min(1,r*(1-o)+o);return[l*255,s*255,a*255]};c.xyz.rgb=function(e){const t=e[0]/100,n=e[1]/100,r=e[2]/100;let o,l,s;return o=t*3.2404542+n*-1.5371385+r*-.4985314,l=t*-.969266+n*1.8760108+r*.041556,s=t*.0556434+n*-.2040259+r*1.0572252,o=o>.0031308?1.055*o**(1/2.4)-.055:o*12.92,l=l>.0031308?1.055*l**(1/2.4)-.055:l*12.92,s=s>.0031308?1.055*s**(1/2.4)-.055:s*12.92,o=Math.min(Math.max(0,o),1),l=Math.min(Math.max(0,l),1),s=Math.min(Math.max(0,s),1),[o*255,l*255,s*255]};c.xyz.lab=function(e){let t=e[0],n=e[1],r=e[2];t/=95.047,n/=100,r/=108.883,t=t>y?t**(1/3):7.787*t+16/116,n=n>y?n**(1/3):7.787*n+16/116,r=r>y?r**(1/3):7.787*r+16/116;const o=116*n-16,l=500*(t-n),s=200*(n-r);return[o,l,s]};c.lab.xyz=function(e){const t=e[0],n=e[1],r=e[2];let o,l,s;l=(t+16)/116,o=n/500+l,s=l-r/200;const a=l**3,i=o**3,u=s**3;return l=a>y?a:(l-16/116)/7.787,o=i>y?i:(o-16/116)/7.787,s=u>y?u:(s-16/116)/7.787,o*=95.047,l*=100,s*=108.883,[o,l,s]};c.lab.lch=function(e){const t=e[0],n=e[1],r=e[2];let o;o=Math.atan2(r,n)*360/2/Math.PI,o<0&&(o+=360);const s=Math.sqrt(n*n+r*r);return[t,s,o]};c.lch.lab=function(e){const t=e[0],n=e[1],o=e[2]/360*2*Math.PI,l=n*Math.cos(o),s=n*Math.sin(o);return[t,l,s]};c.rgb.ansi16=function(e,t=null){const[n,r,o]=e;let l=t===null?c.rgb.hsv(e)[2]:t;if(l=Math.round(l/50),l===0)return 30;let s=30+(Math.round(o/255)<<2|Math.round(r/255)<<1|Math.round(n/255));return l===2&&(s+=60),s};c.hsv.ansi16=function(e){return c.rgb.ansi16(c.hsv.rgb(e),e[2])};c.rgb.ansi256=function(e){const t=e[0],n=e[1],r=e[2];return t>>4===n>>4&&n>>4===r>>4?t<8?16:t>248?231:Math.round((t-8)/247*24)+232:16+36*Math.round(t/255*5)+6*Math.round(n/255*5)+Math.round(r/255*5)};c.ansi16.rgb=function(e){e=e[0];let t=e%10;if(t===0||t===7)return e>50&&(t+=3.5),t=t/10.5*255,[t,t,t];const n=(Math.trunc(e>50)+1)*.5,r=(t&1)*n*255,o=(t>>1&1)*n*255,l=(t>>2&1)*n*255;return[r,o,l]};c.ansi256.rgb=function(e){if(e=e[0],e>=232){const l=(e-232)*10+8;return[l,l,l]}e-=16;let t;const n=Math.floor(e/36)/5*255,r=Math.floor((t=e%36)/6)/5*255,o=t%6/5*255;return[n,r,o]};c.rgb.hex=function(e){const n=(((Math.round(e[0])&255)<<16)+((Math.round(e[1])&255)<<8)+(Math.round(e[2])&255)).toString(16).toUpperCase();return"000000".slice(n.length)+n};c.hex.rgb=function(e){const t=e.toString(16).match(/[a-f\d]{6}|[a-f\d]{3}/i);if(!t)return[0,0,0];let n=t[0];t[0].length===3&&(n=[...n].map(a=>a+a).join(""));const r=Number.parseInt(n,16),o=r>>16&255,l=r>>8&255,s=r&255;return[o,l,s]};c.rgb.hcg=function(e){const t=e[0]/255,n=e[1]/255,r=e[2]/255,o=Math.max(Math.max(t,n),r),l=Math.min(Math.min(t,n),r),s=o-l;let a;const i=s<1?l/(1-s):0;return s<=0?a=0:o===t?a=(n-r)/s%6:o===n?a=2+(r-t)/s:a=4+(t-n)/s,a/=6,a%=1,[a*360,s*100,i*100]};c.hsl.hcg=function(e){const t=e[1]/100,n=e[2]/100,r=n<.5?2*t*n:2*t*(1-n);let o=0;return r<1&&(o=(n-.5*r)/(1-r)),[e[0],r*100,o*100]};c.hsv.hcg=function(e){const t=e[1]/100,n=e[2]/100,r=t*n;let o=0;return r<1&&(o=(n-r)/(1-r)),[e[0],r*100,o*100]};c.hcg.rgb=function(e){const t=e[0]/360,n=e[1]/100,r=e[2]/100;if(n===0)return[r*255,r*255,r*255];const o=[0,0,0],l=t%1*6,s=l%1,a=1-s;let i=0;switch(Math.floor(l)){case 0:{o[0]=1,o[1]=s,o[2]=0;break}case 1:{o[0]=a,o[1]=1,o[2]=0;break}case 2:{o[0]=0,o[1]=1,o[2]=s;break}case 3:{o[0]=0,o[1]=a,o[2]=1;break}case 4:{o[0]=s,o[1]=0,o[2]=1;break}default:o[0]=1,o[1]=0,o[2]=a}return i=(1-n)*r,[(n*o[0]+i)*255,(n*o[1]+i)*255,(n*o[2]+i)*255]};c.hcg.hsv=function(e){const t=e[1]/100,n=e[2]/100,r=t+n*(1-t);let o=0;return r>0&&(o=t/r),[e[0],o*100,r*100]};c.hcg.hsl=function(e){const t=e[1]/100,r=e[2]/100*(1-t)+.5*t;let o=0;return r>0&&r<.5?o=t/(2*r):r>=.5&&r<1&&(o=t/(2*(1-r))),[e[0],o*100,r*100]};c.hcg.hwb=function(e){const t=e[1]/100,n=e[2]/100,r=t+n*(1-t);return[e[0],(r-t)*100,(1-r)*100]};c.hwb.hcg=function(e){const t=e[1]/100,r=1-e[2]/100,o=r-t;let l=0;return o<1&&(l=(r-o)/(1-o)),[e[0],o*100,l*100]};c.apple.rgb=function(e){return[e[0]/65535*255,e[1]/65535*255,e[2]/65535*255]};c.rgb.apple=function(e){return[e[0]/255*65535,e[1]/255*65535,e[2]/255*65535]};c.gray.rgb=function(e){return[e[0]/100*255,e[0]/100*255,e[0]/100*255]};c.gray.hsl=function(e){return[0,0,e[0]]};c.gray.hsv=c.gray.hsl;c.gray.hwb=function(e){return[0,100,e[0]]};c.gray.cmyk=function(e){return[0,0,0,e[0]]};c.gray.lab=function(e){return[e[0],0,0]};c.gray.hex=function(e){const t=Math.round(e[0]/100*255)&255,r=((t<<16)+(t<<8)+t).toString(16).toUpperCase();return"000000".slice(r.length)+r};c.rgb.gray=function(e){return[(e[0]+e[1]+e[2])/3/255*100]};function I(){const e={},t=Object.keys(c);for(let{length:n}=t,r=0;r<n;r++)e[t[r]]={distance:-1,parent:null};return e}function j(e){const t=I(),n=[e];for(t[e].distance=0;n.length>0;){const r=n.pop(),o=Object.keys(c[r]);for(let{length:l}=o,s=0;s<l;s++){const a=o[s],i=t[a];i.distance===-1&&(i.distance=t[r].distance+1,i.parent=r,n.unshift(a))}}return t}function E(e,t){return function(n){return t(e(n))}}function $(e,t){const n=[t[e].parent,e];let r=c[t[e].parent][e],o=t[e].parent;for(;t[o].parent;)n.unshift(t[o].parent),r=E(c[t[o].parent][o],r),o=t[o].parent;return r.conversion=n,r}function T(e){const t=j(e),n={},r=Object.keys(t);for(let{length:o}=r,l=0;l<o;l++){const s=r[l];t[s].parent!==null&&(n[s]=$(s,t))}return n}const g={},U=Object.keys(c);function D(e){const t=function(...n){const r=n[0];return r==null?r:(r.length>1&&(n=r),e(n))};return"conversion"in e&&(t.conversion=e.conversion),t}function K(e){const t=function(...n){const r=n[0];if(r==null)return r;r.length>1&&(n=r);const o=e(n);if(typeof o=="object")for(let{length:l}=o,s=0;s<l;s++)o[s]=Math.round(o[s]);return o};return"conversion"in e&&(t.conversion=e.conversion),t}for(const e of U){g[e]={},Object.defineProperty(g[e],"channels",{value:c[e].channels}),Object.defineProperty(g[e],"labels",{value:c[e].labels});const t=T(e),n=Object.keys(t);for(const r of n){const o=t[r];g[e][r]=K(o),g[e][r].raw=D(o)}}const C=["keyword","gray","hex"],F={};for(const e of Object.keys(g))F[[...g[e].labels].sort().join("")]=e;const v={};function b(e,t){if(!(this instanceof b))return new b(e,t);if(t&&t in C&&(t=null),t&&!(t in g))throw new Error("Unknown model: "+t);let n,r;if(e==null)this.model="rgb",this.color=[0,0,0],this.valpha=1;else if(e instanceof b)this.model=e.model,this.color=[...e.color],this.valpha=e.valpha;else if(typeof e=="string"){const o=d.get(e);if(o===null)throw new Error("Unable to parse color from string: "+e);this.model=o.model,r=g[this.model].channels,this.color=o.value.slice(0,r),this.valpha=typeof o.value[r]=="number"?o.value[r]:1}else if(e.length>0){this.model=t||"rgb",r=g[this.model].channels;const o=Array.prototype.slice.call(e,0,r);this.color=N(o,r),this.valpha=typeof e[r]=="number"?e[r]:1}else if(typeof e=="number")this.model="rgb",this.color=[e>>16&255,e>>8&255,e&255],this.valpha=1;else{this.valpha=1;const o=Object.keys(e);"alpha"in e&&(o.splice(o.indexOf("alpha"),1),this.valpha=typeof e.alpha=="number"?e.alpha:0);const l=o.sort().join("");if(!(l in F))throw new Error("Unable to parse color from object: "+JSON.stringify(e));this.model=F[l];const{labels:s}=g[this.model],a=[];for(n=0;n<s.length;n++)a.push(e[s[n]]);this.color=N(a)}if(v[this.model])for(r=g[this.model].channels,n=0;n<r;n++){const o=v[this.model][n];o&&(this.color[n]=o(this.color[n]))}this.valpha=Math.max(0,Math.min(1,this.valpha)),Object.freeze&&Object.freeze(this)}b.prototype={toString(){return this.string()},toJSON(){return this[this.model]()},string(e){let t=this.model in d.to?this:this.rgb();t=t.round(typeof e=="number"?e:1);const n=t.valpha===1?t.color:[...t.color,this.valpha];return d.to[t.model](...n)},percentString(e){const t=this.rgb().round(typeof e=="number"?e:1),n=t.valpha===1?t.color:[...t.color,this.valpha];return d.to.rgb.percent(...n)},array(){return this.valpha===1?[...this.color]:[...this.color,this.valpha]},object(){const e={},{channels:t}=g[this.model],{labels:n}=g[this.model];for(let r=0;r<t;r++)e[n[r]]=this.color[r];return this.valpha!==1&&(e.alpha=this.valpha),e},unitArray(){const e=this.rgb().color;return e[0]/=255,e[1]/=255,e[2]/=255,this.valpha!==1&&e.push(this.valpha),e},unitObject(){const e=this.rgb().object();return e.r/=255,e.g/=255,e.b/=255,this.valpha!==1&&(e.alpha=this.valpha),e},round(e){return e=Math.max(e||0,0),new b([...this.color.map(L(e)),this.valpha],this.model)},alpha(e){return e!==void 0?new b([...this.color,Math.max(0,Math.min(1,e))],this.model):this.valpha},red:h("rgb",0,f(255)),green:h("rgb",1,f(255)),blue:h("rgb",2,f(255)),hue:h(["hsl","hsv","hsl","hwb","hcg"],0,e=>(e%360+360)%360),saturationl:h("hsl",1,f(100)),lightness:h("hsl",2,f(100)),saturationv:h("hsv",1,f(100)),value:h("hsv",2,f(100)),chroma:h("hcg",1,f(100)),gray:h("hcg",2,f(100)),white:h("hwb",1,f(100)),wblack:h("hwb",2,f(100)),cyan:h("cmyk",0,f(100)),magenta:h("cmyk",1,f(100)),yellow:h("cmyk",2,f(100)),black:h("cmyk",3,f(100)),x:h("xyz",0,f(95.047)),y:h("xyz",1,f(100)),z:h("xyz",2,f(108.833)),l:h("lab",0,f(100)),a:h("lab",1),b:h("lab",2),keyword(e){return e!==void 0?new b(e):g[this.model].keyword(this.color)},hex(e){return e!==void 0?new b(e):d.to.hex(...this.rgb().round().color)},hexa(e){if(e!==void 0)return new b(e);const t=this.rgb().round().color;let n=Math.round(this.valpha*255).toString(16).toUpperCase();return n.length===1&&(n="0"+n),d.to.hex(...t)+n},rgbNumber(){const e=this.rgb().color;return(e[0]&255)<<16|(e[1]&255)<<8|e[2]&255},luminosity(){const e=this.rgb().color,t=[];for(const[n,r]of e.entries()){const o=r/255;t[n]=o<=.04045?o/12.92:((o+.055)/1.055)**2.4}return .2126*t[0]+.7152*t[1]+.0722*t[2]},contrast(e){const t=this.luminosity(),n=e.luminosity();return t>n?(t+.05)/(n+.05):(n+.05)/(t+.05)},level(e){const t=this.contrast(e);return t>=7?"AAA":t>=4.5?"AA":""},isDark(){const e=this.rgb().color;return(e[0]*2126+e[1]*7152+e[2]*722)/1e4<128},isLight(){return!this.isDark()},negate(){const e=this.rgb();for(let t=0;t<3;t++)e.color[t]=255-e.color[t];return e},lighten(e){const t=this.hsl();return t.color[2]+=t.color[2]*e,t},darken(e){const t=this.hsl();return t.color[2]-=t.color[2]*e,t},saturate(e){const t=this.hsl();return t.color[1]+=t.color[1]*e,t},desaturate(e){const t=this.hsl();return t.color[1]-=t.color[1]*e,t},whiten(e){const t=this.hwb();return t.color[1]+=t.color[1]*e,t},blacken(e){const t=this.hwb();return t.color[2]+=t.color[2]*e,t},grayscale(){const e=this.rgb().color,t=e[0]*.3+e[1]*.59+e[2]*.11;return b.rgb(t,t,t)},fade(e){return this.alpha(this.valpha-this.valpha*e)},opaquer(e){return this.alpha(this.valpha+this.valpha*e)},rotate(e){const t=this.hsl();let n=t.color[0];return n=(n+e)%360,n=n<0?360+n:n,t.color[0]=n,t},mix(e,t){if(!e||!e.rgb)throw new Error('Argument to "mix" was not a Color instance, but rather an instance of '+typeof e);const n=e.rgb(),r=this.rgb(),o=t===void 0?.5:t,l=2*o-1,s=n.alpha()-r.alpha(),a=((l*s===-1?l:(l+s)/(1+l*s))+1)/2,i=1-a;return b.rgb(a*n.red()+i*r.red(),a*n.green()+i*r.green(),a*n.blue()+i*r.blue(),n.alpha()*o+r.alpha()*(1-o))}};for(const e of Object.keys(g)){if(C.includes(e))continue;const{channels:t}=g[e];b.prototype[e]=function(...n){return this.model===e?new b(this):n.length>0?new b(n,e):new b([...R(g[this.model][e].raw(this.color)),this.valpha],e)},b[e]=function(...n){let r=n[0];return typeof r=="number"&&(r=N(n,t)),new b(r,e)}}function B(e,t){return Number(e.toFixed(t))}function L(e){return function(t){return B(t,e)}}function h(e,t,n){e=Array.isArray(e)?e:[e];for(const r of e)(v[r]||(v[r]=[]))[t]=n;return e=e[0],function(r){let o;return r!==void 0?(n&&(r=n(r)),o=this[e](),o.color[t]=r,o):(o=this[e]().color[t],n&&(o=n(o)),o)}}function f(e){return function(t){return Math.max(0,Math.min(e,t))}}function R(e){return Array.isArray(e)?e:[e]}function N(e,t){for(let n=0;n<t;n++)typeof e[n]!="number"&&(e[n]=0);return e}class V{constructor(t){_(this,"isColor",!0);_(this,"currentColor");this.base=t;const n=this._resolveBaseColor(t);return this.currentColor=b(n),this._createProxy()}_createProxy(){return new Proxy(this,{get(t,n){return n in t?t[n]:n in t.currentColor?t._handleColorMethod(n):t[n]}})}_resolveBaseColor(t){if(typeof t!="string"||!/\{[^{}]+\}/g.test(t))return t;if(typeof saltyConfig>"u")return"transparent";const{staticVariables:r}=saltyConfig;return r?t.replace(/^\{|\}$/g,"").split(".").reduce((s,a)=>s[a],r):"transparent"}_handleColorMethod(t){const n=this.currentColor;return typeof n[t]!="function"?n[t]:(...r)=>(this.currentColor=n[t](...r),this._createProxy())}toString(){return this.currentColor.toString()}}const J=e=>new V(e);exports.color=J;
package/helpers.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from '@salty-css/core/helpers';