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,22 +1,19 @@
1
1
  import * as React from "react";
2
- import { useContext, useEffect, useRef, useState } from "react";
2
+ import { useRef } from "react";
3
3
  // @ts-ignore
4
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";
5
+ import { Sprite, Container, useApp } from "@pixi/react";
8
6
  import * as PIXI from "pixi.js";
9
- import gsap from "gsap";
10
7
  import { SVG } from "pixi-svg";
11
- import PixiTransformer from "../../utils/PixiTransformer";
12
8
  // @ts-ignore
13
9
  import svgpath from "svgpath";
14
10
  // @ts-ignore
15
11
  import isEmpty from "lodash/isEmpty";
16
- import { getAnimByName } from "../../utils/GsapAnim";
17
- import { TransformationEnd } from "../../types/transformation";
12
+ import { PixiBaseSpriteProps } from "../../types/BaseProps";
13
+ import AbstractContainer from "../../hocs/AbstractContainer";
14
+ import { Effects } from "../../types/Effects";
18
15
 
19
- type PixiSvgPathSpriteProps = {
16
+ interface PixiSvgPathSpriteProps extends PixiBaseSpriteProps {
20
17
  uniqueId: string;
21
18
  path: string;
22
19
  startAt: number;
@@ -60,7 +57,7 @@ type PixiSvgPathSpriteProps = {
60
57
  alpha?: number;
61
58
  scaleInput?: number;
62
59
  };
63
- effect?: string;
60
+ effect?: Effects;
64
61
  };
65
62
  pointerdown?: () => void;
66
63
  pointerup?: () => void;
@@ -71,73 +68,32 @@ type PixiSvgPathSpriteProps = {
71
68
  mouseout?: () => void;
72
69
  applyTransformer?: boolean;
73
70
  onAnchorTransformationEnd?: (endData: any) => void;
74
- };
75
-
76
- type EffectFunc = () => void;
77
- type Deps = ReadonlyArray<unknown>;
78
-
79
- const Filters = withFilters(Container, {
80
- blur: PIXI.filters.BlurFilter,
81
- adjust: AdjustmentFilter,
82
- matrix: PIXI.filters.ColorMatrixFilter,
83
- });
84
-
85
- /** filter config */
86
- const config = {
87
- dot: {
88
- scale: 1,
89
- angle: 5,
90
- },
91
- blur: {
92
- blur: 0,
93
- quality: 4,
94
- },
95
- };
96
-
97
- /** CYAN Filters */
98
- const CYAN = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0];
71
+ }
99
72
 
100
73
  const PixiSvgPathSprite: React.FC<PixiSvgPathSpriteProps> = (props) => {
101
74
  //// State
102
- const [isMounted, setIsMounted] = React.useState(false);
103
- const [isTransformerDragging, setIsTransformerDragging] = useState(false);
104
- const [isMouseOverTransformer, setIsMouseOverTransformer] = useState(false);
105
75
  const [texture, setTexture] = React.useState<any>(null);
106
76
 
107
- console.log("allProps", props);
108
77
  //// Refs
109
78
  const imageRef = useRef<PIXI.Sprite>(null);
110
- const containerRef = useRef<PIXI.Container>(null);
111
79
  const parentNode = useRef<PIXI.Container>(null);
112
80
  const imgGroupRef = useRef<PIXI.Container>(null);
113
- const transformerRef = useRef<PIXI.Container>(null);
114
81
 
115
82
  //// Context
116
- const { tl } = useContext(GsapPixieContext);
117
83
 
118
84
  /// 1001
119
85
  // console.log("contxt Values", tl);
120
86
  const {
121
- uniqueId,
122
87
  path,
123
- startAt,
124
- endAt,
125
- initialAlpha,
126
88
  transformation: {
127
89
  x,
128
90
  y,
129
91
  width,
130
92
  height,
131
93
  anchor,
132
- animation,
133
- colorCorrection,
134
- effect,
135
94
  fill,
136
- fontWeight,
137
- fontStyle,
138
95
  stroke = "none",
139
96
  strokeWidth = 0,
140
- blurRadius = 0,
141
97
  },
142
98
  pointerdown,
143
99
  pointerup,
@@ -146,115 +102,11 @@ const PixiSvgPathSprite: React.FC<PixiSvgPathSpriteProps> = (props) => {
146
102
  pointerover,
147
103
  mouseover,
148
104
  mouseout,
149
- applyTransformer,
150
- onAnchorTransformationEnd,
151
- ...restProps
152
105
  } = props;
153
106
 
154
- // color corrections
155
- const {
156
- enabled = false,
157
- temperature = 1,
158
- hue = 1,
159
- contrast = 1,
160
- saturation = 1,
161
- exposure = 1,
162
- reset,
163
- sharpness = 1,
164
- value = 0,
165
- levels = 1,
166
- luminance = 0,
167
- enhance = 0,
168
- red = 150,
169
- green = 150,
170
- blue = 150,
171
- alpha = 1,
172
- scaleInput = 1,
173
- } = colorCorrection || {};
174
-
175
107
  const app = useApp();
176
108
 
177
- /** adjustment filter */
178
- const adjustments = {
179
- brightness: exposure,
180
- contrast,
181
- saturation,
182
- alpha,
183
- };
184
-
185
- const fillColor = PIXI.utils.string2hex(fill || "#262730");
186
-
187
- /** handle on tranformer onchange */
188
- const handleOnTransformChange = React.useCallback(() => {
189
- setIsTransformerDragging(true);
190
- }, []);
191
-
192
- // transformer to handle sprite transformation
193
- const handleOnTransformEnd = React.useCallback(
194
- (endData: TransformationEnd) => {
195
- console.log("changeEnd", endData);
196
- if (onAnchorTransformationEnd) {
197
- console.log("running onAnchorTransformationEnd");
198
- onAnchorTransformationEnd(endData);
199
- }
200
- },
201
- []
202
- );
203
-
204
- useEffect(() => {
205
- let ctx = gsap.context(() => {});
206
- if (containerRef.current && tl.current) {
207
- const data = {
208
- duration: Number(endAt) - Number(startAt),
209
- };
210
-
211
- const ease = getAnimByName(animation || "None");
212
- ctx = gsap.context(() => {
213
- if (!isEmpty(ease.from)) {
214
- tl.current
215
- .from(containerRef.current, { ...ease.from }, startAt)
216
- .to(imgGroupRef.current, { alpha: 1, duration: 0.2 }, startAt)
217
- .from(imgGroupRef.current, { ...data }, startAt)
218
- .to(containerRef.current, { alpha: 0, duration: 0.2 }, endAt - 0.2);
219
- } else if (!isEmpty(ease.to)) {
220
- tl.current
221
- .to(
222
- containerRef.current,
223
- { alpha: 1, duration: 0.2, ...ease.to },
224
- startAt
225
- )
226
- .from(imgGroupRef.current, { ...data }, startAt)
227
- .to(containerRef.current, { alpha: 0, duration: 0.2 }, endAt - 0.2);
228
- } else if (!isEmpty(ease.fromTo)) {
229
- tl.current
230
- .fromTo(
231
- containerRef.current,
232
- ease.fromTo?.from,
233
- ease.fromTo?.to,
234
- startAt
235
- )
236
- .from(imgGroupRef.current, { ...data }, startAt)
237
- .to(containerRef.current, { alpha: 0, duration: 0.2 }, endAt - 0.2);
238
- } else {
239
- tl.current
240
- .to(containerRef.current, { alpha: 1, duration: 0.01 }, startAt)
241
- .from(imgGroupRef.current, { ...data }, startAt)
242
- .to(
243
- containerRef.current,
244
- { alpha: 0, duration: 0.1 },
245
- Number(endAt) - Number(0.1)
246
- );
247
- }
248
- });
249
- }
250
- return () => ctx.revert(); // cleanup!
251
- }, [animation, startAt, endAt]);
252
-
253
- React.useEffect(() => {
254
- if (containerRef.current) {
255
- setIsMounted(true);
256
- }
257
- }, []);
109
+ // const fillColor = PIXI.utils.string2hex(fill || "#262730");
258
110
 
259
111
  React.useEffect(() => {
260
112
  const transformedPath = svgpath(path).scale(5).translate(0, 0).toString();
@@ -274,104 +126,32 @@ const PixiSvgPathSprite: React.FC<PixiSvgPathSpriteProps> = (props) => {
274
126
  }, [app, path, stroke, strokeWidth, fill]);
275
127
 
276
128
  return (
277
- // @ts-ignore
278
- <Container ref={parentNode}>
279
- {/* @ts-ignore */}
280
- <Container
281
- ref={containerRef}
282
- alpha={initialAlpha}
283
- position={[x, y]}
284
- pivot={[x, y]}
285
- width={width}
286
- height={height}
287
- >
288
- {colorCorrection && colorCorrection.enabled ? (
289
- <Filters
290
- scale={1}
291
- blur={{ blur: blurRadius, quality: 4 }}
292
- adjust={adjustments}
293
- apply={({ matrix }: { matrix: any }) => {
294
- if (effect === "BlackAndWhite") {
295
- matrix.desaturate();
296
- } else if (effect === "Sepia") {
297
- matrix.sepia();
298
- } else if (effect === "RetroVintage") {
299
- matrix.negative();
300
- } else if (effect === "NightVision") {
301
- matrix.negative();
302
- } else if (effect === "Normal") {
303
- matrix.reset();
304
- }
305
- }}
306
- matrix={{
307
- enabled: true,
129
+ <AbstractContainer {...props}>
130
+ <Container ref={parentNode}>
131
+ <Container ref={imgGroupRef}>
132
+ {texture && (
133
+ <Sprite
134
+ texture={texture}
135
+ width={width}
136
+ height={height}
137
+ anchor={anchor}
138
+ ref={imageRef}
139
+ x={x}
140
+ y={y}
308
141
  // @ts-ignore
309
- matrix: CYAN,
310
- }}
311
- >
312
- {/* @ts-ignore */}
313
-
314
- <Container ref={imgGroupRef}>
315
- {texture && (
316
- <Sprite
317
- texture={texture}
318
- width={width}
319
- height={height}
320
- anchor={anchor}
321
- ref={imageRef}
322
- x={x}
323
- y={y}
324
- // @ts-ignore
325
- interactive={true}
326
- pointerdown={pointerdown}
327
- pointerup={pointerup}
328
- pointerover={pointerover}
329
- mousedown={mousedown}
330
- mouseup={mouseup}
331
- mouseover={mouseover}
332
- mouseout={mouseout}
333
- />
334
- )}
335
- </Container>
336
- </Filters>
337
- ) : (
338
- // @ts-ignore
339
- <Container ref={imgGroupRef}>
340
- {texture && (
341
- <Sprite
342
- texture={texture}
343
- width={width}
344
- height={height}
345
- anchor={anchor}
346
- ref={imageRef}
347
- x={x}
348
- y={y}
349
- // @ts-ignore
350
- interactive={true}
351
- pointerdown={pointerdown}
352
- pointerup={pointerup}
353
- pointerover={pointerover}
354
- mousedown={mousedown}
355
- mouseup={mouseup}
356
- mouseover={mouseover}
357
- mouseout={mouseout}
358
- />
359
- )}
360
- </Container>
361
- )}
142
+ interactive={true}
143
+ pointerdown={pointerdown}
144
+ pointerup={pointerup}
145
+ pointerover={pointerover}
146
+ mousedown={mousedown}
147
+ mouseup={mouseup}
148
+ mouseover={mouseover}
149
+ mouseout={mouseout}
150
+ />
151
+ )}
152
+ </Container>
362
153
  </Container>
363
- {applyTransformer && (
364
- <PixiTransformer
365
- pixiTransformerRef={transformerRef}
366
- imageRef={containerRef}
367
- isMounted={isMounted}
368
- transformCommit={handleOnTransformEnd}
369
- transformChange={handleOnTransformChange}
370
- mouseoverEvent={setIsMouseOverTransformer}
371
- uniqueId={uniqueId}
372
- />
373
- )}
374
- </Container>
154
+ </AbstractContainer>
375
155
  );
376
156
  };
377
157
 
@@ -0,0 +1,228 @@
1
+ import type { Meta, StoryObj } from "@storybook/react";
2
+ import { PixiTextSprite } 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/TextSprite",
8
+ component: PixiTextSprite,
9
+
10
+ tags: ["autodocs"],
11
+ argTypes: {
12
+ uniqueId: {
13
+ control: "text",
14
+ description: "uniqueId of the sprite",
15
+ },
16
+ text: {
17
+ control: "text",
18
+ description: "Text to be displayed",
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
+ pointerup: {
73
+ action: "pointerup",
74
+ description: "pointerup event",
75
+ },
76
+ onTextUpdate: {
77
+ action: "onTextUpdate",
78
+ description: "onTextUpdate event",
79
+ },
80
+ },
81
+ } satisfies Meta<typeof PixiTextSprite>;
82
+
83
+ export default meta;
84
+ type Story = StoryObj<typeof meta>;
85
+
86
+ // More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
87
+ export const Normal: Story = {
88
+ render: (args: any) => (
89
+ <AppStateContextProvider {...args}>
90
+ <PixiTextSprite {...args} />
91
+ </AppStateContextProvider>
92
+ ),
93
+ args: {
94
+ uniqueId: "TextSpritexx001", // uniqueId of the sprite
95
+ text: "Hello Welcome to PixiJS",
96
+ locked: false,
97
+ applyTransformer: false,
98
+ transformation: {
99
+ x: 200,
100
+ y: 200,
101
+ width: 200,
102
+ height: 200,
103
+ anchor: 0.5,
104
+ rotation: 0,
105
+ alpha: 1,
106
+ scale: 1,
107
+ blendMode: 0,
108
+ colorCorrection: {},
109
+ fill: "#00ff99",
110
+ fontSize: 80,
111
+ fontFamily: "Arial",
112
+ align: "center",
113
+ stroke: "#522d2d",
114
+ strokeThickness: 0,
115
+ letterSpacing: 0,
116
+ lineHeight: 0,
117
+ dropShadow: false,
118
+ dropShadowColor: "#522d2d",
119
+ dropShadowBlur: 0,
120
+ wordWrap: false,
121
+ wordWrapWidth: 5000000,
122
+ padding: 10,
123
+ textBaseline: "alphabetic",
124
+ trim: false,
125
+ },
126
+ startAt: 0,
127
+ endAt: 10,
128
+ initialAlpha: 1,
129
+ },
130
+ };
131
+
132
+ export const FadeIn: Story = {
133
+ render: (args: any) => (
134
+ <AppStateContextProvider {...args}>
135
+ <PixiTextSprite {...args} />
136
+ </AppStateContextProvider>
137
+ ),
138
+ args: {
139
+ uniqueId: "TextSprite001", // uniqueId of the sprite
140
+ text: "Hello Welcome to PixiJS",
141
+ locked: false,
142
+ applyTransformer: false,
143
+ transformation: {
144
+ x: 200,
145
+ y: 200,
146
+ width: 200,
147
+ height: 200,
148
+ anchor: 0.5,
149
+ rotation: 0,
150
+ alpha: 1,
151
+ scale: 1,
152
+ tint: 0xffffff,
153
+ blendMode: 0,
154
+ colorCorrection: {},
155
+ fill: "#00ff99",
156
+ fontSize: 20,
157
+ fontFamily: "Arial",
158
+ align: "center",
159
+ stroke: 0x000000,
160
+ strokeThickness: 0,
161
+ letterSpacing: 0,
162
+ lineHeight: 0,
163
+ dropShadow: false,
164
+ dropShadowColor: 0x000000,
165
+ dropShadowBlur: 0,
166
+ wordWrap: false,
167
+ wordWrapWidth: 100,
168
+ padding: 0,
169
+ textBaseline: "alphabetic",
170
+ trim: false,
171
+ },
172
+ startAt: 0,
173
+ endAt: 10,
174
+ initialAlpha: 0,
175
+ },
176
+ };
177
+
178
+ // More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
179
+ export const Filters: Story = {
180
+ render: (args: any) => (
181
+ <AppStateContextProvider {...args}>
182
+ <PixiTextSprite {...args} />
183
+ </AppStateContextProvider>
184
+ ),
185
+ args: {
186
+ uniqueId: "TextSpritexx001", // uniqueId of the sprite
187
+ text: "Hello Welcome to PixiJS",
188
+ locked: false,
189
+ applyTransformer: false,
190
+ transformation: {
191
+ x: 200,
192
+ y: 200,
193
+ width: 200,
194
+ height: 200,
195
+ anchor: 0.5,
196
+ rotation: 0,
197
+ alpha: 1,
198
+ scale: 1,
199
+ blendMode: 0,
200
+ colorCorrection: {
201
+ enabled: true,
202
+ contrast: 2,
203
+ saturation: 2,
204
+ exposure: 2,
205
+ blurRadius: 1,
206
+ },
207
+ fill: "#00ff99",
208
+ fontSize: 80,
209
+ fontFamily: "Arial",
210
+ align: "center",
211
+ stroke: "#522d2d",
212
+ strokeThickness: 0,
213
+ letterSpacing: 0,
214
+ lineHeight: 0,
215
+ dropShadow: false,
216
+ dropShadowColor: "#522d2d",
217
+ dropShadowBlur: 0,
218
+ wordWrap: false,
219
+ wordWrapWidth: 5000000,
220
+ padding: 10,
221
+ textBaseline: "alphabetic",
222
+ trim: false,
223
+ },
224
+ startAt: 0,
225
+ endAt: 10,
226
+ initialAlpha: 1,
227
+ },
228
+ };