@salty-css/core 0.0.1-alpha.13 → 0.0.1-alpha.14
Sign up to get free protection for your applications and to get access to all the features.
- package/compiler/index.cjs +5 -5
- package/compiler/index.js +75 -77
- package/generator/index.cjs +1 -1
- package/generator/index.js +20 -16
- package/generator/style-generator.d.ts +6 -4
- package/package.json +1 -1
- package/types/index.d.ts +6 -5
package/compiler/index.cjs
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const K=require("esbuild"),
|
2
|
-
`),
|
3
|
-
`);let
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const K=require("esbuild"),G=require("winston"),J=require("child_process"),k=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),P=q(G),A=P.createLogger({level:"info",format:P.format.combine(P.format.colorize(),P.format.cli()),transports:[new P.transports.Console({})]}),O=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=O(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:S}=await import(`${e}?t=${a}`);return S},H=async t=>{const s=await U(t),n=new Set,e=(d,p=[])=>d?Object.entries(d).flatMap(([y,c])=>{if(!c)return;if(typeof c=="object")return e(c,[...p,y]);const x=[...p,y].join(".");n.add(`"${x}"`);const C=[...p.map(k.dashCase),k.dashCase(y)].join("-"),{result:D}=_.parseValueTokens(c);return`--${C}: ${D};`}):[],a=d=>d?Object.entries(d).flatMap(([p,y])=>{const c=e(y);return p==="base"?c.join(""):`${p} { ${c.join("")} }`}):[],S=d=>d?Object.entries(d).flatMap(([p,y])=>Object.entries(y).flatMap(([c,x])=>{const C=e(x,[p]),D=`.${p}-${c}, [data-${p}="${c}"]`,N=C.join("");return`${D} { ${N} }`})):[],b=e(s.variables),w=a(s.responsiveVariables),l=S(s.conditionalVariables),j=O(t),f=o.join(j,"css/variables.css"),i=`:root { ${b.join("")} ${w.join("")} } ${l.join("")}`;r.writeFileSync(f,i);const g=o.join(j,"types/css-tokens.d.ts"),m=`type VariableTokens = ${[...n].join("|")}; type PropertyValueToken = \`{\${VariableTokens}}\``;r.writeFileSync(g,m);const u=o.join(j,"css/global.css"),h=_.parseStyles(s.global,"");r.writeFileSync(u,h);const F=o.join(j,"css/templates.css"),v=_.parseTemplates(s.templates);r.writeFileSync(F,v)},V=async(t,s)=>{const n=k.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=O(t),n=o.join(s,"salty-config.js"),{config:e}=await import(n);return e},W=async t=>{try{const s=[],n=[],e=O(t),a=o.join(e,"index.css");(()=>{r.existsSync(e)&&J.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 m=r.readdirSync(i);await Promise.all(m.map(u=>w(o.join(i,u),o.join(g,u))))}else if($.isFile()&&T(i)){const u=await V(i,e),h=[];Object.entries(u).forEach(([p,y])=>{if(y.isKeyframes&&y.css){const N=`${y.animationName}.css`,I=`css/${N}`,B=o.join(e,I);s.push(N),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),h.push(x);const C=`css/${x}`,D=o.join(e,C);r.writeFileSync(D,c.css)});const F=h.map(p=>`@import url('./${p}');`).join(`
|
2
|
+
`),v=k.toHash(i,6),d=o.join(e,`css/${v}.css`);r.writeFileSync(d,F)}}await w(t,e);const l=s.map(i=>`@import url('./css/${i}');`).join(`
|
3
|
+
`);let f=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
4
4
|
|
5
5
|
${["@import url('./css/variables.css');","@import url('./css/global.css');","@import url('./css/templates.css');"].join(`
|
6
6
|
`)}
|
7
7
|
${l}`;if(b.importStrategy!=="component"){const i=n.flat().map(g=>`@import url('./css/${g}');`).join(`
|
8
|
-
`);
|
8
|
+
`);f+=i}r.writeFileSync(a,f)}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 m=$.generator._withBuildContext({name:g,config:b}),u=`${m.hash}-${m.priority}.css`,h=`css/${u}`,F=o.join(e,h);n.push(u),r.writeFileSync(F,m.css)});const l=r.readFileSync(a,"utf8").split(`
|
9
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)){
|
10
|
+
`);r.writeFileSync(a,i)}}catch(n){console.error(n)}},Y=async(t,s)=>{try{const n=o.join(t,"./saltygen");if(T(s)){const a=r.readFileSync(s,"utf8");a.replace(/^(?!export\s)const\s.*/gm,f=>`export ${f}`)!==a&&await L.writeFile(s,a);const b=await E(t),w=await V(s,n);let l=a;Object.entries(w).forEach(([f,i])=>{var F;if(i.isKeyframes){console.log("value",i);return}if(!i.generator)return;const g=i.generator._withBuildContext({name:f,config:b}),$=new RegExp(`${f}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(a);if(!$)return console.error("Could not find the original declaration");const m=(F=$.at(1))==null?void 0:F.trim(),u=`${f} = styled(${m}, "${g.classNames}", "${g._callerName}", ${JSON.stringify(g.props)});`,h=new RegExp(`${f}[=\\s]+[^()]+styled\\(([^,]+),[^;]+;`,"g");l=l.replace(h,u)});const j=k.toHash(s,6);return b.importStrategy==="component"&&(l=`import '../../saltygen/css/${j}.css';
|
11
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;
|
package/compiler/index.js
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
import * as M from "esbuild";
|
2
|
-
import * as
|
3
|
-
import { execSync as
|
2
|
+
import * as P from "winston";
|
3
|
+
import { execSync as H } from "child_process";
|
4
4
|
import { toHash as T, dashCase as I } from "../util/index.js";
|
5
|
-
import { join as
|
6
|
-
import { writeFileSync as $, existsSync as
|
5
|
+
import { join as n } from "path";
|
6
|
+
import { writeFileSync as $, existsSync as K, mkdirSync as v, statSync as G, readdirSync as J, readFileSync as _ } from "fs";
|
7
7
|
import { writeFile as L } from "fs/promises";
|
8
8
|
import { p as q, a as A, b as U } from "../parse-templates-BOSK0Tb6.js";
|
9
|
-
const rt =
|
9
|
+
const rt = P.createLogger({
|
10
10
|
level: "info",
|
11
|
-
format:
|
12
|
-
transports: [new
|
13
|
-
}),
|
14
|
-
const e =
|
11
|
+
format: P.format.combine(P.format.colorize(), P.format.cli()),
|
12
|
+
transports: [new P.transports.Console({})]
|
13
|
+
}), V = (s) => n(s, "./saltygen"), W = ["salty", "css", "styles", "styled"], X = (s = []) => new RegExp(`\\.(${[...W, ...s].join("|")})\\.`), E = (s, e = []) => X(e).test(s), Y = async (s) => {
|
14
|
+
const e = V(s), o = n(s, "salty-config.ts"), t = n(e, "salty-config.js");
|
15
15
|
await M.build({
|
16
|
-
entryPoints: [
|
16
|
+
entryPoints: [o],
|
17
17
|
minify: !0,
|
18
18
|
treeShaking: !0,
|
19
19
|
bundle: !0,
|
@@ -21,32 +21,32 @@ const rt = N.createLogger({
|
|
21
21
|
format: "esm",
|
22
22
|
external: ["react"]
|
23
23
|
});
|
24
|
-
const c = Date.now(), { config:
|
25
|
-
return
|
24
|
+
const c = Date.now(), { config: S } = await import(`${t}?t=${c}`);
|
25
|
+
return S;
|
26
26
|
}, Z = async (s) => {
|
27
|
-
const e = await Y(s),
|
27
|
+
const e = await Y(s), o = /* @__PURE__ */ new Set(), t = (u, l = []) => u ? Object.entries(u).flatMap(([p, i]) => {
|
28
28
|
if (!i) return;
|
29
29
|
if (typeof i == "object") return t(i, [...l, p]);
|
30
30
|
const x = [...l, p].join(".");
|
31
|
-
|
32
|
-
const
|
33
|
-
return `--${
|
34
|
-
}) : [], c = (
|
31
|
+
o.add(`"${x}"`);
|
32
|
+
const C = [...l.map(I), I(p)].join("-"), { result: D } = U(i);
|
33
|
+
return `--${C}: ${D};`;
|
34
|
+
}) : [], c = (u) => u ? Object.entries(u).flatMap(([l, p]) => {
|
35
35
|
const i = t(p);
|
36
36
|
return l === "base" ? i.join("") : `${l} { ${i.join("")} }`;
|
37
|
-
}) : [],
|
38
|
-
const
|
39
|
-
return `${
|
40
|
-
})) : [], d = t(e.variables), w = c(e.responsiveVariables), a =
|
41
|
-
$(
|
42
|
-
const f =
|
43
|
-
$(f,
|
44
|
-
const
|
45
|
-
$(
|
46
|
-
const
|
47
|
-
$(
|
48
|
-
},
|
49
|
-
const
|
37
|
+
}) : [], S = (u) => u ? Object.entries(u).flatMap(([l, p]) => Object.entries(p).flatMap(([i, x]) => {
|
38
|
+
const C = t(x, [l]), D = `.${l}-${i}, [data-${l}="${i}"]`, N = C.join("");
|
39
|
+
return `${D} { ${N} }`;
|
40
|
+
})) : [], d = t(e.variables), w = c(e.responsiveVariables), a = S(e.conditionalVariables), b = V(s), m = n(b, "css/variables.css"), r = `:root { ${d.join("")} ${w.join("")} } ${a.join("")}`;
|
41
|
+
$(m, r);
|
42
|
+
const f = n(b, "types/css-tokens.d.ts"), g = `type VariableTokens = ${[...o].join("|")}; type PropertyValueToken = \`{\${VariableTokens}}\``;
|
43
|
+
$(f, g);
|
44
|
+
const y = n(b, "css/global.css"), F = q(e.global, "");
|
45
|
+
$(y, F);
|
46
|
+
const j = n(b, "css/templates.css"), k = A(e.templates);
|
47
|
+
$(j, k);
|
48
|
+
}, O = async (s, e) => {
|
49
|
+
const o = T(s), t = n(e, "js", o + ".js");
|
50
50
|
await M.build({
|
51
51
|
entryPoints: [s],
|
52
52
|
minify: !0,
|
@@ -61,26 +61,26 @@ const rt = N.createLogger({
|
|
61
61
|
const c = Date.now();
|
62
62
|
return await import(`${t}?t=${c}`);
|
63
63
|
}, R = async (s) => {
|
64
|
-
const e =
|
64
|
+
const e = V(s), o = n(e, "salty-config.js"), { config: t } = await import(o);
|
65
65
|
return t;
|
66
66
|
}, it = async (s) => {
|
67
67
|
try {
|
68
|
-
const e = [],
|
68
|
+
const e = [], o = [], t = V(s), c = n(t, "index.css");
|
69
69
|
(() => {
|
70
|
-
|
70
|
+
K(t) && H("rm -rf " + t), v(t), v(n(t, "css")), v(n(t, "types"));
|
71
71
|
})(), await Z(s);
|
72
72
|
const d = await R(s);
|
73
73
|
async function w(r, f) {
|
74
|
-
const h =
|
74
|
+
const h = G(r);
|
75
75
|
if (h.isDirectory()) {
|
76
|
-
const
|
77
|
-
await Promise.all(
|
78
|
-
} else if (h.isFile() &&
|
79
|
-
const
|
80
|
-
Object.entries(
|
76
|
+
const g = J(r);
|
77
|
+
await Promise.all(g.map((y) => w(n(r, y), n(f, y))));
|
78
|
+
} else if (h.isFile() && E(r)) {
|
79
|
+
const y = await O(r, t), F = [];
|
80
|
+
Object.entries(y).forEach(([l, p]) => {
|
81
81
|
if (p.isKeyframes && p.css) {
|
82
|
-
const
|
83
|
-
e.push(
|
82
|
+
const N = `${p.animationName}.css`, B = `css/${N}`, z = n(t, B);
|
83
|
+
e.push(N), $(z, p.css);
|
84
84
|
return;
|
85
85
|
}
|
86
86
|
if (!p.generator) return;
|
@@ -88,93 +88,91 @@ const rt = N.createLogger({
|
|
88
88
|
name: l,
|
89
89
|
config: d
|
90
90
|
}), x = `${i.hash}-${i.priority}.css`;
|
91
|
-
|
92
|
-
const
|
93
|
-
$(
|
91
|
+
o[i.priority] || (o[i.priority] = []), o[i.priority].push(x), F.push(x);
|
92
|
+
const C = `css/${x}`, D = n(t, C);
|
93
|
+
$(D, i.css);
|
94
94
|
});
|
95
|
-
const
|
96
|
-
`),
|
97
|
-
$(
|
95
|
+
const j = F.map((l) => `@import url('./${l}');`).join(`
|
96
|
+
`), k = T(r, 6), u = n(t, `css/${k}.css`);
|
97
|
+
$(u, j);
|
98
98
|
}
|
99
99
|
}
|
100
100
|
await w(s, t);
|
101
101
|
const a = e.map((r) => `@import url('./css/${r}');`).join(`
|
102
102
|
`);
|
103
|
-
let
|
103
|
+
let m = `@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
104
104
|
|
105
105
|
${["@import url('./css/variables.css');", "@import url('./css/global.css');", "@import url('./css/templates.css');"].join(`
|
106
106
|
`)}
|
107
107
|
${a}`;
|
108
108
|
if (d.importStrategy !== "component") {
|
109
|
-
const r =
|
109
|
+
const r = o.flat().map((f) => `@import url('./css/${f}');`).join(`
|
110
110
|
`);
|
111
|
-
|
111
|
+
m += r;
|
112
112
|
}
|
113
|
-
$(c,
|
113
|
+
$(c, m);
|
114
114
|
} catch (e) {
|
115
115
|
console.error(e);
|
116
116
|
}
|
117
117
|
}, ct = async (s, e) => {
|
118
118
|
try {
|
119
|
-
const
|
120
|
-
if (
|
121
|
-
const d = await R(s), w = await
|
119
|
+
const o = [], t = n(s, "./saltygen"), c = n(t, "index.css");
|
120
|
+
if (E(e)) {
|
121
|
+
const d = await R(s), w = await O(e, t);
|
122
122
|
Object.entries(w).forEach(([f, h]) => {
|
123
123
|
if (!h.generator) return;
|
124
|
-
const
|
124
|
+
const g = h.generator._withBuildContext({
|
125
125
|
name: f,
|
126
126
|
config: d
|
127
|
-
}),
|
128
|
-
|
127
|
+
}), y = `${g.hash}-${g.priority}.css`, F = `css/${y}`, j = n(t, F);
|
128
|
+
o.push(y), $(j, g.css);
|
129
129
|
});
|
130
130
|
const a = _(c, "utf8").split(`
|
131
|
-
`), b =
|
131
|
+
`), b = o.map((f) => `@import url('../saltygen/css/${f}');`), r = [.../* @__PURE__ */ new Set([...a, ...b])].join(`
|
132
132
|
`);
|
133
133
|
$(c, r);
|
134
134
|
}
|
135
|
-
} catch (
|
136
|
-
console.error(
|
135
|
+
} catch (o) {
|
136
|
+
console.error(o);
|
137
137
|
}
|
138
138
|
}, at = async (s, e) => {
|
139
139
|
try {
|
140
|
-
const
|
141
|
-
if (
|
142
|
-
|
143
|
-
c.replace(/^(?!export\s)const\s.*/gm, (
|
144
|
-
const d = await R(s), w = await
|
140
|
+
const o = n(s, "./saltygen");
|
141
|
+
if (E(e)) {
|
142
|
+
const c = _(e, "utf8");
|
143
|
+
c.replace(/^(?!export\s)const\s.*/gm, (m) => `export ${m}`) !== c && await L(e, c);
|
144
|
+
const d = await R(s), w = await O(e, o);
|
145
145
|
let a = c;
|
146
|
-
Object.entries(w).forEach(([
|
147
|
-
var
|
146
|
+
Object.entries(w).forEach(([m, r]) => {
|
147
|
+
var j;
|
148
148
|
if (r.isKeyframes) {
|
149
149
|
console.log("value", r);
|
150
150
|
return;
|
151
151
|
}
|
152
152
|
if (!r.generator) return;
|
153
153
|
const f = r.generator._withBuildContext({
|
154
|
-
name:
|
154
|
+
name: m,
|
155
155
|
config: d
|
156
|
-
}), h = new RegExp(`${
|
156
|
+
}), h = new RegExp(`${m}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(c);
|
157
157
|
if (!h)
|
158
158
|
return console.error("Could not find the original declaration");
|
159
|
-
const
|
160
|
-
|
161
|
-
)});`, C = new RegExp(`${y}[=\\s]+[^()]+styled\\(([^,]+),[^;]+;`, "g");
|
162
|
-
a = a.replace(C, S);
|
159
|
+
const g = (j = h.at(1)) == null ? void 0 : j.trim(), y = `${m} = styled(${g}, "${f.classNames}", "${f._callerName}", ${JSON.stringify(f.props)});`, F = new RegExp(`${m}[=\\s]+[^()]+styled\\(([^,]+),[^;]+;`, "g");
|
160
|
+
a = a.replace(F, y);
|
163
161
|
});
|
164
162
|
const b = T(e, 6);
|
165
163
|
return d.importStrategy === "component" && (a = `import '../../saltygen/css/${b}.css';
|
166
164
|
${a}`), a = a.replace("{ styled }", "{ styledClient as styled }"), a = a.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), a;
|
167
165
|
}
|
168
|
-
} catch (
|
169
|
-
console.error(
|
166
|
+
} catch (o) {
|
167
|
+
console.error(o);
|
170
168
|
}
|
171
169
|
};
|
172
170
|
export {
|
173
|
-
|
171
|
+
O as compileSaltyFile,
|
174
172
|
it as generateCss,
|
175
173
|
ct as generateFile,
|
176
174
|
Z as generateVariables,
|
177
|
-
|
175
|
+
E as isSaltyFile,
|
178
176
|
rt as logger,
|
179
177
|
at as minimizeFile,
|
180
178
|
W as saltyFileExtensions,
|
package/generator/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 p=require("../util/index.cjs"),c=require("../parse-templates-BY1Xai-_.cjs");class h{constructor(t,s){this.tagName=t,this.params=s}get hash(){return p.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?c.getTemplateKeys(this._context.config.templates):[]}get css(){var e;const{base:t={},variants:s={},compoundVariants:a=[]}=this.params,r={...t,variants:s,compoundVariants:a};return c.parseStyles(r,`.${this.cssClassName}`,this.priority,(e=this._context)==null?void 0:e.config)}get props(){const{element:t}=this.params,s=this.params.variants?Object.keys(this.params.variants).map(e=>{var i;const n=(i=this.params.defaultVariants)==null?void 0:i[e];return n!==void 0?`${e}=${String(n)}`:e}):void 0,a=new Set([]),r=/\{props\.([\w\d]+)\}/gi.exec(JSON.stringify(this.params.base));return r&&r.forEach((e,n,i)=>{const o=i.at(1);o&&a.add(o)}),{element:t,variantKeys:s,propValueKeys:[...a]}}_withBuildContext(t){this._context=t;const{name:s,config:a}=t;return this._callerName=s,this}}exports.StyleComponentGenerator=h;
|
package/generator/index.js
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
import { toHash as
|
2
|
-
import { g as
|
3
|
-
class
|
1
|
+
import { toHash as p } from "../util/index.js";
|
2
|
+
import { g as c, p as h } from "../parse-templates-BOSK0Tb6.js";
|
3
|
+
class u {
|
4
4
|
constructor(t, s) {
|
5
5
|
this.tagName = t, this.params = s;
|
6
6
|
}
|
7
7
|
get hash() {
|
8
|
-
return
|
8
|
+
return p(this.params.base || this.params);
|
9
9
|
}
|
10
10
|
get priority() {
|
11
11
|
var t;
|
@@ -23,30 +23,34 @@ class p {
|
|
23
23
|
}
|
24
24
|
get templateKeys() {
|
25
25
|
var t;
|
26
|
-
return (t = this._context) != null && t.config.templates ?
|
26
|
+
return (t = this._context) != null && t.config.templates ? c(this._context.config.templates) : [];
|
27
27
|
}
|
28
28
|
get css() {
|
29
|
-
var
|
30
|
-
const { base: t = {}, variants: s = {}, compoundVariants:
|
31
|
-
return
|
29
|
+
var a;
|
30
|
+
const { base: t = {}, variants: s = {}, compoundVariants: e = [] } = this.params, r = { ...t, variants: s, compoundVariants: e };
|
31
|
+
return h(r, `.${this.cssClassName}`, this.priority, (a = this._context) == null ? void 0 : a.config);
|
32
32
|
}
|
33
33
|
get props() {
|
34
34
|
const { element: t } = this.params, s = this.params.variants ? Object.keys(this.params.variants).map((a) => {
|
35
|
-
var
|
36
|
-
const
|
37
|
-
return
|
38
|
-
}) : void 0;
|
39
|
-
return {
|
35
|
+
var i;
|
36
|
+
const n = (i = this.params.defaultVariants) == null ? void 0 : i[a];
|
37
|
+
return n !== void 0 ? `${a}=${String(n)}` : a;
|
38
|
+
}) : void 0, e = /* @__PURE__ */ new Set([]), r = /\{props\.([\w\d]+)\}/gi.exec(JSON.stringify(this.params.base));
|
39
|
+
return r && r.forEach((a, n, i) => {
|
40
|
+
const o = i.at(1);
|
41
|
+
o && e.add(o);
|
42
|
+
}), {
|
40
43
|
element: t,
|
41
|
-
variantKeys: s
|
44
|
+
variantKeys: s,
|
45
|
+
propValueKeys: [...e]
|
42
46
|
};
|
43
47
|
}
|
44
48
|
_withBuildContext(t) {
|
45
49
|
this._context = t;
|
46
|
-
const { name: s, config:
|
50
|
+
const { name: s, config: e } = t;
|
47
51
|
return this._callerName = s, this;
|
48
52
|
}
|
49
53
|
}
|
50
54
|
export {
|
51
|
-
|
55
|
+
u as StyleComponentGenerator
|
52
56
|
};
|
@@ -1,4 +1,9 @@
|
|
1
1
|
import { StyledParams, Tag } from '../types';
|
2
|
+
export interface GeneratorProps {
|
3
|
+
element?: string;
|
4
|
+
variantKeys?: string[];
|
5
|
+
propValueKeys?: string[];
|
6
|
+
}
|
2
7
|
export declare class StyleComponentGenerator {
|
3
8
|
tagName: Tag<any>;
|
4
9
|
params: StyledParams;
|
@@ -15,10 +20,7 @@ export declare class StyleComponentGenerator {
|
|
15
20
|
get cssDisplayNameVar(): string;
|
16
21
|
get templateKeys(): string[];
|
17
22
|
get css(): string;
|
18
|
-
get props():
|
19
|
-
element: string | undefined;
|
20
|
-
variantKeys: string[] | undefined;
|
21
|
-
};
|
23
|
+
get props(): GeneratorProps;
|
22
24
|
_withBuildContext(context: {
|
23
25
|
name: string;
|
24
26
|
config: any;
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
@@ -11,7 +11,7 @@ export type CreateElementProps = {
|
|
11
11
|
/** vks = Variant key set */
|
12
12
|
_vks?: Set<string>;
|
13
13
|
};
|
14
|
-
export type StyledComponentProps = Record<string, unknown> & CreateElementProps
|
14
|
+
export type StyledComponentProps = Record<string, unknown> & CreateElementProps;
|
15
15
|
type FnComponent<PROPS extends StyledComponentProps> = {
|
16
16
|
(props: PROPS): ReactNode;
|
17
17
|
generator?: StyleComponentGenerator;
|
@@ -39,13 +39,14 @@ type Variants = {
|
|
39
39
|
compoundVariants?: CompoundVariant[];
|
40
40
|
};
|
41
41
|
type VariantPropValue<T> = T extends 'true' ? 'true' | true : T;
|
42
|
-
export type VariantProps<STYLES extends StyledParams> = STYLES['variants'] extends undefined ?
|
42
|
+
export type VariantProps<STYLES extends StyledParams> = STYLES['variants'] extends undefined ? object : {
|
43
43
|
[K in keyof STYLES['variants']]?: VariantPropValue<keyof STYLES['variants'][K]> | '';
|
44
44
|
};
|
45
|
-
|
46
|
-
export type
|
47
|
-
|
45
|
+
type CssValuePropKey = `props-${string}`;
|
46
|
+
export type ValueProps = {
|
47
|
+
[key: CssValuePropKey]: string;
|
48
48
|
};
|
49
|
+
export type ParentComponentProps<TAG extends Tag<any>> = TAG extends (props: infer P) => ReactNode ? P : unknown;
|
49
50
|
type StylePropertyValue = Record<never, never> & unknown;
|
50
51
|
export type CssStyles = {
|
51
52
|
[key in StyleKeys | OrString]?: StyleValue<key> | StylePropertyValue | PropertyValueToken | CssStyles;
|