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G,WAAW,CAAC;QAC7B,IACE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;YACrB,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC;YAC1B,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;YACrD,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,iBAAiB,EAC3D;YACA,OAAO;SACR;QAED,IAAI,QAAQ,EAAE;YACZ,QAAQ,CAAC,WAAW,CAAC,CAAC;YACtB,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC;YACxC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;SACrD;IACH,CAAC,CAAC;IAEJ,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;;AAGH,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,cAAc,EAAE,GACtF,cAAc,CAAC","sourcesContent":["import {\n  PermissionResponse,\n  PermissionStatus,\n  PermissionHookOptions,\n  createPermissionHook,\n  UnavailabilityError,\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 { PermissionResponse, PermissionStatus, PermissionHookOptions };\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 defaultProps = {\n    type: Type.back,\n    barCodeTypes: Object.values(BarCodeType),\n  };\n\n  static async getPermissionsAsync(): Promise<PermissionResponse> {\n    return ExpoBarCodeScannerModule.getPermissionsAsync();\n  }\n\n  static async requestPermissionsAsync(): Promise<PermissionResponse> {\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<BarCodeScannerResult[]> {\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  onObjectDetected =\n    (callback?: BarCodeScannedCallback) =>\n    ({ nativeEvent }: 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 { Constants, getPermissionsAsync, requestPermissionsAsync, usePermissions } =\n  BarCodeScanner;\n"]}