@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,279 @@
1
+ import { __decorate } from "tslib";
2
+ import { css, html, LitElement } from 'lit';
3
+ import { customElement, property, query, state } from 'lit/decorators.js';
4
+ import { NOTHING_RESULT } from './type';
5
+ import { touch2mouse } from './utils/touch-to-mouse-event';
6
+ let OcrResultImage = class OcrResultImage extends LitElement {
7
+ constructor() {
8
+ super(...arguments);
9
+ this.result = NOTHING_RESULT;
10
+ this._ratio = { x: 1, y: 1 };
11
+ this._trails = [];
12
+ this._tracking = false;
13
+ this._selections = [];
14
+ this._text = '';
15
+ }
16
+ render() {
17
+ return html `
18
+ <img src=${this._image} @load=${() => this.calculateRatio()} />
19
+ <canvas overlay></canvas>
20
+
21
+ ${this._text ? html ` <div notice>${this._text} copied!</div> ` : html ``}
22
+ `;
23
+ }
24
+ renderOverlay() {
25
+ const { boundaries } = this.result;
26
+ const context = this._overlay.getContext('2d');
27
+ if (!context) {
28
+ return;
29
+ }
30
+ context.save();
31
+ context.clearRect(0, 0, this._overlay.width, this._overlay.height);
32
+ context.lineWidth = 5;
33
+ context.strokeStyle = 'red';
34
+ context.fillStyle = 'red';
35
+ context.lineJoin = 'round';
36
+ context.lineCap = 'round';
37
+ this._image &&
38
+ boundaries
39
+ .map((bounds) => {
40
+ return bounds.map(bound => {
41
+ return {
42
+ x: bound.x,
43
+ y: bound.y // * this._ratio.y
44
+ };
45
+ });
46
+ })
47
+ .forEach((bounds, idx) => {
48
+ context.beginPath();
49
+ context.moveTo(bounds[0].x, bounds[0].y);
50
+ context.lineTo(bounds[1].x, bounds[1].y);
51
+ context.lineTo(bounds[2].x, bounds[2].y);
52
+ context.lineTo(bounds[3].x, bounds[3].y);
53
+ context.closePath();
54
+ if (this._selections.includes(idx)) {
55
+ context.fill();
56
+ }
57
+ context.stroke();
58
+ });
59
+ /* draw trails */
60
+ if (this._trails && this._trails.length > 0) {
61
+ context.lineWidth = 10;
62
+ context.strokeStyle = 'blue';
63
+ context.beginPath();
64
+ this._trails.forEach(trail => {
65
+ if (trail && trail.length > 0) {
66
+ const { x, y } = trail[0];
67
+ context.moveTo(x, y);
68
+ trail.slice(1).forEach(point => {
69
+ const { x, y } = point;
70
+ context.lineTo(x, y);
71
+ });
72
+ }
73
+ });
74
+ context.stroke();
75
+ }
76
+ context.restore();
77
+ }
78
+ async calculateRatio() {
79
+ const { naturalWidth, naturalHeight, offsetWidth, offsetHeight } = this._img;
80
+ const { offsetWidth: overlayWidth, offsetHeight: overlayHeight } = this._overlay;
81
+ if (!naturalWidth || !naturalHeight) {
82
+ return;
83
+ }
84
+ this._ratio = {
85
+ x: offsetWidth / naturalWidth,
86
+ y: offsetHeight / naturalHeight
87
+ };
88
+ this._overlay.setAttribute('width', String(overlayWidth / this._ratio.x));
89
+ this._overlay.setAttribute('height', String(overlayHeight / this._ratio.y));
90
+ }
91
+ async connectedCallback() {
92
+ await super.connectedCallback();
93
+ this._resizeObserver = new ResizeObserver(entries => {
94
+ this.calculateRatio();
95
+ this.renderOverlay();
96
+ });
97
+ await this.updateComplete;
98
+ this._resizeObserver.observe(this._overlay);
99
+ this.calculateRatio();
100
+ this.addEventListener('mousedown', this.onTrailStart.bind(this));
101
+ this.addEventListener('mouseup', this.onTrailEnd.bind(this));
102
+ this.addEventListener('mousemove', this.onTrail.bind(this));
103
+ this.addEventListener('touchstart', touch2mouse);
104
+ this.addEventListener('touchend', touch2mouse);
105
+ this.addEventListener('touchmove', touch2mouse);
106
+ }
107
+ disconnectedCallback() {
108
+ super.disconnectedCallback();
109
+ this._resizeObserver.disconnect();
110
+ }
111
+ initialize() {
112
+ this._selections = [];
113
+ this._trails = [];
114
+ this._text = '';
115
+ }
116
+ async updated(changes) {
117
+ if (changes.has('file') || changes.has('result')) {
118
+ this.initialize();
119
+ }
120
+ if (changes.has('file')) {
121
+ this._image = this.file && URL.createObjectURL(this.file);
122
+ if (this._image) {
123
+ requestAnimationFrame(() => {
124
+ URL.revokeObjectURL(this._image);
125
+ });
126
+ await this.updateComplete;
127
+ this.calculateRatio();
128
+ }
129
+ }
130
+ this.renderOverlay();
131
+ }
132
+ findIndex(x, y) {
133
+ const { boundaries } = this.result;
134
+ return boundaries.findIndex(path => {
135
+ var result = false;
136
+ path.forEach((p, idx) => {
137
+ let j = (idx + path.length + 1) % path.length;
138
+ let x1 = p.x;
139
+ let y1 = p.y;
140
+ let x2 = path[j].x;
141
+ let y2 = path[j].y;
142
+ if (y1 > y != y2 > y && x < ((x2 - x1) * (y - y1)) / (y2 - y1) + x1) {
143
+ result = !result;
144
+ }
145
+ });
146
+ return result;
147
+ });
148
+ }
149
+ updateTrails(point, started, attached) {
150
+ if (started && !attached) {
151
+ this.initialize();
152
+ }
153
+ if (started) {
154
+ this._trails.push([]);
155
+ }
156
+ var trail = this._trails[this._trails.length - 1];
157
+ if (!trail) {
158
+ return;
159
+ }
160
+ trail.push(point);
161
+ this._trails.flat().forEach(({ x, y }) => {
162
+ const idx = this.findIndex(x, y);
163
+ if (idx === -1) {
164
+ return;
165
+ }
166
+ if (!this._selections.includes(idx)) {
167
+ this._selections.push(idx);
168
+ }
169
+ });
170
+ this.requestUpdate();
171
+ }
172
+ onTrailStart(e) {
173
+ const { offsetX: x, offsetY: y, button, shiftKey } = e;
174
+ if (button !== 0) {
175
+ return;
176
+ }
177
+ this._tracking = true;
178
+ this.updateTrails({ x: x / this._ratio.x, y: y / this._ratio.y }, true, shiftKey);
179
+ }
180
+ onTrailEnd(e) {
181
+ if (!this._tracking) {
182
+ return;
183
+ }
184
+ this._text = this._selections.map(idx => this.result.texts[idx]).join('');
185
+ this.dispatchEvent(new CustomEvent('selected', {
186
+ detail: this._text
187
+ }));
188
+ this._tracking = false;
189
+ }
190
+ onTrail(e) {
191
+ const { offsetX: x, offsetY: y } = e;
192
+ if (!this._tracking) {
193
+ return;
194
+ }
195
+ this.updateTrails({ x: x / this._ratio.x, y: y / this._ratio.y }, false);
196
+ }
197
+ };
198
+ OcrResultImage.styles = [
199
+ css `
200
+ :host {
201
+ display: block;
202
+ position: relative;
203
+ }
204
+
205
+ img {
206
+ display: block;
207
+ flex: 1;
208
+ border: 0;
209
+ padding: 0;
210
+ margin: 0;
211
+ max-width: 100%;
212
+ max-height: 100%;
213
+ }
214
+
215
+ [overlay] {
216
+ position: absolute;
217
+ top: 0;
218
+ left: 0;
219
+ width: 100%;
220
+ height: 100%;
221
+
222
+ border: 0;
223
+ padding: 0;
224
+ margin: 0;
225
+ opacity: 50%;
226
+ }
227
+
228
+ [notice] {
229
+ position: absolute;
230
+ bottom: 0;
231
+ background-color: var(--primary-color, #38a25b);
232
+ padding: var(--padding-default, 9px) var(--padding-wide, 15px);
233
+ opacity: 0.95;
234
+
235
+ overflow-wrap: anywhere;
236
+
237
+ color: #fff;
238
+ font-size: 1.5em;
239
+ }
240
+ `
241
+ ];
242
+ __decorate([
243
+ property({ type: Array })
244
+ ], OcrResultImage.prototype, "file", void 0);
245
+ __decorate([
246
+ property({ type: Array })
247
+ ], OcrResultImage.prototype, "result", void 0);
248
+ __decorate([
249
+ state()
250
+ ], OcrResultImage.prototype, "_ratio", void 0);
251
+ __decorate([
252
+ state()
253
+ ], OcrResultImage.prototype, "_image", void 0);
254
+ __decorate([
255
+ state()
256
+ ], OcrResultImage.prototype, "_resizeObserver", void 0);
257
+ __decorate([
258
+ state()
259
+ ], OcrResultImage.prototype, "_trails", void 0);
260
+ __decorate([
261
+ state()
262
+ ], OcrResultImage.prototype, "_tracking", void 0);
263
+ __decorate([
264
+ state()
265
+ ], OcrResultImage.prototype, "_selections", void 0);
266
+ __decorate([
267
+ state()
268
+ ], OcrResultImage.prototype, "_text", void 0);
269
+ __decorate([
270
+ query('img')
271
+ ], OcrResultImage.prototype, "_img", void 0);
272
+ __decorate([
273
+ query('[overlay]')
274
+ ], OcrResultImage.prototype, "_overlay", void 0);
275
+ OcrResultImage = __decorate([
276
+ customElement('ox-ocr-result-image')
277
+ ], OcrResultImage);
278
+ export { OcrResultImage };
279
+ //# sourceMappingURL=ox-ocr-result-image.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ox-ocr-result-image.js","sourceRoot":"","sources":["../../src/ox-ocr-result-image.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAkB,MAAM,KAAK,CAAA;AAC3D,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAEzE,OAAO,EAAE,cAAc,EAAc,MAAM,QAAQ,CAAA;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAA;AAG1D,IAAa,cAAc,GAA3B,MAAa,cAAe,SAAQ,UAAU;IAA9C;;QA+C6B,WAAM,GAAe,cAAc,CAAA;QAErD,WAAM,GAA6B,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAA;QAGjD,YAAO,GAA2C,EAAE,CAAA;QACpD,cAAS,GAAY,KAAK,CAAA;QAC1B,gBAAW,GAAkB,EAAE,CAAA;QAC/B,UAAK,GAAW,EAAE,CAAA;IAgP7B,CAAC;IA3OC,MAAM;QACJ,OAAO,IAAI,CAAA;iBACE,IAAI,CAAC,MAAM,UAAU,GAAG,EAAE,CAAC,IAAI,CAAC,cAAc,EAAE;;;QAGzD,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAA,gBAAgB,IAAI,CAAC,KAAK,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAA,EAAE;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B,CAAC;GACxB,cAAc,CAuS1B;SAvSY,cAAc","sourcesContent":["import { css, html, LitElement, PropertyValues } from 'lit'\nimport { customElement, property, query, state } from 'lit/decorators.js'\n\nimport { NOTHING_RESULT, ScanResult } from './type'\nimport { touch2mouse } from './utils/touch-to-mouse-event'\n\n@customElement('ox-ocr-result-image')\nexport class OcrResultImage extends LitElement {\n static styles = [\n css`\n :host {\n display: block;\n position: relative;\n }\n\n img {\n display: block;\n flex: 1;\n border: 0;\n padding: 0;\n margin: 0;\n max-width: 100%;\n max-height: 100%;\n }\n\n [overlay] {\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n\n border: 0;\n padding: 0;\n margin: 0;\n opacity: 50%;\n }\n\n [notice] {\n position: absolute;\n bottom: 0;\n background-color: var(--primary-color, #38a25b);\n padding: var(--padding-default, 9px) var(--padding-wide, 15px);\n opacity: 0.95;\n\n overflow-wrap: anywhere;\n\n color: #fff;\n font-size: 1.5em;\n }\n `\n ]\n\n @property({ type: Array }) file: any\n @property({ type: Array }) result: ScanResult = NOTHING_RESULT\n\n @state() _ratio: { x: number; y: number } = { x: 1, y: 1 }\n @state() _image!: string\n @state() _resizeObserver!: ResizeObserver\n @state() _trails: Array<Array<{ x: number; y: number }>> = []\n @state() _tracking: boolean = false\n @state() _selections: Array<number> = []\n @state() _text: string = ''\n\n @query('img') _img!: HTMLImageElement\n @query('[overlay]') _overlay!: HTMLCanvasElement\n\n render() {\n return html`\n <img src=${this._image} @load=${() => this.calculateRatio()} />\n <canvas overlay></canvas>\n\n ${this._text ? html` <div notice>${this._text} copied!</div> ` : html``}\n `\n }\n\n renderOverlay() {\n const { boundaries } = this.result\n\n const context = this._overlay.getContext('2d')\n if (!context) {\n return\n }\n\n context.save()\n\n context.clearRect(0, 0, this._overlay.width, this._overlay.height)\n\n context.lineWidth = 5\n context.strokeStyle = 'red'\n context.fillStyle = 'red'\n context.lineJoin = 'round'\n context.lineCap = 'round'\n\n this._image &&\n boundaries\n .map((bounds): Array<{ x: number; y: number }> => {\n return bounds.map(bound => {\n return {\n x: bound.x, //* this._ratio.x,\n y: bound.y // * this._ratio.y\n }\n })\n })\n .forEach((bounds, idx) => {\n context.beginPath()\n context.moveTo(bounds[0].x, bounds[0].y)\n context.lineTo(bounds[1].x, bounds[1].y)\n context.lineTo(bounds[2].x, bounds[2].y)\n context.lineTo(bounds[3].x, bounds[3].y)\n context.closePath()\n\n if (this._selections.includes(idx)) {\n context.fill()\n }\n context.stroke()\n })\n\n /* draw trails */\n if (this._trails && this._trails.length > 0) {\n context.lineWidth = 10\n context.strokeStyle = 'blue'\n\n context.beginPath()\n\n this._trails.forEach(trail => {\n if (trail && trail.length > 0) {\n const { x, y } = trail[0]\n context.moveTo(x, y)\n\n trail.slice(1).forEach(point => {\n const { x, y } = point\n context.lineTo(x, y)\n })\n }\n })\n\n context.stroke()\n }\n\n context.restore()\n }\n\n async calculateRatio() {\n const { naturalWidth, naturalHeight, offsetWidth, offsetHeight } = this._img\n const { offsetWidth: overlayWidth, offsetHeight: overlayHeight } = this._overlay\n\n if (!naturalWidth || !naturalHeight) {\n return\n }\n\n this._ratio = {\n x: offsetWidth / naturalWidth,\n y: offsetHeight / naturalHeight\n }\n\n this._overlay.setAttribute('width', String(overlayWidth / this._ratio.x))\n this._overlay.setAttribute('height', String(overlayHeight / this._ratio.y))\n }\n\n async connectedCallback() {\n await super.connectedCallback()\n\n this._resizeObserver = new ResizeObserver(entries => {\n this.calculateRatio()\n this.renderOverlay()\n })\n\n await this.updateComplete\n this._resizeObserver.observe(this._overlay)\n\n this.calculateRatio()\n\n this.addEventListener('mousedown', this.onTrailStart.bind(this) as EventListener)\n this.addEventListener('mouseup', this.onTrailEnd.bind(this) as EventListener)\n this.addEventListener('mousemove', this.onTrail.bind(this) as EventListener)\n this.addEventListener('touchstart', touch2mouse as EventListener)\n this.addEventListener('touchend', touch2mouse as EventListener)\n this.addEventListener('touchmove', touch2mouse as EventListener)\n }\n\n disconnectedCallback() {\n super.disconnectedCallback()\n\n this._resizeObserver.disconnect()\n }\n\n initialize() {\n this._selections = []\n this._trails = []\n this._text = ''\n }\n\n async updated(changes: PropertyValues<this>) {\n if (changes.has('file') || changes.has('result')) {\n this.initialize()\n }\n\n if (changes.has('file')) {\n this._image = this.file && URL.createObjectURL(this.file)\n if (this._image) {\n requestAnimationFrame(() => {\n URL.revokeObjectURL(this._image)\n })\n\n await this.updateComplete\n this.calculateRatio()\n }\n }\n\n this.renderOverlay()\n }\n\n findIndex(x: number, y: number): number {\n const { boundaries } = this.result\n\n return boundaries.findIndex(path => {\n var result = false\n\n path.forEach((p, idx) => {\n let j = (idx + path.length + 1) % path.length\n\n let x1 = p.x\n let y1 = p.y\n let x2 = path[j].x\n let y2 = path[j].y\n\n if (y1 > y != y2 > y && x < ((x2 - x1) * (y - y1)) / (y2 - y1) + x1) {\n result = !result\n }\n })\n\n return result\n })\n }\n\n updateTrails(point: { x: number; y: number }, started: boolean, attached?: boolean) {\n if (started && !attached) {\n this.initialize()\n }\n\n if (started) {\n this._trails.push([])\n }\n\n var trail = this._trails[this._trails.length - 1]\n if (!trail) {\n return\n }\n\n trail.push(point)\n\n this._trails.flat().forEach(({ x, y }) => {\n const idx = this.findIndex(x, y)\n if (idx === -1) {\n return\n }\n\n if (!this._selections.includes(idx)) {\n this._selections.push(idx)\n }\n })\n\n this.requestUpdate()\n }\n\n onTrailStart(e: MouseEvent) {\n const { offsetX: x, offsetY: y, button, shiftKey } = e\n\n if (button !== 0) {\n return\n }\n\n this._tracking = true\n this.updateTrails({ x: x / this._ratio.x, y: y / this._ratio.y }, true, shiftKey)\n }\n\n onTrailEnd(e: MouseEvent) {\n if (!this._tracking) {\n return\n }\n\n this._text = this._selections.map(idx => this.result.texts[idx]).join('')\n\n this.dispatchEvent(\n new CustomEvent('selected', {\n detail: this._text\n })\n )\n\n this._tracking = false\n }\n\n onTrail(e: MouseEvent) {\n const { offsetX: x, offsetY: y } = e\n\n if (!this._tracking) {\n return\n }\n\n this.updateTrails({ x: x / this._ratio.x, y: y / this._ratio.y }, false)\n }\n}\n"]}
@@ -0,0 +1,15 @@
1
+ export declare type ScanResult = {
2
+ key_values: {
3
+ [key: string]: Array<string>;
4
+ };
5
+ boundaries: Array<Array<{
6
+ x: number;
7
+ y: number;
8
+ }>>;
9
+ texts: Array<string>;
10
+ };
11
+ export declare const NOTHING_RESULT: {
12
+ boundaries: never[];
13
+ key_values: {};
14
+ texts: never[];
15
+ };
@@ -0,0 +1,6 @@
1
+ export const NOTHING_RESULT = {
2
+ boundaries: [],
3
+ key_values: {},
4
+ texts: []
5
+ };
6
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../src/type.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,UAAU,EAAE,EAAE;IACd,UAAU,EAAE,EAAE;IACd,KAAK,EAAE,EAAE;CACV,CAAA","sourcesContent":["export type ScanResult = {\n key_values: {\n [key: string]: Array<string>\n }\n boundaries: Array<Array<{ x: number; y: number }>>\n texts: Array<string>\n}\n\nexport const NOTHING_RESULT = {\n boundaries: [],\n key_values: {},\n texts: []\n}\n"]}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * judge callback function for FileDropHelper.set
3
+ */
4
+ declare type JudgeCallback = () => boolean;
5
+ /**
6
+ * file drop assist class
7
+ */
8
+ export declare class FileDropHelper {
9
+ /**
10
+ * 파일 드롭 영역에서의 file drag&drop과 관련된 이벤트에 대한 처리를 설정한다.
11
+ * @param dropArea file drag&drop target area
12
+ * @param [judge] file drag&drop과 관련된 이벤트에 대한 judge callback function
13
+ */
14
+ static set(dropArea: HTMLElement, judge?: JudgeCallback): void;
15
+ }
16
+ export {};
@@ -0,0 +1,47 @@
1
+ /**
2
+ * file drop assist class
3
+ */
4
+ export class FileDropHelper {
5
+ /**
6
+ * 파일 드롭 영역에서의 file drag&drop과 관련된 이벤트에 대한 처리를 설정한다.
7
+ * @param dropArea file drag&drop target area
8
+ * @param [judge] file drag&drop과 관련된 이벤트에 대한 judge callback function
9
+ */
10
+ static set(dropArea, judge) {
11
+ var preventDefaults = (e) => {
12
+ if (!judge || judge()) {
13
+ e.preventDefault();
14
+ e.stopPropagation();
15
+ }
16
+ };
17
+ var highlight = (e) => {
18
+ if (!judge || judge()) {
19
+ dropArea.classList.add('candrop');
20
+ }
21
+ };
22
+ var unhighlight = (e) => {
23
+ if (!judge || judge()) {
24
+ dropArea.classList.remove('candrop');
25
+ }
26
+ };
27
+ ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(event => {
28
+ dropArea.addEventListener(event, preventDefaults, false);
29
+ });
30
+ ['dragenter', 'dragover'].forEach(event => {
31
+ dropArea.addEventListener(event, highlight, false);
32
+ });
33
+ ['dragleave', 'drop'].forEach(event => {
34
+ dropArea.addEventListener(event, unhighlight, false);
35
+ });
36
+ dropArea.addEventListener('drop', e => {
37
+ if (!judge || judge()) {
38
+ let dt = e.dataTransfer;
39
+ let files = dt.files;
40
+ dropArea.dispatchEvent(new CustomEvent('file-drop', {
41
+ detail: [...Array.from(files)]
42
+ }));
43
+ }
44
+ }, false);
45
+ }
46
+ }
47
+ //# sourceMappingURL=file-drop-helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-drop-helper.js","sourceRoot":"","sources":["../../../src/utils/file-drop-helper.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,MAAM,OAAO,cAAc;IACzB;;;;OAIG;IACH,MAAM,CAAC,GAAG,CAAC,QAAqB,EAAE,KAAqB;QACrD,IAAI,eAAe,GAAG,CAAC,CAAQ,EAAE,EAAE;YACjC,IAAI,CAAC,KAAK,IAAI,KAAK,EAAE,EAAE;gBACrB,CAAC,CAAC,cAAc,EAAE,CAAA;gBAClB,CAAC,CAAC,eAAe,EAAE,CAAA;aACpB;QACH,CAAC,CAAA;QAED,IAAI,SAAS,GAAG,CAAC,CAAQ,EAAE,EAAE;YAC3B,IAAI,C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ACD,KAAK,CACN,CAAA;IACH,CAAC;CACF","sourcesContent":["/**\n * judge callback function for FileDropHelper.set\n */\ntype JudgeCallback = () => boolean\n\n/**\n * file drop assist class\n */\nexport class FileDropHelper {\n /**\n * 파일 드롭 영역에서의 file drag&drop과 관련된 이벤트에 대한 처리를 설정한다.\n * @param dropArea file drag&drop target area\n * @param [judge] file drag&drop과 관련된 이벤트에 대한 judge callback function\n */\n static set(dropArea: HTMLElement, judge?: JudgeCallback) {\n var preventDefaults = (e: Event) => {\n if (!judge || judge()) {\n e.preventDefault()\n e.stopPropagation()\n }\n }\n\n var highlight = (e: Event) => {\n if (!judge || judge()) {\n dropArea.classList.add('candrop')\n }\n }\n\n var unhighlight = (e: Event) => {\n if (!judge || judge()) {\n dropArea.classList.remove('candrop')\n }\n }\n\n ;['dragenter', 'dragover', 'dragleave', 'drop'].forEach(event => {\n dropArea.addEventListener(event, preventDefaults, false)\n })\n ;['dragenter', 'dragover'].forEach(event => {\n dropArea.addEventListener(event, highlight, false)\n })\n ;['dragleave', 'drop'].forEach(event => {\n dropArea.addEventListener(event, unhighlight, false)\n })\n\n dropArea.addEventListener(\n 'drop',\n e => {\n if (!judge || judge()) {\n let dt = e.dataTransfer!\n let files = dt.files\n\n dropArea.dispatchEvent(\n new CustomEvent('file-drop', {\n detail: [...Array.from(files)]\n })\n )\n }\n },\n false\n )\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ export declare function touch2mouse(e: TouchEvent): void;
@@ -0,0 +1,34 @@
1
+ export function touch2mouse(e) {
2
+ var _a;
3
+ e.preventDefault();
4
+ if (e.touches.length > 1 || (e.type == 'touchend' && e.touches.length > 0)) {
5
+ return;
6
+ }
7
+ var type = '';
8
+ const touch = e.changedTouches[0];
9
+ switch (e.type) {
10
+ case 'touchstart':
11
+ type = 'mousedown';
12
+ break;
13
+ case 'touchmove':
14
+ type = 'mousemove';
15
+ break;
16
+ case 'touchend':
17
+ type = 'mouseup';
18
+ break;
19
+ }
20
+ const { screenX, screenY, clientX, clientY } = touch;
21
+ const { ctrlKey, altKey, shiftKey, metaKey } = e;
22
+ (_a = e.target) === null || _a === void 0 ? void 0 : _a.dispatchEvent(new MouseEvent(type, {
23
+ screenX,
24
+ screenY,
25
+ clientX,
26
+ clientY,
27
+ ctrlKey,
28
+ altKey,
29
+ shiftKey,
30
+ metaKey,
31
+ button: 0
32
+ }));
33
+ }
34
+ //# sourceMappingURL=touch-to-mouse-event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"touch-to-mouse-event.js","sourceRoot":"","sources":["../../../src/utils/touch-to-mouse-event.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,WAAW,CAAC,CAAa;;IACvC,CAAC,CAAC,cAAc,EAAE,CAAA;IAElB,IAAI,CAAC,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,UAAU,IAAI,CAAC,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE;QAC1E,OAAM;KACP;IAED,IAAI,IAAI,GAAG,EAAE,CAAA;IACb,MAAM,KAAK,GAAG,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CAAA;IAEjC,QAAQ,CAAC,CAAC,IAAI,EAAE;QACd,KAAK,YAAY;YACf,IAAI,GAAG,WAAW,CAAA;YAClB,MAAK;QACP,KAAK,WAAW;YACd,IAAI,GAAG,WAAW,CAAA;YAClB,MAAK;QACP,KAAK,UAAU;YACb,IAAI,GAAG,SAAS,CAAA;YAChB,MAAK;KACR;IAED,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,KAAK,CAAA;IACpD,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,CAAC,CAAA;IAEhD,MAAA,CAAC,CAAC,MAAM,0CAAE,aAAa,CACrB,IAAI,UAAU,CAAC,IAAI,EAAE;QACnB,OAAO;QACP,OAAO;QACP,OAAO;QACP,OAAO;QACP,OAAO;QACP,MAAM;QACN,QAAQ;QACR,OAAO;QACP,MAAM,EAAE,CAAC;KACV,CAAC,CACH,CAAA;AACH,CAAC","sourcesContent":["export function touch2mouse(e: TouchEvent) {\n e.preventDefault()\n\n if (e.touches.length > 1 || (e.type == 'touchend' && e.touches.length > 0)) {\n return\n }\n\n var type = ''\n const touch = e.changedTouches[0]\n\n switch (e.type) {\n case 'touchstart':\n type = 'mousedown'\n break\n case 'touchmove':\n type = 'mousemove'\n break\n case 'touchend':\n type = 'mouseup'\n break\n }\n\n const { screenX, screenY, clientX, clientY } = touch\n const { ctrlKey, altKey, shiftKey, metaKey } = e\n\n e.target?.dispatchEvent(\n new MouseEvent(type, {\n screenX,\n screenY,\n clientX,\n clientY,\n ctrlKey,\n altKey,\n shiftKey,\n metaKey,\n button: 0\n })\n )\n}\n"]}
@@ -1,5 +1,5 @@
1
+ import '../src/ox-ocr-helper.js';
1
2
  import { TemplateResult } from 'lit';
2
- import '../src/ocr-helper.js';
3
3
  declare const _default: {
4
4
  title: string;
5
5
  component: string;
@@ -1,37 +1,33 @@
1
+ import '../src/ox-ocr-helper.js';
1
2
  import { html } from 'lit';
2
- import '../src/ocr-helper.js';
3
3
  export default {
4
4
  title: 'OcrHelper',
5
- component: 'ocr-helper',
5
+ component: 'ox-ocr-helper',
6
6
  argTypes: {
7
7
  title: { control: 'text' },
8
8
  counter: { control: 'number' },
9
- textColor: { control: 'color' },
10
- },
9
+ textColor: { control: 'color' }
10
+ }
11
11
  };
12
- const Template = ({ title = 'Hello world', counter = 5, textColor, slot, }) => html `
13
- <ocr-helper
14
- style="--ocr-helper-text-color: ${textColor || 'black'}"
15
- .title=${title}
16
- .counter=${counter}
17
- >
12
+ const Template = ({ title = 'Hello world', counter = 5, textColor, slot }) => html `
13
+ <ocr-helper style="--ocr-helper-text-color: ${textColor || 'black'}" .title=${title} .counter=${counter}>
18
14
  ${slot}
19
15
  </ocr-helper>
20
16
  `;
21
17
  export const Regular = Template.bind({});
22
18
  export const CustomTitle = Template.bind({});
23
19
  CustomTitle.args = {
24
- title: 'My title',
20
+ title: 'My title'
25
21
  };
26
22
  export const CustomCounter = Template.bind({});
27
23
  CustomCounter.args = {
28
- counter: 123456,
24
+ counter: 123456
29
25
  };
30
26
  export const SlottedContent = Template.bind({});
31
27
  SlottedContent.args = {
32
- slot: html `<p>Slotted content</p>`,
28
+ slot: html `<p>Slotted content</p>`
33
29
  };
34
30
  SlottedContent.argTypes = {
35
- slot: { table: { disable: true } },
31
+ slot: { table: { disable: true } }
36
32
  };
37
33
  //# sourceMappingURL=index.stories.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.stories.js","sourceRoot":"","sources":["../../stories/index.stories.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAkB,MAAM,KAAK,CAAC;AAC3C,OAAO,sBAAsB,CAAC;AAE9B,eAAe;IACb,KAAK,EAAE,WAAW;IAClB,SAAS,EAAE,YAAY;IACvB,QAAQ,EAAE;QACR,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE;QAC1B,OAAO,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE;QAC9B,SAAS,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE;KAChC;CACF,CAAC;AAeF,MAAM,QAAQ,GAAoB,CAAC,EACjC,KAAK,GAAG,aAAa,EACrB,OAAO,GAAG,CAAC,EACX,SAAS,EACT,IAAI,GACK,EAAE,EAAE,CAAC,IAAI,CAAA;;sCAEkB,SAAS,IAAI,OAAO;aAC7C,KAAK;eACH,OAAO;;MAEhB,IAAI;;CAET,CAAC;AAEF,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAEzC,MAAM,CAAC,MAAM,WAAW,GAAG,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC7C,WAAW,CAAC,IAAI,GAAG;IACjB,KAAK,EAAE,UAAU;CAClB,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC/C,aAAa,CAAC,IAAI,GAAG;IACnB,OAAO,EAAE,MAAM;CAChB,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAChD,cAAc,CAAC,IAAI,GAAG;IACpB,IAAI,EAAE,IAAI,CAAA,wBAAwB;CACnC,CAAC;AACF,cAAc,CAAC,QAAQ,GAAG;IACxB,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;CACnC,CAAC","sourcesContent":["import { html, TemplateResult } from 'lit';\nimport '../src/ocr-helper.js';\n\nexport default {\n title: 'OcrHelper',\n component: 'ocr-helper',\n argTypes: {\n title: { control: 'text' },\n counter: { control: 'number' },\n textColor: { control: 'color' },\n },\n};\n\ninterface Story<T> {\n (args: T): TemplateResult;\n args?: Partial<T>;\n argTypes?: Record<string, unknown>;\n}\n\ninterface ArgTypes {\n title?: string;\n counter?: number;\n textColor?: string;\n slot?: TemplateResult;\n}\n\nconst Template: Story<ArgTypes> = ({\n title = 'Hello world',\n counter = 5,\n textColor,\n slot,\n}: ArgTypes) => html`\n <ocr-helper\n style=\"--ocr-helper-text-color: ${textColor || 'black'}\"\n .title=${title}\n .counter=${counter}\n >\n ${slot}\n </ocr-helper>\n`;\n\nexport const Regular = Template.bind({});\n\nexport const CustomTitle = Template.bind({});\nCustomTitle.args = {\n title: 'My title',\n};\n\nexport const CustomCounter = Template.bind({});\nCustomCounter.args = {\n counter: 123456,\n};\n\nexport const SlottedContent = Template.bind({});\nSlottedContent.args = {\n slot: html`<p>Slotted content</p>`,\n};\nSlottedContent.argTypes = {\n slot: { table: { disable: true } },\n};\n"]}
1
+ {"version":3,"file":"index.stories.js","sourceRoot":"","sources":["../../stories/index.stories.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA;AA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per',\n component: 'ox-ocr-helper',\n argTypes: {\n title: { control: 'text' },\n counter: { control: 'number' },\n textColor: { control: 'color' }\n }\n}\n\ninterface Story<T> {\n (args: T): TemplateResult\n args?: Partial<T>\n argTypes?: Record<string, unknown>\n}\n\ninterface ArgTypes {\n title?: string\n counter?: number\n textColor?: string\n slot?: TemplateResult\n}\n\nconst Template: Story<ArgTypes> = ({ title = 'Hello world', counter = 5, textColor, slot }: ArgTypes) => html`\n <ocr-helper style=\"--ocr-helper-text-color: ${textColor || 'black'}\" .title=${title} .counter=${counter}>\n ${slot}\n </ocr-helper>\n`\n\nexport const Regular = Template.bind({})\n\nexport const CustomTitle = Template.bind({})\nCustomTitle.args = {\n title: 'My title'\n}\n\nexport const CustomCounter = Template.bind({})\nCustomCounter.args = {\n counter: 123456\n}\n\nexport const SlottedContent = Template.bind({})\nSlottedContent.args = {\n slot: html`<p>Slotted content</p>`\n}\nSlottedContent.argTypes = {\n slot: { table: { disable: true } }\n}\n"]}
@@ -0,0 +1 @@
1
+ import '../src/ox-ocr-helper.js';
@@ -1,24 +1,24 @@
1
- import '../src/ocr-helper.js';
2
- import { expect, fixture } from '@open-wc/testing';
1
+ import '../src/ox-ocr-helper.js';
3
2
  import { html } from 'lit';
3
+ import { expect, fixture } from '@open-wc/testing';
4
4
  describe('OcrHelper', () => {
5
5
  it('has a default title "Hey there" and counter 5', async () => {
6
- const el = await fixture(html `<ocr-helper></ocr-helper>`);
6
+ const el = await fixture(html `<ox-ocr-helper></ox-ocr-helper>`);
7
7
  expect(el.title).to.equal('Hey there');
8
8
  // expect(el.counter).to.equal(5)
9
9
  });
10
10
  it('increases the counter on button click', async () => {
11
- const el = await fixture(html `<ocr-helper></ocr-helper>`);
11
+ const el = await fixture(html `<ox-ocr-helper></ox-ocr-helper>`);
12
12
  el.shadowRoot.querySelector('button').click();
13
13
  // expect(el.counter).to.equal(6)
14
14
  });
15
15
  it('can override the title via attribute', async () => {
16
- const el = await fixture(html `<ocr-helper title="attribute title"></ocr-helper>`);
16
+ const el = await fixture(html `<ox-ocr-helper title="attribute title"></ox-ocr-helper>`);
17
17
  expect(el.title).to.equal('attribute title');
18
18
  });
19
19
  it('passes the a11y audit', async () => {
20
- const el = await fixture(html `<ocr-helper></ocr-helper>`);
20
+ const el = await fixture(html `<ox-ocr-helper></ox-ocr-helper>`);
21
21
  await expect(el).shadowDom.to.be.accessible();
22
22
  });
23
23
  });
24
- //# sourceMappingURL=ocr-helper.test.js.map
24
+ //# sourceMappingURL=ox-ocr-helper.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ox-ocr-helper.test.js","sourceRoot":"","sources":["../../test/ox-ocr-helper.test.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA;AAEhC,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAA;AAE1B,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAIlD,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,EAAE,CAAC,+CAA+C,EAAE,KAAK,IAAI,EAAE;QAC7D,MAAM,EAAE,GAAG,MAAM,OAAO,CAAY,IAAI,CAAA,iCAAiC,CAAC,CAAA;QAE1E,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,iCAAiC,CAAC,CAAA;QAC1E,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,yDAAyD,CAAC,CAAA;QAElG,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,iCAAiC,CAAC,CAAA;QAE1E,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/ox-ocr-helper.js'\n\nimport { html } from 'lit'\n\nimport { expect, fixture } from '@open-wc/testing'\n\nimport { OcrHelper } from '../src/ox-ocr-helper.js'\n\ndescribe('OcrHelper', () => {\n it('has a default title \"Hey there\" and counter 5', async () => {\n const el = await fixture<OcrHelper>(html`<ox-ocr-helper></ox-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`<ox-ocr-helper></ox-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`<ox-ocr-helper title=\"attribute title\"></ox-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`<ox-ocr-helper></ox-ocr-helper>`)\n\n await expect(el).shadowDom.to.be.accessible()\n })\n})\n"]}