@designbasekorea/ui-wc 0.5.3 → 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 (156) 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.d.ts +1 -1
  153. package/dist/react/index.esm.js +39373 -1
  154. package/package.json +1 -1
  155. package/dist/chunks/lottie-2d1f6278.js +0 -1
  156. package/dist/react/chunks/lottie-14e7addb.js +0 -1
@@ -1 +1,522 @@
1
- import{createDbIcon as t}from"./db-icons.js";const e=["s","m","l","xl","full"],s=["default","tabs","segment"],i=["s","m","l"];class DbModal extends HTMLElement{constructor(){super(...arguments),this.titleId=`db-modal-title-${Math.random().toString(36).slice(2,9)}`,this.isMounted=!1,this.internalTabId="",this.internalSegment="",this.exitTimerId=null,this.handleDocumentKeyDown=t=>{"Escape"===t.key&&this.open&&"false"!==this.getAttribute("close-on-escape")&&(t.preventDefault(),this.close())}}static get observedAttributes(){return["open","title","size","header-variant","tabs","segments","selected-tab-id","default-selected-tab-id","segment-value","default-segment-value","nav-size","segment-full-width","close-on-outside-click","close-on-escape","show-close-button"]}get open(){return this.hasAttribute("open")&&"false"!==this.getAttribute("open")}set open(t){t?this.setAttribute("open","true"):this.removeAttribute("open")}connectedCallback(){this.classList.add("designbase-wc-modal-host"),document.addEventListener("keydown",this.handleDocumentKeyDown),this.childObserver=new MutationObserver(()=>{this.open&&this.render()}),this.childObserver.observe(this,{childList:!0}),this.syncOpenState()}disconnectedCallback(){this.childObserver?.disconnect(),document.removeEventListener("keydown",this.handleDocumentKeyDown),this.exitTimerId&&clearTimeout(this.exitTimerId),this.teardown()}attributeChangedCallback(t){if(this.isConnected)if("open"!==t){if("selected-tab-id"===t||"segment-value"===t){const t=this.getClassifiedChildren();return this.renderBodyContent(t.body),void this.renderHeader(t.header)}this.render(),this.isMounted&&this.syncVisibility()}else this.syncOpenState()}resolvedSize(){return e.includes(this.size)?this.size:"m"}get size(){return this.getAttribute("size")||"m"}set size(t){t?this.setAttribute("size",t):this.removeAttribute("size")}resolvedHeaderVariant(){const t=this.getAttribute("header-variant")||"default";return s.includes(t)?t:"default"}parsedTabs(){const t=this.getAttribute("tabs");if(!t)return[];try{const e=JSON.parse(t);return Array.isArray(e)?e:[]}catch{return[]}}parsedSegments(){const t=this.getAttribute("segments");if(!t)return[];try{const e=JSON.parse(t);return Array.isArray(e)?e:[]}catch{return[]}}usesIntegratedNav(){const t=this.resolvedHeaderVariant();return"tabs"===t&&this.parsedTabs().length>0||"segment"===t&&this.parsedSegments().length>0}closeIconSize(){const t=this.resolvedSize();return"s"===t?16:"l"===t?20:"xl"===t?24:18}activeTabId(){return this.getAttribute("selected-tab-id")||this.internalTabId||this.getAttribute("default-selected-tab-id")||this.parsedTabs()[0]?.id||""}activeSegmentValue(){return this.getAttribute("segment-value")||this.internalSegment||this.getAttribute("default-segment-value")||this.parsedSegments()[0]?.value||""}collectUserChildren(){return Array.from(this.children).filter(t=>!t.hasAttribute("data-wc-internal"))}classifyChildren(t){const isPart=(t,e,s)=>t.classList.contains(s)||t.getAttribute("data-modal-part")===e,e=t.filter(t=>isPart(t,"header","designbase-wc-modal__header")),s=t.filter(t=>isPart(t,"footer","designbase-wc-modal__footer")||"footer"===t.getAttribute("slot")),i=t.filter(t=>isPart(t,"body","designbase-wc-modal__body")),n=t.filter(t=>!e.includes(t)&&!s.includes(t)&&!i.includes(t));return{header:e,body:[...i,...n],footer:s}}getClassifiedChildren(){const t=this.classifyChildren(this.collectUserChildren());if(t.header.length||t.body.length||t.footer.length)return t;return{header:Array.from(this.headerEl?.children||[]).filter(t=>t!==this.closeButton&&!t.classList.contains("designbase-wc-modal__header-row")&&("header"===t.getAttribute("data-modal-part")||t.classList.contains("designbase-wc-modal__header"))),body:this.collectContentParts("body"),footer:this.collectContentParts("footer")}}isBodyPart(t){return t.classList.contains("designbase-wc-modal__body")||"body"===t.getAttribute("data-modal-part")}isFooterPart(t){return t.classList.contains("designbase-wc-modal__footer")||"footer"===t.getAttribute("data-modal-part")||"footer"===t.getAttribute("slot")}collectContentParts(t){if(!this.contentEl)return[];const e=Array.from(this.contentEl.children).filter(e=>"body"===t?this.isBodyPart(e):this.isFooterPart(e));return e.length>0?e:Array.from(this.children).filter(e=>"body"===t?this.isBodyPart(e):this.isFooterPart(e))}placeContentParts(t,e){this.contentEl&&e.forEach(e=>{if(e.parentElement!==this.contentEl){if("body"===t){const t=this.contentEl.querySelector(':scope > .designbase-wc-modal__footer, :scope > [data-modal-part="footer"]')||null;return void this.contentEl.insertBefore(e,t)}this.contentEl.append(e)}})}restorePartsToHost(){this.contentEl&&Array.from(this.contentEl.children).filter(t=>!t.classList.contains("designbase-wc-modal__integrated-content")&&!t.hasAttribute("data-wc-internal")).forEach(t=>{t.parentElement!==this&&this.append(t)})}bindFooterActions(){if(!this.contentEl||"true"===this.contentEl.dataset.modalActionsBound)return;this.contentEl.dataset.modalActionsBound="true";const handleClose=t=>{const e=t.target?.closest("[data-modal-close]");e&&this.contentEl?.contains(e)&&this.close()};this.contentEl.addEventListener("click",handleClose),this.contentEl.addEventListener("db-click",handleClose)}ensureStructure(){this.root||(this.root=document.createElement("div"),this.root.className="designbase-wc-modal__overlay",this.root.setAttribute("data-wc-internal",""),this.root.addEventListener("click",t=>{t.target===this.root&&"false"!==this.getAttribute("close-on-outside-click")&&this.close()}),this.panel=document.createElement("div"),this.panel.className="designbase-wc-modal",this.panel.setAttribute("role","dialog"),this.panel.setAttribute("aria-modal","true"),this.panel.addEventListener("click",t=>t.stopPropagation()),this.headerEl=document.createElement("div"),this.headerEl.className="designbase-wc-modal__header",this.headerContentEl=document.createElement("div"),this.headerContentEl.className="designbase-wc-modal__header-content",this.titleEl=document.createElement("h2"),this.titleEl.className="designbase-wc-modal__title",this.titleEl.id=this.titleId,this.closeButton=document.createElement("button"),this.closeButton.type="button",this.closeButton.className="designbase-wc-modal__close-button",this.closeButton.setAttribute("aria-label","모달 닫기"),this.closeButton.addEventListener("click",()=>this.close()),this.navEl=document.createElement("div"),this.navEl.className="designbase-wc-modal__header-nav",this.contentEl=document.createElement("div"),this.contentEl.className="designbase-wc-modal__content",this.panel.append(this.headerEl,this.contentEl),this.root.append(this.panel))}renderCloseButton(){if(!this.closeButton)return;const e=this.closeIconSize();this.closeButton.replaceChildren(t("close",e)),this.closeButton.hidden="false"===this.getAttribute("show-close-button")}renderDefaultHeader(t){if(!(this.headerEl&&this.headerContentEl&&this.titleEl&&this.closeButton))return;if(this.headerEl.className="designbase-wc-modal__header",this.headerEl.replaceChildren(),t.length>0)return t.forEach(t=>this.headerEl.append(t)),void("false"!==this.getAttribute("show-close-button")&&this.headerEl.append(this.closeButton));const e=this.getAttribute("title")||"";this.titleEl.textContent=e,this.titleEl.hidden=!e,this.headerContentEl.replaceChildren(),e&&this.headerContentEl.append(this.titleEl),this.renderCloseButton(),this.headerEl.append(this.headerContentEl),"false"!==this.getAttribute("show-close-button")&&this.headerEl.append(this.closeButton),this.panel&&(e?this.panel.setAttribute("aria-labelledby",this.titleId):this.panel.removeAttribute("aria-labelledby"))}renderNavHeader(){if(!(this.headerEl&&this.headerContentEl&&this.titleEl&&this.closeButton&&this.navEl))return;const t=this.resolvedHeaderVariant(),e=this.parsedTabs(),s=this.parsedSegments(),n=i.includes(this.getAttribute("nav-size")||"m")?this.getAttribute("nav-size")||"m":"s";this.headerEl.className=["designbase-wc-modal__header","tabs"===t&&"designbase-wc-modal__header--tabs","segment"===t&&"designbase-wc-modal__header--segment"].filter(Boolean).join(" ");const a=this.getAttribute("title")||"";this.titleEl.textContent=a,this.titleEl.hidden=!a,this.headerContentEl.replaceChildren(),a&&this.headerContentEl.append(this.titleEl),this.renderCloseButton();const r=document.createElement("div");if(r.className="designbase-wc-modal__header-row",r.append(this.headerContentEl),"false"!==this.getAttribute("show-close-button")&&r.append(this.closeButton),this.headerEl.replaceChildren(r),this.navEl.replaceChildren(),"tabs"===t&&e.length>0){const t=document.createElement("db-tabs");t.setAttribute("size",n),t.setAttribute("items",JSON.stringify(e.map(t=>({id:t.id,label:t.label,disabled:t.disabled})))),t.setAttribute("selected-id",this.activeTabId()),t.addEventListener("db-change",t=>{const e=t.detail?.id;e&&(this.hasAttribute("selected-tab-id")||(this.internalTabId=e),this.dispatchEvent(new CustomEvent("db-tab-change",{detail:{tabId:e},bubbles:!0,composed:!0})),this.renderBodyContent(this.getClassifiedChildren().body))}),this.tabsEl=t,this.navEl.append(t),this.headerEl.append(this.navEl)}if("segment"===t&&s.length>0){const t=document.createElement("db-segment-control");t.setAttribute("size",n),t.setAttribute("options",JSON.stringify(s.map(t=>({value:t.value,label:t.label,disabled:t.disabled})))),t.setAttribute("value",this.activeSegmentValue()),"false"!==this.getAttribute("segment-full-width")&&t.setAttribute("full-width",""),t.addEventListener("db-change",t=>{const e=t.detail?.value;e&&(this.hasAttribute("segment-value")||(this.internalSegment=e),this.dispatchEvent(new CustomEvent("db-segment-change",{detail:{value:e},bubbles:!0,composed:!0})),this.renderBodyContent(this.getClassifiedChildren().body))}),this.segmentEl=t,this.navEl.append(t),this.headerEl.append(this.navEl)}this.panel&&(a?this.panel.setAttribute("aria-labelledby",this.titleId):this.panel.removeAttribute("aria-labelledby"))}renderHeader(t){if(!this.headerEl)return;if(t.length>0)return this.headerEl.hidden=!1,void this.renderDefaultHeader(t);if(this.usesIntegratedNav())return this.headerEl.hidden=!1,void this.renderNavHeader();this.getAttribute("title")||""?(this.headerEl.hidden=!1,this.renderDefaultHeader([])):this.headerEl.hidden=!0}renderBodyContent(t=[]){if(!this.contentEl)return;let e=this.contentEl.querySelector(":scope > .designbase-wc-modal__integrated-content"),s="";if(this.usesIntegratedNav()){const t=this.resolvedHeaderVariant();if("tabs"===t){const t=this.parsedTabs().find(t=>t.id===this.activeTabId());s=t?.content||""}if("segment"===t){const t=this.parsedSegments().find(t=>t.value===this.activeSegmentValue());s=t?.content||""}}s?(e||(e=document.createElement("div"),e.className="designbase-wc-modal__integrated-content designbase-wc-modal__body",this.contentEl.insertBefore(e,this.contentEl.firstChild)),e.textContent=s):e?.remove();const i=t.filter(t=>this.isBodyPart(t)),n=t.filter(t=>!this.isBodyPart(t)&&!this.isFooterPart(t));this.placeContentParts("body",i.length>0?i:n)}renderFooter(t){if(!this.contentEl)return;const e=t.filter(t=>this.isFooterPart(t)),s=t.filter(t=>!this.isFooterPart(t)&&!this.isBodyPart(t)),i=e.length>0?e:s;this.placeContentParts("footer",i),i.forEach(t=>{t.hidden=!1}),this.bindFooterActions()}render(){this.ensureStructure();const{header:t,body:s,footer:i}=this.getClassifiedChildren();e.forEach(t=>this.panel?.classList.remove(`designbase-wc-modal--${t}`)),this.panel?.classList.add(`designbase-wc-modal--${this.resolvedSize()}`),this.renderHeader(t),this.renderBodyContent(s),this.renderFooter(i)}syncVisibility(){if(this.root&&this.panel){if(this.open)return this.root.setAttribute("data-state","entering"),this.panel.setAttribute("data-state","entering"),void requestAnimationFrame(()=>{this.panel,requestAnimationFrame(()=>{this.open&&this.root&&this.panel&&(this.root.setAttribute("data-state","entered"),this.panel.setAttribute("data-state","entered"))})});this.root.setAttribute("data-state","exiting"),this.panel.setAttribute("data-state","exiting")}}syncOpenState(){if(this.open)return this.render(),this.root&&!this.root.isConnected&&document.body.append(this.root),document.body.style.overflow="hidden",this.isMounted=!0,void this.syncVisibility();this.isMounted&&(this.syncVisibility(),document.body.style.overflow="",this.exitTimerId&&clearTimeout(this.exitTimerId),this.exitTimerId=window.setTimeout(()=>{this.open||this.teardown()},200))}teardown(){this.restorePartsToHost(),this.root?.remove(),this.isMounted=!1,document.body.style.overflow=""}close(){this.open=!1,this.dispatchEvent(new CustomEvent("db-close",{bubbles:!0,composed:!0}))}}customElements.get("db-modal")||customElements.define("db-modal",DbModal);export{DbModal};
1
+ import { createDbIcon } from './db-icons.js';
2
+
3
+ const SIZES = ['s', 'm', 'l', 'xl', 'full'];
4
+ const HEADER_VARIANTS = ['default', 'tabs', 'segment'];
5
+ const NAV_SIZES = ['s', 'm', 'l'];
6
+ class DbModal extends HTMLElement {
7
+ constructor() {
8
+ super(...arguments);
9
+ this.titleId = `db-modal-title-${Math.random().toString(36).slice(2, 9)}`;
10
+ this.isMounted = false;
11
+ this.internalTabId = '';
12
+ this.internalSegment = '';
13
+ this.exitTimerId = null;
14
+ this.handleDocumentKeyDown = (event) => {
15
+ if (event.key === 'Escape' && this.open && this.getAttribute('close-on-escape') !== 'false') {
16
+ event.preventDefault();
17
+ this.close();
18
+ }
19
+ };
20
+ }
21
+ static get observedAttributes() {
22
+ return [
23
+ 'open',
24
+ 'title',
25
+ 'size',
26
+ 'header-variant',
27
+ 'tabs',
28
+ 'segments',
29
+ 'selected-tab-id',
30
+ 'default-selected-tab-id',
31
+ 'segment-value',
32
+ 'default-segment-value',
33
+ 'nav-size',
34
+ 'segment-full-width',
35
+ 'close-on-outside-click',
36
+ 'close-on-escape',
37
+ 'show-close-button',
38
+ ];
39
+ }
40
+ get open() {
41
+ return this.hasAttribute('open') && this.getAttribute('open') !== 'false';
42
+ }
43
+ set open(value) {
44
+ if (value)
45
+ this.setAttribute('open', 'true');
46
+ else
47
+ this.removeAttribute('open');
48
+ }
49
+ connectedCallback() {
50
+ this.classList.add('designbase-wc-modal-host');
51
+ document.addEventListener('keydown', this.handleDocumentKeyDown);
52
+ this.childObserver = new MutationObserver(() => {
53
+ if (this.open)
54
+ this.render();
55
+ });
56
+ this.childObserver.observe(this, { childList: true });
57
+ this.syncOpenState();
58
+ }
59
+ disconnectedCallback() {
60
+ this.childObserver?.disconnect();
61
+ document.removeEventListener('keydown', this.handleDocumentKeyDown);
62
+ if (this.exitTimerId)
63
+ clearTimeout(this.exitTimerId);
64
+ this.teardown();
65
+ }
66
+ attributeChangedCallback(name) {
67
+ if (!this.isConnected)
68
+ return;
69
+ if (name === 'open') {
70
+ this.syncOpenState();
71
+ return;
72
+ }
73
+ if (name === 'selected-tab-id' || name === 'segment-value') {
74
+ const classified = this.getClassifiedChildren();
75
+ this.renderBodyContent(classified.body);
76
+ this.renderHeader(classified.header);
77
+ return;
78
+ }
79
+ this.render();
80
+ if (this.isMounted)
81
+ this.syncVisibility();
82
+ }
83
+ resolvedSize() {
84
+ return SIZES.includes(this.size) ? this.size : 'm';
85
+ }
86
+ get size() {
87
+ return this.getAttribute('size') || 'm';
88
+ }
89
+ set size(value) {
90
+ if (value)
91
+ this.setAttribute('size', value);
92
+ else
93
+ this.removeAttribute('size');
94
+ }
95
+ resolvedHeaderVariant() {
96
+ const value = this.getAttribute('header-variant') || 'default';
97
+ return HEADER_VARIANTS.includes(value) ? value : 'default';
98
+ }
99
+ parsedTabs() {
100
+ const raw = this.getAttribute('tabs');
101
+ if (!raw)
102
+ return [];
103
+ try {
104
+ const parsed = JSON.parse(raw);
105
+ return Array.isArray(parsed) ? parsed : [];
106
+ }
107
+ catch {
108
+ return [];
109
+ }
110
+ }
111
+ parsedSegments() {
112
+ const raw = this.getAttribute('segments');
113
+ if (!raw)
114
+ return [];
115
+ try {
116
+ const parsed = JSON.parse(raw);
117
+ return Array.isArray(parsed) ? parsed : [];
118
+ }
119
+ catch {
120
+ return [];
121
+ }
122
+ }
123
+ usesIntegratedNav() {
124
+ const variant = this.resolvedHeaderVariant();
125
+ return ((variant === 'tabs' && this.parsedTabs().length > 0) ||
126
+ (variant === 'segment' && this.parsedSegments().length > 0));
127
+ }
128
+ closeIconSize() {
129
+ const size = this.resolvedSize();
130
+ if (size === 's')
131
+ return 16;
132
+ if (size === 'l')
133
+ return 20;
134
+ if (size === 'xl')
135
+ return 24;
136
+ return 18;
137
+ }
138
+ activeTabId() {
139
+ return (this.getAttribute('selected-tab-id') ||
140
+ this.internalTabId ||
141
+ this.getAttribute('default-selected-tab-id') ||
142
+ this.parsedTabs()[0]?.id ||
143
+ '');
144
+ }
145
+ activeSegmentValue() {
146
+ return (this.getAttribute('segment-value') ||
147
+ this.internalSegment ||
148
+ this.getAttribute('default-segment-value') ||
149
+ this.parsedSegments()[0]?.value ||
150
+ '');
151
+ }
152
+ collectUserChildren() {
153
+ return Array.from(this.children).filter((child) => !child.hasAttribute('data-wc-internal'));
154
+ }
155
+ classifyChildren(children) {
156
+ const isPart = (child, part, className) => child.classList.contains(className) || child.getAttribute('data-modal-part') === part;
157
+ const header = children.filter((child) => isPart(child, 'header', 'designbase-wc-modal__header'));
158
+ const footer = children.filter((child) => isPart(child, 'footer', 'designbase-wc-modal__footer') || child.getAttribute('slot') === 'footer');
159
+ const body = children.filter((child) => isPart(child, 'body', 'designbase-wc-modal__body'));
160
+ const rest = children.filter((child) => !header.includes(child) && !footer.includes(child) && !body.includes(child));
161
+ return { header, body: [...body, ...rest], footer };
162
+ }
163
+ getClassifiedChildren() {
164
+ const fromHost = this.classifyChildren(this.collectUserChildren());
165
+ if (fromHost.header.length || fromHost.body.length || fromHost.footer.length) {
166
+ return fromHost;
167
+ }
168
+ const header = Array.from(this.headerEl?.children || []).filter((child) => {
169
+ if (child === this.closeButton || child.classList.contains('designbase-wc-modal__header-row'))
170
+ return false;
171
+ return child.getAttribute('data-modal-part') === 'header' || child.classList.contains('designbase-wc-modal__header');
172
+ });
173
+ const body = this.collectContentParts('body');
174
+ const footer = this.collectContentParts('footer');
175
+ return { header, body, footer };
176
+ }
177
+ isBodyPart(child) {
178
+ return child.classList.contains('designbase-wc-modal__body') || child.getAttribute('data-modal-part') === 'body';
179
+ }
180
+ isFooterPart(child) {
181
+ return (child.classList.contains('designbase-wc-modal__footer') ||
182
+ child.getAttribute('data-modal-part') === 'footer' ||
183
+ child.getAttribute('slot') === 'footer');
184
+ }
185
+ collectContentParts(kind) {
186
+ if (!this.contentEl)
187
+ return [];
188
+ const matches = Array.from(this.contentEl.children).filter((child) => kind === 'body' ? this.isBodyPart(child) : this.isFooterPart(child));
189
+ if (matches.length > 0)
190
+ return matches;
191
+ return Array.from(this.children).filter((child) => kind === 'body' ? this.isBodyPart(child) : this.isFooterPart(child));
192
+ }
193
+ placeContentParts(kind, parts) {
194
+ if (!this.contentEl)
195
+ return;
196
+ parts.forEach((part) => {
197
+ if (part.parentElement === this.contentEl)
198
+ return;
199
+ if (kind === 'body') {
200
+ const anchor = this.contentEl.querySelector(':scope > .designbase-wc-modal__footer, :scope > [data-modal-part="footer"]') ||
201
+ null;
202
+ this.contentEl.insertBefore(part, anchor);
203
+ return;
204
+ }
205
+ this.contentEl.append(part);
206
+ });
207
+ }
208
+ restorePartsToHost() {
209
+ if (!this.contentEl)
210
+ return;
211
+ Array.from(this.contentEl.children)
212
+ .filter((child) => !child.classList.contains('designbase-wc-modal__integrated-content') &&
213
+ !child.hasAttribute('data-wc-internal'))
214
+ .forEach((child) => {
215
+ if (child.parentElement !== this) {
216
+ this.append(child);
217
+ }
218
+ });
219
+ }
220
+ bindFooterActions() {
221
+ if (!this.contentEl || this.contentEl.dataset.modalActionsBound === 'true')
222
+ return;
223
+ this.contentEl.dataset.modalActionsBound = 'true';
224
+ const handleClose = (event) => {
225
+ const target = event.target?.closest('[data-modal-close]');
226
+ if (target && this.contentEl?.contains(target)) {
227
+ this.close();
228
+ }
229
+ };
230
+ this.contentEl.addEventListener('click', handleClose);
231
+ this.contentEl.addEventListener('db-click', handleClose);
232
+ }
233
+ ensureStructure() {
234
+ if (!this.root) {
235
+ this.root = document.createElement('div');
236
+ this.root.className = 'designbase-wc-modal__overlay';
237
+ this.root.setAttribute('data-wc-internal', '');
238
+ this.root.addEventListener('click', (event) => {
239
+ if (event.target === this.root && this.getAttribute('close-on-outside-click') !== 'false') {
240
+ this.close();
241
+ }
242
+ });
243
+ this.panel = document.createElement('div');
244
+ this.panel.className = 'designbase-wc-modal';
245
+ this.panel.setAttribute('role', 'dialog');
246
+ this.panel.setAttribute('aria-modal', 'true');
247
+ this.panel.addEventListener('click', (event) => event.stopPropagation());
248
+ this.headerEl = document.createElement('div');
249
+ this.headerEl.className = 'designbase-wc-modal__header';
250
+ this.headerContentEl = document.createElement('div');
251
+ this.headerContentEl.className = 'designbase-wc-modal__header-content';
252
+ this.titleEl = document.createElement('h2');
253
+ this.titleEl.className = 'designbase-wc-modal__title';
254
+ this.titleEl.id = this.titleId;
255
+ this.closeButton = document.createElement('button');
256
+ this.closeButton.type = 'button';
257
+ this.closeButton.className = 'designbase-wc-modal__close-button';
258
+ this.closeButton.setAttribute('aria-label', '모달 닫기');
259
+ this.closeButton.addEventListener('click', () => this.close());
260
+ this.navEl = document.createElement('div');
261
+ this.navEl.className = 'designbase-wc-modal__header-nav';
262
+ this.contentEl = document.createElement('div');
263
+ this.contentEl.className = 'designbase-wc-modal__content';
264
+ this.panel.append(this.headerEl, this.contentEl);
265
+ this.root.append(this.panel);
266
+ }
267
+ }
268
+ renderCloseButton() {
269
+ if (!this.closeButton)
270
+ return;
271
+ const iconSize = this.closeIconSize();
272
+ this.closeButton.replaceChildren(createDbIcon('close', iconSize));
273
+ this.closeButton.hidden = this.getAttribute('show-close-button') === 'false';
274
+ }
275
+ renderDefaultHeader(customHeader) {
276
+ if (!this.headerEl || !this.headerContentEl || !this.titleEl || !this.closeButton)
277
+ return;
278
+ this.headerEl.className = 'designbase-wc-modal__header';
279
+ this.headerEl.replaceChildren();
280
+ if (customHeader.length > 0) {
281
+ customHeader.forEach((child) => this.headerEl.append(child));
282
+ if (this.getAttribute('show-close-button') !== 'false') {
283
+ this.headerEl.append(this.closeButton);
284
+ }
285
+ return;
286
+ }
287
+ const title = this.getAttribute('title') || '';
288
+ this.titleEl.textContent = title;
289
+ this.titleEl.hidden = !title;
290
+ this.headerContentEl.replaceChildren();
291
+ if (title)
292
+ this.headerContentEl.append(this.titleEl);
293
+ this.renderCloseButton();
294
+ this.headerEl.append(this.headerContentEl);
295
+ if (this.getAttribute('show-close-button') !== 'false') {
296
+ this.headerEl.append(this.closeButton);
297
+ }
298
+ if (this.panel) {
299
+ if (title)
300
+ this.panel.setAttribute('aria-labelledby', this.titleId);
301
+ else
302
+ this.panel.removeAttribute('aria-labelledby');
303
+ }
304
+ }
305
+ renderNavHeader() {
306
+ if (!this.headerEl || !this.headerContentEl || !this.titleEl || !this.closeButton || !this.navEl)
307
+ return;
308
+ const variant = this.resolvedHeaderVariant();
309
+ const tabs = this.parsedTabs();
310
+ const segments = this.parsedSegments();
311
+ const navSize = NAV_SIZES.includes((this.getAttribute('nav-size') || 'm'))
312
+ ? this.getAttribute('nav-size') || 'm'
313
+ : 's';
314
+ this.headerEl.className = [
315
+ 'designbase-wc-modal__header',
316
+ variant === 'tabs' && 'designbase-wc-modal__header--tabs',
317
+ variant === 'segment' && 'designbase-wc-modal__header--segment',
318
+ ]
319
+ .filter(Boolean)
320
+ .join(' ');
321
+ const title = this.getAttribute('title') || '';
322
+ this.titleEl.textContent = title;
323
+ this.titleEl.hidden = !title;
324
+ this.headerContentEl.replaceChildren();
325
+ if (title)
326
+ this.headerContentEl.append(this.titleEl);
327
+ this.renderCloseButton();
328
+ const headerRow = document.createElement('div');
329
+ headerRow.className = 'designbase-wc-modal__header-row';
330
+ headerRow.append(this.headerContentEl);
331
+ if (this.getAttribute('show-close-button') !== 'false') {
332
+ headerRow.append(this.closeButton);
333
+ }
334
+ this.headerEl.replaceChildren(headerRow);
335
+ this.navEl.replaceChildren();
336
+ if (variant === 'tabs' && tabs.length > 0) {
337
+ const tabsComponent = document.createElement('db-tabs');
338
+ tabsComponent.setAttribute('size', navSize);
339
+ tabsComponent.setAttribute('items', JSON.stringify(tabs.map((tab) => ({ id: tab.id, label: tab.label, disabled: tab.disabled }))));
340
+ tabsComponent.setAttribute('selected-id', this.activeTabId());
341
+ tabsComponent.addEventListener('db-change', (event) => {
342
+ const tabId = event.detail?.id;
343
+ if (!tabId)
344
+ return;
345
+ if (!this.hasAttribute('selected-tab-id')) {
346
+ this.internalTabId = tabId;
347
+ }
348
+ this.dispatchEvent(new CustomEvent('db-tab-change', {
349
+ detail: { tabId },
350
+ bubbles: true,
351
+ composed: true,
352
+ }));
353
+ this.renderBodyContent(this.getClassifiedChildren().body);
354
+ });
355
+ this.tabsEl = tabsComponent;
356
+ this.navEl.append(tabsComponent);
357
+ this.headerEl.append(this.navEl);
358
+ }
359
+ if (variant === 'segment' && segments.length > 0) {
360
+ const segmentComponent = document.createElement('db-segment-control');
361
+ segmentComponent.setAttribute('size', navSize);
362
+ segmentComponent.setAttribute('options', JSON.stringify(segments.map((segment) => ({ value: segment.value, label: segment.label, disabled: segment.disabled }))));
363
+ segmentComponent.setAttribute('value', this.activeSegmentValue());
364
+ if (this.getAttribute('segment-full-width') !== 'false') {
365
+ segmentComponent.setAttribute('full-width', '');
366
+ }
367
+ segmentComponent.addEventListener('db-change', (event) => {
368
+ const value = event.detail?.value;
369
+ if (!value)
370
+ return;
371
+ if (!this.hasAttribute('segment-value')) {
372
+ this.internalSegment = value;
373
+ }
374
+ this.dispatchEvent(new CustomEvent('db-segment-change', {
375
+ detail: { value },
376
+ bubbles: true,
377
+ composed: true,
378
+ }));
379
+ this.renderBodyContent(this.getClassifiedChildren().body);
380
+ });
381
+ this.segmentEl = segmentComponent;
382
+ this.navEl.append(segmentComponent);
383
+ this.headerEl.append(this.navEl);
384
+ }
385
+ if (this.panel) {
386
+ if (title)
387
+ this.panel.setAttribute('aria-labelledby', this.titleId);
388
+ else
389
+ this.panel.removeAttribute('aria-labelledby');
390
+ }
391
+ }
392
+ renderHeader(customHeader) {
393
+ if (!this.headerEl)
394
+ return;
395
+ if (customHeader.length > 0) {
396
+ this.headerEl.hidden = false;
397
+ this.renderDefaultHeader(customHeader);
398
+ return;
399
+ }
400
+ if (this.usesIntegratedNav()) {
401
+ this.headerEl.hidden = false;
402
+ this.renderNavHeader();
403
+ return;
404
+ }
405
+ const title = this.getAttribute('title') || '';
406
+ if (!title) {
407
+ this.headerEl.hidden = true;
408
+ return;
409
+ }
410
+ this.headerEl.hidden = false;
411
+ this.renderDefaultHeader([]);
412
+ }
413
+ renderBodyContent(userBody = []) {
414
+ if (!this.contentEl)
415
+ return;
416
+ let integratedEl = this.contentEl.querySelector(':scope > .designbase-wc-modal__integrated-content');
417
+ let integratedText = '';
418
+ if (this.usesIntegratedNav()) {
419
+ const variant = this.resolvedHeaderVariant();
420
+ if (variant === 'tabs') {
421
+ const tab = this.parsedTabs().find((item) => item.id === this.activeTabId());
422
+ integratedText = tab?.content || '';
423
+ }
424
+ if (variant === 'segment') {
425
+ const segment = this.parsedSegments().find((item) => item.value === this.activeSegmentValue());
426
+ integratedText = segment?.content || '';
427
+ }
428
+ }
429
+ if (integratedText) {
430
+ if (!integratedEl) {
431
+ integratedEl = document.createElement('div');
432
+ integratedEl.className = 'designbase-wc-modal__integrated-content designbase-wc-modal__body';
433
+ this.contentEl.insertBefore(integratedEl, this.contentEl.firstChild);
434
+ }
435
+ integratedEl.textContent = integratedText;
436
+ }
437
+ else {
438
+ integratedEl?.remove();
439
+ }
440
+ const bodyWrappers = userBody.filter((child) => this.isBodyPart(child));
441
+ const looseBody = userBody.filter((child) => !this.isBodyPart(child) && !this.isFooterPart(child));
442
+ this.placeContentParts('body', bodyWrappers.length > 0 ? bodyWrappers : looseBody);
443
+ }
444
+ renderFooter(footerChildren) {
445
+ if (!this.contentEl)
446
+ return;
447
+ const footerWrappers = footerChildren.filter((child) => this.isFooterPart(child));
448
+ const looseFooter = footerChildren.filter((child) => !this.isFooterPart(child) && !this.isBodyPart(child));
449
+ const footerParts = footerWrappers.length > 0 ? footerWrappers : looseFooter;
450
+ this.placeContentParts('footer', footerParts);
451
+ footerParts.forEach((part) => {
452
+ part.hidden = false;
453
+ });
454
+ this.bindFooterActions();
455
+ }
456
+ render() {
457
+ this.ensureStructure();
458
+ const { header, body, footer } = this.getClassifiedChildren();
459
+ SIZES.forEach((size) => this.panel?.classList.remove(`designbase-wc-modal--${size}`));
460
+ this.panel?.classList.add(`designbase-wc-modal--${this.resolvedSize()}`);
461
+ this.renderHeader(header);
462
+ this.renderBodyContent(body);
463
+ this.renderFooter(footer);
464
+ }
465
+ syncVisibility() {
466
+ if (!this.root || !this.panel)
467
+ return;
468
+ if (this.open) {
469
+ this.root.setAttribute('data-state', 'entering');
470
+ this.panel.setAttribute('data-state', 'entering');
471
+ requestAnimationFrame(() => {
472
+ void this.panel?.offsetHeight;
473
+ requestAnimationFrame(() => {
474
+ if (!this.open || !this.root || !this.panel)
475
+ return;
476
+ this.root.setAttribute('data-state', 'entered');
477
+ this.panel.setAttribute('data-state', 'entered');
478
+ });
479
+ });
480
+ return;
481
+ }
482
+ this.root.setAttribute('data-state', 'exiting');
483
+ this.panel.setAttribute('data-state', 'exiting');
484
+ }
485
+ syncOpenState() {
486
+ if (this.open) {
487
+ this.render();
488
+ if (this.root && !this.root.isConnected) {
489
+ document.body.append(this.root);
490
+ }
491
+ document.body.style.overflow = 'hidden';
492
+ this.isMounted = true;
493
+ this.syncVisibility();
494
+ return;
495
+ }
496
+ if (!this.isMounted)
497
+ return;
498
+ this.syncVisibility();
499
+ document.body.style.overflow = '';
500
+ if (this.exitTimerId)
501
+ clearTimeout(this.exitTimerId);
502
+ this.exitTimerId = window.setTimeout(() => {
503
+ if (!this.open)
504
+ this.teardown();
505
+ }, 200);
506
+ }
507
+ teardown() {
508
+ this.restorePartsToHost();
509
+ this.root?.remove();
510
+ this.isMounted = false;
511
+ document.body.style.overflow = '';
512
+ }
513
+ close() {
514
+ this.open = false;
515
+ this.dispatchEvent(new CustomEvent('db-close', { bubbles: true, composed: true }));
516
+ }
517
+ }
518
+ if (!customElements.get('db-modal')) {
519
+ customElements.define('db-modal', DbModal);
520
+ }
521
+
522
+ export { DbModal };