elit 3.0.0 → 3.0.2
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/build.d.ts +4 -12
- package/dist/build.d.ts.map +1 -0
- package/dist/chokidar.d.ts +7 -9
- package/dist/chokidar.d.ts.map +1 -0
- package/dist/cli.d.ts +6 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +17 -4
- package/dist/config.d.ts +29 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/dom.d.ts +7 -14
- package/dist/dom.d.ts.map +1 -0
- package/dist/el.d.ts +19 -191
- package/dist/el.d.ts.map +1 -0
- package/dist/fs.d.ts +35 -35
- package/dist/fs.d.ts.map +1 -0
- package/dist/hmr.d.ts +3 -3
- package/dist/hmr.d.ts.map +1 -0
- package/dist/http.d.ts +20 -22
- package/dist/http.d.ts.map +1 -0
- package/dist/https.d.ts +12 -15
- package/dist/https.d.ts.map +1 -0
- package/dist/index.d.ts +10 -629
- package/dist/index.d.ts.map +1 -0
- package/dist/mime-types.d.ts +9 -9
- package/dist/mime-types.d.ts.map +1 -0
- package/dist/path.d.ts +22 -19
- package/dist/path.d.ts.map +1 -0
- package/dist/router.d.ts +10 -17
- package/dist/router.d.ts.map +1 -0
- package/dist/runtime.d.ts +5 -6
- package/dist/runtime.d.ts.map +1 -0
- package/dist/server.d.ts +105 -7
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +14 -2
- package/dist/server.mjs +14 -2
- package/dist/state.d.ts +21 -27
- package/dist/state.d.ts.map +1 -0
- package/dist/style.d.ts +14 -55
- package/dist/style.d.ts.map +1 -0
- package/dist/types.d.ts +26 -240
- package/dist/types.d.ts.map +1 -0
- package/dist/ws.d.ts +14 -17
- package/dist/ws.d.ts.map +1 -0
- package/dist/wss.d.ts +16 -16
- package/dist/wss.d.ts.map +1 -0
- package/package.json +3 -2
- package/src/build.ts +337 -0
- package/src/chokidar.ts +401 -0
- package/src/cli.ts +638 -0
- package/src/config.ts +205 -0
- package/src/dom.ts +817 -0
- package/src/el.ts +164 -0
- package/src/fs.ts +727 -0
- package/src/hmr.ts +137 -0
- package/src/http.ts +775 -0
- package/src/https.ts +411 -0
- package/src/index.ts +14 -0
- package/src/mime-types.ts +222 -0
- package/src/path.ts +493 -0
- package/src/router.ts +237 -0
- package/src/runtime.ts +97 -0
- package/src/server.ts +1290 -0
- package/src/state.ts +468 -0
- package/src/style.ts +524 -0
- package/{dist/types-Du6kfwTm.d.ts → src/types.ts} +58 -141
- package/src/ws.ts +506 -0
- package/src/wss.ts +241 -0
- package/dist/build.d.mts +0 -20
- package/dist/chokidar.d.mts +0 -134
- package/dist/dom.d.mts +0 -87
- package/dist/el.d.mts +0 -207
- package/dist/fs.d.mts +0 -255
- package/dist/hmr.d.mts +0 -38
- package/dist/http.d.mts +0 -163
- package/dist/https.d.mts +0 -108
- package/dist/index.d.mts +0 -629
- package/dist/mime-types.d.mts +0 -48
- package/dist/path.d.mts +0 -163
- package/dist/router.d.mts +0 -47
- package/dist/runtime.d.mts +0 -97
- package/dist/server.d.mts +0 -7
- package/dist/state.d.mts +0 -111
- package/dist/style.d.mts +0 -159
- package/dist/types-C0nGi6MX.d.mts +0 -346
- package/dist/types.d.mts +0 -452
- package/dist/ws.d.mts +0 -195
- package/dist/wss.d.mts +0 -108
package/src/hmr.ts
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-side HMR runtime for Elit
|
|
3
|
+
* Import this in your app to enable hot module replacement
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface HMRClient {
|
|
7
|
+
/** Check if HMR is enabled */
|
|
8
|
+
enabled: boolean;
|
|
9
|
+
/** Manually reload the page */
|
|
10
|
+
reload: () => void;
|
|
11
|
+
/** Accept HMR updates for current module */
|
|
12
|
+
accept: (callback?: () => void) => void;
|
|
13
|
+
/** Decline HMR updates (forces full reload) */
|
|
14
|
+
decline: () => void;
|
|
15
|
+
/** Dispose callback before module is replaced */
|
|
16
|
+
dispose: (callback: () => void) => void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
declare global {
|
|
20
|
+
interface Window {
|
|
21
|
+
__ELIT_HMR__: HMRClient;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
class ElitHMR implements HMRClient {
|
|
26
|
+
enabled = false;
|
|
27
|
+
private ws: WebSocket | null = null;
|
|
28
|
+
private acceptCallbacks: (() => void)[] = [];
|
|
29
|
+
private disposeCallbacks: (() => void)[] = [];
|
|
30
|
+
private declined = false;
|
|
31
|
+
|
|
32
|
+
constructor() {
|
|
33
|
+
if (typeof window === 'undefined') {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
this.connect();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private connect() {
|
|
41
|
+
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
42
|
+
const host = window.location.hostname;
|
|
43
|
+
const port = window.location.port || '3000';
|
|
44
|
+
|
|
45
|
+
this.ws = new WebSocket(`${protocol}//${host}:${port}`);
|
|
46
|
+
|
|
47
|
+
this.ws.onopen = () => {
|
|
48
|
+
this.enabled = true;
|
|
49
|
+
console.log('[Elit HMR] Connected ✓');
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
this.ws.onmessage = (event) => {
|
|
53
|
+
try {
|
|
54
|
+
const data = JSON.parse(event.data);
|
|
55
|
+
this.handleMessage(data);
|
|
56
|
+
} catch (error) {
|
|
57
|
+
console.error('[Elit HMR] Error parsing message:', error);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
this.ws.onclose = () => {
|
|
62
|
+
this.enabled = false;
|
|
63
|
+
console.log('[Elit HMR] Disconnected - Attempting reconnect...');
|
|
64
|
+
setTimeout(() => this.reload(), 1000);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
this.ws.onerror = (error) => {
|
|
68
|
+
console.error('[Elit HMR] WebSocket error:', error);
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private handleMessage(data: any) {
|
|
73
|
+
switch (data.type) {
|
|
74
|
+
case 'connected':
|
|
75
|
+
console.log('[Elit HMR] Ready');
|
|
76
|
+
break;
|
|
77
|
+
|
|
78
|
+
case 'update':
|
|
79
|
+
console.log(`[Elit HMR] Update detected: ${data.path}`);
|
|
80
|
+
|
|
81
|
+
if (this.declined) {
|
|
82
|
+
this.reload();
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Run dispose callbacks
|
|
87
|
+
this.disposeCallbacks.forEach(cb => cb());
|
|
88
|
+
this.disposeCallbacks = [];
|
|
89
|
+
|
|
90
|
+
// Run accept callbacks or reload
|
|
91
|
+
if (this.acceptCallbacks.length > 0) {
|
|
92
|
+
this.acceptCallbacks.forEach(cb => cb());
|
|
93
|
+
} else {
|
|
94
|
+
this.reload();
|
|
95
|
+
}
|
|
96
|
+
break;
|
|
97
|
+
|
|
98
|
+
case 'reload':
|
|
99
|
+
console.log('[Elit HMR] Full reload requested');
|
|
100
|
+
this.reload();
|
|
101
|
+
break;
|
|
102
|
+
|
|
103
|
+
case 'error':
|
|
104
|
+
console.error('[Elit HMR] Server error:', data.error);
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
reload() {
|
|
110
|
+
window.location.reload();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
accept(callback?: () => void) {
|
|
114
|
+
if (callback) {
|
|
115
|
+
this.acceptCallbacks.push(callback);
|
|
116
|
+
}
|
|
117
|
+
this.declined = false;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
decline() {
|
|
121
|
+
this.declined = true;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
dispose(callback: () => void) {
|
|
125
|
+
this.disposeCallbacks.push(callback);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Create singleton instance
|
|
130
|
+
const hmr = new ElitHMR();
|
|
131
|
+
|
|
132
|
+
// Expose globally
|
|
133
|
+
if (typeof window !== 'undefined') {
|
|
134
|
+
window.__ELIT_HMR__ = hmr;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export default hmr;
|