etudes 5.2.0 → 5.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/Accordion.js +171 -205
- package/components/BurgerButton.js +40 -94
- package/components/Carousel.js +87 -123
- package/components/Collection.js +84 -120
- package/components/Counter.js +32 -63
- package/components/CoverImage.js +24 -68
- package/components/CoverVideo.js +25 -69
- package/components/DebugConsole.js +27 -79
- package/components/Dial.js +28 -65
- package/components/Dropdown.js +86 -98
- package/components/FlatSVG.js +22 -71
- package/components/Image.js +21 -50
- package/components/MasonryGrid.js +122 -257
- package/components/Panorama.js +48 -92
- package/components/PanoramaSlider.js +57 -113
- package/components/RangeSlider.js +125 -182
- package/components/RotatingGallery.js +28 -59
- package/components/SelectableButton.js +10 -54
- package/components/Slider.js +108 -159
- package/components/StepwiseSlider.js +124 -176
- package/components/SwipeContainer.js +30 -73
- package/components/TextField.js +12 -49
- package/components/Video.js +31 -61
- package/components/WithTooltip.js +117 -111
- package/components/index.js +24 -0
- package/hooks/index.js +17 -0
- package/hooks/useClickOutsideEffect.js +8 -38
- package/hooks/useDragEffect.js +20 -53
- package/hooks/useDragValueEffect.js +31 -81
- package/hooks/useImageSize.js +16 -38
- package/hooks/useInterval.js +9 -41
- package/hooks/useLoadImageEffect.js +15 -48
- package/hooks/useLoadVideoMetadataEffect.js +15 -48
- package/hooks/useMounted.js +5 -25
- package/hooks/usePrevious.js +4 -9
- package/hooks/useRect.js +9 -29
- package/hooks/useResizeEffect.js +10 -44
- package/hooks/useScrollPositionEffect.js +19 -50
- package/hooks/useSearchParamState.js +12 -34
- package/hooks/useSize.js +9 -29
- package/hooks/useTimeout.js +8 -38
- package/hooks/useVideoSize.js +16 -38
- package/hooks/useViewportSize.js +7 -27
- package/operators/Conditional.js +6 -11
- package/operators/Each.js +6 -14
- package/operators/ExtractChild.js +9 -36
- package/operators/ExtractChildren.js +7 -34
- package/operators/Repeat.js +4 -37
- package/operators/index.js +5 -0
- package/package.json +27 -41
- package/providers/ScrollPositionProvider.js +37 -60
- package/providers/index.js +1 -0
- package/utils/asClassNameDict.js +1 -5
- package/utils/asComponentDict.js +11 -16
- package/utils/asStyleDict.js +1 -5
- package/utils/cloneStyledElement.js +14 -61
- package/utils/index.js +5 -22
- package/utils/styles.js +5 -21
- package/components/Accordion.d.ts +0 -219
- package/components/Accordion.js.map +0 -1
- package/components/BurgerButton.d.ts +0 -34
- package/components/BurgerButton.js.map +0 -1
- package/components/Carousel.d.ts +0 -53
- package/components/Carousel.js.map +0 -1
- package/components/Collection.d.ts +0 -171
- package/components/Collection.js.map +0 -1
- package/components/Counter.d.ts +0 -11
- package/components/Counter.js.map +0 -1
- package/components/CoverImage.d.ts +0 -28
- package/components/CoverImage.js.map +0 -1
- package/components/CoverVideo.d.ts +0 -28
- package/components/CoverVideo.js.map +0 -1
- package/components/DebugConsole.d.ts +0 -15
- package/components/DebugConsole.js.map +0 -1
- package/components/Dial.d.ts +0 -79
- package/components/Dial.js.map +0 -1
- package/components/Dropdown.d.ts +0 -109
- package/components/Dropdown.js.map +0 -1
- package/components/FlatSVG.d.ts +0 -72
- package/components/FlatSVG.js.map +0 -1
- package/components/Image.d.ts +0 -144
- package/components/Image.js.map +0 -1
- package/components/MasonryGrid.d.ts +0 -29
- package/components/MasonryGrid.js.map +0 -1
- package/components/Panorama.d.ts +0 -77
- package/components/Panorama.js.map +0 -1
- package/components/PanoramaSlider.d.ts +0 -71
- package/components/PanoramaSlider.js.map +0 -1
- package/components/RangeSlider.d.ts +0 -34
- package/components/RangeSlider.js.map +0 -1
- package/components/RotatingGallery.d.ts +0 -91
- package/components/RotatingGallery.js.map +0 -1
- package/components/SelectableButton.d.ts +0 -19
- package/components/SelectableButton.js.map +0 -1
- package/components/Slider.d.ts +0 -160
- package/components/Slider.js.map +0 -1
- package/components/StepwiseSlider.d.ts +0 -215
- package/components/StepwiseSlider.js.map +0 -1
- package/components/SwipeContainer.d.ts +0 -21
- package/components/SwipeContainer.js.map +0 -1
- package/components/TextField.d.ts +0 -21
- package/components/TextField.js.map +0 -1
- package/components/Video.d.ts +0 -38
- package/components/Video.js.map +0 -1
- package/components/WithTooltip.d.ts +0 -32
- package/components/WithTooltip.js.map +0 -1
- package/hooks/useClickOutsideEffect.d.ts +0 -2
- package/hooks/useClickOutsideEffect.js.map +0 -1
- package/hooks/useDragEffect.d.ts +0 -48
- package/hooks/useDragEffect.js.map +0 -1
- package/hooks/useDragValueEffect.d.ts +0 -56
- package/hooks/useDragValueEffect.js.map +0 -1
- package/hooks/useImageSize.d.ts +0 -21
- package/hooks/useImageSize.js.map +0 -1
- package/hooks/useInterval.d.ts +0 -18
- package/hooks/useInterval.js.map +0 -1
- package/hooks/useLoadImageEffect.d.ts +0 -43
- package/hooks/useLoadImageEffect.js.map +0 -1
- package/hooks/useLoadVideoMetadataEffect.d.ts +0 -35
- package/hooks/useLoadVideoMetadataEffect.js.map +0 -1
- package/hooks/useMounted.d.ts +0 -1
- package/hooks/useMounted.js.map +0 -1
- package/hooks/usePrevious.d.ts +0 -19
- package/hooks/usePrevious.js.map +0 -1
- package/hooks/useRect.d.ts +0 -11
- package/hooks/useRect.js.map +0 -1
- package/hooks/useResizeEffect.d.ts +0 -17
- package/hooks/useResizeEffect.js.map +0 -1
- package/hooks/useScrollPositionEffect.d.ts +0 -13
- package/hooks/useScrollPositionEffect.js.map +0 -1
- package/hooks/useSearchParamState.d.ts +0 -34
- package/hooks/useSearchParamState.js.map +0 -1
- package/hooks/useSize.d.ts +0 -10
- package/hooks/useSize.js.map +0 -1
- package/hooks/useTimeout.d.ts +0 -10
- package/hooks/useTimeout.js.map +0 -1
- package/hooks/useVideoSize.d.ts +0 -21
- package/hooks/useVideoSize.js.map +0 -1
- package/hooks/useViewportSize.d.ts +0 -7
- package/hooks/useViewportSize.js.map +0 -1
- package/operators/Conditional.d.ts +0 -5
- package/operators/Conditional.js.map +0 -1
- package/operators/Each.d.ts +0 -7
- package/operators/Each.js.map +0 -1
- package/operators/ExtractChild.d.ts +0 -8
- package/operators/ExtractChild.js.map +0 -1
- package/operators/ExtractChildren.d.ts +0 -6
- package/operators/ExtractChildren.js.map +0 -1
- package/operators/Repeat.d.ts +0 -11
- package/operators/Repeat.js.map +0 -1
- package/providers/ScrollPositionProvider.d.ts +0 -15
- package/providers/ScrollPositionProvider.js.map +0 -1
- package/utils/asClassNameDict.d.ts +0 -3
- package/utils/asClassNameDict.js.map +0 -1
- package/utils/asComponentDict.d.ts +0 -5
- package/utils/asComponentDict.js.map +0 -1
- package/utils/asStyleDict.d.ts +0 -4
- package/utils/asStyleDict.js.map +0 -1
- package/utils/cloneStyledElement.d.ts +0 -18
- package/utils/cloneStyledElement.js.map +0 -1
- package/utils/index.d.ts +0 -5
- package/utils/index.js.map +0 -1
- package/utils/styles.d.ts +0 -2
- package/utils/styles.js.map +0 -1
|
@@ -1,54 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
14
|
-
var t = {};
|
|
15
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
16
|
-
t[p] = s[p];
|
|
17
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
18
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
19
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
20
|
-
t[p[i]] = s[p[i]];
|
|
21
|
-
}
|
|
22
|
-
return t;
|
|
23
|
-
};
|
|
24
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
25
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
26
|
-
if (!m) return o;
|
|
27
|
-
var i = m.call(o), r, ar = [], e;
|
|
28
|
-
try {
|
|
29
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
30
|
-
}
|
|
31
|
-
catch (error) { e = { error: error }; }
|
|
32
|
-
finally {
|
|
33
|
-
try {
|
|
34
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
35
|
-
}
|
|
36
|
-
finally { if (e) throw e.error; }
|
|
37
|
-
}
|
|
38
|
-
return ar;
|
|
39
|
-
};
|
|
40
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
41
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
42
|
-
};
|
|
43
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
-
exports.StepwiseSliderLabel = exports.StepwiseSliderKnob = exports.StepwiseSliderTrack = exports.StepwiseSlider = void 0;
|
|
45
|
-
exports.generateSteps = generateSteps;
|
|
46
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
47
|
-
var clsx_1 = __importDefault(require("clsx"));
|
|
48
|
-
var react_1 = require("react");
|
|
49
|
-
var spase_1 = require("spase");
|
|
50
|
-
var useDragValueEffect_1 = require("../hooks/useDragValueEffect");
|
|
51
|
-
var utils_1 = require("../utils");
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import clsx from 'clsx';
|
|
3
|
+
import { forwardRef, useEffect, useRef, useState } from 'react';
|
|
4
|
+
import { Rect } from 'spase';
|
|
5
|
+
import { useDragValueEffect } from '../hooks/useDragValueEffect.js';
|
|
6
|
+
import { asClassNameDict, asComponentDict, asStyleDict, cloneStyledElement, styles } from '../utils/index.js';
|
|
52
7
|
/**
|
|
53
8
|
* A "stepwise" slider component supporting both horizontal and vertical
|
|
54
9
|
* orientations that automatically snaps to a set of predefined points on the
|
|
@@ -67,34 +22,30 @@ var utils_1 = require("../utils");
|
|
|
67
22
|
* @exports StepwiseSliderTrack The component for the slide track on either side
|
|
68
23
|
* of the knob.
|
|
69
24
|
*/
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
var trueNewPositionY = truePosition * rect.height + dy;
|
|
79
|
-
var trueNewPosition = orientation === 'vertical' ? Math.max(0, Math.min(1, trueNewPositionY / rect.height)) : Math.max(0, Math.min(1, trueNewPositionX / rect.width));
|
|
80
|
-
var normalizedPosition = isInverted ? 1 - trueNewPosition : trueNewPosition;
|
|
25
|
+
export const StepwiseSlider = forwardRef(({ children, className, index: externalIndex = 0, isInverted = false, isTrackInteractive = true, knobHeight = 30, knobWidth = 30, labelProvider, onlyDispatchesOnDragEnd = false, orientation = 'vertical', steps = generateSteps(10), trackPadding = 0, usesDefaultStyles = false, onDragEnd, onDragStart, onIndexChange, onPositionChange, ...props }, ref) => {
|
|
26
|
+
const mapDragValueToPosition = (value, dx, dy) => {
|
|
27
|
+
const rect = Rect.from(bodyRef.current) ?? new Rect();
|
|
28
|
+
const truePosition = isInverted ? 1 - value : value;
|
|
29
|
+
const trueNewPositionX = truePosition * rect.width + dx;
|
|
30
|
+
const trueNewPositionY = truePosition * rect.height + dy;
|
|
31
|
+
const trueNewPosition = orientation === 'vertical' ? Math.max(0, Math.min(1, trueNewPositionY / rect.height)) : Math.max(0, Math.min(1, trueNewPositionX / rect.width));
|
|
32
|
+
const normalizedPosition = isInverted ? 1 - trueNewPosition : trueNewPosition;
|
|
81
33
|
return normalizedPosition;
|
|
82
34
|
};
|
|
83
|
-
|
|
84
|
-
var _a;
|
|
35
|
+
const trackClickHandler = (event) => {
|
|
85
36
|
if (!isTrackInteractive)
|
|
86
37
|
return;
|
|
87
|
-
|
|
38
|
+
const rect = Rect.from(bodyRef.current) ?? new Rect();
|
|
88
39
|
switch (orientation) {
|
|
89
40
|
case 'horizontal': {
|
|
90
|
-
|
|
91
|
-
|
|
41
|
+
const trackPosition = (event.clientX - rect.left) / rect.width;
|
|
42
|
+
const normalizedPosition = isInverted ? 1 - trackPosition : trackPosition;
|
|
92
43
|
setPosition(normalizedPosition);
|
|
93
44
|
break;
|
|
94
45
|
}
|
|
95
46
|
case 'vertical': {
|
|
96
|
-
|
|
97
|
-
|
|
47
|
+
const trackPosition = (event.clientY - rect.top) / rect.height;
|
|
48
|
+
const normalizedPosition = isInverted ? 1 - trackPosition : trackPosition;
|
|
98
49
|
setPosition(normalizedPosition);
|
|
99
50
|
break;
|
|
100
51
|
}
|
|
@@ -102,32 +53,32 @@ exports.StepwiseSlider = (0, react_1.forwardRef)(function (_a, ref) {
|
|
|
102
53
|
break;
|
|
103
54
|
}
|
|
104
55
|
};
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
56
|
+
const bodyRef = useRef(null);
|
|
57
|
+
const knobContainerRef = useRef(null);
|
|
58
|
+
const [index, setIndex] = useState(externalIndex);
|
|
59
|
+
const { isDragging: [isDragging], isReleasing: [isReleasing], value: [position, setPosition] } = useDragValueEffect(knobContainerRef, {
|
|
109
60
|
initialValue: getPositionAt(externalIndex, steps),
|
|
110
61
|
transform: mapDragValueToPosition,
|
|
111
|
-
onDragStart
|
|
112
|
-
onDragEnd
|
|
113
|
-
})
|
|
62
|
+
onDragStart,
|
|
63
|
+
onDragEnd,
|
|
64
|
+
});
|
|
114
65
|
// Natural position is the position affecting internal components accounting
|
|
115
66
|
// for `isInverted`.
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
knob:
|
|
121
|
-
label:
|
|
122
|
-
track:
|
|
67
|
+
const naturalPosition = isInverted ? 1 - position : position;
|
|
68
|
+
const isAtEnd = isInverted ? position === 0 : position === 1;
|
|
69
|
+
const isAtStart = isInverted ? position === 1 : position === 0;
|
|
70
|
+
const components = asComponentDict(children, {
|
|
71
|
+
knob: StepwiseSliderKnob,
|
|
72
|
+
label: StepwiseSliderLabel,
|
|
73
|
+
track: StepwiseSliderTrack,
|
|
123
74
|
});
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
75
|
+
const fixedClassNames = getFixedClassNames({ orientation, isAtEnd, isAtStart, isDragging, isReleasing });
|
|
76
|
+
const fixedStyles = getFixedStyles({ orientation, naturalPosition, isDragging, knobHeight, knobWidth, isTrackInteractive });
|
|
77
|
+
const defaultStyles = usesDefaultStyles ? getDefaultStyles({ knobHeight }) : undefined;
|
|
78
|
+
useEffect(() => {
|
|
128
79
|
if (isDragging)
|
|
129
80
|
return;
|
|
130
|
-
|
|
81
|
+
const newPosition = getPositionAt(externalIndex, steps);
|
|
131
82
|
if (position !== newPosition) {
|
|
132
83
|
setPosition(newPosition);
|
|
133
84
|
}
|
|
@@ -135,71 +86,59 @@ exports.StepwiseSlider = (0, react_1.forwardRef)(function (_a, ref) {
|
|
|
135
86
|
setIndex(externalIndex);
|
|
136
87
|
}
|
|
137
88
|
}, [externalIndex]);
|
|
138
|
-
|
|
89
|
+
useEffect(() => {
|
|
139
90
|
if (isDragging && onlyDispatchesOnDragEnd)
|
|
140
91
|
return;
|
|
141
|
-
onPositionChange
|
|
142
|
-
|
|
92
|
+
onPositionChange?.(position, isDragging);
|
|
93
|
+
const newIndex = getNearestIndexByPosition(position, steps);
|
|
143
94
|
if (index !== newIndex)
|
|
144
95
|
setIndex(newIndex);
|
|
145
96
|
}, [position]);
|
|
146
|
-
|
|
147
|
-
onIndexChange
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
onIndexChange?.(index, isDragging);
|
|
148
99
|
}, [index]);
|
|
149
|
-
|
|
100
|
+
useEffect(() => {
|
|
150
101
|
if (isDragging)
|
|
151
102
|
return;
|
|
152
|
-
|
|
153
|
-
|
|
103
|
+
const nearestIndex = getNearestIndexByPosition(position, steps);
|
|
104
|
+
const nearestPosition = getPositionAt(nearestIndex, steps);
|
|
154
105
|
if (nearestPosition !== position || onlyDispatchesOnDragEnd) {
|
|
155
106
|
setPosition(nearestPosition);
|
|
156
|
-
onPositionChange
|
|
107
|
+
onPositionChange?.(nearestPosition, true);
|
|
157
108
|
}
|
|
158
109
|
}, [isDragging]);
|
|
159
|
-
return ((
|
|
160
|
-
className: (
|
|
161
|
-
style:
|
|
162
|
-
height:
|
|
110
|
+
return (_jsx("div", { ...props, ref: ref, className: clsx(className, fixedClassNames.root), "data-component": 'stepwise-slider', children: _jsxs("div", { ref: bodyRef, style: fixedStyles.body, children: [cloneStyledElement(components.track ?? _jsx(StepwiseSliderTrack, { style: defaultStyles?.track }), {
|
|
111
|
+
className: clsx('start', fixedClassNames.track),
|
|
112
|
+
style: styles(fixedStyles.track, orientation === 'vertical' ? {
|
|
113
|
+
height: `calc(${naturalPosition * 100}% - ${trackPadding <= 0 ? 0 : knobHeight * 0.5}px - ${trackPadding}px)`,
|
|
163
114
|
top: '0',
|
|
164
115
|
} : {
|
|
165
116
|
left: '0',
|
|
166
|
-
width:
|
|
117
|
+
width: `calc(${naturalPosition * 100}% - ${trackPadding <= 0 ? 0 : knobWidth * 0.5}px - ${trackPadding}px)`,
|
|
167
118
|
}),
|
|
168
119
|
onClick: trackClickHandler,
|
|
169
|
-
}, (
|
|
170
|
-
className: (
|
|
171
|
-
style:
|
|
120
|
+
}, _jsx("div", { style: fixedStyles.trackHitbox })), cloneStyledElement(components.track ?? _jsx(StepwiseSliderTrack, { style: defaultStyles?.track }), {
|
|
121
|
+
className: clsx('end', fixedClassNames.track),
|
|
122
|
+
style: styles(fixedStyles.track, orientation === 'vertical' ? {
|
|
172
123
|
bottom: '0',
|
|
173
|
-
height:
|
|
124
|
+
height: `calc(${(1 - naturalPosition) * 100}% - ${trackPadding <= 0 ? 0 : knobHeight * 0.5}px - ${trackPadding}px)`,
|
|
174
125
|
} : {
|
|
175
126
|
right: '0',
|
|
176
|
-
width:
|
|
127
|
+
width: `calc(${(1 - naturalPosition) * 100}% - ${trackPadding <= 0 ? 0 : knobWidth * 0.5}px - ${trackPadding}px)`,
|
|
177
128
|
}),
|
|
178
129
|
onClick: trackClickHandler,
|
|
179
|
-
}, (
|
|
180
|
-
className: (
|
|
181
|
-
style:
|
|
182
|
-
}, steps && labelProvider &&
|
|
183
|
-
className: (
|
|
184
|
-
style:
|
|
185
|
-
}, labelProvider(position, getNearestIndexByPosition(position, steps)))) })] }) }))
|
|
130
|
+
}, _jsx("div", { style: fixedStyles.trackHitbox })), _jsx("button", { ref: knobContainerRef, style: fixedStyles.knobContainer, children: cloneStyledElement(components.knob ?? _jsx(StepwiseSliderKnob, { style: defaultStyles?.knob }), {
|
|
131
|
+
className: clsx(fixedClassNames.knob),
|
|
132
|
+
style: styles(fixedStyles.knob),
|
|
133
|
+
}, steps && labelProvider && cloneStyledElement(components.label ?? _jsx(StepwiseSliderLabel, { style: defaultStyles?.label }), {
|
|
134
|
+
className: clsx(fixedClassNames.label),
|
|
135
|
+
style: styles(fixedStyles.label),
|
|
136
|
+
}, labelProvider(position, getNearestIndexByPosition(position, steps)))) })] }) }));
|
|
186
137
|
});
|
|
187
|
-
Object.defineProperty(
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
};
|
|
192
|
-
exports.StepwiseSliderTrack = StepwiseSliderTrack;
|
|
193
|
-
var StepwiseSliderKnob = function (_a) {
|
|
194
|
-
var props = __rest(_a, []);
|
|
195
|
-
return (0, jsx_runtime_1.jsx)("div", __assign({}, props, { "data-child": 'knob' }));
|
|
196
|
-
};
|
|
197
|
-
exports.StepwiseSliderKnob = StepwiseSliderKnob;
|
|
198
|
-
var StepwiseSliderLabel = function (_a) {
|
|
199
|
-
var props = __rest(_a, []);
|
|
200
|
-
return (0, jsx_runtime_1.jsx)("div", __assign({}, props, { "data-child": 'label' }));
|
|
201
|
-
};
|
|
202
|
-
exports.StepwiseSliderLabel = StepwiseSliderLabel;
|
|
138
|
+
Object.defineProperty(StepwiseSlider, 'displayName', { value: 'StepwiseSlider', writable: false });
|
|
139
|
+
export const StepwiseSliderTrack = ({ ...props }) => _jsx("div", { ...props, "data-child": 'track' });
|
|
140
|
+
export const StepwiseSliderKnob = ({ ...props }) => _jsx("div", { ...props, "data-child": 'knob' });
|
|
141
|
+
export const StepwiseSliderLabel = ({ ...props }) => _jsx("div", { ...props, "data-child": 'label' });
|
|
203
142
|
/**
|
|
204
143
|
* Generates a set of steps compatible with this component.
|
|
205
144
|
*
|
|
@@ -208,14 +147,14 @@ exports.StepwiseSliderLabel = StepwiseSliderLabel;
|
|
|
208
147
|
*
|
|
209
148
|
* @returns An array of steps.
|
|
210
149
|
*/
|
|
211
|
-
function generateSteps(length) {
|
|
150
|
+
export function generateSteps(length) {
|
|
212
151
|
if (length <= 1)
|
|
213
152
|
throw new Error('`length` value must be greater than or equal to 2');
|
|
214
153
|
if (Math.round(length) !== length)
|
|
215
154
|
throw new Error('`length` value must be an integer');
|
|
216
|
-
|
|
217
|
-
return Array(length).fill(null).map(
|
|
218
|
-
|
|
155
|
+
const interval = 1 / (length - 1);
|
|
156
|
+
return Array(length).fill(null).map((v, i) => {
|
|
157
|
+
const position = interval * i;
|
|
219
158
|
return position;
|
|
220
159
|
});
|
|
221
160
|
}
|
|
@@ -229,13 +168,13 @@ function generateSteps(length) {
|
|
|
229
168
|
* @returns The nearest index.
|
|
230
169
|
*/
|
|
231
170
|
function getNearestIndexByPosition(position, steps) {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
for (
|
|
235
|
-
|
|
171
|
+
let index = -1;
|
|
172
|
+
let minDelta = NaN;
|
|
173
|
+
for (let i = 0, n = steps.length; i < n; i++) {
|
|
174
|
+
const step = getPositionAt(i, steps);
|
|
236
175
|
if (isNaN(step))
|
|
237
176
|
continue;
|
|
238
|
-
|
|
177
|
+
const delta = Math.abs(position - step);
|
|
239
178
|
if (isNaN(minDelta) || delta < minDelta) {
|
|
240
179
|
minDelta = delta;
|
|
241
180
|
index = i;
|
|
@@ -257,28 +196,27 @@ function getPositionAt(index, steps) {
|
|
|
257
196
|
return NaN;
|
|
258
197
|
return steps[index];
|
|
259
198
|
}
|
|
260
|
-
function getFixedClassNames(
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
root: (0, clsx_1.default)(orientation, {
|
|
199
|
+
function getFixedClassNames({ orientation = 'vertical', isAtEnd = false, isAtStart = false, isDragging = false, isReleasing = false }) {
|
|
200
|
+
return asClassNameDict({
|
|
201
|
+
root: clsx(orientation, {
|
|
264
202
|
'at-end': isAtEnd,
|
|
265
203
|
'at-start': isAtStart,
|
|
266
204
|
'dragging': isDragging,
|
|
267
205
|
'releasing': isReleasing,
|
|
268
206
|
}),
|
|
269
|
-
track: (
|
|
207
|
+
track: clsx(orientation, {
|
|
270
208
|
'at-end': isAtEnd,
|
|
271
209
|
'at-start': isAtStart,
|
|
272
210
|
'dragging': isDragging,
|
|
273
211
|
'releasing': isReleasing,
|
|
274
212
|
}),
|
|
275
|
-
knob: (
|
|
213
|
+
knob: clsx(orientation, {
|
|
276
214
|
'at-end': isAtEnd,
|
|
277
215
|
'at-start': isAtStart,
|
|
278
216
|
'dragging': isDragging,
|
|
279
217
|
'releasing': isReleasing,
|
|
280
218
|
}),
|
|
281
|
-
label: (
|
|
219
|
+
label: clsx(orientation, {
|
|
282
220
|
'at-end': isAtEnd,
|
|
283
221
|
'at-start': isAtStart,
|
|
284
222
|
'dragging': isDragging,
|
|
@@ -286,42 +224,54 @@ function getFixedClassNames(_a) {
|
|
|
286
224
|
}),
|
|
287
225
|
});
|
|
288
226
|
}
|
|
289
|
-
function getFixedStyles(
|
|
290
|
-
|
|
291
|
-
return (0, utils_1.asStyleDict)({
|
|
227
|
+
function getFixedStyles({ orientation = 'vertical', naturalPosition = 0, isDragging = false, knobHeight = 0, knobWidth = 0, isTrackInteractive = false }) {
|
|
228
|
+
return asStyleDict({
|
|
292
229
|
body: {
|
|
293
230
|
height: '100%',
|
|
294
231
|
width: '100%',
|
|
295
232
|
},
|
|
296
|
-
knobContainer:
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
233
|
+
knobContainer: {
|
|
234
|
+
background: 'none',
|
|
235
|
+
border: 'none',
|
|
236
|
+
outline: 'none',
|
|
237
|
+
position: 'absolute',
|
|
238
|
+
transform: 'translate3d(-50%, -50%, 0)',
|
|
239
|
+
zIndex: '1',
|
|
240
|
+
...orientation === 'vertical' ? {
|
|
241
|
+
left: '50%',
|
|
242
|
+
top: `${naturalPosition * 100}%`,
|
|
243
|
+
transition: isDragging === false ? 'top 100ms ease-out' : 'none',
|
|
244
|
+
} : {
|
|
245
|
+
left: `${naturalPosition * 100}%`,
|
|
246
|
+
top: '50%',
|
|
247
|
+
transition: isDragging === false ? 'left 100ms ease-out' : 'none',
|
|
248
|
+
},
|
|
249
|
+
},
|
|
305
250
|
knob: {
|
|
306
|
-
height:
|
|
251
|
+
height: `${knobHeight}px`,
|
|
307
252
|
touchAction: 'none',
|
|
308
|
-
width:
|
|
253
|
+
width: `${knobWidth}px`,
|
|
309
254
|
},
|
|
310
255
|
label: {
|
|
311
256
|
pointerEvents: 'none',
|
|
312
257
|
userSelect: 'none',
|
|
313
258
|
},
|
|
314
|
-
track:
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
259
|
+
track: {
|
|
260
|
+
cursor: isTrackInteractive ? 'pointer' : 'auto',
|
|
261
|
+
pointerEvents: isTrackInteractive ? 'auto' : 'none',
|
|
262
|
+
position: 'absolute',
|
|
263
|
+
...orientation === 'vertical' ? {
|
|
264
|
+
left: '0',
|
|
265
|
+
margin: '0 auto',
|
|
266
|
+
right: '0',
|
|
267
|
+
width: '100%',
|
|
268
|
+
} : {
|
|
269
|
+
bottom: '0',
|
|
270
|
+
height: '100%',
|
|
271
|
+
margin: 'auto 0',
|
|
272
|
+
top: '0',
|
|
273
|
+
},
|
|
274
|
+
},
|
|
325
275
|
trackHitbox: {
|
|
326
276
|
height: '100%',
|
|
327
277
|
minHeight: '20px',
|
|
@@ -332,9 +282,8 @@ function getFixedStyles(_a) {
|
|
|
332
282
|
},
|
|
333
283
|
});
|
|
334
284
|
}
|
|
335
|
-
function getDefaultStyles(
|
|
336
|
-
|
|
337
|
-
return (0, utils_1.asStyleDict)({
|
|
285
|
+
function getDefaultStyles({ knobHeight = 0 }) {
|
|
286
|
+
return asStyleDict({
|
|
338
287
|
knob: {
|
|
339
288
|
alignItems: 'center',
|
|
340
289
|
background: '#fff',
|
|
@@ -345,11 +294,10 @@ function getDefaultStyles(_a) {
|
|
|
345
294
|
label: {
|
|
346
295
|
color: '#000',
|
|
347
296
|
fontSize: '12px',
|
|
348
|
-
lineHeight:
|
|
297
|
+
lineHeight: `${knobHeight}px`,
|
|
349
298
|
},
|
|
350
299
|
track: {
|
|
351
300
|
background: '#fff',
|
|
352
301
|
},
|
|
353
302
|
});
|
|
354
303
|
}
|
|
355
|
-
//# sourceMappingURL=StepwiseSlider.js.map
|
|
@@ -1,110 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
14
|
-
var t = {};
|
|
15
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
16
|
-
t[p] = s[p];
|
|
17
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
18
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
19
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
20
|
-
t[p[i]] = s[p[i]];
|
|
21
|
-
}
|
|
22
|
-
return t;
|
|
23
|
-
};
|
|
24
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
25
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
26
|
-
if (!m) return o;
|
|
27
|
-
var i = m.call(o), r, ar = [], e;
|
|
28
|
-
try {
|
|
29
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
30
|
-
}
|
|
31
|
-
catch (error) { e = { error: error }; }
|
|
32
|
-
finally {
|
|
33
|
-
try {
|
|
34
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
35
|
-
}
|
|
36
|
-
finally { if (e) throw e.error; }
|
|
37
|
-
}
|
|
38
|
-
return ar;
|
|
39
|
-
};
|
|
40
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
-
exports.SwipeContainer = void 0;
|
|
42
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
43
|
-
var react_1 = require("react");
|
|
44
|
-
var spase_1 = require("spase");
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useState } from 'react';
|
|
3
|
+
import { Point } from 'spase';
|
|
45
4
|
/**
|
|
46
5
|
* An empty component with a backing `<div>` element that detects swipe
|
|
47
6
|
* gestures.
|
|
48
7
|
*/
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
var onDragStart = function (x, y) {
|
|
8
|
+
export const SwipeContainer = forwardRef(({ children, isEnabled = true, threshold = 0.5, onSwipeDown, onSwipeLeft, onSwipeRight, onSwipeUp, ...props }, ref) => {
|
|
9
|
+
const [dragStartPosition, setDragStartPosition] = useState(undefined);
|
|
10
|
+
const [dragEndPosition, setDragEndPosition] = useState(undefined);
|
|
11
|
+
const [dragStartTime, setDragStartTime] = useState(NaN);
|
|
12
|
+
const onDragStart = (x, y) => {
|
|
55
13
|
if (isNaN(x) || isNaN(y))
|
|
56
14
|
return onDragCancel();
|
|
57
|
-
setDragStartPosition(new
|
|
15
|
+
setDragStartPosition(new Point([x, y]));
|
|
58
16
|
};
|
|
59
|
-
|
|
60
|
-
|
|
17
|
+
const onDragMove = (x, y) => {
|
|
18
|
+
const startPosition = dragStartPosition;
|
|
61
19
|
if (startPosition === undefined)
|
|
62
20
|
return;
|
|
63
|
-
|
|
64
|
-
|
|
21
|
+
const hasMovement = startPosition.x !== x || startPosition.y !== y;
|
|
22
|
+
const hasStartTime = !isNaN(dragStartTime);
|
|
65
23
|
if (!hasMovement)
|
|
66
24
|
return;
|
|
67
25
|
if (!hasStartTime)
|
|
68
26
|
setDragStartTime(Date.now());
|
|
69
|
-
setDragEndPosition(new
|
|
27
|
+
setDragEndPosition(new Point([x, y]));
|
|
70
28
|
};
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
29
|
+
const onDragEnd = () => {
|
|
30
|
+
const time = dragStartTime;
|
|
31
|
+
const startPosition = dragStartPosition;
|
|
32
|
+
const endPosition = dragEndPosition;
|
|
75
33
|
if (isNaN(time) || startPosition === undefined || endPosition === undefined)
|
|
76
34
|
return;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
35
|
+
const dt = Date.now() - time;
|
|
36
|
+
const dx = endPosition.x - startPosition.x;
|
|
37
|
+
const dy = endPosition.y - startPosition.y;
|
|
38
|
+
const vx = dx / dt;
|
|
39
|
+
const vy = dy / dt;
|
|
82
40
|
if (isEnabled) {
|
|
83
41
|
if (Math.abs(vx) >= threshold && Math.abs(vx) > Math.abs(vy)) {
|
|
84
42
|
if (vx > 0) {
|
|
85
|
-
onSwipeRight
|
|
43
|
+
onSwipeRight?.();
|
|
86
44
|
}
|
|
87
45
|
else {
|
|
88
|
-
onSwipeLeft
|
|
46
|
+
onSwipeLeft?.();
|
|
89
47
|
}
|
|
90
48
|
}
|
|
91
49
|
else if (Math.abs(vy) >= threshold && Math.abs(vy) > Math.abs(vx)) {
|
|
92
50
|
if (vy > 0) {
|
|
93
|
-
onSwipeDown
|
|
51
|
+
onSwipeDown?.();
|
|
94
52
|
}
|
|
95
53
|
else {
|
|
96
|
-
onSwipeUp
|
|
54
|
+
onSwipeUp?.();
|
|
97
55
|
}
|
|
98
56
|
}
|
|
99
57
|
}
|
|
100
58
|
onDragCancel();
|
|
101
59
|
};
|
|
102
|
-
|
|
60
|
+
const onDragCancel = () => {
|
|
103
61
|
setDragStartPosition(undefined);
|
|
104
62
|
setDragEndPosition(undefined);
|
|
105
63
|
setDragStartTime(NaN);
|
|
106
64
|
};
|
|
107
|
-
return ((
|
|
65
|
+
return (_jsx("div", { ...props, ref: ref, "data-component": 'swipe-container', onMouseDown: event => onDragStart(event.clientX, event.clientY), onMouseLeave: () => onDragCancel(), onMouseMove: event => onDragMove(event.clientX, event.clientY), onMouseUp: () => onDragEnd(), onTouchEnd: () => onDragEnd(), onTouchMove: event => onDragMove(event.targetTouches[0].clientX, event.targetTouches[0].clientY), onTouchStart: event => onDragStart(event.targetTouches[0].clientX, event.targetTouches[0].clientY), children: children }));
|
|
108
66
|
});
|
|
109
|
-
Object.defineProperty(
|
|
110
|
-
//# sourceMappingURL=SwipeContainer.js.map
|
|
67
|
+
Object.defineProperty(SwipeContainer, 'displayName', { value: 'SwipeContainer', writable: false });
|