@salty-css/core 0.0.1-alpha.178 → 0.0.1-alpha.179
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 +3 -1
- package/compiler/index.js +1 -1
- package/config/index.cjs +1 -1
- package/config/index.js +8 -6
- package/factories/define-templates.d.ts +10 -0
- package/factories/index.cjs +1 -1
- package/factories/index.d.ts +1 -0
- package/factories/index.js +16 -5
- package/index-DZsck9Ko.cjs +29 -0
- package/index-DlLbtfD0.js +403 -0
- package/package.json +1 -1
- package/server/index.cjs +1 -1
- package/server/index.js +1 -1
- package/index-D0d8j1Jc.cjs +0 -29
- package/index-D9VggpwE.js +0 -397
package/bin/main.cjs
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const te=require("commander"),G=require("fs"),s=require("fs/promises"),n=require("path"),ne=require("ejs"),t=require("../index-
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const te=require("commander"),G=require("fs"),s=require("fs/promises"),n=require("path"),ne=require("ejs"),t=require("../index-DZsck9Ko.cjs"),ie=require("../pascal-case-iWoaJWwT.cjs"),se=require("child_process"),oe=require("ora");var z=typeof document<"u"?document.currentScript:null;const X=y=>new Promise((C,P)=>{se.exec(y,F=>{if(F)return P(F);C()})}),I=async(...y)=>{const C=y.map(b=>b.replace("-D","").split("@").slice(0,-1).join("@").trim()).join(", "),P=oe(`Installing packages: ${C}`).start(),F=y.join(" ");await X(`npm install ${F}`),P.succeed(`Installed packages: ${C}`)},ae=()=>G.existsSync(n.join(process.cwd(),"node_modules",".bin","prettier"));async function S(y){try{if(!ae())return;await X(`./node_modules/.bin/prettier --write "${y}"`),t.logger.info(`Formatted ${y} with Prettier`)}catch(C){t.logger.error(`Error formatting ${y} with Prettier:`,C)}}async function re(){const y=new te.Command;y.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");const C={"salty.config.ts":Promise.resolve().then(()=>require("../salty.config-Dk6ZcCxI.cjs")),"saltygen/index.css":Promise.resolve().then(()=>require("../index-84Wroia-.cjs")),"react/react-styled-file.ts":Promise.resolve().then(()=>require("../react-styled-file-Dkubsz-U.cjs")),"react/react-vanilla-file.ts":Promise.resolve().then(()=>require("../react-vanilla-file-CG_WJLam.cjs"))},P=async(i,a)=>{const{default:l}=await C[i],u=ne.render(l,a);return{fileName:i,content:u}},F=async()=>{const i=n.join(process.cwd(),".saltyrc.json");return await s.readFile(i,"utf-8").then(JSON.parse).catch(()=>({}))},b=n.join(process.cwd(),"package.json"),N=async(i=b)=>{const a=await s.readFile(i,"utf-8").then(JSON.parse).catch(()=>{});if(!a)throw"Could not read package.json file!";return a},Y=async(i,a=b)=>{typeof i=="object"&&(i=JSON.stringify(i,null,2)),await s.writeFile(a,i)},B=async()=>{const i=new URL("../package.json",typeof document>"u"?require("url").pathToFileURL(__filename).href:z&&z.tagName.toUpperCase()==="SCRIPT"&&z.src||new URL("bin/main.cjs",document.baseURI).href);return N(i)},V=await(async()=>(await F()).defaultProject)(),$=await B(),D={core:`@salty-css/core@${$.version}`,react:`@salty-css/react@${$.version}`,eslintConfigCore:`@salty-css/eslint-config-core@${$.version}`,vite:`@salty-css/vite@${$.version}`,next:`@salty-css/next@${$.version}`},R=i=>{const a=i==="."?"":i,l=process.cwd();return n.join(l,a)};y.command("init [directory]").description("Initialize a new Salty-CSS project.").option("-d, --dir <dir>","Project directory to initialize the project in.").option("--css-file <css-file>","Existing CSS file where to import the generated CSS. Path must be relative to the given project directory.").option("--skip-install","Skip installing dependencies.").action(async function(i="."){if(!await N().catch(()=>{}))return t.logError("Salty CSS project must be initialized in a directory with a package.json file.");t.logger.info("Initializing a new Salty-CSS project!");const{dir:l=i,cssFile:u,skipInstall:p}=this.opts();if(!l)return t.logError("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");p||await I(D.core,D.react);const f=process.cwd(),r=R(l),T=await Promise.all([P("salty.config.ts"),P("saltygen/index.css")]);await s.mkdir(r,{recursive:!0});const m=T.map(async({fileName:e,content:g})=>{const c=n.join(r,e);if(await s.readFile(c,"utf-8").catch(()=>{})!==void 0){t.logger.debug("File already exists: "+c);return}const k=e.split("/").slice(0,-1).join("/");k&&await s.mkdir(n.join(r,k),{recursive:!0}),t.logger.info("Creating file: "+c),await s.writeFile(c,g),await S(c)});await Promise.all(m);const w=n.relative(f,r)||".",h=n.join(f,".saltyrc.json"),d=await s.readFile(h,"utf-8").catch(()=>{});if(d===void 0){t.logger.info("Creating file: "+h);const g=JSON.stringify({$schema:"./node_modules/@salty-css/core/.saltyrc.schema.json",info:"This file is used to define projects and their configurations for Salty CSS cli. Do not delete, modify or add this file to .gitignore.",defaultProject:w,projects:[{dir:w,framework:"react"}]},null,2);await s.writeFile(h,g),await S(h)}else{const e=JSON.parse(d),g=(e==null?void 0:e.projects)||[];if(g.findIndex(o=>o.dir===w)===-1){g.push({dir:w,framework:"react"}),e.projects=[...g];const o=JSON.stringify(e,null,2);o!==d&&(t.logger.info("Edit file: "+h),await s.writeFile(h,o),await S(h))}}const j=n.join(f,".gitignore"),U=await s.readFile(j,"utf-8").catch(()=>{});U!==void 0&&(U.includes("saltygen")||(t.logger.info("Edit file: "+j),await s.writeFile(j,U+`
|
2
2
|
|
3
3
|
# Salty-CSS
|
4
4
|
saltygen
|
package/bin/main.js
CHANGED
@@ -3,7 +3,7 @@ import { existsSync as K } from "fs";
|
|
3
3
|
import { mkdir as q, readFile as C, writeFile as w } from "fs/promises";
|
4
4
|
import { join as i, relative as z, parse as re, format as ee } from "path";
|
5
5
|
import { render as ce } from "ejs";
|
6
|
-
import { l as t, a as h, g as te } from "../index-
|
6
|
+
import { l as t, a as h, g as te } from "../index-DlLbtfD0.js";
|
7
7
|
import { p as le } from "../pascal-case-BQpR5PdN.js";
|
8
8
|
import { exec as de } from "child_process";
|
9
9
|
import fe from "ora";
|
package/compiler/index.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("esbuild");require("child_process");require("../dash-case-BJEkFEGQ.cjs");require("path");require("fs");require("fs/promises");require("../parse-styles-3zK35muR.cjs");require("../parse-templates-VIvmVb52.cjs");const e=require("../index-
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("esbuild");require("child_process");require("../dash-case-BJEkFEGQ.cjs");require("path");require("fs");require("fs/promises");require("../parse-styles-3zK35muR.cjs");require("../parse-templates-VIvmVb52.cjs");const e=require("../index-DZsck9Ko.cjs");require("../merge-DxGoJDHv.cjs");exports.compileSaltyFile=e.compileSaltyFile;exports.generateConfigStyles=e.generateConfigStyles;exports.generateCss=e.generateCss;exports.generateFile=e.generateFile;exports.isSaltyFile=e.isSaltyFile;exports.minimizeFile=e.minimizeFile;exports.saltyFileExtensions=e.saltyFileExtensions;exports.saltyFileRegExp=e.saltyFileRegExp;
|
package/compiler/index.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { StyleComponentGenerator } from '../generator/style-generator';
|
2
2
|
import { MediaQueryFactory } from '../css/media';
|
3
|
-
import { GlobalStylesFactory, VariablesFactory } from '../factories';
|
3
|
+
import { GlobalStylesFactory, TemplatesFactory, VariablesFactory } from '../factories';
|
4
4
|
interface GeneratorResult<V extends object> {
|
5
5
|
value: V;
|
6
6
|
src: string;
|
@@ -15,6 +15,7 @@ interface GenerationResults {
|
|
15
15
|
mediaQueries: MediaQueryFactory[];
|
16
16
|
globalStyles: GlobalStylesFactory[];
|
17
17
|
variables: VariablesFactory[];
|
18
|
+
templates: TemplatesFactory[];
|
18
19
|
}
|
19
20
|
export declare const saltyFileExtensions: string[];
|
20
21
|
export declare const saltyFileRegExp: (additional?: string[]) => RegExp;
|
@@ -26,6 +27,7 @@ export declare const compileSaltyFile: (dirname: string, sourceFilePath: string,
|
|
26
27
|
isMedia?: boolean;
|
27
28
|
isGlobalDefine?: boolean;
|
28
29
|
isDefineVariables?: boolean;
|
30
|
+
isDefineTemplates?: boolean;
|
29
31
|
isKeyframes?: boolean;
|
30
32
|
animationName?: string;
|
31
33
|
css?: string;
|
package/compiler/index.js
CHANGED
@@ -6,7 +6,7 @@ import "fs";
|
|
6
6
|
import "fs/promises";
|
7
7
|
import "../parse-styles-DrLhKtqW.js";
|
8
8
|
import "../parse-templates-DRKlN-pP.js";
|
9
|
-
import { d as g, c as F, g as y, e as x, i as S, m as c, s as f, b as C } from "../index-
|
9
|
+
import { d as g, c as F, g as y, e as x, i as S, m as c, s as f, b as C } from "../index-DlLbtfD0.js";
|
10
10
|
import "../merge-BVm9us1A.js";
|
11
11
|
export {
|
12
12
|
g as compileSaltyFile,
|
package/config/index.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../factories/index.cjs"),a
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../factories/index.cjs"),i=a=>a;exports.GlobalStylesFactory=e.GlobalStylesFactory;exports.TemplatesFactory=e.TemplatesFactory;exports.VariablesFactory=e.VariablesFactory;exports.defineConditionalVariables=e.defineConditionalVariables;exports.defineGlobalStyles=e.defineGlobalStyles;exports.defineResponsiveVariables=e.defineResponsiveVariables;exports.defineStaticVariables=e.defineStaticVariables;exports.defineTemplates=e.defineTemplates;exports.defineVariables=e.defineVariables;exports.defineConfig=i;
|
package/config/index.js
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
-
import { GlobalStylesFactory as n, VariablesFactory as o, defineConditionalVariables as r, defineGlobalStyles as
|
1
|
+
import { GlobalStylesFactory as t, TemplatesFactory as n, VariablesFactory as o, defineConditionalVariables as r, defineGlobalStyles as s, defineResponsiveVariables as f, defineStaticVariables as d, defineTemplates as b, defineVariables as c } from "../factories/index.js";
|
2
2
|
const a = (e) => e;
|
3
3
|
export {
|
4
|
-
|
4
|
+
t as GlobalStylesFactory,
|
5
|
+
n as TemplatesFactory,
|
5
6
|
o as VariablesFactory,
|
6
7
|
r as defineConditionalVariables,
|
7
8
|
a as defineConfig,
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
b as
|
9
|
+
s as defineGlobalStyles,
|
10
|
+
f as defineResponsiveVariables,
|
11
|
+
d as defineStaticVariables,
|
12
|
+
b as defineTemplates,
|
13
|
+
c as defineVariables
|
12
14
|
};
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { CssTemplates } from '../types/config-types';
|
2
|
+
export interface TemplatesFactoryParams {
|
3
|
+
templates?: CssTemplates;
|
4
|
+
}
|
5
|
+
export declare class TemplatesFactory {
|
6
|
+
_current: TemplatesFactoryParams;
|
7
|
+
constructor(_current: TemplatesFactoryParams);
|
8
|
+
get isDefineTemplates(): boolean;
|
9
|
+
}
|
10
|
+
export declare const defineTemplates: (templates: CssTemplates) => TemplatesFactory;
|
package/factories/index.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class n{constructor(
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class n{constructor(t){this._current=t}get isGlobalDefine(){return!0}}const s=e=>new n(e);class r{constructor(t){this._current=t}get isDefineVariables(){return!0}}const i=e=>new r(e),l=e=>new r({variables:e}),o=e=>new r({responsiveVariables:e}),c=e=>new r({conditionalVariables:e});class a{constructor(t){this._current=t}get isDefineTemplates(){return!0}}const u=e=>new a(e);exports.GlobalStylesFactory=n;exports.TemplatesFactory=a;exports.VariablesFactory=r;exports.defineConditionalVariables=c;exports.defineGlobalStyles=s;exports.defineResponsiveVariables=o;exports.defineStaticVariables=l;exports.defineTemplates=u;exports.defineVariables=i;
|
package/factories/index.d.ts
CHANGED
package/factories/index.js
CHANGED
@@ -6,7 +6,7 @@ class n {
|
|
6
6
|
return !0;
|
7
7
|
}
|
8
8
|
}
|
9
|
-
const
|
9
|
+
const a = (e) => new n(e);
|
10
10
|
class r {
|
11
11
|
constructor(t) {
|
12
12
|
this._current = t;
|
@@ -15,13 +15,24 @@ class r {
|
|
15
15
|
return !0;
|
16
16
|
}
|
17
17
|
}
|
18
|
-
const
|
18
|
+
const i = (e) => new r(e), c = (e) => new r({ variables: e }), o = (e) => new r({ responsiveVariables: e }), l = (e) => new r({ conditionalVariables: e });
|
19
|
+
class s {
|
20
|
+
constructor(t) {
|
21
|
+
this._current = t;
|
22
|
+
}
|
23
|
+
get isDefineTemplates() {
|
24
|
+
return !0;
|
25
|
+
}
|
26
|
+
}
|
27
|
+
const u = (e) => new s(e);
|
19
28
|
export {
|
20
29
|
n as GlobalStylesFactory,
|
30
|
+
s as TemplatesFactory,
|
21
31
|
r as VariablesFactory,
|
22
32
|
l as defineConditionalVariables,
|
23
|
-
|
33
|
+
a as defineGlobalStyles,
|
24
34
|
o as defineResponsiveVariables,
|
25
|
-
|
26
|
-
|
35
|
+
c as defineStaticVariables,
|
36
|
+
u as defineTemplates,
|
37
|
+
i as defineVariables
|
27
38
|
};
|
@@ -0,0 +1,29 @@
|
|
1
|
+
"use strict";const ue=require("esbuild"),ye=require("child_process"),_=require("./dash-case-BJEkFEGQ.cjs"),o=require("path"),r=require("fs"),Q=require("fs/promises"),A=require("./parse-styles-3zK35muR.cjs"),te=require("./parse-templates-VIvmVb52.cjs"),z=require("winston"),q=require("./merge-DxGoJDHv.cjs");var U=typeof document<"u"?document.currentScript:null;function ge(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const c=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,c.get?c:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const ne=ge(ue),oe=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=o.join(e,"package.json");return r.existsSync(t)?t:oe(o.join(e,".."))},me=async e=>{const t=oe(e);return await Q.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},he=async e=>{const t=await me(e);if(t)return t.type};let R;const re=async e=>{if(R)return R;const t=await he(e);return t==="module"?R="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:U&&U.tagName.toUpperCase()==="SCRIPT"&&U.src||new URL("index-DZsck9Ko.cjs",document.baseURI).href).endsWith(".cjs"))&&(R="cjs"),R||"esm"},H=z.createLogger({level:"debug",format:z.format.combine(z.format.colorize(),z.format.cli()),transports:[new z.transports.Console({})]}),Se=e=>{H.error(e)};function ie(e){return e?typeof e!="string"?ie(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 be={"*, *::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"}},E={externalModules:[],rcFile:void 0,destDir:void 0},ae=e=>{if(E.externalModules.length>0)return E.externalModules;const s=r.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const c=s[1].split(",").map(f=>f.replace(/['"`]/g,"").trim());return E.externalModules=c,c},v=async e=>{if(E.destDir)return E.destDir;const t=await Y(e),s=o.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return E.destDir=s,s},X=["salty","css","styles","styled"],ce=(e=[])=>new RegExp(`\\.(${[...X,...e].join("|")})\\.`),W=(e,t=[])=>ce(t).test(e),le=async e=>{if(E.rcFile)return E.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=o.join(e,".saltyrc.json"),s=await Q.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(E.rcFile=s,s):le(o.join(e,".."))},Y=async e=>{var c,f;const t=await le(e),s=(c=t.projects)==null?void 0:c.find(n=>e.endsWith(n.dir||""));return s||((f=t.projects)==null?void 0:f.find(n=>n.dir===t.defaultProject))},je=async e=>{const t=await Y(e),s=await v(e),c=o.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),f=o.join(s,"salty.config.js"),n=await re(e),w=ae(c);await ne.build({entryPoints:[c],minify:!0,treeShaking:!0,bundle:!0,outfile:f,format:n,external:w});const m=Date.now(),{config:a}=await import(`${f}?t=${m}`);return a},fe=async(e,t)=>{const s=await je(e),c={...s},f=new Set,n=($,j=[])=>$?Object.entries($).flatMap(([P,k])=>{if(!k)return;if(typeof k=="object")return n(k,[...j,P]);const L=ie(P),B=_.dashCase(P),K=[...j,L].join(".");f.add(`"${K}"`);const Z=[...j.map(_.dashCase),B].join("-"),{result:pe}=A.parseValueTokens(k);return`--${Z}: ${pe};`}):[],w=$=>$?Object.entries($).flatMap(([j,P])=>{const k=n(P);return j==="base"?k.join(""):`${j} { ${k.join("")} }`}):[],m=$=>$?Object.entries($).flatMap(([j,P])=>Object.entries(P).flatMap(([k,L])=>{const B=n(L,[j]),K=`.${j}-${k}, [data-${j}="${k}"]`,Z=B.join("");return`${K} { ${Z} }`})):[],a=$=>t.variables.map(j=>j._current[$]),i=n(q.mergeStyles(s.variables,a("variables"))),d=w(q.mergeStyles(s.responsiveVariables,a("responsiveVariables"))),u=m(q.mergeStyles(s.conditionalVariables,a("conditionalVariables"))),h=await v(e),D=o.join(h,"css/_variables.css"),C=`:root { ${i.join("")} ${d.join("")} } ${u.join("")}`;r.writeFileSync(D,C);const M=o.join(h,"css/_global.css"),x=q.mergeStyles(s.global,t.globalStyles),T=A.parseStyles(x,"");r.writeFileSync(M,`@layer global { ${T} }`);const N=o.join(h,"css/_reset.css"),l=s.reset==="none"?{}:typeof s.reset=="object"?s.reset:be,S=A.parseStyles(l,"");r.writeFileSync(N,`@layer reset { ${S} }`);const F=o.join(h,"css/_templates.css"),g=q.mergeStyles(s.templates,t.templates);console.log("all",g);const y=te.parseTemplates(g),b=te.getTemplateTypes(g);r.writeFileSync(F,y),c.templates=g;const p=o.join(h,"types/css-tokens.d.ts"),J=`
|
2
|
+
// Variable types
|
3
|
+
type VariableTokens = ${[...f].join("|")};
|
4
|
+
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
5
|
+
|
6
|
+
// Template types
|
7
|
+
type TemplateTokens = {
|
8
|
+
${Object.entries(b).map(([$,j])=>`${$}?: ${j}`).join(`
|
9
|
+
`)}
|
10
|
+
}
|
11
|
+
`;r.writeFileSync(p,J);const I=o.join(h,"cache/config-cache.json");r.writeFileSync(I,JSON.stringify(c,null,2))},se=e=>e.replace(/styled\(([^"'`{,]+),/g,(t,s)=>{if(/^['"`]/.test(s))return t;const f=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!f.test(e))return t;const w=f.exec(e);if(w){const m=w.at(1);if(X.some(i=>m==null?void 0:m.includes(i)))return t}return"styled('div',"}),G=async(e,t,s)=>{const c=_.toHash(t),f=o.join(s,"./temp");r.existsSync(f)||r.mkdirSync(f);const n=o.parse(t);let w=r.readFileSync(t,"utf8");w=se(w);const m=o.join(s,"js",c+".js"),a=await Y(e),i=o.join(e,(a==null?void 0:a.configDir)||"","salty.config.ts"),d=ae(i),u=await re(e);await ne.build({stdin:{contents:w,sourcefile:n.base,resolveDir:n.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:m,format:u,target:["node20"],keepNames:!0,external:d,packages:"external",plugins:[{name:"test",setup:C=>{C.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},M=>{const x=r.readFileSync(M.path,"utf8");return{contents:se(x),loader:"ts"}})}}]});const h=Date.now();return await import(`${m}?t=${h}`)},ee=async e=>{const t=await v(e),s=o.join(t,"cache/config-cache.json"),c=r.readFileSync(s,"utf8");if(!c)throw new Error("Could not find config cache file");return JSON.parse(c)},de=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},we=async(e,t=de())=>{try{const s=Date.now();t?H.info("Generating CSS in production mode! 🔥"):H.info("Generating CSS in development mode! 🚀");const c=[],f=[],n=await v(e),w=o.join(n,"index.css");(()=>{r.existsSync(n)&&ye.execSync("rm -rf "+n),r.mkdirSync(n,{recursive:!0}),r.mkdirSync(o.join(n,"css")),r.mkdirSync(o.join(n,"types")),r.mkdirSync(o.join(n,"js")),r.mkdirSync(o.join(n,"cache"))})();const a={keyframes:[],mediaQueries:[],globalStyles:[],variables:[],components:[],templates:[]};async function i(l){const S=["node_modules","saltygen"],F=r.statSync(l);if(F.isDirectory()){const g=r.readdirSync(l);if(S.some(b=>l.includes(b)))return;await Promise.all(g.map(b=>i(o.join(l,b))))}else if(F.isFile()&&W(l)){const y=await G(e,l,n);Object.entries(y).forEach(([b,p])=>{p.isKeyframes?a.keyframes.push({value:p,src:l,name:b}):p.isMedia?a.mediaQueries.push(p):p.isGlobalDefine?a.globalStyles.push(p):p.isDefineVariables?a.variables.push(p):p.isDefineTemplates?a.templates.push(p):p.generator&&a.components.push({value:p.generator,src:l,name:b})})}}await i(e),await fe(e,a);const d=await ee(e);for(const l of a.keyframes){const{value:S}=l,F=`a_${S.animationName}.css`,g=`css/${F}`,y=o.join(n,g);c.push(F),r.writeFileSync(y,S.css)}const u={};for(const l of a.components){const{value:S,name:F,src:g}=l,y=S._withBuildContext({name:F,config:d,prod:t});f[y.priority]||(f[y.priority]=[]),f[y.priority].push(y.cssFileName),d.importStrategy==="component"&&(u[g]?u[g].push(y.cssFileName):u[g]=[y.cssFileName]);const b=`css/${y.cssFileName}`,p=o.join(n,b);r.writeFileSync(p,y.css)}d.importStrategy==="component"&&Object.entries(u).forEach(([l,S])=>{const F=S.map(O=>`@import url('./${O}');`).join(`
|
12
|
+
`),g=_.toHash(l,6),y=o.parse(l),b=_.dashCase(y.name),p=o.join(n,`css/f_${b}-${g}.css`);r.writeFileSync(p,F)});const h=c.map(l=>`@import url('./css/${l}');`).join(`
|
13
|
+
`);let x=`@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
14
|
+
|
15
|
+
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(l=>{try{return r.readFileSync(o.join(n,"css",l),"utf8").length>0}catch{return!1}}).map(l=>`@import url('./css/${l}');`).join(`
|
16
|
+
`)}
|
17
|
+
${h}`;if(d.importStrategy!=="component"){const l=f.reduce((S,F,g)=>{const y=F.reduce((J,I)=>{var k;const $=o.join(n,"css",I),j=r.readFileSync($,"utf8"),P=((k=/.*-([^-]+)-\d+.css/.exec(I))==null?void 0:k.at(1))||_.toHash($,6);return J.includes(P)?J:`${J}
|
18
|
+
/*start:${P}*/
|
19
|
+
${j}
|
20
|
+
/*end:${P}*/
|
21
|
+
`},""),b=`l_${g}.css`,p=o.join(n,"css",b),O=`@layer l${g} { ${y}
|
22
|
+
}`;return r.writeFileSync(p,O),`${S}
|
23
|
+
@import url('./css/${b}');`},"");x+=l}r.writeFileSync(w,x);const N=Date.now()-s,V=N<200?"🔥":N<500?"🚀":N<1e3?"🎉":N<2e3?"🚗":N<5e3?"🤔":"🥴";H.info(`Generated CSS in ${N}ms! ${V}`)}catch(s){console.error(s)}},Fe=async(e,t)=>{try{const s=await v(e);if(W(t)){const f=[],n=await ee(e),w=await G(e,t,s);Object.entries(w).forEach(([m,a])=>{if(a.isKeyframes&&a.css){const D=`css/${`a_${a.animationName}.css`}`,C=o.join(s,D);r.writeFileSync(C,a.css);return}if(!a.generator)return;const i=a.generator._withBuildContext({name:m,config:n}),d=`css/${i.cssFileName}`,u=o.join(s,d);r.writeFileSync(u,i.css),f[i.priority]||(f[i.priority]=[]),f[i.priority].push(i.cssFileName)}),n.importStrategy!=="component"&&f.forEach((m,a)=>{const i=`l_${a}.css`,d=o.join(s,"css",i);let u=r.readFileSync(d,"utf8");m.forEach(h=>{var x;const D=o.join(s,"css",h),C=((x=/.*-([^-]+)-\d+.css/.exec(h))==null?void 0:x.at(1))||_.toHash(D,6);if(!u.includes(C)){const T=r.readFileSync(D,"utf8"),N=`/*start:${C}*/
|
24
|
+
${T}
|
25
|
+
/*end:${C}*/
|
26
|
+
`;u=`${u.replace(/\}$/,"")}
|
27
|
+
${N}
|
28
|
+
}`}}),r.writeFileSync(d,u)})}}catch(s){console.error(s)}},$e=async(e,t,s=de())=>{try{const c=await v(e);if(W(t)){const n=r.readFileSync(t,"utf8");n.replace(/^(?!export\s)const\s.*/gm,d=>`export ${d}`)!==n&&await Q.writeFile(t,n);const m=await ee(e),a=await G(e,t,c);let i=n;if(Object.entries(a).forEach(([d,u])=>{var p;if(u.isKeyframes||!u.generator)return;const h=u.generator._withBuildContext({name:d,config:m,prod:s}),D=new RegExp(`\\s${d}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(n);if(!D)return console.error("Could not find the original declaration");const C=(p=D.at(1))==null?void 0:p.trim(),M=new RegExp(`\\s${d}[=\\s]+styled\\(`,"g").exec(i);if(!M)return console.error("Could not find the original declaration");const{index:x}=M;let T=!1;const N=setTimeout(()=>T=!0,5e3);let V=0,l=!1,S=0;for(;!l&&!T;){const O=i[x+V];O==="("&&S++,O===")"&&S--,S===0&&O===")"&&(l=!0),V>i.length&&(T=!0),V++}if(!T)clearTimeout(N);else throw new Error("Failed to find the end of the styled call and timed out");const F=x+V,g=i.slice(x,F),y=i,b=` ${d} = styled(${C}, "${h.classNames}", ${JSON.stringify(h.props)});`;i=i.replace(g,b),y===i&&console.error("Minimize file failed to change content",{name:d,tagName:C})}),m.importStrategy==="component"){const d=_.toHash(t,6),u=o.parse(t);i=`import '../../saltygen/css/${`f_${_.dashCase(u.name)}-${d}.css`}';
|
29
|
+
${i}`}return i=i.replace("{ styled }","{ styledClient as styled }"),i=i.replace("@salty-css/react/styled","@salty-css/react/styled-client"),i}}catch(c){console.error("Error in minimizeFile:",c)}};exports.compileSaltyFile=G;exports.generateConfigStyles=fe;exports.generateCss=we;exports.generateFile=Fe;exports.isSaltyFile=W;exports.logError=Se;exports.logger=H;exports.minimizeFile=$e;exports.saltyFileExtensions=X;exports.saltyFileRegExp=ce;
|
@@ -0,0 +1,403 @@
|
|
1
|
+
import * as oe from "esbuild";
|
2
|
+
import { execSync as me } from "child_process";
|
3
|
+
import { t as I, d as B } from "./dash-case-DBThphLm.js";
|
4
|
+
import { join as r, parse as q } from "path";
|
5
|
+
import { existsSync as U, writeFileSync as F, mkdirSync as J, readFileSync as V, statSync as ge, readdirSync as ye } from "fs";
|
6
|
+
import { readFile as re, writeFile as he } from "fs/promises";
|
7
|
+
import { p as se, a as be } from "./parse-styles-DrLhKtqW.js";
|
8
|
+
import { p as $e, a as Se } from "./parse-templates-DRKlN-pP.js";
|
9
|
+
import { createLogger as we, format as Q, transports as Ce } from "winston";
|
10
|
+
import { m as W } from "./merge-BVm9us1A.js";
|
11
|
+
const ae = (e) => {
|
12
|
+
if (!e || e === "/") throw new Error("Could not find package.json file");
|
13
|
+
const t = r(e, "package.json");
|
14
|
+
return U(t) ? t : ae(r(e, ".."));
|
15
|
+
}, Fe = async (e) => {
|
16
|
+
const t = ae(e);
|
17
|
+
return await re(t, "utf-8").then(JSON.parse).catch(() => {
|
18
|
+
});
|
19
|
+
}, xe = async (e) => {
|
20
|
+
const t = await Fe(e);
|
21
|
+
if (t)
|
22
|
+
return t.type;
|
23
|
+
};
|
24
|
+
let O;
|
25
|
+
const ie = async (e) => {
|
26
|
+
if (O) return O;
|
27
|
+
const t = await xe(e);
|
28
|
+
return t === "module" ? O = "esm" : (t === "commonjs" || import.meta.url.endsWith(".cjs")) && (O = "cjs"), O || "esm";
|
29
|
+
}, H = we({
|
30
|
+
level: "debug",
|
31
|
+
format: Q.combine(Q.colorize(), Q.cli()),
|
32
|
+
transports: [new Ce.Console({})]
|
33
|
+
}), Re = (e) => {
|
34
|
+
H.error(e);
|
35
|
+
};
|
36
|
+
function ce(e) {
|
37
|
+
return e ? typeof e != "string" ? ce(String(e)) : e.replace(/[\s-]/g, ".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (t, s) => (s > 0 ? "." : "") + t.toLowerCase()) : "";
|
38
|
+
}
|
39
|
+
const je = {
|
40
|
+
/** Set box model to border-box */
|
41
|
+
"*, *::before, *::after": {
|
42
|
+
boxSizing: "border-box"
|
43
|
+
},
|
44
|
+
/** Remove default margin and padding */
|
45
|
+
"*": {
|
46
|
+
margin: 0
|
47
|
+
},
|
48
|
+
/** Remove adjust font properties */
|
49
|
+
html: {
|
50
|
+
lineHeight: 1.15,
|
51
|
+
textSizeAdjust: "100%",
|
52
|
+
WebkitFontSmoothing: "antialiased"
|
53
|
+
},
|
54
|
+
/** Make media elements responsive */
|
55
|
+
"img, picture, video, canvas, svg": {
|
56
|
+
display: "block",
|
57
|
+
maxWidth: "100%"
|
58
|
+
},
|
59
|
+
/** Avoid overflow of text */
|
60
|
+
"p, h1, h2, h3, h4, h5, h6": {
|
61
|
+
overflowWrap: "break-word"
|
62
|
+
},
|
63
|
+
/** Improve text wrapping */
|
64
|
+
p: {
|
65
|
+
textWrap: "pretty"
|
66
|
+
},
|
67
|
+
"h1, h2, h3, h4, h5, h6": {
|
68
|
+
textWrap: "balance"
|
69
|
+
},
|
70
|
+
/** Improve link color */
|
71
|
+
a: {
|
72
|
+
color: "currentColor"
|
73
|
+
},
|
74
|
+
/** Improve button line height */
|
75
|
+
button: {
|
76
|
+
lineHeight: "1em",
|
77
|
+
color: "currentColor"
|
78
|
+
},
|
79
|
+
/** Improve form elements */
|
80
|
+
"input, optgroup, select, textarea": {
|
81
|
+
fontFamily: "inherit",
|
82
|
+
fontSize: "100%",
|
83
|
+
lineHeight: "1.15em"
|
84
|
+
}
|
85
|
+
}, E = {
|
86
|
+
externalModules: [],
|
87
|
+
rcFile: void 0,
|
88
|
+
destDir: void 0
|
89
|
+
}, le = (e) => {
|
90
|
+
if (E.externalModules.length > 0) return E.externalModules;
|
91
|
+
const s = V(e, "utf8").match(/externalModules:\s?\[(.*)\]/);
|
92
|
+
if (!s) return [];
|
93
|
+
const l = s[1].split(",").map((c) => c.replace(/['"`]/g, "").trim());
|
94
|
+
return E.externalModules = l, l;
|
95
|
+
}, R = async (e) => {
|
96
|
+
if (E.destDir) return E.destDir;
|
97
|
+
const t = await Y(e), s = r(e, (t == null ? void 0 : t.saltygenDir) || "saltygen");
|
98
|
+
return E.destDir = s, s;
|
99
|
+
}, fe = ["salty", "css", "styles", "styled"], ke = (e = []) => new RegExp(`\\.(${[...fe, ...e].join("|")})\\.`), X = (e, t = []) => ke(t).test(e), pe = async (e) => {
|
100
|
+
if (E.rcFile) return E.rcFile;
|
101
|
+
if (e === "/") throw new Error("Could not find .saltyrc.json file");
|
102
|
+
const t = r(e, ".saltyrc.json"), s = await re(t, "utf-8").then(JSON.parse).catch(() => {
|
103
|
+
});
|
104
|
+
return s ? (E.rcFile = s, s) : pe(r(e, ".."));
|
105
|
+
}, Y = async (e) => {
|
106
|
+
var l, c;
|
107
|
+
const t = await pe(e), s = (l = t.projects) == null ? void 0 : l.find((n) => e.endsWith(n.dir || ""));
|
108
|
+
return s || ((c = t.projects) == null ? void 0 : c.find((n) => n.dir === t.defaultProject));
|
109
|
+
}, De = async (e) => {
|
110
|
+
const t = await Y(e), s = await R(e), l = r(e, (t == null ? void 0 : t.configDir) || "", "salty.config.ts"), c = r(s, "salty.config.js"), n = await ie(e), S = le(l);
|
111
|
+
await oe.build({
|
112
|
+
entryPoints: [l],
|
113
|
+
minify: !0,
|
114
|
+
treeShaking: !0,
|
115
|
+
bundle: !0,
|
116
|
+
outfile: c,
|
117
|
+
format: n,
|
118
|
+
external: S
|
119
|
+
});
|
120
|
+
const g = Date.now(), { config: a } = await import(`${c}?t=${g}`);
|
121
|
+
return a;
|
122
|
+
}, Ne = async (e, t) => {
|
123
|
+
const s = await De(e), l = { ...s }, c = /* @__PURE__ */ new Set(), n = (C, $ = []) => C ? Object.entries(C).flatMap(([P, k]) => {
|
124
|
+
if (!k) return;
|
125
|
+
if (typeof k == "object") return n(k, [...$, P]);
|
126
|
+
const K = ce(P), L = B(P), Z = [...$, K].join(".");
|
127
|
+
c.add(`"${Z}"`);
|
128
|
+
const A = [...$.map(B), L].join("-"), { result: ue } = be(k);
|
129
|
+
return `--${A}: ${ue};`;
|
130
|
+
}) : [], S = (C) => C ? Object.entries(C).flatMap(([$, P]) => {
|
131
|
+
const k = n(P);
|
132
|
+
return $ === "base" ? k.join("") : `${$} { ${k.join("")} }`;
|
133
|
+
}) : [], g = (C) => C ? Object.entries(C).flatMap(([$, P]) => Object.entries(P).flatMap(([k, K]) => {
|
134
|
+
const L = n(K, [$]), Z = `.${$}-${k}, [data-${$}="${k}"]`, A = L.join("");
|
135
|
+
return `${Z} { ${A} }`;
|
136
|
+
})) : [], a = (C) => t.variables.map(($) => $._current[C]), o = n(W(s.variables, a("variables"))), f = S(W(s.responsiveVariables, a("responsiveVariables"))), d = g(W(s.conditionalVariables, a("conditionalVariables"))), y = await R(e), D = r(y, "css/_variables.css"), x = `:root { ${o.join("")} ${f.join("")} } ${d.join("")}`;
|
137
|
+
F(D, x);
|
138
|
+
const _ = r(y, "css/_global.css"), j = W(s.global, t.globalStyles), T = se(j, "");
|
139
|
+
F(_, `@layer global { ${T} }`);
|
140
|
+
const N = r(y, "css/_reset.css"), i = s.reset === "none" ? {} : typeof s.reset == "object" ? s.reset : je, h = se(i, "");
|
141
|
+
F(N, `@layer reset { ${h} }`);
|
142
|
+
const w = r(y, "css/_templates.css"), m = W(s.templates, t.templates);
|
143
|
+
console.log("all", m);
|
144
|
+
const u = $e(m), b = Se(m);
|
145
|
+
F(w, u), l.templates = m;
|
146
|
+
const p = r(y, "types/css-tokens.d.ts"), z = `
|
147
|
+
// Variable types
|
148
|
+
type VariableTokens = ${[...c].join("|")};
|
149
|
+
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
150
|
+
|
151
|
+
// Template types
|
152
|
+
type TemplateTokens = {
|
153
|
+
${Object.entries(b).map(([C, $]) => `${C}?: ${$}`).join(`
|
154
|
+
`)}
|
155
|
+
}
|
156
|
+
`;
|
157
|
+
F(p, z);
|
158
|
+
const G = r(y, "cache/config-cache.json");
|
159
|
+
F(G, JSON.stringify(l, null, 2));
|
160
|
+
}, ne = (e) => e.replace(/styled\(([^"'`{,]+),/g, (t, s) => {
|
161
|
+
if (/^['"`]/.test(s)) return t;
|
162
|
+
const c = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
|
163
|
+
if (!c.test(e)) return t;
|
164
|
+
const S = c.exec(e);
|
165
|
+
if (S) {
|
166
|
+
const g = S.at(1);
|
167
|
+
if (fe.some((o) => g == null ? void 0 : g.includes(o))) return t;
|
168
|
+
}
|
169
|
+
return "styled('div',";
|
170
|
+
}), ee = async (e, t, s) => {
|
171
|
+
const l = I(t), c = r(s, "./temp");
|
172
|
+
U(c) || J(c);
|
173
|
+
const n = q(t);
|
174
|
+
let S = V(t, "utf8");
|
175
|
+
S = ne(S);
|
176
|
+
const g = r(s, "js", l + ".js"), a = await Y(e), o = r(e, (a == null ? void 0 : a.configDir) || "", "salty.config.ts"), f = le(o), d = await ie(e);
|
177
|
+
await oe.build({
|
178
|
+
stdin: {
|
179
|
+
contents: S,
|
180
|
+
sourcefile: n.base,
|
181
|
+
resolveDir: n.dir,
|
182
|
+
loader: "tsx"
|
183
|
+
},
|
184
|
+
minify: !1,
|
185
|
+
treeShaking: !0,
|
186
|
+
bundle: !0,
|
187
|
+
outfile: g,
|
188
|
+
format: d,
|
189
|
+
target: ["node20"],
|
190
|
+
keepNames: !0,
|
191
|
+
external: f,
|
192
|
+
packages: "external",
|
193
|
+
plugins: [
|
194
|
+
{
|
195
|
+
name: "test",
|
196
|
+
setup: (x) => {
|
197
|
+
x.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (_) => {
|
198
|
+
const j = V(_.path, "utf8");
|
199
|
+
return { contents: ne(j), loader: "ts" };
|
200
|
+
});
|
201
|
+
}
|
202
|
+
}
|
203
|
+
]
|
204
|
+
});
|
205
|
+
const y = Date.now();
|
206
|
+
return await import(`${g}?t=${y}`);
|
207
|
+
}, te = async (e) => {
|
208
|
+
const t = await R(e), s = r(t, "cache/config-cache.json"), l = V(s, "utf8");
|
209
|
+
if (!l) throw new Error("Could not find config cache file");
|
210
|
+
return JSON.parse(l);
|
211
|
+
}, de = () => {
|
212
|
+
try {
|
213
|
+
return process.env.NODE_ENV === "production";
|
214
|
+
} catch {
|
215
|
+
return !1;
|
216
|
+
}
|
217
|
+
}, ze = async (e, t = de()) => {
|
218
|
+
try {
|
219
|
+
const s = Date.now();
|
220
|
+
t ? H.info("Generating CSS in production mode! 🔥") : H.info("Generating CSS in development mode! 🚀");
|
221
|
+
const l = [], c = [], n = await R(e), S = r(n, "index.css");
|
222
|
+
(() => {
|
223
|
+
U(n) && me("rm -rf " + n), J(n, { recursive: !0 }), J(r(n, "css")), J(r(n, "types")), J(r(n, "js")), J(r(n, "cache"));
|
224
|
+
})();
|
225
|
+
const a = {
|
226
|
+
keyframes: [],
|
227
|
+
mediaQueries: [],
|
228
|
+
globalStyles: [],
|
229
|
+
variables: [],
|
230
|
+
components: [],
|
231
|
+
templates: []
|
232
|
+
};
|
233
|
+
async function o(i) {
|
234
|
+
const h = ["node_modules", "saltygen"], w = ge(i);
|
235
|
+
if (w.isDirectory()) {
|
236
|
+
const m = ye(i);
|
237
|
+
if (h.some((b) => i.includes(b))) return;
|
238
|
+
await Promise.all(m.map((b) => o(r(i, b))));
|
239
|
+
} else if (w.isFile() && X(i)) {
|
240
|
+
const u = await ee(e, i, n);
|
241
|
+
Object.entries(u).forEach(([b, p]) => {
|
242
|
+
p.isKeyframes ? a.keyframes.push({
|
243
|
+
value: p,
|
244
|
+
src: i,
|
245
|
+
name: b
|
246
|
+
}) : p.isMedia ? a.mediaQueries.push(p) : p.isGlobalDefine ? a.globalStyles.push(p) : p.isDefineVariables ? a.variables.push(p) : p.isDefineTemplates ? a.templates.push(p) : p.generator && a.components.push({
|
247
|
+
value: p.generator,
|
248
|
+
src: i,
|
249
|
+
name: b
|
250
|
+
});
|
251
|
+
});
|
252
|
+
}
|
253
|
+
}
|
254
|
+
await o(e), await Ne(e, a);
|
255
|
+
const f = await te(e);
|
256
|
+
for (const i of a.keyframes) {
|
257
|
+
const { value: h } = i, w = `a_${h.animationName}.css`, m = `css/${w}`, u = r(n, m);
|
258
|
+
l.push(w), F(u, h.css);
|
259
|
+
}
|
260
|
+
const d = {};
|
261
|
+
for (const i of a.components) {
|
262
|
+
const { value: h, name: w, src: m } = i, u = h._withBuildContext({
|
263
|
+
name: w,
|
264
|
+
config: f,
|
265
|
+
prod: t
|
266
|
+
});
|
267
|
+
c[u.priority] || (c[u.priority] = []), c[u.priority].push(u.cssFileName), f.importStrategy === "component" && (d[m] ? d[m].push(u.cssFileName) : d[m] = [u.cssFileName]);
|
268
|
+
const b = `css/${u.cssFileName}`, p = r(n, b);
|
269
|
+
F(p, u.css);
|
270
|
+
}
|
271
|
+
f.importStrategy === "component" && Object.entries(d).forEach(([i, h]) => {
|
272
|
+
const w = h.map((M) => `@import url('./${M}');`).join(`
|
273
|
+
`), m = I(i, 6), u = q(i), b = B(u.name), p = r(n, `css/f_${b}-${m}.css`);
|
274
|
+
F(p, w);
|
275
|
+
});
|
276
|
+
const y = l.map((i) => `@import url('./css/${i}');`).join(`
|
277
|
+
`);
|
278
|
+
let j = `@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
279
|
+
|
280
|
+
${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((i) => {
|
281
|
+
try {
|
282
|
+
return V(r(n, "css", i), "utf8").length > 0;
|
283
|
+
} catch {
|
284
|
+
return !1;
|
285
|
+
}
|
286
|
+
}).map((i) => `@import url('./css/${i}');`).join(`
|
287
|
+
`)}
|
288
|
+
${y}`;
|
289
|
+
if (f.importStrategy !== "component") {
|
290
|
+
const i = c.reduce((h, w, m) => {
|
291
|
+
const u = w.reduce((z, G) => {
|
292
|
+
var k;
|
293
|
+
const C = r(n, "css", G), $ = V(C, "utf8"), P = ((k = /.*-([^-]+)-\d+.css/.exec(G)) == null ? void 0 : k.at(1)) || I(C, 6);
|
294
|
+
return z.includes(P) ? z : `${z}
|
295
|
+
/*start:${P}*/
|
296
|
+
${$}
|
297
|
+
/*end:${P}*/
|
298
|
+
`;
|
299
|
+
}, ""), b = `l_${m}.css`, p = r(n, "css", b), M = `@layer l${m} { ${u}
|
300
|
+
}`;
|
301
|
+
return F(p, M), `${h}
|
302
|
+
@import url('./css/${b}');`;
|
303
|
+
}, "");
|
304
|
+
j += i;
|
305
|
+
}
|
306
|
+
F(S, j);
|
307
|
+
const N = Date.now() - s, v = N < 200 ? "🔥" : N < 500 ? "🚀" : N < 1e3 ? "🎉" : N < 2e3 ? "🚗" : N < 5e3 ? "🤔" : "🥴";
|
308
|
+
H.info(`Generated CSS in ${N}ms! ${v}`);
|
309
|
+
} catch (s) {
|
310
|
+
console.error(s);
|
311
|
+
}
|
312
|
+
}, We = async (e, t) => {
|
313
|
+
try {
|
314
|
+
const s = await R(e);
|
315
|
+
if (X(t)) {
|
316
|
+
const c = [], n = await te(e), S = await ee(e, t, s);
|
317
|
+
Object.entries(S).forEach(([g, a]) => {
|
318
|
+
if (a.isKeyframes && a.css) {
|
319
|
+
const D = `css/${`a_${a.animationName}.css`}`, x = r(s, D);
|
320
|
+
F(x, a.css);
|
321
|
+
return;
|
322
|
+
}
|
323
|
+
if (!a.generator) return;
|
324
|
+
const o = a.generator._withBuildContext({
|
325
|
+
name: g,
|
326
|
+
config: n
|
327
|
+
}), f = `css/${o.cssFileName}`, d = r(s, f);
|
328
|
+
F(d, o.css), c[o.priority] || (c[o.priority] = []), c[o.priority].push(o.cssFileName);
|
329
|
+
}), n.importStrategy !== "component" && c.forEach((g, a) => {
|
330
|
+
const o = `l_${a}.css`, f = r(s, "css", o);
|
331
|
+
let d = V(f, "utf8");
|
332
|
+
g.forEach((y) => {
|
333
|
+
var j;
|
334
|
+
const D = r(s, "css", y), x = ((j = /.*-([^-]+)-\d+.css/.exec(y)) == null ? void 0 : j.at(1)) || I(D, 6);
|
335
|
+
if (!d.includes(x)) {
|
336
|
+
const T = V(D, "utf8"), N = `/*start:${x}*/
|
337
|
+
${T}
|
338
|
+
/*end:${x}*/
|
339
|
+
`;
|
340
|
+
d = `${d.replace(/\}$/, "")}
|
341
|
+
${N}
|
342
|
+
}`;
|
343
|
+
}
|
344
|
+
}), F(f, d);
|
345
|
+
});
|
346
|
+
}
|
347
|
+
} catch (s) {
|
348
|
+
console.error(s);
|
349
|
+
}
|
350
|
+
}, Ie = async (e, t, s = de()) => {
|
351
|
+
try {
|
352
|
+
const l = await R(e);
|
353
|
+
if (X(t)) {
|
354
|
+
const n = V(t, "utf8");
|
355
|
+
n.replace(/^(?!export\s)const\s.*/gm, (f) => `export ${f}`) !== n && await he(t, n);
|
356
|
+
const g = await te(e), a = await ee(e, t, l);
|
357
|
+
let o = n;
|
358
|
+
if (Object.entries(a).forEach(([f, d]) => {
|
359
|
+
var p;
|
360
|
+
if (d.isKeyframes || !d.generator) return;
|
361
|
+
const y = d.generator._withBuildContext({
|
362
|
+
name: f,
|
363
|
+
config: g,
|
364
|
+
prod: s
|
365
|
+
}), D = new RegExp(`\\s${f}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(n);
|
366
|
+
if (!D) return console.error("Could not find the original declaration");
|
367
|
+
const x = (p = D.at(1)) == null ? void 0 : p.trim(), _ = new RegExp(`\\s${f}[=\\s]+styled\\(`, "g").exec(o);
|
368
|
+
if (!_) return console.error("Could not find the original declaration");
|
369
|
+
const { index: j } = _;
|
370
|
+
let T = !1;
|
371
|
+
const N = setTimeout(() => T = !0, 5e3);
|
372
|
+
let v = 0, i = !1, h = 0;
|
373
|
+
for (; !i && !T; ) {
|
374
|
+
const M = o[j + v];
|
375
|
+
M === "(" && h++, M === ")" && h--, h === 0 && M === ")" && (i = !0), v > o.length && (T = !0), v++;
|
376
|
+
}
|
377
|
+
if (!T) clearTimeout(N);
|
378
|
+
else throw new Error("Failed to find the end of the styled call and timed out");
|
379
|
+
const w = j + v, m = o.slice(j, w), u = o, b = ` ${f} = styled(${x}, "${y.classNames}", ${JSON.stringify(y.props)});`;
|
380
|
+
o = o.replace(m, b), u === o && console.error("Minimize file failed to change content", { name: f, tagName: x });
|
381
|
+
}), g.importStrategy === "component") {
|
382
|
+
const f = I(t, 6), d = q(t);
|
383
|
+
o = `import '../../saltygen/css/${`f_${B(d.name)}-${f}.css`}';
|
384
|
+
${o}`;
|
385
|
+
}
|
386
|
+
return o = o.replace("{ styled }", "{ styledClient as styled }"), o = o.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), o;
|
387
|
+
}
|
388
|
+
} catch (l) {
|
389
|
+
console.error("Error in minimizeFile:", l);
|
390
|
+
}
|
391
|
+
};
|
392
|
+
export {
|
393
|
+
Re as a,
|
394
|
+
ke as b,
|
395
|
+
Ne as c,
|
396
|
+
ee as d,
|
397
|
+
We as e,
|
398
|
+
ze as g,
|
399
|
+
X as i,
|
400
|
+
H as l,
|
401
|
+
Ie as m,
|
402
|
+
fe as s
|
403
|
+
};
|
package/package.json
CHANGED
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-DZsck9Ko.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-DlLbtfD0.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/index-D0d8j1Jc.cjs
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
"use strict";const fe=require("esbuild"),de=require("child_process"),_=require("./dash-case-BJEkFEGQ.cjs"),r=require("path"),a=require("fs"),Z=require("fs/promises"),B=require("./parse-styles-3zK35muR.cjs"),X=require("./parse-templates-VIvmVb52.cjs"),q=require("winston"),I=require("./merge-DxGoJDHv.cjs");var K=typeof document<"u"?document.currentScript:null;function ue(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const f=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,f.get?f:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const ee=ue(fe),te=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=r.join(e,"package.json");return a.existsSync(t)?t:te(r.join(e,".."))},pe=async e=>{const t=te(e);return await Z.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},ye=async e=>{const t=await pe(e);if(t)return t.type};let O;const se=async e=>{if(O)return O;const t=await ye(e);return t==="module"?O="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:K&&K.tagName.toUpperCase()==="SCRIPT"&&K.src||new URL("index-D0d8j1Jc.cjs",document.baseURI).href).endsWith(".cjs"))&&(O="cjs"),O||"esm"},H=q.createLogger({level:"debug",format:q.format.combine(q.format.colorize(),q.format.cli()),transports:[new q.transports.Console({})]}),ge=e=>{H.error(e)};function ne(e){return e?typeof e!="string"?ne(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 me={"*, *::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"}},E={externalModules:[],rcFile:void 0,destDir:void 0},oe=e=>{if(E.externalModules.length>0)return E.externalModules;const s=a.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const f=s[1].split(",").map(i=>i.replace(/['"`]/g,"").trim());return E.externalModules=f,f},z=async e=>{if(E.destDir)return E.destDir;const t=await U(e),s=r.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return E.destDir=s,s},A=["salty","css","styles","styled"],re=(e=[])=>new RegExp(`\\.(${[...A,...e].join("|")})\\.`),W=(e,t=[])=>re(t).test(e),ie=async e=>{if(E.rcFile)return E.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=r.join(e,".saltyrc.json"),s=await Z.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(E.rcFile=s,s):ie(r.join(e,".."))},U=async e=>{var f,i;const t=await ie(e),s=(f=t.projects)==null?void 0:f.find(n=>e.endsWith(n.dir||""));return s||((i=t.projects)==null?void 0:i.find(n=>n.dir===t.defaultProject))},he=async e=>{const t=await U(e),s=await z(e),f=r.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),i=r.join(s,"salty.config.js"),n=await se(e),F=oe(f);await ee.build({entryPoints:[f],minify:!0,treeShaking:!0,bundle:!0,outfile:i,format:n,external:F});const g=Date.now(),{config:c}=await import(`${i}?t=${g}`);return c},ae=async(e,t)=>{const s=await he(e),f=new Set,i=(m,h=[])=>m?Object.entries(m).flatMap(([T,k])=>{if(!k)return;if(typeof k=="object")return i(k,[...h,T]);const J=ne(T),v=_.dashCase(T),R=[...h,J].join(".");f.add(`"${R}"`);const L=[...h.map(_.dashCase),v].join("-"),{result:le}=B.parseValueTokens(k);return`--${L}: ${le};`}):[],n=m=>m?Object.entries(m).flatMap(([h,T])=>{const k=i(T);return h==="base"?k.join(""):`${h} { ${k.join("")} }`}):[],F=m=>m?Object.entries(m).flatMap(([h,T])=>Object.entries(T).flatMap(([k,J])=>{const v=i(J,[h]),R=`.${h}-${k}, [data-${h}="${k}"]`,L=v.join("");return`${R} { ${L} }`})):[],g=m=>t.variables.map(h=>h._current[m]),c=i(I.mergeStyles(s.variables,g("variables"))),o=n(I.mergeStyles(s.responsiveVariables,g("responsiveVariables"))),u=F(I.mergeStyles(s.conditionalVariables,g("conditionalVariables"))),d=await z(e),$=r.join(d,"css/_variables.css"),D=`:root { ${c.join("")} ${o.join("")} } ${u.join("")}`;a.writeFileSync($,D);const C=r.join(d,"css/_global.css"),M=I.mergeStyles(s.global,t.globalStyles),x=B.parseStyles(M,"");a.writeFileSync(C,`@layer global { ${x} }`);const N=r.join(d,"css/_reset.css"),V=s.reset==="none"?{}:typeof s.reset=="object"?s.reset:me,l=B.parseStyles(V,"");a.writeFileSync(N,`@layer reset { ${l} }`);const S=r.join(d,"css/_templates.css"),j=X.parseTemplates(s.templates),b=X.getTemplateTypes(s.templates);a.writeFileSync(S,j);const p=r.join(d,"types/css-tokens.d.ts"),y=`
|
2
|
-
// Variable types
|
3
|
-
type VariableTokens = ${[...f].join("|")};
|
4
|
-
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
5
|
-
|
6
|
-
// Template types
|
7
|
-
type TemplateTokens = {
|
8
|
-
${Object.entries(b).map(([m,h])=>`${m}?: ${h}`).join(`
|
9
|
-
`)}
|
10
|
-
}
|
11
|
-
`;a.writeFileSync(p,y)},Y=e=>e.replace(/styled\(([^"'`{,]+),/g,(t,s)=>{if(/^['"`]/.test(s))return t;const i=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!i.test(e))return t;const F=i.exec(e);if(F){const g=F.at(1);if(A.some(o=>g==null?void 0:g.includes(o)))return t}return"styled('div',"}),G=async(e,t,s)=>{const f=_.toHash(t),i=r.join(s,"./temp");a.existsSync(i)||a.mkdirSync(i);const n=r.parse(t);let F=a.readFileSync(t,"utf8");F=Y(F);const g=r.join(s,"js",f+".js"),c=await U(e),o=r.join(e,(c==null?void 0:c.configDir)||"","salty.config.ts"),u=oe(o),d=await se(e);await ee.build({stdin:{contents:F,sourcefile:n.base,resolveDir:n.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:g,format:d,target:["node20"],keepNames:!0,external:u,packages:"external",plugins:[{name:"test",setup:C=>{C.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},M=>{const x=a.readFileSync(M.path,"utf8");return{contents:Y(x),loader:"ts"}})}}]});const $=Date.now();return await import(`${g}?t=${$}`)},Q=async e=>{const t=await z(e),s=r.join(t,"salty.config.js"),f=Date.now(),{config:i}=await import(`${s}?t=${f}`);return i},ce=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Se=async(e,t=ce())=>{try{const s=Date.now();t?H.info("Generating CSS in production mode! 🔥"):H.info("Generating CSS in development mode! 🚀");const f=[],i=[],n=await z(e),F=r.join(n,"index.css");(()=>{a.existsSync(n)&&de.execSync("rm -rf "+n),a.mkdirSync(n,{recursive:!0}),a.mkdirSync(r.join(n,"css")),a.mkdirSync(r.join(n,"types"))})();const c={keyframes:[],mediaQueries:[],globalStyles:[],variables:[],components:[]};async function o(l){const S=["node_modules","saltygen"],j=a.statSync(l);if(j.isDirectory()){const b=a.readdirSync(l);if(S.some(w=>l.includes(w)))return;await Promise.all(b.map(w=>o(r.join(l,w))))}else if(j.isFile()&&W(l)){const p=await G(e,l,n);Object.entries(p).forEach(([w,y])=>{y.isKeyframes?c.keyframes.push({value:y,src:l,name:w}):y.isMedia?c.mediaQueries.push(y):y.isGlobalDefine?c.globalStyles.push(y):y.isDefineVariables?c.variables.push(y):y.generator&&c.components.push({value:y.generator,src:l,name:w})})}}await o(e),await ae(e,c);const u=await Q(e);for(const l of c.keyframes){const{value:S}=l,j=`a_${S.animationName}.css`,b=`css/${j}`,p=r.join(n,b);f.push(j),a.writeFileSync(p,S.css)}const d={};for(const l of c.components){const{value:S,name:j,src:b}=l,p=S._withBuildContext({name:j,config:u,prod:t});i[p.priority]||(i[p.priority]=[]),i[p.priority].push(p.cssFileName),u.importStrategy==="component"&&(d[b]?d[b].push(p.cssFileName):d[b]=[p.cssFileName]);const w=`css/${p.cssFileName}`,y=r.join(n,w);a.writeFileSync(y,p.css)}u.importStrategy==="component"&&Object.entries(d).forEach(([l,S])=>{const j=S.map(m=>`@import url('./${m}');`).join(`
|
12
|
-
`),b=_.toHash(l,6),p=r.parse(l),w=_.dashCase(p.name),y=r.join(n,`css/f_${w}-${b}.css`);a.writeFileSync(y,j)});const $=f.map(l=>`@import url('./css/${l}');`).join(`
|
13
|
-
`);let x=`@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
14
|
-
|
15
|
-
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(l=>{try{return a.readFileSync(r.join(n,"css",l),"utf8").length>0}catch{return!1}}).map(l=>`@import url('./css/${l}');`).join(`
|
16
|
-
`)}
|
17
|
-
${$}`;if(u.importStrategy!=="component"){const l=i.reduce((S,j,b)=>{const p=j.reduce((h,T)=>{var R;const k=r.join(n,"css",T),J=a.readFileSync(k,"utf8"),v=((R=/.*-([^-]+)-\d+.css/.exec(T))==null?void 0:R.at(1))||_.toHash(k,6);return h.includes(v)?h:`${h}
|
18
|
-
/*start:${v}*/
|
19
|
-
${J}
|
20
|
-
/*end:${v}*/
|
21
|
-
`},""),w=`l_${b}.css`,y=r.join(n,"css",w),m=`@layer l${b} { ${p}
|
22
|
-
}`;return a.writeFileSync(y,m),`${S}
|
23
|
-
@import url('./css/${w}');`},"");x+=l}a.writeFileSync(F,x);const P=Date.now()-s,V=P<200?"🔥":P<500?"🚀":P<1e3?"🎉":P<2e3?"🚗":P<5e3?"🤔":"🥴";H.info(`Generated CSS in ${P}ms! ${V}`)}catch(s){console.error(s)}},be=async(e,t)=>{try{const s=await z(e);if(W(t)){const i=[],n=await Q(e),F=await G(e,t,s);Object.entries(F).forEach(([g,c])=>{if(c.isKeyframes&&c.css){const D=`css/${`a_${c.animationName}.css`}`,C=r.join(s,D);a.writeFileSync(C,c.css);return}if(!c.generator)return;const o=c.generator._withBuildContext({name:g,config:n}),u=`css/${o.cssFileName}`,d=r.join(s,u);a.writeFileSync(d,o.css),i[o.priority]||(i[o.priority]=[]),i[o.priority].push(o.cssFileName)}),n.importStrategy!=="component"&&i.forEach((g,c)=>{const o=`l_${c}.css`,u=r.join(s,"css",o);let d=a.readFileSync(u,"utf8");g.forEach($=>{var x;const D=r.join(s,"css",$),C=((x=/.*-([^-]+)-\d+.css/.exec($))==null?void 0:x.at(1))||_.toHash(D,6);if(!d.includes(C)){const N=a.readFileSync(D,"utf8"),P=`/*start:${C}*/
|
24
|
-
${N}
|
25
|
-
/*end:${C}*/
|
26
|
-
`;d=`${d.replace(/\}$/,"")}
|
27
|
-
${P}
|
28
|
-
}`}}),a.writeFileSync(u,d)})}}catch(s){console.error(s)}},we=async(e,t,s=ce())=>{try{const f=await z(e);if(W(t)){const n=a.readFileSync(t,"utf8");n.replace(/^(?!export\s)const\s.*/gm,u=>`export ${u}`)!==n&&await Z.writeFile(t,n);const g=await Q(e),c=await G(e,t,f);let o=n;if(Object.entries(c).forEach(([u,d])=>{var y;if(d.isKeyframes||!d.generator)return;const $=d.generator._withBuildContext({name:u,config:g,prod:s}),D=new RegExp(`\\s${u}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(n);if(!D)return console.error("Could not find the original declaration");const C=(y=D.at(1))==null?void 0:y.trim(),M=new RegExp(`\\s${u}[=\\s]+styled\\(`,"g").exec(o);if(!M)return console.error("Could not find the original declaration");const{index:x}=M;let N=!1;const P=setTimeout(()=>N=!0,5e3);let V=0,l=!1,S=0;for(;!l&&!N;){const m=o[x+V];m==="("&&S++,m===")"&&S--,S===0&&m===")"&&(l=!0),V>o.length&&(N=!0),V++}if(!N)clearTimeout(P);else throw new Error("Failed to find the end of the styled call and timed out");const j=x+V,b=o.slice(x,j),p=o,w=` ${u} = styled(${C}, "${$.classNames}", ${JSON.stringify($.props)});`;o=o.replace(b,w),p===o&&console.error("Minimize file failed to change content",{name:u,tagName:C})}),g.importStrategy==="component"){const u=_.toHash(t,6),d=r.parse(t);o=`import '../../saltygen/css/${`f_${_.dashCase(d.name)}-${u}.css`}';
|
29
|
-
${o}`}return o=o.replace("{ styled }","{ styledClient as styled }"),o=o.replace("@salty-css/react/styled","@salty-css/react/styled-client"),o}}catch(f){console.error("Error in minimizeFile:",f)}};exports.compileSaltyFile=G;exports.generateConfigStyles=ae;exports.generateCss=Se;exports.generateFile=be;exports.isSaltyFile=W;exports.logError=ge;exports.logger=H;exports.minimizeFile=we;exports.saltyFileExtensions=A;exports.saltyFileRegExp=re;
|
package/index-D9VggpwE.js
DELETED
@@ -1,397 +0,0 @@
|
|
1
|
-
import * as te from "esbuild";
|
2
|
-
import { execSync as pe } from "child_process";
|
3
|
-
import { t as W, d as B } from "./dash-case-DBThphLm.js";
|
4
|
-
import { join as a, parse as Z } from "path";
|
5
|
-
import { existsSync as A, writeFileSync as k, mkdirSync as G, readFileSync as M, statSync as de, readdirSync as ue } from "fs";
|
6
|
-
import { readFile as se, writeFile as me } from "fs/promises";
|
7
|
-
import { p as Y, a as ge } from "./parse-styles-DrLhKtqW.js";
|
8
|
-
import { p as ye, a as he } from "./parse-templates-DRKlN-pP.js";
|
9
|
-
import { createLogger as be, format as L, transports as $e } from "winston";
|
10
|
-
import { m as I } from "./merge-BVm9us1A.js";
|
11
|
-
const ne = (e) => {
|
12
|
-
if (!e || e === "/") throw new Error("Could not find package.json file");
|
13
|
-
const t = a(e, "package.json");
|
14
|
-
return A(t) ? t : ne(a(e, ".."));
|
15
|
-
}, we = async (e) => {
|
16
|
-
const t = ne(e);
|
17
|
-
return await se(t, "utf-8").then(JSON.parse).catch(() => {
|
18
|
-
});
|
19
|
-
}, Se = async (e) => {
|
20
|
-
const t = await we(e);
|
21
|
-
if (t)
|
22
|
-
return t.type;
|
23
|
-
};
|
24
|
-
let O;
|
25
|
-
const oe = async (e) => {
|
26
|
-
if (O) return O;
|
27
|
-
const t = await Se(e);
|
28
|
-
return t === "module" ? O = "esm" : (t === "commonjs" || import.meta.url.endsWith(".cjs")) && (O = "cjs"), O || "esm";
|
29
|
-
}, H = be({
|
30
|
-
level: "debug",
|
31
|
-
format: L.combine(L.colorize(), L.cli()),
|
32
|
-
transports: [new $e.Console({})]
|
33
|
-
}), ve = (e) => {
|
34
|
-
H.error(e);
|
35
|
-
};
|
36
|
-
function re(e) {
|
37
|
-
return e ? typeof e != "string" ? re(String(e)) : e.replace(/[\s-]/g, ".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (t, s) => (s > 0 ? "." : "") + t.toLowerCase()) : "";
|
38
|
-
}
|
39
|
-
const Ce = {
|
40
|
-
/** Set box model to border-box */
|
41
|
-
"*, *::before, *::after": {
|
42
|
-
boxSizing: "border-box"
|
43
|
-
},
|
44
|
-
/** Remove default margin and padding */
|
45
|
-
"*": {
|
46
|
-
margin: 0
|
47
|
-
},
|
48
|
-
/** Remove adjust font properties */
|
49
|
-
html: {
|
50
|
-
lineHeight: 1.15,
|
51
|
-
textSizeAdjust: "100%",
|
52
|
-
WebkitFontSmoothing: "antialiased"
|
53
|
-
},
|
54
|
-
/** Make media elements responsive */
|
55
|
-
"img, picture, video, canvas, svg": {
|
56
|
-
display: "block",
|
57
|
-
maxWidth: "100%"
|
58
|
-
},
|
59
|
-
/** Avoid overflow of text */
|
60
|
-
"p, h1, h2, h3, h4, h5, h6": {
|
61
|
-
overflowWrap: "break-word"
|
62
|
-
},
|
63
|
-
/** Improve text wrapping */
|
64
|
-
p: {
|
65
|
-
textWrap: "pretty"
|
66
|
-
},
|
67
|
-
"h1, h2, h3, h4, h5, h6": {
|
68
|
-
textWrap: "balance"
|
69
|
-
},
|
70
|
-
/** Improve link color */
|
71
|
-
a: {
|
72
|
-
color: "currentColor"
|
73
|
-
},
|
74
|
-
/** Improve button line height */
|
75
|
-
button: {
|
76
|
-
lineHeight: "1em",
|
77
|
-
color: "currentColor"
|
78
|
-
},
|
79
|
-
/** Improve form elements */
|
80
|
-
"input, optgroup, select, textarea": {
|
81
|
-
fontFamily: "inherit",
|
82
|
-
fontSize: "100%",
|
83
|
-
lineHeight: "1.15em"
|
84
|
-
}
|
85
|
-
}, E = {
|
86
|
-
externalModules: [],
|
87
|
-
rcFile: void 0,
|
88
|
-
destDir: void 0
|
89
|
-
}, ae = (e) => {
|
90
|
-
if (E.externalModules.length > 0) return E.externalModules;
|
91
|
-
const s = M(e, "utf8").match(/externalModules:\s?\[(.*)\]/);
|
92
|
-
if (!s) return [];
|
93
|
-
const f = s[1].split(",").map((r) => r.replace(/['"`]/g, "").trim());
|
94
|
-
return E.externalModules = f, f;
|
95
|
-
}, J = async (e) => {
|
96
|
-
if (E.destDir) return E.destDir;
|
97
|
-
const t = await q(e), s = a(e, (t == null ? void 0 : t.saltygenDir) || "saltygen");
|
98
|
-
return E.destDir = s, s;
|
99
|
-
}, ie = ["salty", "css", "styles", "styled"], Fe = (e = []) => new RegExp(`\\.(${[...ie, ...e].join("|")})\\.`), Q = (e, t = []) => Fe(t).test(e), ce = async (e) => {
|
100
|
-
if (E.rcFile) return E.rcFile;
|
101
|
-
if (e === "/") throw new Error("Could not find .saltyrc.json file");
|
102
|
-
const t = a(e, ".saltyrc.json"), s = await se(t, "utf-8").then(JSON.parse).catch(() => {
|
103
|
-
});
|
104
|
-
return s ? (E.rcFile = s, s) : ce(a(e, ".."));
|
105
|
-
}, q = async (e) => {
|
106
|
-
var f, r;
|
107
|
-
const t = await ce(e), s = (f = t.projects) == null ? void 0 : f.find((n) => e.endsWith(n.dir || ""));
|
108
|
-
return s || ((r = t.projects) == null ? void 0 : r.find((n) => n.dir === t.defaultProject));
|
109
|
-
}, xe = async (e) => {
|
110
|
-
const t = await q(e), s = await J(e), f = a(e, (t == null ? void 0 : t.configDir) || "", "salty.config.ts"), r = a(s, "salty.config.js"), n = await oe(e), w = ae(f);
|
111
|
-
await te.build({
|
112
|
-
entryPoints: [f],
|
113
|
-
minify: !0,
|
114
|
-
treeShaking: !0,
|
115
|
-
bundle: !0,
|
116
|
-
outfile: r,
|
117
|
-
format: n,
|
118
|
-
external: w
|
119
|
-
});
|
120
|
-
const m = Date.now(), { config: i } = await import(`${r}?t=${m}`);
|
121
|
-
return i;
|
122
|
-
}, je = async (e, t) => {
|
123
|
-
const s = await xe(e), f = /* @__PURE__ */ new Set(), r = (g, y = []) => g ? Object.entries(g).flatMap(([T, j]) => {
|
124
|
-
if (!j) return;
|
125
|
-
if (typeof j == "object") return r(j, [...y, T]);
|
126
|
-
const z = re(T), v = B(T), R = [...y, z].join(".");
|
127
|
-
f.add(`"${R}"`);
|
128
|
-
const K = [...y.map(B), v].join("-"), { result: fe } = ge(j);
|
129
|
-
return `--${K}: ${fe};`;
|
130
|
-
}) : [], n = (g) => g ? Object.entries(g).flatMap(([y, T]) => {
|
131
|
-
const j = r(T);
|
132
|
-
return y === "base" ? j.join("") : `${y} { ${j.join("")} }`;
|
133
|
-
}) : [], w = (g) => g ? Object.entries(g).flatMap(([y, T]) => Object.entries(T).flatMap(([j, z]) => {
|
134
|
-
const v = r(z, [y]), R = `.${y}-${j}, [data-${y}="${j}"]`, K = v.join("");
|
135
|
-
return `${R} { ${K} }`;
|
136
|
-
})) : [], m = (g) => t.variables.map((y) => y._current[g]), i = r(I(s.variables, m("variables"))), o = n(I(s.responsiveVariables, m("responsiveVariables"))), p = w(I(s.conditionalVariables, m("conditionalVariables"))), l = await J(e), C = a(l, "css/_variables.css"), D = `:root { ${i.join("")} ${o.join("")} } ${p.join("")}`;
|
137
|
-
k(C, D);
|
138
|
-
const F = a(l, "css/_global.css"), V = I(s.global, t.globalStyles), x = Y(V, "");
|
139
|
-
k(F, `@layer global { ${x} }`);
|
140
|
-
const P = a(l, "css/_reset.css"), _ = s.reset === "none" ? {} : typeof s.reset == "object" ? s.reset : Ce, c = Y(_, "");
|
141
|
-
k(P, `@layer reset { ${c} }`);
|
142
|
-
const h = a(l, "css/_templates.css"), S = ye(s.templates), b = he(s.templates);
|
143
|
-
k(h, S);
|
144
|
-
const d = a(l, "types/css-tokens.d.ts"), u = `
|
145
|
-
// Variable types
|
146
|
-
type VariableTokens = ${[...f].join("|")};
|
147
|
-
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
148
|
-
|
149
|
-
// Template types
|
150
|
-
type TemplateTokens = {
|
151
|
-
${Object.entries(b).map(([g, y]) => `${g}?: ${y}`).join(`
|
152
|
-
`)}
|
153
|
-
}
|
154
|
-
`;
|
155
|
-
k(d, u);
|
156
|
-
}, ee = (e) => e.replace(/styled\(([^"'`{,]+),/g, (t, s) => {
|
157
|
-
if (/^['"`]/.test(s)) return t;
|
158
|
-
const r = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
|
159
|
-
if (!r.test(e)) return t;
|
160
|
-
const w = r.exec(e);
|
161
|
-
if (w) {
|
162
|
-
const m = w.at(1);
|
163
|
-
if (ie.some((o) => m == null ? void 0 : m.includes(o))) return t;
|
164
|
-
}
|
165
|
-
return "styled('div',";
|
166
|
-
}), U = async (e, t, s) => {
|
167
|
-
const f = W(t), r = a(s, "./temp");
|
168
|
-
A(r) || G(r);
|
169
|
-
const n = Z(t);
|
170
|
-
let w = M(t, "utf8");
|
171
|
-
w = ee(w);
|
172
|
-
const m = a(s, "js", f + ".js"), i = await q(e), o = a(e, (i == null ? void 0 : i.configDir) || "", "salty.config.ts"), p = ae(o), l = await oe(e);
|
173
|
-
await te.build({
|
174
|
-
stdin: {
|
175
|
-
contents: w,
|
176
|
-
sourcefile: n.base,
|
177
|
-
resolveDir: n.dir,
|
178
|
-
loader: "tsx"
|
179
|
-
},
|
180
|
-
minify: !1,
|
181
|
-
treeShaking: !0,
|
182
|
-
bundle: !0,
|
183
|
-
outfile: m,
|
184
|
-
format: l,
|
185
|
-
target: ["node20"],
|
186
|
-
keepNames: !0,
|
187
|
-
external: p,
|
188
|
-
packages: "external",
|
189
|
-
plugins: [
|
190
|
-
{
|
191
|
-
name: "test",
|
192
|
-
setup: (F) => {
|
193
|
-
F.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (V) => {
|
194
|
-
const x = M(V.path, "utf8");
|
195
|
-
return { contents: ee(x), loader: "ts" };
|
196
|
-
});
|
197
|
-
}
|
198
|
-
}
|
199
|
-
]
|
200
|
-
});
|
201
|
-
const C = Date.now();
|
202
|
-
return await import(`${m}?t=${C}`);
|
203
|
-
}, X = async (e) => {
|
204
|
-
const t = await J(e), s = a(t, "salty.config.js"), f = Date.now(), { config: r } = await import(`${s}?t=${f}`);
|
205
|
-
return r;
|
206
|
-
}, le = () => {
|
207
|
-
try {
|
208
|
-
return process.env.NODE_ENV === "production";
|
209
|
-
} catch {
|
210
|
-
return !1;
|
211
|
-
}
|
212
|
-
}, Re = async (e, t = le()) => {
|
213
|
-
try {
|
214
|
-
const s = Date.now();
|
215
|
-
t ? H.info("Generating CSS in production mode! 🔥") : H.info("Generating CSS in development mode! 🚀");
|
216
|
-
const f = [], r = [], n = await J(e), w = a(n, "index.css");
|
217
|
-
(() => {
|
218
|
-
A(n) && pe("rm -rf " + n), G(n, { recursive: !0 }), G(a(n, "css")), G(a(n, "types"));
|
219
|
-
})();
|
220
|
-
const i = {
|
221
|
-
keyframes: [],
|
222
|
-
mediaQueries: [],
|
223
|
-
globalStyles: [],
|
224
|
-
variables: [],
|
225
|
-
components: []
|
226
|
-
};
|
227
|
-
async function o(c) {
|
228
|
-
const h = ["node_modules", "saltygen"], S = de(c);
|
229
|
-
if (S.isDirectory()) {
|
230
|
-
const b = ue(c);
|
231
|
-
if (h.some(($) => c.includes($))) return;
|
232
|
-
await Promise.all(b.map(($) => o(a(c, $))));
|
233
|
-
} else if (S.isFile() && Q(c)) {
|
234
|
-
const d = await U(e, c, n);
|
235
|
-
Object.entries(d).forEach(([$, u]) => {
|
236
|
-
u.isKeyframes ? i.keyframes.push({
|
237
|
-
value: u,
|
238
|
-
src: c,
|
239
|
-
name: $
|
240
|
-
}) : u.isMedia ? i.mediaQueries.push(u) : u.isGlobalDefine ? i.globalStyles.push(u) : u.isDefineVariables ? i.variables.push(u) : u.generator && i.components.push({
|
241
|
-
value: u.generator,
|
242
|
-
src: c,
|
243
|
-
name: $
|
244
|
-
});
|
245
|
-
});
|
246
|
-
}
|
247
|
-
}
|
248
|
-
await o(e), await je(e, i);
|
249
|
-
const p = await X(e);
|
250
|
-
for (const c of i.keyframes) {
|
251
|
-
const { value: h } = c, S = `a_${h.animationName}.css`, b = `css/${S}`, d = a(n, b);
|
252
|
-
f.push(S), k(d, h.css);
|
253
|
-
}
|
254
|
-
const l = {};
|
255
|
-
for (const c of i.components) {
|
256
|
-
const { value: h, name: S, src: b } = c, d = h._withBuildContext({
|
257
|
-
name: S,
|
258
|
-
config: p,
|
259
|
-
prod: t
|
260
|
-
});
|
261
|
-
r[d.priority] || (r[d.priority] = []), r[d.priority].push(d.cssFileName), p.importStrategy === "component" && (l[b] ? l[b].push(d.cssFileName) : l[b] = [d.cssFileName]);
|
262
|
-
const $ = `css/${d.cssFileName}`, u = a(n, $);
|
263
|
-
k(u, d.css);
|
264
|
-
}
|
265
|
-
p.importStrategy === "component" && Object.entries(l).forEach(([c, h]) => {
|
266
|
-
const S = h.map((g) => `@import url('./${g}');`).join(`
|
267
|
-
`), b = W(c, 6), d = Z(c), $ = B(d.name), u = a(n, `css/f_${$}-${b}.css`);
|
268
|
-
k(u, S);
|
269
|
-
});
|
270
|
-
const C = f.map((c) => `@import url('./css/${c}');`).join(`
|
271
|
-
`);
|
272
|
-
let x = `@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
273
|
-
|
274
|
-
${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((c) => {
|
275
|
-
try {
|
276
|
-
return M(a(n, "css", c), "utf8").length > 0;
|
277
|
-
} catch {
|
278
|
-
return !1;
|
279
|
-
}
|
280
|
-
}).map((c) => `@import url('./css/${c}');`).join(`
|
281
|
-
`)}
|
282
|
-
${C}`;
|
283
|
-
if (p.importStrategy !== "component") {
|
284
|
-
const c = r.reduce((h, S, b) => {
|
285
|
-
const d = S.reduce((y, T) => {
|
286
|
-
var R;
|
287
|
-
const j = a(n, "css", T), z = M(j, "utf8"), v = ((R = /.*-([^-]+)-\d+.css/.exec(T)) == null ? void 0 : R.at(1)) || W(j, 6);
|
288
|
-
return y.includes(v) ? y : `${y}
|
289
|
-
/*start:${v}*/
|
290
|
-
${z}
|
291
|
-
/*end:${v}*/
|
292
|
-
`;
|
293
|
-
}, ""), $ = `l_${b}.css`, u = a(n, "css", $), g = `@layer l${b} { ${d}
|
294
|
-
}`;
|
295
|
-
return k(u, g), `${h}
|
296
|
-
@import url('./css/${$}');`;
|
297
|
-
}, "");
|
298
|
-
x += c;
|
299
|
-
}
|
300
|
-
k(w, x);
|
301
|
-
const N = Date.now() - s, _ = N < 200 ? "🔥" : N < 500 ? "🚀" : N < 1e3 ? "🎉" : N < 2e3 ? "🚗" : N < 5e3 ? "🤔" : "🥴";
|
302
|
-
H.info(`Generated CSS in ${N}ms! ${_}`);
|
303
|
-
} catch (s) {
|
304
|
-
console.error(s);
|
305
|
-
}
|
306
|
-
}, Oe = async (e, t) => {
|
307
|
-
try {
|
308
|
-
const s = await J(e);
|
309
|
-
if (Q(t)) {
|
310
|
-
const r = [], n = await X(e), w = await U(e, t, s);
|
311
|
-
Object.entries(w).forEach(([m, i]) => {
|
312
|
-
if (i.isKeyframes && i.css) {
|
313
|
-
const D = `css/${`a_${i.animationName}.css`}`, F = a(s, D);
|
314
|
-
k(F, i.css);
|
315
|
-
return;
|
316
|
-
}
|
317
|
-
if (!i.generator) return;
|
318
|
-
const o = i.generator._withBuildContext({
|
319
|
-
name: m,
|
320
|
-
config: n
|
321
|
-
}), p = `css/${o.cssFileName}`, l = a(s, p);
|
322
|
-
k(l, o.css), r[o.priority] || (r[o.priority] = []), r[o.priority].push(o.cssFileName);
|
323
|
-
}), n.importStrategy !== "component" && r.forEach((m, i) => {
|
324
|
-
const o = `l_${i}.css`, p = a(s, "css", o);
|
325
|
-
let l = M(p, "utf8");
|
326
|
-
m.forEach((C) => {
|
327
|
-
var x;
|
328
|
-
const D = a(s, "css", C), F = ((x = /.*-([^-]+)-\d+.css/.exec(C)) == null ? void 0 : x.at(1)) || W(D, 6);
|
329
|
-
if (!l.includes(F)) {
|
330
|
-
const P = M(D, "utf8"), N = `/*start:${F}*/
|
331
|
-
${P}
|
332
|
-
/*end:${F}*/
|
333
|
-
`;
|
334
|
-
l = `${l.replace(/\}$/, "")}
|
335
|
-
${N}
|
336
|
-
}`;
|
337
|
-
}
|
338
|
-
}), k(p, l);
|
339
|
-
});
|
340
|
-
}
|
341
|
-
} catch (s) {
|
342
|
-
console.error(s);
|
343
|
-
}
|
344
|
-
}, Je = async (e, t, s = le()) => {
|
345
|
-
try {
|
346
|
-
const f = await J(e);
|
347
|
-
if (Q(t)) {
|
348
|
-
const n = M(t, "utf8");
|
349
|
-
n.replace(/^(?!export\s)const\s.*/gm, (p) => `export ${p}`) !== n && await me(t, n);
|
350
|
-
const m = await X(e), i = await U(e, t, f);
|
351
|
-
let o = n;
|
352
|
-
if (Object.entries(i).forEach(([p, l]) => {
|
353
|
-
var u;
|
354
|
-
if (l.isKeyframes || !l.generator) return;
|
355
|
-
const C = l.generator._withBuildContext({
|
356
|
-
name: p,
|
357
|
-
config: m,
|
358
|
-
prod: s
|
359
|
-
}), D = new RegExp(`\\s${p}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(n);
|
360
|
-
if (!D) return console.error("Could not find the original declaration");
|
361
|
-
const F = (u = D.at(1)) == null ? void 0 : u.trim(), V = new RegExp(`\\s${p}[=\\s]+styled\\(`, "g").exec(o);
|
362
|
-
if (!V) return console.error("Could not find the original declaration");
|
363
|
-
const { index: x } = V;
|
364
|
-
let P = !1;
|
365
|
-
const N = setTimeout(() => P = !0, 5e3);
|
366
|
-
let _ = 0, c = !1, h = 0;
|
367
|
-
for (; !c && !P; ) {
|
368
|
-
const g = o[x + _];
|
369
|
-
g === "(" && h++, g === ")" && h--, h === 0 && g === ")" && (c = !0), _ > o.length && (P = !0), _++;
|
370
|
-
}
|
371
|
-
if (!P) clearTimeout(N);
|
372
|
-
else throw new Error("Failed to find the end of the styled call and timed out");
|
373
|
-
const S = x + _, b = o.slice(x, S), d = o, $ = ` ${p} = styled(${F}, "${C.classNames}", ${JSON.stringify(C.props)});`;
|
374
|
-
o = o.replace(b, $), d === o && console.error("Minimize file failed to change content", { name: p, tagName: F });
|
375
|
-
}), m.importStrategy === "component") {
|
376
|
-
const p = W(t, 6), l = Z(t);
|
377
|
-
o = `import '../../saltygen/css/${`f_${B(l.name)}-${p}.css`}';
|
378
|
-
${o}`;
|
379
|
-
}
|
380
|
-
return o = o.replace("{ styled }", "{ styledClient as styled }"), o = o.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), o;
|
381
|
-
}
|
382
|
-
} catch (f) {
|
383
|
-
console.error("Error in minimizeFile:", f);
|
384
|
-
}
|
385
|
-
};
|
386
|
-
export {
|
387
|
-
ve as a,
|
388
|
-
Fe as b,
|
389
|
-
je as c,
|
390
|
-
U as d,
|
391
|
-
Oe as e,
|
392
|
-
Re as g,
|
393
|
-
Q as i,
|
394
|
-
H as l,
|
395
|
-
Je as m,
|
396
|
-
ie as s
|
397
|
-
};
|