@mateosuarezdev/flash 0.0.12 → 0.0.16

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.
@@ -8,4 +8,4 @@
8
8
  * See LICENSE file for full terms.
9
9
  */
10
10
 
11
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./jsx-dev-runtime-C5Q23IsT.cjs");exports.Fragment=e.Fragment;exports.jsx=e.jsx;exports.jsxDEV=e.jsx;exports.jsxs=e.jsx;
11
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./jsx-runtime.cjs");exports.Fragment=e.Fragment;exports.jsx=e.jsx;exports.jsxDEV=e.jsx;exports.jsxs=e.jsx;
@@ -8,10 +8,10 @@
8
8
  * See LICENSE file for full terms.
9
9
  */
10
10
 
11
- import { F as a, j as x, j as r, j as e } from "./jsx-dev-runtime-dAReTOgq.js";
11
+ import { Fragment as j, jsx as a, jsx as r, jsx as e } from "./jsx-runtime.js";
12
12
  export {
13
- a as Fragment,
14
- x as jsx,
13
+ j as Fragment,
14
+ a as jsx,
15
15
  r as jsxDEV,
16
16
  e as jsxs
17
17
  };
@@ -8,4 +8,4 @@
8
8
  * See LICENSE file for full terms.
9
9
  */
10
10
 
11
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./jsx-dev-runtime-C5Q23IsT.cjs");exports.Fragment=e.Fragment;exports.jsx=e.jsx;exports.jsxDEV=e.jsx;exports.jsxs=e.jsx;
11
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./vnode-tracking-DC68rWms.cjs");function i(n,e,t){return{type:n,kind:"VNode",props:e,key:t,children:e.children,_id:o.newVNodeId(),_onMountCallbacks:[],_onUnmountCallbacks:[],_onBeforeExitCallbacks:[],_element:null,_parent:null,_renderedChildren:[],_lifecycleState:"mounting"}}function c(n,e,t){return{type:n,kind:"IntrinsicVNode",props:e,key:t,_id:o.newVNodeId(),_dom:void 0,_parent:null,_renderedChildren:[],_onMountCallbacks:[],_onUnmountCallbacks:[],_onBeforeExitCallbacks:[],_lifecycleState:"mounting"}}const l=Symbol.for("jsx.fragment");function r(n,e,t){return n===l?e?.children:typeof n=="function"?i(n,e??{},t):c(n,e??{},t)}exports.Fragment=l;exports.jsx=r;exports.jsxDEV=r;exports.jsxs=r;
@@ -8,10 +8,48 @@
8
8
  * See LICENSE file for full terms.
9
9
  */
10
10
 
11
- import { F as a, j as x, j as r, j as e } from "./jsx-dev-runtime-dAReTOgq.js";
11
+ import { n as r } from "./vnode-tracking-BAFaVke9.js";
12
+ function l(n, e, t) {
13
+ return {
14
+ type: n,
15
+ kind: "VNode",
16
+ props: e,
17
+ key: t,
18
+ children: e.children,
19
+ _id: r(),
20
+ _onMountCallbacks: [],
21
+ _onUnmountCallbacks: [],
22
+ _onBeforeExitCallbacks: [],
23
+ _element: null,
24
+ _parent: null,
25
+ _renderedChildren: [],
26
+ _lifecycleState: "mounting"
27
+ };
28
+ }
29
+ function o(n, e, t) {
30
+ return {
31
+ type: n,
32
+ kind: "IntrinsicVNode",
33
+ props: e,
34
+ key: t,
35
+ _id: r(),
36
+ _dom: void 0,
37
+ // DOM created lazily during render
38
+ _parent: null,
39
+ _renderedChildren: [],
40
+ _onMountCallbacks: [],
41
+ _onUnmountCallbacks: [],
42
+ _onBeforeExitCallbacks: [],
43
+ _lifecycleState: "mounting"
44
+ };
45
+ }
46
+ const i = Symbol.for("jsx.fragment");
47
+ function c(n, e, t) {
48
+ return n === i ? e?.children : typeof n == "function" ? l(n, e ?? {}, t) : o(n, e ?? {}, t);
49
+ }
12
50
  export {
13
- a as Fragment,
14
- x as jsx,
15
- r as jsxDEV,
16
- e as jsxs
51
+ i as Fragment,
52
+ c as jsx,
53
+ c as jsxDEV,
54
+ c as jsxs
17
55
  };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @license
3
+ * Flash
4
+ * Copyright (c) 2025 Mateo Suarez. All rights reserved.
5
+ *
6
+ * Free to use in your own personal or commercial applications and projects.
7
+ * Unauthorized copying, modification, or distribution is strictly prohibited.
8
+ * See LICENSE file for full terms.
9
+ */
10
+
11
+ "use strict";const n=new Map;let d=0,r=null;function c(){const e=d++;return n.set(e,null),r=e,e}function l(e){n.delete(e),r===e&&(r=null)}function o(){return r===null?null:n.get(r)??null}function i(e){if(r===null)throw new Error("No active render context");n.set(r,e)}function a(){if(r===null)throw new Error("createServerVNode called outside of render context");return{_parent:o(),_renderId:r}}function s(e,u){const t=o();if(!t)throw new Error("provideServerContext called outside of component render");t._contextMap||(t._contextMap=new Map),t._contextMap.set(e,u)}function x(e,u){let t=o();for(;t;){if(t._contextMap?.has(e))return t._contextMap.get(e);t=t._parent}return u}exports.consumeServerContext=x;exports.createServerVNode=a;exports.endRenderContext=l;exports.getCurrentServerVNode=o;exports.provideServerContext=s;exports.setCurrentServerVNode=i;exports.startRenderContext=c;
@@ -0,0 +1,59 @@
1
+ /**
2
+ * @license
3
+ * Flash
4
+ * Copyright (c) 2025 Mateo Suarez. All rights reserved.
5
+ *
6
+ * Free to use in your own personal or commercial applications and projects.
7
+ * Unauthorized copying, modification, or distribution is strictly prohibited.
8
+ * See LICENSE file for full terms.
9
+ */
10
+
11
+ const r = /* @__PURE__ */ new Map();
12
+ let u = 0, n = null;
13
+ function a() {
14
+ const e = u++;
15
+ return r.set(e, null), n = e, e;
16
+ }
17
+ function l(e) {
18
+ r.delete(e), n === e && (n = null);
19
+ }
20
+ function c() {
21
+ return n === null ? null : r.get(n) ?? null;
22
+ }
23
+ function d(e) {
24
+ if (n === null)
25
+ throw new Error("No active render context");
26
+ r.set(n, e);
27
+ }
28
+ function s() {
29
+ if (n === null)
30
+ throw new Error("createServerVNode called outside of render context");
31
+ return {
32
+ _parent: c(),
33
+ _renderId: n
34
+ };
35
+ }
36
+ function i(e, o) {
37
+ const t = c();
38
+ if (!t)
39
+ throw new Error("provideServerContext called outside of component render");
40
+ t._contextMap || (t._contextMap = /* @__PURE__ */ new Map()), t._contextMap.set(e, o);
41
+ }
42
+ function f(e, o) {
43
+ let t = c();
44
+ for (; t; ) {
45
+ if (t._contextMap?.has(e))
46
+ return t._contextMap.get(e);
47
+ t = t._parent;
48
+ }
49
+ return o;
50
+ }
51
+ export {
52
+ d as a,
53
+ s as b,
54
+ f as c,
55
+ l as e,
56
+ c as g,
57
+ i as p,
58
+ a as s
59
+ };
package/dist/server.cjs CHANGED
@@ -8,20 +8,20 @@
8
8
  * See LICENSE file for full terms.
9
9
  */
10
10
 
11
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("./server-context-TAJ6UxWy.cjs"),$=require("node:fs/promises"),g=require("node:path");function N(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function b(t){return t.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}const C=new Set(["area","base","br","col","embed","hr","img","input","link","meta","source","track","wbr"]);function H(t){return/^on[A-Z]/.test(t)}function j(t){return Object.entries(t).map(([r,o])=>`${r.replace(/[A-Z]/g,n=>`-${n.toLowerCase()}`)}:${o}`).join(";")}function E(t,r=!0){const o=Object.entries(t).filter(([e,n])=>!(n==null||r&&e==="children"||e==="innerHTML"||H(e))).map(([e,n])=>(e==="className"&&(e="class"),e==="style"&&typeof n=="object"&&(n=j(n)),typeof n=="boolean"?n?e:"":`${e}="${b(String(n))}"`)).filter(Boolean).join(" ");return o?` ${o}`:""}function v(t){return t?Array.isArray(t)?t:[t]:[]}function T(t){return t&&typeof t.then=="function"}function S(t,r){return`<div id="${t}" data-server-component="suspended" data-component-name="${r}">Loading...</div>`}const d=new Map;let y=0;function w(t){return d.clear(),y=0,u.resetServerContext(),c(t)}async function D(t){d.clear(),y=0,u.resetServerContext();let r=c(t);for(;d.size>0;){console.log(`🔄 Resolving ${d.size} async components in parallel...`);const o=Array.from(d.entries());d.clear();const e=await Promise.allSettled(o.map(([n,{promise:a}])=>a));for(let n=0;n<o.length;n++){const a=o[n];if(!a)continue;const[l,{componentName:s,errorFallback:i,parentNode:f}]=a,m=e[n];if(!m)continue;const h=S(l,s);if(m.status==="fulfilled")try{console.log(`✅ Resolved: ${s} (${l})`),u.setCurrentServerVNode(f);const p=c(m.value);r=r.replace(h,p)}catch(p){console.error(`❌ Error rendering ${s}:`,p),u.setCurrentServerVNode(f);const A=i?c(typeof i=="function"?i(p):i):`<div class="error">Error rendering ${s}</div>`;r=r.replace(h,A)}else{console.error(`❌ Error resolving ${s}:`,m.reason),u.setCurrentServerVNode(f);const p=i?c(typeof i=="function"?i(m.reason):i):`<div class="error">Error loading ${s}</div>`;r=r.replace(h,p)}}}return console.log("✅ All async components resolved!"),r}async function*x(t){for(d.clear(),y=0,u.resetServerContext(),yield c(t);d.size>0;){const o=Array.from(d.entries());d.clear();const e=o.map(async([n,{promise:a,parentNode:l}])=>{try{const s=await a;u.setCurrentServerVNode(l);const i=c(s);return`<script>
11
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./server-context-C7Uxb3AS.cjs"),S=require("node:fs/promises"),g=require("node:path");function N(r){return r.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function b(r){return r.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}const H=new Set(["area","base","br","col","embed","hr","img","input","link","meta","source","track","wbr"]);function j(r){return/^on[A-Z]/.test(r)}function E(r){return Object.entries(r).map(([t,n])=>`${t.replace(/[A-Z]/g,o=>`-${o.toLowerCase()}`)}:${n}`).join(";")}function T(r,t=!0){const n=Object.entries(r).filter(([e,o])=>!(o==null||t&&e==="children"||e==="innerHTML"||j(e))).map(([e,o])=>(e==="className"&&(e="class"),e==="style"&&typeof o=="object"&&(o=E(o)),typeof o=="boolean"?o?e:"":`${e}="${b(String(o))}"`)).filter(Boolean).join(" ");return n?` ${n}`:""}function A(r){return r?Array.isArray(r)?r:[r]:[]}function w(r){return r&&typeof r.then=="function"}function v(r,t){return`<div id="${r}" data-server-component="suspended" data-component-name="${t}">Loading...</div>`}const p=new Map;let y=0;function D(r){p.clear(),y=0;const t=l.startRenderContext();try{return a(r)}finally{l.endRenderContext(t)}}async function x(r){p.clear(),y=0;const t=l.startRenderContext();try{let n=a(r);for(;p.size>0;){console.log(`🔄 Resolving ${p.size} async components in parallel...`);const e=Array.from(p.entries());p.clear();const o=await Promise.allSettled(e.map(([s,{promise:i}])=>i));for(let s=0;s<e.length;s++){const i=e[s];if(!i)continue;const[u,{componentName:c,errorFallback:d,parentNode:h}]=i,m=o[s];if(!m)continue;const $=v(u,c);if(m.status==="fulfilled")try{console.log(`✅ Resolved: ${c} (${u})`),l.setCurrentServerVNode(h);const f=a(m.value);n=n.replace($,f)}catch(f){console.error(`❌ Error rendering ${c}:`,f),l.setCurrentServerVNode(h);const C=d?a(typeof d=="function"?d(f):d):`<div class="error">Error rendering ${c}</div>`;n=n.replace($,C)}else{console.error(`❌ Error resolving ${c}:`,m.reason),l.setCurrentServerVNode(h);const f=d?a(typeof d=="function"?d(m.reason):d):`<div class="error">Error loading ${c}</div>`;n=n.replace($,f)}}}return console.log("✅ All async components resolved!"),n}finally{l.endRenderContext(t)}}async function*P(r){p.clear(),y=0;const t=l.startRenderContext();try{for(yield a(r);p.size>0;){const e=Array.from(p.entries());p.clear();const o=e.map(async([s,{promise:i,parentNode:u}])=>{try{const c=await i;l.setCurrentServerVNode(u);const d=a(c);return`<script>
12
12
  (function() {
13
- const el = document.getElementById('${n}');
13
+ const el = document.getElementById('${s}');
14
14
  if (el) {
15
- el.outerHTML = \`${i.replace(/`/g,"\\`").replace(/\$/g,"\\$")}\`;
15
+ el.outerHTML = \`${d.replace(/`/g,"\\`").replace(/\$/g,"\\$")}\`;
16
16
  }
17
17
  })();
18
18
  <\/script>`}catch{return`<script>
19
19
  (function() {
20
- const el = document.getElementById('${n}');
20
+ const el = document.getElementById('${s}');
21
21
  if (el) {
22
22
  el.innerHTML = '<div class="error">Error loading component</div>';
23
23
  }
24
24
  })();
25
- <\/script>`}});for(const n of e)yield await n}}function c(t){if(typeof t=="function"){const e=t();return Array.isArray(e)?`<!--reactive-list-->${e.map(a=>c(a)).join("")}`:c(e)}if(typeof t=="string")return N(t);if(typeof t=="number")return String(t);if(Array.isArray(t))return t.map(e=>c(e)).join("");if(!t||typeof t!="object")return"";const{type:r,props:o}=t;if(r===Symbol.for("jsx.fragment"))return v(o.children).map(n=>c(n)).join("");if(typeof r=="string"&&r==="suspended"){const e=t,n=`async-${y++}`;return console.log(`⏳ Suspending: ${e._componentName} (${n})`),d.set(n,{id:n,promise:e.promise,componentName:e._componentName,errorFallback:e.errorFallback,parentNode:u.getCurrentServerVNode()}),S(n,e._componentName)}if(typeof r=="function"){const e=u.createServerVNode(),n=u.getCurrentServerVNode();u.setCurrentServerVNode(e);const a=r(o);if(T(a)){const s=`async-${y++}`,i=r.name||"AsyncComponent";return console.warn(`⚠️ DEPRECATED: Direct async component "${i}" detected. Please use suspend() HOF instead for better type safety and custom fallbacks.
26
- Example: const ${i} = suspend(async (props) => { ... }, <Loading />, <Error />);`),console.log(`⏳ Suspending: ${i} (${s})`),d.set(s,{id:s,promise:a,componentName:i,parentNode:e}),u.setCurrentServerVNode(n),S(s,i)}const l=c(a);return u.setCurrentServerVNode(n),l}if(typeof r=="string"){const e=E(o);if(C.has(r))return`<${r}${e} />`;if(o.innerHTML!==void 0){const l=typeof o.innerHTML=="object"?JSON.stringify(o.innerHTML):o.innerHTML;return`<${r}${e}>${l}</${r}>`}const a=v(o.children).map(l=>{if(Array.isArray(l))return l.map(s=>c(s)).join("");if(typeof l=="function"){const s=l();return Array.isArray(s)?`<!--reactive-list-->${s.map(f=>c(f)).join("")}`:`<!--reactive-->${c(s)}`}return c(l)}).join("");return r==="html"?`<!DOCTYPE html>
27
- <html${e}>${a}</html>`:`<${r}${e}>${a}</${r}>`}return""}class P{cacheDir;useDirectoryStructure;constructor(r={}){this.cacheDir=r.cacheDir||"./cache/html",this.useDirectoryStructure=r.useDirectoryStructure??!1}async save(r,o){const e=this.getFilepath(r);return await $.mkdir(g.dirname(e),{recursive:!0}),await Bun.write(e,o),console.log(`✅ Pre-rendered: ${r} → ${e}`),e}async load(r){const o=this.getFilepath(r),e=Bun.file(o);return await e.exists()?e:null}async clear(){await $.rm(this.cacheDir,{recursive:!0,force:!0}),await $.mkdir(this.cacheDir,{recursive:!0}),console.log("🗑️ Cache cleared")}async exists(r){const o=this.getFilepath(r);return await Bun.file(o).exists()}getFilepath(r){const o=r.replace(/^\/+|\/+$/g,"");if(this.useDirectoryStructure)return o===""?g.join(this.cacheDir,"index.html"):g.join(this.cacheDir,o,"index.html");{const e=o===""?"index.html":`${o.replace(/\//g,"-")}.html`;return g.join(this.cacheDir,e)}}}exports.PreRenderer=P;exports.renderToStream=x;exports.renderToString=w;exports.renderToStringAsync=D;
25
+ <\/script>`}});for(const s of o)yield await s}}finally{l.endRenderContext(t)}}function a(r){if(typeof r=="function"){const e=r();return Array.isArray(e)?`<!--reactive-list-->${e.map(s=>a(s)).join("")}`:a(e)}if(typeof r=="string")return N(r);if(typeof r=="number")return String(r);if(Array.isArray(r))return r.map(e=>a(e)).join("");if(!r||typeof r!="object")return"";const{type:t,props:n}=r;if(t===Symbol.for("jsx.fragment"))return A(n.children).map(o=>a(o)).join("");if(typeof t=="string"&&t==="suspended"){const e=r,o=`async-${y++}`;return console.log(`⏳ Suspending: ${e._componentName} (${o})`),p.set(o,{id:o,promise:e.promise,componentName:e._componentName,errorFallback:e.errorFallback,parentNode:l.getCurrentServerVNode()}),v(o,e._componentName)}if(typeof t=="function"){const e=l.createServerVNode(),o=l.getCurrentServerVNode();l.setCurrentServerVNode(e);const s=t(n);if(w(s)){const u=`async-${y++}`,c=t.name||"AsyncComponent";return console.warn(`⚠️ DEPRECATED: Direct async component "${c}" detected. Please use suspend() HOF instead for better type safety and custom fallbacks.
26
+ Example: const ${c} = suspend(async (props) => { ... }, <Loading />, <Error />);`),console.log(`⏳ Suspending: ${c} (${u})`),p.set(u,{id:u,promise:s,componentName:c,parentNode:e}),l.setCurrentServerVNode(o),v(u,c)}const i=a(s);return l.setCurrentServerVNode(o),i}if(typeof t=="string"){const e=T(n);if(H.has(t))return`<${t}${e} />`;if(n.innerHTML!==void 0){const i=typeof n.innerHTML=="object"?JSON.stringify(n.innerHTML):n.innerHTML;return`<${t}${e}>${i}</${t}>`}const s=A(n.children).map(i=>{if(Array.isArray(i))return i.map(u=>a(u)).join("");if(typeof i=="function"){const u=i();return Array.isArray(u)?`<!--reactive-list-->${u.map(d=>a(d)).join("")}`:`<!--reactive-->${a(u)}`}return a(i)}).join("");return t==="html"?`<!DOCTYPE html>
27
+ <html${e}>${s}</html>`:`<${t}${e}>${s}</${t}>`}return""}class V{cacheDir;useDirectoryStructure;constructor(t={}){this.cacheDir=t.cacheDir||"./cache/html",this.useDirectoryStructure=t.useDirectoryStructure??!1}async save(t,n){const e=this.getFilepath(t);return await S.mkdir(g.dirname(e),{recursive:!0}),await Bun.write(e,n),console.log(`✅ Pre-rendered: ${t} → ${e}`),e}async load(t){const n=this.getFilepath(t),e=Bun.file(n);return await e.exists()?e:null}async clear(){await S.rm(this.cacheDir,{recursive:!0,force:!0}),await S.mkdir(this.cacheDir,{recursive:!0}),console.log("🗑️ Cache cleared")}async exists(t){const n=this.getFilepath(t);return await Bun.file(n).exists()}getFilepath(t){const n=t.replace(/^\/+|\/+$/g,"");if(this.useDirectoryStructure)return n===""?g.join(this.cacheDir,"index.html"):g.join(this.cacheDir,n,"index.html");{const e=n===""?"index.html":`${n.replace(/\//g,"-")}.html`;return g.join(this.cacheDir,e)}}}exports.PreRenderer=V;exports.renderToStream=P;exports.renderToString=D;exports.renderToStringAsync=x;
package/dist/server.js CHANGED
@@ -8,16 +8,16 @@
8
8
  * See LICENSE file for full terms.
9
9
  */
10
10
 
11
- import { r as S, s as p, g as v, c as E } from "./server-context-EvJ6E74m.js";
12
- import { mkdir as A, rm as N } from "node:fs/promises";
13
- import { dirname as w, join as h } from "node:path";
14
- function D(t) {
15
- return t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
11
+ import { s as v, e as A, a as f, g as b, b as w } from "./server-context-giztFmxM.js";
12
+ import { mkdir as H, rm as D } from "node:fs/promises";
13
+ import { dirname as j, join as $ } from "node:path";
14
+ function T(r) {
15
+ return r.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
16
16
  }
17
- function j(t) {
18
- return t.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
17
+ function C(r) {
18
+ return r.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
19
19
  }
20
- const T = /* @__PURE__ */ new Set([
20
+ const x = /* @__PURE__ */ new Set([
21
21
  "area",
22
22
  "base",
23
23
  "br",
@@ -32,208 +32,225 @@ const T = /* @__PURE__ */ new Set([
32
32
  "track",
33
33
  "wbr"
34
34
  ]);
35
- function C(t) {
36
- return /^on[A-Z]/.test(t);
35
+ function L(r) {
36
+ return /^on[A-Z]/.test(r);
37
37
  }
38
- function L(t) {
39
- return Object.entries(t).map(([r, o]) => `${r.replace(/[A-Z]/g, (n) => `-${n.toLowerCase()}`)}:${o}`).join(";");
38
+ function P(r) {
39
+ return Object.entries(r).map(([t, n]) => `${t.replace(/[A-Z]/g, (o) => `-${o.toLowerCase()}`)}:${n}`).join(";");
40
40
  }
41
- function x(t, r = !0) {
42
- const o = Object.entries(t).filter(([e, n]) => !(n == null || r && e === "children" || e === "innerHTML" || C(e))).map(([e, n]) => (e === "className" && (e = "class"), e === "style" && typeof n == "object" && (n = L(n)), typeof n == "boolean" ? n ? e : "" : `${e}="${j(String(n))}"`)).filter(Boolean).join(" ");
43
- return o ? ` ${o}` : "";
41
+ function I(r, t = !0) {
42
+ const n = Object.entries(r).filter(([e, o]) => !(o == null || t && e === "children" || e === "innerHTML" || L(e))).map(([e, o]) => (e === "className" && (e = "class"), e === "style" && typeof o == "object" && (o = P(o)), typeof o == "boolean" ? o ? e : "" : `${e}="${C(String(o))}"`)).filter(Boolean).join(" ");
43
+ return n ? ` ${n}` : "";
44
44
  }
45
- function b(t) {
46
- return t ? Array.isArray(t) ? t : [t] : [];
45
+ function E(r) {
46
+ return r ? Array.isArray(r) ? r : [r] : [];
47
47
  }
48
- function P(t) {
49
- return t && typeof t.then == "function";
48
+ function M(r) {
49
+ return r && typeof r.then == "function";
50
50
  }
51
- function $(t, r) {
52
- return `<div id="${t}" data-server-component="suspended" data-component-name="${r}">Loading...</div>`;
51
+ function S(r, t) {
52
+ return `<div id="${r}" data-server-component="suspended" data-component-name="${t}">Loading...</div>`;
53
53
  }
54
- const u = /* @__PURE__ */ new Map();
54
+ const p = /* @__PURE__ */ new Map();
55
55
  let y = 0;
56
- function B(t) {
57
- return u.clear(), y = 0, S(), c(t);
56
+ function O(r) {
57
+ p.clear(), y = 0;
58
+ const t = v();
59
+ try {
60
+ return a(r);
61
+ } finally {
62
+ A(t);
63
+ }
58
64
  }
59
- async function I(t) {
60
- u.clear(), y = 0, S();
61
- let r = c(t);
62
- for (; u.size > 0; ) {
63
- console.log(
64
- `🔄 Resolving ${u.size} async components in parallel...`
65
- );
66
- const o = Array.from(u.entries());
67
- u.clear();
68
- const e = await Promise.allSettled(
69
- o.map(([n, { promise: a }]) => a)
70
- );
71
- for (let n = 0; n < o.length; n++) {
72
- const a = o[n];
73
- if (!a) continue;
74
- const [l, { componentName: i, errorFallback: s, parentNode: d }] = a, m = e[n];
75
- if (!m) continue;
76
- const g = $(l, i);
77
- if (m.status === "fulfilled")
78
- try {
79
- console.log(`✅ Resolved: ${i} (${l})`), p(d);
80
- const f = c(m.value);
81
- r = r.replace(g, f);
82
- } catch (f) {
83
- console.error(`❌ Error rendering ${i}:`, f), p(d);
84
- const H = s ? c(
85
- typeof s == "function" ? s(f) : s
86
- ) : `<div class="error">Error rendering ${i}</div>`;
87
- r = r.replace(g, H);
65
+ async function R(r) {
66
+ p.clear(), y = 0;
67
+ const t = v();
68
+ try {
69
+ let n = a(r);
70
+ for (; p.size > 0; ) {
71
+ console.log(
72
+ `🔄 Resolving ${p.size} async components in parallel...`
73
+ );
74
+ const e = Array.from(p.entries());
75
+ p.clear();
76
+ const o = await Promise.allSettled(
77
+ e.map(([i, { promise: s }]) => s)
78
+ );
79
+ for (let i = 0; i < e.length; i++) {
80
+ const s = e[i];
81
+ if (!s) continue;
82
+ const [l, { componentName: c, errorFallback: u, parentNode: g }] = s, m = o[i];
83
+ if (!m) continue;
84
+ const h = S(l, c);
85
+ if (m.status === "fulfilled")
86
+ try {
87
+ console.log(`✅ Resolved: ${c} (${l})`), f(g);
88
+ const d = a(m.value);
89
+ n = n.replace(h, d);
90
+ } catch (d) {
91
+ console.error(`❌ Error rendering ${c}:`, d), f(g);
92
+ const N = u ? a(
93
+ typeof u == "function" ? u(d) : u
94
+ ) : `<div class="error">Error rendering ${c}</div>`;
95
+ n = n.replace(h, N);
96
+ }
97
+ else {
98
+ console.error(`❌ Error resolving ${c}:`, m.reason), f(g);
99
+ const d = u ? a(
100
+ typeof u == "function" ? u(m.reason) : u
101
+ ) : `<div class="error">Error loading ${c}</div>`;
102
+ n = n.replace(h, d);
88
103
  }
89
- else {
90
- console.error(`❌ Error resolving ${i}:`, m.reason), p(d);
91
- const f = s ? c(
92
- typeof s == "function" ? s(m.reason) : s
93
- ) : `<div class="error">Error loading ${i}</div>`;
94
- r = r.replace(g, f);
95
104
  }
96
105
  }
106
+ return console.log("✅ All async components resolved!"), n;
107
+ } finally {
108
+ A(t);
97
109
  }
98
- return console.log("✅ All async components resolved!"), r;
99
110
  }
100
- async function* O(t) {
101
- for (u.clear(), y = 0, S(), yield c(t); u.size > 0; ) {
102
- const o = Array.from(u.entries());
103
- u.clear();
104
- const e = o.map(
105
- async ([n, { promise: a, parentNode: l }]) => {
106
- try {
107
- const i = await a;
108
- p(l);
109
- const s = c(i);
110
- return `<script>
111
+ async function* V(r) {
112
+ p.clear(), y = 0;
113
+ const t = v();
114
+ try {
115
+ for (yield a(r); p.size > 0; ) {
116
+ const e = Array.from(p.entries());
117
+ p.clear();
118
+ const o = e.map(
119
+ async ([i, { promise: s, parentNode: l }]) => {
120
+ try {
121
+ const c = await s;
122
+ f(l);
123
+ const u = a(c);
124
+ return `<script>
111
125
  (function() {
112
- const el = document.getElementById('${n}');
126
+ const el = document.getElementById('${i}');
113
127
  if (el) {
114
- el.outerHTML = \`${s.replace(/`/g, "\\`").replace(/\$/g, "\\$")}\`;
128
+ el.outerHTML = \`${u.replace(/`/g, "\\`").replace(/\$/g, "\\$")}\`;
115
129
  }
116
130
  })();
117
131
  <\/script>`;
118
- } catch {
119
- return `<script>
132
+ } catch {
133
+ return `<script>
120
134
  (function() {
121
- const el = document.getElementById('${n}');
135
+ const el = document.getElementById('${i}');
122
136
  if (el) {
123
137
  el.innerHTML = '<div class="error">Error loading component</div>';
124
138
  }
125
139
  })();
126
140
  <\/script>`;
141
+ }
127
142
  }
128
- }
129
- );
130
- for (const n of e)
131
- yield await n;
143
+ );
144
+ for (const i of o)
145
+ yield await i;
146
+ }
147
+ } finally {
148
+ A(t);
132
149
  }
133
150
  }
134
- function c(t) {
135
- if (typeof t == "function") {
136
- const e = t();
137
- return Array.isArray(e) ? `<!--reactive-list-->${e.map((a) => c(a)).join("")}` : c(e);
151
+ function a(r) {
152
+ if (typeof r == "function") {
153
+ const e = r();
154
+ return Array.isArray(e) ? `<!--reactive-list-->${e.map((i) => a(i)).join("")}` : a(e);
138
155
  }
139
- if (typeof t == "string")
140
- return D(t);
141
- if (typeof t == "number")
142
- return String(t);
143
- if (Array.isArray(t))
144
- return t.map((e) => c(e)).join("");
145
- if (!t || typeof t != "object")
156
+ if (typeof r == "string")
157
+ return T(r);
158
+ if (typeof r == "number")
159
+ return String(r);
160
+ if (Array.isArray(r))
161
+ return r.map((e) => a(e)).join("");
162
+ if (!r || typeof r != "object")
146
163
  return "";
147
- const { type: r, props: o } = t;
148
- if (r === Symbol.for("jsx.fragment"))
149
- return b(o.children).map((n) => c(n)).join("");
150
- if (typeof r == "string" && r === "suspended") {
151
- const e = t, n = `async-${y++}`;
164
+ const { type: t, props: n } = r;
165
+ if (t === Symbol.for("jsx.fragment"))
166
+ return E(n.children).map((o) => a(o)).join("");
167
+ if (typeof t == "string" && t === "suspended") {
168
+ const e = r, o = `async-${y++}`;
152
169
  return console.log(
153
- `⏳ Suspending: ${e._componentName} (${n})`
154
- ), u.set(n, {
155
- id: n,
170
+ `⏳ Suspending: ${e._componentName} (${o})`
171
+ ), p.set(o, {
172
+ id: o,
156
173
  promise: e.promise,
157
174
  componentName: e._componentName,
158
175
  errorFallback: e.errorFallback,
159
- parentNode: v()
160
- }), $(n, e._componentName);
176
+ parentNode: b()
177
+ }), S(o, e._componentName);
161
178
  }
162
- if (typeof r == "function") {
163
- const e = E(), n = v();
164
- p(e);
165
- const a = r(o);
166
- if (P(a)) {
167
- const i = `async-${y++}`, s = r.name || "AsyncComponent";
179
+ if (typeof t == "function") {
180
+ const e = w(), o = b();
181
+ f(e);
182
+ const i = t(n);
183
+ if (M(i)) {
184
+ const l = `async-${y++}`, c = t.name || "AsyncComponent";
168
185
  return console.warn(
169
- `⚠️ DEPRECATED: Direct async component "${s}" detected. Please use suspend() HOF instead for better type safety and custom fallbacks.
170
- Example: const ${s} = suspend(async (props) => { ... }, <Loading />, <Error />);`
171
- ), console.log(`⏳ Suspending: ${s} (${i})`), u.set(i, {
172
- id: i,
173
- promise: a,
174
- componentName: s,
186
+ `⚠️ DEPRECATED: Direct async component "${c}" detected. Please use suspend() HOF instead for better type safety and custom fallbacks.
187
+ Example: const ${c} = suspend(async (props) => { ... }, <Loading />, <Error />);`
188
+ ), console.log(`⏳ Suspending: ${c} (${l})`), p.set(l, {
189
+ id: l,
190
+ promise: i,
191
+ componentName: c,
175
192
  parentNode: e
176
- }), p(n), $(i, s);
193
+ }), f(o), S(l, c);
177
194
  }
178
- const l = c(a);
179
- return p(n), l;
195
+ const s = a(i);
196
+ return f(o), s;
180
197
  }
181
- if (typeof r == "string") {
182
- const e = x(o);
183
- if (T.has(r))
184
- return `<${r}${e} />`;
185
- if (o.innerHTML !== void 0) {
186
- const l = typeof o.innerHTML == "object" ? JSON.stringify(o.innerHTML) : o.innerHTML;
187
- return `<${r}${e}>${l}</${r}>`;
198
+ if (typeof t == "string") {
199
+ const e = I(n);
200
+ if (x.has(t))
201
+ return `<${t}${e} />`;
202
+ if (n.innerHTML !== void 0) {
203
+ const s = typeof n.innerHTML == "object" ? JSON.stringify(n.innerHTML) : n.innerHTML;
204
+ return `<${t}${e}>${s}</${t}>`;
188
205
  }
189
- const a = b(o.children).map((l) => {
190
- if (Array.isArray(l))
191
- return l.map((i) => c(i)).join("");
192
- if (typeof l == "function") {
193
- const i = l();
194
- return Array.isArray(i) ? `<!--reactive-list-->${i.map((d) => c(d)).join("")}` : `<!--reactive-->${c(i)}`;
206
+ const i = E(n.children).map((s) => {
207
+ if (Array.isArray(s))
208
+ return s.map((l) => a(l)).join("");
209
+ if (typeof s == "function") {
210
+ const l = s();
211
+ return Array.isArray(l) ? `<!--reactive-list-->${l.map((u) => a(u)).join("")}` : `<!--reactive-->${a(l)}`;
195
212
  }
196
- return c(l);
213
+ return a(s);
197
214
  }).join("");
198
- return r === "html" ? `<!DOCTYPE html>
199
- <html${e}>${a}</html>` : `<${r}${e}>${a}</${r}>`;
215
+ return t === "html" ? `<!DOCTYPE html>
216
+ <html${e}>${i}</html>` : `<${t}${e}>${i}</${t}>`;
200
217
  }
201
218
  return "";
202
219
  }
203
- class V {
220
+ class _ {
204
221
  cacheDir;
205
222
  useDirectoryStructure;
206
- constructor(r = {}) {
207
- this.cacheDir = r.cacheDir || "./cache/html", this.useDirectoryStructure = r.useDirectoryStructure ?? !1;
223
+ constructor(t = {}) {
224
+ this.cacheDir = t.cacheDir || "./cache/html", this.useDirectoryStructure = t.useDirectoryStructure ?? !1;
208
225
  }
209
- async save(r, o) {
210
- const e = this.getFilepath(r);
211
- return await A(w(e), { recursive: !0 }), await Bun.write(e, o), console.log(`✅ Pre-rendered: ${r} → ${e}`), e;
226
+ async save(t, n) {
227
+ const e = this.getFilepath(t);
228
+ return await H(j(e), { recursive: !0 }), await Bun.write(e, n), console.log(`✅ Pre-rendered: ${t} → ${e}`), e;
212
229
  }
213
- async load(r) {
214
- const o = this.getFilepath(r), e = Bun.file(o);
230
+ async load(t) {
231
+ const n = this.getFilepath(t), e = Bun.file(n);
215
232
  return await e.exists() ? e : null;
216
233
  }
217
234
  async clear() {
218
- await N(this.cacheDir, { recursive: !0, force: !0 }), await A(this.cacheDir, { recursive: !0 }), console.log("🗑️ Cache cleared");
235
+ await D(this.cacheDir, { recursive: !0, force: !0 }), await H(this.cacheDir, { recursive: !0 }), console.log("🗑️ Cache cleared");
219
236
  }
220
- async exists(r) {
221
- const o = this.getFilepath(r);
222
- return await Bun.file(o).exists();
237
+ async exists(t) {
238
+ const n = this.getFilepath(t);
239
+ return await Bun.file(n).exists();
223
240
  }
224
- getFilepath(r) {
225
- const o = r.replace(/^\/+|\/+$/g, "");
241
+ getFilepath(t) {
242
+ const n = t.replace(/^\/+|\/+$/g, "");
226
243
  if (this.useDirectoryStructure)
227
- return o === "" ? h(this.cacheDir, "index.html") : h(this.cacheDir, o, "index.html");
244
+ return n === "" ? $(this.cacheDir, "index.html") : $(this.cacheDir, n, "index.html");
228
245
  {
229
- const e = o === "" ? "index.html" : `${o.replace(/\//g, "-")}.html`;
230
- return h(this.cacheDir, e);
246
+ const e = n === "" ? "index.html" : `${n.replace(/\//g, "-")}.html`;
247
+ return $(this.cacheDir, e);
231
248
  }
232
249
  }
233
250
  }
234
251
  export {
235
- V as PreRenderer,
236
- O as renderToStream,
237
- B as renderToString,
238
- I as renderToStringAsync
252
+ _ as PreRenderer,
253
+ V as renderToStream,
254
+ O as renderToString,
255
+ R as renderToStringAsync
239
256
  };