Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | 47x 47x 47x 47x 47x 47x 47x 47x 47x 47x 47x 47x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 47x 47x 47x 64x 64x 47x 47x 47x 41x 41x 1x 1x 1x 1x 41x 40x 40x 40x 40x 41x 41x 40x 40x 41x 47x 47x 47x 5x 5x 47x 47x 47x 4x 4x 47x 47x 47x 18x 2x 2x 16x 18x 4x 4x 12x 12x 12x 12x 12x 18x 47x 47x 47x 18x 18x 18x 47x 47x 47x 16x 16x 16x 47x 47x 47x 3x 3x 47x 47x 47x 16x 16x 47x 47x 47x 1x 1x 47x 47x 47x 49x 49x 47x 47x 47x 5x 5x 5x 5x 47x | import { NavigationDelegate } from './NavigationDelegate.js';
/**
* In-memory navigation delegate for Node.js / SSR / headless environments.
* Manages route location state without DOM or window dependencies.
* @augments NavigationDelegate
*/
export class MemoryNavigationDelegate extends NavigationDelegate {
/**
* @param {string} [initialHash] - Initial location hash string.
*/
constructor(initialHash = '#/') {
super();
const initial = initialHash || '#/';
this.history = [initial];
this.cursorIndex = 0;
this.currentHash = initial;
this.title = '';
this.hashListeners = new Set();
this.linkClickListeners = new Set();
this.activeRouters = new Set();
}
/** @override */
getHash() {
return this.history[this.cursorIndex] || this.currentHash || '#/';
}
/** @override */
setHash(hash, options = {}) {
const targetHash = hash || '#/';
if (options.replace) {
if (this.history.length === 0) {
this.history.push(targetHash);
this.cursorIndex = 0;
} else {
this.history[this.cursorIndex] = targetHash;
}
} else {
this.history = this.history.slice(0, this.cursorIndex + 1);
this.history.push(targetHash);
this.cursorIndex = this.history.length - 1;
}
this.currentHash = this.history[this.cursorIndex];
for (const listener of this.hashListeners) {
listener(this.currentHash);
}
}
/** @override */
back() {
this.go(-1);
}
/** @override */
forward() {
this.go(1);
}
/** @override */
go(delta) {
if (typeof delta !== 'number' || isNaN(delta) || delta === 0) {
return;
}
const targetIndex = this.cursorIndex + delta;
if (targetIndex < 0 || targetIndex >= this.history.length) {
return;
}
this.cursorIndex = targetIndex;
this.currentHash = this.history[this.cursorIndex];
for (const listener of this.hashListeners) {
listener(this.currentHash);
}
}
/** @override */
onHashChange(callback) {
this.hashListeners.add(callback);
return () => this.hashListeners.delete(callback);
}
/** @override */
onLinkClick(callback) {
this.linkClickListeners.add(callback);
return () => this.linkClickListeners.delete(callback);
}
/** @override */
setTitle(title) {
this.title = title;
}
/** @override */
registerRouter(router) {
this.activeRouters.add(router);
}
/** @override */
unregisterRouter(router) {
this.activeRouters.delete(router);
}
/** @override */
getActiveRouters() {
return this.activeRouters;
}
/** @override */
destroy() {
this.hashListeners.clear();
this.linkClickListeners.clear();
this.activeRouters.clear();
}
}
|