@operato/ocr 0.2.15 → 0.2.19
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/CHANGELOG.md +19 -0
- package/demo/index.html +35 -25
- package/dist/src/camera-capturer.js +2 -2
- package/dist/src/camera-capturer.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/ox-camera-capturer.d.ts +14 -0
- package/dist/src/ox-camera-capturer.js +178 -0
- package/dist/src/ox-camera-capturer.js.map +1 -0
- package/dist/src/{ocr-helper.d.ts → ox-ocr-helper.d.ts} +4 -2
- package/dist/src/{ocr-helper.js → ox-ocr-helper.js} +26 -25
- package/dist/src/ox-ocr-helper.js.map +1 -0
- package/dist/src/ox-ocr-result-image.d.ts +47 -0
- package/dist/src/ox-ocr-result-image.js +921 -0
- package/dist/src/ox-ocr-result-image.js.map +1 -0
- package/dist/src/utils/file-drop-helper.d.ts +16 -0
- package/dist/src/utils/file-drop-helper.js +47 -0
- package/dist/src/utils/file-drop-helper.js.map +1 -0
- package/dist/src/utils/touch-mouse-event.d.ts +0 -0
- package/dist/src/utils/touch-mouse-event.js +2 -0
- package/dist/src/utils/touch-mouse-event.js.map +1 -0
- package/dist/src/utils/touch-to-mouse-event.d.ts +1 -0
- package/dist/src/utils/touch-to-mouse-event.js +34 -0
- package/dist/src/utils/touch-to-mouse-event.js.map +1 -0
- package/dist/stories/index.stories.d.ts +1 -1
- package/dist/stories/index.stories.js +10 -14
- package/dist/stories/index.stories.js.map +1 -1
- package/dist/test/ox-ocr-helper.test.d.ts +1 -0
- package/dist/test/{ocr-helper.test.js → ox-ocr-helper.test.js} +7 -7
- package/dist/test/ox-ocr-helper.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -2
- package/src/index.ts +1 -1
- package/src/{camera-capturer.ts → ox-camera-capturer.ts} +18 -10
- package/src/{ocr-helper.ts → ox-ocr-helper.ts} +27 -26
- package/src/ox-ocr-result-image.ts +954 -0
- package/src/{file-drop-helper.ts → utils/file-drop-helper.ts} +0 -0
- package/src/utils/touch-to-mouse-event.ts +39 -0
- package/stories/index.stories.ts +29 -37
- package/test/{ocr-helper.test.ts → ox-ocr-helper.test.ts} +8 -7
- package/dist/src/ocr-helper.js.map +0 -1
- package/dist/test/ocr-helper.test.d.ts +0 -1
- package/dist/test/ocr-helper.test.js.map +0 -1
|
File without changes
|
|
@@ -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
|
+
}
|
package/stories/index.stories.ts
CHANGED
|
@@ -1,60 +1,52 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
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
|
-
|
|
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;;QAqD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G,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAA,EAAE;;;KAGhF,CAAA;IACH,CAAC;IAED,WAAW,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'\n // }\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import '../src/ocr-helper.js';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ocr-helper.test.js","sourceRoot":"","sources":["../../test/ocr-helper.test.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAA;AAE7B,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAGlD,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAA;AAE1B,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,EAAE,CAAC,+CAA+C,EAAE,KAAK,IAAI,EAAE;QAC7D,MAAM,EAAE,GAAG,MAAM,OAAO,CAAY,IAAI,CAAA,2BAA2B,CAAC,CAAA;QAEpE,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;QACtC,iCAAiC;IACnC,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,uCAAuC,EAAE,KAAK,IAAI,EAAE;QACrD,MAAM,EAAE,GAAG,MAAM,OAAO,CAAY,IAAI,CAAA,2BAA2B,CAAC,CAAA;QACpE,EAAE,CAAC,UAAW,CAAC,aAAa,CAAC,QAAQ,CAAE,CAAC,KAAK,EAAE,CAAA;QAE/C,iCAAiC;IACnC,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,sCAAsC,EAAE,KAAK,IAAI,EAAE;QACpD,MAAM,EAAE,GAAG,MAAM,OAAO,CAAY,IAAI,CAAA,mDAAmD,CAAC,CAAA;QAE5F,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAA;IAC9C,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,uBAAuB,EAAE,KAAK,IAAI,EAAE;QACrC,MAAM,EAAE,GAAG,MAAM,OAAO,CAAY,IAAI,CAAA,2BAA2B,CAAC,CAAA;QAEpE,MAAM,MAAM,CAAC,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"]}
|