@askrjs/askr 0.0.4 → 0.0.5

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 (83) hide show
  1. package/dist/fx.js +636 -0
  2. package/dist/fx.js.map +1 -0
  3. package/dist/index.js +3709 -42
  4. package/dist/index.js.map +1 -1
  5. package/dist/{jsx/jsx-dev-runtime.d.ts → jsx-dev-runtime.d.ts} +3 -3
  6. package/dist/jsx-dev-runtime.js +17 -0
  7. package/dist/jsx-dev-runtime.js.map +1 -0
  8. package/dist/jsx-runtime.d.ts +14 -0
  9. package/dist/{chunk-SALJX5PZ.js → jsx-runtime.js} +6 -9
  10. package/dist/jsx-runtime.js.map +1 -0
  11. package/dist/{fx/index.cjs → resources.js} +45 -453
  12. package/dist/resources.js.map +1 -0
  13. package/dist/{router/index.d.ts → router.d.ts} +2 -2
  14. package/dist/{router/index.cjs → router.js} +14 -116
  15. package/dist/router.js.map +1 -0
  16. package/dist/{ssr/index.d.ts → ssr.d.ts} +2 -2
  17. package/dist/{ssr/index.cjs → ssr.js} +17 -150
  18. package/dist/ssr.js.map +1 -0
  19. package/dist/{types-CZHOAiC1.d.ts → types-uOPfcrdz.d.ts} +3 -1
  20. package/dist/vite/index.d.ts +17 -0
  21. package/dist/vite/index.js +2306 -0
  22. package/dist/vite/index.js.map +1 -0
  23. package/package.json +19 -23
  24. package/dist/chunk-64C7W2AE.js +0 -43
  25. package/dist/chunk-64C7W2AE.js.map +0 -1
  26. package/dist/chunk-6FLMH4EL.js +0 -124
  27. package/dist/chunk-6FLMH4EL.js.map +0 -1
  28. package/dist/chunk-FJUXFA72.js +0 -16
  29. package/dist/chunk-FJUXFA72.js.map +0 -1
  30. package/dist/chunk-SALJX5PZ.js.map +0 -1
  31. package/dist/chunk-VRAEBIJ3.js +0 -82
  32. package/dist/chunk-VRAEBIJ3.js.map +0 -1
  33. package/dist/chunk-WTFWRSHB.js +0 -98
  34. package/dist/chunk-WTFWRSHB.js.map +0 -1
  35. package/dist/chunk-XHKZGJE3.js +0 -2907
  36. package/dist/chunk-XHKZGJE3.js.map +0 -1
  37. package/dist/chunk-Z5ZSTLYF.js +0 -420
  38. package/dist/chunk-Z5ZSTLYF.js.map +0 -1
  39. package/dist/fx/index.cjs.map +0 -1
  40. package/dist/fx/index.d.ts +0 -186
  41. package/dist/fx/index.js +0 -418
  42. package/dist/fx/index.js.map +0 -1
  43. package/dist/index.cjs +0 -4035
  44. package/dist/index.cjs.map +0 -1
  45. package/dist/index.d.cts +0 -168
  46. package/dist/jsx/jsx-dev-runtime.cjs +0 -46
  47. package/dist/jsx/jsx-dev-runtime.cjs.map +0 -1
  48. package/dist/jsx/jsx-dev-runtime.d.cts +0 -12
  49. package/dist/jsx/jsx-dev-runtime.js +0 -19
  50. package/dist/jsx/jsx-dev-runtime.js.map +0 -1
  51. package/dist/jsx/jsx-runtime.cjs +0 -54
  52. package/dist/jsx/jsx-runtime.cjs.map +0 -1
  53. package/dist/jsx/jsx-runtime.d.cts +0 -21
  54. package/dist/jsx/jsx-runtime.d.ts +0 -21
  55. package/dist/jsx/jsx-runtime.js +0 -16
  56. package/dist/jsx/jsx-runtime.js.map +0 -1
  57. package/dist/jsx-AzPM8gMS.d.cts +0 -35
  58. package/dist/navigate-LUVYHYZZ.js +0 -17
  59. package/dist/navigate-LUVYHYZZ.js.map +0 -1
  60. package/dist/resources/index.cjs +0 -1200
  61. package/dist/resources/index.cjs.map +0 -1
  62. package/dist/resources/index.d.ts +0 -21
  63. package/dist/resources/index.js +0 -278
  64. package/dist/resources/index.js.map +0 -1
  65. package/dist/route-BCND6MPK.js +0 -32
  66. package/dist/route-BCND6MPK.js.map +0 -1
  67. package/dist/router/index.cjs.map +0 -1
  68. package/dist/router/index.d.cts +0 -64
  69. package/dist/router/index.js +0 -49
  70. package/dist/router/index.js.map +0 -1
  71. package/dist/router-DaGtH1Sq.d.cts +0 -36
  72. package/dist/ssr/index.cjs.map +0 -1
  73. package/dist/ssr/index.d.cts +0 -123
  74. package/dist/ssr/index.js +0 -666
  75. package/dist/ssr/index.js.map +0 -1
  76. package/dist/types-CZ5sWur5.d.cts +0 -23
  77. package/src/jsx/index.ts +0 -4
  78. package/src/jsx/jsx-dev-runtime.ts +0 -23
  79. package/src/jsx/jsx-runtime.ts +0 -48
  80. package/src/jsx/types.ts +0 -33
  81. package/src/jsx/utils.ts +0 -19
  82. /package/dist/{fx/index.d.cts → fx.d.ts} +0 -0
  83. /package/dist/{resources/index.d.cts → resources.d.ts} +0 -0
package/dist/fx.js ADDED
@@ -0,0 +1,636 @@
1
+ // src/fx/timing.ts
2
+ function debounce(fn, ms, options) {
3
+ let timeoutId = null;
4
+ const { leading = false, trailing = true } = options || {};
5
+ let lastArgs = null;
6
+ let lastThis = null;
7
+ let lastCallTime = 0;
8
+ const debounced = function(...args) {
9
+ const callTime = Date.now();
10
+ lastArgs = args;
11
+ lastThis = this;
12
+ if (timeoutId !== null) {
13
+ clearTimeout(timeoutId);
14
+ }
15
+ if (leading && callTime - lastCallTime >= ms) {
16
+ fn.apply(this, args);
17
+ lastCallTime = callTime;
18
+ }
19
+ if (trailing) {
20
+ timeoutId = setTimeout(() => {
21
+ fn.apply(lastThis, lastArgs);
22
+ timeoutId = null;
23
+ lastCallTime = Date.now();
24
+ }, ms);
25
+ }
26
+ };
27
+ debounced.cancel = () => {
28
+ if (timeoutId !== null) {
29
+ clearTimeout(timeoutId);
30
+ timeoutId = null;
31
+ }
32
+ };
33
+ return debounced;
34
+ }
35
+ function throttle(fn, ms, options) {
36
+ let lastCallTime = 0;
37
+ let timeoutId = null;
38
+ const { leading = true, trailing = true } = options || {};
39
+ let lastArgs = null;
40
+ let lastThis = null;
41
+ const throttled = function(...args) {
42
+ const callTime = Date.now();
43
+ lastArgs = args;
44
+ lastThis = this;
45
+ if (leading && callTime - lastCallTime >= ms) {
46
+ fn.apply(this, args);
47
+ lastCallTime = callTime;
48
+ if (timeoutId !== null) {
49
+ clearTimeout(timeoutId);
50
+ timeoutId = null;
51
+ }
52
+ } else if (!leading && lastCallTime === 0) {
53
+ lastCallTime = callTime;
54
+ }
55
+ if (trailing && timeoutId === null) {
56
+ timeoutId = setTimeout(
57
+ () => {
58
+ fn.apply(lastThis, lastArgs);
59
+ lastCallTime = Date.now();
60
+ timeoutId = null;
61
+ },
62
+ ms - (callTime - lastCallTime)
63
+ );
64
+ }
65
+ };
66
+ throttled.cancel = () => {
67
+ if (timeoutId !== null) {
68
+ clearTimeout(timeoutId);
69
+ timeoutId = null;
70
+ }
71
+ };
72
+ return throttled;
73
+ }
74
+ function once(fn) {
75
+ let called = false;
76
+ let result;
77
+ return ((...args) => {
78
+ if (!called) {
79
+ called = true;
80
+ result = fn(...args);
81
+ }
82
+ return result;
83
+ });
84
+ }
85
+ function defer(fn) {
86
+ Promise.resolve().then(fn);
87
+ }
88
+ function raf(fn) {
89
+ let frameId = null;
90
+ let lastArgs = null;
91
+ let lastThis = null;
92
+ return function(...args) {
93
+ lastArgs = args;
94
+ lastThis = this;
95
+ if (frameId === null) {
96
+ frameId = requestAnimationFrame(() => {
97
+ fn.apply(lastThis, lastArgs);
98
+ frameId = null;
99
+ });
100
+ }
101
+ };
102
+ }
103
+ function idle(fn, options) {
104
+ if (typeof requestIdleCallback !== "undefined") {
105
+ requestIdleCallback(fn, options ? { timeout: options.timeout } : void 0);
106
+ } else {
107
+ Promise.resolve().then(() => {
108
+ setTimeout(fn, 0);
109
+ });
110
+ }
111
+ }
112
+ function timeout(ms) {
113
+ return new Promise((resolve) => setTimeout(resolve, ms));
114
+ }
115
+ async function retry(fn, options) {
116
+ const {
117
+ maxAttempts = 3,
118
+ delayMs = 100,
119
+ backoff = (i) => delayMs * Math.pow(2, i)
120
+ } = options || {};
121
+ let lastError = null;
122
+ for (let attempt = 0; attempt < maxAttempts; attempt++) {
123
+ try {
124
+ return await fn();
125
+ } catch (error) {
126
+ lastError = error;
127
+ if (attempt < maxAttempts - 1) {
128
+ const delay = backoff(attempt);
129
+ await timeout(delay);
130
+ }
131
+ }
132
+ }
133
+ throw lastError || new Error("Retry failed");
134
+ }
135
+
136
+ // src/dev/invariant.ts
137
+ function invariant(condition, message, context) {
138
+ if (!condition) {
139
+ const contextStr = "";
140
+ throw new Error(`[Askr Invariant] ${message}${contextStr}`);
141
+ }
142
+ }
143
+ function assertSchedulingPrecondition(condition, violationMessage) {
144
+ invariant(condition, `[Scheduler Precondition] ${violationMessage}`);
145
+ }
146
+
147
+ // src/dev/logger.ts
148
+ function callConsole(method, args) {
149
+ const c = typeof console !== "undefined" ? console : void 0;
150
+ if (!c) return;
151
+ const fn = c[method];
152
+ if (typeof fn === "function") {
153
+ try {
154
+ fn.apply(console, args);
155
+ } catch {
156
+ }
157
+ }
158
+ }
159
+ var logger = {
160
+ debug: (...args) => {
161
+ if (process.env.NODE_ENV === "production") return;
162
+ callConsole("debug", args);
163
+ },
164
+ info: (...args) => {
165
+ if (process.env.NODE_ENV === "production") return;
166
+ callConsole("info", args);
167
+ },
168
+ warn: (...args) => {
169
+ if (process.env.NODE_ENV === "production") return;
170
+ callConsole("warn", args);
171
+ },
172
+ error: (...args) => {
173
+ callConsole("error", args);
174
+ }
175
+ };
176
+
177
+ // src/runtime/scheduler.ts
178
+ var MAX_FLUSH_DEPTH = 50;
179
+ function isBulkCommitActive() {
180
+ try {
181
+ const fb = globalThis.__ASKR_FASTLANE;
182
+ return typeof fb?.isBulkCommitActive === "function" ? !!fb.isBulkCommitActive() : false;
183
+ } catch (e) {
184
+ return false;
185
+ }
186
+ }
187
+ var Scheduler = class {
188
+ constructor() {
189
+ this.q = [];
190
+ this.head = 0;
191
+ this.running = false;
192
+ this.inHandler = false;
193
+ this.depth = 0;
194
+ this.executionDepth = 0;
195
+ // for compat with existing diagnostics
196
+ // Monotonic flush version increments at end of each flush
197
+ this.flushVersion = 0;
198
+ // Best-effort microtask kick scheduling
199
+ this.kickScheduled = false;
200
+ // Escape hatch flag for runWithSyncProgress
201
+ this.allowSyncProgress = false;
202
+ // Waiters waiting for flushVersion >= target
203
+ this.waiters = [];
204
+ // Keep a lightweight taskCount for compatibility/diagnostics
205
+ this.taskCount = 0;
206
+ }
207
+ enqueue(task) {
208
+ assertSchedulingPrecondition(
209
+ typeof task === "function",
210
+ "enqueue() requires a function"
211
+ );
212
+ if (isBulkCommitActive() && !this.allowSyncProgress) {
213
+ if (process.env.NODE_ENV !== "production") {
214
+ throw new Error(
215
+ "[Scheduler] enqueue() during bulk commit (not allowed)"
216
+ );
217
+ }
218
+ return;
219
+ }
220
+ this.q.push(task);
221
+ this.taskCount++;
222
+ if (!this.running && !this.kickScheduled && !this.inHandler && !isBulkCommitActive()) {
223
+ this.kickScheduled = true;
224
+ queueMicrotask(() => {
225
+ this.kickScheduled = false;
226
+ if (this.running) return;
227
+ if (isBulkCommitActive()) return;
228
+ try {
229
+ this.flush();
230
+ } catch (err) {
231
+ setTimeout(() => {
232
+ throw err;
233
+ });
234
+ }
235
+ });
236
+ }
237
+ }
238
+ flush() {
239
+ invariant(
240
+ !this.running,
241
+ "[Scheduler] flush() called while already running"
242
+ );
243
+ if (process.env.NODE_ENV !== "production") {
244
+ if (isBulkCommitActive() && !this.allowSyncProgress) {
245
+ throw new Error(
246
+ "[Scheduler] flush() started during bulk commit (not allowed)"
247
+ );
248
+ }
249
+ }
250
+ this.running = true;
251
+ this.depth = 0;
252
+ let fatal = null;
253
+ try {
254
+ while (this.head < this.q.length) {
255
+ this.depth++;
256
+ if (process.env.NODE_ENV !== "production" && this.depth > MAX_FLUSH_DEPTH) {
257
+ throw new Error(
258
+ `[Scheduler] exceeded MAX_FLUSH_DEPTH (${MAX_FLUSH_DEPTH}). Likely infinite update loop.`
259
+ );
260
+ }
261
+ const task = this.q[this.head++];
262
+ try {
263
+ this.executionDepth++;
264
+ task();
265
+ this.executionDepth--;
266
+ } catch (err) {
267
+ if (this.executionDepth > 0) this.executionDepth = 0;
268
+ fatal = err;
269
+ break;
270
+ }
271
+ if (this.taskCount > 0) this.taskCount--;
272
+ }
273
+ } finally {
274
+ this.running = false;
275
+ this.depth = 0;
276
+ this.executionDepth = 0;
277
+ if (this.head >= this.q.length) {
278
+ this.q.length = 0;
279
+ this.head = 0;
280
+ } else if (this.head > 0) {
281
+ const remaining = this.q.length - this.head;
282
+ for (let i = 0; i < remaining; i++) {
283
+ this.q[i] = this.q[this.head + i];
284
+ }
285
+ this.q.length = remaining;
286
+ this.head = 0;
287
+ }
288
+ this.flushVersion++;
289
+ this.resolveWaiters();
290
+ }
291
+ if (fatal) throw fatal;
292
+ }
293
+ runWithSyncProgress(fn) {
294
+ const prev = this.allowSyncProgress;
295
+ this.allowSyncProgress = true;
296
+ const g = globalThis;
297
+ const origQueueMicrotask = g.queueMicrotask;
298
+ const origSetTimeout = g.setTimeout;
299
+ if (process.env.NODE_ENV !== "production") {
300
+ g.queueMicrotask = () => {
301
+ throw new Error(
302
+ "[Scheduler] queueMicrotask not allowed during runWithSyncProgress"
303
+ );
304
+ };
305
+ g.setTimeout = () => {
306
+ throw new Error(
307
+ "[Scheduler] setTimeout not allowed during runWithSyncProgress"
308
+ );
309
+ };
310
+ }
311
+ const startVersion = this.flushVersion;
312
+ try {
313
+ const res = fn();
314
+ if (!this.running && this.q.length - this.head > 0) {
315
+ this.flush();
316
+ }
317
+ if (process.env.NODE_ENV !== "production") {
318
+ if (this.q.length - this.head > 0) {
319
+ throw new Error(
320
+ "[Scheduler] tasks remain after runWithSyncProgress flush"
321
+ );
322
+ }
323
+ }
324
+ return res;
325
+ } finally {
326
+ if (process.env.NODE_ENV !== "production") {
327
+ g.queueMicrotask = origQueueMicrotask;
328
+ g.setTimeout = origSetTimeout;
329
+ }
330
+ try {
331
+ if (this.flushVersion === startVersion) {
332
+ this.flushVersion++;
333
+ this.resolveWaiters();
334
+ }
335
+ } catch (e) {
336
+ }
337
+ this.allowSyncProgress = prev;
338
+ }
339
+ }
340
+ waitForFlush(targetVersion, timeoutMs = 2e3) {
341
+ const target = typeof targetVersion === "number" ? targetVersion : this.flushVersion + 1;
342
+ if (this.flushVersion >= target) return Promise.resolve();
343
+ return new Promise((resolve, reject) => {
344
+ const timer = setTimeout(() => {
345
+ const ns = globalThis.__ASKR__ || {};
346
+ const diag = {
347
+ flushVersion: this.flushVersion,
348
+ queueLen: this.q.length - this.head,
349
+ running: this.running,
350
+ inHandler: this.inHandler,
351
+ bulk: isBulkCommitActive(),
352
+ namespace: ns
353
+ };
354
+ reject(
355
+ new Error(
356
+ `waitForFlush timeout ${timeoutMs}ms: ${JSON.stringify(diag)}`
357
+ )
358
+ );
359
+ }, timeoutMs);
360
+ this.waiters.push({ target, resolve, reject, timer });
361
+ });
362
+ }
363
+ getState() {
364
+ return {
365
+ queueLength: this.q.length - this.head,
366
+ running: this.running,
367
+ depth: this.depth,
368
+ executionDepth: this.executionDepth,
369
+ taskCount: this.taskCount,
370
+ flushVersion: this.flushVersion,
371
+ // New fields for optional inspection
372
+ inHandler: this.inHandler,
373
+ allowSyncProgress: this.allowSyncProgress
374
+ };
375
+ }
376
+ setInHandler(v) {
377
+ this.inHandler = v;
378
+ }
379
+ isInHandler() {
380
+ return this.inHandler;
381
+ }
382
+ isExecuting() {
383
+ return this.running || this.executionDepth > 0;
384
+ }
385
+ // Clear pending synchronous tasks (used by fastlane enter/exit)
386
+ clearPendingSyncTasks() {
387
+ const remaining = this.q.length - this.head;
388
+ if (remaining <= 0) return 0;
389
+ if (this.running) {
390
+ this.q.length = this.head;
391
+ this.taskCount = Math.max(0, this.taskCount - remaining);
392
+ queueMicrotask(() => {
393
+ try {
394
+ this.flushVersion++;
395
+ this.resolveWaiters();
396
+ } catch (e) {
397
+ }
398
+ });
399
+ return remaining;
400
+ }
401
+ this.q.length = 0;
402
+ this.head = 0;
403
+ this.taskCount = Math.max(0, this.taskCount - remaining);
404
+ this.flushVersion++;
405
+ this.resolveWaiters();
406
+ return remaining;
407
+ }
408
+ resolveWaiters() {
409
+ if (this.waiters.length === 0) return;
410
+ const ready = [];
411
+ const remaining = [];
412
+ for (const w of this.waiters) {
413
+ if (this.flushVersion >= w.target) {
414
+ if (w.timer) clearTimeout(w.timer);
415
+ ready.push(w.resolve);
416
+ } else {
417
+ remaining.push(w);
418
+ }
419
+ }
420
+ this.waiters = remaining;
421
+ for (const r of ready) r();
422
+ }
423
+ };
424
+ var globalScheduler = new Scheduler();
425
+
426
+ // src/fx/noop.ts
427
+ Object.assign((_ev) => {
428
+ }, { cancel() {
429
+ } });
430
+ Object.assign((_ev) => {
431
+ }, { cancel() {
432
+ }, flush() {
433
+ } });
434
+ function enqueueUserCallback(fn) {
435
+ globalScheduler.enqueue(() => {
436
+ try {
437
+ fn();
438
+ } catch (err) {
439
+ logger.error("[Askr] FX handler error:", err);
440
+ }
441
+ });
442
+ }
443
+ function debounceEvent(ms, handler, options) {
444
+ const { leading = false, trailing = true } = options || {};
445
+ let timeoutId = null;
446
+ let lastEvent = null;
447
+ let lastCallTime = 0;
448
+ const debounced = function(ev) {
449
+ const now = Date.now();
450
+ lastEvent = ev;
451
+ if (timeoutId !== null) {
452
+ clearTimeout(timeoutId);
453
+ timeoutId = null;
454
+ }
455
+ if (leading && now - lastCallTime >= ms) {
456
+ enqueueUserCallback(() => handler.call(null, ev));
457
+ lastCallTime = now;
458
+ }
459
+ if (trailing) {
460
+ timeoutId = setTimeout(() => {
461
+ if (lastEvent) {
462
+ enqueueUserCallback(() => handler.call(null, lastEvent));
463
+ }
464
+ timeoutId = null;
465
+ lastCallTime = Date.now();
466
+ }, ms);
467
+ }
468
+ };
469
+ debounced.cancel = () => {
470
+ if (timeoutId !== null) {
471
+ clearTimeout(timeoutId);
472
+ timeoutId = null;
473
+ }
474
+ lastEvent = null;
475
+ };
476
+ debounced.flush = () => {
477
+ if (timeoutId !== null) {
478
+ clearTimeout(timeoutId);
479
+ const ev = lastEvent;
480
+ lastEvent = null;
481
+ timeoutId = null;
482
+ if (ev) enqueueUserCallback(() => handler.call(null, ev));
483
+ }
484
+ };
485
+ return debounced;
486
+ }
487
+ function throttleEvent(ms, handler, options) {
488
+ const { leading = true, trailing = true } = options || {};
489
+ let lastCallTime = 0;
490
+ let timeoutId = null;
491
+ let lastEvent = null;
492
+ const throttled = function(ev) {
493
+ const now = Date.now();
494
+ lastEvent = ev;
495
+ if (leading && now - lastCallTime >= ms) {
496
+ enqueueUserCallback(() => handler.call(null, ev));
497
+ lastCallTime = now;
498
+ if (timeoutId !== null) {
499
+ clearTimeout(timeoutId);
500
+ timeoutId = null;
501
+ }
502
+ } else if (!leading && lastCallTime === 0) {
503
+ lastCallTime = now;
504
+ }
505
+ if (trailing && timeoutId === null) {
506
+ const wait = ms - (now - lastCallTime);
507
+ timeoutId = setTimeout(
508
+ () => {
509
+ if (lastEvent)
510
+ enqueueUserCallback(() => handler.call(null, lastEvent));
511
+ lastCallTime = Date.now();
512
+ timeoutId = null;
513
+ },
514
+ Math.max(0, wait)
515
+ );
516
+ }
517
+ };
518
+ throttled.cancel = () => {
519
+ if (timeoutId !== null) {
520
+ clearTimeout(timeoutId);
521
+ timeoutId = null;
522
+ }
523
+ lastEvent = null;
524
+ };
525
+ return throttled;
526
+ }
527
+ function rafEvent(handler) {
528
+ let frameId = null;
529
+ let lastEvent = null;
530
+ const scheduleFrame = () => {
531
+ const rAF = typeof requestAnimationFrame !== "undefined" ? requestAnimationFrame : (cb) => setTimeout(() => cb(Date.now()), 16);
532
+ frameId = rAF(() => {
533
+ frameId = null;
534
+ if (lastEvent) {
535
+ const ev = lastEvent;
536
+ lastEvent = null;
537
+ enqueueUserCallback(() => handler.call(null, ev));
538
+ }
539
+ });
540
+ };
541
+ const fn = function(ev) {
542
+ lastEvent = ev;
543
+ if (frameId === null) scheduleFrame();
544
+ };
545
+ fn.cancel = () => {
546
+ if (frameId !== null) {
547
+ if (typeof cancelAnimationFrame !== "undefined" && typeof frameId === "number") {
548
+ cancelAnimationFrame(frameId);
549
+ } else {
550
+ clearTimeout(frameId);
551
+ }
552
+ frameId = null;
553
+ }
554
+ lastEvent = null;
555
+ };
556
+ return fn;
557
+ }
558
+ function scheduleTimeout(ms, fn) {
559
+ let id = setTimeout(() => {
560
+ id = null;
561
+ enqueueUserCallback(fn);
562
+ }, ms);
563
+ const cancel = () => {
564
+ if (id !== null) {
565
+ clearTimeout(id);
566
+ id = null;
567
+ }
568
+ };
569
+ return cancel;
570
+ }
571
+ function scheduleIdle(fn, options) {
572
+ let id = null;
573
+ let usingRIC = false;
574
+ if (typeof requestIdleCallback !== "undefined") {
575
+ usingRIC = true;
576
+ id = requestIdleCallback(() => {
577
+ id = null;
578
+ enqueueUserCallback(fn);
579
+ }, options);
580
+ } else {
581
+ id = setTimeout(() => {
582
+ id = null;
583
+ enqueueUserCallback(fn);
584
+ }, 0);
585
+ }
586
+ const cancel = () => {
587
+ if (id !== null) {
588
+ if (usingRIC && typeof cancelIdleCallback !== "undefined" && typeof id === "number") {
589
+ cancelIdleCallback(id);
590
+ } else {
591
+ clearTimeout(id);
592
+ }
593
+ id = null;
594
+ }
595
+ };
596
+ return cancel;
597
+ }
598
+ function scheduleRetry(fn, options) {
599
+ const {
600
+ maxAttempts = 3,
601
+ delayMs = 100,
602
+ backoff = (i) => delayMs * Math.pow(2, i)
603
+ } = options || {};
604
+ let cancelled = false;
605
+ const attempt = (index) => {
606
+ if (cancelled) return;
607
+ globalScheduler.enqueue(() => {
608
+ if (cancelled) return;
609
+ const p = fn();
610
+ p.then(
611
+ () => {
612
+ },
613
+ () => {
614
+ if (cancelled) return;
615
+ if (index + 1 < maxAttempts) {
616
+ const delay = backoff(index);
617
+ setTimeout(() => {
618
+ attempt(index + 1);
619
+ }, delay);
620
+ }
621
+ }
622
+ ).catch((e) => {
623
+ logger.error("[Askr] scheduleRetry error:", e);
624
+ });
625
+ });
626
+ };
627
+ attempt(0);
628
+ const cancel = () => {
629
+ cancelled = true;
630
+ };
631
+ return { cancel };
632
+ }
633
+
634
+ export { debounce, debounceEvent, defer, idle, once, raf, rafEvent, retry, scheduleIdle, scheduleRetry, scheduleTimeout, throttle, throttleEvent, timeout };
635
+ //# sourceMappingURL=fx.js.map
636
+ //# sourceMappingURL=fx.js.map