@real-router/solid 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +49 -4
  2. package/dist/cjs/index.d.ts +178 -2
  3. package/dist/cjs/index.js +407 -22
  4. package/dist/esm/index.d.mts +178 -2
  5. package/dist/esm/index.mjs +406 -23
  6. package/dist/types/RouterProvider.d.ts +1 -0
  7. package/dist/types/RouterProvider.d.ts.map +1 -1
  8. package/dist/types/components/RouteView/RouteView.d.ts +3 -2
  9. package/dist/types/components/RouteView/RouteView.d.ts.map +1 -1
  10. package/dist/types/components/RouteView/components.d.ts +12 -2
  11. package/dist/types/components/RouteView/components.d.ts.map +1 -1
  12. package/dist/types/components/RouteView/helpers.d.ts.map +1 -1
  13. package/dist/types/components/RouteView/index.d.ts +1 -1
  14. package/dist/types/components/RouteView/index.d.ts.map +1 -1
  15. package/dist/types/components/RouteView/types.d.ts +6 -0
  16. package/dist/types/components/RouteView/types.d.ts.map +1 -1
  17. package/dist/types/dom-utils/direction-tracker.d.ts +27 -0
  18. package/dist/types/dom-utils/direction-tracker.d.ts.map +1 -0
  19. package/dist/types/dom-utils/index.d.ts +4 -0
  20. package/dist/types/dom-utils/index.d.ts.map +1 -1
  21. package/dist/types/dom-utils/view-transitions.d.ts +6 -0
  22. package/dist/types/dom-utils/view-transitions.d.ts.map +1 -0
  23. package/dist/types/hooks/useRouteEnter.d.ts +76 -0
  24. package/dist/types/hooks/useRouteEnter.d.ts.map +1 -0
  25. package/dist/types/hooks/useRouteExit.d.ts +90 -0
  26. package/dist/types/hooks/useRouteExit.d.ts.map +1 -0
  27. package/dist/types/index.d.ts +5 -1
  28. package/dist/types/index.d.ts.map +1 -1
  29. package/package.json +3 -3
  30. package/src/RouterProvider.tsx +18 -1
  31. package/src/components/RouteView/RouteView.tsx +7 -2
  32. package/src/components/RouteView/components.tsx +25 -2
  33. package/src/components/RouteView/helpers.tsx +67 -21
  34. package/src/components/RouteView/index.ts +1 -0
  35. package/src/components/RouteView/types.ts +7 -0
  36. package/src/hooks/useRouteEnter.tsx +129 -0
  37. package/src/hooks/useRouteExit.tsx +123 -0
  38. package/src/index.tsx +17 -0
@@ -9,6 +9,7 @@ import { UNKNOWN_ROUTE, getNavigator } from '@real-router/core';
9
9
  // Local (non-global) Symbols — Symbol.for() would expose markers to spoofing
10
10
  // via the global Symbol registry. See Gotchas section "RouteView Marker Objects".
11
11
  const MATCH_MARKER = Symbol("RouteView.Match");
12
+ const SELF_MARKER = Symbol("RouteView.Self");
12
13
  const NOT_FOUND_MARKER = Symbol("RouteView.NotFound");
13
14
  function Match(props) {
14
15
  const result = {
@@ -27,6 +28,19 @@ function Match(props) {
27
28
  return result;
28
29
  }
29
30
  Match.displayName = "RouteView.Match";
31
+ function Self(props) {
32
+ const result = {
33
+ $$type: SELF_MARKER,
34
+ fallback: props.fallback,
35
+ get children() {
36
+ return props.children;
37
+ }
38
+ };
39
+
40
+ // See Match for the marker-pattern rationale.
41
+ return result;
42
+ }
43
+ Self.displayName = "RouteView.Self";
30
44
  function NotFound(props) {
31
45
  const result = {
32
46
  $$type: NOT_FOUND_MARKER,
@@ -49,6 +63,9 @@ function isSegmentMatch(routeName, fullSegmentName, exact) {
49
63
  function isMatchMarker(value) {
50
64
  return value != null && typeof value === "object" && "$$type" in value && value.$$type === MATCH_MARKER;
51
65
  }
66
+ function isSelfMarker(value) {
67
+ return value != null && typeof value === "object" && "$$type" in value && value.$$type === SELF_MARKER;
68
+ }
52
69
  function isNotFoundMarker(value) {
53
70
  return value != null && typeof value === "object" && "$$type" in value && value.$$type === NOT_FOUND_MARKER;
54
71
  }
@@ -62,11 +79,48 @@ function collectElements(children, result) {
62
79
  }
63
80
  return;
64
81
  }
65
- if (isMatchMarker(children) || isNotFoundMarker(children)) {
82
+ if (isMatchMarker(children) || isSelfMarker(children) || isNotFoundMarker(children)) {
66
83
  result.push(children);
67
84
  }
68
85
  }
86
+
87
+ // child.children is a getter — read it INSIDE the JSX expression so Solid
88
+ // creates a reactive dependency. Pulling it into a variable freezes the
89
+ // value at template-build time and breaks Suspense fallback transitions
90
+ // (lazy() resolution).
91
+ function renderMatch(child) {
92
+ return child.fallback === undefined ? child.children : createComponent(Suspense, {
93
+ get fallback() {
94
+ return child.fallback;
95
+ },
96
+ get children() {
97
+ return child.children;
98
+ }
99
+ });
100
+ }
101
+ function renderSelf(self) {
102
+ return self.fallback === undefined ? self.children : createComponent(Suspense, {
103
+ get fallback() {
104
+ return self.fallback;
105
+ },
106
+ get children() {
107
+ return self.children;
108
+ }
109
+ });
110
+ }
111
+ function processMatchChild(child, routeName, nodeName) {
112
+ const {
113
+ segment,
114
+ exact
115
+ } = child;
116
+ const fullSegmentName = nodeName ? `${nodeName}.${segment}` : segment;
117
+ if (!isSegmentMatch(routeName, fullSegmentName, exact)) {
118
+ return null;
119
+ }
120
+ return renderMatch(child);
121
+ }
69
122
  function buildRenderList(elements, routeName, nodeName) {
123
+ let selfMarker = null;
70
124
  let notFoundChildren = null;
71
125
  let activeMatchFound = false;
72
126
  const rendered = [];
@@ -75,28 +129,25 @@ function buildRenderList(elements, routeName, nodeName) {
75
129
  notFoundChildren = child.children;
76
130
  continue;
77
131
  }
78
- if (activeMatchFound) {
132
+ if (isSelfMarker(child)) {
133
+ selfMarker ??= child;
79
134
  continue;
80
135
  }
81
- const {
82
- segment,
83
- exact,
84
- fallback
85
- } = child;
86
- const fullSegmentName = nodeName ? `${nodeName}.${segment}` : segment;
87
- if (!isSegmentMatch(routeName, fullSegmentName, exact)) {
136
+ if (activeMatchFound) {
88
137
  continue;
89
138
  }
90
- activeMatchFound = true;
91
- rendered.push(fallback === undefined ? child.children : createComponent(Suspense, {
92
- fallback: fallback,
93
- get children() {
94
- return child.children;
95
- }
96
- }));
139
+ const matchRendered = processMatchChild(child, routeName, nodeName);
140
+ if (matchRendered !== null) {
141
+ activeMatchFound = true;
142
+ rendered.push(matchRendered);
143
+ }
97
144
  }
98
- if (!activeMatchFound && routeName === UNKNOWN_ROUTE && notFoundChildren !== null) {
99
- rendered.push(notFoundChildren);
145
+ if (!activeMatchFound) {
146
+ if (selfMarker !== null && routeName === nodeName) {
147
+ rendered.push(renderSelf(selfMarker));
148
+ } else if (routeName === UNKNOWN_ROUTE && notFoundChildren !== null) {
149
+ rendered.push(notFoundChildren);
150
+ }
100
151
  }
101
152
  return rendered;
102
153
  }
@@ -155,6 +206,7 @@ function RouteViewRoot(props) {
155
206
  RouteViewRoot.displayName = "RouteView";
156
207
  const RouteView = Object.assign(RouteViewRoot, {
157
208
  Match,
209
+ Self,
158
210
  NotFound
159
211
  });
160
212
 
@@ -265,7 +317,7 @@ function removeAnnouncer() {
265
317
  document.querySelector(`[${ANNOUNCER_ATTR}]`)?.remove();
266
318
  }
267
319
  function resolveText(route, prefix, getCustomText, h1) {
268
- const h1Text = h1?.textContent.trim() ?? "";
320
+ const h1Text = (h1?.textContent ?? "").trim();
269
321
  const routeName = route.name.startsWith(INTERNAL_ROUTE_PREFIX) ? "" : route.name;
270
322
  const rawText = h1Text || document.title || routeName || globalThis.location.pathname;
271
323
  return `${prefix}${rawText}`;
@@ -283,14 +335,14 @@ function manageFocus(h1) {
283
335
  }
284
336
 
285
337
  const STORAGE_KEY = "real-router:scroll";
286
- const NOOP_INSTANCE = Object.freeze({
338
+ const NOOP_INSTANCE$1 = Object.freeze({
287
339
  destroy: () => {
288
340
  /* no-op */
289
341
  }
290
342
  });
291
343
  function createScrollRestoration(router, options) {
292
344
  if (typeof globalThis.window === "undefined") {
293
- return NOOP_INSTANCE;
345
+ return NOOP_INSTANCE$1;
294
346
  }
295
347
  const mode = options?.mode ?? "restore";
296
348
 
@@ -298,7 +350,7 @@ function createScrollRestoration(router, options) {
298
350
  // don't subscribe, don't register pagehide — leave the browser's native
299
351
  // auto-restore intact for the app to override if it wants to.
300
352
  if (mode === "manual") {
301
- return NOOP_INSTANCE;
353
+ return NOOP_INSTANCE$1;
302
354
  }
303
355
  const anchorEnabled = options?.anchorScrolling ?? true;
304
356
  const getContainer = options?.scrollContainer;
@@ -439,6 +491,128 @@ function canonicalReplacer(_key, val) {
439
491
  return val;
440
492
  }
441
493
 
494
+ const NOOP_INSTANCE = Object.freeze({
495
+ destroy: () => {
496
+ /* no-op */
497
+ }
498
+ });
499
+ function createViewTransitions(router) {
500
+ if (typeof document === "undefined" || typeof document.startViewTransition !== "function") {
501
+ return NOOP_INSTANCE;
502
+ }
503
+ let closeVT = null;
504
+ let currentVT = null;
505
+ // Tracks whether TRANSITION_SUCCESS fired for the current leave. Used to
506
+ // distinguish "benign cleanup abort" (router's async path aborts its own
507
+ // controller in a finally block after successful navigation) from "real
508
+ // cancellation" (concurrent navigate, guard rejection, dispose).
509
+ let successFired = false;
510
+ const resolveAndClear = () => {
511
+ closeVT?.();
512
+ closeVT = null;
513
+ };
514
+ const offLeave = router.subscribeLeave(({
515
+ signal
516
+ }) => {
517
+ // Reentrant abort: signal already aborted when we're called. Open no VT
518
+ // — router will fall through to TRANSITION_CANCELLED via isCurrentNav()
519
+ // after leave resolves. addEventListener("abort", ...) does not re-fire
520
+ // for past events, so skipping startViewTransition is the safe path.
521
+ if (signal.aborted) {
522
+ return;
523
+ }
524
+ successFired = false;
525
+ resolveAndClear();
526
+
527
+ // Return a Promise so the router awaits until the browser invokes
528
+ // updateCallback. This ensures old DOM snapshot is captured BEFORE the
529
+ // router commits the new state — giving correct exit→state→entry
530
+ // ordering (vs fire-and-forget, where URL changes before VT captures).
531
+ return new Promise(resolveLeave => {
532
+ // Capture the resolver synchronously BEFORE startViewTransition() is
533
+ // called. The browser invokes updateCallback in a later task, but
534
+ // router.subscribe (TRANSITION_SUCCESS) can fire before that. If we
535
+ // captured `resolve` inside the callback, subscribe would see closeVT
536
+ // still null and skip resolving — the deferred would hang for 4s
537
+ // until the VT API aborts with TimeoutError.
538
+ const deferred = new Promise(resolve => {
539
+ closeVT = resolve;
540
+ });
541
+ signal.addEventListener("abort", () => {
542
+ if (successFired) {
543
+ // Router's async path (#finishAsyncNavigation) aborts its own
544
+ // controller in a finally block AFTER completeTransition (and
545
+ // thus AFTER subscribe fired). This is cleanup, not
546
+ // cancellation — VT is progressing normally, do nothing.
547
+ return;
548
+ }
549
+
550
+ // Real cancellation (concurrent navigate, dispose). Resolve the
551
+ // deferred so updateCallback can complete, skip the VT so no
552
+ // stale animation leaks, and unblock the router if the abort
553
+ // fires before updateCallback was invoked.
554
+ resolveAndClear();
555
+ currentVT?.skipTransition?.();
556
+ resolveLeave();
557
+ }, {
558
+ once: true
559
+ });
560
+ try {
561
+ currentVT = document.startViewTransition(() => {
562
+ // Resolving here unblocks the router at the moment the browser
563
+ // enters updateCallback — by spec, old DOM snapshot is captured
564
+ // before this callback runs. Router now proceeds through
565
+ // activation guards and setState; the VT animation waits on
566
+ // `deferred`, which is resolved from router.subscribe after a
567
+ // task-queue tick (see NOTE on setTimeout below).
568
+ resolveLeave();
569
+ return deferred;
570
+ });
571
+ } catch {
572
+ // Defensive: spec says startViewTransition doesn't throw under
573
+ // normal conditions, but Chromium has had edge cases (detached
574
+ // document, extension interference). Clean up and unblock router.
575
+ resolveAndClear();
576
+ resolveLeave();
577
+ }
578
+ });
579
+ });
580
+ const offSuccess = router.subscribe(() => {
581
+ const resolver = closeVT;
582
+ successFired = true;
583
+ closeVT = null;
584
+ if (resolver === null) {
585
+ currentVT = null;
586
+ } else {
587
+ // CRITICAL: CANNOT use requestAnimationFrame here. When the router
588
+ // takes the async path (leave returned a Promise), subscribe fires
589
+ // AFTER the browser has already transitioned VT into the
590
+ // "update-callback-called" phase. In that phase Chromium sets
591
+ // rendering suppression to true, which ALSO blocks rAF callbacks.
592
+ // rAF would never fire → deferred never resolves → browser aborts
593
+ // vt.ready with TimeoutError after 4s (observed in Chromium).
594
+ //
595
+ // setTimeout runs on the task queue independent of the rendering
596
+ // pipeline, so it fires regardless of suppression. React's scheduler
597
+ // uses MessageChannel tasks, which are queued before our setTimeout,
598
+ // so the new DOM is committed by the time our callback runs.
599
+ setTimeout(() => {
600
+ resolver();
601
+ currentVT = null;
602
+ }, 0);
603
+ }
604
+ });
605
+ return {
606
+ destroy: () => {
607
+ offLeave();
608
+ offSuccess();
609
+ currentVT?.skipTransition?.();
610
+ currentVT = null;
611
+ resolveAndClear();
612
+ }
613
+ };
614
+ }
615
+
442
616
  function shouldNavigate(evt) {
443
617
  return evt.button === 0 && !evt.metaKey && !evt.altKey && !evt.ctrlKey && !evt.shiftKey;
444
618
  }
@@ -656,6 +830,206 @@ function useRouterTransition() {
656
830
  return createSignalFromSource(source);
657
831
  }
658
832
 
833
+ /**
834
+ * Subscribe to the router's leave-window with the universal guards baked
835
+ * in. Wraps `router.subscribeLeave` so consumers don't repeat the same
836
+ * boilerplate every time:
837
+ *
838
+ * - **Reentrant abort pre-check**: if `signal.aborted` is already `true`
839
+ * when the handler would run (rapid navigation superseded a slower
840
+ * one), the handler is skipped entirely. `signal.addEventListener(
841
+ * "abort", ...)` does not fire retroactively, so without this guard
842
+ * downstream cleanup would never trigger.
843
+ * - **Same-route skip**: by default, `route.name === nextRoute.name`
844
+ * short-circuits the handler — query-only navigations (sort, filter,
845
+ * pagination) skip the work. Opt out with `skipSameRoute: false`.
846
+ *
847
+ * Returns nothing — the subscription's lifecycle is bound to the
848
+ * component via `onCleanup`.
849
+ *
850
+ * If the handler returns a Promise, the router blocks on it. If the
851
+ * Promise resolves, navigation proceeds. If it rejects, the router emits
852
+ * `TRANSITION_CANCELLED`.
853
+ *
854
+ * **Handler reactivity (Solid)**: Solid components run **once** at mount;
855
+ * `handler` is captured in closure at the call site. If you need
856
+ * different behavior across renders, derive it from a signal inside the
857
+ * handler body — do not rely on swapping the handler reference.
858
+ *
859
+ * @example Animation
860
+ * ```tsx
861
+ * let ref: HTMLDivElement | undefined;
862
+ *
863
+ * useRouteExit(async ({ signal }) => {
864
+ * const el = ref;
865
+ * if (!el) return;
866
+ * el.classList.add("fade-out");
867
+ * const cleanup = () => el.classList.remove("fade-out");
868
+ * signal.addEventListener("abort", cleanup, { once: true });
869
+ * try {
870
+ * el.getBoundingClientRect(); // style flush
871
+ * await Promise.allSettled(el.getAnimations().map((a) => a.finished));
872
+ * } finally {
873
+ * cleanup();
874
+ * }
875
+ * });
876
+ * ```
877
+ *
878
+ * @example Auto-save form draft
879
+ * ```tsx
880
+ * useRouteExit(async ({ signal }) => {
881
+ * if (formState.dirty) await api.saveDraft(formState, { signal });
882
+ * });
883
+ * ```
884
+ *
885
+ * @example Reading rich transition metadata via `nextRoute.transition`
886
+ * ```tsx
887
+ * useRouteExit(({ route, nextRoute }) => {
888
+ * if (nextRoute.transition.segments.deactivated.includes("products")) {
889
+ * productCache.clear();
890
+ * }
891
+ * if (nextRoute.transition.redirected) {
892
+ * return;
893
+ * }
894
+ * });
895
+ * ```
896
+ */
897
+ function useRouteExit(handler, options) {
898
+ const router = useRouter();
899
+ const skipSameRoute = options?.skipSameRoute ?? true;
900
+ const off = router.subscribeLeave(({
901
+ route,
902
+ nextRoute,
903
+ signal
904
+ }) => {
905
+ if (skipSameRoute && route.name === nextRoute.name) {
906
+ return;
907
+ }
908
+
909
+ // Reentrant abort: signal is already aborted when listener fires
910
+ // (e.g. a newer navigate superseded this one before subscribeLeave
911
+ // even ran). addEventListener("abort", ...) does not fire
912
+ // retroactively, so we skip the handler entirely.
913
+ if (signal.aborted) {
914
+ return;
915
+ }
916
+ return handler({
917
+ route,
918
+ nextRoute,
919
+ signal
920
+ });
921
+ });
922
+ onCleanup(off);
923
+ }
924
+
925
+ /**
926
+ * Fire `handler` once when the component mounts as a result of a
927
+ * navigation. Mirror of `useRouteExit` for the entry side.
928
+ *
929
+ * What this hook covers that an ad-hoc `createEffect` + `useRoute()`
930
+ * doesn't:
931
+ *
932
+ * - **Skip-initial**: handler is skipped when there is no
933
+ * `transition.from` (i.e. first-load mount). Most consumers want to
934
+ * fire side effects only on real navigations, not on hydration.
935
+ * - **Same-route skip** (default): handler is skipped when
936
+ * `route.transition.from === route.name`. Sort/filter/query-only
937
+ * navigations re-trigger the effect (because the `route` reference
938
+ * changes), but they are not "entries" in the animation / analytics
939
+ * sense — the component instance has stayed mounted throughout.
940
+ * Opt out with `skipSameRoute: false`.
941
+ * - **Mount-time `route` / `previousRoute` snapshot**: the handler
942
+ * receives the values that were live at the moment of effect
943
+ * activation, not the latest ones (which may have moved on if the
944
+ * user navigated again before the effect drained).
945
+ *
946
+ * **Handler reactivity (Solid)**: Solid components run **once** at mount;
947
+ * `handler` is captured in closure when the hook is called. If you need
948
+ * different behavior across renders, derive it from a signal inside the
949
+ * handler body — do not rely on swapping the handler reference.
950
+ *
951
+ * @example Direction-aware entry animation
952
+ * ```tsx
953
+ * useRouteEnter(({ route }) => {
954
+ * const direction = route.context.browser?.direction;
955
+ * ref?.classList.add(
956
+ * direction === "back" ? "slide-from-left" : "slide-from-right",
957
+ * );
958
+ * });
959
+ * ```
960
+ *
961
+ * @example Analytics page-enter event (skip-initial built-in)
962
+ * ```tsx
963
+ * useRouteEnter(({ route, previousRoute }) => {
964
+ * analytics.track("page_enter", {
965
+ * route: route.name,
966
+ * from: previousRoute.name,
967
+ * });
968
+ * });
969
+ * ```
970
+ *
971
+ * @example Reading rich transition metadata via `route.transition`
972
+ * ```tsx
973
+ * useRouteEnter(({ route }) => {
974
+ * if (route.transition.redirected) {
975
+ * showToast(`Redirected from ${route.transition.from}`);
976
+ * }
977
+ * if (route.transition.segments.activated.includes("products")) {
978
+ * // products subtree just became active
979
+ * }
980
+ * });
981
+ * ```
982
+ */
983
+ function useRouteEnter(handler, options) {
984
+ const routeState = useRoute();
985
+ const skipSameRoute = options?.skipSameRoute ?? true;
986
+ let lastHandledRoute = null;
987
+ createEffect(() => {
988
+ const {
989
+ route,
990
+ previousRoute
991
+ } = routeState();
992
+
993
+ // Early-exit guards, top-down:
994
+ //
995
+ // - **Defensive**: `route` may be undefined during SSR or
996
+ // pre-start hydration. Not testable from vitest (tests start
997
+ // the router before render), so v8-ignored.
998
+ // - **Skip-initial**: `state.transition.from` is undefined only
999
+ // for the very first state committed by `router.start()`.
1000
+ // - **Skip-same-route**: query-only navigations have
1001
+ // `transition.from === route.name`. Opt-out via
1002
+ // `skipSameRoute: false`.
1003
+ // - **Defensive dedupe + missing `previousRoute`**: same `route`
1004
+ // ref between effect activations is unexpected on Solid (effects
1005
+ // run once per dependency change); `!previousRoute` is unreachable
1006
+ // once `transition.from` is set (the two are populated together by
1007
+ // core). Both kept for parity with React; v8-ignored.
1008
+ /* v8 ignore start */
1009
+ if (!route) {
1010
+ return;
1011
+ }
1012
+ /* v8 ignore stop */
1013
+ if (!route.transition.from) {
1014
+ return;
1015
+ }
1016
+ if (skipSameRoute && route.transition.from === route.name) {
1017
+ return;
1018
+ }
1019
+ /* v8 ignore start */
1020
+ if (lastHandledRoute === route || !previousRoute) {
1021
+ return;
1022
+ }
1023
+ /* v8 ignore stop */
1024
+
1025
+ lastHandledRoute = route;
1026
+ handler({
1027
+ route,
1028
+ previousRoute
1029
+ });
1030
+ });
1031
+ }
1032
+
659
1033
  function isRouteActive(linkRouteName, currentRouteName) {
660
1034
  return currentRouteName === linkRouteName || currentRouteName.startsWith(`${linkRouteName}.`);
661
1035
  }
@@ -678,6 +1052,15 @@ function RouterProvider(props) {
678
1052
  sr.destroy();
679
1053
  });
680
1054
  });
1055
+ onMount(() => {
1056
+ if (!props.viewTransitions) {
1057
+ return;
1058
+ }
1059
+ const vt = createViewTransitions(props.router);
1060
+ onCleanup(() => {
1061
+ vt.destroy();
1062
+ });
1063
+ });
681
1064
  const navigator = getNavigator(props.router);
682
1065
  const routeSource = createRouteSource(props.router);
683
1066
  const routeSignal = createSignalFromSource(routeSource);
@@ -701,4 +1084,4 @@ function RouterProvider(props) {
701
1084
  });
702
1085
  }
703
1086
 
704
- export { Link, RouteContext, RouteView, RouterContext, RouterErrorBoundary, RouterProvider, createSignalFromSource, createStoreFromSource, link, useNavigator, useRoute, useRouteNode, useRouteNodeStore, useRouteStore, useRouteUtils, useRouter, useRouterTransition };
1087
+ export { Link, RouteContext, RouteView, RouterContext, RouterErrorBoundary, RouterProvider, createSignalFromSource, createStoreFromSource, link, useNavigator, useRoute, useRouteEnter, useRouteExit, useRouteNode, useRouteNodeStore, useRouteStore, useRouteUtils, useRouter, useRouterTransition };
@@ -5,6 +5,7 @@ export interface RouteProviderProps {
5
5
  router: Router;
6
6
  announceNavigation?: boolean;
7
7
  scrollRestoration?: ScrollRestorationOptions;
8
+ viewTransitions?: boolean;
8
9
  }
9
10
  export declare function isRouteActive(linkRouteName: string, currentRouteName: string): boolean;
10
11
  export declare function RouterProvider(props: ParentProps<RouteProviderProps>): JSX.Element;
@@ -1 +1 @@
1
- {"version":3,"file":"RouterProvider.d.ts","sourceRoot":"","sources":["../../src/RouterProvider.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAEjD,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,iBAAiB,CAAC,EAAE,wBAAwB,CAAC;CAC9C;AAED,wBAAgB,aAAa,CAC3B,aAAa,EAAE,MAAM,EACrB,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAKT;AAED,wBAAgB,cAAc,CAC5B,KAAK,EAAE,WAAW,CAAC,kBAAkB,CAAC,GACrC,GAAG,CAAC,OAAO,CA2Cb"}
1
+ {"version":3,"file":"RouterProvider.d.ts","sourceRoot":"","sources":["../../src/RouterProvider.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAEjD,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,iBAAiB,CAAC,EAAE,wBAAwB,CAAC;IAC7C,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,wBAAgB,aAAa,CAC3B,aAAa,EAAE,MAAM,EACrB,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAKT;AAED,wBAAgB,cAAc,CAC5B,KAAK,EAAE,WAAW,CAAC,kBAAkB,CAAC,GACrC,GAAG,CAAC,OAAO,CAuDb"}
@@ -1,4 +1,4 @@
1
- import { Match, NotFound } from "./components";
1
+ import { Match, NotFound, Self } from "./components";
2
2
  import type { RouteViewProps } from "./types";
3
3
  import type { JSX } from "solid-js";
4
4
  declare function RouteViewRoot(props: Readonly<RouteViewProps>): JSX.Element;
@@ -7,7 +7,8 @@ declare namespace RouteViewRoot {
7
7
  }
8
8
  export declare const RouteView: typeof RouteViewRoot & {
9
9
  Match: typeof Match;
10
+ Self: typeof Self;
10
11
  NotFound: typeof NotFound;
11
12
  };
12
- export type { RouteViewProps, MatchProps as RouteViewMatchProps, NotFoundProps as RouteViewNotFoundProps, } from "./types";
13
+ export type { RouteViewProps, MatchProps as RouteViewMatchProps, SelfProps as RouteViewSelfProps, NotFoundProps as RouteViewNotFoundProps, } from "./types";
13
14
  //# sourceMappingURL=RouteView.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RouteView.d.ts","sourceRoot":"","sources":["../../../../src/components/RouteView/RouteView.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAK/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAEpC,iBAAS,aAAa,CAAC,KAAK,EAAE,QAAQ,CAAC,cAAc,CAAC,GAAG,GAAG,CAAC,OAAO,CAgCnE;kBAhCQ,aAAa;;;AAoCtB,eAAO,MAAM,SAAS;;;CAAoD,CAAC;AAE3E,YAAY,EACV,cAAc,EACd,UAAU,IAAI,mBAAmB,EACjC,aAAa,IAAI,sBAAsB,GACxC,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"RouteView.d.ts","sourceRoot":"","sources":["../../../../src/components/RouteView/RouteView.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAKrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAEpC,iBAAS,aAAa,CAAC,KAAK,EAAE,QAAQ,CAAC,cAAc,CAAC,GAAG,GAAG,CAAC,OAAO,CAgCnE;kBAhCQ,aAAa;;;AAoCtB,eAAO,MAAM,SAAS;;;;CAIpB,CAAC;AAEH,YAAY,EACV,cAAc,EACd,UAAU,IAAI,mBAAmB,EACjC,SAAS,IAAI,kBAAkB,EAC/B,aAAa,IAAI,sBAAsB,GACxC,MAAM,SAAS,CAAC"}
@@ -1,6 +1,7 @@
1
- import type { MatchProps, NotFoundProps } from "./types";
1
+ import type { MatchProps, NotFoundProps, SelfProps } from "./types";
2
2
  import type { JSX } from "solid-js";
3
3
  export declare const MATCH_MARKER: unique symbol;
4
+ export declare const SELF_MARKER: unique symbol;
4
5
  export declare const NOT_FOUND_MARKER: unique symbol;
5
6
  export interface MatchMarker {
6
7
  $$type: typeof MATCH_MARKER;
@@ -9,15 +10,24 @@ export interface MatchMarker {
9
10
  fallback?: JSX.Element;
10
11
  children: JSX.Element;
11
12
  }
13
+ export interface SelfMarker {
14
+ $$type: typeof SELF_MARKER;
15
+ fallback?: JSX.Element;
16
+ children: JSX.Element;
17
+ }
12
18
  export interface NotFoundMarker {
13
19
  $$type: typeof NOT_FOUND_MARKER;
14
20
  children: JSX.Element;
15
21
  }
16
- export type RouteViewMarker = MatchMarker | NotFoundMarker;
22
+ export type RouteViewMarker = MatchMarker | SelfMarker | NotFoundMarker;
17
23
  export declare function Match(props: MatchProps): JSX.Element;
18
24
  export declare namespace Match {
19
25
  var displayName: string;
20
26
  }
27
+ export declare function Self(props: SelfProps): JSX.Element;
28
+ export declare namespace Self {
29
+ var displayName: string;
30
+ }
21
31
  export declare function NotFound(props: NotFoundProps): JSX.Element;
22
32
  export declare namespace NotFound {
23
33
  var displayName: string;
@@ -1 +1 @@
1
- {"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../../../../src/components/RouteView/components.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACzD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAIpC,eAAO,MAAM,YAAY,eAA4B,CAAC;AAEtD,eAAO,MAAM,gBAAgB,eAA+B,CAAC;AAE7D,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,OAAO,YAAY,CAAC;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,OAAO,CAAC;IACf,QAAQ,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;IACvB,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,OAAO,gBAAgB,CAAC;IAChC,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC;CACvB;AAED,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,cAAc,CAAC;AAE3D,wBAAgB,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,GAAG,CAAC,OAAO,CAepD;yBAfe,KAAK;;;AAmBrB,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,GAAG,CAAC,OAAO,CAU1D;yBAVe,QAAQ"}
1
+ {"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../../../../src/components/RouteView/components.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAIpC,eAAO,MAAM,YAAY,eAA4B,CAAC;AAEtD,eAAO,MAAM,WAAW,eAA2B,CAAC;AAEpD,eAAO,MAAM,gBAAgB,eAA+B,CAAC;AAE7D,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,OAAO,YAAY,CAAC;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,OAAO,CAAC;IACf,QAAQ,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;IACvB,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,OAAO,WAAW,CAAC;IAC3B,QAAQ,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;IACvB,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,OAAO,gBAAgB,CAAC;IAChC,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC;CACvB;AAED,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,UAAU,GAAG,cAAc,CAAC;AAExE,wBAAgB,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,GAAG,CAAC,OAAO,CAepD;yBAfe,KAAK;;;AAmBrB,wBAAgB,IAAI,CAAC,KAAK,EAAE,SAAS,GAAG,GAAG,CAAC,OAAO,CAWlD;yBAXe,IAAI;;;AAepB,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,GAAG,CAAC,OAAO,CAU1D;yBAVe,QAAQ"}
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../../src/components/RouteView/helpers.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAGV,eAAe,EAChB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAEpC,wBAAgB,cAAc,CAC5B,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,MAAM,EACvB,KAAK,EAAE,OAAO,GACb,OAAO,CAMT;AAoBD,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,OAAO,EACjB,MAAM,EAAE,eAAe,EAAE,GACxB,IAAI,CAgBN;AAED,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,eAAe,EAAE,EAC3B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GACf,GAAG,CAAC,OAAO,EAAE,CAyCf"}
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../../src/components/RouteView/helpers.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAGV,eAAe,EAEhB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAEpC,wBAAgB,cAAc,CAC5B,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,MAAM,EACvB,KAAK,EAAE,OAAO,GACb,OAAO,CAMT;AA6BD,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,OAAO,EACjB,MAAM,EAAE,eAAe,EAAE,GACxB,IAAI,CAoBN;AAqCD,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,eAAe,EAAE,EAC3B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GACf,GAAG,CAAC,OAAO,EAAE,CAsCf"}
@@ -1,3 +1,3 @@
1
1
  export { RouteView } from "./RouteView";
2
- export type { RouteViewProps, RouteViewMatchProps, RouteViewNotFoundProps, } from "./RouteView";
2
+ export type { RouteViewProps, RouteViewMatchProps, RouteViewSelfProps, RouteViewNotFoundProps, } from "./RouteView";
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/RouteView/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,YAAY,EACV,cAAc,EACd,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/RouteView/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,YAAY,EACV,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,aAAa,CAAC"}
@@ -9,6 +9,12 @@ export interface MatchProps {
9
9
  readonly fallback?: JSX.Element;
10
10
  readonly children: JSX.Element;
11
11
  }
12
+ export interface SelfProps {
13
+ /** Fallback content while children are suspended. */
14
+ readonly fallback?: JSX.Element;
15
+ /** Content to render when the active route name equals the parent RouteView's nodeName. */
16
+ readonly children: JSX.Element;
17
+ }
12
18
  export interface NotFoundProps {
13
19
  readonly children: JSX.Element;
14
20
  }
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/components/RouteView/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAEpC,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC;CAChC;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,QAAQ,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;IAChC,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC;CAChC;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC;CAChC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/components/RouteView/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAEpC,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC;CAChC;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,QAAQ,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;IAChC,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC;CAChC;AAED,MAAM,WAAW,SAAS;IACxB,qDAAqD;IACrD,QAAQ,CAAC,QAAQ,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;IAChC,2FAA2F;IAC3F,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC;CAChC;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC;CAChC"}
@@ -0,0 +1,27 @@
1
+ import type { Router } from "@real-router/core";
2
+ export interface DirectionTracker {
3
+ destroy: () => void;
4
+ }
5
+ /**
6
+ * Track navigation direction (forward / back) and write it to
7
+ * `<html data-nav-direction>` on every leave. CSS / JS readers consume
8
+ * the attribute via `html[data-nav-direction="back"]` selectors or
9
+ * `document.documentElement.dataset.navDirection`.
10
+ *
11
+ * Mechanism-agnostic — works identically whether downstream UI uses CSS
12
+ * `@keyframes`, View Transitions pseudo-elements, or library state
13
+ * (motion's `motion.div initial={{ x: ... }}`).
14
+ *
15
+ * Implementation:
16
+ * - On install, set `data-nav-direction="forward"` baseline.
17
+ * - Attach a `popstate` listener that flips an internal flag to
18
+ * `true`. Browser back/forward navigation triggers popstate; user
19
+ * clicks on `<Link>` / programmatic `router.navigate(...)` do not.
20
+ * - On every `subscribeLeave`, write
21
+ * `popstateFlag ? "back" : "forward"` and reset the flag.
22
+ *
23
+ * Returns `{ destroy }` to clean up the listener and clear the dataset
24
+ * attribute.
25
+ */
26
+ export declare function createDirectionTracker(router: Router): DirectionTracker;
27
+ //# sourceMappingURL=direction-tracker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"direction-tracker.d.ts","sourceRoot":"","sources":["../../../src/dom-utils/direction-tracker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAQD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,gBAAgB,CAoCvE"}