@@ -5,6 +5,7 @@ export { sim }
5
5
type ClickAction = {
6
6
type : "click"
7
7
selector : string
8
+ offset ?: number
8
9
}
9
10
type ScrollAction = {
10
11
type : "scroll"
@@ -21,7 +22,8 @@ function scroll(action: ScrollAction, document: Document) {
21
22
}
22
23
23
24
function click ( action : ClickAction , document : Document ) {
24
- const element = document . querySelector ( action . selector ) !
25
+ const { selector, offset = 100 } = action
26
+ const element = document . querySelector ( selector ) !
25
27
// userEvent.click(element)
26
28
27
29
const elemRect = element . getBoundingClientRect ( )
@@ -32,8 +34,8 @@ function click(action: ClickAction, document: Document) {
32
34
window . pageXOffset +
33
35
( 2 * elemRect . width ) / 3
34
36
35
- const startTop = offsetTop + 200
36
- const startLeft = offsetLeft + 200
37
+ const startTop = offsetTop + offset
38
+ const startLeft = offsetLeft + offset
37
39
const cursor = createCursor ( )
38
40
cursor . style . position = "absolute"
39
41
cursor . style . top = startTop + "px"
@@ -47,20 +49,45 @@ function click(action: ClickAction, document: Document) {
47
49
requestAnimationFrame ( ( ) =>
48
50
requestAnimationFrame ( ( ) => {
49
51
// console.log(element.offsetLeft)
50
- cursor . style . transform = `translate(${ - 200 } px, ${ - 200 } px) scale(1)`
52
+ cursor . style . transform = `translate(${ - offset } px, ${ - offset } px) scale(1)`
51
53
cursor . style . opacity = "1"
52
- cursor . style . scale = "1"
53
54
} )
54
55
)
55
56
56
57
cursor . addEventListener (
57
58
"transitionend" ,
58
59
async ( ) => {
59
60
userEvent . click ( element )
60
- cursor . style . opacity = "0"
61
- cursor . addEventListener ( "transitionend" , ( ) =>
62
- cursor . parentElement ! . removeChild ( cursor )
61
+
62
+ const circle = document . createElementNS (
63
+ "http://www.w3.org/2000/svg" ,
64
+ "circle"
63
65
)
66
+ circle . setAttribute ( "cx" , "8" )
67
+ circle . setAttribute ( "cy" , "5" )
68
+ circle . setAttribute ( "fill" , "currentColor" )
69
+ circle . setAttribute ( "r" , "3" )
70
+ circle . style . opacity = "0.99"
71
+ circle . style . transformOrigin = "8px 5px"
72
+ circle . style . transition =
73
+ "transform 300ms, opacity 300ms"
74
+
75
+ const svg = cursor . firstChild as SVGElement
76
+
77
+ svg . innerHTML = ""
78
+ svg . appendChild ( circle )
79
+
80
+ requestAnimationFrame ( ( ) =>
81
+ requestAnimationFrame ( ( ) => {
82
+ circle . style . opacity = "0"
83
+ circle . style . transform = `scale(10)`
84
+ } )
85
+ )
86
+
87
+ circle . addEventListener ( "transitionend" , ( ) => {
88
+ if ( cursor . parentElement )
89
+ cursor . parentElement . removeChild ( cursor )
90
+ } )
64
91
} ,
65
92
{ once : true }
66
93
)
@@ -82,7 +109,7 @@ function createCursor() {
82
109
const div = document . createElement ( "div" )
83
110
div . style . color = "#7387c4"
84
111
div . innerHTML = `<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
85
- style="display:block; filter: drop-shadow(0px 0px 1px rgba(0, 0, 0, .4))"
112
+ style="display:block; overflow:visible; filter: drop-shadow(0px 0px 1px rgba(0, 0, 0, .4))"
86
113
viewBox="8 5 28 28" enable-background="new 0 0 28 28" xml:space="preserve" height="28px" width="28px">
87
114
<polygon fill="#FFFFFF" points="8.2,20.9 8.2,4.9 19.8,16.5 13,16.5 12.6,16.6 "/>
88
115
<polygon fill="#FFFFFF" points="17.3,21.6 13.7,23.1 9,12 12.7,10.5 "/>
0 commit comments