@operato/input 7.1.30 → 7.1.32

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 (119) hide show
  1. package/CHANGELOG.md +10 -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/demo/index-3dish.html +0 -38
  9. package/demo/index-angle.html +0 -36
  10. package/demo/index-barcode.html +0 -68
  11. package/demo/index-button-radio.html +0 -42
  12. package/demo/index-checkbox.html +0 -69
  13. package/demo/index-code.html +0 -61
  14. package/demo/index-color-gradient.html +0 -35
  15. package/demo/index-color-stops.html +0 -62
  16. package/demo/index-color.html +0 -35
  17. package/demo/index-crontab.html +0 -37
  18. package/demo/index-file.html +0 -41
  19. package/demo/index-image.html +0 -40
  20. package/demo/index-multiple-colors.html +0 -52
  21. package/demo/index-options.html +0 -43
  22. package/demo/index-partition-keys.html +0 -79
  23. package/demo/index-range.html +0 -40
  24. package/demo/index-select.html +0 -136
  25. package/demo/index-stack.html +0 -33
  26. package/demo/index-table.html +0 -50
  27. package/demo/index-value-map.html +0 -80
  28. package/demo/index-value-ranges.html +0 -80
  29. package/demo/index-work-shift.html +0 -59
  30. package/demo/index.html +0 -54
  31. package/src/index.ts +0 -34
  32. package/src/locale/locale-codes.ts +0 -18
  33. package/src/locale/locale-picker.ts +0 -43
  34. package/src/locale/localization.ts +0 -15
  35. package/src/locales/en.ts +0 -30
  36. package/src/locales/ko.ts +0 -30
  37. package/src/locales/ms.ts +0 -30
  38. package/src/locales/zh.ts +0 -30
  39. package/src/ox-buttons-radio.ts +0 -140
  40. package/src/ox-checkbox.ts +0 -181
  41. package/src/ox-form-field.ts +0 -53
  42. package/src/ox-input-3axis.ts +0 -77
  43. package/src/ox-input-3dish.ts +0 -211
  44. package/src/ox-input-angle.ts +0 -73
  45. package/src/ox-input-barcode.ts +0 -318
  46. package/src/ox-input-code.ts +0 -139
  47. package/src/ox-input-color-gradient.ts +0 -349
  48. package/src/ox-input-color-stops.ts +0 -525
  49. package/src/ox-input-color.ts +0 -338
  50. package/src/ox-input-container.ts +0 -32
  51. package/src/ox-input-crontab.ts +0 -595
  52. package/src/ox-input-data.ts +0 -219
  53. package/src/ox-input-direction.ts +0 -65
  54. package/src/ox-input-duration.ts +0 -175
  55. package/src/ox-input-file.ts +0 -209
  56. package/src/ox-input-hashtags.ts +0 -185
  57. package/src/ox-input-i18n-label.ts +0 -140
  58. package/src/ox-input-image.ts +0 -168
  59. package/src/ox-input-key-values.ts +0 -301
  60. package/src/ox-input-layout/ox-input-card-layout.ts +0 -58
  61. package/src/ox-input-layout/ox-input-grid-layout.ts +0 -64
  62. package/src/ox-input-layout/ox-input-layout.ts +0 -77
  63. package/src/ox-input-mass-fraction.ts +0 -437
  64. package/src/ox-input-multiple-colors.ts +0 -135
  65. package/src/ox-input-options.ts +0 -216
  66. package/src/ox-input-partition-keys.ts +0 -303
  67. package/src/ox-input-privilege.ts +0 -163
  68. package/src/ox-input-quantifier.ts +0 -62
  69. package/src/ox-input-range.ts +0 -146
  70. package/src/ox-input-scene-component-id.ts +0 -73
  71. package/src/ox-input-search.ts +0 -126
  72. package/src/ox-input-select-buttons.ts +0 -75
  73. package/src/ox-input-signature.ts +0 -180
  74. package/src/ox-input-stack.ts +0 -136
  75. package/src/ox-input-table-column-config.ts +0 -211
  76. package/src/ox-input-table.ts +0 -404
  77. package/src/ox-input-textarea.ts +0 -86
  78. package/src/ox-input-unit-number.ts +0 -354
  79. package/src/ox-input-value-map.ts +0 -342
  80. package/src/ox-input-value-ranges.ts +0 -363
  81. package/src/ox-input-work-shift.ts +0 -290
  82. package/src/ox-select.ts +0 -219
  83. package/src/ox-zoomable-image.ts +0 -75
  84. package/stories/ox-buttons-radio.stories.ts +0 -89
  85. package/stories/ox-checkbox.stories.ts +0 -111
  86. package/stories/ox-input-3axis.stories.ts +0 -77
  87. package/stories/ox-input-3dish.stories.ts +0 -106
  88. package/stories/ox-input-angle.stories.ts +0 -84
  89. package/stories/ox-input-barcode.stories.ts +0 -117
  90. package/stories/ox-input-code.stories.ts +0 -99
  91. package/stories/ox-input-crontab.stories.ts +0 -82
  92. package/stories/ox-input-data.stories.ts +0 -82
  93. package/stories/ox-input-direction.stories.ts +0 -80
  94. package/stories/ox-input-duration.stories.ts +0 -84
  95. package/stories/ox-input-file.stories.ts +0 -111
  96. package/stories/ox-input-hashtags.stories.ts +0 -82
  97. package/stories/ox-input-i18n-label.stories.ts +0 -103
  98. package/stories/ox-input-key-values.stories.ts +0 -97
  99. package/stories/ox-input-mass-fraction.stories.ts +0 -102
  100. package/stories/ox-input-multiple-colors.stories.ts +0 -72
  101. package/stories/ox-input-options.stories.ts +0 -80
  102. package/stories/ox-input-partition-keys.stories.ts +0 -84
  103. package/stories/ox-input-privilege.stories.ts +0 -108
  104. package/stories/ox-input-quantifier.stories.ts +0 -80
  105. package/stories/ox-input-range.stories.ts +0 -89
  106. package/stories/ox-input-search.stories.ts +0 -91
  107. package/stories/ox-input-select-buttons.stories.ts +0 -118
  108. package/stories/ox-input-signature.stories.ts +0 -75
  109. package/stories/ox-input-table-column-config.stories.ts +0 -109
  110. package/stories/ox-input-unit.stories.ts +0 -151
  111. package/stories/ox-input-value-map.stories.ts +0 -92
  112. package/stories/ox-input-value-ranges.stories.ts +0 -92
  113. package/stories/ox-input-work-shift.stories.ts +0 -106
  114. package/stories/ox-select-set-options.stories.ts +0 -208
  115. package/stories/ox-select.stories.ts +0 -181
  116. package/tsconfig.json +0 -25
  117. package/web-dev-server.config.mjs +0 -27
  118. package/web-test-runner.config.mjs +0 -41
  119. package/yarn-error.log +0 -17084
@@ -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,180 +0,0 @@
1
- import '@material/web/icon/icon.js'
2
-
3
- import { css, html, nothing } from 'lit'
4
- import { customElement, property, query, state } 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
- width: 100%;
35
- height: 100%;
36
- border: 1px solid var(--md-sys-color-outline);
37
- }
38
-
39
- .controls {
40
- margin-top: 10px;
41
- display: flex;
42
- flex-direction: row;
43
- gap: var(--spacing-medium);
44
- }
45
-
46
- .filler {
47
- flex: 1;
48
- }
49
- `
50
- ]
51
-
52
- @property({ type: String }) value: string | null = null
53
-
54
- @query('.signature-preview')
55
- private previewDiv!: HTMLDivElement
56
- @query('dialog')
57
- private dialog!: HTMLDialogElement
58
- @query('canvas')
59
- private canvas!: HTMLCanvasElement
60
-
61
- private ctx!: CanvasRenderingContext2D
62
- private isDrawing = false
63
-
64
- render() {
65
- return html`
66
- <div class="signature-preview" @click=${this.openDialog}></div>
67
-
68
- <dialog>
69
- <canvas
70
- width="800"
71
- height="400"
72
- @mousedown=${this.startDrawing}
73
- @mouseup=${this.stopDrawing}
74
- @mousemove=${this.draw}
75
- @mouseleave=${this.stopDrawing}
76
- @touchstart=${this.startDrawing}
77
- @touchend=${this.stopDrawing}
78
- @touchmove=${this.draw}
79
- ></canvas>
80
- <div class="controls">
81
- <button @click="${this.clearCanvas}">Clear</button>
82
- <div class="filler"></div>
83
- <button @click="${this.saveSignature}">Save</button>
84
- <button @click="${this.closeDialog}">Close</button>
85
- </div>
86
- </dialog>
87
- `
88
- }
89
-
90
- firstUpdated() {
91
- this.ctx = this.canvas.getContext('2d')!
92
- this.ctx.strokeStyle = '#000'
93
- this.ctx.lineWidth = 2
94
-
95
- // 처음 로딩 시 서명 데이터를 미리보기 div에 표시
96
- if (this.value) {
97
- this.loadSignature(this.value)
98
- }
99
- }
100
-
101
- openDialog() {
102
- if (this.disabled) return
103
- this.dialog.showModal()
104
-
105
- // 다이아로그가 열릴 때 현재 value를 캔버스에 그리기
106
- if (this.value) {
107
- const img = new Image()
108
- img.onload = () => {
109
- this.ctx.drawImage(img, 0, 0, this.canvas.width, this.canvas.height)
110
- }
111
- img.src = this.value
112
- }
113
- }
114
-
115
- closeDialog() {
116
- this.dialog.close()
117
- }
118
-
119
- startDrawing(event: MouseEvent | TouchEvent) {
120
- if (this.disabled) {
121
- return
122
- }
123
-
124
- this.isDrawing = true
125
- this.ctx.beginPath()
126
- const position = this.getEventPosition(event)
127
- this.ctx.moveTo(position.x, position.y)
128
- }
129
-
130
- stopDrawing() {
131
- this.isDrawing = false
132
- }
133
-
134
- draw(event: MouseEvent | TouchEvent) {
135
- if (!this.isDrawing) return
136
- const position = this.getEventPosition(event)
137
- this.ctx.lineTo(position.x, position.y)
138
- this.ctx.stroke()
139
- }
140
-
141
- clearCanvas() {
142
- this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height)
143
- }
144
-
145
- saveSignature() {
146
- this.value = this.canvas.toDataURL()
147
- this._notifyChange()
148
- this.previewDiv.style.backgroundImage = `url(${this.value})`
149
- this.closeDialog()
150
- }
151
-
152
- loadSignature(dataUrl: string) {
153
- this.previewDiv.style.backgroundImage = `url(${dataUrl})`
154
- }
155
-
156
- getEventPosition(event: MouseEvent | TouchEvent) {
157
- const rect = this.canvas.getBoundingClientRect()
158
-
159
- // 캔버스의 실제 크기와 CSS 크기 간의 비율을 계산
160
- const scaleX = this.canvas.width / rect.width
161
- const scaleY = this.canvas.height / rect.height
162
-
163
- // 실제 좌표 계산
164
- const isTouchEvent = event instanceof TouchEvent
165
- const x = (isTouchEvent ? event.touches[0].clientX - rect.left : (event as MouseEvent).clientX - rect.left) * scaleX
166
- const y = (isTouchEvent ? event.touches[0].clientY - rect.top : (event as MouseEvent).clientY - rect.top) * scaleY
167
-
168
- return { x, y }
169
- }
170
-
171
- _notifyChange() {
172
- this.dispatchEvent(
173
- new CustomEvent('change', {
174
- bubbles: true,
175
- composed: true,
176
- detail: this.value
177
- })
178
- )
179
- }
180
- }