@salty-css/react 0.0.1-alpha.25 → 0.0.1-alpha.251
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 +469 -26
- package/class-name-client.cjs +1 -0
- package/class-name-client.d.ts +3 -0
- package/class-name-client.js +11 -0
- package/class-name.cjs +1 -0
- package/class-name.d.ts +6 -0
- package/class-name.js +18 -0
- package/config.cjs +1 -0
- package/config.d.ts +1 -0
- package/config.js +78 -0
- package/element-factory-B1PSIJV4.js +67 -0
- package/element-factory-DjYdX8Jd.cjs +1 -0
- package/element-factory.d.ts +3 -3
- package/helpers.cjs +1 -0
- package/helpers.d.ts +1 -0
- package/helpers.js +1156 -0
- package/index.cjs +1 -0
- package/index.d.ts +1 -0
- package/index.js +11 -0
- package/keyframes.cjs +1 -1
- package/keyframes.d.ts +1 -22
- package/keyframes.js +22 -19
- package/media.cjs +1 -1
- package/media.d.ts +1 -71
- package/media.js +6 -3
- package/package.json +29 -4
- package/parse-styles-BbXScIK9.js +145 -0
- package/parse-styles-DqNFvgCM.cjs +5 -0
- package/parse-tokens-CssTiO78.js +9 -0
- package/parse-tokens-DfRKmjt1.cjs +1 -0
- package/styled-client.cjs +1 -1
- package/styled-client.d.ts +3 -3
- package/styled-client.js +3 -5
- package/styled.cjs +1 -1
- package/styled.d.ts +5 -5
- package/styled.js +36 -59
- package/styles-generator-DvtuxJMl.cjs +1 -0
- package/styles-generator-QutiM0qS.js +47 -0
- package/dash-case-B_odFlTl.cjs +0 -1
- package/dash-case-CGJ_UIZz.js +0 -6
- package/element-factory-WgNOpLmJ.cjs +0 -1
- package/element-factory-uEk4VrqP.js +0 -59
- package/parse-styles-SPT4zc_H.cjs +0 -7
- package/parse-styles-T74HIH4_.js +0 -85
@@ -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;
|
package/element-factory.d.ts
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
3
|
-
export declare const elementFactory: (tagName: Tag<any>, _className
|
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 k={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 k)Object.hasOwn(k,e)&&(O[k[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(k,a[1])?(s=k[a[1]],s[3]=1,s):null:null;for(i=0;i<3;i++)s[i]=w(s[i],0,255);return s[3]=w(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=w(Number.parseFloat(n[2]),0,100),s=w(Number.parseFloat(n[3]),0,100),a=w(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=w(Number.parseFloat(n[2]),0,100),s=w(Number.parseFloat(n[3]),0,100),a=w(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 w(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 $(){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 I(e){const t=$(),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 j(e,t){return function(n){return t(e(n))}}function E(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=j(c[t[o].parent][o],r),o=t[o].parent;return r.conversion=n,r}function T(e){const t=I(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]=E(s,t))}return n}const g={},U=Object.keys(c);function V(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 D(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]=D(o),g[e][r].raw=V(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(B(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([...L(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 K(e,t){return Number(e.toFixed(t))}function B(e){return function(t){return K(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 L(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 R{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 R(e),G=e=>t=>{const{screenSize:n,axis:r="horizontal",minMultiplier:o=.5,maxMultiplier:l=1.5}=e,s=Math.round(t/n*1e4)/100,a=r==="vertical"?"vh":"vw",i=Math.round(o*t),u=Math.round(l*t);return`clamp(${i}px, ${s}${a}, ${u}px)`};exports.color=J;exports.defineViewportClamp=G;
|
package/helpers.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export * from '@salty-css/core/helpers';
|