@salty-css/core 0.0.1-alpha.285 → 0.0.1-alpha.287
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 +4 -4
- package/bin/main.js +125 -125
- package/cache/resolve-dynamic-config-cache.cjs +1 -1
- package/cache/resolve-dynamic-config-cache.js +1 -1
- package/compiler/helpers.d.ts +1 -0
- package/compiler/index.cjs +1 -1
- package/compiler/index.d.ts +0 -1
- package/compiler/index.js +10 -10
- package/css/keyframes.cjs +1 -1
- package/css/keyframes.js +1 -1
- package/generators/index.cjs +1 -1
- package/generators/index.js +13 -13
- package/helpers-C1RIrlCB.js +10 -0
- package/helpers-DVANmpVz.cjs +1 -0
- package/{index-nYFJiyUY.js → index-6JCRY_wd.js} +121 -126
- package/index-Dg98Xd3x.cjs +41 -0
- package/package.json +1 -1
- package/parse-styles-DLPgVsVQ.js +154 -0
- package/parse-styles-DZYIEhB4.cjs +5 -0
- package/parsers/index.cjs +1 -1
- package/parsers/index.js +2 -2
- package/server/index.cjs +1 -1
- package/server/index.js +1 -1
- package/{should-restart-9v8CVeO9.cjs → should-restart-2eX-l4VO.cjs} +1 -1
- package/{should-restart-BQEu8oUb.js → should-restart-YBRJU0GU.js} +1 -1
- package/index-De9SH8ms.cjs +0 -41
- package/parse-styles-Bdgw_4ME.cjs +0 -5
- package/parse-styles-C1E6ETeH.js +0 -154
@@ -0,0 +1,41 @@
|
|
1
|
+
"use strict";const ve=require("esbuild"),Oe=require("child_process"),_=require("./dash-case-BJEkFEGQ.cjs"),i=require("path"),c=require("fs"),we=require("fs/promises"),ae=require("./parse-styles-DZYIEhB4.cjs"),he=require("./parsers/index.cjs"),Q=require("winston"),J=require("./css/merge.cjs"),Ee=require("./define-templates-Cunsb_Tr.cjs"),ce=require("typescript"),Ve=require("./helpers-DVANmpVz.cjs");var re=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 je=Re(ve),be=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=i.join(e,"package.json");return c.existsSync(t)?t:be(i.join(e,".."))},Me=async e=>{const t=be(e);return await we.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},Je=async e=>{const t=await Me(e);if(t)return t.type};let H;const Fe=async e=>{if(H)return H;const t=await Je(e);return t==="module"?H="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:re&&re.tagName.toUpperCase()==="SCRIPT"&&re.src||new URL("index-Dg98Xd3x.cjs",document.baseURI).href).endsWith(".cjs"))&&(H="cjs"),H||"esm"},B=Q.createLogger({level:"debug",format:Q.format.combine(Q.format.colorize(),Q.format.cli()),transports:[new Q.transports.Console({})]}),qe=e=>{B.error(e)};function $e(e){return e?typeof e!="string"?$e(String(e)):e.replace(/[^\d\w]/g,"."):""}const ze={"*, *::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"}},He=(e,t)=>new Promise((s,n)=>{const r=setTimeout(()=>{n(new Error("Timeout"))},100),l=ce.createSourceFile("temp.ts",e,ce.ScriptTarget.Latest,!0);function o(y){if(ce.isVariableDeclaration(y)&&y.name.getText()===t){const w=y.getStart(),m=y.getEnd();clearTimeout(r),s([w,m])}y.forEachChild(o)}o(l)}),O={externalModules:[],rcFile:void 0,destDir:void 0},Ce=e=>{if(O.externalModules.length>0)return O.externalModules;const s=c.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(r=>r.replace(/['"`]/g,"").trim());return O.externalModules=n,n},q=async e=>{if(O.destDir)return O.destDir;const t=await fe(e),s=i.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return O.destDir=s,s},le=["salty","css","styles","styled"],Pe=(e=[])=>new RegExp(`\\.(${[...le,...e].join("|")})\\.`),Z=(e,t=[])=>Pe(t).test(e),Ne=async e=>{if(O.rcFile)return O.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=i.join(e,".saltyrc.json"),s=await we.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(O.rcFile=s,s):Ne(i.join(e,".."))},fe=async e=>{var n,r;const t=await Ne(e),s=(n=t.projects)==null?void 0:n.find(l=>e.endsWith(l.dir||""));return s||((r=t.projects)==null?void 0:r.find(l=>l.dir===t.defaultProject))},We=async e=>{const t=await fe(e),s=await q(e),n=i.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),r=i.join(s,"salty.config.js"),l=await Fe(e),o=Ce(n);await je.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:r,format:l,external:o});const y=Date.now(),{config:w}=await import(`${r}?t=${y}`);return{config:w,path:r}},xe=async(e,t)=>{var de,ye;const s=await q(e),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...t].map(async S=>{const{contents:F,outputFilePath:K}=await U(e,S,s);Object.entries(F).forEach(([D,P])=>{P.isMedia?n.mediaQueries.push([D,P]):P.isGlobalDefine?n.globalStyles.push(P):P.isDefineVariables?n.variables.push(P):P.isDefineTemplates&&n.templates.push(P._setPath(`${D};;${K}`))})}));const{config:r,path:l}=await We(e),o={...r},{mediaQueries:y}=n;o.mediaQueries=Object.fromEntries(y.map(([S,F])=>[`@${S}`,F]));const w=y.map(([S])=>`'@${S}'`).join(" | "),m=new Set,a=async(S,F=[])=>{if(!S)return[];const K=Object.entries(S).map(async([P,M])=>{const L=async T=>{if(!T)return;if(T instanceof Promise)return await L(await T);if(typeof T=="function")return await L(await T());if(typeof T=="object")return await a(T,[...F,P]);const ne=$e(P),oe=_.dashCase(P),ie=[...F,ne].join(".");m.add(`"${ie}"`);const Y=[...F.map(_.dashCase),oe].join("-"),ge=ae.parseVariableTokens(T);return ge?`--${Y}: ${ge.transformed};`:`--${Y}: ${T};`};return await L(M)});return(await Promise.all(K)).flat()},g=async S=>{if(!S)return[];const F=Object.entries(S).map(async([D,P])=>{const M=await a(P);return D==="base"?M.join(""):o.mediaQueries[D]?`${o.mediaQueries[D]} { ${M.join("")} }`:`${D} { ${M.join("")} }`});return(await Promise.all(F)).flat()},d=async S=>{if(!S)return[];const F=Object.entries(S).map(async([D,P])=>{const M=Object.entries(P).map(async([T,ne])=>{const oe=await a(ne,[D]),ie=`.${D}-${T}, [data-${D}="${T}"]`,Y=oe.join("");return`${ie} { ${Y} }`});return(await Promise.all(M)).flat()});return(await Promise.all(F)).flat()},h=S=>({...S,responsive:void 0,conditional:void 0}),p=S=>n.variables.map(F=>S==="static"?h(F._current):F._current[S]),$=J.mergeObjects(h(r.variables),p("static")),x=await a($),k=J.mergeObjects((de=r.variables)==null?void 0:de.responsive,p("responsive")),E=await g(k),z=J.mergeObjects((ye=r.variables)==null?void 0:ye.conditional,p("conditional")),A=await d(z),me=i.join(s,"css/_variables.css"),V=`:root { ${x.join("")} ${E.join("")} } ${A.join("")}`;c.writeFileSync(me,V),o.staticVariables=$;const ee=i.join(s,"css/_global.css"),u=J.mergeObjects(r.global,n.globalStyles),j=await ae.parseAndJoinStyles(u,"");c.writeFileSync(ee,`@layer global { ${j} }`);const b=i.join(s,"css/_reset.css"),C=r.reset==="none"?{}:typeof r.reset=="object"?r.reset:ze,N=await ae.parseAndJoinStyles(C,"");c.writeFileSync(b,`@layer reset { ${N} }`);const v=i.join(s,"css/_templates.css"),R=J.mergeObjects(r.templates,n.templates),W=await he.parseTemplates(R),I=he.getTemplateTypes(R);c.writeFileSync(v,`@layer templates { ${W} }`),o.templates=R;const X=r.templates?[Ee.defineTemplates(r.templates)._setPath(`config;;${l}`)]:[],te=J.mergeFactories(n.templates,X);o.templatePaths=Object.fromEntries(Object.entries(te).map(([S,F])=>[S,F._path]));const G=i.join(s,"types/css-tokens.d.ts"),ke=`
|
2
|
+
// Variable types
|
3
|
+
type VariableTokens = ${[...m].join("|")};
|
4
|
+
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
5
|
+
|
6
|
+
// Template types
|
7
|
+
type TemplateTokens = {
|
8
|
+
${Object.entries(I).map(([S,F])=>`${S}?: ${F}`).join(`
|
9
|
+
`)}
|
10
|
+
}
|
11
|
+
|
12
|
+
// Media query types
|
13
|
+
type MediaQueryKeys = ${w||"''"};
|
14
|
+
`;c.writeFileSync(G,ke);const De=i.join(s,"cache/config-cache.json");c.writeFileSync(De,JSON.stringify(o,null,2));const Te=Ve.getCorePackageRoot(),_e=i.join(Te,"cache/config-cache.json");c.writeFileSync(_e,JSON.stringify(o,null,2))},Se=e=>e.replace(/styled\(([^"'`{,]+),/g,(t,s)=>{if(/^['"`]/.test(s))return t;const r=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!r.test(e))return t;const o=r.exec(e);if(o){const y=o.at(1);if(le.some(m=>y==null?void 0:y.includes(m)))return t}return"styled('div',"}),Ie=(e,t)=>{try{const s=c.readFileSync(i.join(t,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
|
15
|
+
|
16
|
+
${e}`:`globalThis.saltyConfig = {};
|
17
|
+
|
18
|
+
${e}`}catch{return e}},U=async(e,t,s)=>{const n=_.toHash(t),r=i.join(s,"./temp");c.existsSync(r)||c.mkdirSync(r);const l=i.parse(t);let o=c.readFileSync(t,"utf8");o=Se(o),o=Ie(o,e);const y=i.join(s,"js",n+".js"),w=await fe(e),m=i.join(e,(w==null?void 0:w.configDir)||"","salty.config.ts"),a=Ce(m),g=await Fe(e);await je.build({stdin:{contents:o,sourcefile:l.base,resolveDir:l.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:y,format:g,target:["node20"],keepNames:!0,external:a,packages:"external",plugins:[{name:"test",setup:p=>{p.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},$=>{const x=c.readFileSync($.path,"utf8");return{contents:Se(x),loader:"ts"}})}}]});const d=Date.now();return{contents:await import(`${y}?t=${d}`),outputFilePath:y}},Ge=async e=>{const t=await q(e),s=i.join(t,"cache/config-cache.json"),n=c.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},ue=async e=>{const t=await Ge(e),s=await q(e),n=i.join(s,"salty.config.js"),r=Date.now(),{config:l}=await import(`${n}?t=${r}`);return J.mergeObjects(l,t)},pe=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Ke=async(e,t=pe(),s=!0)=>{try{const n=Date.now();t?B.info("Generating CSS in production mode! 🔥"):B.info("Generating CSS in development mode! 🚀");const r=[],l=[],o=await q(e),y=i.join(o,"index.css");s&&(()=>{c.existsSync(o)&&Oe.execSync("rm -rf "+o),c.mkdirSync(o,{recursive:!0}),c.mkdirSync(i.join(o,"css")),c.mkdirSync(i.join(o,"types")),c.mkdirSync(i.join(o,"js")),c.mkdirSync(i.join(o,"cache"))})();const m=new Set,a=new Set;async function g(u){const j=["node_modules","saltygen"],b=c.statSync(u);if(b.isDirectory()){const f=c.readdirSync(u);if(j.some(N=>u.includes(N)))return;await Promise.all(f.map(N=>g(i.join(u,N))))}else if(b.isFile()&&Z(u)){m.add(u);const C=c.readFileSync(u,"utf8");/define[\w\d]+\(/.test(C)&&a.add(u)}}await g(e),await xe(e,a);const d={keyframes:[],components:[],classNames:[]};await Promise.all([...m].map(async u=>{const{contents:j}=await U(e,u,o);for(let[b,f]of Object.entries(j))f instanceof Promise&&(f=await f),f.isKeyframes?d.keyframes.push({value:f,src:u,name:b}):f.isClassName?d.classNames.push({...f,src:u,name:b}):f.generator&&d.components.push({...f,src:u,name:b})}));const h=await ue(e);for(const u of d.keyframes){const{value:j}=u,b=`a_${j.animationName}.css`,f=`css/${b}`,C=i.join(o,f);r.push(b),c.writeFileSync(C,j.css)}const p={};for(const u of d.components){const{src:j,name:b}=u;p[j]||(p[j]=[]);const f=u.generator._withBuildContext({callerName:b,isProduction:t,config:h});l[f.priority]||(l[f.priority]=[]);const C=await f.css;if(!C)continue;l[f.priority].push(f.cssFileName);const N=`css/${f.cssFileName}`,v=i.join(o,N);c.writeFileSync(v,C),h.importStrategy==="component"&&p[j].push(f.cssFileName)}for(const u of d.classNames){const{src:j,name:b}=u;p[j]||(p[j]=[]);const f=u.generator._withBuildContext({callerName:b,isProduction:t,config:h}),C=await f.css;if(!C)continue;l[f.priority]||(l[f.priority]=[]),l[f.priority].push(f.cssFileName);const N=`css/${f.cssFileName}`,v=i.join(o,N);c.writeFileSync(v,C),h.importStrategy==="component"&&p[j].push(f.cssFileName)}h.importStrategy==="component"&&Object.entries(p).forEach(([u,j])=>{const b=j.map(R=>`@import url('./${R}');`).join(`
|
19
|
+
`),f=_.toHash(u,6),C=i.parse(u),N=_.dashCase(C.name),v=i.join(o,`css/f_${N}-${f}.css`);c.writeFileSync(v,b||"/* Empty file */")});const $=r.map(u=>`@import url('./css/${u}');`).join(`
|
20
|
+
`);let A=`/*!
|
21
|
+
* Generated with Salty CSS (https://salty-css.dev)
|
22
|
+
* Do not edit this file directly
|
23
|
+
*/
|
24
|
+
@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
25
|
+
|
26
|
+
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(u=>{try{return c.readFileSync(i.join(o,"css",u),"utf8").length>0}catch{return!1}}).map(u=>`@import url('./css/${u}');`).join(`
|
27
|
+
`)}
|
28
|
+
${$}`;if(h.importStrategy!=="component"){const u=l.reduce((j,b,f)=>{const C=b.reduce((W,I)=>{var se;const X=i.join(o,"css",I),te=c.readFileSync(X,"utf8"),G=((se=/.*-([^-]+)-\d+.css/.exec(I))==null?void 0:se.at(1))||_.toHash(X,6);return W.includes(G)?W:`${W}
|
29
|
+
/*start:${G}-${I}*/
|
30
|
+
${te}
|
31
|
+
/*end:${G}*/
|
32
|
+
`},""),N=`l_${f}.css`,v=i.join(o,"css",N),R=`@layer l${f} { ${C}
|
33
|
+
}`;return c.writeFileSync(v,R),`${j}
|
34
|
+
@import url('./css/${N}');`},"");A+=u}c.writeFileSync(y,A);const V=Date.now()-n,ee=V<200?"🔥":V<500?"🚀":V<1e3?"🎉":V<2e3?"🚗":V<5e3?"🤔":"🥴";B.info(`Generated CSS in ${V}ms! ${ee}`)}catch(n){console.error(n)}},Le=async(e,t,s=pe())=>{try{const n=await q(e);if(Z(t)){const l=[],o=await ue(e),{contents:y}=await U(e,t,n);for(const[w,m]of Object.entries(y)){if(m.isKeyframes&&m.css){const $=`css/${`a_${m.animationName}.css`}`,x=i.join(n,$);c.writeFileSync(x,await m.css);continue}if(m.isClassName){const p=m.generator._withBuildContext({callerName:w,isProduction:s,config:o}),$=await p.css;if(!$)continue;l[p.priority]||(l[p.priority]=[]),l[p.priority].push(p.cssFileName);const x=`css/${p.cssFileName}`,k=i.join(n,x);c.writeFileSync(k,$);continue}if(!m.generator)continue;const a=m.generator._withBuildContext({callerName:w,isProduction:s,config:o}),g=await a.css;if(!g)continue;const d=`css/${a.cssFileName}`,h=i.join(n,d);c.writeFileSync(h,g),l[a.priority]||(l[a.priority]=[]),l[a.priority].push(a.cssFileName)}if(o.importStrategy!=="component")l.forEach((w,m)=>{const a=`l_${m}.css`,g=i.join(n,"css",a);let d=c.readFileSync(g,"utf8");w.forEach(h=>{var k;const p=i.join(n,"css",h),$=((k=/.*-([^-]+)-\d+.css/.exec(h))==null?void 0:k.at(1))||_.toHash(p,6);if(!d.includes($)){const E=c.readFileSync(p,"utf8"),z=`/*start:${$}-${h}*/
|
35
|
+
${E}
|
36
|
+
/*end:${$}*/
|
37
|
+
`;d=`${d.replace(/\}$/,"")}
|
38
|
+
${z}
|
39
|
+
}`}}),c.writeFileSync(g,d)});else{const w=l.flat().map(h=>`@import url('./${h}');`).join(`
|
40
|
+
`),m=_.toHash(t,6),a=i.parse(t),g=_.dashCase(a.name),d=i.join(n,`css/f_${g}-${m}.css`);c.writeFileSync(d,w||"/* Empty file */")}}}catch(n){console.error(n)}},Qe=async(e,t,s=pe())=>{var n,r;try{const l=await q(e);if(Z(t)){const y=c.readFileSync(t,"utf8"),w=await ue(e),{contents:m}=await U(e,t,l);let a=y;for(const[g,d]of Object.entries(m)){if(d.isKeyframes||!d.generator)continue;const h=d.generator._withBuildContext({callerName:g,isProduction:s,config:w}),[p,$]=await He(a,g),x=a.slice(p,$);if(d.isClassName){const k=a,E=` ${g} = className("${h.classNames}")`;a=a.replace(x,E),k===a&&console.error("Minimize file failed to change content",{name:g})}if(x.includes("styled")){const k=(r=(n=/styled\(([^,]+),/.exec(x))==null?void 0:n.at(1))==null?void 0:r.trim(),E=a,z=` ${g} = styled(${k}, "${h.classNames}", ${JSON.stringify(h.clientProps)})`;a=a.replace(x,z),E===a&&console.error("Minimize file failed to change content",{name:g,tagName:k})}}if(w.importStrategy==="component"){const g=_.toHash(t,6),d=i.parse(t);a=`import '../../saltygen/css/${`f_${_.dashCase(d.name)}-${g}.css`}';
|
41
|
+
${a}`}return a=a.replace("@salty-css/react/class-name","@salty-css/react/class-name-client"),a=a.replace("{ styled }","{ styledClient as styled }"),a=a.replace("@salty-css/react/styled","@salty-css/react/styled-client"),a}}catch(l){console.error("Error in minimizeFile:",l)}};exports.compileSaltyFile=U;exports.generateConfigStyles=xe;exports.generateCss=Ke;exports.generateFile=Le;exports.isSaltyFile=Z;exports.logError=qe;exports.logger=B;exports.minimizeFile=Qe;exports.saltyFileExtensions=le;exports.saltyFileRegExp=Pe;
|
package/package.json
CHANGED
@@ -0,0 +1,154 @@
|
|
1
|
+
import { d as O } from "./dash-case-DBThphLm.js";
|
2
|
+
import { d as N } from "./viewport-clamp-BOc-8Oph.js";
|
3
|
+
const U = (o) => (s) => {
|
4
|
+
if (typeof s != "string" || !o) return;
|
5
|
+
let t = s;
|
6
|
+
const m = [];
|
7
|
+
return Object.values(o).forEach((e) => {
|
8
|
+
const { pattern: p, transform: f } = e;
|
9
|
+
t = t.replace(p, (E) => {
|
10
|
+
const { value: x, css: v } = f(E);
|
11
|
+
return v && m.push(v), x;
|
12
|
+
});
|
13
|
+
}), { transformed: t, additionalCss: m };
|
14
|
+
}, A = (o) => (s) => typeof s != "string" || !/\{[^{}]+\}/g.test(s) ? void 0 : { transformed: s.replace(/\{([^{}]+)\}/g, (...e) => {
|
15
|
+
const p = O(e[1].replaceAll(".", "-"));
|
16
|
+
return o && !o.includes(p) && console.warn(`Token ${p} might not exist`), p.startsWith("-") ? `-${p}` : `var(--${p})`;
|
17
|
+
}) }, D = A(), M = [
|
18
|
+
"top",
|
19
|
+
"right",
|
20
|
+
"bottom",
|
21
|
+
"left",
|
22
|
+
"min-width",
|
23
|
+
/.*width.*/,
|
24
|
+
/^[^line]*height.*/,
|
25
|
+
// Exclude line-height
|
26
|
+
/padding.*/,
|
27
|
+
/margin.*/,
|
28
|
+
/border.*/,
|
29
|
+
/inset.*/,
|
30
|
+
/.*radius.*/,
|
31
|
+
/.*spacing.*/,
|
32
|
+
/.*gap.*/,
|
33
|
+
/.*indent.*/,
|
34
|
+
/.*offset.*/,
|
35
|
+
/.*size.*/,
|
36
|
+
/.*thickness.*/,
|
37
|
+
/.*font-size.*/
|
38
|
+
], Q = (o, s, t) => {
|
39
|
+
if (M.some((e) => typeof e == "string" ? e === o : e.test(o))) {
|
40
|
+
const e = (t == null ? void 0 : t.defaultUnit) || "px";
|
41
|
+
if (e.startsWith("viewport-clamp:"))
|
42
|
+
try {
|
43
|
+
const f = e.split(":")[1];
|
44
|
+
return N({
|
45
|
+
screenSize: parseInt(f)
|
46
|
+
})(Number(s));
|
47
|
+
} catch (f) {
|
48
|
+
throw console.error(f), new Error(`Invalid viewport-clamp value: ${e}`);
|
49
|
+
}
|
50
|
+
return `${s}${e}`;
|
51
|
+
}
|
52
|
+
return `${s}`;
|
53
|
+
}, _ = ["Webkit", "Moz", "ms", "O"], q = (o) => o.startsWith("-") ? o : _.some((s) => o.startsWith(s)) ? `-${O(o)}` : O(o), y = async (o, s = "", t, m = !1) => {
|
54
|
+
if (!o) throw new Error("No styles provided to parseStyles function!");
|
55
|
+
const e = /* @__PURE__ */ new Set(), p = Object.entries(o), f = async ([u, r]) => {
|
56
|
+
var P;
|
57
|
+
const n = u.trim().replace(/^\?+/g, ""), b = q(n), h = (a, c = ";") => `${b}:${a}${c}`, C = { scope: s, config: t };
|
58
|
+
if (typeof r == "function") return f([u, r(C)]);
|
59
|
+
if (r instanceof Promise) return f([u, await r]);
|
60
|
+
if (t != null && t.templates && t.templatePaths[n])
|
61
|
+
try {
|
62
|
+
const [a, c] = t.templatePaths[n].split(";;"), i = await import(
|
63
|
+
/* webpackIgnore: true */
|
64
|
+
/* @vite-ignore */
|
65
|
+
c
|
66
|
+
), d = c.includes("salty.config"), l = d ? i[a].templates : i[a], $ = d ? l[n] : l.params[n];
|
67
|
+
if (l && typeof $ == "function") {
|
68
|
+
const j = await $(r), [w] = await y(j, "");
|
69
|
+
return w;
|
70
|
+
}
|
71
|
+
} catch (a) {
|
72
|
+
console.error(`Error loading template "${n}" from path "${t.templatePaths[n]}"`, a);
|
73
|
+
return;
|
74
|
+
}
|
75
|
+
if (t != null && t.templates && t.templates[n]) {
|
76
|
+
if (m) return;
|
77
|
+
const c = r.split(".").reduce((i, d) => i[d], t.templates[n]);
|
78
|
+
if (c) {
|
79
|
+
const [i] = await y(c, "");
|
80
|
+
return i;
|
81
|
+
}
|
82
|
+
console.warn(`Template "${n}" with path of "${r}" was not found in config!`);
|
83
|
+
return;
|
84
|
+
}
|
85
|
+
if (typeof r == "object") {
|
86
|
+
if (!r) return;
|
87
|
+
if (r.isColor) return h(r.toString());
|
88
|
+
if (n === "defaultVariants") return;
|
89
|
+
if (n === "variants") {
|
90
|
+
const i = Object.entries(r);
|
91
|
+
for (const [d, l] of i) {
|
92
|
+
if (!l) continue;
|
93
|
+
const $ = Object.entries(l);
|
94
|
+
for (const [j, w] of $) {
|
95
|
+
if (!w) continue;
|
96
|
+
const W = `${s}.${d}-${j}`;
|
97
|
+
(await y(w, W, t)).forEach((I) => e.add(I));
|
98
|
+
}
|
99
|
+
}
|
100
|
+
return;
|
101
|
+
}
|
102
|
+
if (n === "compoundVariants") {
|
103
|
+
for (const i of r) {
|
104
|
+
const { css: d, ...l } = i, $ = Object.entries(l).reduce((w, [W, V]) => `${w}.${W}-${V}`, s);
|
105
|
+
(await y(d, $, t)).forEach((w) => e.add(w));
|
106
|
+
}
|
107
|
+
return;
|
108
|
+
}
|
109
|
+
if (n.startsWith("@")) {
|
110
|
+
const i = ((P = t == null ? void 0 : t.mediaQueries) == null ? void 0 : P[n]) || n, d = await z(r, s, t), l = `${i} { ${d} }`;
|
111
|
+
e.add(l);
|
112
|
+
return;
|
113
|
+
}
|
114
|
+
const a = u.includes("&") ? n.replaceAll("&", s) : n.startsWith(":") ? `${s}${n}` : `${s} ${n}`;
|
115
|
+
(await y(r, a, t)).forEach((i) => e.add(i));
|
116
|
+
return;
|
117
|
+
}
|
118
|
+
if (typeof r == "number") {
|
119
|
+
const a = Q(b, r, t);
|
120
|
+
return h(a);
|
121
|
+
}
|
122
|
+
if (typeof r != "string")
|
123
|
+
if ("toString" in r) r = r.toString();
|
124
|
+
else throw new Error(`Invalid value type for property ${b}`);
|
125
|
+
return h(r);
|
126
|
+
}, E = p.map(f), { modifiers: x } = t || {}, v = [A(), U(x)], S = (await Promise.all(E).then((u) => Promise.all(
|
127
|
+
u.map((r) => v.reduce(async (n, b) => {
|
128
|
+
const h = await n;
|
129
|
+
if (!h) return h;
|
130
|
+
const C = await b(h);
|
131
|
+
if (!C) return h;
|
132
|
+
const { transformed: P, additionalCss: a } = C;
|
133
|
+
let c = "";
|
134
|
+
if (a)
|
135
|
+
for (const i of a)
|
136
|
+
c += await z(i, "");
|
137
|
+
return `${c}${P}`;
|
138
|
+
}, Promise.resolve(r)))
|
139
|
+
))).filter((u) => u !== void 0).join(`
|
140
|
+
`);
|
141
|
+
if (!S.trim()) return Array.from(e);
|
142
|
+
const T = s ? `${s} {
|
143
|
+
${S}
|
144
|
+
}` : S;
|
145
|
+
return e.has(T) ? Array.from(e) : [T, ...e];
|
146
|
+
}, z = async (o, s, t, m = !1) => (await y(o, s, t, m)).join(`
|
147
|
+
`);
|
148
|
+
export {
|
149
|
+
D as a,
|
150
|
+
U as b,
|
151
|
+
y as c,
|
152
|
+
A as d,
|
153
|
+
z as p
|
154
|
+
};
|
@@ -0,0 +1,5 @@
|
|
1
|
+
"use strict";const x=require("./dash-case-BJEkFEGQ.cjs"),M=require("./viewport-clamp-kY8JqYzm.cjs"),q=o=>s=>{if(typeof s!="string"||!o)return;let t=s;const u=[];return Object.values(o).forEach(e=>{const{pattern:p,transform:f}=e;t=t.replace(p,C=>{const{value:V,css:v}=f(C);return v&&u.push(v),V})}),{transformed:t,additionalCss:u}},A=o=>s=>typeof s!="string"||!/\{[^{}]+\}/g.test(s)?void 0:{transformed:s.replace(/\{([^{}]+)\}/g,(...e)=>{const p=x.dashCase(e[1].replaceAll(".","-"));return o&&!o.includes(p)&&console.warn(`Token ${p} might not exist`),p.startsWith("-")?`-${p}`:`var(--${p})`})},N=A(),U=["top","right","bottom","left","min-width",/.*width.*/,/^[^line]*height.*/,/padding.*/,/margin.*/,/border.*/,/inset.*/,/.*radius.*/,/.*spacing.*/,/.*gap.*/,/.*indent.*/,/.*offset.*/,/.*size.*/,/.*thickness.*/,/.*font-size.*/],k=(o,s,t)=>{if(U.some(e=>typeof e=="string"?e===o:e.test(o))){const e=(t==null?void 0:t.defaultUnit)||"px";if(e.startsWith("viewport-clamp:"))try{const f=e.split(":")[1];return M.defineViewportClamp({screenSize:parseInt(f)})(Number(s))}catch(f){throw console.error(f),new Error(`Invalid viewport-clamp value: ${e}`)}return`${s}${e}`}return`${s}`},J=["Webkit","Moz","ms","O"],Q=o=>o.startsWith("-")?o:J.some(s=>o.startsWith(s))?`-${x.dashCase(o)}`:x.dashCase(o),$=async(o,s="",t,u=!1)=>{if(!o)throw new Error("No styles provided to parseStyles function!");const e=new Set,p=Object.entries(o),f=async([m,r])=>{var P;const n=m.trim().replace(/^\?+/g,""),b=Q(n),h=(a,c=";")=>`${b}:${a}${c}`,E={scope:s,config:t};if(typeof r=="function")return f([m,r(E)]);if(r instanceof Promise)return f([m,await r]);if(t!=null&&t.templates&&t.templatePaths[n])try{const[a,c]=t.templatePaths[n].split(";;"),i=await import(c),l=c.includes("salty.config"),d=l?i[a].templates:i[a],y=l?d[n]:d.params[n];if(d&&typeof y=="function"){const S=await y(r),[w]=await $(S,"");return w}}catch(a){console.error(`Error loading template "${n}" from path "${t.templatePaths[n]}"`,a);return}if(t!=null&&t.templates&&t.templates[n]){if(u)return;const c=r.split(".").reduce((i,l)=>i[l],t.templates[n]);if(c){const[i]=await $(c,"");return i}console.warn(`Template "${n}" with path of "${r}" was not found in config!`);return}if(typeof r=="object"){if(!r)return;if(r.isColor)return h(r.toString());if(n==="defaultVariants")return;if(n==="variants"){const i=Object.entries(r);for(const[l,d]of i){if(!d)continue;const y=Object.entries(d);for(const[S,w]of y){if(!w)continue;const T=`${s}.${l}-${S}`;(await $(w,T,t)).forEach(I=>e.add(I))}}return}if(n==="compoundVariants"){for(const i of r){const{css:l,...d}=i,y=Object.entries(d).reduce((w,[T,z])=>`${w}.${T}-${z}`,s);(await $(l,y,t)).forEach(w=>e.add(w))}return}if(n.startsWith("@")){const i=((P=t==null?void 0:t.mediaQueries)==null?void 0:P[n])||n,l=await W(r,s,t),d=`${i} { ${l} }`;e.add(d);return}const a=m.includes("&")?n.replaceAll("&",s):n.startsWith(":")?`${s}${n}`:`${s} ${n}`;(await $(r,a,t)).forEach(i=>e.add(i));return}if(typeof r=="number"){const a=k(b,r,t);return h(a)}if(typeof r!="string")if("toString"in r)r=r.toString();else throw new Error(`Invalid value type for property ${b}`);return h(r)},C=p.map(f),{modifiers:V}=t||{},v=[A(),q(V)],j=(await Promise.all(C).then(m=>Promise.all(m.map(r=>v.reduce(async(n,b)=>{const h=await n;if(!h)return h;const E=await b(h);if(!E)return h;const{transformed:P,additionalCss:a}=E;let c="";if(a)for(const i of a)c+=await W(i,"");return`${c}${P}`},Promise.resolve(r)))))).filter(m=>m!==void 0).join(`
|
2
|
+
`);if(!j.trim())return Array.from(e);const O=s?`${s} {
|
3
|
+
${j}
|
4
|
+
}`:j;return e.has(O)?Array.from(e):[O,...e]},W=async(o,s,t,u=!1)=>(await $(o,s,t,u)).join(`
|
5
|
+
`);exports.parseAndJoinStyles=W;exports.parseStyles=$;exports.parseValueModifiers=q;exports.parseValueTokens=A;exports.parseVariableTokens=N;
|
package/parsers/index.cjs
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../parse-styles-
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../parse-styles-DZYIEhB4.cjs"),c=require("../dash-case-BJEkFEGQ.cjs"),p=async(e,s=[])=>{if(!e)return"";const t=[],r={};for(const[n,o]of Object.entries(e))if(typeof o!="function")if(o&&typeof o=="object"){const i=n.trim(),u=await p(o,[...s,i]);t.push(u)}else r[n]=o;if(Object.keys(r).length){const n=s.map(c.dashCase).join("-"),o="t_"+c.toHash(n,4),i=await a.parseAndJoinStyles(r,`.${n}, .${o}`);t.push(i)}return t.join(`
|
2
2
|
`)},y=e=>Object.keys(e),f=e=>e?Object.entries(e).reduce((s,[t,r])=>(typeof r=="function"?s[t]="any":typeof r=="object"&&(s[t]=l(r).map(n=>`"${n}"`).join(" | ")),s),{}):{},l=(e,s="",t=new Set)=>e?(Object.entries(e).forEach(([r,n])=>{const o=s?`${s}.${r}`:r;return typeof n=="object"?l(n,o,t):t.add(s)}),[...t]):[];exports.parseAndJoinStyles=a.parseAndJoinStyles;exports.parseStyles=a.parseStyles;exports.parseValueModifiers=a.parseValueModifiers;exports.parseValueTokens=a.parseValueTokens;exports.parseVariableTokens=a.parseVariableTokens;exports.getTemplateKeys=y;exports.getTemplateTokens=l;exports.getTemplateTypes=f;exports.parseTemplates=p;
|
package/parsers/index.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { p as f } from "../parse-styles-
|
2
|
-
import { c as T, b as O, d as $, a as g } from "../parse-styles-
|
1
|
+
import { p as f } from "../parse-styles-DLPgVsVQ.js";
|
2
|
+
import { c as T, b as O, d as $, a as g } from "../parse-styles-DLPgVsVQ.js";
|
3
3
|
import { d as p, t as u } from "../dash-case-DBThphLm.js";
|
4
4
|
const l = async (e, s = []) => {
|
5
5
|
if (!e) return "";
|
package/server/index.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../should-restart-
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../should-restart-2eX-l4VO.cjs");exports.checkShouldRestart=e.checkShouldRestart;
|
package/server/index.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";const s=require("fs/promises"),r=require("./index-
|
1
|
+
"use strict";const s=require("fs/promises"),r=require("./index-Dg98Xd3x.cjs"),i=async t=>{if(!t||t.includes("node_modules")||t.includes("saltygen"))return!1;if(t.includes("salty.config"))return!0;if(!r.isSaltyFile(t))return!1;const e=await s.readFile(t,"utf-8");return!!(/.+define[A-Z]\w+/.test(e)||/.+keyframes\(.+/.test(e))};exports.checkShouldRestart=i;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { readFile as r } from "fs/promises";
|
2
|
-
import { i as e } from "./index-
|
2
|
+
import { i as e } from "./index-6JCRY_wd.js";
|
3
3
|
const f = async (t) => {
|
4
4
|
if (!t || t.includes("node_modules") || t.includes("saltygen")) return !1;
|
5
5
|
if (t.includes("salty.config")) return !0;
|
package/index-De9SH8ms.cjs
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
"use strict";const Re=require("esbuild"),ve=require("child_process"),_=require("./dash-case-BJEkFEGQ.cjs"),i=require("path"),c=require("fs"),Se=require("fs/promises"),ce=require("./parse-styles-Bdgw_4ME.cjs"),he=require("./parsers/index.cjs"),Q=require("winston"),J=require("./css/merge.cjs"),Ee=require("./define-templates-Cunsb_Tr.cjs"),re=require("typescript");var I=typeof document<"u"?document.currentScript:null;function Ve(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 je=Ve(Re),be=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=i.join(e,"package.json");return c.existsSync(t)?t:be(i.join(e,".."))},Me=async e=>{const t=be(e);return await Se.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},Je=async e=>{const t=await Me(e);if(t)return t.type};let H;const Fe=async e=>{if(H)return H;const t=await Je(e);return t==="module"?H="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:I&&I.tagName.toUpperCase()==="SCRIPT"&&I.src||new URL("index-De9SH8ms.cjs",document.baseURI).href).endsWith(".cjs"))&&(H="cjs"),H||"esm"},B=Q.createLogger({level:"debug",format:Q.format.combine(Q.format.colorize(),Q.format.cli()),transports:[new Q.transports.Console({})]}),qe=e=>{B.error(e)};function $e(e){return e?typeof e!="string"?$e(String(e)):e.replace(/[^\d\w]/g,"."):""}const ze={"*, *::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"}},He=(e,t)=>new Promise((s,n)=>{const r=setTimeout(()=>{n(new Error("Timeout"))},100),l=re.createSourceFile("temp.ts",e,re.ScriptTarget.Latest,!0);function o(y){if(re.isVariableDeclaration(y)&&y.name.getText()===t){const S=y.getStart(),d=y.getEnd();clearTimeout(r),s([S,d])}y.forEachChild(o)}o(l)}),Ce=()=>{let{pathname:e}=new URL(typeof document>"u"?require("url").pathToFileURL(__filename).href:I&&I.tagName.toUpperCase()==="SCRIPT"&&I.src||new URL("index-De9SH8ms.cjs",document.baseURI).href);for(;/core\/?(src\/)?$/.test(e)===!1;)e=i.join(e,"../");return e},R={externalModules:[],rcFile:void 0,destDir:void 0},Pe=e=>{if(R.externalModules.length>0)return R.externalModules;const s=c.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(r=>r.replace(/['"`]/g,"").trim());return R.externalModules=n,n},q=async e=>{if(R.destDir)return R.destDir;const t=await fe(e),s=i.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return R.destDir=s,s},le=["salty","css","styles","styled"],Ne=(e=[])=>new RegExp(`\\.(${[...le,...e].join("|")})\\.`),ee=(e,t=[])=>Ne(t).test(e),xe=async e=>{if(R.rcFile)return R.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=i.join(e,".saltyrc.json"),s=await Se.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(R.rcFile=s,s):xe(i.join(e,".."))},fe=async e=>{var n,r;const t=await xe(e),s=(n=t.projects)==null?void 0:n.find(l=>e.endsWith(l.dir||""));return s||((r=t.projects)==null?void 0:r.find(l=>l.dir===t.defaultProject))},Ie=async e=>{const t=await fe(e),s=await q(e),n=i.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),r=i.join(s,"salty.config.js"),l=await Fe(e),o=Pe(n);await je.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:r,format:l,external:o});const y=Date.now(),{config:S}=await import(`${r}?t=${y}`);return{config:S,path:r}},ke=async(e,t)=>{var me,ye;const s=await q(e),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...t].map(async w=>{const{contents:F,outputFilePath:G}=await A(e,w,s);Object.entries(F).forEach(([D,P])=>{P.isMedia?n.mediaQueries.push([D,P]):P.isGlobalDefine?n.globalStyles.push(P):P.isDefineVariables?n.variables.push(P):P.isDefineTemplates&&n.templates.push(P._setPath(`${D};;${G}`))})}));const{config:r,path:l}=await Ie(e),o={...r},{mediaQueries:y}=n;o.mediaQueries=Object.fromEntries(y.map(([w,F])=>[`@${w}`,F]));const S=y.map(([w])=>`'@${w}'`).join(" | "),d=new Set,a=async(w,F=[])=>{if(!w)return[];const G=Object.entries(w).map(async([P,M])=>{const K=async T=>{if(!T)return;if(T instanceof Promise)return await K(await T);if(typeof T=="function")return await K(await T());if(typeof T=="object")return await a(T,[...F,P]);const oe=$e(P),ie=_.dashCase(P),ae=[...F,oe].join(".");d.add(`"${ae}"`);const Z=[...F.map(_.dashCase),ie].join("-"),ge=ce.parseVariableTokens(T);return ge?`--${Z}: ${ge.transformed};`:`--${Z}: ${T};`};return await K(M)});return(await Promise.all(G)).flat()},g=async w=>{if(!w)return[];const F=Object.entries(w).map(async([D,P])=>{const M=await a(P);return D==="base"?M.join(""):o.mediaQueries[D]?`${o.mediaQueries[D]} { ${M.join("")} }`:`${D} { ${M.join("")} }`});return(await Promise.all(F)).flat()},m=async w=>{if(!w)return[];const F=Object.entries(w).map(async([D,P])=>{const M=Object.entries(P).map(async([T,oe])=>{const ie=await a(oe,[D]),ae=`.${D}-${T}, [data-${D}="${T}"]`,Z=ie.join("");return`${ae} { ${Z} }`});return(await Promise.all(M)).flat()});return(await Promise.all(F)).flat()},h=w=>({...w,responsive:void 0,conditional:void 0}),p=w=>n.variables.map(F=>w==="static"?h(F._current):F._current[w]),$=J.mergeObjects(h(r.variables),p("static")),x=await a($),k=J.mergeObjects((me=r.variables)==null?void 0:me.responsive,p("responsive")),v=await g(k),z=J.mergeObjects((ye=r.variables)==null?void 0:ye.conditional,p("conditional")),X=await m(z),de=i.join(s,"css/_variables.css"),E=`:root { ${x.join("")} ${v.join("")} } ${X.join("")}`;c.writeFileSync(de,E),o.staticVariables=$;const te=i.join(s,"css/_global.css"),u=J.mergeObjects(r.global,n.globalStyles),j=await ce.parseAndJoinStyles(u,"");c.writeFileSync(te,`@layer global { ${j} }`);const b=i.join(s,"css/_reset.css"),C=r.reset==="none"?{}:typeof r.reset=="object"?r.reset:ze,N=await ce.parseAndJoinStyles(C,"");c.writeFileSync(b,`@layer reset { ${N} }`);const O=i.join(s,"css/_templates.css"),V=J.mergeObjects(r.templates,n.templates),L=await he.parseTemplates(V),W=he.getTemplateTypes(V);c.writeFileSync(O,`@layer templates { ${L} }`),o.templates=V;const Y=r.templates?[Ee.defineTemplates(r.templates)._setPath(`config;;${l}`)]:[],se=J.mergeFactories(n.templates,Y);o.templatePaths=Object.fromEntries(Object.entries(se).map(([w,F])=>[w,F._path]));const U=i.join(s,"types/css-tokens.d.ts"),De=`
|
2
|
-
// Variable types
|
3
|
-
type VariableTokens = ${[...d].join("|")};
|
4
|
-
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
5
|
-
|
6
|
-
// Template types
|
7
|
-
type TemplateTokens = {
|
8
|
-
${Object.entries(W).map(([w,F])=>`${w}?: ${F}`).join(`
|
9
|
-
`)}
|
10
|
-
}
|
11
|
-
|
12
|
-
// Media query types
|
13
|
-
type MediaQueryKeys = ${S||"''"};
|
14
|
-
`;c.writeFileSync(U,De);const Te=i.join(s,"cache/config-cache.json");c.writeFileSync(Te,JSON.stringify(o,null,2));const _e=Ce(),Oe=i.join(_e,"cache/config-cache.json");c.writeFileSync(Oe,JSON.stringify(o,null,2))},we=e=>e.replace(/styled\(([^"'`{,]+),/g,(t,s)=>{if(/^['"`]/.test(s))return t;const r=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!r.test(e))return t;const o=r.exec(e);if(o){const y=o.at(1);if(le.some(d=>y==null?void 0:y.includes(d)))return t}return"styled('div',"}),Le=(e,t)=>{try{const s=c.readFileSync(i.join(t,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
|
15
|
-
|
16
|
-
${e}`:`globalThis.saltyConfig = {};
|
17
|
-
|
18
|
-
${e}`}catch{return e}},A=async(e,t,s)=>{const n=_.toHash(t),r=i.join(s,"./temp");c.existsSync(r)||c.mkdirSync(r);const l=i.parse(t);let o=c.readFileSync(t,"utf8");o=we(o),o=Le(o,e);const y=i.join(s,"js",n+".js"),S=await fe(e),d=i.join(e,(S==null?void 0:S.configDir)||"","salty.config.ts"),a=Pe(d),g=await Fe(e);await je.build({stdin:{contents:o,sourcefile:l.base,resolveDir:l.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:y,format:g,target:["node20"],keepNames:!0,external:a,packages:"external",plugins:[{name:"test",setup:p=>{p.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},$=>{const x=c.readFileSync($.path,"utf8");return{contents:we(x),loader:"ts"}})}}]});const m=Date.now();return{contents:await import(`${y}?t=${m}`),outputFilePath:y}},We=async e=>{const t=await q(e),s=i.join(t,"cache/config-cache.json"),n=c.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},ue=async e=>{const t=await We(e),s=await q(e),n=i.join(s,"salty.config.js"),r=Date.now(),{config:l}=await import(`${n}?t=${r}`);return J.mergeObjects(l,t)},pe=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Ue=async(e,t=pe(),s=!0)=>{try{const n=Date.now();t?B.info("Generating CSS in production mode! 🔥"):B.info("Generating CSS in development mode! 🚀");const r=[],l=[],o=await q(e),y=i.join(o,"index.css");s&&(()=>{c.existsSync(o)&&ve.execSync("rm -rf "+o),c.mkdirSync(o,{recursive:!0}),c.mkdirSync(i.join(o,"css")),c.mkdirSync(i.join(o,"types")),c.mkdirSync(i.join(o,"js")),c.mkdirSync(i.join(o,"cache"))})();const d=new Set,a=new Set;async function g(u){const j=["node_modules","saltygen"],b=c.statSync(u);if(b.isDirectory()){const f=c.readdirSync(u);if(j.some(N=>u.includes(N)))return;await Promise.all(f.map(N=>g(i.join(u,N))))}else if(b.isFile()&&ee(u)){d.add(u);const C=c.readFileSync(u,"utf8");/define[\w\d]+\(/.test(C)&&a.add(u)}}await g(e),await ke(e,a);const m={keyframes:[],components:[],classNames:[]};await Promise.all([...d].map(async u=>{const{contents:j}=await A(e,u,o);for(let[b,f]of Object.entries(j))f instanceof Promise&&(f=await f),f.isKeyframes?m.keyframes.push({value:f,src:u,name:b}):f.isClassName?m.classNames.push({...f,src:u,name:b}):f.generator&&m.components.push({...f,src:u,name:b})}));const h=await ue(e);for(const u of m.keyframes){const{value:j}=u,b=`a_${j.animationName}.css`,f=`css/${b}`,C=i.join(o,f);r.push(b),c.writeFileSync(C,j.css)}const p={};for(const u of m.components){const{src:j,name:b}=u;p[j]||(p[j]=[]);const f=u.generator._withBuildContext({callerName:b,isProduction:t,config:h});l[f.priority]||(l[f.priority]=[]);const C=await f.css;if(!C)continue;l[f.priority].push(f.cssFileName);const N=`css/${f.cssFileName}`,O=i.join(o,N);c.writeFileSync(O,C),h.importStrategy==="component"&&p[j].push(f.cssFileName)}for(const u of m.classNames){const{src:j,name:b}=u;p[j]||(p[j]=[]);const f=u.generator._withBuildContext({callerName:b,isProduction:t,config:h}),C=await f.css;if(!C)continue;l[f.priority]||(l[f.priority]=[]),l[f.priority].push(f.cssFileName);const N=`css/${f.cssFileName}`,O=i.join(o,N);c.writeFileSync(O,C),h.importStrategy==="component"&&p[j].push(f.cssFileName)}h.importStrategy==="component"&&Object.entries(p).forEach(([u,j])=>{const b=j.map(V=>`@import url('./${V}');`).join(`
|
19
|
-
`),f=_.toHash(u,6),C=i.parse(u),N=_.dashCase(C.name),O=i.join(o,`css/f_${N}-${f}.css`);c.writeFileSync(O,b||"/* Empty file */")});const $=r.map(u=>`@import url('./css/${u}');`).join(`
|
20
|
-
`);let X=`/*!
|
21
|
-
* Generated with Salty CSS (https://salty-css.dev)
|
22
|
-
* Do not edit this file directly
|
23
|
-
*/
|
24
|
-
@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
25
|
-
|
26
|
-
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(u=>{try{return c.readFileSync(i.join(o,"css",u),"utf8").length>0}catch{return!1}}).map(u=>`@import url('./css/${u}');`).join(`
|
27
|
-
`)}
|
28
|
-
${$}`;if(h.importStrategy!=="component"){const u=l.reduce((j,b,f)=>{const C=b.reduce((L,W)=>{var ne;const Y=i.join(o,"css",W),se=c.readFileSync(Y,"utf8"),U=((ne=/.*-([^-]+)-\d+.css/.exec(W))==null?void 0:ne.at(1))||_.toHash(Y,6);return L.includes(U)?L:`${L}
|
29
|
-
/*start:${U}-${W}*/
|
30
|
-
${se}
|
31
|
-
/*end:${U}*/
|
32
|
-
`},""),N=`l_${f}.css`,O=i.join(o,"css",N),V=`@layer l${f} { ${C}
|
33
|
-
}`;return c.writeFileSync(O,V),`${j}
|
34
|
-
@import url('./css/${N}');`},"");X+=u}c.writeFileSync(y,X);const E=Date.now()-n,te=E<200?"🔥":E<500?"🚀":E<1e3?"🎉":E<2e3?"🚗":E<5e3?"🤔":"🥴";B.info(`Generated CSS in ${E}ms! ${te}`)}catch(n){console.error(n)}},Ge=async(e,t,s=pe())=>{try{const n=await q(e);if(ee(t)){const l=[],o=await ue(e),{contents:y}=await A(e,t,n);for(const[S,d]of Object.entries(y)){if(d.isKeyframes&&d.css){const $=`css/${`a_${d.animationName}.css`}`,x=i.join(n,$);c.writeFileSync(x,await d.css);continue}if(d.isClassName){const p=d.generator._withBuildContext({callerName:S,isProduction:s,config:o}),$=await p.css;if(!$)continue;l[p.priority]||(l[p.priority]=[]),l[p.priority].push(p.cssFileName);const x=`css/${p.cssFileName}`,k=i.join(n,x);c.writeFileSync(k,$);continue}if(!d.generator)continue;const a=d.generator._withBuildContext({callerName:S,isProduction:s,config:o}),g=await a.css;if(!g)continue;const m=`css/${a.cssFileName}`,h=i.join(n,m);c.writeFileSync(h,g),l[a.priority]||(l[a.priority]=[]),l[a.priority].push(a.cssFileName)}if(o.importStrategy!=="component")l.forEach((S,d)=>{const a=`l_${d}.css`,g=i.join(n,"css",a);let m=c.readFileSync(g,"utf8");S.forEach(h=>{var k;const p=i.join(n,"css",h),$=((k=/.*-([^-]+)-\d+.css/.exec(h))==null?void 0:k.at(1))||_.toHash(p,6);if(!m.includes($)){const v=c.readFileSync(p,"utf8"),z=`/*start:${$}-${h}*/
|
35
|
-
${v}
|
36
|
-
/*end:${$}*/
|
37
|
-
`;m=`${m.replace(/\}$/,"")}
|
38
|
-
${z}
|
39
|
-
}`}}),c.writeFileSync(g,m)});else{const S=l.flat().map(h=>`@import url('./${h}');`).join(`
|
40
|
-
`),d=_.toHash(t,6),a=i.parse(t),g=_.dashCase(a.name),m=i.join(n,`css/f_${g}-${d}.css`);c.writeFileSync(m,S||"/* Empty file */")}}}catch(n){console.error(n)}},Ke=async(e,t,s=pe())=>{var n,r;try{const l=await q(e);if(ee(t)){const y=c.readFileSync(t,"utf8"),S=await ue(e),{contents:d}=await A(e,t,l);let a=y;for(const[g,m]of Object.entries(d)){if(m.isKeyframes||!m.generator)continue;const h=m.generator._withBuildContext({callerName:g,isProduction:s,config:S}),[p,$]=await He(a,g),x=a.slice(p,$);if(m.isClassName){const k=a,v=` ${g} = className("${h.classNames}")`;a=a.replace(x,v),k===a&&console.error("Minimize file failed to change content",{name:g})}if(x.includes("styled")){const k=(r=(n=/styled\(([^,]+),/.exec(x))==null?void 0:n.at(1))==null?void 0:r.trim(),v=a,z=` ${g} = styled(${k}, "${h.classNames}", ${JSON.stringify(h.clientProps)})`;a=a.replace(x,z),v===a&&console.error("Minimize file failed to change content",{name:g,tagName:k})}}if(S.importStrategy==="component"){const g=_.toHash(t,6),m=i.parse(t);a=`import '../../saltygen/css/${`f_${_.dashCase(m.name)}-${g}.css`}';
|
41
|
-
${a}`}return a=a.replace("@salty-css/react/class-name","@salty-css/react/class-name-client"),a=a.replace("{ styled }","{ styledClient as styled }"),a=a.replace("@salty-css/react/styled","@salty-css/react/styled-client"),a}}catch(l){console.error("Error in minimizeFile:",l)}};exports.compileSaltyFile=A;exports.generateConfigStyles=ke;exports.generateCss=Ue;exports.generateFile=Ge;exports.getCorePackageRoot=Ce;exports.isSaltyFile=ee;exports.logError=qe;exports.logger=B;exports.minimizeFile=Ke;exports.saltyFileExtensions=le;exports.saltyFileRegExp=Ne;
|
@@ -1,5 +0,0 @@
|
|
1
|
-
"use strict";const W=require("./dash-case-BJEkFEGQ.cjs"),N=require("./viewport-clamp-kY8JqYzm.cjs"),I=i=>e=>{if(typeof e!="string"||!i)return;let t=e;const u=[];return Object.values(i).forEach(r=>{const{pattern:d,transform:f}=r;t=t.replace(d,C=>{const{value:j,css:E}=f(C);return E&&u.push(E),j})}),{transformed:t,additionalCss:u}},O=i=>e=>typeof e!="string"||!/\{[^{}]+\}/g.test(e)?void 0:{transformed:e.replace(/\{([^{}]+)\}/g,(...r)=>{const d=W.dashCase(r[1].replaceAll(".","-"));return i&&!i.includes(d)&&console.warn(`Token ${d} might not exist`),d.startsWith("-")?`-${d}`:`var(--${d})`})},U=O(),k=["top","right","bottom","left","min-width",/.*width.*/,/^[^line]*height.*/,/padding.*/,/margin.*/,/border.*/,/inset.*/,/.*radius.*/,/.*spacing.*/,/.*gap.*/,/.*indent.*/,/.*offset.*/,/.*size.*/,/.*thickness.*/,/.*font-size.*/],J=(i,e,t)=>{if(k.some(r=>typeof r=="string"?r===i:r.test(i))){const r=(t==null?void 0:t.defaultUnit)||"px";if(r.startsWith("viewport-clamp:"))try{const f=r.split(":")[1];return N.defineViewportClamp({screenSize:parseInt(f)})(Number(e))}catch(f){throw console.error(f),new Error(`Invalid viewport-clamp value: ${r}`)}return`${e}${r}`}return`${e}`},Q=["Webkit","Moz","ms","O"],_=i=>i.startsWith("-")?i:Q.some(e=>i.startsWith(e))?`-${W.dashCase(i)}`:W.dashCase(i),$=async(i,e="",t,u=!1)=>{if(!i)throw new Error("No styles provided to parseStyles function!");const r=new Set,d=Object.entries(i),f=async([m,s])=>{var S;const n=m.trim().replace(/^\?+/g,""),b=_(n),h=(a,c=";")=>`${b}:${a}${c}`,P={scope:e,config:t};if(typeof s=="function")return f([m,s(P)]);if(s instanceof Promise)return f([m,await s]);if(t!=null&&t.templates&&t.templatePaths[n])try{const[a,c]=t.templatePaths[n].split(";;"),o=await import(c),p=c.includes("salty.config"),l=p?o[a].templates:o[a],y=p?l[n]:l.params[n];if(l&&typeof y=="function"){const V=await y(s),[w]=await $(V,"");return w}}catch(a){console.error(`Error loading template "${n}" from path "${t.templatePaths[n]}"`,a);return}if(t!=null&&t.templates&&t.templates[n]){if(u)return;const c=s.split(".").reduce((o,p)=>o[p],t.templates[n]);if(c){const[o]=await $(c,"");return o}console.warn(`Template "${n}" with path of "${s}" was not found in config!`);return}if(typeof s=="object"){if(!s)return;if(s.isColor)return h(s.toString());if(n==="defaultVariants")return;if(n==="variants"){const o=Object.entries(s);for(const[p,l]of o){if(!l)continue;const y=Object.entries(l);for(const[V,w]of y){if(!w)continue;const x=`${e}.${p}-${V}`;(await $(w,x,t)).forEach(M=>r.add(M))}}return}if(n==="compoundVariants"){for(const o of s){const{css:p,...l}=o,y=Object.entries(l).reduce((w,[x,q])=>`${w}.${x}-${q}`,e);(await $(p,y,t)).forEach(w=>r.add(w))}return}if(n.startsWith("@")){const o=((S=t==null?void 0:t.mediaQueries)==null?void 0:S[n])||n,p=await A(s,e,t),l=`${o} { ${p} }`;r.add(l);return}const a=m.includes("&")?n.replaceAll("&",e):n.startsWith(":")?`${e}${n}`:`${e} ${n}`;(await $(s,a,t)).forEach(o=>r.add(o));return}if(typeof s=="number"){const a=J(b,s,t);return h(a)}if(typeof s!="string")if("toString"in s)s=s.toString();else throw new Error(`Invalid value type for property ${b}`);return h(s)},C=d.map(f),{modifiers:j}=t||{},E=[O(),I(j)],T=(await Promise.all(C).then(m=>Promise.all(m.map(s=>E.reduce(async(n,b)=>{const h=await n;if(!h)return h;const P=await b(h);if(!P)return h;const{transformed:S,additionalCss:a}=P;let c="";if(a)for(const o of a)c+=await A(o,"");return`${c}${S}`},Promise.resolve(s)))))).filter(m=>m!==void 0).join(`
|
2
|
-
`);if(!T.trim())return Array.from(r);const z=e?`${e} {
|
3
|
-
${T}
|
4
|
-
}`:T;return r.has(z)?Array.from(r):[z,...r]},A=async(i,e,t,u=!1)=>(await $(i,e,t,u)).join(`
|
5
|
-
`);exports.parseAndJoinStyles=A;exports.parseStyles=$;exports.parseValueModifiers=I;exports.parseValueTokens=O;exports.parseVariableTokens=U;
|
package/parse-styles-C1E6ETeH.js
DELETED
@@ -1,154 +0,0 @@
|
|
1
|
-
import { d as T } from "./dash-case-DBThphLm.js";
|
2
|
-
import { d as U } from "./viewport-clamp-BOc-8Oph.js";
|
3
|
-
const M = (o) => (s) => {
|
4
|
-
if (typeof s != "string" || !o) return;
|
5
|
-
let t = s;
|
6
|
-
const u = [];
|
7
|
-
return Object.values(o).forEach((r) => {
|
8
|
-
const { pattern: d, transform: l } = r;
|
9
|
-
t = t.replace(d, (E) => {
|
10
|
-
const { value: S, css: C } = l(E);
|
11
|
-
return C && u.push(C), S;
|
12
|
-
});
|
13
|
-
}), { transformed: t, additionalCss: u };
|
14
|
-
}, I = (o) => (s) => typeof s != "string" || !/\{[^{}]+\}/g.test(s) ? void 0 : { transformed: s.replace(/\{([^{}]+)\}/g, (...r) => {
|
15
|
-
const d = T(r[1].replaceAll(".", "-"));
|
16
|
-
return o && !o.includes(d) && console.warn(`Token ${d} might not exist`), d.startsWith("-") ? `-${d}` : `var(--${d})`;
|
17
|
-
}) }, G = I(), Q = [
|
18
|
-
"top",
|
19
|
-
"right",
|
20
|
-
"bottom",
|
21
|
-
"left",
|
22
|
-
"min-width",
|
23
|
-
/.*width.*/,
|
24
|
-
/^[^line]*height.*/,
|
25
|
-
// Exclude line-height
|
26
|
-
/padding.*/,
|
27
|
-
/margin.*/,
|
28
|
-
/border.*/,
|
29
|
-
/inset.*/,
|
30
|
-
/.*radius.*/,
|
31
|
-
/.*spacing.*/,
|
32
|
-
/.*gap.*/,
|
33
|
-
/.*indent.*/,
|
34
|
-
/.*offset.*/,
|
35
|
-
/.*size.*/,
|
36
|
-
/.*thickness.*/,
|
37
|
-
/.*font-size.*/
|
38
|
-
], _ = (o, s, t) => {
|
39
|
-
if (Q.some((r) => typeof r == "string" ? r === o : r.test(o))) {
|
40
|
-
const r = (t == null ? void 0 : t.defaultUnit) || "px";
|
41
|
-
if (r.startsWith("viewport-clamp:"))
|
42
|
-
try {
|
43
|
-
const l = r.split(":")[1];
|
44
|
-
return U({
|
45
|
-
screenSize: parseInt(l)
|
46
|
-
})(Number(s));
|
47
|
-
} catch (l) {
|
48
|
-
throw console.error(l), new Error(`Invalid viewport-clamp value: ${r}`);
|
49
|
-
}
|
50
|
-
return `${s}${r}`;
|
51
|
-
}
|
52
|
-
return `${s}`;
|
53
|
-
}, q = ["Webkit", "Moz", "ms", "O"], F = (o) => o.startsWith("-") ? o : q.some((s) => o.startsWith(s)) ? `-${T(o)}` : T(o), y = async (o, s = "", t, u = !1) => {
|
54
|
-
if (!o) throw new Error("No styles provided to parseStyles function!");
|
55
|
-
const r = /* @__PURE__ */ new Set(), d = Object.entries(o), l = async ([m, e]) => {
|
56
|
-
var j;
|
57
|
-
const n = m.trim().replace(/^\?+/g, ""), b = F(n), h = (a, c = ";") => `${b}:${a}${c}`, P = { scope: s, config: t };
|
58
|
-
if (typeof e == "function") return l([m, e(P)]);
|
59
|
-
if (e instanceof Promise) return l([m, await e]);
|
60
|
-
if (t != null && t.templates && t.templatePaths[n])
|
61
|
-
try {
|
62
|
-
const [a, c] = t.templatePaths[n].split(";;"), i = await import(
|
63
|
-
/* webpackIgnore: true */
|
64
|
-
/* @vite-ignore */
|
65
|
-
c
|
66
|
-
), p = c.includes("salty.config"), f = p ? i[a].templates : i[a], $ = p ? f[n] : f.params[n];
|
67
|
-
if (f && typeof $ == "function") {
|
68
|
-
const x = await $(e), [w] = await y(x, "");
|
69
|
-
return w;
|
70
|
-
}
|
71
|
-
} catch (a) {
|
72
|
-
console.error(`Error loading template "${n}" from path "${t.templatePaths[n]}"`, a);
|
73
|
-
return;
|
74
|
-
}
|
75
|
-
if (t != null && t.templates && t.templates[n]) {
|
76
|
-
if (u) return;
|
77
|
-
const c = e.split(".").reduce((i, p) => i[p], t.templates[n]);
|
78
|
-
if (c) {
|
79
|
-
const [i] = await y(c, "");
|
80
|
-
return i;
|
81
|
-
}
|
82
|
-
console.warn(`Template "${n}" with path of "${e}" was not found in config!`);
|
83
|
-
return;
|
84
|
-
}
|
85
|
-
if (typeof e == "object") {
|
86
|
-
if (!e) return;
|
87
|
-
if (e.isColor) return h(e.toString());
|
88
|
-
if (n === "defaultVariants") return;
|
89
|
-
if (n === "variants") {
|
90
|
-
const i = Object.entries(e);
|
91
|
-
for (const [p, f] of i) {
|
92
|
-
if (!f) continue;
|
93
|
-
const $ = Object.entries(f);
|
94
|
-
for (const [x, w] of $) {
|
95
|
-
if (!w) continue;
|
96
|
-
const O = `${s}.${p}-${x}`;
|
97
|
-
(await y(w, O, t)).forEach((N) => r.add(N));
|
98
|
-
}
|
99
|
-
}
|
100
|
-
return;
|
101
|
-
}
|
102
|
-
if (n === "compoundVariants") {
|
103
|
-
for (const i of e) {
|
104
|
-
const { css: p, ...f } = i, $ = Object.entries(f).reduce((w, [O, z]) => `${w}.${O}-${z}`, s);
|
105
|
-
(await y(p, $, t)).forEach((w) => r.add(w));
|
106
|
-
}
|
107
|
-
return;
|
108
|
-
}
|
109
|
-
if (n.startsWith("@")) {
|
110
|
-
const i = ((j = t == null ? void 0 : t.mediaQueries) == null ? void 0 : j[n]) || n, p = await A(e, s, t), f = `${i} { ${p} }`;
|
111
|
-
r.add(f);
|
112
|
-
return;
|
113
|
-
}
|
114
|
-
const a = m.includes("&") ? n.replaceAll("&", s) : n.startsWith(":") ? `${s}${n}` : `${s} ${n}`;
|
115
|
-
(await y(e, a, t)).forEach((i) => r.add(i));
|
116
|
-
return;
|
117
|
-
}
|
118
|
-
if (typeof e == "number") {
|
119
|
-
const a = _(b, e, t);
|
120
|
-
return h(a);
|
121
|
-
}
|
122
|
-
if (typeof e != "string")
|
123
|
-
if ("toString" in e) e = e.toString();
|
124
|
-
else throw new Error(`Invalid value type for property ${b}`);
|
125
|
-
return h(e);
|
126
|
-
}, E = d.map(l), { modifiers: S } = t || {}, C = [I(), M(S)], W = (await Promise.all(E).then((m) => Promise.all(
|
127
|
-
m.map((e) => C.reduce(async (n, b) => {
|
128
|
-
const h = await n;
|
129
|
-
if (!h) return h;
|
130
|
-
const P = await b(h);
|
131
|
-
if (!P) return h;
|
132
|
-
const { transformed: j, additionalCss: a } = P;
|
133
|
-
let c = "";
|
134
|
-
if (a)
|
135
|
-
for (const i of a)
|
136
|
-
c += await A(i, "");
|
137
|
-
return `${c}${j}`;
|
138
|
-
}, Promise.resolve(e)))
|
139
|
-
))).filter((m) => m !== void 0).join(`
|
140
|
-
`);
|
141
|
-
if (!W.trim()) return Array.from(r);
|
142
|
-
const V = s ? `${s} {
|
143
|
-
${W}
|
144
|
-
}` : W;
|
145
|
-
return r.has(V) ? Array.from(r) : [V, ...r];
|
146
|
-
}, A = async (o, s, t, u = !1) => (await y(o, s, t, u)).join(`
|
147
|
-
`);
|
148
|
-
export {
|
149
|
-
G as a,
|
150
|
-
M as b,
|
151
|
-
y as c,
|
152
|
-
I as d,
|
153
|
-
A as p
|
154
|
-
};
|