@ldelia/react-media 0.4.1 → 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.
Files changed (149) hide show
  1. package/dist/components/__tests__/timeline/timeline.test.js +5 -10
  2. package/dist/components/index.js +2 -17
  3. package/dist/components/timeline/RangeSelectorCanvas/RangeSelectorCanvas.js +16 -44
  4. package/dist/components/timeline/Timeline.js +26 -56
  5. package/dist/components/timeline/TimelineCanvas/TickTime.js +5 -10
  6. package/dist/components/timeline/TimelineCanvas/TickTimeCollectionDisplay.js +9 -14
  7. package/dist/components/timeline/TimelineCanvas/TimelineCanvas.js +16 -44
  8. package/dist/components/timeline/TimelineCanvas/drawTimeBlocksOnCanvas.js +4 -8
  9. package/dist/components/timeline/TimelineValue/TimelineValue.js +24 -54
  10. package/dist/components/timeline/ZoomContext/ZoomContext.js +2 -8
  11. package/dist/components/timeline/constants.js +1 -4
  12. package/dist/components/timeline/index.js +1 -17
  13. package/dist/components/timeline/utils/utils.js +6 -15
  14. package/dist/index.js +1 -17
  15. package/dist/setupTests.js +1 -3
  16. package/dist/stories/timeline.stories.js +18 -24
  17. package/package.json +45 -35
  18. package/.bitmap +0 -48
  19. package/.eslintcache +0 -1
  20. package/.prettierignore +0 -3
  21. package/.prettierrc +0 -7
  22. package/.storybook/main.js +0 -38
  23. package/.storybook/preview.js +0 -4
  24. package/config/env.js +0 -104
  25. package/config/getHttpsConfig.js +0 -66
  26. package/config/jest/babelTransform.js +0 -29
  27. package/config/jest/cssTransform.js +0 -14
  28. package/config/jest/fileTransform.js +0 -40
  29. package/config/modules.js +0 -134
  30. package/config/paths.js +0 -77
  31. package/config/webpack/persistentCache/createEnvironmentHash.js +0 -9
  32. package/config/webpack.config.js +0 -755
  33. package/config/webpackDevServer.config.js +0 -127
  34. package/dist/components/__tests__/timeline/timeline.test.d.ts +0 -1
  35. package/dist/components/index.d.ts +0 -1
  36. package/dist/components/timeline/RangeSelectorCanvas/RangeSelectorCanvas.d.ts +0 -8
  37. package/dist/components/timeline/Timeline.d.ts +0 -12
  38. package/dist/components/timeline/TimelineCanvas/TickTime.d.ts +0 -7
  39. package/dist/components/timeline/TimelineCanvas/TickTimeCollectionDisplay.d.ts +0 -6
  40. package/dist/components/timeline/TimelineCanvas/TimelineCanvas.d.ts +0 -7
  41. package/dist/components/timeline/TimelineCanvas/drawTimeBlocksOnCanvas.d.ts +0 -2
  42. package/dist/components/timeline/TimelineValue/TimelineValue.d.ts +0 -7
  43. package/dist/components/timeline/ZoomContext/ZoomContext.d.ts +0 -7
  44. package/dist/components/timeline/constants.d.ts +0 -1
  45. package/dist/components/timeline/index.d.ts +0 -1
  46. package/dist/components/timeline/utils/utils.d.ts +0 -7
  47. package/dist/index.d.ts +0 -1
  48. package/dist/setupTests.d.ts +0 -1
  49. package/dist/stories/timeline.stories.d.ts +0 -9
  50. package/scripts/build.js +0 -217
  51. package/scripts/start.js +0 -154
  52. package/scripts/test.js +0 -52
  53. package/src/components/__tests__/timeline/timeline.test.js +0 -22
  54. package/src/components/__tests__/timeline/timeline.test.tsx +0 -26
  55. package/src/components/index.js +0 -2
  56. package/src/components/index.ts +0 -2
  57. package/src/components/reproduction-widget/README.md +0 -27
  58. package/src/components/reproduction-widget/ReproductionWidget.tsx +0 -68
  59. package/src/components/reproduction-widget/index.tsx +0 -1
  60. package/src/components/reproduction-widget/inner-players/PlayAlongInnerPlayer.tsx +0 -10
  61. package/src/components/reproduction-widget/inner-players/YouTubeInnerPlayer.tsx +0 -36
  62. package/src/components/reproduction-widget/models/Player/PlayAlongPlayer.ts +0 -129
  63. package/src/components/reproduction-widget/models/Player/PlayerEvents.ts +0 -4
  64. package/src/components/reproduction-widget/models/Player/YouTubePlayer.ts +0 -171
  65. package/src/components/reproduction-widget/models/Reproduction.ts +0 -272
  66. package/src/components/reproduction-widget/models/ReproductionBuilder.ts +0 -70
  67. package/src/components/timeline/README.md +0 -111
  68. package/src/components/timeline/RangeSelectorCanvas/RangeSelectorCanvas.js +0 -127
  69. package/src/components/timeline/RangeSelectorCanvas/RangeSelectorCanvas.tsx +0 -166
  70. package/src/components/timeline/Timeline.js +0 -77
  71. package/src/components/timeline/Timeline.tsx +0 -139
  72. package/src/components/timeline/TimelineCanvas/TickTime.js +0 -26
  73. package/src/components/timeline/TimelineCanvas/TickTime.tsx +0 -45
  74. package/src/components/timeline/TimelineCanvas/TickTimeCollectionDisplay.js +0 -19
  75. package/src/components/timeline/TimelineCanvas/TickTimeCollectionDisplay.tsx +0 -42
  76. package/src/components/timeline/TimelineCanvas/TimelineCanvas.js +0 -44
  77. package/src/components/timeline/TimelineCanvas/TimelineCanvas.tsx +0 -79
  78. package/src/components/timeline/TimelineCanvas/drawTimeBlocksOnCanvas.js +0 -28
  79. package/src/components/timeline/TimelineCanvas/drawTimeBlocksOnCanvas.ts +0 -43
  80. package/src/components/timeline/TimelineValue/TimelineValue.js +0 -50
  81. package/src/components/timeline/TimelineValue/TimelineValue.tsx +0 -87
  82. package/src/components/timeline/ZoomContext/ZoomContext.js +0 -2
  83. package/src/components/timeline/ZoomContext/ZoomContext.ts +0 -10
  84. package/src/components/timeline/constants.js +0 -13
  85. package/src/components/timeline/constants.ts +0 -13
  86. package/src/components/timeline/index.js +0 -1
  87. package/src/components/timeline/index.tsx +0 -1
  88. package/src/components/timeline/utils/utils.js +0 -28
  89. package/src/components/timeline/utils/utils.ts +0 -49
  90. package/src/index.js +0 -1
  91. package/src/index.ts +0 -1
  92. package/src/modules.d.ts +0 -1
  93. package/src/react-app-env.d.ts +0 -71
  94. package/src/react-docgen-types.d.ts +0 -37
  95. package/src/setupTests.js +0 -5
  96. package/src/setupTests.ts +0 -5
  97. package/src/stories/Configure.mdx +0 -364
  98. package/src/stories/reproduction-widget.stories.tsx +0 -23
  99. package/src/stories/timeline.stories.custom.css +0 -29
  100. package/src/stories/timeline.stories.js +0 -54
  101. package/src/stories/timeline.stories.tsx +0 -66
  102. package/storybook-static/favicon.svg +0 -1
  103. package/storybook-static/index.html +0 -173
  104. package/storybook-static/index.json +0 -1
  105. package/storybook-static/nunito-sans-bold-italic.woff2 +0 -0
  106. package/storybook-static/nunito-sans-bold.woff2 +0 -0
  107. package/storybook-static/nunito-sans-italic.woff2 +0 -0
  108. package/storybook-static/nunito-sans-regular.woff2 +0 -0
  109. package/storybook-static/project.json +0 -1
  110. package/storybook-static/sb-addons/essentials-actions-3/manager-bundle.js +0 -3
  111. package/storybook-static/sb-addons/essentials-actions-3/manager-bundle.js.LEGAL.txt +0 -0
  112. package/storybook-static/sb-addons/essentials-backgrounds-4/manager-bundle.js +0 -12
  113. package/storybook-static/sb-addons/essentials-backgrounds-4/manager-bundle.js.LEGAL.txt +0 -0
  114. package/storybook-static/sb-addons/essentials-controls-2/manager-bundle.js +0 -412
  115. package/storybook-static/sb-addons/essentials-controls-2/manager-bundle.js.LEGAL.txt +0 -0
  116. package/storybook-static/sb-addons/essentials-measure-7/manager-bundle.js +0 -3
  117. package/storybook-static/sb-addons/essentials-measure-7/manager-bundle.js.LEGAL.txt +0 -0
  118. package/storybook-static/sb-addons/essentials-outline-8/manager-bundle.js +0 -3
  119. package/storybook-static/sb-addons/essentials-outline-8/manager-bundle.js.LEGAL.txt +0 -0
  120. package/storybook-static/sb-addons/essentials-toolbars-6/manager-bundle.js +0 -3
  121. package/storybook-static/sb-addons/essentials-toolbars-6/manager-bundle.js.LEGAL.txt +0 -0
  122. package/storybook-static/sb-addons/essentials-viewport-5/manager-bundle.js +0 -3
  123. package/storybook-static/sb-addons/essentials-viewport-5/manager-bundle.js.LEGAL.txt +0 -0
  124. package/storybook-static/sb-addons/links-1/manager-bundle.js +0 -3
  125. package/storybook-static/sb-addons/links-1/manager-bundle.js.LEGAL.txt +0 -0
  126. package/storybook-static/sb-addons/storybook-core-core-server-presets-0/common-manager-bundle.js +0 -3
  127. package/storybook-static/sb-addons/storybook-core-core-server-presets-0/common-manager-bundle.js.LEGAL.txt +0 -0
  128. package/storybook-static/sb-common-assets/favicon.svg +0 -1
  129. package/storybook-static/sb-common-assets/nunito-sans-bold-italic.woff2 +0 -0
  130. package/storybook-static/sb-common-assets/nunito-sans-bold.woff2 +0 -0
  131. package/storybook-static/sb-common-assets/nunito-sans-italic.woff2 +0 -0
  132. package/storybook-static/sb-common-assets/nunito-sans-regular.woff2 +0 -0
  133. package/storybook-static/sb-manager/globals-module-info.js +0 -995
  134. package/storybook-static/sb-manager/globals-runtime.js +0 -53527
  135. package/storybook-static/sb-manager/globals.js +0 -48
  136. package/storybook-static/sb-manager/runtime.js +0 -11885
  137. package/storybook-static/sb-preview/globals.js +0 -33
  138. package/storybook-static/sb-preview/runtime.js +0 -9483
  139. package/tsconfig.json +0 -14
  140. /package/{src → dist}/components/reproduction-widget/ReproductionWidget.js +0 -0
  141. /package/{src → dist}/components/reproduction-widget/index.js +0 -0
  142. /package/{src → dist}/components/reproduction-widget/inner-players/PlayAlongInnerPlayer.js +0 -0
  143. /package/{src → dist}/components/reproduction-widget/inner-players/YouTubeInnerPlayer.js +0 -0
  144. /package/{src → dist}/components/reproduction-widget/models/Player/PlayAlongPlayer.js +0 -0
  145. /package/{src → dist}/components/reproduction-widget/models/Player/PlayerEvents.js +0 -0
  146. /package/{src → dist}/components/reproduction-widget/models/Player/YouTubePlayer.js +0 -0
  147. /package/{src → dist}/components/reproduction-widget/models/Reproduction.js +0 -0
  148. /package/{src → dist}/components/reproduction-widget/models/ReproductionBuilder.js +0 -0
  149. /package/{src → dist}/stories/reproduction-widget.stories.js +0 -0
@@ -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,77 +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 } from './ZoomContext/ZoomContext';
8
- import { getBlockOffsetForZoomLevel, getTimelineWrapperWidth, numberToPxString, } from './utils/utils';
9
- const TimelineContainer = styled.div `
10
- background-color: #f0f0f0;
11
- border: 1px solid #c9c9c9;
12
- height: 80px;
13
- width: 100%;
14
- max-width: 100%;
15
- overflow-x: auto;
16
- position: relative;
17
- display: flex;
18
- `;
19
- const TimelineWrapper = styled.div `
20
- position: absolute;
21
- height: 100%;
22
- display: flex;
23
- flex-direction: row;
24
- align-items: center;
25
- overflow: hidden;
26
- `;
27
- export const Timeline = ({ duration, value, zoomLevel = 0, selectedRange = [], withTimeBlocks = true, onChange = () => { }, onRangeChange = () => { }, className = '', }) => {
28
- const timeLineContainerRef = useRef(null);
29
- const canvasRef = useRef(null);
30
- const [zoomContextValue, setZoomContextValue] = useState({
31
- blockOffset: 0,
32
- pixelsInSecond: 0,
33
- timelineWrapperWidth: 0,
34
- });
35
- let zoomLevelValue = zoomLevel ? zoomLevel : 0;
36
- if (zoomLevelValue < 0 || zoomLevelValue >= zoomLevelConfigurations.length) {
37
- console.warn('Invalid value for property zoomLevel.');
38
- zoomLevelValue = 0;
39
- }
40
- if (value < 0 || value > duration) {
41
- console.warn('Invalid value.');
42
- }
43
- if (!(selectedRange.length === 0 || selectedRange.length === 2)) {
44
- selectedRange = [];
45
- console.warn('The selected range must contain only two values.');
46
- }
47
- if (selectedRange.length === 2 &&
48
- !(0 <= selectedRange[0] &&
49
- selectedRange[0] < selectedRange[1] &&
50
- selectedRange[1] <= duration)) {
51
- selectedRange = [];
52
- console.warn('The selected range is inconsistent.');
53
- }
54
- useEffect(() => {
55
- if (!timeLineContainerRef.current)
56
- return;
57
- const timelineWrapperWidth = getTimelineWrapperWidth(timeLineContainerRef.current.offsetWidth, zoomLevelValue);
58
- setZoomContextValue({
59
- blockOffset: getBlockOffsetForZoomLevel(zoomLevelValue, duration, timelineWrapperWidth),
60
- pixelsInSecond: timelineWrapperWidth / duration,
61
- timelineWrapperWidth: timelineWrapperWidth,
62
- });
63
- }, [timeLineContainerRef.current, zoomLevelValue, duration]);
64
- useEffect(() => {
65
- const timeLineWrapper = timeLineContainerRef.current;
66
- const scrollPosition = value * zoomContextValue.pixelsInSecond - 300;
67
- timeLineWrapper.scrollLeft = Math.max(0, scrollPosition);
68
- }, [duration, value, zoomContextValue]);
69
- return (React.createElement(TimelineContainer, { ref: timeLineContainerRef, className: className },
70
- React.createElement(TimelineWrapper, { style: {
71
- width: numberToPxString(zoomContextValue.timelineWrapperWidth),
72
- } },
73
- React.createElement(ZoomContext.Provider, { value: zoomContextValue },
74
- React.createElement(TimelineCanvas, { ref: canvasRef, duration: duration, withTimeBlocks: withTimeBlocks }),
75
- React.createElement(TimelineValue, { value: value, canvasRef: canvasRef }),
76
- React.createElement(RangeSelectorCanvas, { selectedRange: selectedRange, onChange: onChange, onRangeChange: onRangeChange })))));
77
- };
@@ -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,26 +0,0 @@
1
- import React from 'react';
2
- import styled from 'styled-components';
3
- const TickTimeContainer = styled.span.attrs((props) => ({
4
- style: {
5
- left: props.left,
6
- },
7
- })) `
8
- background: transparent;
9
- position: absolute;
10
- padding-left: 8px;
11
- color: #646464;
12
- user-select: none;
13
- min-width: 20px;
14
- max-width: 20px;
15
- align-self: flex-end;
16
- `;
17
- const TickTime = ({ start, leftPosition }) => {
18
- const minutes = Math.floor(start / 60);
19
- let seconds = start - minutes * 60;
20
- let secondsFormatted = seconds < 10 ? '0' + seconds : seconds.toString();
21
- return (React.createElement(TickTimeContainer, { left: leftPosition, className: 'media-timeline-tick-time' },
22
- minutes,
23
- ":",
24
- secondsFormatted));
25
- };
26
- export default TickTime;
@@ -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,19 +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
- const TickTimeCollectionDisplayContainer = styled.div `
6
- position: absolute;
7
- display: flex;
8
- align-self: flex-end;
9
- height: 100%;
10
- `;
11
- const TickTimeCollectionDisplay = ({ tickTimes = [], }) => {
12
- return (React.createElement(ZoomContext.Consumer, null, (value) => {
13
- return (React.createElement(TickTimeCollectionDisplayContainer, null, tickTimes.map((tickTimeValue, index) => {
14
- const leftPosition = tickTimeValue * value.pixelsInSecond + 'px';
15
- return (React.createElement(TickTime, { key: index, start: tickTimeValue, leftPosition: leftPosition }));
16
- })));
17
- }));
18
- };
19
- export default TickTimeCollectionDisplay;
@@ -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,44 +0,0 @@
1
- import React, { forwardRef, useContext, useEffect, useImperativeHandle, useRef, } from 'react';
2
- import styled from 'styled-components';
3
- import { ZoomContext } from '../ZoomContext/ZoomContext';
4
- import TickTimeCollectionDisplay from './TickTimeCollectionDisplay';
5
- import { drawTimeBlocksOnCanvas } from './drawTimeBlocksOnCanvas';
6
- const OverlayCanvas = styled.canvas `
7
- position: absolute;
8
- top: 0;
9
- left: 0;
10
- width: 100%;
11
- height: 100%;
12
- color: #c9c9c9;
13
- `;
14
- const TimelineCanvas = forwardRef(({ duration, withTimeBlocks }, ref) => {
15
- const internalCanvasRef = useRef(null);
16
- const zoomContextValue = useContext(ZoomContext);
17
- const blockStartingTimes = (() => {
18
- if (!withTimeBlocks || !zoomContextValue.blockOffset)
19
- return [];
20
- let blockStartingTimes = [0];
21
- let secondsToCover = duration;
22
- while (secondsToCover > 0) {
23
- blockStartingTimes.push(blockStartingTimes[blockStartingTimes.length - 1] +
24
- zoomContextValue.blockOffset);
25
- secondsToCover = secondsToCover - zoomContextValue.blockOffset;
26
- }
27
- blockStartingTimes.splice(-1);
28
- return blockStartingTimes;
29
- })();
30
- // Pass the internal ref's current value directly to the forwarded ref
31
- useImperativeHandle(ref, () => internalCanvasRef.current);
32
- useEffect(() => {
33
- const canvas = internalCanvasRef.current;
34
- // https://stackoverflow.com/questions/8696631/canvas-drawings-like-lines-are-blurry
35
- canvas.width = canvas.offsetWidth;
36
- canvas.height = canvas.offsetHeight;
37
- if (withTimeBlocks)
38
- drawTimeBlocksOnCanvas(canvas, blockStartingTimes, zoomContextValue);
39
- }, [blockStartingTimes, withTimeBlocks, zoomContextValue]);
40
- return (React.createElement(React.Fragment, null,
41
- React.createElement(OverlayCanvas, { ref: internalCanvasRef, className: 'media-timeline-value-line-canvas' }),
42
- withTimeBlocks && (React.createElement(TickTimeCollectionDisplay, { tickTimes: blockStartingTimes }))));
43
- });
44
- export default TimelineCanvas;
@@ -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,28 +0,0 @@
1
- import { secondsToPixel } from '../utils/utils';
2
- export const drawTimeBlocksOnCanvas = (canvas, blockStartingTimes, zoomContextValue) => {
3
- const blockHeight = 20;
4
- const context = canvas.getContext('2d');
5
- // draw top line
6
- context.beginPath();
7
- context.moveTo(0, canvas.height - blockHeight);
8
- context.lineTo(zoomContextValue.timelineWrapperWidth, canvas.height - blockHeight);
9
- context.strokeStyle = window
10
- .getComputedStyle(canvas)
11
- .getPropertyValue('color');
12
- context.stroke();
13
- for (const blockStartingTime of blockStartingTimes) {
14
- const x0Pixel = secondsToPixel(zoomContextValue, blockStartingTime);
15
- const x1Pixel = secondsToPixel(zoomContextValue, blockStartingTime + zoomContextValue.blockOffset);
16
- context.beginPath();
17
- // draw left line
18
- context.moveTo(x0Pixel, canvas.height);
19
- context.lineTo(x0Pixel, canvas.height - blockHeight);
20
- // draw right line
21
- context.moveTo(x1Pixel, canvas.height);
22
- context.lineTo(x1Pixel, canvas.height - blockHeight);
23
- context.strokeStyle = window
24
- .getComputedStyle(canvas)
25
- .getPropertyValue('color');
26
- context.stroke();
27
- }
28
- };