@ldelia/react-media 0.2.6 → 0.2.8
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/dist/components/timeline/RangeSelectorCanvas/RangeSelectorCanvas.d.ts +8 -0
- package/dist/components/timeline/RangeSelectorCanvas/RangeSelectorCanvas.js +155 -0
- package/dist/components/timeline/Timeline.d.ts +0 -5
- package/dist/components/timeline/Timeline.js +35 -27
- package/dist/components/timeline/TimelineCanvas/TickTime.d.ts +7 -0
- package/dist/components/timeline/TimelineCanvas/TickTime.js +31 -0
- package/dist/components/timeline/TimelineCanvas/TickTimeCollectionDisplay.d.ts +6 -0
- package/dist/components/timeline/TimelineCanvas/TickTimeCollectionDisplay.js +24 -0
- package/dist/components/timeline/TimelineCanvas/TimelineCanvas.d.ts +7 -0
- package/dist/components/timeline/TimelineCanvas/TimelineCanvas.js +72 -0
- package/dist/components/timeline/TimelineCanvas/drawTimeBlocksOnCanvas.d.ts +2 -0
- package/dist/components/timeline/TimelineCanvas/drawTimeBlocksOnCanvas.js +32 -0
- package/dist/components/timeline/TimelineValue/TimelineValue.d.ts +7 -0
- package/dist/components/timeline/TimelineValue/TimelineValue.js +80 -0
- package/dist/components/timeline/VaLueLineCanvas.js +59 -17
- package/dist/components/timeline/ZoomContext/ZoomContext.d.ts +7 -0
- package/dist/components/timeline/ZoomContext/ZoomContext.js +8 -0
- package/dist/components/timeline/utils/utils.d.ts +5 -1
- package/dist/components/timeline/utils/utils.js +26 -1
- package/dist/stories/timeline.stories.d.ts +6 -6
- package/dist/stories/timeline.stories.js +12 -4
- package/package.json +1 -1
- package/src/components/timeline/{RangeSelectorCanvas.tsx → RangeSelectorCanvas/RangeSelectorCanvas.tsx} +9 -11
- package/src/components/timeline/Timeline.tsx +50 -37
- package/src/components/timeline/{TickTimeCollectionDisplay.tsx → TimelineCanvas/TickTimeCollectionDisplay.tsx} +5 -5
- package/src/components/timeline/TimelineCanvas/TimelineCanvas.tsx +79 -0
- package/src/components/timeline/TimelineCanvas/drawTimeBlocksOnCanvas.ts +43 -0
- package/src/components/timeline/TimelineValue/TimelineValue.tsx +87 -0
- package/src/components/timeline/ZoomContext/ZoomContext.ts +10 -0
- package/src/components/timeline/utils/utils.ts +34 -1
- package/src/stories/timeline.stories.custom.css +27 -1
- package/src/stories/timeline.stories.tsx +12 -3
- package/src/components/timeline/VaLueLineCanvas.tsx +0 -101
- /package/src/components/timeline/{TickTime.tsx → TimelineCanvas/TickTime.tsx} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ZoomContextType } from '../
|
|
1
|
+
import { ZoomContextType } from '../ZoomContext/ZoomContext';
|
|
2
2
|
|
|
3
3
|
export const secondsToPixel = (
|
|
4
4
|
zoomContextValue: ZoomContextType,
|
|
@@ -14,3 +14,36 @@ export const pixelToSeconds = (
|
|
|
14
14
|
const seconds = pixel / zoomContextValue.pixelsInSecond;
|
|
15
15
|
return Math.round((seconds + Number.EPSILON) * 100) / 100;
|
|
16
16
|
};
|
|
17
|
+
|
|
18
|
+
export const getComputedElementWidth = (element: HTMLElement): number => {
|
|
19
|
+
const elementWidthCSSProperty: string = window
|
|
20
|
+
.getComputedStyle(element)
|
|
21
|
+
.getPropertyValue('width')
|
|
22
|
+
.replace(/[^-\d]/g, '');
|
|
23
|
+
return parseInt(elementWidthCSSProperty);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const numberToPxString = (number: number): string => {
|
|
27
|
+
return `${number}px`;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const getTimelineWrapperWidth = (
|
|
31
|
+
timeLineContainerWidth: number,
|
|
32
|
+
zoomLevel: number,
|
|
33
|
+
): number => {
|
|
34
|
+
return timeLineContainerWidth * Math.pow(1.25, zoomLevel) - 2; //-2px to account for the border
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export function getBlockOffsetForZoomLevel(
|
|
38
|
+
zoomLevel: number,
|
|
39
|
+
duration: number,
|
|
40
|
+
timelineWrapperWidth: number,
|
|
41
|
+
): number {
|
|
42
|
+
const offsets = [10, 5, 5, 5, 2, 2, 2, 2, 2, 1];
|
|
43
|
+
|
|
44
|
+
let optimalOffset = offsets[zoomLevel];
|
|
45
|
+
while ((duration / optimalOffset) * 40 > timelineWrapperWidth) {
|
|
46
|
+
optimalOffset = optimalOffset * 1.25;
|
|
47
|
+
}
|
|
48
|
+
return Math.ceil(optimalOffset);
|
|
49
|
+
}
|
|
@@ -1,3 +1,29 @@
|
|
|
1
|
-
#storybook-root .this-class-redefines-
|
|
1
|
+
#storybook-root .this-class-redefines-styles {
|
|
2
2
|
background-color: transparent;
|
|
3
3
|
}
|
|
4
|
+
|
|
5
|
+
#storybook-root .minimalist {
|
|
6
|
+
background-color: transparent;
|
|
7
|
+
border: 0;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
#storybook-root .minimalist > canvas {
|
|
11
|
+
color: transparent;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
#storybook-root .minimalist > div > .media-timeline-pre-value-line {
|
|
15
|
+
height: 4px;
|
|
16
|
+
background-color: greenyellow;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
#storybook-root .minimalist > div > .media-timeline-value-line {
|
|
20
|
+
height: 10px;
|
|
21
|
+
width: 10px;
|
|
22
|
+
background-color: greenyellow;
|
|
23
|
+
border-radius: 10px;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
#storybook-root .minimalist > div > .media-timeline-post-value-line {
|
|
27
|
+
height: 4px;
|
|
28
|
+
background-color: rgba(10, 10, 10, 0.24);
|
|
29
|
+
}
|
|
@@ -45,13 +45,22 @@ WithCustomClassName.args = {
|
|
|
45
45
|
duration: 305,
|
|
46
46
|
value: 31,
|
|
47
47
|
zoomLevel: 0,
|
|
48
|
-
className: 'this-class-redefines-
|
|
48
|
+
className: 'this-class-redefines-styles',
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
-
export const
|
|
52
|
-
|
|
51
|
+
export const WithoutTimeBlocks = Template.bind({});
|
|
52
|
+
WithoutTimeBlocks.args = {
|
|
53
53
|
duration: 305,
|
|
54
54
|
value: 31,
|
|
55
55
|
zoomLevel: 0,
|
|
56
56
|
withTimeBlocks: false,
|
|
57
57
|
};
|
|
58
|
+
|
|
59
|
+
export const Minimalist = Template.bind({});
|
|
60
|
+
Minimalist.args = {
|
|
61
|
+
duration: 305,
|
|
62
|
+
value: 31,
|
|
63
|
+
zoomLevel: 0,
|
|
64
|
+
withTimeBlocks: false,
|
|
65
|
+
className: 'minimalist',
|
|
66
|
+
};
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import styled from 'styled-components';
|
|
3
|
-
|
|
4
|
-
import { ZoomContext, ZoomContextType } from './index';
|
|
5
|
-
import { useCallback, useContext, useEffect, useRef } from 'react';
|
|
6
|
-
import { secondsToPixel } from './utils/utils';
|
|
7
|
-
|
|
8
|
-
export interface VaLueLineCanvasProps {
|
|
9
|
-
blockStartingTimes: number[];
|
|
10
|
-
value: number;
|
|
11
|
-
}
|
|
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
|
-
const ValueLine = styled.span`
|
|
22
|
-
position: absolute;
|
|
23
|
-
width: 1px;
|
|
24
|
-
height: 100%;
|
|
25
|
-
background-color: #575757;
|
|
26
|
-
`;
|
|
27
|
-
|
|
28
|
-
const VaLueLineCanvas: React.FC<VaLueLineCanvasProps> = ({
|
|
29
|
-
blockStartingTimes = [],
|
|
30
|
-
value,
|
|
31
|
-
}) => {
|
|
32
|
-
const canvasRef = useRef(null);
|
|
33
|
-
const valueLineRef = useRef(null);
|
|
34
|
-
const zoomContextValue: ZoomContextType = useContext(ZoomContext);
|
|
35
|
-
|
|
36
|
-
const showBlocks = useCallback(
|
|
37
|
-
(canvas: HTMLCanvasElement) => {
|
|
38
|
-
const blockHeight = 20;
|
|
39
|
-
const context: CanvasRenderingContext2D = canvas.getContext('2d')!;
|
|
40
|
-
|
|
41
|
-
for (const blockStartingTime of blockStartingTimes) {
|
|
42
|
-
const x0Pixel = secondsToPixel(zoomContextValue, blockStartingTime);
|
|
43
|
-
const x1Pixel = secondsToPixel(
|
|
44
|
-
zoomContextValue,
|
|
45
|
-
blockStartingTime + zoomContextValue.blockOffset,
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
context.beginPath();
|
|
49
|
-
context.moveTo(x0Pixel, canvas.height);
|
|
50
|
-
context.lineTo(x0Pixel, canvas.height - blockHeight);
|
|
51
|
-
context.lineTo(x1Pixel, canvas.height - blockHeight);
|
|
52
|
-
context.lineTo(x1Pixel, canvas.height);
|
|
53
|
-
|
|
54
|
-
context.strokeStyle = window
|
|
55
|
-
.getComputedStyle(canvas)
|
|
56
|
-
.getPropertyValue('color');
|
|
57
|
-
context.stroke();
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
[blockStartingTimes, zoomContextValue],
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
const showValueLine = useCallback(() => {
|
|
64
|
-
const linePosition: number = secondsToPixel(zoomContextValue, value);
|
|
65
|
-
|
|
66
|
-
const valueLineElement: HTMLElement = valueLineRef.current!;
|
|
67
|
-
const elementWidthCSSProperty: string = window
|
|
68
|
-
.getComputedStyle(valueLineElement)
|
|
69
|
-
.getPropertyValue('width')
|
|
70
|
-
.replace(/[^-\d]/g, '');
|
|
71
|
-
const elementWidth: number = parseInt(elementWidthCSSProperty);
|
|
72
|
-
const linePositionAtValueLineMiddle: number =
|
|
73
|
-
linePosition - elementWidth / 2;
|
|
74
|
-
valueLineElement.style.left = linePositionAtValueLineMiddle + 'px';
|
|
75
|
-
}, [value, zoomContextValue]);
|
|
76
|
-
|
|
77
|
-
useEffect(() => {
|
|
78
|
-
const canvas: HTMLCanvasElement = canvasRef.current!;
|
|
79
|
-
|
|
80
|
-
// https://stackoverflow.com/questions/8696631/canvas-drawings-like-lines-are-blurry
|
|
81
|
-
canvas.width = canvas.offsetWidth;
|
|
82
|
-
canvas.height = canvas.offsetHeight;
|
|
83
|
-
|
|
84
|
-
showBlocks(canvas);
|
|
85
|
-
showValueLine();
|
|
86
|
-
}, [showBlocks, showValueLine]);
|
|
87
|
-
|
|
88
|
-
return (
|
|
89
|
-
<>
|
|
90
|
-
<OverlayCanvas
|
|
91
|
-
ref={canvasRef}
|
|
92
|
-
className={'media-timeline-value-line-canvas'}
|
|
93
|
-
/>
|
|
94
|
-
<ValueLine
|
|
95
|
-
ref={valueLineRef}
|
|
96
|
-
className={'media-timeline-value-line'}
|
|
97
|
-
></ValueLine>
|
|
98
|
-
</>
|
|
99
|
-
);
|
|
100
|
-
};
|
|
101
|
-
export default VaLueLineCanvas;
|
|
File without changes
|