@authme/util 2.3.1-rc.3 → 2.4.4-rc.7

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/index.cjs CHANGED
@@ -11,15 +11,20 @@ require('core-js/modules/es.typed-array.sort.js');
11
11
  require('core-js/modules/es.typed-array.to-locale-string.js');
12
12
  require('core-js/modules/es.promise.js');
13
13
  require('core-js/modules/es.regexp.exec.js');
14
+ require('core-js/modules/es.regexp.to-string.js');
14
15
  require('core-js/modules/web.dom-collections.iterator.js');
16
+ require('core-js/modules/es.object.assign.js');
17
+ require('core-js/modules/es.number.parse-int.js');
18
+ var jwt_decode = require('jwt-decode');
19
+ require('core-js/modules/es.string.match.js');
20
+ require('core-js/modules/es.string.replace.js');
15
21
  require('core-js/modules/web.url-search-params.js');
16
22
  require('core-js/modules/es.string.search.js');
17
- require('core-js/modules/es.string.match.js');
23
+ require('core-js/modules/es.typed-array.uint32-array.js');
24
+ var Lottie = require('lottie-web');
18
25
  require('core-js/modules/es.array.sort.js');
19
26
  require('core-js/modules/es.array.includes.js');
20
27
  require('core-js/modules/es.string.includes.js');
21
- var lottie = require('lottie-web');
22
- require('core-js/modules/es.string.replace.js');
23
28
  require('core-js/modules/es.parse-int.js');
24
29
  require('core-js/modules/es.string.trim.js');
25
30
  require('core-js/modules/es.string.starts-with.js');
@@ -27,23 +32,33 @@ require('core-js/modules/es.symbol.description.js');
27
32
 
28
33
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
29
34
 
30
- var lottie__default = /*#__PURE__*/_interopDefaultLegacy(lottie);
35
+ var jwt_decode__default = /*#__PURE__*/_interopDefaultLegacy(jwt_decode);
36
+ var Lottie__default = /*#__PURE__*/_interopDefaultLegacy(Lottie);
31
37
 
32
38
  const GLOBAL_KEY = '_AuthmeConfig';
39
+ const _storage = {};
40
+ exports.STORAGE_KEY = void 0;
41
+ (function (STORAGE_KEY) {
42
+ STORAGE_KEY["LOADING_LOTTIE"] = "loadingLottie";
43
+ STORAGE_KEY["OCR_IDCARD_RESULT_FORMAT"] = "ocrIdcardResultFormat";
44
+ STORAGE_KEY["ENABLE_EVENT_TRACKING"] = "enableEventTracking";
45
+ STORAGE_KEY["EVENT_TRACK_URL"] = "eventTrackUrl";
46
+ STORAGE_KEY["API_BASE_URL"] = "apiBaseUrl";
47
+ })(exports.STORAGE_KEY || (exports.STORAGE_KEY = {}));
33
48
  function getItem(key) {
34
- return window[GLOBAL_KEY][key];
49
+ return _storage[GLOBAL_KEY][key];
35
50
  }
36
51
  function setItem(key, val) {
37
- if (!window[GLOBAL_KEY]) {
38
- window[GLOBAL_KEY] = {};
52
+ if (!_storage[GLOBAL_KEY]) {
53
+ _storage[GLOBAL_KEY] = {};
39
54
  }
40
- return window[GLOBAL_KEY][key] = val;
55
+ return _storage[GLOBAL_KEY][key] = val;
41
56
  }
42
57
  function removeItem(key) {
43
- return delete window[GLOBAL_KEY][key];
58
+ return delete _storage[GLOBAL_KEY][key];
44
59
  }
45
60
  function clear() {
46
- window[GLOBAL_KEY] = {};
61
+ _storage[GLOBAL_KEY] = {};
47
62
  }
48
63
  const Storage = {
49
64
  getItem,
@@ -67,6 +82,18 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
67
82
  PERFORMANCE OF THIS SOFTWARE.
68
83
  ***************************************************************************** */
69
84
 
85
+ function __rest(s, e) {
86
+ var t = {};
87
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
88
+ t[p] = s[p];
89
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
90
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
91
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
92
+ t[p[i]] = s[p[i]];
93
+ }
94
+ return t;
95
+ }
96
+
70
97
  function __awaiter(thisArg, _arguments, P, generator) {
71
98
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
72
99
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -113,6 +140,188 @@ function __asyncValues(o) {
113
140
  function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
114
141
  }
115
142
 
143
+ class AuthmeError {
144
+ constructor(code, cause = null) {
145
+ this._cause = null;
146
+ this._code = null;
147
+ this._code = code;
148
+ this._cause = cause;
149
+ }
150
+ get message() {
151
+ return '[Authme SDK Error] Code: ' + this.code;
152
+ }
153
+ setCode(code) {
154
+ this._code = code;
155
+ }
156
+ get code() {
157
+ return this._code;
158
+ }
159
+ get cause() {
160
+ return this._cause;
161
+ }
162
+ }
163
+ exports.ErrorCode = void 0;
164
+ (function (ErrorCode) {
165
+ // 1XX for engine
166
+ ErrorCode[ErrorCode["BROWSER_NOT_SUPPORT"] = 100] = "BROWSER_NOT_SUPPORT";
167
+ ErrorCode[ErrorCode["ENGINE_INIT_ERROR"] = 101] = "ENGINE_INIT_ERROR";
168
+ ErrorCode[ErrorCode["ENGINE_MODULE_IS_INITIALIZING"] = 102] = "ENGINE_MODULE_IS_INITIALIZING";
169
+ ErrorCode[ErrorCode["ENGINE_MODULE_INIT_ERROR"] = 103] = "ENGINE_MODULE_INIT_ERROR";
170
+ ErrorCode[ErrorCode["RECOGNITION_NOT_AVAILABLE"] = 104] = "RECOGNITION_NOT_AVAILABLE";
171
+ ErrorCode[ErrorCode["RECOGNITION_ERROR"] = 105] = "RECOGNITION_ERROR";
172
+ ErrorCode[ErrorCode["INVALID_AUTH_ERROR"] = 106] = "INVALID_AUTH_ERROR";
173
+ ErrorCode[ErrorCode["SCREEN_RESOLUTION_TOO_LOW"] = 107] = "SCREEN_RESOLUTION_TOO_LOW";
174
+ ErrorCode[ErrorCode["SCREEN_SIZE_CHANGED"] = 108] = "SCREEN_SIZE_CHANGED";
175
+ // 2 for LIVENESS
176
+ ErrorCode[ErrorCode["LIVENESS_NOT_PASSED"] = 201] = "LIVENESS_NOT_PASSED";
177
+ // 3 for ID-Recognition
178
+ ErrorCode[ErrorCode["ID_RECOGNITION_CONFIRM_INFO_ERROR"] = 301] = "ID_RECOGNITION_CONFIRM_INFO_ERROR";
179
+ ErrorCode[ErrorCode["ID_RECOGNITION_TIMEOUT"] = 302] = "ID_RECOGNITION_TIMEOUT";
180
+ // 4 for Anti-fraud
181
+ ErrorCode[ErrorCode["ID_RECOGNITION_ANTI_FRAUD_NOT_PASSED"] = 401] = "ID_RECOGNITION_ANTI_FRAUD_NOT_PASSED";
182
+ // 9 for common
183
+ ErrorCode[ErrorCode["SDK_INTERNAL_ERROR"] = 900] = "SDK_INTERNAL_ERROR";
184
+ ErrorCode[ErrorCode["NETWORK_ERROR"] = 901] = "NETWORK_ERROR";
185
+ ErrorCode[ErrorCode["HTTP_ERROR_RESPONSE"] = 902] = "HTTP_ERROR_RESPONSE";
186
+ ErrorCode[ErrorCode["USER_CANCEL"] = 903] = "USER_CANCEL";
187
+ ErrorCode[ErrorCode["CAMERA_NOT_SUPPORT"] = 904] = "CAMERA_NOT_SUPPORT";
188
+ ErrorCode[ErrorCode["SERVER_ERROR"] = 905] = "SERVER_ERROR";
189
+ ErrorCode[ErrorCode["EVENT_NAME_WRONG"] = 906] = "EVENT_NAME_WRONG";
190
+ })(exports.ErrorCode || (exports.ErrorCode = {}));
191
+
192
+ function decodeToken(token) {
193
+ const decoded = jwt_decode__default["default"](token);
194
+ const {
195
+ exp,
196
+ iat
197
+ } = decoded;
198
+ return {
199
+ payload: decoded,
200
+ exp: typeof exp === 'number' ? exp : 0,
201
+ iat: typeof iat === 'number' ? iat : 0
202
+ };
203
+ }
204
+
205
+ function getDeviceInfo() {
206
+ const userAgent = window.navigator.userAgent;
207
+ const deviceType = getDeviceType(userAgent);
208
+ const browserType = getBrowserType(userAgent);
209
+ return `${deviceType} (${browserType})`;
210
+ }
211
+ function getDeviceType(userAgent) {
212
+ if (userAgent.match(/iPad/i) || userAgent.match(/iPhone/i)) {
213
+ return 'iPad/iPhone';
214
+ } else if (userAgent.match(/Android/i)) {
215
+ return 'Android';
216
+ } else if (userAgent.match(/Windows Phone/i)) {
217
+ return 'Windows Phone';
218
+ } else if (userAgent.match(/Windows NT/i)) {
219
+ return 'Windows PC';
220
+ } else if (userAgent.match(/Mac OS/i)) {
221
+ return 'Mac';
222
+ } else if (userAgent.match(/Linux/i)) {
223
+ return 'Linux';
224
+ } else {
225
+ return 'Unknown Device';
226
+ }
227
+ }
228
+ function getBrowserType(userAgent) {
229
+ if (userAgent.match(/Chrome/i)) {
230
+ return 'Chrome';
231
+ } else if (userAgent.match(/Firefox/i)) {
232
+ return 'Firefox';
233
+ } else if (userAgent.match(/Edge/i)) {
234
+ return 'Edge';
235
+ } else if (userAgent.match(/Safari/i)) {
236
+ return 'Safari';
237
+ } else if (userAgent.match(/MSIE/i) || userAgent.match(/Trident/i)) {
238
+ return 'IE';
239
+ } else {
240
+ return 'Unknown Browser';
241
+ }
242
+ }
243
+ function getSystemInfo() {
244
+ const userAgent = window.navigator.userAgent;
245
+ const os = getOs(userAgent);
246
+ const osVersion = getOsVersion(userAgent);
247
+ return `${os} (${osVersion})`;
248
+ }
249
+ function getOs(userAgent) {
250
+ if (userAgent.match(/Windows NT 10/i)) {
251
+ return 'Windows 10';
252
+ } else if (userAgent.match(/Windows NT 6.3/i)) {
253
+ return 'Windows 8.1';
254
+ } else if (userAgent.match(/Windows NT 6.2/i)) {
255
+ return 'Windows 8';
256
+ } else if (userAgent.match(/Windows NT 6.1/i)) {
257
+ return 'Windows 7';
258
+ } else if (userAgent.match(/Windows NT 6.0/i)) {
259
+ return 'Windows Vista';
260
+ } else if (userAgent.match(/Windows NT 5.1/i)) {
261
+ return 'Windows XP';
262
+ } else if (userAgent.match(/Windows NT 5.0/i)) {
263
+ return 'Windows 2000';
264
+ } else if (userAgent.match(/Mac/i)) {
265
+ return 'Mac OS';
266
+ } else if (userAgent.match(/Linux/i)) {
267
+ return 'Linux';
268
+ } else {
269
+ return 'Unknown OS';
270
+ }
271
+ }
272
+ function getOsVersion(userAgent) {
273
+ if (userAgent.match(/Windows NT/i)) {
274
+ const matches = userAgent.match(/Windows NT ([\d\\.]+)/i);
275
+ if (matches) {
276
+ return matches[1];
277
+ } else {
278
+ return '';
279
+ }
280
+ }
281
+ if (userAgent.match(/Mac/i)) {
282
+ const matches = userAgent.match(/Mac OS X ([\d_.]+)/i);
283
+ if (matches) {
284
+ return matches[1].replace(/_/g, '.');
285
+ } else {
286
+ return '';
287
+ }
288
+ } else if (userAgent.match(/Android/i)) {
289
+ const matches = userAgent.match(/Android ([\d.]+)/i);
290
+ if (matches) {
291
+ return matches[1];
292
+ } else {
293
+ return '';
294
+ }
295
+ } else {
296
+ return '';
297
+ }
298
+ }
299
+
300
+ class State {
301
+ constructor(initialValue = null) {
302
+ this._value = initialValue;
303
+ }
304
+ getValue() {
305
+ return this._value;
306
+ }
307
+ setValue(newValue) {
308
+ this._value = newValue;
309
+ }
310
+ }
311
+ function useState(initialValue = null, subscription) {
312
+ const state = new State(initialValue);
313
+ function getValue() {
314
+ return state.getValue();
315
+ }
316
+ function setValue(newValue) {
317
+ if (subscription && newValue !== state.getValue()) {
318
+ subscription.next(newValue);
319
+ }
320
+ state.setValue(newValue);
321
+ }
322
+ return [getValue, setValue];
323
+ }
324
+
116
325
  function dataURItoBlob(dataURI) {
117
326
  // convert base64/URLEncoded data component to raw binary data held in a string
118
327
  const byteString = atob(dataURI.split(',')[1]);
@@ -164,7 +373,9 @@ function retryPromiseWithCondition(promiseFactory, conditionFactory) {
164
373
  const res = yield promiseFactory();
165
374
  return res;
166
375
  } catch (e) {
167
- console.error(e);
376
+ if ((e === null || e === void 0 ? void 0 : e._code) === exports.ErrorCode.SERVER_ERROR) {
377
+ throw e;
378
+ }
168
379
  const retry = yield conditionFactory(e);
169
380
  if (retry) {
170
381
  return retryPromiseWithCondition(promiseFactory, conditionFactory);
@@ -187,59 +398,185 @@ function isMobile() {
187
398
  return !!(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55\/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk\/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i.test(a.substr(0, 4)) || /Android|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
188
399
  }(navigator.userAgent || navigator.vendor || window.opera);
189
400
  }
190
-
191
- class AuthmeError {
192
- constructor(code, cause = null) {
193
- this._cause = null;
194
- this._code = null;
195
- this._code = code;
196
- this._cause = cause;
401
+ function splitResult(result) {
402
+ if (result.address) {
403
+ const originAddress = result.address;
404
+ const address1Index = checkCity(originAddress);
405
+ result.address1 = address1Index === -1 ? '' : originAddress.slice(0, 3);
406
+ const address2 = address1Index === -1 ? originAddress : originAddress.slice(3);
407
+ const address2Index = checkZone(address2);
408
+ result.address2 = address2Index === -1 ? '' : address2.slice(0, address2Index + 1);
409
+ result.address3 = address2Index === -1 ? address2 : address2.slice(address2Index + 1);
197
410
  }
198
- get message() {
199
- return '[Authme SDK Error] Code: ' + this.code;
411
+ if (result.dateOfBirth) {
412
+ const splitDateOfBirth = result.dateOfBirth.split('-');
413
+ const dateOfBirthY = (+splitDateOfBirth[0] - 1911).toString();
414
+ result.dateOfBirthY = dateOfBirthY.length < 3 ? '0' + dateOfBirthY : dateOfBirthY;
415
+ result.dateOfBirthM = splitDateOfBirth[1];
416
+ result.dateOfBirthD = splitDateOfBirth[2];
200
417
  }
201
- setCode(code) {
202
- this._code = code;
418
+ if (result.dateOfIssue) {
419
+ const splitDateOfIssue = result.dateOfIssue.split('-');
420
+ const dateOfIssueY = (+splitDateOfIssue[0] - 1911).toString();
421
+ result.dateOfIssueY = dateOfIssueY.length < 3 ? '0' + dateOfIssueY : dateOfIssueY;
422
+ result.dateOfIssueM = splitDateOfIssue[1];
423
+ result.dateOfIssueD = splitDateOfIssue[2];
203
424
  }
204
- get code() {
205
- return this._code;
425
+ return result;
426
+ }
427
+ function checkCity(address) {
428
+ const citys = ['臺北市', '臺中市', '基隆市', '臺南市', '高雄市', '新北市', '宜蘭縣', '桃園市', '嘉義市', '新竹縣', '苗栗縣', '南投縣', '彰化縣', '新竹市', '雲林縣', '嘉義縣', '屏東縣', '花蓮縣', '臺東縣', '金門縣', '澎湖縣', '連江縣', '臺中縣', '臺南縣', '高雄縣'];
429
+ for (const city of citys) {
430
+ if (address.indexOf(city) !== -1) {
431
+ return address.indexOf(city);
432
+ }
206
433
  }
207
- get cause() {
208
- return this._cause;
434
+ return -1;
435
+ }
436
+ function checkZone(address) {
437
+ const zones = ['鄉', '鎮', '市', '區'];
438
+ for (const zone of zones) {
439
+ if (address.indexOf(zone) !== -1) {
440
+ return address.indexOf(zone);
441
+ }
209
442
  }
443
+ return -1;
210
444
  }
211
- exports.ErrorCode = void 0;
212
- (function (ErrorCode) {
213
- // 1XX for engine
214
- ErrorCode[ErrorCode["BROWSER_NOT_SUPPORT"] = 100] = "BROWSER_NOT_SUPPORT";
215
- ErrorCode[ErrorCode["ENGINE_INIT_ERROR"] = 101] = "ENGINE_INIT_ERROR";
216
- ErrorCode[ErrorCode["ENGINE_MODULE_IS_INITIALIZING"] = 102] = "ENGINE_MODULE_IS_INITIALIZING";
217
- ErrorCode[ErrorCode["ENGINE_MODULE_INIT_ERROR"] = 103] = "ENGINE_MODULE_INIT_ERROR";
218
- ErrorCode[ErrorCode["RECOGNITION_NOT_AVAILABLE"] = 104] = "RECOGNITION_NOT_AVAILABLE";
219
- ErrorCode[ErrorCode["RECOGNITION_ERROR"] = 105] = "RECOGNITION_ERROR";
220
- ErrorCode[ErrorCode["INVALID_AUTH_ERROR"] = 106] = "INVALID_AUTH_ERROR";
221
- ErrorCode[ErrorCode["SCREEN_RESOLUTION_TOO_LOW"] = 107] = "SCREEN_RESOLUTION_TOO_LOW";
222
- ErrorCode[ErrorCode["SCREEN_SIZE_CHANGED"] = 108] = "SCREEN_SIZE_CHANGED";
223
- // 2 for LIVENESS
224
- ErrorCode[ErrorCode["LIVENESS_NOT_PASSED"] = 201] = "LIVENESS_NOT_PASSED";
225
- // 3 for ID-Recognition
226
- ErrorCode[ErrorCode["ID_RECOGNITION_CONFIRM_INFO_ERROR"] = 301] = "ID_RECOGNITION_CONFIRM_INFO_ERROR";
227
- ErrorCode[ErrorCode["ID_RECOGNITION_TIMEOUT"] = 302] = "ID_RECOGNITION_TIMEOUT";
228
- // 4 for Anti-fraud
229
- ErrorCode[ErrorCode["ID_RECOGNITION_ANTI_FRAUD_NOT_PASSED"] = 401] = "ID_RECOGNITION_ANTI_FRAUD_NOT_PASSED";
230
- // 9 for common
231
- ErrorCode[ErrorCode["SDK_INTERNAL_ERROR"] = 900] = "SDK_INTERNAL_ERROR";
232
- ErrorCode[ErrorCode["NETWORK_ERROR"] = 901] = "NETWORK_ERROR";
233
- ErrorCode[ErrorCode["HTTP_ERROR_RESPONSE"] = 902] = "HTTP_ERROR_RESPONSE";
234
- ErrorCode[ErrorCode["USER_CANCEL"] = 903] = "USER_CANCEL";
235
- ErrorCode[ErrorCode["CAMERA_NOT_SUPPORT"] = 904] = "CAMERA_NOT_SUPPORT";
236
- })(exports.ErrorCode || (exports.ErrorCode = {}));
445
+ function notEmpty(value) {
446
+ return typeof value !== 'undefined' && value !== null && value !== '';
447
+ }
448
+ function combineResult(result) {
449
+ const {
450
+ address1,
451
+ address2,
452
+ address3,
453
+ dateOfBirthY,
454
+ dateOfBirthM,
455
+ dateOfBirthD,
456
+ dateOfIssueY,
457
+ dateOfIssueM,
458
+ dateOfIssueD
459
+ } = result,
460
+ others = __rest(result, ["address1", "address2", "address3", "dateOfBirthY", "dateOfBirthM", "dateOfBirthD", "dateOfIssueY", "dateOfIssueM", "dateOfIssueD"]);
461
+ // 由於呼叫函數的情境包含 confirmOCRResult,
462
+ // confirmOCRResult 並不會知道目前是什麼卡片類型,
463
+ // 所以會以分割出的欄位來判斷是否進行欄位合併與覆寫。
464
+ const newResult = Object.assign({}, others);
465
+ if ([address1, address2, address3].every(notEmpty)) {
466
+ newResult.address = `${address1}${address2}${address3}`;
467
+ }
468
+ if ([dateOfBirthY, dateOfBirthM, dateOfBirthD].every(notEmpty)) {
469
+ newResult.dateOfBirth = `${1911 + Number.parseInt(dateOfBirthY || '0')}-${dateOfBirthM}-${dateOfBirthD}`;
470
+ }
471
+ if ([dateOfIssueY, dateOfIssueM, dateOfIssueD].every(notEmpty)) {
472
+ newResult.dateOfIssue = `${1911 + Number.parseInt(dateOfIssueY || '0')}-${dateOfIssueM}-${dateOfIssueD}`;
473
+ }
474
+ return newResult;
475
+ }
476
+ const isIphone14proOrProMax = () => {
477
+ const isIphone = () => {
478
+ return /iPhone|iPad|iPod/i.test(navigator.userAgent);
479
+ };
480
+ return isIphone() && (screen.width === 430 && screen.height === 932 || screen.width === 393 && screen.height === 852);
481
+ };
237
482
 
238
483
  function debugLog(message, ...others) {
239
484
  if (new URLSearchParams(location.search).get('authme-debug') === 'true') {
240
485
  console.log(message, ...others);
241
486
  }
242
487
  }
488
+ function generateUniqueId(length = 32) {
489
+ if (length <= 0) {
490
+ throw new Error('Length should be a positive integer.');
491
+ }
492
+ // 定義可能的字元
493
+ const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
494
+ const charactersLength = characters.length;
495
+ const randomValues = new Uint32Array(length);
496
+ // 使用window.crypto.getRandomValues取得真正的隨機值
497
+ window.crypto.getRandomValues(randomValues);
498
+ let result = '';
499
+ for (let i = 0; i < length; i++) {
500
+ result += characters[randomValues[i] % charactersLength];
501
+ }
502
+ return result;
503
+ }
504
+ function downloadObjectAsJson(exportObj, exportName) {
505
+ const dataStr = `data:application/octet-stream;headers=Content-Disposition%3A%20attachment%3B%20filename=${exportName}.json,${encodeURIComponent(JSON.stringify(exportObj, null, 4))}`;
506
+ //'data:text/json;charset=utf-8,' +
507
+ const downloadAnchorNode = document.createElement('a');
508
+ downloadAnchorNode.setAttribute('href', dataStr);
509
+ downloadAnchorNode.setAttribute('download', exportName + '.json');
510
+ document.body.appendChild(downloadAnchorNode); // required for firefox
511
+ downloadAnchorNode.click();
512
+ downloadAnchorNode.remove();
513
+ }
514
+ function debugTools(config) {
515
+ const debugLogs = [];
516
+ let currentRoundId = generateUniqueId(8);
517
+ let currentType = null;
518
+ function pushNewDebugLog(logParams) {
519
+ var _a;
520
+ if (!config.debugMode) return;
521
+ const now = new Date();
522
+ const _logParams = JSON.parse(JSON.stringify(logParams));
523
+ if (_logParams.result) {
524
+ (_a = _logParams.result) === null || _a === void 0 ? true : delete _a.imageData;
525
+ }
526
+ const newDebugLog = Object.assign({
527
+ time: now.getTime(),
528
+ dateTime: now.toLocaleString(),
529
+ roundId: currentRoundId,
530
+ type: currentType !== null && currentType !== void 0 ? currentType : undefined
531
+ }, _logParams);
532
+ debugLogs.push(newDebugLog);
533
+ }
534
+ function functionLogging(func, logParams) {
535
+ return new Promise((resolve, reject) => {
536
+ pushNewDebugLog(Object.assign(Object.assign({}, logParams), {
537
+ status: 'run-start'
538
+ }));
539
+ func().then(result => {
540
+ pushNewDebugLog(Object.assign(Object.assign({}, logParams), {
541
+ status: 'run-end',
542
+ roundId: currentRoundId,
543
+ result
544
+ }));
545
+ resolve(result);
546
+ }).catch(error => {
547
+ pushNewDebugLog(Object.assign(Object.assign({}, logParams), {
548
+ status: 'run-error',
549
+ roundId: currentRoundId,
550
+ result: error
551
+ }));
552
+ reject(error);
553
+ });
554
+ });
555
+ }
556
+ return {
557
+ pushNewDebugLog,
558
+ getDebugLogs: () => debugLogs,
559
+ getDebugLogsLength: () => debugLogs.length,
560
+ modifyDeubgLog: (index, logParams) => {
561
+ if (!config.debugMode) return;
562
+ debugLogs[index] = Object.assign(Object.assign({}, debugLogs[index]), logParams);
563
+ },
564
+ downloadDebugLogs: () => {
565
+ if (!config.debugMode) return;
566
+ downloadObjectAsJson(debugLogs, `debugLog${new Date().getTime().toString()}`);
567
+ },
568
+ functionLogging,
569
+ nextDebugRound: type => {
570
+ if (!config.debugMode) return;
571
+ currentRoundId = generateUniqueId(8);
572
+ if (type) currentType = type;
573
+ },
574
+ modifyDebugType: type => {
575
+ if (!config.debugMode) return;
576
+ currentType = type;
577
+ }
578
+ };
579
+ }
243
580
 
244
581
  exports.TIME_UNIT = void 0;
245
582
  (function (TIME_UNIT) {
@@ -344,24 +681,58 @@ function cropByRatio(width, height, ratio) {
344
681
  };
345
682
  }
346
683
 
347
- function startSpinner(text) {
684
+ function startSpinner(text, backgroundOpaque) {
685
+ const loadingLottie = Storage.getItem(exports.STORAGE_KEY.LOADING_LOTTIE);
348
686
  const body = document.querySelector('.authme-container');
687
+ if (loadingLottie) {
688
+ const loadingSDKOuter = document.createElement('div');
689
+ const loadingSDKContent = document.createElement('div');
690
+ const loadingSDKText = document.createElement('div');
691
+ loadingSDKOuter.classList.add('authme-loading-sdk-outer');
692
+ loadingSDKContent.classList.add('authme-loading-sdk-content');
693
+ loadingSDKOuter.appendChild(loadingSDKContent);
694
+ Lottie__default["default"].loadAnimation({
695
+ container: loadingSDKContent,
696
+ renderer: 'svg',
697
+ loop: true,
698
+ autoplay: true,
699
+ name: 'spinner-loading',
700
+ animationData: loadingLottie
701
+ });
702
+ body === null || body === void 0 ? void 0 : body.appendChild(loadingSDKOuter);
703
+ if (text) {
704
+ loadingSDKText.classList.add('authme-loading-sdk-text');
705
+ loadingSDKText.textContent = text;
706
+ loadingSDKContent.appendChild(loadingSDKText);
707
+ }
708
+ if (backgroundOpaque) {
709
+ loadingSDKOuter.classList.add('authme-loading-sdk-outer--opaque');
710
+ }
711
+ return;
712
+ }
349
713
  const spinnerOuter = document.createElement('div');
350
- spinnerOuter.className = 'loading-outer';
351
714
  const spinner = document.createElement('div');
352
- spinner.className = 'loading';
353
715
  const spinnerText = document.createElement('div');
354
716
  spinnerOuter.appendChild(spinner);
717
+ spinnerOuter.className = 'loading-outer';
718
+ spinner.className = 'loading';
355
719
  if (text) {
356
720
  spinnerText.className = 'loading-text';
357
721
  spinnerText.textContent = text;
358
722
  spinnerOuter.appendChild(spinnerText);
359
723
  }
724
+ if (backgroundOpaque) {
725
+ spinnerOuter.classList.add('loading-outer--opaque');
726
+ }
360
727
  body === null || body === void 0 ? void 0 : body.appendChild(spinnerOuter);
361
728
  }
362
729
  function stopSpinner() {
730
+ const loadingLottie = Storage.getItem(exports.STORAGE_KEY.LOADING_LOTTIE);
363
731
  const body = document.querySelector('.authme-container');
364
- const spinner = document.querySelector('.loading-outer');
732
+ if (loadingLottie) {
733
+ Lottie__default["default"].destroy('spinner-loading');
734
+ }
735
+ const spinner = loadingLottie ? document.querySelector('.authme-loading-sdk-outer') : document.querySelector('.loading-outer');
365
736
  if (spinner) {
366
737
  body === null || body === void 0 ? void 0 : body.removeChild(spinner);
367
738
  }
@@ -373,7 +744,7 @@ exports.Icon = void 0;
373
744
  Icon["PictureIcon"] = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFAAAABQCAYAAACOEfKtAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAt9SURBVHgB7VxdTFRJFq7q23/Q0NC6IKDGhrgiG4mSGAejmyDoToxri5F1ZV9Gk0lWn8CnyY4Pgw9rsk+LT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uyiSoyqanQYdH2315b2sBn9EQCRe/fubS8pKalPtSLjEQehCnjbMl90yT+N984mErIoIalDJ9SUCJmd31WVnPnRrFc9VAdMu6qqaqfZbN6SzKETHo9nlDqHPlijVCIOAIE/xK6Kh04sU3kRJH/sSfgIAPmi0rEn7/S6uz+UmS7HIhIAWa+Q3Lh69WpQpgkywJSOPQHC6NL7KN0ZHIENINifUSMNEEt1YYdB6JjXm9zxeWk/eAfUCCViUOWkZNbpABDX/NppW+MN2mD+rnDJyjl4J4JwBrvk7cIa1KH0OxA5r9MOJqLI5SIB4sJBMsR5K+roJxZhk5bouBjr8DFJM/TKpL87XGwcSpZM2DGETa8yT7Axahmeh506ixPJmqyItJ0fGPbSGr5cVgmgTI+kGXXpNSPvDNpRSKt1aZHK8XfIBOkWpkCo3OwL1ZiD8pb4x9+Fx7rzKGjsTpXqWKT3AEaouQui44kQmXqkl7gIMnaGKpTP/lRC1oTSi4Hwfg7dkkgncRFkjMAIwqoMoabUkUnCiQCZJI1FxgkUAXNrJMnboMBnsYyAxpNQKaB0DHIY5Ck1zbFwEpRMBlDAZM80aXnkkUceeSzif3+l5taU5LriAAAAAElFTkSuQmCC";
374
745
  })(exports.Icon || (exports.Icon = {}));
375
746
 
376
- function showErrorMessage(text, showRetryBtn, callback) {
747
+ function showErrorMessage(text, showRetryBtn, callback, buttonText, _titleText) {
377
748
  return __awaiter(this, void 0, void 0, function* () {
378
749
  const target = document.querySelector('.authme-container');
379
750
  if (!target) {
@@ -392,7 +763,39 @@ function showErrorMessage(text, showRetryBtn, callback) {
392
763
  if (showRetryBtn) {
393
764
  const retryText = document.createElement('div');
394
765
  retryText.className = 'retry-text';
395
- retryText.textContent = '重試';
766
+ retryText.textContent = buttonText !== null && buttonText !== void 0 ? buttonText : '重試';
767
+ errorMessagePanel.appendChild(retryText);
768
+ if (callback) {
769
+ retryText.addEventListener('click', e => {
770
+ target.removeChild(errorMessagePanel);
771
+ callback(e);
772
+ });
773
+ }
774
+ }
775
+ target === null || target === void 0 ? void 0 : target.appendChild(errorMessagePanel);
776
+ });
777
+ }
778
+ function showErrorMessageEventName(text, showRetryBtn, callback, buttonText, titleText) {
779
+ return __awaiter(this, void 0, void 0, function* () {
780
+ const target = document.querySelector('.authme-container');
781
+ if (!target) {
782
+ return;
783
+ }
784
+ const errorMessagePanel = document.createElement('div');
785
+ errorMessagePanel.classList.add('error-message-panel');
786
+ errorMessagePanel.classList.add('event-name');
787
+ const errorText = document.createElement('div');
788
+ errorText.className = 'error-text';
789
+ errorText.textContent = text;
790
+ const title = document.createElement('div');
791
+ title.className = 'error-title';
792
+ title.textContent = titleText !== null && titleText !== void 0 ? titleText : 'error';
793
+ errorMessagePanel.appendChild(title);
794
+ errorMessagePanel.appendChild(errorText);
795
+ if (showRetryBtn) {
796
+ const retryText = document.createElement('div');
797
+ retryText.className = 'retry-text';
798
+ retryText.textContent = buttonText !== null && buttonText !== void 0 ? buttonText : '重試';
396
799
  errorMessagePanel.appendChild(retryText);
397
800
  if (callback) {
398
801
  retryText.addEventListener('click', e => {
@@ -411,14 +814,17 @@ function hideErrorMessage() {
411
814
  body === null || body === void 0 ? void 0 : body.removeChild(errorMessagePanel);
412
815
  }
413
816
  }
414
- function asyncShowErrorMessage(text, showRetryBtn) {
817
+ function asyncShowErrorMessage(text, showRetryBtn, options) {
818
+ var _a;
415
819
  return __awaiter(this, void 0, void 0, function* () {
820
+ const _showErrorMessage = (_a = options === null || options === void 0 ? void 0 : options.showErrorMessageHandler) !== null && _a !== void 0 ? _a : showErrorMessage;
416
821
  return new Promise((res, rej) => {
822
+ var _a;
417
823
  const callback = () => {
418
824
  res(true);
419
825
  hideErrorMessage();
420
826
  };
421
- showErrorMessage(text, showRetryBtn, callback);
827
+ _showErrorMessage(text, showRetryBtn, (_a = options === null || options === void 0 ? void 0 : options.callback) !== null && _a !== void 0 ? _a : callback, options === null || options === void 0 ? void 0 : options.buttonText, options === null || options === void 0 ? void 0 : options.titleText);
422
828
  });
423
829
  });
424
830
  }
@@ -500,6 +906,7 @@ var BROWSER_CAMERA_ERRORS;
500
906
  BROWSER_CAMERA_ERRORS["NOT_ALLOWED_ERROR"] = "NotAllowedError";
501
907
  BROWSER_CAMERA_ERRORS["NOT_FOUND_ERROR"] = "NotFoundError";
502
908
  })(BROWSER_CAMERA_ERRORS || (BROWSER_CAMERA_ERRORS = {}));
909
+ let stream;
503
910
  const videoConstraintsFactory = (isPC, facingMode) => {
504
911
  return isPC ? {
505
912
  video: {
@@ -580,6 +987,43 @@ function arrayFromAsync(asyncIterable) {
580
987
  return result;
581
988
  });
582
989
  }
990
+ function switchCamera(deviceId, video) {
991
+ return __awaiter(this, void 0, void 0, function* () {
992
+ try {
993
+ if (stream) {
994
+ stream.getTracks().forEach(track => track.stop());
995
+ }
996
+ const constraints = {
997
+ video: {
998
+ // 推測依然需要使用 width & height 的限制條件,
999
+ // 否則即使是高解析度相機,也有可能拿到低解析度的圖片。(待驗證)
1000
+ width: {
1001
+ min: 1280,
1002
+ ideal: 1920,
1003
+ max: 1920
1004
+ },
1005
+ height: {
1006
+ min: 720,
1007
+ ideal: 1080,
1008
+ max: 1080
1009
+ },
1010
+ focusMode: 'auto',
1011
+ deviceId: deviceId
1012
+ }
1013
+ };
1014
+ stream = yield navigator.mediaDevices.getUserMedia(constraints);
1015
+ video.srcObject = stream;
1016
+ yield video.play();
1017
+ // Note: Fix Safari 15 video not showing bug
1018
+ video.srcObject = null;
1019
+ setTimeout(() => {
1020
+ video.srcObject = stream;
1021
+ }, 10);
1022
+ } catch (e) {
1023
+ throw new AuthmeError(exports.ErrorCode.CAMERA_NOT_SUPPORT, e);
1024
+ }
1025
+ });
1026
+ }
583
1027
  function _requestCamera(video, facingMode) {
584
1028
  var _a;
585
1029
  return __awaiter(this, void 0, void 0, function* () {
@@ -654,39 +1098,14 @@ function _requestCamera(video, facingMode) {
654
1098
  if (!deviceId) {
655
1099
  throw BROWSER_CAMERA_ERRORS.NO_CAMERA;
656
1100
  }
657
- const constraints = {
658
- video: {
659
- // 推測依然需要使用 width & height 的限制條件,
660
- // 否則即使是高解析度相機,也有可能拿到低解析度的圖片。(待驗證)
661
- width: {
662
- min: 1280,
663
- ideal: 1920,
664
- max: 1920
665
- },
666
- height: {
667
- min: 720,
668
- ideal: 1080,
669
- max: 1080
670
- },
671
- focusMode: 'auto',
672
- deviceId: {
673
- exact: deviceId
674
- }
675
- }
1101
+ if (stream) {
1102
+ stream.getTracks().forEach(track => track.stop());
1103
+ }
1104
+ yield switchCamera(deviceId, video);
1105
+ return {
1106
+ facingMode: firstDevice.meta.facingMode,
1107
+ deviceMetas: deviceMetas
676
1108
  };
677
- debugLog('camera info', {
678
- firstDevice,
679
- deviceMetas
680
- });
681
- const stream = yield navigator.mediaDevices.getUserMedia(constraints);
682
- video.srcObject = stream;
683
- yield video.play();
684
- // Note: Fix Safari 15 video not showing bug
685
- video.srcObject = null;
686
- setTimeout(() => {
687
- video.srcObject = stream;
688
- }, 10);
689
- return firstDevice.meta.facingMode;
690
1109
  });
691
1110
  }
692
1111
  function isOverconstrainedError(error) {
@@ -698,6 +1117,9 @@ function isOverconstrainedError(error) {
698
1117
  }
699
1118
  return 'constraint' in error;
700
1119
  }
1120
+ function sleep(ms) {
1121
+ return new Promise(resolve => setTimeout(resolve, ms));
1122
+ }
701
1123
  function requestCamera({
702
1124
  video,
703
1125
  facingMode,
@@ -706,7 +1128,29 @@ function requestCamera({
706
1128
  }) {
707
1129
  return __awaiter(this, void 0, void 0, function* () {
708
1130
  try {
709
- return yield _requestCamera(video, facingMode);
1131
+ let perm = yield navigator.permissions.query({
1132
+ name: 'camera'
1133
+ });
1134
+ if (perm.state == 'prompt') {
1135
+ for (let i = 0; i < 5; ++i) {
1136
+ try {
1137
+ //for ios 17.4.1 hack, if you call getUserMedia too early will only get not allowed.
1138
+ yield sleep(1000);
1139
+ return yield _requestCamera(video, facingMode);
1140
+ } catch (error) {
1141
+ if ((error === null || error === void 0 ? void 0 : error.name) === BROWSER_CAMERA_ERRORS.NOT_ALLOWED_ERROR) {
1142
+ perm = yield navigator.permissions.query({
1143
+ name: 'camera'
1144
+ });
1145
+ } else {
1146
+ throw error;
1147
+ }
1148
+ }
1149
+ }
1150
+ return yield _requestCamera(video, facingMode);
1151
+ } else {
1152
+ return yield _requestCamera(video, facingMode);
1153
+ }
710
1154
  } catch (error) {
711
1155
  if (error === BROWSER_CAMERA_ERRORS.NOT_SUPPORT) {
712
1156
  showMessage(translate('camera.error.notFound'));
@@ -1654,25 +2098,27 @@ const sdk_loading = () => ({
1654
2098
  });
1655
2099
 
1656
2100
  function startLoadingSDK(text) {
2101
+ const loadingLottie = Storage.getItem(exports.STORAGE_KEY.LOADING_LOTTIE);
1657
2102
  const body = document.body;
1658
2103
  const loadingSDKOuter = document.createElement('div');
1659
2104
  const loadingSDKContent = document.createElement('div');
1660
2105
  loadingSDKOuter.classList.add('authme-loading-sdk-outer');
1661
2106
  loadingSDKContent.classList.add('authme-loading-sdk-content');
1662
2107
  loadingSDKOuter.appendChild(loadingSDKContent);
1663
- lottie__default["default"].loadAnimation({
2108
+ Lottie__default["default"].loadAnimation({
1664
2109
  container: loadingSDKContent,
1665
2110
  renderer: 'svg',
1666
2111
  loop: true,
1667
2112
  autoplay: true,
1668
- name: 'tutorial',
1669
- animationData: sdk_loading()
2113
+ name: 'init-sdk-loading',
2114
+ animationData: loadingLottie ? loadingLottie : sdk_loading()
1670
2115
  });
1671
2116
  body === null || body === void 0 ? void 0 : body.appendChild(loadingSDKOuter);
1672
2117
  }
1673
2118
  function stopLoadingSDK() {
1674
2119
  const body = document.body;
1675
2120
  const loadingSDKOuter = document.querySelector('.authme-loading-sdk-outer');
2121
+ Lottie__default["default"].destroy('init-sdk-loading');
1676
2122
  if (loadingSDKOuter) {
1677
2123
  body === null || body === void 0 ? void 0 : body.removeChild(loadingSDKOuter);
1678
2124
  }
@@ -1714,7 +2160,7 @@ function RGBToLottieColor(color) {
1714
2160
  }
1715
2161
 
1716
2162
  var name = "@authme/util";
1717
- var version$1 = "2.3.1-rc.3";
2163
+ var version$1 = "2.4.4-rc.7";
1718
2164
  var peerDependencies = {
1719
2165
  "core-js": "^3.6.0"
1720
2166
  };
@@ -1741,17 +2187,23 @@ exports.checkOnlineStatus = checkOnlineStatus;
1741
2187
  exports.clearCanvas = clearCanvas;
1742
2188
  exports.colorStringToRGB = colorStringToRGB;
1743
2189
  exports.colorToRGB = colorToRGB;
2190
+ exports.combineResult = combineResult;
1744
2191
  exports.cropByRatio = cropByRatio;
1745
2192
  exports.dataURItoBlob = dataURItoBlob;
1746
2193
  exports.debugLog = debugLog;
2194
+ exports.debugTools = debugTools;
2195
+ exports.decodeToken = decodeToken;
1747
2196
  exports.getCanvasSize = getCanvasSize;
1748
2197
  exports.getCssVariable = getCssVariable;
2198
+ exports.getDeviceInfo = getDeviceInfo;
1749
2199
  exports.getImageData = getImageData;
2200
+ exports.getSystemInfo = getSystemInfo;
1750
2201
  exports.getUserAgent = getUserAgent;
1751
2202
  exports.hexToRGB = hexToRGB;
1752
2203
  exports.hideElement = hideElement;
1753
2204
  exports.hideErrorMessage = hideErrorMessage;
1754
2205
  exports.hidePopup = hidePopup;
2206
+ exports.isIphone14proOrProMax = isIphone14proOrProMax;
1755
2207
  exports.isMobile = isMobile;
1756
2208
  exports.isMobileOrTablet = isMobileOrTablet;
1757
2209
  exports.requestCamera = requestCamera;
@@ -1759,11 +2211,15 @@ exports.resize = resize;
1759
2211
  exports.retryPromiseWithCondition = retryPromiseWithCondition;
1760
2212
  exports.showElement = showElement;
1761
2213
  exports.showErrorMessage = showErrorMessage;
2214
+ exports.showErrorMessageEventName = showErrorMessageEventName;
1762
2215
  exports.showPopup = showPopup;
2216
+ exports.splitResult = splitResult;
1763
2217
  exports.startLoadingSDK = startLoadingSDK;
1764
2218
  exports.startSpinner = startSpinner;
1765
2219
  exports.stopLoadingSDK = stopLoadingSDK;
1766
2220
  exports.stopSpinner = stopSpinner;
2221
+ exports.switchCamera = switchCamera;
2222
+ exports.useState = useState;
1767
2223
  exports.version = version;
1768
2224
  exports.videoConstraintsFactory = videoConstraintsFactory;
1769
2225
  exports.waitTime = waitTime;