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
|
import * as sort from './sort'
import * as format from './format'
import * as maths from './math'
import './hidpi-canvas'
const is_iphone = !!((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)))
const is_ipad = !!(navigator.userAgent.match(/iPad/i))
const is_android = !!(navigator.userAgent.match(/Android/i))
const is_mobile = is_iphone || is_ipad || is_android
const is_desktop = ! is_mobile;
const htmlClassList = document.body.parentNode.classList
htmlClassList.add(is_desktop ? 'desktop' : 'mobile')
htmlClassList.remove('loading')
// window.debug = false
const allProgress = (promises, progress_cb) => {
let d = 0
progress_cb(0, 0, promises.length)
promises.forEach((p) => {
p.then((s) => {
d += 1
progress_cb(Math.floor((d * 100) / promises.length), d, promises.length)
return s
})
})
return Promise.all(promises)
}
document.body.style.backgroundImage = 'linear-gradient(' + (maths.randint(40)+40) + 'deg, #fde, #ffe)'
const fieldSet = defaultFields => fields => {
if (fields) {
if (fields instanceof Set) {
return fields
}
return new Set(fields.split(' '))
}
return defaultFields
}
export default {
...maths,
...format,
sort,
allProgress, fieldSet,
is_iphone, is_ipad, is_android, is_mobile, is_desktop,
}
|