aberdeen 1.10.0 → 1.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/dist/src/aberdeen.d.ts +916 -0
  2. package/dist/src/aberdeen.js +1793 -0
  3. package/dist/src/aberdeen.js.map +11 -0
  4. package/dist/src/aberdeen.min.js +10 -0
  5. package/dist/src/aberdeen.min.js.map +10 -0
  6. package/dist/src/dispatcher.d.ts +57 -0
  7. package/dist/src/dispatcher.js +66 -0
  8. package/{dist-min → dist/src}/dispatcher.js.map +3 -3
  9. package/dist/src/dispatcher.min.js +4 -0
  10. package/dist/src/dispatcher.min.js.map +10 -0
  11. package/dist/src/helpers/reverseSortedSet.d.ts +96 -0
  12. package/dist/src/prediction.d.ts +33 -0
  13. package/dist/src/prediction.js +112 -0
  14. package/{dist-min → dist/src}/prediction.js.map +3 -3
  15. package/dist/src/prediction.min.js +4 -0
  16. package/dist/src/prediction.min.js.map +10 -0
  17. package/dist/src/route.d.ts +116 -0
  18. package/dist/src/route.js +237 -0
  19. package/{dist-min → dist/src}/route.js.map +3 -3
  20. package/dist/src/route.min.js +4 -0
  21. package/dist/src/route.min.js.map +10 -0
  22. package/dist/src/transitions.d.ts +18 -0
  23. package/dist/src/transitions.js +47 -0
  24. package/{dist-min → dist/src}/transitions.js.map +3 -3
  25. package/dist/src/transitions.min.js +4 -0
  26. package/dist/src/transitions.min.js.map +10 -0
  27. package/dist/tests/fakedom.d.ts +9 -0
  28. package/dist/tests/fakedom.js +577 -0
  29. package/dist/tests/fakedom.js.map +10 -0
  30. package/dist/tests/helpers.d.ts +21 -0
  31. package/dist/tests/helpers.js +674 -0
  32. package/dist/tests/helpers.js.map +11 -0
  33. package/dist-docs/.nojekyll +1 -0
  34. package/dist-docs/Tutorial/index.html +296 -0
  35. package/dist-docs/aberdeen/NO_COPY/index.html +4 -0
  36. package/dist-docs/aberdeen/PromiseProxy/index.html +8 -0
  37. package/dist-docs/aberdeen/_/index.html +115 -0
  38. package/dist-docs/aberdeen/clean/index.html +11 -0
  39. package/dist-docs/aberdeen/clone/index.html +5 -0
  40. package/dist-docs/aberdeen/copy/index.html +22 -0
  41. package/dist-docs/aberdeen/count/index.html +7 -0
  42. package/dist-docs/aberdeen/cssVars/index.html +11 -0
  43. package/dist-docs/aberdeen/darkMode/index.html +9 -0
  44. package/dist-docs/aberdeen/default/index.html +328 -0
  45. package/dist-docs/aberdeen/derive/index.html +18 -0
  46. package/dist-docs/aberdeen/disableCreateDestroy/index.html +6 -0
  47. package/dist-docs/aberdeen/dump/index.html +11 -0
  48. package/dist-docs/aberdeen/index.html +52 -0
  49. package/dist-docs/aberdeen/insertCss/index.html +30 -0
  50. package/dist-docs/aberdeen/insertGlobalCss/index.html +13 -0
  51. package/dist-docs/aberdeen/invertString/index.html +13 -0
  52. package/dist-docs/aberdeen/isEmpty/index.html +12 -0
  53. package/dist-docs/aberdeen/map/index.html +26 -0
  54. package/dist-docs/aberdeen/merge/index.html +11 -0
  55. package/dist-docs/aberdeen/mount/index.html +17 -0
  56. package/dist-docs/aberdeen/multiMap/index.html +28 -0
  57. package/dist-docs/aberdeen/onEach/index.html +16 -0
  58. package/dist-docs/aberdeen/partition/index.html +36 -0
  59. package/dist-docs/aberdeen/peek/index.html +40 -0
  60. package/dist-docs/aberdeen/proxy/index.html +31 -0
  61. package/dist-docs/aberdeen/ref/index.html +13 -0
  62. package/dist-docs/aberdeen/runQueue/index.html +13 -0
  63. package/dist-docs/aberdeen/setErrorHandler/index.html +16 -0
  64. package/dist-docs/aberdeen/setSpacingCssVars/index.html +8 -0
  65. package/dist-docs/aberdeen/unmountAll/index.html +5 -0
  66. package/dist-docs/aberdeen/unproxy/index.html +11 -0
  67. package/{dist → dist-docs/assets/aberdeen}/aberdeen.js +11 -9
  68. package/dist-docs/assets/aberdeen/aberdeen.js.map +11 -0
  69. package/dist-docs/assets/aberdeen/aberdeen.min.js +10 -0
  70. package/dist-docs/assets/aberdeen/aberdeen.min.js.map +10 -0
  71. package/{dist → dist-docs/assets/aberdeen}/dispatcher.js.map +1 -1
  72. package/dist-docs/assets/aberdeen/dispatcher.min.js +4 -0
  73. package/dist-docs/assets/aberdeen/dispatcher.min.js.map +10 -0
  74. package/{dist → dist-docs/assets/aberdeen}/prediction.js.map +1 -1
  75. package/dist-docs/assets/aberdeen/prediction.min.js +4 -0
  76. package/dist-docs/assets/aberdeen/prediction.min.js.map +10 -0
  77. package/{dist → dist-docs/assets/aberdeen}/route.js.map +1 -1
  78. package/dist-docs/assets/aberdeen/route.min.js +4 -0
  79. package/dist-docs/assets/aberdeen/route.min.js.map +10 -0
  80. package/{dist → dist-docs/assets/aberdeen}/transitions.js.map +1 -1
  81. package/dist-docs/assets/aberdeen/transitions.min.js +4 -0
  82. package/dist-docs/assets/aberdeen/transitions.min.js.map +10 -0
  83. package/dist-docs/assets/custom.js +573 -0
  84. package/dist-docs/assets/favicon.png +0 -0
  85. package/dist-docs/assets/hierarchy.js +1 -0
  86. package/dist-docs/assets/highlight.css +134 -0
  87. package/dist-docs/assets/icons.js +18 -0
  88. package/dist-docs/assets/icons.svg +1 -0
  89. package/dist-docs/assets/main.js +60 -0
  90. package/dist-docs/assets/navigation.js +1 -0
  91. package/dist-docs/assets/search.js +1 -0
  92. package/dist-docs/assets/style.css +1640 -0
  93. package/dist-docs/dispatcher/Dispatcher/index.html +21 -0
  94. package/dist-docs/dispatcher/MATCH_FAILED/index.html +2 -0
  95. package/dist-docs/dispatcher/MATCH_REST/index.html +2 -0
  96. package/dist-docs/dispatcher/index.html +4 -0
  97. package/dist-docs/hierarchy.html +1 -0
  98. package/dist-docs/index.html +61 -0
  99. package/dist-docs/media/CHANGELOG.md +184 -0
  100. package/dist-docs/modules.html +1 -0
  101. package/dist-docs/prediction/applyCanon/index.html +13 -0
  102. package/dist-docs/prediction/applyPrediction/index.html +8 -0
  103. package/dist-docs/prediction/index.html +9 -0
  104. package/dist-docs/route/Route/index.html +23 -0
  105. package/dist-docs/route/back/index.html +4 -0
  106. package/dist-docs/route/current/index.html +2 -0
  107. package/dist-docs/route/go/index.html +14 -0
  108. package/dist-docs/route/index.html +14 -0
  109. package/dist-docs/route/interceptLinks/index.html +8 -0
  110. package/dist-docs/route/persistScroll/index.html +6 -0
  111. package/dist-docs/route/push/index.html +6 -0
  112. package/dist-docs/route/setLog/index.html +3 -0
  113. package/dist-docs/route/up/index.html +5 -0
  114. package/dist-docs/sitemap.xml +227 -0
  115. package/dist-docs/transitions/grow/index.html +6 -0
  116. package/dist-docs/transitions/index.html +5 -0
  117. package/dist-docs/transitions/shrink/index.html +6 -0
  118. package/package.json +33 -24
  119. package/skill/aberdeen.md +51 -51
  120. package/skill/dispatcher.md +6 -6
  121. package/skill/prediction.md +3 -3
  122. package/skill/route.md +17 -17
  123. package/skill/transitions.md +3 -3
  124. package/src/aberdeen.ts +9 -8
  125. package/dist/aberdeen.js.map +0 -11
  126. package/dist-min/aberdeen.js +0 -10
  127. package/dist-min/aberdeen.js.map +0 -11
  128. package/dist-min/dispatcher.js +0 -4
  129. package/dist-min/prediction.js +0 -4
  130. package/dist-min/route.js +0 -4
  131. package/dist-min/transitions.js +0 -4
  132. /package/{dist → dist-docs/assets/aberdeen}/aberdeen.d.ts +0 -0
  133. /package/{dist → dist-docs/assets/aberdeen}/dispatcher.d.ts +0 -0
  134. /package/{dist → dist-docs/assets/aberdeen}/dispatcher.js +0 -0
  135. /package/{dist → dist-docs/assets/aberdeen}/helpers/reverseSortedSet.d.ts +0 -0
  136. /package/{dist → dist-docs/assets/aberdeen}/prediction.d.ts +0 -0
  137. /package/{dist → dist-docs/assets/aberdeen}/prediction.js +0 -0
  138. /package/{dist → dist-docs/assets/aberdeen}/route.d.ts +0 -0
  139. /package/{dist → dist-docs/assets/aberdeen}/route.js +0 -0
  140. /package/{dist → dist-docs/assets/aberdeen}/transitions.d.ts +0 -0
  141. /package/{dist → dist-docs/assets/aberdeen}/transitions.js +0 -0
@@ -0,0 +1,916 @@
1
+ /**
2
+ * Forces the immediate and synchronous execution of all pending reactive updates.
3
+ *
4
+ * Normally, changes to observed data sources (like proxied objects or arrays)
5
+ * are processed asynchronously in a batch after a brief timeout (0ms). This function
6
+ * allows you to bypass the timeout and process the update queue immediately.
7
+ *
8
+ * This can be useful in specific scenarios where you need the DOM to be updated
9
+ * synchronously.
10
+ *
11
+ * This function is re-entrant, meaning it is safe to call `runQueue` from within
12
+ * a function that is itself being executed as part of an update cycle triggered
13
+ * by a previous (or the same) `runQueue` call.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const data = A.proxy("before");
18
+ *
19
+ * A('#', data);
20
+ * console.log(1, document.body.innerHTML); // before
21
+ *
22
+ * // Make an update that should cause the DOM to change.
23
+ * data.value = "after";
24
+ *
25
+ * // Normally, the DOM update would happen after a timeout.
26
+ * // But this causes an immediate update:
27
+ * A.runQueue();
28
+ *
29
+ * console.log(2, document.body.innerHTML); // after
30
+ * ```
31
+ */
32
+ export declare function runQueue(): void;
33
+ /**
34
+ * Creates a new string that has the opposite sort order compared to the input string.
35
+ *
36
+ * This is achieved by flipping the bits of each character code in the input string.
37
+ * The resulting string is intended for use as a sort key, particularly with the
38
+ * `makeKey` function in {@link onEach}, to achieve a descending sort order.
39
+ *
40
+ * **Warning:** The output string will likely contain non-printable characters or
41
+ * appear as gibberish and should not be displayed to the user.
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * const users = A.proxy([
46
+ * { id: 1, name: 'Charlie', score: 95 },
47
+ * { id: 2, name: 'Alice', score: 100 },
48
+ * { id: 3, name: 'Bob', score: 90 },
49
+ * ]);
50
+ *
51
+ * A.onEach(users, (user) => {
52
+ * A(`p#${user.name}: ${user.score}`);
53
+ * }, (user) => A.invertString(user.name)); // Reverse alphabetic order
54
+ * ```
55
+ *
56
+ * @param input The string whose sort order needs to be inverted.
57
+ * @returns A new string that will sort in the reverse order of the input string.
58
+ * @see {@link onEach} for usage with sorting.
59
+ */
60
+ export declare function invertString(input: string): string;
61
+ export declare function onEach<K, T>(target: Map<K, undefined | T>, render: (value: T, key: K) => void, makeKey?: (value: T, key: K) => SortKeyType): void;
62
+ export declare function onEach<T>(target: ReadonlyArray<undefined | T>, render: (value: T, index: number) => void, makeKey?: (value: T, index: number) => SortKeyType): void;
63
+ export declare function onEach<K extends string | number | symbol, T>(target: Record<K, undefined | T>, render: (value: T, index: KeyToString<K>) => void, makeKey?: (value: T, index: KeyToString<K>) => SortKeyType): void;
64
+ /** @private */
65
+ export declare const EMPTY: unique symbol;
66
+ /**
67
+ * Reactively checks if an observable array or object is empty.
68
+ *
69
+ * This function not only returns the current emptiness state but also establishes
70
+ * a reactive dependency. If the emptiness state of the `proxied` object or array
71
+ * changes later (e.g., an item is added to an empty array, or the last property
72
+ * is deleted from an object), the scope that called `isEmpty` will be automatically
73
+ * scheduled for re-evaluation.
74
+ *
75
+ * @param proxied The observable array or object to check.
76
+ * @returns `true` if the array has length 0 or the object has no own enumerable properties, `false` otherwise.
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * const items = A.proxy([]);
81
+ *
82
+ * // Reactively display a message if the items array is empty
83
+ * A('div', () => {
84
+ * if (A.isEmpty(items)) {
85
+ * A('p i#No items yet!');
86
+ * } else {
87
+ * A.onEach(items, item => A('p#'+item));
88
+ * }
89
+ * });
90
+ *
91
+ * // Adding an item will automatically remove the "No items yet!" message
92
+ * setInterval(() => {
93
+ * if (!items.length || Math.random()>0.5) items.push('Item');
94
+ * else items.length = 0;
95
+ * }, 1000)
96
+ * ```
97
+ */
98
+ export declare function isEmpty(proxied: TargetType): boolean;
99
+ /** @private */
100
+ export interface ValueRef<T> {
101
+ value: T;
102
+ }
103
+ /**
104
+ * Reactively counts the number of properties in an objects.
105
+ *
106
+ * @param proxied The observable object to count. In case an `array` is passed in, a {@link ref} to its `.length` will be returned.
107
+ * @returns an observable object for which the `value` property reflects the number of properties in `proxied` with a value other than `undefined`.
108
+ *
109
+ * @example
110
+ * ```typescript
111
+ * const items = A.proxy({x: 3, y: 7} as any);
112
+ * const cnt = A.count(items);
113
+ *
114
+ * // Create a DOM text node for the count:
115
+ * A('div text=', cnt);
116
+ * // <div>2</div>
117
+
118
+ * // Or we can use it in an {@link derive} function:
119
+ * A(() => console.log("The count is now", cnt.value));
120
+ * // The count is now 2
121
+ *
122
+ * // Adding/removing items will update the count
123
+ * items.z = 12;
124
+ * // Asynchronously, after 0ms:
125
+ * // <div>3</div>
126
+ * // The count is now 3
127
+ * ```
128
+ */
129
+ export declare function count(proxied: TargetType): ValueRef<number>;
130
+ /**
131
+ * When `proxy` is called with a Promise, the returned object has this shape.
132
+ */
133
+ export interface PromiseProxy<T> {
134
+ /**
135
+ * True if the promise is still pending, false if it has resolved or rejected.
136
+ */
137
+ busy: boolean;
138
+ /**
139
+ * If the promise has resolved, this contains the resolved value.
140
+ */
141
+ value?: T;
142
+ /**
143
+ * If the promise has rejected, this contains the rejection error.
144
+ */
145
+ error?: any;
146
+ }
147
+ export declare function proxy<T extends any>(target: Promise<T>): PromiseProxy<T>;
148
+ export declare function proxy<T extends any>(target: Array<T>): Array<T extends number ? number : T extends string ? string : T extends boolean ? boolean : T>;
149
+ export declare function proxy<T extends object>(target: T): T;
150
+ export declare function proxy<T extends any>(target: T): ValueRef<T extends number ? number : T extends string ? string : T extends boolean ? boolean : T>;
151
+ /**
152
+ * Returns the original, underlying data target from a reactive proxy created by {@link proxy}.
153
+ * If the input `target` is not a proxy, it is returned directly.
154
+ *
155
+ * This is useful when you want to avoid triggering subscriptions during read operations or
156
+ * re-executes during write operations. Using {@link peek} is an alternative way to achieve this.
157
+ *
158
+ * @param target - A proxied object, array, or any other value.
159
+ * @returns The underlying (unproxied) data, or the input value if it wasn't a proxy.
160
+ * @template T - The type of the target.
161
+ *
162
+ * @example
163
+ * ```typescript
164
+ * const userProxy = A.proxy({ name: 'Frank' });
165
+ * const rawUser = A.unproxy(userProxy);
166
+ *
167
+ * // Log reactively
168
+ * A(() => console.log('proxied', userProxy.name));
169
+ * // The following will only ever log once, as we're not subscribing to any observable
170
+ * A(() => console.log('unproxied', rawUser.name));
171
+ *
172
+ * // This cause the first log to run again:
173
+ * setTimeout(() => userProxy.name += '!', 1000);
174
+ *
175
+ * // This doesn't cause any new logs:
176
+ * setTimeout(() => rawUser.name += '?', 2000);
177
+ *
178
+ * // Both userProxy and rawUser end up as `{name: 'Frank!?'}`
179
+ * setTimeout(() => {
180
+ * console.log('final proxied', userProxy)
181
+ * console.log('final unproxied', rawUser)
182
+ * }, 3000);
183
+ * ```
184
+ */
185
+ export declare function unproxy<T>(target: T): T;
186
+ /**
187
+ * Recursively copies properties or array items from `src` to `dst`.
188
+ * It's designed to work efficiently with reactive proxies created by {@link proxy}.
189
+ *
190
+ * - **Minimizes Updates:** When copying between objects/arrays (proxied or not), if a nested object
191
+ * exists in `dst` with the same constructor as the corresponding object in `src`, `copy`
192
+ * will recursively copy properties into the existing `dst` object instead of replacing it.
193
+ * This minimizes change notifications for reactive (proxied) destinations.
194
+ * - **Fast with Proxies:** When copying to/from proxied objects, `copy` uses Aberdeen internals
195
+ * to speed things up (compared to a non-Aberdeen-aware deep copy).
196
+ *
197
+ * @param dst - The destination object/array/Map (proxied or unproxied).
198
+ * @param src - The source object/array/Map (proxied or unproxied). It won't be modified.
199
+ * @template T - The type of the objects being copied.
200
+ * @returns `true` if any changes were made to `dst`, or `false` if not.
201
+ * @throws Error if attempting to copy an array into a non-array or vice versa.
202
+ *
203
+ * @example Basic Copy
204
+ * ```typescript
205
+ * const source = A.proxy({ a: 1, b: { c: 2 } });
206
+ * const dest = A.proxy({ b: { d: 3 } });
207
+ * A.copy(dest, source);
208
+ * console.log(dest); // proxy({ a: 1, b: { c: 2 } })
209
+ * A.copy(dest, 'b', { e: 4 });
210
+ * console.log(dest); // proxy({ a: 1, b: { e: 4 } })
211
+ * ```
212
+ */
213
+ export declare function copy<T extends object>(dst: T, src: T): boolean;
214
+ /**
215
+ * Like above, but copies `src` into `dst[dstKey]`. This is useful if you're unsure if dst[dstKey]
216
+ * already exists (as the right type of object) or if you don't want to subscribe to dst[dstKey].
217
+ *
218
+ * @param dstKey - Optional key in `dst` to copy into.
219
+ */
220
+ export declare function copy<T extends object>(dst: T, dstKey: keyof T, src: T[typeof dstKey]): boolean;
221
+ /**
222
+ * Like {@link copy}, but uses merge semantics. Properties in `dst` not present in `src` are kept.
223
+ * `null`/`undefined` in `src` delete properties in `dst`.
224
+ *
225
+ * @example Basic merge
226
+ * ```typescript
227
+ * const source = { b: { c: 99 }, d: undefined }; // d: undefined will delete
228
+ * const dest = A.proxy({ a: 1, b: { x: 5 }, d: 4 });
229
+ * A.merge(dest, source);
230
+ * A.merge(dest, 'b', { y: 6 }); // merge into dest.b
231
+ * A.merge(dest, 'c', { z: 7 }); // merge.c doesn't exist yet, so it will just be assigned
232
+ * console.log(dest); // proxy({ a: 1, b: { c: 99, x: 5, y: 6 }, c: { z: 7 } })
233
+ * ```
234
+ *
235
+ */
236
+ export declare function merge<T extends object>(dst: T, value: Partial<T>): boolean;
237
+ export declare function merge<T extends object>(dst: T, dstKey: keyof T, value: Partial<T[typeof dstKey]>): boolean;
238
+ /**
239
+ * A symbol that can be added to an object to prevent it from being cloned by {@link clone} or {@link copy}.
240
+ * This is useful for objects that should be shared by reference. That also mean that their contents won't
241
+ * be observed for changes.
242
+ */
243
+ export declare const NO_COPY: unique symbol;
244
+ /**
245
+ * A reactive object containing CSS variable definitions.
246
+ *
247
+ * Any property you assign to `cssVars` becomes available as a CSS custom property throughout your application.
248
+ *
249
+ * Use {@link setSpacingCssVars} to optionally initialize `cssVars[1]` through `cssVars[12]` with an exponential spacing scale.
250
+ *
251
+ * When you reference a CSS variable in Aberdeen using the `$` prefix (e.g., `$primary`), it automatically resolves to `var(--primary)`.
252
+ * For numeric keys (which can't be used directly as CSS custom property names), Aberdeen prefixes them with `m` (e.g., `$3` becomes `var(--m3)`).
253
+ *
254
+ * When you add the first property to cssVars, Aberdeen automatically creates a reactive `<style>` tag in `<head>`
255
+ * containing the `:root` CSS custom property declarations. The style tag is automatically removed if cssVars becomes empty.
256
+ *
257
+ * @example
258
+ * ```javascript
259
+ * import A from 'aberdeen';
260
+ *
261
+ * // Optionally initialize spacing scale
262
+ * A.setSpacingCssVars(); // Uses defaults: base=1, unit='rem'
263
+ *
264
+ * // Define custom colors - style tag is automatically created
265
+ * A.cssVars.primary = '#3b82f6';
266
+ * A.cssVars.danger = '#ef4444';
267
+ *
268
+ * // Use in elements with the $ prefix
269
+ * A('button bg:$primary fg:white #I'm a primary button');
270
+ *
271
+ * // Use spacing (if setSpacingCssVars() was called)
272
+ * A('hr mt:$3'); // Sets margin-top to var(--m3)
273
+ * ```
274
+ */
275
+ export declare const cssVars: Record<string, string>;
276
+ /**
277
+ * Initializes `cssVars[0]` through `cssVars[12]` with an exponential spacing scale.
278
+ *
279
+ * The scale is calculated as `2^(n-3) * base`, providing values from `0.25 * base` to `512 * base`.
280
+ *
281
+ * @param base - The base size for the spacing scale that will apply to `cssVars[3]`. Every step up the scale will double this, while every step down will halve it. Defaults to 1.
282
+ * @param unit - The CSS unit to use, like 'rem', 'em', or 'px'. Defaults to 'rem'.
283
+ *
284
+ * @example
285
+ * ```javascript
286
+ * import A from 'aberdeen';
287
+ * // Use default scale (0.25rem to 512rem)
288
+ * A.setSpacingCssVars();
289
+ *
290
+ * // Use custom base size
291
+ * A.setSpacingCssVars(16, 'px'); // 4px to 8192px
292
+ *
293
+ * // Use em units
294
+ * A.setSpacingCssVars(1, 'em'); // 0.25em to 512em
295
+ *
296
+ * // Show the last generated spacing values
297
+ * A.onEach(A.cssVars, (value, key) => {
298
+ * A(`div #${key} → ${value}`)
299
+ * }, (value, key) => parseInt(key)); // Numeric sort
300
+ * ```
301
+ */
302
+ export declare function setSpacingCssVars(base?: number, unit?: string): void;
303
+ /**
304
+ * Returns whether the user's browser prefers a dark color scheme.
305
+ *
306
+ * This function is reactive - scopes that call it will re-execute when the
307
+ * browser's color scheme preference changes (via the `prefers-color-scheme` media query).
308
+ *
309
+ * Use this in combination with {@link $ | A} and {@link cssVars} to implement theme switching:
310
+ *
311
+ * @returns `true` if the browser prefers dark mode, `false` if it prefers light mode.
312
+ *
313
+ * @example
314
+ * ```javascript
315
+ * import A from 'aberdeen';
316
+ *
317
+ * // Reactively set colors based on browser preference
318
+ * A(() => {
319
+ * A.cssVars.bg = A.darkMode() ? '#1a1a1a' : '#ffffff';
320
+ * A.cssVars.fg = A.darkMode() ? '#e5e5e5' : '#000000';
321
+ * });
322
+ *
323
+ * A('div bg:$bg fg:$fg p:1rem #Colors change based on system dark mode preference');
324
+ * ```
325
+ */
326
+ export declare function darkMode(): boolean;
327
+ /**
328
+ * Clone an (optionally proxied) object or array.
329
+ *
330
+ * @param src The object or array to clone. If it is proxied, `clone` will subscribe to any changes to the (nested) data structure.
331
+ * @template T - The type of the objects being copied.
332
+ * @returns A new unproxied array or object (of the same type as `src`), containing a deep copy of `src`.
333
+ */
334
+ export declare function clone<T extends object>(src: T): T;
335
+ /**
336
+ * Creates a reactive reference (`{ value: T }`-like object) to a specific value
337
+ * within a proxied object or array.
338
+ *
339
+ * This is primarily used for the `bind` property in {@link $ | A} to create two-way data bindings
340
+ * with form elements, and for passing a reactive property to any of the {@link $ | A} key-value pairs.
341
+ *
342
+ * Reading `ref.value` accesses the property from the underlying proxy (and subscribes the current scope).
343
+ * Assigning to `ref.value` updates the property in the underlying proxy (triggering reactive updates).
344
+ *
345
+ * @param target - The reactive proxy (created by {@link proxy}) containing the target property.
346
+ * @param index - The key (for objects) or index (for arrays) of the property to reference.
347
+ * @returns A reference object with a `value` property linked to the specified proxy property.
348
+ *
349
+ * @example
350
+ * ```javascript
351
+ * const formData = A.proxy({ color: 'orange', velocity: 42 });
352
+ *
353
+ * // Usage with `bind`
354
+ * A('input type=text bind=', A.ref(formData, 'color'));
355
+ *
356
+ * // Usage as a dynamic property, causes a TextNode with just the name to be created and live-updated
357
+ * A('p text="Selected color: " text=', A.ref(formData, 'color'), 'color:', A.ref(formData, 'color'));
358
+ *
359
+ * // Changes are actually stored in formData - this causes logs like `{color: "Blue", velocity 42}`
360
+ * A(() => console.log(formData))
361
+ * ```
362
+ */
363
+ export declare function ref<T extends TargetType, K extends keyof T>(target: T, index: K): ValueRef<T[K]>;
364
+ /**
365
+ * Make the `create` and `destroy` special properties no-ops.
366
+ *
367
+ * This is useful from within automated testing environments, where the transitioning
368
+ * new and lingering old elements may make writing reliable selectors difficult.
369
+ *
370
+ * As this is only intended for testing, there's no way to re-enable the special properties
371
+ * once disabled.
372
+ */
373
+ export declare function disableCreateDestroy(): void;
374
+ /**
375
+ * The core function for building reactive user interfaces in Aberdeen. It creates and inserts new DOM elements
376
+ * and sets attributes/properties/event listeners on DOM elements. It does so in a reactive way, meaning that
377
+ * changes will be (mostly) undone when the current *scope* is destroyed or will be re-execute.
378
+ *
379
+ * @param {...(string | function | object | false | undefined | null)} args - Any number of arguments can be given. How they're interpreted depends on their types:
380
+ *
381
+ * ### String arguments
382
+ * Strings can be used to create and insert new elements, set classnames for the *current* element, and add text to the current element.
383
+ * The format of a string is: (**tag** | `.` **class** | **key**[=:]**val** | **key**[=:]"**val containing spaces**")* ('#' **text** | **key**[=:])?
384
+ *
385
+ * So a string may consist of any number of...
386
+ * - **tag** elements, like `h1` or `div`. These elements are created, added to the *current* element, and become the new *current* element for the rest of this `A` function execution.
387
+ * - CSS classes prefixed by `.` characters. These classes will be added to the *current* element. Optionally, CSS classes can be appended to a **tag** without a space. So both `div.myclass` and `div .myclass` are valid and do the same thing.
388
+ * - Property key/value pairs, like `type=password`, `placeholder="Your name"` or `data-id=123`. When the value contains spaces, it needs to be quoted with either "double quotes", 'single quotes' or \`backticks\`. Quotes within quoted values cannot be escaped (see the next rule for a solution). Key/value pairs will be handled according to *Property rules* below, but with the caveat that values can only be strings.
389
+ * - CSS key/value pairs using two syntaxes:
390
+ * - **Short form** `key:value` (no space after colon): The value ends at the next whitespace. Example: `m:$3 bg:red r:8px`
391
+ * - **Long form** `key: value;` (space after colon): The value continues until a semicolon. Example: `box-shadow: 2px 0 6px black; transition: all 0.3s ease;`
392
+ *
393
+ * Both forms support CSS shortcuts (see below). You can mix them: `m:$3 box-shadow: 0 2px 4px rgba(0,0,0,0.2); bg:$cardBg`
394
+ * The elements must be separated by spaces, except before a `.cssClass` if it is preceded by either **tag** or another CSS class.
395
+ *
396
+ * And a string may end in...
397
+ * - A '#' followed by text, which will be added as a `TextNode` to the *current* element. The text ranges til the end of the string, and may contain any characters, including spaces and quotes.
398
+ * - A key followed by an '=' character, in which case the value is expected as a separate argument. The key/value pair is set according to the *Property rules* below. This is useful when the value is not a string or contains spaces or user data. Example: `A('button text="Click me" click=', () => alert('Clicked!'))` or `A('input.value=', someUserData, "placeholder=", "Type your stuff")`. In case the value is a proxied object, its `.value` property will be applied reactively without needing to rerender the parent scope.
399
+ * - A key followed by a ':' character (with no value), in which case the value is expected as a separate argument. The value is treated as a CSS value to be set inline on the *current* element. Example: `A('div margin-top:', someValueInPx)`. In case the value is a proxied object, its `.value` property will be applied reactively without needing to rerender the parent scope.
400
+ *
401
+ * ### Function arguments
402
+ * When a function (without arguments nor a return value) is passed in, it will be reactively executed in its own observer scope, preserving the *current* element. So any `A()` invocations within this function will add child elements to or set properties on that element. If the function reads observable data, and that data is changed later on, the function we re-execute (after side effects, such as DOM modifications through `A`, have been cleaned - see also {@link clean}).
403
+ *
404
+ * ### Object arguments
405
+ * When an object is passed in, its key-value pairs are used to modify the *current* element according to the *Property rules* below, *unless* the key starts with a `$` character, in which case that character is stripped of and the key/value pair is treated as a CSS property, subject to the *CSS shortcuts* below. In case a value is a proxied object, its `.value` property will be applied reactively without needing to rerender the parent scope. In most cases, the string notation (`key=` and `key:`) is preferred over this object notation, for readability.
406
+ *
407
+ * ### DOM node arguments
408
+ * When a DOM Node (Element or TextNode) is passed in, it is added as a child to the *current* element. If the Node is an Element, it becomes the new *current* element for the rest of this `A` function execution.
409
+ *
410
+ * ### Property rules
411
+ * - **Attribute:** The common case is setting the value as an HTML attribute named key. For example `A('input placeholder=Name')` results in `<input placeholder="Name">`.
412
+ * - **Event listener:** If the value is a `function` it is set as an event listener for the event with the name given by the key. For example: A('button text=Press! click=', () => alert('Clicked!'))`. The event listener will be removed when the current scope is destroyed.
413
+ * - **DOM property:** When the value is a boolean, or the key is `"value"` or `"selectedIndex"`, it is set on the `current` element as a DOM property instead of an HTML attribute. For example `A('checked=', true)` would do `el.checked = true` for the *current* element.
414
+ * - **Conditional CSS class:** If the key starts with a `.` character, its either added to or removed from the *current* element as a CSS class, based on the truthiness of the value. So `A('.hidden=', isHidden)` would toggle the `hidden` CSS class. This only works if the `=` is the last character of the string, and the next argument is the value. Its common for the value to be a proxied object, in which case its `.value` is reactively applied without needing to rerender the parent scope.
415
+ * - **Create transition:** When the key is `"create"`, the value will be added as a CSS class to the *current* element immediately, and then removed right after the browser has finished doing a layout pass. This behavior only triggers when the scope setting the `create` is the top-level scope being (re-)run. This allows for creation transitions, without triggering the transitions for deeply nested elements being drawn as part of a larger component. The string may also contain multiple dot-separated CSS classes, such as `.fade.grow`. The initial dot is optional. Alternatively, to allow for more complex transitions, the value may be a function that receives the `HTMLElement` being created as its only argument. It is *only* called if this is the top-level element being created in this scope run. See `transitions.ts` in the Aberdeen source code for some examples.
416
+ * - **Destroy transition:** When the key is `"destroy"` the value will be used to apply a CSS transition if the *current* element is later on removed from the DOM and is the top-level element to be removed. This happens as follows: actual removal from the DOM is delayed by 2 seconds, and in the mean-time the value string is added as a CSS class to the element, allowing for a deletion transition. The string may also contain multiple dot-separated CSS classes, such as `.fade.shrink`. The initial dot is optional. Alternatively, to allow for more complex transitions, the value may be a function that receives the `HTMLElement` to be removed from the DOM as its only argument. This function may perform any transitions and is then itself responsible for eventually removing the element from the DOM. See `transitions.ts` in the Aberdeen source code for some examples.
417
+ * - **Two-way data binding:** When the key is `"bind"` a two-way binding between the `.value` property of the given proxied object, and the *current* input element (`<input>`, `<select>` or `<textarea>`) is created. This is often used together with {@link ref}, in order to use properties other than `.value`.
418
+ * - **Text:**: If the key is `"text"`, the value will be appended as a `TextNode` to the *current* element. The same can also be done with the `#` syntax in string arguments, though `text=` allows additional properties to come after in the same string: `A('button text=Hello click=', alert)`.
419
+ * - **Unsafe HTML:** When the key is `"html"`, the value will be added as HTML to the *current* element. This should only be used in exceptional situations. Beware of XSS! Never use this with untrusted user data.
420
+ * - **Rich text:** When the key is `"rich"`, the value is parsed as simple markdown-like syntax and rendered as inline elements. Supports `*italic*`, `**bold**`, `` `code` ``, and `[link text](/path)`. All text content is safely escaped, making it suitable for user data (though links should be validated if untrusted). Example: `A('p rich="Click *here* for **more** info")`.
421
+ *
422
+ * ### CSS shortcuts
423
+ * For conciseness, Aberdeen supports some CSS shortcuts when setting CSS properties.
424
+ * | Shortcut | Expands to |
425
+ * |----------|------------|
426
+ * | `m`, `mt`, `mb`, `ml`, `mr` | `margin`, `margin-top`, `margin-bottom`, `margin-left`, `margin-right` |
427
+ * | `mv`, `mh` | Vertical (top+bottom) or horizontal (left+right) margins |
428
+ * | `p`, `pt`, `pb`, `pl`, `pr` | `padding`, `padding-top`, `padding-bottom`, `padding-left`, `padding-right` |
429
+ * | `pv`, `ph` | Vertical or horizontal padding |
430
+ * | `w`, `h` | `width`, `height` |
431
+ * | `bg` | `background` |
432
+ * | `fg` | `color` |
433
+ * | `r` | `border-radius` |
434
+ *
435
+ * Also, when the value is a string starting with `$`, it is treated as a reference to a CSS variable, expanding to `var(--variableName)`. For numeric variable names (which can't be used directly as CSS custom property names), Aberdeen prefixes them with `m`, so `$3` expands to `var(--m3)`. This is primarily intended for use with {@link setSpacingCssVars}, which initializes spacing variables named `0` through `12` with an exponential spacing scale.
436
+ *
437
+ * @returns The most inner DOM element that was created (not counting text nodes nor elements created by content functions), or the current element if no new element was created. You should normally not need to use the return value - use this function's DOM manipulation abilities instead. One valid use case is when integrating with non-Aberdeen code that requires a reference to a DOM element.
438
+ *
439
+ * @example Create Element
440
+ * ```typescript
441
+ * A('button.secondary.outline text=Submit color:red disabled=', false, 'click=', () => console.log('Clicked!'));
442
+ * ```
443
+ *
444
+ * We want to set `disabled` as a property instead of an attribute, so we must use the `key=` syntax in order to provide
445
+ * `false` as a boolean instead of a string.
446
+ *
447
+ * @example Create Nested Elements
448
+ * ```typescript
449
+ * let inputElement: Element = A('label text="Click me" input type=checkbox');
450
+ * // You should usually not touch raw DOM elements, unless when integrating
451
+ * // with non-Aberdeen code.
452
+ * console.log('DOM element:', inputElement);
453
+ * ```
454
+ *
455
+ * @example Content Functions & Reactive Scope
456
+ * ```typescript
457
+ * const state = A.proxy({ count: 0 });
458
+ * A('div', () => { // Outer element
459
+ * // This scope re-renders when state.count changes
460
+ * A(`p#Count is ${state.count}`);
461
+ * A('button text=Increment click=', () => state.count++);
462
+ * });
463
+ * ```
464
+ *
465
+ * @example Two-way Binding
466
+ * ```typescript
467
+ * const user = A.proxy({ name: '' });
468
+ * A('input placeholder=Name bind=', A.ref(user, 'name'));
469
+ * A('h3', () => { // Reactive scope
470
+ * A(`#Hello ${user.name || 'stranger'}`);
471
+ * });
472
+ * ```
473
+ *
474
+ * @example Conditional Rendering
475
+ * ```typescript
476
+ * const show = A.proxy(false);
477
+ * A('button click=', () => show.value = !show.value, () => A(show.value ? '#Hide' : '#Show'));
478
+ * A(() => { // Reactive scope
479
+ * if (show.value) {
480
+ * A('p#Details are visible!');
481
+ * }
482
+ * });
483
+ * ```
484
+ *
485
+ * @example Proxied objects as values
486
+ * ```typescript
487
+ * const myColor = A.proxy('red');
488
+ * A('p text="The color is " text=', myColor, 'click=', () => myColor.value = 'yellow')
489
+ * // Clicking the text will cause it to change color without recreating the <p> itself
490
+ * ```
491
+ * This is often used together with {@link ref}, in order to use properties other than `.value`.
492
+ */
493
+ export declare function $(...args: any[]): undefined | Element;
494
+ /**
495
+ * Inserts CSS rules into the document, scoping them with a unique class name.
496
+ *
497
+ * The `style` parameter can be either:
498
+ * - A **concise style string** (for rules applying to the root class).
499
+ * - An **object** where keys are selectors (with `&` representing the root class)
500
+ * and values are concise style strings or nested objects. When the key does not contain `&`,
501
+ * it is treated as a descendant selector. So `{p: "color:red"}` becomes `".AbdStlX p { color: red; }"` with `AbdStlX` being the generated class name.
502
+ *
503
+ * ### Concise Style Strings
504
+ *
505
+ * Concise style strings use two syntaxes (same as inline CSS in {@link $ | A}):
506
+ * - **Short form** `key:value` (no space after colon): The value ends at the next whitespace.
507
+ * Example: `'m:$3 bg:red r:8px'`
508
+ * - **Long form** `key: value;` (space after colon): The value continues until a semicolon.
509
+ * Example: `'box-shadow: 2px 0 6px black; transition: all 0.3s ease;'`
510
+ *
511
+ * Both forms can be mixed: `'m:$3 box-shadow: 0 2px 4px rgba(0,0,0,0.2); bg:$cardBg'`
512
+ *
513
+ * Supports the same CSS shortcuts as {@link $ | A} and CSS variable references with `$` (e.g., `$primary`, `$3`).
514
+ *
515
+ * @param style - A concise style string or a style object.
516
+ * @returns The unique class name prefix used for scoping (e.g., `.AbdStl1`).
517
+ * Use this prefix with {@link $ | A} to apply the styles.
518
+ *
519
+ * @example Basic Usage with Shortcuts and CSS Variables
520
+ * ```typescript
521
+ * const cardClass = A.insertCss({
522
+ * '&': 'bg:white p:$4 r:8px transition: background-color 0.3s;',
523
+ * '&:hover': 'bg:#f5f5f5',
524
+ * });
525
+ *
526
+ * A('section', cardClass, () => {
527
+ * A('p#Card content');
528
+ * });
529
+ * ```
530
+ *
531
+ * @example Nested Selectors and Media Queries
532
+ * ```typescript
533
+ * const formClass = A.insertCss({
534
+ * '&': 'bg:#0004 p:$3 r:$2',
535
+ * button: {
536
+ * '&': 'bg:$primary fg:white p:$2 r:4px cursor:pointer',
537
+ * '&:hover': 'bg:$primaryHover',
538
+ * '&:disabled': 'bg:#ccc cursor:not-allowed',
539
+ * '.icon': 'display:inline-block mr:$1',
540
+ * '@media (max-width: 600px)': 'p:$1 font-size:14px'
541
+ * }
542
+ * });
543
+ *
544
+ * A('form', formClass, () => {
545
+ * A('button', () => {
546
+ * A('span.icon text=🔥');
547
+ * A('#Click Me');
548
+ * });
549
+ * });
550
+ * ```
551
+ *
552
+ * @example Complex CSS Values
553
+ * ```typescript
554
+ * const badge = A.insertCss({
555
+ * '&::before': 'content: "★"; color:gold mr:$1',
556
+ * '&': 'position:relative box-shadow: 0 2px 8px rgba(0,0,0,0.15);'
557
+ * });
558
+ *
559
+ * A(badge + ' span#Product Name');
560
+ * ```
561
+ */
562
+ export declare function insertCss(style: string | object): string;
563
+ /**
564
+ * Inserts CSS rules globally (unscoped).
565
+ *
566
+ * Works exactly like {@link insertCss}, but without prefixing selectors with a unique class name.
567
+ * This is useful for global resets, base styles, or styles that need to apply to the entire document.
568
+ *
569
+ * Accepts the same concise style string syntax and CSS shortcuts as {@link insertCss}.
570
+ * See {@link insertCss} for detailed documentation on syntax and shortcuts.
571
+ *
572
+ * @param style - Object with selectors as keys and concise CSS strings as values.
573
+ *
574
+ * @example Global Reset and Base Styles
575
+ * ```typescript
576
+ * // Set up global styles using CSS shortcuts
577
+ * A.insertGlobalCss({
578
+ * "*": "m:0 p:0 box-sizing:border-box",
579
+ * "body": "font-family: system-ui, sans-serif; m:0 p:$3 bg:#434 fg:#d0dafa",
580
+ * "a": "text-decoration:none fg:#57f",
581
+ * "a:hover": "text-decoration:underline",
582
+ * "code": "font-family:monospace bg:#222 fg:#afc p:4px r:3px"
583
+ * });
584
+ *
585
+ * A('h2#Title without margins');
586
+ * A('a#This is a link');
587
+ * A('code#const x = 42;');
588
+ * ```
589
+ *
590
+ * @example Responsive Global Styles
591
+ * ```typescript
592
+ * A.insertGlobalCss({
593
+ * "html": "font-size:16px",
594
+ * "body": "line-height:1.6",
595
+ * "h1, h2, h3": "font-weight:600 mt:$4 mb:$2",
596
+ * "@media (max-width: 768px)": {
597
+ * "html": "font-size:14px",
598
+ * "body": "p:$2"
599
+ * },
600
+ * "@media (prefers-color-scheme: dark)": {
601
+ * "body": "bg:#1a1a1a fg:#e5e5e5",
602
+ * "code": "bg:#2a2a2a"
603
+ * }
604
+ * });
605
+ * ```
606
+ */
607
+ export declare function insertGlobalCss(style: object): void;
608
+ /**
609
+ * Sets a custom error handler function for errors that occur asynchronously
610
+ * within reactive scopes (e.g., during updates triggered by proxy changes in
611
+ * {@link derive} or {@link $ | A} render functions).
612
+ *
613
+ * The default handler logs the error to `console.error` and adds a simple
614
+ * 'Error' message div to the DOM at the location where the error occurred (if possible).
615
+ *
616
+ * Your handler can provide custom logging, UI feedback, or suppress the default
617
+ * error message.
618
+ *
619
+ * @param handler - A function that accepts the `Error` object.
620
+ * - Return `false` to prevent adding an error message to the DOM.
621
+ * - Return `true` or `undefined` (or throw) to allow the error messages to be added to the DOM.
622
+ *
623
+ * @example Custom Logging and Suppressing Default Message
624
+ * ```typescript
625
+ * A.setErrorHandler(error => {
626
+ * console.warn('Aberdeen render error:', error.message);
627
+ * // Log to error reporting service
628
+ * // myErrorReporter.log(error);
629
+ *
630
+ * try {
631
+ * // Attempt to show a custom message in the UI
632
+ * A('div#Oops, something went wrong!', errorClass);
633
+ * } catch (e) {
634
+ * // Ignore errors during error handling itself
635
+ * }
636
+ *
637
+ * return false; // Suppress default console log and DOM error message
638
+ * });
639
+ *
640
+ * // Styling for our custom error message
641
+ * const errorClass = A.insertCss('background-color:#e31f00 display:inline-block color:white r:3px padding: 2px 4px;');
642
+ *
643
+ * // Cause an error within a render scope.
644
+ * A('div.box', () => {
645
+ * // Will cause our error handler to insert an error message within the box
646
+ * noSuchFunction();
647
+ * })
648
+ * ```
649
+ */
650
+ export declare function setErrorHandler(handler?: (error: Error) => boolean | undefined): void;
651
+ /**
652
+ * Registers a cleanup function to be executed just before the current reactive scope
653
+ * is destroyed or redraws.
654
+ *
655
+ * This is useful for releasing resources, removing manual event listeners, or cleaning up
656
+ * side effects associated with the scope. Cleaners are run in reverse order of registration.
657
+ *
658
+ * Scopes are created by functions like {@link derive}, {@link mount}, {@link $ | A} (when given a render function),
659
+ * and internally by constructs like {@link onEach}.
660
+ *
661
+ * @param cleaner - The function to execute during cleanup.
662
+ *
663
+ * @example Maintaing a sum for a changing array
664
+ * ```typescript
665
+ * const myArray = A.proxy([3, 5, 10]);
666
+ * let sum = A.proxy(0);
667
+ *
668
+ * // Show the array items and maintain the sum
669
+ * A.onEach(myArray, (item, index) => {
670
+ * A(`code#${index}→${item}`);
671
+ * // We'll update sum.value using peek, as += first does a read, but
672
+ * // we don't want to subscribe.
673
+ * A.peek(() => sum.value += item);
674
+ * // Clean gets called before each rerun for a certain item index
675
+ * // No need for peek here, as the clean code doesn't run in an
676
+ * // observer scope.
677
+ * A.clean(() => sum.value -= item);
678
+ * })
679
+ *
680
+ * // Show the sum
681
+ * A('h1 text=', sum);
682
+ *
683
+ * // Make random changes to the array
684
+ * const rnd = () => 0|(Math.random()*20);
685
+ * setInterval(() => myArray[rnd()] = rnd(), 1000);
686
+ * ```
687
+ */
688
+ export declare function clean(cleaner: () => void): void;
689
+ /**
690
+ * Creates a reactive scope that automatically re-executes the provided function
691
+ * whenever any proxied data (created by {@link proxy}) read during its last execution changes, storing
692
+ * its return value in an observable.
693
+ *
694
+ * Updates are batched and run asynchronously shortly after the changes occur.
695
+ * Use {@link clean} to register cleanup logic for the scope.
696
+ * Use {@link peek} or {@link unproxy} within the function to read proxied data without subscribing to it.
697
+ *
698
+ * @param func - The function to execute reactively. Any DOM manipulations should typically
699
+ * be done using {@link $ | A} within this function. Its return value will be made available as an
700
+ * observable returned by the `derive()` function.
701
+ * @returns An observable object, with its `value` property containing whatever the last run of `func` returned.
702
+ *
703
+ * @example Observation creating a UI components
704
+ * ```typescript
705
+ * const data = A.proxy({ user: 'Frank', notifications: 42 });
706
+ *
707
+ * A('main', () => {
708
+ * console.log('Welcome');
709
+ * A('h3#Welcome, ' + data.user); // Reactive text
710
+ *
711
+ * A.derive(() => {
712
+ * // When data.notifications changes, only this inner scope reruns,
713
+ * // leaving the `<p>Welcome, ..</p>` untouched.
714
+ * console.log('Notifications');
715
+ * A('code.notification-badge text=', data.notifications);
716
+ * A('a text=Notify! click=', () => data.notifications++);
717
+ * });
718
+ * });
719
+ * ```
720
+ *
721
+ * ***Note*** that the above could just as easily be done using `A(func)` instead of `derive(func)`.
722
+ *
723
+ * @example Observation with return value
724
+ * ```typescript
725
+ * const counter = A.proxy(0);
726
+ * setInterval(() => counter.value++, 1000);
727
+ * const double = A.derive(() => counter.value * 2);
728
+ *
729
+ * A('h3', () => {
730
+ * A(`#counter=${counter.value} double=${double.value}`);
731
+ * })
732
+ * ```
733
+ *
734
+ * @overload
735
+ * @param func Func without a return value.
736
+ */
737
+ export declare function derive<T>(func: () => T): ValueRef<T>;
738
+ /**
739
+ * Attaches a reactive Aberdeen UI fragment to an existing DOM element. Without the use of
740
+ * this function, {@link $ | A} will assume `document.body` as its root.
741
+ *
742
+ * It creates a top-level reactive scope associated with the `parentElement`. The provided
743
+ * function `func` is executed immediately within this scope. Any proxied data read by `func`
744
+ * will cause it to re-execute when the data changes, updating the DOM elements created within it.
745
+ *
746
+ * Calls to {@link $ | A} inside `func` will append nodes to `parentElement`.
747
+ * You can nest {@link derive} or other {@link $ | A} scopes within `func`.
748
+ * Use {@link unmountAll} to clean up all mounted scopes and their DOM nodes.
749
+ *
750
+ * Mounting scopes happens reactively, meaning that if this function is called from within another
751
+ * ({@link derive} or {@link $ | A} or {@link mount}) scope that gets cleaned up, so will the mount.
752
+ *
753
+ * @param parentElement - The native DOM `Element` to which the UI fragment will be appended.
754
+ * @param func - The function that defines the UI fragment, typically containing calls to {@link $ | A}.
755
+ *
756
+ * @example Basic Mount
757
+ * ```javascript
758
+ * // Create a pre-existing DOM structure (without Aberdeen)
759
+ * document.body.innerHTML = `<h3>Static content <span id="title-extra"></span></h3><div class="box" id="app-root"></div>`;
760
+ *
761
+ * import A from 'aberdeen';
762
+ *
763
+ * const runTime = A.proxy(0);
764
+ * setInterval(() => runTime.value++, 1000);
765
+ *
766
+ * A.mount(document.getElementById('app-root'), () => {
767
+ * A('h4#Aberdeen App');
768
+ * A(`p#Run time: ${runTime.value}s`);
769
+ * // Conditionally render some content somewhere else in the static page
770
+ * if (runTime.value&1) {
771
+ * A.mount(document.getElementById('title-extra'), () =>
772
+ * A(`i#(${runTime.value}s)`)
773
+ * );
774
+ * }
775
+ * });
776
+ * ```
777
+ *
778
+ * Note how the inner mount behaves reactively as well, automatically unmounting when it's parent observer scope re-runs.
779
+ */
780
+ export declare function mount(parentElement: Element, func: () => void): void;
781
+ /**
782
+ * Removes all Aberdeen-managed DOM nodes and stops all active reactive scopes
783
+ * (created by {@link mount}, {@link derive}, {@link $ | A} with functions, etc.).
784
+ *
785
+ * This effectively cleans up the entire Aberdeen application state. Aside from in
786
+ * automated tests, there should probably be little reason to call this function.
787
+ */
788
+ export declare function unmountAll(): void;
789
+ /**
790
+ * Executes a function or retrieves a value *without* creating subscriptions in the current reactive scope, and returns its result.
791
+ *
792
+ * This is useful when you need to access reactive data inside a reactive scope (like {@link $ | A})
793
+ * but do not want changes to that specific data to trigger a re-execute of the scope.
794
+ *
795
+ * Note: You may also use {@link unproxy} to get to the raw underlying data structure, which can be used to similar effect.
796
+ *
797
+ * @param target - Either a function to execute, or an object (which may also be an Array or a Map) to index.
798
+ * @param key - Optional key/index to use when `target` is an object.
799
+ * @returns The result of the function call, or the value at `target[key]` when `target` is an object or `target.get(key)` when it's a Map.
800
+ *
801
+ * @example Peeking within observer
802
+ * ```typescript
803
+ * const data = A.proxy({ a: 1, b: 2 });
804
+ * A(() => {
805
+ * // re-executes only when data.a changes, because data.b is peeked.
806
+ * const b = A.peek(() => data.b);
807
+ * console.log(`A is ${data.a}, B was ${b} when A changed.`);
808
+ * });
809
+ * data.b = 3; // Does not trigger console.log
810
+ * data.a = 2; // Triggers console.log (logs "A is 2, B was 3 when A changed.")
811
+ * ```
812
+ *
813
+ */
814
+ export declare function peek<T extends object, K extends keyof T>(target: T, key: K): T[K];
815
+ export declare function peek<K, V>(target: Map<K, V>, key: K): V | undefined;
816
+ export declare function peek<T>(target: T[], key: number): T | undefined;
817
+ export declare function peek<T>(target: () => T): T;
818
+ /** When using a Map as `source`. */
819
+ export declare function map<K, IN, OUT>(source: Map<K, IN>, func: (value: IN, key: K) => undefined | OUT): Map<K, OUT>;
820
+ /** When using an array as `source`. */
821
+ export declare function map<IN, OUT>(source: Array<IN>, func: (value: IN, index: number) => undefined | OUT): Array<OUT>;
822
+ /** When using an object as `source`. */
823
+ export declare function map<IN, const IN_KEY extends string | number | symbol, OUT>(source: Record<IN_KEY, IN>, func: (value: IN, index: KeyToString<IN_KEY>) => undefined | OUT): Record<string | symbol, OUT>;
824
+ /** When using an array as `source`. */
825
+ export declare function multiMap<IN, OUT extends {
826
+ [key: string | symbol]: any;
827
+ }>(source: Array<IN>, func: (value: IN, index: number) => OUT | undefined): OUT;
828
+ /** When using an object as `source`. */
829
+ export declare function multiMap<K extends string | number | symbol, IN, OUT extends {
830
+ [key: string | symbol]: any;
831
+ }>(source: Record<K, IN>, func: (value: IN, index: KeyToString<K>) => OUT | undefined): OUT;
832
+ /** When using a Map as `source`. */
833
+ export declare function multiMap<K, IN, OUT extends {
834
+ [key: string | symbol]: any;
835
+ }>(source: Map<K, IN>, func: (value: IN, key: K) => OUT | undefined): OUT;
836
+ /** When using an object as `array`. */
837
+ export declare function partition<OUT_K extends string | number | symbol, IN_V>(source: IN_V[], func: (value: IN_V, key: number) => undefined | OUT_K | OUT_K[]): Record<OUT_K, Record<number, IN_V>>;
838
+ /** When using an object as `source`. */
839
+ export declare function partition<IN_K extends string | number | symbol, OUT_K extends string | number | symbol, IN_V>(source: Record<IN_K, IN_V>, func: (value: IN_V, key: IN_K) => undefined | OUT_K | OUT_K[]): Record<OUT_K, Record<IN_K, IN_V>>;
840
+ /** When using a Map as `source`. */
841
+ export declare function partition<IN_K extends string | number | symbol, OUT_K extends string | number | symbol, IN_V>(source: Map<IN_K, IN_V>, func: (value: IN_V, key: IN_K) => undefined | OUT_K | OUT_K[]): Record<OUT_K, Record<IN_K, IN_V>>;
842
+ /**
843
+ * Renders a live, recursive dump of a proxied data structure (or any value)
844
+ * into the DOM at the current {@link $ | A} insertion point.
845
+ *
846
+ * Uses `<ul>` and `<li>` elements to display object properties and array items.
847
+ * Updates reactively if the dumped data changes. Primarily intended for debugging purposes.
848
+ *
849
+ * @param data - The proxied data structure (or any value) to display.
850
+ * @returns The original `data` argument, allowing for chaining.
851
+ * @template T - The type of the data being dumped.
852
+ *
853
+ * @example Dumping reactive state
854
+ * ```typescript
855
+ * import A from 'aberdeen';
856
+ *
857
+ * const state = A.proxy({
858
+ * user: { name: 'Frank', kids: 1 },
859
+ * items: ['a', 'b']
860
+ * });
861
+ *
862
+ * A('h2#Live State Dump');
863
+ * A.dump(state);
864
+ *
865
+ * // Change state later, the dump in the DOM will update
866
+ * setTimeout(() => { state.user.kids++; state.items.push('c'); }, 2000);
867
+ * ```
868
+ */
869
+ export declare function dump<T>(data: T): T;
870
+ /**
871
+ * The main Aberdeen API. `A` is itself a callable function for building reactive DOM trees
872
+ * (creating elements, setting attributes, adding content). All other Aberdeen functions and
873
+ * values are available as properties on `A`.
874
+ *
875
+ * @example Basic usage
876
+ * ```typescript
877
+ * import A from 'aberdeen';
878
+ *
879
+ * const state = A.proxy({ count: 0 });
880
+ * A('div', () => {
881
+ * A(`p#Count: ${state.count}`);
882
+ * A('button text=+ click=', () => state.count++);
883
+ * });
884
+ * ```
885
+ */
886
+ declare const A: typeof $ & {
887
+ /** {@inheritDoc clean} */ clean: typeof clean;
888
+ /** {@inheritDoc clone} */ clone: typeof clone;
889
+ /** {@inheritDoc copy} */ copy: typeof copy;
890
+ /** {@inheritDoc count} */ count: typeof count;
891
+ /** {@inheritDoc cssVars} */ cssVars: Record<string, string>;
892
+ /** {@inheritDoc darkMode} */ darkMode: typeof darkMode;
893
+ /** {@inheritDoc derive} */ derive: typeof derive;
894
+ /** {@inheritDoc disableCreateDestroy} */ disableCreateDestroy: typeof disableCreateDestroy;
895
+ /** {@inheritDoc dump} */ dump: typeof dump;
896
+ /** {@inheritDoc insertCss} */ insertCss: typeof insertCss;
897
+ /** {@inheritDoc insertGlobalCss} */ insertGlobalCss: typeof insertGlobalCss;
898
+ /** {@inheritDoc invertString} */ invertString: typeof invertString;
899
+ /** {@inheritDoc isEmpty} */ isEmpty: typeof isEmpty;
900
+ /** {@inheritDoc map} */ map: typeof map;
901
+ /** {@inheritDoc merge} */ merge: typeof merge;
902
+ /** {@inheritDoc mount} */ mount: typeof mount;
903
+ /** {@inheritDoc multiMap} */ multiMap: typeof multiMap;
904
+ /** {@inheritDoc NO_COPY} */ NO_COPY: symbol;
905
+ /** {@inheritDoc onEach} */ onEach: typeof onEach;
906
+ /** {@inheritDoc partition} */ partition: typeof partition;
907
+ /** {@inheritDoc peek} */ peek: typeof peek;
908
+ /** {@inheritDoc proxy} */ proxy: typeof proxy;
909
+ /** {@inheritDoc ref} */ ref: typeof ref;
910
+ /** {@inheritDoc runQueue} */ runQueue: typeof runQueue;
911
+ /** {@inheritDoc setErrorHandler} */ setErrorHandler: typeof setErrorHandler;
912
+ /** {@inheritDoc setSpacingCssVars} */ setSpacingCssVars: typeof setSpacingCssVars;
913
+ /** {@inheritDoc unmountAll} */ unmountAll: typeof unmountAll;
914
+ /** {@inheritDoc unproxy} */ unproxy: typeof unproxy;
915
+ };
916
+ export default A;