@mateosuarezdev/flash 0.0.2 → 0.0.3

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.cjs CHANGED
@@ -8,7 +8,7 @@
8
8
  * See LICENSE file for full terms.
9
9
  */
10
10
 
11
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("node:fs/promises"),m=require("node:path");function b(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function A(t){return t.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}const v=new Set(["area","base","br","col","embed","hr","img","input","link","meta","source","track","wbr"]);function E(t){return/^on[A-Z]/.test(t)}function w(t){return Object.entries(t).map(([r,o])=>`${r.replace(/[A-Z]/g,n=>`-${n.toLowerCase()}`)}:${o}`).join(";")}function D(t,r=!0){const o=Object.entries(t).filter(([e,n])=>!(n==null||r&&e==="children"||E(e))).map(([e,n])=>(e==="className"&&(e="class"),e==="style"&&typeof n=="object"&&(n=w(n)),typeof n=="boolean"?n?e:"":`${e}="${A(String(n))}"`)).filter(Boolean).join(" ");return o?` ${o}`:""}function $(t){return t?Array.isArray(t)?t:[t]:[]}function j(t){return t&&typeof t.then=="function"}function h(t,r){return`<div id="${t}" data-server-component="suspended" data-component-name="${r}">Loading...</div>`}const a=new Map;let d=0;function H(t){return a.clear(),d=0,s(t)}async function T(t){a.clear(),d=0;let r=s(t);for(;a.size>0;){console.log(`🔄 Resolving ${a.size} async components in parallel...`);const o=Array.from(a.entries());a.clear();const e=await Promise.allSettled(o.map(([n,{promise:i}])=>i));for(let n=0;n<o.length;n++){const i=o[n];if(!i)continue;const[l,{componentName:c,errorFallback:u}]=i,p=e[n];if(!p)continue;const y=h(l,c);if(p.status==="fulfilled")try{console.log(`✅ Resolved: ${c} (${l})`);const f=s(p.value);r=r.replace(y,f)}catch(f){console.error(`❌ Error rendering ${c}:`,f);const S=u?s(typeof u=="function"?u(f):u):`<div class="error">Error rendering ${c}</div>`;r=r.replace(y,S)}else{console.error(`❌ Error resolving ${c}:`,p.reason);const f=u?s(typeof u=="function"?u(p.reason):u):`<div class="error">Error loading ${c}</div>`;r=r.replace(y,f)}}}return console.log("✅ All async components resolved!"),r}async function*P(t){for(a.clear(),d=0,yield s(t);a.size>0;){const o=Array.from(a.entries());a.clear();const e=o.map(async([n,{promise:i}])=>{try{const l=await i,c=s(l);return`<script>
11
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("node:fs/promises"),m=require("node:path");function A(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 v=new Set(["area","base","br","col","embed","hr","img","input","link","meta","source","track","wbr"]);function E(r){return/^on[A-Z]/.test(r)}function j(r){return Object.entries(r).map(([t,o])=>`${t.replace(/[A-Z]/g,n=>`-${n.toLowerCase()}`)}:${o}`).join(";")}function w(r,t=!0){const o=Object.entries(r).filter(([e,n])=>!(n==null||t&&e==="children"||E(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 $(r){return r?Array.isArray(r)?r:[r]:[]}function D(r){return r&&typeof r.then=="function"}function h(r,t){return`<div id="${r}" data-server-component="suspended" data-component-name="${t}">Loading...</div>`}const a=new Map;let d=0;function H(r){return a.clear(),d=0,s(r)}async function T(r){a.clear(),d=0;let t=s(r);for(;a.size>0;){console.log(`🔄 Resolving ${a.size} async components in parallel...`);const o=Array.from(a.entries());a.clear();const e=await Promise.allSettled(o.map(([n,{promise:i}])=>i));for(let n=0;n<o.length;n++){const i=o[n];if(!i)continue;const[l,{componentName:c,errorFallback:u}]=i,p=e[n];if(!p)continue;const y=h(l,c);if(p.status==="fulfilled")try{console.log(`✅ Resolved: ${c} (${l})`);const f=s(p.value);t=t.replace(y,f)}catch(f){console.error(`❌ Error rendering ${c}:`,f);const S=u?s(typeof u=="function"?u(f):u):`<div class="error">Error rendering ${c}</div>`;t=t.replace(y,S)}else{console.error(`❌ Error resolving ${c}:`,p.reason);const f=u?s(typeof u=="function"?u(p.reason):u):`<div class="error">Error loading ${c}</div>`;t=t.replace(y,f)}}}return console.log("✅ All async components resolved!"),t}async function*P(r){for(a.clear(),d=0,yield s(r);a.size>0;){const o=Array.from(a.entries());a.clear();const e=o.map(async([n,{promise:i}])=>{try{const l=await i,c=s(l);return`<script>
12
12
  (function() {
13
13
  const el = document.getElementById('${n}');
14
14
  if (el) {
@@ -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 s(t){if(typeof t=="function"){const e=t();return Array.isArray(e)?`<!--reactive-list-->${e.map(i=>s(i)).join("")}`:s(e)}if(typeof t=="string")return b(t);if(typeof t=="number")return String(t);if(!t||typeof t!="object")return"";const{type:r,props:o}=t;if(r===Symbol.for("jsx.fragment"))return $(o.children).map(n=>s(n)).join("");if(typeof r=="string"&&r==="suspended"){const e=t,n=`async-${d++}`;return console.log(`⏳ Suspending: ${e._componentName} (${n})`),a.set(n,{id:n,promise:e.promise,componentName:e._componentName,errorFallback:e.errorFallback}),h(n,e._componentName)}if(typeof r=="function"){const e=r(o);if(j(e)){const n=`async-${d++}`,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} (${n})`),a.set(n,{id:n,promise:e,componentName:i}),h(n,i)}return s(e)}if(typeof r=="string"){const e=D(o);if(v.has(r))return`<${r}${e} />`;const i=$(o.children).map(l=>{if(Array.isArray(l))return l.map(c=>s(c)).join("");if(typeof l=="function"){const c=l();return Array.isArray(c)?`<!--reactive-list-->${c.map(p=>s(p)).join("")}`:`<!--reactive-->${s(c)}`}return s(l)}).join("");return r==="html"?`<!DOCTYPE html>
27
- <html${e}>${i}</html>`:`<${r}${e}>${i}</${r}>`}return""}class C{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 g.mkdir(m.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 g.rm(this.cacheDir,{recursive:!0,force:!0}),await g.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===""?m.join(this.cacheDir,"index.html"):m.join(this.cacheDir,o,"index.html");{const e=o===""?"index.html":`${o.replace(/\//g,"-")}.html`;return m.join(this.cacheDir,e)}}}exports.PreRenderer=C;exports.renderToStream=P;exports.renderToString=H;exports.renderToStringAsync=T;
25
+ <\/script>`}});for(const n of e)yield await n}}function s(r){if(typeof r=="function"){const e=r();return Array.isArray(e)?`<!--reactive-list-->${e.map(i=>s(i)).join("")}`:s(e)}if(typeof r=="string")return A(r);if(typeof r=="number")return String(r);if(Array.isArray(r))return r.map(e=>s(e)).join("");if(!r||typeof r!="object")return"";const{type:t,props:o}=r;if(t===Symbol.for("jsx.fragment"))return $(o.children).map(n=>s(n)).join("");if(typeof t=="string"&&t==="suspended"){const e=r,n=`async-${d++}`;return console.log(`⏳ Suspending: ${e._componentName} (${n})`),a.set(n,{id:n,promise:e.promise,componentName:e._componentName,errorFallback:e.errorFallback}),h(n,e._componentName)}if(typeof t=="function"){const e=t(o);if(D(e)){const n=`async-${d++}`,i=t.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} (${n})`),a.set(n,{id:n,promise:e,componentName:i}),h(n,i)}return s(e)}if(typeof t=="string"){const e=w(o);if(v.has(t))return`<${t}${e} />`;const i=$(o.children).map(l=>{if(Array.isArray(l))return l.map(c=>s(c)).join("");if(typeof l=="function"){const c=l();return Array.isArray(c)?`<!--reactive-list-->${c.map(p=>s(p)).join("")}`:`<!--reactive-->${s(c)}`}return s(l)}).join("");return t==="html"?`<!DOCTYPE html>
27
+ <html${e}>${i}</html>`:`<${t}${e}>${i}</${t}>`}return""}class C{cacheDir;useDirectoryStructure;constructor(t={}){this.cacheDir=t.cacheDir||"./cache/html",this.useDirectoryStructure=t.useDirectoryStructure??!1}async save(t,o){const e=this.getFilepath(t);return await g.mkdir(m.dirname(e),{recursive:!0}),await Bun.write(e,o),console.log(`✅ Pre-rendered: ${t} → ${e}`),e}async load(t){const o=this.getFilepath(t),e=Bun.file(o);return await e.exists()?e:null}async clear(){await g.rm(this.cacheDir,{recursive:!0,force:!0}),await g.mkdir(this.cacheDir,{recursive:!0}),console.log("🗑️ Cache cleared")}async exists(t){const o=this.getFilepath(t);return await Bun.file(o).exists()}getFilepath(t){const o=t.replace(/^\/+|\/+$/g,"");if(this.useDirectoryStructure)return o===""?m.join(this.cacheDir,"index.html"):m.join(this.cacheDir,o,"index.html");{const e=o===""?"index.html":`${o.replace(/\//g,"-")}.html`;return m.join(this.cacheDir,e)}}}exports.PreRenderer=C;exports.renderToStream=P;exports.renderToString=H;exports.renderToStringAsync=T;
package/dist/server.js CHANGED
@@ -8,13 +8,13 @@
8
8
  * See LICENSE file for full terms.
9
9
  */
10
10
 
11
- import { mkdir as h, rm as A } from "node:fs/promises";
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(t) {
14
- return t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
13
+ function v(r) {
14
+ return r.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
15
15
  }
16
- function E(t) {
17
- return t.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
16
+ function E(r) {
17
+ return r.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
18
18
  }
19
19
  const w = /* @__PURE__ */ new Set([
20
20
  "area",
@@ -31,33 +31,33 @@ const w = /* @__PURE__ */ new Set([
31
31
  "track",
32
32
  "wbr"
33
33
  ]);
34
- function D(t) {
35
- return /^on[A-Z]/.test(t);
34
+ function D(r) {
35
+ return /^on[A-Z]/.test(r);
36
36
  }
37
- function H(t) {
38
- return Object.entries(t).map(([r, o]) => `${r.replace(/[A-Z]/g, (n) => `-${n.toLowerCase()}`)}:${o}`).join(";");
37
+ function H(r) {
38
+ return Object.entries(r).map(([t, o]) => `${t.replace(/[A-Z]/g, (n) => `-${n.toLowerCase()}`)}:${o}`).join(";");
39
39
  }
40
- function j(t, r = !0) {
41
- const o = Object.entries(t).filter(([e, n]) => !(n == null || r && 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(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(" ");
42
42
  return o ? ` ${o}` : "";
43
43
  }
44
- function $(t) {
45
- return t ? Array.isArray(t) ? t : [t] : [];
44
+ function $(r) {
45
+ return r ? Array.isArray(r) ? r : [r] : [];
46
46
  }
47
- function P(t) {
48
- return t && typeof t.then == "function";
47
+ function P(r) {
48
+ return r && typeof r.then == "function";
49
49
  }
50
- function g(t, r) {
51
- return `<div id="${t}" data-server-component="suspended" data-component-name="${r}">Loading...</div>`;
50
+ function g(r, t) {
51
+ return `<div id="${r}" data-server-component="suspended" data-component-name="${t}">Loading...</div>`;
52
52
  }
53
53
  const a = /* @__PURE__ */ new Map();
54
54
  let d = 0;
55
- function N(t) {
56
- return a.clear(), d = 0, s(t);
55
+ function N(r) {
56
+ return a.clear(), d = 0, s(r);
57
57
  }
58
- async function T(t) {
58
+ async function T(r) {
59
59
  a.clear(), d = 0;
60
- let r = s(t);
60
+ let t = s(r);
61
61
  for (; a.size > 0; ) {
62
62
  console.log(
63
63
  `🔄 Resolving ${a.size} async components in parallel...`
@@ -77,27 +77,27 @@ async function T(t) {
77
77
  try {
78
78
  console.log(`✅ Resolved: ${c} (${l})`);
79
79
  const f = s(p.value);
80
- r = r.replace(m, f);
80
+ t = t.replace(m, f);
81
81
  } catch (f) {
82
82
  console.error(`❌ Error rendering ${c}:`, f);
83
- const S = u ? s(
83
+ const A = u ? s(
84
84
  typeof u == "function" ? u(f) : u
85
85
  ) : `<div class="error">Error rendering ${c}</div>`;
86
- r = r.replace(m, S);
86
+ t = t.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
- r = r.replace(m, f);
93
+ t = t.replace(m, f);
94
94
  }
95
95
  }
96
96
  }
97
- return console.log("✅ All async components resolved!"), r;
97
+ return console.log("✅ All async components resolved!"), t;
98
98
  }
99
- async function* F(t) {
100
- for (a.clear(), d = 0, yield s(t); a.size > 0; ) {
99
+ async function* F(r) {
100
+ for (a.clear(), d = 0, yield s(r); a.size > 0; ) {
101
101
  const o = Array.from(a.entries());
102
102
  a.clear();
103
103
  const e = o.map(
@@ -128,22 +128,24 @@ async function* F(t) {
128
128
  yield await n;
129
129
  }
130
130
  }
131
- function s(t) {
132
- if (typeof t == "function") {
133
- const e = t();
131
+ function s(r) {
132
+ if (typeof r == "function") {
133
+ const e = r();
134
134
  return Array.isArray(e) ? `<!--reactive-list-->${e.map((i) => s(i)).join("")}` : s(e);
135
135
  }
136
- if (typeof t == "string")
137
- return v(t);
138
- if (typeof t == "number")
139
- return String(t);
140
- if (!t || typeof t != "object")
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")
141
143
  return "";
142
- const { type: r, props: o } = t;
143
- if (r === Symbol.for("jsx.fragment"))
144
+ const { type: t, props: o } = r;
145
+ if (t === Symbol.for("jsx.fragment"))
144
146
  return $(o.children).map((n) => s(n)).join("");
145
- if (typeof r == "string" && r === "suspended") {
146
- const e = t, n = `async-${d++}`;
147
+ if (typeof t == "string" && t === "suspended") {
148
+ const e = r, n = `async-${d++}`;
147
149
  return console.log(
148
150
  `⏳ Suspending: ${e._componentName} (${n})`
149
151
  ), a.set(n, {
@@ -154,10 +156,10 @@ function s(t) {
154
156
  // Store custom error fallback
155
157
  }), g(n, e._componentName);
156
158
  }
157
- if (typeof r == "function") {
158
- const e = r(o);
159
+ if (typeof t == "function") {
160
+ const e = t(o);
159
161
  if (P(e)) {
160
- const n = `async-${d++}`, i = r.name || "AsyncComponent";
162
+ const n = `async-${d++}`, i = t.name || "AsyncComponent";
161
163
  return console.warn(
162
164
  `⚠️ DEPRECATED: Direct async component "${i}" detected. Please use suspend() HOF instead for better type safety and custom fallbacks.
163
165
  Example: const ${i} = suspend(async (props) => { ... }, <Loading />, <Error />);`
@@ -169,10 +171,10 @@ Example: const ${i} = suspend(async (props) => { ... }, <Loading />, <Error />);
169
171
  }
170
172
  return s(e);
171
173
  }
172
- if (typeof r == "string") {
174
+ if (typeof t == "string") {
173
175
  const e = j(o);
174
- if (w.has(r))
175
- return `<${r}${e} />`;
176
+ if (w.has(t))
177
+ return `<${t}${e} />`;
176
178
  const i = $(o.children).map((l) => {
177
179
  if (Array.isArray(l))
178
180
  return l.map((c) => s(c)).join("");
@@ -182,34 +184,34 @@ Example: const ${i} = suspend(async (props) => { ... }, <Loading />, <Error />);
182
184
  }
183
185
  return s(l);
184
186
  }).join("");
185
- return r === "html" ? `<!DOCTYPE html>
186
- <html${e}>${i}</html>` : `<${r}${e}>${i}</${r}>`;
187
+ return t === "html" ? `<!DOCTYPE html>
188
+ <html${e}>${i}</html>` : `<${t}${e}>${i}</${t}>`;
187
189
  }
188
190
  return "";
189
191
  }
190
192
  class z {
191
193
  cacheDir;
192
194
  useDirectoryStructure;
193
- constructor(r = {}) {
194
- this.cacheDir = r.cacheDir || "./cache/html", this.useDirectoryStructure = r.useDirectoryStructure ?? !1;
195
+ constructor(t = {}) {
196
+ this.cacheDir = t.cacheDir || "./cache/html", this.useDirectoryStructure = t.useDirectoryStructure ?? !1;
195
197
  }
196
- async save(r, o) {
197
- const e = this.getFilepath(r);
198
- return await h(b(e), { recursive: !0 }), await Bun.write(e, o), console.log(`✅ Pre-rendered: ${r} → ${e}`), e;
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;
199
201
  }
200
- async load(r) {
201
- const o = this.getFilepath(r), e = Bun.file(o);
202
+ async load(t) {
203
+ const o = this.getFilepath(t), e = Bun.file(o);
202
204
  return await e.exists() ? e : null;
203
205
  }
204
206
  async clear() {
205
- await A(this.cacheDir, { recursive: !0, force: !0 }), await h(this.cacheDir, { recursive: !0 }), console.log("🗑️ Cache cleared");
207
+ await S(this.cacheDir, { recursive: !0, force: !0 }), await h(this.cacheDir, { recursive: !0 }), console.log("🗑️ Cache cleared");
206
208
  }
207
- async exists(r) {
208
- const o = this.getFilepath(r);
209
+ async exists(t) {
210
+ const o = this.getFilepath(t);
209
211
  return await Bun.file(o).exists();
210
212
  }
211
- getFilepath(r) {
212
- const o = r.replace(/^\/+|\/+$/g, "");
213
+ getFilepath(t) {
214
+ const o = t.replace(/^\/+|\/+$/g, "");
213
215
  if (this.useDirectoryStructure)
214
216
  return o === "" ? y(this.cacheDir, "index.html") : y(this.cacheDir, o, "index.html");
215
217
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mateosuarezdev/flash",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "Custom jsx runtime",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",