zero-query 1.1.1 → 1.2.2

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.
Files changed (156) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +2 -0
  3. package/cli/args.js +33 -33
  4. package/cli/commands/build-api.js +442 -442
  5. package/cli/commands/build.js +253 -247
  6. package/cli/commands/bundle.js +1226 -1224
  7. package/cli/commands/create.js +178 -121
  8. package/cli/commands/dev/devtools/index.js +56 -56
  9. package/cli/commands/dev/devtools/js/components.js +49 -49
  10. package/cli/commands/dev/devtools/js/core.js +423 -423
  11. package/cli/commands/dev/devtools/js/elements.js +421 -421
  12. package/cli/commands/dev/devtools/js/network.js +166 -166
  13. package/cli/commands/dev/devtools/js/performance.js +73 -73
  14. package/cli/commands/dev/devtools/js/router.js +105 -105
  15. package/cli/commands/dev/devtools/js/source.js +132 -132
  16. package/cli/commands/dev/devtools/js/stats.js +35 -35
  17. package/cli/commands/dev/devtools/js/tabs.js +79 -79
  18. package/cli/commands/dev/devtools/panel.html +95 -95
  19. package/cli/commands/dev/devtools/styles.css +244 -244
  20. package/cli/commands/dev/index.js +107 -107
  21. package/cli/commands/dev/logger.js +75 -75
  22. package/cli/commands/dev/overlay.js +858 -858
  23. package/cli/commands/dev/server.js +220 -220
  24. package/cli/commands/dev/validator.js +94 -94
  25. package/cli/commands/dev/watcher.js +172 -172
  26. package/cli/help.js +114 -112
  27. package/cli/index.js +52 -52
  28. package/cli/scaffold/default/LICENSE +21 -21
  29. package/cli/scaffold/default/app/app.js +207 -207
  30. package/cli/scaffold/default/app/components/about.js +201 -201
  31. package/cli/scaffold/default/app/components/api-demo.js +143 -143
  32. package/cli/scaffold/default/app/components/contact-card.js +231 -231
  33. package/cli/scaffold/default/app/components/contacts/contacts.css +706 -706
  34. package/cli/scaffold/default/app/components/contacts/contacts.html +200 -200
  35. package/cli/scaffold/default/app/components/contacts/contacts.js +196 -196
  36. package/cli/scaffold/default/app/components/counter.js +127 -127
  37. package/cli/scaffold/default/app/components/home.js +249 -249
  38. package/cli/scaffold/default/app/components/not-found.js +16 -16
  39. package/cli/scaffold/default/app/components/playground/playground.css +115 -115
  40. package/cli/scaffold/default/app/components/playground/playground.html +161 -161
  41. package/cli/scaffold/default/app/components/playground/playground.js +116 -116
  42. package/cli/scaffold/default/app/components/todos.js +225 -225
  43. package/cli/scaffold/default/app/components/toolkit/toolkit.css +97 -97
  44. package/cli/scaffold/default/app/components/toolkit/toolkit.html +146 -146
  45. package/cli/scaffold/default/app/components/toolkit/toolkit.js +280 -280
  46. package/cli/scaffold/default/app/routes.js +15 -15
  47. package/cli/scaffold/default/app/store.js +101 -101
  48. package/cli/scaffold/default/global.css +552 -552
  49. package/cli/scaffold/default/index.html +99 -99
  50. package/cli/scaffold/minimal/app/app.js +85 -85
  51. package/cli/scaffold/minimal/app/components/about.js +68 -68
  52. package/cli/scaffold/minimal/app/components/counter.js +122 -122
  53. package/cli/scaffold/minimal/app/components/home.js +68 -68
  54. package/cli/scaffold/minimal/app/components/not-found.js +16 -16
  55. package/cli/scaffold/minimal/app/routes.js +9 -9
  56. package/cli/scaffold/minimal/app/store.js +36 -36
  57. package/cli/scaffold/minimal/global.css +300 -300
  58. package/cli/scaffold/minimal/index.html +44 -44
  59. package/cli/scaffold/ssr/app/app.js +41 -41
  60. package/cli/scaffold/ssr/app/components/about.js +55 -55
  61. package/cli/scaffold/ssr/app/components/blog/index.js +65 -65
  62. package/cli/scaffold/ssr/app/components/blog/post.js +86 -86
  63. package/cli/scaffold/ssr/app/components/home.js +37 -37
  64. package/cli/scaffold/ssr/app/components/not-found.js +15 -15
  65. package/cli/scaffold/ssr/app/routes.js +8 -8
  66. package/cli/scaffold/ssr/global.css +228 -228
  67. package/cli/scaffold/ssr/index.html +37 -37
  68. package/cli/scaffold/ssr/package.json +8 -8
  69. package/cli/scaffold/ssr/server/data/posts.js +144 -144
  70. package/cli/scaffold/ssr/server/index.js +213 -213
  71. package/cli/scaffold/webrtc/app/app.js +11 -0
  72. package/cli/scaffold/webrtc/app/components/video-room.js +441 -0
  73. package/cli/scaffold/webrtc/assets/.gitkeep +0 -0
  74. package/cli/scaffold/webrtc/global.css +250 -0
  75. package/cli/scaffold/webrtc/index.html +21 -0
  76. package/cli/scaffold/webrtc/package.json +16 -0
  77. package/cli/scaffold/webrtc/server/index.js +198 -0
  78. package/cli/utils.js +305 -287
  79. package/dist/API.md +661 -0
  80. package/dist/zquery.dist.zip +0 -0
  81. package/dist/zquery.js +10454 -6614
  82. package/dist/zquery.min.js +8 -631
  83. package/index.d.ts +570 -371
  84. package/index.js +311 -240
  85. package/package.json +77 -70
  86. package/src/component.js +1758 -1691
  87. package/src/core.js +929 -921
  88. package/src/diff.js +497 -497
  89. package/src/errors.js +209 -209
  90. package/src/expression.js +929 -922
  91. package/src/http.js +242 -242
  92. package/src/package.json +1 -1
  93. package/src/reactive.js +271 -255
  94. package/src/router.js +878 -843
  95. package/src/ssr.js +421 -418
  96. package/src/store.js +325 -318
  97. package/src/utils.js +534 -515
  98. package/src/webrtc/e2ee.js +351 -0
  99. package/src/webrtc/errors.js +116 -0
  100. package/src/webrtc/ice.js +301 -0
  101. package/src/webrtc/index.js +131 -0
  102. package/src/webrtc/joinToken.js +119 -0
  103. package/src/webrtc/observe.js +172 -0
  104. package/src/webrtc/peer.js +351 -0
  105. package/src/webrtc/reactive.js +268 -0
  106. package/src/webrtc/room.js +625 -0
  107. package/src/webrtc/sdp.js +302 -0
  108. package/src/webrtc/sfu/index.js +43 -0
  109. package/src/webrtc/sfu/livekit.js +131 -0
  110. package/src/webrtc/sfu/mediasoup.js +150 -0
  111. package/src/webrtc/signaling.js +373 -0
  112. package/src/webrtc/turn.js +237 -0
  113. package/tests/_helpers/webrtcFakes.js +289 -0
  114. package/tests/audit.test.js +4158 -4158
  115. package/tests/bench/render.bench.js +77 -0
  116. package/tests/cli.test.js +1136 -1103
  117. package/tests/compare.test.js +497 -486
  118. package/tests/component.test.js +4076 -3938
  119. package/tests/core.test.js +1926 -1910
  120. package/tests/dev-server.test.js +489 -489
  121. package/tests/diff.test.js +1416 -1416
  122. package/tests/docs.test.js +1664 -1650
  123. package/tests/electron-features.test.js +864 -864
  124. package/tests/errors.test.js +619 -619
  125. package/tests/expression.test.js +1087 -1056
  126. package/tests/http.test.js +693 -648
  127. package/tests/reactive.test.js +844 -819
  128. package/tests/router.test.js +2423 -2327
  129. package/tests/ssr.test.js +916 -870
  130. package/tests/store.test.js +840 -830
  131. package/tests/test-minifier.js +153 -153
  132. package/tests/test-ssr.js +27 -27
  133. package/tests/utils.test.js +1411 -1377
  134. package/tests/webrtc/e2ee.test.js +283 -0
  135. package/tests/webrtc/ice.test.js +202 -0
  136. package/tests/webrtc/joinToken.test.js +89 -0
  137. package/tests/webrtc/observe.test.js +111 -0
  138. package/tests/webrtc/peer.test.js +373 -0
  139. package/tests/webrtc/reactive.test.js +235 -0
  140. package/tests/webrtc/room.test.js +406 -0
  141. package/tests/webrtc/sdp.test.js +151 -0
  142. package/tests/webrtc/sfu-livekit.test.js +119 -0
  143. package/tests/webrtc/sfu.test.js +160 -0
  144. package/tests/webrtc/signaling.test.js +251 -0
  145. package/tests/webrtc/turn.test.js +256 -0
  146. package/types/collection.d.ts +383 -383
  147. package/types/component.d.ts +186 -186
  148. package/types/errors.d.ts +135 -135
  149. package/types/http.d.ts +92 -92
  150. package/types/misc.d.ts +201 -201
  151. package/types/reactive.d.ts +98 -98
  152. package/types/router.d.ts +190 -190
  153. package/types/ssr.d.ts +102 -102
  154. package/types/store.d.ts +146 -146
  155. package/types/utils.d.ts +245 -245
  156. package/types/webrtc.d.ts +653 -0
@@ -1,383 +1,383 @@
1
- /**
2
- * ZQueryCollection - chainable DOM element wrapper.
3
- *
4
- * Returned by `$()`, `$.all()`, `$.create()`, and many traversal methods.
5
- * Similar to a jQuery object: wraps an array of elements with fluent methods.
6
- *
7
- * @module collection
8
- */
9
-
10
- /**
11
- * Chainable wrapper around an array of DOM elements, similar to a jQuery object.
12
- * Returned by `$.all()` and many traversal / filtering methods.
13
- */
14
- export class ZQueryCollection {
15
- /** Number of elements in the collection. */
16
- readonly length: number;
17
-
18
- /** Access element by numeric index. */
19
- readonly [index: number]: Element;
20
-
21
- constructor(elements: Element | Element[]);
22
-
23
- // -- Iteration -----------------------------------------------------------
24
-
25
- /**
26
- * Iterate over each element. `this` inside the callback is the element.
27
- * @returns The collection (for chaining).
28
- */
29
- each(fn: (this: Element, index: number, element: Element) => void): this;
30
-
31
- /**
32
- * Map over elements and return a plain array.
33
- */
34
- map<T>(fn: (this: Element, index: number, element: Element) => T): T[];
35
-
36
- /**
37
- * Iterate elements with Array-style `forEach`. Returns `this` for chaining.
38
- */
39
- forEach(fn: (element: Element, index: number, elements: Element[]) => void): this;
40
-
41
- /** First raw element, or `null`. */
42
- first(): Element | null;
43
-
44
- /** Last raw element, or `null`. */
45
- last(): Element | null;
46
-
47
- /** New collection containing only the element at `index`. */
48
- eq(index: number): ZQueryCollection;
49
-
50
- /** Convert to a plain `Element[]`. */
51
- toArray(): Element[];
52
-
53
- /** Iterable protocol - works with `for...of` and spread. */
54
- [Symbol.iterator](): IterableIterator<Element>;
55
-
56
- // -- Traversal -----------------------------------------------------------
57
-
58
- /** Descendants matching `selector`. */
59
- find(selector: string): ZQueryCollection;
60
-
61
- /** Unique parent elements. */
62
- parent(): ZQueryCollection;
63
-
64
- /** Nearest ancestor matching `selector`. */
65
- closest(selector: string): ZQueryCollection;
66
-
67
- /** Direct children, optionally filtered by `selector`. */
68
- children(selector?: string): ZQueryCollection;
69
-
70
- /** All sibling elements. */
71
- siblings(): ZQueryCollection;
72
-
73
- /** Next sibling of each element, optionally filtered by selector. */
74
- next(selector?: string): ZQueryCollection;
75
-
76
- /** Previous sibling of each element, optionally filtered by selector. */
77
- prev(selector?: string): ZQueryCollection;
78
-
79
- /** All following siblings, optionally filtered by selector. */
80
- nextAll(selector?: string): ZQueryCollection;
81
-
82
- /** Following siblings up to (but not including) the element matching `selector`. */
83
- nextUntil(selector?: string, filter?: string): ZQueryCollection;
84
-
85
- /** All preceding siblings, optionally filtered by selector. */
86
- prevAll(selector?: string): ZQueryCollection;
87
-
88
- /** Preceding siblings up to (but not including) the element matching `selector`. */
89
- prevUntil(selector?: string, filter?: string): ZQueryCollection;
90
-
91
- /** All ancestor elements, optionally filtered by selector (deduplicated). */
92
- parents(selector?: string): ZQueryCollection;
93
-
94
- /** Ancestors up to (but not including) the element matching `selector`. */
95
- parentsUntil(selector?: string, filter?: string): ZQueryCollection;
96
-
97
- /** All child nodes including text and comment nodes. */
98
- contents(): ZQueryCollection;
99
-
100
- // -- Filtering -----------------------------------------------------------
101
-
102
- /** Keep elements matching a CSS selector or predicate. */
103
- filter(selector: string): ZQueryCollection;
104
- filter(fn: (element: Element, index: number) => boolean): ZQueryCollection;
105
-
106
- /** Remove elements matching a CSS selector or predicate. */
107
- not(selector: string): ZQueryCollection;
108
- not(fn: (this: Element, index: number, element: Element) => boolean): ZQueryCollection;
109
-
110
- /** Keep elements that have a descendant matching `selector`. */
111
- has(selector: string): ZQueryCollection;
112
-
113
- /** Check if any element matches the selector or predicate. */
114
- is(selector: string): boolean;
115
- is(fn: (this: Element, index: number, element: Element) => boolean): boolean;
116
-
117
- /** Return a subset of the collection. */
118
- slice(start: number, end?: number): ZQueryCollection;
119
-
120
- /** Add elements to the collection, returning a new combined collection. */
121
- add(selector: string, context?: Element | Document): ZQueryCollection;
122
- add(element: Element): ZQueryCollection;
123
- add(collection: ZQueryCollection): ZQueryCollection;
124
-
125
- /** Retrieve a raw DOM element by index (supports negative). No args → array of all elements. */
126
- get(): Element[];
127
- get(index: number): Element | undefined;
128
-
129
- /** Position of the first element among its siblings, or index of a given element/selector in the collection. */
130
- index(selector?: string | Element): number;
131
-
132
- // -- Classes -------------------------------------------------------------
133
-
134
- /** Add one or more classes (space-separated strings accepted). */
135
- addClass(...names: string[]): this;
136
-
137
- /** Remove one or more classes. */
138
- removeClass(...names: string[]): this;
139
-
140
- /** Toggle one or more classes (space-separated strings accepted). Optional trailing `force` boolean. */
141
- toggleClass(...names: Array<string | boolean>): this;
142
-
143
- /** Check whether the first element has the given class. */
144
- hasClass(name: string): boolean;
145
-
146
- // -- Attributes & Properties ---------------------------------------------
147
-
148
- /** Get attribute value of the first element. */
149
- attr(name: string): string | null;
150
- /** Set attribute on all elements. */
151
- attr(name: string, value: string): this;
152
-
153
- /** Remove attribute from all elements. */
154
- removeAttr(name: string): this;
155
-
156
- /** Get JS property of the first element. */
157
- prop(name: string): any;
158
- /** Set JS property on all elements. */
159
- prop(name: string, value: any): this;
160
-
161
- /** Get data attribute value (JSON auto-parsed). No key → full dataset. */
162
- data(): DOMStringMap;
163
- data(key: string): any;
164
- /** Set data attribute on all elements. Objects are JSON-stringified. */
165
- data(key: string, value: any): this;
166
-
167
- // -- CSS & Dimensions ----------------------------------------------------
168
-
169
- /** Get computed style property of the first element, or `undefined` if empty. */
170
- css(property: string): string | undefined;
171
- /** Set inline styles on all elements. */
172
- css(props: Partial<CSSStyleDeclaration>): this;
173
-
174
- /** First element's width (from `getBoundingClientRect`). */
175
- width(): number | undefined;
176
-
177
- /** First element's height. */
178
- height(): number | undefined;
179
-
180
- /** Position relative to the document. */
181
- offset(): { top: number; left: number; width: number; height: number } | null;
182
-
183
- /** Position relative to the offset parent. */
184
- position(): { top: number; left: number } | null;
185
-
186
- /** Get vertical scroll position of the first element. */
187
- scrollTop(): number | undefined;
188
- /** Set vertical scroll position on all elements. */
189
- scrollTop(value: number): this;
190
-
191
- /** Get horizontal scroll position of the first element. */
192
- scrollLeft(): number | undefined;
193
- /** Set horizontal scroll position on all elements. */
194
- scrollLeft(value: number): this;
195
-
196
- /** Width including padding (clientWidth). */
197
- innerWidth(): number | undefined;
198
-
199
- /** Height including padding (clientHeight). */
200
- innerHeight(): number | undefined;
201
-
202
- /** Width including padding + border. Pass `true` to include margin. */
203
- outerWidth(includeMargin?: boolean): number | undefined;
204
-
205
- /** Height including padding + border. Pass `true` to include margin. */
206
- outerHeight(includeMargin?: boolean): number | undefined;
207
-
208
- // -- Content -------------------------------------------------------------
209
-
210
- /** Get `innerHTML` of the first element, or `undefined` if empty. */
211
- html(): string | undefined;
212
- /**
213
- * Set content on all elements. Auto-morphs when the element already has
214
- * children (preserves focus, scroll, form state, keyed reorder via LIS).
215
- * Empty elements receive raw `innerHTML` for fast first-paint.
216
- * Use `empty().html(content)` to force raw innerHTML.
217
- */
218
- html(content: string): this;
219
-
220
- /**
221
- * Morph all elements' children to match new HTML using the diff engine.
222
- * Always morphs regardless of whether the element already has children.
223
- */
224
- morph(content: string): this;
225
-
226
- /** Get `textContent` of the first element, or `undefined` if empty. */
227
- text(): string | undefined;
228
- /** Set `textContent` on all elements. */
229
- text(content: string): this;
230
-
231
- /** Get value of the first input/select/textarea, or `undefined` if empty. */
232
- val(): string | undefined;
233
- /** Set value on all inputs. */
234
- val(value: string): this;
235
-
236
- // -- DOM Manipulation ----------------------------------------------------
237
-
238
- /** Insert content at the end of each element. */
239
- append(content: string | Node | ZQueryCollection): this;
240
-
241
- /** Insert content at the beginning of each element. */
242
- prepend(content: string | Node): this;
243
-
244
- /** Insert content after each element. */
245
- after(content: string | Node): this;
246
-
247
- /** Insert content before each element. */
248
- before(content: string | Node): this;
249
-
250
- /** Wrap each element with the given HTML string or Node. */
251
- wrap(wrapper: string | Node): this;
252
-
253
- /** Remove all elements from the DOM. */
254
- remove(): this;
255
-
256
- /** Clear `innerHTML` of all elements. */
257
- empty(): this;
258
-
259
- /** Clone elements (default: deep clone). */
260
- clone(deep?: boolean): ZQueryCollection;
261
-
262
- /**
263
- * Replace elements with new content. When given an HTML string with the
264
- * same tag name, morphs the element in place (preserving identity and state).
265
- * Falls back to full replacement when the tag name differs or content is a Node.
266
- */
267
- replaceWith(content: string | Node): this;
268
-
269
- /** Insert every element in the collection at the end of the target. */
270
- appendTo(target: string | Element | ZQueryCollection): this;
271
-
272
- /** Insert every element in the collection at the beginning of the target. */
273
- prependTo(target: string | Element | ZQueryCollection): this;
274
-
275
- /** Insert every element in the collection after the target. */
276
- insertAfter(target: string | Element | ZQueryCollection): this;
277
-
278
- /** Insert every element in the collection before the target. */
279
- insertBefore(target: string | Element | ZQueryCollection): this;
280
-
281
- /** Replace the target elements with the collection's elements. */
282
- replaceAll(target: string | Element | ZQueryCollection): this;
283
-
284
- /** Remove the parent of each element, optionally only if it matches `selector`. */
285
- unwrap(selector?: string): this;
286
-
287
- /** Wrap all elements together in a single wrapper. */
288
- wrapAll(wrapper: string | Element): this;
289
-
290
- /** Wrap the inner contents of each element with the given wrapper. */
291
- wrapInner(wrapper: string | Element): this;
292
-
293
- /** Remove all elements from the DOM (alias for `remove`). */
294
- detach(): this;
295
-
296
- // -- Visibility ----------------------------------------------------------
297
-
298
- /** Show elements. Optional display value (default: `''`). */
299
- show(display?: string): this;
300
-
301
- /** Set `display: none` on all elements. */
302
- hide(): this;
303
-
304
- /** Toggle visibility. */
305
- toggle(display?: string): this;
306
-
307
- // -- Events --------------------------------------------------------------
308
-
309
- /** Attach event handler. Space-separated events accepted. */
310
- on(events: string, handler: (event: Event) => void): this;
311
- /** Delegated event handler. */
312
- on(events: string, selector: string, handler: (this: Element, event: Event) => void): this;
313
-
314
- /** Remove event handler. */
315
- off(events: string, handler: (event: Event) => void): this;
316
-
317
- /** One-time event handler. */
318
- one(event: string, handler: (event: Event) => void): this;
319
-
320
- /**
321
- * Dispatch a `CustomEvent` with optional detail payload.
322
- * Bubbles by default.
323
- */
324
- trigger(event: string, detail?: any): this;
325
-
326
- /** Attach click handler, or trigger a click when called with no arguments. */
327
- click(fn?: (event: Event) => void): this;
328
-
329
- /** Attach submit handler, or trigger submit when called with no arguments. */
330
- submit(fn?: (event: Event) => void): this;
331
-
332
- /** Focus the first element. */
333
- focus(): this;
334
-
335
- /** Blur the first element. */
336
- blur(): this;
337
-
338
- /** Bind mouseenter and mouseleave handlers. If only one function is provided, it's used for both. */
339
- hover(enterFn: (event: Event) => void, leaveFn?: (event: Event) => void): this;
340
-
341
- // -- Animation -----------------------------------------------------------
342
-
343
- /**
344
- * CSS transition animation.
345
- * @param props CSS properties to animate to.
346
- * @param duration Duration in ms (default 300).
347
- * @param easing CSS easing function (default `'ease'`).
348
- */
349
- animate(
350
- props: Partial<CSSStyleDeclaration>,
351
- duration?: number,
352
- easing?: string,
353
- ): Promise<ZQueryCollection>;
354
-
355
- /** Fade in (opacity 0→1). Default 300 ms. */
356
- fadeIn(duration?: number): Promise<ZQueryCollection>;
357
-
358
- /** Fade out (opacity 1→0) then hide. Default 300 ms. */
359
- fadeOut(duration?: number): Promise<ZQueryCollection>;
360
-
361
- /** Toggle fade in/out. Default 300 ms. */
362
- fadeToggle(duration?: number): Promise<ZQueryCollection>;
363
-
364
- /** Fade to a specific opacity. */
365
- fadeTo(duration: number, opacity: number): Promise<ZQueryCollection>;
366
-
367
- /** Slide down (reveal). Default 300 ms. */
368
- slideDown(duration?: number): this;
369
-
370
- /** Slide up (hide). Default 300 ms. */
371
- slideUp(duration?: number): this;
372
-
373
- /** Toggle height with a slide animation. Default 300 ms. */
374
- slideToggle(duration?: number): this;
375
-
376
- // -- Form Helpers --------------------------------------------------------
377
-
378
- /** URL-encoded form data string. */
379
- serialize(): string;
380
-
381
- /** Form data as key/value object. Duplicate keys become arrays. */
382
- serializeObject(): Record<string, string | string[]>;
383
- }
1
+ /**
2
+ * ZQueryCollection - chainable DOM element wrapper.
3
+ *
4
+ * Returned by `$()`, `$.all()`, `$.create()`, and many traversal methods.
5
+ * Similar to a jQuery object: wraps an array of elements with fluent methods.
6
+ *
7
+ * @module collection
8
+ */
9
+
10
+ /**
11
+ * Chainable wrapper around an array of DOM elements, similar to a jQuery object.
12
+ * Returned by `$.all()` and many traversal / filtering methods.
13
+ */
14
+ export class ZQueryCollection {
15
+ /** Number of elements in the collection. */
16
+ readonly length: number;
17
+
18
+ /** Access element by numeric index. */
19
+ readonly [index: number]: Element;
20
+
21
+ constructor(elements: Element | Element[]);
22
+
23
+ // -- Iteration -----------------------------------------------------------
24
+
25
+ /**
26
+ * Iterate over each element. `this` inside the callback is the element.
27
+ * @returns The collection (for chaining).
28
+ */
29
+ each(fn: (this: Element, index: number, element: Element) => void): this;
30
+
31
+ /**
32
+ * Map over elements and return a plain array.
33
+ */
34
+ map<T>(fn: (this: Element, index: number, element: Element) => T): T[];
35
+
36
+ /**
37
+ * Iterate elements with Array-style `forEach`. Returns `this` for chaining.
38
+ */
39
+ forEach(fn: (element: Element, index: number, elements: Element[]) => void): this;
40
+
41
+ /** First raw element, or `null`. */
42
+ first(): Element | null;
43
+
44
+ /** Last raw element, or `null`. */
45
+ last(): Element | null;
46
+
47
+ /** New collection containing only the element at `index`. */
48
+ eq(index: number): ZQueryCollection;
49
+
50
+ /** Convert to a plain `Element[]`. */
51
+ toArray(): Element[];
52
+
53
+ /** Iterable protocol - works with `for...of` and spread. */
54
+ [Symbol.iterator](): IterableIterator<Element>;
55
+
56
+ // -- Traversal -----------------------------------------------------------
57
+
58
+ /** Descendants matching `selector`. */
59
+ find(selector: string): ZQueryCollection;
60
+
61
+ /** Unique parent elements. */
62
+ parent(): ZQueryCollection;
63
+
64
+ /** Nearest ancestor matching `selector`. */
65
+ closest(selector: string): ZQueryCollection;
66
+
67
+ /** Direct children, optionally filtered by `selector`. */
68
+ children(selector?: string): ZQueryCollection;
69
+
70
+ /** All sibling elements. */
71
+ siblings(): ZQueryCollection;
72
+
73
+ /** Next sibling of each element, optionally filtered by selector. */
74
+ next(selector?: string): ZQueryCollection;
75
+
76
+ /** Previous sibling of each element, optionally filtered by selector. */
77
+ prev(selector?: string): ZQueryCollection;
78
+
79
+ /** All following siblings, optionally filtered by selector. */
80
+ nextAll(selector?: string): ZQueryCollection;
81
+
82
+ /** Following siblings up to (but not including) the element matching `selector`. */
83
+ nextUntil(selector?: string, filter?: string): ZQueryCollection;
84
+
85
+ /** All preceding siblings, optionally filtered by selector. */
86
+ prevAll(selector?: string): ZQueryCollection;
87
+
88
+ /** Preceding siblings up to (but not including) the element matching `selector`. */
89
+ prevUntil(selector?: string, filter?: string): ZQueryCollection;
90
+
91
+ /** All ancestor elements, optionally filtered by selector (deduplicated). */
92
+ parents(selector?: string): ZQueryCollection;
93
+
94
+ /** Ancestors up to (but not including) the element matching `selector`. */
95
+ parentsUntil(selector?: string, filter?: string): ZQueryCollection;
96
+
97
+ /** All child nodes including text and comment nodes. */
98
+ contents(): ZQueryCollection;
99
+
100
+ // -- Filtering -----------------------------------------------------------
101
+
102
+ /** Keep elements matching a CSS selector or predicate. */
103
+ filter(selector: string): ZQueryCollection;
104
+ filter(fn: (element: Element, index: number) => boolean): ZQueryCollection;
105
+
106
+ /** Remove elements matching a CSS selector or predicate. */
107
+ not(selector: string): ZQueryCollection;
108
+ not(fn: (this: Element, index: number, element: Element) => boolean): ZQueryCollection;
109
+
110
+ /** Keep elements that have a descendant matching `selector`. */
111
+ has(selector: string): ZQueryCollection;
112
+
113
+ /** Check if any element matches the selector or predicate. */
114
+ is(selector: string): boolean;
115
+ is(fn: (this: Element, index: number, element: Element) => boolean): boolean;
116
+
117
+ /** Return a subset of the collection. */
118
+ slice(start: number, end?: number): ZQueryCollection;
119
+
120
+ /** Add elements to the collection, returning a new combined collection. */
121
+ add(selector: string, context?: Element | Document): ZQueryCollection;
122
+ add(element: Element): ZQueryCollection;
123
+ add(collection: ZQueryCollection): ZQueryCollection;
124
+
125
+ /** Retrieve a raw DOM element by index (supports negative). No args → array of all elements. */
126
+ get(): Element[];
127
+ get(index: number): Element | undefined;
128
+
129
+ /** Position of the first element among its siblings, or index of a given element/selector in the collection. */
130
+ index(selector?: string | Element): number;
131
+
132
+ // -- Classes -------------------------------------------------------------
133
+
134
+ /** Add one or more classes (space-separated strings accepted). */
135
+ addClass(...names: string[]): this;
136
+
137
+ /** Remove one or more classes. */
138
+ removeClass(...names: string[]): this;
139
+
140
+ /** Toggle one or more classes (space-separated strings accepted). Optional trailing `force` boolean. */
141
+ toggleClass(...names: Array<string | boolean>): this;
142
+
143
+ /** Check whether the first element has the given class. */
144
+ hasClass(name: string): boolean;
145
+
146
+ // -- Attributes & Properties ---------------------------------------------
147
+
148
+ /** Get attribute value of the first element. */
149
+ attr(name: string): string | null;
150
+ /** Set attribute on all elements. */
151
+ attr(name: string, value: string): this;
152
+
153
+ /** Remove attribute from all elements. */
154
+ removeAttr(name: string): this;
155
+
156
+ /** Get JS property of the first element. */
157
+ prop(name: string): any;
158
+ /** Set JS property on all elements. */
159
+ prop(name: string, value: any): this;
160
+
161
+ /** Get data attribute value (JSON auto-parsed). No key → full dataset. */
162
+ data(): DOMStringMap;
163
+ data(key: string): any;
164
+ /** Set data attribute on all elements. Objects are JSON-stringified. */
165
+ data(key: string, value: any): this;
166
+
167
+ // -- CSS & Dimensions ----------------------------------------------------
168
+
169
+ /** Get computed style property of the first element, or `undefined` if empty. */
170
+ css(property: string): string | undefined;
171
+ /** Set inline styles on all elements. */
172
+ css(props: Partial<CSSStyleDeclaration>): this;
173
+
174
+ /** First element's width (from `getBoundingClientRect`). */
175
+ width(): number | undefined;
176
+
177
+ /** First element's height. */
178
+ height(): number | undefined;
179
+
180
+ /** Position relative to the document. */
181
+ offset(): { top: number; left: number; width: number; height: number } | null;
182
+
183
+ /** Position relative to the offset parent. */
184
+ position(): { top: number; left: number } | null;
185
+
186
+ /** Get vertical scroll position of the first element. */
187
+ scrollTop(): number | undefined;
188
+ /** Set vertical scroll position on all elements. */
189
+ scrollTop(value: number): this;
190
+
191
+ /** Get horizontal scroll position of the first element. */
192
+ scrollLeft(): number | undefined;
193
+ /** Set horizontal scroll position on all elements. */
194
+ scrollLeft(value: number): this;
195
+
196
+ /** Width including padding (clientWidth). */
197
+ innerWidth(): number | undefined;
198
+
199
+ /** Height including padding (clientHeight). */
200
+ innerHeight(): number | undefined;
201
+
202
+ /** Width including padding + border. Pass `true` to include margin. */
203
+ outerWidth(includeMargin?: boolean): number | undefined;
204
+
205
+ /** Height including padding + border. Pass `true` to include margin. */
206
+ outerHeight(includeMargin?: boolean): number | undefined;
207
+
208
+ // -- Content -------------------------------------------------------------
209
+
210
+ /** Get `innerHTML` of the first element, or `undefined` if empty. */
211
+ html(): string | undefined;
212
+ /**
213
+ * Set content on all elements. Auto-morphs when the element already has
214
+ * children (preserves focus, scroll, form state, keyed reorder via LIS).
215
+ * Empty elements receive raw `innerHTML` for fast first-paint.
216
+ * Use `empty().html(content)` to force raw innerHTML.
217
+ */
218
+ html(content: string): this;
219
+
220
+ /**
221
+ * Morph all elements' children to match new HTML using the diff engine.
222
+ * Always morphs regardless of whether the element already has children.
223
+ */
224
+ morph(content: string): this;
225
+
226
+ /** Get `textContent` of the first element, or `undefined` if empty. */
227
+ text(): string | undefined;
228
+ /** Set `textContent` on all elements. */
229
+ text(content: string): this;
230
+
231
+ /** Get value of the first input/select/textarea, or `undefined` if empty. */
232
+ val(): string | undefined;
233
+ /** Set value on all inputs. */
234
+ val(value: string): this;
235
+
236
+ // -- DOM Manipulation ----------------------------------------------------
237
+
238
+ /** Insert content at the end of each element. */
239
+ append(content: string | Node | ZQueryCollection): this;
240
+
241
+ /** Insert content at the beginning of each element. */
242
+ prepend(content: string | Node): this;
243
+
244
+ /** Insert content after each element. */
245
+ after(content: string | Node): this;
246
+
247
+ /** Insert content before each element. */
248
+ before(content: string | Node): this;
249
+
250
+ /** Wrap each element with the given HTML string or Node. */
251
+ wrap(wrapper: string | Node): this;
252
+
253
+ /** Remove all elements from the DOM. */
254
+ remove(): this;
255
+
256
+ /** Clear `innerHTML` of all elements. */
257
+ empty(): this;
258
+
259
+ /** Clone elements (default: deep clone). */
260
+ clone(deep?: boolean): ZQueryCollection;
261
+
262
+ /**
263
+ * Replace elements with new content. When given an HTML string with the
264
+ * same tag name, morphs the element in place (preserving identity and state).
265
+ * Falls back to full replacement when the tag name differs or content is a Node.
266
+ */
267
+ replaceWith(content: string | Node): this;
268
+
269
+ /** Insert every element in the collection at the end of the target. */
270
+ appendTo(target: string | Element | ZQueryCollection): this;
271
+
272
+ /** Insert every element in the collection at the beginning of the target. */
273
+ prependTo(target: string | Element | ZQueryCollection): this;
274
+
275
+ /** Insert every element in the collection after the target. */
276
+ insertAfter(target: string | Element | ZQueryCollection): this;
277
+
278
+ /** Insert every element in the collection before the target. */
279
+ insertBefore(target: string | Element | ZQueryCollection): this;
280
+
281
+ /** Replace the target elements with the collection's elements. */
282
+ replaceAll(target: string | Element | ZQueryCollection): this;
283
+
284
+ /** Remove the parent of each element, optionally only if it matches `selector`. */
285
+ unwrap(selector?: string): this;
286
+
287
+ /** Wrap all elements together in a single wrapper. */
288
+ wrapAll(wrapper: string | Element): this;
289
+
290
+ /** Wrap the inner contents of each element with the given wrapper. */
291
+ wrapInner(wrapper: string | Element): this;
292
+
293
+ /** Remove all elements from the DOM (alias for `remove`). */
294
+ detach(): this;
295
+
296
+ // -- Visibility ----------------------------------------------------------
297
+
298
+ /** Show elements. Optional display value (default: `''`). */
299
+ show(display?: string): this;
300
+
301
+ /** Set `display: none` on all elements. */
302
+ hide(): this;
303
+
304
+ /** Toggle visibility. */
305
+ toggle(display?: string): this;
306
+
307
+ // -- Events --------------------------------------------------------------
308
+
309
+ /** Attach event handler. Space-separated events accepted. */
310
+ on(events: string, handler: (event: Event) => void): this;
311
+ /** Delegated event handler. */
312
+ on(events: string, selector: string, handler: (this: Element, event: Event) => void): this;
313
+
314
+ /** Remove event handler. */
315
+ off(events: string, handler: (event: Event) => void): this;
316
+
317
+ /** One-time event handler. */
318
+ one(event: string, handler: (event: Event) => void): this;
319
+
320
+ /**
321
+ * Dispatch a `CustomEvent` with optional detail payload.
322
+ * Bubbles by default.
323
+ */
324
+ trigger(event: string, detail?: any): this;
325
+
326
+ /** Attach click handler, or trigger a click when called with no arguments. */
327
+ click(fn?: (event: Event) => void): this;
328
+
329
+ /** Attach submit handler, or trigger submit when called with no arguments. */
330
+ submit(fn?: (event: Event) => void): this;
331
+
332
+ /** Focus the first element. */
333
+ focus(): this;
334
+
335
+ /** Blur the first element. */
336
+ blur(): this;
337
+
338
+ /** Bind mouseenter and mouseleave handlers. If only one function is provided, it's used for both. */
339
+ hover(enterFn: (event: Event) => void, leaveFn?: (event: Event) => void): this;
340
+
341
+ // -- Animation -----------------------------------------------------------
342
+
343
+ /**
344
+ * CSS transition animation.
345
+ * @param props CSS properties to animate to.
346
+ * @param duration Duration in ms (default 300).
347
+ * @param easing CSS easing function (default `'ease'`).
348
+ */
349
+ animate(
350
+ props: Partial<CSSStyleDeclaration>,
351
+ duration?: number,
352
+ easing?: string,
353
+ ): Promise<ZQueryCollection>;
354
+
355
+ /** Fade in (opacity 0→1). Default 300 ms. */
356
+ fadeIn(duration?: number): Promise<ZQueryCollection>;
357
+
358
+ /** Fade out (opacity 1→0) then hide. Default 300 ms. */
359
+ fadeOut(duration?: number): Promise<ZQueryCollection>;
360
+
361
+ /** Toggle fade in/out. Default 300 ms. */
362
+ fadeToggle(duration?: number): Promise<ZQueryCollection>;
363
+
364
+ /** Fade to a specific opacity. */
365
+ fadeTo(duration: number, opacity: number): Promise<ZQueryCollection>;
366
+
367
+ /** Slide down (reveal). Default 300 ms. */
368
+ slideDown(duration?: number): this;
369
+
370
+ /** Slide up (hide). Default 300 ms. */
371
+ slideUp(duration?: number): this;
372
+
373
+ /** Toggle height with a slide animation. Default 300 ms. */
374
+ slideToggle(duration?: number): this;
375
+
376
+ // -- Form Helpers --------------------------------------------------------
377
+
378
+ /** URL-encoded form data string. */
379
+ serialize(): string;
380
+
381
+ /** Form data as key/value object. Duplicate keys become arrays. */
382
+ serializeObject(): Record<string, string | string[]>;
383
+ }