@popmelt.com/core 0.10.2 → 0.11.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{a as p,b as d,c as l,d as g}from"./chunk-PNWGTRYW.mjs";import"./chunk-NOHXTT24.mjs";import{Buffer as c}from"buffer";function u(e){return typeof e=="string"?e:e instanceof Uint8Array?c.from(e).toString("utf8"):String(e??"")}function m(e,t,r){let o=e.url||"";if(r.port===null||!(e.headers.accept?.includes("text/html")||o==="/"||o.endsWith(".html")))return;let a=t.write.bind(t),s=t.end.bind(t),n="";t.write=(i=>(n+=u(i),!0)),t.end=(i=>(i!==void 0&&(n+=u(i)),n=n.replace("<head>",`<head><script type="text/javascript">${g(r)}</script>`),t.getHeader("content-length")&&t.setHeader("content-length",c.byteLength(n)),a(n,"utf8"),s()))}function y(e){let t=e?.basePath??"/popmelt",r={port:null,projectId:null};return{name:"popmelt",hooks:{async"astro:server:setup"({server:o}){r=await p(e,o,4321),await d(r,o);let a=l(t,()=>r);o.middlewares.use((s,n,i)=>{if((s.url||"").startsWith(t))return a(s,n,i);m(s,n,r),i()})}}}}export{y as popmelt};
1
+ import{a as p,b as d,c as l,d as g}from"./chunk-ETDSFA4K.mjs";import"./chunk-NOHXTT24.mjs";import{Buffer as c}from"buffer";function u(e){return typeof e=="string"?e:e instanceof Uint8Array?c.from(e).toString("utf8"):String(e??"")}function m(e,t,r){let o=e.url||"";if(r.port===null||!(e.headers.accept?.includes("text/html")||o==="/"||o.endsWith(".html")))return;let a=t.write.bind(t),s=t.end.bind(t),n="";t.write=(i=>(n+=u(i),!0)),t.end=(i=>(i!==void 0&&(n+=u(i)),n=n.replace("<head>",`<head><script type="text/javascript">${g(r)}</script>`),t.getHeader("content-length")&&t.setHeader("content-length",c.byteLength(n)),a(n,"utf8"),s()))}function y(e){let t=e?.basePath??"/popmelt",r={port:null,projectId:null};return{name:"popmelt",hooks:{async"astro:server:setup"({server:o}){r=await p(e,o,4321),await d(r,o);let a=l(t,()=>r);o.middlewares.use((s,n,i)=>{if((s.url||"").startsWith(t))return a(s,n,i);m(s,n,r),i()})}}}}export{y as popmelt};
@@ -1 +1 @@
1
- import{NextResponse as v}from"next/server";function T(t){return G(t).slice(0,12)}var S=[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 G(t){let e=typeof TextEncoder<"u"?Array.from(new TextEncoder().encode(t)):F(t),r=e.length*8;for(e.push(128);e.length%64!==56;)e.push(0);for(let f=7;f>=0;f--)e.push(r/Math.pow(2,f*8)&255);let n=1779033703,c=3144134277,s=1013904242,u=2773480762,i=1359893119,a=2600822924,m=528734635,w=1541459225,l=new Array(64);for(let f=0;f<e.length;f+=64){for(let o=0;o<16;o++){let d=f+o*4;l[o]=(e[d]<<24|e[d+1]<<16|e[d+2]<<8|e[d+3])>>>0}for(let o=16;o<64;o++){let d=x(l[o-15],7)^x(l[o-15],18)^l[o-15]>>>3,_=x(l[o-2],17)^x(l[o-2],19)^l[o-2]>>>10;l[o]=l[o-16]+d+l[o-7]+_>>>0}let p=n,g=c,P=s,E=u,b=i,R=a,y=m,I=w;for(let o=0;o<64;o++){let d=x(b,6)^x(b,11)^x(b,25),_=b&R^~b&y,N=I+d+_+S[o]+l[o]>>>0,C=x(p,2)^x(p,13)^x(p,22),L=p&g^p&P^g&P,M=C+L>>>0;I=y,y=R,R=b,b=E+N>>>0,E=P,P=g,g=p,p=N+M>>>0}n=n+p>>>0,c=c+g>>>0,s=s+P>>>0,u=u+E>>>0,i=i+b>>>0,a=a+R>>>0,m=m+y>>>0,w=w+I>>>0}return[n,c,s,u,i,a,m,w].map(f=>f.toString(16).padStart(8,"0")).join("")}function x(t,e){return t>>>e|t<<32-e}function F(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 B(){if(process.env.POPMELT_BRIDGE_URL)try{let t=new URL(process.env.POPMELT_BRIDGE_URL).port;if(t)return parseInt(t,10)}catch{}return parseInt(process.env.POPMELT_BRIDGE_PORT||"1111",10)}var k=1111,H=10,U=1e3,h=null;function j(){try{return typeof process<"u"&&typeof process.cwd=="function"?process.cwd():null}catch{return null}}function O(t=j()??void 0){return process.env.POPMELT_PROJECT_ID||(t?T(t):null)}async function A(t,e){let r=new AbortController,n=setTimeout(()=>r.abort(),350);try{let c=new URL("/status",`http://localhost:${t}`);e&&c.searchParams.set("projectId",e);let s=await fetch(c,{signal:r.signal,cache:"no-store"});if(!s.ok)return null;let u=await s.json();return e&&u.projectId!==e?null:u}catch{return null}finally{clearTimeout(n)}}async function $(t,e){let r=Date.now();if(h&&h.preferredPort===t&&h.projectId===e&&h.expiresAt>r)return h.port;if(await A(t,e))return h={preferredPort:t,projectId:e,port:t,expiresAt:r+U},t;if(!e)return t;let c=Array.from({length:H},(a,m)=>k+m).filter(a=>a!==t),i=(await Promise.all(c.map(async a=>await A(a,e)?a:null))).find(a=>a!==null)??t;return h={preferredPort:t,projectId:e,port:i,expiresAt:r+U},i}async function D(t,e,r){let n=await $(e,r),c=new URL(t,`http://localhost:${n}`);return r&&c.searchParams.set("projectId",r),v.rewrite(c)}function K(t,e){let r=e?.basePath??"/popmelt",n=e?.port??B(),c=e?.projectId??O(e?.projectRoot??j()??void 0);if(t.nextUrl.searchParams.get("popmelt")==="canvas"){if(process.env.NODE_ENV==="production")return null;let s=new Headers(t.headers);return s.set("x-popmelt-canvas","1"),v.next({request:{headers:s}})}if(t.nextUrl.pathname.startsWith(r+"/render")){if(process.env.NODE_ENV==="production")return null;let s=new Headers(t.headers);return s.set("x-popmelt-canvas","1"),v.next({request:{headers:s}})}if(t.nextUrl.pathname===r||t.nextUrl.pathname.startsWith(r+"/")){if(t.nextUrl.pathname===`${r}/status`)return D("/status",n,c);let s="/canvas"+t.nextUrl.pathname.slice(r.length);return D(s||"/canvas",n,c)}return null}function X(t,e){if(process.env.NODE_ENV==="production")return t;let r=e?.port??B(),n=e?.projectId??O(e?.projectRoot??j()??void 0),c=t.rewrites;return{...t,async rewrites(){let s=c?await c():[],i=`http://localhost:${await $(r,n)}`,a=[{source:"/popmelt/status",destination:n?`${i}/status?projectId=${encodeURIComponent(n)}`:`${i}/status`},{source:"/popmelt",destination:n?`${i}/canvas?projectId=${encodeURIComponent(n)}`:`${i}/canvas`},{source:"/popmelt/:path*",destination:n?`${i}/canvas/:path*?projectId=${encodeURIComponent(n)}`:`${i}/canvas/:path*`}];return Array.isArray(s)?{beforeFiles:a,afterFiles:s,fallback:[]}:{...s,beforeFiles:[...s.beforeFiles||[],...a]}}}}export{O as getPopmeltProjectId,K as popmeltMiddleware,X as withPopmelt};
1
+ import{NextResponse as A}from"next/server";function I(e){return U(e).slice(0,12)}var S=[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 U(e){let t=typeof TextEncoder<"u"?Array.from(new TextEncoder().encode(e)):$(e),o=t.length*8;for(t.push(128);t.length%64!==56;)t.push(0);for(let f=7;f>=0;f--)t.push(o/Math.pow(2,f*8)&255);let r=1779033703,c=3144134277,a=1013904242,x=2773480762,i=1359893119,s=2600822924,m=528734635,w=1541459225,l=new Array(64);for(let f=0;f<t.length;f+=64){for(let n=0;n<16;n++){let d=f+n*4;l[n]=(t[d]<<24|t[d+1]<<16|t[d+2]<<8|t[d+3])>>>0}for(let n=16;n<64;n++){let d=u(l[n-15],7)^u(l[n-15],18)^l[n-15]>>>3,_=u(l[n-2],17)^u(l[n-2],19)^l[n-2]>>>10;l[n]=l[n-16]+d+l[n-7]+_>>>0}let b=r,g=c,P=a,j=x,p=i,R=s,y=m,E=w;for(let n=0;n<64;n++){let d=u(p,6)^u(p,11)^u(p,25),_=p&R^~p&y,T=E+d+_+S[n]+l[n]>>>0,O=u(b,2)^u(b,13)^u(b,22),v=b&g^b&P^g&P,M=O+v>>>0;E=y,y=R,R=p,p=j+T>>>0,j=P,P=g,g=b,b=T+M>>>0}r=r+b>>>0,c=c+g>>>0,a=a+P>>>0,x=x+j>>>0,i=i+p>>>0,s=s+R>>>0,m=m+y>>>0,w=w+E>>>0}return[r,c,a,x,i,s,m,w].map(f=>f.toString(16).padStart(8,"0")).join("")}function u(e,t){return e>>>t|e<<32-t}function $(e){let t=[];for(let o=0;o<e.length;o++){let r=e.charCodeAt(o);r<128?t.push(r):r<2048?t.push(192|r>>6,128|r&63):t.push(224|r>>12,128|r>>6&63,128|r&63)}return t}function D(){if(process.env.POPMELT_BRIDGE_URL)try{let e=new URL(process.env.POPMELT_BRIDGE_URL).port;if(e)return parseInt(e,10)}catch{}return parseInt(process.env.POPMELT_BRIDGE_PORT||"1111",10)}var G=1111,F=10,B=1e3,h=null;function k(){try{return typeof process<"u"&&typeof process.cwd=="function"?process.cwd():null}catch{return null}}function L(e){if(e)return I(e);let t=k();return process.env.POPMELT_PROJECT_ID||(t?I(t):null)}async function C(e,t){let o=new AbortController,r=setTimeout(()=>o.abort(),350);try{let c=new URL("/status",`http://localhost:${e}`);t&&c.searchParams.set("projectId",t);let a=await fetch(c,{signal:o.signal,cache:"no-store"});if(!a.ok)return null;let x=await a.json();return t&&x.projectId!==t?null:x}catch{return null}finally{clearTimeout(r)}}async function N(e,t){let o=Date.now();if(h&&h.preferredPort===e&&h.projectId===t&&h.expiresAt>o)return h.port;if(await C(e,t))return h={preferredPort:e,projectId:t,port:e,expiresAt:o+B},e;if(!t)return e;let c=Array.from({length:F},(s,m)=>G+m).filter(s=>s!==e),i=(await Promise.all(c.map(async s=>await C(s,t)?s:null))).find(s=>s!==null)??null;return h={preferredPort:e,projectId:t,port:i,expiresAt:o+B},i}async function q(e,t){let o=await N(e,t);if(o===null)return A.json({error:"Popmelt bridge unavailable for this project",projectId:t},{status:503,headers:{"Cache-Control":"no-store"}});let r=new URL("/status",`http://localhost:${o}`);return t&&r.searchParams.set("projectId",t),A.rewrite(r)}function V(e,t){let o=t?.basePath??"/popmelt",r=t?.port??D(),c=t?.projectId??L(t?.projectRoot);return e.nextUrl.pathname===`${o}/status`?q(r,c):null}function X(e,t){if(process.env.NODE_ENV==="production")return e;let o=t?.port??D(),r=t?.projectId??L(t?.projectRoot),c=e.rewrites;return{...e,async rewrites(){let a=c?await c():[],i=`http://localhost:${await N(o,r)??o}`,s=[{source:"/popmelt/status",destination:r?`${i}/status?projectId=${encodeURIComponent(r)}`:`${i}/status`}];return Array.isArray(a)?{beforeFiles:s,afterFiles:a,fallback:[]}:{...a,beforeFiles:[...a.beforeFiles||[],...s]}}}}export{L as getPopmeltProjectId,V as popmeltMiddleware,X as withPopmelt};
@@ -1 +1 @@
1
- import{a as n,b as i,c as o,d as a}from"./chunk-PNWGTRYW.mjs";import"./chunk-NOHXTT24.mjs";function s(r){let d=r?.basePath??"/popmelt",e={port:null,projectId:null};return{name:"popmelt",async configureServer(t){e=await n(r,t,5173),await i(e,t),t.middlewares.use(o(d,()=>e))},transformIndexHtml(){if(e.port!==null)return[{tag:"script",attrs:{type:"text/javascript"},children:a(e),injectTo:"head-prepend"}]}}}export{s as popmelt};
1
+ import{a as n,b as i,c as o,d as a}from"./chunk-ETDSFA4K.mjs";import"./chunk-NOHXTT24.mjs";function s(r){let d=r?.basePath??"/popmelt",e={port:null,projectId:null};return{name:"popmelt",async configureServer(t){e=await n(r,t,5173),await i(e,t),t.middlewares.use(o(d,()=>e))},transformIndexHtml(){if(e.port!==null)return[{tag:"script",attrs:{type:"text/javascript"},children:a(e),injectTo:"head-prepend"}]}}}export{s as popmelt};