@salty-css/core 0.0.1-alpha.128 → 0.0.1-alpha.129

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