@operato/input 8.0.0-alpha.51 → 8.0.0-beta.1

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 (99) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/tsconfig.tsbuildinfo +1 -1
  3. package/package.json +7 -7
  4. package/.editorconfig +0 -29
  5. package/.storybook/main.js +0 -3
  6. package/.storybook/preview.js +0 -52
  7. package/.storybook/server.mjs +0 -8
  8. package/src/index.ts +0 -35
  9. package/src/locale/locale-codes.ts +0 -18
  10. package/src/locale/locale-picker.ts +0 -43
  11. package/src/locale/localization.ts +0 -15
  12. package/src/locales/en.ts +0 -30
  13. package/src/locales/ko.ts +0 -30
  14. package/src/locales/ms.ts +0 -30
  15. package/src/locales/zh.ts +0 -30
  16. package/src/ox-buttons-radio.ts +0 -140
  17. package/src/ox-checkbox.ts +0 -181
  18. package/src/ox-form-field.ts +0 -53
  19. package/src/ox-input-3axis.ts +0 -77
  20. package/src/ox-input-3dish.ts +0 -211
  21. package/src/ox-input-angle.ts +0 -73
  22. package/src/ox-input-barcode.ts +0 -318
  23. package/src/ox-input-code.ts +0 -139
  24. package/src/ox-input-color-gradient.ts +0 -349
  25. package/src/ox-input-color-stops.ts +0 -525
  26. package/src/ox-input-color.ts +0 -338
  27. package/src/ox-input-container.ts +0 -32
  28. package/src/ox-input-crontab.ts +0 -595
  29. package/src/ox-input-data.ts +0 -219
  30. package/src/ox-input-direction.ts +0 -92
  31. package/src/ox-input-duration.ts +0 -175
  32. package/src/ox-input-file.ts +0 -209
  33. package/src/ox-input-hashtags.ts +0 -185
  34. package/src/ox-input-i18n-label.ts +0 -140
  35. package/src/ox-input-image.ts +0 -168
  36. package/src/ox-input-key-values.ts +0 -301
  37. package/src/ox-input-layout/ox-input-card-layout.ts +0 -58
  38. package/src/ox-input-layout/ox-input-grid-layout.ts +0 -64
  39. package/src/ox-input-layout/ox-input-layout.ts +0 -77
  40. package/src/ox-input-mass-fraction.ts +0 -437
  41. package/src/ox-input-multiple-colors.ts +0 -135
  42. package/src/ox-input-options.ts +0 -216
  43. package/src/ox-input-partition-keys.ts +0 -303
  44. package/src/ox-input-privilege.ts +0 -163
  45. package/src/ox-input-quantifier.ts +0 -62
  46. package/src/ox-input-range.ts +0 -146
  47. package/src/ox-input-scene-component-id.ts +0 -73
  48. package/src/ox-input-search.ts +0 -126
  49. package/src/ox-input-select-buttons.ts +0 -75
  50. package/src/ox-input-signature.ts +0 -208
  51. package/src/ox-input-stack.ts +0 -136
  52. package/src/ox-input-switch.ts +0 -117
  53. package/src/ox-input-table-column-config.ts +0 -211
  54. package/src/ox-input-table.ts +0 -404
  55. package/src/ox-input-textarea.ts +0 -86
  56. package/src/ox-input-unit-number.ts +0 -354
  57. package/src/ox-input-value-map.ts +0 -342
  58. package/src/ox-input-value-ranges.ts +0 -363
  59. package/src/ox-input-work-shift.ts +0 -290
  60. package/src/ox-select-floor.ts +0 -246
  61. package/src/ox-select.ts +0 -219
  62. package/stories/image-for-select-floor.ts +0 -2
  63. package/stories/ox-buttons-radio.stories.ts +0 -89
  64. package/stories/ox-checkbox.stories.ts +0 -111
  65. package/stories/ox-input-3axis.stories.ts +0 -77
  66. package/stories/ox-input-3dish.stories.ts +0 -106
  67. package/stories/ox-input-angle.stories.ts +0 -84
  68. package/stories/ox-input-barcode.stories.ts +0 -117
  69. package/stories/ox-input-code.stories.ts +0 -99
  70. package/stories/ox-input-crontab.stories.ts +0 -82
  71. package/stories/ox-input-data.stories.ts +0 -82
  72. package/stories/ox-input-direction.stories.ts +0 -91
  73. package/stories/ox-input-duration.stories.ts +0 -84
  74. package/stories/ox-input-file.stories.ts +0 -111
  75. package/stories/ox-input-hashtags.stories.ts +0 -82
  76. package/stories/ox-input-i18n-label.stories.ts +0 -103
  77. package/stories/ox-input-key-values.stories.ts +0 -97
  78. package/stories/ox-input-mass-fraction.stories.ts +0 -102
  79. package/stories/ox-input-multiple-colors.stories.ts +0 -72
  80. package/stories/ox-input-options.stories.ts +0 -80
  81. package/stories/ox-input-partition-keys.stories.ts +0 -84
  82. package/stories/ox-input-privilege.stories.ts +0 -108
  83. package/stories/ox-input-quantifier.stories.ts +0 -80
  84. package/stories/ox-input-range.stories.ts +0 -89
  85. package/stories/ox-input-search.stories.ts +0 -91
  86. package/stories/ox-input-select-buttons.stories.ts +0 -118
  87. package/stories/ox-input-signature.stories.ts +0 -75
  88. package/stories/ox-input-switch.stories.ts +0 -91
  89. package/stories/ox-input-table-column-config.stories.ts +0 -109
  90. package/stories/ox-input-unit.stories.ts +0 -151
  91. package/stories/ox-input-value-map.stories.ts +0 -92
  92. package/stories/ox-input-value-ranges.stories.ts +0 -92
  93. package/stories/ox-input-work-shift.stories.ts +0 -106
  94. package/stories/ox-select-floor.stories.ts +0 -197
  95. package/stories/ox-select-set-options.stories.ts +0 -208
  96. package/stories/ox-select.stories.ts +0 -181
  97. package/tsconfig.json +0 -25
  98. package/web-dev-server.config.mjs +0 -27
  99. package/web-test-runner.config.mjs +0 -41
@@ -1,62 +0,0 @@
1
- /**
2
- * @license Copyright © HatioLab Inc. All rights reserved.
3
- */
4
-
5
- import { css, html } from 'lit'
6
- import { customElement, property, queryAll } from 'lit/decorators.js'
7
-
8
- import { OxFormField } from './ox-form-field.js'
9
-
10
- @customElement('ox-input-quantifier')
11
- export class OxInputQuantifier extends OxFormField {
12
- static styles = css`
13
- :host {
14
- display: flex;
15
- gap: var(--spacing-medium);
16
- align-items: center;
17
-
18
- width: 100%;
19
- user-select: text;
20
- }
21
-
22
- input[type='number'] {
23
- width: 48px;
24
- border: 0;
25
- border-bottom: 1px solid rgba(0, 0, 0, 0.15);
26
- padding: var(--spacing-tiny);
27
- font: var(--input-font);
28
- color: var(--md-sys-color-on-primary-container);
29
- }
30
- input[type='number']:focus {
31
- outline: none;
32
- border-bottom: 1px solid var(--md-sys-color-on-primary-container);
33
- }
34
-
35
- input:focus {
36
- outline: none;
37
- opacity: 1;
38
- }
39
- `
40
-
41
- @property({ type: Array }) value: number[] = [1, 1]
42
-
43
- render() {
44
- const [min = 1, max = 1] = this.value || []
45
-
46
- return html`
47
- <span>
48
- <input type="number" .value=${min} @change=${(e: Event) => this.onChange(e)} ?disabled=${this.disabled} />
49
- -
50
- <input type="number" .value=${max} @change=${(e: Event) => this.onChange(e)} ?disabled=${this.disabled} />
51
- </span>
52
- `
53
- }
54
-
55
- @queryAll('input') inputs?: HTMLInputElement[]
56
-
57
- onChange(e: Event) {
58
- e.stopPropagation()
59
- this.value = Array.from(this.inputs || []).map(input => input.valueAsNumber) || [1, 1]
60
- this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))
61
- }
62
- }
@@ -1,146 +0,0 @@
1
- /**
2
- * @license Copyright © HatioLab Inc. All rights reserved.
3
- */
4
-
5
- import { css, html } from 'lit'
6
- import { customElement, property } from 'lit/decorators.js'
7
-
8
- import { OxFormField } from './ox-form-field.js'
9
-
10
- @customElement('ox-input-range')
11
- class OxInputRange extends OxFormField {
12
- static styles = css`
13
- :host {
14
- display: flex;
15
- gap: var(--spacing-medium);
16
- align-items: center;
17
-
18
- width: 100%;
19
- user-select: text;
20
- }
21
-
22
- input[type='number'] {
23
- width: 48px;
24
- border: 0;
25
- border-bottom: 1px solid rgba(0, 0, 0, 0.15);
26
- padding: var(--spacing-tiny);
27
- font: var(--input-font);
28
- color: var(--md-sys-color-on-primary-container);
29
- }
30
- input[type='number']:focus {
31
- outline: none;
32
- border-bottom: 1px solid var(--md-sys-color-on-primary-container);
33
- }
34
-
35
- input[type='range'] {
36
- -webkit-appearance: none;
37
- border: none;
38
- outline: none;
39
- width: 100%;
40
- flex: 1;
41
- height: 16px;
42
- background-color: transparent;
43
- }
44
- input[type='range']::-webkit-slider-runnable-track {
45
- width: 100%;
46
- height: 7px;
47
- background-color: rgba(0, 0, 0, 0.02);
48
- border: 1px solid rgba(0, 0, 0, 0.05);
49
- border-radius: 5px;
50
- }
51
- input[type='range']::-webkit-slider-thumb {
52
- -webkit-appearance: none;
53
- border: none;
54
- height: 16px;
55
- width: 16px;
56
- border-radius: 50%;
57
- background: var(--md-sys-color-on-primary-container);
58
- margin-top: -6px;
59
- box-shadow: 0px 0px 2px 1px rgba(0, 0, 0, 0.15);
60
- }
61
- input[type='range']:focus {
62
- outline: none;
63
- }
64
-
65
- input[type='range']::-moz-range-track {
66
- width: 100%;
67
- height: 7px;
68
- background-color: rgba(0, 0, 0, 0.02);
69
- border: 1px solid rgba(0, 0, 0, 0.05);
70
- border-radius: 5px;
71
- }
72
- input[type='range']::-moz-range-thumb {
73
- border: none;
74
- height: 16px;
75
- width: 16px;
76
- border-radius: 50%;
77
- background: var(--md-sys-color-on-primary-container);
78
- margin-top: -6px;
79
- box-shadow: 0px 0px 2px 1px rgba(0, 0, 0, 0.15);
80
- }
81
-
82
- input[type='range']:-moz-focusring {
83
- outline: 1px solid black;
84
- outline-offset: -1px;
85
- }
86
-
87
- input[type='range']::-ms-track {
88
- width: 100%;
89
- height: 7px;
90
- background-color: rgba(0, 0, 0, 0.02);
91
- border: 1px solid rgba(0, 0, 0, 0.05);
92
- border-radius: 5px;
93
- }
94
- input[type='range']::-ms-thumb {
95
- border: none;
96
- height: 16px;
97
- width: 16px;
98
- border-radius: 50%;
99
- background: var(--md-sys-color-on-primary-container);
100
- margin-top: -6px;
101
- box-shadow: 0px 0px 2px 1px rgba(0, 0, 0, 0.15);
102
- }
103
-
104
- input:focus {
105
- outline: none;
106
- opacity: 1;
107
- }
108
- `
109
-
110
- @property({ type: Number }) value: number = 0
111
- @property({ type: Number }) step: number = 1
112
- @property({ type: Number }) min: number = -100
113
- @property({ type: Number }) max: number = 100
114
-
115
- render() {
116
- return html`
117
- <input
118
- type="range"
119
- .value=${this.value}
120
- .step=${this.step}
121
- .min=${this.min}
122
- .max=${this.max}
123
- @input=${(e: InputEvent) => {
124
- e.stopPropagation()
125
- this.value = Number((e.target as HTMLInputElement).value)
126
- this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))
127
- }}
128
- ?disabled=${this.disabled}
129
- />
130
-
131
- <input
132
- type="number"
133
- .value=${this.value}
134
- .step=${this.step}
135
- .min=${this.min}
136
- .max=${this.max}
137
- @change=${(e: Event) => {
138
- e.stopPropagation()
139
- this.value = Number((e.target as HTMLInputElement).value)
140
- this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))
141
- }}
142
- ?disabled=${this.disabled}
143
- />
144
- `
145
- }
146
- }
@@ -1,73 +0,0 @@
1
- /**
2
- * @license Copyright © HatioLab Inc. All rights reserved.
3
- */
4
-
5
- import { css, html } from 'lit'
6
- import { customElement, property, state } from 'lit/decorators.js'
7
-
8
- import { OxFormField } from './ox-form-field'
9
-
10
- @customElement('ox-input-scene-component-id')
11
- export class OxInputId extends OxFormField {
12
- static styles = css`
13
- :host {
14
- position: relative;
15
- display: inline-flex;
16
- align-items: center;
17
- justify-content: flex-end;
18
- }
19
-
20
- input {
21
- width: 100%;
22
- height: 100%;
23
- box-sizing: border-box;
24
- border: 1px solid rgba(0, 0, 0, 0.2);
25
- }
26
- `
27
-
28
- @property({ type: Object }) property: { component?: any } | null | undefined
29
-
30
- @state() _ids: Array<string> = []
31
-
32
- render() {
33
- const ids = this._ids || []
34
-
35
- return html`
36
- <input
37
- id="text"
38
- type="text"
39
- .value=${this.value || ''}
40
- @focusin=${(e: FocusEvent) => this._onInputFocused(e)}
41
- @change=${(e: InputEvent) => this._onInputChanged(e)}
42
- .placeholder=${this.getAttribute('placeholder') || ''}
43
- list="ids"
44
- ?disabled=${this.disabled}
45
- />
46
-
47
- <datalist id="ids">${ids.map(id => html` <option value=${id}></option> `)}</datalist>
48
- `
49
- }
50
-
51
- _onInputFocused(e: FocusEvent) {
52
- var { component } = this.property || {}
53
-
54
- document.dispatchEvent(
55
- new CustomEvent('get-all-scene-component-ids', {
56
- detail: {
57
- component,
58
- callback: (ids: string[]) => {
59
- this._ids = ids
60
- }
61
- }
62
- })
63
- )
64
- }
65
-
66
- _onInputChanged(e: InputEvent) {
67
- e.stopPropagation()
68
-
69
- this.value = (e.target as HTMLInputElement).value
70
-
71
- this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))
72
- }
73
- }
@@ -1,126 +0,0 @@
1
- /**
2
- * @license Copyright © HatioLab Inc. All rights reserved.
3
- */
4
-
5
- import '@material/web/icon/icon.js'
6
-
7
- // import debounce from 'lodash-es/debounce'
8
- import { css, html } from 'lit'
9
- import { customElement, property, query } from 'lit/decorators.js'
10
-
11
- import { OxFormField } from './ox-form-field'
12
-
13
- @customElement('ox-input-search')
14
- export class OxInputSearch extends OxFormField {
15
- static styles = [
16
- css`
17
- :host {
18
- display: flex;
19
- position: relative;
20
- align-items: center;
21
-
22
- color: var(--ox-input-search-color, var(--md-sys-color-on-surface-variant));
23
- background-color: var(--ox-input-search-background-color, var(--md-sys-color-surface-variant));
24
-
25
- --md-icon-size: 20px;
26
- }
27
-
28
- [type='text'] {
29
- flex: 1;
30
- color: inherit;
31
- background-color: transparent;
32
- border: 0;
33
- padding: var(--input-search-padding, var(--spacing-tiny));
34
- padding-left: 25px;
35
- overflow: hidden;
36
- }
37
-
38
- [type='text']:focus {
39
- outline: none;
40
- }
41
-
42
- md-icon {
43
- position: absolute;
44
- }
45
-
46
- input {
47
- width: 100%;
48
- }
49
- `
50
- ]
51
-
52
- @property({ type: String }) placeholder?: string
53
- @property({ attribute: 'select-after-change', type: Boolean }) selectAfterChange?: boolean
54
-
55
- @query('input') input!: HTMLInputElement
56
-
57
- // private dispatchChangeEventDebouncer = debounce((value: string) => this.dispatchChangeEvent(value), 100)
58
-
59
- render() {
60
- return html`
61
- <md-icon @click=${(e: Event) => !this.disabled && this._onClickSearch(e)}>search</md-icon>
62
- <input
63
- type="text"
64
- .value=${this.value || ''}
65
- .placeholder=${this.placeholder || ''}
66
- @change=${(e: Event) => {
67
- e.stopPropagation()
68
- this.dispatchChangeEvent((e.target as HTMLInputElement).value)
69
- // this.dispatchChangeEventDebouncer((e.target as HTMLInputElement).value)
70
- }}
71
- @keydown=${(e: KeyboardEvent) => {
72
- if (e.key === 'Enter') {
73
- if ((e.target as HTMLInputElement).value == this.value) {
74
- /* Even if the value has not changed, the enter key triggers a change event. */
75
- e.preventDefault() /* Prevent change event from occurring twice. */
76
-
77
- this.input.dispatchEvent(
78
- new CustomEvent('change', {
79
- detail: (e.target as HTMLInputElement).value
80
- })
81
- )
82
- }
83
- }
84
- }}
85
- ?disabled=${this.disabled}
86
- />
87
- `
88
- }
89
-
90
- firstUpdated() {
91
- if (this.autofocus) {
92
- this.input.focus()
93
- }
94
- }
95
-
96
- dispatchChangeEvent(value: string) {
97
- this.value = value
98
-
99
- this.dispatchEvent(
100
- new CustomEvent('change', {
101
- bubbles: true,
102
- composed: true,
103
- detail: value
104
- })
105
- )
106
-
107
- if (this.selectAfterChange) {
108
- requestAnimationFrame(() => {
109
- this.input.select()
110
- })
111
- }
112
- }
113
-
114
- _onClickSearch(e: Event) {
115
- if (this._form) {
116
- e.stopPropagation()
117
- this._form.requestSubmit()
118
- } else {
119
- this.input.dispatchEvent(
120
- new CustomEvent('change', {
121
- detail: this.input.value
122
- })
123
- )
124
- }
125
- }
126
- }
@@ -1,75 +0,0 @@
1
- /**
2
- * @license Copyright © HatioLab Inc. All rights reserved.
3
- */
4
-
5
- import '@material/web/chips/filter-chip.js'
6
- import '@material/web/chips/chip-set.js'
7
-
8
- import { css, html } from 'lit'
9
- import { customElement, property } from 'lit/decorators.js'
10
-
11
- import { OxFormField } from './ox-form-field'
12
- import { MdFilterChip } from '@material/web/chips/filter-chip.js'
13
-
14
- type Option = { display: string; value: string }
15
-
16
- @customElement('ox-input-select-buttons')
17
- export class OxInputSelectButtons extends OxFormField {
18
- static styles = css`
19
- :host {
20
- display: flex;
21
- flex-flow: row;
22
- flex-wrap: wrap;
23
- gap: var(--spacing-medium);
24
-
25
- text-transform: capitalize;
26
- }
27
- `
28
-
29
- @property({ type: Array }) value: string[] | string | undefined = []
30
- @property({ type: Array }) options: Option[] = []
31
- @property({ type: Boolean }) multiple: boolean = false
32
-
33
- render() {
34
- const options = this.options.filter(option => !!option.value)
35
- const values = this.value instanceof Array ? this.value : typeof this.value == 'string' ? [this.value] : []
36
-
37
- return html`
38
- <md-chip-set>
39
- ${(options || []).map(
40
- ({ display, value }) => html`
41
- <md-filter-chip
42
- data-value=${value}
43
- label=${display}
44
- ?selected=${values.includes(value)}
45
- @tap=${(e: MouseEvent | TouchEvent) => !this.disabled && this.onTap(e)}
46
- ></md-filter-chip>
47
- `
48
- )}
49
- </md-chip-set>
50
- `
51
- }
52
-
53
- onTap(e: MouseEvent | TouchEvent) {
54
- e.stopPropagation()
55
-
56
- const target = e.target as MdFilterChip
57
- const value = target.getAttribute('data-value') as string
58
-
59
- if (this.multiple) {
60
- const values = this.value instanceof Array ? this.value : typeof this.value == 'string' ? [this.value] : []
61
-
62
- const idx = (this.value || []).indexOf(value)
63
- if (idx != -1) {
64
- values.splice(idx, 1)
65
- } else {
66
- values.push(value)
67
- }
68
- this.value = [...values]
69
- } else {
70
- this.value = this.value === value ? undefined : value
71
- }
72
-
73
- this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }))
74
- }
75
- }
@@ -1,208 +0,0 @@
1
- import '@material/web/icon/icon.js'
2
-
3
- import { css, html, PropertyValues } from 'lit'
4
- import { customElement, property, query } from 'lit/decorators.js'
5
-
6
- import { OxFormField } from './ox-form-field.js'
7
-
8
- @customElement('ox-input-signature')
9
- export class OxInputSignature extends OxFormField {
10
- static styles = [
11
- css`
12
- :host {
13
- display: flex;
14
- flex-direction: column;
15
- min-height: var(--signature-min-height, 80px);
16
- min-width: var(--signature-min-width, 120px);
17
-
18
- background-color: var(--signature-background-color, white);
19
-
20
- overflow: hidden;
21
- }
22
-
23
- .signature-preview {
24
- flex: 1;
25
- align-self: stretch;
26
-
27
- border: 1px solid var(--md-sys-color-outline);
28
- background-size: contain;
29
- background-repeat: no-repeat;
30
- background-position: center;
31
- }
32
-
33
- dialog canvas {
34
- border: 1px solid var(--md-sys-color-outline);
35
- }
36
-
37
- .controls {
38
- margin-top: 10px;
39
- display: flex;
40
- flex-direction: row;
41
- gap: var(--spacing-medium);
42
- }
43
-
44
- .filler {
45
- flex: 1;
46
- }
47
-
48
- /* 버튼 스타일 */
49
- button {
50
- background-color: var(--md-sys-color-primary);
51
- color: var(--md-sys-color-on-primary);
52
- padding: 10px 20px;
53
- border: none;
54
- border-radius: var(--spacing-small);
55
- font-family: 'Roboto', sans-serif;
56
- font-size: 14px;
57
- cursor: pointer;
58
- transition: background-color 0.3s ease;
59
- }
60
- `
61
- ]
62
-
63
- @property({ type: String }) value: string | null = null
64
-
65
- @query('.signature-preview')
66
- private previewDiv!: HTMLDivElement
67
- @query('dialog')
68
- private dialog!: HTMLDialogElement
69
- @query('canvas')
70
- private canvas!: HTMLCanvasElement
71
-
72
- private ctx!: CanvasRenderingContext2D
73
- private isDrawing = false
74
-
75
- render() {
76
- return html`
77
- <div class="signature-preview" @click=${this.openDialog}></div>
78
-
79
- <dialog>
80
- <canvas
81
- width="800"
82
- height="400"
83
- @pointerdown=${this.startDrawing}
84
- @pointerup=${this.stopDrawing}
85
- @pointermove=${this.draw}
86
- @pointerleave=${this.stopDrawing}
87
- ></canvas>
88
- <div class="controls">
89
- <button @click="${this.clearCanvas}">Clear</button>
90
- <div class="filler"></div>
91
- <button @click="${this.saveSignature}">Save</button>
92
- <button @click="${this.closeDialog}">Close</button>
93
- </div>
94
- </dialog>
95
- `
96
- }
97
-
98
- firstUpdated() {
99
- this.ctx = this.canvas.getContext('2d')!
100
- this.ctx.strokeStyle = '#000'
101
- this.ctx.lineWidth = 2
102
-
103
- // 처음 로딩 시 서명 데이터를 미리보기 div에 표시
104
- if (this.value) {
105
- this.loadSignature(this.value)
106
- }
107
- }
108
-
109
- updated(changes: PropertyValues<this>) {
110
- if (changes.has('value')) {
111
- this.loadSignature(this.value)
112
- }
113
- }
114
-
115
- openDialog() {
116
- if (this.disabled) {
117
- return
118
- }
119
-
120
- this.dialog.showModal()
121
-
122
- if (this.value) {
123
- const img = new Image()
124
- img.onload = () => {
125
- this.ctx.drawImage(img, 0, 0, this.canvas.width, this.canvas.height)
126
- }
127
- img.src = this.value
128
- }
129
- }
130
-
131
- closeDialog() {
132
- this.dialog.close()
133
- }
134
-
135
- startDrawing(event: MouseEvent | TouchEvent) {
136
- if (this.disabled) {
137
- return
138
- }
139
-
140
- event.preventDefault()
141
- event.stopPropagation()
142
-
143
- this.isDrawing = true
144
- this.ctx.beginPath()
145
- const position = this.getEventPosition(event)
146
- this.ctx.moveTo(position.x, position.y)
147
- }
148
-
149
- stopDrawing(event: MouseEvent | TouchEvent) {
150
- event.preventDefault()
151
- event.stopPropagation()
152
-
153
- this.isDrawing = false
154
- }
155
-
156
- draw(event: MouseEvent | TouchEvent) {
157
- if (!this.isDrawing) {
158
- return
159
- }
160
-
161
- event.preventDefault()
162
- event.stopPropagation()
163
-
164
- const position = this.getEventPosition(event)
165
- this.ctx.lineTo(position.x, position.y)
166
- this.ctx.stroke()
167
- }
168
-
169
- clearCanvas() {
170
- this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height)
171
- }
172
-
173
- saveSignature() {
174
- this.value = this.canvas.toDataURL()
175
- this._notifyChange()
176
- this.previewDiv.style.backgroundImage = `url(${this.value})`
177
- this.closeDialog()
178
- }
179
-
180
- loadSignature(dataUrl: string | null) {
181
- this.previewDiv.style.backgroundImage = dataUrl ? `url(${dataUrl})` : 'none'
182
- }
183
-
184
- getEventPosition(event: MouseEvent | TouchEvent) {
185
- const rect = this.canvas.getBoundingClientRect()
186
-
187
- // 캔버스의 실제 크기와 CSS 크기 간의 비율을 계산
188
- const scaleX = this.canvas.width / rect.width
189
- const scaleY = this.canvas.height / rect.height
190
-
191
- // 실제 좌표 계산
192
- const isTouchEvent = event instanceof TouchEvent
193
- const x = (isTouchEvent ? event.touches[0].clientX - rect.left : (event as MouseEvent).clientX - rect.left) * scaleX
194
- const y = (isTouchEvent ? event.touches[0].clientY - rect.top : (event as MouseEvent).clientY - rect.top) * scaleY
195
-
196
- return { x, y }
197
- }
198
-
199
- _notifyChange() {
200
- this.dispatchEvent(
201
- new CustomEvent('change', {
202
- bubbles: true,
203
- composed: true,
204
- detail: this.value
205
- })
206
- )
207
- }
208
- }