reacthub-pixitweenjs 0.2.5 → 0.2.7

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 (33) hide show
  1. package/.storybook/preview.tsx +6 -0
  2. package/CHANGELOG.md +26 -0
  3. package/README.md +1 -1
  4. package/package.json +4 -1
  5. package/src/components/PixiAudioSprite/PixiAudioSprite.tsx +5 -15
  6. package/src/components/PixiGifSprite/PixiGifSprite.stories.tsx +41 -4
  7. package/src/components/PixiGifSprite/PixiGifSprite.tsx +64 -95
  8. package/src/components/PixiImageSprite/PixiImageSprite.stories.tsx +53 -7
  9. package/src/components/PixiImageSprite/PixiImageSprite.tsx +27 -307
  10. package/src/components/PixiSVGSprite/PixiSvgPathSprite.stories.tsx +51 -14
  11. package/src/components/PixiSVGSprite/PixiSvgPathSprite.tsx +33 -253
  12. package/src/components/PixiTextSprite/PixiTextSprite.stories.tsx +228 -0
  13. package/src/components/PixiTextSprite/PixiTextSprite.tsx +361 -0
  14. package/src/components/PixiTextSprite/index.ts +1 -0
  15. package/src/components/PixiVideoSprite/PixiVideoSprite.stories.tsx +39 -0
  16. package/src/components/PixiVideoSprite/PixiVideoSprite.tsx +595 -684
  17. package/src/hocs/AbstractContainer.tsx +199 -0
  18. package/src/hocs/WithFilterContainer.tsx +159 -0
  19. package/src/main.tsx +8 -7
  20. package/src/providers/GsapPixieContextProvider.tsx +14 -20
  21. package/src/stories/Installation.mdx +3 -3
  22. package/src/types/Animations.tsx +41 -0
  23. package/src/types/BaseProps.tsx +56 -0
  24. package/src/types/BlendModes.tsx +19 -0
  25. package/src/types/Effects.tsx +10 -0
  26. package/src/utils/AppStateProvider.tsx +3 -3
  27. package/src/utils/AppStateStage.tsx +1 -13
  28. package/src/utils/AppWrapper.tsx +4 -0
  29. package/src/utils/GsapAnim.tsx +1 -7
  30. package/src/utils/InteractionManager.tsx +36 -0
  31. package/src/utils/PixiTransformer.tsx +68 -3
  32. package/src/utils/VideoSeekBar.tsx +4 -11
  33. package/src/hooks/usePixiTransformer.tsx +0 -168
@@ -1,129 +1,27 @@
1
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";
2
+ import { useRef } from "react";
3
+ import { Sprite, Container } from "@pixi/react";
8
4
  import * as PIXI from "pixi.js";
9
- import gsap from "gsap";
10
- import PixiTransformer from "../../utils/PixiTransformer";
11
-
12
5
  // @ts-ignore
13
6
  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
- });
7
+ // setup hocs
8
+ import AbstractContainer from "../../hocs/AbstractContainer";
9
+ import { PixiBaseSpriteProps } from "../../types/BaseProps";
76
10
 
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) => {
11
+ const PixiImageSprite: React.FC<PixiBaseSpriteProps> = (props) => {
93
12
  //// State
94
- const [isMounted, setIsMounted] = React.useState(false);
95
- const [isTransformerDragging, setIsTransformerDragging] = useState(false);
96
- const [isMouseOverTransformer, setIsMouseOverTransformer] = useState(false);
97
13
 
98
- console.log("allProps", props);
99
14
  //// Refs
100
15
  const imageRef = useRef<PIXI.Sprite>(null);
101
- const containerRef = useRef<PIXI.Container>(null);
102
- const parentNode = useRef<PIXI.Container>(null);
103
16
  const imgGroupRef = useRef<PIXI.Container>(null);
104
- const transformerRef = useRef<PIXI.Container>(null);
105
17
 
106
18
  //// Context
107
- const { tl } = useContext(GsapPixieContext);
108
19
 
109
20
  /// 1001
110
21
  // console.log("contxt Values", tl);
111
22
  const {
112
- uniqueId,
113
23
  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
- },
24
+ transformation: { x, y, width, height, anchor },
127
25
  pointerdown,
128
26
  pointerup,
129
27
  mousedown,
@@ -131,209 +29,31 @@ const PixiImageSprite: React.FC<PixiImageSpriteProps> = (props) => {
131
29
  pointerover,
132
30
  mouseover,
133
31
  mouseout,
134
- applyTransformer,
135
- onAnchorTransformationEnd,
136
- ...restProps
137
32
  } = props;
138
33
 
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
34
  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
- ) : (
35
+ <AbstractContainer {...props}>
36
+ <Container ref={imgGroupRef}>
37
+ <Sprite
38
+ image={src}
39
+ width={width}
40
+ height={height}
41
+ anchor={anchor}
42
+ ref={imageRef}
43
+ x={x}
44
+ y={y}
302
45
  // @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}
46
+ interactive={true}
47
+ pointerdown={pointerdown}
48
+ pointerup={pointerup}
49
+ pointerover={pointerover}
50
+ mousedown={mousedown}
51
+ mouseup={mouseup}
52
+ mouseover={mouseover}
53
+ mouseout={mouseout}
334
54
  />
335
- )}
336
- </Container>
55
+ </Container>
56
+ </AbstractContainer>
337
57
  );
338
58
  };
339
59
 
@@ -13,9 +13,9 @@ const meta = {
13
13
  control: "text",
14
14
  description: "uniqueId of the sprite",
15
15
  },
16
- src: {
16
+ path: {
17
17
  control: "text",
18
- description: "source of the image",
18
+ description: "source of the svg path",
19
19
  },
20
20
  transformation: {
21
21
  control: "object",
@@ -84,11 +84,14 @@ export const Normal: Story = {
84
84
  args: {
85
85
  uniqueId: "svg001", // uniqueId of the sprite
86
86
  path: "M 100 100 L 300 100 L 200 300 z",
87
+ applyTransformer: false,
88
+ startAt: 0,
89
+ endAt: 10,
87
90
  transformation: {
88
- x: 100,
89
- y: 100,
90
- width: 150,
91
- height: 150,
91
+ x: 200,
92
+ y: 200,
93
+ width: 200,
94
+ height: 200,
92
95
  anchor: 0.5,
93
96
  rotation: 0,
94
97
  alpha: 1,
@@ -98,9 +101,6 @@ export const Normal: Story = {
98
101
  colorCorrection: {},
99
102
  fill: "#FFC0CB",
100
103
  },
101
- applyTransformer: false,
102
- startAt: 0,
103
- endAt: 10,
104
104
  initialAlpha: 1,
105
105
  },
106
106
  };
@@ -114,11 +114,14 @@ export const FadeIn: Story = {
114
114
  args: {
115
115
  uniqueId: "surya002", // uniqueId of the sprite
116
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
+ applyTransformer: false,
118
+ startAt: 0,
119
+ endAt: 10,
117
120
  transformation: {
118
- x: 100,
119
- y: 100,
120
- width: 150,
121
- height: 150,
121
+ x: 200,
122
+ y: 200,
123
+ width: 200,
124
+ height: 200,
122
125
  anchor: 0.5,
123
126
  rotation: 0,
124
127
  alpha: 1,
@@ -129,9 +132,43 @@ export const FadeIn: Story = {
129
132
  colorCorrection: {},
130
133
  fill: "#fe2c54",
131
134
  },
135
+ initialAlpha: 0,
136
+ },
137
+ };
138
+
139
+ // More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
140
+ export const Filters: Story = {
141
+ render: (args: any) => (
142
+ <AppStateContextProvider {...args}>
143
+ <PixiSvgPathSprite {...args} />
144
+ </AppStateContextProvider>
145
+ ),
146
+ args: {
147
+ uniqueId: "svgfilters001", // uniqueId of the sprite
148
+ path: "M 100 100 L 300 100 L 200 300 z",
132
149
  applyTransformer: false,
133
150
  startAt: 0,
134
151
  endAt: 10,
135
- initialAlpha: 0,
152
+ transformation: {
153
+ x: 200,
154
+ y: 200,
155
+ width: 200,
156
+ height: 200,
157
+ anchor: 0.5,
158
+ rotation: 0,
159
+ alpha: 1,
160
+ scale: 1,
161
+ tint: 0xffffff,
162
+ blendMode: 0,
163
+ colorCorrection: {
164
+ enabled: true,
165
+ contrast: 1,
166
+ saturation: 2,
167
+ exposure: 1,
168
+ blurRadius: 3,
169
+ },
170
+ fill: "#FFC0CB",
171
+ },
172
+ initialAlpha: 1,
136
173
  },
137
174
  };