@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.
Files changed (48) hide show
  1. package/README.md +68 -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/lynx.min.js +51 -0
  7. package/dist/lynx.min.js.map +17 -0
  8. package/dist/mf2.min.js +4 -0
  9. package/dist/mf2.min.js.map +38 -0
  10. package/dist/precompile.min.js +19 -16
  11. package/dist/precompile.min.js.map +7 -6
  12. package/dist/runtime.min.js +4 -3
  13. package/dist/runtime.min.js.map +13 -12
  14. package/dist/stylis.min.js +3 -0
  15. package/dist/stylis.min.js.map +16 -0
  16. package/dist/types/i18n/engine.d.ts +14 -0
  17. package/dist/types/i18n/index.d.ts +122 -5
  18. package/dist/types/i18n/intl.d.ts +1 -0
  19. package/dist/types/i18n/lookup.d.ts +22 -0
  20. package/dist/types/ir/compiler.d.ts +75 -2
  21. package/dist/types/ir/expression.d.ts +32 -3
  22. package/dist/types/ir/facade.d.ts +74 -30
  23. package/dist/types/ir/host.d.ts +75 -0
  24. package/dist/types/ir/index.d.ts +5 -2
  25. package/dist/types/ir/policy.d.ts +95 -0
  26. package/dist/types/ir/runtime.d.ts +54 -19
  27. package/dist/types/ir/signal.d.ts +6 -4
  28. package/dist/types/ir/style.d.ts +119 -0
  29. package/dist/types/ir/swap.d.ts +5 -0
  30. package/dist/types/ir/tree.d.ts +51 -0
  31. package/dist/types/lips.d.ts +20 -3
  32. package/dist/types/lynx/a11y.d.ts +61 -0
  33. package/dist/types/lynx/background.d.ts +71 -0
  34. package/dist/types/lynx/main.d.ts +46 -0
  35. package/dist/types/lynx/protocol.d.ts +52 -0
  36. package/dist/types/lynx/style.d.ts +49 -0
  37. package/dist/types/lynx/template.d.ts +37 -0
  38. package/dist/types/lynx.d.ts +22 -0
  39. package/dist/types/mf2.d.ts +14 -0
  40. package/dist/types/precompile.d.ts +30 -5
  41. package/dist/types/runtime.d.ts +1 -1
  42. package/dist/types/stylesheet.d.ts +12 -16
  43. package/dist/types/stylis.d.ts +2 -0
  44. package/dist/types/types.d.ts +138 -11
  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 +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: