@dodlhuat/basix 1.2.7 → 1.2.9
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 +1 -1
- package/js/bottom-sheet.d.ts +37 -0
- package/js/calendar.d.ts +115 -0
- package/js/carousel.d.ts +34 -0
- package/js/chart.d.ts +73 -0
- package/js/code-viewer.d.ts +16 -0
- package/js/context-menu.d.ts +31 -0
- package/js/datepicker.d.ts +55 -0
- package/js/dropdown.d.ts +30 -0
- package/js/editor.d.ts +41 -0
- package/js/file-uploader.d.ts +48 -0
- package/js/flyout-menu.d.ts +37 -0
- package/js/gallery.d.ts +35 -0
- package/js/group-picker.d.ts +59 -0
- package/js/lightbox.d.ts +46 -0
- package/js/modal.d.ts +28 -0
- package/js/popover.d.ts +46 -0
- package/js/position.d.ts +31 -0
- package/js/push-menu.d.ts +31 -0
- package/js/range-slider.d.ts +9 -0
- package/js/scroll.d.ts +15 -0
- package/js/scrollbar.d.ts +48 -0
- package/js/select.d.ts +16 -0
- package/js/sidebar-nav.d.ts +22 -0
- package/js/stepper.d.ts +26 -0
- package/js/table.d.ts +98 -0
- package/js/tabs.d.ts +57 -0
- package/js/theme.d.ts +65 -0
- package/js/timepicker.d.ts +37 -0
- package/js/toast.d.ts +26 -0
- package/js/tooltip.d.ts +34 -0
- package/js/tree.d.ts +40 -0
- package/js/utils.d.ts +24 -0
- package/js/virtual-dropdown.d.ts +55 -0
- package/package.json +1 -1
- package/js/bottom-sheet.ts +0 -224
- package/js/calendar.ts +0 -774
- package/js/carousel.ts +0 -222
- package/js/chart.ts +0 -694
- package/js/code-viewer.ts +0 -188
- package/js/context-menu.ts +0 -252
- package/js/datepicker.ts +0 -640
- package/js/dropdown.ts +0 -180
- package/js/editor.ts +0 -492
- package/js/file-uploader.ts +0 -361
- package/js/flyout-menu.ts +0 -255
- package/js/gallery.ts +0 -237
- package/js/group-picker.ts +0 -451
- package/js/lightbox.ts +0 -333
- package/js/modal.ts +0 -171
- package/js/popover.ts +0 -221
- package/js/position.ts +0 -111
- package/js/push-menu.ts +0 -286
- package/js/range-slider.ts +0 -33
- package/js/scroll.ts +0 -47
- package/js/scrollbar.ts +0 -335
- package/js/select.ts +0 -235
- package/js/sidebar-nav.ts +0 -66
- package/js/stepper.ts +0 -109
- package/js/table.ts +0 -459
- package/js/tabs.ts +0 -280
- package/js/theme.ts +0 -235
- package/js/timepicker.ts +0 -202
- package/js/toast.ts +0 -134
- package/js/tooltip.ts +0 -196
- package/js/tree.ts +0 -244
- package/js/tsconfig.json +0 -18
- package/js/utils.ts +0 -119
- package/js/virtual-dropdown.ts +0 -396
package/js/carousel.ts
DELETED
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
interface CarouselOptions {
|
|
2
|
-
loop?: boolean;
|
|
3
|
-
autoPlay?: boolean;
|
|
4
|
-
autoPlayInterval?: number;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
class Carousel {
|
|
8
|
-
private root: HTMLElement;
|
|
9
|
-
private options: CarouselOptions;
|
|
10
|
-
private track!: HTMLUListElement;
|
|
11
|
-
private slides!: HTMLElement[];
|
|
12
|
-
private slideWidth!: number;
|
|
13
|
-
private currentIndex!: number;
|
|
14
|
-
private prevButton!: HTMLButtonElement;
|
|
15
|
-
private nextButton!: HTMLButtonElement;
|
|
16
|
-
private dotsNav!: HTMLDivElement;
|
|
17
|
-
private dots!: HTMLButtonElement[];
|
|
18
|
-
private autoPlayTimer: number | null = null;
|
|
19
|
-
private abortController = new AbortController();
|
|
20
|
-
|
|
21
|
-
constructor(elementOrSelector: string | HTMLElement, options: CarouselOptions = {}) {
|
|
22
|
-
const element = typeof elementOrSelector === 'string'
|
|
23
|
-
? document.querySelector<HTMLElement>(elementOrSelector)
|
|
24
|
-
: elementOrSelector;
|
|
25
|
-
|
|
26
|
-
this.options = {
|
|
27
|
-
loop: options.loop ?? false,
|
|
28
|
-
autoPlay: options.autoPlay ?? false,
|
|
29
|
-
autoPlayInterval: options.autoPlayInterval ?? 3000
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
if (!element) {
|
|
33
|
-
throw new Error(`Carousel: Element not found for selector "${elementOrSelector}"`);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
this.root = element;
|
|
37
|
-
this.init();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
private init(): void {
|
|
41
|
-
this.setupDOM();
|
|
42
|
-
this.slides = Array.from(this.track.children) as HTMLElement[];
|
|
43
|
-
this.slideWidth = this.slides[0].getBoundingClientRect().width;
|
|
44
|
-
this.currentIndex = 0;
|
|
45
|
-
this.bindEvents();
|
|
46
|
-
this.updateDots(0);
|
|
47
|
-
if (this.options.autoPlay) {
|
|
48
|
-
this.startAutoPlay();
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
private setupDOM(): void {
|
|
53
|
-
const slides = Array.from(this.root.children) as HTMLElement[];
|
|
54
|
-
const container = document.createElement('div');
|
|
55
|
-
container.classList.add('carousel-track-container');
|
|
56
|
-
|
|
57
|
-
this.track = document.createElement('ul');
|
|
58
|
-
this.track.classList.add('carousel-track');
|
|
59
|
-
|
|
60
|
-
slides.forEach(slide => {
|
|
61
|
-
slide.classList.add('carousel-slide');
|
|
62
|
-
this.track.appendChild(slide);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
container.appendChild(this.track);
|
|
66
|
-
this.root.appendChild(container);
|
|
67
|
-
|
|
68
|
-
this.prevButton = document.createElement('button');
|
|
69
|
-
this.prevButton.classList.add('carousel-button', 'carousel-button--left');
|
|
70
|
-
this.prevButton.innerHTML = '<span class="icon-navigate_before icon"></span>';
|
|
71
|
-
this.prevButton.setAttribute('aria-label', 'Previous Slide');
|
|
72
|
-
|
|
73
|
-
this.nextButton = document.createElement('button');
|
|
74
|
-
this.nextButton.classList.add('carousel-button', 'carousel-button--right');
|
|
75
|
-
this.nextButton.innerHTML = '<span class="icon-navigate_next icon"></span>';
|
|
76
|
-
this.nextButton.setAttribute('aria-label', 'Next Slide');
|
|
77
|
-
|
|
78
|
-
this.root.appendChild(this.prevButton);
|
|
79
|
-
this.root.appendChild(this.nextButton);
|
|
80
|
-
|
|
81
|
-
this.dotsNav = document.createElement('div');
|
|
82
|
-
this.dotsNav.classList.add('carousel-nav');
|
|
83
|
-
|
|
84
|
-
this.dots = [];
|
|
85
|
-
slides.forEach((_, index) => {
|
|
86
|
-
const dot = document.createElement('button');
|
|
87
|
-
dot.classList.add('carousel-indicator');
|
|
88
|
-
dot.setAttribute('aria-label', `Slide ${index + 1}`);
|
|
89
|
-
this.dotsNav.appendChild(dot);
|
|
90
|
-
this.dots.push(dot);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
this.root.appendChild(this.dotsNav);
|
|
94
|
-
|
|
95
|
-
// Make focusable for keyboard nav
|
|
96
|
-
this.root.setAttribute('tabindex', '0');
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
private bindEvents(): void {
|
|
100
|
-
const sig = { signal: this.abortController.signal };
|
|
101
|
-
|
|
102
|
-
this.nextButton.addEventListener('click', () => this.moveToNextSlide(), sig);
|
|
103
|
-
this.prevButton.addEventListener('click', () => this.moveToPrevSlide(), sig);
|
|
104
|
-
|
|
105
|
-
this.dotsNav.addEventListener('click', (e: MouseEvent) => {
|
|
106
|
-
const targetDot = (e.target as HTMLElement).closest('button');
|
|
107
|
-
if (!targetDot) return;
|
|
108
|
-
const targetIndex = this.dots.findIndex(dot => dot === targetDot);
|
|
109
|
-
this.moveToSlide(targetIndex);
|
|
110
|
-
}, sig);
|
|
111
|
-
|
|
112
|
-
window.addEventListener('resize', () => {
|
|
113
|
-
this.slideWidth = this.slides[0].getBoundingClientRect().width;
|
|
114
|
-
this.moveToSlide(this.currentIndex, false);
|
|
115
|
-
}, sig);
|
|
116
|
-
|
|
117
|
-
// Keyboard navigation
|
|
118
|
-
this.root.addEventListener('keydown', (e: KeyboardEvent) => {
|
|
119
|
-
if (e.key === 'ArrowLeft') this.moveToPrevSlide();
|
|
120
|
-
if (e.key === 'ArrowRight') this.moveToNextSlide();
|
|
121
|
-
}, sig);
|
|
122
|
-
|
|
123
|
-
// Pause autoplay on hover / focus
|
|
124
|
-
if (this.options.autoPlay) {
|
|
125
|
-
this.root.addEventListener('mouseenter', () => this.pauseAutoPlay(), sig);
|
|
126
|
-
this.root.addEventListener('mouseleave', () => this.resumeAutoPlay(), sig);
|
|
127
|
-
this.root.addEventListener('focusin', () => this.pauseAutoPlay(), sig);
|
|
128
|
-
this.root.addEventListener('focusout', () => this.resumeAutoPlay(), sig);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
this.addTouchSupport();
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
private moveToSlide(targetIndex: number, animate: boolean = true): void {
|
|
135
|
-
if (targetIndex < 0) {
|
|
136
|
-
if (this.options.loop) targetIndex = this.slides.length - 1;
|
|
137
|
-
else targetIndex = 0;
|
|
138
|
-
} else if (targetIndex >= this.slides.length) {
|
|
139
|
-
if (this.options.loop) targetIndex = 0;
|
|
140
|
-
else targetIndex = this.slides.length - 1;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if (!animate) {
|
|
144
|
-
this.track.style.transitionDuration = '0ms';
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
const amountToMove = -1 * (this.slideWidth * targetIndex);
|
|
148
|
-
this.track.style.transform = `translateX(${amountToMove}px)`;
|
|
149
|
-
|
|
150
|
-
if (!animate) {
|
|
151
|
-
// Restore CSS transition after the paint to avoid a flash
|
|
152
|
-
requestAnimationFrame(() => {
|
|
153
|
-
this.track.style.transitionDuration = '';
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
this.updateDots(targetIndex);
|
|
158
|
-
this.currentIndex = targetIndex;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
private moveToNextSlide(): void {
|
|
162
|
-
this.moveToSlide(this.currentIndex + 1);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
private moveToPrevSlide(): void {
|
|
166
|
-
this.moveToSlide(this.currentIndex - 1);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
private updateDots(targetIndex: number): void {
|
|
170
|
-
this.dots.forEach(dot => dot.classList.remove('current-slide'));
|
|
171
|
-
this.dots[targetIndex].classList.add('current-slide');
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
private addTouchSupport(): void {
|
|
175
|
-
let startX = 0;
|
|
176
|
-
let isDragging = false;
|
|
177
|
-
const sig = { signal: this.abortController.signal };
|
|
178
|
-
|
|
179
|
-
this.track.addEventListener('touchstart', (e: TouchEvent) => {
|
|
180
|
-
startX = e.touches[0].clientX;
|
|
181
|
-
isDragging = true;
|
|
182
|
-
}, { passive: true, signal: this.abortController.signal });
|
|
183
|
-
|
|
184
|
-
this.track.addEventListener('touchend', (e: TouchEvent) => {
|
|
185
|
-
if (!isDragging) return;
|
|
186
|
-
const endX = e.changedTouches[0].clientX;
|
|
187
|
-
const diffX = startX - endX;
|
|
188
|
-
if (Math.abs(diffX) > 50) {
|
|
189
|
-
if (diffX > 0) this.moveToNextSlide();
|
|
190
|
-
else this.moveToPrevSlide();
|
|
191
|
-
}
|
|
192
|
-
isDragging = false;
|
|
193
|
-
}, sig);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
private startAutoPlay(): void {
|
|
197
|
-
this.autoPlayTimer = window.setInterval(() => {
|
|
198
|
-
this.moveToNextSlide();
|
|
199
|
-
}, this.options.autoPlayInterval);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
private pauseAutoPlay(): void {
|
|
203
|
-
if (this.autoPlayTimer !== null) {
|
|
204
|
-
clearInterval(this.autoPlayTimer);
|
|
205
|
-
this.autoPlayTimer = null;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
private resumeAutoPlay(): void {
|
|
210
|
-
if (this.options.autoPlay && this.autoPlayTimer === null) {
|
|
211
|
-
this.startAutoPlay();
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
public destroy(): void {
|
|
216
|
-
this.pauseAutoPlay();
|
|
217
|
-
this.abortController.abort();
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
export { Carousel };
|
|
222
|
-
export type { CarouselOptions };
|