@salty-css/core 0.0.1-alpha.0 → 0.0.1-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -18
- package/compiler/index.cjs +11 -0
- package/compiler/index.d.ts +16 -0
- package/compiler/index.js +180 -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/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 +24 -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 I=require("esbuild"),B=require("winston"),K=require("child_process"),N=require("../util/index.cjs"),o=require("path"),r=require("fs"),J=require("fs/promises"),_=require("../parse-templates-BY1Xai-_.cjs");function E(e){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const t=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(s,n,t.get?t:{enumerable:!0,get:()=>e[n]})}}return s.default=e,Object.freeze(s)}const M=E(I),k=E(B),G=k.createLogger({level:"info",format:k.format.combine(k.format.colorize(),k.format.cli()),transports:[new k.transports.Console({})]}),v=e=>o.join(e,"./saltygen"),L=["salty","css","styles","styled"],T=e=>new RegExp(`\\.(${L.join("|")})\\.`).test(e),A=async e=>{const s=v(e),n=o.join(e,"salty-config.ts"),t=o.join(s,"salty-config.js");await M.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:t,format:"esm",external:["react"]});const a=Date.now(),{config:h}=await import(`${t}?t=${a}`);return h},R=async e=>{const s=await A(e),n=new Set,t=(f,p=[])=>f?Object.entries(f).flatMap(([y,c])=>{if(!c)return;if(typeof c=="object")return t(c,[...p,y]);const C=[...p,y].join(".");n.add(`"${C}"`);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=t(y);return p==="base"?c.join(""):`${p} { ${c.join("")} }`}):[],h=f=>f?Object.entries(f).flatMap(([p,y])=>Object.entries(y).flatMap(([c,C])=>{const D=t(C,[p]),P=`.${p}-${c}, [data-${p}="${c}"]`,O=D.join("");return`${P} { ${O} }`})):[],b=t(s.variables),w=a(s.responsiveVariables),l=h(s.conditionalVariables),j=v(e),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"),x=_.parseTemplates(s.templates);r.writeFileSync(F,x)},V=async(e,s)=>{const n=N.toHash(e),t=o.join(s,"js",n+".js");await M.build({entryPoints:[e],minify:!0,treeShaking:!0,bundle:!0,outfile:t,format:"esm",target:["es2022"],keepNames:!0,external:["react"]});const a=Date.now();return await import(`${t}?t=${a}`)},q=async e=>{const s=v(e),n=o.join(s,"salty-config.js"),{config:t}=await import(n);return t},U=async e=>{try{const s=[],n=[],t=v(e),a=o.join(t,"index.css");(()=>{r.existsSync(t)&&K.execSync("rm -rf "+t),r.mkdirSync(t),r.mkdirSync(o.join(t,"css")),r.mkdirSync(o.join(t,"types"))})(),await R(e);const b=await q(e);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,t),S=[];Object.entries(m).forEach(([p,y])=>{if(y.isKeyframes&&y.css){const O=`${y.animationName}.css`,z=`css/${O}`,H=o.join(t,z);s.push(O),r.writeFileSync(H,y.css);return}if(!y.generator)return;const c=y.generator._withBuildContext({name:p,config:b}),C=`${c.hash}-${c.priority}.css`;n[c.priority]||(n[c.priority]=[]),n[c.priority].push(C),S.push(C);const D=`css/${C}`,P=o.join(t,D);r.writeFileSync(P,c.css)});const F=S.map(p=>`@import url('./${p}');`).join(`
|
|
2
|
+
`),x=N.toHash(i,6),f=o.join(t,`css/${x}.css`);r.writeFileSync(f,F)}}await w(e,t);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)}},W=async(e,s)=>{try{const n=[],t=o.join(e,"./saltygen"),a=o.join(t,"index.css");if(T(s)){const b=await q(e),w=await V(s,t);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(t,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)}},X=async(e,s)=>{try{const n=o.join(e,"./saltygen");if(T(s)){let a=r.readFileSync(s,"utf8");a.replace(/^(?!export\s)const\s.*/gm,u=>`export ${u}`)!==a&&await J.writeFile(s,a);const b=await q(e),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)});`,x=new RegExp(`${u}[=\\s]+[^()]+styled\\(([^,]+),[^;]+;`,"g");l=l.replace(x,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=U;exports.generateFile=W;exports.generateVariables=R;exports.isSaltyFile=T;exports.logger=G;exports.minimizeFile=X;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { StyleComponentGenerator } from '../generator/style-generator';
|
|
2
|
+
import * as winston from 'winston';
|
|
3
|
+
export declare const logger: winston.Logger;
|
|
4
|
+
export declare const isSaltyFile: (file: string) => boolean;
|
|
5
|
+
export declare const generateVariables: (dirname: string) => Promise<void>;
|
|
6
|
+
export declare const compileSaltyFile: (sourceFilePath: string, outputDirectory: string) => Promise<{
|
|
7
|
+
[key: string]: {
|
|
8
|
+
generator: StyleComponentGenerator;
|
|
9
|
+
isKeyframes?: boolean;
|
|
10
|
+
animationName?: string;
|
|
11
|
+
css?: string;
|
|
12
|
+
};
|
|
13
|
+
}>;
|
|
14
|
+
export declare const generateCss: (dirname: string) => Promise<void>;
|
|
15
|
+
export declare const generateFile: (dirname: string, file: string) => Promise<void>;
|
|
16
|
+
export declare const minimizeFile: (dirname: string, file: string) => Promise<string | undefined>;
|
|
@@ -0,0 +1,180 @@
|
|
|
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 ot = 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"], O = (s) => new RegExp(`\\.(${W.join("|")})\\.`).test(s), X = 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: S } = await import(`${t}?t=${c}`);
|
|
25
|
+
return S;
|
|
26
|
+
}, Y = async (s) => {
|
|
27
|
+
const e = await X(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 C = [...l, p].join(".");
|
|
31
|
+
n.add(`"${C}"`);
|
|
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
|
+
}) : [], S = (m) => m ? Object.entries(m).flatMap(([l, p]) => Object.entries(p).flatMap(([i, C]) => {
|
|
38
|
+
const D = t(C, [l]), P = `.${l}-${i}, [data-${l}="${i}"]`, V = D.join("");
|
|
39
|
+
return `${P} { ${V} }`;
|
|
40
|
+
})) : [], d = t(e.variables), w = c(e.responsiveVariables), a = S(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"), j = q(e.global, "");
|
|
45
|
+
$(g, j);
|
|
46
|
+
const F = o(b, "css/templates.css"), x = A(e.templates);
|
|
47
|
+
$(F, x);
|
|
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
|
+
}, rt = 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 Y(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), j = [];
|
|
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
|
+
}), C = `${i.hash}-${i.priority}.css`;
|
|
91
|
+
n[i.priority] || (n[i.priority] = []), n[i.priority].push(C), j.push(C);
|
|
92
|
+
const D = `css/${C}`, P = o(t, D);
|
|
93
|
+
$(P, i.css);
|
|
94
|
+
});
|
|
95
|
+
const F = j.map((l) => `@import url('./${l}');`).join(`
|
|
96
|
+
`), x = T(r, 6), m = o(t, `css/${x}.css`);
|
|
97
|
+
$(m, F);
|
|
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
|
+
}, it = 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`, j = `css/${g}`, F = o(t, j);
|
|
128
|
+
n.push(g), $(F, 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
|
+
}, ct = 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: j } = f.props, F = `${y} = styled(${u}, "${f.classNames}", "${f._callerName}", ${JSON.stringify(g)}, ${JSON.stringify(
|
|
160
|
+
j
|
|
161
|
+
)});`, x = new RegExp(`${y}[=\\s]+[^()]+styled\\(([^,]+),[^;]+;`, "g");
|
|
162
|
+
a = a.replace(x, F);
|
|
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
|
+
rt as generateCss,
|
|
175
|
+
it as generateFile,
|
|
176
|
+
Y as generateVariables,
|
|
177
|
+
O as isSaltyFile,
|
|
178
|
+
ot as logger,
|
|
179
|
+
ct as minimizeFile
|
|
180
|
+
};
|
|
@@ -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
|
@@ -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.10",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"typings": "./dist/index.d.ts",
|
|
@@ -15,36 +15,40 @@
|
|
|
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
22
|
"name": "core"
|
|
23
23
|
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"clsx": ">=2.x",
|
|
26
|
+
"winston": ">=3.x"
|
|
27
|
+
},
|
|
24
28
|
"exports": {
|
|
25
|
-
"
|
|
26
|
-
"import": "./index.js",
|
|
27
|
-
"require": "./index.cjs"
|
|
29
|
+
"./compiler": {
|
|
30
|
+
"import": "./compiler/index.js",
|
|
31
|
+
"require": "./compiler/index.cjs"
|
|
28
32
|
},
|
|
29
|
-
"./
|
|
30
|
-
"import": "./
|
|
31
|
-
"require": "./
|
|
33
|
+
"./css": {
|
|
34
|
+
"import": "./css/index.js",
|
|
35
|
+
"require": "./css/index.cjs"
|
|
32
36
|
},
|
|
33
|
-
"./
|
|
34
|
-
"import": "./
|
|
35
|
-
"require": "./
|
|
37
|
+
"./generator": {
|
|
38
|
+
"import": "./generator/index.js",
|
|
39
|
+
"require": "./generator/index.cjs"
|
|
36
40
|
},
|
|
37
|
-
"./
|
|
38
|
-
"import": "./
|
|
39
|
-
"require": "./
|
|
41
|
+
"./config": {
|
|
42
|
+
"import": "./config/index.js",
|
|
43
|
+
"require": "./config/index.cjs"
|
|
40
44
|
},
|
|
41
|
-
"./
|
|
42
|
-
"import": "./
|
|
43
|
-
"require": "./
|
|
45
|
+
"./types": {
|
|
46
|
+
"import": "./types/index.js",
|
|
47
|
+
"require": "./types/index.cjs"
|
|
44
48
|
},
|
|
45
|
-
"./
|
|
46
|
-
"import": "./
|
|
47
|
-
"require": "./
|
|
49
|
+
"./util": {
|
|
50
|
+
"import": "./util/index.js",
|
|
51
|
+
"require": "./util/index.cjs"
|
|
48
52
|
}
|
|
49
53
|
}
|
|
50
54
|
}
|
|
@@ -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
|
+
};
|