@salty-css/core 0.0.1-alpha.201 → 0.0.1-alpha.203
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/bin/main.cjs +1 -1
- package/bin/main.js +1 -1
- package/compiler/index.cjs +1 -1
- package/compiler/index.d.ts +14 -11
- package/compiler/index.js +2 -2
- package/config/index.cjs +1 -1
- package/config/index.js +7 -6
- package/css/index.cjs +1 -1
- package/css/index.js +5 -4
- package/css/keyframes.cjs +1 -1
- package/css/keyframes.d.ts +1 -1
- package/css/keyframes.js +26 -26
- package/css/merge.cjs +1 -1
- package/css/merge.d.ts +2 -0
- package/css/merge.js +3 -2
- package/factories/define-templates.d.ts +23 -6
- package/generators/index.cjs +1 -1
- package/generators/index.js +1 -1
- package/generators/styles-generator.d.ts +1 -1
- package/index-CuE3hjO7.js +491 -0
- package/index-_k0TKi9f.cjs +38 -0
- package/package.json +1 -1
- package/parse-styles-CbYzTfwr.js +118 -0
- package/parse-styles-DhDStS4F.cjs +3 -0
- package/parsers/index.cjs +1 -1
- package/parsers/index.js +59 -20
- package/parsers/parse-modifiers.d.ts +2 -2
- package/parsers/parse-styles.d.ts +11 -1
- package/parsers/parse-templates.d.ts +1 -1
- package/parsers/parse-tokens.d.ts +3 -2
- package/parsers/parser-types.d.ts +5 -1
- package/server/index.cjs +1 -1
- package/server/index.js +1 -1
- package/types/config-types.d.ts +10 -3
- package/index-BtsgjRXm.cjs +0 -38
- package/index-DVzNO1Qt.js +0 -486
- package/parse-styles-Bjxh8lZv.js +0 -107
- package/parse-styles-D_gL6efj.cjs +0 -7
@@ -0,0 +1,3 @@
|
|
1
|
+
"use strict";const T=require("./dash-case-BJEkFEGQ.cjs"),S=r=>e=>{if(typeof e!="string"||!r)return;let t=e;const i=[];return Object.values(r).forEach(a=>{const{pattern:w,transform:j}=a;t=t.replace(w,C=>{const{value:x,css:p}=j(C);return p&&i.push(p),x})}),{transformed:t,additionalCss:i}},N=r=>e=>typeof e!="string"||!/\{[^{}]+\}/g.test(e)?void 0:{transformed:e.replace(/\{([^{}]+)\}/g,(...a)=>`var(--${T.dashCase(a[1].replaceAll(".","-"))})`)},U=N(),q=["top","right","bottom","left","min-width",/.*width.*/,/^[^line]*height.*/,/padding.*/,/margin.*/,/border.*/,/inset.*/,/.*radius.*/,/.*spacing.*/,/.*gap.*/,/.*indent.*/,/.*offset.*/,/.*size.*/,/.*thickness.*/,/.*font-size.*/],J=(r,e,t)=>{if(q.some(a=>typeof a=="string"?a===r:a.test(r))){const a=(t==null?void 0:t.defaultUnit)||"px";return`${e}${a}`}return`${e}`},M=["Webkit","Moz","ms","O"],Q=r=>r.startsWith("-")?r:M.some(e=>r.startsWith(e))?`-${T.dashCase(r)}`:T.dashCase(r),$=async(r,e="",t)=>{if(!r)throw new Error("No styles provided to parseStyles function!");const i=new Set,w=Object.entries(r).map(async([y,s])=>{var b;const n=y.trim(),h=Q(n),c=(d,f=";")=>`${h}:${d}${f}`;if(typeof s=="function"&&(s=s({scope:e,config:t})),s instanceof Promise&&(s=await s),t!=null&&t.templates&&t.templates[n]){const f=s.split(".").reduce((o,u)=>o[u],t.templates[n]);if(f){const[o]=await $(f,"");return o}console.warn(`Template "${n}" with path of "${s}" was not found in config!`);return}if(typeof s=="object"){if(!s)return;if(s.isColor)return c(s.toString());if(n==="defaultVariants")return;if(n==="variants"){const o=Object.entries(s);for(const[u,l]of o){if(!l)return;const E=Object.entries(l);for(const[W,m]of E){if(!m)return;const O=`${e}.${u}-${W}`;(await $(m,O,t)).forEach(A=>i.add(A))}}return}if(n==="compoundVariants"){for(const o of s){const{css:u,...l}=o,E=Object.entries(l).reduce((m,[O,k])=>`${m}.${O}-${k}`,e);(await $(u,E,t)).forEach(m=>i.add(m))}return}if(n.startsWith("@")){const o=((b=t==null?void 0:t.mediaQueries)==null?void 0:b[n])||n,u=await V(s,e,t),l=`${o} { ${u} }`;i.add(l);return}const d=y.includes("&")?n.replace("&",e):n.startsWith(":")?`${e}${n}`:`${e} ${n}`;(await $(s,d,t)).forEach(o=>i.add(o));return}if(typeof s=="number"){const d=J(h,s,t);return c(d)}if(typeof s!="string")if("toString"in s)s=s.toString();else throw new Error(`Invalid value type for property ${h}`);return c(s)}),{modifiers:j}=t||{},C=[N(),S(j)],p=(await Promise.all(w).then(y=>Promise.all(y.map(s=>C.reduce(async(n,h)=>{const c=await n;if(!c)return c;const P=await h(c);if(!P)return c;const{transformed:b,additionalCss:d}=P;let f="";if(d)for(const o of d)f+=await V(o,"");return`${f}${b}`},Promise.resolve(s)))))).join(`
|
2
|
+
`);if(!p.trim())return i;const z=e?`${e} { ${p} }`:p;return i.add(z),i},V=async(r,e,t)=>[...await $(r,e,t)].join(`
|
3
|
+
`);exports.parseAndJoinStyles=V;exports.parseVariableTokens=U;
|
package/parsers/index.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
1
|
+
"use strict";var o=Object.defineProperty;var u=(t,e,r)=>e in t?o(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var s=(t,e,r)=>u(t,typeof e!="symbol"?e+"":e,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("../css/media.cjs");class a{constructor(e){this._current=e}get isGlobalDefine(){return!0}}const m=t=>new a(t),p=t=>t(h.media);class n{constructor(e){this._current=e}get isDefineVariables(){return!0}}const f=t=>new n(t);class i{constructor(e){s(this,"_path");this.params=e}get _current(){return this.params.template}get isDefineTemplate(){return!0}_setPath(e){return this._path=e,this}}class l{constructor(e){s(this,"_path");s(this,"templates",[]);this.params=e,Object.entries(e).forEach(([r,c])=>{this.templates.push(new i({name:r,template:c}))})}get _current(){return this.params}get _children(){return Object.fromEntries(this.templates.map(e=>[e.params.name,e]))}get isDefineTemplates(){return!0}_setPath(e){return this._path=e,this.templates.forEach(r=>r._setPath(e)),this}}const y=t=>new l(t);exports.GlobalStylesFactory=a;exports.TemplateFactory=i;exports.TemplatesFactory=l;exports.VariablesFactory=n;exports.defineGlobalStyles=m;exports.defineMediaQuery=p;exports.defineTemplates=y;exports.defineVariables=f;
|
package/parsers/index.js
CHANGED
@@ -1,37 +1,76 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
var n = Object.defineProperty;
|
2
|
+
var i = (e, t, r) => t in e ? n(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
3
|
+
var s = (e, t, r) => i(e, typeof t != "symbol" ? t + "" : t, r);
|
4
|
+
import { media as c } from "../css/media.js";
|
5
|
+
class u {
|
6
|
+
constructor(t) {
|
7
|
+
this._current = t;
|
5
8
|
}
|
6
9
|
get isGlobalDefine() {
|
7
10
|
return !0;
|
8
11
|
}
|
9
12
|
}
|
10
|
-
const
|
11
|
-
class
|
12
|
-
constructor(
|
13
|
-
this._current =
|
13
|
+
const f = (e) => new u(e), _ = (e) => e(c);
|
14
|
+
class l {
|
15
|
+
constructor(t) {
|
16
|
+
this._current = t;
|
14
17
|
}
|
15
18
|
get isDefineVariables() {
|
16
19
|
return !0;
|
17
20
|
}
|
18
21
|
}
|
19
|
-
const
|
20
|
-
class
|
21
|
-
constructor(
|
22
|
-
this
|
22
|
+
const b = (e) => new l(e);
|
23
|
+
class o {
|
24
|
+
constructor(t) {
|
25
|
+
s(this, "_path");
|
26
|
+
this.params = t;
|
27
|
+
}
|
28
|
+
get _current() {
|
29
|
+
return this.params.template;
|
30
|
+
}
|
31
|
+
get isDefineTemplate() {
|
32
|
+
return !0;
|
33
|
+
}
|
34
|
+
_setPath(t) {
|
35
|
+
return this._path = t, this;
|
36
|
+
}
|
37
|
+
}
|
38
|
+
class h {
|
39
|
+
constructor(t) {
|
40
|
+
s(this, "_path");
|
41
|
+
s(this, "templates", []);
|
42
|
+
this.params = t, Object.entries(t).forEach(([r, a]) => {
|
43
|
+
this.templates.push(
|
44
|
+
new o({
|
45
|
+
name: r,
|
46
|
+
template: a
|
47
|
+
})
|
48
|
+
);
|
49
|
+
});
|
50
|
+
}
|
51
|
+
get _current() {
|
52
|
+
return this.params;
|
53
|
+
}
|
54
|
+
get _children() {
|
55
|
+
return Object.fromEntries(
|
56
|
+
this.templates.map((t) => [t.params.name, t])
|
57
|
+
);
|
23
58
|
}
|
24
59
|
get isDefineTemplates() {
|
25
60
|
return !0;
|
26
61
|
}
|
62
|
+
_setPath(t) {
|
63
|
+
return this._path = t, this.templates.forEach((r) => r._setPath(t)), this;
|
64
|
+
}
|
27
65
|
}
|
28
|
-
const
|
66
|
+
const d = (e) => new h(e);
|
29
67
|
export {
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
68
|
+
u as GlobalStylesFactory,
|
69
|
+
o as TemplateFactory,
|
70
|
+
h as TemplatesFactory,
|
71
|
+
l as VariablesFactory,
|
72
|
+
f as defineGlobalStyles,
|
73
|
+
_ as defineMediaQuery,
|
74
|
+
d as defineTemplates,
|
75
|
+
b as defineVariables
|
37
76
|
};
|
@@ -1,3 +1,3 @@
|
|
1
1
|
import { CssModifiers } from '../types/config-types';
|
2
|
-
import {
|
3
|
-
export declare const parseValueModifiers: (
|
2
|
+
import { StyleValueModifierFunction } from './parser-types';
|
3
|
+
export declare const parseValueModifiers: (modifiers?: CssModifiers) => StyleValueModifierFunction;
|
@@ -1,2 +1,12 @@
|
|
1
1
|
import { CachedConfig, SaltyConfig } from '../types/config-types';
|
2
|
-
|
2
|
+
/**
|
3
|
+
* Transform styles object to css string with or without scope
|
4
|
+
* @param styles CSS as JS object
|
5
|
+
* @param currentScope Scope of the styles, for class names full path with dot separator is required
|
6
|
+
* @param config Salty config object to allow use of templates and media queries etc.
|
7
|
+
* @returns CSS strings that can be injected to the .css file or used inside of styles tag
|
8
|
+
* - First item is the main class with all the styles
|
9
|
+
* - Rest of the items are child selectors or media queries etc.
|
10
|
+
*/
|
11
|
+
export declare const parseStyles: <T extends object>(styles?: T, currentScope?: string, config?: (SaltyConfig & CachedConfig) | undefined) => Promise<Set<string>>;
|
12
|
+
export declare const parseAndJoinStyles: <T extends object>(styles: T, currentClass: string, config?: (SaltyConfig & CachedConfig) | undefined) => Promise<string>;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
export declare const parseTemplates: <T extends object>(obj: T, path?: PropertyKey[]) => string
|
1
|
+
export declare const parseTemplates: <T extends object>(obj: T, path?: PropertyKey[]) => Promise<string>;
|
2
2
|
export declare const getTemplateKeys: <T extends object>(templates: T) => string[];
|
3
3
|
export declare const getTemplateTypes: <T extends object>(templates: T) => Record<string, string>;
|
4
4
|
export declare const getTemplateTokens: <T extends object>(templates: T, parent?: string, templateTokens?: Set<string>) => string[];
|
@@ -1,2 +1,3 @@
|
|
1
|
-
import {
|
2
|
-
export declare const parseValueTokens: (
|
1
|
+
import { SyncronousStyleValueModifierFunction } from './parser-types';
|
2
|
+
export declare const parseValueTokens: (tokenNames?: string[]) => SyncronousStyleValueModifierFunction;
|
3
|
+
export declare const parseVariableTokens: SyncronousStyleValueModifierFunction;
|
@@ -1,4 +1,8 @@
|
|
1
1
|
export interface ValueParserReturnValue {
|
2
|
-
|
2
|
+
transformed: string;
|
3
3
|
additionalCss?: object[];
|
4
4
|
}
|
5
|
+
type StyleValueModifierFunctionReturnValue = undefined | ValueParserReturnValue;
|
6
|
+
export type SyncronousStyleValueModifierFunction = (current: string) => StyleValueModifierFunctionReturnValue;
|
7
|
+
export type StyleValueModifierFunction = (current: string) => Promise<StyleValueModifierFunctionReturnValue> | StyleValueModifierFunctionReturnValue;
|
8
|
+
export {};
|
package/server/index.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("fs/promises"),r=require("../index-
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("fs/promises"),r=require("../index-_k0TKi9f.cjs"),i=async t=>{if(!t||t.includes("node_modules")||t.includes("saltygen"))return!1;if(t.includes("salty.config"))return!0;if(!r.isSaltyFile(t))return!1;const e=await s.readFile(t,"utf-8");return!!/.+define[A-Z]\w+/.test(e)};exports.checkShouldRestart=i;
|
package/server/index.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { readFile as r } from "fs/promises";
|
2
|
-
import { i as e } from "../index-
|
2
|
+
import { i as e } from "../index-CuE3hjO7.js";
|
3
3
|
const f = async (t) => {
|
4
4
|
if (!t || t.includes("node_modules") || t.includes("saltygen")) return !1;
|
5
5
|
if (t.includes("salty.config")) return !0;
|
package/types/config-types.d.ts
CHANGED
@@ -18,10 +18,14 @@ export interface SaltyVariables {
|
|
18
18
|
type CssTemplate = CssStyles | {
|
19
19
|
[key: PropertyKey]: CssTemplate;
|
20
20
|
};
|
21
|
+
export interface CssTemplateObject {
|
22
|
+
[key: PropertyKey]: CssTemplate;
|
23
|
+
}
|
24
|
+
export interface CssTemplateFunction {
|
25
|
+
(value: unknown): CssTemplate;
|
26
|
+
}
|
21
27
|
export interface CssTemplates {
|
22
|
-
[key: PropertyKey]:
|
23
|
-
[key: PropertyKey]: CssTemplate;
|
24
|
-
};
|
28
|
+
[key: PropertyKey]: CssTemplateObject | CssTemplateFunction;
|
25
29
|
}
|
26
30
|
export interface CssModifier {
|
27
31
|
pattern: RegExp;
|
@@ -73,5 +77,8 @@ export interface CachedConfig {
|
|
73
77
|
templates: CssTemplates;
|
74
78
|
staticVariables: Record<string, any>;
|
75
79
|
mediaQueries: Record<string, string>;
|
80
|
+
templatePaths: {
|
81
|
+
[key: string]: string;
|
82
|
+
};
|
76
83
|
}
|
77
84
|
export {};
|
package/index-BtsgjRXm.cjs
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
"use strict";const $e=require("esbuild"),Ce=require("child_process"),k=require("./dash-case-BJEkFEGQ.cjs"),i=require("path"),c=require("fs"),ne=require("fs/promises"),A=require("./parse-styles-D_gL6efj.cjs"),B=require("winston"),z=require("./css/merge.cjs");var se=typeof document<"u"?document.currentScript:null;function xe(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,n.get?n:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const de=xe($e),ue=(e,t=[])=>{if(!e)return"";const s=[],n={};if(Object.entries(e).forEach(([o,r])=>{if(typeof r=="object"){if(!r)return;const f=o.trim(),u=ue(r,[...t,f]);s.push(u)}else n[o]=r}),Object.keys(n).length){const o=t.map(k.dashCase).join("-"),r=A.parseStyles(n,`.${o}`);s.push(r)}return s.join(`
|
2
|
-
`)},Ne=e=>e?Object.entries(e).reduce((t,[s,n])=>(typeof n=="object"&&(t[s]=pe(n).map(o=>`"${o}"`).join(" | ")),t),{}):{},pe=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,o])=>{const r=t?`${t}.${n}`:n;return typeof o=="object"?pe(o,r,s):s.add(t)}),[...s]):[],ye=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=i.join(e,"package.json");return c.existsSync(t)?t:ye(i.join(e,".."))},ke=async e=>{const t=ye(e);return await ne.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},Pe=async e=>{const t=await ke(e);if(t)return t.type};let J;const ge=async e=>{if(J)return J;const t=await Pe(e);return t==="module"?J="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:se&&se.tagName.toUpperCase()==="SCRIPT"&&se.src||new URL("index-BtsgjRXm.cjs",document.baseURI).href).endsWith(".cjs"))&&(J="cjs"),J||"esm"},G=B.createLogger({level:"debug",format:B.format.combine(B.format.colorize(),B.format.cli()),transports:[new B.transports.Console({})]}),De=e=>{G.error(e)};function me(e){return e?typeof e!="string"?me(String(e)):e.replace(/[\s-]/g,".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(t,s)=>(s>0?".":"")+t.toLowerCase()):""}const _e={"*, *::before, *::after":{boxSizing:"border-box"},"*":{margin:0},html:{lineHeight:1.15,textSizeAdjust:"100%",WebkitFontSmoothing:"antialiased"},"img, picture, video, canvas, svg":{display:"block",maxWidth:"100%"},"p, h1, h2, h3, h4, h5, h6":{overflowWrap:"break-word"},p:{textWrap:"pretty"},"h1, h2, h3, h4, h5, h6":{textWrap:"balance"},a:{color:"currentColor"},button:{lineHeight:"1em",color:"currentColor"},"input, optgroup, select, textarea":{fontFamily:"inherit",fontSize:"100%",lineHeight:"1.15em"}},O={externalModules:[],rcFile:void 0,destDir:void 0},he=e=>{if(O.externalModules.length>0)return O.externalModules;const s=c.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(o=>o.replace(/['"`]/g,"").trim());return O.externalModules=n,n},R=async e=>{if(O.destDir)return O.destDir;const t=await ie(e),s=i.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return O.destDir=s,s},oe=["salty","css","styles","styled"],Se=(e=[])=>new RegExp(`\\.(${[...oe,...e].join("|")})\\.`),U=(e,t=[])=>Se(t).test(e),je=async e=>{if(O.rcFile)return O.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=i.join(e,".saltyrc.json"),s=await ne.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(O.rcFile=s,s):je(i.join(e,".."))},ie=async e=>{var n,o;const t=await je(e),s=(n=t.projects)==null?void 0:n.find(r=>e.endsWith(r.dir||""));return s||((o=t.projects)==null?void 0:o.find(r=>r.dir===t.defaultProject))},Te=async e=>{const t=await ie(e),s=await R(e),n=i.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),o=i.join(s,"salty.config.js"),r=await ge(e),f=he(n);await de.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:r,external:f});const u=Date.now(),{config:y}=await import(`${o}?t=${u}`);return y},be=async(e,t)=>{var ae,le;const s=await R(e),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...t].map(async b=>{const F=await K(e,b,s);Object.entries(F).forEach(([E,$])=>{$.isMedia?n.mediaQueries.push([E,$]):$.isGlobalDefine?n.globalStyles.push($):$.isDefineVariables?n.variables.push($):$.isDefineTemplates&&n.templates.push($)})}));const o=await Te(e),r={...o},f=new Set,u=(b,F=[])=>b?Object.entries(b).flatMap(([E,$])=>{if(!$)return;if(typeof $=="object")return u($,[...F,E]);const X=me(E),Y=k.dashCase(E),ee=[...F,X].join(".");f.add(`"${ee}"`);const te=[...F.map(k.dashCase),Y].join("-"),{result:Fe}=A.parseValueTokens($);return`--${te}: ${Fe};`}):[],y=b=>b?Object.entries(b).flatMap(([F,E])=>{const $=u(E);return F==="base"?$.join(""):`${F} { ${$.join("")} }`}):[],d=b=>b?Object.entries(b).flatMap(([F,E])=>Object.entries(E).flatMap(([$,X])=>{const Y=u(X,[F]),ee=`.${F}-${$}, [data-${F}="${$}"]`,te=Y.join("");return`${ee} { ${te} }`})):[],g=b=>({...b,responsive:void 0,conditional:void 0}),m=b=>n.variables.map(F=>b==="static"?g(F._current):F._current[b]),p=z.mergeStyles(g(o.variables),m("static")),w=u(p),h=z.mergeStyles((ae=o.variables)==null?void 0:ae.responsive,m("responsive")),_=y(h),P=z.mergeStyles((le=o.variables)==null?void 0:le.conditional,m("conditional")),D=d(P),V=i.join(s,"css/_variables.css"),T=`:root { ${w.join("")} ${_.join("")} } ${D.join("")}`;c.writeFileSync(V,T),r.staticVariables=p;const H=i.join(s,"css/_global.css"),N=z.mergeStyles(o.global,n.globalStyles),q=A.parseStyles(N,"");c.writeFileSync(H,`@layer global { ${q} }`);const a=i.join(s,"css/_reset.css"),j=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:_e,l=A.parseStyles(j,"");c.writeFileSync(a,`@layer reset { ${l} }`);const C=i.join(s,"css/_templates.css"),x=z.mergeStyles(o.templates,n.templates),v=ue(x),I=Ne(x);c.writeFileSync(C,v),r.templates=x;const{mediaQueries:M}=n;r.mediaQueries=Object.fromEntries(M.map(([b,F])=>[`@${b}`,F]));const L=M.map(([b])=>`'@${b}'`).join(" | "),Q=i.join(s,"types/css-tokens.d.ts"),W=`
|
3
|
-
// Variable types
|
4
|
-
type VariableTokens = ${[...f].join("|")};
|
5
|
-
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
6
|
-
|
7
|
-
// Template types
|
8
|
-
type TemplateTokens = {
|
9
|
-
${Object.entries(I).map(([b,F])=>`${b}?: ${F}`).join(`
|
10
|
-
`)}
|
11
|
-
}
|
12
|
-
|
13
|
-
// Media query types
|
14
|
-
type MediaQueryKeys = ${L||"''"};
|
15
|
-
`;c.writeFileSync(Q,W);const Z=i.join(s,"cache/config-cache.json");c.writeFileSync(Z,JSON.stringify(r,null,2))},fe=e=>e.replace(/styled\(([^"'`{,]+),/g,(t,s)=>{if(/^['"`]/.test(s))return t;const o=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!o.test(e))return t;const f=o.exec(e);if(f){const u=f.at(1);if(oe.some(d=>u==null?void 0:u.includes(d)))return t}return"styled('div',"}),Ee=(e,t)=>{try{const s=c.readFileSync(i.join(t,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
|
16
|
-
|
17
|
-
${e}`:`globalThis.saltyConfig = {};
|
18
|
-
|
19
|
-
${e}`}catch{return e}},K=async(e,t,s)=>{const n=k.toHash(t),o=i.join(s,"./temp");c.existsSync(o)||c.mkdirSync(o);const r=i.parse(t);let f=c.readFileSync(t,"utf8");f=fe(f),f=Ee(f,e);const u=i.join(s,"js",n+".js"),y=await ie(e),d=i.join(e,(y==null?void 0:y.configDir)||"","salty.config.ts"),g=he(d),m=await ge(e);await de.build({stdin:{contents:f,sourcefile:r.base,resolveDir:r.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:u,format:m,target:["node20"],keepNames:!0,external:g,packages:"external",plugins:[{name:"test",setup:h=>{h.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},_=>{const P=c.readFileSync(_.path,"utf8");return{contents:fe(P),loader:"ts"}})}}]});const p=Date.now();return await import(`${u}?t=${p}`)},Oe=async e=>{const t=await R(e),s=i.join(t,"cache/config-cache.json"),n=c.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},re=async e=>{const t=await Oe(e),s=await R(e),n=i.join(s,"salty.config.js"),o=Date.now(),{config:r}=await import(`${n}?t=${o}`);return z.mergeStyles(r,t)},we=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Re=async(e,t=we(),s=!0)=>{try{const n=Date.now();t?G.info("Generating CSS in production mode! 🔥"):G.info("Generating CSS in development mode! 🚀");const o=[],r=[],f=await R(e),u=i.join(f,"index.css");s&&(()=>{c.existsSync(f)&&Ce.execSync("rm -rf "+f),c.mkdirSync(f,{recursive:!0}),c.mkdirSync(i.join(f,"css")),c.mkdirSync(i.join(f,"types")),c.mkdirSync(i.join(f,"js")),c.mkdirSync(i.join(f,"cache"))})();const d=new Set,g=new Set;async function m(a){const S=["node_modules","saltygen"],j=c.statSync(a);if(j.isDirectory()){const l=c.readdirSync(a);if(S.some(x=>a.includes(x)))return;await Promise.all(l.map(x=>m(i.join(a,x))))}else if(j.isFile()&&U(a)){d.add(a);const C=c.readFileSync(a,"utf8");/define[\w\d]+\(/.test(C)&&g.add(a)}}await m(e),await be(e,g);const p={keyframes:[],components:[],classNames:[]};await Promise.all([...d].map(async a=>{const S=await K(e,a,f);Object.entries(S).forEach(([j,l])=>{l.isKeyframes?p.keyframes.push({value:l,src:a,name:j}):l.isClassName?p.classNames.push({...l,src:a,name:j}):l.generator&&p.components.push({...l,src:a,name:j})})}));const w=await re(e);for(const a of p.keyframes){const{value:S}=a,j=`a_${S.animationName}.css`,l=`css/${j}`,C=i.join(f,l);o.push(j),c.writeFileSync(C,S.css)}const h={};for(const a of p.components){const{src:S,name:j}=a,l=a.generator._withBuildContext({callerName:j,isProduction:t,config:w});r[l.priority]||(r[l.priority]=[]),r[l.priority].push(l.cssFileName);const C=`css/${l.cssFileName}`,x=i.join(f,C);c.writeFileSync(x,l.css),w.importStrategy==="component"&&(h[S]?h[S].push(l.cssFileName):h[S]=[l.cssFileName])}for(const a of p.classNames){const{src:S,name:j}=a,l=a.generator._withBuildContext({callerName:j,isProduction:t,config:w});r[0].push(l.cssFileName);const C=`css/${l.cssFileName}`,x=i.join(f,C);c.writeFileSync(x,l.css),w.importStrategy==="component"&&(h[S]?h[S].push(l.cssFileName):h[S]=[l.cssFileName])}w.importStrategy==="component"&&Object.entries(h).forEach(([a,S])=>{const j=S.map(I=>`@import url('./${I}');`).join(`
|
20
|
-
`),l=k.toHash(a,6),C=i.parse(a),x=k.dashCase(C.name),v=i.join(f,`css/f_${x}-${l}.css`);c.writeFileSync(v,j)});const _=o.map(a=>`@import url('./css/${a}');`).join(`
|
21
|
-
`);let T=`@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
22
|
-
|
23
|
-
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(a=>{try{return c.readFileSync(i.join(f,"css",a),"utf8").length>0}catch{return!1}}).map(a=>`@import url('./css/${a}');`).join(`
|
24
|
-
`)}
|
25
|
-
${_}`;if(w.importStrategy!=="component"){const a=r.reduce((S,j,l)=>{const C=j.reduce((M,L)=>{var Z;const Q=i.join(f,"css",L),ce=c.readFileSync(Q,"utf8"),W=((Z=/.*-([^-]+)-\d+.css/.exec(L))==null?void 0:Z.at(1))||k.toHash(Q,6);return M.includes(W)?M:`${M}
|
26
|
-
/*start:${W}*/
|
27
|
-
${ce}
|
28
|
-
/*end:${W}*/
|
29
|
-
`},""),x=`l_${l}.css`,v=i.join(f,"css",x),I=`@layer l${l} { ${C}
|
30
|
-
}`;return c.writeFileSync(v,I),`${S}
|
31
|
-
@import url('./css/${x}');`},"");T+=a}c.writeFileSync(u,T);const N=Date.now()-n,q=N<200?"🔥":N<500?"🚀":N<1e3?"🎉":N<2e3?"🚗":N<5e3?"🤔":"🥴";G.info(`Generated CSS in ${N}ms! ${q}`)}catch(n){console.error(n)}},Ve=async(e,t)=>{try{const s=await R(e);if(U(t)){const o=[],r=await re(e),f=await K(e,t,s);if(Object.entries(f).forEach(([u,y])=>{if(y.isKeyframes&&y.css){const w=`css/${`a_${y.animationName}.css`}`,h=i.join(s,w);c.writeFileSync(h,y.css);return}if(y.isClassName){const p=y.factory._withBuildContext({name:u});o[0].push(p.cssFileName);const w=`css/${p.cssFileName}`,h=i.join(s,w);c.writeFileSync(h,p.css)}if(!y.generator)return;const d=y.generator._withBuildContext({name:u,config:r}),g=`css/${d.cssFileName}`,m=i.join(s,g);c.writeFileSync(m,d.css),o[d.priority]||(o[d.priority]=[]),o[d.priority].push(d.cssFileName)}),r.importStrategy!=="component")o.forEach((u,y)=>{const d=`l_${y}.css`,g=i.join(s,"css",d);let m=c.readFileSync(g,"utf8");u.forEach(p=>{var P;const w=i.join(s,"css",p),h=((P=/.*-([^-]+)-\d+.css/.exec(p))==null?void 0:P.at(1))||k.toHash(w,6);if(!m.includes(h)){const D=c.readFileSync(w,"utf8"),V=`/*start:${h}*/
|
32
|
-
${D}
|
33
|
-
/*end:${h}*/
|
34
|
-
`;m=`${m.replace(/\}$/,"")}
|
35
|
-
${V}
|
36
|
-
}`}}),c.writeFileSync(g,m)});else{const u=o.flat().map(p=>`@import url('./${p}');`).join(`
|
37
|
-
`),y=k.toHash(t,6),d=i.parse(t),g=k.dashCase(d.name),m=i.join(s,`css/f_${g}-${y}.css`);c.writeFileSync(m,u)}}}catch(s){console.error(s)}},Me=async(e,t,s=we())=>{try{const n=await R(e);if(U(t)){const r=c.readFileSync(t,"utf8");r.replace(/^(?!export\s)const\s.*/gm,g=>`export ${g}`)!==r&&await ne.writeFile(t,r);const u=await re(e),y=await K(e,t,n);let d=r;if(Object.entries(y).forEach(([g,m])=>{var l;if(m.isKeyframes||!m.generator)return;const p=m.generator._withBuildContext({name:g,config:u,prod:s}),w=new RegExp(`\\s${g}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(r);if(!w)return console.error("Could not find the original declaration");const h=(l=w.at(1))==null?void 0:l.trim(),_=new RegExp(`\\s${g}[=\\s]+styled\\(`,"g").exec(d);if(!_)return console.error("Could not find the original declaration");const{index:P}=_;let D=!1;const V=setTimeout(()=>D=!0,5e3);let T=0,H=!1,N=0;for(;!H&&!D;){const C=d[P+T];C==="("&&N++,C===")"&&N--,N===0&&C===")"&&(H=!0),T>d.length&&(D=!0),T++}if(!D)clearTimeout(V);else throw new Error("Failed to find the end of the styled call and timed out");const q=P+T,a=d.slice(P,q),S=d,j=` ${g} = styled(${h}, "${p.classNames}", ${JSON.stringify(p.clientProps)});`;d=d.replace(a,j),S===d&&console.error("Minimize file failed to change content",{name:g,tagName:h})}),u.importStrategy==="component"){const g=k.toHash(t,6),m=i.parse(t);d=`import '../../saltygen/css/${`f_${k.dashCase(m.name)}-${g}.css`}';
|
38
|
-
${d}`}return d=d.replace("{ styled }","{ styledClient as styled }"),d=d.replace("@salty-css/react/styled","@salty-css/react/styled-client"),d}}catch(n){console.error("Error in minimizeFile:",n)}};exports.compileSaltyFile=K;exports.generateConfigStyles=be;exports.generateCss=Re;exports.generateFile=Ve;exports.isSaltyFile=U;exports.logError=De;exports.logger=G;exports.minimizeFile=Me;exports.saltyFileExtensions=oe;exports.saltyFileRegExp=Se;
|