@ecopages/browser-router 0.2.0-beta.37 → 0.2.0-beta.39
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
CHANGED
|
@@ -53,6 +53,8 @@ const router = createRouter({
|
|
|
53
53
|
});
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
+
By default, when view transitions are enabled, the router opts the document out of the UA root group (no lighter flash on dark themes) and only calls `startViewTransition` when a page uses `data-view-transition` shared-element morphs. Set `viewTransitions: false` to disable.
|
|
57
|
+
|
|
56
58
|
By default, browser-router only syncs root `<html>` metadata it owns. Client-managed attributes and classes such as theme state are preserved unless you explicitly include them in `documentElementAttributesToSync`.
|
|
57
59
|
|
|
58
60
|
For advanced cases, browser-router also exports low-level document sync tooling without changing the router instance API:
|
|
@@ -92,7 +94,7 @@ Call `router.stop()` before replacing the router script in long-lived sessions (
|
|
|
92
94
|
| `reloadAttribute` | `string` | `'data-eco-reload'` | Attribute to force full page reload |
|
|
93
95
|
| `updateHistory` | `boolean` | `true` | Whether to update browser history |
|
|
94
96
|
| `scrollBehavior` | `'top' \| 'preserve' \| 'auto'` | `'top'` | Scroll behavior after navigation |
|
|
95
|
-
| `viewTransitions` | `boolean` | `
|
|
97
|
+
| `viewTransitions` | `boolean` | `true` | View Transition API; disables UA root crossfade by default. `false` disables. |
|
|
96
98
|
| `smoothScroll` | `boolean` | `false` | Use smooth scrolling during navigation |
|
|
97
99
|
|
|
98
100
|
## Persistence
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecopages/browser-router",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.39",
|
|
4
4
|
"description": "Client-side router for Ecopages with view transitions support",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ecopages",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"morphdom": "^2.7.8"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@ecopages/core": "0.2.0-beta.
|
|
38
|
+
"@ecopages/core": "0.2.0-beta.39"
|
|
39
39
|
},
|
|
40
40
|
"types": "./src/index.d.ts"
|
|
41
41
|
}
|
|
@@ -82,7 +82,7 @@ export class NavigationCommit {
|
|
|
82
82
|
});
|
|
83
83
|
};
|
|
84
84
|
if (useViewTransitions) {
|
|
85
|
-
await this.viewTransitionManager.transition(commitSwap);
|
|
85
|
+
await this.viewTransitionManager.transition(commitSwap, { incomingDocument: newDocument });
|
|
86
86
|
}
|
|
87
87
|
else {
|
|
88
88
|
commitSwap();
|
|
@@ -2,13 +2,17 @@
|
|
|
2
2
|
* Manages View Transition API integration
|
|
3
3
|
* @module
|
|
4
4
|
*/
|
|
5
|
+
export type ViewTransitionNavigationOptions = {
|
|
6
|
+
/** Incoming document for the navigation (used to detect named transitions on the next page). */
|
|
7
|
+
incomingDocument?: Document;
|
|
8
|
+
};
|
|
5
9
|
/**
|
|
6
10
|
* Service for handling View Transition API during page transitions.
|
|
7
11
|
* Falls back to direct execution if the API is not supported.
|
|
8
12
|
*/
|
|
9
13
|
export declare class ViewTransitionManager {
|
|
10
14
|
private enabled;
|
|
11
|
-
constructor(enabled
|
|
15
|
+
constructor(enabled?: boolean);
|
|
12
16
|
/**
|
|
13
17
|
* Check if the View Transition API is supported
|
|
14
18
|
*/
|
|
@@ -25,5 +29,5 @@ export declare class ViewTransitionManager {
|
|
|
25
29
|
* @param callback - The DOM update callback to execute
|
|
26
30
|
* @returns Promise that resolves when the DOM update has committed
|
|
27
31
|
*/
|
|
28
|
-
transition(callback: () => void | Promise<void
|
|
32
|
+
transition(callback: () => void | Promise<void>, options?: ViewTransitionNavigationOptions): Promise<void>;
|
|
29
33
|
}
|
|
@@ -2,15 +2,18 @@
|
|
|
2
2
|
* Manages View Transition API integration
|
|
3
3
|
* @module
|
|
4
4
|
*/
|
|
5
|
-
import { applyViewTransitionNames, clearViewTransitionNames } from '@ecopages/core/client/view-transitions';
|
|
5
|
+
import { applyViewTransitionNames, clearViewTransitionNames, ensureRootViewTransitionStyles, navigationHasNamedViewTransitions, } from '@ecopages/core/client/view-transitions';
|
|
6
6
|
/**
|
|
7
7
|
* Service for handling View Transition API during page transitions.
|
|
8
8
|
* Falls back to direct execution if the API is not supported.
|
|
9
9
|
*/
|
|
10
10
|
export class ViewTransitionManager {
|
|
11
11
|
enabled;
|
|
12
|
-
constructor(enabled) {
|
|
12
|
+
constructor(enabled = true) {
|
|
13
13
|
this.enabled = enabled;
|
|
14
|
+
if (this.enabled) {
|
|
15
|
+
ensureRootViewTransitionStyles();
|
|
16
|
+
}
|
|
14
17
|
}
|
|
15
18
|
/**
|
|
16
19
|
* Check if the View Transition API is supported
|
|
@@ -30,8 +33,10 @@ export class ViewTransitionManager {
|
|
|
30
33
|
* @param callback - The DOM update callback to execute
|
|
31
34
|
* @returns Promise that resolves when the DOM update has committed
|
|
32
35
|
*/
|
|
33
|
-
async transition(callback) {
|
|
34
|
-
|
|
36
|
+
async transition(callback, options = {}) {
|
|
37
|
+
const incoming = options.incomingDocument;
|
|
38
|
+
const useNamedTransition = this.enabled && this.isSupported() && navigationHasNamedViewTransitions(document, incoming ?? document);
|
|
39
|
+
if (!useNamedTransition) {
|
|
35
40
|
await callback();
|
|
36
41
|
return;
|
|
37
42
|
}
|
package/src/client/types.d.ts
CHANGED
|
@@ -59,6 +59,12 @@ export interface EcoRouterOptions {
|
|
|
59
59
|
/**
|
|
60
60
|
* Whether to use the View Transition API for animations.
|
|
61
61
|
* Falls back to instant swap if not supported.
|
|
62
|
+
*
|
|
63
|
+
* @remarks
|
|
64
|
+
* When enabled, injects `html { view-transition-name: none }` so the UA root
|
|
65
|
+
* group does not flash lighter on dark UIs. `startViewTransition` runs only when
|
|
66
|
+
* the current or incoming page has `data-view-transition` elements. Use
|
|
67
|
+
* `viewTransitions: false` to disable entirely.
|
|
62
68
|
* @default true
|
|
63
69
|
*/
|
|
64
70
|
viewTransitions?: boolean;
|
package/src/styles.css
CHANGED
|
@@ -6,14 +6,10 @@
|
|
|
6
6
|
*
|
|
7
7
|
* Use the ecopages npm package instead:
|
|
8
8
|
* @import 'ecopages/css/view-transitions.css';
|
|
9
|
+
*
|
|
10
|
+
* Root opt-out is injected by the router when view transitions are enabled.
|
|
9
11
|
*/
|
|
10
12
|
|
|
11
|
-
/* Disable root animation to prevent full page flash during transitions */
|
|
12
|
-
::view-transition-old(root),
|
|
13
|
-
::view-transition-new(root) {
|
|
14
|
-
animation: none;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
13
|
/* Shared element transitions animate position/size smoothly */
|
|
18
14
|
::view-transition-group(*) {
|
|
19
15
|
animation-duration: 180ms;
|