@authme/identity-verification 2.2.0 → 2.2.1-rc.3

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 (93) hide show
  1. package/assets/locale/en_US.json +28 -1
  2. package/assets/locale/zh_Hant_TW.json +28 -1
  3. package/assets/styles/style.css +143 -96
  4. package/index.cjs +11634 -0
  5. package/index.js +11610 -0
  6. package/package.json +14 -14
  7. package/src/index.d.ts +5 -4
  8. package/src/lib/identity-verification-feature-identity-verification.d.ts +33 -27
  9. package/src/lib/interface/config.interface.d.ts +42 -40
  10. package/src/lib/interface/index.d.ts +1 -1
  11. package/src/lib/interface/result.model.d.ts +35 -35
  12. package/src/lib/lottie/arrow_down.d.ts +215 -215
  13. package/src/lib/lottie/arrow_left.d.ts +215 -215
  14. package/src/lib/lottie/arrow_right.d.ts +215 -215
  15. package/src/lib/lottie/arrow_up.d.ts +215 -215
  16. package/src/lib/lottie/card_lr.d.ts +182 -182
  17. package/src/lib/lottie/card_ud.d.ts +182 -182
  18. package/src/lib/lottie/index.d.ts +9 -9
  19. package/src/lib/lottie/scan.d.ts +562 -562
  20. package/src/lib/lottie/success.d.ts +946 -946
  21. package/src/lib/lottie/tutorial.d.ts +1449 -1449
  22. package/src/lib/module/liveness-verify.module.d.ts +13 -12
  23. package/src/lib/module/liveness.module.d.ts +14 -12
  24. package/src/lib/module/mrz.module.d.ts +13 -11
  25. package/src/lib/module/ocr.module.d.ts +15 -12
  26. package/src/lib/operator/index.d.ts +16 -16
  27. package/src/lib/ui/basic.d.ts +13 -13
  28. package/src/lib/ui/default-images.d.ts +2 -2
  29. package/src/lib/ui/index.d.ts +3 -3
  30. package/src/lib/ui/liveness-flow.d.ts +16 -16
  31. package/src/lib/ui/liveness.ui.d.ts +10 -10
  32. package/src/lib/ui/ocr-flow.d.ts +73 -73
  33. package/src/lib/ui/ocr.ui.d.ts +63 -63
  34. package/src/lib/ui/shared.d.ts +2 -0
  35. package/src/lib/ui/ui-init.d.ts +1 -1
  36. package/src/lib/version.d.ts +1 -0
  37. package/CHANGELOG.md +0 -1053
  38. package/src/index.js +0 -8
  39. package/src/index.js.map +0 -1
  40. package/src/lib/identity-verification-feature-identity-verification.js +0 -122
  41. package/src/lib/identity-verification-feature-identity-verification.js.map +0 -1
  42. package/src/lib/interface/config.interface.js +0 -29
  43. package/src/lib/interface/config.interface.js.map +0 -1
  44. package/src/lib/interface/index.js +0 -5
  45. package/src/lib/interface/index.js.map +0 -1
  46. package/src/lib/interface/result.model.js +0 -3
  47. package/src/lib/interface/result.model.js.map +0 -1
  48. package/src/lib/lottie/arrow_down.js +0 -203
  49. package/src/lib/lottie/arrow_down.js.map +0 -1
  50. package/src/lib/lottie/arrow_left.js +0 -203
  51. package/src/lib/lottie/arrow_left.js.map +0 -1
  52. package/src/lib/lottie/arrow_right.js +0 -203
  53. package/src/lib/lottie/arrow_right.js.map +0 -1
  54. package/src/lib/lottie/arrow_up.js +0 -203
  55. package/src/lib/lottie/arrow_up.js.map +0 -1
  56. package/src/lib/lottie/card_lr.js +0 -1903
  57. package/src/lib/lottie/card_lr.js.map +0 -1
  58. package/src/lib/lottie/card_ud.js +0 -1937
  59. package/src/lib/lottie/card_ud.js.map +0 -1
  60. package/src/lib/lottie/index.js +0 -13
  61. package/src/lib/lottie/index.js.map +0 -1
  62. package/src/lib/lottie/scan.js +0 -384
  63. package/src/lib/lottie/scan.js.map +0 -1
  64. package/src/lib/lottie/success.js +0 -509
  65. package/src/lib/lottie/success.js.map +0 -1
  66. package/src/lib/lottie/tutorial.js +0 -3683
  67. package/src/lib/lottie/tutorial.js.map +0 -1
  68. package/src/lib/module/liveness-verify.module.js +0 -218
  69. package/src/lib/module/liveness-verify.module.js.map +0 -1
  70. package/src/lib/module/liveness.module.js +0 -195
  71. package/src/lib/module/liveness.module.js.map +0 -1
  72. package/src/lib/module/mrz.module.js +0 -156
  73. package/src/lib/module/mrz.module.js.map +0 -1
  74. package/src/lib/module/ocr.module.js +0 -235
  75. package/src/lib/module/ocr.module.js.map +0 -1
  76. package/src/lib/operator/index.js +0 -38
  77. package/src/lib/operator/index.js.map +0 -1
  78. package/src/lib/ui/basic.js +0 -59
  79. package/src/lib/ui/basic.js.map +0 -1
  80. package/src/lib/ui/default-images.js +0 -6
  81. package/src/lib/ui/default-images.js.map +0 -1
  82. package/src/lib/ui/index.js +0 -7
  83. package/src/lib/ui/index.js.map +0 -1
  84. package/src/lib/ui/liveness-flow.js +0 -180
  85. package/src/lib/ui/liveness-flow.js.map +0 -1
  86. package/src/lib/ui/liveness.ui.js +0 -176
  87. package/src/lib/ui/liveness.ui.js.map +0 -1
  88. package/src/lib/ui/ocr-flow.js +0 -700
  89. package/src/lib/ui/ocr-flow.js.map +0 -1
  90. package/src/lib/ui/ocr.ui.js +0 -382
  91. package/src/lib/ui/ocr.ui.js.map +0 -1
  92. package/src/lib/ui/ui-init.js +0 -7
  93. package/src/lib/ui/ui-init.js.map +0 -1
@@ -1,700 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.startOCR = void 0;
4
- const tslib_1 = require("tslib");
5
- const arrow_down_1 = require("../lottie/arrow_down");
6
- const arrow_up_1 = require("../lottie/arrow_up");
7
- const arrow_right_1 = require("../lottie/arrow_right");
8
- const arrow_left_1 = require("../lottie/arrow_left");
9
- const rxjs_1 = require("rxjs");
10
- const util_1 = require("@authme/util");
11
- const id_recognition_1 = require("@authme/id-recognition");
12
- const lottie_web_1 = tslib_1.__importDefault(require("lottie-web"));
13
- const rxjs_2 = require("rxjs");
14
- const lottie_1 = require("../lottie");
15
- const basic_1 = require("./basic");
16
- const ocr_ui_1 = require("./ocr.ui");
17
- const operator_1 = require("../operator");
18
- const core_1 = require("@authme/core");
19
- function startOCR(config) {
20
- const translateService = (0, core_1.getTranslateInstance)();
21
- let rotateTimer = [];
22
- let rotatePosition = '';
23
- let isValidScreenSize = true;
24
- let ocrConfig = {
25
- enableManualUpload: false,
26
- fraudRetryTimes: 1,
27
- fraudTimeout: 52,
28
- fraudMaxFps: 2,
29
- };
30
- const unsubscribe$ = new rxjs_1.Subject();
31
- const getCardBorderPoint = () => {
32
- return [
33
- [
34
- cardborder.offsetLeft / cardborderContainer.offsetWidth,
35
- cardborder.offsetTop / cardborderContainer.offsetHeight,
36
- ],
37
- [
38
- cardborder.offsetLeft / cardborderContainer.offsetWidth,
39
- (cardborder.offsetTop + cardborder.offsetHeight) /
40
- cardborderContainer.offsetHeight,
41
- ],
42
- [
43
- (cardborder.offsetLeft + cardborder.offsetWidth) /
44
- cardborderContainer.offsetWidth,
45
- (cardborder.offsetTop + cardborder.offsetHeight) /
46
- cardborderContainer.offsetHeight,
47
- ],
48
- [
49
- (cardborder.offsetLeft + cardborder.offsetWidth) /
50
- cardborderContainer.offsetWidth,
51
- cardborder.offsetTop / cardborderContainer.offsetHeight,
52
- ],
53
- ];
54
- };
55
- const { container, videoContainer, video, closeIcon, headerTitle, headerSubtitle, } = (0, basic_1.renderBasicUI)({
56
- headerIcon: config.ocrConfig.icon,
57
- headerMode: config.ocrConfig.headerMode,
58
- });
59
- const { antiFraudInstructionContainer, titleTextPanel, titleText, hintText, statusText, statusTextPanel, lottieMask, arrowAnimationContainer, scanAnimationContainer, antiFraudInstructionAnimationContainer, confirmImageContainer, imageTypeText, cardborder, cardborderContainer, statementContainer, retryBtn, confirmBtn, completeBtn, image, } = (0, ocr_ui_1.renderOCRUI)({
60
- videoContainer,
61
- container,
62
- showStatement: config.ocrConfig.showStatement,
63
- });
64
- const canvasSizeInfo$ = (0, rxjs_1.merge)((0, rxjs_1.from)((0, util_1.requestCamera)(video, 'back')).pipe((0, rxjs_1.tap)((cameraFacingMode) => {
65
- if (typeof cameraFacingMode === 'string') {
66
- video.classList.add(cameraFacingMode);
67
- }
68
- (0, util_1.showElement)(videoContainer);
69
- }), (0, rxjs_1.switchMap)(() => (0, util_1.getCanvasSize)(video)), (0, rxjs_1.shareReplay)(1), (0, rxjs_1.catchError)((error) => {
70
- if (error instanceof OverconstrainedError) {
71
- alert(translateService.translate('camera.error.lowResolution'));
72
- }
73
- else {
74
- alert(translateService.translate('camera.error.notFound'));
75
- }
76
- return (0, rxjs_1.throwError)(() => new core_1.AuthmeError(core_1.ErrorCode.CAMERA_NOT_SUPPORT));
77
- })), (0, rxjs_1.fromEvent)(window, 'resize').pipe((0, rxjs_1.switchMapTo)((0, util_1.getCanvasSize)(video))));
78
- function startAntiFraud(type) {
79
- let startRotate = false;
80
- if (type !== id_recognition_1.EAuthMeCardClass.TWN_IDCard_Front ||
81
- !config.ocrConfig.needAntiFraud) {
82
- return (0, rxjs_1.of)(true);
83
- }
84
- const applyTextByResult = (result) => {
85
- statusText.classList.add('non-empty');
86
- switch (result.eStatus) {
87
- case id_recognition_1.EAuthMeIDCardAntiFraudStatus.PositionNotMatch:
88
- statusText.textContent = translateService.translate('verify.error.mismatch');
89
- setBorderColor('error');
90
- break;
91
- case id_recognition_1.EAuthMeIDCardAntiFraudStatus.NeedMoreFrame:
92
- statusText.textContent = '';
93
- statusText.classList.remove('non-empty');
94
- setBorderColor('pass');
95
- break;
96
- case id_recognition_1.EAuthMeIDCardAntiFraudStatus.NoCard:
97
- statusText.textContent = translateService.translate('verify.error.noCard');
98
- setBorderColor('error');
99
- break;
100
- case id_recognition_1.EAuthMeIDCardAntiFraudStatus.WrongCardType:
101
- statusText.textContent = translateService.translate('verify.error.wrongCardType');
102
- setBorderColor('error');
103
- break;
104
- case id_recognition_1.EAuthMeIDCardAntiFraudStatus.Reflective:
105
- statusText.textContent = translateService.translate('verify.error.reflective');
106
- setBorderColor('error');
107
- break;
108
- case id_recognition_1.EAuthMeIDCardAntiFraudStatus.Blur:
109
- statusText.textContent =
110
- translateService.translate('verify.error.blur');
111
- setBorderColor('error');
112
- break;
113
- case id_recognition_1.EAuthMeIDCardAntiFraudStatus.Gray:
114
- statusText.classList.remove('non-empty');
115
- statusText.textContent = '';
116
- setBorderColor('error');
117
- break;
118
- case id_recognition_1.EAuthMeIDCardAntiFraudStatus.Error:
119
- statusText.textContent = translateService.translate('verify.error.serverError');
120
- (0, util_1.showErrorMessage)(translateService.translate('verify.error.serverError'), true);
121
- break;
122
- default:
123
- break;
124
- }
125
- };
126
- const antiFraudStart$ = (0, rxjs_1.from)(showAntiFraudLottie()).pipe((0, rxjs_1.switchMap)(() => (0, util_1.checkOnlineStatus)(translateService.translate('network.error.offline'))), (0, rxjs_1.switchMap)(() => canvasSizeInfo$), (0, rxjs_1.switchMap)((canvasSizeInfo) => (0, rxjs_1.from)(config.setFrameSize(canvasSizeInfo.canvasWidth, canvasSizeInfo.canvasHeight)).pipe((0, rxjs_1.switchMap)(() => config.antiFraudStart(getCardBorderPoint())), (0, operator_1.sendFrame)(canvasSizeInfo, image, video, config.onAntiFraudFrame, ocrConfig.fraudMaxFps, false, 'jpg'), (0, rxjs_1.map)((x) => x.result), (0, rxjs_1.tap)((x) => {
127
- if (!startRotate)
128
- applyTextByResult(x);
129
- }), (0, rxjs_1.takeWhile)((x) => x.eStatus !== id_recognition_1.EAuthMeIDCardAntiFraudStatus.Pass &&
130
- x.eStatus !== id_recognition_1.EAuthMeIDCardAntiFraudStatus.Failed, true))), (0, rxjs_1.shareReplay)(1));
131
- const detected$ = antiFraudStart$
132
- .pipe((0, rxjs_2.filter)((x) => x.eStage !== id_recognition_1.EAuthMeIDCardAntiFraudStage.Frontal), (0, rxjs_1.take)(1), (0, rxjs_1.tap)(() => {
133
- startRotate = true;
134
- startCardBorderRotate();
135
- hintText.textContent = '';
136
- }))
137
- .subscribe();
138
- const handleSuccess$ = antiFraudStart$.pipe((0, rxjs_2.filter)((x) => x.eStatus === id_recognition_1.EAuthMeIDCardAntiFraudStatus.Pass), (0, rxjs_1.take)(1), (0, rxjs_1.tap)(() => {
139
- for (let i = 0; i < rotateTimer.length; i++) {
140
- clearTimeout(rotateTimer[i]);
141
- }
142
- (0, util_1.hidePopup)();
143
- clearAllFraudLottie();
144
- statusText.textContent = '';
145
- statusText.classList.remove('non-empty');
146
- setBorderColor('pass');
147
- lottie_web_1.default.play('success');
148
- }), (0, rxjs_1.switchMap)(() => (0, util_1.waitTime)(2000)), (0, rxjs_1.tap)(() => {
149
- if (!rotatePosition.includes('Default')) {
150
- setEndFraudRotate();
151
- }
152
- }), (0, rxjs_1.switchMap)(() => (0, util_1.waitTime)(2000)), (0, rxjs_1.tap)(() => {
153
- lottie_web_1.default.stop('success');
154
- }));
155
- const handleError$ = antiFraudStart$.pipe((0, rxjs_2.filter)((x) => x.eStatus === id_recognition_1.EAuthMeIDCardAntiFraudStatus.Failed), (0, rxjs_1.take)(1), (0, rxjs_1.tap)(() => {
156
- (0, ocr_ui_1.setHtmlRotate)(cardborder, ocr_ui_1.OcrRotateAnimationName.Default);
157
- }));
158
- return (0, rxjs_1.merge)(handleSuccess$, handleError$).pipe((0, rxjs_1.take)(1), (0, rxjs_1.tap)(() => detected$.unsubscribe()));
159
- }
160
- function startOCR(type) {
161
- if (!config.ocrConfig.needOCR &&
162
- type === id_recognition_1.EAuthMeCardClass.TWN_IDCard_Front) {
163
- return (0, rxjs_1.of)(true);
164
- }
165
- const applyTextByResult = (result) => {
166
- statusText.classList.add('non-empty');
167
- switch (result.eStatus) {
168
- case id_recognition_1.EAuthMeCardOCRStatus.NoCard:
169
- case id_recognition_1.EAuthMePassportServiceStatus.NotFound:
170
- statusText.textContent = translateService.translate('verify.error.noCard');
171
- setBorderColor('error');
172
- break;
173
- case id_recognition_1.EAuthMeCardOCRStatus.WrongCardType:
174
- statusText.textContent = translateService.translate('verify.error.wrongCardType');
175
- setBorderColor('error');
176
- break;
177
- case id_recognition_1.EAuthMeCardOCRStatus.PositionNotMatch:
178
- statusText.textContent = translateService.translate('verify.error.mismatch');
179
- setBorderColor('error');
180
- break;
181
- case id_recognition_1.EAuthMeCardOCRStatus.Reflective:
182
- statusText.textContent = translateService.translate('verify.error.reflective');
183
- setBorderColor('error');
184
- break;
185
- case id_recognition_1.EAuthMeCardOCRStatus.Blur:
186
- statusText.textContent =
187
- translateService.translate('verify.error.blur');
188
- setBorderColor('error');
189
- break;
190
- case id_recognition_1.EAuthMePassportServiceStatus.RecogFailed:
191
- statusText.textContent = translateService.translate('verify.error.wrongCardType');
192
- setBorderColor('error');
193
- break;
194
- default:
195
- break;
196
- }
197
- };
198
- const init = (retry) => canvasSizeInfo$.pipe((0, rxjs_1.take)(1), (0, rxjs_1.switchMap)((canvasSizeInfo) => (0, rxjs_1.from)(config.setFrameSize(canvasSizeInfo.canvasWidth, canvasSizeInfo.canvasHeight)).pipe((0, rxjs_1.switchMap)(() => (0, util_1.checkOnlineStatus)(translateService.translate('network.error.offline'))), (0, rxjs_1.switchMap)(() => config.ocrStart(getCardBorderPoint(), type, retry)), (0, rxjs_1.tap)(() => (0, util_1.stopSpinner)()), (0, rxjs_1.map)(() => canvasSizeInfo))));
199
- setBorderColor(null);
200
- const recognition = (retry) => init(retry).pipe((0, rxjs_1.switchMap)((canvasSizeInfo) => (0, rxjs_1.of)(canvasSizeInfo).pipe((0, operator_1.sendFrame)(canvasSizeInfo, image, video, config.recognition, 30, false, 'jpg'), (0, rxjs_1.tap)((x) => applyTextByResult(x.result)), (0, rxjs_2.filter)(({ result }) => result.eStatus === id_recognition_1.EAuthMeCardOCRStatus.Pass ||
201
- result.eStatus === id_recognition_1.EAuthMePassportServiceStatus.Success), (0, rxjs_1.take)(1), (0, rxjs_1.tap)(() => {
202
- setBorderColor('pass');
203
- statusText.textContent =
204
- translateService.translate('verify.ocrSuccess');
205
- (0, util_1.showElement)(scanAnimationContainer);
206
- scanAnimationContainer.style.width = `${cardborder.offsetWidth}px`;
207
- scanAnimationContainer.style.height = `${cardborder.offsetHeight}px`;
208
- lottie_web_1.default.play('scan');
209
- }), (0, rxjs_1.switchMap)((resp) => (0, rxjs_1.from)((0, util_1.waitTime)(3000)).pipe((0, rxjs_1.tap)(() => {
210
- (0, util_1.hideElement)(scanAnimationContainer);
211
- lottie_web_1.default.stop('scan');
212
- lottie_web_1.default.play('success');
213
- }), (0, rxjs_1.switchMap)(() => (0, util_1.waitTime)(1000)), (0, rxjs_1.tap)(() => {
214
- lottie_web_1.default.stop('success');
215
- resetMaskUI();
216
- }), (0, rxjs_1.map)(() => resp))), (0, rxjs_1.switchMap)(({ result }) => (0, rxjs_1.from)(type === id_recognition_1.EAuthMeCardClass.Passport
217
- ? (0, rxjs_1.of)(false)
218
- : checkConfirmImage(result.imageData, result.iWidth, result.iHeight, type)).pipe((0, rxjs_1.switchMap)((needRetry) => {
219
- (0, util_1.startSpinner)(translateService.translate('verify.uploading'));
220
- return needRetry
221
- ? (0, rxjs_1.of)(true)
222
- : (0, rxjs_1.from)(config.confirmImage(type)).pipe((0, rxjs_1.map)((confirmResp) => !confirmResp));
223
- }), (0, rxjs_1.tap)(() => {
224
- (0, util_1.hideElement)(confirmImageContainer);
225
- showVideoElement();
226
- }), (0, rxjs_1.switchMap)((needRetry) => needRetry ? recognition(true) : (0, rxjs_1.of)(true)))))));
227
- return recognition(false);
228
- }
229
- function createFlowByType(type) {
230
- return (0, rxjs_1.of)(true).pipe((0, rxjs_1.tap)(() => setUIByType(type)), (0, rxjs_1.switchMap)(() => startAntiFraud(type)), (0, rxjs_1.tap)(() => setUIByType(type)), (0, rxjs_1.switchMap)(() => startOCR(type)));
231
- }
232
- function main() {
233
- (0, util_1.hideElement)(antiFraudInstructionContainer);
234
- (0, util_1.startSpinner)(translateService.translate('general.loading'));
235
- const flow$ = config.acceptTypes
236
- .map((x) => createFlowByType(x))
237
- .reduce((prev, cur) => prev.pipe((0, rxjs_1.switchMap)(() => cur)), canvasSizeInfo$.pipe((0, rxjs_1.take)(1), (0, rxjs_1.tap)(() => setUIByType(config.acceptTypes[0])), (0, rxjs_1.switchMap)((canvasSizeInfo) => (0, rxjs_1.from)(config.init(canvasSizeInfo.canvasWidth, canvasSizeInfo.canvasHeight)).pipe((0, rxjs_1.tap)((x) => (ocrConfig = x)), (0, rxjs_1.tap)(() => (0, util_1.stopSpinner)())))))
238
- .pipe((0, rxjs_1.tap)(() => {
239
- (0, util_1.hideElement)(videoContainer);
240
- (0, util_1.startSpinner)(translateService.translate('verify.uploading'));
241
- }), (0, rxjs_1.switchMap)(() => config.onSuccess()), (0, rxjs_1.tap)(() => {
242
- (0, util_1.stopSpinner)();
243
- container.style.display = 'none';
244
- }), (0, rxjs_1.concatMap)((result) => {
245
- function resultFromConfirmUI() {
246
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
247
- return Object.assign(Object.assign({}, result), { details: yield (0, ocr_ui_1.renderConfirmUI)({
248
- cardType: config.ocrConfig.type,
249
- items: {
250
- columns: Object.keys(result.details).sort((a, b) => {
251
- const aScore = (0, id_recognition_1.getRecognitionColumnOrder)(a);
252
- const bScore = (0, id_recognition_1.getRecognitionColumnOrder)(b);
253
- return aScore - bScore || a.localeCompare(b);
254
- }),
255
- details: result.details,
256
- },
257
- options: {
258
- headerIcon: config.ocrConfig.icon,
259
- translate: (key) => translateService.translate(key),
260
- },
261
- }) });
262
- });
263
- }
264
- return config.ocrConfig.displayResultPage
265
- ? (0, rxjs_1.defer)(resultFromConfirmUI)
266
- : (0, rxjs_1.of)(result);
267
- }), (0, rxjs_1.map)((x) => ({ isSuccess: true, message: '', data: x })), (0, rxjs_1.takeUntil)(unsubscribe$), (0, rxjs_1.finalize)(() => {
268
- (0, util_1.stopSpinner)();
269
- reset();
270
- }));
271
- const cancel$ = (0, rxjs_1.fromEvent)(closeIcon, 'click').pipe((0, rxjs_1.map)(() => {
272
- document.body.removeChild(container);
273
- return {
274
- isSuccess: false,
275
- code: `${core_1.ErrorCode.USER_CANCEL}`,
276
- message: new core_1.AuthmeError(core_1.ErrorCode.USER_CANCEL).message,
277
- data: {},
278
- };
279
- }), (0, rxjs_1.takeUntil)(unsubscribe$));
280
- return (0, rxjs_1.merge)(flow$, cancel$).pipe((0, rxjs_1.take)(1));
281
- }
282
- (0, rxjs_1.fromEvent)(window, 'offline')
283
- .pipe((0, rxjs_1.switchMap)(() => (0, util_1.asyncOnLineShowErrorMessage)(translateService.translate('network.error.offline'), true)), (0, rxjs_1.takeUntil)(unsubscribe$))
284
- .subscribe();
285
- function startCardBorderRotate() {
286
- rotateTimer = [];
287
- setTopText(translateService.translate('verify.idCardFlipLeft'));
288
- (0, ocr_ui_1.setHtmlRotate)(cardborder, ocr_ui_1.OcrRotateAnimationName.Right);
289
- rotatePosition = ocr_ui_1.OcrRotateAnimationName.Right;
290
- lottie_web_1.default.loadAnimation({
291
- container: arrowAnimationContainer,
292
- renderer: 'svg',
293
- loop: true,
294
- autoplay: true,
295
- name: 'arrow_left',
296
- animationData: (0, arrow_left_1.arrow_left)(),
297
- });
298
- rotateTimer.push(setTimeout(() => {
299
- lottie_web_1.default.stop('arrow_left');
300
- lottie_web_1.default.destroy('arrow_left');
301
- }, 2000));
302
- rotateTimer.push(setTimeout(() => {
303
- setTopText(translateService.translate('verify.idCardFlipRight'));
304
- (0, ocr_ui_1.setHtmlRotate)(cardborder, ocr_ui_1.OcrRotateAnimationName.RightToDefault);
305
- rotatePosition = ocr_ui_1.OcrRotateAnimationName.RightToDefault;
306
- }, 3000));
307
- rotateTimer.push(setTimeout(() => {
308
- lottie_web_1.default.loadAnimation({
309
- container: arrowAnimationContainer,
310
- renderer: 'svg',
311
- loop: true,
312
- autoplay: true,
313
- name: 'arrow_right',
314
- animationData: (0, arrow_right_1.arrow_right)(),
315
- });
316
- setTopText(translateService.translate('verify.idCardFlipRight'));
317
- (0, ocr_ui_1.setHtmlRotate)(cardborder, ocr_ui_1.OcrRotateAnimationName.Left);
318
- rotatePosition = ocr_ui_1.OcrRotateAnimationName.Left;
319
- }, 6000));
320
- rotateTimer.push(setTimeout(() => {
321
- lottie_web_1.default.stop('arrow_right');
322
- lottie_web_1.default.destroy('arrow_right');
323
- }, 8000));
324
- rotateTimer.push(setTimeout(() => {
325
- setTopText(translateService.translate('verify.idCardFlipLeft'));
326
- (0, ocr_ui_1.setHtmlRotate)(cardborder, ocr_ui_1.OcrRotateAnimationName.LeftToDefault);
327
- rotatePosition = ocr_ui_1.OcrRotateAnimationName.LeftToDefault;
328
- }, 9000));
329
- rotateTimer.push(setTimeout(() => {
330
- (0, util_1.showPopup)(translateService.translate('verify.fraud.hintTitle'), translateService.translate('verify.fraud.hintText'), false);
331
- }, 11000));
332
- rotateTimer.push(setTimeout(() => {
333
- (0, util_1.hidePopup)();
334
- setTopText(translateService.translate('verify.idCardFlipLeft'));
335
- (0, ocr_ui_1.setHtmlRotate)(cardborder, ocr_ui_1.OcrRotateAnimationName.Right);
336
- rotatePosition = ocr_ui_1.OcrRotateAnimationName.Right;
337
- lottie_web_1.default.loadAnimation({
338
- container: arrowAnimationContainer,
339
- renderer: 'svg',
340
- loop: true,
341
- autoplay: true,
342
- name: 'arrow_left',
343
- animationData: (0, arrow_left_1.arrow_left)(),
344
- });
345
- }, 14000));
346
- rotateTimer.push(setTimeout(() => {
347
- lottie_web_1.default.stop('arrow_left');
348
- lottie_web_1.default.destroy('arrow_left');
349
- }, 16000));
350
- rotateTimer.push(setTimeout(() => {
351
- setTopText(translateService.translate('verify.idCardFlipRight'));
352
- (0, ocr_ui_1.setHtmlRotate)(cardborder, ocr_ui_1.OcrRotateAnimationName.RightToDefault);
353
- rotatePosition = ocr_ui_1.OcrRotateAnimationName.RightToDefault;
354
- }, 17000));
355
- rotateTimer.push(setTimeout(() => {
356
- lottie_web_1.default.loadAnimation({
357
- container: arrowAnimationContainer,
358
- renderer: 'svg',
359
- loop: true,
360
- autoplay: true,
361
- name: 'arrow_right',
362
- animationData: (0, arrow_right_1.arrow_right)(),
363
- });
364
- setTopText(translateService.translate('verify.idCardFlipRight'));
365
- (0, ocr_ui_1.setHtmlRotate)(cardborder, ocr_ui_1.OcrRotateAnimationName.Left);
366
- rotatePosition = ocr_ui_1.OcrRotateAnimationName.Left;
367
- }, 20000));
368
- rotateTimer.push(setTimeout(() => {
369
- lottie_web_1.default.stop('arrow_right');
370
- lottie_web_1.default.destroy('arrow_right');
371
- }, 22000));
372
- rotateTimer.push(setTimeout(() => {
373
- setTopText(translateService.translate('verify.idCardFlipLeft'));
374
- (0, ocr_ui_1.setHtmlRotate)(cardborder, ocr_ui_1.OcrRotateAnimationName.LeftToDefault);
375
- rotatePosition = ocr_ui_1.OcrRotateAnimationName.LeftToDefault;
376
- }, 23000));
377
- rotateTimer.push(setTimeout(() => {
378
- lottie_web_1.default.loadAnimation({
379
- container: arrowAnimationContainer,
380
- renderer: 'svg',
381
- loop: true,
382
- autoplay: true,
383
- name: 'arrow_up',
384
- animationData: (0, arrow_up_1.arrow_up)(),
385
- });
386
- setTopText(translateService.translate('verify.idCardFlipUp'));
387
- (0, ocr_ui_1.setHtmlRotate)(cardborder, ocr_ui_1.OcrRotateAnimationName.Top);
388
- rotatePosition = ocr_ui_1.OcrRotateAnimationName.Top;
389
- }, 26000));
390
- rotateTimer.push(setTimeout(() => {
391
- lottie_web_1.default.stop('arrow_up');
392
- lottie_web_1.default.destroy('arrow_up');
393
- }, 28000));
394
- rotateTimer.push(setTimeout(() => {
395
- setTopText(translateService.translate('verify.idCardFlipDown'));
396
- (0, ocr_ui_1.setHtmlRotate)(cardborder, ocr_ui_1.OcrRotateAnimationName.TopToDefault);
397
- rotatePosition = ocr_ui_1.OcrRotateAnimationName.TopToDefault;
398
- }, 29000));
399
- rotateTimer.push(setTimeout(() => {
400
- lottie_web_1.default.loadAnimation({
401
- container: arrowAnimationContainer,
402
- renderer: 'svg',
403
- loop: true,
404
- autoplay: true,
405
- name: 'arrow_down',
406
- animationData: (0, arrow_down_1.arrow_down)(),
407
- });
408
- setTopText(translateService.translate('verify.idCardFlipDown'));
409
- (0, ocr_ui_1.setHtmlRotate)(cardborder, ocr_ui_1.OcrRotateAnimationName.Bottom);
410
- rotatePosition = ocr_ui_1.OcrRotateAnimationName.Bottom;
411
- }, 32000));
412
- rotateTimer.push(setTimeout(() => {
413
- lottie_web_1.default.stop('arrow_down');
414
- lottie_web_1.default.destroy('arrow_down');
415
- }, 34000));
416
- rotateTimer.push(setTimeout(() => {
417
- setTopText(translateService.translate('verify.idCardFlipUp'));
418
- (0, ocr_ui_1.setHtmlRotate)(cardborder, ocr_ui_1.OcrRotateAnimationName.BottomToDefault);
419
- rotatePosition = ocr_ui_1.OcrRotateAnimationName.BottomToDefault;
420
- }, 35000));
421
- rotateTimer.push(setTimeout(() => {
422
- (0, util_1.showPopup)(translateService.translate('verify.fraud.hintTitle'), translateService.translate('verify.fraud.hintText'), false);
423
- }, 37000));
424
- rotateTimer.push(setTimeout(() => {
425
- (0, util_1.hidePopup)();
426
- lottie_web_1.default.loadAnimation({
427
- container: arrowAnimationContainer,
428
- renderer: 'svg',
429
- loop: true,
430
- autoplay: true,
431
- name: 'arrow_up',
432
- animationData: (0, arrow_up_1.arrow_up)(),
433
- });
434
- setTopText(translateService.translate('verify.idCardFlipUp'));
435
- (0, ocr_ui_1.setHtmlRotate)(cardborder, ocr_ui_1.OcrRotateAnimationName.Top);
436
- rotatePosition = ocr_ui_1.OcrRotateAnimationName.Top;
437
- }, 40000));
438
- rotateTimer.push(setTimeout(() => {
439
- lottie_web_1.default.stop('arrow_up');
440
- lottie_web_1.default.destroy('arrow_up');
441
- }, 42000));
442
- rotateTimer.push(setTimeout(() => {
443
- setTopText(translateService.translate('verify.idCardFlipDown'));
444
- (0, ocr_ui_1.setHtmlRotate)(cardborder, ocr_ui_1.OcrRotateAnimationName.TopToDefault);
445
- rotatePosition = ocr_ui_1.OcrRotateAnimationName.TopToDefault;
446
- }, 43000));
447
- rotateTimer.push(setTimeout(() => {
448
- lottie_web_1.default.loadAnimation({
449
- container: arrowAnimationContainer,
450
- renderer: 'svg',
451
- loop: true,
452
- autoplay: true,
453
- name: 'arrow_down',
454
- animationData: (0, arrow_down_1.arrow_down)(),
455
- });
456
- setTopText(translateService.translate('verify.idCardFlipDown'));
457
- (0, ocr_ui_1.setHtmlRotate)(cardborder, ocr_ui_1.OcrRotateAnimationName.Bottom);
458
- rotatePosition = ocr_ui_1.OcrRotateAnimationName.Bottom;
459
- }, 46000));
460
- rotateTimer.push(setTimeout(() => {
461
- lottie_web_1.default.stop('arrow_down');
462
- lottie_web_1.default.destroy('arrow_down');
463
- }, 48000));
464
- rotateTimer.push(setTimeout(() => {
465
- setTopText(translateService.translate('verify.idCardFlipUp'));
466
- (0, ocr_ui_1.setHtmlRotate)(cardborder, ocr_ui_1.OcrRotateAnimationName.BottomToDefault);
467
- rotatePosition = ocr_ui_1.OcrRotateAnimationName.BottomToDefault;
468
- }, 49000));
469
- }
470
- // resize
471
- (0, rxjs_1.fromEvent)(window, 'resize')
472
- .pipe((0, rxjs_1.switchMapTo)((0, util_1.getCanvasSize)(video)), (0, rxjs_1.switchMap)((canvasSizeInfo) => config.setFrameSize(canvasSizeInfo.canvasWidth, canvasSizeInfo.canvasHeight, getCardBorderPoint())), (0, rxjs_1.tap)(() => {
473
- scanAnimationContainer.style.width = `${cardborder.offsetWidth}px`;
474
- scanAnimationContainer.style.height = `${cardborder.offsetHeight}px`;
475
- }), (0, rxjs_1.takeUntil)(unsubscribe$))
476
- .subscribe();
477
- (0, rxjs_1.merge)((0, rxjs_1.fromEvent)(window, 'resize'), (0, rxjs_1.of)(0))
478
- .pipe((0, rxjs_1.map)(() => window.innerWidth >= 320 && window.innerHeight >= 500), (0, rxjs_2.filter)((x) => x !== isValidScreenSize), (0, rxjs_1.tap)((x) => (isValidScreenSize = x)), (0, rxjs_1.tap)((x) => x
479
- ? (0, util_1.hidePopup)()
480
- : (0, util_1.showPopup)(translateService.translate('error.screenSize.title'), translateService.translate('error.screenSize.content'), false)), (0, rxjs_1.takeUntil)(unsubscribe$))
481
- .subscribe();
482
- function showAntiFraudLottie() {
483
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
484
- showVideoElement(false);
485
- (0, util_1.showElement)(antiFraudInstructionContainer);
486
- (0, util_1.showElement)(lottieMask);
487
- setHeaderText(translateService.translate('verify.idCard'), translateService.translate('verify.header.step', { current: 1, total: 3 }));
488
- lottie_web_1.default.loadAnimation({
489
- container: antiFraudInstructionAnimationContainer,
490
- renderer: 'svg',
491
- loop: true,
492
- autoplay: true,
493
- name: 'tutorial',
494
- animationData: (0, lottie_1.tutorial)(),
495
- });
496
- setTimeout(() => {
497
- confirmBtn.disabled = false;
498
- }, 3000);
499
- yield (0, rxjs_1.firstValueFrom)((0, rxjs_1.fromEvent)(confirmBtn, 'click').pipe((0, rxjs_1.tap)(() => {
500
- (0, util_1.hideElement)(lottieMask);
501
- (0, util_1.hideElement)(antiFraudInstructionContainer);
502
- lottie_web_1.default.stop('tutorial');
503
- lottie_web_1.default.destroy('tutorial');
504
- showVideoElement();
505
- return;
506
- })));
507
- });
508
- }
509
- function checkConfirmImage(data, width, height, type) {
510
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
511
- showVideoElement(false);
512
- (0, util_1.showElement)(confirmImageContainer);
513
- if (data) {
514
- const ctx2 = image.getContext('2d');
515
- image.width = width;
516
- image.height = height;
517
- const imgData = ctx2.createImageData(image.width, image.height);
518
- imgData.data.set(data);
519
- ctx2.putImageData(imgData, 0, 0);
520
- }
521
- const retryEvents = (0, rxjs_1.fromEvent)(retryBtn, 'click').pipe((0, rxjs_1.mapTo)(true));
522
- const confirmEvents = (0, rxjs_1.fromEvent)(completeBtn, 'click').pipe((0, rxjs_1.mapTo)(false));
523
- const allEvents$ = (0, rxjs_1.merge)(retryEvents, confirmEvents);
524
- return yield (0, rxjs_1.firstValueFrom)(allEvents$.pipe());
525
- });
526
- }
527
- function setEndFraudRotate() {
528
- let position;
529
- switch (rotatePosition) {
530
- case ocr_ui_1.OcrRotateAnimationName.Top:
531
- setTopText(translateService.translate('verify.idCardFlipDown'));
532
- position = ocr_ui_1.OcrRotateAnimationName.TopToDefault;
533
- break;
534
- case ocr_ui_1.OcrRotateAnimationName.Bottom:
535
- setTopText(translateService.translate('verify.idCardFlipUp'));
536
- position = ocr_ui_1.OcrRotateAnimationName.BottomToDefault;
537
- break;
538
- case ocr_ui_1.OcrRotateAnimationName.Left:
539
- setTopText(translateService.translate('verify.idCardFlipLeft'));
540
- position = ocr_ui_1.OcrRotateAnimationName.LeftToDefault;
541
- break;
542
- case ocr_ui_1.OcrRotateAnimationName.Right:
543
- setTopText(translateService.translate('verify.idCardFlipRight'));
544
- position = ocr_ui_1.OcrRotateAnimationName.RightToDefault;
545
- break;
546
- default:
547
- position = ocr_ui_1.OcrRotateAnimationName.Default;
548
- break;
549
- }
550
- (0, ocr_ui_1.setHtmlRotate)(cardborder, position);
551
- }
552
- function setTopText(title) {
553
- titleText.textContent = title;
554
- }
555
- function setUIByType(type) {
556
- setTextByType(type);
557
- setHeaderByType(type);
558
- setCardSize(type);
559
- }
560
- function setTextByType(type) {
561
- const typeMap = {
562
- EAuthMeCardClass_Passport: 'verify.passportFrontSide',
563
- EAuthMeCardClass_TWN_IDCard_Front: 'verify.idCardFrontSide',
564
- EAuthMeCardClass_TWN_IDCard_Back: 'verify.idCardBackSide',
565
- EAuthMeCardClass_TWN_DriverLicense_Front: 'verify.licenseFrontSide',
566
- EAuthMeCardClass_TWN_DriverLicense_Back: 'verify.licenseBackSide',
567
- EAuthMeCardClass_TWN_HealthCard_Front: 'verify.healthFrontSide',
568
- };
569
- titleText.textContent = translateService.translate(typeMap[type]);
570
- statusText.textContent = '';
571
- statusText.classList.remove('non-empty');
572
- hintText.textContent = type.includes('Back')
573
- ? translateService.translate('verify.backSide')
574
- : translateService.translate('verify.frontSide');
575
- const typeConfirmTextMap = {
576
- EAuthMeCardClass_TWN_IDCard_Front: 'verify.confirmIdCardFront',
577
- EAuthMeCardClass_TWN_IDCard_Back: 'verify.confirmIdCardBack',
578
- EAuthMeCardClass_TWN_DriverLicense_Front: 'verify.confirmLicenseFront',
579
- EAuthMeCardClass_TWN_DriverLicense_Back: 'verify.confirmLicenseBack',
580
- EAuthMeCardClass_TWN_HealthCard_Front: 'verify.confirmHealthFront',
581
- };
582
- imageTypeText.textContent = translateService.translate(typeConfirmTextMap[type]);
583
- }
584
- function setHeaderByType(type) {
585
- const typeMap = {
586
- EAuthMeCardClass_Passport: 'verify.header.passport',
587
- EAuthMeCardClass_TWN_IDCard_Front: 'verify.header.idCard',
588
- EAuthMeCardClass_TWN_IDCard_Back: 'verify.header.idCard',
589
- EAuthMeCardClass_TWN_DriverLicense_Front: 'verify.header.driverLicense',
590
- EAuthMeCardClass_TWN_DriverLicense_Back: 'verify.header.driverLicense',
591
- EAuthMeCardClass_TWN_HealthCard_Front: 'verify.header.healthCard',
592
- };
593
- if (type.includes('Health') || type.includes('Passport')) {
594
- setHeaderText(translateService.translate(typeMap[type]), translateService.translate('verify.header.step', {
595
- current: 1,
596
- total: 1,
597
- }));
598
- }
599
- else {
600
- if (type.includes('Front')) {
601
- const stepNow = type.includes('TWN_IDCard')
602
- ? translateService.translate('verify.header.step', {
603
- current: 2,
604
- total: 3,
605
- })
606
- : translateService.translate('verify.header.step', {
607
- current: 1,
608
- total: 2,
609
- });
610
- setHeaderText(translateService.translate(typeMap[type]), stepNow);
611
- }
612
- else {
613
- const stepNow = type.includes('TWN_IDCard')
614
- ? translateService.translate('verify.header.step', {
615
- current: 3,
616
- total: 3,
617
- })
618
- : translateService.translate('verify.header.step', {
619
- current: 2,
620
- total: 2,
621
- });
622
- setHeaderText(translateService.translate(typeMap[type]), stepNow);
623
- }
624
- }
625
- }
626
- function setCardSize(type) {
627
- const maxWidth = cardborderContainer.offsetWidth * 0.95;
628
- const maxHeight = cardborderContainer.offsetHeight * 0.6;
629
- let ratio = 17 / 11;
630
- if (type === id_recognition_1.EAuthMeCardClass.TWN_DriverLicense_Back ||
631
- type === id_recognition_1.EAuthMeCardClass.TWN_DriverLicense_Front) {
632
- ratio = 17 / 12;
633
- }
634
- const { width, height } = (0, util_1.cropByRatio)(maxWidth, maxHeight, ratio);
635
- cardborder.style.width = `${width}px`;
636
- cardborder.style.height = `${height}px`;
637
- scanAnimationContainer.style.width = `${width}px`;
638
- scanAnimationContainer.style.height = `${height}px`;
639
- }
640
- function resetMaskUI() {
641
- setBorderColor(null);
642
- }
643
- function setBorderColor(status) {
644
- cardborder.classList.remove('error');
645
- cardborder.classList.remove('pass');
646
- if (status) {
647
- cardborder.classList.add(status);
648
- }
649
- }
650
- function clearAllFraudLottie() {
651
- lottie_web_1.default.stop('arrow_left');
652
- lottie_web_1.default.stop('arrow_right');
653
- lottie_web_1.default.stop('arrow_up');
654
- lottie_web_1.default.stop('arrow_down');
655
- lottie_web_1.default.destroy('arrow_left');
656
- lottie_web_1.default.destroy('arrow_right');
657
- lottie_web_1.default.destroy('arrow_up');
658
- lottie_web_1.default.destroy('arrow_down');
659
- }
660
- function setHeaderText(title, step) {
661
- headerTitle.textContent = title;
662
- headerSubtitle.textContent = step;
663
- }
664
- function showVideoElement(isShow = true) {
665
- if (isShow) {
666
- (0, util_1.showElement)(closeIcon);
667
- (0, util_1.showElement)(titleTextPanel);
668
- (0, util_1.showElement)(statusTextPanel);
669
- }
670
- else {
671
- (0, util_1.hideElement)(closeIcon);
672
- (0, util_1.hideElement)(titleTextPanel);
673
- (0, util_1.hideElement)(statusTextPanel);
674
- }
675
- }
676
- function reset() {
677
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
678
- try {
679
- video.srcObject
680
- .getTracks()
681
- .forEach((stream) => stream.stop());
682
- }
683
- catch (error) {
684
- // no video, ignore
685
- }
686
- yield config.onDestroy();
687
- for (let i = 0; i < rotateTimer.length; i++) {
688
- clearTimeout(rotateTimer[i]);
689
- }
690
- (0, util_1.hidePopup)();
691
- video.srcObject = null;
692
- document.body.removeChild(container);
693
- unsubscribe$.next();
694
- unsubscribe$.complete();
695
- });
696
- }
697
- return main();
698
- }
699
- exports.startOCR = startOCR;
700
- //# sourceMappingURL=ocr-flow.js.map