@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,503 +1 @@
1
- import { createDbIcon } from './db-icons.js';
2
-
3
- const CLASS = 'designbase-wc-video-player';
4
- const CONTROL_ICON = 20;
5
- const CENTER_ICON = 48;
6
- class DbVideoPlayer extends HTMLElement {
7
- constructor() {
8
- super(...arguments);
9
- this.built = false;
10
- this.rafId = null;
11
- this.playlistIndex = 0;
12
- this.isFullscreen = false;
13
- this.showControlsOverlay = false;
14
- this.isPlaying = false;
15
- this.isMuted = false;
16
- this.volume = 1;
17
- this.lastVolumeBeforeMute = 1;
18
- this.currentTime = 0;
19
- this.duration = 0;
20
- this.isLoading = false;
21
- this.error = null;
22
- this.onFullscreenChange = () => {
23
- this.isFullscreen = document.fullscreenElement === this;
24
- this.dispatchEvent(new CustomEvent('db-fullscreen-change', {
25
- detail: { isFullscreen: this.isFullscreen },
26
- bubbles: true,
27
- composed: true,
28
- }));
29
- this.updateUI();
30
- };
31
- this.onMouseEnter = () => {
32
- this.showControlsOverlay = true;
33
- this.updateUI();
34
- };
35
- this.onMouseLeave = () => {
36
- this.showControlsOverlay = false;
37
- this.updateUI();
38
- };
39
- }
40
- static get observedAttributes() {
41
- return [
42
- 'src',
43
- 'poster',
44
- 'title',
45
- 'description',
46
- 'size',
47
- 'variant',
48
- 'theme',
49
- 'auto-play',
50
- 'loop',
51
- 'muted',
52
- 'show-controls',
53
- 'enable-fullscreen',
54
- 'show-progress',
55
- 'show-time',
56
- 'show-volume',
57
- 'playlist',
58
- 'current-index',
59
- ];
60
- }
61
- connectedCallback() {
62
- if (!this.built) {
63
- this.built = true;
64
- this.build();
65
- this.bindVideoEvents();
66
- }
67
- this.syncFromAttributes();
68
- this.updateUI();
69
- document.addEventListener('fullscreenchange', this.onFullscreenChange);
70
- this.addEventListener('mouseenter', this.onMouseEnter);
71
- this.addEventListener('mouseleave', this.onMouseLeave);
72
- }
73
- disconnectedCallback() {
74
- document.removeEventListener('fullscreenchange', this.onFullscreenChange);
75
- this.removeEventListener('mouseenter', this.onMouseEnter);
76
- this.removeEventListener('mouseleave', this.onMouseLeave);
77
- this.stopProgressAnimation();
78
- }
79
- attributeChangedCallback(name) {
80
- if (!this.built)
81
- return;
82
- if (name === 'src' || name === 'playlist' || name === 'current-index') {
83
- this.loadVideoSource();
84
- return;
85
- }
86
- if (name === 'muted' && this.videoEl) {
87
- this.videoEl.muted = this.getBool('muted');
88
- }
89
- this.updateUI();
90
- }
91
- getBool(name, fallback = false) {
92
- if (!this.hasAttribute(name))
93
- return fallback;
94
- const value = this.getAttribute(name);
95
- return value === '' || value === 'true';
96
- }
97
- getPlaylist() {
98
- try {
99
- const raw = this.getAttribute('playlist');
100
- const parsed = raw ? JSON.parse(raw) : [];
101
- return Array.isArray(parsed) ? parsed : [];
102
- }
103
- catch {
104
- return [];
105
- }
106
- }
107
- getCurrentSrc() {
108
- const playlist = this.getPlaylist();
109
- if (playlist.length > 0) {
110
- const index = Number(this.getAttribute('current-index') || this.playlistIndex || 0);
111
- return playlist[Math.max(0, Math.min(playlist.length - 1, index))];
112
- }
113
- return this.getAttribute('src') || '';
114
- }
115
- formatTime(time) {
116
- if (!Number.isFinite(time) || time < 0)
117
- return '0:00';
118
- const minutes = Math.floor(time / 60);
119
- const seconds = Math.floor(time % 60);
120
- return `${minutes}:${seconds.toString().padStart(2, '0')}`;
121
- }
122
- iconButton(icon, size, onClick) {
123
- const button = document.createElement('button');
124
- button.type = 'button';
125
- button.className = `${CLASS}__control-button`;
126
- button.append(createDbIcon(icon, size));
127
- button.addEventListener('click', (event) => {
128
- event.stopPropagation();
129
- onClick();
130
- });
131
- return button;
132
- }
133
- skipButton(label, seconds) {
134
- const button = document.createElement('button');
135
- button.type = 'button';
136
- button.className = `${CLASS}__skip-button`;
137
- button.textContent = label;
138
- button.setAttribute('aria-label', seconds < 0 ? '10초 되감기' : '10초 빨리감기');
139
- button.addEventListener('click', (event) => {
140
- event.stopPropagation();
141
- this.seekBy(seconds);
142
- });
143
- return button;
144
- }
145
- syncFromAttributes() {
146
- this.playlistIndex = Number(this.getAttribute('current-index') || 0);
147
- this.isMuted = this.getBool('muted');
148
- this.volume = this.isMuted ? 0 : 1;
149
- this.lastVolumeBeforeMute = this.volume > 0 ? this.volume : 1;
150
- this.loadVideoSource();
151
- }
152
- loadVideoSource() {
153
- if (!this.videoEl)
154
- return;
155
- const src = this.getCurrentSrc();
156
- if (!src)
157
- return;
158
- const absoluteSrc = new URL(src, window.location.href).href;
159
- if (this.videoEl.src !== absoluteSrc) {
160
- this.videoEl.src = src;
161
- this.videoEl.load();
162
- }
163
- this.videoEl.poster = this.getAttribute('poster') || '';
164
- this.videoEl.autoplay = this.getBool('auto-play');
165
- this.videoEl.loop = this.getBool('loop');
166
- this.videoEl.muted = this.getBool('muted');
167
- this.videoEl.playsInline = true;
168
- }
169
- bindVideoEvents() {
170
- const video = this.videoEl;
171
- if (!video)
172
- return;
173
- video.addEventListener('play', () => {
174
- this.isPlaying = true;
175
- this.startProgressAnimation();
176
- this.dispatchEvent(new CustomEvent('db-play', { bubbles: true, composed: true }));
177
- this.updateUI();
178
- });
179
- video.addEventListener('pause', () => {
180
- this.isPlaying = false;
181
- this.stopProgressAnimation();
182
- this.dispatchEvent(new CustomEvent('db-pause', { bubbles: true, composed: true }));
183
- this.updateUI();
184
- });
185
- video.addEventListener('timeupdate', () => {
186
- this.currentTime = video.currentTime;
187
- this.duration = Number.isFinite(video.duration) ? video.duration : 0;
188
- this.dispatchEvent(new CustomEvent('db-time-update', {
189
- detail: { currentTime: this.currentTime, duration: this.duration },
190
- bubbles: true,
191
- composed: true,
192
- }));
193
- this.updateProgress();
194
- this.updateTime();
195
- });
196
- video.addEventListener('volumechange', () => {
197
- this.volume = video.volume;
198
- this.isMuted = video.muted || video.volume === 0;
199
- if (!this.isMuted && this.volume > 0)
200
- this.lastVolumeBeforeMute = this.volume;
201
- this.dispatchEvent(new CustomEvent('db-volume-change', { detail: { volume: this.volume }, bubbles: true, composed: true }));
202
- this.updateVolumeUI();
203
- });
204
- video.addEventListener('ended', () => {
205
- this.isPlaying = false;
206
- this.stopProgressAnimation();
207
- this.dispatchEvent(new CustomEvent('db-ended', { bubbles: true, composed: true }));
208
- const playlist = this.getPlaylist();
209
- const next = this.playlistIndex + 1;
210
- if (playlist.length > 0 && next < playlist.length) {
211
- this.playlistIndex = next;
212
- this.loadVideoSource();
213
- void video.play();
214
- }
215
- this.updateUI();
216
- });
217
- video.addEventListener('error', () => {
218
- this.error = '비디오를 재생할 수 없습니다.';
219
- this.dispatchEvent(new CustomEvent('db-error', { detail: { error: this.error }, bubbles: true, composed: true }));
220
- this.updateUI();
221
- });
222
- video.addEventListener('loadstart', () => {
223
- this.isLoading = true;
224
- this.error = null;
225
- this.updateUI();
226
- });
227
- video.addEventListener('loadedmetadata', () => {
228
- this.duration = Number.isFinite(video.duration) ? video.duration : 0;
229
- this.updateTime();
230
- });
231
- video.addEventListener('canplay', () => {
232
- this.isLoading = false;
233
- this.updateUI();
234
- });
235
- video.addEventListener('click', () => this.togglePlay());
236
- }
237
- togglePlay() {
238
- if (!this.videoEl)
239
- return;
240
- if (this.videoEl.paused)
241
- void this.videoEl.play();
242
- else
243
- this.videoEl.pause();
244
- }
245
- toggleMute() {
246
- if (!this.videoEl)
247
- return;
248
- if (this.isMuted) {
249
- this.videoEl.muted = false;
250
- this.videoEl.volume = this.lastVolumeBeforeMute > 0 ? this.lastVolumeBeforeMute : 1;
251
- return;
252
- }
253
- if (this.videoEl.volume > 0)
254
- this.lastVolumeBeforeMute = this.videoEl.volume;
255
- this.videoEl.muted = true;
256
- this.videoEl.volume = 0;
257
- }
258
- seekBy(seconds) {
259
- if (!this.videoEl)
260
- return;
261
- const duration = Number.isFinite(this.videoEl.duration) ? this.videoEl.duration : 0;
262
- const maxTime = duration > 0 ? duration : Number.MAX_SAFE_INTEGER;
263
- const nextTime = Math.max(0, Math.min(maxTime, this.videoEl.currentTime + seconds));
264
- this.videoEl.currentTime = nextTime;
265
- }
266
- toggleFullscreen() {
267
- if (!this.getBool('enable-fullscreen', true))
268
- return;
269
- if (!this.isFullscreen)
270
- void this.requestFullscreen?.();
271
- else
272
- void document.exitFullscreen?.();
273
- }
274
- build() {
275
- this.videoEl = document.createElement('video');
276
- this.videoEl.className = `${CLASS}__video`;
277
- const loading = document.createElement('div');
278
- loading.className = `${CLASS}__loading`;
279
- const spinner = document.createElement('div');
280
- spinner.className = `${CLASS}__spinner`;
281
- loading.append(spinner);
282
- const errorWrap = document.createElement('div');
283
- errorWrap.className = `${CLASS}__error`;
284
- const errorText = document.createElement('p');
285
- errorText.textContent = '비디오를 재생할 수 없습니다.';
286
- const retry = document.createElement('button');
287
- retry.type = 'button';
288
- retry.textContent = '다시 시도';
289
- retry.addEventListener('click', () => {
290
- this.error = null;
291
- this.loadVideoSource();
292
- this.updateUI();
293
- });
294
- errorWrap.append(errorText, retry);
295
- this.dimOverlayEl = document.createElement('div');
296
- this.dimOverlayEl.className = `${CLASS}__dim-overlay`;
297
- this.overlayEl = document.createElement('div');
298
- this.overlayEl.className = `${CLASS}__overlay`;
299
- const top = document.createElement('div');
300
- top.className = `${CLASS}__top-controls`;
301
- const titleWrap = document.createElement('div');
302
- titleWrap.className = `${CLASS}__title`;
303
- const titleEl = document.createElement('h3');
304
- const descEl = document.createElement('p');
305
- titleWrap.append(titleEl, descEl);
306
- top.append(titleWrap);
307
- this._titleEl = titleEl;
308
- this._descEl = descEl;
309
- const center = document.createElement('div');
310
- center.className = `${CLASS}__center-controls`;
311
- const rewindButton = this.skipButton('-10', -10);
312
- this.centerPlayEl = document.createElement('button');
313
- this.centerPlayEl.type = 'button';
314
- this.centerPlayEl.className = `${CLASS}__play-button`;
315
- this.centerPlayEl.addEventListener('click', (event) => {
316
- event.stopPropagation();
317
- this.togglePlay();
318
- });
319
- const forwardButton = this.skipButton('+10', 10);
320
- center.append(rewindButton, this.centerPlayEl, forwardButton);
321
- const bottom = document.createElement('div');
322
- bottom.className = `${CLASS}__bottom-controls`;
323
- this.progressEl = document.createElement('div');
324
- this.progressEl.className = `${CLASS}__progress`;
325
- this.progressBarEl = document.createElement('div');
326
- this.progressBarEl.className = `${CLASS}__progress-bar`;
327
- this.progressHandleEl = document.createElement('div');
328
- this.progressHandleEl.className = `${CLASS}__progress-handle`;
329
- this.progressEl.append(this.progressBarEl, this.progressHandleEl);
330
- this.progressEl.addEventListener('click', (event) => {
331
- if (!this.videoEl || !Number.isFinite(this.duration) || this.duration <= 0)
332
- return;
333
- const rect = this.progressEl.getBoundingClientRect();
334
- const percentage = (event.clientX - rect.left) / rect.width;
335
- this.videoEl.currentTime = percentage * this.duration;
336
- });
337
- const controls = document.createElement('div');
338
- controls.className = `${CLASS}__controls`;
339
- const left = document.createElement('div');
340
- left.className = `${CLASS}__left-controls`;
341
- this.togglePlayEl = this.iconButton('play', CONTROL_ICON, () => this.togglePlay());
342
- this.volumeWrapEl = document.createElement('div');
343
- this.volumeWrapEl.className = `${CLASS}__volume`;
344
- this.muteButtonEl = this.iconButton('volume-up', CONTROL_ICON, () => this.toggleMute());
345
- const volumeSlider = document.createElement('div');
346
- volumeSlider.className = `${CLASS}__volume-slider`;
347
- this.volumeInputEl = document.createElement('input');
348
- this.volumeInputEl.type = 'range';
349
- this.volumeInputEl.min = '0';
350
- this.volumeInputEl.max = '1';
351
- this.volumeInputEl.step = '0.1';
352
- this.volumeInputEl.addEventListener('input', () => {
353
- if (!this.videoEl || !this.volumeInputEl)
354
- return;
355
- const nextVolume = parseFloat(this.volumeInputEl.value);
356
- if (nextVolume > 0)
357
- this.lastVolumeBeforeMute = nextVolume;
358
- this.videoEl.volume = nextVolume;
359
- this.videoEl.muted = nextVolume === 0;
360
- });
361
- volumeSlider.append(this.volumeInputEl);
362
- this.volumeWrapEl.append(this.muteButtonEl, volumeSlider);
363
- this.timeEl = document.createElement('div');
364
- this.timeEl.className = `${CLASS}__time`;
365
- this.timeCurrentEl = document.createElement('span');
366
- const slash = document.createElement('span');
367
- slash.textContent = '/';
368
- this.timeDurationEl = document.createElement('span');
369
- this.timeEl.append(this.timeCurrentEl, slash, this.timeDurationEl);
370
- left.append(this.togglePlayEl, this.volumeWrapEl, this.timeEl);
371
- const right = document.createElement('div');
372
- right.className = `${CLASS}__right-controls`;
373
- this.fullscreenButtonEl = this.iconButton('expand', CONTROL_ICON, () => this.toggleFullscreen());
374
- right.append(this.fullscreenButtonEl);
375
- controls.append(left, right);
376
- bottom.append(this.progressEl, controls);
377
- this.overlayEl.append(top, center, bottom);
378
- this.append(this.videoEl, loading, errorWrap, this.dimOverlayEl, this.overlayEl);
379
- }
380
- get titleEl() {
381
- return this._titleEl;
382
- }
383
- get descEl() {
384
- return this._descEl;
385
- }
386
- updateProgress() {
387
- const ratio = this.duration > 0 ? (this.currentTime / this.duration) * 100 : 0;
388
- if (this.progressBarEl)
389
- this.progressBarEl.style.width = `${ratio}%`;
390
- if (this.progressHandleEl)
391
- this.progressHandleEl.style.left = `${ratio}%`;
392
- }
393
- updateTime() {
394
- if (this.timeCurrentEl)
395
- this.timeCurrentEl.textContent = this.formatTime(this.currentTime);
396
- if (this.timeDurationEl)
397
- this.timeDurationEl.textContent = this.formatTime(this.duration);
398
- }
399
- updateVolumeUI() {
400
- const visibleVolume = this.isMuted ? 0 : this.volume;
401
- if (this.volumeInputEl)
402
- this.volumeInputEl.value = String(visibleVolume);
403
- if (this.muteButtonEl) {
404
- this.muteButtonEl.replaceChildren(createDbIcon(this.isMuted || visibleVolume === 0 ? 'mute-filled' : 'volume-up', CONTROL_ICON));
405
- }
406
- }
407
- startProgressAnimation() {
408
- this.stopProgressAnimation();
409
- const tick = () => {
410
- if (!this.videoEl || this.videoEl.paused || this.videoEl.ended)
411
- return;
412
- this.currentTime = this.videoEl.currentTime;
413
- this.duration = Number.isFinite(this.videoEl.duration) ? this.videoEl.duration : 0;
414
- this.updateProgress();
415
- this.updateTime();
416
- this.rafId = requestAnimationFrame(tick);
417
- };
418
- this.rafId = requestAnimationFrame(tick);
419
- }
420
- stopProgressAnimation() {
421
- if (this.rafId !== null) {
422
- cancelAnimationFrame(this.rafId);
423
- this.rafId = null;
424
- }
425
- }
426
- updatePlayIcons() {
427
- const centerIcon = this.isPlaying ? 'pause' : 'play';
428
- if (this.centerPlayEl) {
429
- this.centerPlayEl.replaceChildren(createDbIcon(centerIcon, CENTER_ICON));
430
- }
431
- if (this.togglePlayEl) {
432
- this.togglePlayEl.replaceChildren(createDbIcon(centerIcon, CONTROL_ICON));
433
- }
434
- }
435
- updateUI() {
436
- const size = this.getAttribute('size') || 'm';
437
- const variant = this.getAttribute('variant') || 'default';
438
- const theme = this.getAttribute('theme') || 'auto';
439
- const showControls = this.getBool('show-controls', true);
440
- const showProgress = this.getBool('show-progress', true);
441
- const showTime = this.getBool('show-time', true);
442
- const showVolume = this.getBool('show-volume', true);
443
- const enableFullscreen = this.getBool('enable-fullscreen', true);
444
- this.className = [
445
- CLASS,
446
- `${CLASS}--size-${size}`,
447
- `${CLASS}--variant-${variant}`,
448
- `${CLASS}--theme-${theme}`,
449
- this.isPlaying && `${CLASS}--playing`,
450
- !this.isPlaying && `${CLASS}--paused`,
451
- this.isMuted && `${CLASS}--muted`,
452
- this.isLoading && `${CLASS}--loading`,
453
- this.error && `${CLASS}--error`,
454
- showControls && this.showControlsOverlay && `${CLASS}--show-controls`,
455
- this.isFullscreen && `${CLASS}--fullscreen`,
456
- ]
457
- .filter(Boolean)
458
- .join(' ');
459
- const title = this.getAttribute('title');
460
- const description = this.getAttribute('description');
461
- if (this.titleEl) {
462
- if (title) {
463
- this.titleEl.textContent = title;
464
- this.titleEl.hidden = false;
465
- }
466
- else {
467
- this.titleEl.hidden = true;
468
- }
469
- }
470
- if (this.descEl) {
471
- if (description) {
472
- this.descEl.textContent = description;
473
- this.descEl.hidden = false;
474
- }
475
- else {
476
- this.descEl.hidden = true;
477
- }
478
- }
479
- if (this.overlayEl)
480
- this.overlayEl.hidden = !showControls;
481
- if (this.dimOverlayEl)
482
- this.dimOverlayEl.hidden = !showControls;
483
- if (this.progressEl)
484
- this.progressEl.hidden = !showProgress;
485
- if (this.timeEl)
486
- this.timeEl.hidden = !showTime;
487
- if (this.volumeWrapEl)
488
- this.volumeWrapEl.hidden = !showVolume;
489
- if (this.fullscreenButtonEl)
490
- this.fullscreenButtonEl.hidden = !enableFullscreen;
491
- if (this.fullscreenButtonEl) {
492
- this.fullscreenButtonEl.replaceChildren(createDbIcon(this.isFullscreen ? 'shrink' : 'expand', CONTROL_ICON));
493
- }
494
- this.updatePlayIcons();
495
- this.updateProgress();
496
- this.updateTime();
497
- this.updateVolumeUI();
498
- }
499
- }
500
- if (!customElements.get('db-video-player'))
501
- customElements.define('db-video-player', DbVideoPlayer);
502
-
503
- export { DbVideoPlayer };
1
+ import{createDbIcon as t}from"./db-icons.js";const e="designbase-wc-video-player",s=20;class DbVideoPlayer extends HTMLElement{constructor(){super(...arguments),this.built=!1,this.rafId=null,this.playlistIndex=0,this.isFullscreen=!1,this.showControlsOverlay=!1,this.isPlaying=!1,this.isMuted=!1,this.volume=1,this.lastVolumeBeforeMute=1,this.currentTime=0,this.duration=0,this.isLoading=!1,this.error=null,this.onFullscreenChange=()=>{this.isFullscreen=document.fullscreenElement===this,this.dispatchEvent(new CustomEvent("db-fullscreen-change",{detail:{isFullscreen:this.isFullscreen},bubbles:!0,composed:!0})),this.updateUI()},this.onMouseEnter=()=>{this.showControlsOverlay=!0,this.updateUI()},this.onMouseLeave=()=>{this.showControlsOverlay=!1,this.updateUI()}}static get observedAttributes(){return["src","poster","title","description","size","variant","theme","auto-play","loop","muted","show-controls","enable-fullscreen","show-progress","show-time","show-volume","playlist","current-index"]}connectedCallback(){this.built||(this.built=!0,this.build(),this.bindVideoEvents()),this.syncFromAttributes(),this.updateUI(),document.addEventListener("fullscreenchange",this.onFullscreenChange),this.addEventListener("mouseenter",this.onMouseEnter),this.addEventListener("mouseleave",this.onMouseLeave)}disconnectedCallback(){document.removeEventListener("fullscreenchange",this.onFullscreenChange),this.removeEventListener("mouseenter",this.onMouseEnter),this.removeEventListener("mouseleave",this.onMouseLeave),this.stopProgressAnimation()}attributeChangedCallback(t){this.built&&("src"!==t&&"playlist"!==t&&"current-index"!==t?("muted"===t&&this.videoEl&&(this.videoEl.muted=this.getBool("muted")),this.updateUI()):this.loadVideoSource())}getBool(t,e=!1){if(!this.hasAttribute(t))return e;const s=this.getAttribute(t);return""===s||"true"===s}getPlaylist(){try{const t=this.getAttribute("playlist"),e=t?JSON.parse(t):[];return Array.isArray(e)?e:[]}catch{return[]}}getCurrentSrc(){const t=this.getPlaylist();if(t.length>0){const e=Number(this.getAttribute("current-index")||this.playlistIndex||0);return t[Math.max(0,Math.min(t.length-1,e))]}return this.getAttribute("src")||""}formatTime(t){if(!Number.isFinite(t)||t<0)return"0:00";return`${Math.floor(t/60)}:${Math.floor(t%60).toString().padStart(2,"0")}`}iconButton(s,i,l){const n=document.createElement("button");return n.type="button",n.className=`${e}__control-button`,n.append(t(s,i)),n.addEventListener("click",t=>{t.stopPropagation(),l()}),n}skipButton(t,s){const i=document.createElement("button");return i.type="button",i.className=`${e}__skip-button`,i.textContent=t,i.setAttribute("aria-label",s<0?"10초 되감기":"10초 빨리감기"),i.addEventListener("click",t=>{t.stopPropagation(),this.seekBy(s)}),i}syncFromAttributes(){this.playlistIndex=Number(this.getAttribute("current-index")||0),this.isMuted=this.getBool("muted"),this.volume=this.isMuted?0:1,this.lastVolumeBeforeMute=this.volume>0?this.volume:1,this.loadVideoSource()}loadVideoSource(){if(!this.videoEl)return;const t=this.getCurrentSrc();if(!t)return;const e=new URL(t,window.location.href).href;this.videoEl.src!==e&&(this.videoEl.src=t,this.videoEl.load()),this.videoEl.poster=this.getAttribute("poster")||"",this.videoEl.autoplay=this.getBool("auto-play"),this.videoEl.loop=this.getBool("loop"),this.videoEl.muted=this.getBool("muted"),this.videoEl.playsInline=!0}bindVideoEvents(){const t=this.videoEl;t&&(t.addEventListener("play",()=>{this.isPlaying=!0,this.startProgressAnimation(),this.dispatchEvent(new CustomEvent("db-play",{bubbles:!0,composed:!0})),this.updateUI()}),t.addEventListener("pause",()=>{this.isPlaying=!1,this.stopProgressAnimation(),this.dispatchEvent(new CustomEvent("db-pause",{bubbles:!0,composed:!0})),this.updateUI()}),t.addEventListener("timeupdate",()=>{this.currentTime=t.currentTime,this.duration=Number.isFinite(t.duration)?t.duration:0,this.dispatchEvent(new CustomEvent("db-time-update",{detail:{currentTime:this.currentTime,duration:this.duration},bubbles:!0,composed:!0})),this.updateProgress(),this.updateTime()}),t.addEventListener("volumechange",()=>{this.volume=t.volume,this.isMuted=t.muted||0===t.volume,!this.isMuted&&this.volume>0&&(this.lastVolumeBeforeMute=this.volume),this.dispatchEvent(new CustomEvent("db-volume-change",{detail:{volume:this.volume},bubbles:!0,composed:!0})),this.updateVolumeUI()}),t.addEventListener("ended",()=>{this.isPlaying=!1,this.stopProgressAnimation(),this.dispatchEvent(new CustomEvent("db-ended",{bubbles:!0,composed:!0}));const e=this.getPlaylist(),s=this.playlistIndex+1;e.length>0&&s<e.length&&(this.playlistIndex=s,this.loadVideoSource(),t.play()),this.updateUI()}),t.addEventListener("error",()=>{this.error="비디오를 재생할 수 없습니다.",this.dispatchEvent(new CustomEvent("db-error",{detail:{error:this.error},bubbles:!0,composed:!0})),this.updateUI()}),t.addEventListener("loadstart",()=>{this.isLoading=!0,this.error=null,this.updateUI()}),t.addEventListener("loadedmetadata",()=>{this.duration=Number.isFinite(t.duration)?t.duration:0,this.updateTime()}),t.addEventListener("canplay",()=>{this.isLoading=!1,this.updateUI()}),t.addEventListener("click",()=>this.togglePlay()))}togglePlay(){this.videoEl&&(this.videoEl.paused?this.videoEl.play():this.videoEl.pause())}toggleMute(){if(this.videoEl){if(this.isMuted)return this.videoEl.muted=!1,void(this.videoEl.volume=this.lastVolumeBeforeMute>0?this.lastVolumeBeforeMute:1);this.videoEl.volume>0&&(this.lastVolumeBeforeMute=this.videoEl.volume),this.videoEl.muted=!0,this.videoEl.volume=0}}seekBy(t){if(!this.videoEl)return;const e=Number.isFinite(this.videoEl.duration)?this.videoEl.duration:0,s=e>0?e:Number.MAX_SAFE_INTEGER,i=Math.max(0,Math.min(s,this.videoEl.currentTime+t));this.videoEl.currentTime=i}toggleFullscreen(){this.getBool("enable-fullscreen",!0)&&(this.isFullscreen?document.exitFullscreen?.():this.requestFullscreen?.())}build(){this.videoEl=document.createElement("video"),this.videoEl.className=`${e}__video`;const t=document.createElement("div");t.className=`${e}__loading`;const i=document.createElement("div");i.className=`${e}__spinner`,t.append(i);const l=document.createElement("div");l.className=`${e}__error`;const n=document.createElement("p");n.textContent="비디오를 재생할 수 없습니다.";const o=document.createElement("button");o.type="button",o.textContent="다시 시도",o.addEventListener("click",()=>{this.error=null,this.loadVideoSource(),this.updateUI()}),l.append(n,o),this.dimOverlayEl=document.createElement("div"),this.dimOverlayEl.className=`${e}__dim-overlay`,this.overlayEl=document.createElement("div"),this.overlayEl.className=`${e}__overlay`;const r=document.createElement("div");r.className=`${e}__top-controls`;const a=document.createElement("div");a.className=`${e}__title`;const h=document.createElement("h3"),u=document.createElement("p");a.append(h,u),r.append(a),this._titleEl=h,this._descEl=u;const d=document.createElement("div");d.className=`${e}__center-controls`;const c=this.skipButton("-10",-10);this.centerPlayEl=document.createElement("button"),this.centerPlayEl.type="button",this.centerPlayEl.className=`${e}__play-button`,this.centerPlayEl.addEventListener("click",t=>{t.stopPropagation(),this.togglePlay()});const m=this.skipButton("+10",10);d.append(c,this.centerPlayEl,m);const E=document.createElement("div");E.className=`${e}__bottom-controls`,this.progressEl=document.createElement("div"),this.progressEl.className=`${e}__progress`,this.progressBarEl=document.createElement("div"),this.progressBarEl.className=`${e}__progress-bar`,this.progressHandleEl=document.createElement("div"),this.progressHandleEl.className=`${e}__progress-handle`,this.progressEl.append(this.progressBarEl,this.progressHandleEl),this.progressEl.addEventListener("click",t=>{if(!this.videoEl||!Number.isFinite(this.duration)||this.duration<=0)return;const e=this.progressEl.getBoundingClientRect(),s=(t.clientX-e.left)/e.width;this.videoEl.currentTime=s*this.duration});const p=document.createElement("div");p.className=`${e}__controls`;const v=document.createElement("div");v.className=`${e}__left-controls`,this.togglePlayEl=this.iconButton("play",s,()=>this.togglePlay()),this.volumeWrapEl=document.createElement("div"),this.volumeWrapEl.className=`${e}__volume`,this.muteButtonEl=this.iconButton("volume-up",s,()=>this.toggleMute());const g=document.createElement("div");g.className=`${e}__volume-slider`,this.volumeInputEl=document.createElement("input"),this.volumeInputEl.type="range",this.volumeInputEl.min="0",this.volumeInputEl.max="1",this.volumeInputEl.step="0.1",this.volumeInputEl.addEventListener("input",()=>{if(!this.videoEl||!this.volumeInputEl)return;const t=parseFloat(this.volumeInputEl.value);t>0&&(this.lastVolumeBeforeMute=t),this.videoEl.volume=t,this.videoEl.muted=0===t}),g.append(this.volumeInputEl),this.volumeWrapEl.append(this.muteButtonEl,g),this.timeEl=document.createElement("div"),this.timeEl.className=`${e}__time`,this.timeCurrentEl=document.createElement("span");const b=document.createElement("span");b.textContent="/",this.timeDurationEl=document.createElement("span"),this.timeEl.append(this.timeCurrentEl,b,this.timeDurationEl),v.append(this.togglePlayEl,this.volumeWrapEl,this.timeEl);const y=document.createElement("div");y.className=`${e}__right-controls`,this.fullscreenButtonEl=this.iconButton("expand",s,()=>this.toggleFullscreen()),y.append(this.fullscreenButtonEl),p.append(v,y),E.append(this.progressEl,p),this.overlayEl.append(r,d,E),this.append(this.videoEl,t,l,this.dimOverlayEl,this.overlayEl)}get titleEl(){return this._titleEl}get descEl(){return this._descEl}updateProgress(){const t=this.duration>0?this.currentTime/this.duration*100:0;this.progressBarEl&&(this.progressBarEl.style.width=`${t}%`),this.progressHandleEl&&(this.progressHandleEl.style.left=`${t}%`)}updateTime(){this.timeCurrentEl&&(this.timeCurrentEl.textContent=this.formatTime(this.currentTime)),this.timeDurationEl&&(this.timeDurationEl.textContent=this.formatTime(this.duration))}updateVolumeUI(){const e=this.isMuted?0:this.volume;this.volumeInputEl&&(this.volumeInputEl.value=String(e)),this.muteButtonEl&&this.muteButtonEl.replaceChildren(t(this.isMuted||0===e?"mute-filled":"volume-up",s))}startProgressAnimation(){this.stopProgressAnimation();const tick=()=>{!this.videoEl||this.videoEl.paused||this.videoEl.ended||(this.currentTime=this.videoEl.currentTime,this.duration=Number.isFinite(this.videoEl.duration)?this.videoEl.duration:0,this.updateProgress(),this.updateTime(),this.rafId=requestAnimationFrame(tick))};this.rafId=requestAnimationFrame(tick)}stopProgressAnimation(){null!==this.rafId&&(cancelAnimationFrame(this.rafId),this.rafId=null)}updatePlayIcons(){const e=this.isPlaying?"pause":"play";this.centerPlayEl&&this.centerPlayEl.replaceChildren(t(e,48)),this.togglePlayEl&&this.togglePlayEl.replaceChildren(t(e,s))}updateUI(){const i=this.getAttribute("size")||"m",l=this.getAttribute("variant")||"default",n=this.getAttribute("theme")||"auto",o=this.getBool("show-controls",!0),r=this.getBool("show-progress",!0),a=this.getBool("show-time",!0),h=this.getBool("show-volume",!0),u=this.getBool("enable-fullscreen",!0);this.className=[e,`${e}--size-${i}`,`${e}--variant-${l}`,`${e}--theme-${n}`,this.isPlaying&&`${e}--playing`,!this.isPlaying&&`${e}--paused`,this.isMuted&&`${e}--muted`,this.isLoading&&`${e}--loading`,this.error&&`${e}--error`,o&&this.showControlsOverlay&&`${e}--show-controls`,this.isFullscreen&&`${e}--fullscreen`].filter(Boolean).join(" ");const d=this.getAttribute("title"),c=this.getAttribute("description");this.titleEl&&(d?(this.titleEl.textContent=d,this.titleEl.hidden=!1):this.titleEl.hidden=!0),this.descEl&&(c?(this.descEl.textContent=c,this.descEl.hidden=!1):this.descEl.hidden=!0),this.overlayEl&&(this.overlayEl.hidden=!o),this.dimOverlayEl&&(this.dimOverlayEl.hidden=!o),this.progressEl&&(this.progressEl.hidden=!r),this.timeEl&&(this.timeEl.hidden=!a),this.volumeWrapEl&&(this.volumeWrapEl.hidden=!h),this.fullscreenButtonEl&&(this.fullscreenButtonEl.hidden=!u),this.fullscreenButtonEl&&this.fullscreenButtonEl.replaceChildren(t(this.isFullscreen?"shrink":"expand",s)),this.updatePlayIcons(),this.updateProgress(),this.updateTime(),this.updateVolumeUI()}}customElements.get("db-video-player")||customElements.define("db-video-player",DbVideoPlayer);export{DbVideoPlayer};