reacthub-pixitweenjs 0.2.6 → 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.
- package/CHANGELOG.md +13 -0
- package/package.json +1 -1
- package/src/components/PixiGifSprite/PixiGifSprite.stories.tsx +41 -4
- package/src/components/PixiGifSprite/PixiGifSprite.tsx +85 -37
- package/src/components/PixiImageSprite/PixiImageSprite.stories.tsx +53 -7
- package/src/components/PixiImageSprite/PixiImageSprite.tsx +27 -276
- package/src/components/PixiSVGSprite/PixiSvgPathSprite.stories.tsx +49 -12
- package/src/components/PixiSVGSprite/PixiSvgPathSprite.tsx +32 -220
- package/src/components/PixiTextSprite/PixiTextSprite.stories.tsx +60 -8
- package/src/components/PixiTextSprite/PixiTextSprite.tsx +44 -223
- package/src/components/PixiVideoSprite/PixiVideoSprite.stories.tsx +39 -0
- package/src/components/PixiVideoSprite/PixiVideoSprite.tsx +595 -631
- package/src/hocs/AbstractContainer.tsx +199 -0
- package/src/hocs/WithFilterContainer.tsx +159 -0
- package/src/types/Animations.tsx +41 -0
- package/src/types/BaseProps.tsx +56 -0
- package/src/types/BlendModes.tsx +19 -0
- package/src/types/Effects.tsx +10 -0
|
@@ -1,26 +1,20 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import {
|
|
3
|
-
import { Container,
|
|
4
|
-
import { AdjustmentFilter } from "@pixi/filter-adjustment";
|
|
2
|
+
import { useRef, useState } from "react";
|
|
3
|
+
import { Container, Text } from "@pixi/react";
|
|
5
4
|
import * as PIXI from "pixi.js";
|
|
6
|
-
import gsap from "gsap";
|
|
7
5
|
import Quill from "quill";
|
|
8
6
|
import "quill/dist/quill.snow.css";
|
|
9
7
|
// @ts-ignore
|
|
10
|
-
import PropTypes from "prop-types";
|
|
11
|
-
// @ts-ignore
|
|
12
8
|
import isEmpty from "lodash/isEmpty";
|
|
13
9
|
// @ts-ignore
|
|
14
10
|
import isEqual from "lodash/isEqual";
|
|
15
11
|
// @ts-ignore
|
|
16
12
|
import pick from "lodash/pick";
|
|
17
|
-
import {
|
|
18
|
-
import
|
|
19
|
-
import {
|
|
20
|
-
import { TransformationEnd } from "../../types/transformation";
|
|
13
|
+
import { PixiBaseSpriteProps } from "../../types/BaseProps";
|
|
14
|
+
import AbstractContainer from "../../hocs/AbstractContainer";
|
|
15
|
+
import { Effects } from "../../types/Effects";
|
|
21
16
|
|
|
22
|
-
|
|
23
|
-
uniqueId: string;
|
|
17
|
+
interface PixiTextSpriteProps extends PixiBaseSpriteProps {
|
|
24
18
|
text: string;
|
|
25
19
|
startAt: number;
|
|
26
20
|
endAt: number;
|
|
@@ -87,7 +81,7 @@ type PixiTextSpriteProps = {
|
|
|
87
81
|
alpha?: number;
|
|
88
82
|
scaleInput?: number;
|
|
89
83
|
};
|
|
90
|
-
effect?:
|
|
84
|
+
effect?: Effects;
|
|
91
85
|
};
|
|
92
86
|
pointerdown?: () => void;
|
|
93
87
|
pointerup?: () => void;
|
|
@@ -99,31 +93,15 @@ type PixiTextSpriteProps = {
|
|
|
99
93
|
applyTransformer?: boolean;
|
|
100
94
|
onTextUpdate?: (data: any) => void;
|
|
101
95
|
onAnchorTransformationEnd?: (endData: any) => void;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const Filters = withFilters(Container, {
|
|
105
|
-
blur: PIXI.filters.BlurFilter,
|
|
106
|
-
adjust: AdjustmentFilter,
|
|
107
|
-
matrix: PIXI.filters.ColorMatrixFilter,
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
/** CYAN Filters */
|
|
111
|
-
const CYAN = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0];
|
|
112
|
-
// change these to control the text size
|
|
96
|
+
}
|
|
113
97
|
|
|
114
98
|
const PixiTextSprite: React.FC<PixiTextSpriteProps> = (props) => {
|
|
115
99
|
//// State
|
|
116
|
-
const [isMounted, setIsMounted] = React.useState(false);
|
|
117
|
-
const [, setIsTransformerDragging] = useState(false);
|
|
118
|
-
const [, setIsMouseOverTransformer] = useState(false);
|
|
119
100
|
const [isEditing, setIsEditing] = useState(false);
|
|
120
101
|
|
|
121
102
|
console.log("allProps", props);
|
|
122
103
|
//// Refs
|
|
123
|
-
const containerRef = useRef<PIXI.Container>(null);
|
|
124
104
|
const parentNode = useRef<PIXI.Container>(null);
|
|
125
|
-
const imgGroupRef = useRef<PIXI.Container>(null);
|
|
126
|
-
const transformerRef = useRef<PIXI.Container>(null);
|
|
127
105
|
|
|
128
106
|
/// refs
|
|
129
107
|
const textRef = useRef<PIXI.Text>(null);
|
|
@@ -132,29 +110,24 @@ const PixiTextSprite: React.FC<PixiTextSpriteProps> = (props) => {
|
|
|
132
110
|
const textFontSize = useRef<number>(16);
|
|
133
111
|
const textTransformDetailRef = useRef<any>(null);
|
|
134
112
|
|
|
135
|
-
//// Context
|
|
136
|
-
const { tl } = useContext(GsapPixieContext);
|
|
137
|
-
|
|
138
113
|
/// 1001
|
|
139
114
|
// console.log("contxt Values", tl);
|
|
140
115
|
const {
|
|
141
116
|
uniqueId,
|
|
142
117
|
text,
|
|
143
|
-
startAt,
|
|
144
|
-
endAt,
|
|
145
|
-
initialAlpha,
|
|
146
118
|
locked,
|
|
147
119
|
transformation,
|
|
120
|
+
onTextUpdate,
|
|
148
121
|
pointerdown,
|
|
122
|
+
pointerup,
|
|
123
|
+
mousedown,
|
|
124
|
+
mouseup,
|
|
125
|
+
pointerover,
|
|
126
|
+
mouseover,
|
|
149
127
|
mouseout,
|
|
150
|
-
applyTransformer,
|
|
151
|
-
onAnchorTransformationEnd,
|
|
152
|
-
onTextUpdate,
|
|
153
128
|
} = props;
|
|
154
129
|
|
|
155
130
|
const {
|
|
156
|
-
width = 0,
|
|
157
|
-
height = 0,
|
|
158
131
|
scale = [1, 1],
|
|
159
132
|
x,
|
|
160
133
|
y,
|
|
@@ -180,91 +153,12 @@ const PixiTextSprite: React.FC<PixiTextSpriteProps> = (props) => {
|
|
|
180
153
|
wordWrapWidth = 50000000,
|
|
181
154
|
leading = 0,
|
|
182
155
|
letterSpacing,
|
|
183
|
-
colorCorrection = {},
|
|
184
|
-
animation,
|
|
185
|
-
effect,
|
|
186
156
|
} = transformation;
|
|
187
157
|
|
|
188
|
-
// color corrections
|
|
189
|
-
const {
|
|
190
|
-
contrast = 1,
|
|
191
|
-
saturation = 1,
|
|
192
|
-
exposure = 1,
|
|
193
|
-
alpha = 1,
|
|
194
|
-
} = colorCorrection || {};
|
|
195
|
-
|
|
196
|
-
/** adjustment filter */
|
|
197
|
-
const adjustments = {
|
|
198
|
-
brightness: exposure,
|
|
199
|
-
contrast,
|
|
200
|
-
saturation,
|
|
201
|
-
alpha,
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
/** handle on tranformer onchange */
|
|
205
|
-
const handleOnTransformChange = React.useCallback(() => {
|
|
206
|
-
setIsTransformerDragging(true);
|
|
207
|
-
}, []);
|
|
208
|
-
|
|
209
158
|
React.useEffect(() => {
|
|
210
159
|
textFontSize.current = Number(fontSize);
|
|
211
160
|
}, [fontSize]);
|
|
212
161
|
|
|
213
|
-
useEffect(() => {
|
|
214
|
-
let ctx = gsap.context(() => {});
|
|
215
|
-
if (containerRef.current && tl.current) {
|
|
216
|
-
const data = {
|
|
217
|
-
duration: Number(endAt) - Number(startAt),
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
const ease = getAnimByName(animation || "None");
|
|
221
|
-
ctx = gsap.context(() => {
|
|
222
|
-
if (!isEmpty(ease.from)) {
|
|
223
|
-
tl.current
|
|
224
|
-
.from(containerRef.current, { ...ease.from }, startAt)
|
|
225
|
-
.to(imgGroupRef.current, { alpha: 1, duration: 0.2 }, startAt)
|
|
226
|
-
.from(imgGroupRef.current, { ...data }, startAt)
|
|
227
|
-
.to(containerRef.current, { alpha: 0, duration: 0.2 }, endAt - 0.2);
|
|
228
|
-
} else if (!isEmpty(ease.to)) {
|
|
229
|
-
tl.current
|
|
230
|
-
.to(
|
|
231
|
-
containerRef.current,
|
|
232
|
-
{ alpha: 1, duration: 0.2, ...ease.to },
|
|
233
|
-
startAt
|
|
234
|
-
)
|
|
235
|
-
.from(imgGroupRef.current, { ...data }, startAt)
|
|
236
|
-
.to(containerRef.current, { alpha: 0, duration: 0.2 }, endAt - 0.2);
|
|
237
|
-
} else if (!isEmpty(ease.fromTo)) {
|
|
238
|
-
tl.current
|
|
239
|
-
.fromTo(
|
|
240
|
-
containerRef.current,
|
|
241
|
-
ease.fromTo?.from,
|
|
242
|
-
ease.fromTo?.to,
|
|
243
|
-
startAt
|
|
244
|
-
)
|
|
245
|
-
.from(imgGroupRef.current, { ...data }, startAt)
|
|
246
|
-
.to(containerRef.current, { alpha: 0, duration: 0.2 }, endAt - 0.2);
|
|
247
|
-
} else {
|
|
248
|
-
tl.current
|
|
249
|
-
.to(containerRef.current, { alpha: 1, duration: 0.01 }, startAt)
|
|
250
|
-
.from(imgGroupRef.current, { ...data }, startAt)
|
|
251
|
-
.to(
|
|
252
|
-
containerRef.current,
|
|
253
|
-
{ alpha: 0, duration: 0.1 },
|
|
254
|
-
Number(endAt) - Number(0.1)
|
|
255
|
-
);
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
return () => ctx.revert(); // cleanup!
|
|
260
|
-
}, [animation, startAt, endAt]);
|
|
261
|
-
|
|
262
|
-
React.useEffect(() => {
|
|
263
|
-
if (containerRef.current) {
|
|
264
|
-
setIsMounted(true);
|
|
265
|
-
}
|
|
266
|
-
}, []);
|
|
267
|
-
|
|
268
162
|
const nFontStyle = ["italic", "oblique"].includes(fontStyle)
|
|
269
163
|
? fontStyle
|
|
270
164
|
: undefined;
|
|
@@ -332,6 +226,7 @@ const PixiTextSprite: React.FC<PixiTextSpriteProps> = (props) => {
|
|
|
332
226
|
};
|
|
333
227
|
}, [transformation]);
|
|
334
228
|
|
|
229
|
+
// @ts-ignore
|
|
335
230
|
const handleOnDoubleClickEditText = () => {
|
|
336
231
|
console.log("double click triggered");
|
|
337
232
|
setIsEditing(true);
|
|
@@ -347,18 +242,6 @@ const PixiTextSprite: React.FC<PixiTextSpriteProps> = (props) => {
|
|
|
347
242
|
}
|
|
348
243
|
};
|
|
349
244
|
|
|
350
|
-
const handleOnTransformEnd = React.useCallback(
|
|
351
|
-
(endData: TransformationEnd) => {
|
|
352
|
-
if (!textRef.current) return;
|
|
353
|
-
console.log("enddata", endData);
|
|
354
|
-
if (onAnchorTransformationEnd) {
|
|
355
|
-
console.log("running onAnchorTransformationEnd");
|
|
356
|
-
onAnchorTransformationEnd(endData);
|
|
357
|
-
}
|
|
358
|
-
},
|
|
359
|
-
[onAnchorTransformationEnd, uniqueId, width]
|
|
360
|
-
);
|
|
361
|
-
|
|
362
245
|
// const handleOnMoveOver = (interactionData) => {
|
|
363
246
|
// if (!isDragging) {
|
|
364
247
|
// setMouseOverSprite(true);
|
|
@@ -435,99 +318,37 @@ const PixiTextSprite: React.FC<PixiTextSpriteProps> = (props) => {
|
|
|
435
318
|
}, [x, y, isEditing]);
|
|
436
319
|
|
|
437
320
|
return (
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
<Container
|
|
442
|
-
ref={containerRef}
|
|
443
|
-
alpha={initialAlpha}
|
|
444
|
-
position={[x, y]}
|
|
445
|
-
pivot={[x, y]}
|
|
446
|
-
width={width}
|
|
447
|
-
height={height}
|
|
448
|
-
>
|
|
321
|
+
<AbstractContainer {...props}>
|
|
322
|
+
<Container ref={parentNode}>
|
|
323
|
+
{/* @ts-ignore */}
|
|
449
324
|
{isEditing && <Container ref={textInputGroupRef}></Container>}
|
|
450
|
-
{
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
<Container alpha={isEditing ? 0 : 1} ref={textInnerGroupRef}>
|
|
476
|
-
<Text
|
|
477
|
-
style={pixiStyles}
|
|
478
|
-
x={x}
|
|
479
|
-
y={y}
|
|
480
|
-
rotation={rotation}
|
|
481
|
-
anchor={0.5}
|
|
482
|
-
text={text}
|
|
483
|
-
{...(!isEditing &&
|
|
484
|
-
!locked && {
|
|
485
|
-
interactive: true,
|
|
486
|
-
buttonMode: true,
|
|
487
|
-
pointerdown: pointerdown,
|
|
488
|
-
pointerout: mouseout,
|
|
489
|
-
})}
|
|
490
|
-
ref={textRef}
|
|
491
|
-
scale={scale}
|
|
492
|
-
/>
|
|
493
|
-
</Container>
|
|
494
|
-
</Filters>
|
|
495
|
-
) : (
|
|
496
|
-
// @ts-ignore
|
|
497
|
-
<Container alpha={isEditing ? 0 : 1} ref={textInnerGroupRef}>
|
|
498
|
-
<Text
|
|
499
|
-
style={pixiStyles}
|
|
500
|
-
x={x}
|
|
501
|
-
y={y}
|
|
502
|
-
rotation={rotation}
|
|
503
|
-
anchor={0.5}
|
|
504
|
-
text={text}
|
|
505
|
-
{...(!isEditing &&
|
|
506
|
-
!locked && {
|
|
507
|
-
interactive: true,
|
|
508
|
-
buttonMode: true,
|
|
509
|
-
pointerdown: pointerdown,
|
|
510
|
-
pointerout: mouseout,
|
|
511
|
-
})}
|
|
512
|
-
ref={textRef}
|
|
513
|
-
scale={scale}
|
|
514
|
-
/>
|
|
515
|
-
</Container>
|
|
516
|
-
)}
|
|
325
|
+
{/* @ts-ignore */}
|
|
326
|
+
<Container alpha={isEditing ? 0 : 1} ref={textInnerGroupRef}>
|
|
327
|
+
<Text
|
|
328
|
+
style={pixiStyles}
|
|
329
|
+
x={x}
|
|
330
|
+
y={y}
|
|
331
|
+
rotation={rotation}
|
|
332
|
+
anchor={0.5}
|
|
333
|
+
text={text}
|
|
334
|
+
{...(!isEditing &&
|
|
335
|
+
!locked && {
|
|
336
|
+
interactive: true,
|
|
337
|
+
buttonMode: true,
|
|
338
|
+
pointerdown: pointerdown,
|
|
339
|
+
pointerout: mouseout,
|
|
340
|
+
pointerover: pointerover,
|
|
341
|
+
pointerup: pointerup,
|
|
342
|
+
mousedown: mousedown,
|
|
343
|
+
mouseup: mouseup,
|
|
344
|
+
mouseover: mouseover,
|
|
345
|
+
})}
|
|
346
|
+
ref={textRef}
|
|
347
|
+
scale={scale}
|
|
348
|
+
/>
|
|
349
|
+
</Container>
|
|
517
350
|
</Container>
|
|
518
|
-
|
|
519
|
-
<PixiTransformer
|
|
520
|
-
pixiTransformerRef={transformerRef}
|
|
521
|
-
imageRef={containerRef}
|
|
522
|
-
isMounted={isMounted}
|
|
523
|
-
transformCommit={handleOnTransformEnd}
|
|
524
|
-
transformChange={handleOnTransformChange}
|
|
525
|
-
mouseoverEvent={setIsMouseOverTransformer}
|
|
526
|
-
uniqueId={uniqueId}
|
|
527
|
-
onDoubleClick={handleOnDoubleClickEditText}
|
|
528
|
-
/>
|
|
529
|
-
)}
|
|
530
|
-
</Container>
|
|
351
|
+
</AbstractContainer>
|
|
531
352
|
);
|
|
532
353
|
};
|
|
533
354
|
|
|
@@ -145,3 +145,42 @@ export const FadeIn: Story = {
|
|
|
145
145
|
locked: false,
|
|
146
146
|
},
|
|
147
147
|
};
|
|
148
|
+
|
|
149
|
+
export const Filters: Story = {
|
|
150
|
+
render: (args: any) => (
|
|
151
|
+
<AppStateContextProvider {...args}>
|
|
152
|
+
<PixiVideoSprite {...args} />
|
|
153
|
+
</AppStateContextProvider>
|
|
154
|
+
),
|
|
155
|
+
args: {
|
|
156
|
+
uniqueId: "videofiter002", // uniqueId of the sprite
|
|
157
|
+
src: "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4",
|
|
158
|
+
transformation: {
|
|
159
|
+
x: 290,
|
|
160
|
+
y: 250,
|
|
161
|
+
width: 550,
|
|
162
|
+
height: 400,
|
|
163
|
+
anchor: 0.5,
|
|
164
|
+
rotation: 0,
|
|
165
|
+
alpha: 1,
|
|
166
|
+
scale: 1,
|
|
167
|
+
tint: 0xffffff,
|
|
168
|
+
blendMode: 0,
|
|
169
|
+
colorCorrection: {
|
|
170
|
+
enabled: true,
|
|
171
|
+
contrast: 2,
|
|
172
|
+
saturation: 2,
|
|
173
|
+
exposure: 2,
|
|
174
|
+
blurRadius: 1,
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
applyTransformer: false,
|
|
178
|
+
startAt: 0,
|
|
179
|
+
endAt: 10,
|
|
180
|
+
frameStartAt: 0,
|
|
181
|
+
frameEndAt: 10,
|
|
182
|
+
initialAlpha: 1,
|
|
183
|
+
mute: false,
|
|
184
|
+
locked: false,
|
|
185
|
+
},
|
|
186
|
+
};
|