@salty-css/webpack 0.0.1-alpha.201 → 0.0.1-alpha.202

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.
@@ -1,44 +0,0 @@
1
- "use strict";const xe=require("esbuild"),Ne=require("child_process"),l=require("path"),u=require("fs"),oe=require("fs/promises"),B=require("winston");var se=typeof document<"u"?document.currentScript:null;function Pe(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,n.get?n:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const de=Pe(xe),fe=e=>String.fromCharCode(e+(e>25?39:97)),ke=(e,t)=>{let s="",n;for(n=Math.abs(e);n>52;n=n/52|0)s=fe(n%52)+s;return s=fe(n%52)+s,s.length<t?s=s.padStart(t,"a"):s.length>t&&(s=s.slice(-t)),s},De=(e,t)=>{let s=t.length;for(;s;)e=e*33^t.charCodeAt(--s);return e},Z=(e,t=5)=>{const s=De(5381,JSON.stringify(e))>>>0;return ke(s,t)};function E(e){return e?typeof e!="string"?E(String(e)):e.replace(/[\s.]/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(t,s)=>(s>0?"-":"")+t.toLowerCase()):""}const _e=(e,t)=>{if(typeof e!="string")return{result:e};if(!t)return{result:e};const s=[];return Object.values(t).forEach(n=>{const{pattern:o,transform:a}=n;e=e.replace(o,i=>{const{value:p,css:r}=a(i);return r&&s.push(r),p})}),{result:e,additionalCss:s}},pe=e=>typeof e!="string"?{result:e}:/\{[^{}]+\}/g.test(e)?{result:e.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${E(n[1].replaceAll(".","-"))})`)}:{result:e},Oe=["top","right","bottom","left","min-width",/.*width.*/,/^[^line]*height.*/,/padding.*/,/margin.*/,/border.*/,/inset.*/,/.*radius.*/,/.*spacing.*/,/.*gap.*/,/.*indent.*/,/.*offset.*/,/.*size.*/,/.*thickness.*/,/.*font-size.*/],Te=(e,t,s)=>Oe.some(o=>typeof o=="string"?o===e:o.test(e))?`${t}px`:`${t}`,Ee=["Webkit","Moz","ms","O"],Ve=e=>e.startsWith("-")?e:Ee.some(t=>e.startsWith(t))?`-${E(e)}`:E(e),z=(e,t,s)=>{if(!e)return"";const n=[],o=Object.entries(e).reduce((i,[p,r])=>{const c=p.trim(),y=Ve(c),m=(j,D=";")=>i=`${i}${j}${D}`,g=j=>m(`${y}:${j}`);if(typeof r=="function"&&(r=r()),typeof r=="object"){if(!r)return i;if(r.isColor)return g(r.toString()),i;if(c==="variants")return Object.entries(r).forEach(([_,x])=>{x&&Object.entries(x).forEach(([T,P])=>{if(!P)return;const V=`${t}.${_}-${T}`,f=z(P,V);n.push(f)})}),i;if(c==="defaultVariants")return i;if(c==="compoundVariants")return r.forEach(_=>{const{css:x,...T}=_,P=Object.entries(T).reduce((f,[h,$])=>`${f}.${h}-${$}`,t),V=z(x,P);n.push(V)}),i;if(c.startsWith("@")){const _=c,x=z(r,t),T=`${_} {
2
- ${x.replace(`
3
- `,`
4
- `)}
5
- }`;return n.push(T),i}const j=p.includes("&")?c.replace("&",t):c.startsWith(":")?`${t}${c}`:`${t} ${c}`,D=z(r,j);return n.push(D),i}if(typeof r=="number"){const j=Te(y,r);return g(j)}if(typeof r!="string")if("toString"in r)r=r.toString();else return i;const{modifiers:b}={},O=function*(){yield pe(r),yield _e(r,b)}();for(const{result:j,additionalCss:D=[]}of O)r=j,D.forEach(_=>{const x=z(_,"");m(x,"")});return g(r)},"");return o?t?[`${t} { ${o} }`,...n].join(`
6
- `):o:n.join(`
7
- `)},ge=(e,t=[])=>{if(!e)return"";const s=[],n={};if(Object.entries(e).forEach(([o,a])=>{if(typeof a=="object"){if(!a)return;const i=o.trim(),p=ge(a,[...t,i]);s.push(p)}else n[o]=a}),Object.keys(n).length){const o=t.map(E).join("-"),a=z(n,`.${o}`);s.push(a)}return s.join(`
8
- `)},Me=e=>e?Object.entries(e).reduce((t,[s,n])=>(typeof n=="object"&&(t[s]=ye(n).map(o=>`"${o}"`).join(" | ")),t),{}):{},ye=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,o])=>{const a=t?`${t}.${n}`:n;return typeof o=="object"?ye(o,a,s):s.add(t)}),[...s]):[],me=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=l.join(e,"package.json");return u.existsSync(t)?t:me(l.join(e,".."))},Re=async e=>{const t=me(e);return await oe.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},ze=async e=>{const t=await Re(e);if(t)return t.type};let A;const he=async e=>{if(A)return A;const t=await ze(e);return t==="module"?A="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:se&&se.tagName.toUpperCase()==="SCRIPT"&&se.src||new URL("index-Dq_u-jmb.cjs",document.baseURI).href).endsWith(".cjs"))&&(A="cjs"),A||"esm"},ne=B.createLogger({level:"debug",format:B.format.combine(B.format.colorize(),B.format.cli()),transports:[new B.transports.Console({})]});function Se(e){return e?typeof e!="string"?Se(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 Je={"*, *::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"}},I=(...e)=>e.flat().reduce((t,s)=>s!=null&&s._current?{...t,...s._current}:{...t,...s},{}),R={externalModules:[],rcFile:void 0,destDir:void 0},$e=e=>{if(R.externalModules.length>0)return R.externalModules;const s=u.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(o=>o.replace(/['"`]/g,"").trim());return R.externalModules=n,n},J=async e=>{if(R.destDir)return R.destDir;const t=await re(e),s=l.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return R.destDir=s,s},be=["salty","css","styles","styled"],je=(e=[])=>new RegExp(`\\.(${[...be,...e].join("|")})\\.`),U=(e,t=[])=>je(t).test(e),we=async e=>{if(R.rcFile)return R.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=l.join(e,".saltyrc.json"),s=await oe.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(R.rcFile=s,s):we(l.join(e,".."))},re=async e=>{var n,o;const t=await we(e),s=(n=t.projects)==null?void 0:n.find(a=>e.endsWith(a.dir||""));return s||((o=t.projects)==null?void 0:o.find(a=>a.dir===t.defaultProject))},We=async e=>{const t=await re(e),s=await J(e),n=l.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),o=l.join(s,"salty.config.js"),a=await he(e),i=$e(n);await de.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:a,external:i});const p=Date.now(),{config:r}=await import(`${o}?t=${p}`);return r},Ae=async(e,t)=>{var ae,le;const s=await J(e),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...t].map(async w=>{const F=await X(e,w,s);Object.entries(F).forEach(([M,C])=>{C.isMedia?n.mediaQueries.push([M,C]):C.isGlobalDefine?n.globalStyles.push(C):C.isDefineVariables?n.variables.push(C):C.isDefineTemplates&&n.templates.push(C)})}));const o=await We(e),a={...o},i=new Set,p=(w,F=[])=>w?Object.entries(w).flatMap(([M,C])=>{if(!C)return;if(typeof C=="object")return p(C,[...F,M]);const Y=Se(M),v=E(M),ee=[...F,Y].join(".");i.add(`"${ee}"`);const te=[...F.map(E),v].join("-"),{result:Ce}=pe(C);return`--${te}: ${Ce};`}):[],r=w=>w?Object.entries(w).flatMap(([F,M])=>{const C=p(M);return F==="base"?C.join(""):`${F} { ${C.join("")} }`}):[],c=w=>w?Object.entries(w).flatMap(([F,M])=>Object.entries(M).flatMap(([C,Y])=>{const v=p(Y,[F]),ee=`.${F}-${C}, [data-${F}="${C}"]`,te=v.join("");return`${ee} { ${te} }`})):[],y=w=>({...w,responsive:void 0,conditional:void 0}),m=w=>n.variables.map(F=>w==="static"?y(F._current):F._current[w]),g=I(y(o.variables),m("static")),b=p(g),S=I((ae=o.variables)==null?void 0:ae.responsive,m("responsive")),O=r(S),j=I((le=o.variables)==null?void 0:le.conditional,m("conditional")),D=c(j),_=l.join(s,"css/_variables.css"),x=`:root { ${b.join("")} ${O.join("")} } ${D.join("")}`;u.writeFileSync(_,x),a.staticVariables=g;const T=l.join(s,"css/_global.css"),P=I(o.global,n.globalStyles),V=z(P,"");u.writeFileSync(T,`@layer global { ${V} }`);const f=l.join(s,"css/_reset.css"),$=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:Je,d=z($,"");u.writeFileSync(f,`@layer reset { ${d} }`);const N=l.join(s,"css/_templates.css"),k=I(o.templates,n.templates),q=ge(k),H=Me(k);u.writeFileSync(N,q),a.templates=k;const{mediaQueries:W}=n;a.mediaQueries=Object.fromEntries(W.map(([w,F])=>[`@${w}`,F]));const G=W.map(([w])=>`'@${w}'`).join(" | "),K=l.join(s,"types/css-tokens.d.ts"),L=`
9
- // Variable types
10
- type VariableTokens = ${[...i].join("|")};
11
- type PropertyValueToken = \`{\${VariableTokens}}\`;
12
-
13
- // Template types
14
- type TemplateTokens = {
15
- ${Object.entries(H).map(([w,F])=>`${w}?: ${F}`).join(`
16
- `)}
17
- }
18
-
19
- // Media query types
20
- type MediaQueryKeys = ${G||"''"};
21
- `;u.writeFileSync(K,L);const Q=l.join(s,"cache/config-cache.json");u.writeFileSync(Q,JSON.stringify(a,null,2))},ue=e=>e.replace(/styled\(([^"'`{,]+),/g,(t,s)=>{if(/^['"`]/.test(s))return t;const o=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!o.test(e))return t;const i=o.exec(e);if(i){const p=i.at(1);if(be.some(c=>p==null?void 0:p.includes(c)))return t}return"styled('div',"}),Ie=(e,t)=>{try{const s=u.readFileSync(l.join(t,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
22
-
23
- ${e}`:`globalThis.saltyConfig = {};
24
-
25
- ${e}`}catch{return e}},X=async(e,t,s)=>{const n=Z(t),o=l.join(s,"./temp");u.existsSync(o)||u.mkdirSync(o);const a=l.parse(t);let i=u.readFileSync(t,"utf8");i=ue(i),i=Ie(i,e);const p=l.join(s,"js",n+".js"),r=await re(e),c=l.join(e,(r==null?void 0:r.configDir)||"","salty.config.ts"),y=$e(c),m=await he(e);await de.build({stdin:{contents:i,sourcefile:a.base,resolveDir:a.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:p,format:m,target:["node20"],keepNames:!0,external:y,packages:"external",plugins:[{name:"test",setup:S=>{S.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},O=>{const j=u.readFileSync(O.path,"utf8");return{contents:ue(j),loader:"ts"}})}}]});const g=Date.now();return await import(`${p}?t=${g}`)},Ze=async e=>{const t=await J(e),s=l.join(t,"cache/config-cache.json"),n=u.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},ie=async e=>{const t=await Ze(e),s=await J(e),n=l.join(s,"salty.config.js"),o=Date.now(),{config:a}=await import(`${n}?t=${o}`);return I(a,t)},Fe=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},qe=async(e,t=Fe(),s=!0)=>{try{const n=Date.now();t?ne.info("Generating CSS in production mode! 🔥"):ne.info("Generating CSS in development mode! 🚀");const o=[],a=[],i=await J(e),p=l.join(i,"index.css");s&&(()=>{u.existsSync(i)&&Ne.execSync("rm -rf "+i),u.mkdirSync(i,{recursive:!0}),u.mkdirSync(l.join(i,"css")),u.mkdirSync(l.join(i,"types")),u.mkdirSync(l.join(i,"js")),u.mkdirSync(l.join(i,"cache"))})();const c=new Set,y=new Set;async function m(f){const h=["node_modules","saltygen"],$=u.statSync(f);if($.isDirectory()){const d=u.readdirSync(f);if(h.some(k=>f.includes(k)))return;await Promise.all(d.map(k=>m(l.join(f,k))))}else if($.isFile()&&U(f)){c.add(f);const N=u.readFileSync(f,"utf8");/define[\w\d]+\(/.test(N)&&y.add(f)}}await m(e),await Ae(e,y);const g={keyframes:[],components:[],classNames:[]};await Promise.all([...c].map(async f=>{const h=await X(e,f,i);Object.entries(h).forEach(([$,d])=>{d.isKeyframes?g.keyframes.push({value:d,src:f,name:$}):d.isClassName?g.classNames.push({...d,src:f,name:$}):d.generator&&g.components.push({...d,src:f,name:$})})}));const b=await ie(e);for(const f of g.keyframes){const{value:h}=f,$=`a_${h.animationName}.css`,d=`css/${$}`,N=l.join(i,d);o.push($),u.writeFileSync(N,h.css)}const S={};for(const f of g.components){const{src:h,name:$}=f,d=f.generator._withBuildContext({callerName:$,isProduction:t,config:b});a[d.priority]||(a[d.priority]=[]),a[d.priority].push(d.cssFileName);const N=`css/${d.cssFileName}`,k=l.join(i,N);u.writeFileSync(k,d.css),b.importStrategy==="component"&&(S[h]?S[h].push(d.cssFileName):S[h]=[d.cssFileName])}for(const f of g.classNames){const{src:h,name:$}=f,d=f.generator._withBuildContext({callerName:$,isProduction:t,config:b});a[0].push(d.cssFileName);const N=`css/${d.cssFileName}`,k=l.join(i,N);u.writeFileSync(k,d.css),b.importStrategy==="component"&&(S[h]?S[h].push(d.cssFileName):S[h]=[d.cssFileName])}b.importStrategy==="component"&&Object.entries(S).forEach(([f,h])=>{const $=h.map(H=>`@import url('./${H}');`).join(`
26
- `),d=Z(f,6),N=l.parse(f),k=E(N.name),q=l.join(i,`css/f_${k}-${d}.css`);u.writeFileSync(q,$)});const O=o.map(f=>`@import url('./css/${f}');`).join(`
27
- `);let x=`@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
28
-
29
- ${["_variables.css","_reset.css","_global.css","_templates.css"].filter(f=>{try{return u.readFileSync(l.join(i,"css",f),"utf8").length>0}catch{return!1}}).map(f=>`@import url('./css/${f}');`).join(`
30
- `)}
31
- ${O}`;if(b.importStrategy!=="component"){const f=a.reduce((h,$,d)=>{const N=$.reduce((W,G)=>{var Q;const K=l.join(i,"css",G),ce=u.readFileSync(K,"utf8"),L=((Q=/.*-([^-]+)-\d+.css/.exec(G))==null?void 0:Q.at(1))||Z(K,6);return W.includes(L)?W:`${W}
32
- /*start:${L}*/
33
- ${ce}
34
- /*end:${L}*/
35
- `},""),k=`l_${d}.css`,q=l.join(i,"css",k),H=`@layer l${d} { ${N}
36
- }`;return u.writeFileSync(q,H),`${h}
37
- @import url('./css/${k}');`},"");x+=f}u.writeFileSync(p,x);const P=Date.now()-n,V=P<200?"🔥":P<500?"🚀":P<1e3?"🎉":P<2e3?"🚗":P<5e3?"🤔":"🥴";ne.info(`Generated CSS in ${P}ms! ${V}`)}catch(n){console.error(n)}},He=async(e,t)=>{try{const s=await J(e);if(U(t)){const o=[],a=await ie(e),i=await X(e,t,s);if(Object.entries(i).forEach(([p,r])=>{if(r.isKeyframes&&r.css){const b=`css/${`a_${r.animationName}.css`}`,S=l.join(s,b);u.writeFileSync(S,r.css);return}if(r.isClassName){const g=r.factory._withBuildContext({name:p});o[0].push(g.cssFileName);const b=`css/${g.cssFileName}`,S=l.join(s,b);u.writeFileSync(S,g.css)}if(!r.generator)return;const c=r.generator._withBuildContext({name:p,config:a}),y=`css/${c.cssFileName}`,m=l.join(s,y);u.writeFileSync(m,c.css),o[c.priority]||(o[c.priority]=[]),o[c.priority].push(c.cssFileName)}),a.importStrategy!=="component")o.forEach((p,r)=>{const c=`l_${r}.css`,y=l.join(s,"css",c);let m=u.readFileSync(y,"utf8");p.forEach(g=>{var j;const b=l.join(s,"css",g),S=((j=/.*-([^-]+)-\d+.css/.exec(g))==null?void 0:j.at(1))||Z(b,6);if(!m.includes(S)){const D=u.readFileSync(b,"utf8"),_=`/*start:${S}*/
38
- ${D}
39
- /*end:${S}*/
40
- `;m=`${m.replace(/\}$/,"")}
41
- ${_}
42
- }`}}),u.writeFileSync(y,m)});else{const p=o.flat().map(g=>`@import url('./${g}');`).join(`
43
- `),r=Z(t,6),c=l.parse(t),y=E(c.name),m=l.join(s,`css/f_${y}-${r}.css`);u.writeFileSync(m,p)}}}catch(s){console.error(s)}},Le=async(e,t,s=Fe())=>{try{const n=await J(e);if(U(t)){const a=u.readFileSync(t,"utf8");a.replace(/^(?!export\s)const\s.*/gm,y=>`export ${y}`)!==a&&await oe.writeFile(t,a);const p=await ie(e),r=await X(e,t,n);let c=a;if(Object.entries(r).forEach(([y,m])=>{var d;if(m.isKeyframes||!m.generator)return;const g=m.generator._withBuildContext({name:y,config:p,prod:s}),b=new RegExp(`\\s${y}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(a);if(!b)return console.error("Could not find the original declaration");const S=(d=b.at(1))==null?void 0:d.trim(),O=new RegExp(`\\s${y}[=\\s]+styled\\(`,"g").exec(c);if(!O)return console.error("Could not find the original declaration");const{index:j}=O;let D=!1;const _=setTimeout(()=>D=!0,5e3);let x=0,T=!1,P=0;for(;!T&&!D;){const N=c[j+x];N==="("&&P++,N===")"&&P--,P===0&&N===")"&&(T=!0),x>c.length&&(D=!0),x++}if(!D)clearTimeout(_);else throw new Error("Failed to find the end of the styled call and timed out");const V=j+x,f=c.slice(j,V),h=c,$=` ${y} = styled(${S}, "${g.classNames}", ${JSON.stringify(g.clientProps)});`;c=c.replace(f,$),h===c&&console.error("Minimize file failed to change content",{name:y,tagName:S})}),p.importStrategy==="component"){const y=Z(t,6),m=l.parse(t);c=`import '../../saltygen/css/${`f_${E(m.name)}-${y}.css`}';
44
- ${c}`}return c=c.replace("{ styled }","{ styledClient as styled }"),c=c.replace("@salty-css/react/styled","@salty-css/react/styled-client"),c}}catch(n){console.error("Error in minimizeFile:",n)}};exports.generateCss=qe;exports.generateFile=He;exports.isSaltyFile=U;exports.minimizeFile=Le;exports.saltyFileRegExp=je;