@ldelia/react-media 0.4.1 → 0.4.2

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 (33) hide show
  1. package/package.json +1 -1
  2. package/dist/components/__tests__/timeline/timeline.test.d.ts +0 -1
  3. package/dist/components/__tests__/timeline/timeline.test.js +0 -27
  4. package/dist/components/index.d.ts +0 -1
  5. package/dist/components/index.js +0 -17
  6. package/dist/components/timeline/RangeSelectorCanvas/RangeSelectorCanvas.d.ts +0 -8
  7. package/dist/components/timeline/RangeSelectorCanvas/RangeSelectorCanvas.js +0 -155
  8. package/dist/components/timeline/Timeline.d.ts +0 -12
  9. package/dist/components/timeline/Timeline.js +0 -107
  10. package/dist/components/timeline/TimelineCanvas/TickTime.d.ts +0 -7
  11. package/dist/components/timeline/TimelineCanvas/TickTime.js +0 -31
  12. package/dist/components/timeline/TimelineCanvas/TickTimeCollectionDisplay.d.ts +0 -6
  13. package/dist/components/timeline/TimelineCanvas/TickTimeCollectionDisplay.js +0 -24
  14. package/dist/components/timeline/TimelineCanvas/TimelineCanvas.d.ts +0 -7
  15. package/dist/components/timeline/TimelineCanvas/TimelineCanvas.js +0 -72
  16. package/dist/components/timeline/TimelineCanvas/drawTimeBlocksOnCanvas.d.ts +0 -2
  17. package/dist/components/timeline/TimelineCanvas/drawTimeBlocksOnCanvas.js +0 -32
  18. package/dist/components/timeline/TimelineValue/TimelineValue.d.ts +0 -7
  19. package/dist/components/timeline/TimelineValue/TimelineValue.js +0 -80
  20. package/dist/components/timeline/ZoomContext/ZoomContext.d.ts +0 -7
  21. package/dist/components/timeline/ZoomContext/ZoomContext.js +0 -8
  22. package/dist/components/timeline/constants.d.ts +0 -1
  23. package/dist/components/timeline/constants.js +0 -16
  24. package/dist/components/timeline/index.d.ts +0 -1
  25. package/dist/components/timeline/index.js +0 -17
  26. package/dist/components/timeline/utils/utils.d.ts +0 -7
  27. package/dist/components/timeline/utils/utils.js +0 -37
  28. package/dist/index.d.ts +0 -1
  29. package/dist/index.js +0 -17
  30. package/dist/setupTests.d.ts +0 -1
  31. package/dist/setupTests.js +0 -7
  32. package/dist/stories/timeline.stories.d.ts +0 -9
  33. package/dist/stories/timeline.stories.js +0 -60
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ldelia/react-media",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "A React components collection for media-related features.",
5
5
  "private": false,
6
6
  "keywords": [
@@ -1 +0,0 @@
1
- export {};
@@ -1,27 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const react_1 = __importDefault(require("react"));
7
- const client_1 = require("react-dom/client");
8
- const timeline_1 = require("../../timeline");
9
- describe('Timeline', () => {
10
- let props;
11
- beforeEach(() => {
12
- props = {
13
- duration: 300,
14
- value: 15,
15
- onChange: jest.fn(),
16
- onRangeChange: jest.fn(),
17
- zoomLevel: 0,
18
- };
19
- });
20
- describe('render()', () => {
21
- it('renders a timeline', () => {
22
- const rootElement = document.createElement('div');
23
- const root = (0, client_1.createRoot)(rootElement);
24
- root.render(react_1.default.createElement(timeline_1.Timeline, Object.assign({}, props)));
25
- });
26
- });
27
- });
@@ -1 +0,0 @@
1
- export * from './timeline';
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./timeline"), exports);
@@ -1,8 +0,0 @@
1
- import React from 'react';
2
- export interface RangeSelectorCanvasProps {
3
- selectedRange: number[];
4
- onChange: (value: number) => void;
5
- onRangeChange: (value: number[]) => void;
6
- }
7
- declare const _default: React.NamedExoticComponent<RangeSelectorCanvasProps>;
8
- export default _default;
@@ -1,155 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- const react_1 = __importStar(require("react"));
30
- const styled_components_1 = __importDefault(require("styled-components"));
31
- const ZoomContext_1 = require("../ZoomContext/ZoomContext");
32
- const utils_1 = require("../utils/utils");
33
- const OverlayCanvas = styled_components_1.default.canvas `
34
- position: absolute;
35
- top: 0;
36
- left: 0;
37
- width: 100%;
38
- height: 100%;
39
- color: cadetblue;
40
- `;
41
- const RangeSelectorCanvas = ({ selectedRange, onChange, onRangeChange, }) => {
42
- const canvasRef = (0, react_1.useRef)(null);
43
- const zoomContextValue = (0, react_1.useContext)(ZoomContext_1.ZoomContext);
44
- let isSelectingRange = false;
45
- let selectedRangeInPixels = (0, react_1.useMemo)(() => [], []);
46
- if (selectedRange.length === 2) {
47
- selectedRangeInPixels = [
48
- (0, utils_1.secondsToPixel)(zoomContextValue, selectedRange[0]),
49
- (0, utils_1.secondsToPixel)(zoomContextValue, selectedRange[1]),
50
- ];
51
- }
52
- let lastValidSelectedRangeInPixels = [];
53
- const getMousePointerPixelPosition = (e) => {
54
- const canvas = canvasRef.current;
55
- let rect = canvas.getBoundingClientRect();
56
- return e.clientX - rect.left;
57
- };
58
- const drawRect = (pixelX0, pixelX1) => {
59
- const canvas = canvasRef.current;
60
- const context = canvas.getContext('2d');
61
- context.globalAlpha = 0.3;
62
- context.fillStyle = window
63
- .getComputedStyle(canvas)
64
- .getPropertyValue('color');
65
- context.fillRect(pixelX0, 0, pixelX1 - pixelX0, context.canvas.height);
66
- context.globalAlpha = 1.0;
67
- };
68
- const onCanvasDoubleClick = (e) => {
69
- const x0 = getMousePointerPixelPosition(e);
70
- onChange((0, utils_1.pixelToSeconds)(zoomContextValue, x0));
71
- selectedRangeInPixels = lastValidSelectedRangeInPixels;
72
- };
73
- const isPixelNearSelectedRange = (x0) => {
74
- if (selectedRangeInPixels.length === 2) {
75
- const diff = Math.min(Math.abs(selectedRangeInPixels[0] - x0), Math.abs(selectedRangeInPixels[1] - x0));
76
- return diff <= zoomContextValue.pixelsInSecond / 2;
77
- }
78
- return false;
79
- };
80
- const onCanvasMouseDown = (e) => {
81
- const mouseCurrentPosition = getMousePointerPixelPosition(e);
82
- if (!isPixelNearSelectedRange(mouseCurrentPosition)) {
83
- // Keep track of the first position of the new range.
84
- selectedRangeInPixels = [mouseCurrentPosition, mouseCurrentPosition];
85
- }
86
- isSelectingRange = true;
87
- };
88
- const onCanvasMouseMove = (e) => {
89
- const canvas = canvasRef.current;
90
- const context = canvas.getContext('2d');
91
- const mouseCurrentPosition = getMousePointerPixelPosition(e);
92
- if (selectedRangeInPixels.length === 2) {
93
- const diff = Math.min(Math.abs(selectedRangeInPixels[0] - mouseCurrentPosition), Math.abs(selectedRangeInPixels[1] - mouseCurrentPosition));
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
- if (!isSelectingRange)
98
- return;
99
- if (mouseCurrentPosition < selectedRangeInPixels[0]) {
100
- // The left side must be enlarged.
101
- selectedRangeInPixels[0] = mouseCurrentPosition;
102
- }
103
- else if (mouseCurrentPosition > selectedRangeInPixels[1]) {
104
- // The right side must be enlarged.
105
- selectedRangeInPixels[1] = mouseCurrentPosition;
106
- }
107
- else {
108
- const diffX0 = mouseCurrentPosition - selectedRangeInPixels[0];
109
- const diffX1 = selectedRangeInPixels[1] - mouseCurrentPosition;
110
- if (diffX0 < diffX1) {
111
- // The left side must be shrunk.
112
- selectedRangeInPixels[0] = mouseCurrentPosition;
113
- }
114
- else {
115
- // The right side must be shrunk.
116
- selectedRangeInPixels[1] = mouseCurrentPosition;
117
- }
118
- }
119
- context.clearRect(0, 0, canvas.width, canvas.height);
120
- drawRect(selectedRangeInPixels[0], selectedRangeInPixels[1]);
121
- }
122
- };
123
- const onCanvasMouseUp = (e) => {
124
- if (selectedRangeInPixels.length !== 2)
125
- return;
126
- isSelectingRange = false;
127
- const mouseCurrentPosition = getMousePointerPixelPosition(e);
128
- const pixelRange = [
129
- Math.min(selectedRangeInPixels[0], mouseCurrentPosition),
130
- Math.max(selectedRangeInPixels[1], mouseCurrentPosition),
131
- ];
132
- if (pixelRange[1] - pixelRange[0] <= 1) {
133
- // It was just a click
134
- selectedRangeInPixels = lastValidSelectedRangeInPixels;
135
- }
136
- else {
137
- lastValidSelectedRangeInPixels = pixelRange;
138
- onRangeChange([
139
- (0, utils_1.pixelToSeconds)(zoomContextValue, pixelRange[0]),
140
- (0, utils_1.pixelToSeconds)(zoomContextValue, pixelRange[1]),
141
- ]);
142
- }
143
- };
144
- (0, react_1.useEffect)(() => {
145
- const canvas = canvasRef.current;
146
- // https://stackoverflow.com/questions/8696631/canvas-drawings-like-lines-are-blurry
147
- canvas.width = canvas.offsetWidth;
148
- canvas.height = canvas.offsetHeight;
149
- if (selectedRangeInPixels.length === 0)
150
- return;
151
- drawRect(selectedRangeInPixels[0], selectedRangeInPixels[1]);
152
- }, [selectedRangeInPixels]);
153
- return (react_1.default.createElement(OverlayCanvas, { ref: canvasRef, onDoubleClick: onCanvasDoubleClick, onMouseDown: onCanvasMouseDown, onMouseMove: onCanvasMouseMove, onMouseUp: onCanvasMouseUp, className: 'media-timeline-range-selector-canvas' }));
154
- };
155
- exports.default = react_1.default.memo(RangeSelectorCanvas);
@@ -1,12 +0,0 @@
1
- import React from 'react';
2
- export interface TimelineProps {
3
- duration: number;
4
- value: number;
5
- zoomLevel?: number;
6
- className?: string;
7
- selectedRange?: number[];
8
- withTimeBlocks?: boolean;
9
- onChange?: (value: number) => void;
10
- onRangeChange?: (value: number[]) => void;
11
- }
12
- export declare const Timeline: React.FC<TimelineProps>;
@@ -1,107 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.Timeline = void 0;
30
- const react_1 = __importStar(require("react"));
31
- const TimelineCanvas_1 = __importDefault(require("./TimelineCanvas/TimelineCanvas"));
32
- const RangeSelectorCanvas_1 = __importDefault(require("./RangeSelectorCanvas/RangeSelectorCanvas"));
33
- const constants_1 = require("./constants");
34
- const styled_components_1 = __importDefault(require("styled-components"));
35
- const TimelineValue_1 = require("./TimelineValue/TimelineValue");
36
- const ZoomContext_1 = require("./ZoomContext/ZoomContext");
37
- const utils_1 = require("./utils/utils");
38
- const TimelineContainer = styled_components_1.default.div `
39
- background-color: #f0f0f0;
40
- border: 1px solid #c9c9c9;
41
- height: 80px;
42
- width: 100%;
43
- max-width: 100%;
44
- overflow-x: auto;
45
- position: relative;
46
- display: flex;
47
- `;
48
- const TimelineWrapper = styled_components_1.default.div `
49
- position: absolute;
50
- height: 100%;
51
- display: flex;
52
- flex-direction: row;
53
- align-items: center;
54
- overflow: hidden;
55
- `;
56
- const Timeline = ({ duration, value, zoomLevel = 0, selectedRange = [], withTimeBlocks = true, onChange = () => { }, onRangeChange = () => { }, className = '', }) => {
57
- const timeLineContainerRef = (0, react_1.useRef)(null);
58
- const canvasRef = (0, react_1.useRef)(null);
59
- const [zoomContextValue, setZoomContextValue] = (0, react_1.useState)({
60
- blockOffset: 0,
61
- pixelsInSecond: 0,
62
- timelineWrapperWidth: 0,
63
- });
64
- let zoomLevelValue = zoomLevel ? zoomLevel : 0;
65
- if (zoomLevelValue < 0 || zoomLevelValue >= constants_1.zoomLevelConfigurations.length) {
66
- console.warn('Invalid value for property zoomLevel.');
67
- zoomLevelValue = 0;
68
- }
69
- if (value < 0 || value > duration) {
70
- console.warn('Invalid value.');
71
- }
72
- if (!(selectedRange.length === 0 || selectedRange.length === 2)) {
73
- selectedRange = [];
74
- console.warn('The selected range must contain only two values.');
75
- }
76
- if (selectedRange.length === 2 &&
77
- !(0 <= selectedRange[0] &&
78
- selectedRange[0] < selectedRange[1] &&
79
- selectedRange[1] <= duration)) {
80
- selectedRange = [];
81
- console.warn('The selected range is inconsistent.');
82
- }
83
- (0, react_1.useEffect)(() => {
84
- if (!timeLineContainerRef.current)
85
- return;
86
- const timelineWrapperWidth = (0, utils_1.getTimelineWrapperWidth)(timeLineContainerRef.current.offsetWidth, zoomLevelValue);
87
- setZoomContextValue({
88
- blockOffset: (0, utils_1.getBlockOffsetForZoomLevel)(zoomLevelValue, duration, timelineWrapperWidth),
89
- pixelsInSecond: timelineWrapperWidth / duration,
90
- timelineWrapperWidth: timelineWrapperWidth,
91
- });
92
- }, [timeLineContainerRef.current, zoomLevelValue, duration]);
93
- (0, react_1.useEffect)(() => {
94
- const timeLineWrapper = timeLineContainerRef.current;
95
- const scrollPosition = value * zoomContextValue.pixelsInSecond - 300;
96
- timeLineWrapper.scrollLeft = Math.max(0, scrollPosition);
97
- }, [duration, value, zoomContextValue]);
98
- return (react_1.default.createElement(TimelineContainer, { ref: timeLineContainerRef, className: className },
99
- react_1.default.createElement(TimelineWrapper, { style: {
100
- width: (0, utils_1.numberToPxString)(zoomContextValue.timelineWrapperWidth),
101
- } },
102
- react_1.default.createElement(ZoomContext_1.ZoomContext.Provider, { value: zoomContextValue },
103
- react_1.default.createElement(TimelineCanvas_1.default, { ref: canvasRef, duration: duration, withTimeBlocks: withTimeBlocks }),
104
- react_1.default.createElement(TimelineValue_1.TimelineValue, { value: value, canvasRef: canvasRef }),
105
- react_1.default.createElement(RangeSelectorCanvas_1.default, { selectedRange: selectedRange, onChange: onChange, onRangeChange: onRangeChange })))));
106
- };
107
- exports.Timeline = Timeline;
@@ -1,7 +0,0 @@
1
- import React from 'react';
2
- export type Props = {
3
- start: number;
4
- leftPosition: string;
5
- };
6
- declare const TickTime: React.FC<Props>;
7
- export default TickTime;
@@ -1,31 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const react_1 = __importDefault(require("react"));
7
- const styled_components_1 = __importDefault(require("styled-components"));
8
- const TickTimeContainer = styled_components_1.default.span.attrs((props) => ({
9
- style: {
10
- left: props.left,
11
- },
12
- })) `
13
- background: transparent;
14
- position: absolute;
15
- padding-left: 8px;
16
- color: #646464;
17
- user-select: none;
18
- min-width: 20px;
19
- max-width: 20px;
20
- align-self: flex-end;
21
- `;
22
- const TickTime = ({ start, leftPosition }) => {
23
- const minutes = Math.floor(start / 60);
24
- let seconds = start - minutes * 60;
25
- let secondsFormatted = seconds < 10 ? '0' + seconds : seconds.toString();
26
- return (react_1.default.createElement(TickTimeContainer, { left: leftPosition, className: 'media-timeline-tick-time' },
27
- minutes,
28
- ":",
29
- secondsFormatted));
30
- };
31
- exports.default = TickTime;
@@ -1,6 +0,0 @@
1
- import React from 'react';
2
- export interface TickTimeCollectionDisplayProps {
3
- tickTimes: number[];
4
- }
5
- declare const TickTimeCollectionDisplay: React.FC<TickTimeCollectionDisplayProps>;
6
- export default TickTimeCollectionDisplay;
@@ -1,24 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const react_1 = __importDefault(require("react"));
7
- const styled_components_1 = __importDefault(require("styled-components"));
8
- const TickTime_1 = __importDefault(require("./TickTime"));
9
- const ZoomContext_1 = require("../ZoomContext/ZoomContext");
10
- const TickTimeCollectionDisplayContainer = styled_components_1.default.div `
11
- position: absolute;
12
- display: flex;
13
- align-self: flex-end;
14
- height: 100%;
15
- `;
16
- const TickTimeCollectionDisplay = ({ tickTimes = [], }) => {
17
- return (react_1.default.createElement(ZoomContext_1.ZoomContext.Consumer, null, (value) => {
18
- return (react_1.default.createElement(TickTimeCollectionDisplayContainer, null, tickTimes.map((tickTimeValue, index) => {
19
- const leftPosition = tickTimeValue * value.pixelsInSecond + 'px';
20
- return (react_1.default.createElement(TickTime_1.default, { key: index, start: tickTimeValue, leftPosition: leftPosition }));
21
- })));
22
- }));
23
- };
24
- exports.default = TickTimeCollectionDisplay;
@@ -1,7 +0,0 @@
1
- import React from 'react';
2
- export interface VaLueLineCanvasProps {
3
- duration: number;
4
- withTimeBlocks: boolean;
5
- }
6
- declare const TimelineCanvas: React.ForwardRefExoticComponent<VaLueLineCanvasProps & React.RefAttributes<HTMLCanvasElement>>;
7
- export default TimelineCanvas;
@@ -1,72 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- const react_1 = __importStar(require("react"));
30
- const styled_components_1 = __importDefault(require("styled-components"));
31
- const ZoomContext_1 = require("../ZoomContext/ZoomContext");
32
- const TickTimeCollectionDisplay_1 = __importDefault(require("./TickTimeCollectionDisplay"));
33
- const drawTimeBlocksOnCanvas_1 = require("./drawTimeBlocksOnCanvas");
34
- const OverlayCanvas = styled_components_1.default.canvas `
35
- position: absolute;
36
- top: 0;
37
- left: 0;
38
- width: 100%;
39
- height: 100%;
40
- color: #c9c9c9;
41
- `;
42
- const TimelineCanvas = (0, react_1.forwardRef)(({ duration, withTimeBlocks }, ref) => {
43
- const internalCanvasRef = (0, react_1.useRef)(null);
44
- const zoomContextValue = (0, react_1.useContext)(ZoomContext_1.ZoomContext);
45
- const blockStartingTimes = (() => {
46
- if (!withTimeBlocks || !zoomContextValue.blockOffset)
47
- return [];
48
- let blockStartingTimes = [0];
49
- let secondsToCover = duration;
50
- while (secondsToCover > 0) {
51
- blockStartingTimes.push(blockStartingTimes[blockStartingTimes.length - 1] +
52
- zoomContextValue.blockOffset);
53
- secondsToCover = secondsToCover - zoomContextValue.blockOffset;
54
- }
55
- blockStartingTimes.splice(-1);
56
- return blockStartingTimes;
57
- })();
58
- // Pass the internal ref's current value directly to the forwarded ref
59
- (0, react_1.useImperativeHandle)(ref, () => internalCanvasRef.current);
60
- (0, react_1.useEffect)(() => {
61
- const canvas = internalCanvasRef.current;
62
- // https://stackoverflow.com/questions/8696631/canvas-drawings-like-lines-are-blurry
63
- canvas.width = canvas.offsetWidth;
64
- canvas.height = canvas.offsetHeight;
65
- if (withTimeBlocks)
66
- (0, drawTimeBlocksOnCanvas_1.drawTimeBlocksOnCanvas)(canvas, blockStartingTimes, zoomContextValue);
67
- }, [blockStartingTimes, withTimeBlocks, zoomContextValue]);
68
- return (react_1.default.createElement(react_1.default.Fragment, null,
69
- react_1.default.createElement(OverlayCanvas, { ref: internalCanvasRef, className: 'media-timeline-value-line-canvas' }),
70
- withTimeBlocks && (react_1.default.createElement(TickTimeCollectionDisplay_1.default, { tickTimes: blockStartingTimes }))));
71
- });
72
- exports.default = TimelineCanvas;
@@ -1,2 +0,0 @@
1
- import { ZoomContextType } from '../ZoomContext/ZoomContext';
2
- export declare const drawTimeBlocksOnCanvas: (canvas: HTMLCanvasElement, blockStartingTimes: number[], zoomContextValue: ZoomContextType) => void;
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.drawTimeBlocksOnCanvas = void 0;
4
- const utils_1 = require("../utils/utils");
5
- const drawTimeBlocksOnCanvas = (canvas, blockStartingTimes, zoomContextValue) => {
6
- const blockHeight = 20;
7
- const context = canvas.getContext('2d');
8
- // draw top line
9
- context.beginPath();
10
- context.moveTo(0, canvas.height - blockHeight);
11
- context.lineTo(zoomContextValue.timelineWrapperWidth, canvas.height - blockHeight);
12
- context.strokeStyle = window
13
- .getComputedStyle(canvas)
14
- .getPropertyValue('color');
15
- context.stroke();
16
- for (const blockStartingTime of blockStartingTimes) {
17
- const x0Pixel = (0, utils_1.secondsToPixel)(zoomContextValue, blockStartingTime);
18
- const x1Pixel = (0, utils_1.secondsToPixel)(zoomContextValue, blockStartingTime + zoomContextValue.blockOffset);
19
- context.beginPath();
20
- // draw left line
21
- context.moveTo(x0Pixel, canvas.height);
22
- context.lineTo(x0Pixel, canvas.height - blockHeight);
23
- // draw right line
24
- context.moveTo(x1Pixel, canvas.height);
25
- context.lineTo(x1Pixel, canvas.height - blockHeight);
26
- context.strokeStyle = window
27
- .getComputedStyle(canvas)
28
- .getPropertyValue('color');
29
- context.stroke();
30
- }
31
- };
32
- exports.drawTimeBlocksOnCanvas = drawTimeBlocksOnCanvas;
@@ -1,7 +0,0 @@
1
- import React from 'react';
2
- interface Props {
3
- canvasRef: React.RefObject<HTMLCanvasElement>;
4
- value: number;
5
- }
6
- export declare const TimelineValue: React.FC<Props>;
7
- export {};
@@ -1,80 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.TimelineValue = void 0;
30
- const react_1 = __importStar(require("react"));
31
- const styled_components_1 = __importDefault(require("styled-components"));
32
- const utils_1 = require("../utils/utils");
33
- const ZoomContext_1 = require("../ZoomContext/ZoomContext");
34
- const PreValueLine = styled_components_1.default.span `
35
- position: absolute;
36
- left: 0;
37
- height: 100%;
38
- `;
39
- const ValueLine = styled_components_1.default.span `
40
- position: absolute;
41
- width: 1px;
42
- height: 100%;
43
- background-color: #575757;
44
- `;
45
- const PostValueLine = styled_components_1.default.span `
46
- position: absolute;
47
- height: 100%;
48
- `;
49
- const TimelineValue = ({ canvasRef, value }) => {
50
- const preValueLineRef = (0, react_1.useRef)(null);
51
- const valueLineRef = (0, react_1.useRef)(null);
52
- const postValueLineRef = (0, react_1.useRef)(null);
53
- const zoomContextValue = (0, react_1.useContext)(ZoomContext_1.ZoomContext);
54
- const showValueLine = (0, react_1.useCallback)(() => {
55
- const canvas = canvasRef.current;
56
- const preValueLineElement = preValueLineRef.current;
57
- const valueLineElement = valueLineRef.current;
58
- const postValueLineElement = postValueLineRef.current;
59
- const valueLineWidth = (0, utils_1.getComputedElementWidth)(valueLineElement);
60
- const linePosition = (0, utils_1.secondsToPixel)(zoomContextValue, value);
61
- const valueLinePositionBeginningConsideringWidth = linePosition - valueLineWidth / 2;
62
- // configure preValueLineElement
63
- preValueLineElement.style.width = (0, utils_1.numberToPxString)(valueLinePositionBeginningConsideringWidth);
64
- // configure valueLineElement
65
- valueLineElement.style.left = (0, utils_1.numberToPxString)(valueLinePositionBeginningConsideringWidth);
66
- // configure postValueLineElement
67
- const postValueLinePosition = valueLinePositionBeginningConsideringWidth + valueLineWidth;
68
- const postValueLineWidth = canvas.width - postValueLinePosition;
69
- postValueLineElement.style.left = (0, utils_1.numberToPxString)(postValueLinePosition);
70
- postValueLineElement.style.width = (0, utils_1.numberToPxString)(postValueLineWidth);
71
- }, [canvasRef, value, zoomContextValue]);
72
- (0, react_1.useEffect)(() => {
73
- showValueLine();
74
- }, [showValueLine]);
75
- return (react_1.default.createElement(react_1.default.Fragment, null,
76
- react_1.default.createElement(PreValueLine, { ref: preValueLineRef, className: 'media-timeline-pre-value-line' }),
77
- react_1.default.createElement(ValueLine, { ref: valueLineRef, className: 'media-timeline-value-line' }),
78
- react_1.default.createElement(PostValueLine, { ref: postValueLineRef, className: 'media-timeline-post-value-line' })));
79
- };
80
- exports.TimelineValue = TimelineValue;
@@ -1,7 +0,0 @@
1
- import React from 'react';
2
- export type ZoomContextType = {
3
- blockOffset: number;
4
- pixelsInSecond: number;
5
- timelineWrapperWidth: number;
6
- };
7
- export declare const ZoomContext: React.Context<ZoomContextType>;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ZoomContext = void 0;
7
- const react_1 = __importDefault(require("react"));
8
- exports.ZoomContext = react_1.default.createContext(null);
@@ -1 +0,0 @@
1
- export declare const zoomLevelConfigurations: number[][];
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.zoomLevelConfigurations = void 0;
4
- //[blockOffset, pixelsInSecond] when zoomLevel === 0, each block has an offset of 20 seconds, and each second has a width of 7px.
5
- exports.zoomLevelConfigurations = [
6
- [20, 7],
7
- [10, 10],
8
- [10, 15],
9
- [5, 20],
10
- [5, 25],
11
- [2, 35],
12
- [2, 50],
13
- [1, 60],
14
- [1, 75],
15
- [1, 90],
16
- ];
@@ -1 +0,0 @@
1
- export * from './Timeline';
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./Timeline"), exports);
@@ -1,7 +0,0 @@
1
- import { ZoomContextType } from '../ZoomContext/ZoomContext';
2
- export declare const secondsToPixel: (zoomContextValue: ZoomContextType, seconds: number) => number;
3
- export declare const pixelToSeconds: (zoomContextValue: ZoomContextType, pixel: number) => number;
4
- export declare const getComputedElementWidth: (element: HTMLElement) => number;
5
- export declare const numberToPxString: (number: number) => string;
6
- export declare const getTimelineWrapperWidth: (timeLineContainerWidth: number, zoomLevel: number) => number;
7
- export declare function getBlockOffsetForZoomLevel(zoomLevel: number, duration: number, timelineWrapperWidth: number): number;
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getBlockOffsetForZoomLevel = exports.getTimelineWrapperWidth = exports.numberToPxString = exports.getComputedElementWidth = exports.pixelToSeconds = exports.secondsToPixel = void 0;
4
- const secondsToPixel = (zoomContextValue, seconds) => {
5
- return zoomContextValue.pixelsInSecond * seconds;
6
- };
7
- exports.secondsToPixel = secondsToPixel;
8
- const pixelToSeconds = (zoomContextValue, pixel) => {
9
- const seconds = pixel / zoomContextValue.pixelsInSecond;
10
- return Math.round((seconds + Number.EPSILON) * 100) / 100;
11
- };
12
- exports.pixelToSeconds = pixelToSeconds;
13
- const getComputedElementWidth = (element) => {
14
- const elementWidthCSSProperty = window
15
- .getComputedStyle(element)
16
- .getPropertyValue('width')
17
- .replace(/[^-\d]/g, '');
18
- return parseInt(elementWidthCSSProperty);
19
- };
20
- exports.getComputedElementWidth = getComputedElementWidth;
21
- const numberToPxString = (number) => {
22
- return `${number}px`;
23
- };
24
- exports.numberToPxString = numberToPxString;
25
- const getTimelineWrapperWidth = (timeLineContainerWidth, zoomLevel) => {
26
- return timeLineContainerWidth * Math.pow(1.25, zoomLevel) - 2; //-2px to account for the border
27
- };
28
- exports.getTimelineWrapperWidth = getTimelineWrapperWidth;
29
- function getBlockOffsetForZoomLevel(zoomLevel, duration, timelineWrapperWidth) {
30
- const offsets = [10, 5, 5, 5, 2, 2, 2, 2, 2, 1];
31
- let optimalOffset = offsets[zoomLevel];
32
- while ((duration / optimalOffset) * 40 > timelineWrapperWidth) {
33
- optimalOffset = optimalOffset * 1.25;
34
- }
35
- return Math.ceil(optimalOffset);
36
- }
37
- exports.getBlockOffsetForZoomLevel = getBlockOffsetForZoomLevel;
package/dist/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './components';
package/dist/index.js DELETED
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./components"), exports);
@@ -1 +0,0 @@
1
- import '@testing-library/jest-dom';
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- // jest-dom adds custom jest matchers for asserting on DOM nodes.
4
- // allows you to do things like:
5
- // expect(element).toHaveTextContent(/react/i)
6
- // learn more: https://github.com/testing-library/jest-dom
7
- require("@testing-library/jest-dom");
@@ -1,9 +0,0 @@
1
- import { TimelineProps } from '../components/timeline';
2
- import './timeline.stories.custom.css';
3
- declare const _default: import("@storybook/csf").ComponentAnnotations<import("@storybook/react/dist/types-a5624094").R, import("@storybook/csf").Args>;
4
- export default _default;
5
- export declare const Default: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react/dist/types-a5624094").R, TimelineProps>;
6
- export declare const WithSelectedRange: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react/dist/types-a5624094").R, TimelineProps>;
7
- export declare const WithCustomClassName: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react/dist/types-a5624094").R, TimelineProps>;
8
- export declare const WithoutTimeBlocks: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react/dist/types-a5624094").R, TimelineProps>;
9
- export declare const Minimalist: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react/dist/types-a5624094").R, TimelineProps>;
@@ -1,60 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Minimalist = exports.WithoutTimeBlocks = exports.WithCustomClassName = exports.WithSelectedRange = exports.Default = void 0;
7
- const react_1 = __importDefault(require("react"));
8
- const timeline_1 = require("../components/timeline");
9
- const styled_components_1 = __importDefault(require("styled-components"));
10
- require("./timeline.stories.custom.css");
11
- const StyledTimeline = (0, styled_components_1.default)(timeline_1.Timeline) `
12
- .media-timeline-value-line {
13
- background-color: red;
14
- width: 5px;
15
- }
16
- `;
17
- exports.default = {
18
- title: 'Timeline',
19
- component: timeline_1.Timeline,
20
- argTypes: {
21
- onChange: { action: 'changed' },
22
- onRangeChange: { action: 'range changed' },
23
- },
24
- };
25
- const Template = (args) => (react_1.default.createElement(StyledTimeline, Object.assign({}, args)));
26
- exports.Default = Template.bind({});
27
- exports.Default.args = {
28
- duration: 305,
29
- value: 301,
30
- zoomLevel: 0,
31
- };
32
- exports.WithSelectedRange = Template.bind({});
33
- exports.WithSelectedRange.args = {
34
- duration: 305,
35
- value: 31,
36
- zoomLevel: 0,
37
- selectedRange: [20, 30],
38
- };
39
- exports.WithCustomClassName = Template.bind({});
40
- exports.WithCustomClassName.args = {
41
- duration: 305,
42
- value: 31,
43
- zoomLevel: 0,
44
- className: 'this-class-redefines-styles',
45
- };
46
- exports.WithoutTimeBlocks = Template.bind({});
47
- exports.WithoutTimeBlocks.args = {
48
- duration: 305,
49
- value: 31,
50
- zoomLevel: 0,
51
- withTimeBlocks: false,
52
- };
53
- exports.Minimalist = Template.bind({});
54
- exports.Minimalist.args = {
55
- duration: 305,
56
- value: 31,
57
- zoomLevel: 0,
58
- withTimeBlocks: false,
59
- className: 'minimalist',
60
- };