@askrjs/askr 0.0.2 → 0.0.4
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/README.md +8 -5
- package/dist/chunk-64C7W2AE.js +43 -0
- package/dist/chunk-64C7W2AE.js.map +1 -0
- package/dist/chunk-6FLMH4EL.js +124 -0
- package/dist/chunk-6FLMH4EL.js.map +1 -0
- package/dist/chunk-FJUXFA72.js +16 -0
- package/dist/chunk-FJUXFA72.js.map +1 -0
- package/dist/chunk-SALJX5PZ.js +26 -0
- package/dist/{chunk-KR6HG7HF.js.map → chunk-SALJX5PZ.js.map} +1 -1
- package/dist/{chunk-RJWOOUYV.js → chunk-VRAEBIJ3.js} +7 -9
- package/dist/chunk-VRAEBIJ3.js.map +1 -0
- package/dist/chunk-WTFWRSHB.js +98 -0
- package/dist/chunk-WTFWRSHB.js.map +1 -0
- package/dist/chunk-XHKZGJE3.js +2907 -0
- package/dist/chunk-XHKZGJE3.js.map +1 -0
- package/dist/chunk-Z5ZSTLYF.js +420 -0
- package/dist/chunk-Z5ZSTLYF.js.map +1 -0
- package/dist/fx/index.cjs +1193 -0
- package/dist/fx/index.cjs.map +1 -0
- package/dist/fx/index.d.cts +186 -0
- package/dist/fx/index.d.ts +186 -0
- package/dist/fx/index.js +418 -0
- package/dist/fx/index.js.map +1 -0
- package/dist/index.cjs +3020 -3506
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +74 -364
- package/dist/index.d.ts +74 -364
- package/dist/index.js +88 -656
- package/dist/index.js.map +1 -1
- package/dist/jsx/jsx-dev-runtime.cjs +1 -1
- package/dist/jsx/jsx-dev-runtime.cjs.map +1 -1
- package/dist/jsx/jsx-dev-runtime.d.cts +3 -2
- package/dist/jsx/jsx-dev-runtime.d.ts +3 -2
- package/dist/jsx/jsx-dev-runtime.js +2 -5
- package/dist/jsx/jsx-dev-runtime.js.map +1 -1
- package/dist/jsx/jsx-runtime.d.cts +2 -1
- package/dist/jsx/jsx-runtime.d.ts +2 -1
- package/dist/jsx/jsx-runtime.js +2 -4
- package/dist/{types-DLTViI21.d.cts → jsx-AzPM8gMS.d.cts} +6 -21
- package/dist/{types-DLTViI21.d.ts → jsx-AzPM8gMS.d.ts} +6 -21
- package/dist/navigate-LUVYHYZZ.js +17 -0
- package/dist/resources/index.cjs +1200 -0
- package/dist/resources/index.cjs.map +1 -0
- package/dist/resources/index.d.cts +21 -0
- package/dist/resources/index.d.ts +21 -0
- package/dist/resources/index.js +278 -0
- package/dist/resources/index.js.map +1 -0
- package/dist/{route-P5YQBT4T.js → route-BCND6MPK.js} +5 -4
- package/dist/router/index.cjs +3247 -0
- package/dist/router/index.cjs.map +1 -0
- package/dist/router/index.d.cts +64 -0
- package/dist/router/index.d.ts +64 -0
- package/dist/router/index.js +49 -0
- package/dist/router/index.js.map +1 -0
- package/dist/router-DaGtH1Sq.d.cts +36 -0
- package/dist/router-DaGtH1Sq.d.ts +36 -0
- package/dist/ssr/index.cjs +4059 -0
- package/dist/ssr/index.cjs.map +1 -0
- package/dist/ssr/index.d.cts +123 -0
- package/dist/ssr/index.d.ts +123 -0
- package/dist/ssr/index.js +666 -0
- package/dist/ssr/index.js.map +1 -0
- package/dist/types-CZ5sWur5.d.cts +23 -0
- package/dist/types-CZHOAiC1.d.ts +23 -0
- package/package.json +21 -7
- package/src/jsx/types.ts +4 -17
- package/dist/chunk-KR6HG7HF.js +0 -38
- package/dist/chunk-MIPES65F.js +0 -3023
- package/dist/chunk-MIPES65F.js.map +0 -1
- package/dist/chunk-PFOLLB6A.js +0 -524
- package/dist/chunk-PFOLLB6A.js.map +0 -1
- package/dist/chunk-QECQ2TF6.js +0 -28
- package/dist/chunk-QECQ2TF6.js.map +0 -1
- package/dist/chunk-RJWOOUYV.js.map +0 -1
- package/dist/navigate-SDZNA2ZE.js +0 -16
- package/dist/ssr-65K3IJ6B.js +0 -28
- package/dist/ssr-65K3IJ6B.js.map +0 -1
- /package/dist/{navigate-SDZNA2ZE.js.map → navigate-LUVYHYZZ.js.map} +0 -0
- /package/dist/{route-P5YQBT4T.js.map → route-BCND6MPK.js.map} +0 -0
|
@@ -0,0 +1,1193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/fx/index.ts
|
|
21
|
+
var fx_exports = {};
|
|
22
|
+
__export(fx_exports, {
|
|
23
|
+
debounce: () => debounce,
|
|
24
|
+
debounceEvent: () => debounceEvent,
|
|
25
|
+
defer: () => defer,
|
|
26
|
+
idle: () => idle,
|
|
27
|
+
once: () => once,
|
|
28
|
+
raf: () => raf,
|
|
29
|
+
rafEvent: () => rafEvent,
|
|
30
|
+
retry: () => retry,
|
|
31
|
+
scheduleIdle: () => scheduleIdle,
|
|
32
|
+
scheduleRetry: () => scheduleRetry,
|
|
33
|
+
scheduleTimeout: () => scheduleTimeout,
|
|
34
|
+
throttle: () => throttle,
|
|
35
|
+
throttleEvent: () => throttleEvent,
|
|
36
|
+
timeout: () => timeout
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(fx_exports);
|
|
39
|
+
|
|
40
|
+
// src/fx/timing.ts
|
|
41
|
+
function debounce(fn, ms, options) {
|
|
42
|
+
let timeoutId = null;
|
|
43
|
+
const { leading = false, trailing = true } = options || {};
|
|
44
|
+
let lastArgs = null;
|
|
45
|
+
let lastThis = null;
|
|
46
|
+
let lastCallTime = 0;
|
|
47
|
+
const debounced = function(...args) {
|
|
48
|
+
const callTime = Date.now();
|
|
49
|
+
lastArgs = args;
|
|
50
|
+
lastThis = this;
|
|
51
|
+
if (timeoutId !== null) {
|
|
52
|
+
clearTimeout(timeoutId);
|
|
53
|
+
}
|
|
54
|
+
if (leading && callTime - lastCallTime >= ms) {
|
|
55
|
+
fn.apply(this, args);
|
|
56
|
+
lastCallTime = callTime;
|
|
57
|
+
}
|
|
58
|
+
if (trailing) {
|
|
59
|
+
timeoutId = setTimeout(() => {
|
|
60
|
+
fn.apply(lastThis, lastArgs);
|
|
61
|
+
timeoutId = null;
|
|
62
|
+
lastCallTime = Date.now();
|
|
63
|
+
}, ms);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
debounced.cancel = () => {
|
|
67
|
+
if (timeoutId !== null) {
|
|
68
|
+
clearTimeout(timeoutId);
|
|
69
|
+
timeoutId = null;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
return debounced;
|
|
73
|
+
}
|
|
74
|
+
function throttle(fn, ms, options) {
|
|
75
|
+
let lastCallTime = 0;
|
|
76
|
+
let timeoutId = null;
|
|
77
|
+
const { leading = true, trailing = true } = options || {};
|
|
78
|
+
let lastArgs = null;
|
|
79
|
+
let lastThis = null;
|
|
80
|
+
const throttled = function(...args) {
|
|
81
|
+
const callTime = Date.now();
|
|
82
|
+
lastArgs = args;
|
|
83
|
+
lastThis = this;
|
|
84
|
+
if (leading && callTime - lastCallTime >= ms) {
|
|
85
|
+
fn.apply(this, args);
|
|
86
|
+
lastCallTime = callTime;
|
|
87
|
+
if (timeoutId !== null) {
|
|
88
|
+
clearTimeout(timeoutId);
|
|
89
|
+
timeoutId = null;
|
|
90
|
+
}
|
|
91
|
+
} else if (!leading && lastCallTime === 0) {
|
|
92
|
+
lastCallTime = callTime;
|
|
93
|
+
}
|
|
94
|
+
if (trailing && timeoutId === null) {
|
|
95
|
+
timeoutId = setTimeout(
|
|
96
|
+
() => {
|
|
97
|
+
fn.apply(lastThis, lastArgs);
|
|
98
|
+
lastCallTime = Date.now();
|
|
99
|
+
timeoutId = null;
|
|
100
|
+
},
|
|
101
|
+
ms - (callTime - lastCallTime)
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
throttled.cancel = () => {
|
|
106
|
+
if (timeoutId !== null) {
|
|
107
|
+
clearTimeout(timeoutId);
|
|
108
|
+
timeoutId = null;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
return throttled;
|
|
112
|
+
}
|
|
113
|
+
function once(fn) {
|
|
114
|
+
let called = false;
|
|
115
|
+
let result;
|
|
116
|
+
return ((...args) => {
|
|
117
|
+
if (!called) {
|
|
118
|
+
called = true;
|
|
119
|
+
result = fn(...args);
|
|
120
|
+
}
|
|
121
|
+
return result;
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
function defer(fn) {
|
|
125
|
+
Promise.resolve().then(fn);
|
|
126
|
+
}
|
|
127
|
+
function raf(fn) {
|
|
128
|
+
let frameId = null;
|
|
129
|
+
let lastArgs = null;
|
|
130
|
+
let lastThis = null;
|
|
131
|
+
return function(...args) {
|
|
132
|
+
lastArgs = args;
|
|
133
|
+
lastThis = this;
|
|
134
|
+
if (frameId === null) {
|
|
135
|
+
frameId = requestAnimationFrame(() => {
|
|
136
|
+
fn.apply(lastThis, lastArgs);
|
|
137
|
+
frameId = null;
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
function idle(fn, options) {
|
|
143
|
+
if (typeof requestIdleCallback !== "undefined") {
|
|
144
|
+
requestIdleCallback(fn, options ? { timeout: options.timeout } : void 0);
|
|
145
|
+
} else {
|
|
146
|
+
Promise.resolve().then(() => {
|
|
147
|
+
setTimeout(fn, 0);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function timeout(ms) {
|
|
152
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
153
|
+
}
|
|
154
|
+
async function retry(fn, options) {
|
|
155
|
+
const {
|
|
156
|
+
maxAttempts = 3,
|
|
157
|
+
delayMs = 100,
|
|
158
|
+
backoff = (i) => delayMs * Math.pow(2, i)
|
|
159
|
+
} = options || {};
|
|
160
|
+
let lastError = null;
|
|
161
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
162
|
+
try {
|
|
163
|
+
return await fn();
|
|
164
|
+
} catch (error) {
|
|
165
|
+
lastError = error;
|
|
166
|
+
if (attempt < maxAttempts - 1) {
|
|
167
|
+
const delay = backoff(attempt);
|
|
168
|
+
await timeout(delay);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
throw lastError || new Error("Retry failed");
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// src/dev/invariant.ts
|
|
176
|
+
function invariant(condition, message, context) {
|
|
177
|
+
if (!condition) {
|
|
178
|
+
const contextStr = context ? "\n" + JSON.stringify(context, null, 2) : "";
|
|
179
|
+
throw new Error(`[Askr Invariant] ${message}${contextStr}`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
function assertSchedulingPrecondition(condition, violationMessage) {
|
|
183
|
+
invariant(condition, `[Scheduler Precondition] ${violationMessage}`);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// src/dev/logger.ts
|
|
187
|
+
function callConsole(method, args) {
|
|
188
|
+
const c = typeof console !== "undefined" ? console : void 0;
|
|
189
|
+
if (!c) return;
|
|
190
|
+
const fn = c[method];
|
|
191
|
+
if (typeof fn === "function") {
|
|
192
|
+
try {
|
|
193
|
+
fn.apply(console, args);
|
|
194
|
+
} catch {
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
var logger = {
|
|
199
|
+
debug: (...args) => {
|
|
200
|
+
if (process.env.NODE_ENV === "production") return;
|
|
201
|
+
callConsole("debug", args);
|
|
202
|
+
},
|
|
203
|
+
info: (...args) => {
|
|
204
|
+
if (process.env.NODE_ENV === "production") return;
|
|
205
|
+
callConsole("info", args);
|
|
206
|
+
},
|
|
207
|
+
warn: (...args) => {
|
|
208
|
+
if (process.env.NODE_ENV === "production") return;
|
|
209
|
+
callConsole("warn", args);
|
|
210
|
+
},
|
|
211
|
+
error: (...args) => {
|
|
212
|
+
callConsole("error", args);
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
// src/runtime/scheduler.ts
|
|
217
|
+
var MAX_FLUSH_DEPTH = 50;
|
|
218
|
+
function isBulkCommitActive() {
|
|
219
|
+
try {
|
|
220
|
+
const fb = globalThis.__ASKR_FASTLANE;
|
|
221
|
+
return typeof fb?.isBulkCommitActive === "function" ? !!fb.isBulkCommitActive() : false;
|
|
222
|
+
} catch (e) {
|
|
223
|
+
void e;
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
var Scheduler = class {
|
|
228
|
+
constructor() {
|
|
229
|
+
this.q = [];
|
|
230
|
+
this.head = 0;
|
|
231
|
+
this.running = false;
|
|
232
|
+
this.inHandler = false;
|
|
233
|
+
this.depth = 0;
|
|
234
|
+
this.executionDepth = 0;
|
|
235
|
+
// for compat with existing diagnostics
|
|
236
|
+
// Monotonic flush version increments at end of each flush
|
|
237
|
+
this.flushVersion = 0;
|
|
238
|
+
// Best-effort microtask kick scheduling
|
|
239
|
+
this.kickScheduled = false;
|
|
240
|
+
// Escape hatch flag for runWithSyncProgress
|
|
241
|
+
this.allowSyncProgress = false;
|
|
242
|
+
// Waiters waiting for flushVersion >= target
|
|
243
|
+
this.waiters = [];
|
|
244
|
+
// Keep a lightweight taskCount for compatibility/diagnostics
|
|
245
|
+
this.taskCount = 0;
|
|
246
|
+
}
|
|
247
|
+
enqueue(task) {
|
|
248
|
+
assertSchedulingPrecondition(
|
|
249
|
+
typeof task === "function",
|
|
250
|
+
"enqueue() requires a function"
|
|
251
|
+
);
|
|
252
|
+
if (isBulkCommitActive() && !this.allowSyncProgress) {
|
|
253
|
+
if (process.env.NODE_ENV !== "production") {
|
|
254
|
+
throw new Error(
|
|
255
|
+
"[Scheduler] enqueue() during bulk commit (not allowed)"
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
this.q.push(task);
|
|
261
|
+
this.taskCount++;
|
|
262
|
+
if (!this.running && !this.kickScheduled && !this.inHandler && !isBulkCommitActive()) {
|
|
263
|
+
this.kickScheduled = true;
|
|
264
|
+
queueMicrotask(() => {
|
|
265
|
+
this.kickScheduled = false;
|
|
266
|
+
if (this.running) return;
|
|
267
|
+
if (isBulkCommitActive()) return;
|
|
268
|
+
try {
|
|
269
|
+
this.flush();
|
|
270
|
+
} catch (err) {
|
|
271
|
+
setTimeout(() => {
|
|
272
|
+
throw err;
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
flush() {
|
|
279
|
+
invariant(
|
|
280
|
+
!this.running,
|
|
281
|
+
"[Scheduler] flush() called while already running"
|
|
282
|
+
);
|
|
283
|
+
if (process.env.NODE_ENV !== "production") {
|
|
284
|
+
if (isBulkCommitActive() && !this.allowSyncProgress) {
|
|
285
|
+
throw new Error(
|
|
286
|
+
"[Scheduler] flush() started during bulk commit (not allowed)"
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
this.running = true;
|
|
291
|
+
this.depth = 0;
|
|
292
|
+
let fatal = null;
|
|
293
|
+
try {
|
|
294
|
+
while (this.head < this.q.length) {
|
|
295
|
+
this.depth++;
|
|
296
|
+
if (process.env.NODE_ENV !== "production" && this.depth > MAX_FLUSH_DEPTH) {
|
|
297
|
+
throw new Error(
|
|
298
|
+
`[Scheduler] exceeded MAX_FLUSH_DEPTH (${MAX_FLUSH_DEPTH}). Likely infinite update loop.`
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
const task = this.q[this.head++];
|
|
302
|
+
try {
|
|
303
|
+
this.executionDepth++;
|
|
304
|
+
task();
|
|
305
|
+
this.executionDepth--;
|
|
306
|
+
} catch (err) {
|
|
307
|
+
if (this.executionDepth > 0) this.executionDepth = 0;
|
|
308
|
+
fatal = err;
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
311
|
+
if (this.taskCount > 0) this.taskCount--;
|
|
312
|
+
}
|
|
313
|
+
} finally {
|
|
314
|
+
this.running = false;
|
|
315
|
+
this.depth = 0;
|
|
316
|
+
this.executionDepth = 0;
|
|
317
|
+
if (this.head >= this.q.length) {
|
|
318
|
+
this.q.length = 0;
|
|
319
|
+
this.head = 0;
|
|
320
|
+
} else if (this.head > 0) {
|
|
321
|
+
const remaining = this.q.length - this.head;
|
|
322
|
+
for (let i = 0; i < remaining; i++) {
|
|
323
|
+
this.q[i] = this.q[this.head + i];
|
|
324
|
+
}
|
|
325
|
+
this.q.length = remaining;
|
|
326
|
+
this.head = 0;
|
|
327
|
+
}
|
|
328
|
+
this.flushVersion++;
|
|
329
|
+
this.resolveWaiters();
|
|
330
|
+
}
|
|
331
|
+
if (fatal) throw fatal;
|
|
332
|
+
}
|
|
333
|
+
runWithSyncProgress(fn) {
|
|
334
|
+
const prev = this.allowSyncProgress;
|
|
335
|
+
this.allowSyncProgress = true;
|
|
336
|
+
const g = globalThis;
|
|
337
|
+
const origQueueMicrotask = g.queueMicrotask;
|
|
338
|
+
const origSetTimeout = g.setTimeout;
|
|
339
|
+
if (process.env.NODE_ENV !== "production") {
|
|
340
|
+
g.queueMicrotask = () => {
|
|
341
|
+
throw new Error(
|
|
342
|
+
"[Scheduler] queueMicrotask not allowed during runWithSyncProgress"
|
|
343
|
+
);
|
|
344
|
+
};
|
|
345
|
+
g.setTimeout = () => {
|
|
346
|
+
throw new Error(
|
|
347
|
+
"[Scheduler] setTimeout not allowed during runWithSyncProgress"
|
|
348
|
+
);
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
const startVersion = this.flushVersion;
|
|
352
|
+
try {
|
|
353
|
+
const res = fn();
|
|
354
|
+
if (!this.running && this.q.length - this.head > 0) {
|
|
355
|
+
this.flush();
|
|
356
|
+
}
|
|
357
|
+
if (process.env.NODE_ENV !== "production") {
|
|
358
|
+
if (this.q.length - this.head > 0) {
|
|
359
|
+
throw new Error(
|
|
360
|
+
"[Scheduler] tasks remain after runWithSyncProgress flush"
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
return res;
|
|
365
|
+
} finally {
|
|
366
|
+
if (process.env.NODE_ENV !== "production") {
|
|
367
|
+
g.queueMicrotask = origQueueMicrotask;
|
|
368
|
+
g.setTimeout = origSetTimeout;
|
|
369
|
+
}
|
|
370
|
+
try {
|
|
371
|
+
if (this.flushVersion === startVersion) {
|
|
372
|
+
this.flushVersion++;
|
|
373
|
+
this.resolveWaiters();
|
|
374
|
+
}
|
|
375
|
+
} catch (e) {
|
|
376
|
+
void e;
|
|
377
|
+
}
|
|
378
|
+
this.allowSyncProgress = prev;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
waitForFlush(targetVersion, timeoutMs = 2e3) {
|
|
382
|
+
const target = typeof targetVersion === "number" ? targetVersion : this.flushVersion + 1;
|
|
383
|
+
if (this.flushVersion >= target) return Promise.resolve();
|
|
384
|
+
return new Promise((resolve, reject) => {
|
|
385
|
+
const timer = setTimeout(() => {
|
|
386
|
+
const ns = globalThis.__ASKR__ || {};
|
|
387
|
+
const diag = {
|
|
388
|
+
flushVersion: this.flushVersion,
|
|
389
|
+
queueLen: this.q.length - this.head,
|
|
390
|
+
running: this.running,
|
|
391
|
+
inHandler: this.inHandler,
|
|
392
|
+
bulk: isBulkCommitActive(),
|
|
393
|
+
namespace: ns
|
|
394
|
+
};
|
|
395
|
+
reject(
|
|
396
|
+
new Error(
|
|
397
|
+
`waitForFlush timeout ${timeoutMs}ms: ${JSON.stringify(diag)}`
|
|
398
|
+
)
|
|
399
|
+
);
|
|
400
|
+
}, timeoutMs);
|
|
401
|
+
this.waiters.push({ target, resolve, reject, timer });
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
getState() {
|
|
405
|
+
return {
|
|
406
|
+
queueLength: this.q.length - this.head,
|
|
407
|
+
running: this.running,
|
|
408
|
+
depth: this.depth,
|
|
409
|
+
executionDepth: this.executionDepth,
|
|
410
|
+
taskCount: this.taskCount,
|
|
411
|
+
flushVersion: this.flushVersion,
|
|
412
|
+
// New fields for optional inspection
|
|
413
|
+
inHandler: this.inHandler,
|
|
414
|
+
allowSyncProgress: this.allowSyncProgress
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
setInHandler(v) {
|
|
418
|
+
this.inHandler = v;
|
|
419
|
+
}
|
|
420
|
+
isInHandler() {
|
|
421
|
+
return this.inHandler;
|
|
422
|
+
}
|
|
423
|
+
isExecuting() {
|
|
424
|
+
return this.running || this.executionDepth > 0;
|
|
425
|
+
}
|
|
426
|
+
// Clear pending synchronous tasks (used by fastlane enter/exit)
|
|
427
|
+
clearPendingSyncTasks() {
|
|
428
|
+
const remaining = this.q.length - this.head;
|
|
429
|
+
if (remaining <= 0) return 0;
|
|
430
|
+
if (this.running) {
|
|
431
|
+
this.q.length = this.head;
|
|
432
|
+
this.taskCount = Math.max(0, this.taskCount - remaining);
|
|
433
|
+
queueMicrotask(() => {
|
|
434
|
+
try {
|
|
435
|
+
this.flushVersion++;
|
|
436
|
+
this.resolveWaiters();
|
|
437
|
+
} catch (e) {
|
|
438
|
+
void e;
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
return remaining;
|
|
442
|
+
}
|
|
443
|
+
this.q.length = 0;
|
|
444
|
+
this.head = 0;
|
|
445
|
+
this.taskCount = Math.max(0, this.taskCount - remaining);
|
|
446
|
+
this.flushVersion++;
|
|
447
|
+
this.resolveWaiters();
|
|
448
|
+
return remaining;
|
|
449
|
+
}
|
|
450
|
+
resolveWaiters() {
|
|
451
|
+
if (this.waiters.length === 0) return;
|
|
452
|
+
const ready = [];
|
|
453
|
+
const remaining = [];
|
|
454
|
+
for (const w of this.waiters) {
|
|
455
|
+
if (this.flushVersion >= w.target) {
|
|
456
|
+
if (w.timer) clearTimeout(w.timer);
|
|
457
|
+
ready.push(w.resolve);
|
|
458
|
+
} else {
|
|
459
|
+
remaining.push(w);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
this.waiters = remaining;
|
|
463
|
+
for (const r of ready) r();
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
var globalScheduler = new Scheduler();
|
|
467
|
+
|
|
468
|
+
// src/renderer/utils.ts
|
|
469
|
+
function isIgnoredForPropChanges(key) {
|
|
470
|
+
if (key === "children" || key === "key") return true;
|
|
471
|
+
if (key.startsWith("on") && key.length > 2) return true;
|
|
472
|
+
if (key.startsWith("data-")) return true;
|
|
473
|
+
return false;
|
|
474
|
+
}
|
|
475
|
+
function hasPropChanged(el, key, value) {
|
|
476
|
+
try {
|
|
477
|
+
if (key === "class" || key === "className") {
|
|
478
|
+
return el.className !== String(value);
|
|
479
|
+
}
|
|
480
|
+
if (key === "value" || key === "checked") {
|
|
481
|
+
return el[key] !== value;
|
|
482
|
+
}
|
|
483
|
+
const attr = el.getAttribute(key);
|
|
484
|
+
if (value === void 0 || value === null || value === false) {
|
|
485
|
+
return attr !== null;
|
|
486
|
+
}
|
|
487
|
+
return String(value) !== attr;
|
|
488
|
+
} catch {
|
|
489
|
+
return true;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
function hasNonTrivialProps(props) {
|
|
493
|
+
for (const k of Object.keys(props)) {
|
|
494
|
+
if (isIgnoredForPropChanges(k)) continue;
|
|
495
|
+
return true;
|
|
496
|
+
}
|
|
497
|
+
return false;
|
|
498
|
+
}
|
|
499
|
+
function extractKey(vnode) {
|
|
500
|
+
if (typeof vnode !== "object" || vnode === null) return void 0;
|
|
501
|
+
const obj = vnode;
|
|
502
|
+
const rawKey = obj.key ?? obj.props?.key;
|
|
503
|
+
if (rawKey === void 0) return void 0;
|
|
504
|
+
return typeof rawKey === "symbol" ? String(rawKey) : rawKey;
|
|
505
|
+
}
|
|
506
|
+
function buildKeyMapFromChildren(parent) {
|
|
507
|
+
const map = /* @__PURE__ */ new Map();
|
|
508
|
+
for (let ch = parent.firstElementChild; ch; ch = ch.nextElementSibling) {
|
|
509
|
+
const k = ch.getAttribute("data-key");
|
|
510
|
+
if (k !== null) {
|
|
511
|
+
map.set(k, ch);
|
|
512
|
+
const n = Number(k);
|
|
513
|
+
if (!Number.isNaN(n)) map.set(n, ch);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
return map;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
// src/renderer/keyed.ts
|
|
520
|
+
var keyedElements = /* @__PURE__ */ new WeakMap();
|
|
521
|
+
function getKeyMapForElement(el) {
|
|
522
|
+
return keyedElements.get(el);
|
|
523
|
+
}
|
|
524
|
+
function populateKeyMapForElement(parent) {
|
|
525
|
+
try {
|
|
526
|
+
if (keyedElements.has(parent)) return;
|
|
527
|
+
let domMap = buildKeyMapFromChildren(parent);
|
|
528
|
+
if (domMap.size === 0) {
|
|
529
|
+
domMap = /* @__PURE__ */ new Map();
|
|
530
|
+
const children = Array.from(parent.children);
|
|
531
|
+
for (const ch of children) {
|
|
532
|
+
const text = (ch.textContent || "").trim();
|
|
533
|
+
if (text) {
|
|
534
|
+
domMap.set(text, ch);
|
|
535
|
+
const n = Number(text);
|
|
536
|
+
if (!Number.isNaN(n)) domMap.set(n, ch);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
if (domMap.size > 0) keyedElements.set(parent, domMap);
|
|
541
|
+
} catch {
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
function extractKeyedVnodes(newChildren) {
|
|
545
|
+
const result = [];
|
|
546
|
+
for (const child of newChildren) {
|
|
547
|
+
const key = extractKey(child);
|
|
548
|
+
if (key !== void 0) {
|
|
549
|
+
result.push({ key, vnode: child });
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
return result;
|
|
553
|
+
}
|
|
554
|
+
function computeLISLength(positions) {
|
|
555
|
+
const tails = [];
|
|
556
|
+
for (const pos of positions) {
|
|
557
|
+
if (pos === -1) continue;
|
|
558
|
+
let lo = 0;
|
|
559
|
+
let hi = tails.length;
|
|
560
|
+
while (lo < hi) {
|
|
561
|
+
const mid = lo + hi >> 1;
|
|
562
|
+
if (tails[mid] < pos) lo = mid + 1;
|
|
563
|
+
else hi = mid;
|
|
564
|
+
}
|
|
565
|
+
if (lo === tails.length) tails.push(pos);
|
|
566
|
+
else tails[lo] = pos;
|
|
567
|
+
}
|
|
568
|
+
return tails.length;
|
|
569
|
+
}
|
|
570
|
+
function checkVnodesHaveProps(keyedVnodes) {
|
|
571
|
+
for (const { vnode } of keyedVnodes) {
|
|
572
|
+
if (typeof vnode !== "object" || vnode === null) continue;
|
|
573
|
+
const vnodeObj = vnode;
|
|
574
|
+
if (vnodeObj.props && hasNonTrivialProps(vnodeObj.props)) {
|
|
575
|
+
return true;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
return false;
|
|
579
|
+
}
|
|
580
|
+
function checkVnodePropChanges(keyedVnodes, oldKeyMap) {
|
|
581
|
+
for (const { key, vnode } of keyedVnodes) {
|
|
582
|
+
const el = oldKeyMap?.get(key);
|
|
583
|
+
if (!el || typeof vnode !== "object" || vnode === null) continue;
|
|
584
|
+
const vnodeObj = vnode;
|
|
585
|
+
const props = vnodeObj.props || {};
|
|
586
|
+
for (const k of Object.keys(props)) {
|
|
587
|
+
if (isIgnoredForPropChanges(k)) continue;
|
|
588
|
+
if (hasPropChanged(el, k, props[k])) {
|
|
589
|
+
return true;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
return false;
|
|
594
|
+
}
|
|
595
|
+
function isKeyedReorderFastPathEligible(parent, newChildren, oldKeyMap) {
|
|
596
|
+
const keyedVnodes = extractKeyedVnodes(newChildren);
|
|
597
|
+
const totalKeyed = keyedVnodes.length;
|
|
598
|
+
const newKeyOrder = keyedVnodes.map((kv) => kv.key);
|
|
599
|
+
const oldKeyOrder = oldKeyMap ? Array.from(oldKeyMap.keys()) : [];
|
|
600
|
+
let moveCount = 0;
|
|
601
|
+
for (let i = 0; i < newKeyOrder.length; i++) {
|
|
602
|
+
const k = newKeyOrder[i];
|
|
603
|
+
if (i >= oldKeyOrder.length || oldKeyOrder[i] !== k || !oldKeyMap?.has(k)) {
|
|
604
|
+
moveCount++;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
const FAST_MOVE_THRESHOLD_ABS = 64;
|
|
608
|
+
const FAST_MOVE_THRESHOLD_REL = 0.1;
|
|
609
|
+
const cheapMoveTrigger = totalKeyed >= 128 && oldKeyOrder.length > 0 && moveCount > Math.max(
|
|
610
|
+
FAST_MOVE_THRESHOLD_ABS,
|
|
611
|
+
Math.floor(totalKeyed * FAST_MOVE_THRESHOLD_REL)
|
|
612
|
+
);
|
|
613
|
+
let lisTrigger = false;
|
|
614
|
+
let lisLen = 0;
|
|
615
|
+
if (totalKeyed >= 128) {
|
|
616
|
+
const parentChildren = Array.from(parent.children);
|
|
617
|
+
const positions = keyedVnodes.map(({ key }) => {
|
|
618
|
+
const el = oldKeyMap?.get(key);
|
|
619
|
+
return el?.parentElement === parent ? parentChildren.indexOf(el) : -1;
|
|
620
|
+
});
|
|
621
|
+
lisLen = computeLISLength(positions);
|
|
622
|
+
lisTrigger = lisLen < Math.floor(totalKeyed * 0.5);
|
|
623
|
+
}
|
|
624
|
+
const hasPropsPresent = checkVnodesHaveProps(keyedVnodes);
|
|
625
|
+
const hasPropChanges = checkVnodePropChanges(keyedVnodes, oldKeyMap);
|
|
626
|
+
const useFastPath = (cheapMoveTrigger || lisTrigger) && !hasPropChanges && !hasPropsPresent;
|
|
627
|
+
return {
|
|
628
|
+
useFastPath,
|
|
629
|
+
totalKeyed,
|
|
630
|
+
moveCount,
|
|
631
|
+
lisLen,
|
|
632
|
+
hasPropChanges
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
// src/common/jsx.ts
|
|
637
|
+
var Fragment = /* @__PURE__ */ Symbol.for("askr.fragment");
|
|
638
|
+
|
|
639
|
+
// src/runtime/dev-namespace.ts
|
|
640
|
+
function getDevNamespace() {
|
|
641
|
+
if (process.env.NODE_ENV === "production") return {};
|
|
642
|
+
try {
|
|
643
|
+
const g = globalThis;
|
|
644
|
+
if (!g.__ASKR__) g.__ASKR__ = {};
|
|
645
|
+
return g.__ASKR__;
|
|
646
|
+
} catch {
|
|
647
|
+
return {};
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
function setDevValue(key, value) {
|
|
651
|
+
if (process.env.NODE_ENV === "production") return;
|
|
652
|
+
try {
|
|
653
|
+
getDevNamespace()[key] = value;
|
|
654
|
+
} catch {
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
function getDevValue(key) {
|
|
658
|
+
if (process.env.NODE_ENV === "production") return void 0;
|
|
659
|
+
try {
|
|
660
|
+
return getDevNamespace()[key];
|
|
661
|
+
} catch {
|
|
662
|
+
return void 0;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
// src/runtime/fastlane.ts
|
|
667
|
+
var _bulkCommitActive = false;
|
|
668
|
+
var _appliedParents = null;
|
|
669
|
+
function enterBulkCommit() {
|
|
670
|
+
_bulkCommitActive = true;
|
|
671
|
+
_appliedParents = /* @__PURE__ */ new WeakSet();
|
|
672
|
+
try {
|
|
673
|
+
const cleared = globalScheduler.clearPendingSyncTasks?.() ?? 0;
|
|
674
|
+
setDevValue("__ASKR_FASTLANE_CLEARED_TASKS", cleared);
|
|
675
|
+
} catch (err) {
|
|
676
|
+
if (process.env.NODE_ENV !== "production") throw err;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
function exitBulkCommit() {
|
|
680
|
+
_bulkCommitActive = false;
|
|
681
|
+
_appliedParents = null;
|
|
682
|
+
}
|
|
683
|
+
function isBulkCommitActive2() {
|
|
684
|
+
return _bulkCommitActive;
|
|
685
|
+
}
|
|
686
|
+
function markFastPathApplied(parent) {
|
|
687
|
+
if (!_appliedParents) return;
|
|
688
|
+
try {
|
|
689
|
+
_appliedParents.add(parent);
|
|
690
|
+
} catch (e) {
|
|
691
|
+
void e;
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
function isFastPathApplied(parent) {
|
|
695
|
+
return !!(_appliedParents && _appliedParents.has(parent));
|
|
696
|
+
}
|
|
697
|
+
function finalizeReadSubscriptions(instance) {
|
|
698
|
+
const newSet = instance._pendingReadStates ?? /* @__PURE__ */ new Set();
|
|
699
|
+
const oldSet = instance._lastReadStates ?? /* @__PURE__ */ new Set();
|
|
700
|
+
const token = instance._currentRenderToken;
|
|
701
|
+
if (token === void 0) return;
|
|
702
|
+
for (const s of oldSet) {
|
|
703
|
+
if (!newSet.has(s)) {
|
|
704
|
+
const readers = s._readers;
|
|
705
|
+
if (readers) readers.delete(instance);
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
instance.lastRenderToken = token;
|
|
709
|
+
for (const s of newSet) {
|
|
710
|
+
let readers = s._readers;
|
|
711
|
+
if (!readers) {
|
|
712
|
+
readers = /* @__PURE__ */ new Map();
|
|
713
|
+
s._readers = readers;
|
|
714
|
+
}
|
|
715
|
+
readers.set(instance, instance.lastRenderToken ?? 0);
|
|
716
|
+
}
|
|
717
|
+
instance._lastReadStates = newSet;
|
|
718
|
+
instance._pendingReadStates = /* @__PURE__ */ new Set();
|
|
719
|
+
instance._currentRenderToken = void 0;
|
|
720
|
+
}
|
|
721
|
+
function unwrapFragmentForFastPath(vnode) {
|
|
722
|
+
if (!vnode || typeof vnode !== "object" || !("type" in vnode)) return vnode;
|
|
723
|
+
const v = vnode;
|
|
724
|
+
if (typeof v.type === "symbol" && (v.type === Fragment || String(v.type) === "Symbol(askr.fragment)")) {
|
|
725
|
+
const children = v.children || v.props?.children;
|
|
726
|
+
if (Array.isArray(children) && children.length > 0) {
|
|
727
|
+
for (const child of children) {
|
|
728
|
+
if (child && typeof child === "object" && "type" in child) {
|
|
729
|
+
const c = child;
|
|
730
|
+
if (typeof c.type === "string") {
|
|
731
|
+
return child;
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
return vnode;
|
|
738
|
+
}
|
|
739
|
+
function classifyUpdate(instance, result) {
|
|
740
|
+
const unwrappedResult = unwrapFragmentForFastPath(result);
|
|
741
|
+
if (!unwrappedResult || typeof unwrappedResult !== "object" || !("type" in unwrappedResult))
|
|
742
|
+
return { useFastPath: false, reason: "not-vnode" };
|
|
743
|
+
const vnode = unwrappedResult;
|
|
744
|
+
if (vnode == null || typeof vnode.type !== "string")
|
|
745
|
+
return { useFastPath: false, reason: "not-intrinsic" };
|
|
746
|
+
const parent = instance.target;
|
|
747
|
+
if (!parent) return { useFastPath: false, reason: "no-root" };
|
|
748
|
+
const firstChild = parent.children[0];
|
|
749
|
+
if (!firstChild) return { useFastPath: false, reason: "no-first-child" };
|
|
750
|
+
if (firstChild.tagName.toLowerCase() !== String(vnode.type).toLowerCase())
|
|
751
|
+
return { useFastPath: false, reason: "root-tag-mismatch" };
|
|
752
|
+
const children = vnode.children || vnode.props?.children;
|
|
753
|
+
if (!Array.isArray(children))
|
|
754
|
+
return { useFastPath: false, reason: "no-children-array" };
|
|
755
|
+
for (const c of children) {
|
|
756
|
+
if (typeof c === "object" && c !== null && "type" in c && typeof c.type === "function") {
|
|
757
|
+
return { useFastPath: false, reason: "component-child-present" };
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
if (instance.mountOperations.length > 0)
|
|
761
|
+
return { useFastPath: false, reason: "pending-mounts" };
|
|
762
|
+
try {
|
|
763
|
+
populateKeyMapForElement(firstChild);
|
|
764
|
+
} catch {
|
|
765
|
+
}
|
|
766
|
+
const oldKeyMap = getKeyMapForElement(firstChild);
|
|
767
|
+
const decision = isKeyedReorderFastPathEligible(
|
|
768
|
+
firstChild,
|
|
769
|
+
children,
|
|
770
|
+
oldKeyMap
|
|
771
|
+
);
|
|
772
|
+
if (!decision.useFastPath || decision.totalKeyed < 128)
|
|
773
|
+
return { ...decision, useFastPath: false, reason: "renderer-declined" };
|
|
774
|
+
return { ...decision, useFastPath: true };
|
|
775
|
+
}
|
|
776
|
+
function commitReorderOnly(instance, result) {
|
|
777
|
+
const evaluate = globalThis.__ASKR_RENDERER?.evaluate;
|
|
778
|
+
if (typeof evaluate !== "function") {
|
|
779
|
+
logger.warn(
|
|
780
|
+
"[Tempo][FASTPATH][DEV] renderer.evaluate not available; declining fast-lane"
|
|
781
|
+
);
|
|
782
|
+
return false;
|
|
783
|
+
}
|
|
784
|
+
const schedBefore = process.env.NODE_ENV !== "production" ? globalScheduler.getState() : null;
|
|
785
|
+
enterBulkCommit();
|
|
786
|
+
try {
|
|
787
|
+
globalScheduler.runWithSyncProgress(() => {
|
|
788
|
+
evaluate(result, instance.target);
|
|
789
|
+
try {
|
|
790
|
+
finalizeReadSubscriptions(instance);
|
|
791
|
+
} catch (e) {
|
|
792
|
+
if (process.env.NODE_ENV !== "production") throw e;
|
|
793
|
+
}
|
|
794
|
+
});
|
|
795
|
+
const clearedAfter = globalScheduler.clearPendingSyncTasks?.() ?? 0;
|
|
796
|
+
setDevValue("__FASTLANE_CLEARED_AFTER", clearedAfter);
|
|
797
|
+
if (process.env.NODE_ENV !== "production") {
|
|
798
|
+
validateFastLaneInvariants(instance, schedBefore);
|
|
799
|
+
}
|
|
800
|
+
return true;
|
|
801
|
+
} finally {
|
|
802
|
+
exitBulkCommit();
|
|
803
|
+
}
|
|
804
|
+
if (process.env.NODE_ENV !== "production") {
|
|
805
|
+
if (isBulkCommitActive2()) {
|
|
806
|
+
throw new Error(
|
|
807
|
+
"Fast-lane invariant violated: bulk commit flag still set after commit"
|
|
808
|
+
);
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
function validateFastLaneInvariants(instance, schedBefore) {
|
|
813
|
+
const commitCount = getDevValue("__LAST_FASTPATH_COMMIT_COUNT") ?? 0;
|
|
814
|
+
const invariants = {
|
|
815
|
+
commitCount,
|
|
816
|
+
mountOps: instance.mountOperations.length,
|
|
817
|
+
cleanupFns: instance.cleanupFns.length
|
|
818
|
+
};
|
|
819
|
+
setDevValue("__LAST_FASTLANE_INVARIANTS", invariants);
|
|
820
|
+
if (commitCount !== 1) {
|
|
821
|
+
console.error(
|
|
822
|
+
"[FASTLANE][INV] commitCount",
|
|
823
|
+
commitCount,
|
|
824
|
+
"diag",
|
|
825
|
+
globalThis.__ASKR_DIAG
|
|
826
|
+
);
|
|
827
|
+
throw new Error(
|
|
828
|
+
"Fast-lane invariant violated: expected exactly one DOM commit during reorder-only commit"
|
|
829
|
+
);
|
|
830
|
+
}
|
|
831
|
+
if (invariants.mountOps > 0) {
|
|
832
|
+
throw new Error(
|
|
833
|
+
"Fast-lane invariant violated: mount operations were registered during bulk commit"
|
|
834
|
+
);
|
|
835
|
+
}
|
|
836
|
+
if (invariants.cleanupFns > 0) {
|
|
837
|
+
throw new Error(
|
|
838
|
+
"Fast-lane invariant violated: cleanup functions were added during bulk commit"
|
|
839
|
+
);
|
|
840
|
+
}
|
|
841
|
+
const schedAfter = globalScheduler.getState();
|
|
842
|
+
if (schedBefore && schedAfter && schedAfter.taskCount > schedBefore.taskCount) {
|
|
843
|
+
console.error(
|
|
844
|
+
"[FASTLANE] schedBefore, schedAfter",
|
|
845
|
+
schedBefore,
|
|
846
|
+
schedAfter
|
|
847
|
+
);
|
|
848
|
+
console.error("[FASTLANE] enqueue logs", getDevValue("__ENQUEUE_LOGS"));
|
|
849
|
+
throw new Error(
|
|
850
|
+
"Fast-lane invariant violated: scheduler enqueued leftover work during bulk commit"
|
|
851
|
+
);
|
|
852
|
+
}
|
|
853
|
+
let finalState = globalScheduler.getState();
|
|
854
|
+
const executing = globalScheduler.isExecuting();
|
|
855
|
+
let outstandingAfter = Math.max(
|
|
856
|
+
0,
|
|
857
|
+
finalState.taskCount - (executing ? 1 : 0)
|
|
858
|
+
);
|
|
859
|
+
if (outstandingAfter !== 0) {
|
|
860
|
+
let attempts = 0;
|
|
861
|
+
while (attempts < 5) {
|
|
862
|
+
const cleared = globalScheduler.clearPendingSyncTasks?.() ?? 0;
|
|
863
|
+
if (cleared === 0) break;
|
|
864
|
+
attempts++;
|
|
865
|
+
}
|
|
866
|
+
finalState = globalScheduler.getState();
|
|
867
|
+
outstandingAfter = Math.max(
|
|
868
|
+
0,
|
|
869
|
+
finalState.taskCount - (globalScheduler.isExecuting() ? 1 : 0)
|
|
870
|
+
);
|
|
871
|
+
if (outstandingAfter !== 0) {
|
|
872
|
+
console.error(
|
|
873
|
+
"[FASTLANE] Post-commit enqueue logs:",
|
|
874
|
+
getDevValue("__ENQUEUE_LOGS")
|
|
875
|
+
);
|
|
876
|
+
console.error(
|
|
877
|
+
"[FASTLANE] Cleared counts:",
|
|
878
|
+
getDevValue("__FASTLANE_CLEARED_TASKS"),
|
|
879
|
+
getDevValue("__FASTLANE_CLEARED_AFTER")
|
|
880
|
+
);
|
|
881
|
+
throw new Error(
|
|
882
|
+
`Fast-lane invariant violated: scheduler has ${finalState.taskCount} pending task(s) after commit`
|
|
883
|
+
);
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
function tryRuntimeFastLaneSync(instance, result) {
|
|
888
|
+
const cls = classifyUpdate(instance, result);
|
|
889
|
+
if (!cls.useFastPath) {
|
|
890
|
+
setDevValue("__LAST_FASTPATH_STATS", void 0);
|
|
891
|
+
setDevValue("__LAST_FASTPATH_COMMIT_COUNT", 0);
|
|
892
|
+
return false;
|
|
893
|
+
}
|
|
894
|
+
try {
|
|
895
|
+
return commitReorderOnly(instance, result);
|
|
896
|
+
} catch (err) {
|
|
897
|
+
if (process.env.NODE_ENV !== "production") throw err;
|
|
898
|
+
return false;
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
if (typeof globalThis !== "undefined") {
|
|
902
|
+
globalThis.__ASKR_FASTLANE = {
|
|
903
|
+
isBulkCommitActive: isBulkCommitActive2,
|
|
904
|
+
enterBulkCommit,
|
|
905
|
+
exitBulkCommit,
|
|
906
|
+
tryRuntimeFastLaneSync,
|
|
907
|
+
markFastPathApplied,
|
|
908
|
+
isFastPathApplied
|
|
909
|
+
};
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
// src/runtime/component.ts
|
|
913
|
+
var currentInstance = null;
|
|
914
|
+
function getCurrentComponentInstance() {
|
|
915
|
+
return currentInstance;
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
// src/fx/noop.ts
|
|
919
|
+
var noopEventListener = Object.assign((_ev) => {
|
|
920
|
+
}, { cancel() {
|
|
921
|
+
} });
|
|
922
|
+
var noopEventListenerWithFlush = Object.assign((_ev) => {
|
|
923
|
+
}, { cancel() {
|
|
924
|
+
}, flush() {
|
|
925
|
+
} });
|
|
926
|
+
|
|
927
|
+
// src/fx/fx.ts
|
|
928
|
+
function throwIfDuringRender() {
|
|
929
|
+
const inst = getCurrentComponentInstance();
|
|
930
|
+
if (inst !== null) {
|
|
931
|
+
throw new Error(
|
|
932
|
+
"[Askr] calling FX handler during render is not allowed. Move calls to event handlers or effects."
|
|
933
|
+
);
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
function enqueueUserCallback(fn) {
|
|
937
|
+
globalScheduler.enqueue(() => {
|
|
938
|
+
try {
|
|
939
|
+
fn();
|
|
940
|
+
} catch (err) {
|
|
941
|
+
logger.error("[Askr] FX handler error:", err);
|
|
942
|
+
}
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
function debounceEvent(ms, handler, options) {
|
|
946
|
+
const { leading = false, trailing = true } = options || {};
|
|
947
|
+
const inst = getCurrentComponentInstance();
|
|
948
|
+
if (inst && inst.ssr) {
|
|
949
|
+
return noopEventListenerWithFlush;
|
|
950
|
+
}
|
|
951
|
+
let timeoutId = null;
|
|
952
|
+
let lastEvent = null;
|
|
953
|
+
let lastCallTime = 0;
|
|
954
|
+
const debounced = function(ev) {
|
|
955
|
+
throwIfDuringRender();
|
|
956
|
+
const now = Date.now();
|
|
957
|
+
lastEvent = ev;
|
|
958
|
+
if (timeoutId !== null) {
|
|
959
|
+
clearTimeout(timeoutId);
|
|
960
|
+
timeoutId = null;
|
|
961
|
+
}
|
|
962
|
+
if (leading && now - lastCallTime >= ms) {
|
|
963
|
+
enqueueUserCallback(() => handler.call(null, ev));
|
|
964
|
+
lastCallTime = now;
|
|
965
|
+
}
|
|
966
|
+
if (trailing) {
|
|
967
|
+
timeoutId = setTimeout(() => {
|
|
968
|
+
if (lastEvent) {
|
|
969
|
+
enqueueUserCallback(() => handler.call(null, lastEvent));
|
|
970
|
+
}
|
|
971
|
+
timeoutId = null;
|
|
972
|
+
lastCallTime = Date.now();
|
|
973
|
+
}, ms);
|
|
974
|
+
}
|
|
975
|
+
};
|
|
976
|
+
debounced.cancel = () => {
|
|
977
|
+
if (timeoutId !== null) {
|
|
978
|
+
clearTimeout(timeoutId);
|
|
979
|
+
timeoutId = null;
|
|
980
|
+
}
|
|
981
|
+
lastEvent = null;
|
|
982
|
+
};
|
|
983
|
+
debounced.flush = () => {
|
|
984
|
+
if (timeoutId !== null) {
|
|
985
|
+
clearTimeout(timeoutId);
|
|
986
|
+
const ev = lastEvent;
|
|
987
|
+
lastEvent = null;
|
|
988
|
+
timeoutId = null;
|
|
989
|
+
if (ev) enqueueUserCallback(() => handler.call(null, ev));
|
|
990
|
+
}
|
|
991
|
+
};
|
|
992
|
+
if (inst) {
|
|
993
|
+
inst.cleanupFns.push(() => {
|
|
994
|
+
debounced.cancel();
|
|
995
|
+
});
|
|
996
|
+
}
|
|
997
|
+
return debounced;
|
|
998
|
+
}
|
|
999
|
+
function throttleEvent(ms, handler, options) {
|
|
1000
|
+
const { leading = true, trailing = true } = options || {};
|
|
1001
|
+
const inst = getCurrentComponentInstance();
|
|
1002
|
+
if (inst && inst.ssr) {
|
|
1003
|
+
return noopEventListener;
|
|
1004
|
+
}
|
|
1005
|
+
let lastCallTime = 0;
|
|
1006
|
+
let timeoutId = null;
|
|
1007
|
+
let lastEvent = null;
|
|
1008
|
+
const throttled = function(ev) {
|
|
1009
|
+
throwIfDuringRender();
|
|
1010
|
+
const now = Date.now();
|
|
1011
|
+
lastEvent = ev;
|
|
1012
|
+
if (leading && now - lastCallTime >= ms) {
|
|
1013
|
+
enqueueUserCallback(() => handler.call(null, ev));
|
|
1014
|
+
lastCallTime = now;
|
|
1015
|
+
if (timeoutId !== null) {
|
|
1016
|
+
clearTimeout(timeoutId);
|
|
1017
|
+
timeoutId = null;
|
|
1018
|
+
}
|
|
1019
|
+
} else if (!leading && lastCallTime === 0) {
|
|
1020
|
+
lastCallTime = now;
|
|
1021
|
+
}
|
|
1022
|
+
if (trailing && timeoutId === null) {
|
|
1023
|
+
const wait = ms - (now - lastCallTime);
|
|
1024
|
+
timeoutId = setTimeout(
|
|
1025
|
+
() => {
|
|
1026
|
+
if (lastEvent)
|
|
1027
|
+
enqueueUserCallback(() => handler.call(null, lastEvent));
|
|
1028
|
+
lastCallTime = Date.now();
|
|
1029
|
+
timeoutId = null;
|
|
1030
|
+
},
|
|
1031
|
+
Math.max(0, wait)
|
|
1032
|
+
);
|
|
1033
|
+
}
|
|
1034
|
+
};
|
|
1035
|
+
throttled.cancel = () => {
|
|
1036
|
+
if (timeoutId !== null) {
|
|
1037
|
+
clearTimeout(timeoutId);
|
|
1038
|
+
timeoutId = null;
|
|
1039
|
+
}
|
|
1040
|
+
lastEvent = null;
|
|
1041
|
+
};
|
|
1042
|
+
if (inst) {
|
|
1043
|
+
inst.cleanupFns.push(() => throttled.cancel());
|
|
1044
|
+
}
|
|
1045
|
+
return throttled;
|
|
1046
|
+
}
|
|
1047
|
+
function rafEvent(handler) {
|
|
1048
|
+
const inst = getCurrentComponentInstance();
|
|
1049
|
+
if (inst && inst.ssr) {
|
|
1050
|
+
return noopEventListener;
|
|
1051
|
+
}
|
|
1052
|
+
let frameId = null;
|
|
1053
|
+
let lastEvent = null;
|
|
1054
|
+
const scheduleFrame = () => {
|
|
1055
|
+
const rAF = typeof requestAnimationFrame !== "undefined" ? requestAnimationFrame : (cb) => setTimeout(() => cb(Date.now()), 16);
|
|
1056
|
+
frameId = rAF(() => {
|
|
1057
|
+
frameId = null;
|
|
1058
|
+
if (lastEvent) {
|
|
1059
|
+
const ev = lastEvent;
|
|
1060
|
+
lastEvent = null;
|
|
1061
|
+
enqueueUserCallback(() => handler.call(null, ev));
|
|
1062
|
+
}
|
|
1063
|
+
});
|
|
1064
|
+
};
|
|
1065
|
+
const fn = function(ev) {
|
|
1066
|
+
throwIfDuringRender();
|
|
1067
|
+
lastEvent = ev;
|
|
1068
|
+
if (frameId === null) scheduleFrame();
|
|
1069
|
+
};
|
|
1070
|
+
fn.cancel = () => {
|
|
1071
|
+
if (frameId !== null) {
|
|
1072
|
+
if (typeof cancelAnimationFrame !== "undefined" && typeof frameId === "number") {
|
|
1073
|
+
cancelAnimationFrame(frameId);
|
|
1074
|
+
} else {
|
|
1075
|
+
clearTimeout(frameId);
|
|
1076
|
+
}
|
|
1077
|
+
frameId = null;
|
|
1078
|
+
}
|
|
1079
|
+
lastEvent = null;
|
|
1080
|
+
};
|
|
1081
|
+
if (inst) inst.cleanupFns.push(() => fn.cancel());
|
|
1082
|
+
return fn;
|
|
1083
|
+
}
|
|
1084
|
+
function scheduleTimeout(ms, fn) {
|
|
1085
|
+
throwIfDuringRender();
|
|
1086
|
+
const inst = getCurrentComponentInstance();
|
|
1087
|
+
if (inst && inst.ssr) {
|
|
1088
|
+
return () => {
|
|
1089
|
+
};
|
|
1090
|
+
}
|
|
1091
|
+
let id = setTimeout(() => {
|
|
1092
|
+
id = null;
|
|
1093
|
+
enqueueUserCallback(fn);
|
|
1094
|
+
}, ms);
|
|
1095
|
+
const cancel = () => {
|
|
1096
|
+
if (id !== null) {
|
|
1097
|
+
clearTimeout(id);
|
|
1098
|
+
id = null;
|
|
1099
|
+
}
|
|
1100
|
+
};
|
|
1101
|
+
if (inst) inst.cleanupFns.push(cancel);
|
|
1102
|
+
return cancel;
|
|
1103
|
+
}
|
|
1104
|
+
function scheduleIdle(fn, options) {
|
|
1105
|
+
throwIfDuringRender();
|
|
1106
|
+
const inst = getCurrentComponentInstance();
|
|
1107
|
+
if (inst && inst.ssr) return () => {
|
|
1108
|
+
};
|
|
1109
|
+
let id = null;
|
|
1110
|
+
let usingRIC = false;
|
|
1111
|
+
if (typeof requestIdleCallback !== "undefined") {
|
|
1112
|
+
usingRIC = true;
|
|
1113
|
+
id = requestIdleCallback(() => {
|
|
1114
|
+
id = null;
|
|
1115
|
+
enqueueUserCallback(fn);
|
|
1116
|
+
}, options);
|
|
1117
|
+
} else {
|
|
1118
|
+
id = setTimeout(() => {
|
|
1119
|
+
id = null;
|
|
1120
|
+
enqueueUserCallback(fn);
|
|
1121
|
+
}, 0);
|
|
1122
|
+
}
|
|
1123
|
+
const cancel = () => {
|
|
1124
|
+
if (id !== null) {
|
|
1125
|
+
if (usingRIC && typeof cancelIdleCallback !== "undefined" && typeof id === "number") {
|
|
1126
|
+
cancelIdleCallback(id);
|
|
1127
|
+
} else {
|
|
1128
|
+
clearTimeout(id);
|
|
1129
|
+
}
|
|
1130
|
+
id = null;
|
|
1131
|
+
}
|
|
1132
|
+
};
|
|
1133
|
+
if (inst) inst.cleanupFns.push(cancel);
|
|
1134
|
+
return cancel;
|
|
1135
|
+
}
|
|
1136
|
+
function scheduleRetry(fn, options) {
|
|
1137
|
+
throwIfDuringRender();
|
|
1138
|
+
const inst = getCurrentComponentInstance();
|
|
1139
|
+
if (inst && inst.ssr) return { cancel: () => {
|
|
1140
|
+
} };
|
|
1141
|
+
const {
|
|
1142
|
+
maxAttempts = 3,
|
|
1143
|
+
delayMs = 100,
|
|
1144
|
+
backoff = (i) => delayMs * Math.pow(2, i)
|
|
1145
|
+
} = options || {};
|
|
1146
|
+
let cancelled = false;
|
|
1147
|
+
const attempt = (index) => {
|
|
1148
|
+
if (cancelled) return;
|
|
1149
|
+
globalScheduler.enqueue(() => {
|
|
1150
|
+
if (cancelled) return;
|
|
1151
|
+
const p = fn();
|
|
1152
|
+
p.then(
|
|
1153
|
+
() => {
|
|
1154
|
+
},
|
|
1155
|
+
() => {
|
|
1156
|
+
if (cancelled) return;
|
|
1157
|
+
if (index + 1 < maxAttempts) {
|
|
1158
|
+
const delay = backoff(index);
|
|
1159
|
+
setTimeout(() => {
|
|
1160
|
+
attempt(index + 1);
|
|
1161
|
+
}, delay);
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
).catch((e) => {
|
|
1165
|
+
logger.error("[Askr] scheduleRetry error:", e);
|
|
1166
|
+
});
|
|
1167
|
+
});
|
|
1168
|
+
};
|
|
1169
|
+
attempt(0);
|
|
1170
|
+
const cancel = () => {
|
|
1171
|
+
cancelled = true;
|
|
1172
|
+
};
|
|
1173
|
+
if (inst) inst.cleanupFns.push(cancel);
|
|
1174
|
+
return { cancel };
|
|
1175
|
+
}
|
|
1176
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1177
|
+
0 && (module.exports = {
|
|
1178
|
+
debounce,
|
|
1179
|
+
debounceEvent,
|
|
1180
|
+
defer,
|
|
1181
|
+
idle,
|
|
1182
|
+
once,
|
|
1183
|
+
raf,
|
|
1184
|
+
rafEvent,
|
|
1185
|
+
retry,
|
|
1186
|
+
scheduleIdle,
|
|
1187
|
+
scheduleRetry,
|
|
1188
|
+
scheduleTimeout,
|
|
1189
|
+
throttle,
|
|
1190
|
+
throttleEvent,
|
|
1191
|
+
timeout
|
|
1192
|
+
});
|
|
1193
|
+
//# sourceMappingURL=index.cjs.map
|