reacthub-pixitweenjs 0.2.3 → 0.2.5

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 (57) hide show
  1. package/.storybook/{main.js → main.ts} +9 -1
  2. package/.storybook/{preview.jsx → preview.tsx} +3 -7
  3. package/CHANGELOG.md +40 -0
  4. package/README.md +21 -2
  5. package/build-storybook.log +94 -0
  6. package/index.html +1 -1
  7. package/package.json +68 -36
  8. package/src/App.tsx +29 -0
  9. package/src/components/PixiAnimatedSprite/PixiAnimatedSprite.tsx +51 -0
  10. package/src/components/PixiAnimatedSprite/index.ts +2 -0
  11. package/src/components/PixiAudioSprite/PixiAudioSprite.stories.tsx +61 -0
  12. package/src/components/PixiAudioSprite/PixiAudioSprite.tsx +212 -0
  13. package/src/components/PixiAudioSprite/index.ts +1 -0
  14. package/src/components/PixiGifSprite/PixiGifSprite.stories.tsx +135 -0
  15. package/src/components/PixiGifSprite/PixiGifSprite.tsx +451 -0
  16. package/src/components/PixiGifSprite/index.ts +2 -0
  17. package/src/{stories/PixiImageSprite/PixiImageSprite.stories.js → components/PixiImageSprite/PixiImageSprite.stories.tsx} +36 -8
  18. package/src/components/PixiImageSprite/PixiImageSprite.tsx +340 -0
  19. package/src/components/PixiImageSprite/index.ts +1 -0
  20. package/src/components/PixiSVGSprite/PixiSvgPathSprite.stories.tsx +137 -0
  21. package/src/components/PixiSVGSprite/PixiSvgPathSprite.tsx +378 -0
  22. package/src/components/PixiSVGSprite/index.ts +1 -0
  23. package/src/components/PixiVideoSprite/PixiVideoSprite.stories.tsx +147 -0
  24. package/src/components/PixiVideoSprite/PixiVideoSprite.tsx +684 -0
  25. package/src/components/PixiVideoSprite/PixiVideoSpriteBackup.txt +755 -0
  26. package/src/components/PixiVideoSprite/index.ts +1 -0
  27. package/src/declare.module.ts +5 -0
  28. package/src/hooks/usePixiTransformer.tsx +168 -0
  29. package/src/index.ts +3 -0
  30. package/src/providers/GsapPixieContextProvider.tsx +251 -0
  31. package/src/providers/index.ts +1 -0
  32. package/src/reacthub-react-bindings.d.ts +27 -0
  33. package/src/types/transformation.tsx +13 -0
  34. package/src/utils/AppStateProvider.tsx +59 -0
  35. package/src/utils/AppStateStage.tsx +27 -0
  36. package/src/utils/AppWrapper.tsx +43 -0
  37. package/src/utils/ContextBridge.tsx +25 -0
  38. package/src/{providers/GsapAnim.jsx → utils/GsapAnim.tsx} +35 -4
  39. package/src/utils/PixiStage.tsx +29 -0
  40. package/src/utils/PixiTransformer.tsx +100 -0
  41. package/src/utils/VideoSeekBar.tsx +129 -0
  42. package/src/utils/useDebounce.tsx +15 -0
  43. package/src/utils/useDeepEffect.tsx +23 -0
  44. package/src/vite-env.d.ts +1 -0
  45. package/tsconfig.json +37 -0
  46. package/tsconfig.node.json +10 -0
  47. package/{vite.config.js → vite.config.ts} +4 -2
  48. package/vitest.config.ts +11 -0
  49. package/src/App.jsx +0 -35
  50. package/src/index.js +0 -3
  51. package/src/providers/ContextBridge.jsx +0 -67
  52. package/src/providers/GsapPixieContextProvider.jsx +0 -162
  53. package/src/providers/VideoSeekBar.jsx +0 -186
  54. package/src/providers/index.js +0 -3
  55. package/src/stories/PixiImageSprite/PixiImageSprite.jsx +0 -318
  56. package/src/stories/PixiImageSprite/index.js +0 -1
  57. /package/src/{main.jsx → main.tsx} +0 -0
@@ -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';
@@ -1,318 +0,0 @@
1
- import React, { Context } from "react";
2
- import PropTypes from "prop-types";
3
- import { GsapPixieContext } from "../../providers/GsapPixieContextProvider";
4
- import { Sprite, Container, useApp, withFilters } from "@pixi/react";
5
- import { AdjustmentFilter } from "@pixi/filter-adjustment";
6
- import * as PIXI from "pixi.js";
7
- import gsap from "gsap";
8
- import isEmpty from "lodash/isEmpty";
9
- import { getAnimByName } from "../../providers/GsapAnim";
10
-
11
- const Filters = withFilters(Container, {
12
- blur: PIXI.filters.BlurFilter,
13
- adjust: AdjustmentFilter,
14
- matrix: PIXI.filters.ColorMatrixFilter,
15
- });
16
-
17
- /** filter config */
18
- const config = {
19
- dot: {
20
- scale: 1,
21
- angle: 5,
22
- },
23
- blur: {
24
- blur: 0,
25
- quality: 4,
26
- },
27
- };
28
-
29
- /** CYAN Filters */
30
- const CYAN = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0];
31
-
32
- export const PixiImageSprite = (props) => {
33
- /// console.log("allProps", props);
34
- //// Refs
35
- const imageRef = React.useRef(null);
36
- const containerRef = React.useRef(null);
37
- const imgGroupRef = React.useRef(null);
38
-
39
- //// Context
40
- const { tl } = React.useContext(GsapPixieContext);
41
-
42
- /// 1001
43
- console.log("contxt Values", tl);
44
- const {
45
- src,
46
- startAt,
47
- endAt,
48
- initialAlpha,
49
- transformation: {
50
- x,
51
- y,
52
- width,
53
- height,
54
- anchor,
55
- animation,
56
- colorCorrection,
57
- effect,
58
- } = {},
59
- pointerdown,
60
- pointerup,
61
- mousedown,
62
- mouseup,
63
- pointerover,
64
- mouseover,
65
- mouseout,
66
- ...restProps
67
- } = props;
68
-
69
- const {
70
- enabled = false,
71
- temperature = 1,
72
- hue = 1,
73
- contrast = 1,
74
- saturation = 1,
75
- exposure = 1,
76
- reset,
77
- sharpness = 1,
78
- value = 0,
79
- levels = 1,
80
- luminance = 0,
81
- enhance = 0,
82
- blurRadius = 0,
83
- red = 150,
84
- green = 150,
85
- blue = 150,
86
- alpha = 1,
87
- scaleInput = 1,
88
- } = colorCorrection;
89
-
90
- const app = useApp();
91
- const PixiTransformer = React.useRef(null);
92
-
93
- /** adjustment filter */
94
- const adjustments = {
95
- brightness: exposure,
96
- contrast,
97
- saturation,
98
- alpha,
99
- };
100
-
101
- React.useEffect(() => {
102
- let ctx = gsap.context(() => {});
103
- if (containerRef.current && tl.current) {
104
- const data = {
105
- duration: Number(endAt) - Number(startAt),
106
- };
107
-
108
- const ease = getAnimByName(animation);
109
- ctx = gsap.context(() => {
110
- if (!isEmpty(ease.from)) {
111
- tl.current
112
- .from(containerRef.current, { ...ease.from }, startAt)
113
- .to(imgGroupRef.current, { alpha: 1, duration: 0.2 }, startAt)
114
- .from(imgGroupRef.current, { ...data }, startAt)
115
- .to(containerRef.current, { alpha: 0, duration: 0.2 }, endAt - 0.2);
116
- } else if (!isEmpty(ease.to)) {
117
- tl.current
118
- .to(
119
- containerRef.current,
120
- { alpha: 1, duration: 0.2, ...ease.to },
121
- startAt,
122
- )
123
- .from(imgGroupRef.current, { ...data }, startAt)
124
- .to(containerRef.current, { alpha: 0, duration: 0.2 }, endAt - 0.2);
125
- } else if (!isEmpty(ease.fromTo)) {
126
- tl.current
127
- .fromTo(
128
- containerRef.current,
129
- ease.fromTo.from,
130
- ease.fromTo.to,
131
- startAt,
132
- )
133
- .from(imgGroupRef.current, { ...data }, startAt)
134
- .to(containerRef.current, { alpha: 0, duration: 0.2 }, endAt - 0.2);
135
- } else {
136
- tl.current
137
- .to(containerRef.current, { alpha: 1, duration: 0.01 }, startAt)
138
- .from(imgGroupRef.current, { ...data }, startAt)
139
- .to(
140
- containerRef.current,
141
- { alpha: 0, duration: 0.1 },
142
- Number(endAt) - Number(0.1),
143
- );
144
- }
145
- });
146
- }
147
- return () => ctx.revert(); // cleanup!
148
- }, [animation, startAt, endAt]);
149
-
150
- return (
151
- <Container ref={containerRef} alpha={initialAlpha}>
152
- {colorCorrection && colorCorrection.enabled ? (
153
- <Filters
154
- scale={1}
155
- blur={{ blur: blurRadius, quality: 4 }}
156
- adjust={adjustments}
157
- apply={({ matrix }) => {
158
- if (effect === "BlackAndWhite") {
159
- matrix.desaturate();
160
- } else if (effect === "Sepia") {
161
- matrix.sepia();
162
- } else if (effect === "RetroVintage") {
163
- matrix.negative();
164
- } else if (effect === "NightVision") {
165
- matrix.negative();
166
- } else if (effect === "Normal") {
167
- matrix.reset();
168
- }
169
- }}
170
- matrix={{
171
- enabled: true,
172
- matrix: CYAN,
173
- }}
174
- >
175
- <Container ref={imgGroupRef}>
176
- <Sprite
177
- image={src}
178
- width={width}
179
- height={height}
180
- anchor={anchor}
181
- ref={imageRef}
182
- x={x}
183
- y={y}
184
- interactive={true}
185
- pointerdown={pointerdown}
186
- pointerup={pointerup}
187
- pointerover={pointerover}
188
- mousedown={mousedown}
189
- mouseup={mouseup}
190
- mouseover={mouseover}
191
- mouseout={mouseout}
192
- />
193
- </Container>
194
- </Filters>
195
- ) : (
196
- <Container ref={imgGroupRef}>
197
- <Sprite
198
- image={src}
199
- width={width}
200
- height={height}
201
- anchor={anchor}
202
- ref={imageRef}
203
- x={x}
204
- y={y}
205
- interactive={true}
206
- pointerdown={pointerdown}
207
- pointerup={pointerup}
208
- pointerover={pointerover}
209
- mousedown={mousedown}
210
- mouseup={mouseup}
211
- mouseover={mouseover}
212
- mouseout={mouseout}
213
- />
214
- </Container>
215
- )}
216
- </Container>
217
- );
218
- };
219
-
220
- PixiImageSprite.propTypes = {
221
- // app background color property
222
- backgroundColor: PropTypes.string,
223
- // sprite transformation properties
224
- transformation: PropTypes.shape({
225
- x: PropTypes.number,
226
- y: PropTypes.number,
227
- width: PropTypes.number,
228
- height: PropTypes.number,
229
- anchor: PropTypes.number,
230
- rotation: PropTypes.number,
231
- alpha: PropTypes.number,
232
- scale: PropTypes.number,
233
- tint: PropTypes.number,
234
- blendMode: PropTypes.number,
235
- colorCorrection: PropTypes.shape({
236
- enabled: PropTypes.bool,
237
- temperature: PropTypes.number,
238
- hue: PropTypes.number,
239
- contrast: PropTypes.number,
240
- saturation: PropTypes.number,
241
- exposure: PropTypes.number,
242
- reset: PropTypes.bool,
243
- sharpness: PropTypes.number,
244
- value: PropTypes.number,
245
- levels: PropTypes.number,
246
- luminance: PropTypes.number,
247
- enhance: PropTypes.number,
248
- blurRadius: PropTypes.number,
249
- red: PropTypes.number,
250
- green: PropTypes.number,
251
- blue: PropTypes.number,
252
- alpha: PropTypes.number,
253
- scaleInput: PropTypes.number,
254
- }),
255
- effect: PropTypes.string,
256
- pointerdown: PropTypes.func,
257
- pointerup: PropTypes.func,
258
- pointerover: PropTypes.func,
259
- mousedown: PropTypes.func,
260
- mouseup: PropTypes.func,
261
- mouseover: PropTypes.func,
262
- mouseout: PropTypes.func,
263
- }).isRequired,
264
- // sprite initial alpha property (opacity)
265
- initialAlpha: PropTypes.number,
266
- // sprite animation properties
267
- applyTransformer: PropTypes.bool,
268
- // sprite startAt and endAt properties
269
- startAt: PropTypes.number.isRequired,
270
- // sprite startAt and endAt properties
271
- endAt: PropTypes.number.isRequired,
272
- };
273
-
274
- PixiImageSprite.defaultProps = {
275
- pointerdown: () => {},
276
- pointerup: () => {},
277
- mousedown: () => {},
278
- mouseup: () => {},
279
- pointerover: () => {},
280
- mouseover: () => {},
281
- mouseout: () => {},
282
- backgroundColor: "0x000000",
283
- transformation: {
284
- x: 0,
285
- y: 0,
286
- width: 0,
287
- height: 0,
288
- anchor: 0,
289
- rotation: 0,
290
- alpha: 1,
291
- scale: 1,
292
- tint: 0xffffff,
293
- blendMode: 0,
294
- colorCorrection: {
295
- enabled: false,
296
- temperature: 1,
297
- hue: 1,
298
- contrast: 1,
299
- saturation: 1,
300
- exposure: 1,
301
- reset: false,
302
- sharpness: 1,
303
- value: 0,
304
- levels: 1,
305
- luminance: 0,
306
- enhance: 0,
307
- blurRadius: 0,
308
- red: 150,
309
- green: 150,
310
- blue: 150,
311
- alpha: 1,
312
- scaleInput: 1,
313
- },
314
- effect: "Normal",
315
- },
316
- initialAlpha: 1,
317
- applyTransformer: false,
318
- };
@@ -1 +0,0 @@
1
- export * from "./PixiImageSprite";
File without changes