@askrjs/askr 0.0.69 → 0.0.71

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 (64) hide show
  1. package/capabilities.json +66 -0
  2. package/dist/actions/index.d.ts +1 -1
  3. package/dist/actions/index.js +9 -2
  4. package/dist/activity-C2tPn9Fr.js +152 -0
  5. package/dist/activity-DZ-NCYr8.d.ts +10 -0
  6. package/dist/{authoring-uaJ556aG.js → authoring-CXmUcaCe.js} +2 -2
  7. package/dist/benchmark.d.ts +1 -1
  8. package/dist/benchmark.js +6 -6
  9. package/dist/boot/index.d.ts +2 -2
  10. package/dist/boot/index.js +1 -1
  11. package/dist/{boot-aTei9rjA.js → boot-DIKbEA4Y.js} +11 -10
  12. package/dist/{cleanup-UyStxIHG.js → cleanup-D8Ufd9Ix.js} +29 -8
  13. package/dist/components/index.d.ts +1 -0
  14. package/dist/components/index.js +1 -0
  15. package/dist/control/index.d.ts +1 -1
  16. package/dist/control/index.js +1 -1
  17. package/dist/{control-CA45Yvvu.js → control-DVRBkN2X.js} +7 -2
  18. package/dist/{csp-nonce-HGZ0vbqT.js → csp-nonce-CwSRP3Jl.js} +16 -1
  19. package/dist/css-BuPaTOfe.js +70 -0
  20. package/dist/data/index.js +3 -3
  21. package/dist/{data-DHt_zO1G.js → data-DFcSmGvN.js} +2 -2
  22. package/dist/{data-runtime-SJ1BSUvk.js → data-runtime-rpV6-3XW.js} +13 -2
  23. package/dist/{deferred-zHtUheIQ.js → deferred-Cr58yIQD.js} +3 -4
  24. package/dist/foundations/index.d.ts +1 -1
  25. package/dist/foundations/index.js +1 -1
  26. package/dist/foundations/structures/index.d.ts +1 -1
  27. package/dist/foundations/structures/index.js +1 -1
  28. package/dist/{index-BFnTM1a8.d.ts → index-BOBtoY_r.d.ts} +34 -2
  29. package/dist/{index-DSClfSoC.d.ts → index-DxYJPVC4.d.ts} +1 -1
  30. package/dist/{index-Dh6ZF9yW.d.ts → index-UmwPZ8ZN.d.ts} +5 -0
  31. package/dist/{index-DjusBb1I.d.ts → index-u3KYoHlM.d.ts} +1 -1
  32. package/dist/index.d.ts +4 -5
  33. package/dist/index.js +12 -7
  34. package/dist/jsx-dev-runtime.d.ts +1 -0
  35. package/dist/jsx-runtime-C6Fs8Mmc.d.ts +2 -0
  36. package/dist/{jsx-runtime-aYZ8zb4q.d.ts → jsx-runtime-CL2r2HHQ.d.ts} +1 -0
  37. package/dist/jsx-runtime.d.ts +1 -1
  38. package/dist/{lifecycle-operations-SlPEK68H.js → lifecycle-operations-Db-_MG-O.js} +9 -12
  39. package/dist/{navigate-CV-RDqYP.d.ts → navigate-Cbq6QHVl.d.ts} +1 -1
  40. package/dist/{navigate-DpR-cML9.js → navigate-CuGQzS_Y.js} +8 -104
  41. package/dist/{portal-D7TC986A.js → portal-wY3j0vvp.js} +59 -1
  42. package/dist/{query-registry-CQIT4mXr.js → query-registry-Bu_cuMch.js} +1 -1
  43. package/dist/{renderer-CBBbYZUO.js → renderer-BJYY2Y8s.js} +91 -10
  44. package/dist/resources/index.d.ts +27 -8
  45. package/dist/resources/index.js +218 -4
  46. package/dist/{route-matching-DLBWDeXX.js → route-matching-M-f1VQRu.js} +276 -2
  47. package/dist/router/index.d.ts +7 -7
  48. package/dist/router/index.js +28 -17
  49. package/dist/{router-C0XQA62W.d.ts → router-C3vENhUh.d.ts} +1 -1
  50. package/dist/{selector-DueeR6Oz.js → selector-DEfqO1rA.js} +8 -0
  51. package/dist/ssg/index.d.ts +8 -1
  52. package/dist/ssg/index.js +53 -17
  53. package/dist/ssr/index.d.ts +15 -1
  54. package/dist/ssr/index.js +1 -1
  55. package/dist/{ssr-vE-KUgDV.js → ssr-BSUA9Y64.js} +72 -78
  56. package/dist/testing/index.d.ts +35 -2
  57. package/dist/testing/index.js +182 -3
  58. package/dist/{verify-hydration-ChyEiBAn.js → verify-hydration-CVSGv6Vs.js} +1 -1
  59. package/package.json +4 -2
  60. package/dist/attr-names-CjhzmHOn.js +0 -15
  61. package/dist/component-scope-CvPba6O6.d.ts +0 -12
  62. package/dist/invalidation-listeners-Des3AHYs.js +0 -13
  63. package/dist/jsx-runtime-X2SX2y8V.d.ts +0 -2
  64. package/dist/resource-operation-BJiLoLYZ.js +0 -276
@@ -9,9 +9,9 @@ import { t as cleanupComponent } from "./component-cleanup-1ZFoLLHt.js";
9
9
  import { c as getCurrentLifecycleCommitBatch, l as registerLifecycleRollback, p as isPromiseLike, r as discardLifecycleCommitBatch, s as flushLifecycleCommitBatch, t as beginLifecycleCommitBatch, u as registerLifecycleTransaction } from "./lifecycle-batch-COgl8jMS.js";
10
10
  import { _ as createChildScope, a as registerForStateTransaction, c as captureForFallbackTransactionSnapshot, d as clearCaseDomUpdateState, f as clearShowDomUpdateState, g as evaluateShowState, h as evaluateCaseState, i as evaluateForState, l as captureForItemTransactionSnapshot, n as clearForDomUpdateState, o as rollbackForStateTransaction, t as beginForStateTransaction, v as disposeChildScope, y as rerenderChildScope } from "./for-internal-BtK9Htl0.js";
11
11
  import { n as createOwnedFineGrainedEffect, r as markFineGrainedEffectsDirtySource, t as createFineGrainedEffect } from "./effect-CFUzIpqX.js";
12
- import { C as getDelegatedHandlersForElement, D as updateDelegatedListener, E as removeDelegatedListener, S as getDelegatedHandlerForElement, T as isEventDelegationEnabled, _ as teardownNodeSubtree, a as elementReactivePropsCleanup, b as addFreshDelegatedListener, c as forEachElementReactivePropCleanup, d as removeAllListeners, f as removeElementReactiveProps, g as setFreshElementReactivePropCleanup, h as setDirectElementReactivePropCleanup, i as elementListeners, l as getElementReactivePropCleanupSize, m as replaceElementRefBookkeeping, n as cleanupInstanceIfPresent, o as elementRefs, p as removeElementRef, r as cleanupInstancesUnder, s as forEachDescendantNode, t as REACTIVE_CHILDREN_KEY, u as getElementReactivePropsCleanupMap, v as updateElementRef, w as isDelegatedEvent, x as clearDelegatedHandlersForElement, y as addDelegatedListener } from "./cleanup-UyStxIHG.js";
13
- import { t as getPublicAttributeName } from "./attr-names-CjhzmHOn.js";
14
- import { i as ROUTE_ROOT_COMPONENT } from "./csp-nonce-HGZ0vbqT.js";
12
+ import { C as getDelegatedHandlersForElement, D as updateDelegatedListener, E as removeDelegatedListener, S as getDelegatedHandlerForElement, T as isEventDelegationEnabled, _ as teardownNodeSubtree, a as elementReactivePropsCleanup, b as addFreshDelegatedListener, c as forEachElementReactivePropCleanup, d as removeAllListeners, f as removeElementReactiveProps, g as setFreshElementReactivePropCleanup, h as setDirectElementReactivePropCleanup, i as elementListeners, l as getElementReactivePropCleanupSize, m as replaceElementRefBookkeeping, n as cleanupInstanceIfPresent, o as elementRefs, p as removeElementRef, r as cleanupInstancesUnder, s as forEachDescendantNode, t as REACTIVE_CHILDREN_KEY, u as getElementReactivePropsCleanupMap, v as updateElementRef, w as isDelegatedEvent, x as clearDelegatedHandlersForElement, y as addDelegatedListener } from "./cleanup-D8Ufd9Ix.js";
13
+ import { n as getPublicAttributeName, t as sanitizeCssValue } from "./css-BuPaTOfe.js";
14
+ import { a as isSafeHref, i as ROUTE_ROOT_COMPONENT } from "./csp-nonce-CwSRP3Jl.js";
15
15
  //#region src/runtime/error-boundary.ts
16
16
  function createBoundaryReset(instance) {
17
17
  return () => {
@@ -500,7 +500,8 @@ function normalizeStyleEntries(value) {
500
500
  const entries = /* @__PURE__ */ new Map();
501
501
  for (const [key, entryValue] of Object.entries(value)) {
502
502
  if (entryValue === void 0 || entryValue === null || entryValue === false) continue;
503
- entries.set(normalizeStylePropertyName(key), String(entryValue));
503
+ const safeValue = sanitizeCssValue(String(entryValue));
504
+ if (safeValue) entries.set(normalizeStylePropertyName(key), safeValue);
504
505
  }
505
506
  return entries;
506
507
  }
@@ -554,6 +555,7 @@ function applyStaticScalarPropsToElement(el, props, tagName) {
554
555
  if (key === "class" || key === "className") writeElementClassName(el, String(value));
555
556
  else if (key === "style") applyStylePropValue(el, value);
556
557
  else if (key === "value" || key === "checked") applyFormControlProp(el, key, value, tagName);
558
+ else if (key.toLowerCase() === "href" && !isSafeHref(String(value))) removeRenderedAttribute(el, key);
557
559
  else setRenderedAttribute(el, key, String(value));
558
560
  }
559
561
  }
@@ -619,6 +621,7 @@ function applyScalarPropValue(el, key, value, tagName, previousValue, descriptor
619
621
  if (key === "class" || key === "className") applyClassPropValue(el, value, previousValue, descriptor);
620
622
  else if (key === "style") applyStylePropValue(el, value);
621
623
  else if (key === "value" || key === "checked") applyFormControlProp(el, key, value, tagName);
624
+ else if (key.toLowerCase() === "href" && !isSafeHref(String(value))) removeRenderedAttribute(el, key);
622
625
  else setRenderedAttribute(el, key, String(value));
623
626
  }
624
627
  function removeStaleAttributes(el, vnode, props) {
@@ -2549,10 +2552,7 @@ function updateElementChildren$1(el, children, forceUpdate = false) {
2549
2552
  keyedElements.delete(el);
2550
2553
  return;
2551
2554
  }
2552
- if (normalizedChildren.some(isControlBoundaryVNode) && normalizedChildren.every((child) => {
2553
- if (!isControlBoundaryVNode(child)) return true;
2554
- return getControlBoundaryState(child)?.kind !== "for";
2555
- })) {
2555
+ if (normalizedChildren.some(isControlBoundaryVNode)) {
2556
2556
  updateMixedControlChildren(el, normalizedChildren, forceUpdate);
2557
2557
  keyedElements.delete(el);
2558
2558
  return;
@@ -2611,6 +2611,7 @@ function removeRangeAtCursor(parent, cursor) {
2611
2611
  return next;
2612
2612
  }
2613
2613
  function updateMixedControlChildren(parent, children, forceUpdate) {
2614
+ clearControlBoundaryCommitOwner(parent);
2614
2615
  const parentNamespace = getParentNamespace(parent);
2615
2616
  const domHost = getRendererDOMHost();
2616
2617
  let cursor = parent.firstChild;
@@ -2618,10 +2619,14 @@ function updateMixedControlChildren(parent, children, forceUpdate) {
2618
2619
  if (isControlBoundaryVNode(child)) {
2619
2620
  const controlState = getControlBoundaryState(child);
2620
2621
  if (!controlState) throw new Error("[updateElementChildren] Control boundary missing internal state");
2621
- registerControlBoundaryCommitOwner(parent, controlState);
2622
2622
  const childVNodes = evaluateControlBoundaryState(controlState);
2623
2623
  const cursorAfterBoundary = cursor ? isRangeStart(cursor) ? findRangeEnd(cursor)?.nextSibling ?? cursor.nextSibling : cursor.nextSibling : null;
2624
2624
  const ranges = syncControlBoundaryInMixedParent(parent, controlState, childVNodes, cursor);
2625
+ if (controlState.kind === "for") {
2626
+ const last = ranges[ranges.length - 1];
2627
+ cursor = last ? last.end.nextSibling : cursorAfterBoundary?.parentNode === parent ? cursorAfterBoundary : cursor?.parentNode === parent ? cursor : null;
2628
+ continue;
2629
+ }
2625
2630
  for (const range of ranges) if (range.start.parentNode !== parent) moveRange(parent, range, cursor?.parentNode === parent ? cursor : null);
2626
2631
  else if (cursor?.parentNode === parent) moveRange(parent, range, cursor);
2627
2632
  const last = ranges[ranges.length - 1];
@@ -3738,6 +3743,11 @@ function updateElementChildren(element, vnodeChildren, cleanupRangeNode) {
3738
3743
  updateForBoundaryChildren(element, vnodeChildren[0]);
3739
3744
  return;
3740
3745
  }
3746
+ if (vnodeChildren.some((child) => _isDOMElement(child) && child.type === __CONTROL_BOUNDARY__)) {
3747
+ updateMixedControlChildren(element, vnodeChildren, false);
3748
+ keyedElements.delete(element);
3749
+ return;
3750
+ }
3741
3751
  if (hasKeyedChildren(vnodeChildren)) reconcileKeyed(element, vnodeChildren, getOrBuildKeyMap(element));
3742
3752
  else reconcileUnkeyed(element, vnodeChildren);
3743
3753
  }
@@ -4398,7 +4408,78 @@ function syncControlBoundaryScopeNode(parent, scope, vnode) {
4398
4408
  return range?.single ? range.start : null;
4399
4409
  }
4400
4410
  function syncControlBoundaryInMixedParent(parent, controlState, childrenVNodes, before) {
4401
- if (controlState.kind === "for") throw new Error("[askr] For ranges require the keyed boundary commit path.");
4411
+ if (controlState.kind === "for") {
4412
+ const ownedNodes = /* @__PURE__ */ new Set();
4413
+ const collectRangeNodes = (range) => {
4414
+ if (range.start.parentNode !== parent) return;
4415
+ ownedNodes.add(range.start);
4416
+ if (!range.single) {
4417
+ let current = range.start.nextSibling;
4418
+ while (current) {
4419
+ ownedNodes.add(current);
4420
+ if (current === range.end) break;
4421
+ current = current.nextSibling;
4422
+ }
4423
+ }
4424
+ };
4425
+ for (const item of controlState.orderedItems) if (item?.scope.range) collectRangeNodes(item.scope.range);
4426
+ if (controlState.fallbackScope?.range) collectRangeNodes(controlState.fallbackScope.range);
4427
+ for (const range of controlState.lastRemovedRanges) collectRangeNodes(range);
4428
+ for (const node of controlState.lastRemovedNodes) if (node.parentNode === parent) ownedNodes.add(node);
4429
+ let afterBoundary = before;
4430
+ while (afterBoundary && ownedNodes.has(afterBoundary)) afterBoundary = afterBoundary.nextSibling;
4431
+ const nextRanges = [];
4432
+ let syncBefore = before;
4433
+ if (controlState.orderedKeys.length === 0) {
4434
+ const fallbackScope = controlState.fallbackScope;
4435
+ const fallbackVNode = childrenVNodes[0];
4436
+ if (fallbackScope && fallbackVNode !== void 0) {
4437
+ if (fallbackScope.hydrationPending && !fallbackScope.range && syncBefore instanceof Element && !checkVNodeShapeChanged(syncBefore, fallbackVNode)) {
4438
+ assignScopeRange(fallbackScope, {
4439
+ start: syncBefore,
4440
+ end: syncBefore,
4441
+ single: true
4442
+ });
4443
+ fallbackScope.hydrationPending = false;
4444
+ }
4445
+ const range = syncControlBoundaryScopeDom(parent, fallbackScope, fallbackVNode, syncBefore, controlState.lastRemovedRanges.length === 0, false);
4446
+ if (range) {
4447
+ nextRanges.push(range);
4448
+ syncBefore = range.end.nextSibling;
4449
+ }
4450
+ }
4451
+ } else for (let index = 0; index < controlState.orderedItems.length; index += 1) {
4452
+ const item = controlState.orderedItems[index];
4453
+ const vnode = childrenVNodes[index];
4454
+ if (!item || vnode === void 0) continue;
4455
+ if (item.scope.hydrationPending && !item.scope.range && syncBefore instanceof Element && getMaterializedKey(syncBefore) === controlState.orderedKeys[index] && !checkVNodeShapeChanged(syncBefore, vnode)) {
4456
+ assignScopeRange(item.scope, {
4457
+ start: syncBefore,
4458
+ end: syncBefore,
4459
+ single: true
4460
+ });
4461
+ item.scope.hydrationPending = false;
4462
+ }
4463
+ const range = syncControlBoundaryScopeDom(parent, item.scope, vnode, syncBefore, controlState.lastRemovedRanges.length === 0, false);
4464
+ if (range) {
4465
+ nextRanges.push(range);
4466
+ syncBefore = range.end.nextSibling;
4467
+ }
4468
+ }
4469
+ const previousAfterBoundary = afterBoundary;
4470
+ if (previousAfterBoundary && nextRanges.some((range) => rangeContains(range, previousAfterBoundary))) afterBoundary = nextRanges[nextRanges.length - 1]?.end.nextSibling ?? null;
4471
+ const nextRangeSet = new Set(nextRanges);
4472
+ for (const range of controlState.lastRemovedRanges) if (!nextRangeSet.has(range)) removeRange(range, teardownBoundaryRangeNode);
4473
+ for (const node of controlState.lastRemovedNodes) if (node.parentNode === parent && !nextRanges.some((range) => rangeContains(range, node))) teardownBoundaryRangeNode(node);
4474
+ let anchor = afterBoundary?.parentNode === parent ? afterBoundary : null;
4475
+ for (let index = nextRanges.length - 1; index >= 0; index -= 1) {
4476
+ const range = nextRanges[index];
4477
+ insertRangeBefore(parent, range, anchor);
4478
+ anchor = range.start;
4479
+ }
4480
+ clearBoundaryState(controlState);
4481
+ return nextRanges;
4482
+ }
4402
4483
  const activeScope = controlState.activeScope;
4403
4484
  const activeVNode = childrenVNodes[0];
4404
4485
  const nextRange = activeScope && activeVNode !== void 0 ? syncControlBoundaryScopeDom(parent, activeScope, activeVNode, before, controlState.lastRemovedRanges.length === 0) : null;
@@ -1,4 +1,5 @@
1
- import { t as getSignal } from "../component-scope-CvPba6O6.js";
1
+ import { h as getSignal } from "../index-BOBtoY_r.js";
2
+ import { i as onRouteChange, n as RouteChangeOptions, t as RouteChangeCleanup } from "../activity-DZ-NCYr8.js";
2
3
  //#region src/runtime/resource-operation.d.ts
3
4
  interface ResourceResult<T> {
4
5
  value: T | null;
@@ -6,10 +7,31 @@ interface ResourceResult<T> {
6
7
  error: Error | null;
7
8
  refresh(): void;
8
9
  }
10
+ /** Creates a render-scoped async resource with cancellation and refresh; SSR has special data rules. */
9
11
  declare function resource<T, const TDeps extends readonly unknown[]>(fn: (opts: {
10
12
  signal: AbortSignal;
11
13
  }) => PromiseLike<T> | T, deps: TDeps): ResourceResult<T>;
12
14
  //#endregion
15
+ //#region src/runtime/stream-operation.d.ts
16
+ type StreamStatus = 'connecting' | 'connected' | 'reconnecting' | 'closed' | 'error';
17
+ interface StreamResult<T> {
18
+ value: T | null;
19
+ status: StreamStatus;
20
+ pending: boolean;
21
+ stale: boolean;
22
+ error: Error | null;
23
+ restart(): void;
24
+ close(): void;
25
+ }
26
+ interface StreamOptions<T> {
27
+ deps?: readonly unknown[];
28
+ initialValue?: T;
29
+ }
30
+ type StreamSource<T> = (context: {
31
+ signal: AbortSignal;
32
+ }) => AsyncIterable<T> | PromiseLike<AsyncIterable<T>>;
33
+ declare function stream<T>(source: StreamSource<T>, options?: StreamOptions<T>): StreamResult<T>;
34
+ //#endregion
13
35
  //#region src/runtime/lifecycle-operations.d.ts
14
36
  type ActivityPredicate = () => boolean;
15
37
  interface TimerOptions {
@@ -18,14 +40,11 @@ interface TimerOptions {
18
40
  declare function routeActive(pathOrPaths: string | readonly string[]): ActivityPredicate;
19
41
  declare function documentVisible(): ActivityPredicate;
20
42
  declare function windowFocused(): ActivityPredicate;
43
+ type ListenerTarget = EventTarget | (() => EventTarget | null | undefined);
21
44
  type ListenerOptions = boolean | AddEventListenerOptions | undefined;
22
- declare function on(target: EventTarget, event: string, handler: EventListener, options?: ListenerOptions): void;
45
+ declare function on(target: ListenerTarget, event: string, handler: EventListener, options?: ListenerOptions): void;
23
46
  declare function timer(intervalMs: number, fn: () => void, options?: TimerOptions): void;
24
- declare function stream<T>(_source: unknown, _options?: Record<string, unknown>): {
25
- value: T | null;
26
- pending: boolean;
27
- error: Error | null;
28
- };
47
+ /** Runs an owned task after commit. */
29
48
  declare function task(fn: () => void | (() => void) | PromiseLike<void | (() => void)>): void;
30
49
  /**
31
50
  * Capture the result of a synchronous expression at call time and return a
@@ -39,4 +58,4 @@ declare function task(fn: () => void | (() => void) | PromiseLike<void | (() =>
39
58
  */
40
59
  declare function capture<T>(fn: () => T): () => T;
41
60
  //#endregion
42
- export { type ActivityPredicate, type ResourceResult, type TimerOptions, capture, documentVisible, getSignal, on, resource, routeActive, stream, task, timer, windowFocused };
61
+ export { type ActivityPredicate, type ListenerTarget, type ResourceResult, type RouteChangeCleanup, type RouteChangeOptions, type StreamOptions, type StreamResult, type StreamStatus, type TimerOptions, capture, documentVisible, getSignal, on, onRouteChange, resource, routeActive, stream, task, timer, windowFocused };
@@ -1,4 +1,218 @@
1
- import { g as getSignal } from "../component-scope-CC3cojX9.js";
2
- import { t as resource } from "../resource-operation-BJiLoLYZ.js";
3
- import { a as stream, c as windowFocused, i as routeActive, n as documentVisible, o as task, r as on, s as timer, t as capture } from "../lifecycle-operations-SlPEK68H.js";
4
- export { capture, documentVisible, getSignal, on, resource, routeActive, stream, task, timer, windowFocused };
1
+ import { t as enqueueRuntimeLane } from "../access-ePqdQqkV.js";
2
+ import { a as registerCommitOperation } from "../component-internal-CPjM4n8M.js";
3
+ import { f as getCurrentComponentInstance, g as getSignal, i as claimHookIndex } from "../component-scope-CC3cojX9.js";
4
+ import { z as resource } from "../route-matching-M-f1VQRu.js";
5
+ import { a as task, i as routeActive, n as documentVisible, o as timer, r as on, s as windowFocused, t as capture } from "../lifecycle-operations-Db-_MG-O.js";
6
+ import { n as onRouteChange } from "../activity-C2tPn9Fr.js";
7
+ //#region src/runtime/stream-operation.ts
8
+ function toError(value) {
9
+ return value instanceof Error ? value : new Error(String(value));
10
+ }
11
+ function depsEqual(left, right) {
12
+ return left.length === right.length && left.every((value, index) => Object.is(value, right[index]));
13
+ }
14
+ function publish(slot) {
15
+ if (slot.disposed) return;
16
+ try {
17
+ slot.owner?.notifyUpdate?.();
18
+ } catch {}
19
+ }
20
+ function setStartingState(slot) {
21
+ const retained = slot.hasValue;
22
+ slot.snapshot.status = retained && slot.generation > 0 ? "reconnecting" : "connecting";
23
+ slot.snapshot.pending = !retained;
24
+ slot.snapshot.stale = retained;
25
+ slot.snapshot.error = null;
26
+ }
27
+ function returnIterator(generation) {
28
+ if (generation.returned || !generation.iterator) return;
29
+ generation.returned = true;
30
+ const returnMethod = generation.iterator.return;
31
+ if (typeof returnMethod !== "function") return;
32
+ try {
33
+ Promise.resolve(returnMethod.call(generation.iterator)).catch(() => {});
34
+ } catch {}
35
+ }
36
+ function stopGeneration(generation) {
37
+ if (!generation || generation.stopped) return;
38
+ generation.stopped = true;
39
+ generation.controller.abort();
40
+ returnIterator(generation);
41
+ }
42
+ function isCurrent(slot, generation) {
43
+ return !slot.disposed && !generation.stopped && slot.current === generation && slot.generation === generation.id;
44
+ }
45
+ async function consume(slot, generation, iterable) {
46
+ const iteratorFactory = iterable?.[Symbol.asyncIterator];
47
+ if (typeof iteratorFactory !== "function") throw new TypeError("stream() source must return an AsyncIterable.");
48
+ const iterator = iteratorFactory.call(iterable);
49
+ if (!iterator || typeof iterator.next !== "function") throw new TypeError("stream() source must return an AsyncIterable with an iterator.");
50
+ generation.iterator = iterator;
51
+ if (!isCurrent(slot, generation)) {
52
+ returnIterator(generation);
53
+ return;
54
+ }
55
+ while (isCurrent(slot, generation)) {
56
+ const step = await iterator.next();
57
+ if (!isCurrent(slot, generation)) return;
58
+ if (step.done) {
59
+ slot.current = null;
60
+ slot.snapshot.status = "closed";
61
+ slot.snapshot.pending = false;
62
+ slot.snapshot.stale = slot.hasValue;
63
+ slot.snapshot.error = null;
64
+ publish(slot);
65
+ return;
66
+ }
67
+ slot.snapshot.value = step.value;
68
+ slot.hasValue = true;
69
+ slot.snapshot.status = "connected";
70
+ slot.snapshot.pending = false;
71
+ slot.snapshot.stale = false;
72
+ slot.snapshot.error = null;
73
+ publish(slot);
74
+ }
75
+ }
76
+ function startSlot(slot) {
77
+ if (!slot.activated || slot.disposed) return;
78
+ stopGeneration(slot.current);
79
+ slot.explicitlyClosed = false;
80
+ setStartingState(slot);
81
+ publish(slot);
82
+ const generation = {
83
+ id: ++slot.generation,
84
+ controller: new AbortController(),
85
+ iterator: null,
86
+ returned: false,
87
+ stopped: false
88
+ };
89
+ slot.current = generation;
90
+ let result;
91
+ try {
92
+ result = slot.source({ signal: generation.controller.signal });
93
+ } catch (error) {
94
+ if (!isCurrent(slot, generation)) return;
95
+ slot.current = null;
96
+ slot.snapshot.status = "error";
97
+ slot.snapshot.pending = false;
98
+ slot.snapshot.stale = slot.hasValue;
99
+ slot.snapshot.error = toError(error);
100
+ publish(slot);
101
+ return;
102
+ }
103
+ Promise.resolve(result).then((iterable) => consume(slot, generation, iterable)).catch((error) => {
104
+ if (!isCurrent(slot, generation)) return;
105
+ slot.current = null;
106
+ slot.snapshot.status = "error";
107
+ slot.snapshot.pending = false;
108
+ slot.snapshot.stale = slot.hasValue;
109
+ slot.snapshot.error = toError(error);
110
+ publish(slot);
111
+ });
112
+ }
113
+ function queueStart(slot) {
114
+ if (slot.startQueued || slot.disposed || slot.explicitlyClosed) return;
115
+ slot.startQueued = true;
116
+ enqueueRuntimeLane("post", () => {
117
+ slot.startQueued = false;
118
+ if (!slot.owner?.notifyUpdate || slot.explicitlyClosed) return;
119
+ startSlot(slot);
120
+ });
121
+ }
122
+ function closeSlot(slot) {
123
+ if (slot.disposed) return;
124
+ slot.explicitlyClosed = true;
125
+ stopGeneration(slot.current);
126
+ slot.current = null;
127
+ slot.snapshot.status = "closed";
128
+ slot.snapshot.pending = false;
129
+ slot.snapshot.stale = slot.hasValue;
130
+ slot.snapshot.error = null;
131
+ publish(slot);
132
+ }
133
+ function createSnapshot(options) {
134
+ const hasInitialValue = Object.prototype.hasOwnProperty.call(options, "initialValue");
135
+ return {
136
+ value: hasInitialValue ? options.initialValue : null,
137
+ status: "connecting",
138
+ pending: !hasInitialValue,
139
+ stale: hasInitialValue,
140
+ error: null,
141
+ restart: () => {},
142
+ close: () => {}
143
+ };
144
+ }
145
+ function createSlot(source, options) {
146
+ const snapshot = createSnapshot(options);
147
+ const slot = {
148
+ kind: "stream",
149
+ source,
150
+ pendingSource: source,
151
+ deps: (options.deps ?? []).slice(),
152
+ pendingDeps: (options.deps ?? []).slice(),
153
+ snapshot,
154
+ generation: 0,
155
+ current: null,
156
+ activated: false,
157
+ disposed: false,
158
+ explicitlyClosed: false,
159
+ hasValue: Object.prototype.hasOwnProperty.call(options, "initialValue"),
160
+ cleanupRegistered: false,
161
+ startQueued: false,
162
+ owner: null
163
+ };
164
+ snapshot.restart = () => {
165
+ if (slot.disposed) return;
166
+ slot.explicitlyClosed = false;
167
+ if (slot.activated) {
168
+ if (!slot.startQueued) startSlot(slot);
169
+ }
170
+ };
171
+ snapshot.close = () => closeSlot(slot);
172
+ return slot;
173
+ }
174
+ function disposeSlot(slot) {
175
+ if (slot.disposed) return;
176
+ slot.disposed = true;
177
+ stopGeneration(slot.current);
178
+ slot.current = null;
179
+ slot.owner = null;
180
+ if (slot.activated && false);
181
+ slot.activated = false;
182
+ }
183
+ function commitSlot(instance, slot) {
184
+ const depsChanged = !depsEqual(slot.deps, slot.pendingDeps);
185
+ const firstCommit = !slot.activated;
186
+ const wasRunning = slot.current !== null;
187
+ slot.owner = instance;
188
+ slot.source = slot.pendingSource;
189
+ slot.deps = slot.pendingDeps;
190
+ if (firstCommit) slot.activated = true;
191
+ if (!slot.cleanupRegistered) {
192
+ slot.cleanupRegistered = true;
193
+ (instance.cleanupFns ??= []).push(() => disposeSlot(slot));
194
+ }
195
+ if (!slot.explicitlyClosed && (firstCommit || depsChanged && wasRunning)) queueStart(slot);
196
+ }
197
+ function getStreamSlot(instance, index, source, options) {
198
+ const slots = instance.lifecycleSlots ??= [];
199
+ const existing = slots[index];
200
+ if (existing) {
201
+ if (existing.kind !== "stream") throw new Error(`stream() lifecycle order violation: slot ${index} already belongs to ${existing.kind ?? "another primitive"}(). Keep lifecycle primitives in a stable top-level order.`);
202
+ return existing;
203
+ }
204
+ const slot = createSlot(source, options);
205
+ slots[index] = slot;
206
+ return slot;
207
+ }
208
+ function stream(source, options = {}) {
209
+ const instance = getCurrentComponentInstance();
210
+ if (!instance) return createSnapshot(options);
211
+ const slot = getStreamSlot(instance, claimHookIndex(instance, "stream"), source, options);
212
+ slot.pendingSource = source;
213
+ slot.pendingDeps = (options.deps ?? []).slice();
214
+ if (!instance.ssr) registerCommitOperation(() => commitSlot(instance, slot));
215
+ return slot.snapshot;
216
+ }
217
+ //#endregion
218
+ export { capture, documentVisible, getSignal, on, onRouteChange, resource, routeActive, stream, task, timer, windowFocused };