()
| 444 | * @category Application |
| 445 | */ |
| 446 | export function getScreenOrientation(): string { |
| 447 | const PORTRAIT = "portrait"; |
| 448 | const LANDSCAPE = "landscape"; |
| 449 | |
| 450 | const screen = globalThis.screen; |
| 451 | |
| 452 | // first try using "standard" values |
| 453 | if (screenOrientation) { |
| 454 | const orientation = prefixed( |
| 455 | "orientation", |
| 456 | screen as unknown as Record<string, unknown>, |
| 457 | ); |
| 458 | if ( |
| 459 | typeof orientation === "object" && |
| 460 | orientation !== null && |
| 461 | typeof (orientation as ScreenOrientation).type === "string" |
| 462 | ) { |
| 463 | // Screen Orientation API specification |
| 464 | return (orientation as ScreenOrientation).type; |
| 465 | } else if (typeof orientation === "string") { |
| 466 | // moz/ms-orientation are strings |
| 467 | return orientation; |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | // check using the deprecated API |
| 472 | if ( |
| 473 | typeof (globalThis as { orientation?: number }).orientation === "number" |
| 474 | ) { |
| 475 | return Math.abs((globalThis as { orientation: number }).orientation) === 90 |
| 476 | ? LANDSCAPE |
| 477 | : PORTRAIT; |
| 478 | } |
| 479 | |
| 480 | // fallback to window size check |
| 481 | return globalThis.outerWidth > globalThis.outerHeight ? LANDSCAPE : PORTRAIT; |
| 482 | } |
| 483 | |
| 484 | /** |
| 485 | * locks the device screen into the specified orientation.<br> |
no test coverage detected