@askrjs/askr 0.0.9 → 0.0.10

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 (49) hide show
  1. package/dist/chunk-37RC6ZT3.js +1 -0
  2. package/dist/chunk-4RTKQ7SC.js +1 -0
  3. package/dist/chunk-534P7OMI.js +2 -0
  4. package/dist/chunk-62D2TNHX.js +1 -0
  5. package/dist/chunk-CI6AOGB5.js +1 -0
  6. package/dist/chunk-D2JSJKCW.js +1 -0
  7. package/dist/chunk-DPHQ4JD6.js +1 -0
  8. package/dist/chunk-FFSNBDHN.js +1 -0
  9. package/dist/chunk-JJDSOK6C.js +1 -0
  10. package/dist/chunk-LOSY3JCR.js +1 -0
  11. package/dist/chunk-OQMK7H2R.js +1 -0
  12. package/dist/chunk-Q7GRUZHR.js +1 -0
  13. package/dist/chunk-XKFPM4SY.js +2 -0
  14. package/dist/chunk-Y3Q3LOFT.js +1 -0
  15. package/dist/chunk-YRY4OLQF.js +1 -0
  16. package/dist/{component-DHAn9JxU.d.ts → component-mtwBWhUr.d.ts} +1 -1
  17. package/dist/for/index.d.ts +61 -0
  18. package/dist/for/index.js +1 -0
  19. package/dist/foundations/core.d.ts +449 -0
  20. package/dist/foundations/core.js +1 -0
  21. package/dist/foundations/index.d.ts +4 -722
  22. package/dist/foundations/index.js +1 -1274
  23. package/dist/foundations/structures.d.ts +223 -0
  24. package/dist/foundations/structures.js +1 -0
  25. package/dist/fx/index.js +1 -636
  26. package/dist/index.d.ts +2 -2
  27. package/dist/index.js +1 -3955
  28. package/dist/jsx-dev-runtime.js +1 -17
  29. package/dist/jsx-runtime.js +1 -23
  30. package/dist/logger-MPMIVXAP.js +1 -0
  31. package/dist/main-EPE35NMW.js +65 -0
  32. package/dist/navigate-6CC6IXXF.js +1 -0
  33. package/dist/resources/index.d.ts +1 -1
  34. package/dist/resources/index.js +1 -792
  35. package/dist/route-4QZ3RYN5.js +1 -0
  36. package/dist/router/index.d.ts +5 -0
  37. package/dist/router/index.js +1 -3194
  38. package/dist/ssr/index.js +1 -3935
  39. package/dist/vite/index.js +1 -2306
  40. package/package.json +19 -5
  41. package/dist/foundations/index.js.map +0 -1
  42. package/dist/fx/index.js.map +0 -1
  43. package/dist/index.js.map +0 -1
  44. package/dist/jsx-dev-runtime.js.map +0 -1
  45. package/dist/jsx-runtime.js.map +0 -1
  46. package/dist/resources/index.js.map +0 -1
  47. package/dist/router/index.js.map +0 -1
  48. package/dist/ssr/index.js.map +0 -1
  49. package/dist/vite/index.js.map +0 -1
@@ -1,792 +1 @@
1
- // src/dev/invariant.ts
2
- function invariant(condition, message, context) {
3
- if (!condition) {
4
- const contextStr = "";
5
- throw new Error(`[Askr Invariant] ${message}${contextStr}`);
6
- }
7
- }
8
- function assertSchedulingPrecondition(condition, violationMessage) {
9
- invariant(condition, `[Scheduler Precondition] ${violationMessage}`);
10
- }
11
-
12
- // src/dev/logger.ts
13
- function callConsole(method, args) {
14
- const c = typeof console !== "undefined" ? console : void 0;
15
- if (!c) return;
16
- const fn = c[method];
17
- if (typeof fn === "function") {
18
- try {
19
- fn.apply(console, args);
20
- } catch {
21
- }
22
- }
23
- }
24
- var logger = {
25
- debug: (...args) => {
26
- if (process.env.NODE_ENV === "production") return;
27
- callConsole("debug", args);
28
- },
29
- info: (...args) => {
30
- if (process.env.NODE_ENV === "production") return;
31
- callConsole("info", args);
32
- },
33
- warn: (...args) => {
34
- if (process.env.NODE_ENV === "production") return;
35
- callConsole("warn", args);
36
- },
37
- error: (...args) => {
38
- callConsole("error", args);
39
- }
40
- };
41
-
42
- // src/runtime/scheduler.ts
43
- var MAX_FLUSH_DEPTH = 50;
44
- function isBulkCommitActive() {
45
- try {
46
- const fb = globalThis.__ASKR_FASTLANE;
47
- return typeof fb?.isBulkCommitActive === "function" ? !!fb.isBulkCommitActive() : false;
48
- } catch (e) {
49
- return false;
50
- }
51
- }
52
- var Scheduler = class {
53
- constructor() {
54
- this.q = [];
55
- this.head = 0;
56
- this.running = false;
57
- this.inHandler = false;
58
- this.depth = 0;
59
- this.executionDepth = 0;
60
- // for compat with existing diagnostics
61
- // Monotonic flush version increments at end of each flush
62
- this.flushVersion = 0;
63
- // Best-effort microtask kick scheduling
64
- this.kickScheduled = false;
65
- // Escape hatch flag for runWithSyncProgress
66
- this.allowSyncProgress = false;
67
- // Waiters waiting for flushVersion >= target
68
- this.waiters = [];
69
- // Keep a lightweight taskCount for compatibility/diagnostics
70
- this.taskCount = 0;
71
- }
72
- enqueue(task) {
73
- assertSchedulingPrecondition(
74
- typeof task === "function",
75
- "enqueue() requires a function"
76
- );
77
- if (isBulkCommitActive() && !this.allowSyncProgress) {
78
- if (process.env.NODE_ENV !== "production") {
79
- throw new Error(
80
- "[Scheduler] enqueue() during bulk commit (not allowed)"
81
- );
82
- }
83
- return;
84
- }
85
- this.q.push(task);
86
- this.taskCount++;
87
- if (!this.running && !this.kickScheduled && !this.inHandler && !isBulkCommitActive()) {
88
- this.kickScheduled = true;
89
- queueMicrotask(() => {
90
- this.kickScheduled = false;
91
- if (this.running) return;
92
- if (isBulkCommitActive()) return;
93
- try {
94
- this.flush();
95
- } catch (err) {
96
- setTimeout(() => {
97
- throw err;
98
- });
99
- }
100
- });
101
- }
102
- }
103
- flush() {
104
- invariant(
105
- !this.running,
106
- "[Scheduler] flush() called while already running"
107
- );
108
- if (process.env.NODE_ENV !== "production") {
109
- if (isBulkCommitActive() && !this.allowSyncProgress) {
110
- throw new Error(
111
- "[Scheduler] flush() started during bulk commit (not allowed)"
112
- );
113
- }
114
- }
115
- this.running = true;
116
- this.depth = 0;
117
- let fatal = null;
118
- try {
119
- while (this.head < this.q.length) {
120
- this.depth++;
121
- if (process.env.NODE_ENV !== "production" && this.depth > MAX_FLUSH_DEPTH) {
122
- throw new Error(
123
- `[Scheduler] exceeded MAX_FLUSH_DEPTH (${MAX_FLUSH_DEPTH}). Likely infinite update loop.`
124
- );
125
- }
126
- const task = this.q[this.head++];
127
- try {
128
- this.executionDepth++;
129
- task();
130
- this.executionDepth--;
131
- } catch (err) {
132
- if (this.executionDepth > 0) this.executionDepth = 0;
133
- fatal = err;
134
- break;
135
- }
136
- if (this.taskCount > 0) this.taskCount--;
137
- }
138
- } finally {
139
- this.running = false;
140
- this.depth = 0;
141
- this.executionDepth = 0;
142
- if (this.head >= this.q.length) {
143
- this.q.length = 0;
144
- this.head = 0;
145
- } else if (this.head > 0) {
146
- const remaining = this.q.length - this.head;
147
- for (let i = 0; i < remaining; i++) {
148
- this.q[i] = this.q[this.head + i];
149
- }
150
- this.q.length = remaining;
151
- this.head = 0;
152
- }
153
- this.flushVersion++;
154
- this.resolveWaiters();
155
- }
156
- if (fatal) throw fatal;
157
- }
158
- runWithSyncProgress(fn) {
159
- const prev = this.allowSyncProgress;
160
- this.allowSyncProgress = true;
161
- const g = globalThis;
162
- const origQueueMicrotask = g.queueMicrotask;
163
- const origSetTimeout = g.setTimeout;
164
- if (process.env.NODE_ENV !== "production") {
165
- g.queueMicrotask = () => {
166
- throw new Error(
167
- "[Scheduler] queueMicrotask not allowed during runWithSyncProgress"
168
- );
169
- };
170
- g.setTimeout = () => {
171
- throw new Error(
172
- "[Scheduler] setTimeout not allowed during runWithSyncProgress"
173
- );
174
- };
175
- }
176
- const startVersion = this.flushVersion;
177
- try {
178
- const res = fn();
179
- if (!this.running && this.q.length - this.head > 0) {
180
- this.flush();
181
- }
182
- if (process.env.NODE_ENV !== "production") {
183
- if (this.q.length - this.head > 0) {
184
- throw new Error(
185
- "[Scheduler] tasks remain after runWithSyncProgress flush"
186
- );
187
- }
188
- }
189
- return res;
190
- } finally {
191
- if (process.env.NODE_ENV !== "production") {
192
- g.queueMicrotask = origQueueMicrotask;
193
- g.setTimeout = origSetTimeout;
194
- }
195
- try {
196
- if (this.flushVersion === startVersion) {
197
- this.flushVersion++;
198
- this.resolveWaiters();
199
- }
200
- } catch (e) {
201
- }
202
- this.allowSyncProgress = prev;
203
- }
204
- }
205
- waitForFlush(targetVersion, timeoutMs = 2e3) {
206
- const target = typeof targetVersion === "number" ? targetVersion : this.flushVersion + 1;
207
- if (this.flushVersion >= target) return Promise.resolve();
208
- return new Promise((resolve, reject) => {
209
- const timer = setTimeout(() => {
210
- const ns = globalThis.__ASKR__ || {};
211
- const diag = {
212
- flushVersion: this.flushVersion,
213
- queueLen: this.q.length - this.head,
214
- running: this.running,
215
- inHandler: this.inHandler,
216
- bulk: isBulkCommitActive(),
217
- namespace: ns
218
- };
219
- reject(
220
- new Error(
221
- `waitForFlush timeout ${timeoutMs}ms: ${JSON.stringify(diag)}`
222
- )
223
- );
224
- }, timeoutMs);
225
- this.waiters.push({ target, resolve, reject, timer });
226
- });
227
- }
228
- getState() {
229
- return {
230
- queueLength: this.q.length - this.head,
231
- running: this.running,
232
- depth: this.depth,
233
- executionDepth: this.executionDepth,
234
- taskCount: this.taskCount,
235
- flushVersion: this.flushVersion,
236
- // New fields for optional inspection
237
- inHandler: this.inHandler,
238
- allowSyncProgress: this.allowSyncProgress
239
- };
240
- }
241
- setInHandler(v) {
242
- this.inHandler = v;
243
- }
244
- isInHandler() {
245
- return this.inHandler;
246
- }
247
- isExecuting() {
248
- return this.running || this.executionDepth > 0;
249
- }
250
- // Clear pending synchronous tasks (used by fastlane enter/exit)
251
- clearPendingSyncTasks() {
252
- const remaining = this.q.length - this.head;
253
- if (remaining <= 0) return 0;
254
- if (this.running) {
255
- this.q.length = this.head;
256
- this.taskCount = Math.max(0, this.taskCount - remaining);
257
- queueMicrotask(() => {
258
- try {
259
- this.flushVersion++;
260
- this.resolveWaiters();
261
- } catch (e) {
262
- }
263
- });
264
- return remaining;
265
- }
266
- this.q.length = 0;
267
- this.head = 0;
268
- this.taskCount = Math.max(0, this.taskCount - remaining);
269
- this.flushVersion++;
270
- this.resolveWaiters();
271
- return remaining;
272
- }
273
- resolveWaiters() {
274
- if (this.waiters.length === 0) return;
275
- const ready = [];
276
- const remaining = [];
277
- for (const w of this.waiters) {
278
- if (this.flushVersion >= w.target) {
279
- if (w.timer) clearTimeout(w.timer);
280
- ready.push(w.resolve);
281
- } else {
282
- remaining.push(w);
283
- }
284
- }
285
- this.waiters = remaining;
286
- for (const r of ready) r();
287
- }
288
- };
289
- var globalScheduler = new Scheduler();
290
-
291
- // src/common/jsx.ts
292
- var Fragment = /* @__PURE__ */ Symbol.for("askr.fragment");
293
-
294
- // src/renderer/utils.ts
295
- function isIgnoredForPropChanges(key) {
296
- if (key === "children" || key === "key") return true;
297
- if (key.startsWith("on") && key.length > 2) return true;
298
- if (key.startsWith("data-")) return true;
299
- return false;
300
- }
301
- function hasPropChanged(el, key, value) {
302
- try {
303
- if (key === "class" || key === "className") {
304
- return el.className !== String(value);
305
- }
306
- if (key === "value" || key === "checked") {
307
- return el[key] !== value;
308
- }
309
- const attr = el.getAttribute(key);
310
- if (value === void 0 || value === null || value === false) {
311
- return attr !== null;
312
- }
313
- return String(value) !== attr;
314
- } catch {
315
- return true;
316
- }
317
- }
318
- function hasNonTrivialProps(props) {
319
- for (const k of Object.keys(props)) {
320
- if (isIgnoredForPropChanges(k)) continue;
321
- return true;
322
- }
323
- return false;
324
- }
325
- function extractKey(vnode) {
326
- if (typeof vnode !== "object" || vnode === null) return void 0;
327
- const obj = vnode;
328
- const rawKey = obj.key ?? obj.props?.key;
329
- if (rawKey === void 0) return void 0;
330
- return typeof rawKey === "symbol" ? String(rawKey) : rawKey;
331
- }
332
- function buildKeyMapFromChildren(parent) {
333
- const map = /* @__PURE__ */ new Map();
334
- for (let ch = parent.firstElementChild; ch; ch = ch.nextElementSibling) {
335
- const k = ch.getAttribute("data-key");
336
- if (k !== null) {
337
- map.set(k, ch);
338
- const n = Number(k);
339
- if (!Number.isNaN(n)) map.set(n, ch);
340
- }
341
- }
342
- return map;
343
- }
344
-
345
- // src/renderer/keyed.ts
346
- var keyedElements = /* @__PURE__ */ new WeakMap();
347
- function getKeyMapForElement(el) {
348
- return keyedElements.get(el);
349
- }
350
- function populateKeyMapForElement(parent) {
351
- try {
352
- if (keyedElements.has(parent)) return;
353
- let domMap = buildKeyMapFromChildren(parent);
354
- if (domMap.size === 0) {
355
- domMap = /* @__PURE__ */ new Map();
356
- const children = Array.from(parent.children);
357
- for (const ch of children) {
358
- const text = (ch.textContent || "").trim();
359
- if (text) {
360
- domMap.set(text, ch);
361
- const n = Number(text);
362
- if (!Number.isNaN(n)) domMap.set(n, ch);
363
- }
364
- }
365
- }
366
- if (domMap.size > 0) keyedElements.set(parent, domMap);
367
- } catch {
368
- }
369
- }
370
- function extractKeyedVnodes(newChildren) {
371
- const result = [];
372
- for (const child of newChildren) {
373
- const key = extractKey(child);
374
- if (key !== void 0) {
375
- result.push({ key, vnode: child });
376
- }
377
- }
378
- return result;
379
- }
380
- function computeLISLength(positions) {
381
- const tails = [];
382
- for (const pos of positions) {
383
- if (pos === -1) continue;
384
- let lo = 0;
385
- let hi = tails.length;
386
- while (lo < hi) {
387
- const mid = lo + hi >> 1;
388
- if (tails[mid] < pos) lo = mid + 1;
389
- else hi = mid;
390
- }
391
- if (lo === tails.length) tails.push(pos);
392
- else tails[lo] = pos;
393
- }
394
- return tails.length;
395
- }
396
- function checkVnodesHaveProps(keyedVnodes) {
397
- for (const { vnode } of keyedVnodes) {
398
- if (typeof vnode !== "object" || vnode === null) continue;
399
- const vnodeObj = vnode;
400
- if (vnodeObj.props && hasNonTrivialProps(vnodeObj.props)) {
401
- return true;
402
- }
403
- }
404
- return false;
405
- }
406
- function checkVnodePropChanges(keyedVnodes, oldKeyMap) {
407
- for (const { key, vnode } of keyedVnodes) {
408
- const el = oldKeyMap?.get(key);
409
- if (!el || typeof vnode !== "object" || vnode === null) continue;
410
- const vnodeObj = vnode;
411
- const props = vnodeObj.props || {};
412
- for (const k of Object.keys(props)) {
413
- if (isIgnoredForPropChanges(k)) continue;
414
- if (hasPropChanged(el, k, props[k])) {
415
- return true;
416
- }
417
- }
418
- }
419
- return false;
420
- }
421
- function isKeyedReorderFastPathEligible(parent, newChildren, oldKeyMap) {
422
- const keyedVnodes = extractKeyedVnodes(newChildren);
423
- const totalKeyed = keyedVnodes.length;
424
- const newKeyOrder = keyedVnodes.map((kv) => kv.key);
425
- const oldKeyOrder = oldKeyMap ? Array.from(oldKeyMap.keys()) : [];
426
- let moveCount = 0;
427
- for (let i = 0; i < newKeyOrder.length; i++) {
428
- const k = newKeyOrder[i];
429
- if (i >= oldKeyOrder.length || oldKeyOrder[i] !== k || !oldKeyMap?.has(k)) {
430
- moveCount++;
431
- }
432
- }
433
- const FAST_MOVE_THRESHOLD_ABS = 64;
434
- const FAST_MOVE_THRESHOLD_REL = 0.1;
435
- const cheapMoveTrigger = totalKeyed >= 128 && oldKeyOrder.length > 0 && moveCount > Math.max(
436
- FAST_MOVE_THRESHOLD_ABS,
437
- Math.floor(totalKeyed * FAST_MOVE_THRESHOLD_REL)
438
- );
439
- let lisTrigger = false;
440
- let lisLen = 0;
441
- if (totalKeyed >= 128) {
442
- const parentChildren = Array.from(parent.children);
443
- const positions = keyedVnodes.map(({ key }) => {
444
- const el = oldKeyMap?.get(key);
445
- return el?.parentElement === parent ? parentChildren.indexOf(el) : -1;
446
- });
447
- lisLen = computeLISLength(positions);
448
- lisTrigger = lisLen < Math.floor(totalKeyed * 0.5);
449
- }
450
- const hasPropsPresent = checkVnodesHaveProps(keyedVnodes);
451
- const hasPropChanges = checkVnodePropChanges(keyedVnodes, oldKeyMap);
452
- const useFastPath = (cheapMoveTrigger || lisTrigger) && !hasPropChanges && !hasPropsPresent;
453
- return {
454
- useFastPath,
455
- totalKeyed,
456
- moveCount,
457
- lisLen,
458
- hasPropChanges
459
- };
460
- }
461
-
462
- // src/runtime/dev-namespace.ts
463
- function getDevNamespace() {
464
- if (process.env.NODE_ENV === "production") return {};
465
- try {
466
- const g = globalThis;
467
- if (!g.__ASKR__) g.__ASKR__ = {};
468
- return g.__ASKR__;
469
- } catch {
470
- return {};
471
- }
472
- }
473
- function setDevValue(key, value) {
474
- if (process.env.NODE_ENV === "production") return;
475
- try {
476
- getDevNamespace()[key] = value;
477
- } catch {
478
- }
479
- }
480
- function getDevValue(key) {
481
- if (process.env.NODE_ENV === "production") return void 0;
482
- try {
483
- return getDevNamespace()[key];
484
- } catch {
485
- return void 0;
486
- }
487
- }
488
-
489
- // src/runtime/fastlane.ts
490
- var _bulkCommitActive = false;
491
- var _appliedParents = null;
492
- function enterBulkCommit() {
493
- _bulkCommitActive = true;
494
- _appliedParents = /* @__PURE__ */ new WeakSet();
495
- try {
496
- const cleared = globalScheduler.clearPendingSyncTasks?.() ?? 0;
497
- setDevValue("__ASKR_FASTLANE_CLEARED_TASKS", cleared);
498
- } catch (err) {
499
- if (process.env.NODE_ENV !== "production") throw err;
500
- }
501
- }
502
- function exitBulkCommit() {
503
- _bulkCommitActive = false;
504
- _appliedParents = null;
505
- }
506
- function isBulkCommitActive2() {
507
- return _bulkCommitActive;
508
- }
509
- function markFastPathApplied(parent) {
510
- if (!_appliedParents) return;
511
- try {
512
- _appliedParents.add(parent);
513
- } catch (e) {
514
- }
515
- }
516
- function isFastPathApplied(parent) {
517
- return !!(_appliedParents && _appliedParents.has(parent));
518
- }
519
- function finalizeReadSubscriptions(instance) {
520
- const newSet = instance._pendingReadStates ?? /* @__PURE__ */ new Set();
521
- const oldSet = instance._lastReadStates ?? /* @__PURE__ */ new Set();
522
- const token = instance._currentRenderToken;
523
- if (token === void 0) return;
524
- for (const s of oldSet) {
525
- if (!newSet.has(s)) {
526
- const readers = s._readers;
527
- if (readers) readers.delete(instance);
528
- }
529
- }
530
- instance.lastRenderToken = token;
531
- for (const s of newSet) {
532
- let readers = s._readers;
533
- if (!readers) {
534
- readers = /* @__PURE__ */ new Map();
535
- s._readers = readers;
536
- }
537
- readers.set(instance, instance.lastRenderToken ?? 0);
538
- }
539
- instance._lastReadStates = newSet;
540
- instance._pendingReadStates = /* @__PURE__ */ new Set();
541
- instance._currentRenderToken = void 0;
542
- }
543
- function unwrapFragmentForFastPath(vnode) {
544
- if (!vnode || typeof vnode !== "object" || !("type" in vnode)) return vnode;
545
- const v = vnode;
546
- if (typeof v.type === "symbol" && (v.type === Fragment || String(v.type) === "Symbol(askr.fragment)")) {
547
- const children = v.children || v.props?.children;
548
- if (Array.isArray(children) && children.length > 0) {
549
- for (const child of children) {
550
- if (child && typeof child === "object" && "type" in child) {
551
- const c = child;
552
- if (typeof c.type === "string") {
553
- return child;
554
- }
555
- }
556
- }
557
- }
558
- }
559
- return vnode;
560
- }
561
- function classifyUpdate(instance, result) {
562
- const unwrappedResult = unwrapFragmentForFastPath(result);
563
- if (!unwrappedResult || typeof unwrappedResult !== "object" || !("type" in unwrappedResult))
564
- return { useFastPath: false, reason: "not-vnode" };
565
- const vnode = unwrappedResult;
566
- if (vnode == null || typeof vnode.type !== "string")
567
- return { useFastPath: false, reason: "not-intrinsic" };
568
- const parent = instance.target;
569
- if (!parent) return { useFastPath: false, reason: "no-root" };
570
- const firstChild = parent.children[0];
571
- if (!firstChild) return { useFastPath: false, reason: "no-first-child" };
572
- if (firstChild.tagName.toLowerCase() !== String(vnode.type).toLowerCase())
573
- return { useFastPath: false, reason: "root-tag-mismatch" };
574
- const children = vnode.children || vnode.props?.children;
575
- if (!Array.isArray(children))
576
- return { useFastPath: false, reason: "no-children-array" };
577
- for (const c of children) {
578
- if (typeof c === "object" && c !== null && "type" in c && typeof c.type === "function") {
579
- return { useFastPath: false, reason: "component-child-present" };
580
- }
581
- }
582
- if (instance.mountOperations.length > 0)
583
- return { useFastPath: false, reason: "pending-mounts" };
584
- try {
585
- populateKeyMapForElement(firstChild);
586
- } catch {
587
- }
588
- const oldKeyMap = getKeyMapForElement(firstChild);
589
- const decision = isKeyedReorderFastPathEligible(
590
- firstChild,
591
- children,
592
- oldKeyMap
593
- );
594
- if (!decision.useFastPath || decision.totalKeyed < 128)
595
- return { ...decision, useFastPath: false, reason: "renderer-declined" };
596
- return { ...decision, useFastPath: true };
597
- }
598
- function commitReorderOnly(instance, result) {
599
- const evaluate = globalThis.__ASKR_RENDERER?.evaluate;
600
- if (typeof evaluate !== "function") {
601
- logger.warn(
602
- "[Tempo][FASTPATH][DEV] renderer.evaluate not available; declining fast-lane"
603
- );
604
- return false;
605
- }
606
- const schedBefore = process.env.NODE_ENV !== "production" ? globalScheduler.getState() : null;
607
- enterBulkCommit();
608
- try {
609
- globalScheduler.runWithSyncProgress(() => {
610
- evaluate(result, instance.target);
611
- try {
612
- finalizeReadSubscriptions(instance);
613
- } catch (e) {
614
- if (process.env.NODE_ENV !== "production") throw e;
615
- }
616
- });
617
- const clearedAfter = globalScheduler.clearPendingSyncTasks?.() ?? 0;
618
- setDevValue("__FASTLANE_CLEARED_AFTER", clearedAfter);
619
- if (process.env.NODE_ENV !== "production") {
620
- validateFastLaneInvariants(instance, schedBefore);
621
- }
622
- return true;
623
- } finally {
624
- exitBulkCommit();
625
- }
626
- if (process.env.NODE_ENV !== "production") {
627
- if (isBulkCommitActive2()) {
628
- throw new Error(
629
- "Fast-lane invariant violated: bulk commit flag still set after commit"
630
- );
631
- }
632
- }
633
- }
634
- function validateFastLaneInvariants(instance, schedBefore) {
635
- const commitCount = getDevValue("__LAST_FASTPATH_COMMIT_COUNT") ?? 0;
636
- const invariants = {
637
- commitCount,
638
- mountOps: instance.mountOperations.length,
639
- cleanupFns: instance.cleanupFns.length
640
- };
641
- setDevValue("__LAST_FASTLANE_INVARIANTS", invariants);
642
- if (commitCount !== 1) {
643
- console.error(
644
- "[FASTLANE][INV] commitCount",
645
- commitCount,
646
- "diag",
647
- globalThis.__ASKR_DIAG
648
- );
649
- throw new Error(
650
- "Fast-lane invariant violated: expected exactly one DOM commit during reorder-only commit"
651
- );
652
- }
653
- if (invariants.mountOps > 0) {
654
- throw new Error(
655
- "Fast-lane invariant violated: mount operations were registered during bulk commit"
656
- );
657
- }
658
- if (invariants.cleanupFns > 0) {
659
- throw new Error(
660
- "Fast-lane invariant violated: cleanup functions were added during bulk commit"
661
- );
662
- }
663
- const schedAfter = globalScheduler.getState();
664
- if (schedBefore && schedAfter && schedAfter.taskCount > schedBefore.taskCount) {
665
- console.error(
666
- "[FASTLANE] schedBefore, schedAfter",
667
- schedBefore,
668
- schedAfter
669
- );
670
- console.error("[FASTLANE] enqueue logs", getDevValue("__ENQUEUE_LOGS"));
671
- throw new Error(
672
- "Fast-lane invariant violated: scheduler enqueued leftover work during bulk commit"
673
- );
674
- }
675
- let finalState = globalScheduler.getState();
676
- const executing = globalScheduler.isExecuting();
677
- let outstandingAfter = Math.max(
678
- 0,
679
- finalState.taskCount - (executing ? 1 : 0)
680
- );
681
- if (outstandingAfter !== 0) {
682
- let attempts = 0;
683
- while (attempts < 5) {
684
- const cleared = globalScheduler.clearPendingSyncTasks?.() ?? 0;
685
- if (cleared === 0) break;
686
- attempts++;
687
- }
688
- finalState = globalScheduler.getState();
689
- outstandingAfter = Math.max(
690
- 0,
691
- finalState.taskCount - (globalScheduler.isExecuting() ? 1 : 0)
692
- );
693
- if (outstandingAfter !== 0) {
694
- console.error(
695
- "[FASTLANE] Post-commit enqueue logs:",
696
- getDevValue("__ENQUEUE_LOGS")
697
- );
698
- console.error(
699
- "[FASTLANE] Cleared counts:",
700
- getDevValue("__FASTLANE_CLEARED_TASKS"),
701
- getDevValue("__FASTLANE_CLEARED_AFTER")
702
- );
703
- throw new Error(
704
- `Fast-lane invariant violated: scheduler has ${finalState.taskCount} pending task(s) after commit`
705
- );
706
- }
707
- }
708
- }
709
- function tryRuntimeFastLaneSync(instance, result) {
710
- const cls = classifyUpdate(instance, result);
711
- if (!cls.useFastPath) {
712
- setDevValue("__LAST_FASTPATH_STATS", void 0);
713
- setDevValue("__LAST_FASTPATH_COMMIT_COUNT", 0);
714
- return false;
715
- }
716
- try {
717
- return commitReorderOnly(instance, result);
718
- } catch (err) {
719
- if (process.env.NODE_ENV !== "production") throw err;
720
- return false;
721
- }
722
- }
723
- if (typeof globalThis !== "undefined") {
724
- globalThis.__ASKR_FASTLANE = {
725
- isBulkCommitActive: isBulkCommitActive2,
726
- enterBulkCommit,
727
- exitBulkCommit,
728
- tryRuntimeFastLaneSync,
729
- markFastPathApplied,
730
- isFastPathApplied
731
- };
732
- }
733
- function getSignal() {
734
- {
735
- throw new Error(
736
- "getSignal() can only be called during component render execution. Ensure you are calling this from inside your component function."
737
- );
738
- }
739
- }
740
-
741
- // src/runtime/ssr-bridge.ts
742
- var defaultBridge = {
743
- getCurrentSSRContext() {
744
- return null;
745
- },
746
- throwSSRDataMissing() {
747
- throw new Error(
748
- "[Askr] SSR data missing (SSR bridge not installed). If you are rendering on the server, ensure you are using the askr SSR entrypoints."
749
- );
750
- },
751
- getCurrentRenderData() {
752
- return null;
753
- },
754
- getNextKey() {
755
- throw new Error(
756
- "[Askr] getNextKey() called outside SSR render phase (SSR bridge not installed)."
757
- );
758
- }
759
- };
760
- var bridge = defaultBridge;
761
- function getSSRBridge() {
762
- return bridge;
763
- }
764
-
765
- // src/runtime/operations.ts
766
- function resource(fn, deps = []) {
767
- {
768
- const ssr2 = getSSRBridge();
769
- const renderData2 = ssr2.getCurrentRenderData();
770
- if (renderData2) {
771
- const key = ssr2.getNextKey();
772
- if (!(key in renderData2)) {
773
- ssr2.throwSSRDataMissing();
774
- }
775
- const val = renderData2[key];
776
- return {
777
- value: val,
778
- pending: false,
779
- error: null,
780
- refresh: () => {
781
- }
782
- };
783
- }
784
- throw new Error(
785
- "[Askr] resource() must be called during component render inside an app. Do not create resources at module scope or outside render."
786
- );
787
- }
788
- }
789
-
790
- export { getSignal, resource };
791
- //# sourceMappingURL=index.js.map
792
- //# sourceMappingURL=index.js.map
1
+ import {c,a as a$1}from'../chunk-YRY4OLQF.js';import {a}from'../chunk-LOSY3JCR.js';import {j,d as d$1,b,c as c$1}from'../chunk-534P7OMI.js';export{m as getSignal}from'../chunk-534P7OMI.js';import'../chunk-JJDSOK6C.js';import {a as a$2}from'../chunk-OQMK7H2R.js';import'../chunk-37RC6ZT3.js';import'../chunk-62D2TNHX.js';var d=class{constructor(o,a,i){this.value=null;this.pending=true;this.error=null;this.generation=0;this.controller=null;this.deps=null;this.resourceFrame=null;this.subscribers=new Set;this.fn=o,this.deps=a?a.slice():null,this.resourceFrame=i,this.snapshot={value:null,pending:true,error:null,refresh:()=>this.refresh()};}subscribe(o){return this.subscribers.add(o),()=>this.subscribers.delete(o)}notifySubscribers(){this.snapshot.value=this.value,this.snapshot.pending=this.pending,this.snapshot.error=this.error;for(let o of this.subscribers)o();}start(o=false,a=true){let i=this.generation;this.controller?.abort();let l=new AbortController;this.controller=l,this.pending=true,this.error=null,a&&this.notifySubscribers();let u;try{u=c$1(this.resourceFrame,()=>this.fn({signal:l.signal}));}catch(t){this.pending=false,this.error=t,a&&this.notifySubscribers();return}if(!(u instanceof Promise)){this.value=u,this.pending=false,this.error=null,a&&this.notifySubscribers();return}o&&c().throwSSRDataMissing(),u.then(t=>{this.generation===i&&this.controller===l&&(this.value=t,this.pending=false,this.error=null,this.notifySubscribers());}).catch(t=>{if(this.generation===i&&this.controller===l){this.pending=false,this.error=t;try{this.ownerName?a$2.error(`[Askr] Async resource error in ${this.ownerName}:`,t):a$2.error("[Askr] Async resource error:",t);}catch{}this.notifySubscribers();}});}refresh(){this.generation++,this.controller?.abort(),this.start();}abort(){this.controller?.abort();}};function x(b$1,o=[]){let a$2=j(),i=a$2;if(!a$2){let r=c(),e=r.getCurrentRenderData();if(e){let n=r.getNextKey();return n in e||r.throwSSRDataMissing(),{value:e[n],pending:false,error:null,refresh:()=>{}}}throw r.getCurrentSSRContext()&&r.throwSSRDataMissing(),new Error("[Askr] resource() must be called during component render inside an app. Do not create resources at module scope or outside render.")}let l=c(),u=l.getCurrentRenderData();if(u){let r=l.getNextKey();r in u||l.throwSSRDataMissing();let e=u[r],p=a({cell:void 0,snapshot:{value:e,pending:false,error:null,refresh:()=>{}}}),n=p();return n.snapshot.value=e,n.snapshot.pending=false,n.snapshot.error=null,p.set(n),n.snapshot}let t=a({cell:void 0,snapshot:{value:null,pending:true,error:null,refresh:()=>{}}}),c$1=t();if(!c$1.cell){let r=d$1(),e=new d(b$1,o,r);e.ownerName=i.fn?.name||"<anonymous>",c$1.cell=e,c$1.snapshot=e.snapshot;let p=e.subscribe(()=>{let n=t();n.snapshot.value=e.snapshot.value,n.snapshot.pending=e.snapshot.pending,n.snapshot.error=e.snapshot.error,t.set(n);try{i._enqueueRun?.();}catch{}});if(i.cleanupFns.push(()=>{p(),e.abort();}),i.ssr){if(e.start(true,false),!e.pending){let n=t();n.snapshot.value=e.value,n.snapshot.pending=e.pending,n.snapshot.error=e.error;}}else b.enqueue(()=>{try{e.start(!1,!1);}catch(n){let h=t();h.snapshot.value=e.value,h.snapshot.pending=e.pending,h.snapshot.error=n??null,t.set(h),i._enqueueRun?.();return}if(!e.pending){let n=t();n.snapshot.value=e.value,n.snapshot.pending=e.pending,n.snapshot.error=e.error,t.set(n),i._enqueueRun?.();}});}let s=c$1.cell;if(!s.deps||s.deps.length!==o.length||s.deps.some((r,e)=>r!==o[e])){s.deps=o.slice(),s.generation++,s.pending=true,s.error=null;try{if(i.ssr){if(s.start(!0,!1),!s.pending){let r=t();r.snapshot.value=s.value,r.snapshot.pending=s.pending,r.snapshot.error=s.error;}}else b.enqueue(()=>{if(s.start(!1,!1),!s.pending){let r=t();r.snapshot.value=s.value,r.snapshot.pending=s.pending,r.snapshot.error=s.error,t.set(r),i._enqueueRun?.();}});}catch(r){if(r instanceof a$1)throw r;s.error=r,s.pending=false;let e=t();e.snapshot.value=s.value,e.snapshot.pending=s.pending,e.snapshot.error=s.error;}}return c$1.snapshot}export{x as resource};