elit 2.0.0 → 2.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.
Files changed (2) hide show
  1. package/README.md +187 -135
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,27 +1,28 @@
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. Minimal 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
+ - **🎯 Lightweight**: Minimal bundle size with tree-shaking support
15
14
  - **⚡ Lightning Fast**: Direct DOM manipulation - no virtual DOM overhead
16
15
  - **🔷 TypeScript First**: Full type safety and IntelliSense out of the box
17
- - **🔄 Reactive State**: Simple but powerful reactive state management
16
+ - **🔄 Reactive State**: Simple but powerful reactive state management with `createState` and `computed`
18
17
  - **🌲 Tree-Shakeable**: Import only what you need for optimal bundle size
19
18
  - **🚀 Full-Stack Ready**: Built-in dev server, HMR, build tool, and REST API
20
19
  - **🔥 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
20
+ - **🏗️ Build System**: Integrated esbuild for fast production builds
21
+ - **🌐 ServerRouter**: Built-in server-side routing for REST APIs
22
+ - **🔌 WebSocket Support**: Real-time communication via WebSocket
23
+ - **🎨 CSS-in-JS**: Type-safe styling with `CreateStyle`
24
+ - **🛣️ Client Router**: Hash and history mode routing with guards
25
+ - **📦 Modular Exports**: Import from specific paths (`elit/dom`, `elit/router`, `elit/state`)
25
26
 
26
27
  ## Installation
27
28
 
@@ -102,17 +103,16 @@ export default defineConfig({
102
103
  - 📦 **Tree-Shakeable**: Import only what you need
103
104
  - 🎮 **DOM Utilities**: Convenient helper functions
104
105
 
105
- ### Full-Stack Tools
106
+ ### Development Tools
106
107
 
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
108
+ - 🔥 **Hot Module Replacement**: Instant development feedback with automatic reload
109
+ - 🏗️ **Build System**: Integrated esbuild for fast production builds
110
+ - 🌐 **ServerRouter**: Built-in REST API routing for server-side logic
111
+ - 🔧 **Middleware Support**: Add custom middleware to the ServerRouter
112
+ - 🔌 **WebSocket Server**: Built-in WebSocket support for real-time features
113
+ - 📁 **Static File Server**: Efficient static file serving with proper MIME types
114
+ - 🎯 **Smart Defaults**: Works with minimal configuration
115
+ - 📦 **TypeScript Compilation**: Automatic TypeScript compilation with esbuild
116
116
 
117
117
  ## Quick Start
118
118
 
@@ -135,7 +135,7 @@ npm install elit
135
135
  Create `src/main.ts`:
136
136
 
137
137
  ```typescript
138
- import { div, h1, button, createState, reactive, domNode } from 'elit';
138
+ import { div, h1, button, createState, reactive, dom } from 'elit';
139
139
 
140
140
  const count = createState(0);
141
141
 
@@ -149,7 +149,8 @@ const app = div({ className: 'app' },
149
149
  )
150
150
  );
151
151
 
152
- domNode.render('#app', app);
152
+ // Render to DOM
153
+ dom.render('#app', app);
153
154
  ```
154
155
 
155
156
  Create `index.html`:
@@ -184,7 +185,7 @@ npm install elit
184
185
  ```
185
186
 
186
187
  ```typescript
187
- import { div, h1, p, button, createState, reactive, domNode } from 'elit';
188
+ import { div, h1, p, button, createState, reactive, dom } from 'elit';
188
189
 
189
190
  // Create reactive state
190
191
  const count = createState(0);
@@ -202,7 +203,7 @@ const app = div({ className: 'app' },
202
203
  );
203
204
 
204
205
  // Render to DOM
205
- domNode.render('#app', app);
206
+ dom.render('#app', app);
206
207
  ```
207
208
 
208
209
  ### CDN Usage
@@ -216,7 +217,7 @@ domNode.render('#app', app);
216
217
  <body>
217
218
  <div id="app"></div>
218
219
  <script>
219
- const { div, h1, button, createState, reactive, domNode } = window;
220
+ const { div, h1, button, createState, reactive, dom } = window;
220
221
 
221
222
  const count = createState(0);
222
223
  const app = div(
@@ -226,7 +227,7 @@ domNode.render('#app', app);
226
227
  )
227
228
  );
228
229
 
229
- domNode.render('#app', app);
230
+ dom.render('#app', app);
230
231
  </script>
231
232
  </body>
232
233
  </html>
@@ -267,106 +268,142 @@ const deepState = createState({ nested: { value: 1 } }, { deep: true });
267
268
  ### Reactive Rendering
268
269
 
269
270
  ```typescript
270
- import { reactive, text, bindValue } from 'elit';
271
+ import { reactive, text, bindValue, bindChecked } from 'elit';
271
272
 
272
273
  const message = createState('Hello');
274
+ const isEnabled = createState(false);
273
275
 
274
276
  // Reactive element - re-renders when state changes
275
277
  const display = reactive(message, (value) =>
276
278
  div({ className: 'message' }, value)
277
279
  );
278
280
 
279
- // Reactive text
281
+ // Reactive text node
280
282
  const label = text(message);
281
283
 
282
284
  // Two-way binding for inputs
283
285
  const inputEl = input({ type: 'text', ...bindValue(message) });
286
+ const checkbox = input({ type: 'checkbox', ...bindChecked(isEnabled) });
284
287
  ```
285
288
 
286
289
  ### Shared State (Real-time Sync)
287
290
 
288
- **Requires `elit-server`** - Shared state syncs automatically between backend and frontend via WebSocket:
291
+ Shared state automatically syncs between server and client via WebSocket:
292
+
293
+ **Client-side:**
289
294
 
290
295
  ```typescript
291
296
  import { createSharedState, reactive } from 'elit';
292
297
 
293
- // Create shared state (auto-connects to elit-server)
298
+ // Create shared state (auto-connects to WebSocket server)
294
299
  const counter = createSharedState('counter', 0);
295
- const todos = createSharedState('todos', []);
300
+ const users = createSharedState('users', []);
296
301
 
297
302
  // Use with reactive rendering
298
303
  const app = div(
299
304
  reactive(counter.state, value =>
300
305
  div(`Counter: ${value}`)
301
306
  ),
302
- button({ onclick: () => counter.value++ }, 'Increment')
307
+ button({ onclick: () => counter.set(counter.state.value + 1) }, 'Increment')
303
308
  );
304
309
 
305
310
  // Listen to changes
306
- counter.onChange((newValue, oldValue) => {
307
- console.log(`${oldValue} ${newValue}`);
311
+ counter.onChange((newValue) => {
312
+ console.log('Counter changed to:', newValue);
308
313
  });
309
314
 
310
- // Update from any client - syncs to all
311
- counter.value++;
315
+ // Update from any client - automatically syncs to all connected clients
316
+ counter.set(10);
312
317
  ```
313
318
 
314
- **Backend (Node.js with elit-server):**
319
+ **Server-side:**
315
320
 
316
- ```javascript
317
- const { createDevServer } = require('elit-server');
321
+ ```typescript
322
+ import { createDevServer, StateManager } from 'elit';
318
323
 
319
324
  const server = createDevServer({ port: 3000 });
320
325
 
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++;
326
+ // StateManager is built-in and handles WebSocket connections
327
+ // All clients with matching shared state keys will sync automatically
332
328
  ```
333
329
 
334
- ### elit-server - Development Server
330
+ ### Development Server with REST API
335
331
 
336
- Full-featured development server with HMR, REST API, and real-time features:
332
+ Elit includes a built-in development server with HMR, WebSocket support, and REST API routing:
337
333
 
338
- ```javascript
339
- const { createDevServer, Router, cors, logger } = require('elit-server');
334
+ **Server Configuration (server.ts):**
335
+
336
+ ```typescript
337
+ import { createDevServer, ServerRouter, cors, logger, json } from 'elit';
340
338
 
341
339
  // Create REST API router
342
- const api = new Router();
340
+ const api = new ServerRouter();
343
341
 
344
342
  // Add middleware
345
- api.use(cors());
343
+ api.use(cors({ origin: '*', methods: ['GET', 'POST', 'PUT', 'DELETE'] }));
346
344
  api.use(logger());
347
345
 
348
- // Define routes
346
+ // Define API routes with helper functions
349
347
  api.get('/api/users', (ctx) => {
350
- return { success: true, users: [...] };
348
+ json(ctx, { success: true, users: [] });
351
349
  });
352
350
 
353
- api.post('/api/users', (ctx) => {
351
+ api.post('/api/users', async (ctx) => {
354
352
  const user = ctx.body;
355
- return { success: true, user };
353
+ json(ctx, { success: true, user });
356
354
  });
357
355
 
358
- // Create server with API
356
+ // Create development server
359
357
  const server = createDevServer({
360
358
  port: 3000,
361
- root: __dirname,
362
- api,
363
- logging: true
359
+ root: './src',
360
+ open: true,
361
+ router: api
364
362
  });
363
+ ```
364
+
365
+ **Available Middleware:**
366
+
367
+ ```typescript
368
+ import {
369
+ cors, // CORS headers
370
+ logger, // Request logging
371
+ errorHandler, // Error handling
372
+ rateLimit, // Rate limiting
373
+ bodyLimit, // Request body size limit
374
+ cacheControl, // Cache headers
375
+ compress, // Gzip compression
376
+ security // Security headers
377
+ } from 'elit';
378
+
379
+ // Example usage
380
+ api.use(cors({ origin: '*' }));
381
+ api.use(logger({ format: 'detailed' }));
382
+ api.use(rateLimit({ max: 100, windowMs: 60000 }));
383
+ api.use(bodyLimit({ limit: 1024 * 1024 })); // 1MB
384
+ api.use(compress());
385
+ api.use(security());
386
+ ```
365
387
 
366
- // Access shared state
367
- const counter = server.state.create('counter', {
368
- initial: 0,
369
- validate: (value) => typeof value === 'number'
388
+ **Helper Functions:**
389
+
390
+ ```typescript
391
+ import { json, sendText, html, status } from 'elit';
392
+
393
+ api.get('/api/data', (ctx) => {
394
+ json(ctx, { message: 'Hello' }); // JSON response
395
+ });
396
+
397
+ api.get('/text', (ctx) => {
398
+ sendText(ctx, 'Hello World'); // Text response
399
+ });
400
+
401
+ api.get('/page', (ctx) => {
402
+ html(ctx, '<h1>Hello</h1>'); // HTML response
403
+ });
404
+
405
+ api.get('/error', (ctx) => {
406
+ status(ctx, 404, 'Not Found'); // Custom status
370
407
  });
371
408
  ```
372
409
 
@@ -374,41 +411,16 @@ const counter = server.state.create('counter', {
374
411
 
375
412
  ```bash
376
413
  # Start dev server
377
- npx elit-dev
414
+ npx elit dev
378
415
 
379
416
  # Custom port
380
- npx elit-dev --port 8080
417
+ npx elit dev --port 8080
381
418
 
382
419
  # Custom root directory
383
- npx elit-dev --root ./public
420
+ npx elit dev --root ./public
384
421
 
385
422
  # 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());
423
+ npx elit dev --no-open
412
424
  ```
413
425
 
414
426
  ### Server-Side Rendering
@@ -478,7 +490,15 @@ const btn = button({ className: buttonClass }, 'Click me');
478
490
  ### Performance Utilities
479
491
 
480
492
  ```typescript
481
- import { batchRender, renderChunked, createVirtualList, throttle, debounce } from 'elit';
493
+ import {
494
+ batchRender,
495
+ renderChunked,
496
+ createVirtualList,
497
+ throttle,
498
+ debounce,
499
+ lazy,
500
+ cleanupUnused
501
+ } from 'elit';
482
502
 
483
503
  // Batch render multiple elements
484
504
  batchRender('#container', elements);
@@ -488,7 +508,7 @@ renderChunked('#container', largeArray, 5000, (current, total) => {
488
508
  console.log(`Rendered ${current}/${total}`);
489
509
  });
490
510
 
491
- // Virtual scrolling
511
+ // Virtual scrolling for 100k+ items
492
512
  const virtualList = createVirtualList(
493
513
  container,
494
514
  items,
@@ -497,9 +517,61 @@ const virtualList = createVirtualList(
497
517
  5 // buffer size
498
518
  );
499
519
 
520
+ // Lazy loading components
521
+ const LazyComponent = lazy(() => import('./HeavyComponent'));
522
+
500
523
  // Throttle and debounce
501
524
  const throttledFn = throttle(handleScroll, 100);
502
525
  const debouncedFn = debounce(handleInput, 300);
526
+
527
+ // Cleanup unused DOM elements
528
+ const cleaned = cleanupUnused(rootElement);
529
+ console.log(`Cleaned ${cleaned} elements`);
530
+ ```
531
+
532
+ ### Additional Features
533
+
534
+ **DOM Utilities:**
535
+
536
+ ```typescript
537
+ import { doc, el, els, createEl, elId, elClass, fragment } from 'elit';
538
+
539
+ // Query selectors
540
+ const element = el('.my-class'); // querySelector
541
+ const elements = els('.my-class'); // querySelectorAll
542
+ const byId = elId('my-id'); // getElementById
543
+ const byClass = elClass('my-class'); // getElementsByClassName
544
+
545
+ // Create elements
546
+ const div = createEl('div'); // createElement
547
+ const frag = fragment(); // createDocumentFragment
548
+
549
+ // Access document
550
+ doc.title = 'New Title';
551
+ ```
552
+
553
+ **Effect System:**
554
+
555
+ ```typescript
556
+ import { createState, effect } from 'elit';
557
+
558
+ const count = createState(0);
559
+
560
+ // Run side effects when state changes
561
+ effect(() => {
562
+ console.log('Count is now:', count.value);
563
+ });
564
+ ```
565
+
566
+ **Reactive As (Advanced):**
567
+
568
+ ```typescript
569
+ import { reactiveAs } from 'elit';
570
+
571
+ // Use different reactive context
572
+ const display = reactiveAs(customState, customContext, (value) =>
573
+ div(value)
574
+ );
503
575
  ```
504
576
 
505
577
  ### JSON Rendering
@@ -530,7 +602,7 @@ renderVNode('#app', {
530
602
  ### Head Management
531
603
 
532
604
  ```typescript
533
- import { setTitle, addMeta, addLink, addStyle, renderToHead } from 'elit';
605
+ import { setTitle, addMeta, addLink, addStyle } from 'elit';
534
606
 
535
607
  setTitle('My App');
536
608
  addMeta({ name: 'description', content: 'My awesome app' });
@@ -538,27 +610,6 @@ addLink({ rel: 'stylesheet', href: '/styles.css' });
538
610
  addStyle('body { margin: 0; }');
539
611
  ```
540
612
 
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
613
  ## Available Elements
563
614
 
564
615
  ### HTML Elements (100+)
@@ -618,7 +669,7 @@ When loaded via script tag, all exports are available on the `window` object:
618
669
  ```html
619
670
  <script src="https://unpkg.com/elit@latest/dist/index.global.js"></script>
620
671
  <script>
621
- const { div, span, createState, domNode } = window;
672
+ const { div, span, createState, dom } = window;
622
673
  // or use DomLib global namespace
623
674
  const app = DomLib.div('Hello');
624
675
  </script>
@@ -794,25 +845,27 @@ const isProd = import.meta.env.PROD;
794
845
 
795
846
  | Feature | Elit | Vite + React | Next.js | SvelteKit |
796
847
  |---------|----------|--------------|---------|-----------|
797
- | Bundle Size | 30KB | ~140KB+ | ~200KB+ | ~15KB* |
798
- | Zero Dependencies | | | | |
848
+ | Runtime Size | Lightweight | ~140KB+ | ~200KB+ | ~15KB* |
849
+ | Dependencies | Minimal (5) | Many | Many | Many |
799
850
  | Dev Server | ✅ Built-in | ✅ Vite | ✅ Built-in | ✅ Built-in |
800
851
  | HMR | ✅ | ✅ | ✅ | ✅ |
801
- | Build Tool | ✅ Built-in | ✅ Vite | ✅ Built-in | ✅ Built-in |
852
+ | Build Tool | ✅ esbuild | ✅ Vite | ✅ Turbopack | ✅ Vite |
802
853
  | REST API | ✅ Built-in | ❌ | ✅ | ✅ |
854
+ | Middleware | ✅ Built-in | ❌ | ✅ | ✅ |
855
+ | WebSocket | ✅ Built-in | ❌ | ❌ | ❌ |
856
+ | Shared State | ✅ Built-in | ❌ | ❌ | ❌ |
803
857
  | TypeScript | ✅ | ✅ | ✅ | ✅ |
804
858
  | SSR | ✅ | ❌ | ✅ | ✅ |
805
859
  | Learning Curve | Easy | Medium | Medium | Easy |
806
860
 
807
- *Svelte requires compilation
861
+ *Svelte requires compilation step
808
862
 
809
863
  ## Documentation
810
864
 
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)
865
+ - 📚 [Full Documentation](https://d-osc.github.io/elit)
866
+ - ⚡ [Quick Start](https://d-osc.github.io/elit#/docs)
867
+ - 📖 [API Reference](https://d-osc.github.io/elit#/api)
868
+ - 🎮 [Interactive Examples](https://d-osc.github.io/elit#/examples)
816
869
 
817
870
  ## Changelog
818
871
 
@@ -854,11 +907,10 @@ Example applications demonstrating Elit features:
854
907
 
855
908
  ## Links
856
909
 
857
- - 📦 [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)
910
+ - 📦 [npm Package](https://www.npmjs.com/package/elit)
911
+ - 🐙 [GitHub Repository](https://github.com/d-osc/elit)
912
+ - 📚 [Documentation](https://d-osc.github.io/elit)
913
+ - 💬 Community & Issues: [GitHub Discussions](https://github.com/d-osc/elit/discussions)
862
914
 
863
915
  ## Contributing
864
916
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elit",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Optimized lightweight library for creating DOM elements with reactive state",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",