@operato/ocr 0.2.19 → 0.2.23

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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Webcomponent ocr following open-wc recommendations",
4
4
  "license": "MIT",
5
5
  "author": "heartyoh@hatiolab.com",
6
- "version": "0.2.19",
6
+ "version": "0.2.23",
7
7
  "main": "dist/src/index.js",
8
8
  "module": "dist/src/index.js",
9
9
  "publishConfig": {
@@ -68,5 +68,5 @@
68
68
  "prettier --write"
69
69
  ]
70
70
  },
71
- "gitHead": "5d37e55fbed0193831675a3d5fcc941e33083bc9"
71
+ "gitHead": "dac60531adc2e2583937eef3945c8aee3daa0958"
72
72
  }
@@ -1,7 +1,7 @@
1
1
  import '@material/mwc-icon'
2
2
 
3
3
  import { css, html, LitElement } from 'lit'
4
- import { customElement, property, query } from 'lit/decorators.js'
4
+ import { customElement, property, query, state } from 'lit/decorators.js'
5
5
 
6
6
  import { FileDropHelper } from './utils/file-drop-helper'
7
7
 
@@ -81,7 +81,12 @@ export class CameraCapturer extends LitElement {
81
81
  @property({ type: Boolean }) multiple?: boolean
82
82
  @property({ type: String }) accept?: string
83
83
  @property({ type: String }) label?: string
84
- @property({ type: Array }) _files?: File[]
84
+ @property({ type: Boolean, reflect: true, attribute: 'hide-filelist' })
85
+ hideFileList: boolean = false
86
+ @property({ type: Boolean, reflect: true, attribute: 'attach-filelist' })
87
+ attachFileList: boolean = false
88
+
89
+ @state() _files?: File[]
85
90
 
86
91
  render() {
87
92
  var files = this._files || []
@@ -99,7 +104,9 @@ export class CameraCapturer extends LitElement {
99
104
  @change=${(e: Event) => {
100
105
  const fileInput = e.currentTarget as HTMLInputElement
101
106
 
102
- this._files = [...files, ...Array.from(fileInput.files as FileList)]
107
+ this._files = this.attachFileList
108
+ ? [...files, ...Array.from(fileInput.files as FileList)]
109
+ : [...Array.from(fileInput.files as FileList)]
103
110
 
104
111
  this.dispatchEvent(
105
112
  new CustomEvent('files-change', {
@@ -115,9 +122,9 @@ export class CameraCapturer extends LitElement {
115
122
  fileInput.files = null
116
123
  }}
117
124
  />
118
- <!-- <label for="input-file">${this.label || 'capture image'}</label> -->
125
+ <label for="input-file">${this.label || 'capture image'}</label>
119
126
 
120
- ${files?.length
127
+ ${!this.hideFileList && files?.length
121
128
  ? html` <ul>
122
129
  ${files.map(
123
130
  file => html`
@@ -143,7 +150,7 @@ export class CameraCapturer extends LitElement {
143
150
  `
144
151
  )}
145
152
  </ul>`
146
- : ''}
153
+ : html``}
147
154
  `
148
155
  }
149
156
 
@@ -3,7 +3,9 @@ import './ox-camera-capturer'
3
3
  import './ox-ocr-result-image'
4
4
 
5
5
  import { css, html, LitElement } from 'lit'
6
- import { customElement, property, query } from 'lit/decorators.js'
6
+ import { customElement, property, query, state } from 'lit/decorators.js'
7
+
8
+ import { NOTHING_RESULT, ScanResult } from './type'
7
9
 
8
10
  @customElement('ox-ocr-helper')
9
11
  export class OcrHelper extends LitElement {
@@ -54,16 +56,19 @@ export class OcrHelper extends LitElement {
54
56
  `
55
57
  ]
56
58
 
57
- @property({ type: Array }) _files: any
58
- @property({ type: Number }) index: number = 0
59
+ @property({ type: Array }) result: ScanResult[] = []
60
+ @property({ type: Array }) files: Array<any> = []
61
+
62
+ @state() _index: number = 0
59
63
 
60
64
  @query('#capturer') fileUploader!: any
61
- @query('#result') result!: any
65
+ @query('#copied') copied!: HTMLElement
62
66
 
63
67
  render() {
64
- const files = this._files || []
65
- const index = this.index || 0
68
+ const files = this.files || []
69
+ const index = this._index || 0
66
70
  const file = files[index]
71
+ const result = this.result?.[index] || NOTHING_RESULT
67
72
 
68
73
  return html`
69
74
  <div attachment-wrap>
@@ -76,12 +81,9 @@ export class OcrHelper extends LitElement {
76
81
  ?hidden=${false}
77
82
  custom-input
78
83
  @files-change=${(e: Event) => this.fileschange(e)}
84
+ hide-filelist
79
85
  ></ox-camera-capturer>
80
86
  </div>
81
- <div buttons>
82
- <mwc-button @click=${(e: Event) => this.submit()}>submit</mwc-button>
83
- <mwc-button @click=${(e: Event) => this.reset()}>reset</mwc-button>
84
- </div>
85
87
  <div id="images">
86
88
  <div
87
89
  tab
@@ -89,53 +91,39 @@ export class OcrHelper extends LitElement {
89
91
  const item = (e.target as HTMLElement)?.closest('[i]')
90
92
  const children = (e.currentTarget as HTMLElement)?.querySelectorAll('[i]')
91
93
  if (item) {
92
- this.index = Array.from(children).indexOf(item)
94
+ this._index = Array.from(children).indexOf(item)
93
95
  }
94
96
  }}
95
97
  >
96
98
  ${files.map((file: any, idx: number) => html`<div i ?active=${idx === index}>${idx}</div>`)}
97
99
  </div>
98
- <ox-ocr-result-image .file=${file} @selected=${(e: CustomEvent) => this.onSelected(e)}></ox-ocr-result-image>
100
+ <ox-ocr-result-image
101
+ .file=${file}
102
+ @selected=${(e: CustomEvent) => this.onSelected(e)}
103
+ .result=${result}
104
+ ></ox-ocr-result-image>
99
105
  </div>
100
106
 
101
- <div id="result"></div>
107
+ <div id="copied"></div>
102
108
  `
103
109
  }
104
110
 
105
111
  fileschange(e: Event) {
106
- this._files = this.fileUploader.files
112
+ this.files = this.fileUploader.files
113
+
114
+ this.dispatchEvent(
115
+ new CustomEvent('attached', {
116
+ detail: this.fileUploader?.files
117
+ })
118
+ )
107
119
  }
108
120
 
109
121
  reset() {
110
122
  this.fileUploader.reset()
111
- this.result.textContent = ''
123
+ this.copied.textContent = ''
112
124
  }
113
125
 
114
126
  onSelected(e: CustomEvent) {
115
127
  navigator.clipboard.writeText(e.detail)
116
128
  }
117
-
118
- async submit() {
119
- this.dispatchEvent(
120
- new CustomEvent('attached', {
121
- detail: this.fileUploader?.files
122
- })
123
- )
124
- // const response = await client.query({
125
- // query: gql`
126
- // query ocrRequest($images: [Upload!]!) {
127
- // ocrRequest(images: $images)
128
- // }
129
- // `,
130
- // variables: {
131
- // images: this.fileUploader?.files
132
- // },
133
- // context: { hasUpload: true }
134
- // })
135
- // if (!response.errors) {
136
- // this.result.textContent = response.data.ocrRequest
137
- // } else {
138
- // this.result.textContent = 'error'
139
- // }
140
- }
141
129
  }