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
package/components/Panorama.js
CHANGED
|
@@ -1,78 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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.Panorama = 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 useDragValueEffect_1 = require("../hooks/useDragValueEffect");
|
|
46
|
-
var useImageSize_1 = require("../hooks/useImageSize");
|
|
47
|
-
var useRect_1 = require("../hooks/useRect");
|
|
48
|
-
var utils_1 = require("../utils");
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { Size } from 'spase';
|
|
4
|
+
import { useDragValueEffect } from '../hooks/useDragValueEffect.js';
|
|
5
|
+
import { useImageSize } from '../hooks/useImageSize.js';
|
|
6
|
+
import { useRect } from '../hooks/useRect.js';
|
|
7
|
+
import { asStyleDict } from '../utils/index.js';
|
|
49
8
|
/**
|
|
50
9
|
* A component containing a pannable 360° panorama image. The angle supports two-way binding.
|
|
51
10
|
*/
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
var newDisplacement = currentPosition - dx * speed;
|
|
11
|
+
export const Panorama = forwardRef(({ angle: externalAngle = 0, speed = 1, src, zeroAnchor = 0, onAngleChange, onPositionChange, onDragStart, onDragEnd, onLoadImageStart, onLoadImageComplete, onLoadImageError, onImageSizeChange, ...props }, ref) => {
|
|
12
|
+
const mapDragPositionToDisplacement = (currentPosition, dx, dy) => {
|
|
13
|
+
const newDisplacement = currentPosition - dx * speed;
|
|
56
14
|
return newDisplacement;
|
|
57
15
|
};
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
16
|
+
const bodyRef = useRef(null);
|
|
17
|
+
const bodyRect = useRect(bodyRef);
|
|
18
|
+
const imageSize = useImageSize({ src }, {
|
|
61
19
|
onLoadStart: onLoadImageStart,
|
|
62
20
|
onLoadComplete: onLoadImageComplete,
|
|
63
21
|
onLoadError: onLoadImageError,
|
|
64
22
|
});
|
|
65
|
-
|
|
66
|
-
|
|
23
|
+
const [angle, setAngle] = useState(externalAngle);
|
|
24
|
+
const { isDragging: [isDragging], value: [displacement, setDisplacement] } = useDragValueEffect(bodyRef, {
|
|
67
25
|
initialValue: 0,
|
|
68
26
|
transform: mapDragPositionToDisplacement,
|
|
69
|
-
onDragStart
|
|
70
|
-
onDragEnd
|
|
71
|
-
})
|
|
72
|
-
|
|
27
|
+
onDragStart,
|
|
28
|
+
onDragEnd,
|
|
29
|
+
});
|
|
30
|
+
useEffect(() => {
|
|
73
31
|
if (isDragging || !imageSize)
|
|
74
32
|
return;
|
|
75
|
-
|
|
33
|
+
const newDisplacement = getDisplacementFromAngle(externalAngle, imageSize, bodyRect.size, zeroAnchor);
|
|
76
34
|
if (newDisplacement !== displacement) {
|
|
77
35
|
setDisplacement(newDisplacement);
|
|
78
36
|
}
|
|
@@ -80,31 +38,30 @@ exports.Panorama = (0, react_1.forwardRef)(function (_a, ref) {
|
|
|
80
38
|
setAngle(externalAngle);
|
|
81
39
|
}
|
|
82
40
|
}, [externalAngle, imageSize, bodyRect.width, bodyRect.height, zeroAnchor]);
|
|
83
|
-
|
|
41
|
+
useEffect(() => {
|
|
84
42
|
if (!isDragging || !imageSize)
|
|
85
43
|
return;
|
|
86
|
-
|
|
44
|
+
const newAngle = getAngleFromDisplacement(displacement, imageSize, bodyRect.size, zeroAnchor);
|
|
87
45
|
if (angle !== newAngle) {
|
|
88
46
|
setAngle(newAngle);
|
|
89
47
|
}
|
|
90
48
|
}, [displacement, imageSize, bodyRect.width, bodyRect.height, zeroAnchor]);
|
|
91
|
-
|
|
92
|
-
onAngleChange
|
|
93
|
-
onPositionChange
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
onAngleChange?.(angle, isDragging);
|
|
51
|
+
onPositionChange?.(angle / 360, isDragging);
|
|
94
52
|
}, [angle]);
|
|
95
|
-
|
|
96
|
-
onImageSizeChange
|
|
97
|
-
}, [imageSize
|
|
98
|
-
|
|
99
|
-
return ((
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
onImageSizeChange?.(imageSize);
|
|
55
|
+
}, [imageSize?.width, imageSize?.height]);
|
|
56
|
+
const fixedStyles = getFixedStyles({ src, displacement });
|
|
57
|
+
return (_jsx("div", { ...props, ref: ref, "data-component": 'panorama', children: _jsx("div", { ref: bodyRef, style: fixedStyles.body }) }));
|
|
100
58
|
});
|
|
101
|
-
Object.defineProperty(
|
|
102
|
-
function getFixedStyles(
|
|
103
|
-
|
|
104
|
-
return (0, utils_1.asStyleDict)({
|
|
59
|
+
Object.defineProperty(Panorama, 'displayName', { value: 'Panorama', writable: false });
|
|
60
|
+
function getFixedStyles({ src = '', displacement = NaN }) {
|
|
61
|
+
return asStyleDict({
|
|
105
62
|
body: {
|
|
106
|
-
backgroundImage:
|
|
107
|
-
backgroundPositionX:
|
|
63
|
+
backgroundImage: `url(${src})`,
|
|
64
|
+
backgroundPositionX: `${-displacement}px`,
|
|
108
65
|
backgroundRepeat: 'repeat',
|
|
109
66
|
backgroundSize: 'auto 100%',
|
|
110
67
|
height: '100%',
|
|
@@ -114,27 +71,26 @@ function getFixedStyles(_a) {
|
|
|
114
71
|
});
|
|
115
72
|
}
|
|
116
73
|
function getFilledImageSize(originalSize, sizeToFill) {
|
|
117
|
-
|
|
118
|
-
|
|
74
|
+
const { width: originalWidth, height: originalHeight } = originalSize;
|
|
75
|
+
const { height: filledHeignt } = sizeToFill;
|
|
119
76
|
if (originalHeight <= 0)
|
|
120
|
-
return new
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
return new
|
|
77
|
+
return new Size();
|
|
78
|
+
const aspectRatio = filledHeignt / originalHeight;
|
|
79
|
+
const filledWidth = aspectRatio * originalWidth;
|
|
80
|
+
return new Size([filledWidth, filledHeignt]);
|
|
124
81
|
}
|
|
125
82
|
function getDisplacementFromAngle(angle, originalImageSize, componentSize, zeroAnchor) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
83
|
+
const { width: imageWidth } = getFilledImageSize(originalImageSize, componentSize);
|
|
84
|
+
const { width: componentWidth } = componentSize;
|
|
85
|
+
const offset = componentWidth * zeroAnchor;
|
|
129
86
|
return angle / 360 * imageWidth - offset;
|
|
130
87
|
}
|
|
131
88
|
function getAngleFromDisplacement(displacement, originalImageSize, componentSize, zeroAnchor) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
89
|
+
const { width: imageWidth } = getFilledImageSize(originalImageSize, componentSize);
|
|
90
|
+
const { width: componentWidth } = componentSize;
|
|
91
|
+
const offset = componentWidth * zeroAnchor;
|
|
92
|
+
let angle = (displacement + offset) % imageWidth / imageWidth * 360;
|
|
136
93
|
while (angle < 0)
|
|
137
94
|
angle += 360;
|
|
138
95
|
return angle;
|
|
139
96
|
}
|
|
140
|
-
//# sourceMappingURL=Panorama.js.map
|
|
@@ -1,54 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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.PanoramaSliderIndicator = exports.PanoramaSliderReticle = exports.PanoramaSliderTrack = exports.PanoramaSlider = 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 spase_1 = require("spase");
|
|
49
|
-
var useRect_1 = require("../hooks/useRect");
|
|
50
|
-
var utils_1 = require("../utils");
|
|
51
|
-
var Panorama_1 = require("./Panorama");
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import clsx from 'clsx';
|
|
3
|
+
import { forwardRef, useRef, useState } from 'react';
|
|
4
|
+
import { Rect } from 'spase';
|
|
5
|
+
import { useRect } from '../hooks/useRect.js';
|
|
6
|
+
import { asComponentDict, asStyleDict, cloneStyledElement, styles } from '../utils/index.js';
|
|
7
|
+
import { Panorama } from './Panorama.js';
|
|
52
8
|
/**
|
|
53
9
|
* A slider for a {@link Panorama} component.
|
|
54
10
|
*
|
|
@@ -58,80 +14,68 @@ var Panorama_1 = require("./Panorama");
|
|
|
58
14
|
* backing {@link Panorama}.
|
|
59
15
|
* @exports PanoramaSliderTrack The slide track.
|
|
60
16
|
*/
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
var className = _a.className, style = _a.style, _f = _a.angle, angle = _f === void 0 ? 0 : _f, _g = _a.autoDimension, autoDimension = _g === void 0 ? 'width' : _g, children = _a.children, fov = _a.fov, _h = _a.speed, speed = _h === void 0 ? 1 : _h, src = _a.src, _j = _a.usesDefaultStyles, usesDefaultStyles = _j === void 0 ? false : _j, viewportSize = _a.viewportSize, _k = _a.zeroAnchor, zeroAnchor = _k === void 0 ? 0 : _k, onAngleChange = _a.onAngleChange, onDragEnd = _a.onDragEnd, onDragStart = _a.onDragStart, onLoadImageComplete = _a.onLoadImageComplete, onLoadImageError = _a.onLoadImageError, onLoadImageStart = _a.onLoadImageStart, onImageSizeChange = _a.onImageSizeChange, onPositionChange = _a.onPositionChange, props = __rest(_a, ["className", "style", "angle", "autoDimension", "children", "fov", "speed", "src", "usesDefaultStyles", "viewportSize", "zeroAnchor", "onAngleChange", "onDragEnd", "onDragStart", "onLoadImageComplete", "onLoadImageError", "onLoadImageStart", "onImageSizeChange", "onPositionChange"]);
|
|
64
|
-
var getAspectRatio = function () {
|
|
17
|
+
export const PanoramaSlider = forwardRef(({ className, style, angle = 0, autoDimension = 'width', children, fov, speed = 1, src, usesDefaultStyles = false, viewportSize, zeroAnchor = 0, onAngleChange, onDragEnd, onDragStart, onLoadImageComplete, onLoadImageError, onLoadImageStart, onImageSizeChange, onPositionChange, ...props }, ref) => {
|
|
18
|
+
const getAspectRatio = () => {
|
|
65
19
|
if (!imageSize)
|
|
66
20
|
return 0;
|
|
67
|
-
|
|
21
|
+
const { width, height } = imageSize;
|
|
68
22
|
if (height === 0)
|
|
69
23
|
return 0;
|
|
70
24
|
return width / height;
|
|
71
25
|
};
|
|
72
|
-
|
|
73
|
-
|
|
26
|
+
const getReticleWidth = () => {
|
|
27
|
+
const deg = Math.min(360, Math.max(0, fov ?? (viewportSize ? viewportSize.width / (viewportSize.height * aspectRatio) * 360 : 0)));
|
|
74
28
|
return panoramaRect.width * (deg / 360);
|
|
75
29
|
};
|
|
76
|
-
|
|
30
|
+
const getAdjustedZeroAnchor = () => {
|
|
77
31
|
if (panoramaRect.width <= 0)
|
|
78
32
|
return zeroAnchor;
|
|
79
33
|
return ((panoramaRect.width - reticleWidth) * 0.5 + zeroAnchor * reticleWidth) / panoramaRect.width;
|
|
80
34
|
};
|
|
81
|
-
|
|
35
|
+
const dragStartHandler = () => {
|
|
82
36
|
setIsDragging(true);
|
|
83
|
-
onDragStart
|
|
37
|
+
onDragStart?.();
|
|
84
38
|
};
|
|
85
|
-
|
|
39
|
+
const dragEndHandler = () => {
|
|
86
40
|
setIsDragging(false);
|
|
87
|
-
onDragEnd
|
|
41
|
+
onDragEnd?.();
|
|
88
42
|
};
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
track:
|
|
98
|
-
reticle:
|
|
99
|
-
indicator:
|
|
43
|
+
const panoramaRef = useRef(null);
|
|
44
|
+
const panoramaRect = useRect(panoramaRef);
|
|
45
|
+
const [imageSize, setImageSize] = useState();
|
|
46
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
47
|
+
const aspectRatio = getAspectRatio();
|
|
48
|
+
const reticleWidth = getReticleWidth();
|
|
49
|
+
const adjustedZeroAnchor = getAdjustedZeroAnchor();
|
|
50
|
+
const components = asComponentDict(children, {
|
|
51
|
+
track: PanoramaSliderTrack,
|
|
52
|
+
reticle: PanoramaSliderReticle,
|
|
53
|
+
indicator: PanoramaSliderIndicator,
|
|
100
54
|
});
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return ((
|
|
104
|
-
style:
|
|
105
|
-
}),
|
|
106
|
-
style:
|
|
107
|
-
}),
|
|
108
|
-
style:
|
|
109
|
-
})] }) }),
|
|
110
|
-
style:
|
|
111
|
-
})] }))
|
|
112
|
-
});
|
|
113
|
-
Object.defineProperty(exports.PanoramaSlider, 'displayName', { value: 'PanoramaSlider', writable: false });
|
|
114
|
-
exports.PanoramaSliderTrack = (0, react_1.forwardRef)(function (_a, ref) {
|
|
115
|
-
var props = __rest(_a, []);
|
|
116
|
-
return (0, jsx_runtime_1.jsx)("div", __assign({}, props, { ref: ref, "data-child": 'track' }));
|
|
117
|
-
});
|
|
118
|
-
exports.PanoramaSliderReticle = (0, react_1.forwardRef)(function (_a, ref) {
|
|
119
|
-
var props = __rest(_a, []);
|
|
120
|
-
return (0, jsx_runtime_1.jsx)("div", __assign({}, props, { ref: ref, "data-child": 'reticle' }));
|
|
55
|
+
const fixedStyles = getFixedStyles({ autoDimension, panoramaRect, aspectRatio, reticleWidth });
|
|
56
|
+
const defaultStyles = usesDefaultStyles ? getDefaultStyles({ isDragging }) : undefined;
|
|
57
|
+
return (_jsxs("div", { ...props, ref: ref, className: clsx(className, { dragging: isDragging }), "data-component": 'panorama-slider', style: styles(style, fixedStyles.root), children: [_jsx(Panorama, { ref: panoramaRef, angle: angle, speed: speed, src: src, style: fixedStyles.panorama, zeroAnchor: adjustedZeroAnchor, onAngleChange: onAngleChange, onDragEnd: dragEndHandler, onDragStart: dragStartHandler, onImageSizeChange: setImageSize, onLoadImageComplete: onLoadImageComplete, onLoadImageError: onLoadImageError, onLoadImageStart: onLoadImageStart, onPositionChange: onPositionChange }), _jsx("div", { style: fixedStyles.body, children: _jsxs("div", { style: fixedStyles.controls, children: [cloneStyledElement(components.track ?? _jsx(PanoramaSliderTrack, { style: defaultStyles?.track }), {
|
|
58
|
+
style: styles(fixedStyles.track),
|
|
59
|
+
}), cloneStyledElement(components.reticle ?? _jsx(PanoramaSliderReticle, { style: defaultStyles?.reticle }), {
|
|
60
|
+
style: styles(fixedStyles.reticle),
|
|
61
|
+
}), cloneStyledElement(components.track ?? _jsx(PanoramaSliderTrack, { style: defaultStyles?.track }), {
|
|
62
|
+
style: styles(fixedStyles.track),
|
|
63
|
+
})] }) }), cloneStyledElement(components.indicator ?? _jsx(PanoramaSliderIndicator, { style: defaultStyles?.indicator }), {
|
|
64
|
+
style: styles(fixedStyles.indicator),
|
|
65
|
+
})] }));
|
|
121
66
|
});
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
});
|
|
126
|
-
function getDefaultStyles(
|
|
127
|
-
|
|
128
|
-
return (0, utils_1.asStyleDict)({
|
|
67
|
+
Object.defineProperty(PanoramaSlider, 'displayName', { value: 'PanoramaSlider', writable: false });
|
|
68
|
+
export const PanoramaSliderTrack = forwardRef(({ ...props }, ref) => _jsx("div", { ...props, ref: ref, "data-child": 'track' }));
|
|
69
|
+
export const PanoramaSliderReticle = forwardRef(({ ...props }, ref) => _jsx("div", { ...props, ref: ref, "data-child": 'reticle' }));
|
|
70
|
+
export const PanoramaSliderIndicator = forwardRef(({ ...props }, ref) => _jsx("div", { ...props, ref: ref, "data-child": 'indicator' }));
|
|
71
|
+
function getDefaultStyles({ isDragging = false }) {
|
|
72
|
+
return asStyleDict({
|
|
129
73
|
track: {
|
|
130
74
|
background: 'rgba(0, 0, 0, .7)',
|
|
131
75
|
height: '100%',
|
|
132
76
|
},
|
|
133
77
|
reticle: {
|
|
134
|
-
background:
|
|
78
|
+
background: `rgba(0, 0, 0, ${isDragging ? 0 : 0.3})`,
|
|
135
79
|
flex: '0 0 auto',
|
|
136
80
|
height: '100%',
|
|
137
81
|
transitionDuration: '100ms',
|
|
@@ -154,14 +98,15 @@ function getDefaultStyles(_a) {
|
|
|
154
98
|
},
|
|
155
99
|
});
|
|
156
100
|
}
|
|
157
|
-
function getFixedStyles(
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
101
|
+
function getFixedStyles({ autoDimension = 'width', panoramaRect = new Rect(), aspectRatio = 0, reticleWidth = 0 }) {
|
|
102
|
+
return asStyleDict({
|
|
103
|
+
root: {
|
|
104
|
+
...autoDimension === 'width' ? {
|
|
105
|
+
width: `${panoramaRect.height * aspectRatio}px`,
|
|
106
|
+
} : {
|
|
107
|
+
height: `${panoramaRect.width / aspectRatio}px`,
|
|
108
|
+
},
|
|
109
|
+
},
|
|
165
110
|
body: {
|
|
166
111
|
height: '100%',
|
|
167
112
|
left: '0',
|
|
@@ -190,11 +135,10 @@ function getFixedStyles(_a) {
|
|
|
190
135
|
flex: '1 0 auto',
|
|
191
136
|
},
|
|
192
137
|
reticle: {
|
|
193
|
-
width:
|
|
138
|
+
width: `${reticleWidth}px`,
|
|
194
139
|
},
|
|
195
140
|
indicator: {
|
|
196
|
-
width:
|
|
141
|
+
width: `${reticleWidth}px`,
|
|
197
142
|
},
|
|
198
143
|
});
|
|
199
144
|
}
|
|
200
|
-
//# sourceMappingURL=PanoramaSlider.js.map
|