From 065f143d5bd47260279a558bc096be3f7d16c5b5 Mon Sep 17 00:00:00 2001 From: Martin Trapp <94928215+martrapp@users.noreply.github.com> Date: Wed, 1 Jan 2025 17:15:49 +0100 Subject: [PATCH] Adds Safari support --- .changeset/cold-boxes-exercise.md | 9 +++++++++ src/vanilla.ts | 24 ++++++++++-------------- 2 files changed, 19 insertions(+), 14 deletions(-) create mode 100644 .changeset/cold-boxes-exercise.md diff --git a/.changeset/cold-boxes-exercise.md b/.changeset/cold-boxes-exercise.md new file mode 100644 index 0000000..9ee7a64 --- /dev/null +++ b/.changeset/cold-boxes-exercise.md @@ -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. diff --git a/src/vanilla.ts b/src/vanilla.ts index 20a1b6f..ec435f2 100644 --- a/src/vanilla.ts +++ b/src/vanilla.ts @@ -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); } } @@ -201,12 +197,12 @@ function restore(values: ElementSpec[]) { values.forEach((elementSpec: ElementSpec) => { let element = document.querySelector( '#' + - 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) => { @@ -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;