mutts 1.0.11 → 1.0.13

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 (59) hide show
  1. package/README.md +5 -2
  2. package/dist/browser.cjs +237 -2596
  3. package/dist/browser.cjs.map +1 -1
  4. package/dist/browser.d.ts +1407 -2
  5. package/dist/browser.dev.cjs +44 -43
  6. package/dist/browser.dev.cjs.map +1 -1
  7. package/dist/browser.dev.d.ts +2 -2
  8. package/dist/browser.dev.esm.js +2 -2
  9. package/dist/browser.esm.js +3 -3
  10. package/dist/chunks/index-CAdnMJev.cjs +2735 -0
  11. package/dist/chunks/index-CAdnMJev.cjs.map +1 -0
  12. package/dist/chunks/{index-Sf74wXTV.esm.js → index-XsYTUhHx.esm.js} +200 -77
  13. package/dist/chunks/index-XsYTUhHx.esm.js.map +1 -0
  14. package/dist/chunks/{async-node-3PrbVAbB.cjs → node-DrrphEPf.cjs} +4 -4
  15. package/dist/chunks/node-DrrphEPf.cjs.map +1 -0
  16. package/dist/chunks/{node-Bo7WU5S2.esm.js → node-NEZvVo4M.esm.js} +2 -2
  17. package/dist/chunks/{node-Bo7WU5S2.esm.js.map → node-NEZvVo4M.esm.js.map} +1 -1
  18. package/dist/chunks/{proxy-D2C49sXH.esm.js → proxy-BtmPFjSr.esm.js} +307 -66
  19. package/dist/chunks/proxy-BtmPFjSr.esm.js.map +1 -0
  20. package/dist/chunks/{proxy-Cc79Lrzj.cjs → proxy-DBHj3kGK.cjs} +341 -70
  21. package/dist/chunks/proxy-DBHj3kGK.cjs.map +1 -0
  22. package/dist/debug.cjs +537 -167
  23. package/dist/debug.cjs.map +1 -1
  24. package/dist/debug.d.ts +96 -80
  25. package/dist/debug.esm.js +533 -166
  26. package/dist/debug.esm.js.map +1 -1
  27. package/dist/devtools/panel.js.map +1 -1
  28. package/dist/mutts.umd.js +508 -140
  29. package/dist/mutts.umd.js.map +1 -1
  30. package/dist/mutts.umd.min.js +1 -1
  31. package/dist/mutts.umd.min.js.map +1 -1
  32. package/dist/node.cjs +44 -42
  33. package/dist/node.cjs.map +1 -1
  34. package/dist/node.d.ts +2 -2
  35. package/dist/node.dev.cjs +44 -42
  36. package/dist/node.dev.cjs.map +1 -1
  37. package/dist/node.dev.d.ts +2 -2
  38. package/dist/node.dev.esm.js +3 -3
  39. package/dist/node.esm.js +3 -3
  40. package/dist/{types-Bx2PhORg.d.ts → types.d.ts} +12 -0
  41. package/docs/ai/api-reference.md +102 -12
  42. package/docs/ai/manual.md +60 -24
  43. package/docs/debug-getReason.md +161 -0
  44. package/docs/flavored.md +98 -1
  45. package/docs/reactive/advanced.md +15 -2
  46. package/docs/reactive/attend.md +32 -0
  47. package/docs/reactive/core.md +40 -6
  48. package/docs/reactive/debugging.md +25 -2
  49. package/docs/reactive.md +2 -0
  50. package/package.json +2 -3
  51. package/dist/chunks/async-browser-Dgr5CreQ.cjs +0 -218
  52. package/dist/chunks/async-browser-Dgr5CreQ.cjs.map +0 -1
  53. package/dist/chunks/async-core-CRLKP3l-.cjs +0 -29
  54. package/dist/chunks/async-core-CRLKP3l-.cjs.map +0 -1
  55. package/dist/chunks/async-node-3PrbVAbB.cjs.map +0 -1
  56. package/dist/chunks/index-Sf74wXTV.esm.js.map +0 -1
  57. package/dist/chunks/proxy-Cc79Lrzj.cjs.map +0 -1
  58. package/dist/chunks/proxy-D2C49sXH.esm.js.map +0 -1
  59. package/dist/index.d.ts +0 -1322
package/dist/index.d.ts DELETED
@@ -1,1322 +0,0 @@
1
- import { c as EffectAccess, d as EffectCloser, S as ScopedCallback, e as State, a as Evolution, b as EffectCleanup, Z as ZoneAggregator, C as CleanupReason, H as HistoryValue, E as EffectTrigger, f as CatchFunction, g as EffectOptions } from './types-Bx2PhORg.js';
2
- export { A as AZone, G as GetterWrapper, P as PropTrigger, R as ReactiveError, h as ReactiveErrorCode, i as Zone, j as ZoneHistory, k as asyncZone, l as debugPreset, m as devPreset, n as formatCleanupReason, o as isReactive, p as objectToProxy, q as prodPreset, r as proxyToObject, s as reactiveOptions, u as unwrap } from './types-Bx2PhORg.js';
3
-
4
- type Restorer = () => () => void;
5
- type Hook = () => Restorer;
6
- declare const hooks$1: Set<Hook>;
7
- declare const asyncHooks: {
8
- addHook(hook: Hook): () => void;
9
- /**
10
- * [Hack] Sanitize a promise (or value) to prevent context leaks.
11
- * Default: Identity function.
12
- * Browser: Uses Macrotask wrapping to break microtask chains.
13
- */
14
- sanitizePromise(p: any): any;
15
- };
16
- /**
17
- * Register a hook that will be called whenever an asynchronous operation is initiated.
18
- * The hook should return a restorer function which will be called just before the async callback runs.
19
- * That restorer should in turn return an undoer function which will be called just after the async callback finishes.
20
- */
21
- declare const asyncHook: (hook: Hook) => () => void;
22
-
23
- /**
24
- * Error thrown when decorator operations fail
25
- */
26
- declare class DecoratorError extends Error {
27
- constructor(message: string);
28
- }
29
- /**
30
- * Legacy property decorator type for methods, getters, and setters
31
- */
32
- type LegacyPropertyDecorator<T> = (target: T, name: string | symbol, descriptor: PropertyDescriptor) => any;
33
- /**
34
- * Legacy class decorator type
35
- */
36
- type LegacyClassDecorator<T> = (target: T) => any;
37
- /**
38
- * Modern method decorator type
39
- */
40
- type ModernMethodDecorator<T> = (target: T, context: ClassMethodDecoratorContext) => any;
41
- /**
42
- * Modern getter decorator type
43
- */
44
- type ModernGetterDecorator<T> = (target: T, context: ClassGetterDecoratorContext) => any;
45
- /**
46
- * Modern setter decorator type
47
- */
48
- type ModernSetterDecorator<T> = (target: T, context: ClassSetterDecoratorContext) => any;
49
- /**
50
- * Modern accessor decorator type
51
- */
52
- type ModernAccessorDecorator<T> = (target: T, context: ClassAccessorDecoratorContext) => any;
53
- /**
54
- * Modern class decorator type
55
- */
56
- type ModernClassDecorator<T> = (target: T, context: ClassDecoratorContext) => any;
57
- type DDMethod<T> = (original: (this: T, ...args: any[]) => any, target: any, name: PropertyKey) => ((this: T, ...args: any[]) => any) | void;
58
- type DDGetter<T> = (original: (this: T) => any, target: any, name: PropertyKey) => ((this: T) => any) | void;
59
- type DDSetter<T> = (original: (this: T, value: any) => void, target: any, name: PropertyKey) => ((this: T, value: any) => void) | void;
60
- type DDClass<T> = <Ctor extends new (...args: any[]) => T = new (...args: any[]) => T>(target: Ctor) => Ctor | void;
61
- /**
62
- * Description object for creating decorators that work with both Legacy and Modern decorator proposals
63
- */
64
- interface DecoratorDescription<T> {
65
- /** Handler for method decorators */
66
- method?: DDMethod<T>;
67
- /** Handler for class decorators */
68
- class?: DDClass<T>;
69
- /** Handler for getter decorators */
70
- getter?: DDGetter<T>;
71
- /** Handler for setter decorators */
72
- setter?: DDSetter<T>;
73
- /** Default handler for any decorator type not explicitly defined */
74
- default?: (...args: any[]) => any;
75
- }
76
- /**
77
- * Type for decorators that work with both Legacy and Modern decorator proposals
78
- * Automatically infers the correct decorator type based on the description
79
- */
80
- type Decorator<T, Description extends DecoratorDescription<T>> = (Description extends {
81
- method: DDMethod<T>;
82
- } ? LegacyPropertyDecorator<T> & ModernMethodDecorator<T> : unknown) & (Description extends {
83
- class: DDClass<new (...args: any[]) => T>;
84
- } ? LegacyClassDecorator<new (...args: any[]) => T> & ModernClassDecorator<new (...args: any[]) => T> : unknown) & (Description extends {
85
- getter: DDGetter<T>;
86
- } ? LegacyPropertyDecorator<T> & ModernGetterDecorator<T> & ModernAccessorDecorator<T> : unknown) & (Description extends {
87
- setter: DDSetter<T>;
88
- } ? LegacyPropertyDecorator<T> & ModernSetterDecorator<T> & ModernAccessorDecorator<T> : unknown) & (Description extends {
89
- default: infer Signature;
90
- } ? Signature : unknown);
91
- /**
92
- * Factory type for creating decorators that work with both Legacy and Modern decorator proposals
93
- */
94
- type DecoratorFactory<T> = <Description extends DecoratorDescription<T>>(description: Description) => (Description extends {
95
- method: DDMethod<T>;
96
- } ? LegacyPropertyDecorator<T> & ModernMethodDecorator<T> : unknown) & (Description extends {
97
- class: DDClass<new (...args: any[]) => T>;
98
- } ? LegacyClassDecorator<new (...args: any[]) => T> & ModernClassDecorator<new (...args: any[]) => T> : unknown) & (Description extends {
99
- getter: DDGetter<T>;
100
- } ? LegacyPropertyDecorator<T> & ModernGetterDecorator<T> & ModernAccessorDecorator<T> : unknown) & (Description extends {
101
- setter: DDSetter<T>;
102
- } ? LegacyPropertyDecorator<T> & ModernSetterDecorator<T> & ModernAccessorDecorator<T> : unknown) & (Description extends {
103
- default: infer Signature;
104
- } ? Signature : unknown);
105
- /**
106
- * Creates a decorator that works with Legacy decorator proposals
107
- * @param description - The decorator description object
108
- * @returns A decorator function compatible with Legacy decorators
109
- */
110
- declare function legacyDecorator<T = any>(description: DecoratorDescription<T>): any;
111
- /**
112
- * Creates a decorator that works with Modern decorator proposals
113
- * @param description - The decorator description object
114
- * @returns A decorator function compatible with Modern decorators
115
- */
116
- declare function modernDecorator<T = any>(description: DecoratorDescription<T>): any;
117
- /**
118
- * Main decorator factory that automatically detects and works with both Legacy and Modern decorator proposals
119
- * @param description - The decorator description object
120
- * @returns A decorator that works in both Legacy and Modern environments
121
- */
122
- declare const decorator: DecoratorFactory<any>;
123
- /**
124
- * Generic class decorator type that works with both Legacy and Modern decorator proposals
125
- */
126
- type GenericClassDecorator<T> = LegacyClassDecorator<abstract new (...args: any[]) => T> & ModernClassDecorator<abstract new (...args: any[]) => T>;
127
-
128
- /**
129
- * Symbol for marking destructor methods
130
- */
131
- declare const destructor: unique symbol;
132
- /**
133
- * Symbol for accessing allocated values in destroyable objects
134
- */
135
- declare const allocatedValues: unique symbol;
136
- /**
137
- * Error thrown when attempting to access a destroyed object
138
- */
139
- declare class DestructionError extends Error {
140
- static throw<_T = void>(msg: string): () => never;
141
- constructor(msg: string);
142
- }
143
- declare abstract class AbstractDestroyable<Allocated> {
144
- abstract [destructor](allocated: Allocated): void;
145
- [Symbol.dispose](): void;
146
- }
147
- interface Destructor<Allocated> {
148
- destructor(allocated: Allocated): void;
149
- }
150
- /**
151
- * Creates a destroyable class with a base class and destructor object
152
- * @param base - The base class to extend
153
- * @param destructorObj - Object containing the destructor method
154
- * @returns A destroyable class with static destroy and isDestroyable methods
155
- */
156
- declare function Destroyable<T extends new (...args: any[]) => any, Allocated extends Partial<InstanceType<T>>>(base: T, destructorObj: Destructor<Allocated>): (new (...args: ConstructorParameters<T>) => InstanceType<T> & {
157
- [allocatedValues]: Allocated;
158
- }) & {
159
- destroy(obj: InstanceType<T>): boolean;
160
- isDestroyable(obj: InstanceType<T>): boolean;
161
- };
162
- /**
163
- * Creates a destroyable class with only a destructor object (no base class)
164
- * @param destructorObj - Object containing the destructor method
165
- * @returns A destroyable class with static destroy and isDestroyable methods
166
- */
167
- declare function Destroyable<Allocated extends Record<PropertyKey, any> = Record<PropertyKey, any>>(destructorObj: Destructor<Allocated>): (new () => {
168
- [allocatedValues]: Allocated;
169
- }) & {
170
- destroy(obj: any): boolean;
171
- isDestroyable(obj: any): boolean;
172
- };
173
- /**
174
- * Creates a destroyable class with a base class (requires [destructor] method)
175
- * @param base - The base class to extend
176
- * @returns A destroyable class with static destroy and isDestroyable methods
177
- */
178
- declare function Destroyable<T extends new (...args: any[]) => any, Allocated extends Record<PropertyKey, any> = Record<PropertyKey, any>>(base: T): (new (...args: ConstructorParameters<T>) => AbstractDestroyable<Allocated> & InstanceType<T> & {
179
- [allocatedValues]: Allocated;
180
- }) & {
181
- destroy(obj: InstanceType<T>): boolean;
182
- isDestroyable(obj: InstanceType<T>): boolean;
183
- };
184
- /**
185
- * Creates an abstract destroyable base class
186
- * @returns An abstract destroyable class with static destroy and isDestroyable methods
187
- */
188
- declare function Destroyable<Allocated extends Record<PropertyKey, any> = Record<PropertyKey, any>>(): abstract new () => (AbstractDestroyable<Allocated> & {
189
- [allocatedValues]: Allocated;
190
- }) & {
191
- destroy(obj: any): boolean;
192
- isDestroyable(obj: any): boolean;
193
- };
194
- /**
195
- * Decorator that marks properties to be stored in the allocated object and passed to the destructor
196
- * Use with accessor properties or explicit get/set pairs
197
- */
198
- declare const allocated: LegacyPropertyDecorator<any> & ModernSetterDecorator<any> & ModernAccessorDecorator<any>;
199
- /**
200
- * Registers a callback to be called when an object is garbage collected
201
- * @param cb - The callback function to execute on garbage collection
202
- * @returns The object whose reference can be collected
203
- */
204
- declare function callOnGC(cb: () => void): () => void;
205
- /**
206
- * Context Manager Protocol for `using` statement integration
207
- * Provides automatic resource cleanup when used with the `using` statement
208
- */
209
- interface ContextManager<T = any> {
210
- [Symbol.dispose](): void;
211
- value?: T;
212
- }
213
-
214
- interface ArrayDiffResult<T> {
215
- indexA: number;
216
- indexB: number;
217
- sliceA: T[];
218
- sliceB: T[];
219
- }
220
- /**
221
- * Myers' diff producing grouped patches: `{indexA, indexB, sliceA, sliceB}[]`.
222
- * - O(N) for identical or prefix/suffix-only differences
223
- * - O(ND) for small D, with a hard bailout at D=BAILOUT_D → single replacement patch
224
- */
225
- declare function arrayDiff<T>(A: readonly T[], B: readonly T[]): ArrayDiffResult<T>[];
226
-
227
- /**
228
- * Base type for event maps - all event handlers must be functions
229
- */
230
- type EventsBase = Record<string, (...args: any[]) => void>;
231
- declare const events: unique symbol;
232
- declare const hooks: unique symbol;
233
- /**
234
- * A type-safe event system that provides a clean API for event handling
235
- * @template Events - The event map defining event names and their handler signatures
236
- */
237
- declare class Eventful<Events extends EventsBase> {
238
- private readonly [events];
239
- private readonly [hooks];
240
- hook(cb: <EventType extends keyof Events>(event: EventType, ...args: Parameters<Events[EventType]>) => void): () => void;
241
- on: ((events: Partial<Events>) => void) & (<EventType extends keyof Events>(event: EventType, cb: Events[EventType]) => () => void) & { [event in keyof Events]: (cb: Events[event]) => () => void; };
242
- off: ((events: Partial<Events>) => void) & (<EventType extends keyof Events>(event: EventType, cb?: Events[EventType]) => void) & { [event in keyof Events]: (cb?: Events[event]) => void; };
243
- emit: (<EventType extends keyof Events>(event: EventType, ...args: Parameters<Events[EventType]>) => void) & Events;
244
- }
245
-
246
- /**
247
- * Creates a flavored (extensible) version of a function with chainable property modifiers.
248
- */
249
- declare function flavored<T extends (...args: any[]) => any, F>(fn: T, flavors: F & ThisType<T & F>): T & F;
250
- /**
251
- * Creates a new flavored function that transforms arguments before calling the base.
252
- *
253
- * @param fn - The base flavored function
254
- * @param transform - Function that receives the original arguments and returns transformed arguments
255
- * @returns A new flavored function with the transformation applied
256
- *
257
- * @example
258
- * ```typescript
259
- * const loudGreet = createFlavor(greet, (name, opts) => [name, { ...opts, loud: true }])
260
- * ```
261
- */
262
- declare function createFlavor<T extends (...args: any[]) => any>(fn: T, transform: (...args: Parameters<T>) => Parameters<T>, name?: string): T;
263
- /**
264
- * Creates a new flavored function that merges options objects at a specific index.
265
- * By default, uses the function's arity (length) as the index for options.
266
- *
267
- * @param fn - The base flavored function
268
- * @param defaultOptions - Options to merge
269
- * @param optionsIndex - Optional explicit index for options (defaults to fn.length)
270
- * @param name - Optional name for the wrapper
271
- * @returns A new flavored function
272
- */
273
- declare function flavorOptions<T extends (...args: any[]) => any>(fn: T, defaultOptions: Record<string, any>, opts?: {
274
- optionsIndex?: number;
275
- name?: string;
276
- }): T;
277
-
278
- /**
279
- * Symbol for defining custom getter logic for numeric index access
280
- */
281
- declare const getAt: unique symbol;
282
- /**
283
- * Symbol for defining custom setter logic for numeric index access
284
- */
285
- declare const setAt: unique symbol;
286
- interface IndexingAt<Items = any> {
287
- [getAt](index: number): Items;
288
- }
289
- interface Accessor<T, Items> {
290
- get(this: T, index: number): Items;
291
- set?(this: T, index: number, value: Items): void;
292
- getLength?(this: T): number;
293
- setLength?(this: T, value: number): void;
294
- }
295
- declare abstract class AbstractGetAt<Items = any> {
296
- abstract [getAt](index: number): Items;
297
- }
298
- /**
299
- * Creates an indexable class with a base class and accessor object
300
- * @param base - The base class to extend
301
- * @param accessor - Object containing get/set methods for numeric index access
302
- * @returns A class that supports numeric index access
303
- */
304
- declare function Indexable<Items, Base extends abstract new (...args: any[]) => any>(base: Base, accessor: Accessor<InstanceType<Base>, Items>): new (...args: ConstructorParameters<Base>) => InstanceType<Base> & {
305
- [x: number]: Items;
306
- };
307
- /**
308
- * Creates an indexable class with only an accessor object (no base class)
309
- * @param accessor - Object containing get/set methods for numeric index access
310
- * @returns A class that supports numeric index access
311
- */
312
- declare function Indexable<Items>(accessor: Accessor<any, Items>): new () => {
313
- [x: number]: Items;
314
- };
315
- /**
316
- * Creates an indexable class with a base class that has [getAt] method
317
- * @param base - The base class that implements [getAt] method
318
- * @returns A class that supports numeric index access using the base class's [getAt] method
319
- */
320
- declare function Indexable<Base extends new (...args: any[]) => IndexingAt>(base: Base): new (...args: ConstructorParameters<Base>) => InstanceType<Base> & {
321
- [x: number]: AtReturnType<InstanceType<Base>>;
322
- };
323
- /**
324
- * Creates an abstract indexable base class
325
- * @returns An abstract class that supports numeric index access
326
- */
327
- declare function Indexable<Items>(): abstract new (...args: any[]) => AbstractGetAt & {
328
- [x: number]: Items;
329
- };
330
- type AtReturnType<T> = T extends {
331
- [getAt](index: number): infer R;
332
- } ? R : never;
333
- /**
334
- * Symbol for accessing the forwarded array in ArrayReadForward
335
- */
336
- declare const forwardArray: unique symbol;
337
- /**
338
- * A read-only array forwarder that implements all reading/iterating methods of Array
339
- * but does not implement modification methods.
340
- *
341
- * The constructor takes a callback that returns an array, and all methods forward
342
- * their behavior to the result of that callback.
343
- */
344
- declare class ArrayReadForward<T> {
345
- protected get [forwardArray](): readonly T[];
346
- /**
347
- * Get the length of the array
348
- */
349
- get length(): number;
350
- /**
351
- * Get an element at a specific index
352
- */
353
- [index: number]: T | undefined;
354
- /**
355
- * Iterator protocol support
356
- */
357
- [Symbol.iterator](): Iterator<T>;
358
- /**
359
- * Creates a new array with the results of calling a provided function on every element
360
- */
361
- map<U>(callbackfn: (value: T, index: number, array: readonly T[]) => U, thisArg?: any): U[];
362
- /**
363
- * Creates a new array with all elements that pass the test implemented by the provided function
364
- */
365
- filter<S extends T>(predicate: (value: T, index: number, array: readonly T[]) => value is S, thisArg?: any): S[];
366
- filter(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): T[];
367
- /**
368
- * Executes a reducer function on each element of the array, resulting in a single output value
369
- */
370
- reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T): T;
371
- reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T, initialValue: T): T;
372
- reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: readonly T[]) => U, initialValue: U): U;
373
- /**
374
- * Executes a reducer function on each element of the array (right-to-left), resulting in a single output value
375
- */
376
- reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T): T;
377
- reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T, initialValue: T): T;
378
- reduceRight<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: readonly T[]) => U, initialValue: U): U;
379
- /**
380
- * Executes a provided function once for each array element
381
- */
382
- forEach(callbackfn: (value: T, index: number, array: readonly T[]) => void, thisArg?: any): void;
383
- /**
384
- * Returns the value of the first element in the array that satisfies the provided testing function
385
- */
386
- find<S extends T>(predicate: (value: T, index: number, array: readonly T[]) => value is S, thisArg?: any): S | undefined;
387
- find(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): T | undefined;
388
- /**
389
- * Returns the index of the first element in the array that satisfies the provided testing function
390
- */
391
- findIndex(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): number;
392
- /**
393
- * Returns the value of the last element in the array that satisfies the provided testing function
394
- */
395
- findLast<S extends T>(predicate: (value: T, index: number, array: readonly T[]) => value is S, thisArg?: any): S | undefined;
396
- findLast(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): T | undefined;
397
- /**
398
- * Returns the index of the last element in the array that satisfies the provided testing function
399
- */
400
- findLastIndex(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): number;
401
- /**
402
- * Determines whether an array includes a certain value among its entries
403
- */
404
- includes(searchElement: T, fromIndex?: number): boolean;
405
- /**
406
- * Returns the first index at which a given element can be found in the array
407
- */
408
- indexOf(searchElement: T, fromIndex?: number): number;
409
- /**
410
- * Returns the last index at which a given element can be found in the array
411
- */
412
- lastIndexOf(searchElement: T, fromIndex?: number): number;
413
- /**
414
- * Returns a shallow copy of a portion of an array into a new array object
415
- */
416
- slice(start?: number, end?: number): T[];
417
- /**
418
- * Returns a new array comprised of this array joined with other array(s) and/or value(s)
419
- */
420
- concat(...items: ConcatArray<T>[]): T[];
421
- concat(...items: (T | ConcatArray<T>)[]): T[];
422
- /**
423
- * Tests whether all elements in the array pass the test implemented by the provided function
424
- */
425
- every(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): boolean;
426
- /**
427
- * Tests whether at least one element in the array passes the test implemented by the provided function
428
- */
429
- some(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): boolean;
430
- /**
431
- * Joins all elements of an array into a string
432
- */
433
- join(separator?: string): string;
434
- /**
435
- * Returns a new array iterator that contains the keys for each index in the array
436
- */
437
- keys(): IterableIterator<number>;
438
- /**
439
- * Returns a new array iterator that contains the values for each index in the array
440
- */
441
- values(): IterableIterator<T>;
442
- /**
443
- * Returns a new array iterator that contains the key/value pairs for each index in the array
444
- */
445
- entries(): IterableIterator<[number, T]>;
446
- /**
447
- * Returns a string representation of the array
448
- */
449
- toString(): string;
450
- /**
451
- * Returns a localized string representing the array
452
- */
453
- toLocaleString(locales?: string | string[], options?: Intl.NumberFormatOptions | Intl.DateTimeFormatOptions): string;
454
- /**
455
- * Returns the element at the specified index, or undefined if the index is out of bounds
456
- */
457
- at(index: number): T | undefined;
458
- /**
459
- * Returns a new array with all sub-array elements concatenated into it recursively up to the specified depth
460
- */
461
- flat(depth?: number): T[];
462
- /**
463
- * Returns a new array formed by applying a given callback function to each element of the array,
464
- * and then flattening the result by one level
465
- */
466
- flatMap<U, This = undefined>(callback: (this: This, value: T, index: number, array: readonly T[]) => U | ReadonlyArray<U>, thisArg?: This): U[];
467
- /**
468
- * Returns a new array with elements in reversed order (ES2023)
469
- */
470
- toReversed(): T[];
471
- /**
472
- * Returns a new array with elements sorted (ES2023)
473
- */
474
- toSorted(compareFn?: ((a: T, b: T) => number) | undefined): T[];
475
- /**
476
- * Returns a new array with some elements removed and/or replaced at a given index (ES2023)
477
- */
478
- toSpliced(start: number, deleteCount?: number, ...items: T[]): T[];
479
- /**
480
- * Returns a new array with the element at the given index replaced with the given value (ES2023)
481
- */
482
- with(index: number, value: T): T[];
483
- get [Symbol.unscopables](): {
484
- readonly [x: number]: boolean;
485
- readonly length?: boolean;
486
- toString?: boolean;
487
- toLocaleString?: boolean;
488
- concat?: boolean;
489
- join?: boolean;
490
- slice?: boolean;
491
- indexOf?: boolean;
492
- lastIndexOf?: boolean;
493
- every?: boolean;
494
- some?: boolean;
495
- forEach?: boolean;
496
- map?: boolean;
497
- filter?: boolean;
498
- reduce?: boolean;
499
- reduceRight?: boolean;
500
- find?: boolean;
501
- findIndex?: boolean;
502
- entries?: boolean;
503
- keys?: boolean;
504
- values?: boolean;
505
- includes?: boolean;
506
- flatMap?: boolean;
507
- flat?: boolean;
508
- at?: boolean;
509
- findLast?: boolean;
510
- findLastIndex?: boolean;
511
- toReversed?: boolean;
512
- toSorted?: boolean;
513
- toSpliced?: boolean;
514
- with?: boolean;
515
- [Symbol.iterator]?: boolean;
516
- readonly [Symbol.unscopables]?: boolean;
517
- };
518
- }
519
-
520
- /**
521
- * Uses weak references but still may iterate through them
522
- * Note: The behavior is highly dependant on the garbage collector - some entries are perhaps deemed to be collected: don't resuscitate them
523
- */
524
- declare class IterableWeakMap<K extends WeakKey, V> implements Map<K, V> {
525
- private uuids;
526
- private refs;
527
- private readonly registry;
528
- constructor(entries?: Iterable<[K, V]>);
529
- private createIterator;
530
- clear(): void;
531
- delete(key: K): boolean;
532
- forEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void;
533
- get(key: K): V | undefined;
534
- has(key: K): boolean;
535
- set(key: K, value: V): this;
536
- get size(): number;
537
- entries(): MapIterator<[K, V]>;
538
- keys(): MapIterator<K>;
539
- values(): MapIterator<V>;
540
- [Symbol.iterator](): MapIterator<[K, V]>;
541
- readonly [Symbol.toStringTag]: string;
542
- }
543
- /**
544
- * Uses weak references but still may iterate through them
545
- * Note: The behavior is highly dependant on the garbage collector - some entries are perhaps deemed to be collected: don't resuscitate them
546
- */
547
- declare class IterableWeakSet<K extends WeakKey> implements Set<K> {
548
- private uuids;
549
- private refs;
550
- private readonly registry;
551
- constructor(entries?: Iterable<K>);
552
- private createIterator;
553
- clear(): void;
554
- add(value: K): this;
555
- delete(value: K): boolean;
556
- forEach(callbackfn: (value: K, value2: K, set: Set<K>) => void, thisArg?: any): void;
557
- has(value: K): boolean;
558
- get size(): number;
559
- entries(): SetIterator<[K, K]>;
560
- keys(): SetIterator<K>;
561
- values(): SetIterator<K>;
562
- [Symbol.iterator](): SetIterator<K>;
563
- readonly [Symbol.toStringTag]: string;
564
- union<U>(other: ReadonlySetLike<U>): Set<K | U>;
565
- intersection<U>(other: ReadonlySetLike<U>): Set<K & U>;
566
- difference<U>(other: ReadonlySetLike<U>): Set<K>;
567
- symmetricDifference<U>(other: ReadonlySetLike<U>): Set<K | U>;
568
- isSubsetOf(other: ReadonlySetLike<unknown>): boolean;
569
- isSupersetOf(other: ReadonlySetLike<unknown>): boolean;
570
- isDisjointFrom(other: ReadonlySetLike<unknown>): boolean;
571
- }
572
-
573
- /**
574
- * A mixin function that takes a base class and returns a new class with mixed-in functionality
575
- * @template Mixed - The functionality to be mixed in
576
- */
577
- type MixinFunction<Mixed> = <Base>(base: new (...args: any[]) => Base) => new (...args: any[]) => Base & Mixed;
578
- /**
579
- * A mixin class that can be used both as a base class and as a mixin function
580
- * @template Mixed - The functionality to be mixed in
581
- */
582
- type MixinClass<Mixed> = new (...args: any[]) => Mixed;
583
- /**
584
- * Creates a mixin that can be used both as a class (extends) and as a function (mixin)
585
- *
586
- * This function supports:
587
- * - Using mixins as base classes: `class MyClass extends MyMixin`
588
- * - Using mixins as functions: `class MyClass extends MyMixin(SomeBase)`
589
- * - Composing mixins: `const Composed = MixinA(MixinB)`
590
- * - Type-safe property inference for all patterns
591
- *
592
- * @param mixinFunction - The function that creates the mixin
593
- * @param unwrapFunction - Optional function to unwrap reactive objects for method calls
594
- * @returns A mixin that can be used both as a class and as a function
595
- */
596
- declare function mixin<MixinFn extends (base: any) => new (...args: any[]) => any>(mixinFunction: MixinFn, unwrapFunction?: (obj: any) => any): (new (...args: any[]) => InstanceType<ReturnType<MixinFn>>) & (<Base>(base: abstract new (...args: any[]) => Base) => new (...args: any[]) => InstanceType<ReturnType<MixinFn>> & Base);
597
-
598
- type Resolved<T> = T extends Promise<infer U> ? Resolved<U> : T extends (...args: infer Args) => infer R ? (...args: Args) => Resolved<R> : T extends object ? {
599
- [k in keyof T]: k extends 'then' | 'catch' | 'finally' ? T[k] : Resolved<T[k]>;
600
- } : T;
601
- type PromiseAnd<T> = Resolved<T> & Promise<Resolved<T>>;
602
- /**
603
- * Type that transforms promises into chainable objects
604
- * Allows calling methods directly on promise results without awaiting them first
605
- */
606
- type PromiseChain<T> = T extends (...args: infer Args) => infer R ? PromiseAnd<(...args: Args) => PromiseChain<Resolved<R>>> : T extends object ? PromiseAnd<{
607
- [k in keyof T]: k extends 'then' | 'catch' | 'finally' ? T[k] : PromiseChain<Resolved<T[k]>>;
608
- }> : Promise<Resolved<T>>;
609
- /**
610
- * Transforms a promise or value into a chainable object
611
- * Allows calling methods directly on promise results without awaiting them first
612
- * @param given - The promise or value to make chainable
613
- * @returns A chainable version of the input
614
- */
615
- declare function chainPromise<T>(given: Promise<T> | T): PromiseChain<T>;
616
-
617
- /**
618
- * Reactively attends to each entry of a collection or each key yielded by an
619
- * enumeration callback. For each key, an inner effect runs the callback. When a
620
- * key disappears, its inner effect is disposed. The callback may return a cleanup
621
- * (like a regular effect closer).
622
- *
623
- * Accepts arrays, records, Maps, Sets, or a raw `() => Iterable<Key>` callback.
624
- *
625
- * @example
626
- * ```typescript
627
- * // Record shorthand
628
- * attend(record, (key) => { console.log(key, record[key]) })
629
- *
630
- * // Array shorthand
631
- * attend(array, (index) => { console.log(index, array[index]) })
632
- *
633
- * // Raw enumeration callback
634
- * attend(() => Object.keys(record), (key) => { ... })
635
- * ```
636
- */
637
- declare function attend<T>(source: readonly T[], callback: (index: number, access: EffectAccess) => EffectCloser | void): ScopedCallback;
638
- declare function attend<K, V>(source: Map<K, V>, callback: (key: K, access: EffectAccess) => EffectCloser | void): ScopedCallback;
639
- declare function attend<T>(source: Set<T>, callback: (value: T, access: EffectAccess) => EffectCloser | void): ScopedCallback;
640
- declare function attend<S extends object>(source: S, callback: (key: keyof S & string, access: EffectAccess) => EffectCloser | void): ScopedCallback;
641
- declare function attend<Key>(enumerate: () => Iterable<Key>, callback: (key: Key, access: EffectAccess) => EffectCloser | void): ScopedCallback;
642
- /**
643
- * Lifts a callback that returns an array into a reactive array that automatically
644
- * synchronizes with the source array returned by the callback.
645
- *
646
- * The returned reactive array will update whenever the callback's dependencies change,
647
- * efficiently syncing only the elements that differ from the previous result.
648
- *
649
- * @example
650
- * ```typescript
651
- * const items = reactive([1, 2, 3])
652
- * const doubled = lift(() => items.map(x => x * 2))
653
- *
654
- * console.log([...doubled]) // [2, 4, 6]
655
- *
656
- * items.push(4)
657
- * console.log([...doubled]) // [2, 4, 6, 8]
658
- * ```
659
- *
660
- * @param cb Callback function that returns an array
661
- * @returns A reactive array synchronized with the callback's result, with a [cleanup] property to stop tracking
662
- */
663
- declare function lift<Output extends any[]>(cb: (access: EffectAccess) => Output): Output;
664
- /**
665
- * Lifts a callback that returns an object into a reactive object that automatically
666
- * synchronizes with the source object returned by the callback.
667
- *
668
- * The returned reactive object will update whenever the callback's dependencies change,
669
- * efficiently syncing only the properties that differ from the previous result using
670
- * Object.assign(). Properties that no longer exist in the source are automatically removed.
671
- *
672
- * @example
673
- * ```typescript
674
- * const user = reactive({ name: 'John', age: 30 })
675
- * const profile = lift(() => ({
676
- * displayName: user.name.toUpperCase(),
677
- * isAdult: user.age >= 18,
678
- * description: `${user.name} is ${user.age} years old`
679
- * }))
680
- *
681
- * console.log(profile.displayName) // JOHN
682
- * console.log(profile.isAdult) // true
683
- *
684
- * user.name = 'Jane'
685
- * console.log(profile.displayName) // JANE
686
- * console.log(profile.description) // Jane is 30 years old
687
- * ```
688
- *
689
- * @param cb Callback function that returns an object
690
- * @returns A reactive object synchronized with the callback's result, with a [cleanup] property to stop tracking
691
- */
692
- declare function lift<Output extends object>(cb: (access: EffectAccess) => Output): Output;
693
- /**
694
- * Options for `morph` and its variants.
695
- *
696
- * @property pure - When `true`, the mapping function is assumed pure (no reactive reads inside `fn`).
697
- * Per-item effects are skipped and items are computed eagerly. When a predicate `(i) => boolean`,
698
- * purity is evaluated per item — pure items skip the effect wrapper, non-pure items get their own.
699
- */
700
- type MorphOptions<I> = {
701
- pure?: boolean | ((i: I) => boolean);
702
- };
703
- /**
704
- * Unified reactive collection mapper. Dispatches to `morphArray`, `morphMap`, or `morphRecord`
705
- * based on the source type. Access `morph.pure(source, fn)` for the `{ pure: true }` shorthand.
706
- *
707
- * @see morphArray
708
- * @see morphMap
709
- * @see morphRecord
710
- */
711
- type Morph = {
712
- <I, O>(source: readonly I[] | (() => readonly I[]), fn: (arg: I, access?: EffectAccess) => O, options?: MorphOptions<I>): readonly O[];
713
- <K, V, O>(source: Map<K, V>, fn: (arg: V, key: K, access?: EffectAccess) => O, options?: MorphOptions<V>): Map<K, O>;
714
- <S extends Record<PropertyKey, any>, O>(source: S, fn: (arg: S[keyof S], key: keyof S, access?: EffectAccess) => O, options?: MorphOptions<S[keyof S]>): {
715
- [K in keyof S]: O;
716
- };
717
- pure: Morph;
718
- };
719
- /**
720
- * Reactively maps a collection (array, Map, or record) through a per-entry function.
721
- *
722
- * Each entry in the source gets its own reactive context — when only one entry's dependencies
723
- * change, only that entry's projection recomputes. Structural changes (additions, removals,
724
- * reorders) are detected via diffing and applied surgically.
725
- *
726
- * Use `morph.pure(source, fn)` when `fn` has no reactive reads (skips per-item effects).
727
- *
728
- * @example
729
- * ```ts
730
- * const users = reactive([{ name: 'John' }, { name: 'Jane' }])
731
- * const names = morph(users, u => u.name.toUpperCase())
732
- * // names[0] = 'JOHN', names[1] = 'JANE'
733
- * // Changing users[0].name only recomputes names[0]
734
- * ```
735
- */
736
- declare const morph: Morph;
737
-
738
- /**
739
- * Gets the current state of a reactive object for evolution tracking
740
- * @param obj - The reactive object
741
- * @returns The current state object
742
- */
743
- declare function getState(obj: any): State;
744
- /**
745
- * Triggers effects for a single property change
746
- * @param obj - The object that changed
747
- * @param evolution - The type of change
748
- * @param prop - The property that changed
749
- */
750
- declare function touched1(obj: any, evolution: Evolution, prop: any): void;
751
- /**
752
- * Triggers effects for property changes
753
- * @param obj - The object that changed
754
- * @param evolution - The type of change
755
- * @param props - The properties that changed
756
- */
757
- declare function touched(obj: any, evolution: Evolution, props?: Iterable<any>): void;
758
-
759
- /**
760
- * Deep watch an object and all its nested properties
761
- * @param target - The object to watch deeply
762
- * @param callback - The callback to call when any nested property changes
763
- * @param options - Options for the deep watch
764
- * @returns A cleanup function to stop watching
765
- */
766
- /**
767
- * Sets up deep watching for an object, tracking all nested property changes
768
- * @param target - The object to watch
769
- * @param callback - The callback to call when changes occur
770
- * @param options - Options for deep watching
771
- * @returns A cleanup function to stop deep watching
772
- */
773
- declare function deepWatch<T extends object>(target: T, callback: (value: T) => void, { immediate }?: {
774
- immediate?: boolean;
775
- }): EffectCleanup | undefined;
776
-
777
- /**
778
- * Aggregator for zones that need to be tracked along effects.
779
- * ie. in each effect, the active zone of the given zoning will be the one active at effect's definition
780
- */
781
- declare const effectAggregator: ZoneAggregator;
782
- declare function getActiveEffect(): ScopedCallback;
783
- /**
784
- * Attach cleanup dependencies to an object. When `unlink(obj)` is called,
785
- * each dependency is disposed: functions are invoked with the cleanup reason,
786
- * objects are recursively `unlink`ed. This forms a cleanup tree.
787
- *
788
- * @param obj - The owner object
789
- * @param cleanupFns - Cleanup callbacks and/or child objects to unlink recursively
790
- * @returns The owner object (for chaining)
791
- *
792
- * @example
793
- * ```ts
794
- * // Functions are called with CleanupReason
795
- * link(parent, () => console.log('disposed'))
796
- *
797
- * // Objects are recursively unlinked
798
- * link(parent, childA, childB)
799
- *
800
- * // Mixed
801
- * link(parent, childObj, () => timer.clear())
802
- *
803
- * unlink(parent) // disposes childA, childB, calls the function
804
- * ```
805
- */
806
- declare function link<T extends object>(obj: T, ...cleanupFns: (ScopedCallback | object | undefined)[]): T;
807
- /**
808
- * Dispose an object's cleanup dependencies. Functions are called with the
809
- * reason; linked objects are recursively unlinked. The cleanup set is removed
810
- * so calling `unlink` twice is safe (second call is a no-op).
811
- *
812
- * @param obj - The object to dispose
813
- * @param reason - Optional cleanup reason propagated to callbacks
814
- */
815
- declare function unlink(obj: object, reason?: CleanupReason): void;
816
-
817
- interface ActivationRecord {
818
- effect: EffectTrigger;
819
- obj: any;
820
- evolution: Evolution;
821
- prop: any;
822
- batchId: number;
823
- }
824
- /**
825
- * Returns the activation log containing recent effect activations for debugging.
826
- * The log is a circular buffer of the last 100 activations.
827
- *
828
- * @returns Array of activation records
829
- */
830
- declare function getActivationLog(): Omit<ActivationRecord, "batchId">[];
831
- declare function caught(onThrow: CatchFunction, effect?: EffectTrigger): void;
832
- /** @deprecated Use `caught` instead */
833
- declare const onEffectThrow: typeof caught;
834
- /**
835
- * Adds a cleanup function to be called when the current batch of effects completes
836
- * @param cleanup - The cleanup function to add
837
- */
838
- declare function addBatchCleanup(cleanup: EffectCleanup): void;
839
- /**
840
- * Semantic alias for `addBatchCleanup` - defers work to the end of the current reactive batch.
841
- *
842
- * Use this when an effect needs to perform an action that would modify state the effect depends on,
843
- * which would create a reactive cycle. The deferred callback runs after all effects complete.
844
- *
845
- * @param callback - The callback to defer until after the current batch completes
846
- *
847
- * @example
848
- * ```typescript
849
- * effect(() => {
850
- * processData()
851
- *
852
- * // Defer to avoid cycle (createMovement modifies state this effect reads)
853
- * defer(() => {
854
- * createMovement(data)
855
- * })
856
- * })
857
- * ```
858
- */
859
- declare const defer: typeof addBatchCleanup;
860
- /**
861
- * Resets the reactive system to a consistent state.
862
- * Call this after an unrecoverable error has set the system to "broken".
863
- * This clears all batch state, effect dependency graphs, and watcher registrations.
864
- * All existing effects become orphaned and must be recreated.
865
- */
866
- declare function reset(): void;
867
-
868
- /**
869
- * Decorator that makes methods atomic - batches all effects triggered within the method
870
- */
871
- declare const atomic: LegacyPropertyDecorator<any> & ModernMethodDecorator<any> & (<Args extends any[], Return>(original: (...args: Args) => Return) => (...args: Args) => Return);
872
- /**
873
- * Wraps `fn` so it runs within `effect`'s zone context when invoked later.
874
- *
875
- * Useful for deferred callbacks (event listeners, `DOMContentLoaded`, etc.)
876
- * that need sub-effects parented to the original effect.
877
- *
878
- * @param prev - The effect whose context should be restored, or `undefined` for root context
879
- * @param fn - The function to wrap
880
- * @returns A function with the same signature that restores the effect context before calling `fn`
881
- */
882
- declare function captured<Args extends any[], Return>(prev: HistoryValue<EffectTrigger> | undefined, fn: (...args: Args) => Return): (...args: Args) => Return;
883
- /**
884
- * Runs `fn` atomically and **always immediately**, batching all reactive effects
885
- * triggered inside it so they fire only once after `fn` completes.
886
- *
887
- * Unlike `atomic(fn)` which **wraps** a function for later invocation,
888
- * `atom(fn)` **executes** the function right away.
889
- *
890
- * @example
891
- * ```ts
892
- * const state = reactive({ a: 0, b: 0 })
893
- * effect(() => console.log(state.a, state.b)) // logs once after atom completes
894
- *
895
- * atom(() => {
896
- * state.a = 1
897
- * state.b = 2
898
- * })
899
- * ```
900
- */
901
- declare function atom<T>(fn: () => T): any;
902
- /**
903
- * @param fn - The effect function to run - provides the cleaner
904
- * @returns The cleanup function
905
- */
906
- /**
907
- * Reactive effect function with chainable flavor modifiers.
908
- */
909
- interface Effect {
910
- (fn: (access: EffectAccess) => EffectCloser | undefined | void | Promise<any>, effectOptions?: EffectOptions): EffectCleanup;
911
- /** Opaque flavor: bypasses deep-touch optimizations */
912
- readonly opaque: Effect;
913
- /** Named flavor: assigns a debug name */
914
- named(name: string): Effect;
915
- }
916
- /**
917
- * Creates a reactive effect that automatically re-runs when dependencies change
918
- * @param fn - The effect function that provides dependencies and may return a cleanup function or Promise
919
- * @param options - Options for effect execution
920
- * @returns A cleanup function to stop the effect
921
- */
922
- declare const effect: Effect;
923
- /**
924
- * Executes a function without tracking dependencies but maintains parent cleanup relationship
925
- * Effects created inside will still be cleaned up when the parent effect is destroyed
926
- * @param fn - The function to execute
927
- */
928
- declare function untracked<T>(fn: () => T): T;
929
- /**
930
- * Executes a function from a virgin/root context - no parent effect, no tracking
931
- * Creates completely independent effects that won't be cleaned up by any parent
932
- * @param fn - The function to execute
933
- */
934
- declare function root<T>(fn: () => T): T;
935
- /**
936
- * Creates a bidirectional binding between a reactive value and a non-reactive external value
937
- * Prevents infinite loops by automatically suppressing circular notifications
938
- *
939
- * @param received - Function called when the reactive value changes (external setter)
940
- * @param get - Getter for the reactive value OR an object with `{ get, set }` properties
941
- * @param set - Setter for the reactive value (required if `get` is a function)
942
- * @returns A function to manually provide updates from the external side
943
- *
944
- * @example
945
- * ```typescript
946
- * const model = reactive({ value: '' })
947
- * const input = { value: '' }
948
- *
949
- * // Bidirectional binding
950
- * const provide = biDi(
951
- * (v) => input.value = v, // external setter
952
- * () => model.value, // reactive getter
953
- * (v) => model.value = v // reactive setter
954
- * )
955
- *
956
- * // External notification (e.g., from input event)
957
- * provide('new value') // Updates model.value, doesn't trigger circular loop
958
- * ```
959
- *
960
- * @example Using object syntax
961
- * ```typescript
962
- * const provide = biDi(
963
- * (v) => setHTMLValue(v),
964
- * { get: () => reactiveObj.value, set: (v) => reactiveObj.value = v }
965
- * )
966
- * ```
967
- */
968
- declare function biDi<T>(received: (value: T) => void, value: {
969
- get: () => T;
970
- set: (value: T) => void;
971
- }): (value: T) => void;
972
- declare function biDi<T>(received: (value: T) => void, get: () => T, set: (value: T) => void): (value: T) => void;
973
-
974
- type MemoizableArgument = object | any[] | ((...args: any[]) => any);
975
- type Memoizable = ((...args: MemoizableArgument[]) => unknown) | Record<string, any>;
976
- /**
977
- * Decorator and function wrapper for memoizing computed values based on reactive dependencies.
978
- *
979
- * When used as a decorator on getters or methods, it caches the result and automatically
980
- * invalidates the cache when reactive dependencies change.
981
- *
982
- * When used as a function wrapper, it memoizes based on object arguments (WeakMap-based cache).
983
- *
984
- * @example
985
- * ```typescript
986
- * class User {
987
- * @memoize
988
- * get fullName() {
989
- * return `${this.firstName} ${this.lastName}`
990
- * }
991
- * }
992
- *
993
- * // Or as a function wrapper
994
- * const expensive = memoize((obj: SomeObject) => {
995
- * return heavyComputation(obj)
996
- * })
997
- * ```
998
- */
999
- declare function makeMemoizeDecorator(memoizeOpts?: {
1000
- lenient?: boolean;
1001
- }): LegacyPropertyDecorator<any> & ModernMethodDecorator<any> & ModernGetterDecorator<any> & ModernAccessorDecorator<any> & (<T extends Memoizable>(target: T) => T);
1002
- declare const memoize: ReturnType<typeof makeMemoizeDecorator> & {
1003
- readonly lenient: ReturnType<typeof makeMemoizeDecorator>;
1004
- };
1005
-
1006
- /**
1007
- * Add unreactive properties to a prototype.
1008
- * If no set is provided, marks the entire object/prototype as non-reactive (sets [unreactiveProperties] = true).
1009
- * If a set is provided, merges with existing unreactive properties (never overrides true).
1010
- */
1011
- declare function addUnreactiveProps<T extends object>(proto: T, set?: Iterable<PropertyKey>): T;
1012
- declare function isNonReactive(obj: any): boolean;
1013
-
1014
- type SubProxy = {
1015
- get?(obj: any, prop: PropertyKey, receiver: any): any;
1016
- has?(obj: any, prop: PropertyKey): boolean;
1017
- ownKeys?(obj: any): ArrayLike<string | symbol>;
1018
- getOwnPropertyDescriptor?(obj: any, prop: PropertyKey): PropertyDescriptor | undefined;
1019
- };
1020
- /**
1021
- * Base mixin for reactive classes that provides proper constructor reactivity
1022
- * Solves constructor reactivity issues in complex inheritance trees
1023
- */
1024
- declare const ReactiveBase: (new (...args: any[]) => {
1025
- [x: string]: any;
1026
- }) & (<Base>(base: abstract new (...args: any[]) => Base) => new (...args: any[]) => {
1027
- [x: string]: any;
1028
- } & Base);
1029
- declare function reactiveObject<T>(anyTarget: T, subProxy?: SubProxy): T;
1030
- /**
1031
- * Main decorator for making classes reactive
1032
- * Automatically makes class instances reactive when created
1033
- */
1034
- declare const reactive: LegacyClassDecorator<new (...args: any[]) => any> & ModernClassDecorator<new (...args: any[]) => any> & typeof reactiveObject;
1035
-
1036
- /**
1037
- * Provides type-safe access to a source object's property within the organized callback.
1038
- * @template Source - The type of the source object
1039
- * @template Key - The type of the property key in the source object
1040
- */
1041
- type OrganizedAccess<Source extends Record<PropertyKey, any>, Key extends keyof Source> = {
1042
- /** The property key being accessed */
1043
- readonly key: Key;
1044
- /**
1045
- * Gets the current value of the property from the source object
1046
- * @returns The current value of the property
1047
- */
1048
- get(): Source[Key];
1049
- /**
1050
- * Updates the property value in the source object
1051
- * @param value - The new value to set
1052
- * @returns {boolean} True if the update was successful
1053
- */
1054
- set(value: Source[Key]): boolean;
1055
- /**
1056
- * The current value of the property (equivalent to using get()/set() directly)
1057
- */
1058
- value: Source[Key];
1059
- };
1060
- /**
1061
- * Callback function type for the organized function that processes each source property.
1062
- * @template Source - The type of the source object
1063
- * @template Target - The type of the target object
1064
- */
1065
- type OrganizedCallback<Source extends Record<PropertyKey, any>, Target extends object> = <Key extends keyof Source>(
1066
- /**
1067
- * Accessor object for the current source property
1068
- */
1069
- access: OrganizedAccess<Source, Key>,
1070
- /**
1071
- * The target object where organized data will be stored
1072
- */
1073
- target: Target) => EffectCloser | undefined;
1074
- /**
1075
- * The result type of the organized function, combining the target object with cleanup capability.
1076
- * @template Target - The type of the target object
1077
- */
1078
- type OrganizedResult<Target extends object> = Target;
1079
- /**
1080
- * Organizes a source object's properties into a target object using a callback function.
1081
- * This creates a reactive mapping between source properties and a target object,
1082
- * automatically handling property additions, updates, and removals.
1083
- *
1084
- * @template Source - The type of the source object
1085
- * @template Target - The type of the target object (defaults to Record<PropertyKey, any>)
1086
- *
1087
- * @param {Source} source - The source object to organize
1088
- * @param {OrganizedCallback<Source, Target>} apply - Callback function that defines how each source property is mapped to the target
1089
- * @param {Target} [baseTarget={}] - Optional base target object to use (will be made reactive if not already)
1090
- *
1091
- * @returns {OrganizedResult<Target>} The target object with cleanup capability
1092
- *
1093
- * @example
1094
- * // Organize user permissions into role-based access
1095
- * const user = reactive({ isAdmin: true, canEdit: false });
1096
- * const permissions = organized(
1097
- * user,
1098
- * (access, target) => {
1099
- * if (access.key === 'isAdmin') {
1100
- * target.hasFullAccess = access.value;
1101
- * }
1102
- * target[`can${access.key.charAt(0).toUpperCase() + access.key.slice(1)}`] = access.value;
1103
- * }
1104
- * );
1105
- *
1106
- * @example
1107
- * // Transform object structure with cleanup
1108
- * const source = reactive({ firstName: 'John', lastName: 'Doe' });
1109
- * const formatted = organized(
1110
- * source,
1111
- * (access, target) => {
1112
- * if (access.key === 'firstName' || access.key === 'lastName') {
1113
- * target.fullName = `${source.firstName} ${source.lastName}`.trim();
1114
- * }
1115
- * }
1116
- * );
1117
- *
1118
- * @example
1119
- * // Using with cleanup in a component
1120
- * effect(() => {
1121
- * const data = fetchData();
1122
- * const organizedData = organized(data, (access, target) => {
1123
- * // Transform data
1124
- * });
1125
- *
1126
- * // The cleanup will be called automatically when the effect is disposed
1127
- * return () => organizedData[cleanup]();
1128
- * });
1129
- */
1130
- declare function organized<Source extends Record<PropertyKey, any>, Target extends object = Record<PropertyKey, any>>(source: Source, apply: OrganizedCallback<Source, Target>, baseTarget?: Target): OrganizedResult<Target>;
1131
- /**
1132
- * Organizes a property on a target object
1133
- * Shortcut for defineProperty/delete with touched signal
1134
- * @param target - The target object
1135
- * @param property - The property to organize
1136
- * @param access - The access object
1137
- * @returns The property descriptor
1138
- */
1139
- declare function organize<T>(target: object, property: PropertyKey, access: {
1140
- get?(): T;
1141
- set?(value: T): boolean;
1142
- }): () => boolean;
1143
-
1144
- /**
1145
- * Options for the watch function
1146
- */
1147
- interface WatchOptions {
1148
- /** Whether to call the callback immediately */
1149
- immediate?: boolean;
1150
- /** Whether to watch nested properties */
1151
- deep?: boolean;
1152
- }
1153
- /**
1154
- * Watches a reactive value and calls a callback when it changes
1155
- */
1156
- interface Watch {
1157
- <T>(value: (dep: EffectAccess) => T, changed: (value: T, oldValue?: T) => void, options?: Omit<WatchOptions, 'deep'> & {
1158
- deep?: false;
1159
- }): EffectCleanup;
1160
- /**
1161
- * Watches a reactive value with deep watching enabled
1162
- */
1163
- <T extends object | any[]>(value: (dep: EffectAccess) => T, changed: (value: T, oldValue?: T) => void, options?: Omit<WatchOptions, 'deep'> & {
1164
- deep: true;
1165
- }): EffectCleanup;
1166
- /**
1167
- * Watches a reactive object directly
1168
- */
1169
- <T extends object | any[]>(value: T, changed: (value: T) => void, options?: WatchOptions): EffectCleanup;
1170
- /** Deep watch flavor */
1171
- get deep(): Watch;
1172
- /** Immediate watch flavor */
1173
- get immediate(): Watch;
1174
- }
1175
- declare const watch: Watch;
1176
- /**
1177
- * Returns a promise that resolves when the predicate returns a truthy value.
1178
- * The predicate is evaluated reactively — it re-runs whenever its dependencies change.
1179
- * @param predicate - Reactive function that returns a value; resolves when truthy
1180
- * @param timeout - Optional timeout in milliseconds — rejects if condition is not met within this duration
1181
- * @returns Promise that resolves with the first truthy return value
1182
- */
1183
- declare function when<T>(predicate: (dep: EffectAccess) => T, timeout?: number): Promise<T>;
1184
- declare function unreactiveApplication<T extends object>(...args: (keyof T)[]): GenericClassDecorator<T>;
1185
- declare function unreactiveApplication<T extends object>(obj: T): T;
1186
- /**
1187
- * Decorator that marks classes or properties as non-reactive
1188
- * Prevents objects from being made reactive
1189
- */
1190
- declare const unreactive: LegacyClassDecorator<new (...args: any[]) => any> & ModernClassDecorator<new (...args: any[]) => any> & typeof unreactiveApplication;
1191
- interface Resource<T> {
1192
- value: T | undefined;
1193
- loading: boolean;
1194
- error: any;
1195
- latest: T | undefined;
1196
- reload(): void;
1197
- promise: Promise<void>;
1198
- }
1199
- /**
1200
- * Creates a reactive resource that automatically tracks async state.
1201
- * @param fetcher - Async function that returns the value. Reactive dependencies are tracked.
1202
- * @param options - Resource options (initialValue)
1203
- * @returns Reactive Resource object with value, loading, error, latest properties
1204
- */
1205
- declare function resource<T>(fetcher: (access: EffectAccess) => Promise<T> | T, options?: {
1206
- initialValue?: T;
1207
- }): Resource<T>;
1208
-
1209
- /**
1210
- * Executes a function and throws if any reactive dependencies are tracked during execution.
1211
- * Used to assert that code runs in an untracked context.
1212
- */
1213
- declare function assertUntracked<T>(fn: () => T): T;
1214
-
1215
- /**
1216
- * Object containing internal reactive system state for debugging and profiling
1217
- */
1218
- declare const profileInfo: any;
1219
-
1220
- /**
1221
- * Decorator that caches the result of a getter method and only recomputes when dependencies change
1222
- * Prevents circular dependencies and provides automatic cache invalidation
1223
- */
1224
- declare const cached: LegacyPropertyDecorator<any> & ModernGetterDecorator<any> & ModernAccessorDecorator<any>;
1225
- /**
1226
- * Checks if a property is cached (has a cached value)
1227
- * @param object - The object to check
1228
- * @param propertyKey - The property key to check
1229
- * @returns True if the property has a cached value
1230
- */
1231
- declare function isCached(object: Object, propertyKey: PropertyKey): boolean;
1232
- /**
1233
- * Caches a value for a property on an object
1234
- * @param object - The object to cache the value on
1235
- * @param propertyKey - The property key to cache
1236
- * @param value - The value to cache
1237
- */
1238
- declare function cache(object: Object, propertyKey: PropertyKey, value: any): void;
1239
- /**
1240
- * Creates a decorator that modifies property descriptors for specified properties
1241
- * @param descriptor - The descriptor properties to apply
1242
- * @returns A class decorator that applies the descriptor to specified properties
1243
- */
1244
- declare const descriptor: any;
1245
- /**
1246
- * Decorator that marks methods, properties, or classes as deprecated
1247
- * Provides warning messages when deprecated items are used
1248
- */
1249
- declare const deprecated: LegacyPropertyDecorator<any> & ModernMethodDecorator<any> & LegacyClassDecorator<new (...args: any[]) => any> & ModernClassDecorator<new (...args: any[]) => any> & ModernGetterDecorator<any> & ModernAccessorDecorator<any> & ModernSetterDecorator<any> & ((message: string) => LegacyPropertyDecorator<any> & ModernMethodDecorator<any> & LegacyClassDecorator<new (...args: any[]) => any> & ModernClassDecorator<new (...args: any[]) => any> & ModernGetterDecorator<any> & ModernAccessorDecorator<any> & ModernSetterDecorator<any>) & {
1250
- warn: (target: any, propertyKey: PropertyKey, message?: string) => void;
1251
- };
1252
- /**
1253
- * Creates a debounced method decorator that delays execution until after the delay period has passed
1254
- * @param delay - The delay in milliseconds
1255
- * @returns A method decorator that debounces method calls
1256
- */
1257
- declare function debounce(delay: number): LegacyPropertyDecorator<any> & ModernMethodDecorator<any>;
1258
- /**
1259
- * Creates a throttled method decorator that limits execution to once per delay period
1260
- * @param delay - The delay in milliseconds
1261
- * @returns A method decorator that throttles method calls
1262
- */
1263
- declare function throttle(delay: number): LegacyPropertyDecorator<any> & ModernMethodDecorator<any>;
1264
-
1265
- type ElementTypes<T extends readonly unknown[]> = {
1266
- [K in keyof T]: T[K] extends readonly (infer U)[] ? U : T[K];
1267
- };
1268
- /**
1269
- * Yields tuples containing elements from each input array, stopping at the longest array length
1270
- * @param args - Arrays to zip together
1271
- * @returns Generator yielding tuples containing elements from each input array
1272
- */
1273
- declare function zip<T extends (readonly unknown[])[]>(...args: T): Generator<ElementTypes<T>>;
1274
- /**
1275
- * Checks if two arrays are strictly equal (shallow comparison)
1276
- * @param a - First value
1277
- * @param b - Second value
1278
- * @returns True if arrays are equal or values are strictly equal
1279
- */
1280
- declare function arrayEquals(a: any, b: any): boolean;
1281
- /**
1282
- * Checks if a function is a constructor (class or constructor function)
1283
- * @param fn - The function to check
1284
- * @returns True if the function is a constructor
1285
- */
1286
- declare function isConstructor(fn: Function): boolean;
1287
- /**
1288
- * Checks if a value is an object
1289
- * @param value - The value to check
1290
- * @returns True if the value is an object
1291
- */
1292
- declare function isObject(value: any): value is object;
1293
- /**
1294
- * Deeply compares two values.
1295
- * For objects, compares prototypes with === and then own properties recursively.
1296
- * Uses a cache to handle circular references.
1297
- * @param a - First value
1298
- * @param b - Second value
1299
- * @param cache - Map for circular reference protection (internal use)
1300
- * @returns True if values are deeply equal
1301
- */
1302
- declare function deepCompare(a: any, b: any, cache?: Map<object, Set<object>>): boolean;
1303
- /**
1304
- * Tags an object with a name
1305
- * @param name - The name to tag the object with
1306
- * @param obj - The object to tag
1307
- * @returns The object with the tag
1308
- */
1309
- declare function tag<T extends object>(name: string, obj: T): T;
1310
- /**
1311
- * Renames a function with a new name
1312
- * @param name - The new name for the function
1313
- * @param fn - The function to rename
1314
- * @returns The function with the new name
1315
- */
1316
- declare function named<T extends Function>(name: string, fn: T): T;
1317
- declare const isDev: boolean;
1318
- declare const isProd: boolean;
1319
- declare const isTest: boolean;
1320
-
1321
- export { ArrayReadForward, CleanupReason, DecoratorError, Destroyable, DestructionError, EffectAccess, EffectCleanup, EffectCloser, EffectOptions, EffectTrigger, Eventful, Evolution, HistoryValue, Indexable, IterableWeakMap, IterableWeakSet, ReactiveBase, ScopedCallback, ZoneAggregator, addBatchCleanup, addUnreactiveProps, allocated, allocatedValues, arrayDiff, arrayEquals, assertUntracked, asyncHook, asyncHooks, atom, atomic, attend, biDi, cache, cached, callOnGC, captured, caught, chainPromise, createFlavor, debounce, decorator, deepCompare, deepWatch, defer, deprecated, descriptor, destructor, effect, effectAggregator, flavorOptions, flavored, forwardArray, getActivationLog, getActiveEffect, getAt, getState, hooks$1 as hooks, isCached, isConstructor, isDev, isNonReactive, isObject, isProd, isTest, legacyDecorator, lift, link, memoize, mixin, modernDecorator, morph, named, onEffectThrow, organize, organized, profileInfo, morph as project, reactive, reset, resource, root, setAt, tag, throttle, touched, touched1, unlink, unreactive, untracked, watch, when, zip };
1322
- export type { ArrayDiffResult, ContextManager, Decorator, DecoratorDescription, DecoratorFactory, EventsBase, GenericClassDecorator, Hook, LegacyClassDecorator, LegacyPropertyDecorator, Memoizable, MemoizableArgument, MixinClass, MixinFunction, ModernAccessorDecorator, ModernClassDecorator, ModernGetterDecorator, ModernMethodDecorator, ModernSetterDecorator, PromiseChain, Resource, Restorer };