mutts 1.0.4 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/README.md +2 -1
  2. package/dist/chunks/{_tslib-Mzh1rNsX.esm.js → _tslib-MCKDzsSq.esm.js} +2 -2
  3. package/dist/chunks/_tslib-MCKDzsSq.esm.js.map +1 -0
  4. package/dist/chunks/decorator-BGILvPtN.esm.js +627 -0
  5. package/dist/chunks/decorator-BGILvPtN.esm.js.map +1 -0
  6. package/dist/chunks/decorator-BQ2eBTCj.js +651 -0
  7. package/dist/chunks/decorator-BQ2eBTCj.js.map +1 -0
  8. package/dist/chunks/{index-GRBSx0mB.js → index-CDCOjzTy.js} +543 -495
  9. package/dist/chunks/index-CDCOjzTy.js.map +1 -0
  10. package/dist/chunks/{index-79Kk8D6e.esm.js → index-DiP0RXoZ.esm.js} +452 -404
  11. package/dist/chunks/index-DiP0RXoZ.esm.js.map +1 -0
  12. package/dist/decorator.d.ts +3 -3
  13. package/dist/decorator.esm.js +1 -1
  14. package/dist/decorator.js +1 -1
  15. package/dist/destroyable.esm.js +4 -4
  16. package/dist/destroyable.esm.js.map +1 -1
  17. package/dist/destroyable.js +4 -4
  18. package/dist/destroyable.js.map +1 -1
  19. package/dist/devtools/panel.js.map +1 -1
  20. package/dist/eventful.esm.js +1 -1
  21. package/dist/index.esm.js +48 -3
  22. package/dist/index.esm.js.map +1 -1
  23. package/dist/index.js +50 -4
  24. package/dist/index.js.map +1 -1
  25. package/dist/mutts.umd.js +1 -1
  26. package/dist/mutts.umd.js.map +1 -1
  27. package/dist/mutts.umd.min.js +1 -1
  28. package/dist/mutts.umd.min.js.map +1 -1
  29. package/dist/reactive.d.ts +54 -1
  30. package/dist/reactive.esm.js +3 -3
  31. package/dist/reactive.js +6 -4
  32. package/dist/reactive.js.map +1 -1
  33. package/dist/std-decorators.d.ts +1 -1
  34. package/dist/std-decorators.esm.js +10 -10
  35. package/dist/std-decorators.esm.js.map +1 -1
  36. package/dist/std-decorators.js +10 -10
  37. package/dist/std-decorators.js.map +1 -1
  38. package/docs/ai/manual.md +14 -95
  39. package/docs/reactive/advanced.md +6 -107
  40. package/docs/reactive/core.md +16 -16
  41. package/docs/reactive/debugging.md +158 -0
  42. package/docs/reactive.md +8 -0
  43. package/package.json +16 -66
  44. package/src/decorator.ts +11 -9
  45. package/src/destroyable.ts +5 -5
  46. package/src/index.ts +46 -0
  47. package/src/reactive/array.ts +3 -5
  48. package/src/reactive/change.ts +7 -3
  49. package/src/reactive/debug.ts +1 -1
  50. package/src/reactive/deep-touch.ts +1 -1
  51. package/src/reactive/deep-watch.ts +1 -1
  52. package/src/reactive/effect-context.ts +2 -2
  53. package/src/reactive/effects.ts +114 -17
  54. package/src/reactive/index.ts +3 -2
  55. package/src/reactive/interface.ts +10 -9
  56. package/src/reactive/map.ts +6 -6
  57. package/src/reactive/mapped.ts +2 -3
  58. package/src/reactive/memoize.ts +77 -31
  59. package/src/reactive/project.ts +103 -6
  60. package/src/reactive/proxy.ts +4 -4
  61. package/src/reactive/registry.ts +67 -0
  62. package/src/reactive/set.ts +6 -6
  63. package/src/reactive/tracking.ts +12 -41
  64. package/src/reactive/types.ts +59 -0
  65. package/src/reactive/zone.ts +1 -1
  66. package/src/std-decorators.ts +10 -10
  67. package/src/utils.ts +141 -0
  68. package/dist/chunks/_tslib-Mzh1rNsX.esm.js.map +0 -1
  69. package/dist/chunks/decorator-DLvrD0UF.js +0 -265
  70. package/dist/chunks/decorator-DLvrD0UF.js.map +0 -1
  71. package/dist/chunks/decorator-DqiszP7i.esm.js +0 -253
  72. package/dist/chunks/decorator-DqiszP7i.esm.js.map +0 -1
  73. package/dist/chunks/index-79Kk8D6e.esm.js.map +0 -1
  74. package/dist/chunks/index-GRBSx0mB.js.map +0 -1
  75. /package/{src/reactive/project.project.md → docs/reactive/project.md} +0 -0
@@ -0,0 +1,651 @@
1
+ 'use strict';
2
+
3
+ // biome-ignore-all lint/suspicious/noConfusingVoidType: Type 'void' is not assignable to type 'ScopedCallback | undefined'.
4
+ // Argument of type '() => void' is not assignable to parameter of type '(dep: DependencyFunction) => ScopedCallback | undefined'.
5
+ // Track native reactivity
6
+ const nativeReactive = Symbol('native-reactive');
7
+ /**
8
+ * Symbol to mark individual objects as non-reactive
9
+ */
10
+ const nonReactiveMark = Symbol('non-reactive');
11
+ /**
12
+ * Symbol to mark class properties as non-reactive
13
+ */
14
+ const unreactiveProperties = Symbol('unreactive-properties');
15
+ /**
16
+ * Symbol for prototype forwarding in reactive objects
17
+ */
18
+ const prototypeForwarding = Symbol('prototype-forwarding');
19
+ /**
20
+ * Symbol representing all properties in reactive tracking
21
+ */
22
+ const allProps = Symbol('all-props');
23
+ /**
24
+ * Symbol for accessing projection information on reactive objects
25
+ */
26
+ const projectionInfo = Symbol('projection-info');
27
+ /**
28
+ * Symbol to check if an effect is stopped
29
+ */
30
+ const stopped = Symbol('stopped');
31
+ /**
32
+ * Symbol to access effect cleanup function
33
+ */
34
+ const cleanup = Symbol('cleanup');
35
+ // Symbol to mark functions with their root function
36
+ const rootFunction = Symbol('root-function');
37
+ /**
38
+ * Structured error codes for machine-readable diagnosis
39
+ */
40
+ exports.ReactiveErrorCode = void 0;
41
+ (function (ReactiveErrorCode) {
42
+ ReactiveErrorCode["CycleDetected"] = "CYCLE_DETECTED";
43
+ ReactiveErrorCode["MaxDepthExceeded"] = "MAX_DEPTH_EXCEEDED";
44
+ ReactiveErrorCode["MaxReactionExceeded"] = "MAX_REACTION_EXCEEDED";
45
+ ReactiveErrorCode["WriteInComputed"] = "WRITE_IN_COMPUTED";
46
+ ReactiveErrorCode["TrackingError"] = "TRACKING_ERROR";
47
+ })(exports.ReactiveErrorCode || (exports.ReactiveErrorCode = {}));
48
+ /**
49
+ * Error class for reactive system errors
50
+ */
51
+ class ReactiveError extends Error {
52
+ constructor(message, debugInfo) {
53
+ super(message);
54
+ this.debugInfo = debugInfo;
55
+ this.name = 'ReactiveError';
56
+ }
57
+ }
58
+ // biome-ignore-start lint/correctness/noUnusedFunctionParameters: Interface declaration with empty defaults
59
+ /**
60
+ * Global options for the reactive system
61
+ */
62
+ const options = {
63
+ /**
64
+ * Debug purpose: called when an effect is entered
65
+ * @param effect - The effect that is entered
66
+ */
67
+ enter: (_effect) => { },
68
+ /**
69
+ * Debug purpose: called when an effect is left
70
+ * @param effect - The effect that is left
71
+ */
72
+ leave: (_effect) => { },
73
+ /**
74
+ * Debug purpose: called when an effect is chained
75
+ * @param target - The effect that is being triggered
76
+ * @param caller - The effect that is calling the target
77
+ */
78
+ chain: (_targets, _caller) => { },
79
+ /**
80
+ * Debug purpose: called when an effect chain is started
81
+ * @param target - The effect that is being triggered
82
+ */
83
+ beginChain: (_targets) => { },
84
+ /**
85
+ * Debug purpose: called when an effect chain is ended
86
+ */
87
+ endChain: () => { },
88
+ garbageCollected: (_fn) => { },
89
+ /**
90
+ * Debug purpose: called when an object is touched
91
+ * @param obj - The object that is touched
92
+ * @param evolution - The type of change
93
+ * @param props - The properties that changed
94
+ * @param deps - The dependencies that changed
95
+ */
96
+ touched: (_obj, _evolution, _props, _deps) => { },
97
+ /**
98
+ * Debug purpose: called when an effect is skipped because it's already running
99
+ * @param effect - The effect that is already running
100
+ * @param runningChain - The array of effects from the detected one to the currently running one
101
+ */
102
+ skipRunningEffect: (_effect, _runningChain) => { },
103
+ /**
104
+ * Debug purpose: maximum effect chain (like call stack max depth)
105
+ * Used to prevent infinite loops
106
+ * @default 100
107
+ */
108
+ maxEffectChain: 100,
109
+ /**
110
+ * Maximum number of times an effect can be triggered by the same cause in a single batch
111
+ * Used to detect aggressive re-computation or infinite loops
112
+ * @default 10
113
+ */
114
+ maxTriggerPerBatch: 10,
115
+ /**
116
+ * Debug purpose: maximum effect reaction (like call stack max depth)
117
+ * Used to prevent infinite loops
118
+ * @default 'throw'
119
+ */
120
+ maxEffectReaction: 'throw',
121
+ /**
122
+ * Callback called when a memoization discrepancy is detected (debug only)
123
+ * When defined, memoized functions will run a second time (untracked) to verify consistency.
124
+ * If the untracked run returns a different value than the cached one, this callback is triggered.
125
+ *
126
+ * This is the primary tool for detecting missing reactive dependencies in computed values.
127
+ *
128
+ * @param cached - The value currently in the memoization cache
129
+ * @param fresh - The value obtained by re-running the function untracked
130
+ * @param fn - The memoized function itself
131
+ * @param args - Arguments passed to the function
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * reactiveOptions.onMemoizationDiscrepancy = (cached, fresh, fn, args) => {
136
+ * throw new Error(`Memoization discrepancy in ${fn.name}!`);
137
+ * };
138
+ * ```
139
+ */
140
+ onMemoizationDiscrepancy: undefined,
141
+ /**
142
+ * How to handle cycles detected in effect batches
143
+ * - 'throw': Throw an error with cycle information (default, recommended for development)
144
+ * - 'warn': Log a warning and break the cycle by executing one effect
145
+ * - 'break': Silently break the cycle by executing one effect (recommended for production)
146
+ * - 'strict': Prevent cycle creation by checking graph before execution (throws error)
147
+ * @default 'throw'
148
+ */
149
+ cycleHandling: 'throw',
150
+ /**
151
+ * Internal flag used by memoization discrepancy detector to avoid counting calls in tests
152
+ * @warning Do not modify this flag manually, this flag is given by the engine
153
+ */
154
+ isVerificationRun: false,
155
+ /**
156
+ * Maximum depth for deep watching traversal
157
+ * Used to prevent infinite recursion in circular references
158
+ * @default 100
159
+ */
160
+ maxDeepWatchDepth: 100,
161
+ /**
162
+ * Only react on instance members modification (not inherited properties)
163
+ * For instance, do not track class methods
164
+ * @default true
165
+ */
166
+ instanceMembers: true,
167
+ /**
168
+ * Ignore accessors (getters and setters) and only track direct properties
169
+ * @default true
170
+ */
171
+ ignoreAccessors: true,
172
+ /**
173
+ * Enable recursive touching when objects with the same prototype are replaced
174
+ * When enabled, replacing an object with another of the same prototype triggers
175
+ * recursive diffing instead of notifying parent effects
176
+ * @default true
177
+ */
178
+ recursiveTouching: true,
179
+ /**
180
+ * Default async execution mode for effects that return Promises
181
+ * - 'cancel': Cancel previous async execution when dependencies change (default, enables async zone)
182
+ * - 'queue': Queue next execution to run after current completes (enables async zone)
183
+ * - 'ignore': Ignore new executions while async work is running (enables async zone)
184
+ * - false: Disable async zone and async mode handling (effects run concurrently)
185
+ *
186
+ * **When truthy:** Enables async zone (Promise.prototype wrapping) for automatic context
187
+ * preservation in Promise callbacks. Warning: This modifies Promise.prototype globally.
188
+ * Only enable if no other library modifies Promise.prototype.
189
+ *
190
+ * **When false:** Async zone is disabled. Use `tracked()` manually in Promise callbacks.
191
+ *
192
+ * Can be overridden per-effect via EffectOptions
193
+ * @default 'cancel'
194
+ */
195
+ asyncMode: 'cancel',
196
+ // biome-ignore lint/suspicious/noConsole: This is the whole point here
197
+ warn: (...args) => console.warn(...args),
198
+ /**
199
+ * Configuration for the introspection system
200
+ */
201
+ introspection: {
202
+ /**
203
+ * Whether to keep a history of mutations for debugging
204
+ * @default false
205
+ */
206
+ enableHistory: false,
207
+ /**
208
+ * Number of mutations to keep in history
209
+ * @default 50
210
+ */
211
+ historySize: 50,
212
+ },
213
+ /**
214
+ * Configuration for zone hooks - control which async APIs are hooked
215
+ * Each option controls whether the corresponding async API is wrapped to preserve effect context
216
+ * Only applies when asyncMode is enabled (truthy)
217
+ */
218
+ zones: {
219
+ /**
220
+ * Hook setTimeout to preserve effect context
221
+ * @default true
222
+ */
223
+ setTimeout: true,
224
+ /**
225
+ * Hook setInterval to preserve effect context
226
+ * @default true
227
+ */
228
+ setInterval: true,
229
+ /**
230
+ * Hook requestAnimationFrame (runs in untracked context when hooked)
231
+ * @default true
232
+ */
233
+ requestAnimationFrame: true,
234
+ /**
235
+ * Hook queueMicrotask to preserve effect context
236
+ * @default true
237
+ */
238
+ queueMicrotask: true,
239
+ },
240
+ };
241
+
242
+ /**
243
+ * Combines multiple arrays into an array of tuples, stopping at the shortest array length
244
+ * @param args - Arrays to zip together
245
+ * @returns Array of tuples containing elements from each input array
246
+ */
247
+ function zip(...args) {
248
+ if (!args.length)
249
+ return [];
250
+ const minLength = Math.min(...args.map((arr) => arr.length));
251
+ const result = [];
252
+ for (let i = 0; i < minLength; i++) {
253
+ const tuple = args.map((arr) => arr[i]);
254
+ result.push(tuple);
255
+ }
256
+ return result;
257
+ }
258
+ /**
259
+ * Checks if two arrays are strictly equal (shallow comparison)
260
+ * @param a - First value
261
+ * @param b - Second value
262
+ * @returns True if arrays are equal or values are strictly equal
263
+ */
264
+ function arrayEquals(a, b) {
265
+ if (a === b)
266
+ return true;
267
+ if (!Array.isArray(a) || !Array.isArray(b))
268
+ return false;
269
+ if (a.length !== b.length)
270
+ return false;
271
+ for (let i = 0; i < a.length; i++) {
272
+ if (a[i] !== b[i])
273
+ return false;
274
+ }
275
+ return true;
276
+ }
277
+ const nativeConstructors = new Set([
278
+ Object,
279
+ Array,
280
+ Date,
281
+ Function,
282
+ Set,
283
+ Map,
284
+ WeakMap,
285
+ WeakSet,
286
+ Promise,
287
+ Error,
288
+ TypeError,
289
+ ReferenceError,
290
+ SyntaxError,
291
+ RangeError,
292
+ URIError,
293
+ EvalError,
294
+ Reflect,
295
+ Proxy,
296
+ RegExp,
297
+ String,
298
+ Number,
299
+ Boolean,
300
+ ]);
301
+ /**
302
+ * Checks if a function is a constructor (class or constructor function)
303
+ * @param fn - The function to check
304
+ * @returns True if the function is a constructor
305
+ */
306
+ function isConstructor(fn) {
307
+ return (fn &&
308
+ typeof fn === 'function' &&
309
+ (nativeConstructors.has(fn) || fn.toString?.().startsWith('class ')));
310
+ }
311
+ /**
312
+ * Renames a function with a new name
313
+ * @param fct - The function to rename
314
+ * @param name - The new name for the function
315
+ * @returns The function with the new name
316
+ */
317
+ function renamed(fct, name) {
318
+ return Object.defineProperties(fct, {
319
+ name: {
320
+ value: name,
321
+ },
322
+ });
323
+ }
324
+ function ReflectGet(obj, prop, receiver) {
325
+ // Check if Node is available and obj is an instance of Node
326
+ if (typeof Node !== 'undefined' && obj instanceof Node)
327
+ return obj[prop];
328
+ return Reflect.get(obj, prop, receiver);
329
+ }
330
+ function ReflectSet(obj, prop, value, receiver) {
331
+ // Check if Node is available and obj is an instance of Node
332
+ if (typeof Node !== 'undefined' && obj instanceof Node) {
333
+ obj[prop] = value;
334
+ return true;
335
+ }
336
+ if (!(obj instanceof Object) && !Reflect.has(obj, prop)) {
337
+ Object.defineProperty(obj, prop, {
338
+ value,
339
+ configurable: true,
340
+ writable: true,
341
+ enumerable: true,
342
+ });
343
+ return true;
344
+ }
345
+ return Reflect.set(obj, prop, value, receiver);
346
+ }
347
+ function isOwnAccessor(obj, prop) {
348
+ const opd = Object.getOwnPropertyDescriptor(obj, prop);
349
+ return !!(opd?.get || opd?.set);
350
+ }
351
+ /**
352
+ * Deeply compares two values.
353
+ * For objects, compares prototypes with === and then own properties recursively.
354
+ * Uses a cache to handle circular references.
355
+ * @param a - First value
356
+ * @param b - Second value
357
+ * @param cache - Map for circular reference protection (internal use)
358
+ * @returns True if values are deeply equal
359
+ */
360
+ function deepCompare(a, b, cache = new Map()) {
361
+ // Unwrap mutts proxies if present
362
+ while (a && typeof a === 'object' && prototypeForwarding in a) {
363
+ a = a[prototypeForwarding];
364
+ }
365
+ while (b && typeof b === 'object' && prototypeForwarding in b) {
366
+ b = b[prototypeForwarding];
367
+ }
368
+ if (a === b)
369
+ return true;
370
+ if (typeof a !== 'object' || a === null || typeof b !== 'object' || b === null) {
371
+ return a === b;
372
+ }
373
+ // Prototype check
374
+ const protoA = Object.getPrototypeOf(a);
375
+ const protoB = Object.getPrototypeOf(b);
376
+ if (protoA !== protoB) {
377
+ console.warn(`[deepCompare] prototype mismatch:`, { nameA: a?.constructor?.name, nameB: b?.constructor?.name });
378
+ return false;
379
+ }
380
+ // Circular reference protection
381
+ let compared = cache.get(a);
382
+ if (compared?.has(b))
383
+ return true;
384
+ if (!compared) {
385
+ compared = new Set();
386
+ cache.set(a, compared);
387
+ }
388
+ compared.add(b);
389
+ // Handle specific object types
390
+ if (Array.isArray(a)) {
391
+ if (!Array.isArray(b)) {
392
+ console.warn(`[deepCompare] B is not an array`);
393
+ return false;
394
+ }
395
+ if (a.length !== b.length) {
396
+ console.warn(`[deepCompare] array length mismatch:`, { lenA: a.length, lenB: b.length });
397
+ return false;
398
+ }
399
+ for (let i = 0; i < a.length; i++) {
400
+ if (!deepCompare(a[i], b[i], cache)) {
401
+ console.warn(`[deepCompare] array element mismatch at index ${i}`);
402
+ return false;
403
+ }
404
+ }
405
+ return true;
406
+ }
407
+ if (a instanceof Date) {
408
+ const match = b instanceof Date && a.getTime() === b.getTime();
409
+ if (!match)
410
+ console.warn(`[deepCompare] Date mismatch`);
411
+ return match;
412
+ }
413
+ if (a instanceof RegExp) {
414
+ const match = b instanceof RegExp && a.toString() === b.toString();
415
+ if (!match)
416
+ console.warn(`[deepCompare] RegExp mismatch`);
417
+ return match;
418
+ }
419
+ if (a instanceof Set) {
420
+ if (!(b instanceof Set) || a.size !== b.size) {
421
+ console.warn(`[deepCompare] Set size mismatch`);
422
+ return false;
423
+ }
424
+ for (const val of a) {
425
+ let found = false;
426
+ for (const bVal of b) {
427
+ if (deepCompare(val, bVal, cache)) {
428
+ found = true;
429
+ break;
430
+ }
431
+ }
432
+ if (!found) {
433
+ console.warn(`[deepCompare] missing Set element`);
434
+ return false;
435
+ }
436
+ }
437
+ return true;
438
+ }
439
+ if (a instanceof Map) {
440
+ if (!(b instanceof Map) || a.size !== b.size) {
441
+ console.warn(`[deepCompare] Map size mismatch`);
442
+ return false;
443
+ }
444
+ for (const [key, val] of a) {
445
+ if (!b.has(key)) {
446
+ let foundMatch = false;
447
+ for (const [bKey, bVal] of b) {
448
+ if (deepCompare(key, bKey, cache) && deepCompare(val, bVal, cache)) {
449
+ foundMatch = true;
450
+ break;
451
+ }
452
+ }
453
+ if (!foundMatch) {
454
+ console.warn(`[deepCompare] missing Map key`);
455
+ return false;
456
+ }
457
+ }
458
+ else {
459
+ if (!deepCompare(val, b.get(key), cache)) {
460
+ console.warn(`[deepCompare] Map value mismatch for key`);
461
+ return false;
462
+ }
463
+ }
464
+ }
465
+ return true;
466
+ }
467
+ // Compare own properties
468
+ const keysA = Object.keys(a);
469
+ const keysB = Object.keys(b);
470
+ if (keysA.length !== keysB.length) {
471
+ console.warn(`[deepCompare] keys length mismatch:`, { lenA: keysA.length, lenB: keysB.length, keysA, keysB, a, b });
472
+ return false;
473
+ }
474
+ for (const key of keysA) {
475
+ if (!Object.prototype.hasOwnProperty.call(b, key)) {
476
+ console.warn(`[deepCompare] missing key ${String(key)} in B`);
477
+ return false;
478
+ }
479
+ if (!deepCompare(a[key], b[key], cache)) {
480
+ console.warn(`[deepCompare] value mismatch for key ${String(key)}:`, { valA: a[key], valB: b[key] });
481
+ return false;
482
+ }
483
+ }
484
+ return true;
485
+ }
486
+
487
+ // biome-ignore-all lint/suspicious/noConfusingVoidType: We *love* voids
488
+ // Standardized decorator system that works with both Legacy and Modern decorators
489
+ /**
490
+ * Error thrown when decorator operations fail
491
+ */
492
+ class DecoratorError extends Error {
493
+ constructor(message) {
494
+ super(message);
495
+ this.name = 'DecoratorException';
496
+ }
497
+ }
498
+ /**
499
+ * Creates a decorator that works with Legacy decorator proposals
500
+ * @param description - The decorator description object
501
+ * @returns A decorator function compatible with Legacy decorators
502
+ */
503
+ function legacyDecorator(description) {
504
+ return function (target, propertyKey, descriptor, ...args) {
505
+ if (propertyKey === undefined) {
506
+ if (isConstructor(target)) {
507
+ if (!('class' in description))
508
+ throw new Error('Decorator cannot be applied to a class');
509
+ return description.class(target);
510
+ }
511
+ }
512
+ else if (typeof target === 'object' && ['string', 'symbol'].includes(typeof propertyKey)) {
513
+ if (!descriptor)
514
+ throw new Error('Decorator cannot be applied to a field');
515
+ else if (typeof descriptor === 'object' && 'configurable' in descriptor) {
516
+ if ('get' in descriptor || 'set' in descriptor) {
517
+ if (!('getter' in description || 'setter' in description))
518
+ throw new Error('Decorator cannot be applied to a getter or setter');
519
+ if ('getter' in description) {
520
+ const newGetter = description.getter(descriptor.get, target, propertyKey);
521
+ if (newGetter)
522
+ descriptor.get = newGetter;
523
+ }
524
+ if ('setter' in description) {
525
+ const newSetter = description.setter(descriptor.set, target, propertyKey);
526
+ if (newSetter)
527
+ descriptor.set = newSetter;
528
+ }
529
+ return descriptor;
530
+ }
531
+ else if (typeof descriptor.value === 'function') {
532
+ if (!('method' in description))
533
+ throw new Error('Decorator cannot be applied to a method');
534
+ const newMethod = description.method(descriptor.value, target, propertyKey);
535
+ if (newMethod)
536
+ descriptor.value = newMethod;
537
+ return descriptor;
538
+ }
539
+ }
540
+ }
541
+ if (!('default' in description))
542
+ throw new Error('Decorator do not have a default implementation');
543
+ return description.default.call(this, target, propertyKey, descriptor, ...args);
544
+ };
545
+ }
546
+ /**
547
+ * Creates a decorator that works with Modern decorator proposals
548
+ * @param description - The decorator description object
549
+ * @returns A decorator function compatible with Modern decorators
550
+ */
551
+ function modernDecorator(description) {
552
+ /*return function (target: any, context?: DecoratorContext, ...args: any[]) {*/
553
+ return function (target, context, ...args) {
554
+ if (!context?.kind || typeof context.kind !== 'string') {
555
+ if (!('default' in description))
556
+ throw new Error('Decorator do not have a default implementation');
557
+ return description.default.call(this, target, context, ...args);
558
+ }
559
+ switch (context.kind) {
560
+ case 'class':
561
+ if (!('class' in description))
562
+ throw new Error('Decorator cannot be applied to a class');
563
+ return description.class(target);
564
+ case 'field':
565
+ throw new Error('Decorator cannot be applied to a field');
566
+ case 'getter':
567
+ if (!('getter' in description))
568
+ throw new Error('Decorator cannot be applied to a getter');
569
+ return description.getter(target, target, context.name);
570
+ case 'setter':
571
+ if (!('setter' in description))
572
+ throw new Error('Decorator cannot be applied to a setter');
573
+ return description.setter(target, target, context.name);
574
+ case 'method':
575
+ if (!('method' in description))
576
+ throw new Error('Decorator cannot be applied to a method');
577
+ return description.method(target, target, context.name);
578
+ case 'accessor': {
579
+ if (!('getter' in description || 'setter' in description))
580
+ throw new Error('Decorator cannot be applied to a getter or setter');
581
+ const rv = {};
582
+ if ('getter' in description) {
583
+ const newGetter = description.getter(target.get, target, context.name);
584
+ if (newGetter)
585
+ rv.get = newGetter;
586
+ }
587
+ if ('setter' in description) {
588
+ const newSetter = description.setter(target.set, target, context.name);
589
+ if (newSetter)
590
+ rv.set = newSetter;
591
+ }
592
+ return rv;
593
+ }
594
+ //return description.accessor?.(target, context.name, target)
595
+ }
596
+ };
597
+ }
598
+ /**
599
+ * Detects if the decorator is being called in modern (Modern) or legacy (Legacy) mode
600
+ * based on the arguments passed to the decorator function
601
+ */
602
+ function detectDecoratorMode(_target, contextOrKey, _descriptor) {
603
+ // Modern decorators have a context object as the second parameter
604
+ // Legacy decorators have a string/symbol key as the second parameter
605
+ if (typeof contextOrKey === 'object' &&
606
+ contextOrKey !== null &&
607
+ typeof contextOrKey.kind === 'string') {
608
+ return 'modern';
609
+ }
610
+ return 'legacy';
611
+ }
612
+ /**
613
+ * Main decorator factory that automatically detects and works with both Legacy and Modern decorator proposals
614
+ * @param description - The decorator description object
615
+ * @returns A decorator that works in both Legacy and Modern environments
616
+ */
617
+ const decorator = (description) => {
618
+ const modern = modernDecorator(description);
619
+ const legacy = legacyDecorator(description);
620
+ return ((target, contextOrKey, ...args) => {
621
+ const mode = detectDecoratorMode(target, contextOrKey, args[0]);
622
+ return mode === 'modern'
623
+ ? modern(target, contextOrKey, ...args)
624
+ : legacy(target, contextOrKey, ...args);
625
+ });
626
+ };
627
+
628
+ exports.DecoratorError = DecoratorError;
629
+ exports.ReactiveError = ReactiveError;
630
+ exports.ReflectGet = ReflectGet;
631
+ exports.ReflectSet = ReflectSet;
632
+ exports.allProps = allProps;
633
+ exports.arrayEquals = arrayEquals;
634
+ exports.cleanup = cleanup;
635
+ exports.decorator = decorator;
636
+ exports.deepCompare = deepCompare;
637
+ exports.isConstructor = isConstructor;
638
+ exports.isOwnAccessor = isOwnAccessor;
639
+ exports.legacyDecorator = legacyDecorator;
640
+ exports.modernDecorator = modernDecorator;
641
+ exports.nativeReactive = nativeReactive;
642
+ exports.nonReactiveMark = nonReactiveMark;
643
+ exports.options = options;
644
+ exports.projectionInfo = projectionInfo;
645
+ exports.prototypeForwarding = prototypeForwarding;
646
+ exports.renamed = renamed;
647
+ exports.rootFunction = rootFunction;
648
+ exports.stopped = stopped;
649
+ exports.unreactiveProperties = unreactiveProperties;
650
+ exports.zip = zip;
651
+ //# sourceMappingURL=decorator-BQ2eBTCj.js.map