[ci] format
This commit is contained in:
parent
bd5aa1cd35
commit
a8b979ef40
2 changed files with 67 additions and 66 deletions
|
@ -48,7 +48,7 @@ const announce = () => {
|
||||||
|
|
||||||
const PERSIST_ATTR = 'data-astro-transition-persist';
|
const PERSIST_ATTR = 'data-astro-transition-persist';
|
||||||
|
|
||||||
let parser: DOMParser
|
let parser: DOMParser;
|
||||||
|
|
||||||
// The History API does not tell you if navigation is forward or back, so
|
// The History API does not tell you if navigation is forward or back, so
|
||||||
// you can figure it using an index. On pushState the index is incremented so you
|
// you can figure it using an index. On pushState the index is incremented so you
|
||||||
|
@ -56,14 +56,14 @@ let parser: DOMParser
|
||||||
let currentHistoryIndex = 0;
|
let currentHistoryIndex = 0;
|
||||||
|
|
||||||
if (inBrowser) {
|
if (inBrowser) {
|
||||||
if (history.state) {
|
if (history.state) {
|
||||||
// we reloaded a page with history state
|
// we reloaded a page with history state
|
||||||
// (e.g. history navigation from non-transition page or browser reload)
|
// (e.g. history navigation from non-transition page or browser reload)
|
||||||
currentHistoryIndex = history.state.index;
|
currentHistoryIndex = history.state.index;
|
||||||
scrollTo({ left: history.state.scrollX, top: history.state.scrollY });
|
scrollTo({ left: history.state.scrollX, top: history.state.scrollY });
|
||||||
} else if (transitionEnabledOnThisPage()) {
|
} else if (transitionEnabledOnThisPage()) {
|
||||||
history.replaceState({ index: currentHistoryIndex, scrollX, scrollY, intraPage: false }, '');
|
history.replaceState({ index: currentHistoryIndex, scrollX, scrollY, intraPage: false }, '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const throttle = (cb: (...args: any[]) => any, delay: number) => {
|
const throttle = (cb: (...args: any[]) => any, delay: number) => {
|
||||||
|
@ -347,7 +347,7 @@ async function transition(
|
||||||
toLocation = new URL(response.redirected);
|
toLocation = new URL(response.redirected);
|
||||||
}
|
}
|
||||||
|
|
||||||
parser ??= new DOMParser()
|
parser ??= new DOMParser();
|
||||||
|
|
||||||
const newDocument = parser.parseFromString(response.html, response.mediaType);
|
const newDocument = parser.parseFromString(response.html, response.mediaType);
|
||||||
// The next line might look like a hack,
|
// The next line might look like a hack,
|
||||||
|
@ -388,12 +388,13 @@ async function transition(
|
||||||
let navigateOnServerWarned = false;
|
let navigateOnServerWarned = false;
|
||||||
|
|
||||||
export function navigate(href: string, options?: Options) {
|
export function navigate(href: string, options?: Options) {
|
||||||
|
|
||||||
if (inBrowser === false) {
|
if (inBrowser === false) {
|
||||||
if (!navigateOnServerWarned) {
|
if (!navigateOnServerWarned) {
|
||||||
// instantiate an error for the stacktrace to show to user.
|
// instantiate an error for the stacktrace to show to user.
|
||||||
const warning = new Error("The view transtions client API was called during a server side render. This may be unintentional as the navigate() function is expected to be called in response to user interactions. Please make sure that your usage is correct.");
|
const warning = new Error(
|
||||||
warning.name = "Warning";
|
'The view transtions client API was called during a server side render. This may be unintentional as the navigate() function is expected to be called in response to user interactions. Please make sure that your usage is correct.'
|
||||||
|
);
|
||||||
|
warning.name = 'Warning';
|
||||||
console.warn(warning);
|
console.warn(warning);
|
||||||
navigateOnServerWarned = true;
|
navigateOnServerWarned = true;
|
||||||
}
|
}
|
||||||
|
@ -457,10 +458,10 @@ function onPopState(ev: PopStateEvent) {
|
||||||
currentHistoryIndex = nextIndex;
|
currentHistoryIndex = nextIndex;
|
||||||
transition(direction, new URL(location.href), {}, state);
|
transition(direction, new URL(location.href), {}, state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inBrowser) {
|
if (inBrowser) {
|
||||||
if (supportsViewTransitions || getFallback() !== 'none') {
|
if (supportsViewTransitions || getFallback() !== 'none') {
|
||||||
addEventListener('popstate', onPopState);
|
addEventListener('popstate', onPopState);
|
||||||
addEventListener('load', onPageLoad);
|
addEventListener('load', onPageLoad);
|
||||||
// There's not a good way to record scroll position before a back button.
|
// There's not a good way to record scroll position before a back button.
|
||||||
|
@ -473,5 +474,5 @@ if (supportsViewTransitions || getFallback() !== 'none') {
|
||||||
else addEventListener('scroll', throttle(updateState, 300));
|
else addEventListener('scroll', throttle(updateState, 300));
|
||||||
|
|
||||||
markScriptsExec();
|
markScriptsExec();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue