@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.
- package/README.md +185 -85
- package/dist/lips.js +6274 -0
- package/dist/lips.js.map +53 -0
- package/dist/lips.min.js +13 -2
- package/dist/lips.min.js.map +47 -43
- package/dist/mf2.min.js +4 -0
- package/dist/mf2.min.js.map +38 -0
- package/dist/precompile.min.js +23 -0
- package/dist/precompile.min.js.map +14 -0
- package/dist/runtime.min.js +5 -0
- package/dist/runtime.min.js.map +20 -0
- package/dist/stylis.min.js +3 -0
- package/dist/stylis.min.js.map +16 -0
- package/dist/types/events.d.ts +1 -1
- package/dist/types/i18n/engine.d.ts +14 -0
- package/dist/types/i18n/index.d.ts +122 -5
- package/dist/types/i18n/intl.d.ts +1 -0
- package/dist/types/i18n/lookup.d.ts +22 -0
- package/dist/types/ir/compiler.d.ts +226 -0
- package/dist/types/ir/expression.d.ts +149 -0
- package/dist/types/ir/facade.d.ts +138 -0
- package/dist/types/ir/host.d.ts +75 -0
- package/dist/types/ir/index.d.ts +18 -0
- package/dist/types/ir/parser.d.ts +124 -0
- package/dist/types/ir/policy.d.ts +95 -0
- package/dist/types/ir/router.d.ts +47 -0
- package/dist/types/ir/runtime.d.ts +130 -0
- package/dist/types/ir/signal.d.ts +28 -0
- package/dist/types/ir/style.d.ts +119 -0
- package/dist/types/ir/swap.d.ts +28 -0
- package/dist/types/ir/tree.d.ts +51 -0
- package/dist/types/lips.d.ts +33 -37
- package/dist/types/lynx/a11y.d.ts +61 -0
- package/dist/types/lynx/background.d.ts +71 -0
- package/dist/types/lynx/main.d.ts +46 -0
- package/dist/types/lynx/protocol.d.ts +52 -0
- package/dist/types/lynx/style.d.ts +49 -0
- package/dist/types/lynx/template.d.ts +37 -0
- package/dist/types/mf2.d.ts +14 -0
- package/dist/types/precompile.d.ts +85 -0
- package/dist/types/runtime.d.ts +16 -0
- package/dist/types/stylesheet.d.ts +21 -41
- package/dist/types/stylis.d.ts +2 -0
- package/dist/types/types.d.ts +176 -185
- package/dist/types/untrusted.d.ts +17 -0
- package/dist/untrusted.min.js +5 -0
- package/dist/untrusted.min.js.map +13 -0
- package/package.json +46 -10
- package/dist/test.component.min.js +0 -3
- package/dist/test.component.min.js.map +0 -50
- package/dist/test.stress.min.js +0 -476
- package/dist/test.stress.min.js.map +0 -50
- package/dist/types/component.d.ts +0 -107
- package/dist/types/constants.d.ts +0 -23
- package/dist/types/dws.d.ts +0 -14
- package/dist/types/iuc/index.d.ts +0 -25
- package/dist/types/iuc/tick.d.ts +0 -38
- package/dist/types/iuc.d.ts +0 -25
- package/dist/types/metrics.d.ts +0 -50
- package/dist/types/preprocess.d.ts +0 -2
- package/dist/types/signal.d.ts +0 -30
- package/dist/types/syntax/async.d.ts +0 -16
- package/dist/types/syntax/for.d.ts +0 -25
- package/dist/types/syntax/if.d.ts +0 -14
- package/dist/types/syntax/router.d.ts +0 -40
- package/dist/types/syntax/switch.d.ts +0 -16
- package/dist/types/tick.d.ts +0 -38
- package/dist/types/tps.d.ts +0 -11
- package/dist/types/uqs.d.ts +0 -37
- package/dist/types/utils.d.ts +0 -25
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase 2 — engine facade (RFC-001 §9)
|
|
3
|
+
*
|
|
4
|
+
* The old public Lips API backed by the IR engine, activated via
|
|
5
|
+
* `new Lips({ engine: 'ir' })`. Templates are the same plain
|
|
6
|
+
* objects ({ default, state, handler, _static, stylesheet, … });
|
|
7
|
+
* behind the API: parse → IR → renderIR with deep-reactive state.
|
|
8
|
+
*
|
|
9
|
+
* Parity gaps this facade does not yet cover (tracked in ROADMAP):
|
|
10
|
+
* router, i18n, macros, component contents/slots + events,
|
|
11
|
+
* declaration-driven syntax components.
|
|
12
|
+
*/
|
|
13
|
+
import type { TemplateIR, CompileResult, CompileOptions } from './compiler';
|
|
14
|
+
/**
|
|
15
|
+
* The template compiler is INJECTED, not imported, so a
|
|
16
|
+
* precompiled-only build can tree-shake the parser and compiler out
|
|
17
|
+
* entirely (see src/runtime.ts vs src/lips.ts).
|
|
18
|
+
*/
|
|
19
|
+
type CompilerFn = (src: string, options?: CompileOptions) => CompileResult;
|
|
20
|
+
export declare function setCompiler(fn: CompilerFn): void;
|
|
21
|
+
/**
|
|
22
|
+
* The style compiler is INJECTED for the same reason the template one is:
|
|
23
|
+
* a static import would pull the CSS scanner (and Stylis behind it) into
|
|
24
|
+
* the `./runtime` bundle, which exists precisely to ship neither.
|
|
25
|
+
*/
|
|
26
|
+
type StyleCompilerFn = (src: string, options: StyleCompileOptions) => StyleCompileResult;
|
|
27
|
+
export declare function setStyleCompiler(fn: StyleCompilerFn): void;
|
|
28
|
+
export declare function setMessageFormat(engine: MessageFormatEngine): void;
|
|
29
|
+
export declare function registerBuiltin(name: string, template: any): void;
|
|
30
|
+
import type { RuntimeOptions } from './runtime';
|
|
31
|
+
import Events from '../events';
|
|
32
|
+
import type { StyleIR, StyleCompileResult, StyleCompileOptions } from './style';
|
|
33
|
+
import type { Template, Metavars, LipsConfig, MessageFormatEngine } from '../types';
|
|
34
|
+
import I18N from '../i18n';
|
|
35
|
+
/**
|
|
36
|
+
* The authoring shape IS the public `Template<MT>` — one type, not a
|
|
37
|
+
* parallel internal one. `FacadeTemplate` remains as the erased form
|
|
38
|
+
* used where the metavars are not known (caches, dynamic resolution).
|
|
39
|
+
*/
|
|
40
|
+
type FacadeTemplate = Template<any>;
|
|
41
|
+
type FacadeConfig<Context extends Object = Record<string, any>> = LipsConfig<Context> & {
|
|
42
|
+
mode?: 'compiled' | 'interpreted';
|
|
43
|
+
};
|
|
44
|
+
export declare class IRFacadeComponent<MT extends Metavars = Metavars> extends Events {
|
|
45
|
+
private lips;
|
|
46
|
+
private template;
|
|
47
|
+
readonly state: MT['State'];
|
|
48
|
+
private instance;
|
|
49
|
+
private contextWatcher?;
|
|
50
|
+
private destroyed;
|
|
51
|
+
constructor(lips: IRLips<any>, name: string, template: Template<MT>, input: MT['Input'] | undefined, ir: TemplateIR, options: RuntimeOptions);
|
|
52
|
+
/**
|
|
53
|
+
* The component bus is bidirectional.
|
|
54
|
+
*
|
|
55
|
+
* Outward has always worked: a handler's `this.emit('save')` reaches
|
|
56
|
+
* `component.on('save')`. Inward is this override — `component.emit(
|
|
57
|
+
* 'reset')` also reaches `this.on('reset')` registered inside the
|
|
58
|
+
* component, so a holder of the handle can send a command without
|
|
59
|
+
* mutating state or reaching into internals.
|
|
60
|
+
*
|
|
61
|
+
* Argument handling matches what an internal emit already does:
|
|
62
|
+
* inward is raw (the caller owns the data), outward is deep-cleaned by
|
|
63
|
+
* `Events` so reactive proxies never escape the component.
|
|
64
|
+
*/
|
|
65
|
+
emit(event: string, ...args: any[]): void;
|
|
66
|
+
/**
|
|
67
|
+
* Live root ELEMENTS — matching `this.node` inside a handler. The
|
|
68
|
+
* instance's node list also carries the block's range markers, which
|
|
69
|
+
* are an internal detail no consumer should have to filter out.
|
|
70
|
+
*/
|
|
71
|
+
get node(): Element[];
|
|
72
|
+
appendTo(selector: string | Element): this;
|
|
73
|
+
swap(newIR: TemplateIR): import("./swap").SwapReport;
|
|
74
|
+
destroy(): void;
|
|
75
|
+
}
|
|
76
|
+
export declare class IRLips<Context extends Object = Record<string, any>> {
|
|
77
|
+
private config?;
|
|
78
|
+
debug: boolean;
|
|
79
|
+
private store;
|
|
80
|
+
private irCache;
|
|
81
|
+
private defCache;
|
|
82
|
+
private styleCache;
|
|
83
|
+
private context;
|
|
84
|
+
private __root?;
|
|
85
|
+
/**
|
|
86
|
+
* `new Lips({ untrusted: untrusted() })` — every template this instance
|
|
87
|
+
* renders is held to it (RFC-007). Passed by value from
|
|
88
|
+
* `@lipsjs/lips/untrusted`, so only an app that renders untrusted
|
|
89
|
+
* templates ships the policy.
|
|
90
|
+
*/
|
|
91
|
+
private u?;
|
|
92
|
+
i18n: I18N;
|
|
93
|
+
/** Language signal — translated binds subscribe through it */
|
|
94
|
+
private getLang;
|
|
95
|
+
private setLang;
|
|
96
|
+
/** Dictionary revision — bumped whenever a dictionary is registered */
|
|
97
|
+
private getRev;
|
|
98
|
+
/**
|
|
99
|
+
* Registered components resolved lazily — the runtime looks
|
|
100
|
+
* names up per render, so registration order doesn't matter.
|
|
101
|
+
*/
|
|
102
|
+
private componentsProxy;
|
|
103
|
+
constructor(config?: FacadeConfig<Context> | undefined);
|
|
104
|
+
register<MT extends Metavars = Metavars>(name: string, template: Template<MT>): this;
|
|
105
|
+
unregister(name: string): this;
|
|
106
|
+
has(name: string): boolean;
|
|
107
|
+
private compile;
|
|
108
|
+
/**
|
|
109
|
+
* Compile `stylesheet` source to StyleIR, or take a precompiled `style`
|
|
110
|
+
* as-is. Cached per template object like the template IR — the sheet is
|
|
111
|
+
* per component type, so this runs once no matter how many instances.
|
|
112
|
+
*/
|
|
113
|
+
styleFor(name: string, template: FacadeTemplate): StyleIR | undefined;
|
|
114
|
+
private defFor;
|
|
115
|
+
render<MT extends Metavars = Metavars>(name: string, template: Template<MT>, input?: MT['Input']): IRFacadeComponent<MT>;
|
|
116
|
+
root<MT extends Metavars = Metavars>(template: Template<MT>, selector: string): IRFacadeComponent<any>;
|
|
117
|
+
/**
|
|
118
|
+
* The only way to change language. Writing `lips.i18n.lang` directly
|
|
119
|
+
* updates the dictionary lookup but not the signal, so nothing already
|
|
120
|
+
* rendered re-translates.
|
|
121
|
+
*/
|
|
122
|
+
setLanguage(lang: string): this;
|
|
123
|
+
getLanguage(): string;
|
|
124
|
+
useTranslator(support: string | string[], fn: (lang: string) => void): () => void;
|
|
125
|
+
/** Reactive store, indexed dynamically — Context only types the surface */
|
|
126
|
+
private get ctx();
|
|
127
|
+
getContext(): Context;
|
|
128
|
+
setContext(arg: (keyof Context & string) | Partial<Context>, value?: any): void;
|
|
129
|
+
/**
|
|
130
|
+
* Subscribe to a subset of context fields — the effect tracks
|
|
131
|
+
* exactly those keys, so unrelated context writes don't fire it.
|
|
132
|
+
* Returns an unsubscribe function.
|
|
133
|
+
*/
|
|
134
|
+
watchContext(fields: (keyof Context & string)[] | string[], fn: () => void): () => void;
|
|
135
|
+
useContext(fields: string[], fn: (ctx: Partial<Context>) => void): () => void;
|
|
136
|
+
dispose(): void;
|
|
137
|
+
}
|
|
138
|
+
export {};
|
|
@@ -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>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase 2 IR engine — public surface
|
|
3
|
+
*
|
|
4
|
+
* template string ──parse──▶ AST ──compile──▶ TemplateIR ──render──▶ live DOM
|
|
5
|
+
*/
|
|
6
|
+
export { parseTemplate, parseSFC } from './parser';
|
|
7
|
+
export type { TemplateNode, ElementNode, AttrNode, TemplateDiagnostic, ParseResult, SFCResult } from './parser';
|
|
8
|
+
export { parseExpression, extractDeps, compileExpression, interpretExpression } from './expression';
|
|
9
|
+
export type { Expr, ExprEnv, ExprDiagnostic, CompiledExpr } from './expression';
|
|
10
|
+
export { compileTemplate } 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';
|
|
14
|
+
export { renderIR } from './runtime';
|
|
15
|
+
export type { Host } from './host';
|
|
16
|
+
export type { IRInstance, IRComponentDef, RuntimeOptions, RenderSetup } from './runtime';
|
|
17
|
+
export type { SwapReport, SwapChange } from './swap';
|
|
18
|
+
export { signal, effect, untrack, reactive, batch } from './signal';
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase 2 — Template parser (RFC-001 §3–4)
|
|
3
|
+
*
|
|
4
|
+
* A dedicated recursive-descent parser for Lips templates:
|
|
5
|
+
* - owns the syntax (no innerHTML, no regex preprocessing) — immune to
|
|
6
|
+
* table-context hoisting, host-parser attribute lenience, whitespace
|
|
7
|
+
* corruption
|
|
8
|
+
* - positioned machine-readable diagnostics with error recovery
|
|
9
|
+
* (`parse` never throws; broken templates yield partial ASTs)
|
|
10
|
+
* - accepts the `.lips` SFC layout (frontscript + template) per
|
|
11
|
+
* RFC-001 decision #5
|
|
12
|
+
*
|
|
13
|
+
* Attribute value semantics (predictable, no heuristics):
|
|
14
|
+
* - `name="text"` → literal string
|
|
15
|
+
* - `name="a {expr} b"` → interpolated parts
|
|
16
|
+
* - `name=expr` → expression (whitespace-free, depth-aware)
|
|
17
|
+
* - `name={ expr }` → expression (braced — spaces allowed)
|
|
18
|
+
* - `name` / `!name` → boolean true / false
|
|
19
|
+
* - `on-click( … )` → event instruction
|
|
20
|
+
* - `await( … )` etc. → callable (fn) attribute
|
|
21
|
+
* - `[a, b]` → iterator argument names
|
|
22
|
+
* - `...expr` → spread
|
|
23
|
+
*/
|
|
24
|
+
export interface Loc {
|
|
25
|
+
offset: number;
|
|
26
|
+
length: number;
|
|
27
|
+
}
|
|
28
|
+
export interface TemplateDiagnostic {
|
|
29
|
+
code: string;
|
|
30
|
+
severity: 'error' | 'warning';
|
|
31
|
+
message: string;
|
|
32
|
+
hint?: string;
|
|
33
|
+
loc: {
|
|
34
|
+
line: number;
|
|
35
|
+
col: number;
|
|
36
|
+
offset: number;
|
|
37
|
+
length: number;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export type ExprSlot = {
|
|
41
|
+
expr: string;
|
|
42
|
+
loc: Loc;
|
|
43
|
+
};
|
|
44
|
+
export type TemplateNode = ElementNode | FragmentNode | {
|
|
45
|
+
t: 'text';
|
|
46
|
+
value: string;
|
|
47
|
+
loc: Loc;
|
|
48
|
+
} | {
|
|
49
|
+
t: 'interp';
|
|
50
|
+
parts: (string | ExprSlot)[];
|
|
51
|
+
loc: Loc;
|
|
52
|
+
} | {
|
|
53
|
+
t: 'comment';
|
|
54
|
+
value: string;
|
|
55
|
+
loc: Loc;
|
|
56
|
+
};
|
|
57
|
+
export interface FragmentNode {
|
|
58
|
+
t: 'fragment';
|
|
59
|
+
children: TemplateNode[];
|
|
60
|
+
loc: Loc;
|
|
61
|
+
}
|
|
62
|
+
export interface ElementNode {
|
|
63
|
+
t: 'element';
|
|
64
|
+
tag: string;
|
|
65
|
+
dynamicTag?: ExprSlot;
|
|
66
|
+
head?: ExprSlot;
|
|
67
|
+
attrs: AttrNode[];
|
|
68
|
+
children: TemplateNode[];
|
|
69
|
+
selfClosed: boolean;
|
|
70
|
+
loc: Loc;
|
|
71
|
+
}
|
|
72
|
+
export type AttrNode = {
|
|
73
|
+
k: 'literal';
|
|
74
|
+
name: string;
|
|
75
|
+
value: string;
|
|
76
|
+
loc: Loc;
|
|
77
|
+
} | {
|
|
78
|
+
k: 'interp';
|
|
79
|
+
name: string;
|
|
80
|
+
parts: (string | ExprSlot)[];
|
|
81
|
+
loc: Loc;
|
|
82
|
+
} | {
|
|
83
|
+
k: 'expr';
|
|
84
|
+
name: string;
|
|
85
|
+
source: string;
|
|
86
|
+
loc: Loc;
|
|
87
|
+
} | {
|
|
88
|
+
k: 'bool';
|
|
89
|
+
name: string;
|
|
90
|
+
value: boolean;
|
|
91
|
+
loc: Loc;
|
|
92
|
+
} | {
|
|
93
|
+
k: 'event';
|
|
94
|
+
name: string;
|
|
95
|
+
source: string;
|
|
96
|
+
loc: Loc;
|
|
97
|
+
} | {
|
|
98
|
+
k: 'fn';
|
|
99
|
+
name: string;
|
|
100
|
+
source: string;
|
|
101
|
+
loc: Loc;
|
|
102
|
+
} | {
|
|
103
|
+
k: 'args';
|
|
104
|
+
names: string[];
|
|
105
|
+
loc: Loc;
|
|
106
|
+
} | {
|
|
107
|
+
k: 'spread';
|
|
108
|
+
source: string;
|
|
109
|
+
loc: Loc;
|
|
110
|
+
};
|
|
111
|
+
export interface ParseResult {
|
|
112
|
+
root: FragmentNode;
|
|
113
|
+
diagnostics: TemplateDiagnostic[];
|
|
114
|
+
}
|
|
115
|
+
export interface SFCResult extends ParseResult {
|
|
116
|
+
script: string;
|
|
117
|
+
}
|
|
118
|
+
export declare function parseTemplate(src: string): ParseResult;
|
|
119
|
+
/**
|
|
120
|
+
* `.lips` single-file component: frontscript (JS/TS) followed by the
|
|
121
|
+
* template. The template starts at the first line-leading `<` that sits
|
|
122
|
+
* at top-level script depth (outside strings, comments, and brackets).
|
|
123
|
+
*/
|
|
124
|
+
export declare function parseSFC(src: string): SFCResult;
|
|
@@ -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 {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase 2 — `<router>` for the IR engine.
|
|
3
|
+
*
|
|
4
|
+
* Implemented as an ordinary component (no engine privileges): its
|
|
5
|
+
* template is a dynamic tag holding the matched page's template
|
|
6
|
+
* object, resolved by the host's `resolveTemplate` hook.
|
|
7
|
+
*
|
|
8
|
+
* <router routes=static.routes global
|
|
9
|
+
* on-before(…) on-after(…) on-not-found(…)></router>
|
|
10
|
+
*/
|
|
11
|
+
type RouteDef = {
|
|
12
|
+
path: string;
|
|
13
|
+
template: any;
|
|
14
|
+
default?: boolean;
|
|
15
|
+
};
|
|
16
|
+
type Route = RouteDef & {
|
|
17
|
+
pathVars: string[];
|
|
18
|
+
pathRegex: RegExp;
|
|
19
|
+
};
|
|
20
|
+
export declare const routerTemplate: {
|
|
21
|
+
state: {
|
|
22
|
+
page: any;
|
|
23
|
+
params: Record<string, any>;
|
|
24
|
+
query: Record<string, any>;
|
|
25
|
+
};
|
|
26
|
+
handler: {
|
|
27
|
+
onCreate(this: any): void;
|
|
28
|
+
onInput(this: any): void;
|
|
29
|
+
processor(this: any, options: {
|
|
30
|
+
routes?: RouteDef[];
|
|
31
|
+
global?: boolean;
|
|
32
|
+
}): void;
|
|
33
|
+
onAttach(this: any): void;
|
|
34
|
+
navigate(this: any, path: string, back?: boolean): void;
|
|
35
|
+
match(this: any, path: string): false | {
|
|
36
|
+
route: Route;
|
|
37
|
+
params: Record<string, any>;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
default: string;
|
|
41
|
+
};
|
|
42
|
+
declare global {
|
|
43
|
+
interface Window {
|
|
44
|
+
navigate: (path: string, back?: boolean) => void;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase 2 — IR runtime (RFC-001 §6, §8)
|
|
3
|
+
*
|
|
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
|
|
8
|
+
* precomputed integer paths
|
|
9
|
+
* - every bind is its own effect over per-key signals — updates are
|
|
10
|
+
* O(changed bindings), no digest, no clones, no deep equality
|
|
11
|
+
* - block instances are bracketed by owned comment markers so
|
|
12
|
+
* control-flow content moves/disposes as a range
|
|
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)
|
|
16
|
+
*
|
|
17
|
+
* Hot-swap (§8): instances retain their structure (bind handles,
|
|
18
|
+
* child handles, resolved path nodes) so `instance.swap( newIR )`
|
|
19
|
+
* can diff old vs new by expression source and update surgically:
|
|
20
|
+
* - identical subtrees → kept wholesale (zero DOM work)
|
|
21
|
+
* - bind-only changes → effects rewired onto the SAME nodes
|
|
22
|
+
* - skeleton changes → that block re-rendered in place
|
|
23
|
+
* State lives outside the IR, so it survives by construction.
|
|
24
|
+
*/
|
|
25
|
+
import type { TemplateIR } from './compiler';
|
|
26
|
+
import type { ExprEnv } from './expression';
|
|
27
|
+
import type { SwapReport } from './swap';
|
|
28
|
+
import type { StyleIR } from './style';
|
|
29
|
+
import type { Host } from './host';
|
|
30
|
+
export interface IRComponentDef {
|
|
31
|
+
ir: TemplateIR;
|
|
32
|
+
state?: Record<string, any>;
|
|
33
|
+
statics?: Record<string, any>;
|
|
34
|
+
/** Context fields this component subscribes to (fires onContext) */
|
|
35
|
+
context?: string[];
|
|
36
|
+
/** Compiled stylesheet (RFC-004) + scope name (the `rel` value) */
|
|
37
|
+
stylesheet?: StyleIR;
|
|
38
|
+
nsp?: string;
|
|
39
|
+
/** Deep-reactive component state (old-engine parity) */
|
|
40
|
+
deep?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Methods bound to the component self — lifecycle keys
|
|
43
|
+
* (onCreate/onInput/onMount/onDestroy) are invoked by the
|
|
44
|
+
* runtime at the matching moments.
|
|
45
|
+
*/
|
|
46
|
+
handlers?: Record<string, (this: any, ...args: any[]) => any>;
|
|
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
|
+
}
|
|
58
|
+
export interface RuntimeOptions {
|
|
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;
|
|
68
|
+
components?: Record<string, IRComponentDef>;
|
|
69
|
+
/**
|
|
70
|
+
* Resolve a plain template object (e.g. a route's `template`)
|
|
71
|
+
* into a component definition — the host owns compilation and
|
|
72
|
+
* caching. Enables `<{state.page}/>` with template objects.
|
|
73
|
+
*/
|
|
74
|
+
resolveTemplate?(value: any): IRComponentDef | undefined;
|
|
75
|
+
/** Extra members merged onto every component's self (e.g. setContext) */
|
|
76
|
+
expose?: Record<string, any>;
|
|
77
|
+
/**
|
|
78
|
+
* Host-provided stylesheet injector (full build wires Stylis; the
|
|
79
|
+
* precompiled `./runtime` build omits it). Returns a handle whose
|
|
80
|
+
* `clear()` releases one reference.
|
|
81
|
+
*/
|
|
82
|
+
createStylesheet?(nsp: string, css: string): {
|
|
83
|
+
clear(): void;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
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.
|
|
94
|
+
*/
|
|
95
|
+
i18n?: {
|
|
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;
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
export interface RenderSetup {
|
|
103
|
+
state?: Record<string, any>;
|
|
104
|
+
input?: Record<string, any>;
|
|
105
|
+
context?: Record<string, any>;
|
|
106
|
+
static?: Record<string, any>;
|
|
107
|
+
handlers?: Record<string, (this: any, ...args: any[]) => any>;
|
|
108
|
+
/** Deep-reactive root state (old-engine parity) */
|
|
109
|
+
deep?: boolean;
|
|
110
|
+
/** Extra members merged onto self before handlers bind (e.g. emit) */
|
|
111
|
+
expose?: Record<string, any>;
|
|
112
|
+
/** Compiled stylesheet (RFC-004) + scope name (the `rel` value) */
|
|
113
|
+
stylesheet?: StyleIR;
|
|
114
|
+
nsp?: string;
|
|
115
|
+
}
|
|
116
|
+
/** `N` is the host's node type — `Node` on the DOM */
|
|
117
|
+
export interface IRInstance<N = Node> {
|
|
118
|
+
state: Record<string, any>;
|
|
119
|
+
self: Record<string, any>;
|
|
120
|
+
nodes: N[];
|
|
121
|
+
mount(container: N): void;
|
|
122
|
+
swap(newIR: TemplateIR): SwapReport;
|
|
123
|
+
dispose(): void;
|
|
124
|
+
}
|
|
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>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase 2 — reactivity core (RFC-001 §6)
|
|
3
|
+
*
|
|
4
|
+
* Minimal per-key signals: no history (that's the opt-in
|
|
5
|
+
* `historySignal` wrapper, later), no deep proxies, no digest.
|
|
6
|
+
* A write notifies exactly the effects that read that signal.
|
|
7
|
+
*/
|
|
8
|
+
export declare function batch<T>(fn: () => T): T;
|
|
9
|
+
export declare function signal<T>(value: T): [() => T, (next: T) => void, () => void];
|
|
10
|
+
export interface EffectHandle {
|
|
11
|
+
dispose(): void;
|
|
12
|
+
}
|
|
13
|
+
export declare function effect(fn: () => void): EffectHandle;
|
|
14
|
+
/** Run `fn` without dependency tracking */
|
|
15
|
+
export declare function untrack<T>(fn: () => T): T;
|
|
16
|
+
/**
|
|
17
|
+
* Per-key reactive facade over a plain object:
|
|
18
|
+
* reading a key inside an effect subscribes to that key;
|
|
19
|
+
* writing notifies only that key's subscribers.
|
|
20
|
+
* Idempotent — wrapping a reactive object returns it as-is.
|
|
21
|
+
*
|
|
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.
|
|
27
|
+
*/
|
|
28
|
+
export declare function reactive<T extends object>(obj: T, deep?: boolean): T;
|