1
+ /**
2
+ * @typedef {import("./types.ts").ExtendedWindow } ExtendedWindow
3
+ * @typedef {import("./types.ts").ViewTransitionsConfig } ViewTransitionsConfig
4
+ * @typedef {import("./types.ts").InitViewTransitionsFunction } InitViewTransitionsFunction
5
+ * @typedef {import("./types.ts").PageSwapListenerFunction } PageSwapListenerFunction
6
+ * @typedef {import("./types.ts").PageRevealListenerFunction } PageRevealListenerFunction
7
+ */
8
+
9
+ /**
10
+ * Window reference to reduce size when script is minified.
11
+ *
12
+ * @type {ExtendedWindow }
13
+ */
14
+ const win = window ;
15
+
1
16
/**
2
17
* Initializes view transitions for the current URL.
3
18
*
4
- * @param {Object } config The view transitions configuration.
5
- * @param {string } config.postSelector General selector for post elements in the DOM.
6
- * @param {Object } config.globalTransitionNames Map of selectors for global elements (queried relative to 'body')
7
- * and their view transition names.
8
- * @param {Object } config.postTransitionNames Map of selectors for post elements (queried relative to an element
9
- * identified by config.postSelector) and their view transition names.
19
+ * @type {InitViewTransitionsFunction }
20
+ * @param {ViewTransitionsConfig } config - The view transitions configuration.
10
21
*/
11
- window . plvtInitViewTransitions = ( config ) => {
12
- if ( ! window . navigation || ! ( 'CSSViewTransitionRule' in window ) ) {
13
- window . console . warn (
22
+ win . plvtInitViewTransitions = ( config ) => {
23
+ if ( ! win . navigation || ! ( 'CSSViewTransitionRule' in win ) ) {
24
+ win . console . warn (
14
25
'View transitions not loaded as the browser is lacking support.'
15
26
) ;
16
27
return ;
@@ -121,9 +132,10 @@ window.plvtInitViewTransitions = ( config ) => {
121
132
/**
122
133
* Customizes view transition behavior on the URL that is being navigated from.
123
134
*
124
- * @param {Event } event Event fired as the previous URL is about to unload.
135
+ * @type {PageSwapListenerFunction }
136
+ * @param {PageSwapEvent } event - Event fired as the previous URL is about to unload.
125
137
*/
126
- window . addEventListener ( 'pageswap' , ( event ) => {
138
+ win . addEventListener ( 'pageswap' , ( event ) => {
127
139
if ( event . viewTransition ) {
128
140
let viewTransitionEntries ;
129
141
if ( document . body . classList . contains ( 'single' ) ) {
@@ -152,9 +164,10 @@ window.plvtInitViewTransitions = ( config ) => {
152
164
/**
153
165
* Customizes view transition behavior on the URL that is being navigated to.
154
166
*
155
- * @param {Event } event Event fired as the new URL being navigated to is loaded.
167
+ * @type {PageRevealListenerFunction }
168
+ * @param {PageRevealEvent } event - Event fired as the new URL being navigated to is loaded.
156
169
*/
157
- window . addEventListener ( 'pagereveal' , ( event ) => {
170
+ win . addEventListener ( 'pagereveal' , ( event ) => {
158
171
if ( event . viewTransition ) {
159
172
let viewTransitionEntries ;
160
173
if ( document . body . classList . contains ( 'single' ) ) {
@@ -168,10 +181,8 @@ window.plvtInitViewTransitions = ( config ) => {
168
181
) {
169
182
viewTransitionEntries = getViewTransitionEntries (
170
183
document . body ,
171
- window . navigation . activation . from
172
- ? getArticleForUrl (
173
- window . navigation . activation . from . url
174
- )
184
+ win . navigation . activation . from
185
+ ? getArticleForUrl ( win . navigation . activation . from . url )
175
186
: null
176
187
) ;
177
188
}
0 commit comments