@but212/atom-effect-jquery 0.10.0 → 0.11.0
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.
- package/dist/atom-effect-jquery.min.js +1 -1
- package/dist/atom-effect-jquery.min.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -30
- package/dist/index.mjs +703 -588
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import u from "jquery";
|
|
2
|
-
import { default as
|
|
3
|
-
const
|
|
2
|
+
import { default as Ot } from "jquery";
|
|
3
|
+
const Be = {
|
|
4
4
|
/** One second in milliseconds */
|
|
5
5
|
ONE_SECOND_MS: 1e3
|
|
6
|
-
},
|
|
6
|
+
}, ue = {
|
|
7
7
|
IDLE: "idle",
|
|
8
8
|
PENDING: "pending",
|
|
9
9
|
RESOLVED: "resolved",
|
|
10
10
|
REJECTED: "rejected"
|
|
11
|
-
},
|
|
11
|
+
}, te = {
|
|
12
12
|
DISPOSED: 1,
|
|
13
13
|
// 0001 - Effect has been disposed
|
|
14
14
|
EXECUTING: 2
|
|
@@ -28,7 +28,10 @@ const Ve = {
|
|
|
28
28
|
// 100000 - Currently recomputing
|
|
29
29
|
HAS_ERROR: 64
|
|
30
30
|
// 1000000 - Has error state
|
|
31
|
-
},
|
|
31
|
+
}, Y = {
|
|
32
|
+
SYNC: 1,
|
|
33
|
+
NOTIFICATION_SCHEDULED: 2
|
|
34
|
+
}, z = {
|
|
32
35
|
/** Maximum effect executions per second to detect infinite loops (Legacy/Fallback) */
|
|
33
36
|
MAX_EXECUTIONS_PER_SECOND: 1e3,
|
|
34
37
|
/**
|
|
@@ -45,13 +48,13 @@ const Ve = {
|
|
|
45
48
|
MAX_FLUSH_ITERATIONS: 1e3,
|
|
46
49
|
/** Minimum allowed value for max flush iterations */
|
|
47
50
|
MIN_FLUSH_ITERATIONS: 10
|
|
48
|
-
},
|
|
51
|
+
}, De = {
|
|
49
52
|
/** Maximum dependencies before warning about large dependency graphs */
|
|
50
53
|
MAX_DEPENDENCIES: 1e3,
|
|
51
54
|
/** Enable infinite loop detection warnings */
|
|
52
55
|
WARN_INFINITE_LOOP: !0
|
|
53
|
-
},
|
|
54
|
-
class
|
|
56
|
+
}, V = 1073741823, _e = 1 << 19, v = typeof process < "u" && process.env && process.env.NODE_ENV !== "production", qe = Object.freeze([]);
|
|
57
|
+
class w extends Error {
|
|
55
58
|
/**
|
|
56
59
|
* Creates a new AtomError
|
|
57
60
|
* @param message - Error message describing what went wrong
|
|
@@ -62,7 +65,7 @@ class k extends Error {
|
|
|
62
65
|
super(e), this.name = "AtomError", this.cause = s, this.recoverable = n, this.timestamp = /* @__PURE__ */ new Date();
|
|
63
66
|
}
|
|
64
67
|
}
|
|
65
|
-
class
|
|
68
|
+
class q extends w {
|
|
66
69
|
/**
|
|
67
70
|
* Creates a new ComputedError
|
|
68
71
|
* @param message - Error message
|
|
@@ -72,7 +75,7 @@ class z extends k {
|
|
|
72
75
|
super(e, s, !0), this.name = "ComputedError";
|
|
73
76
|
}
|
|
74
77
|
}
|
|
75
|
-
class
|
|
78
|
+
class B extends w {
|
|
76
79
|
/**
|
|
77
80
|
* Creates a new EffectError
|
|
78
81
|
* @param message - Error message
|
|
@@ -82,7 +85,7 @@ class V extends k {
|
|
|
82
85
|
super(e, s, !1), this.name = "EffectError";
|
|
83
86
|
}
|
|
84
87
|
}
|
|
85
|
-
class
|
|
88
|
+
class se extends w {
|
|
86
89
|
/**
|
|
87
90
|
* Creates a new SchedulerError
|
|
88
91
|
* @param message - Error message
|
|
@@ -92,7 +95,7 @@ class Z extends k {
|
|
|
92
95
|
super(e, s, !1), this.name = "SchedulerError";
|
|
93
96
|
}
|
|
94
97
|
}
|
|
95
|
-
const
|
|
98
|
+
const g = {
|
|
96
99
|
// ─────────────────────────────────────────────────────────────────
|
|
97
100
|
// Computed errors
|
|
98
101
|
// ─────────────────────────────────────────────────────────────────
|
|
@@ -144,28 +147,28 @@ const y = {
|
|
|
144
147
|
* @remarks This prevents cascading failures from masking the original error.
|
|
145
148
|
*/
|
|
146
149
|
CALLBACK_ERROR_IN_ERROR_HANDLER: "Error occurred during onError callback execution"
|
|
147
|
-
},
|
|
148
|
-
function
|
|
150
|
+
}, fe = /* @__PURE__ */ Symbol("debugName"), ze = /* @__PURE__ */ Symbol("id"), de = /* @__PURE__ */ Symbol("type"), Ie = /* @__PURE__ */ Symbol("noDefaultValue");
|
|
151
|
+
function Qe(t) {
|
|
149
152
|
return "dependencies" in t && Array.isArray(t.dependencies);
|
|
150
153
|
}
|
|
151
|
-
let
|
|
152
|
-
function
|
|
154
|
+
let Ce = 0;
|
|
155
|
+
function Re(t, e, s) {
|
|
153
156
|
if (t._visitedEpoch !== s) {
|
|
154
157
|
if (t._visitedEpoch = s, t === e)
|
|
155
|
-
throw new
|
|
156
|
-
if (
|
|
158
|
+
throw new q("Indirect circular dependency detected");
|
|
159
|
+
if (Qe(t)) {
|
|
157
160
|
const n = t.dependencies;
|
|
158
161
|
for (let i = 0; i < n.length; i++) {
|
|
159
162
|
const r = n[i];
|
|
160
|
-
r &&
|
|
163
|
+
r && Re(r, e, s);
|
|
161
164
|
}
|
|
162
165
|
}
|
|
163
166
|
}
|
|
164
167
|
}
|
|
165
|
-
const
|
|
168
|
+
const R = {
|
|
166
169
|
enabled: typeof process < "u" && process.env?.NODE_ENV === "development",
|
|
167
|
-
maxDependencies:
|
|
168
|
-
warnInfiniteLoop:
|
|
170
|
+
maxDependencies: De.MAX_DEPENDENCIES,
|
|
171
|
+
warnInfiniteLoop: De.WARN_INFINITE_LOOP,
|
|
169
172
|
warn(t, e) {
|
|
170
173
|
this.enabled && t && console.warn(`[Atom Effect] ${e}`);
|
|
171
174
|
},
|
|
@@ -176,34 +179,73 @@ const A = {
|
|
|
176
179
|
*/
|
|
177
180
|
checkCircular(t, e) {
|
|
178
181
|
if (t === e)
|
|
179
|
-
throw new
|
|
180
|
-
this.enabled && (
|
|
182
|
+
throw new q("Direct circular dependency detected");
|
|
183
|
+
this.enabled && (Ce++, Re(t, e, Ce));
|
|
181
184
|
},
|
|
182
185
|
attachDebugInfo(t, e, s) {
|
|
183
186
|
if (!this.enabled)
|
|
184
187
|
return;
|
|
185
188
|
const n = t;
|
|
186
|
-
n[
|
|
189
|
+
n[fe] = `${e}_${s}`, n[ze] = s, n[de] = e;
|
|
187
190
|
},
|
|
188
191
|
getDebugName(t) {
|
|
189
|
-
if (t != null &&
|
|
190
|
-
return t[
|
|
192
|
+
if (t != null && fe in t)
|
|
193
|
+
return t[fe];
|
|
191
194
|
},
|
|
192
195
|
getDebugType(t) {
|
|
193
|
-
if (t != null &&
|
|
194
|
-
return t[
|
|
196
|
+
if (t != null && de in t)
|
|
197
|
+
return t[de];
|
|
195
198
|
}
|
|
196
199
|
};
|
|
197
|
-
let
|
|
198
|
-
const
|
|
199
|
-
class
|
|
200
|
+
let Xe = 1;
|
|
201
|
+
const Ge = () => Xe++;
|
|
202
|
+
class xe {
|
|
200
203
|
constructor() {
|
|
201
|
-
this.id =
|
|
204
|
+
this.id = Ge() & V, this.flags = 0, this.version = 0;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Rotates the phase by 1, automatically incrementing cycle on overflow.
|
|
208
|
+
*
|
|
209
|
+
* Performance Benefits:
|
|
210
|
+
* - Branchless: No conditional statements
|
|
211
|
+
* - O(1): Single bitwise AND operation
|
|
212
|
+
* - Smi-safe: Result always within 30-bit range (0x3fffffff)
|
|
213
|
+
*
|
|
214
|
+
* When Phase reaches 0xfffff (1,048,575), the next increment:
|
|
215
|
+
* - Overflows into Cycle bits
|
|
216
|
+
* - Phase resets to 0
|
|
217
|
+
* - Cycle increments by 1
|
|
218
|
+
*
|
|
219
|
+
* @returns The new version after phase rotation
|
|
220
|
+
*/
|
|
221
|
+
rotatePhase() {
|
|
222
|
+
return this.version = this.version + 1 & V, this.version;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Calculates the logical distance (shift) between current and cached version.
|
|
226
|
+
*
|
|
227
|
+
* Uses modular arithmetic to handle cycle wraparound correctly.
|
|
228
|
+
* The result represents how many phase rotations have occurred since
|
|
229
|
+
* the cached version was recorded.
|
|
230
|
+
*
|
|
231
|
+
* Performance Benefits:
|
|
232
|
+
* - Branchless: Single subtraction with mask
|
|
233
|
+
* - Handles wraparound: Works correctly even when version overflows
|
|
234
|
+
*
|
|
235
|
+
* Use Cases:
|
|
236
|
+
* - Scheduler priority: Large shifts indicate stale updates
|
|
237
|
+
* - Dependency staleness: Detect how outdated a cached value is
|
|
238
|
+
*
|
|
239
|
+
* @param cachedVersion - The previously cached version to compare against
|
|
240
|
+
* @returns Non-negative shift distance (0 to 0x3fffffff)
|
|
241
|
+
*/
|
|
242
|
+
getShift(e) {
|
|
243
|
+
return this.version - e & V;
|
|
202
244
|
}
|
|
203
245
|
}
|
|
204
|
-
class
|
|
246
|
+
class Ue extends xe {
|
|
205
247
|
constructor() {
|
|
206
|
-
super(), this.
|
|
248
|
+
super(), this._lastSeenEpoch = -1;
|
|
207
249
|
}
|
|
208
250
|
/**
|
|
209
251
|
* Subscribes a listener function or Subscriber object to value changes.
|
|
@@ -216,7 +258,7 @@ class ve extends Ce {
|
|
|
216
258
|
if (typeof e == "object" && e !== null && "execute" in e)
|
|
217
259
|
return this._objectSubscribers.add(e);
|
|
218
260
|
if (typeof e != "function")
|
|
219
|
-
throw new
|
|
261
|
+
throw new w(g.ATOM_SUBSCRIBER_MUST_BE_FUNCTION);
|
|
220
262
|
return this._functionSubscribers.add(e);
|
|
221
263
|
}
|
|
222
264
|
/**
|
|
@@ -234,68 +276,98 @@ class ve extends Ce {
|
|
|
234
276
|
_notifySubscribers(e, s) {
|
|
235
277
|
this._functionSubscribers.forEachSafe(
|
|
236
278
|
(n) => n(e, s),
|
|
237
|
-
(n) => console.error(new
|
|
279
|
+
(n) => console.error(new w(g.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED, n))
|
|
238
280
|
), this._objectSubscribers.forEachSafe(
|
|
239
281
|
(n) => n.execute(),
|
|
240
|
-
(n) => console.error(new
|
|
282
|
+
(n) => console.error(new w(g.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED, n))
|
|
241
283
|
);
|
|
242
284
|
}
|
|
243
285
|
}
|
|
244
|
-
let
|
|
245
|
-
function
|
|
246
|
-
return
|
|
286
|
+
let ne = 0;
|
|
287
|
+
function Oe() {
|
|
288
|
+
return ne = ne + 1 & V || 1, ne;
|
|
247
289
|
}
|
|
248
|
-
function
|
|
249
|
-
return
|
|
290
|
+
function He() {
|
|
291
|
+
return ne;
|
|
250
292
|
}
|
|
251
|
-
let
|
|
252
|
-
function
|
|
253
|
-
return
|
|
293
|
+
let re = 0, be = 0, oe = !1;
|
|
294
|
+
function ve() {
|
|
295
|
+
return oe ? (v && console.warn(
|
|
254
296
|
"Warning: startFlush() called during flush - ignored to prevent infinite loop detection bypass"
|
|
255
|
-
), !1) : (
|
|
297
|
+
), !1) : (oe = !0, re = re + 1 & V, be = 0, !0);
|
|
256
298
|
}
|
|
257
|
-
function
|
|
258
|
-
|
|
299
|
+
function Te() {
|
|
300
|
+
oe = !1;
|
|
259
301
|
}
|
|
260
|
-
function
|
|
261
|
-
return
|
|
302
|
+
function Ye() {
|
|
303
|
+
return oe ? ++be : 0;
|
|
262
304
|
}
|
|
263
|
-
class
|
|
305
|
+
class Je {
|
|
264
306
|
constructor() {
|
|
265
|
-
this.queueA = [], this.queueB = [], this.queue = this.queueA, this.queueSize = 0, this._epoch = 0, this.isProcessing = !1, this.isBatching = !1, this.batchDepth = 0, this.batchQueue = [], this.batchQueueSize = 0, this.isFlushingSync = !1, this.maxFlushIterations =
|
|
307
|
+
this.queueA = [], this.queueB = [], this.queue = this.queueA, this.queueSize = 0, this.urgentQueueA = [], this.urgentQueueB = [], this.urgentQueue = this.urgentQueueA, this.urgentQueueSize = 0, this._epoch = 0, this.isProcessing = !1, this.isBatching = !1, this.batchDepth = 0, this.batchQueue = [], this.batchQueueSize = 0, this.isFlushingSync = !1, this.maxFlushIterations = z.MAX_FLUSH_ITERATIONS;
|
|
266
308
|
}
|
|
267
309
|
get phase() {
|
|
268
310
|
return this.isProcessing || this.isFlushingSync ? 2 : this.isBatching ? 1 : 0;
|
|
269
311
|
}
|
|
270
312
|
/**
|
|
271
|
-
* Schedules a task for execution.
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
*
|
|
313
|
+
* Schedules a task for execution with optional priority based on phase shift.
|
|
314
|
+
*
|
|
315
|
+
* Priority Calculation (Branchless):
|
|
316
|
+
* - If sourceNode and cachedVersion are provided, calculates shift
|
|
317
|
+
* - Jobs with shift >= PHASE_THRESHOLD go to urgentQueue
|
|
318
|
+
* - Uses branchless bit manipulation: ((shift - THRESHOLD) >>> 31) ^ 1
|
|
319
|
+
*
|
|
320
|
+
* @param callback - The function to execute
|
|
321
|
+
* @param sourceNode - Optional reactive node for shift calculation
|
|
322
|
+
* @throws {SchedulerError} If the callback is not a function
|
|
275
323
|
*/
|
|
276
|
-
schedule(e) {
|
|
324
|
+
schedule(e, s) {
|
|
277
325
|
if (typeof e != "function")
|
|
278
|
-
throw new
|
|
279
|
-
|
|
326
|
+
throw new se("Scheduler callback must be a function");
|
|
327
|
+
if (e._nextEpoch !== this._epoch)
|
|
328
|
+
if (e._nextEpoch = this._epoch, this.isBatching || this.isFlushingSync)
|
|
329
|
+
this.batchQueue[this.batchQueueSize++] = e;
|
|
330
|
+
else {
|
|
331
|
+
const n = this._calculateUrgency(e, s);
|
|
332
|
+
this.urgentQueue[this.urgentQueueSize] = e, this.queue[this.queueSize] = e, this.urgentQueueSize += n, this.queueSize += n ^ 1, this.isProcessing || this.flush();
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Calculates urgency flag using branchless bit manipulation.
|
|
337
|
+
*
|
|
338
|
+
* Formula: ((shift - PHASE_THRESHOLD) >>> 31) ^ 1
|
|
339
|
+
* - If shift >= THRESHOLD: (negative >>> 31) = 0, XOR 1 = 1 (urgent)
|
|
340
|
+
* - If shift < THRESHOLD: (positive >>> 31) = 0... wait, that's wrong
|
|
341
|
+
*
|
|
342
|
+
* Correct formula: (shift >= THRESHOLD) ? 1 : 0
|
|
343
|
+
* Branchless: ((PHASE_THRESHOLD - 1 - shift) >>> 31)
|
|
344
|
+
*
|
|
345
|
+
* @returns 1 if urgent, 0 if normal
|
|
346
|
+
*/
|
|
347
|
+
_calculateUrgency(e, s) {
|
|
348
|
+
if (!s || e._cachedVersion === void 0)
|
|
349
|
+
return 0;
|
|
350
|
+
const n = s.getShift(e._cachedVersion);
|
|
351
|
+
return _e - 1 - n >>> 31 & 1;
|
|
280
352
|
}
|
|
281
353
|
flush() {
|
|
282
|
-
this.isProcessing || this.queueSize === 0 || (this.isProcessing = !0, queueMicrotask(() => {
|
|
354
|
+
this.isProcessing || this.queueSize === 0 && this.urgentQueueSize === 0 || (this.isProcessing = !0, queueMicrotask(() => {
|
|
283
355
|
try {
|
|
284
|
-
if (this.queueSize === 0) return;
|
|
285
|
-
const e =
|
|
286
|
-
this._drainQueue(), e &&
|
|
356
|
+
if (this.queueSize === 0 && this.urgentQueueSize === 0) return;
|
|
357
|
+
const e = ve();
|
|
358
|
+
this._drainQueue(), e && Te();
|
|
287
359
|
} finally {
|
|
288
|
-
this.isProcessing = !1, this.queueSize > 0 && !this.isBatching && this.flush();
|
|
360
|
+
this.isProcessing = !1, (this.queueSize > 0 || this.urgentQueueSize > 0) && !this.isBatching && this.flush();
|
|
289
361
|
}
|
|
290
362
|
}));
|
|
291
363
|
}
|
|
292
364
|
flushSync() {
|
|
293
365
|
this.isFlushingSync = !0;
|
|
294
|
-
const e =
|
|
366
|
+
const e = ve();
|
|
295
367
|
try {
|
|
296
368
|
this._mergeBatchQueue(), this._drainQueue();
|
|
297
369
|
} finally {
|
|
298
|
-
this.isFlushingSync = !1, e &&
|
|
370
|
+
this.isFlushingSync = !1, e && Te();
|
|
299
371
|
}
|
|
300
372
|
}
|
|
301
373
|
_mergeBatchQueue() {
|
|
@@ -307,26 +379,44 @@ class Qe {
|
|
|
307
379
|
this.batchQueueSize = 0;
|
|
308
380
|
}
|
|
309
381
|
}
|
|
382
|
+
/**
|
|
383
|
+
* Drains all queues, processing urgent queue completely first.
|
|
384
|
+
*
|
|
385
|
+
* Processing Order:
|
|
386
|
+
* 1. Process all urgent jobs (high phase shift = stale updates)
|
|
387
|
+
* 2. Process normal jobs
|
|
388
|
+
* 3. Repeat until both queues are empty
|
|
389
|
+
*
|
|
390
|
+
* This ordering reduces glitches by ensuring that the most
|
|
391
|
+
* impactful state changes are propagated first.
|
|
392
|
+
*/
|
|
310
393
|
_drainQueue() {
|
|
311
394
|
let e = 0;
|
|
312
|
-
for (; this.queueSize > 0; ) {
|
|
395
|
+
for (; this.urgentQueueSize > 0 || this.queueSize > 0; ) {
|
|
313
396
|
if (++e > this.maxFlushIterations) {
|
|
314
397
|
this._handleFlushOverflow();
|
|
315
398
|
break;
|
|
316
399
|
}
|
|
317
|
-
this._processCurrentQueue(), this._mergeBatchQueue();
|
|
400
|
+
this.urgentQueueSize > 0 && this._processUrgentQueue(), this.queueSize > 0 && this._processCurrentQueue(), this._mergeBatchQueue();
|
|
318
401
|
}
|
|
319
402
|
}
|
|
403
|
+
/**
|
|
404
|
+
* Processes the urgent queue using double-buffering.
|
|
405
|
+
*/
|
|
406
|
+
_processUrgentQueue() {
|
|
407
|
+
const e = this.urgentQueue, s = this.urgentQueueSize;
|
|
408
|
+
this.urgentQueue = this.urgentQueue === this.urgentQueueA ? this.urgentQueueB : this.urgentQueueA, this.urgentQueueSize = 0, this._epoch++, this._processJobs(e, s);
|
|
409
|
+
}
|
|
320
410
|
_processCurrentQueue() {
|
|
321
411
|
const e = this.queue, s = this.queueSize;
|
|
322
412
|
this.queue = this.queue === this.queueA ? this.queueB : this.queueA, this.queueSize = 0, this._epoch++, this._processJobs(e, s);
|
|
323
413
|
}
|
|
324
414
|
_handleFlushOverflow() {
|
|
325
415
|
console.error(
|
|
326
|
-
new
|
|
416
|
+
new se(
|
|
327
417
|
`Maximum flush iterations (${this.maxFlushIterations}) exceeded. Possible infinite loop.`
|
|
328
418
|
)
|
|
329
|
-
), this.queueSize = 0, this.queue.length = 0, this.batchQueueSize = 0;
|
|
419
|
+
), this.queueSize = 0, this.queue.length = 0, this.urgentQueueSize = 0, this.urgentQueue.length = 0, this.batchQueueSize = 0;
|
|
330
420
|
}
|
|
331
421
|
_processJobs(e, s) {
|
|
332
422
|
for (let n = 0; n < s; n++)
|
|
@@ -334,7 +424,7 @@ class Qe {
|
|
|
334
424
|
e[n]?.();
|
|
335
425
|
} catch (i) {
|
|
336
426
|
console.error(
|
|
337
|
-
new
|
|
427
|
+
new se("Error occurred during scheduler execution", i)
|
|
338
428
|
);
|
|
339
429
|
}
|
|
340
430
|
e.length = 0;
|
|
@@ -355,25 +445,25 @@ class Qe {
|
|
|
355
445
|
* @param max - Maximum iterations count.
|
|
356
446
|
*/
|
|
357
447
|
setMaxFlushIterations(e) {
|
|
358
|
-
if (e <
|
|
359
|
-
throw new
|
|
360
|
-
`Max flush iterations must be at least ${
|
|
448
|
+
if (e < z.MIN_FLUSH_ITERATIONS)
|
|
449
|
+
throw new se(
|
|
450
|
+
`Max flush iterations must be at least ${z.MIN_FLUSH_ITERATIONS}`
|
|
361
451
|
);
|
|
362
452
|
this.maxFlushIterations = e;
|
|
363
453
|
}
|
|
364
454
|
}
|
|
365
|
-
const
|
|
366
|
-
function
|
|
455
|
+
const Z = new Je();
|
|
456
|
+
function Ke(t) {
|
|
367
457
|
if (typeof t != "function")
|
|
368
|
-
throw new
|
|
369
|
-
|
|
458
|
+
throw new w("Batch callback must be a function");
|
|
459
|
+
Z.startBatch();
|
|
370
460
|
try {
|
|
371
461
|
return t();
|
|
372
462
|
} finally {
|
|
373
|
-
|
|
463
|
+
Z.endBatch();
|
|
374
464
|
}
|
|
375
465
|
}
|
|
376
|
-
class
|
|
466
|
+
class We {
|
|
377
467
|
constructor() {
|
|
378
468
|
this.current = null;
|
|
379
469
|
}
|
|
@@ -400,19 +490,19 @@ class Je {
|
|
|
400
490
|
return this.current;
|
|
401
491
|
}
|
|
402
492
|
}
|
|
403
|
-
const
|
|
404
|
-
function
|
|
493
|
+
const X = new We();
|
|
494
|
+
function we(t) {
|
|
405
495
|
if (typeof t != "function")
|
|
406
|
-
throw new
|
|
407
|
-
const e =
|
|
408
|
-
|
|
496
|
+
throw new w("Untracked callback must be a function");
|
|
497
|
+
const e = X.current;
|
|
498
|
+
X.current = null;
|
|
409
499
|
try {
|
|
410
500
|
return t();
|
|
411
501
|
} finally {
|
|
412
|
-
|
|
502
|
+
X.current = e;
|
|
413
503
|
}
|
|
414
504
|
}
|
|
415
|
-
class
|
|
505
|
+
class ce {
|
|
416
506
|
constructor() {
|
|
417
507
|
this.subscribers = null;
|
|
418
508
|
}
|
|
@@ -468,9 +558,9 @@ class ie {
|
|
|
468
558
|
return this.subscribers ? [...this.subscribers] : [];
|
|
469
559
|
}
|
|
470
560
|
}
|
|
471
|
-
class
|
|
561
|
+
class Ee {
|
|
472
562
|
constructor() {
|
|
473
|
-
this.pool = [], this.maxPoolSize = 50, this.maxReusableCapacity = 256, this.stats =
|
|
563
|
+
this.pool = [], this.maxPoolSize = 50, this.maxReusableCapacity = 256, this.stats = v ? {
|
|
474
564
|
acquired: 0,
|
|
475
565
|
released: 0,
|
|
476
566
|
rejected: { frozen: 0, tooLarge: 0, poolFull: 0 }
|
|
@@ -478,7 +568,7 @@ class fe {
|
|
|
478
568
|
}
|
|
479
569
|
/** Acquires an array from the pool or creates a new one if the pool is empty. */
|
|
480
570
|
acquire() {
|
|
481
|
-
return
|
|
571
|
+
return v && this.stats && this.stats.acquired++, this.pool.pop() ?? [];
|
|
482
572
|
}
|
|
483
573
|
/**
|
|
484
574
|
* Releases an array back to the pool.
|
|
@@ -489,23 +579,23 @@ class fe {
|
|
|
489
579
|
release(e, s) {
|
|
490
580
|
if (!(s && e === s)) {
|
|
491
581
|
if (Object.isFrozen(e)) {
|
|
492
|
-
|
|
582
|
+
v && this.stats && this.stats.rejected.frozen++;
|
|
493
583
|
return;
|
|
494
584
|
}
|
|
495
585
|
if (e.length > this.maxReusableCapacity) {
|
|
496
|
-
|
|
586
|
+
v && this.stats && this.stats.rejected.tooLarge++;
|
|
497
587
|
return;
|
|
498
588
|
}
|
|
499
589
|
if (this.pool.length >= this.maxPoolSize) {
|
|
500
|
-
|
|
590
|
+
v && this.stats && this.stats.rejected.poolFull++;
|
|
501
591
|
return;
|
|
502
592
|
}
|
|
503
|
-
e.length = 0, this.pool.push(e),
|
|
593
|
+
e.length = 0, this.pool.push(e), v && this.stats && this.stats.released++;
|
|
504
594
|
}
|
|
505
595
|
}
|
|
506
596
|
/** Returns current stats for the pool (dev mode only). */
|
|
507
597
|
getStats() {
|
|
508
|
-
if (!
|
|
598
|
+
if (!v || !this.stats) return null;
|
|
509
599
|
const { acquired: e, released: s, rejected: n } = this.stats, i = n.frozen + n.tooLarge + n.poolFull;
|
|
510
600
|
return {
|
|
511
601
|
acquired: e,
|
|
@@ -517,142 +607,145 @@ class fe {
|
|
|
517
607
|
}
|
|
518
608
|
/** Resets the pool and its stats. */
|
|
519
609
|
reset() {
|
|
520
|
-
this.pool.length = 0,
|
|
610
|
+
this.pool.length = 0, v && this.stats && (this.stats.acquired = 0, this.stats.released = 0, this.stats.rejected = { frozen: 0, tooLarge: 0, poolFull: 0 });
|
|
521
611
|
}
|
|
522
612
|
}
|
|
523
|
-
const S = Object.freeze([]),
|
|
524
|
-
function
|
|
613
|
+
const S = Object.freeze([]), A = Object.freeze([]), y = Object.freeze([]), F = new Ee(), Q = new Ee(), N = new Ee();
|
|
614
|
+
function pe(t) {
|
|
525
615
|
return t !== null && typeof t == "object" && "value" in t && "subscribe" in t && typeof t.subscribe == "function";
|
|
526
616
|
}
|
|
527
|
-
function
|
|
528
|
-
if (
|
|
529
|
-
const e =
|
|
617
|
+
function Ae(t) {
|
|
618
|
+
if (R.enabled && (t == null || typeof t == "object")) {
|
|
619
|
+
const e = R.getDebugType(t);
|
|
530
620
|
if (e)
|
|
531
621
|
return e === "computed";
|
|
532
622
|
}
|
|
533
|
-
return
|
|
623
|
+
return pe(t) && "invalidate" in t && typeof t.invalidate == "function";
|
|
534
624
|
}
|
|
535
|
-
function
|
|
625
|
+
function ke(t) {
|
|
536
626
|
return t != null && typeof t.then == "function";
|
|
537
627
|
}
|
|
538
|
-
function
|
|
628
|
+
function Ze(t) {
|
|
539
629
|
return typeof t == "object" && t !== null;
|
|
540
630
|
}
|
|
541
|
-
function
|
|
631
|
+
function et(t) {
|
|
542
632
|
return (typeof t == "object" || typeof t == "function") && t !== null && typeof t.addDependency == "function";
|
|
543
633
|
}
|
|
544
|
-
function
|
|
634
|
+
function tt(t) {
|
|
545
635
|
return typeof t == "function" && typeof t.addDependency != "function";
|
|
546
636
|
}
|
|
547
|
-
function
|
|
548
|
-
return
|
|
637
|
+
function st(t) {
|
|
638
|
+
return Ze(t) && typeof t.execute == "function";
|
|
549
639
|
}
|
|
550
|
-
function
|
|
640
|
+
function Fe(t, e, s, n) {
|
|
551
641
|
if (e) {
|
|
552
|
-
if (
|
|
642
|
+
if (et(e)) {
|
|
553
643
|
e.addDependency(t);
|
|
554
644
|
return;
|
|
555
645
|
}
|
|
556
|
-
if (
|
|
646
|
+
if (tt(e)) {
|
|
557
647
|
s.add(e);
|
|
558
648
|
return;
|
|
559
649
|
}
|
|
560
|
-
|
|
650
|
+
st(e) && n.add(e);
|
|
561
651
|
}
|
|
562
652
|
}
|
|
563
|
-
function
|
|
564
|
-
if (e !== S && s !==
|
|
653
|
+
function nt(t, e, s, n) {
|
|
654
|
+
if (e !== S && s !== A)
|
|
565
655
|
for (let r = 0; r < e.length; r++) {
|
|
566
656
|
const o = e[r];
|
|
567
657
|
o && (o._tempUnsub = s[r]);
|
|
568
658
|
}
|
|
569
|
-
const i =
|
|
659
|
+
const i = Q.acquire();
|
|
570
660
|
i.length = t.length;
|
|
571
661
|
for (let r = 0; r < t.length; r++) {
|
|
572
662
|
const o = t[r];
|
|
573
|
-
o && (o._tempUnsub ? (i[r] = o._tempUnsub, o._tempUnsub = void 0) : (
|
|
663
|
+
o && (o._tempUnsub ? (i[r] = o._tempUnsub, o._tempUnsub = void 0) : (R.checkCircular(o, n), i[r] = o.subscribe(n)));
|
|
574
664
|
}
|
|
575
665
|
if (e !== S)
|
|
576
666
|
for (let r = 0; r < e.length; r++) {
|
|
577
667
|
const o = e[r];
|
|
578
668
|
o?._tempUnsub && (o._tempUnsub(), o._tempUnsub = void 0);
|
|
579
669
|
}
|
|
580
|
-
return s !==
|
|
670
|
+
return s !== A && Q.release(s), i;
|
|
581
671
|
}
|
|
582
|
-
class
|
|
672
|
+
class it extends Ue {
|
|
583
673
|
constructor(e, s) {
|
|
584
|
-
super(), this.
|
|
674
|
+
super(), this._functionSubscribersStore = null, this._objectSubscribersStore = null, this._value = e, s && (this.flags |= Y.SYNC), R.attachDebugInfo(this, "atom", this.id);
|
|
585
675
|
}
|
|
586
|
-
/** Gets the manager for function-based subscribers. */
|
|
587
676
|
get _functionSubscribers() {
|
|
588
|
-
return this._functionSubscribersStore;
|
|
677
|
+
return this._functionSubscribersStore || (this._functionSubscribersStore = new ce()), this._functionSubscribersStore;
|
|
589
678
|
}
|
|
590
|
-
/** Gets the manager for object-based subscribers. */
|
|
591
679
|
get _objectSubscribers() {
|
|
592
|
-
return this._objectSubscribersStore;
|
|
680
|
+
return this._objectSubscribersStore || (this._objectSubscribersStore = new ce()), this._objectSubscribersStore;
|
|
593
681
|
}
|
|
594
682
|
/**
|
|
595
|
-
* Returns the current value and registers the atom as a dependency in
|
|
683
|
+
* Returns the current value and registers the atom as a dependency if in a tracking context.
|
|
596
684
|
*/
|
|
597
685
|
get value() {
|
|
598
|
-
const e =
|
|
599
|
-
return e && this.
|
|
686
|
+
const e = X.current;
|
|
687
|
+
return e && Fe(this, e, this._functionSubscribers, this._objectSubscribers), this._value;
|
|
600
688
|
}
|
|
601
689
|
/**
|
|
602
690
|
* Sets a new value and schedules notifications if the value has changed.
|
|
603
|
-
* Uses `Object.is` for comparison.
|
|
604
691
|
*/
|
|
605
692
|
set value(e) {
|
|
606
693
|
if (Object.is(this._value, e)) return;
|
|
607
694
|
const s = this._value;
|
|
608
|
-
this.
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
Re(this, e, this._functionSubscribersStore, this._objectSubscribersStore);
|
|
695
|
+
this._value = e, this.rotatePhase();
|
|
696
|
+
const n = this._functionSubscribersStore?.hasSubscribers, i = this._objectSubscribersStore?.hasSubscribers;
|
|
697
|
+
(n || i) && this._scheduleNotification(s);
|
|
612
698
|
}
|
|
699
|
+
/**
|
|
700
|
+
* Schedules or flushes notifications based on sync mode and batching state.
|
|
701
|
+
*/
|
|
613
702
|
_scheduleNotification(e) {
|
|
614
|
-
this.
|
|
703
|
+
if (this.flags & Y.NOTIFICATION_SCHEDULED || (this._pendingOldValue = e, this.flags |= Y.NOTIFICATION_SCHEDULED), this.flags & Y.SYNC && !Z.isBatching) {
|
|
704
|
+
this._flushNotifications();
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
707
|
+
this._notifyTask || (this._notifyTask = () => this._flushNotifications()), Z.schedule(this._notifyTask);
|
|
615
708
|
}
|
|
616
709
|
_flushNotifications() {
|
|
617
|
-
if (!this.
|
|
710
|
+
if (!(this.flags & Y.NOTIFICATION_SCHEDULED)) return;
|
|
618
711
|
const e = this._pendingOldValue, s = this._value;
|
|
619
|
-
this._pendingOldValue = void 0, this.
|
|
712
|
+
this._pendingOldValue = void 0, this.flags &= -3, this._notifySubscribers(s, e);
|
|
620
713
|
}
|
|
621
714
|
/**
|
|
622
|
-
*
|
|
715
|
+
* Overridden to avoid unnecessary manager creation during notification loop.
|
|
623
716
|
*/
|
|
717
|
+
_notifySubscribers(e, s) {
|
|
718
|
+
this._functionSubscribersStore && this._functionSubscribersStore.forEachSafe((n) => n(e, s)), this._objectSubscribersStore && this._objectSubscribersStore.forEachSafe((n) => n.execute());
|
|
719
|
+
}
|
|
624
720
|
peek() {
|
|
625
721
|
return this._value;
|
|
626
722
|
}
|
|
627
|
-
/**
|
|
628
|
-
* Disposes of the atom, clearing all subscribers and resetting the value.
|
|
629
|
-
*/
|
|
630
723
|
dispose() {
|
|
631
|
-
this._functionSubscribersStore
|
|
724
|
+
this._functionSubscribersStore?.clear(), this._objectSubscribersStore?.clear(), this._value = void 0, this._notifyTask = void 0;
|
|
632
725
|
}
|
|
633
726
|
}
|
|
634
|
-
function
|
|
635
|
-
return new
|
|
727
|
+
function rt(t, e = {}) {
|
|
728
|
+
return new it(t, e.sync ?? !1);
|
|
636
729
|
}
|
|
637
|
-
function
|
|
730
|
+
function K(t, e, s) {
|
|
638
731
|
if (t instanceof TypeError)
|
|
639
732
|
return new e(`Type error (${s}): ${t.message}`, t);
|
|
640
733
|
if (t instanceof ReferenceError)
|
|
641
734
|
return new e(`Reference error (${s}): ${t.message}`, t);
|
|
642
|
-
if (t instanceof
|
|
735
|
+
if (t instanceof w)
|
|
643
736
|
return t;
|
|
644
737
|
const n = t instanceof Error ? t.message : String(t), i = t instanceof Error ? t : null;
|
|
645
738
|
return new e(`Unexpected error (${s}): ${n}`, i);
|
|
646
739
|
}
|
|
647
|
-
const
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
class
|
|
740
|
+
const Ve = d.RESOLVED | d.PENDING | d.REJECTED, he = Array(Ve + 1).fill(ue.IDLE);
|
|
741
|
+
he[d.RESOLVED] = ue.RESOLVED;
|
|
742
|
+
he[d.PENDING] = ue.PENDING;
|
|
743
|
+
he[d.REJECTED] = ue.REJECTED;
|
|
744
|
+
class Me extends Ue {
|
|
652
745
|
constructor(e, s = {}) {
|
|
653
746
|
if (typeof e != "function")
|
|
654
|
-
throw new
|
|
655
|
-
if (super(), this._cachedErrors = null, this._errorCacheEpoch = -1, this._value = void 0, this.flags = d.DIRTY | d.IDLE, this._error = null, this._promiseId = 0, this._equal = s.equal ?? Object.is, this._fn = e, this._defaultValue = "defaultValue" in s ? s.defaultValue :
|
|
747
|
+
throw new q(g.COMPUTED_MUST_BE_FUNCTION);
|
|
748
|
+
if (super(), this._cachedErrors = null, this._errorCacheEpoch = -1, this._asyncStartAggregateVersion = 0, this._asyncRetryCount = 0, this.MAX_ASYNC_RETRIES = 3, this._value = void 0, this.flags = d.DIRTY | d.IDLE, this._error = null, this._promiseId = 0, this._equal = s.equal ?? Object.is, this._fn = e, this._defaultValue = "defaultValue" in s ? s.defaultValue : Ie, this._hasDefaultValue = this._defaultValue !== Ie, this._onError = s.onError ?? null, this.MAX_PROMISE_ID = Number.MAX_SAFE_INTEGER - 1, this._functionSubscribersStore = new ce(), this._objectSubscribersStore = new ce(), this._dependencies = S, this._dependencyVersions = y, this._unsubscribes = A, this._notifyJob = () => {
|
|
656
749
|
this._functionSubscribersStore.forEachSafe(
|
|
657
750
|
(n) => n(),
|
|
658
751
|
(n) => console.error(n)
|
|
@@ -663,7 +756,7 @@ class Oe extends ve {
|
|
|
663
756
|
}, this._trackable = Object.assign(() => this._markDirty(), {
|
|
664
757
|
addDependency: (n) => {
|
|
665
758
|
}
|
|
666
|
-
}),
|
|
759
|
+
}), R.attachDebugInfo(this, "computed", this.id), R.enabled) {
|
|
667
760
|
const n = this;
|
|
668
761
|
n.subscriberCount = () => this._functionSubscribersStore.size + this._objectSubscribersStore.size, n.isDirty = () => this._isDirty(), n.dependencies = this._dependencies, n.stateFlags = this._getFlagsAsString();
|
|
669
762
|
}
|
|
@@ -703,8 +796,8 @@ class Oe extends ve {
|
|
|
703
796
|
}
|
|
704
797
|
get errors() {
|
|
705
798
|
if (this._registerTracking(), !this.hasError)
|
|
706
|
-
return
|
|
707
|
-
const e =
|
|
799
|
+
return qe;
|
|
800
|
+
const e = He();
|
|
708
801
|
if (this._errorCacheEpoch === e && this._cachedErrors !== null)
|
|
709
802
|
return this._cachedErrors;
|
|
710
803
|
const s = /* @__PURE__ */ new Set();
|
|
@@ -731,17 +824,17 @@ class Oe extends ve {
|
|
|
731
824
|
return this._registerTracking(), this._isResolved();
|
|
732
825
|
}
|
|
733
826
|
invalidate() {
|
|
734
|
-
this._markDirty(), this._dependencyVersions !==
|
|
827
|
+
this._markDirty(), this._dependencyVersions !== y && (N.release(this._dependencyVersions), this._dependencyVersions = y), this._errorCacheEpoch = -1, this._cachedErrors = null;
|
|
735
828
|
}
|
|
736
829
|
dispose() {
|
|
737
|
-
if (this._unsubscribes !==
|
|
830
|
+
if (this._unsubscribes !== A) {
|
|
738
831
|
for (let e = 0; e < this._unsubscribes.length; e++) {
|
|
739
832
|
const s = this._unsubscribes[e];
|
|
740
833
|
s && s();
|
|
741
834
|
}
|
|
742
|
-
|
|
835
|
+
Q.release(this._unsubscribes), this._unsubscribes = A;
|
|
743
836
|
}
|
|
744
|
-
this._dependencies !== S && (
|
|
837
|
+
this._dependencies !== S && (F.release(this._dependencies), this._dependencies = S), this._dependencyVersions !== y && (N.release(this._dependencyVersions), this._dependencyVersions = y), this._functionSubscribersStore.clear(), this._objectSubscribersStore.clear(), this.flags = d.DIRTY | d.IDLE, this._error = null, this._value = void 0, this._promiseId = (this._promiseId + 1) % this.MAX_PROMISE_ID, this._cachedErrors = null, this._errorCacheEpoch = -1;
|
|
745
838
|
}
|
|
746
839
|
// State flag operations
|
|
747
840
|
_isDirty() {
|
|
@@ -785,7 +878,7 @@ class Oe extends ve {
|
|
|
785
878
|
this.flags = this.flags & ~s | -Number(e) & s;
|
|
786
879
|
}
|
|
787
880
|
_getAsyncState() {
|
|
788
|
-
return
|
|
881
|
+
return he[this.flags & Ve];
|
|
789
882
|
}
|
|
790
883
|
_getFlagsAsString() {
|
|
791
884
|
const e = [];
|
|
@@ -800,8 +893,8 @@ class Oe extends ve {
|
|
|
800
893
|
const e = this._prepareComputationContext();
|
|
801
894
|
let s = !1;
|
|
802
895
|
try {
|
|
803
|
-
const n =
|
|
804
|
-
this._commitDependencies(e), s = !0,
|
|
896
|
+
const n = X.run(this._trackable, this._fn);
|
|
897
|
+
this._commitDependencies(e), s = !0, ke(n) ? this._handleAsyncComputation(n) : this._handleSyncResult(n);
|
|
805
898
|
} catch (n) {
|
|
806
899
|
if (!s)
|
|
807
900
|
try {
|
|
@@ -815,59 +908,112 @@ class Oe extends ve {
|
|
|
815
908
|
}
|
|
816
909
|
}
|
|
817
910
|
_prepareComputationContext() {
|
|
818
|
-
const e = this._dependencies, s = this._dependencyVersions, n =
|
|
911
|
+
const e = this._dependencies, s = this._dependencyVersions, n = F.acquire(), i = N.acquire(), r = Oe(), o = { depCount: 0 }, c = (_) => {
|
|
819
912
|
_._lastSeenEpoch !== r && (_._lastSeenEpoch = r, o.depCount < n.length ? (n[o.depCount] = _, i[o.depCount] = _.version) : (n.push(_), i.push(_.version)), o.depCount++);
|
|
820
|
-
},
|
|
821
|
-
return this._trackable.addDependency = c, { prevDeps: e, prevVersions: s, nextDeps: n, nextVersions: i, originalAdd:
|
|
913
|
+
}, h = this._trackable.addDependency;
|
|
914
|
+
return this._trackable.addDependency = c, { prevDeps: e, prevVersions: s, nextDeps: n, nextVersions: i, originalAdd: h, state: o };
|
|
822
915
|
}
|
|
823
916
|
_commitDependencies(e) {
|
|
824
917
|
const { nextDeps: s, nextVersions: n, state: i, prevDeps: r } = e;
|
|
825
|
-
s.length = i.depCount, n.length = i.depCount, this._unsubscribes =
|
|
918
|
+
s.length = i.depCount, n.length = i.depCount, this._unsubscribes = nt(s, r, this._unsubscribes, this), this._dependencies = s, this._dependencyVersions = n;
|
|
826
919
|
}
|
|
827
920
|
_cleanupContext(e, s) {
|
|
828
|
-
this._trackable.addDependency = e.originalAdd, s ? (e.prevDeps !== S &&
|
|
921
|
+
this._trackable.addDependency = e.originalAdd, s ? (e.prevDeps !== S && F.release(e.prevDeps), e.prevVersions !== y && N.release(e.prevVersions)) : (F.release(e.nextDeps), N.release(e.nextVersions));
|
|
922
|
+
}
|
|
923
|
+
/**
|
|
924
|
+
* Calculates aggregate shift from all dependencies.
|
|
925
|
+
* Used for scheduling priority in computed chains.
|
|
926
|
+
*
|
|
927
|
+
* Performance: O(N) where N = dependency count
|
|
928
|
+
* Branchless: Each dep.getShift uses modular arithmetic
|
|
929
|
+
*
|
|
930
|
+
* @returns Sum of all dependency shifts (capped at SMI_MAX)
|
|
931
|
+
*/
|
|
932
|
+
_getAggregateShift() {
|
|
933
|
+
let e = 0;
|
|
934
|
+
const s = this._dependencies, n = this._dependencyVersions;
|
|
935
|
+
for (let i = 0; i < s.length; i++) {
|
|
936
|
+
const r = s[i], o = n[i];
|
|
937
|
+
r && o !== void 0 && (e = e + r.getShift(o) & V);
|
|
938
|
+
}
|
|
939
|
+
return e;
|
|
940
|
+
}
|
|
941
|
+
/**
|
|
942
|
+
* Checks if this computed should be scheduled with urgent priority.
|
|
943
|
+
* Based on aggregate shift from all dependencies.
|
|
944
|
+
*
|
|
945
|
+
* @returns true if aggregate shift exceeds PHASE_THRESHOLD
|
|
946
|
+
*/
|
|
947
|
+
isUrgent() {
|
|
948
|
+
return this._getAggregateShift() >= _e;
|
|
829
949
|
}
|
|
830
950
|
_handleSyncResult(e) {
|
|
831
|
-
|
|
832
|
-
this.version = this.version + Number(s) & B, this._value = e, this._clearDirty(), this._setResolved(), this._error = null, this._setRecomputing(!1), this._cachedErrors = null, this._errorCacheEpoch = -1;
|
|
951
|
+
(!this._isResolved() || !this._equal(this._value, e)) && this.rotatePhase(), this._value = e, this._clearDirty(), this._setResolved(), this._error = null, this._setRecomputing(!1), this._cachedErrors = null, this._errorCacheEpoch = -1;
|
|
833
952
|
}
|
|
834
953
|
_handleAsyncComputation(e) {
|
|
835
|
-
this._setPending(), this._clearDirty(), this._notifyJob(), this._promiseId = this._promiseId >= this.MAX_PROMISE_ID ? 1 : this._promiseId + 1;
|
|
954
|
+
this._setPending(), this._clearDirty(), this._notifyJob(), this._asyncStartAggregateVersion = this._captureVersionSnapshot(), this._asyncRetryCount = 0, this._promiseId = this._promiseId >= this.MAX_PROMISE_ID ? 1 : this._promiseId + 1;
|
|
836
955
|
const s = this._promiseId;
|
|
837
956
|
e.then((n) => {
|
|
838
|
-
s
|
|
957
|
+
if (s !== this._promiseId) return;
|
|
958
|
+
const i = this._captureVersionSnapshot() - this._asyncStartAggregateVersion & V;
|
|
959
|
+
if (_e - 1 - i >>> 31 & 1) {
|
|
960
|
+
if (this._asyncRetryCount < this.MAX_ASYNC_RETRIES) {
|
|
961
|
+
this._asyncRetryCount++, this._markDirty();
|
|
962
|
+
return;
|
|
963
|
+
}
|
|
964
|
+
const r = new q(
|
|
965
|
+
`Async drift exceeded threshold after ${this.MAX_ASYNC_RETRIES} retries. Dependencies changed too rapidly for stable computation.`
|
|
966
|
+
);
|
|
967
|
+
this._handleAsyncRejection(r);
|
|
968
|
+
return;
|
|
969
|
+
}
|
|
970
|
+
this._handleAsyncResolution(n);
|
|
839
971
|
}).catch((n) => {
|
|
840
972
|
s === this._promiseId && this._handleAsyncRejection(n);
|
|
841
973
|
});
|
|
842
974
|
}
|
|
975
|
+
/**
|
|
976
|
+
* Captures the aggregate version of all dependencies.
|
|
977
|
+
* Used for phase drift validation in async computations.
|
|
978
|
+
*
|
|
979
|
+
* @returns Sum of all dependency versions (capped at SMI_MAX)
|
|
980
|
+
*/
|
|
981
|
+
_captureVersionSnapshot() {
|
|
982
|
+
let e = 0;
|
|
983
|
+
const s = this._dependencies;
|
|
984
|
+
for (let n = 0; n < s.length; n++) {
|
|
985
|
+
const i = s[n];
|
|
986
|
+
i && (e = e + i.version & V);
|
|
987
|
+
}
|
|
988
|
+
return e;
|
|
989
|
+
}
|
|
843
990
|
_handleAsyncResolution(e) {
|
|
844
|
-
|
|
845
|
-
this.version = this.version + Number(s) & B, this._value = e, this._clearDirty(), this._setResolved(), this._error = null, this._setRecomputing(!1), this._cachedErrors = null, this._errorCacheEpoch = -1, this._notifyJob();
|
|
991
|
+
(!this._isResolved() || !this._equal(this._value, e)) && this.rotatePhase(), this._value = e, this._clearDirty(), this._setResolved(), this._error = null, this._setRecomputing(!1), this._cachedErrors = null, this._errorCacheEpoch = -1, this._notifyJob();
|
|
846
992
|
}
|
|
847
993
|
_handleAsyncRejection(e) {
|
|
848
|
-
const s =
|
|
849
|
-
if (this.
|
|
994
|
+
const s = K(e, q, g.COMPUTED_ASYNC_COMPUTATION_FAILED);
|
|
995
|
+
if (!this._isRejected() && this.rotatePhase(), this._error = s, this._setRejected(), this._clearDirty(), this._setRecomputing(!1), this._onError)
|
|
850
996
|
try {
|
|
851
997
|
this._onError(s);
|
|
852
|
-
} catch (
|
|
853
|
-
console.error(
|
|
998
|
+
} catch (n) {
|
|
999
|
+
console.error(g.CALLBACK_ERROR_IN_ERROR_HANDLER, n);
|
|
854
1000
|
}
|
|
855
1001
|
this._notifyJob();
|
|
856
1002
|
}
|
|
857
1003
|
_handleComputationError(e) {
|
|
858
|
-
const s =
|
|
1004
|
+
const s = K(e, q, g.COMPUTED_COMPUTATION_FAILED);
|
|
859
1005
|
if (this._error = s, this._setRejected(), this._clearDirty(), this._setRecomputing(!1), this._onError)
|
|
860
1006
|
try {
|
|
861
1007
|
this._onError(s);
|
|
862
1008
|
} catch (n) {
|
|
863
|
-
console.error(
|
|
1009
|
+
console.error(g.CALLBACK_ERROR_IN_ERROR_HANDLER, n);
|
|
864
1010
|
}
|
|
865
1011
|
throw s;
|
|
866
1012
|
}
|
|
867
1013
|
_handlePending() {
|
|
868
1014
|
if (this._hasDefaultValue)
|
|
869
1015
|
return this._defaultValue;
|
|
870
|
-
throw new
|
|
1016
|
+
throw new q(g.COMPUTED_ASYNC_PENDING_NO_DEFAULT);
|
|
871
1017
|
}
|
|
872
1018
|
_handleRejected() {
|
|
873
1019
|
if (this._error?.recoverable && this._hasDefaultValue)
|
|
@@ -882,19 +1028,19 @@ class Oe extends ve {
|
|
|
882
1028
|
this._isRecomputing() || this._isDirty() || (this._setDirty(), this._notifyJob());
|
|
883
1029
|
}
|
|
884
1030
|
_registerTracking() {
|
|
885
|
-
|
|
1031
|
+
Fe(
|
|
886
1032
|
this,
|
|
887
|
-
|
|
1033
|
+
X.getCurrent(),
|
|
888
1034
|
this._functionSubscribersStore,
|
|
889
1035
|
this._objectSubscribersStore
|
|
890
1036
|
);
|
|
891
1037
|
}
|
|
892
1038
|
}
|
|
893
|
-
Object.freeze(
|
|
894
|
-
function
|
|
895
|
-
return new
|
|
1039
|
+
Object.freeze(Me.prototype);
|
|
1040
|
+
function ot(t, e = {}) {
|
|
1041
|
+
return new Me(t, e);
|
|
896
1042
|
}
|
|
897
|
-
class
|
|
1043
|
+
class ct extends xe {
|
|
898
1044
|
/**
|
|
899
1045
|
* Creates a new EffectImpl instance.
|
|
900
1046
|
* @param fn - The effect function to run.
|
|
@@ -903,18 +1049,18 @@ class it extends Ce {
|
|
|
903
1049
|
constructor(e, s = {}) {
|
|
904
1050
|
super(), this.run = () => {
|
|
905
1051
|
if (this.isDisposed)
|
|
906
|
-
throw new
|
|
907
|
-
this._dependencyVersions !==
|
|
1052
|
+
throw new B(g.EFFECT_MUST_BE_FUNCTION);
|
|
1053
|
+
this._dependencyVersions !== y && (N.release(this._dependencyVersions), this._dependencyVersions = y), this.execute();
|
|
908
1054
|
}, this.dispose = () => {
|
|
909
1055
|
if (!this.isDisposed) {
|
|
910
|
-
if (this._setDisposed(), this._safeCleanup(), this._unsubscribes !==
|
|
1056
|
+
if (this._setDisposed(), this._safeCleanup(), this._unsubscribes !== A) {
|
|
911
1057
|
for (let i = 0; i < this._unsubscribes.length; i++) {
|
|
912
1058
|
const r = this._unsubscribes[i];
|
|
913
1059
|
r && r();
|
|
914
1060
|
}
|
|
915
|
-
|
|
1061
|
+
Q.release(this._unsubscribes), this._unsubscribes = A;
|
|
916
1062
|
}
|
|
917
|
-
this._dependencies !== S && (
|
|
1063
|
+
this._dependencies !== S && (F.release(this._dependencies), this._dependencies = S), this._dependencyVersions !== y && (N.release(this._dependencyVersions), this._dependencyVersions = y);
|
|
918
1064
|
}
|
|
919
1065
|
}, this.addDependency = (i) => {
|
|
920
1066
|
if (this.isExecuting && this._nextDeps && this._nextUnsubs && this._nextVersions) {
|
|
@@ -928,8 +1074,8 @@ class it extends Ce {
|
|
|
928
1074
|
const i = this._prepareEffectContext();
|
|
929
1075
|
let r = !1;
|
|
930
1076
|
try {
|
|
931
|
-
const o =
|
|
932
|
-
this._commitEffect(i), r = !0, this._checkLoopWarnings(),
|
|
1077
|
+
const o = X.run(this, this._fn);
|
|
1078
|
+
this._commitEffect(i), r = !0, this._checkLoopWarnings(), ke(o) ? o.then((c) => {
|
|
933
1079
|
!this.isDisposed && typeof c == "function" && (this._cleanup = c);
|
|
934
1080
|
}).catch((c) => {
|
|
935
1081
|
this._handleExecutionError(c);
|
|
@@ -939,20 +1085,20 @@ class it extends Ce {
|
|
|
939
1085
|
} finally {
|
|
940
1086
|
this._cleanupEffect(i, r), this._setExecuting(!1);
|
|
941
1087
|
}
|
|
942
|
-
}, this._currentEpoch = -1, this._lastFlushEpoch = -1, this._executionsInEpoch = 0, this._fn = e, this._sync = s.sync ?? !1, this._maxExecutions = s.maxExecutionsPerSecond ??
|
|
1088
|
+
}, this._currentEpoch = -1, this._lastFlushEpoch = -1, this._executionsInEpoch = 0, this._fn = e, this._sync = s.sync ?? !1, this._maxExecutions = s.maxExecutionsPerSecond ?? z.MAX_EXECUTIONS_PER_SECOND, this._maxExecutionsPerFlush = s.maxExecutionsPerFlush ?? z.MAX_EXECUTIONS_PER_EFFECT, this._trackModifications = s.trackModifications ?? !1, this._cleanup = null, this._dependencies = S, this._dependencyVersions = y, this._unsubscribes = A, this._nextDeps = null, this._nextVersions = null, this._nextUnsubs = null, this._onError = s.onError ?? null, this._historyPtr = 0;
|
|
943
1089
|
const n = Number.isFinite(this._maxExecutions);
|
|
944
|
-
this._historyCapacity = n ? Math.min(this._maxExecutions + 1,
|
|
1090
|
+
this._historyCapacity = n ? Math.min(this._maxExecutions + 1, z.MAX_EXECUTIONS_PER_SECOND + 1) : 0, this._history = v && n && this._historyCapacity > 0 ? new Array(this._historyCapacity).fill(0) : null, this._executionCount = 0, R.attachDebugInfo(this, "effect", this.id);
|
|
945
1091
|
}
|
|
946
1092
|
/**
|
|
947
1093
|
* Prepares the execution context by acquiring pools and setting up epoch.
|
|
948
1094
|
* @returns The prepared EffectContext.
|
|
949
1095
|
*/
|
|
950
1096
|
_prepareEffectContext() {
|
|
951
|
-
const e = this._dependencies, s = this._dependencyVersions, n = this._unsubscribes, i =
|
|
952
|
-
if (e !== S && n !==
|
|
953
|
-
for (let
|
|
954
|
-
const _ = e[
|
|
955
|
-
_ && (_._tempUnsub = n[
|
|
1097
|
+
const e = this._dependencies, s = this._dependencyVersions, n = this._unsubscribes, i = F.acquire(), r = N.acquire(), o = Q.acquire(), c = Oe();
|
|
1098
|
+
if (e !== S && n !== A)
|
|
1099
|
+
for (let h = 0; h < e.length; h++) {
|
|
1100
|
+
const _ = e[h];
|
|
1101
|
+
_ && (_._tempUnsub = n[h]);
|
|
956
1102
|
}
|
|
957
1103
|
return this._nextDeps = i, this._nextVersions = r, this._nextUnsubs = o, this._currentEpoch = c, { prevDeps: e, prevVersions: s, prevUnsubs: n, nextDeps: i, nextVersions: r, nextUnsubs: o };
|
|
958
1104
|
}
|
|
@@ -976,14 +1122,14 @@ class it extends Ce {
|
|
|
976
1122
|
const i = e.prevDeps[n];
|
|
977
1123
|
i?._tempUnsub && (i._tempUnsub(), i._tempUnsub = void 0);
|
|
978
1124
|
}
|
|
979
|
-
|
|
1125
|
+
F.release(e.prevDeps);
|
|
980
1126
|
}
|
|
981
|
-
e.prevUnsubs !==
|
|
1127
|
+
e.prevUnsubs !== A && Q.release(e.prevUnsubs), e.prevVersions !== y && N.release(e.prevVersions);
|
|
982
1128
|
} else {
|
|
983
|
-
|
|
1129
|
+
F.release(e.nextDeps), N.release(e.nextVersions);
|
|
984
1130
|
for (let n = 0; n < e.nextUnsubs.length; n++)
|
|
985
1131
|
e.nextUnsubs[n]?.();
|
|
986
|
-
if (
|
|
1132
|
+
if (Q.release(e.nextUnsubs), e.prevDeps !== S)
|
|
987
1133
|
for (let n = 0; n < e.prevDeps.length; n++) {
|
|
988
1134
|
const i = e.prevDeps[n];
|
|
989
1135
|
i && (i._tempUnsub = void 0);
|
|
@@ -997,11 +1143,11 @@ class it extends Ce {
|
|
|
997
1143
|
_subscribeTo(e) {
|
|
998
1144
|
try {
|
|
999
1145
|
const s = e.subscribe(() => {
|
|
1000
|
-
this._trackModifications && this.isExecuting && (e._modifiedAtEpoch = this._currentEpoch), this._sync ? this.execute() :
|
|
1146
|
+
this._trackModifications && this.isExecuting && (e._modifiedAtEpoch = this._currentEpoch), this._sync ? this.execute() : Z.schedule(this.execute);
|
|
1001
1147
|
});
|
|
1002
1148
|
this._nextUnsubs && this._nextUnsubs.push(s);
|
|
1003
1149
|
} catch (s) {
|
|
1004
|
-
console.error(
|
|
1150
|
+
console.error(K(s, B, g.EFFECT_EXECUTION_FAILED)), this._nextUnsubs && this._nextUnsubs.push(() => {
|
|
1005
1151
|
});
|
|
1006
1152
|
}
|
|
1007
1153
|
}
|
|
@@ -1009,7 +1155,7 @@ class it extends Ce {
|
|
|
1009
1155
|
* Whether the effect has been disposed.
|
|
1010
1156
|
*/
|
|
1011
1157
|
get isDisposed() {
|
|
1012
|
-
return (this.flags &
|
|
1158
|
+
return (this.flags & te.DISPOSED) !== 0;
|
|
1013
1159
|
}
|
|
1014
1160
|
/**
|
|
1015
1161
|
* Total number of times this effect has executed.
|
|
@@ -1021,13 +1167,13 @@ class it extends Ce {
|
|
|
1021
1167
|
* Whether the effect is currently executing.
|
|
1022
1168
|
*/
|
|
1023
1169
|
get isExecuting() {
|
|
1024
|
-
return (this.flags &
|
|
1170
|
+
return (this.flags & te.EXECUTING) !== 0;
|
|
1025
1171
|
}
|
|
1026
1172
|
_setDisposed() {
|
|
1027
|
-
this.flags |=
|
|
1173
|
+
this.flags |= te.DISPOSED;
|
|
1028
1174
|
}
|
|
1029
1175
|
_setExecuting(e) {
|
|
1030
|
-
const s =
|
|
1176
|
+
const s = te.EXECUTING;
|
|
1031
1177
|
this.flags = this.flags & ~s | -Number(e) & s;
|
|
1032
1178
|
}
|
|
1033
1179
|
/**
|
|
@@ -1038,7 +1184,7 @@ class it extends Ce {
|
|
|
1038
1184
|
try {
|
|
1039
1185
|
this._cleanup();
|
|
1040
1186
|
} catch (e) {
|
|
1041
|
-
console.error(
|
|
1187
|
+
console.error(K(e, B, g.EFFECT_CLEANUP_FAILED));
|
|
1042
1188
|
}
|
|
1043
1189
|
this._cleanup = null;
|
|
1044
1190
|
}
|
|
@@ -1048,22 +1194,22 @@ class it extends Ce {
|
|
|
1048
1194
|
* @throws {EffectError} If an infinite loop is detected.
|
|
1049
1195
|
*/
|
|
1050
1196
|
_checkInfiniteLoop() {
|
|
1051
|
-
if (this._lastFlushEpoch !==
|
|
1197
|
+
if (this._lastFlushEpoch !== re && (this._lastFlushEpoch = re, this._executionsInEpoch = 0), this._executionsInEpoch++, this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"), Ye() > z.MAX_EXECUTIONS_PER_FLUSH && this._throwInfiniteLoopError("global"), this._executionCount++, this._history && this._maxExecutions > 0) {
|
|
1052
1198
|
const e = Date.now(), s = this._historyPtr, n = this._historyCapacity;
|
|
1053
1199
|
this._history[s] = e;
|
|
1054
1200
|
const i = (s + 1) % n, r = this._history[i] ?? 0;
|
|
1055
|
-
if (this._historyPtr = i, r > 0 && e - r <
|
|
1056
|
-
const o = new
|
|
1201
|
+
if (this._historyPtr = i, r > 0 && e - r < Be.ONE_SECOND_MS) {
|
|
1202
|
+
const o = new B(
|
|
1057
1203
|
`Effect executed ${n} times within 1 second. Infinite loop suspected`
|
|
1058
1204
|
);
|
|
1059
|
-
if (this.dispose(), console.error(o), this._onError && this._onError(o),
|
|
1205
|
+
if (this.dispose(), console.error(o), this._onError && this._onError(o), v)
|
|
1060
1206
|
throw o;
|
|
1061
1207
|
}
|
|
1062
1208
|
}
|
|
1063
1209
|
}
|
|
1064
1210
|
_throwInfiniteLoopError(e) {
|
|
1065
|
-
const s = new
|
|
1066
|
-
`Infinite loop detected (${e}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${
|
|
1211
|
+
const s = new B(
|
|
1212
|
+
`Infinite loop detected (${e}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${be}`
|
|
1067
1213
|
);
|
|
1068
1214
|
throw this.dispose(), console.error(s), s;
|
|
1069
1215
|
}
|
|
@@ -1072,14 +1218,14 @@ class it extends Ce {
|
|
|
1072
1218
|
* @returns true if any dependency has changed or if it's the first run.
|
|
1073
1219
|
*/
|
|
1074
1220
|
_shouldExecute() {
|
|
1075
|
-
if (this._dependencies === S || this._dependencyVersions ===
|
|
1221
|
+
if (this._dependencies === S || this._dependencyVersions === y)
|
|
1076
1222
|
return !0;
|
|
1077
1223
|
for (let e = 0; e < this._dependencies.length; e++) {
|
|
1078
1224
|
const s = this._dependencies[e];
|
|
1079
1225
|
if (s) {
|
|
1080
1226
|
if ("value" in s)
|
|
1081
1227
|
try {
|
|
1082
|
-
|
|
1228
|
+
we(() => s.value);
|
|
1083
1229
|
} catch {
|
|
1084
1230
|
return !0;
|
|
1085
1231
|
}
|
|
@@ -1094,7 +1240,7 @@ class it extends Ce {
|
|
|
1094
1240
|
* Wraps the error, logs it to console, and calls onError callback if provided.
|
|
1095
1241
|
*/
|
|
1096
1242
|
_handleExecutionError(e) {
|
|
1097
|
-
const s =
|
|
1243
|
+
const s = K(e, B, g.EFFECT_EXECUTION_FAILED);
|
|
1098
1244
|
console.error(s), this._onError && this._onError(s);
|
|
1099
1245
|
}
|
|
1100
1246
|
/**
|
|
@@ -1102,31 +1248,31 @@ class it extends Ce {
|
|
|
1102
1248
|
* Only active if trackModifications is enabled and debug is on.
|
|
1103
1249
|
*/
|
|
1104
1250
|
_checkLoopWarnings() {
|
|
1105
|
-
if (this._trackModifications &&
|
|
1251
|
+
if (this._trackModifications && R.enabled) {
|
|
1106
1252
|
const e = this._dependencies;
|
|
1107
1253
|
for (let s = 0; s < e.length; s++) {
|
|
1108
1254
|
const n = e[s];
|
|
1109
|
-
n && n._modifiedAtEpoch === this._currentEpoch &&
|
|
1255
|
+
n && n._modifiedAtEpoch === this._currentEpoch && R.warn(
|
|
1110
1256
|
!0,
|
|
1111
|
-
`Effect is reading a dependency (${
|
|
1257
|
+
`Effect is reading a dependency (${R.getDebugName(n) || "unknown"}) that it just modified. Infinite loop may occur`
|
|
1112
1258
|
);
|
|
1113
1259
|
}
|
|
1114
1260
|
}
|
|
1115
1261
|
}
|
|
1116
1262
|
}
|
|
1117
|
-
function
|
|
1263
|
+
function D(t, e = {}) {
|
|
1118
1264
|
if (typeof t != "function")
|
|
1119
|
-
throw new
|
|
1120
|
-
const s = new
|
|
1265
|
+
throw new B(g.EFFECT_MUST_BE_FUNCTION);
|
|
1266
|
+
const s = new ct(t, e);
|
|
1121
1267
|
return s.execute(), s;
|
|
1122
1268
|
}
|
|
1123
|
-
function
|
|
1269
|
+
function p(t) {
|
|
1124
1270
|
return t !== null && typeof t == "object" && "value" in t && "subscribe" in t;
|
|
1125
1271
|
}
|
|
1126
|
-
function
|
|
1127
|
-
return
|
|
1272
|
+
function k(t) {
|
|
1273
|
+
return p(t) ? t.value : t;
|
|
1128
1274
|
}
|
|
1129
|
-
function
|
|
1275
|
+
function ae(t) {
|
|
1130
1276
|
if (!t) return "unknown";
|
|
1131
1277
|
const e = "jquery" in t ? t[0] : t;
|
|
1132
1278
|
if (!e) return "unknown";
|
|
@@ -1137,7 +1283,7 @@ function ce(t) {
|
|
|
1137
1283
|
}
|
|
1138
1284
|
return e.tagName.toLowerCase();
|
|
1139
1285
|
}
|
|
1140
|
-
function
|
|
1286
|
+
function ut() {
|
|
1141
1287
|
if (typeof window < "u") {
|
|
1142
1288
|
const t = window.__ATOM_DEBUG__;
|
|
1143
1289
|
if (typeof t == "boolean")
|
|
@@ -1150,36 +1296,36 @@ function rt() {
|
|
|
1150
1296
|
}
|
|
1151
1297
|
return !1;
|
|
1152
1298
|
}
|
|
1153
|
-
let
|
|
1154
|
-
const
|
|
1299
|
+
let j = ut();
|
|
1300
|
+
const l = {
|
|
1155
1301
|
get enabled() {
|
|
1156
|
-
return
|
|
1302
|
+
return j;
|
|
1157
1303
|
},
|
|
1158
1304
|
set enabled(t) {
|
|
1159
|
-
|
|
1305
|
+
j = t;
|
|
1160
1306
|
},
|
|
1161
1307
|
log(t, ...e) {
|
|
1162
|
-
|
|
1308
|
+
j && console.log(`[atom-effect-jquery] ${t}:`, ...e);
|
|
1163
1309
|
},
|
|
1164
1310
|
atomChanged(t, e, s) {
|
|
1165
|
-
|
|
1311
|
+
j && console.log(`[atom-effect-jquery] Atom "${t || "anonymous"}" changed:`, e, "→", s);
|
|
1166
1312
|
},
|
|
1167
1313
|
/**
|
|
1168
1314
|
* Logs DOM updates and triggers visual highlight.
|
|
1169
1315
|
*/
|
|
1170
1316
|
domUpdated(t, e, s) {
|
|
1171
|
-
if (!
|
|
1172
|
-
const n =
|
|
1173
|
-
console.log(`[atom-effect-jquery] DOM updated: ${n}.${e} =`, s),
|
|
1317
|
+
if (!j) return;
|
|
1318
|
+
const n = ae(t);
|
|
1319
|
+
console.log(`[atom-effect-jquery] DOM updated: ${n}.${e} =`, s), ht(t);
|
|
1174
1320
|
},
|
|
1175
1321
|
cleanup(t) {
|
|
1176
|
-
|
|
1322
|
+
j && console.log(`[atom-effect-jquery] Cleanup: ${t}`);
|
|
1177
1323
|
},
|
|
1178
1324
|
warn(...t) {
|
|
1179
|
-
|
|
1325
|
+
j && console.warn("[atom-effect-jquery]", ...t);
|
|
1180
1326
|
}
|
|
1181
1327
|
};
|
|
1182
|
-
function
|
|
1328
|
+
function ht(t) {
|
|
1183
1329
|
const e = t[0];
|
|
1184
1330
|
if (!e || !document.contains(e)) return;
|
|
1185
1331
|
const s = "atom_debug_timer", n = "atom_debug_cleanup_timer", i = "atom_debug_org_style";
|
|
@@ -1208,83 +1354,76 @@ function ot(t) {
|
|
|
1208
1354
|
}, 100);
|
|
1209
1355
|
t.data(s, r);
|
|
1210
1356
|
}
|
|
1211
|
-
const
|
|
1212
|
-
function
|
|
1213
|
-
const s =
|
|
1214
|
-
return e.name &&
|
|
1357
|
+
const at = /* @__PURE__ */ new WeakMap();
|
|
1358
|
+
function Pe(t, e = {}) {
|
|
1359
|
+
const s = rt(t, e);
|
|
1360
|
+
return e.name && at.set(s, { name: e.name }), s;
|
|
1215
1361
|
}
|
|
1216
|
-
Object.defineProperty(
|
|
1362
|
+
Object.defineProperty(Pe, "debug", {
|
|
1217
1363
|
get() {
|
|
1218
|
-
return
|
|
1364
|
+
return l.enabled;
|
|
1219
1365
|
},
|
|
1220
1366
|
set(t) {
|
|
1221
|
-
|
|
1367
|
+
l.enabled = t;
|
|
1222
1368
|
}
|
|
1223
1369
|
});
|
|
1224
|
-
function
|
|
1370
|
+
function lt() {
|
|
1225
1371
|
return new Promise((t) => setTimeout(t, 0));
|
|
1226
1372
|
}
|
|
1227
1373
|
u.extend({
|
|
1228
|
-
atom:
|
|
1229
|
-
computed:
|
|
1230
|
-
effect:
|
|
1231
|
-
batch:
|
|
1232
|
-
untracked:
|
|
1233
|
-
isAtom:
|
|
1234
|
-
isComputed:
|
|
1235
|
-
isReactive: (t) =>
|
|
1236
|
-
nextTick:
|
|
1374
|
+
atom: Pe,
|
|
1375
|
+
computed: ot,
|
|
1376
|
+
effect: D,
|
|
1377
|
+
batch: Ke,
|
|
1378
|
+
untracked: we,
|
|
1379
|
+
isAtom: pe,
|
|
1380
|
+
isComputed: Ae,
|
|
1381
|
+
isReactive: (t) => pe(t) || Ae(t),
|
|
1382
|
+
nextTick: lt
|
|
1237
1383
|
});
|
|
1238
|
-
function
|
|
1384
|
+
function $e() {
|
|
1239
1385
|
return { timeoutId: null, phase: "idle", hasFocus: !1 };
|
|
1240
1386
|
}
|
|
1241
|
-
function
|
|
1387
|
+
function Le(t, e, s = {}) {
|
|
1242
1388
|
const {
|
|
1243
1389
|
debounce: n,
|
|
1244
1390
|
event: i = "input",
|
|
1245
|
-
parse: r = (
|
|
1246
|
-
format: o = (
|
|
1247
|
-
} = s, c =
|
|
1391
|
+
parse: r = (I) => I,
|
|
1392
|
+
format: o = (I) => String(I ?? "")
|
|
1393
|
+
} = s, c = $e(), h = () => {
|
|
1248
1394
|
c.phase = "composing";
|
|
1249
1395
|
}, _ = () => {
|
|
1250
|
-
c.phase = "idle",
|
|
1396
|
+
c.phase = "idle", T();
|
|
1251
1397
|
};
|
|
1252
|
-
t.on("compositionstart",
|
|
1253
|
-
const
|
|
1398
|
+
t.on("compositionstart", h), t.on("compositionend", _);
|
|
1399
|
+
const m = () => {
|
|
1254
1400
|
c.hasFocus = !0;
|
|
1255
|
-
},
|
|
1401
|
+
}, G = () => {
|
|
1256
1402
|
c.hasFocus = !1;
|
|
1257
|
-
const
|
|
1258
|
-
t.val() !==
|
|
1403
|
+
const I = o(e.value);
|
|
1404
|
+
t.val() !== I && t.val(I);
|
|
1259
1405
|
};
|
|
1260
|
-
t.on("focus",
|
|
1261
|
-
const
|
|
1406
|
+
t.on("focus", m), t.on("blur", G);
|
|
1407
|
+
const T = () => {
|
|
1262
1408
|
c.phase === "idle" && (c.phase = "syncing-to-atom", e.value = r(t.val()), c.phase = "idle");
|
|
1263
|
-
},
|
|
1264
|
-
c.phase === "idle" && (n ? (c.timeoutId && clearTimeout(c.timeoutId), c.timeoutId = window.setTimeout(
|
|
1409
|
+
}, x = () => {
|
|
1410
|
+
c.phase === "idle" && (n ? (c.timeoutId && clearTimeout(c.timeoutId), c.timeoutId = window.setTimeout(T, n)) : T());
|
|
1265
1411
|
};
|
|
1266
|
-
return t.on(i,
|
|
1267
|
-
const
|
|
1268
|
-
if (
|
|
1269
|
-
if (c.hasFocus && r(
|
|
1412
|
+
return t.on(i, x), t.on("change", x), { effect: () => {
|
|
1413
|
+
const I = o(e.value), H = t.val();
|
|
1414
|
+
if (H !== I) {
|
|
1415
|
+
if (c.hasFocus && r(H) === e.value)
|
|
1270
1416
|
return;
|
|
1271
|
-
c.phase = "syncing-to-dom", t.val(
|
|
1417
|
+
c.phase = "syncing-to-dom", t.val(I), l.domUpdated(t, "val", I), c.phase = "idle";
|
|
1272
1418
|
}
|
|
1273
1419
|
}, cleanup: () => {
|
|
1274
|
-
t.off(i,
|
|
1420
|
+
t.off(i, x), t.off("change", x), t.off("compositionstart", h), t.off("compositionend", _), t.off("focus", m), t.off("blur", G), c.timeoutId && clearTimeout(c.timeoutId);
|
|
1275
1421
|
} };
|
|
1276
1422
|
}
|
|
1277
|
-
class
|
|
1278
|
-
// DOM Element -> Effect Array (for disposal)
|
|
1423
|
+
class ft {
|
|
1279
1424
|
effects = /* @__PURE__ */ new WeakMap();
|
|
1280
|
-
// DOM Element -> Custom Cleanup Function Array
|
|
1281
1425
|
cleanups = /* @__PURE__ */ new WeakMap();
|
|
1282
|
-
// Track bound elements (Performance optimization)
|
|
1283
1426
|
boundElements = /* @__PURE__ */ new WeakSet();
|
|
1284
|
-
/**
|
|
1285
|
-
* Tracks elements that are temporarily detached (e.g. via .detach())
|
|
1286
|
-
* so they are NOT cleaned up by the MutationObserver.
|
|
1287
|
-
*/
|
|
1288
1427
|
preservedNodes = /* @__PURE__ */ new WeakSet();
|
|
1289
1428
|
keep(e) {
|
|
1290
1429
|
this.preservedNodes.add(e);
|
|
@@ -1292,183 +1431,156 @@ class ht {
|
|
|
1292
1431
|
isKept(e) {
|
|
1293
1432
|
return this.preservedNodes.has(e);
|
|
1294
1433
|
}
|
|
1295
|
-
/**
|
|
1296
|
-
* Registers an Effect to be disposed later.
|
|
1297
|
-
*/
|
|
1298
1434
|
trackEffect(e, s) {
|
|
1299
|
-
|
|
1300
|
-
n
|
|
1435
|
+
let n = this.effects.get(e);
|
|
1436
|
+
n || (n = [], this.effects.set(e, n), this.boundElements.add(e)), n.push(s);
|
|
1301
1437
|
}
|
|
1302
|
-
/**
|
|
1303
|
-
* Registers a custom cleanup function (e.g., event listener removal).
|
|
1304
|
-
*/
|
|
1305
1438
|
trackCleanup(e, s) {
|
|
1306
|
-
|
|
1307
|
-
n
|
|
1439
|
+
let n = this.cleanups.get(e);
|
|
1440
|
+
n || (n = [], this.cleanups.set(e, n), this.boundElements.add(e)), n.push(s);
|
|
1308
1441
|
}
|
|
1309
|
-
/**
|
|
1310
|
-
* Checks if an element has bindings (Fast check).
|
|
1311
|
-
*/
|
|
1312
1442
|
hasBind(e) {
|
|
1313
1443
|
return this.boundElements.has(e);
|
|
1314
1444
|
}
|
|
1315
|
-
/**
|
|
1316
|
-
* Cleans up a single element.
|
|
1317
|
-
* - Disposes all Effects (severs connection with Atom).
|
|
1318
|
-
* - Executes all custom cleanups.
|
|
1319
|
-
*/
|
|
1320
1445
|
cleanup(e) {
|
|
1321
|
-
if (!this.boundElements.
|
|
1322
|
-
|
|
1446
|
+
if (!this.boundElements.delete(e)) return;
|
|
1447
|
+
l.cleanup(ae(e));
|
|
1323
1448
|
const s = this.effects.get(e);
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1449
|
+
if (s) {
|
|
1450
|
+
this.effects.delete(e);
|
|
1451
|
+
for (let i = 0, r = s.length; i < r; i++) {
|
|
1452
|
+
const o = s[i];
|
|
1453
|
+
if (o)
|
|
1454
|
+
try {
|
|
1455
|
+
o.dispose();
|
|
1456
|
+
} catch (c) {
|
|
1457
|
+
l.warn("Effect dispose error:", c);
|
|
1458
|
+
}
|
|
1329
1459
|
}
|
|
1330
|
-
}
|
|
1460
|
+
}
|
|
1331
1461
|
const n = this.cleanups.get(e);
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1462
|
+
if (n) {
|
|
1463
|
+
this.cleanups.delete(e);
|
|
1464
|
+
for (let i = 0, r = n.length; i < r; i++) {
|
|
1465
|
+
const o = n[i];
|
|
1466
|
+
if (o)
|
|
1467
|
+
try {
|
|
1468
|
+
o();
|
|
1469
|
+
} catch (c) {
|
|
1470
|
+
l.warn("Cleanup error:", c);
|
|
1471
|
+
}
|
|
1337
1472
|
}
|
|
1338
|
-
}
|
|
1473
|
+
}
|
|
1339
1474
|
}
|
|
1340
|
-
/**
|
|
1341
|
-
* Cleans up the element and all its descendants (Recursive).
|
|
1342
|
-
* - Essential for deep removal (empty(), remove(), etc.).
|
|
1343
|
-
*/
|
|
1344
1475
|
cleanupTree(e) {
|
|
1345
|
-
e.querySelectorAll("*")
|
|
1346
|
-
|
|
1347
|
-
|
|
1476
|
+
const s = e.querySelectorAll("*");
|
|
1477
|
+
for (let n = 0, i = s.length; n < i; n++) {
|
|
1478
|
+
const r = s[n];
|
|
1479
|
+
r && this.boundElements.has(r) && this.cleanup(r);
|
|
1480
|
+
}
|
|
1481
|
+
this.cleanup(e);
|
|
1348
1482
|
}
|
|
1349
1483
|
}
|
|
1350
|
-
const
|
|
1351
|
-
let
|
|
1352
|
-
function
|
|
1353
|
-
|
|
1354
|
-
for (
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1484
|
+
const f = new ft();
|
|
1485
|
+
let W = null;
|
|
1486
|
+
function dt(t = document.body) {
|
|
1487
|
+
W || (W = new MutationObserver((e) => {
|
|
1488
|
+
for (let s = 0, n = e.length; s < n; s++) {
|
|
1489
|
+
const i = e[s];
|
|
1490
|
+
if (!i) continue;
|
|
1491
|
+
const r = i.removedNodes;
|
|
1492
|
+
for (let o = 0, c = r.length; o < c; o++) {
|
|
1493
|
+
const h = r[o];
|
|
1494
|
+
h && (f.isKept(h) || h.isConnected || h.nodeType === 1 && f.cleanupTree(h));
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
}), W.observe(t, { childList: !0, subtree: !0 }));
|
|
1359
1498
|
}
|
|
1360
|
-
function
|
|
1361
|
-
|
|
1499
|
+
function Nt() {
|
|
1500
|
+
W?.disconnect(), W = null;
|
|
1362
1501
|
}
|
|
1363
1502
|
u.fn.atomText = function(t, e) {
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
s.text(r), h.domUpdated(s, "text", r);
|
|
1503
|
+
if (p(t))
|
|
1504
|
+
return this.each(function() {
|
|
1505
|
+
const n = u(this), i = D(() => {
|
|
1506
|
+
const r = t.value, o = e ? e(r) : String(r ?? "");
|
|
1507
|
+
n.text(o), l.domUpdated(n, "text", o);
|
|
1370
1508
|
});
|
|
1371
|
-
|
|
1372
|
-
}
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
}
|
|
1376
|
-
});
|
|
1509
|
+
f.trackEffect(this, i);
|
|
1510
|
+
});
|
|
1511
|
+
const s = e ? e(t) : String(t ?? "");
|
|
1512
|
+
return this.text(s);
|
|
1377
1513
|
};
|
|
1378
1514
|
u.fn.atomHtml = function(t) {
|
|
1379
|
-
return this.each(function() {
|
|
1380
|
-
const e = u(this)
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
l.trackEffect(this, s);
|
|
1387
|
-
} else
|
|
1388
|
-
e.html(String(t ?? ""));
|
|
1389
|
-
});
|
|
1515
|
+
return p(t) ? this.each(function() {
|
|
1516
|
+
const e = u(this), s = D(() => {
|
|
1517
|
+
const n = String(t.value ?? "");
|
|
1518
|
+
e.html(n), l.domUpdated(e, "html", n);
|
|
1519
|
+
});
|
|
1520
|
+
f.trackEffect(this, s);
|
|
1521
|
+
}) : this.html(String(t ?? ""));
|
|
1390
1522
|
};
|
|
1391
1523
|
u.fn.atomClass = function(t, e) {
|
|
1392
|
-
return this.each(function() {
|
|
1393
|
-
const s = u(this)
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
l.trackEffect(this, n);
|
|
1400
|
-
} else
|
|
1401
|
-
s.toggleClass(t, !!e);
|
|
1402
|
-
});
|
|
1524
|
+
return p(e) ? this.each(function() {
|
|
1525
|
+
const s = u(this), n = D(() => {
|
|
1526
|
+
const i = !!e.value;
|
|
1527
|
+
s.toggleClass(t, i), l.domUpdated(s, `class.${t}`, i);
|
|
1528
|
+
});
|
|
1529
|
+
f.trackEffect(this, n);
|
|
1530
|
+
}) : this.toggleClass(t, !!e);
|
|
1403
1531
|
};
|
|
1404
1532
|
u.fn.atomCss = function(t, e, s) {
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
n.css(t, o), h.domUpdated(n, `css.${t}`, o);
|
|
1533
|
+
if (p(e))
|
|
1534
|
+
return this.each(function() {
|
|
1535
|
+
const i = u(this), r = D(() => {
|
|
1536
|
+
const o = e.value, c = s ? `${o}${s}` : o;
|
|
1537
|
+
i.css(t, c), l.domUpdated(i, `css.${t}`, c);
|
|
1411
1538
|
});
|
|
1412
|
-
|
|
1413
|
-
}
|
|
1414
|
-
|
|
1415
|
-
|
|
1539
|
+
f.trackEffect(this, r);
|
|
1540
|
+
});
|
|
1541
|
+
const n = s ? `${e}${s}` : e;
|
|
1542
|
+
return this.css(t, n);
|
|
1416
1543
|
};
|
|
1417
1544
|
u.fn.atomAttr = function(t, e) {
|
|
1418
|
-
return this.each(function() {
|
|
1419
|
-
const s = u(this), n = (
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
} else
|
|
1426
|
-
n(e);
|
|
1427
|
-
});
|
|
1545
|
+
return p(e) ? this.each(function() {
|
|
1546
|
+
const s = u(this), n = D(() => {
|
|
1547
|
+
const i = e.value;
|
|
1548
|
+
i == null || i === !1 ? s.removeAttr(t) : i === !0 ? s.attr(t, t) : s.attr(t, String(i)), l.domUpdated(s, `attr.${t}`, i);
|
|
1549
|
+
});
|
|
1550
|
+
f.trackEffect(this, n);
|
|
1551
|
+
}) : e == null || e === !1 ? this.removeAttr(t) : e === !0 ? this.attr(t, t) : this.attr(t, String(e));
|
|
1428
1552
|
};
|
|
1429
1553
|
u.fn.atomProp = function(t, e) {
|
|
1430
|
-
return this.each(function() {
|
|
1431
|
-
const s = u(this)
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
l.trackEffect(this, n);
|
|
1438
|
-
} else
|
|
1439
|
-
s.prop(t, e);
|
|
1440
|
-
});
|
|
1554
|
+
return p(e) ? this.each(function() {
|
|
1555
|
+
const s = u(this), n = D(() => {
|
|
1556
|
+
const i = e.value;
|
|
1557
|
+
s.prop(t, i), l.domUpdated(s, `prop.${t}`, i);
|
|
1558
|
+
});
|
|
1559
|
+
f.trackEffect(this, n);
|
|
1560
|
+
}) : this.prop(t, e);
|
|
1441
1561
|
};
|
|
1442
1562
|
u.fn.atomShow = function(t) {
|
|
1443
|
-
return this.each(function() {
|
|
1444
|
-
const e = u(this)
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
l.trackEffect(this, s);
|
|
1451
|
-
} else
|
|
1452
|
-
e.toggle(!!t);
|
|
1453
|
-
});
|
|
1563
|
+
return p(t) ? this.each(function() {
|
|
1564
|
+
const e = u(this), s = D(() => {
|
|
1565
|
+
const n = !!t.value;
|
|
1566
|
+
e.toggle(n), l.domUpdated(e, "show", n);
|
|
1567
|
+
});
|
|
1568
|
+
f.trackEffect(this, s);
|
|
1569
|
+
}) : this.toggle(!!t);
|
|
1454
1570
|
};
|
|
1455
1571
|
u.fn.atomHide = function(t) {
|
|
1456
|
-
return this.each(function() {
|
|
1457
|
-
const e = u(this)
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
l.trackEffect(this, s);
|
|
1464
|
-
} else
|
|
1465
|
-
e.toggle(!t);
|
|
1466
|
-
});
|
|
1572
|
+
return p(t) ? this.each(function() {
|
|
1573
|
+
const e = u(this), s = D(() => {
|
|
1574
|
+
const n = !t.value;
|
|
1575
|
+
e.toggle(n), l.domUpdated(e, "hide", !n);
|
|
1576
|
+
});
|
|
1577
|
+
f.trackEffect(this, s);
|
|
1578
|
+
}) : this.toggle(!t);
|
|
1467
1579
|
};
|
|
1468
1580
|
u.fn.atomVal = function(t, e = {}) {
|
|
1469
1581
|
return this.each(function() {
|
|
1470
|
-
const { effect:
|
|
1471
|
-
|
|
1582
|
+
const s = u(this), { effect: n, cleanup: i } = Le(s, t, e), r = D(n);
|
|
1583
|
+
f.trackEffect(this, r), f.trackCleanup(this, i);
|
|
1472
1584
|
});
|
|
1473
1585
|
};
|
|
1474
1586
|
u.fn.atomChecked = function(t) {
|
|
@@ -1476,100 +1588,100 @@ u.fn.atomChecked = function(t) {
|
|
|
1476
1588
|
const e = u(this);
|
|
1477
1589
|
let s = !1;
|
|
1478
1590
|
const n = () => {
|
|
1479
|
-
s || (t.value = e.prop("checked"));
|
|
1591
|
+
s || (t.value = !!e.prop("checked"));
|
|
1480
1592
|
};
|
|
1481
|
-
e.on("change", n),
|
|
1482
|
-
const i =
|
|
1483
|
-
s = !0
|
|
1593
|
+
e.on("change", n), f.trackCleanup(this, () => e.off("change", n));
|
|
1594
|
+
const i = D(() => {
|
|
1595
|
+
s = !0;
|
|
1596
|
+
const r = !!t.value;
|
|
1597
|
+
e.prop("checked", r), l.domUpdated(e, "checked", r), s = !1;
|
|
1484
1598
|
});
|
|
1485
|
-
|
|
1599
|
+
f.trackEffect(this, i);
|
|
1486
1600
|
});
|
|
1487
1601
|
};
|
|
1488
1602
|
u.fn.atomOn = function(t, e) {
|
|
1489
1603
|
return this.each(function() {
|
|
1490
|
-
const s = u(this)
|
|
1491
|
-
|
|
1492
|
-
};
|
|
1493
|
-
s.on(t, n), l.trackCleanup(this, () => s.off(t, n));
|
|
1604
|
+
const s = u(this);
|
|
1605
|
+
s.on(t, e), f.trackCleanup(this, () => s.off(t, e));
|
|
1494
1606
|
});
|
|
1495
1607
|
};
|
|
1496
1608
|
u.fn.atomUnbind = function() {
|
|
1497
1609
|
return this.each(function() {
|
|
1498
|
-
|
|
1610
|
+
f.cleanupTree(this);
|
|
1499
1611
|
});
|
|
1500
1612
|
};
|
|
1501
|
-
function
|
|
1502
|
-
|
|
1503
|
-
const s = String(
|
|
1504
|
-
t.$el.text(s),
|
|
1613
|
+
function _t(t, e) {
|
|
1614
|
+
p(e) ? t.effects.push(() => {
|
|
1615
|
+
const s = String(k(e) ?? "");
|
|
1616
|
+
t.$el.text(s), l.domUpdated(t.$el, "text", s);
|
|
1505
1617
|
}) : t.$el.text(String(e ?? ""));
|
|
1506
1618
|
}
|
|
1507
|
-
function
|
|
1508
|
-
|
|
1509
|
-
const s = String(
|
|
1510
|
-
t.$el.html(s),
|
|
1619
|
+
function pt(t, e) {
|
|
1620
|
+
p(e) ? t.effects.push(() => {
|
|
1621
|
+
const s = String(k(e) ?? "");
|
|
1622
|
+
t.$el.html(s), l.domUpdated(t.$el, "html", s);
|
|
1511
1623
|
}) : t.$el.html(String(e ?? ""));
|
|
1512
1624
|
}
|
|
1513
|
-
function
|
|
1625
|
+
function bt(t, e) {
|
|
1514
1626
|
for (const [s, n] of Object.entries(e))
|
|
1515
|
-
|
|
1516
|
-
const i = !!
|
|
1517
|
-
t.$el.toggleClass(s, i),
|
|
1627
|
+
p(n) ? t.effects.push(() => {
|
|
1628
|
+
const i = !!k(n);
|
|
1629
|
+
t.$el.toggleClass(s, i), l.domUpdated(t.$el, `class.${s}`, i);
|
|
1518
1630
|
}) : t.$el.toggleClass(s, !!n);
|
|
1519
1631
|
}
|
|
1520
|
-
function
|
|
1632
|
+
function Et(t, e) {
|
|
1521
1633
|
for (const [s, n] of Object.entries(e))
|
|
1522
1634
|
if (Array.isArray(n)) {
|
|
1523
1635
|
const [i, r] = n;
|
|
1524
|
-
|
|
1525
|
-
const o = `${
|
|
1526
|
-
t.$el.css(s, o),
|
|
1636
|
+
p(i) ? t.effects.push(() => {
|
|
1637
|
+
const o = `${k(i)}${r}`;
|
|
1638
|
+
t.$el.css(s, o), l.domUpdated(t.$el, `css.${s}`, o);
|
|
1527
1639
|
}) : t.$el.css(s, `${i}${r}`);
|
|
1528
|
-
} else
|
|
1529
|
-
const i =
|
|
1530
|
-
t.$el.css(s, i),
|
|
1640
|
+
} else p(n) ? t.effects.push(() => {
|
|
1641
|
+
const i = k(n);
|
|
1642
|
+
t.$el.css(s, i), l.domUpdated(t.$el, `css.${s}`, i);
|
|
1531
1643
|
}) : t.$el.css(s, n);
|
|
1532
1644
|
}
|
|
1533
|
-
function
|
|
1645
|
+
function gt(t, e) {
|
|
1534
1646
|
for (const [s, n] of Object.entries(e)) {
|
|
1535
1647
|
const i = (r) => {
|
|
1536
|
-
r == null || r === !1 ? t.$el.removeAttr(s) : r === !0 ? t.$el.attr(s, s) : t.$el.attr(s, String(r)),
|
|
1648
|
+
r == null || r === !1 ? t.$el.removeAttr(s) : r === !0 ? t.$el.attr(s, s) : t.$el.attr(s, String(r)), l.domUpdated(t.$el, `attr.${s}`, r);
|
|
1537
1649
|
};
|
|
1538
|
-
|
|
1650
|
+
p(n) ? t.effects.push(() => i(k(n))) : i(n);
|
|
1539
1651
|
}
|
|
1540
1652
|
}
|
|
1541
|
-
function
|
|
1653
|
+
function mt(t, e) {
|
|
1542
1654
|
for (const [s, n] of Object.entries(e))
|
|
1543
|
-
|
|
1544
|
-
const i =
|
|
1545
|
-
t.$el.prop(s, i),
|
|
1655
|
+
p(n) ? t.effects.push(() => {
|
|
1656
|
+
const i = k(n);
|
|
1657
|
+
t.$el.prop(s, i), l.domUpdated(t.$el, `prop.${s}`, i);
|
|
1546
1658
|
}) : t.$el.prop(s, n);
|
|
1547
1659
|
}
|
|
1548
|
-
function
|
|
1549
|
-
|
|
1550
|
-
const s = !!
|
|
1551
|
-
t.$el.toggle(s),
|
|
1660
|
+
function St(t, e) {
|
|
1661
|
+
p(e) ? t.effects.push(() => {
|
|
1662
|
+
const s = !!k(e);
|
|
1663
|
+
t.$el.toggle(s), l.domUpdated(t.$el, "show", s);
|
|
1552
1664
|
}) : t.$el.toggle(!!e);
|
|
1553
1665
|
}
|
|
1554
|
-
function
|
|
1555
|
-
|
|
1556
|
-
const s = !
|
|
1557
|
-
t.$el.toggle(s),
|
|
1666
|
+
function yt(t, e) {
|
|
1667
|
+
p(e) ? t.effects.push(() => {
|
|
1668
|
+
const s = !k(e);
|
|
1669
|
+
t.$el.toggle(s), l.domUpdated(t.$el, "hide", !s);
|
|
1558
1670
|
}) : t.$el.toggle(!e);
|
|
1559
1671
|
}
|
|
1560
|
-
function
|
|
1561
|
-
const s = Array.isArray(e) ? e[0] : e, n = Array.isArray(e) ? e[1] : {}, { effect: i, cleanup: r } =
|
|
1672
|
+
function Dt(t, e) {
|
|
1673
|
+
const s = Array.isArray(e) ? e[0] : e, n = Array.isArray(e) ? e[1] : {}, { effect: i, cleanup: r } = Le(t.$el, s, n);
|
|
1562
1674
|
t.effects.push(i), t.trackCleanup(r);
|
|
1563
1675
|
}
|
|
1564
|
-
function
|
|
1565
|
-
const s =
|
|
1676
|
+
function It(t, e) {
|
|
1677
|
+
const s = $e(), n = () => {
|
|
1566
1678
|
s.phase === "idle" && (e.value = t.$el.prop("checked"));
|
|
1567
1679
|
};
|
|
1568
1680
|
t.$el.on("change", n), t.trackCleanup(() => t.$el.off("change", n)), t.effects.push(() => {
|
|
1569
|
-
s.phase = "syncing-to-dom", t.$el.prop("checked", e.value),
|
|
1681
|
+
s.phase = "syncing-to-dom", t.$el.prop("checked", e.value), l.domUpdated(t.$el, "checked", e.value), s.phase = "idle";
|
|
1570
1682
|
});
|
|
1571
1683
|
}
|
|
1572
|
-
function
|
|
1684
|
+
function Ct(t, e) {
|
|
1573
1685
|
for (const [s, n] of Object.entries(e)) {
|
|
1574
1686
|
const i = function(r) {
|
|
1575
1687
|
n.call(this, r);
|
|
@@ -1583,148 +1695,151 @@ u.fn.atomBind = function(t) {
|
|
|
1583
1695
|
$el: e,
|
|
1584
1696
|
el: this,
|
|
1585
1697
|
effects: s,
|
|
1586
|
-
trackCleanup: (i) =>
|
|
1698
|
+
trackCleanup: (i) => f.trackCleanup(this, i)
|
|
1587
1699
|
};
|
|
1588
|
-
t.text !== void 0 &&
|
|
1589
|
-
const r =
|
|
1590
|
-
|
|
1700
|
+
t.text !== void 0 && _t(n, t.text), t.html !== void 0 && pt(n, t.html), t.class && bt(n, t.class), t.css && Et(n, t.css), t.attr && gt(n, t.attr), t.prop && mt(n, t.prop), t.show !== void 0 && St(n, t.show), t.hide !== void 0 && yt(n, t.hide), t.val !== void 0 && Dt(n, t.val), t.checked !== void 0 && It(n, t.checked), t.on && Ct(n, t.on), s.forEach((i) => {
|
|
1701
|
+
const r = D(i);
|
|
1702
|
+
f.trackEffect(this, r);
|
|
1591
1703
|
});
|
|
1592
1704
|
});
|
|
1593
1705
|
};
|
|
1594
|
-
function
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
for (
|
|
1600
|
-
const
|
|
1601
|
-
if (
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
continue;
|
|
1606
|
-
}
|
|
1607
|
-
for (i = 0, r = s.length - 1; i < r; )
|
|
1608
|
-
o = (i + r) / 2 | 0, t[s[o]] < w ? i = o + 1 : r = o;
|
|
1609
|
-
w < t[s[i]] && (i > 0 && (e[n] = s[i - 1]), s[i] = n);
|
|
1706
|
+
function vt(t) {
|
|
1707
|
+
const e = t.length;
|
|
1708
|
+
if (e === 0) return new Int32Array(0);
|
|
1709
|
+
const s = new Int32Array(e), n = new Int32Array(e);
|
|
1710
|
+
let i = 0;
|
|
1711
|
+
for (let o = 0; o < e; o++) {
|
|
1712
|
+
const c = t[o];
|
|
1713
|
+
if (c === -1) continue;
|
|
1714
|
+
if (i === 0 || t[n[i - 1]] < c) {
|
|
1715
|
+
s[o] = i > 0 ? n[i - 1] : -1, n[i++] = o;
|
|
1716
|
+
continue;
|
|
1610
1717
|
}
|
|
1718
|
+
let h = 0, _ = i - 1;
|
|
1719
|
+
for (; h < _; ) {
|
|
1720
|
+
const m = h + _ >>> 1;
|
|
1721
|
+
t[n[m]] < c ? h = m + 1 : _ = m;
|
|
1722
|
+
}
|
|
1723
|
+
c < t[n[h]] && (h > 0 && (s[o] = n[h - 1]), n[h] = o);
|
|
1611
1724
|
}
|
|
1612
|
-
|
|
1613
|
-
for (;
|
|
1614
|
-
|
|
1615
|
-
return
|
|
1725
|
+
const r = new Int32Array(i);
|
|
1726
|
+
for (let o = i - 1, c = n[i - 1]; o >= 0; o--)
|
|
1727
|
+
r[o] = c, c = s[c];
|
|
1728
|
+
return r;
|
|
1616
1729
|
}
|
|
1617
1730
|
u.fn.atomList = function(t, e) {
|
|
1731
|
+
const { key: s, render: n, bind: i, update: r, onAdd: o, onRemove: c, empty: h } = e, _ = typeof s == "function" ? s : (m) => m[s];
|
|
1618
1732
|
return this.each(function() {
|
|
1619
|
-
const
|
|
1620
|
-
let
|
|
1621
|
-
const
|
|
1622
|
-
const
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1733
|
+
const m = u(this), G = ae(this), T = /* @__PURE__ */ new Map(), x = /* @__PURE__ */ new Set();
|
|
1734
|
+
let M = [], P = null;
|
|
1735
|
+
const I = D(() => {
|
|
1736
|
+
const H = t.value, U = H.length;
|
|
1737
|
+
if (U === 0 ? h && !P && (P = u(h).appendTo(m)) : P && (P.remove(), P = null), U === 0 && T.size === 0) {
|
|
1738
|
+
M = [];
|
|
1739
|
+
return;
|
|
1626
1740
|
}
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1741
|
+
l.log("list", `${G} updating with ${U} items`);
|
|
1742
|
+
const ee = new Array(U), ge = /* @__PURE__ */ new Set();
|
|
1743
|
+
for (let a = 0; a < U; a++) {
|
|
1744
|
+
const b = H[a], C = _(b, a);
|
|
1745
|
+
ee[a] = C, ge.add(C);
|
|
1746
|
+
}
|
|
1747
|
+
for (const [a, b] of T) {
|
|
1748
|
+
if (ge.has(a) || x.has(a)) continue;
|
|
1749
|
+
const C = () => {
|
|
1750
|
+
b.$el.remove();
|
|
1751
|
+
const E = b.$el[0];
|
|
1752
|
+
E && f.cleanup(E), x.delete(a), l.log("list", `${G} removed item:`, a);
|
|
1753
|
+
};
|
|
1754
|
+
if (T.delete(a), x.add(a), c) {
|
|
1755
|
+
const E = c(b.$el);
|
|
1756
|
+
E instanceof Promise ? E.then(C) : C();
|
|
1757
|
+
} else
|
|
1758
|
+
C();
|
|
1759
|
+
}
|
|
1760
|
+
if (U === 0) {
|
|
1761
|
+
M = [];
|
|
1635
1762
|
return;
|
|
1636
|
-
}
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
const
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
v.item = N;
|
|
1657
|
-
const R = v.$el[0];
|
|
1658
|
-
if (!R) continue;
|
|
1659
|
-
if (e.update && e.update(v.$el, N, a), !K)
|
|
1660
|
-
T ? v.$el.insertBefore(T) : v.$el.appendTo(s);
|
|
1661
|
-
else {
|
|
1662
|
-
const X = R.nextSibling;
|
|
1663
|
-
T && X !== T ? v.$el.insertBefore(T) : !T && X && v.$el.appendTo(s);
|
|
1664
|
-
}
|
|
1665
|
-
T = R;
|
|
1763
|
+
}
|
|
1764
|
+
const me = /* @__PURE__ */ new Map();
|
|
1765
|
+
for (let a = 0; a < M.length; a++) {
|
|
1766
|
+
const b = M[a];
|
|
1767
|
+
b !== void 0 && me.set(b, a);
|
|
1768
|
+
}
|
|
1769
|
+
const Se = new Int32Array(U);
|
|
1770
|
+
for (let a = 0; a < U; a++) {
|
|
1771
|
+
const b = ee[a];
|
|
1772
|
+
Se[a] = b !== void 0 ? me.get(b) ?? -1 : -1;
|
|
1773
|
+
}
|
|
1774
|
+
const ye = vt(Se);
|
|
1775
|
+
let le = ye.length - 1, O = null;
|
|
1776
|
+
for (let a = U - 1; a >= 0; a--) {
|
|
1777
|
+
const b = ee[a], C = H[a], E = T.get(b);
|
|
1778
|
+
if (E) {
|
|
1779
|
+
E.item = C;
|
|
1780
|
+
const $ = E.$el[0];
|
|
1781
|
+
if (!$) continue;
|
|
1782
|
+
r && r(E.$el, C, a), le >= 0 && ye[le] === a ? (le--, $.nextSibling !== O && (O ? E.$el.insertBefore(O) : E.$el.appendTo(m))) : O ? E.$el.insertBefore(O) : E.$el.appendTo(m), O = $;
|
|
1666
1783
|
} else {
|
|
1667
|
-
const
|
|
1668
|
-
|
|
1669
|
-
const X = R[0];
|
|
1670
|
-
X && (T = X);
|
|
1784
|
+
const $ = n(C, a), L = $ instanceof Element ? u($) : u($);
|
|
1785
|
+
T.set(b, { $el: L, item: C }), O ? L.insertBefore(O) : L.appendTo(m), i && i(L, C, a), o && o(L), l.log("list", `${G} added item:`, b), O = L[0] || null;
|
|
1671
1786
|
}
|
|
1672
1787
|
}
|
|
1673
|
-
|
|
1788
|
+
M = ee;
|
|
1674
1789
|
});
|
|
1675
|
-
|
|
1676
|
-
|
|
1790
|
+
f.trackEffect(this, I), f.trackCleanup(this, () => {
|
|
1791
|
+
T.clear(), x.clear(), M = [], P?.remove();
|
|
1677
1792
|
});
|
|
1678
1793
|
});
|
|
1679
1794
|
};
|
|
1680
|
-
const
|
|
1795
|
+
const ie = /* @__PURE__ */ new WeakMap();
|
|
1681
1796
|
u.fn.atomMount = function(t, e = {}) {
|
|
1682
1797
|
return this.each(function() {
|
|
1683
|
-
const s = u(this), n =
|
|
1684
|
-
i && (
|
|
1798
|
+
const s = u(this), n = ae(this), i = ie.get(this);
|
|
1799
|
+
i && (l.log("mount", `${n} unmounting existing component`), i()), l.log("mount", `${n} mounting component`);
|
|
1685
1800
|
let r;
|
|
1686
1801
|
try {
|
|
1687
1802
|
r = t(s, e);
|
|
1688
|
-
} catch (
|
|
1689
|
-
console.error("[atom-effect-jquery] Mount error:",
|
|
1803
|
+
} catch (h) {
|
|
1804
|
+
console.error("[atom-effect-jquery] Mount error:", h);
|
|
1690
1805
|
return;
|
|
1691
1806
|
}
|
|
1692
1807
|
let o = !1;
|
|
1693
1808
|
const c = () => {
|
|
1694
1809
|
if (!o) {
|
|
1695
|
-
if (o = !0,
|
|
1810
|
+
if (o = !0, l.log("mount", `${n} full cleanup`), typeof r == "function")
|
|
1696
1811
|
try {
|
|
1697
1812
|
r();
|
|
1698
1813
|
} catch {
|
|
1699
1814
|
}
|
|
1700
|
-
|
|
1815
|
+
f.cleanupTree(this), ie.delete(this);
|
|
1701
1816
|
}
|
|
1702
1817
|
};
|
|
1703
|
-
|
|
1818
|
+
ie.set(this, c), f.trackCleanup(this, c);
|
|
1704
1819
|
});
|
|
1705
1820
|
};
|
|
1706
1821
|
u.fn.atomUnmount = function() {
|
|
1707
1822
|
return this.each(function() {
|
|
1708
|
-
|
|
1823
|
+
ie.get(this)?.();
|
|
1709
1824
|
});
|
|
1710
1825
|
};
|
|
1711
|
-
const
|
|
1712
|
-
let
|
|
1713
|
-
function
|
|
1714
|
-
if (
|
|
1715
|
-
|
|
1826
|
+
const J = /* @__PURE__ */ new WeakMap();
|
|
1827
|
+
let Ne = !1;
|
|
1828
|
+
function je() {
|
|
1829
|
+
if (Ne) return;
|
|
1830
|
+
Ne = !0;
|
|
1716
1831
|
const t = u.fn.on, e = u.fn.off, s = u.fn.remove, n = u.fn.empty, i = u.fn.detach;
|
|
1717
1832
|
u.fn.remove = function(r) {
|
|
1718
1833
|
return (r ? this.filter(r) : this).each(function() {
|
|
1719
|
-
|
|
1834
|
+
f.cleanupTree(this);
|
|
1720
1835
|
}), s.call(this, r);
|
|
1721
1836
|
}, u.fn.empty = function() {
|
|
1722
1837
|
return this.each(function() {
|
|
1723
|
-
this.querySelectorAll("*").forEach((o) =>
|
|
1838
|
+
this.querySelectorAll("*").forEach((o) => f.cleanup(o));
|
|
1724
1839
|
}), n.call(this);
|
|
1725
1840
|
}, u.fn.detach = function(r) {
|
|
1726
1841
|
return (r ? this.filter(r) : this).each(function() {
|
|
1727
|
-
|
|
1842
|
+
f.keep(this);
|
|
1728
1843
|
}), i.call(this, r);
|
|
1729
1844
|
}, u.fn.on = function(...r) {
|
|
1730
1845
|
let o = -1;
|
|
@@ -1735,10 +1850,10 @@ function Fe() {
|
|
|
1735
1850
|
}
|
|
1736
1851
|
if (o !== -1) {
|
|
1737
1852
|
const c = r[o];
|
|
1738
|
-
let
|
|
1739
|
-
|
|
1853
|
+
let h;
|
|
1854
|
+
J.has(c) ? h = J.get(c) : (h = function(..._) {
|
|
1740
1855
|
return c.apply(this, _);
|
|
1741
|
-
},
|
|
1856
|
+
}, J.set(c, h)), r[o] = h;
|
|
1742
1857
|
}
|
|
1743
1858
|
return t.apply(this, r);
|
|
1744
1859
|
}, u.fn.off = function(...r) {
|
|
@@ -1750,27 +1865,27 @@ function Fe() {
|
|
|
1750
1865
|
}
|
|
1751
1866
|
if (o !== -1) {
|
|
1752
1867
|
const c = r[o];
|
|
1753
|
-
|
|
1868
|
+
J.has(c) && (r[o] = J.get(c));
|
|
1754
1869
|
}
|
|
1755
1870
|
return e.apply(this, r);
|
|
1756
1871
|
};
|
|
1757
1872
|
}
|
|
1758
|
-
const
|
|
1759
|
-
|
|
1873
|
+
const Rt = je;
|
|
1874
|
+
je();
|
|
1760
1875
|
u(() => {
|
|
1761
|
-
|
|
1876
|
+
dt(document.body);
|
|
1762
1877
|
});
|
|
1763
1878
|
export {
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1879
|
+
rt as atom,
|
|
1880
|
+
Ke as batch,
|
|
1881
|
+
ot as computed,
|
|
1882
|
+
Ot as default,
|
|
1883
|
+
Nt as disableAutoCleanup,
|
|
1884
|
+
D as effect,
|
|
1885
|
+
dt as enableAutoCleanup,
|
|
1886
|
+
Rt as enablejQueryBatching,
|
|
1887
|
+
je as enablejQueryOverrides,
|
|
1888
|
+
f as registry,
|
|
1889
|
+
we as untracked
|
|
1775
1890
|
};
|
|
1776
1891
|
//# sourceMappingURL=index.mjs.map
|