@rpg-engine/shared 0.8.95 → 0.8.97

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.
@@ -1,3 +1,5 @@
1
- export declare const isMobileOrTablet: () => boolean;
2
1
  export declare const isMobile: () => boolean;
2
+ export declare const isTablet: () => boolean;
3
+ export declare const isMobileOrTablet: () => boolean;
4
+ export declare const isDesktop: () => boolean;
3
5
  //# sourceMappingURL=deviceHelpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"deviceHelpers.d.ts","sourceRoot":"","sources":["../../src/helpers/deviceHelpers.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,gBAAgB,QAAO,OAEnC,CAAC;AAEF,eAAO,MAAM,QAAQ,QAAO,OAE3B,CAAC"}
1
+ {"version":3,"file":"deviceHelpers.d.ts","sourceRoot":"","sources":["../../src/helpers/deviceHelpers.ts"],"names":[],"mappings":"AAoBA,eAAO,MAAM,QAAQ,QAAO,OAG3B,CAAC;AAEF,eAAO,MAAM,QAAQ,QAAO,OAG3B,CAAC;AAEF,eAAO,MAAM,gBAAgB,QAAO,OAEnC,CAAC;AAEF,eAAO,MAAM,SAAS,QAAO,OAE5B,CAAC"}
@@ -1,17 +1,34 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isMobile = exports.isMobileOrTablet = void 0;
4
- const mobile_device_detect_1 = require("mobile-device-detect");
5
- const isSmallerThanBreakpoint = (breakpoint) => {
6
- const mql = window.matchMedia(`(max-width: ${breakpoint}) and (orientation: portrait), (max-height: ${breakpoint}) and (orientation: landscape)`);
7
- return mql.matches;
3
+ exports.isDesktop = exports.isMobileOrTablet = exports.isTablet = exports.isMobile = void 0;
4
+ const isTouchScreen = () => "ontouchstart" in window || navigator.maxTouchPoints > 0;
5
+ const checkUserAgent = (regex) => {
6
+ const userAgent = navigator.userAgent || navigator.vendor;
7
+ return regex.test(userAgent);
8
8
  };
9
- const isMobileOrTablet = () => {
10
- return mobile_device_detect_1.isMobile !== null && mobile_device_detect_1.isMobile !== void 0 ? mobile_device_detect_1.isMobile : (isSmallerThanBreakpoint("767px") && !isSmallerThanBreakpoint("479px"));
9
+ const hasMotionAndOrientation = () => {
10
+ return "DeviceMotionEvent" in window && "DeviceOrientationEvent" in window;
11
+ };
12
+ const estimatePerformance = () => {
13
+ const isHighPerformance = window.matchMedia("(min-resolution: 2dppx)").matches;
14
+ return isHighPerformance;
11
15
  };
12
- exports.isMobileOrTablet = isMobileOrTablet;
13
16
  const isMobile = () => {
14
- return mobile_device_detect_1.isMobileOnly !== null && mobile_device_detect_1.isMobileOnly !== void 0 ? mobile_device_detect_1.isMobileOnly : isSmallerThanBreakpoint("479px");
17
+ const mobileRegex = /iPhone|Android.+Mobile/i;
18
+ return checkUserAgent(mobileRegex) && isTouchScreen() && !estimatePerformance();
15
19
  };
16
20
  exports.isMobile = isMobile;
21
+ const isTablet = () => {
22
+ const tabletRegex = /iPad|Android/i;
23
+ return checkUserAgent(tabletRegex) && isTouchScreen() && hasMotionAndOrientation();
24
+ };
25
+ exports.isTablet = isTablet;
26
+ const isMobileOrTablet = () => {
27
+ return (0, exports.isMobile)() || (0, exports.isTablet)();
28
+ };
29
+ exports.isMobileOrTablet = isMobileOrTablet;
30
+ const isDesktop = () => {
31
+ return !(0, exports.isMobileOrTablet)() && !isTouchScreen();
32
+ };
33
+ exports.isDesktop = isDesktop;
17
34
  //# sourceMappingURL=deviceHelpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"deviceHelpers.js","sourceRoot":"","sources":["../../src/helpers/deviceHelpers.ts"],"names":[],"mappings":";;;AAAA,+DAA8G;AAE9G,MAAM,uBAAuB,GAAG,CAAC,UAAkB,EAAW,EAAE;IAC9D,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAC3B,eAAe,UAAU,+CAA+C,UAAU,gCAAgC,CACnH,CAAC;IAEF,OAAO,GAAG,CAAC,OAAO,CAAC;AACrB,CAAC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mB,EAAE,CAAC;AAClF,CAAC,CAAC;AAHW,QAAA,QAAQ,YAGnB;AAEK,MAAM,QAAQ,GAAG,GAAY,EAAE;IACpC,MAAM,WAAW,GAAG,eAAe,CAAC;IACpC,OAAO,cAAc,CAAC,WAAW,CAAC,IAAI,aAAa,EAAE,IAAI,uBAAuB,EAAE,CAAC;AACrF,CAAC,CAAC;AAHW,QAAA,QAAQ,YAGnB;AAEK,MAAM,gBAAgB,GAAG,GAAY,EAAE;IAC5C,OAAO,IAAA,gBAAQ,GAAE,IAAI,IAAA,gBAAQ,GAAE,CAAC;AAClC,CAAC,CAAC;AAFW,QAAA,gBAAgB,oBAE3B;AAEK,MAAM,SAAS,GAAG,GAAY,EAAE;IACrC,OAAO,CAAC,IAAA,wBAAgB,GAAE,IAAI,CAAC,aAAa,EAAE,CAAC;AACjD,CAAC,CAAC;AAFW,QAAA,SAAS,aAEpB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpg-engine/shared",
3
- "version": "0.8.95",
3
+ "version": "0.8.97",
4
4
  "description": "Types shared across our API and client",
5
5
  "author": "Definya Team",
6
6
  "homepage": "",