@lipsjs/lips 0.1.1 → 0.3.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 (70) hide show
  1. package/README.md +185 -85
  2. package/dist/lips.js +6274 -0
  3. package/dist/lips.js.map +53 -0
  4. package/dist/lips.min.js +13 -2
  5. package/dist/lips.min.js.map +47 -43
  6. package/dist/mf2.min.js +4 -0
  7. package/dist/mf2.min.js.map +38 -0
  8. package/dist/precompile.min.js +23 -0
  9. package/dist/precompile.min.js.map +14 -0
  10. package/dist/runtime.min.js +5 -0
  11. package/dist/runtime.min.js.map +20 -0
  12. package/dist/stylis.min.js +3 -0
  13. package/dist/stylis.min.js.map +16 -0
  14. package/dist/types/events.d.ts +1 -1
  15. package/dist/types/i18n/engine.d.ts +14 -0
  16. package/dist/types/i18n/index.d.ts +122 -5
  17. package/dist/types/i18n/intl.d.ts +1 -0
  18. package/dist/types/i18n/lookup.d.ts +22 -0
  19. package/dist/types/ir/compiler.d.ts +226 -0
  20. package/dist/types/ir/expression.d.ts +149 -0
  21. package/dist/types/ir/facade.d.ts +138 -0
  22. package/dist/types/ir/host.d.ts +75 -0
  23. package/dist/types/ir/index.d.ts +18 -0
  24. package/dist/types/ir/parser.d.ts +124 -0
  25. package/dist/types/ir/policy.d.ts +95 -0
  26. package/dist/types/ir/router.d.ts +47 -0
  27. package/dist/types/ir/runtime.d.ts +130 -0
  28. package/dist/types/ir/signal.d.ts +28 -0
  29. package/dist/types/ir/style.d.ts +119 -0
  30. package/dist/types/ir/swap.d.ts +28 -0
  31. package/dist/types/ir/tree.d.ts +51 -0
  32. package/dist/types/lips.d.ts +33 -37
  33. package/dist/types/lynx/a11y.d.ts +61 -0
  34. package/dist/types/lynx/background.d.ts +71 -0
  35. package/dist/types/lynx/main.d.ts +46 -0
  36. package/dist/types/lynx/protocol.d.ts +52 -0
  37. package/dist/types/lynx/style.d.ts +49 -0
  38. package/dist/types/lynx/template.d.ts +37 -0
  39. package/dist/types/mf2.d.ts +14 -0
  40. package/dist/types/precompile.d.ts +85 -0
  41. package/dist/types/runtime.d.ts +16 -0
  42. package/dist/types/stylesheet.d.ts +21 -41
  43. package/dist/types/stylis.d.ts +2 -0
  44. package/dist/types/types.d.ts +176 -185
  45. package/dist/types/untrusted.d.ts +17 -0
  46. package/dist/untrusted.min.js +5 -0
  47. package/dist/untrusted.min.js.map +13 -0
  48. package/package.json +46 -10
  49. package/dist/test.component.min.js +0 -3
  50. package/dist/test.component.min.js.map +0 -50
  51. package/dist/test.stress.min.js +0 -476
  52. package/dist/test.stress.min.js.map +0 -50
  53. package/dist/types/component.d.ts +0 -107
  54. package/dist/types/constants.d.ts +0 -23
  55. package/dist/types/dws.d.ts +0 -14
  56. package/dist/types/iuc/index.d.ts +0 -25
  57. package/dist/types/iuc/tick.d.ts +0 -38
  58. package/dist/types/iuc.d.ts +0 -25
  59. package/dist/types/metrics.d.ts +0 -50
  60. package/dist/types/preprocess.d.ts +0 -2
  61. package/dist/types/signal.d.ts +0 -30
  62. package/dist/types/syntax/async.d.ts +0 -16
  63. package/dist/types/syntax/for.d.ts +0 -25
  64. package/dist/types/syntax/if.d.ts +0 -14
  65. package/dist/types/syntax/router.d.ts +0 -40
  66. package/dist/types/syntax/switch.d.ts +0 -16
  67. package/dist/types/tick.d.ts +0 -38
  68. package/dist/types/tps.d.ts +0 -11
  69. package/dist/types/uqs.d.ts +0 -37
  70. 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
16
 
17
- ## 🚀 Quick Start
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
26
+
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,189 @@ 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/untrusted` | opt-in policy for templates you did not write ([RFC-007](design/untrusted-templates.md)) | ~9 KB |
74
+ | `@lipsjs/lips/dev` | unminified full build | — |
75
+
76
+ ## 🧩 Template syntax
63
77
 
64
78
  ```html
65
- <script src="https://cdn.jsdelivr.net/npm/@lipsjs/lips"></script>
79
+ <!-- interpolation & attributes -->
80
+ <p title=state.title>Hello {state.name}!</p>
81
+
82
+ <!-- events: named handler (+args) or inline arrow -->
83
+ <button on-click(select, item.id)>pick</button>
84
+ <button on-click(() => state.count++)>+</button>
85
+
86
+ <!-- conditionals -->
87
+ <if(state.ready)>…</if>
88
+ <else-if(state.loading)>…</else-if>
89
+ <else>…</else>
90
+
91
+ <!-- keyed lists: node identity & child state survive reorders -->
92
+ <for [item, i] in=state.items by="id">
93
+ <li>{i}: {item.label}</li>
94
+ </for>
95
+
96
+ <!-- switch, async, scoped vars, dynamic tags -->
97
+ <switch(state.tab)><case is="a">…</case><default>…</default></switch>
98
+ <async await(context.load())><loading>…</loading><then [data]>…</then><catch [e]>…</catch></async>
99
+ <let doubled={ state.n * 2 }/>
100
+ <{state.page} params=state.params/>
66
101
  ```
67
102
 
68
- ## 📖 Documentation
103
+ Components compose with **slots** (`<{input.renderer}/>`) and **events**
104
+ (`this.emit('picked', …)` → parent `on-picked(...)`). Full lifecycle:
105
+ `onCreate · onInput · onMount · onRender · onUpdate · onAttach · onDetach · onContext ·
106
+ onError · onDestroy`.
69
107
 
70
- For comprehensive documentation, examples, and API reference, visit:
108
+ ### Constants
71
109
 
72
- [Full Lips Documentation](https://lips-js.github.io)
110
+ `static` holds values that never change — reading them creates no subscription:
73
111
 
74
- ## 🏗️ Building from Source
112
+ ```js
113
+ {
114
+ static: { api: 'https://api.example.com', pageSize: 25 },
115
+ handler: { load(){ return fetch(`${this.static.api}/items`) } },
116
+ default: `<p>{static.pageSize} per page</p>`
117
+ }
118
+ ```
75
119
 
76
- Lips is developed using [Bun](https://bun.sh) runtime environment.
120
+ Use `_static` only in the named-export form — `export const static` is a
121
+ SyntaxError, since `static` is reserved in strict mode. Both spellings are the
122
+ same field.
77
123
 
78
- ```bash
79
- # Clone the repository
80
- git clone https://github.com/fabrice8/lips.git
81
- cd lips
124
+ ### The component bus runs both ways
125
+
126
+ A rendered component's bus is bidirectional, so the handle you hold can send
127
+ commands in, not just receive events out:
128
+
129
+ ```js
130
+ const editor = lips.render('editor', template).appendTo('#app')
131
+
132
+ // out — the component reports
133
+ editor.on('saved', doc => console.log( doc.id ))
134
+
135
+ // in — the holder commands
136
+ editor.emit('reset')
137
+ editor.emit('focus', 'title')
138
+ ```
139
+
140
+ ```js
141
+ handler: {
142
+ onCreate(){
143
+ this.on('reset', () => this.state.draft = '')
144
+ this.on('focus', field => this.node[0].querySelector(`[name="${field}"]`)?.focus() )
145
+ }
146
+ }
147
+ ```
148
+
149
+ Inbound events reach listeners the component registered with `this.on(…)` —
150
+ **not** handler methods by name, so what a component accepts stays an explicit
151
+ contract. This is the way to drive a component imperatively; its internals are
152
+ deliberately not exposed.
82
153
 
83
- # Install dependencies
84
- npm install
154
+ ## ⚡ Precompile & CSP
85
155
 
86
- # Make sure you have Bun installed
87
- # If not: curl -fsSL https://bun.sh/install | bash
156
+ Compile templates to IR at build time — no runtime parsing, and with
157
+ `mode: 'interpreted'` no `eval`/`Function`, so the app runs under `script-src` without
158
+ `unsafe-eval`. That is CSP-safety, not a sandbox: both modes are for templates you
159
+ trust. For one you did not write — a generated UI, a partner's embed — see below.
88
160
 
89
- # Development with watch mode
90
- bun run dev
161
+ ```js
162
+ import { precompile } from '@lipsjs/lips/precompile'
163
+ const card = precompile({ state: {/*…*/}, default: `<div>…</div>` }).template // { ir, state, … }
164
+ ```
165
+
166
+ Or let the bundler do it (Vite/Rollup) for `.lips` single-file components:
167
+
168
+ ```js
169
+ // vite.config.js
170
+ import { lipsPlugin } from '@lipsjs/lips/precompile'
171
+ export default { plugins: [ lipsPlugin() ] }
172
+ ```
173
+
174
+ ```js
175
+ import Card from './card.lips' // already-compiled IR
176
+ lips.register('card', Card)
177
+ ```
178
+
179
+ ## 🛡 Untrusted templates
180
+
181
+ A template you did not write runs under a policy:
182
+
183
+ ```js
184
+ import Lips from '@lipsjs/lips'
185
+ import { untrusted, untrustedPolicy } from '@lipsjs/lips/untrusted'
186
+
187
+ const embed = new Lips({ untrusted: untrusted() })
188
+ const strict = new Lips({ untrusted: untrusted({ ...untrustedPolicy, url: sameOriginOnly }) })
189
+ ```
190
+
191
+ It reaches the data and functions you hand it, a few pure globals, and its own
192
+ subtree through the template language — not the page, not the realm's prototypes,
193
+ not script. What it may not do is reported as a diagnostic with `line`/`col`/`code`/`hint`,
194
+ and refused again at runtime. What Lips leaves to CSP and to the page is listed in
195
+ [RFC-007](design/untrusted-templates.md).
91
196
 
92
- # Build for production
93
- bun run compile
197
+ ## 🔥 Hot-swap
198
+
199
+ Re-render a live component against a revised template, keeping component state:
200
+
201
+ ```js
202
+ const app = lips.render('editor', template).appendTo('#app')
203
+ const { changes } = app.swap(newIR) // patches only what differs
204
+ ```
205
+
206
+ ## 📖 Documentation
207
+
208
+ [Full Lips documentation](https://lips-js.github.io)
209
+
210
+ ## 🏗️ Building from source
211
+
212
+ Developed with [Bun](https://bun.sh).
213
+
214
+ ```bash
215
+ git clone https://github.com/fabrice8/lips.git
216
+ cd lips
217
+ bun install
94
218
 
95
- # Build type declarations
96
- bun run build:declaration
219
+ bun run dev # watch build
220
+ bun run build # production bundles
221
+ bun run test # test suite
222
+ bun run size # size-budget check
97
223
  ```
98
224
 
99
225
  ## 🤝 Contributing
100
226
 
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
227
+ Contributions welcome — fork, branch, and open a PR. Please keep the runtime dependency
228
+ footprint small, add tests for new behavior, and run `bun run test` before submitting.
127
229
 
128
230
  ## 📄 License
129
231
 
130
- This project is licensed under the MIT License - see the LICENSE file for details.
232
+ MIT — see [LICENSE](LICENSE).
131
233
 
132
234
  ## 🙏 Acknowledgements
133
235
 
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
236
+ - [Bun](https://bun.sh) — runtime & bundler
237
+ - [Stylis](https://github.com/thysultan/stylis) — CSS preprocessor
238
+ - [MarkoJS](https://github.com/marko-js/marko) — inspiring template syntax
239
+ - [SolidJS](https://github.com/solidjs/solid) — signal-based fine-grained reactivity
140
240
 
141
241
  ---
142
242
 
143
- Lips - Reactive UI without the complexity. Created with ❤️ by [Fabrice K.E.M](https://github.com/fabrice8)
243
+ Lips — reactive UI without the complexity. Created with ❤️ by [Fabrice K.E.M](https://github.com/fabrice8)