zero-query 0.5.2 → 0.7.5

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 (58) hide show
  1. package/README.md +12 -10
  2. package/cli/commands/build.js +7 -5
  3. package/cli/commands/bundle.js +286 -8
  4. package/cli/commands/dev/index.js +82 -0
  5. package/cli/commands/dev/logger.js +70 -0
  6. package/cli/commands/dev/overlay.js +366 -0
  7. package/cli/commands/dev/server.js +158 -0
  8. package/cli/commands/dev/validator.js +94 -0
  9. package/cli/commands/dev/watcher.js +147 -0
  10. package/cli/scaffold/favicon.ico +0 -0
  11. package/cli/scaffold/index.html +1 -0
  12. package/cli/scaffold/scripts/app.js +15 -22
  13. package/cli/scaffold/scripts/components/about.js +14 -2
  14. package/cli/scaffold/scripts/components/contacts/contacts.css +0 -7
  15. package/cli/scaffold/scripts/components/contacts/contacts.html +8 -7
  16. package/cli/scaffold/scripts/components/contacts/contacts.js +17 -1
  17. package/cli/scaffold/scripts/components/counter.js +30 -10
  18. package/cli/scaffold/scripts/components/home.js +3 -3
  19. package/cli/scaffold/scripts/components/todos.js +6 -5
  20. package/cli/scaffold/styles/styles.css +1 -0
  21. package/cli/utils.js +111 -6
  22. package/dist/zquery.dist.zip +0 -0
  23. package/dist/zquery.js +2005 -216
  24. package/dist/zquery.min.js +3 -13
  25. package/index.d.ts +149 -1080
  26. package/index.js +18 -7
  27. package/package.json +9 -3
  28. package/src/component.js +186 -45
  29. package/src/core.js +327 -35
  30. package/src/diff.js +280 -0
  31. package/src/errors.js +155 -0
  32. package/src/expression.js +806 -0
  33. package/src/http.js +18 -10
  34. package/src/reactive.js +29 -4
  35. package/src/router.js +59 -6
  36. package/src/ssr.js +224 -0
  37. package/src/store.js +24 -8
  38. package/tests/component.test.js +304 -0
  39. package/tests/core.test.js +726 -0
  40. package/tests/diff.test.js +194 -0
  41. package/tests/errors.test.js +162 -0
  42. package/tests/expression.test.js +334 -0
  43. package/tests/http.test.js +181 -0
  44. package/tests/reactive.test.js +191 -0
  45. package/tests/router.test.js +332 -0
  46. package/tests/store.test.js +253 -0
  47. package/tests/utils.test.js +353 -0
  48. package/types/collection.d.ts +368 -0
  49. package/types/component.d.ts +210 -0
  50. package/types/errors.d.ts +103 -0
  51. package/types/http.d.ts +81 -0
  52. package/types/misc.d.ts +166 -0
  53. package/types/reactive.d.ts +76 -0
  54. package/types/router.d.ts +132 -0
  55. package/types/ssr.d.ts +49 -0
  56. package/types/store.d.ts +107 -0
  57. package/types/utils.d.ts +142 -0
  58. /package/cli/commands/{dev.js → dev.old.js} +0 -0
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Utility functions — debounce, throttle, strings, objects, URL, storage, event bus.
3
+ *
4
+ * @module utils
5
+ */
6
+
7
+ // ---------------------------------------------------------------------------
8
+ // Function Utilities
9
+ // ---------------------------------------------------------------------------
10
+
11
+ /** Debounced function with a `.cancel()` helper. */
12
+ export interface DebouncedFunction<T extends (...args: any[]) => any> {
13
+ (...args: Parameters<T>): void;
14
+ /** Cancel the pending invocation. */
15
+ cancel(): void;
16
+ }
17
+
18
+ /**
19
+ * Returns a debounced function that delays execution until `ms` ms of inactivity.
20
+ * @param ms Default `250`.
21
+ */
22
+ export function debounce<T extends (...args: any[]) => any>(fn: T, ms?: number): DebouncedFunction<T>;
23
+
24
+ /**
25
+ * Returns a throttled function that executes at most once per `ms` ms.
26
+ * The return value of the original function is discarded.
27
+ * @param ms Default `250`.
28
+ */
29
+ export function throttle<T extends (...args: any[]) => any>(fn: T, ms?: number): (...args: Parameters<T>) => void;
30
+
31
+ /** Left-to-right function composition. */
32
+ export function pipe<A, B>(f1: (a: A) => B): (input: A) => B;
33
+ export function pipe<A, B, C>(f1: (a: A) => B, f2: (b: B) => C): (input: A) => C;
34
+ export function pipe<A, B, C, D>(f1: (a: A) => B, f2: (b: B) => C, f3: (c: C) => D): (input: A) => D;
35
+ 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;
36
+ export function pipe<T>(...fns: Array<(value: any) => any>): (input: T) => any;
37
+
38
+ /** Returns a function that only executes once, caching the result. */
39
+ export function once<T extends (...args: any[]) => any>(fn: T): (...args: Parameters<T>) => ReturnType<T>;
40
+
41
+ /** Returns a `Promise` that resolves after `ms` milliseconds. */
42
+ export function sleep(ms: number): Promise<void>;
43
+
44
+ // ---------------------------------------------------------------------------
45
+ // String Utilities
46
+ // ---------------------------------------------------------------------------
47
+
48
+ /** Escape HTML entities: `&`, `<`, `>`, `"`, `'`. */
49
+ export function escapeHtml(str: string): string;
50
+
51
+ /**
52
+ * Tagged template literal that auto-escapes interpolated values.
53
+ * Use `$.trust()` to mark values as safe.
54
+ */
55
+ export function html(strings: TemplateStringsArray, ...values: any[]): string;
56
+
57
+ /** Wrapper that marks an HTML string as trusted (not escaped by `$.html`). */
58
+ export interface TrustedHTML {
59
+ toString(): string;
60
+ }
61
+
62
+ /** Mark an HTML string as trusted so it won't be escaped in `$.html`. */
63
+ export function trust(htmlStr: string): TrustedHTML;
64
+
65
+ /** Generate a UUID v4 string. */
66
+ export function uuid(): string;
67
+
68
+ /** Convert kebab-case to camelCase. */
69
+ export function camelCase(str: string): string;
70
+
71
+ /** Convert camelCase to kebab-case. */
72
+ export function kebabCase(str: string): string;
73
+
74
+ // ---------------------------------------------------------------------------
75
+ // Object Utilities
76
+ // ---------------------------------------------------------------------------
77
+
78
+ /** Deep clone using `structuredClone` (JSON fallback). */
79
+ export function deepClone<T>(obj: T): T;
80
+
81
+ /** Recursively merge objects. Arrays are replaced, not merged. */
82
+ export function deepMerge<T extends object>(target: T, ...sources: Partial<T>[]): T;
83
+
84
+ /** Deep equality comparison. */
85
+ export function isEqual(a: any, b: any): boolean;
86
+
87
+ // ---------------------------------------------------------------------------
88
+ // URL Utilities
89
+ // ---------------------------------------------------------------------------
90
+
91
+ /** Serialize an object to a URL query string. */
92
+ export function param(obj: Record<string, any>): string;
93
+
94
+ /** Parse a URL query string into an object. */
95
+ export function parseQuery(str: string): Record<string, string>;
96
+
97
+ // ---------------------------------------------------------------------------
98
+ // Storage Wrappers
99
+ // ---------------------------------------------------------------------------
100
+
101
+ /** JSON-aware storage wrapper (localStorage or sessionStorage). */
102
+ export interface StorageWrapper {
103
+ /**
104
+ * Get and JSON-parse a value.
105
+ * @param key Storage key.
106
+ * @param fallback Value returned if key is missing or parse fails (default `null`).
107
+ */
108
+ get<T = any>(key: string, fallback?: T): T;
109
+ /** JSON-stringify and store. */
110
+ set(key: string, value: any): void;
111
+ /** Remove a key. */
112
+ remove(key: string): void;
113
+ /** Clear all entries. */
114
+ clear(): void;
115
+ }
116
+
117
+ /** `localStorage` wrapper with auto JSON serialization. */
118
+ export declare const storage: StorageWrapper;
119
+
120
+ /** `sessionStorage` wrapper (same API as `storage`). */
121
+ export declare const session: StorageWrapper;
122
+
123
+ // ---------------------------------------------------------------------------
124
+ // Event Bus
125
+ // ---------------------------------------------------------------------------
126
+
127
+ /** Singleton pub/sub event bus for cross-component communication. */
128
+ export interface EventBus {
129
+ /** Subscribe. Returns an unsubscribe function. */
130
+ on(event: string, fn: (...args: any[]) => void): () => void;
131
+ /** Unsubscribe a specific handler. */
132
+ off(event: string, fn: (...args: any[]) => void): void;
133
+ /** Emit an event with arguments. */
134
+ emit(event: string, ...args: any[]): void;
135
+ /** Subscribe for a single invocation. Returns an unsubscribe function. */
136
+ once(event: string, fn: (...args: any[]) => void): () => void;
137
+ /** Remove all listeners. */
138
+ clear(): void;
139
+ }
140
+
141
+ /** Global event bus instance. */
142
+ export declare const bus: EventBus;
File without changes