@rokkit/helpers 1.0.0-next.145 → 1.0.0-next.147
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/package.json +1 -1
- package/src/mocks/animate.js +23 -4
package/package.json
CHANGED
package/src/mocks/animate.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { vi } from 'vitest'
|
|
2
2
|
|
|
3
|
-
// Mock the animate function
|
|
3
|
+
// Mock the animate function and getAnimations (used by Svelte's flip/transition)
|
|
4
|
+
if (!global.Element.prototype.getAnimations) {
|
|
5
|
+
global.Element.prototype.getAnimations = vi.fn().mockReturnValue([])
|
|
6
|
+
}
|
|
7
|
+
|
|
4
8
|
if (!global.Element.prototype.animate) {
|
|
5
9
|
global.Element.prototype.animate = vi.fn().mockImplementation(() => {
|
|
10
|
+
// Use getter/setter so Svelte's `animation.onfinish = callback` assignment
|
|
11
|
+
// immediately queues the callback, simulating instant animation completion.
|
|
12
|
+
let _onfinish = null
|
|
13
|
+
let _oncancel = null
|
|
6
14
|
return {
|
|
7
15
|
play: vi.fn(),
|
|
8
16
|
pause: vi.fn(),
|
|
@@ -10,12 +18,23 @@ if (!global.Element.prototype.animate) {
|
|
|
10
18
|
cancel: vi.fn(),
|
|
11
19
|
reverse: vi.fn(),
|
|
12
20
|
persist: vi.fn(),
|
|
13
|
-
onfinish
|
|
14
|
-
|
|
21
|
+
get onfinish() {
|
|
22
|
+
return _onfinish
|
|
23
|
+
},
|
|
24
|
+
set onfinish(cb) {
|
|
25
|
+
_onfinish = cb
|
|
26
|
+
if (cb) queueMicrotask(() => cb())
|
|
27
|
+
},
|
|
28
|
+
get oncancel() {
|
|
29
|
+
return _oncancel
|
|
30
|
+
},
|
|
31
|
+
set oncancel(cb) {
|
|
32
|
+
_oncancel = cb
|
|
33
|
+
},
|
|
15
34
|
currentTime: 0,
|
|
16
35
|
startTime: 0,
|
|
17
36
|
playbackRate: 1,
|
|
18
|
-
playState: '
|
|
37
|
+
playState: 'finished',
|
|
19
38
|
finished: Promise.resolve(),
|
|
20
39
|
effect: {
|
|
21
40
|
getTiming: vi.fn(),
|