@cyca/react-timeline-editor 0.2.4-alpha.5 → 0.2.5-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # react-timeline-editor
2
+
2
3
  `@cyca/react-timeline-editor` is a React-based component for quickly building timeline editing capabilities.
3
4
 
4
5
  This is a fork of the original [@xzdarcy/react-timeline-editor](https://github.com/xzdarcy/react-timeline-editor)
@@ -6,6 +7,7 @@ This is a fork of the original [@xzdarcy/react-timeline-editor](https://github.c
6
7
  It can be mainly used to build animation editors, video editors, etc.
7
8
 
8
9
  ## ✨ Features
10
+
9
11
  - 🛠 Supports drag and scale modes, with convenient control hooks.
10
12
  - 🔗 Provides grid snapping, auxiliary line snapping, and other interactive capabilities.
11
13
  - 🏷 Automatically recognizes action length and infinite scrolling.
@@ -13,6 +15,7 @@ It can be mainly used to build animation editors, video editors, etc.
13
15
  - ❌ Removed Runner from the original library.
14
16
 
15
17
  ## Changes from the original library
18
+
16
19
  - Replaced react-virtualized with @tanstack/virtual
17
20
  - Replaced Interact.js with @use-gesture/react
18
21
  - Uses React-19 as a base
@@ -26,15 +29,10 @@ npm install @cyca/react-timeline-editor
26
29
  ```
27
30
 
28
31
  ```js
29
- import React from 'react';
30
- import { Timeline } from '@cyca/react-timeline-editor';
32
+ import React from "react";
33
+ import { Timeline } from "@cyca/react-timeline-editor";
31
34
 
32
35
  export const TimelineEditor = () => {
33
- return (
34
- <Timeline
35
- editorData={[]}
36
- effects={{}}
37
- />
38
- )
39
- }
36
+ return <Timeline editorData={[]} effects={{}} />;
37
+ };
40
38
  ```
@@ -0,0 +1,52 @@
1
+ //#region src/interface/action.d.ts
2
+ /**
3
+ * Basic parameters of action
4
+ * @export
5
+ * @interface TimelineAction
6
+ */
7
+ interface TimelineAction {
8
+ /** Action id */
9
+ id: string;
10
+ /** Action start time */
11
+ start: number;
12
+ /** Action end time */
13
+ end: number;
14
+ /** Effect ID corresponding to the action */
15
+ effectId: string;
16
+ /** Whether the action is selected */
17
+ selected?: boolean;
18
+ /** Whether the action is resizable */
19
+ flexible?: boolean;
20
+ /** Whether the action is movable */
21
+ movable?: boolean;
22
+ /** Whether the action is disabled */
23
+ disable?: boolean;
24
+ /** Minimum start time limit for the action */
25
+ minStart?: number;
26
+ /** Maximum end time limit for the action */
27
+ maxEnd?: number;
28
+ }
29
+ /**
30
+ * Basic parameters of action row
31
+ * @export
32
+ * @interface TimelineRow
33
+ */
34
+ interface TimelineRow {
35
+ /** Action row id */
36
+ id: string;
37
+ /** List of actions in the row */
38
+ actions: TimelineAction[];
39
+ /** Custom row height. Used as expanded height when the row is collapsible. */
40
+ rowHeight?: number;
41
+ /** Collapsible row configuration. Rows without this option are fixed. */
42
+ collapsed?: {
43
+ /** Collapsed row height */height?: number; /** Whether this row is expanded when no collapsible row is focused */
44
+ expandedByDefault?: boolean;
45
+ };
46
+ /** Whether the row is selected */
47
+ selected?: boolean;
48
+ /** Extended class names of the row */
49
+ classNames?: string[];
50
+ }
51
+ //#endregion
52
+ export { TimelineRow as n, TimelineAction as t };
@@ -0,0 +1,52 @@
1
+ //#region src/interface/action.d.ts
2
+ /**
3
+ * Basic parameters of action
4
+ * @export
5
+ * @interface TimelineAction
6
+ */
7
+ interface TimelineAction {
8
+ /** Action id */
9
+ id: string;
10
+ /** Action start time */
11
+ start: number;
12
+ /** Action end time */
13
+ end: number;
14
+ /** Effect ID corresponding to the action */
15
+ effectId: string;
16
+ /** Whether the action is selected */
17
+ selected?: boolean;
18
+ /** Whether the action is resizable */
19
+ flexible?: boolean;
20
+ /** Whether the action is movable */
21
+ movable?: boolean;
22
+ /** Whether the action is disabled */
23
+ disable?: boolean;
24
+ /** Minimum start time limit for the action */
25
+ minStart?: number;
26
+ /** Maximum end time limit for the action */
27
+ maxEnd?: number;
28
+ }
29
+ /**
30
+ * Basic parameters of action row
31
+ * @export
32
+ * @interface TimelineRow
33
+ */
34
+ interface TimelineRow {
35
+ /** Action row id */
36
+ id: string;
37
+ /** List of actions in the row */
38
+ actions: TimelineAction[];
39
+ /** Custom row height. Used as expanded height when the row is collapsible. */
40
+ rowHeight?: number;
41
+ /** Collapsible row configuration. Rows without this option are fixed. */
42
+ collapsed?: {
43
+ /** Collapsed row height */height?: number; /** Whether this row is expanded when no collapsible row is focused */
44
+ expandedByDefault?: boolean;
45
+ };
46
+ /** Whether the row is selected */
47
+ selected?: boolean;
48
+ /** Extended class names of the row */
49
+ classNames?: string[];
50
+ }
51
+ //#endregion
52
+ export { TimelineRow as n, TimelineAction as t };
@@ -0,0 +1,111 @@
1
+ //#region src/interface/const.ts
2
+ const PREFIX = `timeline-editor`;
3
+ //#endregion
4
+ //#region src/utils/deal-data.ts
5
+ /** Convert time to pixels */
6
+ function parserTimeToPixel(data, param) {
7
+ const { startLeft, scale, scaleWidth } = param;
8
+ return startLeft + data / scale * scaleWidth;
9
+ }
10
+ /** Convert pixels to time */
11
+ function parserPixelToTime(data, param) {
12
+ const { startLeft, scale, scaleWidth } = param;
13
+ return (data - startLeft) / scaleWidth * scale;
14
+ }
15
+ /** Convert position + width to start + end */
16
+ function parserTransformToTime(data, param) {
17
+ const { left, width } = data;
18
+ return {
19
+ start: parserPixelToTime(left, param),
20
+ end: parserPixelToTime(left + width, param)
21
+ };
22
+ }
23
+ /** Convert start + end to position + width */
24
+ function parserTimeToTransform(data, param) {
25
+ const { start, end } = data;
26
+ const left = parserTimeToPixel(start, param);
27
+ return {
28
+ left,
29
+ width: parserTimeToPixel(end, param) - left
30
+ };
31
+ }
32
+ /** Get scale count based on data */
33
+ function getScaleCountByRows(data, param) {
34
+ let max = 0;
35
+ data.forEach((row) => {
36
+ row.actions.forEach((action) => {
37
+ max = Math.max(max, action.end);
38
+ });
39
+ });
40
+ return Math.ceil(max / param.scale) + (param.pad ?? 2);
41
+ }
42
+ /** Get current scale count based on time */
43
+ function getScaleCountByPixel(data, param) {
44
+ const { startLeft, scaleWidth } = param;
45
+ const count = Math.ceil((data - startLeft) / scaleWidth);
46
+ return Math.max(count + 2, param.scaleCount);
47
+ }
48
+ /** Get position set of all times for actions */
49
+ function parserActionsToPositions(actions, param) {
50
+ const positions = [];
51
+ actions.forEach((item) => {
52
+ positions.push({
53
+ value: parserTimeToPixel(item.start, param),
54
+ actionId: item.id
55
+ });
56
+ positions.push({
57
+ value: parserTimeToPixel(item.end, param),
58
+ actionId: item.id
59
+ });
60
+ });
61
+ return positions;
62
+ }
63
+ //#endregion
64
+ Object.defineProperty(exports, "PREFIX", {
65
+ enumerable: true,
66
+ get: function() {
67
+ return PREFIX;
68
+ }
69
+ });
70
+ Object.defineProperty(exports, "getScaleCountByPixel", {
71
+ enumerable: true,
72
+ get: function() {
73
+ return getScaleCountByPixel;
74
+ }
75
+ });
76
+ Object.defineProperty(exports, "getScaleCountByRows", {
77
+ enumerable: true,
78
+ get: function() {
79
+ return getScaleCountByRows;
80
+ }
81
+ });
82
+ Object.defineProperty(exports, "parserActionsToPositions", {
83
+ enumerable: true,
84
+ get: function() {
85
+ return parserActionsToPositions;
86
+ }
87
+ });
88
+ Object.defineProperty(exports, "parserPixelToTime", {
89
+ enumerable: true,
90
+ get: function() {
91
+ return parserPixelToTime;
92
+ }
93
+ });
94
+ Object.defineProperty(exports, "parserTimeToPixel", {
95
+ enumerable: true,
96
+ get: function() {
97
+ return parserTimeToPixel;
98
+ }
99
+ });
100
+ Object.defineProperty(exports, "parserTimeToTransform", {
101
+ enumerable: true,
102
+ get: function() {
103
+ return parserTimeToTransform;
104
+ }
105
+ });
106
+ Object.defineProperty(exports, "parserTransformToTime", {
107
+ enumerable: true,
108
+ get: function() {
109
+ return parserTransformToTime;
110
+ }
111
+ });
@@ -0,0 +1,64 @@
1
+ //#region src/interface/const.ts
2
+ const PREFIX = `timeline-editor`;
3
+ //#endregion
4
+ //#region src/utils/deal-data.ts
5
+ /** Convert time to pixels */
6
+ function parserTimeToPixel(data, param) {
7
+ const { startLeft, scale, scaleWidth } = param;
8
+ return startLeft + data / scale * scaleWidth;
9
+ }
10
+ /** Convert pixels to time */
11
+ function parserPixelToTime(data, param) {
12
+ const { startLeft, scale, scaleWidth } = param;
13
+ return (data - startLeft) / scaleWidth * scale;
14
+ }
15
+ /** Convert position + width to start + end */
16
+ function parserTransformToTime(data, param) {
17
+ const { left, width } = data;
18
+ return {
19
+ start: parserPixelToTime(left, param),
20
+ end: parserPixelToTime(left + width, param)
21
+ };
22
+ }
23
+ /** Convert start + end to position + width */
24
+ function parserTimeToTransform(data, param) {
25
+ const { start, end } = data;
26
+ const left = parserTimeToPixel(start, param);
27
+ return {
28
+ left,
29
+ width: parserTimeToPixel(end, param) - left
30
+ };
31
+ }
32
+ /** Get scale count based on data */
33
+ function getScaleCountByRows(data, param) {
34
+ let max = 0;
35
+ data.forEach((row) => {
36
+ row.actions.forEach((action) => {
37
+ max = Math.max(max, action.end);
38
+ });
39
+ });
40
+ return Math.ceil(max / param.scale) + (param.pad ?? 2);
41
+ }
42
+ /** Get current scale count based on time */
43
+ function getScaleCountByPixel(data, param) {
44
+ const { startLeft, scaleWidth } = param;
45
+ const count = Math.ceil((data - startLeft) / scaleWidth);
46
+ return Math.max(count + 2, param.scaleCount);
47
+ }
48
+ /** Get position set of all times for actions */
49
+ function parserActionsToPositions(actions, param) {
50
+ const positions = [];
51
+ actions.forEach((item) => {
52
+ positions.push({
53
+ value: parserTimeToPixel(item.start, param),
54
+ actionId: item.id
55
+ });
56
+ positions.push({
57
+ value: parserTimeToPixel(item.end, param),
58
+ actionId: item.id
59
+ });
60
+ });
61
+ return positions;
62
+ }
63
+ //#endregion
64
+ export { parserTimeToPixel as a, PREFIX as c, parserPixelToTime as i, getScaleCountByRows as n, parserTimeToTransform as o, parserActionsToPositions as r, parserTransformToTime as s, getScaleCountByPixel as t };