@studiometa/ui 0.2.23 → 0.2.25
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 +2 -12
- package/atoms/AnchorScrollTo/AnchorScrollTo.cjs +11 -0
- package/atoms/AnchorScrollTo/AnchorScrollTo.cjs.map +2 -2
- package/atoms/AnchorScrollTo/AnchorScrollTo.js +11 -0
- package/atoms/AnchorScrollTo/AnchorScrollTo.js.map +2 -2
- package/atoms/Button/StyledButton.twig +6 -4
- package/atoms/Button/StyledButtonRounded.twig +65 -0
- package/atoms/Cursor/Cursor.cjs +12 -0
- package/atoms/Cursor/Cursor.cjs.map +2 -2
- package/atoms/Cursor/Cursor.js +12 -0
- package/atoms/Cursor/Cursor.js.map +2 -2
- package/atoms/Figure/Figure.cjs +27 -3
- package/atoms/Figure/Figure.cjs.map +2 -2
- package/atoms/Figure/Figure.js +27 -3
- package/atoms/Figure/Figure.js.map +2 -2
- package/atoms/Figure/Figure.twig +6 -1
- package/atoms/Figure/FigureTwicpics.cjs +21 -0
- package/atoms/Figure/FigureTwicpics.cjs.map +1 -1
- package/atoms/Figure/FigureTwicpics.js +21 -0
- package/atoms/Figure/FigureTwicpics.js.map +1 -1
- package/atoms/LargeText/LargeText.cjs +27 -0
- package/atoms/LargeText/LargeText.cjs.map +2 -2
- package/atoms/LargeText/LargeText.js +27 -0
- package/atoms/LargeText/LargeText.js.map +2 -2
- package/atoms/LazyInclude/LazyInclude.cjs +15 -0
- package/atoms/LazyInclude/LazyInclude.cjs.map +2 -2
- package/atoms/LazyInclude/LazyInclude.js +15 -0
- package/atoms/LazyInclude/LazyInclude.js.map +2 -2
- package/atoms/Prefetch/AbstractPrefetch.cjs +12 -0
- package/atoms/Prefetch/AbstractPrefetch.cjs.map +2 -2
- package/atoms/Prefetch/AbstractPrefetch.js +12 -0
- package/atoms/Prefetch/AbstractPrefetch.js.map +2 -2
- package/atoms/Prefetch/PrefetchWhenOver.cjs +6 -0
- package/atoms/Prefetch/PrefetchWhenOver.cjs.map +2 -2
- package/atoms/Prefetch/PrefetchWhenOver.js +6 -0
- package/atoms/Prefetch/PrefetchWhenOver.js.map +2 -2
- package/atoms/Prefetch/PrefetchWhenVisible.cjs +6 -0
- package/atoms/Prefetch/PrefetchWhenVisible.cjs.map +2 -2
- package/atoms/Prefetch/PrefetchWhenVisible.js +6 -0
- package/atoms/Prefetch/PrefetchWhenVisible.js.map +2 -2
- package/atoms/ScrollAnimation/AbstractScrollAnimation.cjs +12 -0
- package/atoms/ScrollAnimation/AbstractScrollAnimation.cjs.map +2 -2
- package/atoms/ScrollAnimation/AbstractScrollAnimation.js +12 -0
- package/atoms/ScrollAnimation/AbstractScrollAnimation.js.map +2 -2
- package/atoms/ScrollAnimation/ScrollAnimation.cjs +6 -0
- package/atoms/ScrollAnimation/ScrollAnimation.cjs.map +1 -1
- package/atoms/ScrollAnimation/ScrollAnimation.js +6 -0
- package/atoms/ScrollAnimation/ScrollAnimation.js.map +1 -1
- package/atoms/ScrollAnimation/ScrollAnimationChild.cjs +18 -1
- package/atoms/ScrollAnimation/ScrollAnimationChild.cjs.map +2 -2
- package/atoms/ScrollAnimation/ScrollAnimationChild.js +18 -1
- package/atoms/ScrollAnimation/ScrollAnimationChild.js.map +2 -2
- package/atoms/ScrollAnimation/ScrollAnimationChildWithEase.cjs +3 -0
- package/atoms/ScrollAnimation/ScrollAnimationChildWithEase.cjs.map +1 -1
- package/atoms/ScrollAnimation/ScrollAnimationChildWithEase.js +3 -0
- package/atoms/ScrollAnimation/ScrollAnimationChildWithEase.js.map +1 -1
- package/atoms/ScrollAnimation/ScrollAnimationParent.cjs +6 -0
- package/atoms/ScrollAnimation/ScrollAnimationParent.cjs.map +1 -1
- package/atoms/ScrollAnimation/ScrollAnimationParent.js +6 -0
- package/atoms/ScrollAnimation/ScrollAnimationParent.js.map +1 -1
- package/atoms/ScrollAnimation/ScrollAnimationWithEase.cjs +3 -0
- package/atoms/ScrollAnimation/ScrollAnimationWithEase.cjs.map +1 -1
- package/atoms/ScrollAnimation/ScrollAnimationWithEase.d.ts +1 -1
- package/atoms/ScrollAnimation/ScrollAnimationWithEase.js +3 -0
- package/atoms/ScrollAnimation/ScrollAnimationWithEase.js.map +1 -1
- package/atoms/ScrollAnimation/animationScrollWithEase.cjs +6 -0
- package/atoms/ScrollAnimation/animationScrollWithEase.cjs.map +2 -2
- package/atoms/ScrollAnimation/animationScrollWithEase.js +6 -0
- package/atoms/ScrollAnimation/animationScrollWithEase.js.map +2 -2
- package/atoms/ScrollReveal/ScrollReveal.cjs +12 -0
- package/atoms/ScrollReveal/ScrollReveal.cjs.map +1 -1
- package/atoms/ScrollReveal/ScrollReveal.js +12 -0
- package/atoms/ScrollReveal/ScrollReveal.js.map +1 -1
- package/decorators/withTransition.cjs +16 -2
- package/decorators/withTransition.cjs.map +2 -2
- package/decorators/withTransition.js +16 -2
- package/decorators/withTransition.js.map +2 -2
- package/molecules/Accordion/AccordionCore.cjs +9 -0
- package/molecules/Accordion/AccordionCore.cjs.map +2 -2
- package/molecules/Accordion/AccordionCore.js +9 -0
- package/molecules/Accordion/AccordionCore.js.map +2 -2
- package/molecules/Accordion/AccordionItem.cjs +33 -1
- package/molecules/Accordion/AccordionItem.cjs.map +2 -2
- package/molecules/Accordion/AccordionItem.d.ts +1 -1
- package/molecules/Accordion/AccordionItem.js +29 -1
- package/molecules/Accordion/AccordionItem.js.map +2 -2
- package/molecules/Menu/Menu.cjs +47 -0
- package/molecules/Menu/Menu.cjs.map +1 -1
- package/molecules/Menu/Menu.js +47 -0
- package/molecules/Menu/Menu.js.map +1 -1
- package/molecules/Menu/MenuBtn.cjs +24 -0
- package/molecules/Menu/MenuBtn.cjs.map +1 -1
- package/molecules/Menu/MenuBtn.js +24 -0
- package/molecules/Menu/MenuBtn.js.map +1 -1
- package/molecules/Menu/MenuList.cjs +39 -0
- package/molecules/Menu/MenuList.cjs.map +2 -2
- package/molecules/Menu/MenuList.d.ts +1 -1
- package/molecules/Menu/MenuList.js +39 -0
- package/molecules/Menu/MenuList.js.map +2 -2
- package/molecules/Modal/Modal.cjs +50 -1
- package/molecules/Modal/Modal.cjs.map +2 -2
- package/molecules/Modal/Modal.d.ts +3 -3
- package/molecules/Modal/Modal.js +50 -1
- package/molecules/Modal/Modal.js.map +2 -2
- package/molecules/Modal/ModalWithTransition.cjs +6 -0
- package/molecules/Modal/ModalWithTransition.cjs.map +2 -2
- package/molecules/Modal/ModalWithTransition.js +6 -0
- package/molecules/Modal/ModalWithTransition.js.map +2 -2
- package/molecules/Panel/Panel.cjs +19 -0
- package/molecules/Panel/Panel.cjs.map +2 -2
- package/molecules/Panel/Panel.js +19 -0
- package/molecules/Panel/Panel.js.map +2 -2
- package/molecules/Slider/AbstractSliderChild.cjs +24 -0
- package/molecules/Slider/AbstractSliderChild.cjs.map +2 -2
- package/molecules/Slider/AbstractSliderChild.js +24 -0
- package/molecules/Slider/AbstractSliderChild.js.map +2 -2
- package/molecules/Slider/Slider.cjs +97 -0
- package/molecules/Slider/Slider.cjs.map +2 -2
- package/molecules/Slider/Slider.d.ts +3 -2
- package/molecules/Slider/Slider.js +97 -0
- package/molecules/Slider/Slider.js.map +2 -2
- package/molecules/Slider/SliderBtn.cjs +22 -2
- package/molecules/Slider/SliderBtn.cjs.map +2 -2
- package/molecules/Slider/SliderBtn.d.ts +1 -0
- package/molecules/Slider/SliderBtn.js +22 -2
- package/molecules/Slider/SliderBtn.js.map +2 -2
- package/molecules/Slider/SliderCount.cjs +9 -0
- package/molecules/Slider/SliderCount.cjs.map +2 -2
- package/molecules/Slider/SliderCount.js +9 -0
- package/molecules/Slider/SliderCount.js.map +2 -2
- package/molecules/Slider/SliderDots.cjs +19 -0
- package/molecules/Slider/SliderDots.cjs.map +2 -2
- package/molecules/Slider/SliderDots.js +19 -0
- package/molecules/Slider/SliderDots.js.map +2 -2
- package/molecules/Slider/SliderDrag.cjs +15 -0
- package/molecules/Slider/SliderDrag.cjs.map +2 -2
- package/molecules/Slider/SliderDrag.js +15 -0
- package/molecules/Slider/SliderDrag.js.map +2 -2
- package/molecules/Slider/SliderItem.cjs +75 -14
- package/molecules/Slider/SliderItem.cjs.map +2 -2
- package/molecules/Slider/SliderItem.d.ts +12 -11
- package/molecules/Slider/SliderItem.js +75 -14
- package/molecules/Slider/SliderItem.js.map +2 -2
- package/molecules/Slider/SliderProgress.cjs +6 -0
- package/molecules/Slider/SliderProgress.cjs.map +2 -2
- package/molecules/Slider/SliderProgress.js +6 -0
- package/molecules/Slider/SliderProgress.js.map +2 -2
- package/molecules/Sticky/Sticky.cjs +56 -0
- package/molecules/Sticky/Sticky.cjs.map +2 -2
- package/molecules/Sticky/Sticky.js +56 -0
- package/molecules/Sticky/Sticky.js.map +2 -2
- package/molecules/TableOfContent/TableOfContent.cjs +13 -0
- package/molecules/TableOfContent/TableOfContent.cjs.map +1 -1
- package/molecules/TableOfContent/TableOfContent.js +13 -0
- package/molecules/TableOfContent/TableOfContent.js.map +1 -1
- package/molecules/TableOfContent/TableOfContentAnchor.cjs +16 -0
- package/molecules/TableOfContent/TableOfContentAnchor.cjs.map +2 -2
- package/molecules/TableOfContent/TableOfContentAnchor.js +16 -0
- package/molecules/TableOfContent/TableOfContentAnchor.js.map +2 -2
- package/molecules/Tabs/Tabs.cjs +16 -0
- package/molecules/Tabs/Tabs.cjs.map +2 -2
- package/molecules/Tabs/Tabs.d.ts +3 -3
- package/molecules/Tabs/Tabs.js +16 -0
- package/molecules/Tabs/Tabs.js.map +2 -2
- package/organisms/Frame/Frame.cjs +30 -0
- package/organisms/Frame/Frame.cjs.map +2 -2
- package/organisms/Frame/Frame.js +30 -0
- package/organisms/Frame/Frame.js.map +2 -2
- package/organisms/Frame/FrameAnchor.cjs +6 -0
- package/organisms/Frame/FrameAnchor.cjs.map +1 -1
- package/organisms/Frame/FrameAnchor.js +6 -0
- package/organisms/Frame/FrameAnchor.js.map +1 -1
- package/organisms/Frame/FrameForm.cjs +6 -0
- package/organisms/Frame/FrameForm.cjs.map +1 -1
- package/organisms/Frame/FrameForm.js +6 -0
- package/organisms/Frame/FrameForm.js.map +1 -1
- package/organisms/Frame/FrameTarget.cjs +25 -2
- package/organisms/Frame/FrameTarget.cjs.map +2 -2
- package/organisms/Frame/FrameTarget.d.ts +1 -1
- package/organisms/Frame/FrameTarget.js +25 -2
- package/organisms/Frame/FrameTarget.js.map +2 -2
- package/organisms/Hero/Hero.twig +151 -0
- package/package.json +2 -2
- package/primitives/Draggable/Draggable.cjs +18 -0
- package/primitives/Draggable/Draggable.cjs.map +2 -2
- package/primitives/Draggable/Draggable.js +18 -0
- package/primitives/Draggable/Draggable.js.map +2 -2
- package/primitives/Sentinel/Sentinel.cjs +3 -0
- package/primitives/Sentinel/Sentinel.cjs.map +2 -2
- package/primitives/Sentinel/Sentinel.js +3 -0
- package/primitives/Sentinel/Sentinel.js.map +2 -2
- package/primitives/Transition/Transition.cjs +3 -0
- package/primitives/Transition/Transition.cjs.map +1 -1
- package/primitives/Transition/Transition.js +3 -0
- package/primitives/Transition/Transition.js.map +1 -1
|
@@ -3,6 +3,9 @@ import { clamp, inertiaFinalValue, nextFrame, isDev } from "@studiometa/js-toolk
|
|
|
3
3
|
import { SliderDrag } from "./SliderDrag.js";
|
|
4
4
|
import { SliderItem } from "./SliderItem.js";
|
|
5
5
|
class Slider extends Base {
|
|
6
|
+
/**
|
|
7
|
+
* Config.
|
|
8
|
+
*/
|
|
6
9
|
static config = {
|
|
7
10
|
name: "Slider",
|
|
8
11
|
refs: ["wrapper", "debug"],
|
|
@@ -21,44 +24,87 @@ class Slider extends Base {
|
|
|
21
24
|
};
|
|
22
25
|
__distanceX = 0;
|
|
23
26
|
__initialX = 0;
|
|
27
|
+
/**
|
|
28
|
+
* Index of the current active slide.
|
|
29
|
+
*/
|
|
24
30
|
__currentIndex = 0;
|
|
31
|
+
/**
|
|
32
|
+
* Get the current index.
|
|
33
|
+
*/
|
|
25
34
|
get currentIndex() {
|
|
26
35
|
return this.__currentIndex;
|
|
27
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Set the current index and emit the `index` event.
|
|
39
|
+
*/
|
|
28
40
|
set currentIndex(value) {
|
|
29
41
|
this.currentSliderItem.disactivate();
|
|
30
42
|
this.$emit("index", value);
|
|
31
43
|
this.__currentIndex = value;
|
|
32
44
|
this.currentSliderItem.activate();
|
|
33
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Store all the states.
|
|
48
|
+
*/
|
|
34
49
|
states = [];
|
|
50
|
+
/**
|
|
51
|
+
* Origins for the different modes.
|
|
52
|
+
*/
|
|
35
53
|
origins = {
|
|
36
54
|
left: 0,
|
|
37
55
|
center: 0,
|
|
38
56
|
right: 0
|
|
39
57
|
};
|
|
58
|
+
/**
|
|
59
|
+
* Wether or not the wrapper is focused.
|
|
60
|
+
* @type {boolean}
|
|
61
|
+
*/
|
|
40
62
|
hasFocus = false;
|
|
63
|
+
/**
|
|
64
|
+
* Get the current state.
|
|
65
|
+
*/
|
|
41
66
|
get currentState() {
|
|
42
67
|
return this.states[this.currentIndex];
|
|
43
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Get the first state.
|
|
71
|
+
*/
|
|
44
72
|
get firstState() {
|
|
45
73
|
return this.states[0];
|
|
46
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Get the last state.
|
|
77
|
+
*/
|
|
47
78
|
get lastState() {
|
|
48
79
|
return this.states.at(-1);
|
|
49
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Get the minimal contain state value.
|
|
83
|
+
*/
|
|
50
84
|
get containMinState() {
|
|
51
85
|
return this.getStateValueByMode(this.firstState.x, "left");
|
|
52
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Get the maximal contain state value.
|
|
89
|
+
*/
|
|
53
90
|
get containMaxState() {
|
|
54
91
|
return this.getStateValueByMode(this.lastState.x, "right");
|
|
55
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* Get the last index.
|
|
95
|
+
*/
|
|
56
96
|
get indexMax() {
|
|
57
97
|
return this.$children.SliderItem.length - 1;
|
|
58
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Get the current SliderItem
|
|
101
|
+
*/
|
|
59
102
|
get currentSliderItem() {
|
|
60
103
|
return this.$children.SliderItem[this.currentIndex];
|
|
61
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Get the states for each SliderItem.
|
|
107
|
+
*/
|
|
62
108
|
getStates() {
|
|
63
109
|
const { wrapper } = this.$refs;
|
|
64
110
|
const originRect = wrapper.getBoundingClientRect();
|
|
@@ -111,17 +157,29 @@ class Slider extends Base {
|
|
|
111
157
|
}
|
|
112
158
|
return states;
|
|
113
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* Get an origin by mode.
|
|
162
|
+
*/
|
|
114
163
|
getOriginByMode(mode) {
|
|
115
164
|
return this.origins[mode ?? this.$options.mode];
|
|
116
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Get a state value according to the given mode.
|
|
168
|
+
*/
|
|
117
169
|
getStateValueByMode(state, mode) {
|
|
118
170
|
return state[mode ?? this.$options.mode];
|
|
119
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* Mounted hook.
|
|
174
|
+
*/
|
|
120
175
|
mounted() {
|
|
121
176
|
this.states = this.getStates();
|
|
122
177
|
this.prepareInvisibleItems();
|
|
123
178
|
this.goTo(this.currentIndex);
|
|
124
179
|
}
|
|
180
|
+
/**
|
|
181
|
+
* Resized hook.
|
|
182
|
+
*/
|
|
125
183
|
resized() {
|
|
126
184
|
nextFrame(() => {
|
|
127
185
|
this.states = this.getStates();
|
|
@@ -131,18 +189,27 @@ class Slider extends Base {
|
|
|
131
189
|
});
|
|
132
190
|
});
|
|
133
191
|
}
|
|
192
|
+
/**
|
|
193
|
+
* Go to the next slide.
|
|
194
|
+
*/
|
|
134
195
|
goNext() {
|
|
135
196
|
if (this.currentIndex + 1 > this.indexMax) {
|
|
136
197
|
return;
|
|
137
198
|
}
|
|
138
199
|
this.goTo(this.currentIndex + 1);
|
|
139
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* Go to the previous slide.
|
|
203
|
+
*/
|
|
140
204
|
goPrev() {
|
|
141
205
|
if (this.currentIndex - 1 < 0) {
|
|
142
206
|
return;
|
|
143
207
|
}
|
|
144
208
|
this.goTo(this.currentIndex - 1);
|
|
145
209
|
}
|
|
210
|
+
/**
|
|
211
|
+
* Go to the given index.
|
|
212
|
+
*/
|
|
146
213
|
goTo(index, { withInstantMove = true } = {}) {
|
|
147
214
|
if (index < 0 || index > this.indexMax) {
|
|
148
215
|
throw new Error("Index out of bound.");
|
|
@@ -163,10 +230,16 @@ class Slider extends Base {
|
|
|
163
230
|
this.currentIndex = index;
|
|
164
231
|
this.$emit("goto", index);
|
|
165
232
|
}
|
|
233
|
+
/**
|
|
234
|
+
* Listen to the Draggable `start` event.
|
|
235
|
+
*/
|
|
166
236
|
onSliderDragStart() {
|
|
167
237
|
this.__initialX = this.currentSliderItem ? this.currentSliderItem.x : 0;
|
|
168
238
|
this.__distanceX = this.__initialX;
|
|
169
239
|
}
|
|
240
|
+
/**
|
|
241
|
+
* Listen to the Draggable `drag` event.
|
|
242
|
+
*/
|
|
170
243
|
onSliderDragDrag(props) {
|
|
171
244
|
if (Math.abs(props.delta.y) > Math.abs(props.delta.x)) {
|
|
172
245
|
return;
|
|
@@ -176,6 +249,9 @@ class Slider extends Base {
|
|
|
176
249
|
item.moveInstantly(this.__distanceX);
|
|
177
250
|
});
|
|
178
251
|
}
|
|
252
|
+
/**
|
|
253
|
+
* Listen to the Draggable `drop` event and find the new active slide.
|
|
254
|
+
*/
|
|
179
255
|
onSliderDragDrop(props) {
|
|
180
256
|
if (Math.abs(props.delta.y) > Math.abs(props.delta.x)) {
|
|
181
257
|
return;
|
|
@@ -203,12 +279,21 @@ class Slider extends Base {
|
|
|
203
279
|
this.currentIndex = closestIndex;
|
|
204
280
|
}
|
|
205
281
|
}
|
|
282
|
+
/**
|
|
283
|
+
* Enable focus.
|
|
284
|
+
*/
|
|
206
285
|
onWrapperFocus() {
|
|
207
286
|
this.hasFocus = true;
|
|
208
287
|
}
|
|
288
|
+
/**
|
|
289
|
+
* Disable focus.
|
|
290
|
+
*/
|
|
209
291
|
onWrapperBlur() {
|
|
210
292
|
this.hasFocus = false;
|
|
211
293
|
}
|
|
294
|
+
/**
|
|
295
|
+
* Go prev or next when focus is on the wrapper and pressing arrow keys.
|
|
296
|
+
*/
|
|
212
297
|
keyed({ LEFT, RIGHT, isDown }) {
|
|
213
298
|
if (this.hasFocus && isDown) {
|
|
214
299
|
if (LEFT) {
|
|
@@ -218,6 +303,9 @@ class Slider extends Base {
|
|
|
218
303
|
}
|
|
219
304
|
}
|
|
220
305
|
}
|
|
306
|
+
/**
|
|
307
|
+
* Prepare invisible items.
|
|
308
|
+
*/
|
|
221
309
|
prepareInvisibleItems() {
|
|
222
310
|
const state = this.states[this.currentIndex];
|
|
223
311
|
const nextItemsToPrepare = [];
|
|
@@ -244,6 +332,9 @@ class Slider extends Base {
|
|
|
244
332
|
}
|
|
245
333
|
});
|
|
246
334
|
}
|
|
335
|
+
/**
|
|
336
|
+
* Get the state where the given item will be visible.
|
|
337
|
+
*/
|
|
247
338
|
getStateWhereItemWillBeInvisible(item, { reversed = false } = {}) {
|
|
248
339
|
const visibleStates = this.states.filter(
|
|
249
340
|
(state) => item.willBeVisible(this.getStateValueByMode(state.x))
|
|
@@ -256,9 +347,15 @@ class Slider extends Base {
|
|
|
256
347
|
const lastVisibleStateIndex = this.states.findIndex((state) => state.x === lastVisibleState.x);
|
|
257
348
|
return reversed ? this.states[lastVisibleStateIndex + 1] : this.states[firstVisibleStateIndex - 1];
|
|
258
349
|
}
|
|
350
|
+
/**
|
|
351
|
+
* Get the visible slides for the given position.
|
|
352
|
+
*/
|
|
259
353
|
getVisibleItems(target) {
|
|
260
354
|
return this.$children.SliderItem.filter((item) => item.isVisible || item.willBeVisible(target));
|
|
261
355
|
}
|
|
356
|
+
/**
|
|
357
|
+
* Get the invisible slides for the given position.
|
|
358
|
+
*/
|
|
262
359
|
getInvisibleItems(target) {
|
|
263
360
|
return this.$children.SliderItem.filter(
|
|
264
361
|
(item) => !item.isVisible && !item.willBeVisible(target)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../packages/ui/molecules/Slider/Slider.ts"],
|
|
4
|
-
"sourcesContent": ["import { Base } from '@studiometa/js-toolkit';\nimport type { BaseProps, BaseConfig, DragServiceProps, KeyServiceProps } from '@studiometa/js-toolkit';\nimport { clamp, inertiaFinalValue, nextFrame, isDev } from '@studiometa/js-toolkit/utils';\nimport { SliderDrag } from './SliderDrag.js';\nimport { SliderItem } from './SliderItem.js';\n\nexport type SliderModes = 'left' | 'center' | 'right';\n\ntype SliderState = { x: Record<SliderModes, number> };\n\nexport interface SliderProps extends BaseProps {\n $refs: {\n wrapper: HTMLElement;\n }\n $children: {\n SliderItem: SliderItem[];\n SliderDrag: SliderDrag[];\n };\n $options: {\n mode: SliderModes;\n fitBounds: boolean;\n sensitivity: number;\n dropSensitivity: number;\n }\n}\n\n/**\n * Orchestrate the slider items state transition.\n * @todo a11y\n */\nexport class Slider<T extends BaseProps = BaseProps> extends Base<T & SliderProps> {\n /**\n * Config.\n */\n static config :BaseConfig = {\n name: 'Slider',\n refs: ['wrapper', 'debug'],\n emits: ['goto', 'index'],\n components: {\n SliderItem,\n SliderDrag,\n },\n options: {\n mode: { type: String, default: 'left' },\n fitBounds: Boolean,\n contain: Boolean,\n sensitivity: { type: Number, default: 1 },\n dropSensitivity: { type: Number, default: 2 },\n },\n };\n\n __distanceX = 0;\n\n __initialX = 0;\n\n /**\n * Index of the current active slide.\n */\n __currentIndex = 0;\n\n /**\n * Get the current index.\n */\n get currentIndex() {\n return this.__currentIndex;\n }\n\n /**\n * Set the current index and emit the `index` event.\n */\n set currentIndex(value:number) {\n this.currentSliderItem.disactivate();\n this.$emit('index', value);\n this.__currentIndex = value;\n this.currentSliderItem.activate();\n }\n\n /**\n * Store all the states.\n */\n states:SliderState[] = [];\n\n /**\n * Origins for the different modes.\n */\n origins:Record<SliderModes, number> = {\n left: 0,\n center: 0,\n right: 0,\n };\n\n /**\n * Wether or not the wrapper is focused.\n * @type {boolean}\n */\n hasFocus = false;\n\n /**\n * Get the current state.\n */\n get currentState() {\n return this.states[this.currentIndex];\n }\n\n /**\n * Get the first state.\n */\n get firstState() {\n return this.states[0];\n }\n\n /**\n * Get the last state.\n */\n get lastState() {\n return this.states.at(-1);\n }\n\n /**\n * Get the minimal contain state value.\n */\n get containMinState():number {\n return this.getStateValueByMode(this.firstState.x, 'left');\n }\n\n /**\n * Get the maximal contain state value.\n */\n get containMaxState():number {\n return this.getStateValueByMode(this.lastState.x, 'right');\n }\n\n /**\n * Get the last index.\n */\n get indexMax():number {\n return this.$children.SliderItem.length - 1;\n }\n\n /**\n * Get the current SliderItem\n */\n get currentSliderItem() {\n return this.$children.SliderItem[this.currentIndex];\n }\n\n /**\n * Get the states for each SliderItem.\n */\n getStates():SliderState[] {\n const { wrapper } = this.$refs;\n const originRect = wrapper.getBoundingClientRect();\n\n this.origins = {\n left: originRect.left,\n center: originRect.x + originRect.width / 2,\n right: originRect.x + originRect.width,\n };\n\n const states:SliderState[] = this.$children.SliderItem.map((item) => ({\n x: {\n left: (item.rect.x - this.origins.left) * -1,\n center: (item.rect.x + item.rect.width / 2 - this.origins.center) * -1,\n right: (item.rect.x + item.rect.width - this.origins.right) * -1,\n },\n }));\n\n if (this.$options.contain) {\n const { mode } = this.$options;\n // Find state where last child has passed the wrapper bound completely\n if (mode === 'left') {\n const lastChild = this.$children.SliderItem.at(-1);\n\n const maxState = states.find((state) => {\n const lastChildPosition =\n lastChild.rect.x - this.origins.left + lastChild.rect.width + state.x.left;\n const diffWithWrapperBound = originRect.width - lastChildPosition;\n if (diffWithWrapperBound > 0) {\n state.x.left = Math.min(state.x.left + diffWithWrapperBound, 0);\n return true;\n }\n\n return false;\n });\n\n if (maxState) {\n return states.map((state) => {\n state.x.left = Math.max(state.x.left, maxState.x.left);\n return state;\n });\n }\n }\n\n if (mode === 'right') {\n const maxStateIndex = states.findIndex((state) => state.x.right <= 0);\n const maxState = maxStateIndex < 0 ? states.at(-1) : states[maxStateIndex - 1];\n\n return states.map((state) => {\n state.x.right = maxStateIndex < 0 ? maxState.x.right : Math.min(state.x.right, 0);\n return state;\n });\n }\n\n if (mode === 'center' && isDev) {\n console.warn(\n `[${this.$id}]`,\n 'The `center` mode is not yet compatible with the `contain` mode.',\n );\n }\n }\n\n return states;\n }\n\n /**\n * Get an origin by mode.\n */\n getOriginByMode(mode?:SliderModes) {\n return this.origins[mode ?? this.$options.mode];\n }\n\n /**\n * Get a state value according to the given mode.\n */\n getStateValueByMode(state:SliderState['x'], mode?:SliderModes) {\n return state[mode ?? this.$options.mode];\n }\n\n /**\n * Mounted hook.\n */\n mounted() {\n this.states = this.getStates();\n this.prepareInvisibleItems();\n this.goTo(this.currentIndex);\n }\n\n /**\n * Resized hook.\n */\n resized() {\n nextFrame(() => {\n this.states = this.getStates();\n nextFrame(() => {\n this.prepareInvisibleItems();\n this.goTo(this.currentIndex);\n });\n });\n }\n\n /**\n * Go to the next slide.\n */\n goNext() {\n if (this.currentIndex + 1 > this.indexMax) {\n return;\n }\n\n this.goTo(this.currentIndex + 1);\n }\n\n /**\n * Go to the previous slide.\n */\n goPrev() {\n if (this.currentIndex - 1 < 0) {\n return;\n }\n\n this.goTo(this.currentIndex - 1);\n }\n\n /**\n * Go to the given index.\n */\n goTo(index:number, { withInstantMove = true } = {}) {\n if (index < 0 || index > this.indexMax) {\n throw new Error('Index out of bound.');\n }\n\n const currentState = this.getStateValueByMode(this.currentState.x);\n const state = this.getStateValueByMode(this.states[index].x);\n const itemsToMove = this.getVisibleItems(state);\n const invisibleItemsToMoveInstantly = this.getInvisibleItems(state);\n\n itemsToMove.forEach((item) => {\n // Better perfs when going fast through the slides\n if (currentState !== state && withInstantMove) {\n item.moveInstantly(currentState);\n }\n nextFrame(() => item.move(state));\n });\n invisibleItemsToMoveInstantly.forEach((item) => {\n item.moveInstantly(state);\n });\n\n this.currentIndex = index;\n this.$emit('goto', index);\n }\n\n /**\n * Listen to the Draggable `start` event.\n */\n onSliderDragStart() {\n this.__initialX = this.currentSliderItem ? this.currentSliderItem.x : 0;\n this.__distanceX = this.__initialX;\n }\n\n /**\n * Listen to the Draggable `drag` event.\n */\n onSliderDragDrag(props:DragServiceProps) {\n if (Math.abs(props.delta.y) > Math.abs(props.delta.x)) {\n return;\n }\n\n this.__distanceX = this.__initialX + props.distance.x * this.$options.sensitivity;\n\n this.getVisibleItems(this.__distanceX).forEach((item) => {\n item.moveInstantly(this.__distanceX);\n });\n }\n\n /**\n * Listen to the Draggable `drop` event and find the new active slide.\n */\n onSliderDragDrop(props:DragServiceProps) {\n if (Math.abs(props.delta.y) > Math.abs(props.delta.x)) {\n return;\n }\n\n let finalX = clamp(\n inertiaFinalValue(this.__distanceX, props.delta.x * this.$options.dropSensitivity),\n this.getStateValueByMode(this.firstState.x),\n this.getStateValueByMode(this.lastState.x),\n );\n\n const absoluteDifferencesBetweenDistanceAndState = this.states.map((state) =>\n Math.abs(finalX - this.getStateValueByMode(state.x)),\n );\n const minimumDifference = Math.min(...absoluteDifferencesBetweenDistanceAndState);\n const closestIndex = absoluteDifferencesBetweenDistanceAndState.indexOf(minimumDifference);\n\n if (this.$options.fitBounds) {\n this.goTo(closestIndex, { withInstantMove: false });\n } else {\n if (this.$options.contain) {\n finalX = Math.min(this.containMinState, finalX);\n finalX = Math.max(this.containMaxState, finalX);\n }\n this.$children.SliderItem.forEach((item) => {\n item.move(finalX);\n });\n this.currentIndex = closestIndex;\n }\n }\n\n /**\n * Enable focus.\n */\n onWrapperFocus() {\n this.hasFocus = true;\n }\n\n /**\n * Disable focus.\n */\n onWrapperBlur() {\n this.hasFocus = false;\n }\n\n /**\n * Go prev or next when focus is on the wrapper and pressing arrow keys.\n */\n keyed({ LEFT, RIGHT, isDown }:KeyServiceProps) {\n if (this.hasFocus && isDown) {\n if (LEFT) {\n this.goPrev();\n } else if (RIGHT) {\n this.goNext();\n }\n }\n }\n\n /**\n * Prepare invisible items.\n */\n prepareInvisibleItems() {\n const state = this.states[this.currentIndex];\n const nextItemsToPrepare = [];\n const previousItemsToPrepare = [];\n\n this.getInvisibleItems(this.getStateValueByMode(state.x)).forEach((item, i) => {\n if (i > this.currentIndex) {\n nextItemsToPrepare.push(item);\n return;\n }\n\n if (i < this.currentIndex) {\n previousItemsToPrepare.push(item);\n }\n });\n\n nextItemsToPrepare.forEach((item) => {\n const invisibleState = this.getStateWhereItemWillBeInvisible(item);\n if (invisibleState) {\n item.moveInstantly(this.getStateValueByMode(invisibleState.x));\n }\n });\n\n previousItemsToPrepare.forEach((item) => {\n const invisibleState = this.getStateWhereItemWillBeInvisible(item, { reversed: true });\n if (invisibleState) {\n item.moveInstantly(this.getStateValueByMode(invisibleState.x));\n }\n });\n }\n\n /**\n * Get the state where the given item will be visible.\n */\n getStateWhereItemWillBeInvisible(item:SliderItem, { reversed = false } = {}):SliderState {\n const visibleStates = this.states.filter((state) =>\n item.willBeVisible(this.getStateValueByMode(state.x)),\n );\n const firstVisibleState = visibleStates[0];\n const lastVisibleState = visibleStates.at(-1);\n const firstVisibleStateIndex = this.states.findIndex(\n (state) =>\n this.getStateValueByMode(state.x) === this.getStateValueByMode(firstVisibleState.x),\n );\n const lastVisibleStateIndex = this.states.findIndex((state) => state.x === lastVisibleState.x);\n\n return reversed\n ? this.states[lastVisibleStateIndex + 1]\n : this.states[firstVisibleStateIndex - 1];\n }\n\n /**\n * Get the visible slides for the given position.\n */\n getVisibleItems(target:number) {\n return this.$children.SliderItem.filter((item) => item.isVisible || item.willBeVisible(target));\n }\n\n /**\n * Get the invisible slides for the given position.\n */\n getInvisibleItems(target:number) {\n return this.$children.SliderItem.filter(\n (item) => !item.isVisible && !item.willBeVisible(target),\n );\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,YAAY;
|
|
4
|
+
"sourcesContent": ["import { Base } from '@studiometa/js-toolkit';\nimport type {\n BaseProps,\n BaseConfig,\n DragServiceProps,\n KeyServiceProps,\n} from '@studiometa/js-toolkit';\nimport { clamp, inertiaFinalValue, nextFrame, isDev } from '@studiometa/js-toolkit/utils';\nimport { SliderDrag } from './SliderDrag.js';\nimport { SliderItem } from './SliderItem.js';\n\nexport type SliderModes = 'left' | 'center' | 'right';\n\ntype SliderState = { x: Record<SliderModes, number> };\n\nexport interface SliderProps extends BaseProps {\n $refs: {\n wrapper: HTMLElement;\n };\n $children: {\n SliderItem: SliderItem[];\n SliderDrag: SliderDrag[];\n };\n $options: {\n mode: SliderModes;\n fitBounds: boolean;\n contain: boolean;\n sensitivity: number;\n dropSensitivity: number;\n };\n}\n\n/**\n * Orchestrate the slider items state transition.\n * @todo a11y\n */\nexport class Slider<T extends BaseProps = BaseProps> extends Base<T & SliderProps> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'Slider',\n refs: ['wrapper', 'debug'],\n emits: ['goto', 'index'],\n components: {\n SliderItem,\n SliderDrag,\n },\n options: {\n mode: { type: String, default: 'left' },\n fitBounds: Boolean,\n contain: Boolean,\n sensitivity: { type: Number, default: 1 },\n dropSensitivity: { type: Number, default: 2 },\n },\n };\n\n __distanceX = 0;\n\n __initialX = 0;\n\n /**\n * Index of the current active slide.\n */\n __currentIndex = 0;\n\n /**\n * Get the current index.\n */\n get currentIndex() {\n return this.__currentIndex;\n }\n\n /**\n * Set the current index and emit the `index` event.\n */\n set currentIndex(value: number) {\n this.currentSliderItem.disactivate();\n this.$emit('index', value);\n this.__currentIndex = value;\n this.currentSliderItem.activate();\n }\n\n /**\n * Store all the states.\n */\n states: SliderState[] = [];\n\n /**\n * Origins for the different modes.\n */\n origins: Record<SliderModes, number> = {\n left: 0,\n center: 0,\n right: 0,\n };\n\n /**\n * Wether or not the wrapper is focused.\n * @type {boolean}\n */\n hasFocus = false;\n\n /**\n * Get the current state.\n */\n get currentState() {\n return this.states[this.currentIndex];\n }\n\n /**\n * Get the first state.\n */\n get firstState() {\n return this.states[0];\n }\n\n /**\n * Get the last state.\n */\n get lastState() {\n return this.states.at(-1);\n }\n\n /**\n * Get the minimal contain state value.\n */\n get containMinState(): number {\n return this.getStateValueByMode(this.firstState.x, 'left');\n }\n\n /**\n * Get the maximal contain state value.\n */\n get containMaxState(): number {\n return this.getStateValueByMode(this.lastState.x, 'right');\n }\n\n /**\n * Get the last index.\n */\n get indexMax(): number {\n return this.$children.SliderItem.length - 1;\n }\n\n /**\n * Get the current SliderItem\n */\n get currentSliderItem() {\n return this.$children.SliderItem[this.currentIndex];\n }\n\n /**\n * Get the states for each SliderItem.\n */\n getStates(): SliderState[] {\n const { wrapper } = this.$refs;\n const originRect = wrapper.getBoundingClientRect();\n\n this.origins = {\n left: originRect.left,\n center: originRect.x + originRect.width / 2,\n right: originRect.x + originRect.width,\n };\n\n const states: SliderState[] = this.$children.SliderItem.map((item) => ({\n x: {\n left: (item.rect.x - this.origins.left) * -1,\n center: (item.rect.x + item.rect.width / 2 - this.origins.center) * -1,\n right: (item.rect.x + item.rect.width - this.origins.right) * -1,\n },\n }));\n\n if (this.$options.contain) {\n const { mode } = this.$options;\n // Find state where last child has passed the wrapper bound completely\n if (mode === 'left') {\n const lastChild = this.$children.SliderItem.at(-1);\n\n const maxState = states.find((state) => {\n const lastChildPosition =\n lastChild.rect.x - this.origins.left + lastChild.rect.width + state.x.left;\n const diffWithWrapperBound = originRect.width - lastChildPosition;\n if (diffWithWrapperBound > 0) {\n state.x.left = Math.min(state.x.left + diffWithWrapperBound, 0);\n return true;\n }\n\n return false;\n });\n\n if (maxState) {\n return states.map((state) => {\n state.x.left = Math.max(state.x.left, maxState.x.left);\n return state;\n });\n }\n }\n\n if (mode === 'right') {\n const maxStateIndex = states.findIndex((state) => state.x.right <= 0);\n const maxState = maxStateIndex < 0 ? states.at(-1) : states[maxStateIndex - 1];\n\n return states.map((state) => {\n state.x.right = maxStateIndex < 0 ? maxState.x.right : Math.min(state.x.right, 0);\n return state;\n });\n }\n\n if (mode === 'center' && isDev) {\n console.warn(\n `[${this.$id}]`,\n 'The `center` mode is not yet compatible with the `contain` mode.',\n );\n }\n }\n\n return states;\n }\n\n /**\n * Get an origin by mode.\n */\n getOriginByMode(mode?: SliderModes) {\n return this.origins[mode ?? this.$options.mode];\n }\n\n /**\n * Get a state value according to the given mode.\n */\n getStateValueByMode(state: SliderState['x'], mode?: SliderModes) {\n return state[mode ?? this.$options.mode];\n }\n\n /**\n * Mounted hook.\n */\n mounted() {\n this.states = this.getStates();\n this.prepareInvisibleItems();\n this.goTo(this.currentIndex);\n }\n\n /**\n * Resized hook.\n */\n resized() {\n nextFrame(() => {\n this.states = this.getStates();\n nextFrame(() => {\n this.prepareInvisibleItems();\n this.goTo(this.currentIndex);\n });\n });\n }\n\n /**\n * Go to the next slide.\n */\n goNext() {\n if (this.currentIndex + 1 > this.indexMax) {\n return;\n }\n\n this.goTo(this.currentIndex + 1);\n }\n\n /**\n * Go to the previous slide.\n */\n goPrev() {\n if (this.currentIndex - 1 < 0) {\n return;\n }\n\n this.goTo(this.currentIndex - 1);\n }\n\n /**\n * Go to the given index.\n */\n goTo(index: number, { withInstantMove = true } = {}) {\n if (index < 0 || index > this.indexMax) {\n throw new Error('Index out of bound.');\n }\n\n const currentState = this.getStateValueByMode(this.currentState.x);\n const state = this.getStateValueByMode(this.states[index].x);\n const itemsToMove = this.getVisibleItems(state);\n const invisibleItemsToMoveInstantly = this.getInvisibleItems(state);\n\n itemsToMove.forEach((item) => {\n // Better perfs when going fast through the slides\n if (currentState !== state && withInstantMove) {\n item.moveInstantly(currentState);\n }\n nextFrame(() => item.move(state));\n });\n invisibleItemsToMoveInstantly.forEach((item) => {\n item.moveInstantly(state);\n });\n\n this.currentIndex = index;\n this.$emit('goto', index);\n }\n\n /**\n * Listen to the Draggable `start` event.\n */\n onSliderDragStart() {\n this.__initialX = this.currentSliderItem ? this.currentSliderItem.x : 0;\n this.__distanceX = this.__initialX;\n }\n\n /**\n * Listen to the Draggable `drag` event.\n */\n onSliderDragDrag(props: DragServiceProps) {\n if (Math.abs(props.delta.y) > Math.abs(props.delta.x)) {\n return;\n }\n\n this.__distanceX = this.__initialX + props.distance.x * this.$options.sensitivity;\n\n this.getVisibleItems(this.__distanceX).forEach((item) => {\n item.moveInstantly(this.__distanceX);\n });\n }\n\n /**\n * Listen to the Draggable `drop` event and find the new active slide.\n */\n onSliderDragDrop(props: DragServiceProps) {\n if (Math.abs(props.delta.y) > Math.abs(props.delta.x)) {\n return;\n }\n\n let finalX = clamp(\n inertiaFinalValue(this.__distanceX, props.delta.x * this.$options.dropSensitivity),\n this.getStateValueByMode(this.firstState.x),\n this.getStateValueByMode(this.lastState.x),\n );\n\n const absoluteDifferencesBetweenDistanceAndState = this.states.map((state) =>\n Math.abs(finalX - this.getStateValueByMode(state.x)),\n );\n const minimumDifference = Math.min(...absoluteDifferencesBetweenDistanceAndState);\n const closestIndex = absoluteDifferencesBetweenDistanceAndState.indexOf(minimumDifference);\n\n if (this.$options.fitBounds) {\n this.goTo(closestIndex, { withInstantMove: false });\n } else {\n if (this.$options.contain) {\n finalX = Math.min(this.containMinState, finalX);\n finalX = Math.max(this.containMaxState, finalX);\n }\n this.$children.SliderItem.forEach((item) => {\n item.move(finalX);\n });\n this.currentIndex = closestIndex;\n }\n }\n\n /**\n * Enable focus.\n */\n onWrapperFocus() {\n this.hasFocus = true;\n }\n\n /**\n * Disable focus.\n */\n onWrapperBlur() {\n this.hasFocus = false;\n }\n\n /**\n * Go prev or next when focus is on the wrapper and pressing arrow keys.\n */\n keyed({ LEFT, RIGHT, isDown }: KeyServiceProps) {\n if (this.hasFocus && isDown) {\n if (LEFT) {\n this.goPrev();\n } else if (RIGHT) {\n this.goNext();\n }\n }\n }\n\n /**\n * Prepare invisible items.\n */\n prepareInvisibleItems() {\n const state = this.states[this.currentIndex];\n const nextItemsToPrepare = [];\n const previousItemsToPrepare = [];\n\n this.getInvisibleItems(this.getStateValueByMode(state.x)).forEach((item, i) => {\n if (i > this.currentIndex) {\n nextItemsToPrepare.push(item);\n return;\n }\n\n if (i < this.currentIndex) {\n previousItemsToPrepare.push(item);\n }\n });\n\n nextItemsToPrepare.forEach((item) => {\n const invisibleState = this.getStateWhereItemWillBeInvisible(item);\n if (invisibleState) {\n item.moveInstantly(this.getStateValueByMode(invisibleState.x));\n }\n });\n\n previousItemsToPrepare.forEach((item) => {\n const invisibleState = this.getStateWhereItemWillBeInvisible(item, { reversed: true });\n if (invisibleState) {\n item.moveInstantly(this.getStateValueByMode(invisibleState.x));\n }\n });\n }\n\n /**\n * Get the state where the given item will be visible.\n */\n getStateWhereItemWillBeInvisible(item: SliderItem, { reversed = false } = {}): SliderState {\n const visibleStates = this.states.filter((state) =>\n item.willBeVisible(this.getStateValueByMode(state.x)),\n );\n const firstVisibleState = visibleStates[0];\n const lastVisibleState = visibleStates.at(-1);\n const firstVisibleStateIndex = this.states.findIndex(\n (state) =>\n this.getStateValueByMode(state.x) === this.getStateValueByMode(firstVisibleState.x),\n );\n const lastVisibleStateIndex = this.states.findIndex((state) => state.x === lastVisibleState.x);\n\n return reversed\n ? this.states[lastVisibleStateIndex + 1]\n : this.states[firstVisibleStateIndex - 1];\n }\n\n /**\n * Get the visible slides for the given position.\n */\n getVisibleItems(target: number) {\n return this.$children.SliderItem.filter((item) => item.isVisible || item.willBeVisible(target));\n }\n\n /**\n * Get the invisible slides for the given position.\n */\n getInvisibleItems(target: number) {\n return this.$children.SliderItem.filter(\n (item) => !item.isVisible && !item.willBeVisible(target),\n );\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,YAAY;AAOrB,SAAS,OAAO,mBAAmB,WAAW,aAAa;AAC3D,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AA2BpB,MAAM,eAAgD,KAAsB;AAAA;AAAA;AAAA;AAAA,EAIjF,OAAO,SAAqB;AAAA,IAC1B,MAAM;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;AACzC,UAAM,mBAAmB,cAAc,GAAG,EAAE;AAC5C,UAAM,yBAAyB,KAAK,OAAO;AAAA,MACzC,CAAC,UACC,KAAK,oBAAoB,MAAM,CAAC,MAAM,KAAK,oBAAoB,kBAAkB,CAAC;AAAA,IACtF;AACA,UAAM,wBAAwB,KAAK,OAAO,UAAU,CAAC,UAAU,MAAM,MAAM,iBAAiB,CAAC;AAE7F,WAAO,WACH,KAAK,OAAO,wBAAwB,CAAC,IACrC,KAAK,OAAO,yBAAyB,CAAC;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA,EAKA,gBAAgB,QAAgB;AAC9B,WAAO,KAAK,UAAU,WAAW,OAAO,CAAC,SAAS,KAAK,aAAa,KAAK,cAAc,MAAM,CAAC;AAAA,EAChG;AAAA;AAAA;AAAA;AAAA,EAKA,kBAAkB,QAAgB;AAChC,WAAO,KAAK,UAAU,WAAW;AAAA,MAC/B,CAAC,SAAS,CAAC,KAAK,aAAa,CAAC,KAAK,cAAc,MAAM;AAAA,IACzD;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -27,15 +27,31 @@ __export(SliderBtn_exports, {
|
|
|
27
27
|
SliderBtn: () => SliderBtn
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(SliderBtn_exports);
|
|
30
|
+
var import_utils = require("@studiometa/js-toolkit/utils");
|
|
30
31
|
var import_AbstractSliderChild = require("./AbstractSliderChild.cjs");
|
|
31
32
|
var SliderBtn = class extends import_AbstractSliderChild.AbstractSliderChild {
|
|
33
|
+
/**
|
|
34
|
+
* Update attributes.
|
|
35
|
+
* @param {number} index
|
|
36
|
+
* @returns {void}
|
|
37
|
+
*/
|
|
32
38
|
update(index) {
|
|
33
|
-
if (
|
|
39
|
+
if (import_utils.isDev && this.$options.contain && !this.$parent.$options.contain) {
|
|
40
|
+
console.warn(
|
|
41
|
+
`[${this.$id}] The contain option will only works if the parent Slider also has the contain option.`
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
const isContainMaxState = this.$options.contain && this.$parent.$options.contain && this.$parent.containMaxState === this.$parent.getStates()[index].x[this.$parent.$options.mode];
|
|
45
|
+
if (index === 0 && this.$options.prev || (index === this.$parent.indexMax || isContainMaxState) && this.$options.next) {
|
|
34
46
|
this.$el.setAttribute("disabled", "");
|
|
35
47
|
} else {
|
|
36
48
|
this.$el.removeAttribute("disabled");
|
|
37
49
|
}
|
|
38
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Go prev or next on click.
|
|
53
|
+
* @returns {void}
|
|
54
|
+
*/
|
|
39
55
|
onClick() {
|
|
40
56
|
const { prev, next } = this.$options;
|
|
41
57
|
if (prev) {
|
|
@@ -45,11 +61,15 @@ var SliderBtn = class extends import_AbstractSliderChild.AbstractSliderChild {
|
|
|
45
61
|
}
|
|
46
62
|
}
|
|
47
63
|
};
|
|
64
|
+
/**
|
|
65
|
+
* Config.
|
|
66
|
+
*/
|
|
48
67
|
__publicField(SliderBtn, "config", {
|
|
49
68
|
name: "SliderBtn",
|
|
50
69
|
options: {
|
|
51
70
|
prev: Boolean,
|
|
52
|
-
next: Boolean
|
|
71
|
+
next: Boolean,
|
|
72
|
+
contain: Boolean
|
|
53
73
|
}
|
|
54
74
|
});
|
|
55
75
|
if (module.exports.default) module.exports = module.exports.default;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../packages/ui/molecules/Slider/SliderBtn.ts"],
|
|
4
|
-
"sourcesContent": ["import type { BaseProps, BaseConfig } from '@studiometa/js-toolkit';\nimport { AbstractSliderChild } from './AbstractSliderChild.js';\n\nexport interface SliderBtnProps extends BaseProps {\n $options: {\n prev: boolean;\n next: boolean;\n };\n}\n\n/**\n * SliderBtn class.\n */\nexport class SliderBtn<T extends BaseProps = BaseProps> extends AbstractSliderChild
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import { isDev } from '@studiometa/js-toolkit/utils';\nimport type { BaseProps, BaseConfig } from '@studiometa/js-toolkit';\nimport { AbstractSliderChild } from './AbstractSliderChild.js';\n\nexport interface SliderBtnProps extends BaseProps {\n $options: {\n prev: boolean;\n next: boolean;\n contain: boolean;\n };\n}\n\n/**\n * SliderBtn class.\n */\nexport class SliderBtn<T extends BaseProps = BaseProps> extends AbstractSliderChild<\n T & SliderBtnProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'SliderBtn',\n options: {\n prev: Boolean,\n next: Boolean,\n contain: Boolean,\n },\n };\n\n /**\n * Update attributes.\n * @param {number} index\n * @returns {void}\n */\n update(index: number) {\n if (isDev && this.$options.contain && !this.$parent.$options.contain) {\n console.warn(\n `[${this.$id}] The contain option will only works if the parent Slider also has the contain option.`,\n );\n }\n\n const isContainMaxState =\n this.$options.contain &&\n this.$parent.$options.contain &&\n this.$parent.containMaxState ===\n this.$parent.getStates()[index].x[this.$parent.$options.mode];\n\n if (\n (index === 0 && this.$options.prev) ||\n ((index === this.$parent.indexMax || isContainMaxState) && this.$options.next)\n ) {\n this.$el.setAttribute('disabled', '');\n } else {\n this.$el.removeAttribute('disabled');\n }\n }\n\n /**\n * Go prev or next on click.\n * @returns {void}\n */\n onClick() {\n const { prev, next } = this.$options;\n\n if (prev) {\n this.$parent.goPrev();\n } else if (next) {\n this.$parent.goNext();\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsB;AAEtB,iCAAoC;AAa7B,IAAM,YAAN,cAAyD,+CAE9D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkBA,OAAO,OAAe;AACpB,QAAI,sBAAS,KAAK,SAAS,WAAW,CAAC,KAAK,QAAQ,SAAS,SAAS;AACpE,cAAQ;AAAA,QACN,IAAI,KAAK;AAAA,MACX;AAAA,IACF;AAEA,UAAM,oBACJ,KAAK,SAAS,WACd,KAAK,QAAQ,SAAS,WACtB,KAAK,QAAQ,oBACX,KAAK,QAAQ,UAAU,EAAE,KAAK,EAAE,EAAE,KAAK,QAAQ,SAAS,IAAI;AAEhE,QACG,UAAU,KAAK,KAAK,SAAS,SAC5B,UAAU,KAAK,QAAQ,YAAY,sBAAsB,KAAK,SAAS,MACzE;AACA,WAAK,IAAI,aAAa,YAAY,EAAE;AAAA,IACtC,OAAO;AACL,WAAK,IAAI,gBAAgB,UAAU;AAAA,IACrC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,UAAU;AACR,UAAM,EAAE,MAAM,KAAK,IAAI,KAAK;AAE5B,QAAI,MAAM;AACR,WAAK,QAAQ,OAAO;AAAA,IACtB,WAAW,MAAM;AACf,WAAK,QAAQ,OAAO;AAAA,IACtB;AAAA,EACF;AACF;AAAA;AAAA;AAAA;AAlDE,cANW,WAMJ,UAAqB;AAAA,EAC1B,MAAM;AAAA,EACN,SAAS;AAAA,IACP,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS;AAAA,EACX;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,19 +1,39 @@
|
|
|
1
|
+
import { isDev } from "@studiometa/js-toolkit/utils";
|
|
1
2
|
import { AbstractSliderChild } from "./AbstractSliderChild.js";
|
|
2
3
|
class SliderBtn extends AbstractSliderChild {
|
|
4
|
+
/**
|
|
5
|
+
* Config.
|
|
6
|
+
*/
|
|
3
7
|
static config = {
|
|
4
8
|
name: "SliderBtn",
|
|
5
9
|
options: {
|
|
6
10
|
prev: Boolean,
|
|
7
|
-
next: Boolean
|
|
11
|
+
next: Boolean,
|
|
12
|
+
contain: Boolean
|
|
8
13
|
}
|
|
9
14
|
};
|
|
15
|
+
/**
|
|
16
|
+
* Update attributes.
|
|
17
|
+
* @param {number} index
|
|
18
|
+
* @returns {void}
|
|
19
|
+
*/
|
|
10
20
|
update(index) {
|
|
11
|
-
if (
|
|
21
|
+
if (isDev && this.$options.contain && !this.$parent.$options.contain) {
|
|
22
|
+
console.warn(
|
|
23
|
+
`[${this.$id}] The contain option will only works if the parent Slider also has the contain option.`
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
const isContainMaxState = this.$options.contain && this.$parent.$options.contain && this.$parent.containMaxState === this.$parent.getStates()[index].x[this.$parent.$options.mode];
|
|
27
|
+
if (index === 0 && this.$options.prev || (index === this.$parent.indexMax || isContainMaxState) && this.$options.next) {
|
|
12
28
|
this.$el.setAttribute("disabled", "");
|
|
13
29
|
} else {
|
|
14
30
|
this.$el.removeAttribute("disabled");
|
|
15
31
|
}
|
|
16
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Go prev or next on click.
|
|
35
|
+
* @returns {void}
|
|
36
|
+
*/
|
|
17
37
|
onClick() {
|
|
18
38
|
const { prev, next } = this.$options;
|
|
19
39
|
if (prev) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../packages/ui/molecules/Slider/SliderBtn.ts"],
|
|
4
|
-
"sourcesContent": ["import type { BaseProps, BaseConfig } from '@studiometa/js-toolkit';\nimport { AbstractSliderChild } from './AbstractSliderChild.js';\n\nexport interface SliderBtnProps extends BaseProps {\n $options: {\n prev: boolean;\n next: boolean;\n };\n}\n\n/**\n * SliderBtn class.\n */\nexport class SliderBtn<T extends BaseProps = BaseProps> extends AbstractSliderChild
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { isDev } from '@studiometa/js-toolkit/utils';\nimport type { BaseProps, BaseConfig } from '@studiometa/js-toolkit';\nimport { AbstractSliderChild } from './AbstractSliderChild.js';\n\nexport interface SliderBtnProps extends BaseProps {\n $options: {\n prev: boolean;\n next: boolean;\n contain: boolean;\n };\n}\n\n/**\n * SliderBtn class.\n */\nexport class SliderBtn<T extends BaseProps = BaseProps> extends AbstractSliderChild<\n T & SliderBtnProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'SliderBtn',\n options: {\n prev: Boolean,\n next: Boolean,\n contain: Boolean,\n },\n };\n\n /**\n * Update attributes.\n * @param {number} index\n * @returns {void}\n */\n update(index: number) {\n if (isDev && this.$options.contain && !this.$parent.$options.contain) {\n console.warn(\n `[${this.$id}] The contain option will only works if the parent Slider also has the contain option.`,\n );\n }\n\n const isContainMaxState =\n this.$options.contain &&\n this.$parent.$options.contain &&\n this.$parent.containMaxState ===\n this.$parent.getStates()[index].x[this.$parent.$options.mode];\n\n if (\n (index === 0 && this.$options.prev) ||\n ((index === this.$parent.indexMax || isContainMaxState) && this.$options.next)\n ) {\n this.$el.setAttribute('disabled', '');\n } else {\n this.$el.removeAttribute('disabled');\n }\n }\n\n /**\n * Go prev or next on click.\n * @returns {void}\n */\n onClick() {\n const { prev, next } = this.$options;\n\n if (prev) {\n this.$parent.goPrev();\n } else if (next) {\n this.$parent.goNext();\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,aAAa;AAEtB,SAAS,2BAA2B;AAa7B,MAAM,kBAAmD,oBAE9D;AAAA;AAAA;AAAA;AAAA,EAIA,OAAO,SAAqB;AAAA,IAC1B,MAAM;AAAA,IACN,SAAS;AAAA,MACP,MAAM;AAAA,MACN,MAAM;AAAA,MACN,SAAS;AAAA,IACX;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,OAAO,OAAe;AACpB,QAAI,SAAS,KAAK,SAAS,WAAW,CAAC,KAAK,QAAQ,SAAS,SAAS;AACpE,cAAQ;AAAA,QACN,IAAI,KAAK;AAAA,MACX;AAAA,IACF;AAEA,UAAM,oBACJ,KAAK,SAAS,WACd,KAAK,QAAQ,SAAS,WACtB,KAAK,QAAQ,oBACX,KAAK,QAAQ,UAAU,EAAE,KAAK,EAAE,EAAE,KAAK,QAAQ,SAAS,IAAI;AAEhE,QACG,UAAU,KAAK,KAAK,SAAS,SAC5B,UAAU,KAAK,QAAQ,YAAY,sBAAsB,KAAK,SAAS,MACzE;AACA,WAAK,IAAI,aAAa,YAAY,EAAE;AAAA,IACtC,OAAO;AACL,WAAK,IAAI,gBAAgB,UAAU;AAAA,IACrC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,UAAU;AACR,UAAM,EAAE,MAAM,KAAK,IAAI,KAAK;AAE5B,QAAI,MAAM;AACR,WAAK,QAAQ,OAAO;AAAA,IACtB,WAAW,MAAM;AACf,WAAK,QAAQ,OAAO;AAAA,IACtB;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -29,10 +29,19 @@ __export(SliderCount_exports, {
|
|
|
29
29
|
module.exports = __toCommonJS(SliderCount_exports);
|
|
30
30
|
var import_AbstractSliderChild = require("./AbstractSliderChild.cjs");
|
|
31
31
|
var SliderCount = class extends import_AbstractSliderChild.AbstractSliderChild {
|
|
32
|
+
/**
|
|
33
|
+
* Update the current counter indicator.
|
|
34
|
+
*
|
|
35
|
+
* @param {number} index The new active index.
|
|
36
|
+
* @returns {void}
|
|
37
|
+
*/
|
|
32
38
|
update(index) {
|
|
33
39
|
this.$refs.current.innerHTML = `${index + 1}`;
|
|
34
40
|
}
|
|
35
41
|
};
|
|
42
|
+
/**
|
|
43
|
+
* Config.
|
|
44
|
+
*/
|
|
36
45
|
__publicField(SliderCount, "config", {
|
|
37
46
|
name: "SliderCount",
|
|
38
47
|
refs: ["current"]
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../packages/ui/molecules/Slider/SliderCount.ts"],
|
|
4
|
-
"sourcesContent": ["import type { BaseProps, BaseConfig } from '@studiometa/js-toolkit';\nimport { AbstractSliderChild } from './AbstractSliderChild.js';\n\nexport interface SliderCountProps extends BaseProps {\n $refs: {\n current: HTMLElement;\n }
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,iCAAoC;AAW7B,IAAM,cAAN,cAA2D,+
|
|
4
|
+
"sourcesContent": ["import type { BaseProps, BaseConfig } from '@studiometa/js-toolkit';\nimport { AbstractSliderChild } from './AbstractSliderChild.js';\n\nexport interface SliderCountProps extends BaseProps {\n $refs: {\n current: HTMLElement;\n };\n}\n\n/**\n * SliderCount class.\n */\nexport class SliderCount<T extends BaseProps = BaseProps> extends AbstractSliderChild<\n T & SliderCountProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'SliderCount',\n refs: ['current'],\n };\n\n /**\n * Update the current counter indicator.\n *\n * @param {number} index The new active index.\n * @returns {void}\n */\n update(index: number) {\n this.$refs.current.innerHTML = `${index + 1}`;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,iCAAoC;AAW7B,IAAM,cAAN,cAA2D,+CAEhE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeA,OAAO,OAAe;AACpB,SAAK,MAAM,QAAQ,YAAY,GAAG,QAAQ;AAAA,EAC5C;AACF;AAAA;AAAA;AAAA;AAdE,cANW,aAMJ,UAAqB;AAAA,EAC1B,MAAM;AAAA,EACN,MAAM,CAAC,SAAS;AAClB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import { AbstractSliderChild } from "./AbstractSliderChild.js";
|
|
2
2
|
class SliderCount extends AbstractSliderChild {
|
|
3
|
+
/**
|
|
4
|
+
* Config.
|
|
5
|
+
*/
|
|
3
6
|
static config = {
|
|
4
7
|
name: "SliderCount",
|
|
5
8
|
refs: ["current"]
|
|
6
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* Update the current counter indicator.
|
|
12
|
+
*
|
|
13
|
+
* @param {number} index The new active index.
|
|
14
|
+
* @returns {void}
|
|
15
|
+
*/
|
|
7
16
|
update(index) {
|
|
8
17
|
this.$refs.current.innerHTML = `${index + 1}`;
|
|
9
18
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../packages/ui/molecules/Slider/SliderCount.ts"],
|
|
4
|
-
"sourcesContent": ["import type { BaseProps, BaseConfig } from '@studiometa/js-toolkit';\nimport { AbstractSliderChild } from './AbstractSliderChild.js';\n\nexport interface SliderCountProps extends BaseProps {\n $refs: {\n current: HTMLElement;\n }
|
|
5
|
-
"mappings": "AACA,SAAS,2BAA2B;AAW7B,MAAM,oBAAqD,
|
|
4
|
+
"sourcesContent": ["import type { BaseProps, BaseConfig } from '@studiometa/js-toolkit';\nimport { AbstractSliderChild } from './AbstractSliderChild.js';\n\nexport interface SliderCountProps extends BaseProps {\n $refs: {\n current: HTMLElement;\n };\n}\n\n/**\n * SliderCount class.\n */\nexport class SliderCount<T extends BaseProps = BaseProps> extends AbstractSliderChild<\n T & SliderCountProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'SliderCount',\n refs: ['current'],\n };\n\n /**\n * Update the current counter indicator.\n *\n * @param {number} index The new active index.\n * @returns {void}\n */\n update(index: number) {\n this.$refs.current.innerHTML = `${index + 1}`;\n }\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,2BAA2B;AAW7B,MAAM,oBAAqD,oBAEhE;AAAA;AAAA;AAAA;AAAA,EAIA,OAAO,SAAqB;AAAA,IAC1B,MAAM;AAAA,IACN,MAAM,CAAC,SAAS;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAO,OAAe;AACpB,SAAK,MAAM,QAAQ,YAAY,GAAG,QAAQ;AAAA,EAC5C;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -30,19 +30,38 @@ module.exports = __toCommonJS(SliderDots_exports);
|
|
|
30
30
|
var import_decorators = require("../../decorators/index.cjs");
|
|
31
31
|
var import_AbstractSliderChild = require("./AbstractSliderChild.cjs");
|
|
32
32
|
var SliderDots = class extends (0, import_decorators.withTransition)(import_AbstractSliderChild.AbstractSliderChild) {
|
|
33
|
+
/**
|
|
34
|
+
* Get target.
|
|
35
|
+
* @returns {HTMLButtonElement[]}
|
|
36
|
+
*/
|
|
33
37
|
get target() {
|
|
34
38
|
return this.$refs.dots;
|
|
35
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* The current active index.
|
|
42
|
+
*/
|
|
36
43
|
currentIndex = 0;
|
|
44
|
+
/**
|
|
45
|
+
* Update dots classes according to the new index.
|
|
46
|
+
*
|
|
47
|
+
* @param {number} index
|
|
48
|
+
* @returns {void}
|
|
49
|
+
*/
|
|
37
50
|
update(index) {
|
|
38
51
|
this.leave(this.$refs.dots[this.currentIndex]);
|
|
39
52
|
this.enter(this.$refs.dots[index]);
|
|
40
53
|
this.currentIndex = index;
|
|
41
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Go to the given index on dot click.
|
|
57
|
+
*/
|
|
42
58
|
onDotsClick(event, index) {
|
|
43
59
|
this.$parent.goTo(index);
|
|
44
60
|
}
|
|
45
61
|
};
|
|
62
|
+
/**
|
|
63
|
+
* Config.
|
|
64
|
+
*/
|
|
46
65
|
__publicField(SliderDots, "config", {
|
|
47
66
|
name: "SliderDots",
|
|
48
67
|
refs: ["dots[]"]
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../packages/ui/molecules/Slider/SliderDots.ts"],
|
|
4
|
-
"sourcesContent": ["import type { BaseProps, BaseConfig } from '@studiometa/js-toolkit';\nimport { withTransition } from '../../decorators/index.js';\nimport { AbstractSliderChild } from './AbstractSliderChild.js';\n\nexport interface SliderDotsProps extends BaseProps {\n $refs: {\n dots: HTMLButtonElement[];\n };\n}\n\n/**\n * SliderDots class.\n */\nexport class SliderDots<\n T extends BaseProps = BaseProps,\n> extends withTransition<AbstractSliderChild>(AbstractSliderChild)<T & SliderDotsProps> {\n /**\n * Config.\n */\n static config:BaseConfig = {\n name: 'SliderDots',\n refs: ['dots[]'],\n };\n\n /**\n * Get target.\n * @returns {HTMLButtonElement[]}\n */\n get target() {\n return this.$refs.dots;\n }\n\n /**\n * The current active index.\n */\n currentIndex = 0;\n\n /**\n * Update dots classes according to the new index.\n *\n * @param {number} index\n * @returns {void}\n */\n update(index:number) {\n this.leave(this.$refs.dots[this.currentIndex]);\n this.enter(this.$refs.dots[index]);\n this.currentIndex = index;\n }\n\n /**\n * Go to the given index on dot click.\n */\n onDotsClick(event:MouseEvent, index:number) {\n this.$parent.goTo(index);\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,wBAA+B;AAC/B,iCAAoC;AAW7B,IAAM,aAAN,kBAEG,kCAAoC,8CAAmB,EAAuB;AAAA,EAatF,IAAI,SAAS;AACX,WAAO,KAAK,MAAM;AAAA,EACpB;AAAA,EAKA,eAAe;AAAA,EAQf,OAAO,
|
|
4
|
+
"sourcesContent": ["import type { BaseProps, BaseConfig } from '@studiometa/js-toolkit';\nimport { withTransition } from '../../decorators/index.js';\nimport { AbstractSliderChild } from './AbstractSliderChild.js';\n\nexport interface SliderDotsProps extends BaseProps {\n $refs: {\n dots: HTMLButtonElement[];\n };\n}\n\n/**\n * SliderDots class.\n */\nexport class SliderDots<\n T extends BaseProps = BaseProps,\n> extends withTransition<AbstractSliderChild>(AbstractSliderChild)<T & SliderDotsProps> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'SliderDots',\n refs: ['dots[]'],\n };\n\n /**\n * Get target.\n * @returns {HTMLButtonElement[]}\n */\n get target() {\n return this.$refs.dots;\n }\n\n /**\n * The current active index.\n */\n currentIndex = 0;\n\n /**\n * Update dots classes according to the new index.\n *\n * @param {number} index\n * @returns {void}\n */\n update(index: number) {\n this.leave(this.$refs.dots[this.currentIndex]);\n this.enter(this.$refs.dots[index]);\n this.currentIndex = index;\n }\n\n /**\n * Go to the given index on dot click.\n */\n onDotsClick(event: MouseEvent, index: number) {\n this.$parent.goTo(index);\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,wBAA+B;AAC/B,iCAAoC;AAW7B,IAAM,aAAN,kBAEG,kCAAoC,8CAAmB,EAAuB;AAAA;AAAA;AAAA;AAAA;AAAA,EAatF,IAAI,SAAS;AACX,WAAO,KAAK,MAAM;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA,EAKA,eAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQf,OAAO,OAAe;AACpB,SAAK,MAAM,KAAK,MAAM,KAAK,KAAK,YAAY,CAAC;AAC7C,SAAK,MAAM,KAAK,MAAM,KAAK,KAAK,CAAC;AACjC,SAAK,eAAe;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA,EAKA,YAAY,OAAmB,OAAe;AAC5C,SAAK,QAAQ,KAAK,KAAK;AAAA,EACzB;AACF;AAAA;AAAA;AAAA;AApCE,cANW,YAMJ,UAAqB;AAAA,EAC1B,MAAM;AAAA,EACN,MAAM,CAAC,QAAQ;AACjB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,19 +1,38 @@
|
|
|
1
1
|
import { withTransition } from "../../decorators/index.js";
|
|
2
2
|
import { AbstractSliderChild } from "./AbstractSliderChild.js";
|
|
3
3
|
class SliderDots extends withTransition(AbstractSliderChild) {
|
|
4
|
+
/**
|
|
5
|
+
* Config.
|
|
6
|
+
*/
|
|
4
7
|
static config = {
|
|
5
8
|
name: "SliderDots",
|
|
6
9
|
refs: ["dots[]"]
|
|
7
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* Get target.
|
|
13
|
+
* @returns {HTMLButtonElement[]}
|
|
14
|
+
*/
|
|
8
15
|
get target() {
|
|
9
16
|
return this.$refs.dots;
|
|
10
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* The current active index.
|
|
20
|
+
*/
|
|
11
21
|
currentIndex = 0;
|
|
22
|
+
/**
|
|
23
|
+
* Update dots classes according to the new index.
|
|
24
|
+
*
|
|
25
|
+
* @param {number} index
|
|
26
|
+
* @returns {void}
|
|
27
|
+
*/
|
|
12
28
|
update(index) {
|
|
13
29
|
this.leave(this.$refs.dots[this.currentIndex]);
|
|
14
30
|
this.enter(this.$refs.dots[index]);
|
|
15
31
|
this.currentIndex = index;
|
|
16
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Go to the given index on dot click.
|
|
35
|
+
*/
|
|
17
36
|
onDotsClick(event, index) {
|
|
18
37
|
this.$parent.goTo(index);
|
|
19
38
|
}
|