@popmelt.com/core 0.7.8 → 0.8.0

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 +1 @@
1
- import{request as y}from"http";function R(d){let h=d?.basePath??"/popmelt",P=d?.bridge!==!1,r=null,i=null,f=null;return{name:"popmelt",hooks:{async"astro:server:setup"({server:u}){if(!P||process.env.POPMELT_BRIDGE_URL){if(process.env.POPMELT_BRIDGE_URL)try{r=new URL(process.env.POPMELT_BRIDGE_URL).port?parseInt(new URL(process.env.POPMELT_BRIDGE_URL).port,10):null,i=process.env.POPMELT_PROJECT_ID||null}catch{}}else try{let{startPopmelt:o}=await import("./server-WF6OWM5R.mjs"),t=u.config,l=t?.server?.host===!0?"0.0.0.0":t?.server?.host||"localhost",a=t?.server?.port??4321,c=`http://${l==="0.0.0.0"?"localhost":l}:${a}`,n=await o({port:d?.port,projectRoot:d?.projectRoot,devOrigin:c,force:!0,detached:!0});r=n.port,i=n.projectId,f=n.close,console.log(`[popmelt] bridge ready at http://localhost:${r}`)}catch(o){console.warn("[popmelt] bridge failed to start:",o.message??o)}u.middlewares.use((o,t,l)=>{let a=o.url||"";if(a.startsWith(h)){if(r===null)return l();let c=`http://localhost:${r}`,n=a.slice(h.length),s=n==="/status"?"/status":"/canvas"+n,e=new URL(s,c);i&&e.searchParams.set("projectId",i);let g=y(e,{method:o.method,headers:{...o.headers,host:e.host}},p=>{t.writeHead(p.statusCode||502,p.headers),p.pipe(t)});g.on("error",()=>{t.writeHead(502,{"Content-Type":"text/plain"}),t.end(`Popmelt bridge not running on port ${r}`)}),o.pipe(g);return}if(r!==null&&(o.headers.accept?.includes("text/html")||a==="/"||a.endsWith(".html"))){let c=t.write,n=t.end,s="";t.write=function(e,...g){return s+=typeof e=="string"?e:e.toString("utf8"),!0},t.end=function(e,...g){e&&(s+=typeof e=="string"?e:e.toString("utf8"));let p=`http://localhost:${r}`,m=`<script type="text/javascript">window.__POPMELT_BRIDGE_URL__=${JSON.stringify(p)};window.__POPMELT_PROJECT_ID__=${JSON.stringify(i)};</script>`;s=s.replace("<head>",`<head>${m}`),t.getHeader("content-length")&&t.setHeader("content-length",Buffer.byteLength(s)),c.call(t,s,"utf8"),n.call(t)}}l()})}}}}export{R as popmelt};
1
+ import{request as y}from"http";function R(d){let h=d?.basePath??"/popmelt",P=d?.bridge!==!1,r=null,i=null,f=null;return{name:"popmelt",hooks:{async"astro:server:setup"({server:u}){if(!P||process.env.POPMELT_BRIDGE_URL){if(process.env.POPMELT_BRIDGE_URL)try{r=new URL(process.env.POPMELT_BRIDGE_URL).port?parseInt(new URL(process.env.POPMELT_BRIDGE_URL).port,10):null,i=process.env.POPMELT_PROJECT_ID||null}catch{}}else try{let{startPopmelt:o}=await import("./server-GDRYHJ4Q.mjs"),t=u.config,l=t?.server?.host===!0?"0.0.0.0":t?.server?.host||"localhost",a=t?.server?.port??4321,c=`http://${l==="0.0.0.0"?"localhost":l}:${a}`,n=await o({port:d?.port,projectRoot:d?.projectRoot,devOrigin:c,force:!0,detached:!0});r=n.port,i=n.projectId,f=n.close,console.log(`[popmelt] bridge ready at http://localhost:${r}`)}catch(o){console.warn("[popmelt] bridge failed to start:",o.message??o)}u.middlewares.use((o,t,l)=>{let a=o.url||"";if(a.startsWith(h)){if(r===null)return l();let c=`http://localhost:${r}`,n=a.slice(h.length),s=n==="/status"?"/status":"/canvas"+n,e=new URL(s,c);i&&e.searchParams.set("projectId",i);let g=y(e,{method:o.method,headers:{...o.headers,host:e.host}},p=>{t.writeHead(p.statusCode||502,p.headers),p.pipe(t)});g.on("error",()=>{t.writeHead(502,{"Content-Type":"text/plain"}),t.end(`Popmelt bridge not running on port ${r}`)}),o.pipe(g);return}if(r!==null&&(o.headers.accept?.includes("text/html")||a==="/"||a.endsWith(".html"))){let c=t.write,n=t.end,s="";t.write=function(e,...g){return s+=typeof e=="string"?e:e.toString("utf8"),!0},t.end=function(e,...g){e&&(s+=typeof e=="string"?e:e.toString("utf8"));let p=`http://localhost:${r}`,m=`<script type="text/javascript">window.__POPMELT_BRIDGE_URL__=${JSON.stringify(p)};window.__POPMELT_PROJECT_ID__=${JSON.stringify(i)};</script>`;s=s.replace("<head>",`<head>${m}`),t.getHeader("content-length")&&t.setHeader("content-length",Buffer.byteLength(s)),c.call(t,s,"utf8"),n.call(t)}}l()})}}}}export{R as popmelt};
@@ -1 +1 @@
1
- var H=Object.defineProperty,V=Object.defineProperties;var W=Object.getOwnPropertyDescriptors;var $=Object.getOwnPropertySymbols;var J=Object.prototype.hasOwnProperty,K=Object.prototype.propertyIsEnumerable;var C=(t,e,r)=>e in t?H(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,v=(t,e)=>{for(var r in e||(e={}))J.call(e,r)&&C(t,r,e[r]);if($)for(var r of $(e))K.call(e,r)&&C(t,r,e[r]);return t},N=(t,e)=>V(t,W(e));import{NextResponse as _}from"next/server";function D(t){return z(t).slice(0,12)}var X=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];function z(t){let e=typeof TextEncoder!="undefined"?Array.from(new TextEncoder().encode(t)):Q(t),r=e.length*8;for(e.push(128);e.length%64!==56;)e.push(0);for(let b=7;b>=0;b--)e.push(r/Math.pow(2,b*8)&255);let n=1779033703,a=3144134277,u=1013904242,l=2773480762,i=1359893119,s=2600822924,x=528734635,f=1541459225,o=new Array(64);for(let b=0;b<e.length;b+=64){for(let c=0;c<16;c++){let h=b+c*4;o[c]=(e[h]<<24|e[h+1]<<16|e[h+2]<<8|e[h+3])>>>0}for(let c=16;c<64;c++){let h=d(o[c-15],7)^d(o[c-15],18)^o[c-15]>>>3,E=d(o[c-2],17)^d(o[c-2],19)^o[c-2]>>>10;o[c]=o[c-16]+h+o[c-7]+E>>>0}let p=n,P=a,w=u,I=l,m=i,R=s,y=x,j=f;for(let c=0;c<64;c++){let h=d(m,6)^d(m,11)^d(m,25),E=m&R^~m&y,T=j+h+E+X[c]+o[c]>>>0,F=d(p,2)^d(p,13)^d(p,22),k=p&P^p&w^P&w,G=F+k>>>0;j=y,y=R,R=m,m=I+T>>>0,I=w,w=P,P=p,p=T+G>>>0}n=n+p>>>0,a=a+P>>>0,u=u+w>>>0,l=l+I>>>0,i=i+m>>>0,s=s+R>>>0,x=x+y>>>0,f=f+j>>>0}return[n,a,u,l,i,s,x,f].map(b=>b.toString(16).padStart(8,"0")).join("")}function d(t,e){return t>>>e|t<<32-e}function Q(t){let e=[];for(let r=0;r<t.length;r++){let n=t.charCodeAt(r);n<128?e.push(n):n<2048?e.push(192|n>>6,128|n&63):e.push(224|n>>12,128|n>>6&63,128|n&63)}return e}function S(){return parseInt(process.env.POPMELT_BRIDGE_PORT||"1111",10)}var Y=1111,Z=10,U=1e3,g=null;function A(){try{return typeof process!="undefined"&&typeof process.cwd=="function"?process.cwd():null}catch(t){return null}}function L(t=(e=>(e=A())!=null?e:void 0)()){return process.env.POPMELT_PROJECT_ID||(t?D(t):null)}async function B(t,e){let r=new AbortController,n=setTimeout(()=>r.abort(),350);try{let a=new URL("/status",`http://localhost:${t}`);e&&a.searchParams.set("projectId",e);let u=await fetch(a,{signal:r.signal,cache:"no-store"});if(!u.ok)return null;let l=await u.json();return e&&l.projectId!==e?null:l}catch(a){return null}finally{clearTimeout(n)}}async function M(t,e){let r=Date.now();if(g&&g.preferredPort===t&&g.projectId===e&&g.expiresAt>r)return g.port;if(await B(t,e))return g={preferredPort:t,projectId:e,port:t,expiresAt:r+U},t;if(!e)return t;let a=Array.from({length:Z},(s,x)=>Y+x).filter(s=>s!==t),l=(await Promise.all(a.map(async s=>await B(s,e)?s:null))).find(s=>s!==null),i=l!=null?l:t;return g={preferredPort:t,projectId:e,port:i,expiresAt:r+U},i}async function O(t,e,r){let n=await M(e,r),a=new URL(t,`http://localhost:${n}`);return r&&a.searchParams.set("projectId",r),_.rewrite(a)}function ne(t,e){var u,l,i,s,x;let r=(u=e==null?void 0:e.basePath)!=null?u:"/popmelt",n=(l=e==null?void 0:e.port)!=null?l:S(),a=(x=e==null?void 0:e.projectId)!=null?x:L((s=(i=e==null?void 0:e.projectRoot)!=null?i:A())!=null?s:void 0);if(t.nextUrl.searchParams.get("popmelt")==="canvas"){if(process.env.NODE_ENV==="production")return null;let f=new Headers(t.headers);return f.set("x-popmelt-canvas","1"),_.next({request:{headers:f}})}if(t.nextUrl.pathname.startsWith(r+"/render")){if(process.env.NODE_ENV==="production")return null;let f=new Headers(t.headers);return f.set("x-popmelt-canvas","1"),_.next({request:{headers:f}})}if(t.nextUrl.pathname===r||t.nextUrl.pathname.startsWith(r+"/")){if(t.nextUrl.pathname===`${r}/status`)return O("/status",n,a);let f="/canvas"+t.nextUrl.pathname.slice(r.length);return O(f||"/canvas",n,a)}return null}function ce(t,e){var u,l,i,s;if(process.env.NODE_ENV==="production")return t;let r=(u=e==null?void 0:e.port)!=null?u:S(),n=(s=e==null?void 0:e.projectId)!=null?s:L((i=(l=e==null?void 0:e.projectRoot)!=null?l:A())!=null?i:void 0),a=t.rewrites;return N(v({},t),{async rewrites(){let x=a?await a():[],o=`http://localhost:${await M(r,n)}`,b=[{source:"/popmelt/status",destination:n?`${o}/status?projectId=${encodeURIComponent(n)}`:`${o}/status`},{source:"/popmelt",destination:n?`${o}/canvas?projectId=${encodeURIComponent(n)}`:`${o}/canvas`},{source:"/popmelt/:path*",destination:n?`${o}/canvas/:path*?projectId=${encodeURIComponent(n)}`:`${o}/canvas/:path*`}];return Array.isArray(x)?{beforeFiles:b,afterFiles:x,fallback:[]}:N(v({},x),{beforeFiles:[...x.beforeFiles||[],...b]})}})}export{L as getPopmeltProjectId,ne as popmeltMiddleware,ce as withPopmelt};
1
+ var H=Object.defineProperty,V=Object.defineProperties;var W=Object.getOwnPropertyDescriptors;var A=Object.getOwnPropertySymbols;var J=Object.prototype.hasOwnProperty,K=Object.prototype.propertyIsEnumerable;var D=(t,e,r)=>e in t?H(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,v=(t,e)=>{for(var r in e||(e={}))J.call(e,r)&&D(t,r,e[r]);if(A)for(var r of A(e))K.call(e,r)&&D(t,r,e[r]);return t},j=(t,e)=>V(t,W(e));import{NextResponse as N}from"next/server";function B(t){return z(t).slice(0,12)}var X=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];function z(t){let e=typeof TextEncoder!="undefined"?Array.from(new TextEncoder().encode(t)):Q(t),r=e.length*8;for(e.push(128);e.length%64!==56;)e.push(0);for(let b=7;b>=0;b--)e.push(r/Math.pow(2,b*8)&255);let n=1779033703,s=3144134277,u=1013904242,l=2773480762,i=1359893119,a=2600822924,x=528734635,f=1541459225,o=new Array(64);for(let b=0;b<e.length;b+=64){for(let c=0;c<16;c++){let h=b+c*4;o[c]=(e[h]<<24|e[h+1]<<16|e[h+2]<<8|e[h+3])>>>0}for(let c=16;c<64;c++){let h=d(o[c-15],7)^d(o[c-15],18)^o[c-15]>>>3,_=d(o[c-2],17)^d(o[c-2],19)^o[c-2]>>>10;o[c]=o[c-16]+h+o[c-7]+_>>>0}let p=n,P=s,w=u,E=l,m=i,R=a,y=x,I=f;for(let c=0;c<64;c++){let h=d(m,6)^d(m,11)^d(m,25),_=m&R^~m&y,U=I+h+_+X[c]+o[c]>>>0,G=d(p,2)^d(p,13)^d(p,22),F=p&P^p&w^P&w,k=G+F>>>0;I=y,y=R,R=m,m=E+U>>>0,E=w,w=P,P=p,p=U+k>>>0}n=n+p>>>0,s=s+P>>>0,u=u+w>>>0,l=l+E>>>0,i=i+m>>>0,a=a+R>>>0,x=x+y>>>0,f=f+I>>>0}return[n,s,u,l,i,a,x,f].map(b=>b.toString(16).padStart(8,"0")).join("")}function d(t,e){return t>>>e|t<<32-e}function Q(t){let e=[];for(let r=0;r<t.length;r++){let n=t.charCodeAt(r);n<128?e.push(n):n<2048?e.push(192|n>>6,128|n&63):e.push(224|n>>12,128|n>>6&63,128|n&63)}return e}function L(){if(process.env.POPMELT_BRIDGE_URL)try{let t=new URL(process.env.POPMELT_BRIDGE_URL).port;if(t)return parseInt(t,10)}catch(t){}return parseInt(process.env.POPMELT_BRIDGE_PORT||"1111",10)}var Y=1111,Z=10,O=1e3,g=null;function T(){try{return typeof process!="undefined"&&typeof process.cwd=="function"?process.cwd():null}catch(t){return null}}function M(t=(e=>(e=T())!=null?e:void 0)()){return process.env.POPMELT_PROJECT_ID||(t?B(t):null)}async function $(t,e){let r=new AbortController,n=setTimeout(()=>r.abort(),350);try{let s=new URL("/status",`http://localhost:${t}`);e&&s.searchParams.set("projectId",e);let u=await fetch(s,{signal:r.signal,cache:"no-store"});if(!u.ok)return null;let l=await u.json();return e&&l.projectId!==e?null:l}catch(s){return null}finally{clearTimeout(n)}}async function S(t,e){let r=Date.now();if(g&&g.preferredPort===t&&g.projectId===e&&g.expiresAt>r)return g.port;if(await $(t,e))return g={preferredPort:t,projectId:e,port:t,expiresAt:r+O},t;if(!e)return t;let s=Array.from({length:Z},(a,x)=>Y+x).filter(a=>a!==t),l=(await Promise.all(s.map(async a=>await $(a,e)?a:null))).find(a=>a!==null),i=l!=null?l:t;return g={preferredPort:t,projectId:e,port:i,expiresAt:r+O},i}async function C(t,e,r){let n=await S(e,r),s=new URL(t,`http://localhost:${n}`);return r&&s.searchParams.set("projectId",r),N.rewrite(s)}function ne(t,e){var u,l,i,a,x;let r=(u=e==null?void 0:e.basePath)!=null?u:"/popmelt",n=(l=e==null?void 0:e.port)!=null?l:L(),s=(x=e==null?void 0:e.projectId)!=null?x:M((a=(i=e==null?void 0:e.projectRoot)!=null?i:T())!=null?a:void 0);if(t.nextUrl.searchParams.get("popmelt")==="canvas"){if(process.env.NODE_ENV==="production")return null;let f=new Headers(t.headers);return f.set("x-popmelt-canvas","1"),N.next({request:{headers:f}})}if(t.nextUrl.pathname.startsWith(r+"/render")){if(process.env.NODE_ENV==="production")return null;let f=new Headers(t.headers);return f.set("x-popmelt-canvas","1"),N.next({request:{headers:f}})}if(t.nextUrl.pathname===r||t.nextUrl.pathname.startsWith(r+"/")){if(t.nextUrl.pathname===`${r}/status`)return C("/status",n,s);let f="/canvas"+t.nextUrl.pathname.slice(r.length);return C(f||"/canvas",n,s)}return null}function ce(t,e){var u,l,i,a;if(process.env.NODE_ENV==="production")return t;let r=(u=e==null?void 0:e.port)!=null?u:L(),n=(a=e==null?void 0:e.projectId)!=null?a:M((i=(l=e==null?void 0:e.projectRoot)!=null?l:T())!=null?i:void 0),s=t.rewrites;return j(v({},t),{async rewrites(){let x=s?await s():[],o=`http://localhost:${await S(r,n)}`,b=[{source:"/popmelt/status",destination:n?`${o}/status?projectId=${encodeURIComponent(n)}`:`${o}/status`},{source:"/popmelt",destination:n?`${o}/canvas?projectId=${encodeURIComponent(n)}`:`${o}/canvas`},{source:"/popmelt/:path*",destination:n?`${o}/canvas/:path*?projectId=${encodeURIComponent(n)}`:`${o}/canvas/:path*`}];return Array.isArray(x)?{beforeFiles:b,afterFiles:x,fallback:[]}:j(v({},x),{beforeFiles:[...x.beforeFiles||[],...b]})}})}export{M as getPopmeltProjectId,ne as popmeltMiddleware,ce as withPopmelt};
@@ -1 +1 @@
1
- import{request as f}from"http";function R(i){let g=i?.basePath??"/popmelt",h=i?.bridge!==!1,e=null,o=null,P=null;return{name:"popmelt",async configureServer(a){if(!h||process.env.POPMELT_BRIDGE_URL){if(process.env.POPMELT_BRIDGE_URL)try{e=new URL(process.env.POPMELT_BRIDGE_URL).port?parseInt(new URL(process.env.POPMELT_BRIDGE_URL).port,10):null,o=process.env.POPMELT_PROJECT_ID||null}catch{}}else try{let{startPopmelt:t}=await import("./server-WF6OWM5R.mjs"),r=a.config,s=r?.server?.host===!0?"0.0.0.0":r?.server?.host||"localhost",l=r?.server?.port??5173,c=`http://${s==="0.0.0.0"?"localhost":s}:${l}`,n=await t({port:i?.port,projectRoot:i?.projectRoot,devOrigin:c,force:!0,detached:!0});e=n.port,o=n.projectId,P=n.close,console.log(`[popmelt] bridge ready at http://localhost:${e}`)}catch(t){console.warn("[popmelt] bridge failed to start:",t.message??t)}a.middlewares.use((t,r,s)=>{let l=t.url||"";if(!l.startsWith(g)||e===null)return s();let c=`http://localhost:${e}`,n=l.slice(g.length),m=n==="/status"?"/status":"/canvas"+n,p=new URL(m,c);o&&p.searchParams.set("projectId",o);let u=f(p,{method:t.method,headers:{...t.headers,host:p.host}},d=>{r.writeHead(d.statusCode||502,d.headers),d.pipe(r)});u.on("error",()=>{r.writeHead(502,{"Content-Type":"text/plain"}),r.end(`Popmelt bridge not running on port ${e}`)}),t.pipe(u)})},transformIndexHtml(){if(e===null)return;let a=`http://localhost:${e}`;return[{tag:"script",attrs:{type:"text/javascript"},children:`window.__POPMELT_BRIDGE_URL__=${JSON.stringify(a)};window.__POPMELT_PROJECT_ID__=${JSON.stringify(o)};`,injectTo:"head-prepend"}]}}}export{R as popmelt};
1
+ import{request as f}from"http";function R(i){let g=i?.basePath??"/popmelt",h=i?.bridge!==!1,e=null,o=null,P=null;return{name:"popmelt",async configureServer(a){if(!h||process.env.POPMELT_BRIDGE_URL){if(process.env.POPMELT_BRIDGE_URL)try{e=new URL(process.env.POPMELT_BRIDGE_URL).port?parseInt(new URL(process.env.POPMELT_BRIDGE_URL).port,10):null,o=process.env.POPMELT_PROJECT_ID||null}catch{}}else try{let{startPopmelt:t}=await import("./server-GDRYHJ4Q.mjs"),r=a.config,s=r?.server?.host===!0?"0.0.0.0":r?.server?.host||"localhost",l=r?.server?.port??5173,c=`http://${s==="0.0.0.0"?"localhost":s}:${l}`,n=await t({port:i?.port,projectRoot:i?.projectRoot,devOrigin:c,force:!0,detached:!0});e=n.port,o=n.projectId,P=n.close,console.log(`[popmelt] bridge ready at http://localhost:${e}`)}catch(t){console.warn("[popmelt] bridge failed to start:",t.message??t)}a.middlewares.use((t,r,s)=>{let l=t.url||"";if(!l.startsWith(g)||e===null)return s();let c=`http://localhost:${e}`,n=l.slice(g.length),m=n==="/status"?"/status":"/canvas"+n,p=new URL(m,c);o&&p.searchParams.set("projectId",o);let u=f(p,{method:t.method,headers:{...t.headers,host:p.host}},d=>{r.writeHead(d.statusCode||502,d.headers),d.pipe(r)});u.on("error",()=>{r.writeHead(502,{"Content-Type":"text/plain"}),r.end(`Popmelt bridge not running on port ${e}`)}),t.pipe(u)})},transformIndexHtml(){if(e===null)return;let a=`http://localhost:${e}`;return[{tag:"script",attrs:{type:"text/javascript"},children:`window.__POPMELT_BRIDGE_URL__=${JSON.stringify(a)};window.__POPMELT_PROJECT_ID__=${JSON.stringify(o)};`,injectTo:"head-prepend"}]}}}export{R as popmelt};