@salty-css/core 0.0.1-alpha.139 → 0.0.1-alpha.140

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 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-BcxXTbUt.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+`
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-Bywmnn_7.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-DivhXuS6.js";
6
+ import { l as t, a as h, g as te } from "../index-ChAB4YZW.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";
@@ -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-templates-DD4hQEpv.cjs");const e=require("../index-BcxXTbUt.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;
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-templates-DD4hQEpv.cjs");const e=require("../index-Bywmnn_7.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.js CHANGED
@@ -5,7 +5,7 @@ import "path";
5
5
  import "fs";
6
6
  import "fs/promises";
7
7
  import "../parse-templates-CgZo0YA1.js";
8
- import { d as p, c as n, g, e as F, i as y, m as x, s as S, b as c } from "../index-DivhXuS6.js";
8
+ import { d as p, c as n, g, e as F, i as y, m as x, s as S, b as c } from "../index-ChAB4YZW.js";
9
9
  export {
10
10
  p as compileSaltyFile,
11
11
  n as generateConfigStyles,
@@ -0,0 +1,22 @@
1
+ "use strict";const ae=require("esbuild"),le=require("child_process"),R=require("./dash-case-BJEkFEGQ.cjs"),o=require("path"),c=require("fs"),G=require("fs/promises"),v=require("./parse-templates-DD4hQEpv.cjs"),z=require("winston");var H=typeof document<"u"?document.currentScript:null;function de(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const r=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,r.get?r:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const U=de(ae),X=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=o.join(e,"package.json");return c.existsSync(t)?t:X(o.join(e,".."))},pe=async e=>{const t=X(e);return await G.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},ue=async e=>{const t=await pe(e);if(t)return t.type};let O;const Y=async e=>{if(O)return O;const t=await ue(e);return t==="module"?O="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:H&&H.tagName.toUpperCase()==="SCRIPT"&&H.src||new URL("index-Bywmnn_7.cjs",document.baseURI).href).endsWith(".cjs"))&&(O="cjs"),O||"esm"},J=z.createLogger({level:"debug",format:z.format.combine(z.format.colorize(),z.format.cli()),transports:[new z.transports.Console({})]}),fe=e=>{J.error(e)};function Q(e){return e?typeof e!="string"?Q(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 ge={"*, *::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"}},L={externalModules:[]},ee=e=>{if(L.externalModules.length>0)return L.externalModules;const t=o.join(e,"salty.config.ts"),r=c.readFileSync(t,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!r)return[];const a=r[1].split(",").map(n=>n.replace(/['"`]/g,"").trim());return L.externalModules=a,a},q=e=>o.join(e,"./saltygen"),A=["salty","css","styles","styled"],te=(e=[])=>new RegExp(`\\.(${[...A,...e].join("|")})\\.`),I=(e,t=[])=>te(t).test(e),ye=async e=>{const t=q(e),s=o.join(e,"salty.config.ts"),r=o.join(t,"salty.config.js"),a=await Y(e),n=ee(e);await U.build({entryPoints:[s],minify:!0,treeShaking:!0,bundle:!0,outfile:r,format:a,external:n});const f=Date.now(),{config:g}=await import(`${r}?t=${f}`);return g},se=async e=>{const t=await ye(e),s=new Set,r=(d,p=[])=>d?Object.entries(d).flatMap(([S,u])=>{if(!u)return;if(typeof u=="object")return r(u,[...p,S]);const E=Q(S),V=R.dashCase(S),M=[...p,E].join(".");s.add(`"${M}"`);const x=[...p.map(R.dashCase),V].join("-"),{result:N}=v.parseValueTokens(u);return`--${x}: ${N};`}):[],a=d=>d?Object.entries(d).flatMap(([p,S])=>{const u=r(S);return p==="base"?u.join(""):`${p} { ${u.join("")} }`}):[],n=d=>d?Object.entries(d).flatMap(([p,S])=>Object.entries(S).flatMap(([u,E])=>{const V=r(E,[p]),M=`.${p}-${u}, [data-${p}="${u}"]`,x=V.join("");return`${M} { ${x} }`})):[],f=r(t.variables),g=a(t.responsiveVariables),j=n(t.conditionalVariables),i=q(e),y=o.join(i,"css/_variables.css"),F=`:root { ${f.join("")} ${g.join("")} } ${j.join("")}`;c.writeFileSync(y,F);const w=o.join(i,"css/_global.css"),m=v.parseStyles(t.global,"");c.writeFileSync(w,`@layer global { ${m} }`);const b=o.join(i,"css/_reset.css"),h=t.reset==="none"?{}:typeof t.reset=="object"?t.reset:ge,k=v.parseStyles(h,"");c.writeFileSync(b,`@layer reset { ${k} }`);const l=o.join(i,"css/_templates.css"),$=v.parseTemplates(t.templates),D=v.getTemplateTypes(t.templates);c.writeFileSync(l,$);const C=o.join(i,"types/css-tokens.d.ts"),T=`
2
+ // Variable types
3
+ type VariableTokens = ${[...s].join("|")};
4
+ type PropertyValueToken = \`{\${VariableTokens}}\`;
5
+
6
+ // Template types
7
+ type TemplateTokens = {
8
+ ${Object.entries(D).map(([d,p])=>`${d}?: ${p}`).join(`
9
+ `)}
10
+ }
11
+ `;c.writeFileSync(C,T)},Z=e=>e.replace(/styled\(([^"'`{,]+),/g,(t,s)=>{const r=/^['"`]/.test(s);if(r&&console.log("String tag",s),r)return t;const a=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`),n=a.test(e);if(n||console.log("Not imported",s),!n)return t;const f=a.exec(e);if(f){const g=f.at(1),j=A.some(i=>g==null?void 0:g.includes(i));if(j&&console.log("Salty import for",s,`"${f.at(0)}"`),j)return t}return console.log("Replacing",s),"styled('div',"}),W=async(e,t,s)=>{console.log({sourceFilePath:t});const r=R.toHash(t),a=o.join(s,"./temp");c.existsSync(a)||c.mkdirSync(a);const n=o.parse(t);let f=c.readFileSync(t,"utf8");f=Z(f);const g=o.join(s,"js",r+".js"),j=ee(e),i=await Y(e);await U.build({stdin:{contents:f,sourcefile:n.base,resolveDir:n.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:g,format:i,target:["node20"],keepNames:!0,external:j,packages:"external",plugins:[{name:"test",setup:w=>{w.onLoad({filter:/.*.css.ts/},m=>{console.log("Loading",{sourceFilePath:t,args:m});const b=c.readFileSync(m.path,"utf8");return{contents:Z(b)}})}}]});const y=Date.now();return await import(`${g}?t=${y}`)},B=async e=>{const t=q(e),s=o.join(t,"salty.config.js"),r=Date.now(),{config:a}=await import(`${s}?t=${r}`);return a},ne=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},me=async(e,t=ne())=>{try{const s=Date.now();t?J.info("Generating CSS in production mode! 🔥"):J.info("Generating CSS in development mode! 🚀");const r=[],a=[],n=q(e),f=o.join(n,"index.css");(()=>{c.existsSync(n)&&le.execSync("rm -rf "+n),c.mkdirSync(n),c.mkdirSync(o.join(n,"css")),c.mkdirSync(o.join(n,"types"))})(),await se(e);const j=await B(e);async function i(l,$){const D=["node_modules","saltygen"],C=c.statSync(l);if(C.isDirectory()){const _=c.readdirSync(l);if(D.some(d=>l.includes(d)))return;await Promise.all(_.map(d=>i(o.join(l,d),o.join($,d))))}else if(C.isFile()&&I(l)){const T=await W(e,l,n),d=[];Object.entries(T).forEach(([M,x])=>{if(x.isKeyframes&&x.css){const K=`a_${x.animationName}.css`,ie=`css/${K}`,ce=o.join(n,ie);r.push(K),c.writeFileSync(ce,x.css);return}if(!x.generator)return;const N=x.generator._withBuildContext({name:M,config:j,prod:t});a[N.priority]||(a[N.priority]=[]),a[N.priority].push(N.cssFileName),d.push(N.cssFileName);const oe=`css/${N.cssFileName}`,re=o.join(n,oe);c.writeFileSync(re,N.css)});const p=d.map(M=>`@import url('./${M}');`).join(`
12
+ `),S=R.toHash(l,6),u=o.parse(l),E=R.dashCase(u.name),V=o.join(n,`css/f_${E}-${S}.css`);c.writeFileSync(V,p)}}await i(e,n);const y=r.map(l=>`@import url('./css/${l}');`).join(`
13
+ `);let b=`@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 c.readFileSync(o.join(n,"css",l),"utf8").length>0}catch{return!1}}).map(l=>`@import url('./css/${l}');`).join(`
16
+ `)}
17
+ ${y}`;if(j.importStrategy!=="component"){const l=a.reduce(($,D,C)=>{const _=D.reduce((S,u)=>{const E=c.readFileSync(o.join(n,"css",u),"utf8");return`${S}
18
+ ${E}`},""),T=`l_${C}.css`,d=o.join(n,"css",T),p=`@layer l${C} { ${_} }`;return c.writeFileSync(d,p),`${$}
19
+ @import url('./css/${T}');`},"");b+=l}c.writeFileSync(f,b);const h=Date.now()-s,k=h<200?"🔥":h<500?"🚀":h<1e3?"🎉":h<2e3?"🚗":h<5e3?"🤔":"🥴";J.info(`Generated CSS in ${h}ms! ${k}`)}catch(s){console.error(s)}},he=async(e,t)=>{try{const s=[],r=o.join(e,"./saltygen"),a=o.join(r,"index.css");if(I(t)){const f=await B(e),g=await W(e,t,r);Object.entries(g).forEach(([w,m])=>{if(m.isKeyframes&&m.css){const l=`css/${`a_${m.animationName}.css`}`,$=o.join(r,l);c.writeFileSync($,m.css);return}if(!m.generator)return;const b=m.generator._withBuildContext({name:w,config:f}),P=`css/${b.cssFileName}`,h=o.join(r,P);s.push(b.cssFileName),c.writeFileSync(h,b.css)});const j=c.readFileSync(a,"utf8").split(`
20
+ `),i=s.map(w=>`@import url('../saltygen/css/${w}');`),F=[...new Set([...j,...i])].join(`
21
+ `);c.writeFileSync(a,F)}}catch(s){console.error(s)}},Se=async(e,t,s=ne())=>{try{const r=o.join(e,"./saltygen");if(I(t)){const n=c.readFileSync(t,"utf8");n.replace(/^(?!export\s)const\s.*/gm,y=>`export ${y}`)!==n&&await G.writeFile(t,n);const g=await B(e),j=await W(e,t,r);let i=n;if(Object.entries(j).forEach(([y,F])=>{var S;if(F.isKeyframes||!F.generator)return;const w=F.generator._withBuildContext({name:y,config:g,prod:s}),m=new RegExp(`\\s${y}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(n);if(!m)return console.error("Could not find the original declaration");const b=(S=m.at(1))==null?void 0:S.trim(),P=new RegExp(`\\s${y}[=\\s]+styled\\(`,"g").exec(i);if(!P)return console.error("Could not find the original declaration");const{index:h}=P;let k=!1;const l=setTimeout(()=>k=!0,5e3);let $=0,D=!1,C=0;for(;!D&&!k;){const u=i[h+$];u==="("&&C++,u===")"&&C--,C===0&&u===")"&&(D=!0),$>i.length&&(k=!0),$++}if(!k)clearTimeout(l);else throw new Error("Failed to find the end of the styled call and timed out");const _=h+$,T=i.slice(h,_),d=i,p=` ${y} = styled(${b}, "${w.classNames}", ${JSON.stringify(w.props)});`;i=i.replace(T,p),d===i&&console.error("Minimize file failed to change content",{name:y,tagName:b})}),g.importStrategy==="component"){const y=R.toHash(t,6),F=o.parse(t);i=`import '../../saltygen/css/${`f_${R.dashCase(F.name)}-${y}.css`}';
22
+ ${i}`}return i=i.replace("{ styled }","{ styledClient as styled }"),i=i.replace("@salty-css/react/styled","@salty-css/react/styled-client"),i}}catch(r){console.error("Error in minimizeFile:",r)}};exports.compileSaltyFile=W;exports.generateConfigStyles=se;exports.generateCss=me;exports.generateFile=he;exports.isSaltyFile=I;exports.logError=fe;exports.logger=J;exports.minimizeFile=Se;exports.saltyFileExtensions=A;exports.saltyFileRegExp=te;
@@ -0,0 +1,349 @@
1
+ import * as Y from "esbuild";
2
+ import { execSync as lt } from "child_process";
3
+ import { t as B, d as z } from "./dash-case-DBThphLm.js";
4
+ import { join as r, parse as H } from "path";
5
+ import { existsSync as K, writeFileSync as w, mkdirSync as J, readFileSync as V, statSync as pt, readdirSync as ft } from "fs";
6
+ import { readFile as dt, writeFile as ut } from "fs/promises";
7
+ import { p as U, a as gt, b as mt, c as yt } from "./parse-templates-CgZo0YA1.js";
8
+ import { createLogger as ht, format as I, transports as $t } from "winston";
9
+ const Q = (t) => {
10
+ if (!t || t === "/") throw new Error("Could not find package.json file");
11
+ const e = r(t, "package.json");
12
+ return K(e) ? e : Q(r(t, ".."));
13
+ }, bt = async (t) => {
14
+ const e = Q(t);
15
+ return await dt(e, "utf-8").then(JSON.parse).catch(() => {
16
+ });
17
+ }, St = async (t) => {
18
+ const e = await bt(t);
19
+ if (e)
20
+ return e.type;
21
+ };
22
+ let R;
23
+ const tt = async (t) => {
24
+ if (R) return R;
25
+ const e = await St(t);
26
+ return e === "module" ? R = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (R = "cjs"), R || "esm";
27
+ }, O = ht({
28
+ level: "debug",
29
+ format: I.combine(I.colorize(), I.cli()),
30
+ transports: [new $t.Console({})]
31
+ }), Mt = (t) => {
32
+ O.error(t);
33
+ };
34
+ function et(t) {
35
+ return t ? typeof t != "string" ? et(String(t)) : t.replace(/[\s-]/g, ".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, n) => (n > 0 ? "." : "") + e.toLowerCase()) : "";
36
+ }
37
+ const wt = {
38
+ /** Set box model to border-box */
39
+ "*, *::before, *::after": {
40
+ boxSizing: "border-box"
41
+ },
42
+ /** Remove default margin and padding */
43
+ "*": {
44
+ margin: 0
45
+ },
46
+ /** Remove adjust font properties */
47
+ html: {
48
+ lineHeight: 1.15,
49
+ textSizeAdjust: "100%",
50
+ WebkitFontSmoothing: "antialiased"
51
+ },
52
+ /** Make media elements responsive */
53
+ "img, picture, video, canvas, svg": {
54
+ display: "block",
55
+ maxWidth: "100%"
56
+ },
57
+ /** Avoid overflow of text */
58
+ "p, h1, h2, h3, h4, h5, h6": {
59
+ overflowWrap: "break-word"
60
+ },
61
+ /** Improve text wrapping */
62
+ p: {
63
+ textWrap: "pretty"
64
+ },
65
+ "h1, h2, h3, h4, h5, h6": {
66
+ textWrap: "balance"
67
+ },
68
+ /** Improve link color */
69
+ a: {
70
+ color: "currentColor"
71
+ },
72
+ /** Improve button line height */
73
+ button: {
74
+ lineHeight: "1em",
75
+ color: "currentColor"
76
+ },
77
+ /** Improve form elements */
78
+ "input, optgroup, select, textarea": {
79
+ fontFamily: "inherit",
80
+ fontSize: "100%",
81
+ lineHeight: "1.15em"
82
+ }
83
+ }, A = {
84
+ externalModules: []
85
+ }, st = (t) => {
86
+ if (A.externalModules.length > 0) return A.externalModules;
87
+ const e = r(t, "salty.config.ts"), a = V(e, "utf8").match(/externalModules:\s?\[(.*)\]/);
88
+ if (!a) return [];
89
+ const c = a[1].split(",").map((s) => s.replace(/['"`]/g, "").trim());
90
+ return A.externalModules = c, c;
91
+ }, W = (t) => r(t, "./saltygen"), nt = ["salty", "css", "styles", "styled"], xt = (t = []) => new RegExp(`\\.(${[...nt, ...t].join("|")})\\.`), L = (t, e = []) => xt(e).test(t), Ct = async (t) => {
92
+ const e = W(t), n = r(t, "salty.config.ts"), a = r(e, "salty.config.js"), c = await tt(t), s = st(t);
93
+ await Y.build({
94
+ entryPoints: [n],
95
+ minify: !0,
96
+ treeShaking: !0,
97
+ bundle: !0,
98
+ outfile: a,
99
+ format: c,
100
+ external: s
101
+ });
102
+ const d = Date.now(), { config: u } = await import(`${a}?t=${d}`);
103
+ return u;
104
+ }, Ft = async (t) => {
105
+ const e = await Ct(t), n = /* @__PURE__ */ new Set(), a = (l, p = []) => l ? Object.entries(l).flatMap(([h, f]) => {
106
+ if (!f) return;
107
+ if (typeof f == "object") return a(f, [...p, h]);
108
+ const M = et(h), v = z(h), _ = [...p, M].join(".");
109
+ n.add(`"${_}"`);
110
+ const j = [...p.map(z), v].join("-"), { result: T } = yt(f);
111
+ return `--${j}: ${T};`;
112
+ }) : [], c = (l) => l ? Object.entries(l).flatMap(([p, h]) => {
113
+ const f = a(h);
114
+ return p === "base" ? f.join("") : `${p} { ${f.join("")} }`;
115
+ }) : [], s = (l) => l ? Object.entries(l).flatMap(([p, h]) => Object.entries(h).flatMap(([f, M]) => {
116
+ const v = a(M, [p]), _ = `.${p}-${f}, [data-${p}="${f}"]`, j = v.join("");
117
+ return `${_} { ${j} }`;
118
+ })) : [], d = a(e.variables), u = c(e.responsiveVariables), $ = s(e.conditionalVariables), o = W(t), g = r(o, "css/_variables.css"), C = `:root { ${d.join("")} ${u.join("")} } ${$.join("")}`;
119
+ w(g, C);
120
+ const x = r(o, "css/_global.css"), m = U(e.global, "");
121
+ w(x, `@layer global { ${m} }`);
122
+ const b = r(o, "css/_reset.css"), y = e.reset === "none" ? {} : typeof e.reset == "object" ? e.reset : wt, k = U(y, "");
123
+ w(b, `@layer reset { ${k} }`);
124
+ const i = r(o, "css/_templates.css"), S = gt(e.templates), D = mt(e.templates);
125
+ w(i, S);
126
+ const F = r(o, "types/css-tokens.d.ts"), N = `
127
+ // Variable types
128
+ type VariableTokens = ${[...n].join("|")};
129
+ type PropertyValueToken = \`{\${VariableTokens}}\`;
130
+
131
+ // Template types
132
+ type TemplateTokens = {
133
+ ${Object.entries(D).map(([l, p]) => `${l}?: ${p}`).join(`
134
+ `)}
135
+ }
136
+ `;
137
+ w(F, N);
138
+ }, X = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, n) => {
139
+ const a = /^['"`]/.test(n);
140
+ if (a && console.log("String tag", n), a) return e;
141
+ const c = new RegExp(`import[^;]*${n}[,\\s{][^;]*from\\s?([^{};]+);`), s = c.test(t);
142
+ if (s || console.log("Not imported", n), !s) return e;
143
+ const d = c.exec(t);
144
+ if (d) {
145
+ const u = d.at(1), $ = nt.some((o) => u == null ? void 0 : u.includes(o));
146
+ if ($ && console.log("Salty import for", n, `"${d.at(0)}"`), $) return e;
147
+ }
148
+ return console.log("Replacing", n), "styled('div',";
149
+ }), Z = async (t, e, n) => {
150
+ console.log({ sourceFilePath: e });
151
+ const a = B(e), c = r(n, "./temp");
152
+ K(c) || J(c);
153
+ const s = H(e);
154
+ let d = V(e, "utf8");
155
+ d = X(d);
156
+ const u = r(n, "js", a + ".js"), $ = st(t), o = await tt(t);
157
+ await Y.build({
158
+ stdin: {
159
+ contents: d,
160
+ sourcefile: s.base,
161
+ resolveDir: s.dir,
162
+ loader: "tsx"
163
+ },
164
+ minify: !1,
165
+ treeShaking: !0,
166
+ bundle: !0,
167
+ outfile: u,
168
+ format: o,
169
+ target: ["node20"],
170
+ keepNames: !0,
171
+ external: $,
172
+ packages: "external",
173
+ plugins: [
174
+ {
175
+ name: "test",
176
+ setup: (x) => {
177
+ x.onLoad({ filter: /.*.css.ts/ }, (m) => {
178
+ console.log("Loading", {
179
+ sourceFilePath: e,
180
+ args: m
181
+ });
182
+ const b = V(m.path, "utf8");
183
+ return { contents: X(b) };
184
+ });
185
+ }
186
+ }
187
+ ]
188
+ });
189
+ const g = Date.now();
190
+ return await import(`${u}?t=${g}`);
191
+ }, G = async (t) => {
192
+ const e = W(t), n = r(e, "salty.config.js"), a = Date.now(), { config: c } = await import(`${n}?t=${a}`);
193
+ return c;
194
+ }, ot = () => {
195
+ try {
196
+ return process.env.NODE_ENV === "production";
197
+ } catch {
198
+ return !1;
199
+ }
200
+ }, _t = async (t, e = ot()) => {
201
+ try {
202
+ const n = Date.now();
203
+ e ? O.info("Generating CSS in production mode! 🔥") : O.info("Generating CSS in development mode! 🚀");
204
+ const a = [], c = [], s = W(t), d = r(s, "index.css");
205
+ (() => {
206
+ K(s) && lt("rm -rf " + s), J(s), J(r(s, "css")), J(r(s, "types"));
207
+ })(), await Ft(t);
208
+ const $ = await G(t);
209
+ async function o(i, S) {
210
+ const D = ["node_modules", "saltygen"], F = pt(i);
211
+ if (F.isDirectory()) {
212
+ const E = ft(i);
213
+ if (D.some((l) => i.includes(l))) return;
214
+ await Promise.all(E.map((l) => o(r(i, l), r(S, l))));
215
+ } else if (F.isFile() && L(i)) {
216
+ const N = await Z(t, i, s), l = [];
217
+ Object.entries(N).forEach(([_, j]) => {
218
+ if (j.isKeyframes && j.css) {
219
+ const q = `a_${j.animationName}.css`, ct = `css/${q}`, it = r(s, ct);
220
+ a.push(q), w(it, j.css);
221
+ return;
222
+ }
223
+ if (!j.generator) return;
224
+ const T = j.generator._withBuildContext({
225
+ name: _,
226
+ config: $,
227
+ prod: e
228
+ });
229
+ c[T.priority] || (c[T.priority] = []), c[T.priority].push(T.cssFileName), l.push(T.cssFileName);
230
+ const rt = `css/${T.cssFileName}`, at = r(s, rt);
231
+ w(at, T.css);
232
+ });
233
+ const p = l.map((_) => `@import url('./${_}');`).join(`
234
+ `), h = B(i, 6), f = H(i), M = z(f.name), v = r(s, `css/f_${M}-${h}.css`);
235
+ w(v, p);
236
+ }
237
+ }
238
+ await o(t, s);
239
+ const g = a.map((i) => `@import url('./css/${i}');`).join(`
240
+ `);
241
+ let b = `@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
242
+
243
+ ${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((i) => {
244
+ try {
245
+ return V(r(s, "css", i), "utf8").length > 0;
246
+ } catch {
247
+ return !1;
248
+ }
249
+ }).map((i) => `@import url('./css/${i}');`).join(`
250
+ `)}
251
+ ${g}`;
252
+ if ($.importStrategy !== "component") {
253
+ const i = c.reduce((S, D, F) => {
254
+ const E = D.reduce((h, f) => {
255
+ const M = V(r(s, "css", f), "utf8");
256
+ return `${h}
257
+ ${M}`;
258
+ }, ""), N = `l_${F}.css`, l = r(s, "css", N), p = `@layer l${F} { ${E} }`;
259
+ return w(l, p), `${S}
260
+ @import url('./css/${N}');`;
261
+ }, "");
262
+ b += i;
263
+ }
264
+ w(d, b);
265
+ const y = Date.now() - n, k = y < 200 ? "🔥" : y < 500 ? "🚀" : y < 1e3 ? "🎉" : y < 2e3 ? "🚗" : y < 5e3 ? "🤔" : "🥴";
266
+ O.info(`Generated CSS in ${y}ms! ${k}`);
267
+ } catch (n) {
268
+ console.error(n);
269
+ }
270
+ }, Vt = async (t, e) => {
271
+ try {
272
+ const n = [], a = r(t, "./saltygen"), c = r(a, "index.css");
273
+ if (L(e)) {
274
+ const d = await G(t), u = await Z(t, e, a);
275
+ Object.entries(u).forEach(([x, m]) => {
276
+ if (m.isKeyframes && m.css) {
277
+ const i = `css/${`a_${m.animationName}.css`}`, S = r(a, i);
278
+ w(S, m.css);
279
+ return;
280
+ }
281
+ if (!m.generator) return;
282
+ const b = m.generator._withBuildContext({
283
+ name: x,
284
+ config: d
285
+ }), P = `css/${b.cssFileName}`, y = r(a, P);
286
+ n.push(b.cssFileName), w(y, b.css);
287
+ });
288
+ const $ = V(c, "utf8").split(`
289
+ `), o = n.map((x) => `@import url('../saltygen/css/${x}');`), C = [.../* @__PURE__ */ new Set([...$, ...o])].join(`
290
+ `);
291
+ w(c, C);
292
+ }
293
+ } catch (n) {
294
+ console.error(n);
295
+ }
296
+ }, Rt = async (t, e, n = ot()) => {
297
+ try {
298
+ const a = r(t, "./saltygen");
299
+ if (L(e)) {
300
+ const s = V(e, "utf8");
301
+ s.replace(/^(?!export\s)const\s.*/gm, (g) => `export ${g}`) !== s && await ut(e, s);
302
+ const u = await G(t), $ = await Z(t, e, a);
303
+ let o = s;
304
+ if (Object.entries($).forEach(([g, C]) => {
305
+ var h;
306
+ if (C.isKeyframes || !C.generator) return;
307
+ const x = C.generator._withBuildContext({
308
+ name: g,
309
+ config: u,
310
+ prod: n
311
+ }), m = new RegExp(`\\s${g}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(s);
312
+ if (!m) return console.error("Could not find the original declaration");
313
+ const b = (h = m.at(1)) == null ? void 0 : h.trim(), P = new RegExp(`\\s${g}[=\\s]+styled\\(`, "g").exec(o);
314
+ if (!P) return console.error("Could not find the original declaration");
315
+ const { index: y } = P;
316
+ let k = !1;
317
+ const i = setTimeout(() => k = !0, 5e3);
318
+ let S = 0, D = !1, F = 0;
319
+ for (; !D && !k; ) {
320
+ const f = o[y + S];
321
+ f === "(" && F++, f === ")" && F--, F === 0 && f === ")" && (D = !0), S > o.length && (k = !0), S++;
322
+ }
323
+ if (!k) clearTimeout(i);
324
+ else throw new Error("Failed to find the end of the styled call and timed out");
325
+ const E = y + S, N = o.slice(y, E), l = o, p = ` ${g} = styled(${b}, "${x.classNames}", ${JSON.stringify(x.props)});`;
326
+ o = o.replace(N, p), l === o && console.error("Minimize file failed to change content", { name: g, tagName: b });
327
+ }), u.importStrategy === "component") {
328
+ const g = B(e, 6), C = H(e);
329
+ o = `import '../../saltygen/css/${`f_${z(C.name)}-${g}.css`}';
330
+ ${o}`;
331
+ }
332
+ return o = o.replace("{ styled }", "{ styledClient as styled }"), o = o.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), o;
333
+ }
334
+ } catch (a) {
335
+ console.error("Error in minimizeFile:", a);
336
+ }
337
+ };
338
+ export {
339
+ Mt as a,
340
+ xt as b,
341
+ Ft as c,
342
+ Z as d,
343
+ Vt as e,
344
+ _t as g,
345
+ L as i,
346
+ O as l,
347
+ Rt as m,
348
+ nt as s
349
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/core",
3
- "version": "0.0.1-alpha.139",
3
+ "version": "0.0.1-alpha.140",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",
@@ -1,22 +0,0 @@
1
- "use strict";const ce=require("esbuild"),ae=require("child_process"),R=require("./dash-case-BJEkFEGQ.cjs"),s=require("path"),c=require("fs"),Z=require("fs/promises"),v=require("./parse-templates-DD4hQEpv.cjs"),z=require("winston");var H=typeof document<"u"?document.currentScript:null;function le(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const o in e)if(o!=="default"){const r=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(t,o,r.get?r:{enumerable:!0,get:()=>e[o]})}}return t.default=e,Object.freeze(t)}const G=le(ce),U=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=s.join(e,"package.json");return c.existsSync(t)?t:U(s.join(e,".."))},pe=async e=>{const t=U(e);return await Z.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},ue=async e=>{const t=await pe(e);if(t)return t.type};let O;const X=async e=>{if(O)return O;const t=await ue(e);return t==="module"?O="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:H&&H.tagName.toUpperCase()==="SCRIPT"&&H.src||new URL("index-BcxXTbUt.cjs",document.baseURI).href).endsWith(".cjs"))&&(O="cjs"),O||"esm"},J=z.createLogger({level:"debug",format:z.format.combine(z.format.colorize(),z.format.cli()),transports:[new z.transports.Console({})]}),de=e=>{J.error(e)};function Y(e){return e?typeof e!="string"?Y(String(e)):e.replace(/[\s-]/g,".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(t,o)=>(o>0?".":"")+t.toLowerCase()):""}const fe={"*, *::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"}},A={externalModules:[]},Q=e=>{if(A.externalModules.length>0)return A.externalModules;const t=s.join(e,"salty.config.ts"),r=c.readFileSync(t,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!r)return[];const p=r[1].split(",").map(n=>n.replace(/['"`]/g,"").trim());return A.externalModules=p,p},q=e=>s.join(e,"./saltygen"),B=["salty","css","styles","styled"],ee=(e=[])=>new RegExp(`\\.(${[...B,...e].join("|")})\\.`),I=(e,t=[])=>ee(t).test(e),ye=async e=>{const t=q(e),o=s.join(e,"salty.config.ts"),r=s.join(t,"salty.config.js"),p=await X(e),n=Q(e);await G.build({entryPoints:[o],minify:!0,treeShaking:!0,bundle:!0,outfile:r,format:p,external:n});const h=Date.now(),{config:F}=await import(`${r}?t=${h}`);return F},te=async e=>{const t=await ye(e),o=new Set,r=(l,d=[])=>l?Object.entries(l).flatMap(([j,f])=>{if(!f)return;if(typeof f=="object")return r(f,[...d,j]);const E=Y(j),V=R.dashCase(j),M=[...d,E].join(".");o.add(`"${M}"`);const P=[...d.map(R.dashCase),V].join("-"),{result:D}=v.parseValueTokens(f);return`--${P}: ${D};`}):[],p=l=>l?Object.entries(l).flatMap(([d,j])=>{const f=r(j);return d==="base"?f.join(""):`${d} { ${f.join("")} }`}):[],n=l=>l?Object.entries(l).flatMap(([d,j])=>Object.entries(j).flatMap(([f,E])=>{const V=r(E,[d]),M=`.${d}-${f}, [data-${d}="${f}"]`,P=V.join("");return`${M} { ${P} }`})):[],h=r(t.variables),F=p(t.responsiveVariables),x=n(t.conditionalVariables),i=q(e),g=s.join(i,"css/_variables.css"),$=`:root { ${h.join("")} ${F.join("")} } ${x.join("")}`;c.writeFileSync(g,$);const S=s.join(i,"css/_global.css"),u=v.parseStyles(t.global,"");c.writeFileSync(S,`@layer global { ${u} }`);const w=s.join(i,"css/_reset.css"),y=t.reset==="none"?{}:typeof t.reset=="object"?t.reset:fe,b=v.parseStyles(y,"");c.writeFileSync(w,`@layer reset { ${b} }`);const a=s.join(i,"css/_templates.css"),m=v.parseTemplates(t.templates),k=v.getTemplateTypes(t.templates);c.writeFileSync(a,m);const C=s.join(i,"types/css-tokens.d.ts"),N=`
2
- // Variable types
3
- type VariableTokens = ${[...o].join("|")};
4
- type PropertyValueToken = \`{\${VariableTokens}}\`;
5
-
6
- // Template types
7
- type TemplateTokens = {
8
- ${Object.entries(k).map(([l,d])=>`${l}?: ${d}`).join(`
9
- `)}
10
- }
11
- `;c.writeFileSync(C,N)},W=async(e,t,o)=>{const r=R.toHash(t),p=s.join(o,"./temp");c.existsSync(p)||c.mkdirSync(p);const n=s.parse(t);let h=c.readFileSync(t,"utf8");h=h.replace(/styled\(([^"'`{,]+),/g,(S,u)=>{if(/^['"`]/.test(u))return S;const T=new RegExp(`import[^;]*${u}[,\\s{][^;]*from\\s?([^{};]+);`),y=T.test(h);if(y||console.log("Not imported",u),!y)return S;const b=T.exec(h);if(b){const a=b.at(1),m=B.some(k=>a==null?void 0:a.includes(k));if(m&&console.log("Salty import",u,b.at(0)),m)return S}return console.log("Replacing",u),"styled('div',"});const F=s.join(o,"js",r+".js"),x=Q(e),i=await X(e);await G.build({stdin:{contents:h,sourcefile:n.base,resolveDir:n.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:F,format:i,target:["node20"],keepNames:!0,external:x,packages:"external"});const g=Date.now();return await import(`${F}?t=${g}`)},K=async e=>{const t=q(e),o=s.join(t,"salty.config.js"),r=Date.now(),{config:p}=await import(`${o}?t=${r}`);return p},se=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},ge=async(e,t=se())=>{try{const o=Date.now();t?J.info("Generating CSS in production mode! 🔥"):J.info("Generating CSS in development mode! 🚀");const r=[],p=[],n=q(e),h=s.join(n,"index.css");(()=>{c.existsSync(n)&&ae.execSync("rm -rf "+n),c.mkdirSync(n),c.mkdirSync(s.join(n,"css")),c.mkdirSync(s.join(n,"types"))})(),await te(e);const x=await K(e);async function i(a,m){const k=["node_modules","saltygen"],C=c.statSync(a);if(C.isDirectory()){const _=c.readdirSync(a);if(k.some(l=>a.includes(l)))return;await Promise.all(_.map(l=>i(s.join(a,l),s.join(m,l))))}else if(C.isFile()&&I(a)){const N=await W(e,a,n),l=[];Object.entries(N).forEach(([M,P])=>{if(P.isKeyframes&&P.css){const L=`a_${P.animationName}.css`,re=`css/${L}`,ie=s.join(n,re);r.push(L),c.writeFileSync(ie,P.css);return}if(!P.generator)return;const D=P.generator._withBuildContext({name:M,config:x,prod:t});p[D.priority]||(p[D.priority]=[]),p[D.priority].push(D.cssFileName),l.push(D.cssFileName);const ne=`css/${D.cssFileName}`,oe=s.join(n,ne);c.writeFileSync(oe,D.css)});const d=l.map(M=>`@import url('./${M}');`).join(`
12
- `),j=R.toHash(a,6),f=s.parse(a),E=R.dashCase(f.name),V=s.join(n,`css/f_${E}-${j}.css`);c.writeFileSync(V,d)}}await i(e,n);const g=r.map(a=>`@import url('./css/${a}');`).join(`
13
- `);let w=`@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
14
-
15
- ${["_variables.css","_reset.css","_global.css","_templates.css"].filter(a=>{try{return c.readFileSync(s.join(n,"css",a),"utf8").length>0}catch{return!1}}).map(a=>`@import url('./css/${a}');`).join(`
16
- `)}
17
- ${g}`;if(x.importStrategy!=="component"){const a=p.reduce((m,k,C)=>{const _=k.reduce((j,f)=>{const E=c.readFileSync(s.join(n,"css",f),"utf8");return`${j}
18
- ${E}`},""),N=`l_${C}.css`,l=s.join(n,"css",N),d=`@layer l${C} { ${_} }`;return c.writeFileSync(l,d),`${m}
19
- @import url('./css/${N}');`},"");w+=a}c.writeFileSync(h,w);const y=Date.now()-o,b=y<200?"🔥":y<500?"🚀":y<1e3?"🎉":y<2e3?"🚗":y<5e3?"🤔":"🥴";J.info(`Generated CSS in ${y}ms! ${b}`)}catch(o){console.error(o)}},me=async(e,t)=>{try{const o=[],r=s.join(e,"./saltygen"),p=s.join(r,"index.css");if(I(t)){const h=await K(e),F=await W(e,t,r);Object.entries(F).forEach(([S,u])=>{if(u.isKeyframes&&u.css){const a=`css/${`a_${u.animationName}.css`}`,m=s.join(r,a);c.writeFileSync(m,u.css);return}if(!u.generator)return;const w=u.generator._withBuildContext({name:S,config:h}),T=`css/${w.cssFileName}`,y=s.join(r,T);o.push(w.cssFileName),c.writeFileSync(y,w.css)});const x=c.readFileSync(p,"utf8").split(`
20
- `),i=o.map(S=>`@import url('../saltygen/css/${S}');`),$=[...new Set([...x,...i])].join(`
21
- `);c.writeFileSync(p,$)}}catch(o){console.error(o)}},he=async(e,t,o=se())=>{try{const r=s.join(e,"./saltygen");if(I(t)){const n=c.readFileSync(t,"utf8");n.replace(/^(?!export\s)const\s.*/gm,g=>`export ${g}`)!==n&&await Z.writeFile(t,n);const F=await K(e),x=await W(e,t,r);let i=n;if(Object.entries(x).forEach(([g,$])=>{var j;if($.isKeyframes||!$.generator)return;const S=$.generator._withBuildContext({name:g,config:F,prod:o}),u=new RegExp(`\\s${g}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(n);if(!u)return console.error("Could not find the original declaration");const w=(j=u.at(1))==null?void 0:j.trim(),T=new RegExp(`\\s${g}[=\\s]+styled\\(`,"g").exec(i);if(!T)return console.error("Could not find the original declaration");const{index:y}=T;let b=!1;const a=setTimeout(()=>b=!0,5e3);let m=0,k=!1,C=0;for(;!k&&!b;){const f=i[y+m];f==="("&&C++,f===")"&&C--,C===0&&f===")"&&(k=!0),m>i.length&&(b=!0),m++}if(!b)clearTimeout(a);else throw new Error("Failed to find the end of the styled call and timed out");const _=y+m,N=i.slice(y,_),l=i,d=` ${g} = styled(${w}, "${S.classNames}", ${JSON.stringify(S.props)});`;i=i.replace(N,d),l===i&&console.error("Minimize file failed to change content",{name:g,tagName:w})}),F.importStrategy==="component"){const g=R.toHash(t,6),$=s.parse(t);i=`import '../../saltygen/css/${`f_${R.dashCase($.name)}-${g}.css`}';
22
- ${i}`}return i=i.replace("{ styled }","{ styledClient as styled }"),i=i.replace("@salty-css/react/styled","@salty-css/react/styled-client"),i}}catch(r){console.error("Error in minimizeFile:",r)}};exports.compileSaltyFile=W;exports.generateConfigStyles=te;exports.generateCss=ge;exports.generateFile=me;exports.isSaltyFile=I;exports.logError=de;exports.logger=J;exports.minimizeFile=he;exports.saltyFileExtensions=B;exports.saltyFileRegExp=ee;
package/index-DivhXuS6.js DELETED
@@ -1,332 +0,0 @@
1
- import * as X from "esbuild";
2
- import { execSync as ie } from "child_process";
3
- import { t as B, d as z } from "./dash-case-DBThphLm.js";
4
- import { join as n, parse as H } from "path";
5
- import { existsSync as K, writeFileSync as S, mkdirSync as J, readFileSync as R, statSync as le, readdirSync as pe } from "fs";
6
- import { readFile as fe, writeFile as ue } from "fs/promises";
7
- import { p as U, a as de, b as ge, c as me } from "./parse-templates-CgZo0YA1.js";
8
- import { createLogger as ye, format as I, transports as he } from "winston";
9
- const Y = (e) => {
10
- if (!e || e === "/") throw new Error("Could not find package.json file");
11
- const t = n(e, "package.json");
12
- return K(t) ? t : Y(n(e, ".."));
13
- }, $e = async (e) => {
14
- const t = Y(e);
15
- return await fe(t, "utf-8").then(JSON.parse).catch(() => {
16
- });
17
- }, be = async (e) => {
18
- const t = await $e(e);
19
- if (t)
20
- return t.type;
21
- };
22
- let V;
23
- const Q = async (e) => {
24
- if (V) return V;
25
- const t = await be(e);
26
- return t === "module" ? V = "esm" : (t === "commonjs" || import.meta.url.endsWith(".cjs")) && (V = "cjs"), V || "esm";
27
- }, O = ye({
28
- level: "debug",
29
- format: I.combine(I.colorize(), I.cli()),
30
- transports: [new he.Console({})]
31
- }), Ee = (e) => {
32
- O.error(e);
33
- };
34
- function ee(e) {
35
- return e ? typeof e != "string" ? ee(String(e)) : e.replace(/[\s-]/g, ".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (t, c) => (c > 0 ? "." : "") + t.toLowerCase()) : "";
36
- }
37
- const Se = {
38
- /** Set box model to border-box */
39
- "*, *::before, *::after": {
40
- boxSizing: "border-box"
41
- },
42
- /** Remove default margin and padding */
43
- "*": {
44
- margin: 0
45
- },
46
- /** Remove adjust font properties */
47
- html: {
48
- lineHeight: 1.15,
49
- textSizeAdjust: "100%",
50
- WebkitFontSmoothing: "antialiased"
51
- },
52
- /** Make media elements responsive */
53
- "img, picture, video, canvas, svg": {
54
- display: "block",
55
- maxWidth: "100%"
56
- },
57
- /** Avoid overflow of text */
58
- "p, h1, h2, h3, h4, h5, h6": {
59
- overflowWrap: "break-word"
60
- },
61
- /** Improve text wrapping */
62
- p: {
63
- textWrap: "pretty"
64
- },
65
- "h1, h2, h3, h4, h5, h6": {
66
- textWrap: "balance"
67
- },
68
- /** Improve link color */
69
- a: {
70
- color: "currentColor"
71
- },
72
- /** Improve button line height */
73
- button: {
74
- lineHeight: "1em",
75
- color: "currentColor"
76
- },
77
- /** Improve form elements */
78
- "input, optgroup, select, textarea": {
79
- fontFamily: "inherit",
80
- fontSize: "100%",
81
- lineHeight: "1.15em"
82
- }
83
- }, A = {
84
- externalModules: []
85
- }, te = (e) => {
86
- if (A.externalModules.length > 0) return A.externalModules;
87
- const t = n(e, "salty.config.ts"), r = R(t, "utf8").match(/externalModules:\s?\[(.*)\]/);
88
- if (!r) return [];
89
- const l = r[1].split(",").map((s) => s.replace(/['"`]/g, "").trim());
90
- return A.externalModules = l, l;
91
- }, W = (e) => n(e, "./saltygen"), se = ["salty", "css", "styles", "styled"], we = (e = []) => new RegExp(`\\.(${[...se, ...e].join("|")})\\.`), Z = (e, t = []) => we(t).test(e), xe = async (e) => {
92
- const t = W(e), c = n(e, "salty.config.ts"), r = n(t, "salty.config.js"), l = await Q(e), s = te(e);
93
- await X.build({
94
- entryPoints: [c],
95
- minify: !0,
96
- treeShaking: !0,
97
- bundle: !0,
98
- outfile: r,
99
- format: l,
100
- external: s
101
- });
102
- const y = Date.now(), { config: w } = await import(`${r}?t=${y}`);
103
- return w;
104
- }, Fe = async (e) => {
105
- const t = await xe(e), c = /* @__PURE__ */ new Set(), r = (i, f = []) => i ? Object.entries(i).flatMap(([$, u]) => {
106
- if (!u) return;
107
- if (typeof u == "object") return r(u, [...f, $]);
108
- const M = ee($), v = z($), _ = [...f, M].join(".");
109
- c.add(`"${_}"`);
110
- const N = [...f.map(z), v].join("-"), { result: T } = me(u);
111
- return `--${N}: ${T};`;
112
- }) : [], l = (i) => i ? Object.entries(i).flatMap(([f, $]) => {
113
- const u = r($);
114
- return f === "base" ? u.join("") : `${f} { ${u.join("")} }`;
115
- }) : [], s = (i) => i ? Object.entries(i).flatMap(([f, $]) => Object.entries($).flatMap(([u, M]) => {
116
- const v = r(M, [f]), _ = `.${f}-${u}, [data-${f}="${u}"]`, N = v.join("");
117
- return `${_} { ${N} }`;
118
- })) : [], y = r(t.variables), w = l(t.responsiveVariables), j = s(t.conditionalVariables), o = W(e), g = n(o, "css/_variables.css"), F = `:root { ${y.join("")} ${w.join("")} } ${j.join("")}`;
119
- S(g, F);
120
- const h = n(o, "css/_global.css"), p = U(t.global, "");
121
- S(h, `@layer global { ${p} }`);
122
- const x = n(o, "css/_reset.css"), d = t.reset === "none" ? {} : typeof t.reset == "object" ? t.reset : Se, b = U(d, "");
123
- S(x, `@layer reset { ${b} }`);
124
- const a = n(o, "css/_templates.css"), m = de(t.templates), k = ge(t.templates);
125
- S(a, m);
126
- const C = n(o, "types/css-tokens.d.ts"), D = `
127
- // Variable types
128
- type VariableTokens = ${[...c].join("|")};
129
- type PropertyValueToken = \`{\${VariableTokens}}\`;
130
-
131
- // Template types
132
- type TemplateTokens = {
133
- ${Object.entries(k).map(([i, f]) => `${i}?: ${f}`).join(`
134
- `)}
135
- }
136
- `;
137
- S(C, D);
138
- }, G = async (e, t, c) => {
139
- const r = B(t), l = n(c, "./temp");
140
- K(l) || J(l);
141
- const s = H(t);
142
- let y = R(t, "utf8");
143
- y = y.replace(/styled\(([^"'`{,]+),/g, (h, p) => {
144
- if (/^['"`]/.test(p)) return h;
145
- const P = new RegExp(`import[^;]*${p}[,\\s{][^;]*from\\s?([^{};]+);`), d = P.test(y);
146
- if (d || console.log("Not imported", p), !d) return h;
147
- const b = P.exec(y);
148
- if (b) {
149
- const a = b.at(1), m = se.some((k) => a == null ? void 0 : a.includes(k));
150
- if (m && console.log("Salty import", p, b.at(0)), m) return h;
151
- }
152
- return console.log("Replacing", p), "styled('div',";
153
- });
154
- const w = n(c, "js", r + ".js"), j = te(e), o = await Q(e);
155
- await X.build({
156
- stdin: {
157
- contents: y,
158
- sourcefile: s.base,
159
- resolveDir: s.dir,
160
- loader: "tsx"
161
- },
162
- minify: !1,
163
- treeShaking: !0,
164
- bundle: !0,
165
- outfile: w,
166
- format: o,
167
- target: ["node20"],
168
- keepNames: !0,
169
- external: j,
170
- packages: "external"
171
- });
172
- const g = Date.now();
173
- return await import(`${w}?t=${g}`);
174
- }, L = async (e) => {
175
- const t = W(e), c = n(t, "salty.config.js"), r = Date.now(), { config: l } = await import(`${c}?t=${r}`);
176
- return l;
177
- }, ne = () => {
178
- try {
179
- return process.env.NODE_ENV === "production";
180
- } catch {
181
- return !1;
182
- }
183
- }, Me = async (e, t = ne()) => {
184
- try {
185
- const c = Date.now();
186
- t ? O.info("Generating CSS in production mode! 🔥") : O.info("Generating CSS in development mode! 🚀");
187
- const r = [], l = [], s = W(e), y = n(s, "index.css");
188
- (() => {
189
- K(s) && ie("rm -rf " + s), J(s), J(n(s, "css")), J(n(s, "types"));
190
- })(), await Fe(e);
191
- const j = await L(e);
192
- async function o(a, m) {
193
- const k = ["node_modules", "saltygen"], C = le(a);
194
- if (C.isDirectory()) {
195
- const E = pe(a);
196
- if (k.some((i) => a.includes(i))) return;
197
- await Promise.all(E.map((i) => o(n(a, i), n(m, i))));
198
- } else if (C.isFile() && Z(a)) {
199
- const D = await G(e, a, s), i = [];
200
- Object.entries(D).forEach(([_, N]) => {
201
- if (N.isKeyframes && N.css) {
202
- const q = `a_${N.animationName}.css`, ae = `css/${q}`, ce = n(s, ae);
203
- r.push(q), S(ce, N.css);
204
- return;
205
- }
206
- if (!N.generator) return;
207
- const T = N.generator._withBuildContext({
208
- name: _,
209
- config: j,
210
- prod: t
211
- });
212
- l[T.priority] || (l[T.priority] = []), l[T.priority].push(T.cssFileName), i.push(T.cssFileName);
213
- const oe = `css/${T.cssFileName}`, re = n(s, oe);
214
- S(re, T.css);
215
- });
216
- const f = i.map((_) => `@import url('./${_}');`).join(`
217
- `), $ = B(a, 6), u = H(a), M = z(u.name), v = n(s, `css/f_${M}-${$}.css`);
218
- S(v, f);
219
- }
220
- }
221
- await o(e, s);
222
- const g = r.map((a) => `@import url('./css/${a}');`).join(`
223
- `);
224
- let x = `@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
225
-
226
- ${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((a) => {
227
- try {
228
- return R(n(s, "css", a), "utf8").length > 0;
229
- } catch {
230
- return !1;
231
- }
232
- }).map((a) => `@import url('./css/${a}');`).join(`
233
- `)}
234
- ${g}`;
235
- if (j.importStrategy !== "component") {
236
- const a = l.reduce((m, k, C) => {
237
- const E = k.reduce(($, u) => {
238
- const M = R(n(s, "css", u), "utf8");
239
- return `${$}
240
- ${M}`;
241
- }, ""), D = `l_${C}.css`, i = n(s, "css", D), f = `@layer l${C} { ${E} }`;
242
- return S(i, f), `${m}
243
- @import url('./css/${D}');`;
244
- }, "");
245
- x += a;
246
- }
247
- S(y, x);
248
- const d = Date.now() - c, b = d < 200 ? "🔥" : d < 500 ? "🚀" : d < 1e3 ? "🎉" : d < 2e3 ? "🚗" : d < 5e3 ? "🤔" : "🥴";
249
- O.info(`Generated CSS in ${d}ms! ${b}`);
250
- } catch (c) {
251
- console.error(c);
252
- }
253
- }, _e = async (e, t) => {
254
- try {
255
- const c = [], r = n(e, "./saltygen"), l = n(r, "index.css");
256
- if (Z(t)) {
257
- const y = await L(e), w = await G(e, t, r);
258
- Object.entries(w).forEach(([h, p]) => {
259
- if (p.isKeyframes && p.css) {
260
- const a = `css/${`a_${p.animationName}.css`}`, m = n(r, a);
261
- S(m, p.css);
262
- return;
263
- }
264
- if (!p.generator) return;
265
- const x = p.generator._withBuildContext({
266
- name: h,
267
- config: y
268
- }), P = `css/${x.cssFileName}`, d = n(r, P);
269
- c.push(x.cssFileName), S(d, x.css);
270
- });
271
- const j = R(l, "utf8").split(`
272
- `), o = c.map((h) => `@import url('../saltygen/css/${h}');`), F = [.../* @__PURE__ */ new Set([...j, ...o])].join(`
273
- `);
274
- S(l, F);
275
- }
276
- } catch (c) {
277
- console.error(c);
278
- }
279
- }, Ve = async (e, t, c = ne()) => {
280
- try {
281
- const r = n(e, "./saltygen");
282
- if (Z(t)) {
283
- const s = R(t, "utf8");
284
- s.replace(/^(?!export\s)const\s.*/gm, (g) => `export ${g}`) !== s && await ue(t, s);
285
- const w = await L(e), j = await G(e, t, r);
286
- let o = s;
287
- if (Object.entries(j).forEach(([g, F]) => {
288
- var $;
289
- if (F.isKeyframes || !F.generator) return;
290
- const h = F.generator._withBuildContext({
291
- name: g,
292
- config: w,
293
- prod: c
294
- }), p = new RegExp(`\\s${g}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(s);
295
- if (!p) return console.error("Could not find the original declaration");
296
- const x = ($ = p.at(1)) == null ? void 0 : $.trim(), P = new RegExp(`\\s${g}[=\\s]+styled\\(`, "g").exec(o);
297
- if (!P) return console.error("Could not find the original declaration");
298
- const { index: d } = P;
299
- let b = !1;
300
- const a = setTimeout(() => b = !0, 5e3);
301
- let m = 0, k = !1, C = 0;
302
- for (; !k && !b; ) {
303
- const u = o[d + m];
304
- u === "(" && C++, u === ")" && C--, C === 0 && u === ")" && (k = !0), m > o.length && (b = !0), m++;
305
- }
306
- if (!b) clearTimeout(a);
307
- else throw new Error("Failed to find the end of the styled call and timed out");
308
- const E = d + m, D = o.slice(d, E), i = o, f = ` ${g} = styled(${x}, "${h.classNames}", ${JSON.stringify(h.props)});`;
309
- o = o.replace(D, f), i === o && console.error("Minimize file failed to change content", { name: g, tagName: x });
310
- }), w.importStrategy === "component") {
311
- const g = B(t, 6), F = H(t);
312
- o = `import '../../saltygen/css/${`f_${z(F.name)}-${g}.css`}';
313
- ${o}`;
314
- }
315
- return o = o.replace("{ styled }", "{ styledClient as styled }"), o = o.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), o;
316
- }
317
- } catch (r) {
318
- console.error("Error in minimizeFile:", r);
319
- }
320
- };
321
- export {
322
- Ee as a,
323
- we as b,
324
- Fe as c,
325
- G as d,
326
- _e as e,
327
- Me as g,
328
- Z as i,
329
- O as l,
330
- Ve as m,
331
- se as s
332
- };