@popmelt.com/core 0.5.5 → 0.5.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/canvas.mjs +1 -0
- package/dist/chunk-3HWT3PC2.mjs +1 -0
- package/dist/chunk-4LDJX6BW.mjs +2 -0
- package/dist/chunk-HGGX55FR.mjs +1 -0
- package/dist/cli.mjs +65 -38
- package/dist/index.mjs +15 -15
- package/dist/plugin-astro.d.mts +10 -0
- package/dist/plugin-astro.mjs +1 -0
- package/dist/plugin-next.mjs +1 -0
- package/dist/plugin-vite.d.mts +10 -0
- package/dist/plugin-vite.mjs +1 -0
- package/dist/react-scanner-5NIJ6ZPL.mjs +1 -0
- package/dist/react-scanner-MSMGKCIV.mjs +2 -0
- package/dist/render-generator-QV5BYGPF.mjs +107 -0
- package/dist/render-generator-ZNV3RDU7.mjs +106 -0
- package/dist/server.d.mts +1 -0
- package/dist/server.mjs +64 -37
- package/package.json +22 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as c,b as g}from"./chunk-HGGX55FR.mjs";import{request as y}from"http";function P(t){var o,h;let n=(o=t==null?void 0:t.port)!=null?o:1111,s=(h=t==null?void 0:t.basePath)!=null?h:"/popmelt",l=`http://localhost:${n}`;return{name:"popmelt-canvas",hooks:{"astro:server:setup"({server:m}){m.middlewares.use((e,r,u)=>{let d=e.url||"";if(!d.startsWith(s))return u();let b="/canvas"+d.slice(s.length),i=new URL(b,l),p=y(i,{method:e.method,headers:g(c({},e.headers),{host:i.host})},a=>{r.writeHead(a.statusCode||502,a.headers),a.pipe(r)});p.on("error",()=>{r.writeHead(502,{"Content-Type":"text/plain"}),r.end(`Popmelt bridge not running on port ${n}`)}),e.pipe(p)})}}}}export{P as popmelt};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var m=Object.defineProperty,d=Object.defineProperties;var f=Object.getOwnPropertyDescriptors;var h=Object.getOwnPropertySymbols;var N=Object.prototype.hasOwnProperty,w=Object.prototype.propertyIsEnumerable;var u=(t,e,r)=>e in t?m(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,i=(t,e)=>{for(var r in e||(e={}))N.call(e,r)&&u(t,r,e[r]);if(h)for(var r of h(e))w.call(e,r)&&u(t,r,e[r]);return t},c=(t,e)=>d(t,f(e));import{NextResponse as p}from"next/server";var x=1111;function v(t,e){var a,s;let r=(a=e==null?void 0:e.basePath)!=null?a:"/popmelt",l=(s=e==null?void 0:e.port)!=null?s:x;if(t.nextUrl.searchParams.get("popmelt")==="canvas"){if(process.env.NODE_ENV==="production")return null;let n=new Headers(t.headers);return n.set("x-popmelt-canvas","1"),p.next({request:{headers:n}})}if(t.nextUrl.pathname.startsWith(r+"/render")){if(process.env.NODE_ENV==="production")return null;let n=new Headers(t.headers);return n.set("x-popmelt-canvas","1"),p.next({request:{headers:n}})}if(t.nextUrl.pathname===r||t.nextUrl.pathname.startsWith(r+"/")){let n="/canvas"+t.nextUrl.pathname.slice(r.length);return p.rewrite(new URL(n||"/canvas",`http://localhost:${l}`))}return null}function y(t,e){var s;if(process.env.NODE_ENV==="production")return t;let l=`http://localhost:${(s=e==null?void 0:e.port)!=null?s:x}`,a=t.rewrites;return c(i({},t),{async rewrites(){let n=a?await a():[],o=[{source:"/popmelt",destination:`${l}/canvas`},{source:"/popmelt/:path*",destination:`${l}/canvas/:path*`}];return Array.isArray(n)?{beforeFiles:o,afterFiles:n,fallback:[]}:c(i({},n),{beforeFiles:[...n.beforeFiles||[],...o]})}})}export{v as popmeltMiddleware,y as withPopmelt};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as c,b as d}from"./chunk-HGGX55FR.mjs";import{request as b}from"http";function y(e){var h,i;let a=(h=e==null?void 0:e.port)!=null?h:1111,s=(i=e==null?void 0:e.basePath)!=null?i:"/popmelt",g=`http://localhost:${a}`;return{name:"popmelt-canvas",configureServer(m){m.middlewares.use((t,r,p)=>{let l=t.url||"";if(!l.startsWith(s))return p();let P="/canvas"+l.slice(s.length),o=new URL(P,g),u=b(o,{method:t.method,headers:d(c({},t.headers),{host:o.host})},n=>{r.writeHead(n.statusCode||502,n.headers),n.pipe(r)});u.on("error",()=>{r.writeHead(502,{"Content-Type":"text/plain"}),r.end(`Popmelt bridge not running on port ${a}`)}),t.pipe(u)})}}}export{y as popmelt};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./chunk-3HWT3PC2.mjs";import{readdir as d,readFile as A,stat as R}from"fs/promises";import{basename as D,dirname as w,join as m,relative as h}from"path";var E=new Set(["node_modules",".next","dist","__popmelt",".git",".turbo"]),M=[/\.test\.tsx?$/,/\.spec\.tsx?$/,/\.stories\.tsx?$/],y=/^[A-Z][a-zA-Z0-9]+$/,T=[{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 P(e,n){let s=[],r=await d(e,{withFileTypes:!0});for(let t of r)if(t.isDirectory()){if(E.has(t.name))continue;let o=await P(m(e,t.name),n);s.push(...o)}else if(t.isFile()&&t.name.endsWith(".tsx")){let o=m(e,t.name),i=h(n,o);if(M.some(a=>a.test(i)))continue;s.push(o)}return s}function S(e,n,s){let r=h(s,n),t=[],o=new Set;for(let{regex:i,type:a}of T){i.lastIndex=0;let p;for(;(p=i.exec(e))!==null;){let c=p[1];if(o.has(c)||!y.test(c))continue;o.add(c);let f,u=w(r);u!=="."&&(f=u.replace(/^app\//,"").replace(/^src\//,"")),t.push({name:c,filePath:r,exportType:a,category:f})}}return t}async function _(e){var t,o;let n=new Map,s=m(e,"app"),r;try{await R(s),r=await C(s,e)}catch(i){return n}for(let i of r){let a=await A(i,"utf-8"),c="/"+w(h(e,i)).replace(/^app\/?/,"").replace(/\([^)]+\)\/?/g,"").replace(/\/$/,""),f=/import\s+.*?from\s+['"](\.\.?\/[^'"]+)['"]/g,u;for(;(u=f.exec(a))!==null;){let Z=u[1],g=D(Z).replace(/\.(tsx?|jsx?)$/,""),F=u[0].match(/\b([A-Z][a-zA-Z0-9]+)\b/g)||[];for(let l of F){if(!y.test(l))continue;let x=(t=n.get(l))!=null?t:[];x.includes(c)||x.push(c),n.set(l,x)}if(y.test(g)){let l=(o=n.get(g))!=null?o:[];l.includes(c)||l.push(c),n.set(g,l)}}}return n}async function C(e,n){let s=[],r=await d(e,{withFileTypes:!0});for(let t of r)if(t.isDirectory()){if(E.has(t.name))continue;s.push(...await C(m(e,t.name),n))}else t.isFile()&&t.name==="page.tsx"&&s.push(m(e,t.name));return s}async function $(e){let n=await P(e,e),s=await _(e),r=[];for(let t of n){let o=await A(t,"utf-8"),i=S(o,t,e);for(let a of i){let p=s.get(a.name);p&&p.length>0&&(a.routes=p),r.push(a)}}return r.sort((t,o)=>t.name.localeCompare(o.name)),{version:1,scannedAt:Date.now(),components:r}}export{$ as scanForComponents};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import"./chunk-4LDJX6BW.mjs";import{readdir as d,readFile as A,stat as R}from"fs/promises";import{basename as D,dirname as w,join as m,relative as h}from"path";var E=new Set(["node_modules",".next","dist","__popmelt",".git",".turbo"]),M=[/\.test\.tsx?$/,/\.spec\.tsx?$/,/\.stories\.tsx?$/],y=/^[A-Z][a-zA-Z0-9]+$/,T=[{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 P(e,n){let s=[],r=await d(e,{withFileTypes:!0});for(let t of r)if(t.isDirectory()){if(E.has(t.name))continue;let o=await P(m(e,t.name),n);s.push(...o)}else if(t.isFile()&&t.name.endsWith(".tsx")){let o=m(e,t.name),i=h(n,o);if(M.some(a=>a.test(i)))continue;s.push(o)}return s}function S(e,n,s){let r=h(s,n),t=[],o=new Set;for(let{regex:i,type:a}of T){i.lastIndex=0;let p;for(;(p=i.exec(e))!==null;){let c=p[1];if(o.has(c)||!y.test(c))continue;o.add(c);let f,u=w(r);u!=="."&&(f=u.replace(/^app\//,"").replace(/^src\//,"")),t.push({name:c,filePath:r,exportType:a,category:f})}}return t}async function _(e){var t,o;let n=new Map,s=m(e,"app"),r;try{await R(s),r=await C(s,e)}catch(i){return n}for(let i of r){let a=await A(i,"utf-8"),c="/"+w(h(e,i)).replace(/^app\/?/,"").replace(/\([^)]+\)\/?/g,"").replace(/\/$/,""),f=/import\s+.*?from\s+['"](\.\.?\/[^'"]+)['"]/g,u;for(;(u=f.exec(a))!==null;){let Z=u[1],g=D(Z).replace(/\.(tsx?|jsx?)$/,""),F=u[0].match(/\b([A-Z][a-zA-Z0-9]+)\b/g)||[];for(let l of F){if(!y.test(l))continue;let x=(t=n.get(l))!=null?t:[];x.includes(c)||x.push(c),n.set(l,x)}if(y.test(g)){let l=(o=n.get(g))!=null?o:[];l.includes(c)||l.push(c),n.set(g,l)}}}return n}async function C(e,n){let s=[],r=await d(e,{withFileTypes:!0});for(let t of r)if(t.isDirectory()){if(E.has(t.name))continue;s.push(...await C(m(e,t.name),n))}else t.isFile()&&t.name==="page.tsx"&&s.push(m(e,t.name));return s}async function $(e){let n=await P(e,e),s=await _(e),r=[];for(let t of n){let o=await A(t,"utf-8"),i=S(o,t,e);for(let a of i){let p=s.get(a.name);p&&p.length>0&&(a.routes=p),r.push(a)}}return r.sort((t,o)=>t.name.localeCompare(o.name)),{version:1,scannedAt:Date.now(),components:r}}export{$ as scanForComponents};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import"./chunk-4LDJX6BW.mjs";import{createHash as v}from"crypto";import{mkdir as P,readFile as g,rm as k,stat as w,writeFile as d}from"fs/promises";import{dirname as R,join as i,relative as T,resolve as E}from"path";function y(r,n){let t=`${r}::${n}`,o=5381;for(let e=0;e<t.length;e++)o=(o<<5)+o+t.charCodeAt(e)&4294967295;return(o>>>0).toString(16).padStart(8,"0")}var x=/\/\/.*$|\/\*[\s\S]*?\*\//gm;async function O(r){var t,o,e,a,s,l;let n={root:r,entries:[]};try{let f=await g(i(r,"tsconfig.json"),"utf-8"),c=JSON.parse(f.replace(x,"")),u=(t=c.compilerOptions)==null?void 0:t.paths,p=(e=(o=c.compilerOptions)==null?void 0:o.baseUrl)!=null?e:".";if(!u&&c.extends)try{let m=i(r,c.extends),b=await g(m,"utf-8"),h=JSON.parse(b.replace(x,""));u=(a=h.compilerOptions)==null?void 0:a.paths,p=(l=(s=h.compilerOptions)==null?void 0:s.baseUrl)!=null?l:p}catch(m){}return u?{root:i(r,p),entries:Object.entries(u)}:n}catch(f){return n}}function C(r,n){for(let[t,o]of n.entries)if(t.endsWith("/*")){let e=t.slice(0,-1);if(r.startsWith(e)){let a=r.slice(e.length),s=o[0],l=s.endsWith("/*")?s.slice(0,-1):s;return i(n.root,l,a)}}else if(t===r&&o.length>0)return i(n.root,o[0]);return null}var A=[".tsx",".ts",".jsx",".js","/index.tsx","/index.ts"];async function S(r){for(let n of["",...A])try{if((await w(r+n)).isFile())return!0}catch(t){}return!1}async function $(r,n,t){try{let o=i(n,r),e=await g(o,"utf-8"),a=[],s=/from\s+['"]([^'"]+)['"]/g,l;for(;(l=s.exec(e))!==null;){let c=l[1];if(c.startsWith("."))a.push(S(E(R(o),c)));else{let u=C(c,t);u&&a.push(S(u))}}return(await Promise.all(a)).every(Boolean)}catch(o){return!1}}async function N(r,n){let t=await O(n);return(await Promise.all(r.components.map(async e=>await $(e.filePath,n,t)?{key:`${e.filePath}::${e.name}`,slug:y(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 M=12;function W(r){let n=r.map(t=>t.key).sort().join(`
|
|
3
|
+
`);return v("sha256").update(M+`
|
|
4
|
+
`+n).digest("hex").slice(0,16)}async function B(r){for(let n of["app","src/app"]){let t=i(r,n);try{if((await w(t)).isDirectory())return t}catch(o){}}return null}function D(r){return r.split("\\").join("/")}function L(r,n,t){let o=i(t,r.filePath.replace(/\.(tsx?|jsx?)$/,"")),e=JSON.stringify(D(T(n,o)));return r.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.${r.exportName} })),
|
|
11
|
+
{ ssr: false },
|
|
12
|
+
);
|
|
13
|
+
`}var U=`// 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
|
+
`,F=`// 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 V(r,n,t){let o=await N(r,n);if(o.length===0)return t!=null?t:"";let e=W(o);if(e===t)return e;let a=await B(n);if(!a)return t!=null?t:"";let s=i(a,"popmelt","render");await k(s,{recursive:!0,force:!0}),await P(s,{recursive:!0});let l=[d(i(s,"layout.tsx"),U),d(i(s,"error.tsx"),F)];for(let f of o){let c=i(s,f.slug);l.push(P(c,{recursive:!0}).then(()=>d(i(c,"page.tsx"),L(f,c,n))))}return await Promise.all(l),e}export{V as generateRenderFiles};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import"./chunk-3HWT3PC2.mjs";import{createHash as v}from"crypto";import{mkdir as P,readFile as g,rm as k,stat as w,writeFile as d}from"fs/promises";import{dirname as R,join as i,relative as T,resolve as E}from"path";function y(r,n){let t=`${r}::${n}`,o=5381;for(let e=0;e<t.length;e++)o=(o<<5)+o+t.charCodeAt(e)&4294967295;return(o>>>0).toString(16).padStart(8,"0")}var x=/\/\/.*$|\/\*[\s\S]*?\*\//gm;async function O(r){var t,o,e,a,s,l;let n={root:r,entries:[]};try{let f=await g(i(r,"tsconfig.json"),"utf-8"),c=JSON.parse(f.replace(x,"")),u=(t=c.compilerOptions)==null?void 0:t.paths,p=(e=(o=c.compilerOptions)==null?void 0:o.baseUrl)!=null?e:".";if(!u&&c.extends)try{let m=i(r,c.extends),b=await g(m,"utf-8"),h=JSON.parse(b.replace(x,""));u=(a=h.compilerOptions)==null?void 0:a.paths,p=(l=(s=h.compilerOptions)==null?void 0:s.baseUrl)!=null?l:p}catch(m){}return u?{root:i(r,p),entries:Object.entries(u)}:n}catch(f){return n}}function C(r,n){for(let[t,o]of n.entries)if(t.endsWith("/*")){let e=t.slice(0,-1);if(r.startsWith(e)){let a=r.slice(e.length),s=o[0],l=s.endsWith("/*")?s.slice(0,-1):s;return i(n.root,l,a)}}else if(t===r&&o.length>0)return i(n.root,o[0]);return null}var A=[".tsx",".ts",".jsx",".js","/index.tsx","/index.ts"];async function S(r){for(let n of["",...A])try{if((await w(r+n)).isFile())return!0}catch(t){}return!1}async function $(r,n,t){try{let o=i(n,r),e=await g(o,"utf-8"),a=[],s=/from\s+['"]([^'"]+)['"]/g,l;for(;(l=s.exec(e))!==null;){let c=l[1];if(c.startsWith("."))a.push(S(E(R(o),c)));else{let u=C(c,t);u&&a.push(S(u))}}return(await Promise.all(a)).every(Boolean)}catch(o){return!1}}async function N(r,n){let t=await O(n);return(await Promise.all(r.components.map(async e=>await $(e.filePath,n,t)?{key:`${e.filePath}::${e.name}`,slug:y(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 M=12;function W(r){let n=r.map(t=>t.key).sort().join(`
|
|
2
|
+
`);return v("sha256").update(M+`
|
|
3
|
+
`+n).digest("hex").slice(0,16)}async function B(r){for(let n of["app","src/app"]){let t=i(r,n);try{if((await w(t)).isDirectory())return t}catch(o){}}return null}function D(r){return r.split("\\").join("/")}function L(r,n,t){let o=i(t,r.filePath.replace(/\.(tsx?|jsx?)$/,"")),e=JSON.stringify(D(T(n,o)));return r.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.${r.exportName} })),
|
|
10
|
+
{ ssr: false },
|
|
11
|
+
);
|
|
12
|
+
`}var U=`// 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
|
+
`,F=`// 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 V(r,n,t){let o=await N(r,n);if(o.length===0)return t!=null?t:"";let e=W(o);if(e===t)return e;let a=await B(n);if(!a)return t!=null?t:"";let s=i(a,"popmelt","render");await k(s,{recursive:!0,force:!0}),await P(s,{recursive:!0});let l=[d(i(s,"layout.tsx"),U),d(i(s,"error.tsx"),F)];for(let f of o){let c=i(s,f.slug);l.push(P(c,{recursive:!0}).then(()=>d(i(c,"page.tsx"),L(f,c,n))))}return await Promise.all(l),e}export{V as generateRenderFiles};
|