Skip to content

Commit eaf9060

Browse files
committed
Fix window handling in TypeScript.
1 parent ec2904e commit eaf9060

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

plugins/view-transitions/js/types.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ export type InitViewTransitionsFunction = (
88
config: ViewTransitionsConfig
99
) => void;
1010

11-
export type ExtendedWindow = Window &
12-
typeof globalThis & {
11+
declare global {
12+
interface Window {
1313
plvtInitViewTransitions?: InitViewTransitionsFunction;
1414
navigation?: {
1515
activation: NavigationActivation;
1616
};
17-
};
17+
}
18+
}
1819

1920
export type PageSwapListenerFunction = ( event: PageSwapEvent ) => void;
2021
export type PageRevealListenerFunction = ( event: PageRevealEvent ) => void;

plugins/view-transitions/js/view-transitions.js

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,19 @@
11
/**
2-
* @typedef {import("./types.ts").ExtendedWindow} ExtendedWindow
32
* @typedef {import("./types.ts").ViewTransitionsConfig} ViewTransitionsConfig
43
* @typedef {import("./types.ts").InitViewTransitionsFunction} InitViewTransitionsFunction
54
* @typedef {import("./types.ts").PageSwapListenerFunction} PageSwapListenerFunction
65
* @typedef {import("./types.ts").PageRevealListenerFunction} PageRevealListenerFunction
76
*/
87

9-
/**
10-
* Window reference to reduce size when script is minified.
11-
*
12-
* @type {ExtendedWindow}
13-
*/
14-
const win = window;
15-
168
/**
179
* Initializes view transitions for the current URL.
1810
*
1911
* @type {InitViewTransitionsFunction}
2012
* @param {ViewTransitionsConfig} config - The view transitions configuration.
2113
*/
22-
win.plvtInitViewTransitions = ( config ) => {
23-
if ( ! win.navigation || ! ( 'CSSViewTransitionRule' in win ) ) {
24-
win.console.warn(
14+
window.plvtInitViewTransitions = ( config ) => {
15+
if ( ! window.navigation || ! ( 'CSSViewTransitionRule' in window ) ) {
16+
window.console.warn(
2517
'View transitions not loaded as the browser is lacking support.'
2618
);
2719
return;
@@ -135,7 +127,7 @@ win.plvtInitViewTransitions = ( config ) => {
135127
* @type {PageSwapListenerFunction}
136128
* @param {PageSwapEvent} event - Event fired as the previous URL is about to unload.
137129
*/
138-
win.addEventListener(
130+
window.addEventListener(
139131
'pageswap',
140132
( /** @type {PageSwapEvent} */ event ) => {
141133
if ( event.viewTransition ) {
@@ -170,7 +162,7 @@ win.plvtInitViewTransitions = ( config ) => {
170162
* @type {PageRevealListenerFunction}
171163
* @param {PageRevealEvent} event - Event fired as the new URL being navigated to is loaded.
172164
*/
173-
win.addEventListener(
165+
window.addEventListener(
174166
'pagereveal',
175167
( /** @type {PageRevealEvent} */ event ) => {
176168
if ( event.viewTransition ) {
@@ -186,9 +178,9 @@ win.plvtInitViewTransitions = ( config ) => {
186178
) {
187179
viewTransitionEntries = getViewTransitionEntries(
188180
document.body,
189-
win.navigation.activation.from
181+
window.navigation.activation.from
190182
? getArticleForUrl(
191-
win.navigation.activation.from.url
183+
window.navigation.activation.from.url
192184
)
193185
: null
194186
);

0 commit comments

Comments
 (0)