@lipsjs/lips 0.3.0 → 0.4.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.
- package/README.md +123 -9
- package/dist/lips.js +915 -669
- package/dist/lips.js.map +15 -12
- package/dist/lips.min.js +12 -12
- package/dist/lips.min.js.map +15 -12
- package/dist/lynx-background.min.js +3 -0
- package/dist/lynx-background.min.js.map +13 -0
- package/dist/lynx-main.min.js +3 -0
- package/dist/lynx-main.min.js.map +11 -0
- package/dist/lynx-plugin.mjs +1487 -0
- package/dist/lynx.min.js +51 -0
- package/dist/lynx.min.js.map +18 -0
- package/dist/mf2.min.js.map +1 -1
- package/dist/parts.min.js +19 -0
- package/dist/parts.min.js.map +11 -0
- package/dist/precompile.min.js +15 -15
- package/dist/precompile.min.js.map +8 -7
- package/dist/runtime.min.js +4 -4
- package/dist/runtime.min.js.map +11 -9
- package/dist/stylis.min.js.map +1 -1
- package/dist/types/component.d.ts +32 -0
- package/dist/types/ir/compiler.d.ts +2 -4
- package/dist/types/ir/facade.d.ts +63 -12
- package/dist/types/ir/host.d.ts +9 -1
- package/dist/types/ir/initial.d.ts +16 -0
- package/dist/types/ir/router.d.ts +2 -0
- package/dist/types/ir/tags.d.ts +16 -0
- package/dist/types/lips.d.ts +7 -7
- package/dist/types/lynx/a11y.d.ts +1 -0
- package/dist/types/lynx/background.d.ts +52 -3
- package/dist/types/lynx/main.d.ts +9 -5
- package/dist/types/lynx/plugin.d.ts +8 -0
- package/dist/types/lynx/protocol.d.ts +55 -4
- package/dist/types/lynx/style.d.ts +7 -0
- package/dist/types/lynx/template.d.ts +6 -0
- package/dist/types/lynx.d.ts +22 -0
- package/dist/types/parts/menu.d.ts +44 -0
- package/dist/types/parts/popover.d.ts +83 -0
- package/dist/types/parts.d.ts +16 -0
- package/dist/types/precompile.d.ts +8 -11
- package/dist/types/runtime.d.ts +1 -0
- package/dist/types/types.d.ts +181 -57
- package/dist/untrusted.min.js +4 -4
- package/dist/untrusted.min.js.map +7 -7
- package/package.json +29 -3
- package/dist/types/i18n/formatters.d.ts +0 -3
package/README.md
CHANGED
|
@@ -17,12 +17,12 @@ template string ──parse──▶ AST ──compile──▶ IR ──render
|
|
|
17
17
|
- **Zero build step** — import and go; templates render at runtime
|
|
18
18
|
- **Fine-grained reactivity** — per-key signals; updates are O(bindings that changed)
|
|
19
19
|
- **HTML-native syntax** — element-shaped control flow (`<if>`, `<for>`, `<switch>`, `<async>`), not an attribute DSL
|
|
20
|
-
- **
|
|
20
|
+
- **Small** — ~36 KB gzip full (compiler, styles, router, MessageFormat 2), ~16 KB precompiled-only
|
|
21
21
|
- **Serializable components** — a template is a plain object; the compiled IR is JSON
|
|
22
22
|
- **Precompile + CSP mode** — build templates to IR; run with no `eval`/`Function` under a strict CSP
|
|
23
23
|
- **Hot-swap** — `instance.swap(newIR)` re-renders only what changed, preserving state
|
|
24
24
|
- **Batteries included** — router, i18n, macros, scoped styles, slots, component events
|
|
25
|
-
- **TypeScript** —
|
|
25
|
+
- **TypeScript** — a component written in `register`/`render` is inferred: `this` typed in every handler, no wrapper
|
|
26
26
|
|
|
27
27
|
## 🚀 Quick start
|
|
28
28
|
|
|
@@ -67,12 +67,56 @@ import Lips from '@lipsjs/lips'
|
|
|
67
67
|
|
|
68
68
|
| Import | Contents | gzip |
|
|
69
69
|
|---|---|---|
|
|
70
|
-
| `@lipsjs/lips` | full: runtime + parser/compiler + styles + router | ~
|
|
71
|
-
| `@lipsjs/lips/runtime` | precompiled-only: no parser/compiler (CSP-friendly) | ~
|
|
70
|
+
| `@lipsjs/lips` | full: runtime + parser/compiler + styles + router + i18n | ~36 KB |
|
|
71
|
+
| `@lipsjs/lips/runtime` | precompiled-only: no parser/compiler (CSP-friendly) | ~16 KB |
|
|
72
72
|
| `@lipsjs/lips/precompile` | build-time helpers + Vite/Rollup plugin | — |
|
|
73
73
|
| `@lipsjs/lips/untrusted` | opt-in policy for templates you did not write ([RFC-007](design/untrusted-templates.md)) | ~9 KB |
|
|
74
|
+
| `@lipsjs/lips/lynx` | build-time Lynx pass: a template and a stylesheet held to what Lynx draws (RFC-006) | — |
|
|
75
|
+
| `@lipsjs/lips/lynx/main` | Lynx main thread: the applier over Element PAPI | ~2.8 KB |
|
|
76
|
+
| `@lipsjs/lips/lynx/background` | Lynx background thread: the host Lips renders into | ~5 KB |
|
|
77
|
+
| `@lipsjs/lips/lynx-plugin` | Rspeedy plugin: `*.lips.css` sheets and the page config Lips needs | — |
|
|
74
78
|
| `@lipsjs/lips/dev` | unminified full build | — |
|
|
75
79
|
|
|
80
|
+
## 🔷 TypeScript
|
|
81
|
+
|
|
82
|
+
A component is typed where it is written. Written in a `register`,
|
|
83
|
+
`render` or `root` call, Lips infers it: `state` and `static` from their
|
|
84
|
+
values, each handler from itself, and `this` in every handler from all
|
|
85
|
+
three, sibling handlers included. No annotation, no wrapper.
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
lips.register('counter', {
|
|
89
|
+
state: { count: 0 },
|
|
90
|
+
handler: {
|
|
91
|
+
step( by: number ){ this.state.count += by },
|
|
92
|
+
reset(){ this.step( -this.state.count ) } // a typo here is an error
|
|
93
|
+
},
|
|
94
|
+
default: `<button on-click(step, 1)>{state.count}</button>`
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
lips.render('greeting', { default: `<b>{input.name}</b>` }, { name: 'Ada' }).state // typed
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Written apart, in a file of its own, its `this` is fixed where it is
|
|
101
|
+
written, so its handler names the parts it reads:
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
export const handler: Handlers<Shape<{ input: Input, state: typeof state }>> = { … }
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
or the object is wrapped in `component( … )`, which infers it as the calls
|
|
108
|
+
do. The app's context is typed once, for every component and for
|
|
109
|
+
`new Lips()`:
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
declare module '@lipsjs/lips' {
|
|
113
|
+
interface SharedContext { theme: 'dark' | 'light' }
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
The types, and what the template strings do not check, are in the
|
|
118
|
+
[reference](docs/reference.md#types).
|
|
119
|
+
|
|
76
120
|
## 🧩 Template syntax
|
|
77
121
|
|
|
78
122
|
```html
|
|
@@ -83,6 +127,14 @@ import Lips from '@lipsjs/lips'
|
|
|
83
127
|
<button on-click(select, item.id)>pick</button>
|
|
84
128
|
<button on-click(() => state.count++)>+</button>
|
|
85
129
|
|
|
130
|
+
<!-- event modifiers, the same on the DOM and on Lynx -->
|
|
131
|
+
<div on-click(openRow)><button on-click.stop(remove)>×</button></div> <!-- the row does not open -->
|
|
132
|
+
<div on-keydown.capture(onKey)>…</div> <!-- before its children -->
|
|
133
|
+
<div class="menu" on-click.outside(dismiss)>…</div> <!-- a tap anywhere else -->
|
|
134
|
+
|
|
135
|
+
<!-- element references: this.refs.search.focus(), .scrollIntoView(), .animate(…) -->
|
|
136
|
+
<input @ref="search">
|
|
137
|
+
|
|
86
138
|
<!-- conditionals -->
|
|
87
139
|
<if(state.ready)>…</if>
|
|
88
140
|
<else-if(state.loading)>…</else-if>
|
|
@@ -101,13 +153,26 @@ import Lips from '@lipsjs/lips'
|
|
|
101
153
|
```
|
|
102
154
|
|
|
103
155
|
Components compose with **slots** (`<{input.renderer}/>`) and **events**
|
|
104
|
-
(`this.emit('picked', …)` → parent `on-picked(...)`).
|
|
156
|
+
(`this.emit('picked', …)` → parent `on-picked(...)`). A slot's expressions
|
|
157
|
+
are where it was written; its context is where it is placed. Full lifecycle:
|
|
105
158
|
`onCreate · onInput · onMount · onRender · onUpdate · onAttach · onDetach · onContext ·
|
|
106
|
-
onError · onDestroy`.
|
|
159
|
+
onError · onDestroy`. `onInput` runs at creation and again each time an
|
|
160
|
+
input changes; `onUpdate` and `onRender` after any change the template
|
|
161
|
+
shows, a branch or a row as much as a text. Whatever a template evaluates,
|
|
162
|
+
and whatever a handler throws, reaches `onError`, and the rest renders.
|
|
107
163
|
|
|
108
|
-
|
|
164
|
+
A library of components installs as a plugin, with what it requires:
|
|
109
165
|
|
|
110
|
-
|
|
166
|
+
```js
|
|
167
|
+
import { menu } from '@lipsjs/lips/parts'
|
|
168
|
+
lips.use( menu ) // and the popover it is built on
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Variables that never re-render
|
|
172
|
+
|
|
173
|
+
`static` holds what a component keeps without re-rendering: reading it
|
|
174
|
+
creates no subscription, and writing it redraws nothing. Each instance has
|
|
175
|
+
its own copy, as it has of `state`:
|
|
111
176
|
|
|
112
177
|
```js
|
|
113
178
|
{
|
|
@@ -194,6 +259,52 @@ not script. What it may not do is reported as a diagnostic with `line`/`col`/`co
|
|
|
194
259
|
and refused again at runtime. What Lips leaves to CSP and to the page is listed in
|
|
195
260
|
[RFC-007](design/untrusted-templates.md).
|
|
196
261
|
|
|
262
|
+
## 📱 Native, on Lynx
|
|
263
|
+
|
|
264
|
+
The same templates render natively through [Lynx](https://lynxjs.org)
|
|
265
|
+
(SDK 4.0 or later), on its two threads: Lips runs in the background and a
|
|
266
|
+
small applier on the main thread is the only code that touches elements
|
|
267
|
+
([RFC-006](design/lynx-binding.md)). With Rspeedy and
|
|
268
|
+
`@lynx-js/vanilla-rsbuild-plugin`:
|
|
269
|
+
|
|
270
|
+
```ts
|
|
271
|
+
// lynx.config.ts
|
|
272
|
+
import { defineConfig } from '@lynx-js/rspeedy'
|
|
273
|
+
import { pluginVanillaLynx } from '@lynx-js/vanilla-rsbuild-plugin'
|
|
274
|
+
import { pluginLips } from '@lipsjs/lips/lynx-plugin'
|
|
275
|
+
|
|
276
|
+
export default defineConfig({
|
|
277
|
+
source: { entry: './src/main-thread.ts' },
|
|
278
|
+
plugins: [ pluginVanillaLynx(), pluginLips() ]
|
|
279
|
+
})
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
```ts
|
|
283
|
+
// src/main-thread.ts
|
|
284
|
+
import { connectMain } from '@lipsjs/lips/lynx/main'
|
|
285
|
+
import './app.lips.css' // a Lips sheet: its name is its scope
|
|
286
|
+
|
|
287
|
+
connectMain( __CreatePage( '0', 0 ) )
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
```ts
|
|
291
|
+
// src/background.ts
|
|
292
|
+
import { compileLynxTemplate } from '@lipsjs/lips/lynx'
|
|
293
|
+
import { renderIR } from '@lipsjs/lips/runtime'
|
|
294
|
+
import { connectBackground } from '@lipsjs/lips/lynx/background'
|
|
295
|
+
import sheet from './app.lips.css?raw' // the sheet's binds: its CSS is in the bundle
|
|
296
|
+
|
|
297
|
+
const { ir } = compileLynxTemplate( template ) // or precompile it at build time
|
|
298
|
+
const bg = connectBackground()
|
|
299
|
+
renderIR( ir, { state, handlers, stylesheet: JSON.parse( sheet ) }, { host: bg.host, mode: 'interpreted' }).mount( bg.root )
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
`pluginLips` compiles `*.lips.css` files (a lint error fails the build), sets
|
|
303
|
+
the page config Lips relies on, and lowers Lips's own files to the app's target,
|
|
304
|
+
since Lynx's engines parse less than browsers. Import a sheet from a script, not
|
|
305
|
+
with `@import`. [`demos/lynx`](demos/lynx) is a complete app, run in the real
|
|
306
|
+
engine on every change.
|
|
307
|
+
|
|
197
308
|
## 🔥 Hot-swap
|
|
198
309
|
|
|
199
310
|
Re-render a live component against a revised template, keeping component state:
|
|
@@ -205,7 +316,10 @@ const { changes } = app.swap(newIR) // patches only what differs
|
|
|
205
316
|
|
|
206
317
|
## 📖 Documentation
|
|
207
318
|
|
|
208
|
-
[
|
|
319
|
+
[**The reference**](docs/reference.md): every part of Lips, when to use it
|
|
320
|
+
and when not, with an example that `tests/reference.spec.ts` runs. The
|
|
321
|
+
design behind each part is in the RFCs under [`design/`](design).
|
|
322
|
+
A guided tour is at [lips-js.github.io](https://lips-js.github.io).
|
|
209
323
|
|
|
210
324
|
## 🏗️ Building from source
|
|
211
325
|
|