@lipsjs/lips 0.2.0 → 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 (45) hide show
  1. package/README.md +67 -1
  2. package/dist/lips.js +3532 -1094
  3. package/dist/lips.js.map +44 -19
  4. package/dist/lips.min.js +13 -9
  5. package/dist/lips.min.js.map +44 -19
  6. package/dist/mf2.min.js +4 -0
  7. package/dist/mf2.min.js.map +38 -0
  8. package/dist/precompile.min.js +19 -16
  9. package/dist/precompile.min.js.map +7 -6
  10. package/dist/runtime.min.js +4 -3
  11. package/dist/runtime.min.js.map +13 -12
  12. package/dist/stylis.min.js +3 -0
  13. package/dist/stylis.min.js.map +16 -0
  14. package/dist/types/i18n/engine.d.ts +14 -0
  15. package/dist/types/i18n/index.d.ts +122 -5
  16. package/dist/types/i18n/intl.d.ts +1 -0
  17. package/dist/types/i18n/lookup.d.ts +22 -0
  18. package/dist/types/ir/compiler.d.ts +75 -2
  19. package/dist/types/ir/expression.d.ts +32 -3
  20. package/dist/types/ir/facade.d.ts +74 -30
  21. package/dist/types/ir/host.d.ts +75 -0
  22. package/dist/types/ir/index.d.ts +5 -2
  23. package/dist/types/ir/policy.d.ts +95 -0
  24. package/dist/types/ir/runtime.d.ts +54 -19
  25. package/dist/types/ir/signal.d.ts +6 -4
  26. package/dist/types/ir/style.d.ts +119 -0
  27. package/dist/types/ir/swap.d.ts +5 -0
  28. package/dist/types/ir/tree.d.ts +51 -0
  29. package/dist/types/lips.d.ts +20 -3
  30. package/dist/types/lynx/a11y.d.ts +61 -0
  31. package/dist/types/lynx/background.d.ts +71 -0
  32. package/dist/types/lynx/main.d.ts +46 -0
  33. package/dist/types/lynx/protocol.d.ts +52 -0
  34. package/dist/types/lynx/style.d.ts +49 -0
  35. package/dist/types/lynx/template.d.ts +37 -0
  36. package/dist/types/mf2.d.ts +14 -0
  37. package/dist/types/precompile.d.ts +30 -5
  38. package/dist/types/runtime.d.ts +1 -1
  39. package/dist/types/stylesheet.d.ts +12 -16
  40. package/dist/types/stylis.d.ts +2 -0
  41. package/dist/types/types.d.ts +138 -11
  42. package/dist/types/untrusted.d.ts +17 -0
  43. package/dist/untrusted.min.js +5 -0
  44. package/dist/untrusted.min.js.map +13 -0
  45. package/package.json +20 -3
package/README.md CHANGED
@@ -70,6 +70,7 @@ 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 |
73
74
  | `@lipsjs/lips/dev` | unminified full build | — |
74
75
 
75
76
  ## 🧩 Template syntax
@@ -104,11 +105,58 @@ Components compose with **slots** (`<{input.renderer}/>`) and **events**
104
105
  `onCreate · onInput · onMount · onRender · onUpdate · onAttach · onDetach · onContext ·
105
106
  onError · onDestroy`.
106
107
 
108
+ ### Constants
109
+
110
+ `static` holds values that never change — reading them creates no subscription:
111
+
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
+ ```
119
+
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.
123
+
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.
153
+
107
154
  ## ⚡ Precompile & CSP
108
155
 
109
156
  Compile templates to IR at build time — no runtime parsing, and with
110
157
  `mode: 'interpreted'` no `eval`/`Function`, so the app runs under `script-src` without
111
- `unsafe-eval`.
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.
112
160
 
113
161
  ```js
114
162
  import { precompile } from '@lipsjs/lips/precompile'
@@ -128,6 +176,24 @@ import Card from './card.lips' // already-compiled IR
128
176
  lips.register('card', Card)
129
177
  ```
130
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).
196
+
131
197
  ## 🔥 Hot-swap
132
198
 
133
199
  Re-render a live component against a revised template, keeping component state: