@designbasekorea/ui-wc 0.5.6 → 0.6.0
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-0e23d630.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 +62 -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 +61 -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.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 +60 -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/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-bash.js +1 -0
- package/dist/esm/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-clike.js +1 -0
- package/dist/esm/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-css.js +1 -0
- package/dist/esm/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-javascript.js +1 -0
- package/dist/esm/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-json.js +1 -0
- package/dist/esm/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-jsx.js +1 -0
- package/dist/esm/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-markup.js +1 -0
- package/dist/esm/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-scss.js +1 -0
- package/dist/esm/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-tsx.js +1 -0
- package/dist/esm/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-typescript.js +1 -0
- package/dist/index.cjs +1 -55414
- package/dist/index.css +1 -1
- package/dist/index.d.ts +1091 -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 +1620 -54
- package/dist/react/index.esm.js +1 -39373
- package/package.json +1 -1
- package/dist/chunks/lottie-e273b936.js +0 -17032
- package/dist/esm/node_modules/prismjs/components/prism-bash.js +0 -235
- package/dist/esm/node_modules/prismjs/components/prism-clike.js +0 -31
- package/dist/esm/node_modules/prismjs/components/prism-css.js +0 -64
- package/dist/esm/node_modules/prismjs/components/prism-javascript.js +0 -172
- package/dist/esm/node_modules/prismjs/components/prism-json.js +0 -27
- package/dist/esm/node_modules/prismjs/components/prism-jsx.js +0 -143
- package/dist/esm/node_modules/prismjs/components/prism-markup.js +0 -186
- package/dist/esm/node_modules/prismjs/components/prism-scss.js +0 -81
- package/dist/esm/node_modules/prismjs/components/prism-tsx.js +0 -15
- package/dist/esm/node_modules/prismjs/components/prism-typescript.js +0 -60
- package/dist/react/chunks/lottie-72a4c6d4.js +0 -17032
|
@@ -1,811 +1 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* RangeSlider Web Component
|
|
3
|
-
* packages/ui RangeSlider.tsx와 DOM·동작·스타일 1:1 동기화
|
|
4
|
-
*/
|
|
5
|
-
const CLASS = 'designbase-wc-range-slider';
|
|
6
|
-
class DbRangeSlider extends HTMLElement {
|
|
7
|
-
constructor() {
|
|
8
|
-
super(...arguments);
|
|
9
|
-
this.built = false;
|
|
10
|
-
this.headerEl = null;
|
|
11
|
-
this.labelEl = null;
|
|
12
|
-
this.valuesEl = null;
|
|
13
|
-
this.containerEl = null;
|
|
14
|
-
this.trackEl = null;
|
|
15
|
-
this.fillEl = null;
|
|
16
|
-
this.thumbEls = [];
|
|
17
|
-
this.currentValue = 50;
|
|
18
|
-
this.currentRange = [25, 75];
|
|
19
|
-
this.isDragging = false;
|
|
20
|
-
this.activeThumb = null;
|
|
21
|
-
this.boundTrackClick = (e) => this.handleTrackClick(e);
|
|
22
|
-
this.boundPointerMove = (e) => this.handlePointerMove(e);
|
|
23
|
-
this.boundPointerUp = () => this.handlePointerUp();
|
|
24
|
-
this.boundContainerKeyDown = (e) => this.handleKeyDown(e);
|
|
25
|
-
this.eventsBound = false;
|
|
26
|
-
}
|
|
27
|
-
static get observedAttributes() {
|
|
28
|
-
return [
|
|
29
|
-
'value',
|
|
30
|
-
'range',
|
|
31
|
-
'min',
|
|
32
|
-
'max',
|
|
33
|
-
'step',
|
|
34
|
-
'size',
|
|
35
|
-
'variant',
|
|
36
|
-
'show-value',
|
|
37
|
-
'show-label',
|
|
38
|
-
'label',
|
|
39
|
-
'value-position',
|
|
40
|
-
'value-fixed',
|
|
41
|
-
'show-thumb-tooltip',
|
|
42
|
-
'show-marks',
|
|
43
|
-
'marks',
|
|
44
|
-
'mark-labels',
|
|
45
|
-
'disabled',
|
|
46
|
-
'readonly',
|
|
47
|
-
'full-width',
|
|
48
|
-
'vertical',
|
|
49
|
-
];
|
|
50
|
-
}
|
|
51
|
-
connectedCallback() {
|
|
52
|
-
if (!this.built) {
|
|
53
|
-
this.build();
|
|
54
|
-
this.built = true;
|
|
55
|
-
}
|
|
56
|
-
this.readAttributeValues();
|
|
57
|
-
this.syncClasses();
|
|
58
|
-
this.syncDomOrder();
|
|
59
|
-
this.syncStructure();
|
|
60
|
-
this.syncVisuals();
|
|
61
|
-
this.syncA11y();
|
|
62
|
-
this.bindEvents();
|
|
63
|
-
}
|
|
64
|
-
disconnectedCallback() {
|
|
65
|
-
this.unbindEvents();
|
|
66
|
-
}
|
|
67
|
-
attributeChangedCallback(name) {
|
|
68
|
-
if (!this.built)
|
|
69
|
-
return;
|
|
70
|
-
this.readAttributeValues();
|
|
71
|
-
this.syncClasses();
|
|
72
|
-
if (this.isStructuralAttribute(name)) {
|
|
73
|
-
this.syncDomOrder();
|
|
74
|
-
this.syncStructure();
|
|
75
|
-
}
|
|
76
|
-
this.syncVisuals();
|
|
77
|
-
this.syncA11y();
|
|
78
|
-
}
|
|
79
|
-
isStructuralAttribute(name) {
|
|
80
|
-
return [
|
|
81
|
-
'range',
|
|
82
|
-
'show-value',
|
|
83
|
-
'show-label',
|
|
84
|
-
'label',
|
|
85
|
-
'value-position',
|
|
86
|
-
'show-marks',
|
|
87
|
-
'marks',
|
|
88
|
-
'mark-labels',
|
|
89
|
-
'vertical',
|
|
90
|
-
].includes(name);
|
|
91
|
-
}
|
|
92
|
-
get value() {
|
|
93
|
-
return this.currentValue;
|
|
94
|
-
}
|
|
95
|
-
set value(v) {
|
|
96
|
-
this.currentValue = this.clamp(v);
|
|
97
|
-
this.setAttribute('value', String(this.currentValue));
|
|
98
|
-
this.syncVisuals();
|
|
99
|
-
}
|
|
100
|
-
get range() {
|
|
101
|
-
if (!this.hasAttribute('range'))
|
|
102
|
-
return undefined;
|
|
103
|
-
return [...this.currentRange];
|
|
104
|
-
}
|
|
105
|
-
set range(v) {
|
|
106
|
-
if (v === undefined || v === null) {
|
|
107
|
-
this.removeAttribute('range');
|
|
108
|
-
if (this.built) {
|
|
109
|
-
this.syncStructure();
|
|
110
|
-
this.syncVisuals();
|
|
111
|
-
}
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
const parsed = this.normalizeRangeInput(v);
|
|
115
|
-
if (!parsed)
|
|
116
|
-
return;
|
|
117
|
-
const sorted = [Math.min(parsed[0], parsed[1]), Math.max(parsed[0], parsed[1])];
|
|
118
|
-
this.currentRange = [
|
|
119
|
-
this.clamp(sorted[0]),
|
|
120
|
-
this.clamp(sorted[1]),
|
|
121
|
-
];
|
|
122
|
-
const nextAttr = `${this.currentRange[0]},${this.currentRange[1]}`;
|
|
123
|
-
if (this.getAttribute('range') !== nextAttr) {
|
|
124
|
-
this.setAttribute('range', nextAttr);
|
|
125
|
-
}
|
|
126
|
-
if (this.built) {
|
|
127
|
-
this.syncVisuals();
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
build() {
|
|
131
|
-
this.classList.add(CLASS);
|
|
132
|
-
this.headerEl = document.createElement('div');
|
|
133
|
-
this.headerEl.className = `${CLASS}__header`;
|
|
134
|
-
this.labelEl = document.createElement('span');
|
|
135
|
-
this.labelEl.className = `${CLASS}__label`;
|
|
136
|
-
this.valuesEl = document.createElement('div');
|
|
137
|
-
this.valuesEl.className = `${CLASS}__values`;
|
|
138
|
-
this.containerEl = document.createElement('div');
|
|
139
|
-
this.containerEl.className = `${CLASS}__container`;
|
|
140
|
-
this.containerEl.setAttribute('role', 'slider');
|
|
141
|
-
this.containerEl.setAttribute('tabindex', '0');
|
|
142
|
-
this.trackEl = document.createElement('div');
|
|
143
|
-
this.trackEl.className = `${CLASS}__track`;
|
|
144
|
-
this.fillEl = document.createElement('div');
|
|
145
|
-
this.fillEl.className = `${CLASS}__fill`;
|
|
146
|
-
this.trackEl.appendChild(this.fillEl);
|
|
147
|
-
this.containerEl.appendChild(this.trackEl);
|
|
148
|
-
}
|
|
149
|
-
getValuePosition() {
|
|
150
|
-
const attr = this.getAttribute('value-position');
|
|
151
|
-
if (attr)
|
|
152
|
-
return attr;
|
|
153
|
-
// 기본값: 레이블이 있으면 top(레이블 좌 · 값 우), 없으면 right(트랙 우측 인라인)
|
|
154
|
-
return this.shouldShowLabel() ? 'top' : 'right';
|
|
155
|
-
}
|
|
156
|
-
shouldShowLabel() {
|
|
157
|
-
return this.hasAttribute('show-label') && Boolean(this.getAttribute('label')?.trim());
|
|
158
|
-
}
|
|
159
|
-
formatValue(value) {
|
|
160
|
-
const fixed = this.getAttribute('value-fixed');
|
|
161
|
-
if (fixed !== null && fixed !== '') {
|
|
162
|
-
const digits = Number(fixed);
|
|
163
|
-
if (Number.isFinite(digits))
|
|
164
|
-
return value.toFixed(digits);
|
|
165
|
-
}
|
|
166
|
-
return String(value);
|
|
167
|
-
}
|
|
168
|
-
syncDomOrder() {
|
|
169
|
-
if (!this.headerEl || !this.valuesEl || !this.containerEl)
|
|
170
|
-
return;
|
|
171
|
-
const valuePosition = this.getValuePosition();
|
|
172
|
-
const showLabel = this.shouldShowLabel();
|
|
173
|
-
const showValue = this.hasAttribute('show-value');
|
|
174
|
-
const isRange = this.hasAttribute('range');
|
|
175
|
-
this.replaceChildren();
|
|
176
|
-
if (this.labelEl) {
|
|
177
|
-
this.labelEl.textContent = this.getAttribute('label')?.trim() || '';
|
|
178
|
-
}
|
|
179
|
-
// 레이블 좌 · 값 우 헤더 — range이거나 value-position=top인 경우
|
|
180
|
-
if (isRange || valuePosition === 'top') {
|
|
181
|
-
this.headerEl.replaceChildren();
|
|
182
|
-
if (showLabel && this.labelEl)
|
|
183
|
-
this.headerEl.appendChild(this.labelEl);
|
|
184
|
-
if (showValue)
|
|
185
|
-
this.headerEl.appendChild(this.valuesEl);
|
|
186
|
-
if (this.headerEl.childElementCount > 0)
|
|
187
|
-
this.append(this.headerEl);
|
|
188
|
-
this.append(this.containerEl);
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
// bottom — 레이블(상단) · 트랙 · 값(하단)
|
|
192
|
-
if (valuePosition === 'bottom') {
|
|
193
|
-
if (showLabel && this.labelEl) {
|
|
194
|
-
this.headerEl.replaceChildren(this.labelEl);
|
|
195
|
-
this.append(this.headerEl);
|
|
196
|
-
}
|
|
197
|
-
this.append(this.containerEl);
|
|
198
|
-
if (showValue)
|
|
199
|
-
this.append(this.valuesEl);
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
// left · right — [값 | 트랙] 인라인 (CSS order로 좌우 결정)
|
|
203
|
-
if (showValue) {
|
|
204
|
-
this.append(this.valuesEl, this.containerEl);
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
this.append(this.containerEl);
|
|
208
|
-
}
|
|
209
|
-
bindEvents() {
|
|
210
|
-
if (this.eventsBound)
|
|
211
|
-
return;
|
|
212
|
-
this.trackEl?.addEventListener('click', this.boundTrackClick);
|
|
213
|
-
this.containerEl?.addEventListener('keydown', this.boundContainerKeyDown);
|
|
214
|
-
this.eventsBound = true;
|
|
215
|
-
}
|
|
216
|
-
unbindEvents() {
|
|
217
|
-
if (!this.eventsBound)
|
|
218
|
-
return;
|
|
219
|
-
this.trackEl?.removeEventListener('click', this.boundTrackClick);
|
|
220
|
-
this.containerEl?.removeEventListener('keydown', this.boundContainerKeyDown);
|
|
221
|
-
document.removeEventListener('pointermove', this.boundPointerMove);
|
|
222
|
-
document.removeEventListener('pointerup', this.boundPointerUp);
|
|
223
|
-
this.eventsBound = false;
|
|
224
|
-
}
|
|
225
|
-
readAttributeValues() {
|
|
226
|
-
const min = this.getNumberAttr('min', 0);
|
|
227
|
-
const max = this.getNumberAttr('max', 100);
|
|
228
|
-
const step = this.getNumberAttr('step', 1);
|
|
229
|
-
if (this.hasAttribute('range')) {
|
|
230
|
-
const parsed = this.parseRangeAttr(this.getAttribute('range'));
|
|
231
|
-
if (parsed) {
|
|
232
|
-
this.currentRange = [
|
|
233
|
-
this.clamp(parsed[0], min, max, step),
|
|
234
|
-
this.clamp(parsed[1], min, max, step),
|
|
235
|
-
];
|
|
236
|
-
}
|
|
237
|
-
else if (!this.currentRange.every(Number.isFinite)) {
|
|
238
|
-
this.currentRange = [25, 75];
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
else {
|
|
242
|
-
this.currentValue = this.clamp(this.getNumberAttr('value', 50), min, max, step);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
syncClasses() {
|
|
246
|
-
const size = (this.getAttribute('size') || 'm');
|
|
247
|
-
const variant = (this.getAttribute('variant') || 'default');
|
|
248
|
-
const isRange = this.hasAttribute('range');
|
|
249
|
-
const valuePosition = this.getValuePosition();
|
|
250
|
-
const effectiveValuePosition = isRange ? 'top' : valuePosition;
|
|
251
|
-
const classTokens = [
|
|
252
|
-
CLASS,
|
|
253
|
-
`${CLASS}--${size}`,
|
|
254
|
-
`${CLASS}--${variant}`,
|
|
255
|
-
`${CLASS}--value-${effectiveValuePosition}`,
|
|
256
|
-
this.shouldShowLabel() ? `${CLASS}--has-label` : '',
|
|
257
|
-
this.hasAttribute('disabled') ? `${CLASS}--disabled` : '',
|
|
258
|
-
this.hasAttribute('readonly') ? `${CLASS}--readonly` : '',
|
|
259
|
-
this.hasAttribute('full-width') ? `${CLASS}--full-width` : '',
|
|
260
|
-
this.hasAttribute('vertical') ? `${CLASS}--vertical` : '',
|
|
261
|
-
this.hasAttribute('show-thumb-tooltip') ? `${CLASS}--show-tooltip` : '',
|
|
262
|
-
isRange ? `${CLASS}--range` : '',
|
|
263
|
-
].filter(Boolean);
|
|
264
|
-
this.className = classTokens.join(' ');
|
|
265
|
-
if (this.trackEl) {
|
|
266
|
-
const trackClasses = [`${CLASS}__track`];
|
|
267
|
-
if (this.hasAttribute('disabled'))
|
|
268
|
-
trackClasses.push(`${CLASS}__track--disabled`);
|
|
269
|
-
if (this.hasAttribute('readonly'))
|
|
270
|
-
trackClasses.push(`${CLASS}__track--readonly`);
|
|
271
|
-
this.trackEl.className = trackClasses.join(' ');
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
syncStructure() {
|
|
275
|
-
if (!this.valuesEl || !this.trackEl || !this.fillEl)
|
|
276
|
-
return;
|
|
277
|
-
const showValue = this.hasAttribute('show-value');
|
|
278
|
-
const isRange = this.hasAttribute('range');
|
|
279
|
-
const showMarks = this.hasAttribute('show-marks');
|
|
280
|
-
this.valuesEl.innerHTML = '';
|
|
281
|
-
this.valuesEl.hidden = !showValue;
|
|
282
|
-
if (showValue) {
|
|
283
|
-
if (isRange) {
|
|
284
|
-
const minSpan = document.createElement('span');
|
|
285
|
-
minSpan.className = `${CLASS}__value ${CLASS}__value--min`;
|
|
286
|
-
const sep = document.createElement('span');
|
|
287
|
-
sep.className = `${CLASS}__value-separator`;
|
|
288
|
-
sep.textContent = '~';
|
|
289
|
-
sep.setAttribute('aria-hidden', 'true');
|
|
290
|
-
const maxSpan = document.createElement('span');
|
|
291
|
-
maxSpan.className = `${CLASS}__value ${CLASS}__value--max`;
|
|
292
|
-
this.valuesEl.append(minSpan, sep, maxSpan);
|
|
293
|
-
}
|
|
294
|
-
else {
|
|
295
|
-
const span = document.createElement('span');
|
|
296
|
-
span.className = `${CLASS}__value ${CLASS}__value--single`;
|
|
297
|
-
this.valuesEl.appendChild(span);
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
this.thumbEls.forEach((el) => el.remove());
|
|
301
|
-
this.thumbEls = [];
|
|
302
|
-
this.trackEl.querySelectorAll(`.${CLASS}__mark`).forEach((el) => el.remove());
|
|
303
|
-
if (showMarks) {
|
|
304
|
-
const marks = this.parseMarks();
|
|
305
|
-
if (marks.length > 0) {
|
|
306
|
-
const labels = this.parseMarkLabels();
|
|
307
|
-
marks.forEach((mark) => {
|
|
308
|
-
const markEl = document.createElement('div');
|
|
309
|
-
markEl.className = `${CLASS}__mark`;
|
|
310
|
-
markEl.setAttribute('aria-hidden', 'true');
|
|
311
|
-
if (this.isMarkActive(mark)) {
|
|
312
|
-
markEl.classList.add(`${CLASS}__mark--active`);
|
|
313
|
-
}
|
|
314
|
-
if (this.hasAttribute('vertical')) {
|
|
315
|
-
markEl.style.bottom = `${this.valueToPercent(mark)}%`;
|
|
316
|
-
}
|
|
317
|
-
else {
|
|
318
|
-
markEl.style.left = `${this.valueToPercent(mark)}%`;
|
|
319
|
-
}
|
|
320
|
-
if (labels[mark] !== undefined) {
|
|
321
|
-
const labelEl = document.createElement('span');
|
|
322
|
-
labelEl.className = `${CLASS}__mark-label`;
|
|
323
|
-
labelEl.textContent = labels[mark];
|
|
324
|
-
markEl.appendChild(labelEl);
|
|
325
|
-
}
|
|
326
|
-
this.trackEl.insertBefore(markEl, this.fillEl);
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
const thumbCount = isRange ? 2 : 1;
|
|
331
|
-
const disabled = this.hasAttribute('disabled') || this.hasAttribute('readonly');
|
|
332
|
-
for (let i = 0; i < thumbCount; i++) {
|
|
333
|
-
const thumb = document.createElement('div');
|
|
334
|
-
thumb.className = `${CLASS}__thumb`;
|
|
335
|
-
thumb.setAttribute('role', 'slider');
|
|
336
|
-
thumb.setAttribute('draggable', 'false');
|
|
337
|
-
thumb.setAttribute('tabindex', disabled ? '-1' : '0');
|
|
338
|
-
const thumbType = isRange
|
|
339
|
-
? (i === 0 ? 'min' : 'max')
|
|
340
|
-
: 'single';
|
|
341
|
-
if (isRange) {
|
|
342
|
-
thumb.dataset.thumb = thumbType;
|
|
343
|
-
}
|
|
344
|
-
thumb.addEventListener('pointerdown', (e) => this.handleThumbPointerDown(e, thumbType));
|
|
345
|
-
thumb.addEventListener('keydown', (e) => this.handleKeyDown(e, thumbType));
|
|
346
|
-
const tooltip = document.createElement('span');
|
|
347
|
-
tooltip.className = `${CLASS}__thumb-tooltip`;
|
|
348
|
-
tooltip.setAttribute('aria-hidden', 'true');
|
|
349
|
-
tooltip.hidden = true;
|
|
350
|
-
thumb.appendChild(tooltip);
|
|
351
|
-
this.trackEl.appendChild(thumb);
|
|
352
|
-
this.thumbEls.push(thumb);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
isMarkActive(mark) {
|
|
356
|
-
if (this.hasAttribute('range')) {
|
|
357
|
-
const [lo, hi] = this.currentRange;
|
|
358
|
-
return mark >= lo && mark <= hi;
|
|
359
|
-
}
|
|
360
|
-
return mark <= this.currentValue;
|
|
361
|
-
}
|
|
362
|
-
syncVisuals() {
|
|
363
|
-
if (!this.fillEl)
|
|
364
|
-
return;
|
|
365
|
-
const isRange = this.hasAttribute('range');
|
|
366
|
-
const min = this.getNumberAttr('min', 0);
|
|
367
|
-
const max = this.getNumberAttr('max', 100);
|
|
368
|
-
if (isRange) {
|
|
369
|
-
const [lo, hi] = this.currentRange;
|
|
370
|
-
const loPct = this.valueToPercent(lo);
|
|
371
|
-
const hiPct = this.valueToPercent(hi);
|
|
372
|
-
if (this.hasAttribute('vertical')) {
|
|
373
|
-
this.fillEl.style.left = '';
|
|
374
|
-
this.fillEl.style.width = '';
|
|
375
|
-
this.fillEl.style.bottom = `${loPct}%`;
|
|
376
|
-
this.fillEl.style.height = `${hiPct - loPct}%`;
|
|
377
|
-
}
|
|
378
|
-
else {
|
|
379
|
-
this.fillEl.style.bottom = '';
|
|
380
|
-
this.fillEl.style.height = '';
|
|
381
|
-
this.fillEl.style.left = `${loPct}%`;
|
|
382
|
-
this.fillEl.style.width = `${hiPct - loPct}%`;
|
|
383
|
-
}
|
|
384
|
-
if (this.thumbEls[0]) {
|
|
385
|
-
this.setThumbPosition(this.thumbEls[0], loPct);
|
|
386
|
-
this.thumbEls[0].setAttribute('aria-valuemin', String(min));
|
|
387
|
-
this.thumbEls[0].setAttribute('aria-valuemax', String(hi));
|
|
388
|
-
this.thumbEls[0].setAttribute('aria-valuenow', String(lo));
|
|
389
|
-
}
|
|
390
|
-
if (this.thumbEls[1]) {
|
|
391
|
-
this.setThumbPosition(this.thumbEls[1], hiPct);
|
|
392
|
-
this.thumbEls[1].setAttribute('aria-valuemin', String(lo));
|
|
393
|
-
this.thumbEls[1].setAttribute('aria-valuemax', String(max));
|
|
394
|
-
this.thumbEls[1].setAttribute('aria-valuenow', String(hi));
|
|
395
|
-
}
|
|
396
|
-
const minVal = this.valuesEl?.querySelector(`.${CLASS}__value--min`);
|
|
397
|
-
const maxVal = this.valuesEl?.querySelector(`.${CLASS}__value--max`);
|
|
398
|
-
if (minVal)
|
|
399
|
-
minVal.textContent = this.formatValue(lo);
|
|
400
|
-
if (maxVal)
|
|
401
|
-
maxVal.textContent = this.formatValue(hi);
|
|
402
|
-
}
|
|
403
|
-
else {
|
|
404
|
-
const pct = this.valueToPercent(this.currentValue);
|
|
405
|
-
if (this.hasAttribute('vertical')) {
|
|
406
|
-
this.fillEl.style.left = '';
|
|
407
|
-
this.fillEl.style.width = '';
|
|
408
|
-
this.fillEl.style.bottom = '0';
|
|
409
|
-
this.fillEl.style.height = `${pct}%`;
|
|
410
|
-
}
|
|
411
|
-
else {
|
|
412
|
-
this.fillEl.style.bottom = '';
|
|
413
|
-
this.fillEl.style.height = '';
|
|
414
|
-
this.fillEl.style.left = '0';
|
|
415
|
-
this.fillEl.style.width = `${pct}%`;
|
|
416
|
-
}
|
|
417
|
-
if (this.thumbEls[0]) {
|
|
418
|
-
this.setThumbPosition(this.thumbEls[0], pct);
|
|
419
|
-
this.thumbEls[0].setAttribute('aria-valuemin', String(min));
|
|
420
|
-
this.thumbEls[0].setAttribute('aria-valuemax', String(max));
|
|
421
|
-
this.thumbEls[0].setAttribute('aria-valuenow', String(this.currentValue));
|
|
422
|
-
}
|
|
423
|
-
const singleVal = this.valuesEl?.querySelector(`.${CLASS}__value--single`);
|
|
424
|
-
if (singleVal)
|
|
425
|
-
singleVal.textContent = this.formatValue(this.currentValue);
|
|
426
|
-
}
|
|
427
|
-
this.syncThumbTooltips();
|
|
428
|
-
this.trackEl?.querySelectorAll(`.${CLASS}__mark`).forEach((markEl) => {
|
|
429
|
-
const left = markEl instanceof HTMLElement ? parseFloat(markEl.style.left) : NaN;
|
|
430
|
-
const bottom = markEl instanceof HTMLElement ? parseFloat(markEl.style.bottom) : NaN;
|
|
431
|
-
const percent = Number.isFinite(left) ? left : bottom;
|
|
432
|
-
if (!Number.isFinite(percent))
|
|
433
|
-
return;
|
|
434
|
-
const markValue = this.percentToValue(percent);
|
|
435
|
-
markEl.classList.toggle(`${CLASS}__mark--active`, this.isMarkActive(markValue));
|
|
436
|
-
});
|
|
437
|
-
}
|
|
438
|
-
syncThumbTooltips() {
|
|
439
|
-
const isRange = this.hasAttribute('range');
|
|
440
|
-
const show = this.hasAttribute('show-thumb-tooltip');
|
|
441
|
-
this.thumbEls.forEach((thumb, index) => {
|
|
442
|
-
const tooltip = thumb.querySelector(`.${CLASS}__thumb-tooltip`);
|
|
443
|
-
if (!tooltip)
|
|
444
|
-
return;
|
|
445
|
-
if (!show) {
|
|
446
|
-
tooltip.hidden = true;
|
|
447
|
-
return;
|
|
448
|
-
}
|
|
449
|
-
// 표시 여부는 CSS(hover/focus/active)가 담당하고, 텍스트만 항상 갱신한다.
|
|
450
|
-
tooltip.hidden = false;
|
|
451
|
-
const value = isRange
|
|
452
|
-
? index === 0
|
|
453
|
-
? this.currentRange[0]
|
|
454
|
-
: this.currentRange[1]
|
|
455
|
-
: this.currentValue;
|
|
456
|
-
tooltip.textContent = this.formatValue(value);
|
|
457
|
-
});
|
|
458
|
-
}
|
|
459
|
-
syncA11y() {
|
|
460
|
-
if (!this.containerEl)
|
|
461
|
-
return;
|
|
462
|
-
const min = this.getNumberAttr('min', 0);
|
|
463
|
-
const max = this.getNumberAttr('max', 100);
|
|
464
|
-
const isRange = this.hasAttribute('range');
|
|
465
|
-
const disabled = this.hasAttribute('disabled');
|
|
466
|
-
const readonly = this.hasAttribute('readonly');
|
|
467
|
-
this.containerEl.setAttribute('aria-valuemin', String(min));
|
|
468
|
-
this.containerEl.setAttribute('aria-valuemax', String(max));
|
|
469
|
-
this.containerEl.setAttribute('aria-valuenow', String(isRange ? this.currentRange[0] : this.currentValue));
|
|
470
|
-
this.containerEl.setAttribute('aria-valuetext', isRange
|
|
471
|
-
? `${this.currentRange[0]} to ${this.currentRange[1]}`
|
|
472
|
-
: String(this.currentValue));
|
|
473
|
-
this.containerEl.setAttribute('aria-disabled', String(disabled));
|
|
474
|
-
this.containerEl.setAttribute('aria-readonly', String(readonly));
|
|
475
|
-
this.containerEl.setAttribute('tabindex', disabled || readonly ? '-1' : '0');
|
|
476
|
-
}
|
|
477
|
-
setThumbPosition(thumb, percent) {
|
|
478
|
-
if (this.hasAttribute('vertical')) {
|
|
479
|
-
thumb.style.left = '';
|
|
480
|
-
thumb.style.bottom = `${percent}%`;
|
|
481
|
-
}
|
|
482
|
-
else {
|
|
483
|
-
thumb.style.bottom = '';
|
|
484
|
-
thumb.style.left = `${percent}%`;
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
valueToPercent(value) {
|
|
488
|
-
const min = this.getNumberAttr('min', 0);
|
|
489
|
-
const max = this.getNumberAttr('max', 100);
|
|
490
|
-
if (max === min)
|
|
491
|
-
return 0;
|
|
492
|
-
return ((value - min) / (max - min)) * 100;
|
|
493
|
-
}
|
|
494
|
-
percentToValue(percent) {
|
|
495
|
-
const min = this.getNumberAttr('min', 0);
|
|
496
|
-
const max = this.getNumberAttr('max', 100);
|
|
497
|
-
const step = this.getNumberAttr('step', 1);
|
|
498
|
-
const raw = min + (percent / 100) * (max - min);
|
|
499
|
-
return this.snapToStep(raw, min, max, step);
|
|
500
|
-
}
|
|
501
|
-
snapToStep(value, min, max, step) {
|
|
502
|
-
const stepped = Math.round(value / step) * step;
|
|
503
|
-
return Math.min(max, Math.max(min, stepped));
|
|
504
|
-
}
|
|
505
|
-
clamp(value, min = this.getNumberAttr('min', 0), max = this.getNumberAttr('max', 100), step = this.getNumberAttr('step', 1)) {
|
|
506
|
-
return this.snapToStep(Math.min(max, Math.max(min, value)), min, max, step);
|
|
507
|
-
}
|
|
508
|
-
getNumberAttr(name, fallback) {
|
|
509
|
-
const raw = this.getAttribute(name);
|
|
510
|
-
if (raw === null || raw === '')
|
|
511
|
-
return fallback;
|
|
512
|
-
const n = Number(raw);
|
|
513
|
-
return Number.isFinite(n) ? n : fallback;
|
|
514
|
-
}
|
|
515
|
-
normalizeRangeInput(value) {
|
|
516
|
-
if (typeof value === 'string') {
|
|
517
|
-
return this.parseRangeAttr(value);
|
|
518
|
-
}
|
|
519
|
-
if (!Array.isArray(value) || value.length < 2)
|
|
520
|
-
return null;
|
|
521
|
-
const a = Number(value[0]);
|
|
522
|
-
const b = Number(value[1]);
|
|
523
|
-
if (!Number.isFinite(a) || !Number.isFinite(b))
|
|
524
|
-
return null;
|
|
525
|
-
return [a, b];
|
|
526
|
-
}
|
|
527
|
-
parseRangeAttr(raw) {
|
|
528
|
-
if (!raw)
|
|
529
|
-
return null;
|
|
530
|
-
if (raw.startsWith('[')) {
|
|
531
|
-
try {
|
|
532
|
-
const parsed = JSON.parse(raw);
|
|
533
|
-
if (Array.isArray(parsed) && parsed.length === 2) {
|
|
534
|
-
const a = Number(parsed[0]);
|
|
535
|
-
const b = Number(parsed[1]);
|
|
536
|
-
if (Number.isFinite(a) && Number.isFinite(b))
|
|
537
|
-
return [a, b];
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
catch {
|
|
541
|
-
return null;
|
|
542
|
-
}
|
|
543
|
-
return null;
|
|
544
|
-
}
|
|
545
|
-
const parts = raw.split(',').map((s) => Number(s.trim()));
|
|
546
|
-
if (parts.length !== 2 || parts.some((n) => !Number.isFinite(n)))
|
|
547
|
-
return null;
|
|
548
|
-
return [parts[0], parts[1]];
|
|
549
|
-
}
|
|
550
|
-
parseMarks() {
|
|
551
|
-
const raw = this.getAttribute('marks');
|
|
552
|
-
if (!raw)
|
|
553
|
-
return [];
|
|
554
|
-
if (raw.startsWith('[')) {
|
|
555
|
-
try {
|
|
556
|
-
const parsed = JSON.parse(raw);
|
|
557
|
-
if (Array.isArray(parsed)) {
|
|
558
|
-
return parsed
|
|
559
|
-
.map((n) => Number(n))
|
|
560
|
-
.filter((n) => Number.isFinite(n));
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
catch {
|
|
564
|
-
return [];
|
|
565
|
-
}
|
|
566
|
-
return [];
|
|
567
|
-
}
|
|
568
|
-
return raw
|
|
569
|
-
.split(',')
|
|
570
|
-
.map((s) => Number(s.trim()))
|
|
571
|
-
.filter((n) => Number.isFinite(n));
|
|
572
|
-
}
|
|
573
|
-
parseMarkLabels() {
|
|
574
|
-
const raw = this.getAttribute('mark-labels');
|
|
575
|
-
if (!raw)
|
|
576
|
-
return {};
|
|
577
|
-
try {
|
|
578
|
-
const parsed = JSON.parse(raw);
|
|
579
|
-
const result = {};
|
|
580
|
-
Object.entries(parsed).forEach(([k, v]) => {
|
|
581
|
-
result[Number(k)] = v;
|
|
582
|
-
});
|
|
583
|
-
return result;
|
|
584
|
-
}
|
|
585
|
-
catch {
|
|
586
|
-
return {};
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
isInteractive() {
|
|
590
|
-
return !this.hasAttribute('disabled') && !this.hasAttribute('readonly');
|
|
591
|
-
}
|
|
592
|
-
getTrackPercent(clientX, clientY) {
|
|
593
|
-
if (!this.trackEl)
|
|
594
|
-
return 0;
|
|
595
|
-
const rect = this.trackEl.getBoundingClientRect();
|
|
596
|
-
if (this.hasAttribute('vertical')) {
|
|
597
|
-
const y = Math.max(rect.top, Math.min(rect.bottom, clientY));
|
|
598
|
-
return ((rect.bottom - y) / rect.height) * 100;
|
|
599
|
-
}
|
|
600
|
-
const x = Math.max(rect.left, Math.min(rect.right, clientX));
|
|
601
|
-
return ((x - rect.left) / rect.width) * 100;
|
|
602
|
-
}
|
|
603
|
-
handleThumbPointerDown(e, thumb) {
|
|
604
|
-
if (!this.isInteractive())
|
|
605
|
-
return;
|
|
606
|
-
e.preventDefault();
|
|
607
|
-
this.isDragging = true;
|
|
608
|
-
this.activeThumb = thumb;
|
|
609
|
-
this.setThumbActive(thumb, true);
|
|
610
|
-
document.addEventListener('pointermove', this.boundPointerMove);
|
|
611
|
-
document.addEventListener('pointerup', this.boundPointerUp);
|
|
612
|
-
}
|
|
613
|
-
handleTrackClick(e) {
|
|
614
|
-
if (!this.isInteractive() || !this.trackEl)
|
|
615
|
-
return;
|
|
616
|
-
if (e.target.closest(`.${CLASS}__thumb`))
|
|
617
|
-
return;
|
|
618
|
-
const percent = this.getTrackPercent(e.clientX, e.clientY);
|
|
619
|
-
const value = this.percentToValue(percent);
|
|
620
|
-
this.commitValueAtPosition(value);
|
|
621
|
-
}
|
|
622
|
-
handlePointerMove(e) {
|
|
623
|
-
if (!this.isDragging || !this.isInteractive())
|
|
624
|
-
return;
|
|
625
|
-
const percent = this.getTrackPercent(e.clientX, e.clientY);
|
|
626
|
-
const value = this.percentToValue(percent);
|
|
627
|
-
this.applyDragValue(value);
|
|
628
|
-
}
|
|
629
|
-
handlePointerUp() {
|
|
630
|
-
if (!this.isDragging)
|
|
631
|
-
return;
|
|
632
|
-
if (this.activeThumb) {
|
|
633
|
-
this.setThumbActive(this.activeThumb, false);
|
|
634
|
-
}
|
|
635
|
-
this.isDragging = false;
|
|
636
|
-
this.activeThumb = null;
|
|
637
|
-
document.removeEventListener('pointermove', this.boundPointerMove);
|
|
638
|
-
document.removeEventListener('pointerup', this.boundPointerUp);
|
|
639
|
-
this.syncThumbTooltips();
|
|
640
|
-
if (this.hasAttribute('range')) {
|
|
641
|
-
this.setAttribute('range', `${this.currentRange[0]},${this.currentRange[1]}`);
|
|
642
|
-
}
|
|
643
|
-
else {
|
|
644
|
-
this.setAttribute('value', String(this.currentValue));
|
|
645
|
-
}
|
|
646
|
-
this.syncA11y();
|
|
647
|
-
}
|
|
648
|
-
setThumbActive(thumb, active) {
|
|
649
|
-
if (this.hasAttribute('range')) {
|
|
650
|
-
const el = this.thumbEls[thumb === 'min' ? 0 : 1];
|
|
651
|
-
el?.classList.toggle(`${CLASS}__thumb--active`, active);
|
|
652
|
-
return;
|
|
653
|
-
}
|
|
654
|
-
this.thumbEls[0]?.classList.toggle(`${CLASS}__thumb--active`, active);
|
|
655
|
-
}
|
|
656
|
-
applyDragValue(value) {
|
|
657
|
-
const next = this.clamp(value);
|
|
658
|
-
if (this.hasAttribute('range')) {
|
|
659
|
-
const [lo, hi] = this.currentRange;
|
|
660
|
-
if (this.activeThumb === 'min') {
|
|
661
|
-
this.currentRange = [Math.min(next, hi), hi];
|
|
662
|
-
}
|
|
663
|
-
else if (this.activeThumb === 'max') {
|
|
664
|
-
this.currentRange = [lo, Math.max(next, lo)];
|
|
665
|
-
}
|
|
666
|
-
else {
|
|
667
|
-
const distMin = Math.abs(next - lo);
|
|
668
|
-
const distMax = Math.abs(next - hi);
|
|
669
|
-
if (distMin <= distMax) {
|
|
670
|
-
this.currentRange = [Math.min(next, hi), hi];
|
|
671
|
-
this.activeThumb = 'min';
|
|
672
|
-
}
|
|
673
|
-
else {
|
|
674
|
-
this.currentRange = [lo, Math.max(next, lo)];
|
|
675
|
-
this.activeThumb = 'max';
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
this.syncVisuals();
|
|
679
|
-
this.dispatchRangeChange();
|
|
680
|
-
}
|
|
681
|
-
else {
|
|
682
|
-
this.currentValue = next;
|
|
683
|
-
this.syncVisuals();
|
|
684
|
-
this.syncA11y();
|
|
685
|
-
this.dispatchValueChange();
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
commitValueAtPosition(value) {
|
|
689
|
-
const next = this.clamp(value);
|
|
690
|
-
if (this.hasAttribute('range')) {
|
|
691
|
-
const [lo, hi] = this.currentRange;
|
|
692
|
-
const distMin = Math.abs(next - lo);
|
|
693
|
-
const distMax = Math.abs(next - hi);
|
|
694
|
-
if (distMin <= distMax) {
|
|
695
|
-
this.currentRange = [Math.min(next, hi), hi];
|
|
696
|
-
}
|
|
697
|
-
else {
|
|
698
|
-
this.currentRange = [lo, Math.max(next, lo)];
|
|
699
|
-
}
|
|
700
|
-
this.setAttribute('range', `${this.currentRange[0]},${this.currentRange[1]}`);
|
|
701
|
-
this.syncVisuals();
|
|
702
|
-
this.dispatchRangeChange();
|
|
703
|
-
}
|
|
704
|
-
else {
|
|
705
|
-
this.currentValue = next;
|
|
706
|
-
this.setAttribute('value', String(this.currentValue));
|
|
707
|
-
this.syncVisuals();
|
|
708
|
-
this.syncA11y();
|
|
709
|
-
this.dispatchValueChange();
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
handleKeyDown(e, thumb = 'single') {
|
|
713
|
-
if (!this.isInteractive())
|
|
714
|
-
return;
|
|
715
|
-
const step = this.getNumberAttr('step', 1);
|
|
716
|
-
const min = this.getNumberAttr('min', 0);
|
|
717
|
-
const max = this.getNumberAttr('max', 100);
|
|
718
|
-
let newValue;
|
|
719
|
-
if (this.hasAttribute('range') && thumb !== 'single') {
|
|
720
|
-
const currentThumbValue = thumb === 'min'
|
|
721
|
-
? this.currentRange[0]
|
|
722
|
-
: this.currentRange[1];
|
|
723
|
-
switch (e.key) {
|
|
724
|
-
case 'ArrowLeft':
|
|
725
|
-
case 'ArrowDown':
|
|
726
|
-
newValue = this.clamp(currentThumbValue - step, min, max);
|
|
727
|
-
break;
|
|
728
|
-
case 'ArrowRight':
|
|
729
|
-
case 'ArrowUp':
|
|
730
|
-
newValue = this.clamp(currentThumbValue + step, min, max);
|
|
731
|
-
break;
|
|
732
|
-
case 'Home':
|
|
733
|
-
newValue = min;
|
|
734
|
-
break;
|
|
735
|
-
case 'End':
|
|
736
|
-
newValue = max;
|
|
737
|
-
break;
|
|
738
|
-
default:
|
|
739
|
-
return;
|
|
740
|
-
}
|
|
741
|
-
const next = [...this.currentRange];
|
|
742
|
-
if (thumb === 'min') {
|
|
743
|
-
next[0] = newValue;
|
|
744
|
-
}
|
|
745
|
-
else {
|
|
746
|
-
next[1] = newValue;
|
|
747
|
-
}
|
|
748
|
-
if (next[0] > next[1])
|
|
749
|
-
return;
|
|
750
|
-
e.preventDefault();
|
|
751
|
-
this.currentRange = next;
|
|
752
|
-
this.afterKeyboard();
|
|
753
|
-
return;
|
|
754
|
-
}
|
|
755
|
-
if (this.hasAttribute('range'))
|
|
756
|
-
return;
|
|
757
|
-
switch (e.key) {
|
|
758
|
-
case 'ArrowLeft':
|
|
759
|
-
case 'ArrowDown':
|
|
760
|
-
newValue = this.clamp(this.currentValue - step, min, max);
|
|
761
|
-
break;
|
|
762
|
-
case 'ArrowRight':
|
|
763
|
-
case 'ArrowUp':
|
|
764
|
-
newValue = this.clamp(this.currentValue + step, min, max);
|
|
765
|
-
break;
|
|
766
|
-
case 'Home':
|
|
767
|
-
newValue = min;
|
|
768
|
-
break;
|
|
769
|
-
case 'End':
|
|
770
|
-
newValue = max;
|
|
771
|
-
break;
|
|
772
|
-
default:
|
|
773
|
-
return;
|
|
774
|
-
}
|
|
775
|
-
e.preventDefault();
|
|
776
|
-
this.currentValue = newValue;
|
|
777
|
-
this.afterKeyboard();
|
|
778
|
-
}
|
|
779
|
-
afterKeyboard() {
|
|
780
|
-
if (this.hasAttribute('range')) {
|
|
781
|
-
this.setAttribute('range', `${this.currentRange[0]},${this.currentRange[1]}`);
|
|
782
|
-
this.syncVisuals();
|
|
783
|
-
this.dispatchRangeChange();
|
|
784
|
-
}
|
|
785
|
-
else {
|
|
786
|
-
this.setAttribute('value', String(this.currentValue));
|
|
787
|
-
this.syncVisuals();
|
|
788
|
-
this.syncA11y();
|
|
789
|
-
this.dispatchValueChange();
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
dispatchValueChange() {
|
|
793
|
-
this.dispatchEvent(new CustomEvent('db-change', {
|
|
794
|
-
bubbles: true,
|
|
795
|
-
composed: true,
|
|
796
|
-
detail: { value: this.currentValue },
|
|
797
|
-
}));
|
|
798
|
-
}
|
|
799
|
-
dispatchRangeChange() {
|
|
800
|
-
this.dispatchEvent(new CustomEvent('db-change', {
|
|
801
|
-
bubbles: true,
|
|
802
|
-
composed: true,
|
|
803
|
-
detail: { range: [...this.currentRange] },
|
|
804
|
-
}));
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
if (!customElements.get('db-range-slider')) {
|
|
808
|
-
customElements.define('db-range-slider', DbRangeSlider);
|
|
809
|
-
}
|
|
810
|
-
|
|
811
|
-
export { DbRangeSlider };
|
|
1
|
+
const t="designbase-wc-range-slider";class DbRangeSlider extends HTMLElement{constructor(){super(...arguments),this.built=!1,this.headerEl=null,this.labelEl=null,this.valuesEl=null,this.containerEl=null,this.trackEl=null,this.fillEl=null,this.thumbEls=[],this.currentValue=50,this.currentRange=[25,75],this.isDragging=!1,this.activeThumb=null,this.boundTrackClick=t=>this.handleTrackClick(t),this.boundPointerMove=t=>this.handlePointerMove(t),this.boundPointerUp=()=>this.handlePointerUp(),this.boundContainerKeyDown=t=>this.handleKeyDown(t),this.eventsBound=!1}static get observedAttributes(){return["value","range","min","max","step","size","variant","show-value","show-label","label","value-position","value-fixed","show-thumb-tooltip","show-marks","marks","mark-labels","disabled","readonly","full-width","vertical"]}connectedCallback(){this.built||(this.build(),this.built=!0),this.readAttributeValues(),this.syncClasses(),this.syncDomOrder(),this.syncStructure(),this.syncVisuals(),this.syncA11y(),this.bindEvents()}disconnectedCallback(){this.unbindEvents()}attributeChangedCallback(t){this.built&&(this.readAttributeValues(),this.syncClasses(),this.isStructuralAttribute(t)&&(this.syncDomOrder(),this.syncStructure()),this.syncVisuals(),this.syncA11y())}isStructuralAttribute(t){return["range","show-value","show-label","label","value-position","show-marks","marks","mark-labels","vertical"].includes(t)}get value(){return this.currentValue}set value(t){this.currentValue=this.clamp(t),this.setAttribute("value",String(this.currentValue)),this.syncVisuals()}get range(){if(this.hasAttribute("range"))return[...this.currentRange]}set range(t){if(null==t)return this.removeAttribute("range"),void(this.built&&(this.syncStructure(),this.syncVisuals()));const e=this.normalizeRangeInput(t);if(!e)return;const i=[Math.min(e[0],e[1]),Math.max(e[0],e[1])];this.currentRange=[this.clamp(i[0]),this.clamp(i[1])];const s=`${this.currentRange[0]},${this.currentRange[1]}`;this.getAttribute("range")!==s&&this.setAttribute("range",s),this.built&&this.syncVisuals()}build(){this.classList.add(t),this.headerEl=document.createElement("div"),this.headerEl.className=`${t}__header`,this.labelEl=document.createElement("span"),this.labelEl.className=`${t}__label`,this.valuesEl=document.createElement("div"),this.valuesEl.className=`${t}__values`,this.containerEl=document.createElement("div"),this.containerEl.className=`${t}__container`,this.containerEl.setAttribute("role","slider"),this.containerEl.setAttribute("tabindex","0"),this.trackEl=document.createElement("div"),this.trackEl.className=`${t}__track`,this.fillEl=document.createElement("div"),this.fillEl.className=`${t}__fill`,this.trackEl.appendChild(this.fillEl),this.containerEl.appendChild(this.trackEl)}getValuePosition(){const t=this.getAttribute("value-position");return t||(this.shouldShowLabel()?"top":"right")}shouldShowLabel(){return this.hasAttribute("show-label")&&Boolean(this.getAttribute("label")?.trim())}formatValue(t){const e=this.getAttribute("value-fixed");if(null!==e&&""!==e){const i=Number(e);if(Number.isFinite(i))return t.toFixed(i)}return String(t)}syncDomOrder(){if(!this.headerEl||!this.valuesEl||!this.containerEl)return;const t=this.getValuePosition(),e=this.shouldShowLabel(),i=this.hasAttribute("show-value"),s=this.hasAttribute("range");return this.replaceChildren(),this.labelEl&&(this.labelEl.textContent=this.getAttribute("label")?.trim()||""),s||"top"===t?(this.headerEl.replaceChildren(),e&&this.labelEl&&this.headerEl.appendChild(this.labelEl),i&&this.headerEl.appendChild(this.valuesEl),this.headerEl.childElementCount>0&&this.append(this.headerEl),void this.append(this.containerEl)):"bottom"===t?(e&&this.labelEl&&(this.headerEl.replaceChildren(this.labelEl),this.append(this.headerEl)),this.append(this.containerEl),void(i&&this.append(this.valuesEl))):void(i?this.append(this.valuesEl,this.containerEl):this.append(this.containerEl))}bindEvents(){this.eventsBound||(this.trackEl?.addEventListener("click",this.boundTrackClick),this.containerEl?.addEventListener("keydown",this.boundContainerKeyDown),this.eventsBound=!0)}unbindEvents(){this.eventsBound&&(this.trackEl?.removeEventListener("click",this.boundTrackClick),this.containerEl?.removeEventListener("keydown",this.boundContainerKeyDown),document.removeEventListener("pointermove",this.boundPointerMove),document.removeEventListener("pointerup",this.boundPointerUp),this.eventsBound=!1)}readAttributeValues(){const t=this.getNumberAttr("min",0),e=this.getNumberAttr("max",100),i=this.getNumberAttr("step",1);if(this.hasAttribute("range")){const s=this.parseRangeAttr(this.getAttribute("range"));s?this.currentRange=[this.clamp(s[0],t,e,i),this.clamp(s[1],t,e,i)]:this.currentRange.every(Number.isFinite)||(this.currentRange=[25,75])}else this.currentValue=this.clamp(this.getNumberAttr("value",50),t,e,i)}syncClasses(){const e=this.getAttribute("size")||"m",i=this.getAttribute("variant")||"default",s=this.hasAttribute("range"),r=this.getValuePosition(),a=[t,`${t}--${e}`,`${t}--${i}`,`${t}--value-${s?"top":r}`,this.shouldShowLabel()?`${t}--has-label`:"",this.hasAttribute("disabled")?`${t}--disabled`:"",this.hasAttribute("readonly")?`${t}--readonly`:"",this.hasAttribute("full-width")?`${t}--full-width`:"",this.hasAttribute("vertical")?`${t}--vertical`:"",this.hasAttribute("show-thumb-tooltip")?`${t}--show-tooltip`:"",s?`${t}--range`:""].filter(Boolean);if(this.className=a.join(" "),this.trackEl){const e=[`${t}__track`];this.hasAttribute("disabled")&&e.push(`${t}__track--disabled`),this.hasAttribute("readonly")&&e.push(`${t}__track--readonly`),this.trackEl.className=e.join(" ")}}syncStructure(){if(!this.valuesEl||!this.trackEl||!this.fillEl)return;const e=this.hasAttribute("show-value"),i=this.hasAttribute("range"),s=this.hasAttribute("show-marks");if(this.valuesEl.innerHTML="",this.valuesEl.hidden=!e,e)if(i){const e=document.createElement("span");e.className=`${t}__value ${t}__value--min`;const i=document.createElement("span");i.className=`${t}__value-separator`,i.textContent="~",i.setAttribute("aria-hidden","true");const s=document.createElement("span");s.className=`${t}__value ${t}__value--max`,this.valuesEl.append(e,i,s)}else{const e=document.createElement("span");e.className=`${t}__value ${t}__value--single`,this.valuesEl.appendChild(e)}if(this.thumbEls.forEach(t=>t.remove()),this.thumbEls=[],this.trackEl.querySelectorAll(`.${t}__mark`).forEach(t=>t.remove()),s){const e=this.parseMarks();if(e.length>0){const i=this.parseMarkLabels();e.forEach(e=>{const s=document.createElement("div");if(s.className=`${t}__mark`,s.setAttribute("aria-hidden","true"),this.isMarkActive(e)&&s.classList.add(`${t}__mark--active`),this.hasAttribute("vertical")?s.style.bottom=`${this.valueToPercent(e)}%`:s.style.left=`${this.valueToPercent(e)}%`,void 0!==i[e]){const r=document.createElement("span");r.className=`${t}__mark-label`,r.textContent=i[e],s.appendChild(r)}this.trackEl.insertBefore(s,this.fillEl)})}}const r=i?2:1,a=this.hasAttribute("disabled")||this.hasAttribute("readonly");for(let e=0;e<r;e++){const s=document.createElement("div");s.className=`${t}__thumb`,s.setAttribute("role","slider"),s.setAttribute("draggable","false"),s.setAttribute("tabindex",a?"-1":"0");const r=i?0===e?"min":"max":"single";i&&(s.dataset.thumb=r),s.addEventListener("pointerdown",t=>this.handleThumbPointerDown(t,r)),s.addEventListener("keydown",t=>this.handleKeyDown(t,r));const n=document.createElement("span");n.className=`${t}__thumb-tooltip`,n.setAttribute("aria-hidden","true"),n.hidden=!0,s.appendChild(n),this.trackEl.appendChild(s),this.thumbEls.push(s)}}isMarkActive(t){if(this.hasAttribute("range")){const[e,i]=this.currentRange;return t>=e&&t<=i}return t<=this.currentValue}syncVisuals(){if(!this.fillEl)return;const e=this.hasAttribute("range"),i=this.getNumberAttr("min",0),s=this.getNumberAttr("max",100);if(e){const[e,r]=this.currentRange,a=this.valueToPercent(e),n=this.valueToPercent(r);this.hasAttribute("vertical")?(this.fillEl.style.left="",this.fillEl.style.width="",this.fillEl.style.bottom=`${a}%`,this.fillEl.style.height=n-a+"%"):(this.fillEl.style.bottom="",this.fillEl.style.height="",this.fillEl.style.left=`${a}%`,this.fillEl.style.width=n-a+"%"),this.thumbEls[0]&&(this.setThumbPosition(this.thumbEls[0],a),this.thumbEls[0].setAttribute("aria-valuemin",String(i)),this.thumbEls[0].setAttribute("aria-valuemax",String(r)),this.thumbEls[0].setAttribute("aria-valuenow",String(e))),this.thumbEls[1]&&(this.setThumbPosition(this.thumbEls[1],n),this.thumbEls[1].setAttribute("aria-valuemin",String(e)),this.thumbEls[1].setAttribute("aria-valuemax",String(s)),this.thumbEls[1].setAttribute("aria-valuenow",String(r)));const h=this.valuesEl?.querySelector(`.${t}__value--min`),l=this.valuesEl?.querySelector(`.${t}__value--max`);h&&(h.textContent=this.formatValue(e)),l&&(l.textContent=this.formatValue(r))}else{const e=this.valueToPercent(this.currentValue);this.hasAttribute("vertical")?(this.fillEl.style.left="",this.fillEl.style.width="",this.fillEl.style.bottom="0",this.fillEl.style.height=`${e}%`):(this.fillEl.style.bottom="",this.fillEl.style.height="",this.fillEl.style.left="0",this.fillEl.style.width=`${e}%`),this.thumbEls[0]&&(this.setThumbPosition(this.thumbEls[0],e),this.thumbEls[0].setAttribute("aria-valuemin",String(i)),this.thumbEls[0].setAttribute("aria-valuemax",String(s)),this.thumbEls[0].setAttribute("aria-valuenow",String(this.currentValue)));const r=this.valuesEl?.querySelector(`.${t}__value--single`);r&&(r.textContent=this.formatValue(this.currentValue))}this.syncThumbTooltips(),this.trackEl?.querySelectorAll(`.${t}__mark`).forEach(e=>{const i=e instanceof HTMLElement?parseFloat(e.style.left):NaN,s=e instanceof HTMLElement?parseFloat(e.style.bottom):NaN,r=Number.isFinite(i)?i:s;if(!Number.isFinite(r))return;const a=this.percentToValue(r);e.classList.toggle(`${t}__mark--active`,this.isMarkActive(a))})}syncThumbTooltips(){const e=this.hasAttribute("range"),i=this.hasAttribute("show-thumb-tooltip");this.thumbEls.forEach((s,r)=>{const a=s.querySelector(`.${t}__thumb-tooltip`);if(!a)return;if(!i)return void(a.hidden=!0);a.hidden=!1;const n=e?0===r?this.currentRange[0]:this.currentRange[1]:this.currentValue;a.textContent=this.formatValue(n)})}syncA11y(){if(!this.containerEl)return;const t=this.getNumberAttr("min",0),e=this.getNumberAttr("max",100),i=this.hasAttribute("range"),s=this.hasAttribute("disabled"),r=this.hasAttribute("readonly");this.containerEl.setAttribute("aria-valuemin",String(t)),this.containerEl.setAttribute("aria-valuemax",String(e)),this.containerEl.setAttribute("aria-valuenow",String(i?this.currentRange[0]:this.currentValue)),this.containerEl.setAttribute("aria-valuetext",i?`${this.currentRange[0]} to ${this.currentRange[1]}`:String(this.currentValue)),this.containerEl.setAttribute("aria-disabled",String(s)),this.containerEl.setAttribute("aria-readonly",String(r)),this.containerEl.setAttribute("tabindex",s||r?"-1":"0")}setThumbPosition(t,e){this.hasAttribute("vertical")?(t.style.left="",t.style.bottom=`${e}%`):(t.style.bottom="",t.style.left=`${e}%`)}valueToPercent(t){const e=this.getNumberAttr("min",0),i=this.getNumberAttr("max",100);return i===e?0:(t-e)/(i-e)*100}percentToValue(t){const e=this.getNumberAttr("min",0),i=this.getNumberAttr("max",100),s=this.getNumberAttr("step",1),r=e+t/100*(i-e);return this.snapToStep(r,e,i,s)}snapToStep(t,e,i,s){const r=Math.round(t/s)*s;return Math.min(i,Math.max(e,r))}clamp(t,e=this.getNumberAttr("min",0),i=this.getNumberAttr("max",100),s=this.getNumberAttr("step",1)){return this.snapToStep(Math.min(i,Math.max(e,t)),e,i,s)}getNumberAttr(t,e){const i=this.getAttribute(t);if(null===i||""===i)return e;const s=Number(i);return Number.isFinite(s)?s:e}normalizeRangeInput(t){if("string"==typeof t)return this.parseRangeAttr(t);if(!Array.isArray(t)||t.length<2)return null;const e=Number(t[0]),i=Number(t[1]);return Number.isFinite(e)&&Number.isFinite(i)?[e,i]:null}parseRangeAttr(t){if(!t)return null;if(t.startsWith("[")){try{const e=JSON.parse(t);if(Array.isArray(e)&&2===e.length){const t=Number(e[0]),i=Number(e[1]);if(Number.isFinite(t)&&Number.isFinite(i))return[t,i]}}catch{return null}return null}const e=t.split(",").map(t=>Number(t.trim()));return 2!==e.length||e.some(t=>!Number.isFinite(t))?null:[e[0],e[1]]}parseMarks(){const t=this.getAttribute("marks");if(!t)return[];if(t.startsWith("[")){try{const e=JSON.parse(t);if(Array.isArray(e))return e.map(t=>Number(t)).filter(t=>Number.isFinite(t))}catch{return[]}return[]}return t.split(",").map(t=>Number(t.trim())).filter(t=>Number.isFinite(t))}parseMarkLabels(){const t=this.getAttribute("mark-labels");if(!t)return{};try{const e=JSON.parse(t),i={};return Object.entries(e).forEach(([t,e])=>{i[Number(t)]=e}),i}catch{return{}}}isInteractive(){return!this.hasAttribute("disabled")&&!this.hasAttribute("readonly")}getTrackPercent(t,e){if(!this.trackEl)return 0;const i=this.trackEl.getBoundingClientRect();if(this.hasAttribute("vertical")){const t=Math.max(i.top,Math.min(i.bottom,e));return(i.bottom-t)/i.height*100}return(Math.max(i.left,Math.min(i.right,t))-i.left)/i.width*100}handleThumbPointerDown(t,e){this.isInteractive()&&(t.preventDefault(),this.isDragging=!0,this.activeThumb=e,this.setThumbActive(e,!0),document.addEventListener("pointermove",this.boundPointerMove),document.addEventListener("pointerup",this.boundPointerUp))}handleTrackClick(e){if(!this.isInteractive()||!this.trackEl)return;if(e.target.closest(`.${t}__thumb`))return;const i=this.getTrackPercent(e.clientX,e.clientY),s=this.percentToValue(i);this.commitValueAtPosition(s)}handlePointerMove(t){if(!this.isDragging||!this.isInteractive())return;const e=this.getTrackPercent(t.clientX,t.clientY),i=this.percentToValue(e);this.applyDragValue(i)}handlePointerUp(){this.isDragging&&(this.activeThumb&&this.setThumbActive(this.activeThumb,!1),this.isDragging=!1,this.activeThumb=null,document.removeEventListener("pointermove",this.boundPointerMove),document.removeEventListener("pointerup",this.boundPointerUp),this.syncThumbTooltips(),this.hasAttribute("range")?this.setAttribute("range",`${this.currentRange[0]},${this.currentRange[1]}`):this.setAttribute("value",String(this.currentValue)),this.syncA11y())}setThumbActive(e,i){if(this.hasAttribute("range")){const s=this.thumbEls["min"===e?0:1];return void s?.classList.toggle(`${t}__thumb--active`,i)}this.thumbEls[0]?.classList.toggle(`${t}__thumb--active`,i)}applyDragValue(t){const e=this.clamp(t);if(this.hasAttribute("range")){const[t,i]=this.currentRange;if("min"===this.activeThumb)this.currentRange=[Math.min(e,i),i];else if("max"===this.activeThumb)this.currentRange=[t,Math.max(e,t)];else{Math.abs(e-t)<=Math.abs(e-i)?(this.currentRange=[Math.min(e,i),i],this.activeThumb="min"):(this.currentRange=[t,Math.max(e,t)],this.activeThumb="max")}this.syncVisuals(),this.dispatchRangeChange()}else this.currentValue=e,this.syncVisuals(),this.syncA11y(),this.dispatchValueChange()}commitValueAtPosition(t){const e=this.clamp(t);if(this.hasAttribute("range")){const[t,i]=this.currentRange,s=Math.abs(e-t),r=Math.abs(e-i);this.currentRange=s<=r?[Math.min(e,i),i]:[t,Math.max(e,t)],this.setAttribute("range",`${this.currentRange[0]},${this.currentRange[1]}`),this.syncVisuals(),this.dispatchRangeChange()}else this.currentValue=e,this.setAttribute("value",String(this.currentValue)),this.syncVisuals(),this.syncA11y(),this.dispatchValueChange()}handleKeyDown(t,e="single"){if(!this.isInteractive())return;const i=this.getNumberAttr("step",1),s=this.getNumberAttr("min",0),r=this.getNumberAttr("max",100);let a;if(this.hasAttribute("range")&&"single"!==e){const n="min"===e?this.currentRange[0]:this.currentRange[1];switch(t.key){case"ArrowLeft":case"ArrowDown":a=this.clamp(n-i,s,r);break;case"ArrowRight":case"ArrowUp":a=this.clamp(n+i,s,r);break;case"Home":a=s;break;case"End":a=r;break;default:return}const h=[...this.currentRange];if("min"===e?h[0]=a:h[1]=a,h[0]>h[1])return;return t.preventDefault(),this.currentRange=h,void this.afterKeyboard()}if(!this.hasAttribute("range")){switch(t.key){case"ArrowLeft":case"ArrowDown":a=this.clamp(this.currentValue-i,s,r);break;case"ArrowRight":case"ArrowUp":a=this.clamp(this.currentValue+i,s,r);break;case"Home":a=s;break;case"End":a=r;break;default:return}t.preventDefault(),this.currentValue=a,this.afterKeyboard()}}afterKeyboard(){this.hasAttribute("range")?(this.setAttribute("range",`${this.currentRange[0]},${this.currentRange[1]}`),this.syncVisuals(),this.dispatchRangeChange()):(this.setAttribute("value",String(this.currentValue)),this.syncVisuals(),this.syncA11y(),this.dispatchValueChange())}dispatchValueChange(){this.dispatchEvent(new CustomEvent("db-change",{bubbles:!0,composed:!0,detail:{value:this.currentValue}}))}dispatchRangeChange(){this.dispatchEvent(new CustomEvent("db-change",{bubbles:!0,composed:!0,detail:{range:[...this.currentRange]}}))}}customElements.get("db-range-slider")||customElements.define("db-range-slider",DbRangeSlider);export{DbRangeSlider};
|