@idmission/websdk-core 0.1.0-rc.1

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 (416) hide show
  1. package/README.md +66 -0
  2. package/dist/attestation/attestationState.d.ts +24 -0
  3. package/dist/attestation/attestationState.d.ts.map +1 -0
  4. package/dist/attestation/attestationState.js +57 -0
  5. package/dist/attestation/clientAttestation.d.ts +40 -0
  6. package/dist/attestation/clientAttestation.d.ts.map +1 -0
  7. package/dist/attestation/clientAttestation.js +19 -0
  8. package/dist/attestation/collectClientAttestation.d.ts +10 -0
  9. package/dist/attestation/collectClientAttestation.d.ts.map +1 -0
  10. package/dist/attestation/collectClientAttestation.js +18 -0
  11. package/dist/attestation/index.d.ts +5 -0
  12. package/dist/attestation/index.d.ts.map +1 -0
  13. package/dist/attestation/index.js +4 -0
  14. package/dist/attestation/nativeAttestationBridge.d.ts +3 -0
  15. package/dist/attestation/nativeAttestationBridge.d.ts.map +1 -0
  16. package/dist/attestation/nativeAttestationBridge.js +38 -0
  17. package/dist/barcode/AAMVAParser.d.ts +77 -0
  18. package/dist/barcode/AAMVAParser.d.ts.map +1 -0
  19. package/dist/barcode/AAMVAParser.js +422 -0
  20. package/dist/barcode/NativeBarcodeDecoder.d.ts +157 -0
  21. package/dist/barcode/NativeBarcodeDecoder.d.ts.map +1 -0
  22. package/dist/barcode/NativeBarcodeDecoder.js +832 -0
  23. package/dist/barcode/Parse.d.ts +6 -0
  24. package/dist/barcode/Parse.d.ts.map +1 -0
  25. package/dist/barcode/Parse.js +148 -0
  26. package/dist/barcode/decodeSummary.d.ts +45 -0
  27. package/dist/barcode/decodeSummary.d.ts.map +1 -0
  28. package/dist/barcode/decodeSummary.js +23 -0
  29. package/dist/barcode/index.d.ts +5 -0
  30. package/dist/barcode/index.d.ts.map +1 -0
  31. package/dist/barcode/index.js +4 -0
  32. package/dist/camera/Camera.d.ts +37 -0
  33. package/dist/camera/Camera.d.ts.map +1 -0
  34. package/dist/camera/Camera.js +453 -0
  35. package/dist/camera/acquireCamera.d.ts +29 -0
  36. package/dist/camera/acquireCamera.d.ts.map +1 -0
  37. package/dist/camera/acquireCamera.js +224 -0
  38. package/dist/camera/cameraSignals.d.ts +23 -0
  39. package/dist/camera/cameraSignals.d.ts.map +1 -0
  40. package/dist/camera/cameraSignals.js +32 -0
  41. package/dist/camera/getUserMediaIntegrity.d.ts +72 -0
  42. package/dist/camera/getUserMediaIntegrity.d.ts.map +1 -0
  43. package/dist/camera/getUserMediaIntegrity.js +256 -0
  44. package/dist/camera/index.d.ts +6 -0
  45. package/dist/camera/index.d.ts.map +1 -0
  46. package/dist/camera/index.js +5 -0
  47. package/dist/camera/isVirtualCamera.d.ts +10 -0
  48. package/dist/camera/isVirtualCamera.d.ts.map +1 -0
  49. package/dist/camera/isVirtualCamera.js +11 -0
  50. package/dist/client/IdmissionClient.d.ts +151 -0
  51. package/dist/client/IdmissionClient.d.ts.map +1 -0
  52. package/dist/client/IdmissionClient.js +638 -0
  53. package/dist/client/additionalDocument.d.ts +14 -0
  54. package/dist/client/additionalDocument.d.ts.map +1 -0
  55. package/dist/client/additionalDocument.js +24 -0
  56. package/dist/client/artifacts.d.ts +146 -0
  57. package/dist/client/artifacts.d.ts.map +1 -0
  58. package/dist/client/artifacts.js +1 -0
  59. package/dist/client/blobToB64.d.ts +2 -0
  60. package/dist/client/blobToB64.d.ts.map +1 -0
  61. package/dist/client/blobToB64.js +17 -0
  62. package/dist/client/endpoints.d.ts +7 -0
  63. package/dist/client/endpoints.d.ts.map +1 -0
  64. package/dist/client/endpoints.js +59 -0
  65. package/dist/client/errors.d.ts +20 -0
  66. package/dist/client/errors.d.ts.map +1 -0
  67. package/dist/client/errors.js +45 -0
  68. package/dist/client/index.d.ts +23 -0
  69. package/dist/client/index.d.ts.map +1 -0
  70. package/dist/client/index.js +38 -0
  71. package/dist/client/payload.d.ts +36 -0
  72. package/dist/client/payload.d.ts.map +1 -0
  73. package/dist/client/payload.js +397 -0
  74. package/dist/client/sessionMachine.d.ts +26 -0
  75. package/dist/client/sessionMachine.d.ts.map +1 -0
  76. package/dist/client/sessionMachine.js +23 -0
  77. package/dist/client/submissionMetadata.d.ts +31 -0
  78. package/dist/client/submissionMetadata.d.ts.map +1 -0
  79. package/dist/client/submissionMetadata.js +90 -0
  80. package/dist/client/timings.d.ts +49 -0
  81. package/dist/client/timings.d.ts.map +1 -0
  82. package/dist/client/timings.js +32 -0
  83. package/dist/client/types.d.ts +305 -0
  84. package/dist/client/types.d.ts.map +1 -0
  85. package/dist/client/types.js +18 -0
  86. package/dist/client/upload.d.ts +60 -0
  87. package/dist/client/upload.d.ts.map +1 -0
  88. package/dist/client/upload.js +313 -0
  89. package/dist/client/uploadedDocument.d.ts +7 -0
  90. package/dist/client/uploadedDocument.d.ts.map +1 -0
  91. package/dist/client/uploadedDocument.js +4 -0
  92. package/dist/client/urls.d.ts +30 -0
  93. package/dist/client/urls.d.ts.map +1 -0
  94. package/dist/client/urls.js +73 -0
  95. package/dist/client/validateSession.d.ts +7 -0
  96. package/dist/client/validateSession.d.ts.map +1 -0
  97. package/dist/client/validateSession.js +63 -0
  98. package/dist/config/cdn.d.ts +2 -0
  99. package/dist/config/cdn.d.ts.map +1 -0
  100. package/dist/config/cdn.js +1 -0
  101. package/dist/diagnostics/buffer.d.ts +8 -0
  102. package/dist/diagnostics/buffer.d.ts.map +1 -0
  103. package/dist/diagnostics/buffer.js +25 -0
  104. package/dist/diagnostics/envCapability.d.ts +3 -0
  105. package/dist/diagnostics/envCapability.d.ts.map +1 -0
  106. package/dist/diagnostics/envCapability.js +40 -0
  107. package/dist/diagnostics/floodControl.d.ts +6 -0
  108. package/dist/diagnostics/floodControl.d.ts.map +1 -0
  109. package/dist/diagnostics/floodControl.js +29 -0
  110. package/dist/diagnostics/index.d.ts +8 -0
  111. package/dist/diagnostics/index.d.ts.map +1 -0
  112. package/dist/diagnostics/index.js +17 -0
  113. package/dist/diagnostics/install.d.ts +20 -0
  114. package/dist/diagnostics/install.d.ts.map +1 -0
  115. package/dist/diagnostics/install.js +159 -0
  116. package/dist/diagnostics/redaction.d.ts +7 -0
  117. package/dist/diagnostics/redaction.d.ts.map +1 -0
  118. package/dist/diagnostics/redaction.js +73 -0
  119. package/dist/diagnostics/transport.d.ts +15 -0
  120. package/dist/diagnostics/transport.d.ts.map +1 -0
  121. package/dist/diagnostics/transport.js +35 -0
  122. package/dist/diagnostics/types.d.ts +59 -0
  123. package/dist/diagnostics/types.d.ts.map +1 -0
  124. package/dist/diagnostics/types.js +1 -0
  125. package/dist/documentCapture/controller.d.ts +35 -0
  126. package/dist/documentCapture/controller.d.ts.map +1 -0
  127. package/dist/documentCapture/controller.js +254 -0
  128. package/dist/documentCapture/index.d.ts +4 -0
  129. package/dist/documentCapture/index.d.ts.map +1 -0
  130. package/dist/documentCapture/index.js +8 -0
  131. package/dist/documentCapture/reducer.d.ts +31 -0
  132. package/dist/documentCapture/reducer.d.ts.map +1 -0
  133. package/dist/documentCapture/reducer.js +87 -0
  134. package/dist/documentCapture/state.d.ts +49 -0
  135. package/dist/documentCapture/state.d.ts.map +1 -0
  136. package/dist/documentCapture/state.js +36 -0
  137. package/dist/idCapture/controller.d.ts +228 -0
  138. package/dist/idCapture/controller.d.ts.map +1 -0
  139. package/dist/idCapture/controller.js +1453 -0
  140. package/dist/idCapture/errors.d.ts +36 -0
  141. package/dist/idCapture/errors.d.ts.map +1 -0
  142. package/dist/idCapture/errors.js +18 -0
  143. package/dist/idCapture/guidance.d.ts +80 -0
  144. package/dist/idCapture/guidance.d.ts.map +1 -0
  145. package/dist/idCapture/guidance.js +143 -0
  146. package/dist/idCapture/index.d.ts +22 -0
  147. package/dist/idCapture/index.d.ts.map +1 -0
  148. package/dist/idCapture/index.js +46 -0
  149. package/dist/idCapture/phase.d.ts +10 -0
  150. package/dist/idCapture/phase.d.ts.map +1 -0
  151. package/dist/idCapture/phase.js +28 -0
  152. package/dist/idCapture/pipeline.d.ts +176 -0
  153. package/dist/idCapture/pipeline.d.ts.map +1 -0
  154. package/dist/idCapture/pipeline.js +1028 -0
  155. package/dist/idCapture/reducer.d.ts +3 -0
  156. package/dist/idCapture/reducer.d.ts.map +1 -0
  157. package/dist/idCapture/reducer.js +661 -0
  158. package/dist/idCapture/requirements.d.ts +10 -0
  159. package/dist/idCapture/requirements.d.ts.map +1 -0
  160. package/dist/idCapture/requirements.js +43 -0
  161. package/dist/idCapture/stabilizer.d.ts +2 -0
  162. package/dist/idCapture/stabilizer.d.ts.map +1 -0
  163. package/dist/idCapture/stabilizer.js +4 -0
  164. package/dist/idCapture/state.d.ts +426 -0
  165. package/dist/idCapture/state.d.ts.map +1 -0
  166. package/dist/idCapture/state.js +91 -0
  167. package/dist/idCapture/submit.d.ts +33 -0
  168. package/dist/idCapture/submit.d.ts.map +1 -0
  169. package/dist/idCapture/submit.js +105 -0
  170. package/dist/idCapture/types.d.ts +20 -0
  171. package/dist/idCapture/types.d.ts.map +1 -0
  172. package/dist/idCapture/types.js +12 -0
  173. package/dist/index.d.ts +6 -0
  174. package/dist/index.d.ts.map +1 -0
  175. package/dist/index.js +5 -0
  176. package/dist/liveness/challengeGeometry.d.ts +66 -0
  177. package/dist/liveness/challengeGeometry.d.ts.map +1 -0
  178. package/dist/liveness/challengeGeometry.js +226 -0
  179. package/dist/liveness/challengeSequence.d.ts +49 -0
  180. package/dist/liveness/challengeSequence.d.ts.map +1 -0
  181. package/dist/liveness/challengeSequence.js +71 -0
  182. package/dist/liveness/index.d.ts +4 -0
  183. package/dist/liveness/index.d.ts.map +1 -0
  184. package/dist/liveness/index.js +3 -0
  185. package/dist/liveness/livenessResult.d.ts +11 -0
  186. package/dist/liveness/livenessResult.d.ts.map +1 -0
  187. package/dist/liveness/livenessResult.js +16 -0
  188. package/dist/models/BarcodeReadability.d.ts +36 -0
  189. package/dist/models/BarcodeReadability.d.ts.map +1 -0
  190. package/dist/models/BarcodeReadability.js +71 -0
  191. package/dist/models/CapabilityProbing.d.ts +25 -0
  192. package/dist/models/CapabilityProbing.d.ts.map +1 -0
  193. package/dist/models/CapabilityProbing.js +172 -0
  194. package/dist/models/DocumentDetection.d.ts +96 -0
  195. package/dist/models/DocumentDetection.d.ts.map +1 -0
  196. package/dist/models/DocumentDetection.js +257 -0
  197. package/dist/models/FaceDetection.d.ts +21 -0
  198. package/dist/models/FaceDetection.d.ts.map +1 -0
  199. package/dist/models/FaceDetection.js +4 -0
  200. package/dist/models/Focus.d.ts +36 -0
  201. package/dist/models/Focus.d.ts.map +1 -0
  202. package/dist/models/Focus.js +69 -0
  203. package/dist/models/FrameLoop.d.ts +13 -0
  204. package/dist/models/FrameLoop.d.ts.map +1 -0
  205. package/dist/models/FrameLoop.js +56 -0
  206. package/dist/models/VisionRuntime.d.ts +18 -0
  207. package/dist/models/VisionRuntime.d.ts.map +1 -0
  208. package/dist/models/VisionRuntime.js +158 -0
  209. package/dist/models/defaults/BarcodeReadability.d.ts +3 -0
  210. package/dist/models/defaults/BarcodeReadability.d.ts.map +1 -0
  211. package/dist/models/defaults/BarcodeReadability.js +3 -0
  212. package/dist/models/defaults/BarcodeReadabilityLiteRT.d.ts +3 -0
  213. package/dist/models/defaults/BarcodeReadabilityLiteRT.d.ts.map +1 -0
  214. package/dist/models/defaults/BarcodeReadabilityLiteRT.js +3 -0
  215. package/dist/models/defaults/DocumentDetector.d.ts +3 -0
  216. package/dist/models/defaults/DocumentDetector.d.ts.map +1 -0
  217. package/dist/models/defaults/DocumentDetector.js +3 -0
  218. package/dist/models/defaults/DocumentDetectorLiteRT.d.ts +3 -0
  219. package/dist/models/defaults/DocumentDetectorLiteRT.d.ts.map +1 -0
  220. package/dist/models/defaults/DocumentDetectorLiteRT.js +3 -0
  221. package/dist/models/defaults/FaceDetector.d.ts +3 -0
  222. package/dist/models/defaults/FaceDetector.d.ts.map +1 -0
  223. package/dist/models/defaults/FaceDetector.js +3 -0
  224. package/dist/models/defaults/FaceLandmarker.d.ts +3 -0
  225. package/dist/models/defaults/FaceLandmarker.d.ts.map +1 -0
  226. package/dist/models/defaults/FaceLandmarker.js +8 -0
  227. package/dist/models/defaults/FaceLandmarkerLiteRT.d.ts +3 -0
  228. package/dist/models/defaults/FaceLandmarkerLiteRT.d.ts.map +1 -0
  229. package/dist/models/defaults/FaceLandmarkerLiteRT.js +3 -0
  230. package/dist/models/defaults/Focus.d.ts +3 -0
  231. package/dist/models/defaults/Focus.d.ts.map +1 -0
  232. package/dist/models/defaults/Focus.js +3 -0
  233. package/dist/models/defaults/FocusLiteRT.d.ts +3 -0
  234. package/dist/models/defaults/FocusLiteRT.d.ts.map +1 -0
  235. package/dist/models/defaults/FocusLiteRT.js +3 -0
  236. package/dist/models/defaults/index.d.ts +31 -0
  237. package/dist/models/defaults/index.d.ts.map +1 -0
  238. package/dist/models/defaults/index.js +38 -0
  239. package/dist/models/helpers.d.ts +25 -0
  240. package/dist/models/helpers.d.ts.map +1 -0
  241. package/dist/models/helpers.js +98 -0
  242. package/dist/models/index.d.ts +15 -0
  243. package/dist/models/index.d.ts.map +1 -0
  244. package/dist/models/index.js +14 -0
  245. package/dist/models/modelLifecycle.d.ts +26 -0
  246. package/dist/models/modelLifecycle.d.ts.map +1 -0
  247. package/dist/models/modelLifecycle.js +137 -0
  248. package/dist/models/occlusion.d.ts +20 -0
  249. package/dist/models/occlusion.d.ts.map +1 -0
  250. package/dist/models/occlusion.js +109 -0
  251. package/dist/models/passportBooklet.d.ts +34 -0
  252. package/dist/models/passportBooklet.d.ts.map +1 -0
  253. package/dist/models/passportBooklet.js +152 -0
  254. package/dist/models/preloadModels.d.ts +42 -0
  255. package/dist/models/preloadModels.d.ts.map +1 -0
  256. package/dist/models/preloadModels.js +204 -0
  257. package/dist/models/providers/litert/BarcodeReadability.d.ts +11 -0
  258. package/dist/models/providers/litert/BarcodeReadability.d.ts.map +1 -0
  259. package/dist/models/providers/litert/BarcodeReadability.js +135 -0
  260. package/dist/models/providers/litert/CapabilityProbe.d.ts +3 -0
  261. package/dist/models/providers/litert/CapabilityProbe.d.ts.map +1 -0
  262. package/dist/models/providers/litert/CapabilityProbe.js +44 -0
  263. package/dist/models/providers/litert/DocumentDetection.d.ts +18 -0
  264. package/dist/models/providers/litert/DocumentDetection.d.ts.map +1 -0
  265. package/dist/models/providers/litert/DocumentDetection.js +194 -0
  266. package/dist/models/providers/litert/FaceDetection.d.ts +11 -0
  267. package/dist/models/providers/litert/FaceDetection.d.ts.map +1 -0
  268. package/dist/models/providers/litert/FaceDetection.js +204 -0
  269. package/dist/models/providers/litert/FaceLandmarker.d.ts +11 -0
  270. package/dist/models/providers/litert/FaceLandmarker.d.ts.map +1 -0
  271. package/dist/models/providers/litert/FaceLandmarker.js +199 -0
  272. package/dist/models/providers/litert/Focus.d.ts +11 -0
  273. package/dist/models/providers/litert/Focus.d.ts.map +1 -0
  274. package/dist/models/providers/litert/Focus.js +141 -0
  275. package/dist/models/providers/litert/barcodeReadabilityPrePost.d.ts +6 -0
  276. package/dist/models/providers/litert/barcodeReadabilityPrePost.d.ts.map +1 -0
  277. package/dist/models/providers/litert/barcodeReadabilityPrePost.js +68 -0
  278. package/dist/models/providers/litert/blazeFacePrePost.d.ts +30 -0
  279. package/dist/models/providers/litert/blazeFacePrePost.d.ts.map +1 -0
  280. package/dist/models/providers/litert/blazeFacePrePost.js +206 -0
  281. package/dist/models/providers/litert/docDetectPrePost.d.ts +25 -0
  282. package/dist/models/providers/litert/docDetectPrePost.d.ts.map +1 -0
  283. package/dist/models/providers/litert/docDetectPrePost.js +197 -0
  284. package/dist/models/providers/litert/faceMeshPrePost.d.ts +23 -0
  285. package/dist/models/providers/litert/faceMeshPrePost.d.ts.map +1 -0
  286. package/dist/models/providers/litert/faceMeshPrePost.js +86 -0
  287. package/dist/models/providers/litert/focusPrePost.d.ts +6 -0
  288. package/dist/models/providers/litert/focusPrePost.d.ts.map +1 -0
  289. package/dist/models/providers/litert/focusPrePost.js +67 -0
  290. package/dist/models/providers/litert/runtime.d.ts +14 -0
  291. package/dist/models/providers/litert/runtime.d.ts.map +1 -0
  292. package/dist/models/providers/litert/runtime.js +83 -0
  293. package/dist/models/providers/mediapipe/BarcodeReadability.d.ts +11 -0
  294. package/dist/models/providers/mediapipe/BarcodeReadability.d.ts.map +1 -0
  295. package/dist/models/providers/mediapipe/BarcodeReadability.js +68 -0
  296. package/dist/models/providers/mediapipe/CapabilityProbe.d.ts +2 -0
  297. package/dist/models/providers/mediapipe/CapabilityProbe.d.ts.map +1 -0
  298. package/dist/models/providers/mediapipe/CapabilityProbe.js +14 -0
  299. package/dist/models/providers/mediapipe/DocumentDetection.d.ts +12 -0
  300. package/dist/models/providers/mediapipe/DocumentDetection.d.ts.map +1 -0
  301. package/dist/models/providers/mediapipe/DocumentDetection.js +90 -0
  302. package/dist/models/providers/mediapipe/FaceDetection.d.ts +11 -0
  303. package/dist/models/providers/mediapipe/FaceDetection.d.ts.map +1 -0
  304. package/dist/models/providers/mediapipe/FaceDetection.js +93 -0
  305. package/dist/models/providers/mediapipe/FaceLandmarker.d.ts +46 -0
  306. package/dist/models/providers/mediapipe/FaceLandmarker.d.ts.map +1 -0
  307. package/dist/models/providers/mediapipe/FaceLandmarker.js +166 -0
  308. package/dist/models/providers/mediapipe/Focus.d.ts +11 -0
  309. package/dist/models/providers/mediapipe/Focus.d.ts.map +1 -0
  310. package/dist/models/providers/mediapipe/Focus.js +51 -0
  311. package/dist/models/runtimeSelection.d.ts +5 -0
  312. package/dist/models/runtimeSelection.d.ts.map +1 -0
  313. package/dist/models/runtimeSelection.js +21 -0
  314. package/dist/selfieCapture/challengeRunner.d.ts +38 -0
  315. package/dist/selfieCapture/challengeRunner.d.ts.map +1 -0
  316. package/dist/selfieCapture/challengeRunner.js +181 -0
  317. package/dist/selfieCapture/controller.d.ts +166 -0
  318. package/dist/selfieCapture/controller.d.ts.map +1 -0
  319. package/dist/selfieCapture/controller.js +1253 -0
  320. package/dist/selfieCapture/faceTracking.d.ts +67 -0
  321. package/dist/selfieCapture/faceTracking.d.ts.map +1 -0
  322. package/dist/selfieCapture/faceTracking.js +158 -0
  323. package/dist/selfieCapture/guidance.d.ts +24 -0
  324. package/dist/selfieCapture/guidance.d.ts.map +1 -0
  325. package/dist/selfieCapture/guidance.js +41 -0
  326. package/dist/selfieCapture/index.d.ts +18 -0
  327. package/dist/selfieCapture/index.d.ts.map +1 -0
  328. package/dist/selfieCapture/index.js +11 -0
  329. package/dist/selfieCapture/lighting.d.ts +36 -0
  330. package/dist/selfieCapture/lighting.d.ts.map +1 -0
  331. package/dist/selfieCapture/lighting.js +95 -0
  332. package/dist/selfieCapture/livenessMachine.d.ts +66 -0
  333. package/dist/selfieCapture/livenessMachine.d.ts.map +1 -0
  334. package/dist/selfieCapture/livenessMachine.js +137 -0
  335. package/dist/selfieCapture/pipeline.d.ts +42 -0
  336. package/dist/selfieCapture/pipeline.d.ts.map +1 -0
  337. package/dist/selfieCapture/pipeline.js +282 -0
  338. package/dist/selfieCapture/reducer.d.ts +35 -0
  339. package/dist/selfieCapture/reducer.d.ts.map +1 -0
  340. package/dist/selfieCapture/reducer.js +143 -0
  341. package/dist/selfieCapture/state.d.ts +40 -0
  342. package/dist/selfieCapture/state.d.ts.map +1 -0
  343. package/dist/selfieCapture/state.js +36 -0
  344. package/dist/selfieCapture/testing/challengeFixtures.d.ts +43 -0
  345. package/dist/selfieCapture/testing/challengeFixtures.d.ts.map +1 -0
  346. package/dist/selfieCapture/testing/challengeFixtures.js +43 -0
  347. package/dist/signature/frameDecode.d.ts +48 -0
  348. package/dist/signature/frameDecode.d.ts.map +1 -0
  349. package/dist/signature/frameDecode.js +491 -0
  350. package/dist/signature/index.d.ts +5 -0
  351. package/dist/signature/index.d.ts.map +1 -0
  352. package/dist/signature/index.js +4 -0
  353. package/dist/signature/metadata.d.ts +63 -0
  354. package/dist/signature/metadata.d.ts.map +1 -0
  355. package/dist/signature/metadata.js +1 -0
  356. package/dist/signature/quality.d.ts +169 -0
  357. package/dist/signature/quality.d.ts.map +1 -0
  358. package/dist/signature/quality.js +186 -0
  359. package/dist/signature/signatureValidity.d.ts +149 -0
  360. package/dist/signature/signatureValidity.d.ts.map +1 -0
  361. package/dist/signature/signatureValidity.js +305 -0
  362. package/dist/signatureCapture/controller.d.ts +67 -0
  363. package/dist/signatureCapture/controller.d.ts.map +1 -0
  364. package/dist/signatureCapture/controller.js +534 -0
  365. package/dist/signatureCapture/guidance.d.ts +9 -0
  366. package/dist/signatureCapture/guidance.d.ts.map +1 -0
  367. package/dist/signatureCapture/guidance.js +7 -0
  368. package/dist/signatureCapture/index.d.ts +6 -0
  369. package/dist/signatureCapture/index.d.ts.map +1 -0
  370. package/dist/signatureCapture/index.js +5 -0
  371. package/dist/signatureCapture/pipeline.d.ts +111 -0
  372. package/dist/signatureCapture/pipeline.d.ts.map +1 -0
  373. package/dist/signatureCapture/pipeline.js +680 -0
  374. package/dist/signatureCapture/reducer.d.ts +42 -0
  375. package/dist/signatureCapture/reducer.d.ts.map +1 -0
  376. package/dist/signatureCapture/reducer.js +159 -0
  377. package/dist/signatureCapture/state.d.ts +92 -0
  378. package/dist/signatureCapture/state.d.ts.map +1 -0
  379. package/dist/signatureCapture/state.js +24 -0
  380. package/dist/utils/canvas.d.ts +4 -0
  381. package/dist/utils/canvas.d.ts.map +1 -0
  382. package/dist/utils/canvas.js +21 -0
  383. package/dist/utils/cropping.d.ts +8 -0
  384. package/dist/utils/cropping.d.ts.map +1 -0
  385. package/dist/utils/cropping.js +85 -0
  386. package/dist/utils/dataUrlToBase64.d.ts +7 -0
  387. package/dist/utils/dataUrlToBase64.d.ts.map +1 -0
  388. package/dist/utils/dataUrlToBase64.js +67 -0
  389. package/dist/utils/getFrameDimensions.d.ts +3 -0
  390. package/dist/utils/getFrameDimensions.d.ts.map +1 -0
  391. package/dist/utils/getFrameDimensions.js +12 -0
  392. package/dist/utils/isMobile.d.ts +3 -0
  393. package/dist/utils/isMobile.d.ts.map +1 -0
  394. package/dist/utils/isMobile.js +36 -0
  395. package/dist/utils/logger.d.ts +19 -0
  396. package/dist/utils/logger.d.ts.map +1 -0
  397. package/dist/utils/logger.js +25 -0
  398. package/dist/utils/platform.d.ts +4 -0
  399. package/dist/utils/platform.d.ts.map +1 -0
  400. package/dist/utils/platform.js +11 -0
  401. package/dist/utils/stabilizer.d.ts +26 -0
  402. package/dist/utils/stabilizer.d.ts.map +1 -0
  403. package/dist/utils/stabilizer.js +65 -0
  404. package/dist/version.d.ts +2 -0
  405. package/dist/version.d.ts.map +1 -0
  406. package/dist/version.js +1 -0
  407. package/dist/videoIdCapture/controller.d.ts +108 -0
  408. package/dist/videoIdCapture/controller.d.ts.map +1 -0
  409. package/dist/videoIdCapture/controller.js +833 -0
  410. package/dist/videoIdCapture/index.d.ts +5 -0
  411. package/dist/videoIdCapture/index.d.ts.map +1 -0
  412. package/dist/videoIdCapture/index.js +2 -0
  413. package/dist/videoIdCapture/state.d.ts +88 -0
  414. package/dist/videoIdCapture/state.d.ts.map +1 -0
  415. package/dist/videoIdCapture/state.js +67 -0
  416. package/package.json +111 -0
@@ -0,0 +1,832 @@
1
+ /**
2
+ * Native barcode decoder that tries browser BarcodeDetector API first,
3
+ * then falls back to zxing-js for broader compatibility.
4
+ */
5
+ import { DEFAULT_CDN_URL } from '../config/cdn';
6
+ import log, { warn } from '../utils/logger';
7
+ // zxing-js UMD build, self-hosted on the SDK's own CDN (version-pinned) rather
8
+ // than fetched from unpkg. The previous `@latest` URL was both an external
9
+ // dependency and a supply-chain risk — it executed whatever unpkg served as
10
+ // latest, which had already drifted past the version in our lockfile. Keep the
11
+ // version here in sync with @zxing/library and upload the matching UMD build
12
+ // with `scripts/setzxing.sh`.
13
+ const ZXING_VERSION = '0.21.3';
14
+ const ZXING_CDN_URL = `${DEFAULT_CDN_URL}/vendor/zxing/${ZXING_VERSION}/index.min.js`;
15
+ // ZXing parse attempt counter for diagnostics
16
+ let zxingAttemptCount = 0;
17
+ export function getZxingAttemptCount() {
18
+ return zxingAttemptCount;
19
+ }
20
+ export function resetZxingAttemptCount() {
21
+ zxingAttemptCount = 0;
22
+ }
23
+ export function incrementZxingAttemptCount() {
24
+ zxingAttemptCount++;
25
+ }
26
+ let zxingLoadPromise = null;
27
+ let zxingInstance = null;
28
+ let nativeSupportChecked = false;
29
+ let nativeSupportsFormat = false;
30
+ /**
31
+ * Check if the native BarcodeDetector API is available
32
+ */
33
+ export function isNativeBarcodeDetectorAvailable() {
34
+ return typeof window !== 'undefined' && 'BarcodeDetector' in window;
35
+ }
36
+ /**
37
+ * Check if the native BarcodeDetector supports PDF417 format
38
+ */
39
+ export async function checkNativePDF417Support() {
40
+ if (nativeSupportChecked) {
41
+ return nativeSupportsFormat;
42
+ }
43
+ if (!isNativeBarcodeDetectorAvailable()) {
44
+ nativeSupportChecked = true;
45
+ nativeSupportsFormat = false;
46
+ return false;
47
+ }
48
+ try {
49
+ const formats = await window.BarcodeDetector.getSupportedFormats();
50
+ nativeSupportsFormat = formats.includes('pdf417');
51
+ nativeSupportChecked = true;
52
+ log('[NativeBarcodeDecoder] Native BarcodeDetector formats:', formats);
53
+ log('[NativeBarcodeDecoder] PDF417 supported:', nativeSupportsFormat);
54
+ return nativeSupportsFormat;
55
+ }
56
+ catch (error) {
57
+ warn('[NativeBarcodeDecoder] Error checking native format support:', error);
58
+ nativeSupportChecked = true;
59
+ nativeSupportsFormat = false;
60
+ return false;
61
+ }
62
+ }
63
+ /**
64
+ * Load a script from URL
65
+ */
66
+ function loadScript(url) {
67
+ return new Promise((resolve, reject) => {
68
+ if (document.querySelector(`script[src="${url}"]`)) {
69
+ resolve();
70
+ return;
71
+ }
72
+ const script = document.createElement('script');
73
+ script.src = url;
74
+ script.async = true;
75
+ script.onload = () => resolve();
76
+ script.onerror = () => reject(new Error(`Failed to load script from ${url}`));
77
+ document.head.appendChild(script);
78
+ });
79
+ }
80
+ /**
81
+ * Load zxing-js from CDN
82
+ */
83
+ export async function loadZXing() {
84
+ if (window.ZXing) {
85
+ return window.ZXing;
86
+ }
87
+ if (zxingLoadPromise) {
88
+ return zxingLoadPromise;
89
+ }
90
+ zxingLoadPromise = (async () => {
91
+ await loadScript(ZXING_CDN_URL);
92
+ if (!window.ZXing) {
93
+ throw new Error('Failed to load ZXing library from CDN');
94
+ }
95
+ log('[NativeBarcodeDecoder] Loaded @zxing/library from CDN');
96
+ return window.ZXing;
97
+ })();
98
+ return zxingLoadPromise;
99
+ }
100
+ /**
101
+ * Create a ZXing reader instance configured for PDF417
102
+ */
103
+ async function getZXingReader() {
104
+ if (zxingInstance) {
105
+ return zxingInstance;
106
+ }
107
+ const ZXing = await loadZXing();
108
+ // Use the dedicated PDF417 reader class
109
+ const reader = new ZXing.BrowserPDF417Reader();
110
+ zxingInstance = reader;
111
+ return reader;
112
+ }
113
+ /**
114
+ * Decode a barcode using the native BarcodeDetector API
115
+ */
116
+ async function decodeWithNative(image) {
117
+ if (!isNativeBarcodeDetectorAvailable()) {
118
+ return null;
119
+ }
120
+ try {
121
+ const detector = new window.BarcodeDetector({ formats: ['pdf417'] });
122
+ const results = await detector.detect(image);
123
+ if (results.length > 0) {
124
+ const result = results[0];
125
+ // Check that rawValue is not empty - the native API sometimes detects the barcode
126
+ // pattern but fails to decode the actual data, returning empty string
127
+ if (!result.rawValue || result.rawValue.trim() === '') {
128
+ warn('[NativeBarcodeDecoder] Native API detected barcode but returned empty rawValue');
129
+ return null;
130
+ }
131
+ return {
132
+ text: result.rawValue,
133
+ format: result.format,
134
+ method: 'native',
135
+ rotationApplied: null,
136
+ };
137
+ }
138
+ return null;
139
+ }
140
+ catch (error) {
141
+ warn('[NativeBarcodeDecoder] Native decode error:', error);
142
+ return null;
143
+ }
144
+ }
145
+ /**
146
+ * Convert a canvas to an HTMLImageElement
147
+ */
148
+ async function canvasToImage(canvas) {
149
+ return new Promise((resolve, reject) => {
150
+ const img = new Image();
151
+ img.onload = () => resolve(img);
152
+ img.onerror = () => reject(new Error('Failed to convert canvas to image'));
153
+ img.src = canvas.toDataURL('image/png');
154
+ });
155
+ }
156
+ /**
157
+ * Decode a barcode using zxing-js
158
+ */
159
+ async function decodeWithZXing(image) {
160
+ try {
161
+ zxingAttemptCount++;
162
+ log(`[NativeBarcodeDecoder] decodeWithZXing called, attempt count now: ${zxingAttemptCount}`);
163
+ const reader = await getZXingReader();
164
+ let imageElement;
165
+ if (image instanceof HTMLImageElement) {
166
+ imageElement = image;
167
+ }
168
+ else if (image instanceof HTMLCanvasElement) {
169
+ // ZXing doesn't have decodeFromCanvas, so convert to image first
170
+ imageElement = await canvasToImage(image);
171
+ }
172
+ else {
173
+ throw new Error('Unsupported image type for ZXing decoder');
174
+ }
175
+ // decodeFromImage takes an image element
176
+ const result = await reader.decodeFromImage(imageElement);
177
+ // Result has both .text property and .getText() method
178
+ const text = result.text || result.getText();
179
+ const format = result.getBarcodeFormat().toString();
180
+ return {
181
+ text,
182
+ format,
183
+ method: 'zxing',
184
+ rotationApplied: null,
185
+ };
186
+ }
187
+ catch (error) {
188
+ // NotFoundException is expected when no barcode is found
189
+ if (error instanceof Error &&
190
+ error.name !== 'NotFoundException' &&
191
+ !error.message?.includes('No barcode') &&
192
+ !error.message?.includes('not found')) {
193
+ warn('[NativeBarcodeDecoder] ZXing decode error:', error);
194
+ }
195
+ return null;
196
+ }
197
+ }
198
+ /**
199
+ * Convert various image sources to HTMLImageElement or HTMLCanvasElement
200
+ */
201
+ async function prepareImageForDecoding(source) {
202
+ // If it's already an HTMLImageElement
203
+ if (source instanceof HTMLImageElement) {
204
+ // Ensure image is loaded
205
+ if (!source.complete) {
206
+ await new Promise((resolve, reject) => {
207
+ source.onload = () => resolve();
208
+ source.onerror = () => reject(new Error('Failed to load image'));
209
+ });
210
+ }
211
+ return source;
212
+ }
213
+ // If it's a canvas, return it directly
214
+ if (source instanceof HTMLCanvasElement) {
215
+ return source;
216
+ }
217
+ // If it's a video element, capture a frame to canvas
218
+ if (source instanceof HTMLVideoElement) {
219
+ const canvas = document.createElement('canvas');
220
+ canvas.width = source.videoWidth;
221
+ canvas.height = source.videoHeight;
222
+ const ctx = canvas.getContext('2d');
223
+ if (!ctx) {
224
+ throw new Error('Failed to get canvas context');
225
+ }
226
+ ctx.drawImage(source, 0, 0);
227
+ return canvas;
228
+ }
229
+ // If it's ImageData, draw to canvas
230
+ if (source instanceof ImageData) {
231
+ const canvas = document.createElement('canvas');
232
+ canvas.width = source.width;
233
+ canvas.height = source.height;
234
+ const ctx = canvas.getContext('2d');
235
+ if (!ctx) {
236
+ throw new Error('Failed to get canvas context');
237
+ }
238
+ ctx.putImageData(source, 0, 0);
239
+ return canvas;
240
+ }
241
+ // If it's a Blob, convert to image
242
+ if (source instanceof Blob) {
243
+ const url = URL.createObjectURL(source);
244
+ try {
245
+ const img = new Image();
246
+ img.crossOrigin = 'anonymous';
247
+ await new Promise((resolve, reject) => {
248
+ img.onload = () => resolve();
249
+ img.onerror = () => reject(new Error('Failed to load image from blob'));
250
+ img.src = url;
251
+ });
252
+ return img;
253
+ }
254
+ finally {
255
+ URL.revokeObjectURL(url);
256
+ }
257
+ }
258
+ // If it's an ImageBitmap, draw to canvas
259
+ if (source instanceof ImageBitmap) {
260
+ const canvas = document.createElement('canvas');
261
+ canvas.width = source.width;
262
+ canvas.height = source.height;
263
+ const ctx = canvas.getContext('2d');
264
+ if (!ctx) {
265
+ throw new Error('Failed to get canvas context');
266
+ }
267
+ ctx.drawImage(source, 0, 0);
268
+ return canvas;
269
+ }
270
+ throw new Error('Unsupported image source type');
271
+ }
272
+ /**
273
+ * Rotate an image or canvas by a given angle (90 or 270 degrees)
274
+ */
275
+ function rotateCanvas(source, degrees) {
276
+ const sourceWidth = source instanceof HTMLImageElement ? source.naturalWidth : source.width;
277
+ const sourceHeight = source instanceof HTMLImageElement ? source.naturalHeight : source.height;
278
+ // For 90° and 270° rotations, width and height are swapped
279
+ const canvas = document.createElement('canvas');
280
+ canvas.width = sourceHeight;
281
+ canvas.height = sourceWidth;
282
+ const ctx = canvas.getContext('2d');
283
+ if (!ctx) {
284
+ throw new Error('Failed to get canvas context for rotation');
285
+ }
286
+ if (degrees === 90) {
287
+ // 90° clockwise: translate to top-right, rotate, draw
288
+ ctx.translate(canvas.width, 0);
289
+ ctx.rotate(Math.PI / 2);
290
+ }
291
+ else {
292
+ // 270° clockwise (90° counter-clockwise): translate to bottom-left, rotate
293
+ ctx.translate(0, canvas.height);
294
+ ctx.rotate(-Math.PI / 2);
295
+ }
296
+ ctx.drawImage(source, 0, 0);
297
+ return canvas;
298
+ }
299
+ /** Fine rotation angles to try, ordered by probability (small skew most common) */
300
+ const FINE_ROTATION_ANGLES = [
301
+ -1, 1, -2, 2, -3, 3, -4, 4, -5, 5, -6, 6,
302
+ -7, 7, -8, 8, -9, 9, -10, 10, -11, 11, -12, 12,
303
+ ];
304
+ /**
305
+ * Rotate an image or canvas by an arbitrary angle (in degrees).
306
+ * Computes the bounding box of the rotated rectangle, fills with white
307
+ * (barcode paper background), and draws the source centered.
308
+ *
309
+ * Accepts an optional outputCanvas for reuse (avoids repeated allocation on old phones).
310
+ */
311
+ function rotateCanvasArbitrary(source, degrees, outputCanvas) {
312
+ const w = source instanceof HTMLImageElement ? source.naturalWidth : source.width;
313
+ const h = source instanceof HTMLImageElement ? source.naturalHeight : source.height;
314
+ const rad = (degrees * Math.PI) / 180;
315
+ const cosA = Math.abs(Math.cos(rad));
316
+ const sinA = Math.abs(Math.sin(rad));
317
+ // Pad the canvas so the barcode quiet zone is preserved after rotation.
318
+ // Use 5% of the larger dimension so padding scales with camera resolution.
319
+ const padding = Math.ceil(Math.max(w, h) * 0.1);
320
+ const newW = Math.ceil(w * cosA + h * sinA) + padding * 2;
321
+ const newH = Math.ceil(w * sinA + h * cosA) + padding * 2;
322
+ const canvas = outputCanvas ?? document.createElement('canvas');
323
+ canvas.width = newW;
324
+ canvas.height = newH;
325
+ const ctx = canvas.getContext('2d');
326
+ if (!ctx) {
327
+ throw new Error('Failed to get canvas context for arbitrary rotation');
328
+ }
329
+ // White background (barcode paper)
330
+ ctx.fillStyle = '#ffffff';
331
+ ctx.fillRect(0, 0, newW, newH);
332
+ // Translate to center, rotate, draw centered
333
+ ctx.translate(newW / 2, newH / 2);
334
+ ctx.rotate(rad);
335
+ ctx.drawImage(source, -w / 2, -h / 2);
336
+ return canvas;
337
+ }
338
+ /**
339
+ * Get dimensions from various image sources
340
+ */
341
+ function getImageDimensions(source) {
342
+ if (source instanceof HTMLImageElement) {
343
+ return { width: source.naturalWidth, height: source.naturalHeight };
344
+ }
345
+ return { width: source.width, height: source.height };
346
+ }
347
+ /**
348
+ * Internal function to attempt decoding with both native and zxing
349
+ */
350
+ async function attemptDecode(source, preparedImage, tryNative, fallbackToZXing) {
351
+ // Try native API first if enabled
352
+ if (tryNative) {
353
+ const supportsNative = await checkNativePDF417Support();
354
+ if (supportsNative) {
355
+ // Native API can work with the original source or a canvas
356
+ const nativeSource = preparedImage ?? source;
357
+ const nativeResult = await decodeWithNative(nativeSource);
358
+ if (nativeResult) {
359
+ return nativeResult;
360
+ }
361
+ }
362
+ }
363
+ // Fall back to zxing-js
364
+ if (fallbackToZXing) {
365
+ const imageForZxing = preparedImage ?? (await prepareImageForDecoding(source));
366
+ const zxingResult = await decodeWithZXing(imageForZxing);
367
+ if (zxingResult) {
368
+ return zxingResult;
369
+ }
370
+ }
371
+ return null;
372
+ }
373
+ /**
374
+ * Decode a PDF417 barcode from an image source.
375
+ *
376
+ * Tries native BarcodeDetector API first (if available and supports PDF417),
377
+ * then falls back to zxing-js.
378
+ *
379
+ * If the image is portrait-oriented (taller than wide), it will also try
380
+ * 90° and 270° rotations since barcodes captured sideways may not parse correctly.
381
+ *
382
+ * @param source - Image source (HTMLImageElement, HTMLCanvasElement, HTMLVideoElement, ImageData, Blob, ImageBitmap)
383
+ * @param options - Decode options
384
+ * @returns Decoded barcode result or null if no barcode found
385
+ */
386
+ export async function decodePDF417(source, options = {}) {
387
+ const { tryNative = false, // Native BarcodeDetector often detects but fails to decode - ZXing is more reliable
388
+ fallbackToZXing = true, preloadZXing = false, tryRotations = true, tryFineRotations = false, } = options;
389
+ // Optionally preload zxing in background
390
+ if (preloadZXing && fallbackToZXing) {
391
+ loadZXing().catch(() => {
392
+ /* ignore preload errors */
393
+ });
394
+ }
395
+ // Prepare the image once for reuse
396
+ const preparedImage = await prepareImageForDecoding(source);
397
+ // Try decoding the original image first
398
+ const originalResult = await attemptDecode(source, preparedImage, tryNative, fallbackToZXing);
399
+ if (originalResult) {
400
+ return { ...originalResult, rotationApplied: 0 };
401
+ }
402
+ // If image is portrait-oriented (taller than wide), try rotations
403
+ // This helps when barcodes are captured sideways
404
+ if (tryRotations) {
405
+ const { width, height } = getImageDimensions(preparedImage);
406
+ if (height > width) {
407
+ log(`[NativeBarcodeDecoder] Image is portrait (${width}x${height}), trying rotations...`);
408
+ // Try 90° rotation
409
+ const rotated90 = rotateCanvas(preparedImage, 90);
410
+ const result90 = await attemptDecode(rotated90, rotated90, tryNative, fallbackToZXing);
411
+ if (result90) {
412
+ log('[NativeBarcodeDecoder] Decoded successfully after 90° rotation');
413
+ return { ...result90, rotationApplied: 90 };
414
+ }
415
+ // Try 270° rotation
416
+ const rotated270 = rotateCanvas(preparedImage, 270);
417
+ const result270 = await attemptDecode(rotated270, rotated270, tryNative, fallbackToZXing);
418
+ if (result270) {
419
+ log('[NativeBarcodeDecoder] Decoded successfully after 270° rotation');
420
+ return { ...result270, rotationApplied: 270 };
421
+ }
422
+ log('[NativeBarcodeDecoder] No barcode found after trying rotations');
423
+ }
424
+ }
425
+ // Try fine rotation angles around each base orientation.
426
+ // Two-step: pixel-clean cardinal rotation (rotateCanvas) preserves barcode
427
+ // detail, then small fine rotation (rotateCanvasArbitrary) applies minimal
428
+ // interpolation. This is much better than a single large-angle rotation.
429
+ if (tryFineRotations) {
430
+ const fineCanvas = document.createElement('canvas');
431
+ const bases = [
432
+ { angle: 0, image: preparedImage },
433
+ ];
434
+ if (tryRotations) {
435
+ const { width, height } = getImageDimensions(preparedImage);
436
+ if (height > width) {
437
+ bases.push({ angle: 90, image: rotateCanvas(preparedImage, 90) }, { angle: 270, image: rotateCanvas(preparedImage, 270) });
438
+ }
439
+ }
440
+ try {
441
+ for (const base of bases) {
442
+ log(`[NativeBarcodeDecoder] Trying fine rotation deskew around ${base.angle}°...`);
443
+ for (const offset of FINE_ROTATION_ANGLES) {
444
+ const totalAngle = base.angle + offset;
445
+ const rotated = rotateCanvasArbitrary(base.image, offset, fineCanvas);
446
+ const fineResult = await attemptDecode(rotated, rotated, tryNative, fallbackToZXing);
447
+ if (fineResult) {
448
+ log(`[NativeBarcodeDecoder] Decoded successfully after ${totalAngle}° rotation (${base.angle}° base + ${offset}° fine)`);
449
+ return { ...fineResult, rotationApplied: totalAngle };
450
+ }
451
+ }
452
+ }
453
+ log('[NativeBarcodeDecoder] No barcode found after fine rotations');
454
+ }
455
+ finally {
456
+ fineCanvas.width = 0;
457
+ fineCanvas.height = 0;
458
+ }
459
+ }
460
+ return null;
461
+ }
462
+ /**
463
+ * Decode with native API and return detailed result
464
+ */
465
+ async function decodeWithNativeDetailed(image) {
466
+ if (!isNativeBarcodeDetectorAvailable()) {
467
+ log('[NativeBarcodeDecoder] Native BarcodeDetector not available');
468
+ return { result: 'not_found', text: null };
469
+ }
470
+ try {
471
+ const detector = new window.BarcodeDetector({ formats: ['pdf417'] });
472
+ const results = await detector.detect(image);
473
+ log(`[NativeBarcodeDecoder] Native detector returned ${results.length} results`);
474
+ if (results.length > 0) {
475
+ const result = results[0];
476
+ if (!result.rawValue || result.rawValue.trim() === '') {
477
+ log('[NativeBarcodeDecoder] Native detected barcode but rawValue is empty');
478
+ return { result: 'empty', text: '' };
479
+ }
480
+ log(`[NativeBarcodeDecoder] Native decode SUCCESS: ${result.rawValue.substring(0, 50)}...`);
481
+ return { result: 'success', text: result.rawValue };
482
+ }
483
+ log('[NativeBarcodeDecoder] Native found no barcodes');
484
+ return { result: 'not_found', text: null };
485
+ }
486
+ catch (error) {
487
+ log('[NativeBarcodeDecoder] Native decode error:', error);
488
+ return {
489
+ result: 'error',
490
+ text: null,
491
+ error: error instanceof Error ? error.message : String(error),
492
+ };
493
+ }
494
+ }
495
+ /**
496
+ * Decode with ZXing and return detailed result
497
+ */
498
+ async function decodeWithZXingDetailed(image) {
499
+ try {
500
+ zxingAttemptCount++;
501
+ log(`[NativeBarcodeDecoder] decodeWithZXingDetailed called, attempt count now: ${zxingAttemptCount}`);
502
+ const reader = await getZXingReader();
503
+ let imageElement;
504
+ if (image instanceof HTMLImageElement) {
505
+ imageElement = image;
506
+ }
507
+ else if (image instanceof HTMLCanvasElement) {
508
+ imageElement = await canvasToImage(image);
509
+ }
510
+ else {
511
+ throw new Error('Unsupported image type for ZXing decoder');
512
+ }
513
+ const result = await reader.decodeFromImage(imageElement);
514
+ const text = result.text || result.getText();
515
+ const format = result.getBarcodeFormat().toString();
516
+ if (!text || text.trim() === '') {
517
+ return { result: 'empty', text: '', format };
518
+ }
519
+ return { result: 'success', text, format };
520
+ }
521
+ catch (error) {
522
+ // NotFoundException is expected when no barcode is found
523
+ if (error instanceof Error &&
524
+ (error.name === 'NotFoundException' ||
525
+ error.message?.includes('No barcode') ||
526
+ error.message?.includes('not found'))) {
527
+ return { result: 'not_found', text: null };
528
+ }
529
+ return {
530
+ result: 'error',
531
+ text: null,
532
+ error: error instanceof Error ? error.message : String(error),
533
+ };
534
+ }
535
+ }
536
+ /**
537
+ * Attempt decode at a specific rotation and track results
538
+ */
539
+ async function attemptDecodeWithTracking(preparedImage, tryNative, fallbackToZXing, nativeSupported) {
540
+ const rotationDetails = {
541
+ nativeResult: null,
542
+ nativeText: null,
543
+ zxingResult: null,
544
+ zxingText: null,
545
+ };
546
+ let nativeAttempted = false;
547
+ let nativeResult = null;
548
+ let nativeError;
549
+ let zxingAttempted = false;
550
+ let zxingResult = null;
551
+ let zxingError;
552
+ // Try native API first if enabled and supported
553
+ if (tryNative && nativeSupported) {
554
+ log('[NativeBarcodeDecoder] Attempting native decode...');
555
+ nativeAttempted = true;
556
+ const nativeDecodeResult = await decodeWithNativeDetailed(preparedImage);
557
+ nativeResult = nativeDecodeResult.result;
558
+ nativeError = nativeDecodeResult.error;
559
+ rotationDetails.nativeResult = nativeDecodeResult.result;
560
+ rotationDetails.nativeText = nativeDecodeResult.text;
561
+ log(`[NativeBarcodeDecoder] Native result: ${nativeDecodeResult.result}`);
562
+ if (nativeDecodeResult.result === 'success' && nativeDecodeResult.text) {
563
+ log('[NativeBarcodeDecoder] Native succeeded, skipping ZXing');
564
+ return {
565
+ result: {
566
+ text: nativeDecodeResult.text,
567
+ format: 'pdf417',
568
+ method: 'native',
569
+ rotationApplied: null,
570
+ },
571
+ rotationDetails,
572
+ nativeAttempted,
573
+ nativeResult,
574
+ nativeError,
575
+ zxingAttempted,
576
+ zxingResult,
577
+ zxingError,
578
+ };
579
+ }
580
+ log('[NativeBarcodeDecoder] Native did not succeed, will try ZXing fallback');
581
+ }
582
+ else {
583
+ log(`[NativeBarcodeDecoder] Skipping native: tryNative=${tryNative}, nativeSupported=${nativeSupported}`);
584
+ }
585
+ // Fall back to ZXing
586
+ if (fallbackToZXing) {
587
+ log('[NativeBarcodeDecoder] Attempting ZXing fallback...');
588
+ zxingAttempted = true;
589
+ const zxingDecodeResult = await decodeWithZXingDetailed(preparedImage);
590
+ zxingResult = zxingDecodeResult.result;
591
+ zxingError = zxingDecodeResult.error;
592
+ rotationDetails.zxingResult = zxingDecodeResult.result;
593
+ rotationDetails.zxingText = zxingDecodeResult.text;
594
+ if (zxingDecodeResult.result === 'success' && zxingDecodeResult.text) {
595
+ return {
596
+ result: {
597
+ text: zxingDecodeResult.text,
598
+ format: zxingDecodeResult.format || 'PDF_417',
599
+ method: 'zxing',
600
+ rotationApplied: null,
601
+ },
602
+ rotationDetails,
603
+ nativeAttempted,
604
+ nativeResult,
605
+ nativeError,
606
+ zxingAttempted,
607
+ zxingResult,
608
+ zxingError,
609
+ };
610
+ }
611
+ }
612
+ return {
613
+ result: null,
614
+ rotationDetails,
615
+ nativeAttempted,
616
+ nativeResult,
617
+ nativeError,
618
+ zxingAttempted,
619
+ zxingResult,
620
+ zxingError,
621
+ };
622
+ }
623
+ /**
624
+ * Decode a PDF417 barcode with detailed tracking of all attempts.
625
+ *
626
+ * Same as decodePDF417 but returns detailed information about each decode attempt
627
+ * for diagnostics purposes.
628
+ */
629
+ export async function decodePDF417WithDetails(source, options = {}) {
630
+ const startedAt = new Date();
631
+ const { tryNative = false, // Native BarcodeDetector often detects but fails to decode - ZXing is more reliable
632
+ fallbackToZXing = true, preloadZXing = false, tryRotations = true, tryFineRotations = false, } = options;
633
+ // Initialize details tracking
634
+ const details = {
635
+ nativeApi: {
636
+ available: isNativeBarcodeDetectorAvailable(),
637
+ supportsPDF417: false,
638
+ attempted: false,
639
+ result: null,
640
+ },
641
+ zxing: {
642
+ attempted: false,
643
+ result: null,
644
+ },
645
+ rotationsAttempted: {
646
+ original: { nativeResult: null, nativeText: null, zxingResult: null, zxingText: null },
647
+ },
648
+ rotationApplied: null,
649
+ startedAt: startedAt.toISOString(),
650
+ completedAt: '',
651
+ durationMs: 0,
652
+ };
653
+ // Check native PDF417 support
654
+ const nativeSupported = await checkNativePDF417Support();
655
+ details.nativeApi.supportsPDF417 = nativeSupported;
656
+ // Optionally preload zxing in background
657
+ if (preloadZXing && fallbackToZXing) {
658
+ loadZXing().catch(() => {
659
+ /* ignore preload errors */
660
+ });
661
+ }
662
+ // Prepare the image once for reuse
663
+ const preparedImage = await prepareImageForDecoding(source);
664
+ // Try decoding the original image first
665
+ const originalAttempt = await attemptDecodeWithTracking(preparedImage, tryNative, fallbackToZXing, nativeSupported);
666
+ // Update tracking
667
+ details.rotationsAttempted.original = originalAttempt.rotationDetails;
668
+ if (originalAttempt.nativeAttempted) {
669
+ details.nativeApi.attempted = true;
670
+ details.nativeApi.result = originalAttempt.nativeResult;
671
+ if (originalAttempt.nativeError) {
672
+ details.nativeApi.errorMessage = originalAttempt.nativeError;
673
+ }
674
+ }
675
+ if (originalAttempt.zxingAttempted) {
676
+ details.zxing.attempted = true;
677
+ details.zxing.result = originalAttempt.zxingResult;
678
+ if (originalAttempt.zxingError) {
679
+ details.zxing.errorMessage = originalAttempt.zxingError;
680
+ }
681
+ }
682
+ if (originalAttempt.result) {
683
+ details.rotationApplied = 0;
684
+ const completedAt = new Date();
685
+ details.completedAt = completedAt.toISOString();
686
+ details.durationMs = completedAt.getTime() - startedAt.getTime();
687
+ return {
688
+ result: { ...originalAttempt.result, rotationApplied: 0 },
689
+ details,
690
+ };
691
+ }
692
+ // If image is portrait-oriented (taller than wide), try rotations
693
+ if (tryRotations) {
694
+ const { width, height } = getImageDimensions(preparedImage);
695
+ if (height > width) {
696
+ log(`[NativeBarcodeDecoder] Image is portrait (${width}x${height}), trying rotations...`);
697
+ // Try 90° rotation
698
+ const rotated90 = rotateCanvas(preparedImage, 90);
699
+ const attempt90 = await attemptDecodeWithTracking(rotated90, tryNative, fallbackToZXing, nativeSupported);
700
+ details.rotationsAttempted.rotated90 = attempt90.rotationDetails;
701
+ // Update overall tracking with best results
702
+ if (attempt90.nativeAttempted && !details.nativeApi.attempted) {
703
+ details.nativeApi.attempted = true;
704
+ }
705
+ if (attempt90.nativeResult === 'success') {
706
+ details.nativeApi.result = 'success';
707
+ }
708
+ if (attempt90.zxingAttempted && !details.zxing.attempted) {
709
+ details.zxing.attempted = true;
710
+ }
711
+ if (attempt90.zxingResult === 'success') {
712
+ details.zxing.result = 'success';
713
+ }
714
+ if (attempt90.result) {
715
+ log('[NativeBarcodeDecoder] Decoded successfully after 90° rotation');
716
+ details.rotationApplied = 90;
717
+ const completedAt = new Date();
718
+ details.completedAt = completedAt.toISOString();
719
+ details.durationMs = completedAt.getTime() - startedAt.getTime();
720
+ return {
721
+ result: { ...attempt90.result, rotationApplied: 90 },
722
+ details,
723
+ };
724
+ }
725
+ // Try 270° rotation
726
+ const rotated270 = rotateCanvas(preparedImage, 270);
727
+ const attempt270 = await attemptDecodeWithTracking(rotated270, tryNative, fallbackToZXing, nativeSupported);
728
+ details.rotationsAttempted.rotated270 = attempt270.rotationDetails;
729
+ // Update overall tracking
730
+ if (attempt270.nativeResult === 'success') {
731
+ details.nativeApi.result = 'success';
732
+ }
733
+ if (attempt270.zxingResult === 'success') {
734
+ details.zxing.result = 'success';
735
+ }
736
+ if (attempt270.result) {
737
+ log('[NativeBarcodeDecoder] Decoded successfully after 270° rotation');
738
+ details.rotationApplied = 270;
739
+ const completedAt = new Date();
740
+ details.completedAt = completedAt.toISOString();
741
+ details.durationMs = completedAt.getTime() - startedAt.getTime();
742
+ return {
743
+ result: { ...attempt270.result, rotationApplied: 270 },
744
+ details,
745
+ };
746
+ }
747
+ log('[NativeBarcodeDecoder] No barcode found after trying rotations');
748
+ }
749
+ }
750
+ // Try fine rotation angles around each base orientation.
751
+ // Two-step: pixel-clean cardinal rotation (rotateCanvas) preserves barcode
752
+ // detail, then small fine rotation (rotateCanvasArbitrary) applies minimal
753
+ // interpolation. This is much better than a single large-angle rotation.
754
+ if (tryFineRotations) {
755
+ const fineRotations = {};
756
+ const fineCanvas = document.createElement('canvas');
757
+ const bases = [
758
+ { angle: 0, image: preparedImage },
759
+ ];
760
+ if (tryRotations) {
761
+ const { width, height } = getImageDimensions(preparedImage);
762
+ if (height > width) {
763
+ bases.push({ angle: 90, image: rotateCanvas(preparedImage, 90) }, { angle: 270, image: rotateCanvas(preparedImage, 270) });
764
+ }
765
+ }
766
+ try {
767
+ for (const base of bases) {
768
+ log(`[NativeBarcodeDecoder] Trying fine rotation deskew around ${base.angle}° (detailed)...`);
769
+ for (const offset of FINE_ROTATION_ANGLES) {
770
+ const totalAngle = base.angle + offset;
771
+ const rotated = rotateCanvasArbitrary(base.image, offset, fineCanvas);
772
+ const fineAttempt = await attemptDecodeWithTracking(rotated, tryNative, fallbackToZXing, nativeSupported);
773
+ const key = `rotated_${totalAngle}`;
774
+ fineRotations[key] = fineAttempt.rotationDetails;
775
+ if (fineAttempt.result) {
776
+ log(`[NativeBarcodeDecoder] Decoded successfully after ${totalAngle}° rotation (${base.angle}° base + ${offset}° fine)`);
777
+ details.fineRotationsAttempted = fineRotations;
778
+ details.rotationApplied = totalAngle;
779
+ const completedAt = new Date();
780
+ details.completedAt = completedAt.toISOString();
781
+ details.durationMs = completedAt.getTime() - startedAt.getTime();
782
+ return {
783
+ result: { ...fineAttempt.result, rotationApplied: totalAngle },
784
+ details,
785
+ };
786
+ }
787
+ }
788
+ }
789
+ log('[NativeBarcodeDecoder] No barcode found after fine rotations');
790
+ }
791
+ finally {
792
+ fineCanvas.width = 0;
793
+ fineCanvas.height = 0;
794
+ }
795
+ details.fineRotationsAttempted = fineRotations;
796
+ }
797
+ // No barcode found
798
+ const completedAt = new Date();
799
+ details.completedAt = completedAt.toISOString();
800
+ details.durationMs = completedAt.getTime() - startedAt.getTime();
801
+ return { result: null, details };
802
+ }
803
+ /**
804
+ * Get the current decoder status
805
+ */
806
+ export async function getDecoderStatus() {
807
+ const nativePDF417Supported = await checkNativePDF417Support();
808
+ return {
809
+ nativeSupported: isNativeBarcodeDetectorAvailable(),
810
+ nativePDF417Supported,
811
+ zxingLoaded: !!window.ZXing,
812
+ zxingLoading: !!zxingLoadPromise && !window.ZXing,
813
+ zxingError: null,
814
+ };
815
+ }
816
+ /**
817
+ * Preload zxing-js in the background
818
+ */
819
+ export function preloadZXing() {
820
+ loadZXing().catch((error) => {
821
+ warn('[NativeBarcodeDecoder] Failed to preload ZXing:', error);
822
+ });
823
+ }
824
+ /**
825
+ * Reset the decoder state (for testing)
826
+ */
827
+ export function resetDecoderState() {
828
+ zxingLoadPromise = null;
829
+ zxingInstance = null;
830
+ nativeSupportChecked = false;
831
+ nativeSupportsFormat = false;
832
+ }