@salty-css/core 0.0.1-alpha.11 → 0.0.1-alpha.111
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/.saltyrc.schema.json +40 -0
- package/README.md +83 -8
- package/bin/bin-util.d.ts +2 -0
- package/bin/index.cjs +2 -0
- package/bin/index.d.ts +2 -0
- package/bin/index.js +3 -0
- package/bin/logger.d.ts +2 -0
- package/bin/main.cjs +11 -0
- package/bin/main.d.ts +1 -0
- package/bin/main.js +260 -0
- package/bin/prettier.d.ts +1 -0
- package/compiler/get-files.d.ts +3 -0
- package/compiler/index.cjs +1 -11
- package/compiler/index.d.ts +4 -6
- package/compiler/index.js +16 -180
- package/config/config-types.d.ts +10 -4
- package/dash-case-DKzpenwY.cjs +1 -0
- package/dash-case-DMQMcCO6.js +19 -0
- package/generator/index.cjs +1 -1
- package/generator/index.js +30 -17
- package/generator/parse-templates.d.ts +2 -0
- package/generator/style-generator.d.ts +11 -4
- package/index-84Wroia-.cjs +1 -0
- package/index-BJOgd2yZ.js +253 -0
- package/index-BNP4ADSL.cjs +21 -0
- package/index-D_732b92.js +4 -0
- package/package.json +22 -5
- package/parse-templates-BNINfXOG.js +100 -0
- package/parse-templates-C1-wQz7G.cjs +8 -0
- package/pascal-case-BQpR5PdN.js +6 -0
- package/pascal-case-iWoaJWwT.cjs +1 -0
- package/react-styled-file-CGVf5n1B.js +11 -0
- package/react-styled-file-Dkubsz-U.cjs +8 -0
- package/react-vanilla-file-CCXbsjIb.js +18 -0
- package/react-vanilla-file-CG_WJLam.cjs +15 -0
- package/salty.config-BhBY_oOk.js +10 -0
- package/salty.config-Dk6ZcCxI.cjs +7 -0
- package/types/index.d.ts +35 -20
- package/util/camel-case.d.ts +1 -0
- package/util/index.cjs +1 -1
- package/util/index.d.ts +2 -0
- package/util/index.js +7 -15
- package/util/module-type.d.ts +1 -0
- package/util/pascal-case.d.ts +1 -0
- package/eslint/index.cjs +0 -1
- package/eslint/index.d.ts +0 -6
- package/eslint/index.js +0 -48
- package/eslint/rules/no-variants-in-base.d.ts +0 -2
- package/parse-templates-BOSK0Tb6.js +0 -90
- package/parse-templates-BY1Xai-_.cjs +0 -8
@@ -0,0 +1,21 @@
|
|
1
|
+
"use strict";const te=require("esbuild"),se=require("child_process"),N=require("./dash-case-DKzpenwY.cjs"),o=require("path"),a=require("fs"),H=require("fs/promises"),O=require("./parse-templates-C1-wQz7G.cjs"),M=require("winston");var q=typeof document<"u"?document.currentScript:null;function ne(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const s=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,s.get?s:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const U=ne(te),G=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=o.join(e,"package.json");return a.existsSync(t)?t:G(o.join(e,".."))},oe=async e=>{const t=G(e);return await H.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},ie=async e=>{const t=await oe(e);if(t)return t.type};let v;const L=async e=>{if(v)return v;const t=await ie(e);return t==="module"?v="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:q&&q.tagName.toUpperCase()==="SCRIPT"&&q.src||new URL("index-BNP4ADSL.cjs",document.baseURI).href).endsWith(".cjs"))&&(v="cjs"),v||"esm"},V=M.createLogger({level:"debug",format:M.format.combine(M.format.colorize(),M.format.cli()),transports:[new M.transports.Console({})]}),re=e=>{V.error(e)},I={externalModules:[]},W=e=>{if(I.externalModules.length>0)return I.externalModules;const t=o.join(e,"salty.config.ts"),s=a.readFileSync(t,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const i=s[1].split(",").map(p=>p.replace(/['"`]/g,"").trim());return I.externalModules=i,i},R=e=>o.join(e,"./saltygen"),K=["salty","css","styles","styled"],A=(e=[])=>new RegExp(`\\.(${[...K,...e].join("|")})\\.`),_=(e,t=[])=>A(t).test(e),ce=async e=>{const t=R(e),n=o.join(e,"salty.config.ts"),s=o.join(t,"salty.config.js"),i=await L(e),p=W(e);await U.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:s,format:i,external:p});const S=Date.now(),{config:f}=await import(`${s}?t=${S}`);return f},X=async e=>{const t=await ce(e),n=new Set,s=(l,u=[])=>l?Object.entries(l).flatMap(([g,d])=>{if(!d)return;if(typeof d=="object")return s(d,[...u,g]);const C=[...u,g].join(".");n.add(`"${C}"`);const h=[...u.map(N.dashCase),N.dashCase(g)].join("-"),{result:j}=O.parseValueTokens(d);return`--${h}: ${j};`}):[],i=l=>l?Object.entries(l).flatMap(([u,g])=>{const d=s(g);return u==="base"?d.join(""):`${u} { ${d.join("")} }`}):[],p=l=>l?Object.entries(l).flatMap(([u,g])=>Object.entries(g).flatMap(([d,C])=>{const h=s(C,[u]),j=`.${u}-${d}, [data-${u}="${d}"]`,T=h.join("");return`${j} { ${T} }`})):[],S=s(t.variables),f=i(t.responsiveVariables),b=p(t.conditionalVariables),r=R(e),P=o.join(r,"css/variables.css"),y=`:root { ${S.join("")} ${f.join("")} } ${b.join("")}`;a.writeFileSync(P,y);const w=o.join(r,"css/global.css"),F=O.parseStyles(t.global,"");a.writeFileSync(w,F);const c=o.join(r,"css/templates.css"),m=O.parseTemplates(t.templates),x=O.getTemplateTypes(t.templates);a.writeFileSync(c,m);const $=o.join(r,"types/css-tokens.d.ts"),D=`
|
2
|
+
// Variable types
|
3
|
+
type VariableTokens = ${[...n].join("|")};
|
4
|
+
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
5
|
+
|
6
|
+
// Template types
|
7
|
+
type TemplateTokens = {
|
8
|
+
${Object.entries(x).map(([l,u])=>`${l}?: ${u}`).join(`
|
9
|
+
`)}
|
10
|
+
}
|
11
|
+
`;a.writeFileSync($,D)},J=async(e,t,n)=>{const s=N.toHash(t),i=o.join(n,"./temp");a.existsSync(i)||a.mkdirSync(i);const p=o.parse(t);let S=a.readFileSync(t,"utf8");S=S.replace(/styled\([^"'`{,]+,/g,"styled('div',");const f=o.join(n,"js",s+".js"),b=W(e),r=await L(e);await U.build({stdin:{contents:S,sourcefile:p.base,resolveDir:p.dir,loader:"ts"},minify:!1,treeShaking:!0,bundle:!0,outfile:f,format:r,target:["node20"],keepNames:!0,external:b,packages:"external"});const P=Date.now();return await import(`${f}?t=${P}`)},z=async e=>{const t=R(e),n=o.join(t,"salty.config.js"),{config:s}=await import(n);return s},Y=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},ae=async(e,t=Y())=>{try{t?V.info("Generating CSS in production mode! 🔥"):V.info("Generating CSS in development mode! 🚀");const n=[],s=[],i=R(e),p=o.join(i,"index.css");(()=>{a.existsSync(i)&&se.execSync("rm -rf "+i),a.mkdirSync(i),a.mkdirSync(o.join(i,"css")),a.mkdirSync(o.join(i,"types"))})(),await X(e);const f=await z(e);async function b(c,m){const x=["node_modules","saltygen"],$=a.statSync(c);if($.isDirectory()){const k=a.readdirSync(c);if(x.some(l=>c.includes(l)))return;await Promise.all(k.map(l=>b(o.join(c,l),o.join(m,l))))}else if($.isFile()&&_(c)){const D=await J(e,c,i),l=[];Object.entries(D).forEach(([C,h])=>{if(h.isKeyframes&&h.css){const B=`${h.animationName}.css`,Q=`css/${B}`,ee=o.join(i,Q);n.push(B),a.writeFileSync(ee,h.css);return}if(!h.generator)return;const j=h.generator._withBuildContext({name:C,config:f,prod:t}),T=`${j.hash}-${j.priority}.css`;s[j.priority]||(s[j.priority]=[]),s[j.priority].push(T),l.push(T);const E=`css/${T}`,Z=o.join(i,E);a.writeFileSync(Z,j.css)});const u=l.map(C=>`@import url('./${C}');`).join(`
|
12
|
+
`),g=N.toHash(c,6),d=o.join(i,`css/${g}.css`);a.writeFileSync(d,u)}}await b(e,i);const r=n.map(c=>`@import url('./css/${c}');`).join(`
|
13
|
+
`);let F=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
14
|
+
|
15
|
+
${["variables.css","global.css","templates.css"].filter(c=>{try{return a.readFileSync(o.join(i,"css",c),"utf8").length>0}catch{return!1}}).map(c=>`@import url('./css/${c}');`).join(`
|
16
|
+
`)}
|
17
|
+
${r}`;if(f.importStrategy!=="component"){const c=s.flat().map(m=>`@import url('./css/${m}');`).join(`
|
18
|
+
`);F+=c}a.writeFileSync(p,F)}catch(n){console.error(n)}},le=async(e,t)=>{try{const n=[],s=o.join(e,"./saltygen"),i=o.join(s,"index.css");if(_(t)){const S=await z(e),f=await J(e,t,s);Object.entries(f).forEach(([w,F])=>{if(!F.generator)return;const c=F.generator._withBuildContext({name:w,config:S}),m=`${c.hash}-${c.priority}.css`,x=`css/${m}`,$=o.join(s,x);n.push(m),a.writeFileSync($,c.css)});const b=a.readFileSync(i,"utf8").split(`
|
19
|
+
`),r=n.map(w=>`@import url('../saltygen/css/${w}');`),y=[...new Set([...b,...r])].join(`
|
20
|
+
`);a.writeFileSync(i,y)}}catch(n){console.error(n)}},pe=async(e,t,n=Y())=>{try{const s=o.join(e,"./saltygen");if(_(t)){const p=a.readFileSync(t,"utf8");p.replace(/^(?!export\s)const\s.*/gm,y=>`export ${y}`)!==p&&await H.writeFile(t,p);const f=await z(e),b=await J(e,t,s);let r=p;Object.entries(b).forEach(([y,w])=>{var T;if(w.isKeyframes||!w.generator)return;const F=w.generator._withBuildContext({name:y,config:f,prod:n}),c=new RegExp(`\\s${y}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(p);if(!c)return console.error("Could not find the original declaration");const m=(T=c.at(1))==null?void 0:T.trim(),x=new RegExp(`\\s${y}[=\\s]+styled\\(`,"g").exec(r);if(!x)return console.error("Could not find the original declaration");const{index:$}=x;let k=!1;const D=setTimeout(()=>k=!0,5e3);let l=0,u=!1,g=0;for(;!u&&!k;){const E=r[$+l];E==="("&&g++,E===")"&&g--,g===0&&E===")"&&(u=!0),l>r.length&&(k=!0),l++}if(!k)clearTimeout(D);else throw new Error("Failed to find the end of the styled call and timed out");const d=$+l,C=r.slice($,d),h=r,j=` ${y} = styled(${m}, "${F.classNames}", ${JSON.stringify(F.props)});`;r=r.replace(C,j),h===r&&console.error("Minimize file failed to change content",{name:y,tagName:m})});const P=N.toHash(t,6);return f.importStrategy==="component"&&(r=`import '../../saltygen/css/${P}.css';
|
21
|
+
${r}`),r=r.replace("{ styled }","{ styledClient as styled }"),r=r.replace("@salty-css/react/styled","@salty-css/react/styled-client"),r}}catch(s){console.error("Error in minimizeFile:",s)}};exports.compileSaltyFile=J;exports.generateConfigStyles=X;exports.generateCss=ae;exports.generateFile=le;exports.isSaltyFile=_;exports.logError=re;exports.logger=V;exports.minimizeFile=pe;exports.saltyFileExtensions=K;exports.saltyFileRegExp=A;
|
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.111",
|
4
4
|
"main": "./dist/index.js",
|
5
5
|
"module": "./dist/index.mjs",
|
6
6
|
"typings": "./dist/index.d.ts",
|
@@ -10,7 +10,12 @@
|
|
10
10
|
"publishConfig": {
|
11
11
|
"access": "public"
|
12
12
|
},
|
13
|
-
"
|
13
|
+
"description": "Core library for Salty CSS. Will be used by other Salty CSS libraries and plugins.",
|
14
|
+
"homepage": "https://salty-css.dev/",
|
15
|
+
"repository": {
|
16
|
+
"type": "git",
|
17
|
+
"url": "git+https://github.com/margarita-form/salty-css.git"
|
18
|
+
},
|
14
19
|
"bugs": {
|
15
20
|
"url": "https://github.com/margarita-form/salty-css/issues"
|
16
21
|
},
|
@@ -23,12 +28,18 @@
|
|
23
28
|
"name": "core"
|
24
29
|
},
|
25
30
|
"peerDependencies": {
|
26
|
-
"
|
27
|
-
"
|
28
|
-
"
|
31
|
+
"commander": ">=12.x",
|
32
|
+
"ejs": ">=3.x",
|
33
|
+
"esbuild": ">=0.21.x",
|
34
|
+
"ora": ">=8.x",
|
35
|
+
"react": ">=18.x || >=19.x",
|
29
36
|
"winston": ">=3.x"
|
30
37
|
},
|
31
38
|
"exports": {
|
39
|
+
"./bin/main": {
|
40
|
+
"import": "./bin/main.js",
|
41
|
+
"require": "./bin/main.cjs"
|
42
|
+
},
|
32
43
|
"./compiler": {
|
33
44
|
"import": "./compiler/index.js",
|
34
45
|
"require": "./compiler/index.cjs"
|
@@ -53,5 +64,11 @@
|
|
53
64
|
"import": "./util/index.js",
|
54
65
|
"require": "./util/index.cjs"
|
55
66
|
}
|
67
|
+
},
|
68
|
+
"bin": {
|
69
|
+
"salty": "./bin/index.js",
|
70
|
+
"salty-css": "./bin/index.js",
|
71
|
+
"salty-css-cjs": "./bin/index.cjs",
|
72
|
+
"@salty-css/core": "./bin/index.js"
|
56
73
|
}
|
57
74
|
}
|
@@ -0,0 +1,100 @@
|
|
1
|
+
import { d as O } from "./dash-case-DMQMcCO6.js";
|
2
|
+
const N = (t, r) => {
|
3
|
+
if (typeof t != "string") return { result: t };
|
4
|
+
if (!r) return { result: t };
|
5
|
+
const s = [];
|
6
|
+
return Object.values(r).forEach((n) => {
|
7
|
+
const { pattern: o, transform: i } = n;
|
8
|
+
t = t.replace(o, (d) => {
|
9
|
+
const { value: c, css: j } = i(d);
|
10
|
+
return j && s.push(j), c;
|
11
|
+
});
|
12
|
+
}), { result: t, additionalCss: s };
|
13
|
+
}, P = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${O(n[1].replaceAll(".", "-"))})`) } : { result: t }, a = (t, r, s, n) => {
|
14
|
+
if (!t) return "";
|
15
|
+
const o = [], i = Object.entries(t).reduce((c, [j, e]) => {
|
16
|
+
const f = j.trim();
|
17
|
+
if (typeof e == "function" && (e = e()), typeof e == "object") {
|
18
|
+
if (!e) return c;
|
19
|
+
if (f === "variants")
|
20
|
+
return Object.entries(e).forEach(([p, u]) => {
|
21
|
+
u && Object.entries(u).forEach(([m, b]) => {
|
22
|
+
if (!b) return;
|
23
|
+
const y = `${r}.${p}-${m}`, l = a(b, y, s);
|
24
|
+
o.push(l);
|
25
|
+
});
|
26
|
+
}), c;
|
27
|
+
if (f === "defaultVariants")
|
28
|
+
return c;
|
29
|
+
if (f === "compoundVariants")
|
30
|
+
return e.forEach((p) => {
|
31
|
+
const { css: u, ...m } = p, b = Object.entries(m).reduce((l, [w, W]) => `${l}.${w}-${W}`, r), y = a(u, b, s);
|
32
|
+
o.push(y);
|
33
|
+
}), c;
|
34
|
+
if (f.startsWith("@")) {
|
35
|
+
const p = a(e, r, s), u = `${f} {
|
36
|
+
${p.replace(`
|
37
|
+
`, `
|
38
|
+
`)}
|
39
|
+
}`;
|
40
|
+
return o.push(u), c;
|
41
|
+
}
|
42
|
+
const $ = j.includes("&") ? f.replace("&", r) : f.startsWith(":") ? `${r}${f}` : `${r} ${f}`, h = a(e, $, s);
|
43
|
+
return o.push(h), c;
|
44
|
+
}
|
45
|
+
if (n != null && n.templates && n.templates[f]) {
|
46
|
+
const h = e.split(".").reduce((p, u) => p[u], n.templates[f]);
|
47
|
+
if (h) {
|
48
|
+
const p = a(h, "");
|
49
|
+
return `${c}${p}`;
|
50
|
+
}
|
51
|
+
return console.warn(`Template "${f}" with path of "${e}" was not found in config!`), c;
|
52
|
+
}
|
53
|
+
const S = f.startsWith("-") ? f : O(f), g = ($, h = ";") => c = `${c}${$}${h}`, T = ($) => g(`${S}:${$}`);
|
54
|
+
if (typeof e == "number") return T(e);
|
55
|
+
if (typeof e != "string")
|
56
|
+
if ("toString" in e) e = e.toString();
|
57
|
+
else return c;
|
58
|
+
const { modifiers: V } = n || {}, k = function* () {
|
59
|
+
yield P(e), yield N(e, V);
|
60
|
+
}();
|
61
|
+
for (const { result: $, additionalCss: h = [] } of k)
|
62
|
+
e = $, h.forEach((p) => {
|
63
|
+
const u = a(p, "");
|
64
|
+
g(u, "");
|
65
|
+
});
|
66
|
+
return T(e);
|
67
|
+
}, "");
|
68
|
+
if (!i) return o.join(`
|
69
|
+
`);
|
70
|
+
if (!r) return i;
|
71
|
+
let d = "";
|
72
|
+
return s !== void 0 ? d = `@layer l${s} { ${r} { ${i} } }` : d = `${r} { ${i} }`, [d, ...o].join(`
|
73
|
+
`);
|
74
|
+
}, _ = (t, r = []) => {
|
75
|
+
if (!t) return "";
|
76
|
+
const s = [], n = {};
|
77
|
+
if (Object.entries(t).forEach(([o, i]) => {
|
78
|
+
if (typeof i == "object") {
|
79
|
+
if (!i) return;
|
80
|
+
const d = o.trim(), c = _(i, [...r, d]);
|
81
|
+
s.push(c);
|
82
|
+
} else
|
83
|
+
n[o] = i;
|
84
|
+
}), Object.keys(n).length) {
|
85
|
+
const o = r.map(O).join("-"), i = a(n, `.${o}`);
|
86
|
+
s.push(i);
|
87
|
+
}
|
88
|
+
return s.join(`
|
89
|
+
`);
|
90
|
+
}, A = (t) => Object.keys(t), K = (t) => Object.entries(t).reduce((r, [s, n]) => (typeof n == "object" && (r[s] = E(n).map((o) => `"${o}"`).join(" | ")), r), {}), E = (t, r = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, o]) => {
|
91
|
+
const i = r ? `${r}.${n}` : n;
|
92
|
+
return typeof o == "object" ? E(o, i, s) : s.add(r);
|
93
|
+
}), [...s]) : [];
|
94
|
+
export {
|
95
|
+
_ as a,
|
96
|
+
K as b,
|
97
|
+
P as c,
|
98
|
+
A as g,
|
99
|
+
a as p
|
100
|
+
};
|
@@ -0,0 +1,8 @@
|
|
1
|
+
"use strict";const T=require("./dash-case-DKzpenwY.cjs"),N=(t,e)=>{if(typeof t!="string")return{result:t};if(!e)return{result:t};const r=[];return Object.values(e).forEach(n=>{const{pattern:o,transform:i}=n;t=t.replace(o,d=>{const{value:c,css:j}=i(d);return j&&r.push(j),c})}),{result:t,additionalCss:r}},S=t=>typeof t!="string"?{result:t}:/\{[^{}]+\}/g.test(t)?{result:t.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${T.dashCase(n[1].replaceAll(".","-"))})`)}:{result:t},a=(t,e,r,n)=>{if(!t)return"";const o=[],i=Object.entries(t).reduce((c,[j,s])=>{const p=j.trim();if(typeof s=="function"&&(s=s()),typeof s=="object"){if(!s)return c;if(p==="variants")return Object.entries(s).forEach(([f,u])=>{u&&Object.entries(u).forEach(([l,m])=>{if(!m)return;const y=`${e}.${f}-${l}`,b=a(m,y,r);o.push(b)})}),c;if(p==="defaultVariants")return c;if(p==="compoundVariants")return s.forEach(f=>{const{css:u,...l}=f,m=Object.entries(l).reduce((b,[q,K])=>`${b}.${q}-${K}`,e),y=a(u,m,r);o.push(y)}),c;if(p.startsWith("@")){const f=a(s,e,r),u=`${p} {
|
2
|
+
${f.replace(`
|
3
|
+
`,`
|
4
|
+
`)}
|
5
|
+
}`;return o.push(u),c}const $=j.includes("&")?p.replace("&",e):p.startsWith(":")?`${e}${p}`:`${e} ${p}`,h=a(s,$,r);return o.push(h),c}if(n!=null&&n.templates&&n.templates[p]){const h=s.split(".").reduce((f,u)=>f[u],n.templates[p]);if(h){const f=a(h,"");return`${c}${f}`}return console.warn(`Template "${p}" with path of "${s}" was not found in config!`),c}const k=p.startsWith("-")?p:T.dashCase(p),O=($,h=";")=>c=`${c}${$}${h}`,g=$=>O(`${k}:${$}`);if(typeof s=="number")return g(s);if(typeof s!="string")if("toString"in s)s=s.toString();else return c;const{modifiers:w}=n||{},W=function*(){yield S(s),yield N(s,w)}();for(const{result:$,additionalCss:h=[]}of W)s=$,h.forEach(f=>{const u=a(f,"");O(u,"")});return g(s)},"");if(!i)return o.join(`
|
6
|
+
`);if(!e)return i;let d="";return r!==void 0?d=`@layer l${r} { ${e} { ${i} } }`:d=`${e} { ${i} }`,[d,...o].join(`
|
7
|
+
`)},E=(t,e=[])=>{if(!t)return"";const r=[],n={};if(Object.entries(t).forEach(([o,i])=>{if(typeof i=="object"){if(!i)return;const d=o.trim(),c=E(i,[...e,d]);r.push(c)}else n[o]=i}),Object.keys(n).length){const o=e.map(T.dashCase).join("-"),i=a(n,`.${o}`);r.push(i)}return r.join(`
|
8
|
+
`)},P=t=>Object.keys(t),_=t=>Object.entries(t).reduce((e,[r,n])=>(typeof n=="object"&&(e[r]=V(n).map(o=>`"${o}"`).join(" | ")),e),{}),V=(t,e="",r=new Set)=>t?(Object.entries(t).forEach(([n,o])=>{const i=e?`${e}.${n}`:n;return typeof o=="object"?V(o,i,r):r.add(e)}),[...r]):[];exports.getTemplateKeys=P;exports.getTemplateTypes=_;exports.parseStyles=a;exports.parseTemplates=E;exports.parseValueTokens=S;
|
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";function r(e){return e?typeof e!="string"?r(String(e)):e.replace(/\s/g,"-").replace(/[-_]([a-z0-9])/g,a=>a[1].toUpperCase()).replace(/^[a-z]/,a=>a.toUpperCase()):""}exports.pascalCase=r;
|
@@ -0,0 +1,8 @@
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=`import { styled } from "@salty-css/react/styled";
|
2
|
+
|
3
|
+
export const <%- name %> = styled('<%- tag %>', {
|
4
|
+
<% if(className) { %>className: '<%- className %>',<% } %>
|
5
|
+
base: {
|
6
|
+
// Add your styles here
|
7
|
+
}
|
8
|
+
})`;exports.default=e;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
const n = `import { <%- styledComponentName %> } from "./<%- fileName %>.css";
|
2
|
+
|
3
|
+
interface <%- componentName %>Props {
|
4
|
+
text?: string;
|
5
|
+
}
|
6
|
+
|
7
|
+
export const <%- componentName %> = ({ text = 'Lorem ipsum' }: <%- componentName %>Props) => {
|
8
|
+
return (
|
9
|
+
<<%- styledComponentName %>>
|
10
|
+
{text}
|
11
|
+
</<%- styledComponentName %>>
|
12
|
+
);
|
13
|
+
};
|
14
|
+
|
15
|
+
export default <%- componentName %>;`;
|
16
|
+
export {
|
17
|
+
n as default
|
18
|
+
};
|
@@ -0,0 +1,15 @@
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=`import { <%- styledComponentName %> } from "./<%- fileName %>.css";
|
2
|
+
|
3
|
+
interface <%- componentName %>Props {
|
4
|
+
text?: string;
|
5
|
+
}
|
6
|
+
|
7
|
+
export const <%- componentName %> = ({ text = 'Lorem ipsum' }: <%- componentName %>Props) => {
|
8
|
+
return (
|
9
|
+
<<%- styledComponentName %>>
|
10
|
+
{text}
|
11
|
+
</<%- styledComponentName %>>
|
12
|
+
);
|
13
|
+
};
|
14
|
+
|
15
|
+
export default <%- componentName %>;`;exports.default=e;
|
@@ -0,0 +1,7 @@
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=`import { defineConfig } from '@salty-css/core/config';
|
2
|
+
|
3
|
+
export const config = defineConfig({
|
4
|
+
// Add your custom config here
|
5
|
+
externalModules: ['react', 'react-dom']
|
6
|
+
});
|
7
|
+
`;exports.default=e;
|
package/types/index.d.ts
CHANGED
@@ -1,32 +1,39 @@
|
|
1
|
-
import {
|
1
|
+
import { ReactNode } from 'react';
|
2
2
|
import { StyleComponentGenerator } from '../generator';
|
3
|
-
import { OrString } from './util-types';
|
3
|
+
import { OrAny, OrString } from './util-types';
|
4
|
+
import type * as CSS from 'csstype';
|
4
5
|
export type CreateElementProps = {
|
5
6
|
extend?: Tag<any>;
|
6
7
|
children?: ReactNode;
|
7
8
|
className?: string;
|
8
9
|
element?: string;
|
9
|
-
passVariantProps?: boolean;
|
10
|
-
style?:
|
10
|
+
passVariantProps?: boolean | string | string[];
|
11
|
+
style?: CssProperties & {
|
12
|
+
[key: string]: OrAny | PropertyValueToken;
|
13
|
+
};
|
11
14
|
/** vks = Variant key set */
|
12
15
|
_vks?: Set<string>;
|
13
16
|
};
|
14
|
-
export type StyledComponentProps = Record<string, unknown> & CreateElementProps
|
17
|
+
export type StyledComponentProps = Record<string, unknown> & CreateElementProps;
|
15
18
|
type FnComponent<PROPS extends StyledComponentProps> = {
|
16
|
-
(props: PROPS): ReactNode;
|
19
|
+
(props: OrAny | PROPS): ReactNode;
|
17
20
|
generator?: StyleComponentGenerator;
|
18
21
|
};
|
19
|
-
export type Tag<PROPS extends StyledComponentProps> = OrString | keyof
|
20
|
-
|
21
|
-
|
22
|
-
|
22
|
+
export type Tag<PROPS extends StyledComponentProps> = OrString | keyof HTMLElementTagNameMap | FnComponent<PROPS>;
|
23
|
+
type CSSPropertyValueFunction = (params?: any) => any;
|
24
|
+
type CssProperties = {
|
25
|
+
[key in keyof CSS.Properties]: CSS.Properties[key] | PropertyValueToken | CSSPropertyValueFunction;
|
23
26
|
};
|
24
|
-
type
|
25
|
-
type
|
26
|
-
|
27
|
+
type CssPropertyKeys = keyof CssProperties;
|
28
|
+
export type StyleValue<K extends string> = K extends CssPropertyKeys ? CssProperties[K] : never;
|
29
|
+
type InvalidVariantKeys = '';
|
27
30
|
type VariantOptions = {
|
28
31
|
[key in InvalidVariantKeys]?: never;
|
29
32
|
};
|
33
|
+
export type CompoundVariant = {
|
34
|
+
[key: PropertyKey]: any;
|
35
|
+
css: CssStyles;
|
36
|
+
};
|
30
37
|
type Variants = {
|
31
38
|
variants?: VariantOptions & {
|
32
39
|
[key: PropertyKey]: {
|
@@ -38,17 +45,19 @@ type Variants = {
|
|
38
45
|
};
|
39
46
|
compoundVariants?: CompoundVariant[];
|
40
47
|
};
|
41
|
-
type
|
42
|
-
|
48
|
+
type BooleanVariantValue = 'true' | 'false' | boolean;
|
49
|
+
type VariantPropValue<T> = T extends 'true' ? BooleanVariantValue : T extends 'false' ? BooleanVariantValue : T;
|
50
|
+
export type VariantProps<STYLES extends StyledParams> = STYLES['variants'] extends undefined ? object : {
|
43
51
|
[K in keyof STYLES['variants']]?: VariantPropValue<keyof STYLES['variants'][K]> | '';
|
44
52
|
};
|
45
|
-
|
46
|
-
export type
|
47
|
-
|
53
|
+
type CssValuePropKey = `props-${string}`;
|
54
|
+
export type ValueProps = {
|
55
|
+
[key: CssValuePropKey]: string;
|
48
56
|
};
|
57
|
+
export type ParentComponentProps<TAG extends Tag<any>> = TAG extends (props: infer P) => ReactNode ? P : object;
|
49
58
|
type StylePropertyValue = Record<never, never> & unknown;
|
50
59
|
export type CssStyles = {
|
51
|
-
[key in
|
60
|
+
[key in OrString]?: CssProperties | StylePropertyValue | PropertyValueToken | TemplateTokens | CssStyles;
|
52
61
|
};
|
53
62
|
export type Styles = CssStyles & Variants;
|
54
63
|
export interface GeneratorOptions {
|
@@ -56,7 +65,13 @@ export interface GeneratorOptions {
|
|
56
65
|
displayName?: string;
|
57
66
|
element?: string;
|
58
67
|
}
|
68
|
+
interface Base extends CssProperties, CssStyles, CssPseudos, TemplateTokens {
|
69
|
+
}
|
70
|
+
type Pseudos = CSS.Pseudos | `&${CSS.Pseudos}`;
|
71
|
+
type CssPseudos = {
|
72
|
+
[P in Pseudos]?: Base;
|
73
|
+
};
|
59
74
|
export interface StyledParams extends GeneratorOptions, Variants {
|
60
|
-
base?:
|
75
|
+
base?: Base;
|
61
76
|
}
|
62
77
|
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function camelCase(str: PropertyKey): string;
|
package/util/index.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../dash-case-DKzpenwY.cjs"),t=require("../pascal-case-iWoaJWwT.cjs");function s(e){return e?typeof e!="string"?s(String(e)):e.replace(/\s/g,"-").replace(/-([a-z])/g,r=>r[1].toUpperCase()):""}exports.dashCase=a.dashCase;exports.toHash=a.toHash;exports.pascalCase=t.pascalCase;exports.camelCase=s;
|
package/util/index.d.ts
CHANGED
package/util/index.js
CHANGED
@@ -1,19 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
return
|
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()) : "";
|
1
|
+
import { d as o, t as s } from "../dash-case-DMQMcCO6.js";
|
2
|
+
import { p as f } from "../pascal-case-BQpR5PdN.js";
|
3
|
+
function r(e) {
|
4
|
+
return e ? typeof e != "string" ? r(String(e)) : e.replace(/\s/g, "-").replace(/-([a-z])/g, (a) => a[1].toUpperCase()) : "";
|
15
5
|
}
|
16
6
|
export {
|
17
|
-
|
7
|
+
r as camelCase,
|
8
|
+
o as dashCase,
|
9
|
+
f as pascalCase,
|
18
10
|
s as toHash
|
19
11
|
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const detectCurrentModuleType: (dirname: string) => Promise<"esm" | "cjs">;
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function pascalCase(str: PropertyKey): string;
|
package/eslint/index.cjs
DELETED
@@ -1 +0,0 @@
|
|
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.d.ts
DELETED
package/eslint/index.js
DELETED
@@ -1,48 +0,0 @@
|
|
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
|
-
};
|
@@ -1,90 +0,0 @@
|
|
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
|
-
};
|
@@ -1,8 +0,0 @@
|
|
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;
|