@ecopages/browser-router 0.2.0-beta.4 → 0.2.0-beta.41
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 +12 -4
- package/package.json +7 -7
- package/src/client/document-element-sync.d.ts +0 -7
- package/src/client/document-element-sync.js +28 -18
- package/src/client/dom/body-morpher.d.ts +24 -0
- package/src/client/dom/body-morpher.js +143 -0
- package/src/client/dom/dom-swapper.d.ts +30 -0
- package/src/client/dom/dom-swapper.js +52 -0
- package/src/client/dom/head-updater.d.ts +42 -0
- package/src/client/dom/head-updater.js +194 -0
- package/src/client/dom/html-parser.d.ts +4 -0
- package/src/client/dom/html-parser.js +8 -0
- package/src/client/dom/stylesheet-discovery.d.ts +12 -0
- package/src/client/dom/stylesheet-discovery.js +24 -0
- package/src/client/dom/stylesheet-preloader.d.ts +10 -0
- package/src/client/dom/stylesheet-preloader.js +44 -0
- package/src/client/eco-router.d.ts +2 -31
- package/src/client/eco-router.js +337 -439
- package/src/client/index.d.ts +3 -0
- package/src/client/index.js +3 -0
- package/src/client/navigation-commit.d.ts +22 -0
- package/src/client/navigation-commit.js +104 -0
- package/src/client/navigation-fetch.d.ts +8 -0
- package/src/client/navigation-fetch.js +24 -0
- package/src/client/services/prefetch-manager.d.ts +2 -14
- package/src/client/services/prefetch-manager.js +378 -370
- package/src/client/services/view-transition-manager.d.ts +6 -2
- package/src/client/services/view-transition-manager.js +76 -52
- package/src/client/types.d.ts +6 -13
- package/src/client/types.js +19 -20
- package/src/index.d.ts +3 -5
- package/src/index.js +8 -18
- package/src/styles.css +2 -6
- package/src/client/services/dom-swapper.d.ts +0 -168
- package/src/client/services/dom-swapper.js +0 -529
- package/src/client/services/index.d.ts +0 -8
- package/src/client/services/index.js +0 -10
- package/src/client/services/scroll-manager.d.ts +0 -19
- package/src/client/services/scroll-manager.js +0 -36
- package/src/client/view-transition-utils.d.ts +0 -14
- package/src/client/view-transition-utils.js +0 -60
- package/src/types.d.ts +0 -15
- package/src/types.js +0 -5
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared stylesheet href discovery for navigation prefetch and commit.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Returns resolved stylesheet hrefs currently in the document head.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getCurrentStylesheetHrefs(): Set<string>;
|
|
9
|
+
/**
|
|
10
|
+
* Returns stylesheet links present in `source` but not in `existingHrefs`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function discoverNewStylesheetLinks(source: Document, existingHrefs?: Set<string>): HTMLLinkElement[];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared stylesheet href discovery for navigation prefetch and commit.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Returns resolved stylesheet hrefs currently in the document head.
|
|
7
|
+
*/
|
|
8
|
+
export function getCurrentStylesheetHrefs() {
|
|
9
|
+
return new Set(Array.from(document.head.querySelectorAll('link[rel="stylesheet"]')).map((link) => link.href));
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Returns stylesheet links present in `source` but not in `existingHrefs`.
|
|
13
|
+
*/
|
|
14
|
+
export function discoverNewStylesheetLinks(source, existingHrefs = getCurrentStylesheetHrefs()) {
|
|
15
|
+
const discovered = [];
|
|
16
|
+
for (const link of source.head.querySelectorAll('link[rel="stylesheet"]')) {
|
|
17
|
+
if (existingHrefs.has(link.href)) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
existingHrefs.add(link.href);
|
|
21
|
+
discovered.push(link);
|
|
22
|
+
}
|
|
23
|
+
return discovered;
|
|
24
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Preloads new stylesheets from target document to prevent FOUC.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Discovers stylesheet links in the target document that aren't present in the
|
|
6
|
+
* current document, creates corresponding link elements, and waits for all to
|
|
7
|
+
* load before resolving. This follows Turbo's approach of waiting for stylesheets
|
|
8
|
+
* before any DOM updates.
|
|
9
|
+
*/
|
|
10
|
+
export declare function preloadStylesheets(newDocument: Document): Promise<void>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { discoverNewStylesheetLinks, getCurrentStylesheetHrefs } from './stylesheet-discovery.js';
|
|
2
|
+
/**
|
|
3
|
+
* Preloads new stylesheets from target document to prevent FOUC.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Discovers stylesheet links in the target document that aren't present in the
|
|
7
|
+
* current document, creates corresponding link elements, and waits for all to
|
|
8
|
+
* load before resolving. This follows Turbo's approach of waiting for stylesheets
|
|
9
|
+
* before any DOM updates.
|
|
10
|
+
*/
|
|
11
|
+
export async function preloadStylesheets(newDocument) {
|
|
12
|
+
const newStylesheetLinks = discoverNewStylesheetLinks(newDocument, getCurrentStylesheetHrefs());
|
|
13
|
+
if (newStylesheetLinks.length === 0) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const TIMEOUT = 5000;
|
|
17
|
+
const loadPromises = newStylesheetLinks.map((link) => {
|
|
18
|
+
return new Promise((resolve) => {
|
|
19
|
+
const newLink = document.createElement('link');
|
|
20
|
+
newLink.rel = 'stylesheet';
|
|
21
|
+
newLink.media = link.media || 'all';
|
|
22
|
+
const timeoutId = setTimeout(() => {
|
|
23
|
+
cleanup();
|
|
24
|
+
resolve();
|
|
25
|
+
}, TIMEOUT);
|
|
26
|
+
const cleanup = () => {
|
|
27
|
+
clearTimeout(timeoutId);
|
|
28
|
+
newLink.onload = null;
|
|
29
|
+
newLink.onerror = null;
|
|
30
|
+
};
|
|
31
|
+
newLink.onload = () => {
|
|
32
|
+
cleanup();
|
|
33
|
+
resolve();
|
|
34
|
+
};
|
|
35
|
+
newLink.onerror = () => {
|
|
36
|
+
cleanup();
|
|
37
|
+
resolve();
|
|
38
|
+
};
|
|
39
|
+
newLink.href = link.href;
|
|
40
|
+
document.head.appendChild(newLink);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
await Promise.all(loadPromises);
|
|
44
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Client-side router for Ecopages with morphdom-based DOM diffing.
|
|
3
3
|
* @module eco-router
|
|
4
4
|
*/
|
|
5
|
-
import type
|
|
5
|
+
import { type EcoRouterOptions } from './types.js';
|
|
6
6
|
/**
|
|
7
7
|
* Intercepts same-origin link clicks and performs client-side navigation
|
|
8
8
|
* using morphdom for efficient DOM diffing. Supports View Transitions API.
|
|
@@ -15,28 +15,12 @@ export declare class EcoRouter {
|
|
|
15
15
|
private pendingPointerNavigation;
|
|
16
16
|
private queuedNavigationHref;
|
|
17
17
|
private domSwapper;
|
|
18
|
-
private scrollManager;
|
|
19
18
|
private viewTransitionManager;
|
|
20
19
|
private prefetchManager;
|
|
20
|
+
private readonly navigationCommit;
|
|
21
21
|
constructor(options?: EcoRouterOptions);
|
|
22
|
-
private getLinkFromEvent;
|
|
23
|
-
private canInterceptLink;
|
|
24
22
|
private getRecoveredPointerHref;
|
|
25
23
|
private isAnotherNavigationRuntimeActive;
|
|
26
|
-
private getDocumentOwner;
|
|
27
|
-
private adoptDocumentOwner;
|
|
28
|
-
private syncDocumentElementAttributes;
|
|
29
|
-
private reloadDocument;
|
|
30
|
-
/**
|
|
31
|
-
* Commits a fully fetched document into the live page.
|
|
32
|
-
*
|
|
33
|
-
* When browser-router accepts a handoff from another runtime, it delays source
|
|
34
|
-
* runtime cleanup until the incoming document has been prepared and is ready to
|
|
35
|
-
* commit. That ordering avoids the blank-page window we previously hit when a
|
|
36
|
-
* delegated navigation went stale after the source runtime had already torn
|
|
37
|
-
* itself down.
|
|
38
|
-
*/
|
|
39
|
-
private commitDocumentNavigation;
|
|
40
24
|
/**
|
|
41
25
|
* Starts the router and begins intercepting navigation.
|
|
42
26
|
*
|
|
@@ -80,11 +64,6 @@ export declare class EcoRouter {
|
|
|
80
64
|
* Triggered by the History API's popstate event.
|
|
81
65
|
*/
|
|
82
66
|
private handlePopState;
|
|
83
|
-
/**
|
|
84
|
-
* Checks if a URL shares the same origin as the current page.
|
|
85
|
-
* Cross-origin navigation always falls back to full page reload.
|
|
86
|
-
*/
|
|
87
|
-
private isSameOrigin;
|
|
88
67
|
private cancelNavigationTransaction;
|
|
89
68
|
private beginNavigationTransaction;
|
|
90
69
|
/**
|
|
@@ -106,13 +85,6 @@ export declare class EcoRouter {
|
|
|
106
85
|
* @param direction - Navigation direction ('forward', 'back', or 'replace')
|
|
107
86
|
*/
|
|
108
87
|
private performNavigation;
|
|
109
|
-
/**
|
|
110
|
-
* Fetches the HTML content of a page.
|
|
111
|
-
* @param url - The URL to fetch
|
|
112
|
-
* @param signal - AbortSignal for cancelling the request
|
|
113
|
-
* @throws Error if the response is not ok
|
|
114
|
-
*/
|
|
115
|
-
private fetchPage;
|
|
116
88
|
}
|
|
117
89
|
/**
|
|
118
90
|
* Creates and starts a router instance.
|
|
@@ -126,4 +98,3 @@ export declare class EcoRouter {
|
|
|
126
98
|
* @returns A started EcoRouter instance
|
|
127
99
|
*/
|
|
128
100
|
export declare function createRouter(options?: EcoRouterOptions): EcoRouter;
|
|
129
|
-
export type { EcoRouterOptions, EcoNavigationEvent, EcoBeforeSwapEvent, EcoAfterSwapEvent } from './types';
|