Skip to content

Commit aba16db

Browse files
committed
feat: update css-animation
1 parent 34876b5 commit aba16db

File tree

3 files changed

+64
-15
lines changed

3 files changed

+64
-15
lines changed

components/_util/css-animation/Event.js

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
1-
const EVENT_NAME_MAP = {
1+
const START_EVENT_NAME_MAP = {
2+
transitionstart: {
3+
transition: 'transitionstart',
4+
WebkitTransition: 'webkitTransitionStart',
5+
MozTransition: 'mozTransitionStart',
6+
OTransition: 'oTransitionStart',
7+
msTransition: 'MSTransitionStart',
8+
},
9+
10+
animationstart: {
11+
animation: 'animationstart',
12+
WebkitAnimation: 'webkitAnimationStart',
13+
MozAnimation: 'mozAnimationStart',
14+
OAnimation: 'oAnimationStart',
15+
msAnimation: 'MSAnimationStart',
16+
},
17+
}
18+
19+
const END_EVENT_NAME_MAP = {
220
transitionend: {
321
transition: 'transitionend',
422
WebkitTransition: 'webkitTransitionEnd',
@@ -16,31 +34,39 @@ const EVENT_NAME_MAP = {
1634
},
1735
}
1836

37+
const startEvents = []
1938
const endEvents = []
2039

2140
function detectEvents () {
2241
const testEl = document.createElement('div')
2342
const style = testEl.style
2443

2544
if (!('AnimationEvent' in window)) {
26-
delete EVENT_NAME_MAP.animationend.animation
45+
delete START_EVENT_NAME_MAP.animationstart.animation
46+
delete END_EVENT_NAME_MAP.animationend.animation
2747
}
2848

2949
if (!('TransitionEvent' in window)) {
30-
delete EVENT_NAME_MAP.transitionend.transition
50+
delete START_EVENT_NAME_MAP.transitionstart.transition
51+
delete END_EVENT_NAME_MAP.transitionend.transition
3152
}
3253

33-
for (const baseEventName in EVENT_NAME_MAP) {
34-
if (EVENT_NAME_MAP.hasOwnProperty(baseEventName)) {
35-
const baseEvents = EVENT_NAME_MAP[baseEventName]
36-
for (const styleName in baseEvents) {
37-
if (styleName in style) {
38-
endEvents.push(baseEvents[styleName])
39-
break
54+
function process (EVENT_NAME_MAP, events) {
55+
for (const baseEventName in EVENT_NAME_MAP) {
56+
if (EVENT_NAME_MAP.hasOwnProperty(baseEventName)) {
57+
const baseEvents = EVENT_NAME_MAP[baseEventName]
58+
for (const styleName in baseEvents) {
59+
if (styleName in style) {
60+
events.push(baseEvents[styleName])
61+
break
62+
}
4063
}
4164
}
4265
}
4366
}
67+
68+
process(START_EVENT_NAME_MAP, startEvents)
69+
process(END_EVENT_NAME_MAP, endEvents)
4470
}
4571

4672
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
@@ -56,6 +82,31 @@ function removeEventListener (node, eventName, eventListener) {
5682
}
5783

5884
const TransitionEvents = {
85+
// Start events
86+
startEvents,
87+
88+
addStartEventListener (node, eventListener) {
89+
if (startEvents.length === 0) {
90+
window.setTimeout(eventListener, 0)
91+
return
92+
}
93+
startEvents.forEach((startEvent) => {
94+
addEventListener(node, startEvent, eventListener)
95+
})
96+
},
97+
98+
removeStartEventListener (node, eventListener) {
99+
if (startEvents.length === 0) {
100+
return
101+
}
102+
startEvents.forEach((startEvent) => {
103+
removeEventListener(node, startEvent, eventListener)
104+
})
105+
},
106+
107+
// End events
108+
endEvents,
109+
59110
addEndEventListener (node, eventListener) {
60111
if (endEvents.length === 0) {
61112
window.setTimeout(eventListener, 0)
@@ -66,8 +117,6 @@ const TransitionEvents = {
66117
})
67118
},
68119

69-
endEvents,
70-
71120
removeEndEventListener (node, eventListener) {
72121
if (endEvents.length === 0) {
73122
return
@@ -79,4 +128,3 @@ const TransitionEvents = {
79128
}
80129

81130
export default TransitionEvents
82-

components/_util/css-animation/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// https://github.com/yiminghe/css-animation 1.5.0
2+
13
import Event from './Event'
24
import classes from 'component-classes'
35
import { requestAnimationTimeout, cancelAnimationTimeout } from '../requestAnimationTimeout'

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@
124124
"minimist": "^1.2.0",
125125
"mkdirp": "^0.5.1",
126126
"mockdate": "^2.0.2",
127-
"moment-timezone": "^0.5.17",
128127
"nprogress": "^0.2.0",
129128
"postcss": "^6.0.20",
130129
"postcss-loader": "^2.1.2",
@@ -184,4 +183,4 @@
184183
"vue-ref": "^1.0.3",
185184
"warning": "^3.0.0"
186185
}
187-
}
186+
}

0 commit comments

Comments
 (0)