@vpmedia/phaser 1.0.1 → 1.0.2
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/dist/phaser.cjs.LICENSE.txt +1 -1
- package/dist/phaser.js.LICENSE.txt +1 -1
- package/package.json +2 -3
- package/src/index.js +99 -0
- package/src/phaser/core/animation.js +355 -0
- package/src/phaser/core/animation_manager.js +238 -0
- package/src/phaser/core/animation_parser.js +130 -0
- package/src/phaser/core/array_set.js +108 -0
- package/src/phaser/core/cache.js +558 -0
- package/src/phaser/core/const.js +106 -0
- package/src/phaser/core/device.js +67 -0
- package/src/phaser/core/device_util.js +386 -0
- package/src/phaser/core/dom.js +207 -0
- package/src/phaser/core/event_manager.js +243 -0
- package/src/phaser/core/factory.js +74 -0
- package/src/phaser/core/frame.js +75 -0
- package/src/phaser/core/frame_data.js +84 -0
- package/src/phaser/core/frame_util.js +31 -0
- package/src/phaser/core/game.js +412 -0
- package/src/phaser/core/input.js +401 -0
- package/src/phaser/core/input_button.js +102 -0
- package/src/phaser/core/input_handler.js +687 -0
- package/src/phaser/core/input_mouse.js +289 -0
- package/src/phaser/core/input_mspointer.js +197 -0
- package/src/phaser/core/input_pointer.js +427 -0
- package/src/phaser/core/input_touch.js +157 -0
- package/src/phaser/core/loader.js +946 -0
- package/src/phaser/core/loader_parser.js +105 -0
- package/src/phaser/core/raf.js +46 -0
- package/src/phaser/core/raf_fb.js +75 -0
- package/src/phaser/core/raf_to.js +34 -0
- package/src/phaser/core/scale_manager.js +806 -0
- package/src/phaser/core/scene.js +66 -0
- package/src/phaser/core/scene_manager.js +310 -0
- package/src/phaser/core/signal.js +175 -0
- package/src/phaser/core/signal_binding.js +69 -0
- package/src/phaser/core/sound.js +538 -0
- package/src/phaser/core/sound_manager.js +365 -0
- package/src/phaser/core/stage.js +108 -0
- package/src/phaser/core/time.js +203 -0
- package/src/phaser/core/timer.js +276 -0
- package/src/phaser/core/timer_event.js +21 -0
- package/src/phaser/core/tween.js +329 -0
- package/src/phaser/core/tween_data.js +258 -0
- package/src/phaser/core/tween_easing.js +316 -0
- package/src/phaser/core/tween_manager.js +185 -0
- package/src/phaser/core/world.js +18 -0
- package/src/phaser/display/bitmap_text.js +322 -0
- package/src/phaser/display/button.js +194 -0
- package/src/phaser/display/canvas/buffer.js +36 -0
- package/src/phaser/display/canvas/graphics.js +227 -0
- package/src/phaser/display/canvas/masker.js +39 -0
- package/src/phaser/display/canvas/pool.js +121 -0
- package/src/phaser/display/canvas/renderer.js +123 -0
- package/src/phaser/display/canvas/tinter.js +141 -0
- package/src/phaser/display/canvas/util.js +151 -0
- package/src/phaser/display/display_object.js +597 -0
- package/src/phaser/display/graphics.js +723 -0
- package/src/phaser/display/graphics_data.js +27 -0
- package/src/phaser/display/graphics_data_util.js +14 -0
- package/src/phaser/display/group.js +227 -0
- package/src/phaser/display/image.js +288 -0
- package/src/phaser/display/sprite_batch.js +15 -0
- package/src/phaser/display/sprite_util.js +248 -0
- package/src/phaser/display/text.js +1089 -0
- package/src/phaser/display/webgl/abstract_filter.js +25 -0
- package/src/phaser/display/webgl/base_texture.js +68 -0
- package/src/phaser/display/webgl/blend_manager.js +35 -0
- package/src/phaser/display/webgl/earcut.js +647 -0
- package/src/phaser/display/webgl/earcut_node.js +28 -0
- package/src/phaser/display/webgl/fast_sprite_batch.js +242 -0
- package/src/phaser/display/webgl/filter_manager.js +46 -0
- package/src/phaser/display/webgl/filter_texture.js +61 -0
- package/src/phaser/display/webgl/graphics.js +618 -0
- package/src/phaser/display/webgl/graphics_data.js +42 -0
- package/src/phaser/display/webgl/mask_manager.js +36 -0
- package/src/phaser/display/webgl/render_texture.js +81 -0
- package/src/phaser/display/webgl/renderer.js +234 -0
- package/src/phaser/display/webgl/shader/complex.js +74 -0
- package/src/phaser/display/webgl/shader/fast.js +97 -0
- package/src/phaser/display/webgl/shader/normal.js +225 -0
- package/src/phaser/display/webgl/shader/primitive.js +72 -0
- package/src/phaser/display/webgl/shader/strip.js +77 -0
- package/src/phaser/display/webgl/shader_manager.js +89 -0
- package/src/phaser/display/webgl/sprite_batch.js +320 -0
- package/src/phaser/display/webgl/stencil_manager.js +170 -0
- package/src/phaser/display/webgl/texture.js +117 -0
- package/src/phaser/display/webgl/texture_util.js +32 -0
- package/src/phaser/display/webgl/util.js +74 -0
- package/src/phaser/geom/circle.js +186 -0
- package/src/phaser/geom/ellipse.js +65 -0
- package/src/phaser/geom/line.js +190 -0
- package/src/phaser/geom/matrix.js +147 -0
- package/src/phaser/geom/point.js +164 -0
- package/src/phaser/geom/polygon.js +141 -0
- package/src/phaser/geom/rectangle.js +306 -0
- package/src/phaser/geom/rounded_rectangle.js +36 -0
- package/src/phaser/geom/util/circle.js +115 -0
- package/src/phaser/geom/util/ellipse.js +30 -0
- package/src/phaser/geom/util/line.js +130 -0
- package/src/phaser/geom/util/matrix.js +48 -0
- package/src/phaser/geom/util/point.js +276 -0
- package/src/phaser/geom/util/polygon.js +24 -0
- package/src/phaser/geom/util/rectangle.js +212 -0
- package/src/phaser/geom/util/rounded_rectangle.js +28 -0
- package/src/phaser/util/math.js +279 -0
- package/src/phaser/util/string.js +26 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author Andras Csizmadia <andras@vpmedia.hu>
|
|
3
|
+
* @author Richard Davey <rich@photonstorm.com>
|
|
4
|
+
* @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export default class {
|
|
8
|
+
|
|
9
|
+
constructor() {
|
|
10
|
+
this.deviceReadyAt = 0;
|
|
11
|
+
this.desktop = false;
|
|
12
|
+
this.iOS = false;
|
|
13
|
+
this.iOSVersion = 0;
|
|
14
|
+
this.cocoonJS = false;
|
|
15
|
+
this.cocoonJSApp = false;
|
|
16
|
+
this.cordova = false;
|
|
17
|
+
this.node = false;
|
|
18
|
+
this.android = false;
|
|
19
|
+
this.chromeOS = false;
|
|
20
|
+
this.linux = false;
|
|
21
|
+
this.macOS = false;
|
|
22
|
+
this.windows = false;
|
|
23
|
+
this.windowsPhone = false;
|
|
24
|
+
this.canvas = false;
|
|
25
|
+
this.pointerLock = false;
|
|
26
|
+
this.touch = false;
|
|
27
|
+
this.mspointer = false;
|
|
28
|
+
this.wheelEvent = null;
|
|
29
|
+
this.chrome = false;
|
|
30
|
+
this.chromeVersion = 0;
|
|
31
|
+
this.firefox = false;
|
|
32
|
+
this.firefoxVersion = 0;
|
|
33
|
+
this.ie = false;
|
|
34
|
+
this.ieVersion = 0;
|
|
35
|
+
this.trident = false;
|
|
36
|
+
this.tridentVersion = 0;
|
|
37
|
+
this.edge = false;
|
|
38
|
+
this.mobileSafari = false;
|
|
39
|
+
this.safari = false;
|
|
40
|
+
this.safariVersion = 0;
|
|
41
|
+
this.webApp = false;
|
|
42
|
+
this.silk = false;
|
|
43
|
+
this.audioData = false;
|
|
44
|
+
this.webAudio = false;
|
|
45
|
+
this.ogg = false;
|
|
46
|
+
this.opus = false;
|
|
47
|
+
this.mp3 = false;
|
|
48
|
+
this.wav = false;
|
|
49
|
+
this.m4a = false;
|
|
50
|
+
this.webm = false;
|
|
51
|
+
this.dolby = false;
|
|
52
|
+
this.oggVideo = false;
|
|
53
|
+
this.h264Video = false;
|
|
54
|
+
this.mp4Video = false;
|
|
55
|
+
this.webmVideo = false;
|
|
56
|
+
this.vp9Video = false;
|
|
57
|
+
this.hlsVideo = false;
|
|
58
|
+
this.iPhone = false;
|
|
59
|
+
this.iPad = false;
|
|
60
|
+
this.pixelRatio = 1;
|
|
61
|
+
this.fullscreen = false;
|
|
62
|
+
this.requestFullscreen = '';
|
|
63
|
+
this.cancelFullscreen = '';
|
|
64
|
+
this.fullscreenKeyboard = false;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
}
|
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author Andras Csizmadia <andras@vpmedia.hu>
|
|
3
|
+
* @author Richard Davey <rich@photonstorm.com>
|
|
4
|
+
* @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @param device
|
|
10
|
+
* @param type
|
|
11
|
+
*/
|
|
12
|
+
export function canPlayAudio(device, type) {
|
|
13
|
+
if (type === 'mp3' && device.mp3) {
|
|
14
|
+
return true;
|
|
15
|
+
} else if (type === 'ogg' && (device.ogg || device.opus)) {
|
|
16
|
+
return true;
|
|
17
|
+
} else if (type === 'm4a' && device.m4a) {
|
|
18
|
+
return true;
|
|
19
|
+
} else if (type === 'opus' && device.opus) {
|
|
20
|
+
return true;
|
|
21
|
+
} else if (type === 'wav' && device.wav) {
|
|
22
|
+
return true;
|
|
23
|
+
} else if (type === 'webm' && device.webm) {
|
|
24
|
+
return true;
|
|
25
|
+
} else if (type === 'mp4' && device.dolby) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
*
|
|
33
|
+
* @param device
|
|
34
|
+
* @param type
|
|
35
|
+
*/
|
|
36
|
+
export function canPlayVideo(device, type) {
|
|
37
|
+
if (type === 'webm' && (device.webmVideo || device.vp9Video)) {
|
|
38
|
+
return true;
|
|
39
|
+
} else if (type === 'mp4' && (device.mp4Video || device.h264Video)) {
|
|
40
|
+
return true;
|
|
41
|
+
} else if ((type === 'ogg' || type === 'ogv') && device.oggVideo) {
|
|
42
|
+
return true;
|
|
43
|
+
} else if (type === 'mpeg' && device.hlsVideo) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
*
|
|
51
|
+
* @param device
|
|
52
|
+
*/
|
|
53
|
+
export function checkOS(device) {
|
|
54
|
+
const ua = navigator.userAgent;
|
|
55
|
+
if (/Android/.test(ua)) {
|
|
56
|
+
device.android = true;
|
|
57
|
+
} else if (/CrOS/.test(ua)) {
|
|
58
|
+
device.chromeOS = true;
|
|
59
|
+
} else if (/iP[ao]d|iPhone/i.test(ua)) {
|
|
60
|
+
device.iOS = true;
|
|
61
|
+
(navigator.appVersion).match(/OS (\d+)/);
|
|
62
|
+
device.iOSVersion = parseInt(RegExp.$1, 10);
|
|
63
|
+
} else if (/Linux/.test(ua)) {
|
|
64
|
+
device.linux = true;
|
|
65
|
+
} else if (/Mac OS/.test(ua)) {
|
|
66
|
+
device.macOS = true;
|
|
67
|
+
} else if (/Windows/.test(ua)) {
|
|
68
|
+
device.windows = true;
|
|
69
|
+
}
|
|
70
|
+
if (/Windows Phone/i.test(ua) || /IEMobile/i.test(ua)) {
|
|
71
|
+
device.android = false;
|
|
72
|
+
device.iOS = false;
|
|
73
|
+
device.macOS = false;
|
|
74
|
+
device.windows = true;
|
|
75
|
+
device.windowsPhone = true;
|
|
76
|
+
}
|
|
77
|
+
const silk = /Silk/.test(ua); // detected in browsers
|
|
78
|
+
if (device.windows || device.macOS || (device.linux && !silk) || device.chromeOS) {
|
|
79
|
+
device.desktop = true;
|
|
80
|
+
}
|
|
81
|
+
// Windows Phone / Table reset
|
|
82
|
+
if (device.windowsPhone || ((/Windows NT/i.test(ua)) && (/Touch/i.test(ua)))) {
|
|
83
|
+
device.desktop = false;
|
|
84
|
+
}
|
|
85
|
+
// VPMedia Special override
|
|
86
|
+
if (window.location.pathname.indexOf('/mobile/') > -1) {
|
|
87
|
+
device.desktop = false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
*
|
|
93
|
+
* @param device
|
|
94
|
+
*/
|
|
95
|
+
export function checkFeatures(device) {
|
|
96
|
+
device.pointerLock = 'pointerLockElement' in document || 'mozPointerLockElement' in document || 'webkitPointerLockElement' in document;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
*
|
|
101
|
+
* @param device
|
|
102
|
+
*/
|
|
103
|
+
export function checkInput(device) {
|
|
104
|
+
if ('ontouchstart' in document.documentElement || (window.navigator.maxTouchPoints && window.navigator.maxTouchPoints >= 1)) {
|
|
105
|
+
device.touch = true;
|
|
106
|
+
}
|
|
107
|
+
if (window.navigator.msPointerEnabled || window.navigator.pointerEnabled) {
|
|
108
|
+
device.mspointer = true;
|
|
109
|
+
}
|
|
110
|
+
if (!device.cocoonJS) {
|
|
111
|
+
// See https://developer.mozilla.org/en-US/docs/Web/Events/wheel
|
|
112
|
+
if ('onwheel' in window || (device.ie && 'WheelEvent' in window)) {
|
|
113
|
+
// DOM3 Wheel Event: FF 17+, IE 9+, Chrome 31+, Safari 7+
|
|
114
|
+
device.wheelEvent = 'wheel';
|
|
115
|
+
} else if ('onmousewheel' in window) {
|
|
116
|
+
// Non-FF legacy: IE 6-9, Chrome 1-31, Safari 5-7.
|
|
117
|
+
device.wheelEvent = 'mousewheel';
|
|
118
|
+
} else if (device.firefox && 'MouseScrollEvent' in window) {
|
|
119
|
+
// FF prior to 17. This should probably be scrubbed.
|
|
120
|
+
device.wheelEvent = 'DOMMouseScroll';
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
*
|
|
127
|
+
* @param device
|
|
128
|
+
*/
|
|
129
|
+
export function checkFullScreenSupport(device) {
|
|
130
|
+
const fs = [
|
|
131
|
+
'requestFullscreen',
|
|
132
|
+
'requestFullScreen',
|
|
133
|
+
'webkitRequestFullscreen',
|
|
134
|
+
'webkitRequestFullScreen',
|
|
135
|
+
'msRequestFullscreen',
|
|
136
|
+
'msRequestFullScreen',
|
|
137
|
+
'mozRequestFullScreen',
|
|
138
|
+
'mozRequestFullscreen',
|
|
139
|
+
];
|
|
140
|
+
const cfs = [
|
|
141
|
+
'cancelFullScreen',
|
|
142
|
+
'exitFullscreen',
|
|
143
|
+
'webkitCancelFullScreen',
|
|
144
|
+
'webkitExitFullscreen',
|
|
145
|
+
'msCancelFullScreen',
|
|
146
|
+
'msExitFullscreen',
|
|
147
|
+
'mozCancelFullScreen',
|
|
148
|
+
'mozExitFullscreen',
|
|
149
|
+
];
|
|
150
|
+
const element = document.createElement('div');
|
|
151
|
+
for (let i = 0; i < fs.length; i += 1) {
|
|
152
|
+
if (element[fs[i]]) {
|
|
153
|
+
device.fullscreen = true;
|
|
154
|
+
device.requestFullscreen = fs[i];
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (device.fullscreen) {
|
|
159
|
+
for (let i = 0; i < cfs.length; i += 1) {
|
|
160
|
+
if (document[cfs[i]]) {
|
|
161
|
+
device.cancelFullscreen = cfs[i];
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (window.Element && Element.ALLOW_KEYBOARD_INPUT) {
|
|
166
|
+
device.fullscreenKeyboard = true;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
*
|
|
173
|
+
* @param device
|
|
174
|
+
*/
|
|
175
|
+
export function checkBrowser(device) {
|
|
176
|
+
const ua = navigator.userAgent;
|
|
177
|
+
if (/Edge\/\d+/.test(ua)) {
|
|
178
|
+
device.edge = true;
|
|
179
|
+
} else if (/Chrome\/(\d+)/.test(ua) && !device.windowsPhone) {
|
|
180
|
+
device.chrome = true;
|
|
181
|
+
device.chromeVersion = parseInt(RegExp.$1, 10);
|
|
182
|
+
} else if (/Firefox\D+(\d+)/.test(ua)) {
|
|
183
|
+
device.firefox = true;
|
|
184
|
+
device.firefoxVersion = parseInt(RegExp.$1, 10);
|
|
185
|
+
} else if (/AppleWebKit/.test(ua) && device.iOS) {
|
|
186
|
+
device.mobileSafari = true;
|
|
187
|
+
} else if (/MSIE (\d+\.\d+);/.test(ua)) {
|
|
188
|
+
device.ie = true;
|
|
189
|
+
device.ieVersion = parseInt(RegExp.$1, 10);
|
|
190
|
+
} else if (/Safari\/(\d+)/.test(ua) && !device.windowsPhone) {
|
|
191
|
+
device.safari = true;
|
|
192
|
+
if (/Version\/(\d+)\./.test(ua)) {
|
|
193
|
+
device.safariVersion = parseInt(RegExp.$1, 10);
|
|
194
|
+
}
|
|
195
|
+
} else if (/Trident\/(\d+\.\d+)(.*)rv:(\d+\.\d+)/.test(ua)) {
|
|
196
|
+
device.ie = true;
|
|
197
|
+
device.trident = true;
|
|
198
|
+
device.tridentVersion = parseInt(RegExp.$1, 10);
|
|
199
|
+
device.ieVersion = parseInt(RegExp.$3, 10);
|
|
200
|
+
}
|
|
201
|
+
// Silk gets its own if clause because its ua also contains 'Safari'
|
|
202
|
+
if (/Silk/.test(ua)) {
|
|
203
|
+
device.silk = true;
|
|
204
|
+
}
|
|
205
|
+
// WebApp mode in iOS
|
|
206
|
+
if (navigator.standalone) {
|
|
207
|
+
device.webApp = true;
|
|
208
|
+
}
|
|
209
|
+
if (typeof window.cordova !== 'undefined') {
|
|
210
|
+
device.cordova = true;
|
|
211
|
+
}
|
|
212
|
+
if (typeof process !== 'undefined' && typeof require !== 'undefined') {
|
|
213
|
+
device.node = true;
|
|
214
|
+
}
|
|
215
|
+
if (navigator.isCocoonJS) {
|
|
216
|
+
device.cocoonJS = true;
|
|
217
|
+
}
|
|
218
|
+
if (device.cocoonJS) {
|
|
219
|
+
try {
|
|
220
|
+
device.cocoonJSApp = (typeof CocoonJS !== 'undefined');
|
|
221
|
+
} catch (error) {
|
|
222
|
+
device.cocoonJSApp = false;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
*
|
|
229
|
+
* @param device
|
|
230
|
+
*/
|
|
231
|
+
export function checkVideo(device) {
|
|
232
|
+
const videoElement = document.createElement('video');
|
|
233
|
+
try {
|
|
234
|
+
if (videoElement.canPlayType) {
|
|
235
|
+
if (videoElement.canPlayType('video/ogg; codecs="theora"').replace(/^no$/, '')) {
|
|
236
|
+
device.oggVideo = true;
|
|
237
|
+
}
|
|
238
|
+
if (videoElement.canPlayType('video/mp4; codecs="avc1.42E01E"').replace(/^no$/, '')) {
|
|
239
|
+
// Without QuickTime, this value will be `undefined`. github.com/Modernizr/Modernizr/issues/546
|
|
240
|
+
device.h264Video = true;
|
|
241
|
+
device.mp4Video = true;
|
|
242
|
+
}
|
|
243
|
+
if (videoElement.canPlayType('video/webm; codecs="vp8, vorbis"').replace(/^no$/, '')) {
|
|
244
|
+
device.webmVideo = true;
|
|
245
|
+
}
|
|
246
|
+
if (videoElement.canPlayType('video/webm; codecs="vp9"').replace(/^no$/, '')) {
|
|
247
|
+
device.vp9Video = true;
|
|
248
|
+
}
|
|
249
|
+
if (videoElement.canPlayType('application/x-mpegURL; codecs="avc1.42E01E"').replace(/^no$/, '')) {
|
|
250
|
+
device.hlsVideo = true;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
} catch (e) {
|
|
254
|
+
// pass
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
*
|
|
260
|
+
* @param device
|
|
261
|
+
*/
|
|
262
|
+
export function checkAudio(device) {
|
|
263
|
+
device.audioData = !!(window.Audio);
|
|
264
|
+
device.webAudio = !!(window.AudioContext || window.webkitAudioContext);
|
|
265
|
+
const audioElement = document.createElement('audio');
|
|
266
|
+
try {
|
|
267
|
+
if (audioElement.canPlayType) {
|
|
268
|
+
if (audioElement.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/, '')) {
|
|
269
|
+
device.ogg = true;
|
|
270
|
+
}
|
|
271
|
+
if (audioElement.canPlayType('audio/ogg; codecs="opus"').replace(/^no$/, '') || audioElement.canPlayType('audio/opus;').replace(/^no$/, '')) {
|
|
272
|
+
device.opus = true;
|
|
273
|
+
}
|
|
274
|
+
if (audioElement.canPlayType('audio/mpeg;').replace(/^no$/, '')) {
|
|
275
|
+
device.mp3 = true;
|
|
276
|
+
}
|
|
277
|
+
// Mimetypes accepted:
|
|
278
|
+
// developer.mozilla.org/En/Media_formats_supported_by_the_audio_and_video_elements
|
|
279
|
+
// bit.ly/iphoneoscodecs
|
|
280
|
+
if (audioElement.canPlayType('audio/wav; codecs="1"').replace(/^no$/, '')) {
|
|
281
|
+
device.wav = true;
|
|
282
|
+
}
|
|
283
|
+
if (audioElement.canPlayType('audio/x-m4a;') || audioElement.canPlayType('audio/aac;').replace(/^no$/, '')) {
|
|
284
|
+
device.m4a = true;
|
|
285
|
+
}
|
|
286
|
+
if (audioElement.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/, '')) {
|
|
287
|
+
device.webm = true;
|
|
288
|
+
}
|
|
289
|
+
if (audioElement.canPlayType('audio/mp4;codecs="ec-3"') !== '') {
|
|
290
|
+
if (device.edge) {
|
|
291
|
+
device.dolby = true;
|
|
292
|
+
} else if (device.safari && device.safariVersion >= 9) {
|
|
293
|
+
if (/Mac OS X (\d+)_(\d+)/.test(navigator.userAgent)) {
|
|
294
|
+
const major = parseInt(RegExp.$1, 10);
|
|
295
|
+
const minor = parseInt(RegExp.$2, 10);
|
|
296
|
+
if ((major === 10 && minor >= 11) || major > 10) {
|
|
297
|
+
device.dolby = true;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
} catch (e) {
|
|
304
|
+
// pass
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
*
|
|
310
|
+
* @param device
|
|
311
|
+
*/
|
|
312
|
+
export function checkDevice(device) {
|
|
313
|
+
device.pixelRatio = window.devicePixelRatio || 1;
|
|
314
|
+
device.iPhone = navigator.userAgent.toLowerCase().indexOf('iphone') !== -1;
|
|
315
|
+
device.iPad = navigator.userAgent.toLowerCase().indexOf('ipad') !== -1;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
*
|
|
320
|
+
* @param device
|
|
321
|
+
*/
|
|
322
|
+
export function initialize(device) {
|
|
323
|
+
checkOS(device);
|
|
324
|
+
checkBrowser(device);
|
|
325
|
+
checkAudio(device);
|
|
326
|
+
checkVideo(device);
|
|
327
|
+
checkDevice(device);
|
|
328
|
+
checkFeatures(device);
|
|
329
|
+
checkFullScreenSupport(device);
|
|
330
|
+
checkInput(device);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
*
|
|
335
|
+
*/
|
|
336
|
+
export function readyCheck() {
|
|
337
|
+
if (!document.body) {
|
|
338
|
+
window.setTimeout(readyCheck._monitor, 20);
|
|
339
|
+
} else if (!this.deviceReadyAt) {
|
|
340
|
+
this.deviceReadyAt = Date.now();
|
|
341
|
+
document.removeEventListener('deviceready', readyCheck._monitor);
|
|
342
|
+
document.removeEventListener('DOMContentLoaded', readyCheck._monitor);
|
|
343
|
+
window.removeEventListener('load', readyCheck._monitor);
|
|
344
|
+
initialize(this);
|
|
345
|
+
let item = readyCheck._queue.shift();
|
|
346
|
+
while (item) {
|
|
347
|
+
const callback = item[0];
|
|
348
|
+
const context = item[1];
|
|
349
|
+
callback.call(context, this);
|
|
350
|
+
item = readyCheck._queue.shift();
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
*
|
|
357
|
+
* @param device
|
|
358
|
+
* @param callback
|
|
359
|
+
* @param context
|
|
360
|
+
* @param nonPrimer
|
|
361
|
+
*/
|
|
362
|
+
export function whenReady(device, callback, context, nonPrimer) {
|
|
363
|
+
if (device.deviceReadyAt) {
|
|
364
|
+
callback.call(context, device);
|
|
365
|
+
} else if (readyCheck._monitor || nonPrimer) {
|
|
366
|
+
readyCheck._queue = readyCheck._queue || [];
|
|
367
|
+
readyCheck._queue.push([callback, context]);
|
|
368
|
+
} else {
|
|
369
|
+
readyCheck._monitor = readyCheck.bind(device);
|
|
370
|
+
readyCheck._queue = readyCheck._queue || [];
|
|
371
|
+
readyCheck._queue.push([callback, context]);
|
|
372
|
+
const cordova = typeof window.cordova !== 'undefined';
|
|
373
|
+
const cocoonJS = navigator.isCocoonJS;
|
|
374
|
+
if (document.readyState === 'complete' || document.readyState === 'interactive') {
|
|
375
|
+
// Why is there an additional timeout here?
|
|
376
|
+
window.setTimeout(readyCheck._monitor, 0);
|
|
377
|
+
} else if (cordova && !cocoonJS) {
|
|
378
|
+
// Ref. http://docs.phonegap.com/en/3.5.0/cordova_events_events.md.html#deviceready
|
|
379
|
+
// Cordova, but NOT Cocoon?
|
|
380
|
+
document.addEventListener('deviceready', readyCheck._monitor, false);
|
|
381
|
+
} else {
|
|
382
|
+
document.addEventListener('DOMContentLoaded', readyCheck._monitor, false);
|
|
383
|
+
window.addEventListener('load', readyCheck._monitor, false);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author Andras Csizmadia <andras@vpmedia.hu>
|
|
3
|
+
* @author Richard Davey <rich@photonstorm.com>
|
|
4
|
+
* @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
|
|
5
|
+
*/
|
|
6
|
+
import Point from '../geom/point';
|
|
7
|
+
|
|
8
|
+
class VisualBoundsDesktopRectangle {
|
|
9
|
+
|
|
10
|
+
get x() {
|
|
11
|
+
return window && ('pageXOffset' in window) ? window.pageXOffset : document.documentElement.scrollLeft;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
get y() {
|
|
15
|
+
return window && ('pageYOffset' in window) ? window.pageYOffset : document.documentElement.scrollTop;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
get width() {
|
|
19
|
+
return Math.max(window.innerWidth, document.documentElement.clientWidth);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
get height() {
|
|
23
|
+
return Math.max(window.innerHeight, document.documentElement.clientHeight);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
class LayoutBoundsDesktopRectangle {
|
|
29
|
+
|
|
30
|
+
get x() {
|
|
31
|
+
return 0;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
get y() {
|
|
35
|
+
return 0;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
get width() {
|
|
39
|
+
return Math.max(window.innerWidth, document.documentElement.clientWidth);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get height() {
|
|
43
|
+
return Math.max(window.innerHeight, document.documentElement.clientHeight);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
class VisualBoundsRectangle {
|
|
49
|
+
|
|
50
|
+
get x() {
|
|
51
|
+
return window && ('pageXOffset' in window) ? window.pageXOffset : document.documentElement.scrollLeft;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
get y() {
|
|
55
|
+
return window && ('pageYOffset' in window) ? window.pageYOffset : document.documentElement.scrollTop;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
get width() {
|
|
59
|
+
return window.innerWidth;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
get height() {
|
|
63
|
+
return window.innerHeight;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
class LayoutBoundsRectangle {
|
|
69
|
+
|
|
70
|
+
get x() {
|
|
71
|
+
return 0;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
get y() {
|
|
75
|
+
return 0;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
get width() {
|
|
79
|
+
const a = document.documentElement.clientWidth;
|
|
80
|
+
const b = window.innerWidth;
|
|
81
|
+
return a < b ? b : a; // max
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
get height() {
|
|
85
|
+
const a = document.documentElement.clientHeight;
|
|
86
|
+
const b = window.innerHeight;
|
|
87
|
+
return a < b ? b : a; // max
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// For documentBounds
|
|
93
|
+
// Ref. http://www.quirksmode.org/mobile/tableViewport_desktop.html
|
|
94
|
+
|
|
95
|
+
class DocumentBoundsRectangle {
|
|
96
|
+
|
|
97
|
+
get x() {
|
|
98
|
+
return 0;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
get y() {
|
|
102
|
+
return 0;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
get width() {
|
|
106
|
+
const d = document.documentElement;
|
|
107
|
+
return Math.max(d.clientWidth, d.offsetWidth, d.scrollWidth);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
get height() {
|
|
111
|
+
const d = document.documentElement;
|
|
112
|
+
return Math.max(d.clientHeight, d.offsetHeight, d.scrollHeight);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export default class {
|
|
118
|
+
|
|
119
|
+
constructor(device) {
|
|
120
|
+
this.treatAsDesktop = device.desktop && (document.documentElement.clientWidth <= window.innerWidth) && (document.documentElement.clientHeight <= window.innerHeight);
|
|
121
|
+
this.visualBounds = this.treatAsDesktop ? new VisualBoundsDesktopRectangle() : new VisualBoundsRectangle();
|
|
122
|
+
this.layoutBounds = this.treatAsDesktop ? new LayoutBoundsDesktopRectangle() : new LayoutBoundsRectangle();
|
|
123
|
+
this.documentBounds = new DocumentBoundsRectangle();
|
|
124
|
+
this.scrollXProvider = window && ('pageXOffset' in window) ? () => window.pageXOffset : () => document.documentElement.scrollLeft;
|
|
125
|
+
this.scrollYProvider = window && ('pageYOffset' in window) ? () => window.pageYOffset : () => document.documentElement.scrollTop;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
getOffset(element, point = null) {
|
|
129
|
+
point = point || new Point();
|
|
130
|
+
const box = element.getBoundingClientRect();
|
|
131
|
+
const scrollTop = this.scrollY;
|
|
132
|
+
const scrollLeft = this.scrollX;
|
|
133
|
+
const clientTop = document.documentElement.clientTop;
|
|
134
|
+
const clientLeft = document.documentElement.clientLeft;
|
|
135
|
+
point.x = box.left + scrollLeft - clientLeft;
|
|
136
|
+
point.y = box.top + scrollTop - clientTop;
|
|
137
|
+
return point;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
getBounds(element, cushion = 0) {
|
|
141
|
+
element = element && !element.nodeType ? element[0] : element;
|
|
142
|
+
if (!element || element.nodeType !== 1) {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
return this.calibrate(element.getBoundingClientRect(), cushion);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
calibrate(coords, cushion = 0) {
|
|
149
|
+
const output = {
|
|
150
|
+
width: 0,
|
|
151
|
+
height: 0,
|
|
152
|
+
left: 0,
|
|
153
|
+
right: 0,
|
|
154
|
+
top: 0,
|
|
155
|
+
bottom: 0,
|
|
156
|
+
};
|
|
157
|
+
output.width = (output.right = coords.right + cushion) - (output.left = coords.left - cushion);
|
|
158
|
+
output.height = (output.bottom = coords.bottom + cushion) - (output.top = coords.top - cushion);
|
|
159
|
+
return output;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
getScreenOrientation(primaryFallback) {
|
|
163
|
+
const screen = window.screen;
|
|
164
|
+
const orientation = screen.orientation || screen.mozOrientation || screen.msOrientation;
|
|
165
|
+
if (orientation && typeof orientation.type === 'string') {
|
|
166
|
+
// Screen Orientation API specification
|
|
167
|
+
return orientation.type;
|
|
168
|
+
} else if (typeof orientation === 'string') {
|
|
169
|
+
// moz/ms-orientation are strings
|
|
170
|
+
return orientation;
|
|
171
|
+
}
|
|
172
|
+
const PORTRAIT = 'portrait-primary';
|
|
173
|
+
const LANDSCAPE = 'landscape-primary';
|
|
174
|
+
if (primaryFallback === 'screen') {
|
|
175
|
+
return (screen.height > screen.width) ? PORTRAIT : LANDSCAPE;
|
|
176
|
+
} else if (primaryFallback === 'viewport') {
|
|
177
|
+
return (this.visualBounds.height > this.visualBounds.width) ? PORTRAIT : LANDSCAPE;
|
|
178
|
+
} else if (primaryFallback === 'window.orientation' && typeof window.orientation === 'number') {
|
|
179
|
+
// This may change by device based on "natural" orientation.
|
|
180
|
+
return (window.orientation === 0 || window.orientation === 180) ? PORTRAIT : LANDSCAPE;
|
|
181
|
+
} else if (window.matchMedia) {
|
|
182
|
+
if (window.matchMedia('(orientation: portrait)').matches) {
|
|
183
|
+
return PORTRAIT;
|
|
184
|
+
} else if (window.matchMedia('(orientation: landscape)').matches) {
|
|
185
|
+
return LANDSCAPE;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return (this.visualBounds.height > this.visualBounds.width) ? PORTRAIT : LANDSCAPE;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
get scrollX() {
|
|
192
|
+
return this.scrollXProvider();
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
get scrollY() {
|
|
196
|
+
return this.scrollYProvider();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
get clientWidth() {
|
|
200
|
+
return Math.max(window.innerWidth, document.documentElement.clientWidth);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
get clientHeight() {
|
|
204
|
+
return Math.max(window.innerHeight, document.documentElement.clientHeight);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
}
|