@onekeyfe/react-native-qr-scanner 0.0.0-stage → 6.8.0-alpha.540

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (240) hide show
  1. package/LICENSE +21 -0
  2. package/QrScanner.podspec +42 -0
  3. package/README.md +74 -2
  4. package/android/CMakeLists.txt +23 -0
  5. package/android/build.gradle +147 -0
  6. package/android/src/main/AndroidManifest.xml +4 -0
  7. package/android/src/main/cpp/cpp-adapter.cpp +8 -0
  8. package/android/src/main/java/com/margelo/nitro/qrscanner/HybridQrImageDecoder.kt +66 -0
  9. package/android/src/main/java/com/margelo/nitro/qrscanner/QrEngines.kt +53 -0
  10. package/android/src/main/java/com/margelo/nitro/qrscanner/QrFrameTextGate.kt +44 -0
  11. package/android/src/main/java/com/margelo/nitro/qrscanner/QrImageDecodingPipeline.kt +169 -0
  12. package/android/src/main/java/com/margelo/nitro/qrscanner/QrScanner.kt +227 -0
  13. package/android/src/main/java/com/margelo/nitro/qrscanner/QrScannerPackage.kt +31 -0
  14. package/android/src/test/java/com/margelo/nitro/qrscanner/QrFrameTextGateTest.kt +69 -0
  15. package/android/src/test/java/com/margelo/nitro/qrscanner/QrImageDecodingPipelineTest.kt +97 -0
  16. package/ios/HybridQrImageDecoder.swift +58 -0
  17. package/ios/QrFrameTextGate.swift +66 -0
  18. package/ios/QrImageDecodingPipeline.swift +159 -0
  19. package/ios/QrScanner.swift +248 -0
  20. package/ios/QrZXingReader.h +15 -0
  21. package/ios/QrZXingReader.mm +46 -0
  22. package/lib/module/QrImageDecoder.nitro.js +4 -0
  23. package/lib/module/QrImageDecoder.nitro.js.map +1 -0
  24. package/lib/module/QrScanner.js +84 -0
  25. package/lib/module/QrScanner.js.map +1 -0
  26. package/lib/module/QrScanner.nitro.js +4 -0
  27. package/lib/module/QrScanner.nitro.js.map +1 -0
  28. package/lib/module/decodeQrImage.constants.js +5 -0
  29. package/lib/module/decodeQrImage.constants.js.map +1 -0
  30. package/lib/module/decodeQrImage.js +27 -0
  31. package/lib/module/decodeQrImage.js.map +1 -0
  32. package/lib/module/errors.js +31 -0
  33. package/lib/module/errors.js.map +1 -0
  34. package/lib/module/index.js +7 -0
  35. package/lib/module/index.js.map +1 -0
  36. package/lib/module/package.json +1 -0
  37. package/lib/module/ur/assembler.js +152 -0
  38. package/lib/module/ur/assembler.js.map +1 -0
  39. package/lib/module/ur/index.js +6 -0
  40. package/lib/module/ur/index.js.map +1 -0
  41. package/lib/module/ur/limits.js +207 -0
  42. package/lib/module/ur/limits.js.map +1 -0
  43. package/lib/module/ur/session.js +74 -0
  44. package/lib/module/ur/session.js.map +1 -0
  45. package/lib/module/ur/types.js +2 -0
  46. package/lib/module/ur/types.js.map +1 -0
  47. package/lib/module/web/decodeQrImage.js +62 -0
  48. package/lib/module/web/decodeQrImage.js.map +1 -0
  49. package/lib/module/web/engines.js +154 -0
  50. package/lib/module/web/engines.js.map +1 -0
  51. package/lib/module/web/imageOps.js +81 -0
  52. package/lib/module/web/imageOps.js.map +1 -0
  53. package/lib/module/web/index.js +11 -0
  54. package/lib/module/web/index.js.map +1 -0
  55. package/lib/module/web/scanner.js +230 -0
  56. package/lib/module/web/scanner.js.map +1 -0
  57. package/lib/module/web/zxing.worker.js +11 -0
  58. package/lib/module/web/zxing.worker.js.map +1 -0
  59. package/lib/module/web/zxingWorkerProtocol.js +67 -0
  60. package/lib/module/web/zxingWorkerProtocol.js.map +1 -0
  61. package/lib/nitrogen/generated/android/c++/JFunc_void_double.hpp +75 -0
  62. package/lib/nitrogen/generated/android/c++/JFunc_void_std__string_double.hpp +76 -0
  63. package/lib/nitrogen/generated/android/c++/JFunc_void_std__string_std__string_double.hpp +76 -0
  64. package/lib/nitrogen/generated/android/c++/JHybridQrImageDecoderSpec.cpp +78 -0
  65. package/lib/nitrogen/generated/android/c++/JHybridQrImageDecoderSpec.hpp +63 -0
  66. package/lib/nitrogen/generated/android/c++/JHybridQrScannerSpec.cpp +114 -0
  67. package/lib/nitrogen/generated/android/c++/JHybridQrScannerSpec.hpp +70 -0
  68. package/lib/nitrogen/generated/android/c++/JQrDecodeEngine.hpp +61 -0
  69. package/lib/nitrogen/generated/android/c++/JQrDecodePass.hpp +64 -0
  70. package/lib/nitrogen/generated/android/c++/JQrImageDecodeResult.hpp +70 -0
  71. package/lib/nitrogen/generated/android/c++/views/JHybridQrScannerStateUpdater.cpp +89 -0
  72. package/lib/nitrogen/generated/android/c++/views/JHybridQrScannerStateUpdater.hpp +54 -0
  73. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/Func_void_double.kt +78 -0
  74. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/Func_void_std__string_double.kt +78 -0
  75. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/Func_void_std__string_std__string_double.kt +78 -0
  76. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/HybridQrImageDecoderSpec.kt +57 -0
  77. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/HybridQrScannerSpec.kt +101 -0
  78. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/QrDecodeEngine.kt +24 -0
  79. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/QrDecodePass.kt +25 -0
  80. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/QrImageDecodeResult.kt +61 -0
  81. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/qrscannerOnLoad.kt +35 -0
  82. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/views/HybridQrScannerManager.kt +96 -0
  83. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/views/HybridQrScannerStateUpdater.kt +23 -0
  84. package/lib/nitrogen/generated/android/qrscanner+autolinking.cmake +85 -0
  85. package/lib/nitrogen/generated/android/qrscanner+autolinking.gradle +27 -0
  86. package/lib/nitrogen/generated/android/qrscannerOnLoad.cpp +78 -0
  87. package/lib/nitrogen/generated/android/qrscannerOnLoad.hpp +34 -0
  88. package/lib/nitrogen/generated/ios/QrScanner+autolinking.rb +62 -0
  89. package/lib/nitrogen/generated/ios/QrScanner-Swift-Cxx-Bridge.cpp +90 -0
  90. package/lib/nitrogen/generated/ios/QrScanner-Swift-Cxx-Bridge.hpp +294 -0
  91. package/lib/nitrogen/generated/ios/QrScanner-Swift-Cxx-Umbrella.hpp +61 -0
  92. package/lib/nitrogen/generated/ios/QrScannerAutolinking.mm +41 -0
  93. package/lib/nitrogen/generated/ios/QrScannerAutolinking.swift +38 -0
  94. package/lib/nitrogen/generated/ios/c++/HybridQrImageDecoderSpecSwift.cpp +11 -0
  95. package/lib/nitrogen/generated/ios/c++/HybridQrImageDecoderSpecSwift.hpp +92 -0
  96. package/lib/nitrogen/generated/ios/c++/HybridQrScannerSpecSwift.cpp +11 -0
  97. package/lib/nitrogen/generated/ios/c++/HybridQrScannerSpecSwift.hpp +103 -0
  98. package/lib/nitrogen/generated/ios/c++/views/HybridQrScannerComponent.mm +162 -0
  99. package/lib/nitrogen/generated/ios/swift/Func_void_QrImageDecodeResult.swift +46 -0
  100. package/lib/nitrogen/generated/ios/swift/Func_void_double.swift +46 -0
  101. package/lib/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
  102. package/lib/nitrogen/generated/ios/swift/Func_void_std__string_double.swift +46 -0
  103. package/lib/nitrogen/generated/ios/swift/Func_void_std__string_std__string_double.swift +46 -0
  104. package/lib/nitrogen/generated/ios/swift/HybridQrImageDecoderSpec.swift +55 -0
  105. package/lib/nitrogen/generated/ios/swift/HybridQrImageDecoderSpec_cxx.swift +145 -0
  106. package/lib/nitrogen/generated/ios/swift/HybridQrScannerSpec.swift +58 -0
  107. package/lib/nitrogen/generated/ios/swift/HybridQrScannerSpec_cxx.swift +252 -0
  108. package/lib/nitrogen/generated/ios/swift/QrDecodeEngine.swift +44 -0
  109. package/lib/nitrogen/generated/ios/swift/QrDecodePass.swift +48 -0
  110. package/lib/nitrogen/generated/ios/swift/QrImageDecodeResult.swift +64 -0
  111. package/lib/nitrogen/generated/shared/c++/HybridQrImageDecoderSpec.cpp +21 -0
  112. package/lib/nitrogen/generated/shared/c++/HybridQrImageDecoderSpec.hpp +65 -0
  113. package/lib/nitrogen/generated/shared/c++/HybridQrScannerSpec.cpp +28 -0
  114. package/lib/nitrogen/generated/shared/c++/HybridQrScannerSpec.hpp +71 -0
  115. package/lib/nitrogen/generated/shared/c++/QrDecodeEngine.hpp +80 -0
  116. package/lib/nitrogen/generated/shared/c++/QrDecodePass.hpp +84 -0
  117. package/lib/nitrogen/generated/shared/c++/QrImageDecodeResult.hpp +97 -0
  118. package/lib/nitrogen/generated/shared/c++/views/HybridQrScannerComponent.cpp +40 -0
  119. package/lib/nitrogen/generated/shared/c++/views/HybridQrScannerComponent.hpp +94 -0
  120. package/lib/nitrogen/generated/shared/json/QrScannerConfig.json +13 -0
  121. package/lib/typescript/package.json +1 -0
  122. package/lib/typescript/src/QrImageDecoder.nitro.d.ts +26 -0
  123. package/lib/typescript/src/QrImageDecoder.nitro.d.ts.map +1 -0
  124. package/lib/typescript/src/QrScanner.d.ts +31 -0
  125. package/lib/typescript/src/QrScanner.d.ts.map +1 -0
  126. package/lib/typescript/src/QrScanner.nitro.d.ts +29 -0
  127. package/lib/typescript/src/QrScanner.nitro.d.ts.map +1 -0
  128. package/lib/typescript/src/decodeQrImage.constants.d.ts +3 -0
  129. package/lib/typescript/src/decodeQrImage.constants.d.ts.map +1 -0
  130. package/lib/typescript/src/decodeQrImage.d.ts +13 -0
  131. package/lib/typescript/src/decodeQrImage.d.ts.map +1 -0
  132. package/lib/typescript/src/errors.d.ts +13 -0
  133. package/lib/typescript/src/errors.d.ts.map +1 -0
  134. package/lib/typescript/src/index.d.ts +9 -0
  135. package/lib/typescript/src/index.d.ts.map +1 -0
  136. package/lib/typescript/src/ur/assembler.d.ts +5 -0
  137. package/lib/typescript/src/ur/assembler.d.ts.map +1 -0
  138. package/lib/typescript/src/ur/index.d.ts +5 -0
  139. package/lib/typescript/src/ur/index.d.ts.map +1 -0
  140. package/lib/typescript/src/ur/limits.d.ts +40 -0
  141. package/lib/typescript/src/ur/limits.d.ts.map +1 -0
  142. package/lib/typescript/src/ur/session.d.ts +11 -0
  143. package/lib/typescript/src/ur/session.d.ts.map +1 -0
  144. package/lib/typescript/src/ur/types.d.ts +61 -0
  145. package/lib/typescript/src/ur/types.d.ts.map +1 -0
  146. package/lib/typescript/src/web/decodeQrImage.d.ts +8 -0
  147. package/lib/typescript/src/web/decodeQrImage.d.ts.map +1 -0
  148. package/lib/typescript/src/web/engines.d.ts +32 -0
  149. package/lib/typescript/src/web/engines.d.ts.map +1 -0
  150. package/lib/typescript/src/web/imageOps.d.ts +37 -0
  151. package/lib/typescript/src/web/imageOps.d.ts.map +1 -0
  152. package/lib/typescript/src/web/index.d.ts +11 -0
  153. package/lib/typescript/src/web/index.d.ts.map +1 -0
  154. package/lib/typescript/src/web/scanner.d.ts +43 -0
  155. package/lib/typescript/src/web/scanner.d.ts.map +1 -0
  156. package/lib/typescript/src/web/zxing.worker.d.ts +2 -0
  157. package/lib/typescript/src/web/zxing.worker.d.ts.map +1 -0
  158. package/lib/typescript/src/web/zxingWorkerProtocol.d.ts +36 -0
  159. package/lib/typescript/src/web/zxingWorkerProtocol.d.ts.map +1 -0
  160. package/nitro.json +27 -0
  161. package/nitrogen/generated/android/c++/JFunc_void_double.hpp +75 -0
  162. package/nitrogen/generated/android/c++/JFunc_void_std__string_double.hpp +76 -0
  163. package/nitrogen/generated/android/c++/JFunc_void_std__string_std__string_double.hpp +76 -0
  164. package/nitrogen/generated/android/c++/JHybridQrImageDecoderSpec.cpp +78 -0
  165. package/nitrogen/generated/android/c++/JHybridQrImageDecoderSpec.hpp +63 -0
  166. package/nitrogen/generated/android/c++/JHybridQrScannerSpec.cpp +114 -0
  167. package/nitrogen/generated/android/c++/JHybridQrScannerSpec.hpp +70 -0
  168. package/nitrogen/generated/android/c++/JQrDecodeEngine.hpp +61 -0
  169. package/nitrogen/generated/android/c++/JQrDecodePass.hpp +64 -0
  170. package/nitrogen/generated/android/c++/JQrImageDecodeResult.hpp +70 -0
  171. package/nitrogen/generated/android/c++/views/JHybridQrScannerStateUpdater.cpp +89 -0
  172. package/nitrogen/generated/android/c++/views/JHybridQrScannerStateUpdater.hpp +54 -0
  173. package/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/Func_void_double.kt +78 -0
  174. package/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/Func_void_std__string_double.kt +78 -0
  175. package/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/Func_void_std__string_std__string_double.kt +78 -0
  176. package/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/HybridQrImageDecoderSpec.kt +57 -0
  177. package/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/HybridQrScannerSpec.kt +101 -0
  178. package/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/QrDecodeEngine.kt +24 -0
  179. package/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/QrDecodePass.kt +25 -0
  180. package/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/QrImageDecodeResult.kt +61 -0
  181. package/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/qrscannerOnLoad.kt +35 -0
  182. package/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/views/HybridQrScannerManager.kt +96 -0
  183. package/nitrogen/generated/android/kotlin/com/margelo/nitro/qrscanner/views/HybridQrScannerStateUpdater.kt +23 -0
  184. package/nitrogen/generated/android/qrscanner+autolinking.cmake +85 -0
  185. package/nitrogen/generated/android/qrscanner+autolinking.gradle +27 -0
  186. package/nitrogen/generated/android/qrscannerOnLoad.cpp +78 -0
  187. package/nitrogen/generated/android/qrscannerOnLoad.hpp +34 -0
  188. package/nitrogen/generated/ios/QrScanner+autolinking.rb +62 -0
  189. package/nitrogen/generated/ios/QrScanner-Swift-Cxx-Bridge.cpp +90 -0
  190. package/nitrogen/generated/ios/QrScanner-Swift-Cxx-Bridge.hpp +294 -0
  191. package/nitrogen/generated/ios/QrScanner-Swift-Cxx-Umbrella.hpp +61 -0
  192. package/nitrogen/generated/ios/QrScannerAutolinking.mm +41 -0
  193. package/nitrogen/generated/ios/QrScannerAutolinking.swift +38 -0
  194. package/nitrogen/generated/ios/c++/HybridQrImageDecoderSpecSwift.cpp +11 -0
  195. package/nitrogen/generated/ios/c++/HybridQrImageDecoderSpecSwift.hpp +92 -0
  196. package/nitrogen/generated/ios/c++/HybridQrScannerSpecSwift.cpp +11 -0
  197. package/nitrogen/generated/ios/c++/HybridQrScannerSpecSwift.hpp +103 -0
  198. package/nitrogen/generated/ios/c++/views/HybridQrScannerComponent.mm +162 -0
  199. package/nitrogen/generated/ios/swift/Func_void_QrImageDecodeResult.swift +46 -0
  200. package/nitrogen/generated/ios/swift/Func_void_double.swift +46 -0
  201. package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
  202. package/nitrogen/generated/ios/swift/Func_void_std__string_double.swift +46 -0
  203. package/nitrogen/generated/ios/swift/Func_void_std__string_std__string_double.swift +46 -0
  204. package/nitrogen/generated/ios/swift/HybridQrImageDecoderSpec.swift +55 -0
  205. package/nitrogen/generated/ios/swift/HybridQrImageDecoderSpec_cxx.swift +145 -0
  206. package/nitrogen/generated/ios/swift/HybridQrScannerSpec.swift +58 -0
  207. package/nitrogen/generated/ios/swift/HybridQrScannerSpec_cxx.swift +252 -0
  208. package/nitrogen/generated/ios/swift/QrDecodeEngine.swift +44 -0
  209. package/nitrogen/generated/ios/swift/QrDecodePass.swift +48 -0
  210. package/nitrogen/generated/ios/swift/QrImageDecodeResult.swift +64 -0
  211. package/nitrogen/generated/shared/c++/HybridQrImageDecoderSpec.cpp +21 -0
  212. package/nitrogen/generated/shared/c++/HybridQrImageDecoderSpec.hpp +65 -0
  213. package/nitrogen/generated/shared/c++/HybridQrScannerSpec.cpp +28 -0
  214. package/nitrogen/generated/shared/c++/HybridQrScannerSpec.hpp +71 -0
  215. package/nitrogen/generated/shared/c++/QrDecodeEngine.hpp +80 -0
  216. package/nitrogen/generated/shared/c++/QrDecodePass.hpp +84 -0
  217. package/nitrogen/generated/shared/c++/QrImageDecodeResult.hpp +97 -0
  218. package/nitrogen/generated/shared/c++/views/HybridQrScannerComponent.cpp +40 -0
  219. package/nitrogen/generated/shared/c++/views/HybridQrScannerComponent.hpp +94 -0
  220. package/nitrogen/generated/shared/json/QrScannerConfig.json +13 -0
  221. package/package.json +191 -4
  222. package/src/QrImageDecoder.nitro.ts +27 -0
  223. package/src/QrScanner.nitro.ts +34 -0
  224. package/src/QrScanner.tsx +109 -0
  225. package/src/decodeQrImage.constants.ts +2 -0
  226. package/src/decodeQrImage.ts +39 -0
  227. package/src/errors.ts +52 -0
  228. package/src/index.tsx +15 -0
  229. package/src/ur/assembler.ts +174 -0
  230. package/src/ur/index.ts +15 -0
  231. package/src/ur/limits.ts +214 -0
  232. package/src/ur/session.ts +57 -0
  233. package/src/ur/types.ts +64 -0
  234. package/src/web/decodeQrImage.ts +59 -0
  235. package/src/web/engines.ts +192 -0
  236. package/src/web/imageOps.ts +102 -0
  237. package/src/web/index.ts +12 -0
  238. package/src/web/scanner.ts +271 -0
  239. package/src/web/zxing.worker.ts +17 -0
  240. package/src/web/zxingWorkerProtocol.ts +79 -0
@@ -0,0 +1,159 @@
1
+ import CoreGraphics
2
+ import CoreImage
3
+ import Foundation
4
+ import ImageIO
5
+ import Vision
6
+
7
+ // Kept free of UIKit and NitroModules so it compiles and runs on macOS for
8
+ // decoding checks against fixture images.
9
+
10
+ enum QrImageDecodeError: Error {
11
+ case invalidImage(String)
12
+ case resourceLimit(String)
13
+
14
+ var codedMessage: String {
15
+ switch self {
16
+ case .invalidImage(let reason): return "invalid-image: \(reason)"
17
+ case .resourceLimit(let reason): return "resource-limit: \(reason)"
18
+ }
19
+ }
20
+ }
21
+
22
+ struct QrImageHit: Equatable {
23
+ let text: String
24
+ /// `vision`, `mlkit` or `zxing`.
25
+ let engine: String
26
+ /// `original`, `padded`, `grayscale` or `inverted`.
27
+ let pass: String
28
+ }
29
+
30
+ protocol QrImageEngine {
31
+ var name: String { get }
32
+ func decode(_ image: CGImage) -> String?
33
+ }
34
+
35
+ final class VisionQrEngine: QrImageEngine {
36
+ let name = "vision"
37
+
38
+ func decode(_ image: CGImage) -> String? {
39
+ let request = VNDetectBarcodesRequest()
40
+ request.symbologies = [.qr]
41
+ let handler = VNImageRequestHandler(cgImage: image, options: [:])
42
+ do {
43
+ try handler.perform([request])
44
+ } catch {
45
+ return nil
46
+ }
47
+ return request.results?
48
+ .lazy
49
+ .compactMap { $0.payloadStringValue }
50
+ .first { !$0.isEmpty }
51
+ }
52
+ }
53
+
54
+ /// Decodes one local image with several engines over several image variants,
55
+ /// returning the first hit. Callers serialize calls; instances hold no
56
+ /// per-call state.
57
+ final class QrImageDecodingPipeline {
58
+ /// Sources above this pixel count are refused before decoding.
59
+ static let maxSourcePixels = 200_000_000
60
+ /// White border added by the padded pass, as a share of the longer side.
61
+ static let paddingRatio = 0.1
62
+
63
+ private let engines: [QrImageEngine]
64
+ private let ciContext = CIContext(options: [.cacheIntermediates: false])
65
+
66
+ init(engines: [QrImageEngine]) {
67
+ self.engines = engines
68
+ }
69
+
70
+ func decode(url: URL, maxPixels: Int) throws -> QrImageHit? {
71
+ let image = try loadOriented(url: url, maxPixels: maxPixels)
72
+ let passes: [(String, () -> CGImage?)] = [
73
+ ("original", { image }),
74
+ ("padded", { self.padded(image, maxPixels: maxPixels) }),
75
+ ("grayscale", { self.grayscale(image, inverted: false) }),
76
+ ("inverted", { self.grayscale(image, inverted: true) }),
77
+ ]
78
+ for (pass, makeVariant) in passes {
79
+ let hit: QrImageHit? = autoreleasepool {
80
+ guard let variant = makeVariant() else { return nil }
81
+ for engine in engines {
82
+ if let text = engine.decode(variant) {
83
+ return QrImageHit(text: text, engine: engine.name, pass: pass)
84
+ }
85
+ }
86
+ return nil
87
+ }
88
+ if let hit { return hit }
89
+ }
90
+ return nil
91
+ }
92
+
93
+ /// Applies EXIF orientation and downscales to at most `maxPixels`.
94
+ private func loadOriented(url: URL, maxPixels: Int) throws -> CGImage {
95
+ let sourceOptions = [kCGImageSourceShouldCache: false] as CFDictionary
96
+ guard let source = CGImageSourceCreateWithURL(url as CFURL, sourceOptions),
97
+ CGImageSourceGetCount(source) > 0
98
+ else {
99
+ throw QrImageDecodeError.invalidImage("unreadable or unsupported image")
100
+ }
101
+ guard
102
+ let properties = CGImageSourceCopyPropertiesAtIndex(source, 0, nil)
103
+ as? [CFString: Any],
104
+ let width = properties[kCGImagePropertyPixelWidth] as? Int,
105
+ let height = properties[kCGImagePropertyPixelHeight] as? Int,
106
+ width > 0, height > 0
107
+ else {
108
+ throw QrImageDecodeError.invalidImage("missing image dimensions")
109
+ }
110
+ let sourcePixels = Double(width) * Double(height)
111
+ if sourcePixels > Double(Self.maxSourcePixels) {
112
+ throw QrImageDecodeError.resourceLimit("image has \(width)x\(height) pixels")
113
+ }
114
+ let scale = min(1, (Double(maxPixels) / sourcePixels).squareRoot())
115
+ let scaledSide = Int((Double(max(width, height)) * scale).rounded(.down))
116
+ let maxSide = max(1, min(maxPixels, scaledSide))
117
+ let thumbnailOptions =
118
+ [
119
+ kCGImageSourceCreateThumbnailFromImageAlways: true,
120
+ kCGImageSourceCreateThumbnailWithTransform: true,
121
+ kCGImageSourceShouldCacheImmediately: true,
122
+ kCGImageSourceThumbnailMaxPixelSize: maxSide,
123
+ ] as CFDictionary
124
+ guard let image = CGImageSourceCreateThumbnailAtIndex(source, 0, thumbnailOptions)
125
+ else {
126
+ throw QrImageDecodeError.invalidImage("image could not be decoded")
127
+ }
128
+ return image
129
+ }
130
+
131
+ /// Adds a white quiet zone; codes rendered edge to edge (no margin) often
132
+ /// fail to locate without one.
133
+ private func padded(_ image: CGImage, maxPixels: Int) -> CGImage? {
134
+ let margin = max(16, Int(Double(max(image.width, image.height)) * Self.paddingRatio))
135
+ let width = image.width + margin * 2
136
+ let height = image.height + margin * 2
137
+ guard width <= maxPixels / height,
138
+ let context = CGContext(
139
+ data: nil, width: width, height: height, bitsPerComponent: 8,
140
+ bytesPerRow: 0, space: CGColorSpaceCreateDeviceRGB(),
141
+ bitmapInfo: CGImageAlphaInfo.noneSkipLast.rawValue)
142
+ else { return nil }
143
+ context.setFillColor(CGColor(red: 1, green: 1, blue: 1, alpha: 1))
144
+ context.fill(CGRect(x: 0, y: 0, width: width, height: height))
145
+ context.draw(
146
+ image, in: CGRect(x: margin, y: margin, width: image.width, height: image.height))
147
+ return context.makeImage()
148
+ }
149
+
150
+ private func grayscale(_ image: CGImage, inverted: Bool) -> CGImage? {
151
+ var output = CIImage(cgImage: image).applyingFilter(
152
+ "CIColorControls",
153
+ parameters: [kCIInputSaturationKey: 0, kCIInputContrastKey: 1.3])
154
+ if inverted {
155
+ output = output.applyingFilter("CIColorInvert")
156
+ }
157
+ return ciContext.createCGImage(output, from: output.extent)
158
+ }
159
+ }
@@ -0,0 +1,248 @@
1
+ import AVFoundation
2
+ import NitroModules
3
+ import UIKit
4
+
5
+ final class QrPreviewView: UIView {
6
+ override class var layerClass: AnyClass { AVCaptureVideoPreviewLayer.self }
7
+
8
+ var previewLayer: AVCaptureVideoPreviewLayer {
9
+ // swiftlint:disable:next force_cast
10
+ layer as! AVCaptureVideoPreviewLayer
11
+ }
12
+
13
+ override init(frame: CGRect) {
14
+ super.init(frame: frame)
15
+ backgroundColor = .black
16
+ previewLayer.videoGravity = .resizeAspectFill
17
+ }
18
+
19
+ required init?(coder: NSCoder) {
20
+ fatalError("init(coder:) is not supported")
21
+ }
22
+ }
23
+
24
+ class HybridQrScanner: HybridQrScannerSpec {
25
+ var view: UIView { previewView }
26
+ private let previewView = QrPreviewView()
27
+
28
+ // Props
29
+ var active: Bool = false
30
+ var onReady: ((Double) -> Void)?
31
+ var onFrameText: ((String, Double) -> Void)?
32
+ var onError: ((String, String, Double) -> Void)?
33
+
34
+ // Owned by `sessionQueue`.
35
+ private let sessionQueue = DispatchQueue(label: "so.onekey.qrscanner.session")
36
+ private let metadataQueue = DispatchQueue(label: "so.onekey.qrscanner.metadata")
37
+ private let session = AVCaptureSession()
38
+ private var isConfigured = false
39
+ private var running = false
40
+ private var observers: [NSObjectProtocol] = []
41
+ private lazy var metadataDelegate = MetadataDelegate(owner: self)
42
+
43
+ // Shared by `sessionQueue` (start/stop) and `metadataQueue` (detections).
44
+ // The same text is reported again after 1 s, so a caller that reset its
45
+ // session still receives a code that stays in view.
46
+ private let gate = QrFrameTextGate(repeatInterval: 1.0)
47
+
48
+ override init() {
49
+ super.init()
50
+ previewView.previewLayer.session = session
51
+ }
52
+
53
+ func afterUpdate() {
54
+ let shouldRun = active
55
+ sessionQueue.async { [weak self] in
56
+ guard let self else { return }
57
+ if shouldRun { self.start() } else { self.stop() }
58
+ }
59
+ }
60
+
61
+ func onDropView() {
62
+ sessionQueue.async { [weak self] in
63
+ self?.stop()
64
+ self?.removeObservers()
65
+ }
66
+ }
67
+
68
+ // MARK: - Session (sessionQueue)
69
+
70
+ private func start() {
71
+ guard !running else { return }
72
+ let currentGeneration = nextGeneration()
73
+ // Check for hardware first: a device without a camera must not prompt.
74
+ guard Self.captureDevice() != nil else {
75
+ emitError("no-camera", "No camera is available", currentGeneration)
76
+ return
77
+ }
78
+ switch AVCaptureDevice.authorizationStatus(for: .video) {
79
+ case .authorized:
80
+ break
81
+ case .notDetermined:
82
+ AVCaptureDevice.requestAccess(for: .video) { [weak self] granted in
83
+ self?.sessionQueue.async {
84
+ guard let self, self.currentGeneration() == currentGeneration, self.active else {
85
+ return
86
+ }
87
+ if granted {
88
+ self.start()
89
+ } else {
90
+ self.emitError("permission-denied", "Camera access was denied", currentGeneration)
91
+ }
92
+ }
93
+ }
94
+ return
95
+ default:
96
+ emitError("permission-denied", "Camera access is not allowed", currentGeneration)
97
+ return
98
+ }
99
+
100
+ if !isConfigured {
101
+ if let error = configure() {
102
+ emitError(error.code, error.message, currentGeneration)
103
+ return
104
+ }
105
+ isConfigured = true
106
+ addObservers()
107
+ }
108
+ session.startRunning()
109
+ running = session.isRunning
110
+ setCapturing(running)
111
+ if running {
112
+ onReady?(Double(currentGeneration))
113
+ } else {
114
+ emitError("camera-busy", "The camera could not start", currentGeneration)
115
+ }
116
+ }
117
+
118
+ private func stop() {
119
+ // A new generation makes late metadata from the old one stale.
120
+ _ = nextGeneration()
121
+ setCapturing(false)
122
+ guard running || session.isRunning else { return }
123
+ session.stopRunning()
124
+ running = false
125
+ }
126
+
127
+ private func configure() -> (code: String, message: String)? {
128
+ guard let device = Self.captureDevice() else {
129
+ return ("no-camera", "No camera is available")
130
+ }
131
+ session.beginConfiguration()
132
+ defer { session.commitConfiguration() }
133
+ if session.canSetSessionPreset(.hd1920x1080) {
134
+ session.sessionPreset = .hd1920x1080
135
+ }
136
+ let input: AVCaptureDeviceInput
137
+ do {
138
+ input = try AVCaptureDeviceInput(device: device)
139
+ } catch {
140
+ return ("camera-busy", error.localizedDescription)
141
+ }
142
+ guard session.canAddInput(input) else {
143
+ return ("camera-busy", "The camera input could not be added")
144
+ }
145
+ session.addInput(input)
146
+
147
+ let output = AVCaptureMetadataOutput()
148
+ guard session.canAddOutput(output) else {
149
+ return ("decoder-unavailable", "The QR detector could not be added")
150
+ }
151
+ session.addOutput(output)
152
+ guard output.availableMetadataObjectTypes.contains(.qr) else {
153
+ return ("decoder-unavailable", "QR detection is not available")
154
+ }
155
+ output.setMetadataObjectsDelegate(metadataDelegate, queue: metadataQueue)
156
+ output.metadataObjectTypes = [.qr]
157
+
158
+ if (try? device.lockForConfiguration()) != nil {
159
+ if device.isFocusModeSupported(.continuousAutoFocus) {
160
+ device.focusMode = .continuousAutoFocus
161
+ }
162
+ if device.isAutoFocusRangeRestrictionSupported {
163
+ // Codes are held close to the lens.
164
+ device.autoFocusRangeRestriction = .near
165
+ }
166
+ device.unlockForConfiguration()
167
+ }
168
+ return nil
169
+ }
170
+
171
+ private static func captureDevice() -> AVCaptureDevice? {
172
+ AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .back)
173
+ ?? AVCaptureDevice.default(for: .video)
174
+ }
175
+
176
+ private func addObservers() {
177
+ let center = NotificationCenter.default
178
+ observers.append(
179
+ center.addObserver(
180
+ forName: AVCaptureSession.wasInterruptedNotification, object: session, queue: nil
181
+ ) { [weak self] note in
182
+ guard let self else { return }
183
+ let reason = (note.userInfo?[AVCaptureSessionInterruptionReasonKey] as? Int)
184
+ .flatMap(AVCaptureSession.InterruptionReason.init(rawValue:))
185
+ if reason == .videoDeviceInUseByAnotherClient {
186
+ self.emitError("camera-busy", "The camera is in use by another app", self.currentGeneration())
187
+ }
188
+ })
189
+ observers.append(
190
+ center.addObserver(
191
+ forName: AVCaptureSession.runtimeErrorNotification, object: session, queue: nil
192
+ ) { [weak self] note in
193
+ guard let self else { return }
194
+ let error = note.userInfo?[AVCaptureSessionErrorKey] as? Error
195
+ self.sessionQueue.async {
196
+ self.running = false
197
+ self.setCapturing(false)
198
+ self.emitError(
199
+ "camera-busy", error?.localizedDescription ?? "The camera stopped",
200
+ self.currentGeneration())
201
+ }
202
+ })
203
+ }
204
+
205
+ private func removeObservers() {
206
+ observers.forEach { NotificationCenter.default.removeObserver($0) }
207
+ observers.removeAll()
208
+ }
209
+
210
+ // MARK: - Generation and events
211
+
212
+ private func nextGeneration() -> Int { gate.nextGeneration() }
213
+
214
+ private func setCapturing(_ value: Bool) { gate.setCapturing(value) }
215
+
216
+ private func currentGeneration() -> Int { gate.currentGeneration }
217
+
218
+ private func emitError(_ code: String, _ message: String, _ generation: Int) {
219
+ onError?(code, message, Double(generation))
220
+ }
221
+
222
+ /// Called on `metadataQueue`.
223
+ fileprivate func handle(texts: [String]) {
224
+ for report in gate.filter(texts, now: ProcessInfo.processInfo.systemUptime) {
225
+ onFrameText?(report.text, Double(report.generation))
226
+ }
227
+ }
228
+ }
229
+
230
+ private final class MetadataDelegate: NSObject, AVCaptureMetadataOutputObjectsDelegate {
231
+ private weak var owner: HybridQrScanner?
232
+
233
+ init(owner: HybridQrScanner) {
234
+ self.owner = owner
235
+ }
236
+
237
+ func metadataOutput(
238
+ _ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject],
239
+ from connection: AVCaptureConnection
240
+ ) {
241
+ let texts = metadataObjects.compactMap {
242
+ ($0 as? AVMetadataMachineReadableCodeObject)?.stringValue
243
+ }
244
+ if !texts.isEmpty {
245
+ owner?.handle(texts: texts)
246
+ }
247
+ }
248
+ }
@@ -0,0 +1,15 @@
1
+ #import <CoreGraphics/CoreGraphics.h>
2
+ #import <Foundation/Foundation.h>
3
+
4
+ NS_ASSUME_NONNULL_BEGIN
5
+
6
+ /// QR-only ZXing-C++ reader. The header exposes CoreGraphics types only, so
7
+ /// ZXing headers stay out of this module's public interface.
8
+ @interface QrZXingReader : NSObject
9
+
10
+ /// Text of the first QR symbol in `image`, or nil when none is found.
11
+ - (nullable NSString *)decodeImage:(CGImageRef)image;
12
+
13
+ @end
14
+
15
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,46 @@
1
+ #import "QrZXingReader.h"
2
+
3
+ #if __has_include(<ZXingCpp/ZXIBarcodeReader.h>)
4
+ #import <ZXingCpp/ZXIBarcodeReader.h>
5
+ #elif __has_include(<zxing-cpp/ZXIBarcodeReader.h>)
6
+ #import <zxing-cpp/ZXIBarcodeReader.h>
7
+ #else
8
+ #import "ZXIBarcodeReader.h"
9
+ #endif
10
+
11
+ @implementation QrZXingReader {
12
+ ZXIBarcodeReader *_reader;
13
+ }
14
+
15
+ - (instancetype)init {
16
+ if (self = [super init]) {
17
+ ZXIReaderOptions *options = [[ZXIReaderOptions alloc] init];
18
+ options.formats = @[ @(QR_CODE) ];
19
+ options.tryHarder = YES;
20
+ options.tryRotate = YES;
21
+ // tryInvert would re-run every attempt on an inverted copy. zxing-cpp
22
+ // 2.2.0 still reads light-on-dark QR codes without it (see the XCTests),
23
+ // and the pipeline has its own inverted pass.
24
+ options.tryInvert = NO;
25
+ options.tryDownscale = YES;
26
+ options.maxNumberOfSymbols = 1;
27
+ _reader = [[ZXIBarcodeReader alloc] initWithOptions:options];
28
+ }
29
+ return self;
30
+ }
31
+
32
+ - (nullable NSString *)decodeImage:(CGImageRef)image {
33
+ NSError *error = nil;
34
+ NSArray<ZXIResult *> *results = [_reader readCGImage:image error:&error];
35
+ if (error != nil) {
36
+ return nil;
37
+ }
38
+ for (ZXIResult *result in results) {
39
+ if (result.text.length > 0) {
40
+ return result.text;
41
+ }
42
+ }
43
+ return nil;
44
+ }
45
+
46
+ @end
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+
3
+ export {};
4
+ //# sourceMappingURL=QrImageDecoder.nitro.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../src","sources":["QrImageDecoder.nitro.ts"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+
3
+ import { useMemo, useRef } from 'react';
4
+ import { callback, getHostComponent } from 'react-native-nitro-modules';
5
+ import { QrScannerError, isQrScannerErrorCode } from "./errors.js";
6
+ import { createScanSession } from "./ur/index.js";
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
9
+ const QrScannerConfig = require('../nitrogen/generated/shared/json/QrScannerConfig.json');
10
+ export const QrScannerView = getHostComponent('QrScanner', () => QrScannerConfig);
11
+ /**
12
+ * Camera preview wired to a shared `./ur` scan session. Native code reports
13
+ * raw text only; this component owns mode handling and UR assembly.
14
+ */
15
+ export function QrScanner({
16
+ active,
17
+ mode,
18
+ allowPlainText,
19
+ limits,
20
+ sessionKey,
21
+ style,
22
+ onReady,
23
+ onProgress,
24
+ onResult,
25
+ onError
26
+ }) {
27
+ const handlers = useRef({
28
+ onReady,
29
+ onProgress,
30
+ onResult,
31
+ onError
32
+ });
33
+ handlers.current = {
34
+ onReady,
35
+ onProgress,
36
+ onResult,
37
+ onError
38
+ };
39
+
40
+ // Limits are read once per session; callers pass a constant object.
41
+ const limitsRef = useRef(limits);
42
+ limitsRef.current = limits;
43
+ const session = useMemo(() => createScanSession({
44
+ mode,
45
+ allowPlainText,
46
+ limits: limitsRef.current
47
+ }),
48
+ // A new key, mode or plain-text rule is a new scan session.
49
+ // eslint-disable-next-line react-hooks/exhaustive-deps
50
+ [mode, allowPlainText, sessionKey]);
51
+
52
+ // Frames from an older capture generation arrive late; drop them. Native
53
+ // generations only grow for the lifetime of the view, across sessions.
54
+ const latestGeneration = useRef(0);
55
+ const nativeCallbacks = useMemo(() => ({
56
+ onReady: callback(generation => {
57
+ latestGeneration.current = Math.max(latestGeneration.current, generation);
58
+ handlers.current.onReady?.();
59
+ }),
60
+ onFrameText: callback((text, generation) => {
61
+ if (generation < latestGeneration.current) return;
62
+ latestGeneration.current = generation;
63
+ const outcome = session.receive(text);
64
+ if (outcome.status === 'progress') {
65
+ handlers.current.onProgress?.(outcome.progress);
66
+ } else if (outcome.status === 'complete') {
67
+ if (outcome.result.kind === 'ur') handlers.current.onProgress?.(1);
68
+ handlers.current.onResult?.(outcome.result);
69
+ } else if (outcome.status === 'rejected') {
70
+ handlers.current.onError?.(outcome.error);
71
+ }
72
+ }),
73
+ onError: callback((code, message, generation) => {
74
+ if (generation < latestGeneration.current) return;
75
+ handlers.current.onError?.(new QrScannerError(isQrScannerErrorCode(code) ? code : 'decoder-unavailable', message));
76
+ })
77
+ }), [session]);
78
+ return /*#__PURE__*/_jsx(QrScannerView, {
79
+ style: style,
80
+ active: active,
81
+ ...nativeCallbacks
82
+ });
83
+ }
84
+ //# sourceMappingURL=QrScanner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useMemo","useRef","callback","getHostComponent","QrScannerError","isQrScannerErrorCode","createScanSession","jsx","_jsx","QrScannerConfig","require","QrScannerView","QrScanner","active","mode","allowPlainText","limits","sessionKey","style","onReady","onProgress","onResult","onError","handlers","current","limitsRef","session","latestGeneration","nativeCallbacks","generation","Math","max","onFrameText","text","outcome","receive","status","progress","result","kind","error","code","message"],"sourceRoot":"../../src","sources":["QrScanner.tsx"],"mappings":"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","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+
3
+ export {};
4
+ //# sourceMappingURL=QrScanner.nitro.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../src","sources":["QrScanner.nitro.ts"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ /** Default pixel budget: a 12 MP photo decodes without downscaling. */
4
+ export const DEFAULT_MAX_IMAGE_PIXELS = 12_000_000;
5
+ //# sourceMappingURL=decodeQrImage.constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["DEFAULT_MAX_IMAGE_PIXELS"],"sourceRoot":"../../src","sources":["decodeQrImage.constants.ts"],"mappings":";;AAAA;AACA,OAAO,MAAMA,wBAAwB,GAAG,UAAU","ignoreList":[]}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ import { NitroModules } from 'react-native-nitro-modules';
4
+ import { toQrScannerError } from "./errors.js";
5
+ import { DEFAULT_MAX_IMAGE_PIXELS } from "./decodeQrImage.constants.js";
6
+ export { DEFAULT_MAX_IMAGE_PIXELS };
7
+ let decoder;
8
+ function getDecoder() {
9
+ decoder ??= NitroModules.createHybridObject('QrImageDecoder');
10
+ return decoder;
11
+ }
12
+
13
+ /**
14
+ * Raw text of the first QR symbol in a local image, or `null` when none is
15
+ * found. Rejects with `QrScannerError` (`invalid-image`, `resource-limit`,
16
+ * `decoder-unavailable`).
17
+ */
18
+ export async function decodeQrImage(uri, options) {
19
+ const maxPixels = options?.maxPixels ?? DEFAULT_MAX_IMAGE_PIXELS;
20
+ try {
21
+ const result = await getDecoder().decodeImage(uri, maxPixels);
22
+ return result.text ?? null;
23
+ } catch (error) {
24
+ throw toQrScannerError(error);
25
+ }
26
+ }
27
+ //# sourceMappingURL=decodeQrImage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["NitroModules","toQrScannerError","DEFAULT_MAX_IMAGE_PIXELS","decoder","getDecoder","createHybridObject","decodeQrImage","uri","options","maxPixels","result","decodeImage","text","error"],"sourceRoot":"../../src","sources":["decodeQrImage.ts"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,4BAA4B;AAEzD,SAASC,gBAAgB,QAAQ,aAAU;AAI3C,SAASC,wBAAwB,QAAQ,8BAA2B;AAEpE,SAASA,wBAAwB;AAOjC,IAAIC,OAAmC;AAEvC,SAASC,UAAUA,CAAA,EAAmB;EACpCD,OAAO,KAAKH,YAAY,CAACK,kBAAkB,CAAiB,gBAAgB,CAAC;EAC7E,OAAOF,OAAO;AAChB;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeG,aAAaA,CACjCC,GAAW,EACXC,OAA8B,EACN;EACxB,MAAMC,SAAS,GAAGD,OAAO,EAAEC,SAAS,IAAIP,wBAAwB;EAChE,IAAI;IACF,MAAMQ,MAAM,GAAG,MAAMN,UAAU,CAAC,CAAC,CAACO,WAAW,CAACJ,GAAG,EAAEE,SAAS,CAAC;IAC7D,OAAOC,MAAM,CAACE,IAAI,IAAI,IAAI;EAC5B,CAAC,CAAC,OAAOC,KAAK,EAAE;IACd,MAAMZ,gBAAgB,CAACY,KAAK,CAAC;EAC/B;AACF","ignoreList":[]}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ const KNOWN_CODES = ['permission-denied', 'no-camera', 'camera-busy', 'decoder-unavailable', 'invalid-image', 'resource-limit'];
4
+ export class QrScannerError extends Error {
5
+ name = 'QrScannerError';
6
+ constructor(code, message) {
7
+ super(message);
8
+ this.code = code;
9
+ }
10
+ }
11
+ export function isQrScannerErrorCode(value) {
12
+ return KNOWN_CODES.includes(value);
13
+ }
14
+
15
+ /**
16
+ * Native code rejects with `<code>: <reason>` because Nitro errors carry only
17
+ * a message. Unknown shapes map to `decoder-unavailable`.
18
+ */
19
+ export function toQrScannerError(error) {
20
+ if (error instanceof QrScannerError) return error;
21
+ // Android's Nitro errors append the Java stack trace; keep the first line.
22
+ const message = (error instanceof Error ? error.message : String(error)).split('\n')[0].trim();
23
+ const match = /(?:^|\s)([a-z-]+):/.exec(message);
24
+ const code = match?.[1];
25
+ if (match && code && isQrScannerErrorCode(code)) {
26
+ const reason = message.slice(match.index + match[0].length).trimStart();
27
+ return new QrScannerError(code, reason || message);
28
+ }
29
+ return new QrScannerError('decoder-unavailable', message);
30
+ }
31
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["KNOWN_CODES","QrScannerError","Error","name","constructor","code","message","isQrScannerErrorCode","value","includes","toQrScannerError","error","String","split","trim","match","exec","reason","slice","index","length","trimStart"],"sourceRoot":"../../src","sources":["errors.ts"],"mappings":";;AAQA,MAAMA,WAA0C,GAAG,CACjD,mBAAmB,EACnB,WAAW,EACX,aAAa,EACb,qBAAqB,EACrB,eAAe,EACf,gBAAgB,CACjB;AAED,OAAO,MAAMC,cAAc,SAASC,KAAK,CAAC;EAC/BC,IAAI,GAAG,gBAAgB;EAEhCC,WAAWA,CACAC,IAAwB,EACjCC,OAAe,EACf;IACA,KAAK,CAACA,OAAO,CAAC;IAAC,KAHND,IAAwB,GAAxBA,IAAwB;EAInC;AACF;AAEA,OAAO,SAASE,oBAAoBA,CAClCC,KAAa,EACgB;EAC7B,OAAQR,WAAW,CAAuBS,QAAQ,CAACD,KAAK,CAAC;AAC3D;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASE,gBAAgBA,CAACC,KAAc,EAAkB;EAC/D,IAAIA,KAAK,YAAYV,cAAc,EAAE,OAAOU,KAAK;EACjD;EACA,MAAML,OAAO,GAAG,CAACK,KAAK,YAAYT,KAAK,GAAGS,KAAK,CAACL,OAAO,GAAGM,MAAM,CAACD,KAAK,CAAC,EACpEE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CACdC,IAAI,CAAC,CAAC;EACT,MAAMC,KAAK,GAAG,oBAAoB,CAACC,IAAI,CAACV,OAAO,CAAC;EAChD,MAAMD,IAAI,GAAGU,KAAK,GAAG,CAAC,CAAC;EACvB,IAAIA,KAAK,IAAIV,IAAI,IAAIE,oBAAoB,CAACF,IAAI,CAAC,EAAE;IAC/C,MAAMY,MAAM,GAAGX,OAAO,CAACY,KAAK,CAACH,KAAK,CAACI,KAAK,GAAGJ,KAAK,CAAC,CAAC,CAAC,CAACK,MAAM,CAAC,CAACC,SAAS,CAAC,CAAC;IACvE,OAAO,IAAIpB,cAAc,CAACI,IAAI,EAAEY,MAAM,IAAIX,OAAO,CAAC;EACpD;EACA,OAAO,IAAIL,cAAc,CAAC,qBAAqB,EAAEK,OAAO,CAAC;AAC3D","ignoreList":[]}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ export { QrScanner, QrScannerView } from "./QrScanner.js";
4
+ export { DEFAULT_MAX_IMAGE_PIXELS, decodeQrImage } from "./decodeQrImage.js";
5
+ export { QrScannerError, toQrScannerError } from "./errors.js";
6
+ export { createScanSession, createUrAssembler, DEFAULT_UR_LIMITS } from "./ur/index.js";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["QrScanner","QrScannerView","DEFAULT_MAX_IMAGE_PIXELS","decodeQrImage","QrScannerError","toQrScannerError","createScanSession","createUrAssembler","DEFAULT_UR_LIMITS"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,SAAS,EAAEC,aAAa,QAAQ,gBAAa;AAEtD,SAASC,wBAAwB,EAAEC,aAAa,QAAQ,oBAAiB;AAEzE,SAASC,cAAc,EAAEC,gBAAgB,QAAQ,aAAU;AAE3D,SAASC,iBAAiB,EAAEC,iBAAiB,EAAEC,iBAAiB,QAAQ,eAAM","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"module"}