@urso/core 0.6.16-dev → 0.6.16

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.
Files changed (156) hide show
  1. package/.babelrc +11 -11
  2. package/LICENSE +20 -20
  3. package/README.md +227 -227
  4. package/build/js/index.js +1 -1
  5. package/build/js/index.js.LICENSE.txt +38 -270
  6. package/package.json +52 -52
  7. package/src/js/app.js +79 -79
  8. package/src/js/components/_info.js +11 -11
  9. package/src/js/components/base/_info.js +3 -3
  10. package/src/js/components/base/controller.js +78 -78
  11. package/src/js/components/debug/_info.js +7 -7
  12. package/src/js/components/debug/controller.js +38 -38
  13. package/src/js/components/debug/coords.js +23 -23
  14. package/src/js/components/debug/fps.js +36 -36
  15. package/src/js/components/debug/template.js +55 -55
  16. package/src/js/components/debug/timescale.js +60 -60
  17. package/src/js/components/deviceRotate/_info.js +3 -3
  18. package/src/js/components/deviceRotate/controller.js +86 -86
  19. package/src/js/components/fullscreen/_info.js +6 -6
  20. package/src/js/components/fullscreen/android.js +104 -104
  21. package/src/js/components/fullscreen/controller.js +76 -76
  22. package/src/js/components/fullscreen/desktop.js +49 -49
  23. package/src/js/components/fullscreen/ios.js +115 -115
  24. package/src/js/components/layersSwitcher/_info.js +4 -4
  25. package/src/js/components/layersSwitcher/config.js +26 -26
  26. package/src/js/components/layersSwitcher/controller.js +34 -34
  27. package/src/js/components/loader/_info.js +4 -4
  28. package/src/js/components/loader/controller.js +65 -65
  29. package/src/js/components/loader/template.js +70 -70
  30. package/src/js/components/soundInitialPopup/_info.js +3 -3
  31. package/src/js/components/soundInitialPopup/controller.js +42 -42
  32. package/src/js/components/soundInitialPopup/template.js +109 -109
  33. package/src/js/components/stateDriven/_info.js +3 -3
  34. package/src/js/components/stateDriven/controller.js +118 -118
  35. package/src/js/config/load.js +5 -5
  36. package/src/js/config/main.js +16 -16
  37. package/src/js/extra/_info.js +26 -26
  38. package/src/js/extra/browserEvents.js +51 -51
  39. package/src/js/extra/pixiPatch.js +150 -150
  40. package/src/js/extra/setTimeout.js +7 -7
  41. package/src/js/index.js +8 -8
  42. package/src/js/lib/_info.js +13 -13
  43. package/src/js/lib/cache.js +105 -105
  44. package/src/js/lib/composition.js +85 -85
  45. package/src/js/lib/device.js +1286 -1286
  46. package/src/js/lib/helper.js +556 -556
  47. package/src/js/lib/loader.js +136 -136
  48. package/src/js/lib/localData.js +15 -15
  49. package/src/js/lib/logger.js +69 -69
  50. package/src/js/lib/math.js +35 -35
  51. package/src/js/lib/objectPool.js +203 -203
  52. package/src/js/lib/time.js +18 -18
  53. package/src/js/lib/tween.js +147 -147
  54. package/src/js/modules/_info.js +12 -12
  55. package/src/js/modules/assets/_info.js +7 -7
  56. package/src/js/modules/assets/baseModel.js +20 -20
  57. package/src/js/modules/assets/config.js +37 -37
  58. package/src/js/modules/assets/controller.js +46 -46
  59. package/src/js/modules/assets/models/_info.js +11 -11
  60. package/src/js/modules/assets/models/atlas.js +8 -8
  61. package/src/js/modules/assets/models/audiosprite.js +27 -27
  62. package/src/js/modules/assets/models/bitmapFont.js +8 -8
  63. package/src/js/modules/assets/models/container.js +16 -16
  64. package/src/js/modules/assets/models/font.js +8 -8
  65. package/src/js/modules/assets/models/image.js +15 -15
  66. package/src/js/modules/assets/models/json.js +8 -8
  67. package/src/js/modules/assets/models/sound.js +14 -14
  68. package/src/js/modules/assets/models/spine.js +14 -14
  69. package/src/js/modules/assets/service.js +366 -366
  70. package/src/js/modules/i18n/_info.js +4 -4
  71. package/src/js/modules/i18n/config.js +17 -17
  72. package/src/js/modules/i18n/controller.js +79 -79
  73. package/src/js/modules/instances/_info.js +3 -3
  74. package/src/js/modules/instances/controller.js +357 -357
  75. package/src/js/modules/logic/_info.js +4 -4
  76. package/src/js/modules/logic/config/_info.js +2 -2
  77. package/src/js/modules/logic/config/sounds.js +23 -23
  78. package/src/js/modules/logic/controller.js +48 -48
  79. package/src/js/modules/logic/sounds.js +103 -103
  80. package/src/js/modules/objects/_info.js +13 -13
  81. package/src/js/modules/objects/baseModel.js +200 -200
  82. package/src/js/modules/objects/cache.js +99 -99
  83. package/src/js/modules/objects/controller.js +131 -131
  84. package/src/js/modules/objects/find.js +58 -58
  85. package/src/js/modules/objects/models/_info.js +27 -27
  86. package/src/js/modules/objects/models/atlasImage.js +50 -50
  87. package/src/js/modules/objects/models/bitmapText.js +37 -37
  88. package/src/js/modules/objects/models/button.js +189 -189
  89. package/src/js/modules/objects/models/buttonComposite.js +35 -35
  90. package/src/js/modules/objects/models/checkbox.js +96 -96
  91. package/src/js/modules/objects/models/collection.js +54 -54
  92. package/src/js/modules/objects/models/component.js +46 -46
  93. package/src/js/modules/objects/models/container.js +19 -19
  94. package/src/js/modules/objects/models/dragContainer.js +667 -667
  95. package/src/js/modules/objects/models/emitter.js +67 -67
  96. package/src/js/modules/objects/models/emitterFx.js +99 -99
  97. package/src/js/modules/objects/models/graphics.js +38 -38
  98. package/src/js/modules/objects/models/group.js +19 -19
  99. package/src/js/modules/objects/models/hitArea.js +104 -104
  100. package/src/js/modules/objects/models/image.js +34 -34
  101. package/src/js/modules/objects/models/imagesAnimation.js +113 -113
  102. package/src/js/modules/objects/models/mask.js +38 -38
  103. package/src/js/modules/objects/models/nineSlicePlane.js +30 -30
  104. package/src/js/modules/objects/models/scrollbox.js +64 -64
  105. package/src/js/modules/objects/models/slider.js +253 -253
  106. package/src/js/modules/objects/models/spine.js +296 -287
  107. package/src/js/modules/objects/models/text.js +59 -59
  108. package/src/js/modules/objects/models/textInput.js +66 -66
  109. package/src/js/modules/objects/models/toggle.js +180 -180
  110. package/src/js/modules/objects/models/world.js +19 -19
  111. package/src/js/modules/objects/propertyAdapter.js +588 -587
  112. package/src/js/modules/objects/proxy.js +294 -294
  113. package/src/js/modules/objects/selector.js +136 -136
  114. package/src/js/modules/objects/service.js +242 -242
  115. package/src/js/modules/objects/styles.js +210 -210
  116. package/src/js/modules/observer/_info.js +4 -4
  117. package/src/js/modules/observer/controller.js +99 -99
  118. package/src/js/modules/observer/events.js +52 -52
  119. package/src/js/modules/scenes/_info.js +8 -8
  120. package/src/js/modules/scenes/controller.js +119 -119
  121. package/src/js/modules/scenes/model.js +28 -28
  122. package/src/js/modules/scenes/pixiWrapper.js +336 -336
  123. package/src/js/modules/scenes/resolutions.js +173 -173
  124. package/src/js/modules/scenes/resolutionsConfig.js +73 -73
  125. package/src/js/modules/scenes/service.js +142 -142
  126. package/src/js/modules/soundManager/_info.js +3 -3
  127. package/src/js/modules/soundManager/controller.js +100 -100
  128. package/src/js/modules/soundManager/soundSprite.js +251 -251
  129. package/src/js/modules/statesManager/_info.js +12 -12
  130. package/src/js/modules/statesManager/action.js +68 -68
  131. package/src/js/modules/statesManager/actions/_info.js +3 -3
  132. package/src/js/modules/statesManager/all.js +23 -23
  133. package/src/js/modules/statesManager/configStates.js +71 -71
  134. package/src/js/modules/statesManager/controller.js +170 -170
  135. package/src/js/modules/statesManager/functionsStorage.js +82 -82
  136. package/src/js/modules/statesManager/helper.js +27 -27
  137. package/src/js/modules/statesManager/race.js +75 -75
  138. package/src/js/modules/statesManager/sequence.js +47 -47
  139. package/src/js/modules/template/_info.js +6 -6
  140. package/src/js/modules/template/controller.js +28 -28
  141. package/src/js/modules/template/model.js +11 -11
  142. package/src/js/modules/template/service.js +137 -137
  143. package/src/js/modules/template/types.js +46 -46
  144. package/src/js/modules/transport/_info.js +8 -8
  145. package/src/js/modules/transport/baseConnectionType.js +24 -24
  146. package/src/js/modules/transport/config.js +13 -13
  147. package/src/js/modules/transport/connectionTypes/_info.js +3 -3
  148. package/src/js/modules/transport/connectionTypes/websocket.js +74 -74
  149. package/src/js/modules/transport/connectionTypes/xhr.js +44 -44
  150. package/src/js/modules/transport/controller.js +48 -48
  151. package/src/js/modules/transport/decorator.js +17 -17
  152. package/src/js/modules/transport/service.js +153 -153
  153. package/src/js/templates/_info.js +4 -4
  154. package/src/js/templates/groups/_info.js +1 -1
  155. package/src/js/templates/scenes/_info.js +1 -1
  156. package/webpack.config.js +47 -47
@@ -1,1286 +1,1286 @@
1
- LibDevice = function () {
2
-
3
- /**
4
- * The time the device became ready.
5
- * @property {integer} deviceReadyAt
6
- * @protected
7
- */
8
- this.deviceReadyAt = 0;
9
-
10
- /**
11
- * The time as which initialization has completed.
12
- * @property {boolean} initialized
13
- * @protected
14
- */
15
- this.initialized = false;
16
-
17
- // Browser / Host / Operating System
18
-
19
- /**
20
- * @property {boolean} desktop - Is running on a desktop?
21
- * @default
22
- */
23
- this.desktop = false;
24
-
25
- /**
26
- * @property {boolean} iOS - Is running on iOS?
27
- * @default
28
- */
29
- this.iOS = false;
30
-
31
- /**
32
- * @property {boolean} cocoonJS - Is the game running under CocoonJS?
33
- * @default
34
- */
35
- this.cocoonJS = false;
36
-
37
- /**
38
- * @property {boolean} cocoonJSApp - Is this game running with CocoonJS.App?
39
- * @default
40
- */
41
- this.cocoonJSApp = false;
42
-
43
- /**
44
- * @property {boolean} cordova - Is the game running under Apache Cordova?
45
- * @default
46
- */
47
- this.cordova = false;
48
-
49
- /**
50
- * @property {boolean} node - Is the game running under Node.js?
51
- * @default
52
- */
53
- this.node = false;
54
-
55
- /**
56
- * @property {boolean} nodeWebkit - Is the game running under Node-Webkit?
57
- * @default
58
- */
59
- this.nodeWebkit = false;
60
-
61
- /**
62
- * @property {boolean} electron - Is the game running under GitHub Electron?
63
- * @default
64
- */
65
- this.electron = false;
66
-
67
- /**
68
- * @property {boolean} ejecta - Is the game running under Ejecta?
69
- * @default
70
- */
71
- this.ejecta = false;
72
-
73
- /**
74
- * @property {boolean} crosswalk - Is the game running under the Intel Crosswalk XDK?
75
- * @default
76
- */
77
- this.crosswalk = false;
78
-
79
- /**
80
- * @property {boolean} android - Is running on android?
81
- * @default
82
- */
83
- this.android = false;
84
-
85
- /**
86
- * @property {boolean} chromeOS - Is running on chromeOS?
87
- * @default
88
- */
89
- this.chromeOS = false;
90
-
91
- /**
92
- * @property {boolean} linux - Is running on linux?
93
- * @default
94
- */
95
- this.linux = false;
96
-
97
- /**
98
- * @property {boolean} macOS - Is running on macOS?
99
- * @default
100
- */
101
- this.macOS = false;
102
-
103
- /**
104
- * @property {boolean} windows - Is running on windows?
105
- * @default
106
- */
107
- this.windows = false;
108
-
109
- /**
110
- * @property {boolean} windowsPhone - Is running on a Windows Phone?
111
- * @default
112
- */
113
- this.windowsPhone = false;
114
-
115
- // Features
116
-
117
- /**
118
- * @property {boolean} canvas - Is canvas available?
119
- * @default
120
- */
121
- this.canvas = false;
122
-
123
- /**
124
- * @property {?boolean} canvasBitBltShift - True if canvas supports a 'copy' bitblt onto itself when the source and destination regions overlap.
125
- * @default
126
- */
127
- this.canvasBitBltShift = null;
128
-
129
- /**
130
- * @property {boolean} webGL - Is webGL available?
131
- * @default
132
- */
133
- this.webGL = false;
134
-
135
- /**
136
- * @property {boolean} file - Is file available?
137
- * @default
138
- */
139
- this.file = false;
140
-
141
- /**
142
- * @property {boolean} fileSystem - Is fileSystem available?
143
- * @default
144
- */
145
- this.fileSystem = false;
146
-
147
- /**
148
- * @property {boolean} localStorage - Is localStorage available?
149
- * @default
150
- */
151
- this.localStorage = false;
152
-
153
- /**
154
- * @property {boolean} worker - Is worker available?
155
- * @default
156
- */
157
- this.worker = false;
158
-
159
- /**
160
- * @property {boolean} css3D - Is css3D available?
161
- * @default
162
- */
163
- this.css3D = false;
164
-
165
- /**
166
- * @property {boolean} pointerLock - Is Pointer Lock available?
167
- * @default
168
- */
169
- this.pointerLock = false;
170
-
171
- /**
172
- * @property {boolean} typedArray - Does the browser support TypedArrays?
173
- * @default
174
- */
175
- this.typedArray = false;
176
-
177
- /**
178
- * @property {boolean} vibration - Does the device support the Vibration API?
179
- * @default
180
- */
181
- this.vibration = false;
182
-
183
- /**
184
- * @property {boolean} getUserMedia - Does the device support the getUserMedia API?
185
- * @default
186
- */
187
- this.getUserMedia = true;
188
-
189
- /**
190
- * @property {boolean} quirksMode - Is the browser running in strict mode (false) or quirks mode? (true)
191
- * @default
192
- */
193
- this.quirksMode = false;
194
-
195
- // Input
196
-
197
- /**
198
- * @property {boolean} touch - Is touch available?
199
- * @default
200
- */
201
- this.touch = false;
202
-
203
- /**
204
- * @property {boolean} mspointer - Is mspointer available?
205
- * @default
206
- */
207
- this.mspointer = false;
208
-
209
- /**
210
- * @property {?string} wheelType - The newest type of Wheel/Scroll event supported: 'wheel', 'mousewheel', 'DOMMouseScroll'
211
- * @default
212
- * @protected
213
- */
214
- this.wheelEvent = null;
215
-
216
- // Browser
217
-
218
- /**
219
- * @property {boolean} arora - Set to true if running in Arora.
220
- * @default
221
- */
222
- this.arora = false;
223
-
224
- /**
225
- * @property {boolean} chrome - Set to true if running in Chrome.
226
- * @default
227
- */
228
- this.chrome = false;
229
-
230
- /**
231
- * @property {number} chromeVersion - If running in Chrome this will contain the major version number.
232
- * @default
233
- */
234
- this.chromeVersion = 0;
235
-
236
- /**
237
- * @property {boolean} epiphany - Set to true if running in Epiphany.
238
- * @default
239
- */
240
- this.epiphany = false;
241
-
242
- /**
243
- * @property {boolean} firefox - Set to true if running in Firefox.
244
- * @default
245
- */
246
- this.firefox = false;
247
-
248
- /**
249
- * @property {number} firefoxVersion - If running in Firefox this will contain the major version number.
250
- * @default
251
- */
252
- this.firefoxVersion = 0;
253
-
254
- /**
255
- * @property {boolean} ie - Set to true if running in Internet Explorer.
256
- * @default
257
- */
258
- this.ie = false;
259
-
260
- /**
261
- * @property {number} ieVersion - If running in Internet Explorer this will contain the major version number. Beyond IE10 you should use Device.trident and Device.tridentVersion.
262
- * @default
263
- */
264
- this.ieVersion = 0;
265
-
266
- /**
267
- * @property {boolean} trident - Set to true if running a Trident version of Internet Explorer (IE11+)
268
- * @default
269
- */
270
- this.trident = false;
271
-
272
- /**
273
- * @property {number} tridentVersion - If running in Internet Explorer 11 this will contain the major version number. See {@link http://msdn.microsoft.com/en-us/library/ie/ms537503(v=vs.85).aspx}
274
- * @default
275
- */
276
- this.tridentVersion = 0;
277
-
278
- /**
279
- * @property {boolean} mobileSafari - Set to true if running in Mobile Safari.
280
- * @default
281
- */
282
- this.mobileSafari = false;
283
-
284
- /**
285
- * @property {boolean} midori - Set to true if running in Midori.
286
- * @default
287
- */
288
- this.midori = false;
289
-
290
- /**
291
- * @property {boolean} opera - Set to true if running in Opera.
292
- * @default
293
- */
294
- this.opera = false;
295
-
296
- /**
297
- * @property {boolean} safari - Set to true if running in Safari.
298
- * @default
299
- */
300
- this.safari = false;
301
-
302
- /**
303
- * @property {boolean} webApp - Set to true if running as a WebApp, i.e. within a WebView
304
- * @default
305
- */
306
- this.webApp = false;
307
-
308
- /**
309
- * @property {boolean} silk - Set to true if running in the Silk browser (as used on the Amazon Kindle)
310
- * @default
311
- */
312
- this.silk = false;
313
-
314
- // Audio
315
-
316
- /**
317
- * @property {boolean} audioData - Are Audio tags available?
318
- * @default
319
- */
320
- this.audioData = false;
321
-
322
- /**
323
- * @property {boolean} webAudio - Is the WebAudio API available?
324
- * @default
325
- */
326
- this.webAudio = false;
327
-
328
- /**
329
- * @property {boolean} ogg - Can this device play ogg files?
330
- * @default
331
- */
332
- this.ogg = false;
333
-
334
- /**
335
- * @property {boolean} opus - Can this device play opus files?
336
- * @default
337
- */
338
- this.opus = false;
339
-
340
- /**
341
- * @property {boolean} mp3 - Can this device play mp3 files?
342
- * @default
343
- */
344
- this.mp3 = false;
345
-
346
- /**
347
- * @property {boolean} wav - Can this device play wav files?
348
- * @default
349
- */
350
- this.wav = false;
351
-
352
- /**
353
- * Can this device play m4a files?
354
- * @property {boolean} m4a - True if this device can play m4a files.
355
- * @default
356
- */
357
- this.m4a = false;
358
-
359
- /**
360
- * @property {boolean} webm - Can this device play webm files?
361
- * @default
362
- */
363
- this.webm = false;
364
-
365
- // Video
366
-
367
- /**
368
- * @property {boolean} oggVideo - Can this device play ogg video files?
369
- * @default
370
- */
371
- this.oggVideo = false;
372
-
373
- /**
374
- * @property {boolean} h264Video - Can this device play h264 mp4 video files?
375
- * @default
376
- */
377
- this.h264Video = false;
378
-
379
- /**
380
- * @property {boolean} mp4Video - Can this device play h264 mp4 video files?
381
- * @default
382
- */
383
- this.mp4Video = false;
384
-
385
- /**
386
- * @property {boolean} webmVideo - Can this device play webm video files?
387
- * @default
388
- */
389
- this.webmVideo = false;
390
-
391
- /**
392
- * @property {boolean} vp9Video - Can this device play vp9 video files?
393
- * @default
394
- */
395
- this.vp9Video = false;
396
-
397
- /**
398
- * @property {boolean} hlsVideo - Can this device play hls video files?
399
- * @default
400
- */
401
- this.hlsVideo = false;
402
-
403
- // Device
404
-
405
- /**
406
- * @property {boolean} iPhone - Is running on iPhone?
407
- * @default
408
- */
409
- this.iPhone = false;
410
-
411
- /**
412
- * @property {boolean} iPhone4 - Is running on iPhone4?
413
- * @default
414
- */
415
- this.iPhone4 = false;
416
-
417
- /**
418
- * @property {boolean} iPhone5 - Is running on iPhone5?
419
- * @default
420
- */
421
- this.iPhone5 = false;
422
-
423
- /**
424
- * @property {boolean} iPad - Is running on iPad?
425
- * @default
426
- */
427
- this.iPad = false;
428
-
429
- // Device features
430
-
431
- /**
432
- * @property {number} pixelRatio - PixelRatio of the host device?
433
- * @default
434
- */
435
- this.pixelRatio = 0;
436
-
437
- /**
438
- * @property {boolean} littleEndian - Is the device big or little endian? (only detected if the browser supports TypedArrays)
439
- * @default
440
- */
441
- this.littleEndian = false;
442
-
443
- /**
444
- * @property {boolean} LITTLE_ENDIAN - Same value as `littleEndian`.
445
- * @default
446
- */
447
- this.LITTLE_ENDIAN = false;
448
-
449
- /**
450
- * @property {boolean} support32bit - Does the device context support 32bit pixel manipulation using array buffer views?
451
- * @default
452
- */
453
- this.support32bit = false;
454
-
455
- /**
456
- * @property {boolean} fullscreen - Does the browser support the Full Screen API?
457
- * @default
458
- */
459
- this.fullscreen = false;
460
-
461
- /**
462
- * @property {string} requestFullscreen - If the browser supports the Full Screen API this holds the call you need to use to activate it.
463
- * @default
464
- */
465
- this.requestFullscreen = '';
466
-
467
- /**
468
- * @property {string} cancelFullscreen - If the browser supports the Full Screen API this holds the call you need to use to cancel it.
469
- * @default
470
- */
471
- this.cancelFullscreen = '';
472
-
473
- /**
474
- * @property {boolean} fullscreenKeyboard - Does the browser support access to the Keyboard during Full Screen mode?
475
- * @default
476
- */
477
- this.fullscreenKeyboard = false;
478
-
479
- /**
480
- * Enum for possible screen orientations.
481
- * @readonly
482
- * @enum {string}
483
- */
484
- this.ScreenOrientation = {
485
- LANDSCAPE: 'landscape',
486
- PORTRAIT: 'portrait'
487
- };
488
-
489
- };
490
-
491
- // Device is really a singleton/static entity; instantiate it
492
- // and add new methods directly sans-prototype.
493
- LibDevice = new LibDevice();
494
-
495
- /**
496
- * Add a device-ready handler and ensure the device ready sequence is started.
497
- *
498
- * Phaser.Device will _not_ activate or initialize until at least one `whenReady` handler is added,
499
- * which is normally done automatically be calling `new Phaser.Game(..)`.
500
- *
501
- * The handler is invoked when the device is considered "ready", which may be immediately
502
- * if the device is already "ready". See {@link Phaser.Device#deviceReadyAt deviceReadyAt}.
503
- *
504
- * @method
505
- * @param {Function} handler - Callback to invoke when the device is ready. It is invoked with the given context the Phaser.Device object is supplied as the first argument.
506
- * @param {Object} [context] - Context in which to invoke the handler
507
- * @param {Boolean} [nonPrimer=false] - If true the device ready check will not be started.
508
- */
509
- LibDevice.whenReady = function (callback, context, nonPrimer) {
510
-
511
- let readyCheck = this._readyCheck;
512
-
513
- if (this.deviceReadyAt || !readyCheck)
514
- {
515
- callback.call(context, this);
516
- }
517
- else if (readyCheck._monitor || nonPrimer)
518
- {
519
- readyCheck._queue = readyCheck._queue || [];
520
- readyCheck._queue.push([callback, context]);
521
- }
522
- else
523
- {
524
- readyCheck._monitor = readyCheck.bind(this);
525
- readyCheck._queue = readyCheck._queue || [];
526
- readyCheck._queue.push([callback, context]);
527
-
528
- let cordova = typeof window.cordova !== 'undefined';
529
- let cocoonJS = navigator['isCocoonJS'];
530
-
531
- if (document.readyState === 'complete' || document.readyState === 'interactive')
532
- {
533
- // Why is there an additional timeout here?
534
- window.setTimeout(readyCheck._monitor, 0);
535
- }
536
- else if (cordova && !cocoonJS)
537
- {
538
- // Ref. http://docs.phonegap.com/en/3.5.0/cordova_events_events.md.html#deviceready
539
- // Cordova, but NOT Cocoon?
540
- document.addEventListener('deviceready', readyCheck._monitor, false);
541
- }
542
- else
543
- {
544
- document.addEventListener('DOMContentLoaded', readyCheck._monitor, false);
545
- window.addEventListener('load', readyCheck._monitor, false);
546
- }
547
- }
548
-
549
- };
550
-
551
- /**
552
- * Internal method used for checking when the device is ready.
553
- * This function is removed from Phaser.Device when the device becomes ready.
554
- *
555
- * @method
556
- * @private
557
- */
558
- LibDevice._readyCheck = function () {
559
-
560
- let readyCheck = this._readyCheck;
561
-
562
- if (!document.body)
563
- {
564
- window.setTimeout(readyCheck._monitor, 20);
565
- }
566
- else if (!this.deviceReadyAt)
567
- {
568
- this.deviceReadyAt = Date.now();
569
-
570
- document.removeEventListener('deviceready', readyCheck._monitor);
571
- document.removeEventListener('DOMContentLoaded', readyCheck._monitor);
572
- window.removeEventListener('load', readyCheck._monitor);
573
-
574
- this._initialize();
575
- this.initialized = true;
576
-
577
- let item;
578
- while ((item = readyCheck._queue.shift()))
579
- {
580
- let callback = item[0];
581
- let context = item[1];
582
- callback.call(context, this);
583
- }
584
-
585
- // Remove no longer useful methods and properties.
586
- this._readyCheck = null;
587
- this._initialize = null;
588
- }
589
-
590
- };
591
-
592
- /**
593
- * Internal method to initialize the capability checks.
594
- * This function is removed from Phaser.Device once the device is initialized.
595
- *
596
- * @method
597
- * @private
598
- */
599
- LibDevice._initialize = function () {
600
-
601
- let device = this;
602
-
603
- /**
604
- * Check which OS is game running on.
605
- */
606
- function _checkOS () {
607
-
608
- let ua = navigator.userAgent;
609
-
610
- if (/Playstation Vita/.test(ua))
611
- {
612
- device.vita = true;
613
- }
614
- else if (/Kindle/.test(ua) || /\bKF[A-Z][A-Z]+/.test(ua) || /Silk.*Mobile Safari/.test(ua))
615
- {
616
- device.kindle = true;
617
- // This will NOT detect early generations of Kindle Fire, I think there is no reliable way...
618
- // E.g. "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us; Silk/1.1.0-80) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16 Silk-Accelerated=true"
619
- }
620
- else if (/Android/.test(ua))
621
- {
622
- device.android = true;
623
- }
624
- else if (/CrOS/.test(ua))
625
- {
626
- device.chromeOS = true;
627
- }
628
- else if (/iP[ao]d|iPhone/i.test(ua))
629
- {
630
- device.iOS = true;
631
- }
632
- else if (/Linux/.test(ua))
633
- {
634
- device.linux = true;
635
- }
636
- else if (/Mac OS/.test(ua))
637
- {
638
- device.macOS = true;
639
- }
640
- else if (/Windows/.test(ua))
641
- {
642
- device.windows = true;
643
- }
644
-
645
- if (/Windows Phone/i.test(ua) || /IEMobile/i.test(ua))
646
- {
647
- device.android = false;
648
- device.iOS = false;
649
- device.macOS = false;
650
- device.windows = true;
651
- device.windowsPhone = true;
652
- }
653
-
654
- let silk = /Silk/.test(ua); // detected in browsers
655
-
656
- if (device.windows || device.macOS || (device.linux && !silk) || device.chromeOS)
657
- {
658
- device.desktop = true;
659
- }
660
-
661
- // Windows Phone / Table reset
662
- if (device.windowsPhone || ((/Windows NT/i.test(ua)) && (/Touch/i.test(ua))))
663
- {
664
- device.desktop = false;
665
- }
666
-
667
- }
668
-
669
- /**
670
- * Check HTML5 features of the host environment.
671
- */
672
- function _checkFeatures () {
673
-
674
- device.canvas = !!window['CanvasRenderingContext2D'] || device.cocoonJS;
675
-
676
- try {
677
- device.localStorage = !!localStorage.getItem;
678
- } catch (error) {
679
- device.localStorage = false;
680
- }
681
-
682
- device.file = !!window['File'] && !!window['FileReader'] && !!window['FileList'] && !!window['Blob'];
683
- device.fileSystem = !!window['requestFileSystem'];
684
-
685
- device.webGL = ( function () { try { let canvas = document.createElement( 'canvas' ); /*Force screencanvas to false*/ canvas.screencanvas = false; return !! window.WebGLRenderingContext && ( canvas.getContext( 'webgl' ) || canvas.getContext( 'experimental-webgl' ) ); } catch( e ) { return false; } } )();
686
- device.webGL = !!device.webGL;
687
-
688
- device.worker = !!window['Worker'];
689
-
690
- device.pointerLock = 'pointerLockElement' in document || 'mozPointerLockElement' in document || 'webkitPointerLockElement' in document;
691
-
692
- device.quirksMode = (document.compatMode === 'CSS1Compat') ? false : true;
693
-
694
- navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia || navigator.oGetUserMedia;
695
-
696
- window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL;
697
-
698
- device.getUserMedia = device.getUserMedia && !!navigator.getUserMedia && !!window.URL;
699
-
700
- // Older versions of firefox (< 21) apparently claim support but user media does not actually work
701
- if (device.firefox && device.firefoxVersion < 21)
702
- {
703
- device.getUserMedia = false;
704
- }
705
-
706
- // Excludes iOS versions as they generally wrap UIWebView (eg. Safari WebKit) and it
707
- // is safer to not try and use the fast copy-over method.
708
- if (!device.iOS && (device.ie || device.firefox || device.chrome))
709
- {
710
- device.canvasBitBltShift = true;
711
- }
712
-
713
- // Known not to work
714
- if (device.safari || device.mobileSafari)
715
- {
716
- device.canvasBitBltShift = false;
717
- }
718
-
719
- }
720
-
721
- /**
722
- * Checks/configures letious input.
723
- */
724
- function _checkInput () {
725
-
726
- if ('ontouchstart' in document.documentElement || (window.navigator.maxTouchPoints && window.navigator.maxTouchPoints >= 1))
727
- {
728
- device.touch = true;
729
- }
730
-
731
- if (window.navigator.msPointerEnabled || window.navigator.pointerEnabled)
732
- {
733
- device.mspointer = true;
734
- }
735
-
736
- if (!device.cocoonJS)
737
- {
738
- // See https://developer.mozilla.org/en-US/docs/Web/Events/wheel
739
- if ('onwheel' in window || (device.ie && 'WheelEvent' in window))
740
- {
741
- // DOM3 Wheel Event: FF 17+, IE 9+, Chrome 31+, Safari 7+
742
- device.wheelEvent = 'wheel';
743
- }
744
- else if ('onmousewheel' in window)
745
- {
746
- // Non-FF legacy: IE 6-9, Chrome 1-31, Safari 5-7.
747
- device.wheelEvent = 'mousewheel';
748
- }
749
- else if (device.firefox && 'MouseScrollEvent' in window)
750
- {
751
- // FF prior to 17. This should probably be scrubbed.
752
- device.wheelEvent = 'DOMMouseScroll';
753
- }
754
- }
755
-
756
- }
757
-
758
- /**
759
- * Checks for support of the Full Screen API.
760
- */
761
- function _checkFullScreenSupport () {
762
-
763
- let fs = [
764
- 'requestFullscreen',
765
- 'requestFullScreen',
766
- 'webkitRequestFullscreen',
767
- 'webkitRequestFullScreen',
768
- 'msRequestFullscreen',
769
- 'msRequestFullScreen',
770
- 'mozRequestFullScreen',
771
- 'mozRequestFullscreen'
772
- ];
773
-
774
- let element = document.createElement('div');
775
-
776
- for (let i = 0; i < fs.length; i++)
777
- {
778
- if (element[fs[i]])
779
- {
780
- device.fullscreen = true;
781
- device.requestFullscreen = fs[i];
782
- break;
783
- }
784
- }
785
-
786
- let cfs = [
787
- 'cancelFullScreen',
788
- 'exitFullscreen',
789
- 'webkitCancelFullScreen',
790
- 'webkitExitFullscreen',
791
- 'msCancelFullScreen',
792
- 'msExitFullscreen',
793
- 'mozCancelFullScreen',
794
- 'mozExitFullscreen'
795
- ];
796
-
797
- if (device.fullscreen)
798
- {
799
- for (let i = 0; i < cfs.length; i++)
800
- {
801
- if (document[cfs[i]])
802
- {
803
- device.cancelFullscreen = cfs[i];
804
- break;
805
- }
806
- }
807
- }
808
-
809
- // Keyboard Input?
810
- if (window['Element'] && Element['ALLOW_KEYBOARD_INPUT'])
811
- {
812
- device.fullscreenKeyboard = true;
813
- }
814
-
815
- }
816
-
817
- /**
818
- * Check what browser is game running in.
819
- */
820
- function _checkBrowser () {
821
-
822
- let ua = navigator.userAgent;
823
-
824
- if (/Arora/.test(ua))
825
- {
826
- device.arora = true;
827
- }
828
- else if (/Chrome\/(\d+)/.test(ua) && !device.windowsPhone)
829
- {
830
- device.chrome = true;
831
- device.chromeVersion = parseInt(RegExp.$1, 10);
832
- }
833
- else if (/Epiphany/.test(ua))
834
- {
835
- device.epiphany = true;
836
- }
837
- else if (/Firefox\D+(\d+)/.test(ua))
838
- {
839
- device.firefox = true;
840
- device.firefoxVersion = parseInt(RegExp.$1, 10);
841
- }
842
- else if (/AppleWebKit/.test(ua) && device.iOS)
843
- {
844
- device.mobileSafari = true;
845
- }
846
- else if (/MSIE (\d+\.\d+);/.test(ua))
847
- {
848
- device.ie = true;
849
- device.ieVersion = parseInt(RegExp.$1, 10);
850
- }
851
- else if (/Midori/.test(ua))
852
- {
853
- device.midori = true;
854
- }
855
- else if (/Opera/.test(ua))
856
- {
857
- device.opera = true;
858
- }
859
- else if (/Safari/.test(ua) && !device.windowsPhone)
860
- {
861
- device.safari = true;
862
- }
863
- else if (/Trident\/(\d+\.\d+)(.*)rv:(\d+\.\d+)/.test(ua))
864
- {
865
- device.ie = true;
866
- device.trident = true;
867
- device.tridentVersion = parseInt(RegExp.$1, 10);
868
- device.ieVersion = parseInt(RegExp.$3, 10);
869
- }
870
-
871
- // Silk gets its own if clause because its ua also contains 'Safari'
872
- if (/Silk/.test(ua))
873
- {
874
- device.silk = true;
875
- }
876
-
877
- // WebApp mode in iOS
878
- if (navigator['standalone'])
879
- {
880
- device.webApp = true;
881
- }
882
-
883
- if (typeof window.cordova !== "undefined")
884
- {
885
- device.cordova = true;
886
- }
887
-
888
- if (typeof process !== "undefined" && typeof require !== "undefined")
889
- {
890
- device.node = true;
891
- }
892
-
893
- if (device.node && typeof process.versions === 'object')
894
- {
895
- device.nodeWebkit = !!process.versions['node-webkit'];
896
-
897
- device.electron = !!process.versions.electron;
898
- }
899
-
900
- if (navigator['isCocoonJS'])
901
- {
902
- device.cocoonJS = true;
903
- }
904
-
905
- if (device.cocoonJS)
906
- {
907
- try {
908
- device.cocoonJSApp = (typeof CocoonJS !== "undefined");
909
- }
910
- catch(error)
911
- {
912
- device.cocoonJSApp = false;
913
- }
914
- }
915
-
916
- if (typeof window.ejecta !== "undefined")
917
- {
918
- device.ejecta = true;
919
- }
920
-
921
- if (/Crosswalk/.test(ua))
922
- {
923
- device.crosswalk = true;
924
- }
925
-
926
- }
927
-
928
- /**
929
- * Check video support.
930
- */
931
- function _checkVideo () {
932
-
933
- let videoElement = document.createElement("video");
934
- let result = false;
935
-
936
- try {
937
- if (result = !!videoElement.canPlayType)
938
- {
939
- if (videoElement.canPlayType('video/ogg; codecs="theora"').replace(/^no$/, ''))
940
- {
941
- device.oggVideo = true;
942
- }
943
-
944
- if (videoElement.canPlayType('video/mp4; codecs="avc1.42E01E"').replace(/^no$/, ''))
945
- {
946
- // Without QuickTime, this value will be `undefined`. github.com/Modernizr/Modernizr/issues/546
947
- device.h264Video = true;
948
- device.mp4Video = true;
949
- }
950
-
951
- if (videoElement.canPlayType('video/webm; codecs="vp8, vorbis"').replace(/^no$/, ''))
952
- {
953
- device.webmVideo = true;
954
- }
955
-
956
- if (videoElement.canPlayType('video/webm; codecs="vp9"').replace(/^no$/, ''))
957
- {
958
- device.vp9Video = true;
959
- }
960
-
961
- if (videoElement.canPlayType('application/x-mpegURL; codecs="avc1.42E01E"').replace(/^no$/, ''))
962
- {
963
- device.hlsVideo = true;
964
- }
965
- }
966
- } catch (e) {}
967
- }
968
-
969
- /**
970
- * Check audio support.
971
- */
972
- function _checkAudio () {
973
-
974
- device.audioData = !!(window['Audio']);
975
- device.webAudio = !!(window['AudioContext'] || window['webkitAudioContext']);
976
- let audioElement = document.createElement('audio');
977
- let result = false;
978
-
979
- try {
980
- if (result = !!audioElement.canPlayType)
981
- {
982
- if (audioElement.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/, ''))
983
- {
984
- device.ogg = true;
985
- }
986
-
987
- if (audioElement.canPlayType('audio/ogg; codecs="opus"').replace(/^no$/, '') || audioElement.canPlayType('audio/opus;').replace(/^no$/, ''))
988
- {
989
- device.opus = true;
990
- }
991
-
992
- if (audioElement.canPlayType('audio/mpeg;').replace(/^no$/, ''))
993
- {
994
- device.mp3 = true;
995
- }
996
-
997
- // Mimetypes accepted:
998
- // developer.mozilla.org/En/Media_formats_supported_by_the_audio_and_video_elements
999
- // bit.ly/iphoneoscodecs
1000
- if (audioElement.canPlayType('audio/wav; codecs="1"').replace(/^no$/, ''))
1001
- {
1002
- device.wav = true;
1003
- }
1004
-
1005
- if (audioElement.canPlayType('audio/x-m4a;') || audioElement.canPlayType('audio/aac;').replace(/^no$/, ''))
1006
- {
1007
- device.m4a = true;
1008
- }
1009
-
1010
- if (audioElement.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/, ''))
1011
- {
1012
- device.webm = true;
1013
- }
1014
- }
1015
- } catch (e) {
1016
- }
1017
-
1018
- }
1019
-
1020
- /**
1021
- * Check PixelRatio, iOS device, Vibration API, ArrayBuffers and endianess.
1022
- */
1023
- function _checkDevice () {
1024
-
1025
- device.pixelRatio = window['devicePixelRatio'] || 1;
1026
- device.iPhone = navigator.userAgent.toLowerCase().indexOf('iphone') != -1;
1027
- device.iPhone4 = (device.pixelRatio == 2 && device.iPhone);
1028
- device.iPhone5 = device.pixelRatio === 2 && device.iPhone &&
1029
- ((screen.availWidth === 320 && screen.availHeight === 568) || (screen.availWidth === 568 && screen.availHeight === 320));
1030
- device.iPad = navigator.userAgent.toLowerCase().indexOf('ipad') != -1;
1031
-
1032
- if (typeof Int8Array !== 'undefined')
1033
- {
1034
- device.typedArray = true;
1035
- }
1036
- else
1037
- {
1038
- device.typedArray = false;
1039
- }
1040
-
1041
- if (typeof ArrayBuffer !== 'undefined' && typeof Uint8Array !== 'undefined' && typeof Uint32Array !== 'undefined')
1042
- {
1043
- device.littleEndian = _checkIsLittleEndian();
1044
- device.LITTLE_ENDIAN = device.littleEndian;
1045
- }
1046
-
1047
- device.support32bit = (typeof ArrayBuffer !== "undefined" && typeof Uint8ClampedArray !== "undefined" && typeof Int32Array !== "undefined" && device.littleEndian !== null && _checkIsUint8ClampedImageData());
1048
-
1049
- navigator.vibrate = navigator.vibrate || navigator.webkitVibrate || navigator.mozVibrate || navigator.msVibrate;
1050
-
1051
- if (navigator.vibrate)
1052
- {
1053
- device.vibration = true;
1054
- }
1055
-
1056
- }
1057
-
1058
- /**
1059
- * Check Little or Big Endian system.
1060
- *
1061
- * @author Matt DesLauriers (@mattdesl)
1062
- */
1063
- function _checkIsLittleEndian () {
1064
-
1065
- let a = new ArrayBuffer(4);
1066
- let b = new Uint8Array(a);
1067
- let c = new Uint32Array(a);
1068
-
1069
- b[0] = 0xa1;
1070
- b[1] = 0xb2;
1071
- b[2] = 0xc3;
1072
- b[3] = 0xd4;
1073
-
1074
- if (c[0] == 0xd4c3b2a1)
1075
- {
1076
- return true;
1077
- }
1078
-
1079
- if (c[0] == 0xa1b2c3d4)
1080
- {
1081
- return false;
1082
- }
1083
- else
1084
- {
1085
- // Could not determine endianness
1086
- return null;
1087
- }
1088
-
1089
- }
1090
-
1091
- /**
1092
- * Test to see if ImageData uses CanvasPixelArray or Uint8ClampedArray.
1093
- *
1094
- * @author Matt DesLauriers (@mattdesl)
1095
- */
1096
- function _checkIsUint8ClampedImageData () {
1097
-
1098
- if (Uint8ClampedArray === undefined)
1099
- {
1100
- return false;
1101
- }
1102
-
1103
- let elem = document.createElement('canvas');
1104
- let ctx = elem.getContext('2d');
1105
-
1106
- if (!ctx)
1107
- {
1108
- return false;
1109
- }
1110
-
1111
- let image = ctx.createImageData(1, 1);
1112
-
1113
- return image.data instanceof Uint8ClampedArray;
1114
-
1115
- }
1116
-
1117
- /**
1118
- * Check whether the host environment support 3D CSS.
1119
- */
1120
- function _checkCSS3D () {
1121
-
1122
- let el = document.createElement('p');
1123
- let has3d;
1124
- let transforms = {
1125
- 'webkitTransform': '-webkit-transform',
1126
- 'OTransform': '-o-transform',
1127
- 'msTransform': '-ms-transform',
1128
- 'MozTransform': '-moz-transform',
1129
- 'transform': 'transform'
1130
- };
1131
-
1132
- // Add it to the body to get the computed style.
1133
- document.body.insertBefore(el, null);
1134
-
1135
- for (let t in transforms)
1136
- {
1137
- if (el.style[t] !== undefined)
1138
- {
1139
- el.style[t] = "translate3d(1px,1px,1px)";
1140
- has3d = window.getComputedStyle(el).getPropertyValue(transforms[t]);
1141
- }
1142
- }
1143
-
1144
- document.body.removeChild(el);
1145
- device.css3D = (has3d !== undefined && has3d.length > 0 && has3d !== "none");
1146
-
1147
- }
1148
-
1149
- // Run the checks
1150
- _checkOS();
1151
- _checkAudio();
1152
- _checkVideo();
1153
- _checkBrowser();
1154
- _checkCSS3D();
1155
- _checkDevice();
1156
- _checkFeatures();
1157
- _checkFullScreenSupport();
1158
- _checkInput();
1159
-
1160
- };
1161
-
1162
- /**
1163
- * Check whether the host environment can play audio.
1164
- *
1165
- * @method canPlayAudio
1166
- * @memberof Phaser.Device.prototype
1167
- * @param {String} type - One of 'mp3, 'ogg', 'm4a', 'wav', 'webm' or 'opus'.
1168
- * @return {boolean} True if the given file type is supported by the browser, otherwise false.
1169
- */
1170
- LibDevice.canPlayAudio = function (type) {
1171
-
1172
- if (type === 'mp3' && this.mp3)
1173
- {
1174
- return true;
1175
- }
1176
- else if (type === 'ogg' && (this.ogg || this.opus))
1177
- {
1178
- return true;
1179
- }
1180
- else if (type === 'm4a' && this.m4a)
1181
- {
1182
- return true;
1183
- }
1184
- else if (type === 'opus' && this.opus)
1185
- {
1186
- return true;
1187
- }
1188
- else if (type === 'wav' && this.wav)
1189
- {
1190
- return true;
1191
- }
1192
- else if (type === 'webm' && this.webm)
1193
- {
1194
- return true;
1195
- }
1196
-
1197
- return false;
1198
-
1199
- };
1200
-
1201
- /**
1202
- * Check whether the host environment can play video files.
1203
- *
1204
- * @method canPlayVideo
1205
- * @memberof Phaser.Device.prototype
1206
- * @param {String} type - One of 'mp4, 'ogg', 'webm' or 'mpeg'.
1207
- * @return {boolean} True if the given file type is supported by the browser, otherwise false.
1208
- */
1209
- LibDevice.canPlayVideo = function (type) {
1210
-
1211
- if (type === 'webm' && (this.webmVideo || this.vp9Video))
1212
- {
1213
- return true;
1214
- }
1215
- else if (type === 'mp4' && (this.mp4Video || this.h264Video))
1216
- {
1217
- return true;
1218
- }
1219
- else if ((type === 'ogg' || type === 'ogv') && this.oggVideo)
1220
- {
1221
- return true;
1222
- }
1223
- else if (type === 'mpeg' && this.hlsVideo)
1224
- {
1225
- return true;
1226
- }
1227
-
1228
- return false;
1229
-
1230
- };
1231
-
1232
- /**
1233
- * Check whether the console is open.
1234
- * Note that this only works in Firefox with Firebug and earlier versions of Chrome.
1235
- * It used to work in Chrome, but then they removed the ability: {@link http://src.chromium.org/viewvc/blink?view=revision&revision=151136}
1236
- *
1237
- * @method isConsoleOpen
1238
- * @memberof Phaser.Device.prototype
1239
- */
1240
- LibDevice.isConsoleOpen = function () {
1241
-
1242
- if (window.console && window.console['firebug'])
1243
- {
1244
- return true;
1245
- }
1246
-
1247
- if (window.console)
1248
- {
1249
- console.profile();
1250
- console.profileEnd();
1251
-
1252
- if (console.clear)
1253
- {
1254
- console.clear();
1255
- }
1256
-
1257
- if (console['profiles'])
1258
- {
1259
- return console['profiles'].length > 0;
1260
- }
1261
- }
1262
-
1263
- return false;
1264
-
1265
- };
1266
-
1267
- /**
1268
- * Detect if the host is a an Android Stock browser.
1269
- * This is available before the device "ready" event.
1270
- *
1271
- * Authors might want to scale down on effects and switch to the CANVAS rendering method on those devices.
1272
- *
1273
- * @example
1274
- * let defaultRenderingMode = Phaser.Device.isAndroidStockBrowser() ? Phaser.CANVAS : Phaser.AUTO;
1275
- *
1276
- * @method isAndroidStockBrowser
1277
- * @memberof Phaser.Device.prototype
1278
- */
1279
- LibDevice.isAndroidStockBrowser = function () {
1280
-
1281
- let matches = window.navigator.userAgent.match(/Android.*AppleWebKit\/([\d.]+)/);
1282
- return matches && matches[1] < 537;
1283
-
1284
- };
1285
-
1286
- module.exports = LibDevice;
1
+ LibDevice = function () {
2
+
3
+ /**
4
+ * The time the device became ready.
5
+ * @property {integer} deviceReadyAt
6
+ * @protected
7
+ */
8
+ this.deviceReadyAt = 0;
9
+
10
+ /**
11
+ * The time as which initialization has completed.
12
+ * @property {boolean} initialized
13
+ * @protected
14
+ */
15
+ this.initialized = false;
16
+
17
+ // Browser / Host / Operating System
18
+
19
+ /**
20
+ * @property {boolean} desktop - Is running on a desktop?
21
+ * @default
22
+ */
23
+ this.desktop = false;
24
+
25
+ /**
26
+ * @property {boolean} iOS - Is running on iOS?
27
+ * @default
28
+ */
29
+ this.iOS = false;
30
+
31
+ /**
32
+ * @property {boolean} cocoonJS - Is the game running under CocoonJS?
33
+ * @default
34
+ */
35
+ this.cocoonJS = false;
36
+
37
+ /**
38
+ * @property {boolean} cocoonJSApp - Is this game running with CocoonJS.App?
39
+ * @default
40
+ */
41
+ this.cocoonJSApp = false;
42
+
43
+ /**
44
+ * @property {boolean} cordova - Is the game running under Apache Cordova?
45
+ * @default
46
+ */
47
+ this.cordova = false;
48
+
49
+ /**
50
+ * @property {boolean} node - Is the game running under Node.js?
51
+ * @default
52
+ */
53
+ this.node = false;
54
+
55
+ /**
56
+ * @property {boolean} nodeWebkit - Is the game running under Node-Webkit?
57
+ * @default
58
+ */
59
+ this.nodeWebkit = false;
60
+
61
+ /**
62
+ * @property {boolean} electron - Is the game running under GitHub Electron?
63
+ * @default
64
+ */
65
+ this.electron = false;
66
+
67
+ /**
68
+ * @property {boolean} ejecta - Is the game running under Ejecta?
69
+ * @default
70
+ */
71
+ this.ejecta = false;
72
+
73
+ /**
74
+ * @property {boolean} crosswalk - Is the game running under the Intel Crosswalk XDK?
75
+ * @default
76
+ */
77
+ this.crosswalk = false;
78
+
79
+ /**
80
+ * @property {boolean} android - Is running on android?
81
+ * @default
82
+ */
83
+ this.android = false;
84
+
85
+ /**
86
+ * @property {boolean} chromeOS - Is running on chromeOS?
87
+ * @default
88
+ */
89
+ this.chromeOS = false;
90
+
91
+ /**
92
+ * @property {boolean} linux - Is running on linux?
93
+ * @default
94
+ */
95
+ this.linux = false;
96
+
97
+ /**
98
+ * @property {boolean} macOS - Is running on macOS?
99
+ * @default
100
+ */
101
+ this.macOS = false;
102
+
103
+ /**
104
+ * @property {boolean} windows - Is running on windows?
105
+ * @default
106
+ */
107
+ this.windows = false;
108
+
109
+ /**
110
+ * @property {boolean} windowsPhone - Is running on a Windows Phone?
111
+ * @default
112
+ */
113
+ this.windowsPhone = false;
114
+
115
+ // Features
116
+
117
+ /**
118
+ * @property {boolean} canvas - Is canvas available?
119
+ * @default
120
+ */
121
+ this.canvas = false;
122
+
123
+ /**
124
+ * @property {?boolean} canvasBitBltShift - True if canvas supports a 'copy' bitblt onto itself when the source and destination regions overlap.
125
+ * @default
126
+ */
127
+ this.canvasBitBltShift = null;
128
+
129
+ /**
130
+ * @property {boolean} webGL - Is webGL available?
131
+ * @default
132
+ */
133
+ this.webGL = false;
134
+
135
+ /**
136
+ * @property {boolean} file - Is file available?
137
+ * @default
138
+ */
139
+ this.file = false;
140
+
141
+ /**
142
+ * @property {boolean} fileSystem - Is fileSystem available?
143
+ * @default
144
+ */
145
+ this.fileSystem = false;
146
+
147
+ /**
148
+ * @property {boolean} localStorage - Is localStorage available?
149
+ * @default
150
+ */
151
+ this.localStorage = false;
152
+
153
+ /**
154
+ * @property {boolean} worker - Is worker available?
155
+ * @default
156
+ */
157
+ this.worker = false;
158
+
159
+ /**
160
+ * @property {boolean} css3D - Is css3D available?
161
+ * @default
162
+ */
163
+ this.css3D = false;
164
+
165
+ /**
166
+ * @property {boolean} pointerLock - Is Pointer Lock available?
167
+ * @default
168
+ */
169
+ this.pointerLock = false;
170
+
171
+ /**
172
+ * @property {boolean} typedArray - Does the browser support TypedArrays?
173
+ * @default
174
+ */
175
+ this.typedArray = false;
176
+
177
+ /**
178
+ * @property {boolean} vibration - Does the device support the Vibration API?
179
+ * @default
180
+ */
181
+ this.vibration = false;
182
+
183
+ /**
184
+ * @property {boolean} getUserMedia - Does the device support the getUserMedia API?
185
+ * @default
186
+ */
187
+ this.getUserMedia = true;
188
+
189
+ /**
190
+ * @property {boolean} quirksMode - Is the browser running in strict mode (false) or quirks mode? (true)
191
+ * @default
192
+ */
193
+ this.quirksMode = false;
194
+
195
+ // Input
196
+
197
+ /**
198
+ * @property {boolean} touch - Is touch available?
199
+ * @default
200
+ */
201
+ this.touch = false;
202
+
203
+ /**
204
+ * @property {boolean} mspointer - Is mspointer available?
205
+ * @default
206
+ */
207
+ this.mspointer = false;
208
+
209
+ /**
210
+ * @property {?string} wheelType - The newest type of Wheel/Scroll event supported: 'wheel', 'mousewheel', 'DOMMouseScroll'
211
+ * @default
212
+ * @protected
213
+ */
214
+ this.wheelEvent = null;
215
+
216
+ // Browser
217
+
218
+ /**
219
+ * @property {boolean} arora - Set to true if running in Arora.
220
+ * @default
221
+ */
222
+ this.arora = false;
223
+
224
+ /**
225
+ * @property {boolean} chrome - Set to true if running in Chrome.
226
+ * @default
227
+ */
228
+ this.chrome = false;
229
+
230
+ /**
231
+ * @property {number} chromeVersion - If running in Chrome this will contain the major version number.
232
+ * @default
233
+ */
234
+ this.chromeVersion = 0;
235
+
236
+ /**
237
+ * @property {boolean} epiphany - Set to true if running in Epiphany.
238
+ * @default
239
+ */
240
+ this.epiphany = false;
241
+
242
+ /**
243
+ * @property {boolean} firefox - Set to true if running in Firefox.
244
+ * @default
245
+ */
246
+ this.firefox = false;
247
+
248
+ /**
249
+ * @property {number} firefoxVersion - If running in Firefox this will contain the major version number.
250
+ * @default
251
+ */
252
+ this.firefoxVersion = 0;
253
+
254
+ /**
255
+ * @property {boolean} ie - Set to true if running in Internet Explorer.
256
+ * @default
257
+ */
258
+ this.ie = false;
259
+
260
+ /**
261
+ * @property {number} ieVersion - If running in Internet Explorer this will contain the major version number. Beyond IE10 you should use Device.trident and Device.tridentVersion.
262
+ * @default
263
+ */
264
+ this.ieVersion = 0;
265
+
266
+ /**
267
+ * @property {boolean} trident - Set to true if running a Trident version of Internet Explorer (IE11+)
268
+ * @default
269
+ */
270
+ this.trident = false;
271
+
272
+ /**
273
+ * @property {number} tridentVersion - If running in Internet Explorer 11 this will contain the major version number. See {@link http://msdn.microsoft.com/en-us/library/ie/ms537503(v=vs.85).aspx}
274
+ * @default
275
+ */
276
+ this.tridentVersion = 0;
277
+
278
+ /**
279
+ * @property {boolean} mobileSafari - Set to true if running in Mobile Safari.
280
+ * @default
281
+ */
282
+ this.mobileSafari = false;
283
+
284
+ /**
285
+ * @property {boolean} midori - Set to true if running in Midori.
286
+ * @default
287
+ */
288
+ this.midori = false;
289
+
290
+ /**
291
+ * @property {boolean} opera - Set to true if running in Opera.
292
+ * @default
293
+ */
294
+ this.opera = false;
295
+
296
+ /**
297
+ * @property {boolean} safari - Set to true if running in Safari.
298
+ * @default
299
+ */
300
+ this.safari = false;
301
+
302
+ /**
303
+ * @property {boolean} webApp - Set to true if running as a WebApp, i.e. within a WebView
304
+ * @default
305
+ */
306
+ this.webApp = false;
307
+
308
+ /**
309
+ * @property {boolean} silk - Set to true if running in the Silk browser (as used on the Amazon Kindle)
310
+ * @default
311
+ */
312
+ this.silk = false;
313
+
314
+ // Audio
315
+
316
+ /**
317
+ * @property {boolean} audioData - Are Audio tags available?
318
+ * @default
319
+ */
320
+ this.audioData = false;
321
+
322
+ /**
323
+ * @property {boolean} webAudio - Is the WebAudio API available?
324
+ * @default
325
+ */
326
+ this.webAudio = false;
327
+
328
+ /**
329
+ * @property {boolean} ogg - Can this device play ogg files?
330
+ * @default
331
+ */
332
+ this.ogg = false;
333
+
334
+ /**
335
+ * @property {boolean} opus - Can this device play opus files?
336
+ * @default
337
+ */
338
+ this.opus = false;
339
+
340
+ /**
341
+ * @property {boolean} mp3 - Can this device play mp3 files?
342
+ * @default
343
+ */
344
+ this.mp3 = false;
345
+
346
+ /**
347
+ * @property {boolean} wav - Can this device play wav files?
348
+ * @default
349
+ */
350
+ this.wav = false;
351
+
352
+ /**
353
+ * Can this device play m4a files?
354
+ * @property {boolean} m4a - True if this device can play m4a files.
355
+ * @default
356
+ */
357
+ this.m4a = false;
358
+
359
+ /**
360
+ * @property {boolean} webm - Can this device play webm files?
361
+ * @default
362
+ */
363
+ this.webm = false;
364
+
365
+ // Video
366
+
367
+ /**
368
+ * @property {boolean} oggVideo - Can this device play ogg video files?
369
+ * @default
370
+ */
371
+ this.oggVideo = false;
372
+
373
+ /**
374
+ * @property {boolean} h264Video - Can this device play h264 mp4 video files?
375
+ * @default
376
+ */
377
+ this.h264Video = false;
378
+
379
+ /**
380
+ * @property {boolean} mp4Video - Can this device play h264 mp4 video files?
381
+ * @default
382
+ */
383
+ this.mp4Video = false;
384
+
385
+ /**
386
+ * @property {boolean} webmVideo - Can this device play webm video files?
387
+ * @default
388
+ */
389
+ this.webmVideo = false;
390
+
391
+ /**
392
+ * @property {boolean} vp9Video - Can this device play vp9 video files?
393
+ * @default
394
+ */
395
+ this.vp9Video = false;
396
+
397
+ /**
398
+ * @property {boolean} hlsVideo - Can this device play hls video files?
399
+ * @default
400
+ */
401
+ this.hlsVideo = false;
402
+
403
+ // Device
404
+
405
+ /**
406
+ * @property {boolean} iPhone - Is running on iPhone?
407
+ * @default
408
+ */
409
+ this.iPhone = false;
410
+
411
+ /**
412
+ * @property {boolean} iPhone4 - Is running on iPhone4?
413
+ * @default
414
+ */
415
+ this.iPhone4 = false;
416
+
417
+ /**
418
+ * @property {boolean} iPhone5 - Is running on iPhone5?
419
+ * @default
420
+ */
421
+ this.iPhone5 = false;
422
+
423
+ /**
424
+ * @property {boolean} iPad - Is running on iPad?
425
+ * @default
426
+ */
427
+ this.iPad = false;
428
+
429
+ // Device features
430
+
431
+ /**
432
+ * @property {number} pixelRatio - PixelRatio of the host device?
433
+ * @default
434
+ */
435
+ this.pixelRatio = 0;
436
+
437
+ /**
438
+ * @property {boolean} littleEndian - Is the device big or little endian? (only detected if the browser supports TypedArrays)
439
+ * @default
440
+ */
441
+ this.littleEndian = false;
442
+
443
+ /**
444
+ * @property {boolean} LITTLE_ENDIAN - Same value as `littleEndian`.
445
+ * @default
446
+ */
447
+ this.LITTLE_ENDIAN = false;
448
+
449
+ /**
450
+ * @property {boolean} support32bit - Does the device context support 32bit pixel manipulation using array buffer views?
451
+ * @default
452
+ */
453
+ this.support32bit = false;
454
+
455
+ /**
456
+ * @property {boolean} fullscreen - Does the browser support the Full Screen API?
457
+ * @default
458
+ */
459
+ this.fullscreen = false;
460
+
461
+ /**
462
+ * @property {string} requestFullscreen - If the browser supports the Full Screen API this holds the call you need to use to activate it.
463
+ * @default
464
+ */
465
+ this.requestFullscreen = '';
466
+
467
+ /**
468
+ * @property {string} cancelFullscreen - If the browser supports the Full Screen API this holds the call you need to use to cancel it.
469
+ * @default
470
+ */
471
+ this.cancelFullscreen = '';
472
+
473
+ /**
474
+ * @property {boolean} fullscreenKeyboard - Does the browser support access to the Keyboard during Full Screen mode?
475
+ * @default
476
+ */
477
+ this.fullscreenKeyboard = false;
478
+
479
+ /**
480
+ * Enum for possible screen orientations.
481
+ * @readonly
482
+ * @enum {string}
483
+ */
484
+ this.ScreenOrientation = {
485
+ LANDSCAPE: 'landscape',
486
+ PORTRAIT: 'portrait'
487
+ };
488
+
489
+ };
490
+
491
+ // Device is really a singleton/static entity; instantiate it
492
+ // and add new methods directly sans-prototype.
493
+ LibDevice = new LibDevice();
494
+
495
+ /**
496
+ * Add a device-ready handler and ensure the device ready sequence is started.
497
+ *
498
+ * Phaser.Device will _not_ activate or initialize until at least one `whenReady` handler is added,
499
+ * which is normally done automatically be calling `new Phaser.Game(..)`.
500
+ *
501
+ * The handler is invoked when the device is considered "ready", which may be immediately
502
+ * if the device is already "ready". See {@link Phaser.Device#deviceReadyAt deviceReadyAt}.
503
+ *
504
+ * @method
505
+ * @param {Function} handler - Callback to invoke when the device is ready. It is invoked with the given context the Phaser.Device object is supplied as the first argument.
506
+ * @param {Object} [context] - Context in which to invoke the handler
507
+ * @param {Boolean} [nonPrimer=false] - If true the device ready check will not be started.
508
+ */
509
+ LibDevice.whenReady = function (callback, context, nonPrimer) {
510
+
511
+ let readyCheck = this._readyCheck;
512
+
513
+ if (this.deviceReadyAt || !readyCheck)
514
+ {
515
+ callback.call(context, this);
516
+ }
517
+ else if (readyCheck._monitor || nonPrimer)
518
+ {
519
+ readyCheck._queue = readyCheck._queue || [];
520
+ readyCheck._queue.push([callback, context]);
521
+ }
522
+ else
523
+ {
524
+ readyCheck._monitor = readyCheck.bind(this);
525
+ readyCheck._queue = readyCheck._queue || [];
526
+ readyCheck._queue.push([callback, context]);
527
+
528
+ let cordova = typeof window.cordova !== 'undefined';
529
+ let cocoonJS = navigator['isCocoonJS'];
530
+
531
+ if (document.readyState === 'complete' || document.readyState === 'interactive')
532
+ {
533
+ // Why is there an additional timeout here?
534
+ window.setTimeout(readyCheck._monitor, 0);
535
+ }
536
+ else if (cordova && !cocoonJS)
537
+ {
538
+ // Ref. http://docs.phonegap.com/en/3.5.0/cordova_events_events.md.html#deviceready
539
+ // Cordova, but NOT Cocoon?
540
+ document.addEventListener('deviceready', readyCheck._monitor, false);
541
+ }
542
+ else
543
+ {
544
+ document.addEventListener('DOMContentLoaded', readyCheck._monitor, false);
545
+ window.addEventListener('load', readyCheck._monitor, false);
546
+ }
547
+ }
548
+
549
+ };
550
+
551
+ /**
552
+ * Internal method used for checking when the device is ready.
553
+ * This function is removed from Phaser.Device when the device becomes ready.
554
+ *
555
+ * @method
556
+ * @private
557
+ */
558
+ LibDevice._readyCheck = function () {
559
+
560
+ let readyCheck = this._readyCheck;
561
+
562
+ if (!document.body)
563
+ {
564
+ window.setTimeout(readyCheck._monitor, 20);
565
+ }
566
+ else if (!this.deviceReadyAt)
567
+ {
568
+ this.deviceReadyAt = Date.now();
569
+
570
+ document.removeEventListener('deviceready', readyCheck._monitor);
571
+ document.removeEventListener('DOMContentLoaded', readyCheck._monitor);
572
+ window.removeEventListener('load', readyCheck._monitor);
573
+
574
+ this._initialize();
575
+ this.initialized = true;
576
+
577
+ let item;
578
+ while ((item = readyCheck._queue.shift()))
579
+ {
580
+ let callback = item[0];
581
+ let context = item[1];
582
+ callback.call(context, this);
583
+ }
584
+
585
+ // Remove no longer useful methods and properties.
586
+ this._readyCheck = null;
587
+ this._initialize = null;
588
+ }
589
+
590
+ };
591
+
592
+ /**
593
+ * Internal method to initialize the capability checks.
594
+ * This function is removed from Phaser.Device once the device is initialized.
595
+ *
596
+ * @method
597
+ * @private
598
+ */
599
+ LibDevice._initialize = function () {
600
+
601
+ let device = this;
602
+
603
+ /**
604
+ * Check which OS is game running on.
605
+ */
606
+ function _checkOS () {
607
+
608
+ let ua = navigator.userAgent;
609
+
610
+ if (/Playstation Vita/.test(ua))
611
+ {
612
+ device.vita = true;
613
+ }
614
+ else if (/Kindle/.test(ua) || /\bKF[A-Z][A-Z]+/.test(ua) || /Silk.*Mobile Safari/.test(ua))
615
+ {
616
+ device.kindle = true;
617
+ // This will NOT detect early generations of Kindle Fire, I think there is no reliable way...
618
+ // E.g. "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us; Silk/1.1.0-80) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16 Silk-Accelerated=true"
619
+ }
620
+ else if (/Android/.test(ua))
621
+ {
622
+ device.android = true;
623
+ }
624
+ else if (/CrOS/.test(ua))
625
+ {
626
+ device.chromeOS = true;
627
+ }
628
+ else if (/iP[ao]d|iPhone/i.test(ua))
629
+ {
630
+ device.iOS = true;
631
+ }
632
+ else if (/Linux/.test(ua))
633
+ {
634
+ device.linux = true;
635
+ }
636
+ else if (/Mac OS/.test(ua))
637
+ {
638
+ device.macOS = true;
639
+ }
640
+ else if (/Windows/.test(ua))
641
+ {
642
+ device.windows = true;
643
+ }
644
+
645
+ if (/Windows Phone/i.test(ua) || /IEMobile/i.test(ua))
646
+ {
647
+ device.android = false;
648
+ device.iOS = false;
649
+ device.macOS = false;
650
+ device.windows = true;
651
+ device.windowsPhone = true;
652
+ }
653
+
654
+ let silk = /Silk/.test(ua); // detected in browsers
655
+
656
+ if (device.windows || device.macOS || (device.linux && !silk) || device.chromeOS)
657
+ {
658
+ device.desktop = true;
659
+ }
660
+
661
+ // Windows Phone / Table reset
662
+ if (device.windowsPhone || ((/Windows NT/i.test(ua)) && (/Touch/i.test(ua))))
663
+ {
664
+ device.desktop = false;
665
+ }
666
+
667
+ }
668
+
669
+ /**
670
+ * Check HTML5 features of the host environment.
671
+ */
672
+ function _checkFeatures () {
673
+
674
+ device.canvas = !!window['CanvasRenderingContext2D'] || device.cocoonJS;
675
+
676
+ try {
677
+ device.localStorage = !!localStorage.getItem;
678
+ } catch (error) {
679
+ device.localStorage = false;
680
+ }
681
+
682
+ device.file = !!window['File'] && !!window['FileReader'] && !!window['FileList'] && !!window['Blob'];
683
+ device.fileSystem = !!window['requestFileSystem'];
684
+
685
+ device.webGL = ( function () { try { let canvas = document.createElement( 'canvas' ); /*Force screencanvas to false*/ canvas.screencanvas = false; return !! window.WebGLRenderingContext && ( canvas.getContext( 'webgl' ) || canvas.getContext( 'experimental-webgl' ) ); } catch( e ) { return false; } } )();
686
+ device.webGL = !!device.webGL;
687
+
688
+ device.worker = !!window['Worker'];
689
+
690
+ device.pointerLock = 'pointerLockElement' in document || 'mozPointerLockElement' in document || 'webkitPointerLockElement' in document;
691
+
692
+ device.quirksMode = (document.compatMode === 'CSS1Compat') ? false : true;
693
+
694
+ navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia || navigator.oGetUserMedia;
695
+
696
+ window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL;
697
+
698
+ device.getUserMedia = device.getUserMedia && !!navigator.getUserMedia && !!window.URL;
699
+
700
+ // Older versions of firefox (< 21) apparently claim support but user media does not actually work
701
+ if (device.firefox && device.firefoxVersion < 21)
702
+ {
703
+ device.getUserMedia = false;
704
+ }
705
+
706
+ // Excludes iOS versions as they generally wrap UIWebView (eg. Safari WebKit) and it
707
+ // is safer to not try and use the fast copy-over method.
708
+ if (!device.iOS && (device.ie || device.firefox || device.chrome))
709
+ {
710
+ device.canvasBitBltShift = true;
711
+ }
712
+
713
+ // Known not to work
714
+ if (device.safari || device.mobileSafari)
715
+ {
716
+ device.canvasBitBltShift = false;
717
+ }
718
+
719
+ }
720
+
721
+ /**
722
+ * Checks/configures letious input.
723
+ */
724
+ function _checkInput () {
725
+
726
+ if ('ontouchstart' in document.documentElement || (window.navigator.maxTouchPoints && window.navigator.maxTouchPoints >= 1))
727
+ {
728
+ device.touch = true;
729
+ }
730
+
731
+ if (window.navigator.msPointerEnabled || window.navigator.pointerEnabled)
732
+ {
733
+ device.mspointer = true;
734
+ }
735
+
736
+ if (!device.cocoonJS)
737
+ {
738
+ // See https://developer.mozilla.org/en-US/docs/Web/Events/wheel
739
+ if ('onwheel' in window || (device.ie && 'WheelEvent' in window))
740
+ {
741
+ // DOM3 Wheel Event: FF 17+, IE 9+, Chrome 31+, Safari 7+
742
+ device.wheelEvent = 'wheel';
743
+ }
744
+ else if ('onmousewheel' in window)
745
+ {
746
+ // Non-FF legacy: IE 6-9, Chrome 1-31, Safari 5-7.
747
+ device.wheelEvent = 'mousewheel';
748
+ }
749
+ else if (device.firefox && 'MouseScrollEvent' in window)
750
+ {
751
+ // FF prior to 17. This should probably be scrubbed.
752
+ device.wheelEvent = 'DOMMouseScroll';
753
+ }
754
+ }
755
+
756
+ }
757
+
758
+ /**
759
+ * Checks for support of the Full Screen API.
760
+ */
761
+ function _checkFullScreenSupport () {
762
+
763
+ let fs = [
764
+ 'requestFullscreen',
765
+ 'requestFullScreen',
766
+ 'webkitRequestFullscreen',
767
+ 'webkitRequestFullScreen',
768
+ 'msRequestFullscreen',
769
+ 'msRequestFullScreen',
770
+ 'mozRequestFullScreen',
771
+ 'mozRequestFullscreen'
772
+ ];
773
+
774
+ let element = document.createElement('div');
775
+
776
+ for (let i = 0; i < fs.length; i++)
777
+ {
778
+ if (element[fs[i]])
779
+ {
780
+ device.fullscreen = true;
781
+ device.requestFullscreen = fs[i];
782
+ break;
783
+ }
784
+ }
785
+
786
+ let cfs = [
787
+ 'cancelFullScreen',
788
+ 'exitFullscreen',
789
+ 'webkitCancelFullScreen',
790
+ 'webkitExitFullscreen',
791
+ 'msCancelFullScreen',
792
+ 'msExitFullscreen',
793
+ 'mozCancelFullScreen',
794
+ 'mozExitFullscreen'
795
+ ];
796
+
797
+ if (device.fullscreen)
798
+ {
799
+ for (let i = 0; i < cfs.length; i++)
800
+ {
801
+ if (document[cfs[i]])
802
+ {
803
+ device.cancelFullscreen = cfs[i];
804
+ break;
805
+ }
806
+ }
807
+ }
808
+
809
+ // Keyboard Input?
810
+ if (window['Element'] && Element['ALLOW_KEYBOARD_INPUT'])
811
+ {
812
+ device.fullscreenKeyboard = true;
813
+ }
814
+
815
+ }
816
+
817
+ /**
818
+ * Check what browser is game running in.
819
+ */
820
+ function _checkBrowser () {
821
+
822
+ let ua = navigator.userAgent;
823
+
824
+ if (/Arora/.test(ua))
825
+ {
826
+ device.arora = true;
827
+ }
828
+ else if (/Chrome\/(\d+)/.test(ua) && !device.windowsPhone)
829
+ {
830
+ device.chrome = true;
831
+ device.chromeVersion = parseInt(RegExp.$1, 10);
832
+ }
833
+ else if (/Epiphany/.test(ua))
834
+ {
835
+ device.epiphany = true;
836
+ }
837
+ else if (/Firefox\D+(\d+)/.test(ua))
838
+ {
839
+ device.firefox = true;
840
+ device.firefoxVersion = parseInt(RegExp.$1, 10);
841
+ }
842
+ else if (/AppleWebKit/.test(ua) && device.iOS)
843
+ {
844
+ device.mobileSafari = true;
845
+ }
846
+ else if (/MSIE (\d+\.\d+);/.test(ua))
847
+ {
848
+ device.ie = true;
849
+ device.ieVersion = parseInt(RegExp.$1, 10);
850
+ }
851
+ else if (/Midori/.test(ua))
852
+ {
853
+ device.midori = true;
854
+ }
855
+ else if (/Opera/.test(ua))
856
+ {
857
+ device.opera = true;
858
+ }
859
+ else if (/Safari/.test(ua) && !device.windowsPhone)
860
+ {
861
+ device.safari = true;
862
+ }
863
+ else if (/Trident\/(\d+\.\d+)(.*)rv:(\d+\.\d+)/.test(ua))
864
+ {
865
+ device.ie = true;
866
+ device.trident = true;
867
+ device.tridentVersion = parseInt(RegExp.$1, 10);
868
+ device.ieVersion = parseInt(RegExp.$3, 10);
869
+ }
870
+
871
+ // Silk gets its own if clause because its ua also contains 'Safari'
872
+ if (/Silk/.test(ua))
873
+ {
874
+ device.silk = true;
875
+ }
876
+
877
+ // WebApp mode in iOS
878
+ if (navigator['standalone'])
879
+ {
880
+ device.webApp = true;
881
+ }
882
+
883
+ if (typeof window.cordova !== "undefined")
884
+ {
885
+ device.cordova = true;
886
+ }
887
+
888
+ if (typeof process !== "undefined" && typeof require !== "undefined")
889
+ {
890
+ device.node = true;
891
+ }
892
+
893
+ if (device.node && typeof process.versions === 'object')
894
+ {
895
+ device.nodeWebkit = !!process.versions['node-webkit'];
896
+
897
+ device.electron = !!process.versions.electron;
898
+ }
899
+
900
+ if (navigator['isCocoonJS'])
901
+ {
902
+ device.cocoonJS = true;
903
+ }
904
+
905
+ if (device.cocoonJS)
906
+ {
907
+ try {
908
+ device.cocoonJSApp = (typeof CocoonJS !== "undefined");
909
+ }
910
+ catch(error)
911
+ {
912
+ device.cocoonJSApp = false;
913
+ }
914
+ }
915
+
916
+ if (typeof window.ejecta !== "undefined")
917
+ {
918
+ device.ejecta = true;
919
+ }
920
+
921
+ if (/Crosswalk/.test(ua))
922
+ {
923
+ device.crosswalk = true;
924
+ }
925
+
926
+ }
927
+
928
+ /**
929
+ * Check video support.
930
+ */
931
+ function _checkVideo () {
932
+
933
+ let videoElement = document.createElement("video");
934
+ let result = false;
935
+
936
+ try {
937
+ if (result = !!videoElement.canPlayType)
938
+ {
939
+ if (videoElement.canPlayType('video/ogg; codecs="theora"').replace(/^no$/, ''))
940
+ {
941
+ device.oggVideo = true;
942
+ }
943
+
944
+ if (videoElement.canPlayType('video/mp4; codecs="avc1.42E01E"').replace(/^no$/, ''))
945
+ {
946
+ // Without QuickTime, this value will be `undefined`. github.com/Modernizr/Modernizr/issues/546
947
+ device.h264Video = true;
948
+ device.mp4Video = true;
949
+ }
950
+
951
+ if (videoElement.canPlayType('video/webm; codecs="vp8, vorbis"').replace(/^no$/, ''))
952
+ {
953
+ device.webmVideo = true;
954
+ }
955
+
956
+ if (videoElement.canPlayType('video/webm; codecs="vp9"').replace(/^no$/, ''))
957
+ {
958
+ device.vp9Video = true;
959
+ }
960
+
961
+ if (videoElement.canPlayType('application/x-mpegURL; codecs="avc1.42E01E"').replace(/^no$/, ''))
962
+ {
963
+ device.hlsVideo = true;
964
+ }
965
+ }
966
+ } catch (e) {}
967
+ }
968
+
969
+ /**
970
+ * Check audio support.
971
+ */
972
+ function _checkAudio () {
973
+
974
+ device.audioData = !!(window['Audio']);
975
+ device.webAudio = !!(window['AudioContext'] || window['webkitAudioContext']);
976
+ let audioElement = document.createElement('audio');
977
+ let result = false;
978
+
979
+ try {
980
+ if (result = !!audioElement.canPlayType)
981
+ {
982
+ if (audioElement.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/, ''))
983
+ {
984
+ device.ogg = true;
985
+ }
986
+
987
+ if (audioElement.canPlayType('audio/ogg; codecs="opus"').replace(/^no$/, '') || audioElement.canPlayType('audio/opus;').replace(/^no$/, ''))
988
+ {
989
+ device.opus = true;
990
+ }
991
+
992
+ if (audioElement.canPlayType('audio/mpeg;').replace(/^no$/, ''))
993
+ {
994
+ device.mp3 = true;
995
+ }
996
+
997
+ // Mimetypes accepted:
998
+ // developer.mozilla.org/En/Media_formats_supported_by_the_audio_and_video_elements
999
+ // bit.ly/iphoneoscodecs
1000
+ if (audioElement.canPlayType('audio/wav; codecs="1"').replace(/^no$/, ''))
1001
+ {
1002
+ device.wav = true;
1003
+ }
1004
+
1005
+ if (audioElement.canPlayType('audio/x-m4a;') || audioElement.canPlayType('audio/aac;').replace(/^no$/, ''))
1006
+ {
1007
+ device.m4a = true;
1008
+ }
1009
+
1010
+ if (audioElement.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/, ''))
1011
+ {
1012
+ device.webm = true;
1013
+ }
1014
+ }
1015
+ } catch (e) {
1016
+ }
1017
+
1018
+ }
1019
+
1020
+ /**
1021
+ * Check PixelRatio, iOS device, Vibration API, ArrayBuffers and endianess.
1022
+ */
1023
+ function _checkDevice () {
1024
+
1025
+ device.pixelRatio = window['devicePixelRatio'] || 1;
1026
+ device.iPhone = navigator.userAgent.toLowerCase().indexOf('iphone') != -1;
1027
+ device.iPhone4 = (device.pixelRatio == 2 && device.iPhone);
1028
+ device.iPhone5 = device.pixelRatio === 2 && device.iPhone &&
1029
+ ((screen.availWidth === 320 && screen.availHeight === 568) || (screen.availWidth === 568 && screen.availHeight === 320));
1030
+ device.iPad = navigator.userAgent.toLowerCase().indexOf('ipad') != -1;
1031
+
1032
+ if (typeof Int8Array !== 'undefined')
1033
+ {
1034
+ device.typedArray = true;
1035
+ }
1036
+ else
1037
+ {
1038
+ device.typedArray = false;
1039
+ }
1040
+
1041
+ if (typeof ArrayBuffer !== 'undefined' && typeof Uint8Array !== 'undefined' && typeof Uint32Array !== 'undefined')
1042
+ {
1043
+ device.littleEndian = _checkIsLittleEndian();
1044
+ device.LITTLE_ENDIAN = device.littleEndian;
1045
+ }
1046
+
1047
+ device.support32bit = (typeof ArrayBuffer !== "undefined" && typeof Uint8ClampedArray !== "undefined" && typeof Int32Array !== "undefined" && device.littleEndian !== null && _checkIsUint8ClampedImageData());
1048
+
1049
+ navigator.vibrate = navigator.vibrate || navigator.webkitVibrate || navigator.mozVibrate || navigator.msVibrate;
1050
+
1051
+ if (navigator.vibrate)
1052
+ {
1053
+ device.vibration = true;
1054
+ }
1055
+
1056
+ }
1057
+
1058
+ /**
1059
+ * Check Little or Big Endian system.
1060
+ *
1061
+ * @author Matt DesLauriers (@mattdesl)
1062
+ */
1063
+ function _checkIsLittleEndian () {
1064
+
1065
+ let a = new ArrayBuffer(4);
1066
+ let b = new Uint8Array(a);
1067
+ let c = new Uint32Array(a);
1068
+
1069
+ b[0] = 0xa1;
1070
+ b[1] = 0xb2;
1071
+ b[2] = 0xc3;
1072
+ b[3] = 0xd4;
1073
+
1074
+ if (c[0] == 0xd4c3b2a1)
1075
+ {
1076
+ return true;
1077
+ }
1078
+
1079
+ if (c[0] == 0xa1b2c3d4)
1080
+ {
1081
+ return false;
1082
+ }
1083
+ else
1084
+ {
1085
+ // Could not determine endianness
1086
+ return null;
1087
+ }
1088
+
1089
+ }
1090
+
1091
+ /**
1092
+ * Test to see if ImageData uses CanvasPixelArray or Uint8ClampedArray.
1093
+ *
1094
+ * @author Matt DesLauriers (@mattdesl)
1095
+ */
1096
+ function _checkIsUint8ClampedImageData () {
1097
+
1098
+ if (Uint8ClampedArray === undefined)
1099
+ {
1100
+ return false;
1101
+ }
1102
+
1103
+ let elem = document.createElement('canvas');
1104
+ let ctx = elem.getContext('2d');
1105
+
1106
+ if (!ctx)
1107
+ {
1108
+ return false;
1109
+ }
1110
+
1111
+ let image = ctx.createImageData(1, 1);
1112
+
1113
+ return image.data instanceof Uint8ClampedArray;
1114
+
1115
+ }
1116
+
1117
+ /**
1118
+ * Check whether the host environment support 3D CSS.
1119
+ */
1120
+ function _checkCSS3D () {
1121
+
1122
+ let el = document.createElement('p');
1123
+ let has3d;
1124
+ let transforms = {
1125
+ 'webkitTransform': '-webkit-transform',
1126
+ 'OTransform': '-o-transform',
1127
+ 'msTransform': '-ms-transform',
1128
+ 'MozTransform': '-moz-transform',
1129
+ 'transform': 'transform'
1130
+ };
1131
+
1132
+ // Add it to the body to get the computed style.
1133
+ document.body.insertBefore(el, null);
1134
+
1135
+ for (let t in transforms)
1136
+ {
1137
+ if (el.style[t] !== undefined)
1138
+ {
1139
+ el.style[t] = "translate3d(1px,1px,1px)";
1140
+ has3d = window.getComputedStyle(el).getPropertyValue(transforms[t]);
1141
+ }
1142
+ }
1143
+
1144
+ document.body.removeChild(el);
1145
+ device.css3D = (has3d !== undefined && has3d.length > 0 && has3d !== "none");
1146
+
1147
+ }
1148
+
1149
+ // Run the checks
1150
+ _checkOS();
1151
+ _checkAudio();
1152
+ _checkVideo();
1153
+ _checkBrowser();
1154
+ _checkCSS3D();
1155
+ _checkDevice();
1156
+ _checkFeatures();
1157
+ _checkFullScreenSupport();
1158
+ _checkInput();
1159
+
1160
+ };
1161
+
1162
+ /**
1163
+ * Check whether the host environment can play audio.
1164
+ *
1165
+ * @method canPlayAudio
1166
+ * @memberof Phaser.Device.prototype
1167
+ * @param {String} type - One of 'mp3, 'ogg', 'm4a', 'wav', 'webm' or 'opus'.
1168
+ * @return {boolean} True if the given file type is supported by the browser, otherwise false.
1169
+ */
1170
+ LibDevice.canPlayAudio = function (type) {
1171
+
1172
+ if (type === 'mp3' && this.mp3)
1173
+ {
1174
+ return true;
1175
+ }
1176
+ else if (type === 'ogg' && (this.ogg || this.opus))
1177
+ {
1178
+ return true;
1179
+ }
1180
+ else if (type === 'm4a' && this.m4a)
1181
+ {
1182
+ return true;
1183
+ }
1184
+ else if (type === 'opus' && this.opus)
1185
+ {
1186
+ return true;
1187
+ }
1188
+ else if (type === 'wav' && this.wav)
1189
+ {
1190
+ return true;
1191
+ }
1192
+ else if (type === 'webm' && this.webm)
1193
+ {
1194
+ return true;
1195
+ }
1196
+
1197
+ return false;
1198
+
1199
+ };
1200
+
1201
+ /**
1202
+ * Check whether the host environment can play video files.
1203
+ *
1204
+ * @method canPlayVideo
1205
+ * @memberof Phaser.Device.prototype
1206
+ * @param {String} type - One of 'mp4, 'ogg', 'webm' or 'mpeg'.
1207
+ * @return {boolean} True if the given file type is supported by the browser, otherwise false.
1208
+ */
1209
+ LibDevice.canPlayVideo = function (type) {
1210
+
1211
+ if (type === 'webm' && (this.webmVideo || this.vp9Video))
1212
+ {
1213
+ return true;
1214
+ }
1215
+ else if (type === 'mp4' && (this.mp4Video || this.h264Video))
1216
+ {
1217
+ return true;
1218
+ }
1219
+ else if ((type === 'ogg' || type === 'ogv') && this.oggVideo)
1220
+ {
1221
+ return true;
1222
+ }
1223
+ else if (type === 'mpeg' && this.hlsVideo)
1224
+ {
1225
+ return true;
1226
+ }
1227
+
1228
+ return false;
1229
+
1230
+ };
1231
+
1232
+ /**
1233
+ * Check whether the console is open.
1234
+ * Note that this only works in Firefox with Firebug and earlier versions of Chrome.
1235
+ * It used to work in Chrome, but then they removed the ability: {@link http://src.chromium.org/viewvc/blink?view=revision&revision=151136}
1236
+ *
1237
+ * @method isConsoleOpen
1238
+ * @memberof Phaser.Device.prototype
1239
+ */
1240
+ LibDevice.isConsoleOpen = function () {
1241
+
1242
+ if (window.console && window.console['firebug'])
1243
+ {
1244
+ return true;
1245
+ }
1246
+
1247
+ if (window.console)
1248
+ {
1249
+ console.profile();
1250
+ console.profileEnd();
1251
+
1252
+ if (console.clear)
1253
+ {
1254
+ console.clear();
1255
+ }
1256
+
1257
+ if (console['profiles'])
1258
+ {
1259
+ return console['profiles'].length > 0;
1260
+ }
1261
+ }
1262
+
1263
+ return false;
1264
+
1265
+ };
1266
+
1267
+ /**
1268
+ * Detect if the host is a an Android Stock browser.
1269
+ * This is available before the device "ready" event.
1270
+ *
1271
+ * Authors might want to scale down on effects and switch to the CANVAS rendering method on those devices.
1272
+ *
1273
+ * @example
1274
+ * let defaultRenderingMode = Phaser.Device.isAndroidStockBrowser() ? Phaser.CANVAS : Phaser.AUTO;
1275
+ *
1276
+ * @method isAndroidStockBrowser
1277
+ * @memberof Phaser.Device.prototype
1278
+ */
1279
+ LibDevice.isAndroidStockBrowser = function () {
1280
+
1281
+ let matches = window.navigator.userAgent.match(/Android.*AppleWebKit\/([\d.]+)/);
1282
+ return matches && matches[1] < 537;
1283
+
1284
+ };
1285
+
1286
+ module.exports = LibDevice;