@ldelia/react-media 0.4.2 → 0.4.3
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/package.json +45 -35
- package/.bitmap +0 -48
- package/.eslintcache +0 -1
- package/.prettierignore +0 -3
- package/.prettierrc +0 -7
- package/.storybook/main.js +0 -38
- package/.storybook/preview.js +0 -4
- package/config/env.js +0 -104
- package/config/getHttpsConfig.js +0 -66
- package/config/jest/babelTransform.js +0 -29
- package/config/jest/cssTransform.js +0 -14
- package/config/jest/fileTransform.js +0 -40
- package/config/modules.js +0 -134
- package/config/paths.js +0 -77
- package/config/webpack/persistentCache/createEnvironmentHash.js +0 -9
- package/config/webpack.config.js +0 -755
- package/config/webpackDevServer.config.js +0 -127
- package/scripts/build.js +0 -217
- package/scripts/start.js +0 -154
- package/scripts/test.js +0 -52
- package/src/components/__tests__/timeline/timeline.test.tsx +0 -26
- package/src/components/index.ts +0 -2
- package/src/components/reproduction-widget/README.md +0 -27
- package/src/components/reproduction-widget/ReproductionWidget.tsx +0 -68
- package/src/components/reproduction-widget/index.tsx +0 -1
- package/src/components/reproduction-widget/inner-players/PlayAlongInnerPlayer.tsx +0 -10
- package/src/components/reproduction-widget/inner-players/YouTubeInnerPlayer.tsx +0 -36
- package/src/components/reproduction-widget/models/Player/PlayAlongPlayer.ts +0 -129
- package/src/components/reproduction-widget/models/Player/PlayerEvents.ts +0 -4
- package/src/components/reproduction-widget/models/Player/YouTubePlayer.ts +0 -171
- package/src/components/reproduction-widget/models/Reproduction.ts +0 -272
- package/src/components/reproduction-widget/models/ReproductionBuilder.ts +0 -70
- package/src/components/timeline/README.md +0 -111
- package/src/components/timeline/RangeSelectorCanvas/RangeSelectorCanvas.tsx +0 -166
- package/src/components/timeline/Timeline.tsx +0 -139
- package/src/components/timeline/TimelineCanvas/TickTime.tsx +0 -45
- package/src/components/timeline/TimelineCanvas/TickTimeCollectionDisplay.tsx +0 -42
- package/src/components/timeline/TimelineCanvas/TimelineCanvas.tsx +0 -79
- package/src/components/timeline/TimelineCanvas/drawTimeBlocksOnCanvas.ts +0 -43
- package/src/components/timeline/TimelineValue/TimelineValue.tsx +0 -87
- package/src/components/timeline/ZoomContext/ZoomContext.ts +0 -10
- package/src/components/timeline/constants.ts +0 -13
- package/src/components/timeline/index.tsx +0 -1
- package/src/components/timeline/utils/utils.ts +0 -49
- package/src/index.ts +0 -1
- package/src/modules.d.ts +0 -1
- package/src/react-app-env.d.ts +0 -71
- package/src/react-docgen-types.d.ts +0 -37
- package/src/setupTests.ts +0 -5
- package/src/stories/Configure.mdx +0 -364
- package/src/stories/reproduction-widget.stories.tsx +0 -23
- package/src/stories/timeline.stories.custom.css +0 -29
- package/src/stories/timeline.stories.tsx +0 -66
- package/storybook-static/favicon.svg +0 -1
- package/storybook-static/index.html +0 -173
- package/storybook-static/index.json +0 -1
- package/storybook-static/nunito-sans-bold-italic.woff2 +0 -0
- package/storybook-static/nunito-sans-bold.woff2 +0 -0
- package/storybook-static/nunito-sans-italic.woff2 +0 -0
- package/storybook-static/nunito-sans-regular.woff2 +0 -0
- package/storybook-static/project.json +0 -1
- package/storybook-static/sb-addons/essentials-actions-3/manager-bundle.js +0 -3
- package/storybook-static/sb-addons/essentials-actions-3/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-static/sb-addons/essentials-backgrounds-4/manager-bundle.js +0 -12
- package/storybook-static/sb-addons/essentials-backgrounds-4/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-static/sb-addons/essentials-controls-2/manager-bundle.js +0 -412
- package/storybook-static/sb-addons/essentials-controls-2/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-static/sb-addons/essentials-measure-7/manager-bundle.js +0 -3
- package/storybook-static/sb-addons/essentials-measure-7/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-static/sb-addons/essentials-outline-8/manager-bundle.js +0 -3
- package/storybook-static/sb-addons/essentials-outline-8/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-static/sb-addons/essentials-toolbars-6/manager-bundle.js +0 -3
- package/storybook-static/sb-addons/essentials-toolbars-6/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-static/sb-addons/essentials-viewport-5/manager-bundle.js +0 -3
- package/storybook-static/sb-addons/essentials-viewport-5/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-static/sb-addons/links-1/manager-bundle.js +0 -3
- package/storybook-static/sb-addons/links-1/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-static/sb-addons/storybook-core-core-server-presets-0/common-manager-bundle.js +0 -3
- package/storybook-static/sb-addons/storybook-core-core-server-presets-0/common-manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-static/sb-common-assets/favicon.svg +0 -1
- package/storybook-static/sb-common-assets/nunito-sans-bold-italic.woff2 +0 -0
- package/storybook-static/sb-common-assets/nunito-sans-bold.woff2 +0 -0
- package/storybook-static/sb-common-assets/nunito-sans-italic.woff2 +0 -0
- package/storybook-static/sb-common-assets/nunito-sans-regular.woff2 +0 -0
- package/storybook-static/sb-manager/globals-module-info.js +0 -995
- package/storybook-static/sb-manager/globals-runtime.js +0 -53527
- package/storybook-static/sb-manager/globals.js +0 -48
- package/storybook-static/sb-manager/runtime.js +0 -11885
- package/storybook-static/sb-preview/globals.js +0 -33
- package/storybook-static/sb-preview/runtime.js +0 -9483
- package/tsconfig.json +0 -14
- /package/{src → dist}/components/__tests__/timeline/timeline.test.js +0 -0
- /package/{src → dist}/components/index.js +0 -0
- /package/{src → dist}/components/reproduction-widget/ReproductionWidget.js +0 -0
- /package/{src → dist}/components/reproduction-widget/index.js +0 -0
- /package/{src → dist}/components/reproduction-widget/inner-players/PlayAlongInnerPlayer.js +0 -0
- /package/{src → dist}/components/reproduction-widget/inner-players/YouTubeInnerPlayer.js +0 -0
- /package/{src → dist}/components/reproduction-widget/models/Player/PlayAlongPlayer.js +0 -0
- /package/{src → dist}/components/reproduction-widget/models/Player/PlayerEvents.js +0 -0
- /package/{src → dist}/components/reproduction-widget/models/Player/YouTubePlayer.js +0 -0
- /package/{src → dist}/components/reproduction-widget/models/Reproduction.js +0 -0
- /package/{src → dist}/components/reproduction-widget/models/ReproductionBuilder.js +0 -0
- /package/{src → dist}/components/timeline/RangeSelectorCanvas/RangeSelectorCanvas.js +0 -0
- /package/{src → dist}/components/timeline/Timeline.js +0 -0
- /package/{src → dist}/components/timeline/TimelineCanvas/TickTime.js +0 -0
- /package/{src → dist}/components/timeline/TimelineCanvas/TickTimeCollectionDisplay.js +0 -0
- /package/{src → dist}/components/timeline/TimelineCanvas/TimelineCanvas.js +0 -0
- /package/{src → dist}/components/timeline/TimelineCanvas/drawTimeBlocksOnCanvas.js +0 -0
- /package/{src → dist}/components/timeline/TimelineValue/TimelineValue.js +0 -0
- /package/{src → dist}/components/timeline/ZoomContext/ZoomContext.js +0 -0
- /package/{src → dist}/components/timeline/constants.js +0 -0
- /package/{src → dist}/components/timeline/index.js +0 -0
- /package/{src → dist}/components/timeline/utils/utils.js +0 -0
- /package/{src → dist}/index.js +0 -0
- /package/{src → dist}/setupTests.js +0 -0
- /package/{src → dist}/stories/reproduction-widget.stories.js +0 -0
- /package/{src → dist}/stories/timeline.stories.js +0 -0
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
# Timeline
|
|
2
|
-
|
|
3
|
-
<!-- STORY -->
|
|
4
|
-
|
|
5
|
-
<hr>
|
|
6
|
-
|
|
7
|
-
A component for displaying the duration of a media file (mp3, mp4, etc.) and the current reproduction position. It also allows selecting a range for reproduction looping purposes.
|
|
8
|
-
|
|
9
|
-
## Installation
|
|
10
|
-
|
|
11
|
-
### NPM
|
|
12
|
-
|
|
13
|
-
```
|
|
14
|
-
npm i @bit/ldelia.react-media.timeline
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
### YARN
|
|
18
|
-
|
|
19
|
-
```
|
|
20
|
-
yarn add @bit/ldelia.react-media.timeline
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
### BIT
|
|
24
|
-
|
|
25
|
-
```
|
|
26
|
-
bit import ldelia.react-media/timeline
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
## Import
|
|
30
|
-
|
|
31
|
-
```js
|
|
32
|
-
import Timeline from '@bit/ldelia.react-media.timeline';
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
## Usage
|
|
36
|
-
|
|
37
|
-
```jsx
|
|
38
|
-
<Timeline
|
|
39
|
-
duration={301}
|
|
40
|
-
value={15}
|
|
41
|
-
onChange={() => 'Do something'}
|
|
42
|
-
onRangeChange={() => 'Do something'}
|
|
43
|
-
/>
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
##### Required props
|
|
47
|
-
|
|
48
|
-
| Name | Type | Description |
|
|
49
|
-
| ---------- | -------- | --------------------------------- |
|
|
50
|
-
| `duration` | `number` | The media file duration |
|
|
51
|
-
| `value` | `number` | The current reproduction position |
|
|
52
|
-
|
|
53
|
-
##### Optional props
|
|
54
|
-
|
|
55
|
-
| Name | Type | Default | Description |
|
|
56
|
-
| --------------- | ---------- | ---------- | -------------------------------------------------- |
|
|
57
|
-
| `onChange` | `function` | `() => {}` | Fired when the user double-clicks on the timeline |
|
|
58
|
-
| `onRangeChange` | `function` | `() => {}` | Fired when the user select a range in the timeline |
|
|
59
|
-
| `selectedRange` | `array` | `[]` | The current selected range |
|
|
60
|
-
| `zoomLevel` | `number` | `0` | `The current timeline zoom level` |
|
|
61
|
-
|
|
62
|
-
## Customization
|
|
63
|
-
|
|
64
|
-
#### Timeline widget
|
|
65
|
-
|
|
66
|
-
```
|
|
67
|
-
const StyledTimeline = styled(Timeline)`
|
|
68
|
-
background-color: green;
|
|
69
|
-
`;
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
#### Value bar
|
|
73
|
-
|
|
74
|
-
```
|
|
75
|
-
const StyledTimeline = styled(Timeline)`
|
|
76
|
-
.media-timeline-value-line {
|
|
77
|
-
background-color: red;
|
|
78
|
-
width: 5px;
|
|
79
|
-
}
|
|
80
|
-
`;
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
#### Tick-time labels
|
|
84
|
-
|
|
85
|
-
```
|
|
86
|
-
const StyledTimeline = styled(Timeline)`
|
|
87
|
-
.media-timeline-tick-time {
|
|
88
|
-
color: red;
|
|
89
|
-
}
|
|
90
|
-
`;
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
#### Tick-time/Value bar container
|
|
94
|
-
|
|
95
|
-
```
|
|
96
|
-
const StyledTimeline = styled(Timeline)`
|
|
97
|
-
.media-timeline-value-line-canvas {
|
|
98
|
-
color: red;
|
|
99
|
-
}
|
|
100
|
-
`;
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
#### Range selector
|
|
104
|
-
|
|
105
|
-
```
|
|
106
|
-
const StyledTimeline = styled(Timeline)`
|
|
107
|
-
.media-timeline-range-selector-canvas {
|
|
108
|
-
color: red;
|
|
109
|
-
}
|
|
110
|
-
`;
|
|
111
|
-
```
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import React, { useContext, useEffect, useMemo, useRef } from 'react';
|
|
2
|
-
import styled from 'styled-components';
|
|
3
|
-
import { ZoomContext, ZoomContextType } from '../ZoomContext/ZoomContext';
|
|
4
|
-
import { pixelToSeconds, secondsToPixel } from '../utils/utils';
|
|
5
|
-
|
|
6
|
-
const OverlayCanvas = styled.canvas`
|
|
7
|
-
position: absolute;
|
|
8
|
-
top: 0;
|
|
9
|
-
left: 0;
|
|
10
|
-
width: 100%;
|
|
11
|
-
height: 100%;
|
|
12
|
-
color: cadetblue;
|
|
13
|
-
`;
|
|
14
|
-
|
|
15
|
-
export interface RangeSelectorCanvasProps {
|
|
16
|
-
selectedRange: number[];
|
|
17
|
-
onChange: (value: number) => void;
|
|
18
|
-
onRangeChange: (value: number[]) => void;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const RangeSelectorCanvas: React.FC<RangeSelectorCanvasProps> = ({
|
|
22
|
-
selectedRange,
|
|
23
|
-
onChange,
|
|
24
|
-
onRangeChange,
|
|
25
|
-
}) => {
|
|
26
|
-
const canvasRef = useRef(null);
|
|
27
|
-
const zoomContextValue: ZoomContextType = useContext(ZoomContext);
|
|
28
|
-
|
|
29
|
-
let isSelectingRange: boolean = false;
|
|
30
|
-
let selectedRangeInPixels: number[] = useMemo(() => [], []);
|
|
31
|
-
if (selectedRange.length === 2) {
|
|
32
|
-
selectedRangeInPixels = [
|
|
33
|
-
secondsToPixel(zoomContextValue, selectedRange[0]),
|
|
34
|
-
secondsToPixel(zoomContextValue, selectedRange[1]),
|
|
35
|
-
];
|
|
36
|
-
}
|
|
37
|
-
let lastValidSelectedRangeInPixels: number[] = [];
|
|
38
|
-
|
|
39
|
-
const getMousePointerPixelPosition = (e: { clientX: number }) => {
|
|
40
|
-
const canvas: HTMLCanvasElement = canvasRef.current!;
|
|
41
|
-
let rect = canvas.getBoundingClientRect();
|
|
42
|
-
return e.clientX - rect.left;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const drawRect = (pixelX0: number, pixelX1: number) => {
|
|
46
|
-
const canvas: HTMLCanvasElement = canvasRef.current!;
|
|
47
|
-
const context: CanvasRenderingContext2D = canvas.getContext('2d')!;
|
|
48
|
-
|
|
49
|
-
context.globalAlpha = 0.3;
|
|
50
|
-
context.fillStyle = window
|
|
51
|
-
.getComputedStyle(canvas)
|
|
52
|
-
.getPropertyValue('color');
|
|
53
|
-
context.fillRect(pixelX0, 0, pixelX1 - pixelX0, context.canvas.height);
|
|
54
|
-
context.globalAlpha = 1.0;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const onCanvasDoubleClick = (e: { clientX: number }) => {
|
|
58
|
-
const x0 = getMousePointerPixelPosition(e);
|
|
59
|
-
onChange(pixelToSeconds(zoomContextValue, x0));
|
|
60
|
-
selectedRangeInPixels = lastValidSelectedRangeInPixels;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const isPixelNearSelectedRange = (x0: number) => {
|
|
64
|
-
if (selectedRangeInPixels.length === 2) {
|
|
65
|
-
const diff = Math.min(
|
|
66
|
-
Math.abs(selectedRangeInPixels[0] - x0),
|
|
67
|
-
Math.abs(selectedRangeInPixels[1] - x0),
|
|
68
|
-
);
|
|
69
|
-
return diff <= zoomContextValue.pixelsInSecond / 2;
|
|
70
|
-
}
|
|
71
|
-
return false;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const onCanvasMouseDown = (e: { clientX: number }) => {
|
|
75
|
-
const mouseCurrentPosition = getMousePointerPixelPosition(e);
|
|
76
|
-
|
|
77
|
-
if (!isPixelNearSelectedRange(mouseCurrentPosition)) {
|
|
78
|
-
// Keep track of the first position of the new range.
|
|
79
|
-
selectedRangeInPixels = [mouseCurrentPosition, mouseCurrentPosition];
|
|
80
|
-
}
|
|
81
|
-
isSelectingRange = true;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const onCanvasMouseMove = (e: { clientX: number }) => {
|
|
85
|
-
const canvas: HTMLCanvasElement = canvasRef.current!;
|
|
86
|
-
const context = canvas.getContext('2d')!;
|
|
87
|
-
const mouseCurrentPosition = getMousePointerPixelPosition(e);
|
|
88
|
-
|
|
89
|
-
if (selectedRangeInPixels.length === 2) {
|
|
90
|
-
const diff = Math.min(
|
|
91
|
-
Math.abs(selectedRangeInPixels[0] - mouseCurrentPosition),
|
|
92
|
-
Math.abs(selectedRangeInPixels[1] - mouseCurrentPosition),
|
|
93
|
-
);
|
|
94
|
-
// Change the mouse's cursor if it's near a selected range.
|
|
95
|
-
canvas.style.cursor =
|
|
96
|
-
diff <= zoomContextValue.pixelsInSecond / 2 ? 'col-resize' : 'default';
|
|
97
|
-
|
|
98
|
-
if (!isSelectingRange) return;
|
|
99
|
-
|
|
100
|
-
if (mouseCurrentPosition < selectedRangeInPixels[0]) {
|
|
101
|
-
// The left side must be enlarged.
|
|
102
|
-
selectedRangeInPixels[0] = mouseCurrentPosition;
|
|
103
|
-
} else if (mouseCurrentPosition > selectedRangeInPixels[1]) {
|
|
104
|
-
// The right side must be enlarged.
|
|
105
|
-
selectedRangeInPixels[1] = mouseCurrentPosition;
|
|
106
|
-
} else {
|
|
107
|
-
const diffX0 = mouseCurrentPosition - selectedRangeInPixels[0];
|
|
108
|
-
const diffX1 = selectedRangeInPixels[1] - mouseCurrentPosition;
|
|
109
|
-
if (diffX0 < diffX1) {
|
|
110
|
-
// The left side must be shrunk.
|
|
111
|
-
selectedRangeInPixels[0] = mouseCurrentPosition;
|
|
112
|
-
} else {
|
|
113
|
-
// The right side must be shrunk.
|
|
114
|
-
selectedRangeInPixels[1] = mouseCurrentPosition;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
118
|
-
drawRect(selectedRangeInPixels[0], selectedRangeInPixels[1]);
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
const onCanvasMouseUp = (e: { clientX: number }) => {
|
|
123
|
-
if (selectedRangeInPixels.length !== 2) return;
|
|
124
|
-
|
|
125
|
-
isSelectingRange = false;
|
|
126
|
-
const mouseCurrentPosition = getMousePointerPixelPosition(e);
|
|
127
|
-
const pixelRange = [
|
|
128
|
-
Math.min(selectedRangeInPixels[0], mouseCurrentPosition),
|
|
129
|
-
Math.max(selectedRangeInPixels[1], mouseCurrentPosition),
|
|
130
|
-
];
|
|
131
|
-
|
|
132
|
-
if (pixelRange[1] - pixelRange[0] <= 1) {
|
|
133
|
-
// It was just a click
|
|
134
|
-
selectedRangeInPixels = lastValidSelectedRangeInPixels;
|
|
135
|
-
} else {
|
|
136
|
-
lastValidSelectedRangeInPixels = pixelRange;
|
|
137
|
-
onRangeChange([
|
|
138
|
-
pixelToSeconds(zoomContextValue, pixelRange[0]),
|
|
139
|
-
pixelToSeconds(zoomContextValue, pixelRange[1]),
|
|
140
|
-
]);
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
useEffect(() => {
|
|
145
|
-
const canvas: HTMLCanvasElement = canvasRef.current!;
|
|
146
|
-
|
|
147
|
-
// https://stackoverflow.com/questions/8696631/canvas-drawings-like-lines-are-blurry
|
|
148
|
-
canvas.width = canvas.offsetWidth;
|
|
149
|
-
canvas.height = canvas.offsetHeight;
|
|
150
|
-
|
|
151
|
-
if (selectedRangeInPixels.length === 0) return;
|
|
152
|
-
drawRect(selectedRangeInPixels[0], selectedRangeInPixels[1]);
|
|
153
|
-
}, [selectedRangeInPixels]);
|
|
154
|
-
|
|
155
|
-
return (
|
|
156
|
-
<OverlayCanvas
|
|
157
|
-
ref={canvasRef}
|
|
158
|
-
onDoubleClick={onCanvasDoubleClick}
|
|
159
|
-
onMouseDown={onCanvasMouseDown}
|
|
160
|
-
onMouseMove={onCanvasMouseMove}
|
|
161
|
-
onMouseUp={onCanvasMouseUp}
|
|
162
|
-
className={'media-timeline-range-selector-canvas'}
|
|
163
|
-
/>
|
|
164
|
-
);
|
|
165
|
-
};
|
|
166
|
-
export default React.memo(RangeSelectorCanvas);
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
-
import TimelineCanvas from './TimelineCanvas/TimelineCanvas';
|
|
3
|
-
import RangeSelectorCanvas from './RangeSelectorCanvas/RangeSelectorCanvas';
|
|
4
|
-
import { zoomLevelConfigurations } from './constants';
|
|
5
|
-
import styled from 'styled-components';
|
|
6
|
-
import { TimelineValue } from './TimelineValue/TimelineValue';
|
|
7
|
-
import { ZoomContext, ZoomContextType } from './ZoomContext/ZoomContext';
|
|
8
|
-
import {
|
|
9
|
-
getBlockOffsetForZoomLevel,
|
|
10
|
-
getTimelineWrapperWidth,
|
|
11
|
-
numberToPxString,
|
|
12
|
-
} from './utils/utils';
|
|
13
|
-
|
|
14
|
-
const TimelineContainer = styled.div`
|
|
15
|
-
background-color: #f0f0f0;
|
|
16
|
-
border: 1px solid #c9c9c9;
|
|
17
|
-
height: 80px;
|
|
18
|
-
width: 100%;
|
|
19
|
-
max-width: 100%;
|
|
20
|
-
overflow-x: auto;
|
|
21
|
-
position: relative;
|
|
22
|
-
display: flex;
|
|
23
|
-
`;
|
|
24
|
-
const TimelineWrapper = styled.div`
|
|
25
|
-
position: absolute;
|
|
26
|
-
height: 100%;
|
|
27
|
-
display: flex;
|
|
28
|
-
flex-direction: row;
|
|
29
|
-
align-items: center;
|
|
30
|
-
overflow: hidden;
|
|
31
|
-
`;
|
|
32
|
-
|
|
33
|
-
export interface TimelineProps {
|
|
34
|
-
duration: number; // duration in seconds
|
|
35
|
-
value: number; // value in seconds
|
|
36
|
-
zoomLevel?: number; //0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
37
|
-
className?: string;
|
|
38
|
-
selectedRange?: number[];
|
|
39
|
-
withTimeBlocks?: boolean;
|
|
40
|
-
onChange?: (value: number) => void;
|
|
41
|
-
onRangeChange?: (value: number[]) => void;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export const Timeline: React.FC<TimelineProps> = ({
|
|
45
|
-
duration,
|
|
46
|
-
value,
|
|
47
|
-
zoomLevel = 0,
|
|
48
|
-
selectedRange = [],
|
|
49
|
-
withTimeBlocks = true,
|
|
50
|
-
onChange = () => {},
|
|
51
|
-
onRangeChange = () => {},
|
|
52
|
-
className = '',
|
|
53
|
-
}) => {
|
|
54
|
-
const timeLineContainerRef = useRef<HTMLDivElement>(null);
|
|
55
|
-
const canvasRef = useRef(null);
|
|
56
|
-
|
|
57
|
-
const [zoomContextValue, setZoomContextValue] = useState<ZoomContextType>({
|
|
58
|
-
blockOffset: 0,
|
|
59
|
-
pixelsInSecond: 0,
|
|
60
|
-
timelineWrapperWidth: 0,
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
let zoomLevelValue = zoomLevel ? zoomLevel : 0;
|
|
64
|
-
if (zoomLevelValue < 0 || zoomLevelValue >= zoomLevelConfigurations.length) {
|
|
65
|
-
console.warn('Invalid value for property zoomLevel.');
|
|
66
|
-
zoomLevelValue = 0;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (value < 0 || value > duration) {
|
|
70
|
-
console.warn('Invalid value.');
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (!(selectedRange.length === 0 || selectedRange.length === 2)) {
|
|
74
|
-
selectedRange = [];
|
|
75
|
-
console.warn('The selected range must contain only two values.');
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (
|
|
79
|
-
selectedRange.length === 2 &&
|
|
80
|
-
!(
|
|
81
|
-
0 <= selectedRange[0] &&
|
|
82
|
-
selectedRange[0] < selectedRange[1] &&
|
|
83
|
-
selectedRange[1] <= duration
|
|
84
|
-
)
|
|
85
|
-
) {
|
|
86
|
-
selectedRange = [];
|
|
87
|
-
console.warn('The selected range is inconsistent.');
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
useEffect(() => {
|
|
91
|
-
if (!timeLineContainerRef.current) return;
|
|
92
|
-
|
|
93
|
-
const timelineWrapperWidth = getTimelineWrapperWidth(
|
|
94
|
-
timeLineContainerRef.current.offsetWidth,
|
|
95
|
-
zoomLevelValue,
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
setZoomContextValue({
|
|
99
|
-
blockOffset: getBlockOffsetForZoomLevel(
|
|
100
|
-
zoomLevelValue,
|
|
101
|
-
duration,
|
|
102
|
-
timelineWrapperWidth,
|
|
103
|
-
),
|
|
104
|
-
pixelsInSecond: timelineWrapperWidth / duration,
|
|
105
|
-
timelineWrapperWidth: timelineWrapperWidth,
|
|
106
|
-
});
|
|
107
|
-
}, [timeLineContainerRef.current, zoomLevelValue, duration]);
|
|
108
|
-
|
|
109
|
-
useEffect(() => {
|
|
110
|
-
const timeLineWrapper: HTMLElement = timeLineContainerRef.current!;
|
|
111
|
-
const scrollPosition: number =
|
|
112
|
-
value * zoomContextValue.pixelsInSecond - 300;
|
|
113
|
-
timeLineWrapper.scrollLeft = Math.max(0, scrollPosition);
|
|
114
|
-
}, [duration, value, zoomContextValue]);
|
|
115
|
-
|
|
116
|
-
return (
|
|
117
|
-
<TimelineContainer ref={timeLineContainerRef} className={className}>
|
|
118
|
-
<TimelineWrapper
|
|
119
|
-
style={{
|
|
120
|
-
width: numberToPxString(zoomContextValue.timelineWrapperWidth),
|
|
121
|
-
}}
|
|
122
|
-
>
|
|
123
|
-
<ZoomContext.Provider value={zoomContextValue}>
|
|
124
|
-
<TimelineCanvas
|
|
125
|
-
ref={canvasRef}
|
|
126
|
-
duration={duration}
|
|
127
|
-
withTimeBlocks={withTimeBlocks}
|
|
128
|
-
/>
|
|
129
|
-
<TimelineValue value={value} canvasRef={canvasRef} />
|
|
130
|
-
<RangeSelectorCanvas
|
|
131
|
-
selectedRange={selectedRange}
|
|
132
|
-
onChange={onChange}
|
|
133
|
-
onRangeChange={onRangeChange}
|
|
134
|
-
/>
|
|
135
|
-
</ZoomContext.Provider>
|
|
136
|
-
</TimelineWrapper>
|
|
137
|
-
</TimelineContainer>
|
|
138
|
-
);
|
|
139
|
-
};
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import styled from 'styled-components';
|
|
3
|
-
|
|
4
|
-
export type Props = {
|
|
5
|
-
start: number;
|
|
6
|
-
leftPosition: string;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
interface TickTimeContainerProps {
|
|
10
|
-
left: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const TickTimeContainer = styled.span.attrs<TickTimeContainerProps>(
|
|
14
|
-
(props) => ({
|
|
15
|
-
style: {
|
|
16
|
-
left: props.left,
|
|
17
|
-
},
|
|
18
|
-
}),
|
|
19
|
-
)<TickTimeContainerProps>`
|
|
20
|
-
background: transparent;
|
|
21
|
-
position: absolute;
|
|
22
|
-
padding-left: 8px;
|
|
23
|
-
color: #646464;
|
|
24
|
-
user-select: none;
|
|
25
|
-
min-width: 20px;
|
|
26
|
-
max-width: 20px;
|
|
27
|
-
align-self: flex-end;
|
|
28
|
-
`;
|
|
29
|
-
|
|
30
|
-
const TickTime: React.FC<Props> = ({ start, leftPosition }) => {
|
|
31
|
-
const minutes = Math.floor(start / 60);
|
|
32
|
-
let seconds = start - minutes * 60;
|
|
33
|
-
let secondsFormatted: string =
|
|
34
|
-
seconds < 10 ? '0' + seconds : seconds.toString();
|
|
35
|
-
return (
|
|
36
|
-
<TickTimeContainer
|
|
37
|
-
left={leftPosition}
|
|
38
|
-
className={'media-timeline-tick-time'}
|
|
39
|
-
>
|
|
40
|
-
{minutes}:{secondsFormatted}
|
|
41
|
-
</TickTimeContainer>
|
|
42
|
-
);
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export default TickTime;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import styled from 'styled-components';
|
|
3
|
-
import TickTime from './TickTime';
|
|
4
|
-
import { ZoomContext } from '../ZoomContext/ZoomContext';
|
|
5
|
-
|
|
6
|
-
const TickTimeCollectionDisplayContainer = styled.div`
|
|
7
|
-
position: absolute;
|
|
8
|
-
display: flex;
|
|
9
|
-
align-self: flex-end;
|
|
10
|
-
height: 100%;
|
|
11
|
-
`;
|
|
12
|
-
|
|
13
|
-
export interface TickTimeCollectionDisplayProps {
|
|
14
|
-
tickTimes: number[];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const TickTimeCollectionDisplay: React.FC<TickTimeCollectionDisplayProps> = ({
|
|
18
|
-
tickTimes = [],
|
|
19
|
-
}) => {
|
|
20
|
-
return (
|
|
21
|
-
<ZoomContext.Consumer>
|
|
22
|
-
{(value) => {
|
|
23
|
-
return (
|
|
24
|
-
<TickTimeCollectionDisplayContainer>
|
|
25
|
-
{tickTimes.map((tickTimeValue, index) => {
|
|
26
|
-
const leftPosition: string =
|
|
27
|
-
tickTimeValue * value.pixelsInSecond + 'px';
|
|
28
|
-
return (
|
|
29
|
-
<TickTime
|
|
30
|
-
key={index}
|
|
31
|
-
start={tickTimeValue}
|
|
32
|
-
leftPosition={leftPosition}
|
|
33
|
-
/>
|
|
34
|
-
);
|
|
35
|
-
})}
|
|
36
|
-
</TickTimeCollectionDisplayContainer>
|
|
37
|
-
);
|
|
38
|
-
}}
|
|
39
|
-
</ZoomContext.Consumer>
|
|
40
|
-
);
|
|
41
|
-
};
|
|
42
|
-
export default TickTimeCollectionDisplay;
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
forwardRef,
|
|
3
|
-
useContext,
|
|
4
|
-
useEffect,
|
|
5
|
-
useImperativeHandle,
|
|
6
|
-
useRef,
|
|
7
|
-
} from 'react';
|
|
8
|
-
import styled from 'styled-components';
|
|
9
|
-
import { ZoomContext, ZoomContextType } from '../ZoomContext/ZoomContext';
|
|
10
|
-
import TickTimeCollectionDisplay from './TickTimeCollectionDisplay';
|
|
11
|
-
import { drawTimeBlocksOnCanvas } from './drawTimeBlocksOnCanvas';
|
|
12
|
-
|
|
13
|
-
const OverlayCanvas = styled.canvas`
|
|
14
|
-
position: absolute;
|
|
15
|
-
top: 0;
|
|
16
|
-
left: 0;
|
|
17
|
-
width: 100%;
|
|
18
|
-
height: 100%;
|
|
19
|
-
color: #c9c9c9;
|
|
20
|
-
`;
|
|
21
|
-
|
|
22
|
-
export interface VaLueLineCanvasProps {
|
|
23
|
-
duration: number;
|
|
24
|
-
withTimeBlocks: boolean;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const TimelineCanvas = forwardRef<HTMLCanvasElement, VaLueLineCanvasProps>(
|
|
28
|
-
({ duration, withTimeBlocks }, ref) => {
|
|
29
|
-
const internalCanvasRef = useRef<HTMLCanvasElement>(null);
|
|
30
|
-
|
|
31
|
-
const zoomContextValue: ZoomContextType = useContext(ZoomContext);
|
|
32
|
-
|
|
33
|
-
const blockStartingTimes = (() => {
|
|
34
|
-
if (!withTimeBlocks || !zoomContextValue.blockOffset) return [];
|
|
35
|
-
|
|
36
|
-
let blockStartingTimes = [0];
|
|
37
|
-
let secondsToCover = duration;
|
|
38
|
-
while (secondsToCover > 0) {
|
|
39
|
-
blockStartingTimes.push(
|
|
40
|
-
blockStartingTimes[blockStartingTimes.length - 1] +
|
|
41
|
-
zoomContextValue.blockOffset,
|
|
42
|
-
);
|
|
43
|
-
secondsToCover = secondsToCover - zoomContextValue.blockOffset;
|
|
44
|
-
}
|
|
45
|
-
blockStartingTimes.splice(-1);
|
|
46
|
-
return blockStartingTimes;
|
|
47
|
-
})();
|
|
48
|
-
|
|
49
|
-
// Pass the internal ref's current value directly to the forwarded ref
|
|
50
|
-
useImperativeHandle(
|
|
51
|
-
ref,
|
|
52
|
-
() => internalCanvasRef.current as HTMLCanvasElement,
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
useEffect(() => {
|
|
56
|
-
const canvas: HTMLCanvasElement = internalCanvasRef.current!;
|
|
57
|
-
|
|
58
|
-
// https://stackoverflow.com/questions/8696631/canvas-drawings-like-lines-are-blurry
|
|
59
|
-
canvas.width = canvas.offsetWidth;
|
|
60
|
-
canvas.height = canvas.offsetHeight;
|
|
61
|
-
|
|
62
|
-
if (withTimeBlocks)
|
|
63
|
-
drawTimeBlocksOnCanvas(canvas, blockStartingTimes, zoomContextValue);
|
|
64
|
-
}, [blockStartingTimes, withTimeBlocks, zoomContextValue]);
|
|
65
|
-
|
|
66
|
-
return (
|
|
67
|
-
<>
|
|
68
|
-
<OverlayCanvas
|
|
69
|
-
ref={internalCanvasRef}
|
|
70
|
-
className={'media-timeline-value-line-canvas'}
|
|
71
|
-
/>
|
|
72
|
-
{withTimeBlocks && (
|
|
73
|
-
<TickTimeCollectionDisplay tickTimes={blockStartingTimes} />
|
|
74
|
-
)}
|
|
75
|
-
</>
|
|
76
|
-
);
|
|
77
|
-
},
|
|
78
|
-
);
|
|
79
|
-
export default TimelineCanvas;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { secondsToPixel } from '../utils/utils';
|
|
2
|
-
import { ZoomContextType } from '../ZoomContext/ZoomContext';
|
|
3
|
-
|
|
4
|
-
export const drawTimeBlocksOnCanvas = (
|
|
5
|
-
canvas: HTMLCanvasElement,
|
|
6
|
-
blockStartingTimes: number[],
|
|
7
|
-
zoomContextValue: ZoomContextType,
|
|
8
|
-
): void => {
|
|
9
|
-
const blockHeight = 20;
|
|
10
|
-
const context: CanvasRenderingContext2D = canvas.getContext('2d')!;
|
|
11
|
-
|
|
12
|
-
// draw top line
|
|
13
|
-
context.beginPath();
|
|
14
|
-
context.moveTo(0, canvas.height - blockHeight);
|
|
15
|
-
context.lineTo(
|
|
16
|
-
zoomContextValue.timelineWrapperWidth,
|
|
17
|
-
canvas.height - blockHeight,
|
|
18
|
-
);
|
|
19
|
-
context.strokeStyle = window
|
|
20
|
-
.getComputedStyle(canvas)
|
|
21
|
-
.getPropertyValue('color');
|
|
22
|
-
context.stroke();
|
|
23
|
-
|
|
24
|
-
for (const blockStartingTime of blockStartingTimes) {
|
|
25
|
-
const x0Pixel = secondsToPixel(zoomContextValue, blockStartingTime);
|
|
26
|
-
const x1Pixel = secondsToPixel(
|
|
27
|
-
zoomContextValue,
|
|
28
|
-
blockStartingTime + zoomContextValue.blockOffset,
|
|
29
|
-
);
|
|
30
|
-
context.beginPath();
|
|
31
|
-
// draw left line
|
|
32
|
-
context.moveTo(x0Pixel, canvas.height);
|
|
33
|
-
context.lineTo(x0Pixel, canvas.height - blockHeight);
|
|
34
|
-
// draw right line
|
|
35
|
-
context.moveTo(x1Pixel, canvas.height);
|
|
36
|
-
context.lineTo(x1Pixel, canvas.height - blockHeight);
|
|
37
|
-
|
|
38
|
-
context.strokeStyle = window
|
|
39
|
-
.getComputedStyle(canvas)
|
|
40
|
-
.getPropertyValue('color');
|
|
41
|
-
context.stroke();
|
|
42
|
-
}
|
|
43
|
-
};
|