@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.
- package/README.md +66 -0
- package/dist/attestation/attestationState.d.ts +24 -0
- package/dist/attestation/attestationState.d.ts.map +1 -0
- package/dist/attestation/attestationState.js +57 -0
- package/dist/attestation/clientAttestation.d.ts +40 -0
- package/dist/attestation/clientAttestation.d.ts.map +1 -0
- package/dist/attestation/clientAttestation.js +19 -0
- package/dist/attestation/collectClientAttestation.d.ts +10 -0
- package/dist/attestation/collectClientAttestation.d.ts.map +1 -0
- package/dist/attestation/collectClientAttestation.js +18 -0
- package/dist/attestation/index.d.ts +5 -0
- package/dist/attestation/index.d.ts.map +1 -0
- package/dist/attestation/index.js +4 -0
- package/dist/attestation/nativeAttestationBridge.d.ts +3 -0
- package/dist/attestation/nativeAttestationBridge.d.ts.map +1 -0
- package/dist/attestation/nativeAttestationBridge.js +38 -0
- package/dist/barcode/AAMVAParser.d.ts +77 -0
- package/dist/barcode/AAMVAParser.d.ts.map +1 -0
- package/dist/barcode/AAMVAParser.js +422 -0
- package/dist/barcode/NativeBarcodeDecoder.d.ts +157 -0
- package/dist/barcode/NativeBarcodeDecoder.d.ts.map +1 -0
- package/dist/barcode/NativeBarcodeDecoder.js +832 -0
- package/dist/barcode/Parse.d.ts +6 -0
- package/dist/barcode/Parse.d.ts.map +1 -0
- package/dist/barcode/Parse.js +148 -0
- package/dist/barcode/decodeSummary.d.ts +45 -0
- package/dist/barcode/decodeSummary.d.ts.map +1 -0
- package/dist/barcode/decodeSummary.js +23 -0
- package/dist/barcode/index.d.ts +5 -0
- package/dist/barcode/index.d.ts.map +1 -0
- package/dist/barcode/index.js +4 -0
- package/dist/camera/Camera.d.ts +37 -0
- package/dist/camera/Camera.d.ts.map +1 -0
- package/dist/camera/Camera.js +453 -0
- package/dist/camera/acquireCamera.d.ts +29 -0
- package/dist/camera/acquireCamera.d.ts.map +1 -0
- package/dist/camera/acquireCamera.js +224 -0
- package/dist/camera/cameraSignals.d.ts +23 -0
- package/dist/camera/cameraSignals.d.ts.map +1 -0
- package/dist/camera/cameraSignals.js +32 -0
- package/dist/camera/getUserMediaIntegrity.d.ts +72 -0
- package/dist/camera/getUserMediaIntegrity.d.ts.map +1 -0
- package/dist/camera/getUserMediaIntegrity.js +256 -0
- package/dist/camera/index.d.ts +6 -0
- package/dist/camera/index.d.ts.map +1 -0
- package/dist/camera/index.js +5 -0
- package/dist/camera/isVirtualCamera.d.ts +10 -0
- package/dist/camera/isVirtualCamera.d.ts.map +1 -0
- package/dist/camera/isVirtualCamera.js +11 -0
- package/dist/client/IdmissionClient.d.ts +151 -0
- package/dist/client/IdmissionClient.d.ts.map +1 -0
- package/dist/client/IdmissionClient.js +638 -0
- package/dist/client/additionalDocument.d.ts +14 -0
- package/dist/client/additionalDocument.d.ts.map +1 -0
- package/dist/client/additionalDocument.js +24 -0
- package/dist/client/artifacts.d.ts +146 -0
- package/dist/client/artifacts.d.ts.map +1 -0
- package/dist/client/artifacts.js +1 -0
- package/dist/client/blobToB64.d.ts +2 -0
- package/dist/client/blobToB64.d.ts.map +1 -0
- package/dist/client/blobToB64.js +17 -0
- package/dist/client/endpoints.d.ts +7 -0
- package/dist/client/endpoints.d.ts.map +1 -0
- package/dist/client/endpoints.js +59 -0
- package/dist/client/errors.d.ts +20 -0
- package/dist/client/errors.d.ts.map +1 -0
- package/dist/client/errors.js +45 -0
- package/dist/client/index.d.ts +23 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +38 -0
- package/dist/client/payload.d.ts +36 -0
- package/dist/client/payload.d.ts.map +1 -0
- package/dist/client/payload.js +397 -0
- package/dist/client/sessionMachine.d.ts +26 -0
- package/dist/client/sessionMachine.d.ts.map +1 -0
- package/dist/client/sessionMachine.js +23 -0
- package/dist/client/submissionMetadata.d.ts +31 -0
- package/dist/client/submissionMetadata.d.ts.map +1 -0
- package/dist/client/submissionMetadata.js +90 -0
- package/dist/client/timings.d.ts +49 -0
- package/dist/client/timings.d.ts.map +1 -0
- package/dist/client/timings.js +32 -0
- package/dist/client/types.d.ts +305 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +18 -0
- package/dist/client/upload.d.ts +60 -0
- package/dist/client/upload.d.ts.map +1 -0
- package/dist/client/upload.js +313 -0
- package/dist/client/uploadedDocument.d.ts +7 -0
- package/dist/client/uploadedDocument.d.ts.map +1 -0
- package/dist/client/uploadedDocument.js +4 -0
- package/dist/client/urls.d.ts +30 -0
- package/dist/client/urls.d.ts.map +1 -0
- package/dist/client/urls.js +73 -0
- package/dist/client/validateSession.d.ts +7 -0
- package/dist/client/validateSession.d.ts.map +1 -0
- package/dist/client/validateSession.js +63 -0
- package/dist/config/cdn.d.ts +2 -0
- package/dist/config/cdn.d.ts.map +1 -0
- package/dist/config/cdn.js +1 -0
- package/dist/diagnostics/buffer.d.ts +8 -0
- package/dist/diagnostics/buffer.d.ts.map +1 -0
- package/dist/diagnostics/buffer.js +25 -0
- package/dist/diagnostics/envCapability.d.ts +3 -0
- package/dist/diagnostics/envCapability.d.ts.map +1 -0
- package/dist/diagnostics/envCapability.js +40 -0
- package/dist/diagnostics/floodControl.d.ts +6 -0
- package/dist/diagnostics/floodControl.d.ts.map +1 -0
- package/dist/diagnostics/floodControl.js +29 -0
- package/dist/diagnostics/index.d.ts +8 -0
- package/dist/diagnostics/index.d.ts.map +1 -0
- package/dist/diagnostics/index.js +17 -0
- package/dist/diagnostics/install.d.ts +20 -0
- package/dist/diagnostics/install.d.ts.map +1 -0
- package/dist/diagnostics/install.js +159 -0
- package/dist/diagnostics/redaction.d.ts +7 -0
- package/dist/diagnostics/redaction.d.ts.map +1 -0
- package/dist/diagnostics/redaction.js +73 -0
- package/dist/diagnostics/transport.d.ts +15 -0
- package/dist/diagnostics/transport.d.ts.map +1 -0
- package/dist/diagnostics/transport.js +35 -0
- package/dist/diagnostics/types.d.ts +59 -0
- package/dist/diagnostics/types.d.ts.map +1 -0
- package/dist/diagnostics/types.js +1 -0
- package/dist/documentCapture/controller.d.ts +35 -0
- package/dist/documentCapture/controller.d.ts.map +1 -0
- package/dist/documentCapture/controller.js +254 -0
- package/dist/documentCapture/index.d.ts +4 -0
- package/dist/documentCapture/index.d.ts.map +1 -0
- package/dist/documentCapture/index.js +8 -0
- package/dist/documentCapture/reducer.d.ts +31 -0
- package/dist/documentCapture/reducer.d.ts.map +1 -0
- package/dist/documentCapture/reducer.js +87 -0
- package/dist/documentCapture/state.d.ts +49 -0
- package/dist/documentCapture/state.d.ts.map +1 -0
- package/dist/documentCapture/state.js +36 -0
- package/dist/idCapture/controller.d.ts +228 -0
- package/dist/idCapture/controller.d.ts.map +1 -0
- package/dist/idCapture/controller.js +1453 -0
- package/dist/idCapture/errors.d.ts +36 -0
- package/dist/idCapture/errors.d.ts.map +1 -0
- package/dist/idCapture/errors.js +18 -0
- package/dist/idCapture/guidance.d.ts +80 -0
- package/dist/idCapture/guidance.d.ts.map +1 -0
- package/dist/idCapture/guidance.js +143 -0
- package/dist/idCapture/index.d.ts +22 -0
- package/dist/idCapture/index.d.ts.map +1 -0
- package/dist/idCapture/index.js +46 -0
- package/dist/idCapture/phase.d.ts +10 -0
- package/dist/idCapture/phase.d.ts.map +1 -0
- package/dist/idCapture/phase.js +28 -0
- package/dist/idCapture/pipeline.d.ts +176 -0
- package/dist/idCapture/pipeline.d.ts.map +1 -0
- package/dist/idCapture/pipeline.js +1028 -0
- package/dist/idCapture/reducer.d.ts +3 -0
- package/dist/idCapture/reducer.d.ts.map +1 -0
- package/dist/idCapture/reducer.js +661 -0
- package/dist/idCapture/requirements.d.ts +10 -0
- package/dist/idCapture/requirements.d.ts.map +1 -0
- package/dist/idCapture/requirements.js +43 -0
- package/dist/idCapture/stabilizer.d.ts +2 -0
- package/dist/idCapture/stabilizer.d.ts.map +1 -0
- package/dist/idCapture/stabilizer.js +4 -0
- package/dist/idCapture/state.d.ts +426 -0
- package/dist/idCapture/state.d.ts.map +1 -0
- package/dist/idCapture/state.js +91 -0
- package/dist/idCapture/submit.d.ts +33 -0
- package/dist/idCapture/submit.d.ts.map +1 -0
- package/dist/idCapture/submit.js +105 -0
- package/dist/idCapture/types.d.ts +20 -0
- package/dist/idCapture/types.d.ts.map +1 -0
- package/dist/idCapture/types.js +12 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/liveness/challengeGeometry.d.ts +66 -0
- package/dist/liveness/challengeGeometry.d.ts.map +1 -0
- package/dist/liveness/challengeGeometry.js +226 -0
- package/dist/liveness/challengeSequence.d.ts +49 -0
- package/dist/liveness/challengeSequence.d.ts.map +1 -0
- package/dist/liveness/challengeSequence.js +71 -0
- package/dist/liveness/index.d.ts +4 -0
- package/dist/liveness/index.d.ts.map +1 -0
- package/dist/liveness/index.js +3 -0
- package/dist/liveness/livenessResult.d.ts +11 -0
- package/dist/liveness/livenessResult.d.ts.map +1 -0
- package/dist/liveness/livenessResult.js +16 -0
- package/dist/models/BarcodeReadability.d.ts +36 -0
- package/dist/models/BarcodeReadability.d.ts.map +1 -0
- package/dist/models/BarcodeReadability.js +71 -0
- package/dist/models/CapabilityProbing.d.ts +25 -0
- package/dist/models/CapabilityProbing.d.ts.map +1 -0
- package/dist/models/CapabilityProbing.js +172 -0
- package/dist/models/DocumentDetection.d.ts +96 -0
- package/dist/models/DocumentDetection.d.ts.map +1 -0
- package/dist/models/DocumentDetection.js +257 -0
- package/dist/models/FaceDetection.d.ts +21 -0
- package/dist/models/FaceDetection.d.ts.map +1 -0
- package/dist/models/FaceDetection.js +4 -0
- package/dist/models/Focus.d.ts +36 -0
- package/dist/models/Focus.d.ts.map +1 -0
- package/dist/models/Focus.js +69 -0
- package/dist/models/FrameLoop.d.ts +13 -0
- package/dist/models/FrameLoop.d.ts.map +1 -0
- package/dist/models/FrameLoop.js +56 -0
- package/dist/models/VisionRuntime.d.ts +18 -0
- package/dist/models/VisionRuntime.d.ts.map +1 -0
- package/dist/models/VisionRuntime.js +158 -0
- package/dist/models/defaults/BarcodeReadability.d.ts +3 -0
- package/dist/models/defaults/BarcodeReadability.d.ts.map +1 -0
- package/dist/models/defaults/BarcodeReadability.js +3 -0
- package/dist/models/defaults/BarcodeReadabilityLiteRT.d.ts +3 -0
- package/dist/models/defaults/BarcodeReadabilityLiteRT.d.ts.map +1 -0
- package/dist/models/defaults/BarcodeReadabilityLiteRT.js +3 -0
- package/dist/models/defaults/DocumentDetector.d.ts +3 -0
- package/dist/models/defaults/DocumentDetector.d.ts.map +1 -0
- package/dist/models/defaults/DocumentDetector.js +3 -0
- package/dist/models/defaults/DocumentDetectorLiteRT.d.ts +3 -0
- package/dist/models/defaults/DocumentDetectorLiteRT.d.ts.map +1 -0
- package/dist/models/defaults/DocumentDetectorLiteRT.js +3 -0
- package/dist/models/defaults/FaceDetector.d.ts +3 -0
- package/dist/models/defaults/FaceDetector.d.ts.map +1 -0
- package/dist/models/defaults/FaceDetector.js +3 -0
- package/dist/models/defaults/FaceLandmarker.d.ts +3 -0
- package/dist/models/defaults/FaceLandmarker.d.ts.map +1 -0
- package/dist/models/defaults/FaceLandmarker.js +8 -0
- package/dist/models/defaults/FaceLandmarkerLiteRT.d.ts +3 -0
- package/dist/models/defaults/FaceLandmarkerLiteRT.d.ts.map +1 -0
- package/dist/models/defaults/FaceLandmarkerLiteRT.js +3 -0
- package/dist/models/defaults/Focus.d.ts +3 -0
- package/dist/models/defaults/Focus.d.ts.map +1 -0
- package/dist/models/defaults/Focus.js +3 -0
- package/dist/models/defaults/FocusLiteRT.d.ts +3 -0
- package/dist/models/defaults/FocusLiteRT.d.ts.map +1 -0
- package/dist/models/defaults/FocusLiteRT.js +3 -0
- package/dist/models/defaults/index.d.ts +31 -0
- package/dist/models/defaults/index.d.ts.map +1 -0
- package/dist/models/defaults/index.js +38 -0
- package/dist/models/helpers.d.ts +25 -0
- package/dist/models/helpers.d.ts.map +1 -0
- package/dist/models/helpers.js +98 -0
- package/dist/models/index.d.ts +15 -0
- package/dist/models/index.d.ts.map +1 -0
- package/dist/models/index.js +14 -0
- package/dist/models/modelLifecycle.d.ts +26 -0
- package/dist/models/modelLifecycle.d.ts.map +1 -0
- package/dist/models/modelLifecycle.js +137 -0
- package/dist/models/occlusion.d.ts +20 -0
- package/dist/models/occlusion.d.ts.map +1 -0
- package/dist/models/occlusion.js +109 -0
- package/dist/models/passportBooklet.d.ts +34 -0
- package/dist/models/passportBooklet.d.ts.map +1 -0
- package/dist/models/passportBooklet.js +152 -0
- package/dist/models/preloadModels.d.ts +42 -0
- package/dist/models/preloadModels.d.ts.map +1 -0
- package/dist/models/preloadModels.js +204 -0
- package/dist/models/providers/litert/BarcodeReadability.d.ts +11 -0
- package/dist/models/providers/litert/BarcodeReadability.d.ts.map +1 -0
- package/dist/models/providers/litert/BarcodeReadability.js +135 -0
- package/dist/models/providers/litert/CapabilityProbe.d.ts +3 -0
- package/dist/models/providers/litert/CapabilityProbe.d.ts.map +1 -0
- package/dist/models/providers/litert/CapabilityProbe.js +44 -0
- package/dist/models/providers/litert/DocumentDetection.d.ts +18 -0
- package/dist/models/providers/litert/DocumentDetection.d.ts.map +1 -0
- package/dist/models/providers/litert/DocumentDetection.js +194 -0
- package/dist/models/providers/litert/FaceDetection.d.ts +11 -0
- package/dist/models/providers/litert/FaceDetection.d.ts.map +1 -0
- package/dist/models/providers/litert/FaceDetection.js +204 -0
- package/dist/models/providers/litert/FaceLandmarker.d.ts +11 -0
- package/dist/models/providers/litert/FaceLandmarker.d.ts.map +1 -0
- package/dist/models/providers/litert/FaceLandmarker.js +199 -0
- package/dist/models/providers/litert/Focus.d.ts +11 -0
- package/dist/models/providers/litert/Focus.d.ts.map +1 -0
- package/dist/models/providers/litert/Focus.js +141 -0
- package/dist/models/providers/litert/barcodeReadabilityPrePost.d.ts +6 -0
- package/dist/models/providers/litert/barcodeReadabilityPrePost.d.ts.map +1 -0
- package/dist/models/providers/litert/barcodeReadabilityPrePost.js +68 -0
- package/dist/models/providers/litert/blazeFacePrePost.d.ts +30 -0
- package/dist/models/providers/litert/blazeFacePrePost.d.ts.map +1 -0
- package/dist/models/providers/litert/blazeFacePrePost.js +206 -0
- package/dist/models/providers/litert/docDetectPrePost.d.ts +25 -0
- package/dist/models/providers/litert/docDetectPrePost.d.ts.map +1 -0
- package/dist/models/providers/litert/docDetectPrePost.js +197 -0
- package/dist/models/providers/litert/faceMeshPrePost.d.ts +23 -0
- package/dist/models/providers/litert/faceMeshPrePost.d.ts.map +1 -0
- package/dist/models/providers/litert/faceMeshPrePost.js +86 -0
- package/dist/models/providers/litert/focusPrePost.d.ts +6 -0
- package/dist/models/providers/litert/focusPrePost.d.ts.map +1 -0
- package/dist/models/providers/litert/focusPrePost.js +67 -0
- package/dist/models/providers/litert/runtime.d.ts +14 -0
- package/dist/models/providers/litert/runtime.d.ts.map +1 -0
- package/dist/models/providers/litert/runtime.js +83 -0
- package/dist/models/providers/mediapipe/BarcodeReadability.d.ts +11 -0
- package/dist/models/providers/mediapipe/BarcodeReadability.d.ts.map +1 -0
- package/dist/models/providers/mediapipe/BarcodeReadability.js +68 -0
- package/dist/models/providers/mediapipe/CapabilityProbe.d.ts +2 -0
- package/dist/models/providers/mediapipe/CapabilityProbe.d.ts.map +1 -0
- package/dist/models/providers/mediapipe/CapabilityProbe.js +14 -0
- package/dist/models/providers/mediapipe/DocumentDetection.d.ts +12 -0
- package/dist/models/providers/mediapipe/DocumentDetection.d.ts.map +1 -0
- package/dist/models/providers/mediapipe/DocumentDetection.js +90 -0
- package/dist/models/providers/mediapipe/FaceDetection.d.ts +11 -0
- package/dist/models/providers/mediapipe/FaceDetection.d.ts.map +1 -0
- package/dist/models/providers/mediapipe/FaceDetection.js +93 -0
- package/dist/models/providers/mediapipe/FaceLandmarker.d.ts +46 -0
- package/dist/models/providers/mediapipe/FaceLandmarker.d.ts.map +1 -0
- package/dist/models/providers/mediapipe/FaceLandmarker.js +166 -0
- package/dist/models/providers/mediapipe/Focus.d.ts +11 -0
- package/dist/models/providers/mediapipe/Focus.d.ts.map +1 -0
- package/dist/models/providers/mediapipe/Focus.js +51 -0
- package/dist/models/runtimeSelection.d.ts +5 -0
- package/dist/models/runtimeSelection.d.ts.map +1 -0
- package/dist/models/runtimeSelection.js +21 -0
- package/dist/selfieCapture/challengeRunner.d.ts +38 -0
- package/dist/selfieCapture/challengeRunner.d.ts.map +1 -0
- package/dist/selfieCapture/challengeRunner.js +181 -0
- package/dist/selfieCapture/controller.d.ts +166 -0
- package/dist/selfieCapture/controller.d.ts.map +1 -0
- package/dist/selfieCapture/controller.js +1253 -0
- package/dist/selfieCapture/faceTracking.d.ts +67 -0
- package/dist/selfieCapture/faceTracking.d.ts.map +1 -0
- package/dist/selfieCapture/faceTracking.js +158 -0
- package/dist/selfieCapture/guidance.d.ts +24 -0
- package/dist/selfieCapture/guidance.d.ts.map +1 -0
- package/dist/selfieCapture/guidance.js +41 -0
- package/dist/selfieCapture/index.d.ts +18 -0
- package/dist/selfieCapture/index.d.ts.map +1 -0
- package/dist/selfieCapture/index.js +11 -0
- package/dist/selfieCapture/lighting.d.ts +36 -0
- package/dist/selfieCapture/lighting.d.ts.map +1 -0
- package/dist/selfieCapture/lighting.js +95 -0
- package/dist/selfieCapture/livenessMachine.d.ts +66 -0
- package/dist/selfieCapture/livenessMachine.d.ts.map +1 -0
- package/dist/selfieCapture/livenessMachine.js +137 -0
- package/dist/selfieCapture/pipeline.d.ts +42 -0
- package/dist/selfieCapture/pipeline.d.ts.map +1 -0
- package/dist/selfieCapture/pipeline.js +282 -0
- package/dist/selfieCapture/reducer.d.ts +35 -0
- package/dist/selfieCapture/reducer.d.ts.map +1 -0
- package/dist/selfieCapture/reducer.js +143 -0
- package/dist/selfieCapture/state.d.ts +40 -0
- package/dist/selfieCapture/state.d.ts.map +1 -0
- package/dist/selfieCapture/state.js +36 -0
- package/dist/selfieCapture/testing/challengeFixtures.d.ts +43 -0
- package/dist/selfieCapture/testing/challengeFixtures.d.ts.map +1 -0
- package/dist/selfieCapture/testing/challengeFixtures.js +43 -0
- package/dist/signature/frameDecode.d.ts +48 -0
- package/dist/signature/frameDecode.d.ts.map +1 -0
- package/dist/signature/frameDecode.js +491 -0
- package/dist/signature/index.d.ts +5 -0
- package/dist/signature/index.d.ts.map +1 -0
- package/dist/signature/index.js +4 -0
- package/dist/signature/metadata.d.ts +63 -0
- package/dist/signature/metadata.d.ts.map +1 -0
- package/dist/signature/metadata.js +1 -0
- package/dist/signature/quality.d.ts +169 -0
- package/dist/signature/quality.d.ts.map +1 -0
- package/dist/signature/quality.js +186 -0
- package/dist/signature/signatureValidity.d.ts +149 -0
- package/dist/signature/signatureValidity.d.ts.map +1 -0
- package/dist/signature/signatureValidity.js +305 -0
- package/dist/signatureCapture/controller.d.ts +67 -0
- package/dist/signatureCapture/controller.d.ts.map +1 -0
- package/dist/signatureCapture/controller.js +534 -0
- package/dist/signatureCapture/guidance.d.ts +9 -0
- package/dist/signatureCapture/guidance.d.ts.map +1 -0
- package/dist/signatureCapture/guidance.js +7 -0
- package/dist/signatureCapture/index.d.ts +6 -0
- package/dist/signatureCapture/index.d.ts.map +1 -0
- package/dist/signatureCapture/index.js +5 -0
- package/dist/signatureCapture/pipeline.d.ts +111 -0
- package/dist/signatureCapture/pipeline.d.ts.map +1 -0
- package/dist/signatureCapture/pipeline.js +680 -0
- package/dist/signatureCapture/reducer.d.ts +42 -0
- package/dist/signatureCapture/reducer.d.ts.map +1 -0
- package/dist/signatureCapture/reducer.js +159 -0
- package/dist/signatureCapture/state.d.ts +92 -0
- package/dist/signatureCapture/state.d.ts.map +1 -0
- package/dist/signatureCapture/state.js +24 -0
- package/dist/utils/canvas.d.ts +4 -0
- package/dist/utils/canvas.d.ts.map +1 -0
- package/dist/utils/canvas.js +21 -0
- package/dist/utils/cropping.d.ts +8 -0
- package/dist/utils/cropping.d.ts.map +1 -0
- package/dist/utils/cropping.js +85 -0
- package/dist/utils/dataUrlToBase64.d.ts +7 -0
- package/dist/utils/dataUrlToBase64.d.ts.map +1 -0
- package/dist/utils/dataUrlToBase64.js +67 -0
- package/dist/utils/getFrameDimensions.d.ts +3 -0
- package/dist/utils/getFrameDimensions.d.ts.map +1 -0
- package/dist/utils/getFrameDimensions.js +12 -0
- package/dist/utils/isMobile.d.ts +3 -0
- package/dist/utils/isMobile.d.ts.map +1 -0
- package/dist/utils/isMobile.js +36 -0
- package/dist/utils/logger.d.ts +19 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +25 -0
- package/dist/utils/platform.d.ts +4 -0
- package/dist/utils/platform.d.ts.map +1 -0
- package/dist/utils/platform.js +11 -0
- package/dist/utils/stabilizer.d.ts +26 -0
- package/dist/utils/stabilizer.d.ts.map +1 -0
- package/dist/utils/stabilizer.js +65 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +1 -0
- package/dist/videoIdCapture/controller.d.ts +108 -0
- package/dist/videoIdCapture/controller.d.ts.map +1 -0
- package/dist/videoIdCapture/controller.js +833 -0
- package/dist/videoIdCapture/index.d.ts +5 -0
- package/dist/videoIdCapture/index.d.ts.map +1 -0
- package/dist/videoIdCapture/index.js +2 -0
- package/dist/videoIdCapture/state.d.ts +88 -0
- package/dist/videoIdCapture/state.d.ts.map +1 -0
- package/dist/videoIdCapture/state.js +67 -0
- 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
|
+
}
|