UNPKG

9.45 kBSource Map (JSON)View Raw
1{"version":3,"file":"ExpoScreenOrientation.web.js","sourceRoot":"","sources":["../../src/ScreenOrientation/ExpoScreenOrientation.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAE5D,OAAO,EAEL,WAAW,EAEX,kBAAkB,EAClB,cAAc,GACf,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAEnF,MAAM,uBAAuB,GAEzB;IACF,OAAO,EAAE,kBAAkB,CAAC,OAAO;IACnC,GAAG,EAAE,kBAAkB,CAAC,GAAG;IAC3B,QAAQ,EAAE,kBAAkB,CAAC,QAAQ;IACrC,WAAW,EAAE,kBAAkB,CAAC,gBAAgB;IAChD,aAAa,EAAE,kBAAkB,CAAC,kBAAkB;IACpD,SAAS,EAAE,kBAAkB,CAAC,SAAS;IACvC,cAAc,EAAE,kBAAkB,CAAC,iBAAiB;IACpD,eAAe,EAAE,kBAAkB,CAAC,mBAAmB;CACxD,CAAC;AAEF,MAAM,mBAAmB,GAErB;IACF,CAAC,cAAc,CAAC,gBAAgB,CAAC,EAAE,WAAW,CAAC,WAAW;IAC1D,CAAC,cAAc,CAAC,kBAAkB,CAAC,EAAE,WAAW,CAAC,aAAa;IAC9D,CAAC,cAAc,CAAC,iBAAiB,CAAC,EAAE,WAAW,CAAC,cAAc;IAC9D,CAAC,cAAc,CAAC,mBAAmB,CAAC,EAAE,WAAW,CAAC,eAAe;CAClE,CAAC;AAIF,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;AAC1B,MAAM,WAAW,GACf,MAAM,CAAC,WAAW,IAAK,MAAc,CAAC,aAAa,IAAI,IAAI,CAAC;AAE9D,KAAK,UAAU,oBAAoB;IACjC,MAAM,CAAC,eAAe,EAAE,eAAe,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAC3D,uBAAu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,kBAAkB,CAAC,CAAC;QACrC,uBAAuB,GAAG,kBAAkB,CAAC;IAC/C,CAAC;IACD,KAAK,CAAC,WAAW;QACf,IAAI,MAAM,CAAC,WAAW,IAAI,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE;YACnD,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;SAC7B;aAAM,IACL,MAAM,CAAC,mBAAmB,CAAC;YAC3B,MAAM,CAAC,sBAAsB,CAAC;YAC9B,MAAM,CAAC,qBAAqB,CAAC,EAC7B;YACA,MAAM,iBAAiB,GACrB,MAAM,CAAC,mBAAmB,CAAC;gBAC3B,MAAM,CAAC,sBAAsB,CAAC;gBAC9B,MAAM,CAAC,qBAAqB,CAAC,CAAC;YAChC,0FAA0F;YAC1F,MAAM,SAAS,GAAG,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACjD,IAAI,CAAC,SAAS,EAAE;gBACd,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;aACtE;SACF;aAAM;YACL,MAAM,IAAI,KAAK,CACb,oFAAoF,CACrF,CAAC;SACH;IACH,CAAC;CACF,CAAC","sourcesContent":["import { SyntheticPlatformEmitter } from '@unimodules/core';\n\nimport {\n OrientationInfo,\n Orientation,\n OrientationLock,\n WebOrientationLock,\n WebOrientation,\n} from './ScreenOrientation.types';\n\nimport { getOrientationLockAsync, getOrientationAsync } from './ScreenOrientation';\n\nconst OrientationLockAPIToWeb: {\n [lock: string]: WebOrientationLock;\n} = {\n DEFAULT: WebOrientationLock.NATURAL,\n ALL: WebOrientationLock.ANY,\n PORTRAIT: WebOrientationLock.PORTRAIT,\n PORTRAIT_UP: WebOrientationLock.PORTRAIT_PRIMARY,\n PORTRAIT_DOWN: WebOrientationLock.PORTRAIT_SECONDARY,\n LANDSCAPE: WebOrientationLock.LANDSCAPE,\n LANDSCAPE_LEFT: WebOrientationLock.LANDSCAPE_PRIMARY,\n LANDSCAPE_RIGHT: WebOrientationLock.LANDSCAPE_SECONDARY,\n};\n\nconst OrientationWebToAPI: {\n [orientationWeb: string]: Orientation;\n} = {\n [WebOrientation.PORTRAIT_PRIMARY]: Orientation.PORTRAIT_UP,\n [WebOrientation.PORTRAIT_SECONDARY]: Orientation.PORTRAIT_DOWN,\n [WebOrientation.LANDSCAPE_PRIMARY]: Orientation.LANDSCAPE_LEFT,\n [WebOrientation.LANDSCAPE_SECONDARY]: Orientation.LANDSCAPE_RIGHT,\n};\n\ndeclare const window: Window;\n\nconst { screen } = window;\nconst orientation: ScreenOrientation | null =\n screen.orientation || (screen as any).msOrientation || null;\n\nasync function emitOrientationEvent() {\n const [orientationLock, orientationInfo] = await Promise.all([\n getOrientationLockAsync(),\n getOrientationAsync(),\n ]);\n SyntheticPlatformEmitter.emit('expoDidUpdateDimensions', {\n orientationLock,\n orientationInfo,\n });\n}\n\nif (orientation) {\n orientation.addEventListener('change', emitOrientationEvent);\n} else {\n window.addEventListener('orientationchange', emitOrientationEvent);\n}\n\nfunction _convertToLegacyOrientationLock(orientationLock: WebOrientationLock): string | string[] {\n switch (orientationLock) {\n case WebOrientationLock.UNKNOWN:\n throw new Error(\n `expo-screen-orientation: WebOrientationLock.UNKNOWN is not a valid lock to be converted.`\n );\n case WebOrientationLock.ANY:\n return ['portrait', 'landscape'];\n case WebOrientationLock.NATURAL:\n return 'default';\n default:\n return orientationLock;\n }\n}\n\nasync function _lockAsync(webOrientationLock: WebOrientationLock): Promise<void> {\n if (webOrientationLock === WebOrientationLock.UNKNOWN) {\n throw new Error(\n `expo-screen-orientation: WebOrientationLock.UNKNOWN is not a valid lock that can be applied to the device.`\n );\n }\n if (screen.orientation && screen.orientation.lock) {\n await screen.orientation.lock(webOrientationLock);\n } else if (\n screen['lockOrientation'] ||\n screen['mozLockOrientation'] ||\n screen['msLockOrientation']\n ) {\n const legacyLock = _convertToLegacyOrientationLock(webOrientationLock);\n const lockOrientation =\n screen['lockOrientation'] || screen['mozLockOrientation'] || screen['msLockOrientation'];\n // correct `this` context must be passed in otherwise method call is disallowed by browser\n const isSuccess = lockOrientation.call(screen, legacyLock);\n if (!isSuccess) {\n throw new Error(\n `Applying orientation lock: ${JSON.stringify(webOrientationLock)} to device was denied`\n );\n }\n } else {\n throw new Error(\n `expo-screen-orientation: The browser doesn't support locking screen orientation.`\n );\n }\n}\n\nlet _lastWebOrientationLock: WebOrientationLock = WebOrientationLock.UNKNOWN;\n\nexport default {\n get name(): string {\n return 'ExpoScreenOrientation';\n },\n async supportsOrientationLockAsync(orientationLock: OrientationLock): Promise<boolean> {\n return orientationLock in OrientationLockAPIToWeb;\n },\n async getPlatformOrientationLockAsync(): Promise<WebOrientationLock> {\n return _lastWebOrientationLock;\n },\n async getOrientationAsync(): Promise<OrientationInfo> {\n const webOrientation =\n screen['msOrientation'] || (screen.orientation || screen['mozOrientation'] || {}).type;\n if (!webOrientation) {\n return {\n orientation: Orientation.UNKNOWN,\n };\n }\n return {\n orientation: OrientationWebToAPI[webOrientation],\n };\n },\n async lockAsync(orientationLock: OrientationLock): Promise<void> {\n const webOrientationLock = OrientationLockAPIToWeb[orientationLock];\n if (!webOrientationLock) {\n throw new TypeError(`Invalid Orientation Lock: ${orientationLock}`);\n }\n await _lockAsync(webOrientationLock);\n },\n async lockPlatformAsync(webOrientationLock: WebOrientationLock): Promise<void> {\n await _lockAsync(webOrientationLock);\n _lastWebOrientationLock = webOrientationLock;\n },\n async unlockAsync(): Promise<void> {\n if (screen.orientation && screen.orientation.unlock) {\n screen.orientation.unlock();\n } else if (\n screen['unlockOrientation'] ||\n screen['mozUnlockOrientation'] ||\n screen['msUnlockOrientation']\n ) {\n const unlockOrientation =\n screen['unlockOrientation'] ||\n screen['mozUnlockOrientation'] ||\n screen['msUnlockOrientation'];\n // correct `this` context must be passed in otherwise method call is disallowed by browser\n const isSuccess = unlockOrientation.call(screen);\n if (!isSuccess) {\n throw new Error(`Unlocking screen orientation on device was denied`);\n }\n } else {\n throw new Error(\n `expo-screen-orientation: The browser doesn't support unlocking screen orientation.`\n );\n }\n },\n};\n"]}
\No newline at end of file