@operato/ocr 0.2.9 → 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.
Files changed (44) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/demo/index.html +699 -25
  3. package/dist/src/index.d.ts +1 -1
  4. package/dist/src/index.js +1 -1
  5. package/dist/src/index.js.map +1 -1
  6. package/dist/src/ox-camera-capturer.d.ts +14 -0
  7. package/dist/src/ox-camera-capturer.js +178 -0
  8. package/dist/src/ox-camera-capturer.js.map +1 -0
  9. package/dist/src/{ocr-helper.d.ts → ox-ocr-helper.d.ts} +8 -4
  10. package/dist/src/{ocr-helper.js → ox-ocr-helper.js} +47 -51
  11. package/dist/src/ox-ocr-helper.js.map +1 -0
  12. package/dist/src/ox-ocr-result-image.d.ts +37 -0
  13. package/dist/src/ox-ocr-result-image.js +279 -0
  14. package/dist/src/ox-ocr-result-image.js.map +1 -0
  15. package/dist/src/type.d.ts +15 -0
  16. package/dist/src/type.js +6 -0
  17. package/dist/src/type.js.map +1 -0
  18. package/dist/src/utils/file-drop-helper.d.ts +16 -0
  19. package/dist/src/utils/file-drop-helper.js +47 -0
  20. package/dist/src/utils/file-drop-helper.js.map +1 -0
  21. package/dist/src/utils/touch-to-mouse-event.d.ts +1 -0
  22. package/dist/src/utils/touch-to-mouse-event.js +34 -0
  23. package/dist/src/utils/touch-to-mouse-event.js.map +1 -0
  24. package/dist/stories/index.stories.d.ts +1 -1
  25. package/dist/stories/index.stories.js +10 -14
  26. package/dist/stories/index.stories.js.map +1 -1
  27. package/dist/test/ox-ocr-helper.test.d.ts +1 -0
  28. package/dist/test/{ocr-helper.test.js → ox-ocr-helper.test.js} +7 -7
  29. package/dist/test/ox-ocr-helper.test.js.map +1 -0
  30. package/dist/tsconfig.tsbuildinfo +1 -1
  31. package/package.json +4 -27
  32. package/src/index.ts +1 -1
  33. package/src/ox-camera-capturer.ts +189 -0
  34. package/src/{ocr-helper.ts → ox-ocr-helper.ts} +43 -49
  35. package/src/ox-ocr-result-image.ts +303 -0
  36. package/src/type.ts +13 -0
  37. package/src/utils/file-drop-helper.ts +62 -0
  38. package/src/utils/touch-to-mouse-event.ts +39 -0
  39. package/stories/index.stories.ts +29 -37
  40. package/test/{ocr-helper.test.ts → ox-ocr-helper.test.ts} +8 -7
  41. package/dist/src/ocr-helper.js.map +0 -1
  42. package/dist/test/ocr-helper.test.d.ts +0 -1
  43. package/dist/test/ocr-helper.test.js.map +0 -1
  44. package/src/camera-capturer.js +0 -184
@@ -0,0 +1,62 @@
1
+ /**
2
+ * judge callback function for FileDropHelper.set
3
+ */
4
+ type JudgeCallback = () => boolean
5
+
6
+ /**
7
+ * file drop assist class
8
+ */
9
+ export class FileDropHelper {
10
+ /**
11
+ * 파일 드롭 영역에서의 file drag&drop과 관련된 이벤트에 대한 처리를 설정한다.
12
+ * @param dropArea file drag&drop target area
13
+ * @param [judge] file drag&drop과 관련된 이벤트에 대한 judge callback function
14
+ */
15
+ static set(dropArea: HTMLElement, judge?: JudgeCallback) {
16
+ var preventDefaults = (e: Event) => {
17
+ if (!judge || judge()) {
18
+ e.preventDefault()
19
+ e.stopPropagation()
20
+ }
21
+ }
22
+
23
+ var highlight = (e: Event) => {
24
+ if (!judge || judge()) {
25
+ dropArea.classList.add('candrop')
26
+ }
27
+ }
28
+
29
+ var unhighlight = (e: Event) => {
30
+ if (!judge || judge()) {
31
+ dropArea.classList.remove('candrop')
32
+ }
33
+ }
34
+
35
+ ;['dragenter', 'dragover', 'dragleave', 'drop'].forEach(event => {
36
+ dropArea.addEventListener(event, preventDefaults, false)
37
+ })
38
+ ;['dragenter', 'dragover'].forEach(event => {
39
+ dropArea.addEventListener(event, highlight, false)
40
+ })
41
+ ;['dragleave', 'drop'].forEach(event => {
42
+ dropArea.addEventListener(event, unhighlight, false)
43
+ })
44
+
45
+ dropArea.addEventListener(
46
+ 'drop',
47
+ e => {
48
+ if (!judge || judge()) {
49
+ let dt = e.dataTransfer!
50
+ let files = dt.files
51
+
52
+ dropArea.dispatchEvent(
53
+ new CustomEvent('file-drop', {
54
+ detail: [...Array.from(files)]
55
+ })
56
+ )
57
+ }
58
+ },
59
+ false
60
+ )
61
+ }
62
+ }
@@ -0,0 +1,39 @@
1
+ export function touch2mouse(e: TouchEvent) {
2
+ e.preventDefault()
3
+
4
+ if (e.touches.length > 1 || (e.type == 'touchend' && e.touches.length > 0)) {
5
+ return
6
+ }
7
+
8
+ var type = ''
9
+ const touch = e.changedTouches[0]
10
+
11
+ switch (e.type) {
12
+ case 'touchstart':
13
+ type = 'mousedown'
14
+ break
15
+ case 'touchmove':
16
+ type = 'mousemove'
17
+ break
18
+ case 'touchend':
19
+ type = 'mouseup'
20
+ break
21
+ }
22
+
23
+ const { screenX, screenY, clientX, clientY } = touch
24
+ const { ctrlKey, altKey, shiftKey, metaKey } = e
25
+
26
+ e.target?.dispatchEvent(
27
+ new MouseEvent(type, {
28
+ screenX,
29
+ screenY,
30
+ clientX,
31
+ clientY,
32
+ ctrlKey,
33
+ altKey,
34
+ shiftKey,
35
+ metaKey,
36
+ button: 0
37
+ })
38
+ )
39
+ }
@@ -1,60 +1,52 @@
1
- import { html, TemplateResult } from 'lit';
2
- import '../src/ocr-helper.js';
1
+ import '../src/ox-ocr-helper.js'
2
+
3
+ import { html, TemplateResult } from 'lit'
3
4
 
4
5
  export default {
5
6
  title: 'OcrHelper',
6
- component: 'ocr-helper',
7
+ component: 'ox-ocr-helper',
7
8
  argTypes: {
8
9
  title: { control: 'text' },
9
10
  counter: { control: 'number' },
10
- textColor: { control: 'color' },
11
- },
12
- };
11
+ textColor: { control: 'color' }
12
+ }
13
+ }
13
14
 
14
15
  interface Story<T> {
15
- (args: T): TemplateResult;
16
- args?: Partial<T>;
17
- argTypes?: Record<string, unknown>;
16
+ (args: T): TemplateResult
17
+ args?: Partial<T>
18
+ argTypes?: Record<string, unknown>
18
19
  }
19
20
 
20
21
  interface ArgTypes {
21
- title?: string;
22
- counter?: number;
23
- textColor?: string;
24
- slot?: TemplateResult;
22
+ title?: string
23
+ counter?: number
24
+ textColor?: string
25
+ slot?: TemplateResult
25
26
  }
26
27
 
27
- const Template: Story<ArgTypes> = ({
28
- title = 'Hello world',
29
- counter = 5,
30
- textColor,
31
- slot,
32
- }: ArgTypes) => html`
33
- <ocr-helper
34
- style="--ocr-helper-text-color: ${textColor || 'black'}"
35
- .title=${title}
36
- .counter=${counter}
37
- >
28
+ const Template: Story<ArgTypes> = ({ title = 'Hello world', counter = 5, textColor, slot }: ArgTypes) => html`
29
+ <ocr-helper style="--ocr-helper-text-color: ${textColor || 'black'}" .title=${title} .counter=${counter}>
38
30
  ${slot}
39
31
  </ocr-helper>
40
- `;
32
+ `
41
33
 
42
- export const Regular = Template.bind({});
34
+ export const Regular = Template.bind({})
43
35
 
44
- export const CustomTitle = Template.bind({});
36
+ export const CustomTitle = Template.bind({})
45
37
  CustomTitle.args = {
46
- title: 'My title',
47
- };
38
+ title: 'My title'
39
+ }
48
40
 
49
- export const CustomCounter = Template.bind({});
41
+ export const CustomCounter = Template.bind({})
50
42
  CustomCounter.args = {
51
- counter: 123456,
52
- };
43
+ counter: 123456
44
+ }
53
45
 
54
- export const SlottedContent = Template.bind({});
46
+ export const SlottedContent = Template.bind({})
55
47
  SlottedContent.args = {
56
- slot: html`<p>Slotted content</p>`,
57
- };
48
+ slot: html`<p>Slotted content</p>`
49
+ }
58
50
  SlottedContent.argTypes = {
59
- slot: { table: { disable: true } },
60
- };
51
+ slot: { table: { disable: true } }
52
+ }
@@ -1,33 +1,34 @@
1
- import '../src/ocr-helper.js'
1
+ import '../src/ox-ocr-helper.js'
2
+
3
+ import { html } from 'lit'
2
4
 
3
5
  import { expect, fixture } from '@open-wc/testing'
4
6
 
5
- import { OcrHelper } from '../src/ocr-helper.js'
6
- import { html } from 'lit'
7
+ import { OcrHelper } from '../src/ox-ocr-helper.js'
7
8
 
8
9
  describe('OcrHelper', () => {
9
10
  it('has a default title "Hey there" and counter 5', async () => {
10
- const el = await fixture<OcrHelper>(html`<ocr-helper></ocr-helper>`)
11
+ const el = await fixture<OcrHelper>(html`<ox-ocr-helper></ox-ocr-helper>`)
11
12
 
12
13
  expect(el.title).to.equal('Hey there')
13
14
  // expect(el.counter).to.equal(5)
14
15
  })
15
16
 
16
17
  it('increases the counter on button click', async () => {
17
- const el = await fixture<OcrHelper>(html`<ocr-helper></ocr-helper>`)
18
+ const el = await fixture<OcrHelper>(html`<ox-ocr-helper></ox-ocr-helper>`)
18
19
  el.shadowRoot!.querySelector('button')!.click()
19
20
 
20
21
  // expect(el.counter).to.equal(6)
21
22
  })
22
23
 
23
24
  it('can override the title via attribute', async () => {
24
- const el = await fixture<OcrHelper>(html`<ocr-helper title="attribute title"></ocr-helper>`)
25
+ const el = await fixture<OcrHelper>(html`<ox-ocr-helper title="attribute title"></ox-ocr-helper>`)
25
26
 
26
27
  expect(el.title).to.equal('attribute title')
27
28
  })
28
29
 
29
30
  it('passes the a11y audit', async () => {
30
- const el = await fixture<OcrHelper>(html`<ocr-helper></ocr-helper>`)
31
+ const el = await fixture<OcrHelper>(html`<ox-ocr-helper></ox-ocr-helper>`)
31
32
 
32
33
  await expect(el).shadowDom.to.be.accessible()
33
34
  })
@@ -1 +0,0 @@
1
- {"version":3,"file":"ocr-helper.js","sourceRoot":"","sources":["../../src/ocr-helper.ts"],"names":[],"mappings":";AAAA,OAAO,mBAAmB,CAAA;AAC1B,OAAO,sBAAsB,CAAA;AAE7B,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAKlE,IAAa,SAAS,GAAtB,MAAa,SAAU,SAAQ,UAAU;IAAzC;;QAqD8B,UAAK,GAAW,CAAC,CAAA;IA6E/C,CAAC;IAxEC,MAAM;QACJ,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,IAAI,EAAE,C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,CAAC,CAAQ;QAClB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,CAAA;IACvC,CAAC;IAED,KAAK;QACH,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAA;QACzB,IAAI,CAAC,MAAM,CAAC,WAAW,GAAG,EAAE,CAAA;IAC9B,CAAC;IAED,KAAK,CAAC,MAAM;QACV,wCAAwC;QACxC,gBAAgB;QAChB,8CAA8C;QAC9C,oCAAoC;QACpC,QAAQ;QACR,OAAO;QACP,iBAAiB;QACjB,uCAAuC;QACvC,OAAO;QACP,iCAAiC;QACjC,KAAK;QACL,0BAA0B;QAC1B,uDAAuD;QACvD,WAAW;QACX,sCAAsC;QACtC,IAAI;IACN,CAAC;CACF,CAAA;AAjIQ,gBAAM,GAAG;IACd,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA+CF;CACF,CAAA;AAE0B;IAA1B,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;yCAAY;AACV;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;wCAAkB;AAEzB;IAAnB,KAAK,CAAC,WAAW,CAAC;+CAAmB;AACpB;IAAjB,KAAK,CAAC,SAAS,CAAC;yCAAa;AAxDnB,SAAS;IADrB,aAAa,CAAC,YAAY,CAAC;GACf,SAAS,CAkIrB;SAlIY,SAAS","sourcesContent":["import './camera-capturer'\nimport '@material/mwc-button'\n\nimport { LitElement, css, html } from 'lit'\nimport { customElement, property, query } from 'lit/decorators.js'\n\nimport { gql } from 'graphql-tag'\n\n@customElement('ocr-helper')\nexport class OcrHelper extends LitElement {\n static styles = [\n css`\n :host {\n display: flex;\n flex-direction: column;\n min-width: 240px;\n }\n\n [buttons] {\n display: flex;\n flex-direction: row-reverse;\n }\n\n #images {\n flex: 1;\n background-color: black;\n color: white;\n\n display: flex;\n flex-direction: column;\n }\n\n [tab] {\n display: flex;\n flex-direction: row;\n }\n\n [i] {\n min-width: 50px;\n background-color: black;\n text-align: center;\n }\n\n [i][active] {\n background-color: red;\n }\n\n [image] {\n flex: 1;\n\n display: flex;\n flex-direction: column;\n justify-content: center;\n }\n\n img {\n style=width: 100%;\n }\n `\n ]\n\n @property({ type: Array }) _files: any\n @property({ type: Number }) index: number = 0\n\n @query('#capturer') fileUploader!: any\n @query('#result') result!: any\n\n render() {\n const files = this._files || []\n const index = this.index || 0\n const file = files[index]\n const image = file && URL.createObjectURL(file)\n if (image) {\n requestAnimationFrame(() => URL.revokeObjectURL(image))\n }\n\n return html`\n <div attachment-wrap>\n <camera-capturer\n name=\"scanner\"\n id=\"capturer\"\n label=\"Capture Images\"\n accept=\"image/*\"\n multiple=\"true\"\n ?hidden=${false}\n custom-input\n @files-change=${(e: Event) => this.fileschange(e)}\n ></camera-capturer>\n </div>\n <div buttons>\n <mwc-button @click=${(e: Event) => this.upload()}>submit</mwc-button>\n <mwc-button @click=${(e: Event) => this.reset()}>reset</mwc-button>\n </div>\n <div id=\"images\">\n <div\n tab\n @click=${(e: MouseEvent) => {\n const item = (e.target as HTMLElement)?.closest('[i]')\n const children = (e.currentTarget as HTMLElement)?.querySelectorAll('[i]')\n if (item) {\n this.index = Array.from(children).indexOf(item)\n }\n }}\n >\n ${files.map((file: any, idx: number) => html`<div i ?active=${idx === index}>${idx}</div>`)}\n </div>\n <div image>${file ? html` <img src=${URL.createObjectURL(file)} /> ` : html``}</div>\n </div>\n <div id=\"result\"></div>\n `\n }\n\n fileschange(e: Event) {\n this._files = this.fileUploader.files\n }\n\n reset() {\n this.fileUploader.reset()\n this.result.textContent = ''\n }\n\n async upload() {\n // const response = await client.query({\n // query: gql`\n // query ocrRequest($images: [Upload!]!) {\n // ocrRequest(images: $images)\n // }\n // `,\n // variables: {\n // images: this.fileUploader?.files\n // },\n // context: { hasUpload: true }\n // })\n // if (!response.errors) {\n // this.result.textContent = response.data.ocrRequest\n // } else {\n // this.result.textContent = 'error'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EAAE,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,CAAC,UAAU,EAAE,CAAA;IAC/C,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import '../src/ocr-helper.js'\n\nimport { expect, fixture } from '@open-wc/testing'\n\nimport { OcrHelper } from '../src/ocr-helper.js'\nimport { html } from 'lit'\n\ndescribe('OcrHelper', () => {\n it('has a default title \"Hey there\" and counter 5', async () => {\n const el = await fixture<OcrHelper>(html`<ocr-helper></ocr-helper>`)\n\n expect(el.title).to.equal('Hey there')\n // expect(el.counter).to.equal(5)\n })\n\n it('increases the counter on button click', async () => {\n const el = await fixture<OcrHelper>(html`<ocr-helper></ocr-helper>`)\n el.shadowRoot!.querySelector('button')!.click()\n\n // expect(el.counter).to.equal(6)\n })\n\n it('can override the title via attribute', async () => {\n const el = await fixture<OcrHelper>(html`<ocr-helper title=\"attribute title\"></ocr-helper>`)\n\n expect(el.title).to.equal('attribute title')\n })\n\n it('passes the a11y audit', async () => {\n const el = await fixture<OcrHelper>(html`<ocr-helper></ocr-helper>`)\n\n await expect(el).shadowDom.to.be.accessible()\n })\n})\n"]}
@@ -1,184 +0,0 @@
1
- import { css, html, LitElement } from 'lit-element'
2
-
3
- import { FileDropHelper } from '@things-factory/utils'
4
-
5
- export class CameraCapturer extends LitElement {
6
- static get styles() {
7
- return [
8
- css`
9
- :host {
10
- display: flex;
11
- flex-direction: column;
12
- border-radius: var(--border-radius);
13
- text-align: center;
14
- padding-bottom: 5px !important;
15
- text-transform: capitalize;
16
-
17
- border: var(--file-uploader-border);
18
- background-color: var(--main-section-background-color);
19
- font: var(--file-uploader-font) !important;
20
- color: var(--file-uploader-color);
21
- }
22
- :host > mwc-icon {
23
- color: var(--file-uploader-icon-color);
24
- }
25
-
26
- :host(.candrop) {
27
- background-color: var(--file-uploader-candrop-background-color);
28
- }
29
-
30
- #input-file {
31
- display: none;
32
- }
33
-
34
- label {
35
- position: relative;
36
- width: auto;
37
- border: none;
38
- text-transform: capitalize;
39
-
40
- padding: var(--file-uploader-label-padding);
41
- border-radius: var(--file-uploader-label-border-radius);
42
- background-color: var(--file-uploader-label-background-color);
43
- color: var(--file-uploader-label-color);
44
- font: var(--file-uploader-label-font) !important;
45
- }
46
-
47
- ul {
48
- max-width: 500px;
49
- list-style: none;
50
- padding: 0;
51
- }
52
- li {
53
- text-align: left;
54
-
55
- padding: var(--file-uploader-li-padding);
56
- border-bottom: var(--file-uploader-li-border-bottom);
57
- }
58
- li mwc-icon {
59
- float: right;
60
- cursor: pointer;
61
- font: var(--file-uploader-li-icon-font);
62
- margin: var(--file-uploader-li-icon-margin);
63
- }
64
- li mwc-icon:hover,
65
- li mwc-icon:active {
66
- color: var(--file-uploader-li-icon-focus-color);
67
- }
68
- `
69
- ]
70
- }
71
-
72
- static get properties() {
73
- return {
74
- multiple: Boolean,
75
- accept: String,
76
- label: String,
77
- _files: Array
78
- }
79
- }
80
-
81
- render() {
82
- var files = this._files || []
83
-
84
- return html`
85
- <mwc-icon>camera</mwc-icon>
86
- <span>Capture image<br />or drop files here!</span>
87
- <input
88
- id="input-file"
89
- type="file"
90
- accept=${this.accept}
91
- ?multiple=${this.multiple}
92
- hidden
93
- capture="environment"
94
- @change=${e => {
95
- const fileInput = e.currentTarget
96
-
97
- this._files = [...files, ...Array.from(fileInput.files)]
98
-
99
- this.dispatchEvent(
100
- new CustomEvent('files-change', {
101
- bubbles: true,
102
- composed: true,
103
- detail: {
104
- files: files
105
- }
106
- })
107
- )
108
-
109
- fileInput.value = null
110
- }}
111
- />
112
- <label for="input-file">${this.label || 'capture image'}</label>
113
-
114
- ${files?.length
115
- ? html` <ul>
116
- ${files.map(
117
- file => html`
118
- <li>
119
- - ${file.name}
120
- <mwc-icon
121
- @click=${e => {
122
- this._files = [...this._files.splice(this._files.indexOf(file), 1)]
123
- this.dispatchEvent(
124
- new CustomEvent('files-change', {
125
- bubbles: true,
126
- composed: true,
127
- detail: {
128
- files: this._files
129
- }
130
- })
131
- )
132
- }}
133
- >delete_outline</mwc-icon
134
- >
135
- </li>
136
- `
137
- )}
138
- </ul>`
139
- : ''}
140
- `
141
- }
142
-
143
- firstUpdated() {
144
- FileDropHelper.set(this)
145
-
146
- this.addEventListener('file-drop', e => {
147
- this._files = this.multiple ? e.detail : e.detail[0] ? [e.detail[0]] : []
148
- this.dispatchEvent(
149
- new CustomEvent('files-change', {
150
- bubbles: true,
151
- composed: true,
152
- detail: {
153
- files: this._files
154
- }
155
- })
156
- )
157
- })
158
- }
159
-
160
- get fileInput() {
161
- return this.shadowRoot.querySelector('#input-file')
162
- }
163
-
164
- get files() {
165
- return this._files
166
- }
167
-
168
- reset() {
169
- this.fileInput.value = ''
170
- this._files = []
171
-
172
- this.dispatchEvent(
173
- new CustomEvent('files-change', {
174
- bubbles: true,
175
- composed: true,
176
- detail: {
177
- files: this._files
178
- }
179
- })
180
- )
181
- }
182
- }
183
-
184
- customElements.define('camera-capturer', CameraCapturer)