@@ -929,23 +929,39 @@ var LibraryHTML5 = {
929
929
} ,
930
930
931
931
$screenOrientation : ( ) => {
932
- if ( ! screen ) return undefined ;
933
- return screen . orientation || screen . mozOrientation || screen . webkitOrientation || screen . msOrientation ;
932
+ if ( ! window . screen ) return undefined ;
933
+ return screen . orientation || screen [ ' mozOrientation' ] || screen [ ' webkitOrientation' ] ;
934
934
} ,
935
935
936
936
$fillOrientationChangeEventData__deps : [ '$screenOrientation' ] ,
937
937
$fillOrientationChangeEventData : ( eventStruct ) => {
938
- var orientations = [ "portrait-primary" , "portrait-secondary" , "landscape-primary" , "landscape-secondary" ] ;
939
- var orientations2 = [ "portrait" , "portrait" , "landscape" , "landscape" ] ;
940
-
941
- var orientationString = screenOrientation ( ) ;
942
- var orientation = orientations . indexOf ( orientationString ) ;
943
- if ( orientation == - 1 ) {
944
- orientation = orientations2 . indexOf ( orientationString ) ;
938
+ // OrientationType enum
939
+ var orientationsType1 = [ 'portrait-primary' , 'portrait-secondary' , 'landscape-primary' , 'landscape-secondary' ] ;
940
+ // alternative selection from OrientationLockType enum
941
+ var orientationsType2 = [ 'portrait' , 'portrait' , 'landscape' , 'landscape' ] ;
942
+
943
+ var orientationIndex = 0 ;
944
+ var orientationAngle = 0 ;
945
+ var screenOrientObj = screenOrientation ( ) ;
946
+ if ( typeof screenOrientObj === 'object' ) {
947
+ orientationIndex = orientationsType1 . indexOf ( screenOrientObj . type ) ;
948
+ if ( orientationIndex < 0 ) {
949
+ orientationIndex = orientationsType2 . indexOf ( screenOrientObj . type ) ;
950
+ }
951
+ if ( orientationIndex >= 0 ) {
952
+ orientationIndex = 1 << orientationIndex ;
953
+ }
954
+ orientationAngle = screenOrientObj . angle ;
955
+ }
956
+ #if MIN_SAFARI_VERSION < 0x100400
957
+ else {
958
+ // fallback for Safari earlier than 16.4 (March 2023)
959
+ orientationAngle = window . orientation ;
945
960
}
961
+ #endif
946
962
947
- { { { makeSetValue ( 'eventStruct' , C_STRUCTS . EmscriptenOrientationChangeEvent . orientationIndex , '1 << orientation ' , 'i32' ) } } } ;
948
- { { { makeSetValue ( 'eventStruct' , C_STRUCTS . EmscriptenOrientationChangeEvent . orientationAngle , 'orientation ' , 'i32' ) } } } ;
963
+ { { { makeSetValue ( 'eventStruct' , C_STRUCTS . EmscriptenOrientationChangeEvent . orientationIndex , 'orientationIndex ' , 'i32' ) } } } ;
964
+ { { { makeSetValue ( 'eventStruct' , C_STRUCTS . EmscriptenOrientationChangeEvent . orientationAngle , 'orientationAngle ' , 'i32' ) } } } ;
949
965
} ,
950
966
951
967
$registerOrientationChangeEventCallback__deps : [ '$JSEvents' , '$fillOrientationChangeEventData' , '$findEventTarget' , 'malloc' ] ,
@@ -971,10 +987,6 @@ var LibraryHTML5 = {
971
987
if ( { { { makeDynCall ( 'iipp' , 'callbackfunc' ) } } } ( eventTypeId , orientationChangeEvent , userData ) ) e . preventDefault ( ) ;
972
988
} ;
973
989
974
- if ( eventTypeId == { { { cDefs . EMSCRIPTEN_EVENT_ORIENTATIONCHANGE } } } && screen . mozOrientation !== undefined ) {
975
- eventTypeString = "mozorientationchange" ;
976
- }
977
-
978
990
var eventHandler = {
979
991
target,
980
992
eventTypeString,
@@ -988,13 +1000,14 @@ var LibraryHTML5 = {
988
1000
emscripten_set_orientationchange_callback_on_thread__proxy : 'sync ',
989
1001
emscripten_set_orientationchange_callback_on_thread__deps : [ '$registerOrientationChangeEventCallback' ] ,
990
1002
emscripten_set_orientationchange_callback_on_thread : ( userData , useCapture , callbackfunc , targetThread ) = > {
991
- if ( ! screen || ! screen [ 'addEventListener' ] ) return { { { cDefs . EMSCRIPTEN_RESULT_NOT_SUPPORTED } } } ;
992
- return registerOrientationChangeEventCallback ( screen , userData , useCapture , callbackfunc , { { { cDefs . EMSCRIPTEN_EVENT_ORIENTATIONCHANGE } } } , "orientationchange" , targetThread) ;
1003
+ if ( ! window . screen || ! screen . orientation ) return { { { cDefs . EMSCRIPTEN_RESULT_NOT_SUPPORTED } } } ;
1004
+ return registerOrientationChangeEventCallback ( screen . orientation , userData , useCapture , callbackfunc , { { { cDefs . EMSCRIPTEN_EVENT_ORIENTATIONCHANGE } } } , 'change' , targetThread) ;
993
1005
} ,
994
1006
995
1007
emscripten_get_orientation_status__proxy : 'sync' ,
996
1008
emscripten_get_orientation_status__deps : [ '$fillOrientationChangeEventData' , '$screenOrientation' ] ,
997
1009
emscripten_get_orientation_status : ( orientationChangeEvent ) => {
1010
+ // screenOrientation() resolving standard, window.orientation being the deprecated mobile-only
998
1011
if ( ! screenOrientation ( ) && typeof orientation == 'undefined' ) return { { { cDefs . EMSCRIPTEN_RESULT_NOT_SUPPORTED } } } ;
999
1012
fillOrientationChangeEventData ( orientationChangeEvent ) ;
1000
1013
return { { { cDefs . EMSCRIPTEN_RESULT_SUCCESS } } } ;
@@ -1014,8 +1027,6 @@ var LibraryHTML5 = {
1014
1027
succeeded = screen . mozLockOrientation ( orientations ) ;
1015
1028
} else if ( screen . webkitLockOrientation ) {
1016
1029
succeeded = screen . webkitLockOrientation ( orientations ) ;
1017
- } else if ( screen . msLockOrientation ) {
1018
- succeeded = screen . msLockOrientation ( orientations ) ;
1019
1030
} else {
1020
1031
return { { { cDefs . EMSCRIPTEN_RESULT_NOT_SUPPORTED } } } ;
1021
1032
}
@@ -1033,8 +1044,6 @@ var LibraryHTML5 = {
1033
1044
screen . mozUnlockOrientation ( ) ;
1034
1045
} else if ( screen . webkitUnlockOrientation ) {
1035
1046
screen . webkitUnlockOrientation ( ) ;
1036
- } else if ( screen . msUnlockOrientation ) {
1037
- screen . msUnlockOrientation ( ) ;
1038
1047
} else {
1039
1048
return { { { cDefs . EMSCRIPTEN_RESULT_NOT_SUPPORTED } } } ;
1040
1049
}
0 commit comments