id-scanner-lib 1.3.3 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -460
- package/dist/id-scanner-lib.esm.js +4641 -0
- package/dist/id-scanner-lib.esm.js.map +1 -0
- package/dist/id-scanner-lib.js +14755 -0
- package/dist/id-scanner-lib.js.map +1 -0
- package/dist/types/core/base-module.d.ts +44 -0
- package/dist/types/core/camera-manager.d.ts +258 -0
- package/dist/types/core/config.d.ts +88 -0
- package/dist/types/core/errors.d.ts +111 -0
- package/dist/types/core/event-emitter.d.ts +55 -0
- package/dist/types/core/logger.d.ts +277 -0
- package/dist/types/core/module-manager.d.ts +78 -0
- package/dist/types/core/plugin-manager.d.ts +158 -0
- package/dist/types/core/resource-manager.d.ts +246 -0
- package/dist/types/core/result.d.ts +83 -0
- package/dist/types/core/scanner-factory.d.ts +93 -0
- package/dist/types/index.bundle.d.ts +1303 -0
- package/dist/types/index.d.ts +86 -0
- package/dist/types/interfaces/external-types.d.ts +174 -0
- package/dist/types/interfaces/face-detection.d.ts +293 -0
- package/dist/types/interfaces/scanner-module.d.ts +280 -0
- package/dist/types/modules/face/face-detector.d.ts +170 -0
- package/dist/types/modules/face/index.d.ts +56 -0
- package/dist/types/modules/face/liveness-detector.d.ts +177 -0
- package/dist/types/modules/face/types.d.ts +136 -0
- package/dist/types/modules/id-card/anti-fake-detector.d.ts +170 -0
- package/dist/types/modules/id-card/id-card-detector.d.ts +131 -0
- package/dist/types/modules/id-card/index.d.ts +89 -0
- package/dist/types/modules/id-card/ocr-processor.d.ts +110 -0
- package/dist/types/modules/id-card/ocr-worker.d.ts +31 -0
- package/dist/types/modules/id-card/types.d.ts +181 -0
- package/dist/types/modules/qrcode/index.d.ts +51 -0
- package/dist/types/modules/qrcode/qr-code-scanner.d.ts +64 -0
- package/dist/types/modules/qrcode/types.d.ts +67 -0
- package/dist/types/utils/camera.d.ts +81 -0
- package/dist/types/utils/image-processing.d.ts +176 -0
- package/dist/types/utils/index.d.ts +175 -0
- package/dist/types/utils/performance.d.ts +81 -0
- package/dist/types/utils/resource-manager.d.ts +53 -0
- package/dist/types/utils/types.d.ts +166 -0
- package/dist/types/utils/worker.d.ts +52 -0
- package/dist/types/version.d.ts +7 -0
- package/package.json +76 -75
- package/src/core/base-module.ts +78 -0
- package/src/core/camera-manager.ts +798 -0
- package/src/core/config.ts +268 -0
- package/src/core/errors.ts +174 -0
- package/src/core/event-emitter.ts +110 -0
- package/src/core/logger.ts +549 -0
- package/src/core/module-manager.ts +165 -0
- package/src/core/plugin-manager.ts +429 -0
- package/src/core/resource-manager.ts +762 -0
- package/src/core/result.ts +163 -0
- package/src/core/scanner-factory.ts +237 -0
- package/src/index.ts +113 -936
- package/src/interfaces/external-types.ts +200 -0
- package/src/interfaces/face-detection.ts +309 -0
- package/src/interfaces/scanner-module.ts +384 -0
- package/src/modules/face/face-detector.ts +931 -0
- package/src/modules/face/index.ts +208 -0
- package/src/modules/face/liveness-detector.ts +908 -0
- package/src/modules/face/types.ts +133 -0
- package/src/{id-recognition → modules/id-card}/anti-fake-detector.ts +273 -239
- package/src/modules/id-card/id-card-detector.ts +474 -0
- package/src/modules/id-card/index.ts +425 -0
- package/src/{id-recognition → modules/id-card}/ocr-processor.ts +149 -92
- package/src/modules/id-card/ocr-worker.ts +259 -0
- package/src/modules/id-card/types.ts +178 -0
- package/src/modules/qrcode/index.ts +175 -0
- package/src/modules/qrcode/qr-code-scanner.ts +230 -0
- package/src/modules/qrcode/types.ts +65 -0
- package/src/types/tesseract.d.ts +265 -22
- package/src/utils/image-processing.ts +68 -49
- package/src/utils/index.ts +426 -0
- package/src/utils/performance.ts +168 -131
- package/src/utils/resource-manager.ts +65 -146
- package/src/utils/types.ts +90 -2
- package/src/utils/worker.ts +123 -84
- package/src/version.ts +11 -0
- package/tools/scaffold.js +543 -0
- package/dist/id-scanner-core.esm.js +0 -11349
- package/dist/id-scanner-core.js +0 -11361
- package/dist/id-scanner-core.min.js +0 -1
- package/dist/id-scanner-ocr.esm.js +0 -2319
- package/dist/id-scanner-ocr.js +0 -2328
- package/dist/id-scanner-ocr.min.js +0 -1
- package/dist/id-scanner-qr.esm.js +0 -1296
- package/dist/id-scanner-qr.js +0 -1305
- package/dist/id-scanner-qr.min.js +0 -1
- package/dist/id-scanner.js +0 -4561
- package/dist/id-scanner.min.js +0 -1
- package/src/core.ts +0 -138
- package/src/demo/demo.ts +0 -204
- package/src/id-recognition/data-extractor.ts +0 -262
- package/src/id-recognition/id-detector.ts +0 -510
- package/src/id-recognition/ocr-worker.ts +0 -156
- package/src/index-umd.ts +0 -477
- package/src/ocr-module.ts +0 -187
- package/src/qr-module.ts +0 -179
- package/src/scanner/barcode-scanner.ts +0 -251
- package/src/scanner/qr-scanner.ts +0 -167
package/package.json
CHANGED
|
@@ -1,95 +1,96 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "id-scanner-lib",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
".": {
|
|
9
|
-
"import": "./dist/id-scanner-core.esm.js",
|
|
10
|
-
"require": "./dist/id-scanner.js"
|
|
11
|
-
},
|
|
12
|
-
"./core": {
|
|
13
|
-
"import": "./dist/id-scanner-core.esm.js",
|
|
14
|
-
"require": "./dist/id-scanner-core.js"
|
|
15
|
-
},
|
|
16
|
-
"./ocr": {
|
|
17
|
-
"import": "./dist/id-scanner-ocr.esm.js",
|
|
18
|
-
"require": "./dist/id-scanner-ocr.js"
|
|
19
|
-
},
|
|
20
|
-
"./qr": {
|
|
21
|
-
"import": "./dist/id-scanner-qr.esm.js",
|
|
22
|
-
"require": "./dist/id-scanner-qr.js"
|
|
23
|
-
}
|
|
24
|
-
},
|
|
5
|
+
"description": "Browser-based ID card, QR code, and face recognition scanner with liveness detection",
|
|
6
|
+
"main": "dist/id-scanner-lib.js",
|
|
7
|
+
"module": "dist/id-scanner-lib.esm.js",
|
|
25
8
|
"types": "dist/types/index.d.ts",
|
|
26
|
-
"
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"src",
|
|
12
|
+
"LICENSE",
|
|
13
|
+
"README.md"
|
|
14
|
+
],
|
|
15
|
+
"bin": {
|
|
16
|
+
"id-scanner-scaffold": "./tools/scaffold.js"
|
|
17
|
+
},
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
27
21
|
"scripts": {
|
|
28
|
-
"build": "rollup -c",
|
|
29
|
-
"dev": "rollup -c -w",
|
|
30
|
-
"test": "
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
22
|
+
"build": "rimraf dist && rollup -c rollup.config.js",
|
|
23
|
+
"dev": "rollup -c -w rollup.config.js",
|
|
24
|
+
"test": "jest",
|
|
25
|
+
"lint": "eslint --ext .ts,.js src",
|
|
26
|
+
"format": "prettier --write \"src/**/*.{ts,js}\"",
|
|
27
|
+
"docs:dev": "vitepress dev docs",
|
|
28
|
+
"docs:build": "vitepress build docs",
|
|
29
|
+
"docs:serve": "vitepress serve docs",
|
|
30
|
+
"prepare": "npm run build",
|
|
31
|
+
"scaffold": "node ./tools/scaffold.js"
|
|
32
|
+
},
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/agions/id-scanner-lib.git"
|
|
38
36
|
},
|
|
39
37
|
"keywords": [
|
|
38
|
+
"id-scanner",
|
|
40
39
|
"id-card",
|
|
41
40
|
"qr-code",
|
|
42
41
|
"scanner",
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
42
|
+
"face-recognition",
|
|
43
|
+
"id-verification",
|
|
44
|
+
"face-detection",
|
|
45
|
+
"face-liveness",
|
|
46
|
+
"biometrics",
|
|
47
|
+
"webcam"
|
|
48
48
|
],
|
|
49
|
-
"author": "
|
|
49
|
+
"author": "Your Name",
|
|
50
50
|
"license": "MIT",
|
|
51
|
-
"description": "一款纯前端实现的TypeScript身份证&二维码识别库,无需后端支持,所有处理在浏览器端完成,新增图像批处理与优化",
|
|
52
|
-
"repository": {
|
|
53
|
-
"type": "git",
|
|
54
|
-
"url": "git+https://github.com/agions/id-scanner-lib.git"
|
|
55
|
-
},
|
|
56
51
|
"bugs": {
|
|
57
52
|
"url": "https://github.com/agions/id-scanner-lib/issues"
|
|
58
53
|
},
|
|
59
54
|
"homepage": "https://github.com/agions/id-scanner-lib#readme",
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"LICENSE"
|
|
65
|
-
],
|
|
66
|
-
"publishConfig": {
|
|
67
|
-
"access": "public"
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@tensorflow/tfjs": "^4.16.0",
|
|
57
|
+
"@vladmandic/face-api": "^1.7.13",
|
|
58
|
+
"jsqr": "^1.4.0"
|
|
68
59
|
},
|
|
69
60
|
"devDependencies": {
|
|
70
|
-
"@
|
|
71
|
-
"@
|
|
72
|
-
"@
|
|
61
|
+
"@babel/core": "^7.23.7",
|
|
62
|
+
"@babel/preset-env": "^7.23.7",
|
|
63
|
+
"@babel/preset-typescript": "^7.23.7",
|
|
64
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
65
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
66
|
+
"@rollup/plugin-json": "^6.0.1",
|
|
67
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
73
68
|
"@rollup/plugin-terser": "^0.4.4",
|
|
74
|
-
"@rollup/plugin-typescript": "^
|
|
75
|
-
"@types/
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"
|
|
69
|
+
"@rollup/plugin-typescript": "^11.1.5",
|
|
70
|
+
"@types/jest": "^29.5.11",
|
|
71
|
+
"@typescript-eslint/eslint-plugin": "^6.19.1",
|
|
72
|
+
"@typescript-eslint/parser": "^6.19.1",
|
|
73
|
+
"dts-bundle-generator": "^9.2.4",
|
|
74
|
+
"eslint": "^8.56.0",
|
|
75
|
+
"eslint-config-prettier": "^9.1.0",
|
|
76
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
77
|
+
"jest": "^29.7.0",
|
|
78
|
+
"prettier": "^3.2.4",
|
|
79
|
+
"rimraf": "^5.0.5",
|
|
80
|
+
"rollup": "^4.9.6",
|
|
81
|
+
"rollup-plugin-copy": "^3.5.0",
|
|
82
|
+
"rollup-plugin-dts": "^6.1.0",
|
|
83
|
+
"rollup-plugin-livereload": "^2.0.5",
|
|
84
|
+
"rollup-plugin-polyfill-node": "^0.13.0",
|
|
85
|
+
"rollup-plugin-serve": "^1.1.1",
|
|
86
|
+
"rollup-plugin-typescript2": "^0.36.0",
|
|
87
|
+
"ts-jest": "^29.1.1",
|
|
88
|
+
"tslib": "^2.6.2",
|
|
89
|
+
"typedoc": "^0.25.7",
|
|
90
|
+
"typescript": "^5.3.3",
|
|
91
|
+
"vitepress": "^1.0.0-rc.25"
|
|
88
92
|
},
|
|
89
|
-
"
|
|
90
|
-
"
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
"last 2 versions"
|
|
94
|
-
]
|
|
95
|
-
}
|
|
93
|
+
"engines": {
|
|
94
|
+
"node": ">=14.0.0"
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file 基础模块
|
|
3
|
+
* @description 提供基础模块实现,作为所有功能模块的基类
|
|
4
|
+
* @module core/base-module
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { EventEmitter } from './event-emitter';
|
|
8
|
+
import { Logger } from './logger';
|
|
9
|
+
import { Module } from './module-manager';
|
|
10
|
+
import { VERSION } from '../version';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 基础模块类
|
|
14
|
+
* 提供模块的基本功能和生命周期管理
|
|
15
|
+
*/
|
|
16
|
+
export abstract class BaseModule extends EventEmitter implements Module {
|
|
17
|
+
/** 模块名称 */
|
|
18
|
+
public abstract readonly name: string;
|
|
19
|
+
|
|
20
|
+
/** 模块版本 */
|
|
21
|
+
public readonly version: string = VERSION;
|
|
22
|
+
|
|
23
|
+
/** 模块是否已初始化 */
|
|
24
|
+
protected _isInitialized: boolean = false;
|
|
25
|
+
|
|
26
|
+
/** 日志工具 */
|
|
27
|
+
protected logger: Logger;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 构造函数
|
|
31
|
+
*/
|
|
32
|
+
constructor() {
|
|
33
|
+
super();
|
|
34
|
+
this.logger = Logger.getInstance();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 获取模块是否已初始化
|
|
39
|
+
*/
|
|
40
|
+
public get isInitialized(): boolean {
|
|
41
|
+
return this._isInitialized;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 初始化模块
|
|
46
|
+
* 子类必须实现此方法
|
|
47
|
+
*/
|
|
48
|
+
public abstract initialize(): Promise<void>;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 释放模块资源
|
|
52
|
+
* 子类可以覆盖此方法以添加额外的资源释放逻辑
|
|
53
|
+
*/
|
|
54
|
+
public async dispose(): Promise<void> {
|
|
55
|
+
if (!this._isInitialized) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
this.logger.debug(this.name, '释放模块资源');
|
|
60
|
+
|
|
61
|
+
// 重置初始化状态
|
|
62
|
+
this._isInitialized = false;
|
|
63
|
+
|
|
64
|
+
// 删除所有事件监听器
|
|
65
|
+
this.removeAllListeners();
|
|
66
|
+
|
|
67
|
+
this.logger.debug(this.name, '模块资源已释放');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 检查模块是否已初始化,如果未初始化则抛出错误
|
|
72
|
+
*/
|
|
73
|
+
protected ensureInitialized(): void {
|
|
74
|
+
if (!this._isInitialized) {
|
|
75
|
+
throw new Error(`模块 ${this.name} 尚未初始化`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|