@ldelia/react-media 0.2.7 → 0.3.0

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 (105) hide show
  1. package/.storybook/main.js +25 -2
  2. package/config/env.js +104 -0
  3. package/config/getHttpsConfig.js +66 -0
  4. package/config/jest/babelTransform.js +29 -0
  5. package/config/jest/cssTransform.js +14 -0
  6. package/config/jest/fileTransform.js +40 -0
  7. package/config/modules.js +134 -0
  8. package/config/paths.js +77 -0
  9. package/config/webpack/persistentCache/createEnvironmentHash.js +9 -0
  10. package/config/webpack.config.js +755 -0
  11. package/config/webpackDevServer.config.js +127 -0
  12. package/dist/components/timeline/{RangeSelectorCanvas.js → RangeSelectorCanvas/RangeSelectorCanvas.js} +30 -8
  13. package/dist/components/timeline/Timeline.d.ts +0 -5
  14. package/dist/components/timeline/Timeline.js +32 -27
  15. package/dist/components/timeline/{TickTimeCollectionDisplay.js → TimelineCanvas/TickTimeCollectionDisplay.js} +2 -2
  16. package/dist/components/timeline/TimelineCanvas/TimelineCanvas.d.ts +7 -0
  17. package/dist/components/timeline/TimelineCanvas/TimelineCanvas.js +72 -0
  18. package/dist/components/timeline/TimelineCanvas/drawTimeBlocksOnCanvas.d.ts +2 -0
  19. package/dist/components/timeline/TimelineCanvas/drawTimeBlocksOnCanvas.js +32 -0
  20. package/dist/components/timeline/TimelineValue/TimelineValue.d.ts +7 -0
  21. package/dist/components/timeline/{VaLueLineCanvas.js → TimelineValue/TimelineValue.js} +8 -39
  22. package/dist/components/timeline/ZoomContext/ZoomContext.d.ts +7 -0
  23. package/dist/components/timeline/ZoomContext/ZoomContext.js +8 -0
  24. package/dist/components/timeline/utils/utils.d.ts +3 -1
  25. package/dist/components/timeline/utils/utils.js +14 -1
  26. package/dist/stories/timeline.stories.d.ts +6 -6
  27. package/package.json +126 -18
  28. package/scripts/build.js +217 -0
  29. package/scripts/start.js +154 -0
  30. package/scripts/test.js +52 -0
  31. package/src/components/__tests__/timeline/timeline.test.js +22 -0
  32. package/src/components/index.js +1 -0
  33. package/src/components/timeline/RangeSelectorCanvas/RangeSelectorCanvas.js +127 -0
  34. package/src/components/timeline/{RangeSelectorCanvas.tsx → RangeSelectorCanvas/RangeSelectorCanvas.tsx} +9 -11
  35. package/src/components/timeline/Timeline.js +77 -0
  36. package/src/components/timeline/Timeline.tsx +47 -37
  37. package/src/components/timeline/TimelineCanvas/TickTime.js +26 -0
  38. package/src/components/timeline/TimelineCanvas/TickTimeCollectionDisplay.js +19 -0
  39. package/src/components/timeline/{TickTimeCollectionDisplay.tsx → TimelineCanvas/TickTimeCollectionDisplay.tsx} +5 -5
  40. package/src/components/timeline/TimelineCanvas/TimelineCanvas.js +44 -0
  41. package/src/components/timeline/TimelineCanvas/TimelineCanvas.tsx +79 -0
  42. package/src/components/timeline/TimelineCanvas/drawTimeBlocksOnCanvas.js +28 -0
  43. package/src/components/timeline/TimelineCanvas/drawTimeBlocksOnCanvas.ts +43 -0
  44. package/src/components/timeline/TimelineValue/TimelineValue.js +50 -0
  45. package/src/components/timeline/{VaLueLineCanvas.tsx → TimelineValue/TimelineValue.tsx} +9 -64
  46. package/src/components/timeline/ZoomContext/ZoomContext.js +2 -0
  47. package/src/components/timeline/ZoomContext/ZoomContext.ts +10 -0
  48. package/src/components/timeline/constants.js +13 -0
  49. package/src/components/timeline/index.js +1 -0
  50. package/src/components/timeline/utils/utils.js +28 -0
  51. package/src/components/timeline/utils/utils.ts +22 -1
  52. package/src/index.js +1 -0
  53. package/src/react-app-env.d.ts +71 -1
  54. package/src/react-docgen-types.d.ts +37 -0
  55. package/src/setupTests.js +5 -0
  56. package/src/stories/timeline.stories.js +54 -0
  57. package/storybook-static/favicon.svg +1 -0
  58. package/storybook-static/index.html +173 -0
  59. package/storybook-static/index.json +1 -0
  60. package/storybook-static/nunito-sans-bold-italic.woff2 +0 -0
  61. package/storybook-static/nunito-sans-bold.woff2 +0 -0
  62. package/storybook-static/nunito-sans-italic.woff2 +0 -0
  63. package/storybook-static/nunito-sans-regular.woff2 +0 -0
  64. package/storybook-static/project.json +1 -0
  65. package/storybook-static/sb-addons/essentials-actions-3/manager-bundle.js +3 -0
  66. package/storybook-static/sb-addons/essentials-actions-3/manager-bundle.js.LEGAL.txt +0 -0
  67. package/storybook-static/sb-addons/essentials-backgrounds-4/manager-bundle.js +12 -0
  68. package/storybook-static/sb-addons/essentials-backgrounds-4/manager-bundle.js.LEGAL.txt +0 -0
  69. package/storybook-static/sb-addons/essentials-controls-2/manager-bundle.js +412 -0
  70. package/storybook-static/sb-addons/essentials-controls-2/manager-bundle.js.LEGAL.txt +0 -0
  71. package/storybook-static/sb-addons/essentials-measure-7/manager-bundle.js +3 -0
  72. package/storybook-static/sb-addons/essentials-measure-7/manager-bundle.js.LEGAL.txt +0 -0
  73. package/storybook-static/sb-addons/essentials-outline-8/manager-bundle.js +3 -0
  74. package/storybook-static/sb-addons/essentials-outline-8/manager-bundle.js.LEGAL.txt +0 -0
  75. package/storybook-static/sb-addons/essentials-toolbars-6/manager-bundle.js +3 -0
  76. package/storybook-static/sb-addons/essentials-toolbars-6/manager-bundle.js.LEGAL.txt +0 -0
  77. package/storybook-static/sb-addons/essentials-viewport-5/manager-bundle.js +3 -0
  78. package/storybook-static/sb-addons/essentials-viewport-5/manager-bundle.js.LEGAL.txt +0 -0
  79. package/storybook-static/sb-addons/links-1/manager-bundle.js +3 -0
  80. package/storybook-static/sb-addons/links-1/manager-bundle.js.LEGAL.txt +0 -0
  81. package/storybook-static/sb-addons/storybook-core-core-server-presets-0/common-manager-bundle.js +3 -0
  82. package/storybook-static/sb-addons/storybook-core-core-server-presets-0/common-manager-bundle.js.LEGAL.txt +0 -0
  83. package/storybook-static/sb-common-assets/favicon.svg +1 -0
  84. package/storybook-static/sb-common-assets/nunito-sans-bold-italic.woff2 +0 -0
  85. package/storybook-static/sb-common-assets/nunito-sans-bold.woff2 +0 -0
  86. package/storybook-static/sb-common-assets/nunito-sans-italic.woff2 +0 -0
  87. package/storybook-static/sb-common-assets/nunito-sans-regular.woff2 +0 -0
  88. package/storybook-static/sb-manager/globals-module-info.js +995 -0
  89. package/storybook-static/sb-manager/globals-runtime.js +53527 -0
  90. package/storybook-static/sb-manager/globals.js +48 -0
  91. package/storybook-static/sb-manager/runtime.js +11885 -0
  92. package/storybook-static/sb-preview/globals.js +33 -0
  93. package/storybook-static/sb-preview/runtime.js +9483 -0
  94. package/tsconfig.json +8 -7
  95. package/.storybook/main.ts +0 -18
  96. package/.storybook/preview.ts +0 -14
  97. package/dist/components/timeline/VaLueLineCanvas.d.ts +0 -7
  98. package/dist/reportWebVitals.d.ts +0 -3
  99. package/dist/reportWebVitals.js +0 -37
  100. package/src/reportWebVitals.ts +0 -15
  101. /package/dist/components/timeline/{RangeSelectorCanvas.d.ts → RangeSelectorCanvas/RangeSelectorCanvas.d.ts} +0 -0
  102. /package/dist/components/timeline/{TickTime.d.ts → TimelineCanvas/TickTime.d.ts} +0 -0
  103. /package/dist/components/timeline/{TickTime.js → TimelineCanvas/TickTime.js} +0 -0
  104. /package/dist/components/timeline/{TickTimeCollectionDisplay.d.ts → TimelineCanvas/TickTimeCollectionDisplay.d.ts} +0 -0
  105. /package/src/components/timeline/{TickTime.tsx → TimelineCanvas/TickTime.tsx} +0 -0
@@ -0,0 +1,127 @@
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const evalSourceMapMiddleware = require('react-dev-utils/evalSourceMapMiddleware');
5
+ const noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMiddleware');
6
+ const ignoredFiles = require('react-dev-utils/ignoredFiles');
7
+ const redirectServedPath = require('react-dev-utils/redirectServedPathMiddleware');
8
+ const paths = require('./paths');
9
+ const getHttpsConfig = require('./getHttpsConfig');
10
+
11
+ const host = process.env.HOST || '0.0.0.0';
12
+ const sockHost = process.env.WDS_SOCKET_HOST;
13
+ const sockPath = process.env.WDS_SOCKET_PATH; // default: '/ws'
14
+ const sockPort = process.env.WDS_SOCKET_PORT;
15
+
16
+ module.exports = function (proxy, allowedHost) {
17
+ const disableFirewall =
18
+ !proxy || process.env.DANGEROUSLY_DISABLE_HOST_CHECK === 'true';
19
+ return {
20
+ // WebpackDevServer 2.4.3 introduced a security fix that prevents remote
21
+ // websites from potentially accessing local content through DNS rebinding:
22
+ // https://github.com/webpack/webpack-dev-server/issues/887
23
+ // https://medium.com/webpack/webpack-dev-server-middleware-security-issues-1489d950874a
24
+ // However, it made several existing use cases such as development in cloud
25
+ // environment or subdomains in development significantly more complicated:
26
+ // https://github.com/facebook/create-react-app/issues/2271
27
+ // https://github.com/facebook/create-react-app/issues/2233
28
+ // While we're investigating better solutions, for now we will take a
29
+ // compromise. Since our WDS configuration only serves files in the `public`
30
+ // folder we won't consider accessing them a vulnerability. However, if you
31
+ // use the `proxy` feature, it gets more dangerous because it can expose
32
+ // remote code execution vulnerabilities in backends like Django and Rails.
33
+ // So we will disable the host check normally, but enable it if you have
34
+ // specified the `proxy` setting. Finally, we let you override it if you
35
+ // really know what you're doing with a special environment variable.
36
+ // Note: ["localhost", ".localhost"] will support subdomains - but we might
37
+ // want to allow setting the allowedHosts manually for more complex setups
38
+ allowedHosts: disableFirewall ? 'all' : [allowedHost],
39
+ headers: {
40
+ 'Access-Control-Allow-Origin': '*',
41
+ 'Access-Control-Allow-Methods': '*',
42
+ 'Access-Control-Allow-Headers': '*',
43
+ },
44
+ // Enable gzip compression of generated files.
45
+ compress: true,
46
+ static: {
47
+ // By default WebpackDevServer serves physical files from current directory
48
+ // in addition to all the virtual build products that it serves from memory.
49
+ // This is confusing because those files won’t automatically be available in
50
+ // production build folder unless we copy them. However, copying the whole
51
+ // project directory is dangerous because we may expose sensitive files.
52
+ // Instead, we establish a convention that only files in `public` directory
53
+ // get served. Our build script will copy `public` into the `build` folder.
54
+ // In `index.html`, you can get URL of `public` folder with %PUBLIC_URL%:
55
+ // <link rel="icon" href="%PUBLIC_URL%/favicon.ico">
56
+ // In JavaScript code, you can access it with `process.env.PUBLIC_URL`.
57
+ // Note that we only recommend to use `public` folder as an escape hatch
58
+ // for files like `favicon.ico`, `manifest.json`, and libraries that are
59
+ // for some reason broken when imported through webpack. If you just want to
60
+ // use an image, put it in `src` and `import` it from JavaScript instead.
61
+ directory: paths.appPublic,
62
+ publicPath: [paths.publicUrlOrPath],
63
+ // By default files from `contentBase` will not trigger a page reload.
64
+ watch: {
65
+ // Reportedly, this avoids CPU overload on some systems.
66
+ // https://github.com/facebook/create-react-app/issues/293
67
+ // src/node_modules is not ignored to support absolute imports
68
+ // https://github.com/facebook/create-react-app/issues/1065
69
+ ignored: ignoredFiles(paths.appSrc),
70
+ },
71
+ },
72
+ client: {
73
+ webSocketURL: {
74
+ // Enable custom sockjs pathname for websocket connection to hot reloading server.
75
+ // Enable custom sockjs hostname, pathname and port for websocket connection
76
+ // to hot reloading server.
77
+ hostname: sockHost,
78
+ pathname: sockPath,
79
+ port: sockPort,
80
+ },
81
+ overlay: {
82
+ errors: true,
83
+ warnings: false,
84
+ },
85
+ },
86
+ devMiddleware: {
87
+ // It is important to tell WebpackDevServer to use the same "publicPath" path as
88
+ // we specified in the webpack config. When homepage is '.', default to serving
89
+ // from the root.
90
+ // remove last slash so user can land on `/test` instead of `/test/`
91
+ publicPath: paths.publicUrlOrPath.slice(0, -1),
92
+ },
93
+
94
+ https: getHttpsConfig(),
95
+ host,
96
+ historyApiFallback: {
97
+ // Paths with dots should still use the history fallback.
98
+ // See https://github.com/facebook/create-react-app/issues/387.
99
+ disableDotRule: true,
100
+ index: paths.publicUrlOrPath,
101
+ },
102
+ // `proxy` is run between `before` and `after` `webpack-dev-server` hooks
103
+ proxy,
104
+ onBeforeSetupMiddleware(devServer) {
105
+ // Keep `evalSourceMapMiddleware`
106
+ // middlewares before `redirectServedPath` otherwise will not have any effect
107
+ // This lets us fetch source contents from webpack for the error overlay
108
+ devServer.app.use(evalSourceMapMiddleware(devServer));
109
+
110
+ if (fs.existsSync(paths.proxySetup)) {
111
+ // This registers user provided middleware for proxy reasons
112
+ require(paths.proxySetup)(devServer.app);
113
+ }
114
+ },
115
+ onAfterSetupMiddleware(devServer) {
116
+ // Redirect to `PUBLIC_URL` or `homepage` from `package.json` if url not match
117
+ devServer.app.use(redirectServedPath(paths.publicUrlOrPath));
118
+
119
+ // This service worker file is effectively a 'no-op' that will reset any
120
+ // previous service worker registered for the same host:port combination.
121
+ // We do this in development to avoid hitting the production cache if
122
+ // it used the same host and port.
123
+ // https://github.com/facebook/create-react-app/issues/2272#issuecomment-302832432
124
+ devServer.app.use(noopServiceWorkerMiddleware(paths.publicUrlOrPath));
125
+ },
126
+ };
127
+ };
@@ -1,13 +1,35 @@
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
- const index_1 = require("./index");
9
- const react_2 = require("react");
10
- const utils_1 = require("./utils/utils");
31
+ const ZoomContext_1 = require("../ZoomContext/ZoomContext");
32
+ const utils_1 = require("../utils/utils");
11
33
  const OverlayCanvas = styled_components_1.default.canvas `
12
34
  position: absolute;
13
35
  top: 0;
@@ -17,10 +39,10 @@ const OverlayCanvas = styled_components_1.default.canvas `
17
39
  color: cadetblue;
18
40
  `;
19
41
  const RangeSelectorCanvas = ({ selectedRange, onChange, onRangeChange, }) => {
20
- const canvasRef = (0, react_2.useRef)(null);
21
- const zoomContextValue = (0, react_2.useContext)(index_1.ZoomContext);
42
+ const canvasRef = (0, react_1.useRef)(null);
43
+ const zoomContextValue = (0, react_1.useContext)(ZoomContext_1.ZoomContext);
22
44
  let isSelectingRange = false;
23
- let selectedRangeInPixels = (0, react_2.useMemo)(() => [], []);
45
+ let selectedRangeInPixels = (0, react_1.useMemo)(() => [], []);
24
46
  if (selectedRange.length === 2) {
25
47
  selectedRangeInPixels = [
26
48
  (0, utils_1.secondsToPixel)(zoomContextValue, selectedRange[0]),
@@ -119,7 +141,7 @@ const RangeSelectorCanvas = ({ selectedRange, onChange, onRangeChange, }) => {
119
141
  ]);
120
142
  }
121
143
  };
122
- (0, react_2.useEffect)(() => {
144
+ (0, react_1.useEffect)(() => {
123
145
  const canvas = canvasRef.current;
124
146
  // https://stackoverflow.com/questions/8696631/canvas-drawings-like-lines-are-blurry
125
147
  canvas.width = canvas.offsetWidth;
@@ -9,9 +9,4 @@ export interface TimelineProps {
9
9
  onChange?: (value: number) => void;
10
10
  onRangeChange?: (value: number[]) => void;
11
11
  }
12
- export type ZoomContextType = {
13
- blockOffset: number;
14
- pixelsInSecond: number;
15
- };
16
- export declare const ZoomContext: React.Context<ZoomContextType>;
17
12
  export declare const Timeline: React.FC<TimelineProps>;
@@ -26,13 +26,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.Timeline = exports.ZoomContext = void 0;
29
+ exports.Timeline = void 0;
30
30
  const react_1 = __importStar(require("react"));
31
- const TickTimeCollectionDisplay_1 = __importDefault(require("./TickTimeCollectionDisplay"));
32
- const VaLueLineCanvas_1 = __importDefault(require("./VaLueLineCanvas"));
33
- const RangeSelectorCanvas_1 = __importDefault(require("./RangeSelectorCanvas"));
31
+ const TimelineCanvas_1 = __importDefault(require("./TimelineCanvas/TimelineCanvas"));
32
+ const RangeSelectorCanvas_1 = __importDefault(require("./RangeSelectorCanvas/RangeSelectorCanvas"));
34
33
  const constants_1 = require("./constants");
35
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");
36
38
  const TimelineContainer = styled_components_1.default.div `
37
39
  background-color: #f0f0f0;
38
40
  border: 1px solid #c9c9c9;
@@ -49,13 +51,16 @@ const TimelineWrapper = styled_components_1.default.div `
49
51
  display: flex;
50
52
  flex-direction: row;
51
53
  align-items: center;
54
+ overflow: hidden;
52
55
  `;
53
- exports.ZoomContext = react_1.default.createContext({
54
- blockOffset: 0,
55
- pixelsInSecond: 0,
56
- });
57
56
  const Timeline = ({ duration, value, zoomLevel = 0, selectedRange = [], withTimeBlocks = true, onChange = () => { }, onRangeChange = () => { }, className = '', }) => {
58
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
+ });
59
64
  let zoomLevelValue = zoomLevel ? zoomLevel : 0;
60
65
  if (zoomLevelValue < 0 || zoomLevelValue >= constants_1.zoomLevelConfigurations.length) {
61
66
  console.warn('Invalid value for property zoomLevel.');
@@ -75,28 +80,28 @@ const Timeline = ({ duration, value, zoomLevel = 0, selectedRange = [], withTime
75
80
  selectedRange = [];
76
81
  console.warn('The selected range is inconsistent.');
77
82
  }
78
- const zoomParams = (0, react_1.useMemo)(() => {
79
- return {
80
- blockOffset: constants_1.zoomLevelConfigurations[zoomLevelValue][0],
81
- pixelsInSecond: constants_1.zoomLevelConfigurations[zoomLevelValue][1],
82
- };
83
- }, [zoomLevelValue]);
84
- let blockStartingTimes = [0];
85
- const blockCounts = Math.ceil(duration / zoomParams.blockOffset);
86
- for (let i = 1; i < blockCounts; i++) {
87
- blockStartingTimes.push(blockStartingTimes[blockStartingTimes.length - 1] +
88
- zoomParams.blockOffset);
89
- }
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]);
90
93
  (0, react_1.useEffect)(() => {
91
94
  const timeLineWrapper = timeLineContainerRef.current;
92
- const scrollPosition = value * zoomParams.pixelsInSecond - 300;
95
+ const scrollPosition = value * zoomContextValue.pixelsInSecond - 300;
93
96
  timeLineWrapper.scrollLeft = Math.max(0, scrollPosition);
94
- }, [value, zoomParams]);
97
+ }, [duration, value, zoomContextValue]);
95
98
  return (react_1.default.createElement(TimelineContainer, { ref: timeLineContainerRef, className: className },
96
- react_1.default.createElement(TimelineWrapper, { style: { width: duration * zoomParams.pixelsInSecond + 'px' } },
97
- react_1.default.createElement(exports.ZoomContext.Provider, { value: zoomParams },
98
- react_1.default.createElement(VaLueLineCanvas_1.default, { blockStartingTimes: withTimeBlocks ? blockStartingTimes : [], value: value }),
99
- react_1.default.createElement(RangeSelectorCanvas_1.default, { selectedRange: selectedRange, onChange: onChange, onRangeChange: onRangeChange }),
100
- withTimeBlocks && (react_1.default.createElement(TickTimeCollectionDisplay_1.default, { tickTimes: blockStartingTimes }))))));
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 })))));
101
106
  };
102
107
  exports.Timeline = Timeline;
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const react_1 = __importDefault(require("react"));
7
7
  const styled_components_1 = __importDefault(require("styled-components"));
8
8
  const TickTime_1 = __importDefault(require("./TickTime"));
9
- const index_1 = require("./index");
9
+ const ZoomContext_1 = require("../ZoomContext/ZoomContext");
10
10
  const TickTimeCollectionDisplayContainer = styled_components_1.default.div `
11
11
  position: absolute;
12
12
  display: flex;
@@ -14,7 +14,7 @@ const TickTimeCollectionDisplayContainer = styled_components_1.default.div `
14
14
  height: 100%;
15
15
  `;
16
16
  const TickTimeCollectionDisplay = ({ tickTimes = [], }) => {
17
- return (react_1.default.createElement(index_1.ZoomContext.Consumer, null, (value) => {
17
+ return (react_1.default.createElement(ZoomContext_1.ZoomContext.Consumer, null, (value) => {
18
18
  return (react_1.default.createElement(TickTimeCollectionDisplayContainer, null, tickTimes.map((tickTimeValue, index) => {
19
19
  const leftPosition = tickTimeValue * value.pixelsInSecond + 'px';
20
20
  return (react_1.default.createElement(TickTime_1.default, { key: index, start: tickTimeValue, leftPosition: leftPosition }));
@@ -0,0 +1,7 @@
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;
@@ -0,0 +1,72 @@
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;
@@ -0,0 +1,2 @@
1
+ import { ZoomContextType } from '../ZoomContext/ZoomContext';
2
+ export declare const drawTimeBlocksOnCanvas: (canvas: HTMLCanvasElement, blockStartingTimes: number[], zoomContextValue: ZoomContextType) => void;
@@ -0,0 +1,32 @@
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;
@@ -0,0 +1,7 @@
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 {};
@@ -26,18 +26,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.TimelineValue = void 0;
29
30
  const react_1 = __importStar(require("react"));
30
31
  const styled_components_1 = __importDefault(require("styled-components"));
31
- const index_1 = require("./index");
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: #c9c9c9;
40
- `;
32
+ const utils_1 = require("../utils/utils");
33
+ const ZoomContext_1 = require("../ZoomContext/ZoomContext");
41
34
  const PreValueLine = styled_components_1.default.span `
42
35
  position: absolute;
43
36
  left: 0;
@@ -53,29 +46,11 @@ const PostValueLine = styled_components_1.default.span `
53
46
  position: absolute;
54
47
  height: 100%;
55
48
  `;
56
- const VaLueLineCanvas = ({ blockStartingTimes = [], value, }) => {
57
- const canvasRef = (0, react_1.useRef)(null);
49
+ const TimelineValue = ({ canvasRef, value }) => {
58
50
  const preValueLineRef = (0, react_1.useRef)(null);
59
51
  const valueLineRef = (0, react_1.useRef)(null);
60
52
  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) => {
63
- const blockHeight = 20;
64
- const context = canvas.getContext('2d');
65
- for (const blockStartingTime of blockStartingTimes) {
66
- const x0Pixel = (0, utils_1.secondsToPixel)(zoomContextValue, blockStartingTime);
67
- const x1Pixel = (0, utils_1.secondsToPixel)(zoomContextValue, blockStartingTime + zoomContextValue.blockOffset);
68
- context.beginPath();
69
- context.moveTo(x0Pixel, canvas.height);
70
- context.lineTo(x0Pixel, canvas.height - blockHeight);
71
- context.lineTo(x1Pixel, canvas.height - blockHeight);
72
- context.lineTo(x1Pixel, canvas.height);
73
- context.strokeStyle = window
74
- .getComputedStyle(canvas)
75
- .getPropertyValue('color');
76
- context.stroke();
77
- }
78
- }, [blockStartingTimes, zoomContextValue]);
53
+ const zoomContextValue = (0, react_1.useContext)(ZoomContext_1.ZoomContext);
79
54
  const showValueLine = (0, react_1.useCallback)(() => {
80
55
  const canvas = canvasRef.current;
81
56
  const preValueLineElement = preValueLineRef.current;
@@ -93,19 +68,13 @@ const VaLueLineCanvas = ({ blockStartingTimes = [], value, }) => {
93
68
  const postValueLineWidth = canvas.width - postValueLinePosition;
94
69
  postValueLineElement.style.left = (0, utils_1.numberToPxString)(postValueLinePosition);
95
70
  postValueLineElement.style.width = (0, utils_1.numberToPxString)(postValueLineWidth);
96
- }, [value, zoomContextValue]);
71
+ }, [canvasRef, value, zoomContextValue]);
97
72
  (0, react_1.useEffect)(() => {
98
- const canvas = canvasRef.current;
99
- // https://stackoverflow.com/questions/8696631/canvas-drawings-like-lines-are-blurry
100
- canvas.width = canvas.offsetWidth;
101
- canvas.height = canvas.offsetHeight;
102
- showBlocks(canvas);
103
73
  showValueLine();
104
- }, [showBlocks, showValueLine]);
74
+ }, [showValueLine]);
105
75
  return (react_1.default.createElement(react_1.default.Fragment, null,
106
- react_1.default.createElement(OverlayCanvas, { ref: canvasRef, className: 'media-timeline-value-line-canvas' }),
107
76
  react_1.default.createElement(PreValueLine, { ref: preValueLineRef, className: 'media-timeline-pre-value-line' }),
108
77
  react_1.default.createElement(ValueLine, { ref: valueLineRef, className: 'media-timeline-value-line' }),
109
78
  react_1.default.createElement(PostValueLine, { ref: postValueLineRef, className: 'media-timeline-post-value-line' })));
110
79
  };
111
- exports.default = VaLueLineCanvas;
80
+ exports.TimelineValue = TimelineValue;
@@ -0,0 +1,7 @@
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>;
@@ -0,0 +1,8 @@
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,5 +1,7 @@
1
- import { ZoomContextType } from '../index';
1
+ import { ZoomContextType } from '../ZoomContext/ZoomContext';
2
2
  export declare const secondsToPixel: (zoomContextValue: ZoomContextType, seconds: number) => number;
3
3
  export declare const pixelToSeconds: (zoomContextValue: ZoomContextType, pixel: number) => number;
4
4
  export declare const getComputedElementWidth: (element: HTMLElement) => number;
5
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,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.numberToPxString = exports.getComputedElementWidth = exports.pixelToSeconds = exports.secondsToPixel = void 0;
3
+ exports.getBlockOffsetForZoomLevel = exports.getTimelineWrapperWidth = exports.numberToPxString = exports.getComputedElementWidth = exports.pixelToSeconds = exports.secondsToPixel = void 0;
4
4
  const secondsToPixel = (zoomContextValue, seconds) => {
5
5
  return zoomContextValue.pixelsInSecond * seconds;
6
6
  };
@@ -22,3 +22,16 @@ const numberToPxString = (number) => {
22
22
  return `${number}px`;
23
23
  };
24
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;
@@ -1,9 +1,9 @@
1
1
  import { TimelineProps } from '../components/timeline';
2
2
  import './timeline.stories.custom.css';
3
- declare const _default: import("@storybook/types").ComponentAnnotations<import("@storybook/react/dist/types-bf5e6555").R, import("@storybook/types").Args>;
3
+ declare const _default: import("@storybook/csf").ComponentAnnotations<import("@storybook/react/dist/types-a5624094").R, import("@storybook/csf").Args>;
4
4
  export default _default;
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>;
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>;