Skip to content

Commit b884f0a

Browse files
committed
formatting and wording
1 parent 1d1d8bc commit b884f0a

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[⭐️Please star to support this work⭐️](https://github.com/vtbag/element-crossing)
22

3-
# 🚸 ElementCrossing
3+
# 🚸 The Element Crossing
44

55
Transfer selected element state across cross-document view transitions.
66

@@ -17,7 +17,7 @@ Small improvements for smoother animations and handling reloads.
1717

1818
For details see the [CHANGELOG](https://github.com/vtbag/element-crossing/blob/main/CHANGELOG.md)
1919

20-
## What happend before?
20+
## What happened before?
2121

2222
> First official release of this code!
2323
@@ -39,4 +39,4 @@ Simply annotate your elements in the HTML source or DOM, and let the library han
3939

4040
Address any CSS property or DOM element property, any CSS class, or CSS animation.
4141

42-
[View configuration examples](https://vtbag.pages.dev/tools/element-crossing/#applications-with-real-world-examples) and [see the Element Crossing in action](https://vtbag.pages.dev/crossing/vanilla/1/)
42+
[View configuration examples](https://vtbag.pages.dev/tools/element-crossing/#applications-with-real-world-examples) and [see the Element Crossing in action](https://vtbag.pages.dev/crossing/vanilla/1/)

src/vanilla.ts

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ function init() {
1515
self.crossingStorage = crossing.fun;
1616
}
1717

18+
document.addEventListener('astro:after-preparation', () => {
19+
pageSwap();
20+
});
21+
document.addEventListener('astro:after-swap', () => {
22+
pageReveal();
23+
});
24+
1825
self.addEventListener('onpageswap' in self ? 'pageswap' : 'pagehide', pageSwap, { once: true });
1926
self.addEventListener('onpagereveal' in self ? 'pagereveal' : 'DOMContentLoaded', pageReveal, {
2027
once: true,
@@ -32,13 +39,6 @@ function pageSwap() {
3239

3340

3441
function pageReveal() {
35-
if (
36-
performance?.navigation?.type === 1 ||
37-
// @ts-expect-error
38-
('navigation' in self && self.navigation?.navigationType === 'reload')
39-
) {
40-
return;
41-
}
4242
let values;
4343
let storage;
4444
if ((storage = self.crossingStorage)) {
@@ -47,7 +47,15 @@ function pageReveal() {
4747
storage = top!.sessionStorage;
4848
values = JSON.parse(storage.getItem('@vtbag/element-crossing') ?? '[]');
4949
}
50-
restore(values);
50+
top!.sessionStorage.removeItem('@vtbag/element-crossing');
51+
self.crossingStorage?.removeItem('@vtbag/element-crossing');
52+
if (
53+
performance?.navigation?.type !== 1 &&
54+
// @ts-expect-error
55+
('navigation' in self && self.navigation?.navigationType !== 'reload')
56+
) {
57+
restore(values);
58+
}
5159
}
5260

5361
function retrieve() {
@@ -181,12 +189,12 @@ function restore(values: ElementSpec[]) {
181189
values.forEach((elementSpec: ElementSpec) => {
182190
let element = document.querySelector<HTMLElement>(
183191
'#' +
184-
elementSpec.id +
185-
",[data-vtbag-x*='#" +
186-
elementSpec.id +
187-
"'],[data-vtbag-x*='id:" +
188-
elementSpec.id +
189-
"']"
192+
elementSpec.id +
193+
",[data-vtbag-x*='#" +
194+
elementSpec.id +
195+
"'],[data-vtbag-x*='id:" +
196+
elementSpec.id +
197+
"']"
190198
);
191199
if (element) {
192200
elementSpec.specs.forEach((s) => {
@@ -229,8 +237,8 @@ function restore(values: ElementSpec[]) {
229237
}
230238
animations.forEach(
231239
(a) =>
232-
(a.currentTime =
233-
~~(s.value ?? '0') + (new Date().getTime() - elementSpec.timestamp))
240+
(a.currentTime =
241+
~~(s.value ?? '0') + (new Date().getTime() - elementSpec.timestamp))
234242
);
235243
break;
236244
case 'elem':

0 commit comments

Comments
 (0)