@ecopages/browser-router 0.2.0-beta.31 → 0.2.0-beta.33
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 +1 -1
- package/package.json +2 -2
- package/src/client/document-element-sync.js +28 -15
- package/src/client/dom/body-morpher.js +123 -83
- package/src/client/dom/dom-swapper.js +51 -50
- package/src/client/dom/head-updater.js +177 -156
- package/src/client/dom/html-parser.js +7 -7
- package/src/client/dom/stylesheet-discovery.js +21 -17
- package/src/client/dom/stylesheet-preloader.js +42 -36
- package/src/client/eco-router.d.ts +1 -1
- package/src/client/eco-router.js +337 -329
- package/src/client/index.d.ts +1 -1
- package/src/client/index.js +3 -13
- package/src/client/navigation-commit.d.ts +2 -1
- package/src/client/navigation-commit.js +100 -110
- package/src/client/navigation-fetch.js +21 -21
- package/src/client/services/prefetch-manager.js +377 -351
- package/src/client/services/view-transition-manager.js +71 -52
- package/src/client/types.d.ts +0 -19
- package/src/client/types.js +19 -20
- package/src/index.d.ts +1 -1
- package/src/index.js +8 -18
|
@@ -1,54 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Manages View Transition API integration
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
import { applyViewTransitionNames, clearViewTransitionNames } from '@ecopages/core/client/view-transitions';
|
|
6
|
+
/**
|
|
7
|
+
* Service for handling View Transition API during page transitions.
|
|
8
|
+
* Falls back to direct execution if the API is not supported.
|
|
9
|
+
*/
|
|
10
|
+
export class ViewTransitionManager {
|
|
11
|
+
enabled;
|
|
12
|
+
constructor(enabled) {
|
|
13
|
+
this.enabled = enabled;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Check if the View Transition API is supported
|
|
17
|
+
*/
|
|
18
|
+
isSupported() {
|
|
19
|
+
return 'startViewTransition' in document;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Execute a callback with view transition if available and enabled.
|
|
23
|
+
* Falls back to direct execution if not supported.
|
|
24
|
+
*
|
|
25
|
+
* Navigation correctness depends on the DOM update callback completing, not on
|
|
26
|
+
* the browser finishing the visual transition animation. Awaiting
|
|
27
|
+
* `finished` here can leave router transactions artificially in-flight and
|
|
28
|
+
* block later navigations during rapid repeated clicks, so the router waits
|
|
29
|
+
* for `updateCallbackDone` and lets the animation finish in the background.
|
|
30
|
+
* @param callback - The DOM update callback to execute
|
|
31
|
+
* @returns Promise that resolves when the DOM update has committed
|
|
32
|
+
*/
|
|
33
|
+
async transition(callback) {
|
|
34
|
+
if (!this.enabled || !this.isSupported()) {
|
|
35
|
+
await callback();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Apply view transition names to current elements before starting the transition.
|
|
40
|
+
* This ensures the "old" state is captured correctly.
|
|
41
|
+
*/
|
|
42
|
+
applyViewTransitionNames();
|
|
43
|
+
const transition = document.startViewTransition(async () => {
|
|
44
|
+
await callback();
|
|
45
|
+
/**
|
|
46
|
+
* Apply names to the NEW elements after DOM swap and hydration.
|
|
47
|
+
* This ensures the "new" state is captured correctly.
|
|
48
|
+
*/
|
|
49
|
+
applyViewTransitionNames();
|
|
50
|
+
});
|
|
51
|
+
void transition.ready.catch((error) => {
|
|
52
|
+
if (error instanceof Error && error.name === 'AbortError') {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
console.error('[ecopages] View transition failed to start:', error);
|
|
56
|
+
});
|
|
57
|
+
void transition.finished
|
|
58
|
+
.catch((error) => {
|
|
59
|
+
if (error instanceof Error && error.name === 'AbortError') {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
console.error('[ecopages] View transition lifecycle failed:', error);
|
|
63
|
+
})
|
|
64
|
+
.finally(() => {
|
|
65
|
+
/**
|
|
66
|
+
* Cleanup view transition names and dynamic styles after the browser's
|
|
67
|
+
* animation lifecycle completes.
|
|
68
|
+
*/
|
|
69
|
+
clearViewTransitionNames();
|
|
70
|
+
});
|
|
71
|
+
await transition.updateCallbackDone;
|
|
29
72
|
}
|
|
30
|
-
applyViewTransitionNames();
|
|
31
|
-
const transition = document.startViewTransition(async () => {
|
|
32
|
-
await callback();
|
|
33
|
-
applyViewTransitionNames();
|
|
34
|
-
});
|
|
35
|
-
void transition.ready.catch((error) => {
|
|
36
|
-
if (error instanceof Error && error.name === "AbortError") {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
console.error("[ecopages] View transition failed to start:", error);
|
|
40
|
-
});
|
|
41
|
-
void transition.finished.catch((error) => {
|
|
42
|
-
if (error instanceof Error && error.name === "AbortError") {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
console.error("[ecopages] View transition lifecycle failed:", error);
|
|
46
|
-
}).finally(() => {
|
|
47
|
-
clearViewTransitionNames();
|
|
48
|
-
});
|
|
49
|
-
await transition.updateCallbackDone;
|
|
50
|
-
}
|
|
51
73
|
}
|
|
52
|
-
export {
|
|
53
|
-
ViewTransitionManager
|
|
54
|
-
};
|
package/src/client/types.d.ts
CHANGED
|
@@ -77,25 +77,6 @@ export interface EcoRouterOptions {
|
|
|
77
77
|
export type BrowserRouterNavigateOptions = {
|
|
78
78
|
direction?: 'forward' | 'back' | 'replace';
|
|
79
79
|
};
|
|
80
|
-
/** Events emitted during the navigation lifecycle */
|
|
81
|
-
export interface EcoNavigationEvent {
|
|
82
|
-
url: URL;
|
|
83
|
-
direction: 'forward' | 'back' | 'replace';
|
|
84
|
-
}
|
|
85
|
-
/** Event fired before the DOM swap occurs */
|
|
86
|
-
export interface EcoBeforeSwapEvent extends EcoNavigationEvent {
|
|
87
|
-
newDocument: Document;
|
|
88
|
-
reload: () => void;
|
|
89
|
-
}
|
|
90
|
-
/** Event fired after the DOM swap completes */
|
|
91
|
-
export interface EcoAfterSwapEvent extends EcoNavigationEvent {
|
|
92
|
-
}
|
|
93
|
-
/** Custom event map for navigation lifecycle */
|
|
94
|
-
export interface EcoRouterEventMap {
|
|
95
|
-
'eco:before-swap': CustomEvent<EcoBeforeSwapEvent>;
|
|
96
|
-
'eco:after-swap': CustomEvent<EcoAfterSwapEvent>;
|
|
97
|
-
'eco:page-load': CustomEvent<EcoNavigationEvent>;
|
|
98
|
-
}
|
|
99
80
|
/** Default document-level `<html>` attributes synchronized during navigation swaps. */
|
|
100
81
|
export declare const DEFAULT_DOCUMENT_ELEMENT_ATTRIBUTES_TO_SYNC: string[];
|
|
101
82
|
/** Default configuration options */
|
package/src/client/types.js
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
import { ECO_DOCUMENT_OWNER_ATTRIBUTE } from
|
|
1
|
+
import { ECO_DOCUMENT_OWNER_ATTRIBUTE } from '@ecopages/core/router/navigation-coordinator';
|
|
2
|
+
/** Default prefetch configuration */
|
|
2
3
|
const DEFAULT_PREFETCH_CONFIG = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
strategy: 'intent',
|
|
5
|
+
delay: 65,
|
|
6
|
+
noPrefetchAttribute: 'data-eco-no-prefetch',
|
|
7
|
+
respectDataSaver: true,
|
|
7
8
|
};
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
DEFAULT_DOCUMENT_ELEMENT_ATTRIBUTES_TO_SYNC,
|
|
22
|
-
DEFAULT_OPTIONS
|
|
9
|
+
/** Default document-level `<html>` attributes synchronized during navigation swaps. */
|
|
10
|
+
export const DEFAULT_DOCUMENT_ELEMENT_ATTRIBUTES_TO_SYNC = ['lang', 'dir', ECO_DOCUMENT_OWNER_ATTRIBUTE];
|
|
11
|
+
/** Default configuration options */
|
|
12
|
+
export const DEFAULT_OPTIONS = {
|
|
13
|
+
linkSelector: 'a[href]',
|
|
14
|
+
documentElementAttributesToSync: DEFAULT_DOCUMENT_ELEMENT_ATTRIBUTES_TO_SYNC,
|
|
15
|
+
persistAttribute: 'data-eco-persist',
|
|
16
|
+
reloadAttribute: 'data-eco-reload',
|
|
17
|
+
updateHistory: true,
|
|
18
|
+
scrollBehavior: 'top',
|
|
19
|
+
viewTransitions: true,
|
|
20
|
+
smoothScroll: false,
|
|
21
|
+
prefetch: DEFAULT_PREFETCH_CONFIG,
|
|
23
22
|
};
|
package/src/index.d.ts
CHANGED
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
* Client-side navigation and view transitions for Ecopages
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
export { createRouter, DEFAULT_DOCUMENT_ELEMENT_ATTRIBUTES_TO_SYNC, DEFAULT_OPTIONS, EcoRouter, syncDocumentElementAttributes, type BrowserRouterNavigateOptions, type
|
|
6
|
+
export { createRouter, DEFAULT_DOCUMENT_ELEMENT_ATTRIBUTES_TO_SYNC, DEFAULT_OPTIONS, EcoRouter, syncDocumentElementAttributes, type BrowserRouterNavigateOptions, type EcoRouterOptions, } from './client/index.js';
|
|
7
7
|
export { DomSwapper } from './client/dom/dom-swapper.js';
|
|
8
8
|
export { ViewTransitionManager } from './client/services/view-transition-manager.js';
|
package/src/index.js
CHANGED
|
@@ -1,18 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from
|
|
8
|
-
|
|
9
|
-
import { ViewTransitionManager } from "./client/services/view-transition-manager.js";
|
|
10
|
-
export {
|
|
11
|
-
DEFAULT_DOCUMENT_ELEMENT_ATTRIBUTES_TO_SYNC,
|
|
12
|
-
DEFAULT_OPTIONS,
|
|
13
|
-
DomSwapper,
|
|
14
|
-
EcoRouter,
|
|
15
|
-
ViewTransitionManager,
|
|
16
|
-
createRouter,
|
|
17
|
-
syncDocumentElementAttributes
|
|
18
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* @ecopages/browser-router
|
|
3
|
+
* Client-side navigation and view transitions for Ecopages
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
export { createRouter, DEFAULT_DOCUMENT_ELEMENT_ATTRIBUTES_TO_SYNC, DEFAULT_OPTIONS, EcoRouter, syncDocumentElementAttributes, } from './client/index.js';
|
|
7
|
+
export { DomSwapper } from './client/dom/dom-swapper.js';
|
|
8
|
+
export { ViewTransitionManager } from './client/services/view-transition-manager.js';
|