@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.
- package/dist/chunks/lottie-e273b936.js +17032 -0
- package/dist/esm/components/animation-background/canvas-controller.js +121 -1
- package/dist/esm/components/animation-background/controls.js +180 -1
- package/dist/esm/components/animation-background/graphite-controller.js +196 -1
- package/dist/esm/components/animation-background/graphite-presets.js +42 -1
- package/dist/esm/components/animation-background/graphite-shader.js +111 -1
- package/dist/esm/components/animation-background/layers.js +369 -1
- package/dist/esm/components/animation-background/lumina-presets.js +53 -1
- package/dist/esm/components/animation-background/lumina-shaders.js +181 -1
- package/dist/esm/components/animation-background/lumina-utils.js +60 -1
- package/dist/esm/components/animation-background/particle-defaults.js +36 -1
- package/dist/esm/components/animation-background/renderers.js +167 -1
- package/dist/esm/components/animation-background/shader-controller.js +154 -1
- package/dist/esm/components/color-picker-utils.js +134 -1
- package/dist/esm/components/date-picker-utils.js +140 -1
- package/dist/esm/components/db-accordion.js +304 -1
- package/dist/esm/components/db-ad-banner.js +455 -1
- package/dist/esm/components/db-alert.js +149 -1
- package/dist/esm/components/db-animation-background.js +486 -1
- package/dist/esm/components/db-animation-text.js +601 -1
- package/dist/esm/components/db-app-badge.js +88 -1
- package/dist/esm/components/db-audio-player.js +752 -1
- package/dist/esm/components/db-avatar.js +188 -1
- package/dist/esm/components/db-backdrop.js +139 -1
- package/dist/esm/components/db-badge.js +91 -1
- package/dist/esm/components/db-banner.js +188 -1
- package/dist/esm/components/db-bottom-navigation.js +146 -1
- package/dist/esm/components/db-bottom-sheet.js +481 -1
- package/dist/esm/components/db-breadcrumbs.js +329 -1
- package/dist/esm/components/db-button.js +316 -1
- package/dist/esm/components/db-calendar.js +675 -1
- package/dist/esm/components/db-card.js +265 -1
- package/dist/esm/components/db-carousel.js +264 -1
- package/dist/esm/components/db-checkbox.js +202 -1
- package/dist/esm/components/db-chip.js +104 -1
- package/dist/esm/components/db-code-block.js +304 -1
- package/dist/esm/components/db-color-picker.js +746 -1
- package/dist/esm/components/db-confirm.js +191 -1
- package/dist/esm/components/db-container.js +39 -1
- package/dist/esm/components/db-context-menu.js +265 -1
- package/dist/esm/components/db-countdown.js +146 -1
- package/dist/esm/components/db-cursor-follower.js +173 -1
- package/dist/esm/components/db-date-picker.js +837 -1
- package/dist/esm/components/db-divider.js +66 -1
- package/dist/esm/components/db-drawer.js +245 -1
- package/dist/esm/components/db-dropdown.js +493 -1
- package/dist/esm/components/db-dropzone.js +266 -1
- package/dist/esm/components/db-empty-state.js +97 -1
- package/dist/esm/components/db-file-uploader.js +256 -1
- package/dist/esm/components/db-floating-action-button.js +139 -1
- package/dist/esm/components/db-footer.js +385 -1
- package/dist/esm/components/db-form.js +566 -1
- package/dist/esm/components/db-gantt.js +882 -1
- package/dist/esm/components/db-gradient.js +133 -1
- package/dist/esm/components/db-grid-background.js +909 -1
- package/dist/esm/components/db-grid.js +73 -1
- package/dist/esm/components/db-icons.js +82 -1
- package/dist/esm/components/db-image-list.js +214 -1
- package/dist/esm/components/db-image-placeholder.js +96 -1
- package/dist/esm/components/db-image.js +289 -1
- package/dist/esm/components/db-indicator.js +517 -1
- package/dist/esm/components/db-input.js +420 -1
- package/dist/esm/components/db-kanban.js +538 -1
- package/dist/esm/components/db-label.js +66 -1
- package/dist/esm/components/db-lightbox.js +372 -1
- package/dist/esm/components/db-list.js +340 -1
- package/dist/esm/components/db-logo-svg.js +72 -1
- package/dist/esm/components/db-logo.js +106 -1
- package/dist/esm/components/db-lottie.js +109 -1
- package/dist/esm/components/db-markdown-editor.js +458 -1
- package/dist/esm/components/db-marquee.js +402 -1
- package/dist/esm/components/db-masonry.js +94 -1
- package/dist/esm/components/db-menu-item.js +211 -1
- package/dist/esm/components/db-modal.js +522 -1
- package/dist/esm/components/db-navbar.js +680 -1
- package/dist/esm/components/db-onboarding-modal.js +322 -1
- package/dist/esm/components/db-page-header.js +312 -1
- package/dist/esm/components/db-pagination.js +271 -1
- package/dist/esm/components/db-popover.js +580 -1
- package/dist/esm/components/db-progress-step.js +166 -1
- package/dist/esm/components/db-progress.js +171 -1
- package/dist/esm/components/db-progressbar.js +72 -1
- package/dist/esm/components/db-radio.js +172 -1
- package/dist/esm/components/db-random-gradient.js +121 -1
- package/dist/esm/components/db-range-slider.js +811 -1
- package/dist/esm/components/db-rating.js +325 -1
- package/dist/esm/components/db-reorder.js +286 -1
- package/dist/esm/components/db-resizable-panels.js +282 -1
- package/dist/esm/components/db-scroll-area.js +126 -1
- package/dist/esm/components/db-search-bar.js +668 -1
- package/dist/esm/components/db-section-app-download.js +101 -1
- package/dist/esm/components/db-section-contact.js +102 -1
- package/dist/esm/components/db-section-cta.js +150 -1
- package/dist/esm/components/db-section-faq.js +120 -1
- package/dist/esm/components/db-section-feature-grid.js +137 -1
- package/dist/esm/components/db-section-feature.js +179 -1
- package/dist/esm/components/db-section-hero.js +243 -1
- package/dist/esm/components/db-section-logo-cloud.js +138 -1
- package/dist/esm/components/db-section-pricing.js +166 -1
- package/dist/esm/components/db-section-stats.js +129 -1
- package/dist/esm/components/db-section-testimonials.js +252 -1
- package/dist/esm/components/db-section.js +385 -1
- package/dist/esm/components/db-segment-control.js +231 -1
- package/dist/esm/components/db-select.js +571 -1
- package/dist/esm/components/db-share-icons.js +40 -1
- package/dist/esm/components/db-share.js +489 -1
- package/dist/esm/components/db-sidebar.js +1068 -1
- package/dist/esm/components/db-skeleton.js +94 -1
- package/dist/esm/components/db-spinner.js +102 -1
- package/dist/esm/components/db-split-view.js +297 -1
- package/dist/esm/components/db-stack.js +46 -1
- package/dist/esm/components/db-stat.js +218 -1
- package/dist/esm/components/db-stepper.js +398 -1
- package/dist/esm/components/db-table.js +412 -1
- package/dist/esm/components/db-tabs.js +335 -1
- package/dist/esm/components/db-testimonial.js +162 -1
- package/dist/esm/components/db-textarea.js +233 -1
- package/dist/esm/components/db-time-picker.js +523 -1
- package/dist/esm/components/db-timeline.js +174 -1
- package/dist/esm/components/db-toast.js +158 -1
- package/dist/esm/components/db-toggle.js +162 -1
- package/dist/esm/components/db-toolbar.js +94 -1
- package/dist/esm/components/db-tooltip.js +440 -1
- package/dist/esm/components/db-top-banner.js +121 -1
- package/dist/esm/components/db-tutorial.js +324 -1
- package/dist/esm/components/db-video-player.js +503 -1
- package/dist/esm/components/db-youtube-player.js +194 -1
- package/dist/esm/components/highlight-code.js +65 -1
- package/dist/esm/components/input-validation.js +50 -1
- package/dist/esm/components/marketing-block-host-utils.js +9 -1
- package/dist/esm/components/number-scrub.js +117 -1
- package/dist/esm/components/random-gradient-palettes.js +67 -1
- package/dist/esm/components/section-block-header-utils.js +48 -1
- package/dist/esm/helpers/confirm.js +52 -1
- package/dist/esm/helpers/toast.js +73 -1
- package/dist/esm/index.js +111 -1
- package/dist/esm/node_modules/prismjs/components/prism-bash.js +235 -1
- package/dist/esm/node_modules/prismjs/components/prism-clike.js +31 -1
- package/dist/esm/node_modules/prismjs/components/prism-css.js +64 -1
- package/dist/esm/node_modules/prismjs/components/prism-javascript.js +172 -1
- package/dist/esm/node_modules/prismjs/components/prism-json.js +27 -1
- package/dist/esm/node_modules/prismjs/components/prism-jsx.js +143 -1
- package/dist/esm/node_modules/prismjs/components/prism-markup.js +186 -1
- package/dist/esm/node_modules/prismjs/components/prism-scss.js +81 -1
- package/dist/esm/node_modules/prismjs/components/prism-tsx.js +15 -1
- package/dist/esm/node_modules/prismjs/components/prism-typescript.js +60 -1
- package/dist/index.cjs +55414 -1
- package/dist/index.css +1 -1
- package/dist/index.esm.js +38284 -1
- package/dist/react/chunks/lottie-72a4c6d4.js +17032 -0
- package/dist/react/index.cjs +56503 -1
- package/dist/react/index.esm.js +39373 -1
- package/package.json +1 -1
- package/dist/chunks/lottie-2637aa0f.js +0 -1
- package/dist/react/chunks/lottie-14e7addb.js +0 -1
|
@@ -1 +1,372 @@
|
|
|
1
|
-
import{createDbIcon
|
|
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 };
|