@lark.js/mvc 0.0.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.
- package/README.md +1 -0
- package/dist/chunk-DZUOIUWX.js +15344 -0
- package/dist/index.cjs +5141 -0
- package/dist/index.d.cts +1471 -0
- package/dist/index.d.ts +1471 -0
- package/dist/index.js +5030 -0
- package/dist/vite.cjs +15385 -0
- package/dist/vite.d.cts +38 -0
- package/dist/vite.d.ts +38 -0
- package/dist/vite.js +36 -0
- package/dist/webpack.cjs +15371 -0
- package/dist/webpack.d.cts +18 -0
- package/dist/webpack.d.ts +18 -0
- package/dist/webpack.js +22 -0
- package/package.json +82 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,1471 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lark framework type definitions.
|
|
3
|
+
* All shared types are defined here to eliminate type cheats across modules.
|
|
4
|
+
*/
|
|
5
|
+
/** Generic function type for event handlers and callbacks.
|
|
6
|
+
* Uses any[] to accept callbacks with specific parameter types
|
|
7
|
+
* (TypeScript function parameters are contravariant).
|
|
8
|
+
*/
|
|
9
|
+
type AnyFunc = (...args: any[]) => unknown;
|
|
10
|
+
/** A function that returns void. */
|
|
11
|
+
type VoidFunc = (...args: any[]) => void;
|
|
12
|
+
interface CacheEntry<T> {
|
|
13
|
+
/** Original key without prefix */
|
|
14
|
+
originalKey: string;
|
|
15
|
+
/** Cached value */
|
|
16
|
+
value: T | undefined;
|
|
17
|
+
/** Access frequency count */
|
|
18
|
+
frequency: number;
|
|
19
|
+
/** Last access timestamp */
|
|
20
|
+
lastTimestamp: number;
|
|
21
|
+
}
|
|
22
|
+
interface CacheOptions<T> {
|
|
23
|
+
/** Maximum cache size before eviction triggers (default: 20) */
|
|
24
|
+
maxSize?: number;
|
|
25
|
+
/** Buffer size for eviction (default: 5) */
|
|
26
|
+
bufferSize?: number;
|
|
27
|
+
/** Callback when entry is removed */
|
|
28
|
+
onRemove?: (key: string) => void;
|
|
29
|
+
/** Comparator for sorting entries */
|
|
30
|
+
sortComparator?: (a: CacheEntry<T>, b: CacheEntry<T>) => number;
|
|
31
|
+
}
|
|
32
|
+
interface EventListenerEntry {
|
|
33
|
+
/** Handler function */
|
|
34
|
+
handler: AnyFunc;
|
|
35
|
+
/** Whether currently executing (1 = executing, '' = done) */
|
|
36
|
+
executing: number | string;
|
|
37
|
+
}
|
|
38
|
+
interface ParsedUri {
|
|
39
|
+
/** Path portion (before ? or #) */
|
|
40
|
+
path: string;
|
|
41
|
+
/** Key-value params */
|
|
42
|
+
params: Record<string, string>;
|
|
43
|
+
}
|
|
44
|
+
interface Location {
|
|
45
|
+
/** Full href */
|
|
46
|
+
href: string;
|
|
47
|
+
/** Query string (before #) */
|
|
48
|
+
srcQuery: string;
|
|
49
|
+
/** Hash string (after #) */
|
|
50
|
+
srcHash: string;
|
|
51
|
+
/** Parsed query object */
|
|
52
|
+
query: ParsedUri;
|
|
53
|
+
/** Parsed hash object */
|
|
54
|
+
hash: ParsedUri;
|
|
55
|
+
/** Merged params from query and hash */
|
|
56
|
+
params: Record<string, string>;
|
|
57
|
+
/** Resolved view path */
|
|
58
|
+
view?: string;
|
|
59
|
+
/** Resolved path */
|
|
60
|
+
path?: string;
|
|
61
|
+
/** Get param by key with optional default */
|
|
62
|
+
get: (key: string, defaultValue?: string) => string;
|
|
63
|
+
}
|
|
64
|
+
interface ParamDiff {
|
|
65
|
+
from: string;
|
|
66
|
+
to: string;
|
|
67
|
+
}
|
|
68
|
+
interface LocationDiff {
|
|
69
|
+
/** Changed params (key -> {from, to}) */
|
|
70
|
+
params: Record<string, ParamDiff>;
|
|
71
|
+
/** Whether path changed */
|
|
72
|
+
path?: ParamDiff;
|
|
73
|
+
/** Whether view changed */
|
|
74
|
+
view?: ParamDiff;
|
|
75
|
+
/** Whether this is a first forced change */
|
|
76
|
+
force: boolean;
|
|
77
|
+
/** Whether anything changed */
|
|
78
|
+
changed: boolean;
|
|
79
|
+
}
|
|
80
|
+
interface VDomRef {
|
|
81
|
+
/** ID update list: [element, newId][] */
|
|
82
|
+
idUpdates: [Element, string][];
|
|
83
|
+
/** Views that need post-processing */
|
|
84
|
+
views: ViewInstance[];
|
|
85
|
+
/** DOM operation list: [opCode, parent, newChild?, oldChild?][] */
|
|
86
|
+
domOps: VDomOp[];
|
|
87
|
+
/** Whether anything changed */
|
|
88
|
+
hasChanged: number;
|
|
89
|
+
}
|
|
90
|
+
type VDomOp = [1, Element, Element] | [2, Element, Element] | [4, Element, Element, Element] | [8, Element, Element, Element];
|
|
91
|
+
type FrameChildrenMap = Record<string, string>;
|
|
92
|
+
type FrameReadyMap = Record<string, number>;
|
|
93
|
+
interface FrameInvokeEntry {
|
|
94
|
+
/** Method name */
|
|
95
|
+
name: string;
|
|
96
|
+
/** Method arguments */
|
|
97
|
+
args: unknown[];
|
|
98
|
+
/** Internal key for dedup */
|
|
99
|
+
key: string;
|
|
100
|
+
/** Whether removed (args match) */
|
|
101
|
+
removed?: boolean;
|
|
102
|
+
}
|
|
103
|
+
/** Mixin event handler with internal merge marker and handler list */
|
|
104
|
+
interface MixinEventHandler extends AnyFunc {
|
|
105
|
+
/** Merged handler list */ a?: AnyFunc[];
|
|
106
|
+
/** Mixin marker: 1 = this is a mixin function */ b?: number;
|
|
107
|
+
}
|
|
108
|
+
/** View event selector map entry: handler name list with selector presence tracking */
|
|
109
|
+
interface ViewEventSelectorEntry {
|
|
110
|
+
/** Selector name list */
|
|
111
|
+
selectors: string[];
|
|
112
|
+
/** Index signature for checking if selector is already registered */
|
|
113
|
+
[selector: string]: unknown;
|
|
114
|
+
}
|
|
115
|
+
/** View class internal markers (SPLITTER key) */
|
|
116
|
+
type ViewClassInternal = Record<string, AnyFunc[]>;
|
|
117
|
+
interface ViewLocationObserved {
|
|
118
|
+
/** Whether observing location */
|
|
119
|
+
flag: number;
|
|
120
|
+
/** Keys to observe */
|
|
121
|
+
keys: string[];
|
|
122
|
+
/** Whether observing path */
|
|
123
|
+
observePath: boolean;
|
|
124
|
+
}
|
|
125
|
+
interface ViewResourceEntry {
|
|
126
|
+
/** The resource entity */
|
|
127
|
+
entity: unknown;
|
|
128
|
+
/** Whether to destroy when render() is called */
|
|
129
|
+
destroyOnRender: boolean;
|
|
130
|
+
}
|
|
131
|
+
type ViewResourceMap = Record<string, ViewResourceEntry>;
|
|
132
|
+
type ViewEventSelectorMap = Record<string, ViewEventSelectorEntry>;
|
|
133
|
+
interface ViewGlobalEventEntry {
|
|
134
|
+
/** Handler function */
|
|
135
|
+
handler: AnyFunc;
|
|
136
|
+
/** Bound handler wrapper (for removeEventListener) */
|
|
137
|
+
boundHandler?: AnyFunc;
|
|
138
|
+
/** DOM element (window/document) */
|
|
139
|
+
element: EventTarget;
|
|
140
|
+
/** Event name */
|
|
141
|
+
eventName: string;
|
|
142
|
+
/** Modifiers */
|
|
143
|
+
modifiers: Record<string, boolean>;
|
|
144
|
+
}
|
|
145
|
+
type ViewEventObjectMap = Record<string, number>;
|
|
146
|
+
interface ViewInstance {
|
|
147
|
+
/** View ID (same as owner frame ID) */
|
|
148
|
+
id: string;
|
|
149
|
+
/** Owner frame */
|
|
150
|
+
owner: FrameLike | number;
|
|
151
|
+
/** Updater instance */
|
|
152
|
+
updater: UpdaterLike;
|
|
153
|
+
/** Signature: > 0 means active, incremented on render, 0 = destroyed */
|
|
154
|
+
signature: number;
|
|
155
|
+
/** Whether rendered at least once */
|
|
156
|
+
rendered?: boolean;
|
|
157
|
+
/** Whether view has template */
|
|
158
|
+
tmpl?: AnyFunc | string;
|
|
159
|
+
/** Location observation config */
|
|
160
|
+
locationObserved: ViewLocationObserved;
|
|
161
|
+
/** Observed state keys */
|
|
162
|
+
observedStateKeys?: string[];
|
|
163
|
+
/** Resource map */
|
|
164
|
+
resources: ViewResourceMap;
|
|
165
|
+
/** Selector event map: eventType -> selector list */
|
|
166
|
+
eventSelectorMap: ViewEventSelectorMap;
|
|
167
|
+
/** Event object map: eventType -> bitmask */
|
|
168
|
+
eventObjectMap: ViewEventObjectMap;
|
|
169
|
+
/** Global event list */
|
|
170
|
+
globalEventList: ViewGlobalEventEntry[];
|
|
171
|
+
/** Assign method reference */
|
|
172
|
+
assignMethod?: AnyFunc;
|
|
173
|
+
/** Whether endUpdate has been called (1 = pending) */
|
|
174
|
+
endUpdatePending?: number;
|
|
175
|
+
/** Render method (wrapped) */
|
|
176
|
+
render: AnyFunc;
|
|
177
|
+
/** init method */
|
|
178
|
+
init: AnyFunc;
|
|
179
|
+
/** Wrapped render method */
|
|
180
|
+
$b?: AnyFunc;
|
|
181
|
+
/** endUpdate pending flag */
|
|
182
|
+
$e?: number;
|
|
183
|
+
on: (event: string, handler: AnyFunc) => ViewInstance;
|
|
184
|
+
off: (event: string, handler?: AnyFunc) => ViewInstance;
|
|
185
|
+
fire: (event: string, data?: Record<string, unknown>, remove?: boolean, lastToFirst?: boolean) => ViewInstance;
|
|
186
|
+
beginUpdate: (id?: string) => void;
|
|
187
|
+
endUpdate: (id?: string, inner?: boolean) => void;
|
|
188
|
+
wrapAsync: <Fn extends AnyFunc>(fn: Fn, context?: unknown) => (...args: Parameters<Fn>) => ReturnType<Fn> | undefined;
|
|
189
|
+
observeLocation: (params: string | string[] | Record<string, unknown>, observePath?: boolean) => void;
|
|
190
|
+
observeState: (keys: string | string[]) => void;
|
|
191
|
+
capture: (key: string, resource?: unknown, destroyOnRender?: boolean) => unknown;
|
|
192
|
+
release: (key: string, destroy?: boolean) => unknown;
|
|
193
|
+
leaveTip: (message: string, condition: () => boolean) => void;
|
|
194
|
+
assign: (options?: unknown) => boolean | undefined;
|
|
195
|
+
}
|
|
196
|
+
/** Minimal Frame interface needed by View */
|
|
197
|
+
interface FrameLike {
|
|
198
|
+
id: string;
|
|
199
|
+
parentId: string | undefined;
|
|
200
|
+
unmountZone: (zoneId?: string, inner?: boolean) => void;
|
|
201
|
+
mountZone: (zoneId?: string, inner?: boolean) => void;
|
|
202
|
+
mountFrame: (frameId: string, viewPath: string, viewInitParams?: Record<string, unknown>) => FrameLike;
|
|
203
|
+
unmountFrame: (id?: string, inner?: boolean) => void;
|
|
204
|
+
view: ViewInstance | undefined;
|
|
205
|
+
children: () => string[];
|
|
206
|
+
invoke: (name: string, args?: unknown[]) => unknown;
|
|
207
|
+
invokeList: FrameInvokeEntry[];
|
|
208
|
+
on: (event: string, handler: AnyFunc) => FrameLike;
|
|
209
|
+
off: (event: string, handler?: AnyFunc) => FrameLike;
|
|
210
|
+
fire: (event: string, data?: Record<string, unknown>) => FrameLike;
|
|
211
|
+
}
|
|
212
|
+
/** Minimal Updater interface needed by View */
|
|
213
|
+
interface UpdaterLike {
|
|
214
|
+
get: <T = unknown>(key?: string) => T;
|
|
215
|
+
set: (data: Record<string, unknown>, excludes?: Set<string>) => UpdaterLike;
|
|
216
|
+
digest: (data?: Record<string, unknown>, excludes?: Set<string>) => void;
|
|
217
|
+
/** Save a snapshot of current data for altered() detection */
|
|
218
|
+
snapshot: () => this;
|
|
219
|
+
/** Check if data has changed since last snapshot */
|
|
220
|
+
altered: () => boolean | undefined;
|
|
221
|
+
/** Ref data for template rendering */
|
|
222
|
+
refData: Record<string, unknown>;
|
|
223
|
+
}
|
|
224
|
+
interface ServiceOptions {
|
|
225
|
+
/** Request URL */
|
|
226
|
+
url: string;
|
|
227
|
+
/** Request params */
|
|
228
|
+
params?: Record<string, unknown>;
|
|
229
|
+
/** HTTP method */
|
|
230
|
+
method?: "GET" | "POST" | "PUT" | "DELETE";
|
|
231
|
+
/** Cache: true for default, number for TTL */
|
|
232
|
+
cache?: boolean | number;
|
|
233
|
+
/** POST data */
|
|
234
|
+
data?: unknown;
|
|
235
|
+
}
|
|
236
|
+
interface BagEntry {
|
|
237
|
+
/** Bag data */
|
|
238
|
+
data: Record<string, unknown>;
|
|
239
|
+
}
|
|
240
|
+
interface ServiceEntry {
|
|
241
|
+
/** Service ID */
|
|
242
|
+
id: string;
|
|
243
|
+
/** Service URL */
|
|
244
|
+
url: string;
|
|
245
|
+
/** Cache time in ms, 0 = no cache */
|
|
246
|
+
cacheTime: number;
|
|
247
|
+
/** Bag instance */
|
|
248
|
+
bag?: BagEntry;
|
|
249
|
+
/** Whether loading */
|
|
250
|
+
loading?: boolean;
|
|
251
|
+
/** Error info */
|
|
252
|
+
error?: Error;
|
|
253
|
+
}
|
|
254
|
+
/** Pending cache entry for deduplication (internal to Service) */
|
|
255
|
+
interface PendingCacheEntry extends Array<unknown> {
|
|
256
|
+
/** Reference to the pending Bag entity */
|
|
257
|
+
e?: unknown;
|
|
258
|
+
}
|
|
259
|
+
interface ServiceMetaEntry {
|
|
260
|
+
/** Endpoint name */
|
|
261
|
+
name: string;
|
|
262
|
+
/** URL */
|
|
263
|
+
url: string;
|
|
264
|
+
/** Cache TTL in ms, 0 = no cache */
|
|
265
|
+
cache?: number;
|
|
266
|
+
/** Before-fetch hook */
|
|
267
|
+
before?: AnyFunc;
|
|
268
|
+
/** After-fetch hook */
|
|
269
|
+
after?: AnyFunc;
|
|
270
|
+
/** Clean keys on destroy */
|
|
271
|
+
cleans?: string;
|
|
272
|
+
/** Additional properties */
|
|
273
|
+
[key: string]: unknown;
|
|
274
|
+
}
|
|
275
|
+
/** Cache info attached to Bag entity */
|
|
276
|
+
interface ServiceCacheInfo {
|
|
277
|
+
/** Endpoint name */
|
|
278
|
+
name: string;
|
|
279
|
+
/** After-fetch hook */
|
|
280
|
+
after?: AnyFunc | undefined;
|
|
281
|
+
/** Clean keys */
|
|
282
|
+
cleans?: string | undefined;
|
|
283
|
+
/** Cache key */
|
|
284
|
+
key: string;
|
|
285
|
+
/** Timestamp when cached */
|
|
286
|
+
time: number;
|
|
287
|
+
}
|
|
288
|
+
interface FrameworkConfig {
|
|
289
|
+
/** Root element ID */
|
|
290
|
+
rootId: string;
|
|
291
|
+
/** Default view path */
|
|
292
|
+
defaultView?: string;
|
|
293
|
+
/** Default path when no hash present */
|
|
294
|
+
defaultPath?: string;
|
|
295
|
+
/** Route mapping: path -> view */
|
|
296
|
+
routes?: Record<string, string | RouteViewConfig>;
|
|
297
|
+
/** Hashbang prefix */
|
|
298
|
+
hashbang?: string;
|
|
299
|
+
/** Error handler */
|
|
300
|
+
error?: (error: Error) => void;
|
|
301
|
+
/** Extensions to load */
|
|
302
|
+
exts?: string[];
|
|
303
|
+
/** Init module to load */
|
|
304
|
+
ini?: string;
|
|
305
|
+
/** Rewrite function for routes */
|
|
306
|
+
rewrite?: (path: string, params: Record<string, string>, routes: Record<string, string>) => string;
|
|
307
|
+
/** Unmatched view (404) */
|
|
308
|
+
unmatchedView?: string;
|
|
309
|
+
/** Module require function */
|
|
310
|
+
require?: (names: string[], params?: Record<string, unknown>) => Promise<unknown> | undefined;
|
|
311
|
+
/** Skip view rendered check */
|
|
312
|
+
skipViewRendered?: boolean;
|
|
313
|
+
/** Remold function for event processing */
|
|
314
|
+
remold?: (target: HTMLElement, type: string, event: Event) => boolean;
|
|
315
|
+
/** Dynamic config access */
|
|
316
|
+
[key: string]: unknown;
|
|
317
|
+
}
|
|
318
|
+
interface RouteViewConfig {
|
|
319
|
+
/** View path */
|
|
320
|
+
view: string;
|
|
321
|
+
/** Additional properties merged into location */
|
|
322
|
+
[key: string]: unknown;
|
|
323
|
+
}
|
|
324
|
+
/** Element with VDOM diff cached compare key */
|
|
325
|
+
interface VdomElement extends Element {
|
|
326
|
+
/** Whether compare key is cached */
|
|
327
|
+
compareKeyCached?: number | undefined;
|
|
328
|
+
/** Cached compare key */
|
|
329
|
+
cachedCompareKey?: string | undefined;
|
|
330
|
+
/** Whether auto-generated ID */
|
|
331
|
+
autoId?: number;
|
|
332
|
+
}
|
|
333
|
+
/** Element with frame binding */
|
|
334
|
+
interface FrameBoundElement extends HTMLElement {
|
|
335
|
+
/** Frame instance bound to this element */
|
|
336
|
+
frame?: FrameLike;
|
|
337
|
+
/** Whether frame is bound (1 = bound) */
|
|
338
|
+
frameBound?: number;
|
|
339
|
+
/** View rendered flag */
|
|
340
|
+
viewRendered?: number;
|
|
341
|
+
/** Range frame ID */
|
|
342
|
+
rangeFrameId?: string;
|
|
343
|
+
/** Range element guid */
|
|
344
|
+
rangeElementGuid?: number;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Lark framework utility functions.
|
|
349
|
+
*/
|
|
350
|
+
|
|
351
|
+
/** Check if value is a plain object (not null, not array, typeof object) */
|
|
352
|
+
declare function isPlainObject(value: unknown): value is Record<string, unknown>;
|
|
353
|
+
/** Check if value is an array */
|
|
354
|
+
declare const isArray: (arg: any) => arg is any[];
|
|
355
|
+
/** Check if value is primitive or function (not a complex object) */
|
|
356
|
+
declare function isPrimitiveOrFunc(value: unknown): boolean;
|
|
357
|
+
/** Check if value is primitive (not object, not function) */
|
|
358
|
+
declare function isPrimitive(value: unknown): boolean;
|
|
359
|
+
declare function generateId(prefix?: string): string;
|
|
360
|
+
/** Sync local counter with global counter */
|
|
361
|
+
declare function syncCounter(val: number): void;
|
|
362
|
+
declare function noop(): void;
|
|
363
|
+
/** Safe hasOwnProperty check */
|
|
364
|
+
declare function has<T extends object>(owner: T | undefined | null, prop: PropertyKey): boolean;
|
|
365
|
+
/** Get object keys (own enumerable) */
|
|
366
|
+
declare function keys<T extends object>(obj: T): string[];
|
|
367
|
+
/** Assign properties from sources to target (like Object.assign but safer) */
|
|
368
|
+
declare function assign<T extends object>(target: T, ...sources: Partial<T>[]): T;
|
|
369
|
+
/**
|
|
370
|
+
* Execute functions in try-catch, ignoring errors.
|
|
371
|
+
* Returns the result of the last successfully executed function.
|
|
372
|
+
*/
|
|
373
|
+
declare function funcWithTry(fns: AnyFunc | AnyFunc[], args: unknown[], context: unknown, configError: (e: unknown) => void): unknown;
|
|
374
|
+
/**
|
|
375
|
+
* Set newData into oldData, tracking changed keys.
|
|
376
|
+
* Returns whether any value changed.
|
|
377
|
+
*/
|
|
378
|
+
declare function setData(newData: Record<string, unknown>, oldData: Record<string, unknown>, changedKeys: Record<string, number>, excludes: Set<string>): boolean;
|
|
379
|
+
/**
|
|
380
|
+
* Translate data references: if a value starts with SPLITTER, replace it
|
|
381
|
+
* with the corresponding value from the data object.
|
|
382
|
+
*/
|
|
383
|
+
declare function translateData(data: object, value: unknown): unknown;
|
|
384
|
+
/** Get element by ID, or return the element itself if already an element */
|
|
385
|
+
declare function getById(id: string | Element | null): Element | null;
|
|
386
|
+
/** Get attribute from element safely */
|
|
387
|
+
declare function getAttribute(element: Element, attr: string): string;
|
|
388
|
+
/** Ensure element has an ID, generating one if missing. Returns the ID. */
|
|
389
|
+
declare function ensureElementId(element: HTMLElement): string;
|
|
390
|
+
/**
|
|
391
|
+
* Check if node A is inside node B (or is the same node).
|
|
392
|
+
* Uses compareDocumentPosition for efficiency.
|
|
393
|
+
*/
|
|
394
|
+
declare function nodeInside(a: string | HTMLElement, b: string | HTMLElement): boolean;
|
|
395
|
+
/**
|
|
396
|
+
* Parse URI string into path and params object.
|
|
397
|
+
* e.g. "/xxx/?a=b&c=d" => { path: "/xxx/", params: { a: "b", c: "d" } }
|
|
398
|
+
*/
|
|
399
|
+
declare function parseUri(uri: string): ParsedUri;
|
|
400
|
+
/**
|
|
401
|
+
* Convert path and params to URI string.
|
|
402
|
+
* e.g. toUri("/xxx/", { a: "b", c: "d" }) => "/xxx/?a=b&c=d"
|
|
403
|
+
*/
|
|
404
|
+
declare function toUri(path: string, params: Record<string, unknown>, keepEmptyObject?: Record<string, number>): string;
|
|
405
|
+
/**
|
|
406
|
+
* Convert array to map/hash object.
|
|
407
|
+
* For simple arrays, counts occurrences.
|
|
408
|
+
* For object arrays, uses specified key as map key.
|
|
409
|
+
*/
|
|
410
|
+
declare function toMap<T>(list: T[] | null | undefined, key?: keyof T): Record<string, T | number>;
|
|
411
|
+
/** Get current timestamp */
|
|
412
|
+
declare function now(): number;
|
|
413
|
+
/** Constructable function type */
|
|
414
|
+
type Constructable = new (...args: never[]) => unknown;
|
|
415
|
+
/**
|
|
416
|
+
* Implement classical inheritance with prototype chain.
|
|
417
|
+
* This is the only place where we touch constructor internals -
|
|
418
|
+
* it's a low-level framework utility for View.extend.
|
|
419
|
+
*/
|
|
420
|
+
declare function classExtend<Proto extends object, Statics extends object>(ctor: Constructable, base: Constructable, props: Proto, statics: Statics): void;
|
|
421
|
+
|
|
422
|
+
/** Internal splitter character (invisible, used as namespace separator) */
|
|
423
|
+
declare const SPLITTER = "\u001E";
|
|
424
|
+
declare const ROUTER_EVENTS: {
|
|
425
|
+
CHANGE: string;
|
|
426
|
+
CHANGED: string;
|
|
427
|
+
PAGE_UNLOAD: string;
|
|
428
|
+
};
|
|
429
|
+
/** Attribute name: lark-key (static key for skipping VDOM diff) */
|
|
430
|
+
declare const TAG_KEY = "lark-key";
|
|
431
|
+
/** Attribute name: lark-attr-key (static attribute key) */
|
|
432
|
+
declare const TAG_ATTR_KEY = "lark-attr-key";
|
|
433
|
+
/** Attribute name: l (view key for assign) */
|
|
434
|
+
declare const TAG_VIEW_KEY = "lark-view-key";
|
|
435
|
+
/** Attribute name: lark-view */
|
|
436
|
+
declare const LARK_VIEW = "lark-view";
|
|
437
|
+
/** View event method regex: e.g. "app\x1eclickHandler(click)" or "clickHandler()"
|
|
438
|
+
* Group 1: optional frame ID (before SPLITTER)
|
|
439
|
+
* Group 2: handler name
|
|
440
|
+
* Group 3: params string
|
|
441
|
+
*/
|
|
442
|
+
declare const EVT_METHOD_REG: RegExp;
|
|
443
|
+
/** View event method name regex: e.g. "name<click,mousedown>" or "$selector<click>" */
|
|
444
|
+
declare const VIEW_EVT_METHOD_REG: RegExp;
|
|
445
|
+
/** Tag name regex for I_GetNode */
|
|
446
|
+
declare const TAG_NAME_REGEX: RegExp;
|
|
447
|
+
/** Async task break time (ms) */
|
|
448
|
+
declare const CALL_BREAK_TIME = 48;
|
|
449
|
+
/** Increment global counter and return new value */
|
|
450
|
+
declare function nextCounter(): number;
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* Dynamically inject CSS styles into the document head.
|
|
454
|
+
* Returns a cleanup function to remove the injected styles.
|
|
455
|
+
*
|
|
456
|
+
* @param styleIdOrPairs - Style ID string or array of [id, content] pairs
|
|
457
|
+
* @param css - CSS content string (only used when first arg is string)
|
|
458
|
+
* @returns Cleanup function to remove the styles
|
|
459
|
+
*/
|
|
460
|
+
declare function applyStyle(styleIdOrPairs: string | string[], css?: string): () => void;
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* Mark/Unmark: signature-based lifecycle tracking for async callbacks.
|
|
464
|
+
*
|
|
465
|
+
* mark() returns a validity checker function. If the host is "unmarked"
|
|
466
|
+
* (e.g. view re-rendered), the checker returns false, preventing stale callbacks.
|
|
467
|
+
*/
|
|
468
|
+
/**
|
|
469
|
+
* Create a mark for tracking async callback validity.
|
|
470
|
+
* Returns a function that checks if the mark is still valid.
|
|
471
|
+
*
|
|
472
|
+
* @param host - Object to store mark state on (typically a view)
|
|
473
|
+
* @param key - Key to track (typically "render" or specific async operation)
|
|
474
|
+
* @returns Checker function that returns true if mark is still valid
|
|
475
|
+
*/
|
|
476
|
+
declare function mark$1(host: object, key: string): () => boolean;
|
|
477
|
+
/**
|
|
478
|
+
* Clear all marks for a host object, invalidating all existing checkers.
|
|
479
|
+
* Called when a view re-renders or is destroyed.
|
|
480
|
+
*
|
|
481
|
+
* @param host - Object whose marks should be cleared
|
|
482
|
+
*/
|
|
483
|
+
declare function unmark$1(host: object): void;
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Safeguard: Proxy-based debug protection for data objects.
|
|
487
|
+
*
|
|
488
|
+
* In DEBUG mode, wraps data objects with Proxy to:
|
|
489
|
+
* 1. Warn when data is read from a different page than where it was set
|
|
490
|
+
* 2. Prevent direct mutation (forces use of State.set/digest)
|
|
491
|
+
* 3. Track access patterns for debugging
|
|
492
|
+
*/
|
|
493
|
+
/**
|
|
494
|
+
* Wrap data with a Proxy for debug-mode protection.
|
|
495
|
+
* Only active when window.__lark_debug is true and Proxy is available.
|
|
496
|
+
*
|
|
497
|
+
* @param data - Data to wrap
|
|
498
|
+
* @param getter - Optional callback when properties are read
|
|
499
|
+
* @param setter - Optional callback when properties are written
|
|
500
|
+
* @param isRoot - Whether this is the root data object
|
|
501
|
+
* @returns Proxied data or original data if debug mode is off
|
|
502
|
+
*/
|
|
503
|
+
declare function safeguard<T>(data: T, getter?: ((key: string) => void) | null, setter?: ((path: string, value: unknown) => void) | null, isRoot?: boolean): T;
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* Cache class with LFU-style eviction.
|
|
507
|
+
* Keys are prefixed with SPLITTER for namespace isolation.
|
|
508
|
+
*
|
|
509
|
+
* @example
|
|
510
|
+
* const cache = new Cache({ maxSize: 20, bufferSize: 5 });
|
|
511
|
+
* cache.set('user', { name: 'Alice' });
|
|
512
|
+
* const user = cache.get('user');
|
|
513
|
+
* cache.has('user'); // true
|
|
514
|
+
* cache.del('user');
|
|
515
|
+
*/
|
|
516
|
+
declare class Cache<T = unknown> {
|
|
517
|
+
/** Cache entries array */
|
|
518
|
+
private entries;
|
|
519
|
+
/** Fast lookup: prefixed key -> entry */
|
|
520
|
+
private lookup;
|
|
521
|
+
/** Buffer size for eviction */
|
|
522
|
+
private readonly bufferSize;
|
|
523
|
+
/** Maximum cache size */
|
|
524
|
+
private readonly maxSize;
|
|
525
|
+
/** Total capacity (maxSize + bufferSize) */
|
|
526
|
+
private readonly capacity;
|
|
527
|
+
/** Callback when entry is removed */
|
|
528
|
+
private readonly onRemove?;
|
|
529
|
+
/** Sort comparator */
|
|
530
|
+
private readonly comparator;
|
|
531
|
+
constructor(options?: CacheOptions<T>);
|
|
532
|
+
/** Prefix a key with SPLITTER for namespace isolation */
|
|
533
|
+
private prefixKey;
|
|
534
|
+
/**
|
|
535
|
+
* Get a cached value by key.
|
|
536
|
+
* Updates frequency and timestamp for cache sorting.
|
|
537
|
+
*/
|
|
538
|
+
get(key: string): T | undefined;
|
|
539
|
+
/**
|
|
540
|
+
* Iterate all cached values.
|
|
541
|
+
*/
|
|
542
|
+
forEach(callback: (value: T | undefined) => void): void;
|
|
543
|
+
/**
|
|
544
|
+
* Set or update a cached value.
|
|
545
|
+
* If key already exists, updates value and increments frequency.
|
|
546
|
+
* If cache exceeds capacity, triggers eviction.
|
|
547
|
+
*/
|
|
548
|
+
set(key: string, value: T): void;
|
|
549
|
+
/**
|
|
550
|
+
* Delete a cached entry.
|
|
551
|
+
*/
|
|
552
|
+
del(key: string): void;
|
|
553
|
+
/**
|
|
554
|
+
* Check if a key exists in cache.
|
|
555
|
+
*/
|
|
556
|
+
has(key: string): boolean;
|
|
557
|
+
/** Get current cache size */
|
|
558
|
+
get size(): number;
|
|
559
|
+
/** Clear all entries */
|
|
560
|
+
clear(): void;
|
|
561
|
+
/** Evict least-used entries from cache */
|
|
562
|
+
private evictEntries;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* Multi-cast event emitter class.
|
|
567
|
+
*
|
|
568
|
+
* @example
|
|
569
|
+
* const emitter = new EventEmitter();
|
|
570
|
+
* emitter.on('change', (data) => console.log(data));
|
|
571
|
+
* emitter.fire('change', { key: 'value' });
|
|
572
|
+
*/
|
|
573
|
+
declare class EventEmitter {
|
|
574
|
+
/** Event listeners: prefixed key -> listener array */
|
|
575
|
+
private listeners;
|
|
576
|
+
/**
|
|
577
|
+
* Bind event listener.
|
|
578
|
+
*/
|
|
579
|
+
on(event: string, handler: AnyFunc): this;
|
|
580
|
+
/**
|
|
581
|
+
* Unbind event listener.
|
|
582
|
+
* If handler is provided, removes only that handler.
|
|
583
|
+
* If no handler, removes all handlers for the event.
|
|
584
|
+
*/
|
|
585
|
+
off(event: string, handler?: AnyFunc): this;
|
|
586
|
+
/**
|
|
587
|
+
* Fire event, execute all bound handlers.
|
|
588
|
+
* Supports executing state management: handlers removed during
|
|
589
|
+
* execution are safely handled.
|
|
590
|
+
*
|
|
591
|
+
* @param event - Event name
|
|
592
|
+
* @param data - Event data (type property added automatically)
|
|
593
|
+
* @param remove - Whether to remove all handlers after firing
|
|
594
|
+
* @param lastToFirst - Whether to execute handlers in reverse order
|
|
595
|
+
*/
|
|
596
|
+
fire(event: string, data?: Record<string, unknown>, remove?: boolean, lastToFirst?: boolean): this;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
/** Mark framework as booted (called from Framework.boot) */
|
|
600
|
+
declare function markBooted(): void;
|
|
601
|
+
/**
|
|
602
|
+
* Observable in-memory data object.
|
|
603
|
+
* Provides get/set/digest/diff/clean methods for cross-view data sharing.
|
|
604
|
+
*/
|
|
605
|
+
declare const State: {
|
|
606
|
+
get<T = unknown>(key?: string): T;
|
|
607
|
+
set(data: Record<string, unknown>, excludes?: Set<string>): typeof State;
|
|
608
|
+
digest(data?: Record<string, unknown>, excludes?: Set<string>): void;
|
|
609
|
+
diff(): Readonly<Record<string, number>>;
|
|
610
|
+
clean(keys: string): {
|
|
611
|
+
ctor: AnyFunc;
|
|
612
|
+
};
|
|
613
|
+
on(event: string, handler: AnyFunc): typeof State;
|
|
614
|
+
off(event: string, handler?: AnyFunc): typeof State;
|
|
615
|
+
fire(event: string, data?: Record<string, unknown>, remove?: boolean): typeof State;
|
|
616
|
+
};
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* Hash-based router with two-phase change confirmation.
|
|
620
|
+
*
|
|
621
|
+
* @example
|
|
622
|
+
* Router.to('/list', { page: 2 });
|
|
623
|
+
* const loc = Router.parse();
|
|
624
|
+
* const diff = Router.diff();
|
|
625
|
+
*/
|
|
626
|
+
declare const Router: {
|
|
627
|
+
/** Parse href into Location object */
|
|
628
|
+
parse(href?: string): Location;
|
|
629
|
+
/** Compute diff between current and previous location */
|
|
630
|
+
diff(): LocationDiff | undefined;
|
|
631
|
+
/** Navigate to new URL */
|
|
632
|
+
to(pathOrParams: string | Record<string, unknown>, params?: Record<string, unknown>, replace?: boolean, silent?: boolean): void;
|
|
633
|
+
/** Join path segments */
|
|
634
|
+
join(...paths: string[]): string;
|
|
635
|
+
/** Bind event listener */
|
|
636
|
+
on(event: string, handler: AnyFunc): typeof Router;
|
|
637
|
+
/** Unbind event listener */
|
|
638
|
+
off(event: string, handler?: AnyFunc): typeof Router;
|
|
639
|
+
/** Fire event */
|
|
640
|
+
fire(event: string, data?: Record<string, unknown>, remove?: boolean): typeof Router;
|
|
641
|
+
/** Internal: bind hashchange (called by Framework.boot) */
|
|
642
|
+
_bind(): void;
|
|
643
|
+
/** Internal: set framework config */
|
|
644
|
+
_setConfig(cfg: FrameworkConfig): void;
|
|
645
|
+
/** Internal: notify hash change (for programmatic trigger) */
|
|
646
|
+
notify?(e?: Event): void;
|
|
647
|
+
};
|
|
648
|
+
/** Mark framework as booted (called by Framework.boot) */
|
|
649
|
+
declare function markRouterBooted(): void;
|
|
650
|
+
|
|
651
|
+
/**
|
|
652
|
+
* Base View class.
|
|
653
|
+
* Views are created via View.extend() and mounted by Frame.
|
|
654
|
+
*
|
|
655
|
+
*/
|
|
656
|
+
declare class View {
|
|
657
|
+
/** View ID (same as owner frame ID) */
|
|
658
|
+
id: string;
|
|
659
|
+
/** Owner frame */
|
|
660
|
+
owner: FrameLike | number;
|
|
661
|
+
/** Updater instance */
|
|
662
|
+
updater: UpdaterLike;
|
|
663
|
+
/** Signature: > 0 means active, incremented on render, 0 = destroyed */
|
|
664
|
+
signature: number;
|
|
665
|
+
/** Whether rendered at least once */
|
|
666
|
+
rendered?: boolean;
|
|
667
|
+
/** Whether view has template */
|
|
668
|
+
tmpl?: AnyFunc | string;
|
|
669
|
+
/** Location observation config */
|
|
670
|
+
locationObserved: ViewLocationObserved;
|
|
671
|
+
/** Observed state keys */
|
|
672
|
+
observedStateKeys?: string[];
|
|
673
|
+
/** Resource map */
|
|
674
|
+
resources: ViewResourceMap;
|
|
675
|
+
/** Selector event map: eventType -> handler name list */
|
|
676
|
+
eventSelectorMap: ViewEventSelectorMap;
|
|
677
|
+
/** Event object map: eventType -> bitmask */
|
|
678
|
+
eventObjectMap: ViewEventObjectMap;
|
|
679
|
+
/** Global event list */
|
|
680
|
+
globalEventList: ViewGlobalEventEntry[];
|
|
681
|
+
/** Assign method reference */
|
|
682
|
+
assignMethod?: AnyFunc;
|
|
683
|
+
/** Whether endUpdate pending */
|
|
684
|
+
endUpdatePending?: number;
|
|
685
|
+
/** Internal event storage */
|
|
686
|
+
private _events;
|
|
687
|
+
/**
|
|
688
|
+
* Initialize view (called by Frame when mounting).
|
|
689
|
+
*/
|
|
690
|
+
init(): void;
|
|
691
|
+
/**
|
|
692
|
+
* Render view template (called by Frame after init).
|
|
693
|
+
* Wrapped by View_WrapMethod to manage signature + resources.
|
|
694
|
+
*
|
|
695
|
+
* Default implementation calls updater.digest() which:
|
|
696
|
+
* 1. Executes the template function with current data
|
|
697
|
+
* 2. Runs VDOM diff against previous DOM
|
|
698
|
+
* 3. Applies DOM operations
|
|
699
|
+
* 4. Calls endUpdate to mount child frames
|
|
700
|
+
*
|
|
701
|
+
*/
|
|
702
|
+
render(): void;
|
|
703
|
+
on(event: string, handler: AnyFunc): this;
|
|
704
|
+
off(event: string, handler?: AnyFunc): this;
|
|
705
|
+
fire(event: string, data?: Record<string, unknown>, remove?: boolean, lastToFirst?: boolean): this;
|
|
706
|
+
/**
|
|
707
|
+
* Notify view that HTML update is about to begin.
|
|
708
|
+
* Unmounts child frames in the update zone.
|
|
709
|
+
*/
|
|
710
|
+
beginUpdate(id?: string): void;
|
|
711
|
+
/**
|
|
712
|
+
* Notify view that HTML update has ended.
|
|
713
|
+
* Mounts child frames in the update zone and runs deferred invokes.
|
|
714
|
+
*/
|
|
715
|
+
endUpdate(id?: string, inner?: boolean): void;
|
|
716
|
+
/**
|
|
717
|
+
* Wrap an async callback to check view signature before executing.
|
|
718
|
+
* If the view has been re-rendered or destroyed, the callback is skipped.
|
|
719
|
+
*/
|
|
720
|
+
wrapAsync<Fn extends AnyFunc>(fn: Fn, context?: unknown): (...args: Parameters<Fn>) => ReturnType<Fn> | undefined;
|
|
721
|
+
/**
|
|
722
|
+
* Observe location parameters or path changes.
|
|
723
|
+
* When observed keys change, render() is called automatically.
|
|
724
|
+
*/
|
|
725
|
+
observeLocation(params: string | string[] | Record<string, unknown>, observePath?: boolean): void;
|
|
726
|
+
/**
|
|
727
|
+
* Observe State data keys for changes.
|
|
728
|
+
* When observed keys change via State.digest(), render() is called.
|
|
729
|
+
*/
|
|
730
|
+
observeState(observedKeys: string | string[]): void;
|
|
731
|
+
/**
|
|
732
|
+
* Capture (register) a resource under a key.
|
|
733
|
+
* If a resource already exists at that key, it's destroyed first.
|
|
734
|
+
* When destroyOnRender=true, the resource is destroyed on next render call.
|
|
735
|
+
*/
|
|
736
|
+
capture(key: string, resource?: unknown, destroyOnRender?: boolean): unknown;
|
|
737
|
+
/**
|
|
738
|
+
* Release a captured resource.
|
|
739
|
+
* If destroy=true, calls the resource's destroy() method.
|
|
740
|
+
*/
|
|
741
|
+
release(key: string, destroy?: boolean): unknown;
|
|
742
|
+
/**
|
|
743
|
+
* Set up a leave confirmation for route changes and page unload.
|
|
744
|
+
*/
|
|
745
|
+
leaveTip(message: string, condition: () => boolean): void;
|
|
746
|
+
/** Collected ctors from mixins */
|
|
747
|
+
static ctors?: AnyFunc[];
|
|
748
|
+
/**
|
|
749
|
+
* Extend View to create a new View subclass.
|
|
750
|
+
*
|
|
751
|
+
* Supports:
|
|
752
|
+
* - props.ctor: constructor-like init (called with initParams + {node, deep})
|
|
753
|
+
* - props.mixins: array of mixin objects
|
|
754
|
+
* - Event method patterns: `'name<click>'` etc.
|
|
755
|
+
*/
|
|
756
|
+
static extend(props?: ThisType<ViewInstance> & Record<string, unknown>, statics?: Record<string, unknown>): typeof View;
|
|
757
|
+
/**
|
|
758
|
+
* Merge mixins into View prototype.
|
|
759
|
+
*/
|
|
760
|
+
static merge(...mixins: Record<string, unknown>[]): typeof View;
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
/**
|
|
764
|
+
* Frame (View Frame) class for view lifecycle management.
|
|
765
|
+
* Each frame owns a view and manages child frames.
|
|
766
|
+
*
|
|
767
|
+
*/
|
|
768
|
+
declare class Frame extends EventEmitter implements FrameLike {
|
|
769
|
+
/** Frame ID (same as owner DOM element ID) */
|
|
770
|
+
readonly id: string;
|
|
771
|
+
/** Parent Frame ID */
|
|
772
|
+
private _parentId;
|
|
773
|
+
get parentId(): string | undefined;
|
|
774
|
+
/** Children map: id -> id */
|
|
775
|
+
childrenMap: FrameChildrenMap;
|
|
776
|
+
/** Children count */
|
|
777
|
+
childrenCount: number;
|
|
778
|
+
/** Ready count (children that have fired 'created') */
|
|
779
|
+
readyCount: number;
|
|
780
|
+
/** Ready map: id -> 1 */
|
|
781
|
+
readyMap: FrameReadyMap;
|
|
782
|
+
/** View instance */
|
|
783
|
+
viewInstance?: ViewInstance;
|
|
784
|
+
/** Get view instance (read-only) */
|
|
785
|
+
get view(): ViewInstance | undefined;
|
|
786
|
+
/** Invoke list for deferred method calls */
|
|
787
|
+
invokeList: FrameInvokeEntry[];
|
|
788
|
+
/** Signature for async operation tracking */
|
|
789
|
+
signature: number;
|
|
790
|
+
/** Whether view has altered */
|
|
791
|
+
hasAltered: number;
|
|
792
|
+
/** Whether view is destroyed */
|
|
793
|
+
destroyed: number;
|
|
794
|
+
/** View path (lark-view attribute value) */
|
|
795
|
+
viewPath?: string;
|
|
796
|
+
/** Original template before mount */
|
|
797
|
+
originalTemplate?: string;
|
|
798
|
+
/** Hold fire created flag */
|
|
799
|
+
holdFireCreated: number;
|
|
800
|
+
/** Children created flag */
|
|
801
|
+
childrenCreated: number;
|
|
802
|
+
/** Children alter flag */
|
|
803
|
+
childrenAlter: number;
|
|
804
|
+
constructor(id: string, parentId?: string);
|
|
805
|
+
/**
|
|
806
|
+
* Mount a view to this frame.
|
|
807
|
+
*
|
|
808
|
+
* Complete flow:
|
|
809
|
+
* 1. Parse viewPath, translate query params from parent
|
|
810
|
+
* 2. Unmount current view
|
|
811
|
+
* 3. Load View class (via require or provided ViewClass)
|
|
812
|
+
* 4. View_Prepare (scan event methods)
|
|
813
|
+
* 5. Create View instance
|
|
814
|
+
* 6. View_DelegateEvents (bind DOM events)
|
|
815
|
+
* 7. Call view.init()
|
|
816
|
+
* 8. If view has tmpl, call render via Updater
|
|
817
|
+
* 9. If no tmpl, call endUpdate directly
|
|
818
|
+
*/
|
|
819
|
+
mountView(viewPath: string, viewInitParams?: Record<string, unknown>): void;
|
|
820
|
+
/**
|
|
821
|
+
* Internal: actually mount the view after class is loaded.
|
|
822
|
+
*/
|
|
823
|
+
doMountView(ViewClass: typeof View, params: Record<string, string>, node: HTMLElement, sign: number): void;
|
|
824
|
+
/**
|
|
825
|
+
* Unmount current view.
|
|
826
|
+
*/
|
|
827
|
+
unmountView(): void;
|
|
828
|
+
/**
|
|
829
|
+
* Mount a child frame.
|
|
830
|
+
*/
|
|
831
|
+
mountFrame(frameId: string, viewPath: string, viewInitParams?: Record<string, unknown>): FrameLike;
|
|
832
|
+
/**
|
|
833
|
+
* Unmount a child frame.
|
|
834
|
+
*/
|
|
835
|
+
unmountFrame(id?: string, _inner?: boolean): void;
|
|
836
|
+
/**
|
|
837
|
+
* Mount all views in a zone.
|
|
838
|
+
*/
|
|
839
|
+
mountZone(zoneId?: string, _inner?: boolean): void;
|
|
840
|
+
/**
|
|
841
|
+
* Unmount all views in a zone.
|
|
842
|
+
*/
|
|
843
|
+
unmountZone(zoneId?: string, _inner?: boolean): void;
|
|
844
|
+
/**
|
|
845
|
+
* Get all child frame IDs.
|
|
846
|
+
*/
|
|
847
|
+
children(): string[];
|
|
848
|
+
/**
|
|
849
|
+
* Get parent frame at given level.
|
|
850
|
+
* @param level - How many levels up (default 1)
|
|
851
|
+
*/
|
|
852
|
+
parent(level?: number): Frame | undefined;
|
|
853
|
+
/**
|
|
854
|
+
* Invoke a method on the view.
|
|
855
|
+
*/
|
|
856
|
+
invoke(name: string, args?: unknown[]): unknown;
|
|
857
|
+
/** Get frame by ID */
|
|
858
|
+
static get(id: string): Frame | undefined;
|
|
859
|
+
/** Get all frames */
|
|
860
|
+
static getAll(): Map<string, Frame>;
|
|
861
|
+
/** Get or create root frame */
|
|
862
|
+
static root(rootId?: string): Frame;
|
|
863
|
+
/** Bind event listener (static) */
|
|
864
|
+
static on(event: string, handler: AnyFunc): typeof Frame;
|
|
865
|
+
/** Unbind event listener (static) */
|
|
866
|
+
static off(event: string, handler?: AnyFunc): typeof Frame;
|
|
867
|
+
/** Fire event (static) */
|
|
868
|
+
static fire(event: string, data?: Record<string, unknown>): void;
|
|
869
|
+
}
|
|
870
|
+
/**
|
|
871
|
+
* Register a View class for a given view path.
|
|
872
|
+
* Called after module loading completes.
|
|
873
|
+
*/
|
|
874
|
+
declare function registerViewClass(viewPath: string, ViewClass: typeof View): void;
|
|
875
|
+
|
|
876
|
+
/**
|
|
877
|
+
* Unmount frames within a DOM node.
|
|
878
|
+
*/
|
|
879
|
+
declare function vdomUnmountFrames(frame: FrameLike, node: ChildNode): void;
|
|
880
|
+
/**
|
|
881
|
+
* Parse HTML string into a DOM element.
|
|
882
|
+
* Handles special elements (table, SVG, MathML) with wrapper elements.
|
|
883
|
+
*/
|
|
884
|
+
declare function vdomGetNode(html: string, refNode: Element): Element;
|
|
885
|
+
/**
|
|
886
|
+
* Get compare key for a DOM node (for keyed diff).
|
|
887
|
+
* Uses id, lark-key (static key), or lark-view path.
|
|
888
|
+
*/
|
|
889
|
+
declare function vdomGetCompareKey(node: ChildNode): string | undefined;
|
|
890
|
+
/**
|
|
891
|
+
* Special diff for form elements (value, checked, selected).
|
|
892
|
+
*/
|
|
893
|
+
declare function vdomSpecialDiff(oldNode: ChildNode, newNode: ChildNode): number;
|
|
894
|
+
/**
|
|
895
|
+
* Set attributes from new element onto old element, tracking changes in ref.
|
|
896
|
+
*/
|
|
897
|
+
declare function vdomSetAttributes(oldNode: Element, newNode: Element, ref: VDomRef, keepId?: boolean): void;
|
|
898
|
+
/**
|
|
899
|
+
* Set child nodes from new parent onto old parent using keyed diff algorithm.
|
|
900
|
+
*/
|
|
901
|
+
declare function vdomSetChildNodes(oldParent: Element, newParent: Element, ref: VDomRef, frame: FrameLike, keys_?: Record<string, number>): void;
|
|
902
|
+
/**
|
|
903
|
+
* Diff two DOM nodes and apply changes.
|
|
904
|
+
*/
|
|
905
|
+
declare function vdomSetNode(oldNode: ChildNode, newNode: ChildNode, oldParent: Element, ref: VDomRef, frame: FrameLike, keys_?: Record<string, number>): void;
|
|
906
|
+
/**
|
|
907
|
+
* Create an empty VDomRef for tracking diff operations.
|
|
908
|
+
*/
|
|
909
|
+
declare function createVdomRef(): VDomRef;
|
|
910
|
+
/**
|
|
911
|
+
* Apply VDOM diff operations to the DOM.
|
|
912
|
+
*/
|
|
913
|
+
declare function applyVdomOps(ops: VDomOp[]): void;
|
|
914
|
+
/**
|
|
915
|
+
* Apply ID updates from VDOM diff.
|
|
916
|
+
*/
|
|
917
|
+
declare function applyIdUpdates(updates: [Element, string][]): void;
|
|
918
|
+
/** Encode value for safe HTML output */
|
|
919
|
+
declare function encodeHTML(v: unknown): string;
|
|
920
|
+
/** Safe string conversion */
|
|
921
|
+
declare function encodeSafe(v: unknown): string;
|
|
922
|
+
/** URI-encode a value with extra character encoding */
|
|
923
|
+
declare function encodeURIExtra(v: unknown): string;
|
|
924
|
+
/** Quote-encode a value for attribute use */
|
|
925
|
+
declare function encodeQ(v: unknown): string;
|
|
926
|
+
|
|
927
|
+
/**
|
|
928
|
+
* Updater class for view data binding.
|
|
929
|
+
* Manages view-local data with change detection and VDOM diff triggering.
|
|
930
|
+
*
|
|
931
|
+
*/
|
|
932
|
+
declare class Updater implements UpdaterLike {
|
|
933
|
+
/** View ID (same as owner frame ID) */
|
|
934
|
+
private viewId;
|
|
935
|
+
/** Current data object */
|
|
936
|
+
private data;
|
|
937
|
+
/** Ref data for template rendering */
|
|
938
|
+
refData: Record<string, unknown>;
|
|
939
|
+
/** Changed keys in current digest cycle */
|
|
940
|
+
private changedKeys;
|
|
941
|
+
/** Whether data has changed since last digest */
|
|
942
|
+
private hasChangedFlag;
|
|
943
|
+
/** Digesting queue: supports re-digest during digest */
|
|
944
|
+
private digestingQueue;
|
|
945
|
+
/** Snapshot JSON string for altered() detection */
|
|
946
|
+
private snapshotJson;
|
|
947
|
+
constructor(viewId: string);
|
|
948
|
+
/**
|
|
949
|
+
* Get data by key.
|
|
950
|
+
* Returns entire data object if key is omitted.
|
|
951
|
+
*/
|
|
952
|
+
get<T = unknown>(key?: string): T;
|
|
953
|
+
/**
|
|
954
|
+
* Set data, tracking changed keys.
|
|
955
|
+
* Returns this for chaining.
|
|
956
|
+
*/
|
|
957
|
+
set(data: Record<string, unknown>, excludes?: Set<string>): this;
|
|
958
|
+
/**
|
|
959
|
+
* Detect changes and trigger VDOM re-render.
|
|
960
|
+
*
|
|
961
|
+
* The core rendering pipeline:
|
|
962
|
+
* 1. Set data if provided
|
|
963
|
+
* 2. If changed, run VDOM diff (template → new DOM → diff against old DOM)
|
|
964
|
+
* 3. Apply DOM operations
|
|
965
|
+
* 4. Apply ID updates
|
|
966
|
+
* 5. Call endUpdate on views that need re-rendering
|
|
967
|
+
* 6. Support re-digest during digest via queue
|
|
968
|
+
*/
|
|
969
|
+
digest(data?: Record<string, unknown>, excludes?: Set<string>, callback?: () => void): void;
|
|
970
|
+
/**
|
|
971
|
+
* Core digest execution.
|
|
972
|
+
*/
|
|
973
|
+
private runDigest;
|
|
974
|
+
/**
|
|
975
|
+
* Save a snapshot of current data for altered() detection.
|
|
976
|
+
*/
|
|
977
|
+
snapshot(): this;
|
|
978
|
+
/**
|
|
979
|
+
* Check if data has changed since last snapshot.
|
|
980
|
+
*/
|
|
981
|
+
altered(): boolean | undefined;
|
|
982
|
+
/**
|
|
983
|
+
* Translate data references (SPLITTER-prefixed values).
|
|
984
|
+
*/
|
|
985
|
+
translate(data: unknown): unknown;
|
|
986
|
+
/**
|
|
987
|
+
* Parse expression with data context.
|
|
988
|
+
*/
|
|
989
|
+
parse(expr: string): unknown;
|
|
990
|
+
/**
|
|
991
|
+
* Get changed keys (for external inspection).
|
|
992
|
+
*/
|
|
993
|
+
getChangedKeys(): Readonly<Record<string, number>>;
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
/**
|
|
997
|
+
* Bag wraps API response data with convenient access methods.
|
|
998
|
+
*/
|
|
999
|
+
declare class Bag {
|
|
1000
|
+
/** Bag data */
|
|
1001
|
+
data: Record<string, unknown>;
|
|
1002
|
+
/** Internal cache info */
|
|
1003
|
+
cacheInfo?: ServiceCacheInfo;
|
|
1004
|
+
constructor(data?: Record<string, unknown>);
|
|
1005
|
+
/** Get a value from bag data */
|
|
1006
|
+
get<T = unknown>(key: string): T;
|
|
1007
|
+
/** Set a value in bag data */
|
|
1008
|
+
set(keyOrData: string | Record<string, unknown> | ServiceMetaEntry, value?: unknown): this;
|
|
1009
|
+
}
|
|
1010
|
+
interface ServiceConstructor {
|
|
1011
|
+
new (): ServiceInstance;
|
|
1012
|
+
add(attrs: ServiceMetaEntry | ServiceMetaEntry[]): void;
|
|
1013
|
+
meta(attrs: string | Record<string, unknown>): ServiceMetaEntry;
|
|
1014
|
+
create(attrs: Record<string, unknown>): Bag;
|
|
1015
|
+
get(attrs: Record<string, unknown>, createNew?: boolean): {
|
|
1016
|
+
entity: Bag;
|
|
1017
|
+
needsUpdate: boolean;
|
|
1018
|
+
};
|
|
1019
|
+
cached(attrs: Record<string, unknown>): Bag | undefined;
|
|
1020
|
+
clear(names: string | string[]): void;
|
|
1021
|
+
on(event: string, handler: AnyFunc): void;
|
|
1022
|
+
off(event: string, handler?: AnyFunc): void;
|
|
1023
|
+
fire(event: string, data?: Record<string, unknown>): void;
|
|
1024
|
+
extend(newSyncFn: (bag: Bag, callback: () => void) => void, newCacheMax?: number, newCacheBuffer?: number): ServiceConstructor;
|
|
1025
|
+
_internals: ServiceInternals;
|
|
1026
|
+
}
|
|
1027
|
+
interface ServiceInstance {
|
|
1028
|
+
id: string;
|
|
1029
|
+
[key: string]: unknown;
|
|
1030
|
+
_emitter: EventEmitter;
|
|
1031
|
+
_internals: ServiceInternals;
|
|
1032
|
+
_type: ServiceStaticsInternal;
|
|
1033
|
+
all(attrs: string | Record<string, unknown> | (string | Record<string, unknown>)[], done: AnyFunc): ServiceInstance;
|
|
1034
|
+
one(attrs: string | Record<string, unknown> | (string | Record<string, unknown>)[], done: AnyFunc): ServiceInstance;
|
|
1035
|
+
save(attrs: string | Record<string, unknown> | (string | Record<string, unknown>)[], done: AnyFunc): ServiceInstance;
|
|
1036
|
+
enqueue(callback: AnyFunc): ServiceInstance;
|
|
1037
|
+
dequeue(...args: unknown[]): void;
|
|
1038
|
+
destroy(): void;
|
|
1039
|
+
on(event: string, handler: AnyFunc): ServiceInstance;
|
|
1040
|
+
off(event: string, handler?: AnyFunc): ServiceInstance;
|
|
1041
|
+
fire(event: string, data?: Record<string, unknown>): ServiceInstance;
|
|
1042
|
+
}
|
|
1043
|
+
interface ServiceInternals {
|
|
1044
|
+
metas: Record<string, ServiceMetaEntry>;
|
|
1045
|
+
bagCache: Cache<Bag>;
|
|
1046
|
+
pendingCacheKeys: Record<string, PendingCacheEntry>;
|
|
1047
|
+
syncFn: (bag: Bag, callback: () => void) => void;
|
|
1048
|
+
staticEmitter: EventEmitter;
|
|
1049
|
+
}
|
|
1050
|
+
/** Internal type for serviceType object (static methods) */
|
|
1051
|
+
interface ServiceStaticsInternal {
|
|
1052
|
+
add(attrs: ServiceMetaEntry | ServiceMetaEntry[]): void;
|
|
1053
|
+
meta(attrs: string | Record<string, unknown>): ServiceMetaEntry;
|
|
1054
|
+
create(attrs: Record<string, unknown>): Bag;
|
|
1055
|
+
get(attrs: Record<string, unknown>, createNew?: boolean): {
|
|
1056
|
+
entity: Bag;
|
|
1057
|
+
needsUpdate: boolean;
|
|
1058
|
+
};
|
|
1059
|
+
cached(attrs: Record<string, unknown>): Bag | undefined;
|
|
1060
|
+
clear(names: string | string[]): void;
|
|
1061
|
+
on(event: string, handler: AnyFunc): void;
|
|
1062
|
+
off(event: string, handler?: AnyFunc): void;
|
|
1063
|
+
fire(event: string, data?: Record<string, unknown>): void;
|
|
1064
|
+
extend(newSyncFn: (bag: Bag, callback: () => void) => void, newCacheMax?: number, newCacheBuffer?: number): ServiceConstructor;
|
|
1065
|
+
}
|
|
1066
|
+
/**
|
|
1067
|
+
* Default Service base class.
|
|
1068
|
+
* Use Service.extend() to create a usable subclass with a sync function.
|
|
1069
|
+
*/
|
|
1070
|
+
declare const Service: ServiceConstructor;
|
|
1071
|
+
|
|
1072
|
+
/**
|
|
1073
|
+
* DOM event delegation system.
|
|
1074
|
+
* Delegates events to document body for performance.
|
|
1075
|
+
*
|
|
1076
|
+
*/
|
|
1077
|
+
declare const EventDelegator: {
|
|
1078
|
+
/**
|
|
1079
|
+
* Bind a DOM event type to document body.
|
|
1080
|
+
*/
|
|
1081
|
+
bind(eventType: string, hasSelector?: boolean): void;
|
|
1082
|
+
/**
|
|
1083
|
+
* Unbind a DOM event type from document body.
|
|
1084
|
+
*/
|
|
1085
|
+
unbind(eventType: string, hasSelector?: boolean): void;
|
|
1086
|
+
/**
|
|
1087
|
+
* Clean up range events for a destroyed view.
|
|
1088
|
+
*/
|
|
1089
|
+
clearRangeEvents(viewId: string): void;
|
|
1090
|
+
/**
|
|
1091
|
+
* Set the frame getter function (called by Framework.boot).
|
|
1092
|
+
*/
|
|
1093
|
+
setFrameGetter(getter: (id: string) => FrameLike | undefined): void;
|
|
1094
|
+
/**
|
|
1095
|
+
* Get next element GUID.
|
|
1096
|
+
*/
|
|
1097
|
+
nextElementGuid(): number;
|
|
1098
|
+
};
|
|
1099
|
+
|
|
1100
|
+
/**
|
|
1101
|
+
* Queue a function for deferred, chunked execution.
|
|
1102
|
+
*
|
|
1103
|
+
* @param fn - Function to execute (wrapped in try-catch automatically)
|
|
1104
|
+
* @param args - Arguments array to pass to the function
|
|
1105
|
+
* @param context - `this` context for the function call
|
|
1106
|
+
*/
|
|
1107
|
+
declare function task(fn: AnyFunc, args?: unknown[], context?: unknown): void;
|
|
1108
|
+
/**
|
|
1109
|
+
* Fire a custom DOM event on a target element.
|
|
1110
|
+
*/
|
|
1111
|
+
declare function dispatchEvent(target: EventTarget, eventType: string, eventInit?: CustomEventInit): void;
|
|
1112
|
+
/**
|
|
1113
|
+
* Base class that can be extended by any object needing EventEmitter.
|
|
1114
|
+
*/
|
|
1115
|
+
declare class Base extends EventEmitter {
|
|
1116
|
+
}
|
|
1117
|
+
/**
|
|
1118
|
+
* Load modules via the configured require function.
|
|
1119
|
+
*/
|
|
1120
|
+
declare function use(names: string | string[], callback?: (...modules: unknown[]) => void): void;
|
|
1121
|
+
/**
|
|
1122
|
+
* Wait for all views in a zone to be rendered.
|
|
1123
|
+
*/
|
|
1124
|
+
declare function waitZoneViewsRendered(viewId: string, timeout?: number): Promise<number>;
|
|
1125
|
+
/**
|
|
1126
|
+
* Main framework object.
|
|
1127
|
+
* Provides boot, config, and all global utility methods.
|
|
1128
|
+
*/
|
|
1129
|
+
declare const Framework: {
|
|
1130
|
+
/**
|
|
1131
|
+
* Get or set framework configuration.
|
|
1132
|
+
*/
|
|
1133
|
+
config(cfg?: FrameworkConfig | string): FrameworkConfig | unknown;
|
|
1134
|
+
/**
|
|
1135
|
+
* Boot the framework.
|
|
1136
|
+
*/
|
|
1137
|
+
boot(cfg?: FrameworkConfig): void;
|
|
1138
|
+
/** Whether framework has booted */
|
|
1139
|
+
isBooted(): boolean;
|
|
1140
|
+
/** Mark async callback validity tracker */
|
|
1141
|
+
mark: typeof mark$1;
|
|
1142
|
+
/** Unmark (invalidate) async callbacks */
|
|
1143
|
+
unmark: typeof unmark$1;
|
|
1144
|
+
/** Fire a custom DOM event on a target */
|
|
1145
|
+
dispatch: typeof dispatchEvent;
|
|
1146
|
+
/** Execute function in try-catch, ignoring errors */
|
|
1147
|
+
task: typeof task;
|
|
1148
|
+
/** Promise-based setTimeout */
|
|
1149
|
+
delay(time: number): Promise<void>;
|
|
1150
|
+
/** Load modules via configured require */
|
|
1151
|
+
use: typeof use;
|
|
1152
|
+
/** Wait for zone views to be rendered */
|
|
1153
|
+
waitZoneViewsRendered: typeof waitZoneViewsRendered;
|
|
1154
|
+
WAIT_OK: number;
|
|
1155
|
+
WAIT_TIMEOUT_OR_UNFOUND: number;
|
|
1156
|
+
/**
|
|
1157
|
+
* Convert array to hash map.
|
|
1158
|
+
*/
|
|
1159
|
+
toMap: typeof toMap;
|
|
1160
|
+
/**
|
|
1161
|
+
* Execute function in try-catch.
|
|
1162
|
+
*/
|
|
1163
|
+
toTry: typeof funcWithTry;
|
|
1164
|
+
/**
|
|
1165
|
+
* Convert path + params to URL string.
|
|
1166
|
+
*/
|
|
1167
|
+
toUrl: typeof toUri;
|
|
1168
|
+
/**
|
|
1169
|
+
* Parse URI string into path and params.
|
|
1170
|
+
*/
|
|
1171
|
+
parseUrl: typeof parseUri;
|
|
1172
|
+
/**
|
|
1173
|
+
* Mix properties from source to target.
|
|
1174
|
+
*/
|
|
1175
|
+
mix: typeof assign;
|
|
1176
|
+
/**
|
|
1177
|
+
* Check if object has own property.
|
|
1178
|
+
*/
|
|
1179
|
+
has: typeof has;
|
|
1180
|
+
/**
|
|
1181
|
+
* Get object keys.
|
|
1182
|
+
*/
|
|
1183
|
+
keys: typeof keys;
|
|
1184
|
+
/**
|
|
1185
|
+
* Check if node A is inside node B.
|
|
1186
|
+
*/
|
|
1187
|
+
inside: typeof nodeInside;
|
|
1188
|
+
/**
|
|
1189
|
+
* Get element by ID (shorthand for document.getElementById).
|
|
1190
|
+
*/
|
|
1191
|
+
node: typeof getById;
|
|
1192
|
+
/**
|
|
1193
|
+
* Apply CSS style.
|
|
1194
|
+
*/
|
|
1195
|
+
applyStyle: typeof applyStyle;
|
|
1196
|
+
/**
|
|
1197
|
+
* Generate globally unique ID.
|
|
1198
|
+
*/
|
|
1199
|
+
guid: typeof generateId;
|
|
1200
|
+
/**
|
|
1201
|
+
* Proxy-based debug guard.
|
|
1202
|
+
*/
|
|
1203
|
+
guard: typeof safeguard;
|
|
1204
|
+
/**
|
|
1205
|
+
* Cache class.
|
|
1206
|
+
*/
|
|
1207
|
+
Cache: typeof Cache;
|
|
1208
|
+
/**
|
|
1209
|
+
* Ensure element has an ID.
|
|
1210
|
+
*/
|
|
1211
|
+
nodeId(element: HTMLElement): string;
|
|
1212
|
+
/**
|
|
1213
|
+
* Base class with EventEmitter.
|
|
1214
|
+
*/
|
|
1215
|
+
Base: typeof Base;
|
|
1216
|
+
/** Router module */
|
|
1217
|
+
Router: {
|
|
1218
|
+
parse(href?: string): Location;
|
|
1219
|
+
diff(): LocationDiff | undefined;
|
|
1220
|
+
to(pathOrParams: string | Record<string, unknown>, params?: Record<string, unknown>, replace?: boolean, silent?: boolean): void;
|
|
1221
|
+
join(...paths: string[]): string;
|
|
1222
|
+
on(event: string, handler: AnyFunc): typeof Router;
|
|
1223
|
+
off(event: string, handler?: AnyFunc): typeof Router;
|
|
1224
|
+
fire(event: string, data?: Record<string, unknown>, remove?: boolean): typeof Router;
|
|
1225
|
+
_bind(): void;
|
|
1226
|
+
_setConfig(cfg: FrameworkConfig): void;
|
|
1227
|
+
notify?(e?: Event): void;
|
|
1228
|
+
};
|
|
1229
|
+
/** State module */
|
|
1230
|
+
State: {
|
|
1231
|
+
get<T = unknown>(key?: string): T;
|
|
1232
|
+
set(data: Record<string, unknown>, excludes?: Set<string>): typeof State;
|
|
1233
|
+
digest(data?: Record<string, unknown>, excludes?: Set<string>): void;
|
|
1234
|
+
diff(): Readonly<Record<string, number>>;
|
|
1235
|
+
clean(keys: string): {
|
|
1236
|
+
ctor: AnyFunc;
|
|
1237
|
+
};
|
|
1238
|
+
on(event: string, handler: AnyFunc): typeof State;
|
|
1239
|
+
off(event: string, handler?: AnyFunc): typeof State;
|
|
1240
|
+
fire(event: string, data?: Record<string, unknown>, remove?: boolean): typeof State;
|
|
1241
|
+
};
|
|
1242
|
+
/** View class */
|
|
1243
|
+
View: typeof View;
|
|
1244
|
+
/** Frame class */
|
|
1245
|
+
Frame: typeof Frame;
|
|
1246
|
+
};
|
|
1247
|
+
|
|
1248
|
+
/**
|
|
1249
|
+
* @lark/framework Store
|
|
1250
|
+
*
|
|
1251
|
+
* Reactive state management with Proxy-based dependency tracking.
|
|
1252
|
+
* Adapted for Lark / React / Node.js.
|
|
1253
|
+
*
|
|
1254
|
+
* Core concepts:
|
|
1255
|
+
* - createState: Proxy-based deep reactive state
|
|
1256
|
+
* - track/trigger/clear: publish-subscribe dependency tracking
|
|
1257
|
+
* - defineStore: declarative store definition with platform adapters
|
|
1258
|
+
* - cell/observeCell: lightweight standalone reactive cells
|
|
1259
|
+
*/
|
|
1260
|
+
|
|
1261
|
+
/** Reactive proxy object — all string keys map to unknown values */
|
|
1262
|
+
type ProxyObject = Record<string, unknown>;
|
|
1263
|
+
interface Task {
|
|
1264
|
+
cb: AnyFunc;
|
|
1265
|
+
params?: Record<string, unknown>;
|
|
1266
|
+
}
|
|
1267
|
+
interface SchedulerObject {
|
|
1268
|
+
add: (tasks: Task[]) => void;
|
|
1269
|
+
clear: () => void;
|
|
1270
|
+
delete: (tasks: Task[]) => void;
|
|
1271
|
+
}
|
|
1272
|
+
type Scheduler = SchedulerObject | ((cb: AnyFunc, payload: unknown) => void);
|
|
1273
|
+
interface StateConfig {
|
|
1274
|
+
belong?: string;
|
|
1275
|
+
linkKeys?: string;
|
|
1276
|
+
shallow?: boolean;
|
|
1277
|
+
}
|
|
1278
|
+
interface StoreConfig {
|
|
1279
|
+
platform?: Platform;
|
|
1280
|
+
scheduler?: Scheduler;
|
|
1281
|
+
}
|
|
1282
|
+
interface ObservePayload {
|
|
1283
|
+
key: string;
|
|
1284
|
+
alias?: string;
|
|
1285
|
+
cb?: (changedMap: Record<string, unknown>) => void;
|
|
1286
|
+
lazy?: boolean;
|
|
1287
|
+
transform?: (val: unknown) => Record<string, unknown>;
|
|
1288
|
+
}
|
|
1289
|
+
declare enum StoreStatus {
|
|
1290
|
+
BEFORE_CREATE = 0,
|
|
1291
|
+
CREATED = 1,
|
|
1292
|
+
ACTIVE = 2,
|
|
1293
|
+
DESTROYED = 3
|
|
1294
|
+
}
|
|
1295
|
+
declare enum Platform {
|
|
1296
|
+
Lark = "lark",
|
|
1297
|
+
React = "react",
|
|
1298
|
+
Node = "node"
|
|
1299
|
+
}
|
|
1300
|
+
declare const cloneData: <T>(data: T) => T;
|
|
1301
|
+
declare class Queue {
|
|
1302
|
+
private pendingTasks;
|
|
1303
|
+
private queue;
|
|
1304
|
+
flushTasks(): void;
|
|
1305
|
+
add(tasks: Task[]): void;
|
|
1306
|
+
delete(tasks: Task[]): void;
|
|
1307
|
+
clear(): void;
|
|
1308
|
+
}
|
|
1309
|
+
/** Check if value is a reactive state */
|
|
1310
|
+
declare const isState: (target: unknown) => boolean;
|
|
1311
|
+
declare const mark: (host: Record<string, unknown>, key: string) => (() => boolean);
|
|
1312
|
+
declare const unmark: (host: Record<string, unknown>) => void;
|
|
1313
|
+
declare function createState(initialData: unknown, config?: StateConfig): ProxyObject;
|
|
1314
|
+
declare function lazySet(target: ProxyObject, data: Record<string, unknown>): void;
|
|
1315
|
+
/** Shallow set: only top-level properties are reactive */
|
|
1316
|
+
declare function shallowSet(target: ProxyObject, key: string, data: unknown): unknown;
|
|
1317
|
+
declare const _storeName: unique symbol;
|
|
1318
|
+
declare const _storeStatus: unique symbol;
|
|
1319
|
+
declare const _storeScheduler: unique symbol;
|
|
1320
|
+
declare const _storeCreate: unique symbol;
|
|
1321
|
+
declare const _storeBoot: unique symbol;
|
|
1322
|
+
declare const _storeDestroy: unique symbol;
|
|
1323
|
+
declare const _innerStore: unique symbol;
|
|
1324
|
+
declare const _outerStore: unique symbol;
|
|
1325
|
+
declare const _originState: unique symbol;
|
|
1326
|
+
declare const _stateKeys: unique symbol;
|
|
1327
|
+
declare const _storeState: unique symbol;
|
|
1328
|
+
declare const _storeDefScheduler: unique symbol;
|
|
1329
|
+
declare const _storeProxy: unique symbol;
|
|
1330
|
+
declare abstract class BaseStore {
|
|
1331
|
+
[_storeName]: string;
|
|
1332
|
+
[_storeStatus]: StoreStatus;
|
|
1333
|
+
[_storeScheduler]: Scheduler;
|
|
1334
|
+
[_originState]: Record<string, unknown>;
|
|
1335
|
+
[_stateKeys]: string[];
|
|
1336
|
+
[_storeState]: ProxyObject;
|
|
1337
|
+
[_storeDefScheduler]: () => Queue;
|
|
1338
|
+
private [_outerStore];
|
|
1339
|
+
[_storeBoot](): ProxyObject;
|
|
1340
|
+
[_storeDestroy](): void;
|
|
1341
|
+
/**
|
|
1342
|
+
*
|
|
1343
|
+
* @param body - The object returned by the creator function
|
|
1344
|
+
* @param excludeFns - Function keys to exclude from handlers (e.g. ['observe'])
|
|
1345
|
+
*/
|
|
1346
|
+
[_storeCreate](body: Record<string, unknown>, excludeFns?: string[]): void;
|
|
1347
|
+
constructor(name: string, config?: StoreConfig);
|
|
1348
|
+
[_innerStore](): ProxyObject;
|
|
1349
|
+
get status(): StoreStatus;
|
|
1350
|
+
get storeName(): string;
|
|
1351
|
+
get scheduler(): Scheduler;
|
|
1352
|
+
[_storeProxy](toOut?: boolean): ProxyObject;
|
|
1353
|
+
}
|
|
1354
|
+
interface LarkView {
|
|
1355
|
+
updater: {
|
|
1356
|
+
set: (data: Record<string, unknown>) => unknown;
|
|
1357
|
+
digest: (data?: Record<string, unknown>) => void;
|
|
1358
|
+
};
|
|
1359
|
+
on: (event: string, handler: AnyFunc) => unknown;
|
|
1360
|
+
}
|
|
1361
|
+
type LarkUseStore<S = Record<string, unknown>> = (view?: LarkView) => S & StoreMethods;
|
|
1362
|
+
type ReactUseStore<S = Record<string, unknown>, StateSlice = S> = (selector?: (store: S & StoreMethods) => StateSlice) => StateSlice;
|
|
1363
|
+
type NodeUseStore<S = Record<string, unknown>> = () => S & NodeStoreMethods;
|
|
1364
|
+
interface NodeStoreMethods {
|
|
1365
|
+
observe: (key: string, callback: AnyFunc, immediate?: boolean) => () => void;
|
|
1366
|
+
}
|
|
1367
|
+
interface StoreMethods {
|
|
1368
|
+
observe: (view: LarkView | undefined, keys: (string | ObservePayload)[] | (() => (string | ObservePayload)[]), defCallback?: (changedMap: Record<string, unknown>) => void) => () => void;
|
|
1369
|
+
}
|
|
1370
|
+
/** Detect platform from a component instance */
|
|
1371
|
+
declare const getPlatform: (comp: unknown) => Platform | undefined;
|
|
1372
|
+
declare const extendApis: {
|
|
1373
|
+
lazySet: typeof lazySet;
|
|
1374
|
+
shallowSet: typeof shallowSet;
|
|
1375
|
+
};
|
|
1376
|
+
/** Inner store type available inside defineStore creator */
|
|
1377
|
+
type InnerStore<S = Record<string, unknown>> = S & StoreMethods;
|
|
1378
|
+
declare function defineStore<S = Record<string, unknown>>(name: string, creator: (store: InnerStore<S>, apis: typeof extendApis) => S, config?: StoreConfig & {
|
|
1379
|
+
platform: Platform.Lark;
|
|
1380
|
+
}): LarkUseStore<S>;
|
|
1381
|
+
declare function defineStore<S = Record<string, unknown>>(name: string, creator: (store: InnerStore<S>, apis: typeof extendApis) => S, config?: StoreConfig & {
|
|
1382
|
+
platform: Platform.React;
|
|
1383
|
+
}): ReactUseStore<S>;
|
|
1384
|
+
declare function defineStore<S = Record<string, unknown>>(name: string, creator: (store: InnerStore<S>, apis: typeof extendApis) => S, config?: StoreConfig & {
|
|
1385
|
+
platform: Platform.Node;
|
|
1386
|
+
}): NodeUseStore<S>;
|
|
1387
|
+
declare function getStore(name: string): BaseStore | undefined;
|
|
1388
|
+
declare function delStore(name: string): void;
|
|
1389
|
+
declare function getUseStore(name: string): AnyFunc | undefined;
|
|
1390
|
+
declare function cloneStore(name: string, useStore: AnyFunc, config?: StoreConfig): unknown;
|
|
1391
|
+
declare function isStoreActive(name: string): boolean;
|
|
1392
|
+
declare function cell<T = unknown>(data: T): T;
|
|
1393
|
+
declare function observeCell(state: ProxyObject, cb: AnyFunc, immediate?: boolean): () => void;
|
|
1394
|
+
declare function multi<S = Record<string, unknown>>(useStore: LarkUseStore<S>): [LarkUseStore<S>, {
|
|
1395
|
+
ctor: AnyFunc;
|
|
1396
|
+
}];
|
|
1397
|
+
|
|
1398
|
+
/**
|
|
1399
|
+
* @lark/framework Template Compiler
|
|
1400
|
+
*
|
|
1401
|
+
* convertArtSyntax() ({{}} → <% %>)
|
|
1402
|
+
* processLarkEvents() (lark-event prefix + param encoding)
|
|
1403
|
+
* compileToFunction() (<% %> → JS template function)
|
|
1404
|
+
* extractGlobalVars() (AST-based global var analysis via @babel/parser)
|
|
1405
|
+
*
|
|
1406
|
+
* - All template operators: = (escape), ! (raw), @ (ref lookup), : (binding)
|
|
1407
|
+
* - lark-event attribute processing with $g prefix + \x1e separator
|
|
1408
|
+
* - $n (null-safe toString), $e (HTML entity encode), $eu (URI encode), $eq (quote encode), $i (ref lookup)
|
|
1409
|
+
* - Debug mode with line tracking ($expr/$art/$line) and try-catch error wrapper
|
|
1410
|
+
* - View ID injection (\x1f → '+$viewId+')
|
|
1411
|
+
* - Post-processing cleanup of empty concatenations
|
|
1412
|
+
* - 0 configuration: auto-extract variables via AST analysis
|
|
1413
|
+
*
|
|
1414
|
+
* Template syntax:
|
|
1415
|
+
* {{=variable}} → escaped output
|
|
1416
|
+
* {{:variable}} → two-way binding (same as = for rendering)
|
|
1417
|
+
* {{!variable}} → raw output (no HTML escaping)
|
|
1418
|
+
* {{@variable}} → reference lookup for component data passing
|
|
1419
|
+
* {{each list as item}} → loop
|
|
1420
|
+
* {{each list as item idx}} → loop with index
|
|
1421
|
+
* {{forin obj as val key}} → object iteration
|
|
1422
|
+
* {{for(let i=0;i<n;i++)}} → generic for loop
|
|
1423
|
+
* {{if condition}} → conditional
|
|
1424
|
+
* {{else if condition}} → else-if
|
|
1425
|
+
* {{else}} → else
|
|
1426
|
+
* {{/if}} / {{/each}} / {{/forin}} / {{/for}} → close blocks
|
|
1427
|
+
* {{set a = b}} → variable declaration
|
|
1428
|
+
*/
|
|
1429
|
+
/** Options for compileTemplate() */
|
|
1430
|
+
interface CompileOptions {
|
|
1431
|
+
/** Enable debug mode with line tracking (default: false) */
|
|
1432
|
+
debug?: boolean;
|
|
1433
|
+
/** Global variable names to destructure from $$ (refData) */
|
|
1434
|
+
globalVars?: string[];
|
|
1435
|
+
/** File path for debug error messages (default: undefined) */
|
|
1436
|
+
file?: string;
|
|
1437
|
+
}
|
|
1438
|
+
/**
|
|
1439
|
+
* Compile an HTML template string into a JS module string.
|
|
1440
|
+
* This is the main entry point for both Vite and Webpack loaders.
|
|
1441
|
+
*
|
|
1442
|
+
* The output is an ES module that exports a function with the signature:
|
|
1443
|
+
* (data, selfId, refData) => string
|
|
1444
|
+
*
|
|
1445
|
+
* Internally it calls the compiled template function with the standard
|
|
1446
|
+
* signature: ($$,$viewId,$$ref,$e,$n,$eu,$i,$eq)
|
|
1447
|
+
*
|
|
1448
|
+
* @param source - The raw HTML template content
|
|
1449
|
+
* @param options - Compilation options
|
|
1450
|
+
* @returns ES module source code exporting the compiled template function
|
|
1451
|
+
*/
|
|
1452
|
+
declare function compileTemplate(source: string, options?: CompileOptions): string;
|
|
1453
|
+
/**
|
|
1454
|
+
* Extract global variable names from a template source using AST analysis.
|
|
1455
|
+
*
|
|
1456
|
+
* 1. Convert template commands (<% %> blocks) into a form parseable by an AST parser
|
|
1457
|
+
* 2. Walk the AST to find all Identifier nodes
|
|
1458
|
+
* 3. Track variable declarations (VariableDeclarator, FunctionDeclaration) as local vars
|
|
1459
|
+
* 4. Track function parameters as local vars
|
|
1460
|
+
* 5. Remaining identifiers that are not local and not in the exclusion list are "global" —
|
|
1461
|
+
* they must be passed in as part of the data context ($$)
|
|
1462
|
+
*
|
|
1463
|
+
* This replaces the old regex-based `extractVariables()` with proper scope analysis,
|
|
1464
|
+
* eliminating false positives from local template variables and function parameters.
|
|
1465
|
+
*
|
|
1466
|
+
* @param source - The raw HTML template content (with {{ }} syntax)
|
|
1467
|
+
* @returns Array of global variable names found in the template
|
|
1468
|
+
*/
|
|
1469
|
+
declare function extractGlobalVars(source: string): string[];
|
|
1470
|
+
|
|
1471
|
+
export { type AnyFunc, Bag, type BagEntry, CALL_BREAK_TIME, Cache, type CacheEntry, type CacheOptions, type CompileOptions, type Constructable, EVT_METHOD_REG, EventDelegator, EventEmitter, type EventListenerEntry, Frame, type FrameBoundElement, type FrameChildrenMap, type FrameInvokeEntry, type FrameLike, type FrameReadyMap, Framework, type FrameworkConfig, LARK_VIEW, type LarkUseStore, type Location, type LocationDiff, type MixinEventHandler, type NodeUseStore, type ObservePayload, type ParamDiff, type ParsedUri, type PendingCacheEntry, Platform, ROUTER_EVENTS, type ReactUseStore, type RouteViewConfig, Router, SPLITTER, Service, type ServiceCacheInfo, type ServiceConstructor, type ServiceEntry, type ServiceMetaEntry, type ServiceOptions, State, type StoreConfig, type StoreMethods, TAG_ATTR_KEY, TAG_KEY, TAG_NAME_REGEX, TAG_VIEW_KEY, Updater, type UpdaterLike, type VDomOp, type VDomRef, VIEW_EVT_METHOD_REG, type VdomElement, View, type ViewClassInternal, type ViewEventObjectMap, type ViewEventSelectorEntry, type ViewEventSelectorMap, type ViewGlobalEventEntry, type ViewInstance, type ViewLocationObserved, type ViewResourceEntry, type ViewResourceMap, type VoidFunc, applyIdUpdates, applyStyle, applyVdomOps, assign, cell, classExtend, cloneData, cloneStore, compileTemplate, createState, createVdomRef, defineStore, delStore, encodeHTML, encodeQ, encodeSafe, encodeURIExtra, ensureElementId, extractGlobalVars, funcWithTry, generateId, getAttribute, getById, getPlatform, getStore, getUseStore, has, isArray, isPlainObject, isPrimitive, isPrimitiveOrFunc, isState, isStoreActive, keys, lazySet, mark$1 as mark, markBooted, markRouterBooted, multi, nextCounter, nodeInside, noop, now, observeCell, parseUri, registerViewClass, safeguard, setData, shallowSet, mark as storeMark, unmark as storeUnmark, syncCounter, toMap, toUri, translateData, unmark$1 as unmark, vdomGetCompareKey, vdomGetNode, vdomSetAttributes, vdomSetChildNodes, vdomSetNode, vdomSpecialDiff, vdomUnmountFrames };
|