iglooform 2.5.54 → 2.5.55

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 (43) hide show
  1. package/es/form/elements.js +3 -1
  2. package/es/form/index.js +12 -2
  3. package/es/form-context.d.ts +2 -1
  4. package/es/form-context.js +2 -1
  5. package/es/hooks/index.d.ts +1 -0
  6. package/es/hooks/index.js +1 -0
  7. package/es/hooks/ocr/index.d.ts +3 -0
  8. package/es/hooks/ocr/index.js +25 -0
  9. package/es/hooks/ocr/micro-blink.d.ts +3 -0
  10. package/es/hooks/ocr/micro-blink.js +231 -0
  11. package/es/input/phone-number.d.ts +1 -1
  12. package/es/input/phone-number.js +38 -15
  13. package/es/ocr/index.d.ts +15 -0
  14. package/es/ocr/index.js +38 -0
  15. package/es/ocr/micro-blink/index.d.ts +8 -0
  16. package/es/ocr/micro-blink/index.js +189 -0
  17. package/es/ocr/micro-blink/style/index.d.ts +1 -0
  18. package/es/ocr/micro-blink/style/index.js +1 -0
  19. package/es/ocr/micro-blink/style/index.less +30 -0
  20. package/es/types.d.ts +12 -0
  21. package/es/utils/form-utils.js +1 -1
  22. package/lib/form/elements.js +4 -1
  23. package/lib/form/index.js +13 -2
  24. package/lib/form-context.d.ts +2 -1
  25. package/lib/form-context.js +2 -1
  26. package/lib/hooks/index.d.ts +1 -0
  27. package/lib/hooks/index.js +1 -0
  28. package/lib/hooks/ocr/index.d.ts +3 -0
  29. package/lib/hooks/ocr/index.js +36 -0
  30. package/lib/hooks/ocr/micro-blink.d.ts +3 -0
  31. package/lib/hooks/ocr/micro-blink.js +251 -0
  32. package/lib/input/phone-number.d.ts +1 -1
  33. package/lib/input/phone-number.js +42 -17
  34. package/lib/ocr/index.d.ts +15 -0
  35. package/lib/ocr/index.js +49 -0
  36. package/lib/ocr/micro-blink/index.d.ts +8 -0
  37. package/lib/ocr/micro-blink/index.js +218 -0
  38. package/lib/ocr/micro-blink/style/index.d.ts +1 -0
  39. package/lib/ocr/micro-blink/style/index.js +3 -0
  40. package/lib/ocr/micro-blink/style/index.less +30 -0
  41. package/lib/types.d.ts +12 -0
  42. package/lib/utils/form-utils.js +1 -1
  43. package/package.json +2 -1
@@ -0,0 +1,189 @@
1
+ import "antd/es/upload/style";
2
+ import _Upload from "antd/es/upload";
3
+
4
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
5
+
6
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
7
+
8
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
9
+ import { useContext } from 'react';
10
+ import { UploadOutlined } from 'iglooicon';
11
+ import { colors } from 'iglootheme';
12
+ import invariant from 'invariant';
13
+ import * as lodash from 'lodash';
14
+ import moment from 'moment';
15
+ import fromContext from '../../form-context';
16
+ import Typography from '../../typography';
17
+ import { LocaleContext } from '../../locale';
18
+ import message from '../../global-message';
19
+ import './style';
20
+
21
+ function getOcrDate(result, format) {
22
+ var successfullyParsed = lodash.get(result, ['dateOfBirth', 'successfullyParsed']);
23
+
24
+ if (successfullyParsed) {
25
+ var year = lodash.get(result, ['dateOfBirth', 'year']);
26
+ var month = lodash.get(result, ['dateOfBirth', 'month']);
27
+ var day = lodash.get(result, ['dateOfBirth', 'day']);
28
+ var date = new Date("".concat(year, "-").concat(month, "-").concat(day));
29
+ return format ? moment(date).format(format) : moment(date);
30
+ }
31
+
32
+ return undefined;
33
+ }
34
+
35
+ var MicroBlink = function MicroBlink(props) {
36
+ var outputMap = props.outputMap,
37
+ disabled = props.disabled;
38
+ var Dragger = _Upload.Dragger;
39
+
40
+ var _useContext = useContext(fromContext),
41
+ ocrHooks = _useContext.ocrHooks,
42
+ form = _useContext.form;
43
+
44
+ var _useContext2 = useContext(LocaleContext),
45
+ formatMessage = _useContext2.formatMessage;
46
+
47
+ var _ref = ocrHooks || {},
48
+ microBlink = _ref.microBlink;
49
+
50
+ var _ref2 = microBlink || {},
51
+ recognize = _ref2.recognize;
52
+
53
+ invariant(Boolean(microBlink) && Boolean(recognize), 'Must Config Micro Blink licenseKey');
54
+
55
+ var onUpload = /*#__PURE__*/function () {
56
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(file) {
57
+ var microBlinkResult, state, formSet;
58
+ return regeneratorRuntime.wrap(function _callee$(_context) {
59
+ while (1) {
60
+ switch (_context.prev = _context.next) {
61
+ case 0:
62
+ if (!recognize) {
63
+ _context.next = 15;
64
+ break;
65
+ }
66
+
67
+ _context.next = 3;
68
+ return recognize(file);
69
+
70
+ case 3:
71
+ microBlinkResult = _context.sent;
72
+
73
+ if (microBlinkResult) {
74
+ _context.next = 6;
75
+ break;
76
+ }
77
+
78
+ return _context.abrupt("return");
79
+
80
+ case 6:
81
+ state = microBlinkResult.state;
82
+ _context.t0 = state;
83
+ _context.next = _context.t0 === 0 ? 10 : 12;
84
+ break;
85
+
86
+ case 10:
87
+ message.error(formatMessage({
88
+ id: 'Nothing has been recognized.'
89
+ }));
90
+ return _context.abrupt("return");
91
+
92
+ case 12:
93
+ return _context.abrupt("break", 13);
94
+
95
+ case 13:
96
+ formSet = (outputMap || []).reduce(function (pre, cur) {
97
+ var field = cur.field,
98
+ source = cur.source,
99
+ format = cur.format,
100
+ formatType = cur.formatType;
101
+
102
+ switch (formatType) {
103
+ case 'date':
104
+ pre.push({
105
+ name: field,
106
+ value: getOcrDate(microBlinkResult, format),
107
+ errors: []
108
+ });
109
+ break;
110
+
111
+ default:
112
+ pre.push({
113
+ name: field,
114
+ value: lodash.get(microBlinkResult || {}, source),
115
+ errors: []
116
+ });
117
+ break;
118
+ }
119
+
120
+ return pre;
121
+ }, []);
122
+ form === null || form === void 0 ? void 0 : form.setFields(formSet);
123
+
124
+ case 15:
125
+ case "end":
126
+ return _context.stop();
127
+ }
128
+ }
129
+ }, _callee);
130
+ }));
131
+
132
+ return function onUpload(_x) {
133
+ return _ref3.apply(this, arguments);
134
+ };
135
+ }();
136
+
137
+ return _jsx("div", {
138
+ className: 'igloo-micro-blink',
139
+ children: _jsx(Dragger, {
140
+ action: function action(file) {
141
+ onUpload(file);
142
+ return '';
143
+ },
144
+ showUploadList: false,
145
+ className: "igloo-upload-box",
146
+ customRequest: function customRequest() {},
147
+ //@ts-ignore
148
+ disabled: disabled,
149
+ multiple: true,
150
+ children: _jsxs("div", {
151
+ className: "igloo-upload-box-center",
152
+ children: [_jsx(UploadOutlined, {
153
+ style: {
154
+ marginRight: 16,
155
+ fontSize: 24,
156
+ color: '#666666'
157
+ }
158
+ }), _jsxs("span", {
159
+ className: "igloo-upload-placeholder",
160
+ children: [_jsx(Typography, {
161
+ level: "body1",
162
+ children: formatMessage({
163
+ id: 'Drag and drop a file here'
164
+ })
165
+ }), _jsx(Typography, {
166
+ level: "body1",
167
+ style: {
168
+ marginLeft: 4
169
+ },
170
+ children: formatMessage({
171
+ id: 'or'
172
+ })
173
+ }), _jsx(Typography, {
174
+ level: "body1",
175
+ style: {
176
+ color: colors.purpleMain,
177
+ marginLeft: 4
178
+ },
179
+ children: formatMessage({
180
+ id: 'browse'
181
+ })
182
+ })]
183
+ })]
184
+ })
185
+ })
186
+ });
187
+ };
188
+
189
+ export default MicroBlink;
@@ -0,0 +1 @@
1
+ import './index.less';
@@ -0,0 +1 @@
1
+ import './index.less';
@@ -0,0 +1,30 @@
1
+ .igloo-micro-blink {
2
+ .igloo-upload-box {
3
+ &:hover {
4
+ border-color: #d9d9d9 !important;
5
+ }
6
+
7
+ & > .ant-upload {
8
+ background: #ffffff !important;
9
+
10
+ .ant-upload-btn {
11
+ padding: 24px 24px;
12
+ }
13
+ }
14
+
15
+ .igloo-upload-box-center {
16
+ display: flex;
17
+ align-items: center;
18
+ justify-content: center;
19
+ white-space: nowrap;
20
+
21
+ .igloo-upload-placeholder {
22
+ white-space: pre-wrap;
23
+
24
+ .igloo-upload-box-center-upload-icon {
25
+ margin-right: 16px;
26
+ }
27
+ }
28
+ }
29
+ }
30
+ }
package/es/types.d.ts CHANGED
@@ -4,8 +4,19 @@ import { ReactNode } from 'react';
4
4
  import { NamePath } from 'rc-field-form/lib/interface';
5
5
  import { CheckboxOptionType } from 'antd/es/checkbox';
6
6
  import { SelectProps } from 'antd/es/select';
7
+ import { BlinkIdSingleSideRecognizerResult } from '@microblink/blinkid-in-browser-sdk';
7
8
  export { Rule } from 'rc-field-form/lib/interface';
8
9
  export declare type FormItemName = NamePath;
10
+ export interface OCRHooks {
11
+ microBlink?: {
12
+ recognize: ((file: File) => Promise<BlinkIdSingleSideRecognizerResult | null>) | null;
13
+ };
14
+ }
15
+ export interface OCRConfig {
16
+ microBlink?: {
17
+ licenseKey: string;
18
+ };
19
+ }
9
20
  export interface FormBasicConfig {
10
21
  className?: string;
11
22
  config: FormItemConfig;
@@ -31,6 +42,7 @@ export interface FormBasicConfig {
31
42
  validationRule?: string;
32
43
  getRuleValidationApi?: string;
33
44
  stepDirection?: 'vertical' | 'horizontal';
45
+ ocr?: OCRConfig;
34
46
  }
35
47
  export declare type FormItemAssert = {
36
48
  field: NamePath;
@@ -210,7 +210,7 @@ export var calcFormItemProps = function calcFormItemProps(config, extraProps, fo
210
210
  shouldRenderCode = config.shouldRenderCode,
211
211
  rest = _objectWithoutProperties(config, _excluded);
212
212
 
213
- invariant(nameProp !== undefined || type === 'Divider' || type === 'Section' || type === 'Typography' || !type, "name property is required for form item config (type: ".concat(type, ")"));
213
+ invariant(nameProp !== undefined || type === 'Divider' || type === 'Section' || type === 'Typography' || type === 'OCR' || !type, "name property is required for form item config (type: ".concat(type, ")"));
214
214
  invariant(!previewFormater || typeof previewFormater === 'function', 'previewFormater property should be a function');
215
215
  invariant(!shouldRender || typeof shouldRender === 'function', 'shouldRender property should be a function');
216
216
 
@@ -37,6 +37,8 @@ var _typography = _interopRequireDefault(require("../typography"));
37
37
 
38
38
  var _searchBox = _interopRequireDefault(require("../search-box"));
39
39
 
40
+ var _ocr = _interopRequireDefault(require("../ocr"));
41
+
40
42
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
41
43
 
42
44
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -75,7 +77,8 @@ var elementMap = {
75
77
  Confirmation: _confirmation.default,
76
78
  ExpiryDate: _input.ExpiryDate,
77
79
  Typography: _typography.default,
78
- SearchBox: _searchBox.default
80
+ SearchBox: _searchBox.default,
81
+ OCR: _ocr.default
79
82
  };
80
83
 
81
84
  var Unknown = function Unknown() {
package/lib/form/index.js CHANGED
@@ -37,6 +37,8 @@ var _locale = require("../locale");
37
37
 
38
38
  var _formUtils = require("./../utils/form-utils");
39
39
 
40
+ var _ocr = _interopRequireDefault(require("../hooks/ocr"));
41
+
40
42
  var _excluded = ["validateMessages"];
41
43
 
42
44
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -91,7 +93,8 @@ var IglooForm = function IglooForm(props, ref) {
91
93
  selectDatasourceApi = props.selectDatasourceApi,
92
94
  getRuleValidationApi = props.getRuleValidationApi,
93
95
  _props$stepDirection = props.stepDirection,
94
- stepDirection = _props$stepDirection === void 0 ? 'vertical' : _props$stepDirection;
96
+ stepDirection = _props$stepDirection === void 0 ? 'vertical' : _props$stepDirection,
97
+ ocr = props.ocr;
95
98
 
96
99
  var _Form$useForm = _form.default.useForm(),
97
100
  _Form$useForm2 = _slicedToArray(_Form$useForm, 1),
@@ -119,6 +122,13 @@ var IglooForm = function IglooForm(props, ref) {
119
122
  currentLang = _useContext.currentLang;
120
123
 
121
124
  var validationRule = props.validationRule || config.validationRule;
125
+ var createHooks = (0, _ocr.default)();
126
+ var ocrHooks = undefined;
127
+
128
+ if (ocr) {
129
+ ocrHooks = createHooks(ocr);
130
+ }
131
+
122
132
  (0, _invariant.default)(type, "Contianer type should be one of ['Pages', 'Page', 'Steps', 'Login']");
123
133
  (0, _invariant.default)(!validationRule || getRuleValidationApi, 'Please provide getRuleValidationApi in Form props');
124
134
 
@@ -302,7 +312,8 @@ var IglooForm = function IglooForm(props, ref) {
302
312
  uploadApi: uploadApi,
303
313
  selectDatasourceApi: selectDatasourceApi,
304
314
  getRuleValidationApi: getRuleValidationApi,
305
- handleValuesChange: handleValuesChange
315
+ handleValuesChange: handleValuesChange,
316
+ ocrHooks: ocrHooks
306
317
  }, locales),
307
318
  children: (0, _jsxRuntime.jsxs)(_form.default, {
308
319
  form: form,
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { FormInstance } from 'antd/es/form';
3
- import { FormItemName } from '@/types';
3
+ import { FormItemName, OCRHooks } from './types';
4
4
  declare const _default: React.Context<{
5
5
  form?: FormInstance<any> | undefined;
6
6
  onCancel?(): void;
@@ -19,5 +19,6 @@ declare const _default: React.Context<{
19
19
  selectDatasourceApi?: string | undefined;
20
20
  getRuleValidationApi?: string | undefined;
21
21
  handleValuesChange(changedFields: any): any;
22
+ ocrHooks?: OCRHooks | undefined;
22
23
  }>;
23
24
  export default _default;
@@ -14,7 +14,8 @@ var _default = /*#__PURE__*/_react.default.createContext({
14
14
  return window;
15
15
  },
16
16
  registerDependencies: function registerDependencies() {},
17
- handleValuesChange: function handleValuesChange() {}
17
+ handleValuesChange: function handleValuesChange() {},
18
+ ocrHooks: {}
18
19
  });
19
20
 
20
21
  exports.default = _default;
@@ -0,0 +1 @@
1
+
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,3 @@
1
+ import { OCRConfig, OCRHooks } from '../../types';
2
+ declare const useOCR: () => (config: OCRConfig) => OCRHooks;
3
+ export default useOCR;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _invariant = _interopRequireDefault(require("invariant"));
9
+
10
+ var _microBlink = _interopRequireDefault(require("./micro-blink"));
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ var useOCR = function useOCR() {
15
+ var createRecognize = (0, _microBlink.default)();
16
+ return function (config) {
17
+ var microBlink = config.microBlink;
18
+
19
+ var _ref = microBlink || {},
20
+ licenseKey = _ref.licenseKey;
21
+
22
+ var hooks = {};
23
+ (0, _invariant.default)(Boolean(microBlink) === Boolean(licenseKey), 'Must Config licenseKey of Micro Blink');
24
+
25
+ if (microBlink && licenseKey) {
26
+ hooks['microBlink'] = {
27
+ recognize: createRecognize(licenseKey)
28
+ };
29
+ }
30
+
31
+ return hooks;
32
+ };
33
+ };
34
+
35
+ var _default = useOCR;
36
+ exports.default = _default;
@@ -0,0 +1,3 @@
1
+ import * as BlinkIDSDK from '@microblink/blinkid-in-browser-sdk';
2
+ declare const useMicroBlink: () => (licenseKey: string) => (file: File) => Promise<BlinkIDSDK.BlinkIdSingleSideRecognizerResult | null>;
3
+ export default useMicroBlink;
@@ -0,0 +1,251 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _react = require("react");
11
+
12
+ var BlinkIDSDK = _interopRequireWildcard(require("@microblink/blinkid-in-browser-sdk"));
13
+
14
+ var _globalMessage = _interopRequireDefault(require("../../global-message"));
15
+
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
18
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
19
+
20
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
+
22
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
23
+
24
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
25
+
26
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
27
+
28
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
29
+
30
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
31
+
32
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
33
+
34
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
35
+
36
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
37
+
38
+ var MICRO_BLINK_SERVICE_PATH = 'https://static.iglooinsure.com/microblink/in-browser';
39
+
40
+ function getWorkerLocation(_x) {
41
+ return _getWorkerLocation.apply(this, arguments);
42
+ }
43
+
44
+ function _getWorkerLocation() {
45
+ _getWorkerLocation = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5(path) {
46
+ return regeneratorRuntime.wrap(function _callee5$(_context5) {
47
+ while (1) {
48
+ switch (_context5.prev = _context5.next) {
49
+ case 0:
50
+ return _context5.abrupt("return", new Promise(function (resolve) {
51
+ window.fetch(path).then(function (response) {
52
+ return response.text();
53
+ }).then(function (data) {
54
+ var blob = new Blob([data], {
55
+ type: 'application/javascript'
56
+ });
57
+ var url = URL.createObjectURL(blob);
58
+ resolve(url);
59
+ });
60
+ }));
61
+
62
+ case 1:
63
+ case "end":
64
+ return _context5.stop();
65
+ }
66
+ }
67
+ }, _callee5);
68
+ }));
69
+ return _getWorkerLocation.apply(this, arguments);
70
+ }
71
+
72
+ var useMicroBlink = function useMicroBlink() {
73
+ var _useState = (0, _react.useState)(''),
74
+ _useState2 = _slicedToArray(_useState, 2),
75
+ currentKey = _useState2[0],
76
+ setCurrentKey = _useState2[1];
77
+
78
+ var _useState3 = (0, _react.useState)(null),
79
+ _useState4 = _slicedToArray(_useState3, 2),
80
+ recognizer = _useState4[0],
81
+ setRecognizer = _useState4[1];
82
+
83
+ var _useState5 = (0, _react.useState)(null),
84
+ _useState6 = _slicedToArray(_useState5, 2),
85
+ recognizerRunner = _useState6[0],
86
+ setRecognizerRunner = _useState6[1];
87
+
88
+ var initSdk = /*#__PURE__*/function () {
89
+ var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(licenseKey) {
90
+ var loadSettings;
91
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
92
+ while (1) {
93
+ switch (_context2.prev = _context2.next) {
94
+ case 0:
95
+ if (!BlinkIDSDK.isBrowserSupported()) {
96
+ _context2.next = 9;
97
+ break;
98
+ }
99
+
100
+ loadSettings = new BlinkIDSDK.WasmSDKLoadSettings(licenseKey);
101
+ loadSettings.engineLocation = MICRO_BLINK_SERVICE_PATH;
102
+ _context2.next = 5;
103
+ return getWorkerLocation("".concat(MICRO_BLINK_SERVICE_PATH, "/BlinkIDWasmSDK.worker.min.js"));
104
+
105
+ case 5:
106
+ loadSettings.workerLocation = _context2.sent;
107
+ BlinkIDSDK.loadWasmModule(loadSettings).then( /*#__PURE__*/function () {
108
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(wasmSDK) {
109
+ var recognizer, recognizerRunner;
110
+ return regeneratorRuntime.wrap(function _callee$(_context) {
111
+ while (1) {
112
+ switch (_context.prev = _context.next) {
113
+ case 0:
114
+ _context.next = 2;
115
+ return BlinkIDSDK.createBlinkIdSingleSideRecognizer(wasmSDK);
116
+
117
+ case 2:
118
+ recognizer = _context.sent;
119
+ _context.next = 5;
120
+ return BlinkIDSDK.createRecognizerRunner(wasmSDK, [recognizer], true);
121
+
122
+ case 5:
123
+ recognizerRunner = _context.sent;
124
+ setRecognizer(recognizer);
125
+ setRecognizerRunner(recognizerRunner);
126
+
127
+ case 8:
128
+ case "end":
129
+ return _context.stop();
130
+ }
131
+ }
132
+ }, _callee);
133
+ }));
134
+
135
+ return function (_x3) {
136
+ return _ref2.apply(this, arguments);
137
+ };
138
+ }(), function (error) {
139
+ console.log('Error during the initialization of the SDK!', error);
140
+ });
141
+ _context2.next = 10;
142
+ break;
143
+
144
+ case 9:
145
+ _globalMessage.default.error('This browser is not supported by the SDK!');
146
+
147
+ case 10:
148
+ case "end":
149
+ return _context2.stop();
150
+ }
151
+ }
152
+ }, _callee2);
153
+ }));
154
+
155
+ return function initSdk(_x2) {
156
+ return _ref.apply(this, arguments);
157
+ };
158
+ }();
159
+
160
+ var recognize = (0, _react.useCallback)(function () {
161
+ if (recognizer && recognizerRunner) {
162
+ return /*#__PURE__*/function () {
163
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(file) {
164
+ var ele, frame, processResult, recognitionResult;
165
+ return regeneratorRuntime.wrap(function _callee3$(_context3) {
166
+ while (1) {
167
+ switch (_context3.prev = _context3.next) {
168
+ case 0:
169
+ ele = document.createElement('img');
170
+ ele.src = URL.createObjectURL(file);
171
+ _context3.next = 4;
172
+ return ele.decode();
173
+
174
+ case 4:
175
+ frame = BlinkIDSDK.captureFrame(ele);
176
+ _context3.next = 7;
177
+ return recognizerRunner.processImage(frame);
178
+
179
+ case 7:
180
+ processResult = _context3.sent;
181
+
182
+ if (!(processResult !== BlinkIDSDK.RecognizerResultState.Empty)) {
183
+ _context3.next = 15;
184
+ break;
185
+ }
186
+
187
+ _context3.next = 11;
188
+ return recognizer.getResult();
189
+
190
+ case 11:
191
+ recognitionResult = _context3.sent;
192
+ return _context3.abrupt("return", recognitionResult);
193
+
194
+ case 15:
195
+ _globalMessage.default.error('Recognition was not successful!');
196
+
197
+ return _context3.abrupt("return", null);
198
+
199
+ case 17:
200
+ case "end":
201
+ return _context3.stop();
202
+ }
203
+ }
204
+ }, _callee3);
205
+ }));
206
+
207
+ return function (_x4) {
208
+ return _ref3.apply(this, arguments);
209
+ };
210
+ }();
211
+ } else {
212
+ return /*#__PURE__*/function () {
213
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(file) {
214
+ return regeneratorRuntime.wrap(function _callee4$(_context4) {
215
+ while (1) {
216
+ switch (_context4.prev = _context4.next) {
217
+ case 0:
218
+ return _context4.abrupt("return", null);
219
+
220
+ case 1:
221
+ case "end":
222
+ return _context4.stop();
223
+ }
224
+ }
225
+ }, _callee4);
226
+ }));
227
+
228
+ return function (_x5) {
229
+ return _ref4.apply(this, arguments);
230
+ };
231
+ }();
232
+ }
233
+ }, [recognizer, recognizerRunner]);
234
+
235
+ var dealRepeatSendRequest = function dealRepeatSendRequest(licenseKey) {
236
+ if (currentKey !== '' && currentKey === licenseKey) {
237
+ return;
238
+ } else {
239
+ setCurrentKey(licenseKey);
240
+ initSdk(licenseKey);
241
+ }
242
+ };
243
+
244
+ return function (licenseKey) {
245
+ dealRepeatSendRequest(licenseKey);
246
+ return recognize();
247
+ };
248
+ };
249
+
250
+ var _default = useMicroBlink;
251
+ exports.default = _default;
@@ -1,6 +1,6 @@
1
1
  import { CSSProperties } from 'react';
2
2
  import { FC, IglooComponentProps } from '../types';
3
- import './style/index';
3
+ import './style/index.less';
4
4
  export interface PhoneNumberProps extends IglooComponentProps {
5
5
  areaCode?: string | string[];
6
6
  phoneNumber?: number;