@hkdigital/lib-core 0.5.15 → 0.5.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.
@@ -3,7 +3,11 @@
3
3
 
4
4
  import {
5
5
  getGameWidthOnLandscape,
6
- getGameWidthOnPortrait
6
+ getGameWidthOnPortrait,
7
+ isIOS,
8
+ isIpadOS,
9
+ getOS,
10
+ getIsMobile
7
11
  } from './gamebox.util.js';
8
12
 
9
13
  import ScaledContainer from './ScaledContainer.svelte';
@@ -127,7 +131,8 @@
127
131
  }
128
132
  } );
129
133
 
130
- const isAppleMobile = /iPhone|iPod/.test(navigator.userAgent);
134
+ // iPad is also considered Apple mobile
135
+ const isAppleMobile = isIOS();
131
136
 
132
137
  let os = $state();
133
138
  let isIos = $derived(os === 'iOS');
@@ -359,35 +364,6 @@
359
364
  }
360
365
  });
361
366
 
362
-
363
- function getOS() {
364
- if (isAppleMobile) {
365
- return 'iOS';
366
- } else if (/Android/.test(navigator.userAgent)) {
367
- return 'Android';
368
- } else {
369
- return 'unknown';
370
- }
371
- }
372
-
373
- /**
374
- * Returns true if a device is a mobile phone (or similar)
375
- */
376
- function getIsMobile() {
377
- // @ts-ignore
378
- if (navigator?.userAgentData?.mobile !== undefined) {
379
- // Supports for mobile flag
380
- // @ts-ignore
381
- return navigator.userAgentData.mobile;
382
- } else if (isAppleMobile) {
383
- return true;
384
- } else if (/Android/.test(navigator.userAgent)) {
385
- return true;
386
- }
387
-
388
- return false;
389
- }
390
-
391
367
  /**
392
368
  * Returns true if the window is in full screen
393
369
  * - Checks if CSS thinks we're in fullscreen mode
@@ -1,3 +1,27 @@
1
+ /**
2
+ * Check if the device is running iOS (iPhone, iPod, or iPad)
3
+ *
4
+ * @returns {boolean} true if iOS device
5
+ */
6
+ export function isIOS(): boolean;
7
+ /**
8
+ * Check if the device is running iPadOS
9
+ *
10
+ * @returns {boolean} true if iPadOS device
11
+ */
12
+ export function isIpadOS(): boolean;
13
+ /**
14
+ * Get the operating system of the device
15
+ *
16
+ * @returns {'iOS'|'Android'|'unknown'} operating system
17
+ */
18
+ export function getOS(): "iOS" | "Android" | "unknown";
19
+ /**
20
+ * Check if the device is a mobile phone or tablet
21
+ *
22
+ * @returns {boolean} true if mobile device
23
+ */
24
+ export function getIsMobile(): boolean;
1
25
  /**
2
26
  * Get game width for landscape mode
3
27
  *
@@ -2,6 +2,67 @@ export const ERROR_WINDOW_SIZE_NOT_LANDSCAPE = 'Window size is not landsccape';
2
2
 
3
3
  export const ERROR_WINDOW_SIZE_NOT_PORTRAIT = 'Window size is not portrait';
4
4
 
5
+ /**
6
+ * Check if the device is running iOS (iPhone, iPod, or iPad)
7
+ *
8
+ * @returns {boolean} true if iOS device
9
+ */
10
+ export function isIOS() {
11
+ if (/iPad|iPhone|iPod/.test(navigator.platform)) {
12
+ return true;
13
+ } else {
14
+ return navigator.maxTouchPoints &&
15
+ navigator.maxTouchPoints > 2 &&
16
+ /MacIntel/.test(navigator.platform);
17
+ }
18
+ }
19
+
20
+ /**
21
+ * Check if the device is running iPadOS
22
+ *
23
+ * @returns {boolean} true if iPadOS device
24
+ */
25
+ export function isIpadOS() {
26
+ return navigator.maxTouchPoints &&
27
+ navigator.maxTouchPoints > 2 &&
28
+ /MacIntel/.test(navigator.platform);
29
+ }
30
+
31
+ /**
32
+ * Get the operating system of the device
33
+ *
34
+ * @returns {'iOS'|'Android'|'unknown'} operating system
35
+ */
36
+ export function getOS() {
37
+ if (isIOS()) {
38
+ return 'iOS';
39
+ } else if (/Android/.test(navigator.userAgent)) {
40
+ return 'Android';
41
+ } else {
42
+ return 'unknown';
43
+ }
44
+ }
45
+
46
+ /**
47
+ * Check if the device is a mobile phone or tablet
48
+ *
49
+ * @returns {boolean} true if mobile device
50
+ */
51
+ export function getIsMobile() {
52
+ // @ts-ignore
53
+ if (navigator?.userAgentData?.mobile !== undefined) {
54
+ // Supports for mobile flag
55
+ // @ts-ignore
56
+ return navigator.userAgentData.mobile;
57
+ } else if (isIOS()) {
58
+ return true;
59
+ } else if (/Android/.test(navigator.userAgent)) {
60
+ return true;
61
+ }
62
+
63
+ return false;
64
+ }
65
+
5
66
  /**
6
67
  * Get game width for landscape mode
7
68
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hkdigital/lib-core",
3
- "version": "0.5.15",
3
+ "version": "0.5.16",
4
4
  "author": {
5
5
  "name": "HKdigital",
6
6
  "url": "https://hkdigital.nl"