@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,372 @@
1
- import{createDbIcon as e}from"./db-icons.js";const t=["s","m","l","xl"];class DbLightbox extends HTMLElement{constructor(){super(...arguments),this.portalEl=null,this.imageEl=null,this.loadingEl=null,this.errorEl=null,this.counterBadge=null,this.prevNav=null,this.nextNav=null,this.currentIndex=0,this.imageLoaded=!1,this.imageError=!1,this.keydownHandler=null,this.boundSrc="",this.thumbnailSignature="",this.handleImageLoad=()=>{this.imageLoaded=!0,this.imageError=!1,this.syncImageLayers()},this.handleImageError=()=>{this.imageLoaded=!1,this.imageError=!0,this.syncImageLayers()}}static get observedAttributes(){return["images","current-index","size","open","enable-keyboard","show-thumbnails","show-counter","show-close-button","show-navigation-buttons","show-toolbar","close-on-backdrop-click","close-on-escape"]}connectedCallback(){this.classList.add("designbase-wc-lightbox-host"),this.syncOpenState()}disconnectedCallback(){this.unmount()}attributeChangedCallback(e,t,s){if("current-index"===e)return this.currentIndex=Number(s||0),this.resetImageState(),void(this.open&&this.refreshView());"open"!==e?"images"===e&&this.open&&this.refreshView():this.syncOpenState()}get open(){return this.hasAttribute("open")&&"false"!==this.getAttribute("open")}set open(e){e?this.setAttribute("open",""):this.removeAttribute("open")}parseImages(){const e=this.getAttribute("images");if(!e)return[];try{const t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}}getCurrentImage(){return this.parseImages()[this.currentIndex]||null}resetImageState(){this.imageLoaded=!1,this.imageError=!1,this.boundSrc=""}close(){this.open=!1,this.dispatchEvent(new CustomEvent("db-close",{bubbles:!0,composed:!0}))}goTo(e){const t=this.parseImages();if(!t.length)return;const s=(e%t.length+t.length)%t.length;s!==this.currentIndex&&(this.currentIndex=s,this.setAttribute("current-index",String(s)),this.resetImageState(),this.refreshView(),this.dispatchEvent(new CustomEvent("db-image-change",{bubbles:!0,composed:!0,detail:{index:s}})))}createIconButton(e,t,s,i,n={}){const a=document.createElement("db-button");return a.className=e,a.setAttribute("variant",n.variant||"ghost"),a.setAttribute("size",n.size||"m"),a.setAttribute("icon-only",""),a.setAttribute("start-icon",t),a.setAttribute("aria-label",s),n.radius&&a.setAttribute("radius",n.radius),a.addEventListener("db-click",i),a}buildPortal(){const s=this.getAttribute("size")||"l",i=t.includes(s)?s:"l",n=document.createElement("div");n.className=`designbase-wc-lightbox designbase-wc-lightbox--size-${i}`,n.setAttribute("data-wc-internal","");const a=document.createElement("div");a.className="designbase-wc-lightbox__overlay";const r=document.createElement("div");r.className="designbase-wc-lightbox__modal";const o=document.createElement("div");o.className="designbase-wc-lightbox__header";const l=document.createElement("div");l.className="designbase-wc-lightbox__title";const h=document.createElement("h3");h.className="designbase-wc-lightbox__title-text";const c=document.createElement("db-badge");c.className="designbase-wc-lightbox__counter",c.setAttribute("size","s"),c.setAttribute("variant","secondary"),c.setAttribute("badge-style","text"),l.append(h,c);const d=document.createElement("div");d.className="designbase-wc-lightbox__header-actions","false"!==this.getAttribute("show-close-button")&&d.append(this.createIconButton("designbase-wc-lightbox__close-button","close","닫기",()=>this.close())),o.append(l,d);const g=document.createElement("div");g.className="designbase-wc-lightbox__content",this.prevNav=this.createIconButton("designbase-wc-lightbox__nav-button designbase-wc-lightbox__nav-button--prev","chevron-left","이전 이미지",()=>this.goTo(this.currentIndex-1),{radius:"pill",size:"l"}),this.nextNav=this.createIconButton("designbase-wc-lightbox__nav-button designbase-wc-lightbox__nav-button--next","chevron-right","다음 이미지",()=>this.goTo(this.currentIndex+1),{radius:"pill",size:"l"});const u=document.createElement("div");u.className="designbase-wc-lightbox__image-container",this.errorEl=document.createElement("div"),this.errorEl.className="designbase-wc-lightbox__error",this.errorEl.hidden=!0;const b=e("gallery",24);b.classList.add("designbase-wc-lightbox__error-icon"),this.errorEl.append(b);const m=document.createElement("p");m.className="designbase-wc-lightbox__error-text",m.textContent="이미지를 불러올 수 없습니다",this.errorEl.append(m),this.loadingEl=document.createElement("div"),this.loadingEl.className="designbase-wc-lightbox__loading";const p=document.createElement("db-spinner");p.setAttribute("type","circular"),p.setAttribute("size","m"),p.setAttribute("show-label",""),p.setAttribute("label","이미지 로딩 중..."),this.loadingEl.append(p),this.imageEl=document.createElement("img"),this.imageEl.className="designbase-wc-lightbox__image",this.imageEl.draggable=!1,this.imageEl.addEventListener("load",this.handleImageLoad),this.imageEl.addEventListener("error",this.handleImageError),u.append(this.errorEl,this.loadingEl,this.imageEl);const E=document.createElement("div");E.className="designbase-wc-lightbox__description";const x=document.createElement("p");x.className="designbase-wc-lightbox__description-text",E.append(x),"false"!==this.getAttribute("show-navigation-buttons")&&g.append(this.prevNav,this.nextNav),g.append(u,E);const w=document.createElement("div");w.className="designbase-wc-lightbox__thumbnails";const v=document.createElement("div");return v.className="designbase-wc-lightbox__thumbnails-container",w.append(v),r.append(o,g,w),a.append(r),n.append(a),a.addEventListener("click",e=>{e.target===a&&"false"!==this.getAttribute("close-on-backdrop-click")&&this.close()}),this.portalEl=n,this.counterBadge=c,n}syncImageLayers(){this.imageEl&&this.loadingEl&&this.errorEl&&(this.imageEl.classList.toggle("designbase-wc-lightbox__image--loaded",this.imageLoaded),this.loadingEl.hidden=this.imageLoaded||this.imageError,this.errorEl.hidden=!this.imageError,this.imageEl.hidden=this.imageError)}updateThumbnails(){if(!this.portalEl)return;const e=this.portalEl.querySelector(".designbase-wc-lightbox__thumbnails-container"),t=this.portalEl.querySelector(".designbase-wc-lightbox__thumbnails");if(!e||!t)return;const s=this.parseImages(),i="false"!==this.getAttribute("show-thumbnails")&&s.length>1;if(t.hidden=!i,!i)return e.replaceChildren(),void(this.thumbnailSignature="");const n=s.map(e=>e.thumbnail||e.src).join("|");n!==this.thumbnailSignature||e.childElementCount!==s.length?(this.thumbnailSignature=n,e.replaceChildren(),s.forEach((t,s)=>{const i=document.createElement("button");i.type="button",i.className=["designbase-wc-lightbox__thumbnail",s===this.currentIndex&&"designbase-wc-lightbox__thumbnail--active"].filter(Boolean).join(" "),i.title=t.title||`이미지 ${s+1}`,i.setAttribute("aria-label",t.alt||t.title||`이미지 ${s+1}`),i.setAttribute("aria-current",s===this.currentIndex?"true":"false");const n=document.createElement("img");n.className="designbase-wc-lightbox__thumbnail-image",n.src=t.thumbnail||t.src,n.alt="",n.draggable=!1,n.loading="lazy",n.decoding="async",i.append(n),i.addEventListener("click",()=>this.goTo(s)),e.append(i)})):Array.from(e.children).forEach((e,t)=>{const s=e,i=t===this.currentIndex;s.classList.toggle("designbase-wc-lightbox__thumbnail--active",i),s.setAttribute("aria-current",i?"true":"false")})}loadCurrentImage(){if(!this.imageEl)return;const e=this.getCurrentImage();if(!e?.src)return this.imageEl.removeAttribute("src"),this.resetImageState(),void this.syncImageLayers();this.boundSrc!==e.src&&(this.boundSrc=e.src,this.resetImageState(),this.imageEl.src=e.src,this.imageEl.alt=e.alt||e.title||`이미지 ${this.currentIndex+1}`,this.syncImageLayers(),this.imageEl.complete&&this.imageEl.naturalWidth>0&&this.handleImageLoad())}refreshView(){if(!this.portalEl)return;const e=this.getCurrentImage(),t=this.parseImages(),s=this.portalEl.querySelector(".designbase-wc-lightbox__title-text"),i=this.portalEl.querySelector(".designbase-wc-lightbox__description-text"),n=this.portalEl.querySelector(".designbase-wc-lightbox__description");if(s&&(s.textContent=e?.title||"",s.hidden=!e?.title),this.counterBadge){const e="false"!==this.getAttribute("show-counter")&&t.length>1?`${this.currentIndex+1} / ${t.length}`:"";this.counterBadge.textContent=e,this.counterBadge.hidden=!e}n&&i&&(i.textContent=e?.description||"",n.hidden=!e?.description);const a="false"!==this.getAttribute("show-navigation-buttons")&&t.length>1;this.prevNav&&(this.prevNav.hidden=!a),this.nextNav&&(this.nextNav.hidden=!a),this.loadCurrentImage(),this.updateThumbnails()}mount(){this.portalEl||(this.portalEl=this.buildPortal()),this.portalEl.isConnected||document.body.append(this.portalEl),document.body.style.overflow="hidden",this.keydownHandler||(this.keydownHandler=e=>{this.open&&"false"!==this.getAttribute("enable-keyboard")&&("Escape"===e.key&&"false"!==this.getAttribute("close-on-escape")&&(e.preventDefault(),this.close()),"ArrowLeft"===e.key&&this.goTo(this.currentIndex-1),"ArrowRight"===e.key&&this.goTo(this.currentIndex+1))},document.addEventListener("keydown",this.keydownHandler)),this.currentIndex=Number(this.getAttribute("current-index")||0),this.refreshView()}unmount(){this.portalEl?.remove(),document.body.style.overflow="",this.keydownHandler&&(document.removeEventListener("keydown",this.keydownHandler),this.keydownHandler=null)}syncOpenState(){this.open?this.mount():this.unmount()}}customElements.get("db-lightbox")||customElements.define("db-lightbox",DbLightbox);export{DbLightbox};
1
+ import { createDbIcon } from './db-icons.js';
2
+
3
+ const SIZES = ['s', 'm', 'l', 'xl'];
4
+ class DbLightbox extends HTMLElement {
5
+ constructor() {
6
+ super(...arguments);
7
+ this.portalEl = null;
8
+ this.imageEl = null;
9
+ this.loadingEl = null;
10
+ this.errorEl = null;
11
+ this.counterBadge = null;
12
+ this.prevNav = null;
13
+ this.nextNav = null;
14
+ this.currentIndex = 0;
15
+ this.imageLoaded = false;
16
+ this.imageError = false;
17
+ this.keydownHandler = null;
18
+ this.boundSrc = '';
19
+ this.thumbnailSignature = '';
20
+ this.handleImageLoad = () => {
21
+ this.imageLoaded = true;
22
+ this.imageError = false;
23
+ this.syncImageLayers();
24
+ };
25
+ this.handleImageError = () => {
26
+ this.imageLoaded = false;
27
+ this.imageError = true;
28
+ this.syncImageLayers();
29
+ };
30
+ }
31
+ static get observedAttributes() {
32
+ return [
33
+ 'images',
34
+ 'current-index',
35
+ 'size',
36
+ 'open',
37
+ 'enable-keyboard',
38
+ 'show-thumbnails',
39
+ 'show-counter',
40
+ 'show-close-button',
41
+ 'show-navigation-buttons',
42
+ 'show-toolbar',
43
+ 'close-on-backdrop-click',
44
+ 'close-on-escape',
45
+ ];
46
+ }
47
+ connectedCallback() {
48
+ this.classList.add('designbase-wc-lightbox-host');
49
+ this.syncOpenState();
50
+ }
51
+ disconnectedCallback() {
52
+ this.unmount();
53
+ }
54
+ attributeChangedCallback(name, _old, newValue) {
55
+ if (name === 'current-index') {
56
+ this.currentIndex = Number(newValue || 0);
57
+ this.resetImageState();
58
+ if (this.open)
59
+ this.refreshView();
60
+ return;
61
+ }
62
+ if (name === 'open') {
63
+ this.syncOpenState();
64
+ return;
65
+ }
66
+ if (name === 'images' && this.open) {
67
+ this.refreshView();
68
+ }
69
+ }
70
+ get open() {
71
+ return this.hasAttribute('open') && this.getAttribute('open') !== 'false';
72
+ }
73
+ set open(value) {
74
+ if (value)
75
+ this.setAttribute('open', '');
76
+ else
77
+ this.removeAttribute('open');
78
+ }
79
+ parseImages() {
80
+ const raw = this.getAttribute('images');
81
+ if (!raw)
82
+ return [];
83
+ try {
84
+ const parsed = JSON.parse(raw);
85
+ return Array.isArray(parsed) ? parsed : [];
86
+ }
87
+ catch {
88
+ return [];
89
+ }
90
+ }
91
+ getCurrentImage() {
92
+ return this.parseImages()[this.currentIndex] || null;
93
+ }
94
+ resetImageState() {
95
+ this.imageLoaded = false;
96
+ this.imageError = false;
97
+ this.boundSrc = '';
98
+ }
99
+ close() {
100
+ this.open = false;
101
+ this.dispatchEvent(new CustomEvent('db-close', { bubbles: true, composed: true }));
102
+ }
103
+ goTo(index) {
104
+ const images = this.parseImages();
105
+ if (!images.length)
106
+ return;
107
+ const next = ((index % images.length) + images.length) % images.length;
108
+ if (next === this.currentIndex)
109
+ return;
110
+ this.currentIndex = next;
111
+ this.setAttribute('current-index', String(next));
112
+ this.resetImageState();
113
+ this.refreshView();
114
+ this.dispatchEvent(new CustomEvent('db-image-change', {
115
+ bubbles: true,
116
+ composed: true,
117
+ detail: { index: next },
118
+ }));
119
+ }
120
+ createIconButton(className, icon, label, onClick, options = {}) {
121
+ const button = document.createElement('db-button');
122
+ button.className = className;
123
+ button.setAttribute('variant', options.variant || 'ghost');
124
+ button.setAttribute('size', options.size || 'm');
125
+ button.setAttribute('icon-only', '');
126
+ button.setAttribute('start-icon', icon);
127
+ button.setAttribute('aria-label', label);
128
+ if (options.radius)
129
+ button.setAttribute('radius', options.radius);
130
+ button.addEventListener('db-click', onClick);
131
+ return button;
132
+ }
133
+ buildPortal() {
134
+ const size = this.getAttribute('size') || 'l';
135
+ const sizeClass = SIZES.includes(size) ? size : 'l';
136
+ const root = document.createElement('div');
137
+ root.className = `designbase-wc-lightbox designbase-wc-lightbox--size-${sizeClass}`;
138
+ root.setAttribute('data-wc-internal', '');
139
+ const overlay = document.createElement('div');
140
+ overlay.className = 'designbase-wc-lightbox__overlay';
141
+ const modal = document.createElement('div');
142
+ modal.className = 'designbase-wc-lightbox__modal';
143
+ const header = document.createElement('div');
144
+ header.className = 'designbase-wc-lightbox__header';
145
+ const titleWrap = document.createElement('div');
146
+ titleWrap.className = 'designbase-wc-lightbox__title';
147
+ const title = document.createElement('h3');
148
+ title.className = 'designbase-wc-lightbox__title-text';
149
+ const counter = document.createElement('db-badge');
150
+ counter.className = 'designbase-wc-lightbox__counter';
151
+ counter.setAttribute('size', 's');
152
+ counter.setAttribute('variant', 'secondary');
153
+ counter.setAttribute('badge-style', 'text');
154
+ titleWrap.append(title, counter);
155
+ const headerActions = document.createElement('div');
156
+ headerActions.className = 'designbase-wc-lightbox__header-actions';
157
+ if (this.getAttribute('show-close-button') !== 'false') {
158
+ headerActions.append(this.createIconButton('designbase-wc-lightbox__close-button', 'close', '닫기', () => this.close()));
159
+ }
160
+ header.append(titleWrap, headerActions);
161
+ const content = document.createElement('div');
162
+ content.className = 'designbase-wc-lightbox__content';
163
+ this.prevNav = this.createIconButton('designbase-wc-lightbox__nav-button designbase-wc-lightbox__nav-button--prev', 'chevron-left', '이전 이미지', () => this.goTo(this.currentIndex - 1), { radius: 'pill', size: 'l' });
164
+ this.nextNav = this.createIconButton('designbase-wc-lightbox__nav-button designbase-wc-lightbox__nav-button--next', 'chevron-right', '다음 이미지', () => this.goTo(this.currentIndex + 1), { radius: 'pill', size: 'l' });
165
+ const imageContainer = document.createElement('div');
166
+ imageContainer.className = 'designbase-wc-lightbox__image-container';
167
+ this.errorEl = document.createElement('div');
168
+ this.errorEl.className = 'designbase-wc-lightbox__error';
169
+ this.errorEl.hidden = true;
170
+ const errorIcon = createDbIcon('gallery', 24);
171
+ errorIcon.classList.add('designbase-wc-lightbox__error-icon');
172
+ this.errorEl.append(errorIcon);
173
+ const errorText = document.createElement('p');
174
+ errorText.className = 'designbase-wc-lightbox__error-text';
175
+ errorText.textContent = '이미지를 불러올 수 없습니다';
176
+ this.errorEl.append(errorText);
177
+ this.loadingEl = document.createElement('div');
178
+ this.loadingEl.className = 'designbase-wc-lightbox__loading';
179
+ const spinner = document.createElement('db-spinner');
180
+ spinner.setAttribute('type', 'circular');
181
+ spinner.setAttribute('size', 'm');
182
+ spinner.setAttribute('show-label', '');
183
+ spinner.setAttribute('label', '이미지 로딩 중...');
184
+ this.loadingEl.append(spinner);
185
+ this.imageEl = document.createElement('img');
186
+ this.imageEl.className = 'designbase-wc-lightbox__image';
187
+ this.imageEl.draggable = false;
188
+ this.imageEl.addEventListener('load', this.handleImageLoad);
189
+ this.imageEl.addEventListener('error', this.handleImageError);
190
+ imageContainer.append(this.errorEl, this.loadingEl, this.imageEl);
191
+ const description = document.createElement('div');
192
+ description.className = 'designbase-wc-lightbox__description';
193
+ const descriptionText = document.createElement('p');
194
+ descriptionText.className = 'designbase-wc-lightbox__description-text';
195
+ description.append(descriptionText);
196
+ if (this.getAttribute('show-navigation-buttons') !== 'false') {
197
+ content.append(this.prevNav, this.nextNav);
198
+ }
199
+ content.append(imageContainer, description);
200
+ const thumbnails = document.createElement('div');
201
+ thumbnails.className = 'designbase-wc-lightbox__thumbnails';
202
+ const thumbnailsContainer = document.createElement('div');
203
+ thumbnailsContainer.className = 'designbase-wc-lightbox__thumbnails-container';
204
+ thumbnails.append(thumbnailsContainer);
205
+ modal.append(header, content, thumbnails);
206
+ overlay.append(modal);
207
+ root.append(overlay);
208
+ overlay.addEventListener('click', (event) => {
209
+ if (event.target === overlay && this.getAttribute('close-on-backdrop-click') !== 'false') {
210
+ this.close();
211
+ }
212
+ });
213
+ this.portalEl = root;
214
+ this.counterBadge = counter;
215
+ return root;
216
+ }
217
+ syncImageLayers() {
218
+ if (!this.imageEl || !this.loadingEl || !this.errorEl)
219
+ return;
220
+ this.imageEl.classList.toggle('designbase-wc-lightbox__image--loaded', this.imageLoaded);
221
+ this.loadingEl.hidden = this.imageLoaded || this.imageError;
222
+ this.errorEl.hidden = !this.imageError;
223
+ this.imageEl.hidden = this.imageError;
224
+ }
225
+ updateThumbnails() {
226
+ if (!this.portalEl)
227
+ return;
228
+ const thumbnailsContainer = this.portalEl.querySelector('.designbase-wc-lightbox__thumbnails-container');
229
+ const thumbnailsWrap = this.portalEl.querySelector('.designbase-wc-lightbox__thumbnails');
230
+ if (!thumbnailsContainer || !thumbnailsWrap)
231
+ return;
232
+ const images = this.parseImages();
233
+ const showThumbnails = this.getAttribute('show-thumbnails') !== 'false' && images.length > 1;
234
+ thumbnailsWrap.hidden = !showThumbnails;
235
+ if (!showThumbnails) {
236
+ thumbnailsContainer.replaceChildren();
237
+ this.thumbnailSignature = '';
238
+ return;
239
+ }
240
+ const signature = images.map((image) => image.thumbnail || image.src).join('|');
241
+ // 이미지 목록이 그대로면 재생성하지 않고 활성 상태만 갱신 → 썸네일 재로딩/깜빡임 방지
242
+ if (signature === this.thumbnailSignature && thumbnailsContainer.childElementCount === images.length) {
243
+ Array.from(thumbnailsContainer.children).forEach((child, index) => {
244
+ const button = child;
245
+ const active = index === this.currentIndex;
246
+ button.classList.toggle('designbase-wc-lightbox__thumbnail--active', active);
247
+ button.setAttribute('aria-current', active ? 'true' : 'false');
248
+ });
249
+ return;
250
+ }
251
+ this.thumbnailSignature = signature;
252
+ thumbnailsContainer.replaceChildren();
253
+ images.forEach((image, index) => {
254
+ const button = document.createElement('button');
255
+ button.type = 'button';
256
+ button.className = [
257
+ 'designbase-wc-lightbox__thumbnail',
258
+ index === this.currentIndex && 'designbase-wc-lightbox__thumbnail--active',
259
+ ]
260
+ .filter(Boolean)
261
+ .join(' ');
262
+ button.title = image.title || `이미지 ${index + 1}`;
263
+ button.setAttribute('aria-label', image.alt || image.title || `이미지 ${index + 1}`);
264
+ button.setAttribute('aria-current', index === this.currentIndex ? 'true' : 'false');
265
+ const thumb = document.createElement('img');
266
+ thumb.className = 'designbase-wc-lightbox__thumbnail-image';
267
+ thumb.src = image.thumbnail || image.src;
268
+ thumb.alt = '';
269
+ thumb.draggable = false;
270
+ thumb.loading = 'lazy';
271
+ thumb.decoding = 'async';
272
+ button.append(thumb);
273
+ button.addEventListener('click', () => this.goTo(index));
274
+ thumbnailsContainer.append(button);
275
+ });
276
+ }
277
+ loadCurrentImage() {
278
+ if (!this.imageEl)
279
+ return;
280
+ const image = this.getCurrentImage();
281
+ if (!image?.src) {
282
+ this.imageEl.removeAttribute('src');
283
+ this.resetImageState();
284
+ this.syncImageLayers();
285
+ return;
286
+ }
287
+ if (this.boundSrc !== image.src) {
288
+ this.boundSrc = image.src;
289
+ this.resetImageState();
290
+ this.imageEl.src = image.src;
291
+ this.imageEl.alt = image.alt || image.title || `이미지 ${this.currentIndex + 1}`;
292
+ this.syncImageLayers();
293
+ if (this.imageEl.complete && this.imageEl.naturalWidth > 0) {
294
+ this.handleImageLoad();
295
+ }
296
+ }
297
+ }
298
+ refreshView() {
299
+ if (!this.portalEl)
300
+ return;
301
+ const image = this.getCurrentImage();
302
+ const images = this.parseImages();
303
+ const title = this.portalEl.querySelector('.designbase-wc-lightbox__title-text');
304
+ const descriptionText = this.portalEl.querySelector('.designbase-wc-lightbox__description-text');
305
+ const description = this.portalEl.querySelector('.designbase-wc-lightbox__description');
306
+ if (title) {
307
+ title.textContent = image?.title || '';
308
+ title.hidden = !image?.title;
309
+ }
310
+ if (this.counterBadge) {
311
+ const showCounter = this.getAttribute('show-counter') !== 'false';
312
+ const text = showCounter && images.length > 1 ? `${this.currentIndex + 1} / ${images.length}` : '';
313
+ this.counterBadge.textContent = text;
314
+ this.counterBadge.hidden = !text;
315
+ }
316
+ if (description && descriptionText) {
317
+ descriptionText.textContent = image?.description || '';
318
+ description.hidden = !image?.description;
319
+ }
320
+ const showNav = this.getAttribute('show-navigation-buttons') !== 'false' && images.length > 1;
321
+ if (this.prevNav)
322
+ this.prevNav.hidden = !showNav;
323
+ if (this.nextNav)
324
+ this.nextNav.hidden = !showNav;
325
+ this.loadCurrentImage();
326
+ this.updateThumbnails();
327
+ }
328
+ mount() {
329
+ if (!this.portalEl) {
330
+ this.portalEl = this.buildPortal();
331
+ }
332
+ if (!this.portalEl.isConnected) {
333
+ document.body.append(this.portalEl);
334
+ }
335
+ document.body.style.overflow = 'hidden';
336
+ if (!this.keydownHandler) {
337
+ this.keydownHandler = (event) => {
338
+ if (!this.open || this.getAttribute('enable-keyboard') === 'false')
339
+ return;
340
+ if (event.key === 'Escape' && this.getAttribute('close-on-escape') !== 'false') {
341
+ event.preventDefault();
342
+ this.close();
343
+ }
344
+ if (event.key === 'ArrowLeft')
345
+ this.goTo(this.currentIndex - 1);
346
+ if (event.key === 'ArrowRight')
347
+ this.goTo(this.currentIndex + 1);
348
+ };
349
+ document.addEventListener('keydown', this.keydownHandler);
350
+ }
351
+ this.currentIndex = Number(this.getAttribute('current-index') || 0);
352
+ this.refreshView();
353
+ }
354
+ unmount() {
355
+ this.portalEl?.remove();
356
+ document.body.style.overflow = '';
357
+ if (this.keydownHandler) {
358
+ document.removeEventListener('keydown', this.keydownHandler);
359
+ this.keydownHandler = null;
360
+ }
361
+ }
362
+ syncOpenState() {
363
+ if (this.open)
364
+ this.mount();
365
+ else
366
+ this.unmount();
367
+ }
368
+ }
369
+ if (!customElements.get('db-lightbox'))
370
+ customElements.define('db-lightbox', DbLightbox);
371
+
372
+ export { DbLightbox };