reacthub-pixitweenjs 0.2.2 → 0.2.4

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 (38) hide show
  1. package/.storybook/{main.js → main.ts} +9 -1
  2. package/.storybook/{preview.jsx → preview.tsx} +3 -7
  3. package/CHANGELOG.md +28 -0
  4. package/README.md +29 -80
  5. package/build-storybook.log +491 -0
  6. package/index.html +1 -1
  7. package/package.json +54 -19
  8. package/src/App.tsx +29 -0
  9. package/src/{stories/PixiImageSprite/PixiImageSprite.stories.js → components/PixiImageSprite/PixiImageSprite.stories.tsx} +25 -8
  10. package/src/components/PixiImageSprite/PixiImageSprite.tsx +346 -0
  11. package/src/components/PixiImageSprite/index.ts +1 -0
  12. package/src/hooks/usePixiTransformer.tsx +168 -0
  13. package/src/index.ts +3 -0
  14. package/src/providers/{GsapPixieContextProvider.jsx → GsapPixieContextProvider.tsx} +27 -24
  15. package/src/providers/index.ts +1 -0
  16. package/src/stories/Introduction.mdx +0 -99
  17. package/src/types/transformation.tsx +13 -0
  18. package/src/utils/AppStateProvider.tsx +70 -0
  19. package/src/utils/AppStateStage.tsx +27 -0
  20. package/src/utils/AppWrapper.tsx +43 -0
  21. package/src/utils/ContextBridge.tsx +25 -0
  22. package/src/{providers/GsapAnim.jsx → utils/GsapAnim.tsx} +35 -4
  23. package/src/utils/PixiStage.tsx +33 -0
  24. package/src/utils/VideoSeekBar.tsx +118 -0
  25. package/src/utils/useDeepEffect.tsx +23 -0
  26. package/src/vite-env.d.ts +1 -0
  27. package/tsconfig.json +37 -0
  28. package/tsconfig.node.json +10 -0
  29. package/{vite.config.js → vite.config.ts} +4 -2
  30. package/vitest.config.ts +11 -0
  31. package/src/App.jsx +0 -35
  32. package/src/index.js +0 -3
  33. package/src/providers/ContextBridge.jsx +0 -67
  34. package/src/providers/VideoSeekBar.jsx +0 -186
  35. package/src/providers/index.js +0 -3
  36. package/src/stories/PixiImageSprite/PixiImageSprite.jsx +0 -318
  37. package/src/stories/PixiImageSprite/index.js +0 -1
  38. /package/src/{main.jsx → main.tsx} +0 -0
@@ -0,0 +1,118 @@
1
+ import * as React from "react";
2
+ import {
3
+ Slider,
4
+ SliderTrack,
5
+ SliderFilledTrack,
6
+ SliderThumb,
7
+ SliderMark,
8
+ Flex,
9
+ Icon,
10
+ Text,
11
+ Box,
12
+ Button,
13
+ } from "@chakra-ui/react";
14
+ import { GsapPixieContext } from "../providers/GsapPixieContextProvider";
15
+
16
+ import { gsap } from "gsap";
17
+ import { Draggable } from "gsap/Draggable";
18
+
19
+ gsap.registerPlugin(Draggable);
20
+
21
+ export const VideoSeekBar: React.FC = () => {
22
+ const rafRef = React.useRef<number>();
23
+ const sliderRef = React.useRef<HTMLDivElement>(null);
24
+ const sliderThumbRef = React.useRef<HTMLDivElement>(null);
25
+ const sliderProgressRef = React.useRef<HTMLDivElement>(null);
26
+ const {
27
+ tl: timeline,
28
+ playerTimeRef,
29
+ handlePlay,
30
+ handlePause,
31
+ handleReset,
32
+ handleSeek,
33
+ handleRestart,
34
+ handleRepeat,
35
+ } = React.useContext(GsapPixieContext);
36
+
37
+ /// state
38
+ const [time, setTime] = React.useState<number>(0);
39
+ const [duration, setDuration] = React.useState<number>(0);
40
+
41
+ const totalVideoSeconds = 20;
42
+
43
+ const animate = (time: number) => {
44
+ /// console.log("totalDuration", timeline.current.totalDuration());
45
+ setDuration(timeline.current.totalDuration());
46
+ if (playerTimeRef && playerTimeRef.current) {
47
+ setTime(playerTimeRef.current);
48
+ }
49
+ rafRef.current = requestAnimationFrame(animate);
50
+ };
51
+
52
+ React.useEffect(() => {
53
+ rafRef.current = requestAnimationFrame(animate);
54
+ return () => cancelAnimationFrame(rafRef.current!);
55
+ }, []); // Make sure the effect runs only once
56
+
57
+ const handleOnSliderChange = (value: number) => {
58
+ const nTotSeconds =
59
+ totalVideoSeconds && totalVideoSeconds > 0 ? totalVideoSeconds : 1;
60
+ const progress = value / nTotSeconds;
61
+ console.log("progressbar", value, progress);
62
+ playerTimeRef.current = value;
63
+ // @ts-ignore
64
+ timeline && timeline.progress(progress);
65
+ gsap.set(sliderProgressRef.current!, {
66
+ scaleX: progress,
67
+ });
68
+ };
69
+ const handleOnSliderChangeStart = (value: number) => {};
70
+ const handleOnSliderChangeEnd = (value: number) => {};
71
+
72
+ /** Create Draggable for the Gsap Player */
73
+
74
+ const updateDrag = React.useCallback(
75
+ (x: number, maxX: number) => {
76
+ console.log("updatgeDrag running", x, maxX);
77
+ const currentTime = (x / maxX) * totalVideoSeconds;
78
+ const prog = x / sliderRef.current!.offsetWidth;
79
+ console.log("drage update", currentTime, prog);
80
+ },
81
+ [totalVideoSeconds],
82
+ );
83
+
84
+ return (
85
+ <Flex flexDir={"column"}>
86
+ <Box>
87
+ <Button onClick={handleRestart}>Play</Button>
88
+ <Button onClick={handlePause}>Pause</Button>
89
+ <Button onClick={handlePlay}>Resume</Button>
90
+ <Button onClick={handleSeek}>Seek (4:00)</Button>
91
+ </Box>
92
+ <Flex px={1} mt={2}>
93
+ <Slider
94
+ aria-label="slider-ex-1"
95
+ data-testid="sliderthumb"
96
+ value={playerTimeRef.current || 0}
97
+ min={0}
98
+ max={duration}
99
+ step={0.1}
100
+ onChange={handleOnSliderChange}
101
+ onChangeStart={handleOnSliderChangeStart}
102
+ onChangeEnd={handleOnSliderChangeEnd}
103
+ >
104
+ <SliderTrack>
105
+ <SliderFilledTrack />
106
+ </SliderTrack>
107
+ <SliderThumb data-testid="sliderthumb" ref={sliderThumbRef} />
108
+ </Slider>
109
+ </Flex>
110
+ <Flex flexDir={"row"}>
111
+ <Text>
112
+ Gsap-CurrentTime: {Math.round((time + Number.EPSILON) * 100) / 100} /{" "}
113
+ {duration}
114
+ </Text>
115
+ </Flex>
116
+ </Flex>
117
+ );
118
+ };
@@ -0,0 +1,23 @@
1
+ import { useEffect, useRef } from "react";
2
+ // @ts-ignore
3
+ import isEqual from "react-fast-compare";
4
+
5
+ type EffectFunc = () => void;
6
+ type Deps = ReadonlyArray<unknown>;
7
+
8
+ const useDeepEffect = (effectFunc: EffectFunc, deps: Deps) => {
9
+ const isFirst = useRef(true);
10
+ const prevDeps = useRef(deps);
11
+ useEffect(() => {
12
+ const isSame = prevDeps.current.every((obj, index) =>
13
+ isEqual(obj, deps[index]),
14
+ );
15
+ if (isFirst.current || !isSame) {
16
+ effectFunc();
17
+ }
18
+ isFirst.current = false;
19
+ prevDeps.current = deps;
20
+ }, deps);
21
+ };
22
+
23
+ export default useDeepEffect;
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
package/tsconfig.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "lib": ["DOM", "DOM.Iterable", "ESNext"],
5
+ "plugins": [
6
+ {
7
+ "name": "typescript-plugin-css-modules",
8
+ "options": {
9
+ "postcssOptions": {
10
+ "useConfig": true
11
+ }
12
+ }
13
+ }
14
+ ],
15
+ "module": "ESNext",
16
+ "skipLibCheck": true,
17
+ /* Bundler mode */
18
+ "moduleResolution": "node",
19
+ "allowImportingTsExtensions": false,
20
+ "resolveJsonModule": true,
21
+ "isolatedModules": true,
22
+ "noEmit": true,
23
+ "jsx": "react-jsx",
24
+ "types": ["vitest/globals"],
25
+ /* Linting */
26
+ "strict": true,
27
+ "noUnusedLocals": true,
28
+ "noUnusedParameters": true,
29
+ "noFallthroughCasesInSwitch": true
30
+ },
31
+ "include": ["src"],
32
+ "references": [
33
+ {
34
+ "path": "./tsconfig.node.json"
35
+ }
36
+ ]
37
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "compilerOptions": {
3
+ "composite": true,
4
+ "skipLibCheck": true,
5
+ "module": "ESNext",
6
+ "moduleResolution": "bundler",
7
+ "allowSyntheticDefaultImports": true
8
+ },
9
+ "include": ["vite.config.ts"]
10
+ }
@@ -1,9 +1,11 @@
1
1
  import { defineConfig } from "vite";
2
- import react from "@vitejs/plugin-react";
2
+ // import react from "@vitejs/plugin-react";
3
+ import react from "@vitejs/plugin-react-swc";
4
+ import EnvironmentPlugin from "vite-plugin-environment";
3
5
 
4
6
  // https://vitejs.dev/config/
5
7
  export default defineConfig({
6
- plugins: [react()],
8
+ plugins: [react(), EnvironmentPlugin("all")],
7
9
  // build: {
8
10
  // rollupOptions: {
9
11
  // external: [
@@ -0,0 +1,11 @@
1
+ import { defineConfig } from "vitest/config";
2
+ import react from "@vitejs/plugin-react";
3
+
4
+ export default defineConfig({
5
+ plugins: [react()],
6
+ test: {
7
+ globals: true,
8
+ css: true,
9
+ environment: "jsdom",
10
+ },
11
+ });
package/src/App.jsx DELETED
@@ -1,35 +0,0 @@
1
- import { useState } from 'react'
2
- import reactLogo from './assets/react.svg'
3
- import viteLogo from '/vite.svg'
4
- import './App.css'
5
-
6
- function App() {
7
- const [count, setCount] = useState(0)
8
-
9
- return (
10
- <div className="App">
11
- <div>
12
- <a href="https://vitejs.dev" target="_blank">
13
- <img src={viteLogo} className="logo" alt="Vite logo" />
14
- </a>
15
- <a href="https://reactjs.org" target="_blank">
16
- <img src={reactLogo} className="logo react" alt="React logo" />
17
- </a>
18
- </div>
19
- <h1>Vite + React</h1>
20
- <div className="card">
21
- <button onClick={() => setCount((count) => count + 1)}>
22
- count is {count}
23
- </button>
24
- <p>
25
- Edit <code>src/App.jsx</code> and save to test HMR
26
- </p>
27
- </div>
28
- <p className="read-the-docs">
29
- Click on the Vite and React logos to learn more
30
- </p>
31
- </div>
32
- )
33
- }
34
-
35
- export default App
package/src/index.js DELETED
@@ -1,3 +0,0 @@
1
- export * from "./stories/PixiImageSprite";
2
- // Path: src\index.js
3
- export * from './providers';
@@ -1,67 +0,0 @@
1
- // your Stage:
2
- import { Stage as PixiStage } from "@pixi/react";
3
- import React from "react";
4
- import { Flex, Icon, Text, Box, Button } from "@chakra-ui/react";
5
- import * as PIXI from "pixi.js";
6
- import { ChakraProvider } from "@chakra-ui/react";
7
- import {
8
- GsapPixieContext,
9
- GsapPixieContextProvider,
10
- } from "./GsapPixieContextProvider";
11
-
12
- import { VideoSeekBar } from "./VideoSeekBar";
13
-
14
- // the context bridge:
15
- const ContextBridge = ({ children, Context, render }) => {
16
- return (
17
- <Context.Consumer>
18
- {(value) => {
19
- console.log("value", value);
20
- return render(
21
- <Context.Provider value={value}>{children}</Context.Provider>,
22
- );
23
- }}
24
- </Context.Consumer>
25
- );
26
- };
27
-
28
- const Stage = ({ children, ...props }) => {
29
- return (
30
- <ContextBridge
31
- Context={GsapPixieContext}
32
- render={(children) => <PixiStage {...props}>{children}</PixiStage>}
33
- >
34
- {children}
35
- </ContextBridge>
36
- );
37
- };
38
-
39
- export const App = ({ children, backgroundColor, ...props }) => {
40
- const backgroundColorx = PIXI.utils.string2hex(backgroundColor || "#2D2E3C");
41
- const width = 600;
42
- const height = 500;
43
-
44
- /// color: 0x1099bb,
45
- return (
46
- <div className="App">
47
- <GsapPixieContextProvider>
48
- <ChakraProvider>
49
- <Flex flexDir={"column"}>
50
- <Stage
51
- width={width}
52
- height={height}
53
- // options={{ background: backgroundColor }}
54
- options={{ backgroundColor: backgroundColorx, resolution: 2 }}
55
- >
56
- {children}
57
- </Stage>
58
-
59
- <Box mt={5} w={600}>
60
- <VideoSeekBar />
61
- </Box>
62
- </Flex>
63
- </ChakraProvider>
64
- </GsapPixieContextProvider>
65
- </div>
66
- );
67
- };
@@ -1,186 +0,0 @@
1
- import React from "react";
2
- import {
3
- Slider,
4
- SliderTrack,
5
- SliderFilledTrack,
6
- SliderThumb,
7
- SliderMark,
8
- Flex,
9
- Icon,
10
- Text,
11
- Box,
12
- Button,
13
- } from "@chakra-ui/react";
14
- import { GsapPixieContext } from "./GsapPixieContextProvider";
15
-
16
- import { gsap } from "gsap";
17
- import { Draggable } from "gsap/Draggable";
18
-
19
- gsap.registerPlugin(Draggable);
20
-
21
- export const VideoSeekBar = () => {
22
- const rafRef = React.useRef();
23
- const sliderRef = React.useRef();
24
- const sliderThumbRef = React.useRef(null);
25
- const sliderProgressRef = React.useRef(null);
26
- const {
27
- tl: timeline,
28
- playerTimeRef,
29
- handlePlay,
30
- handlePause,
31
- handleReset,
32
- handleSeek,
33
- handleRestart,
34
- handleRepeat,
35
- } = React.useContext(GsapPixieContext);
36
-
37
- /// state
38
- const [time, setTime] = React.useState(0);
39
- const [duration, setDuration] = React.useState(0);
40
-
41
- const totalVideoSeconds = 20;
42
-
43
- const animate = (time) => {
44
- /// console.log("totalDuration", timeline.current.totalDuration());
45
- setDuration(timeline.current.totalDuration());
46
- if (playerTimeRef && playerTimeRef.current) {
47
- setTime(playerTimeRef.current);
48
- }
49
- rafRef.current = requestAnimationFrame(animate);
50
- };
51
-
52
- React.useEffect(() => {
53
- rafRef.current = requestAnimationFrame(animate);
54
- return () => cancelAnimationFrame(rafRef.current);
55
- }, []); // Make sure the effect runs only once
56
-
57
- const handleOnSliderChange = (value) => {
58
- const nTotSeconds =
59
- totalVideoSeconds && totalVideoSeconds > 0 ? totalVideoSeconds : 1;
60
- const progress = value / nTotSeconds;
61
- console.log("progressbar", value, progress);
62
- playerTimeRef.current = value;
63
- timeline && timeline.progress(progress);
64
- gsap.set(sliderProgressRef.current, {
65
- scaleX: progress,
66
- });
67
- };
68
- const handleOnSliderChangeStart = (value) => {};
69
- const handleOnSliderChangeEnd = (value) => {};
70
-
71
- /** Create Draggable for the Gsap Player */
72
-
73
- const updateDrag = React.useCallback(
74
- (x, maxX) => {
75
- console.log("updatgeDrag running", x, maxX);
76
- const currentTime = (x / maxX) * totalVideoSeconds;
77
- const prog = x / sliderRef.current.offsetWidth;
78
- console.log("drage update", currentTime, prog);
79
- },
80
- [totalVideoSeconds],
81
- );
82
-
83
- /**
84
- React.useEffect(() => {
85
- console.log(sliderRef.current.clientWidth, sliderRef.current.innerWidth);
86
- console.log(
87
- sliderThumbRef.current.clientWidth,
88
- sliderThumbRef.current.innerWidth,
89
- );
90
- Draggable.create(sliderThumbRef.current, {
91
- type: "x",
92
- trigger: sliderRef.current,
93
- bounds: sliderRef.current,
94
- onPress: function () {
95
- console.log("Draggable clicked");
96
- },
97
- onDrag: function () {
98
- const currentTime = (this.x / this.maxX) * totalVideoSeconds;
99
- /// console.log("onDragggg currenttime", currentTime);
100
- playerTimeRef.current = currentTime;
101
- const progress = this.x / sliderRef.current.offsetWidth;
102
- timeline && timeline.progress(progress);
103
- gsap.set(sliderProgressRef.current, {
104
- scaleX: progress,
105
- });
106
- },
107
- onRelease: function (e) {
108
- e.preventDefault();
109
- timeline && timeline.pause();
110
- handlePause();
111
- },
112
- });
113
- }, []);
114
- */
115
- return (
116
- <Flex flexDir={"column"}>
117
- <Box>
118
- <Button onClick={handleRestart}>Play</Button>
119
- <Button onClick={handlePause}>Pause</Button>
120
- <Button onClick={handlePlay}>Resume</Button>
121
- <Button onClick={handleSeek}>Seek (4:00)</Button>
122
- </Box>
123
- <Flex px={1} mt={2}>
124
- <Slider
125
- aria-label="slider-ex-1"
126
- data-testid="sliderthumb"
127
- value={playerTimeRef.current || 0}
128
- min={0}
129
- max={duration}
130
- step={0.1}
131
- onChange={handleOnSliderChange}
132
- onChangeStart={handleOnSliderChangeStart}
133
- onChangeEnd={handleOnSliderChangeEnd}
134
- >
135
- <SliderTrack>
136
- <SliderFilledTrack />
137
- </SliderTrack>
138
- <SliderThumb data-testid="sliderthumb" />
139
- </Slider>
140
- </Flex>
141
- <Flex flexDir={"row"}>
142
- <Text>
143
- Gsap-CurrentTime: {Math.round((time + Number.EPSILON) * 100) / 100} /{" "}
144
- {duration}
145
- </Text>
146
- </Flex>
147
- </Flex>
148
- );
149
- };
150
-
151
- /**
152
- *
153
- <Box mt={5}>
154
- <Box
155
- ref={sliderRef}
156
- bgColor={"black"}
157
- width={"100%"}
158
- height={5}
159
- cursor={"pointer"}
160
- position={"relative"}
161
- >
162
- <Box
163
- ref={sliderThumbRef}
164
- data-id="draggable"
165
- bgColor={"yellow"}
166
- h={5}
167
- width={"5px"}
168
- top={0}
169
- position={"absolute"}
170
- zIndex={2}
171
- transformOrigin={"0 0"}
172
- />
173
- <Box
174
- ref={sliderProgressRef}
175
- data-id="draggable"
176
- width={"100%"}
177
- height={"100%"}
178
- bgColor={"green.100"}
179
- transform={"scaleX(0)"}
180
- transformOrigin={"0 0"}
181
- position={"relative"}
182
- zIndex={1}
183
- />
184
- </Box>
185
- </Box>
186
- */
@@ -1,3 +0,0 @@
1
- export * from './ContextBridge';
2
- export * from './GsapAnim';
3
- export * from './GsapPixieContextProvider';