Skip to content

Commit

Permalink
Adds Safari support
Browse files Browse the repository at this point in the history
  • Loading branch information
martrapp committed Jan 1, 2025
1 parent 6c139ce commit 065f143
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
9 changes: 9 additions & 0 deletions .changeset/cold-boxes-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@vtbag/element-crossing': minor
---

Adds support for Safari.

Starting with version 18.2, Safari introduced support for cross-document view transitions but still lacks support for the Navigation API.

As of version 1.1.0, Element-Crossing now handles Safari as well, again enabling the transfer of selected element states across cross-document view transitions in all browsers that support this feature.
24 changes: 10 additions & 14 deletions src/vanilla.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,8 @@ function pageReveal() {
}
top!.sessionStorage.removeItem('@vtbag/element-crossing');
self.crossingStorage?.removeItem('@vtbag/element-crossing');
if (
performance?.navigation?.type !== 1 &&
'navigation' in self &&
// @ts-expect-error
self.navigation?.navigationType !== 'reload'
) {
if ("navigation" in self && self.navigation?.activation?.navigationType !== 'reload'
|| performance?.navigation?.type !== 1) {
restore(values);
}
}
Expand Down Expand Up @@ -201,12 +197,12 @@ function restore(values: ElementSpec[]) {
values.forEach((elementSpec: ElementSpec) => {
let element = document.querySelector<HTMLElement>(
'#' +
elementSpec.id +
",[data-vtbag-x*='#" +
elementSpec.id +
"'],[data-vtbag-x*='id:" +
elementSpec.id +
"']"
elementSpec.id +
",[data-vtbag-x*='#" +
elementSpec.id +
"'],[data-vtbag-x*='id:" +
elementSpec.id +
"']"
);
if (element) {
elementSpec.specs.forEach((s) => {
Expand Down Expand Up @@ -266,8 +262,8 @@ function restore(values: ElementSpec[]) {
}
animations.forEach(
(a) =>
(a.currentTime =
~~(s.value ?? '0') + (new Date().getTime() - elementSpec.timestamp))
(a.currentTime =
~~(s.value ?? '0') + (new Date().getTime() - elementSpec.timestamp))
);
}
break;
Expand Down

0 comments on commit 065f143

Please sign in to comment.