@lipsjs/lips 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +68 -1
  2. package/dist/lips.js +3532 -1094
  3. package/dist/lips.js.map +44 -19
  4. package/dist/lips.min.js +13 -9
  5. package/dist/lips.min.js.map +44 -19
  6. package/dist/lynx.min.js +51 -0
  7. package/dist/lynx.min.js.map +17 -0
  8. package/dist/mf2.min.js +4 -0
  9. package/dist/mf2.min.js.map +38 -0
  10. package/dist/precompile.min.js +19 -16
  11. package/dist/precompile.min.js.map +7 -6
  12. package/dist/runtime.min.js +4 -3
  13. package/dist/runtime.min.js.map +13 -12
  14. package/dist/stylis.min.js +3 -0
  15. package/dist/stylis.min.js.map +16 -0
  16. package/dist/types/i18n/engine.d.ts +14 -0
  17. package/dist/types/i18n/index.d.ts +122 -5
  18. package/dist/types/i18n/intl.d.ts +1 -0
  19. package/dist/types/i18n/lookup.d.ts +22 -0
  20. package/dist/types/ir/compiler.d.ts +75 -2
  21. package/dist/types/ir/expression.d.ts +32 -3
  22. package/dist/types/ir/facade.d.ts +74 -30
  23. package/dist/types/ir/host.d.ts +75 -0
  24. package/dist/types/ir/index.d.ts +5 -2
  25. package/dist/types/ir/policy.d.ts +95 -0
  26. package/dist/types/ir/runtime.d.ts +54 -19
  27. package/dist/types/ir/signal.d.ts +6 -4
  28. package/dist/types/ir/style.d.ts +119 -0
  29. package/dist/types/ir/swap.d.ts +5 -0
  30. package/dist/types/ir/tree.d.ts +51 -0
  31. package/dist/types/lips.d.ts +20 -3
  32. package/dist/types/lynx/a11y.d.ts +61 -0
  33. package/dist/types/lynx/background.d.ts +71 -0
  34. package/dist/types/lynx/main.d.ts +46 -0
  35. package/dist/types/lynx/protocol.d.ts +52 -0
  36. package/dist/types/lynx/style.d.ts +49 -0
  37. package/dist/types/lynx/template.d.ts +37 -0
  38. package/dist/types/lynx.d.ts +22 -0
  39. package/dist/types/mf2.d.ts +14 -0
  40. package/dist/types/precompile.d.ts +30 -5
  41. package/dist/types/runtime.d.ts +1 -1
  42. package/dist/types/stylesheet.d.ts +12 -16
  43. package/dist/types/stylis.d.ts +2 -0
  44. package/dist/types/types.d.ts +138 -11
  45. package/dist/types/untrusted.d.ts +17 -0
  46. package/dist/untrusted.min.js +5 -0
  47. package/dist/untrusted.min.js.map +13 -0
  48. package/package.json +25 -3
@@ -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,22 @@
1
+ /**
2
+ * The Lynx pass (RFC-006), an entry of its own for a build step: what
3
+ * holds a template and a stylesheet to what Lynx can draw, the same pass
4
+ * Lips's own Lynx build runs.
5
+ *
6
+ * import { compileLynxTemplate, compileLynxStyle } from '@lipsjs/lips/lynx'
7
+ * import { stylisPreprocessor } from '@lipsjs/lips/stylis'
8
+ *
9
+ * const { diagnostics } = compileLynxTemplate( source )
10
+ * const sheet = compileLynxStyle( css, { nsp: 'app', preprocess: stylisPreprocessor })
11
+ *
12
+ * `compileLynxTemplate` compiles a template for the `'tree'` target with
13
+ * the HTML-shaped vocabulary mapped onto Lynx's elements, and reports what
14
+ * Lynx cannot draw (`LIPS-L1xx`) and the ARIA it cannot read; `lynxVocabulary`
15
+ * is that vocabulary pass on its own. `compileLynxStyle` compiles a sheet
16
+ * for Lynx and lints it against what Lynx's CSS admits (`LIPS-L0xx`).
17
+ *
18
+ * Build-time only, like `./precompile`: the Lynx hosts that run on the
19
+ * main thread and the background thread are not part of it.
20
+ */
21
+ export { compileLynxTemplate, lynxVocabulary } from './lynx/template';
22
+ export { compileLynxStyle, LYNX_PAGE_CONFIG, type LynxStyleOptions } from './lynx/style';
@@ -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';
@@ -13,32 +13,57 @@
13
13
  * The IR is plain JSON, so it can be emitted into a bundle, shipped
14
14
  * from a server, or stored as a Modela artifact.
15
15
  */
16
- import type { TemplateIR } from './ir/compiler';
16
+ import type { TemplateIR, CompileOptions } from './ir/compiler';
17
+ import type { StyleIR, StylePreprocessor } from './ir/style';
17
18
  import type { TemplateDiagnostic } from './ir/parser';
18
19
  export interface PrecompiledTemplate {
19
20
  ir: TemplateIR;
21
+ /** Compiled stylesheet — replaces `stylesheet` source (RFC-004) */
22
+ style?: StyleIR;
20
23
  state?: Record<string, any>;
21
24
  _static?: Record<string, any>;
22
25
  context?: string[];
23
26
  handler?: Record<string, (...args: any[]) => any>;
24
- stylesheet?: string;
27
+ }
28
+ export interface PrecompileOptions {
29
+ /**
30
+ * Scope name for the stylesheet — baked into the StyleIR, so it must
31
+ * match how the component is registered. Defaults to `'lips'`.
32
+ */
33
+ name?: string;
34
+ /**
35
+ * CSS preprocessor for the stylesheet, e.g. `stylisPreprocessor` from
36
+ * `@lipsjs/lips/stylis`. Absent, the sheet is baked nested and native
37
+ * CSS nesting resolves it. Passed here, not set globally: this entry
38
+ * and `@lipsjs/lips/stylis` are separate bundles with separate state.
39
+ */
40
+ preprocess?: StylePreprocessor;
41
+ /** The kind of host the IR is for — see `CompileOptions.target` */
42
+ target?: CompileOptions['target'];
25
43
  }
26
44
  export interface PrecompileResult {
27
45
  template: PrecompiledTemplate;
28
46
  diagnostics: TemplateDiagnostic[];
29
47
  }
30
48
  /**
31
- * Precompile one authoring template. Macros are inlined at this
32
- * point, so the `macros` source does not ship to the client.
49
+ * Precompile one authoring template. Macros are inlined at this point,
50
+ * so the `macros` source does not ship to the client — and the stylesheet
51
+ * is compiled to StyleIR, so the `./runtime` build needs no CSS
52
+ * preprocessor either (RFC-004 §1).
33
53
  */
34
- export declare function precompile(template: Record<string, any>): PrecompileResult;
54
+ export declare function precompile(template: Record<string, any>, options?: PrecompileOptions): PrecompileResult;
35
55
  /** Serialize an IR for embedding in generated source */
36
56
  export declare const serializeIR: (ir: TemplateIR) => string;
57
+ export declare const serializeStyleIR: (ir: StyleIR) => string;
37
58
  export interface PluginOptions {
38
59
  /** Files to transform (default: `.lips` single-file components) */
39
60
  include?: RegExp;
40
61
  /** Emit diagnostics as build warnings (default true) */
41
62
  reportDiagnostics?: boolean;
63
+ /** CSS preprocessor for lifted stylesheets — see `PrecompileOptions.preprocess` */
64
+ preprocess?: StylePreprocessor;
65
+ /** The kind of host the IR is for — see `CompileOptions.target` */
66
+ target?: CompileOptions['target'];
42
67
  }
43
68
  /**
44
69
  * Vite/Rollup plugin: compiles `.lips` single-file components into a
@@ -12,5 +12,5 @@ import { IRLips } from './ir/facade';
12
12
  export * from './types';
13
13
  export { renderIR } from './ir/runtime';
14
14
  export { signal, effect, untrack, reactive } from './ir/signal';
15
- export type { TemplateIR, IRInstance, RuntimeOptions, RenderSetup, SwapReport } from './ir';
15
+ export type { TemplateIR, IRInstance, RuntimeOptions, RenderSetup, SwapReport, Host } from './ir';
16
16
  export default IRLips;
@@ -1,35 +1,31 @@
1
1
  /**
2
- * Component stylesheets — scoped by a `rel` attribute selector,
3
- * injected once per namespace and reference counted so shared
4
- * components clean up correctly. Native DOM only (no cash-dom).
2
+ * Component stylesheets — injected once per namespace and reference
3
+ * counted so shared components clean up correctly. Native DOM only.
5
4
  *
6
- * The CSS preprocessor (Stylis) is INJECTED, not imported, so the
7
- * precompiled-only `./runtime` build tree-shakes it out entirely.
8
- * The full `@lipsjs/lips` entry wires it (see src/lips.ts); a build
9
- * without it warns and skips source stylesheets rather than shipping
10
- * a preprocessor a precompiled/CSP app never needs.
5
+ * Compilation lives in `ir/style.ts` and happens at COMPILE time: what
6
+ * arrives here is final, scoped, compact CSS (StyleIR.css). That
7
+ * is what lets the precompiled-only `./runtime` build ship styles with
8
+ * no CSS preprocessor at all — see RFC-004 §1.
11
9
  */
12
10
  export type StyleSettings = {
11
+ /** Final CSS — already scoped and preprocessed */
13
12
  sheet?: string;
14
- /** Inject globally instead of scoping to `[rel="<nsp>"]` */
13
+ /** Marks a globally-injected sheet (prepended, so authors can override) */
15
14
  meta?: boolean;
16
15
  };
17
- type StyleCompiler = (css: string) => string;
18
- /** Wire the CSS preprocessor (full build only) */
19
- export declare function setStyleCompiler(fn: StyleCompiler): void;
20
16
  export default class Stylesheet {
21
17
  private nsp;
22
18
  private settings;
23
19
  constructor(nsp: string, settings?: StyleSettings);
24
20
  private get rel();
21
+ /** Quoted, so a name can only ever select its own `<style>` */
25
22
  private get styleElement();
26
23
  /**
27
- * Compile and inject. `dindex` counts live instances sharing this
28
- * namespace: it increases per instance and decreases on clear, so
29
- * the element is removed only by the last one out.
24
+ * Inject. `dindex` counts live instances sharing this namespace: it
25
+ * increases per instance and decreases on clear, so the element is
26
+ * removed only by the last one out.
30
27
  */
31
28
  load(settings: StyleSettings): HTMLStyleElement | undefined;
32
29
  /** Release this instance's reference; removes the element at zero */
33
30
  clear(): void;
34
31
  }
35
- export {};
@@ -0,0 +1,2 @@
1
+ /** Hand this to `new Lips({ stylePreprocessor })` or `precompile(…, { preprocess })` */
2
+ export declare const stylisPreprocessor: (css: string) => string;
@@ -5,8 +5,24 @@
5
5
  * always taken, and the serializable artifact a generator can emit:
6
6
  *
7
7
  * { default, state, handler, _static, context, macros, stylesheet }
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.
12
+ */
13
+ import type { MessageFormat, Model } from 'messageformat';
14
+ import type { MessageFunction } from 'messageformat/functions';
15
+ import type { TemplateIR } from './ir/compiler';
16
+ import type { StyleIR } from './ir/style';
17
+ import type { Untrusted } from './ir/policy';
18
+ /**
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.
8
24
  */
9
- export interface Metavars<Input extends Object = {}, State extends Object = {}, Static extends Object = {}, Context extends Object = {}> {
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>> {
10
26
  Input: Input;
11
27
  State: State;
12
28
  Static: Static;
@@ -22,10 +38,28 @@ export interface ComponentSelf<MT extends Metavars = Metavars> {
22
38
  input: MT['Input'];
23
39
  context: MT['Context'];
24
40
  static: MT['Static'];
41
+ /** Live root elements of this component */
42
+ readonly node: Element[];
43
+ /**
44
+ * Active language, read reactively — a bind that reads it re-renders
45
+ * on `setLanguage()`. Component-grained: a component under
46
+ * `<i18n lang=…>` reports the scoped language, but an `<i18n>` block
47
+ * inside this component's own template does not change it (RFC-005 §2).
48
+ */
49
+ readonly lang: string;
50
+ /** Switches the language for the whole app — the single writer */
51
+ setLanguage(lang: string): void;
52
+ /** Reaches both this component's own listeners and external ones */
25
53
  emit(event: string, ...args: any[]): void;
54
+ /**
55
+ * Also the inbound channel: a listener registered here receives
56
+ * `component.emit(…)` calls made by whoever holds the handle.
57
+ */
26
58
  on(event: string, fn: (...args: any[]) => void): ComponentSelf<MT>;
27
- off(event: string): ComponentSelf<MT>;
59
+ once(event: string, fn: (...args: any[]) => void): ComponentSelf<MT>;
60
+ off(event: string, fn?: (...args: any[]) => void): ComponentSelf<MT>;
28
61
  setContext(arg: string | Record<string, any>, value?: any): void;
62
+ /** Sibling handlers, reachable as `this.otherMethod()` */
29
63
  [key: string]: any;
30
64
  }
31
65
  export interface LifecycleEvents<MT extends Metavars> {
@@ -46,30 +80,123 @@ export type Handler<MT extends Metavars> = Partial<LifecycleEvents<MT>> & {
46
80
  export type Template<MT extends Metavars = Metavars> = {
47
81
  /** Template source — the component's markup */
48
82
  default?: string;
83
+ /** Precompiled template IR — used instead of `default` (see `precompile`) */
84
+ ir?: TemplateIR;
49
85
  state?: MT['State'];
86
+ /**
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`.
92
+ */
93
+ static?: MT['Static'];
50
94
  _static?: MT['Static'];
51
- /** Context fields this component subscribes to (drives onContext) */
95
+ /**
96
+ * Context fields whose change fires this component's `onContext`.
97
+ *
98
+ * It does NOT declare what the component reads: bindings that read
99
+ * `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.
102
+ */
103
+ watchContext?: string[];
104
+ /** @deprecated Renamed to `watchContext` — same meaning (RFC-005 §4.3) */
52
105
  context?: string[];
53
106
  /** `<macro [argv] name="X">…</macro>` definitions, inlined at compile time */
54
107
  macros?: string;
55
108
  handler?: Handler<MT>;
109
+ /** Scoped CSS — declaration values may be `{expr}` (RFC-004) */
56
110
  stylesheet?: string;
111
+ /** Precompiled StyleIR — used instead of `stylesheet` (see `precompile`) */
112
+ style?: StyleIR;
57
113
  };
58
114
  export type LipsConfig<Context extends Object = {}> = {
59
115
  debug?: boolean;
60
116
  context?: Context;
117
+ /** Reserved for engine selection; the IR engine is the only one shipped */
118
+ engine?: string;
61
119
  /**
62
- * Expression execution:
120
+ * Initial i18n language, e.g. 'fr-FR'. Defaults to `navigator.language`,
121
+ * falling back to 'en-US' where there is no navigator (SSR, workers).
122
+ * Set it when the language comes from the app — a user preference, a
123
+ * URL segment, a server-rendered locale — rather than from the browser.
124
+ * Change it later with `lips.setLanguage()`.
125
+ */
126
+ lang?: string;
127
+ /**
128
+ * Emit component sheets inside `@layer <name>` (RFC-004 §9). Absent by
129
+ * default, and absent output is byte-identical to no layer at all —
130
+ * only utility-framework users (Tailwind) need this, because unlayered
131
+ * styles beat layered ones regardless of specificity.
132
+ */
133
+ styleLayer?: string;
134
+ /**
135
+ * CSS preprocessor for component stylesheets. Absent, the sheet ships
136
+ * nested and the browser's own CSS nesting resolves the scope wrap —
137
+ * Chrome/Edge 112+, Safari 16.5+, Firefox 117+ — 1.9 KB gzipped
138
+ * lighter. Older engines drop a nested sheet whole.
139
+ *
140
+ * import { stylisPreprocessor } from '@lipsjs/lips/stylis'
141
+ * new Lips({ stylePreprocessor: stylisPreprocessor })
142
+ *
143
+ * Wire it to flatten for pre-nesting engines, or pass a preprocessor
144
+ * of your own: it receives the scoped sheet, comments kept, with the
145
+ * at-rules that cannot nest already hoisted. `@import`, `@charset` and
146
+ * `@namespace` are placed ahead of its output as written. It is passed
147
+ * here rather than imported for its side effect because the two
148
+ * entries are separate bundles with separate module state.
149
+ */
150
+ stylePreprocessor?: (css: string) => string;
151
+ /**
152
+ * The MessageFormat 2 engine dictionaries are formatted with. The full
153
+ * build wires it in; the precompiled `./runtime` entry ships without it
154
+ * (~7.2 KB gzipped), so an app that translates passes it:
155
+ *
156
+ * import { messageFormat } from '@lipsjs/lips/i18n'
157
+ * new Lips({ messageFormat })
158
+ *
159
+ * Without one, registering a dictionary is refused rather than read
160
+ * some other way. Passed by value for the same reason as
161
+ * `stylePreprocessor`: the entries are separate bundles.
162
+ */
163
+ messageFormat?: MessageFormatEngine;
164
+ /**
165
+ * Expression execution, for templates you trust:
63
166
  * - 'compiled' (default) — one cached Function per expression
64
- * - 'interpreted' — sandboxed AST walker, required under a CSP
65
- * without `unsafe-eval`
167
+ * - 'interpreted' — an AST walker that never builds a Function, for a
168
+ * CSP without `unsafe-eval`. CSP-safe, NOT a sandbox: a template run
169
+ * this way can still reach anything it can name a path to.
66
170
  */
67
171
  mode?: 'compiled' | 'interpreted';
172
+ /**
173
+ * Every template this instance renders is one you did not write
174
+ * (RFC-007). It reaches only the data and functions it is handed, the
175
+ * globals the policy offers, and its own subtree through the template
176
+ * language; refusals are diagnostics.
177
+ *
178
+ * import { untrusted, untrustedPolicy } from '@lipsjs/lips/untrusted'
179
+ * new Lips({ untrusted: untrusted() })
180
+ * new Lips({ untrusted: untrusted({ ...untrustedPolicy, url: sameOriginOnly }) })
181
+ *
182
+ * Passed by value, like `messageFormat`: an app that never renders an
183
+ * untrusted template ships none of it. Runs interpreted — `mode:
184
+ * 'compiled'` is refused. On `./runtime` templates must be precompiled;
185
+ * their skeletons are checked when first used.
186
+ */
187
+ untrusted?: Untrusted;
68
188
  };
69
189
  export type EventListener = (...args: any[]) => void;
70
- export type I18nVariant = Record<string, string>;
71
- export type I18nFormat = {
72
- type: string;
73
- value: string | I18nVariant | Record<string, string | I18nVariant>;
190
+ /**
191
+ * A Unicode MessageFormat 2 message: its source, or its data model as JSON
192
+ * (what `parseMessage` makes of it, and what a server that parsed it once
193
+ * serves).
194
+ */
195
+ export type Message = string | Model.Message;
196
+ /** `messageformat`'s formatter and the functions a message may call — what `@lipsjs/lips/i18n` exports as `messageFormat`. */
197
+ export type MessageFormatEngine = {
198
+ MessageFormat: typeof MessageFormat;
199
+ functions: Record<string, MessageFunction<any, any>>;
74
200
  };
75
- export type Dictionary = Record<string, string | I18nFormat | I18nVariant>;
201
+ /** One language's messages, by stable key or by source text. */
202
+ export type Dictionary = Record<string, Message>;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Untrusted templates (RFC-007) — an entry of its own, passed to Lips by
3
+ * value so an app that never renders one ships none of it:
4
+ *
5
+ * import Lips from '@lipsjs/lips'
6
+ * import { untrusted, untrustedPolicy } from '@lipsjs/lips/untrusted'
7
+ *
8
+ * const embed = new Lips({ untrusted: untrusted() })
9
+ * const strict = new Lips({ untrusted: untrusted({ ...untrustedPolicy, url: sameOriginOnly }) })
10
+ *
11
+ * `checkTemplate( policy )` is the compile-time half on its own, for a
12
+ * build step or a generator that wants the diagnostics:
13
+ *
14
+ * compileTemplate( src, { check: checkTemplate( untrustedPolicy ) } )
15
+ */
16
+ export { untrusted, untrustedPolicy, checkTemplate } from './ir/policy';
17
+ export type { TemplatePolicy, Refusal, Verdict, Untrusted } from './ir/policy';