-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathenv.js
131 lines (119 loc) · 3.41 KB
/
env.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/* global MutationObserver */
// can we use __proto__?
export const hasProto = '__proto__' in {}
// Browser environment sniffing
export const inBrowser =
typeof window !== 'undefined' &&
Object.prototype.toString.call(window) !== '[object Object]'
// detect devtools
export const devtools = inBrowser && window.__VUE_DEVTOOLS_GLOBAL_HOOK__
// UA sniffing for working around browser-specific quirks
const UA = inBrowser && window.navigator.userAgent.toLowerCase()
export const isIE9 = UA && UA.indexOf('msie 9.0') > 0
export const isAndroid = UA && UA.indexOf('android') > 0
export const isIos = UA && /(iphone|ipad|ipod|ios)/i.test(UA)
export const isWechat = UA && UA.indexOf('micromessenger') > 0
let transitionProp
let transitionEndEvent
let animationProp
let animationEndEvent
// Transition property/event sniffing
if (inBrowser && !isIE9) {
const isWebkitTrans =
window.ontransitionend === undefined &&
window.onwebkittransitionend !== undefined
const isWebkitAnim =
window.onanimationend === undefined &&
window.onwebkitanimationend !== undefined
transitionProp = isWebkitTrans
? 'WebkitTransition'
: 'transition'
transitionEndEvent = isWebkitTrans
? 'webkitTransitionEnd'
: 'transitionend'
animationProp = isWebkitAnim
? 'WebkitAnimation'
: 'animation'
animationEndEvent = isWebkitAnim
? 'webkitAnimationEnd'
: 'animationend'
}
export {
transitionProp,
transitionEndEvent,
animationProp,
animationEndEvent
}
/**
* Defer a task to execute it asynchronously. Ideally this
* should be executed as a microtask, so we leverage
* MutationObserver if it's available, and fallback to
* setTimeout(0).
*
* @param {Function} cb
* @param {Object} ctx
*/
export const nextTick = (function () {
var callbacks = []
var pending = false
var timerFunc
function nextTickHandler () {
pending = false
var copies = callbacks.slice(0)
callbacks = []
for (var i = 0; i < copies.length; i++) {
copies[i]()
}
}
/* istanbul ignore if */
if (typeof MutationObserver !== 'undefined' && !(isWechat && isIos)) {
var counter = 1
var observer = new MutationObserver(nextTickHandler)
var textNode = document.createTextNode(counter)
observer.observe(textNode, {
characterData: true
})
timerFunc = function () {
counter = (counter + 1) % 2
textNode.data = counter
}
} else {
// webpack attempts to inject a shim for setImmediate
// if it is used as a global, so we have to work around that to
// avoid bundling unnecessary code.
const context = inBrowser
? window
: typeof global !== 'undefined' ? global : {}
timerFunc = context.setImmediate || setTimeout
}
return function (cb, ctx) {
var func = ctx
? function () { cb.call(ctx) }
: cb
callbacks.push(func)
if (pending) return
pending = true
timerFunc(nextTickHandler, 0)
}
})()
let _Set
/* istanbul ignore if */
if (typeof Set !== 'undefined' && Set.toString().match(/native code/)) {
// use native Set when available.
_Set = Set
} else {
// a non-standard Set polyfill that only works with primitive keys.
_Set = function () {
this.set = Object.create(null)
}
_Set.prototype.has = function (key) {
return this.set[key] !== undefined
}
_Set.prototype.add = function (key) {
this.set[key] = 1
}
_Set.prototype.clear = function () {
this.set = Object.create(null)
}
}
export { _Set }