@lipsjs/lips 0.1.1 → 0.2.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 (47) hide show
  1. package/README.md +119 -85
  2. package/dist/lips.js +3836 -0
  3. package/dist/lips.js.map +28 -0
  4. package/dist/lips.min.js +9 -2
  5. package/dist/lips.min.js.map +22 -43
  6. package/dist/precompile.min.js +20 -0
  7. package/dist/precompile.min.js.map +13 -0
  8. package/dist/runtime.min.js +4 -0
  9. package/dist/runtime.min.js.map +19 -0
  10. package/dist/types/events.d.ts +1 -1
  11. package/dist/types/ir/compiler.d.ts +153 -0
  12. package/dist/types/ir/expression.d.ts +120 -0
  13. package/dist/types/ir/facade.d.ts +94 -0
  14. package/dist/types/ir/index.d.ts +15 -0
  15. package/dist/types/ir/parser.d.ts +124 -0
  16. package/dist/types/ir/router.d.ts +47 -0
  17. package/dist/types/ir/runtime.d.ts +95 -0
  18. package/dist/types/ir/signal.d.ts +26 -0
  19. package/dist/types/ir/swap.d.ts +23 -0
  20. package/dist/types/lips.d.ts +16 -37
  21. package/dist/types/precompile.d.ts +60 -0
  22. package/dist/types/runtime.d.ts +16 -0
  23. package/dist/types/stylesheet.d.ts +24 -40
  24. package/dist/types/types.d.ts +49 -185
  25. package/package.json +29 -10
  26. package/dist/test.component.min.js +0 -3
  27. package/dist/test.component.min.js.map +0 -50
  28. package/dist/test.stress.min.js +0 -476
  29. package/dist/test.stress.min.js.map +0 -50
  30. package/dist/types/component.d.ts +0 -107
  31. package/dist/types/constants.d.ts +0 -23
  32. package/dist/types/dws.d.ts +0 -14
  33. package/dist/types/iuc/index.d.ts +0 -25
  34. package/dist/types/iuc/tick.d.ts +0 -38
  35. package/dist/types/iuc.d.ts +0 -25
  36. package/dist/types/metrics.d.ts +0 -50
  37. package/dist/types/preprocess.d.ts +0 -2
  38. package/dist/types/signal.d.ts +0 -30
  39. package/dist/types/syntax/async.d.ts +0 -16
  40. package/dist/types/syntax/for.d.ts +0 -25
  41. package/dist/types/syntax/if.d.ts +0 -14
  42. package/dist/types/syntax/router.d.ts +0 -40
  43. package/dist/types/syntax/switch.d.ts +0 -16
  44. package/dist/types/tick.d.ts +0 -38
  45. package/dist/types/tps.d.ts +0 -11
  46. package/dist/types/uqs.d.ts +0 -37
  47. package/dist/types/utils.d.ts +0 -25
package/README.md CHANGED
@@ -1,51 +1,53 @@
1
- # Lips: Fast, Lightweight Reactive UI Framework
1
+ # Lips — Fast, Lightweight Reactive UI Framework
2
2
 
3
- Lips is a modern, runtime-based UI framework that brings fine-grained reactivity without the need for build steps. Create dynamic web applications with a simple, declarative syntax that feels familiar to HTML developers while providing powerful reactive capabilities.
3
+ Lips is a runtime, fine-grained reactive UI framework with an HTML-native template
4
+ syntax. Import it and build — **no build step required** — or precompile your templates
5
+ ahead of time for CSP-safe, parse-free startup.
4
6
 
5
- ## ✨ Key Features
7
+ Under the hood a template compiles to a small **IR** (intermediate representation): the
8
+ DOM is cloned from static skeletons and each binding is its own effect over per-key
9
+ signals, so a state change updates only what actually read it — no virtual DOM, no diffing.
6
10
 
7
- - **Zero Build Step**: Just import the script and start building
8
- - **Fine-Grained Reactivity**: Only updates what changed, not the entire component
9
- - **Intuitive Template Syntax**: Simple yet powerful templating that's familiar to HTML developers
10
- - **TypeScript Support**: Full type definitions for better developer experience
11
- - **Built-in Performance Monitoring**: Track rendering performance with integrated benchmarking
12
- - **Flexible Component Architecture**: Object-based or ES Module syntax for your components
13
- - **Context API**: Share state across components without prop drilling
14
- - **Lifecycle Hooks**: Fine-grained control over component behavior
15
- - **Built-in Routing & i18n**: Everything you need in a single package
11
+ ```
12
+ template string ──parse──▶ AST ──compile──▶ IR ──render──▶ DOM
13
+ ```
14
+
15
+ ## ✨ Highlights
16
+
17
+ - **Zero build step** — import and go; templates render at runtime
18
+ - **Fine-grained reactivity** — per-key signals; updates are O(bindings that changed)
19
+ - **HTML-native syntax** — element-shaped control flow (`<if>`, `<for>`, `<switch>`, `<async>`), not an attribute DSL
20
+ - **Tiny** — ~21 KB gzip full, ~12 KB gzip precompiled-only, one dependency
21
+ - **Serializable components** — a template is a plain object; the compiled IR is JSON
22
+ - **Precompile + CSP mode** — build templates to IR; run with no `eval`/`Function` under a strict CSP
23
+ - **Hot-swap** — `instance.swap(newIR)` re-renders only what changed, preserving state
24
+ - **Batteries included** — router, i18n, macros, scoped styles, slots, component events
25
+ - **TypeScript** — full type definitions
16
26
 
17
- ## 🚀 Quick Start
27
+ ## 🚀 Quick start
18
28
 
19
29
  ```html
20
30
  <!DOCTYPE html>
21
31
  <html>
22
- <head>
23
- <title>My Lips App</title>
24
- </head>
25
32
  <body>
26
33
  <div id="app"></div>
27
-
34
+
28
35
  <script type="module">
29
- // Import from CDN directly in the module script
30
36
  import Lips from 'https://cdn.jsdelivr.net/npm/@lipsjs/lips'
31
37
 
32
- const lips = new Lips();
33
-
34
- // <counter/> component
35
- const counter = {
38
+ const lips = new Lips()
39
+
40
+ lips.root({
36
41
  state: { count: 0 },
37
42
  handler: {
38
- increment() { this.state.count++; }
43
+ increment(){ this.state.count++ }
39
44
  },
40
45
  default: `
41
46
  <div>
42
47
  <h2>Count: {state.count}</h2>
43
48
  <button on-click(increment)>Increment</button>
44
- </div>
45
- `
46
- };
47
-
48
- lips.root(counter, '#app');
49
+ </div>`
50
+ }, '#app')
49
51
  </script>
50
52
  </body>
51
53
  </html>
@@ -53,91 +55,123 @@ Lips is a modern, runtime-based UI framework that brings fine-grained reactivity
53
55
 
54
56
  ## 📦 Installation
55
57
 
56
- ### Via NPM
57
-
58
58
  ```bash
59
59
  npm install @lipsjs/lips
60
60
  ```
61
61
 
62
- ### Via CDN
62
+ ```js
63
+ import Lips from '@lipsjs/lips'
64
+ ```
65
+
66
+ ### Entry points
67
+
68
+ | Import | Contents | gzip |
69
+ |---|---|---|
70
+ | `@lipsjs/lips` | full: runtime + parser/compiler + styles + router | ~21 KB |
71
+ | `@lipsjs/lips/runtime` | precompiled-only: no parser/compiler (CSP-friendly) | ~12 KB |
72
+ | `@lipsjs/lips/precompile` | build-time helpers + Vite/Rollup plugin | — |
73
+ | `@lipsjs/lips/dev` | unminified full build | — |
74
+
75
+ ## 🧩 Template syntax
63
76
 
64
77
  ```html
65
- <script src="https://cdn.jsdelivr.net/npm/@lipsjs/lips"></script>
78
+ <!-- interpolation & attributes -->
79
+ <p title=state.title>Hello {state.name}!</p>
80
+
81
+ <!-- events: named handler (+args) or inline arrow -->
82
+ <button on-click(select, item.id)>pick</button>
83
+ <button on-click(() => state.count++)>+</button>
84
+
85
+ <!-- conditionals -->
86
+ <if(state.ready)>…</if>
87
+ <else-if(state.loading)>…</else-if>
88
+ <else>…</else>
89
+
90
+ <!-- keyed lists: node identity & child state survive reorders -->
91
+ <for [item, i] in=state.items by="id">
92
+ <li>{i}: {item.label}</li>
93
+ </for>
94
+
95
+ <!-- switch, async, scoped vars, dynamic tags -->
96
+ <switch(state.tab)><case is="a">…</case><default>…</default></switch>
97
+ <async await(context.load())><loading>…</loading><then [data]>…</then><catch [e]>…</catch></async>
98
+ <let doubled={ state.n * 2 }/>
99
+ <{state.page} params=state.params/>
66
100
  ```
67
101
 
68
- ## 📖 Documentation
102
+ Components compose with **slots** (`<{input.renderer}/>`) and **events**
103
+ (`this.emit('picked', …)` → parent `on-picked(...)`). Full lifecycle:
104
+ `onCreate · onInput · onMount · onRender · onUpdate · onAttach · onDetach · onContext ·
105
+ onError · onDestroy`.
69
106
 
70
- For comprehensive documentation, examples, and API reference, visit:
107
+ ## ⚡ Precompile & CSP
71
108
 
72
- [Full Lips Documentation](https://lips-js.github.io)
109
+ Compile templates to IR at build time — no runtime parsing, and with
110
+ `mode: 'interpreted'` no `eval`/`Function`, so the app runs under `script-src` without
111
+ `unsafe-eval`.
73
112
 
74
- ## 🏗️ Building from Source
113
+ ```js
114
+ import { precompile } from '@lipsjs/lips/precompile'
115
+ const card = precompile({ state: {/*…*/}, default: `<div>…</div>` }).template // { ir, state, … }
116
+ ```
75
117
 
76
- Lips is developed using [Bun](https://bun.sh) runtime environment.
118
+ Or let the bundler do it (Vite/Rollup) for `.lips` single-file components:
77
119
 
78
- ```bash
79
- # Clone the repository
80
- git clone https://github.com/fabrice8/lips.git
81
- cd lips
120
+ ```js
121
+ // vite.config.js
122
+ import { lipsPlugin } from '@lipsjs/lips/precompile'
123
+ export default { plugins: [ lipsPlugin() ] }
124
+ ```
125
+
126
+ ```js
127
+ import Card from './card.lips' // already-compiled IR
128
+ lips.register('card', Card)
129
+ ```
130
+
131
+ ## 🔥 Hot-swap
132
+
133
+ Re-render a live component against a revised template, keeping component state:
82
134
 
83
- # Install dependencies
84
- npm install
135
+ ```js
136
+ const app = lips.render('editor', template).appendTo('#app')
137
+ const { changes } = app.swap(newIR) // patches only what differs
138
+ ```
139
+
140
+ ## 📖 Documentation
141
+
142
+ [Full Lips documentation](https://lips-js.github.io)
85
143
 
86
- # Make sure you have Bun installed
87
- # If not: curl -fsSL https://bun.sh/install | bash
144
+ ## 🏗️ Building from source
88
145
 
89
- # Development with watch mode
90
- bun run dev
146
+ Developed with [Bun](https://bun.sh).
91
147
 
92
- # Build for production
93
- bun run compile
148
+ ```bash
149
+ git clone https://github.com/fabrice8/lips.git
150
+ cd lips
151
+ bun install
94
152
 
95
- # Build type declarations
96
- bun run build:declaration
153
+ bun run dev # watch build
154
+ bun run build # production bundles
155
+ bun run test # test suite
156
+ bun run size # size-budget check
97
157
  ```
98
158
 
99
159
  ## 🤝 Contributing
100
160
 
101
- Contributions are welcome! Here's how you can help:
102
-
103
- 1. **Fork the repository**
104
- 2. **Create a feature branch**:
105
- ```bash
106
- git checkout -b feature/amazing-feature
107
- ```
108
- 3. **Commit your changes**:
109
- ```bash
110
- git commit -m 'Add some amazing feature'
111
- ```
112
- 4. **Push to the branch**:
113
- ```bash
114
- git push origin feature/amazing-feature
115
- ```
116
- 5. **Open a Pull Request**
117
-
118
- Please ensure your code follows the existing style and includes appropriate tests.
119
-
120
- ### Development Guidelines
121
-
122
- - Ensure you have [Bun](https://bun.sh) installed for development
123
- - Follow the TypeScript coding style
124
- - Add unit tests for new features
125
- - Maintain the zero-build philosophy for runtime usage
126
- - Update documentation for any new features or changes
161
+ Contributions welcome — fork, branch, and open a PR. Please keep the runtime dependency
162
+ footprint small, add tests for new behavior, and run `bun run test` before submitting.
127
163
 
128
164
  ## 📄 License
129
165
 
130
- This project is licensed under the MIT License - see the LICENSE file for details.
166
+ MIT — see [LICENSE](LICENSE).
131
167
 
132
168
  ## 🙏 Acknowledgements
133
169
 
134
- - [Bun](https://bun.sh) for the fast JavaScript runtime and bundler
135
- - [Cash-DOM](https://github.com/fabiospampinato/cash) for the lightweight jQuery alternative
136
- - [Stylis](https://github.com/thysultan/stylis) for the CSS preprocessor
137
- - [MarkoJS](https://github.com/marko-js/marko) for their inspiring syntax declaration struture.
138
- - [SolidJS](https://github.com/solidjs/solid) for the signal based reactivity concept.
139
- - All contributors who have helped make Lips better
170
+ - [Bun](https://bun.sh) — runtime & bundler
171
+ - [Stylis](https://github.com/thysultan/stylis) — CSS preprocessor
172
+ - [MarkoJS](https://github.com/marko-js/marko) — inspiring template syntax
173
+ - [SolidJS](https://github.com/solidjs/solid) — signal-based fine-grained reactivity
140
174
 
141
175
  ---
142
176
 
143
- Lips - Reactive UI without the complexity. Created with ❤️ by [Fabrice K.E.M](https://github.com/fabrice8)
177
+ Lips — reactive UI without the complexity. Created with ❤️ by [Fabrice K.E.M](https://github.com/fabrice8)