etudes 5.2.0 → 5.3.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/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 +29 -42
- 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,112 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
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.BurgerButtonBar = exports.BurgerButton = void 0;
|
|
45
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
46
|
-
var clsx_1 = __importDefault(require("clsx"));
|
|
47
|
-
var react_1 = require("react");
|
|
48
|
-
var Repeat_1 = require("../operators/Repeat");
|
|
49
|
-
var utils_1 = require("../utils");
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import clsx from 'clsx';
|
|
3
|
+
import { forwardRef, useEffect, useState } from 'react';
|
|
4
|
+
import { Repeat } from '../operators/Repeat.js';
|
|
5
|
+
import { asClassNameDict, asComponentDict, asStyleDict, cloneStyledElement, styles } from '../utils/index.js';
|
|
50
6
|
/**
|
|
51
7
|
* Three-striped burger button component that transforms into an "X" when
|
|
52
8
|
* selected.
|
|
53
9
|
*
|
|
54
10
|
* @exports BurgerButtonBar Component for each line on the burger button.
|
|
55
11
|
*/
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
(0, react_1.useEffect)(function () {
|
|
12
|
+
export const BurgerButton = forwardRef(({ children, className, style, height = 20, isActive: externalIsActive = false, isDoubleJointed = false, isLastBarHalfWidth = false, thickness = 2, transitionDuration = 200, usesDefaultStyles = false, width = 20, onActivate, onDeactivate, ...props }, ref) => {
|
|
13
|
+
const [isActive, setIsActive] = useState(externalIsActive);
|
|
14
|
+
useEffect(() => {
|
|
60
15
|
if (isActive === externalIsActive)
|
|
61
16
|
return;
|
|
62
17
|
setIsActive(externalIsActive);
|
|
63
18
|
}, [externalIsActive]);
|
|
64
|
-
|
|
19
|
+
useEffect(() => {
|
|
65
20
|
if (isActive) {
|
|
66
|
-
onActivate
|
|
21
|
+
onActivate?.();
|
|
67
22
|
}
|
|
68
23
|
else {
|
|
69
|
-
onDeactivate
|
|
24
|
+
onDeactivate?.();
|
|
70
25
|
}
|
|
71
26
|
}, [isActive]);
|
|
72
|
-
|
|
73
|
-
bar:
|
|
27
|
+
const components = asComponentDict(children, {
|
|
28
|
+
bar: BurgerButtonBar,
|
|
74
29
|
});
|
|
75
|
-
|
|
76
|
-
root: (
|
|
30
|
+
const fixedClassNames = asClassNameDict({
|
|
31
|
+
root: clsx({
|
|
77
32
|
active: isActive,
|
|
78
33
|
}),
|
|
79
|
-
bar: (
|
|
34
|
+
bar: clsx({
|
|
80
35
|
active: isActive,
|
|
81
36
|
}),
|
|
82
37
|
});
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return ((
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
'data-index': i,
|
|
91
|
-
});
|
|
92
|
-
} }) })); } }) })));
|
|
38
|
+
const fixedStyles = getFixedStyles({ height, width, isDoubleJointed, thickness, isActive, isLastBarHalfWidth });
|
|
39
|
+
const defaultStyles = usesDefaultStyles ? getDefaultStyles() : undefined;
|
|
40
|
+
return (_jsx("button", { ...props, ref: ref, className: clsx(className, fixedClassNames.root), "data-component": 'burger-button', style: styles(style, fixedStyles.root), onClick: () => setIsActive(!isActive), children: _jsx(Repeat, { count: isDoubleJointed ? 2 : 1, children: j => (_jsx("div", { "data-child": 'joint', style: styles(fixedStyles.joint, fixedStyles[`joint${j}`]), children: _jsx(Repeat, { count: 3, children: i => cloneStyledElement(components.bar ?? _jsx(BurgerButtonBar, { style: defaultStyles?.bar }), {
|
|
41
|
+
'className': clsx(fixedClassNames.bar),
|
|
42
|
+
'style': styles(fixedStyles.bar, fixedStyles[`bar${j}${i}`]),
|
|
43
|
+
'data-index': i,
|
|
44
|
+
}) }) })) }) }));
|
|
93
45
|
});
|
|
94
|
-
Object.defineProperty(
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return (
|
|
98
|
-
};
|
|
99
|
-
exports.BurgerButtonBar = BurgerButtonBar;
|
|
100
|
-
function getFixedStyles(_a) {
|
|
101
|
-
var _b = _a.height, height = _b === void 0 ? 0 : _b, _c = _a.width, width = _c === void 0 ? 0 : _c, _d = _a.isDoubleJointed, isDoubleJointed = _d === void 0 ? false : _d, _e = _a.thickness, thickness = _e === void 0 ? 0 : _e, _f = _a.isActive, isActive = _f === void 0 ? false : _f, _g = _a.isLastBarHalfWidth, isLastBarHalfWidth = _g === void 0 ? false : _g;
|
|
102
|
-
return (0, utils_1.asStyleDict)({
|
|
46
|
+
Object.defineProperty(BurgerButton, 'displayName', { value: 'BurgerButton', writable: false });
|
|
47
|
+
export const BurgerButtonBar = ({ ...props }) => _jsx("span", { ...props, "data-child": 'bar' });
|
|
48
|
+
function getFixedStyles({ height = 0, width = 0, isDoubleJointed = false, thickness = 0, isActive = false, isLastBarHalfWidth = false }) {
|
|
49
|
+
return asStyleDict({
|
|
103
50
|
root: {
|
|
104
51
|
background: 'transparent',
|
|
105
52
|
border: 'none',
|
|
106
53
|
display: 'block',
|
|
107
|
-
height:
|
|
54
|
+
height: `${height}px`,
|
|
108
55
|
outline: 'none',
|
|
109
|
-
width:
|
|
56
|
+
width: `${width}px`,
|
|
110
57
|
},
|
|
111
58
|
joint: {
|
|
112
59
|
height: '100%',
|
|
@@ -122,7 +69,7 @@ function getFixedStyles(_a) {
|
|
|
122
69
|
top: '0',
|
|
123
70
|
},
|
|
124
71
|
bar: {
|
|
125
|
-
height:
|
|
72
|
+
height: `${thickness}px`,
|
|
126
73
|
margin: '0',
|
|
127
74
|
padding: '0',
|
|
128
75
|
position: 'absolute',
|
|
@@ -131,45 +78,45 @@ function getFixedStyles(_a) {
|
|
|
131
78
|
bar00: {
|
|
132
79
|
left: '0',
|
|
133
80
|
top: '0',
|
|
134
|
-
transform: isActive ?
|
|
81
|
+
transform: isActive ? `translate3d(0, ${height * 0.5 - thickness * 0.5}px, 0) rotate(45deg)` : 'translate3d(0, 0, 0) rotate(0deg)',
|
|
135
82
|
transformOrigin: isDoubleJointed ? 'right center' : 'center',
|
|
136
83
|
},
|
|
137
84
|
bar01: {
|
|
138
85
|
left: '0',
|
|
139
|
-
top:
|
|
86
|
+
top: `${height * 0.5 - thickness * 0.5}px`,
|
|
140
87
|
transform: isActive ? 'translate3d(0, 0, 0) scale(0)' : 'translate3d(0, 0, 0) scale(1)',
|
|
141
88
|
transformOrigin: isDoubleJointed ? 'right center' : 'center',
|
|
142
89
|
},
|
|
143
90
|
bar02: {
|
|
144
91
|
left: '0',
|
|
145
|
-
top:
|
|
146
|
-
transform: isActive ?
|
|
92
|
+
top: `${height - thickness}px`,
|
|
93
|
+
transform: isActive ? `translate3d(0, ${thickness * 0.5 - height * 0.5}px, 0) rotate(-45deg)` : 'translate3d(0, 0, 0) rotate(0deg)',
|
|
147
94
|
transformOrigin: isDoubleJointed ? 'right center' : 'center',
|
|
148
|
-
width: isActive || isDoubleJointed ? '100%' :
|
|
95
|
+
width: isActive || isDoubleJointed ? '100%' : `${isLastBarHalfWidth ? '50%' : '100%'}`,
|
|
149
96
|
},
|
|
150
97
|
bar10: {
|
|
151
98
|
left: '0',
|
|
152
99
|
top: '0',
|
|
153
|
-
transform: isActive ?
|
|
100
|
+
transform: isActive ? `translate3d(0, ${height * 0.5 - thickness * 0.5}px, 0) rotate(-45deg)` : 'translate3d(0, 0, 0) rotate(0deg)',
|
|
154
101
|
transformOrigin: 'left center',
|
|
155
102
|
},
|
|
156
103
|
bar11: {
|
|
157
104
|
left: '0',
|
|
158
|
-
top:
|
|
105
|
+
top: `${height * 0.5 - thickness * 0.5}px`,
|
|
159
106
|
transform: isActive ? 'translate3d(0, 0, 0) scale(0)' : 'translate3d(0, 0, 0) scale(1)',
|
|
160
107
|
transformOrigin: 'left center',
|
|
161
108
|
},
|
|
162
109
|
bar12: {
|
|
163
110
|
left: '0',
|
|
164
|
-
top:
|
|
165
|
-
transform: isActive ?
|
|
111
|
+
top: `${height - thickness}px`,
|
|
112
|
+
transform: isActive ? `translate3d(0, ${thickness * 0.5 - height * 0.5}px, 0) rotate(45deg)` : 'translate3d(0, 0, 0) rotate(0deg)',
|
|
166
113
|
transformOrigin: 'left center',
|
|
167
114
|
width: isLastBarHalfWidth && !isActive ? '0' : '100%',
|
|
168
115
|
},
|
|
169
116
|
});
|
|
170
117
|
}
|
|
171
118
|
function getDefaultStyles() {
|
|
172
|
-
return
|
|
119
|
+
return asStyleDict({
|
|
173
120
|
bar: {
|
|
174
121
|
background: '#fff',
|
|
175
122
|
transitionDuration: '100ms',
|
|
@@ -178,4 +125,3 @@ function getDefaultStyles() {
|
|
|
178
125
|
},
|
|
179
126
|
});
|
|
180
127
|
}
|
|
181
|
-
//# sourceMappingURL=BurgerButton.js.map
|
package/components/Carousel.js
CHANGED
|
@@ -1,69 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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.Carousel = void 0;
|
|
42
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
43
|
-
var react_1 = require("react");
|
|
44
|
-
var spase_1 = require("spase");
|
|
45
|
-
var useDragEffect_1 = require("../hooks/useDragEffect");
|
|
46
|
-
var useTimeout_1 = require("../hooks/useTimeout");
|
|
47
|
-
var Each_1 = require("../operators/Each");
|
|
48
|
-
var utils_1 = require("../utils");
|
|
49
|
-
exports.Carousel = (0, react_1.forwardRef)(function (_a, ref) {
|
|
50
|
-
var style = _a.style, _b = _a.autoAdvanceInterval, autoAdvanceInterval = _b === void 0 ? 0 : _b, _c = _a.index, index = _c === void 0 ? 0 : _c, _d = _a.isDragEnabled, isDragEnabled = _d === void 0 ? true : _d, _e = _a.items, items = _e === void 0 ? [] : _e, _f = _a.orientation, orientation = _f === void 0 ? 'horizontal' : _f, _g = _a.tracksItemExposure, tracksItemExposure = _g === void 0 ? false : _g, onAutoAdvancePause = _a.onAutoAdvancePause, onAutoAdvanceResume = _a.onAutoAdvanceResume, onIndexChange = _a.onIndexChange, ItemComponent = _a.ItemComponent, props = __rest(_a, ["style", "autoAdvanceInterval", "index", "isDragEnabled", "items", "orientation", "tracksItemExposure", "onAutoAdvancePause", "onAutoAdvanceResume", "onIndexChange", "ItemComponent"]);
|
|
51
|
-
var getItemExposures = function () {
|
|
52
|
-
var viewportElement = viewportRef.current;
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { Point, Rect } from 'spase';
|
|
4
|
+
import { useDragEffect } from '../hooks/useDragEffect.js';
|
|
5
|
+
import { useTimeout } from '../hooks/useTimeout.js';
|
|
6
|
+
import { Each } from '../operators/Each.js';
|
|
7
|
+
import { asStyleDict, styles } from '../utils/index.js';
|
|
8
|
+
export const Carousel = forwardRef(({ style, autoAdvanceInterval = 0, index = 0, isDragEnabled = true, items = [], orientation = 'horizontal', tracksItemExposure = false, onAutoAdvancePause, onAutoAdvanceResume, onIndexChange, ItemComponent, ...props }, ref) => {
|
|
9
|
+
const getItemExposures = () => {
|
|
10
|
+
const viewportElement = viewportRef.current;
|
|
53
11
|
if (!viewportElement)
|
|
54
12
|
return undefined;
|
|
55
|
-
|
|
56
|
-
for (
|
|
13
|
+
const exposures = [];
|
|
14
|
+
for (let i = 0; i < viewportElement.children.length; i++) {
|
|
57
15
|
exposures.push(getItemExposureAt(i));
|
|
58
16
|
}
|
|
59
17
|
return exposures;
|
|
60
18
|
};
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
19
|
+
const getItemExposureAt = (idx) => {
|
|
20
|
+
const viewportElement = viewportRef.current;
|
|
21
|
+
const child = viewportElement?.children[idx];
|
|
64
22
|
if (!child)
|
|
65
23
|
return 0;
|
|
66
|
-
|
|
24
|
+
const intersection = Rect.intersecting(child, viewportElement);
|
|
67
25
|
if (!intersection)
|
|
68
26
|
return 0;
|
|
69
27
|
switch (orientation) {
|
|
@@ -72,68 +30,68 @@ exports.Carousel = (0, react_1.forwardRef)(function (_a, ref) {
|
|
|
72
30
|
case 'vertical':
|
|
73
31
|
return Math.max(0, Math.min(1, Math.round((intersection.height / viewportElement.clientHeight + Number.EPSILON) * 1000) / 1000));
|
|
74
32
|
default:
|
|
75
|
-
throw new Error(
|
|
33
|
+
throw new Error(`Unsupported orientation '${orientation}'`);
|
|
76
34
|
}
|
|
77
35
|
};
|
|
78
|
-
|
|
79
|
-
onIndexChange
|
|
36
|
+
const handleIndexChange = (newValue) => {
|
|
37
|
+
onIndexChange?.(newValue);
|
|
80
38
|
};
|
|
81
|
-
|
|
82
|
-
pointerDownPositionRef.current = new
|
|
39
|
+
const handlePointerDown = (event) => {
|
|
40
|
+
pointerDownPositionRef.current = new Point([event.clientX, event.clientY]);
|
|
83
41
|
setIsPointerDown(true);
|
|
84
42
|
};
|
|
85
|
-
|
|
86
|
-
pointerUpPositionRef.current = new
|
|
43
|
+
const handlePointerUp = (event) => {
|
|
44
|
+
pointerUpPositionRef.current = new Point([event.clientX, event.clientY]);
|
|
87
45
|
setIsPointerDown(false);
|
|
88
46
|
};
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
47
|
+
const handleClick = (event) => {
|
|
48
|
+
const downPosition = pointerDownPositionRef.current;
|
|
49
|
+
const upPosition = pointerUpPositionRef.current;
|
|
92
50
|
if (!downPosition || !upPosition)
|
|
93
51
|
return;
|
|
94
|
-
|
|
95
|
-
|
|
52
|
+
const threshold = 5;
|
|
53
|
+
const delta = downPosition.subtract(upPosition);
|
|
96
54
|
if (Math.abs(delta.x) > threshold || Math.abs(delta.y) > threshold) {
|
|
97
55
|
event.stopPropagation();
|
|
98
56
|
}
|
|
99
57
|
pointerDownPositionRef.current = undefined;
|
|
100
58
|
pointerUpPositionRef.current = undefined;
|
|
101
59
|
};
|
|
102
|
-
|
|
103
|
-
|
|
60
|
+
const autoScrollToCurrentIndex = () => {
|
|
61
|
+
const viewportElement = viewportRef.current;
|
|
104
62
|
if (!viewportElement)
|
|
105
63
|
return;
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
viewportElement.scrollTo({ top
|
|
64
|
+
const top = orientation === 'horizontal' ? 0 : viewportElement.clientHeight * index;
|
|
65
|
+
const left = orientation === 'horizontal' ? viewportElement.clientWidth * index : 0;
|
|
66
|
+
viewportElement.scrollTo({ top, left, behavior: 'smooth' });
|
|
109
67
|
clearTimeout(autoScrollTimeoutRef.current);
|
|
110
|
-
autoScrollTimeoutRef.current = setTimeout(
|
|
68
|
+
autoScrollTimeoutRef.current = setTimeout(() => {
|
|
111
69
|
clearTimeout(autoScrollTimeoutRef.current);
|
|
112
70
|
autoScrollTimeoutRef.current = undefined;
|
|
113
71
|
}, autoScrollTimeoutMs);
|
|
114
72
|
};
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
73
|
+
const prevIndexRef = useRef();
|
|
74
|
+
const viewportRef = useRef(null);
|
|
75
|
+
const pointerDownPositionRef = useRef();
|
|
76
|
+
const pointerUpPositionRef = useRef();
|
|
77
|
+
const [exposures, setExposures] = useState(getItemExposures());
|
|
78
|
+
const autoScrollTimeoutRef = useRef();
|
|
79
|
+
const autoScrollTimeoutMs = 1000;
|
|
80
|
+
const [isPointerDown, setIsPointerDown] = useState(false);
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
const viewportElement = viewportRef.current;
|
|
125
83
|
if (!viewportElement)
|
|
126
84
|
return;
|
|
127
|
-
|
|
85
|
+
const scrollHandler = () => {
|
|
128
86
|
if (tracksItemExposure) {
|
|
129
87
|
setExposures(getItemExposures());
|
|
130
88
|
}
|
|
131
89
|
if (autoScrollTimeoutRef.current !== undefined)
|
|
132
90
|
return;
|
|
133
|
-
|
|
91
|
+
const newIndex = orientation === 'horizontal'
|
|
134
92
|
? Math.round(viewportElement.scrollLeft / viewportElement.clientWidth)
|
|
135
93
|
: Math.round(viewportElement.scrollTop / viewportElement.clientHeight);
|
|
136
|
-
|
|
94
|
+
const clampedIndex = Math.max(0, Math.min(items.length - 1, newIndex));
|
|
137
95
|
if (clampedIndex === index)
|
|
138
96
|
return;
|
|
139
97
|
// Set previous index ref here to avoid the side-effect of handling index
|
|
@@ -142,13 +100,13 @@ exports.Carousel = (0, react_1.forwardRef)(function (_a, ref) {
|
|
|
142
100
|
handleIndexChange(clampedIndex);
|
|
143
101
|
};
|
|
144
102
|
viewportElement.addEventListener('scroll', scrollHandler);
|
|
145
|
-
return
|
|
103
|
+
return () => {
|
|
146
104
|
viewportElement.removeEventListener('scroll', scrollHandler);
|
|
147
105
|
};
|
|
148
106
|
}, [index, orientation]);
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
const isInitialRender = prevIndexRef.current === undefined;
|
|
109
|
+
const isIndexModifiedFromManualScrolling = prevIndexRef.current === index;
|
|
152
110
|
if (isIndexModifiedFromManualScrolling)
|
|
153
111
|
return;
|
|
154
112
|
prevIndexRef.current = index;
|
|
@@ -157,62 +115,69 @@ exports.Carousel = (0, react_1.forwardRef)(function (_a, ref) {
|
|
|
157
115
|
handleIndexChange(index);
|
|
158
116
|
autoScrollToCurrentIndex();
|
|
159
117
|
}, [index, orientation]);
|
|
160
|
-
|
|
118
|
+
useEffect(() => {
|
|
161
119
|
if (autoAdvanceInterval <= 0)
|
|
162
120
|
return;
|
|
163
121
|
if (isPointerDown) {
|
|
164
|
-
onAutoAdvancePause
|
|
122
|
+
onAutoAdvancePause?.();
|
|
165
123
|
}
|
|
166
124
|
else {
|
|
167
|
-
onAutoAdvanceResume
|
|
125
|
+
onAutoAdvanceResume?.();
|
|
168
126
|
}
|
|
169
127
|
}, [isPointerDown]);
|
|
170
|
-
|
|
128
|
+
useDragEffect(viewportRef, {
|
|
171
129
|
isEnabled: isDragEnabled && items.length > 1,
|
|
172
|
-
onDragMove:
|
|
130
|
+
onDragMove: (displacement) => {
|
|
173
131
|
switch (orientation) {
|
|
174
132
|
case 'horizontal':
|
|
175
|
-
requestAnimationFrame(
|
|
133
|
+
requestAnimationFrame(() => {
|
|
176
134
|
if (!viewportRef.current)
|
|
177
135
|
return;
|
|
178
136
|
viewportRef.current.scrollLeft += displacement.x * 1.5;
|
|
179
137
|
});
|
|
180
138
|
break;
|
|
181
139
|
case 'vertical':
|
|
182
|
-
requestAnimationFrame(
|
|
140
|
+
requestAnimationFrame(() => {
|
|
183
141
|
if (!viewportRef.current)
|
|
184
142
|
return;
|
|
185
143
|
viewportRef.current.scrollTop += displacement.y * 1.5;
|
|
186
144
|
});
|
|
187
145
|
break;
|
|
188
146
|
default:
|
|
189
|
-
throw Error(
|
|
147
|
+
throw Error(`Unsupported orientation '${orientation}'`);
|
|
190
148
|
}
|
|
191
149
|
},
|
|
192
150
|
});
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
return ((
|
|
196
|
-
var itemStyle = _a.style, itemProps = __rest(_a, ["style"]);
|
|
197
|
-
return ((0, jsx_runtime_1.jsx)("div", { style: (0, utils_1.styles)(fixedStyles.itemContainer), children: (0, jsx_runtime_1.jsx)(ItemComponent, __assign({ "data-child": 'item', exposure: tracksItemExposure ? exposures === null || exposures === void 0 ? void 0 : exposures[idx] : undefined, style: (0, utils_1.styles)(itemStyle, fixedStyles.item) }, itemProps)) }));
|
|
198
|
-
} }) }) })));
|
|
151
|
+
useTimeout(() => handleIndexChange((index + items.length + 1) % items.length), (isPointerDown || autoAdvanceInterval <= 0) ? -1 : autoAdvanceInterval, [isPointerDown, index, items.length]);
|
|
152
|
+
const fixedStyles = getFixedStyles({ isPointerDown, orientation });
|
|
153
|
+
return (_jsx("div", { ...props, ref: ref, "data-component": 'carousel', style: styles(style, fixedStyles.root), onClick: event => handleClick(event), onPointerDown: event => handlePointerDown(event), onPointerLeave: event => handlePointerUp(event), onPointerUp: event => handlePointerUp(event), children: _jsx("div", { ref: viewportRef, "data-child": 'viewport', style: styles(fixedStyles.viewport), children: _jsx(Each, { in: items, children: ({ style: itemStyle, ...itemProps }, idx) => (_jsx("div", { style: styles(fixedStyles.itemContainer), children: _jsx(ItemComponent, { "data-child": 'item', exposure: tracksItemExposure ? exposures?.[idx] : undefined, style: styles(itemStyle, fixedStyles.item), ...itemProps }) })) }) }) }));
|
|
199
154
|
});
|
|
200
|
-
Object.defineProperty(
|
|
201
|
-
function getFixedStyles(
|
|
202
|
-
|
|
203
|
-
return (0, utils_1.asStyleDict)({
|
|
155
|
+
Object.defineProperty(Carousel, 'displayName', { value: 'Carousel', writable: false });
|
|
156
|
+
function getFixedStyles({ isPointerDown = false, orientation = 'horizontal' }) {
|
|
157
|
+
return asStyleDict({
|
|
204
158
|
root: {},
|
|
205
|
-
viewport:
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
159
|
+
viewport: {
|
|
160
|
+
alignItems: 'center',
|
|
161
|
+
display: 'flex',
|
|
162
|
+
height: '100%',
|
|
163
|
+
userSelect: isPointerDown ? 'none' : 'auto',
|
|
164
|
+
justifyContent: 'flex-start',
|
|
165
|
+
scrollBehavior: isPointerDown ? 'auto' : 'smooth',
|
|
166
|
+
scrollSnapStop: isPointerDown ? 'unset' : 'always',
|
|
167
|
+
WebkitOverflowScrolling: 'touch',
|
|
168
|
+
width: '100%',
|
|
169
|
+
...orientation === 'horizontal' ? {
|
|
170
|
+
flexDirection: 'row',
|
|
171
|
+
overflowX: 'scroll',
|
|
172
|
+
overflowY: 'hidden',
|
|
173
|
+
scrollSnapType: isPointerDown ? 'none' : 'x mandatory',
|
|
174
|
+
} : {
|
|
175
|
+
flexDirection: 'column',
|
|
176
|
+
overflowX: 'hidden',
|
|
177
|
+
overflowY: 'scroll',
|
|
178
|
+
scrollSnapType: isPointerDown ? 'none' : 'y mandatory',
|
|
179
|
+
},
|
|
180
|
+
},
|
|
216
181
|
itemContainer: {
|
|
217
182
|
height: '100%',
|
|
218
183
|
overflow: 'hidden',
|
|
@@ -227,4 +192,3 @@ function getFixedStyles(_a) {
|
|
|
227
192
|
},
|
|
228
193
|
});
|
|
229
194
|
}
|
|
230
|
-
//# sourceMappingURL=Carousel.js.map
|