@real-router/sources 0.15.0 → 0.16.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.
- package/README.md +13 -11
- package/dist/cjs/index.d.ts +33 -60
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.d.mts +33 -60
- package/dist/esm/index.d.mts.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/package.json +5 -4
package/dist/esm/index.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Params, Router, RouterError, SearchParams, State } from "@real-router/core";
|
|
2
|
-
//#region src/types.d.ts
|
|
3
2
|
interface RouteSnapshot<P extends Params = Params> {
|
|
4
3
|
route: State<P> | undefined;
|
|
5
4
|
previousRoute: State | undefined;
|
|
@@ -56,8 +55,6 @@ interface DismissableErrorSnapshot {
|
|
|
56
55
|
/** Dismisses the current error. Next error (new version) becomes visible again. */
|
|
57
56
|
resetError: () => void;
|
|
58
57
|
}
|
|
59
|
-
//#endregion
|
|
60
|
-
//#region src/createRouteSource.d.ts
|
|
61
58
|
/**
|
|
62
59
|
* Creates a source for the full route state.
|
|
63
60
|
*
|
|
@@ -66,8 +63,6 @@ interface DismissableErrorSnapshot {
|
|
|
66
63
|
* This is compatible with React's useSyncExternalStore and Strict Mode.
|
|
67
64
|
*/
|
|
68
65
|
export declare function createRouteSource(router: Router): RouterSource<RouteSnapshot>;
|
|
69
|
-
//#endregion
|
|
70
|
-
//#region src/createRouteNodeSource.d.ts
|
|
71
66
|
/**
|
|
72
67
|
* Creates a source scoped to a specific route node.
|
|
73
68
|
*
|
|
@@ -86,8 +81,6 @@ export declare function createRouteSource(router: Router): RouterSource<RouteSna
|
|
|
86
81
|
* can use `buildRouteNodeSource` internally (not exported).
|
|
87
82
|
*/
|
|
88
83
|
export declare function createRouteNodeSource(router: Router, nodeName: string): RouterSource<RouteNodeSnapshot>;
|
|
89
|
-
//#endregion
|
|
90
|
-
//#region src/createActiveRouteSource.d.ts
|
|
91
84
|
/**
|
|
92
85
|
* Creates a source tracking whether a route (with given params/options) is active.
|
|
93
86
|
*
|
|
@@ -104,8 +97,6 @@ export declare function createRouteNodeSource(router: Router, nodeName: string):
|
|
|
104
97
|
* `router.subscribe` handle.
|
|
105
98
|
*/
|
|
106
99
|
export declare function createActiveRouteSource(router: Router, routeName: string, params?: Params, search?: SearchParams, options?: ActiveRouteSourceOptions): RouterSource<boolean>;
|
|
107
|
-
//#endregion
|
|
108
|
-
//#region src/createActiveSource.d.ts
|
|
109
100
|
/**
|
|
110
101
|
* Framework-agnostic fast/slow builder for an adapter `<Link>`'s active-route
|
|
111
102
|
* `RouterSource<boolean>`. An adapter routing its active-state check through
|
|
@@ -144,8 +135,6 @@ export declare function createActiveRouteSource(router: Router, routeName: strin
|
|
|
144
135
|
* the slow path preserves that.
|
|
145
136
|
*/
|
|
146
137
|
export declare function createActiveSource(router: Router, routeName: string, params: Params | undefined, search: SearchParams | undefined, strict: boolean, ignoreQueryParams: boolean, hash: string | undefined): RouterSource<boolean>;
|
|
147
|
-
//#endregion
|
|
148
|
-
//#region src/createTransitionSource.d.ts
|
|
149
138
|
export declare function createTransitionSource(router: Router): RouterSource<RouterTransitionSnapshot>;
|
|
150
139
|
/**
|
|
151
140
|
* Returns a per-router cached transition source shared across all consumers.
|
|
@@ -162,8 +151,6 @@ export declare function createTransitionSource(router: Router): RouterSource<Rou
|
|
|
162
151
|
* a working `destroy()`.
|
|
163
152
|
*/
|
|
164
153
|
export declare function getTransitionSource(router: Router): RouterSource<RouterTransitionSnapshot>;
|
|
165
|
-
//#endregion
|
|
166
|
-
//#region src/createErrorSource.d.ts
|
|
167
154
|
export declare function createErrorSource(router: Router): RouterSource<RouterErrorSnapshot>;
|
|
168
155
|
/**
|
|
169
156
|
* Returns a per-router cached error source shared across all consumers.
|
|
@@ -195,8 +182,6 @@ export declare function getErrorSource(router: Router): RouterSource<RouterError
|
|
|
195
182
|
* genuine invalid-router error there.
|
|
196
183
|
*/
|
|
197
184
|
export declare function primeErrorSource(router: Router): void;
|
|
198
|
-
//#endregion
|
|
199
|
-
//#region src/createDismissableError.d.ts
|
|
200
185
|
/**
|
|
201
186
|
* Returns a per-router cached source that wraps `getErrorSource(router)` with
|
|
202
187
|
* an integrated "dismissed" version counter, exposing a single reactive
|
|
@@ -217,8 +202,6 @@ export declare function primeErrorSource(router: Router): void;
|
|
|
217
202
|
* a no-op. Shared across all `RouterErrorBoundary` consumers.
|
|
218
203
|
*/
|
|
219
204
|
export declare function createDismissableError(router: Router): RouterSource<DismissableErrorSnapshot>;
|
|
220
|
-
//#endregion
|
|
221
|
-
//#region src/createActiveNameSelector.d.ts
|
|
222
205
|
interface ActiveNameSelector {
|
|
223
206
|
/**
|
|
224
207
|
* Subscribes to active-state changes of a specific route name.
|
|
@@ -258,8 +241,6 @@ interface ActiveNameSelector {
|
|
|
258
241
|
* @see Solid reference implementation — `packages/solid/src/RouterProvider.tsx`
|
|
259
242
|
*/
|
|
260
243
|
export declare function createActiveNameSelector(router: Router): ActiveNameSelector;
|
|
261
|
-
//#endregion
|
|
262
|
-
//#region src/normalizeActiveOptions.d.ts
|
|
263
244
|
/**
|
|
264
245
|
* Normalized options shape — booleans are required (filled with defaults),
|
|
265
246
|
* `hash` stays `string | undefined` because `undefined` is the meaningful
|
|
@@ -283,40 +264,30 @@ export declare const DEFAULT_ACTIVE_OPTIONS: Readonly<NormalizedActiveOptions>;
|
|
|
283
264
|
* downstream consumers that require all fields present.
|
|
284
265
|
*/
|
|
285
266
|
export declare function normalizeActiveOptions(options?: ActiveRouteSourceOptions): NormalizedActiveOptions;
|
|
286
|
-
//#endregion
|
|
287
|
-
//#region src/canonicalJson.d.ts
|
|
288
267
|
/**
|
|
289
|
-
* Serializes a
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
* **Divergence from `shared/dom-utils/scroll-restore.canonicalJson` — by
|
|
297
|
-
* design.** That sibling implementation is the cheap navigation-hot-path
|
|
298
|
-
* variant (uses `localeCompare`, plain-object accumulator, native cycle
|
|
299
|
-
* detector) and pairs with `safeKeyOf` for crash-tolerance. This one is the
|
|
300
|
-
* strict cache-key variant: byte-order compare, prototype-less accumulator,
|
|
301
|
-
* bespoke cycle detection — eagerly throws on inputs that would cause
|
|
302
|
-
* collisions or pollution, so callers can fall back to non-cached sources.
|
|
303
|
-
* They are NOT interchangeable; cross-package equivalence is explicitly not
|
|
304
|
-
* a goal (audit-2 / audit-2026-05-17 §2).
|
|
268
|
+
* Serializes a params or search bag into a stable cache key: the bag's own keys
|
|
269
|
+
* are sorted, so `{ a: 1, b: 2 }` and `{ b: 2, a: 1 }` produce the same output.
|
|
270
|
+
*
|
|
271
|
+
* Used as a cache key for `createActiveRouteSource`, so two bags share a
|
|
272
|
+
* cached source only when `@real-router/core` compares them equal: each value
|
|
273
|
+
* is spelled as core compares it (#2905).
|
|
305
274
|
*
|
|
306
275
|
* Edge cases:
|
|
307
|
-
* -
|
|
276
|
+
* - A plain object inside the bag keeps its own key order: core compares it by
|
|
277
|
+
* `JSON.stringify`, which spells `{ a, b }` and `{ b, a }` apart.
|
|
278
|
+
* - An array is read by index, as core compares it, and keeps its order.
|
|
308
279
|
* - `undefined` values are dropped (standard JSON behaviour).
|
|
309
|
-
* - `Date` is
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
*
|
|
280
|
+
* - A `Date` that is a value, or an element of an array value, is spelled by
|
|
281
|
+
* its `getTime()`, apart from every string, because core never equates a
|
|
282
|
+
* `Date` with a string there. Inside a plain object it is its `toJSON` ISO
|
|
283
|
+
* string, as `JSON.stringify` spells it for core.
|
|
284
|
+
* - A function, a symbol, a number that is not finite, and `undefined` in an
|
|
285
|
+
* array value throw: JSON drops them or spells them `null`.
|
|
315
286
|
* - `BigInt` throws via `JSON.stringify` defaults.
|
|
316
|
-
* -
|
|
317
|
-
* `
|
|
318
|
-
*
|
|
319
|
-
*
|
|
287
|
+
* - Any other object that is not a plain one or an array throws: a `Map`, a
|
|
288
|
+
* `Set`, a `RegExp`, a class instance, a `Temporal` value, a `URL`. JSON would
|
|
289
|
+
* spell it by its own enumerable fields, or as `"{}"`, while core compares it
|
|
290
|
+
* by its `toString` or by identity.
|
|
320
291
|
* - Circular references throw `TypeError` (parity with native `JSON.stringify`).
|
|
321
292
|
* The replacer copies each object level into a fresh prototype-less record,
|
|
322
293
|
* so we must run our own cycle detection — the native detector never sees
|
|
@@ -324,12 +295,11 @@ export declare function normalizeActiveOptions(options?: ActiveRouteSourceOption
|
|
|
324
295
|
* - `__proto__` keys are preserved as own properties (no prototype pollution
|
|
325
296
|
* and no silent collision between `{ __proto__: x, b: 1 }` and `{ b: 1 }`).
|
|
326
297
|
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
298
|
+
* A throw sends the caller to its non-cached fallback path. Only a plain
|
|
299
|
+
* object whose single key is `"\u0000Date"` shares a `Date`'s spelling, which
|
|
300
|
+
* is unsupported.
|
|
329
301
|
*/
|
|
330
302
|
export declare function canonicalJson(value: unknown): string;
|
|
331
|
-
//#endregion
|
|
332
|
-
//#region src/createRouteEnterGate.d.ts
|
|
333
303
|
/**
|
|
334
304
|
* Context handed to a route-enter handler once a navigation-driven mount is
|
|
335
305
|
* confirmed. `previousRoute` is **non-nullable** — the gate is the sole bridge
|
|
@@ -384,8 +354,6 @@ type RouteEnterGate = (route: State | undefined, previousRoute: State | undefine
|
|
|
384
354
|
* `isDeactivated`, #1221) compose *before* this gate and stay adapter-side.
|
|
385
355
|
*/
|
|
386
356
|
export declare function createRouteEnterGate(): RouteEnterGate;
|
|
387
|
-
//#endregion
|
|
388
|
-
//#region src/guardLeaveListener.d.ts
|
|
389
357
|
type LeaveFn = Parameters<Router["subscribeLeave"]>[0];
|
|
390
358
|
/**
|
|
391
359
|
* Context handed to a route-exit handler when a genuine departure is approved.
|
|
@@ -423,13 +391,18 @@ type LeaveHandler = (context: RouteExitContext) => void | Promise<void>;
|
|
|
423
391
|
* core's `settleLeavePromises` and **blocks** the activation phase.
|
|
424
392
|
*
|
|
425
393
|
* **Error contract:** a rejected handler Promise rejects `navigate()` with the
|
|
426
|
-
* handler's **original error**
|
|
427
|
-
*
|
|
428
|
-
*
|
|
429
|
-
* `opts.signal`). A
|
|
430
|
-
*
|
|
394
|
+
* handler's **original error** (a value that is not an `Error` arrives
|
|
395
|
+
* wrapped in one) and emits `TRANSITION_ERROR` — it is NOT re-coded to
|
|
396
|
+
* `TRANSITION_CANCELLED`, which arises when the payload `signal` aborts
|
|
397
|
+
* (supersede / `stop()` / `dispose()` / external `opts.signal`). A handler
|
|
398
|
+
* that rejects with a `RouterError(TRANSITION_CANCELLED)` itself cancels the
|
|
399
|
+
* navigation quietly: `navigate()` rejects with that error and core emits
|
|
400
|
+
* `TRANSITION_CANCEL` instead (#2787). A handler that rejects with the error
|
|
401
|
+
* the router ended ANOTHER navigation with — it awaited that navigation's
|
|
402
|
+
* work — fails this one with `CANNOT_DEACTIVATE` (#2786). A fire-and-forget
|
|
403
|
+
* call here would silently un-block the transition, so arm 3 must stay a
|
|
404
|
+
* passthrough.
|
|
431
405
|
*/
|
|
432
406
|
export declare function guardLeaveListener(handler: LeaveHandler, options?: UseRouteExitOptions): LeaveFn;
|
|
433
|
-
//#endregion
|
|
434
407
|
export type { ActiveNameSelector, ActiveRouteSourceOptions, DismissableErrorSnapshot, RouteEnterContext, RouteEnterGate, RouteExitContext, RouteNodeSnapshot, RouteSnapshot, RouterErrorSnapshot, RouterSource, RouterTransitionSnapshot, UseRouteExitOptions };
|
|
435
408
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/esm/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/types.ts","../../src/createRouteSource.ts","../../src/createRouteNodeSource.ts","../../src/createActiveRouteSource.ts","../../src/createActiveSource.ts","../../src/createTransitionSource.ts","../../src/createErrorSource.ts","../../src/createDismissableError.ts","../../src/createActiveNameSelector.ts","../../src/normalizeActiveOptions.ts","../../src/canonicalJson.ts","../../src/createRouteEnterGate.ts","../../src/guardLeaveListener.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/types.ts","../../src/createRouteSource.ts","../../src/createRouteNodeSource.ts","../../src/createActiveRouteSource.ts","../../src/createActiveSource.ts","../../src/createTransitionSource.ts","../../src/createErrorSource.ts","../../src/createDismissableError.ts","../../src/createActiveNameSelector.ts","../../src/normalizeActiveOptions.ts","../../src/canonicalJson.ts","../../src/createRouteEnterGate.ts","../../src/guardLeaveListener.ts"],"mappings":";UAEiB,cAAc,UAAU,SAAS;EAChD,OAAO,MAAM;EACb,eAAe;;UAGA,kBAAkB,UAAU,SAAS;EACpD,OAAO,MAAM;EACb,eAAe;;UAGA,aAAa;EAC5B,YAAY;EACZ,mBAAmB;EACnB;;UAGe;EACf;EACA;;;;;;;;;;;;;;;EAeA;;UAGe;EACf;EACA;EACA,SAAS;EACT,WAAW;;UAGI;EACf,OAAO;EACP,SAAS;EACT,WAAW;EACX;;UAGe;;EAEf,OAAO;;EAEP,SAAS;;EAET,WAAW;;EAEX;;EAEA;;;;;;;;;wBCjDc,kBAAkB,QAAQ,SAAS,aAAa;;;;;;;;;;;;;;;;;;wBCgBhD,sBACd,QAAQ,QACR,mBACC,aAAa;;;;;;;;;;;;;;;;wBCDA,wBACd,QAAQ,QACR,mBACA,SAAS,QACT,SAAS,cACT,UAAU,2BACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBCQa,mBACd,QAAQ,QACR,mBACA,QAAQ,oBACR,QAAQ,0BACR,iBACA,4BACA,2BACC;wBCkCa,uBACd,QAAQ,SACP,aAAa;;;;;;;;;;;;;;;wBA8HA,oBACd,QAAQ,SACP,aAAa;wBChMA,kBACd,QAAQ,SACP,aAAa;;;;;;;;;;;;;;;wBA2FA,eACd,QAAQ,SACP,aAAa;;;;;;;;;;;;;;;wBAkCA,iBAAiB,QAAQ;;;;;;;;;;;;;;;;;;;;wBC3HzB,uBACd,QAAQ,SACP,aAAa;UC3BC;;;;;;EAMf,YAAY,mBAAmB;;;;;EAK/B,WAAW;;EAEX;;;;;;;;;;;;;;;;;;;;;;;;;wBA4Bc,yBAAyB,QAAQ,SAAS;;;;;;UCxCzC;EACf;EACA;EACA;;;;;;;qBAQW,wBAAwB,SAAS;;;;;;;wBAa9B,uBACd,UAAU,2BACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBCsBa,cAAc;;;;;;;UC/Cb;;EAEf,OAAO;;EAEP,eAAe;;;;;;;;;;KAWL,kBACV,OAAO,mBACP,eAAe,mBACf,2BACG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAkCW,wBAAwB;KCvDnC,UAAU,WAAW;;;;;;UAOT;;EAEf,OAAO;;EAEP,WAAW;;EAEX,QAAQ;;UAGO;;;;;EAKf;;KAGG,gBAAgB,SAAS,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA6B1C,mBACd,SAAS,cACT,UAAU,sBACT"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{areRoutesRelated as e}from"@real-router/route-utils";import{events as t}from"@real-router/core";import{getPluginApi as n}from"@real-router/core/api";var r=class{#e;#t=!1;#n=new Set;#r;#i;#a;constructor(e,t){this.#e=e,this.#r=t?.onFirstSubscribe,this.#i=t?.onLastUnsubscribe,this.#a=t?.onDestroy,this.subscribe=this.subscribe.bind(this),this.getSnapshot=this.getSnapshot.bind(this),this.destroy=this.destroy.bind(this)}subscribe(e){if(this.#t)return()=>{};let t=this.#n.size===0;return this.#n.add(e),t&&this.#r&&this.#r(),()=>{this.#n.delete(e),!this.#t&&this.#n.size===0&&this.#i&&this.#i()}}getSnapshot(){return this.#e}updateSnapshot(e){if(!this.#t){this.#e=e;for(let e of this.#n)try{e()}catch(e){queueMicrotask(()=>{throw e})}}}destroy(){this.#t||(this.#t=!0,this.#a?.(),this.#n.clear())}};function i(e){return(e?.context)?.url?.hash}function a(e,t){return e===t?e:e?.path!==t?.path||i(e)!==i(t)||o(t)?t:e}function o(e){return e?.transition?.reload===!0}function s(e){let t=null,n=()=>{let e=t;t=null,e?.()},i=new r({route:e.getState(),previousRoute:void 0},{onFirstSubscribe:()=>{let n=i.getSnapshot(),r=a(n.route,e.getState());r!==n.route&&i.updateSnapshot({route:r,previousRoute:void 0}),t=e.subscribe(e=>{let t=i.getSnapshot(),n=a(t.route,e.route),r=a(t.previousRoute,e.previousRoute);(n!==t.route||r!==t.previousRoute)&&i.updateSnapshot({route:n,previousRoute:r})})},onLastUnsubscribe:n,onDestroy:n});return i}function c(e,t,n,r){let i=r?.route??t.getState(),o=r?.previousRoute,s=n===``||i!==void 0&&(i.name===n||i.name.startsWith(`${n}.`))?i:void 0;if(s===e.route&&o===e.previousRoute)return e;let c=a(e.route,s),l=a(e.previousRoute,o);return c===e.route&&l===e.previousRoute?e:{route:c,previousRoute:l}}function l(){}const u=new WeakMap;function d(e,t){let n=u.get(e);n||(n=new Map,u.set(e,n));let r=n.get(t);if(!r){let i=f(e,t);r={subscribe:i.subscribe,getSnapshot:i.getSnapshot,destroy:l},n.set(t,r)}return r}function f(e,t){let n=null,i=e.shouldUpdateNode(t),a=new r(c({route:void 0,previousRoute:void 0},e,t),{onFirstSubscribe:()=>{let r=c(a.getSnapshot(),e,t);Object.is(r,a.getSnapshot())||a.updateSnapshot(r),n=e.subscribe(n=>{if(!i(n.route,n.previousRoute))return;let r=c(a.getSnapshot(),e,t,n);Object.is(a.getSnapshot(),r)||a.updateSnapshot(r)})},onLastUnsubscribe:()=>{let e=n;n=null,e?.()}});return a}const p=Object.keys,m=Object.create;function
|
|
1
|
+
import{areRoutesRelated as e}from"@real-router/route-utils";import{events as t}from"@real-router/core";import{getPluginApi as n}from"@real-router/core/api";var r=class{#e;#t=!1;#n=new Set;#r;#i;#a;constructor(e,t){this.#e=e,this.#r=t?.onFirstSubscribe,this.#i=t?.onLastUnsubscribe,this.#a=t?.onDestroy,this.subscribe=this.subscribe.bind(this),this.getSnapshot=this.getSnapshot.bind(this),this.destroy=this.destroy.bind(this)}subscribe(e){if(this.#t)return()=>{};let t=this.#n.size===0;return this.#n.add(e),t&&this.#r&&this.#r(),()=>{this.#n.delete(e),!this.#t&&this.#n.size===0&&this.#i&&this.#i()}}getSnapshot(){return this.#e}updateSnapshot(e){if(!this.#t){this.#e=e;for(let e of this.#n)try{e()}catch(e){queueMicrotask(()=>{throw e})}}}destroy(){this.#t||(this.#t=!0,this.#a?.(),this.#n.clear())}};function i(e){return(e?.context)?.url?.hash}function a(e,t){return e===t?e:e?.path!==t?.path||i(e)!==i(t)||o(t)?t:e}function o(e){return e?.transition?.reload===!0}function s(e){let t=null,n=()=>{let e=t;t=null,e?.()},i=new r({route:e.getState(),previousRoute:void 0},{onFirstSubscribe:()=>{let n=i.getSnapshot(),r=a(n.route,e.getState());r!==n.route&&i.updateSnapshot({route:r,previousRoute:void 0}),t=e.subscribe(e=>{let t=i.getSnapshot(),n=a(t.route,e.route),r=a(t.previousRoute,e.previousRoute);(n!==t.route||r!==t.previousRoute)&&i.updateSnapshot({route:n,previousRoute:r})})},onLastUnsubscribe:n,onDestroy:n});return i}function c(e,t,n,r){let i=r?.route??t.getState(),o=r?.previousRoute,s=n===``||i!==void 0&&(i.name===n||i.name.startsWith(`${n}.`))?i:void 0;if(s===e.route&&o===e.previousRoute)return e;let c=a(e.route,s),l=a(e.previousRoute,o);return c===e.route&&l===e.previousRoute?e:{route:c,previousRoute:l}}function l(){}const u=new WeakMap;function d(e,t){let n=u.get(e);n||(n=new Map,u.set(e,n));let r=n.get(t);if(!r){let i=f(e,t);r={subscribe:i.subscribe,getSnapshot:i.getSnapshot,destroy:l},n.set(t,r)}return r}function f(e,t){let n=null,i=e.shouldUpdateNode(t),a=new r(c({route:void 0,previousRoute:void 0},e,t),{onFirstSubscribe:()=>{let r=c(a.getSnapshot(),e,t);Object.is(r,a.getSnapshot())||a.updateSnapshot(r),n=e.subscribe(n=>{if(!i(n.route,n.previousRoute))return;let r=c(a.getSnapshot(),e,t,n);Object.is(a.getSnapshot(),r)||a.updateSnapshot(r)})},onLastUnsubscribe:()=>{let e=n;n=null,e?.()}});return a}const p=Object.keys,m=Object.getPrototypeOf,h=Date.prototype.getTime,g=Object.create;function _(e){return JSON.stringify(w(e,new Set,`root`))}function v(e){if(Array.isArray(e))return!0;let t=m(e);return t===null||t===Object.prototype}function y(e,t){return e<t?-1:1}function b(e){return TypeError(`canonicalJson: cannot serialize ${e} — JSON drops it or spells it null, so two values core tells apart would share one cache key.`)}function x(e){let t=g(null);return t[`\0Date`]=h.call(e),t}function S(e){if(typeof e==`function`||typeof e==`symbol`)throw b(`a ${typeof e}`);if(typeof e==`number`&&!Number.isFinite(e))throw b(String(e));return e}function C(e){let t=e.constructor?.name;return TypeError(`canonicalJson: cannot serialize ${typeof t==`string`&&t!==``?t:`an object`} — a cache-key is built only from plain objects, arrays, Dates and JSON values: core compares any other object by its toString or by identity, not by its fields.`)}function w(e,t,n){if(typeof e!=`object`||!e)return S(e);if(e instanceof Date)return n===`field`?e:x(e);if(!v(e))throw C(e);if(t.has(e))throw TypeError(`canonicalJson: cannot serialize circular structure (cycle detected during traversal).`);t.add(e);try{return Array.isArray(e)?E(e,t,n===`field`?`field`:`value`):T(e,t,n)}finally{t.delete(e)}}function T(e,t,n){let r=g(null),i=n===`root`?p(e).toSorted(y):p(e),a=n===`root`?`value`:`field`;for(let n of i)r[n]=w(e[n],t,a);return r}function E(e,t,n){let{length:r}=e,i=[];for(let a=0;a<r;a++){let r=e[a];if(r===void 0&&n===`value`)throw b(`undefined in an array`);i[a]=w(r,t,n)}return i}const D=Object.freeze({strict:!1,ignoreQueryParams:!0,hash:void 0});function O(e){return{strict:e?.strict??D.strict,ignoreQueryParams:e?.ignoreQueryParams??D.ignoreQueryParams,hash:e?.hash}}const k=new WeakMap;function A(e,t,n,r,i){let{strict:a,ignoreQueryParams:o,hash:s}=O(i),c;if(typeof t!=`string`)return M(e,t,n,r,a,o,s);try{let e=s===void 0?``:`#${s}`;c=`${t}|${n===void 0?``:_(n)}|${r===void 0?``:_(r)}|${String(a)}|${String(o)}|${e}`}catch{c=void 0}if(c===void 0)return M(e,t,n,r,a,o,s);let u=k.get(e);u||(u=new Map,k.set(e,u));let d=u.get(c);if(!d){let i=M(e,t,n,r,a,o,s);d={subscribe:i.subscribe,getSnapshot:i.getSnapshot,destroy:l},u.set(c,d)}return d}function j(e,t,n,r,a,o,s){return e.isActiveRoute(t,n,r,a,o)?s===void 0||(i(e.getState())??``)===s:!1}function M(t,n,i,a,o,s,c){let l=j(t,n,i,a,o,s,c),u,d=()=>{let e=u;u=void 0,e?.()},f=new r(l,{onFirstSubscribe:()=>{let r=j(t,n,i,a,o,s,c);Object.is(f.getSnapshot(),r)||f.updateSnapshot(r),u=t.subscribe(r=>{let l=e(n,r.route.name),u=r.previousRoute&&e(n,r.previousRoute.name),d=c!==void 0&&(r.route.context?.url?.hashChanged??!1);if(!l&&!u&&!d)return;let p=l&&j(t,n,i,a,o,s,c);Object.is(f.getSnapshot(),p)||f.updateSnapshot(p)})},onLastUnsubscribe:d,onDestroy:d});return f}const N=new WeakMap;function P(t){let n=N.get(t);if(n)return n;let r=new Map,i=new Map,a=null,o=e=>{let n=t.getState();return n?e===``||n.name===e||n.name.startsWith(`${e}.`):!1},s=(t,n,r,a)=>{if(t!==``){let n=e(t,r),i=a!==void 0&&e(t,a);if(!n&&!i)return}let s=i.get(t)===!0,c=o(t);if(s!==c){i.set(t,c);for(let e of n)try{e()}catch(e){queueMicrotask(()=>{throw e})}}},c=()=>{a=t.subscribe(e=>{let t=e.route.name,n=e.previousRoute?.name;for(let[e,i]of r)try{s(e,i,t,n)}catch(e){queueMicrotask(()=>{throw e})}})},u=()=>{let e=a;a=null,e?.()},d={subscribe:(e,t)=>{let n=r.get(e);n||(n=new Set,r.set(e,n),i.set(e,o(e))),n.add(t),a||c();let s=!1;return()=>{s||(s=!0,r.get(e)===n&&(n.delete(t),n.size===0&&(r.delete(e),i.delete(e)),r.size===0&&u()))}},isActive:e=>{let t=i.get(e);return t===void 0?o(e):t},destroy:l};return N.set(t,d),d}const F=()=>{};function I(e,t,n,r,i,a,o){if(t!==``&&n===void 0&&r===void 0&&!i&&a&&o===void 0){let n=P(e);return{subscribe:e=>n.subscribe(t,e),getSnapshot:()=>n.isActive(t),destroy:F}}return A(e,t,n,r,o===void 0?{strict:i,ignoreQueryParams:a}:{strict:i,ignoreQueryParams:a,hash:o})}const L=Object.freeze({isTransitioning:!1,isLeaveApproved:!1,toRoute:null,fromRoute:null}),R=new WeakMap;function z(e,t,n){let r=a(e.toRoute,t),i=a(e.fromRoute,n??null);return e.isTransitioning&&r===e.toRoute&&i===e.fromRoute?null:{isTransitioning:!0,isLeaveApproved:!1,toRoute:r,fromRoute:i}}function B(e,t,n){let r=a(e.toRoute,t),i=a(e.fromRoute,n??null);return e.isLeaveApproved&&r===e.toRoute&&i===e.fromRoute?null:{isTransitioning:!0,isLeaveApproved:!0,toRoute:r,fromRoute:i}}function V(e){let i=[],a=new r(L,{onDestroy:()=>{for(let e of i)e()}}),o=n(e),s,c=()=>{a.updateSnapshot(L)},l=e=>{e?.context===s?.context&&c()},u=(e,t)=>{s=e;let n=z(a.getSnapshot(),e,t);n!==null&&a.updateSnapshot(n)},d=(e,t)=>{s=e;let n=B(a.getSnapshot(),e,t);n!==null&&a.updateSnapshot(n)};try{i.push(o.addEventListener(t.TRANSITION_START,u)),i.push(o.addEventListener(t.TRANSITION_LEAVE_APPROVE,d)),i.push(o.addEventListener(t.TRANSITION_SUCCESS,c)),i.push(o.addEventListener(t.TRANSITION_ERROR,l)),i.push(o.addEventListener(t.TRANSITION_CANCEL,c))}catch(e){for(let e of i)e();throw e}return a}function H(e){let t=R.get(e);if(!t){let n=V(e);t={subscribe:n.subscribe,getSnapshot:n.getSnapshot,destroy:l},R.set(e,t)}return t}const U=Object.freeze({error:null,toRoute:null,fromRoute:null,version:0}),W=new WeakMap;function G(e){let i=0,a=!1,o=[],s=new r(U,{onDestroy:()=>{for(let e of o)e()}}),c=n(e);try{o.push(c.addEventListener(t.TRANSITION_ERROR,(e,t,n)=>{i++,a=!0,s.updateSnapshot({error:n,toRoute:e??null,fromRoute:t??null,version:i})})),o.push(c.addEventListener(t.TRANSITION_SUCCESS,()=>{a&&(a=!1,s.updateSnapshot({error:null,toRoute:null,fromRoute:null,version:i}))}))}catch(e){for(let e of o)e();throw e}return s}function K(e){let t=W.get(e);if(!t){let n=G(e);t={subscribe:n.subscribe,getSnapshot:n.getSnapshot,destroy:l},W.set(e,t)}return t}function q(e){try{K(e)}catch{}}const J=new WeakMap;function Y(e){let t=J.get(e);if(t)return t;let n=K(e),i=-1,a=null,o=()=>{let e=n.getSnapshot(),t=e.version<=i;return{error:t?null:e.error,toRoute:t?null:e.toRoute,fromRoute:t?null:e.fromRoute,version:e.version,resetError:c}},s=new r(o(),{onFirstSubscribe:()=>{a=n.subscribe(()=>{s.updateSnapshot(o())});let e=o();e.error!==s.getSnapshot().error&&s.updateSnapshot(e)},onLastUnsubscribe:()=>{u()}});function c(){let e=n.getSnapshot().version;e<=i||(i=e,s.updateSnapshot(o()))}function u(){let e=a;a=null,e?.()}let d={subscribe:s.subscribe,getSnapshot:s.getSnapshot,destroy:l};return J.set(e,d),d}function X(){let e=null;return(t,n,r)=>!t||!t.transition?.from||r&&t.transition.from===t.name||e===t||!n?null:(e=t,{route:t,previousRoute:n})}function Z(e,t){let n=t?.skipSameRoute??!0;return({route:t,nextRoute:r,signal:i})=>{if(!(n&&t.name===r.name)&&!i.aborted)return e({route:t,nextRoute:r,signal:i})}}export{D as DEFAULT_ACTIVE_OPTIONS,_ as canonicalJson,P as createActiveNameSelector,A as createActiveRouteSource,I as createActiveSource,Y as createDismissableError,G as createErrorSource,X as createRouteEnterGate,d as createRouteNodeSource,s as createRouteSource,V as createTransitionSource,K as getErrorSource,H as getTransitionSource,Z as guardLeaveListener,O as normalizeActiveOptions,q as primeErrorSource};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|