reacthub-pixitweenjs 0.2.4 → 0.2.6
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/.storybook/preview.tsx +6 -0
- package/CHANGELOG.md +27 -0
- package/README.md +1 -1
- package/build-storybook.log +79 -476
- package/package.json +29 -29
- package/src/components/PixiAnimatedSprite/PixiAnimatedSprite.tsx +51 -0
- package/src/components/PixiAnimatedSprite/index.ts +2 -0
- package/src/components/PixiAudioSprite/PixiAudioSprite.stories.tsx +61 -0
- package/src/components/PixiAudioSprite/PixiAudioSprite.tsx +202 -0
- package/src/components/PixiAudioSprite/index.ts +1 -0
- package/src/components/PixiGifSprite/PixiGifSprite.stories.tsx +135 -0
- package/src/components/PixiGifSprite/PixiGifSprite.tsx +372 -0
- package/src/components/PixiGifSprite/index.ts +2 -0
- package/src/components/PixiImageSprite/PixiImageSprite.stories.tsx +11 -0
- package/src/components/PixiImageSprite/PixiImageSprite.tsx +33 -70
- package/src/components/PixiSVGSprite/PixiSvgPathSprite.stories.tsx +137 -0
- package/src/components/PixiSVGSprite/PixiSvgPathSprite.tsx +346 -0
- package/src/components/PixiSVGSprite/index.ts +1 -0
- package/src/components/PixiTextSprite/PixiTextSprite.stories.tsx +176 -0
- package/src/components/PixiTextSprite/PixiTextSprite.tsx +540 -0
- package/src/components/PixiTextSprite/index.ts +1 -0
- package/src/components/PixiVideoSprite/PixiVideoSprite.stories.tsx +147 -0
- package/src/components/PixiVideoSprite/PixiVideoSprite.tsx +631 -0
- package/src/components/PixiVideoSprite/PixiVideoSpriteBackup.txt +755 -0
- package/src/components/PixiVideoSprite/index.ts +1 -0
- package/src/declare.module.ts +5 -0
- package/src/main.tsx +8 -7
- package/src/providers/GsapPixieContextProvider.tsx +102 -22
- package/src/reacthub-react-bindings.d.ts +27 -0
- package/src/stories/Installation.mdx +3 -3
- package/src/utils/AppStateProvider.tsx +18 -29
- package/src/utils/AppStateStage.tsx +1 -13
- package/src/utils/AppWrapper.tsx +4 -0
- package/src/utils/GsapAnim.tsx +1 -7
- package/src/utils/InteractionManager.tsx +36 -0
- package/src/utils/PixiStage.tsx +1 -5
- package/src/utils/PixiTransformer.tsx +165 -0
- package/src/utils/VideoSeekBar.tsx +35 -31
- package/src/utils/useDebounce.tsx +15 -0
- package/src/hooks/usePixiTransformer.tsx +0 -168
|
@@ -4,14 +4,16 @@ import {
|
|
|
4
4
|
SliderTrack,
|
|
5
5
|
SliderFilledTrack,
|
|
6
6
|
SliderThumb,
|
|
7
|
-
SliderMark,
|
|
8
7
|
Flex,
|
|
9
|
-
Icon,
|
|
10
8
|
Text,
|
|
11
9
|
Box,
|
|
12
10
|
Button,
|
|
13
11
|
} from "@chakra-ui/react";
|
|
14
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
GsapPixieContext,
|
|
14
|
+
Events,
|
|
15
|
+
} from "../providers/GsapPixieContextProvider";
|
|
16
|
+
import { emitCustomEvent } from "react-custom-events";
|
|
15
17
|
|
|
16
18
|
import { gsap } from "gsap";
|
|
17
19
|
import { Draggable } from "gsap/Draggable";
|
|
@@ -20,29 +22,23 @@ gsap.registerPlugin(Draggable);
|
|
|
20
22
|
|
|
21
23
|
export const VideoSeekBar: React.FC = () => {
|
|
22
24
|
const rafRef = React.useRef<number>();
|
|
23
|
-
const sliderRef = React.useRef<HTMLDivElement>(null);
|
|
24
25
|
const sliderThumbRef = React.useRef<HTMLDivElement>(null);
|
|
25
|
-
const sliderProgressRef = React.useRef<HTMLDivElement>(null);
|
|
26
26
|
const {
|
|
27
27
|
tl: timeline,
|
|
28
28
|
playerTimeRef,
|
|
29
29
|
handlePlay,
|
|
30
30
|
handlePause,
|
|
31
|
-
|
|
32
|
-
handleSeek,
|
|
31
|
+
handleSeekTest,
|
|
33
32
|
handleRestart,
|
|
34
|
-
|
|
33
|
+
totalDuration: duration,
|
|
35
34
|
} = React.useContext(GsapPixieContext);
|
|
36
35
|
|
|
37
36
|
/// state
|
|
38
37
|
const [time, setTime] = React.useState<number>(0);
|
|
39
|
-
const [duration, setDuration] = React.useState<number>(0);
|
|
40
|
-
|
|
41
38
|
const totalVideoSeconds = 20;
|
|
42
39
|
|
|
43
|
-
const animate = (
|
|
40
|
+
const animate = () => {
|
|
44
41
|
/// console.log("totalDuration", timeline.current.totalDuration());
|
|
45
|
-
setDuration(timeline.current.totalDuration());
|
|
46
42
|
if (playerTimeRef && playerTimeRef.current) {
|
|
47
43
|
setTime(playerTimeRef.current);
|
|
48
44
|
}
|
|
@@ -55,31 +51,39 @@ export const VideoSeekBar: React.FC = () => {
|
|
|
55
51
|
}, []); // Make sure the effect runs only once
|
|
56
52
|
|
|
57
53
|
const handleOnSliderChange = (value: number) => {
|
|
54
|
+
console.log("onslider change", value);
|
|
58
55
|
const nTotSeconds =
|
|
59
56
|
totalVideoSeconds && totalVideoSeconds > 0 ? totalVideoSeconds : 1;
|
|
60
57
|
const progress = value / nTotSeconds;
|
|
61
58
|
console.log("progressbar", value, progress);
|
|
59
|
+
|
|
62
60
|
playerTimeRef.current = value;
|
|
63
|
-
//
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
// handleSeek(value);
|
|
62
|
+
// // @ts-ignore
|
|
63
|
+
timeline && timeline.current.progress(progress);
|
|
64
|
+
// timeline && timeline.current.pause();
|
|
65
|
+
// gsap.set(sliderProgressRef.current!, {
|
|
66
|
+
// scaleX: progress,
|
|
67
|
+
// });
|
|
68
68
|
};
|
|
69
|
-
const handleOnSliderChangeStart = (value: number) => {};
|
|
70
|
-
const handleOnSliderChangeEnd = (value: number) => {};
|
|
71
69
|
|
|
72
|
-
/**
|
|
70
|
+
/** on slider start
|
|
71
|
+
* 1. pause the timeline
|
|
72
|
+
* 2. trigger custom event isDraggingStart
|
|
73
|
+
*/
|
|
74
|
+
const handleOnSliderChangeStart = () => {
|
|
75
|
+
// trigger custom event and pause the timeline
|
|
76
|
+
emitCustomEvent(Events.DRAGGING_START);
|
|
77
|
+
timeline && timeline.current.pause();
|
|
78
|
+
};
|
|
73
79
|
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
[totalVideoSeconds],
|
|
82
|
-
);
|
|
80
|
+
const handleOnSliderChangeEnd = () => {
|
|
81
|
+
// trigger custom event and pause the timeline
|
|
82
|
+
emitCustomEvent(Events.DRAGGING_END);
|
|
83
|
+
timeline && timeline.current.pause();
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/** Create Draggable for the Gsap Player */
|
|
83
87
|
|
|
84
88
|
return (
|
|
85
89
|
<Flex flexDir={"column"}>
|
|
@@ -87,7 +91,7 @@ export const VideoSeekBar: React.FC = () => {
|
|
|
87
91
|
<Button onClick={handleRestart}>Play</Button>
|
|
88
92
|
<Button onClick={handlePause}>Pause</Button>
|
|
89
93
|
<Button onClick={handlePlay}>Resume</Button>
|
|
90
|
-
<Button onClick={
|
|
94
|
+
<Button onClick={handleSeekTest}>Seek (4:00)</Button>
|
|
91
95
|
</Box>
|
|
92
96
|
<Flex px={1} mt={2}>
|
|
93
97
|
<Slider
|
|
@@ -95,7 +99,7 @@ export const VideoSeekBar: React.FC = () => {
|
|
|
95
99
|
data-testid="sliderthumb"
|
|
96
100
|
value={playerTimeRef.current || 0}
|
|
97
101
|
min={0}
|
|
98
|
-
max={
|
|
102
|
+
max={10}
|
|
99
103
|
step={0.1}
|
|
100
104
|
onChange={handleOnSliderChange}
|
|
101
105
|
onChangeStart={handleOnSliderChangeStart}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
export function useDebounce<T>(value: T, delay?: number): T {
|
|
4
|
+
const [debouncedValue, setDebouncedValue] = useState<T>(value);
|
|
5
|
+
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
const timer = setTimeout(() => setDebouncedValue(value), delay || 500);
|
|
8
|
+
|
|
9
|
+
return () => {
|
|
10
|
+
clearTimeout(timer);
|
|
11
|
+
};
|
|
12
|
+
}, [value, delay]);
|
|
13
|
+
|
|
14
|
+
return debouncedValue;
|
|
15
|
+
}
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import { Transformer } from "@pixi-essentials/transformer";
|
|
2
|
-
import * as PIXI from "pixi.js";
|
|
3
|
-
import { useApp } from "@pixi/react";
|
|
4
|
-
import * as React from "react";
|
|
5
|
-
import { useEffect, useRef, useCallback } from "react";
|
|
6
|
-
import { Transformation } from "../types/transformation";
|
|
7
|
-
// @ts-ignore
|
|
8
|
-
import has from "lodash/has";
|
|
9
|
-
|
|
10
|
-
const colorYellow = PIXI.utils.string2hex("#F3C409");
|
|
11
|
-
const anchorFill = PIXI.utils.string2hex("#F3C409");
|
|
12
|
-
|
|
13
|
-
interface Events {
|
|
14
|
-
dblclick?: (e: any) => void;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface Props {
|
|
18
|
-
uniqueId?: string;
|
|
19
|
-
onTransformEnd?: (data: {
|
|
20
|
-
uniqueId: string;
|
|
21
|
-
transformation: Transformation;
|
|
22
|
-
}) => void;
|
|
23
|
-
events?: Events;
|
|
24
|
-
mouseoverEvent?: (flag: boolean) => void;
|
|
25
|
-
setDragging?: (flag: boolean) => void;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export const usePixiTransformer = ({
|
|
29
|
-
uniqueId = "",
|
|
30
|
-
onTransformEnd,
|
|
31
|
-
events = {},
|
|
32
|
-
mouseoverEvent = (f) => f,
|
|
33
|
-
setDragging = (f) => f,
|
|
34
|
-
}: Props) => {
|
|
35
|
-
const [isDragging, setIsDragging] = React.useState(false);
|
|
36
|
-
const PixiTransformer = React.useRef<PIXI.Container>(null);
|
|
37
|
-
const mounted = React.useRef(false);
|
|
38
|
-
const app = useApp();
|
|
39
|
-
const transformerRef = useRef<Transformer>(null);
|
|
40
|
-
const parentRef = useRef<PIXI.Container>(null);
|
|
41
|
-
|
|
42
|
-
useEffect(() => {
|
|
43
|
-
mounted.current = true;
|
|
44
|
-
return () => {
|
|
45
|
-
mounted.current = false;
|
|
46
|
-
if (transformerRef.current) {
|
|
47
|
-
parentRef.current?.removeChild(transformerRef.current);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
}, []);
|
|
51
|
-
|
|
52
|
-
const transformChange = useCallback(() => {
|
|
53
|
-
setIsDragging(true);
|
|
54
|
-
setDragging(true);
|
|
55
|
-
}, []);
|
|
56
|
-
|
|
57
|
-
const transformCommit = useCallback(() => {
|
|
58
|
-
if (PixiTransformer.current === null) return;
|
|
59
|
-
const x = PixiTransformer.current.x;
|
|
60
|
-
const y = PixiTransformer.current.y;
|
|
61
|
-
const width = PixiTransformer.current.width;
|
|
62
|
-
const height = PixiTransformer.current.height;
|
|
63
|
-
const rotate = PixiTransformer.current.rotation;
|
|
64
|
-
const scale: [number, number] = [
|
|
65
|
-
PixiTransformer.current.scale.x,
|
|
66
|
-
PixiTransformer.current.scale.y,
|
|
67
|
-
];
|
|
68
|
-
if (onTransformEnd) {
|
|
69
|
-
onTransformEnd({
|
|
70
|
-
uniqueId,
|
|
71
|
-
transformation: {
|
|
72
|
-
x: Math.round(x),
|
|
73
|
-
y: Math.round(y),
|
|
74
|
-
width: Math.round(Math.max(5, width)),
|
|
75
|
-
height: Math.round(Math.max(5, height)),
|
|
76
|
-
rotate: Math.round(rotate),
|
|
77
|
-
scale: scale,
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
setIsDragging(false);
|
|
82
|
-
setDragging(false);
|
|
83
|
-
}, []);
|
|
84
|
-
|
|
85
|
-
const handleOnDblClick = useCallback((e: any) => {
|
|
86
|
-
if (events && has(events, "dblclick") && events.dblclick) {
|
|
87
|
-
events.dblclick(e);
|
|
88
|
-
}
|
|
89
|
-
}, []);
|
|
90
|
-
|
|
91
|
-
const handleOnMouseOver = useCallback(
|
|
92
|
-
(msevent: any) => {
|
|
93
|
-
if (mouseoverEvent) {
|
|
94
|
-
mouseoverEvent(true);
|
|
95
|
-
}
|
|
96
|
-
},
|
|
97
|
-
[mouseoverEvent],
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
const handleOnMouseOut = useCallback(
|
|
101
|
-
(msevent: any) => {
|
|
102
|
-
if (mouseoverEvent) {
|
|
103
|
-
mouseoverEvent(false);
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
[mouseoverEvent],
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
const handleTransformer = useCallback(
|
|
110
|
-
(node: PIXI.Container, parentNode: PIXI.Container) => {
|
|
111
|
-
const isEnabled = true;
|
|
112
|
-
// @ts-ignore
|
|
113
|
-
PixiTransformer.current = node;
|
|
114
|
-
const transformer = new Transformer({
|
|
115
|
-
rotateEnabled: isEnabled,
|
|
116
|
-
boxRotationEnabled: isEnabled,
|
|
117
|
-
boxScalingEnabled: isEnabled,
|
|
118
|
-
scaleEnabled: isEnabled,
|
|
119
|
-
group: [node],
|
|
120
|
-
wireframeStyle: {
|
|
121
|
-
thickness: 2,
|
|
122
|
-
color: anchorFill,
|
|
123
|
-
},
|
|
124
|
-
lockAspectRatio: true,
|
|
125
|
-
handleStyle: {
|
|
126
|
-
// color: colorYellow,
|
|
127
|
-
outlineColor: colorYellow,
|
|
128
|
-
shape: "circle",
|
|
129
|
-
radius: 10,
|
|
130
|
-
},
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
// transformer.addListener("transformchange", transformChange);
|
|
134
|
-
// @ts-ignore
|
|
135
|
-
transformer.addListener("transformcommit", transformCommit);
|
|
136
|
-
// transformer.addListener("dblclick", (evt) => {
|
|
137
|
-
// handleOnDblClick(evt);
|
|
138
|
-
// });
|
|
139
|
-
// transformer.on("mouseover", () => {
|
|
140
|
-
// handleOnMouseOver(true);
|
|
141
|
-
// });
|
|
142
|
-
// transformer.on("mouseout", () => {
|
|
143
|
-
// handleOnMouseOut(false);
|
|
144
|
-
// });
|
|
145
|
-
// @ts-ignore
|
|
146
|
-
transformerRef.current = transformer;
|
|
147
|
-
// @ts-ignore
|
|
148
|
-
parentRef.current = parentNode;
|
|
149
|
-
parentRef.current.addChild(transformerRef.current);
|
|
150
|
-
},
|
|
151
|
-
[
|
|
152
|
-
transformCommit,
|
|
153
|
-
transformChange,
|
|
154
|
-
handleOnMouseOver,
|
|
155
|
-
handleOnMouseOut,
|
|
156
|
-
handleOnDblClick,
|
|
157
|
-
],
|
|
158
|
-
);
|
|
159
|
-
|
|
160
|
-
const removeTransformer = useCallback(() => {
|
|
161
|
-
if (transformerRef.current) {
|
|
162
|
-
// @ts-ignore
|
|
163
|
-
parentRef.current.removeChild(transformerRef.current);
|
|
164
|
-
}
|
|
165
|
-
}, []);
|
|
166
|
-
|
|
167
|
-
return { handleTransformer, removeTransformer, isDragging };
|
|
168
|
-
};
|