@salty-css/core 0.0.1-alpha.1 → 0.0.1-alpha.11
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +22 -18
- package/compiler/index.cjs +11 -0
- package/compiler/index.d.ts +18 -0
- package/compiler/index.js +182 -0
- package/config/config-types.d.ts +59 -0
- package/config/define-config.d.ts +2 -0
- package/config/index.cjs +1 -0
- package/config/index.d.ts +2 -0
- package/config/index.js +4 -0
- package/css/index.cjs +1 -0
- package/css/index.d.ts +1 -0
- package/css/index.js +4 -0
- package/eslint/index.cjs +1 -0
- package/eslint/index.d.ts +6 -0
- package/eslint/index.js +48 -0
- package/eslint/rules/no-variants-in-base.d.ts +2 -0
- package/generator/index.cjs +1 -0
- package/generator/index.d.ts +1 -0
- package/generator/index.js +52 -0
- package/generator/parse-modifiers.d.ts +3 -0
- package/generator/parse-styles.d.ts +2 -0
- package/generator/parse-templates.d.ts +2 -0
- package/generator/parse-tokens.d.ts +2 -0
- package/generator/parser-types.d.ts +4 -0
- package/generator/style-generator.d.ts +26 -0
- package/package.json +27 -20
- package/parse-templates-BOSK0Tb6.js +90 -0
- package/parse-templates-BY1Xai-_.cjs +8 -0
- package/types/index.cjs +1 -0
- package/types/index.d.ts +62 -0
- package/types/index.js +1 -0
- package/types/util-types.d.ts +13 -0
- package/util/dash-case.d.ts +1 -0
- package/util/index.cjs +1 -0
- package/util/index.d.ts +2 -0
- package/util/index.js +19 -0
- package/util/to-hash.d.ts +4 -0
package/README.md
CHANGED
@@ -54,8 +54,10 @@ export const IndexPage = () => {
|
|
54
54
|
import { styled } from '@salty-css/react/styled';
|
55
55
|
|
56
56
|
export const Wrapper = styled('div', {
|
57
|
-
|
58
|
-
|
57
|
+
base: {
|
58
|
+
display: 'block',
|
59
|
+
padding: '2vw',
|
60
|
+
},
|
59
61
|
});
|
60
62
|
```
|
61
63
|
|
@@ -65,22 +67,24 @@ export const Wrapper = styled('div', {
|
|
65
67
|
import { styled } from '@salty-css/react/styled';
|
66
68
|
|
67
69
|
export const Button = styled('button', {
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
70
|
+
base: {
|
71
|
+
display: 'block',
|
72
|
+
padding: `0.6em 1.2em`,
|
73
|
+
border: '1px solid currentColor',
|
74
|
+
background: 'transparent',
|
75
|
+
color: 'currentColor/40',
|
76
|
+
cursor: 'pointer',
|
77
|
+
transition: '200ms',
|
78
|
+
textDecoration: 'none',
|
79
|
+
'&:hover': {
|
80
|
+
background: 'black',
|
81
|
+
borderColor: 'black',
|
82
|
+
color: 'white',
|
83
|
+
},
|
84
|
+
'&:disabled': {
|
85
|
+
opacity: 0.25,
|
86
|
+
pointerEvents: 'none',
|
87
|
+
},
|
84
88
|
},
|
85
89
|
variants: {
|
86
90
|
variant: {
|
@@ -0,0 +1,11 @@
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const K=require("esbuild"),J=require("winston"),G=require("child_process"),N=require("../util/index.cjs"),o=require("path"),r=require("fs"),L=require("fs/promises"),_=require("../parse-templates-BY1Xai-_.cjs");function q(t){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const e=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(s,n,e.get?e:{enumerable:!0,get:()=>t[n]})}}return s.default=t,Object.freeze(s)}const R=q(K),k=q(J),A=k.createLogger({level:"info",format:k.format.combine(k.format.colorize(),k.format.cli()),transports:[new k.transports.Console({})]}),v=t=>o.join(t,"./saltygen"),M=["salty","css","styles","styled"],z=(t=[])=>new RegExp(`\\.(${[...M,...t].join("|")})\\.`),T=(t,s=[])=>z(s).test(t),U=async t=>{const s=v(t),n=o.join(t,"salty-config.ts"),e=o.join(s,"salty-config.js");await R.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:e,format:"esm",external:["react"]});const a=Date.now(),{config:h}=await import(`${e}?t=${a}`);return h},H=async t=>{const s=await U(t),n=new Set,e=(f,p=[])=>f?Object.entries(f).flatMap(([y,c])=>{if(!c)return;if(typeof c=="object")return e(c,[...p,y]);const x=[...p,y].join(".");n.add(`"${x}"`);const D=[...p.map(N.dashCase),N.dashCase(y)].join("-"),{result:P}=_.parseValueTokens(c);return`--${D}: ${P};`}):[],a=f=>f?Object.entries(f).flatMap(([p,y])=>{const c=e(y);return p==="base"?c.join(""):`${p} { ${c.join("")} }`}):[],h=f=>f?Object.entries(f).flatMap(([p,y])=>Object.entries(y).flatMap(([c,x])=>{const D=e(x,[p]),P=`.${p}-${c}, [data-${p}="${c}"]`,O=D.join("");return`${P} { ${O} }`})):[],b=e(s.variables),w=a(s.responsiveVariables),l=h(s.conditionalVariables),j=v(t),u=o.join(j,"css/variables.css"),i=`:root { ${b.join("")} ${w.join("")} } ${l.join("")}`;r.writeFileSync(u,i);const g=o.join(j,"types/css-tokens.d.ts"),d=`type VariableTokens = ${[...n].join("|")}; type PropertyValueToken = \`{\${VariableTokens}}\``;r.writeFileSync(g,d);const m=o.join(j,"css/global.css"),S=_.parseStyles(s.global,"");r.writeFileSync(m,S);const F=o.join(j,"css/templates.css"),C=_.parseTemplates(s.templates);r.writeFileSync(F,C)},V=async(t,s)=>{const n=N.toHash(t),e=o.join(s,"js",n+".js");await R.build({entryPoints:[t],minify:!0,treeShaking:!0,bundle:!0,outfile:e,format:"esm",target:["es2022"],keepNames:!0,external:["react"]});const a=Date.now();return await import(`${e}?t=${a}`)},E=async t=>{const s=v(t),n=o.join(s,"salty-config.js"),{config:e}=await import(n);return e},W=async t=>{try{const s=[],n=[],e=v(t),a=o.join(e,"index.css");(()=>{r.existsSync(e)&&G.execSync("rm -rf "+e),r.mkdirSync(e),r.mkdirSync(o.join(e,"css")),r.mkdirSync(o.join(e,"types"))})(),await H(t);const b=await E(t);async function w(i,g){const $=r.statSync(i);if($.isDirectory()){const d=r.readdirSync(i);await Promise.all(d.map(m=>w(o.join(i,m),o.join(g,m))))}else if($.isFile()&&T(i)){const m=await V(i,e),S=[];Object.entries(m).forEach(([p,y])=>{if(y.isKeyframes&&y.css){const O=`${y.animationName}.css`,I=`css/${O}`,B=o.join(e,I);s.push(O),r.writeFileSync(B,y.css);return}if(!y.generator)return;const c=y.generator._withBuildContext({name:p,config:b}),x=`${c.hash}-${c.priority}.css`;n[c.priority]||(n[c.priority]=[]),n[c.priority].push(x),S.push(x);const D=`css/${x}`,P=o.join(e,D);r.writeFileSync(P,c.css)});const F=S.map(p=>`@import url('./${p}');`).join(`
|
2
|
+
`),C=N.toHash(i,6),f=o.join(e,`css/${C}.css`);r.writeFileSync(f,F)}}await w(t,e);const l=s.map(i=>`@import url('./css/${i}');`).join(`
|
3
|
+
`);let u=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
4
|
+
|
5
|
+
${["@import url('./css/variables.css');","@import url('./css/global.css');","@import url('./css/templates.css');"].join(`
|
6
|
+
`)}
|
7
|
+
${l}`;if(b.importStrategy!=="component"){const i=n.flat().map(g=>`@import url('./css/${g}');`).join(`
|
8
|
+
`);u+=i}r.writeFileSync(a,u)}catch(s){console.error(s)}},X=async(t,s)=>{try{const n=[],e=o.join(t,"./saltygen"),a=o.join(e,"index.css");if(T(s)){const b=await E(t),w=await V(s,e);Object.entries(w).forEach(([g,$])=>{if(!$.generator)return;const d=$.generator._withBuildContext({name:g,config:b}),m=`${d.hash}-${d.priority}.css`,S=`css/${m}`,F=o.join(e,S);n.push(m),r.writeFileSync(F,d.css)});const l=r.readFileSync(a,"utf8").split(`
|
9
|
+
`),j=n.map(g=>`@import url('../saltygen/css/${g}');`),i=[...new Set([...l,...j])].join(`
|
10
|
+
`);r.writeFileSync(a,i)}}catch(n){console.error(n)}},Y=async(t,s)=>{try{const n=o.join(t,"./saltygen");if(T(s)){let a=r.readFileSync(s,"utf8");a.replace(/^(?!export\s)const\s.*/gm,u=>`export ${u}`)!==a&&await L.writeFile(s,a);const b=await E(t),w=await V(s,n);let l=a;Object.entries(w).forEach(([u,i])=>{var f;if(i.isKeyframes){console.log("value",i);return}if(!i.generator)return;const g=i.generator._withBuildContext({name:u,config:b}),$=new RegExp(`${u}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(a);if(!$)return console.error("Could not find the original declaration");const d=(f=$.at(1))==null?void 0:f.trim(),{element:m,variantKeys:S}=g.props,F=`${u} = styled(${d}, "${g.classNames}", "${g._callerName}", ${JSON.stringify(m)}, ${JSON.stringify(S)});`,C=new RegExp(`${u}[=\\s]+[^()]+styled\\(([^,]+),[^;]+;`,"g");l=l.replace(C,F)});const j=N.toHash(s,6);return b.importStrategy==="component"&&(l=`import '../../saltygen/css/${j}.css';
|
11
|
+
${l}`),l=l.replace("{ styled }","{ styledClient as styled }"),l=l.replace("@salty-css/react/styled","@salty-css/react/styled-client"),l}}catch(n){console.error(n)}};exports.compileSaltyFile=V;exports.generateCss=W;exports.generateFile=X;exports.generateVariables=H;exports.isSaltyFile=T;exports.logger=A;exports.minimizeFile=Y;exports.saltyFileExtensions=M;exports.saltyFileRegExp=z;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { StyleComponentGenerator } from '../generator/style-generator';
|
2
|
+
import * as winston from 'winston';
|
3
|
+
export declare const logger: winston.Logger;
|
4
|
+
export declare const saltyFileExtensions: string[];
|
5
|
+
export declare const saltyFileRegExp: (additional?: string[]) => RegExp;
|
6
|
+
export declare const isSaltyFile: (file: string, additional?: string[]) => boolean;
|
7
|
+
export declare const generateVariables: (dirname: string) => Promise<void>;
|
8
|
+
export declare const compileSaltyFile: (sourceFilePath: string, outputDirectory: string) => Promise<{
|
9
|
+
[key: string]: {
|
10
|
+
generator: StyleComponentGenerator;
|
11
|
+
isKeyframes?: boolean;
|
12
|
+
animationName?: string;
|
13
|
+
css?: string;
|
14
|
+
};
|
15
|
+
}>;
|
16
|
+
export declare const generateCss: (dirname: string) => Promise<void>;
|
17
|
+
export declare const generateFile: (dirname: string, file: string) => Promise<void>;
|
18
|
+
export declare const minimizeFile: (dirname: string, file: string) => Promise<string | undefined>;
|
@@ -0,0 +1,182 @@
|
|
1
|
+
import * as M from "esbuild";
|
2
|
+
import * as N from "winston";
|
3
|
+
import { execSync as z } from "child_process";
|
4
|
+
import { toHash as T, dashCase as I } from "../util/index.js";
|
5
|
+
import { join as o } from "path";
|
6
|
+
import { writeFileSync as $, existsSync as H, mkdirSync as v, statSync as J, readdirSync as G, readFileSync as _ } from "fs";
|
7
|
+
import { writeFile as L } from "fs/promises";
|
8
|
+
import { p as q, a as A, b as U } from "../parse-templates-BOSK0Tb6.js";
|
9
|
+
const rt = N.createLogger({
|
10
|
+
level: "info",
|
11
|
+
format: N.format.combine(N.format.colorize(), N.format.cli()),
|
12
|
+
transports: [new N.transports.Console({})]
|
13
|
+
}), k = (s) => o(s, "./saltygen"), W = ["salty", "css", "styles", "styled"], X = (s = []) => new RegExp(`\\.(${[...W, ...s].join("|")})\\.`), O = (s, e = []) => X(e).test(s), Y = async (s) => {
|
14
|
+
const e = k(s), n = o(s, "salty-config.ts"), t = o(e, "salty-config.js");
|
15
|
+
await M.build({
|
16
|
+
entryPoints: [n],
|
17
|
+
minify: !0,
|
18
|
+
treeShaking: !0,
|
19
|
+
bundle: !0,
|
20
|
+
outfile: t,
|
21
|
+
format: "esm",
|
22
|
+
external: ["react"]
|
23
|
+
});
|
24
|
+
const c = Date.now(), { config: j } = await import(`${t}?t=${c}`);
|
25
|
+
return j;
|
26
|
+
}, Z = async (s) => {
|
27
|
+
const e = await Y(s), n = /* @__PURE__ */ new Set(), t = (m, l = []) => m ? Object.entries(m).flatMap(([p, i]) => {
|
28
|
+
if (!i) return;
|
29
|
+
if (typeof i == "object") return t(i, [...l, p]);
|
30
|
+
const x = [...l, p].join(".");
|
31
|
+
n.add(`"${x}"`);
|
32
|
+
const D = [...l.map(I), I(p)].join("-"), { result: P } = U(i);
|
33
|
+
return `--${D}: ${P};`;
|
34
|
+
}) : [], c = (m) => m ? Object.entries(m).flatMap(([l, p]) => {
|
35
|
+
const i = t(p);
|
36
|
+
return l === "base" ? i.join("") : `${l} { ${i.join("")} }`;
|
37
|
+
}) : [], j = (m) => m ? Object.entries(m).flatMap(([l, p]) => Object.entries(p).flatMap(([i, x]) => {
|
38
|
+
const D = t(x, [l]), P = `.${l}-${i}, [data-${l}="${i}"]`, V = D.join("");
|
39
|
+
return `${P} { ${V} }`;
|
40
|
+
})) : [], d = t(e.variables), w = c(e.responsiveVariables), a = j(e.conditionalVariables), b = k(s), y = o(b, "css/variables.css"), r = `:root { ${d.join("")} ${w.join("")} } ${a.join("")}`;
|
41
|
+
$(y, r);
|
42
|
+
const f = o(b, "types/css-tokens.d.ts"), u = `type VariableTokens = ${[...n].join("|")}; type PropertyValueToken = \`{\${VariableTokens}}\``;
|
43
|
+
$(f, u);
|
44
|
+
const g = o(b, "css/global.css"), F = q(e.global, "");
|
45
|
+
$(g, F);
|
46
|
+
const S = o(b, "css/templates.css"), C = A(e.templates);
|
47
|
+
$(S, C);
|
48
|
+
}, E = async (s, e) => {
|
49
|
+
const n = T(s), t = o(e, "js", n + ".js");
|
50
|
+
await M.build({
|
51
|
+
entryPoints: [s],
|
52
|
+
minify: !0,
|
53
|
+
treeShaking: !0,
|
54
|
+
bundle: !0,
|
55
|
+
outfile: t,
|
56
|
+
format: "esm",
|
57
|
+
target: ["es2022"],
|
58
|
+
keepNames: !0,
|
59
|
+
external: ["react"]
|
60
|
+
});
|
61
|
+
const c = Date.now();
|
62
|
+
return await import(`${t}?t=${c}`);
|
63
|
+
}, R = async (s) => {
|
64
|
+
const e = k(s), n = o(e, "salty-config.js"), { config: t } = await import(n);
|
65
|
+
return t;
|
66
|
+
}, it = async (s) => {
|
67
|
+
try {
|
68
|
+
const e = [], n = [], t = k(s), c = o(t, "index.css");
|
69
|
+
(() => {
|
70
|
+
H(t) && z("rm -rf " + t), v(t), v(o(t, "css")), v(o(t, "types"));
|
71
|
+
})(), await Z(s);
|
72
|
+
const d = await R(s);
|
73
|
+
async function w(r, f) {
|
74
|
+
const h = J(r);
|
75
|
+
if (h.isDirectory()) {
|
76
|
+
const u = G(r);
|
77
|
+
await Promise.all(u.map((g) => w(o(r, g), o(f, g))));
|
78
|
+
} else if (h.isFile() && O(r)) {
|
79
|
+
const g = await E(r, t), F = [];
|
80
|
+
Object.entries(g).forEach(([l, p]) => {
|
81
|
+
if (p.isKeyframes && p.css) {
|
82
|
+
const V = `${p.animationName}.css`, B = `css/${V}`, K = o(t, B);
|
83
|
+
e.push(V), $(K, p.css);
|
84
|
+
return;
|
85
|
+
}
|
86
|
+
if (!p.generator) return;
|
87
|
+
const i = p.generator._withBuildContext({
|
88
|
+
name: l,
|
89
|
+
config: d
|
90
|
+
}), x = `${i.hash}-${i.priority}.css`;
|
91
|
+
n[i.priority] || (n[i.priority] = []), n[i.priority].push(x), F.push(x);
|
92
|
+
const D = `css/${x}`, P = o(t, D);
|
93
|
+
$(P, i.css);
|
94
|
+
});
|
95
|
+
const S = F.map((l) => `@import url('./${l}');`).join(`
|
96
|
+
`), C = T(r, 6), m = o(t, `css/${C}.css`);
|
97
|
+
$(m, S);
|
98
|
+
}
|
99
|
+
}
|
100
|
+
await w(s, t);
|
101
|
+
const a = e.map((r) => `@import url('./css/${r}');`).join(`
|
102
|
+
`);
|
103
|
+
let y = `@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
104
|
+
|
105
|
+
${["@import url('./css/variables.css');", "@import url('./css/global.css');", "@import url('./css/templates.css');"].join(`
|
106
|
+
`)}
|
107
|
+
${a}`;
|
108
|
+
if (d.importStrategy !== "component") {
|
109
|
+
const r = n.flat().map((f) => `@import url('./css/${f}');`).join(`
|
110
|
+
`);
|
111
|
+
y += r;
|
112
|
+
}
|
113
|
+
$(c, y);
|
114
|
+
} catch (e) {
|
115
|
+
console.error(e);
|
116
|
+
}
|
117
|
+
}, ct = async (s, e) => {
|
118
|
+
try {
|
119
|
+
const n = [], t = o(s, "./saltygen"), c = o(t, "index.css");
|
120
|
+
if (O(e)) {
|
121
|
+
const d = await R(s), w = await E(e, t);
|
122
|
+
Object.entries(w).forEach(([f, h]) => {
|
123
|
+
if (!h.generator) return;
|
124
|
+
const u = h.generator._withBuildContext({
|
125
|
+
name: f,
|
126
|
+
config: d
|
127
|
+
}), g = `${u.hash}-${u.priority}.css`, F = `css/${g}`, S = o(t, F);
|
128
|
+
n.push(g), $(S, u.css);
|
129
|
+
});
|
130
|
+
const a = _(c, "utf8").split(`
|
131
|
+
`), b = n.map((f) => `@import url('../saltygen/css/${f}');`), r = [.../* @__PURE__ */ new Set([...a, ...b])].join(`
|
132
|
+
`);
|
133
|
+
$(c, r);
|
134
|
+
}
|
135
|
+
} catch (n) {
|
136
|
+
console.error(n);
|
137
|
+
}
|
138
|
+
}, at = async (s, e) => {
|
139
|
+
try {
|
140
|
+
const n = o(s, "./saltygen");
|
141
|
+
if (O(e)) {
|
142
|
+
let c = _(e, "utf8");
|
143
|
+
c.replace(/^(?!export\s)const\s.*/gm, (y) => `export ${y}`) !== c && await L(e, c);
|
144
|
+
const d = await R(s), w = await E(e, n);
|
145
|
+
let a = c;
|
146
|
+
Object.entries(w).forEach(([y, r]) => {
|
147
|
+
var m;
|
148
|
+
if (r.isKeyframes) {
|
149
|
+
console.log("value", r);
|
150
|
+
return;
|
151
|
+
}
|
152
|
+
if (!r.generator) return;
|
153
|
+
const f = r.generator._withBuildContext({
|
154
|
+
name: y,
|
155
|
+
config: d
|
156
|
+
}), h = new RegExp(`${y}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(c);
|
157
|
+
if (!h)
|
158
|
+
return console.error("Could not find the original declaration");
|
159
|
+
const u = (m = h.at(1)) == null ? void 0 : m.trim(), { element: g, variantKeys: F } = f.props, S = `${y} = styled(${u}, "${f.classNames}", "${f._callerName}", ${JSON.stringify(g)}, ${JSON.stringify(
|
160
|
+
F
|
161
|
+
)});`, C = new RegExp(`${y}[=\\s]+[^()]+styled\\(([^,]+),[^;]+;`, "g");
|
162
|
+
a = a.replace(C, S);
|
163
|
+
});
|
164
|
+
const b = T(e, 6);
|
165
|
+
return d.importStrategy === "component" && (a = `import '../../saltygen/css/${b}.css';
|
166
|
+
${a}`), a = a.replace("{ styled }", "{ styledClient as styled }"), a = a.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), a;
|
167
|
+
}
|
168
|
+
} catch (n) {
|
169
|
+
console.error(n);
|
170
|
+
}
|
171
|
+
};
|
172
|
+
export {
|
173
|
+
E as compileSaltyFile,
|
174
|
+
it as generateCss,
|
175
|
+
ct as generateFile,
|
176
|
+
Z as generateVariables,
|
177
|
+
O as isSaltyFile,
|
178
|
+
rt as logger,
|
179
|
+
at as minimizeFile,
|
180
|
+
W as saltyFileExtensions,
|
181
|
+
X as saltyFileRegExp
|
182
|
+
};
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import { CssStyles } from '../types';
|
2
|
+
type CssTemplate = CssStyles | {
|
3
|
+
[key: PropertyKey]: CssTemplate;
|
4
|
+
};
|
5
|
+
export type CssVariables = Record<string, unknown>;
|
6
|
+
export interface CssResponsiveVariables {
|
7
|
+
[key: string]: CssVariables;
|
8
|
+
}
|
9
|
+
export interface CssConditionalVariables {
|
10
|
+
[key: PropertyKey]: {
|
11
|
+
[key: PropertyKey]: CssVariables;
|
12
|
+
};
|
13
|
+
}
|
14
|
+
export interface CssTemplates {
|
15
|
+
[key: PropertyKey]: {
|
16
|
+
[key: PropertyKey]: CssTemplate;
|
17
|
+
};
|
18
|
+
}
|
19
|
+
export interface CssModifier {
|
20
|
+
pattern: RegExp;
|
21
|
+
transform: (regexMatch: string) => {
|
22
|
+
css?: CssStyles;
|
23
|
+
value: string;
|
24
|
+
};
|
25
|
+
}
|
26
|
+
export type CssModifiers = Record<string, CssModifier>;
|
27
|
+
export interface SaltyConfig {
|
28
|
+
/**
|
29
|
+
* The import strategy to use when importing css files.
|
30
|
+
* - `root` will import the css file from the root of the project.
|
31
|
+
* - `component` will import the css file from the component's directory.
|
32
|
+
*/
|
33
|
+
importStrategy?: 'root' | 'component';
|
34
|
+
/**
|
35
|
+
* Base variables that can be used in all styles as they are applied globally to :root.
|
36
|
+
*/
|
37
|
+
variables?: CssVariables;
|
38
|
+
/**
|
39
|
+
* Variables that are defined for different media queries.
|
40
|
+
*/
|
41
|
+
responsiveVariables?: CssResponsiveVariables;
|
42
|
+
/**
|
43
|
+
* Variables that are defined for different parent selectors (classes or data attributes).
|
44
|
+
*/
|
45
|
+
conditionalVariables?: CssConditionalVariables;
|
46
|
+
/**
|
47
|
+
* The global styles that are imported in the root of the project.
|
48
|
+
*/
|
49
|
+
global?: CssStyles;
|
50
|
+
/**
|
51
|
+
* The templates that can be used in styles to create reusable css.
|
52
|
+
*/
|
53
|
+
templates?: CssTemplates;
|
54
|
+
/**
|
55
|
+
* The modifiers that can transform css values.
|
56
|
+
*/
|
57
|
+
modifiers?: CssModifiers;
|
58
|
+
}
|
59
|
+
export {};
|
package/config/index.cjs
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=e=>e;exports.defineConfig=n;
|
package/config/index.js
ADDED
package/css/index.cjs
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=e=>`{${e}}`;exports.token=t;
|
package/css/index.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export declare const token: <T extends VariableTokens>(token: T) => string;
|
package/css/index.js
ADDED
package/eslint/index.cjs
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";const l=require("../compiler/index.cjs"),c={meta:{type:"problem",docs:{description:"Ensure `variants` are not nested inside `base` in styled calls",category:"Errors",recommended:!0},messages:{nestedVariants:"`variants` should not be nested inside `base`."}},create(r){return l.isSaltyFile(r.filename)?{CallExpression:o=>{try{const{callee:s,arguments:d}=o;if(!(s.type==="Identifier"&&s.name==="styled"))return;const t=d[0];if(!t||!(t.type==="ObjectExpression"))return;const n=t.properties.find(e=>e.type==="Property"&&e.key.type==="Identifier"&&e.key.name==="base");if(!n)return;const{value:a}=n;if(!(a.type==="ObjectExpression"))return;const i=a.properties.find(e=>e.type==="Property"&&e.key.type==="Identifier"&&e.key.name==="variants");if(!i)return;r.report({node:i,messageId:"nestedVariants"})}catch(s){console.log("ESlint error",s);return}}}:{}}},y={rules:{"no-variants-in-base":c}};module.exports=y;
|
package/eslint/index.js
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
import { isSaltyFile as l } from "../compiler/index.js";
|
2
|
+
const y = {
|
3
|
+
meta: {
|
4
|
+
type: "problem",
|
5
|
+
docs: {
|
6
|
+
description: "Ensure `variants` are not nested inside `base` in styled calls",
|
7
|
+
category: "Errors",
|
8
|
+
recommended: !0
|
9
|
+
},
|
10
|
+
messages: {
|
11
|
+
nestedVariants: "`variants` should not be nested inside `base`."
|
12
|
+
}
|
13
|
+
},
|
14
|
+
create(r) {
|
15
|
+
return l(r.filename) ? {
|
16
|
+
CallExpression: (o) => {
|
17
|
+
try {
|
18
|
+
const { callee: s, arguments: d } = o;
|
19
|
+
if (!(s.type === "Identifier" && s.name === "styled")) return;
|
20
|
+
const t = d[0];
|
21
|
+
if (!t || !(t.type === "ObjectExpression")) return;
|
22
|
+
const n = t.properties.find((e) => e.type === "Property" && e.key.type === "Identifier" && e.key.name === "base");
|
23
|
+
if (!n) return;
|
24
|
+
const { value: a } = n;
|
25
|
+
if (!(a.type === "ObjectExpression")) return;
|
26
|
+
const i = a.properties.find(
|
27
|
+
(e) => e.type === "Property" && e.key.type === "Identifier" && e.key.name === "variants"
|
28
|
+
);
|
29
|
+
if (!i) return;
|
30
|
+
r.report({
|
31
|
+
node: i,
|
32
|
+
messageId: "nestedVariants"
|
33
|
+
});
|
34
|
+
} catch (s) {
|
35
|
+
console.log("ESlint error", s);
|
36
|
+
return;
|
37
|
+
}
|
38
|
+
}
|
39
|
+
} : {};
|
40
|
+
}
|
41
|
+
}, b = {
|
42
|
+
rules: {
|
43
|
+
"no-variants-in-base": y
|
44
|
+
}
|
45
|
+
};
|
46
|
+
export {
|
47
|
+
b as default
|
48
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../util/index.cjs"),i=require("../parse-templates-BY1Xai-_.cjs");class o{constructor(t,s){this.tagName=t,this.params=s}get hash(){return n.toHash(this.params.base||this.params)}get priority(){var t;return typeof this.tagName=="function"||typeof this.tagName=="object"?(((t=this.tagName.generator)==null?void 0:t.priority)||0)+1:0}get classNames(){const t=[this.hash],{className:s}=this.params;return s&&t.push(s),t.join(" ")}get cssClassName(){return this.hash}get cssDisplayNameVar(){return`--${this.hash}-display-name: ${this._callerName};`}get templateKeys(){var t;return(t=this._context)!=null&&t.config.templates?i.getTemplateKeys(this._context.config.templates):[]}get css(){var a;const{base:t={},variants:s={},compoundVariants:e=[]}=this.params,r={...t,variants:s,compoundVariants:e};return i.parseStyles(r,`.${this.cssClassName}`,this.priority,(a=this._context)==null?void 0:a.config)}get props(){const{element:t}=this.params,s=this.params.variants?Object.keys(this.params.variants).map(e=>{var a;const r=(a=this.params.defaultVariants)==null?void 0:a[e];return r!==void 0?`${e}=${String(r)}`:e}):void 0;return{element:t,variantKeys:s}}_withBuildContext(t){this._context=t;const{name:s,config:e}=t;return this._callerName=s,this}}exports.StyleComponentGenerator=o;
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './style-generator';
|
@@ -0,0 +1,52 @@
|
|
1
|
+
import { toHash as i } from "../util/index.js";
|
2
|
+
import { g as n, p as o } from "../parse-templates-BOSK0Tb6.js";
|
3
|
+
class p {
|
4
|
+
constructor(t, s) {
|
5
|
+
this.tagName = t, this.params = s;
|
6
|
+
}
|
7
|
+
get hash() {
|
8
|
+
return i(this.params.base || this.params);
|
9
|
+
}
|
10
|
+
get priority() {
|
11
|
+
var t;
|
12
|
+
return typeof this.tagName == "function" || typeof this.tagName == "object" ? (((t = this.tagName.generator) == null ? void 0 : t.priority) || 0) + 1 : 0;
|
13
|
+
}
|
14
|
+
get classNames() {
|
15
|
+
const t = [this.hash], { className: s } = this.params;
|
16
|
+
return s && t.push(s), t.join(" ");
|
17
|
+
}
|
18
|
+
get cssClassName() {
|
19
|
+
return this.hash;
|
20
|
+
}
|
21
|
+
get cssDisplayNameVar() {
|
22
|
+
return `--${this.hash}-display-name: ${this._callerName};`;
|
23
|
+
}
|
24
|
+
get templateKeys() {
|
25
|
+
var t;
|
26
|
+
return (t = this._context) != null && t.config.templates ? n(this._context.config.templates) : [];
|
27
|
+
}
|
28
|
+
get css() {
|
29
|
+
var e;
|
30
|
+
const { base: t = {}, variants: s = {}, compoundVariants: a = [] } = this.params, r = { ...t, variants: s, compoundVariants: a };
|
31
|
+
return o(r, `.${this.cssClassName}`, this.priority, (e = this._context) == null ? void 0 : e.config);
|
32
|
+
}
|
33
|
+
get props() {
|
34
|
+
const { element: t } = this.params, s = this.params.variants ? Object.keys(this.params.variants).map((a) => {
|
35
|
+
var e;
|
36
|
+
const r = (e = this.params.defaultVariants) == null ? void 0 : e[a];
|
37
|
+
return r !== void 0 ? `${a}=${String(r)}` : a;
|
38
|
+
}) : void 0;
|
39
|
+
return {
|
40
|
+
element: t,
|
41
|
+
variantKeys: s
|
42
|
+
};
|
43
|
+
}
|
44
|
+
_withBuildContext(t) {
|
45
|
+
this._context = t;
|
46
|
+
const { name: s, config: a } = t;
|
47
|
+
return this._callerName = s, this;
|
48
|
+
}
|
49
|
+
}
|
50
|
+
export {
|
51
|
+
p as StyleComponentGenerator
|
52
|
+
};
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { StyledParams, Tag } from '../types';
|
2
|
+
export declare class StyleComponentGenerator {
|
3
|
+
tagName: Tag<any>;
|
4
|
+
params: StyledParams;
|
5
|
+
_callerName: string | undefined;
|
6
|
+
_context: {
|
7
|
+
name: string;
|
8
|
+
config: any;
|
9
|
+
} | undefined;
|
10
|
+
constructor(tagName: Tag<any>, params: StyledParams);
|
11
|
+
get hash(): string;
|
12
|
+
get priority(): number;
|
13
|
+
get classNames(): string;
|
14
|
+
get cssClassName(): string;
|
15
|
+
get cssDisplayNameVar(): string;
|
16
|
+
get templateKeys(): string[];
|
17
|
+
get css(): string;
|
18
|
+
get props(): {
|
19
|
+
element: string | undefined;
|
20
|
+
variantKeys: string[] | undefined;
|
21
|
+
};
|
22
|
+
_withBuildContext(context: {
|
23
|
+
name: string;
|
24
|
+
config: any;
|
25
|
+
}): this;
|
26
|
+
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@salty-css/core",
|
3
|
-
"version": "0.0.1-alpha.
|
3
|
+
"version": "0.0.1-alpha.11",
|
4
4
|
"main": "./dist/index.js",
|
5
5
|
"module": "./dist/index.mjs",
|
6
6
|
"typings": "./dist/index.d.ts",
|
@@ -15,36 +15,43 @@
|
|
15
15
|
"url": "https://github.com/margarita-form/salty-css/issues"
|
16
16
|
},
|
17
17
|
"files": [
|
18
|
-
"
|
18
|
+
"**/*",
|
19
19
|
"!**/*.tsbuildinfo"
|
20
20
|
],
|
21
21
|
"nx": {
|
22
|
+
"sourceRoot": "libs/core/src",
|
22
23
|
"name": "core"
|
23
24
|
},
|
25
|
+
"peerDependencies": {
|
26
|
+
"esbuild": "0.21.x",
|
27
|
+
"eslint": "^9.x",
|
28
|
+
"react": "^18.x",
|
29
|
+
"winston": ">=3.x"
|
30
|
+
},
|
24
31
|
"exports": {
|
25
|
-
"
|
26
|
-
"import": "./index.js",
|
27
|
-
"require": "./index.cjs"
|
32
|
+
"./compiler": {
|
33
|
+
"import": "./compiler/index.js",
|
34
|
+
"require": "./compiler/index.cjs"
|
28
35
|
},
|
29
|
-
"./
|
30
|
-
"import": "./
|
31
|
-
"require": "./
|
36
|
+
"./css": {
|
37
|
+
"import": "./css/index.js",
|
38
|
+
"require": "./css/index.cjs"
|
32
39
|
},
|
33
|
-
"./
|
34
|
-
"import": "./
|
35
|
-
"require": "./
|
40
|
+
"./generator": {
|
41
|
+
"import": "./generator/index.js",
|
42
|
+
"require": "./generator/index.cjs"
|
36
43
|
},
|
37
|
-
"./
|
38
|
-
"import": "./
|
39
|
-
"require": "./
|
44
|
+
"./config": {
|
45
|
+
"import": "./config/index.js",
|
46
|
+
"require": "./config/index.cjs"
|
40
47
|
},
|
41
|
-
"./
|
42
|
-
"import": "./
|
43
|
-
"require": "./
|
48
|
+
"./types": {
|
49
|
+
"import": "./types/index.js",
|
50
|
+
"require": "./types/index.cjs"
|
44
51
|
},
|
45
|
-
"./
|
46
|
-
"import": "./
|
47
|
-
"require": "./
|
52
|
+
"./util": {
|
53
|
+
"import": "./util/index.js",
|
54
|
+
"require": "./util/index.cjs"
|
48
55
|
}
|
49
56
|
}
|
50
57
|
}
|
@@ -0,0 +1,90 @@
|
|
1
|
+
import { dashCase as O } from "./util/index.js";
|
2
|
+
const N = (s, r) => {
|
3
|
+
if (typeof s != "string") return { result: s };
|
4
|
+
if (!r) return { result: s };
|
5
|
+
const e = [];
|
6
|
+
return Object.values(r).forEach((n) => {
|
7
|
+
const { pattern: o, transform: c } = n;
|
8
|
+
s = s.replace(o, (h) => {
|
9
|
+
const { value: i, css: m } = c(h);
|
10
|
+
return m && e.push(m), i;
|
11
|
+
});
|
12
|
+
}), { result: s, additionalCss: e };
|
13
|
+
}, P = (s) => typeof s != "string" ? { result: s } : /\{[^{}]+\}/g.test(s) ? { result: s.replace(/\{([^{}]+)\}/g, (...n) => `var(--${O(n[1].replaceAll(".", "-"))})`) } : { result: s }, d = (s, r, e, n) => {
|
14
|
+
const o = [], c = Object.entries(s).reduce((i, [m, t]) => {
|
15
|
+
const p = m.trim();
|
16
|
+
if (typeof t == "function" && (t = t()), typeof t == "object") {
|
17
|
+
if (!t) return i;
|
18
|
+
if (p === "variants")
|
19
|
+
return Object.entries(t).forEach(([u, f]) => {
|
20
|
+
f && Object.entries(f).forEach(([b, j]) => {
|
21
|
+
if (!j) return;
|
22
|
+
const l = `${r}.${u}-${b}`, y = d(j, l, e);
|
23
|
+
o.push(y);
|
24
|
+
});
|
25
|
+
}), i;
|
26
|
+
if (p === "defaultVariants")
|
27
|
+
return i;
|
28
|
+
if (p === "compoundVariants")
|
29
|
+
return t.forEach((u) => {
|
30
|
+
const { css: f, ...b } = u, j = Object.entries(b).reduce((y, [V, W]) => `${y}.${V}-${W}`, r), l = d(f, j, e);
|
31
|
+
o.push(l);
|
32
|
+
}), i;
|
33
|
+
if (p.startsWith("@")) {
|
34
|
+
const u = d(t, r, e), f = `${p} {
|
35
|
+
${u.replace(`
|
36
|
+
`, `
|
37
|
+
`)}
|
38
|
+
}`;
|
39
|
+
return o.push(f), i;
|
40
|
+
}
|
41
|
+
const $ = m.includes("&") ? p.replace("&", r) : p.startsWith(":") ? `${r}${p}` : `${r} ${p}`, a = d(t, $, e);
|
42
|
+
return o.push(a), i;
|
43
|
+
}
|
44
|
+
if (n != null && n.templates && n.templates[p]) {
|
45
|
+
const a = t.split(".").reduce((f, b) => f[b], n.templates[p]), u = d(a, "");
|
46
|
+
return `${i}${u}`;
|
47
|
+
}
|
48
|
+
const g = p.startsWith("-") ? p : O(p), E = ($, a = ";") => i = `${i}${$}${a}`, S = ($) => E(`${g}:${$}`);
|
49
|
+
if (typeof t == "number") return S(t);
|
50
|
+
if (typeof t != "string")
|
51
|
+
if ("toString" in t) t = t.toString();
|
52
|
+
else return i;
|
53
|
+
const { modifiers: k } = n || {}, T = function* () {
|
54
|
+
yield P(t), yield N(t, k);
|
55
|
+
}();
|
56
|
+
for (const { result: $, additionalCss: a = [] } of T)
|
57
|
+
t = $, a.forEach((u) => {
|
58
|
+
const f = d(u, "");
|
59
|
+
E(f, "");
|
60
|
+
});
|
61
|
+
return S(t);
|
62
|
+
}, "");
|
63
|
+
if (!c) return o.join(`
|
64
|
+
`);
|
65
|
+
if (!r) return c;
|
66
|
+
let h = "";
|
67
|
+
return e !== void 0 ? h = `@layer l${e} { ${r} { ${c} } }` : h = `${r} { ${c} }`, [h, ...o].join(`
|
68
|
+
`);
|
69
|
+
}, _ = (s, r = []) => {
|
70
|
+
const e = [], n = {};
|
71
|
+
if (Object.entries(s).forEach(([o, c]) => {
|
72
|
+
if (typeof c == "object") {
|
73
|
+
if (!c) return;
|
74
|
+
const h = o.trim(), i = _(c, [...r, h]);
|
75
|
+
e.push(i);
|
76
|
+
} else
|
77
|
+
n[o] = c;
|
78
|
+
}), Object.keys(n).length) {
|
79
|
+
const o = r.map(O).join("-"), c = d(n, `.${o}`);
|
80
|
+
e.push(c);
|
81
|
+
}
|
82
|
+
return e.join(`
|
83
|
+
`);
|
84
|
+
}, A = (s) => Object.keys(s);
|
85
|
+
export {
|
86
|
+
_ as a,
|
87
|
+
P as b,
|
88
|
+
A as g,
|
89
|
+
d as p
|
90
|
+
};
|
@@ -0,0 +1,8 @@
|
|
1
|
+
"use strict";const O=require("./util/index.cjs"),K=(s,e)=>{if(typeof s!="string")return{result:s};if(!e)return{result:s};const r=[];return Object.values(e).forEach(n=>{const{pattern:o,transform:c}=n;s=s.replace(o,a=>{const{value:i,css:l}=c(a);return l&&r.push(l),i})}),{result:s,additionalCss:r}},k=s=>typeof s!="string"?{result:s}:/\{[^{}]+\}/g.test(s)?{result:s.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${O.dashCase(n[1].replaceAll(".","-"))})`)}:{result:s},h=(s,e,r,n)=>{const o=[],c=Object.entries(s).reduce((i,[l,t])=>{const p=l.trim();if(typeof t=="function"&&(t=t()),typeof t=="object"){if(!t)return i;if(p==="variants")return Object.entries(t).forEach(([u,f])=>{f&&Object.entries(f).forEach(([m,j])=>{if(!j)return;const y=`${e}.${u}-${m}`,b=h(j,y,r);o.push(b)})}),i;if(p==="defaultVariants")return i;if(p==="compoundVariants")return t.forEach(u=>{const{css:f,...m}=u,j=Object.entries(m).reduce((b,[_,q])=>`${b}.${_}-${q}`,e),y=h(f,j,r);o.push(y)}),i;if(p.startsWith("@")){const u=h(t,e,r),f=`${p} {
|
2
|
+
${u.replace(`
|
3
|
+
`,`
|
4
|
+
`)}
|
5
|
+
}`;return o.push(f),i}const $=l.includes("&")?p.replace("&",e):p.startsWith(":")?`${e}${p}`:`${e} ${p}`,d=h(t,$,r);return o.push(d),i}if(n!=null&&n.templates&&n.templates[p]){const d=t.split(".").reduce((f,m)=>f[m],n.templates[p]),u=h(d,"");return`${i}${u}`}const V=p.startsWith("-")?p:O.dashCase(p),T=($,d=";")=>i=`${i}${$}${d}`,S=$=>T(`${V}:${$}`);if(typeof t=="number")return S(t);if(typeof t!="string")if("toString"in t)t=t.toString();else return i;const{modifiers:g}=n||{},W=function*(){yield k(t),yield K(t,g)}();for(const{result:$,additionalCss:d=[]}of W)t=$,d.forEach(u=>{const f=h(u,"");T(f,"")});return S(t)},"");if(!c)return o.join(`
|
6
|
+
`);if(!e)return c;let a="";return r!==void 0?a=`@layer l${r} { ${e} { ${c} } }`:a=`${e} { ${c} }`,[a,...o].join(`
|
7
|
+
`)},E=(s,e=[])=>{const r=[],n={};if(Object.entries(s).forEach(([o,c])=>{if(typeof c=="object"){if(!c)return;const a=o.trim(),i=E(c,[...e,a]);r.push(i)}else n[o]=c}),Object.keys(n).length){const o=e.map(O.dashCase).join("-"),c=h(n,`.${o}`);r.push(c)}return r.join(`
|
8
|
+
`)},N=s=>Object.keys(s);exports.getTemplateKeys=N;exports.parseStyles=h;exports.parseTemplates=E;exports.parseValueTokens=k;
|
package/types/index.cjs
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";
|
package/types/index.d.ts
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
import { AllHTMLAttributes, ReactDOM, ReactNode } from 'react';
|
2
|
+
import { StyleComponentGenerator } from '../generator';
|
3
|
+
import { OrString } from './util-types';
|
4
|
+
export type CreateElementProps = {
|
5
|
+
extend?: Tag<any>;
|
6
|
+
children?: ReactNode;
|
7
|
+
className?: string;
|
8
|
+
element?: string;
|
9
|
+
passVariantProps?: boolean;
|
10
|
+
style?: any;
|
11
|
+
/** vks = Variant key set */
|
12
|
+
_vks?: Set<string>;
|
13
|
+
};
|
14
|
+
export type StyledComponentProps = Record<string, unknown> & CreateElementProps & CssRuntimeValues;
|
15
|
+
type FnComponent<PROPS extends StyledComponentProps> = {
|
16
|
+
(props: PROPS): ReactNode;
|
17
|
+
generator?: StyleComponentGenerator;
|
18
|
+
};
|
19
|
+
export type Tag<PROPS extends StyledComponentProps> = OrString | keyof ReactDOM | FnComponent<PROPS>;
|
20
|
+
export type CompoundVariant = {
|
21
|
+
[key: PropertyKey]: any;
|
22
|
+
css: CssStyles;
|
23
|
+
};
|
24
|
+
type InvalidVariantKeys = keyof AllHTMLAttributes<HTMLElement>;
|
25
|
+
type StyleKeys = keyof Required<AllHTMLAttributes<HTMLElement>>['style'];
|
26
|
+
export type StyleValue<K extends string> = K extends StyleKeys ? Required<AllHTMLAttributes<HTMLElement>>['style'][K] : never;
|
27
|
+
type VariantOptions = {
|
28
|
+
[key in InvalidVariantKeys]?: never;
|
29
|
+
};
|
30
|
+
type Variants = {
|
31
|
+
variants?: VariantOptions & {
|
32
|
+
[key: PropertyKey]: {
|
33
|
+
[key: string]: Styles;
|
34
|
+
};
|
35
|
+
};
|
36
|
+
defaultVariants?: {
|
37
|
+
[key: PropertyKey]: any;
|
38
|
+
};
|
39
|
+
compoundVariants?: CompoundVariant[];
|
40
|
+
};
|
41
|
+
type VariantPropValue<T> = T extends 'true' ? 'true' | true : T;
|
42
|
+
export type VariantProps<STYLES extends StyledParams> = STYLES['variants'] extends undefined ? {} : {
|
43
|
+
[K in keyof STYLES['variants']]?: VariantPropValue<keyof STYLES['variants'][K]> | '';
|
44
|
+
};
|
45
|
+
export type ParentComponentProps<TAG extends Tag<any>> = TAG extends (props: infer P) => ReactNode ? P : unknown;
|
46
|
+
export type CssRuntimeValues = {
|
47
|
+
cssValues?: Record<string, unknown>;
|
48
|
+
};
|
49
|
+
type StylePropertyValue = Record<never, never> & unknown;
|
50
|
+
export type CssStyles = {
|
51
|
+
[key in StyleKeys | OrString]?: StyleValue<key> | StylePropertyValue | PropertyValueToken | CssStyles;
|
52
|
+
};
|
53
|
+
export type Styles = CssStyles & Variants;
|
54
|
+
export interface GeneratorOptions {
|
55
|
+
className?: string;
|
56
|
+
displayName?: string;
|
57
|
+
element?: string;
|
58
|
+
}
|
59
|
+
export interface StyledParams extends GeneratorOptions, Variants {
|
60
|
+
base?: CssStyles;
|
61
|
+
}
|
62
|
+
export {};
|
package/types/index.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
export type CommonRecord<TYPE = unknown> = Record<PropertyKey, TYPE>;
|
2
|
+
export type IsUnion<T, U extends T = T> = T extends unknown ? ([U] extends [T] ? false : true) : false;
|
3
|
+
export type IsSpecifiedString<T> = T extends string ? (string extends T ? false : true) : false;
|
4
|
+
export type NeverObj = Record<never, never>;
|
5
|
+
export type OrAny = any & NeverObj;
|
6
|
+
export type NotFunction = string | number | boolean | object | null | undefined | CommonRecord;
|
7
|
+
export type OrT<T> = T & NeverObj;
|
8
|
+
export type OrString = OrT<string>;
|
9
|
+
export type OrNumber = OrT<number>;
|
10
|
+
export type ReplaceAny<TYPE, WITH = unknown> = TYPE extends any ? WITH : TYPE;
|
11
|
+
export type BothTrue<T, U> = T extends true ? (U extends true ? true : false) : false;
|
12
|
+
export type EitherTrue<T, U> = T extends true ? true : U extends true ? true : false;
|
13
|
+
export type Tail<T extends any[]> = ((...args: T) => any) extends (arg: any, ...rest: infer R) => any ? R : never;
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function dashCase(str: PropertyKey): string;
|
package/util/index.cjs
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=t=>String.fromCharCode(t+(t>25?39:97)),o=(t,r)=>{let e="",a;for(a=Math.abs(t);a>52;a=a/52|0)e=n(a%52)+e;return e=n(a%52)+e,e.length<r?e=e.padStart(r,"a"):e.length>r&&(e=e.slice(-r)),e},i=(t,r)=>{let e=r.length;for(;e;)t=t*33^r.charCodeAt(--e);return t},s=(t,r=3)=>{const e=i(5381,JSON.stringify(t))>>>0;return o(e,r)};function c(t){return t?typeof t!="string"?String(t):t.replace(/\s/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(r,e)=>(e>0?"-":"")+r.toLowerCase()):""}exports.dashCase=c;exports.toHash=s;
|
package/util/index.d.ts
ADDED
package/util/index.js
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
const n = (e) => String.fromCharCode(e + (e > 25 ? 39 : 97)), o = (e, r) => {
|
2
|
+
let t = "", a;
|
3
|
+
for (a = Math.abs(e); a > 52; a = a / 52 | 0) t = n(a % 52) + t;
|
4
|
+
return t = n(a % 52) + t, t.length < r ? t = t.padStart(r, "a") : t.length > r && (t = t.slice(-r)), t;
|
5
|
+
}, i = (e, r) => {
|
6
|
+
let t = r.length;
|
7
|
+
for (; t; ) e = e * 33 ^ r.charCodeAt(--t);
|
8
|
+
return e;
|
9
|
+
}, s = (e, r = 3) => {
|
10
|
+
const t = i(5381, JSON.stringify(e)) >>> 0;
|
11
|
+
return o(t, r);
|
12
|
+
};
|
13
|
+
function c(e) {
|
14
|
+
return e ? typeof e != "string" ? String(e) : e.replace(/\s/g, "-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (r, t) => (t > 0 ? "-" : "") + r.toLowerCase()) : "";
|
15
|
+
}
|
16
|
+
export {
|
17
|
+
c as dashCase,
|
18
|
+
s as toHash
|
19
|
+
};
|