@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
@@ -0,0 +1,75 @@
1
+ /**
2
+ * The host seam (RFC-006 §4.1).
3
+ *
4
+ * The IR runtime never touches a node itself. It creates, places, walks
5
+ * and mutates nodes through a `Host`, so one runtime drives the DOM, an
6
+ * in-memory tree (`./tree`) or a native element API. The node type is
7
+ * the host's own and opaque to the runtime.
8
+ *
9
+ * What a host must provide is what the runtime actually does with
10
+ * nodes, no more:
11
+ *
12
+ * - instantiate a block's skeleton (`clone`), and create the few nodes
13
+ * the runtime adds itself: markers, text runs, unresolved elements
14
+ * - a sibling-linked tree with parents: block instances are ranges
15
+ * between two markers, walked and moved whole (`range`, `insertAfter`)
16
+ * - attributes, text, inline custom properties, listeners
17
+ * - two host decisions: how a stylesheet scope marks an element
18
+ * (`rel` here, a class on Lynx) and whether markup can be parsed
19
+ * (`html` is optional — the `'tree'` compile target rejects `@html`)
20
+ *
21
+ * Stylesheet injection is not here: it already reaches the runtime as
22
+ * `RuntimeOptions.createStylesheet`, supplied by the facade.
23
+ */
24
+ import type { BlockIR } from './compiler';
25
+ export interface Host<N = any> {
26
+ /** A detached container holding a fresh copy of the block's skeleton */
27
+ clone(block: BlockIR): N;
28
+ /** An empty detached container */
29
+ fragment(): N;
30
+ element(tag: string): N;
31
+ text(value: string): N;
32
+ /** An invisible node: block boundaries and control-flow anchors */
33
+ marker(label: string): N;
34
+ /** The child at `index` — skeleton paths are child-index walks */
35
+ child(parent: N, index: number): N;
36
+ next(node: N): N | null;
37
+ /** `first`, its following siblings, up to and including `last` */
38
+ range(first: N, last: N): N[];
39
+ /** Insert `node` before `ref`, or at the end when `ref` is null */
40
+ insert(parent: N, node: N, ref: N | null): void;
41
+ /** Place `nodes`, in order, right after `ref` — nothing when `ref` has no parent */
42
+ insertAfter(ref: N, nodes: N[]): void;
43
+ /**
44
+ * `gone`: the node will never be inserted again — the runtime is
45
+ * destroying it, not moving it. A host may release what it holds for
46
+ * it (the Lynx host frees its ids); the DOM has nothing to free.
47
+ */
48
+ remove(node: N, gone?: boolean): void;
49
+ isElement(node: N): boolean;
50
+ /** In the live tree — what `onAttach` waits for */
51
+ connected(node: N): boolean;
52
+ /** `a` comes before `b` in tree order; false when they share no tree */
53
+ precedes(a: N, b: N): boolean;
54
+ /** A text node's value — the hot path of every text bind */
55
+ setText(node: N, value: string): void;
56
+ /** Replace an element's children with one text run (`@text`, `@format`) */
57
+ content(el: N, value: string): void;
58
+ /** `null` removes the attribute */
59
+ attr(el: N, name: string, value: string | null): void;
60
+ /** Replace the element's children with parsed markup (`@html`) — DOM only */
61
+ html?(el: N, value: string): void;
62
+ /** Set an inline custom property, or remove it when `null` (RFC-004 §8) */
63
+ styleVar(el: N, prop: string, value: string | null): void;
64
+ /** Mark a component root with its stylesheet scope. An inner scope already set wins */
65
+ scope(el: N, nsp: string): void;
66
+ /** Returns the unlisten function */
67
+ listen(el: N, name: string, fn: (event: any) => void): () => void;
68
+ /** Capture focus before a swap moves nodes; the returned function restores it */
69
+ keepFocus?(): () => void;
70
+ }
71
+ /**
72
+ * Today's behaviour, unchanged: skeletons parsed once per block into a
73
+ * `<template>` and cloned per instance, scope stamped as `rel`.
74
+ */
75
+ export declare const domHost: Host<Node>;
@@ -8,8 +8,11 @@ export type { TemplateNode, ElementNode, AttrNode, TemplateDiagnostic, ParseResu
8
8
  export { parseExpression, extractDeps, compileExpression, interpretExpression } from './expression';
9
9
  export type { Expr, ExprEnv, ExprDiagnostic, CompiledExpr } from './expression';
10
10
  export { compileTemplate } from './compiler';
11
- export type { TemplateIR, BlockIR, BindIR, ChildIR, CompInput, CompileResult } from './compiler';
11
+ export type { TemplateIR, BlockIR, NodeIR, BindIR, ChildIR, CompInput, CompileResult, CompileOptions } from './compiler';
12
+ export { compileStyle, setStylePreprocessor, hasStylePreprocessor } from './style';
13
+ export type { StyleIR, StyleBindIR, PropertyIR, StyleCompileOptions, StyleCompileResult } from './style';
12
14
  export { renderIR } from './runtime';
15
+ export type { Host } from './host';
13
16
  export type { IRInstance, IRComponentDef, RuntimeOptions, RenderSetup } from './runtime';
14
17
  export type { SwapReport, SwapChange } from './swap';
15
- export { signal, effect, untrack, reactive } from './signal';
18
+ export { signal, effect, untrack, reactive, batch } from './signal';
@@ -0,0 +1,95 @@
1
+ /**
2
+ * RFC-007 — what a template you did not write may touch.
3
+ *
4
+ * ONE policy decides; three places ask it:
5
+ *
6
+ * checkTemplate compile time — a refusal is a positioned diagnostic,
7
+ * and the refused construct is dropped before it compiles
8
+ * guard runtime, expressions — a second evaluator over the same
9
+ * AST, asking the policy at every name, member and value
10
+ * host runtime, the page — the DOM host with every write to
11
+ * the page held to the same rules (RFC-006 §4.1's seam)
12
+ *
13
+ * Compile time REPORTS, runtime ENFORCES: a precompiled IR, a template
14
+ * object built from data, or a value that only exists at runtime never
15
+ * meets the compiler, so the runtime holds the line on its own.
16
+ *
17
+ * The policy is data plus predicates. Replace it whole, or in part —
18
+ * methods call each other through `this`, so overriding `url` changes
19
+ * what `attr` and `css` accept too:
20
+ *
21
+ * new Lips({ untrusted: { ...untrustedPolicy, url: sameOriginOnly } })
22
+ *
23
+ * It ships as its own entry, `@lipsjs/lips/untrusted`, passed to Lips by
24
+ * value: an app that never renders an untrusted template pays nothing.
25
+ */
26
+ import type { CompileOptions } from './compiler';
27
+ import type { RuntimeOptions } from './runtime';
28
+ import type { StyleCompileOptions, StyleCompileResult } from './style';
29
+ type StyleCompiler = (src: string, options: StyleCompileOptions) => StyleCompileResult;
30
+ export interface Refusal {
31
+ code: string;
32
+ message: string;
33
+ hint?: string;
34
+ }
35
+ /** `undefined` allows */
36
+ export type Verdict = Refusal | undefined;
37
+ export interface TemplatePolicy {
38
+ /** Names an expression may read besides its metavars and its scope */
39
+ globals: Record<string, unknown>;
40
+ /**
41
+ * May an expression reach `key` — read it, call it, or with `write`
42
+ * assign it? `obj` is the value when known: always at runtime, and at
43
+ * compile time when it is one of `globals`.
44
+ */
45
+ member(key: string, write: boolean, obj?: unknown): Verdict;
46
+ /** The same question for the component's own `self`, which has rules of its own */
47
+ self(key: string, write?: boolean): Verdict;
48
+ /** May an expression hold this value — read from data, returned by a call, passed to an arrow? */
49
+ value(v: unknown): Verdict;
50
+ /** What an inline handler receives in place of a DOM event */
51
+ event(e: Event): object;
52
+ /** May the template create this element (lower-case tag)? */
53
+ tag(name: string): Verdict;
54
+ /** May the template render this registered component? */
55
+ component(name: string): Verdict;
56
+ /**
57
+ * May the template set this attribute on `tag`? `value` is undefined
58
+ * when it is not known yet (an expression, at compile time). `@html` is
59
+ * asked under the name '@html'.
60
+ */
61
+ attr(tag: string, name: string, value?: string): Verdict;
62
+ /** May the page load this URL — an href, a src, a CSS url()? */
63
+ url(value: string): Verdict;
64
+ /** May this CSS reach the page — a stylesheet, a style=, a reactive declaration? */
65
+ css(text: string): Verdict;
66
+ /** Runtime refusals outside an expression land here (inside one, they throw into the component's onError) */
67
+ report(refusal: Refusal): void;
68
+ }
69
+ /** What the facade needs, built once per untrusted Lips instance — `untrusted()` makes one */
70
+ export interface Untrusted {
71
+ check: Check;
72
+ /** The style compiler, held to the policy: a sheet with a refusal ships empty */
73
+ style(compile: StyleCompiler): StyleCompiler;
74
+ /** The facade's runtime options, guarded */
75
+ runtime(options: RuntimeOptions): RuntimeOptions;
76
+ }
77
+ type Check = NonNullable<CompileOptions['check']>;
78
+ export declare const untrustedPolicy: TemplatePolicy;
79
+ /**
80
+ * The compile-time half: a `CompileOptions.check` that holds a parsed
81
+ * template (and its macros) to `policy`. Every refusal is reported where
82
+ * it is written; the refused element or attribute is removed, a refused
83
+ * expression becomes `undefined`.
84
+ *
85
+ * compileTemplate( src, { check: checkTemplate( untrustedPolicy ) } )
86
+ */
87
+ export declare function checkTemplate(policy?: TemplatePolicy): Check;
88
+ /**
89
+ * Everything an untrusted Lips instance runs with:
90
+ *
91
+ * new Lips({ untrusted: untrusted() })
92
+ * new Lips({ untrusted: untrusted({ ...untrustedPolicy, url: sameOriginOnly }) })
93
+ */
94
+ export declare function untrusted(policy?: TemplatePolicy): Untrusted;
95
+ export {};
@@ -1,16 +1,18 @@
1
1
  /**
2
2
  * Phase 2 — IR runtime (RFC-001 §6, §8)
3
3
  *
4
- * TemplateIR → live DOM:
5
- * - skeletons parsed ONCE per block into <template>, instantiated
6
- * per use via content.cloneNode(true) + a bind walk over
4
+ * TemplateIR → live nodes, through a `Host` (RFC-006 §4.1; the DOM
5
+ * unless told otherwise):
6
+ * - skeletons instantiated per use by the host (on the DOM: parsed
7
+ * ONCE per block into <template>, then cloned) + a bind walk over
7
8
  * precomputed integer paths
8
9
  * - every bind is its own effect over per-key signals — updates are
9
10
  * O(changed bindings), no digest, no clones, no deep equality
10
11
  * - block instances are bracketed by owned comment markers so
11
12
  * control-flow content moves/disposes as a range
12
- * - dual expression modes over the same IR: 'compiled' (Function,
13
- * trusted) / 'interpreted' (sandboxed AST walker, CSP-safe)
13
+ * - dual expression modes over the same IR: 'compiled' (Function) /
14
+ * 'interpreted' (AST walker, CSP-safe) — both for trusted templates;
15
+ * an untrusted one runs through a `guard` instead (RFC-007)
14
16
  *
15
17
  * Hot-swap (§8): instances retain their structure (bind handles,
16
18
  * child handles, resolved path nodes) so `instance.swap( newIR )`
@@ -21,15 +23,18 @@
21
23
  * State lives outside the IR, so it survives by construction.
22
24
  */
23
25
  import type { TemplateIR } from './compiler';
26
+ import type { ExprEnv } from './expression';
24
27
  import type { SwapReport } from './swap';
28
+ import type { StyleIR } from './style';
29
+ import type { Host } from './host';
25
30
  export interface IRComponentDef {
26
31
  ir: TemplateIR;
27
32
  state?: Record<string, any>;
28
33
  statics?: Record<string, any>;
29
34
  /** Context fields this component subscribes to (fires onContext) */
30
35
  context?: string[];
31
- /** Scoped stylesheet source + scope name (the `rel` value) */
32
- stylesheet?: string;
36
+ /** Compiled stylesheet (RFC-004) + scope name (the `rel` value) */
37
+ stylesheet?: StyleIR;
33
38
  nsp?: string;
34
39
  /** Deep-reactive component state (old-engine parity) */
35
40
  deep?: boolean;
@@ -40,11 +45,27 @@ export interface IRComponentDef {
40
45
  */
41
46
  handlers?: Record<string, (this: any, ...args: any[]) => any>;
42
47
  }
48
+ /**
49
+ * How an untrusted template's expressions run (RFC-007): `run` replaces
50
+ * the executor, and `self` decides which members of the component a bare
51
+ * handler name in an event instruction may reach. Built by `./policy`.
52
+ */
53
+ export interface Guard {
54
+ run(src: string): (env: ExprEnv) => any;
55
+ /** A refusal (truthy) keeps the instruction off `self[ key ]` */
56
+ self(key: string): unknown;
57
+ }
43
58
  export interface RuntimeOptions {
44
59
  mode?: 'compiled' | 'interpreted';
60
+ /** Untrusted templates only — set by `new Lips({ untrusted })` */
61
+ guard?: Guard;
62
+ /**
63
+ * What the IR renders into (RFC-006 §4.1). Defaults to the DOM. A host
64
+ * that builds nodes one by one (`treeHost` in `./tree`) needs IR compiled
65
+ * with `{ target: 'tree' }`, which carries the node tree it builds from.
66
+ */
67
+ host?: Host;
45
68
  components?: Record<string, IRComponentDef>;
46
- /** Host-provided context subscription (returns an unsubscribe) */
47
- watchContext?(fields: string[], fn: () => void): () => void;
48
69
  /**
49
70
  * Resolve a plain template object (e.g. a route's `template`)
50
71
  * into a component definition — the host owns compilation and
@@ -62,12 +83,20 @@ export interface RuntimeOptions {
62
83
  clear(): void;
63
84
  };
64
85
  /**
65
- * i18n plugin hook (RFC §6): both calls must READ a language
66
- * signal so translated binds re-run on language change.
86
+ * i18n plugin hook (RFC §6). Every call must READ a language signal
87
+ * so translated binds re-run on language change — including `lang()`,
88
+ * which is what makes `<span text=self.lang>` live.
89
+ *
90
+ * `key` is a STABLE translation id (RFC-005 §3): given one, the
91
+ * dictionary is consulted for it first and `text` is only the
92
+ * fallback wording. `lang` overrides the active language for one
93
+ * call — how `<i18n lang=…>` translates its subtree.
67
94
  */
68
95
  i18n?: {
69
- translate(text: string): string;
70
- format(reference: string, params: any): string;
96
+ translate(text: string, key?: string, lang?: string): string;
97
+ format(reference: string, params: any, lang?: string): string;
98
+ /** Active language, read reactively */
99
+ lang(): string;
71
100
  };
72
101
  }
73
102
  export interface RenderSetup {
@@ -80,16 +109,22 @@ export interface RenderSetup {
80
109
  deep?: boolean;
81
110
  /** Extra members merged onto self before handlers bind (e.g. emit) */
82
111
  expose?: Record<string, any>;
83
- /** Scoped stylesheet source + scope name (the `rel` value) */
84
- stylesheet?: string;
112
+ /** Compiled stylesheet (RFC-004) + scope name (the `rel` value) */
113
+ stylesheet?: StyleIR;
85
114
  nsp?: string;
86
115
  }
87
- export interface IRInstance {
116
+ /** `N` is the host's node type — `Node` on the DOM */
117
+ export interface IRInstance<N = Node> {
88
118
  state: Record<string, any>;
89
119
  self: Record<string, any>;
90
- nodes: Node[];
91
- mount(container: Element): void;
120
+ nodes: N[];
121
+ mount(container: N): void;
92
122
  swap(newIR: TemplateIR): SwapReport;
93
123
  dispose(): void;
94
124
  }
95
- export declare function renderIR(ir: TemplateIR, setup?: RenderSetup, options?: RuntimeOptions): IRInstance;
125
+ /**
126
+ * Marks a component `self`. A guard needs to tell it apart from data: the
127
+ * policy has its own rules for members of `self` (RFC-007 §5.2).
128
+ */
129
+ export declare const SELF: unique symbol;
130
+ export declare function renderIR<T = Node>(ir: TemplateIR, setup?: RenderSetup, options?: RuntimeOptions): IRInstance<T>;
@@ -5,6 +5,7 @@
5
5
  * `historySignal` wrapper, later), no deep proxies, no digest.
6
6
  * A write notifies exactly the effects that read that signal.
7
7
  */
8
+ export declare function batch<T>(fn: () => T): T;
8
9
  export declare function signal<T>(value: T): [() => T, (next: T) => void, () => void];
9
10
  export interface EffectHandle {
10
11
  dispose(): void;
@@ -18,9 +19,10 @@ export declare function untrack<T>(fn: () => T): T;
18
19
  * writing notifies only that key's subscribers.
19
20
  * Idempotent — wrapping a reactive object returns it as-is.
20
21
  *
21
- * Shallow by default (RFC §6). `deep: true` opts into nested
22
- * mutation tracking: plain objects/arrays read through a key are
23
- * lazily proxied, and any nested write force-notifies that top
24
- * key's subscribers (coarse but O(subscribers-of-key)).
22
+ * Shallow by default (RFC-001 §6). `deep: true` opts into nested
23
+ * mutation tracking: plain objects/arrays read through a key are lazily
24
+ * given their OWN per-key channels (see `nestedProxy`), so a nested
25
+ * write stays O(subscribers-of-that-key) rather than invalidating the
26
+ * whole top-level key.
25
27
  */
26
28
  export declare function reactive<T extends object>(obj: T, deep?: boolean): T;
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Style IR (RFC-004 Layer 1) — reactive declarations for component stylesheets.
3
+ *
4
+ * stylesheet source
5
+ * │ scanner — lifts {expr} out of declaration VALUES only, hoists the
6
+ * │ at-rules that cannot nest, compacts the text
7
+ * ▼
8
+ * scope wrap `[rel="x"]{…}` — resolved by native CSS nesting, or
9
+ * flattened by an opt-in preprocessor (`@lipsjs/lips/stylis`)
10
+ * ▼
11
+ * StyleIR ──────────► JSON (precompiled module)
12
+ * │
13
+ * ▼
14
+ * runtime: inject `css` verbatim, bind each custom property on the scope roots
15
+ *
16
+ * The sheet is IMMUTABLE once injected. Updates write custom properties on the
17
+ * component's own roots — one shared rule, N per-instance values. Rule-level
18
+ * revision (insert/delete) is Layer 2 and deliberately absent here.
19
+ *
20
+ * Like the template compiler, the CSS preprocessor is INJECTED rather than
21
+ * imported, so the precompiled-only `./runtime` build tree-shakes Stylis out.
22
+ */
23
+ import type { TemplateDiagnostic } from './parser';
24
+ export interface StyleBindIR {
25
+ /** Custom property to write on the scope roots (e.g. '--card-0') */
26
+ prop: string;
27
+ /** Index into StyleIR.exprs */
28
+ e: number;
29
+ /**
30
+ * Unit appended to the value when it is written: a full-value bind, for
31
+ * engines whose `calc()` cannot multiply a number back into it (Lynx,
32
+ * RFC-006 §3.2)
33
+ */
34
+ u?: string;
35
+ }
36
+ export interface PropertyIR {
37
+ name: string;
38
+ syntax: string;
39
+ inherits: boolean;
40
+ initial: string;
41
+ }
42
+ export interface StyleIR {
43
+ v: 1;
44
+ /**
45
+ * Scope name baked in at compile time. The runtime stamps `rel` with
46
+ * THIS, not the registration name — a precompiled sheet is already
47
+ * scoped to it, and the two must agree.
48
+ */
49
+ nsp: string;
50
+ /** Scoped and compact — nested, or flat if a preprocessor ran. Injected verbatim, never re-parsed. */
51
+ css: string;
52
+ exprs: string[];
53
+ binds: StyleBindIR[];
54
+ /** @property registrations — makes the variables interpolable (RFC-004 §10) */
55
+ props?: PropertyIR[];
56
+ }
57
+ export interface StyleCompileOptions {
58
+ /** Scope name — the `rel` attribute value, and the variable-name prefix */
59
+ nsp: string;
60
+ /** Inject globally instead of scoping to `[rel="<nsp>"]` */
61
+ meta?: boolean;
62
+ /** Emit inside `@layer <name>` so utility frameworks can win (RFC-004 §9) */
63
+ layer?: string;
64
+ /**
65
+ * CSS preprocessor for this call, overriding any process-wide one.
66
+ *
67
+ * Passed per call rather than only set globally because the opt-in
68
+ * preprocessor ships as a SEPARATE bundle: `@lipsjs/lips/stylis` and
69
+ * `@lipsjs/lips` each carry their own copy of this module, so a global
70
+ * set from one is invisible to the other. Handing the function across
71
+ * the call is the only wiring that survives that boundary.
72
+ */
73
+ preprocess?: StylePreprocessor;
74
+ /**
75
+ * The scope wrap's selector, for a host that does not scope by `rel`
76
+ * (Lynx scopes by class, RFC-006 §4.4). Default `[rel="<nsp>"]`.
77
+ */
78
+ scope?: string;
79
+ /**
80
+ * What the target cannot do, reported on the source. Passed per call,
81
+ * like the preprocessor, so a target's rules — and their bytes — stay
82
+ * out of the DOM bundles.
83
+ */
84
+ lint?: StyleLint;
85
+ }
86
+ /**
87
+ * Called on every selector (`text`), at-rule prelude (`text` starting
88
+ * with `@`) and declaration (`text` the property, plus its `value`).
89
+ * Returns its diagnostics; the compiler adds where it is in the source.
90
+ */
91
+ export type StyleLint = (text: string, value?: string) => Omit<TemplateDiagnostic, 'loc'>[] | undefined;
92
+ export interface StyleCompileResult {
93
+ ir: StyleIR;
94
+ diagnostics: TemplateDiagnostic[];
95
+ }
96
+ export type StylePreprocessor = (css: string) => string;
97
+ /**
98
+ * Process-wide default preprocessor, `null` to clear it. Only reaches
99
+ * `compileStyle` in the SAME module graph — each published entry bundles
100
+ * its own copy of this module — so outside of tests and source builds,
101
+ * pass `preprocess` per call (`LipsConfig.stylePreprocessor`,
102
+ * `precompile(…, { preprocess })`) instead.
103
+ */
104
+ export declare function setStylePreprocessor(fn: StylePreprocessor | null): void;
105
+ export declare function hasStylePreprocessor(): boolean;
106
+ export declare function locOf(src: string, offset: number, length: number): {
107
+ line: number;
108
+ col: number;
109
+ offset: number;
110
+ length: number;
111
+ };
112
+ /**
113
+ * Compile a component stylesheet to StyleIR.
114
+ *
115
+ * The scanner MUST run before any preprocessor: a brace in a declaration
116
+ * value breaks Stylis's block parsing, so interpolations are replaced
117
+ * with `var()` first.
118
+ */
119
+ export declare function compileStyle(src: string, options: StyleCompileOptions): StyleCompileResult;
@@ -14,6 +14,11 @@ export interface SwapChange {
14
14
  }
15
15
  export interface SwapReport {
16
16
  changes: SwapChange[];
17
+ /**
18
+ * Components carried through the swap instead of being remounted —
19
+ * one entry per instance, by component name.
20
+ */
21
+ salvaged: string[];
17
22
  }
18
23
  export declare const normBind: (b: BindIR, x: string[]) => any;
19
24
  export declare function normChild(c: ChildIR, x: string[]): any;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * An in-memory host (RFC-006 §4.1): the IR runtime over plain objects,
3
+ * with no DOM anywhere.
4
+ *
5
+ * What it is for:
6
+ * - proving the seam: the host spec renders the same IR through this
7
+ * and through the DOM and requires identical trees
8
+ * - the shape a native binding starts from: a background-thread Lynx
9
+ * host keeps exactly this kind of shadow tree, because the runtime
10
+ * walks siblings synchronously and the real elements live on another
11
+ * thread
12
+ * - rendering where there is no document (tests, servers)
13
+ *
14
+ * Skeletons are built from `BlockIR.nodes`, so the IR must be compiled
15
+ * with `{ target: 'tree' }`.
16
+ *
17
+ * const root = treeRoot()
18
+ * renderIR( compileTemplate( src, { target: 'tree' } ).ir, setup, { host: treeHost } ).mount( root )
19
+ */
20
+ import type { Host } from './host';
21
+ export interface TreeNode {
22
+ /** Element tag, or '#text' | '#marker' | '#fragment' | '#root' */
23
+ type: string;
24
+ /** A text run's value, a marker's label */
25
+ value: string;
26
+ attrs: Record<string, string>;
27
+ /** Inline custom properties (RFC-004 §8) */
28
+ vars: Record<string, string>;
29
+ /** The stylesheet scope `Host.scope` assigned — recorded, not styled */
30
+ scope?: string;
31
+ listeners: Record<string, Set<(event: any) => void>>;
32
+ parent: TreeNode | null;
33
+ first: TreeNode | null;
34
+ last: TreeNode | null;
35
+ prev: TreeNode | null;
36
+ next: TreeNode | null;
37
+ }
38
+ /** A fresh, unattached node — also the base of the Lynx background host's nodes */
39
+ export declare const treeNode: (type: string, value?: string) => TreeNode;
40
+ export declare function unlink(n: TreeNode): void;
41
+ /** DOM `insertBefore`: the node leaves wherever it was first */
42
+ export declare function link(parent: TreeNode, n: TreeNode, ref: TreeNode | null): void;
43
+ export declare const treeHost: Host<TreeNode>;
44
+ /** A live root to mount into: what is under it counts as connected */
45
+ export declare const treeRoot: () => TreeNode;
46
+ export declare function childrenOf(n: TreeNode): TreeNode[];
47
+ /**
48
+ * Fire an element's own listeners — what a tap would do. No bubbling:
49
+ * the runtime attaches every listener to the element that declares it.
50
+ */
51
+ export declare function dispatch(el: TreeNode, name: string, event?: any): void;
@@ -10,8 +10,25 @@
10
10
  * time (see `compileTemplate`) for CSP-safe, parse-free startup.
11
11
  */
12
12
  import { IRLips, IRFacadeComponent } from './ir/facade';
13
+ import type { Metavars } from './types';
13
14
  export * from './types';
14
- export { parseTemplate, parseSFC, compileTemplate, renderIR, signal, effect, untrack, reactive } from './ir';
15
- export type { TemplateIR, BlockIR, BindIR, ChildIR, CompileResult, TemplateDiagnostic, IRInstance, IRComponentDef, RuntimeOptions, RenderSetup, SwapReport, SwapChange } from './ir';
16
- export type Component = IRFacadeComponent;
15
+ export type { TemplatePolicy, Refusal, Verdict, Untrusted } from './ir/policy';
16
+ export { parseTemplate, parseSFC, compileTemplate, compileStyle, renderIR, signal, effect, untrack, reactive, batch } from './ir';
17
+ export type { TemplateIR, BlockIR, NodeIR, CompileOptions, Host, BindIR, ChildIR, CompileResult, StyleIR, StyleBindIR, StyleCompileResult, TemplateDiagnostic, IRInstance, IRComponentDef, RuntimeOptions, RenderSetup, SwapReport, SwapChange } from './ir';
18
+ /**
19
+ * A rendered component handle. Generic over the same `Metavars` the
20
+ * template declares, so `component.state` is typed, not `any`:
21
+ *
22
+ * type MT = Metavars<{ tone: string }, { count: number }>
23
+ * const c: Component<MT> = lips.render<MT>('counter', counter)
24
+ * c.state.count++ // number
25
+ *
26
+ * Its event bus runs both ways — `c.on('saved', …)` receives what the
27
+ * component emits, and `c.emit('reset')` reaches listeners the component
28
+ * registered with `this.on(…)`. Inbound events do NOT invoke handler
29
+ * methods by name, so what a component accepts stays explicit.
30
+ */
31
+ export type Component<MT extends Metavars = Metavars> = IRFacadeComponent<MT>;
32
+ /** The Lips instance, generic over the shared context shape */
33
+ export type Lips<Context extends Object = Record<string, any>> = IRLips<Context>;
17
34
  export default IRLips;
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Accessibility on Lynx (RFC-006 §4.8): a template's ARIA, read as Lynx's
3
+ * own accessibility attributes (verified in §3.8).
4
+ *
5
+ * The background host keeps each element's ARIA and, once per flush,
6
+ * sends what it comes to:
7
+ *
8
+ * ARIA Lynx
9
+ * role (and button, a, h1–h6) accessibility-traits, -element, -heading, -role-description
10
+ * aria-label, alt, aria-labelledby, accessibility-label: ids and <label for> resolved to
11
+ * <label for>, aria-describedby their text here, and kept current
12
+ * aria-checked, -selected, -expanded, accessibility-value: words, the same on every platform
13
+ * -pressed, -current, -disabled,
14
+ * -invalid, -required, -valuetext/now
15
+ * aria-hidden accessibility-elements-hidden
16
+ * aria-modal accessibility-exclusive-focus
17
+ * aria-live, role=status|log|alert lynx.accessibilityAnnounce of the region's text
18
+ * tabindex focusable
19
+ *
20
+ * What has no Lynx equivalent is a compile-time warning (`./template`).
21
+ */
22
+ /** Spoken words: the states, and the role descriptions Android speaks as given. Replace them to translate */
23
+ export declare const WORDS: {
24
+ checked: string;
25
+ unchecked: string;
26
+ mixed: string;
27
+ pressed: string;
28
+ selected: string;
29
+ expanded: string;
30
+ collapsed: string;
31
+ current: string;
32
+ disabled: string;
33
+ invalid: string;
34
+ required: string;
35
+ radio: string;
36
+ tab: string;
37
+ };
38
+ export type Words = Record<keyof typeof WORDS, string>;
39
+ /**
40
+ * A role → its trait, and Android's role description. `checkbox`,
41
+ * `switch` and `progressbar` are Android class names, not words: Android
42
+ * speaks them in the user's language. Android and HarmonyOS take one
43
+ * trait, of `button`, `image` and `text`; the others reach iOS only.
44
+ */
45
+ export declare const ROLES: Record<string, [string, string?]>;
46
+ /** Regions whose changes are announced */
47
+ export declare const LIVE: Record<string, string>;
48
+ export declare const QUIET: Set<string>;
49
+ /** The roles HTML tags carry: what Lynx's `view` and `text` lose */
50
+ export declare const IMPLICIT: Record<string, string>;
51
+ /** The attributes the host reads instead of sending */
52
+ export declare const A11Y: Set<string>;
53
+ export type Aria = Record<string, string>;
54
+ /** ARIA takes the first token of a role list it knows; Lynx knows one */
55
+ export declare const roleOf: (a: Aria, implicit?: string) => string;
56
+ /**
57
+ * The Lynx attributes one element's ARIA comes to; `undefined` resets one.
58
+ * `refs( ids )` is the text of those ids, `content()` the element's own,
59
+ * `labelled` the text of a `<label for>` it.
60
+ */
61
+ export declare function lynxA11y(a: Aria, role: string, isText: boolean, refs: (ids: string) => string, content: () => string, labelled: string, words: Words): Record<string, unknown>;