@studiometa/ui 1.0.0-rc.0 → 1.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AnchorScrollTo/AnchorScrollTo.d.ts +2 -2
- package/AnchorScrollTo/AnchorScrollTo.js +0 -1
- package/AnchorScrollTo/AnchorScrollTo.js.map +2 -2
- package/Button/Button.twig +12 -9
- package/Button/StyledButton.twig +40 -5
- package/Button/StyledButtonRounded.twig +12 -42
- package/Data/DataBind.js +1 -1
- package/Data/DataBind.js.map +2 -2
- package/Draggable/Draggable.js +7 -2
- package/Draggable/Draggable.js.map +2 -2
- package/Figure/Figure.d.ts +1 -0
- package/Figure/Figure.js.map +2 -2
- package/Frame/AbstractFrameTrigger.d.ts +43 -0
- package/Frame/AbstractFrameTrigger.js +72 -0
- package/Frame/AbstractFrameTrigger.js.map +7 -0
- package/Frame/Frame.d.ts +55 -27
- package/Frame/Frame.js +132 -138
- package/Frame/Frame.js.map +3 -3
- package/Frame/FrameAnchor.d.ts +7 -4
- package/Frame/FrameAnchor.js +8 -5
- package/Frame/FrameAnchor.js.map +2 -2
- package/Frame/FrameForm.d.ts +22 -4
- package/Frame/FrameForm.js +43 -6
- package/Frame/FrameForm.js.map +2 -2
- package/Frame/FrameLoader.d.ts +22 -0
- package/Frame/FrameLoader.js +22 -0
- package/Frame/FrameLoader.js.map +7 -0
- package/Frame/FrameTarget.d.ts +6 -17
- package/Frame/FrameTarget.js +25 -60
- package/Frame/FrameTarget.js.map +2 -2
- package/Frame/FrameTriggerLoader.d.ts +13 -0
- package/Frame/FrameTriggerLoader.js +13 -0
- package/Frame/FrameTriggerLoader.js.map +7 -0
- package/Frame/index.d.ts +4 -0
- package/Frame/index.js +4 -0
- package/Frame/index.js.map +2 -2
- package/Frame/types.d.ts +12 -0
- package/Frame/types.js +1 -0
- package/Frame/types.js.map +7 -0
- package/Frame/utils.d.ts +9 -0
- package/Frame/utils.js +13 -0
- package/Frame/utils.js.map +7 -0
- package/Slider/AbstractSliderChild.d.ts +5 -9
- package/Slider/AbstractSliderChild.js +0 -11
- package/Slider/AbstractSliderChild.js.map +2 -2
- package/Slider/Slider.d.ts +23 -30
- package/Slider/Slider.js +40 -100
- package/Slider/Slider.js.map +2 -2
- package/Slider/SliderBtn.d.ts +0 -3
- package/Slider/SliderBtn.js +3 -7
- package/Slider/SliderBtn.js.map +2 -2
- package/Slider/SliderCount.d.ts +0 -2
- package/Slider/SliderCount.js +4 -3
- package/Slider/SliderCount.js.map +2 -2
- package/Slider/SliderDots.d.ts +0 -3
- package/Slider/SliderDots.js +6 -7
- package/Slider/SliderDots.js.map +2 -2
- package/Slider/SliderDrag.d.ts +0 -2
- package/Slider/SliderDrag.js +0 -2
- package/Slider/SliderDrag.js.map +2 -2
- package/Slider/SliderItem.d.ts +10 -26
- package/Slider/SliderItem.js +9 -41
- package/Slider/SliderItem.js.map +2 -2
- package/decorators/withTransition.d.ts +4 -0
- package/decorators/withTransition.js +40 -45
- package/decorators/withTransition.js.map +2 -2
- package/package.json +4 -3
package/Slider/Slider.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Base } from "@studiometa/js-toolkit";
|
|
2
|
-
import { clamp, inertiaFinalValue, nextFrame
|
|
2
|
+
import { clamp, inertiaFinalValue, nextFrame } from "@studiometa/js-toolkit/utils";
|
|
3
3
|
import { SliderDrag } from "./SliderDrag.js";
|
|
4
4
|
import { SliderItem } from "./SliderItem.js";
|
|
5
5
|
class Slider extends Base {
|
|
@@ -8,7 +8,7 @@ class Slider extends Base {
|
|
|
8
8
|
*/
|
|
9
9
|
static config = {
|
|
10
10
|
name: "Slider",
|
|
11
|
-
refs: ["wrapper"
|
|
11
|
+
refs: ["wrapper"],
|
|
12
12
|
emits: ["goto", "index"],
|
|
13
13
|
components: {
|
|
14
14
|
SliderItem,
|
|
@@ -22,28 +22,26 @@ class Slider extends Base {
|
|
|
22
22
|
dropSensitivity: { type: Number, default: 2 }
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* Distance on the x axis.
|
|
27
|
+
* @private
|
|
28
|
+
*/
|
|
25
29
|
__distanceX = 0;
|
|
30
|
+
/**
|
|
31
|
+
* Initial x position.
|
|
32
|
+
* @private
|
|
33
|
+
*/
|
|
26
34
|
__initialX = 0;
|
|
27
35
|
/**
|
|
28
36
|
* Index of the current active slide.
|
|
37
|
+
* @private
|
|
29
38
|
*/
|
|
30
39
|
__currentIndex = 0;
|
|
31
|
-
__isDragging = false;
|
|
32
|
-
/**
|
|
33
|
-
* Get the current index.
|
|
34
|
-
*/
|
|
35
|
-
get currentIndex() {
|
|
36
|
-
return this.__currentIndex;
|
|
37
|
-
}
|
|
38
40
|
/**
|
|
39
|
-
*
|
|
41
|
+
* Drag state.
|
|
42
|
+
* @private
|
|
40
43
|
*/
|
|
41
|
-
|
|
42
|
-
this.currentSliderItem.disactivate();
|
|
43
|
-
this.$emit("index", value);
|
|
44
|
-
this.__currentIndex = value;
|
|
45
|
-
this.currentSliderItem.activate();
|
|
46
|
-
}
|
|
44
|
+
__isDragging = false;
|
|
47
45
|
/**
|
|
48
46
|
* Store all the states.
|
|
49
47
|
*/
|
|
@@ -58,9 +56,23 @@ class Slider extends Base {
|
|
|
58
56
|
};
|
|
59
57
|
/**
|
|
60
58
|
* Wether or not the wrapper is focused.
|
|
61
|
-
* @type {boolean}
|
|
62
59
|
*/
|
|
63
60
|
hasFocus = false;
|
|
61
|
+
/**
|
|
62
|
+
* Get the current index.
|
|
63
|
+
*/
|
|
64
|
+
get currentIndex() {
|
|
65
|
+
return this.__currentIndex;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Set the current index and emit the `index` event.
|
|
69
|
+
*/
|
|
70
|
+
set currentIndex(value) {
|
|
71
|
+
this.currentSliderItem.disactivate();
|
|
72
|
+
this.$emit("index", value);
|
|
73
|
+
this.__currentIndex = value;
|
|
74
|
+
this.currentSliderItem.activate();
|
|
75
|
+
}
|
|
64
76
|
/**
|
|
65
77
|
* Get the current state.
|
|
66
78
|
*/
|
|
@@ -149,11 +161,8 @@ class Slider extends Base {
|
|
|
149
161
|
return state;
|
|
150
162
|
});
|
|
151
163
|
}
|
|
152
|
-
if (mode === "center"
|
|
153
|
-
|
|
154
|
-
`[${this.$id}]`,
|
|
155
|
-
"The `center` mode is not yet compatible with the `contain` mode."
|
|
156
|
-
);
|
|
164
|
+
if (mode === "center") {
|
|
165
|
+
this.$warn("The `center` mode is not yet compatible with the `contain` mode.");
|
|
157
166
|
}
|
|
158
167
|
}
|
|
159
168
|
return states;
|
|
@@ -176,7 +185,6 @@ class Slider extends Base {
|
|
|
176
185
|
mounted() {
|
|
177
186
|
this.states = this.getStates();
|
|
178
187
|
this.setAccessibilityAttributes();
|
|
179
|
-
this.prepareInvisibleItems();
|
|
180
188
|
this.goTo(this.currentIndex);
|
|
181
189
|
}
|
|
182
190
|
/**
|
|
@@ -186,7 +194,6 @@ class Slider extends Base {
|
|
|
186
194
|
nextFrame(() => {
|
|
187
195
|
this.states = this.getStates();
|
|
188
196
|
nextFrame(() => {
|
|
189
|
-
this.prepareInvisibleItems();
|
|
190
197
|
this.goTo(this.currentIndex);
|
|
191
198
|
});
|
|
192
199
|
});
|
|
@@ -219,23 +226,14 @@ class Slider extends Base {
|
|
|
219
226
|
/**
|
|
220
227
|
* Go to the given index.
|
|
221
228
|
*/
|
|
222
|
-
goTo(index
|
|
229
|
+
goTo(index) {
|
|
223
230
|
if (index < 0 || index > this.indexMax) {
|
|
224
231
|
throw new Error("Index out of bound.");
|
|
225
232
|
}
|
|
226
|
-
const currentState = this.getStateValueByMode(this.currentState.x);
|
|
227
233
|
const state = this.getStateValueByMode(this.states[index].x);
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
if (currentState !== state && withInstantMove) {
|
|
232
|
-
item.moveInstantly(currentState);
|
|
233
|
-
}
|
|
234
|
-
nextFrame(() => item.move(state));
|
|
235
|
-
});
|
|
236
|
-
invisibleItemsToMoveInstantly.forEach((item) => {
|
|
237
|
-
item.moveInstantly(state);
|
|
238
|
-
});
|
|
234
|
+
for (const item of this.$children.SliderItem) {
|
|
235
|
+
item.move(state);
|
|
236
|
+
}
|
|
239
237
|
this.currentIndex = index;
|
|
240
238
|
this.$emit("goto", index);
|
|
241
239
|
}
|
|
@@ -255,9 +253,9 @@ class Slider extends Base {
|
|
|
255
253
|
return;
|
|
256
254
|
}
|
|
257
255
|
this.__distanceX = this.__initialX + props.distance.x * this.$options.sensitivity;
|
|
258
|
-
|
|
256
|
+
for (const item of this.$children.SliderItem) {
|
|
259
257
|
item.moveInstantly(this.__distanceX);
|
|
260
|
-
}
|
|
258
|
+
}
|
|
261
259
|
}
|
|
262
260
|
/**
|
|
263
261
|
* Listen to the Draggable `drop` event and find the new active slide.
|
|
@@ -281,15 +279,15 @@ class Slider extends Base {
|
|
|
281
279
|
const minimumDifference = Math.min(...absoluteDifferencesBetweenDistanceAndState);
|
|
282
280
|
const closestIndex = absoluteDifferencesBetweenDistanceAndState.indexOf(minimumDifference);
|
|
283
281
|
if (this.$options.fitBounds) {
|
|
284
|
-
this.goTo(closestIndex
|
|
282
|
+
this.goTo(closestIndex);
|
|
285
283
|
} else {
|
|
286
284
|
if (this.$options.contain) {
|
|
287
285
|
finalX = Math.min(this.containMinState, finalX);
|
|
288
286
|
finalX = Math.max(this.containMaxState, finalX);
|
|
289
287
|
}
|
|
290
|
-
this.$children.SliderItem
|
|
288
|
+
for (const item of this.$children.SliderItem) {
|
|
291
289
|
item.move(finalX);
|
|
292
|
-
}
|
|
290
|
+
}
|
|
293
291
|
this.currentIndex = closestIndex;
|
|
294
292
|
}
|
|
295
293
|
}
|
|
@@ -317,64 +315,6 @@ class Slider extends Base {
|
|
|
317
315
|
}
|
|
318
316
|
}
|
|
319
317
|
}
|
|
320
|
-
/**
|
|
321
|
-
* Prepare invisible items.
|
|
322
|
-
*/
|
|
323
|
-
prepareInvisibleItems() {
|
|
324
|
-
const state = this.states[this.currentIndex];
|
|
325
|
-
const nextItemsToPrepare = [];
|
|
326
|
-
const previousItemsToPrepare = [];
|
|
327
|
-
this.getInvisibleItems(this.getStateValueByMode(state.x)).forEach((item, i) => {
|
|
328
|
-
if (i > this.currentIndex) {
|
|
329
|
-
nextItemsToPrepare.push(item);
|
|
330
|
-
return;
|
|
331
|
-
}
|
|
332
|
-
if (i < this.currentIndex) {
|
|
333
|
-
previousItemsToPrepare.push(item);
|
|
334
|
-
}
|
|
335
|
-
});
|
|
336
|
-
nextItemsToPrepare.forEach((item) => {
|
|
337
|
-
const invisibleState = this.getStateWhereItemWillBeInvisible(item);
|
|
338
|
-
if (invisibleState) {
|
|
339
|
-
item.moveInstantly(this.getStateValueByMode(invisibleState.x));
|
|
340
|
-
}
|
|
341
|
-
});
|
|
342
|
-
previousItemsToPrepare.forEach((item) => {
|
|
343
|
-
const invisibleState = this.getStateWhereItemWillBeInvisible(item, { reversed: true });
|
|
344
|
-
if (invisibleState) {
|
|
345
|
-
item.moveInstantly(this.getStateValueByMode(invisibleState.x));
|
|
346
|
-
}
|
|
347
|
-
});
|
|
348
|
-
}
|
|
349
|
-
/**
|
|
350
|
-
* Get the state where the given item will be visible.
|
|
351
|
-
*/
|
|
352
|
-
getStateWhereItemWillBeInvisible(item, { reversed = false } = {}) {
|
|
353
|
-
const visibleStates = this.states.filter(
|
|
354
|
-
(state) => item.willBeVisible(this.getStateValueByMode(state.x))
|
|
355
|
-
);
|
|
356
|
-
const firstVisibleState = visibleStates[0];
|
|
357
|
-
const lastVisibleState = visibleStates.at(-1);
|
|
358
|
-
const firstVisibleStateIndex = this.states.findIndex(
|
|
359
|
-
(state) => this.getStateValueByMode(state.x) === this.getStateValueByMode(firstVisibleState.x)
|
|
360
|
-
);
|
|
361
|
-
const lastVisibleStateIndex = this.states.findIndex((state) => state.x === lastVisibleState.x);
|
|
362
|
-
return reversed ? this.states[lastVisibleStateIndex + 1] : this.states[firstVisibleStateIndex - 1];
|
|
363
|
-
}
|
|
364
|
-
/**
|
|
365
|
-
* Get the visible slides for the given position.
|
|
366
|
-
*/
|
|
367
|
-
getVisibleItems(target) {
|
|
368
|
-
return this.$children.SliderItem.filter((item) => item.isVisible || item.willBeVisible(target));
|
|
369
|
-
}
|
|
370
|
-
/**
|
|
371
|
-
* Get the invisible slides for the given position.
|
|
372
|
-
*/
|
|
373
|
-
getInvisibleItems(target) {
|
|
374
|
-
return this.$children.SliderItem.filter(
|
|
375
|
-
(item) => !item.isVisible && !item.willBeVisible(target)
|
|
376
|
-
);
|
|
377
|
-
}
|
|
378
318
|
}
|
|
379
319
|
export {
|
|
380
320
|
Slider
|
package/Slider/Slider.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/ui/Slider/Slider.ts"],
|
|
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 __isDragging = false;\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.setAccessibilityAttributes();\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 * Set accessibility attributes for the component\n */\n setAccessibilityAttributes() {\n this.$el.setAttribute('role', 'group');\n this.$el.setAttribute('aria-roledescription', 'carousel');\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 this.__isDragging = true;\n }\n\n /**\n * Listen to the Draggable `drag` event.\n */\n onSliderDragDrag({ args: [props] }: { args: [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({ args: [props] }: { args: [DragServiceProps] }) {\n if (!this.__isDragging) {\n return;\n }\n this.__isDragging = false;\n\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,
|
|
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 } 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 * Slider class.\n * @see https://ui.studiometa.dev/-/components/Slider/\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'],\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 /**\n * Distance on the x axis.\n * @private\n */\n __distanceX = 0;\n\n /**\n * Initial x position.\n * @private\n */\n __initialX = 0;\n\n /**\n * Index of the current active slide.\n * @private\n */\n __currentIndex = 0;\n\n /**\n * Drag state.\n * @private\n */\n __isDragging = false;\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 */\n hasFocus = false;\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 * 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') {\n this.$warn('The `center` mode is not yet compatible with the `contain` mode.');\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.setAccessibilityAttributes();\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.goTo(this.currentIndex);\n });\n });\n }\n\n /**\n * Set accessibility attributes for the component\n */\n setAccessibilityAttributes() {\n this.$el.setAttribute('role', 'group');\n this.$el.setAttribute('aria-roledescription', 'carousel');\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) {\n if (index < 0 || index > this.indexMax) {\n throw new Error('Index out of bound.');\n }\n\n const state = this.getStateValueByMode(this.states[index].x);\n\n for (const item of this.$children.SliderItem) {\n item.move(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 this.__isDragging = true;\n }\n\n /**\n * Listen to the Draggable `drag` event.\n */\n onSliderDragDrag({ args: [props] }: { args: [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 for (const item of this.$children.SliderItem) {\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({ args: [props] }: { args: [DragServiceProps] }) {\n if (!this.__isDragging) {\n return;\n }\n this.__isDragging = false;\n\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);\n } else {\n if (this.$options.contain) {\n finalX = Math.min(this.containMinState, finalX);\n finalX = Math.max(this.containMaxState, finalX);\n }\n for (const item of this.$children.SliderItem) {\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"],
|
|
5
|
+
"mappings": "AAAA,SAAS,YAAY;AAOrB,SAAS,OAAO,mBAAmB,iBAAiB;AACpD,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AA4BpB,MAAM,eAAgD,KAAsB;AAAA;AAAA;AAAA;AAAA,EAIjF,OAAO,SAAqB;AAAA,IAC1B,MAAM;AAAA,IACN,MAAM,CAAC,SAAS;AAAA,IAChB,OAAO,CAAC,QAAQ,OAAO;AAAA,IACvB,YAAY;AAAA,MACV;AAAA,MACA;AAAA,IACF;AAAA,IACA,SAAS;AAAA,MACP,MAAM,EAAE,MAAM,QAAQ,SAAS,OAAO;AAAA,MACtC,WAAW;AAAA,MACX,SAAS;AAAA,MACT,aAAa,EAAE,MAAM,QAAQ,SAAS,EAAE;AAAA,MACxC,iBAAiB,EAAE,MAAM,QAAQ,SAAS,EAAE;AAAA,IAC9C;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA,EAMd,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA,EAMb,iBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMjB,eAAe;AAAA;AAAA;AAAA;AAA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I,CAAC,UAClE,KAAK,IAAI,SAAS,KAAK,oBAAoB,MAAM,CAAC,CAAC;AAAA,IACrD;AACA,UAAM,oBAAoB,KAAK,IAAI,GAAG,0CAA0C;AAChF,UAAM,eAAe,2CAA2C,QAAQ,iBAAiB;AAEzF,QAAI,KAAK,SAAS,WAAW;AAC3B,WAAK,KAAK,YAAY;AAAA,IACxB,OAAO;AACL,UAAI,KAAK,SAAS,SAAS;AACzB,iBAAS,KAAK,IAAI,KAAK,iBAAiB,MAAM;AAC9C,iBAAS,KAAK,IAAI,KAAK,iBAAiB,MAAM;AAAA,MAChD;AACA,iBAAW,QAAQ,KAAK,UAAU,YAAY;AAC5C,aAAK,KAAK,MAAM;AAAA,MAClB;AACA,WAAK,eAAe;AAAA,IACtB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,iBAAiB;AACf,SAAK,WAAW;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA,EAKA,gBAAgB;AACd,SAAK,WAAW;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,EAAE,MAAM,OAAO,OAAO,GAAoB;AAC9C,QAAI,KAAK,YAAY,QAAQ;AAC3B,UAAI,MAAM;AACR,aAAK,OAAO;AAAA,MACd,WAAW,OAAO;AAChB,aAAK,OAAO;AAAA,MACd;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/Slider/SliderBtn.d.ts
CHANGED
|
@@ -17,13 +17,10 @@ export declare class SliderBtn<T extends BaseProps = BaseProps> extends Abstract
|
|
|
17
17
|
static config: BaseConfig;
|
|
18
18
|
/**
|
|
19
19
|
* Update attributes.
|
|
20
|
-
* @param {number} index
|
|
21
|
-
* @returns {void}
|
|
22
20
|
*/
|
|
23
21
|
update(index: number): void;
|
|
24
22
|
/**
|
|
25
23
|
* Go prev or next on click.
|
|
26
|
-
* @returns {void}
|
|
27
24
|
*/
|
|
28
25
|
onClick(): void;
|
|
29
26
|
}
|
package/Slider/SliderBtn.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { isDev } from "@studiometa/js-toolkit/utils";
|
|
2
1
|
import { AbstractSliderChild } from "./AbstractSliderChild.js";
|
|
3
2
|
class SliderBtn extends AbstractSliderChild {
|
|
4
3
|
/**
|
|
@@ -14,13 +13,11 @@ class SliderBtn extends AbstractSliderChild {
|
|
|
14
13
|
};
|
|
15
14
|
/**
|
|
16
15
|
* Update attributes.
|
|
17
|
-
* @param {number} index
|
|
18
|
-
* @returns {void}
|
|
19
16
|
*/
|
|
20
17
|
update(index) {
|
|
21
|
-
if (
|
|
22
|
-
|
|
23
|
-
`
|
|
18
|
+
if (this.$options.contain && !this.$parent.$options.contain) {
|
|
19
|
+
this.$warn(
|
|
20
|
+
`The contain option will only works if the parent Slider also has the contain option.`
|
|
24
21
|
);
|
|
25
22
|
}
|
|
26
23
|
const isContainMaxState = this.$options.contain && this.$parent.$options.contain && this.$parent.containMaxState === this.$parent.getStates()[index].x[this.$parent.$options.mode];
|
|
@@ -32,7 +29,6 @@ class SliderBtn extends AbstractSliderChild {
|
|
|
32
29
|
}
|
|
33
30
|
/**
|
|
34
31
|
* Go prev or next on click.
|
|
35
|
-
* @returns {void}
|
|
36
32
|
*/
|
|
37
33
|
onClick() {
|
|
38
34
|
const { prev, next } = this.$options;
|
package/Slider/SliderBtn.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/ui/Slider/SliderBtn.ts"],
|
|
4
|
-
"sourcesContent": ["import
|
|
5
|
-
"mappings": "
|
|
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 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 */\n update(index: number) {\n if (this.$options.contain && !this.$parent.$options.contain) {\n this.$warn(\n `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 */\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": "AACA,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,EAKA,OAAO,OAAe;AACpB,QAAI,KAAK,SAAS,WAAW,CAAC,KAAK,QAAQ,SAAS,SAAS;AAC3D,WAAK;AAAA,QACH;AAAA,MACF;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,EAKA,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
|
}
|
package/Slider/SliderCount.d.ts
CHANGED
|
@@ -15,8 +15,6 @@ export declare class SliderCount<T extends BaseProps = BaseProps> extends Abstra
|
|
|
15
15
|
static config: BaseConfig;
|
|
16
16
|
/**
|
|
17
17
|
* Update the current counter indicator.
|
|
18
|
-
* @param {number} index The new active index.
|
|
19
|
-
* @returns {void}
|
|
20
18
|
*/
|
|
21
19
|
update(index: number): void;
|
|
22
20
|
}
|
package/Slider/SliderCount.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { domScheduler } from "@studiometa/js-toolkit/utils";
|
|
1
2
|
import { AbstractSliderChild } from "./AbstractSliderChild.js";
|
|
2
3
|
class SliderCount extends AbstractSliderChild {
|
|
3
4
|
/**
|
|
@@ -9,11 +10,11 @@ class SliderCount extends AbstractSliderChild {
|
|
|
9
10
|
};
|
|
10
11
|
/**
|
|
11
12
|
* Update the current counter indicator.
|
|
12
|
-
* @param {number} index The new active index.
|
|
13
|
-
* @returns {void}
|
|
14
13
|
*/
|
|
15
14
|
update(index) {
|
|
16
|
-
|
|
15
|
+
domScheduler.write(() => {
|
|
16
|
+
this.$refs.current.textContent = `${index + 1}`;
|
|
17
|
+
});
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/ui/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 };\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
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { domScheduler } from '@studiometa/js-toolkit/utils';\nimport 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 update(index: number) {\n domScheduler.write(() => {\n this.$refs.current.textContent = `${index + 1}`;\n });\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,oBAAoB;AAE7B,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,EAKA,OAAO,OAAe;AACpB,iBAAa,MAAM,MAAM;AACvB,WAAK,MAAM,QAAQ,cAAc,GAAG,QAAQ,CAAC;AAAA,IAC/C,CAAC;AAAA,EACH;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/Slider/SliderDots.d.ts
CHANGED
|
@@ -16,7 +16,6 @@ export declare class SliderDots<T extends BaseProps = BaseProps> extends SliderD
|
|
|
16
16
|
static config: BaseConfig;
|
|
17
17
|
/**
|
|
18
18
|
* Get target.
|
|
19
|
-
* @returns {HTMLButtonElement[]}
|
|
20
19
|
*/
|
|
21
20
|
get target(): HTMLButtonElement[];
|
|
22
21
|
/**
|
|
@@ -25,8 +24,6 @@ export declare class SliderDots<T extends BaseProps = BaseProps> extends SliderD
|
|
|
25
24
|
currentIndex: number;
|
|
26
25
|
/**
|
|
27
26
|
* Update dots classes according to the new index.
|
|
28
|
-
* @param {number} index
|
|
29
|
-
* @returns {void}
|
|
30
27
|
*/
|
|
31
28
|
update(index: number): void;
|
|
32
29
|
/**
|
package/Slider/SliderDots.js
CHANGED
|
@@ -10,7 +10,6 @@ class SliderDots extends withTransition(AbstractSliderChild) {
|
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
12
12
|
* Get target.
|
|
13
|
-
* @returns {HTMLButtonElement[]}
|
|
14
13
|
*/
|
|
15
14
|
get target() {
|
|
16
15
|
return this.$refs.dots;
|
|
@@ -18,16 +17,16 @@ class SliderDots extends withTransition(AbstractSliderChild) {
|
|
|
18
17
|
/**
|
|
19
18
|
* The current active index.
|
|
20
19
|
*/
|
|
21
|
-
currentIndex =
|
|
20
|
+
currentIndex = -1;
|
|
22
21
|
/**
|
|
23
22
|
* Update dots classes according to the new index.
|
|
24
|
-
* @param {number} index
|
|
25
|
-
* @returns {void}
|
|
26
23
|
*/
|
|
27
24
|
update(index) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
if (index !== this.currentIndex) {
|
|
26
|
+
this.leave(this.$refs.dots[this.currentIndex]);
|
|
27
|
+
this.enter(this.$refs.dots[index]);
|
|
28
|
+
this.currentIndex = index;
|
|
29
|
+
}
|
|
31
30
|
}
|
|
32
31
|
/**
|
|
33
32
|
* Go to the given index on dot click.
|
package/Slider/SliderDots.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/ui/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
|
|
5
|
-
"mappings": "AACA,SAAS,sBAAsB;AAC/B,SAAS,2BAA2B;AAW7B,MAAM,mBAEH,eAAoC,mBAAmB,EAAuB;AAAA;AAAA;AAAA;AAAA,EAItF,OAAO,SAAqB;AAAA,IAC1B,MAAM;AAAA,IACN,MAAM,CAAC,QAAQ;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA
|
|
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 */\n get target() {\n return this.$refs.dots;\n }\n\n /**\n * The current active index.\n */\n currentIndex = -1;\n\n /**\n * Update dots classes according to the new index.\n */\n update(index: number) {\n if (index !== this.currentIndex) {\n this.leave(this.$refs.dots[this.currentIndex]);\n this.enter(this.$refs.dots[index]);\n this.currentIndex = index;\n }\n }\n\n /**\n * Go to the given index on dot click.\n */\n onDotsClick({ index }: { index: number }) {\n this.$parent.goTo(index);\n }\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,sBAAsB;AAC/B,SAAS,2BAA2B;AAW7B,MAAM,mBAEH,eAAoC,mBAAmB,EAAuB;AAAA;AAAA;AAAA;AAAA,EAItF,OAAO,SAAqB;AAAA,IAC1B,MAAM;AAAA,IACN,MAAM,CAAC,QAAQ;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,SAAS;AACX,WAAO,KAAK,MAAM;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA,EAKA,eAAe;AAAA;AAAA;AAAA;AAAA,EAKf,OAAO,OAAe;AACpB,QAAI,UAAU,KAAK,cAAc;AAC/B,WAAK,MAAM,KAAK,MAAM,KAAK,KAAK,YAAY,CAAC;AAC7C,WAAK,MAAM,KAAK,MAAM,KAAK,KAAK,CAAC;AACjC,WAAK,eAAe;AAAA,IACtB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,YAAY,EAAE,MAAM,GAAsB;AACxC,SAAK,QAAQ,KAAK,KAAK;AAAA,EACzB;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/Slider/SliderDrag.d.ts
CHANGED
package/Slider/SliderDrag.js
CHANGED
package/Slider/SliderDrag.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/ui/Slider/SliderDrag.ts"],
|
|
4
|
-
"sourcesContent": ["import type { BaseProps, BaseConfig, DragServiceProps } from '@studiometa/js-toolkit';\nimport { Base, withDrag } from '@studiometa/js-toolkit';\n\nexport interface SliderDragProps extends BaseProps {\n $options: {\n scrollLockThreshold: number;\n };\n}\n\n/**\n * SliderDrag class.\n */\nexport class SliderDrag<T extends BaseProps = BaseProps> extends withDrag(Base)<\n T & SliderDragProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'SliderDrag',\n emits: ['start', 'drag', 'drop', 'inertia', 'stop'],\n options: {\n scrollLockThreshold: {\n type: Number,\n default: 10,\n },\n },\n };\n\n /**\n * Test if the scroll should be blocked. Used with the touchmove event to prevent\n * scrolling vertically when trying to drag the slider.\n */\n get shouldPreventScroll() {\n const { distance } = this.$services.get('dragged') as DragServiceProps;\n return (\n Math.abs(distance.x) > this.$options.scrollLockThreshold &&\n Math.abs(distance.x) > Math.abs(distance.y)\n );\n }\n\n /**\n * Touchmove handler.\n
|
|
5
|
-
"mappings": "AACA,SAAS,MAAM,gBAAgB;AAWxB,MAAM,mBAAoD,SAAS,IAAI,EAE5E;AAAA;AAAA;AAAA;AAAA,EAIA,OAAO,SAAqB;AAAA,IAC1B,MAAM;AAAA,IACN,OAAO,CAAC,SAAS,QAAQ,QAAQ,WAAW,MAAM;AAAA,IAClD,SAAS;AAAA,MACP,qBAAqB;AAAA,QACnB,MAAM;AAAA,QACN,SAAS;AAAA,MACX;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,sBAAsB;AACxB,UAAM,EAAE,SAAS,IAAI,KAAK,UAAU,IAAI,SAAS;AACjD,WACE,KAAK,IAAI,SAAS,CAAC,IAAI,KAAK,SAAS,uBACrC,KAAK,IAAI,SAAS,CAAC,IAAI,KAAK,IAAI,SAAS,CAAC;AAAA,EAE9C;AAAA;AAAA;AAAA;AAAA
|
|
4
|
+
"sourcesContent": ["import type { BaseProps, BaseConfig, DragServiceProps } from '@studiometa/js-toolkit';\nimport { Base, withDrag } from '@studiometa/js-toolkit';\n\nexport interface SliderDragProps extends BaseProps {\n $options: {\n scrollLockThreshold: number;\n };\n}\n\n/**\n * SliderDrag class.\n */\nexport class SliderDrag<T extends BaseProps = BaseProps> extends withDrag(Base)<\n T & SliderDragProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'SliderDrag',\n emits: ['start', 'drag', 'drop', 'inertia', 'stop'],\n options: {\n scrollLockThreshold: {\n type: Number,\n default: 10,\n },\n },\n };\n\n /**\n * Test if the scroll should be blocked. Used with the touchmove event to prevent\n * scrolling vertically when trying to drag the slider.\n */\n get shouldPreventScroll() {\n const { distance } = this.$services.get('dragged') as DragServiceProps;\n return (\n Math.abs(distance.x) > this.$options.scrollLockThreshold &&\n Math.abs(distance.x) > Math.abs(distance.y)\n );\n }\n\n /**\n * Touchmove handler.\n */\n onTouchmove({ event }: { event: TouchEvent }) {\n if (this.shouldPreventScroll) {\n event.preventDefault();\n }\n }\n\n /**\n * Emit drag events.\n */\n dragged(props: DragServiceProps) {\n this.$emit(props.mode, props);\n }\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,MAAM,gBAAgB;AAWxB,MAAM,mBAAoD,SAAS,IAAI,EAE5E;AAAA;AAAA;AAAA;AAAA,EAIA,OAAO,SAAqB;AAAA,IAC1B,MAAM;AAAA,IACN,OAAO,CAAC,SAAS,QAAQ,QAAQ,WAAW,MAAM;AAAA,IAClD,SAAS;AAAA,MACP,qBAAqB;AAAA,QACnB,MAAM;AAAA,QACN,SAAS;AAAA,MACX;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,sBAAsB;AACxB,UAAM,EAAE,SAAS,IAAI,KAAK,UAAU,IAAI,SAAS;AACjD,WACE,KAAK,IAAI,SAAS,CAAC,IAAI,KAAK,SAAS,uBACrC,KAAK,IAAI,SAAS,CAAC,IAAI,KAAK,IAAI,SAAS,CAAC;AAAA,EAE9C;AAAA;AAAA;AAAA;AAAA,EAKA,YAAY,EAAE,MAAM,GAA0B;AAC5C,QAAI,KAAK,qBAAqB;AAC5B,YAAM,eAAe;AAAA,IACvB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,QAAQ,OAAyB;AAC/B,SAAK,MAAM,MAAM,MAAM,KAAK;AAAA,EAC9B;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/Slider/SliderItem.d.ts
CHANGED
|
@@ -1,27 +1,21 @@
|
|
|
1
1
|
import { Base } from '@studiometa/js-toolkit';
|
|
2
2
|
import type { BaseProps, BaseConfig } from '@studiometa/js-toolkit';
|
|
3
|
-
|
|
3
|
+
export interface SliderItemProps extends BaseProps {
|
|
4
|
+
}
|
|
4
5
|
/**
|
|
5
|
-
*
|
|
6
|
+
* SliderItem class.
|
|
6
7
|
*/
|
|
7
|
-
export declare class SliderItem<T extends BaseProps = BaseProps> extends
|
|
8
|
+
export declare class SliderItem<T extends BaseProps = BaseProps> extends Base<T & SliderItemProps> {
|
|
8
9
|
/**
|
|
9
10
|
* Config.
|
|
10
11
|
*/
|
|
11
12
|
static config: BaseConfig;
|
|
12
|
-
/**
|
|
13
|
-
* Wether the SliderItem is visible or not.
|
|
14
|
-
* @type {boolean}
|
|
15
|
-
*/
|
|
16
|
-
isVisible: boolean;
|
|
17
13
|
/**
|
|
18
14
|
* The SliderItem `x` position.
|
|
19
|
-
* @type {number}
|
|
20
15
|
*/
|
|
21
16
|
x: number;
|
|
22
17
|
/**
|
|
23
18
|
* The smoothed `x` position.
|
|
24
|
-
* @type {number}
|
|
25
19
|
*/
|
|
26
20
|
dampedX: number;
|
|
27
21
|
/**
|
|
@@ -37,7 +31,13 @@ export declare class SliderItem<T extends BaseProps = BaseProps> extends SliderI
|
|
|
37
31
|
width: number;
|
|
38
32
|
height: number;
|
|
39
33
|
};
|
|
34
|
+
/**
|
|
35
|
+
* Wether the slider item size should be evaluated or not.
|
|
36
|
+
*/
|
|
40
37
|
shouldEvaluateRect: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Size of the slider item.
|
|
40
|
+
*/
|
|
41
41
|
get rect(): {
|
|
42
42
|
x: number;
|
|
43
43
|
y: number;
|
|
@@ -60,16 +60,11 @@ export declare class SliderItem<T extends BaseProps = BaseProps> extends SliderI
|
|
|
60
60
|
* Reset position to `0` on destroy.
|
|
61
61
|
*/
|
|
62
62
|
destroyed(): void;
|
|
63
|
-
/**
|
|
64
|
-
* Intersected hook.
|
|
65
|
-
*/
|
|
66
|
-
intersected([{ intersectionRatio, isIntersecting }]: IntersectionObserverEntry[]): void;
|
|
67
63
|
/**
|
|
68
64
|
* Ticked hook.
|
|
69
65
|
* @todo create AbstractSliderItem with `render` method
|
|
70
66
|
* @todo add state to SliderItem
|
|
71
67
|
* @todo add origin to SliderItem
|
|
72
|
-
* @returns {void}
|
|
73
68
|
*/
|
|
74
69
|
ticked(): void;
|
|
75
70
|
/**
|
|
@@ -96,15 +91,4 @@ export declare class SliderItem<T extends BaseProps = BaseProps> extends SliderI
|
|
|
96
91
|
* Render the component.
|
|
97
92
|
*/
|
|
98
93
|
render(): void;
|
|
99
|
-
/**
|
|
100
|
-
* Check if SliderItem is partially visible for the given target position.
|
|
101
|
-
*/
|
|
102
|
-
willBeVisible(targetPosition: number): boolean;
|
|
103
|
-
/**
|
|
104
|
-
* Check if SliderItem is fully visible for the given target position.
|
|
105
|
-
* @param {number} targetPosition
|
|
106
|
-
* @returns {boolean}
|
|
107
|
-
*/
|
|
108
|
-
willBeFullyVisible(targetPosition: any): boolean;
|
|
109
94
|
}
|
|
110
|
-
export {};
|