mutts 1.0.7 → 1.0.8

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 (132) hide show
  1. package/README.md +61 -23
  2. package/dist/async/browser.d.ts +2 -0
  3. package/dist/async/browser.d.ts.map +1 -0
  4. package/dist/async/index.d.ts +18 -0
  5. package/dist/async/index.d.ts.map +1 -0
  6. package/dist/async/node.d.ts +2 -0
  7. package/dist/async/node.d.ts.map +1 -0
  8. package/dist/{chunks/index-BFYK02LG.js → browser.cjs} +169 -60
  9. package/dist/browser.cjs.map +1 -0
  10. package/dist/browser.d.ts +1654 -1
  11. package/dist/browser.esm.js +260 -25
  12. package/dist/browser.esm.js.map +1 -1
  13. package/dist/chunks/async-browser-CA0jPWIi.cjs +304 -0
  14. package/dist/chunks/async-browser-CA0jPWIi.cjs.map +1 -0
  15. package/dist/chunks/async-core-UqHzvJ-S.cjs +25 -0
  16. package/dist/chunks/async-core-UqHzvJ-S.cjs.map +1 -0
  17. package/dist/chunks/async-node-BYHuGTni.cjs +103 -0
  18. package/dist/chunks/async-node-BYHuGTni.cjs.map +1 -0
  19. package/dist/chunks/{index-CNR6QRUl.esm.js → index-DhaOVusv.esm.js} +173 -53
  20. package/dist/chunks/index-DhaOVusv.esm.js.map +1 -0
  21. package/dist/decorator.d.ts +106 -0
  22. package/dist/decorator.d.ts.map +1 -0
  23. package/dist/destroyable.d.ts +87 -0
  24. package/dist/destroyable.d.ts.map +1 -0
  25. package/dist/devtools/devtool/devtools.d.ts +1 -0
  26. package/dist/devtools/devtool/devtools.d.ts.map +1 -0
  27. package/dist/devtools/devtool/panel.d.ts +2 -0
  28. package/dist/devtools/devtool/panel.d.ts.map +1 -0
  29. package/dist/entry-browser.d.ts +3 -0
  30. package/dist/entry-browser.d.ts.map +1 -0
  31. package/dist/entry-node.d.ts +3 -0
  32. package/dist/entry-node.d.ts.map +1 -0
  33. package/dist/eventful.d.ts +18 -0
  34. package/dist/eventful.d.ts.map +1 -0
  35. package/dist/index.d.ts +13 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/indexable.d.ts +243 -0
  38. package/dist/indexable.d.ts.map +1 -0
  39. package/dist/introspection.d.ts +27 -0
  40. package/dist/introspection.d.ts.map +1 -0
  41. package/dist/iterableWeak.d.ts +53 -0
  42. package/dist/iterableWeak.d.ts.map +1 -0
  43. package/dist/mixins.d.ts +25 -0
  44. package/dist/mixins.d.ts.map +1 -0
  45. package/dist/mutts.umd.js +1 -1
  46. package/dist/mutts.umd.js.map +1 -1
  47. package/dist/mutts.umd.min.js +1 -1
  48. package/dist/mutts.umd.min.js.map +1 -1
  49. package/dist/node.cjs +105 -0
  50. package/dist/node.cjs.map +1 -0
  51. package/dist/node.d.ts +1 -2
  52. package/dist/node.esm.js +91 -32
  53. package/dist/node.esm.js.map +1 -1
  54. package/dist/promiseChain.d.ts +20 -0
  55. package/dist/promiseChain.d.ts.map +1 -0
  56. package/dist/reactive/array.d.ts +49 -0
  57. package/dist/reactive/array.d.ts.map +1 -0
  58. package/dist/reactive/buffer.d.ts +44 -0
  59. package/dist/reactive/buffer.d.ts.map +1 -0
  60. package/dist/reactive/change.d.ts +29 -0
  61. package/dist/reactive/change.d.ts.map +1 -0
  62. package/dist/reactive/debug.d.ts +111 -0
  63. package/dist/reactive/debug.d.ts.map +1 -0
  64. package/dist/reactive/deep-touch.d.ts +28 -0
  65. package/dist/reactive/deep-touch.d.ts.map +1 -0
  66. package/dist/reactive/deep-watch-state.d.ts +25 -0
  67. package/dist/reactive/deep-watch-state.d.ts.map +1 -0
  68. package/dist/reactive/deep-watch.d.ts +19 -0
  69. package/dist/reactive/deep-watch.d.ts.map +1 -0
  70. package/dist/reactive/effect-context.d.ts +7 -0
  71. package/dist/reactive/effect-context.d.ts.map +1 -0
  72. package/dist/reactive/effects.d.ts +151 -0
  73. package/dist/reactive/effects.d.ts.map +1 -0
  74. package/dist/reactive/index.d.ts +20 -0
  75. package/dist/reactive/index.d.ts.map +1 -0
  76. package/dist/reactive/interface.d.ts +64 -0
  77. package/dist/reactive/interface.d.ts.map +1 -0
  78. package/dist/reactive/map.d.ts +30 -0
  79. package/dist/reactive/map.d.ts.map +1 -0
  80. package/dist/reactive/memoize.d.ts +5 -0
  81. package/dist/reactive/memoize.d.ts.map +1 -0
  82. package/dist/reactive/non-reactive-state.d.ts +9 -0
  83. package/dist/reactive/non-reactive-state.d.ts.map +1 -0
  84. package/dist/reactive/non-reactive.d.ts +11 -0
  85. package/dist/reactive/non-reactive.d.ts.map +1 -0
  86. package/dist/reactive/project.d.ts +41 -0
  87. package/dist/reactive/project.d.ts.map +1 -0
  88. package/dist/reactive/proxy-state.d.ts +8 -0
  89. package/dist/reactive/proxy-state.d.ts.map +1 -0
  90. package/dist/reactive/proxy.d.ts +23 -0
  91. package/dist/reactive/proxy.d.ts.map +1 -0
  92. package/dist/reactive/record.d.ts +116 -0
  93. package/dist/reactive/record.d.ts.map +1 -0
  94. package/dist/reactive/register.d.ts +64 -0
  95. package/dist/reactive/register.d.ts.map +1 -0
  96. package/dist/reactive/registry.d.ts +20 -0
  97. package/dist/reactive/registry.d.ts.map +1 -0
  98. package/dist/reactive/set.d.ts +28 -0
  99. package/dist/reactive/set.d.ts.map +1 -0
  100. package/dist/reactive/tracking.d.ts +7 -0
  101. package/dist/reactive/tracking.d.ts.map +1 -0
  102. package/dist/reactive/types.d.ts +376 -0
  103. package/dist/reactive/types.d.ts.map +1 -0
  104. package/dist/std-decorators.d.ts +50 -0
  105. package/dist/std-decorators.d.ts.map +1 -0
  106. package/dist/utils.d.ts +49 -0
  107. package/dist/utils.d.ts.map +1 -0
  108. package/dist/zone.d.ts +40 -0
  109. package/dist/zone.d.ts.map +1 -0
  110. package/docs/std-decorators.md +69 -1
  111. package/docs/zone.md +7 -0
  112. package/package.json +39 -27
  113. package/src/async/browser.ts +266 -34
  114. package/src/async/index.ts +17 -2
  115. package/src/async/node.ts +89 -31
  116. package/src/entry-browser.ts +5 -0
  117. package/src/entry-node.ts +5 -0
  118. package/src/index.d.ts +12 -9
  119. package/src/index.ts +1 -0
  120. package/src/reactive/array.ts +139 -52
  121. package/src/reactive/effect-context.ts +3 -3
  122. package/src/reactive/index.ts +2 -1
  123. package/src/reactive/map.ts +1 -1
  124. package/src/reactive/set.ts +1 -1
  125. package/src/utils.ts +1 -1
  126. package/src/zone.ts +19 -8
  127. package/dist/browser.js +0 -161
  128. package/dist/browser.js.map +0 -1
  129. package/dist/chunks/index-BFYK02LG.js.map +0 -1
  130. package/dist/chunks/index-CNR6QRUl.esm.js.map +0 -1
  131. package/dist/node.js +0 -136
  132. package/dist/node.js.map +0 -1
@@ -1,51 +1,284 @@
1
- import { a as asyncHooks } from './chunks/index-CNR6QRUl.esm.js';
2
- export { A as AZone, b as ArrayReadForward, D as DecoratorError, c as Destroyable, d as DestructionError, E as Eventful, F as FoolProof, I as Indexable, e as IterableWeakMap, f as IterableWeakSet, R as ReactiveBase, g as ReactiveError, h as ReactiveErrorCode, i as Register, Z as Zone, j as ZoneAggregator, k as ZoneHistory, l as addBatchCleanup, m as allocated, n as allocatedValues, o as arrayEquals, p as asyncZone, q as atomic, r as biDi, s as buildReactivityGraph, t as cache, u as cached, v as callOnGC, w as chainPromise, x as cleanedBy, y as cleanup, z as contentRef, B as debounce, C as decorator, G as deepCompare, H as deepWatch, J as defer, K as deprecated, L as derived, M as describe, N as destructor, O as effect, P as enableDevTools, Q as forwardArray, S as getActivationLog, T as getActiveProjection, U as getAt, V as getState, W as immutables, X as isCached, Y as isConstructor, _ as isDevtoolsEnabled, $ as isNonReactive, a0 as isOwnAccessor, a1 as isReactive, a2 as legacyDecorator, a3 as memoize, a4 as mixin, a5 as modernDecorator, a6 as named, a7 as organize, a8 as organized, a9 as profileInfo, aa as project, ab as reactive, ac as reactiveOptions, ad as register, ae as registerEffectForDebug, af as registerNativeReactivity, ag as registerObjectForDebug, ah as renamed, ai as root, aj as scan, ak as setAt, al as setEffectName, am as setObjectName, an as tag, ao as throttle, ap as touched, aq as touched1, ar as trackEffect, as as unreactive, at as untracked, au as unwrap, av as watch, aw as zip } from './chunks/index-CNR6QRUl.esm.js';
1
+ import { a as asyncHooks } from './chunks/index-DhaOVusv.esm.js';
2
+ export { A as AZone, b as ArrayReadForward, D as DecoratorError, c as Destroyable, d as DestructionError, E as Eventful, F as FoolProof, I as Indexable, e as IterableWeakMap, f as IterableWeakSet, R as ReactiveBase, g as ReactiveError, h as ReactiveErrorCode, i as Register, Z as Zone, j as ZoneAggregator, k as ZoneHistory, l as addBatchCleanup, m as allocated, n as allocatedValues, o as arrayEquals, p as asyncHook, q as asyncZone, r as atomic, s as biDi, t as buildReactivityGraph, u as cache, v as cached, w as callOnGC, x as chainPromise, y as cleanedBy, z as cleanup, B as contentRef, C as debounce, G as decorator, H as deepCompare, J as deepWatch, K as defer, L as deprecated, M as derived, N as describe, O as destructor, P as effect, Q as effectAggregator, S as enableDevTools, T as forwardArray, U as getActivationLog, V as getActiveEffect, W as getActiveProjection, X as getAt, Y as getState, _ as immutables, $ as isCached, a0 as isConstructor, a1 as isDevtoolsEnabled, a2 as isNonReactive, a3 as isOwnAccessor, a4 as isReactive, a5 as legacyDecorator, a6 as memoize, a7 as mixin, a8 as modernDecorator, a9 as named, aa as organize, ab as organized, ac as profileInfo, ad as project, ae as reactive, af as reactiveOptions, ag as register, ah as registerEffectForDebug, ai as registerNativeReactivity, aj as registerObjectForDebug, ak as renamed, al as resolve, am as root, an as scan, ao as setAt, ap as setEffectName, aq as setObjectName, ar as tag, as as throttle, at as touched, au as touched1, av as trackEffect, aw as unreactive, ax as untracked, ay as unwrap, az as watch, aA as zip } from './chunks/index-DhaOVusv.esm.js';
3
3
 
4
4
  const hooks = new Set();
5
+ const promiseContexts = new WeakMap();
5
6
  asyncHooks.addHook = function (hook) {
6
7
  hooks.add(hook);
7
8
  return () => {
8
9
  hooks.delete(hook);
9
10
  };
10
11
  };
11
- function wrap(fn) {
12
+ // [HACK]: Sanitization
13
+ // If a Promise is created inside the zone, it carries the "Sticky" zone context.
14
+ // If returned to the outer scope, that context leaks. We wrap it in a new Promise
15
+ // created here (in the outer scope) to break the chain and sanitize the return value.
16
+ // See BROWSER_ASYNC_POLYFILL.md for full details.
17
+ asyncHooks.sanitizePromise = (res) => {
18
+ if (res && typeof res.then === 'function') {
19
+ return new Promise((resolve, reject) => {
20
+ setTimeout(() => {
21
+ res.then(resolve, reject);
22
+ }, 0);
23
+ });
24
+ }
25
+ return res;
26
+ };
27
+ function captureRestorers() {
28
+ const restorers = new Set();
29
+ for (const hook of hooks) {
30
+ const restorer = hook();
31
+ if (restorer)
32
+ restorers.add(restorer);
33
+ }
34
+ return restorers;
35
+ }
36
+ function wrap(fn, capturedRestorers) {
12
37
  if (typeof fn !== 'function')
13
38
  return fn;
14
- const restorers = new Set();
15
- for (const hook of hooks)
16
- restorers.add(hook());
39
+ const restorers = capturedRestorers || captureRestorers();
17
40
  return function (...args) {
18
- const undoers = new Set();
41
+ const undoers = [];
19
42
  for (const restore of restorers)
20
- undoers.add(restore());
43
+ undoers.push(restore());
21
44
  try {
22
45
  return fn.apply(this, args);
23
46
  }
24
47
  finally {
25
- for (const undo of undoers)
26
- undo();
48
+ if (originals.queueMicrotask) {
49
+ // Double microtask ensures we run after the first await resumption microtask
50
+ originals.queueMicrotask.call(globalThis, () => {
51
+ originals.queueMicrotask.call(globalThis, () => {
52
+ originals.queueMicrotask.call(globalThis, () => {
53
+ for (let i = undoers.length - 1; i >= 0; i--)
54
+ undoers[i]();
55
+ });
56
+ });
57
+ });
58
+ }
59
+ else {
60
+ for (let i = undoers.length - 1; i >= 0; i--)
61
+ undoers[i]();
62
+ }
63
+ }
64
+ };
65
+ }
66
+ const targetWrappers = new WeakMap();
67
+ function patchEventTarget(proto) {
68
+ if (!proto || !proto.addEventListener || !proto.removeEventListener)
69
+ return;
70
+ const nativeAdd = proto.addEventListener;
71
+ const nativeRemove = proto.removeEventListener;
72
+ proto.addEventListener = function (type, listener, options) {
73
+ if (typeof listener !== 'function') {
74
+ return nativeAdd.call(this, type, listener, options);
75
+ }
76
+ let types = targetWrappers.get(this);
77
+ if (!types) {
78
+ types = new Map();
79
+ targetWrappers.set(this, types);
80
+ }
81
+ let listeners = types.get(type);
82
+ if (!listeners) {
83
+ listeners = new WeakMap();
84
+ types.set(type, listeners);
85
+ }
86
+ let wrapped = listeners.get(listener);
87
+ if (!wrapped) {
88
+ wrapped = wrap(listener);
89
+ listeners.set(listener, wrapped);
90
+ }
91
+ return nativeAdd.call(this, type, wrapped, options);
92
+ };
93
+ proto.removeEventListener = function (type, listener, options) {
94
+ if (typeof listener !== 'function') {
95
+ return nativeRemove.call(this, type, listener, options);
96
+ }
97
+ const types = targetWrappers.get(this);
98
+ if (types) {
99
+ const listeners = types.get(type);
100
+ if (listeners) {
101
+ const wrapped = listeners.get(listener);
102
+ if (wrapped) {
103
+ return nativeRemove.call(this, type, wrapped, options);
104
+ }
105
+ }
106
+ }
107
+ return nativeRemove.call(this, type, listener, options);
108
+ };
109
+ }
110
+ function patchOnProperties(proto) {
111
+ if (!proto)
112
+ return;
113
+ for (const prop of Object.getOwnPropertyNames(proto)) {
114
+ if (prop.startsWith('on')) {
115
+ const desc = Object.getOwnPropertyDescriptor(proto, prop);
116
+ if (desc && desc.set && desc.configurable) {
117
+ const nativeSet = desc.set;
118
+ Object.defineProperty(proto, prop, {
119
+ ...desc,
120
+ set: function (fn) {
121
+ nativeSet.call(this, wrap(fn));
122
+ }
123
+ });
124
+ }
27
125
  }
126
+ }
127
+ }
128
+ if (typeof EventTarget !== 'undefined') {
129
+ patchEventTarget(EventTarget.prototype);
130
+ }
131
+ const prototypesToPatch = [
132
+ typeof EventTarget !== 'undefined' && EventTarget.prototype,
133
+ typeof HTMLElement !== 'undefined' && HTMLElement.prototype,
134
+ typeof Window !== 'undefined' && Window.prototype,
135
+ typeof Document !== 'undefined' && Document.prototype,
136
+ typeof MessagePort !== 'undefined' && MessagePort.prototype,
137
+ typeof XMLHttpRequest !== 'undefined' && XMLHttpRequest.prototype,
138
+ typeof IDBRequest !== 'undefined' && IDBRequest.prototype,
139
+ typeof IDBTransaction !== 'undefined' && IDBTransaction.prototype,
140
+ typeof IDBDatabase !== 'undefined' && IDBDatabase.prototype,
141
+ typeof FileReader !== 'undefined' && FileReader.prototype,
142
+ typeof AbortSignal !== 'undefined' && AbortSignal.prototype,
143
+ ];
144
+ for (const proto of prototypesToPatch) {
145
+ if (proto) {
146
+ patchOnProperties(proto);
147
+ }
148
+ }
149
+ const GLOBAL_ORIGINALS = Symbol.for('mutts.originals');
150
+ const GLOBAL_PROMISE = Symbol.for('mutts.OriginalPromise');
151
+ let originals;
152
+ let OriginalPromise;
153
+ if (globalThis[GLOBAL_ORIGINALS]) {
154
+ originals = globalThis[GLOBAL_ORIGINALS];
155
+ OriginalPromise = globalThis[GLOBAL_PROMISE];
156
+ }
157
+ else {
158
+ OriginalPromise = globalThis.Promise;
159
+ originals = {
160
+ then: OriginalPromise.prototype.then,
161
+ catch: OriginalPromise.prototype.catch,
162
+ finally: OriginalPromise.prototype.finally,
163
+ resolve: OriginalPromise.resolve,
164
+ reject: OriginalPromise.reject,
165
+ all: OriginalPromise.all,
166
+ allSettled: OriginalPromise.allSettled,
167
+ race: OriginalPromise.race,
168
+ any: OriginalPromise.any,
169
+ setTimeout: globalThis.setTimeout,
170
+ setInterval: globalThis.setInterval,
171
+ setImmediate: globalThis.setImmediate,
172
+ requestAnimationFrame: globalThis.requestAnimationFrame,
173
+ queueMicrotask: globalThis.queueMicrotask,
28
174
  };
175
+ globalThis[GLOBAL_ORIGINALS] = originals;
176
+ globalThis[GLOBAL_PROMISE] = OriginalPromise;
177
+ }
178
+ // Ensure modern statics are captured even if originals was cached from an older version
179
+ if (!originals.allSettled)
180
+ originals.allSettled = OriginalPromise.allSettled;
181
+ if (!originals.any)
182
+ originals.any = OriginalPromise.any;
183
+ if (!originals.race)
184
+ originals.race = OriginalPromise.race;
185
+ function patchedThen(onFulfilled, onRejected) {
186
+ const context = promiseContexts.get(this) || captureRestorers();
187
+ const nextPromise = originals.then.call(this, wrap(onFulfilled, context), wrap(onRejected, context));
188
+ if (context.size > 0)
189
+ promiseContexts.set(nextPromise, context);
190
+ return nextPromise;
191
+ }
192
+ function patchedCatch(onRejected) {
193
+ const context = promiseContexts.get(this) || captureRestorers();
194
+ const nextPromise = originals.catch.call(this, wrap(onRejected, context));
195
+ if (context.size > 0)
196
+ promiseContexts.set(nextPromise, context);
197
+ return nextPromise;
198
+ }
199
+ function patchedFinally(onFinally) {
200
+ const context = promiseContexts.get(this) || captureRestorers();
201
+ const nextPromise = originals.finally.call(this, wrap(onFinally, context));
202
+ if (context.size > 0)
203
+ promiseContexts.set(nextPromise, context);
204
+ return nextPromise;
29
205
  }
30
- const originals = {
31
- then: Promise.prototype.then,
32
- catch: Promise.prototype.catch,
33
- finally: Promise.prototype.finally,
34
- setTimeout: globalThis.setTimeout,
35
- setInterval: globalThis.setInterval,
36
- setImmediate: globalThis.setImmediate,
37
- requestAnimationFrame: globalThis.requestAnimationFrame,
38
- queueMicrotask: globalThis.queueMicrotask,
206
+ function PatchedPromise(executor) {
207
+ if (typeof executor === 'function') {
208
+ const p = new OriginalPromise((resolve, reject) => {
209
+ const wrappedResolve = wrap(resolve);
210
+ const wrappedReject = wrap(reject);
211
+ executor(wrappedResolve, wrappedReject);
212
+ });
213
+ const context = captureRestorers();
214
+ promiseContexts.set(p, context); // Always set, even if empty (Sticky Root)
215
+ return p;
216
+ }
217
+ return new OriginalPromise(executor);
218
+ }
219
+ // Copy statics
220
+ Object.assign(PatchedPromise, OriginalPromise);
221
+ // Inherit prototype for instanceof checks
222
+ PatchedPromise.prototype = OriginalPromise.prototype;
223
+ PatchedPromise.resolve = function (value) {
224
+ const p = originals.resolve.call(OriginalPromise, value);
225
+ const context = captureRestorers();
226
+ // Ensure we don't overwrite if it already has context (e.g. from constructor)
227
+ if (context.size > 0 && !promiseContexts.has(p))
228
+ promiseContexts.set(p, context);
229
+ return p;
230
+ };
231
+ PatchedPromise.reject = function (reason) {
232
+ const p = originals.reject.call(OriginalPromise, reason);
233
+ const context = captureRestorers();
234
+ if (context.size > 0)
235
+ promiseContexts.set(p, context);
236
+ return p;
39
237
  };
40
- Promise.prototype.then = function (onFulfilled, onRejected) {
41
- return originals.then.call(this, wrap(onFulfilled), wrap(onRejected));
238
+ PatchedPromise.all = function (values) {
239
+ const p = originals.all.call(OriginalPromise, values);
240
+ const context = captureRestorers();
241
+ if (context.size > 0)
242
+ promiseContexts.set(p, context);
243
+ return p;
42
244
  };
43
- Promise.prototype.catch = function (onRejected) {
44
- return originals.catch.call(this, wrap(onRejected));
245
+ PatchedPromise.allSettled = function (values) {
246
+ const p = originals.allSettled.call(OriginalPromise, values);
247
+ const context = captureRestorers();
248
+ if (context.size > 0)
249
+ promiseContexts.set(p, context);
250
+ return p;
45
251
  };
46
- Promise.prototype.finally = function (onFinally) {
47
- return originals.finally.call(this, wrap(onFinally));
252
+ PatchedPromise.race = function (values) {
253
+ const p = originals.race.call(OriginalPromise, values);
254
+ const context = captureRestorers();
255
+ if (context.size > 0)
256
+ promiseContexts.set(p, context);
257
+ return p;
48
258
  };
259
+ PatchedPromise.any = function (values) {
260
+ const p = originals.any.call(OriginalPromise, values);
261
+ const context = captureRestorers();
262
+ if (context.size > 0)
263
+ promiseContexts.set(p, context);
264
+ return p;
265
+ };
266
+ // Only apply patches if not already applied (or re-apply safely)
267
+ // Note: OriginalPromise.prototype might be shared if we used the global one.
268
+ // We must ensure we don't patch it twice if it's the SAME object.
269
+ if (OriginalPromise.prototype.then !== patchedThen) {
270
+ OriginalPromise.prototype.then = patchedThen;
271
+ OriginalPromise.prototype.catch = patchedCatch;
272
+ OriginalPromise.prototype.finally = patchedFinally;
273
+ }
274
+ try {
275
+ Object.defineProperty(OriginalPromise, Symbol.species, {
276
+ get: () => PatchedPromise,
277
+ configurable: true
278
+ });
279
+ }
280
+ catch (e) { }
281
+ globalThis.Promise = PatchedPromise;
49
282
  globalThis.setTimeout = ((callback, ...args) => {
50
283
  return originals.setTimeout.call(globalThis, wrap(callback), ...args);
51
284
  });
@@ -67,4 +300,6 @@ if (originals.queueMicrotask) {
67
300
  originals.queueMicrotask.call(globalThis, wrap(callback));
68
301
  };
69
302
  }
303
+
304
+ export { asyncHooks };
70
305
  //# sourceMappingURL=browser.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"browser.esm.js","sources":["../src/async/browser.ts"],"sourcesContent":["import { Hook, Restorer, asyncHooks } from '.'\n\nconst hooks = new Set<Hook>()\n\nasyncHooks.addHook = function (hook: Hook) {\n\thooks.add(hook)\n\treturn () => {\n\t\thooks.delete(hook)\n\t}\n}\n\nexport * from '../index'\n\nfunction wrap<Args extends any[], R>(fn: ((...args: Args) => R) | null | undefined) {\n\tif (typeof fn !== 'function') return fn\n\tconst restorers = new Set<Restorer>()\n\tfor (const hook of hooks) restorers.add(hook())\n\n\treturn function (this: any, ...args: Args) {\n\t\tconst undoers = new Set<() => void>()\n\t\tfor (const restore of restorers) undoers.add(restore())\n\t\ttry {\n\t\t\treturn fn.apply(this, args)\n\t\t} finally {\n\t\t\tfor (const undo of undoers) undo()\n\t\t}\n\t}\n}\n\nconst originals = {\n\tthen: Promise.prototype.then,\n\tcatch: Promise.prototype.catch,\n\tfinally: Promise.prototype.finally,\n\tsetTimeout: globalThis.setTimeout,\n\tsetInterval: globalThis.setInterval,\n\tsetImmediate: globalThis.setImmediate,\n\trequestAnimationFrame: globalThis.requestAnimationFrame,\n\tqueueMicrotask: globalThis.queueMicrotask,\n}\n\nPromise.prototype.then = function <T, R1, R2>(\n\tthis: Promise<T>,\n\tonFulfilled?: ((value: T) => R1 | PromiseLike<R1>) | null,\n\tonRejected?: ((reason: any) => R2 | PromiseLike<R2>) | null\n): Promise<R1 | R2> {\n\treturn originals.then.call(this, wrap(onFulfilled), wrap(onRejected))\n}\n\nPromise.prototype.catch = function <T>(\n\tthis: Promise<T>,\n\tonRejected?: ((reason: any) => T | PromiseLike<T>) | null\n): Promise<T> {\n\treturn originals.catch.call(this, wrap(onRejected))\n}\n\nPromise.prototype.finally = function <T>(\n\tthis: Promise<T>,\n\tonFinally?: (() => void) | null\n): Promise<T> {\n\treturn originals.finally.call(this, wrap(onFinally))\n}\n\nglobalThis.setTimeout = ((callback: Function, ...args: any[]) => {\n\treturn originals.setTimeout.call(globalThis, wrap(callback as any), ...args)\n}) as any\n\nglobalThis.setInterval = ((callback: Function, ...args: any[]) => {\n\treturn originals.setInterval.call(globalThis, wrap(callback as any), ...args)\n}) as any\n\nif (originals.setImmediate) {\n\tglobalThis.setImmediate = ((callback: Function, ...args: any[]) => {\n\t\treturn originals.setImmediate.call(globalThis, wrap(callback as any), ...args)\n\t}) as any\n}\n\nif (originals.requestAnimationFrame) {\n\tglobalThis.requestAnimationFrame = (callback: FrameRequestCallback) => {\n\t\treturn originals.requestAnimationFrame.call(globalThis, wrap(callback))\n\t}\n}\n\nif (originals.queueMicrotask) {\n\tglobalThis.queueMicrotask = (callback: VoidFunction): void => {\n\t\toriginals.queueMicrotask.call(globalThis, wrap(callback))\n\t}\n}"],"names":[],"mappings":";;;AAEA,MAAM,KAAK,GAAG,IAAI,GAAG,EAAQ;AAE7B,UAAU,CAAC,OAAO,GAAG,UAAU,IAAU,EAAA;AACxC,IAAA,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;AACf,IAAA,OAAO,MAAK;AACX,QAAA,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC;AACnB,IAAA,CAAC;AACF,CAAC;AAID,SAAS,IAAI,CAAwB,EAA6C,EAAA;IACjF,IAAI,OAAO,EAAE,KAAK,UAAU;AAAE,QAAA,OAAO,EAAE;AACvC,IAAA,MAAM,SAAS,GAAG,IAAI,GAAG,EAAY;IACrC,KAAK,MAAM,IAAI,IAAI,KAAK;AAAE,QAAA,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IAE/C,OAAO,UAAqB,GAAG,IAAU,EAAA;AACxC,QAAA,MAAM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AC;AAED,UAAU,CAAC,UAAU,IAAI,CAAC,QAAkB,EAAE,GAAG,IAAW,KAAI;AAC/D,IAAA,OAAO,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,QAAe,CAAC,EAAE,GAAG,IAAI,CAAC;AAC7E,CAAC,CAAQ;AAET,UAAU,CAAC,WAAW,IAAI,CAAC,QAAkB,EAAE,GAAG,IAAW,KAAI;AAChE,IAAA,OAAO,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,QAAe,CAAC,EAAE,GAAG,IAAI,CAAC;AAC9E,CAAC,CAAQ;AAET,IAAI,SAAS,CAAC,YAAY,EAAE;IAC3B,UAAU,CAAC,YAAY,IAAI,CAAC,QAAkB,EAAE,GAAG,IAAW,KAAI;AACjE,QAAA,OAAO,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,QAAe,CAAC,EAAE,GAAG,IAAI,CAAC;AAC/E,IAAA,CAAC,CAAQ;AACV;AAEA,IAAI,SAAS,CAAC,qBAAqB,EAAE;AACpC,IAAA,UAAU,CAAC,qBAAqB,GAAG,CAAC,QAA8B,KAAI;AACrE,QAAA,OAAO,SAAS,CAAC,qBAAqB,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;AACxE,IAAA,CAAC;AACF;AAEA,IAAI,SAAS,CAAC,cAAc,EAAE;AAC7B,IAAA,UAAU,CAAC,cAAc,GAAG,CAAC,QAAsB,KAAU;AAC5D,QAAA,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC1D,IAAA,CAAC;AACF"}
1
+ {"version":3,"file":"browser.esm.js","sources":["../src/async/browser.ts"],"sourcesContent":["import { Hook, Restorer, asyncHooks } from '.'\n\nconst hooks = new Set<Hook>()\nconst promiseContexts = new WeakMap<Promise<any>, Set<Restorer>>()\n\nasyncHooks.addHook = function (hook: Hook) {\n\thooks.add(hook)\n\treturn () => {\n\t\thooks.delete(hook)\n\t}\n}\n\n// [HACK]: Sanitization\n// If a Promise is created inside the zone, it carries the \"Sticky\" zone context.\n// If returned to the outer scope, that context leaks. We wrap it in a new Promise\n// created here (in the outer scope) to break the chain and sanitize the return value.\n// See BROWSER_ASYNC_POLYFILL.md for full details.\nasyncHooks.sanitizePromise = (res: any) => {\n if (res && typeof (res as any).then === 'function') {\n return new Promise((resolve, reject) => {\n setTimeout(() => {\n (res as any).then(resolve, reject)\n }, 0)\n })\n }\n return res\n}\n\nfunction captureRestorers() {\n\tconst restorers = new Set<Restorer>()\n\tfor (const hook of hooks) {\n\t\tconst restorer = hook()\n\t\tif (restorer) restorers.add(restorer)\n\t}\n\treturn restorers\n}\n\nfunction wrap<Args extends any[], R>(fn: ((...args: Args) => R) | null | undefined, capturedRestorers?: Set<Restorer>) {\n\tif (typeof fn !== 'function') return fn\n\tconst restorers = capturedRestorers || captureRestorers()\n\treturn function (this: any, ...args: Args) {\n\t\tconst undoers: (() => void)[] = []\n\t\tfor (const restore of restorers) undoers.push(restore())\n\t\ttry {\n\t\t\treturn fn.apply(this, args)\n\t\t} finally {\n\t\t\tif (originals.queueMicrotask) {\n\t\t\t\t// Double microtask ensures we run after the first await resumption microtask\n\t\t\t\toriginals.queueMicrotask.call(globalThis, () => {\n\t\t\t\t\toriginals.queueMicrotask.call(globalThis, () => {\n\t\t\t\t\t\toriginals.queueMicrotask.call(globalThis, () => {\n\t\t\t\t\t\t\tfor (let i = undoers.length - 1; i >= 0; i--) undoers[i]()\n\t\t\t\t\t\t})\n\t\t\t\t\t})\n\t\t\t\t})\n\t\t\t} else {\n\t\t\t\tfor (let i = undoers.length - 1; i >= 0; i--) undoers[i]()\n\t\t\t}\n\t\t}\n\t}\n}\n\nconst targetWrappers = new WeakMap<any, Map<string, WeakMap<Function, Function>>>()\n\nfunction patchEventTarget(proto: any) {\n\tif (!proto || !proto.addEventListener || !proto.removeEventListener) return\n\tconst nativeAdd = proto.addEventListener\n\tconst nativeRemove = proto.removeEventListener\n\n\tproto.addEventListener = function (this: any, type: string, listener: any, options: any) {\n\t\tif (typeof listener !== 'function') {\n\t\t\treturn nativeAdd.call(this, type, listener, options)\n\t\t}\n\n\t\tlet types = targetWrappers.get(this)\n\t\tif (!types) {\n\t\t\ttypes = new Map()\n\t\t\ttargetWrappers.set(this, types)\n\t\t}\n\t\tlet listeners = types.get(type)\n\t\tif (!listeners) {\n\t\t\tlisteners = new WeakMap()\n\t\t\ttypes.set(type, listeners)\n\t\t}\n\n\t\tlet wrapped = listeners.get(listener)\n\t\tif (!wrapped) {\n\t\t\twrapped = wrap(listener)\n\t\t\tlisteners.set(listener, wrapped)\n\t\t}\n\t\t\n\t\treturn nativeAdd.call(this, type, wrapped, options)\n\t}\n\n\tproto.removeEventListener = function (this: any, type: string, listener: any, options: any) {\n\t\tif (typeof listener !== 'function') {\n\t\t\treturn nativeRemove.call(this, type, listener, options)\n\t\t}\n\n\t\tconst types = targetWrappers.get(this)\n\t\tif (types) {\n\t\t\tconst listeners = types.get(type)\n\t\t\tif (listeners) {\n\t\t\t\tconst wrapped = listeners.get(listener)\n\t\t\t\tif (wrapped) {\n\t\t\t\t\treturn nativeRemove.call(this, type, wrapped, options)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn nativeRemove.call(this, type, listener, options)\n\t}\n}\n\nfunction patchOnProperties(proto: any) {\n\tif (!proto) return\n\tfor (const prop of Object.getOwnPropertyNames(proto)) {\n\t\tif (prop.startsWith('on')) {\n\t\t\tconst desc = Object.getOwnPropertyDescriptor(proto, prop)\n\t\t\tif (desc && desc.set && desc.configurable) {\n\t\t\t\tconst nativeSet = desc.set\n\t\t\t\tObject.defineProperty(proto, prop, {\n\t\t\t\t\t...desc,\n\t\t\t\t\tset: function (this: any, fn: any) {\n\t\t\t\t\t\tnativeSet.call(this, wrap(fn))\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t}\n}\n\nif (typeof EventTarget !== 'undefined') {\n\tpatchEventTarget(EventTarget.prototype)\n}\n\nconst prototypesToPatch = [\n\ttypeof EventTarget !== 'undefined' && EventTarget.prototype,\n\ttypeof HTMLElement !== 'undefined' && HTMLElement.prototype,\n\ttypeof Window !== 'undefined' && Window.prototype,\n\ttypeof Document !== 'undefined' && Document.prototype,\n\ttypeof MessagePort !== 'undefined' && MessagePort.prototype,\n\ttypeof XMLHttpRequest !== 'undefined' && XMLHttpRequest.prototype,\n\ttypeof IDBRequest !== 'undefined' && IDBRequest.prototype,\n\ttypeof IDBTransaction !== 'undefined' && IDBTransaction.prototype,\n\ttypeof IDBDatabase !== 'undefined' && IDBDatabase.prototype,\n\ttypeof FileReader !== 'undefined' && FileReader.prototype,\n\ttypeof AbortSignal !== 'undefined' && AbortSignal.prototype,\n]\n\nfor (const proto of prototypesToPatch) {\n\tif (proto) {\n\t\tpatchOnProperties(proto)\n\t}\n}\n\nconst GLOBAL_ORIGINALS = Symbol.for('mutts.originals');\nconst GLOBAL_PROMISE = Symbol.for('mutts.OriginalPromise');\n\nlet originals: any;\nlet OriginalPromise: any;\n\nif ((globalThis as any)[GLOBAL_ORIGINALS]) {\n originals = (globalThis as any)[GLOBAL_ORIGINALS];\n OriginalPromise = (globalThis as any)[GLOBAL_PROMISE];\n} else {\n OriginalPromise = globalThis.Promise;\n originals = {\n then: OriginalPromise.prototype.then,\n catch: OriginalPromise.prototype.catch,\n finally: OriginalPromise.prototype.finally,\n resolve: OriginalPromise.resolve,\n reject: OriginalPromise.reject,\n all: OriginalPromise.all,\n allSettled: (OriginalPromise as any).allSettled,\n race: OriginalPromise.race,\n any: (OriginalPromise as any).any,\n setTimeout: globalThis.setTimeout,\n setInterval: globalThis.setInterval,\n setImmediate: (globalThis as any).setImmediate,\n requestAnimationFrame: (globalThis as any).requestAnimationFrame,\n queueMicrotask: globalThis.queueMicrotask,\n };\n (globalThis as any)[GLOBAL_ORIGINALS] = originals;\n (globalThis as any)[GLOBAL_PROMISE] = OriginalPromise;\n}\n\n// Ensure modern statics are captured even if originals was cached from an older version\nif (!originals.allSettled) originals.allSettled = (OriginalPromise as any).allSettled\nif (!originals.any) originals.any = (OriginalPromise as any).any\nif (!originals.race) originals.race = OriginalPromise.race\n\nfunction patchedThen(this: any, onFulfilled: any, onRejected: any) {\n\tconst context = promiseContexts.get(this) || captureRestorers()\n\tconst nextPromise = originals.then.call(this, wrap(onFulfilled, context), wrap(onRejected, context))\n\tif (context.size > 0) promiseContexts.set(nextPromise, context)\n\treturn nextPromise\n}\n\nfunction patchedCatch(this: any, onRejected: any) {\n\tconst context = promiseContexts.get(this) || captureRestorers()\n\tconst nextPromise = originals.catch.call(this, wrap(onRejected, context))\n\tif (context.size > 0) promiseContexts.set(nextPromise, context)\n\treturn nextPromise\n}\n\nfunction patchedFinally(this: any, onFinally: any) {\n\tconst context = promiseContexts.get(this) || captureRestorers()\n\tconst nextPromise = originals.finally.call(this, wrap(onFinally, context))\n\tif (context.size > 0) promiseContexts.set(nextPromise, context)\n\treturn nextPromise\n}\n\nfunction PatchedPromise<T>(this: any, executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void) {\n if (typeof executor === 'function') {\n const p = new OriginalPromise((resolve, reject) => {\n const wrappedResolve = wrap(resolve)\n const wrappedReject = wrap(reject)\n executor(wrappedResolve, wrappedReject)\n })\n const context = captureRestorers()\n promiseContexts.set(p, context) // Always set, even if empty (Sticky Root)\n return p\n }\n return new OriginalPromise(executor)\n}\n\n// Copy statics\nObject.assign(PatchedPromise, (OriginalPromise as any))\n\n// Inherit prototype for instanceof checks\nPatchedPromise.prototype = OriginalPromise.prototype\n\nPatchedPromise.resolve = function<T>(value?: T | PromiseLike<T>): Promise<T> {\n const p = originals.resolve.call(OriginalPromise, value) as Promise<T>\n const context = captureRestorers()\n // Ensure we don't overwrite if it already has context (e.g. from constructor)\n if (context.size > 0 && !promiseContexts.has(p)) promiseContexts.set(p, context)\n return p\n} as any\n\nPatchedPromise.reject = function<T = never>(reason?: any): Promise<T> {\n const p = originals.reject.call(OriginalPromise, reason) as Promise<T>\n const context = captureRestorers()\n if (context.size > 0) promiseContexts.set(p, context)\n return p\n} as any\n\nPatchedPromise.all = function<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]> {\n const p = originals.all.call(OriginalPromise, values) as Promise<Awaited<T>[]>\n const context = captureRestorers()\n if (context.size > 0) promiseContexts.set(p, context)\n return p\n} as any\n\nPatchedPromise.allSettled = function<T>(values: Iterable<T | PromiseLike<T>>): Promise<PromiseSettledResult<Awaited<T>>[]> {\n const p = (originals.allSettled as any).call(OriginalPromise, values)\n const context = captureRestorers()\n if (context.size > 0) promiseContexts.set(p, context)\n return p\n} as any\n\nPatchedPromise.race = function<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>> {\n const p = originals.race.call(OriginalPromise, values) as Promise<Awaited<T>>\n const context = captureRestorers()\n if (context.size > 0) promiseContexts.set(p, context)\n return p\n} as any\n\nPatchedPromise.any = function<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>> {\n const p = (originals.any as any).call(OriginalPromise, values)\n const context = captureRestorers()\n if (context.size > 0) promiseContexts.set(p, context)\n return p\n} as any\n\n// Only apply patches if not already applied (or re-apply safely)\n// Note: OriginalPromise.prototype might be shared if we used the global one.\n// We must ensure we don't patch it twice if it's the SAME object.\nif (OriginalPromise.prototype.then !== patchedThen) {\n OriginalPromise.prototype.then = patchedThen as any\n OriginalPromise.prototype.catch = patchedCatch as any\n OriginalPromise.prototype.finally = patchedFinally as any\n}\n\ntry {\n\tObject.defineProperty(OriginalPromise, Symbol.species, {\n\t\tget: () => PatchedPromise,\n\t\tconfigurable: true\n\t})\n} catch (e) {}\n\n;(globalThis as any).Promise = PatchedPromise\n\nglobalThis.setTimeout = ((callback: Function, ...args: any[]) => {\n\treturn originals.setTimeout.call(globalThis, wrap(callback as any), ...args)\n}) as any\n\nglobalThis.setInterval = ((callback: Function, ...args: any[]) => {\n\treturn originals.setInterval.call(globalThis, wrap(callback as any), ...args)\n}) as any\n\nif (originals.setImmediate) {\n\t;(globalThis as any).setImmediate = ((callback: Function, ...args: any[]) => {\n\t\treturn originals.setImmediate.call(globalThis, wrap(callback as any), ...args)\n\t}) as any\n}\n\nif (originals.requestAnimationFrame) {\n\tglobalThis.requestAnimationFrame = (callback: FrameRequestCallback) => {\n\t\treturn originals.requestAnimationFrame.call(globalThis, wrap(callback))\n\t}\n}\n\nif (originals.queueMicrotask) {\n\tglobalThis.queueMicrotask = (callback: VoidFunction): void => {\n\t\toriginals.queueMicrotask.call(globalThis, wrap(callback))\n\t}\n}\n"],"names":[],"mappings":";;;AAEA,MAAM,KAAK,GAAG,IAAI,GAAG,EAAQ;AAC7B,MAAM,eAAe,GAAG,IAAI,OAAO,EAA+B;AAElE,UAAU,CAAC,OAAO,GAAG,UAAU,IAAU,EAAA;AACxC,IAAA,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;AACf,IAAA,OAAO,MAAK;AACX,QAAA,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC;AACnB,IAAA,CAAC;AACF,CAAC;AAED;AACA;AACA;AACA;AACA;AACA,UAAU,CAAC,eAAe,GAAG,CAAC,GAAQ,KAAI;IACtC,IAAI,GAAG,IAAI,OAAQ,GAAW,CAAC,IAAI,KAAK,UAAU,EAAE;QAChD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAI;YACnC,UAAU,CAAC,MAAK;AACX,gBAAA,GAAW,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC;YACtC,CAAC,EAAE,CAAC,CAAC;AACT,QAAA,CAAC,CAAC;IACN;AACA,IAAA,OAAO,GAAG;AACd,CAAC;AAED,SAAS,gBAAgB,GAAA;AACxB,IAAA,MAAM,SAAS,GAAG,IAAI,GAAG,EAAY;AACrC,IAAA,KAAK,MAAM,IAAI,IAAI,KA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