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AAC,CAAC,EAC1D,CACH,CAAC;IACJ,CAAC;IAwBD,kBAAkB,CAAC,KAA0B;QAC3C,MAAM,QAAQ,GAAG,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QACpD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,WAAW,CAAC,KAAU,EAAE,GAAW;QACjC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,cAAc,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAAE;YACrE,OAAO,cAAc,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;SACpD;QACD,OAAO,KAAK,CAAC;IACf,CAAC;;AAxFM,wBAAS,GAAG;IACjB,WAAW;IACX,IAAI;CACL,CAAC;AAEK,+BAAgB,GAAG;IACxB,IAAI,EAAE,IAAI;CACX,CAAC;AAEK,wBAAS,GAAG;IACjB,GAAG,aAAa;IAChB,gBAAgB,EAAE,SAAS,CAAC,IAAI;IAChC,YAAY,EAAE,SAAS,CAAC,KAAK;IAC7B,IAAI,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;CAChE,CAAC;AAEK,2BAAY,GAAG;IACpB,IAAI,EAAE,IAAI,CAAC,IAAI;IACf,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC;CACzC,CAAC;AAwEJ,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,cAAc,CAAC","sourcesContent":["import { UnavailabilityError } from '@unimodules/core';\nimport mapValues from 'lodash/mapValues';\nimport PropTypes from 'prop-types';\nimport React from 'react';\nimport { Platform, ViewProps, ViewPropTypes } from 'react-native';\n\nimport ExpoBarCodeScannerModule from './ExpoBarCodeScannerModule';\nimport ExpoBarCodeScannerView from './ExpoBarCodeScannerView';\n\nconst { BarCodeType, Type } = ExpoBarCodeScannerModule;\n\nconst EVENT_THROTTLE_MS = 500;\n\ntype BarCodeEvent = {\n type: string;\n data: string;\n [key: string]: any;\n};\n\nexport type BarCodeEventCallbackArguments = {\n nativeEvent: BarCodeEvent;\n};\n\nexport type BarCodeScannedCallback = (params: BarCodeEvent) => void;\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<BarCodeScannerProps> {\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 propTypes = {\n ...ViewPropTypes,\n onBarCodeScanned: PropTypes.func,\n barCodeTypes: PropTypes.array,\n type: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),\n };\n\n static defaultProps = {\n type: Type.back,\n barCodeTypes: Object.values(BarCodeType),\n };\n\n static async scanFromURLAsync(\n url: string,\n barCodeTypes: string[] = Object.values(BarCodeType)\n ): Promise<{ type: string; data: string }> {\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 <ExpoBarCodeScannerView\n {...nativeProps}\n onBarCodeScanned={this.onObjectDetected(onBarCodeScanned)}\n />\n );\n }\n\n // coordinates of cornerPoints and boundingBox are represented in DP (Display-Indepent Points) unit\n // React Native is using the same unit\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 newProps = mapValues(props, this.convertProp);\n return newProps;\n }\n\n convertProp(value: any, key: string): any {\n if (typeof value === 'string' && BarCodeScanner.ConversionTables[key]) {\n return BarCodeScanner.ConversionTables[key][value];\n }\n return value;\n }\n}\n\nexport const { Constants } = BarCodeScanner;\n"]}
\No newline at end of file