@pinnacle0/web-ui 0.6.30 → 0.6.32
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/package.json
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Orientation detection utility for mobile and desktop devices.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* For Android,
|
|
5
|
+
* Uses the ScreenOrientation API for checking the orientation of the screen.
|
|
6
|
+
* For Deprecated browsers, it uses the window.orientation API.
|
|
7
7
|
*
|
|
8
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/
|
|
8
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/ScreenOrientation
|
|
9
|
+
*
|
|
10
|
+
* For iOS 26.0+ PWA, it does not dispatch any event when the orientation changes,
|
|
11
|
+
* For mobile Safari,
|
|
12
|
+
* Use media queries to check the orientation of the screen for iOS.
|
|
13
|
+
*
|
|
14
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_media_queries/Using_media_queries
|
|
9
15
|
*/
|
|
10
16
|
export type OrientationType = "portrait" | "landscape";
|
|
11
17
|
export type Subscriber = (orientation: OrientationType) => void;
|
|
@@ -1,33 +1,50 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Orientation detection utility for mobile and desktop devices.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* For Android,
|
|
5
|
+
* Uses the ScreenOrientation API for checking the orientation of the screen.
|
|
6
|
+
* For Deprecated browsers, it uses the window.orientation API.
|
|
7
7
|
*
|
|
8
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/
|
|
8
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/ScreenOrientation
|
|
9
|
+
*
|
|
10
|
+
* For iOS 26.0+ PWA, it does not dispatch any event when the orientation changes,
|
|
11
|
+
* For mobile Safari,
|
|
12
|
+
* Use media queries to check the orientation of the screen for iOS.
|
|
13
|
+
*
|
|
14
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_media_queries/Using_media_queries
|
|
9
15
|
*/
|
|
16
|
+
import { BrowserUtil } from "../BrowserUtil";
|
|
17
|
+
const supportScreenOrientationAPI = typeof window.screen.orientation !== "undefined";
|
|
18
|
+
// DO NOT USE matchMedia for non-safari browsers, because it can be incorrect if keyboard is popped up
|
|
19
|
+
// Tested on iOS safari: 26.0-15.2
|
|
20
|
+
// See Note from: https://developer.mozilla.org/en-US/docs/Web/CSS/@media/orientation
|
|
21
|
+
const isIOSSafari = BrowserUtil.os() === "ios" && navigator.userAgent.includes("Safari");
|
|
10
22
|
function subscribe(subscriber) {
|
|
11
23
|
const handler = () => subscriber(current());
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
return () =>
|
|
24
|
+
if (isIOSSafari) {
|
|
25
|
+
window.matchMedia("(orientation: portrait)").addEventListener("change", handler);
|
|
26
|
+
return () => window.matchMedia("(orientation: portrait)").removeEventListener("change", handler);
|
|
27
|
+
}
|
|
28
|
+
else if (supportScreenOrientationAPI) {
|
|
29
|
+
window.screen.orientation.addEventListener("change", handler);
|
|
30
|
+
return () => window.screen.orientation.removeEventListener("change", handler);
|
|
19
31
|
}
|
|
20
32
|
else {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return () => portraitQuery.removeListener(mediaHandler);
|
|
33
|
+
window.addEventListener("orientationchange", handler);
|
|
34
|
+
return () => window.removeEventListener("orientationchange", handler, false);
|
|
24
35
|
}
|
|
25
36
|
}
|
|
26
37
|
function current() {
|
|
27
38
|
try {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
39
|
+
if (isIOSSafari) {
|
|
40
|
+
return window.matchMedia("(orientation: portrait)").matches ? "portrait" : "landscape";
|
|
41
|
+
}
|
|
42
|
+
else if (supportScreenOrientationAPI) {
|
|
43
|
+
return window.screen.orientation.angle === 0 ? "portrait" : "landscape";
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
return window.orientation === 0 ? "portrait" : "landscape";
|
|
47
|
+
}
|
|
31
48
|
}
|
|
32
49
|
catch {
|
|
33
50
|
// Do not use window.innerHeight/window.innerWidth comparison, because it is incorrect if keyboard is popped up
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/util/OrientationUtil/index.tsx"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/util/OrientationUtil/index.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAE3C,MAAM,2BAA2B,GAAG,OAAO,MAAM,CAAC,MAAM,CAAC,WAAW,KAAK,WAAW,CAAC;AAMrF,sGAAsG;AACtG,kCAAkC;AAClC,qFAAqF;AACrF,MAAM,WAAW,GAAG,WAAW,CAAC,EAAE,EAAE,KAAK,KAAK,IAAI,SAAS,CAAC,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAEzF,SAAS,SAAS,CAAC,UAAsB;IACrC,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC;IAC5C,IAAI,WAAW,EAAE,CAAC;QACd,MAAM,CAAC,UAAU,CAAC,yBAAyB,CAAC,CAAC,gBAAgB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACjF,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,yBAAyB,CAAC,CAAC,mBAAmB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACrG,CAAC;SAAM,IAAI,2BAA2B,EAAE,CAAC;QACrC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,gBAAgB,CAAC,QAAQ,EAAE,OA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