@designbasekorea/ui-wc 0.5.5 → 0.5.6

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 (155) hide show
  1. package/dist/chunks/lottie-e273b936.js +17032 -0
  2. package/dist/esm/components/animation-background/canvas-controller.js +121 -1
  3. package/dist/esm/components/animation-background/controls.js +180 -1
  4. package/dist/esm/components/animation-background/graphite-controller.js +196 -1
  5. package/dist/esm/components/animation-background/graphite-presets.js +42 -1
  6. package/dist/esm/components/animation-background/graphite-shader.js +111 -1
  7. package/dist/esm/components/animation-background/layers.js +369 -1
  8. package/dist/esm/components/animation-background/lumina-presets.js +53 -1
  9. package/dist/esm/components/animation-background/lumina-shaders.js +181 -1
  10. package/dist/esm/components/animation-background/lumina-utils.js +60 -1
  11. package/dist/esm/components/animation-background/particle-defaults.js +36 -1
  12. package/dist/esm/components/animation-background/renderers.js +167 -1
  13. package/dist/esm/components/animation-background/shader-controller.js +154 -1
  14. package/dist/esm/components/color-picker-utils.js +134 -1
  15. package/dist/esm/components/date-picker-utils.js +140 -1
  16. package/dist/esm/components/db-accordion.js +304 -1
  17. package/dist/esm/components/db-ad-banner.js +455 -1
  18. package/dist/esm/components/db-alert.js +149 -1
  19. package/dist/esm/components/db-animation-background.js +486 -1
  20. package/dist/esm/components/db-animation-text.js +601 -1
  21. package/dist/esm/components/db-app-badge.js +88 -1
  22. package/dist/esm/components/db-audio-player.js +752 -1
  23. package/dist/esm/components/db-avatar.js +188 -1
  24. package/dist/esm/components/db-backdrop.js +139 -1
  25. package/dist/esm/components/db-badge.js +91 -1
  26. package/dist/esm/components/db-banner.js +188 -1
  27. package/dist/esm/components/db-bottom-navigation.js +146 -1
  28. package/dist/esm/components/db-bottom-sheet.js +481 -1
  29. package/dist/esm/components/db-breadcrumbs.js +329 -1
  30. package/dist/esm/components/db-button.js +316 -1
  31. package/dist/esm/components/db-calendar.js +675 -1
  32. package/dist/esm/components/db-card.js +265 -1
  33. package/dist/esm/components/db-carousel.js +264 -1
  34. package/dist/esm/components/db-checkbox.js +202 -1
  35. package/dist/esm/components/db-chip.js +104 -1
  36. package/dist/esm/components/db-code-block.js +304 -1
  37. package/dist/esm/components/db-color-picker.js +746 -1
  38. package/dist/esm/components/db-confirm.js +191 -1
  39. package/dist/esm/components/db-container.js +39 -1
  40. package/dist/esm/components/db-context-menu.js +265 -1
  41. package/dist/esm/components/db-countdown.js +146 -1
  42. package/dist/esm/components/db-cursor-follower.js +173 -1
  43. package/dist/esm/components/db-date-picker.js +837 -1
  44. package/dist/esm/components/db-divider.js +66 -1
  45. package/dist/esm/components/db-drawer.js +245 -1
  46. package/dist/esm/components/db-dropdown.js +493 -1
  47. package/dist/esm/components/db-dropzone.js +266 -1
  48. package/dist/esm/components/db-empty-state.js +97 -1
  49. package/dist/esm/components/db-file-uploader.js +256 -1
  50. package/dist/esm/components/db-floating-action-button.js +139 -1
  51. package/dist/esm/components/db-footer.js +385 -1
  52. package/dist/esm/components/db-form.js +566 -1
  53. package/dist/esm/components/db-gantt.js +882 -1
  54. package/dist/esm/components/db-gradient.js +133 -1
  55. package/dist/esm/components/db-grid-background.js +909 -1
  56. package/dist/esm/components/db-grid.js +73 -1
  57. package/dist/esm/components/db-icons.js +82 -1
  58. package/dist/esm/components/db-image-list.js +214 -1
  59. package/dist/esm/components/db-image-placeholder.js +96 -1
  60. package/dist/esm/components/db-image.js +289 -1
  61. package/dist/esm/components/db-indicator.js +517 -1
  62. package/dist/esm/components/db-input.js +420 -1
  63. package/dist/esm/components/db-kanban.js +538 -1
  64. package/dist/esm/components/db-label.js +66 -1
  65. package/dist/esm/components/db-lightbox.js +372 -1
  66. package/dist/esm/components/db-list.js +340 -1
  67. package/dist/esm/components/db-logo-svg.js +72 -1
  68. package/dist/esm/components/db-logo.js +106 -1
  69. package/dist/esm/components/db-lottie.js +109 -1
  70. package/dist/esm/components/db-markdown-editor.js +458 -1
  71. package/dist/esm/components/db-marquee.js +402 -1
  72. package/dist/esm/components/db-masonry.js +94 -1
  73. package/dist/esm/components/db-menu-item.js +211 -1
  74. package/dist/esm/components/db-modal.js +522 -1
  75. package/dist/esm/components/db-navbar.js +680 -1
  76. package/dist/esm/components/db-onboarding-modal.js +322 -1
  77. package/dist/esm/components/db-page-header.js +312 -1
  78. package/dist/esm/components/db-pagination.js +271 -1
  79. package/dist/esm/components/db-popover.js +580 -1
  80. package/dist/esm/components/db-progress-step.js +166 -1
  81. package/dist/esm/components/db-progress.js +171 -1
  82. package/dist/esm/components/db-progressbar.js +72 -1
  83. package/dist/esm/components/db-radio.js +172 -1
  84. package/dist/esm/components/db-random-gradient.js +121 -1
  85. package/dist/esm/components/db-range-slider.js +811 -1
  86. package/dist/esm/components/db-rating.js +325 -1
  87. package/dist/esm/components/db-reorder.js +286 -1
  88. package/dist/esm/components/db-resizable-panels.js +282 -1
  89. package/dist/esm/components/db-scroll-area.js +126 -1
  90. package/dist/esm/components/db-search-bar.js +668 -1
  91. package/dist/esm/components/db-section-app-download.js +101 -1
  92. package/dist/esm/components/db-section-contact.js +102 -1
  93. package/dist/esm/components/db-section-cta.js +150 -1
  94. package/dist/esm/components/db-section-faq.js +120 -1
  95. package/dist/esm/components/db-section-feature-grid.js +137 -1
  96. package/dist/esm/components/db-section-feature.js +179 -1
  97. package/dist/esm/components/db-section-hero.js +243 -1
  98. package/dist/esm/components/db-section-logo-cloud.js +138 -1
  99. package/dist/esm/components/db-section-pricing.js +166 -1
  100. package/dist/esm/components/db-section-stats.js +129 -1
  101. package/dist/esm/components/db-section-testimonials.js +252 -1
  102. package/dist/esm/components/db-section.js +385 -1
  103. package/dist/esm/components/db-segment-control.js +231 -1
  104. package/dist/esm/components/db-select.js +571 -1
  105. package/dist/esm/components/db-share-icons.js +40 -1
  106. package/dist/esm/components/db-share.js +489 -1
  107. package/dist/esm/components/db-sidebar.js +1068 -1
  108. package/dist/esm/components/db-skeleton.js +94 -1
  109. package/dist/esm/components/db-spinner.js +102 -1
  110. package/dist/esm/components/db-split-view.js +297 -1
  111. package/dist/esm/components/db-stack.js +46 -1
  112. package/dist/esm/components/db-stat.js +218 -1
  113. package/dist/esm/components/db-stepper.js +398 -1
  114. package/dist/esm/components/db-table.js +412 -1
  115. package/dist/esm/components/db-tabs.js +335 -1
  116. package/dist/esm/components/db-testimonial.js +162 -1
  117. package/dist/esm/components/db-textarea.js +233 -1
  118. package/dist/esm/components/db-time-picker.js +523 -1
  119. package/dist/esm/components/db-timeline.js +174 -1
  120. package/dist/esm/components/db-toast.js +158 -1
  121. package/dist/esm/components/db-toggle.js +162 -1
  122. package/dist/esm/components/db-toolbar.js +94 -1
  123. package/dist/esm/components/db-tooltip.js +440 -1
  124. package/dist/esm/components/db-top-banner.js +121 -1
  125. package/dist/esm/components/db-tutorial.js +324 -1
  126. package/dist/esm/components/db-video-player.js +503 -1
  127. package/dist/esm/components/db-youtube-player.js +194 -1
  128. package/dist/esm/components/highlight-code.js +65 -1
  129. package/dist/esm/components/input-validation.js +50 -1
  130. package/dist/esm/components/marketing-block-host-utils.js +9 -1
  131. package/dist/esm/components/number-scrub.js +117 -1
  132. package/dist/esm/components/random-gradient-palettes.js +67 -1
  133. package/dist/esm/components/section-block-header-utils.js +48 -1
  134. package/dist/esm/helpers/confirm.js +52 -1
  135. package/dist/esm/helpers/toast.js +73 -1
  136. package/dist/esm/index.js +111 -1
  137. package/dist/esm/node_modules/prismjs/components/prism-bash.js +235 -1
  138. package/dist/esm/node_modules/prismjs/components/prism-clike.js +31 -1
  139. package/dist/esm/node_modules/prismjs/components/prism-css.js +64 -1
  140. package/dist/esm/node_modules/prismjs/components/prism-javascript.js +172 -1
  141. package/dist/esm/node_modules/prismjs/components/prism-json.js +27 -1
  142. package/dist/esm/node_modules/prismjs/components/prism-jsx.js +143 -1
  143. package/dist/esm/node_modules/prismjs/components/prism-markup.js +186 -1
  144. package/dist/esm/node_modules/prismjs/components/prism-scss.js +81 -1
  145. package/dist/esm/node_modules/prismjs/components/prism-tsx.js +15 -1
  146. package/dist/esm/node_modules/prismjs/components/prism-typescript.js +60 -1
  147. package/dist/index.cjs +55414 -1
  148. package/dist/index.css +1 -1
  149. package/dist/index.esm.js +38284 -1
  150. package/dist/react/chunks/lottie-72a4c6d4.js +17032 -0
  151. package/dist/react/index.cjs +56503 -1
  152. package/dist/react/index.esm.js +39373 -1
  153. package/package.json +1 -1
  154. package/dist/chunks/lottie-2637aa0f.js +0 -1
  155. package/dist/react/chunks/lottie-14e7addb.js +0 -1
@@ -1 +1,503 @@
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};
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 };