view-transitions-mock 0.0.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -2
- package/dist/index.d.ts +24 -14
- package/dist/index.js +343 -91
- package/dist/index.js.map +4 -4
- package/package.json +13 -5
package/README.md
CHANGED
|
@@ -6,7 +6,32 @@ Mock support for `document.startViewTransition` in browsers with no support.
|
|
|
6
6
|
|
|
7
7
|
This library mocks `document.startViewTransition` along with `document.activeViewTransition`. With the mock installed, you can safely call `document.startViewTransition()` – and rely on its promises and what not – without it throwing an error in browsers that have no support for it.
|
|
8
8
|
|
|
9
|
-
This way, you don’t need to sprinkle
|
|
9
|
+
This way, you don’t need to sprinkle `if (document.startViewTransition) …` checks throughout your code.
|
|
10
|
+
|
|
11
|
+
- Without `view-transitions-mock`:
|
|
12
|
+
|
|
13
|
+
```javascript
|
|
14
|
+
document.querySelector('button').addEventListener('click', async () => {
|
|
15
|
+
if (document.startViewTransition) {
|
|
16
|
+
document.querySelector('#thing').style.viewTransitionName = 'the-thing';
|
|
17
|
+
const t = document.startViewTransition(updateTheDOM);
|
|
18
|
+
await t.finished;
|
|
19
|
+
document.querySelector('#thing').style.viewTransitionName = '';
|
|
20
|
+
} else {
|
|
21
|
+
updateTheDOM();
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
- With `view-transitions-mock` registered:
|
|
26
|
+
|
|
27
|
+
```javascript
|
|
28
|
+
document.querySelector('button').addEventListener('click', async () => {
|
|
29
|
+
document.querySelector('#thing').style.viewTransitionName = 'the-thing';
|
|
30
|
+
const t = document.startViewTransition(updateTheDOM);
|
|
31
|
+
await t.finished;
|
|
32
|
+
document.querySelector('#thing').style.viewTransitionName = '';
|
|
33
|
+
});
|
|
34
|
+
```
|
|
10
35
|
|
|
11
36
|
## Installation
|
|
12
37
|
|
|
@@ -27,7 +52,28 @@ npm i view-transitions-mock
|
|
|
27
52
|
|
|
28
53
|
2. Done.
|
|
29
54
|
|
|
30
|
-
|
|
55
|
+
## Registration Configuration
|
|
56
|
+
|
|
57
|
+
By default, the registation of `view-transitions-mock` checks whether `document.startViewTransition` and View Transition Types are supported or not. When both are supported, it won’t register the mock.
|
|
58
|
+
|
|
59
|
+
You can tweak the registration by passing an object with the following properties into the `register` function:
|
|
60
|
+
|
|
61
|
+
- `requireTypes` _(`Boolean`, default value: `true`)_: Require support for View Transition Types.
|
|
62
|
+
- `forced` _(`Boolean`, default value: `false`)_: Force register the mock, regardless of support.
|
|
63
|
+
|
|
64
|
+
For example, if you are not relying on View Transition Types, call `register` as follows so that it does not register the mock in Firefox 144–146 which does not have support for View Transition Types:
|
|
65
|
+
|
|
66
|
+
```javascript
|
|
67
|
+
import { register } from "view-transitions-mock";
|
|
68
|
+
register({ requireTypes: false });
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Or if you want to disable native support for Same-Document View Transitions entirely – handy if you want to test how your site looks without View Transitions – call `register` as follows:
|
|
72
|
+
|
|
73
|
+
```javascript
|
|
74
|
+
import { register } from "view-transitions-mock";
|
|
75
|
+
register({ forced: true });
|
|
76
|
+
```
|
|
31
77
|
|
|
32
78
|
## License
|
|
33
79
|
|
package/dist/index.d.ts
CHANGED
|
@@ -23,7 +23,13 @@ declare module "types" {
|
|
|
23
23
|
}
|
|
24
24
|
interface ViewTransitionTypeSet extends Set<string> {
|
|
25
25
|
}
|
|
26
|
-
|
|
26
|
+
type ViewTransitionPhase = "pending-capture" | "update-callback-called" | "animating" | "done";
|
|
27
|
+
const possibleViewTransitionPhases: ViewTransitionPhase[];
|
|
28
|
+
type RegistrationTrigger = {
|
|
29
|
+
requireTypes: boolean;
|
|
30
|
+
forced: boolean;
|
|
31
|
+
};
|
|
32
|
+
export { ViewTransition, ViewTransitionUpdateCallback, StartViewTransitionOptions, ViewTransitionTypeSet, ViewTransitionPhase, possibleViewTransitionPhases, RegistrationTrigger, };
|
|
27
33
|
}
|
|
28
34
|
declare module "classes/ViewTransitionTypeSet" {
|
|
29
35
|
/**
|
|
@@ -41,33 +47,37 @@ declare module "classes/ViewTransition" {
|
|
|
41
47
|
* Copyright 2026 Google LLC
|
|
42
48
|
* SPDX-License-Identifier: Apache-2.0
|
|
43
49
|
*/
|
|
44
|
-
import
|
|
50
|
+
import WatchablePromise from "watchable-promise";
|
|
51
|
+
import { ViewTransition as ViewTransitionInterface, ViewTransitionUpdateCallback, ViewTransitionPhase } from "types";
|
|
45
52
|
import { ViewTransitionTypeSet } from "classes/ViewTransitionTypeSet";
|
|
46
53
|
const setAllowClassCreation: (value: boolean) => void;
|
|
47
54
|
export { setAllowClassCreation };
|
|
48
55
|
class ViewTransition implements ViewTransitionInterface {
|
|
49
56
|
#private;
|
|
50
|
-
constructor(
|
|
51
|
-
skipTransition: () =>
|
|
52
|
-
get
|
|
53
|
-
get ready():
|
|
54
|
-
get
|
|
57
|
+
constructor();
|
|
58
|
+
skipTransition: () => undefined;
|
|
59
|
+
get updateCallbackDone(): WatchablePromise<void>;
|
|
60
|
+
get ready(): WatchablePromise<void>;
|
|
61
|
+
get finished(): WatchablePromise<void>;
|
|
55
62
|
get types(): ViewTransitionTypeSet;
|
|
63
|
+
set phase(phase: ViewTransitionPhase);
|
|
64
|
+
get phase(): ViewTransitionPhase;
|
|
65
|
+
set updateCallback(callback: ViewTransitionUpdateCallback);
|
|
66
|
+
get updateCallback(): ViewTransitionUpdateCallback | null;
|
|
56
67
|
}
|
|
57
68
|
export { ViewTransition };
|
|
58
69
|
}
|
|
59
70
|
declare module "same-document" {
|
|
60
|
-
/**
|
|
61
|
-
* Copyright 2026 Google LLC
|
|
62
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
63
|
-
*/
|
|
64
71
|
import { ViewTransitionUpdateCallback, StartViewTransitionOptions } from "types";
|
|
65
72
|
import { ViewTransition } from "classes/ViewTransition";
|
|
66
73
|
const startViewTransition: (params?: ViewTransitionUpdateCallback | StartViewTransitionOptions) => ViewTransition;
|
|
67
74
|
const getActiveViewTranstion: () => ViewTransition | null;
|
|
68
|
-
|
|
75
|
+
const skipTheViewTransition: (transition: ViewTransition, reason?: any) => Promise<undefined>;
|
|
76
|
+
export { startViewTransition, getActiveViewTranstion, skipTheViewTransition };
|
|
69
77
|
}
|
|
70
78
|
declare module "index" {
|
|
71
|
-
|
|
72
|
-
|
|
79
|
+
import { RegistrationTrigger } from "types";
|
|
80
|
+
const register: (registrationTrigger?: RegistrationTrigger) => void;
|
|
81
|
+
const unregister: () => void;
|
|
82
|
+
export { register, unregister };
|
|
73
83
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,81 @@
|
|
|
1
|
+
// node_modules/watchable-promise/dist/index.js
|
|
2
|
+
var WatchablePromise = class _WatchablePromise extends Promise {
|
|
3
|
+
#settled = false;
|
|
4
|
+
#state = "pending";
|
|
5
|
+
#value;
|
|
6
|
+
#resolve;
|
|
7
|
+
#reject;
|
|
8
|
+
constructor(executor) {
|
|
9
|
+
let resolve;
|
|
10
|
+
let reject;
|
|
11
|
+
super((res, rej) => {
|
|
12
|
+
resolve = res;
|
|
13
|
+
reject = rej;
|
|
14
|
+
});
|
|
15
|
+
this.#resolve = resolve;
|
|
16
|
+
this.#reject = reject;
|
|
17
|
+
this.then(
|
|
18
|
+
(value) => {
|
|
19
|
+
this.#state = "fulfilled";
|
|
20
|
+
this.#value = value;
|
|
21
|
+
this.#settled = true;
|
|
22
|
+
},
|
|
23
|
+
(reason) => {
|
|
24
|
+
this.#state = "rejected";
|
|
25
|
+
this.#value = reason;
|
|
26
|
+
this.#settled = true;
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
executor(this.#resolve, this.#reject);
|
|
30
|
+
}
|
|
31
|
+
resolve(value) {
|
|
32
|
+
return this.#resolve(value);
|
|
33
|
+
}
|
|
34
|
+
reject(reason) {
|
|
35
|
+
return this.#reject(reason);
|
|
36
|
+
}
|
|
37
|
+
get settled() {
|
|
38
|
+
return this.#settled;
|
|
39
|
+
}
|
|
40
|
+
get state() {
|
|
41
|
+
return this.#state;
|
|
42
|
+
}
|
|
43
|
+
get value() {
|
|
44
|
+
return this.#value;
|
|
45
|
+
}
|
|
46
|
+
static from(existingPromise) {
|
|
47
|
+
return new _WatchablePromise((resolve, reject) => {
|
|
48
|
+
existingPromise.then(resolve, reject);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
static withResolvers() {
|
|
52
|
+
let resolve;
|
|
53
|
+
let reject;
|
|
54
|
+
const promise = new _WatchablePromise((res, rej) => {
|
|
55
|
+
resolve = res;
|
|
56
|
+
reject = rej;
|
|
57
|
+
});
|
|
58
|
+
return { promise, resolve, reject };
|
|
59
|
+
}
|
|
60
|
+
static get [Symbol.species]() {
|
|
61
|
+
return Promise;
|
|
62
|
+
}
|
|
63
|
+
get [Symbol.toStringTag]() {
|
|
64
|
+
return "WatchablePromise";
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
var index_default = WatchablePromise;
|
|
68
|
+
|
|
69
|
+
// src/types.ts
|
|
70
|
+
var possibleViewTransitionPhases = [
|
|
71
|
+
"pending-capture",
|
|
72
|
+
"update-callback-called",
|
|
73
|
+
"animating",
|
|
74
|
+
"done"
|
|
75
|
+
];
|
|
76
|
+
|
|
1
77
|
// src/classes/ViewTransitionTypeSet.ts
|
|
2
|
-
var
|
|
78
|
+
var ViewTransitionTypeSet2 = class extends Set {
|
|
3
79
|
constructor() {
|
|
4
80
|
super();
|
|
5
81
|
}
|
|
@@ -10,110 +86,95 @@ var allowClassCreation = false;
|
|
|
10
86
|
var setAllowClassCreation = (value) => {
|
|
11
87
|
allowClassCreation = value;
|
|
12
88
|
};
|
|
13
|
-
var
|
|
14
|
-
constructor(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
this.#
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
89
|
+
var ViewTransition2 = class {
|
|
90
|
+
constructor() {
|
|
91
|
+
this.#updateCallback = null;
|
|
92
|
+
// The phase – One of the possible VT phases, initially "pending-capture"
|
|
93
|
+
this.#phase = possibleViewTransitionPhases[0];
|
|
94
|
+
// #start = async (): Promise<void> => {
|
|
95
|
+
// if (this.#isBeingSkipped == false) {
|
|
96
|
+
// try {
|
|
97
|
+
// await this.#flushTheUpdateCallbackQueue();
|
|
98
|
+
// this.#ready.resolve();
|
|
99
|
+
// this.#finished.resolve();
|
|
100
|
+
// } catch (e) {
|
|
101
|
+
// this.#ready.reject();
|
|
102
|
+
// this.#finished.reject();
|
|
103
|
+
// }
|
|
104
|
+
// }
|
|
105
|
+
// };
|
|
29
106
|
// @ref https://drafts.csswg.org/css-view-transitions-1/#dom-viewtransition-skiptransition
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
} catch (e) {
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
if (this.#updateCallbackState == "resolved") {
|
|
43
|
-
this.#resolveFinished();
|
|
44
|
-
} else {
|
|
45
|
-
this.#rejectFinished();
|
|
107
|
+
this.skipTransition = () => {
|
|
108
|
+
if (this.#phase !== "done") {
|
|
109
|
+
skipTheViewTransition(
|
|
110
|
+
this,
|
|
111
|
+
new DOMException(
|
|
112
|
+
"ViewTransition.skipTransition() was called",
|
|
113
|
+
"AbortError"
|
|
114
|
+
)
|
|
115
|
+
);
|
|
46
116
|
}
|
|
47
|
-
|
|
48
|
-
this.#flushTheUpdateCallbackQueue = async () => {
|
|
49
|
-
try {
|
|
50
|
-
this.#updateCallback();
|
|
51
|
-
this.#updateCallbackState = "resolved";
|
|
52
|
-
this.#resolveUpdateCallbackDone();
|
|
53
|
-
} catch (e) {
|
|
54
|
-
this.#updateCallbackState = "rejected";
|
|
55
|
-
this.#rejectUpdateCallbackDone();
|
|
56
|
-
}
|
|
57
|
-
return this.#updateCallbackDone;
|
|
117
|
+
return void 0;
|
|
58
118
|
};
|
|
59
119
|
if (!allowClassCreation) {
|
|
60
120
|
throw new TypeError("Illegal constructor");
|
|
61
121
|
}
|
|
62
|
-
this.#
|
|
63
|
-
this.#updateCallbackDone = new Promise((res, rej) => {
|
|
64
|
-
this.#resolveUpdateCallbackDone = res;
|
|
65
|
-
this.#rejectUpdateCallbackDone = rej;
|
|
122
|
+
this.#updateCallbackDone = new index_default((resolve, reject) => {
|
|
66
123
|
});
|
|
67
|
-
this.#ready = new
|
|
68
|
-
this.#resolveReady = res;
|
|
69
|
-
this.#rejectReady = rej;
|
|
124
|
+
this.#ready = new index_default((resolve, reject) => {
|
|
70
125
|
});
|
|
71
|
-
this.#finished = new
|
|
72
|
-
this.#resolveFinished = res;
|
|
73
|
-
this.#rejectFinished = rej;
|
|
126
|
+
this.#finished = new index_default((resolve, reject) => {
|
|
74
127
|
});
|
|
75
|
-
this.#types = new
|
|
76
|
-
this.#updateCallback = updateCallback;
|
|
77
|
-
window.queueMicrotask(this.#start);
|
|
128
|
+
this.#types = new ViewTransitionTypeSet2();
|
|
78
129
|
}
|
|
79
130
|
// The promises and their resolve/reject functions
|
|
80
131
|
#finished;
|
|
81
|
-
// @ts-ignore
|
|
82
|
-
#resolveFinished;
|
|
83
|
-
// @ts-ignore
|
|
84
|
-
#rejectFinished;
|
|
85
132
|
#ready;
|
|
86
|
-
// @ts-ignore
|
|
87
|
-
#resolveReady;
|
|
88
|
-
// @ts-ignore
|
|
89
|
-
#rejectReady;
|
|
90
133
|
#updateCallbackDone;
|
|
91
|
-
// @ts-ignore
|
|
92
|
-
#resolveUpdateCallbackDone;
|
|
93
|
-
// @ts-ignore
|
|
94
|
-
#rejectUpdateCallbackDone;
|
|
95
|
-
#updateCallbackState;
|
|
96
134
|
#types;
|
|
97
135
|
#updateCallback;
|
|
98
|
-
#
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return this.#finished;
|
|
136
|
+
#phase;
|
|
137
|
+
// @TODO: The spec defines this as Promise<undefined>
|
|
138
|
+
get updateCallbackDone() {
|
|
139
|
+
return this.#updateCallbackDone;
|
|
103
140
|
}
|
|
141
|
+
// @TODO: The spec defines this as Promise<undefined>
|
|
104
142
|
get ready() {
|
|
105
143
|
return this.#ready;
|
|
106
144
|
}
|
|
107
|
-
|
|
108
|
-
|
|
145
|
+
// @TODO: The spec defines this as Promise<undefined>
|
|
146
|
+
get finished() {
|
|
147
|
+
return this.#finished;
|
|
109
148
|
}
|
|
110
149
|
get types() {
|
|
111
150
|
return this.#types;
|
|
112
151
|
}
|
|
152
|
+
// @TODO: This should not be exposed
|
|
153
|
+
set phase(phase) {
|
|
154
|
+
if (!possibleViewTransitionPhases.includes(phase)) {
|
|
155
|
+
throw new Error("Invalid phase");
|
|
156
|
+
}
|
|
157
|
+
this.#phase = phase;
|
|
158
|
+
}
|
|
159
|
+
// @TODO: This should not be exposed
|
|
160
|
+
get phase() {
|
|
161
|
+
return this.#phase;
|
|
162
|
+
}
|
|
163
|
+
// @TODO: This should not be expose
|
|
164
|
+
set updateCallback(callback) {
|
|
165
|
+
this.#updateCallback = callback;
|
|
166
|
+
}
|
|
167
|
+
get updateCallback() {
|
|
168
|
+
return this.#updateCallback;
|
|
169
|
+
}
|
|
170
|
+
// @TODO: transitionRoot
|
|
171
|
+
// @TODO: waitUntil
|
|
113
172
|
};
|
|
114
173
|
|
|
115
174
|
// src/same-document.ts
|
|
116
175
|
var activeViewTransition = null;
|
|
176
|
+
var updateCallbackQueue = [];
|
|
177
|
+
var renderingSuppression = false;
|
|
117
178
|
var startViewTransition = (params) => {
|
|
118
179
|
let callback = null;
|
|
119
180
|
let types = [];
|
|
@@ -127,44 +188,235 @@ var startViewTransition = (params) => {
|
|
|
127
188
|
callback = () => {
|
|
128
189
|
};
|
|
129
190
|
}
|
|
130
|
-
if (activeViewTransition) {
|
|
131
|
-
activeViewTransition.skipTransition();
|
|
132
|
-
activeViewTransition = null;
|
|
133
|
-
}
|
|
134
191
|
setAllowClassCreation(true);
|
|
135
|
-
const transition = new
|
|
192
|
+
const transition = new ViewTransition2();
|
|
136
193
|
setAllowClassCreation(false);
|
|
137
194
|
types.forEach((t) => transition.types.add(t));
|
|
138
|
-
|
|
139
|
-
|
|
195
|
+
transition.updateCallback = callback;
|
|
196
|
+
if (document.visibilityState === "hidden") {
|
|
197
|
+
skipTheViewTransition(
|
|
198
|
+
transition,
|
|
199
|
+
new DOMException(
|
|
200
|
+
`The document's visibility state is "hidden"`,
|
|
201
|
+
"InvalidStateError"
|
|
202
|
+
)
|
|
203
|
+
);
|
|
204
|
+
return transition;
|
|
205
|
+
}
|
|
206
|
+
if (activeViewTransition) {
|
|
207
|
+
skipTheViewTransition(
|
|
208
|
+
activeViewTransition,
|
|
209
|
+
new DOMException(
|
|
210
|
+
"Document.startViewTransition() was called",
|
|
211
|
+
"AbortError"
|
|
212
|
+
)
|
|
213
|
+
);
|
|
140
214
|
activeViewTransition = null;
|
|
215
|
+
}
|
|
216
|
+
activeViewTransition = transition;
|
|
217
|
+
window.queueMicrotask(async () => {
|
|
218
|
+
await performPendingOperations();
|
|
141
219
|
});
|
|
142
220
|
return transition;
|
|
143
221
|
};
|
|
144
222
|
var getActiveViewTranstion = () => {
|
|
145
223
|
return activeViewTransition;
|
|
146
224
|
};
|
|
225
|
+
var performPendingOperations = async () => {
|
|
226
|
+
if (activeViewTransition) {
|
|
227
|
+
if (activeViewTransition.phase === "pending-capture") {
|
|
228
|
+
await setupViewTransition(activeViewTransition);
|
|
229
|
+
}
|
|
230
|
+
if (activeViewTransition.phase === "animating") {
|
|
231
|
+
await handleTransitionFrame(activeViewTransition);
|
|
232
|
+
}
|
|
233
|
+
requestAnimationFrame(async () => {
|
|
234
|
+
await performPendingOperations();
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
var setupViewTransition = async (transition) => {
|
|
239
|
+
await flushTheUpdateCallbackQueue();
|
|
240
|
+
renderingSuppression = true;
|
|
241
|
+
window.queueMicrotask(async () => {
|
|
242
|
+
if (transition.phase === "done") return;
|
|
243
|
+
scheduleTheUpdateCallback(transition);
|
|
244
|
+
});
|
|
245
|
+
};
|
|
246
|
+
var scheduleTheUpdateCallback = (transition) => {
|
|
247
|
+
updateCallbackQueue.push(transition);
|
|
248
|
+
window.queueMicrotask(async () => {
|
|
249
|
+
await flushTheUpdateCallbackQueue();
|
|
250
|
+
});
|
|
251
|
+
};
|
|
252
|
+
var skipTheViewTransition = async (transition, reason) => {
|
|
253
|
+
if (transition.phase === "done") {
|
|
254
|
+
throw new Error('Assertion failed: transition\u2019s phase is not "done"');
|
|
255
|
+
}
|
|
256
|
+
if (possibleViewTransitionPhases.indexOf(transition.phase) < possibleViewTransitionPhases.indexOf("update-callback-called")) {
|
|
257
|
+
scheduleTheUpdateCallback(transition);
|
|
258
|
+
}
|
|
259
|
+
renderingSuppression = false;
|
|
260
|
+
if (document.activeViewTransition === transition) {
|
|
261
|
+
clearViewTransition(transition);
|
|
262
|
+
}
|
|
263
|
+
transition.phase = "done";
|
|
264
|
+
await transition.ready.reject(reason);
|
|
265
|
+
await transition.updateCallbackDone.resolve();
|
|
266
|
+
if (transition.updateCallbackDone.state === "fulfilled") {
|
|
267
|
+
await transition.finished.resolve(transition.updateCallbackDone.value);
|
|
268
|
+
} else {
|
|
269
|
+
await transition.finished.reject();
|
|
270
|
+
}
|
|
271
|
+
if (transition.finished.state === "fulfilled") return void 0;
|
|
272
|
+
};
|
|
273
|
+
var flushTheUpdateCallbackQueue = async () => {
|
|
274
|
+
for (const transition of updateCallbackQueue) {
|
|
275
|
+
await callTheUpdateCallback(transition);
|
|
276
|
+
}
|
|
277
|
+
updateCallbackQueue = [];
|
|
278
|
+
};
|
|
279
|
+
var handleTransitionFrame = async (transition) => {
|
|
280
|
+
let hasActiveAnimations = false;
|
|
281
|
+
if (hasActiveAnimations === false) {
|
|
282
|
+
transition.phase = "done";
|
|
283
|
+
clearViewTransition(transition);
|
|
284
|
+
await transition.finished.resolve();
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
var callTheUpdateCallback = async (transition) => {
|
|
289
|
+
if (!(transition.phase === "done" || possibleViewTransitionPhases.indexOf(transition.phase) < possibleViewTransitionPhases.indexOf("update-callback-called"))) {
|
|
290
|
+
debugger;
|
|
291
|
+
throw new Error(
|
|
292
|
+
`Assertion failed: transition\u2019s phase is "done", or before "update-callback-called". The transition\u2019s phase is "${transition.phase}"`
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
if (transition.phase !== "done") {
|
|
296
|
+
transition.phase = "update-callback-called";
|
|
297
|
+
}
|
|
298
|
+
let callbackPromise = null;
|
|
299
|
+
if (transition.updateCallback === null) {
|
|
300
|
+
callbackPromise = new index_default((resolve, reject) => {
|
|
301
|
+
});
|
|
302
|
+
await callbackPromise.resolve(void 0);
|
|
303
|
+
} else {
|
|
304
|
+
callbackPromise = new index_default((resolve, reject) => {
|
|
305
|
+
});
|
|
306
|
+
await callbackPromise.resolve(await transition.updateCallback());
|
|
307
|
+
}
|
|
308
|
+
let fulfillSteps = async () => {
|
|
309
|
+
await transition.updateCallbackDone.resolve();
|
|
310
|
+
await activateViewTransition(transition);
|
|
311
|
+
};
|
|
312
|
+
let rejectSteps = async (reason) => {
|
|
313
|
+
await transition.updateCallbackDone.reject(reason);
|
|
314
|
+
if (transition.phase === "done") return;
|
|
315
|
+
await transition.ready.resolve();
|
|
316
|
+
await skipTheViewTransition(transition, reason);
|
|
317
|
+
};
|
|
318
|
+
if (callbackPromise.state === "fulfilled") {
|
|
319
|
+
await fulfillSteps();
|
|
320
|
+
} else {
|
|
321
|
+
await rejectSteps(callbackPromise.value);
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
var activateViewTransition = async (transition) => {
|
|
325
|
+
if (transition.phase === "done") return;
|
|
326
|
+
renderingSuppression = false;
|
|
327
|
+
transition.phase = "animating";
|
|
328
|
+
await transition.ready.resolve();
|
|
329
|
+
};
|
|
330
|
+
var clearViewTransition = (transition) => {
|
|
331
|
+
if (transition !== activeViewTransition) {
|
|
332
|
+
throw new Error(
|
|
333
|
+
"Assertion failed: transition !== document.activeViewTransition"
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
activeViewTransition = null;
|
|
337
|
+
};
|
|
147
338
|
|
|
148
339
|
// src/index.ts
|
|
149
340
|
var registered = false;
|
|
150
|
-
var
|
|
341
|
+
var nativeImplementations = {
|
|
342
|
+
ViewTransition: window.ViewTransition,
|
|
343
|
+
ViewTransitionTypeSet: window.ViewTransitionTypeSet,
|
|
344
|
+
startViewTransition: document.startViewTransition,
|
|
345
|
+
activeViewTransition: Reflect.getOwnPropertyDescriptor(
|
|
346
|
+
Document.prototype,
|
|
347
|
+
"activeViewTransition"
|
|
348
|
+
)
|
|
349
|
+
};
|
|
350
|
+
var defaultRegistrationTrigger = {
|
|
351
|
+
requireTypes: true,
|
|
352
|
+
forced: false
|
|
353
|
+
};
|
|
354
|
+
var register = (registrationTrigger = defaultRegistrationTrigger) => {
|
|
151
355
|
if (registered) return;
|
|
152
|
-
|
|
356
|
+
const requireTypesSupport = registrationTrigger.requireTypes;
|
|
357
|
+
const forceRegister = registrationTrigger.forced;
|
|
358
|
+
const hasSameDocumentViewTransitionsSupport = !!document.startViewTransition;
|
|
359
|
+
const hasViewTransitionTypesSupport = hasSameDocumentViewTransitionsSupport && nativeImplementations.ViewTransition && "types" in nativeImplementations.ViewTransition.prototype;
|
|
360
|
+
const needsRegistration = !hasSameDocumentViewTransitionsSupport || hasSameDocumentViewTransitionsSupport && !hasViewTransitionTypesSupport && requireTypesSupport || forceRegister;
|
|
361
|
+
if (needsRegistration) {
|
|
153
362
|
Reflect.defineProperty(window, "ViewTransition", {
|
|
154
|
-
value:
|
|
363
|
+
value: ViewTransition2,
|
|
364
|
+
configurable: true
|
|
155
365
|
});
|
|
156
366
|
Reflect.defineProperty(window, "ViewTransitionTypeSet", {
|
|
157
|
-
value:
|
|
367
|
+
value: ViewTransitionTypeSet2,
|
|
368
|
+
configurable: true
|
|
158
369
|
});
|
|
159
370
|
Reflect.defineProperty(document, "activeViewTransition", {
|
|
160
|
-
get: getActiveViewTranstion
|
|
371
|
+
get: getActiveViewTranstion,
|
|
372
|
+
configurable: true
|
|
373
|
+
});
|
|
374
|
+
Reflect.defineProperty(document, "startViewTransition", {
|
|
375
|
+
value: startViewTransition,
|
|
376
|
+
configurable: true,
|
|
377
|
+
writable: true
|
|
161
378
|
});
|
|
162
|
-
document.startViewTransition = startViewTransition;
|
|
163
379
|
registered = true;
|
|
164
380
|
console.info("Support for Same-Document View Transitions is now mocked");
|
|
165
381
|
}
|
|
166
382
|
};
|
|
383
|
+
var unregister = () => {
|
|
384
|
+
if (!registered) return;
|
|
385
|
+
if (nativeImplementations.ViewTransition) {
|
|
386
|
+
Reflect.defineProperty(window, "ViewTransition", {
|
|
387
|
+
value: nativeImplementations.ViewTransition
|
|
388
|
+
});
|
|
389
|
+
} else {
|
|
390
|
+
Reflect.deleteProperty(window, "ViewTransition");
|
|
391
|
+
}
|
|
392
|
+
if (nativeImplementations.ViewTransitionTypeSet) {
|
|
393
|
+
Reflect.defineProperty(window, "ViewTransitionTypeSet", {
|
|
394
|
+
value: nativeImplementations.ViewTransitionTypeSet
|
|
395
|
+
});
|
|
396
|
+
} else {
|
|
397
|
+
Reflect.deleteProperty(window, "ViewTransitionTypeSet");
|
|
398
|
+
}
|
|
399
|
+
if (nativeImplementations.activeViewTransition) {
|
|
400
|
+
Reflect.defineProperty(
|
|
401
|
+
document,
|
|
402
|
+
"activeViewTransition",
|
|
403
|
+
nativeImplementations.activeViewTransition
|
|
404
|
+
);
|
|
405
|
+
} else {
|
|
406
|
+
Reflect.deleteProperty(document, "activeViewTransition");
|
|
407
|
+
}
|
|
408
|
+
if (nativeImplementations.startViewTransition) {
|
|
409
|
+
document.startViewTransition = nativeImplementations.startViewTransition;
|
|
410
|
+
} else {
|
|
411
|
+
Reflect.deleteProperty(document, "startViewTransition");
|
|
412
|
+
}
|
|
413
|
+
registered = false;
|
|
414
|
+
console.info(
|
|
415
|
+
"Support for Same-Document View Transitions is no longer mocked"
|
|
416
|
+
);
|
|
417
|
+
};
|
|
167
418
|
export {
|
|
168
|
-
register
|
|
419
|
+
register,
|
|
420
|
+
unregister
|
|
169
421
|
};
|
|
170
422
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/classes/ViewTransitionTypeSet.ts", "../src/classes/ViewTransition.ts", "../src/same-document.ts", "../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Copyright 2026 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { ViewTransitionTypeSet as ViewTransitionTypeSetInterface } from \"../types\";\n\nclass ViewTransitionTypeSet\n extends Set<string>\n implements ViewTransitionTypeSetInterface\n{\n constructor() {\n super();\n }\n}\nexport { ViewTransitionTypeSet };\n", "/**\n * Copyright 2026 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n ViewTransition as ViewTransitionInterface,\n ViewTransitionUpdateCallback,\n} from \"../types\";\nimport { ViewTransitionTypeSet } from \"./ViewTransitionTypeSet\";\n\ntype ResolveFunction = (value: void | PromiseLike<void>) => void;\ntype RejectFunction = (reason?: any) => void;\ntype PromiseStatus = \"pending\" | \"resolved\" | \"rejected\";\n\nlet allowClassCreation = false;\nconst setAllowClassCreation = (value: boolean): void => {\n allowClassCreation = value;\n};\nexport { setAllowClassCreation };\n\nclass ViewTransition implements ViewTransitionInterface {\n // The promises and their resolve/reject functions\n #finished: Promise<void>;\n // @ts-ignore\n #resolveFinished: ResolveFunction;\n // @ts-ignore\n #rejectFinished: RejectFunction;\n\n #ready: Promise<void>;\n // @ts-ignore\n #resolveReady: ResolveFunction;\n // @ts-ignore\n #rejectReady: RejectFunction;\n\n #updateCallbackDone: Promise<void>;\n // @ts-ignore\n #resolveUpdateCallbackDone: ResolveFunction;\n // @ts-ignore\n #rejectUpdateCallbackDone: RejectFunction;\n #updateCallbackState: PromiseStatus;\n\n #types: ViewTransitionTypeSet;\n #updateCallback: ViewTransitionUpdateCallback;\n\n // We need this flag to be able to skip the transition before it actually starts.\n #isBeingSkipped = false;\n\n constructor(updateCallback: ViewTransitionUpdateCallback) {\n // Prevent externals from creating an instance\n if (!allowClassCreation) {\n throw new TypeError(\"Illegal constructor\");\n }\n\n // The updateCallbackDone promise.\n this.#updateCallbackState = \"pending\";\n this.#updateCallbackDone = new Promise((res, rej) => {\n this.#resolveUpdateCallbackDone = res;\n this.#rejectUpdateCallbackDone = rej;\n });\n\n // The ready promise.\n this.#ready = new Promise((res, rej) => {\n this.#resolveReady = res;\n this.#rejectReady = rej;\n });\n\n // The finished promise.\n this.#finished = new Promise((res, rej) => {\n this.#resolveFinished = res;\n this.#rejectFinished = rej;\n });\n\n // The types\n this.#types = new ViewTransitionTypeSet();\n\n // The updateCallback\n this.#updateCallback = updateCallback;\n\n // Start the transition\n window.queueMicrotask(this.#start);\n }\n\n #start = async (): Promise<void> => {\n if (this.#isBeingSkipped == false) {\n try {\n await this.#flushTheUpdateCallbackQueue();\n this.#resolveReady();\n this.#resolveFinished();\n } catch (e) {\n this.#rejectReady();\n this.#rejectFinished();\n }\n }\n };\n\n // @ref https://drafts.csswg.org/css-view-transitions-1/#dom-viewtransition-skiptransition\n // Spec: If this\u2019s phase is not \"done\", then skip the view transition for this with an \"AbortError\" DOMException.\n skipTransition = async (): Promise<void> => {\n this.#isBeingSkipped = true;\n\n // Spec: Reject transition\u2019s ready promise with reason.\n // @TODO: Ready should not reject if already resolved\n await this.#rejectReady(\n new DOMException(\"Transition was skipped\", \"AbortError\"),\n );\n\n // Spec: If transition\u2019s phase is before \"update-callback-called\", then schedule the update callback for transition.\n if (this.#updateCallbackState == \"pending\") {\n try {\n await this.#flushTheUpdateCallbackQueue();\n } catch (e) {}\n }\n\n // Spec: Resolve transition\u2019s finished promise with the result of reacting to transition\u2019s update callback done promise\n if (this.#updateCallbackState == \"resolved\") {\n this.#resolveFinished();\n } else {\n this.#rejectFinished();\n }\n };\n\n #flushTheUpdateCallbackQueue = async (): Promise<void> => {\n try {\n this.#updateCallback();\n\n this.#updateCallbackState = \"resolved\";\n this.#resolveUpdateCallbackDone();\n } catch (e) {\n this.#updateCallbackState = \"rejected\";\n this.#rejectUpdateCallbackDone();\n }\n\n return this.#updateCallbackDone;\n };\n\n get finished(): Promise<void> {\n return this.#finished;\n }\n\n get ready(): Promise<void> {\n return this.#ready;\n }\n\n get updateCallbackDone(): Promise<void> {\n return this.#updateCallbackDone;\n }\n\n get types(): ViewTransitionTypeSet {\n return this.#types;\n }\n}\n\nexport { ViewTransition };\n", "/**\n * Copyright 2026 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n ViewTransitionUpdateCallback,\n StartViewTransitionOptions,\n} from \"./types\";\nimport {\n ViewTransition,\n setAllowClassCreation,\n} from \"./classes/ViewTransition\";\n\nlet activeViewTransition: ViewTransition | null = null;\n\nconst startViewTransition = (\n params?: ViewTransitionUpdateCallback | StartViewTransitionOptions,\n): ViewTransition => {\n let callback: ViewTransitionUpdateCallback | null | undefined = null;\n let types: string[] = [];\n\n // Extract the callback and types\n if (typeof params === \"function\") {\n callback = params;\n } else if (params && typeof params === \"object\") {\n callback = params.update;\n types = params.types ?? [];\n }\n\n // Make sure there is a callback\n if (!callback) {\n callback = () => {};\n }\n\n // If there already is a ViewTransition active, skip that first\n if (activeViewTransition) {\n activeViewTransition.skipTransition();\n activeViewTransition = null;\n }\n\n // Create the (Mocked) View Transition\n setAllowClassCreation(true);\n const transition = new ViewTransition(callback);\n setAllowClassCreation(false);\n types.forEach((t) => transition.types.add(t));\n\n // Store it as the activeViewTransition\n activeViewTransition = transition;\n transition.finished.then(() => {\n activeViewTransition = null;\n });\n\n // Return it\n return transition;\n};\n\nconst getActiveViewTranstion = (): ViewTransition | null => {\n return activeViewTransition;\n};\n\nexport { startViewTransition, getActiveViewTranstion };\n", "/**\n * Copyright 2026 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { startViewTransition, getActiveViewTranstion } from \"./same-document\";\n\nimport { ViewTransition } from \"./classes/ViewTransition\";\nimport { ViewTransitionTypeSet } from \"./classes/ViewTransitionTypeSet\";\n\nlet registered = false;\n\nconst register = (force: boolean = false): void => {\n if (registered) return;\n\n if (!document.startViewTransition || force) {\n Reflect.defineProperty(window, \"ViewTransition\", {\n value: ViewTransition,\n });\n\n Reflect.defineProperty(window, \"ViewTransitionTypeSet\", {\n value: ViewTransitionTypeSet,\n });\n\n Reflect.defineProperty(document, \"activeViewTransition\", {\n get: getActiveViewTranstion,\n });\n\n document.startViewTransition = startViewTransition;\n\n registered = true;\n\n console.info(\"Support for Same-Document View Transitions is now mocked\");\n }\n};\n\nexport { register };\n"],
|
|
5
|
-
"mappings": ";
|
|
6
|
-
"names": []
|
|
3
|
+
"sources": ["../node_modules/watchable-promise/src/index.ts", "../src/types.ts", "../src/classes/ViewTransitionTypeSet.ts", "../src/classes/ViewTransition.ts", "../src/same-document.ts", "../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["class WatchablePromise<T> extends Promise<T> {\n #settled = false;\n #state: \"pending\" | \"fulfilled\" | \"rejected\" = \"pending\";\n #value: T | any;\n #resolve: (value: T | PromiseLike<T>) => void;\n #reject: (reason?: any) => void;\n\n constructor(\n executor: (\n resolve: (value: T | PromiseLike<T>) => void,\n reject: (reason?: any) => void,\n ) => void,\n ) {\n let resolve: (value: T | PromiseLike<T>) => void;\n let reject: (reason?: any) => void;\n\n super((res, rej) => {\n resolve = res;\n reject = rej;\n });\n\n // @ts-ignore\n this.#resolve = resolve;\n // @ts-ignore\n this.#reject = reject;\n\n this.then(\n (value) => {\n this.#state = \"fulfilled\";\n this.#value = value;\n this.#settled = true;\n },\n (reason) => {\n this.#state = \"rejected\";\n this.#value = reason;\n this.#settled = true;\n },\n );\n\n executor(this.#resolve, this.#reject);\n }\n\n resolve(value: T) {\n return this.#resolve(value);\n }\n\n reject(reason?: any) {\n return this.#reject(reason);\n }\n\n get settled() {\n return this.#settled;\n }\n\n get state() {\n return this.#state;\n }\n\n get value() {\n return this.#value;\n }\n\n static from<T>(existingPromise: Promise<T>): WatchablePromise<T> {\n return new WatchablePromise<T>((resolve, reject) => {\n existingPromise.then(resolve, reject);\n });\n }\n\n static withResolvers<T>() {\n let resolve: (value: T | PromiseLike<T>) => void;\n let reject: (reason?: any) => void;\n const promise = new WatchablePromise<T>((res, rej) => {\n resolve = res;\n reject = rej;\n });\n // @ts-ignore\n return { promise, resolve, reject };\n }\n\n static get [Symbol.species]() {\n return Promise;\n }\n\n get [Symbol.toStringTag]() {\n return \"WatchablePromise\";\n }\n}\n\nexport default WatchablePromise;\n", "/**\n * Copyright 2026 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\ndeclare global {\n interface Document {\n activeViewTransition: ViewTransition | null;\n startViewTransition(\n callbackOptions?:\n | ViewTransitionUpdateCallback\n | StartViewTransitionOptions,\n ): ViewTransition;\n }\n}\n\ninterface ViewTransition {\n readonly finished: Promise<void>;\n readonly ready: Promise<void>;\n readonly updateCallbackDone: Promise<void>;\n readonly types: ViewTransitionTypeSet;\n skipTransition(): void;\n}\n\ntype ViewTransitionUpdateCallback = () => void | Promise<void>;\n\ninterface StartViewTransitionOptions {\n update: ViewTransitionUpdateCallback | null;\n types?: string[] | null;\n}\n\ninterface ViewTransitionTypeSet extends Set<string> {}\n\n// @ref https://drafts.csswg.org/css-view-transitions-1/#viewtransition-phase\ntype ViewTransitionPhase =\n | \"pending-capture\"\n | \"update-callback-called\"\n | \"animating\"\n | \"done\";\n\nconst possibleViewTransitionPhases: ViewTransitionPhase[] = [\n \"pending-capture\",\n \"update-callback-called\",\n \"animating\",\n \"done\",\n];\n\ntype RegistrationTrigger = {\n requireTypes: boolean;\n forced: boolean;\n};\n\nexport {\n ViewTransition,\n ViewTransitionUpdateCallback,\n StartViewTransitionOptions,\n ViewTransitionTypeSet,\n ViewTransitionPhase,\n possibleViewTransitionPhases,\n RegistrationTrigger,\n};\n", "/**\n * Copyright 2026 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { ViewTransitionTypeSet as ViewTransitionTypeSetInterface } from \"../types\";\n\nclass ViewTransitionTypeSet\n extends Set<string>\n implements ViewTransitionTypeSetInterface\n{\n constructor() {\n super();\n }\n}\nexport { ViewTransitionTypeSet };\n", "/**\n * Copyright 2026 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport WatchablePromise from \"watchable-promise\";\n\nimport {\n ViewTransition as ViewTransitionInterface,\n ViewTransitionUpdateCallback,\n ViewTransitionPhase,\n possibleViewTransitionPhases,\n} from \"../types\";\nimport { ViewTransitionTypeSet } from \"./ViewTransitionTypeSet\";\nimport { skipTheViewTransition } from \"../same-document\";\n\ntype ResolveFunction = (value: void | PromiseLike<void>) => void;\ntype RejectFunction = (reason?: any) => void;\n\nlet allowClassCreation = false;\nconst setAllowClassCreation = (value: boolean): void => {\n allowClassCreation = value;\n};\nexport { setAllowClassCreation };\n\nclass ViewTransition implements ViewTransitionInterface {\n // The promises and their resolve/reject functions\n #finished: WatchablePromise<void>;\n #ready: WatchablePromise<void>;\n #updateCallbackDone: WatchablePromise<void>;\n\n #types: ViewTransitionTypeSet;\n #updateCallback: ViewTransitionUpdateCallback | null = null;\n\n // The phase \u2013 One of the possible VT phases, initially \"pending-capture\"\n #phase = possibleViewTransitionPhases[0];\n\n constructor() {\n // Prevent externals from creating an instance\n if (!allowClassCreation) {\n throw new TypeError(\"Illegal constructor\");\n }\n\n // The updateCallbackDone promise.\n this.#updateCallbackDone = new WatchablePromise((resolve, reject) => {});\n\n // The ready promise.\n this.#ready = new WatchablePromise((resolve, reject) => {});\n\n // The finished promise.\n this.#finished = new WatchablePromise((resolve, reject) => {});\n\n // The types\n this.#types = new ViewTransitionTypeSet();\n }\n\n // #start = async (): Promise<void> => {\n // if (this.#isBeingSkipped == false) {\n // try {\n // await this.#flushTheUpdateCallbackQueue();\n // this.#ready.resolve();\n // this.#finished.resolve();\n // } catch (e) {\n // this.#ready.reject();\n // this.#finished.reject();\n // }\n // }\n // };\n\n // @ref https://drafts.csswg.org/css-view-transitions-1/#dom-viewtransition-skiptransition\n skipTransition = (): undefined => {\n // 1. If this\u2019s phase is not \"done\", then skip the view transition for this with an \"AbortError\" DOMException.\n if (this.#phase !== \"done\") {\n skipTheViewTransition(\n this,\n new DOMException(\n \"ViewTransition.skipTransition() was called\",\n \"AbortError\",\n ),\n );\n }\n\n return undefined;\n };\n\n // @TODO: The spec defines this as Promise<undefined>\n get updateCallbackDone(): WatchablePromise<void> {\n return this.#updateCallbackDone;\n }\n\n // @TODO: The spec defines this as Promise<undefined>\n get ready(): WatchablePromise<void> {\n return this.#ready;\n }\n\n // @TODO: The spec defines this as Promise<undefined>\n get finished(): WatchablePromise<void> {\n return this.#finished;\n }\n\n get types(): ViewTransitionTypeSet {\n return this.#types;\n }\n\n // @TODO: This should not be exposed\n set phase(phase: ViewTransitionPhase) {\n if (!possibleViewTransitionPhases.includes(phase)) {\n throw new Error(\"Invalid phase\");\n }\n this.#phase = phase;\n }\n\n // @TODO: This should not be exposed\n get phase(): ViewTransitionPhase {\n return this.#phase;\n }\n\n // @TODO: This should not be expose\n set updateCallback(callback: ViewTransitionUpdateCallback) {\n this.#updateCallback = callback;\n }\n\n get updateCallback(): ViewTransitionUpdateCallback | null {\n return this.#updateCallback;\n }\n\n // @TODO: transitionRoot\n // @TODO: waitUntil\n}\n\nexport { ViewTransition };\n", "/**\n * Copyright 2026 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport WatchablePromise from \"watchable-promise\";\n\nimport {\n ViewTransitionUpdateCallback,\n StartViewTransitionOptions,\n possibleViewTransitionPhases,\n} from \"./types\";\nimport {\n ViewTransition,\n setAllowClassCreation,\n} from \"./classes/ViewTransition\";\n\nlet activeViewTransition: ViewTransition | null = null;\n\n// @TODO: Implement https://drafts.csswg.org/css-view-transitions-1/#page-visibility-change-steps\n\n// update callback queue \u2013 A list, initially empty.\nlet updateCallbackQueue: any[] = [];\n\nlet renderingSuppression = false;\n\nconst startViewTransition = (\n params?: ViewTransitionUpdateCallback | StartViewTransitionOptions,\n): ViewTransition => {\n let callback: ViewTransitionUpdateCallback | null | undefined = null;\n let types: string[] = [];\n\n // Extract the callback and types\n if (typeof params === \"function\") {\n callback = params;\n } else if (params && typeof params === \"object\") {\n callback = params.update;\n types = params.types ?? [];\n }\n\n // @TODO: This is not spec compliant. Remove this.\n // Make sure there is a callback\n if (!callback) {\n callback = () => {};\n }\n\n // @ref https://drafts.csswg.org/css-view-transitions-1/#ViewTransition-prepare\n\n // 1. Let transition be a new ViewTransition object in this\u2019s relevant Realm.\n setAllowClassCreation(true);\n const transition = new ViewTransition();\n setAllowClassCreation(false);\n types.forEach((t) => transition.types.add(t));\n\n // 2. If updateCallback is provided, set transition\u2019s update callback to updateCallback.\n transition.updateCallback = callback;\n\n // 3. Let document be this\u2019s relevant global object\u2019s associated document.\n // @NOTIMPLEMENTED\n\n // 4. If document\u2019s visibility state is \"hidden\", then skip transition with an \"InvalidStateError\" DOMException, and return transition.\n if (document.visibilityState === \"hidden\") {\n skipTheViewTransition(\n transition,\n new DOMException(\n 'The document\\'s visibility state is \"hidden\"',\n \"InvalidStateError\",\n ),\n );\n return transition;\n }\n\n // 5. If document\u2019s active view transition is not null, then skip that view transition with an \"AbortError\" DOMException in this\u2019s relevant Realm.\n if (activeViewTransition) {\n skipTheViewTransition(\n activeViewTransition,\n new DOMException(\n \"Document.startViewTransition() was called\",\n \"AbortError\",\n ),\n );\n activeViewTransition = null;\n }\n\n // 6. Set document\u2019s active view transition to transition.\n // NOTE: The view transition process continues in setup view transition, via perform pending transition operations.\n activeViewTransition = transition;\n window.queueMicrotask(async () => {\n await performPendingOperations();\n });\n\n // 7. Return transition.\n return transition;\n};\n\nconst getActiveViewTranstion = (): ViewTransition | null => {\n return activeViewTransition;\n};\n\nconst performPendingOperations = async () => {\n // 1. If document\u2019s active view transition is not null, then:\n if (activeViewTransition) {\n // 1.1. If document\u2019s active view transition\u2019s phase is \"pending-capture\", then setup view transition for document\u2019s active view transition.\n if (activeViewTransition.phase === \"pending-capture\") {\n await setupViewTransition(activeViewTransition);\n }\n\n // 1.2 Otherwise, if document\u2019s active view transition\u2019s phase is \"animating\", then handle transition frame for document\u2019s active view transition.\n if (activeViewTransition.phase === \"animating\") {\n // @TODO: I think we can diverge from the spec here and replace the call to handleTransitionFrame\n // by a callback that awaits for Promise.allSettled(allAnimations.map(a => a.finished)).\n // When doing so, we could return early here, bypassing the rAF below.\n //\n // However, for this to work correctly it would also require a window.resize listener to\n // make sure the activeViewTransition gets skipped when the VP (and thus SCB changes)\n // This check is also part of handleTransitionFrame.\n await handleTransitionFrame(activeViewTransition);\n }\n\n // @NOTE: The spec says performPendingOperations should be implemented\n // as part of the of the \u201Cupdate the rendering loop\u201D from the html spec.\n // To fake this, We need to do this non-spec compliant call here,\n // to make sure performPendingOperations runs at the next frame.\n requestAnimationFrame(async () => {\n await performPendingOperations();\n });\n }\n};\n\n// @ref https://drafts.csswg.org/css-view-transitions-1/#setup-view-transition-algorithm instead\nconst setupViewTransition = async (transition: ViewTransition) => {\n // 1. Let document be transition\u2019s relevant global object\u2019s associated document.\n // @NOTIMPLEMENTED\n\n // 2. Flush the update callback queue.\n await flushTheUpdateCallbackQueue();\n\n // 3. Capture the old state for transition.\n // If failure is returned, then skip the view transition for transition with an \"InvalidStateError\" DOMException\n // in transition\u2019s relevant Realm, and return.\n // @NOTIMPLEMENTED\n\n // 4. Set document\u2019s rendering suppression for view transitions to true.\n renderingSuppression = true;\n\n // 5. Queue a global task on the DOM manipulation task source, given transition\u2019s relevant global object,\n // to perform the following steps:\n window.queueMicrotask(async () => {\n // 1. If transition\u2019s phase is \"done\", then abort these steps.\n if (transition.phase === \"done\") return;\n\n // 2. schedule the update callback for transition.\n scheduleTheUpdateCallback(transition);\n\n // 3. Flush the update callback queue.\n // @NOTIMPLMENTED \u2013 As per https://github.com/w3c/csswg-drafts/issues/11987, it is noticed that\n // scheduleTheUpdateCallback includes a call to flushTheUpdateCallbackQueue, which makes this call\n // obsolute. Furthermore, when enabling this line right here, there is an assertion that fails.\n // await flushTheUpdateCallbackQueue();\n });\n};\n\n// @ref https://drafts.csswg.org/css-view-transitions-1/#schedule-the-update-callback\nconst scheduleTheUpdateCallback = (transition: ViewTransition) => {\n // 1. Append transition to transition\u2019s relevant settings object\u2019s update callback queue.\n // @TODO: What is \u201Crelevant settings object\u201D?\n // @TODO: Monitor https://github.com/w3c/csswg-drafts/issues/11986\n updateCallbackQueue.push(transition);\n\n // 2. Queue a global task on the DOM manipulation task source, given transition\u2019s relevant global object, to flush the update callback queue.\n window.queueMicrotask(async () => {\n await flushTheUpdateCallbackQueue();\n });\n};\n\n// @ref https://drafts.csswg.org/css-view-transitions-1/#skip-the-view-transition\nconst skipTheViewTransition = async (\n transition: ViewTransition,\n reason?: any,\n) => {\n // 1. Let document be transition\u2019s relevant global object\u2019s associated document.\n // @NOTIMPLEMENTED\n\n // 2. Assert: transition\u2019s phase is not \"done\".\n if (transition.phase === \"done\") {\n throw new Error('Assertion failed: transition\u2019s phase is not \"done\"');\n }\n\n // 3. If transition\u2019s phase is before \"update-callback-called\", then schedule the update callback for transition.\n if (\n possibleViewTransitionPhases.indexOf(transition.phase) <\n possibleViewTransitionPhases.indexOf(\"update-callback-called\")\n ) {\n scheduleTheUpdateCallback(transition);\n }\n\n // 4. Set rendering suppression for view transitions to false.\n renderingSuppression = false;\n\n // 5. If document\u2019s active view transition is transition, Clear view transition transition.\n if (document.activeViewTransition === transition) {\n clearViewTransition(transition);\n }\n\n // 6. Set transition\u2019s phase to \"done\".\n transition.phase = \"done\";\n\n // 7. Reject transition\u2019s ready promise with reason.\n // The ready promise may already be resolved at this point, if skipTransition() is called after we start animating.\n // In that case, this step is a no-op.\n await transition.ready.reject(reason);\n\n // 8. Resolve transition\u2019s finished promise with the result of reacting to transition\u2019s update callback done promise\n // - If the promise was fulfilled, then return undefined.\n // @TODO: Which promise is \u201Cthe promise\u201D? The finished one or the updateCallbackDone one?\n // @TODO: Monitor https://github.com/w3c/csswg-drafts/issues/11990\n await transition.updateCallbackDone.resolve();\n\n if (transition.updateCallbackDone.state === \"fulfilled\") {\n await transition.finished.resolve(transition.updateCallbackDone.value);\n } else {\n await transition.finished.reject();\n }\n\n // @TODO: Do we need to return something else when it is not fullfilled?\n if (transition.finished.state === \"fulfilled\") return undefined;\n};\n\n// @ref https://drafts.csswg.org/css-view-transitions-1/#flush-the-update-callback-queue\n//\n// @TODO: Monitor https://github.com/w3c/csswg-drafts/issues/11986\n// This function takes a document but it doesn\u2019t really do anything\nconst flushTheUpdateCallbackQueue = async () => {\n // 1. For each transition in document\u2019s update callback queue, call the update callback given transition.\n // @TODO: Should we try-catch this?\n for (const transition of updateCallbackQueue) {\n await callTheUpdateCallback(transition);\n }\n\n // 2. Set document\u2019s update callback queue to an empty list.\n updateCallbackQueue = [];\n};\n\n// @ref https://drafts.csswg.org/css-view-transitions-1/#handle-transition-frame\nconst handleTransitionFrame = async (transition: ViewTransition) => {\n // 1. Let document be transition\u2019s relevant global object\u2019s associated document.\n // @NOTIMPLEMENTED\n\n // 2. Let hasActiveAnimations be a boolean, initially false.\n let hasActiveAnimations = false;\n\n // 3. For each element of transition\u2019s transition root pseudo-element\u2019s inclusive descendants:\n // 3.1 For each animation whose timeline is a document timeline associated with document, and contains at least one associated effect whose effect target is element, set hasActiveAnimations to true if any of the following conditions are true:\n // - animation\u2019s play state is paused or running.\n // - document\u2019s pending animation event queue has any events associated with animation.\n // @NOTIMPLEMENTED\n\n // 4. If hasActiveAnimations is false:\n if (hasActiveAnimations === false) {\n // 4.1 Set transition\u2019s phase to \"done\".\n transition.phase = \"done\";\n\n // 4.2 Clear view transition transition.\n clearViewTransition(transition);\n\n // 4.3 Resolve transition\u2019s finished promise.\n await transition.finished.resolve();\n\n // 4.4 Return.\n return;\n }\n\n // 5. If transition\u2019s initial snapshot containing block size is not equal to the snapshot containing block size,\n // then skip the view transition for transition with an \"InvalidStateError\" DOMException in transition\u2019s relevant Realm, and return.\n // @TODO: Implement this\n\n // 6. Update pseudo-element styles for transition.\n // If failure is returned, then skip the view transition for transition with an \"InvalidStateError\" DOMException in transition\u2019s relevant Realm, and return.\n // @NOTIMPLEMENTED\n};\n\n// @ref https://drafts.csswg.org/css-view-transitions-1/#call-the-update-callback\nconst callTheUpdateCallback = async (transition: ViewTransition) => {\n // 1. Assert: transition\u2019s phase is \"done\", or before \"update-callback-called\".\n if (\n !(\n transition.phase === \"done\" ||\n possibleViewTransitionPhases.indexOf(transition.phase) <\n possibleViewTransitionPhases.indexOf(\"update-callback-called\")\n )\n ) {\n debugger;\n throw new Error(\n `Assertion failed: transition\u2019s phase is \"done\", or before \"update-callback-called\". The transition\u2019s phase is \"${transition.phase}\"`,\n );\n }\n\n // 2. If transition\u2019s phase is not \"done\", then set transition\u2019s phase to \"update-callback-called\".\n if (transition.phase !== \"done\") {\n transition.phase = \"update-callback-called\";\n }\n\n // 3. Let callbackPromise be null.\n let callbackPromise = null;\n\n // 4. If transition\u2019s update callback is null, then set callbackPromise to a promise resolved with undefined, in transition\u2019s relevant Realm.\n if (transition.updateCallback === null) {\n callbackPromise = new WatchablePromise((resolve, reject) => {});\n await callbackPromise.resolve(undefined);\n }\n\n // 5. Otherwise, set callbackPromise to the result of invoking transition\u2019s update callback.\n else {\n callbackPromise = new WatchablePromise((resolve, reject) => {});\n await callbackPromise.resolve(await transition.updateCallback());\n }\n\n // 6. Let fulfillSteps be the following steps:\n let fulfillSteps = async () => {\n // 1. Resolve transition\u2019s update callback done promise with undefined.\n await transition.updateCallbackDone.resolve();\n\n // 2. Activate transition.\n await activateViewTransition(transition);\n };\n\n // 7. Let rejectSteps be the following steps given reason:\n let rejectSteps = async (reason: any) => {\n // 1. Reject transition\u2019s update callback done promise with reason.\n await transition.updateCallbackDone.reject(reason);\n\n // 2. If transition\u2019s phase is \"done\", then return.\n if (transition.phase === \"done\") return;\n\n // 3. Mark as handled transition\u2019s ready promise.\n // @ref: https://webidl.spec.whatwg.org/#mark-a-promise-as-handled\n await transition.ready.resolve(); // @TODO: Is this correct?\n\n // 4. Skip the view transition transition with reason.\n await skipTheViewTransition(transition, reason);\n };\n\n // 8. React to callbackPromise with fulfillSteps and rejectSteps.\n // @TODO: Monitor https://github.com/w3c/csswg-drafts/issues/11990\n if (callbackPromise.state === \"fulfilled\") {\n await fulfillSteps();\n } else {\n await rejectSteps(callbackPromise.value);\n }\n\n // 9. To skip a transition after a timeout, the user agent may perform the following steps in parallel:\n // @TODO\n\n // 9.1. Wait for an implementation-defined duration.\n // @TODO\n\n // 9.2. Queue a global task on the DOM manipulation task source, given transition\u2019s relevant global object, to perform the following steps:\n // @TODO\n\n // 9.2.1. If transition\u2019s phase is \"done\", then return.\n // @TODO\n\n // 9.2.2. Skip transition with a \"TimeoutError\" DOMException.\n // @TODO\n};\n\n// @ref https://drafts.csswg.org/css-view-transitions-1/#activate-view-transition\nconst activateViewTransition = async (transition: ViewTransition) => {\n // 1. If transition\u2019s phase is \"done\", then return.\n if (transition.phase === \"done\") return;\n\n // 2. Set transition\u2019s relevant global object\u2019s associated document\u2019s rendering suppression for view transitions to false.\n renderingSuppression = false;\n\n // 3. If transition\u2019s initial snapshot containing block size is not equal to the snapshot containing block size, then skip transition with an \"InvalidStateError\" DOMException in transition\u2019s relevant Realm, and return.\n // @TODO: Implement this\n\n // 4. Capture the new state for transition.\n // If failure is returned, then skip transition with an \"InvalidStateError\" DOMException in transition\u2019s relevant Realm, and return.\n // @NOTIMPLEMENTED\n\n // 5. For each capturedElement of transition\u2019s named elements' values:\n // @NOTIMPLEMENTED\n\n // 6. Setup transition pseudo-elements for transition.\n // @NOTIMPLEMENTED\n\n // 7. Update pseudo-element styles for transition.\n // If failure is returned, then skip the view transition for transition with an \"InvalidStateError\" DOMException in transition\u2019s relevant Realm, and return.\n // @NOTIMPLEMENTED\n\n // 8. Set transition\u2019s phase to \"animating\".\n transition.phase = \"animating\";\n\n // 9. Resolve transition\u2019s ready promise.\n await transition.ready.resolve();\n};\n\n// @ref https://drafts.csswg.org/css-view-transitions-1/#clear-view-transition\nconst clearViewTransition = (transition: ViewTransition) => {\n // 1. Let document be transition\u2019s relevant global object\u2019s associated document.\n // @NOTIMPLEMENTED\n\n // 2. Assert: document\u2019s active view transition is transition.\n if (transition !== activeViewTransition) {\n throw new Error(\n \"Assertion failed: transition !== document.activeViewTransition\",\n );\n }\n\n // 3. For each capturedElement of transition\u2019s named elements' values:\n // @NOTIMPLEMENTED\n\n // 4. Set document\u2019s show view transition tree to false.\n // @NOTIMPLEMENTED\n\n // 5. Set document\u2019s active view transition to null.\n activeViewTransition = null;\n};\n\nexport { startViewTransition, getActiveViewTranstion, skipTheViewTransition };\n", "/**\n * Copyright 2026 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { startViewTransition, getActiveViewTranstion } from \"./same-document\";\n\nimport { ViewTransition } from \"./classes/ViewTransition\";\nimport { ViewTransitionTypeSet } from \"./classes/ViewTransitionTypeSet\";\nimport { RegistrationTrigger } from \"./types\";\n\nlet registered = false;\n\n// Store native implementations if they exist\nconst nativeImplementations = {\n ViewTransition: window.ViewTransition,\n ViewTransitionTypeSet: (window as any).ViewTransitionTypeSet,\n startViewTransition: document.startViewTransition,\n activeViewTransition: Reflect.getOwnPropertyDescriptor(\n Document.prototype,\n \"activeViewTransition\",\n ),\n};\n\nconst defaultRegistrationTrigger = {\n requireTypes: true,\n forced: false,\n};\n\nconst register = (\n registrationTrigger: RegistrationTrigger = defaultRegistrationTrigger,\n): void => {\n if (registered) return;\n\n const requireTypesSupport = registrationTrigger.requireTypes;\n const forceRegister = registrationTrigger.forced;\n\n const hasSameDocumentViewTransitionsSupport = !!document.startViewTransition;\n const hasViewTransitionTypesSupport =\n hasSameDocumentViewTransitionsSupport &&\n nativeImplementations.ViewTransition &&\n \"types\" in nativeImplementations.ViewTransition.prototype;\n\n const needsRegistration =\n !hasSameDocumentViewTransitionsSupport ||\n (hasSameDocumentViewTransitionsSupport &&\n !hasViewTransitionTypesSupport &&\n requireTypesSupport) ||\n forceRegister;\n\n if (needsRegistration) {\n Reflect.defineProperty(window, \"ViewTransition\", {\n value: ViewTransition,\n configurable: true,\n });\n\n Reflect.defineProperty(window, \"ViewTransitionTypeSet\", {\n value: ViewTransitionTypeSet,\n configurable: true,\n });\n\n Reflect.defineProperty(document, \"activeViewTransition\", {\n get: getActiveViewTranstion,\n configurable: true,\n });\n\n Reflect.defineProperty(document, \"startViewTransition\", {\n value: startViewTransition,\n configurable: true,\n writable: true,\n });\n\n registered = true;\n\n console.info(\"Support for Same-Document View Transitions is now mocked\");\n }\n};\n\nconst unregister = (): void => {\n if (!registered) return;\n\n if (nativeImplementations.ViewTransition) {\n Reflect.defineProperty(window, \"ViewTransition\", {\n value: nativeImplementations.ViewTransition,\n });\n } else {\n Reflect.deleteProperty(window, \"ViewTransition\");\n }\n\n if (nativeImplementations.ViewTransitionTypeSet) {\n Reflect.defineProperty(window, \"ViewTransitionTypeSet\", {\n value: nativeImplementations.ViewTransitionTypeSet,\n });\n } else {\n Reflect.deleteProperty(window, \"ViewTransitionTypeSet\");\n }\n\n if (nativeImplementations.activeViewTransition) {\n Reflect.defineProperty(\n document,\n \"activeViewTransition\",\n nativeImplementations.activeViewTransition,\n );\n } else {\n Reflect.deleteProperty(document, \"activeViewTransition\");\n }\n\n if (nativeImplementations.startViewTransition) {\n document.startViewTransition = nativeImplementations.startViewTransition;\n } else {\n Reflect.deleteProperty(document, \"startViewTransition\");\n }\n\n registered = false;\n\n console.info(\n \"Support for Same-Document View Transitions is no longer mocked\",\n );\n};\n\nexport { register, unregister };\n"],
|
|
5
|
+
"mappings": ";AAAA,IA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;AAAA,IAC/B,CAAC;AAAA,EACH,OAAO;AACL,YAAQ,eAAe,QAAQ,gBAAgB;AAAA,EACjD;AAEA,MAAI,sBAAsB,uBAAuB;AAC/C,YAAQ,eAAe,QAAQ,yBAAyB;AAAA,MACtD,OAAO,sBAAsB;AAAA,IAC/B,CAAC;AAAA,EACH,OAAO;AACL,YAAQ,eAAe,QAAQ,uBAAuB;AAAA,EACxD;AAEA,MAAI,sBAAsB,sBAAsB;AAC9C,YAAQ;AAAA,MACN;AAAA,MACA;AAAA,MACA,sBAAsB;AAAA,IACxB;AAAA,EACF,OAAO;AACL,YAAQ,eAAe,UAAU,sBAAsB;AAAA,EACzD;AAEA,MAAI,sBAAsB,qBAAqB;AAC7C,aAAS,sBAAsB,sBAAsB;AAAA,EACvD,OAAO;AACL,YAAQ,eAAe,UAAU,qBAAqB;AAAA,EACxD;AAEA,eAAa;AAEb,UAAQ;AAAA,IACN;AAAA,EACF;AACF;",
|
|
6
|
+
"names": ["ViewTransitionTypeSet", "ViewTransition", "ViewTransitionTypeSet", "ViewTransition", "ViewTransition", "ViewTransitionTypeSet"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "view-transitions-mock",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Mock support for Same-Document View Transitions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
],
|
|
11
11
|
"scripts": {
|
|
12
12
|
"clean": "rm -rf ./dist",
|
|
13
|
-
"lint": "prettier --check '{src,
|
|
14
|
-
"format": "prettier --write '{src,
|
|
13
|
+
"lint": "prettier --check '{src,tests,demo}/**/*.{ts,tsx,js,jsx}'",
|
|
14
|
+
"format": "prettier --write '{src,tests,demo}/**/*.{ts,tsx,js,jsx}'",
|
|
15
15
|
"prebuild": "npm run clean",
|
|
16
16
|
"build": "esbuild src/index.ts --sourcemap --bundle --outfile=dist/index.js --platform=browser --format=esm && tsc --declaration --emitDeclarationOnly --outFile dist/index.d.ts",
|
|
17
17
|
"start": "concurrently --kill-others 'npm run watch' 'npm run serve'",
|
|
@@ -20,9 +20,11 @@
|
|
|
20
20
|
"dev": "npm run start",
|
|
21
21
|
"prepack": "npm run require-license-headers && npm run require-pristine-tree && npm run test",
|
|
22
22
|
"prepublish": "npm run build",
|
|
23
|
-
"
|
|
24
|
-
"
|
|
23
|
+
"type-check": "tsc --noEmit",
|
|
24
|
+
"pretest": "npm run build && npx playwright install --with-deps",
|
|
25
|
+
"test": "playwright test",
|
|
25
26
|
"preversion": "npm run require-license-headers && npm run require-pristine-tree && npm run test",
|
|
27
|
+
"prepare": "husky install",
|
|
26
28
|
"require-license-headers": "addlicense -check -f=./LICENSE src",
|
|
27
29
|
"require-pristine-tree": "exit $(git status --porcelain | wc -l)",
|
|
28
30
|
"add-license-headers": "addlicense -c 'Google LLC' -l apache -s=only -f=./LICENSE ."
|
|
@@ -46,9 +48,15 @@
|
|
|
46
48
|
},
|
|
47
49
|
"homepage": "https://github.com/GoogleChromeLabs/view-transitions-mock#readme",
|
|
48
50
|
"devDependencies": {
|
|
51
|
+
"@playwright/test": "^1.42.1",
|
|
52
|
+
"@types/node": "^25.0.8",
|
|
49
53
|
"concurrently": "^9.2.1",
|
|
50
54
|
"esbuild": "^0.27.2",
|
|
55
|
+
"husky": "^8.0.0",
|
|
51
56
|
"prettier": "^3.4.1",
|
|
52
57
|
"typescript": "^5.7.2"
|
|
58
|
+
},
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"watchable-promise": "^2.1.3"
|
|
53
61
|
}
|
|
54
62
|
}
|