reacthub-pixitweenjs 0.2.6 → 0.2.8

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.
@@ -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,55 +68,32 @@ type PixiSvgPathSpriteProps = {
71
68
  mouseout?: () => void;
72
69
  applyTransformer?: boolean;
73
70
  onAnchorTransformationEnd?: (endData: any) => void;
74
- };
75
-
76
- const Filters = withFilters(Container, {
77
- blur: PIXI.filters.BlurFilter,
78
- adjust: AdjustmentFilter,
79
- matrix: PIXI.filters.ColorMatrixFilter,
80
- });
81
-
82
- /** CYAN Filters */
83
- const CYAN = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0];
71
+ }
84
72
 
85
73
  const PixiSvgPathSprite: React.FC<PixiSvgPathSpriteProps> = (props) => {
86
74
  //// State
87
- const [isMounted, setIsMounted] = React.useState(false);
88
- const [, setIsTransformerDragging] = useState(false);
89
- const [, setIsMouseOverTransformer] = useState(false);
90
75
  const [texture, setTexture] = React.useState<any>(null);
91
76
 
92
77
  //// Refs
93
78
  const imageRef = useRef<PIXI.Sprite>(null);
94
- const containerRef = useRef<PIXI.Container>(null);
95
79
  const parentNode = useRef<PIXI.Container>(null);
96
80
  const imgGroupRef = useRef<PIXI.Container>(null);
97
- const transformerRef = useRef<PIXI.Container>(null);
98
81
 
99
82
  //// Context
100
- const { tl } = useContext(GsapPixieContext);
101
83
 
102
84
  /// 1001
103
85
  // console.log("contxt Values", tl);
104
86
  const {
105
- uniqueId,
106
87
  path,
107
- startAt,
108
- endAt,
109
- initialAlpha,
110
88
  transformation: {
111
89
  x,
112
90
  y,
113
91
  width,
114
92
  height,
115
93
  anchor,
116
- animation,
117
- colorCorrection,
118
- effect,
119
94
  fill,
120
95
  stroke = "none",
121
96
  strokeWidth = 0,
122
- blurRadius = 0,
123
97
  },
124
98
  pointerdown,
125
99
  pointerup,
@@ -128,102 +102,12 @@ const PixiSvgPathSprite: React.FC<PixiSvgPathSpriteProps> = (props) => {
128
102
  pointerover,
129
103
  mouseover,
130
104
  mouseout,
131
- applyTransformer,
132
- onAnchorTransformationEnd,
133
105
  } = props;
134
106
 
135
- // color corrections
136
- const {
137
- contrast = 1,
138
- saturation = 1,
139
- exposure = 1,
140
- alpha = 1,
141
- } = colorCorrection || {};
142
-
143
107
  const app = useApp();
144
108
 
145
- /** adjustment filter */
146
- const adjustments = {
147
- brightness: exposure,
148
- contrast,
149
- saturation,
150
- alpha,
151
- };
152
-
153
109
  // const fillColor = PIXI.utils.string2hex(fill || "#262730");
154
110
 
155
- /** handle on tranformer onchange */
156
- const handleOnTransformChange = React.useCallback(() => {
157
- setIsTransformerDragging(true);
158
- }, []);
159
-
160
- // transformer to handle sprite transformation
161
- const handleOnTransformEnd = React.useCallback(
162
- (endData: TransformationEnd) => {
163
- console.log("changeEnd", endData);
164
- if (onAnchorTransformationEnd) {
165
- console.log("running onAnchorTransformationEnd");
166
- onAnchorTransformationEnd(endData);
167
- }
168
- },
169
- []
170
- );
171
-
172
- useEffect(() => {
173
- let ctx = gsap.context(() => {});
174
- if (containerRef.current && tl.current) {
175
- const data = {
176
- duration: Number(endAt) - Number(startAt),
177
- };
178
-
179
- const ease = getAnimByName(animation || "None");
180
- ctx = gsap.context(() => {
181
- if (!isEmpty(ease.from)) {
182
- tl.current
183
- .from(containerRef.current, { ...ease.from }, startAt)
184
- .to(imgGroupRef.current, { alpha: 1, duration: 0.2 }, startAt)
185
- .from(imgGroupRef.current, { ...data }, startAt)
186
- .to(containerRef.current, { alpha: 0, duration: 0.2 }, endAt - 0.2);
187
- } else if (!isEmpty(ease.to)) {
188
- tl.current
189
- .to(
190
- containerRef.current,
191
- { alpha: 1, duration: 0.2, ...ease.to },
192
- startAt
193
- )
194
- .from(imgGroupRef.current, { ...data }, startAt)
195
- .to(containerRef.current, { alpha: 0, duration: 0.2 }, endAt - 0.2);
196
- } else if (!isEmpty(ease.fromTo)) {
197
- tl.current
198
- .fromTo(
199
- containerRef.current,
200
- ease.fromTo?.from,
201
- ease.fromTo?.to,
202
- startAt
203
- )
204
- .from(imgGroupRef.current, { ...data }, startAt)
205
- .to(containerRef.current, { alpha: 0, duration: 0.2 }, endAt - 0.2);
206
- } else {
207
- tl.current
208
- .to(containerRef.current, { alpha: 1, duration: 0.01 }, startAt)
209
- .from(imgGroupRef.current, { ...data }, startAt)
210
- .to(
211
- containerRef.current,
212
- { alpha: 0, duration: 0.1 },
213
- Number(endAt) - Number(0.1)
214
- );
215
- }
216
- });
217
- }
218
- return () => ctx.revert(); // cleanup!
219
- }, [animation, startAt, endAt]);
220
-
221
- React.useEffect(() => {
222
- if (containerRef.current) {
223
- setIsMounted(true);
224
- }
225
- }, []);
226
-
227
111
  React.useEffect(() => {
228
112
  const transformedPath = svgpath(path).scale(5).translate(0, 0).toString();
229
113
  // console.log('path', path);
@@ -242,104 +126,32 @@ const PixiSvgPathSprite: React.FC<PixiSvgPathSpriteProps> = (props) => {
242
126
  }, [app, path, stroke, strokeWidth, fill]);
243
127
 
244
128
  return (
245
- // @ts-ignore
246
- <Container ref={parentNode}>
247
- {/* @ts-ignore */}
248
- <Container
249
- ref={containerRef}
250
- alpha={initialAlpha}
251
- position={[x, y]}
252
- pivot={[x, y]}
253
- width={width}
254
- height={height}
255
- >
256
- {colorCorrection && colorCorrection.enabled ? (
257
- <Filters
258
- scale={1}
259
- blur={{ blur: blurRadius, quality: 4 }}
260
- adjust={adjustments}
261
- apply={({ matrix }: { matrix: any }) => {
262
- if (effect === "BlackAndWhite") {
263
- matrix.desaturate();
264
- } else if (effect === "Sepia") {
265
- matrix.sepia();
266
- } else if (effect === "RetroVintage") {
267
- matrix.negative();
268
- } else if (effect === "NightVision") {
269
- matrix.negative();
270
- } else if (effect === "Normal") {
271
- matrix.reset();
272
- }
273
- }}
274
- matrix={{
275
- 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}
276
141
  // @ts-ignore
277
- matrix: CYAN,
278
- }}
279
- >
280
- {/* @ts-ignore */}
281
-
282
- <Container ref={imgGroupRef}>
283
- {texture && (
284
- <Sprite
285
- texture={texture}
286
- width={width}
287
- height={height}
288
- anchor={anchor}
289
- ref={imageRef}
290
- x={x}
291
- y={y}
292
- // @ts-ignore
293
- interactive={true}
294
- pointerdown={pointerdown}
295
- pointerup={pointerup}
296
- pointerover={pointerover}
297
- mousedown={mousedown}
298
- mouseup={mouseup}
299
- mouseover={mouseover}
300
- mouseout={mouseout}
301
- />
302
- )}
303
- </Container>
304
- </Filters>
305
- ) : (
306
- // @ts-ignore
307
- <Container ref={imgGroupRef}>
308
- {texture && (
309
- <Sprite
310
- texture={texture}
311
- width={width}
312
- height={height}
313
- anchor={anchor}
314
- ref={imageRef}
315
- x={x}
316
- y={y}
317
- // @ts-ignore
318
- interactive={true}
319
- pointerdown={pointerdown}
320
- pointerup={pointerup}
321
- pointerover={pointerover}
322
- mousedown={mousedown}
323
- mouseup={mouseup}
324
- mouseover={mouseover}
325
- mouseout={mouseout}
326
- />
327
- )}
328
- </Container>
329
- )}
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>
330
153
  </Container>
331
- {applyTransformer && (
332
- <PixiTransformer
333
- pixiTransformerRef={transformerRef}
334
- imageRef={containerRef}
335
- isMounted={isMounted}
336
- transformCommit={handleOnTransformEnd}
337
- transformChange={handleOnTransformChange}
338
- mouseoverEvent={setIsMouseOverTransformer}
339
- uniqueId={uniqueId}
340
- />
341
- )}
342
- </Container>
154
+ </AbstractContainer>
343
155
  );
344
156
  };
345
157
 
@@ -96,10 +96,10 @@ export const Normal: Story = {
96
96
  locked: false,
97
97
  applyTransformer: false,
98
98
  transformation: {
99
- x: 100,
100
- y: 100,
101
- width: 150,
102
- height: 150,
99
+ x: 200,
100
+ y: 200,
101
+ width: 200,
102
+ height: 200,
103
103
  anchor: 0.5,
104
104
  rotation: 0,
105
105
  alpha: 1,
@@ -141,10 +141,10 @@ export const FadeIn: Story = {
141
141
  locked: false,
142
142
  applyTransformer: false,
143
143
  transformation: {
144
- x: 100,
145
- y: 100,
146
- width: 150,
147
- height: 150,
144
+ x: 200,
145
+ y: 200,
146
+ width: 200,
147
+ height: 200,
148
148
  anchor: 0.5,
149
149
  rotation: 0,
150
150
  alpha: 1,
@@ -174,3 +174,55 @@ export const FadeIn: Story = {
174
174
  initialAlpha: 0,
175
175
  },
176
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
+ };