@lark.js/mvc 0.0.13 → 0.0.15
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 +4 -5
- package/dist/apply-style.d.ts +9 -0
- package/dist/cache.d.ts +69 -0
- package/dist/common.d.ts +64 -0
- package/dist/compiler/compile-template.d.ts +16 -0
- package/dist/compiler/compile-to-vdom-function.d.ts +13 -0
- package/dist/compiler/extract-global-vars.d.ts +17 -0
- package/dist/compiler/template-syntax.d.ts +61 -0
- package/dist/compiler.cjs +15843 -15805
- package/dist/compiler.d.cts +1 -30
- package/dist/compiler.d.ts +1 -30
- package/dist/compiler.js +15840 -15789
- package/dist/cross-site.d.ts +29 -0
- package/dist/devtool.cjs +4139 -3166
- package/dist/devtool.d.cts +2 -1
- package/dist/devtool.d.ts +2 -1
- package/dist/devtool.js +4149 -3092
- package/dist/dom.d.ts +45 -0
- package/dist/event-delegator.d.ts +28 -0
- package/dist/event-emitter.d.ts +38 -0
- package/dist/frame.d.ts +143 -0
- package/dist/framework.d.ts +9 -0
- package/dist/hmr.d.ts +53 -0
- package/dist/index.amd.js +6285 -0
- package/dist/index.cjs +5959 -4484
- package/dist/index.d.cts +10 -19
- package/dist/index.d.ts +10 -19
- package/dist/index.js +5919 -4419
- package/dist/index.umd.js +6272 -0
- package/dist/mark.d.ts +26 -0
- package/dist/module-loader.d.ts +20 -0
- package/dist/router.d.ts +14 -0
- package/dist/rspack.cjs +15927 -15877
- package/dist/rspack.d.cts +45 -23
- package/dist/rspack.d.ts +45 -23
- package/dist/rspack.js +15926 -15870
- package/dist/runtime.amd.js +94 -0
- package/dist/runtime.cjs +79 -82
- package/dist/runtime.js +85 -19
- package/dist/runtime.umd.js +98 -0
- package/dist/service.d.ts +173 -0
- package/dist/state.d.ts +8 -0
- package/dist/store.d.ts +60 -0
- package/dist/types.d.ts +1259 -0
- package/dist/updater.d.ts +90 -0
- package/dist/url-state.d.ts +32 -0
- package/dist/utils.d.ts +90 -0
- package/dist/vdom.d.ts +45 -0
- package/dist/view-registry.d.ts +20 -0
- package/dist/view.d.ts +214 -0
- package/dist/vite.cjs +15940 -15898
- package/dist/vite.d.cts +10 -8
- package/dist/vite.d.ts +10 -8
- package/dist/vite.js +15937 -15890
- package/dist/webpack.cjs +15977 -15877
- package/dist/webpack.d.cts +36 -14
- package/dist/webpack.d.ts +36 -14
- package/dist/webpack.js +15976 -15870
- package/package.json +6 -5
- package/dist/chunk-66OZBBSP.js +0 -108
- /package/{src → dist}/client.d.ts +0 -0
package/README.md
CHANGED
|
@@ -120,7 +120,7 @@ Both integrations share the same compilation pipeline: `extractGlobalVars` extra
|
|
|
120
120
|
import { defineView, Router } from "@lark.js/mvc";
|
|
121
121
|
|
|
122
122
|
export default defineView({
|
|
123
|
-
|
|
123
|
+
ctor() {
|
|
124
124
|
this.updater.set({ appName: "My App" });
|
|
125
125
|
this.on("destroy", () => console.log(`view destroyed: ${this.id}`));
|
|
126
126
|
},
|
|
@@ -130,7 +130,7 @@ export default defineView({
|
|
|
130
130
|
});
|
|
131
131
|
```
|
|
132
132
|
|
|
133
|
-
`defineView` is a typed wrapper around `View.extend`: via `ThisType<P & ViewInterface>` it threads the literal's own fields into `this`, so writing `this.appName` in `
|
|
133
|
+
`defineView` is a typed wrapper around `View.extend`: via `ThisType<P & ViewInterface>` it threads the literal's own fields into `this`, so writing `this.appName` in `ctor` requires no cast. Runtime behavior is equivalent to `View.extend({...})`.
|
|
134
134
|
|
|
135
135
|
### View and Template
|
|
136
136
|
|
|
@@ -439,7 +439,7 @@ Both produce equivalent runtime artifacts; the difference is purely in TypeScrip
|
|
|
439
439
|
### Lifecycle
|
|
440
440
|
|
|
441
441
|
- `init(params?)` — Called when the view is first instantiated. `params` comes from query strings on `v-lark`. Read stores and call `this.assign()` to prepare initial data here.
|
|
442
|
-
- `
|
|
442
|
+
- `ctor()` — Called by the merged ctors pipeline; each mixin's `ctor` executes in order. Suitable for "run once per instance" initialization.
|
|
443
443
|
- `assign()` — Should be called when data may have changed. Pattern: `this.updater.snapshot()` at the top, `this.updater.set(...)` in the middle, `return this.updater.altered()` at the end. The framework uses `altered()` to determine whether re-render is needed.
|
|
444
444
|
- `render()` — Default implementation is `this.updater.digest()`. Wrapped by `View.wrapMethod`: increments signature on entry, handles pending endUpdate cleanup on exit.
|
|
445
445
|
- Destruction — The framework automatically calls `release(key, true)` to release all `capture`d resources, cleans up event delegation, and sets signature to 0.
|
|
@@ -735,7 +735,6 @@ Marking large static subtrees with `ldk` can completely skip rendering work. Thi
|
|
|
735
735
|
| `Frame.getAll()` | All Frames as `Map<string, Frame>` |
|
|
736
736
|
| `Frame.getRoot()` | Current root Frame; returns `undefined` if not created |
|
|
737
737
|
| `Frame.createRoot(id)` | Idempotent root creation (`Framework.boot` calls this) |
|
|
738
|
-
| `Frame.root(id)` | `@deprecated` alias, forwards to `createRoot` |
|
|
739
738
|
| `new Frame(containerId)` | Independent Frame instance for micro-frontend / embedded widget scenarios |
|
|
740
739
|
| `frame.invoke(name, args?)` | Call the owning view's method; if view not mounted, pushes to `invokeList`, flushed by `View.runInvokes(frame)` after mounting |
|
|
741
740
|
| `frame.children()` | Child Frame id array (order not guaranteed) |
|
|
@@ -945,7 +944,7 @@ Similarities: unidirectional data flow; immutable write-back style; async protec
|
|
|
945
944
|
| --------------------- | ---------------------------------------- | ------------------------------------------------------------ |
|
|
946
945
|
| Component abstraction | Function components + Hooks | Class inheritance `View.extend` / `defineView` |
|
|
947
946
|
| State encapsulation | `useState` / `useReducer` | View instance fields, `create()` store, `State` |
|
|
948
|
-
| Side effects | `useEffect` / `useLayoutEffect` | `init` / `
|
|
947
|
+
| Side effects | `useEffect` / `useLayoutEffect` | `init` / `ctor` + `capture` / `release` |
|
|
949
948
|
| Render interruption | Fiber time-slicing, Suspense, Transition | Synchronous digest, not interruptible |
|
|
950
949
|
| Compile optimization | React Compiler (auto-memo) | Template compile-time only; no runtime auto-memo |
|
|
951
950
|
| Server rendering | RSC, streaming SSR | Not supported (design trade-off) |
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dynamically inject CSS styles into the document head.
|
|
3
|
+
* Returns a cleanup function to remove the injected styles.
|
|
4
|
+
*
|
|
5
|
+
* @param styleIdOrPairs - Style ID string or array of [id, content] pairs
|
|
6
|
+
* @param css - CSS content string (only used when first arg is string)
|
|
7
|
+
* @returns Cleanup function to remove the styles
|
|
8
|
+
*/
|
|
9
|
+
export declare function applyStyle(styleIdOrPairs: string | string[], css?: string): () => void;
|
package/dist/cache.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { CacheInterface, CacheOptions } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Cache class with LFU-style eviction.
|
|
4
|
+
* Keys are prefixed with SPLITTER for namespace isolation.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* const cache = new Cache({ maxSize: 20, bufferSize: 5 });
|
|
8
|
+
* cache.set('user', { name: 'Alice' });
|
|
9
|
+
* const user = cache.get('user');
|
|
10
|
+
* cache.has('user'); // true
|
|
11
|
+
* cache.del('user');
|
|
12
|
+
*/
|
|
13
|
+
export declare class Cache<T = unknown> implements CacheInterface<T> {
|
|
14
|
+
/** Cache entries array */
|
|
15
|
+
private entries;
|
|
16
|
+
/** Fast lookup: prefixed key -> entry */
|
|
17
|
+
private lookup;
|
|
18
|
+
/** Buffer size for eviction */
|
|
19
|
+
private readonly bufferSize;
|
|
20
|
+
/** Maximum cache size */
|
|
21
|
+
private readonly maxSize;
|
|
22
|
+
/** Total capacity (maxSize + bufferSize) */
|
|
23
|
+
private readonly capacity;
|
|
24
|
+
/** Callback when entry is removed */
|
|
25
|
+
private readonly onRemove?;
|
|
26
|
+
/** Sort comparator */
|
|
27
|
+
private readonly comparator;
|
|
28
|
+
constructor(options?: CacheOptions<T>);
|
|
29
|
+
/** Prefix a key with SPLITTER for namespace isolation */
|
|
30
|
+
private prefixKey;
|
|
31
|
+
/**
|
|
32
|
+
* Get a cached value by key.
|
|
33
|
+
* Updates frequency and timestamp for cache sorting.
|
|
34
|
+
*/
|
|
35
|
+
get(key: string): T | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Iterate all cached values.
|
|
38
|
+
*/
|
|
39
|
+
forEach(callback: (value: T | undefined) => void): void;
|
|
40
|
+
/**
|
|
41
|
+
* Set or update a cached value.
|
|
42
|
+
* If key already exists, updates value and increments frequency.
|
|
43
|
+
* If cache exceeds capacity, triggers eviction.
|
|
44
|
+
*/
|
|
45
|
+
set(key: string, value: T): void;
|
|
46
|
+
/**
|
|
47
|
+
* Delete a cached entry. Removes it immediately from both the lookup map
|
|
48
|
+
* and the entries array so the GC can reclaim the value without waiting
|
|
49
|
+
* for the next eviction sweep.
|
|
50
|
+
*/
|
|
51
|
+
del(key: string): void;
|
|
52
|
+
/**
|
|
53
|
+
* Check if a key exists in cache.
|
|
54
|
+
*/
|
|
55
|
+
has(key: string): boolean;
|
|
56
|
+
/** Get current cache size */
|
|
57
|
+
get size(): number;
|
|
58
|
+
/** Clear all entries */
|
|
59
|
+
clear(): void;
|
|
60
|
+
/**
|
|
61
|
+
* Evict the `bufferSize` worst entries from the cache.
|
|
62
|
+
*
|
|
63
|
+
* Uses single-pass partial selection (O(n·k)) instead of sorting the entire
|
|
64
|
+
* `entries` array (O(n log n)). For the typical `bufferSize = 5` this is
|
|
65
|
+
* effectively a linear scan with at most 5 in-bucket comparisons per
|
|
66
|
+
* iteration — and it avoids mutating the rest of `entries`.
|
|
67
|
+
*/
|
|
68
|
+
private evictEntries;
|
|
69
|
+
}
|
package/dist/common.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lark framework constants.
|
|
3
|
+
*/
|
|
4
|
+
/** Internal splitter character (U+001E Record Separator, invisible, used as namespace separator).
|
|
5
|
+
* Uses String.fromCharCode to survive bundlers that strip control-char literals. */
|
|
6
|
+
export declare const SPLITTER: string;
|
|
7
|
+
export declare const RouterEvents: {
|
|
8
|
+
CHANGE: string;
|
|
9
|
+
CHANGED: string;
|
|
10
|
+
PAGE_UNLOAD: string;
|
|
11
|
+
};
|
|
12
|
+
/** Attribute name: v-lark */
|
|
13
|
+
export declare const LARK_VIEW = "v-lark";
|
|
14
|
+
/** View event method regex: e.g. "app\x1eclickHandler(click)" or "clickHandler()"
|
|
15
|
+
* Group 1: optional frame ID (before SPLITTER)
|
|
16
|
+
* Group 2: handler name
|
|
17
|
+
* Group 3: params string
|
|
18
|
+
*/
|
|
19
|
+
export declare const EVENT_METHOD_REGEXP: RegExp;
|
|
20
|
+
/** View event method name regex: e.g. "name<click,mousedown>" or "$selector<click>" */
|
|
21
|
+
export declare const VIEW_EVENT_METHOD_REGEXP: RegExp;
|
|
22
|
+
/** URL query/hash trim regexp */
|
|
23
|
+
export declare const URL_TRIM_HASH_REGEXP: RegExp;
|
|
24
|
+
/** URL trim query regexp (before hash) */
|
|
25
|
+
export declare const URL_TRIM_QUERY_REGEXP: RegExp;
|
|
26
|
+
/** URL param key-value regexp */
|
|
27
|
+
export declare const URL_PARAM_REGEXP: RegExp;
|
|
28
|
+
/** URL params test regexp */
|
|
29
|
+
export declare const IS_URL_PARAMS: RegExp;
|
|
30
|
+
/** URL query/hash trim regexp for path extraction */
|
|
31
|
+
export declare const URL_QUERY_HASH_REGEXP: RegExp;
|
|
32
|
+
/** SVG namespace */
|
|
33
|
+
export declare const SVG_NS = "http://www.w3.org/2000/svg";
|
|
34
|
+
/** MathML namespace */
|
|
35
|
+
export declare const MATH_NS = "http://www.w3.org/1998/Math/MathML";
|
|
36
|
+
/** Tag name regexp for I_GetNode */
|
|
37
|
+
export declare const TAG_NAME_REGEXP: RegExp;
|
|
38
|
+
/** Async task break time (ms) */
|
|
39
|
+
export declare const CALL_BREAK_TIME = 48;
|
|
40
|
+
/** VDOM text node tag value (number 0, falsy, distinct from string tags) */
|
|
41
|
+
export declare const V_TEXT_NODE = 0;
|
|
42
|
+
/** Namespace map for SVG/MathML element creation in VDOM mode */
|
|
43
|
+
export declare const VDOM_NS_MAP: Record<string, string>;
|
|
44
|
+
/** Increment global counter and return new value */
|
|
45
|
+
export declare function nextCounter(): number;
|
|
46
|
+
/** Null-safe String conversion */
|
|
47
|
+
export declare function strSafe(v: unknown): string;
|
|
48
|
+
/** HTML entity encoding for safe output */
|
|
49
|
+
export declare function encodeHTML(v: unknown): string;
|
|
50
|
+
/** URI-encode with extra character encoding */
|
|
51
|
+
export declare function encodeURIExtra(v: unknown): string;
|
|
52
|
+
/** Quote-encode for attribute values */
|
|
53
|
+
export declare function encodeQuote(v: unknown): string;
|
|
54
|
+
/**
|
|
55
|
+
* Template reference function for creating stable keys for objects.
|
|
56
|
+
* Stores objects in refData with SPLITTER-prefixed keys.
|
|
57
|
+
*/
|
|
58
|
+
export declare function refFn(ref: Record<string, unknown>, value: unknown, key: string): string;
|
|
59
|
+
/**
|
|
60
|
+
* Check if a string is a refData reference token: SPLITTER followed by
|
|
61
|
+
* one or more ASCII decimal digits. Used by utils.ts translateData and
|
|
62
|
+
* updater.ts translate.
|
|
63
|
+
*/
|
|
64
|
+
export declare function isRefToken(s: string): boolean;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CompileOptions } from "@/types";
|
|
2
|
+
/**
|
|
3
|
+
* Compile an HTML template string into a JS module string.
|
|
4
|
+
* This is the main entry point for both Vite and Webpack loaders.
|
|
5
|
+
*
|
|
6
|
+
* The output is an ES module that exports a function with the signature:
|
|
7
|
+
* (data, viewId, refData) => string
|
|
8
|
+
*
|
|
9
|
+
* Internally it calls the compiled template function with the standard
|
|
10
|
+
* signature: ($data,$viewId,$refAlt,$encHtml,$strSafe,$encUri,$refFn,$encQuote)
|
|
11
|
+
*
|
|
12
|
+
* @param source - The raw HTML template content
|
|
13
|
+
* @param options - Compilation options
|
|
14
|
+
* @returns ES module source code exporting the compiled template function
|
|
15
|
+
*/
|
|
16
|
+
export declare function compileTemplate(source: string, options?: CompileOptions): Promise<string>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compile the internal `<% %>` syntax to a VDOM template function string.
|
|
3
|
+
*
|
|
4
|
+
* Uses htmlparser2 for robust HTML parsing:
|
|
5
|
+
* 1. Extract `<% %>` blocks into a store, replace with `\x00N\x00` placeholders
|
|
6
|
+
* 2. Parse the protected source with `parseDocument`
|
|
7
|
+
* 3. Walk the DOM tree recursively, emitting `$c()` (vdomCreate) calls
|
|
8
|
+
*
|
|
9
|
+
* Output is an arrow function:
|
|
10
|
+
* `($data,$viewId,$refAlt,$n,$refFn,$encUri,$encQuote)=>{...}`
|
|
11
|
+
* that returns the root VDomNode.
|
|
12
|
+
*/
|
|
13
|
+
export declare function compileToVDomFunction(source: string, debug: boolean, file?: string): string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extract global variable names from a template source using AST analysis.
|
|
3
|
+
*
|
|
4
|
+
* 1. Convert template commands (<% %> blocks) into a form parseable by an AST parser
|
|
5
|
+
* 2. Walk the AST to find all Identifier nodes
|
|
6
|
+
* 3. Track variable declarations (VariableDeclarator, FunctionDeclaration) as local vars
|
|
7
|
+
* 4. Track function parameters as local vars
|
|
8
|
+
* 5. Remaining identifiers that are not local and not in the exclusion list are "global" —
|
|
9
|
+
* they must be passed in as part of the data context ($$)
|
|
10
|
+
*
|
|
11
|
+
* This replaces the old regex-based `extractVariables()` with proper scope analysis,
|
|
12
|
+
* eliminating false positives from local template variables and function parameters.
|
|
13
|
+
*
|
|
14
|
+
* @param source - The raw HTML template content (with {{ }} syntax)
|
|
15
|
+
* @returns Array of global variable names found in the template
|
|
16
|
+
*/
|
|
17
|
+
export declare function extractGlobalVars(source: string): Promise<string[]>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @lark.js/mvc Template Compiler
|
|
3
|
+
*
|
|
4
|
+
* convertArtSyntax() ({{}} → <% %>)
|
|
5
|
+
* processViewEvents() (@event prefix + param encoding)
|
|
6
|
+
* compileToFunction() (<% %> → JS template function)
|
|
7
|
+
* extractGlobalVars() (AST-based global var analysis via @babel/parser)
|
|
8
|
+
*
|
|
9
|
+
* - All template operators: = (escape), ! (raw), @ (ref lookup), : (binding)
|
|
10
|
+
* - @event attribute processing with $splitter prefix + \x1e separator
|
|
11
|
+
* - $strSafe (null-safe toString), $encHtml (HTML entity encode), $encUri (URI encode), $encQuote (quote encode), $refFn (ref lookup)
|
|
12
|
+
* - Debug mode with line tracking ($dbgExpr/$dbgArt/$dbgLine) and try-catch error wrapper
|
|
13
|
+
* - View ID injection (\x1f → '+$viewId+')
|
|
14
|
+
* - Post-processing cleanup of empty concatenations
|
|
15
|
+
* - 0 configuration: auto-extract variables via AST analysis
|
|
16
|
+
*
|
|
17
|
+
* Template syntax:
|
|
18
|
+
* {{=variable}} → escaped output
|
|
19
|
+
* {{:variable}} → two-way binding (same as = for rendering)
|
|
20
|
+
* {{!variable}} → raw output (no HTML escaping)
|
|
21
|
+
* {{@variable}} → reference lookup for component data passing
|
|
22
|
+
* {{forOf list as item}} → loop
|
|
23
|
+
* {{forOf list as item idx}} → loop with index
|
|
24
|
+
* {{forIn obj as val key}} → object iteration
|
|
25
|
+
* {{for(let i=0;i<n;i++)}} → generic for loop
|
|
26
|
+
* {{if condition}} → conditional
|
|
27
|
+
* {{else if condition}} → else-if
|
|
28
|
+
* {{else}} → else
|
|
29
|
+
* {{/if}} / {{/forOf}} / {{/forIn}} / {{/for}} → close blocks
|
|
30
|
+
* {{set a = b}} → variable declaration
|
|
31
|
+
*/
|
|
32
|
+
/** Protected comment store — used internally by protectComments */
|
|
33
|
+
/**
|
|
34
|
+
* Preserve HTML comments to prevent template syntax inside comments from being converted.
|
|
35
|
+
*/
|
|
36
|
+
export declare function protectComments(source: string): {
|
|
37
|
+
protectedSource: string;
|
|
38
|
+
comments: string[];
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Restore previously protected HTML comments.
|
|
42
|
+
*/
|
|
43
|
+
export declare function restoreComments(source: string, comments: string[]): string;
|
|
44
|
+
/**
|
|
45
|
+
* Process @event attributes.
|
|
46
|
+
*
|
|
47
|
+
* 1. Add \x1f (VIEW_ID_PLACEHOLDER, becomes $viewId at render time) prefix + \x1e separator
|
|
48
|
+
* 2. Convert JS object literal params to URL query params
|
|
49
|
+
*
|
|
50
|
+
* @click="handlerName({key: 'value'})" → @click="\x1f\x1ehandlerName(key=value)"
|
|
51
|
+
* @click="handlerName()" → @click="\x1f\x1ehandlerName()"
|
|
52
|
+
* @click="goHome" → unchanged (no parens = not an event handler)
|
|
53
|
+
*/
|
|
54
|
+
export declare function processViewEvents(source: string): string;
|
|
55
|
+
/**
|
|
56
|
+
* Convert {{=}}/{{:}}/{{!}}/{{@}} and control flow syntax to internal <% %> syntax.
|
|
57
|
+
*
|
|
58
|
+
* In debug mode, adds \x11-delimited line tracking markers:
|
|
59
|
+
* <%'lineNo\x11code\x11'%> before forOf art expression
|
|
60
|
+
*/
|
|
61
|
+
export declare function convertArtSyntax(source: string, debug: boolean): string;
|