@desynova-digital/player 3.9.7 → 4.0.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.
Files changed (130) hide show
  1. package/Player.js +945 -0
  2. package/control/AudioTracksMenuButton.js +91 -0
  3. package/control/AudioTracksMenuButton.jsx +80 -0
  4. package/control/ControlBar.js +303 -0
  5. package/control/ControlBar.jsx +264 -0
  6. package/control/CurrentTimeDisplay.js +34 -0
  7. package/control/CurrentTimeDisplay.jsx +35 -0
  8. package/control/DurationDisplay.js +38 -0
  9. package/control/DurationDisplay.jsx +48 -0
  10. package/control/ForwardBackwardControl.js +76 -0
  11. package/control/ForwardBackwardControl.jsx +79 -0
  12. package/control/FullscreenToggle.js +82 -0
  13. package/control/FullscreenToggle.jsx +83 -0
  14. package/control/MarkInControl.js +124 -0
  15. package/control/MarkInControl.jsx +109 -0
  16. package/control/MarkOutControl.js +137 -0
  17. package/control/MarkOutControl.jsx +131 -0
  18. package/control/MarkerBar.js +127 -0
  19. package/control/MarkerBar.jsx +107 -0
  20. package/control/MarkingControl.js +82 -0
  21. package/control/MarkingControl.jsx +143 -0
  22. package/control/MarkingDuration.js +44 -0
  23. package/control/MarkingPreview.js +49 -0
  24. package/control/MarkingPreview.jsx +60 -0
  25. package/control/PlayBackRateControl.js +106 -0
  26. package/control/PlayBackRateControl.jsx +106 -0
  27. package/control/PlayProgressBar.js +61 -0
  28. package/control/PlayProgressBar.jsx +92 -0
  29. package/control/PlayToggle.js +56 -0
  30. package/control/PlayToggle.jsx +57 -0
  31. package/control/PointersBar.js +231 -0
  32. package/control/PointersBar.jsx +286 -0
  33. package/control/ProgressControl.js +127 -0
  34. package/control/ProgressControl.jsx +155 -0
  35. package/control/SeekBar.js +204 -0
  36. package/control/SeekBar.jsx +229 -0
  37. package/control/SettingsMenuButton.js +63 -0
  38. package/control/SettingsMenuButton.jsx +69 -0
  39. package/control/Slider.js +274 -0
  40. package/control/Slider.jsx +243 -0
  41. package/control/Timeline.js +118 -0
  42. package/control/Timeline.jsx +131 -0
  43. package/control/VolumeBar.js +198 -0
  44. package/control/VolumeBar.jsx +174 -0
  45. package/control/VolumeLevel.js +61 -0
  46. package/control/VolumeLevel.jsx +66 -0
  47. package/control/VolumneMenuButton.js +112 -0
  48. package/control/VolumneMenuButton.jsx +111 -0
  49. package/header/Header.js +309 -0
  50. package/header/Header.jsx +479 -0
  51. package/index.js +9 -151
  52. package/media/AudioMeter.js +381 -0
  53. package/media/AudioMeter.jsx +411 -0
  54. package/media/SDOutline.js +82 -0
  55. package/media/SDOutline.jsx +90 -0
  56. package/media/Video.js +684 -0
  57. package/media/Video.jsx +714 -0
  58. package/package.json +5 -1
  59. package/playlist/Playlist.js +67 -0
  60. package/playlist/Playlist.jsx +91 -0
  61. package/playlist/index.js +13 -0
  62. package/shortcuts/Shortcut.js +662 -0
  63. package/utils/Menu.js +50 -0
  64. package/utils/Menu.jsx +105 -0
  65. package/{colors.js → utils/colors.js} +13 -13
  66. package/utils/index.js +52 -122
  67. package/Manager.js +0 -124
  68. package/actions/player.js +0 -375
  69. package/actions/video.js +0 -230
  70. package/components/AudioMeter.js +0 -414
  71. package/components/BigPlayButton.js +0 -110
  72. package/components/ImageViewer.js +0 -318
  73. package/components/MarkerBar.js +0 -138
  74. package/components/Menu.js +0 -77
  75. package/components/Player.js +0 -821
  76. package/components/PlayerHeader.js +0 -472
  77. package/components/Playlist.js +0 -133
  78. package/components/PointersBar.js +0 -299
  79. package/components/PosterImage.js +0 -61
  80. package/components/SDOutline.js +0 -68
  81. package/components/Shortcut.js +0 -621
  82. package/components/Slider.js +0 -317
  83. package/components/TagsBar.js +0 -100
  84. package/components/Video.js +0 -1431
  85. package/components/control-bar/AudioTracksMenuButton.js +0 -113
  86. package/components/control-bar/CameraButton.js +0 -88
  87. package/components/control-bar/CommentsButton.js +0 -216
  88. package/components/control-bar/ControlBar.js +0 -260
  89. package/components/control-bar/EditorControlMenuButton.js +0 -412
  90. package/components/control-bar/ForwardControl.js +0 -17
  91. package/components/control-bar/ForwardReplayControl.js +0 -122
  92. package/components/control-bar/FullscreenToggle.js +0 -101
  93. package/components/control-bar/PlayToggle.js +0 -98
  94. package/components/control-bar/ReplayControl.js +0 -17
  95. package/components/control-bar/SettingsMenuButton.js +0 -43
  96. package/components/control-bar/SubtitleLanguagesMenuButton.js +0 -174
  97. package/components/control-bar/VolumeMenuButton.js +0 -134
  98. package/components/control-bar/ZoomMenuButton.js +0 -116
  99. package/components/marking-controls/MarkInControl.js +0 -140
  100. package/components/marking-controls/MarkOutControl.js +0 -155
  101. package/components/marking-controls/MarkingAddButton.js +0 -94
  102. package/components/marking-controls/MarkingControl.js +0 -135
  103. package/components/marking-controls/MarkingDeleteButton.js +0 -84
  104. package/components/marking-controls/MarkingDuration.js +0 -77
  105. package/components/marking-controls/MarkingPreview.js +0 -86
  106. package/components/progress-bar/AudioWaveform.js +0 -144
  107. package/components/progress-bar/LoadProgressBar.js +0 -90
  108. package/components/progress-bar/MouseTimeDisplay.js +0 -53
  109. package/components/progress-bar/PlayProgressBar.js +0 -79
  110. package/components/progress-bar/ProgressControl.js +0 -222
  111. package/components/progress-bar/SeekBar.js +0 -261
  112. package/components/progress-bar/Timeline.js +0 -134
  113. package/components/settings-menu-control/PlaybackRateControl.js +0 -147
  114. package/components/settings-menu-control/SafeAreaControl.js +0 -92
  115. package/components/settings-menu-control/SettingsMenu.js +0 -68
  116. package/components/settings-menu-control/SubtitleControl.js +0 -1
  117. package/components/time-controls/CurrentTimeDisplay.js +0 -53
  118. package/components/time-controls/DurationDisplay.js +0 -51
  119. package/components/time-controls/TimeDivider.js +0 -41
  120. package/components/volume-control/VolumeBar.js +0 -216
  121. package/components/volume-control/VolumeControl.js +0 -35
  122. package/components/volume-control/VolumeLevel.js +0 -78
  123. package/components/zoom-control/ZoomBar.js +0 -189
  124. package/components/zoom-control/ZoomLevel.js +0 -68
  125. package/reducers/index.js +0 -23
  126. package/reducers/operation.js +0 -36
  127. package/reducers/player.js +0 -222
  128. package/utils/browser.js +0 -29
  129. package/utils/dom.js +0 -104
  130. package/utils/fullscreen.js +0 -73
@@ -0,0 +1,69 @@
1
+ import { PropTypes } from 'prop-types';
2
+ import React from 'react';
3
+ import styled from 'styled-components';
4
+ import Menu from '../utils/Menu';
5
+ import { Icon } from '@desynova-digital/components';
6
+ import PlaybackRateControl from './PlayBackRateControl';
7
+
8
+ const propTypes = {
9
+ player: PropTypes.instanceOf(Object),
10
+ actions: PropTypes.instanceOf(Object),
11
+ style: PropTypes.instanceOf(Object)
12
+ };
13
+
14
+ const SettingsMenuContainer = styled.div`
15
+ width: 100%;
16
+ position: relative;
17
+ .settings-menu-tile {
18
+ background: transparent;
19
+ div {
20
+ padding: 15px;
21
+ cursor: pointer;
22
+ }
23
+ }
24
+ `;
25
+
26
+ const SafeAreaBlock = styled('div')`
27
+ display: flex;
28
+ background: transparent;
29
+ font-family: SFUIText-Medium;
30
+ font-size: 12px;
31
+ text-transform: uppercase;
32
+ justify-content: flex-start;
33
+ align-items: center;
34
+ &:hover {
35
+ background: rgba(0, 206, 198, 0.1);
36
+ }
37
+ p {
38
+ margin-left: 10px;
39
+ white-space: nowrap;
40
+ }
41
+ `;
42
+
43
+ export default function SettingsMenuButton({ style, SDBorderActive, actionClick, playbackRate }) {
44
+ const handleClick = () => {
45
+ actionClick({
46
+ action: 'handle_sd_border_change',
47
+ value: !SDBorderActive
48
+ });
49
+ };
50
+
51
+ return (
52
+ <Menu icon="settings" position="left" style={style}>
53
+ <SettingsMenuContainer style={style}>
54
+ <div className="settings-menu-tile">
55
+ <SafeAreaBlock onClick={handleClick}>
56
+ <Icon name="safe-area" width={20} height={20} color={SDBorderActive ? '#00cec6' : '#333333'} />
57
+ <p style={SDBorderActive ? { color: '#00cec6' } : { color: '#333333' }}>4:3 Safe Area</p>
58
+ </SafeAreaBlock>
59
+ </div>
60
+ <div className="settings-menu-tile">
61
+ <PlaybackRateControl actionClick={actionClick} playbackRate={playbackRate} />
62
+ </div>
63
+ </SettingsMenuContainer>
64
+ </Menu>
65
+ );
66
+ }
67
+
68
+ SettingsMenuButton.propTypes = propTypes;
69
+ SettingsMenuButton.displayName = 'SettingsMenuButton';
@@ -0,0 +1,274 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports["default"] = void 0;
8
+ var _propTypes = require("prop-types");
9
+ var _react = _interopRequireWildcard(require("react"));
10
+ var _reactDom = require("react-dom");
11
+ var _styledComponents = _interopRequireDefault(require("styled-components"));
12
+ var _colors = _interopRequireDefault(require("../utils/colors"));
13
+ var Dom = _interopRequireWildcard(require("../utils/dom"));
14
+ var _templateObject;
15
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
16
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
18
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
19
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
20
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
21
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
22
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
23
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
24
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
25
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
26
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
27
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
28
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
29
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
30
+ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
31
+ var propTypes = {
32
+ onMouseDown: _propTypes.PropTypes.func,
33
+ onMouseMove: _propTypes.PropTypes.func,
34
+ stepForward: _propTypes.PropTypes.func,
35
+ stepBack: _propTypes.PropTypes.func,
36
+ sliderActive: _propTypes.PropTypes.func,
37
+ sliderInactive: _propTypes.PropTypes.func,
38
+ onMouseUp: _propTypes.PropTypes.func,
39
+ onFocus: _propTypes.PropTypes.func,
40
+ onBlur: _propTypes.PropTypes.func,
41
+ onClick: _propTypes.PropTypes.func,
42
+ getPercent: _propTypes.PropTypes.func,
43
+ vertical: _propTypes.PropTypes.bool,
44
+ children: _propTypes.PropTypes.node,
45
+ label: _propTypes.PropTypes.string,
46
+ valuenow: _propTypes.PropTypes.string,
47
+ valuetext: _propTypes.PropTypes.string
48
+ };
49
+ var defaultProps = {
50
+ onMouseDown: null,
51
+ onMouseMove: null,
52
+ stepForward: null,
53
+ stepBack: null,
54
+ sliderActive: null,
55
+ sliderInactive: null,
56
+ onMouseUp: null,
57
+ onFocus: null,
58
+ onBlur: null,
59
+ onClick: null,
60
+ getPercent: null,
61
+ vertical: false,
62
+ children: null,
63
+ label: '',
64
+ valuenow: '',
65
+ valuetext: ''
66
+ };
67
+ var SliderBlock = _styledComponents["default"].div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n position: relative;\n z-index: 2;\n width: 100%;\n height: 100%;\n background: ", ";\n"])), _colors["default"].dark.base);
68
+ var Slider = /*#__PURE__*/function (_Component) {
69
+ _inherits(Slider, _Component);
70
+ var _super = _createSuper(Slider);
71
+ function Slider(props, context) {
72
+ var _this;
73
+ _classCallCheck(this, Slider);
74
+ _this = _super.call(this, props, context);
75
+ _this.handleMouseDown = _this.handleMouseDown.bind(_assertThisInitialized(_this));
76
+ _this.handleMouseMove = _this.handleMouseMove.bind(_assertThisInitialized(_this));
77
+ _this.handleMouseUp = _this.handleMouseUp.bind(_assertThisInitialized(_this));
78
+ _this.handleFocus = _this.handleFocus.bind(_assertThisInitialized(_this));
79
+ _this.handleBlur = _this.handleBlur.bind(_assertThisInitialized(_this));
80
+ _this.handleClick = _this.handleClick.bind(_assertThisInitialized(_this));
81
+ _this.handleKeyPress = _this.handleKeyPress.bind(_assertThisInitialized(_this));
82
+ _this.stepForward = _this.stepForward.bind(_assertThisInitialized(_this));
83
+ _this.stepBack = _this.stepBack.bind(_assertThisInitialized(_this));
84
+ _this.calculateDistance = _this.calculateDistance.bind(_assertThisInitialized(_this));
85
+ _this.getProgress = _this.getProgress.bind(_assertThisInitialized(_this));
86
+ _this.renderChildren = _this.renderChildren.bind(_assertThisInitialized(_this));
87
+ _this.state = {
88
+ // active: false,
89
+ };
90
+ return _this;
91
+ }
92
+ _createClass(Slider, [{
93
+ key: "getProgress",
94
+ value: function getProgress() {
95
+ var getPercent = this.props.getPercent;
96
+ if (!getPercent) {
97
+ return 0;
98
+ }
99
+ var progress = getPercent();
100
+
101
+ // Protect against no duration and other division issues
102
+ if (typeof progress !== 'number' || progress < 0 || progress === Infinity) {
103
+ progress = 0;
104
+ }
105
+ return progress;
106
+ }
107
+ }, {
108
+ key: "handleMouseDown",
109
+ value: function handleMouseDown(event) {
110
+ var _this$props = this.props,
111
+ onMouseDown = _this$props.onMouseDown,
112
+ sliderActive = _this$props.sliderActive;
113
+ /*
114
+ * event.preventDefault();
115
+ * event.stopPropagation();
116
+ */
117
+
118
+ document.addEventListener('mousemove', this.handleMouseMove, true);
119
+ document.addEventListener('mouseup', this.handleMouseUp, true);
120
+ document.addEventListener('touchmove', this.handleMouseMove, true);
121
+ document.addEventListener('touchend', this.handleMouseUp, true);
122
+ this.setState({
123
+ /*
124
+ * active: true,
125
+ * distance: 0
126
+ */
127
+ });
128
+ if (sliderActive) {
129
+ sliderActive(event);
130
+ }
131
+ this.handleMouseMove(event);
132
+ if (onMouseDown) {
133
+ onMouseDown(event);
134
+ }
135
+ }
136
+ }, {
137
+ key: "handleMouseMove",
138
+ value: function handleMouseMove(event) {
139
+ var onMouseMove = this.props.onMouseMove;
140
+ if (onMouseMove) {
141
+ onMouseMove(event);
142
+ }
143
+ }
144
+ }, {
145
+ key: "handleMouseUp",
146
+ value: function handleMouseUp(event) {
147
+ var _this$props2 = this.props,
148
+ onMouseUp = _this$props2.onMouseUp,
149
+ sliderInactive = _this$props2.sliderInactive;
150
+ document.removeEventListener('mousemove', this.handleMouseMove, true);
151
+ document.removeEventListener('mouseup', this.handleMouseUp, true);
152
+ document.removeEventListener('touchmove', this.handleMouseMove, true);
153
+ document.removeEventListener('touchend', this.handleMouseUp, true);
154
+ this.setState({
155
+ // active: false
156
+ });
157
+ if (sliderInactive) {
158
+ sliderInactive(event);
159
+ }
160
+ if (onMouseUp) {
161
+ onMouseUp(event);
162
+ }
163
+ }
164
+ }, {
165
+ key: "handleFocus",
166
+ value: function handleFocus(e) {
167
+ var onFocus = this.props.onFocus;
168
+ document.addEventListener('keydown', this.handleKeyPress, true);
169
+ if (onFocus) {
170
+ onFocus(e);
171
+ }
172
+ }
173
+ }, {
174
+ key: "handleBlur",
175
+ value: function handleBlur(e) {
176
+ var onBlur = this.props.onBlur;
177
+ document.removeEventListener('keydown', this.handleKeyPress, true);
178
+ if (onBlur) {
179
+ onBlur(e);
180
+ }
181
+ }
182
+ }, {
183
+ key: "handleClick",
184
+ value: function handleClick(event) {
185
+ var onClick = this.props.onClick;
186
+ event.preventDefault();
187
+ // event.stopPropagation();
188
+ if (onClick) {
189
+ onClick(event);
190
+ }
191
+ }
192
+ }, {
193
+ key: "handleKeyPress",
194
+ value: function handleKeyPress(event) {
195
+ if (event.which === 37 || event.which === 40) {
196
+ // Left and Down Arrows
197
+ event.preventDefault();
198
+ event.stopPropagation();
199
+ this.stepBack();
200
+ } else if (event.which === 38 || event.which === 39) {
201
+ // Up and Right Arrows
202
+ event.preventDefault();
203
+ event.stopPropagation();
204
+ this.stepForward();
205
+ }
206
+ }
207
+ }, {
208
+ key: "stepForward",
209
+ value: function stepForward() {
210
+ var stepForward = this.props.stepForward;
211
+ if (stepForward) {
212
+ stepForward();
213
+ }
214
+ }
215
+ }, {
216
+ key: "stepBack",
217
+ value: function stepBack() {
218
+ var stepBack = this.props.stepBack;
219
+ if (stepBack) {
220
+ stepBack();
221
+ }
222
+ }
223
+ }, {
224
+ key: "calculateDistance",
225
+ value: function calculateDistance(event) {
226
+ var node = (0, _reactDom.findDOMNode)(this);
227
+ var position = Dom.getPointerPosition(node, event);
228
+ var vertical = this.props.vertical;
229
+ if (vertical) {
230
+ return position.y;
231
+ }
232
+ return position.x;
233
+ }
234
+ }, {
235
+ key: "renderChildren",
236
+ value: function renderChildren() {
237
+ var progress = this.getProgress();
238
+ var percentage = "".concat((progress * 100).toFixed(2), "%");
239
+ var children = this.props.children;
240
+ return _react["default"].Children.map(children, function (child) {
241
+ return /*#__PURE__*/_react["default"].cloneElement(child, {
242
+ progress: progress,
243
+ percentage: percentage
244
+ });
245
+ });
246
+ }
247
+ }, {
248
+ key: "render",
249
+ value: function render() {
250
+ var _this$props3 = this.props,
251
+ label = _this$props3.label,
252
+ valuenow = _this$props3.valuenow,
253
+ valuetext = _this$props3.valuetext;
254
+ return /*#__PURE__*/_react["default"].createElement(SliderBlock, {
255
+ tabIndex: "0",
256
+ onMouseDown: this.handleMouseDown,
257
+ onTouchStart: this.handleMouseDown,
258
+ onFocus: this.handleFocus,
259
+ onBlur: this.handleBlur,
260
+ onClick: this.handleClick,
261
+ "aria-label": label || '',
262
+ "aria-valuenow": valuenow || '',
263
+ "aria-valuetext": valuetext || '',
264
+ "aria-valuemin": 0,
265
+ "aria-valuemax": 100
266
+ }, this.renderChildren());
267
+ }
268
+ }]);
269
+ return Slider;
270
+ }(_react.Component);
271
+ exports["default"] = Slider;
272
+ Slider.propTypes = propTypes;
273
+ Slider.defaultProps = defaultProps;
274
+ Slider.displayName = 'Slider';
@@ -0,0 +1,243 @@
1
+ import { PropTypes } from 'prop-types';
2
+ import React, { Component } from 'react';
3
+ import { findDOMNode } from 'react-dom';
4
+ import styled from 'styled-components';
5
+ import colors from '../utils/colors';
6
+ import * as Dom from '../utils/dom';
7
+
8
+ const propTypes = {
9
+ onMouseDown: PropTypes.func,
10
+ onMouseMove: PropTypes.func,
11
+ stepForward: PropTypes.func,
12
+ stepBack: PropTypes.func,
13
+ sliderActive: PropTypes.func,
14
+ sliderInactive: PropTypes.func,
15
+ onMouseUp: PropTypes.func,
16
+ onFocus: PropTypes.func,
17
+ onBlur: PropTypes.func,
18
+ onClick: PropTypes.func,
19
+ getPercent: PropTypes.func,
20
+ vertical: PropTypes.bool,
21
+ children: PropTypes.node,
22
+ label: PropTypes.string,
23
+ valuenow: PropTypes.string,
24
+ valuetext: PropTypes.string
25
+ };
26
+
27
+ const defaultProps = {
28
+ onMouseDown: null,
29
+ onMouseMove: null,
30
+ stepForward: null,
31
+ stepBack: null,
32
+ sliderActive: null,
33
+ sliderInactive: null,
34
+ onMouseUp: null,
35
+ onFocus: null,
36
+ onBlur: null,
37
+ onClick: null,
38
+ getPercent: null,
39
+ vertical: false,
40
+ children: null,
41
+ label: '',
42
+ valuenow: '',
43
+ valuetext: ''
44
+ };
45
+
46
+ const SliderBlock = styled.div`
47
+ position: relative;
48
+ z-index: 2;
49
+ width: 100%;
50
+ height: 100%;
51
+ background: ${colors.dark.base};
52
+ `;
53
+
54
+ export default class Slider extends Component {
55
+ constructor(props, context) {
56
+ super(props, context);
57
+
58
+ this.handleMouseDown = this.handleMouseDown.bind(this);
59
+ this.handleMouseMove = this.handleMouseMove.bind(this);
60
+ this.handleMouseUp = this.handleMouseUp.bind(this);
61
+ this.handleFocus = this.handleFocus.bind(this);
62
+ this.handleBlur = this.handleBlur.bind(this);
63
+ this.handleClick = this.handleClick.bind(this);
64
+ this.handleKeyPress = this.handleKeyPress.bind(this);
65
+ this.stepForward = this.stepForward.bind(this);
66
+ this.stepBack = this.stepBack.bind(this);
67
+ this.calculateDistance = this.calculateDistance.bind(this);
68
+ this.getProgress = this.getProgress.bind(this);
69
+ this.renderChildren = this.renderChildren.bind(this);
70
+
71
+ this.state = {
72
+ // active: false,
73
+ };
74
+ }
75
+
76
+ getProgress() {
77
+ const { getPercent } = this.props;
78
+ if (!getPercent) {
79
+ return 0;
80
+ }
81
+ let progress = getPercent();
82
+
83
+ // Protect against no duration and other division issues
84
+ if (typeof progress !== 'number' || progress < 0 || progress === Infinity) {
85
+ progress = 0;
86
+ }
87
+ return progress;
88
+ }
89
+
90
+ handleMouseDown(event) {
91
+ const { onMouseDown, sliderActive } = this.props;
92
+ /*
93
+ * event.preventDefault();
94
+ * event.stopPropagation();
95
+ */
96
+
97
+ document.addEventListener('mousemove', this.handleMouseMove, true);
98
+ document.addEventListener('mouseup', this.handleMouseUp, true);
99
+ document.addEventListener('touchmove', this.handleMouseMove, true);
100
+ document.addEventListener('touchend', this.handleMouseUp, true);
101
+
102
+ this.setState({
103
+ /*
104
+ * active: true,
105
+ * distance: 0
106
+ */
107
+ });
108
+
109
+ if (sliderActive) {
110
+ sliderActive(event);
111
+ }
112
+
113
+ this.handleMouseMove(event);
114
+
115
+ if (onMouseDown) {
116
+ onMouseDown(event);
117
+ }
118
+ }
119
+
120
+ handleMouseMove(event) {
121
+ const { onMouseMove } = this.props;
122
+
123
+ if (onMouseMove) {
124
+ onMouseMove(event);
125
+ }
126
+ }
127
+
128
+ handleMouseUp(event) {
129
+ const { onMouseUp, sliderInactive } = this.props;
130
+
131
+ document.removeEventListener('mousemove', this.handleMouseMove, true);
132
+ document.removeEventListener('mouseup', this.handleMouseUp, true);
133
+ document.removeEventListener('touchmove', this.handleMouseMove, true);
134
+ document.removeEventListener('touchend', this.handleMouseUp, true);
135
+
136
+ this.setState({
137
+ // active: false
138
+ });
139
+
140
+ if (sliderInactive) {
141
+ sliderInactive(event);
142
+ }
143
+
144
+ if (onMouseUp) {
145
+ onMouseUp(event);
146
+ }
147
+ }
148
+
149
+ handleFocus(e) {
150
+ const { onFocus } = this.props;
151
+ document.addEventListener('keydown', this.handleKeyPress, true);
152
+ if (onFocus) {
153
+ onFocus(e);
154
+ }
155
+ }
156
+
157
+ handleBlur(e) {
158
+ const { onBlur } = this.props;
159
+ document.removeEventListener('keydown', this.handleKeyPress, true);
160
+ if (onBlur) {
161
+ onBlur(e);
162
+ }
163
+ }
164
+
165
+ handleClick(event) {
166
+ const { onClick } = this.props;
167
+ event.preventDefault();
168
+ // event.stopPropagation();
169
+ if (onClick) {
170
+ onClick(event);
171
+ }
172
+ }
173
+
174
+ handleKeyPress(event) {
175
+ if (event.which === 37 || event.which === 40) {
176
+ // Left and Down Arrows
177
+ event.preventDefault();
178
+ event.stopPropagation();
179
+ this.stepBack();
180
+ } else if (event.which === 38 || event.which === 39) {
181
+ // Up and Right Arrows
182
+ event.preventDefault();
183
+ event.stopPropagation();
184
+ this.stepForward();
185
+ }
186
+ }
187
+
188
+ stepForward() {
189
+ const { stepForward } = this.props;
190
+ if (stepForward) {
191
+ stepForward();
192
+ }
193
+ }
194
+
195
+ stepBack() {
196
+ const { stepBack } = this.props;
197
+ if (stepBack) {
198
+ stepBack();
199
+ }
200
+ }
201
+
202
+ calculateDistance(event) {
203
+ const node = findDOMNode(this);
204
+ const position = Dom.getPointerPosition(node, event);
205
+ const { vertical } = this.props;
206
+ if (vertical) {
207
+ return position.y;
208
+ }
209
+ return position.x;
210
+ }
211
+
212
+ renderChildren() {
213
+ const progress = this.getProgress();
214
+ const percentage = `${(progress * 100).toFixed(2)}%`;
215
+ const { children } = this.props;
216
+ return React.Children.map(children, (child) => React.cloneElement(child, { progress, percentage }));
217
+ }
218
+
219
+ render() {
220
+ const { label, valuenow, valuetext } = this.props;
221
+
222
+ return (
223
+ <SliderBlock
224
+ tabIndex="0"
225
+ onMouseDown={this.handleMouseDown}
226
+ onTouchStart={this.handleMouseDown}
227
+ onFocus={this.handleFocus}
228
+ onBlur={this.handleBlur}
229
+ onClick={this.handleClick}
230
+ aria-label={label || ''}
231
+ aria-valuenow={valuenow || ''}
232
+ aria-valuetext={valuetext || ''}
233
+ aria-valuemin={0}
234
+ aria-valuemax={100}>
235
+ {this.renderChildren()}
236
+ </SliderBlock>
237
+ );
238
+ }
239
+ }
240
+
241
+ Slider.propTypes = propTypes;
242
+ Slider.defaultProps = defaultProps;
243
+ Slider.displayName = 'Slider';