// Generated from WebIDL - DO NOT EDIT
// Source: @webref/idl/orientation-event

///|
/// DeviceOrientationEventInit dictionary
pub(all) struct DeviceOrientationEventInit {
  alpha : Nullable[Double]
  beta : Nullable[Double]
  gamma : Nullable[Double]
  absolute : Bool?
}

///|
/// Create a new DeviceOrientationEventInit with default values
pub fn DeviceOrientationEventInit::default() -> DeviceOrientationEventInit {
  DeviceOrientationEventInit::{
    alpha: Nullable::Undefined,
    beta: Nullable::Undefined,
    gamma: Nullable::Undefined,
    absolute: None,
  }
}

///|
extern "js" fn DeviceOrientationEventInit::to_js_ffi(
  self : DeviceOrientationEventInit,
) -> JsValue =
  #| (self) => ({
  #|   alpha: ((() => { const v = self.alpha; if (v.$tag === 0) return undefined; if (v.$tag === 1) return null; return v._0; })()),
  #|   beta: ((() => { const v = self.beta; if (v.$tag === 0) return undefined; if (v.$tag === 1) return null; return v._0; })()),
  #|   gamma: ((() => { const v = self.gamma; if (v.$tag === 0) return undefined; if (v.$tag === 1) return null; return v._0; })()),
  #|   absolute: (self.absolute === -1 ? undefined : self.absolute)
  #| })

///|
/// Convert to JsValue
pub fn DeviceOrientationEventInit::to_js(
  self : DeviceOrientationEventInit,
) -> JsValue {
  DeviceOrientationEventInit::to_js_ffi(self)
}

///|
extern "js" fn DeviceOrientationEventInit::from_js_ffi(
  value : JsValue,
) -> DeviceOrientationEventInit =
  #| (v) => ({
  #|   alpha: (v.alpha === undefined ? { $tag: 0 } : v.alpha === null ? { $tag: 1 } : { $tag: 2, _0: v.alpha }),
  #|   beta: (v.beta === undefined ? { $tag: 0 } : v.beta === null ? { $tag: 1 } : { $tag: 2, _0: v.beta }),
  #|   gamma: (v.gamma === undefined ? { $tag: 0 } : v.gamma === null ? { $tag: 1 } : { $tag: 2, _0: v.gamma }),
  #|   absolute: (v.absolute === undefined ? -1 : v.absolute)
  #| })

///|
/// Convert from JsValue
pub fn DeviceOrientationEventInit::from_js(
  value : JsValue,
) -> DeviceOrientationEventInit {
  DeviceOrientationEventInit::from_js_ffi(value)
}

///|
/// DeviceMotionEventAccelerationInit dictionary
pub(all) struct DeviceMotionEventAccelerationInit {
  x : Nullable[Double]
  y : Nullable[Double]
  z : Nullable[Double]
}

///|
/// Create a new DeviceMotionEventAccelerationInit with default values
pub fn DeviceMotionEventAccelerationInit::default() -> DeviceMotionEventAccelerationInit {
  DeviceMotionEventAccelerationInit::{
    x: Nullable::Undefined,
    y: Nullable::Undefined,
    z: Nullable::Undefined,
  }
}

///|
extern "js" fn DeviceMotionEventAccelerationInit::to_js_ffi(
  self : DeviceMotionEventAccelerationInit,
) -> JsValue =
  #| (self) => ({
  #|   x: ((() => { const v = self.x; if (v.$tag === 0) return undefined; if (v.$tag === 1) return null; return v._0; })()),
  #|   y: ((() => { const v = self.y; if (v.$tag === 0) return undefined; if (v.$tag === 1) return null; return v._0; })()),
  #|   z: ((() => { const v = self.z; if (v.$tag === 0) return undefined; if (v.$tag === 1) return null; return v._0; })())
  #| })

///|
/// Convert to JsValue
pub fn DeviceMotionEventAccelerationInit::to_js(
  self : DeviceMotionEventAccelerationInit,
) -> JsValue {
  DeviceMotionEventAccelerationInit::to_js_ffi(self)
}

///|
extern "js" fn DeviceMotionEventAccelerationInit::from_js_ffi(
  value : JsValue,
) -> DeviceMotionEventAccelerationInit =
  #| (v) => ({
  #|   x: (v.x === undefined ? { $tag: 0 } : v.x === null ? { $tag: 1 } : { $tag: 2, _0: v.x }),
  #|   y: (v.y === undefined ? { $tag: 0 } : v.y === null ? { $tag: 1 } : { $tag: 2, _0: v.y }),
  #|   z: (v.z === undefined ? { $tag: 0 } : v.z === null ? { $tag: 1 } : { $tag: 2, _0: v.z })
  #| })

///|
/// Convert from JsValue
pub fn DeviceMotionEventAccelerationInit::from_js(
  value : JsValue,
) -> DeviceMotionEventAccelerationInit {
  DeviceMotionEventAccelerationInit::from_js_ffi(value)
}

///|
/// DeviceMotionEventRotationRateInit dictionary
pub(all) struct DeviceMotionEventRotationRateInit {
  alpha : Nullable[Double]
  beta : Nullable[Double]
  gamma : Nullable[Double]
}

///|
/// Create a new DeviceMotionEventRotationRateInit with default values
pub fn DeviceMotionEventRotationRateInit::default() -> DeviceMotionEventRotationRateInit {
  DeviceMotionEventRotationRateInit::{
    alpha: Nullable::Undefined,
    beta: Nullable::Undefined,
    gamma: Nullable::Undefined,
  }
}

///|
extern "js" fn DeviceMotionEventRotationRateInit::to_js_ffi(
  self : DeviceMotionEventRotationRateInit,
) -> JsValue =
  #| (self) => ({
  #|   alpha: ((() => { const v = self.alpha; if (v.$tag === 0) return undefined; if (v.$tag === 1) return null; return v._0; })()),
  #|   beta: ((() => { const v = self.beta; if (v.$tag === 0) return undefined; if (v.$tag === 1) return null; return v._0; })()),
  #|   gamma: ((() => { const v = self.gamma; if (v.$tag === 0) return undefined; if (v.$tag === 1) return null; return v._0; })())
  #| })

///|
/// Convert to JsValue
pub fn DeviceMotionEventRotationRateInit::to_js(
  self : DeviceMotionEventRotationRateInit,
) -> JsValue {
  DeviceMotionEventRotationRateInit::to_js_ffi(self)
}

///|
extern "js" fn DeviceMotionEventRotationRateInit::from_js_ffi(
  value : JsValue,
) -> DeviceMotionEventRotationRateInit =
  #| (v) => ({
  #|   alpha: (v.alpha === undefined ? { $tag: 0 } : v.alpha === null ? { $tag: 1 } : { $tag: 2, _0: v.alpha }),
  #|   beta: (v.beta === undefined ? { $tag: 0 } : v.beta === null ? { $tag: 1 } : { $tag: 2, _0: v.beta }),
  #|   gamma: (v.gamma === undefined ? { $tag: 0 } : v.gamma === null ? { $tag: 1 } : { $tag: 2, _0: v.gamma })
  #| })

///|
/// Convert from JsValue
pub fn DeviceMotionEventRotationRateInit::from_js(
  value : JsValue,
) -> DeviceMotionEventRotationRateInit {
  DeviceMotionEventRotationRateInit::from_js_ffi(value)
}

///|
/// DeviceMotionEventInit dictionary
pub(all) struct DeviceMotionEventInit {
  acceleration : DeviceMotionEventAccelerationInit?
  accelerationIncludingGravity : DeviceMotionEventAccelerationInit?
  rotationRate : DeviceMotionEventRotationRateInit?
  interval : Double?
}

///|
/// Create a new DeviceMotionEventInit with default values
pub fn DeviceMotionEventInit::default() -> DeviceMotionEventInit {
  DeviceMotionEventInit::{
    acceleration: None,
    accelerationIncludingGravity: None,
    rotationRate: None,
    interval: None,
  }
}

///|
extern "js" fn DeviceMotionEventInit::to_js_ffi(
  self : DeviceMotionEventInit,
) -> JsValue =
  #| (self) => ({
  #|   acceleration: ((() => { const v = self.acceleration; if (v === undefined || v.$tag !== 1) return undefined; return v._0; })()),
  #|   accelerationIncludingGravity: ((() => { const v = self.accelerationIncludingGravity; if (v === undefined || v.$tag !== 1) return undefined; return v._0; })()),
  #|   rotationRate: ((() => { const v = self.rotationRate; if (v === undefined || v.$tag !== 1) return undefined; return v._0; })()),
  #|   interval: ((() => { const v = self.interval; if (v === undefined || v.$tag !== 1) return undefined; return v._0; })())
  #| })

///|
/// Convert to JsValue
pub fn DeviceMotionEventInit::to_js(self : DeviceMotionEventInit) -> JsValue {
  DeviceMotionEventInit::to_js_ffi(self)
}

///|
extern "js" fn DeviceMotionEventInit::from_js_ffi(
  value : JsValue,
) -> DeviceMotionEventInit =
  #| (v) => ({
  #|   acceleration: (v.acceleration === undefined ? { $tag: 0 } : { $tag: 1, _0: v.acceleration }),
  #|   accelerationIncludingGravity: (v.accelerationIncludingGravity === undefined ? { $tag: 0 } : { $tag: 1, _0: v.accelerationIncludingGravity }),
  #|   rotationRate: (v.rotationRate === undefined ? { $tag: 0 } : { $tag: 1, _0: v.rotationRate }),
  #|   interval: (v.interval === undefined ? { $tag: 0 } : { $tag: 1, _0: v.interval })
  #| })

///|
/// Convert from JsValue
pub fn DeviceMotionEventInit::from_js(value : JsValue) -> DeviceMotionEventInit {
  DeviceMotionEventInit::from_js_ffi(value)
}

///|
/// DeviceOrientationEvent interface
pub type DeviceOrientationEvent

///|
pub extern "js" fn DeviceOrientationEvent::to_js_value(
  self : DeviceOrientationEvent,
) -> JsValue =
  #| (self) => self

///|
/// Cast JsValue to DeviceOrientationEvent (unchecked)
pub extern "js" fn DeviceOrientationEvent::from_js_value(
  v : JsValue,
) -> DeviceOrientationEvent =
  #| (v) => v

///|
/// Safely cast JsValue to DeviceOrientationEvent (checked with instanceof)
pub extern "js" fn DeviceOrientationEvent::from_js_value_opt(
  v : JsValue,
) -> DeviceOrientationEvent? =
  #| (v) => (v instanceof DeviceOrientationEvent) ? { $tag: 1, _0: v } : { $tag: 0 }

///|
/// Safely cast JsValue to DeviceOrientationEvent (checked with instanceof)
pub extern "js" fn JsValue::as_device_orientation_event(
  self : JsValue,
) -> DeviceOrientationEvent? =
  #| (self) => (self instanceof DeviceOrientationEvent) ? { $tag: 1, _0: self } : { $tag: 0 }

///|
/// Cast JsValue to DeviceOrientationEvent (unchecked)
pub extern "js" fn JsValue::to_device_orientation_event(
  self : JsValue,
) -> DeviceOrientationEvent =
  #| (self) => self

///|
pub extern "js" fn DeviceOrientationEvent::to_event(
  self : DeviceOrientationEvent,
) -> Event =
  #| (self) => self

///|
/// Error type for throwing methods
pub(all) enum DeviceOrientationEventRequestPermissionError {
  NotAllowedError(JsError)
  OtherError(JsError)
} derive(Show)

///|
pub extern "js" fn DeviceOrientationEvent::new(
  type_ : String,
) -> DeviceOrientationEvent =
  #| (type_) => new DeviceOrientationEvent(type_)

///|
extern "js" fn DeviceOrientationEvent::new_with_event_init_dict_ffi(
  type_ : String,
  event_init_dict : JsValue,
) -> DeviceOrientationEvent =
  #| (type_, event_init_dict) => new DeviceOrientationEvent(type_, event_init_dict)

///|
pub fn DeviceOrientationEvent::new_with_event_init_dict(
  type_ : String,
  event_init_dict : DeviceOrientationEventInit,
) -> DeviceOrientationEvent {
  DeviceOrientationEvent::new_with_event_init_dict_ffi(
    type_,
    event_init_dict.to_js(),
  )
}

///|
pub extern "js" fn DeviceOrientationEvent::get_alpha(
  self : DeviceOrientationEvent,
) -> Double? =
  #| (self) => (() => { const v = self.alpha; return v == null ? { $tag: 0 } : { $tag: 1, _0: v }; })()

///|
pub extern "js" fn DeviceOrientationEvent::get_beta(
  self : DeviceOrientationEvent,
) -> Double? =
  #| (self) => (() => { const v = self.beta; return v == null ? { $tag: 0 } : { $tag: 1, _0: v }; })()

///|
pub extern "js" fn DeviceOrientationEvent::get_gamma(
  self : DeviceOrientationEvent,
) -> Double? =
  #| (self) => (() => { const v = self.gamma; return v == null ? { $tag: 0 } : { $tag: 1, _0: v }; })()

///|
pub extern "js" fn DeviceOrientationEvent::get_absolute(
  self : DeviceOrientationEvent,
) -> Bool =
  #| (self) => self.absolute

///|
pub extern "js" fn DeviceOrientationEvent::request_permission() -> Promise[
  Result[PermissionState, DeviceOrientationEventRequestPermissionError],
] =
  #| () => DeviceOrientationEvent.requestPermission().then(r => ({ $tag: 1, _0: r })).catch(e => ({ $tag: 0, _0: (() => { const n = (e && e.name) || ''; if (n === 'NotAllowedError') return { $tag: 0, _0: e }; return { $tag: 1, _0: e }; })() }))

///|
pub extern "js" fn DeviceOrientationEvent::request_permission_with_absolute(
  absolute : Bool,
) -> Promise[
  Result[PermissionState, DeviceOrientationEventRequestPermissionError],
] =
  #| (absolute) => DeviceOrientationEvent.requestPermission(absolute).then(r => ({ $tag: 1, _0: r })).catch(e => ({ $tag: 0, _0: (() => { const n = (e && e.name) || ''; if (n === 'NotAllowedError') return { $tag: 0, _0: e }; return { $tag: 1, _0: e }; })() }))

///|
/// DeviceMotionEventAcceleration interface
pub type DeviceMotionEventAcceleration

///|
pub extern "js" fn DeviceMotionEventAcceleration::to_js_value(
  self : DeviceMotionEventAcceleration,
) -> JsValue =
  #| (self) => self

///|
/// Cast JsValue to DeviceMotionEventAcceleration (unchecked)
pub extern "js" fn DeviceMotionEventAcceleration::from_js_value(
  v : JsValue,
) -> DeviceMotionEventAcceleration =
  #| (v) => v

///|
/// Safely cast JsValue to DeviceMotionEventAcceleration (checked with instanceof)
pub extern "js" fn DeviceMotionEventAcceleration::from_js_value_opt(
  v : JsValue,
) -> DeviceMotionEventAcceleration? =
  #| (v) => (v instanceof DeviceMotionEventAcceleration) ? { $tag: 1, _0: v } : { $tag: 0 }

///|
/// Safely cast JsValue to DeviceMotionEventAcceleration (checked with instanceof)
pub extern "js" fn JsValue::as_device_motion_event_acceleration(
  self : JsValue,
) -> DeviceMotionEventAcceleration? =
  #| (self) => (self instanceof DeviceMotionEventAcceleration) ? { $tag: 1, _0: self } : { $tag: 0 }

///|
/// Cast JsValue to DeviceMotionEventAcceleration (unchecked)
pub extern "js" fn JsValue::to_device_motion_event_acceleration(
  self : JsValue,
) -> DeviceMotionEventAcceleration =
  #| (self) => self

///|
pub extern "js" fn DeviceMotionEventAcceleration::get_x(
  self : DeviceMotionEventAcceleration,
) -> Double? =
  #| (self) => (() => { const v = self.x; return v == null ? { $tag: 0 } : { $tag: 1, _0: v }; })()

///|
pub extern "js" fn DeviceMotionEventAcceleration::get_y(
  self : DeviceMotionEventAcceleration,
) -> Double? =
  #| (self) => (() => { const v = self.y; return v == null ? { $tag: 0 } : { $tag: 1, _0: v }; })()

///|
pub extern "js" fn DeviceMotionEventAcceleration::get_z(
  self : DeviceMotionEventAcceleration,
) -> Double? =
  #| (self) => (() => { const v = self.z; return v == null ? { $tag: 0 } : { $tag: 1, _0: v }; })()

///|
/// DeviceMotionEventRotationRate interface
pub type DeviceMotionEventRotationRate

///|
pub extern "js" fn DeviceMotionEventRotationRate::to_js_value(
  self : DeviceMotionEventRotationRate,
) -> JsValue =
  #| (self) => self

///|
/// Cast JsValue to DeviceMotionEventRotationRate (unchecked)
pub extern "js" fn DeviceMotionEventRotationRate::from_js_value(
  v : JsValue,
) -> DeviceMotionEventRotationRate =
  #| (v) => v

///|
/// Safely cast JsValue to DeviceMotionEventRotationRate (checked with instanceof)
pub extern "js" fn DeviceMotionEventRotationRate::from_js_value_opt(
  v : JsValue,
) -> DeviceMotionEventRotationRate? =
  #| (v) => (v instanceof DeviceMotionEventRotationRate) ? { $tag: 1, _0: v } : { $tag: 0 }

///|
/// Safely cast JsValue to DeviceMotionEventRotationRate (checked with instanceof)
pub extern "js" fn JsValue::as_device_motion_event_rotation_rate(
  self : JsValue,
) -> DeviceMotionEventRotationRate? =
  #| (self) => (self instanceof DeviceMotionEventRotationRate) ? { $tag: 1, _0: self } : { $tag: 0 }

///|
/// Cast JsValue to DeviceMotionEventRotationRate (unchecked)
pub extern "js" fn JsValue::to_device_motion_event_rotation_rate(
  self : JsValue,
) -> DeviceMotionEventRotationRate =
  #| (self) => self

///|
pub extern "js" fn DeviceMotionEventRotationRate::get_alpha(
  self : DeviceMotionEventRotationRate,
) -> Double? =
  #| (self) => (() => { const v = self.alpha; return v == null ? { $tag: 0 } : { $tag: 1, _0: v }; })()

///|
pub extern "js" fn DeviceMotionEventRotationRate::get_beta(
  self : DeviceMotionEventRotationRate,
) -> Double? =
  #| (self) => (() => { const v = self.beta; return v == null ? { $tag: 0 } : { $tag: 1, _0: v }; })()

///|
pub extern "js" fn DeviceMotionEventRotationRate::get_gamma(
  self : DeviceMotionEventRotationRate,
) -> Double? =
  #| (self) => (() => { const v = self.gamma; return v == null ? { $tag: 0 } : { $tag: 1, _0: v }; })()

///|
/// DeviceMotionEvent interface
pub type DeviceMotionEvent

///|
pub extern "js" fn DeviceMotionEvent::to_js_value(
  self : DeviceMotionEvent,
) -> JsValue =
  #| (self) => self

///|
/// Cast JsValue to DeviceMotionEvent (unchecked)
pub extern "js" fn DeviceMotionEvent::from_js_value(
  v : JsValue,
) -> DeviceMotionEvent =
  #| (v) => v

///|
/// Safely cast JsValue to DeviceMotionEvent (checked with instanceof)
pub extern "js" fn DeviceMotionEvent::from_js_value_opt(
  v : JsValue,
) -> DeviceMotionEvent? =
  #| (v) => (v instanceof DeviceMotionEvent) ? { $tag: 1, _0: v } : { $tag: 0 }

///|
/// Safely cast JsValue to DeviceMotionEvent (checked with instanceof)
pub extern "js" fn JsValue::as_device_motion_event(
  self : JsValue,
) -> DeviceMotionEvent? =
  #| (self) => (self instanceof DeviceMotionEvent) ? { $tag: 1, _0: self } : { $tag: 0 }

///|
/// Cast JsValue to DeviceMotionEvent (unchecked)
pub extern "js" fn JsValue::to_device_motion_event(
  self : JsValue,
) -> DeviceMotionEvent =
  #| (self) => self

///|
pub extern "js" fn DeviceMotionEvent::to_event(
  self : DeviceMotionEvent,
) -> Event =
  #| (self) => self

///|
/// Error type for throwing methods
pub(all) enum DeviceMotionEventRequestPermissionError {
  NotAllowedError(JsError)
  OtherError(JsError)
} derive(Show)

///|
pub extern "js" fn DeviceMotionEvent::new(type_ : String) -> DeviceMotionEvent =
  #| (type_) => new DeviceMotionEvent(type_)

///|
extern "js" fn DeviceMotionEvent::new_with_event_init_dict_ffi(
  type_ : String,
  event_init_dict : JsValue,
) -> DeviceMotionEvent =
  #| (type_, event_init_dict) => new DeviceMotionEvent(type_, event_init_dict)

///|
pub fn DeviceMotionEvent::new_with_event_init_dict(
  type_ : String,
  event_init_dict : DeviceMotionEventInit,
) -> DeviceMotionEvent {
  DeviceMotionEvent::new_with_event_init_dict_ffi(
    type_,
    event_init_dict.to_js(),
  )
}

///|
pub extern "js" fn DeviceMotionEvent::get_acceleration(
  self : DeviceMotionEvent,
) -> DeviceMotionEventAcceleration? =
  #| (self) => (() => { const v = self.acceleration; return v == null ? { $tag: 0 } : { $tag: 1, _0: v }; })()

///|
pub extern "js" fn DeviceMotionEvent::get_acceleration_including_gravity(
  self : DeviceMotionEvent,
) -> DeviceMotionEventAcceleration? =
  #| (self) => (() => { const v = self.accelerationIncludingGravity; return v == null ? { $tag: 0 } : { $tag: 1, _0: v }; })()

///|
pub extern "js" fn DeviceMotionEvent::get_rotation_rate(
  self : DeviceMotionEvent,
) -> DeviceMotionEventRotationRate? =
  #| (self) => (() => { const v = self.rotationRate; return v == null ? { $tag: 0 } : { $tag: 1, _0: v }; })()

///|
pub extern "js" fn DeviceMotionEvent::get_interval(
  self : DeviceMotionEvent,
) -> Double =
  #| (self) => self.interval

///|
pub extern "js" fn DeviceMotionEvent::request_permission() -> Promise[
  Result[PermissionState, DeviceMotionEventRequestPermissionError],
] =
  #| () => DeviceMotionEvent.requestPermission().then(r => ({ $tag: 1, _0: r })).catch(e => ({ $tag: 0, _0: (() => { const n = (e && e.name) || ''; if (n === 'NotAllowedError') return { $tag: 0, _0: e }; return { $tag: 1, _0: e }; })() }))