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,EAAE,gBAAgB,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QACxC,OAAO,CACL,oBAAC,sBAAsB,oBACjB,WAAW,IACf,gBAAgB,EAAE,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,IACzD,CACH,CAAC;IACJ,CAAC;IAsBD,kBAAkB,CAAC,KAA0B;QAC3C,MAAM,WAAW,GAAwB,EAAE,CAAC;QAE5C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YAChD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,cAAc,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAAE;gBACrE,WAAW,CAAC,GAAG,CAAC,GAAG,cAAc,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;aAChE;iBAAM;gBACL,WAAW,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;aAC1B;SACF;QAED,OAAO,WAAW,CAAC;IACrB,CAAC;;AAxGM,wBAAS,GAAG;IACjB,WAAW;IACX,IAAI;CACL,CAAC;AAEK,+BAAgB,GAAG;IACxB,IAAI,EAAE,IAAI;CACX,CAAC;AAEK,2BAAY,GAAG;IACpB,IAAI,EAAE,IAAI,CAAC,IAAI;IACf,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC;CACzC,CAAC;AAUF,cAAc;AACd;;;;;;;;GAQG;AACI,6BAAc,GAAG,oBAAoB,CAAC;IAC3C,SAAS,EAAE,cAAc,CAAC,mBAAmB;IAC7C,aAAa,EAAE,cAAc,CAAC,uBAAuB;CACtD,CAAC,CAAC;AAwEL,MAAM,CAAC,MAAM,EACX,SAAS,EACT,mBAAmB,EACnB,uBAAuB,EACvB,cAAc,GACf,GAAG,cAAc,CAAC","sourcesContent":["import { UnavailabilityError } from '@unimodules/core';\nimport {\n PermissionResponse,\n PermissionStatus,\n PermissionHookOptions,\n createPermissionHook,\n} from 'expo-modules-core';\nimport * as React from 'react';\nimport { Platform, ViewProps } from 'react-native';\n\nimport ExpoBarCodeScannerModule from './ExpoBarCodeScannerModule';\nimport ExpoBarCodeScannerView from './ExpoBarCodeScannerView';\n\nconst { BarCodeType, Type } = ExpoBarCodeScannerModule;\n\nconst EVENT_THROTTLE_MS = 500;\n\nexport type BarCodePoint = {\n x: number;\n y: number;\n};\n\nexport type BarCodeSize = {\n height: number;\n width: number;\n};\n\nexport type BarCodeBounds = {\n origin: BarCodePoint;\n size: BarCodeSize;\n};\n\nexport type BarCodeScannerResult = {\n type: string;\n data: string;\n bounds?: BarCodeBounds;\n cornerPoints?: BarCodePoint[];\n};\n\nexport type BarCodeEvent = BarCodeScannerResult & {\n target?: number;\n};\n\nexport type BarCodeEventCallbackArguments = {\n nativeEvent: BarCodeEvent;\n};\n\nexport type BarCodeScannedCallback = (params: BarCodeEvent) => void;\n\nexport { PermissionResponse, PermissionStatus, PermissionHookOptions };\n\nexport interface BarCodeScannerProps extends ViewProps {\n type?: 'front' | 'back' | number;\n barCodeTypes?: string[];\n onBarCodeScanned?: BarCodeScannedCallback;\n}\n\nexport class BarCodeScanner extends React.Component {\n lastEvents: { [key: string]: any } = {};\n lastEventsTimes: { [key: string]: any } = {};\n\n static Constants = {\n BarCodeType,\n Type,\n };\n\n static ConversionTables = {\n type: Type,\n };\n\n static defaultProps = {\n type: Type.back,\n barCodeTypes: Object.values(BarCodeType),\n };\n\n static async getPermissionsAsync(): Promise {\n return ExpoBarCodeScannerModule.getPermissionsAsync();\n }\n\n static async requestPermissionsAsync(): Promise {\n return ExpoBarCodeScannerModule.requestPermissionsAsync();\n }\n\n // @needsAudit\n /**\n * Check or request permissions for the barcode scanner.\n * This uses both `requestPermissionAsync` and `getPermissionsAsync` to interact with the permissions.\n *\n * @example\n * ```ts\n * const [status, requestPermission] = BarCodeScanner.usePermissions();\n * ```\n */\n static usePermissions = createPermissionHook({\n getMethod: BarCodeScanner.getPermissionsAsync,\n requestMethod: BarCodeScanner.requestPermissionsAsync,\n });\n\n static async scanFromURLAsync(\n url: string,\n barCodeTypes: string[] = Object.values(BarCodeType)\n ): Promise {\n if (!ExpoBarCodeScannerModule.scanFromURLAsync) {\n throw new UnavailabilityError('expo-barcode-scanner', 'scanFromURLAsync');\n }\n if (Array.isArray(barCodeTypes) && !barCodeTypes.length) {\n throw new Error('No barCodeTypes specified; provide at least one barCodeType for scanner');\n }\n\n if (Platform.OS === 'ios') {\n if (Array.isArray(barCodeTypes) && !barCodeTypes.includes(BarCodeType.qr)) {\n // Only QR type is supported on iOS, fail if one tries to use other types\n throw new Error('Only QR type is supported by scanFromURLAsync() on iOS');\n }\n // on iOS use only supported QR type\n return await ExpoBarCodeScannerModule.scanFromURLAsync(url, [BarCodeType.qr]);\n }\n\n // On other platforms, if barCodeTypes is not provided, use all available types\n return await ExpoBarCodeScannerModule.scanFromURLAsync(url, barCodeTypes);\n }\n\n render() {\n const nativeProps = this.convertNativeProps(this.props);\n const { onBarCodeScanned } = this.props;\n return (\n \n );\n }\n\n onObjectDetected = (callback?: BarCodeScannedCallback) => ({\n nativeEvent,\n }: BarCodeEventCallbackArguments) => {\n const { type } = nativeEvent;\n if (\n this.lastEvents[type] &&\n this.lastEventsTimes[type] &&\n JSON.stringify(nativeEvent) === this.lastEvents[type] &&\n Date.now() - this.lastEventsTimes[type] < EVENT_THROTTLE_MS\n ) {\n return;\n }\n\n if (callback) {\n callback(nativeEvent);\n this.lastEventsTimes[type] = new Date();\n this.lastEvents[type] = JSON.stringify(nativeEvent);\n }\n };\n\n convertNativeProps(props: BarCodeScannerProps) {\n const nativeProps: BarCodeScannerProps = {};\n\n for (const [key, value] of Object.entries(props)) {\n if (typeof value === 'string' && BarCodeScanner.ConversionTables[key]) {\n nativeProps[key] = BarCodeScanner.ConversionTables[key][value];\n } else {\n nativeProps[key] = value;\n }\n }\n\n return nativeProps;\n }\n}\n\nexport const {\n Constants,\n getPermissionsAsync,\n requestPermissionsAsync,\n usePermissions,\n} = BarCodeScanner;\n"]}