@digipair/skill-web-ocr 0.90.0 → 0.91.0-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/.swcrc ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "jsc": {
3
+ "target": "es2017",
4
+ "parser": {
5
+ "syntax": "typescript",
6
+ "decorators": true,
7
+ "dynamicImport": true
8
+ },
9
+ "transform": {
10
+ "decoratorMetadata": true,
11
+ "legacyDecorator": true
12
+ },
13
+ "keepClassNames": true,
14
+ "externalHelpers": true,
15
+ "loose": true
16
+ },
17
+ "module": {
18
+ "type": "es6"
19
+ },
20
+ "sourceMaps": true,
21
+ "exclude": [
22
+ "jest.config.ts",
23
+ ".*\\.spec.tsx?$",
24
+ ".*\\.test.tsx?$",
25
+ "./src/jest-setup.ts$",
26
+ "./**/jest-setup.ts$"
27
+ ]
28
+ }
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # mylib
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build mylib` to build the library.
@@ -0,0 +1,22 @@
1
+ import baseConfig from '../../eslint.config.mjs';
2
+
3
+ export default [
4
+ ...baseConfig,
5
+ {
6
+ files: ['**/*.json'],
7
+ rules: {
8
+ '@nx/dependency-checks': [
9
+ 'error',
10
+ {
11
+ ignoredFiles: [
12
+ '{projectRoot}/eslint.config.{js,cjs,mjs}',
13
+ '{projectRoot}/rollup.config.{js,ts,mjs,mts,cjs,cts}',
14
+ ],
15
+ },
16
+ ],
17
+ },
18
+ languageOptions: {
19
+ parser: await import('jsonc-eslint-parser'),
20
+ },
21
+ },
22
+ ];
package/package.json CHANGED
@@ -1,12 +1,28 @@
1
1
  {
2
2
  "name": "@digipair/skill-web-ocr",
3
- "version": "0.90.0",
3
+ "version": "0.91.0-0",
4
+ "type": "module",
5
+ "main": "dist/libs/skill-web-ocr/index.cjs.js",
6
+ "module": "dist/libs/skill-web-ocr/index.esm.js",
7
+ "types": "dist/libs/skill-web-ocr/index.esm.d.ts",
8
+ "exports": {
9
+ "./package.json": "./libs/skill-web-ocr/package.json",
10
+ ".": {
11
+ "development": "./dist/libs/skill-web-ocr/src/index.ts",
12
+ "types": "./dist/libs/skill-web-ocr/index.esm.d.ts",
13
+ "import": "./dist/libs/skill-web-ocr/index.esm.js",
14
+ "default": "./dist/libs/skill-web-ocr/index.cjs.js"
15
+ }
16
+ },
4
17
  "keywords": [
5
18
  "digipair",
6
19
  "web",
7
20
  "util"
8
21
  ],
9
- "dependencies": {},
10
- "main": "./index.cjs.js",
11
- "module": "./index.esm.js"
12
- }
22
+ "nx": {
23
+ "name": "skill-web-ocr"
24
+ },
25
+ "dependencies": {
26
+ "@digipair/engine": "0.91.0-0"
27
+ }
28
+ }
@@ -0,0 +1,28 @@
1
+ const { withNx } = require('@nx/rollup/with-nx');
2
+
3
+ module.exports = withNx(
4
+ {
5
+ main: 'libs/skill-web-ocr/src/index.ts',
6
+ outputPath: 'dist/libs/skill-web-ocr',
7
+ tsConfig: 'libs/skill-web-ocr/tsconfig.lib.json',
8
+ compiler: 'swc',
9
+ format: ['esm', "cjs"],
10
+ assets: [
11
+ {
12
+ input: 'libs/skill-web-ocr/',
13
+ glob: 'package.json',
14
+ output: '.'
15
+ },
16
+ {
17
+ input: 'libs/skill-web-ocr/src/',
18
+ glob: '*.json',
19
+ output: '.'
20
+ }
21
+ ]
22
+ },
23
+ {
24
+ // Provide additional rollup configuration here. See: https://rollupjs.org/configuration-options
25
+ // e.g.
26
+ // output: { sourcemap: true },
27
+ }
28
+ );
@@ -0,0 +1,47 @@
1
+ import { LitElement, TemplateResult, html } from 'lit';
2
+ import { customElement, property } from 'lit/decorators.js';
3
+ import tesseract from 'tesseract.js/dist/tesseract.esm.min.js';
4
+
5
+ @customElement('digipair-input-ocr-selector')
6
+ export class HiddenElement extends LitElement {
7
+ @property()
8
+ selector!: string;
9
+
10
+ @property()
11
+ language = 'eng';
12
+
13
+ @property()
14
+ required = true;
15
+
16
+ private _value: string | ArrayBuffer = '';
17
+ get value(): string | ArrayBuffer {
18
+ return this._value;
19
+ }
20
+
21
+ override connectedCallback(): void {
22
+ super.connectedCallback();
23
+ this.initialize();
24
+ }
25
+
26
+ private async initialize(): Promise<void> {
27
+ const img = document.querySelector(this.selector) as HTMLImageElement;
28
+ if (img) {
29
+ this._value = await this.analyzeFile(img);
30
+ this.dispatchEvent(new CustomEvent('change', { detail: { value: this.value } }));
31
+ }
32
+ }
33
+
34
+ private async analyzeFile(file: any): Promise<string> {
35
+ const worker = await tesseract.createWorker(this.language);
36
+ const {
37
+ data: { text },
38
+ } = await worker.recognize(file);
39
+ await worker.terminate();
40
+
41
+ return text;
42
+ }
43
+
44
+ override render(): TemplateResult {
45
+ return html``;
46
+ }
47
+ }
@@ -0,0 +1,112 @@
1
+ import { LitElement, TemplateResult, css, html } from 'lit';
2
+ import { customElement, property, state } from 'lit/decorators.js';
3
+ import tesseract from 'tesseract.js/dist/tesseract.esm.min.js';
4
+
5
+ @customElement('digipair-input-ocr')
6
+ export class InputOcrElement extends LitElement {
7
+ @property()
8
+ label = 'Upload';
9
+
10
+ @property()
11
+ language = 'eng';
12
+
13
+ @property()
14
+ accept = 'image/*';
15
+
16
+ @property()
17
+ required = true;
18
+
19
+ @state()
20
+ private state = 'unloaded';
21
+
22
+ @state()
23
+ private _content = 'aucun fichier selectionne';
24
+ get content() {
25
+ return this._content;
26
+ }
27
+
28
+ private _value: string | ArrayBuffer = '';
29
+ get value(): string | ArrayBuffer {
30
+ return this._value;
31
+ }
32
+
33
+ static override styles = css`
34
+ .download {
35
+ padding: 10px 15px;
36
+ margin-bottom: 10px;
37
+ line-height: 1.4;
38
+ border: 1px solid var(--digipair-color-primary, #52dfdb);
39
+ color: var(--digipair-color-primary, #52dfdb);
40
+ align-self: flex-start;
41
+ margin-right: auto;
42
+ text-align: center;
43
+ }
44
+
45
+ .download ui5-icon {
46
+ color: var(--digipair-color-secondary, #52dfdb);
47
+ }
48
+
49
+ .download.unloaded ui5-icon {
50
+ color: var(--digipair-color-primary, #52dfdb);
51
+ }
52
+
53
+ .download p {
54
+ text-align: center;
55
+ font-size: 12px;
56
+ margin: 0;
57
+ }
58
+
59
+ .download.unloaded {
60
+ cursor: pointer;
61
+ }
62
+
63
+ .download.loaded ui5-icon {
64
+ float: left;
65
+ }
66
+ `;
67
+
68
+ private loadFile() {
69
+ const input = document.createElement('input');
70
+ input.type = 'file';
71
+ input.multiple = false;
72
+ input.accept = this.accept;
73
+ input.onchange = async (event: any) => {
74
+ const files = event.target.files;
75
+ const file = files[0];
76
+
77
+ this.state = 'loading';
78
+ this._value = await this.analyzeFile(file);
79
+ this._content = `> ${file.name}`;
80
+ this.state = 'loaded';
81
+ this.dispatchEvent(new CustomEvent('change', { detail: { value: this.value } }));
82
+ };
83
+ input.click();
84
+ }
85
+
86
+ private async analyzeFile(file: any): Promise<string> {
87
+ const worker = await tesseract.createWorker(this.language);
88
+ const {
89
+ data: { text },
90
+ } = await worker.recognize(file);
91
+ await worker.terminate();
92
+
93
+ return text;
94
+ }
95
+
96
+ override render(): TemplateResult {
97
+ return html`
98
+ <section
99
+ class="download ${this.state}"
100
+ @click=${() => (['unloaded', 'loaded'].indexOf(this.state) >= 0 ? this.loadFile() : void 0)}
101
+ >
102
+ ${this.state === 'loaded'
103
+ ? html` <ui5-icon name="attachment"></ui5-icon>
104
+ <p>${this.label}<br />${this._content}</p>`
105
+ : this.state === 'loading'
106
+ ? html`<ui5-busy-indicator size="Small" active></ui5-busy-indicator>`
107
+ : html` <ui5-icon name="add-document"></ui5-icon>
108
+ <p>${this.label}</p>`}
109
+ </section>
110
+ `;
111
+ }
112
+ }
@@ -0,0 +1,7 @@
1
+ import { skillWebOcr } from './skill-web-ocr';
2
+
3
+ describe('skillWebOcr', () => {
4
+ it('should work', () => {
5
+ expect(skillWebOcr()).toEqual('skill-web-ocr');
6
+ });
7
+ });
@@ -0,0 +1 @@
1
+ declare module 'tesseract.js/dist/tesseract.esm.min.js';
package/tsconfig.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "files": [],
4
+ "include": [],
5
+ "references": [
6
+ {
7
+ "path": "../engine"
8
+ },
9
+ {
10
+ "path": "./tsconfig.lib.json"
11
+ }
12
+ ]
13
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist",
6
+ "tsBuildInfoFile": "dist/tsconfig.lib.tsbuildinfo",
7
+ "emitDeclarationOnly": true,
8
+ "module": "esnext",
9
+ "moduleResolution": "node",
10
+ "forceConsistentCasingInFileNames": true,
11
+ "types": ["node"]
12
+ },
13
+ "include": ["src/**/*.ts"],
14
+ "references": [
15
+ {
16
+ "path": "../engine/tsconfig.lib.json"
17
+ }
18
+ ]
19
+ }
package/index.cjs.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./src/index";