Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [v1.2.0] - 2026-04-30

### Added
- Implement basics of View Transitions

## [v1.1.15] - 2026-02-27

### Added
Expand Down
7 changes: 6 additions & 1 deletion http.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ import { useDefaultCSP, addScriptSrc, addStyleSrc, addConnectSrc, addImageSrc, a

addScriptSrc(
imports['@shgysk8zer0/polyfills'],
imports['@shgysk8zer0/signals/'],
'https://unpkg.com/@aegisjsproject/',
'https://unpkg.com/@lit/',
imports.marked,
imports['marked-highlight'],
imports['@highlightjs/cdn-assets/'],
);
addConnectSrc('https://api.github.com/users/', 'https://baconipsum.com/api/');
addStyleSrc(imports['@shgysk8zer0/core-css/'], imports['@highlightjs/cdn-assets/es/styles/']);
addStyleSrc(
imports['@shgysk8zer0/core-css/'],
imports['@aegisjsproject/styles/'] + 'css/',
imports['@highlightjs/cdn-assets/es/styles/'],
);
addImageSrc('https://avatars.githubusercontent.com/u/', 'https://images.unsplash.com/', 'blob:');
addTrustedTypePolicy('aegis-router#html', 'aegis-sanitizer#html', 'aegis-escape#html', 'lit-html', 'default');
lockCSP();
Expand Down
86 changes: 48 additions & 38 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aegisjsproject/router",
"version": "1.1.15",
"version": "1.2.0",
"description": "A simple but powerful router module",
"keywords": [
"router",
Expand Down Expand Up @@ -95,20 +95,20 @@
},
"homepage": "https://github.com/AegisJSProject/router#readme",
"dependencies": {
"@aegisjsproject/state": "^1.0.5"
"@aegisjsproject/state": "^1.0.7"
},
"devDependencies": {
"@aegisjsproject/component": "^0.1.6",
"@aegisjsproject/core": "^0.2.27",
"@aegisjsproject/dev-server": "^1.0.5",
"@aegisjsproject/component": "^0.1.8",
"@aegisjsproject/core": "^0.2.34",
"@aegisjsproject/dev-server": "^1.0.6",
"@aegisjsproject/http-utils": "^1.0.4",
"@aegisjsproject/url": "^1.0.3",
"@rollup/plugin-node-resolve": "^16.0.0",
"@rollup/plugin-node-resolve": "^16.0.3",
"@rollup/plugin-terser": "^1.0.0",
"@shgysk8zer0/eslint-config": "^1.0.4",
"@shgysk8zer0/http-server": "^1.1.1",
"@shgysk8zer0/importmap": "^1.7.8",
"eslint": "^10.0.0",
"rollup": "^4.38.0"
"@shgysk8zer0/eslint-config": "^1.0.9",
"@shgysk8zer0/http-server": "^1.1.2",
"@shgysk8zer0/importmap": "^1.9.12",
"eslint": "^10.2.1",
"rollup": "^4.60.2"
}
}
64 changes: 35 additions & 29 deletions router.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ let rootSelector = '#' + ROOT_ID;
const SUPPORTS_TRUSTED_TYPES = 'trustedTypes' in globalThis;
const _isTrustedHTML = input => SUPPORTS_TRUSTED_TYPES && trustedTypes.isHTML(input);

const startViewTransition = typeof document.startViewTransition === 'function'
? (update, types) => document.startViewTransition({ update, types })
: update => Promise.try(update);

function _handlePreloadMutations(target) {
if (target instanceof MutationRecord) {
_handlePreloadMutations(target.target);
Expand Down Expand Up @@ -440,38 +444,40 @@ async function _getHTML(url, { signal, method = 'GET', body, integrity, cache =
}
}

function _updatePage(content) {
async function _updatePage(content) {
const timestamp = performance.now();

if (content instanceof Document) {
if (content.head.childElementCount !== 0) {
setTitle(content.title);
setDescription(content.querySelector(DESC_SELECTOR)?.content);
}
await startViewTransition(() => {
if (content instanceof Document) {
if (content.head.childElementCount !== 0) {
setTitle(content.title);
setDescription(content.querySelector(DESC_SELECTOR)?.content);
}

const contentEl = typeof rootSelector === 'string' ? content.body.querySelector(rootSelector) ?? content.body : content.body;

rootEl.replaceChildren(...contentEl.childNodes);
} else if (content instanceof HTMLTemplateElement) {
rootEl.replaceChildren(content.content);
} else if (content instanceof Function && content.prototype instanceof HTMLElement) {
rootEl.replaceChildren(new content({ state: getStateObj(), url: new URL(location.href), timestamp }));
} else if (content instanceof Node) {
rootEl.replaceChildren(content);
} else if (content instanceof Function) {
_updatePage(content());
} else if (typeof content === 'string') {
rootEl.setHTMLUnsafe(policy.createHTML(content));
} else if (_isTrustedHTML(content)) {
rootEl.setHTMLUnsafe(content);
} else if (content instanceof Error) {
reportError(content);
rootEl.textContent = content.message;
} else if (content instanceof URL) {
navigate(content);
} else if (! (content === null || typeof content === 'undefined')) {
rootEl.textContent = content;
}
const contentEl = typeof rootSelector === 'string' ? content.body.querySelector(rootSelector) ?? content.body : content.body;

rootEl.replaceChildren(...contentEl.childNodes);
} else if (content instanceof HTMLTemplateElement) {
rootEl.replaceChildren(content.content);
} else if (content instanceof Function && content.prototype instanceof HTMLElement) {
rootEl.replaceChildren(new content({ state: getStateObj(), url: new URL(location.href), timestamp }));
} else if (content instanceof Node) {
rootEl.replaceChildren(content);
} else if (content instanceof Function) {
_updatePage(content());
} else if (typeof content === 'string') {
rootEl.setHTMLUnsafe(policy.createHTML(content));
} else if (_isTrustedHTML(content)) {
rootEl.setHTMLUnsafe(content);
} else if (content instanceof Error) {
reportError(content);
rootEl.textContent = content.message;
} else if (content instanceof URL) {
navigate(content);
} else if (! (content === null || typeof content === 'undefined')) {
rootEl.textContent = content;
}
});

const ev = new AegisNavigationEvent(NAV_EVENT, EVENT_TYPES.load, { cancelable: false });
Promise.try(() => EVENT_TARGET.dispatchEvent(ev)).finally(ev[Symbol.asyncDispose].bind(ev));
Expand Down
20 changes: 10 additions & 10 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ init('#routes', {
rootEl: '#root',
inteceptRoot: document.body,
observePreloads: true,
transition: {
keyframes: {
opacity: [1, 0],
transform: ['none', 'scale(0.8) translateX(-100%)']
},
options: {
easing: 'ease-in',
duration: 150,
}
},
// transition: {
// keyframes: {
// opacity: [1, 0],
// transform: ['none', 'scale(0.8) translateX(-100%)']
// },
// options: {
// easing: 'ease-in',
// duration: 150,
// }
// },
signal: controller.signal,
}).finally(() => console.timeEnd('init'));

Expand Down
Loading