@designbasekorea/ui-wc 0.5.6 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/lottie-35a9b0f5.js +1 -0
- package/dist/esm/components/animation-background/canvas-controller.js +1 -121
- package/dist/esm/components/animation-background/controls.js +1 -180
- package/dist/esm/components/animation-background/graphite-controller.js +1 -196
- package/dist/esm/components/animation-background/graphite-presets.js +1 -42
- package/dist/esm/components/animation-background/graphite-shader.js +1 -111
- package/dist/esm/components/animation-background/layers.js +1 -369
- package/dist/esm/components/animation-background/lumina-presets.js +1 -53
- package/dist/esm/components/animation-background/lumina-shaders.js +1 -181
- package/dist/esm/components/animation-background/lumina-utils.js +1 -60
- package/dist/esm/components/animation-background/particle-defaults.js +1 -36
- package/dist/esm/components/animation-background/renderers.js +1 -167
- package/dist/esm/components/animation-background/shader-controller.js +1 -154
- package/dist/esm/components/color-picker-utils.js +1 -134
- package/dist/esm/components/date-picker-utils.js +1 -140
- package/dist/esm/components/db-accordion.js +1 -304
- package/dist/esm/components/db-ad-banner.js +1 -455
- package/dist/esm/components/db-ai-chat-list.d.ts +43 -0
- package/dist/esm/components/db-ai-chat-list.js +1 -0
- package/dist/esm/components/db-ai-chat.d.ts +159 -0
- package/dist/esm/components/db-ai-chat.js +1 -0
- package/dist/esm/components/db-alert.js +1 -149
- package/dist/esm/components/db-animation-background.js +1 -486
- package/dist/esm/components/db-animation-text.js +1 -601
- package/dist/esm/components/db-app-badge.js +1 -88
- package/dist/esm/components/db-audio-player.js +1 -752
- package/dist/esm/components/db-avatar.js +1 -188
- package/dist/esm/components/db-backdrop.js +1 -139
- package/dist/esm/components/db-badge.js +1 -91
- package/dist/esm/components/db-banner.js +1 -188
- package/dist/esm/components/db-bottom-navigation.js +1 -146
- package/dist/esm/components/db-bottom-sheet.js +1 -481
- package/dist/esm/components/db-breadcrumbs.js +1 -329
- package/dist/esm/components/db-button.js +1 -316
- package/dist/esm/components/db-calendar.js +1 -675
- package/dist/esm/components/db-card.js +1 -265
- package/dist/esm/components/db-carousel.js +1 -264
- package/dist/esm/components/db-chat-composer.d.ts +134 -0
- package/dist/esm/components/db-chat-composer.js +1 -0
- package/dist/esm/components/db-chat-list.d.ts +47 -0
- package/dist/esm/components/db-chat-list.js +1 -0
- package/dist/esm/components/db-chat-message.d.ts +39 -0
- package/dist/esm/components/db-chat-message.js +1 -0
- package/dist/esm/components/db-chat-orb.d.ts +99 -0
- package/dist/esm/components/db-chat-orb.js +1 -0
- package/dist/esm/components/db-chat-room.d.ts +71 -0
- package/dist/esm/components/db-chat-room.js +1 -0
- package/dist/esm/components/db-chat-suggestions.d.ts +44 -0
- package/dist/esm/components/db-chat-suggestions.js +1 -0
- package/dist/esm/components/db-chat-typing.d.ts +22 -0
- package/dist/esm/components/db-chat-typing.js +1 -0
- package/dist/esm/components/db-chat-welcome.d.ts +32 -0
- package/dist/esm/components/db-chat-welcome.js +1 -0
- package/dist/esm/components/db-chat-widget.d.ts +146 -0
- package/dist/esm/components/db-chat-widget.js +1 -0
- package/dist/esm/components/db-checkbox.js +1 -202
- package/dist/esm/components/db-chip.js +1 -104
- package/dist/esm/components/db-code-block.js +1 -304
- package/dist/esm/components/db-color-picker.js +1 -746
- package/dist/esm/components/db-confirm.js +1 -191
- package/dist/esm/components/db-container.js +1 -39
- package/dist/esm/components/db-context-menu.js +1 -265
- package/dist/esm/components/db-countdown.js +1 -146
- package/dist/esm/components/db-cursor-follower.js +1 -173
- package/dist/esm/components/db-date-picker.js +1 -837
- package/dist/esm/components/db-divider.js +1 -66
- package/dist/esm/components/db-download-progress.d.ts +89 -0
- package/dist/esm/components/db-download-progress.js +1 -0
- package/dist/esm/components/db-drawer.js +1 -245
- package/dist/esm/components/db-dropdown.js +1 -493
- package/dist/esm/components/db-dropzone.js +1 -266
- package/dist/esm/components/db-email-verify.d.ts +64 -0
- package/dist/esm/components/db-email-verify.js +1 -0
- package/dist/esm/components/db-empty-state.js +1 -97
- package/dist/esm/components/db-file-uploader.js +1 -256
- package/dist/esm/components/db-floating-action-button.js +1 -139
- package/dist/esm/components/db-footer.js +1 -385
- package/dist/esm/components/db-form.js +1 -566
- package/dist/esm/components/db-gantt.js +1 -882
- package/dist/esm/components/db-gradient.js +1 -133
- package/dist/esm/components/db-grid-background.js +1 -909
- package/dist/esm/components/db-grid.js +1 -73
- package/dist/esm/components/db-icons.d.ts +3 -0
- package/dist/esm/components/db-icons.js +1 -82
- package/dist/esm/components/db-image-list.js +1 -214
- package/dist/esm/components/db-image-placeholder.js +1 -96
- package/dist/esm/components/db-image.js +1 -289
- package/dist/esm/components/db-indicator.js +1 -517
- package/dist/esm/components/db-input.js +1 -420
- package/dist/esm/components/db-kanban.js +1 -538
- package/dist/esm/components/db-label.js +1 -66
- package/dist/esm/components/db-lightbox.js +1 -372
- package/dist/esm/components/db-list.js +1 -340
- package/dist/esm/components/db-logo-svg.js +1 -72
- package/dist/esm/components/db-logo.js +1 -106
- package/dist/esm/components/db-lottie.js +1 -109
- package/dist/esm/components/db-markdown-editor.js +1 -458
- package/dist/esm/components/db-marquee.js +1 -402
- package/dist/esm/components/db-masonry.js +1 -94
- package/dist/esm/components/db-menu-item.js +1 -211
- package/dist/esm/components/db-modal.js +1 -522
- package/dist/esm/components/db-navbar.js +1 -680
- package/dist/esm/components/db-onboarding-modal.js +1 -322
- package/dist/esm/components/db-otp-input.d.ts +53 -0
- package/dist/esm/components/db-otp-input.js +1 -0
- package/dist/esm/components/db-page-header.js +1 -312
- package/dist/esm/components/db-pagination.js +1 -271
- package/dist/esm/components/db-phone-verify.d.ts +63 -0
- package/dist/esm/components/db-phone-verify.js +1 -0
- package/dist/esm/components/db-popover.js +1 -580
- package/dist/esm/components/db-progress-step.js +1 -166
- package/dist/esm/components/db-progress.js +1 -171
- package/dist/esm/components/db-progressbar.js +1 -72
- package/dist/esm/components/db-radio.js +1 -172
- package/dist/esm/components/db-random-gradient.js +1 -121
- package/dist/esm/components/db-range-slider.js +1 -811
- package/dist/esm/components/db-rating.js +1 -325
- package/dist/esm/components/db-reorder.js +1 -286
- package/dist/esm/components/db-resizable-panels.js +1 -282
- package/dist/esm/components/db-scroll-area.js +1 -126
- package/dist/esm/components/db-search-bar.js +1 -668
- package/dist/esm/components/db-section-app-download.js +1 -101
- package/dist/esm/components/db-section-contact.js +1 -102
- package/dist/esm/components/db-section-cta.js +1 -150
- package/dist/esm/components/db-section-faq.js +1 -120
- package/dist/esm/components/db-section-feature-grid.js +1 -137
- package/dist/esm/components/db-section-feature.js +1 -179
- package/dist/esm/components/db-section-hero.js +1 -243
- package/dist/esm/components/db-section-logo-cloud.js +1 -138
- package/dist/esm/components/db-section-pricing.js +1 -166
- package/dist/esm/components/db-section-stats.js +1 -129
- package/dist/esm/components/db-section-testimonials.js +1 -252
- package/dist/esm/components/db-section.js +1 -385
- package/dist/esm/components/db-segment-control.js +1 -231
- package/dist/esm/components/db-select.js +1 -571
- package/dist/esm/components/db-share-icons.js +1 -40
- package/dist/esm/components/db-share.js +1 -489
- package/dist/esm/components/db-sidebar.d.ts +20 -0
- package/dist/esm/components/db-sidebar.js +1 -1068
- package/dist/esm/components/db-skeleton.js +1 -94
- package/dist/esm/components/db-spinner.js +1 -102
- package/dist/esm/components/db-split-view.js +1 -297
- package/dist/esm/components/db-stack.js +1 -46
- package/dist/esm/components/db-stat.js +1 -218
- package/dist/esm/components/db-stepper.js +1 -398
- package/dist/esm/components/db-table.js +1 -412
- package/dist/esm/components/db-tabs.js +1 -335
- package/dist/esm/components/db-testimonial.d.ts +2 -0
- package/dist/esm/components/db-testimonial.js +1 -162
- package/dist/esm/components/db-textarea.js +1 -233
- package/dist/esm/components/db-time-picker.js +1 -523
- package/dist/esm/components/db-timeline.js +1 -174
- package/dist/esm/components/db-toast.js +1 -158
- package/dist/esm/components/db-toggle.js +1 -162
- package/dist/esm/components/db-toolbar.js +1 -94
- package/dist/esm/components/db-tooltip.js +1 -440
- package/dist/esm/components/db-top-banner.js +1 -121
- package/dist/esm/components/db-tutorial.js +1 -324
- package/dist/esm/components/db-two-factor.d.ts +71 -0
- package/dist/esm/components/db-two-factor.js +1 -0
- package/dist/esm/components/db-video-player.js +1 -503
- package/dist/esm/components/db-youtube-player.js +1 -194
- package/dist/esm/components/highlight-code.js +1 -65
- package/dist/esm/components/input-validation.js +1 -50
- package/dist/esm/components/marketing-block-host-utils.js +1 -9
- package/dist/esm/components/number-scrub.js +1 -117
- package/dist/esm/components/random-gradient-palettes.js +1 -67
- package/dist/esm/components/section-block-header-utils.js +1 -48
- package/dist/esm/helpers/confirm.js +1 -52
- package/dist/esm/helpers/toast.js +1 -73
- package/dist/esm/index.d.ts +16 -0
- package/dist/esm/index.js +1 -111
- package/dist/esm/node_modules/prismjs/components/prism-bash.js +1 -235
- package/dist/esm/node_modules/prismjs/components/prism-clike.js +1 -31
- package/dist/esm/node_modules/prismjs/components/prism-css.js +1 -64
- package/dist/esm/node_modules/prismjs/components/prism-javascript.js +1 -172
- package/dist/esm/node_modules/prismjs/components/prism-json.js +1 -27
- package/dist/esm/node_modules/prismjs/components/prism-jsx.js +1 -143
- package/dist/esm/node_modules/prismjs/components/prism-markup.js +1 -186
- package/dist/esm/node_modules/prismjs/components/prism-scss.js +1 -81
- package/dist/esm/node_modules/prismjs/components/prism-tsx.js +1 -15
- package/dist/esm/node_modules/prismjs/components/prism-typescript.js +1 -60
- package/dist/index.cjs +1 -55414
- package/dist/index.css +1 -1
- package/dist/index.d.ts +1125 -2
- package/dist/index.esm.js +1 -38284
- package/dist/react/chunks/lottie-14e7addb.js +1 -0
- package/dist/react/index.cjs +1 -56503
- package/dist/react/index.d.ts +1637 -21
- package/dist/react/index.esm.js +1 -39373
- package/package.json +2 -2
- package/dist/chunks/lottie-e273b936.js +0 -17032
- package/dist/react/chunks/lottie-72a4c6d4.js +0 -17032
|
@@ -1,601 +1 @@
|
|
|
1
|
-
const CLASS = 'designbase-wc-animation-text';
|
|
2
|
-
class DbAnimationText extends HTMLElement {
|
|
3
|
-
constructor() {
|
|
4
|
-
super(...arguments);
|
|
5
|
-
this.timers = [];
|
|
6
|
-
this.displayText = '';
|
|
7
|
-
this.isVisible = false;
|
|
8
|
-
this.isAnimating = false;
|
|
9
|
-
this.wordEls = [];
|
|
10
|
-
this.rotateToken = 0;
|
|
11
|
-
}
|
|
12
|
-
static get observedAttributes() {
|
|
13
|
-
return [
|
|
14
|
-
'text',
|
|
15
|
-
'texts',
|
|
16
|
-
'interval',
|
|
17
|
-
'trigger',
|
|
18
|
-
'type',
|
|
19
|
-
'speed',
|
|
20
|
-
'repeat',
|
|
21
|
-
'delay',
|
|
22
|
-
'direction',
|
|
23
|
-
'size',
|
|
24
|
-
'color',
|
|
25
|
-
'custom-color',
|
|
26
|
-
'weight',
|
|
27
|
-
'align',
|
|
28
|
-
'gradient-colors',
|
|
29
|
-
'wave-colors',
|
|
30
|
-
'glow-color',
|
|
31
|
-
'clickable',
|
|
32
|
-
'disabled',
|
|
33
|
-
];
|
|
34
|
-
}
|
|
35
|
-
connectedCallback() {
|
|
36
|
-
this.style.display = 'inline-block';
|
|
37
|
-
this.ensureStructure();
|
|
38
|
-
this.syncFromAttributes();
|
|
39
|
-
this.setupTrigger();
|
|
40
|
-
}
|
|
41
|
-
disconnectedCallback() {
|
|
42
|
-
this.clearTimers();
|
|
43
|
-
this.observer?.disconnect();
|
|
44
|
-
this.teardownScrollFill();
|
|
45
|
-
this.rotateObserver?.disconnect();
|
|
46
|
-
}
|
|
47
|
-
attributeChangedCallback() {
|
|
48
|
-
if (!this.isConnected)
|
|
49
|
-
return;
|
|
50
|
-
this.syncFromAttributes();
|
|
51
|
-
this.setupTrigger();
|
|
52
|
-
}
|
|
53
|
-
getText() {
|
|
54
|
-
return this.getAttribute('text') || this.textContent?.trim() || '';
|
|
55
|
-
}
|
|
56
|
-
getRotateTexts() {
|
|
57
|
-
const raw = this.getAttribute('texts');
|
|
58
|
-
if (raw) {
|
|
59
|
-
const list = raw
|
|
60
|
-
.split(',')
|
|
61
|
-
.map((s) => s.trim())
|
|
62
|
-
.filter(Boolean);
|
|
63
|
-
if (list.length)
|
|
64
|
-
return list;
|
|
65
|
-
}
|
|
66
|
-
const single = this.getText();
|
|
67
|
-
return single ? [single] : [];
|
|
68
|
-
}
|
|
69
|
-
getLongestText() {
|
|
70
|
-
return this.getRotateTexts().reduce((a, b) => (b.length > a.length ? b : a), '');
|
|
71
|
-
}
|
|
72
|
-
getType() {
|
|
73
|
-
const value = this.getAttribute('type') || 'fade';
|
|
74
|
-
const allowed = [
|
|
75
|
-
'typing',
|
|
76
|
-
'fade',
|
|
77
|
-
'slide',
|
|
78
|
-
'bounce',
|
|
79
|
-
'shake',
|
|
80
|
-
'glow',
|
|
81
|
-
'gradient',
|
|
82
|
-
'wave',
|
|
83
|
-
'flip',
|
|
84
|
-
'scale',
|
|
85
|
-
'decode',
|
|
86
|
-
'roll',
|
|
87
|
-
'reveal',
|
|
88
|
-
'scroll-fill',
|
|
89
|
-
'text-rotate',
|
|
90
|
-
];
|
|
91
|
-
return allowed.includes(value) ? value : 'fade';
|
|
92
|
-
}
|
|
93
|
-
getTrigger() {
|
|
94
|
-
const value = this.getAttribute('trigger') || 'mount';
|
|
95
|
-
return ['mount', 'hover', 'click', 'in-view'].includes(value) ? value : 'mount';
|
|
96
|
-
}
|
|
97
|
-
ensureStructure() {
|
|
98
|
-
if (this.ghostEl)
|
|
99
|
-
return;
|
|
100
|
-
this.ghostEl = document.createElement('span');
|
|
101
|
-
this.ghostEl.setAttribute('aria-hidden', 'true');
|
|
102
|
-
this.ghostEl.style.visibility = 'hidden';
|
|
103
|
-
this.ghostEl.style.pointerEvents = 'none';
|
|
104
|
-
this.ghostEl.style.userSelect = 'none';
|
|
105
|
-
this.layerEl = document.createElement('span');
|
|
106
|
-
this.layerEl.style.position = 'absolute';
|
|
107
|
-
this.layerEl.style.top = '0';
|
|
108
|
-
this.layerEl.style.left = '0';
|
|
109
|
-
this.append(this.ghostEl, this.layerEl);
|
|
110
|
-
this.addEventListener('mouseenter', () => {
|
|
111
|
-
if (this.getTrigger() !== 'hover' || this.hasAttribute('disabled'))
|
|
112
|
-
return;
|
|
113
|
-
// roll 은 정적 렌더 + CSS :hover 로만 동작한다. 재렌더 시 transition 이 리셋된다.
|
|
114
|
-
if (this.getType() === 'roll')
|
|
115
|
-
return;
|
|
116
|
-
this.isVisible = true;
|
|
117
|
-
this.startAnimation();
|
|
118
|
-
this.syncClasses();
|
|
119
|
-
});
|
|
120
|
-
this.addEventListener('mouseleave', () => {
|
|
121
|
-
if (this.getTrigger() !== 'hover')
|
|
122
|
-
return;
|
|
123
|
-
if (this.getType() === 'roll')
|
|
124
|
-
return;
|
|
125
|
-
this.isVisible = false;
|
|
126
|
-
this.isAnimating = false;
|
|
127
|
-
this.clearTimers();
|
|
128
|
-
const type = this.getType();
|
|
129
|
-
if (type === 'typing' || type === 'decode') {
|
|
130
|
-
this.displayText = this.getText();
|
|
131
|
-
}
|
|
132
|
-
this.renderLayer();
|
|
133
|
-
this.syncClasses();
|
|
134
|
-
});
|
|
135
|
-
this.addEventListener('click', () => {
|
|
136
|
-
if (this.hasAttribute('disabled'))
|
|
137
|
-
return;
|
|
138
|
-
if (this.getTrigger() === 'click') {
|
|
139
|
-
this.isVisible = !this.isVisible;
|
|
140
|
-
if (this.isVisible)
|
|
141
|
-
this.startAnimation();
|
|
142
|
-
else {
|
|
143
|
-
this.isAnimating = false;
|
|
144
|
-
this.clearTimers();
|
|
145
|
-
const type = this.getType();
|
|
146
|
-
if (type === 'typing' || type === 'decode')
|
|
147
|
-
this.displayText = this.getText();
|
|
148
|
-
this.renderLayer();
|
|
149
|
-
}
|
|
150
|
-
this.syncClasses();
|
|
151
|
-
}
|
|
152
|
-
if (this.hasAttribute('clickable')) {
|
|
153
|
-
this.dispatchEvent(new CustomEvent('db-click', { bubbles: true, composed: true }));
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
clearTimers() {
|
|
158
|
-
this.timers.forEach((id) => window.clearInterval(id));
|
|
159
|
-
this.timers.forEach((id) => window.clearTimeout(id));
|
|
160
|
-
this.timers = [];
|
|
161
|
-
}
|
|
162
|
-
syncFromAttributes() {
|
|
163
|
-
const text = this.getText();
|
|
164
|
-
const type = this.getType();
|
|
165
|
-
const trigger = this.getTrigger();
|
|
166
|
-
const speed = Number(this.getAttribute('speed') || 1000);
|
|
167
|
-
const repeat = Number(this.getAttribute('repeat') || 1);
|
|
168
|
-
const customColor = this.getAttribute('custom-color');
|
|
169
|
-
const gradientColors = (this.getAttribute('gradient-colors') || '#667eea,#764ba2').split(',');
|
|
170
|
-
const waveColors = (this.getAttribute('wave-colors') || '#ff6b6b,#4ecdc4,#45b7d1,#96ceb4,#feca57').split(',');
|
|
171
|
-
const glowColor = this.getAttribute('glow-color') || '#667eea';
|
|
172
|
-
this.className = [
|
|
173
|
-
CLASS,
|
|
174
|
-
type !== 'typing' && `${CLASS}--${type}`,
|
|
175
|
-
`${CLASS}--${this.getAttribute('size') || 'm'}`,
|
|
176
|
-
`${CLASS}--${this.getAttribute('color') || 'primary'}`,
|
|
177
|
-
`${CLASS}--${this.getAttribute('weight') || 'normal'}`,
|
|
178
|
-
`${CLASS}--${this.getAttribute('align') || 'left'}`,
|
|
179
|
-
`${CLASS}--${this.getAttribute('direction') || 'left'}`,
|
|
180
|
-
this.isVisible && `${CLASS}--visible`,
|
|
181
|
-
this.isAnimating && `${CLASS}--animating`,
|
|
182
|
-
(this.hasAttribute('clickable') || trigger === 'click') && `${CLASS}--clickable`,
|
|
183
|
-
this.hasAttribute('disabled') && `${CLASS}--disabled`,
|
|
184
|
-
]
|
|
185
|
-
.filter(Boolean)
|
|
186
|
-
.join(' ');
|
|
187
|
-
this.style.setProperty('--db-animation-speed', `${Number.isFinite(speed) ? speed : 1000}ms`);
|
|
188
|
-
this.style.setProperty('--db-animation-iteration-count', repeat === 0 ? 'infinite' : String(repeat));
|
|
189
|
-
if (customColor)
|
|
190
|
-
this.style.setProperty('--db-text-custom', customColor);
|
|
191
|
-
this.style.setProperty('--db-wave-colors', waveColors.join(', '));
|
|
192
|
-
this.style.setProperty('--db-glow-color', glowColor);
|
|
193
|
-
// 그라디언트 텍스트는 실제 텍스트가 들어있는 레이어(span)에 적용해야 한다.
|
|
194
|
-
// (host에 background-clip:text를 걸면 자식 레이어 텍스트는 투명하게만 보인다)
|
|
195
|
-
this.style.removeProperty('background');
|
|
196
|
-
this.style.removeProperty('background-size');
|
|
197
|
-
this.style.removeProperty('-webkit-background-clip');
|
|
198
|
-
this.style.removeProperty('-webkit-text-fill-color');
|
|
199
|
-
this.style.removeProperty('background-clip');
|
|
200
|
-
if (this.layerEl) {
|
|
201
|
-
if (type === 'gradient' && gradientColors.length >= 2) {
|
|
202
|
-
this.layerEl.style.backgroundImage = `linear-gradient(45deg, ${gradientColors.join(', ')})`;
|
|
203
|
-
}
|
|
204
|
-
else {
|
|
205
|
-
this.layerEl.style.removeProperty('background-image');
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
if ((type === 'typing' || type === 'decode') && trigger === 'mount' && !this.isAnimating) {
|
|
209
|
-
this.displayText = '';
|
|
210
|
-
}
|
|
211
|
-
else if (!this.isAnimating) {
|
|
212
|
-
this.displayText = text;
|
|
213
|
-
}
|
|
214
|
-
// typing/decode 는 글자 수가 변하고 roll 은 1줄 높이를 고정해야 하므로
|
|
215
|
-
// ghost 로 공간을 예약하고 layer 를 절대배치로 겹친다.
|
|
216
|
-
// 그 외 타입(fade·reveal·scroll-fill 등)은 일반 흐름으로 렌더해
|
|
217
|
-
// 문장 길이(줄바꿈)에 따라 호스트 높이가 자연스럽게 늘어나도록 한다.
|
|
218
|
-
const overlay = type === 'typing' || type === 'decode' || type === 'roll' || type === 'text-rotate';
|
|
219
|
-
const whiteSpace = type === 'roll' || type === 'text-rotate' ? 'nowrap' : overlay ? 'pre-wrap' : '';
|
|
220
|
-
if (this.ghostEl) {
|
|
221
|
-
if (overlay) {
|
|
222
|
-
this.ghostEl.textContent = type === 'text-rotate' ? this.getLongestText() : text;
|
|
223
|
-
this.ghostEl.style.display = 'inline-block';
|
|
224
|
-
this.ghostEl.style.whiteSpace = whiteSpace;
|
|
225
|
-
// 타이핑은 완료 시 텍스트가 폭을 꽉 채워 캐럿이 다음 줄로 밀리지 않도록 여유 확보
|
|
226
|
-
this.ghostEl.style.paddingRight = type === 'typing' ? '0.25em' : '';
|
|
227
|
-
}
|
|
228
|
-
else {
|
|
229
|
-
this.ghostEl.textContent = '';
|
|
230
|
-
this.ghostEl.style.display = 'none';
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
if (this.layerEl) {
|
|
234
|
-
this.layerEl.className = [
|
|
235
|
-
`${CLASS}__layer`,
|
|
236
|
-
type === 'typing' && `${CLASS}--typing`,
|
|
237
|
-
this.isAnimating && type === 'typing' && `${CLASS}--animating`,
|
|
238
|
-
]
|
|
239
|
-
.filter(Boolean)
|
|
240
|
-
.join(' ');
|
|
241
|
-
if (overlay) {
|
|
242
|
-
this.layerEl.style.position = 'absolute';
|
|
243
|
-
this.layerEl.style.top = '0';
|
|
244
|
-
this.layerEl.style.left = '0';
|
|
245
|
-
this.layerEl.style.width = '100%';
|
|
246
|
-
this.layerEl.style.height = '100%';
|
|
247
|
-
this.layerEl.style.whiteSpace = whiteSpace;
|
|
248
|
-
}
|
|
249
|
-
else {
|
|
250
|
-
this.layerEl.style.position = 'static';
|
|
251
|
-
this.layerEl.style.removeProperty('top');
|
|
252
|
-
this.layerEl.style.removeProperty('left');
|
|
253
|
-
this.layerEl.style.width = 'auto';
|
|
254
|
-
this.layerEl.style.height = 'auto';
|
|
255
|
-
this.layerEl.style.whiteSpace = '';
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
this.renderLayer();
|
|
259
|
-
}
|
|
260
|
-
syncClasses() {
|
|
261
|
-
this.classList.toggle(`${CLASS}--visible`, this.isVisible);
|
|
262
|
-
this.classList.toggle(`${CLASS}--animating`, this.isAnimating);
|
|
263
|
-
}
|
|
264
|
-
setupTrigger() {
|
|
265
|
-
this.clearTimers();
|
|
266
|
-
this.observer?.disconnect();
|
|
267
|
-
this.teardownScrollFill();
|
|
268
|
-
this.rotateObserver?.disconnect();
|
|
269
|
-
this.rotateObserver = undefined;
|
|
270
|
-
this.rotateToken++; // 대기 중이던 이전 rotate 예약 무효화
|
|
271
|
-
const trigger = this.getTrigger();
|
|
272
|
-
const delay = Number(this.getAttribute('delay') || 0);
|
|
273
|
-
// scroll-fill 은 스크롤 위치에 연동되므로 별도 핸들러로 처리한다.
|
|
274
|
-
if (this.getType() === 'scroll-fill') {
|
|
275
|
-
this.setupScrollFill();
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
// text-rotate 는 타이머로 자동 순환한다.
|
|
279
|
-
if (this.getType() === 'text-rotate') {
|
|
280
|
-
this.setupTextRotate();
|
|
281
|
-
return;
|
|
282
|
-
}
|
|
283
|
-
if (trigger === 'mount') {
|
|
284
|
-
const timer = window.setTimeout(() => {
|
|
285
|
-
this.isVisible = true;
|
|
286
|
-
this.syncClasses();
|
|
287
|
-
this.startAnimation();
|
|
288
|
-
}, delay);
|
|
289
|
-
this.timers.push(timer);
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
292
|
-
if (trigger === 'in-view') {
|
|
293
|
-
this.observer = new IntersectionObserver((entries) => {
|
|
294
|
-
if (entries[0]?.isIntersecting) {
|
|
295
|
-
window.setTimeout(() => {
|
|
296
|
-
this.isVisible = true;
|
|
297
|
-
this.syncClasses();
|
|
298
|
-
this.startAnimation();
|
|
299
|
-
}, delay);
|
|
300
|
-
this.observer?.disconnect();
|
|
301
|
-
}
|
|
302
|
-
});
|
|
303
|
-
this.observer.observe(this);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
setupTextRotate() {
|
|
307
|
-
const texts = this.getRotateTexts();
|
|
308
|
-
if (texts.length <= 1)
|
|
309
|
-
return; // 순환할 텍스트가 없으면 정적 표시
|
|
310
|
-
// 재설정마다 토큰을 올려, 폰트 로드 후 뒤늦게 실행되는 이전 예약을 무효화한다.
|
|
311
|
-
const token = ++this.rotateToken;
|
|
312
|
-
const start = () => {
|
|
313
|
-
if (token !== this.rotateToken || !this.isConnected || this.getType() !== 'text-rotate')
|
|
314
|
-
return;
|
|
315
|
-
const track = this.layerEl?.querySelector(`.${CLASS}__rotate-track`);
|
|
316
|
-
if (!track || !track.firstElementChild)
|
|
317
|
-
return;
|
|
318
|
-
const items = Array.from(track.children);
|
|
319
|
-
const duration = Number(this.getAttribute('speed') || 500);
|
|
320
|
-
const interval = Math.max(duration + 200, Number(this.getAttribute('interval') || 2000));
|
|
321
|
-
let index = 0;
|
|
322
|
-
// 줄 높이·폭은 폰트 로드 타이밍에 따라 달라지므로 매번 실측한다.
|
|
323
|
-
const stepOf = () => items[0].getBoundingClientRect().height;
|
|
324
|
-
const widthOf = (i) => items[i].getBoundingClientRect().width;
|
|
325
|
-
// 현재 index 위치로 트랙/호스트를 맞춘다. animate=false 면 즉시(트랜지션 없이) 스냅.
|
|
326
|
-
const apply = (animate) => {
|
|
327
|
-
const step = stepOf();
|
|
328
|
-
if (!step)
|
|
329
|
-
return;
|
|
330
|
-
const ease = 'cubic-bezier(0.22, 1, 0.36, 1)';
|
|
331
|
-
track.style.transition = animate ? `transform ${duration}ms ${ease}` : 'none';
|
|
332
|
-
track.style.transform = `translateY(-${index * step}px)`;
|
|
333
|
-
this.style.transition = animate ? `width ${duration}ms ${ease}` : 'none';
|
|
334
|
-
this.style.width = `${widthOf(index)}px`;
|
|
335
|
-
};
|
|
336
|
-
apply(false);
|
|
337
|
-
const advance = () => {
|
|
338
|
-
index += 1;
|
|
339
|
-
apply(true);
|
|
340
|
-
if (index === items.length - 1) {
|
|
341
|
-
// 마지막 복제본(=첫 항목) 위치 → 트랜지션 종료 후 순간 이동으로 원점 복귀
|
|
342
|
-
const reset = window.setTimeout(() => {
|
|
343
|
-
index = 0;
|
|
344
|
-
apply(false);
|
|
345
|
-
}, duration);
|
|
346
|
-
this.timers.push(reset);
|
|
347
|
-
}
|
|
348
|
-
};
|
|
349
|
-
const timer = window.setInterval(advance, interval);
|
|
350
|
-
this.timers.push(timer);
|
|
351
|
-
// 폰트 로드 등으로 항목 크기가 바뀌면(초기 폴백→웹폰트) 현재 위치를 다시 맞춰
|
|
352
|
-
// 세로 어긋남·가로 잘림을 보정한다. 최초 observe 콜백(초기 크기)은 건너뛴다.
|
|
353
|
-
this.rotateObserver?.disconnect();
|
|
354
|
-
let firstObserve = true;
|
|
355
|
-
const ro = new ResizeObserver(() => {
|
|
356
|
-
if (firstObserve) {
|
|
357
|
-
firstObserve = false;
|
|
358
|
-
return;
|
|
359
|
-
}
|
|
360
|
-
apply(false);
|
|
361
|
-
});
|
|
362
|
-
ro.observe(items[0]);
|
|
363
|
-
this.rotateObserver = ro;
|
|
364
|
-
};
|
|
365
|
-
// 웹폰트 로드 후 측정을 시도하되, ready 가 조기 resolve 되는 경우는 위 ResizeObserver 가 보정한다.
|
|
366
|
-
if (typeof document !== 'undefined' && document.fonts) {
|
|
367
|
-
document.fonts.ready.then(() => window.requestAnimationFrame(start));
|
|
368
|
-
}
|
|
369
|
-
else {
|
|
370
|
-
window.requestAnimationFrame(start);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
setupScrollFill() {
|
|
374
|
-
this.scrollHandler = () => {
|
|
375
|
-
if (this.rafId != null)
|
|
376
|
-
return;
|
|
377
|
-
this.rafId = window.requestAnimationFrame(() => {
|
|
378
|
-
this.rafId = undefined;
|
|
379
|
-
this.updateScrollFill();
|
|
380
|
-
});
|
|
381
|
-
};
|
|
382
|
-
window.addEventListener('scroll', this.scrollHandler, { passive: true });
|
|
383
|
-
window.addEventListener('resize', this.scrollHandler, { passive: true });
|
|
384
|
-
this.updateScrollFill();
|
|
385
|
-
}
|
|
386
|
-
teardownScrollFill() {
|
|
387
|
-
if (this.scrollHandler) {
|
|
388
|
-
window.removeEventListener('scroll', this.scrollHandler);
|
|
389
|
-
window.removeEventListener('resize', this.scrollHandler);
|
|
390
|
-
this.scrollHandler = undefined;
|
|
391
|
-
}
|
|
392
|
-
if (this.rafId != null) {
|
|
393
|
-
window.cancelAnimationFrame(this.rafId);
|
|
394
|
-
this.rafId = undefined;
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
updateScrollFill() {
|
|
398
|
-
if (this.getType() !== 'scroll-fill' || this.wordEls.length === 0)
|
|
399
|
-
return;
|
|
400
|
-
const clamp = (v) => Math.max(0, Math.min(1, v));
|
|
401
|
-
const rect = this.getBoundingClientRect();
|
|
402
|
-
const vh = window.innerHeight || document.documentElement.clientHeight;
|
|
403
|
-
// 요소 상단이 뷰포트 85% 지점에 오면 시작, 35% 지점에 오면 완료
|
|
404
|
-
const start = vh * 0.85;
|
|
405
|
-
const end = vh * 0.35;
|
|
406
|
-
const progress = clamp((start - rect.top) / (start - end || 1));
|
|
407
|
-
const n = this.wordEls.length;
|
|
408
|
-
const softness = 4; // 몇 단어에 걸쳐 부드럽게 채워질지
|
|
409
|
-
const minOpacity = 0.18;
|
|
410
|
-
this.wordEls.forEach((el, i) => {
|
|
411
|
-
const p = clamp((progress * (n + softness) - i) / softness);
|
|
412
|
-
el.style.opacity = String(minOpacity + (1 - minOpacity) * p);
|
|
413
|
-
});
|
|
414
|
-
}
|
|
415
|
-
startAnimation() {
|
|
416
|
-
const type = this.getType();
|
|
417
|
-
const text = this.getText();
|
|
418
|
-
this.isAnimating = true;
|
|
419
|
-
this.syncClasses();
|
|
420
|
-
this.syncFromAttributes();
|
|
421
|
-
if (type === 'typing') {
|
|
422
|
-
this.startTyping(0);
|
|
423
|
-
return;
|
|
424
|
-
}
|
|
425
|
-
if (type === 'decode') {
|
|
426
|
-
this.startDecoding(0);
|
|
427
|
-
return;
|
|
428
|
-
}
|
|
429
|
-
// reveal 은 --visible 클래스로 CSS stagger 가 재생되므로 재빌드 루프를 타지 않는다.
|
|
430
|
-
// roll 은 이미 정적으로 렌더되어 있고 CSS :hover 로만 동작하므로 재렌더하지 않는다.
|
|
431
|
-
if (type === 'reveal' || type === 'scroll-fill' || type === 'roll') {
|
|
432
|
-
this.displayText = text;
|
|
433
|
-
if (type !== 'roll')
|
|
434
|
-
this.renderLayer();
|
|
435
|
-
this.isAnimating = false;
|
|
436
|
-
this.syncClasses();
|
|
437
|
-
return;
|
|
438
|
-
}
|
|
439
|
-
this.displayText = text;
|
|
440
|
-
this.renderLayer();
|
|
441
|
-
const speed = Number(this.getAttribute('speed') || 1000);
|
|
442
|
-
const timer = window.setTimeout(() => {
|
|
443
|
-
this.isAnimating = false;
|
|
444
|
-
this.syncClasses();
|
|
445
|
-
this.syncFromAttributes();
|
|
446
|
-
}, speed);
|
|
447
|
-
this.timers.push(timer);
|
|
448
|
-
}
|
|
449
|
-
startTyping(iteration) {
|
|
450
|
-
const text = this.getText();
|
|
451
|
-
const speed = Number(this.getAttribute('speed') || 1000);
|
|
452
|
-
const repeat = Number(this.getAttribute('repeat') || 1);
|
|
453
|
-
this.displayText = '';
|
|
454
|
-
this.renderLayer();
|
|
455
|
-
let currentIndex = 0;
|
|
456
|
-
const interval = window.setInterval(() => {
|
|
457
|
-
if (currentIndex >= text.length) {
|
|
458
|
-
window.clearInterval(interval);
|
|
459
|
-
if (repeat === 0 || iteration < repeat - 1) {
|
|
460
|
-
const timer = window.setTimeout(() => this.startTyping(iteration + 1), 500);
|
|
461
|
-
this.timers.push(timer);
|
|
462
|
-
}
|
|
463
|
-
else {
|
|
464
|
-
this.isAnimating = false;
|
|
465
|
-
this.syncClasses();
|
|
466
|
-
}
|
|
467
|
-
return;
|
|
468
|
-
}
|
|
469
|
-
this.displayText = text.slice(0, currentIndex + 1);
|
|
470
|
-
this.renderLayer();
|
|
471
|
-
currentIndex += 1;
|
|
472
|
-
}, Math.max(16, speed / Math.max(text.length, 1)));
|
|
473
|
-
this.timers.push(interval);
|
|
474
|
-
}
|
|
475
|
-
startDecoding(iteration) {
|
|
476
|
-
const text = this.getText();
|
|
477
|
-
const repeat = Number(this.getAttribute('repeat') || 1);
|
|
478
|
-
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+';
|
|
479
|
-
let iterations = 0;
|
|
480
|
-
const interval = window.setInterval(() => {
|
|
481
|
-
this.displayText = text
|
|
482
|
-
.split('')
|
|
483
|
-
.map((char, index) => {
|
|
484
|
-
if (index < iterations)
|
|
485
|
-
return text[index];
|
|
486
|
-
return characters[Math.floor(Math.random() * characters.length)] || char;
|
|
487
|
-
})
|
|
488
|
-
.join('');
|
|
489
|
-
this.renderLayer();
|
|
490
|
-
if (iterations >= text.length) {
|
|
491
|
-
window.clearInterval(interval);
|
|
492
|
-
this.displayText = text;
|
|
493
|
-
this.renderLayer();
|
|
494
|
-
if (repeat === 0 || iteration < repeat - 1) {
|
|
495
|
-
const timer = window.setTimeout(() => this.startDecoding(iteration + 1), 500);
|
|
496
|
-
this.timers.push(timer);
|
|
497
|
-
}
|
|
498
|
-
else {
|
|
499
|
-
this.isAnimating = false;
|
|
500
|
-
this.syncClasses();
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
iterations += 1 / 3;
|
|
504
|
-
}, 30);
|
|
505
|
-
this.timers.push(interval);
|
|
506
|
-
}
|
|
507
|
-
renderLayer() {
|
|
508
|
-
if (!this.layerEl)
|
|
509
|
-
return;
|
|
510
|
-
const type = this.getType();
|
|
511
|
-
const text = this.getText();
|
|
512
|
-
const visible = this.isVisible || this.isAnimating;
|
|
513
|
-
// Reveal / Scroll-fill: 텍스트를 단어 단위 span 으로 렌더한다.
|
|
514
|
-
// (reveal 은 CSS stagger 애니메이션, scroll-fill 은 스크롤 연동 투명도)
|
|
515
|
-
if (type === 'reveal' || type === 'scroll-fill') {
|
|
516
|
-
this.wordEls = [];
|
|
517
|
-
const frag = document.createDocumentFragment();
|
|
518
|
-
const tokens = text.split(/(\s+)/);
|
|
519
|
-
let wordIndex = 0;
|
|
520
|
-
for (const token of tokens) {
|
|
521
|
-
if (token === '')
|
|
522
|
-
continue;
|
|
523
|
-
if (/^\s+$/.test(token)) {
|
|
524
|
-
frag.appendChild(document.createTextNode(token));
|
|
525
|
-
continue;
|
|
526
|
-
}
|
|
527
|
-
const span = document.createElement('span');
|
|
528
|
-
span.className = `${CLASS}__word`;
|
|
529
|
-
span.textContent = token;
|
|
530
|
-
if (type === 'reveal')
|
|
531
|
-
span.style.animationDelay = `${wordIndex * 0.06}s`;
|
|
532
|
-
this.wordEls.push(span);
|
|
533
|
-
frag.appendChild(span);
|
|
534
|
-
wordIndex += 1;
|
|
535
|
-
}
|
|
536
|
-
this.layerEl.replaceChildren(frag);
|
|
537
|
-
if (type === 'scroll-fill')
|
|
538
|
-
this.updateScrollFill();
|
|
539
|
-
return;
|
|
540
|
-
}
|
|
541
|
-
// Text-rotate: 여러 텍스트를 세로로 쌓아 일정 간격으로 위로 롤링하며 순환한다.
|
|
542
|
-
if (type === 'text-rotate') {
|
|
543
|
-
const texts = this.getRotateTexts();
|
|
544
|
-
const list = texts.length ? texts : [text];
|
|
545
|
-
const track = document.createElement('span');
|
|
546
|
-
track.className = `${CLASS}__rotate-track`;
|
|
547
|
-
const build = (t) => {
|
|
548
|
-
const s = document.createElement('span');
|
|
549
|
-
s.className = `${CLASS}__rotate-item`;
|
|
550
|
-
s.textContent = t;
|
|
551
|
-
return s;
|
|
552
|
-
};
|
|
553
|
-
list.forEach((t) => track.appendChild(build(t)));
|
|
554
|
-
// 마지막 → 첫 항목으로 끊김 없이 순환하도록 첫 항목 복제본을 덧붙인다.
|
|
555
|
-
if (list.length > 1)
|
|
556
|
-
track.appendChild(build(list[0]));
|
|
557
|
-
this.layerEl.replaceChildren(track);
|
|
558
|
-
return;
|
|
559
|
-
}
|
|
560
|
-
// Roll: 동일 텍스트 2개를 세로로 쌓고 hover 시 위로 굴려 교체한다.
|
|
561
|
-
if (type === 'roll') {
|
|
562
|
-
const track = document.createElement('span');
|
|
563
|
-
track.className = `${CLASS}__roll-track`;
|
|
564
|
-
const first = document.createElement('span');
|
|
565
|
-
first.className = `${CLASS}__roll-item`;
|
|
566
|
-
first.textContent = text;
|
|
567
|
-
const second = first.cloneNode(true);
|
|
568
|
-
track.append(first, second);
|
|
569
|
-
this.layerEl.replaceChildren(track);
|
|
570
|
-
return;
|
|
571
|
-
}
|
|
572
|
-
// Typing: 타이핑된 부분 텍스트 뒤에 인라인 캐럿을 붙여 텍스트를 따라가게 한다.
|
|
573
|
-
// 캐럿은 타이핑 중(isAnimating)에만 표시하고, 완료되면 제거한다.
|
|
574
|
-
if (type === 'typing') {
|
|
575
|
-
this.layerEl.textContent = this.displayText;
|
|
576
|
-
if (this.isAnimating) {
|
|
577
|
-
const caret = document.createElement('span');
|
|
578
|
-
caret.className = `${CLASS}__caret`;
|
|
579
|
-
caret.setAttribute('aria-hidden', 'true');
|
|
580
|
-
this.layerEl.appendChild(caret);
|
|
581
|
-
}
|
|
582
|
-
return;
|
|
583
|
-
}
|
|
584
|
-
if ((type === 'wave' || type === 'shake') && visible) {
|
|
585
|
-
this.layerEl.replaceChildren(...text.split('').map((char, index) => {
|
|
586
|
-
const span = document.createElement('span');
|
|
587
|
-
span.style.animationDelay = `${index * 0.05}s`;
|
|
588
|
-
span.style.display = 'inline-block';
|
|
589
|
-
span.textContent = char === ' ' ? '\u00A0' : char;
|
|
590
|
-
return span;
|
|
591
|
-
}));
|
|
592
|
-
return;
|
|
593
|
-
}
|
|
594
|
-
this.layerEl.textContent = this.displayText || (visible ? text : '');
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
if (!customElements.get('db-animation-text')) {
|
|
598
|
-
customElements.define('db-animation-text', DbAnimationText);
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
export { DbAnimationText };
|
|
1
|
+
const t="designbase-wc-animation-text";class DbAnimationText extends HTMLElement{constructor(){super(...arguments),this.timers=[],this.displayText="",this.isVisible=!1,this.isAnimating=!1,this.wordEls=[],this.rotateToken=0}static get observedAttributes(){return["text","texts","interval","trigger","type","speed","repeat","delay","direction","size","color","custom-color","weight","align","gradient-colors","wave-colors","glow-color","clickable","disabled"]}connectedCallback(){this.style.display="inline-block",this.ensureStructure(),this.syncFromAttributes(),this.setupTrigger()}disconnectedCallback(){this.clearTimers(),this.observer?.disconnect(),this.teardownScrollFill(),this.rotateObserver?.disconnect()}attributeChangedCallback(){this.isConnected&&(this.syncFromAttributes(),this.setupTrigger())}getText(){return this.getAttribute("text")||this.textContent?.trim()||""}getRotateTexts(){const t=this.getAttribute("texts");if(t){const e=t.split(",").map(t=>t.trim()).filter(Boolean);if(e.length)return e}const e=this.getText();return e?[e]:[]}getLongestText(){return this.getRotateTexts().reduce((t,e)=>e.length>t.length?e:t,"")}getType(){const t=this.getAttribute("type")||"fade";return["typing","fade","slide","bounce","shake","glow","gradient","wave","flip","scale","decode","roll","reveal","scroll-fill","text-rotate"].includes(t)?t:"fade"}getTrigger(){const t=this.getAttribute("trigger")||"mount";return["mount","hover","click","in-view"].includes(t)?t:"mount"}ensureStructure(){this.ghostEl||(this.ghostEl=document.createElement("span"),this.ghostEl.setAttribute("aria-hidden","true"),this.ghostEl.style.visibility="hidden",this.ghostEl.style.pointerEvents="none",this.ghostEl.style.userSelect="none",this.layerEl=document.createElement("span"),this.layerEl.style.position="absolute",this.layerEl.style.top="0",this.layerEl.style.left="0",this.append(this.ghostEl,this.layerEl),this.addEventListener("mouseenter",()=>{"hover"!==this.getTrigger()||this.hasAttribute("disabled")||"roll"!==this.getType()&&(this.isVisible=!0,this.startAnimation(),this.syncClasses())}),this.addEventListener("mouseleave",()=>{if("hover"!==this.getTrigger())return;if("roll"===this.getType())return;this.isVisible=!1,this.isAnimating=!1,this.clearTimers();const t=this.getType();"typing"!==t&&"decode"!==t||(this.displayText=this.getText()),this.renderLayer(),this.syncClasses()}),this.addEventListener("click",()=>{if(!this.hasAttribute("disabled")){if("click"===this.getTrigger()){if(this.isVisible=!this.isVisible,this.isVisible)this.startAnimation();else{this.isAnimating=!1,this.clearTimers();const t=this.getType();"typing"!==t&&"decode"!==t||(this.displayText=this.getText()),this.renderLayer()}this.syncClasses()}this.hasAttribute("clickable")&&this.dispatchEvent(new CustomEvent("db-click",{bubbles:!0,composed:!0}))}}))}clearTimers(){this.timers.forEach(t=>window.clearInterval(t)),this.timers.forEach(t=>window.clearTimeout(t)),this.timers=[]}syncFromAttributes(){const e=this.getText(),i=this.getType(),s=this.getTrigger(),r=Number(this.getAttribute("speed")||1e3),n=Number(this.getAttribute("repeat")||1),l=this.getAttribute("custom-color"),o=(this.getAttribute("gradient-colors")||"#667eea,#764ba2").split(","),a=(this.getAttribute("wave-colors")||"#ff6b6b,#4ecdc4,#45b7d1,#96ceb4,#feca57").split(","),h=this.getAttribute("glow-color")||"#667eea";this.className=[t,"typing"!==i&&`${t}--${i}`,`${t}--${this.getAttribute("size")||"m"}`,`${t}--${this.getAttribute("color")||"primary"}`,`${t}--${this.getAttribute("weight")||"normal"}`,`${t}--${this.getAttribute("align")||"left"}`,`${t}--${this.getAttribute("direction")||"left"}`,this.isVisible&&`${t}--visible`,this.isAnimating&&`${t}--animating`,(this.hasAttribute("clickable")||"click"===s)&&`${t}--clickable`,this.hasAttribute("disabled")&&`${t}--disabled`].filter(Boolean).join(" "),this.style.setProperty("--db-animation-speed",`${Number.isFinite(r)?r:1e3}ms`),this.style.setProperty("--db-animation-iteration-count",0===n?"infinite":String(n)),l&&this.style.setProperty("--db-text-custom",l),this.style.setProperty("--db-wave-colors",a.join(", ")),this.style.setProperty("--db-glow-color",h),this.style.removeProperty("background"),this.style.removeProperty("background-size"),this.style.removeProperty("-webkit-background-clip"),this.style.removeProperty("-webkit-text-fill-color"),this.style.removeProperty("background-clip"),this.layerEl&&("gradient"===i&&o.length>=2?this.layerEl.style.backgroundImage=`linear-gradient(45deg, ${o.join(", ")})`:this.layerEl.style.removeProperty("background-image")),"typing"!==i&&"decode"!==i||"mount"!==s||this.isAnimating?this.isAnimating||(this.displayText=e):this.displayText="";const c="typing"===i||"decode"===i||"roll"===i||"text-rotate"===i,d="roll"===i||"text-rotate"===i?"nowrap":c?"pre-wrap":"";this.ghostEl&&(c?(this.ghostEl.textContent="text-rotate"===i?this.getLongestText():e,this.ghostEl.style.display="inline-block",this.ghostEl.style.whiteSpace=d,this.ghostEl.style.paddingRight="typing"===i?"0.25em":""):(this.ghostEl.textContent="",this.ghostEl.style.display="none")),this.layerEl&&(this.layerEl.className=[`${t}__layer`,"typing"===i&&`${t}--typing`,this.isAnimating&&"typing"===i&&`${t}--animating`].filter(Boolean).join(" "),c?(this.layerEl.style.position="absolute",this.layerEl.style.top="0",this.layerEl.style.left="0",this.layerEl.style.width="100%",this.layerEl.style.height="100%",this.layerEl.style.whiteSpace=d):(this.layerEl.style.position="static",this.layerEl.style.removeProperty("top"),this.layerEl.style.removeProperty("left"),this.layerEl.style.width="auto",this.layerEl.style.height="auto",this.layerEl.style.whiteSpace="")),this.renderLayer()}syncClasses(){this.classList.toggle(`${t}--visible`,this.isVisible),this.classList.toggle(`${t}--animating`,this.isAnimating)}setupTrigger(){this.clearTimers(),this.observer?.disconnect(),this.teardownScrollFill(),this.rotateObserver?.disconnect(),this.rotateObserver=void 0,this.rotateToken++;const t=this.getTrigger(),e=Number(this.getAttribute("delay")||0);if("scroll-fill"!==this.getType())if("text-rotate"!==this.getType()){if("mount"===t){const t=window.setTimeout(()=>{this.isVisible=!0,this.syncClasses(),this.startAnimation()},e);return void this.timers.push(t)}"in-view"===t&&(this.observer=new IntersectionObserver(t=>{t[0]?.isIntersecting&&(window.setTimeout(()=>{this.isVisible=!0,this.syncClasses(),this.startAnimation()},e),this.observer?.disconnect())}),this.observer.observe(this))}else this.setupTextRotate();else this.setupScrollFill()}setupTextRotate(){if(this.getRotateTexts().length<=1)return;const e=++this.rotateToken,start=()=>{if(e!==this.rotateToken||!this.isConnected||"text-rotate"!==this.getType())return;const i=this.layerEl?.querySelector(`.${t}__rotate-track`);if(!i||!i.firstElementChild)return;const s=Array.from(i.children),r=Number(this.getAttribute("speed")||500),n=Math.max(r+200,Number(this.getAttribute("interval")||2e3));let l=0;const apply=t=>{const e=s[0].getBoundingClientRect().height;if(!e)return;const n="cubic-bezier(0.22, 1, 0.36, 1)";var o;i.style.transition=t?`transform ${r}ms ${n}`:"none",i.style.transform=`translateY(-${l*e}px)`,this.style.transition=t?`width ${r}ms ${n}`:"none",this.style.width=`${o=l,s[o].getBoundingClientRect().width}px`};apply(!1);const o=window.setInterval(()=>{if(l+=1,apply(!0),l===s.length-1){const t=window.setTimeout(()=>{l=0,apply(!1)},r);this.timers.push(t)}},n);this.timers.push(o),this.rotateObserver?.disconnect();let a=!0;const h=new ResizeObserver(()=>{a?a=!1:apply(!1)});h.observe(s[0]),this.rotateObserver=h};"undefined"!=typeof document&&document.fonts?document.fonts.ready.then(()=>window.requestAnimationFrame(start)):window.requestAnimationFrame(start)}setupScrollFill(){this.scrollHandler=()=>{null==this.rafId&&(this.rafId=window.requestAnimationFrame(()=>{this.rafId=void 0,this.updateScrollFill()}))},window.addEventListener("scroll",this.scrollHandler,{passive:!0}),window.addEventListener("resize",this.scrollHandler,{passive:!0}),this.updateScrollFill()}teardownScrollFill(){this.scrollHandler&&(window.removeEventListener("scroll",this.scrollHandler),window.removeEventListener("resize",this.scrollHandler),this.scrollHandler=void 0),null!=this.rafId&&(window.cancelAnimationFrame(this.rafId),this.rafId=void 0)}updateScrollFill(){if("scroll-fill"!==this.getType()||0===this.wordEls.length)return;const clamp=t=>Math.max(0,Math.min(1,t)),t=this.getBoundingClientRect(),e=window.innerHeight||document.documentElement.clientHeight,i=.85*e,s=.35*e,r=clamp((i-t.top)/(i-s||1)),n=this.wordEls.length;this.wordEls.forEach((t,e)=>{const i=clamp((r*(n+4)-e)/4);t.style.opacity=String(.18+(1-.18)*i)})}startAnimation(){const t=this.getType(),e=this.getText();if(this.isAnimating=!0,this.syncClasses(),this.syncFromAttributes(),"typing"===t)return void this.startTyping(0);if("decode"===t)return void this.startDecoding(0);if("reveal"===t||"scroll-fill"===t||"roll"===t)return this.displayText=e,"roll"!==t&&this.renderLayer(),this.isAnimating=!1,void this.syncClasses();this.displayText=e,this.renderLayer();const i=Number(this.getAttribute("speed")||1e3),s=window.setTimeout(()=>{this.isAnimating=!1,this.syncClasses(),this.syncFromAttributes()},i);this.timers.push(s)}startTyping(t){const e=this.getText(),i=Number(this.getAttribute("speed")||1e3),s=Number(this.getAttribute("repeat")||1);this.displayText="",this.renderLayer();let r=0;const n=window.setInterval(()=>{if(r>=e.length)if(window.clearInterval(n),0===s||t<s-1){const e=window.setTimeout(()=>this.startTyping(t+1),500);this.timers.push(e)}else this.isAnimating=!1,this.syncClasses();else this.displayText=e.slice(0,r+1),this.renderLayer(),r+=1},Math.max(16,i/Math.max(e.length,1)));this.timers.push(n)}startDecoding(t){const e=this.getText(),i=Number(this.getAttribute("repeat")||1),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+";let r=0;const n=window.setInterval(()=>{if(this.displayText=e.split("").map((t,i)=>i<r?e[i]:s[Math.floor(74*Math.random())]||t).join(""),this.renderLayer(),r>=e.length)if(window.clearInterval(n),this.displayText=e,this.renderLayer(),0===i||t<i-1){const e=window.setTimeout(()=>this.startDecoding(t+1),500);this.timers.push(e)}else this.isAnimating=!1,this.syncClasses();r+=1/3},30);this.timers.push(n)}renderLayer(){if(!this.layerEl)return;const e=this.getType(),i=this.getText(),s=this.isVisible||this.isAnimating;if("reveal"===e||"scroll-fill"===e){this.wordEls=[];const s=document.createDocumentFragment(),r=i.split(/(\s+)/);let n=0;for(const i of r){if(""===i)continue;if(/^\s+$/.test(i)){s.appendChild(document.createTextNode(i));continue}const r=document.createElement("span");r.className=`${t}__word`,r.textContent=i,"reveal"===e&&(r.style.animationDelay=.06*n+"s"),this.wordEls.push(r),s.appendChild(r),n+=1}return this.layerEl.replaceChildren(s),void("scroll-fill"===e&&this.updateScrollFill())}if("text-rotate"===e){const e=this.getRotateTexts(),s=e.length?e:[i],r=document.createElement("span");r.className=`${t}__rotate-track`;const build=e=>{const i=document.createElement("span");return i.className=`${t}__rotate-item`,i.textContent=e,i};return s.forEach(t=>r.appendChild(build(t))),s.length>1&&r.appendChild(build(s[0])),void this.layerEl.replaceChildren(r)}if("roll"===e){const e=document.createElement("span");e.className=`${t}__roll-track`;const s=document.createElement("span");s.className=`${t}__roll-item`,s.textContent=i;const r=s.cloneNode(!0);return e.append(s,r),void this.layerEl.replaceChildren(e)}if("typing"!==e)"wave"!==e&&"shake"!==e||!s?this.layerEl.textContent=this.displayText||(s?i:""):this.layerEl.replaceChildren(...i.split("").map((t,e)=>{const i=document.createElement("span");return i.style.animationDelay=.05*e+"s",i.style.display="inline-block",i.textContent=" "===t?" ":t,i}));else if(this.layerEl.textContent=this.displayText,this.isAnimating){const e=document.createElement("span");e.className=`${t}__caret`,e.setAttribute("aria-hidden","true"),this.layerEl.appendChild(e)}}}customElements.get("db-animation-text")||customElements.define("db-animation-text",DbAnimationText);export{DbAnimationText};
|