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/CoverVideo.js
CHANGED
|
@@ -1,64 +1,21 @@
|
|
|
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.CoverVideo = 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 useRect_1 = require("../hooks/useRect");
|
|
46
|
-
var utils_1 = require("../utils");
|
|
47
|
-
var Video_1 = require("./Video");
|
|
48
|
-
exports.CoverVideo = (0, react_1.forwardRef)(function (_a, ref) {
|
|
49
|
-
var _b;
|
|
50
|
-
var className = _a.className, children = _a.children, style = _a.style, _c = _a.aspectRatio, externalAspectRatio = _c === void 0 ? NaN : _c, autoLoop = _a.autoLoop, autoPlay = _a.autoPlay, hasControls = _a.hasControls, isMuted = _a.isMuted, playsInline = _a.playsInline, posterSrc = _a.posterSrc, renderViewportContent = _a.renderViewportContent, src = _a.src, onCanPlay = _a.onCanPlay, onEnd = _a.onEnd, onFullscreenChange = _a.onFullscreenChange, onLoadMetadata = _a.onLoadMetadata, onLoadMetadataComplete = _a.onLoadMetadataComplete, onLoadMetadataError = _a.onLoadMetadataError, onPause = _a.onPause, onPlay = _a.onPlay, onSizeChange = _a.onSizeChange, props = __rest(_a, ["className", "children", "style", "aspectRatio", "autoLoop", "autoPlay", "hasControls", "isMuted", "playsInline", "posterSrc", "renderViewportContent", "src", "onCanPlay", "onEnd", "onFullscreenChange", "onLoadMetadata", "onLoadMetadataComplete", "onLoadMetadataError", "onPause", "onPlay", "onSizeChange"]);
|
|
51
|
-
var handleSizeChange = function (size) {
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useRef, useState } from 'react';
|
|
3
|
+
import { Size } from 'spase';
|
|
4
|
+
import { useRect } from '../hooks/useRect.js';
|
|
5
|
+
import { asStyleDict, styles } from '../utils/index.js';
|
|
6
|
+
import { Video } from './Video.js';
|
|
7
|
+
export const CoverVideo = forwardRef(({ className, children, style, aspectRatio: externalAspectRatio = NaN, autoLoop, autoPlay, hasControls, isMuted, playsInline, posterSrc, renderViewportContent, src, onCanPlay, onEnd, onFullscreenChange, onLoadMetadata, onLoadMetadataComplete, onLoadMetadataError, onPause, onPlay, onSizeChange, ...props }, ref) => {
|
|
8
|
+
const handleSizeChange = (size) => {
|
|
52
9
|
setLocalAspectRatio(size ? size.width / size.height : NaN);
|
|
53
|
-
onSizeChange
|
|
10
|
+
onSizeChange?.(size);
|
|
54
11
|
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
12
|
+
const localRef = useRef(null);
|
|
13
|
+
const rootRef = ref ?? localRef;
|
|
14
|
+
const [localAspectRatio, setLocalAspectRatio] = useState(NaN);
|
|
15
|
+
const aspectRatio = isNaN(externalAspectRatio) ? localAspectRatio : externalAspectRatio;
|
|
16
|
+
const rootRect = useRect(rootRef);
|
|
17
|
+
const rootAspectRatio = rootRect.width / rootRect.height;
|
|
18
|
+
const videoSize = new Size([
|
|
62
19
|
rootAspectRatio > 1
|
|
63
20
|
? Math.max(rootRect.width, rootRect.height * aspectRatio)
|
|
64
21
|
: Math.max(rootRect.width, (Math.max(rootRect.height, rootRect.width / aspectRatio)) * aspectRatio),
|
|
@@ -66,17 +23,17 @@ exports.CoverVideo = (0, react_1.forwardRef)(function (_a, ref) {
|
|
|
66
23
|
? Math.max(rootRect.height, Math.max(rootRect.width, rootRect.height * aspectRatio) / aspectRatio)
|
|
67
24
|
: Math.max(rootRect.height, rootRect.width / aspectRatio),
|
|
68
25
|
]);
|
|
69
|
-
return ((
|
|
70
|
-
width:
|
|
71
|
-
height:
|
|
72
|
-
}), onCanPlay: onCanPlay, onEnd: onEnd, onFullscreenChange: onFullscreenChange, onLoadMetadata: onLoadMetadata, onLoadMetadataComplete: onLoadMetadataComplete, onLoadMetadataError: onLoadMetadataError, onPause: onPause, onPlay: onPlay, onSizeChange:
|
|
73
|
-
height:
|
|
26
|
+
return (_jsxs("div", { ...props, ref: rootRef, className: className, "data-component": 'cover-video', style: styles(style, FIXED_STYLES.root), children: [_jsx(Video, { autoLoop: autoLoop, autoPlay: autoPlay, "data-child": 'video', hasControls: hasControls, isMuted: isMuted, playsInline: playsInline, posterSrc: posterSrc, src: src, style: styles(FIXED_STYLES.viewport, {
|
|
27
|
+
width: `${videoSize.width}px`,
|
|
28
|
+
height: `${videoSize.height}px`,
|
|
29
|
+
}), onCanPlay: onCanPlay, onEnd: onEnd, onFullscreenChange: onFullscreenChange, onLoadMetadata: onLoadMetadata, onLoadMetadataComplete: onLoadMetadataComplete, onLoadMetadataError: onLoadMetadataError, onPause: onPause, onPlay: onPlay, onSizeChange: size => handleSizeChange(size) }), renderViewportContent && (_jsx("div", { "data-child": 'viewport', style: styles(FIXED_STYLES.viewport, {
|
|
30
|
+
height: `${videoSize.height}px`,
|
|
74
31
|
pointerEvents: 'none',
|
|
75
|
-
width:
|
|
76
|
-
}), children: renderViewportContent() })), children] }))
|
|
32
|
+
width: `${videoSize.width}px`,
|
|
33
|
+
}), children: renderViewportContent() })), children] }));
|
|
77
34
|
});
|
|
78
|
-
Object.defineProperty(
|
|
79
|
-
|
|
35
|
+
Object.defineProperty(CoverVideo, 'displayName', { value: 'CoverVideo', writable: false });
|
|
36
|
+
const FIXED_STYLES = asStyleDict({
|
|
80
37
|
root: {
|
|
81
38
|
overflow: 'hidden',
|
|
82
39
|
},
|
|
@@ -95,4 +52,3 @@ var FIXED_STYLES = (0, utils_1.asStyleDict)({
|
|
|
95
52
|
width: '100%',
|
|
96
53
|
},
|
|
97
54
|
});
|
|
98
|
-
//# sourceMappingURL=CoverVideo.js.map
|
|
@@ -1,95 +1,44 @@
|
|
|
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 __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
41
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
42
|
-
if (ar || !(i in from)) {
|
|
43
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
44
|
-
ar[i] = from[i];
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
48
|
-
};
|
|
49
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
exports.DebugConsole = void 0;
|
|
51
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
52
|
-
var react_1 = require("react");
|
|
53
|
-
var Each_1 = require("../operators/Each");
|
|
54
|
-
var utils_1 = require("../utils");
|
|
55
|
-
exports.DebugConsole = (0, react_1.forwardRef)(function (_a, ref) {
|
|
56
|
-
var _b = _a.align, align = _b === void 0 ? 'br' : _b, _c = _a.margin, margin = _c === void 0 ? 0 : _c, _d = _a.maxEntries, maxEntries = _d === void 0 ? -1 : _d, message = _a.message, _e = _a.style, style = _e === void 0 ? {} : _e, title = _a.title, props = __rest(_a, ["align", "margin", "maxEntries", "message", "style", "title"]);
|
|
57
|
-
var _f = __read((0, react_1.useState)([]), 2), messages = _f[0], setMessages = _f[1];
|
|
58
|
-
var messagesRef = (0, react_1.useRef)(null);
|
|
59
|
-
(0, react_1.useEffect)(function () {
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { Each } from '../operators/Each.js';
|
|
4
|
+
import { asStyleDict, styles } from '../utils/index.js';
|
|
5
|
+
export const DebugConsole = forwardRef(({ align = 'br', margin = 0, maxEntries = -1, message, style = {}, title, ...props }, ref) => {
|
|
6
|
+
const [messages, setMessages] = useState([]);
|
|
7
|
+
const messagesRef = useRef(null);
|
|
8
|
+
useEffect(() => {
|
|
60
9
|
if (message === undefined) {
|
|
61
10
|
setMessages([]);
|
|
62
11
|
}
|
|
63
12
|
else {
|
|
64
|
-
|
|
65
|
-
setMessages(
|
|
66
|
-
|
|
67
|
-
|
|
13
|
+
const numMessages = messages.length;
|
|
14
|
+
setMessages([
|
|
15
|
+
...maxEntries < 0
|
|
16
|
+
? messages
|
|
17
|
+
: messages.slice(Math.max(0, numMessages - (maxEntries - 1)), numMessages),
|
|
68
18
|
message,
|
|
69
|
-
]
|
|
19
|
+
]);
|
|
70
20
|
}
|
|
71
21
|
}, [message]);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
(_a = messagesRef.current) === null || _a === void 0 ? void 0 : _a.scrollTo(0, (_b = messagesRef.current) === null || _b === void 0 ? void 0 : _b.scrollHeight);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
messagesRef.current?.scrollTo(0, messagesRef.current?.scrollHeight);
|
|
75
24
|
}, [messages]);
|
|
76
|
-
return ((
|
|
25
|
+
return (_jsxs("div", { ...props, ref: ref, "data-component": 'debug-console', style: styles(style, FIXED_STYLES.root, getStyleByAlignment(align, margin)), children: [_jsx("div", { "data-child": 'header', style: FIXED_STYLES.title, children: title ?? 'Untitled' }), _jsx("div", { ref: messagesRef, "data-child": 'messages', style: FIXED_STYLES.messages, children: _jsx(Each, { in: messages, render: msg => _jsx("div", { dangerouslySetInnerHTML: { __html: msg } }) }) })] }));
|
|
77
26
|
});
|
|
78
|
-
Object.defineProperty(
|
|
27
|
+
Object.defineProperty(DebugConsole, 'displayName', { value: 'DebugConsole', writable: false });
|
|
79
28
|
function getStyleByAlignment(align, margin) {
|
|
80
29
|
switch (align) {
|
|
81
|
-
case 'tl': return { top:
|
|
82
|
-
case 'tc': return { top:
|
|
83
|
-
case 'tr': return { top:
|
|
84
|
-
case 'cl': return { top: 0, left:
|
|
30
|
+
case 'tl': return { top: `${margin}px`, left: `${margin}px` };
|
|
31
|
+
case 'tc': return { top: `${margin}px`, left: 0, right: 0, margin: '0 auto' };
|
|
32
|
+
case 'tr': return { top: `${margin}px`, right: `${margin}px` };
|
|
33
|
+
case 'cl': return { top: 0, left: `${margin}px`, bottom: 0, margin: 'auto 0' };
|
|
85
34
|
case 'cc': return { top: 0, left: 0, right: 0, bottom: 0, margin: 'auto' };
|
|
86
|
-
case 'cr': return { top: 0, bottom: 0, right:
|
|
87
|
-
case 'bl': return { bottom:
|
|
88
|
-
case 'bc': return { bottom:
|
|
89
|
-
default: return { bottom:
|
|
35
|
+
case 'cr': return { top: 0, bottom: 0, right: `${margin}px`, margin: 'auto 0' };
|
|
36
|
+
case 'bl': return { bottom: `${margin}px`, left: `${margin}px` };
|
|
37
|
+
case 'bc': return { bottom: `${margin}px`, left: 0, right: 0, margin: '0 auto' };
|
|
38
|
+
default: return { bottom: `${margin}px`, right: `${margin}px` };
|
|
90
39
|
}
|
|
91
40
|
}
|
|
92
|
-
|
|
41
|
+
const FIXED_STYLES = asStyleDict({
|
|
93
42
|
root: {
|
|
94
43
|
background: '#000',
|
|
95
44
|
fontFamily: 'monospace',
|
|
@@ -125,4 +74,3 @@ var FIXED_STYLES = (0, utils_1.asStyleDict)({
|
|
|
125
74
|
width: '100%',
|
|
126
75
|
},
|
|
127
76
|
});
|
|
128
|
-
//# sourceMappingURL=DebugConsole.js.map
|
package/components/Dial.js
CHANGED
|
@@ -1,81 +1,46 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.DialKnob = exports.DialTrack = exports.Dial = void 0;
|
|
26
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
27
|
-
var react_1 = require("react");
|
|
28
|
-
var utils_1 = require("../utils");
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import { asComponentDict, asStyleDict, cloneStyledElement, styles } from '../utils/index.js';
|
|
29
4
|
/**
|
|
30
5
|
* A circular dial with a knob and a track.
|
|
31
6
|
*
|
|
32
7
|
* @exports DialKnob
|
|
33
8
|
* @exports DialTrack
|
|
34
9
|
*/
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
track: exports.DialTrack,
|
|
42
|
-
knob: exports.DialKnob,
|
|
10
|
+
export const Dial = forwardRef(({ children, style, angle = 0, knobLength = 30, knobThickness = 10, radius = 50, trackThickness = 2, usesDefaultStyles = false, ...props }, ref) => {
|
|
11
|
+
const diameter = radius * 2;
|
|
12
|
+
const clampedKnobAngle = Math.max(0, Math.min(360, knobLength));
|
|
13
|
+
const components = asComponentDict(children, {
|
|
14
|
+
track: DialTrack,
|
|
15
|
+
knob: DialKnob,
|
|
43
16
|
});
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return ((
|
|
17
|
+
const fixedStyles = getFixedStyles({ angle, diameter });
|
|
18
|
+
const defaultStyles = usesDefaultStyles ? getDefaultStyles() : undefined;
|
|
19
|
+
return (_jsxs("div", { ...props, ref: ref, "data-component": 'dial', style: styles(style, fixedStyles.root), children: [_jsx("div", { style: fixedStyles.trackContainer, children: _jsx("svg", { height: diameter, style: fixedStyles.svgContainer, viewBox: `0 0 ${diameter} ${diameter}`, width: diameter, children: cloneStyledElement(components.track ?? _jsx(DialTrack, { style: defaultStyles?.track }), {
|
|
47
20
|
cx: radius,
|
|
48
21
|
cy: radius,
|
|
49
22
|
r: radius - trackThickness / 2,
|
|
50
23
|
strokeWidth: trackThickness,
|
|
51
|
-
}) }) }), (
|
|
24
|
+
}) }) }), _jsx("div", { style: styles(fixedStyles.knobContainer), children: _jsx("svg", { style: fixedStyles.svgContainer, viewBox: `0 0 ${diameter} ${diameter}`, xmlns: 'http://www.w3.org/2000/svg', children: cloneStyledElement(components.knob ?? _jsx(DialKnob, { style: defaultStyles?.knob }), {
|
|
52
25
|
strokeWidth: knobThickness,
|
|
53
26
|
d: arcPath(radius, radius, radius - knobThickness / 2 - (trackThickness - knobThickness) / 2, -clampedKnobAngle / 2, clampedKnobAngle / 2),
|
|
54
|
-
}) }) })] }))
|
|
27
|
+
}) }) })] }));
|
|
55
28
|
});
|
|
56
|
-
Object.defineProperty(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return (0, jsx_runtime_1.jsx)("circle", __assign({}, props, { "data-child": 'track' }));
|
|
60
|
-
};
|
|
61
|
-
exports.DialTrack = DialTrack;
|
|
62
|
-
var DialKnob = function (_a) {
|
|
63
|
-
var props = __rest(_a, []);
|
|
64
|
-
return (0, jsx_runtime_1.jsx)("path", __assign({}, props, { "data-child": 'knob' }));
|
|
65
|
-
};
|
|
66
|
-
exports.DialKnob = DialKnob;
|
|
29
|
+
Object.defineProperty(Dial, 'displayName', { value: 'Dial', writable: false });
|
|
30
|
+
export const DialTrack = ({ ...props }) => _jsx("circle", { ...props, "data-child": 'track' });
|
|
31
|
+
export const DialKnob = ({ ...props }) => _jsx("path", { ...props, "data-child": 'knob' });
|
|
67
32
|
function polarToCartesian(centerX, centerY, radius, angleInDegrees) {
|
|
68
|
-
|
|
33
|
+
const angleInRadians = (angleInDegrees - 90) * Math.PI / 180.0;
|
|
69
34
|
return {
|
|
70
35
|
x: centerX + radius * Math.cos(angleInRadians),
|
|
71
36
|
y: centerY + radius * Math.sin(angleInRadians),
|
|
72
37
|
};
|
|
73
38
|
}
|
|
74
39
|
function arcPath(x, y, radius, startAngle, endAngle) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
40
|
+
const start = polarToCartesian(x, y, radius, endAngle);
|
|
41
|
+
const end = polarToCartesian(x, y, radius, startAngle);
|
|
42
|
+
const largeArcFlag = endAngle - startAngle <= 180 ? '0' : '1';
|
|
43
|
+
const d = [
|
|
79
44
|
'M',
|
|
80
45
|
start.x,
|
|
81
46
|
start.y,
|
|
@@ -90,12 +55,11 @@ function arcPath(x, y, radius, startAngle, endAngle) {
|
|
|
90
55
|
];
|
|
91
56
|
return d.join(' ');
|
|
92
57
|
}
|
|
93
|
-
function getFixedStyles(
|
|
94
|
-
|
|
95
|
-
return (0, utils_1.asStyleDict)({
|
|
58
|
+
function getFixedStyles({ diameter = 0, angle = 0 }) {
|
|
59
|
+
return asStyleDict({
|
|
96
60
|
root: {
|
|
97
|
-
height:
|
|
98
|
-
width:
|
|
61
|
+
height: `${diameter}px`,
|
|
62
|
+
width: `${diameter}px`,
|
|
99
63
|
},
|
|
100
64
|
knobContainer: {
|
|
101
65
|
backgroundPosition: 'center',
|
|
@@ -107,7 +71,7 @@ function getFixedStyles(_a) {
|
|
|
107
71
|
top: '0',
|
|
108
72
|
transformOrigin: 'center',
|
|
109
73
|
width: '100%',
|
|
110
|
-
transform:
|
|
74
|
+
transform: `rotate(${(angle + 360) % 360}deg)`,
|
|
111
75
|
},
|
|
112
76
|
trackContainer: {
|
|
113
77
|
height: '100%',
|
|
@@ -126,7 +90,7 @@ function getFixedStyles(_a) {
|
|
|
126
90
|
});
|
|
127
91
|
}
|
|
128
92
|
function getDefaultStyles() {
|
|
129
|
-
return
|
|
93
|
+
return asStyleDict({
|
|
130
94
|
knob: {
|
|
131
95
|
stroke: '#fff',
|
|
132
96
|
},
|
|
@@ -136,4 +100,3 @@ function getDefaultStyles() {
|
|
|
136
100
|
},
|
|
137
101
|
});
|
|
138
102
|
}
|
|
139
|
-
//# sourceMappingURL=Dial.js.map
|