@dodlhuat/basix 1.2.0 → 1.2.2
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/README.md +266 -6
- package/css/accordion.scss +86 -87
- package/css/alert.scss +137 -137
- package/css/button.scss +48 -0
- package/css/calendar.scss +957 -0
- package/css/card.scss +65 -65
- package/css/chart.scss +270 -157
- package/css/chat-bubbles.scss +134 -68
- package/css/chips.scss +109 -19
- package/css/colors.scss +32 -32
- package/css/datepicker.scss +336 -336
- package/css/defaults.scss +90 -90
- package/css/docs.scss +529 -0
- package/css/editor.scss +36 -0
- package/css/file-uploader.scss +1 -1
- package/css/flyout-menu.scss +361 -361
- package/css/form.scss +0 -15
- package/css/gallery.scss +65 -6
- package/css/grid.scss +41 -40
- package/css/group-picker.scss +345 -0
- package/css/guitar-chords.css +250 -250
- package/css/icons.scss +330 -330
- package/css/parameters.scss +3 -3
- package/css/placeholder.scss +33 -33
- package/css/popover.scss +206 -0
- package/css/progress.scss +76 -32
- package/css/properties.scss +51 -36
- package/css/push-menu.scss +302 -174
- package/css/reset.scss +39 -39
- package/css/scrollbar.scss +62 -5
- package/css/sidebar-nav.scss +92 -0
- package/css/spinner.scss +65 -65
- package/css/stepper.scss +48 -12
- package/css/style.css +3155 -254
- package/css/style.css.map +1 -1
- package/css/style.min.css +1 -1
- package/css/style.scss +51 -45
- package/css/table.scss +199 -199
- package/css/tabs.scss +154 -123
- package/css/timeline.scss +83 -38
- package/css/timepicker.scss +100 -5
- package/css/toast.scss +81 -81
- package/css/virtual-dropdown.scss +35 -29
- package/js/calendar.js +532 -0
- package/js/calendar.ts +706 -0
- package/js/chart.js +573 -257
- package/js/chart.ts +692 -0
- package/js/code-viewer.js +10 -10
- package/js/code-viewer.ts +188 -188
- package/js/datepicker.ts +627 -627
- package/js/docs-nav.js +204 -0
- package/js/dropdown.ts +179 -179
- package/js/editor.js +50 -6
- package/js/editor.ts +483 -444
- package/js/file-uploader.js +1 -0
- package/js/file-uploader.ts +1 -0
- package/js/flyout-menu.js +14 -14
- package/js/flyout-menu.ts +249 -249
- package/js/form-builder.js +106 -106
- package/js/gallery.js +14 -8
- package/js/gallery.ts +245 -236
- package/js/group-picker.js +342 -0
- package/js/group-picker.ts +447 -0
- package/js/guitar-chords.js +268 -268
- package/js/lazy-loader.js +121 -121
- package/js/modal.ts +166 -166
- package/js/popover.js +163 -0
- package/js/popover.ts +219 -0
- package/js/position.js +108 -0
- package/js/position.ts +111 -0
- package/js/push-menu.js +113 -0
- package/js/push-menu.ts +284 -145
- package/js/request.js +50 -50
- package/js/scroll.ts +47 -47
- package/js/scrollbar.js +13 -0
- package/js/scrollbar.ts +324 -307
- package/js/select.ts +216 -216
- package/js/sidebar-nav.js +41 -0
- package/js/sidebar-nav.ts +66 -0
- package/js/table.ts +452 -452
- package/js/tabs.ts +279 -279
- package/js/theme.js +17 -6
- package/js/theme.ts +234 -224
- package/js/toast.ts +137 -137
- package/js/tooltip.js +6 -60
- package/js/tooltip.ts +184 -251
- package/js/tsconfig.json +18 -18
- package/js/utils.ts +83 -83
- package/js/virtual-dropdown.js +25 -25
- package/js/virtual-dropdown.ts +365 -365
- package/package.json +37 -39
- package/js/index.js +0 -816
- package/js/index.ts +0 -987
package/js/scrollbar.ts
CHANGED
|
@@ -1,308 +1,325 @@
|
|
|
1
|
-
interface ScrollbarElements {
|
|
2
|
-
viewport: HTMLElement;
|
|
3
|
-
content: HTMLElement;
|
|
4
|
-
track: HTMLElement;
|
|
5
|
-
thumb: HTMLElement;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
class Scrollbar {
|
|
9
|
-
private static readonly instances = new WeakMap<HTMLElement, Scrollbar>();
|
|
10
|
-
private static activeInstance: Scrollbar | null = null;
|
|
11
|
-
private static globalListenersInstalled = false;
|
|
12
|
-
|
|
13
|
-
private readonly container!: HTMLElement;
|
|
14
|
-
private readonly viewport!: HTMLElement;
|
|
15
|
-
private readonly content!: HTMLElement;
|
|
16
|
-
private readonly track!: HTMLElement;
|
|
17
|
-
private readonly thumb!: HTMLElement;
|
|
18
|
-
private readonly MIN_THUMB_HEIGHT!: number;
|
|
19
|
-
private readonly ro!: ResizeObserver;
|
|
20
|
-
|
|
21
|
-
private dragging = false;
|
|
22
|
-
private activePointerId: number | null = null;
|
|
23
|
-
private startPointerY = 0;
|
|
24
|
-
private startThumbTop = 0;
|
|
25
|
-
|
|
26
|
-
// Bound methods for event handling
|
|
27
|
-
private readonly boundPointerMove!: (e: PointerEvent) => void;
|
|
28
|
-
private readonly boundPointerUp!: (e: PointerEvent) => void;
|
|
29
|
-
private readonly boundThumbPointerDown!: (e: PointerEvent) => void;
|
|
30
|
-
private readonly boundTrackClick!: (e: MouseEvent) => void;
|
|
31
|
-
private readonly boundViewportScroll!: () => void;
|
|
32
|
-
private readonly boundUpdateThumb!: () => void;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
this.
|
|
55
|
-
this.
|
|
56
|
-
this.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
this.
|
|
64
|
-
this.
|
|
65
|
-
this.
|
|
66
|
-
this.
|
|
67
|
-
this.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
this.
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
this.
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
this.
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
const
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
const
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
const
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
1
|
+
interface ScrollbarElements {
|
|
2
|
+
viewport: HTMLElement;
|
|
3
|
+
content: HTMLElement;
|
|
4
|
+
track: HTMLElement;
|
|
5
|
+
thumb: HTMLElement;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
class Scrollbar {
|
|
9
|
+
private static readonly instances = new WeakMap<HTMLElement, Scrollbar>();
|
|
10
|
+
private static activeInstance: Scrollbar | null = null;
|
|
11
|
+
private static globalListenersInstalled = false;
|
|
12
|
+
|
|
13
|
+
private readonly container!: HTMLElement;
|
|
14
|
+
private readonly viewport!: HTMLElement;
|
|
15
|
+
private readonly content!: HTMLElement;
|
|
16
|
+
private readonly track!: HTMLElement;
|
|
17
|
+
private readonly thumb!: HTMLElement;
|
|
18
|
+
private readonly MIN_THUMB_HEIGHT!: number;
|
|
19
|
+
private readonly ro!: ResizeObserver;
|
|
20
|
+
|
|
21
|
+
private dragging = false;
|
|
22
|
+
private activePointerId: number | null = null;
|
|
23
|
+
private startPointerY = 0;
|
|
24
|
+
private startThumbTop = 0;
|
|
25
|
+
|
|
26
|
+
// Bound methods for event handling
|
|
27
|
+
private readonly boundPointerMove!: (e: PointerEvent) => void;
|
|
28
|
+
private readonly boundPointerUp!: (e: PointerEvent) => void;
|
|
29
|
+
private readonly boundThumbPointerDown!: (e: PointerEvent) => void;
|
|
30
|
+
private readonly boundTrackClick!: (e: MouseEvent) => void;
|
|
31
|
+
private readonly boundViewportScroll!: () => void;
|
|
32
|
+
private readonly boundUpdateThumb!: () => void;
|
|
33
|
+
private readonly boundContainerWheel!: (e: WheelEvent) => void;
|
|
34
|
+
|
|
35
|
+
constructor(elementOrSelector: string | HTMLElement) {
|
|
36
|
+
const container = typeof elementOrSelector === 'string'
|
|
37
|
+
? document.querySelector<HTMLElement>(elementOrSelector)
|
|
38
|
+
: elementOrSelector;
|
|
39
|
+
|
|
40
|
+
if (!container) {
|
|
41
|
+
throw new Error(`Scrollbar: Element not found for selector "${elementOrSelector}"`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Return existing instance if already initialized
|
|
45
|
+
const existingInstance = Scrollbar.instances.get(container);
|
|
46
|
+
if (existingInstance) {
|
|
47
|
+
return existingInstance as any;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
this.container = container;
|
|
51
|
+
|
|
52
|
+
// Query and validate required elements
|
|
53
|
+
const elements = this.getRequiredElements(container);
|
|
54
|
+
this.viewport = elements.viewport;
|
|
55
|
+
this.content = elements.content;
|
|
56
|
+
this.track = elements.track;
|
|
57
|
+
this.thumb = elements.thumb;
|
|
58
|
+
|
|
59
|
+
// Get minimum thumb height from CSS variable or use default
|
|
60
|
+
this.MIN_THUMB_HEIGHT = this.getMinThumbHeight();
|
|
61
|
+
|
|
62
|
+
// Bind all event handlers once
|
|
63
|
+
this.boundPointerMove = this.handlePointerMove.bind(this);
|
|
64
|
+
this.boundPointerUp = this.handlePointerUp.bind(this);
|
|
65
|
+
this.boundThumbPointerDown = this.handleThumbPointerDown.bind(this);
|
|
66
|
+
this.boundTrackClick = this.handleTrackClick.bind(this);
|
|
67
|
+
this.boundViewportScroll = this.updateThumb.bind(this);
|
|
68
|
+
this.boundUpdateThumb = this.updateThumb.bind(this);
|
|
69
|
+
this.boundContainerWheel = this.handleContainerWheel.bind(this);
|
|
70
|
+
|
|
71
|
+
// Setup ResizeObserver
|
|
72
|
+
this.ro = new ResizeObserver(this.boundUpdateThumb);
|
|
73
|
+
|
|
74
|
+
// Initialize
|
|
75
|
+
this.attachEventListeners();
|
|
76
|
+
Scrollbar.instances.set(container, this);
|
|
77
|
+
|
|
78
|
+
// Install global listeners once for all instances
|
|
79
|
+
if (!Scrollbar.globalListenersInstalled) {
|
|
80
|
+
Scrollbar.installGlobalListeners();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Initial thumb update
|
|
84
|
+
requestAnimationFrame(this.boundUpdateThumb);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private getRequiredElements(container: HTMLElement): ScrollbarElements {
|
|
88
|
+
const viewport = container.querySelector<HTMLElement>('.viewport');
|
|
89
|
+
const content = container.querySelector<HTMLElement>('.content');
|
|
90
|
+
const track = container.querySelector<HTMLElement>('.track');
|
|
91
|
+
const thumb = container.querySelector<HTMLElement>('.thumb');
|
|
92
|
+
|
|
93
|
+
if (!viewport || !content || !track || !thumb) {
|
|
94
|
+
throw new Error(
|
|
95
|
+
'Required scrollbar elements not found. Expected: .viewport, .content, .track, .thumb'
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return { viewport, content, track, thumb };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
private getMinThumbHeight(): number {
|
|
103
|
+
const cssValue = getComputedStyle(document.documentElement)
|
|
104
|
+
.getPropertyValue('--thumb-min')
|
|
105
|
+
.trim();
|
|
106
|
+
|
|
107
|
+
const parsed = parseInt(cssValue, 10);
|
|
108
|
+
const defaultMin = 28;
|
|
109
|
+
const absoluteMin = 16;
|
|
110
|
+
|
|
111
|
+
return Math.max(absoluteMin, parsed || defaultMin);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
private static installGlobalListeners(): void {
|
|
115
|
+
// Route pointer events to the active scrollbar instance
|
|
116
|
+
document.addEventListener('pointermove', (e: PointerEvent) => {
|
|
117
|
+
Scrollbar.activeInstance?.boundPointerMove(e);
|
|
118
|
+
}, { passive: false });
|
|
119
|
+
|
|
120
|
+
document.addEventListener('pointerup', (e: PointerEvent) => {
|
|
121
|
+
Scrollbar.activeInstance?.boundPointerUp(e);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
document.addEventListener('pointercancel', (e: PointerEvent) => {
|
|
125
|
+
Scrollbar.activeInstance?.boundPointerUp(e);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
Scrollbar.globalListenersInstalled = true;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
private attachEventListeners(): void {
|
|
132
|
+
// Instance-specific events
|
|
133
|
+
this.viewport.addEventListener('scroll', this.boundViewportScroll, { passive: true });
|
|
134
|
+
this.thumb.addEventListener('pointerdown', this.boundThumbPointerDown);
|
|
135
|
+
this.track.addEventListener('click', this.boundTrackClick);
|
|
136
|
+
this.container.addEventListener('wheel', this.boundContainerWheel, { passive: false });
|
|
137
|
+
|
|
138
|
+
// Observe size changes
|
|
139
|
+
this.ro.observe(this.viewport);
|
|
140
|
+
this.ro.observe(this.content);
|
|
141
|
+
window.addEventListener('resize', this.boundUpdateThumb);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private updateThumb(): void {
|
|
145
|
+
const viewportHeight = this.viewport.clientHeight;
|
|
146
|
+
const contentHeight = this.content.scrollHeight;
|
|
147
|
+
const trackHeight = this.track.clientHeight;
|
|
148
|
+
|
|
149
|
+
// Hide thumb if content fits in viewport
|
|
150
|
+
if (contentHeight <= viewportHeight + 1) {
|
|
151
|
+
this.thumb.style.display = 'none';
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
this.thumb.style.display = '';
|
|
156
|
+
|
|
157
|
+
// Calculate thumb size
|
|
158
|
+
const ratio = viewportHeight / contentHeight;
|
|
159
|
+
const thumbHeight = Math.max(
|
|
160
|
+
Math.floor(ratio * trackHeight),
|
|
161
|
+
this.MIN_THUMB_HEIGHT
|
|
162
|
+
);
|
|
163
|
+
this.thumb.style.height = `${thumbHeight}px`;
|
|
164
|
+
|
|
165
|
+
// Calculate thumb position
|
|
166
|
+
const maxScroll = contentHeight - viewportHeight;
|
|
167
|
+
const maxThumbTop = trackHeight - thumbHeight;
|
|
168
|
+
const scrollRatio = this.viewport.scrollTop / (maxScroll || 1);
|
|
169
|
+
const thumbTop = scrollRatio * (maxThumbTop || 0);
|
|
170
|
+
|
|
171
|
+
this.thumb.style.top = `${thumbTop}px`;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
private handleThumbPointerDown(e: PointerEvent): void {
|
|
175
|
+
e.preventDefault();
|
|
176
|
+
|
|
177
|
+
this.dragging = true;
|
|
178
|
+
this.activePointerId = e.pointerId;
|
|
179
|
+
Scrollbar.activeInstance = this;
|
|
180
|
+
|
|
181
|
+
// Capture pointer for reliable tracking
|
|
182
|
+
try {
|
|
183
|
+
this.thumb.setPointerCapture(e.pointerId);
|
|
184
|
+
} catch (err) {
|
|
185
|
+
console.warn('Failed to capture pointer:', err);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
this.startPointerY = e.clientY;
|
|
189
|
+
|
|
190
|
+
const thumbRect = this.thumb.getBoundingClientRect();
|
|
191
|
+
const trackRect = this.track.getBoundingClientRect();
|
|
192
|
+
this.startThumbTop = thumbRect.top - trackRect.top;
|
|
193
|
+
|
|
194
|
+
// Prevent text selection during drag
|
|
195
|
+
document.body.style.userSelect = 'none';
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
private handlePointerMove(e: PointerEvent): void {
|
|
199
|
+
// Only handle events for the active pointer
|
|
200
|
+
if (!this.dragging || this.activePointerId !== e.pointerId) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
e.preventDefault();
|
|
205
|
+
|
|
206
|
+
const pointerDelta = e.clientY - this.startPointerY;
|
|
207
|
+
const trackHeight = this.track.clientHeight;
|
|
208
|
+
const thumbHeight = this.thumb.clientHeight;
|
|
209
|
+
const maxThumbTop = trackHeight - thumbHeight;
|
|
210
|
+
|
|
211
|
+
// Calculate new thumb position
|
|
212
|
+
const newThumbTop = Math.max(
|
|
213
|
+
0,
|
|
214
|
+
Math.min(maxThumbTop, this.startThumbTop + pointerDelta)
|
|
215
|
+
);
|
|
216
|
+
this.thumb.style.top = `${newThumbTop}px`;
|
|
217
|
+
|
|
218
|
+
// Update viewport scroll position
|
|
219
|
+
const contentHeight = this.content.scrollHeight;
|
|
220
|
+
const viewportHeight = this.viewport.clientHeight;
|
|
221
|
+
const maxScroll = contentHeight - viewportHeight;
|
|
222
|
+
const scrollRatio = newThumbTop / (maxThumbTop || 1);
|
|
223
|
+
|
|
224
|
+
this.viewport.scrollTop = scrollRatio * (maxScroll || 0);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
private handlePointerUp(e: PointerEvent): void {
|
|
228
|
+
if (!this.dragging || this.activePointerId !== e.pointerId) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
this.dragging = false;
|
|
233
|
+
|
|
234
|
+
// Release pointer capture
|
|
235
|
+
try {
|
|
236
|
+
this.thumb.releasePointerCapture(e.pointerId);
|
|
237
|
+
} catch (err) {
|
|
238
|
+
console.warn('Failed to release pointer:', err);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
this.activePointerId = null;
|
|
242
|
+
Scrollbar.activeInstance = null;
|
|
243
|
+
document.body.style.userSelect = '';
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
private handleTrackClick(e: MouseEvent): void {
|
|
247
|
+
// Ignore clicks directly on the thumb
|
|
248
|
+
if (e.target === this.thumb) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const trackRect = this.track.getBoundingClientRect();
|
|
253
|
+
const clickY = e.clientY - trackRect.top;
|
|
254
|
+
const thumbHeight = this.thumb.clientHeight;
|
|
255
|
+
const trackHeight = this.track.clientHeight;
|
|
256
|
+
|
|
257
|
+
// Center thumb on click position
|
|
258
|
+
const targetThumbTop = clickY - thumbHeight / 2;
|
|
259
|
+
const maxThumbTop = trackHeight - thumbHeight;
|
|
260
|
+
const clampedThumbTop = Math.max(0, Math.min(maxThumbTop, targetThumbTop));
|
|
261
|
+
|
|
262
|
+
// Calculate corresponding scroll position
|
|
263
|
+
const contentHeight = this.content.scrollHeight;
|
|
264
|
+
const viewportHeight = this.viewport.clientHeight;
|
|
265
|
+
const maxScroll = contentHeight - viewportHeight;
|
|
266
|
+
const scrollRatio = clampedThumbTop / (maxThumbTop || 1);
|
|
267
|
+
const scrollTop = scrollRatio * (maxScroll || 0);
|
|
268
|
+
|
|
269
|
+
this.viewport.scrollTo({ top: scrollTop, behavior: 'smooth' });
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
private handleContainerWheel(e: WheelEvent): void {
|
|
273
|
+
const { scrollTop, scrollHeight, clientHeight } = this.viewport;
|
|
274
|
+
const scrollable = scrollHeight > clientHeight;
|
|
275
|
+
const atTop = scrollTop === 0 && e.deltaY < 0;
|
|
276
|
+
const atBottom = scrollTop + clientHeight >= scrollHeight - 1 && e.deltaY > 0;
|
|
277
|
+
|
|
278
|
+
if (scrollable && !atTop && !atBottom) {
|
|
279
|
+
e.preventDefault();
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
this.viewport.scrollTop += e.deltaY;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
public destroy(): void {
|
|
286
|
+
// Remove event listeners
|
|
287
|
+
this.viewport.removeEventListener('scroll', this.boundViewportScroll);
|
|
288
|
+
this.thumb.removeEventListener('pointerdown', this.boundThumbPointerDown);
|
|
289
|
+
this.track.removeEventListener('click', this.boundTrackClick);
|
|
290
|
+
this.container.removeEventListener('wheel', this.boundContainerWheel);
|
|
291
|
+
window.removeEventListener('resize', this.boundUpdateThumb);
|
|
292
|
+
|
|
293
|
+
// Disconnect observer
|
|
294
|
+
this.ro.disconnect();
|
|
295
|
+
|
|
296
|
+
// Clear from instances map
|
|
297
|
+
Scrollbar.instances.delete(this.container);
|
|
298
|
+
|
|
299
|
+
// Clear active instance if this was it
|
|
300
|
+
if (Scrollbar.activeInstance === this) {
|
|
301
|
+
Scrollbar.activeInstance = null;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// Static factory methods
|
|
306
|
+
public static initAll(selector: string): Scrollbar[] {
|
|
307
|
+
const containers = document.querySelectorAll<HTMLElement>(selector);
|
|
308
|
+
return Array.from(containers).map(container => new Scrollbar(container));
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
public static initOne(elementOrSelector: string | HTMLElement): Scrollbar {
|
|
312
|
+
return new Scrollbar(elementOrSelector);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
public static getInstance(container: HTMLElement): Scrollbar | undefined {
|
|
316
|
+
return Scrollbar.instances.get(container);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
public static destroyAll(): void {
|
|
320
|
+
// Note: WeakMap doesn't support iteration, so this is a no-op
|
|
321
|
+
// Individual instances should be destroyed by calling destroy()
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
308
325
|
export { Scrollbar, ScrollbarElements };
|