@mateosuarezdev/flash 0.0.1
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/LICENSE.md +32 -0
- package/README.md +945 -0
- package/dist/debug.cjs +11 -0
- package/dist/debug.d.ts +195 -0
- package/dist/debug.js +28 -0
- package/dist/index.cjs +11 -0
- package/dist/index.d.ts +600 -0
- package/dist/index.js +1335 -0
- package/dist/jsx-dev-runtime-BfTCjShK.js +65 -0
- package/dist/jsx-dev-runtime-D4XANMVW.cjs +11 -0
- package/dist/jsx-dev-runtime.cjs +11 -0
- package/dist/jsx-dev-runtime.d.ts +90 -0
- package/dist/jsx-dev-runtime.js +17 -0
- package/dist/jsx-runtime.cjs +11 -0
- package/dist/jsx-runtime.d.ts +90 -0
- package/dist/jsx-runtime.js +17 -0
- package/dist/server.cjs +27 -0
- package/dist/server.d.ts +60 -0
- package/dist/server.js +224 -0
- package/dist/utils.cjs +11 -0
- package/dist/utils.d.ts +13 -0
- package/dist/utils.js +18 -0
- package/package.json +123 -0
|
@@ -0,0 +1,65 @@
|
|
|
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 o = 0;
|
|
12
|
+
const r = () => o++;
|
|
13
|
+
let l = null;
|
|
14
|
+
function d(n) {
|
|
15
|
+
l = n;
|
|
16
|
+
}
|
|
17
|
+
function u() {
|
|
18
|
+
return l;
|
|
19
|
+
}
|
|
20
|
+
function i(n, e, t) {
|
|
21
|
+
return {
|
|
22
|
+
type: n,
|
|
23
|
+
kind: "VNode",
|
|
24
|
+
props: e,
|
|
25
|
+
key: t,
|
|
26
|
+
children: e.children,
|
|
27
|
+
_id: r(),
|
|
28
|
+
_onMountCallbacks: [],
|
|
29
|
+
_onUnmountCallbacks: [],
|
|
30
|
+
_onBeforeExitCallbacks: [],
|
|
31
|
+
_element: null,
|
|
32
|
+
_parent: null,
|
|
33
|
+
_renderedChildren: [],
|
|
34
|
+
_lifecycleState: "mounting"
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function c(n, e, t) {
|
|
38
|
+
return {
|
|
39
|
+
type: n,
|
|
40
|
+
kind: "IntrinsicVNode",
|
|
41
|
+
props: e,
|
|
42
|
+
key: t,
|
|
43
|
+
_id: r(),
|
|
44
|
+
_dom: void 0,
|
|
45
|
+
// DOM created lazily during render
|
|
46
|
+
_parent: null,
|
|
47
|
+
_renderedChildren: [],
|
|
48
|
+
_onMountCallbacks: [],
|
|
49
|
+
_onUnmountCallbacks: [],
|
|
50
|
+
_onBeforeExitCallbacks: [],
|
|
51
|
+
_lifecycleState: "mounting"
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const a = Symbol("fragment");
|
|
55
|
+
function s(n, e, t) {
|
|
56
|
+
return n === a ? e?.children : typeof n == "function" ? i(n, e ?? {}, t) : c(n, e ?? {}, t);
|
|
57
|
+
}
|
|
58
|
+
export {
|
|
59
|
+
a as F,
|
|
60
|
+
l as c,
|
|
61
|
+
u as g,
|
|
62
|
+
s as j,
|
|
63
|
+
r as n,
|
|
64
|
+
d as s
|
|
65
|
+
};
|
|
@@ -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 d=0;const r=()=>d++;exports.currentVNode=null;function l(n){exports.currentVNode=n}function u(){return exports.currentVNode}function c(n,e,t){return{type:n,kind:"VNode",props:e,key:t,children:e.children,_id:r(),_onMountCallbacks:[],_onUnmountCallbacks:[],_onBeforeExitCallbacks:[],_element:null,_parent:null,_renderedChildren:[],_lifecycleState:"mounting"}}function i(n,e,t){return{type:n,kind:"IntrinsicVNode",props:e,key:t,_id:r(),_dom:void 0,_parent:null,_renderedChildren:[],_onMountCallbacks:[],_onUnmountCallbacks:[],_onBeforeExitCallbacks:[],_lifecycleState:"mounting"}}const o=Symbol("fragment");function a(n,e,t){return n===o?e?.children:typeof n=="function"?c(n,e??{},t):i(n,e??{},t)}exports.Fragment=o;exports.getCurrentVNode=u;exports.jsx=a;exports.newVNodeId=r;exports.setCurrentVNode=l;
|
|
@@ -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";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./jsx-dev-runtime-D4XANMVW.cjs");exports.Fragment=e.Fragment;exports.jsx=e.jsx;exports.jsxDEV=e.jsx;exports.jsxs=e.jsx;
|
|
@@ -0,0 +1,90 @@
|
|
|
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
|
+
declare class CancelToken {
|
|
12
|
+
private _cancelled;
|
|
13
|
+
private _cancelCallbacks;
|
|
14
|
+
get cancelled(): boolean;
|
|
15
|
+
cancel(): void;
|
|
16
|
+
onCancel(callback: () => void): void;
|
|
17
|
+
throwIfCancelled(): void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
declare type Child = IntrinsicVNode | VNode | ReactiveVNode | Text | string | number | boolean | null | undefined | (() => Child);
|
|
21
|
+
|
|
22
|
+
declare type Children = Child | Children[];
|
|
23
|
+
|
|
24
|
+
declare type ComponentFunction<P = Props> = (props: P) => Child;
|
|
25
|
+
|
|
26
|
+
export declare const Fragment: unique symbol;
|
|
27
|
+
|
|
28
|
+
declare interface IntrinsicVNode {
|
|
29
|
+
type: string;
|
|
30
|
+
kind: "IntrinsicVNode";
|
|
31
|
+
props: Props;
|
|
32
|
+
key?: Key;
|
|
33
|
+
_id: number;
|
|
34
|
+
_dom?: HTMLElement | SVGElement;
|
|
35
|
+
_parent: VNode | ReactiveVNode | IntrinsicVNode | null;
|
|
36
|
+
_renderedChildren: (VNode | ReactiveVNode | IntrinsicVNode)[];
|
|
37
|
+
_onMountCallbacks: (() => void)[];
|
|
38
|
+
_onUnmountCallbacks: (() => void)[];
|
|
39
|
+
_onBeforeExitCallbacks: ((token: CancelToken) => void | Promise<void>)[];
|
|
40
|
+
_lifecycleState?: "mounting" | "mounted" | "exiting" | "exited";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
declare function jsx(type: string | ComponentFunction | symbol, props: Props | null, key: string): Children;
|
|
44
|
+
export { jsx }
|
|
45
|
+
export { jsx as jsxDEV }
|
|
46
|
+
export { jsx as jsxs }
|
|
47
|
+
|
|
48
|
+
declare type Key = string | number;
|
|
49
|
+
|
|
50
|
+
declare interface Props {
|
|
51
|
+
children?: Children;
|
|
52
|
+
ref?: (element: HTMLElement | SVGElement) => void;
|
|
53
|
+
key?: string | number;
|
|
54
|
+
[key: string]: any;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
declare interface ReactiveVNode {
|
|
58
|
+
type: "reactive";
|
|
59
|
+
kind: "ReactiveVNode";
|
|
60
|
+
fn: () => Child;
|
|
61
|
+
_id: number;
|
|
62
|
+
_dispose: VoidFunction | null;
|
|
63
|
+
_currentChild: VNode | IntrinsicVNode | ReactiveVNode | null;
|
|
64
|
+
_currentDom: Node | null;
|
|
65
|
+
_placeholder: Comment | null;
|
|
66
|
+
_parent: VNode | ReactiveVNode | IntrinsicVNode | null;
|
|
67
|
+
_renderedChildren: (VNode | ReactiveVNode | IntrinsicVNode)[];
|
|
68
|
+
_listState?: {
|
|
69
|
+
items: any[];
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
declare interface VNode {
|
|
74
|
+
type: ComponentFunction;
|
|
75
|
+
kind: "VNode";
|
|
76
|
+
props: Props;
|
|
77
|
+
children: Children;
|
|
78
|
+
key?: Key;
|
|
79
|
+
_id: number;
|
|
80
|
+
_onMountCallbacks: (() => void)[];
|
|
81
|
+
_onUnmountCallbacks: (() => void)[];
|
|
82
|
+
_onBeforeExitCallbacks: ((token: CancelToken) => void | Promise<void>)[];
|
|
83
|
+
_element: Node | null;
|
|
84
|
+
_parent: VNode | ReactiveVNode | IntrinsicVNode | null;
|
|
85
|
+
_renderedChildren: (VNode | ReactiveVNode | IntrinsicVNode)[];
|
|
86
|
+
_lifecycleState?: "mounting" | "mounted" | "exiting" | "exited";
|
|
87
|
+
_contextMap?: Map<Symbol, any>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { }
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
import { F as a, j as x, j as r, j as e } from "./jsx-dev-runtime-BfTCjShK.js";
|
|
12
|
+
export {
|
|
13
|
+
a as Fragment,
|
|
14
|
+
x as jsx,
|
|
15
|
+
r as jsxDEV,
|
|
16
|
+
e as jsxs
|
|
17
|
+
};
|
|
@@ -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";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./jsx-dev-runtime-D4XANMVW.cjs");exports.Fragment=e.Fragment;exports.jsx=e.jsx;exports.jsxDEV=e.jsx;exports.jsxs=e.jsx;
|
|
@@ -0,0 +1,90 @@
|
|
|
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
|
+
declare class CancelToken {
|
|
12
|
+
private _cancelled;
|
|
13
|
+
private _cancelCallbacks;
|
|
14
|
+
get cancelled(): boolean;
|
|
15
|
+
cancel(): void;
|
|
16
|
+
onCancel(callback: () => void): void;
|
|
17
|
+
throwIfCancelled(): void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
declare type Child = IntrinsicVNode | VNode | ReactiveVNode | Text | string | number | boolean | null | undefined | (() => Child);
|
|
21
|
+
|
|
22
|
+
declare type Children = Child | Children[];
|
|
23
|
+
|
|
24
|
+
declare type ComponentFunction<P = Props> = (props: P) => Child;
|
|
25
|
+
|
|
26
|
+
export declare const Fragment: unique symbol;
|
|
27
|
+
|
|
28
|
+
declare interface IntrinsicVNode {
|
|
29
|
+
type: string;
|
|
30
|
+
kind: "IntrinsicVNode";
|
|
31
|
+
props: Props;
|
|
32
|
+
key?: Key;
|
|
33
|
+
_id: number;
|
|
34
|
+
_dom?: HTMLElement | SVGElement;
|
|
35
|
+
_parent: VNode | ReactiveVNode | IntrinsicVNode | null;
|
|
36
|
+
_renderedChildren: (VNode | ReactiveVNode | IntrinsicVNode)[];
|
|
37
|
+
_onMountCallbacks: (() => void)[];
|
|
38
|
+
_onUnmountCallbacks: (() => void)[];
|
|
39
|
+
_onBeforeExitCallbacks: ((token: CancelToken) => void | Promise<void>)[];
|
|
40
|
+
_lifecycleState?: "mounting" | "mounted" | "exiting" | "exited";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
declare function jsx(type: string | ComponentFunction | symbol, props: Props | null, key: string): Children;
|
|
44
|
+
export { jsx }
|
|
45
|
+
export { jsx as jsxDEV }
|
|
46
|
+
export { jsx as jsxs }
|
|
47
|
+
|
|
48
|
+
declare type Key = string | number;
|
|
49
|
+
|
|
50
|
+
declare interface Props {
|
|
51
|
+
children?: Children;
|
|
52
|
+
ref?: (element: HTMLElement | SVGElement) => void;
|
|
53
|
+
key?: string | number;
|
|
54
|
+
[key: string]: any;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
declare interface ReactiveVNode {
|
|
58
|
+
type: "reactive";
|
|
59
|
+
kind: "ReactiveVNode";
|
|
60
|
+
fn: () => Child;
|
|
61
|
+
_id: number;
|
|
62
|
+
_dispose: VoidFunction | null;
|
|
63
|
+
_currentChild: VNode | IntrinsicVNode | ReactiveVNode | null;
|
|
64
|
+
_currentDom: Node | null;
|
|
65
|
+
_placeholder: Comment | null;
|
|
66
|
+
_parent: VNode | ReactiveVNode | IntrinsicVNode | null;
|
|
67
|
+
_renderedChildren: (VNode | ReactiveVNode | IntrinsicVNode)[];
|
|
68
|
+
_listState?: {
|
|
69
|
+
items: any[];
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
declare interface VNode {
|
|
74
|
+
type: ComponentFunction;
|
|
75
|
+
kind: "VNode";
|
|
76
|
+
props: Props;
|
|
77
|
+
children: Children;
|
|
78
|
+
key?: Key;
|
|
79
|
+
_id: number;
|
|
80
|
+
_onMountCallbacks: (() => void)[];
|
|
81
|
+
_onUnmountCallbacks: (() => void)[];
|
|
82
|
+
_onBeforeExitCallbacks: ((token: CancelToken) => void | Promise<void>)[];
|
|
83
|
+
_element: Node | null;
|
|
84
|
+
_parent: VNode | ReactiveVNode | IntrinsicVNode | null;
|
|
85
|
+
_renderedChildren: (VNode | ReactiveVNode | IntrinsicVNode)[];
|
|
86
|
+
_lifecycleState?: "mounting" | "mounted" | "exiting" | "exited";
|
|
87
|
+
_contextMap?: Map<Symbol, any>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { }
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
import { F as a, j as x, j as r, j as e } from "./jsx-dev-runtime-BfTCjShK.js";
|
|
12
|
+
export {
|
|
13
|
+
a as Fragment,
|
|
14
|
+
x as jsx,
|
|
15
|
+
r as jsxDEV,
|
|
16
|
+
e as jsxs
|
|
17
|
+
};
|
package/dist/server.cjs
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
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";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("node:fs/promises"),m=require("node:path");function b(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function v(t){return t.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}const A=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}="${v(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 f=0;function H(t){return a.clear(),f=0,s(t)}async function T(t){a.clear(),f=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 d=s(p.value);r=r.replace(y,d)}catch(d){console.error(`❌ Error rendering ${c}:`,d);const S=u?s(typeof u=="function"?u(d):u):`<div class="error">Error rendering ${c}</div>`;r=r.replace(y,S)}else{console.error(`❌ Error resolving ${c}:`,p.reason);const d=u?s(typeof u=="function"?u(p.reason):u):`<div class="error">Error loading ${c}</div>`;r=r.replace(y,d)}}}return console.log("✅ All async components resolved!"),r}async function*P(t){for(a.clear(),f=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>
|
|
12
|
+
(function() {
|
|
13
|
+
const el = document.getElementById('${n}');
|
|
14
|
+
if (el) {
|
|
15
|
+
el.outerHTML = \`${c.replace(/`/g,"\\`").replace(/\$/g,"\\$")}\`;
|
|
16
|
+
}
|
|
17
|
+
})();
|
|
18
|
+
<\/script>`}catch{return`<script>
|
|
19
|
+
(function() {
|
|
20
|
+
const el = document.getElementById('${n}');
|
|
21
|
+
if (el) {
|
|
22
|
+
el.innerHTML = '<div class="error">Error loading component</div>';
|
|
23
|
+
}
|
|
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-${f++}`;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-${f++}`,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(A.has(r))return`<${r}${e} />`;const i=$(o.children).map(l=>{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;
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
/**
|
|
12
|
+
* Usage
|
|
13
|
+
* const prerenderer = new PreRenderer()
|
|
14
|
+
*/
|
|
15
|
+
export declare class PreRenderer {
|
|
16
|
+
private cacheDir;
|
|
17
|
+
private useDirectoryStructure;
|
|
18
|
+
constructor(options?: PreRenderOptions);
|
|
19
|
+
save(pathname: string, html: string): Promise<string>;
|
|
20
|
+
load(pathname: string): Promise<Bun.BunFile | null>;
|
|
21
|
+
clear(): Promise<void>;
|
|
22
|
+
exists(pathname: string): Promise<boolean>;
|
|
23
|
+
private getFilepath;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
declare interface PreRenderOptions {
|
|
27
|
+
cacheDir?: string;
|
|
28
|
+
useDirectoryStructure?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 3. renderToStream - Stream HTML with placeholders, then stream updates
|
|
33
|
+
* Use for: Dynamic content, personalized pages, better perceived performance
|
|
34
|
+
*/
|
|
35
|
+
export declare function renderToStream(element: ServerChildren): AsyncGenerator<string>;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 1. renderToString - Synchronous only (no async support)
|
|
39
|
+
* Use for: Pure sync components, or client first
|
|
40
|
+
*/
|
|
41
|
+
export declare function renderToString(element: ServerChildren): string;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 2. renderToStringAsync - Wait for all async components, then return complete HTML
|
|
45
|
+
* Use for: Pre-rendering, caching, SSG, SEO
|
|
46
|
+
*/
|
|
47
|
+
export declare function renderToStringAsync(element: ServerChildren): Promise<string>;
|
|
48
|
+
|
|
49
|
+
declare type ServerChildren = ServerJSXElement | string | number | (() => ServerChildren);
|
|
50
|
+
|
|
51
|
+
declare interface ServerJSXElement {
|
|
52
|
+
type: string | Function | symbol;
|
|
53
|
+
props: {
|
|
54
|
+
children?: ServerChildren[];
|
|
55
|
+
[key: string]: any;
|
|
56
|
+
};
|
|
57
|
+
key?: string | number;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { }
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
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
|
+
import { mkdir as g, rm as b } from "node:fs/promises";
|
|
12
|
+
import { dirname as v, join as y } from "node:path";
|
|
13
|
+
function A(t) {
|
|
14
|
+
return t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
15
|
+
}
|
|
16
|
+
function E(t) {
|
|
17
|
+
return t.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
18
|
+
}
|
|
19
|
+
const w = /* @__PURE__ */ new Set([
|
|
20
|
+
"area",
|
|
21
|
+
"base",
|
|
22
|
+
"br",
|
|
23
|
+
"col",
|
|
24
|
+
"embed",
|
|
25
|
+
"hr",
|
|
26
|
+
"img",
|
|
27
|
+
"input",
|
|
28
|
+
"link",
|
|
29
|
+
"meta",
|
|
30
|
+
"source",
|
|
31
|
+
"track",
|
|
32
|
+
"wbr"
|
|
33
|
+
]);
|
|
34
|
+
function D(t) {
|
|
35
|
+
return /^on[A-Z]/.test(t);
|
|
36
|
+
}
|
|
37
|
+
function H(t) {
|
|
38
|
+
return Object.entries(t).map(([r, o]) => `${r.replace(/[A-Z]/g, (n) => `-${n.toLowerCase()}`)}:${o}`).join(";");
|
|
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(" ");
|
|
42
|
+
return o ? ` ${o}` : "";
|
|
43
|
+
}
|
|
44
|
+
function $(t) {
|
|
45
|
+
return t ? Array.isArray(t) ? t : [t] : [];
|
|
46
|
+
}
|
|
47
|
+
function P(t) {
|
|
48
|
+
return t && typeof t.then == "function";
|
|
49
|
+
}
|
|
50
|
+
function h(t, r) {
|
|
51
|
+
return `<div id="${t}" data-server-component="suspended" data-component-name="${r}">Loading...</div>`;
|
|
52
|
+
}
|
|
53
|
+
const a = /* @__PURE__ */ new Map();
|
|
54
|
+
let d = 0;
|
|
55
|
+
function N(t) {
|
|
56
|
+
return a.clear(), d = 0, c(t);
|
|
57
|
+
}
|
|
58
|
+
async function T(t) {
|
|
59
|
+
a.clear(), d = 0;
|
|
60
|
+
let r = c(t);
|
|
61
|
+
for (; a.size > 0; ) {
|
|
62
|
+
console.log(
|
|
63
|
+
`🔄 Resolving ${a.size} async components in parallel...`
|
|
64
|
+
);
|
|
65
|
+
const o = Array.from(a.entries());
|
|
66
|
+
a.clear();
|
|
67
|
+
const e = await Promise.allSettled(
|
|
68
|
+
o.map(([n, { promise: i }]) => i)
|
|
69
|
+
);
|
|
70
|
+
for (let n = 0; n < o.length; n++) {
|
|
71
|
+
const i = o[n];
|
|
72
|
+
if (!i) continue;
|
|
73
|
+
const [l, { componentName: s, errorFallback: u }] = i, p = e[n];
|
|
74
|
+
if (!p) continue;
|
|
75
|
+
const m = h(l, s);
|
|
76
|
+
if (p.status === "fulfilled")
|
|
77
|
+
try {
|
|
78
|
+
console.log(`✅ Resolved: ${s} (${l})`);
|
|
79
|
+
const f = c(p.value);
|
|
80
|
+
r = r.replace(m, f);
|
|
81
|
+
} catch (f) {
|
|
82
|
+
console.error(`❌ Error rendering ${s}:`, f);
|
|
83
|
+
const S = u ? c(
|
|
84
|
+
typeof u == "function" ? u(f) : u
|
|
85
|
+
) : `<div class="error">Error rendering ${s}</div>`;
|
|
86
|
+
r = r.replace(m, S);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
console.error(`❌ Error resolving ${s}:`, p.reason);
|
|
90
|
+
const f = u ? c(
|
|
91
|
+
typeof u == "function" ? u(p.reason) : u
|
|
92
|
+
) : `<div class="error">Error loading ${s}</div>`;
|
|
93
|
+
r = r.replace(m, f);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return console.log("✅ All async components resolved!"), r;
|
|
98
|
+
}
|
|
99
|
+
async function* F(t) {
|
|
100
|
+
for (a.clear(), d = 0, yield c(t); a.size > 0; ) {
|
|
101
|
+
const o = Array.from(a.entries());
|
|
102
|
+
a.clear();
|
|
103
|
+
const e = o.map(
|
|
104
|
+
async ([n, { promise: i }]) => {
|
|
105
|
+
try {
|
|
106
|
+
const l = await i, s = c(l);
|
|
107
|
+
return `<script>
|
|
108
|
+
(function() {
|
|
109
|
+
const el = document.getElementById('${n}');
|
|
110
|
+
if (el) {
|
|
111
|
+
el.outerHTML = \`${s.replace(/`/g, "\\`").replace(/\$/g, "\\$")}\`;
|
|
112
|
+
}
|
|
113
|
+
})();
|
|
114
|
+
<\/script>`;
|
|
115
|
+
} catch {
|
|
116
|
+
return `<script>
|
|
117
|
+
(function() {
|
|
118
|
+
const el = document.getElementById('${n}');
|
|
119
|
+
if (el) {
|
|
120
|
+
el.innerHTML = '<div class="error">Error loading component</div>';
|
|
121
|
+
}
|
|
122
|
+
})();
|
|
123
|
+
<\/script>`;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
);
|
|
127
|
+
for (const n of e)
|
|
128
|
+
yield await n;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function c(t) {
|
|
132
|
+
if (typeof t == "function") {
|
|
133
|
+
const e = t();
|
|
134
|
+
return Array.isArray(e) ? `<!--reactive-list-->${e.map((i) => c(i)).join("")}` : c(e);
|
|
135
|
+
}
|
|
136
|
+
if (typeof t == "string")
|
|
137
|
+
return A(t);
|
|
138
|
+
if (typeof t == "number")
|
|
139
|
+
return String(t);
|
|
140
|
+
if (!t || typeof t != "object")
|
|
141
|
+
return "";
|
|
142
|
+
const { type: r, props: o } = t;
|
|
143
|
+
if (r === Symbol.for("jsx.fragment"))
|
|
144
|
+
return $(o.children).map((n) => c(n)).join("");
|
|
145
|
+
if (typeof r == "string" && r === "suspended") {
|
|
146
|
+
const e = t, n = `async-${d++}`;
|
|
147
|
+
return console.log(
|
|
148
|
+
`⏳ Suspending: ${e._componentName} (${n})`
|
|
149
|
+
), a.set(n, {
|
|
150
|
+
id: n,
|
|
151
|
+
promise: e.promise,
|
|
152
|
+
componentName: e._componentName,
|
|
153
|
+
errorFallback: e.errorFallback
|
|
154
|
+
// Store custom error fallback
|
|
155
|
+
}), h(n, e._componentName);
|
|
156
|
+
}
|
|
157
|
+
if (typeof r == "function") {
|
|
158
|
+
const e = r(o);
|
|
159
|
+
if (P(e)) {
|
|
160
|
+
const n = `async-${d++}`, i = r.name || "AsyncComponent";
|
|
161
|
+
return console.warn(
|
|
162
|
+
`⚠️ DEPRECATED: Direct async component "${i}" detected. Please use suspend() HOF instead for better type safety and custom fallbacks.
|
|
163
|
+
Example: const ${i} = suspend(async (props) => { ... }, <Loading />, <Error />);`
|
|
164
|
+
), console.log(`⏳ Suspending: ${i} (${n})`), a.set(n, {
|
|
165
|
+
id: n,
|
|
166
|
+
promise: e,
|
|
167
|
+
componentName: i
|
|
168
|
+
}), h(n, i);
|
|
169
|
+
}
|
|
170
|
+
return c(e);
|
|
171
|
+
}
|
|
172
|
+
if (typeof r == "string") {
|
|
173
|
+
const e = j(o);
|
|
174
|
+
if (w.has(r))
|
|
175
|
+
return `<${r}${e} />`;
|
|
176
|
+
const i = $(o.children).map((l) => {
|
|
177
|
+
if (typeof l == "function") {
|
|
178
|
+
const s = l();
|
|
179
|
+
return Array.isArray(s) ? `<!--reactive-list-->${s.map((p) => c(p)).join("")}` : `<!--reactive-->${c(s)}`;
|
|
180
|
+
}
|
|
181
|
+
return c(l);
|
|
182
|
+
}).join("");
|
|
183
|
+
return r === "html" ? `<!DOCTYPE html>
|
|
184
|
+
<html${e}>${i}</html>` : `<${r}${e}>${i}</${r}>`;
|
|
185
|
+
}
|
|
186
|
+
return "";
|
|
187
|
+
}
|
|
188
|
+
class z {
|
|
189
|
+
cacheDir;
|
|
190
|
+
useDirectoryStructure;
|
|
191
|
+
constructor(r = {}) {
|
|
192
|
+
this.cacheDir = r.cacheDir || "./cache/html", this.useDirectoryStructure = r.useDirectoryStructure ?? !1;
|
|
193
|
+
}
|
|
194
|
+
async save(r, o) {
|
|
195
|
+
const e = this.getFilepath(r);
|
|
196
|
+
return await g(v(e), { recursive: !0 }), await Bun.write(e, o), console.log(`✅ Pre-rendered: ${r} → ${e}`), e;
|
|
197
|
+
}
|
|
198
|
+
async load(r) {
|
|
199
|
+
const o = this.getFilepath(r), e = Bun.file(o);
|
|
200
|
+
return await e.exists() ? e : null;
|
|
201
|
+
}
|
|
202
|
+
async clear() {
|
|
203
|
+
await b(this.cacheDir, { recursive: !0, force: !0 }), await g(this.cacheDir, { recursive: !0 }), console.log("🗑️ Cache cleared");
|
|
204
|
+
}
|
|
205
|
+
async exists(r) {
|
|
206
|
+
const o = this.getFilepath(r);
|
|
207
|
+
return await Bun.file(o).exists();
|
|
208
|
+
}
|
|
209
|
+
getFilepath(r) {
|
|
210
|
+
const o = r.replace(/^\/+|\/+$/g, "");
|
|
211
|
+
if (this.useDirectoryStructure)
|
|
212
|
+
return o === "" ? y(this.cacheDir, "index.html") : y(this.cacheDir, o, "index.html");
|
|
213
|
+
{
|
|
214
|
+
const e = o === "" ? "index.html" : `${o.replace(/\//g, "-")}.html`;
|
|
215
|
+
return y(this.cacheDir, e);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
export {
|
|
220
|
+
z as PreRenderer,
|
|
221
|
+
F as renderToStream,
|
|
222
|
+
N as renderToString,
|
|
223
|
+
T as renderToStringAsync
|
|
224
|
+
};
|
package/dist/utils.cjs
ADDED
|
@@ -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";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function o(e){return new Promise(t=>{setTimeout(t,e)})}exports.sleep=o;
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
export declare function sleep(ms: number): Promise<void>;
|
|
12
|
+
|
|
13
|
+
export { }
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
function n(e) {
|
|
12
|
+
return new Promise((t) => {
|
|
13
|
+
setTimeout(t, e);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
n as sleep
|
|
18
|
+
};
|