@infinityfx/fluid
Version:
React UI library, using zero-runtime CSS-in-JS.
3 lines (2 loc) • 3.19 kB
JavaScript
import t from"fs";import{createElement as e}from"react";import{renderToString as s}from"react-dom/server";import{glob as n}from"glob";import{stripImports as a,getContext as i,getIOHelper as o,keyFromImport as c,extractImports as r,replace as l,matchBrackets as u}from"./utils.js";async function p(t,n,p,m=!1){let d=t.source(p);try{const a=[await t.module(p)],[c,r]=n.split(".");r&&a.unshift(await t.module(p.replace(/index\.js/,`${r.toLowerCase()}.js`))),s(await async function(t){const{isInternal:s}=await i(),n=o("node_modules/@infinityfx/fluid/",s);if(!n)throw new Error("Unable to access FluidProvider module");const a=await n.module("./context/fluid.js"),c=t.reduce(((t,s)=>{t="Root"in s?e(s.Root,{},t):e(s,{key:0,pages:1,steps:[],options:[],data:[],columns:[],include:[],name:""},t)}),void 0);return e(a,void 0,e("div",{key:0},c))}(a))}catch{}await async function(t,e,s=!1){const{dependents:n}=await i();(t=c(t))in n||(n[t]=[]),s?r(e,"fluid").forEach((e=>e&&n[t].push(e))):Array.from(e.matchAll(/import\s+\w+\s+from\s*(?:'|").*?\/([^\/]+)(\/index)?\.js(?:'|")/g)).forEach((([e,s])=>{s.startsWith("use")||n[t].push(s)}))}(n,d,"fluid"!==t.parent),d=await async function(t,e){const{styles:s}=await i(),{selectors:n}=s[t.replace(/([a-z])([A-Z])/,"$1-$2").toLowerCase()]||{},a=e.match(/import\s*\{[^{]*(createStyles(?:\s*as\s*([^\s},]+))?)[^}]*\}/),o=e.match(new RegExp(`(=|,|;|\\s|:)${a?.[2]||a?.[1]}\\(`));o?.index&&(e=l(e,o.index+1,u(e,o.index+o[0].length,"()")+1,JSON.stringify(n||{})));const c=e.match(/import\s*\{[^{]*(createGlobalStyles(?:\s*as\s*([^\s},]+))?)[^}]*\}/);let r,p=e.matchAll(new RegExp(`(=|,|;|\\s|:)${c?.[2]||c?.[1]}\\(`,"g")),m=0;for(;r=p.next().value;){const t=r.index+m;let s=u(e,t+r[0].length,"()");[";",","].includes(e.charAt(s+1))&&s++,e=l(e,t+1,s+1,""),m-=s-t}return e}(n,d),m&&(d=await async function(t,e,s){const{theme:n,cssOutput:a}=await i(),o=e.match(/import\s*\{[^{]*(GLOBAL_CONTEXT(?:\s*as\s*([^\s},]+))?)[^}]*\}/);e=e.replace(new RegExp(`${o?.[2]||o?.[1]}\\.theme`),JSON.stringify(n));const c=e.match(/(?:(?:'|")use\sclient(?:'|");\n?)?()/);if(void 0===c?.index||"manual"===a)return e;const r=c.index+c[0].length;return l(e,r,r,`import "./${t.split(/\/|\\/g).slice(2).map((()=>"../")).join("")}${s}.css";`)}(p,d,`${t.parent}-${t.timestamp}`)),t.output(p,a(d))}async function m(e,s,n){const{dependents:a}=await i(),o=t.readFileSync(s,{encoding:"ascii"}),c=r(o,e);for(;c.length;){const t=c.pop();if(!t)return null;t in n||(t in a&&c.push(...a[t]),n[t]=!0)}return n}async function d(e,s,a=!1){const{paths:o,styles:c,cssOutput:r,isDev:l,isInternal:u}=await i();let p=null;if(!u&&!l){const t=await n(o);p={};for(const s of t)if(p=await m(e.parent,s,p),!p)break}const d=Object.entries(c).reduce(((t,[e,n])=>"__globals"===(e=e.replace(/\.\w+$/,""))||null===p||e in p?a&&"__globals"===e?t:(s.compiled++,t+n.rules):t),"");s.files.push({name:"automatic"===r?`${e.parent}-${e.timestamp}.css`:`${e.parent}.css (partial)`,size:new Blob([d],{type:"text/css"}).size}),"automatic"===r?e.output(`./${e.parent}-${e.timestamp}.css`,d):t.writeFileSync(process.cwd()+"/fluid.css",d,{flag:s.index?"a":"w"})}export{p as compileFile,d as emitCss};
//# sourceMappingURL=core.js.map