@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/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(r) {
14
- return r.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
13
+ function v(t) {
14
+ return t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
15
15
  }
16
- function E(r) {
17
- return r.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
16
+ function H(t) {
17
+ return t.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
18
18
  }
19
- const w = /* @__PURE__ */ new Set([
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 D(r) {
35
- return /^on[A-Z]/.test(r);
34
+ function w(t) {
35
+ return /^on[A-Z]/.test(t);
36
36
  }
37
- function H(r) {
38
- return Object.entries(r).map(([t, o]) => `${t.replace(/[A-Z]/g, (n) => `-${n.toLowerCase()}`)}:${o}`).join(";");
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(r, t = !0) {
41
- const o = Object.entries(r).filter(([e, n]) => !(n == null || t && e === "children" || D(e))).map(([e, n]) => (e === "className" && (e = "class"), e === "style" && typeof n == "object" && (n = H(n)), typeof n == "boolean" ? n ? e : "" : `${e}="${E(String(n))}"`)).filter(Boolean).join(" ");
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 $(r) {
45
- return r ? Array.isArray(r) ? r : [r] : [];
44
+ function $(t) {
45
+ return t ? Array.isArray(t) ? t : [t] : [];
46
46
  }
47
- function P(r) {
48
- return r && typeof r.then == "function";
47
+ function T(t) {
48
+ return t && typeof t.then == "function";
49
49
  }
50
- function g(r, t) {
51
- return `<div id="${r}" data-server-component="suspended" data-component-name="${t}">Loading...</div>`;
50
+ function g(t, r) {
51
+ return `<div id="${t}" data-server-component="suspended" data-component-name="${r}">Loading...</div>`;
52
52
  }
53
- const a = /* @__PURE__ */ new Map();
53
+ const l = /* @__PURE__ */ new Map();
54
54
  let d = 0;
55
- function N(r) {
56
- return a.clear(), d = 0, s(r);
55
+ function P(t) {
56
+ return l.clear(), d = 0, s(t);
57
57
  }
58
- async function T(r) {
59
- a.clear(), d = 0;
60
- let t = s(r);
61
- for (; a.size > 0; ) {
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 ${a.size} async components in parallel...`
63
+ `🔄 Resolving ${l.size} async components in parallel...`
64
64
  );
65
- const o = Array.from(a.entries());
66
- a.clear();
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 [l, { componentName: c, errorFallback: u }] = i, p = e[n];
73
+ const [a, { componentName: c, errorFallback: u }] = i, p = e[n];
74
74
  if (!p) continue;
75
- const m = g(l, c);
75
+ const m = g(a, c);
76
76
  if (p.status === "fulfilled")
77
77
  try {
78
- console.log(`✅ Resolved: ${c} (${l})`);
78
+ console.log(`✅ Resolved: ${c} (${a})`);
79
79
  const f = s(p.value);
80
- t = t.replace(m, f);
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
- t = t.replace(m, A);
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
- t = t.replace(m, f);
93
+ r = r.replace(m, f);
94
94
  }
95
95
  }
96
96
  }
97
- return console.log("✅ All async components resolved!"), t;
97
+ return console.log("✅ All async components resolved!"), r;
98
98
  }
99
- async function* F(r) {
100
- for (a.clear(), d = 0, yield s(r); a.size > 0; ) {
101
- const o = Array.from(a.entries());
102
- a.clear();
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 l = await i, c = s(l);
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(r) {
132
- if (typeof r == "function") {
133
- const e = r();
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 r == "string")
137
- return v(r);
138
- if (typeof r == "number")
139
- return String(r);
140
- if (Array.isArray(r))
141
- return r.map((e) => s(e)).join("");
142
- if (!r || typeof r != "object")
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: t, props: o } = r;
145
- if (t === Symbol.for("jsx.fragment"))
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 t == "string" && t === "suspended") {
148
- const e = r, n = `async-${d++}`;
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
- ), a.set(n, {
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 t == "function") {
160
- const e = t(o);
161
- if (P(e)) {
162
- const n = `async-${d++}`, i = t.name || "AsyncComponent";
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})`), a.set(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 t == "string") {
174
+ if (typeof r == "string") {
175
175
  const e = j(o);
176
- if (w.has(t))
177
- return `<${t}${e} />`;
178
- const i = $(o.children).map((l) => {
179
- if (Array.isArray(l))
180
- return l.map((c) => s(c)).join("");
181
- if (typeof l == "function") {
182
- const c = l();
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(l);
189
+ return s(a);
186
190
  }).join("");
187
- return t === "html" ? `<!DOCTYPE html>
188
- <html${e}>${i}</html>` : `<${t}${e}>${i}</${t}>`;
191
+ return r === "html" ? `<!DOCTYPE html>
192
+ <html${e}>${i}</html>` : `<${r}${e}>${i}</${r}>`;
189
193
  }
190
194
  return "";
191
195
  }
192
- class z {
196
+ class M {
193
197
  cacheDir;
194
198
  useDirectoryStructure;
195
- constructor(t = {}) {
196
- this.cacheDir = t.cacheDir || "./cache/html", this.useDirectoryStructure = t.useDirectoryStructure ?? !1;
199
+ constructor(r = {}) {
200
+ this.cacheDir = r.cacheDir || "./cache/html", this.useDirectoryStructure = r.useDirectoryStructure ?? !1;
197
201
  }
198
- async save(t, o) {
199
- const e = this.getFilepath(t);
200
- return await h(b(e), { recursive: !0 }), await Bun.write(e, o), console.log(`✅ Pre-rendered: ${t} → ${e}`), e;
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(t) {
203
- const o = this.getFilepath(t), e = Bun.file(o);
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(t) {
210
- const o = this.getFilepath(t);
213
+ async exists(r) {
214
+ const o = this.getFilepath(r);
211
215
  return await Bun.file(o).exists();
212
216
  }
213
- getFilepath(t) {
214
- const o = t.replace(/^\/+|\/+$/g, "");
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
- z as PreRenderer,
225
- F as renderToStream,
226
- N as renderToString,
227
- T as renderToStringAsync
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",
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",