@mateosuarezdev/flash 0.0.3 → 0.0.5
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 +897 -0
- package/dist/index.js +62 -62
- package/dist/server.cjs +4 -4
- package/dist/server.js +90 -86
- package/package.json +2 -2
package/dist/server.js
CHANGED
|
@@ -10,13 +10,13 @@
|
|
|
10
10
|
|
|
11
11
|
import { mkdir as h, rm as S } from "node:fs/promises";
|
|
12
12
|
import { dirname as b, join as y } from "node:path";
|
|
13
|
-
function v(
|
|
14
|
-
return
|
|
13
|
+
function v(t) {
|
|
14
|
+
return t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
15
15
|
}
|
|
16
|
-
function
|
|
17
|
-
return
|
|
16
|
+
function H(t) {
|
|
17
|
+
return t.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
18
18
|
}
|
|
19
|
-
const
|
|
19
|
+
const E = /* @__PURE__ */ new Set([
|
|
20
20
|
"area",
|
|
21
21
|
"base",
|
|
22
22
|
"br",
|
|
@@ -31,79 +31,79 @@ const w = /* @__PURE__ */ new Set([
|
|
|
31
31
|
"track",
|
|
32
32
|
"wbr"
|
|
33
33
|
]);
|
|
34
|
-
function
|
|
35
|
-
return /^on[A-Z]/.test(
|
|
34
|
+
function w(t) {
|
|
35
|
+
return /^on[A-Z]/.test(t);
|
|
36
36
|
}
|
|
37
|
-
function
|
|
38
|
-
return Object.entries(
|
|
37
|
+
function D(t) {
|
|
38
|
+
return Object.entries(t).map(([r, o]) => `${r.replace(/[A-Z]/g, (n) => `-${n.toLowerCase()}`)}:${o}`).join(";");
|
|
39
39
|
}
|
|
40
|
-
function j(
|
|
41
|
-
const o = Object.entries(
|
|
40
|
+
function j(t, r = !0) {
|
|
41
|
+
const o = Object.entries(t).filter(([e, n]) => !(n == null || r && e === "children" || e === "innerHTML" || w(e))).map(([e, n]) => (e === "className" && (e = "class"), e === "style" && typeof n == "object" && (n = D(n)), typeof n == "boolean" ? n ? e : "" : `${e}="${H(String(n))}"`)).filter(Boolean).join(" ");
|
|
42
42
|
return o ? ` ${o}` : "";
|
|
43
43
|
}
|
|
44
|
-
function $(
|
|
45
|
-
return
|
|
44
|
+
function $(t) {
|
|
45
|
+
return t ? Array.isArray(t) ? t : [t] : [];
|
|
46
46
|
}
|
|
47
|
-
function
|
|
48
|
-
return
|
|
47
|
+
function T(t) {
|
|
48
|
+
return t && typeof t.then == "function";
|
|
49
49
|
}
|
|
50
|
-
function g(
|
|
51
|
-
return `<div id="${
|
|
50
|
+
function g(t, r) {
|
|
51
|
+
return `<div id="${t}" data-server-component="suspended" data-component-name="${r}">Loading...</div>`;
|
|
52
52
|
}
|
|
53
|
-
const
|
|
53
|
+
const l = /* @__PURE__ */ new Map();
|
|
54
54
|
let d = 0;
|
|
55
|
-
function
|
|
56
|
-
return
|
|
55
|
+
function P(t) {
|
|
56
|
+
return l.clear(), d = 0, s(t);
|
|
57
57
|
}
|
|
58
|
-
async function
|
|
59
|
-
|
|
60
|
-
let
|
|
61
|
-
for (;
|
|
58
|
+
async function x(t) {
|
|
59
|
+
l.clear(), d = 0;
|
|
60
|
+
let r = s(t);
|
|
61
|
+
for (; l.size > 0; ) {
|
|
62
62
|
console.log(
|
|
63
|
-
`🔄 Resolving ${
|
|
63
|
+
`🔄 Resolving ${l.size} async components in parallel...`
|
|
64
64
|
);
|
|
65
|
-
const o = Array.from(
|
|
66
|
-
|
|
65
|
+
const o = Array.from(l.entries());
|
|
66
|
+
l.clear();
|
|
67
67
|
const e = await Promise.allSettled(
|
|
68
68
|
o.map(([n, { promise: i }]) => i)
|
|
69
69
|
);
|
|
70
70
|
for (let n = 0; n < o.length; n++) {
|
|
71
71
|
const i = o[n];
|
|
72
72
|
if (!i) continue;
|
|
73
|
-
const [
|
|
73
|
+
const [a, { componentName: c, errorFallback: u }] = i, p = e[n];
|
|
74
74
|
if (!p) continue;
|
|
75
|
-
const m = g(
|
|
75
|
+
const m = g(a, c);
|
|
76
76
|
if (p.status === "fulfilled")
|
|
77
77
|
try {
|
|
78
|
-
console.log(`✅ Resolved: ${c} (${
|
|
78
|
+
console.log(`✅ Resolved: ${c} (${a})`);
|
|
79
79
|
const f = s(p.value);
|
|
80
|
-
|
|
80
|
+
r = r.replace(m, f);
|
|
81
81
|
} catch (f) {
|
|
82
82
|
console.error(`❌ Error rendering ${c}:`, f);
|
|
83
83
|
const A = u ? s(
|
|
84
84
|
typeof u == "function" ? u(f) : u
|
|
85
85
|
) : `<div class="error">Error rendering ${c}</div>`;
|
|
86
|
-
|
|
86
|
+
r = r.replace(m, A);
|
|
87
87
|
}
|
|
88
88
|
else {
|
|
89
89
|
console.error(`❌ Error resolving ${c}:`, p.reason);
|
|
90
90
|
const f = u ? s(
|
|
91
91
|
typeof u == "function" ? u(p.reason) : u
|
|
92
92
|
) : `<div class="error">Error loading ${c}</div>`;
|
|
93
|
-
|
|
93
|
+
r = r.replace(m, f);
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
-
return console.log("✅ All async components resolved!"),
|
|
97
|
+
return console.log("✅ All async components resolved!"), r;
|
|
98
98
|
}
|
|
99
|
-
async function*
|
|
100
|
-
for (
|
|
101
|
-
const o = Array.from(
|
|
102
|
-
|
|
99
|
+
async function* C(t) {
|
|
100
|
+
for (l.clear(), d = 0, yield s(t); l.size > 0; ) {
|
|
101
|
+
const o = Array.from(l.entries());
|
|
102
|
+
l.clear();
|
|
103
103
|
const e = o.map(
|
|
104
104
|
async ([n, { promise: i }]) => {
|
|
105
105
|
try {
|
|
106
|
-
const
|
|
106
|
+
const a = await i, c = s(a);
|
|
107
107
|
return `<script>
|
|
108
108
|
(function() {
|
|
109
109
|
const el = document.getElementById('${n}');
|
|
@@ -128,27 +128,27 @@ async function* F(r) {
|
|
|
128
128
|
yield await n;
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
|
-
function s(
|
|
132
|
-
if (typeof
|
|
133
|
-
const e =
|
|
131
|
+
function s(t) {
|
|
132
|
+
if (typeof t == "function") {
|
|
133
|
+
const e = t();
|
|
134
134
|
return Array.isArray(e) ? `<!--reactive-list-->${e.map((i) => s(i)).join("")}` : s(e);
|
|
135
135
|
}
|
|
136
|
-
if (typeof
|
|
137
|
-
return v(
|
|
138
|
-
if (typeof
|
|
139
|
-
return String(
|
|
140
|
-
if (Array.isArray(
|
|
141
|
-
return
|
|
142
|
-
if (!
|
|
136
|
+
if (typeof t == "string")
|
|
137
|
+
return v(t);
|
|
138
|
+
if (typeof t == "number")
|
|
139
|
+
return String(t);
|
|
140
|
+
if (Array.isArray(t))
|
|
141
|
+
return t.map((e) => s(e)).join("");
|
|
142
|
+
if (!t || typeof t != "object")
|
|
143
143
|
return "";
|
|
144
|
-
const { type:
|
|
145
|
-
if (
|
|
144
|
+
const { type: r, props: o } = t;
|
|
145
|
+
if (r === Symbol.for("jsx.fragment"))
|
|
146
146
|
return $(o.children).map((n) => s(n)).join("");
|
|
147
|
-
if (typeof
|
|
148
|
-
const e =
|
|
147
|
+
if (typeof r == "string" && r === "suspended") {
|
|
148
|
+
const e = t, n = `async-${d++}`;
|
|
149
149
|
return console.log(
|
|
150
150
|
`⏳ Suspending: ${e._componentName} (${n})`
|
|
151
|
-
),
|
|
151
|
+
), l.set(n, {
|
|
152
152
|
id: n,
|
|
153
153
|
promise: e.promise,
|
|
154
154
|
componentName: e._componentName,
|
|
@@ -156,14 +156,14 @@ function s(r) {
|
|
|
156
156
|
// Store custom error fallback
|
|
157
157
|
}), g(n, e._componentName);
|
|
158
158
|
}
|
|
159
|
-
if (typeof
|
|
160
|
-
const e =
|
|
161
|
-
if (
|
|
162
|
-
const n = `async-${d++}`, i =
|
|
159
|
+
if (typeof r == "function") {
|
|
160
|
+
const e = r(o);
|
|
161
|
+
if (T(e)) {
|
|
162
|
+
const n = `async-${d++}`, i = r.name || "AsyncComponent";
|
|
163
163
|
return console.warn(
|
|
164
164
|
`⚠️ DEPRECATED: Direct async component "${i}" detected. Please use suspend() HOF instead for better type safety and custom fallbacks.
|
|
165
165
|
Example: const ${i} = suspend(async (props) => { ... }, <Loading />, <Error />);`
|
|
166
|
-
), console.log(`⏳ Suspending: ${i} (${n})`),
|
|
166
|
+
), console.log(`⏳ Suspending: ${i} (${n})`), l.set(n, {
|
|
167
167
|
id: n,
|
|
168
168
|
promise: e,
|
|
169
169
|
componentName: i
|
|
@@ -171,47 +171,51 @@ Example: const ${i} = suspend(async (props) => { ... }, <Loading />, <Error />);
|
|
|
171
171
|
}
|
|
172
172
|
return s(e);
|
|
173
173
|
}
|
|
174
|
-
if (typeof
|
|
174
|
+
if (typeof r == "string") {
|
|
175
175
|
const e = j(o);
|
|
176
|
-
if (
|
|
177
|
-
return `<${
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
176
|
+
if (E.has(r))
|
|
177
|
+
return `<${r}${e} />`;
|
|
178
|
+
if (o.innerHTML !== void 0) {
|
|
179
|
+
const a = typeof o.innerHTML == "object" ? JSON.stringify(o.innerHTML) : o.innerHTML;
|
|
180
|
+
return `<${r}${e}>${a}</${r}>`;
|
|
181
|
+
}
|
|
182
|
+
const i = $(o.children).map((a) => {
|
|
183
|
+
if (Array.isArray(a))
|
|
184
|
+
return a.map((c) => s(c)).join("");
|
|
185
|
+
if (typeof a == "function") {
|
|
186
|
+
const c = a();
|
|
183
187
|
return Array.isArray(c) ? `<!--reactive-list-->${c.map((p) => s(p)).join("")}` : `<!--reactive-->${s(c)}`;
|
|
184
188
|
}
|
|
185
|
-
return s(
|
|
189
|
+
return s(a);
|
|
186
190
|
}).join("");
|
|
187
|
-
return
|
|
188
|
-
<html${e}>${i}</html>` : `<${
|
|
191
|
+
return r === "html" ? `<!DOCTYPE html>
|
|
192
|
+
<html${e}>${i}</html>` : `<${r}${e}>${i}</${r}>`;
|
|
189
193
|
}
|
|
190
194
|
return "";
|
|
191
195
|
}
|
|
192
|
-
class
|
|
196
|
+
class M {
|
|
193
197
|
cacheDir;
|
|
194
198
|
useDirectoryStructure;
|
|
195
|
-
constructor(
|
|
196
|
-
this.cacheDir =
|
|
199
|
+
constructor(r = {}) {
|
|
200
|
+
this.cacheDir = r.cacheDir || "./cache/html", this.useDirectoryStructure = r.useDirectoryStructure ?? !1;
|
|
197
201
|
}
|
|
198
|
-
async save(
|
|
199
|
-
const e = this.getFilepath(
|
|
200
|
-
return await h(b(e), { recursive: !0 }), await Bun.write(e, o), console.log(`✅ Pre-rendered: ${
|
|
202
|
+
async save(r, o) {
|
|
203
|
+
const e = this.getFilepath(r);
|
|
204
|
+
return await h(b(e), { recursive: !0 }), await Bun.write(e, o), console.log(`✅ Pre-rendered: ${r} → ${e}`), e;
|
|
201
205
|
}
|
|
202
|
-
async load(
|
|
203
|
-
const o = this.getFilepath(
|
|
206
|
+
async load(r) {
|
|
207
|
+
const o = this.getFilepath(r), e = Bun.file(o);
|
|
204
208
|
return await e.exists() ? e : null;
|
|
205
209
|
}
|
|
206
210
|
async clear() {
|
|
207
211
|
await S(this.cacheDir, { recursive: !0, force: !0 }), await h(this.cacheDir, { recursive: !0 }), console.log("🗑️ Cache cleared");
|
|
208
212
|
}
|
|
209
|
-
async exists(
|
|
210
|
-
const o = this.getFilepath(
|
|
213
|
+
async exists(r) {
|
|
214
|
+
const o = this.getFilepath(r);
|
|
211
215
|
return await Bun.file(o).exists();
|
|
212
216
|
}
|
|
213
|
-
getFilepath(
|
|
214
|
-
const o =
|
|
217
|
+
getFilepath(r) {
|
|
218
|
+
const o = r.replace(/^\/+|\/+$/g, "");
|
|
215
219
|
if (this.useDirectoryStructure)
|
|
216
220
|
return o === "" ? y(this.cacheDir, "index.html") : y(this.cacheDir, o, "index.html");
|
|
217
221
|
{
|
|
@@ -221,8 +225,8 @@ class z {
|
|
|
221
225
|
}
|
|
222
226
|
}
|
|
223
227
|
export {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
+
M as PreRenderer,
|
|
229
|
+
C as renderToStream,
|
|
230
|
+
P as renderToString,
|
|
231
|
+
x as renderToStringAsync
|
|
228
232
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mateosuarezdev/flash",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "Custom jsx runtime",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"sideEffects": false,
|
|
47
47
|
"scripts": {
|
|
48
48
|
"dev": "vite --host",
|
|
49
|
-
"build": "vite build && bun run scripts/prepend-license.ts",
|
|
49
|
+
"build": "vite build && bun run scripts/append-jsx-types.ts && bun run scripts/prepend-license.ts",
|
|
50
50
|
"build:visualize": "vite-bundle-visualizer",
|
|
51
51
|
"typecheck": "tsc --noEmit",
|
|
52
52
|
"clean": "rimraf dist",
|