@operato/ocr 0.2.19 → 0.2.20

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.20",
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": "7142b87dbb0923c5f0efb95fedf3363a336092d8"
72
72
  }
@@ -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
+
61
+ @state() _files: any
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
68
  const files = this._files || []
65
- const index = this.index || 0
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>
@@ -89,16 +94,20 @@ export class OcrHelper extends LitElement {
89
94
  const item = (e.target as HTMLElement)?.closest('[i]')
90
95
  const children = (e.currentTarget as HTMLElement)?.querySelectorAll('[i]')
91
96
  if (item) {
92
- this.index = Array.from(children).indexOf(item)
97
+ this._index = Array.from(children).indexOf(item)
93
98
  }
94
99
  }}
95
100
  >
96
101
  ${files.map((file: any, idx: number) => html`<div i ?active=${idx === index}>${idx}</div>`)}
97
102
  </div>
98
- <ox-ocr-result-image .file=${file} @selected=${(e: CustomEvent) => this.onSelected(e)}></ox-ocr-result-image>
103
+ <ox-ocr-result-image
104
+ .file=${file}
105
+ @selected=${(e: CustomEvent) => this.onSelected(e)}
106
+ .result=${result}
107
+ ></ox-ocr-result-image>
99
108
  </div>
100
109
 
101
- <div id="result"></div>
110
+ <div id="copied"></div>
102
111
  `
103
112
  }
104
113
 
@@ -108,7 +117,7 @@ export class OcrHelper extends LitElement {
108
117
 
109
118
  reset() {
110
119
  this.fileUploader.reset()
111
- this.result.textContent = ''
120
+ this.copied.textContent = ''
112
121
  }
113
122
 
114
123
  onSelected(e: CustomEvent) {
@@ -121,21 +130,5 @@ export class OcrHelper extends LitElement {
121
130
  detail: this.fileUploader?.files
122
131
  })
123
132
  )
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
133
  }
141
134
  }