@lipsjs/lips 0.3.1 → 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.
Files changed (45) hide show
  1. package/README.md +122 -9
  2. package/dist/lips.js +915 -669
  3. package/dist/lips.js.map +15 -12
  4. package/dist/lips.min.js +12 -12
  5. package/dist/lips.min.js.map +15 -12
  6. package/dist/lynx-background.min.js +3 -0
  7. package/dist/lynx-background.min.js.map +13 -0
  8. package/dist/lynx-main.min.js +3 -0
  9. package/dist/lynx-main.min.js.map +11 -0
  10. package/dist/lynx-plugin.mjs +1487 -0
  11. package/dist/lynx.min.js +8 -8
  12. package/dist/lynx.min.js.map +11 -10
  13. package/dist/mf2.min.js.map +1 -1
  14. package/dist/parts.min.js +19 -0
  15. package/dist/parts.min.js.map +11 -0
  16. package/dist/precompile.min.js +15 -15
  17. package/dist/precompile.min.js.map +8 -7
  18. package/dist/runtime.min.js +4 -4
  19. package/dist/runtime.min.js.map +11 -9
  20. package/dist/stylis.min.js.map +1 -1
  21. package/dist/types/component.d.ts +32 -0
  22. package/dist/types/ir/compiler.d.ts +2 -4
  23. package/dist/types/ir/facade.d.ts +63 -12
  24. package/dist/types/ir/host.d.ts +9 -1
  25. package/dist/types/ir/initial.d.ts +16 -0
  26. package/dist/types/ir/router.d.ts +2 -0
  27. package/dist/types/ir/tags.d.ts +16 -0
  28. package/dist/types/lips.d.ts +7 -7
  29. package/dist/types/lynx/a11y.d.ts +1 -0
  30. package/dist/types/lynx/background.d.ts +52 -3
  31. package/dist/types/lynx/main.d.ts +9 -5
  32. package/dist/types/lynx/plugin.d.ts +8 -0
  33. package/dist/types/lynx/protocol.d.ts +55 -4
  34. package/dist/types/lynx/style.d.ts +7 -0
  35. package/dist/types/lynx/template.d.ts +6 -0
  36. package/dist/types/parts/menu.d.ts +44 -0
  37. package/dist/types/parts/popover.d.ts +83 -0
  38. package/dist/types/parts.d.ts +16 -0
  39. package/dist/types/precompile.d.ts +8 -11
  40. package/dist/types/runtime.d.ts +1 -0
  41. package/dist/types/types.d.ts +181 -57
  42. package/dist/untrusted.min.js +4 -4
  43. package/dist/untrusted.min.js.map +7 -7
  44. package/package.json +24 -3
  45. package/dist/types/i18n/formatters.d.ts +0 -3
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Popover: a trigger and the panel it opens, over the page (RFC-008 §5).
3
+ *
4
+ * lips.use( popover )
5
+ *
6
+ * <popover open=state.open on-change( setOpen )>
7
+ * <popover-trigger class="btn"><span>Actions</span></popover-trigger>
8
+ * <popover-content class="panel">…</popover-content>
9
+ * </popover>
10
+ *
11
+ * It is controlled: `open` is the app's, and a change comes back as
12
+ * `change`. `popover` provides what its pieces share as `context.popover`
13
+ * (`PopoverApi`), which reaches them where its slot places them (RFC-005
14
+ * §4.4). A piece given `of` uses that instead, so a piece can be driven by
15
+ * any controller of the same shape.
16
+ *
17
+ * `popover-content` renders, while open, a layer over the whole page, a
18
+ * backdrop in it and the panel. The layer is one fixed element on both
19
+ * hosts: on Lynx `fixed` places it as a child of the page's root, which is
20
+ * what Lynx asks of a page that is all Lynx (its `overlay` is for Lynx
21
+ * inside a native page). Each time it opens, the panel is drawn invisible,
22
+ * then the trigger, the layer and the panel are measured and the panel is
23
+ * placed (`place`, or the app's own as `place=`), and focus goes to it.
24
+ *
25
+ * Closing: Escape, a tap on the backdrop, and whatever the content asks
26
+ * (`p.set( false )`); focus goes back to the trigger. The backdrop takes a
27
+ * tap outside whole, so it closes the panel and reaches nothing beneath,
28
+ * as a menu on a phone does. `.outside` would not do: it listens in the
29
+ * capture phase on both hosts, before the trigger's own tap, which would
30
+ * close the panel and open it again.
31
+ *
32
+ * `popup` says which element is the popup a screen reader is told of:
33
+ * `"panel"` (the default) gives the panel the popover's id, its `role`,
34
+ * the trigger as its label, and focus; `"content"` leaves all of that to
35
+ * the content, as a menu's list takes it (`./menu`).
36
+ *
37
+ * Its mechanics (the layer over the page, where the panel sits) are
38
+ * inline styles: Lynx cannot add a sheet at run time, so a part's own
39
+ * sheet would have to reach the app's build, and nothing here needs what
40
+ * only a sheet reaches (`:hover`, `@keyframes`, `@media`). Its look is the
41
+ * app's, through the classes it is given.
42
+ */
43
+ import type { Plugin } from '../types';
44
+ /** What a popover's pieces share: `context.popover`, or a piece's `of` */
45
+ export interface PopoverApi {
46
+ /** The popup's id; the trigger's is this with `-trigger` */
47
+ readonly id: string;
48
+ /** The app's `open`, read live */
49
+ readonly open: boolean;
50
+ /** The popup's id while it is open: what `aria-controls` names */
51
+ readonly controls: string | null;
52
+ /** The trigger's element, set by the trigger */
53
+ trigger?: {
54
+ focus(): void;
55
+ getBoundingClientRect(): unknown;
56
+ };
57
+ /** Where content with items starts when it opens, as the trigger's key asked */
58
+ start: 'first' | 'last';
59
+ /** Ask for `open`; closed, focus goes back to the trigger unless `back` is false */
60
+ set(open: boolean, back?: boolean): void;
61
+ toggle(): void;
62
+ }
63
+ /** A box as the DOM and Lips's Lynx refs both give it */
64
+ export interface Box {
65
+ top: number;
66
+ left: number;
67
+ right: number;
68
+ bottom: number;
69
+ width: number;
70
+ height: number;
71
+ }
72
+ /** Where a panel goes in its layer, from the three boxes measured */
73
+ export type Placement = (trigger: Box, layer: Box, panel: Box, rtl?: boolean) => {
74
+ top: number;
75
+ left: number;
76
+ };
77
+ /**
78
+ * Below the trigger, or above it where it does not fit below and does
79
+ * above; its start edge on the trigger's, or its end edge in right-to-left;
80
+ * kept inside the layer.
81
+ */
82
+ export declare const place: Placement;
83
+ export declare const popover: Plugin;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * `@lipsjs/lips/parts`: headless components (RFC-008).
3
+ *
4
+ * Each part is a plugin: `lips.use()` installs its components and what it
5
+ * is built on, once.
6
+ *
7
+ * import { menu } from '@lipsjs/lips/parts'
8
+ * lips.use( menu ) // and the popover it is built on
9
+ *
10
+ * A part's templates are source. An app that runs in interpreted mode
11
+ * under a content security policy precompiles them in its build with
12
+ * `precompile()` (`@lipsjs/lips/precompile`), as it does its own; on Lynx,
13
+ * with `compileLynxTemplate()`.
14
+ */
15
+ export { popover, place, type PopoverApi, type Placement, type Box } from './parts/popover';
16
+ export { menu, move, typed, type MenuItem } from './parts/menu';
@@ -16,15 +16,12 @@
16
16
  import type { TemplateIR, CompileOptions } from './ir/compiler';
17
17
  import type { StyleIR, StylePreprocessor } from './ir/style';
18
18
  import type { TemplateDiagnostic } from './ir/parser';
19
- export interface PrecompiledTemplate {
19
+ import type { Component, TypedComponent, Shape } from './types';
20
+ /** What `precompile()` returns: the template it was given, with `ir` (and `style`) for its sources */
21
+ /** A component with its markup and stylesheet compiled: no source ships */
22
+ export type PrecompiledComponent<S extends Shape = Shape> = Omit<TypedComponent<S>, 'default' | 'macros' | 'stylesheet'> & {
20
23
  ir: TemplateIR;
21
- /** Compiled stylesheet — replaces `stylesheet` source (RFC-004) */
22
- style?: StyleIR;
23
- state?: Record<string, any>;
24
- _static?: Record<string, any>;
25
- context?: string[];
26
- handler?: Record<string, (...args: any[]) => any>;
27
- }
24
+ };
28
25
  export interface PrecompileOptions {
29
26
  /**
30
27
  * Scope name for the stylesheet — baked into the StyleIR, so it must
@@ -41,8 +38,8 @@ export interface PrecompileOptions {
41
38
  /** The kind of host the IR is for — see `CompileOptions.target` */
42
39
  target?: CompileOptions['target'];
43
40
  }
44
- export interface PrecompileResult {
45
- template: PrecompiledTemplate;
41
+ export interface PrecompileResult<S extends Shape = Shape> {
42
+ template: PrecompiledComponent<S>;
46
43
  diagnostics: TemplateDiagnostic[];
47
44
  }
48
45
  /**
@@ -51,7 +48,7 @@ export interface PrecompileResult {
51
48
  * is compiled to StyleIR, so the `./runtime` build needs no CSS
52
49
  * preprocessor either (RFC-004 §1).
53
50
  */
54
- export declare function precompile(template: Record<string, any>, options?: PrecompileOptions): PrecompileResult;
51
+ export declare function precompile<S extends Shape = Shape>(template: Component<S>, options?: PrecompileOptions): PrecompileResult<S>;
55
52
  /** Serialize an IR for embedding in generated source */
56
53
  export declare const serializeIR: (ir: TemplateIR) => string;
57
54
  export declare const serializeStyleIR: (ir: StyleIR) => string;
@@ -10,6 +10,7 @@
10
10
  */
11
11
  import { IRLips } from './ir/facade';
12
12
  export * from './types';
13
+ export { component } from './component';
13
14
  export { renderIR } from './ir/runtime';
14
15
  export { signal, effect, untrack, reactive } from './ir/signal';
15
16
  export type { TemplateIR, IRInstance, RuntimeOptions, RenderSetup, SwapReport, Host } from './ir';
@@ -1,45 +1,115 @@
1
1
  /**
2
2
  * Public types.
3
3
  *
4
- * Component authoring shape — the same plain object the framework has
5
- * always taken, and the serializable artifact a generator can emit:
4
+ * A component is a plain object — the same one the framework has always
5
+ * taken, and the serializable artifact a generator can emit:
6
6
  *
7
- * { default, state, handler, _static, context, macros, stylesheet }
7
+ * { name, default, state, static, handler, watchContext, macros, stylesheet }
8
8
  *
9
- * These are the types `register`/`render`/`root` actually accept: the
10
- * facade is generic over `Metavars`, so `Template<MT>` here and the
11
- * argument the engine takes are the same type, not parallel ones.
9
+ * `component()` writes one with its types inferred: `state` and `static`
10
+ * from their values, the handlers from themselves, `this` in each of them
11
+ * from all three. What no value can show, the `input` a parent hands it,
12
+ * it is told by name:
13
+ *
14
+ * const counter = component<{ input: { initial?: number } }>()({
15
+ * state: { count: 0 },
16
+ * handler: {
17
+ * onInput(){ this.state.count = this.input.initial ?? 0 },
18
+ * step( by: number ){ this.state.count += by }
19
+ * },
20
+ * default: `<button on-click(step, 1)>{state.count}</button>`
21
+ * })
22
+ *
23
+ * lips.render('counter', counter, { initial: 2 }).state.count // number
24
+ *
25
+ * The context is the app's, so it is typed once for every component, by
26
+ * augmenting `SharedContext`. What the template strings read is not
27
+ * checked: their expressions are not TypeScript.
12
28
  */
13
29
  import type { MessageFormat, Model } from 'messageformat';
14
30
  import type { MessageFunction } from 'messageformat/functions';
15
31
  import type { TemplateIR } from './ir/compiler';
16
32
  import type { StyleIR } from './ir/style';
17
33
  import type { Untrusted } from './ir/policy';
34
+ import type { IRLips, RESERVED } from './ir/facade';
18
35
  /**
19
- * The four typed surfaces of a component. Defaults are permissive on
20
- * purpose: an untyped `lips.render('x', { state: { n: 0 } })` still
21
- * gets `c.state.n` without annotation, and a component that declares
22
- * its metavars gets exact types. Tightening these to `{}` would turn
23
- * every unannotated read into a compile error.
36
+ * What every component of an app reads as `context`. Empty here, so an
37
+ * app types it once, for every component and for `new Lips()`:
38
+ *
39
+ * declare module '@lipsjs/lips' {
40
+ * interface SharedContext { theme: 'dark' | 'light' }
41
+ * }
42
+ *
43
+ * Left empty, `context` reads as `Record<string, any>`.
24
44
  */
25
- export interface Metavars<Input extends Object = Record<string, any>, State extends Object = Record<string, any>, Static extends Object = Record<string, any>, Context extends Object = Record<string, any>> {
26
- Input: Input;
27
- State: State;
28
- Static: Static;
29
- Context: Context;
45
+ export interface SharedContext {
30
46
  }
31
- export type LifeCycleEventTypes = 'onCreate' | 'onInput' | 'onMount' | 'onRender' | 'onUpdate' | 'onAttach' | 'onDetach' | 'onContext' | 'onError' | 'onDestroy';
47
+ type Shared = keyof SharedContext extends never ? Record<string, any> : SharedContext;
48
+ /** The parts a component names; any it leaves out */
49
+ export type Parts = {
50
+ input?: object;
51
+ state?: object;
52
+ static?: object;
53
+ context?: object;
54
+ };
55
+ /** A part `P` names, or `Else` */
56
+ type Part<P, K extends keyof Parts, Else> = P extends {
57
+ [k in K]: infer X extends object;
58
+ } ? X : Else;
32
59
  /**
33
- * `this` inside a handler: reactive stores plus the component's
34
- * own API (emit/on/off, setContext).
60
+ * The four typed parts of a component, by name: what a parent hands it
61
+ * (`input`), what it changes (`state`), what never re-renders (`static`)
62
+ * and what the app shares (`context`).
63
+ *
64
+ * Shape<{ input: { tone: string }, state: { count: number } }>
65
+ *
66
+ * A part it names is exact, a part it leaves out is empty, and `context`
67
+ * is the app's `SharedContext` unless named. Bare, `Shape` reads every
68
+ * part as `any`: the shape of a component nothing typed, and one every
69
+ * typed component is assignable to.
35
70
  */
36
- export interface ComponentSelf<MT extends Metavars = Metavars> {
37
- state: MT['State'];
38
- input: MT['Input'];
39
- context: MT['Context'];
40
- static: MT['Static'];
71
+ export type Shape<P extends Parts = {
72
+ input: any;
73
+ state: any;
74
+ static: any;
75
+ context: any;
76
+ }> = {
77
+ input: Part<P, 'input', {}>;
78
+ state: Part<P, 'state', {}>;
79
+ static: Part<P, 'static', {}>;
80
+ context: Part<P, 'context', Shared>;
81
+ };
82
+ /** The lifecycle, in the order it runs (`onError` and `onContext` when they occur) */
83
+ export interface Hooks {
84
+ onCreate(): void;
85
+ onInput(): void;
86
+ onMount(): void;
87
+ onRender(): void;
88
+ onUpdate(): void;
89
+ onAttach(): void;
90
+ onDetach(): void;
91
+ onContext(): void;
92
+ onError(error: Error): void;
93
+ onDestroy(): void;
94
+ }
95
+ export type HookName = keyof Hooks;
96
+ /** Names a handler cannot take: the component's own members */
97
+ export type ReservedName = typeof RESERVED[number];
98
+ /** The component's own members, in `this` beside its handlers */
99
+ export interface Members<S extends Shape = Shape> {
100
+ state: S['state'];
101
+ input: S['input'];
102
+ context: S['context'];
103
+ static: S['static'];
41
104
  /** Live root elements of this component */
42
105
  readonly node: Element[];
106
+ /**
107
+ * The elements its template names with `@ref="name"`, while they live:
108
+ * `this.refs.search.focus()`. On the DOM each is the element; on Lynx a
109
+ * node that answers `focus`, `blur`, `scrollTo`, `scrollIntoView` and
110
+ * `animate` as the element would.
111
+ */
112
+ readonly refs: Record<string, any>;
43
113
  /**
44
114
  * Active language, read reactively — a bind that reads it re-renders
45
115
  * on `setLanguage()`. Component-grained: a component under
@@ -55,62 +125,115 @@ export interface ComponentSelf<MT extends Metavars = Metavars> {
55
125
  * Also the inbound channel: a listener registered here receives
56
126
  * `component.emit(…)` calls made by whoever holds the handle.
57
127
  */
58
- on(event: string, fn: (...args: any[]) => void): ComponentSelf<MT>;
59
- once(event: string, fn: (...args: any[]) => void): ComponentSelf<MT>;
60
- off(event: string, fn?: (...args: any[]) => void): ComponentSelf<MT>;
128
+ on(event: string, fn: (...args: any[]) => void): this;
129
+ once(event: string, fn: (...args: any[]) => void): this;
130
+ off(event: string, fn?: (...args: any[]) => void): this;
61
131
  setContext(arg: string | Record<string, any>, value?: any): void;
62
- /** Sibling handlers, reachable as `this.otherMethod()` */
63
- [key: string]: any;
64
132
  }
65
- export interface LifecycleEvents<MT extends Metavars> {
66
- onCreate(this: ComponentSelf<MT>): void;
67
- onInput(this: ComponentSelf<MT>): void;
68
- onMount(this: ComponentSelf<MT>): void;
69
- onRender(this: ComponentSelf<MT>): void;
70
- onUpdate(this: ComponentSelf<MT>): void;
71
- onAttach(this: ComponentSelf<MT>): void;
72
- onDetach(this: ComponentSelf<MT>): void;
73
- onContext(this: ComponentSelf<MT>): void;
74
- onError(this: ComponentSelf<MT>, error: Error): void;
75
- onDestroy(this: ComponentSelf<MT>): void;
76
- }
77
- export type Handler<MT extends Metavars> = Partial<LifecycleEvents<MT>> & {
78
- [K in string as K extends keyof LifecycleEvents<MT> ? never : K]?: (this: ComponentSelf<MT>, ...args: any[]) => any;
133
+ /**
134
+ * `this` in a handler: the component's members and its other handlers.
135
+ * `Methods` are the handlers `component()` saw, so a sibling it does not
136
+ * have is an error; left out, any name reads as `any`.
137
+ */
138
+ export type Self<S extends Shape = Shape, Methods = Record<string, any>> = Members<S> & Methods;
139
+ /**
140
+ * A component's `handler` object, typed by hand: for a component written
141
+ * as module exports (`export const handler: Handlers<S> = { … }`), which
142
+ * `component()` cannot see whole. Its `this` reads siblings as `any`.
143
+ */
144
+ export type Handlers<S extends Shape = Shape> = {
145
+ [K in HookName]?: (this: Self<S>, ...args: Parameters<Hooks[K]>) => void;
146
+ } & {
147
+ [K in string as K extends HookName | ReservedName ? never : K]?: (this: Self<S>, ...args: any[]) => any;
79
148
  };
80
- export type Template<MT extends Metavars = Metavars> = {
149
+ /** What `register`, `render`, `root` and a route take */
150
+ export type Component<S extends Shape = Shape> = {
151
+ /**
152
+ * The scope of a component placed by value — a route page, or
153
+ * `<{state.view}/>` — that no `register()` names: its stylesheet's
154
+ * `rel`. Left out, each such object gets one of its own.
155
+ */
156
+ name?: string;
81
157
  /** Template source — the component's markup */
82
158
  default?: string;
83
159
  /** Precompiled template IR — used instead of `default` (see `precompile`) */
84
160
  ir?: TemplateIR;
85
- state?: MT['State'];
161
+ state?: S['state'];
86
162
  /**
87
- * Constants — read as `this.static` in a handler and `static.x` in a
88
- * template. `_static` is the same field: a NAMED MODULE EXPORT cannot
89
- * be called `static` (it is reserved in strict mode, and ES modules
90
- * are always strict), so the underscore exists for that form only.
91
- * Object literals should use `static`.
163
+ * Variables that never re-render — read and written as `this.static` in
164
+ * a handler, read as `static.x` in a template, which subscribes to none
165
+ * of them. Each instance has its own copy, as it has of `state`: what
166
+ * the component declares is where each starts. `_static` is the same
167
+ * field: a NAMED MODULE EXPORT cannot be called `static` (it is reserved
168
+ * in strict mode, and ES modules are always strict), so the underscore
169
+ * exists for that form only. Object literals use `static`.
92
170
  */
93
- static?: MT['Static'];
94
- _static?: MT['Static'];
171
+ static?: S['static'];
172
+ _static?: S['static'];
95
173
  /**
96
174
  * Context fields whose change fires this component's `onContext`.
97
175
  *
98
176
  * It does NOT declare what the component reads: bindings that read
99
177
  * `context.x` are tracked individually and update whether or not `x`
100
- * is listed here. The old spelling for this was `context`, which read
101
- * as "the context this component uses" and misled accordingly.
178
+ * is listed here.
102
179
  */
103
180
  watchContext?: string[];
104
- /** @deprecated Renamed to `watchContext` — same meaning (RFC-005 §4.3) */
105
- context?: string[];
106
181
  /** `<macro [argv] name="X">…</macro>` definitions, inlined at compile time */
107
182
  macros?: string;
108
- handler?: Handler<MT>;
183
+ handler?: Handlers<S>;
109
184
  /** Scoped CSS — declaration values may be `{expr}` (RFC-004) */
110
185
  stylesheet?: string;
111
186
  /** Precompiled StyleIR — used instead of `stylesheet` (see `precompile`) */
112
187
  style?: StyleIR;
113
188
  };
189
+ /** Marks a component that carries its shape; type-only, never set */
190
+ declare const SHAPE: unique symbol;
191
+ /**
192
+ * A component whose shape is known, so `render()` reads it back: what
193
+ * `component()` and `precompile()` return.
194
+ */
195
+ export type TypedComponent<S extends Shape = Shape> = Component<S> & {
196
+ readonly [SHAPE]: S;
197
+ };
198
+ /**
199
+ * A component being written, its state, static and handlers inferred:
200
+ * what `component()` takes, and what `register`, `render` and `root` take
201
+ * written in the call. Each handler's `this` is the component's members
202
+ * and every handler beside it. A `TypedComponent` is not one: its shape is
203
+ * already known.
204
+ */
205
+ export type Definition<S extends Shape, Methods> = Omit<Component<S>, 'handler'> & {
206
+ readonly [SHAPE]?: never;
207
+ handler?: Methods & Partial<Hooks> & {
208
+ [K in ReservedName]?: never;
209
+ } & ThisType<Self<S, Methods>>;
210
+ };
211
+ /**
212
+ * The shape a `Definition` gives: what `P` names, else what was inferred.
213
+ * Written in a `register`, `render` or `root` call, nothing names `input`,
214
+ * so it reads as `Record<string, any>` there (or as what `render()` is
215
+ * handed).
216
+ */
217
+ export type Inferred<P extends Parts, State, Static> = {
218
+ input: Part<P, 'input', {}>;
219
+ state: Part<P, 'state', State>;
220
+ static: Part<P, 'static', Static>;
221
+ context: Part<P, 'context', Shared>;
222
+ };
223
+ /**
224
+ * What `lips.use()` installs: a library of components (`@lipsjs/lips/parts`
225
+ * is one), what it needs installed before it, and its own setup.
226
+ */
227
+ export interface Plugin<Options = unknown> {
228
+ /** Installed once per Lips, however many times it is used or required */
229
+ readonly name: string;
230
+ /** Installed before it, each once */
231
+ readonly requires?: readonly Plugin<any>[];
232
+ /** Registered by name; a name something else holds is refused */
233
+ readonly components?: Readonly<Record<string, Component<any>>>;
234
+ /** Anything else it sets up, with what `use()` was given */
235
+ install?(lips: IRLips<any>, options?: Options): void;
236
+ }
114
237
  export type LipsConfig<Context extends Object = {}> = {
115
238
  debug?: boolean;
116
239
  context?: Context;
@@ -200,3 +323,4 @@ export type MessageFormatEngine = {
200
323
  };
201
324
  /** One language's messages, by stable key or by source text. */
202
325
  export type Dictionary = Record<string, Message>;
326
+ export {};
@@ -1,5 +1,5 @@
1
- var G=["===","!==","...","=>","==","!=","<=",">=","&&","||","??","?.","++","--","+=","-=","*=","/=","%=","+","-","*","/","%","<",">","!","?",":",".",",","(",")","[","]","{","}","="];function z(t,e){let r=[],s=0,f=(g)=>/[A-Za-z_$]/.test(g),m=(g)=>/[A-Za-z0-9_$]/.test(g);while(s<t.length){let g=t[s];if(/\s/.test(g)){s++;continue}if(/[0-9]/.test(g)||g==="."&&/[0-9]/.test(t[s+1])){let p=s;while(s<t.length&&/[0-9]/.test(t[s]))s++;if(t[s]==="."){s++;while(s<t.length&&/[0-9]/.test(t[s]))s++}if(t[s]==="e"||t[s]==="E"){if(s++,t[s]==="+"||t[s]==="-")s++;while(s<t.length&&/[0-9]/.test(t[s]))s++}r.push({t:"num",value:t.slice(p,s),start:p,end:s});continue}if(g==="'"||g==='"'){let p=s;s++;let l="",o=!1;while(s<t.length){let n=t[s];if(n==="\\"){let a=t[s+1],c={n:`
2
- `,t:"\t",r:"\r",b:"\b",f:"\f",v:"\v","0":"\x00"};if(a==="u"){let h=t.slice(s+2,s+6);l+=String.fromCharCode(parseInt(h,16)||0),s+=6}else l+=c[a]??a,s+=2;continue}if(n===g){o=!0,s++;break}l+=n,s++}if(!o)e.push({code:"LIPS-E001",message:"Unterminated string literal",loc:{offset:p,length:s-p}});r.push({t:"str",value:l,start:p,end:s});continue}if(f(g)){let p=s;while(s<t.length&&m(t[s]))s++;r.push({t:"id",value:t.slice(p,s),start:p,end:s});continue}let d=G.find((p)=>t.startsWith(p,s));if(d==="?."&&/[0-9]/.test(t[s+2]??""))d="?";if(d){r.push({t:"punct",value:d,start:s,end:s+d.length}),s+=d.length;continue}e.push({code:"LIPS-E002",message:`Unexpected character '${g}'`,loc:{offset:s,length:1}}),s++}return r.push({t:"eof",value:"",start:t.length,end:t.length}),r}class C{tokens;diagnostics;pos=0;constructor(t,e){this.tokens=t;this.diagnostics=e}peek(t=0){return this.tokens[Math.min(this.pos+t,this.tokens.length-1)]}next(){return this.tokens[this.pos++]??this.tokens[this.tokens.length-1]}at(t){let e=this.peek();return e.t==="punct"&&e.value===t}eat(t){if(this.at(t))return this.pos++,!0;return!1}error(t,e,r=this.peek()){return this.diagnostics.push({code:t,message:e,loc:{offset:r.start,length:Math.max(1,r.end-r.start)}}),{t:"error"}}expect(t,e){if(!this.eat(t))this.error(e,`Expected '${t}'`)}parse(){let t=this.assign();if(this.peek().t!=="eof")this.error("LIPS-E003",`Unexpected token '${this.peek().value}' after expression`);return t}isArrowAhead(){let t=this.peek();if(t.t==="id"){let e=this.peek(1);return e.t==="punct"&&e.value==="=>"}if(t.t==="punct"&&t.value==="("){let e=0,r=0;while(!0){let s=this.peek(r);if(s.t==="eof")return!1;if(s.t==="punct"&&s.value==="(")e++;if(s.t==="punct"&&s.value===")"){if(e--,e===0){let f=this.peek(r+1);return f.t==="punct"&&f.value==="=>"}}r++}}return!1}assign(){if(this.isArrowAhead()){let r=[];if(this.peek().t==="id")r.push(this.next().value);else{this.expect("(","LIPS-E004");while(!this.at(")")&&this.peek().t!=="eof"){let s=this.next();if(s.t!=="id")return this.error("LIPS-E005","Invalid arrow parameter",s);if(r.push(s.value),!this.eat(","))break}this.expect(")","LIPS-E004")}return this.expect("=>","LIPS-E004"),{t:"arrow",params:r,body:this.assign()}}let t=this.conditional(),e=this.peek();if(e.t==="punct"&&["=","+=","-=","*=","/=","%="].includes(e.value)){if(t.t!=="id"&&t.t!=="member")return this.error("LIPS-E006","Invalid assignment target",e);return this.next(),{t:"assign",op:e.value,target:t,value:this.assign()}}return t}conditional(){let t=this.nullish();if(this.eat("?")){let e=this.assign();return this.expect(":","LIPS-E007"),{t:"cond",test:t,cons:e,alt:this.assign()}}return t}nullish(){let t=this.or();while(this.at("??"))this.next(),t={t:"logic",op:"??",l:t,r:this.or()};return t}or(){let t=this.and();while(this.at("||"))this.next(),t={t:"logic",op:"||",l:t,r:this.and()};return t}and(){let t=this.equality();while(this.at("&&"))this.next(),t={t:"logic",op:"&&",l:t,r:this.equality()};return t}equality(){let t=this.relational();while(["===","!==","==","!="].some((e)=>this.at(e)))t={t:"bin",op:this.next().value,l:t,r:this.relational()};return t}relational(){let t=this.additive();while(["<=",">=","<",">"].some((e)=>this.at(e)))t={t:"bin",op:this.next().value,l:t,r:this.additive()};return t}additive(){let t=this.multiplicative();while(this.at("+")||this.at("-"))t={t:"bin",op:this.next().value,l:t,r:this.multiplicative()};return t}multiplicative(){let t=this.unary();while(this.at("*")||this.at("/")||this.at("%"))t={t:"bin",op:this.next().value,l:t,r:this.unary()};return t}unary(){if(this.at("!")||this.at("-")||this.at("+"))return{t:"unary",op:this.next().value,arg:this.unary()};if(this.at("++")||this.at("--")){let t=this.next().value,e=this.unary();if(e.t!=="id"&&e.t!=="member")return this.error("LIPS-E006","Invalid update target");return{t:"update",op:t,arg:e,prefix:!0}}return this.postfix()}postfix(){let t=this.callMember();if(this.at("++")||this.at("--")){let e=this.next().value;if(t.t!=="id"&&t.t!=="member")return this.error("LIPS-E006","Invalid update target");t={t:"update",op:e,arg:t,prefix:!1}}return t}callMember(){let t=this.primary();while(!0)if(this.eat(".")){let e=this.next();if(e.t!=="id")return this.error("LIPS-E008","Expected property name",e);t={t:"member",obj:t,prop:e.value,computed:!1,optional:!1,at:e.start}}else if(this.eat("?."))if(this.at("("))t={t:"call",callee:t,args:this.argList(),optional:!0};else if(this.eat("[")){let e=this.peek().start,r=this.assign();this.expect("]","LIPS-E009"),t={t:"member",obj:t,prop:r,computed:!0,optional:!0,at:e}}else{let e=this.next();if(e.t!=="id")return this.error("LIPS-E008","Expected property name",e);t={t:"member",obj:t,prop:e.value,computed:!1,optional:!0,at:e.start}}else if(this.eat("[")){let e=this.peek().start,r=this.assign();this.expect("]","LIPS-E009"),t={t:"member",obj:t,prop:r,computed:!0,optional:!1,at:e}}else if(this.at("("))t={t:"call",callee:t,args:this.argList(),optional:!1};else break;return t}argList(){this.expect("(","LIPS-E010");let t=[];while(!this.at(")")&&this.peek().t!=="eof")if(t.push(this.assign()),!this.eat(","))break;return this.expect(")","LIPS-E010"),t}primary(){let t=this.peek();if(t.t==="num")return this.next(),{t:"lit",v:parseFloat(t.value)};if(t.t==="str")return this.next(),{t:"lit",v:t.value};if(t.t==="id")switch(this.next(),t.value){case"true":return{t:"lit",v:!0};case"false":return{t:"lit",v:!1};case"null":return{t:"lit",v:null};case"undefined":return{t:"lit",v:void 0};case"NaN":return{t:"lit",v:NaN};case"Infinity":return{t:"lit",v:1/0};default:return{t:"id",name:t.value,at:t.start}}if(this.eat("(")){let e=this.assign();return this.expect(")","LIPS-E010"),e}if(this.eat("[")){let e=[];while(!this.at("]")&&this.peek().t!=="eof"){let r=this.eat("...");if(e.push({spread:r||void 0,value:this.assign()}),!this.eat(","))break}return this.expect("]","LIPS-E009"),{t:"arr",items:e}}if(this.eat("{")){let e=[];while(!this.at("}")&&this.peek().t!=="eof"){if(this.eat("..."))e.push({spread:!0,value:this.assign()});else{let r=this.next();if(r.t!=="id"&&r.t!=="str"&&r.t!=="num")return this.error("LIPS-E011","Invalid object key",r);if(this.eat(":"))e.push({key:String(r.value),value:this.assign(),at:r.start});else if(r.t==="id")e.push({key:r.value,value:{t:"id",name:r.value,at:r.start},at:r.start});else return this.error("LIPS-E011","Invalid shorthand property",r)}if(!this.eat(","))break}return this.expect("}","LIPS-E011"),{t:"obj",props:e}}return this.next(),this.error("LIPS-E012",t.t==="eof"?"Unexpected end of expression":`Unexpected token '${t.value}'`,t)}}function S(t){let e=[],r=z(t,e);return{ast:new C(r,e).parse(),diagnostics:e}}function A(t){let e=[],r=0,s=0;for(let f=0;f<t.length;f++){let m=t[f];if(m==="'"||m==='"'||m==="`"){f++;while(f<t.length&&t[f]!==m){if(t[f]==="\\")f++;f++}continue}if(m==="("||m==="["||m==="{")r++;else if(m===")"||m==="]"||m==="}")r--;else if(m===","&&r===0)e.push(t.slice(s,f)),s=f+1}return e.push(t.slice(s)),e.map((f)=>f.trim()).filter(Boolean)}var j=new Set(["if","else-if","else","for","switch","async","let","const","log","context","i18n"]),O=new Set(["case","default","then","catch","loading"]),L=new Set(["a","abbr","address","area","article","aside","audio","b","base","bdi","bdo","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","kbd","label","legend","li","link","main","map","mark","menu","meta","meter","nav","noscript","object","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","slot","small","source","span","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","u","ul","var","video","wbr","svg","circle","clippath","defs","ellipse","foreignobject","g","image","line","lineargradient","marker","mask","path","pattern","polygon","polyline","radialgradient","rect","stop","symbol","text","tspan","use"]);var _=new WeakMap,M={clone(t){let e=_.get(t);if(!e)e=document.createElement("template"),e.innerHTML=t.html,_.set(t,e);return e.content.cloneNode(!0)},fragment:()=>document.createDocumentFragment(),element:(t)=>document.createElement(t),text:(t)=>document.createTextNode(t),marker:(t)=>document.createComment(t),child:(t,e)=>t.childNodes[e],next:(t)=>t.nextSibling,range(t,e){let r=[];for(let s=t;s;s=s.nextSibling)if(r.push(s),s===e)break;return r},insert:(t,e,r)=>{t.insertBefore(e,r)},insertAfter(t,e){let r=t.parentNode;if(!r)return;let s=t;for(let f of e)r.insertBefore(f,s.nextSibling),s=f},remove:(t)=>t.remove(),isElement:(t)=>t.nodeType===1,connected:(t)=>t.isConnected,precedes:(t,e)=>!!(t.compareDocumentPosition(e)&4),attr:(t,e,r)=>r===null?t.removeAttribute(e):t.setAttribute(e,r),setText:(t,e)=>{t.data=e},content:(t,e)=>{t.textContent=e},html:(t,e)=>{t.innerHTML=e},styleVar:(t,e,r)=>r===null?t.style.removeProperty(e):t.style.setProperty(e,r),scope:(t,e)=>{t.hasAttribute("rel")||t.setAttribute("rel",e)},listen(t,e,r){return t.addEventListener(e,r),()=>t.removeEventListener(e,r)},keepFocus(){let t=document.activeElement;return()=>{t&&t.isConnected&&t!==document.activeElement&&t.focus()}}};var J=Symbol.for("lips.self"),H=(t,e,r)=>{let s=t.slice(0,e).split(`
3
- `);return{line:s.length,col:s[s.length-1].length+1,offset:e,length:r}},k=(t,e,r)=>({code:t,message:e,hint:r}),w=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),U=new Set(["constructor","__proto__","prototype","__defineGetter__","__defineSetter__","__lookupGetter__","__lookupSetter__","caller","callee"]),K=new Set(["script","iframe","frame","frameset","object","embed","applet","portal","fencedframe","base","link","meta","style","title","head","body","html","template","noscript","noembed","noframes","xmp","plaintext","animate","animatemotion","animatetransform","set"]),X=new Set(["href","src","action","formaction","xlink:href","poster","cite","background","longdesc","manifest","data","codebase","lowsrc","dynsrc","icon"]),Z=new Set(["http","https","mailto","tel"]),B={srcdoc:"It is a whole document, written into an attribute",is:"It makes the element one the page defined, running the page's code",form:"It joins a form of the host page by id"},W=new WeakSet,I=(t)=>(W.add(t),Object.freeze(t)),E=(t,e)=>Object.fromEntries(e.map((r)=>[r,t[r]])),P=(t,e={})=>I(Object.assign((...r)=>t(...r),e)),Y={Math:I(E(Math,Object.getOwnPropertyNames(Math))),JSON:I(E(JSON,["parse","stringify"])),Object:I(E(Object,["keys","values","entries","fromEntries"])),Array:I(E(Array,["isArray","from","of"])),String:P(String,E(String,["fromCharCode","fromCodePoint"])),Number:P(Number,E(Number,["isFinite","isInteger","isNaN","isSafeInteger","parseFloat","parseInt","EPSILON","MAX_SAFE_INTEGER","MIN_SAFE_INTEGER"])),Boolean:P(Boolean),Date:P(Date,E(Date,["now","parse","UTC"])),parseInt,parseFloat,isNaN,isFinite,encodeURIComponent,decodeURIComponent,encodeURI,decodeURI};function Q(t){let e="",r=0;while(r<t.length){let s=t[r];if(s==='"'||s==="'"){let f=r+1;while(f<t.length&&t[f]!==s)f+=t[f]==="\\"?2:1;e+=t.slice(r,f+1),r=f+1;continue}if(s==="/"&&t[r+1]==="*"){let f=t.indexOf("*/",r+2);r=f<0?t.length:f+2;continue}e+=s,r++}return e.replace(/\\(?:([\da-f]{1,6})[ \t\n\r\f]?|([^\n\r\f\da-f])|[\n\r\f])/gi,(s,f,m)=>f?String.fromCodePoint(Math.min(parseInt(f,16),1114111)||65533):m??"")}var tt=(t)=>t===globalThis||t===globalThis.eval||typeof t==="function"&&/^(Async|AsyncGenerator|Generator)?Function$/.test(t.name)&&t.prototype?.constructor===t||typeof Node==="function"&&t instanceof Node||typeof Event==="function"&&t instanceof Event||typeof EventTarget==="function"&&t instanceof EventTarget||typeof t==="object"&&(("nodeType"in t)&&("ownerDocument"in t)||t.window===t),T={globals:Y,member(t,e,r){if(U.has(t))return k("LIPS-U002",`'${t}' leads to prototypes and constructors, not data`,"An untrusted template reads and writes data; prototype machinery is not reachable");if(r!=null&&W.has(r)&&(e||!w(r,t)))return k("LIPS-U003",e?`Globals are read-only — '${t}' cannot be written`:`'${t}' is not offered`,"Offered: Math, JSON, Object.keys/values/entries/fromEntries, Array.isArray/from/of, String, Number, Boolean, Date, parseInt, parseFloat, isNaN, isFinite and the URI codecs")},self(t,e){if(e)return k("LIPS-U005",`self is read-only — '${t}' cannot be written`,"Write state instead: state.x = …");if(U.has(t))return this.member(t,!1);if(t==="node")return k("LIPS-U005","self.node holds the component's DOM nodes","An untrusted template reaches the page only through the template language")},value(t){if(t!==null&&(typeof t==="object"||typeof t==="function")&&tt(t))return k("LIPS-U004","A DOM node, window, event or code constructor cannot be held by an untrusted template","Hand the template data, not the platform object it came from")},event(t){let e=(r)=>r&&{value:r.value,checked:r.checked,name:r.name,id:r.id,type:r.type,tagName:r.tagName,dataset:{...r.dataset}};return{type:t.type,key:t.key,code:t.code,data:t.data,inputType:t.inputType,altKey:t.altKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,shiftKey:t.shiftKey,repeat:t.repeat,button:t.button,buttons:t.buttons,clientX:t.clientX,clientY:t.clientY,deltaX:t.deltaX,deltaY:t.deltaY,target:e(t.target),currentTarget:e(t.currentTarget),preventDefault:()=>t.preventDefault(),stopPropagation:()=>t.stopPropagation()}},tag(t){let e=t.toLowerCase();if(K.has(e))return k("LIPS-U010",`<${e}> is refused in an untrusted template`,"It runs script, holds a document of its own, or acts on the whole page");if(e.includes("-"))return k("LIPS-U011",`<${e}> is a custom element`,"Custom elements run the page's own code — a Lips component the host registered renders instead")},component(t){if(t==="router")return k("LIPS-U012","<router> owns the page URL and window.navigate","Switch on state for pages — <switch( state.page )>; routing stays with the host")},attr(t,e,r){let s=e.toLowerCase();if(s.startsWith("on"))return k("LIPS-U020",`'${e}' is an event-handler attribute`,"Use the instruction form: on-click( … )");if(w(B,s))return k("LIPS-U021",`'${e}' is refused`,B[s]);if(r===void 0)return;if((s==="id"||s==="name")&&typeof document==="object"&&r in document)return k("LIPS-U022",`${s}="${r}" would shadow document.${r}`,"Choose another value");if(s==="style")return this.css(r);if(X.has(s))return this.url(r);if(s==="srcset"||s==="imagesrcset"||s==="ping")for(let f of r.split(s==="ping"?/\s+/:",")){let m=f.trim()?this.url(f.trim().split(/\s+/)[0]):void 0;if(m)return m}},url(t){let e=String(t).replace(/[\t\n\r]/g,"").replace(/^[\u0000- ]+/,""),r=/^([a-z][a-z\d+.-]*):/i.exec(e)?.[1].toLowerCase();if(!r||Z.has(r)||/^data:image\/(png|gif|jpe?g|webp|avif|bmp)[;,]/i.test(e))return;return k("LIPS-U030",`'${r}:' URLs are refused`,"Use a relative, http(s), mailto: or tel: URL — or a raster data:image")},css(t){let e=Q(t);if(/@import\b/i.test(e))return k("LIPS-U040","@import loads a stylesheet outside the component scope","Write the rules into the stylesheet itself");if(/(?:^|[^\w-])(?:-webkit-|-moz-)?(?:image-set|image|cross-fade|element)\(/i.test(e))return k("LIPS-U041","image-set(), image(), cross-fade() and element() load without url()","Use url( … ), which is held to the URL rule");for(let r of e.matchAll(/\b(?:url|src)\(\s*(?:"([^"]*)"|'([^']*)'|([^)]*))/gi)){let s=this.url((r[1]??r[2]??r[3]).trim());if(s)return s}},report(t){console.warn("[lips:untrusted]",t)}},et=new Set(["state","input","context","static","self","arguments"]),rt=new Set([...j,...O,"macro"]),R=new Set;function V(t,e,r,s,f=!1){let{ast:m,diagnostics:g}=S(e);if(g.length)return!0;let d=!0,p=(n,a=0,c=1)=>{if(n)d=!1,s(n,a,c)},l=(n,a)=>a.has(n)||r.has(n)||et.has(n)||w(t.globals,n);if(f&&m.t==="id"&&!l(m.name,R))return p(t.self(m.name),m.at,m.name.length),d;let o=(n,a,c=!1)=>{switch(n.t){case"id":l(n.name,a)||p(k("LIPS-U001",`'${n.name}' is not provided to an untrusted template`,"Expressions read state, input, context, static, self, their scope, and the globals the policy offers"),n.at,n.name.length);return;case"member":{o(n.obj,a),n.computed&&o(n.prop,a);let h=n.prop,i=!n.computed?n.prop:h.t==="lit"&&(typeof h.v==="string"||typeof h.v==="number")?String(h.v):void 0;if(i===void 0)return;let u=n.obj.t==="id"&&!a.has(n.obj.name)&&!r.has(n.obj.name)?n.obj.name:"";p(u==="self"?t.self(i,c):u&&w(t.globals,u)?t.member(i,c,t.globals[u]):t.member(i,c),n.at,i.length);return}case"call":o(n.callee,a),n.args.forEach((h)=>o(h,a));return;case"unary":o(n.arg,a);return;case"update":o(n.arg,a,!0);return;case"bin":case"logic":o(n.l,a),o(n.r,a);return;case"cond":o(n.test,a),o(n.cons,a),o(n.alt,a);return;case"assign":o(n.target,a,!0),o(n.value,a);return;case"arrow":o(n.body,new Set([...a,...n.params]));return;case"arr":n.items.forEach((h)=>o(h.value,a));return;case"obj":for(let h of n.props)h.key!==void 0&&p(t.member(h.key,!0),h.at,h.key.length),o(h.value,a)}};return o(m,R),d}function q(t=T){return(e,r,s)=>{let f=new Set,m=(i,u,b=1)=>r.push({...i,severity:"error",loc:H(s,u,b)}),g=(i,u)=>{let b=s.indexOf(i,u);return b<0?u:b},d=(i,u,b=!1)=>V(t,i,f,(x,y,v)=>m(x,u+y,v),b),p=(i,u,b=!0)=>{let x=!0,y=0;return A(i).forEach((v,N)=>{y=i.indexOf(v,y),x=d(v,u+y,b&&N===0)&&x,y+=v.length}),x},l=(i)=>{for(let u of i)if(typeof u!=="string"&&!d(u.expr,g(u.expr,u.loc.offset)))u.expr="undefined"},o=(i)=>L.has(i)?t.tag(i):t.component(i),n=(i)=>{for(let u of i){if(u.t==="fragment")n(u.children);if(u.t!=="element")continue;for(let b of u.attrs)b.k==="args"?b.names.forEach((x)=>f.add(x)):(u.tag==="let"||u.tag==="const")&&("name"in b)&&f.add(b.name);n(u.children)}},a=(i,u)=>{let b=i.loc.offset;switch(i.k){case"args":return!0;case"event":return p(i.source,g(i.source,b));case"spread":case"fn":return d(i.source,g(i.source,b))}if(u&&!/^(@(?!html$)|i18n(-|$))/.test(i.name)){let x=t.attr(u,i.name,i.k==="literal"?i.value:i.k==="bool"?"":void 0);if(x)return m(x,b,i.name.length),!1}if(i.name==="@format"){let x=i.k==="literal"?i.value:i.k==="expr"?i.source:i.k==="interp"?i.parts.map((v)=>typeof v==="string"?v:`{${v.expr}}`).join(""):"",y=x.slice(x.indexOf(",")+1).trim();return!x.includes(",")||d(y,g(y,b))}if(i.k==="expr"&&!d(i.source,g(i.source,b)))i.source="undefined";if(i.k==="interp")l(i.parts);return!0},c=(i)=>{let{tag:u}=i;if(u==="#dynamic"){let x=i.dynamicTag,y=g(x.expr,x.loc.offset);if(!d(x.expr,y))x.expr="undefined";else{let{ast:v}=S(x.expr),N=v.t==="lit"&&typeof v.v==="string"?o(v.v.toLowerCase()):void 0;if(N)return m(N,y,x.expr.length),!1}}else if(!rt.has(u)){let x=o(u);if(x)return m(x,i.loc.offset,u.length+1),!1}if(i.head){let x=i.head,y=g(x.expr,x.loc.offset);(u==="log"?p(x.expr,y,!1):d(x.expr,y))||(x.expr="undefined")}let b=L.has(u)?u:null;return i.attrs=i.attrs.filter((x)=>a(x,b)),!0},h=(i)=>{for(let u=0;u<i.length;u++){let b=i[u];if(b.t==="fragment")h(b.children);else if(b.t==="interp")l(b.parts);else if(b.t==="element")c(b)?h(b.children):i.splice(u--,1)}};n(e),h(e)}}var D=(t)=>Object.assign(Error(t.message),{name:"PolicyError"},t),F={"+":(t,e)=>t+e,"-":(t,e)=>t-e,"*":(t,e)=>t*e,"/":(t,e)=>t/e,"%":(t,e)=>t%e,"<":(t,e)=>t<e,">":(t,e)=>t>e,"<=":(t,e)=>t<=e,">=":(t,e)=>t>=e,"==":(t,e)=>t==e,"!=":(t,e)=>t!=e,"===":(t,e)=>t===e,"!==":(t,e)=>t!==e};function st(t){let e=(m)=>{if(m)throw D(m)},r=(m)=>(e(t.value(m)),m),s=(m)=>{if(typeof m==="string")return m;if(typeof m==="number")return String(m);throw D(k("LIPS-U002","A computed member must be a string or a number"))},f=(m,g,d)=>e(m!=null&&typeof m==="object"&&m[J]?t.self(g,d):t.member(g,d,m));return(m,g)=>{let d=g.scope,p=(n,a)=>{for(let c of a)if(n in c)return c[n];if(d&&n in d)return r(d[n]);switch(n){case"state":return g.state;case"input":return g.input;case"context":return g.context;case"static":return g.static;case"self":return g.self;case"arguments":return g.arguments}return w(t.globals,n)?t.globals[n]:void 0},l=(n,a,c)=>{if(n.t==="id"){let h=c.find((i)=>(n.name in i))??d;h&&(h[n.name]=a)}else if(n.t==="member"){let h=o(n.obj,c),i=s(n.computed?o(n.prop,c):n.prop);if(f(h,i,!0),h!=null)h[i]=a}return a},o=(n,a)=>{switch(n.t){case"lit":return n.v;case"id":return p(n.name,a);case"member":{let c=o(n.obj,a);if(n.optional&&c==null)return;let h=s(n.computed?o(n.prop,a):n.prop);return f(c,h,!1),c==null?void 0:r(c[h])}case"call":{let c=n.callee,h,i;if(c.t==="member"){if(h=o(c.obj,a),(c.optional||n.optional)&&h==null)return;let u=s(c.computed?o(c.prop,a):c.prop);f(h,u,!1),i=h==null?void 0:r(h[u])}else i=o(c,a);if(n.optional&&i==null)return;return r(Reflect.apply(i,h,n.args.map((u)=>o(u,a))))}case"unary":{let c=o(n.arg,a);return n.op==="!"?!c:n.op==="-"?-c:+c}case"update":{let c=o(n.arg,a),h=n.op==="++"?c+1:c-1;return l(n.arg,h,a),n.prefix?h:c}case"bin":return F[n.op](o(n.l,a),o(n.r,a));case"logic":{let c=o(n.l,a);return n.op==="&&"?c&&o(n.r,a):n.op==="||"?c||o(n.r,a):c??o(n.r,a)}case"cond":return o(n.test,a)?o(n.cons,a):o(n.alt,a);case"assign":return l(n.target,n.op==="="?o(n.value,a):F[n.op[0]](o(n.target,a),o(n.value,a)),a);case"arrow":return(...c)=>{let h=Object.create(null);return n.params.forEach((i,u)=>h[i]=r(c[u])),o(n.body,[h,...a])};case"arr":{let c=[];for(let h of n.items)h.spread?c.push(...o(h.value,a)):c.push(o(h.value,a));return c}case"obj":{let c={},h=(i,u)=>{f(c,i,!0),c[i]=u};for(let i of n.props){let u=o(i.value,a);if(!i.spread)h(i.key,u);else if(u!=null)for(let b of Object.keys(u))h(b,r(u[b]))}return c}}};return o(m,[])}}function nt(t,e=M){let r=new WeakMap,s=(p)=>(p&&t.report(p),!!p),f=(p)=>p.localName.toLowerCase(),m=(p,l)=>{let o=p.createElement("template");return o.setAttribute("data-lips-refused",l),o},g=(p)=>{for(let l of[...p.querySelectorAll("*")]){let o=f(l);if(s(t.tag(o))){let a=m(l.ownerDocument,o);a.append(...l.childNodes),l.replaceWith(a);continue}let n=!1;for(let{name:a,value:c}of[...l.attributes])if(s(t.attr(o,a,c)))l.removeAttribute(a),n||=a.toLowerCase()==="is";if(n){let a=l.ownerDocument.createElementNS(l.namespaceURI,l.localName);for(let c of[...l.attributes])a.setAttribute(c.name,c.value);a.append(...l.childNodes),l.replaceWith(a)}}},d=(p)=>{let l=document.createElement("template");return l.innerHTML=p,g(l.content),l};return{...e,clone(p){let l=r.get(p);if(!l)r.set(p,l=d(p.html));return l.content.cloneNode(!0)},element:(p)=>s(t.tag(p.toLowerCase()))?m(document,p):e.element(p),attr(p,l,o){e.attr(p,l,o!==null&&s(t.attr(f(p),l,o))?null:o)},html(p,l){s(t.attr(f(p),"@html",l))?e.content(p,""):p.replaceChildren(d(l).content)},styleVar(p,l,o){e.styleVar(p,l,o!==null&&s(t.css(o))?null:o)},listen:(p,l,o)=>e.listen(p,l,(n)=>o(t.event(n)))}}var it={ir:{v:1,exprs:[],root:{html:"",scope:[],binds:[],blocks:[]}}};function ot(t=T){let e=st(t),r=new Map,s=nt(t),f=new Set,m={run(g){let d=r.get(g);if(!d)r.set(g,d=S(g).ast);return(p)=>e(d,p)},self:(g)=>t.self(g)};return{check:q(t),style:(g)=>(d,p)=>{let l=g(d,{...p,lint(c,h){let i=h!==void 0?t.css(h):c[0]==="@"?t.css(c):void 0;return i&&[{...i,severity:"error"}]}}),o=(c,h,i)=>l.diagnostics.push({...c,severity:"error",loc:H(d,Math.max(h,0),i)}),n=!l.diagnostics.some((c)=>c.code.startsWith("LIPS-U"));for(let c of l.ir.exprs){let h=d.indexOf(c);n=V(t,c,R,(i,u,b)=>o(i,h+u,b))&&n}let a=n?t.css(l.ir.css):void 0;if(a&&o(a,0,0),!n||a)return{...l,ir:{...l.ir,css:"",binds:[],props:void 0}};return f.add(l.ir.css),l},runtime(g){let{components:d,createStylesheet:p}=g;return{...g,guard:m,host:s,components:d&&new Proxy(d,{get:(l,o)=>at(t,o)?it:l[o]}),createStylesheet:p&&((l,o)=>{if(f.has(o))return p(l,o);return t.report(k("LIPS-U042",`A stylesheet Lips did not compile cannot be checked — <${l}> ships unstyled`,"Send the stylesheet source; precompiled sheets are trusted output")),{clear(){}}})}}}}var at=(t,e)=>{let r=typeof e==="string"?t.component(e):void 0;return r&&t.report(r),!!r};export{q as checkTemplate,ot as untrusted,T as untrustedPolicy};
1
+ var z=["===","!==","...","=>","==","!=","<=",">=","&&","||","??","?.","++","--","+=","-=","*=","/=","%=","+","-","*","/","%","<",">","!","?",":",".",",","(",")","[","]","{","}","="];function q(t,e){let r=[],n=0,p=(g)=>/[A-Za-z_$]/.test(g),h=(g)=>/[A-Za-z0-9_$]/.test(g);while(n<t.length){let g=t[n];if(/\s/.test(g)){n++;continue}if(/[0-9]/.test(g)||g==="."&&/[0-9]/.test(t[n+1])){let l=n;while(n<t.length&&/[0-9]/.test(t[n]))n++;if(t[n]==="."){n++;while(n<t.length&&/[0-9]/.test(t[n]))n++}if(t[n]==="e"||t[n]==="E"){if(n++,t[n]==="+"||t[n]==="-")n++;while(n<t.length&&/[0-9]/.test(t[n]))n++}r.push({t:"num",value:t.slice(l,n),start:l,end:n});continue}if(g==="'"||g==='"'){let l=n;n++;let u="",a=!1;while(n<t.length){let s=t[n];if(s==="\\"){let o=t[n+1],c={n:`
2
+ `,t:"\t",r:"\r",b:"\b",f:"\f",v:"\v","0":"\x00"};if(o==="u"){let m=t.slice(n+2,n+6);u+=String.fromCharCode(parseInt(m,16)||0),n+=6}else u+=c[o]??o,n+=2;continue}if(s===g){a=!0,n++;break}u+=s,n++}if(!a)e.push({code:"LIPS-E001",message:"Unterminated string literal",loc:{offset:l,length:n-l}});r.push({t:"str",value:u,start:l,end:n});continue}if(p(g)){let l=n;while(n<t.length&&h(t[n]))n++;r.push({t:"id",value:t.slice(l,n),start:l,end:n});continue}let d=z.find((l)=>t.startsWith(l,n));if(d==="?."&&/[0-9]/.test(t[n+2]??""))d="?";if(d){r.push({t:"punct",value:d,start:n,end:n+d.length}),n+=d.length;continue}e.push({code:"LIPS-E002",message:`Unexpected character '${g}'`,loc:{offset:n,length:1}}),n++}return r.push({t:"eof",value:"",start:t.length,end:t.length}),r}class R{tokens;diagnostics;pos=0;constructor(t,e){this.tokens=t;this.diagnostics=e}peek(t=0){return this.tokens[Math.min(this.pos+t,this.tokens.length-1)]}next(){return this.tokens[this.pos++]??this.tokens[this.tokens.length-1]}at(t){let e=this.peek();return e.t==="punct"&&e.value===t}eat(t){if(this.at(t))return this.pos++,!0;return!1}error(t,e,r=this.peek()){return this.diagnostics.push({code:t,message:e,loc:{offset:r.start,length:Math.max(1,r.end-r.start)}}),{t:"error"}}expect(t,e){if(!this.eat(t))this.error(e,`Expected '${t}'`)}parse(){let t=this.assign();if(this.peek().t!=="eof")this.error("LIPS-E003",`Unexpected token '${this.peek().value}' after expression`);return t}isArrowAhead(){let t=this.peek();if(t.t==="id"){let e=this.peek(1);return e.t==="punct"&&e.value==="=>"}if(t.t==="punct"&&t.value==="("){let e=0,r=0;while(!0){let n=this.peek(r);if(n.t==="eof")return!1;if(n.t==="punct"&&n.value==="(")e++;if(n.t==="punct"&&n.value===")"){if(e--,e===0){let p=this.peek(r+1);return p.t==="punct"&&p.value==="=>"}}r++}}return!1}assign(){if(this.isArrowAhead()){let r=[];if(this.peek().t==="id")r.push(this.next().value);else{this.expect("(","LIPS-E004");while(!this.at(")")&&this.peek().t!=="eof"){let n=this.next();if(n.t!=="id")return this.error("LIPS-E005","Invalid arrow parameter",n);if(r.push(n.value),!this.eat(","))break}this.expect(")","LIPS-E004")}return this.expect("=>","LIPS-E004"),{t:"arrow",params:r,body:this.assign()}}let t=this.conditional(),e=this.peek();if(e.t==="punct"&&["=","+=","-=","*=","/=","%="].includes(e.value)){if(t.t!=="id"&&t.t!=="member")return this.error("LIPS-E006","Invalid assignment target",e);return this.next(),{t:"assign",op:e.value,target:t,value:this.assign()}}return t}conditional(){let t=this.nullish();if(this.eat("?")){let e=this.assign();return this.expect(":","LIPS-E007"),{t:"cond",test:t,cons:e,alt:this.assign()}}return t}nullish(){let t=this.or();while(this.at("??"))this.next(),t={t:"logic",op:"??",l:t,r:this.or()};return t}or(){let t=this.and();while(this.at("||"))this.next(),t={t:"logic",op:"||",l:t,r:this.and()};return t}and(){let t=this.equality();while(this.at("&&"))this.next(),t={t:"logic",op:"&&",l:t,r:this.equality()};return t}equality(){let t=this.relational();while(["===","!==","==","!="].some((e)=>this.at(e)))t={t:"bin",op:this.next().value,l:t,r:this.relational()};return t}relational(){let t=this.additive();while(["<=",">=","<",">"].some((e)=>this.at(e)))t={t:"bin",op:this.next().value,l:t,r:this.additive()};return t}additive(){let t=this.multiplicative();while(this.at("+")||this.at("-"))t={t:"bin",op:this.next().value,l:t,r:this.multiplicative()};return t}multiplicative(){let t=this.unary();while(this.at("*")||this.at("/")||this.at("%"))t={t:"bin",op:this.next().value,l:t,r:this.unary()};return t}unary(){if(this.at("!")||this.at("-")||this.at("+"))return{t:"unary",op:this.next().value,arg:this.unary()};if(this.at("++")||this.at("--")){let t=this.next().value,e=this.unary();if(e.t!=="id"&&e.t!=="member")return this.error("LIPS-E006","Invalid update target");return{t:"update",op:t,arg:e,prefix:!0}}return this.postfix()}postfix(){let t=this.callMember();if(this.at("++")||this.at("--")){let e=this.next().value;if(t.t!=="id"&&t.t!=="member")return this.error("LIPS-E006","Invalid update target");t={t:"update",op:e,arg:t,prefix:!1}}return t}callMember(){let t=this.primary();while(!0)if(this.eat(".")){let e=this.next();if(e.t!=="id")return this.error("LIPS-E008","Expected property name",e);t={t:"member",obj:t,prop:e.value,computed:!1,optional:!1,at:e.start}}else if(this.eat("?."))if(this.at("("))t={t:"call",callee:t,args:this.argList(),optional:!0};else if(this.eat("[")){let e=this.peek().start,r=this.assign();this.expect("]","LIPS-E009"),t={t:"member",obj:t,prop:r,computed:!0,optional:!0,at:e}}else{let e=this.next();if(e.t!=="id")return this.error("LIPS-E008","Expected property name",e);t={t:"member",obj:t,prop:e.value,computed:!1,optional:!0,at:e.start}}else if(this.eat("[")){let e=this.peek().start,r=this.assign();this.expect("]","LIPS-E009"),t={t:"member",obj:t,prop:r,computed:!0,optional:!1,at:e}}else if(this.at("("))t={t:"call",callee:t,args:this.argList(),optional:!1};else break;return t}argList(){this.expect("(","LIPS-E010");let t=[];while(!this.at(")")&&this.peek().t!=="eof")if(t.push(this.assign()),!this.eat(","))break;return this.expect(")","LIPS-E010"),t}primary(){let t=this.peek();if(t.t==="num")return this.next(),{t:"lit",v:parseFloat(t.value)};if(t.t==="str")return this.next(),{t:"lit",v:t.value};if(t.t==="id")switch(this.next(),t.value){case"true":return{t:"lit",v:!0};case"false":return{t:"lit",v:!1};case"null":return{t:"lit",v:null};case"undefined":return{t:"lit",v:void 0};case"NaN":return{t:"lit",v:NaN};case"Infinity":return{t:"lit",v:1/0};default:return{t:"id",name:t.value,at:t.start}}if(this.eat("(")){let e=this.assign();return this.expect(")","LIPS-E010"),e}if(this.eat("[")){let e=[];while(!this.at("]")&&this.peek().t!=="eof"){let r=this.eat("...");if(e.push({spread:r||void 0,value:this.assign()}),!this.eat(","))break}return this.expect("]","LIPS-E009"),{t:"arr",items:e}}if(this.eat("{")){let e=[];while(!this.at("}")&&this.peek().t!=="eof"){if(this.eat("..."))e.push({spread:!0,value:this.assign()});else{let r=this.next();if(r.t!=="id"&&r.t!=="str"&&r.t!=="num")return this.error("LIPS-E011","Invalid object key",r);if(this.eat(":"))e.push({key:String(r.value),value:this.assign(),at:r.start});else if(r.t==="id")e.push({key:r.value,value:{t:"id",name:r.value,at:r.start},at:r.start});else return this.error("LIPS-E011","Invalid shorthand property",r)}if(!this.eat(","))break}return this.expect("}","LIPS-E011"),{t:"obj",props:e}}return this.next(),this.error("LIPS-E012",t.t==="eof"?"Unexpected end of expression":`Unexpected token '${t.value}'`,t)}}function I(t){let e=[],r=q(t,e);return{ast:new R(r,e).parse(),diagnostics:e}}function _(t){let e=[],r=0,n=0;for(let p=0;p<t.length;p++){let h=t[p];if(h==="'"||h==='"'||h==="`"){p++;while(p<t.length&&t[p]!==h){if(t[p]==="\\")p++;p++}continue}if(h==="("||h==="["||h==="{")r++;else if(h===")"||h==="]"||h==="}")r--;else if(h===","&&r===0)e.push(t.slice(n,p)),n=p+1}return e.push(t.slice(n)),e.map((p)=>p.trim()).filter(Boolean)}var lt=Symbol("lips.ended");var O=new Set(["if","else-if","else","for","switch","async","let","const","log","context","i18n"]),A=new Set(["case","default","then","catch","loading"]),T=new Set(["a","abbr","address","area","article","aside","audio","b","base","bdi","bdo","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","kbd","label","legend","li","link","main","map","mark","menu","meta","meter","nav","noscript","object","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","slot","small","source","span","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","u","ul","var","video","wbr","svg","circle","clippath","defs","ellipse","foreignobject","g","image","line","lineargradient","marker","mask","path","pattern","polygon","polyline","radialgradient","rect","stop","symbol","text","tspan","use"]);var C=new WeakMap,U=(t)=>t!==null,J={__proto__:null,value:(t)=>t??"",checked:U,selected:U},M={clone(t){let e=C.get(t);if(!e)e=document.createElement("template"),e.innerHTML=t.html,C.set(t,e);return e.content.cloneNode(!0)},fragment:()=>document.createDocumentFragment(),element:(t)=>document.createElement(t),text:(t)=>document.createTextNode(t),marker:(t)=>document.createComment(t),child:(t,e)=>t.childNodes[e],next:(t)=>t.nextSibling,range(t,e){let r=[];for(let n=t;n;n=n.nextSibling)if(r.push(n),n===e)break;return r},insert:(t,e,r)=>{t.insertBefore(e,r)},insertAfter(t,e){let r=t.parentNode;if(!r)return;let n=t;for(let p of e)r.insertBefore(p,n.nextSibling),n=p},remove:(t)=>t.remove(),isElement:(t)=>t.nodeType===1,connected:(t)=>t.isConnected,precedes:(t,e)=>!!(t.compareDocumentPosition(e)&4),attr(t,e,r){r===null?t.removeAttribute(e):t.setAttribute(e,r);let n=J[e];n&&e in t&&(t[e]=n(r))},setText:(t,e)=>{t.data=e},content:(t,e)=>{t.textContent=e},html:(t,e)=>{t.innerHTML=e},styleVar:(t,e,r)=>r===null?t.style.removeProperty(e):t.style.setProperty(e,r),scope:(t,e)=>{t.hasAttribute("rel")||t.setAttribute("rel",e)},listen(t,e,r){let n=e.split(".")[0],p=e.includes(".outside"),h=p?document:t,g=p||e.includes(".capture"),d=!p&&e.includes(".stop"),l=(u)=>p&&t.contains(u.target)||(d&&u.stopPropagation(),r(u));return h.addEventListener(n,l,g),()=>h.removeEventListener(n,l,g)},keepFocus(){let t=document.activeElement;return()=>{t&&t.isConnected&&t!==document.activeElement&&t.focus()}}};var X=Symbol.for("lips.self"),G=(t,e,r)=>{let n=t.slice(0,e).split(`
3
+ `);return{line:n.length,col:n[n.length-1].length+1,offset:e,length:r}},y=(t,e,r)=>({code:t,message:e,hint:r}),w=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),F=new Set(["constructor","__proto__","prototype","__defineGetter__","__defineSetter__","__lookupGetter__","__lookupSetter__","caller","callee"]),Y=new Set(["script","iframe","frame","frameset","object","embed","applet","portal","fencedframe","base","link","meta","style","title","head","body","html","template","noscript","noembed","noframes","xmp","plaintext","animate","animatemotion","animatetransform","set"]),Z=new Set(["href","src","action","formaction","xlink:href","poster","cite","background","longdesc","manifest","data","codebase","lowsrc","dynsrc","icon"]),Q=new Set(["http","https","mailto","tel"]),D={srcdoc:"It is a whole document, written into an attribute",is:"It makes the element one the page defined, running the page's code",form:"It joins a form of the host page by id"},B=new WeakSet,k=(t)=>(B.add(t),Object.freeze(t)),S=(t,e)=>Object.fromEntries(e.map((r)=>[r,t[r]])),L=(t,e={})=>k(Object.assign((...r)=>t(...r),e)),tt={Math:k(S(Math,Object.getOwnPropertyNames(Math))),JSON:k(S(JSON,["parse","stringify"])),Object:k(S(Object,["keys","values","entries","fromEntries"])),Array:k(S(Array,["isArray","from","of"])),String:L(String,S(String,["fromCharCode","fromCodePoint"])),Number:L(Number,S(Number,["isFinite","isInteger","isNaN","isSafeInteger","parseFloat","parseInt","EPSILON","MAX_SAFE_INTEGER","MIN_SAFE_INTEGER"])),Boolean:L(Boolean),Date:L(Date,S(Date,["now","parse","UTC"])),parseInt,parseFloat,isNaN,isFinite,encodeURIComponent,decodeURIComponent,encodeURI,decodeURI};function et(t){let e="",r=0;while(r<t.length){let n=t[r];if(n==='"'||n==="'"){let p=r+1;while(p<t.length&&t[p]!==n)p+=t[p]==="\\"?2:1;e+=t.slice(r,p+1),r=p+1;continue}if(n==="/"&&t[r+1]==="*"){let p=t.indexOf("*/",r+2);r=p<0?t.length:p+2;continue}e+=n,r++}return e.replace(/\\(?:([\da-f]{1,6})[ \t\n\r\f]?|([^\n\r\f\da-f])|[\n\r\f])/gi,(n,p,h)=>p?String.fromCodePoint(Math.min(parseInt(p,16),1114111)||65533):h??"")}var rt=(t)=>t===globalThis||t===globalThis.eval||typeof t==="function"&&/^(Async|AsyncGenerator|Generator)?Function$/.test(t.name)&&t.prototype?.constructor===t||typeof Node==="function"&&t instanceof Node||typeof Event==="function"&&t instanceof Event||typeof EventTarget==="function"&&t instanceof EventTarget||typeof t==="object"&&(("nodeType"in t)&&("ownerDocument"in t)||t.window===t),P={globals:tt,member(t,e,r){if(F.has(t))return y("LIPS-U002",`'${t}' leads to prototypes and constructors, not data`,"An untrusted template reads and writes data; prototype machinery is not reachable");if(r!=null&&B.has(r)&&(e||!w(r,t)))return y("LIPS-U003",e?`Globals are read-only — '${t}' cannot be written`:`'${t}' is not offered`,"Offered: Math, JSON, Object.keys/values/entries/fromEntries, Array.isArray/from/of, String, Number, Boolean, Date, parseInt, parseFloat, isNaN, isFinite and the URI codecs")},self(t,e){if(e)return y("LIPS-U005",`self is read-only — '${t}' cannot be written`,"Write state instead: state.x = …");if(F.has(t))return this.member(t,!1);if(t==="node"||t==="refs")return y("LIPS-U005",`self.${t} holds the component's DOM nodes`,"An untrusted template reaches the page only through the template language")},value(t){if(t!==null&&(typeof t==="object"||typeof t==="function")&&rt(t))return y("LIPS-U004","A DOM node, window, event or code constructor cannot be held by an untrusted template","Hand the template data, not the platform object it came from")},event(t){let e=(r)=>r&&{value:r.value,checked:r.checked,name:r.name,id:r.id,type:r.type,tagName:r.tagName,dataset:{...r.dataset}};return{type:t.type,key:t.key,code:t.code,data:t.data,inputType:t.inputType,altKey:t.altKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,shiftKey:t.shiftKey,repeat:t.repeat,button:t.button,buttons:t.buttons,clientX:t.clientX,clientY:t.clientY,deltaX:t.deltaX,deltaY:t.deltaY,target:e(t.target),currentTarget:e(t.currentTarget),preventDefault:()=>t.preventDefault(),stopPropagation:()=>t.stopPropagation()}},tag(t){let e=t.toLowerCase();if(Y.has(e))return y("LIPS-U010",`<${e}> is refused in an untrusted template`,"It runs script, holds a document of its own, or acts on the whole page");if(e.includes("-"))return y("LIPS-U011",`<${e}> is a custom element`,"Custom elements run the page's own code — a Lips component the host registered renders instead")},component(t){if(t==="router")return y("LIPS-U012","<router> owns the page URL and window.navigate","Switch on state for pages — <switch( state.page )>; routing stays with the host")},attr(t,e,r){let n=e.toLowerCase();if(n.startsWith("on"))return y("LIPS-U020",`'${e}' is an event-handler attribute`,"Use the instruction form: on-click( … )");if(w(D,n))return y("LIPS-U021",`'${e}' is refused`,D[n]);if(r===void 0)return;if((n==="id"||n==="name")&&typeof document==="object"&&r in document)return y("LIPS-U022",`${n}="${r}" would shadow document.${r}`,"Choose another value");if(n==="style")return this.css(r);if(Z.has(n))return this.url(r);if(n==="srcset"||n==="imagesrcset"||n==="ping")for(let p of r.split(n==="ping"?/\s+/:",")){let h=p.trim()?this.url(p.trim().split(/\s+/)[0]):void 0;if(h)return h}},url(t){let e=String(t).replace(/[\t\n\r]/g,"").replace(/^[\u0000- ]+/,""),r=/^([a-z][a-z\d+.-]*):/i.exec(e)?.[1].toLowerCase();if(!r||Q.has(r)||/^data:image\/(png|gif|jpe?g|webp|avif|bmp)[;,]/i.test(e))return;return y("LIPS-U030",`'${r}:' URLs are refused`,"Use a relative, http(s), mailto: or tel: URL — or a raster data:image")},css(t){let e=et(t);if(/@import\b/i.test(e))return y("LIPS-U040","@import loads a stylesheet outside the component scope","Write the rules into the stylesheet itself");if(/(?:^|[^\w-])(?:-webkit-|-moz-)?(?:image-set|image|cross-fade|element)\(/i.test(e))return y("LIPS-U041","image-set(), image(), cross-fade() and element() load without url()","Use url( … ), which is held to the URL rule");for(let r of e.matchAll(/\b(?:url|src)\(\s*(?:"([^"]*)"|'([^']*)'|([^)]*))/gi)){let n=this.url((r[1]??r[2]??r[3]).trim());if(n)return n}},report(t){console.warn("[lips:untrusted]",t)}},nt=new Set(["state","input","context","static","self","arguments"]),st=new Set([...O,...A,"macro"]),j=new Set;function W(t,e,r,n,p=!1){let{ast:h,diagnostics:g}=I(e);if(g.length)return!0;let d=!0,l=(s,o=0,c=1)=>{if(s)d=!1,n(s,o,c)},u=(s,o)=>o.has(s)||r.has(s)||nt.has(s)||w(t.globals,s);if(p&&h.t==="id"&&!u(h.name,j))return l(t.self(h.name),h.at,h.name.length),d;let a=(s,o,c=!1)=>{switch(s.t){case"id":u(s.name,o)||l(y("LIPS-U001",`'${s.name}' is not provided to an untrusted template`,"Expressions read state, input, context, static, self, their scope, and the globals the policy offers"),s.at,s.name.length);return;case"member":{a(s.obj,o),s.computed&&a(s.prop,o);let m=s.prop,i=!s.computed?s.prop:m.t==="lit"&&(typeof m.v==="string"||typeof m.v==="number")?String(m.v):void 0;if(i===void 0)return;let f=s.obj.t==="id"&&!o.has(s.obj.name)&&!r.has(s.obj.name)?s.obj.name:"";l(f==="self"?t.self(i,c):f&&w(t.globals,f)?t.member(i,c,t.globals[f]):t.member(i,c),s.at,i.length);return}case"call":a(s.callee,o),s.args.forEach((m)=>a(m,o));return;case"unary":a(s.arg,o);return;case"update":a(s.arg,o,!0);return;case"bin":case"logic":a(s.l,o),a(s.r,o);return;case"cond":a(s.test,o),a(s.cons,o),a(s.alt,o);return;case"assign":a(s.target,o,!0),a(s.value,o);return;case"arrow":a(s.body,new Set([...o,...s.params]));return;case"arr":s.items.forEach((m)=>a(m.value,o));return;case"obj":for(let m of s.props)m.key!==void 0&&l(t.member(m.key,!0),m.at,m.key.length),a(m.value,o)}};return a(h,j),d}function K(t=P){return(e,r,n)=>{let p=new Set,h=(i,f,b=1)=>r.push({...i,severity:"error",loc:G(n,f,b)}),g=(i,f)=>{let b=n.indexOf(i,f);return b<0?f:b},d=(i,f,b=!1)=>W(t,i,p,(x,E,v)=>h(x,f+E,v),b),l=(i,f,b=!0)=>{let x=!0,E=0;return _(i).forEach((v,N)=>{E=i.indexOf(v,E),x=d(v,f+E,b&&N===0)&&x,E+=v.length}),x},u=(i)=>{for(let f of i)if(typeof f!=="string"&&!d(f.expr,g(f.expr,f.loc.offset)))f.expr="undefined"},a=(i)=>T.has(i)?t.tag(i):t.component(i),s=(i)=>{for(let f of i){if(f.t==="fragment")s(f.children);if(f.t!=="element")continue;for(let b of f.attrs)b.k==="args"?b.names.forEach((x)=>p.add(x)):(f.tag==="let"||f.tag==="const")&&("name"in b)&&p.add(b.name);s(f.children)}},o=(i,f)=>{let b=i.loc.offset;switch(i.k){case"args":return!0;case"event":return l(i.source,g(i.source,b));case"spread":case"fn":return d(i.source,g(i.source,b))}if(f&&!/^(@(?!html$)|i18n(-|$))/.test(i.name)){let x=t.attr(f,i.name,i.k==="literal"?i.value:i.k==="bool"?"":void 0);if(x)return h(x,b,i.name.length),!1}if(i.name==="@format"){let x=i.k==="literal"?i.value:i.k==="expr"?i.source:i.k==="interp"?i.parts.map((v)=>typeof v==="string"?v:`{${v.expr}}`).join(""):"",E=x.slice(x.indexOf(",")+1).trim();return!x.includes(",")||d(E,g(E,b))}if(i.k==="expr"&&!d(i.source,g(i.source,b)))i.source="undefined";if(i.k==="interp")u(i.parts);return!0},c=(i)=>{let{tag:f}=i;if(f==="#dynamic"){let x=i.dynamicTag,E=g(x.expr,x.loc.offset);if(!d(x.expr,E))x.expr="undefined";else{let{ast:v}=I(x.expr),N=v.t==="lit"&&typeof v.v==="string"?a(v.v.toLowerCase()):void 0;if(N)return h(N,E,x.expr.length),!1}}else if(!st.has(f)){let x=a(f);if(x)return h(x,i.loc.offset,f.length+1),!1}if(i.head){let x=i.head,E=g(x.expr,x.loc.offset);(f==="log"?l(x.expr,E,!1):d(x.expr,E))||(x.expr="undefined")}let b=T.has(f)?f:null;return i.attrs=i.attrs.filter((x)=>o(x,b)),!0},m=(i)=>{for(let f=0;f<i.length;f++){let b=i[f];if(b.t==="fragment")m(b.children);else if(b.t==="interp")u(b.parts);else if(b.t==="element")c(b)?m(b.children):i.splice(f--,1)}};s(e),m(e)}}var H=(t)=>Object.assign(Error(t.message),{name:"PolicyError"},t),V={"+":(t,e)=>t+e,"-":(t,e)=>t-e,"*":(t,e)=>t*e,"/":(t,e)=>t/e,"%":(t,e)=>t%e,"<":(t,e)=>t<e,">":(t,e)=>t>e,"<=":(t,e)=>t<=e,">=":(t,e)=>t>=e,"==":(t,e)=>t==e,"!=":(t,e)=>t!=e,"===":(t,e)=>t===e,"!==":(t,e)=>t!==e};function it(t){let e=(h)=>{if(h)throw H(h)},r=(h)=>(e(t.value(h)),h),n=(h)=>{if(typeof h==="string")return h;if(typeof h==="number")return String(h);throw H(y("LIPS-U002","A computed member must be a string or a number"))},p=(h,g,d)=>e(h!=null&&typeof h==="object"&&h[X]?t.self(g,d):t.member(g,d,h));return(h,g)=>{let d=g.scope,l=(s,o)=>{for(let c of o)if(s in c)return c[s];if(d&&s in d)return r(d[s]);switch(s){case"state":return g.state;case"input":return g.input;case"context":return g.context;case"static":return g.static;case"self":return g.self;case"arguments":return g.arguments}return w(t.globals,s)?t.globals[s]:void 0},u=(s,o,c)=>{if(s.t==="id"){let m=c.find((i)=>(s.name in i))??d;m&&(m[s.name]=o)}else if(s.t==="member"){let m=a(s.obj,c),i=n(s.computed?a(s.prop,c):s.prop);if(p(m,i,!0),m!=null)m[i]=o}return o},a=(s,o)=>{switch(s.t){case"lit":return s.v;case"id":return l(s.name,o);case"member":{let c=a(s.obj,o);if(s.optional&&c==null)return;let m=n(s.computed?a(s.prop,o):s.prop);return p(c,m,!1),c==null?void 0:r(c[m])}case"call":{let c=s.callee,m,i;if(c.t==="member"){if(m=a(c.obj,o),(c.optional||s.optional)&&m==null)return;let f=n(c.computed?a(c.prop,o):c.prop);p(m,f,!1),i=m==null?void 0:r(m[f])}else i=a(c,o);if(s.optional&&i==null)return;return r(Reflect.apply(i,m,s.args.map((f)=>a(f,o))))}case"unary":{let c=a(s.arg,o);return s.op==="!"?!c:s.op==="-"?-c:+c}case"update":{let c=a(s.arg,o),m=s.op==="++"?c+1:c-1;return u(s.arg,m,o),s.prefix?m:c}case"bin":return V[s.op](a(s.l,o),a(s.r,o));case"logic":{let c=a(s.l,o);return s.op==="&&"?c&&a(s.r,o):s.op==="||"?c||a(s.r,o):c??a(s.r,o)}case"cond":return a(s.test,o)?a(s.cons,o):a(s.alt,o);case"assign":return u(s.target,s.op==="="?a(s.value,o):V[s.op[0]](a(s.target,o),a(s.value,o)),o);case"arrow":return(...c)=>{let m=Object.create(null);return s.params.forEach((i,f)=>m[i]=r(c[f])),a(s.body,[m,...o])};case"arr":{let c=[];for(let m of s.items)m.spread?c.push(...a(m.value,o)):c.push(a(m.value,o));return c}case"obj":{let c={},m=(i,f)=>{p(c,i,!0),c[i]=f};for(let i of s.props){let f=a(i.value,o);if(!i.spread)m(i.key,f);else if(f!=null)for(let b of Object.keys(f))m(b,r(f[b]))}return c}}};return a(h,[])}}function at(t,e=M){let r=new WeakMap,n=(l)=>(l&&t.report(l),!!l),p=(l)=>l.localName.toLowerCase(),h=(l,u)=>{let a=l.createElement("template");return a.setAttribute("data-lips-refused",u),a},g=(l)=>{for(let u of[...l.querySelectorAll("*")]){let a=p(u);if(n(t.tag(a))){let o=h(u.ownerDocument,a);o.append(...u.childNodes),u.replaceWith(o);continue}let s=!1;for(let{name:o,value:c}of[...u.attributes])if(n(t.attr(a,o,c)))u.removeAttribute(o),s||=o.toLowerCase()==="is";if(s){let o=u.ownerDocument.createElementNS(u.namespaceURI,u.localName);for(let c of[...u.attributes])o.setAttribute(c.name,c.value);o.append(...u.childNodes),u.replaceWith(o)}}},d=(l)=>{let u=document.createElement("template");return u.innerHTML=l,g(u.content),u};return{...e,clone(l){let u=r.get(l);if(!u)r.set(l,u=d(l.html));return u.content.cloneNode(!0)},element:(l)=>n(t.tag(l.toLowerCase()))?h(document,l):e.element(l),attr(l,u,a){e.attr(l,u,a!==null&&n(t.attr(p(l),u,a))?null:a)},html(l,u){n(t.attr(p(l),"@html",u))?e.content(l,""):l.replaceChildren(d(u).content)},styleVar(l,u,a){e.styleVar(l,u,a!==null&&n(t.css(a))?null:a)},listen:(l,u,a)=>e.listen(l,u,(s)=>a(t.event(s)))}}var ot={ir:{v:1,exprs:[],root:{html:"",scope:[],binds:[],blocks:[]}}};function ct(t=P){let e=it(t),r=new Map,n=at(t),p=new Set,h={run(g){let d=r.get(g);if(!d)r.set(g,d=I(g).ast);return(l)=>e(d,l)},self:(g)=>t.self(g)};return{check:K(t),style:(g)=>(d,l)=>{let u=g(d,{...l,lint(c,m){let i=m!==void 0?t.css(m):c[0]==="@"?t.css(c):void 0;return i&&[{...i,severity:"error"}]}}),a=(c,m,i)=>u.diagnostics.push({...c,severity:"error",loc:G(d,Math.max(m,0),i)}),s=!u.diagnostics.some((c)=>c.code.startsWith("LIPS-U"));for(let c of u.ir.exprs){let m=d.indexOf(c);s=W(t,c,j,(i,f,b)=>a(i,m+f,b))&&s}let o=s?t.css(u.ir.css):void 0;if(o&&a(o,0,0),!s||o)return{...u,ir:{...u.ir,css:"",binds:[],props:void 0}};return p.add(u.ir.css),u},runtime(g){let{components:d,createStylesheet:l}=g;return{...g,guard:h,host:n,components:d&&new Proxy(d,{get:(u,a)=>ut(t,a)?ot:u[a]}),createStylesheet:l&&((u,a)=>{if(p.has(a))return l(u,a);return t.report(y("LIPS-U042",`A stylesheet Lips did not compile cannot be checked — <${u}> ships unstyled`,"Send the stylesheet source; precompiled sheets are trusted output")),{clear(){}}})}}}}var ut=(t,e)=>{let r=typeof e==="string"?t.component(e):void 0;return r&&t.report(r),!!r};export{K as checkTemplate,ct as untrusted,P as untrustedPolicy};
4
4
 
5
- //# debugId=DD4429B74F5A6C4F64756E2164756E21
5
+ //# debugId=86138909CC04E89F64756E2164756E21