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
@@ -0,0 +1,340 @@
1
+ import * as React from "react";
2
+ import { useContext, useEffect, useRef, useState } from "react";
3
+ // @ts-ignore
4
+ import PropTypes from "prop-types";
5
+ import { GsapPixieContext } from "../../providers/GsapPixieContextProvider";
6
+ import { Sprite, Container, useApp, withFilters } from "@pixi/react";
7
+ import { AdjustmentFilter } from "@pixi/filter-adjustment";
8
+ import * as PIXI from "pixi.js";
9
+ import gsap from "gsap";
10
+ import PixiTransformer from "../../utils/PixiTransformer";
11
+
12
+ // @ts-ignore
13
+ import isEmpty from "lodash/isEmpty";
14
+ import { getAnimByName } from "../../utils/GsapAnim";
15
+ import { TransformationEnd } from "../../types/transformation";
16
+
17
+ type PixiImageSpriteProps = {
18
+ uniqueId: string;
19
+ src: string;
20
+ startAt: number;
21
+ endAt: number;
22
+ initialAlpha: number;
23
+ transformation: {
24
+ x: number;
25
+ y: number;
26
+ width: number;
27
+ height: number;
28
+ anchor: number;
29
+ rotation?: number;
30
+ alpha?: number;
31
+ scale?: number | [number, number];
32
+ tint?: number;
33
+ blendMode?: number;
34
+ animation?: string;
35
+ colorCorrection?: {
36
+ enabled?: boolean;
37
+ temperature?: number;
38
+ hue?: number;
39
+ contrast?: number;
40
+ saturation?: number;
41
+ exposure?: number;
42
+ reset?: boolean;
43
+ sharpness?: number;
44
+ value?: number;
45
+ levels?: number;
46
+ luminance?: number;
47
+ enhance?: number;
48
+ blurRadius?: number;
49
+ red?: number;
50
+ green?: number;
51
+ blue?: number;
52
+ alpha?: number;
53
+ scaleInput?: number;
54
+ };
55
+ effect?: string;
56
+ };
57
+ pointerdown?: () => void;
58
+ pointerup?: () => void;
59
+ mousedown?: () => void;
60
+ mouseup?: () => void;
61
+ pointerover?: () => void;
62
+ mouseover?: () => void;
63
+ mouseout?: () => void;
64
+ applyTransformer?: boolean;
65
+ onAnchorTransformationEnd?: (endData: any) => void;
66
+ };
67
+
68
+ type EffectFunc = () => void;
69
+ type Deps = ReadonlyArray<unknown>;
70
+
71
+ const Filters = withFilters(Container, {
72
+ blur: PIXI.filters.BlurFilter,
73
+ adjust: AdjustmentFilter,
74
+ matrix: PIXI.filters.ColorMatrixFilter,
75
+ });
76
+
77
+ /** filter config */
78
+ const config = {
79
+ dot: {
80
+ scale: 1,
81
+ angle: 5,
82
+ },
83
+ blur: {
84
+ blur: 0,
85
+ quality: 4,
86
+ },
87
+ };
88
+
89
+ /** CYAN Filters */
90
+ const CYAN = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0];
91
+
92
+ const PixiImageSprite: React.FC<PixiImageSpriteProps> = (props) => {
93
+ //// State
94
+ const [isMounted, setIsMounted] = React.useState(false);
95
+ const [isTransformerDragging, setIsTransformerDragging] = useState(false);
96
+ const [isMouseOverTransformer, setIsMouseOverTransformer] = useState(false);
97
+
98
+ console.log("allProps", props);
99
+ //// Refs
100
+ const imageRef = useRef<PIXI.Sprite>(null);
101
+ const containerRef = useRef<PIXI.Container>(null);
102
+ const parentNode = useRef<PIXI.Container>(null);
103
+ const imgGroupRef = useRef<PIXI.Container>(null);
104
+ const transformerRef = useRef<PIXI.Container>(null);
105
+
106
+ //// Context
107
+ const { tl } = useContext(GsapPixieContext);
108
+
109
+ /// 1001
110
+ // console.log("contxt Values", tl);
111
+ const {
112
+ uniqueId,
113
+ src,
114
+ startAt,
115
+ endAt,
116
+ initialAlpha,
117
+ transformation: {
118
+ x,
119
+ y,
120
+ width,
121
+ height,
122
+ anchor,
123
+ animation,
124
+ colorCorrection,
125
+ effect,
126
+ },
127
+ pointerdown,
128
+ pointerup,
129
+ mousedown,
130
+ mouseup,
131
+ pointerover,
132
+ mouseover,
133
+ mouseout,
134
+ applyTransformer,
135
+ onAnchorTransformationEnd,
136
+ ...restProps
137
+ } = props;
138
+
139
+ // color corrections
140
+ const {
141
+ enabled = false,
142
+ temperature = 1,
143
+ hue = 1,
144
+ contrast = 1,
145
+ saturation = 1,
146
+ exposure = 1,
147
+ reset,
148
+ sharpness = 1,
149
+ value = 0,
150
+ levels = 1,
151
+ luminance = 0,
152
+ enhance = 0,
153
+ blurRadius = 0,
154
+ red = 150,
155
+ green = 150,
156
+ blue = 150,
157
+ alpha = 1,
158
+ scaleInput = 1,
159
+ } = colorCorrection || {};
160
+
161
+ const app = useApp();
162
+
163
+ /** adjustment filter */
164
+ const adjustments = {
165
+ brightness: exposure,
166
+ contrast,
167
+ saturation,
168
+ alpha,
169
+ };
170
+
171
+ /** handle on tranformer onchange */
172
+ const handleOnTransformChange = React.useCallback(() => {
173
+ setIsTransformerDragging(true);
174
+ }, []);
175
+
176
+ // transformer to handle sprite transformation
177
+ const handleOnTransformEnd = React.useCallback(
178
+ (endData: TransformationEnd) => {
179
+ console.log("changeEnd", endData);
180
+ if (onAnchorTransformationEnd) {
181
+ console.log("running onAnchorTransformationEnd");
182
+ onAnchorTransformationEnd(endData);
183
+ }
184
+ },
185
+ []
186
+ );
187
+
188
+ useEffect(() => {
189
+ let ctx = gsap.context(() => {});
190
+ if (containerRef.current && tl.current) {
191
+ const data = {
192
+ duration: Number(endAt) - Number(startAt),
193
+ };
194
+
195
+ const ease = getAnimByName(animation || "None");
196
+ ctx = gsap.context(() => {
197
+ if (!isEmpty(ease.from)) {
198
+ tl.current
199
+ .from(containerRef.current, { ...ease.from }, startAt)
200
+ .to(imgGroupRef.current, { alpha: 1, duration: 0.2 }, startAt)
201
+ .from(imgGroupRef.current, { ...data }, startAt)
202
+ .to(containerRef.current, { alpha: 0, duration: 0.2 }, endAt - 0.2);
203
+ } else if (!isEmpty(ease.to)) {
204
+ tl.current
205
+ .to(
206
+ containerRef.current,
207
+ { alpha: 1, duration: 0.2, ...ease.to },
208
+ startAt
209
+ )
210
+ .from(imgGroupRef.current, { ...data }, startAt)
211
+ .to(containerRef.current, { alpha: 0, duration: 0.2 }, endAt - 0.2);
212
+ } else if (!isEmpty(ease.fromTo)) {
213
+ tl.current
214
+ .fromTo(
215
+ containerRef.current,
216
+ ease.fromTo?.from,
217
+ ease.fromTo?.to,
218
+ startAt
219
+ )
220
+ .from(imgGroupRef.current, { ...data }, startAt)
221
+ .to(containerRef.current, { alpha: 0, duration: 0.2 }, endAt - 0.2);
222
+ } else {
223
+ tl.current
224
+ .to(containerRef.current, { alpha: 1, duration: 0.01 }, startAt)
225
+ .from(imgGroupRef.current, { ...data }, startAt)
226
+ .to(
227
+ containerRef.current,
228
+ { alpha: 0, duration: 0.1 },
229
+ Number(endAt) - Number(0.1)
230
+ );
231
+ }
232
+ });
233
+ }
234
+ return () => ctx.revert(); // cleanup!
235
+ }, [animation, startAt, endAt]);
236
+
237
+ React.useEffect(() => {
238
+ if (containerRef.current) {
239
+ setIsMounted(true);
240
+ }
241
+ }, []);
242
+
243
+ return (
244
+ // @ts-ignore
245
+ <Container ref={parentNode}>
246
+ {/* @ts-ignore */}
247
+ <Container
248
+ ref={containerRef}
249
+ alpha={initialAlpha}
250
+ position={[x, y]}
251
+ pivot={[x, y]}
252
+ width={width}
253
+ height={height}
254
+ >
255
+ {colorCorrection && colorCorrection.enabled ? (
256
+ <Filters
257
+ scale={1}
258
+ blur={{ blur: blurRadius, quality: 4 }}
259
+ adjust={adjustments}
260
+ apply={({ matrix }: { matrix: any }) => {
261
+ if (effect === "BlackAndWhite") {
262
+ matrix.desaturate();
263
+ } else if (effect === "Sepia") {
264
+ matrix.sepia();
265
+ } else if (effect === "RetroVintage") {
266
+ matrix.negative();
267
+ } else if (effect === "NightVision") {
268
+ matrix.negative();
269
+ } else if (effect === "Normal") {
270
+ matrix.reset();
271
+ }
272
+ }}
273
+ matrix={{
274
+ enabled: true,
275
+ // @ts-ignore
276
+ matrix: CYAN,
277
+ }}
278
+ >
279
+ {/* @ts-ignore */}
280
+ <Container ref={imgGroupRef}>
281
+ <Sprite
282
+ image={src}
283
+ width={width}
284
+ height={height}
285
+ anchor={anchor}
286
+ ref={imageRef}
287
+ x={x}
288
+ y={y}
289
+ // @ts-ignore
290
+ interactive={true}
291
+ pointerdown={pointerdown}
292
+ pointerup={pointerup}
293
+ pointerover={pointerover}
294
+ mousedown={mousedown}
295
+ mouseup={mouseup}
296
+ mouseover={mouseover}
297
+ mouseout={mouseout}
298
+ />
299
+ </Container>
300
+ </Filters>
301
+ ) : (
302
+ // @ts-ignore
303
+ <Container ref={imgGroupRef}>
304
+ <Sprite
305
+ image={src}
306
+ width={width}
307
+ height={height}
308
+ anchor={anchor}
309
+ ref={imageRef}
310
+ x={x}
311
+ y={y}
312
+ // @ts-ignore
313
+ interactive={true}
314
+ pointerdown={pointerdown}
315
+ pointerup={pointerup}
316
+ pointerover={pointerover}
317
+ mousedown={mousedown}
318
+ mouseup={mouseup}
319
+ mouseover={mouseover}
320
+ mouseout={mouseout}
321
+ />
322
+ </Container>
323
+ )}
324
+ </Container>
325
+ {applyTransformer && (
326
+ <PixiTransformer
327
+ pixiTransformerRef={transformerRef}
328
+ imageRef={containerRef}
329
+ isMounted={isMounted}
330
+ transformCommit={handleOnTransformEnd}
331
+ transformChange={handleOnTransformChange}
332
+ mouseoverEvent={setIsMouseOverTransformer}
333
+ uniqueId={uniqueId}
334
+ />
335
+ )}
336
+ </Container>
337
+ );
338
+ };
339
+
340
+ export default PixiImageSprite;
@@ -0,0 +1 @@
1
+ export { default as PixiImageSprite } from "./PixiImageSprite";
@@ -0,0 +1,137 @@
1
+ import type { Meta, StoryObj } from "@storybook/react";
2
+ import { PixiSvgPathSprite } from ".";
3
+ import { AppStateContextProvider } from "../../utils/AppStateProvider";
4
+
5
+ // More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction
6
+ const meta = {
7
+ title: "Components/SvgSprite",
8
+ component: PixiSvgPathSprite,
9
+
10
+ tags: ["autodocs"],
11
+ argTypes: {
12
+ uniqueId: {
13
+ control: "text",
14
+ description: "uniqueId of the sprite",
15
+ },
16
+ src: {
17
+ control: "text",
18
+ description: "source of the image",
19
+ },
20
+ transformation: {
21
+ control: "object",
22
+ description: "transformation of the sprite",
23
+ x: { control: "number", description: "x position of the sprite" },
24
+ y: { control: "number", description: "y position of the sprite" },
25
+ width: { control: "number", description: "width of the sprite" },
26
+ height: { control: "number", description: "height of the sprite" },
27
+ anchor: { control: "number", description: "anchor of the sprite" },
28
+ rotation: { control: "number", description: "rotation of the sprite" },
29
+ alpha: {
30
+ control: "number",
31
+ min: 0,
32
+ max: 1,
33
+ description: "alpha of the sprite",
34
+ },
35
+ scale: { control: "number", description: "scale of the sprite" },
36
+ tint: { control: "number", description: "tint of the sprite" },
37
+ blendMode: { control: "number", description: "blendMode of the sprite" },
38
+ colorCorrection: {
39
+ control: "object",
40
+ description: "colorCorrection of the sprite",
41
+ brightness: {
42
+ control: "number",
43
+ description: "brightness of the sprite",
44
+ },
45
+ contrast: { control: "number", description: "contrast of the sprite" },
46
+ saturation: {
47
+ control: "number",
48
+ description: "saturation of the sprite",
49
+ },
50
+ alpha: { control: "number", description: "alpha of the sprite" },
51
+ },
52
+ },
53
+ applyTransformer: { control: "boolean", description: "applyTransformer" },
54
+ startAt: { control: "number", description: "startAt" },
55
+ endAt: { control: "number", description: "endAt" },
56
+ initialAlpha: {
57
+ control: "number",
58
+ min: 0,
59
+ max: 1,
60
+ description: "sprite initial alpha value (default 1)",
61
+ },
62
+ onAnchorTransformationEnd: {
63
+ action: "onAnchorTransformationEnd",
64
+ description:
65
+ "on transforamtion end the event is fire callback with latest sprite transformation properties.",
66
+ },
67
+ pointerdown: {
68
+ action: "pointerdown",
69
+ description: "pointerdown event",
70
+ },
71
+ },
72
+ } satisfies Meta<typeof PixiSvgPathSprite>;
73
+
74
+ export default meta;
75
+ type Story = StoryObj<typeof meta>;
76
+
77
+ // More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
78
+ export const Normal: Story = {
79
+ render: (args: any) => (
80
+ <AppStateContextProvider {...args}>
81
+ <PixiSvgPathSprite {...args} />
82
+ </AppStateContextProvider>
83
+ ),
84
+ args: {
85
+ uniqueId: "svg001", // uniqueId of the sprite
86
+ path: "M 100 100 L 300 100 L 200 300 z",
87
+ transformation: {
88
+ x: 100,
89
+ y: 100,
90
+ width: 150,
91
+ height: 150,
92
+ anchor: 0.5,
93
+ rotation: 0,
94
+ alpha: 1,
95
+ scale: 1,
96
+ tint: 0xffffff,
97
+ blendMode: 0,
98
+ colorCorrection: {},
99
+ fill: "#FFC0CB",
100
+ },
101
+ applyTransformer: false,
102
+ startAt: 0,
103
+ endAt: 10,
104
+ initialAlpha: 1,
105
+ },
106
+ };
107
+
108
+ export const FadeIn: Story = {
109
+ render: (args: any) => (
110
+ <AppStateContextProvider {...args}>
111
+ <PixiSvgPathSprite {...args} />
112
+ </AppStateContextProvider>
113
+ ),
114
+ args: {
115
+ uniqueId: "surya002", // uniqueId of the sprite
116
+ path: "M 100, 100 m -75, 0 a 75,75 0 1,0 150,0 a 75,75 0 1,0 -150,0",
117
+ transformation: {
118
+ x: 100,
119
+ y: 100,
120
+ width: 150,
121
+ height: 150,
122
+ anchor: 0.5,
123
+ rotation: 0,
124
+ alpha: 1,
125
+ scale: 1,
126
+ tint: 0xffffff,
127
+ blendMode: 0,
128
+ animation: "FADE_IN",
129
+ colorCorrection: {},
130
+ fill: "#fe2c54",
131
+ },
132
+ applyTransformer: false,
133
+ startAt: 0,
134
+ endAt: 10,
135
+ initialAlpha: 0,
136
+ },
137
+ };