@devup-ui/next-plugin
Version:
Zero Config, Zero FOUC, Zero Runtime, CSS in JS Preprocessor
2 lines (1 loc) • 2.35 kB
JavaScript
var{defineProperty:F,getOwnPropertyNames:E,getOwnPropertyDescriptor:j}=Object,x=Object.prototype.hasOwnProperty;function A(e){return this[e]}var B=(e)=>{var t=(y??=new WeakMap).get(e),n;if(t)return t;if(t=F({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function"){for(var i of E(e))if(!x.call(t,i))F(t,i,{get:A.bind(e,i),enumerable:!(n=j(e,i))||n.enumerable})}return y.set(e,t),t},y;var D=(e)=>e;function J(e,t){this[e]=D.bind(null,t)}var Q=(e,t)=>{for(var n in t)F(e,n,{get:t[n],enumerable:!0,configurable:!0,set:J.bind(t,n)})};var W={};Q(W,{default:()=>z,resetInit:()=>G});module.exports=B(W);var o=require("node:fs"),m=require("node:http"),g=require("@devup-ui/plugin-utils"),r=require("@devup-ui/wasm"),C=!1,c=null,U=new m.Agent({keepAlive:!0});function R(e){if(c!==null)return c;return c=parseInt(o.readFileSync(e,"utf-8").trim()),c}function T(e,t,n,i,a){let u=new URLSearchParams;if(t!=null)u.set("fileNum",String(t));if(u.set("importMainCss",String(n)),i)u.set("waitForIdle","true");let l=m.request({hostname:"127.0.0.1",port:e,path:`/css?${u.toString()}`,method:"GET",agent:U},(s)=>{let f=[];s.on("data",(h)=>f.push(h)),s.on("end",()=>{if(s.statusCode!==200){a(Error(`Coordinator CSS error: ${s.statusCode}`));return}a(null,Buffer.concat(f).toString("utf-8"))})});l.on("error",(s)=>a(s)),l.end()}var q=function(e,t,n){let{watch:i,coordinatorPortFile:a,sheetFile:u,classMapFile:l,fileMapFile:s,themeFile:f,theme:h,defaultClassMap:v,defaultFileMap:O,defaultSheet:P}=this.getOptions();if(a){let p=this.async(),I=this.resourceQuery??"",L=this.resourcePath+I,S=g.getFileNumByFilename(L),N=S!==null,b=(M)=>{if(!o.existsSync(a)){if(M>0){setTimeout(()=>b(M-1),50);return}p(Error("Coordinator port file not found"));return}try{let d=R(a);T(d,S,N,!i,(w,k)=>{if(w)return p(w);p(null,k)})}catch(d){p(d)}};b(20);return}if(!C)if(C=!0,i){if(o.existsSync(u))r.importSheet(JSON.parse(o.readFileSync(u,"utf-8")));if(o.existsSync(l))r.importClassMap(JSON.parse(o.readFileSync(l,"utf-8")));if(o.existsSync(s))r.importFileMap(JSON.parse(o.readFileSync(s,"utf-8")));if(o.existsSync(f))r.registerTheme(JSON.parse(o.readFileSync(f,"utf-8"))?.theme??{})}else r.importFileMap(O),r.importClassMap(v),r.importSheet(P),r.registerTheme(h);this.callback(null,!i?e:r.getCss(g.getFileNumByFilename(this.resourcePath),!0),t,n)},z=q,G=()=>{C=!1,c=null};