|
| 1 | +module Web.CSSOMView.ScreenOrientation |
| 2 | + ( ScreenOrientation |
| 3 | + , lock |
| 4 | + , unlock |
| 5 | + , type_ |
| 6 | + , angle |
| 7 | + , onChange |
| 8 | + , toEventTarget |
| 9 | + , fromEventTarget |
| 10 | + ) where |
| 11 | + |
| 12 | +-- https://w3c.github.io/screen-orientation/ |
| 13 | + |
| 14 | +import Prelude |
| 15 | + |
| 16 | +import Data.Maybe (Maybe) |
| 17 | +import Effect (Effect) |
| 18 | +import Effect.Aff (Aff) |
| 19 | +import Effect.Aff.Compat (EffectFnAff, fromEffectFnAff) |
| 20 | +import Effect.Uncurried (EffectFn1, EffectFn2, runEffectFn1, runEffectFn2) |
| 21 | +import Unsafe.Coerce (unsafeCoerce) |
| 22 | +import Web.CSSOMView.ScreenOrientation.OrientationLockType (OrientationLockType) |
| 23 | +import Web.CSSOMView.ScreenOrientation.OrientationLockType as OrientationLockType |
| 24 | +import Web.CSSOMView.ScreenOrientation.OrientationType (OrientationType) |
| 25 | +import Web.CSSOMView.ScreenOrientation.OrientationType as OrientationType |
| 26 | +import Web.Event.Internal.Types (Event, EventTarget) |
| 27 | +import Web.Internal.FFI (unsafeReadProtoTagged) |
| 28 | + |
| 29 | +foreign import data ScreenOrientation :: Type |
| 30 | + |
| 31 | +foreign import lockImpl :: String -> ScreenOrientation -> EffectFnAff Unit |
| 32 | + |
| 33 | +lock :: OrientationLockType -> ScreenOrientation -> Aff Unit |
| 34 | +lock lockType = fromEffectFnAff <<< lockImpl (OrientationLockType.print lockType) |
| 35 | + |
| 36 | +foreign import unlockImpl :: EffectFn1 ScreenOrientation Unit |
| 37 | + |
| 38 | +unlock ∷ ScreenOrientation -> Effect Unit |
| 39 | +unlock = runEffectFn1 unlockImpl |
| 40 | + |
| 41 | +foreign import typeImpl :: EffectFn1 ScreenOrientation String |
| 42 | + |
| 43 | +type_ :: ScreenOrientation -> Effect (Maybe OrientationType) |
| 44 | +type_ = map OrientationType.parse <<< runEffectFn1 typeImpl |
| 45 | + |
| 46 | +foreign import angleImpl :: EffectFn1 ScreenOrientation Int |
| 47 | + |
| 48 | +angle :: ScreenOrientation -> Effect Int |
| 49 | +angle = runEffectFn1 angleImpl |
| 50 | + |
| 51 | +foreign import onChangeImpl :: EffectFn2 (Event -> Effect Unit) ScreenOrientation Unit |
| 52 | + |
| 53 | +onChange :: (Event -> Effect Unit) -> ScreenOrientation -> Effect Unit |
| 54 | +onChange = runEffectFn2 onChangeImpl |
| 55 | + |
| 56 | +toEventTarget :: ScreenOrientation -> EventTarget |
| 57 | +toEventTarget = unsafeCoerce |
| 58 | + |
| 59 | +fromEventTarget :: EventTarget -> Maybe ScreenOrientation |
| 60 | +fromEventTarget = unsafeReadProtoTagged "ScreenOrientation" |
0 commit comments