etudes 0.37.0 → 0.41.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/lib/BurgerButton.d.ts +14 -35
- package/lib/BurgerButton.js +47 -80
- package/lib/BurgerButton.js.map +1 -1
- package/lib/Dial.d.ts +5 -8
- package/lib/Dial.js +3 -6
- package/lib/Dial.js.map +1 -1
- package/lib/FlatSVG.d.ts +37 -9
- package/lib/FlatSVG.js +83 -28
- package/lib/FlatSVG.js.map +1 -1
- package/lib/Group.d.ts +7 -0
- package/lib/Group.js +53 -0
- package/lib/Group.js.map +1 -0
- package/lib/Panorama.d.ts +0 -5
- package/lib/Panorama.js +0 -7
- package/lib/Panorama.js.map +1 -1
- package/lib/PanoramaSlider.d.ts +5 -5
- package/lib/PanoramaSlider.js +6 -6
- package/lib/PanoramaSlider.js.map +1 -1
- package/lib/RangeSlider.d.ts +8 -8
- package/lib/RangeSlider.js +10 -10
- package/lib/RangeSlider.js.map +1 -1
- package/lib/RotatingGallery.d.ts +55 -0
- package/lib/RotatingGallery.js +94 -0
- package/lib/RotatingGallery.js.map +1 -0
- package/lib/Slider.d.ts +6 -12
- package/lib/Slider.js +5 -10
- package/lib/Slider.js.map +1 -1
- package/lib/StepwiseSlider.d.ts +6 -12
- package/lib/StepwiseSlider.js +5 -10
- package/lib/StepwiseSlider.js.map +1 -1
- package/lib/hooks/useDragEffect.d.ts +0 -4
- package/lib/hooks/useDragEffect.js +0 -5
- package/lib/hooks/useDragEffect.js.map +1 -1
- package/lib/hooks/useInterval.d.ts +1 -0
- package/lib/hooks/useInterval.js +17 -0
- package/lib/hooks/useInterval.js.map +1 -0
- package/lib/hooks/useResizeEffect.js +0 -1
- package/lib/hooks/useResizeEffect.js.map +1 -1
- package/package.json +3 -1
package/lib/BurgerButton.d.ts
CHANGED
|
@@ -1,37 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
transitionDuration: number;
|
|
1
|
+
import { HTMLAttributes } from 'react';
|
|
2
|
+
import { CSSProp } from 'styled-components';
|
|
3
|
+
export declare type Props = HTMLAttributes<HTMLButtonElement> & {
|
|
4
|
+
isActive?: boolean;
|
|
5
|
+
isDoubleJointed?: boolean;
|
|
6
|
+
isLastBarHalfWidth?: boolean;
|
|
7
|
+
height?: number;
|
|
8
|
+
thickness?: number;
|
|
9
|
+
width?: number;
|
|
10
|
+
tintColor?: string;
|
|
11
|
+
transitionDuration?: number;
|
|
13
12
|
onActivate?: () => void;
|
|
14
13
|
onDeactivate?: () => void;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
declare class BurgerButton extends PureComponent<Props, State> {
|
|
20
|
-
static defaultProps: {
|
|
21
|
-
height: number;
|
|
22
|
-
isActiveByDefault: boolean;
|
|
23
|
-
isDoubleJointed: boolean;
|
|
24
|
-
isFunky: boolean;
|
|
25
|
-
style: {};
|
|
26
|
-
thickness: number;
|
|
27
|
-
tintColor: string;
|
|
28
|
-
transitionDuration: number;
|
|
29
|
-
width: number;
|
|
30
|
-
};
|
|
31
|
-
constructor(props: Props);
|
|
32
|
-
toggle(): void;
|
|
33
|
-
activate(): void;
|
|
34
|
-
deactivate(): void;
|
|
35
|
-
render(): JSX.Element;
|
|
36
|
-
}
|
|
37
|
-
export default BurgerButton;
|
|
14
|
+
cssBar?: CSSProp<any>;
|
|
15
|
+
};
|
|
16
|
+
export default function BurgerButton({ isActive: externalIsActive, isDoubleJointed, isLastBarHalfWidth, height, thickness, width, tintColor, transitionDuration, onActivate, onDeactivate, cssBar, ...props }: Props): JSX.Element;
|
package/lib/BurgerButton.js
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
18
3
|
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
19
4
|
return cooked;
|
|
20
5
|
};
|
|
6
|
+
var __assign = (this && this.__assign) || function () {
|
|
7
|
+
__assign = Object.assign || function(t) {
|
|
8
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
9
|
+
s = arguments[i];
|
|
10
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
11
|
+
t[p] = s[p];
|
|
12
|
+
}
|
|
13
|
+
return t;
|
|
14
|
+
};
|
|
15
|
+
return __assign.apply(this, arguments);
|
|
16
|
+
};
|
|
21
17
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
22
18
|
if (k2 === undefined) k2 = k;
|
|
23
19
|
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
@@ -37,6 +33,17 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
37
33
|
__setModuleDefault(result, mod);
|
|
38
34
|
return result;
|
|
39
35
|
};
|
|
36
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
37
|
+
var t = {};
|
|
38
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
39
|
+
t[p] = s[p];
|
|
40
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
41
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
42
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
43
|
+
t[p[i]] = s[p[i]];
|
|
44
|
+
}
|
|
45
|
+
return t;
|
|
46
|
+
};
|
|
40
47
|
var __read = (this && this.__read) || function (o, n) {
|
|
41
48
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
42
49
|
if (!m) return o;
|
|
@@ -53,79 +60,39 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
53
60
|
}
|
|
54
61
|
return ar;
|
|
55
62
|
};
|
|
56
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
57
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
58
|
-
if (ar || !(i in from)) {
|
|
59
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
60
|
-
ar[i] = from[i];
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
64
|
-
};
|
|
65
63
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
66
64
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
67
65
|
};
|
|
68
66
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
67
|
+
var classnames_1 = __importDefault(require("classnames"));
|
|
69
68
|
var react_1 = __importStar(require("react"));
|
|
70
69
|
var styled_components_1 = __importDefault(require("styled-components"));
|
|
71
|
-
var
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (
|
|
82
|
-
|
|
70
|
+
var Group_1 = __importDefault(require("./Group"));
|
|
71
|
+
function BurgerButton(_a) {
|
|
72
|
+
var _b = _a.isActive, externalIsActive = _b === void 0 ? false : _b, _c = _a.isDoubleJointed, isDoubleJointed = _c === void 0 ? false : _c, _d = _a.isLastBarHalfWidth, isLastBarHalfWidth = _d === void 0 ? false : _d, _e = _a.height, height = _e === void 0 ? 20 : _e, _f = _a.thickness, thickness = _f === void 0 ? 2 : _f, _g = _a.width, width = _g === void 0 ? 20 : _g, _h = _a.tintColor, tintColor = _h === void 0 ? '#000' : _h, _j = _a.transitionDuration, transitionDuration = _j === void 0 ? 200 : _j, onActivate = _a.onActivate, onDeactivate = _a.onDeactivate, cssBar = _a.cssBar, props = __rest(_a, ["isActive", "isDoubleJointed", "isLastBarHalfWidth", "height", "thickness", "width", "tintColor", "transitionDuration", "onActivate", "onDeactivate", "cssBar"]);
|
|
73
|
+
var _k = __read((0, react_1.useState)(externalIsActive), 2), isActive = _k[0], setIsActive = _k[1];
|
|
74
|
+
(0, react_1.useEffect)(function () {
|
|
75
|
+
if (isActive !== externalIsActive) {
|
|
76
|
+
setIsActive(externalIsActive);
|
|
77
|
+
}
|
|
78
|
+
}, [externalIsActive]);
|
|
79
|
+
(0, react_1.useEffect)(function () {
|
|
80
|
+
if (isActive) {
|
|
81
|
+
onActivate === null || onActivate === void 0 ? void 0 : onActivate();
|
|
83
82
|
}
|
|
84
83
|
else {
|
|
85
|
-
|
|
84
|
+
onDeactivate === null || onDeactivate === void 0 ? void 0 : onDeactivate();
|
|
86
85
|
}
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
};
|
|
95
|
-
BurgerButton.prototype.deactivate = function () {
|
|
96
|
-
if (!this.state.isActive)
|
|
97
|
-
return;
|
|
98
|
-
this.setState({ isActive: false });
|
|
99
|
-
if (this.props.onDeactivate)
|
|
100
|
-
this.props.onDeactivate();
|
|
101
|
-
};
|
|
102
|
-
BurgerButton.prototype.render = function () {
|
|
103
|
-
var _this = this;
|
|
104
|
-
var w = this.props.width * 0.5;
|
|
105
|
-
var h = this.props.height * 0.5;
|
|
106
|
-
var t = this.props.thickness * 0.5;
|
|
107
|
-
var d = 45;
|
|
108
|
-
var r = d * Math.PI / 180;
|
|
109
|
-
var n = this.props.isDoubleJointed ? 2 : 1;
|
|
110
|
-
return (react_1.default.createElement(StyledRoot, { className: this.props.className, height: this.props.height, isActive: this.state.isActive, isDoubleJointed: this.props.isDoubleJointed, isFunky: this.props.isFunky, onClick: function () { return _this.toggle(); }, style: this.props.style, thickness: this.props.thickness, tintColor: this.props.tintColor, transitionDuration: this.props.transitionDuration, width: this.props.width, w: w, h: h, t: t, d: d, r: r }, this.props.isDoubleJointed && (react_1.default.createElement(react_1.Fragment, null, __spreadArray([], __read(new Array(n)), false).map(function (v, i) { return (react_1.default.createElement("div", { key: "joint-".concat(i) },
|
|
111
|
-
react_1.default.createElement("span", null),
|
|
112
|
-
react_1.default.createElement("span", null),
|
|
113
|
-
react_1.default.createElement("span", null))); })))));
|
|
114
|
-
};
|
|
115
|
-
BurgerButton.defaultProps = {
|
|
116
|
-
height: 20,
|
|
117
|
-
isActiveByDefault: false,
|
|
118
|
-
isDoubleJointed: true,
|
|
119
|
-
isFunky: false,
|
|
120
|
-
style: {},
|
|
121
|
-
thickness: 2,
|
|
122
|
-
tintColor: '#000',
|
|
123
|
-
transitionDuration: 200,
|
|
124
|
-
width: 20,
|
|
125
|
-
};
|
|
126
|
-
return BurgerButton;
|
|
127
|
-
}(react_1.PureComponent));
|
|
86
|
+
}, [isActive]);
|
|
87
|
+
return (react_1.default.createElement(StyledRoot, __assign({ width: width, height: height, thickness: thickness, onClick: function () { return setIsActive(!isActive); } }, props),
|
|
88
|
+
react_1.default.createElement(Group_1.default, { count: isDoubleJointed ? 2 : 1 },
|
|
89
|
+
react_1.default.createElement(StyledJoint, { className: (0, classnames_1.default)({ active: isActive, half: isDoubleJointed }), height: height, isLastBarHalfWidth: isLastBarHalfWidth, thickness: thickness, width: width },
|
|
90
|
+
react_1.default.createElement(Group_1.default, { count: 3 },
|
|
91
|
+
react_1.default.createElement(StyledBar, { className: (0, classnames_1.default)({ active: isActive, half: isDoubleJointed }), style: { height: "".concat(thickness, "px") }, css: cssBar }))))));
|
|
92
|
+
}
|
|
128
93
|
exports.default = BurgerButton;
|
|
129
|
-
var
|
|
130
|
-
var
|
|
94
|
+
var StyledBar = styled_components_1.default.span(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n background: #fff;\n box-sizing: border-box;\n margin: 0;\n padding: 0;\n position: absolute;\n transition-duration: 100ms;\n transition-property: width, height, transform, opacity, background;\n transition-timing-function: ease-out;\n width: 100%;\n\n ", "\n"], ["\n background: #fff;\n box-sizing: border-box;\n margin: 0;\n padding: 0;\n position: absolute;\n transition-duration: 100ms;\n transition-property: width, height, transform, opacity, background;\n transition-timing-function: ease-out;\n width: 100%;\n\n ", "\n"])), function (props) { return props.css; });
|
|
95
|
+
var StyledJoint = styled_components_1.default.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n height: 100%;\n position: absolute;\n width: 100%;\n\n &.half {\n width: 50%;\n }\n\n &:nth-of-type(1) {\n left: 0;\n top: 0;\n\n ", ":nth-child(1) {\n left: 0;\n top: 0;\n transform-origin: center;\n transform: translate3d(0, 0, 0) rotate(0deg);\n }\n\n ", ":nth-child(2) {\n left: 0;\n top: ", "px;\n transform-origin: center;\n transform: translate3d(0, 0, 0) scale(1);\n }\n\n ", ":nth-child(3) {\n left: 0;\n top: ", "px;\n transform-origin: center;\n transform: translate3d(0, 0, 0) rotate(0deg);\n width: ", ";\n }\n\n &.active {\n ", ":nth-child(1) {\n transform: ", ";\n }\n\n ", ":nth-child(2) {\n transform: ", ";\n }\n\n ", ":nth-child(3) {\n transform: ", ";\n width: 100%;\n }\n }\n\n &.half {\n ", ":nth-child(1) {\n transform-origin: right center;\n }\n\n ", ":nth-child(2) {\n transform-origin: right center;\n }\n\n ", ":nth-child(3) {\n transform-origin: right center;\n width: 100%;\n }\n }\n }\n\n &:nth-of-type(2) {\n right: 0;\n top: 0;\n\n span:nth-child(1) {\n left: 0;\n top: 0;\n transform-origin: left center;\n transform: translate3d(0, 0, 0) rotate(0deg);\n }\n\n span:nth-child(2) {\n left: 0;\n top: ", "px;\n transform-origin: left center;\n transform: translate3d(0, 0, 0) scale(1);\n }\n\n span:nth-child(3) {\n left: 0;\n top: ", "px;\n transform-origin: left center;\n transform: translate3d(0, 0, 0) rotate(0deg);\n width: ", ";\n }\n\n &.active {\n span:nth-child(1) {\n transform: ", ";\n }\n\n span:nth-child(2) {\n transform: translate3d(0, 0, 0) scale(0);\n }\n\n span:nth-child(3) {\n transform: ", ";\n width: 100%;\n }\n }\n }\n"], ["\n height: 100%;\n position: absolute;\n width: 100%;\n\n &.half {\n width: 50%;\n }\n\n &:nth-of-type(1) {\n left: 0;\n top: 0;\n\n ", ":nth-child(1) {\n left: 0;\n top: 0;\n transform-origin: center;\n transform: translate3d(0, 0, 0) rotate(0deg);\n }\n\n ", ":nth-child(2) {\n left: 0;\n top: ", "px;\n transform-origin: center;\n transform: translate3d(0, 0, 0) scale(1);\n }\n\n ", ":nth-child(3) {\n left: 0;\n top: ", "px;\n transform-origin: center;\n transform: translate3d(0, 0, 0) rotate(0deg);\n width: ", ";\n }\n\n &.active {\n ", ":nth-child(1) {\n transform: ", ";\n }\n\n ", ":nth-child(2) {\n transform: ", ";\n }\n\n ", ":nth-child(3) {\n transform: ", ";\n width: 100%;\n }\n }\n\n &.half {\n ", ":nth-child(1) {\n transform-origin: right center;\n }\n\n ", ":nth-child(2) {\n transform-origin: right center;\n }\n\n ", ":nth-child(3) {\n transform-origin: right center;\n width: 100%;\n }\n }\n }\n\n &:nth-of-type(2) {\n right: 0;\n top: 0;\n\n span:nth-child(1) {\n left: 0;\n top: 0;\n transform-origin: left center;\n transform: translate3d(0, 0, 0) rotate(0deg);\n }\n\n span:nth-child(2) {\n left: 0;\n top: ", "px;\n transform-origin: left center;\n transform: translate3d(0, 0, 0) scale(1);\n }\n\n span:nth-child(3) {\n left: 0;\n top: ", "px;\n transform-origin: left center;\n transform: translate3d(0, 0, 0) rotate(0deg);\n width: ", ";\n }\n\n &.active {\n span:nth-child(1) {\n transform: ", ";\n }\n\n span:nth-child(2) {\n transform: translate3d(0, 0, 0) scale(0);\n }\n\n span:nth-child(3) {\n transform: ", ";\n width: 100%;\n }\n }\n }\n"])), StyledBar, StyledBar, function (props) { return props.height * .5 - props.thickness * .5; }, StyledBar, function (props) { return props.height - props.thickness; }, function (props) { return props.isLastBarHalfWidth ? '50%' : '100%'; }, StyledBar, function (props) { return "translate3d(0, ".concat(props.height * .5 - props.thickness * .5, "px, 0) rotate(45deg)"); }, StyledBar, function (props) { return 'translate3d(0, 0, 0) scale(0)'; }, StyledBar, function (props) { return "translate3d(0, ".concat(props.thickness * .5 - props.height * .5, "px, 0) rotate(-45deg)"); }, StyledBar, StyledBar, StyledBar, function (props) { return props.height * .5 - props.thickness * .5; }, function (props) { return props.height - props.thickness; }, function (props) { return props.isLastBarHalfWidth ? 0 : '100%'; }, function (props) { return "translate3d(0, ".concat(props.height * .5 - props.thickness * .5, "px, 0) rotate(-45deg)"); }, function (props) { return "translate3d(0, ".concat(props.thickness * .5 - props.height * .5, "px, 0) rotate(45deg)"); });
|
|
96
|
+
var StyledRoot = styled_components_1.default.button(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n background: transparent;\n border: none;\n box-sizing: border-box;\n display: block;\n height: ", "px;\n margin: 0;\n min-height: ", "px;\n min-width: ", "px;\n outline: none;\n padding: 0;\n pointer-events: auto;\n position: relative;\n width: ", "px;\n\n html:not(.touch) &:hover {\n ", ":not(.half) {\n span:nth-child(3) {\n width: ", "px;\n }\n }\n\n ", ".half:nth-of-type(2) {\n span:nth-child(3) {\n width: ", "px;\n }\n }\n }\n"], ["\n background: transparent;\n border: none;\n box-sizing: border-box;\n display: block;\n height: ", "px;\n margin: 0;\n min-height: ", "px;\n min-width: ", "px;\n outline: none;\n padding: 0;\n pointer-events: auto;\n position: relative;\n width: ", "px;\n\n html:not(.touch) &:hover {\n ", ":not(.half) {\n span:nth-child(3) {\n width: ", "px;\n }\n }\n\n ", ".half:nth-of-type(2) {\n span:nth-child(3) {\n width: ", "px;\n }\n }\n }\n"])), function (props) { return props.height; }, function (props) { return props.height; }, function (props) { return props.width; }, function (props) { return props.width; }, StyledJoint, function (props) { return props.width; }, StyledJoint, function (props) { return props.width * .5; });
|
|
97
|
+
var templateObject_1, templateObject_2, templateObject_3;
|
|
131
98
|
//# sourceMappingURL=BurgerButton.js.map
|
package/lib/BurgerButton.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BurgerButton.js","sourceRoot":"/","sources":["BurgerButton.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAqE;AACrE,wEAAsC;AAqBtC;IAA2B,gCAA2B;IAapD,sBAAY,KAAY;QAAxB,YACE,kBAAM,KAAK,CAAC,SAKb;QAHC,KAAI,CAAC,KAAK,GAAG;YACX,QAAQ,EAAE,KAAI,CAAC,KAAK,CAAC,iBAAiB;SACvC,CAAA;;IACH,CAAC;IAED,6BAAM,GAAN;QACE,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE;YACvB,IAAI,CAAC,UAAU,EAAE,CAAA;SAClB;aACI;YACH,IAAI,CAAC,QAAQ,EAAE,CAAA;SAChB;IACH,CAAC;IAED,+BAAQ,GAAR;QACE,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ;YAAE,OAAM;QAC/B,IAAI,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;QACjC,IAAI,IAAI,CAAC,KAAK,CAA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,CAAC,GAAG,KAAK,CAAC,CAAC,2BAAiB,KAAK,CAAC,CAAC,SAAM,CAAC,CAAC,CAAC,mCAAmC,EAAxH,CAAwH,EACrI,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,EAAtD,CAAsD,EAEjE,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,MAAM,GAAG,KAAK,CAAC,SAAS,EAA9B,CAA8B,EAMpC,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,SAAS,EAAf,CAAe,EAM5B,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,SAAS,EAAf,CAAe,EACX,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,kBAAkB,EAAxB,CAAwB,EAO5C,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,SAAS,EAAf,CAAe,EACzB,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,CAAC,EAAP,CAAO,EAIf,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,SAAS,EAAf,CAAe,EACzB,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,KAAK,EAAX,CAAW,CAGlC,CAAA","sourcesContent":["import React, { CSSProperties, Fragment, PureComponent } from 'react'\nimport styled from 'styled-components'\n\nexport interface Props {\n className?: string\n style: CSSProperties\n isActiveByDefault: boolean\n isDoubleJointed: boolean\n isFunky: boolean\n height: number\n thickness: number\n width: number\n tintColor: string\n transitionDuration: number\n onActivate?: () => void\n onDeactivate?: () => void\n}\n\nexport interface State {\n isActive: boolean\n}\n\nclass BurgerButton extends PureComponent<Props, State> {\n static defaultProps = {\n height: 20,\n isActiveByDefault: false,\n isDoubleJointed: true,\n isFunky: false,\n style: {},\n thickness: 2,\n tintColor: '#000',\n transitionDuration: 200,\n width: 20,\n }\n\n constructor(props: Props) {\n super(props)\n\n this.state = {\n isActive: this.props.isActiveByDefault,\n }\n }\n\n toggle() {\n if (this.state.isActive) {\n this.deactivate()\n }\n else {\n this.activate()\n }\n }\n\n activate() {\n if (this.state.isActive) return\n this.setState({ isActive: true })\n if (this.props.onActivate) this.props.onActivate()\n }\n\n deactivate() {\n if (!this.state.isActive) return\n this.setState({ isActive: false })\n if (this.props.onDeactivate) this.props.onDeactivate()\n }\n\n render() {\n const w = this.props.width * 0.5\n const h = this.props.height * 0.5\n const t = this.props.thickness * 0.5\n const d = 45\n const r = d * Math.PI / 180\n const n = this.props.isDoubleJointed ? 2 : 1\n\n return (\n <StyledRoot\n className={this.props.className}\n height={this.props.height}\n isActive={this.state.isActive}\n isDoubleJointed={this.props.isDoubleJointed}\n isFunky={this.props.isFunky}\n onClick={() => this.toggle()}\n style={this.props.style}\n thickness={this.props.thickness}\n tintColor={this.props.tintColor}\n transitionDuration={this.props.transitionDuration}\n width={this.props.width}\n w={w}\n h={h}\n t={t}\n d={d}\n r={r}\n >\n {this.props.isDoubleJointed && (\n <Fragment>\n {[...new Array(n)].map((v, i) => (\n <div key={`joint-${i}`}>\n <span/>\n <span/>\n <span/>\n </div>\n ))}\n </Fragment>\n )}\n </StyledRoot>\n )\n }\n}\n\nexport default BurgerButton\n\nconst StyledRoot = styled.button<{\n isActive: boolean\n width: number\n height: number\n thickness: number\n tintColor: string\n isDoubleJointed: boolean\n isFunky: boolean\n transitionDuration: number\n w: number\n h: number\n t: number\n d: number\n r: number\n}>`\n background: transparent;\n border: none;\n box-sizing: border-box;\n display: block;\n height: ${props => props.height}px;\n margin: 0;\n min-height: ${props => props.height}px;\n min-width: ${props => props.width}px;\n outline: none;\n padding: 0;\n pointer-events: auto;\n position: relative;\n width: ${props => props.width}px;\n\n > div:only-of-type {\n width: 100%;\n height: 100%;\n\n span:nth-child(1) {\n left: 0;\n position: absolute;\n top: 0;\n transform-origin: center;\n transform: ${props => props.isActive ? `translate3d(0, ${props.h - props.t}px, 0) rotate(${props.d}deg)` : 'translate3d(0, 0, 0) rotate(0deg)'};\n }\n\n span:nth-child(2) {\n left: 0;\n position: absolute;\n top: ${props => props.h - props.t}px;\n transform-origin: center;\n transform: ${props => props.isActive ? 'translate3d(0, 0, 0) scale(0)' : 'translate3d(0, 0, 0) scale(1)'};\n }\n\n span:nth-child(3) {\n top: ${props => props.height - props.thickness};\n left: 0;\n position: absolute;\n transform-origin: center;\n transform: ${props => props.isActive ? `translate3d(0, ${props.t - props.h}px, 0) rotate(${-props.d}deg)` : 'translate3d(0, 0, 0) rotate(0deg)'};\n width: ${props => props.isActive ? '100%' : (props.isFunky ? '50%' : '100%')};\n }\n }\n\n > div:not(:only-of-type) {\n height: 100%;\n width: 50%;\n\n &:nth-of-type(1) {\n left: 0;\n top: 0;\n position: absolute;\n\n span:nth-child(1) {\n top: 0;\n left: 0;\n transform-origin: right center;\n transform: ${props => props.isActive ? `translate3d(0, ${props.h - props.t}px, 0) rotate(${props.d}deg)` : 'translate3d(0, 0, 0) rotate(0deg)'};\n }\n\n span:nth-child(2) {\n left: 0;\n top: ${props => props.h - props.t}px;\n transform: ${props => props.isActive ? 'translate3d(0, 0, 0) scale(0)' : 'translate3d(0, 0, 0) scale(1)'};\n transform-origin: right center;\n }\n\n span:nth-child(3) {\n top: ${props => props.height - props.thickness}px;\n left: 0;\n width: 100%;\n transform-origin: right center;\n transform: ${props => props.isActive ? `translate3d(0, ${props.t - props.h}px, 0) rotate(${-props.d}deg)` : 'translate3d(0, 0, 0) rotate(0deg)'};\n }\n }\n\n &:nth-of-type(2) {\n right: 0;\n top: 0;\n position: absolute;\n\n span:nth-child(1) {\n top: 0;\n left: 0;\n transform-origin: left center;\n transform: ${props => props.isActive ? `translate3d(${0}px, ${props.h - props.t}px, 0) rotate(${-props.d}deg)` : 'translate3d(0, 0, 0) rotate(0deg)'};\n }\n\n span:nth-child(2) {\n left: 0;\n top: ${props => props.h - props.t}px;\n transform: ${props => props.isActive ? 'translate3d(0, 0, 0) scale(0)' : 'translate3d(0, 0, 0) scale(1)'};\n transform-origin: left center;\n }\n\n span:nth-child(3) {\n transform-origin: left center;\n transform: ${props => props.isActive ? `translate3d(0, ${props.t - props.h}px, 0) rotate(${props.d}deg)` : 'translate3d(0, 0, 0) rotate(0deg)'};\n width: ${props => props.isActive ? '100%' : (props.isFunky ? 0 : '100%')};\n left: 0;\n top: ${props => props.height - props.thickness}px;\n }\n }\n }\n\n span {\n background: ${props => props.tintColor};\n box-sizing: border-box;\n margin: 0;\n padding: 0;\n position: absolute;\n width: 100%;\n height: ${props => props.thickness}px;\n transition-duration: ${props => props.transitionDuration}ms;\n transition-property: width, height, transform, opacity, background;\n transition-timing-function: ease-out;\n }\n\n &:hover {\n div:not(:only-of-type):nth-of-type(2)::after {\n height: ${props => props.thickness}px;\n width: ${props => props.w}px;\n }\n\n div:only-of-type span:nth-child(3) {\n height: ${props => props.thickness}px;\n width: ${props => props.width}px;\n }\n }\n`\n"]}
|
|
1
|
+
{"version":3,"file":"BurgerButton.js","sourceRoot":"/","sources":["BurgerButton.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAAmC;AACnC,6CAAkE;AAClE,wEAAmD;AACnD,kDAA2B;AAgB3B,SAAwB,YAAY,CAAC,EAa7B;IAZN,IAAA,gBAAkC,EAAxB,gBAAgB,mBAAG,KAAK,KAAA,EAClC,uBAAuB,EAAvB,eAAe,mBAAG,KAAK,KAAA,EACvB,0BAA0B,EAA1B,kBAAkB,mBAAG,KAAK,KAAA,EAC1B,cAAW,EAAX,MAAM,mBAAG,EAAE,KAAA,EACX,iBAAa,EAAb,SAAS,mBAAG,CAAC,KAAA,EACb,aAAU,EAAV,KAAK,mBAAG,EAAE,KAAA,EACV,iBAAkB,EAAlB,SAAS,mBAAG,MAAM,KAAA,EAClB,0BAAwB,EAAxB,kBAAkB,mBAAG,GAAG,KAAA,EACxB,UAAU,gBAA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KAAK,IAAI,OAAA,KAAK,CAAC,KAAK,GAAC,EAAE,EAAd,CAAc,CAIvC,CAAA","sourcesContent":["import classNames from 'classnames'\nimport React, { HTMLAttributes, useEffect, useState } from 'react'\nimport styled, { CSSProp } from 'styled-components'\nimport Group from './Group'\n\nexport type Props = HTMLAttributes<HTMLButtonElement> & {\n isActive?: boolean\n isDoubleJointed?: boolean\n isLastBarHalfWidth?: boolean\n height?: number\n thickness?: number\n width?: number\n tintColor?: string\n transitionDuration?: number\n onActivate?: () => void\n onDeactivate?: () => void\n cssBar?: CSSProp<any>\n}\n\nexport default function BurgerButton({\n isActive: externalIsActive = false,\n isDoubleJointed = false,\n isLastBarHalfWidth = false,\n height = 20,\n thickness = 2,\n width = 20,\n tintColor = '#000',\n transitionDuration = 200,\n onActivate,\n onDeactivate,\n cssBar,\n ...props\n}: Props) {\n const [isActive, setIsActive] = useState(externalIsActive)\n\n useEffect(() => {\n if (isActive !== externalIsActive) {\n setIsActive(externalIsActive)\n }\n }, [externalIsActive])\n\n useEffect(() => {\n if (isActive) {\n onActivate?.()\n }\n else {\n onDeactivate?.()\n }\n }, [isActive])\n\n return (\n <StyledRoot width={width} height={height} thickness={thickness} onClick={() => setIsActive(!isActive)} {...props}>\n <Group count={isDoubleJointed ? 2 : 1}>\n <StyledJoint\n className={classNames({ active: isActive, half: isDoubleJointed })}\n height={height}\n isLastBarHalfWidth={isLastBarHalfWidth}\n thickness={thickness}\n width={width}\n >\n <Group count={3}>\n <StyledBar className={classNames({ active: isActive, half: isDoubleJointed })} style={{ height: `${thickness}px` }} css={cssBar}/>\n </Group>\n </StyledJoint>\n </Group>\n </StyledRoot>\n )\n}\n\nconst StyledBar = styled.span`\n background: #fff;\n box-sizing: border-box;\n margin: 0;\n padding: 0;\n position: absolute;\n transition-duration: 100ms;\n transition-property: width, height, transform, opacity, background;\n transition-timing-function: ease-out;\n width: 100%;\n\n ${props => props.css}\n`\n\nconst StyledJoint = styled.div<{\n height: number\n isLastBarHalfWidth: boolean\n thickness: number\n width: number\n}>`\n height: 100%;\n position: absolute;\n width: 100%;\n\n &.half {\n width: 50%;\n }\n\n &:nth-of-type(1) {\n left: 0;\n top: 0;\n\n ${StyledBar}:nth-child(1) {\n left: 0;\n top: 0;\n transform-origin: center;\n transform: translate3d(0, 0, 0) rotate(0deg);\n }\n\n ${StyledBar}:nth-child(2) {\n left: 0;\n top: ${props => props.height*.5 - props.thickness*.5}px;\n transform-origin: center;\n transform: translate3d(0, 0, 0) scale(1);\n }\n\n ${StyledBar}:nth-child(3) {\n left: 0;\n top: ${props => props.height - props.thickness}px;\n transform-origin: center;\n transform: translate3d(0, 0, 0) rotate(0deg);\n width: ${props => props.isLastBarHalfWidth ? '50%' : '100%'};\n }\n\n &.active {\n ${StyledBar}:nth-child(1) {\n transform: ${props => `translate3d(0, ${props.height*.5 - props.thickness*.5}px, 0) rotate(45deg)`};\n }\n\n ${StyledBar}:nth-child(2) {\n transform: ${props => 'translate3d(0, 0, 0) scale(0)'};\n }\n\n ${StyledBar}:nth-child(3) {\n transform: ${props => `translate3d(0, ${props.thickness*.5 - props.height*.5}px, 0) rotate(-45deg)`};\n width: 100%;\n }\n }\n\n &.half {\n ${StyledBar}:nth-child(1) {\n transform-origin: right center;\n }\n\n ${StyledBar}:nth-child(2) {\n transform-origin: right center;\n }\n\n ${StyledBar}:nth-child(3) {\n transform-origin: right center;\n width: 100%;\n }\n }\n }\n\n &:nth-of-type(2) {\n right: 0;\n top: 0;\n\n span:nth-child(1) {\n left: 0;\n top: 0;\n transform-origin: left center;\n transform: translate3d(0, 0, 0) rotate(0deg);\n }\n\n span:nth-child(2) {\n left: 0;\n top: ${props => props.height*.5 - props.thickness*.5}px;\n transform-origin: left center;\n transform: translate3d(0, 0, 0) scale(1);\n }\n\n span:nth-child(3) {\n left: 0;\n top: ${props => props.height - props.thickness}px;\n transform-origin: left center;\n transform: translate3d(0, 0, 0) rotate(0deg);\n width: ${props => props.isLastBarHalfWidth ? 0 : '100%'};\n }\n\n &.active {\n span:nth-child(1) {\n transform: ${props => `translate3d(0, ${props.height*.5 - props.thickness*.5}px, 0) rotate(-45deg)`};\n }\n\n span:nth-child(2) {\n transform: translate3d(0, 0, 0) scale(0);\n }\n\n span:nth-child(3) {\n transform: ${props => `translate3d(0, ${props.thickness*.5 - props.height*.5}px, 0) rotate(45deg)`};\n width: 100%;\n }\n }\n }\n`\n\nconst StyledRoot = styled.button<{\n height: number\n thickness: number\n width: number\n}>`\n background: transparent;\n border: none;\n box-sizing: border-box;\n display: block;\n height: ${props => props.height}px;\n margin: 0;\n min-height: ${props => props.height}px;\n min-width: ${props => props.width}px;\n outline: none;\n padding: 0;\n pointer-events: auto;\n position: relative;\n width: ${props => props.width}px;\n\n html:not(.touch) &:hover {\n ${StyledJoint}:not(.half) {\n span:nth-child(3) {\n width: ${props => props.width}px;\n }\n }\n\n ${StyledJoint}.half:nth-of-type(2) {\n span:nth-child(3) {\n width: ${props => props.width*.5}px;\n }\n }\n }\n`\n"]}
|
package/lib/Dial.d.ts
CHANGED
|
@@ -20,27 +20,24 @@ export declare type Props = HTMLAttributes<HTMLDivElement> & {
|
|
|
20
20
|
radius?: number;
|
|
21
21
|
/**
|
|
22
22
|
* The thickness of the knob, which is equivalent to the `stroke-width` of the `<path>` element.
|
|
23
|
-
* Note that this overwrites the `stroke-width` set inside `
|
|
23
|
+
* Note that this overwrites the `stroke-width` set inside `cssKnob`.
|
|
24
24
|
*/
|
|
25
25
|
knobThickness?: number;
|
|
26
26
|
/**
|
|
27
27
|
* CSS of the knob, which is a `<path>` element.
|
|
28
28
|
*/
|
|
29
|
-
|
|
29
|
+
cssKnob?: CSSProp<any>;
|
|
30
30
|
/**
|
|
31
31
|
* The thickness of the circular track, which is equivalent to the `stroke-width` of the
|
|
32
|
-
* `<circle>` element. Note that this overwrites the `stroke-width` set inside `
|
|
32
|
+
* `<circle>` element. Note that this overwrites the `stroke-width` set inside `cssTrack`.
|
|
33
33
|
*/
|
|
34
34
|
trackThickness?: number;
|
|
35
35
|
/**
|
|
36
36
|
* CSS of the track, which is a `<circle>` element.
|
|
37
37
|
*/
|
|
38
|
-
|
|
38
|
+
cssTrack?: CSSProp<any>;
|
|
39
39
|
};
|
|
40
40
|
/**
|
|
41
41
|
* A circular dial with a knob and a track.
|
|
42
|
-
*
|
|
43
|
-
* @requires react
|
|
44
|
-
* @requires styled-components
|
|
45
42
|
*/
|
|
46
|
-
export default function Dial({ angle, radius, knobLength, knobThickness,
|
|
43
|
+
export default function Dial({ angle, radius, knobLength, knobThickness, cssKnob, trackThickness, cssTrack, style, ...props }: Props): JSX.Element;
|
package/lib/Dial.js
CHANGED
|
@@ -50,21 +50,18 @@ function arcPath(x, y, radius, startAngle, endAngle) {
|
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
52
|
* A circular dial with a knob and a track.
|
|
53
|
-
*
|
|
54
|
-
* @requires react
|
|
55
|
-
* @requires styled-components
|
|
56
53
|
*/
|
|
57
54
|
function Dial(_a) {
|
|
58
|
-
var _b = _a.angle, angle = _b === void 0 ? 0 : _b, _c = _a.radius, radius = _c === void 0 ? 50 : _c, _d = _a.knobLength, knobLength = _d === void 0 ? 30 : _d, _e = _a.knobThickness, knobThickness = _e === void 0 ? 10 : _e,
|
|
55
|
+
var _b = _a.angle, angle = _b === void 0 ? 0 : _b, _c = _a.radius, radius = _c === void 0 ? 50 : _c, _d = _a.knobLength, knobLength = _d === void 0 ? 30 : _d, _e = _a.knobThickness, knobThickness = _e === void 0 ? 10 : _e, cssKnob = _a.cssKnob, _f = _a.trackThickness, trackThickness = _f === void 0 ? 2 : _f, cssTrack = _a.cssTrack, style = _a.style, props = __rest(_a, ["angle", "radius", "knobLength", "knobThickness", "cssKnob", "trackThickness", "cssTrack", "style"]);
|
|
59
56
|
var diameter = radius * 2;
|
|
60
57
|
var clampedKnobAngle = Math.max(0, Math.min(360, knobLength));
|
|
61
58
|
return (react_1.default.createElement(StyledRoot, __assign({ style: __assign(__assign({}, style), { width: "".concat(diameter, "px"), height: "".concat(diameter, "px") }) }, props),
|
|
62
59
|
react_1.default.createElement(StyledTrack, null,
|
|
63
60
|
react_1.default.createElement("svg", { width: diameter, height: diameter, viewBox: "0 0 ".concat(diameter, " ").concat(diameter) },
|
|
64
|
-
react_1.default.createElement(StyledTrackCircle, { cx: radius, cy: radius, r: radius - trackThickness / 2, css:
|
|
61
|
+
react_1.default.createElement(StyledTrackCircle, { cx: radius, cy: radius, r: radius - trackThickness / 2, css: cssTrack, strokeWidth: trackThickness }))),
|
|
65
62
|
react_1.default.createElement(StyledKnob, { style: { transform: "rotate(".concat((angle + 360) % 360, "deg)") } },
|
|
66
63
|
react_1.default.createElement("svg", { viewBox: "0 0 ".concat(diameter, " ").concat(diameter), xmlns: 'http://www.w3.org/2000/svg' },
|
|
67
|
-
react_1.default.createElement(StyledKnobPath, { css:
|
|
64
|
+
react_1.default.createElement(StyledKnobPath, { css: cssKnob, strokeWidth: knobThickness, d: arcPath(radius, radius, radius - knobThickness / 2 - (trackThickness - knobThickness) / 2, -clampedKnobAngle / 2, clampedKnobAngle / 2) })))));
|
|
68
65
|
}
|
|
69
66
|
exports.default = Dial;
|
|
70
67
|
var StyledTrack = styled_components_1.default.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n height: 100%;\n left: 0;\n position: absolute;\n top: 0;\n transform-origin: center;\n width: 100%;\n"], ["\n height: 100%;\n left: 0;\n position: absolute;\n top: 0;\n transform-origin: center;\n width: 100%;\n"])));
|
package/lib/Dial.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dial.js","sourceRoot":"/","sources":["Dial.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAA6C;AAC7C,wEAAmD;AA8CnD,SAAS,gBAAgB,CAAC,OAAe,EAAE,OAAe,EAAE,MAAc,EAAE,cAAsB;IAChG,IAAM,cAAc,GAAG,CAAC,cAAc,GAAG,EAAE,CAAC,GAAG,IAA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CAAC,MAAM,wHAAA,+CAGnC,EAAkB,IACrB,KADG,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,GAAG,EAAT,CAAS,CACrB,CAAA;AAED,IAAM,UAAU,GAAG,2BAAM,CAAC,GAAG,2WAAA,wSAiB5B,IAAA,CAAA;AAED,IAAM,cAAc,GAAG,2BAAM,CAAC,IAAI,gGAAA,uBAE9B,EAAkB,IACrB,KADG,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,GAAG,EAAT,CAAS,CACrB,CAAA;AAED,IAAM,UAAU,GAAG,2BAAM,CAAC,GAAG,qHAAA,kDAG5B,IAAA,CAAA","sourcesContent":["import React, { HTMLAttributes } from 'react'\nimport styled, { CSSProp } from 'styled-components'\n\nexport type Props = HTMLAttributes<HTMLDivElement> & {\n /**\n * Current angle reading of the compass, between 0.0 - 360.0 degrees, inclusive.\n */\n angle?: number\n\n /**\n * Length of the knob along the track expressed in degrees, between 0.0 and 360.0 degrees,\n * exclusive. If set to 0 or 360, the knob disappears.\n *\n * @example Suppose the compass were to be used to control a photosphere of an image that is 1000\n * x 500, and the window size is 500 x 500, that would mean the FOV is 500 / 1000 * 360 =\n * 180 degrees.\n */\n knobLength?: number\n\n /**\n * Radius of the compass.\n */\n radius?: number\n\n /**\n * The thickness of the knob, which is equivalent to the `stroke-width` of the `<path>` element.\n * Note that this overwrites the `stroke-width` set inside `cssKnob`.\n */\n knobThickness?: number\n\n /**\n * CSS of the knob, which is a `<path>` element.\n */\n cssKnob?: CSSProp<any>\n\n /**\n * The thickness of the circular track, which is equivalent to the `stroke-width` of the\n * `<circle>` element. Note that this overwrites the `stroke-width` set inside `cssTrack`.\n */\n trackThickness?: number\n\n /**\n * CSS of the track, which is a `<circle>` element.\n */\n cssTrack?: CSSProp<any>\n}\n\nfunction polarToCartesian(centerX: number, centerY: number, radius: number, angleInDegrees: number) {\n const angleInRadians = (angleInDegrees - 90) * Math.PI / 180.0\n\n return {\n x: centerX + (radius * Math.cos(angleInRadians)),\n y: centerY + (radius * Math.sin(angleInRadians)),\n }\n}\n\nfunction arcPath(x: number, y: number, radius: number, startAngle: number, endAngle: number) {\n const start = polarToCartesian(x, y, radius, endAngle)\n const end = polarToCartesian(x, y, radius, startAngle)\n const largeArcFlag = endAngle - startAngle <= 180 ? '0' : '1'\n const d = [\n 'M', start.x, start.y,\n 'A', radius, radius, 0, largeArcFlag, 0, end.x, end.y,\n ]\n\n return d.join(' ')\n}\n\n/**\n * A circular dial with a knob and a track.\n */\nexport default function Dial({\n angle = 0,\n radius = 50,\n knobLength = 30,\n knobThickness = 10,\n cssKnob,\n trackThickness = 2,\n cssTrack,\n style,\n ...props\n}: Props) {\n const diameter = radius * 2\n const clampedKnobAngle = Math.max(0, Math.min(360, knobLength))\n\n return (\n <StyledRoot style={{ ...style, width: `${diameter}px`, height: `${diameter}px` }} {...props}>\n <StyledTrack>\n <svg width={diameter} height={diameter} viewBox={`0 0 ${diameter} ${diameter}`}>\n <StyledTrackCircle\n cx={radius}\n cy={radius}\n r={radius - trackThickness / 2}\n css={cssTrack}\n strokeWidth={trackThickness}\n />\n </svg>\n </StyledTrack>\n <StyledKnob style={{ transform: `rotate(${(angle + 360) % 360}deg)` }}>\n <svg viewBox={`0 0 ${diameter} ${diameter}`} xmlns='http://www.w3.org/2000/svg'>\n <StyledKnobPath css={cssKnob} strokeWidth={knobThickness} d={arcPath(radius, radius, radius - knobThickness / 2 - (trackThickness - knobThickness) / 2, -clampedKnobAngle / 2, clampedKnobAngle / 2)}/>\n </svg>\n </StyledKnob>\n </StyledRoot>\n )\n}\n\nconst StyledTrack = styled.div`\n height: 100%;\n left: 0;\n position: absolute;\n top: 0;\n transform-origin: center;\n width: 100%;\n`\n\nconst StyledTrackCircle = styled.circle`\n stroke-dasharray: 4;\n stroke: #fff;\n ${props => props.css}\n`\n\nconst StyledKnob = styled.div`\n background-position: center;\n background-repeat: no-repeat;\n background-size: 100%;\n height: 100%;\n left: 0;\n position: absolute;\n top: 0;\n transform-origin: center;\n width: 100%;\n\n svg {\n overflow: visible;\n position: absolute;\n right: 0;\n top: 0;\n }\n`\n\nconst StyledKnobPath = styled.path`\n stroke: #fff;\n ${props => props.css}\n`\n\nconst StyledRoot = styled.div`\n box-sizing: border-box;\n display: block;\n`\n"]}
|
package/lib/FlatSVG.d.ts
CHANGED
|
@@ -1,14 +1,42 @@
|
|
|
1
1
|
import { HTMLAttributes } from 'react';
|
|
2
|
+
import { CSSProp } from 'styled-components';
|
|
2
3
|
export declare type Props = HTMLAttributes<HTMLDivElement> & {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
/**
|
|
5
|
+
* The SVG string markup, i.e. "<svg>...</svg>".
|
|
6
|
+
*/
|
|
7
|
+
markup: string;
|
|
8
|
+
/**
|
|
9
|
+
* Specifies whether the 'class' should be removed in the SVG root node and all of its child
|
|
10
|
+
* nodes.
|
|
11
|
+
*/
|
|
12
|
+
stripClasses?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Specifies whether extraneous attributes should be removed from the SVG root node. The
|
|
15
|
+
* `whitelistedAttributes` prop defines what attributes should be kept.
|
|
16
|
+
*/
|
|
17
|
+
stripExtraneousAttributes?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Specifies whether the 'id' attribute should be removed in the SVG root node and all of its
|
|
20
|
+
* child nodes.
|
|
21
|
+
*/
|
|
22
|
+
stripIds?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Specifies whether the 'style' atribute and any <style> nodes should be removed in the SVG root
|
|
25
|
+
* node and all of its child nodes.
|
|
26
|
+
*/
|
|
27
|
+
stripStyles?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Extended CSS to be provided to the SVG root node.
|
|
30
|
+
*/
|
|
31
|
+
cssSVG?: CSSProp<any>;
|
|
32
|
+
/**
|
|
33
|
+
* Specifies attribute names to exclude from being stripped if `stripExtraneousAttributes` is
|
|
34
|
+
* enabled. By default, only `viewBox` is whitelisted.
|
|
35
|
+
*/
|
|
36
|
+
whitelistedAttributes?: string[];
|
|
7
37
|
};
|
|
8
38
|
/**
|
|
9
|
-
* A component whose root element wraps an SVG markup.
|
|
10
|
-
*
|
|
11
|
-
* @requires react
|
|
12
|
-
* @requires styled-component
|
|
39
|
+
* A component whose root element wraps an SVG markup. When wrapping the SVG, it will attempt to
|
|
40
|
+
* sanitize the markup (i.e. stripping useless attributes) according to the props specified.
|
|
13
41
|
*/
|
|
14
|
-
export default function FlatSVG({
|
|
42
|
+
export default function FlatSVG({ markup, stripClasses, stripExtraneousAttributes, stripIds, stripStyles, cssSVG, whitelistedAttributes, ...props }: Props): JSX.Element;
|
package/lib/FlatSVG.js
CHANGED
|
@@ -14,25 +14,6 @@ var __assign = (this && this.__assign) || function () {
|
|
|
14
14
|
};
|
|
15
15
|
return __assign.apply(this, arguments);
|
|
16
16
|
};
|
|
17
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
-
if (k2 === undefined) k2 = k;
|
|
19
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
20
|
-
}) : (function(o, m, k, k2) {
|
|
21
|
-
if (k2 === undefined) k2 = k;
|
|
22
|
-
o[k2] = m[k];
|
|
23
|
-
}));
|
|
24
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
-
}) : function(o, v) {
|
|
27
|
-
o["default"] = v;
|
|
28
|
-
});
|
|
29
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
30
|
-
if (mod && mod.__esModule) return mod;
|
|
31
|
-
var result = {};
|
|
32
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
33
|
-
__setModuleDefault(result, mod);
|
|
34
|
-
return result;
|
|
35
|
-
};
|
|
36
17
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
37
18
|
var t = {};
|
|
38
19
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -44,23 +25,97 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
44
25
|
}
|
|
45
26
|
return t;
|
|
46
27
|
};
|
|
28
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
29
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
30
|
+
if (!m) return o;
|
|
31
|
+
var i = m.call(o), r, ar = [], e;
|
|
32
|
+
try {
|
|
33
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
34
|
+
}
|
|
35
|
+
catch (error) { e = { error: error }; }
|
|
36
|
+
finally {
|
|
37
|
+
try {
|
|
38
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
39
|
+
}
|
|
40
|
+
finally { if (e) throw e.error; }
|
|
41
|
+
}
|
|
42
|
+
return ar;
|
|
43
|
+
};
|
|
44
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
45
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
46
|
+
if (ar || !(i in from)) {
|
|
47
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
48
|
+
ar[i] = from[i];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
52
|
+
};
|
|
47
53
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
48
54
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
49
55
|
};
|
|
50
56
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
57
|
var react_1 = __importDefault(require("react"));
|
|
52
|
-
var styled_components_1 =
|
|
58
|
+
var styled_components_1 = __importDefault(require("styled-components"));
|
|
59
|
+
function removeStyles(element) {
|
|
60
|
+
element.removeAttribute('style');
|
|
61
|
+
var inlineStyles = element.getElementsByTagName('style');
|
|
62
|
+
var numInlineStyles = inlineStyles.length;
|
|
63
|
+
for (var i = 0; i < numInlineStyles; i++) {
|
|
64
|
+
var inlineStyle = inlineStyles[i];
|
|
65
|
+
inlineStyle.remove();
|
|
66
|
+
}
|
|
67
|
+
var numChildren = element.children.length;
|
|
68
|
+
for (var i = 0; i < numChildren; i++) {
|
|
69
|
+
removeStyles(element.children[i]);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function removeAttributes(element, attributes, recursive, whitelist) {
|
|
73
|
+
if (attributes === void 0) { attributes = undefined; }
|
|
74
|
+
if (recursive === void 0) { recursive = false; }
|
|
75
|
+
if (whitelist === void 0) { whitelist = []; }
|
|
76
|
+
var attrs = attributes !== null && attributes !== void 0 ? attributes : element.getAttributeNames();
|
|
77
|
+
var numAttrs = attrs.length;
|
|
78
|
+
for (var i = 0; i < numAttrs; i++) {
|
|
79
|
+
var attr = attrs[i];
|
|
80
|
+
var keep = whitelist.indexOf(attr) > -1;
|
|
81
|
+
if (!keep)
|
|
82
|
+
element.removeAttribute(attr);
|
|
83
|
+
}
|
|
84
|
+
if (recursive) {
|
|
85
|
+
var numChildren = element.children.length;
|
|
86
|
+
for (var i = 0; i < numChildren; i++) {
|
|
87
|
+
removeAttributes(element.children[i], attributes, recursive, whitelist);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
53
91
|
/**
|
|
54
|
-
* A component whose root element wraps an SVG markup.
|
|
55
|
-
*
|
|
56
|
-
* @requires react
|
|
57
|
-
* @requires styled-component
|
|
92
|
+
* A component whose root element wraps an SVG markup. When wrapping the SVG, it will attempt to
|
|
93
|
+
* sanitize the markup (i.e. stripping useless attributes) according to the props specified.
|
|
58
94
|
*/
|
|
59
95
|
function FlatSVG(_a) {
|
|
60
|
-
var _b = _a.
|
|
61
|
-
|
|
96
|
+
var markup = _a.markup, _b = _a.stripClasses, stripClasses = _b === void 0 ? true : _b, _c = _a.stripExtraneousAttributes, stripExtraneousAttributes = _c === void 0 ? true : _c, _d = _a.stripIds, stripIds = _d === void 0 ? true : _d, _e = _a.stripStyles, stripStyles = _e === void 0 ? true : _e, cssSVG = _a.cssSVG, _f = _a.whitelistedAttributes, whitelistedAttributes = _f === void 0 ? ['viewBox'] : _f, props = __rest(_a, ["markup", "stripClasses", "stripExtraneousAttributes", "stripIds", "stripStyles", "cssSVG", "whitelistedAttributes"]);
|
|
97
|
+
function sanitizedMarkup() {
|
|
98
|
+
var mockContainer = document.createElement('div');
|
|
99
|
+
mockContainer.innerHTML = markup;
|
|
100
|
+
var elements = mockContainer.getElementsByTagName('svg');
|
|
101
|
+
if (elements.length > 1)
|
|
102
|
+
throw new Error('More than one SVG element found in provided markup');
|
|
103
|
+
var svgElement = elements[0];
|
|
104
|
+
if (!svgElement)
|
|
105
|
+
throw new Error('No SVG in provided markup');
|
|
106
|
+
if (stripExtraneousAttributes)
|
|
107
|
+
removeAttributes(svgElement, undefined, false, __spreadArray(__spreadArray([], __read(whitelistedAttributes), false), ['style', 'class', 'id'], false));
|
|
108
|
+
if (stripIds)
|
|
109
|
+
removeAttributes(svgElement, ['id'], true);
|
|
110
|
+
if (stripClasses)
|
|
111
|
+
removeAttributes(svgElement, ['class'], true);
|
|
112
|
+
if (stripStyles)
|
|
113
|
+
removeStyles(svgElement);
|
|
114
|
+
return svgElement.outerHTML;
|
|
115
|
+
}
|
|
116
|
+
return (react_1.default.createElement(StyledRoot, __assign({ dangerouslySetInnerHTML: { __html: sanitizedMarkup() }, cssSVG: cssSVG }, props)));
|
|
62
117
|
}
|
|
63
118
|
exports.default = FlatSVG;
|
|
64
|
-
var StyledRoot = styled_components_1.default.figure(
|
|
65
|
-
var templateObject_1
|
|
119
|
+
var StyledRoot = styled_components_1.default.figure(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n box-sizing: border-box;\n display: inline-block;\n flex: 0 0 auto;\n height: auto;\n position: relative;\n width: auto;\n\n > svg {\n height: auto;\n transition-delay: inherit;\n transition-duration: inherit;\n transition-property: inherit;\n transition-timing-function: inherit;\n width: auto;\n\n * {\n transition-delay: inherit;\n transition-duration: inherit;\n transition-property: inherit;\n transition-timing-function: inherit;\n }\n\n ", "\n }\n"], ["\n box-sizing: border-box;\n display: inline-block;\n flex: 0 0 auto;\n height: auto;\n position: relative;\n width: auto;\n\n > svg {\n height: auto;\n transition-delay: inherit;\n transition-duration: inherit;\n transition-property: inherit;\n transition-timing-function: inherit;\n width: auto;\n\n * {\n transition-delay: inherit;\n transition-duration: inherit;\n transition-property: inherit;\n transition-timing-function: inherit;\n }\n\n ", "\n }\n"])), function (props) { return props.cssSVG; });
|
|
120
|
+
var templateObject_1;
|
|
66
121
|
//# sourceMappingURL=FlatSVG.js.map
|
package/lib/FlatSVG.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FlatSVG.js","sourceRoot":"/","sources":["FlatSVG.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"FlatSVG.js","sourceRoot":"/","sources":["FlatSVG.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAA6C;AAC7C,wEAAmD;AA4CnD,SAAS,YAAY,CAAC,OAAgB;IACpC,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,CAAA;IAEhC,IAAM,YAAY,GAAG,OAAO,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAA;IAC1D,IAAM,eAAe,GAAG,YAAY,CAAC,MAAM,CAAA;IAE3C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,eAAe,EAAE,CAAC,EAAE,EAAE;QACxC,IAAM,WAAW,GAAG,YAAY,CAAC,CAAC,CAAC,CAAA;QACnC,WAAW,CAAC,MAAM,EAAE,CAAA;KACrB;IAED,IAAM,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAA;IAE3C,KAAK,IAAI,CAAC,GAAG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fAuBvD,EAAqB,SAE1B,KAFK,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,MAAM,EAAZ,CAAY,CAE1B,CAAA","sourcesContent":["import React, { HTMLAttributes } from 'react'\nimport styled, { CSSProp } from 'styled-components'\n\nexport type Props = HTMLAttributes<HTMLDivElement> & {\n /**\n * The SVG string markup, i.e. \"<svg>...</svg>\".\n */\n markup: string\n\n /**\n * Specifies whether the 'class' should be removed in the SVG root node and all of its child\n * nodes.\n */\n stripClasses?: boolean\n\n /**\n * Specifies whether extraneous attributes should be removed from the SVG root node. The\n * `whitelistedAttributes` prop defines what attributes should be kept.\n */\n stripExtraneousAttributes?: boolean\n\n /**\n * Specifies whether the 'id' attribute should be removed in the SVG root node and all of its\n * child nodes.\n */\n stripIds?: boolean\n\n /**\n * Specifies whether the 'style' atribute and any <style> nodes should be removed in the SVG root\n * node and all of its child nodes.\n */\n stripStyles?: boolean\n\n /**\n * Extended CSS to be provided to the SVG root node.\n */\n cssSVG?: CSSProp<any>\n\n /**\n * Specifies attribute names to exclude from being stripped if `stripExtraneousAttributes` is\n * enabled. By default, only `viewBox` is whitelisted.\n */\n whitelistedAttributes?: string[]\n}\n\nfunction removeStyles(element: Element) {\n element.removeAttribute('style')\n\n const inlineStyles = element.getElementsByTagName('style')\n const numInlineStyles = inlineStyles.length\n\n for (let i = 0; i < numInlineStyles; i++) {\n const inlineStyle = inlineStyles[i]\n inlineStyle.remove()\n }\n\n const numChildren = element.children.length\n\n for (let i = 0; i < numChildren; i++) {\n removeStyles(element.children[i])\n }\n}\n\nfunction removeAttributes(element: Element, attributes: string[] | undefined = undefined, recursive = false, whitelist: string[] = []) {\n const attrs = attributes ?? element.getAttributeNames()\n const numAttrs = attrs.length\n\n for (let i = 0; i < numAttrs; i++) {\n const attr = attrs[i]\n const keep = whitelist.indexOf(attr) > -1\n if (!keep) element.removeAttribute(attr)\n }\n\n if (recursive) {\n const numChildren = element.children.length\n\n for (let i = 0; i < numChildren; i++) {\n removeAttributes(element.children[i], attributes, recursive, whitelist)\n }\n }\n}\n\n/**\n * A component whose root element wraps an SVG markup. When wrapping the SVG, it will attempt to\n * sanitize the markup (i.e. stripping useless attributes) according to the props specified.\n */\nexport default function FlatSVG({\n markup,\n stripClasses = true,\n stripExtraneousAttributes = true,\n stripIds = true,\n stripStyles = true,\n cssSVG,\n whitelistedAttributes = ['viewBox'],\n ...props\n}: Props) {\n function sanitizedMarkup(): string {\n const mockContainer = document.createElement('div')\n mockContainer.innerHTML = markup\n\n const elements = mockContainer.getElementsByTagName('svg')\n if (elements.length > 1) throw new Error('More than one SVG element found in provided markup')\n\n const svgElement = elements[0]\n if (!svgElement) throw new Error('No SVG in provided markup')\n\n if (stripExtraneousAttributes) removeAttributes(svgElement, undefined, false, [...whitelistedAttributes, 'style', 'class', 'id'])\n if (stripIds) removeAttributes(svgElement, ['id'], true)\n if (stripClasses) removeAttributes(svgElement, ['class'], true)\n if (stripStyles) removeStyles(svgElement)\n\n return svgElement.outerHTML\n }\n\n return (\n <StyledRoot\n dangerouslySetInnerHTML={{ __html: sanitizedMarkup() }}\n cssSVG={cssSVG}\n {...props}\n />\n )\n}\n\nconst StyledRoot = styled.figure<{ cssSVG: Props['cssSVG'] }>`\n box-sizing: border-box;\n display: inline-block;\n flex: 0 0 auto;\n height: auto;\n position: relative;\n width: auto;\n\n > svg {\n height: auto;\n transition-delay: inherit;\n transition-duration: inherit;\n transition-property: inherit;\n transition-timing-function: inherit;\n width: auto;\n\n * {\n transition-delay: inherit;\n transition-duration: inherit;\n transition-property: inherit;\n transition-timing-function: inherit;\n }\n\n ${props => props.cssSVG}\n }\n`\n"]}
|