@lipsjs/lips 0.2.0 → 0.3.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.
- package/README.md +68 -1
- package/dist/lips.js +3532 -1094
- package/dist/lips.js.map +44 -19
- package/dist/lips.min.js +13 -9
- package/dist/lips.min.js.map +44 -19
- package/dist/lynx.min.js +51 -0
- package/dist/lynx.min.js.map +17 -0
- package/dist/mf2.min.js +4 -0
- package/dist/mf2.min.js.map +38 -0
- package/dist/precompile.min.js +19 -16
- package/dist/precompile.min.js.map +7 -6
- package/dist/runtime.min.js +4 -3
- package/dist/runtime.min.js.map +13 -12
- package/dist/stylis.min.js +3 -0
- package/dist/stylis.min.js.map +16 -0
- package/dist/types/i18n/engine.d.ts +14 -0
- package/dist/types/i18n/index.d.ts +122 -5
- package/dist/types/i18n/intl.d.ts +1 -0
- package/dist/types/i18n/lookup.d.ts +22 -0
- package/dist/types/ir/compiler.d.ts +75 -2
- package/dist/types/ir/expression.d.ts +32 -3
- package/dist/types/ir/facade.d.ts +74 -30
- package/dist/types/ir/host.d.ts +75 -0
- package/dist/types/ir/index.d.ts +5 -2
- package/dist/types/ir/policy.d.ts +95 -0
- package/dist/types/ir/runtime.d.ts +54 -19
- package/dist/types/ir/signal.d.ts +6 -4
- package/dist/types/ir/style.d.ts +119 -0
- package/dist/types/ir/swap.d.ts +5 -0
- package/dist/types/ir/tree.d.ts +51 -0
- package/dist/types/lips.d.ts +20 -3
- package/dist/types/lynx/a11y.d.ts +61 -0
- package/dist/types/lynx/background.d.ts +71 -0
- package/dist/types/lynx/main.d.ts +46 -0
- package/dist/types/lynx/protocol.d.ts +52 -0
- package/dist/types/lynx/style.d.ts +49 -0
- package/dist/types/lynx/template.d.ts +37 -0
- package/dist/types/lynx.d.ts +22 -0
- package/dist/types/mf2.d.ts +14 -0
- package/dist/types/precompile.d.ts +30 -5
- package/dist/types/runtime.d.ts +1 -1
- package/dist/types/stylesheet.d.ts +12 -16
- package/dist/types/stylis.d.ts +2 -0
- package/dist/types/types.d.ts +138 -11
- package/dist/types/untrusted.d.ts +17 -0
- package/dist/untrusted.min.js +5 -0
- package/dist/untrusted.min.js.map +13 -0
- package/package.json +25 -3
package/README.md
CHANGED
|
@@ -70,6 +70,8 @@ import Lips from '@lipsjs/lips'
|
|
|
70
70
|
| `@lipsjs/lips` | full: runtime + parser/compiler + styles + router | ~21 KB |
|
|
71
71
|
| `@lipsjs/lips/runtime` | precompiled-only: no parser/compiler (CSP-friendly) | ~12 KB |
|
|
72
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/lynx` | build-time Lynx pass: a template and a stylesheet held to what Lynx draws (RFC-006) | — |
|
|
73
75
|
| `@lipsjs/lips/dev` | unminified full build | — |
|
|
74
76
|
|
|
75
77
|
## 🧩 Template syntax
|
|
@@ -104,11 +106,58 @@ Components compose with **slots** (`<{input.renderer}/>`) and **events**
|
|
|
104
106
|
`onCreate · onInput · onMount · onRender · onUpdate · onAttach · onDetach · onContext ·
|
|
105
107
|
onError · onDestroy`.
|
|
106
108
|
|
|
109
|
+
### Constants
|
|
110
|
+
|
|
111
|
+
`static` holds values that never change — reading them creates no subscription:
|
|
112
|
+
|
|
113
|
+
```js
|
|
114
|
+
{
|
|
115
|
+
static: { api: 'https://api.example.com', pageSize: 25 },
|
|
116
|
+
handler: { load(){ return fetch(`${this.static.api}/items`) } },
|
|
117
|
+
default: `<p>{static.pageSize} per page</p>`
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Use `_static` only in the named-export form — `export const static` is a
|
|
122
|
+
SyntaxError, since `static` is reserved in strict mode. Both spellings are the
|
|
123
|
+
same field.
|
|
124
|
+
|
|
125
|
+
### The component bus runs both ways
|
|
126
|
+
|
|
127
|
+
A rendered component's bus is bidirectional, so the handle you hold can send
|
|
128
|
+
commands in, not just receive events out:
|
|
129
|
+
|
|
130
|
+
```js
|
|
131
|
+
const editor = lips.render('editor', template).appendTo('#app')
|
|
132
|
+
|
|
133
|
+
// out — the component reports
|
|
134
|
+
editor.on('saved', doc => console.log( doc.id ))
|
|
135
|
+
|
|
136
|
+
// in — the holder commands
|
|
137
|
+
editor.emit('reset')
|
|
138
|
+
editor.emit('focus', 'title')
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
```js
|
|
142
|
+
handler: {
|
|
143
|
+
onCreate(){
|
|
144
|
+
this.on('reset', () => this.state.draft = '')
|
|
145
|
+
this.on('focus', field => this.node[0].querySelector(`[name="${field}"]`)?.focus() )
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Inbound events reach listeners the component registered with `this.on(…)` —
|
|
151
|
+
**not** handler methods by name, so what a component accepts stays an explicit
|
|
152
|
+
contract. This is the way to drive a component imperatively; its internals are
|
|
153
|
+
deliberately not exposed.
|
|
154
|
+
|
|
107
155
|
## ⚡ Precompile & CSP
|
|
108
156
|
|
|
109
157
|
Compile templates to IR at build time — no runtime parsing, and with
|
|
110
158
|
`mode: 'interpreted'` no `eval`/`Function`, so the app runs under `script-src` without
|
|
111
|
-
`unsafe-eval`.
|
|
159
|
+
`unsafe-eval`. That is CSP-safety, not a sandbox: both modes are for templates you
|
|
160
|
+
trust. For one you did not write — a generated UI, a partner's embed — see below.
|
|
112
161
|
|
|
113
162
|
```js
|
|
114
163
|
import { precompile } from '@lipsjs/lips/precompile'
|
|
@@ -128,6 +177,24 @@ import Card from './card.lips' // already-compiled IR
|
|
|
128
177
|
lips.register('card', Card)
|
|
129
178
|
```
|
|
130
179
|
|
|
180
|
+
## 🛡 Untrusted templates
|
|
181
|
+
|
|
182
|
+
A template you did not write runs under a policy:
|
|
183
|
+
|
|
184
|
+
```js
|
|
185
|
+
import Lips from '@lipsjs/lips'
|
|
186
|
+
import { untrusted, untrustedPolicy } from '@lipsjs/lips/untrusted'
|
|
187
|
+
|
|
188
|
+
const embed = new Lips({ untrusted: untrusted() })
|
|
189
|
+
const strict = new Lips({ untrusted: untrusted({ ...untrustedPolicy, url: sameOriginOnly }) })
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
It reaches the data and functions you hand it, a few pure globals, and its own
|
|
193
|
+
subtree through the template language — not the page, not the realm's prototypes,
|
|
194
|
+
not script. What it may not do is reported as a diagnostic with `line`/`col`/`code`/`hint`,
|
|
195
|
+
and refused again at runtime. What Lips leaves to CSP and to the page is listed in
|
|
196
|
+
[RFC-007](design/untrusted-templates.md).
|
|
197
|
+
|
|
131
198
|
## 🔥 Hot-swap
|
|
132
199
|
|
|
133
200
|
Re-render a live component against a revised template, keeping component state:
|