@digipair/skill-web-pdf 0.89.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-pdf",
3
- "version": "0.89.0",
3
+ "version": "0.91.0-0",
4
+ "type": "module",
5
+ "main": "dist/libs/skill-web-pdf/index.cjs.js",
6
+ "module": "dist/libs/skill-web-pdf/index.esm.js",
7
+ "types": "dist/libs/skill-web-pdf/index.esm.d.ts",
8
+ "exports": {
9
+ "./package.json": "./libs/skill-web-pdf/package.json",
10
+ ".": {
11
+ "development": "./dist/libs/skill-web-pdf/src/index.ts",
12
+ "types": "./dist/libs/skill-web-pdf/index.esm.d.ts",
13
+ "import": "./dist/libs/skill-web-pdf/index.esm.js",
14
+ "default": "./dist/libs/skill-web-pdf/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-pdf"
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-pdf/src/index.ts',
6
+ outputPath: 'dist/libs/skill-web-pdf',
7
+ tsConfig: 'libs/skill-web-pdf/tsconfig.lib.json',
8
+ compiler: 'swc',
9
+ format: ['esm', "cjs"],
10
+ assets: [
11
+ {
12
+ input: 'libs/skill-web-pdf/',
13
+ glob: 'package.json',
14
+ output: '.'
15
+ },
16
+ {
17
+ input: 'libs/skill-web-pdf/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,126 @@
1
+ import { LitElement, TemplateResult, css, html } from 'lit';
2
+ import { customElement, property, state } from 'lit/decorators.js';
3
+
4
+ @customElement('digipair-input-pdf')
5
+ export class InputPdfElement extends LitElement {
6
+ @property()
7
+ label = 'Upload';
8
+
9
+ @property()
10
+ accept = '.pdf';
11
+
12
+ @property()
13
+ required = true;
14
+
15
+ @state()
16
+ private state = 'unloaded';
17
+
18
+ @state()
19
+ private _content = 'aucun fichier selectionne';
20
+ get content() {
21
+ return this._content;
22
+ }
23
+
24
+ private _value: string | ArrayBuffer = '';
25
+ get value(): string | ArrayBuffer {
26
+ return 'NOEVAL:' + this._value;
27
+ }
28
+
29
+ static override styles = css`
30
+ .download {
31
+ padding: 10px 15px;
32
+ margin-bottom: 10px;
33
+ line-height: 1.4;
34
+ border: 1px solid var(--digipair-color-primary, #52dfdb);
35
+ color: var(--digipair-color-primary, #52dfdb);
36
+ align-self: flex-start;
37
+ margin-right: auto;
38
+ text-align: center;
39
+ }
40
+
41
+ .download ui5-icon {
42
+ color: var(--digipair-color-secondary, #52dfdb);
43
+ }
44
+
45
+ .download.unloaded ui5-icon {
46
+ color: var(--digipair-color-primary, #52dfdb);
47
+ }
48
+
49
+ .download p {
50
+ text-align: center;
51
+ font-size: 12px;
52
+ margin: 0;
53
+ }
54
+
55
+ .download.unloaded {
56
+ cursor: pointer;
57
+ }
58
+
59
+ .download.loaded ui5-icon {
60
+ float: left;
61
+ }
62
+ `;
63
+
64
+ private loadFile() {
65
+ const input = document.createElement('input');
66
+ input.type = 'file';
67
+ input.multiple = false;
68
+ input.accept = this.accept;
69
+ input.onchange = async (event: any) => {
70
+ const files = event.target.files;
71
+ const file = files[0];
72
+
73
+ this.state = 'loading';
74
+
75
+ const reader = new FileReader();
76
+ reader.readAsArrayBuffer(file);
77
+ reader.onload = async () => {
78
+ const typeArray = new Uint8Array(reader.result as ArrayBuffer);
79
+
80
+ this._value = await this.extractText(typeArray);
81
+ this._content = `> ${file.name}`;
82
+ this.state = 'loaded';
83
+ this.dispatchEvent(new CustomEvent('change', { detail: { value: this.value } }));
84
+ };
85
+ };
86
+ input.click();
87
+ }
88
+
89
+ private async extractText(file: Uint8Array): Promise<string> {
90
+ const globalInstance: any = typeof window === 'undefined' ? global : window;
91
+ const config = globalInstance.__DIGIPAIR_CONFIG__;
92
+ const version = 'latest';
93
+ const pdfjs = await import(`${config.BASE_URL}/pdfjs-dist@${version}/build/pdf.min.mjs`);
94
+ pdfjs.GlobalWorkerOptions.workerSrc = `${config.BASE_URL}/pdfjs-dist@${version}/build/pdf.worker.min.mjs`;
95
+ const pdf = await pdfjs.getDocument(file).promise;
96
+ let text = '';
97
+
98
+ for (let i = 1; i <= pdf.numPages; i++) {
99
+ const page = await pdf.getPage(i);
100
+ const textContent = await page.getTextContent();
101
+
102
+ textContent.items.forEach(function (item: any) {
103
+ text += item.str + ' ';
104
+ });
105
+ }
106
+
107
+ return text;
108
+ }
109
+
110
+ override render(): TemplateResult {
111
+ return html`
112
+ <section
113
+ class="download ${this.state}"
114
+ @click=${() => (['unloaded', 'loaded'].indexOf(this.state) >= 0 ? this.loadFile() : void 0)}
115
+ >
116
+ ${this.state === 'loaded'
117
+ ? html` <ui5-icon name="attachment"></ui5-icon>
118
+ <p>${this.label}<br />${this._content}</p>`
119
+ : this.state === 'loading'
120
+ ? html`<ui5-busy-indicator size="Small" active></ui5-busy-indicator>`
121
+ : html` <ui5-icon name="add-document"></ui5-icon>
122
+ <p>${this.label}</p>`}
123
+ </section>
124
+ `;
125
+ }
126
+ }
@@ -0,0 +1,7 @@
1
+ import { skillWebPdf } from './skill-web-pdf';
2
+
3
+ describe('skillWebPdf', () => {
4
+ it('should work', () => {
5
+ expect(skillWebPdf()).toEqual('skill-web-pdf');
6
+ });
7
+ });
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";