@mateosuarezdev/flash 0.0.6 → 0.0.10
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/index.cjs +1 -1
- package/dist/index.d.ts +10 -9
- package/dist/index.js +165 -157
- package/dist/server-context-BA2xc7wp.js +47 -0
- package/dist/server-context-BPTFSl-d.cjs +11 -0
- package/dist/server.cjs +5 -5
- package/dist/server.js +99 -92
- package/package.json +1 -1
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
let e = null;
|
|
12
|
+
function o() {
|
|
13
|
+
return e;
|
|
14
|
+
}
|
|
15
|
+
function a(r) {
|
|
16
|
+
e = r;
|
|
17
|
+
}
|
|
18
|
+
function c() {
|
|
19
|
+
return {
|
|
20
|
+
_parent: e
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function u() {
|
|
24
|
+
e = null;
|
|
25
|
+
}
|
|
26
|
+
function p(r, n) {
|
|
27
|
+
if (!e)
|
|
28
|
+
throw new Error("provideServerContext called outside of component render");
|
|
29
|
+
e._contextMap || (e._contextMap = /* @__PURE__ */ new Map()), e._contextMap.set(r, n);
|
|
30
|
+
}
|
|
31
|
+
function s(r, n) {
|
|
32
|
+
let t = e;
|
|
33
|
+
for (; t; ) {
|
|
34
|
+
if (t._contextMap?.has(r))
|
|
35
|
+
return t._contextMap.get(r);
|
|
36
|
+
t = t._parent;
|
|
37
|
+
}
|
|
38
|
+
return n;
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
s as a,
|
|
42
|
+
c,
|
|
43
|
+
o as g,
|
|
44
|
+
p,
|
|
45
|
+
u as r,
|
|
46
|
+
a as s
|
|
47
|
+
};
|
|
@@ -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";let e=null;function o(){return e}function u(r){e=r}function c(){return{_parent:e}}function v(){e=null}function i(r,n){if(!e)throw new Error("provideServerContext called outside of component render");e._contextMap||(e._contextMap=new Map),e._contextMap.set(r,n)}function S(r,n){let t=e;for(;t;){if(t._contextMap?.has(r))return t._contextMap.get(r);t=t._parent}return n}exports.consumeServerContext=S;exports.createServerVNode=c;exports.getCurrentServerVNode=o;exports.provideServerContext=i;exports.resetServerContext=v;exports.setCurrentServerVNode=u;
|
package/dist/server.cjs
CHANGED
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
* See LICENSE file for full terms.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
11
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("./server-context-BPTFSl-d.cjs"),$=require("node:fs/promises"),g=require("node:path");function N(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function b(t){return t.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}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>
|
|
12
12
|
(function() {
|
|
13
13
|
const el = document.getElementById('${n}');
|
|
14
14
|
if (el) {
|
|
15
|
-
el.outerHTML = \`${
|
|
15
|
+
el.outerHTML = \`${i.replace(/`/g,"\\`").replace(/\$/g,"\\$")}\`;
|
|
16
16
|
}
|
|
17
17
|
})();
|
|
18
18
|
<\/script>`}catch{return`<script>
|
|
@@ -22,6 +22,6 @@
|
|
|
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
|
|
26
|
-
Example: const ${i} = suspend(async (props) => { ... }, <Loading />, <Error />);`),console.log(`⏳ Suspending: ${i} (${
|
|
27
|
-
<html${e}>${
|
|
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;
|
package/dist/server.js
CHANGED
|
@@ -8,15 +8,16 @@
|
|
|
8
8
|
* See LICENSE file for full terms.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
11
|
+
import { s as p, g as v, c as E, r as S } from "./server-context-BA2xc7wp.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) {
|
|
14
15
|
return t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
15
16
|
}
|
|
16
|
-
function
|
|
17
|
+
function j(t) {
|
|
17
18
|
return t.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
18
19
|
}
|
|
19
|
-
const
|
|
20
|
+
const T = /* @__PURE__ */ new Set([
|
|
20
21
|
"area",
|
|
21
22
|
"base",
|
|
22
23
|
"br",
|
|
@@ -31,84 +32,86 @@ const E = /* @__PURE__ */ new Set([
|
|
|
31
32
|
"track",
|
|
32
33
|
"wbr"
|
|
33
34
|
]);
|
|
34
|
-
function
|
|
35
|
+
function C(t) {
|
|
35
36
|
return /^on[A-Z]/.test(t);
|
|
36
37
|
}
|
|
37
|
-
function
|
|
38
|
+
function L(t) {
|
|
38
39
|
return Object.entries(t).map(([r, o]) => `${r.replace(/[A-Z]/g, (n) => `-${n.toLowerCase()}`)}:${o}`).join(";");
|
|
39
40
|
}
|
|
40
|
-
function
|
|
41
|
-
const o = Object.entries(t).filter(([e, n]) => !(n == null || r && e === "children" || e === "innerHTML" ||
|
|
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(" ");
|
|
42
43
|
return o ? ` ${o}` : "";
|
|
43
44
|
}
|
|
44
|
-
function
|
|
45
|
+
function b(t) {
|
|
45
46
|
return t ? Array.isArray(t) ? t : [t] : [];
|
|
46
47
|
}
|
|
47
|
-
function
|
|
48
|
+
function P(t) {
|
|
48
49
|
return t && typeof t.then == "function";
|
|
49
50
|
}
|
|
50
|
-
function
|
|
51
|
+
function $(t, r) {
|
|
51
52
|
return `<div id="${t}" data-server-component="suspended" data-component-name="${r}">Loading...</div>`;
|
|
52
53
|
}
|
|
53
|
-
const
|
|
54
|
-
let
|
|
55
|
-
function
|
|
56
|
-
return
|
|
54
|
+
const u = /* @__PURE__ */ new Map();
|
|
55
|
+
let y = 0;
|
|
56
|
+
function B(t) {
|
|
57
|
+
return u.clear(), y = 0, S(), c(t);
|
|
57
58
|
}
|
|
58
|
-
async function
|
|
59
|
-
|
|
60
|
-
let r =
|
|
61
|
-
for (;
|
|
59
|
+
async function I(t) {
|
|
60
|
+
u.clear(), y = 0, S();
|
|
61
|
+
let r = c(t);
|
|
62
|
+
for (; u.size > 0; ) {
|
|
62
63
|
console.log(
|
|
63
|
-
`🔄 Resolving ${
|
|
64
|
+
`🔄 Resolving ${u.size} async components in parallel...`
|
|
64
65
|
);
|
|
65
|
-
const o = Array.from(
|
|
66
|
-
|
|
66
|
+
const o = Array.from(u.entries());
|
|
67
|
+
u.clear();
|
|
67
68
|
const e = await Promise.allSettled(
|
|
68
|
-
o.map(([n, { promise:
|
|
69
|
+
o.map(([n, { promise: a }]) => a)
|
|
69
70
|
);
|
|
70
71
|
for (let n = 0; n < o.length; n++) {
|
|
71
|
-
const
|
|
72
|
-
if (!
|
|
73
|
-
const [
|
|
74
|
-
if (!
|
|
75
|
-
const
|
|
76
|
-
if (
|
|
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")
|
|
77
78
|
try {
|
|
78
|
-
console.log(`✅ Resolved: ${
|
|
79
|
-
const f =
|
|
80
|
-
r = r.replace(
|
|
79
|
+
console.log(`✅ Resolved: ${i} (${l})`), p(d);
|
|
80
|
+
const f = c(m.value);
|
|
81
|
+
r = r.replace(g, f);
|
|
81
82
|
} catch (f) {
|
|
82
|
-
console.error(`❌ Error rendering ${
|
|
83
|
-
const
|
|
84
|
-
typeof
|
|
85
|
-
) : `<div class="error">Error rendering ${
|
|
86
|
-
r = r.replace(
|
|
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);
|
|
87
88
|
}
|
|
88
89
|
else {
|
|
89
|
-
console.error(`❌ Error resolving ${
|
|
90
|
-
const f =
|
|
91
|
-
typeof
|
|
92
|
-
) : `<div class="error">Error loading ${
|
|
93
|
-
r = r.replace(
|
|
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);
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
97
|
}
|
|
97
98
|
return console.log("✅ All async components resolved!"), r;
|
|
98
99
|
}
|
|
99
|
-
async function*
|
|
100
|
-
for (
|
|
101
|
-
const o = Array.from(
|
|
102
|
-
|
|
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();
|
|
103
104
|
const e = o.map(
|
|
104
|
-
async ([n, { promise:
|
|
105
|
+
async ([n, { promise: a, parentNode: l }]) => {
|
|
105
106
|
try {
|
|
106
|
-
const
|
|
107
|
+
const i = await a;
|
|
108
|
+
p(l);
|
|
109
|
+
const s = c(i);
|
|
107
110
|
return `<script>
|
|
108
111
|
(function() {
|
|
109
112
|
const el = document.getElementById('${n}');
|
|
110
113
|
if (el) {
|
|
111
|
-
el.outerHTML = \`${
|
|
114
|
+
el.outerHTML = \`${s.replace(/`/g, "\\`").replace(/\$/g, "\\$")}\`;
|
|
112
115
|
}
|
|
113
116
|
})();
|
|
114
117
|
<\/script>`;
|
|
@@ -128,72 +131,76 @@ async function* C(t) {
|
|
|
128
131
|
yield await n;
|
|
129
132
|
}
|
|
130
133
|
}
|
|
131
|
-
function
|
|
134
|
+
function c(t) {
|
|
132
135
|
if (typeof t == "function") {
|
|
133
136
|
const e = t();
|
|
134
|
-
return Array.isArray(e) ? `<!--reactive-list-->${e.map((
|
|
137
|
+
return Array.isArray(e) ? `<!--reactive-list-->${e.map((a) => c(a)).join("")}` : c(e);
|
|
135
138
|
}
|
|
136
139
|
if (typeof t == "string")
|
|
137
|
-
return
|
|
140
|
+
return D(t);
|
|
138
141
|
if (typeof t == "number")
|
|
139
142
|
return String(t);
|
|
140
143
|
if (Array.isArray(t))
|
|
141
|
-
return t.map((e) =>
|
|
144
|
+
return t.map((e) => c(e)).join("");
|
|
142
145
|
if (!t || typeof t != "object")
|
|
143
146
|
return "";
|
|
144
147
|
const { type: r, props: o } = t;
|
|
145
148
|
if (r === Symbol.for("jsx.fragment"))
|
|
146
|
-
return
|
|
149
|
+
return b(o.children).map((n) => c(n)).join("");
|
|
147
150
|
if (typeof r == "string" && r === "suspended") {
|
|
148
|
-
const e = t, n = `async-${
|
|
151
|
+
const e = t, n = `async-${y++}`;
|
|
149
152
|
return console.log(
|
|
150
153
|
`⏳ Suspending: ${e._componentName} (${n})`
|
|
151
|
-
),
|
|
154
|
+
), u.set(n, {
|
|
152
155
|
id: n,
|
|
153
156
|
promise: e.promise,
|
|
154
157
|
componentName: e._componentName,
|
|
155
|
-
errorFallback: e.errorFallback
|
|
156
|
-
|
|
157
|
-
}),
|
|
158
|
+
errorFallback: e.errorFallback,
|
|
159
|
+
parentNode: v()
|
|
160
|
+
}), $(n, e._componentName);
|
|
158
161
|
}
|
|
159
162
|
if (typeof r == "function") {
|
|
160
|
-
const e =
|
|
161
|
-
|
|
162
|
-
|
|
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";
|
|
163
168
|
return console.warn(
|
|
164
|
-
`⚠️ DEPRECATED: Direct async component "${
|
|
165
|
-
Example: const ${
|
|
166
|
-
), console.log(`⏳ Suspending: ${
|
|
167
|
-
id:
|
|
168
|
-
promise:
|
|
169
|
-
componentName:
|
|
170
|
-
|
|
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,
|
|
175
|
+
parentNode: e
|
|
176
|
+
}), p(n), $(i, s);
|
|
171
177
|
}
|
|
172
|
-
|
|
178
|
+
const l = c(a);
|
|
179
|
+
return p(n), l;
|
|
173
180
|
}
|
|
174
181
|
if (typeof r == "string") {
|
|
175
|
-
const e =
|
|
176
|
-
if (
|
|
182
|
+
const e = x(o);
|
|
183
|
+
if (T.has(r))
|
|
177
184
|
return `<${r}${e} />`;
|
|
178
185
|
if (o.innerHTML !== void 0) {
|
|
179
|
-
const
|
|
180
|
-
return `<${r}${e}>${
|
|
186
|
+
const l = typeof o.innerHTML == "object" ? JSON.stringify(o.innerHTML) : o.innerHTML;
|
|
187
|
+
return `<${r}${e}>${l}</${r}>`;
|
|
181
188
|
}
|
|
182
|
-
const
|
|
183
|
-
if (Array.isArray(
|
|
184
|
-
return
|
|
185
|
-
if (typeof
|
|
186
|
-
const
|
|
187
|
-
return Array.isArray(
|
|
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)}`;
|
|
188
195
|
}
|
|
189
|
-
return
|
|
196
|
+
return c(l);
|
|
190
197
|
}).join("");
|
|
191
198
|
return r === "html" ? `<!DOCTYPE html>
|
|
192
|
-
<html${e}>${
|
|
199
|
+
<html${e}>${a}</html>` : `<${r}${e}>${a}</${r}>`;
|
|
193
200
|
}
|
|
194
201
|
return "";
|
|
195
202
|
}
|
|
196
|
-
class
|
|
203
|
+
class V {
|
|
197
204
|
cacheDir;
|
|
198
205
|
useDirectoryStructure;
|
|
199
206
|
constructor(r = {}) {
|
|
@@ -201,14 +208,14 @@ class M {
|
|
|
201
208
|
}
|
|
202
209
|
async save(r, o) {
|
|
203
210
|
const e = this.getFilepath(r);
|
|
204
|
-
return await
|
|
211
|
+
return await A(w(e), { recursive: !0 }), await Bun.write(e, o), console.log(`✅ Pre-rendered: ${r} → ${e}`), e;
|
|
205
212
|
}
|
|
206
213
|
async load(r) {
|
|
207
214
|
const o = this.getFilepath(r), e = Bun.file(o);
|
|
208
215
|
return await e.exists() ? e : null;
|
|
209
216
|
}
|
|
210
217
|
async clear() {
|
|
211
|
-
await
|
|
218
|
+
await N(this.cacheDir, { recursive: !0, force: !0 }), await A(this.cacheDir, { recursive: !0 }), console.log("🗑️ Cache cleared");
|
|
212
219
|
}
|
|
213
220
|
async exists(r) {
|
|
214
221
|
const o = this.getFilepath(r);
|
|
@@ -217,16 +224,16 @@ class M {
|
|
|
217
224
|
getFilepath(r) {
|
|
218
225
|
const o = r.replace(/^\/+|\/+$/g, "");
|
|
219
226
|
if (this.useDirectoryStructure)
|
|
220
|
-
return o === "" ?
|
|
227
|
+
return o === "" ? h(this.cacheDir, "index.html") : h(this.cacheDir, o, "index.html");
|
|
221
228
|
{
|
|
222
229
|
const e = o === "" ? "index.html" : `${o.replace(/\//g, "-")}.html`;
|
|
223
|
-
return
|
|
230
|
+
return h(this.cacheDir, e);
|
|
224
231
|
}
|
|
225
232
|
}
|
|
226
233
|
}
|
|
227
234
|
export {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
235
|
+
V as PreRenderer,
|
|
236
|
+
O as renderToStream,
|
|
237
|
+
B as renderToString,
|
|
238
|
+
I as renderToStringAsync
|
|
232
239
|
};
|