@designbasekorea/ui-wc 0.5.6 → 0.6.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 (193) hide show
  1. package/dist/chunks/lottie-35a9b0f5.js +1 -0
  2. package/dist/esm/components/animation-background/canvas-controller.js +1 -121
  3. package/dist/esm/components/animation-background/controls.js +1 -180
  4. package/dist/esm/components/animation-background/graphite-controller.js +1 -196
  5. package/dist/esm/components/animation-background/graphite-presets.js +1 -42
  6. package/dist/esm/components/animation-background/graphite-shader.js +1 -111
  7. package/dist/esm/components/animation-background/layers.js +1 -369
  8. package/dist/esm/components/animation-background/lumina-presets.js +1 -53
  9. package/dist/esm/components/animation-background/lumina-shaders.js +1 -181
  10. package/dist/esm/components/animation-background/lumina-utils.js +1 -60
  11. package/dist/esm/components/animation-background/particle-defaults.js +1 -36
  12. package/dist/esm/components/animation-background/renderers.js +1 -167
  13. package/dist/esm/components/animation-background/shader-controller.js +1 -154
  14. package/dist/esm/components/color-picker-utils.js +1 -134
  15. package/dist/esm/components/date-picker-utils.js +1 -140
  16. package/dist/esm/components/db-accordion.js +1 -304
  17. package/dist/esm/components/db-ad-banner.js +1 -455
  18. package/dist/esm/components/db-ai-chat-list.d.ts +43 -0
  19. package/dist/esm/components/db-ai-chat-list.js +1 -0
  20. package/dist/esm/components/db-ai-chat.d.ts +159 -0
  21. package/dist/esm/components/db-ai-chat.js +1 -0
  22. package/dist/esm/components/db-alert.js +1 -149
  23. package/dist/esm/components/db-animation-background.js +1 -486
  24. package/dist/esm/components/db-animation-text.js +1 -601
  25. package/dist/esm/components/db-app-badge.js +1 -88
  26. package/dist/esm/components/db-audio-player.js +1 -752
  27. package/dist/esm/components/db-avatar.js +1 -188
  28. package/dist/esm/components/db-backdrop.js +1 -139
  29. package/dist/esm/components/db-badge.js +1 -91
  30. package/dist/esm/components/db-banner.js +1 -188
  31. package/dist/esm/components/db-bottom-navigation.js +1 -146
  32. package/dist/esm/components/db-bottom-sheet.js +1 -481
  33. package/dist/esm/components/db-breadcrumbs.js +1 -329
  34. package/dist/esm/components/db-button.js +1 -316
  35. package/dist/esm/components/db-calendar.js +1 -675
  36. package/dist/esm/components/db-card.js +1 -265
  37. package/dist/esm/components/db-carousel.js +1 -264
  38. package/dist/esm/components/db-chat-composer.d.ts +134 -0
  39. package/dist/esm/components/db-chat-composer.js +1 -0
  40. package/dist/esm/components/db-chat-list.d.ts +47 -0
  41. package/dist/esm/components/db-chat-list.js +1 -0
  42. package/dist/esm/components/db-chat-message.d.ts +39 -0
  43. package/dist/esm/components/db-chat-message.js +1 -0
  44. package/dist/esm/components/db-chat-orb.d.ts +99 -0
  45. package/dist/esm/components/db-chat-orb.js +1 -0
  46. package/dist/esm/components/db-chat-room.d.ts +71 -0
  47. package/dist/esm/components/db-chat-room.js +1 -0
  48. package/dist/esm/components/db-chat-suggestions.d.ts +44 -0
  49. package/dist/esm/components/db-chat-suggestions.js +1 -0
  50. package/dist/esm/components/db-chat-typing.d.ts +22 -0
  51. package/dist/esm/components/db-chat-typing.js +1 -0
  52. package/dist/esm/components/db-chat-welcome.d.ts +32 -0
  53. package/dist/esm/components/db-chat-welcome.js +1 -0
  54. package/dist/esm/components/db-chat-widget.d.ts +146 -0
  55. package/dist/esm/components/db-chat-widget.js +1 -0
  56. package/dist/esm/components/db-checkbox.js +1 -202
  57. package/dist/esm/components/db-chip.js +1 -104
  58. package/dist/esm/components/db-code-block.js +1 -304
  59. package/dist/esm/components/db-color-picker.js +1 -746
  60. package/dist/esm/components/db-confirm.js +1 -191
  61. package/dist/esm/components/db-container.js +1 -39
  62. package/dist/esm/components/db-context-menu.js +1 -265
  63. package/dist/esm/components/db-countdown.js +1 -146
  64. package/dist/esm/components/db-cursor-follower.js +1 -173
  65. package/dist/esm/components/db-date-picker.js +1 -837
  66. package/dist/esm/components/db-divider.js +1 -66
  67. package/dist/esm/components/db-download-progress.d.ts +89 -0
  68. package/dist/esm/components/db-download-progress.js +1 -0
  69. package/dist/esm/components/db-drawer.js +1 -245
  70. package/dist/esm/components/db-dropdown.js +1 -493
  71. package/dist/esm/components/db-dropzone.js +1 -266
  72. package/dist/esm/components/db-email-verify.d.ts +64 -0
  73. package/dist/esm/components/db-email-verify.js +1 -0
  74. package/dist/esm/components/db-empty-state.js +1 -97
  75. package/dist/esm/components/db-file-uploader.js +1 -256
  76. package/dist/esm/components/db-floating-action-button.js +1 -139
  77. package/dist/esm/components/db-footer.js +1 -385
  78. package/dist/esm/components/db-form.js +1 -566
  79. package/dist/esm/components/db-gantt.js +1 -882
  80. package/dist/esm/components/db-gradient.js +1 -133
  81. package/dist/esm/components/db-grid-background.js +1 -909
  82. package/dist/esm/components/db-grid.js +1 -73
  83. package/dist/esm/components/db-icons.d.ts +3 -0
  84. package/dist/esm/components/db-icons.js +1 -82
  85. package/dist/esm/components/db-image-list.js +1 -214
  86. package/dist/esm/components/db-image-placeholder.js +1 -96
  87. package/dist/esm/components/db-image.js +1 -289
  88. package/dist/esm/components/db-indicator.js +1 -517
  89. package/dist/esm/components/db-input.js +1 -420
  90. package/dist/esm/components/db-kanban.js +1 -538
  91. package/dist/esm/components/db-label.js +1 -66
  92. package/dist/esm/components/db-lightbox.js +1 -372
  93. package/dist/esm/components/db-list.js +1 -340
  94. package/dist/esm/components/db-logo-svg.js +1 -72
  95. package/dist/esm/components/db-logo.js +1 -106
  96. package/dist/esm/components/db-lottie.js +1 -109
  97. package/dist/esm/components/db-markdown-editor.js +1 -458
  98. package/dist/esm/components/db-marquee.js +1 -402
  99. package/dist/esm/components/db-masonry.js +1 -94
  100. package/dist/esm/components/db-menu-item.js +1 -211
  101. package/dist/esm/components/db-modal.js +1 -522
  102. package/dist/esm/components/db-navbar.js +1 -680
  103. package/dist/esm/components/db-onboarding-modal.js +1 -322
  104. package/dist/esm/components/db-otp-input.d.ts +53 -0
  105. package/dist/esm/components/db-otp-input.js +1 -0
  106. package/dist/esm/components/db-page-header.js +1 -312
  107. package/dist/esm/components/db-pagination.js +1 -271
  108. package/dist/esm/components/db-phone-verify.d.ts +63 -0
  109. package/dist/esm/components/db-phone-verify.js +1 -0
  110. package/dist/esm/components/db-popover.js +1 -580
  111. package/dist/esm/components/db-progress-step.js +1 -166
  112. package/dist/esm/components/db-progress.js +1 -171
  113. package/dist/esm/components/db-progressbar.js +1 -72
  114. package/dist/esm/components/db-radio.js +1 -172
  115. package/dist/esm/components/db-random-gradient.js +1 -121
  116. package/dist/esm/components/db-range-slider.js +1 -811
  117. package/dist/esm/components/db-rating.js +1 -325
  118. package/dist/esm/components/db-reorder.js +1 -286
  119. package/dist/esm/components/db-resizable-panels.js +1 -282
  120. package/dist/esm/components/db-scroll-area.js +1 -126
  121. package/dist/esm/components/db-search-bar.js +1 -668
  122. package/dist/esm/components/db-section-app-download.js +1 -101
  123. package/dist/esm/components/db-section-contact.js +1 -102
  124. package/dist/esm/components/db-section-cta.js +1 -150
  125. package/dist/esm/components/db-section-faq.js +1 -120
  126. package/dist/esm/components/db-section-feature-grid.js +1 -137
  127. package/dist/esm/components/db-section-feature.js +1 -179
  128. package/dist/esm/components/db-section-hero.js +1 -243
  129. package/dist/esm/components/db-section-logo-cloud.js +1 -138
  130. package/dist/esm/components/db-section-pricing.js +1 -166
  131. package/dist/esm/components/db-section-stats.js +1 -129
  132. package/dist/esm/components/db-section-testimonials.js +1 -252
  133. package/dist/esm/components/db-section.js +1 -385
  134. package/dist/esm/components/db-segment-control.js +1 -231
  135. package/dist/esm/components/db-select.js +1 -571
  136. package/dist/esm/components/db-share-icons.js +1 -40
  137. package/dist/esm/components/db-share.js +1 -489
  138. package/dist/esm/components/db-sidebar.d.ts +20 -0
  139. package/dist/esm/components/db-sidebar.js +1 -1068
  140. package/dist/esm/components/db-skeleton.js +1 -94
  141. package/dist/esm/components/db-spinner.js +1 -102
  142. package/dist/esm/components/db-split-view.js +1 -297
  143. package/dist/esm/components/db-stack.js +1 -46
  144. package/dist/esm/components/db-stat.js +1 -218
  145. package/dist/esm/components/db-stepper.js +1 -398
  146. package/dist/esm/components/db-table.js +1 -412
  147. package/dist/esm/components/db-tabs.js +1 -335
  148. package/dist/esm/components/db-testimonial.d.ts +2 -0
  149. package/dist/esm/components/db-testimonial.js +1 -162
  150. package/dist/esm/components/db-textarea.js +1 -233
  151. package/dist/esm/components/db-time-picker.js +1 -523
  152. package/dist/esm/components/db-timeline.js +1 -174
  153. package/dist/esm/components/db-toast.js +1 -158
  154. package/dist/esm/components/db-toggle.js +1 -162
  155. package/dist/esm/components/db-toolbar.js +1 -94
  156. package/dist/esm/components/db-tooltip.js +1 -440
  157. package/dist/esm/components/db-top-banner.js +1 -121
  158. package/dist/esm/components/db-tutorial.js +1 -324
  159. package/dist/esm/components/db-two-factor.d.ts +71 -0
  160. package/dist/esm/components/db-two-factor.js +1 -0
  161. package/dist/esm/components/db-video-player.js +1 -503
  162. package/dist/esm/components/db-youtube-player.js +1 -194
  163. package/dist/esm/components/highlight-code.js +1 -65
  164. package/dist/esm/components/input-validation.js +1 -50
  165. package/dist/esm/components/marketing-block-host-utils.js +1 -9
  166. package/dist/esm/components/number-scrub.js +1 -117
  167. package/dist/esm/components/random-gradient-palettes.js +1 -67
  168. package/dist/esm/components/section-block-header-utils.js +1 -48
  169. package/dist/esm/helpers/confirm.js +1 -52
  170. package/dist/esm/helpers/toast.js +1 -73
  171. package/dist/esm/index.d.ts +16 -0
  172. package/dist/esm/index.js +1 -111
  173. package/dist/esm/node_modules/prismjs/components/prism-bash.js +1 -235
  174. package/dist/esm/node_modules/prismjs/components/prism-clike.js +1 -31
  175. package/dist/esm/node_modules/prismjs/components/prism-css.js +1 -64
  176. package/dist/esm/node_modules/prismjs/components/prism-javascript.js +1 -172
  177. package/dist/esm/node_modules/prismjs/components/prism-json.js +1 -27
  178. package/dist/esm/node_modules/prismjs/components/prism-jsx.js +1 -143
  179. package/dist/esm/node_modules/prismjs/components/prism-markup.js +1 -186
  180. package/dist/esm/node_modules/prismjs/components/prism-scss.js +1 -81
  181. package/dist/esm/node_modules/prismjs/components/prism-tsx.js +1 -15
  182. package/dist/esm/node_modules/prismjs/components/prism-typescript.js +1 -60
  183. package/dist/index.cjs +1 -55414
  184. package/dist/index.css +1 -1
  185. package/dist/index.d.ts +1125 -2
  186. package/dist/index.esm.js +1 -38284
  187. package/dist/react/chunks/lottie-14e7addb.js +1 -0
  188. package/dist/react/index.cjs +1 -56503
  189. package/dist/react/index.d.ts +1637 -21
  190. package/dist/react/index.esm.js +1 -39373
  191. package/package.json +2 -2
  192. package/dist/chunks/lottie-e273b936.js +0 -17032
  193. package/dist/react/chunks/lottie-72a4c6d4.js +0 -17032
@@ -1,420 +1 @@
1
- import { getDbComponentIconSize, createDbIcon } from './db-icons.js';
2
- import { getPasswordValidation } from './input-validation.js';
3
- import { attachNumberScrub, readNumericAttribute } from './number-scrub.js';
4
-
5
- const TYPES = ['text', 'email', 'password', 'url', 'search', 'tel', 'number'];
6
- const SIZES = ['s', 'm', 'l'];
7
- const ICON_NAMES = new Set([
8
- 'arrow-bar-left', 'arrow-bar-right', 'caret-down-filled', 'chevron-down', 'chevron-left',
9
- 'chevron-right', 'circle-checked', 'close', 'error-filled', 'edit', 'hide', 'info-filled',
10
- 'lock', 'mail', 'plus', 'search', 'share-alt', 'show', 'sparkle', 'trash', 'user', 'warning-filled',
11
- ]);
12
- class DbInput extends HTMLElement {
13
- constructor() {
14
- super(...arguments);
15
- this.passwordVisible = false;
16
- this.isFocused = false;
17
- this.touched = false;
18
- this.isScrubbing = false;
19
- this.handleInput = (event) => {
20
- event.stopPropagation();
21
- const target = event.target;
22
- this.updateDynamicUI();
23
- this.dispatchEvent(new InputEvent('input', { bubbles: true, composed: true }));
24
- this.dispatchEvent(new CustomEvent('db-input', {
25
- detail: { value: target.value, nativeEvent: event },
26
- bubbles: true,
27
- composed: true,
28
- }));
29
- };
30
- this.handleChange = (event) => {
31
- event.stopPropagation();
32
- const target = event.target;
33
- this.dispatchEvent(new Event('change', { bubbles: true }));
34
- this.dispatchEvent(new CustomEvent('db-change', {
35
- detail: { value: target.value, nativeEvent: event },
36
- bubbles: true,
37
- composed: true,
38
- }));
39
- };
40
- this.handleFocus = (event) => {
41
- this.isFocused = true;
42
- this.updateDynamicUI();
43
- this.dispatchEvent(new CustomEvent('db-focus', {
44
- detail: { nativeEvent: event },
45
- bubbles: true,
46
- composed: true,
47
- }));
48
- };
49
- this.handleBlur = (event) => {
50
- this.isFocused = false;
51
- this.touched = true;
52
- this.updateDynamicUI();
53
- this.dispatchEvent(new CustomEvent('db-blur', {
54
- detail: { nativeEvent: event },
55
- bubbles: true,
56
- composed: true,
57
- }));
58
- };
59
- this.handlePasswordToggle = () => {
60
- this.passwordVisible = !this.passwordVisible;
61
- this.render();
62
- };
63
- this.handleSearchClear = () => {
64
- if (!this.input)
65
- return;
66
- this.input.value = '';
67
- this.setAttribute('value', '');
68
- this.input.focus();
69
- this.updateDynamicUI();
70
- this.dispatchEvent(new CustomEvent('db-input', {
71
- detail: { value: '', nativeEvent: null },
72
- bubbles: true,
73
- composed: true,
74
- }));
75
- this.dispatchEvent(new CustomEvent('db-clear', {
76
- bubbles: true,
77
- composed: true,
78
- }));
79
- };
80
- }
81
- static get observedAttributes() {
82
- return [
83
- 'type',
84
- 'label',
85
- 'placeholder',
86
- 'value',
87
- 'default-value',
88
- 'size',
89
- 'disabled',
90
- 'readonly',
91
- 'required',
92
- 'error',
93
- 'error-message',
94
- 'helper-text',
95
- 'full-width',
96
- 'name',
97
- 'start-icon',
98
- 'end-icon',
99
- 'validate',
100
- 'validation-visibility',
101
- 'validate-on-blur',
102
- 'password-min-length',
103
- 'scrubbable',
104
- 'scrub-step',
105
- 'scrub-sensitivity',
106
- 'min',
107
- 'max',
108
- 'step',
109
- ];
110
- }
111
- get value() {
112
- return this.input?.value ?? this.getAttribute('value') ?? '';
113
- }
114
- set value(value) {
115
- this.setAttribute('value', value);
116
- if (this.input)
117
- this.input.value = value;
118
- this.updateDynamicUI();
119
- }
120
- get type() {
121
- return this.getAttribute('type') || 'text';
122
- }
123
- set type(value) {
124
- this.setAttribute('type', value);
125
- }
126
- get size() {
127
- return this.getAttribute('size') || 'm';
128
- }
129
- set size(value) {
130
- this.setAttribute('size', value);
131
- }
132
- get disabled() {
133
- return this.hasAttribute('disabled');
134
- }
135
- set disabled(value) {
136
- this.toggleAttribute('disabled', value);
137
- }
138
- get readOnly() {
139
- return this.hasAttribute('readonly');
140
- }
141
- set readOnly(value) {
142
- this.toggleAttribute('readonly', value);
143
- }
144
- connectedCallback() {
145
- this.render();
146
- }
147
- disconnectedCallback() {
148
- this.detachScrub?.();
149
- this.detachScrub = undefined;
150
- }
151
- attributeChangedCallback(name) {
152
- if (name === 'value' && this.isScrubbing)
153
- return;
154
- if (name === 'value' && this.input) {
155
- const next = this.getAttribute('value') ?? '';
156
- if (this.input.value !== next)
157
- this.input.value = next;
158
- this.updateDynamicUI();
159
- return;
160
- }
161
- this.render();
162
- }
163
- focus() {
164
- this.input?.focus();
165
- }
166
- get passwordMinLength() {
167
- return Number(this.getAttribute('password-min-length') || 8);
168
- }
169
- get validationVisibility() {
170
- return this.getAttribute('validation-visibility') || 'focus';
171
- }
172
- get validateOnBlur() {
173
- return !this.hasAttribute('validate-on-blur') || this.getAttribute('validate-on-blur') !== 'false';
174
- }
175
- get isValidationEnabled() {
176
- return this.hasAttribute('validate');
177
- }
178
- getIconSize() {
179
- return getDbComponentIconSize(this.size);
180
- }
181
- resolveIconName(attribute) {
182
- const value = this.getAttribute(attribute);
183
- if (value && ICON_NAMES.has(value))
184
- return value;
185
- return undefined;
186
- }
187
- resolveStartIcon() {
188
- const explicit = this.resolveIconName('start-icon');
189
- if (explicit)
190
- return explicit;
191
- if (this.type === 'search')
192
- return 'search';
193
- return undefined;
194
- }
195
- getCurrentValue() {
196
- return this.input?.value ?? this.getAttribute('value') ?? this.getAttribute('default-value') ?? '';
197
- }
198
- render() {
199
- const value = this.getCurrentValue();
200
- const type = TYPES.includes(this.type) ? this.type : 'text';
201
- const isSearch = type === 'search';
202
- const isPassword = type === 'password';
203
- const actualType = isPassword && this.passwordVisible ? 'text' : isSearch ? 'text' : type;
204
- const label = this.getAttribute('label') || '';
205
- const helperText = this.getAttribute('helper-text') || '';
206
- const errorMessage = this.getAttribute('error-message') || '';
207
- const hasError = this.hasAttribute('error');
208
- const startIcon = this.resolveStartIcon();
209
- const endIcon = this.resolveIconName('end-icon');
210
- this.classList.add('designbase-wc-input');
211
- SIZES.forEach((size) => this.classList.remove(`designbase-wc-input--${size}`));
212
- this.classList.add(`designbase-wc-input--${SIZES.includes(this.size) ? this.size : 'm'}`);
213
- this.classList.toggle('designbase-wc-input--error', hasError);
214
- this.classList.toggle('designbase-wc-input--disabled', this.disabled);
215
- this.classList.toggle('designbase-wc-input--readonly', this.readOnly);
216
- this.classList.toggle('designbase-wc-input--full-width', this.hasAttribute('full-width'));
217
- this.classList.toggle('designbase-wc-input--with-start-icon', Boolean(startIcon));
218
- const showSearchClear = isSearch && value.length > 0 && !this.disabled && !this.readOnly;
219
- this.classList.toggle('designbase-wc-input--with-end-icon', Boolean(endIcon && !isPassword && !isSearch) || isPassword || showSearchClear);
220
- this.classList.toggle('designbase-wc-input--with-password-toggle', isPassword);
221
- this.classList.toggle('designbase-wc-input--with-search-clear', showSearchClear);
222
- const isScrubbable = this.hasAttribute('scrubbable') && type === 'number' && !this.disabled && !this.readOnly;
223
- this.classList.toggle('designbase-wc-input--scrubbable', isScrubbable);
224
- this.classList.toggle('designbase-wc-input--scrubbing', this.isScrubbing);
225
- const id = this.getAttribute('id') || `db-input-${Math.random().toString(36).slice(2)}`;
226
- if (!this.hasAttribute('id'))
227
- this.setAttribute('id', id);
228
- const fieldId = `${id}-field`;
229
- const helperId = `${id}-helper`;
230
- const errorId = `${id}-error`;
231
- const validationId = `${id}-validation`;
232
- const min = this.getAttribute('min');
233
- const max = this.getAttribute('max');
234
- const step = this.getAttribute('step');
235
- this.innerHTML = `
236
- ${label ? `<label class="designbase-wc-input__label" for="${fieldId}">${this.escape(label)}${this.hasAttribute('required') ? '<span aria-hidden="true"> *</span>' : ''}</label>` : ''}
237
- <span class="designbase-wc-input__wrapper">
238
- ${startIcon ? '<span class="designbase-wc-input__start-icon" aria-hidden="true"></span>' : ''}
239
- <input
240
- id="${fieldId}"
241
- class="designbase-wc-input__field"
242
- type="${actualType}"
243
- value="${this.escape(value)}"
244
- placeholder="${this.escape(this.getAttribute('placeholder') || '')}"
245
- ${isSearch ? 'role="searchbox"' : ''}
246
- ${this.getAttribute('name') ? `name="${this.escape(this.getAttribute('name') || '')}"` : ''}
247
- ${this.disabled ? 'disabled' : ''}
248
- ${this.readOnly ? 'readonly' : ''}
249
- ${this.hasAttribute('required') ? 'required' : ''}
250
- ${min !== null ? `min="${this.escape(min)}"` : ''}
251
- ${max !== null ? `max="${this.escape(max)}"` : ''}
252
- ${step !== null ? `step="${this.escape(step)}"` : ''}
253
- aria-invalid="${String(hasError)}"
254
- />
255
- ${isPassword ? `<button type="button" class="designbase-wc-input__password-toggle" ${this.disabled ? 'disabled' : ''} aria-label="${this.passwordVisible ? '비밀번호 숨기기' : '비밀번호 보기'}"></button>` : ''}
256
- ${isSearch ? `<button type="button" class="designbase-wc-input__clear-button" hidden aria-label="검색어 지우기"></button>` : ''}
257
- ${endIcon && !isPassword && !isSearch ? '<span class="designbase-wc-input__end-icon" aria-hidden="true"></span>' : ''}
258
- </span>
259
- ${this.isValidationEnabled && isPassword ? `<div class="designbase-wc-input__validation-slot" id="${validationId}"></div>` : ''}
260
- ${helperText && !hasError ? `<p id="${helperId}" class="designbase-wc-input__helper-text">${this.escape(helperText)}</p>` : ''}
261
- ${hasError && errorMessage ? `<p id="${errorId}" class="designbase-wc-input__error-message">${this.escape(errorMessage)}</p>` : ''}
262
- `;
263
- this.mountIcons(startIcon, endIcon && !isPassword && !isSearch ? endIcon : undefined, isPassword);
264
- this.input = this.querySelector('input') || undefined;
265
- if (this.input) {
266
- this.input.value = value;
267
- this.input.addEventListener('input', this.handleInput);
268
- this.input.addEventListener('change', this.handleChange);
269
- this.input.addEventListener('focus', this.handleFocus);
270
- this.input.addEventListener('blur', this.handleBlur);
271
- }
272
- this.querySelector('.designbase-wc-input__password-toggle')
273
- ?.addEventListener('click', this.handlePasswordToggle);
274
- this.querySelector('.designbase-wc-input__clear-button')
275
- ?.addEventListener('click', this.handleSearchClear);
276
- this.detachScrub?.();
277
- this.detachScrub = undefined;
278
- if (isScrubbable && this.input) {
279
- this.detachScrub = attachNumberScrub(this.input, {
280
- isEnabled: () => this.hasAttribute('scrubbable') && this.type === 'number',
281
- isInteractive: () => !this.disabled && !this.readOnly,
282
- getValue: () => this.getCurrentValue(),
283
- getStep: () => readNumericAttribute(this, 'scrub-step') ?? readNumericAttribute(this, 'step') ?? 1,
284
- getMin: () => readNumericAttribute(this, 'min'),
285
- getMax: () => readNumericAttribute(this, 'max'),
286
- getSensitivity: () => readNumericAttribute(this, 'scrub-sensitivity') ?? 4,
287
- onValueChange: (nextValue) => this.applyScrubValue(nextValue),
288
- onScrubStateChange: (active) => {
289
- this.isScrubbing = active;
290
- this.classList.toggle('designbase-wc-input--scrubbing', active);
291
- if (!active && this.input) {
292
- this.dispatchEvent(new CustomEvent('db-change', {
293
- detail: { value: this.input.value, nativeEvent: null },
294
- bubbles: true,
295
- composed: true,
296
- }));
297
- }
298
- },
299
- });
300
- }
301
- this.updateDynamicUI();
302
- }
303
- mountIcons(startIcon, endIcon, isPassword = false) {
304
- const iconSize = this.getIconSize();
305
- if (startIcon) {
306
- const host = this.querySelector('.designbase-wc-input__start-icon');
307
- host?.replaceChildren(createDbIcon(startIcon, iconSize));
308
- }
309
- if (endIcon) {
310
- const host = this.querySelector('.designbase-wc-input__end-icon');
311
- host?.replaceChildren(createDbIcon(endIcon, iconSize));
312
- }
313
- if (isPassword) {
314
- const toggle = this.querySelector('.designbase-wc-input__password-toggle');
315
- toggle?.replaceChildren(createDbIcon(this.passwordVisible ? 'hide' : 'show', iconSize));
316
- }
317
- const clearButton = this.querySelector('.designbase-wc-input__clear-button');
318
- clearButton?.replaceChildren(createDbIcon('close', iconSize));
319
- }
320
- shouldShowPasswordValidation(value) {
321
- if (!this.isValidationEnabled || this.type !== 'password')
322
- return false;
323
- if (this.validationVisibility === 'never')
324
- return false;
325
- if (this.validationVisibility === 'always')
326
- return true;
327
- return this.isFocused || value.length > 0;
328
- }
329
- renderValidationMarkup(value) {
330
- const validation = getPasswordValidation(value, this.passwordMinLength);
331
- const segments = Array.from({ length: 4 }, (_, index) => {
332
- const active = index < validation.score;
333
- const levelClass = active ? ` designbase-wc-input__password-strength-segment--${validation.level}` : '';
334
- return `<span class="designbase-wc-input__password-strength-segment${levelClass}"></span>`;
335
- }).join('');
336
- const requirements = validation.requirements.map((requirement) => {
337
- const metClass = requirement.met ? ' designbase-wc-input__password-requirement--met' : '';
338
- const icon = requirement.met
339
- ? '<span class="designbase-wc-input__password-requirement-icon" aria-hidden="true"></span>'
340
- : '<span class="designbase-wc-input__password-requirement-icon" aria-hidden="true"><span class="designbase-wc-input__password-requirement-dot"></span></span>';
341
- return `<li class="designbase-wc-input__password-requirement${metClass}">${icon}<span class="designbase-wc-input__password-requirement-label">${this.escape(requirement.label)}</span></li>`;
342
- }).join('');
343
- return `
344
- <div class="designbase-wc-input__validation" aria-live="polite">
345
- <div class="designbase-wc-input__password-strength">
346
- <div class="designbase-wc-input__password-strength-bar" role="progressbar" aria-valuemin="0" aria-valuemax="4" aria-valuenow="${validation.score}" aria-label="비밀번호 강도">${segments}</div>
347
- <span class="designbase-wc-input__password-strength-label designbase-wc-input__password-strength-label--${validation.level}">${validation.levelLabel}</span>
348
- </div>
349
- <ul class="designbase-wc-input__password-requirements">${requirements}</ul>
350
- </div>
351
- `;
352
- }
353
- updateDynamicUI() {
354
- const value = this.getCurrentValue();
355
- const isSearch = this.type === 'search';
356
- const showSearchClear = isSearch && value.length > 0 && !this.disabled && !this.readOnly;
357
- this.classList.toggle('designbase-wc-input--with-search-clear', showSearchClear);
358
- const clearButton = this.querySelector('.designbase-wc-input__clear-button');
359
- if (clearButton) {
360
- clearButton.hidden = !showSearchClear;
361
- clearButton.replaceChildren(createDbIcon('close', this.getIconSize()));
362
- }
363
- const validationSlot = this.querySelector('.designbase-wc-input__validation-slot');
364
- if (validationSlot) {
365
- if (this.shouldShowPasswordValidation(value)) {
366
- validationSlot.innerHTML = this.renderValidationMarkup(value);
367
- validationSlot.querySelectorAll('.designbase-wc-input__password-requirement--met .designbase-wc-input__password-requirement-icon')
368
- .forEach((iconHost) => {
369
- iconHost.replaceChildren(createDbIcon('circle-checked', 12));
370
- });
371
- }
372
- else {
373
- validationSlot.innerHTML = '';
374
- }
375
- }
376
- if (this.input) {
377
- const helperId = `${this.getAttribute('id')}-helper`;
378
- const errorId = `${this.getAttribute('id')}-error`;
379
- const validationId = `${this.getAttribute('id')}-validation`;
380
- const helperText = this.getAttribute('helper-text') || '';
381
- const errorMessage = this.getAttribute('error-message') || '';
382
- const hasError = this.hasAttribute('error');
383
- const describedBy = [
384
- helperText && !hasError ? helperId : '',
385
- this.shouldShowPasswordValidation(value) ? validationId : '',
386
- hasError && errorMessage ? errorId : '',
387
- ].filter(Boolean).join(' ') || undefined;
388
- if (describedBy)
389
- this.input.setAttribute('aria-describedby', describedBy);
390
- else
391
- this.input.removeAttribute('aria-describedby');
392
- }
393
- }
394
- applyScrubValue(nextValue) {
395
- if (!this.input)
396
- return;
397
- this.input.value = nextValue;
398
- this.setAttribute('value', nextValue);
399
- this.updateDynamicUI();
400
- this.dispatchEvent(new CustomEvent('db-input', {
401
- detail: { value: nextValue, nativeEvent: null },
402
- bubbles: true,
403
- composed: true,
404
- }));
405
- }
406
- escape(value) {
407
- return value.replace(/[&<>"']/g, (char) => ({
408
- '&': '&amp;',
409
- '<': '&lt;',
410
- '>': '&gt;',
411
- '"': '&quot;',
412
- "'": '&#39;',
413
- }[char] || char));
414
- }
415
- }
416
- if (!customElements.get('db-input')) {
417
- customElements.define('db-input', DbInput);
418
- }
419
-
420
- export { DbInput };
1
+ import{getDbComponentIconSize as t,createDbIcon as e}from"./db-icons.js";import{getPasswordValidation as s}from"./input-validation.js";import{attachNumberScrub as i,readNumericAttribute as n}from"./number-scrub.js";const a=["text","email","password","url","search","tel","number"],r=["s","m","l"],l=new Set(["arrow-bar-left","arrow-bar-right","caret-down-filled","chevron-down","chevron-left","chevron-right","circle-checked","close","error-filled","edit","hide","info-filled","lock","mail","plus","search","share-alt","show","sparkle","trash","user","warning-filled"]);class DbInput extends HTMLElement{constructor(){super(...arguments),this.passwordVisible=!1,this.isFocused=!1,this.touched=!1,this.isScrubbing=!1,this.handleInput=t=>{t.stopPropagation();const e=t.target;this.updateDynamicUI(),this.dispatchEvent(new InputEvent("input",{bubbles:!0,composed:!0})),this.dispatchEvent(new CustomEvent("db-input",{detail:{value:e.value,nativeEvent:t},bubbles:!0,composed:!0}))},this.handleChange=t=>{t.stopPropagation();const e=t.target;this.dispatchEvent(new Event("change",{bubbles:!0})),this.dispatchEvent(new CustomEvent("db-change",{detail:{value:e.value,nativeEvent:t},bubbles:!0,composed:!0}))},this.handleFocus=t=>{this.isFocused=!0,this.updateDynamicUI(),this.dispatchEvent(new CustomEvent("db-focus",{detail:{nativeEvent:t},bubbles:!0,composed:!0}))},this.handleBlur=t=>{this.isFocused=!1,this.touched=!0,this.updateDynamicUI(),this.dispatchEvent(new CustomEvent("db-blur",{detail:{nativeEvent:t},bubbles:!0,composed:!0}))},this.handlePasswordToggle=()=>{this.passwordVisible=!this.passwordVisible,this.render()},this.handleSearchClear=()=>{this.input&&(this.input.value="",this.setAttribute("value",""),this.input.focus(),this.updateDynamicUI(),this.dispatchEvent(new CustomEvent("db-input",{detail:{value:"",nativeEvent:null},bubbles:!0,composed:!0})),this.dispatchEvent(new CustomEvent("db-clear",{bubbles:!0,composed:!0})))}}static get observedAttributes(){return["type","label","placeholder","value","default-value","size","disabled","readonly","required","error","error-message","helper-text","full-width","name","start-icon","end-icon","validate","validation-visibility","validate-on-blur","password-min-length","scrubbable","scrub-step","scrub-sensitivity","min","max","step"]}get value(){return this.input?.value??this.getAttribute("value")??""}set value(t){this.setAttribute("value",t),this.input&&(this.input.value=t),this.updateDynamicUI()}get type(){return this.getAttribute("type")||"text"}set type(t){this.setAttribute("type",t)}get size(){return this.getAttribute("size")||"m"}set size(t){this.setAttribute("size",t)}get disabled(){return this.hasAttribute("disabled")}set disabled(t){this.toggleAttribute("disabled",t)}get readOnly(){return this.hasAttribute("readonly")}set readOnly(t){this.toggleAttribute("readonly",t)}connectedCallback(){this.render()}disconnectedCallback(){this.detachScrub?.(),this.detachScrub=void 0}attributeChangedCallback(t){if("value"!==t||!this.isScrubbing){if("value"===t&&this.input){const t=this.getAttribute("value")??"";return this.input.value!==t&&(this.input.value=t),void this.updateDynamicUI()}this.render()}}focus(){this.input?.focus()}get passwordMinLength(){return Number(this.getAttribute("password-min-length")||8)}get validationVisibility(){return this.getAttribute("validation-visibility")||"focus"}get validateOnBlur(){return!this.hasAttribute("validate-on-blur")||"false"!==this.getAttribute("validate-on-blur")}get isValidationEnabled(){return this.hasAttribute("validate")}getIconSize(){return t(this.size)}resolveIconName(t){const e=this.getAttribute(t);if(e&&l.has(e))return e}resolveStartIcon(){const t=this.resolveIconName("start-icon");return t||("search"===this.type?"search":void 0)}getCurrentValue(){return this.input?.value??this.getAttribute("value")??this.getAttribute("default-value")??""}render(){const t=this.getCurrentValue(),e=a.includes(this.type)?this.type:"text",s="search"===e,l="password"===e,u=l&&this.passwordVisible||s?"text":e,d=this.getAttribute("label")||"",h=this.getAttribute("helper-text")||"",c=this.getAttribute("error-message")||"",o=this.hasAttribute("error"),b=this.resolveStartIcon(),p=this.resolveIconName("end-icon");this.classList.add("designbase-wc-input"),r.forEach(t=>this.classList.remove(`designbase-wc-input--${t}`)),this.classList.add(`designbase-wc-input--${r.includes(this.size)?this.size:"m"}`),this.classList.toggle("designbase-wc-input--error",o),this.classList.toggle("designbase-wc-input--disabled",this.disabled),this.classList.toggle("designbase-wc-input--readonly",this.readOnly),this.classList.toggle("designbase-wc-input--full-width",this.hasAttribute("full-width")),this.classList.toggle("designbase-wc-input--with-start-icon",Boolean(b));const g=s&&t.length>0&&!this.disabled&&!this.readOnly;this.classList.toggle("designbase-wc-input--with-end-icon",Boolean(p&&!l&&!s)||l||g),this.classList.toggle("designbase-wc-input--with-password-toggle",l),this.classList.toggle("designbase-wc-input--with-search-clear",g);const v=this.hasAttribute("scrubbable")&&"number"===e&&!this.disabled&&!this.readOnly;this.classList.toggle("designbase-wc-input--scrubbable",v),this.classList.toggle("designbase-wc-input--scrubbing",this.isScrubbing);const w=this.getAttribute("id")||`db-input-${Math.random().toString(36).slice(2)}`;this.hasAttribute("id")||this.setAttribute("id",w);const m=`${w}-field`,_=`${w}-helper`,y=`${w}-error`,$=`${w}-validation`,A=this.getAttribute("min"),E=this.getAttribute("max"),S=this.getAttribute("step");this.innerHTML=`\n ${d?`<label class="designbase-wc-input__label" for="${m}">${this.escape(d)}${this.hasAttribute("required")?'<span aria-hidden="true"> *</span>':""}</label>`:""}\n <span class="designbase-wc-input__wrapper">\n ${b?'<span class="designbase-wc-input__start-icon" aria-hidden="true"></span>':""}\n <input\n id="${m}"\n class="designbase-wc-input__field"\n type="${u}"\n value="${this.escape(t)}"\n placeholder="${this.escape(this.getAttribute("placeholder")||"")}"\n ${s?'role="searchbox"':""}\n ${this.getAttribute("name")?`name="${this.escape(this.getAttribute("name")||"")}"`:""}\n ${this.disabled?"disabled":""}\n ${this.readOnly?"readonly":""}\n ${this.hasAttribute("required")?"required":""}\n ${null!==A?`min="${this.escape(A)}"`:""}\n ${null!==E?`max="${this.escape(E)}"`:""}\n ${null!==S?`step="${this.escape(S)}"`:""}\n aria-invalid="${String(o)}"\n />\n ${l?`<button type="button" class="designbase-wc-input__password-toggle" ${this.disabled?"disabled":""} aria-label="${this.passwordVisible?"비밀번호 숨기기":"비밀번호 보기"}"></button>`:""}\n ${s?'<button type="button" class="designbase-wc-input__clear-button" hidden aria-label="검색어 지우기"></button>':""}\n ${!p||l||s?"":'<span class="designbase-wc-input__end-icon" aria-hidden="true"></span>'}\n </span>\n ${this.isValidationEnabled&&l?`<div class="designbase-wc-input__validation-slot" id="${$}"></div>`:""}\n ${h&&!o?`<p id="${_}" class="designbase-wc-input__helper-text">${this.escape(h)}</p>`:""}\n ${o&&c?`<p id="${y}" class="designbase-wc-input__error-message">${this.escape(c)}</p>`:""}\n `,this.mountIcons(b,!p||l||s?void 0:p,l),this.input=this.querySelector("input")||void 0,this.input&&(this.input.value=t,this.input.addEventListener("input",this.handleInput),this.input.addEventListener("change",this.handleChange),this.input.addEventListener("focus",this.handleFocus),this.input.addEventListener("blur",this.handleBlur)),this.querySelector(".designbase-wc-input__password-toggle")?.addEventListener("click",this.handlePasswordToggle),this.querySelector(".designbase-wc-input__clear-button")?.addEventListener("click",this.handleSearchClear),this.detachScrub?.(),this.detachScrub=void 0,v&&this.input&&(this.detachScrub=i(this.input,{isEnabled:()=>this.hasAttribute("scrubbable")&&"number"===this.type,isInteractive:()=>!this.disabled&&!this.readOnly,getValue:()=>this.getCurrentValue(),getStep:()=>n(this,"scrub-step")??n(this,"step")??1,getMin:()=>n(this,"min"),getMax:()=>n(this,"max"),getSensitivity:()=>n(this,"scrub-sensitivity")??4,onValueChange:t=>this.applyScrubValue(t),onScrubStateChange:t=>{this.isScrubbing=t,this.classList.toggle("designbase-wc-input--scrubbing",t),!t&&this.input&&this.dispatchEvent(new CustomEvent("db-change",{detail:{value:this.input.value,nativeEvent:null},bubbles:!0,composed:!0}))}})),this.updateDynamicUI()}mountIcons(t,s,i=!1){const n=this.getIconSize();if(t){const s=this.querySelector(".designbase-wc-input__start-icon");s?.replaceChildren(e(t,n))}if(s){const t=this.querySelector(".designbase-wc-input__end-icon");t?.replaceChildren(e(s,n))}if(i){const t=this.querySelector(".designbase-wc-input__password-toggle");t?.replaceChildren(e(this.passwordVisible?"hide":"show",n))}const a=this.querySelector(".designbase-wc-input__clear-button");a?.replaceChildren(e("close",n))}shouldShowPasswordValidation(t){return!(!this.isValidationEnabled||"password"!==this.type)&&("never"!==this.validationVisibility&&("always"===this.validationVisibility||(this.isFocused||t.length>0)))}renderValidationMarkup(t){const e=s(t,this.passwordMinLength),i=Array.from({length:4},(t,s)=>`<span class="designbase-wc-input__password-strength-segment${s<e.score?` designbase-wc-input__password-strength-segment--${e.level}`:""}"></span>`).join(""),n=e.requirements.map(t=>`<li class="designbase-wc-input__password-requirement${t.met?" designbase-wc-input__password-requirement--met":""}">${t.met?'<span class="designbase-wc-input__password-requirement-icon" aria-hidden="true"></span>':'<span class="designbase-wc-input__password-requirement-icon" aria-hidden="true"><span class="designbase-wc-input__password-requirement-dot"></span></span>'}<span class="designbase-wc-input__password-requirement-label">${this.escape(t.label)}</span></li>`).join("");return`\n <div class="designbase-wc-input__validation" aria-live="polite">\n <div class="designbase-wc-input__password-strength">\n <div class="designbase-wc-input__password-strength-bar" role="progressbar" aria-valuemin="0" aria-valuemax="4" aria-valuenow="${e.score}" aria-label="비밀번호 강도">${i}</div>\n <span class="designbase-wc-input__password-strength-label designbase-wc-input__password-strength-label--${e.level}">${e.levelLabel}</span>\n </div>\n <ul class="designbase-wc-input__password-requirements">${n}</ul>\n </div>\n `}updateDynamicUI(){const t=this.getCurrentValue(),s="search"===this.type&&t.length>0&&!this.disabled&&!this.readOnly;this.classList.toggle("designbase-wc-input--with-search-clear",s);const i=this.querySelector(".designbase-wc-input__clear-button");i&&(i.hidden=!s,i.replaceChildren(e("close",this.getIconSize())));const n=this.querySelector(".designbase-wc-input__validation-slot");if(n&&(this.shouldShowPasswordValidation(t)?(n.innerHTML=this.renderValidationMarkup(t),n.querySelectorAll(".designbase-wc-input__password-requirement--met .designbase-wc-input__password-requirement-icon").forEach(t=>{t.replaceChildren(e("circle-checked",12))})):n.innerHTML=""),this.input){const e=`${this.getAttribute("id")}-helper`,s=`${this.getAttribute("id")}-error`,i=`${this.getAttribute("id")}-validation`,n=this.getAttribute("helper-text")||"",a=this.getAttribute("error-message")||"",r=this.hasAttribute("error"),l=[n&&!r?e:"",this.shouldShowPasswordValidation(t)?i:"",r&&a?s:""].filter(Boolean).join(" ")||void 0;l?this.input.setAttribute("aria-describedby",l):this.input.removeAttribute("aria-describedby")}}applyScrubValue(t){this.input&&(this.input.value=t,this.setAttribute("value",t),this.updateDynamicUI(),this.dispatchEvent(new CustomEvent("db-input",{detail:{value:t,nativeEvent:null},bubbles:!0,composed:!0})))}escape(t){return t.replace(/[&<>"']/g,t=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"}[t]||t))}}customElements.get("db-input")||customElements.define("db-input",DbInput);export{DbInput};