@lipsjs/lips 0.1.1 → 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 (70) hide show
  1. package/README.md +185 -85
  2. package/dist/lips.js +6274 -0
  3. package/dist/lips.js.map +53 -0
  4. package/dist/lips.min.js +13 -2
  5. package/dist/lips.min.js.map +47 -43
  6. package/dist/mf2.min.js +4 -0
  7. package/dist/mf2.min.js.map +38 -0
  8. package/dist/precompile.min.js +23 -0
  9. package/dist/precompile.min.js.map +14 -0
  10. package/dist/runtime.min.js +5 -0
  11. package/dist/runtime.min.js.map +20 -0
  12. package/dist/stylis.min.js +3 -0
  13. package/dist/stylis.min.js.map +16 -0
  14. package/dist/types/events.d.ts +1 -1
  15. package/dist/types/i18n/engine.d.ts +14 -0
  16. package/dist/types/i18n/index.d.ts +122 -5
  17. package/dist/types/i18n/intl.d.ts +1 -0
  18. package/dist/types/i18n/lookup.d.ts +22 -0
  19. package/dist/types/ir/compiler.d.ts +226 -0
  20. package/dist/types/ir/expression.d.ts +149 -0
  21. package/dist/types/ir/facade.d.ts +138 -0
  22. package/dist/types/ir/host.d.ts +75 -0
  23. package/dist/types/ir/index.d.ts +18 -0
  24. package/dist/types/ir/parser.d.ts +124 -0
  25. package/dist/types/ir/policy.d.ts +95 -0
  26. package/dist/types/ir/router.d.ts +47 -0
  27. package/dist/types/ir/runtime.d.ts +130 -0
  28. package/dist/types/ir/signal.d.ts +28 -0
  29. package/dist/types/ir/style.d.ts +119 -0
  30. package/dist/types/ir/swap.d.ts +28 -0
  31. package/dist/types/ir/tree.d.ts +51 -0
  32. package/dist/types/lips.d.ts +33 -37
  33. package/dist/types/lynx/a11y.d.ts +61 -0
  34. package/dist/types/lynx/background.d.ts +71 -0
  35. package/dist/types/lynx/main.d.ts +46 -0
  36. package/dist/types/lynx/protocol.d.ts +52 -0
  37. package/dist/types/lynx/style.d.ts +49 -0
  38. package/dist/types/lynx/template.d.ts +37 -0
  39. package/dist/types/mf2.d.ts +14 -0
  40. package/dist/types/precompile.d.ts +85 -0
  41. package/dist/types/runtime.d.ts +16 -0
  42. package/dist/types/stylesheet.d.ts +21 -41
  43. package/dist/types/stylis.d.ts +2 -0
  44. package/dist/types/types.d.ts +176 -185
  45. package/dist/types/untrusted.d.ts +17 -0
  46. package/dist/untrusted.min.js +5 -0
  47. package/dist/untrusted.min.js.map +13 -0
  48. package/package.json +46 -10
  49. package/dist/test.component.min.js +0 -3
  50. package/dist/test.component.min.js.map +0 -50
  51. package/dist/test.stress.min.js +0 -476
  52. package/dist/test.stress.min.js.map +0 -50
  53. package/dist/types/component.d.ts +0 -107
  54. package/dist/types/constants.d.ts +0 -23
  55. package/dist/types/dws.d.ts +0 -14
  56. package/dist/types/iuc/index.d.ts +0 -25
  57. package/dist/types/iuc/tick.d.ts +0 -38
  58. package/dist/types/iuc.d.ts +0 -25
  59. package/dist/types/metrics.d.ts +0 -50
  60. package/dist/types/preprocess.d.ts +0 -2
  61. package/dist/types/signal.d.ts +0 -30
  62. package/dist/types/syntax/async.d.ts +0 -16
  63. package/dist/types/syntax/for.d.ts +0 -25
  64. package/dist/types/syntax/if.d.ts +0 -14
  65. package/dist/types/syntax/router.d.ts +0 -40
  66. package/dist/types/syntax/switch.d.ts +0 -16
  67. package/dist/types/tick.d.ts +0 -38
  68. package/dist/types/tps.d.ts +0 -11
  69. package/dist/types/uqs.d.ts +0 -37
  70. package/dist/types/utils.d.ts +0 -25
@@ -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;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Phase 2 — hot-swap support (RFC-001 §8)
3
+ *
4
+ * Structural IR comparison by EXPRESSION SOURCE: two compilations
5
+ * of related templates produce different expression-table indices,
6
+ * so equality must resolve every `E` through its own table before
7
+ * comparing. These normalizers produce plain comparable shapes.
8
+ */
9
+ import type { BlockIR, BindIR, ChildIR } from './compiler';
10
+ export interface SwapChange {
11
+ kind: 'skeleton' | 'binds' | 'block';
12
+ /** Block-tree coordinates, e.g. 'root', 'root/2', 'root/2/0' */
13
+ path: string;
14
+ }
15
+ export interface SwapReport {
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[];
22
+ }
23
+ export declare const normBind: (b: BindIR, x: string[]) => any;
24
+ export declare function normChild(c: ChildIR, x: string[]): any;
25
+ export declare const normBlock: (b: BlockIR, x: string[]) => any;
26
+ export declare const sameChild: (a: ChildIR, ax: string[], b: ChildIR, bx: string[]) => boolean;
27
+ export declare const sameBinds: (a: BindIR[], ax: string[], b: BindIR[], bx: string[]) => boolean;
28
+ export declare const sameLets: (a: BlockIR, ax: string[], b: BlockIR, bx: string[]) => boolean;
@@ -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;
@@ -1,38 +1,34 @@
1
- import type { LipsConfig, Template, Metavars } from './types';
2
- import TPS from './tps';
3
- import IUC from './iuc';
4
- import DWS from './dws';
5
- import I18N from './i18n';
6
- import Stylesheet from './stylesheet';
7
- import ComponentClass from './component';
1
+ /**
2
+ * Lips — fast, lightweight, runtime reactive UI framework.
3
+ *
4
+ * Pipeline (no build step required):
5
+ *
6
+ * template string ──parse──▶ AST ──compile──▶ TemplateIR ──render──▶ DOM
7
+ *
8
+ * Updates are fine-grained: a state write notifies only the bindings
9
+ * that read that key. Templates can also be precompiled to IR at build
10
+ * time (see `compileTemplate`) for CSP-safe, parse-free startup.
11
+ */
12
+ import { IRLips, IRFacadeComponent } from './ir/facade';
13
+ import type { Metavars } from './types';
8
14
  export * from './types';
9
- export type Component<MT extends Metavars> = ComponentClass<MT>;
10
- export default class Lips<Context extends Object = {}> {
11
- debug: boolean;
12
- stylesheets: Stylesheet[];
13
- private config?;
14
- private store;
15
- private __root?;
16
- preprocessor: TPS;
17
- i18n: I18N;
18
- watcher: DWS<any>;
19
- IUC: IUC;
20
- private __setLang;
21
- private __getLang;
22
- private __setContext;
23
- private __getContext;
24
- constructor(config?: LipsConfig<Context>);
25
- register<MT extends Metavars>(name: string, template: Template<MT>): this;
26
- unregister(name: string): this;
27
- has(name: string): boolean;
28
- import<MT extends Metavars>(pathname: string): Template<MT>;
29
- render<MT extends Metavars>(name: string, template: Template<MT>, input?: MT['Input']): ComponentClass<MT>;
30
- root<MT extends Metavars>(template: Template<MT>, selector: string): ComponentClass<any>;
31
- setLanguage(lang: string): void;
32
- getLanguage(): string;
33
- setContext(arg: Context | string, value?: any): void;
34
- getContext(): Context;
35
- useContext<P extends Context>(fields: (keyof P)[], fn: (context: P) => void): void;
36
- useTranslator(support: string | string[], fn: (lang: string) => void): void;
37
- dispose(): void;
38
- }
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>;
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>;
@@ -0,0 +1,71 @@
1
+ /**
2
+ * The background-thread host (RFC-006 §4.2).
3
+ *
4
+ * The Lips runtime runs here, against a SHADOW tree: the runtime walks
5
+ * siblings and resolves paths synchronously, and the real elements live
6
+ * on the other thread. Every mutation that the main thread must mirror is
7
+ * recorded as protocol ops (`./protocol`) and sent once per microtask.
8
+ *
9
+ * Only some shadow nodes are REAL — they exist on the main thread:
10
+ *
11
+ * - elements, and the page
12
+ * - text, once it sits under a `text` element (Lynx renders raw text
13
+ * nowhere else)
14
+ *
15
+ * Markers, fragments and stray text never cross. Insert positions skip
16
+ * them, so the main thread sees exactly the real children, in order.
17
+ *
18
+ * const lynxHost = createBackgroundHost( ops => send( ops ) )
19
+ * renderIR( ir, setup, { host: lynxHost.host } ).mount( lynxHost.root )
20
+ */
21
+ import type { Host } from '../ir/host';
22
+ import { type TreeNode } from '../ir/tree';
23
+ import { type Aria, type Words } from './a11y';
24
+ import { type WireEvent } from './protocol';
25
+ export interface LynxNode extends TreeNode {
26
+ parent: LynxNode | null;
27
+ first: LynxNode | null;
28
+ last: LynxNode | null;
29
+ prev: LynxNode | null;
30
+ next: LynxNode | null;
31
+ /** Shared with the main thread; 0 for nodes that never cross */
32
+ id: number;
33
+ /** Exists on the main thread */
34
+ real: boolean;
35
+ /** The real parent the main thread has it under, if any */
36
+ at: LynxNode | null;
37
+ /** `class` and `style` as written — merged with the scope class and variables */
38
+ cls?: string;
39
+ css?: string;
40
+ /** Where its TEXT op's value sits in the unsent batch; the batch it was created in */
41
+ slot?: number;
42
+ batch?: number;
43
+ /** Its ARIA (RFC-006 §4.8), the role its tag implies, its `id`, what was sent for them, what it last announced */
44
+ aria?: Aria;
45
+ role?: string;
46
+ idv?: string;
47
+ sent?: Record<string, unknown>;
48
+ said?: string;
49
+ }
50
+ export interface BackgroundOptions {
51
+ /** Speak a live region's new text: `lynx.accessibilityAnnounce` on the real thread */
52
+ announce?: (text: string) => void;
53
+ /** The spoken words for states and roles (`WORDS`), to translate them */
54
+ words?: Words;
55
+ }
56
+ export interface BackgroundHost {
57
+ host: Host<LynxNode>;
58
+ /** The page: mount the root instance here */
59
+ root: LynxNode;
60
+ /** An element event forwarded by the main thread */
61
+ receive(wire: WireEvent): void;
62
+ /** Send what is pending now instead of at the end of the microtask */
63
+ flush(): void;
64
+ }
65
+ export declare function createBackgroundHost(send: (ops: unknown[]) => void, { announce, words }?: BackgroundOptions): BackgroundHost;
66
+ /**
67
+ * Wire a background host to the real thread bridge. On the background
68
+ * thread `lynx.getCoreContext()` is the endpoint connected to the main
69
+ * thread, both ways.
70
+ */
71
+ export declare function connectBackground(words?: Words): BackgroundHost;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * The main-thread applier (RFC-006 §4.2).
3
+ *
4
+ * Small on purpose: it owns no Lips logic. It receives the background
5
+ * thread's op batches (`./protocol`), applies them through Element PAPI,
6
+ * flushes once per batch, and forwards element events back as data.
7
+ *
8
+ * Only the public, documented API is used (RFC-006 §5): creation,
9
+ * `__InsertElementBefore` / `__AppendElement` / `__RemoveElement`,
10
+ * `__SetAttribute` / `__SetClasses` / `__SetID` / `__AddDataset`,
11
+ * `__SetInlineStyles`, `__AddEventListener` / `__RemoveEventListener`,
12
+ * `__CreateList` with `update-list-info`, `__InvokeUIMethod` and
13
+ * `__FlushElementTree`.
14
+ */
15
+ import { type WireEvent } from './protocol';
16
+ /** An Element PAPI handle — opaque, never read or sent */
17
+ type Ref = object;
18
+ declare global {
19
+ function __GetElementUniqueID(el: Ref): number;
20
+ function __CreateView(pageId: number): Ref;
21
+ function __CreateText(pageId: number): Ref;
22
+ function __CreateImage(pageId: number): Ref;
23
+ function __CreateScrollView(pageId: number): Ref;
24
+ function __CreateElement(tag: string, pageId: number): Ref;
25
+ function __CreateList(pageId: number, componentAtIndex: (list: Ref, listId: number, index: number, opId: number) => number, enqueueComponent: (list: Ref, listId: number, uid: number) => void): Ref;
26
+ function __CreateRawText(text: string): Ref;
27
+ function __AppendElement(parent: Ref, child: Ref): void;
28
+ function __InsertElementBefore(parent: Ref, child: Ref, ref?: Ref): void;
29
+ function __RemoveElement(parent: Ref, child: Ref): void;
30
+ function __SetAttribute(el: Ref, name: string, value: unknown): void;
31
+ function __SetClasses(el: Ref, classes: string | undefined): void;
32
+ function __SetID(el: Ref, id: string | null): void;
33
+ function __AddDataset(el: Ref, key: string, value: unknown): void;
34
+ function __SetInlineStyles(el: Ref, styles: unknown): void;
35
+ function __AddEventListener(el: Ref, name: string, fn: (e: any) => void, options: object): void;
36
+ function __RemoveEventListener(el: Ref, name: string, fn: (e: any) => void, options: object): void;
37
+ function __InvokeUIMethod(el: Ref, method: string, params: object, callback: (result: unknown) => void): void;
38
+ function __FlushElementTree(el?: Ref, options?: object): void;
39
+ }
40
+ export declare function createApplier(page: Ref, forward: (wire: WireEvent) => void): (ops: any[]) => void;
41
+ /**
42
+ * Wire an applier to the real thread bridge. On the main thread
43
+ * `lynx.getJSContext()` is the endpoint connected to the background.
44
+ */
45
+ export declare function connectMain(page: Ref): (ops: any[]) => void;
46
+ export {};
@@ -0,0 +1,52 @@
1
+ /**
2
+ * The change protocol between the two Lynx threads (RFC-006 §4.2).
3
+ *
4
+ * The background thread runs Lips and never touches an element. What it
5
+ * sends is ONE flat array per flush: an opcode followed by a fixed number
6
+ * of operands, repeated. Flat and primitive-only, so the cross-thread copy
7
+ * is as cheap as a message can be, and it serializes to the same thing on
8
+ * every platform. Ids are integers the background allocates; 1 is the page.
9
+ *
10
+ * op operands main thread does
11
+ * CREATE id, tag element of that Lynx tag
12
+ * TEXT id, value raw text
13
+ * INSERT parent, id, ref insert before `ref`, or append when 0
14
+ * REMOVE parent, id detach
15
+ * ATTR id, name, value routed: class / id / data-* / attribute
16
+ * SET_TEXT id, value raw text's value
17
+ * STYLES id, css the whole inline style
18
+ * LISTEN id, name forward that event to the background
19
+ * UNLISTEN id, name stop forwarding it
20
+ * RELEASE id forget the id (the node is gone)
21
+ * INVOKE id, method, params a UI method (`setValue`, `scrollTo`, …),
22
+ * once the batch is flushed
23
+ *
24
+ * A `list` is the exception to "INSERT inserts": Lynx asks for its cells
25
+ * as they scroll into view. The applier keeps each list's order and
26
+ * hands it over as `update-list-info` once per batch.
27
+ */
28
+ export declare const CREATE = 0, TEXT = 1, INSERT = 2, REMOVE = 3, ATTR = 4, SET_TEXT = 5, STYLES = 6, LISTEN = 7, UNLISTEN = 8, RELEASE = 9, INVOKE = 10;
29
+ /** Operand count per opcode, indexed by opcode */
30
+ export declare const ARITY: number[];
31
+ export declare const PAGE_ID = 1;
32
+ /** Cross-thread event names — background → main, and main → background */
33
+ export declare const OPS_EVENT = "lips:ops";
34
+ export declare const DOM_EVENT = "lips:event";
35
+ /** An element event as it crosses to the background: data only, never a ref */
36
+ export interface WireEvent {
37
+ id: number;
38
+ name: string;
39
+ event: {
40
+ type: string;
41
+ detail?: unknown;
42
+ };
43
+ }
44
+ export declare const LYNX_TAG: Record<string, string>;
45
+ /**
46
+ * The class a stylesheet scope stamps on a component's roots — what its
47
+ * `.lips-<nsp>` rules select (RFC-006 §4.4). Attribute selectors never
48
+ * match on Lynx, so the DOM's `rel` cannot be used.
49
+ */
50
+ export declare const scopeClass: (nsp: string) => string;
51
+ /** Template event name → Lynx event name: DOM spellings keep working */
52
+ export declare const LYNX_EVENT: Record<string, string>;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * The style pipeline for the Lynx target (RFC-006 §4.4). Build-time only:
3
+ * Lynx cannot add a stylesheet at runtime (§3.7), so a component sheet is
4
+ * compiled into the bundle's CSS, and the background thread gets only the
5
+ * binds.
6
+ *
7
+ * const { ir, diagnostics } = compileLynxStyle( source, { nsp: 'card', preprocess: stylisPreprocessor })
8
+ * ir.css → the bundle's CSS: flat, scoped by class
9
+ * ir.binds → the background: variables written on the scope roots
10
+ *
11
+ * What changes from the DOM, each because of what the engine does (§3):
12
+ *
13
+ * - **Flat.** Lynx has no CSS nesting, so the sheet always goes through
14
+ * the preprocessor.
15
+ * - **Scoped by class**, `.lips-<nsp>`. Attribute selectors parse but
16
+ * never match (§3.1).
17
+ * - **Full-value binds.** `calc()` works on lengths only (§3.2), so
18
+ * `padding: {x}px` binds a variable that carries the unit (`12px`)
19
+ * instead of multiplying a number back into it. There is no
20
+ * `@property`, so no registrations either.
21
+ * - **Lint.** Whatever parses but does nothing on Lynx is a diagnostic on
22
+ * the source (`LIPS-L…`), not a silent no-op.
23
+ */
24
+ import { type StylePreprocessor, type StyleCompileResult } from '../ir/style';
25
+ export interface LynxStyleOptions {
26
+ /** Scope name: the component's registration name */
27
+ nsp: string;
28
+ /** Flattens the sheet. Required: Lynx has no CSS nesting */
29
+ preprocess: StylePreprocessor;
30
+ /** Global sheet: no scope */
31
+ meta?: boolean;
32
+ }
33
+ /**
34
+ * The page config the pipeline relies on (RFC-006 §4.4). These are PAGE
35
+ * config, `sourceContent.config` in the encoder — as compiler options
36
+ * they do nothing (tested, tier B):
37
+ *
38
+ * - `enableCSSInlineVariables`: variables set inline (the binds) apply
39
+ * - `enableCSSRule`: `@media` applies
40
+ * - `enableCSSInheritance`: `color`, `font-size` and the other text
41
+ * properties inherit, as on the web. Templates are HTML-shaped and
42
+ * sheets are written for the web's cascade.
43
+ */
44
+ export declare const LYNX_PAGE_CONFIG: {
45
+ enableCSSInlineVariables: boolean;
46
+ enableCSSRule: boolean;
47
+ enableCSSInheritance: boolean;
48
+ };
49
+ export declare function compileLynxStyle(source: string, options: LynxStyleOptions): StyleCompileResult;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Templates on Lynx (RFC-006 §4.3): HTML-shaped tags, Lynx's rules.
3
+ *
4
+ * `compileLynxTemplate( src )` is `compileTemplate( src, { target: 'tree' })`
5
+ * plus a pass over the parsed template for what HTML allows and Lynx
6
+ * does not:
7
+ *
8
+ * - Text renders only inside a text element. Where an element's content
9
+ * is inline — text, binds, text-like tags, control flow around them —
10
+ * it is wrapped in ONE `text`, which lays it out as a browser would:
11
+ * `<button>Save {state.n}</button>` just works. Text beside block
12
+ * content is ambiguous (one text? several?), so it is an error to fix
13
+ * (RFC-006 §9.2, decided 2026-10-16).
14
+ * - An HTML tag with no Lynx element is an error, with what to use.
15
+ * - A `list` holds `list-item`s: Lynx renders nothing else in one.
16
+ * - ARIA Lynx cannot read is a warning: the content stays readable, the
17
+ * semantics are lost (RFC-006 §4.8; what it can read, `./a11y`).
18
+ *
19
+ * code what
20
+ * LIPS-L101 HTML tag with no Lynx element
21
+ * LIPS-L102 text beside block content, in an element that is not text
22
+ * LIPS-L103 text at the top level: renders only inside a text element (warning)
23
+ * LIPS-L104 a list child that is not a list-item
24
+ * LIPS-L105 a role with no Lynx equivalent (warning)
25
+ * LIPS-L106 an aria-* attribute with no Lynx equivalent (warning)
26
+ * LIPS-L107 a positive tabindex: Lynx has no focus order (warning)
27
+ *
28
+ * Macro bodies are inlined after this pass, so it does not see them.
29
+ */
30
+ import { type CompileOptions, type CompileResult } from '../ir/compiler';
31
+ import type { TemplateNode, TemplateDiagnostic } from '../ir/parser';
32
+ export declare function lynxVocabulary(src: string): (nodes: TemplateNode[], diagnostics: TemplateDiagnostic[]) => void;
33
+ /**
34
+ * Compile a template for Lynx: the node tree a native host builds from,
35
+ * with the vocabulary adapted and checked.
36
+ */
37
+ export declare const compileLynxTemplate: (src: string, options?: Omit<CompileOptions, "target" | "transform">) => CompileResult;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The MessageFormat 2 engine, for the precompiled-only entry.
3
+ *
4
+ * import Lips from '@lipsjs/lips/runtime'
5
+ * import { messageFormat } from '@lipsjs/lips/i18n'
6
+ *
7
+ * const lips = new Lips({ messageFormat })
8
+ *
9
+ * The full `@lipsjs/lips` build already carries it. `./runtime` does not:
10
+ * an app that never translates should not pay ~7.2 KB gzipped for it.
11
+ */
12
+ export { messageFormat } from './i18n/engine';
13
+ export { parseMessage } from 'messageformat';
14
+ export type { MessageFormatEngine, Message, Dictionary } from './types';