elit 2.0.0 → 3.0.0

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.
Files changed (82) hide show
  1. package/README.md +436 -237
  2. package/dist/build.d.mts +10 -1
  3. package/dist/build.d.ts +10 -1
  4. package/dist/build.js +670 -1
  5. package/dist/build.mjs +641 -1
  6. package/dist/chokidar.d.mts +134 -0
  7. package/dist/chokidar.d.ts +134 -0
  8. package/dist/chokidar.js +240 -0
  9. package/dist/chokidar.mjs +221 -0
  10. package/dist/cli.js +2792 -495
  11. package/dist/dom.d.mts +10 -3
  12. package/dist/dom.d.ts +10 -3
  13. package/dist/dom.js +676 -1
  14. package/dist/dom.mjs +647 -1
  15. package/dist/el.d.mts +16 -36
  16. package/dist/el.d.ts +16 -36
  17. package/dist/el.js +789 -1
  18. package/dist/el.mjs +583 -1
  19. package/dist/fs.d.mts +255 -0
  20. package/dist/fs.d.ts +255 -0
  21. package/dist/fs.js +513 -0
  22. package/dist/fs.mjs +469 -0
  23. package/dist/hmr.js +112 -1
  24. package/dist/hmr.mjs +91 -1
  25. package/dist/http.d.mts +163 -0
  26. package/dist/http.d.ts +163 -0
  27. package/dist/http.js +632 -0
  28. package/dist/http.mjs +605 -0
  29. package/dist/https.d.mts +108 -0
  30. package/dist/https.d.ts +108 -0
  31. package/dist/https.js +907 -0
  32. package/dist/https.mjs +901 -0
  33. package/dist/index.d.mts +613 -33
  34. package/dist/index.d.ts +613 -33
  35. package/dist/index.js +2589 -1
  36. package/dist/index.mjs +2312 -1
  37. package/dist/mime-types.d.mts +48 -0
  38. package/dist/mime-types.d.ts +48 -0
  39. package/dist/mime-types.js +197 -0
  40. package/dist/mime-types.mjs +166 -0
  41. package/dist/path.d.mts +163 -0
  42. package/dist/path.d.ts +163 -0
  43. package/dist/path.js +350 -0
  44. package/dist/path.mjs +310 -0
  45. package/dist/router.d.mts +3 -1
  46. package/dist/router.d.ts +3 -1
  47. package/dist/router.js +830 -1
  48. package/dist/router.mjs +801 -1
  49. package/dist/runtime.d.mts +97 -0
  50. package/dist/runtime.d.ts +97 -0
  51. package/dist/runtime.js +43 -0
  52. package/dist/runtime.mjs +15 -0
  53. package/dist/server.d.mts +5 -1
  54. package/dist/server.d.ts +5 -1
  55. package/dist/server.js +3267 -1
  56. package/dist/server.mjs +3241 -1
  57. package/dist/state.d.mts +3 -1
  58. package/dist/state.d.ts +3 -1
  59. package/dist/state.js +1036 -1
  60. package/dist/state.mjs +992 -1
  61. package/dist/style.d.mts +47 -1
  62. package/dist/style.d.ts +47 -1
  63. package/dist/style.js +551 -1
  64. package/dist/style.mjs +483 -1
  65. package/dist/{types-DOAdFFJB.d.ts → types-C0nGi6MX.d.mts} +29 -13
  66. package/dist/{types-DOAdFFJB.d.mts → types-Du6kfwTm.d.ts} +29 -13
  67. package/dist/types.d.mts +452 -3
  68. package/dist/types.d.ts +452 -3
  69. package/dist/types.js +18 -1
  70. package/dist/ws.d.mts +195 -0
  71. package/dist/ws.d.ts +195 -0
  72. package/dist/ws.js +380 -0
  73. package/dist/ws.mjs +358 -0
  74. package/dist/wss.d.mts +108 -0
  75. package/dist/wss.d.ts +108 -0
  76. package/dist/wss.js +1306 -0
  77. package/dist/wss.mjs +1300 -0
  78. package/package.json +53 -6
  79. package/dist/client.d.mts +0 -9
  80. package/dist/client.d.ts +0 -9
  81. package/dist/client.js +0 -1
  82. package/dist/client.mjs +0 -1
package/README.md CHANGED
@@ -1,29 +1,85 @@
1
1
  # Elit
2
2
 
3
- ⚡ A full-stack TypeScript framework (~10KB gzipped) with built-in dev server, HMR, build tool, and REST API. Zero dependencies, maximum productivity.
3
+ ⚡ A lightweight TypeScript framework with built-in dev server, HMR, routing, and reactive state management. **Zero production dependencies**, maximum developer experience.
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/elit.svg)](https://www.npmjs.com/package/elit)
6
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
- [![Bundle Size](https://img.shields.io/badge/bundle%20size-~10KB%20gzipped-success)](https://bundlephobia.com/package/elit)
7
+ [![Bundle Size](https://img.shields.io/badge/bundle%20size-lightweight-success)](https://bundlephobia.com/package/elit)
8
8
 
9
9
  > **Quick Links:** [Installation](#installation) | [Features](#features) | [Quick Start](#quick-start) | [CLI Tools](#cli-tools) | [API](#api) | [Deployment](#deployment)
10
10
 
11
11
  ## Why Elit?
12
12
 
13
- - **🎯 Tiny Bundle Size**: Only ~10KB gzipped (30KB minified) - no framework bloat
14
- - **📦 Zero Dependencies**: Pure TypeScript, no external dependencies
13
+ ### Frontend Excellence
14
+ - **🎯 Ultra Lightweight**: Modular design - import only what you need (DOM: 11KB, State: 15KB)
15
15
  - **⚡ Lightning Fast**: Direct DOM manipulation - no virtual DOM overhead
16
+ - **🔄 Reactive State**: Simple but powerful reactive state management with `createState` and `computed`
17
+ - **🎨 CSS-in-JS**: Type-safe styling with `CreateStyle`
18
+ - **🛣️ Client Router**: Hash and history mode routing with dynamic parameters and guards
19
+ - **📱 Virtual Scrolling**: Handle 100k+ items efficiently
20
+ - **🌲 Tree-Shakeable**: Smart ES modules - only bundle what you use
21
+
22
+ ### Backend Performance
23
+ - **🚀 High Performance**: 10,000+ req/s on Node.js with sub-7ms latency
24
+ - **🌐 ServerRouter**: Full-featured routing with only 2.7% overhead vs raw HTTP
25
+ - **🔌 WebSocket**: Built-in real-time communication support
26
+ - **⚡ Cross-Runtime**: Works on Node.js, Bun, and Deno with runtime-specific optimizations
27
+ - **🔧 Middleware Stack**: CORS, logging, rate limiting, compression, and more
28
+ - **🔐 Zero Dependencies**: No production dependencies for maximum security
29
+
30
+ ### Developer Experience
16
31
  - **🔷 TypeScript First**: Full type safety and IntelliSense out of the box
17
- - **🔄 Reactive State**: Simple but powerful reactive state management
18
- - **🌲 Tree-Shakeable**: Import only what you need for optimal bundle size
19
- - **🚀 Full-Stack Ready**: Built-in dev server, HMR, build tool, and REST API
32
+ - **📝 TypeScript Imports**: Write `import './file.ts'` - automatically rewritten to `.js` for browsers
20
33
  - **🔥 Hot Module Replacement**: Instant development feedback with automatic HMR
21
- - **🏗️ Build System**: Integrated esbuild with automatic client/server separation
22
- - **🌐 REST API Router**: Built-in server-side routing with middleware stack
23
- - **🔌 WebSocket Support**: Real-time state synchronization out of the box
24
- - **🎨 Developer Experience**: CLI tools, zero config, and excellent tooling support
34
+ - **🏗️ Build System**: Integrated esbuild for fast production builds
35
+ - **🎯 Zero Config**: Works out of the box with optional `elit.config.ts`
36
+ - **📦 CLI Tools**: `npx elit dev`, `npx elit build`, `npx elit preview`
37
+ - **🌍 Environment Support**: .env files with VITE_ prefix
25
38
 
26
- ## Installation
39
+ ## Quick Start
40
+
41
+ The fastest way to get started with Elit is using our scaffolding tool:
42
+
43
+ ```bash
44
+ # With npm
45
+ npm create elit@latest my-app
46
+
47
+ # With yarn
48
+ yarn create elit my-app
49
+
50
+ # With pnpm
51
+ pnpm create elit my-app
52
+
53
+ # With bun
54
+ bun create elit my-app
55
+
56
+ # With deno
57
+ deno run -A npm:create-elit my-app
58
+ ```
59
+
60
+ Then follow the prompts!
61
+
62
+ ```bash
63
+ cd my-app
64
+ npm install
65
+ npm run dev
66
+ ```
67
+
68
+ ### Available Templates
69
+
70
+ Choose a template with the `--template` flag:
71
+
72
+ - **basic** (default) - Full-featured app with styled counter example
73
+ - **full** - Full-stack app with dev server and API routes
74
+ - **minimal** - Minimal setup with just DOM rendering
75
+
76
+ ```bash
77
+ npm create elit@latest my-app --template=full
78
+ ```
79
+
80
+ ## Manual Installation
81
+
82
+ If you prefer to set up manually:
27
83
 
28
84
  ```bash
29
85
  npm install elit
@@ -46,75 +102,116 @@ npx elit preview
46
102
 
47
103
  ### Configuration
48
104
 
49
- Create `elit.config.mjs` (or .ts, .js, .json) in your project root:
105
+ Create `elit.config.ts` (or .js, .mjs, .json) in your project root:
50
106
 
51
- ```javascript
52
- import { defineConfig } from 'elit';
53
- import { resolve } from 'path';
107
+ ```typescript
108
+ import { server } from './src/server';
109
+ import { client } from './src/client';
54
110
 
55
- export default defineConfig({
111
+ export default {
56
112
  dev: {
57
- port: 3000,
58
- host: 'localhost',
59
- root: './src',
60
- basePath: '/',
61
- open: true
113
+ port: 3003,
114
+ host: '0.0.0.0',
115
+ open: false,
116
+ logging: true,
117
+ clients: [{
118
+ root: '.',
119
+ basePath: '',
120
+ ssr: () => client, // Server-side rendering
121
+ api: server // API routes
122
+ }]
62
123
  },
63
- build: {
124
+ build: [{
64
125
  entry: './src/main.ts',
65
126
  outDir: './dist',
127
+ outFile: 'main.js',
66
128
  format: 'esm',
67
129
  minify: true,
68
- platform: 'browser',
69
- basePath: '/app',
130
+ sourcemap: true,
131
+ target: 'es2020',
70
132
  copy: [
71
- {
72
- from: 'index.html',
73
- to: 'index.html',
74
- transform: (content, config) => {
75
- // Inject base tag from basePath
76
- return content;
77
- }
78
- }
133
+ { from: './public/index.html', to: './index.html' }
79
134
  ]
80
- },
135
+ }],
81
136
  preview: {
82
- port: 4173,
137
+ port: 3000,
138
+ host: '0.0.0.0',
139
+ open: false,
140
+ logging: true,
83
141
  root: './dist',
84
- basePath: '/app'
142
+ basePath: '',
143
+ index: './index.html'
85
144
  }
86
- });
145
+ };
87
146
  ```
88
147
 
89
- ## Features
148
+ **Server setup (src/server.ts):**
90
149
 
91
- ### Frontend Framework
150
+ ```typescript
151
+ import { ServerRouter } from 'elit/server';
92
152
 
93
- - 🎯 **Ultra Lightweight**: Just 30KB minified, ~10KB gzipped
94
- - ⚡ **Reactive State**: Built-in reactive state management with `createState`
95
- - 🔄 **Computed Values**: Automatic dependency tracking with `computed`
96
- - 🎨 **CSS-in-JS**: Type-safe styling with `CreateStyle`
97
- - 🛣️ **Client-Side Router**: Hash and history mode routing with dynamic parameters
98
- - 📱 **Virtual Scrolling**: Handle 100k+ items efficiently
99
- - 🖥️ **SSR Support**: Full server-side rendering capabilities
100
- - 🎭 **SVG & MathML**: Complete support for all elements
101
- - 🔧 **Performance Utilities**: Throttle, debounce, batch rendering
102
- - 📦 **Tree-Shakeable**: Import only what you need
103
- - 🎮 **DOM Utilities**: Convenient helper functions
153
+ export const router = new ServerRouter();
154
+
155
+ router.get('/api/hello', async (ctx) => {
156
+ ctx.res.setHeader('Content-Type', 'text/html; charset=UTF-8');
157
+ ctx.res.end("Hello from Elit ServerRouter!");
158
+ });
104
159
 
105
- ### Full-Stack Tools
160
+ export const server = router;
161
+ ```
106
162
 
107
- - 🔥 **Hot Module Replacement**: Instant development feedback
108
- - 🏗️ **Build System**: esbuild integration with automatic client/server separation
109
- - 🌐 **REST API Router**: Server-side routing with middleware stack
110
- - 🔧 **Middleware**: CORS, logging, error handling, rate limiting, compression, security
111
- - 🔄 **Shared State**: Real-time WebSocket state synchronization
112
- - 📊 **WebSocket Support**: Built-in WebSocket server
113
- - 📁 **Static File Server**: Gzip compression and cache headers
114
- - 🎯 **Zero Config**: Works out of the box with sensible defaults
115
- - 🔐 **Environment Variables**: Support for .env files with VITE_ prefix
163
+ **Client SSR template (src/client.ts):**
116
164
 
117
- ## Quick Start
165
+ ```typescript
166
+ import { div, html, head, body, title, link, script, meta } from 'elit/el';
167
+
168
+ export const client = html(
169
+ head(
170
+ title('Elit - Full-Stack TypeScript Framework'),
171
+ link({ rel: 'icon', type: 'image/svg+xml', href: 'favicon.svg' }),
172
+ meta({ charset: 'UTF-8' }),
173
+ meta({ name: 'viewport', content: 'width=device-width, initial-scale=1.0' }),
174
+ meta({ name: 'description', content: 'Full-stack TypeScript framework' })
175
+ ),
176
+ body(
177
+ div({ id: 'root' }),
178
+ script({ type: 'module', src: '/src/main.js' })
179
+ )
180
+ );
181
+ ```
182
+
183
+ ## Features
184
+
185
+ ### Frontend Framework
186
+
187
+ - 🎯 **Modular & Lightweight**: DOM (11KB), State (15KB), Router (13KB) - use only what you need
188
+ - ⚡ **Reactive State**: Built-in reactive state management with `createState` and automatic dependency tracking
189
+ - 🔄 **Computed Values**: Automatic dependency tracking with `computed` for derived state
190
+ - 🎨 **CSS-in-JS**: Type-safe styling with `CreateStyle` and support for pseudo-selectors
191
+ - 🛣️ **Client-Side Router**: Hash and history mode routing with dynamic parameters and navigation guards
192
+ - 📱 **Virtual Scrolling**: Handle 100k+ items efficiently with `createVirtualList`
193
+ - 🖥️ **SSR Support**: Full server-side rendering with `renderToString`
194
+ - 🎭 **100+ Elements**: Complete HTML, SVG, and MathML element support
195
+ - 🔧 **Performance Utilities**: Throttle, debounce, batch rendering, chunked rendering
196
+ - 📦 **Tree-Shakeable**: ES modules with excellent tree-shaking support
197
+ - 🎮 **DOM Utilities**: Query selectors, element creation, fragment support
198
+
199
+ ### Backend & Development
200
+
201
+ - 🔥 **Hot Module Replacement**: Instant development feedback with automatic state preservation
202
+ - 🏗️ **Build System**: Integrated esbuild with runtime-specific optimizations (Node.js, Bun, Deno)
203
+ - 🌐 **ServerRouter**: High-performance routing (10,128 req/s) with minimal overhead (2.7%)
204
+ - 🔧 **Rich Middleware**: CORS, logging, rate limiting, compression, security headers, and more
205
+ - 🔌 **WebSocket Server**: Built-in WebSocket with automatic state synchronization
206
+ - 📁 **Static File Server**: Efficient serving with proper MIME types and caching
207
+ - 🎯 **Smart Defaults**: Zero-config development with optional `elit.config.mjs`
208
+ - 📦 **Auto TypeScript**: Automatic TypeScript compilation on all runtimes
209
+ - 🌍 **Environment Variables**: .env file support with VITE_ prefix
210
+ - ⚡ **Cross-Runtime**: Optimized for Node.js, Bun, and Deno with specific adaptations
211
+
212
+ ## Manual Setup
213
+
214
+ If you prefer to set up your project manually:
118
215
 
119
216
  ### 1. Create Your Project
120
217
 
@@ -135,7 +232,7 @@ npm install elit
135
232
  Create `src/main.ts`:
136
233
 
137
234
  ```typescript
138
- import { div, h1, button, createState, reactive, domNode } from 'elit';
235
+ import { div, h1, button, createState, reactive, dom } from 'elit';
139
236
 
140
237
  const count = createState(0);
141
238
 
@@ -149,7 +246,8 @@ const app = div({ className: 'app' },
149
246
  )
150
247
  );
151
248
 
152
- domNode.render('#app', app);
249
+ // Render to DOM
250
+ dom.render('#app', app);
153
251
  ```
154
252
 
155
253
  Create `index.html`:
@@ -177,34 +275,6 @@ npx elit dev
177
275
 
178
276
  Your app will automatically reload when you make changes with HMR!
179
277
 
180
- ### NPM Installation
181
-
182
- ```bash
183
- npm install elit
184
- ```
185
-
186
- ```typescript
187
- import { div, h1, p, button, createState, reactive, domNode } from 'elit';
188
-
189
- // Create reactive state
190
- const count = createState(0);
191
-
192
- // Create elements with reactive updates
193
- const app = div({ className: 'app' },
194
- h1('Hello Elit! 👋'),
195
- p('A lightweight, reactive DOM library'),
196
- reactive(count, (value) =>
197
- button({
198
- onclick: () => count.value++,
199
- className: 'btn-primary'
200
- }, `Count: ${value}`)
201
- )
202
- );
203
-
204
- // Render to DOM
205
- domNode.render('#app', app);
206
- ```
207
-
208
278
  ### CDN Usage
209
279
 
210
280
  ```html
@@ -216,7 +286,7 @@ domNode.render('#app', app);
216
286
  <body>
217
287
  <div id="app"></div>
218
288
  <script>
219
- const { div, h1, button, createState, reactive, domNode } = window;
289
+ const { div, h1, button, createState, reactive, dom } = window;
220
290
 
221
291
  const count = createState(0);
222
292
  const app = div(
@@ -226,7 +296,7 @@ domNode.render('#app', app);
226
296
  )
227
297
  );
228
298
 
229
- domNode.render('#app', app);
299
+ dom.render('#app', app);
230
300
  </script>
231
301
  </body>
232
302
  </html>
@@ -267,106 +337,142 @@ const deepState = createState({ nested: { value: 1 } }, { deep: true });
267
337
  ### Reactive Rendering
268
338
 
269
339
  ```typescript
270
- import { reactive, text, bindValue } from 'elit';
340
+ import { reactive, text, bindValue, bindChecked } from 'elit';
271
341
 
272
342
  const message = createState('Hello');
343
+ const isEnabled = createState(false);
273
344
 
274
345
  // Reactive element - re-renders when state changes
275
346
  const display = reactive(message, (value) =>
276
347
  div({ className: 'message' }, value)
277
348
  );
278
349
 
279
- // Reactive text
350
+ // Reactive text node
280
351
  const label = text(message);
281
352
 
282
353
  // Two-way binding for inputs
283
354
  const inputEl = input({ type: 'text', ...bindValue(message) });
355
+ const checkbox = input({ type: 'checkbox', ...bindChecked(isEnabled) });
284
356
  ```
285
357
 
286
358
  ### Shared State (Real-time Sync)
287
359
 
288
- **Requires `elit-server`** - Shared state syncs automatically between backend and frontend via WebSocket:
360
+ Shared state automatically syncs between server and client via WebSocket:
361
+
362
+ **Client-side:**
289
363
 
290
364
  ```typescript
291
365
  import { createSharedState, reactive } from 'elit';
292
366
 
293
- // Create shared state (auto-connects to elit-server)
367
+ // Create shared state (auto-connects to WebSocket server)
294
368
  const counter = createSharedState('counter', 0);
295
- const todos = createSharedState('todos', []);
369
+ const users = createSharedState('users', []);
296
370
 
297
371
  // Use with reactive rendering
298
372
  const app = div(
299
373
  reactive(counter.state, value =>
300
374
  div(`Counter: ${value}`)
301
375
  ),
302
- button({ onclick: () => counter.value++ }, 'Increment')
376
+ button({ onclick: () => counter.set(counter.state.value + 1) }, 'Increment')
303
377
  );
304
378
 
305
379
  // Listen to changes
306
- counter.onChange((newValue, oldValue) => {
307
- console.log(`${oldValue} ${newValue}`);
380
+ counter.onChange((newValue) => {
381
+ console.log('Counter changed to:', newValue);
308
382
  });
309
383
 
310
- // Update from any client - syncs to all
311
- counter.value++;
384
+ // Update from any client - automatically syncs to all connected clients
385
+ counter.set(10);
312
386
  ```
313
387
 
314
- **Backend (Node.js with elit-server):**
388
+ **Server-side:**
315
389
 
316
- ```javascript
317
- const { createDevServer } = require('elit-server');
390
+ ```typescript
391
+ import { createDevServer, StateManager } from 'elit';
318
392
 
319
393
  const server = createDevServer({ port: 3000 });
320
394
 
321
- // Create matching shared states
322
- const counter = server.state.create('counter', { initial: 0 });
323
- const todos = server.state.create('todos', { initial: [] });
324
-
325
- // Listen to changes
326
- counter.onChange((newValue, oldValue) => {
327
- console.log(`Counter: ${oldValue} → ${newValue}`);
328
- });
329
-
330
- // Update from backend - syncs to all clients
331
- counter.value++;
395
+ // StateManager is built-in and handles WebSocket connections
396
+ // All clients with matching shared state keys will sync automatically
332
397
  ```
333
398
 
334
- ### elit-server - Development Server
399
+ ### Development Server with REST API
400
+
401
+ Elit includes a built-in development server with HMR, WebSocket support, and REST API routing:
335
402
 
336
- Full-featured development server with HMR, REST API, and real-time features:
403
+ **Server Configuration (server.ts):**
337
404
 
338
- ```javascript
339
- const { createDevServer, Router, cors, logger } = require('elit-server');
405
+ ```typescript
406
+ import { createDevServer, ServerRouter, cors, logger, json } from 'elit';
340
407
 
341
408
  // Create REST API router
342
- const api = new Router();
409
+ const api = new ServerRouter();
343
410
 
344
411
  // Add middleware
345
- api.use(cors());
412
+ api.use(cors({ origin: '*', methods: ['GET', 'POST', 'PUT', 'DELETE'] }));
346
413
  api.use(logger());
347
414
 
348
- // Define routes
415
+ // Define API routes with helper functions
349
416
  api.get('/api/users', (ctx) => {
350
- return { success: true, users: [...] };
417
+ json(ctx, { success: true, users: [] });
351
418
  });
352
419
 
353
- api.post('/api/users', (ctx) => {
420
+ api.post('/api/users', async (ctx) => {
354
421
  const user = ctx.body;
355
- return { success: true, user };
422
+ json(ctx, { success: true, user });
356
423
  });
357
424
 
358
- // Create server with API
425
+ // Create development server
359
426
  const server = createDevServer({
360
427
  port: 3000,
361
- root: __dirname,
362
- api,
363
- logging: true
428
+ root: './src',
429
+ open: true,
430
+ router: api
364
431
  });
432
+ ```
433
+
434
+ **Available Middleware:**
365
435
 
366
- // Access shared state
367
- const counter = server.state.create('counter', {
368
- initial: 0,
369
- validate: (value) => typeof value === 'number'
436
+ ```typescript
437
+ import {
438
+ cors, // CORS headers
439
+ logger, // Request logging
440
+ errorHandler, // Error handling
441
+ rateLimit, // Rate limiting
442
+ bodyLimit, // Request body size limit
443
+ cacheControl, // Cache headers
444
+ compress, // Gzip compression
445
+ security // Security headers
446
+ } from 'elit';
447
+
448
+ // Example usage
449
+ api.use(cors({ origin: '*' }));
450
+ api.use(logger({ format: 'detailed' }));
451
+ api.use(rateLimit({ max: 100, windowMs: 60000 }));
452
+ api.use(bodyLimit({ limit: 1024 * 1024 })); // 1MB
453
+ api.use(compress());
454
+ api.use(security());
455
+ ```
456
+
457
+ **Helper Functions:**
458
+
459
+ ```typescript
460
+ import { json, sendText, html, status } from 'elit';
461
+
462
+ api.get('/api/data', (ctx) => {
463
+ json(ctx, { message: 'Hello' }); // JSON response
464
+ });
465
+
466
+ api.get('/text', (ctx) => {
467
+ sendText(ctx, 'Hello World'); // Text response
468
+ });
469
+
470
+ api.get('/page', (ctx) => {
471
+ html(ctx, '<h1>Hello</h1>'); // HTML response
472
+ });
473
+
474
+ api.get('/error', (ctx) => {
475
+ status(ctx, 404, 'Not Found'); // Custom status
370
476
  });
371
477
  ```
372
478
 
@@ -374,41 +480,16 @@ const counter = server.state.create('counter', {
374
480
 
375
481
  ```bash
376
482
  # Start dev server
377
- npx elit-dev
483
+ npx elit dev
378
484
 
379
485
  # Custom port
380
- npx elit-dev --port 8080
486
+ npx elit dev --port 8080
381
487
 
382
488
  # Custom root directory
383
- npx elit-dev --root ./public
489
+ npx elit dev --root ./public
384
490
 
385
491
  # Disable auto-open browser
386
- npx elit-dev --no-open
387
-
388
- # Silent mode
389
- npx elit-dev --silent
390
- ```
391
-
392
- **Middleware:**
393
-
394
- ```javascript
395
- const {
396
- cors, // CORS headers
397
- logger, // Request logging
398
- errorHandler, // Error handling
399
- rateLimit, // Rate limiting
400
- bodyLimit, // Request body size limit
401
- cacheControl, // Cache headers
402
- compress, // Gzip compression
403
- security // Security headers
404
- } = require('elit-server');
405
-
406
- api.use(cors({ origin: '*' }));
407
- api.use(logger());
408
- api.use(rateLimit({ max: 100, window: 60000 }));
409
- api.use(bodyLimit(1024 * 1024)); // 1MB
410
- api.use(compress());
411
- api.use(security());
492
+ npx elit dev --no-open
412
493
  ```
413
494
 
414
495
  ### Server-Side Rendering
@@ -478,7 +559,15 @@ const btn = button({ className: buttonClass }, 'Click me');
478
559
  ### Performance Utilities
479
560
 
480
561
  ```typescript
481
- import { batchRender, renderChunked, createVirtualList, throttle, debounce } from 'elit';
562
+ import {
563
+ batchRender,
564
+ renderChunked,
565
+ createVirtualList,
566
+ throttle,
567
+ debounce,
568
+ lazy,
569
+ cleanupUnused
570
+ } from 'elit';
482
571
 
483
572
  // Batch render multiple elements
484
573
  batchRender('#container', elements);
@@ -488,7 +577,7 @@ renderChunked('#container', largeArray, 5000, (current, total) => {
488
577
  console.log(`Rendered ${current}/${total}`);
489
578
  });
490
579
 
491
- // Virtual scrolling
580
+ // Virtual scrolling for 100k+ items
492
581
  const virtualList = createVirtualList(
493
582
  container,
494
583
  items,
@@ -497,9 +586,61 @@ const virtualList = createVirtualList(
497
586
  5 // buffer size
498
587
  );
499
588
 
589
+ // Lazy loading components
590
+ const LazyComponent = lazy(() => import('./HeavyComponent'));
591
+
500
592
  // Throttle and debounce
501
593
  const throttledFn = throttle(handleScroll, 100);
502
594
  const debouncedFn = debounce(handleInput, 300);
595
+
596
+ // Cleanup unused DOM elements
597
+ const cleaned = cleanupUnused(rootElement);
598
+ console.log(`Cleaned ${cleaned} elements`);
599
+ ```
600
+
601
+ ### Additional Features
602
+
603
+ **DOM Utilities:**
604
+
605
+ ```typescript
606
+ import { doc, el, els, createEl, elId, elClass, fragment } from 'elit';
607
+
608
+ // Query selectors
609
+ const element = el('.my-class'); // querySelector
610
+ const elements = els('.my-class'); // querySelectorAll
611
+ const byId = elId('my-id'); // getElementById
612
+ const byClass = elClass('my-class'); // getElementsByClassName
613
+
614
+ // Create elements
615
+ const div = createEl('div'); // createElement
616
+ const frag = fragment(); // createDocumentFragment
617
+
618
+ // Access document
619
+ doc.title = 'New Title';
620
+ ```
621
+
622
+ **Effect System:**
623
+
624
+ ```typescript
625
+ import { createState, effect } from 'elit';
626
+
627
+ const count = createState(0);
628
+
629
+ // Run side effects when state changes
630
+ effect(() => {
631
+ console.log('Count is now:', count.value);
632
+ });
633
+ ```
634
+
635
+ **Reactive As (Advanced):**
636
+
637
+ ```typescript
638
+ import { reactiveAs } from 'elit';
639
+
640
+ // Use different reactive context
641
+ const display = reactiveAs(customState, customContext, (value) =>
642
+ div(value)
643
+ );
503
644
  ```
504
645
 
505
646
  ### JSON Rendering
@@ -530,7 +671,7 @@ renderVNode('#app', {
530
671
  ### Head Management
531
672
 
532
673
  ```typescript
533
- import { setTitle, addMeta, addLink, addStyle, renderToHead } from 'elit';
674
+ import { setTitle, addMeta, addLink, addStyle } from 'elit';
534
675
 
535
676
  setTitle('My App');
536
677
  addMeta({ name: 'description', content: 'My awesome app' });
@@ -538,27 +679,6 @@ addLink({ rel: 'stylesheet', href: '/styles.css' });
538
679
  addStyle('body { margin: 0; }');
539
680
  ```
540
681
 
541
- ### DOM Utilities
542
-
543
- Elit provides convenient DOM utility functions for common operations:
544
-
545
- ```typescript
546
- import { doc, el, els, createEl, elId, elClass, fragment } from 'elit';
547
-
548
- // Query selectors (bound to document)
549
- const element = el('.my-class'); // querySelector
550
- const elements = els('.my-class'); // querySelectorAll
551
- const byId = elId('my-id'); // getElementById
552
- const byClass = elClass('my-class'); // getElementsByClassName
553
-
554
- // Create elements
555
- const div = createEl('div'); // createElement
556
- const frag = fragment(); // createDocumentFragment
557
-
558
- // Access document object
559
- doc.title = 'New Title';
560
- ```
561
-
562
682
  ## Available Elements
563
683
 
564
684
  ### HTML Elements (100+)
@@ -594,23 +714,62 @@ All MathML elements are prefixed with `math`:
594
714
 
595
715
  ## Bundle Size & Performance
596
716
 
597
- Elit is designed to be extremely lightweight while providing powerful features:
717
+ Elit is designed to be modular and lightweight with excellent tree-shaking support:
718
+
719
+ ### Bundle Sizes (Minified)
720
+
721
+ | Component | ESM | CJS | Description |
722
+ |-----------|-----|-----|-------------|
723
+ | **Full Framework** | 79.52 KB | 80.48 KB | All features included |
724
+ | **DOM Only** | 11.06 KB | 11.07 KB | Just DOM utilities |
725
+ | **State** | 15.34 KB | 15.38 KB | Reactive state management |
726
+ | **Router** | 13.22 KB | 13.22 KB | Client-side routing |
727
+ | **Server** | 51.07 KB | 51.18 KB | Server features + Router |
728
+ | **HTTP** | 7.70 KB | 7.85 KB | HTTP utilities |
729
+ | **CLI** | 127.63 KB | - | Full development toolchain |
730
+
731
+ **Tree-shaking**: Import only what you need! Using modular imports (`elit/dom`, `elit/state`) keeps your bundle minimal.
732
+
733
+ ### Server Performance (Node.js v24.12.0)
598
734
 
599
- | Format | Size (Minified) | Size (Gzipped) |
600
- |--------|----------------|----------------|
601
- | ESM | 29KB | ~10KB |
602
- | CJS | 30KB | ~10KB |
603
- | IIFE | 30KB | ~10KB |
735
+ | Component | Throughput | Latency (P50) | Latency (Avg) | Description |
736
+ |-----------|-----------|---------------|---------------|-------------|
737
+ | **HTTP Server** | 10,410 req/s | 5.91ms | 6.69ms | Raw HTTP optimized |
738
+ | **ServerRouter** | 10,128 req/s | 6.09ms | 6.94ms | Full routing + middleware |
604
739
 
605
- **Tree-shaking**: When using ES modules, only the features you import will be included in your bundle.
740
+ **Router Overhead**: Only 2.7% slower than raw HTTP while providing:
741
+ - Route matching with dynamic params
742
+ - Query string parsing
743
+ - Request context
744
+ - Middleware chain support
745
+ - Body parsing
606
746
 
607
- **Performance Optimizations**:
747
+ ### Cross-Runtime Support
748
+
749
+ Elit works seamlessly on **Node.js, Bun, and Deno** with runtime-specific optimizations:
750
+
751
+ - **Node.js**: Uses native `http` module
752
+ - **Bun**: Ultra-fast `Bun.serve()` with synchronous response detection
753
+ - **Deno**: `Deno.serve()` integration
754
+
755
+ ### Performance Optimizations
756
+
757
+ **Frontend**:
608
758
  - Direct DOM manipulation (no virtual DOM diffing)
609
759
  - Optimized rendering with RAF batching
610
760
  - Smart children rendering with automatic fragment usage
611
761
  - Efficient attribute updates using charCode checks
612
762
  - Minimal function closures and memory allocation
613
763
 
764
+ **Backend**:
765
+ - **Zero-copy headers** for Bun/Deno runtimes
766
+ - **Synchronous response detection** eliminates Promise overhead
767
+ - **String-based body buffering** reduces allocations
768
+ - **Inline Response creation** minimizes object overhead
769
+ - **Pre-compiled route patterns** for fast matching
770
+
771
+ [View detailed benchmarks →](./benchmark)
772
+
614
773
  ## Browser Usage
615
774
 
616
775
  When loaded via script tag, all exports are available on the `window` object:
@@ -618,7 +777,7 @@ When loaded via script tag, all exports are available on the `window` object:
618
777
  ```html
619
778
  <script src="https://unpkg.com/elit@latest/dist/index.global.js"></script>
620
779
  <script>
621
- const { div, span, createState, domNode } = window;
780
+ const { div, span, createState, dom } = window;
622
781
  // or use DomLib global namespace
623
782
  const app = DomLib.div('Hello');
624
783
  </script>
@@ -792,54 +951,94 @@ const isProd = import.meta.env.PROD;
792
951
 
793
952
  ## Comparison with Other Frameworks
794
953
 
795
- | Feature | Elit | Vite + React | Next.js | SvelteKit |
796
- |---------|----------|--------------|---------|-----------|
797
- | Bundle Size | 30KB | ~140KB+ | ~200KB+ | ~15KB* |
798
- | Zero Dependencies | | | | |
799
- | Dev Server | Built-in | Vite | Built-in | Built-in |
800
- | HMR | ✅ | ✅ | ✅ | ✅ |
801
- | Build Tool | ✅ Built-in | ✅ Vite | ✅ Built-in | ✅ Built-in |
802
- | REST API | ✅ Built-in | | ✅ | ✅ |
803
- | TypeScript | ✅ | ✅ | ✅ | ✅ |
804
- | SSR | ✅ | ❌ | ✅ | ✅ |
805
- | Learning Curve | Easy | Medium | Medium | Easy |
806
-
807
- *Svelte requires compilation
954
+ | Feature | Elit | Vite + React | Next.js | SvelteKit | Express.js |
955
+ |---------|----------|--------------|---------|-----------|------------|
956
+ | **Frontend Size** | 11-15KB (modular) | ~140KB+ | ~200KB+ | ~15KB* | N/A |
957
+ | **Backend Size** | 51KB (Server) | N/A | N/A | N/A | ~200KB+ |
958
+ | **Prod Dependencies** | **0** (Zero!) | Many | Many | Many | Many |
959
+ | **Dev Server** | ✅ Built-in | ✅ Vite | ✅ Built-in | ✅ Built-in | ❌ |
960
+ | **HMR** | ✅ | ✅ | ✅ | ✅ | |
961
+ | **Build Tool** | ✅ esbuild | Vite | ✅ Turbopack | ✅ Vite | ❌ |
962
+ | **REST API** | ✅ 10K+ req/s | ❌ | ✅ | ✅ | ✅ 8K+ req/s |
963
+ | **Middleware** | ✅ Built-in | ❌ | ✅ | ✅ | ✅ |
964
+ | **WebSocket** | ✅ Built-in | | | | Via package |
965
+ | **Shared State** | ✅ Auto-sync | ❌ | ❌ | ❌ | ❌ |
966
+ | **Cross-Runtime** | ✅ Node/Bun/Deno | ❌ | ❌ | ❌ | ✅ Node only |
967
+ | **TypeScript** | ✅ Native | ✅ | ✅ | ✅ | ➕ Via setup |
968
+ | **SSR** | ✅ | ❌ | ✅ | ✅ | ➕ Manual |
969
+ | **Tree-Shaking** | ✅ Excellent | ✅ | ✅ | ✅ | ❌ |
970
+ | **Learning Curve** | Easy | Medium | Medium | Easy | Easy |
971
+
972
+ *Svelte requires compilation step
973
+
974
+ ### Performance Comparison
975
+
976
+ **Backend (10K requests, 100 concurrent)**:
977
+ - **Elit ServerRouter**: 10,128 req/s (6.94ms avg) on Node.js
978
+ - **Express.js**: ~8,000 req/s (12ms avg) on Node.js
979
+ - **Fastify**: ~12,000 req/s (8ms avg) on Node.js
980
+ - **Elysia (Bun)**: ~100,000 req/s (<1ms avg) on Bun
981
+
982
+ **Frontend Bundle**:
983
+ - **Elit (modular)**: 11KB (DOM) + 15KB (State) = 26KB for typical app
984
+ - **React + React-DOM**: 140KB+ (45KB gzipped)
985
+ - **Vue 3**: 95KB+ (32KB gzipped)
986
+ - **Svelte**: 15KB+ (6KB gzipped) *after compilation*
808
987
 
809
988
  ## Documentation
810
989
 
811
- - 📚 [Full Documentation](https://github.com/oangsa/elit/docs)
812
- - ⚡ [Quick Start Guide](./docs/QUICK_START.md)
813
- - 📖 [API Reference](./docs/API.md)
814
- - 🔄 [Migration Guide](./docs/MIGRATION.md)
815
- - 🤝 [Contributing Guide](./CONTRIBUTING.md)
990
+ - 📚 [Full Documentation](https://d-osc.github.io/elit)
991
+ - ⚡ [Quick Start](https://d-osc.github.io/elit#/docs)
992
+ - 📖 [API Reference](https://d-osc.github.io/elit#/api)
993
+ - 🎮 [Interactive Examples](https://d-osc.github.io/elit#/examples)
816
994
 
817
995
  ## Changelog
818
996
 
819
- ### Elit - Full-Stack Framework
997
+ ### v2.0.0 - Full-Stack Framework with Performance Optimizations
998
+
999
+ **🚀 Backend Performance Enhancements:**
1000
+ - ⚡ **Ultra-Fast HTTP**: 10,410 req/s with sub-7ms latency on Node.js
1001
+ - 🎯 **Optimized ServerRouter**: 10,128 req/s with only 2.7% overhead vs raw HTTP
1002
+ - 🔄 **Synchronous Response Detection**: Eliminates Promise overhead for Bun runtime
1003
+ - 🆓 **Zero-Copy Headers**: Direct headers reference for Bun/Deno runtimes
1004
+ - 📦 **String-Based Body Buffering**: Reduced allocations and faster responses
1005
+ - ⚡ **Cross-Runtime Optimizations**: Runtime-specific code paths for Node.js, Bun, and Deno
1006
+ - 🔧 **Pre-Compiled Routes**: Route patterns compiled once during registration
820
1007
 
821
- **Major Changes:**
822
- - 🚀 **Integrated Build System**: Built-in esbuild with automatic client/server code separation
823
- - 🔥 **CLI Tools**: New commands - `npx elit dev`, `npx elit build`, `npx elit preview`
1008
+ **🏗️ Build System & CLI:**
1009
+ - 🚀 **Integrated Build System**: Built-in esbuild with runtime-specific transpilation
1010
+ - 🔥 **CLI Tools**: `npx elit dev`, `npx elit build`, `npx elit preview`
824
1011
  - 🏗️ **Zero Config**: Works out of the box with optional `elit.config.mjs`
825
- - 🌐 **REST API Router**: Server-side routing with full middleware stack
826
- - 🔄 **Shared State**: Real-time WebSocket state synchronization
827
1012
  - 🎯 **basePath Support**: Configure base paths for subdirectory deployments
828
1013
  - 🔐 **Environment Variables**: .env file support with VITE_ prefix
829
- - 📦 **Gzip Compression**: Automatic compression for production builds
830
- - 💾 **Cache Headers**: Smart caching for static assets
1014
+ - 📦 **Smart Bundling**: Automatic code splitting and tree-shaking
831
1015
  - ⚡ **Hot Module Replacement**: Instant development feedback
832
1016
 
833
- **Core Library:**
834
- - 🎯 Ultra lightweight (~10KB gzipped)
835
- - Reactive state management
836
- - 🎨 CSS-in-JS with CreateStyle
837
- - 🛣️ Client-side router
838
- - 📱 Virtual scrolling
839
- - 🖥️ SSR support
840
- - 🎭 100+ HTML, SVG, and MathML elements
841
- - 🔧 Performance utilities
842
- - 📦 Tree-shakeable ES modules
1017
+ **🌐 Server Features:**
1018
+ - 🌐 **ServerRouter**: High-performance routing with regex pattern matching
1019
+ - 🔧 **Rich Middleware**: CORS, logger, rate limit, compression, security headers
1020
+ - 🔌 **WebSocket Server**: Built-in WebSocket with state synchronization
1021
+ - 🔄 **Shared State**: Real-time auto-sync between server and all clients
1022
+ - 📁 **Static File Server**: Efficient serving with proper MIME types
1023
+ - 💾 **Cache Headers**: Smart caching for static assets
1024
+ - 📦 **Gzip Compression**: Automatic compression for production
1025
+
1026
+ **🎨 Frontend Library:**
1027
+ - 🎯 **Modular Design**: DOM (11KB), State (15KB), Router (13KB) - use only what you need
1028
+ - ⚡ **Reactive State**: Automatic dependency tracking with `createState` and `computed`
1029
+ - 🎨 **CSS-in-JS**: Type-safe styling with `CreateStyle`
1030
+ - 🛣️ **Client Router**: Hash and history mode with navigation guards
1031
+ - 📱 **Virtual Scrolling**: Handle 100k+ items with `createVirtualList`
1032
+ - 🖥️ **SSR Support**: `renderToString` for server-side rendering
1033
+ - 🎭 **100+ Elements**: Complete HTML, SVG, and MathML support
1034
+ - 🔧 **Performance Utilities**: Throttle, debounce, batch rendering
1035
+ - 📦 **Tree-Shakeable**: Excellent ES module tree-shaking
1036
+
1037
+ **📊 Benchmarks:**
1038
+ - HTTP Server: 10,410 req/s (Node.js v24.12.0)
1039
+ - ServerRouter: 10,128 req/s with full routing + middleware
1040
+ - Router Overhead: Only 2.7% vs raw HTTP
1041
+ - [View detailed benchmarks →](./benchmark)
843
1042
 
844
1043
  ## Examples
845
1044
 
@@ -855,10 +1054,10 @@ Example applications demonstrating Elit features:
855
1054
  ## Links
856
1055
 
857
1056
  - 📦 [npm - elit](https://www.npmjs.com/package/elit)
858
- - 📦 [npm - elit-server](https://www.npmjs.com/package/elit-server)
859
- - 🐙 [GitHub Repository](https://github.com/oangsa/elit)
860
- - 📚 Documentation (coming soon)
861
- - 💬 Discord Community (coming soon)
1057
+ - 🚀 [npm - create-elit](https://www.npmjs.com/package/create-elit)
1058
+ - 🐙 [GitHub Repository](https://github.com/d-osc/elit)
1059
+ - 📚 [Documentation](https://d-osc.github.io/elit)
1060
+ - 💬 Community & Issues: [GitHub Discussions](https://github.com/d-osc/elit/discussions)
862
1061
 
863
1062
  ## Contributing
864
1063