@popmelt.com/core 0.6.5 → 0.6.7
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/dist/bridge-entry.mjs +135 -47
- package/dist/cli.mjs +135 -47
- package/dist/index.mjs +22 -22
- package/dist/plugin-astro.mjs +1 -1
- package/dist/plugin-vite.mjs +1 -1
- package/dist/react-scanner-P3VD53VT.mjs +1 -0
- package/dist/react-scanner-ZXYS5M3Y.mjs +2 -0
- package/dist/render-generator-EANIDD2E.mjs +107 -0
- package/dist/render-generator-HWFLZYC3.mjs +106 -0
- package/dist/server-E44GIKD2.mjs +221 -0
- package/dist/server.mjs +133 -45
- package/package.json +1 -1
- package/dist/chunk-3HWT3PC2.mjs +0 -1
- package/dist/chunk-4LDJX6BW.mjs +0 -2
- package/dist/react-scanner-5NIJ6ZPL.mjs +0 -1
- package/dist/react-scanner-MSMGKCIV.mjs +0 -2
- package/dist/render-generator-QV5BYGPF.mjs +0 -107
- package/dist/render-generator-ZNV3RDU7.mjs +0 -106
- package/dist/server-CXH52R3U.mjs +0 -133
package/dist/plugin-astro.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{request as P}from"http";function y(c){let d=c?.basePath??"/popmelt",h=c?.bridge!==!1,n=null,u=null;return{name:"popmelt",hooks:{async"astro:server:setup"({server:g}){if(!h||process.env.POPMELT_BRIDGE_URL){if(process.env.POPMELT_BRIDGE_URL)try{n=new URL(process.env.POPMELT_BRIDGE_URL).port?parseInt(new URL(process.env.POPMELT_BRIDGE_URL).port,10):null}catch{}}else try{let{startPopmelt:o}=await import("./server-E44GIKD2.mjs"),t=g.config,i=t?.server?.host===!0?"0.0.0.0":t?.server?.host||"localhost",s=t?.server?.port??4321,l=`http://${i==="0.0.0.0"?"localhost":i}:${s}`,a=await o({port:c?.port,projectRoot:c?.projectRoot,devOrigin:l,force:!0,detached:!0});n=a.port,u=a.close,console.log(`[popmelt] bridge ready at http://localhost:${n}`)}catch(o){console.warn("[popmelt] bridge failed to start:",o.message??o)}g.middlewares.use((o,t,i)=>{let s=o.url||"";if(s.startsWith(d)){if(n===null)return i();let l=`http://localhost:${n}`,a="/canvas"+s.slice(d.length),r=new URL(a,l),e=P(r,{method:o.method,headers:{...o.headers,host:r.host}},p=>{t.writeHead(p.statusCode||502,p.headers),p.pipe(t)});e.on("error",()=>{t.writeHead(502,{"Content-Type":"text/plain"}),t.end(`Popmelt bridge not running on port ${n}`)}),o.pipe(e);return}if(n!==null&&(o.headers.accept?.includes("text/html")||s==="/"||s.endsWith(".html"))){let l=t.write,a=t.end,r="";t.write=function(e,...p){return r+=typeof e=="string"?e:e.toString("utf8"),!0},t.end=function(e,...p){e&&(r+=typeof e=="string"?e:e.toString("utf8"));let m=`<script type="text/javascript">window.__POPMELT_BRIDGE_URL__="http://localhost:${n}";</script>`;r=r.replace("<head>",`<head>${m}`),t.getHeader("content-length")&&t.setHeader("content-length",Buffer.byteLength(r)),l.call(t,r,"utf8"),a.call(t)}}i()})}}}}export{y as popmelt};
|
package/dist/plugin-vite.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{request as m}from"http";function f(n){let c=n?.basePath??"/popmelt",u=n?.bridge!==!1,e=null,h=null;return{name:"popmelt",async configureServer(p){if(!u||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}catch{}}else try{let{startPopmelt:t}=await import("./server-E44GIKD2.mjs"),r=p.config,o=r?.server?.host===!0?"0.0.0.0":r?.server?.host||"localhost",s=r?.server?.port??5173,i=`http://${o==="0.0.0.0"?"localhost":o}:${s}`,a=await t({port:n?.port,projectRoot:n?.projectRoot,devOrigin:i,force:!0,detached:!0});e=a.port,h=a.close,console.log(`[popmelt] bridge ready at http://localhost:${e}`)}catch(t){console.warn("[popmelt] bridge failed to start:",t.message??t)}p.middlewares.use((t,r,o)=>{let s=t.url||"";if(!s.startsWith(c)||e===null)return o();let i=`http://localhost:${e}`,a="/canvas"+s.slice(c.length),d=new URL(a,i),g=m(d,{method:t.method,headers:{...t.headers,host:d.host}},l=>{r.writeHead(l.statusCode||502,l.headers),l.pipe(r)});g.on("error",()=>{r.writeHead(502,{"Content-Type":"text/plain"}),r.end(`Popmelt bridge not running on port ${e}`)}),t.pipe(g)})},transformIndexHtml(){if(e!==null)return[{tag:"script",attrs:{type:"text/javascript"},children:`window.__POPMELT_BRIDGE_URL__="http://localhost:${e}";`,injectTo:"head-prepend"}]}}}export{f as popmelt};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{readdir as h,readFile as d,stat as Z}from"fs/promises";import{basename as F,dirname as A,join as m,relative as y}from"path";var w=new Set(["node_modules",".next","dist","__popmelt",".git",".turbo"]),R=[/\.test\.tsx?$/,/\.spec\.tsx?$/,/\.stories\.tsx?$/],x=/^[A-Z][a-zA-Z0-9]+$/,D=[{regex:/export\s+function\s+([A-Z][a-zA-Z0-9]+)/g,type:"named"},{regex:/export\s+default\s+function\s+([A-Z][a-zA-Z0-9]+)/g,type:"default"},{regex:/export\s+const\s+([A-Z][a-zA-Z0-9]+)\s*[=:]/g,type:"named"},{regex:/export\s+default\s+([A-Z][a-zA-Z0-9]+)\s*;/g,type:"default"}];async function E(e,n){let s=[],o=await h(e,{withFileTypes:!0});for(let t of o)if(t.isDirectory()){if(w.has(t.name))continue;let r=await E(m(e,t.name),n);s.push(...r)}else if(t.isFile()&&t.name.endsWith(".tsx")){let r=m(e,t.name),p=y(n,r);if(R.some(i=>i.test(p)))continue;s.push(r)}return s}function M(e,n,s){let o=y(s,n),t=[],r=new Set;for(let{regex:p,type:i}of D){p.lastIndex=0;let a;for(;(a=p.exec(e))!==null;){let c=a[1];if(r.has(c)||!x.test(c))continue;r.add(c);let f,u=A(o);u!=="."&&(f=u.replace(/^app\//,"").replace(/^src\//,"")),t.push({name:c,filePath:o,exportType:i,category:f})}}return t}async function T(e){let n=new Map,s=m(e,"app"),o;try{await Z(s),o=await P(s,e)}catch{return n}for(let t of o){let r=await d(t,"utf-8"),i="/"+A(y(e,t)).replace(/^app\/?/,"").replace(/\([^)]+\)\/?/g,"").replace(/\/$/,""),a=/import\s+.*?from\s+['"](\.\.?\/[^'"]+)['"]/g,c;for(;(c=a.exec(r))!==null;){let f=c[1],u=F(f).replace(/\.(tsx?|jsx?)$/,""),C=c[0].match(/\b([A-Z][a-zA-Z0-9]+)\b/g)||[];for(let l of C){if(!x.test(l))continue;let g=n.get(l)??[];g.includes(i)||g.push(i),n.set(l,g)}if(x.test(u)){let l=n.get(u)??[];l.includes(i)||l.push(i),n.set(u,l)}}}return n}async function P(e,n){let s=[],o=await h(e,{withFileTypes:!0});for(let t of o)if(t.isDirectory()){if(w.has(t.name))continue;s.push(...await P(m(e,t.name),n))}else t.isFile()&&t.name==="page.tsx"&&s.push(m(e,t.name));return s}async function b(e){let n=await E(e,e),s=await T(e),o=[];for(let t of n){let r=await d(t,"utf-8"),p=M(r,t,e);for(let i of p){let a=s.get(i.name);a&&a.length>0&&(i.routes=a),o.push(i)}}return o.sort((t,r)=>t.name.localeCompare(r.name)),{version:1,scannedAt:Date.now(),components:o}}export{b as scanForComponents};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{readdir as h,readFile as d,stat as Z}from"fs/promises";import{basename as F,dirname as A,join as m,relative as y}from"path";var w=new Set(["node_modules",".next","dist","__popmelt",".git",".turbo"]),R=[/\.test\.tsx?$/,/\.spec\.tsx?$/,/\.stories\.tsx?$/],x=/^[A-Z][a-zA-Z0-9]+$/,D=[{regex:/export\s+function\s+([A-Z][a-zA-Z0-9]+)/g,type:"named"},{regex:/export\s+default\s+function\s+([A-Z][a-zA-Z0-9]+)/g,type:"default"},{regex:/export\s+const\s+([A-Z][a-zA-Z0-9]+)\s*[=:]/g,type:"named"},{regex:/export\s+default\s+([A-Z][a-zA-Z0-9]+)\s*;/g,type:"default"}];async function E(e,n){let s=[],o=await h(e,{withFileTypes:!0});for(let t of o)if(t.isDirectory()){if(w.has(t.name))continue;let r=await E(m(e,t.name),n);s.push(...r)}else if(t.isFile()&&t.name.endsWith(".tsx")){let r=m(e,t.name),p=y(n,r);if(R.some(i=>i.test(p)))continue;s.push(r)}return s}function M(e,n,s){let o=y(s,n),t=[],r=new Set;for(let{regex:p,type:i}of D){p.lastIndex=0;let a;for(;(a=p.exec(e))!==null;){let c=a[1];if(r.has(c)||!x.test(c))continue;r.add(c);let f,u=A(o);u!=="."&&(f=u.replace(/^app\//,"").replace(/^src\//,"")),t.push({name:c,filePath:o,exportType:i,category:f})}}return t}async function T(e){let n=new Map,s=m(e,"app"),o;try{await Z(s),o=await P(s,e)}catch{return n}for(let t of o){let r=await d(t,"utf-8"),i="/"+A(y(e,t)).replace(/^app\/?/,"").replace(/\([^)]+\)\/?/g,"").replace(/\/$/,""),a=/import\s+.*?from\s+['"](\.\.?\/[^'"]+)['"]/g,c;for(;(c=a.exec(r))!==null;){let f=c[1],u=F(f).replace(/\.(tsx?|jsx?)$/,""),C=c[0].match(/\b([A-Z][a-zA-Z0-9]+)\b/g)||[];for(let l of C){if(!x.test(l))continue;let g=n.get(l)??[];g.includes(i)||g.push(i),n.set(l,g)}if(x.test(u)){let l=n.get(u)??[];l.includes(i)||l.push(i),n.set(u,l)}}}return n}async function P(e,n){let s=[],o=await h(e,{withFileTypes:!0});for(let t of o)if(t.isDirectory()){if(w.has(t.name))continue;s.push(...await P(m(e,t.name),n))}else t.isFile()&&t.name==="page.tsx"&&s.push(m(e,t.name));return s}async function b(e){let n=await E(e,e),s=await T(e),o=[];for(let t of n){let r=await d(t,"utf-8"),p=M(r,t,e);for(let i of p){let a=s.get(i.name);a&&a.length>0&&(i.routes=a),o.push(i)}}return o.sort((t,r)=>t.name.localeCompare(r.name)),{version:1,scannedAt:Date.now(),components:o}}export{b as scanForComponents};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{createHash as x}from"crypto";import{mkdir as m,readFile as p,rm as S,stat as P,writeFile as f}from"fs/promises";import{dirname as w,join as a,relative as b,resolve as v}from"path";function g(t,r){let n=`${t}::${r}`,s=5381;for(let e=0;e<n.length;e++)s=(s<<5)+s+n.charCodeAt(e)&4294967295;return(s>>>0).toString(16).padStart(8,"0")}var h=/\/\/.*$|\/\*[\s\S]*?\*\//gm;async function k(t){let r={root:t,entries:[]};try{let n=await p(a(t,"tsconfig.json"),"utf-8"),s=JSON.parse(n.replace(h,"")),e=s.compilerOptions?.paths,o=s.compilerOptions?.baseUrl??".";if(!e&&s.extends)try{let i=a(t,s.extends),l=await p(i,"utf-8"),u=JSON.parse(l.replace(h,""));e=u.compilerOptions?.paths,o=u.compilerOptions?.baseUrl??o}catch{}return e?{root:a(t,o),entries:Object.entries(e)}:r}catch{return r}}function R(t,r){for(let[n,s]of r.entries)if(n.endsWith("/*")){let e=n.slice(0,-1);if(t.startsWith(e)){let o=t.slice(e.length),i=s[0],l=i.endsWith("/*")?i.slice(0,-1):i;return a(r.root,l,o)}}else if(n===t&&s.length>0)return a(r.root,s[0]);return null}var T=[".tsx",".ts",".jsx",".js","/index.tsx","/index.ts"];async function y(t){for(let r of["",...T])try{if((await P(t+r)).isFile())return!0}catch{}return!1}async function E(t,r,n){try{let s=a(r,t),e=await p(s,"utf-8"),o=[],i=/from\s+['"]([^'"]+)['"]/g,l;for(;(l=i.exec(e))!==null;){let c=l[1];if(c.startsWith("."))o.push(y(v(w(s),c)));else{let d=R(c,n);d&&o.push(y(d))}}return(await Promise.all(o)).every(Boolean)}catch{return!1}}async function O(t,r){let n=await k(r);return(await Promise.all(t.components.map(async e=>await E(e.filePath,r,n)?{key:`${e.filePath}::${e.name}`,slug:g(e.filePath,e.name),filePath:e.filePath,exportName:e.name,exportType:e.exportType}:(console.warn(`[Popmelt] Skipping ${e.filePath}::${e.name} \u2014 unresolvable imports`),null)))).filter(e=>e!==null)}var C=12;function A(t){let r=t.map(n=>n.key).sort().join(`
|
|
3
|
+
`);return x("sha256").update(C+`
|
|
4
|
+
`+r).digest("hex").slice(0,16)}async function $(t){for(let r of["app","src/app"]){let n=a(t,r);try{if((await P(n)).isDirectory())return n}catch{}}return null}function N(t){return t.split("\\").join("/")}function M(t,r,n){let s=a(n,t.filePath.replace(/\.(tsx?|jsx?)$/,"")),e=JSON.stringify(N(b(r,s)));return t.exportType==="default"?`'use client';
|
|
5
|
+
import dynamic from 'next/dynamic';
|
|
6
|
+
export default dynamic(() => import(${e}), { ssr: false });
|
|
7
|
+
`:`'use client';
|
|
8
|
+
import dynamic from 'next/dynamic';
|
|
9
|
+
export default dynamic(
|
|
10
|
+
() => import(${e}).then(mod => ({ default: mod.${t.exportName} })),
|
|
11
|
+
{ ssr: false },
|
|
12
|
+
);
|
|
13
|
+
`}var W=`// Auto-generated by Popmelt scanner \u2014 do not edit
|
|
14
|
+
'use client';
|
|
15
|
+
|
|
16
|
+
import { useEffect, type ReactNode } from 'react';
|
|
17
|
+
|
|
18
|
+
export default function PopmeltRenderLayout({ children }: { children: ReactNode }) {
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
const origPush = history.pushState.bind(history);
|
|
21
|
+
const origReplace = history.replaceState.bind(history);
|
|
22
|
+
|
|
23
|
+
history.pushState = function (...args: Parameters<typeof history.pushState>) {
|
|
24
|
+
const url = args[2];
|
|
25
|
+
if (url && String(url).indexOf('/popmelt/render') !== 0) {
|
|
26
|
+
console.warn('[Popmelt] Blocked navigation to:', url);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
return origPush(...args);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
history.replaceState = function (...args: Parameters<typeof history.replaceState>) {
|
|
33
|
+
const url = args[2];
|
|
34
|
+
if (url && String(url).indexOf('/popmelt/render') !== 0) {
|
|
35
|
+
console.warn('[Popmelt] Blocked navigation to:', url);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
return origReplace(...args);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const handleClick = (e: MouseEvent) => {
|
|
42
|
+
const anchor = (e.target as Element).closest?.('a');
|
|
43
|
+
if (!anchor) return;
|
|
44
|
+
const href = anchor.getAttribute('href');
|
|
45
|
+
if (href && !href.startsWith('/popmelt/render') && !href.startsWith('#')) {
|
|
46
|
+
e.preventDefault();
|
|
47
|
+
e.stopPropagation();
|
|
48
|
+
console.warn('[Popmelt] Blocked link navigation to:', href);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
document.addEventListener('click', handleClick, true);
|
|
53
|
+
|
|
54
|
+
return () => {
|
|
55
|
+
history.pushState = origPush;
|
|
56
|
+
history.replaceState = origReplace;
|
|
57
|
+
document.removeEventListener('click', handleClick, true);
|
|
58
|
+
};
|
|
59
|
+
}, []);
|
|
60
|
+
|
|
61
|
+
return children;
|
|
62
|
+
}
|
|
63
|
+
`,B=`// Auto-generated by Popmelt scanner \u2014 do not edit
|
|
64
|
+
'use client';
|
|
65
|
+
|
|
66
|
+
export default function PopmeltRenderError({
|
|
67
|
+
error,
|
|
68
|
+
reset,
|
|
69
|
+
}: {
|
|
70
|
+
error: Error & { digest?: string };
|
|
71
|
+
reset: () => void;
|
|
72
|
+
}) {
|
|
73
|
+
return (
|
|
74
|
+
<div style={{ padding: 40, fontFamily: 'system-ui' }}>
|
|
75
|
+
<h2 style={{ color: '#ef4444', fontSize: 16, fontWeight: 600, margin: 0 }}>
|
|
76
|
+
Component render error
|
|
77
|
+
</h2>
|
|
78
|
+
<pre style={{
|
|
79
|
+
marginTop: 12,
|
|
80
|
+
padding: 12,
|
|
81
|
+
background: '#fef2f2',
|
|
82
|
+
border: '1px solid #fecaca',
|
|
83
|
+
fontSize: 12,
|
|
84
|
+
color: '#991b1b',
|
|
85
|
+
whiteSpace: 'pre-wrap',
|
|
86
|
+
wordBreak: 'break-word',
|
|
87
|
+
}}>
|
|
88
|
+
{error.message}
|
|
89
|
+
</pre>
|
|
90
|
+
<button
|
|
91
|
+
onClick={reset}
|
|
92
|
+
style={{
|
|
93
|
+
marginTop: 12,
|
|
94
|
+
padding: '6px 16px',
|
|
95
|
+
fontSize: 12,
|
|
96
|
+
background: '#1f2937',
|
|
97
|
+
color: '#fff',
|
|
98
|
+
border: 'none',
|
|
99
|
+
cursor: 'pointer',
|
|
100
|
+
}}
|
|
101
|
+
>
|
|
102
|
+
Retry
|
|
103
|
+
</button>
|
|
104
|
+
</div>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
`;async function z(t,r,n){let s=await O(t,r);if(s.length===0)return n??"";let e=A(s);if(e===n)return e;let o=await $(r);if(!o)return n??"";let i=a(o,"popmelt","render");await S(i,{recursive:!0,force:!0}),await m(i,{recursive:!0});let l=[f(a(i,"layout.tsx"),W),f(a(i,"error.tsx"),B)];for(let u of s){let c=a(i,u.slug);l.push(m(c,{recursive:!0}).then(()=>f(a(c,"page.tsx"),M(u,c,r))))}return await Promise.all(l),e}export{z as generateRenderFiles};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import{createHash as x}from"crypto";import{mkdir as m,readFile as p,rm as S,stat as P,writeFile as f}from"fs/promises";import{dirname as w,join as a,relative as b,resolve as v}from"path";function g(t,r){let n=`${t}::${r}`,s=5381;for(let e=0;e<n.length;e++)s=(s<<5)+s+n.charCodeAt(e)&4294967295;return(s>>>0).toString(16).padStart(8,"0")}var h=/\/\/.*$|\/\*[\s\S]*?\*\//gm;async function k(t){let r={root:t,entries:[]};try{let n=await p(a(t,"tsconfig.json"),"utf-8"),s=JSON.parse(n.replace(h,"")),e=s.compilerOptions?.paths,o=s.compilerOptions?.baseUrl??".";if(!e&&s.extends)try{let i=a(t,s.extends),l=await p(i,"utf-8"),u=JSON.parse(l.replace(h,""));e=u.compilerOptions?.paths,o=u.compilerOptions?.baseUrl??o}catch{}return e?{root:a(t,o),entries:Object.entries(e)}:r}catch{return r}}function R(t,r){for(let[n,s]of r.entries)if(n.endsWith("/*")){let e=n.slice(0,-1);if(t.startsWith(e)){let o=t.slice(e.length),i=s[0],l=i.endsWith("/*")?i.slice(0,-1):i;return a(r.root,l,o)}}else if(n===t&&s.length>0)return a(r.root,s[0]);return null}var T=[".tsx",".ts",".jsx",".js","/index.tsx","/index.ts"];async function y(t){for(let r of["",...T])try{if((await P(t+r)).isFile())return!0}catch{}return!1}async function E(t,r,n){try{let s=a(r,t),e=await p(s,"utf-8"),o=[],i=/from\s+['"]([^'"]+)['"]/g,l;for(;(l=i.exec(e))!==null;){let c=l[1];if(c.startsWith("."))o.push(y(v(w(s),c)));else{let d=R(c,n);d&&o.push(y(d))}}return(await Promise.all(o)).every(Boolean)}catch{return!1}}async function O(t,r){let n=await k(r);return(await Promise.all(t.components.map(async e=>await E(e.filePath,r,n)?{key:`${e.filePath}::${e.name}`,slug:g(e.filePath,e.name),filePath:e.filePath,exportName:e.name,exportType:e.exportType}:(console.warn(`[Popmelt] Skipping ${e.filePath}::${e.name} \u2014 unresolvable imports`),null)))).filter(e=>e!==null)}var C=12;function A(t){let r=t.map(n=>n.key).sort().join(`
|
|
2
|
+
`);return x("sha256").update(C+`
|
|
3
|
+
`+r).digest("hex").slice(0,16)}async function $(t){for(let r of["app","src/app"]){let n=a(t,r);try{if((await P(n)).isDirectory())return n}catch{}}return null}function N(t){return t.split("\\").join("/")}function M(t,r,n){let s=a(n,t.filePath.replace(/\.(tsx?|jsx?)$/,"")),e=JSON.stringify(N(b(r,s)));return t.exportType==="default"?`'use client';
|
|
4
|
+
import dynamic from 'next/dynamic';
|
|
5
|
+
export default dynamic(() => import(${e}), { ssr: false });
|
|
6
|
+
`:`'use client';
|
|
7
|
+
import dynamic from 'next/dynamic';
|
|
8
|
+
export default dynamic(
|
|
9
|
+
() => import(${e}).then(mod => ({ default: mod.${t.exportName} })),
|
|
10
|
+
{ ssr: false },
|
|
11
|
+
);
|
|
12
|
+
`}var W=`// Auto-generated by Popmelt scanner \u2014 do not edit
|
|
13
|
+
'use client';
|
|
14
|
+
|
|
15
|
+
import { useEffect, type ReactNode } from 'react';
|
|
16
|
+
|
|
17
|
+
export default function PopmeltRenderLayout({ children }: { children: ReactNode }) {
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
const origPush = history.pushState.bind(history);
|
|
20
|
+
const origReplace = history.replaceState.bind(history);
|
|
21
|
+
|
|
22
|
+
history.pushState = function (...args: Parameters<typeof history.pushState>) {
|
|
23
|
+
const url = args[2];
|
|
24
|
+
if (url && String(url).indexOf('/popmelt/render') !== 0) {
|
|
25
|
+
console.warn('[Popmelt] Blocked navigation to:', url);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
return origPush(...args);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
history.replaceState = function (...args: Parameters<typeof history.replaceState>) {
|
|
32
|
+
const url = args[2];
|
|
33
|
+
if (url && String(url).indexOf('/popmelt/render') !== 0) {
|
|
34
|
+
console.warn('[Popmelt] Blocked navigation to:', url);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
return origReplace(...args);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const handleClick = (e: MouseEvent) => {
|
|
41
|
+
const anchor = (e.target as Element).closest?.('a');
|
|
42
|
+
if (!anchor) return;
|
|
43
|
+
const href = anchor.getAttribute('href');
|
|
44
|
+
if (href && !href.startsWith('/popmelt/render') && !href.startsWith('#')) {
|
|
45
|
+
e.preventDefault();
|
|
46
|
+
e.stopPropagation();
|
|
47
|
+
console.warn('[Popmelt] Blocked link navigation to:', href);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
document.addEventListener('click', handleClick, true);
|
|
52
|
+
|
|
53
|
+
return () => {
|
|
54
|
+
history.pushState = origPush;
|
|
55
|
+
history.replaceState = origReplace;
|
|
56
|
+
document.removeEventListener('click', handleClick, true);
|
|
57
|
+
};
|
|
58
|
+
}, []);
|
|
59
|
+
|
|
60
|
+
return children;
|
|
61
|
+
}
|
|
62
|
+
`,B=`// Auto-generated by Popmelt scanner \u2014 do not edit
|
|
63
|
+
'use client';
|
|
64
|
+
|
|
65
|
+
export default function PopmeltRenderError({
|
|
66
|
+
error,
|
|
67
|
+
reset,
|
|
68
|
+
}: {
|
|
69
|
+
error: Error & { digest?: string };
|
|
70
|
+
reset: () => void;
|
|
71
|
+
}) {
|
|
72
|
+
return (
|
|
73
|
+
<div style={{ padding: 40, fontFamily: 'system-ui' }}>
|
|
74
|
+
<h2 style={{ color: '#ef4444', fontSize: 16, fontWeight: 600, margin: 0 }}>
|
|
75
|
+
Component render error
|
|
76
|
+
</h2>
|
|
77
|
+
<pre style={{
|
|
78
|
+
marginTop: 12,
|
|
79
|
+
padding: 12,
|
|
80
|
+
background: '#fef2f2',
|
|
81
|
+
border: '1px solid #fecaca',
|
|
82
|
+
fontSize: 12,
|
|
83
|
+
color: '#991b1b',
|
|
84
|
+
whiteSpace: 'pre-wrap',
|
|
85
|
+
wordBreak: 'break-word',
|
|
86
|
+
}}>
|
|
87
|
+
{error.message}
|
|
88
|
+
</pre>
|
|
89
|
+
<button
|
|
90
|
+
onClick={reset}
|
|
91
|
+
style={{
|
|
92
|
+
marginTop: 12,
|
|
93
|
+
padding: '6px 16px',
|
|
94
|
+
fontSize: 12,
|
|
95
|
+
background: '#1f2937',
|
|
96
|
+
color: '#fff',
|
|
97
|
+
border: 'none',
|
|
98
|
+
cursor: 'pointer',
|
|
99
|
+
}}
|
|
100
|
+
>
|
|
101
|
+
Retry
|
|
102
|
+
</button>
|
|
103
|
+
</div>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
`;async function z(t,r,n){let s=await O(t,r);if(s.length===0)return n??"";let e=A(s);if(e===n)return e;let o=await $(r);if(!o)return n??"";let i=a(o,"popmelt","render");await S(i,{recursive:!0,force:!0}),await m(i,{recursive:!0});let l=[f(a(i,"layout.tsx"),W),f(a(i,"error.tsx"),B)];for(let u of s){let c=a(i,u.slug);l.push(m(c,{recursive:!0}).then(()=>f(a(c,"page.tsx"),M(u,c,r))))}return await Promise.all(l),e}export{z as generateRenderFiles};
|