zero-query 0.6.3 → 0.8.6
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 +39 -29
- package/cli/commands/build.js +113 -4
- package/cli/commands/bundle.js +392 -29
- package/cli/commands/create.js +1 -1
- package/cli/commands/dev/devtools/index.js +56 -0
- package/cli/commands/dev/devtools/js/components.js +49 -0
- package/cli/commands/dev/devtools/js/core.js +409 -0
- package/cli/commands/dev/devtools/js/elements.js +413 -0
- package/cli/commands/dev/devtools/js/network.js +166 -0
- package/cli/commands/dev/devtools/js/performance.js +73 -0
- package/cli/commands/dev/devtools/js/router.js +105 -0
- package/cli/commands/dev/devtools/js/source.js +132 -0
- package/cli/commands/dev/devtools/js/stats.js +35 -0
- package/cli/commands/dev/devtools/js/tabs.js +79 -0
- package/cli/commands/dev/devtools/panel.html +95 -0
- package/cli/commands/dev/devtools/styles.css +244 -0
- package/cli/commands/dev/index.js +29 -4
- package/cli/commands/dev/logger.js +6 -1
- package/cli/commands/dev/overlay.js +428 -2
- package/cli/commands/dev/server.js +42 -5
- package/cli/commands/dev/watcher.js +59 -1
- package/cli/help.js +8 -5
- package/cli/scaffold/{scripts → app}/app.js +16 -23
- package/cli/scaffold/{scripts → app}/components/about.js +4 -4
- package/cli/scaffold/{scripts → app}/components/api-demo.js +1 -1
- package/cli/scaffold/{scripts → app}/components/contacts/contacts.css +0 -7
- package/cli/scaffold/{scripts → app}/components/contacts/contacts.html +3 -3
- package/cli/scaffold/app/components/home.js +137 -0
- package/cli/scaffold/{scripts → app}/routes.js +1 -1
- package/cli/scaffold/{scripts → app}/store.js +6 -6
- package/cli/scaffold/assets/.gitkeep +0 -0
- package/cli/scaffold/{styles/styles.css → global.css} +4 -2
- package/cli/scaffold/index.html +12 -11
- package/cli/utils.js +111 -6
- package/dist/zquery.dist.zip +0 -0
- package/dist/zquery.js +1122 -158
- package/dist/zquery.min.js +3 -16
- package/index.d.ts +129 -1290
- package/index.js +15 -10
- package/package.json +7 -6
- package/src/component.js +172 -49
- package/src/core.js +359 -18
- package/src/diff.js +256 -58
- package/src/expression.js +33 -3
- package/src/reactive.js +37 -5
- package/src/router.js +243 -7
- package/tests/component.test.js +886 -0
- package/tests/core.test.js +977 -0
- package/tests/diff.test.js +525 -0
- package/tests/errors.test.js +162 -0
- package/tests/expression.test.js +482 -0
- package/tests/http.test.js +289 -0
- package/tests/reactive.test.js +339 -0
- package/tests/router.test.js +649 -0
- package/tests/store.test.js +379 -0
- package/tests/utils.test.js +512 -0
- package/types/collection.d.ts +383 -0
- package/types/component.d.ts +217 -0
- package/types/errors.d.ts +103 -0
- package/types/http.d.ts +81 -0
- package/types/misc.d.ts +179 -0
- package/types/reactive.d.ts +76 -0
- package/types/router.d.ts +161 -0
- package/types/ssr.d.ts +49 -0
- package/types/store.d.ts +107 -0
- package/types/utils.d.ts +142 -0
- package/cli/commands/dev.old.js +0 -520
- package/cli/scaffold/scripts/components/home.js +0 -137
- /package/cli/scaffold/{scripts → app}/components/contacts/contacts.js +0 -0
- /package/cli/scaffold/{scripts → app}/components/counter.js +0 -0
- /package/cli/scaffold/{scripts → app}/components/not-found.js +0 -0
- /package/cli/scaffold/{scripts → app}/components/todos.js +0 -0
package/index.d.ts
CHANGED
|
@@ -4,1278 +4,133 @@
|
|
|
4
4
|
* Lightweight modern frontend library — jQuery-like selectors, reactive
|
|
5
5
|
* components, SPA router, state management, HTTP client & utilities.
|
|
6
6
|
*
|
|
7
|
-
* @version 0.6
|
|
7
|
+
* @version 0.8.6
|
|
8
8
|
* @license MIT
|
|
9
9
|
* @see https://z-query.com/docs
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
// ---------------------------------------------------------------------------
|
|
13
|
-
//
|
|
14
|
-
// ---------------------------------------------------------------------------
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
/** Remove attribute from all elements. */
|
|
115
|
-
removeAttr(name: string): this;
|
|
116
|
-
|
|
117
|
-
/** Get JS property of the first element. */
|
|
118
|
-
prop(name: string): any;
|
|
119
|
-
/** Set JS property on all elements. */
|
|
120
|
-
prop(name: string, value: any): this;
|
|
121
|
-
|
|
122
|
-
/** Get data attribute value (JSON auto-parsed). No key → full dataset. */
|
|
123
|
-
data(): DOMStringMap;
|
|
124
|
-
data(key: string): any;
|
|
125
|
-
/** Set data attribute on all elements. Objects are JSON-stringified. */
|
|
126
|
-
data(key: string, value: any): this;
|
|
127
|
-
|
|
128
|
-
// -- CSS & Dimensions ----------------------------------------------------
|
|
129
|
-
/** Get computed style property of the first element, or `undefined` if empty. */
|
|
130
|
-
css(property: string): string | undefined;
|
|
131
|
-
/** Set inline styles on all elements. */
|
|
132
|
-
css(props: Partial<CSSStyleDeclaration>): this;
|
|
133
|
-
|
|
134
|
-
/** First element's width (from `getBoundingClientRect`). */
|
|
135
|
-
width(): number | undefined;
|
|
136
|
-
|
|
137
|
-
/** First element's height. */
|
|
138
|
-
height(): number | undefined;
|
|
139
|
-
|
|
140
|
-
/** Position relative to the document. */
|
|
141
|
-
offset(): { top: number; left: number; width: number; height: number } | null;
|
|
142
|
-
|
|
143
|
-
/** Position relative to the offset parent. */
|
|
144
|
-
position(): { top: number; left: number } | null;
|
|
145
|
-
|
|
146
|
-
// -- Content -------------------------------------------------------------
|
|
147
|
-
/** Get `innerHTML` of the first element, or `undefined` if empty. */
|
|
148
|
-
html(): string | undefined;
|
|
149
|
-
/** Set `innerHTML` on all elements. */
|
|
150
|
-
html(content: string): this;
|
|
151
|
-
|
|
152
|
-
/** Get `textContent` of the first element, or `undefined` if empty. */
|
|
153
|
-
text(): string | undefined;
|
|
154
|
-
/** Set `textContent` on all elements. */
|
|
155
|
-
text(content: string): this;
|
|
156
|
-
|
|
157
|
-
/** Get value of the first input/select/textarea, or `undefined` if empty. */
|
|
158
|
-
val(): string | undefined;
|
|
159
|
-
/** Set value on all inputs. */
|
|
160
|
-
val(value: string): this;
|
|
161
|
-
|
|
162
|
-
// -- DOM Manipulation ----------------------------------------------------
|
|
163
|
-
/** Insert content at the end of each element. */
|
|
164
|
-
append(content: string | Node | ZQueryCollection): this;
|
|
165
|
-
|
|
166
|
-
/** Insert content at the beginning of each element. */
|
|
167
|
-
prepend(content: string | Node): this;
|
|
168
|
-
|
|
169
|
-
/** Insert content after each element. */
|
|
170
|
-
after(content: string | Node): this;
|
|
171
|
-
|
|
172
|
-
/** Insert content before each element. */
|
|
173
|
-
before(content: string | Node): this;
|
|
174
|
-
|
|
175
|
-
/** Wrap each element with the given HTML string or Node. */
|
|
176
|
-
wrap(wrapper: string | Node): this;
|
|
177
|
-
|
|
178
|
-
/** Remove all elements from the DOM. */
|
|
179
|
-
remove(): this;
|
|
180
|
-
|
|
181
|
-
/** Clear `innerHTML` of all elements. */
|
|
182
|
-
empty(): this;
|
|
183
|
-
|
|
184
|
-
/** Clone elements (default: deep clone). */
|
|
185
|
-
clone(deep?: boolean): ZQueryCollection;
|
|
186
|
-
|
|
187
|
-
/** Replace elements with new content. */
|
|
188
|
-
replaceWith(content: string | Node): this;
|
|
189
|
-
|
|
190
|
-
// -- Visibility ----------------------------------------------------------
|
|
191
|
-
/** Show elements. Optional display value (default: `''`). */
|
|
192
|
-
show(display?: string): this;
|
|
193
|
-
|
|
194
|
-
/** Set `display: none` on all elements. */
|
|
195
|
-
hide(): this;
|
|
196
|
-
|
|
197
|
-
/** Toggle visibility. */
|
|
198
|
-
toggle(display?: string): this;
|
|
199
|
-
|
|
200
|
-
// -- Events --------------------------------------------------------------
|
|
201
|
-
/** Attach event handler. Space-separated events accepted. */
|
|
202
|
-
on(events: string, handler: (event: Event) => void): this;
|
|
203
|
-
/** Delegated event handler. */
|
|
204
|
-
on(events: string, selector: string, handler: (this: Element, event: Event) => void): this;
|
|
205
|
-
|
|
206
|
-
/** Remove event handler. */
|
|
207
|
-
off(events: string, handler: (event: Event) => void): this;
|
|
208
|
-
|
|
209
|
-
/** One-time event handler. */
|
|
210
|
-
one(event: string, handler: (event: Event) => void): this;
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Dispatch a `CustomEvent` with optional detail payload.
|
|
214
|
-
* Bubbles by default.
|
|
215
|
-
*/
|
|
216
|
-
trigger(event: string, detail?: any): this;
|
|
217
|
-
|
|
218
|
-
/** Attach click handler, or trigger a click when called with no arguments. */
|
|
219
|
-
click(fn?: (event: Event) => void): this;
|
|
220
|
-
|
|
221
|
-
/** Attach submit handler, or trigger submit when called with no arguments. */
|
|
222
|
-
submit(fn?: (event: Event) => void): this;
|
|
223
|
-
|
|
224
|
-
/** Focus the first element. */
|
|
225
|
-
focus(): this;
|
|
226
|
-
|
|
227
|
-
/** Blur the first element. */
|
|
228
|
-
blur(): this;
|
|
229
|
-
|
|
230
|
-
// -- Animation -----------------------------------------------------------
|
|
231
|
-
/**
|
|
232
|
-
* CSS transition animation.
|
|
233
|
-
* @param props CSS properties to animate to.
|
|
234
|
-
* @param duration Duration in ms (default 300).
|
|
235
|
-
* @param easing CSS easing function (default `'ease'`).
|
|
236
|
-
*/
|
|
237
|
-
animate(
|
|
238
|
-
props: Partial<CSSStyleDeclaration>,
|
|
239
|
-
duration?: number,
|
|
240
|
-
easing?: string,
|
|
241
|
-
): Promise<ZQueryCollection>;
|
|
242
|
-
|
|
243
|
-
/** Fade in (opacity 0→1). Default 300 ms. */
|
|
244
|
-
fadeIn(duration?: number): Promise<ZQueryCollection>;
|
|
245
|
-
|
|
246
|
-
/** Fade out (opacity 1→0) then hide. Default 300 ms. */
|
|
247
|
-
fadeOut(duration?: number): Promise<ZQueryCollection>;
|
|
248
|
-
|
|
249
|
-
/** Toggle height with a slide animation. Default 300 ms. */
|
|
250
|
-
slideToggle(duration?: number): this;
|
|
251
|
-
|
|
252
|
-
// -- Form Helpers --------------------------------------------------------
|
|
253
|
-
/** URL-encoded form data string. */
|
|
254
|
-
serialize(): string;
|
|
255
|
-
|
|
256
|
-
/** Form data as key/value object. Duplicate keys become arrays. */
|
|
257
|
-
serializeObject(): Record<string, string | string[]>;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
// ---------------------------------------------------------------------------
|
|
262
|
-
// Reactive
|
|
263
|
-
// ---------------------------------------------------------------------------
|
|
264
|
-
|
|
265
|
-
/** Marker properties added to every reactive proxy. */
|
|
266
|
-
interface ReactiveProxy<T extends object = object> {
|
|
267
|
-
/** Always `true` — indicates this object is wrapped in a reactive Proxy. */
|
|
268
|
-
readonly __isReactive: true;
|
|
269
|
-
/** The original un-proxied object. */
|
|
270
|
-
readonly __raw: T;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* Wrap an object in a deep Proxy that fires `onChange` on every set / delete.
|
|
275
|
-
*/
|
|
276
|
-
export function reactive<T extends object>(
|
|
277
|
-
target: T,
|
|
278
|
-
onChange: (key: string, value: any, oldValue: any) => void,
|
|
279
|
-
): T & ReactiveProxy<T>;
|
|
280
|
-
|
|
281
|
-
/** A lightweight reactive primitive (inspired by Solid / Preact signals). */
|
|
282
|
-
export class Signal<T = any> {
|
|
283
|
-
constructor(value: T);
|
|
284
|
-
|
|
285
|
-
/** Get/set the current value. The getter auto-tracks inside `effect()`. */
|
|
286
|
-
value: T;
|
|
287
|
-
|
|
288
|
-
/** Read the value without creating a subscription. */
|
|
289
|
-
peek(): T;
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* Manually subscribe to changes.
|
|
293
|
-
* @returns An unsubscribe function.
|
|
294
|
-
*/
|
|
295
|
-
subscribe(fn: () => void): () => void;
|
|
296
|
-
|
|
297
|
-
toString(): string;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/** Create a new `Signal`. */
|
|
301
|
-
export function signal<T>(initial: T): Signal<T>;
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* Create a derived signal that recomputes when its dependencies change.
|
|
305
|
-
* The returned signal is effectively read-only.
|
|
306
|
-
*/
|
|
307
|
-
export function computed<T>(fn: () => T): Signal<T>;
|
|
308
|
-
|
|
309
|
-
/**
|
|
310
|
-
* Run a side-effect that auto-subscribes to signals read during execution.
|
|
311
|
-
* @returns A dispose function that stops tracking.
|
|
312
|
-
*/
|
|
313
|
-
export function effect(fn: () => void): () => void;
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
// ---------------------------------------------------------------------------
|
|
317
|
-
// Component System
|
|
318
|
-
// ---------------------------------------------------------------------------
|
|
319
|
-
|
|
320
|
-
/** Item in a `pages` config — either a string id or an `{ id, label }` object. */
|
|
321
|
-
type PageItem = string | { id: string; label?: string };
|
|
322
|
-
|
|
323
|
-
/**
|
|
324
|
-
* Declarative multi-page configuration for a component.
|
|
325
|
-
*
|
|
326
|
-
* Pages are **lazy-loaded**: only the active page is fetched on first render.
|
|
327
|
-
* Remaining pages are prefetched in the background for instant navigation.
|
|
328
|
-
*/
|
|
329
|
-
interface PagesConfig {
|
|
330
|
-
/** Directory containing the page HTML files (resolved relative to `base`). */
|
|
331
|
-
dir?: string;
|
|
332
|
-
/** Route parameter name to read (e.g. `'section'` for `/docs/:section`). */
|
|
333
|
-
param?: string;
|
|
334
|
-
/** Default page id when the param is absent. */
|
|
335
|
-
default?: string;
|
|
336
|
-
/** File extension appended to each page id (default `'.html'`). */
|
|
337
|
-
ext?: string;
|
|
338
|
-
/** List of page ids and/or `{ id, label }` objects. */
|
|
339
|
-
items?: PageItem[];
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
/** The object passed to `$.component()` to define a component. */
|
|
343
|
-
interface ComponentDefinition {
|
|
344
|
-
/**
|
|
345
|
-
* Initial reactive state.
|
|
346
|
-
* A function form is recommended so each instance gets its own copy.
|
|
347
|
-
*/
|
|
348
|
-
state?: Record<string, any> | (() => Record<string, any>);
|
|
349
|
-
|
|
350
|
-
/**
|
|
351
|
-
* Returns an HTML string. Called on every state change.
|
|
352
|
-
* `this` is the component instance.
|
|
353
|
-
*/
|
|
354
|
-
render?(this: ComponentInstance): string;
|
|
355
|
-
|
|
356
|
-
/** CSS string — scoped to the component root on first render. */
|
|
357
|
-
styles?: string;
|
|
358
|
-
|
|
359
|
-
/**
|
|
360
|
-
* URL (or array / object map of URLs) to external HTML template file(s).
|
|
361
|
-
* If `render()` is also defined, `render()` takes priority.
|
|
362
|
-
*/
|
|
363
|
-
templateUrl?: string | string[] | Record<string, string>;
|
|
364
|
-
|
|
365
|
-
/**
|
|
366
|
-
* URL (or array of URLs) to external CSS file(s).
|
|
367
|
-
* Fetched and auto-scoped on first mount; merged with `styles` if both present.
|
|
368
|
-
*/
|
|
369
|
-
styleUrl?: string | string[];
|
|
370
|
-
|
|
371
|
-
/** High-level multi-page configuration shorthand. */
|
|
372
|
-
pages?: PagesConfig;
|
|
373
|
-
|
|
374
|
-
/**
|
|
375
|
-
* Override the base path for resolving relative `templateUrl`, `styleUrl`,
|
|
376
|
-
* and `pages.dir` paths. Normally auto-detected from the calling file.
|
|
377
|
-
*/
|
|
378
|
-
base?: string;
|
|
379
|
-
|
|
380
|
-
/** Called before first render (during construction). */
|
|
381
|
-
init?(this: ComponentInstance): void;
|
|
382
|
-
|
|
383
|
-
/** Called once after first render and DOM insertion. */
|
|
384
|
-
mounted?(this: ComponentInstance): void;
|
|
385
|
-
|
|
386
|
-
/** Called after every subsequent re-render. */
|
|
387
|
-
updated?(this: ComponentInstance): void;
|
|
388
|
-
|
|
389
|
-
/** Called when the component is destroyed. Clean up subscriptions here. */
|
|
390
|
-
destroyed?(this: ComponentInstance): void;
|
|
391
|
-
|
|
392
|
-
/**
|
|
393
|
-
* Computed properties — lazy getters derived from state.
|
|
394
|
-
* Each function receives the raw state as its argument.
|
|
395
|
-
* Access via `this.computed.name` in methods and templates.
|
|
396
|
-
*/
|
|
397
|
-
computed?: Record<string, (state: Record<string, any>) => any>;
|
|
398
|
-
|
|
399
|
-
/**
|
|
400
|
-
* Watch state keys for changes.
|
|
401
|
-
* Keys support dot-path notation (e.g. `'user.name'`).
|
|
402
|
-
* Handler receives `(newValue, oldValue)`.
|
|
403
|
-
*/
|
|
404
|
-
watch?: Record<string, ((this: ComponentInstance, newVal: any, oldVal: any) => void) | { handler: (this: ComponentInstance, newVal: any, oldVal: any) => void }>;
|
|
405
|
-
|
|
406
|
-
/** Additional keys become instance methods (bound to the instance). */
|
|
407
|
-
[method: string]: any;
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
/** The runtime instance of a mounted component. */
|
|
411
|
-
interface ComponentInstance {
|
|
412
|
-
/** Reactive state proxy. Mutating triggers re-render. */
|
|
413
|
-
state: Record<string, any> & ReactiveProxy;
|
|
414
|
-
|
|
415
|
-
/** Frozen props passed from parent / router.
|
|
416
|
-
* When mounted by the router, includes `$route` (NavigationContext), `$query`, and `$params`.
|
|
417
|
-
*/
|
|
418
|
-
readonly props: Readonly<Record<string, any> & {
|
|
419
|
-
$route?: NavigationContext;
|
|
420
|
-
$query?: Record<string, string>;
|
|
421
|
-
$params?: Record<string, string>;
|
|
422
|
-
}>;
|
|
423
|
-
|
|
424
|
-
/** Map of `z-ref` name → DOM element. Populated after each render. */
|
|
425
|
-
refs: Record<string, Element>;
|
|
426
|
-
|
|
427
|
-
/** Keyed template map (when using multi-`templateUrl` or `pages`). */
|
|
428
|
-
templates: Record<string, string>;
|
|
429
|
-
|
|
430
|
-
/** Normalized page metadata (when using `pages` config). */
|
|
431
|
-
pages: Array<{ id: string; label: string }>;
|
|
432
|
-
|
|
433
|
-
/** Active page id derived from route param (when using `pages` config). */
|
|
434
|
-
activePage: string;
|
|
435
|
-
|
|
436
|
-
/**
|
|
437
|
-
* Computed properties — lazy getters derived from state.
|
|
438
|
-
* Defined via `computed` in the component definition.
|
|
439
|
-
*/
|
|
440
|
-
readonly computed: Record<string, any>;
|
|
441
|
-
|
|
442
|
-
/** Merge partial state (triggers re-render). */
|
|
443
|
-
setState(partial: Record<string, any>): void;
|
|
444
|
-
|
|
445
|
-
/** Dispatch a bubbling `CustomEvent` from the component root. */
|
|
446
|
-
emit(name: string, detail?: any): void;
|
|
447
|
-
|
|
448
|
-
/** Teardown: removes listeners, scoped styles, clears DOM. */
|
|
449
|
-
destroy(): void;
|
|
450
|
-
|
|
451
|
-
/** Manually queue a re-render (microtask-batched). Safe to call from anywhere — state mutations during render are coalesced (no infinite loop risk). */
|
|
452
|
-
_scheduleUpdate(): void;
|
|
453
|
-
|
|
454
|
-
/** Any user-defined methods from the component definition. */
|
|
455
|
-
[method: string]: any;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
/**
|
|
459
|
-
* Register a new component.
|
|
460
|
-
* @param name Must contain a hyphen (Web Component convention).
|
|
461
|
-
* @param definition Component definition object.
|
|
462
|
-
*/
|
|
463
|
-
export function component(name: string, definition: ComponentDefinition): void;
|
|
464
|
-
|
|
465
|
-
/**
|
|
466
|
-
* Mount a registered component into a target element.
|
|
467
|
-
* @returns The component instance.
|
|
468
|
-
*/
|
|
469
|
-
export function mount(
|
|
470
|
-
target: string | Element,
|
|
471
|
-
componentName: string,
|
|
472
|
-
props?: Record<string, any>,
|
|
473
|
-
): ComponentInstance;
|
|
474
|
-
|
|
475
|
-
/**
|
|
476
|
-
* Scan `root` for elements whose tag matches a registered component and mount them.
|
|
477
|
-
* @param root Defaults to `document.body`.
|
|
478
|
-
*/
|
|
479
|
-
export function mountAll(root?: Element): void;
|
|
480
|
-
|
|
481
|
-
/**
|
|
482
|
-
* Get the component instance mounted on `target`.
|
|
483
|
-
*/
|
|
484
|
-
export function getInstance(target: string | Element): ComponentInstance | null;
|
|
485
|
-
|
|
486
|
-
/**
|
|
487
|
-
* Destroy the component at the given target.
|
|
488
|
-
*/
|
|
489
|
-
export function destroy(target: string | Element): void;
|
|
490
|
-
|
|
491
|
-
/**
|
|
492
|
-
* Returns an object of all registered component definitions (for debugging).
|
|
493
|
-
*/
|
|
494
|
-
export function getRegistry(): Record<string, ComponentDefinition>;
|
|
495
|
-
|
|
496
|
-
/** Handle returned by `$.style()`. */
|
|
497
|
-
interface StyleHandle {
|
|
498
|
-
/** Remove all injected `<link>` elements. */
|
|
499
|
-
remove(): void;
|
|
500
|
-
/** Resolves when all stylesheets have loaded. */
|
|
501
|
-
ready: Promise<void>;
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
/** Options for `$.style()`. */
|
|
505
|
-
interface StyleOptions {
|
|
506
|
-
/** Hide page until loaded to prevent FOUC (default `true`). */
|
|
507
|
-
critical?: boolean;
|
|
508
|
-
/** Background color while hidden during critical load (default `'#0d1117'`). */
|
|
509
|
-
bg?: string;
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
/**
|
|
513
|
-
* Dynamically load global (unscoped) stylesheet file(s) into `<head>`.
|
|
514
|
-
* Relative paths resolve relative to the calling file.
|
|
515
|
-
*/
|
|
516
|
-
export function style(urls: string | string[], opts?: StyleOptions): StyleHandle;
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
// ---------------------------------------------------------------------------
|
|
520
|
-
// DOM Diffing (Morphing)
|
|
521
|
-
// ---------------------------------------------------------------------------
|
|
522
|
-
|
|
523
|
-
/**
|
|
524
|
-
* Morph an existing DOM element's children to match new HTML.
|
|
525
|
-
* Only touches nodes that actually differ — preserves focus, scroll
|
|
526
|
-
* positions, video playback, and other live DOM state.
|
|
527
|
-
*
|
|
528
|
-
* Use `z-key="uniqueId"` attributes on list items for keyed reconciliation.
|
|
529
|
-
*
|
|
530
|
-
* @param rootEl The live DOM container to patch.
|
|
531
|
-
* @param newHTML The desired HTML string.
|
|
532
|
-
*/
|
|
533
|
-
export function morph(rootEl: Element, newHTML: string): void;
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
// ---------------------------------------------------------------------------
|
|
537
|
-
// Safe Expression Evaluator
|
|
538
|
-
// ---------------------------------------------------------------------------
|
|
539
|
-
|
|
540
|
-
/**
|
|
541
|
-
* CSP-safe expression evaluator. Parses and evaluates JS expressions
|
|
542
|
-
* without `eval()` or `new Function()`. Used internally by directives.
|
|
543
|
-
*
|
|
544
|
-
* @param expr Expression string.
|
|
545
|
-
* @param scope Array of scope objects checked in order for identifier resolution.
|
|
546
|
-
* @returns Evaluation result, or `undefined` on error.
|
|
547
|
-
*/
|
|
548
|
-
export function safeEval(expr: string, scope: object[]): any;
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
// ---------------------------------------------------------------------------
|
|
552
|
-
// SSR (Server-Side Rendering)
|
|
553
|
-
// ---------------------------------------------------------------------------
|
|
554
|
-
|
|
555
|
-
/** SSR application instance for server-side component rendering. */
|
|
556
|
-
interface SSRApp {
|
|
557
|
-
/** Register a component for SSR. */
|
|
558
|
-
component(name: string, definition: ComponentDefinition): SSRApp;
|
|
559
|
-
|
|
560
|
-
/**
|
|
561
|
-
* Render a component to an HTML string.
|
|
562
|
-
* @param componentName Registered component name.
|
|
563
|
-
* @param props Props to pass to the component.
|
|
564
|
-
* @param options Rendering options.
|
|
565
|
-
*/
|
|
566
|
-
renderToString(
|
|
567
|
-
componentName: string,
|
|
568
|
-
props?: Record<string, any>,
|
|
569
|
-
options?: { hydrate?: boolean },
|
|
570
|
-
): Promise<string>;
|
|
571
|
-
|
|
572
|
-
/**
|
|
573
|
-
* Render a full HTML page with a component mounted in a shell.
|
|
574
|
-
*/
|
|
575
|
-
renderPage(options: {
|
|
576
|
-
component?: string;
|
|
577
|
-
props?: Record<string, any>;
|
|
578
|
-
title?: string;
|
|
579
|
-
styles?: string[];
|
|
580
|
-
scripts?: string[];
|
|
581
|
-
lang?: string;
|
|
582
|
-
meta?: string;
|
|
583
|
-
bodyAttrs?: string;
|
|
584
|
-
}): Promise<string>;
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
/** Create an SSR application instance. */
|
|
588
|
-
export function createSSRApp(): SSRApp;
|
|
589
|
-
|
|
590
|
-
/**
|
|
591
|
-
* Quick one-shot render of a component definition to an HTML string.
|
|
592
|
-
* @param definition Component definition object.
|
|
593
|
-
* @param props Props to pass.
|
|
594
|
-
*/
|
|
595
|
-
export function renderToString(definition: ComponentDefinition, props?: Record<string, any>): string;
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
// ---------------------------------------------------------------------------
|
|
599
|
-
// Directive System
|
|
600
|
-
// ---------------------------------------------------------------------------
|
|
601
|
-
//
|
|
602
|
-
// Directives are special attributes processed by zQuery's component renderer.
|
|
603
|
-
// They work in both `render()` template literals and external `templateUrl`
|
|
604
|
-
// HTML files. All expressions evaluate in the component's state context
|
|
605
|
-
// (bare names resolve to `this.state.*`; `props` and `refs` also available).
|
|
606
|
-
//
|
|
607
|
-
// ─── Structural Directives ──────────────────────────────────────────────
|
|
608
|
-
//
|
|
609
|
-
// z-if="expression" Conditional rendering — element removed when falsy.
|
|
610
|
-
// z-else-if="expression" Else-if branch (must be immediate sibling of z-if).
|
|
611
|
-
// z-else Default branch (must follow z-if or z-else-if).
|
|
612
|
-
//
|
|
613
|
-
// z-for="item in items" List rendering — repeats the element per item.
|
|
614
|
-
// {{item.prop}} Use double-brace interpolation for item data.
|
|
615
|
-
// (item, index) in items Destructured index support.
|
|
616
|
-
// n in 5 Number range → [1, 2, 3, 4, 5].
|
|
617
|
-
// (val, key) in object Object iteration → {key, value} entries.
|
|
618
|
-
//
|
|
619
|
-
// z-key="uniqueId" Keyed reconciliation for list items.
|
|
620
|
-
// Preserves DOM nodes across reorders. Use inside
|
|
621
|
-
// z-for to give each item a stable identity.
|
|
622
|
-
// Example: <li z-for="item in items" z-key="{{item.id}}">
|
|
623
|
-
//
|
|
624
|
-
// z-show="expression" Toggle `display: none` (element stays in DOM).
|
|
625
|
-
//
|
|
626
|
-
// ─── Attribute Directives ───────────────────────────────────────────────
|
|
627
|
-
//
|
|
628
|
-
// z-bind:attr="expression" Dynamic attribute binding.
|
|
629
|
-
// :attr="expression" Shorthand for z-bind:attr.
|
|
630
|
-
// false/null/undefined → removes the attribute.
|
|
631
|
-
// true → sets empty attribute (e.g. disabled="").
|
|
632
|
-
//
|
|
633
|
-
// z-class="expression" Dynamic class binding.
|
|
634
|
-
// String: space-separated class names.
|
|
635
|
-
// Array: list of class names (falsy filtered).
|
|
636
|
-
// Object: { className: condition } map.
|
|
637
|
-
//
|
|
638
|
-
// z-style="expression" Dynamic inline styles.
|
|
639
|
-
// String: appended to existing cssText.
|
|
640
|
-
// Object: { property: value } map (camelCase keys).
|
|
641
|
-
//
|
|
642
|
-
// z-html="expression" Set innerHTML from expression (use trusted content only).
|
|
643
|
-
// z-text="expression" Set textContent from expression (safe, no HTML).
|
|
644
|
-
//
|
|
645
|
-
// ─── Form & Reference Directives ────────────────────────────────────────
|
|
646
|
-
//
|
|
647
|
-
// z-model="stateKey" Two-way binding for form elements.
|
|
648
|
-
// Supports: input, textarea, select, select[multiple], contenteditable.
|
|
649
|
-
// Nested keys: z-model="user.name" → this.state.user.name.
|
|
650
|
-
// Modifiers (boolean attributes on same element):
|
|
651
|
-
// z-lazy — update on 'change' instead of 'input' (update on blur).
|
|
652
|
-
// z-trim — auto .trim() whitespace before writing to state.
|
|
653
|
-
// z-number — force Number() conversion regardless of input type.
|
|
654
|
-
//
|
|
655
|
-
// z-ref="name" Element reference → this.refs.name.
|
|
656
|
-
//
|
|
657
|
-
// ─── Event Directives ───────────────────────────────────────────────────
|
|
658
|
-
//
|
|
659
|
-
// @event="method" Event binding with delegation (shorthand).
|
|
660
|
-
// z-on:event="method" Event binding with delegation (full syntax).
|
|
661
|
-
// @event="method(args)" Pass arguments: strings, numbers, booleans,
|
|
662
|
-
// null, $event, state.key references.
|
|
663
|
-
//
|
|
664
|
-
// Event Modifiers (chainable with dots):
|
|
665
|
-
// .prevent event.preventDefault()
|
|
666
|
-
// .stop event.stopPropagation()
|
|
667
|
-
// .self Only fire if event.target === element itself.
|
|
668
|
-
// .once Handler fires at most once per element.
|
|
669
|
-
// .capture addEventListener with { capture: true }.
|
|
670
|
-
// .passive addEventListener with { passive: true }.
|
|
671
|
-
// .debounce.{ms} Debounce: delay until {ms}ms idle (default 250).
|
|
672
|
-
// .throttle.{ms} Throttle: invoke at most once per {ms}ms (default 250).
|
|
673
|
-
//
|
|
674
|
-
// ─── Special Directives ─────────────────────────────────────────────────
|
|
675
|
-
//
|
|
676
|
-
// z-cloak Hidden until rendered (auto-removed after mount).
|
|
677
|
-
// Global CSS: [z-cloak] { display: none !important }.
|
|
678
|
-
// Also injects: *, *::before, *::after { -webkit-tap-highlight-color: transparent }.
|
|
679
|
-
//
|
|
680
|
-
// z-pre Skip all directive processing for this element
|
|
681
|
-
// and its descendants.
|
|
682
|
-
//
|
|
683
|
-
// ─── Slot System ────────────────────────────────────────────────────────
|
|
684
|
-
//
|
|
685
|
-
// <slot> Default slot — replaced with child content
|
|
686
|
-
// passed by the parent component.
|
|
687
|
-
// <slot name="header"> Named slot — replaced with child content that
|
|
688
|
-
// has a matching slot="header" attribute.
|
|
689
|
-
// <slot>fallback</slot> Fallback content shown when no slot content provided.
|
|
690
|
-
//
|
|
691
|
-
// Parent usage:
|
|
692
|
-
// <my-component>
|
|
693
|
-
// <h1 slot="header">Title</h1> (→ named slot "header")
|
|
694
|
-
// <p>Body text</p> (→ default slot)
|
|
695
|
-
// </my-component>
|
|
696
|
-
//
|
|
697
|
-
// ─── Processing Order ───────────────────────────────────────────────────
|
|
698
|
-
//
|
|
699
|
-
// 1. z-for (pre-innerHTML expansion)
|
|
700
|
-
// 2. z-if chain (DOM removal)
|
|
701
|
-
// 3. z-show (display toggle)
|
|
702
|
-
// 4. z-bind / : (dynamic attributes)
|
|
703
|
-
// 5. z-class (dynamic classes)
|
|
704
|
-
// 6. z-style (dynamic styles)
|
|
705
|
-
// 7. z-html/text (content injection)
|
|
706
|
-
// 8. @/z-on (event binding)
|
|
707
|
-
// 9. z-ref (element references)
|
|
708
|
-
// 10. z-model (two-way binding)
|
|
709
|
-
// 11. z-cloak (attribute removal)
|
|
710
|
-
//
|
|
711
|
-
// ---------------------------------------------------------------------------
|
|
712
|
-
|
|
713
|
-
/**
|
|
714
|
-
* Supported event modifier strings for `@event` and `z-on:event` bindings.
|
|
715
|
-
* Modifiers are appended to the event name with dots, e.g. `@click.prevent.stop`.
|
|
716
|
-
*/
|
|
717
|
-
type EventModifier =
|
|
718
|
-
| 'prevent'
|
|
719
|
-
| 'stop'
|
|
720
|
-
| 'self'
|
|
721
|
-
| 'once'
|
|
722
|
-
| 'capture'
|
|
723
|
-
| 'passive'
|
|
724
|
-
| `debounce`
|
|
725
|
-
| `debounce.${number}`
|
|
726
|
-
| `throttle`
|
|
727
|
-
| `throttle.${number}`;
|
|
728
|
-
|
|
729
|
-
export { EventModifier };
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
// ---------------------------------------------------------------------------
|
|
733
|
-
// Router
|
|
734
|
-
// ---------------------------------------------------------------------------
|
|
735
|
-
|
|
736
|
-
/** A single route definition. */
|
|
737
|
-
interface RouteDefinition {
|
|
738
|
-
/**
|
|
739
|
-
* URL pattern. Supports `:param` segments and `*` wildcard.
|
|
740
|
-
* @example '/user/:id'
|
|
741
|
-
*/
|
|
742
|
-
path: string;
|
|
743
|
-
|
|
744
|
-
/**
|
|
745
|
-
* Registered component name (auto-mounted), or a render function.
|
|
746
|
-
*/
|
|
747
|
-
component: string | ((route: NavigationContext) => string);
|
|
748
|
-
|
|
749
|
-
/** Async function called before mounting (for lazy-loading modules). */
|
|
750
|
-
load?: () => Promise<any>;
|
|
751
|
-
|
|
752
|
-
/**
|
|
753
|
-
* An additional path that also matches this route.
|
|
754
|
-
* Missing `:param` values will be `undefined`.
|
|
755
|
-
*/
|
|
756
|
-
fallback?: string;
|
|
757
|
-
}
|
|
758
|
-
|
|
759
|
-
/** Navigation context passed to guards and `onChange` listeners. */
|
|
760
|
-
interface NavigationContext {
|
|
761
|
-
/** The matched route definition. */
|
|
762
|
-
route: RouteDefinition;
|
|
763
|
-
/** Parsed `:param` values. */
|
|
764
|
-
params: Record<string, string>;
|
|
765
|
-
/** Parsed query-string values. */
|
|
766
|
-
query: Record<string, string>;
|
|
767
|
-
/** Matched path (base-stripped in history mode). */
|
|
768
|
-
path: string;
|
|
769
|
-
}
|
|
770
|
-
|
|
771
|
-
/** Router configuration. */
|
|
772
|
-
interface RouterConfig {
|
|
773
|
-
/** Outlet element where route components are rendered. */
|
|
774
|
-
el?: string | Element;
|
|
775
|
-
/** Routing mode (default: `'history'`; `'hash'` for file:// or hash routing). */
|
|
776
|
-
mode?: 'history' | 'hash';
|
|
777
|
-
/**
|
|
778
|
-
* Base path prefix (e.g. `'/my-app'`).
|
|
779
|
-
* Auto-detected from `<base href>` or `window.__ZQ_BASE` if not set.
|
|
780
|
-
*/
|
|
781
|
-
base?: string;
|
|
782
|
-
/** Route definitions. */
|
|
783
|
-
routes?: RouteDefinition[];
|
|
784
|
-
/** Component name to render when no route matches (404). */
|
|
785
|
-
fallback?: string;
|
|
786
|
-
}
|
|
787
|
-
|
|
788
|
-
/** The SPA router instance. */
|
|
789
|
-
interface RouterInstance {
|
|
790
|
-
/** Push a new state and resolve the route. */
|
|
791
|
-
navigate(path: string, options?: { state?: any }): RouterInstance;
|
|
792
|
-
/** Replace the current state (no new history entry). */
|
|
793
|
-
replace(path: string, options?: { state?: any }): RouterInstance;
|
|
794
|
-
/** `history.back()` */
|
|
795
|
-
back(): RouterInstance;
|
|
796
|
-
/** `history.forward()` */
|
|
797
|
-
forward(): RouterInstance;
|
|
798
|
-
/** `history.go(n)` */
|
|
799
|
-
go(n: number): RouterInstance;
|
|
800
|
-
|
|
801
|
-
/** Add a route dynamically. Chainable. */
|
|
802
|
-
add(route: RouteDefinition): RouterInstance;
|
|
803
|
-
/** Remove a route by path. */
|
|
804
|
-
remove(path: string): RouterInstance;
|
|
805
|
-
|
|
806
|
-
/**
|
|
807
|
-
* Navigation guard — runs before each route change.
|
|
808
|
-
* Return `false` to cancel, or a `string` to redirect.
|
|
809
|
-
*/
|
|
810
|
-
beforeEach(
|
|
811
|
-
fn: (to: NavigationContext, from: NavigationContext | null) => boolean | string | void | Promise<boolean | string | void>,
|
|
812
|
-
): RouterInstance;
|
|
813
|
-
|
|
814
|
-
/** Post-navigation hook. */
|
|
815
|
-
afterEach(
|
|
816
|
-
fn: (to: NavigationContext, from: NavigationContext | null) => void | Promise<void>,
|
|
817
|
-
): RouterInstance;
|
|
818
|
-
|
|
819
|
-
/**
|
|
820
|
-
* Subscribe to route changes.
|
|
821
|
-
* @returns An unsubscribe function.
|
|
822
|
-
*/
|
|
823
|
-
onChange(
|
|
824
|
-
fn: (to: NavigationContext, from: NavigationContext | null) => void,
|
|
825
|
-
): () => void;
|
|
826
|
-
|
|
827
|
-
/** Teardown the router and mounted component. */
|
|
828
|
-
destroy(): void;
|
|
829
|
-
|
|
830
|
-
/** Resolve a path applying the base prefix. */
|
|
831
|
-
resolve(path: string): string;
|
|
832
|
-
|
|
833
|
-
// -- Properties ----------------------------------------------------------
|
|
834
|
-
/** Current navigation context. */
|
|
835
|
-
readonly current: NavigationContext | null;
|
|
836
|
-
/** Current path (base-stripped in history mode). */
|
|
837
|
-
readonly path: string;
|
|
838
|
-
/** Parsed query-string object. */
|
|
839
|
-
readonly query: Record<string, string>;
|
|
840
|
-
/** Configured base path. */
|
|
841
|
-
readonly base: string;
|
|
842
|
-
}
|
|
843
|
-
|
|
844
|
-
/** Create and activate a client-side SPA router. */
|
|
845
|
-
export function createRouter(config: RouterConfig): RouterInstance;
|
|
846
|
-
|
|
847
|
-
/** Get the currently active router instance. */
|
|
848
|
-
export function getRouter(): RouterInstance | null;
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
// ---------------------------------------------------------------------------
|
|
852
|
-
// Store
|
|
853
|
-
// ---------------------------------------------------------------------------
|
|
854
|
-
|
|
855
|
-
/** Store configuration. */
|
|
856
|
-
interface StoreConfig<
|
|
857
|
-
S extends Record<string, any> = Record<string, any>,
|
|
858
|
-
A extends Record<string, (state: S, ...args: any[]) => any> = Record<string, (state: S, ...args: any[]) => any>,
|
|
859
|
-
G extends Record<string, (state: S) => any> = Record<string, (state: S) => any>,
|
|
860
|
-
> {
|
|
861
|
-
/** Initial state. Function form creates a fresh copy. */
|
|
862
|
-
state?: S | (() => S);
|
|
863
|
-
|
|
864
|
-
/**
|
|
865
|
-
* Named action functions. The first argument is always the reactive `state`.
|
|
866
|
-
*/
|
|
867
|
-
actions?: A;
|
|
868
|
-
|
|
869
|
-
/** Computed getters derived from state (lazily evaluated). */
|
|
870
|
-
getters?: G;
|
|
871
|
-
|
|
872
|
-
/** Log dispatched actions to the console. */
|
|
873
|
-
debug?: boolean;
|
|
874
|
-
}
|
|
875
|
-
|
|
876
|
-
/** A store action history entry. */
|
|
877
|
-
interface StoreHistoryEntry {
|
|
878
|
-
action: string;
|
|
879
|
-
args: any[];
|
|
880
|
-
timestamp: number;
|
|
881
|
-
}
|
|
882
|
-
|
|
883
|
-
/** The reactive store instance. */
|
|
884
|
-
interface StoreInstance<
|
|
885
|
-
S extends Record<string, any> = Record<string, any>,
|
|
886
|
-
A extends Record<string, (state: S, ...args: any[]) => any> = Record<string, (state: S, ...args: any[]) => any>,
|
|
887
|
-
G extends Record<string, (state: S) => any> = Record<string, (state: S) => any>,
|
|
888
|
-
> {
|
|
889
|
-
/** Reactive state proxy. Read / write triggers subscriptions. */
|
|
890
|
-
state: S & ReactiveProxy<S>;
|
|
891
|
-
|
|
892
|
-
/** Computed getters object. */
|
|
893
|
-
readonly getters: { readonly [K in keyof G]: ReturnType<G[K]> };
|
|
894
|
-
|
|
895
|
-
/** Log of all dispatched actions. */
|
|
896
|
-
readonly history: ReadonlyArray<StoreHistoryEntry>;
|
|
897
|
-
|
|
898
|
-
/**
|
|
899
|
-
* Execute a named action.
|
|
900
|
-
* @returns The action's return value.
|
|
901
|
-
*/
|
|
902
|
-
dispatch<K extends keyof A>(
|
|
903
|
-
name: K,
|
|
904
|
-
...args: A[K] extends (state: any, ...rest: infer P) => any ? P : any[]
|
|
905
|
-
): ReturnType<A[K]>;
|
|
906
|
-
dispatch(name: string, ...args: any[]): any;
|
|
907
|
-
|
|
908
|
-
/**
|
|
909
|
-
* Subscribe to changes on a specific state key.
|
|
910
|
-
* @returns An unsubscribe function.
|
|
911
|
-
*/
|
|
912
|
-
subscribe(key: string, fn: (value: any, oldValue: any, key: string) => void): () => void;
|
|
913
|
-
/** Subscribe to all state changes (wildcard). */
|
|
914
|
-
subscribe(fn: (key: string, value: any, oldValue: any) => void): () => void;
|
|
915
|
-
|
|
916
|
-
/** Deep clone of the current state. */
|
|
917
|
-
snapshot(): S;
|
|
918
|
-
|
|
919
|
-
/** Replace the entire state. */
|
|
920
|
-
replaceState(newState: Partial<S>): void;
|
|
921
|
-
|
|
922
|
-
/**
|
|
923
|
-
* Add middleware. Return `false` from `fn` to block the action.
|
|
924
|
-
* Chainable.
|
|
925
|
-
*/
|
|
926
|
-
use(fn: (actionName: string, args: any[], state: S) => boolean | void): StoreInstance<S, A, G>;
|
|
927
|
-
|
|
928
|
-
/** Replace state and clear action history. */
|
|
929
|
-
reset(initialState: Partial<S>): void;
|
|
930
|
-
}
|
|
931
|
-
|
|
932
|
-
/** Create a new global reactive store. */
|
|
933
|
-
export function createStore<
|
|
934
|
-
S extends Record<string, any>,
|
|
935
|
-
A extends Record<string, (state: S, ...args: any[]) => any>,
|
|
936
|
-
G extends Record<string, (state: S) => any>,
|
|
937
|
-
>(config: StoreConfig<S, A, G>): StoreInstance<S, A, G>;
|
|
938
|
-
export function createStore<
|
|
939
|
-
S extends Record<string, any>,
|
|
940
|
-
A extends Record<string, (state: S, ...args: any[]) => any>,
|
|
941
|
-
G extends Record<string, (state: S) => any>,
|
|
942
|
-
>(name: string, config: StoreConfig<S, A, G>): StoreInstance<S, A, G>;
|
|
943
|
-
|
|
944
|
-
/** Retrieve a previously created store by name (default: `'default'`). */
|
|
945
|
-
export function getStore<
|
|
946
|
-
S extends Record<string, any> = Record<string, any>,
|
|
947
|
-
A extends Record<string, (state: S, ...args: any[]) => any> = Record<string, (state: S, ...args: any[]) => any>,
|
|
948
|
-
G extends Record<string, (state: S) => any> = Record<string, (state: S) => any>,
|
|
949
|
-
>(name?: string): StoreInstance<S, A, G> | null;
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
// ---------------------------------------------------------------------------
|
|
953
|
-
// HTTP Client
|
|
954
|
-
// ---------------------------------------------------------------------------
|
|
955
|
-
|
|
956
|
-
/** The response object resolved by all HTTP request methods (except `raw`). */
|
|
957
|
-
interface HttpResponse<T = any> {
|
|
958
|
-
/** `true` if status 200-299. */
|
|
959
|
-
ok: boolean;
|
|
960
|
-
/** HTTP status code. */
|
|
961
|
-
status: number;
|
|
962
|
-
/** HTTP status text. */
|
|
963
|
-
statusText: string;
|
|
964
|
-
/** Response headers as a plain object. */
|
|
965
|
-
headers: Record<string, string>;
|
|
966
|
-
/** Auto-parsed body (JSON, text, or Blob depending on content type). */
|
|
967
|
-
data: T;
|
|
968
|
-
/** Raw `fetch` Response object. */
|
|
969
|
-
response: Response;
|
|
970
|
-
}
|
|
971
|
-
|
|
972
|
-
/** Per-request options passed to HTTP methods. */
|
|
973
|
-
interface HttpRequestOptions extends Omit<RequestInit, 'body' | 'method'> {
|
|
974
|
-
/** Additional headers (merged with defaults). */
|
|
975
|
-
headers?: Record<string, string>;
|
|
976
|
-
/** Override default timeout (ms). */
|
|
977
|
-
timeout?: number;
|
|
978
|
-
/** Abort signal for cancellation. */
|
|
979
|
-
signal?: AbortSignal;
|
|
980
|
-
}
|
|
981
|
-
|
|
982
|
-
/** Global HTTP configuration options. */
|
|
983
|
-
interface HttpConfigureOptions {
|
|
984
|
-
/** Prepended to non-absolute URLs. */
|
|
985
|
-
baseURL?: string;
|
|
986
|
-
/** Default headers (merged, not replaced). */
|
|
987
|
-
headers?: Record<string, string>;
|
|
988
|
-
/** Default timeout in ms (default 30 000). Set `0` to disable. */
|
|
989
|
-
timeout?: number;
|
|
990
|
-
}
|
|
991
|
-
|
|
992
|
-
/** Request interceptor function. */
|
|
993
|
-
type HttpRequestInterceptor = (
|
|
994
|
-
fetchOpts: RequestInit & { headers: Record<string, string> },
|
|
995
|
-
url: string,
|
|
996
|
-
) => void | false | { url?: string; options?: RequestInit } | Promise<void | false | { url?: string; options?: RequestInit }>;
|
|
997
|
-
|
|
998
|
-
/** Response interceptor function. */
|
|
999
|
-
type HttpResponseInterceptor = (result: HttpResponse) => void | Promise<void>;
|
|
1000
|
-
|
|
1001
|
-
/** The `$.http` namespace. */
|
|
1002
|
-
interface HttpClient {
|
|
1003
|
-
/** GET request. `params` appended as query string. */
|
|
1004
|
-
get<T = any>(url: string, params?: Record<string, any> | null, opts?: HttpRequestOptions): Promise<HttpResponse<T>>;
|
|
1005
|
-
/** POST request. `data` sent as JSON body (or FormData). */
|
|
1006
|
-
post<T = any>(url: string, data?: any, opts?: HttpRequestOptions): Promise<HttpResponse<T>>;
|
|
1007
|
-
/** PUT request. */
|
|
1008
|
-
put<T = any>(url: string, data?: any, opts?: HttpRequestOptions): Promise<HttpResponse<T>>;
|
|
1009
|
-
/** PATCH request. */
|
|
1010
|
-
patch<T = any>(url: string, data?: any, opts?: HttpRequestOptions): Promise<HttpResponse<T>>;
|
|
1011
|
-
/** DELETE request. */
|
|
1012
|
-
delete<T = any>(url: string, data?: any, opts?: HttpRequestOptions): Promise<HttpResponse<T>>;
|
|
1013
|
-
|
|
1014
|
-
/** Update default configuration for all subsequent requests. */
|
|
1015
|
-
configure(options: HttpConfigureOptions): void;
|
|
1016
|
-
|
|
1017
|
-
/** Add a request interceptor (called before every request). */
|
|
1018
|
-
onRequest(fn: HttpRequestInterceptor): void;
|
|
1019
|
-
|
|
1020
|
-
/** Add a response interceptor (called after every response, before error check). */
|
|
1021
|
-
onResponse(fn: HttpResponseInterceptor): void;
|
|
1022
|
-
|
|
1023
|
-
/** Create a new `AbortController` for manual request cancellation. */
|
|
1024
|
-
createAbort(): AbortController;
|
|
1025
|
-
|
|
1026
|
-
/** Direct passthrough to native `fetch()` — no JSON handling, no interceptors. */
|
|
1027
|
-
raw(url: string, opts?: RequestInit): Promise<Response>;
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
|
-
export const http: HttpClient;
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
// ---------------------------------------------------------------------------
|
|
1034
|
-
// Utilities — Functions
|
|
1035
|
-
// ---------------------------------------------------------------------------
|
|
1036
|
-
|
|
1037
|
-
/** Debounced function with a `.cancel()` helper. */
|
|
1038
|
-
interface DebouncedFunction<T extends (...args: any[]) => any> {
|
|
1039
|
-
(...args: Parameters<T>): void;
|
|
1040
|
-
/** Cancel the pending invocation. */
|
|
1041
|
-
cancel(): void;
|
|
1042
|
-
}
|
|
1043
|
-
|
|
1044
|
-
/**
|
|
1045
|
-
* Returns a debounced function that delays execution until `ms` ms of inactivity.
|
|
1046
|
-
* @param ms Default `250`.
|
|
1047
|
-
*/
|
|
1048
|
-
export function debounce<T extends (...args: any[]) => any>(fn: T, ms?: number): DebouncedFunction<T>;
|
|
1049
|
-
|
|
1050
|
-
/**
|
|
1051
|
-
* Returns a throttled function that executes at most once per `ms` ms.
|
|
1052
|
-
* @param ms Default `250`.
|
|
1053
|
-
*/
|
|
1054
|
-
export function throttle<T extends (...args: any[]) => any>(fn: T, ms?: number): (...args: Parameters<T>) => void;
|
|
1055
|
-
|
|
1056
|
-
/** Left-to-right function composition. */
|
|
1057
|
-
export function pipe<A, B>(f1: (a: A) => B): (input: A) => B;
|
|
1058
|
-
export function pipe<A, B, C>(f1: (a: A) => B, f2: (b: B) => C): (input: A) => C;
|
|
1059
|
-
export function pipe<A, B, C, D>(f1: (a: A) => B, f2: (b: B) => C, f3: (c: C) => D): (input: A) => D;
|
|
1060
|
-
export function pipe<A, B, C, D, E>(f1: (a: A) => B, f2: (b: B) => C, f3: (c: C) => D, f4: (d: D) => E): (input: A) => E;
|
|
1061
|
-
export function pipe<T>(...fns: Array<(value: any) => any>): (input: T) => any;
|
|
1062
|
-
|
|
1063
|
-
/**
|
|
1064
|
-
* Returns a function that only executes once, caching the result.
|
|
1065
|
-
*/
|
|
1066
|
-
export function once<T extends (...args: any[]) => any>(fn: T): (...args: Parameters<T>) => ReturnType<T>;
|
|
1067
|
-
|
|
1068
|
-
/** Returns a `Promise` that resolves after `ms` milliseconds. */
|
|
1069
|
-
export function sleep(ms: number): Promise<void>;
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
// ---------------------------------------------------------------------------
|
|
1073
|
-
// Utilities — Strings
|
|
1074
|
-
// ---------------------------------------------------------------------------
|
|
1075
|
-
|
|
1076
|
-
/** Escape HTML entities: `&`, `<`, `>`, `"`, `'`. */
|
|
1077
|
-
export function escapeHtml(str: string): string;
|
|
1078
|
-
|
|
1079
|
-
/**
|
|
1080
|
-
* Tagged template literal that auto-escapes interpolated values.
|
|
1081
|
-
* Use `$.trust()` to mark values as safe.
|
|
1082
|
-
*/
|
|
1083
|
-
export function html(strings: TemplateStringsArray, ...values: any[]): string;
|
|
1084
|
-
|
|
1085
|
-
/** Wrapper that marks an HTML string as trusted (not escaped by `$.html`). */
|
|
1086
|
-
interface TrustedHTML {
|
|
1087
|
-
toString(): string;
|
|
1088
|
-
}
|
|
1089
|
-
|
|
1090
|
-
/** Mark an HTML string as trusted so it won't be escaped in `$.html`. */
|
|
1091
|
-
export function trust(htmlStr: string): TrustedHTML;
|
|
1092
|
-
|
|
1093
|
-
/** Generate a UUID v4 string. */
|
|
1094
|
-
export function uuid(): string;
|
|
1095
|
-
|
|
1096
|
-
/** Convert kebab-case to camelCase. */
|
|
1097
|
-
export function camelCase(str: string): string;
|
|
1098
|
-
|
|
1099
|
-
/** Convert camelCase to kebab-case. */
|
|
1100
|
-
export function kebabCase(str: string): string;
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
// ---------------------------------------------------------------------------
|
|
1104
|
-
// Utilities — Objects
|
|
1105
|
-
// ---------------------------------------------------------------------------
|
|
1106
|
-
|
|
1107
|
-
/** Deep clone using `structuredClone` (JSON fallback). */
|
|
1108
|
-
export function deepClone<T>(obj: T): T;
|
|
1109
|
-
|
|
1110
|
-
/** Recursively merge objects. Arrays are replaced, not merged. */
|
|
1111
|
-
export function deepMerge<T extends object>(target: T, ...sources: Partial<T>[]): T;
|
|
1112
|
-
|
|
1113
|
-
/** Deep equality comparison. */
|
|
1114
|
-
export function isEqual(a: any, b: any): boolean;
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
// ---------------------------------------------------------------------------
|
|
1118
|
-
// Utilities — URL
|
|
1119
|
-
// ---------------------------------------------------------------------------
|
|
1120
|
-
|
|
1121
|
-
/** Serialize an object to a URL query string. */
|
|
1122
|
-
export function param(obj: Record<string, any>): string;
|
|
1123
|
-
|
|
1124
|
-
/** Parse a URL query string into an object. */
|
|
1125
|
-
export function parseQuery(str: string): Record<string, string>;
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
// ---------------------------------------------------------------------------
|
|
1129
|
-
// Utilities — Storage
|
|
1130
|
-
// ---------------------------------------------------------------------------
|
|
1131
|
-
|
|
1132
|
-
/** JSON-aware `localStorage` wrapper. */
|
|
1133
|
-
interface StorageWrapper {
|
|
1134
|
-
/** Get and JSON-parse a value. Returns `fallback` on missing / error. */
|
|
1135
|
-
get<T = any>(key: string, fallback?: T): T;
|
|
1136
|
-
/** JSON-stringify and store. */
|
|
1137
|
-
set(key: string, value: any): void;
|
|
1138
|
-
/** Remove a key. */
|
|
1139
|
-
remove(key: string): void;
|
|
1140
|
-
/** Clear all entries. */
|
|
1141
|
-
clear(): void;
|
|
1142
|
-
}
|
|
1143
|
-
|
|
1144
|
-
/** `localStorage` wrapper. */
|
|
1145
|
-
export const storage: StorageWrapper;
|
|
1146
|
-
|
|
1147
|
-
/** `sessionStorage` wrapper (same API as `storage`). */
|
|
1148
|
-
export const session: StorageWrapper;
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
// ---------------------------------------------------------------------------
|
|
1152
|
-
// Utilities — Event Bus
|
|
1153
|
-
// ---------------------------------------------------------------------------
|
|
1154
|
-
|
|
1155
|
-
/** Singleton pub/sub event bus for cross-component communication. */
|
|
1156
|
-
interface EventBus {
|
|
1157
|
-
/** Subscribe. Returns an unsubscribe function. */
|
|
1158
|
-
on(event: string, fn: (...args: any[]) => void): () => void;
|
|
1159
|
-
/** Unsubscribe a specific handler. */
|
|
1160
|
-
off(event: string, fn: (...args: any[]) => void): void;
|
|
1161
|
-
/** Emit an event with arguments. */
|
|
1162
|
-
emit(event: string, ...args: any[]): void;
|
|
1163
|
-
/** Subscribe for a single invocation. Returns an unsubscribe function. */
|
|
1164
|
-
once(event: string, fn: (...args: any[]) => void): () => void;
|
|
1165
|
-
/** Remove all listeners. */
|
|
1166
|
-
clear(): void;
|
|
1167
|
-
}
|
|
1168
|
-
|
|
1169
|
-
export const bus: EventBus;
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
// ---------------------------------------------------------------------------
|
|
1173
|
-
// Error Handling
|
|
1174
|
-
// ---------------------------------------------------------------------------
|
|
1175
|
-
|
|
1176
|
-
/** All structured error codes used by zQuery. */
|
|
1177
|
-
export const ErrorCode: {
|
|
1178
|
-
// Reactive
|
|
1179
|
-
readonly REACTIVE_CALLBACK: 'ZQ_REACTIVE_CALLBACK';
|
|
1180
|
-
readonly SIGNAL_CALLBACK: 'ZQ_SIGNAL_CALLBACK';
|
|
1181
|
-
readonly EFFECT_EXEC: 'ZQ_EFFECT_EXEC';
|
|
1182
|
-
|
|
1183
|
-
// Expression parser
|
|
1184
|
-
readonly EXPR_PARSE: 'ZQ_EXPR_PARSE';
|
|
1185
|
-
readonly EXPR_EVAL: 'ZQ_EXPR_EVAL';
|
|
1186
|
-
readonly EXPR_UNSAFE_ACCESS: 'ZQ_EXPR_UNSAFE_ACCESS';
|
|
1187
|
-
|
|
1188
|
-
// Component
|
|
1189
|
-
readonly COMP_INVALID_NAME: 'ZQ_COMP_INVALID_NAME';
|
|
1190
|
-
readonly COMP_NOT_FOUND: 'ZQ_COMP_NOT_FOUND';
|
|
1191
|
-
readonly COMP_MOUNT_TARGET: 'ZQ_COMP_MOUNT_TARGET';
|
|
1192
|
-
readonly COMP_RENDER: 'ZQ_COMP_RENDER';
|
|
1193
|
-
readonly COMP_LIFECYCLE: 'ZQ_COMP_LIFECYCLE';
|
|
1194
|
-
readonly COMP_RESOURCE: 'ZQ_COMP_RESOURCE';
|
|
1195
|
-
readonly COMP_DIRECTIVE: 'ZQ_COMP_DIRECTIVE';
|
|
1196
|
-
|
|
1197
|
-
// Router
|
|
1198
|
-
readonly ROUTER_LOAD: 'ZQ_ROUTER_LOAD';
|
|
1199
|
-
readonly ROUTER_GUARD: 'ZQ_ROUTER_GUARD';
|
|
1200
|
-
readonly ROUTER_RESOLVE: 'ZQ_ROUTER_RESOLVE';
|
|
1201
|
-
|
|
1202
|
-
// Store
|
|
1203
|
-
readonly STORE_ACTION: 'ZQ_STORE_ACTION';
|
|
1204
|
-
readonly STORE_MIDDLEWARE: 'ZQ_STORE_MIDDLEWARE';
|
|
1205
|
-
readonly STORE_SUBSCRIBE: 'ZQ_STORE_SUBSCRIBE';
|
|
1206
|
-
|
|
1207
|
-
// HTTP
|
|
1208
|
-
readonly HTTP_REQUEST: 'ZQ_HTTP_REQUEST';
|
|
1209
|
-
readonly HTTP_TIMEOUT: 'ZQ_HTTP_TIMEOUT';
|
|
1210
|
-
readonly HTTP_INTERCEPTOR: 'ZQ_HTTP_INTERCEPTOR';
|
|
1211
|
-
readonly HTTP_PARSE: 'ZQ_HTTP_PARSE';
|
|
1212
|
-
|
|
1213
|
-
// General
|
|
1214
|
-
readonly INVALID_ARGUMENT: 'ZQ_INVALID_ARGUMENT';
|
|
1215
|
-
};
|
|
1216
|
-
|
|
1217
|
-
/** Union of all error code string values. */
|
|
1218
|
-
export type ErrorCodeValue = typeof ErrorCode[keyof typeof ErrorCode];
|
|
1219
|
-
|
|
1220
|
-
/** Structured error class used throughout zQuery. */
|
|
1221
|
-
export class ZQueryError extends Error {
|
|
1222
|
-
readonly name: 'ZQueryError';
|
|
1223
|
-
/** Machine-readable error code (e.g. `'ZQ_COMP_RENDER'`). */
|
|
1224
|
-
readonly code: ErrorCodeValue;
|
|
1225
|
-
/** Extra contextual data (component name, expression string, etc.). */
|
|
1226
|
-
readonly context: Record<string, any>;
|
|
1227
|
-
/** Original error that caused this one, if any. */
|
|
1228
|
-
readonly cause?: Error;
|
|
1229
|
-
|
|
1230
|
-
constructor(
|
|
1231
|
-
code: ErrorCodeValue,
|
|
1232
|
-
message: string,
|
|
1233
|
-
context?: Record<string, any>,
|
|
1234
|
-
cause?: Error,
|
|
1235
|
-
);
|
|
1236
|
-
}
|
|
1237
|
-
|
|
1238
|
-
/** Error handler callback type. */
|
|
1239
|
-
export type ZQueryErrorHandler = (error: ZQueryError) => void;
|
|
1240
|
-
|
|
1241
|
-
/**
|
|
1242
|
-
* Register a global error handler. Called whenever zQuery catches an
|
|
1243
|
-
* error internally. Pass `null` to remove.
|
|
1244
|
-
*/
|
|
1245
|
-
export function onError(handler: ZQueryErrorHandler | null): void;
|
|
1246
|
-
|
|
1247
|
-
/**
|
|
1248
|
-
* Report an error through the global handler and console.
|
|
1249
|
-
* Non-throwing — used for recoverable errors in callbacks, lifecycle hooks, etc.
|
|
1250
|
-
*/
|
|
1251
|
-
export function reportError(
|
|
1252
|
-
code: ErrorCodeValue,
|
|
1253
|
-
message: string,
|
|
1254
|
-
context?: Record<string, any>,
|
|
1255
|
-
cause?: Error,
|
|
1256
|
-
): void;
|
|
1257
|
-
|
|
1258
|
-
/**
|
|
1259
|
-
* Wrap a callback so that thrown errors are caught, reported via `reportError`,
|
|
1260
|
-
* and don't crash the current execution context.
|
|
1261
|
-
*/
|
|
1262
|
-
export function guardCallback<T extends (...args: any[]) => any>(
|
|
1263
|
-
fn: T,
|
|
1264
|
-
code: ErrorCodeValue,
|
|
1265
|
-
context?: Record<string, any>,
|
|
1266
|
-
): (...args: Parameters<T>) => ReturnType<T> | undefined;
|
|
1267
|
-
|
|
1268
|
-
/**
|
|
1269
|
-
* Validate a required value is defined and of the expected type.
|
|
1270
|
-
* Throws `ZQueryError` with `INVALID_ARGUMENT` on failure.
|
|
1271
|
-
*/
|
|
1272
|
-
export function validate(value: any, name: string, expectedType?: string): void;
|
|
1273
|
-
|
|
13
|
+
// Re-export every public type from the modular type files
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
|
|
16
|
+
export { ZQueryCollection } from './types/collection';
|
|
17
|
+
|
|
18
|
+
export {
|
|
19
|
+
ReactiveProxy,
|
|
20
|
+
reactive,
|
|
21
|
+
Signal,
|
|
22
|
+
signal,
|
|
23
|
+
computed,
|
|
24
|
+
effect,
|
|
25
|
+
} from './types/reactive';
|
|
26
|
+
|
|
27
|
+
export {
|
|
28
|
+
PageItem,
|
|
29
|
+
PagesConfig,
|
|
30
|
+
ComponentDefinition,
|
|
31
|
+
ComponentInstance,
|
|
32
|
+
component,
|
|
33
|
+
mount,
|
|
34
|
+
mountAll,
|
|
35
|
+
getInstance,
|
|
36
|
+
destroy,
|
|
37
|
+
getRegistry,
|
|
38
|
+
prefetch,
|
|
39
|
+
StyleHandle,
|
|
40
|
+
StyleOptions,
|
|
41
|
+
style,
|
|
42
|
+
} from './types/component';
|
|
43
|
+
|
|
44
|
+
export {
|
|
45
|
+
RouteDefinition,
|
|
46
|
+
NavigationContext,
|
|
47
|
+
RouterConfig,
|
|
48
|
+
RouterInstance,
|
|
49
|
+
createRouter,
|
|
50
|
+
getRouter,
|
|
51
|
+
} from './types/router';
|
|
52
|
+
|
|
53
|
+
export {
|
|
54
|
+
StoreConfig,
|
|
55
|
+
StoreHistoryEntry,
|
|
56
|
+
StoreInstance,
|
|
57
|
+
createStore,
|
|
58
|
+
getStore,
|
|
59
|
+
} from './types/store';
|
|
60
|
+
|
|
61
|
+
export {
|
|
62
|
+
HttpResponse,
|
|
63
|
+
HttpRequestOptions,
|
|
64
|
+
HttpConfigureOptions,
|
|
65
|
+
HttpRequestInterceptor,
|
|
66
|
+
HttpResponseInterceptor,
|
|
67
|
+
HttpClient,
|
|
68
|
+
http,
|
|
69
|
+
} from './types/http';
|
|
70
|
+
|
|
71
|
+
export {
|
|
72
|
+
DebouncedFunction,
|
|
73
|
+
debounce,
|
|
74
|
+
throttle,
|
|
75
|
+
pipe,
|
|
76
|
+
once,
|
|
77
|
+
sleep,
|
|
78
|
+
escapeHtml,
|
|
79
|
+
html,
|
|
80
|
+
TrustedHTML,
|
|
81
|
+
trust,
|
|
82
|
+
uuid,
|
|
83
|
+
camelCase,
|
|
84
|
+
kebabCase,
|
|
85
|
+
deepClone,
|
|
86
|
+
deepMerge,
|
|
87
|
+
isEqual,
|
|
88
|
+
param,
|
|
89
|
+
parseQuery,
|
|
90
|
+
StorageWrapper,
|
|
91
|
+
storage,
|
|
92
|
+
session,
|
|
93
|
+
EventBus,
|
|
94
|
+
bus,
|
|
95
|
+
} from './types/utils';
|
|
96
|
+
|
|
97
|
+
export {
|
|
98
|
+
ErrorCode,
|
|
99
|
+
ErrorCodeValue,
|
|
100
|
+
ZQueryError,
|
|
101
|
+
ZQueryErrorHandler,
|
|
102
|
+
onError,
|
|
103
|
+
reportError,
|
|
104
|
+
guardCallback,
|
|
105
|
+
validate,
|
|
106
|
+
} from './types/errors';
|
|
107
|
+
|
|
108
|
+
export {
|
|
109
|
+
morph,
|
|
110
|
+
morphElement,
|
|
111
|
+
safeEval,
|
|
112
|
+
EventModifier,
|
|
113
|
+
} from './types/misc';
|
|
1274
114
|
|
|
1275
115
|
// ---------------------------------------------------------------------------
|
|
1276
116
|
// $ — Main function & namespace
|
|
1277
117
|
// ---------------------------------------------------------------------------
|
|
1278
118
|
|
|
119
|
+
import type { ZQueryCollection } from './types/collection';
|
|
120
|
+
import type { reactive, Signal, signal, computed, effect } from './types/reactive';
|
|
121
|
+
import type { component, mount, mountAll, getInstance, destroy, getRegistry, prefetch, style } from './types/component';
|
|
122
|
+
import type { createRouter, getRouter } from './types/router';
|
|
123
|
+
import type { createStore, getStore } from './types/store';
|
|
124
|
+
import type { HttpClient } from './types/http';
|
|
125
|
+
import type {
|
|
126
|
+
debounce, throttle, pipe, once, sleep,
|
|
127
|
+
escapeHtml, html, trust, uuid, camelCase, kebabCase,
|
|
128
|
+
deepClone, deepMerge, isEqual, param, parseQuery,
|
|
129
|
+
StorageWrapper, EventBus,
|
|
130
|
+
} from './types/utils';
|
|
131
|
+
import type { onError, ZQueryError, ErrorCode } from './types/errors';
|
|
132
|
+
import type { morph, morphElement, safeEval } from './types/misc';
|
|
133
|
+
|
|
1279
134
|
/**
|
|
1280
135
|
* Main selector / DOM-ready function — always returns a `ZQueryCollection` (like jQuery).
|
|
1281
136
|
*
|
|
@@ -1286,7 +141,7 @@ export function validate(value: any, name: string, expectedType?: string): void;
|
|
|
1286
141
|
*/
|
|
1287
142
|
interface ZQueryStatic {
|
|
1288
143
|
(selector: string, context?: string | Element): ZQueryCollection;
|
|
1289
|
-
(element: Element): ZQueryCollection;
|
|
144
|
+
(element: Element | Window): ZQueryCollection;
|
|
1290
145
|
(nodeList: NodeList | HTMLCollection | Element[]): ZQueryCollection;
|
|
1291
146
|
(fn: () => void): void;
|
|
1292
147
|
|
|
@@ -1300,7 +155,7 @@ interface ZQueryStatic {
|
|
|
1300
155
|
* - `$.all(nodeList)` → wrap NodeList
|
|
1301
156
|
*/
|
|
1302
157
|
all(selector: string, context?: string | Element): ZQueryCollection;
|
|
1303
|
-
all(element: Element): ZQueryCollection;
|
|
158
|
+
all(element: Element | Window): ZQueryCollection;
|
|
1304
159
|
all(nodeList: NodeList | HTMLCollection | Element[]): ZQueryCollection;
|
|
1305
160
|
|
|
1306
161
|
// -- Quick-ref shortcuts -------------------------------------------------
|
|
@@ -1326,7 +181,7 @@ interface ZQueryStatic {
|
|
|
1326
181
|
tag: string,
|
|
1327
182
|
attrs?: Record<string, any>,
|
|
1328
183
|
...children: Array<string | Node>
|
|
1329
|
-
):
|
|
184
|
+
): ZQueryCollection;
|
|
1330
185
|
|
|
1331
186
|
/** Register a DOMContentLoaded callback (fires immediately if already loaded). */
|
|
1332
187
|
ready(fn: () => void): void;
|
|
@@ -1334,6 +189,9 @@ interface ZQueryStatic {
|
|
|
1334
189
|
/** Global event delegation on `document`. */
|
|
1335
190
|
on(event: string, selector: string, handler: (this: Element, e: Event) => void): void;
|
|
1336
191
|
|
|
192
|
+
/** Direct event listener on a specific target (e.g. `window`). */
|
|
193
|
+
on(event: string, target: EventTarget, handler: (e: Event) => void): void;
|
|
194
|
+
|
|
1337
195
|
/** Direct event listener on `document` (for keydown, resize, etc.). */
|
|
1338
196
|
on(event: string, handler: (e: Event) => void): void;
|
|
1339
197
|
|
|
@@ -1358,8 +216,12 @@ interface ZQueryStatic {
|
|
|
1358
216
|
destroy: typeof destroy;
|
|
1359
217
|
/** Returns all registered component definitions. */
|
|
1360
218
|
components: typeof getRegistry;
|
|
219
|
+
/** Pre-load external templates and styles for a component. */
|
|
220
|
+
prefetch: typeof prefetch;
|
|
1361
221
|
style: typeof style;
|
|
1362
222
|
morph: typeof morph;
|
|
223
|
+
/** Morph a single element in place — preserves identity when tag name matches. */
|
|
224
|
+
morphElement: typeof morphElement;
|
|
1363
225
|
safeEval: typeof safeEval;
|
|
1364
226
|
|
|
1365
227
|
// -- Router --------------------------------------------------------------
|
|
@@ -1414,6 +276,8 @@ interface ZQueryStatic {
|
|
|
1414
276
|
// -- Meta ----------------------------------------------------------------
|
|
1415
277
|
/** Library version string. */
|
|
1416
278
|
version: string;
|
|
279
|
+
/** Minified library size string (e.g. `"~85.5 KB"`), injected at build time. */
|
|
280
|
+
libSize: string;
|
|
1417
281
|
/** Populated at build time by the CLI bundler. */
|
|
1418
282
|
meta: Record<string, any>;
|
|
1419
283
|
/** Remove `$` from `window` and return the library object. */
|
|
@@ -1428,28 +292,3 @@ export { $ as zQuery };
|
|
|
1428
292
|
export function queryAll(selector: string, context?: string | Element): ZQueryCollection;
|
|
1429
293
|
export function queryAll(element: Element): ZQueryCollection;
|
|
1430
294
|
export function queryAll(nodeList: NodeList | HTMLCollection | Element[]): ZQueryCollection;
|
|
1431
|
-
|
|
1432
|
-
export default $;
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
// ---------------------------------------------------------------------------
|
|
1436
|
-
// Global augmentation (browser)
|
|
1437
|
-
// ---------------------------------------------------------------------------
|
|
1438
|
-
|
|
1439
|
-
declare global {
|
|
1440
|
-
interface Window {
|
|
1441
|
-
/** zQuery main function & namespace. */
|
|
1442
|
-
$: ZQueryStatic;
|
|
1443
|
-
/** Alias for `$`. */
|
|
1444
|
-
zQuery: ZQueryStatic;
|
|
1445
|
-
/** Optional base path override read by the router. */
|
|
1446
|
-
__ZQ_BASE?: string;
|
|
1447
|
-
/** Inline template / style cache populated by the CLI bundler. */
|
|
1448
|
-
__zqInline?: Record<string, string>;
|
|
1449
|
-
}
|
|
1450
|
-
|
|
1451
|
-
/** Global `$` — available when loaded via `<script>` tag. */
|
|
1452
|
-
const $: ZQueryStatic;
|
|
1453
|
-
/** Global alias for `$`. */
|
|
1454
|
-
const zQuery: ZQueryStatic;
|
|
1455
|
-
}
|