@things-factory/barcode-ui 8.0.0-beta.0 → 8.0.0-beta.2

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/barcode-ui",
3
- "version": "8.0.0-beta.0",
3
+ "version": "8.0.0-beta.2",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "dist-client/index.js",
6
6
  "things-factory": true,
@@ -28,8 +28,8 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@operato/layout": "^8.0.0-beta",
31
- "@things-factory/shell": "^8.0.0-beta.0",
31
+ "@things-factory/shell": "^8.0.0-beta.2",
32
32
  "bwip-js": "^4.4.0"
33
33
  },
34
- "gitHead": "add6fb8224b2cb19cbea47bed6a5ecb0424c9a28"
34
+ "gitHead": "f03431a09435511b2595515658f9cb8f78ba4ebb"
35
35
  }
@@ -1,56 +0,0 @@
1
- import './barcode-tag'
2
-
3
- import { css, html, LitElement } from 'lit'
4
- import { customElement, property } from 'lit/decorators.js'
5
-
6
- @customElement('barcode-input')
7
- export class BarcodeInput extends LitElement {
8
- static styles = [
9
- css`
10
- :host {
11
- display: flex;
12
- flex-direction: column;
13
- align-items: center;
14
-
15
- padding: initial;
16
- border: 0;
17
- }
18
-
19
- :host * {
20
- align-self: stretch;
21
- }
22
-
23
- input {
24
- margin: 5px 0;
25
- }
26
-
27
- barcode-tag {
28
- margin: 5px 0;
29
- }
30
- `
31
- ]
32
-
33
- @property({ type: String }) bcid?: string
34
- @property({ type: Number }) bcWidth?: number
35
- @property({ type: Number }) bcHeight?: number
36
- @property({ type: Number }) bcScale?: number
37
- @property({ type: String }) value?: string
38
-
39
- render() {
40
- return html`
41
- <input type="text" @change=${this.onChange.bind(this)} .value=${this.value || ''} />
42
- <barcode-tag
43
- .bcid=${this.bcid}
44
- .value=${this.value}
45
- .bcWidth=${this.bcWidth}
46
- .bcHeight=${this.bcHeight}
47
- .bcScale=${this.bcScale}
48
- ></barcode-tag>
49
- `
50
- }
51
-
52
- onChange(e) {
53
- this.value = e.target.value
54
- this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))
55
- }
56
- }
@@ -1,177 +0,0 @@
1
- import { css, html, LitElement } from 'lit'
2
- import { customElement, property, query } from 'lit/decorators.js'
3
-
4
- import { openPopup } from '@operato/layout'
5
- import { BrowserMultiFormatReader } from '@zxing/library'
6
-
7
- const barcodeIcon = new URL('../../assets/images/barcode.png', import.meta.url).href
8
-
9
- @customElement('scan-camera-template')
10
- class ScanCameraTemplate extends LitElement {
11
- get video() {
12
- return this.renderRoot.querySelector('video')
13
- }
14
-
15
- render() {
16
- return html` <video></video> `
17
- }
18
- }
19
-
20
- /**
21
- * @deprecated use ox-input-barcode from @operato/input/ox-input-barcode.js
22
- *
23
- * BarcodeScanableInput is using mediadevice api of html5
24
- */
25
- @customElement('barcode-scanable-input')
26
- export class BarcodeScanableInput extends LitElement {
27
- static styles = [
28
- css`
29
- :host {
30
- display: flex;
31
- align-items: center;
32
- border: none;
33
- overflow: hidden;
34
- background-color: var(--md-sys-color-surface);
35
-
36
- padding: var(--custom-input-barcode-field-padding) !important;
37
- }
38
-
39
- * {
40
- align-self: stretch;
41
- }
42
-
43
- *:focus {
44
- outline: none;
45
- }
46
-
47
- input {
48
- flex: 1 !important;
49
- border: none;
50
- font: var(--custom-input-barcode-field-font);
51
- width: 10px;
52
- flex-grow: 1;
53
- }
54
-
55
- #scan-button {
56
- display: block;
57
- width: 30px;
58
- height: 100%;
59
- min-height: 24px;
60
- border: none;
61
- background-color: transparent;
62
- background-repeat: no-repeat;
63
- background-position: center;
64
- background-image: var(--barcodescan-input-button-icon);
65
- }
66
-
67
- #scan-button[hidden] {
68
- display: none;
69
- }
70
- `
71
- ]
72
-
73
- @property({ type: String, attribute: true }) name?: string
74
- @property({ type: Boolean }) scannable?: boolean
75
- @property({ type: Boolean, attribute: 'without-enter' }) withoutEnter?: boolean
76
- @property({ type: String }) value?: string
77
-
78
- @query('input') input!: HTMLInputElement
79
-
80
- private stream?: MediaStream
81
- private reader?: BrowserMultiFormatReader
82
-
83
- connectedCallback() {
84
- super.connectedCallback()
85
-
86
- this.scannable = false
87
-
88
- if (navigator.mediaDevices) {
89
- ;(async () => {
90
- try {
91
- var stream = await navigator.mediaDevices.getUserMedia({ video: { facingMode: 'environment' } })
92
- if (stream) {
93
- stream.getTracks().forEach(track => track.stop())
94
- this.scannable = true
95
- }
96
- } catch (e) {
97
- console.warn('this device not support camera for barcode scan', e)
98
- }
99
- })()
100
- }
101
- }
102
-
103
- disconnectedCallback() {
104
- this.stopScan()
105
- }
106
-
107
- render() {
108
- this.style.setProperty('--barcodescan-input-button-icon', `url(${barcodeIcon})`)
109
-
110
- return html`
111
- <input type="search" .value=${this.value || ''} maxlength="50" />
112
- <button
113
- ?hidden=${!this.scannable}
114
- id="scan-button"
115
- @click=${e => {
116
- this.scan(e)
117
- }}
118
- ></button>
119
- `
120
- }
121
-
122
- async scan(e) {
123
- var popup
124
-
125
- try {
126
- var template = document.createElement('scan-camera-template') as any
127
-
128
- popup = openPopup(template, {
129
- backdrop: true,
130
- size: 'large',
131
- closable: false
132
- })
133
-
134
- popup.onclosed = () => {
135
- /* 뒤로가기 등으로 popup이 종료된 경우에도 scan 자원을 clear해준다. */
136
- this.stopScan()
137
- }
138
-
139
- /* template.video가 생성된 후에 접근하기 위해서, 한 프레임을 강제로 건너뛴다. */
140
- await this.updateComplete
141
-
142
- var constraints = { video: { facingMode: 'environment' } } /* backside camera first */
143
- this.stream = await navigator.mediaDevices.getUserMedia(constraints)
144
-
145
- this.reader = new BrowserMultiFormatReader()
146
- if (!popup.closed && this.stream) {
147
- var result = await this.reader.decodeOnceFromStream(this.stream, template.video)
148
-
149
- this.input.value = result as any
150
- if (!this.withoutEnter) {
151
- this.dispatchEvent(new KeyboardEvent('keypress', { keyCode: 0x0d }))
152
- }
153
- } else {
154
- /* popup이 비동기 진행 중에 close된 경우라면, stopScan()을 처리하지 못하게 되므로, 다시한번 clear해준다. */
155
- this.stopScan()
156
- }
157
- } catch (err) {
158
- /*
159
- * 1. stream device 문제로 예외 발생한 경우.
160
- * 2. 뒤로가기 등으로 popup이 종료된 경우에도 NotFoundException: Video stream has ended before any code could be detected. 이 발생한다.
161
- */
162
- console.warn(err)
163
- } finally {
164
- popup?.close()
165
-
166
- this.stopScan()
167
- }
168
- }
169
-
170
- stopScan() {
171
- this.stream && this.stream.getTracks().forEach(track => track.stop())
172
- this.reader && this.reader.reset()
173
-
174
- delete this.stream
175
- delete this.reader
176
- }
177
- }
@@ -1,115 +0,0 @@
1
- import bwipjs from 'bwip-js'
2
- import { css, html, LitElement } from 'lit'
3
- import { customElement, property } from 'lit/decorators.js'
4
-
5
- /**
6
- * @deprecated use ox-barcode from @operato/barcode/ox-barcode.js
7
- */
8
- @customElement('barcode-tag')
9
- export class BarcodeTag extends LitElement {
10
- static styles = [
11
- css`
12
- :host {
13
- display: flex;
14
- align-items: center;
15
-
16
- position: relative;
17
- }
18
-
19
- canvas {
20
- width: 100%;
21
- height: 100px;
22
- }
23
-
24
- [dimmer] {
25
- display: block;
26
- position: absolute;
27
- width: 100%;
28
- height: 100%;
29
- top: 0;
30
- left: 0;
31
- background-color: rgba(255, 0, 0, 0.5);
32
- }
33
- `
34
- ]
35
-
36
- @property({ type: String }) bcid?: string
37
- @property({ type: Number }) bcWidth?: number
38
- @property({ type: Number }) bcHeight?: number
39
- @property({ type: Number }) bcScale?: number
40
- @property({ type: String }) value?: string
41
- @property({ type: Boolean }) validity?: boolean
42
- @property({ type: Number }) padding?: number
43
-
44
- render() {
45
- return html`
46
- <canvas></canvas>
47
-
48
- ${!this.value || !this.validity ? html` <div dimmer></div> ` : html``}
49
- `
50
- }
51
-
52
- constructor() {
53
- super()
54
- this.addEventListener('click', this._downloadQR)
55
- }
56
-
57
- _downloadQR() {
58
- if (this.value && this.value != '') {
59
- let link = document.createElement('a')
60
- let canvas = this.renderRoot.querySelector('canvas') as HTMLCanvasElement
61
-
62
- let options = {
63
- bcid: this.bcid || 'code128', // Barcode type
64
- height: this.bcHeight || 30, // Bar height, in millimeters
65
- width: this.bcHeight || 30,
66
- padding: this.padding || 5,
67
- scale: this.bcScale || 3, // scaling factor
68
- text: this.value || '12345678990',
69
- // includetext: true,
70
- textalign: 'center',
71
- backgroundcolor: 'ffffff'
72
- }
73
- //@ts-ignore
74
- canvas = bwipjs.toCanvas(canvas, options)
75
-
76
- link.download = `${this.value}` + '-barcode.png'
77
- link.href = canvas.toDataURL()
78
- link.click()
79
-
80
- //@ts-ignore
81
- bwipjs.toCanvas(canvas, {
82
- bcid: this.bcid || 'code128', // Barcode type
83
- height: this.bcHeight || 20, // Bar height, in millimeters
84
- scale: this.bcScale || 3, // scaling factor
85
- text: this.value || '12345678990',
86
- // includetext: true,
87
- textalign: 'center'
88
- })
89
- }
90
- }
91
-
92
- updated(changes) {
93
- var options = {
94
- bcid: this.bcid || 'code128', // Barcode type
95
- height: this.bcHeight || 20, // Bar height, in millimeters
96
- scale: this.bcScale || 3, // scaling factor
97
- text: this.value || '12345678990',
98
- // includetext: true,
99
- textalign: 'center'
100
- }
101
-
102
- let canvas = this.renderRoot.querySelector('canvas')
103
-
104
- try {
105
- //@ts-ignore
106
- bwipjs.toCanvas(canvas, options)
107
-
108
- this.validity = true
109
- } catch (err) {
110
- console.error(err)
111
-
112
- this.validity = false
113
- }
114
- }
115
- }
package/client/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from './components/barcode-tag'
2
- export * from './components/barcode-input'
3
- export * from './components/barcode-scanable-input'
@@ -1,4 +0,0 @@
1
- body {
2
- --custom-input-barcode-field-font: normal 18px var(--theme-font);
3
- --custom-input-barcode-field-padding: 2px 2px 2px 9px;
4
- }
package/server/index.ts DELETED
File without changes