@lipsjs/lips 0.1.1 → 0.2.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 +119 -85
- package/dist/lips.js +3836 -0
- package/dist/lips.js.map +28 -0
- package/dist/lips.min.js +9 -2
- package/dist/lips.min.js.map +22 -43
- package/dist/precompile.min.js +20 -0
- package/dist/precompile.min.js.map +13 -0
- package/dist/runtime.min.js +4 -0
- package/dist/runtime.min.js.map +19 -0
- package/dist/types/events.d.ts +1 -1
- package/dist/types/ir/compiler.d.ts +153 -0
- package/dist/types/ir/expression.d.ts +120 -0
- package/dist/types/ir/facade.d.ts +94 -0
- package/dist/types/ir/index.d.ts +15 -0
- package/dist/types/ir/parser.d.ts +124 -0
- package/dist/types/ir/router.d.ts +47 -0
- package/dist/types/ir/runtime.d.ts +95 -0
- package/dist/types/ir/signal.d.ts +26 -0
- package/dist/types/ir/swap.d.ts +23 -0
- package/dist/types/lips.d.ts +16 -37
- package/dist/types/precompile.d.ts +60 -0
- package/dist/types/runtime.d.ts +16 -0
- package/dist/types/stylesheet.d.ts +24 -40
- package/dist/types/types.d.ts +49 -185
- package/package.json +29 -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,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase 2 — Expression subsystem (RFC-001 §5)
|
|
3
|
+
*
|
|
4
|
+
* A dedicated parser for the template expression subset with:
|
|
5
|
+
* - positioned, machine-readable diagnostics (never throws)
|
|
6
|
+
* - AST-derived precise dependency paths
|
|
7
|
+
* - two interchangeable executors over the same AST:
|
|
8
|
+
* compiled — one Function per unique expression (trusted contexts)
|
|
9
|
+
* interpreted — sandboxed AST walker (CSP / untrusted embeds)
|
|
10
|
+
*
|
|
11
|
+
* Grammar (expression-only, no statements):
|
|
12
|
+
* literals (number, string, boolean, null, undefined), identifiers,
|
|
13
|
+
* member access (incl. optional/computed), calls, unary ! - + and
|
|
14
|
+
* prefix/postfix ++ --, binary arithmetic/relational/equality,
|
|
15
|
+
* && || ??, ternary, arrow functions, assignment (= += -= *= /= %=),
|
|
16
|
+
* array/object literals with spread.
|
|
17
|
+
*/
|
|
18
|
+
export interface ExprDiagnostic {
|
|
19
|
+
code: string;
|
|
20
|
+
message: string;
|
|
21
|
+
loc: {
|
|
22
|
+
offset: number;
|
|
23
|
+
length: number;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export type Expr = {
|
|
27
|
+
t: 'lit';
|
|
28
|
+
v: any;
|
|
29
|
+
} | {
|
|
30
|
+
t: 'id';
|
|
31
|
+
name: string;
|
|
32
|
+
} | {
|
|
33
|
+
t: 'member';
|
|
34
|
+
obj: Expr;
|
|
35
|
+
prop: string | Expr;
|
|
36
|
+
computed: boolean;
|
|
37
|
+
optional: boolean;
|
|
38
|
+
} | {
|
|
39
|
+
t: 'call';
|
|
40
|
+
callee: Expr;
|
|
41
|
+
args: Expr[];
|
|
42
|
+
optional: boolean;
|
|
43
|
+
} | {
|
|
44
|
+
t: 'unary';
|
|
45
|
+
op: '!' | '-' | '+';
|
|
46
|
+
arg: Expr;
|
|
47
|
+
} | {
|
|
48
|
+
t: 'update';
|
|
49
|
+
op: '++' | '--';
|
|
50
|
+
arg: Expr;
|
|
51
|
+
prefix: boolean;
|
|
52
|
+
} | {
|
|
53
|
+
t: 'bin';
|
|
54
|
+
op: string;
|
|
55
|
+
l: Expr;
|
|
56
|
+
r: Expr;
|
|
57
|
+
} | {
|
|
58
|
+
t: 'logic';
|
|
59
|
+
op: '&&' | '||' | '??';
|
|
60
|
+
l: Expr;
|
|
61
|
+
r: Expr;
|
|
62
|
+
} | {
|
|
63
|
+
t: 'cond';
|
|
64
|
+
test: Expr;
|
|
65
|
+
cons: Expr;
|
|
66
|
+
alt: Expr;
|
|
67
|
+
} | {
|
|
68
|
+
t: 'assign';
|
|
69
|
+
op: string;
|
|
70
|
+
target: Expr;
|
|
71
|
+
value: Expr;
|
|
72
|
+
} | {
|
|
73
|
+
t: 'arrow';
|
|
74
|
+
params: string[];
|
|
75
|
+
body: Expr;
|
|
76
|
+
} | {
|
|
77
|
+
t: 'arr';
|
|
78
|
+
items: {
|
|
79
|
+
spread?: boolean;
|
|
80
|
+
value: Expr;
|
|
81
|
+
}[];
|
|
82
|
+
} | {
|
|
83
|
+
t: 'obj';
|
|
84
|
+
props: {
|
|
85
|
+
key?: string;
|
|
86
|
+
value: Expr;
|
|
87
|
+
spread?: boolean;
|
|
88
|
+
}[];
|
|
89
|
+
} | {
|
|
90
|
+
t: 'error';
|
|
91
|
+
};
|
|
92
|
+
export declare function parseExpression(src: string): {
|
|
93
|
+
ast: Expr;
|
|
94
|
+
diagnostics: ExprDiagnostic[];
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Precise dependency paths from the AST: dotted member paths
|
|
98
|
+
* rooted at metavars (up to the first computed/call boundary),
|
|
99
|
+
* plus bare scope-variable reads. Arrow params shadow.
|
|
100
|
+
*/
|
|
101
|
+
export declare function extractDeps(ast: Expr, scopeNames?: string[]): string[];
|
|
102
|
+
export interface ExprEnv {
|
|
103
|
+
state?: any;
|
|
104
|
+
input?: any;
|
|
105
|
+
context?: any;
|
|
106
|
+
static?: any;
|
|
107
|
+
self?: any;
|
|
108
|
+
arguments?: any;
|
|
109
|
+
scope?: Record<string, any>;
|
|
110
|
+
}
|
|
111
|
+
export interface CompiledExpr {
|
|
112
|
+
run(env: ExprEnv): any;
|
|
113
|
+
source: string;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Compiled mode: one Function per unique (source, scopeNames) —
|
|
117
|
+
* strict-compatible, no `with`. Trusted contexts only.
|
|
118
|
+
*/
|
|
119
|
+
export declare function compileExpression(src: string, scopeNames?: string[]): CompiledExpr;
|
|
120
|
+
export declare function interpretExpression(ast: Expr, env: ExprEnv): any;
|
|
@@ -0,0 +1,94 @@
|
|
|
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
|
+
export declare function registerBuiltin(name: string, template: any): void;
|
|
22
|
+
import type { RuntimeOptions } from './runtime';
|
|
23
|
+
import Events from '../events';
|
|
24
|
+
import I18N from '../i18n';
|
|
25
|
+
interface FacadeTemplate {
|
|
26
|
+
default?: string;
|
|
27
|
+
/** Precompiled IR — skips parsing entirely (see src/precompile.ts) */
|
|
28
|
+
ir?: TemplateIR;
|
|
29
|
+
macros?: string;
|
|
30
|
+
state?: Record<string, any>;
|
|
31
|
+
handler?: Record<string, (this: any, ...args: any[]) => any>;
|
|
32
|
+
_static?: Record<string, any>;
|
|
33
|
+
context?: string[];
|
|
34
|
+
stylesheet?: string;
|
|
35
|
+
}
|
|
36
|
+
interface FacadeConfig {
|
|
37
|
+
engine?: string;
|
|
38
|
+
debug?: boolean;
|
|
39
|
+
context?: Record<string, any>;
|
|
40
|
+
mode?: 'compiled' | 'interpreted';
|
|
41
|
+
}
|
|
42
|
+
export declare class IRFacadeComponent extends Events {
|
|
43
|
+
private lips;
|
|
44
|
+
private template;
|
|
45
|
+
readonly state: Record<string, any>;
|
|
46
|
+
private instance;
|
|
47
|
+
private contextWatcher?;
|
|
48
|
+
private destroyed;
|
|
49
|
+
constructor(lips: IRLips, name: string, template: FacadeTemplate, input: Record<string, any> | undefined, ir: TemplateIR, options: RuntimeOptions);
|
|
50
|
+
get node(): Node[];
|
|
51
|
+
appendTo(selector: string | Element): this;
|
|
52
|
+
swap(newIR: TemplateIR): import("./swap").SwapReport;
|
|
53
|
+
destroy(): void;
|
|
54
|
+
}
|
|
55
|
+
export declare class IRLips {
|
|
56
|
+
private config?;
|
|
57
|
+
debug: boolean;
|
|
58
|
+
private store;
|
|
59
|
+
private irCache;
|
|
60
|
+
private defCache;
|
|
61
|
+
private context;
|
|
62
|
+
private __root?;
|
|
63
|
+
i18n: I18N;
|
|
64
|
+
/** Language signal — translated binds subscribe through it */
|
|
65
|
+
private getLang;
|
|
66
|
+
private setLang;
|
|
67
|
+
/**
|
|
68
|
+
* Registered components resolved lazily — the runtime looks
|
|
69
|
+
* names up per render, so registration order doesn't matter.
|
|
70
|
+
*/
|
|
71
|
+
private componentsProxy;
|
|
72
|
+
constructor(config?: FacadeConfig | undefined);
|
|
73
|
+
register(name: string, template: FacadeTemplate): this;
|
|
74
|
+
unregister(name: string): this;
|
|
75
|
+
has(name: string): boolean;
|
|
76
|
+
private compile;
|
|
77
|
+
private defFor;
|
|
78
|
+
render(name: string, template: FacadeTemplate, input?: Record<string, any>): IRFacadeComponent;
|
|
79
|
+
root(template: FacadeTemplate, selector: string): IRFacadeComponent;
|
|
80
|
+
setLanguage(lang: string): void;
|
|
81
|
+
getLanguage(): string;
|
|
82
|
+
useTranslator(support: string | string[], fn: (lang: string) => void): () => void;
|
|
83
|
+
getContext(): Record<string, any>;
|
|
84
|
+
setContext(arg: string | Record<string, any>, value?: any): void;
|
|
85
|
+
/**
|
|
86
|
+
* Subscribe to a subset of context fields — the effect tracks
|
|
87
|
+
* exactly those keys, so unrelated context writes don't fire it.
|
|
88
|
+
* Returns an unsubscribe function.
|
|
89
|
+
*/
|
|
90
|
+
watchContext(fields: string[], fn: () => void): () => void;
|
|
91
|
+
useContext(fields: string[], fn: (ctx: Record<string, any>) => void): () => void;
|
|
92
|
+
dispose(): void;
|
|
93
|
+
}
|
|
94
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
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, BindIR, ChildIR, CompInput, CompileResult } from './compiler';
|
|
12
|
+
export { renderIR } from './runtime';
|
|
13
|
+
export type { IRInstance, IRComponentDef, RuntimeOptions, RenderSetup } from './runtime';
|
|
14
|
+
export type { SwapReport, SwapChange } from './swap';
|
|
15
|
+
export { signal, effect, untrack, reactive } 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,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,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase 2 — IR runtime (RFC-001 §6, §8)
|
|
3
|
+
*
|
|
4
|
+
* TemplateIR → live DOM:
|
|
5
|
+
* - skeletons parsed ONCE per block into <template>, instantiated
|
|
6
|
+
* per use via content.cloneNode(true) + a bind walk over
|
|
7
|
+
* precomputed integer paths
|
|
8
|
+
* - every bind is its own effect over per-key signals — updates are
|
|
9
|
+
* O(changed bindings), no digest, no clones, no deep equality
|
|
10
|
+
* - block instances are bracketed by owned comment markers so
|
|
11
|
+
* control-flow content moves/disposes as a range
|
|
12
|
+
* - dual expression modes over the same IR: 'compiled' (Function,
|
|
13
|
+
* trusted) / 'interpreted' (sandboxed AST walker, CSP-safe)
|
|
14
|
+
*
|
|
15
|
+
* Hot-swap (§8): instances retain their structure (bind handles,
|
|
16
|
+
* child handles, resolved path nodes) so `instance.swap( newIR )`
|
|
17
|
+
* can diff old vs new by expression source and update surgically:
|
|
18
|
+
* - identical subtrees → kept wholesale (zero DOM work)
|
|
19
|
+
* - bind-only changes → effects rewired onto the SAME nodes
|
|
20
|
+
* - skeleton changes → that block re-rendered in place
|
|
21
|
+
* State lives outside the IR, so it survives by construction.
|
|
22
|
+
*/
|
|
23
|
+
import type { TemplateIR } from './compiler';
|
|
24
|
+
import type { SwapReport } from './swap';
|
|
25
|
+
export interface IRComponentDef {
|
|
26
|
+
ir: TemplateIR;
|
|
27
|
+
state?: Record<string, any>;
|
|
28
|
+
statics?: Record<string, any>;
|
|
29
|
+
/** Context fields this component subscribes to (fires onContext) */
|
|
30
|
+
context?: string[];
|
|
31
|
+
/** Scoped stylesheet source + scope name (the `rel` value) */
|
|
32
|
+
stylesheet?: string;
|
|
33
|
+
nsp?: string;
|
|
34
|
+
/** Deep-reactive component state (old-engine parity) */
|
|
35
|
+
deep?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Methods bound to the component self — lifecycle keys
|
|
38
|
+
* (onCreate/onInput/onMount/onDestroy) are invoked by the
|
|
39
|
+
* runtime at the matching moments.
|
|
40
|
+
*/
|
|
41
|
+
handlers?: Record<string, (this: any, ...args: any[]) => any>;
|
|
42
|
+
}
|
|
43
|
+
export interface RuntimeOptions {
|
|
44
|
+
mode?: 'compiled' | 'interpreted';
|
|
45
|
+
components?: Record<string, IRComponentDef>;
|
|
46
|
+
/** Host-provided context subscription (returns an unsubscribe) */
|
|
47
|
+
watchContext?(fields: string[], fn: () => void): () => void;
|
|
48
|
+
/**
|
|
49
|
+
* Resolve a plain template object (e.g. a route's `template`)
|
|
50
|
+
* into a component definition — the host owns compilation and
|
|
51
|
+
* caching. Enables `<{state.page}/>` with template objects.
|
|
52
|
+
*/
|
|
53
|
+
resolveTemplate?(value: any): IRComponentDef | undefined;
|
|
54
|
+
/** Extra members merged onto every component's self (e.g. setContext) */
|
|
55
|
+
expose?: Record<string, any>;
|
|
56
|
+
/**
|
|
57
|
+
* Host-provided stylesheet injector (full build wires Stylis; the
|
|
58
|
+
* precompiled `./runtime` build omits it). Returns a handle whose
|
|
59
|
+
* `clear()` releases one reference.
|
|
60
|
+
*/
|
|
61
|
+
createStylesheet?(nsp: string, css: string): {
|
|
62
|
+
clear(): void;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* i18n plugin hook (RFC §6): both calls must READ a language
|
|
66
|
+
* signal so translated binds re-run on language change.
|
|
67
|
+
*/
|
|
68
|
+
i18n?: {
|
|
69
|
+
translate(text: string): string;
|
|
70
|
+
format(reference: string, params: any): string;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export interface RenderSetup {
|
|
74
|
+
state?: Record<string, any>;
|
|
75
|
+
input?: Record<string, any>;
|
|
76
|
+
context?: Record<string, any>;
|
|
77
|
+
static?: Record<string, any>;
|
|
78
|
+
handlers?: Record<string, (this: any, ...args: any[]) => any>;
|
|
79
|
+
/** Deep-reactive root state (old-engine parity) */
|
|
80
|
+
deep?: boolean;
|
|
81
|
+
/** Extra members merged onto self before handlers bind (e.g. emit) */
|
|
82
|
+
expose?: Record<string, any>;
|
|
83
|
+
/** Scoped stylesheet source + scope name (the `rel` value) */
|
|
84
|
+
stylesheet?: string;
|
|
85
|
+
nsp?: string;
|
|
86
|
+
}
|
|
87
|
+
export interface IRInstance {
|
|
88
|
+
state: Record<string, any>;
|
|
89
|
+
self: Record<string, any>;
|
|
90
|
+
nodes: Node[];
|
|
91
|
+
mount(container: Element): void;
|
|
92
|
+
swap(newIR: TemplateIR): SwapReport;
|
|
93
|
+
dispose(): void;
|
|
94
|
+
}
|
|
95
|
+
export declare function renderIR(ir: TemplateIR, setup?: RenderSetup, options?: RuntimeOptions): IRInstance;
|
|
@@ -0,0 +1,26 @@
|
|
|
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 signal<T>(value: T): [() => T, (next: T) => void, () => void];
|
|
9
|
+
export interface EffectHandle {
|
|
10
|
+
dispose(): void;
|
|
11
|
+
}
|
|
12
|
+
export declare function effect(fn: () => void): EffectHandle;
|
|
13
|
+
/** Run `fn` without dependency tracking */
|
|
14
|
+
export declare function untrack<T>(fn: () => T): T;
|
|
15
|
+
/**
|
|
16
|
+
* Per-key reactive facade over a plain object:
|
|
17
|
+
* reading a key inside an effect subscribes to that key;
|
|
18
|
+
* writing notifies only that key's subscribers.
|
|
19
|
+
* Idempotent — wrapping a reactive object returns it as-is.
|
|
20
|
+
*
|
|
21
|
+
* Shallow by default (RFC §6). `deep: true` opts into nested
|
|
22
|
+
* mutation tracking: plain objects/arrays read through a key are
|
|
23
|
+
* lazily proxied, and any nested write force-notifies that top
|
|
24
|
+
* key's subscribers (coarse but O(subscribers-of-key)).
|
|
25
|
+
*/
|
|
26
|
+
export declare function reactive<T extends object>(obj: T, deep?: boolean): T;
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
export declare const normBind: (b: BindIR, x: string[]) => any;
|
|
19
|
+
export declare function normChild(c: ChildIR, x: string[]): any;
|
|
20
|
+
export declare const normBlock: (b: BlockIR, x: string[]) => any;
|
|
21
|
+
export declare const sameChild: (a: ChildIR, ax: string[], b: ChildIR, bx: string[]) => boolean;
|
|
22
|
+
export declare const sameBinds: (a: BindIR[], ax: string[], b: BindIR[], bx: string[]) => boolean;
|
|
23
|
+
export declare const sameLets: (a: BlockIR, ax: string[], b: BlockIR, bx: string[]) => boolean;
|
package/dist/types/lips.d.ts
CHANGED
|
@@ -1,38 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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';
|
|
8
13
|
export * from './types';
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
}
|
|
14
|
+
export { parseTemplate, parseSFC, compileTemplate, renderIR, signal, effect, untrack, reactive } from './ir';
|
|
15
|
+
export type { TemplateIR, BlockIR, BindIR, ChildIR, CompileResult, TemplateDiagnostic, IRInstance, IRComponentDef, RuntimeOptions, RenderSetup, SwapReport, SwapChange } from './ir';
|
|
16
|
+
export type Component = IRFacadeComponent;
|
|
17
|
+
export default IRLips;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build-time precompilation (RFC-001 §5, §9 — Phase 3).
|
|
3
|
+
*
|
|
4
|
+
* Turns `{ default: '<template…>' }` into `{ ir: {…} }` ahead of time.
|
|
5
|
+
* Two payoffs:
|
|
6
|
+
*
|
|
7
|
+
* 1. **CSP**: with `mode: 'interpreted'`, a precompiled app never
|
|
8
|
+
* calls `Function`/`eval`, so it runs under `script-src` without
|
|
9
|
+
* `unsafe-eval`.
|
|
10
|
+
* 2. **Startup**: no parse/compile at runtime — the app boots
|
|
11
|
+
* straight into cloning skeletons.
|
|
12
|
+
*
|
|
13
|
+
* The IR is plain JSON, so it can be emitted into a bundle, shipped
|
|
14
|
+
* from a server, or stored as a Modela artifact.
|
|
15
|
+
*/
|
|
16
|
+
import type { TemplateIR } from './ir/compiler';
|
|
17
|
+
import type { TemplateDiagnostic } from './ir/parser';
|
|
18
|
+
export interface PrecompiledTemplate {
|
|
19
|
+
ir: TemplateIR;
|
|
20
|
+
state?: Record<string, any>;
|
|
21
|
+
_static?: Record<string, any>;
|
|
22
|
+
context?: string[];
|
|
23
|
+
handler?: Record<string, (...args: any[]) => any>;
|
|
24
|
+
stylesheet?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface PrecompileResult {
|
|
27
|
+
template: PrecompiledTemplate;
|
|
28
|
+
diagnostics: TemplateDiagnostic[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Precompile one authoring template. Macros are inlined at this
|
|
32
|
+
* point, so the `macros` source does not ship to the client.
|
|
33
|
+
*/
|
|
34
|
+
export declare function precompile(template: Record<string, any>): PrecompileResult;
|
|
35
|
+
/** Serialize an IR for embedding in generated source */
|
|
36
|
+
export declare const serializeIR: (ir: TemplateIR) => string;
|
|
37
|
+
export interface PluginOptions {
|
|
38
|
+
/** Files to transform (default: `.lips` single-file components) */
|
|
39
|
+
include?: RegExp;
|
|
40
|
+
/** Emit diagnostics as build warnings (default true) */
|
|
41
|
+
reportDiagnostics?: boolean;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Vite/Rollup plugin: compiles `.lips` single-file components into a
|
|
45
|
+
* module exporting a precompiled template.
|
|
46
|
+
*
|
|
47
|
+
* import Card from './card.lips'
|
|
48
|
+
* lips.register('card', Card) // no runtime parsing
|
|
49
|
+
*
|
|
50
|
+
* Kept dependency-free (duck-typed plugin object) so importing this
|
|
51
|
+
* module never pulls a bundler into the runtime graph.
|
|
52
|
+
*/
|
|
53
|
+
export declare function lipsPlugin(options?: PluginOptions): {
|
|
54
|
+
name: string;
|
|
55
|
+
enforce: "pre";
|
|
56
|
+
transform(code: string, id: string): Promise<{
|
|
57
|
+
code: string;
|
|
58
|
+
map: null;
|
|
59
|
+
} | null>;
|
|
60
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Precompiled-only entry: the runtime WITHOUT the template parser
|
|
3
|
+
* and compiler.
|
|
4
|
+
*
|
|
5
|
+
* import Lips from '@lipsjs/lips/runtime'
|
|
6
|
+
*
|
|
7
|
+
* Templates must carry precompiled `ir` (see `precompile()` or the
|
|
8
|
+
* bundler plugin). Combined with `mode: 'interpreted'` this build
|
|
9
|
+
* never constructs a Function, so it runs under a strict CSP.
|
|
10
|
+
*/
|
|
11
|
+
import { IRLips } from './ir/facade';
|
|
12
|
+
export * from './types';
|
|
13
|
+
export { renderIR } from './ir/runtime';
|
|
14
|
+
export { signal, effect, untrack, reactive } from './ir/signal';
|
|
15
|
+
export type { TemplateIR, IRInstance, RuntimeOptions, RenderSetup, SwapReport } from './ir';
|
|
16
|
+
export default IRLips;
|