@ldelia/react-media 0.2.6 → 0.2.7

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.
@@ -46,6 +46,9 @@ const TimelineContainer = styled_components_1.default.div `
46
46
  const TimelineWrapper = styled_components_1.default.div `
47
47
  position: absolute;
48
48
  height: 100%;
49
+ display: flex;
50
+ flex-direction: row;
51
+ align-items: center;
49
52
  `;
50
53
  exports.ZoomContext = react_1.default.createContext({
51
54
  blockOffset: 0,
@@ -1,12 +1,34 @@
1
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
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
5
28
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const react_1 = __importDefault(require("react"));
29
+ const react_1 = __importStar(require("react"));
7
30
  const styled_components_1 = __importDefault(require("styled-components"));
8
31
  const index_1 = require("./index");
9
- const react_2 = require("react");
10
32
  const utils_1 = require("./utils/utils");
11
33
  const OverlayCanvas = styled_components_1.default.canvas `
12
34
  position: absolute;
@@ -16,17 +38,28 @@ const OverlayCanvas = styled_components_1.default.canvas `
16
38
  height: 100%;
17
39
  color: #c9c9c9;
18
40
  `;
41
+ const PreValueLine = styled_components_1.default.span `
42
+ position: absolute;
43
+ left: 0;
44
+ height: 100%;
45
+ `;
19
46
  const ValueLine = styled_components_1.default.span `
20
47
  position: absolute;
21
48
  width: 1px;
22
49
  height: 100%;
23
50
  background-color: #575757;
24
51
  `;
52
+ const PostValueLine = styled_components_1.default.span `
53
+ position: absolute;
54
+ height: 100%;
55
+ `;
25
56
  const VaLueLineCanvas = ({ blockStartingTimes = [], value, }) => {
26
- const canvasRef = (0, react_2.useRef)(null);
27
- const valueLineRef = (0, react_2.useRef)(null);
28
- const zoomContextValue = (0, react_2.useContext)(index_1.ZoomContext);
29
- const showBlocks = (0, react_2.useCallback)((canvas) => {
57
+ const canvasRef = (0, react_1.useRef)(null);
58
+ const preValueLineRef = (0, react_1.useRef)(null);
59
+ const valueLineRef = (0, react_1.useRef)(null);
60
+ const postValueLineRef = (0, react_1.useRef)(null);
61
+ const zoomContextValue = (0, react_1.useContext)(index_1.ZoomContext);
62
+ const showBlocks = (0, react_1.useCallback)((canvas) => {
30
63
  const blockHeight = 20;
31
64
  const context = canvas.getContext('2d');
32
65
  for (const blockStartingTime of blockStartingTimes) {
@@ -43,18 +76,25 @@ const VaLueLineCanvas = ({ blockStartingTimes = [], value, }) => {
43
76
  context.stroke();
44
77
  }
45
78
  }, [blockStartingTimes, zoomContextValue]);
46
- const showValueLine = (0, react_2.useCallback)(() => {
47
- const linePosition = (0, utils_1.secondsToPixel)(zoomContextValue, value);
79
+ const showValueLine = (0, react_1.useCallback)(() => {
80
+ const canvas = canvasRef.current;
81
+ const preValueLineElement = preValueLineRef.current;
48
82
  const valueLineElement = valueLineRef.current;
49
- const elementWidthCSSProperty = window
50
- .getComputedStyle(valueLineElement)
51
- .getPropertyValue('width')
52
- .replace(/[^-\d]/g, '');
53
- const elementWidth = parseInt(elementWidthCSSProperty);
54
- const linePositionAtValueLineMiddle = linePosition - elementWidth / 2;
55
- valueLineElement.style.left = linePositionAtValueLineMiddle + 'px';
83
+ const postValueLineElement = postValueLineRef.current;
84
+ const valueLineWidth = (0, utils_1.getComputedElementWidth)(valueLineElement);
85
+ const linePosition = (0, utils_1.secondsToPixel)(zoomContextValue, value);
86
+ const valueLinePositionBeginningConsideringWidth = linePosition - valueLineWidth / 2;
87
+ // configure preValueLineElement
88
+ preValueLineElement.style.width = (0, utils_1.numberToPxString)(valueLinePositionBeginningConsideringWidth);
89
+ // configure valueLineElement
90
+ valueLineElement.style.left = (0, utils_1.numberToPxString)(valueLinePositionBeginningConsideringWidth);
91
+ // configure postValueLineElement
92
+ const postValueLinePosition = valueLinePositionBeginningConsideringWidth + valueLineWidth;
93
+ const postValueLineWidth = canvas.width - postValueLinePosition;
94
+ postValueLineElement.style.left = (0, utils_1.numberToPxString)(postValueLinePosition);
95
+ postValueLineElement.style.width = (0, utils_1.numberToPxString)(postValueLineWidth);
56
96
  }, [value, zoomContextValue]);
57
- (0, react_2.useEffect)(() => {
97
+ (0, react_1.useEffect)(() => {
58
98
  const canvas = canvasRef.current;
59
99
  // https://stackoverflow.com/questions/8696631/canvas-drawings-like-lines-are-blurry
60
100
  canvas.width = canvas.offsetWidth;
@@ -64,6 +104,8 @@ const VaLueLineCanvas = ({ blockStartingTimes = [], value, }) => {
64
104
  }, [showBlocks, showValueLine]);
65
105
  return (react_1.default.createElement(react_1.default.Fragment, null,
66
106
  react_1.default.createElement(OverlayCanvas, { ref: canvasRef, className: 'media-timeline-value-line-canvas' }),
67
- react_1.default.createElement(ValueLine, { ref: valueLineRef, className: 'media-timeline-value-line' })));
107
+ react_1.default.createElement(PreValueLine, { ref: preValueLineRef, className: 'media-timeline-pre-value-line' }),
108
+ react_1.default.createElement(ValueLine, { ref: valueLineRef, className: 'media-timeline-value-line' }),
109
+ react_1.default.createElement(PostValueLine, { ref: postValueLineRef, className: 'media-timeline-post-value-line' })));
68
110
  };
69
111
  exports.default = VaLueLineCanvas;
@@ -1,3 +1,5 @@
1
1
  import { ZoomContextType } from '../index';
2
2
  export declare const secondsToPixel: (zoomContextValue: ZoomContextType, seconds: number) => number;
3
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;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pixelToSeconds = exports.secondsToPixel = void 0;
3
+ exports.numberToPxString = exports.getComputedElementWidth = exports.pixelToSeconds = exports.secondsToPixel = void 0;
4
4
  const secondsToPixel = (zoomContextValue, seconds) => {
5
5
  return zoomContextValue.pixelsInSecond * seconds;
6
6
  };
@@ -10,3 +10,15 @@ const pixelToSeconds = (zoomContextValue, pixel) => {
10
10
  return Math.round((seconds + Number.EPSILON) * 100) / 100;
11
11
  };
12
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;
@@ -1,9 +1,9 @@
1
1
  import { TimelineProps } from '../components/timeline';
2
- import { Meta } from '@storybook/react';
3
2
  import './timeline.stories.custom.css';
4
- declare const _default: Meta;
3
+ declare const _default: import("@storybook/types").ComponentAnnotations<import("@storybook/react/dist/types-bf5e6555").R, import("@storybook/types").Args>;
5
4
  export default _default;
6
- export declare const Default: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, TimelineProps>;
7
- export declare const WithSelectedRange: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, TimelineProps>;
8
- export declare const WithCustomClassName: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, TimelineProps>;
9
- export declare const WithOutTimeBlocks: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, TimelineProps>;
5
+ export declare const Default: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-bf5e6555").R, TimelineProps>;
6
+ export declare const WithSelectedRange: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-bf5e6555").R, TimelineProps>;
7
+ export declare const WithCustomClassName: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-bf5e6555").R, TimelineProps>;
8
+ export declare const WithoutTimeBlocks: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-bf5e6555").R, TimelineProps>;
9
+ export declare const Minimalist: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-bf5e6555").R, TimelineProps>;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.WithOutTimeBlocks = exports.WithCustomClassName = exports.WithSelectedRange = exports.Default = void 0;
6
+ exports.Minimalist = exports.WithoutTimeBlocks = exports.WithCustomClassName = exports.WithSelectedRange = exports.Default = void 0;
7
7
  const react_1 = __importDefault(require("react"));
8
8
  const timeline_1 = require("../components/timeline");
9
9
  const styled_components_1 = __importDefault(require("styled-components"));
@@ -41,12 +41,20 @@ exports.WithCustomClassName.args = {
41
41
  duration: 305,
42
42
  value: 31,
43
43
  zoomLevel: 0,
44
- className: 'this-class-redefines-values',
44
+ className: 'this-class-redefines-styles',
45
45
  };
46
- exports.WithOutTimeBlocks = Template.bind({});
47
- exports.WithOutTimeBlocks.args = {
46
+ exports.WithoutTimeBlocks = Template.bind({});
47
+ exports.WithoutTimeBlocks.args = {
48
48
  duration: 305,
49
49
  value: 31,
50
50
  zoomLevel: 0,
51
51
  withTimeBlocks: false,
52
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
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ldelia/react-media",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "description": "A React components collection for media-related features.",
5
5
  "private": false,
6
6
  "keywords": [
@@ -18,6 +18,9 @@ const TimelineContainer = styled.div`
18
18
  const TimelineWrapper = styled.div`
19
19
  position: absolute;
20
20
  height: 100%;
21
+ display: flex;
22
+ flex-direction: row;
23
+ align-items: center;
21
24
  `;
22
25
 
23
26
  export interface TimelineProps {
@@ -1,9 +1,12 @@
1
- import React from 'react';
1
+ import React, { useCallback, useContext, useEffect, useRef } from 'react';
2
2
  import styled from 'styled-components';
3
3
 
4
4
  import { ZoomContext, ZoomContextType } from './index';
5
- import { useCallback, useContext, useEffect, useRef } from 'react';
6
- import { secondsToPixel } from './utils/utils';
5
+ import {
6
+ getComputedElementWidth,
7
+ numberToPxString,
8
+ secondsToPixel,
9
+ } from './utils/utils';
7
10
 
8
11
  export interface VaLueLineCanvasProps {
9
12
  blockStartingTimes: number[];
@@ -18,6 +21,13 @@ const OverlayCanvas = styled.canvas`
18
21
  height: 100%;
19
22
  color: #c9c9c9;
20
23
  `;
24
+
25
+ const PreValueLine = styled.span`
26
+ position: absolute;
27
+ left: 0;
28
+ height: 100%;
29
+ `;
30
+
21
31
  const ValueLine = styled.span`
22
32
  position: absolute;
23
33
  width: 1px;
@@ -25,12 +35,21 @@ const ValueLine = styled.span`
25
35
  background-color: #575757;
26
36
  `;
27
37
 
38
+ const PostValueLine = styled.span`
39
+ position: absolute;
40
+ height: 100%;
41
+ `;
42
+
28
43
  const VaLueLineCanvas: React.FC<VaLueLineCanvasProps> = ({
29
44
  blockStartingTimes = [],
30
45
  value,
31
46
  }) => {
32
47
  const canvasRef = useRef(null);
48
+
49
+ const preValueLineRef = useRef(null);
33
50
  const valueLineRef = useRef(null);
51
+ const postValueLineRef = useRef(null);
52
+
34
53
  const zoomContextValue: ZoomContextType = useContext(ZoomContext);
35
54
 
36
55
  const showBlocks = useCallback(
@@ -61,17 +80,33 @@ const VaLueLineCanvas: React.FC<VaLueLineCanvasProps> = ({
61
80
  );
62
81
 
63
82
  const showValueLine = useCallback(() => {
64
- const linePosition: number = secondsToPixel(zoomContextValue, value);
83
+ const canvas: HTMLCanvasElement = canvasRef.current!;
65
84
 
85
+ const preValueLineElement: HTMLElement = preValueLineRef.current!;
66
86
  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';
87
+ const postValueLineElement: HTMLElement = postValueLineRef.current!;
88
+
89
+ const valueLineWidth: number = getComputedElementWidth(valueLineElement);
90
+ const linePosition: number = secondsToPixel(zoomContextValue, value);
91
+ const valueLinePositionBeginningConsideringWidth: number =
92
+ linePosition - valueLineWidth / 2;
93
+
94
+ // configure preValueLineElement
95
+ preValueLineElement.style.width = numberToPxString(
96
+ valueLinePositionBeginningConsideringWidth,
97
+ );
98
+
99
+ // configure valueLineElement
100
+ valueLineElement.style.left = numberToPxString(
101
+ valueLinePositionBeginningConsideringWidth,
102
+ );
103
+
104
+ // configure postValueLineElement
105
+ const postValueLinePosition =
106
+ valueLinePositionBeginningConsideringWidth + valueLineWidth;
107
+ const postValueLineWidth = canvas.width - postValueLinePosition;
108
+ postValueLineElement.style.left = numberToPxString(postValueLinePosition);
109
+ postValueLineElement.style.width = numberToPxString(postValueLineWidth);
75
110
  }, [value, zoomContextValue]);
76
111
 
77
112
  useEffect(() => {
@@ -91,10 +126,16 @@ const VaLueLineCanvas: React.FC<VaLueLineCanvasProps> = ({
91
126
  ref={canvasRef}
92
127
  className={'media-timeline-value-line-canvas'}
93
128
  />
94
- <ValueLine
95
- ref={valueLineRef}
96
- className={'media-timeline-value-line'}
97
- ></ValueLine>
129
+
130
+ <PreValueLine
131
+ ref={preValueLineRef}
132
+ className={'media-timeline-pre-value-line'}
133
+ />
134
+ <ValueLine ref={valueLineRef} className={'media-timeline-value-line'} />
135
+ <PostValueLine
136
+ ref={postValueLineRef}
137
+ className={'media-timeline-post-value-line'}
138
+ />
98
139
  </>
99
140
  );
100
141
  };
@@ -14,3 +14,15 @@ 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
+ };
@@ -1,3 +1,29 @@
1
- #storybook-root .this-class-redefines-values {
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-values',
48
+ className: 'this-class-redefines-styles',
49
49
  };
50
50
 
51
- export const WithOutTimeBlocks = Template.bind({});
52
- WithOutTimeBlocks.args = {
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
+ };