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.
- package/.storybook/preview.tsx +6 -0
- package/CHANGELOG.md +26 -0
- package/README.md +1 -1
- package/package.json +4 -1
- package/src/components/PixiAudioSprite/PixiAudioSprite.tsx +5 -15
- package/src/components/PixiGifSprite/PixiGifSprite.stories.tsx +41 -4
- package/src/components/PixiGifSprite/PixiGifSprite.tsx +64 -95
- package/src/components/PixiImageSprite/PixiImageSprite.stories.tsx +53 -7
- package/src/components/PixiImageSprite/PixiImageSprite.tsx +27 -307
- package/src/components/PixiSVGSprite/PixiSvgPathSprite.stories.tsx +51 -14
- package/src/components/PixiSVGSprite/PixiSvgPathSprite.tsx +33 -253
- package/src/components/PixiTextSprite/PixiTextSprite.stories.tsx +228 -0
- package/src/components/PixiTextSprite/PixiTextSprite.tsx +361 -0
- package/src/components/PixiTextSprite/index.ts +1 -0
- package/src/components/PixiVideoSprite/PixiVideoSprite.stories.tsx +39 -0
- package/src/components/PixiVideoSprite/PixiVideoSprite.tsx +595 -684
- package/src/hocs/AbstractContainer.tsx +199 -0
- package/src/hocs/WithFilterContainer.tsx +159 -0
- package/src/main.tsx +8 -7
- package/src/providers/GsapPixieContextProvider.tsx +14 -20
- package/src/stories/Installation.mdx +3 -3
- 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
- package/src/utils/AppStateProvider.tsx +3 -3
- package/src/utils/AppStateStage.tsx +1 -13
- package/src/utils/AppWrapper.tsx +4 -0
- package/src/utils/GsapAnim.tsx +1 -7
- package/src/utils/InteractionManager.tsx +36 -0
- package/src/utils/PixiTransformer.tsx +68 -3
- package/src/utils/VideoSeekBar.tsx +4 -11
- package/src/hooks/usePixiTransformer.tsx +0 -168
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { useRef, useState } from "react";
|
|
3
|
+
import { Container, Text } from "@pixi/react";
|
|
4
|
+
import * as PIXI from "pixi.js";
|
|
5
|
+
import Quill from "quill";
|
|
6
|
+
import "quill/dist/quill.snow.css";
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
import isEmpty from "lodash/isEmpty";
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
import isEqual from "lodash/isEqual";
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
import pick from "lodash/pick";
|
|
13
|
+
import { PixiBaseSpriteProps } from "../../types/BaseProps";
|
|
14
|
+
import AbstractContainer from "../../hocs/AbstractContainer";
|
|
15
|
+
import { Effects } from "../../types/Effects";
|
|
16
|
+
|
|
17
|
+
interface PixiTextSpriteProps extends PixiBaseSpriteProps {
|
|
18
|
+
text: string;
|
|
19
|
+
startAt: number;
|
|
20
|
+
endAt: number;
|
|
21
|
+
initialAlpha: number;
|
|
22
|
+
locked: boolean;
|
|
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
|
+
fontWeight?: string;
|
|
36
|
+
fontSize?: number;
|
|
37
|
+
fontFamily?: string;
|
|
38
|
+
fontStyle?: string;
|
|
39
|
+
fontColor?: string;
|
|
40
|
+
fontVariant?: string;
|
|
41
|
+
lineHeight?: number;
|
|
42
|
+
letterSpacing?: number;
|
|
43
|
+
textDecoration?: string;
|
|
44
|
+
wordWrap?: boolean;
|
|
45
|
+
wordWrapWidth?: number;
|
|
46
|
+
leading?: number;
|
|
47
|
+
padding?: number;
|
|
48
|
+
border?: string;
|
|
49
|
+
dropShadow?: boolean;
|
|
50
|
+
dropShadowColor?: string | number;
|
|
51
|
+
shadowOffsetX?: number;
|
|
52
|
+
shadowOffsetY?: number;
|
|
53
|
+
dropShadowBlur?: number;
|
|
54
|
+
blurEnabled?: boolean;
|
|
55
|
+
blurRadius?: number;
|
|
56
|
+
fill: string | number;
|
|
57
|
+
stroke?: string | number;
|
|
58
|
+
strokeThickness?: number;
|
|
59
|
+
zIndex?: number;
|
|
60
|
+
align?: string;
|
|
61
|
+
textBaseline?: string;
|
|
62
|
+
trim?: boolean;
|
|
63
|
+
|
|
64
|
+
colorCorrection?: {
|
|
65
|
+
enabled?: boolean;
|
|
66
|
+
temperature?: number;
|
|
67
|
+
hue?: number;
|
|
68
|
+
contrast?: number;
|
|
69
|
+
saturation?: number;
|
|
70
|
+
exposure?: number;
|
|
71
|
+
reset?: boolean;
|
|
72
|
+
sharpness?: number;
|
|
73
|
+
value?: number;
|
|
74
|
+
levels?: number;
|
|
75
|
+
luminance?: number;
|
|
76
|
+
enhance?: number;
|
|
77
|
+
blurRadius?: number;
|
|
78
|
+
red?: number;
|
|
79
|
+
green?: number;
|
|
80
|
+
blue?: number;
|
|
81
|
+
alpha?: number;
|
|
82
|
+
scaleInput?: number;
|
|
83
|
+
};
|
|
84
|
+
effect?: Effects;
|
|
85
|
+
};
|
|
86
|
+
pointerdown?: () => void;
|
|
87
|
+
pointerup?: () => void;
|
|
88
|
+
mousedown?: () => void;
|
|
89
|
+
mouseup?: () => void;
|
|
90
|
+
pointerover?: () => void;
|
|
91
|
+
mouseover?: () => void;
|
|
92
|
+
mouseout?: () => void;
|
|
93
|
+
applyTransformer?: boolean;
|
|
94
|
+
onTextUpdate?: (data: any) => void;
|
|
95
|
+
onAnchorTransformationEnd?: (endData: any) => void;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const PixiTextSprite: React.FC<PixiTextSpriteProps> = (props) => {
|
|
99
|
+
//// State
|
|
100
|
+
const [isEditing, setIsEditing] = useState(false);
|
|
101
|
+
|
|
102
|
+
console.log("allProps", props);
|
|
103
|
+
//// Refs
|
|
104
|
+
const parentNode = useRef<PIXI.Container>(null);
|
|
105
|
+
|
|
106
|
+
/// refs
|
|
107
|
+
const textRef = useRef<PIXI.Text>(null);
|
|
108
|
+
const textInputGroupRef = useRef(null);
|
|
109
|
+
const textInnerGroupRef = useRef(null);
|
|
110
|
+
const textFontSize = useRef<number>(16);
|
|
111
|
+
const textTransformDetailRef = useRef<any>(null);
|
|
112
|
+
|
|
113
|
+
/// 1001
|
|
114
|
+
// console.log("contxt Values", tl);
|
|
115
|
+
const {
|
|
116
|
+
uniqueId,
|
|
117
|
+
text,
|
|
118
|
+
locked,
|
|
119
|
+
transformation,
|
|
120
|
+
onTextUpdate,
|
|
121
|
+
pointerdown,
|
|
122
|
+
pointerup,
|
|
123
|
+
mousedown,
|
|
124
|
+
mouseup,
|
|
125
|
+
pointerover,
|
|
126
|
+
mouseover,
|
|
127
|
+
mouseout,
|
|
128
|
+
} = props;
|
|
129
|
+
|
|
130
|
+
const {
|
|
131
|
+
scale = [1, 1],
|
|
132
|
+
x,
|
|
133
|
+
y,
|
|
134
|
+
rotation = 1,
|
|
135
|
+
/// font
|
|
136
|
+
fontFamily = "Arial",
|
|
137
|
+
fontWeight = "normal",
|
|
138
|
+
fontStyle = "normal",
|
|
139
|
+
fontSize = 16,
|
|
140
|
+
|
|
141
|
+
// fill
|
|
142
|
+
fill = "black",
|
|
143
|
+
|
|
144
|
+
// stroke
|
|
145
|
+
stroke,
|
|
146
|
+
strokeThickness: strokeWidth,
|
|
147
|
+
// drop shadow
|
|
148
|
+
blurRadius = 0,
|
|
149
|
+
blurEnabled = false,
|
|
150
|
+
dropShadowColor: shadowColor = null,
|
|
151
|
+
|
|
152
|
+
// multiline
|
|
153
|
+
wordWrapWidth = 50000000,
|
|
154
|
+
leading = 0,
|
|
155
|
+
letterSpacing,
|
|
156
|
+
} = transformation;
|
|
157
|
+
|
|
158
|
+
React.useEffect(() => {
|
|
159
|
+
textFontSize.current = Number(fontSize);
|
|
160
|
+
}, [fontSize]);
|
|
161
|
+
|
|
162
|
+
const nFontStyle = ["italic", "oblique"].includes(fontStyle)
|
|
163
|
+
? fontStyle
|
|
164
|
+
: undefined;
|
|
165
|
+
|
|
166
|
+
const nFontWeight = ["bold", "lighter", "100", "200", "300"].includes(
|
|
167
|
+
fontWeight
|
|
168
|
+
)
|
|
169
|
+
? fontWeight
|
|
170
|
+
: undefined;
|
|
171
|
+
|
|
172
|
+
const nLetterSpacing = Number(letterSpacing) > 0 ? letterSpacing : undefined;
|
|
173
|
+
|
|
174
|
+
const pixiStyles = React.useMemo(() => {
|
|
175
|
+
return new PIXI.TextStyle({
|
|
176
|
+
fontFamily: fontFamily,
|
|
177
|
+
fontSize: fontSize,
|
|
178
|
+
fill: fill || "white", //[color, '#00ff99'], // gradient
|
|
179
|
+
stroke: stroke,
|
|
180
|
+
strokeThickness: strokeWidth,
|
|
181
|
+
...(nFontStyle && {
|
|
182
|
+
fontStyle: nFontStyle as unknown as PIXI.TextStyleFontStyle,
|
|
183
|
+
}),
|
|
184
|
+
...(nFontWeight && {
|
|
185
|
+
fontWeight: nFontWeight as unknown as PIXI.TextStyleFontWeight,
|
|
186
|
+
}),
|
|
187
|
+
...(nLetterSpacing && { letterSpacing: nLetterSpacing }),
|
|
188
|
+
...(blurEnabled && {
|
|
189
|
+
dropShadow: true,
|
|
190
|
+
dropShadowBlur: Number(blurRadius),
|
|
191
|
+
dropShadowColor: shadowColor?.toString() || "black",
|
|
192
|
+
// / dropShadowAngle: Math.PI / 6,
|
|
193
|
+
dropShadowDistance: 0,
|
|
194
|
+
}),
|
|
195
|
+
wordWrap: true,
|
|
196
|
+
breakWords: true,
|
|
197
|
+
wordWrapWidth: wordWrapWidth || 500,
|
|
198
|
+
leading: leading || 0,
|
|
199
|
+
// lineHeight: lineHeight,
|
|
200
|
+
});
|
|
201
|
+
}, [
|
|
202
|
+
blurEnabled,
|
|
203
|
+
blurRadius,
|
|
204
|
+
fill,
|
|
205
|
+
fontFamily,
|
|
206
|
+
fontSize,
|
|
207
|
+
leading,
|
|
208
|
+
nFontStyle,
|
|
209
|
+
nFontWeight,
|
|
210
|
+
nLetterSpacing,
|
|
211
|
+
shadowColor,
|
|
212
|
+
stroke,
|
|
213
|
+
strokeWidth,
|
|
214
|
+
wordWrapWidth,
|
|
215
|
+
]);
|
|
216
|
+
|
|
217
|
+
// let textMetrics = {};
|
|
218
|
+
// if (!isEmpty(text) && !isEmpty(pixiStyles)) {
|
|
219
|
+
// textMetrics = PIXI.TextMetrics.measureText(text, pixiStyles);
|
|
220
|
+
// }
|
|
221
|
+
|
|
222
|
+
// On transformation change, update the textTransformDetailRef
|
|
223
|
+
React.useEffect(() => {
|
|
224
|
+
textTransformDetailRef.current = {
|
|
225
|
+
...transformation,
|
|
226
|
+
};
|
|
227
|
+
}, [transformation]);
|
|
228
|
+
|
|
229
|
+
// @ts-ignore
|
|
230
|
+
const handleOnDoubleClickEditText = () => {
|
|
231
|
+
console.log("double click triggered");
|
|
232
|
+
setIsEditing(true);
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
const handleTextChange = (e: string) => {
|
|
236
|
+
if (onTextUpdate) {
|
|
237
|
+
onTextUpdate({
|
|
238
|
+
text: e,
|
|
239
|
+
uniqueId: uniqueId,
|
|
240
|
+
droptype: "titles",
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
// const handleOnMoveOver = (interactionData) => {
|
|
246
|
+
// if (!isDragging) {
|
|
247
|
+
// setMouseOverSprite(true);
|
|
248
|
+
// }
|
|
249
|
+
// };
|
|
250
|
+
|
|
251
|
+
// const handleOnMoveOut = () => {
|
|
252
|
+
// if (!isDragging) {
|
|
253
|
+
// setMouseOverSprite(false);
|
|
254
|
+
// }
|
|
255
|
+
// };
|
|
256
|
+
|
|
257
|
+
React.useEffect(() => {
|
|
258
|
+
if (isEditing && textInputGroupRef.current) {
|
|
259
|
+
let el = document.getElementById("note-editor");
|
|
260
|
+
if (el) {
|
|
261
|
+
el.style.position = "absolute";
|
|
262
|
+
el.style.zIndex = "10";
|
|
263
|
+
el.style.left = x + "px";
|
|
264
|
+
el.style.top = y + "px";
|
|
265
|
+
el.style.backgroundColor = "var(--chakra-color-darkShark)";
|
|
266
|
+
el.style.transform = "scale(1.5)";
|
|
267
|
+
el.style.width = 300 + "px";
|
|
268
|
+
el.style.height = 100 + "px";
|
|
269
|
+
el.style.color = "#fff";
|
|
270
|
+
el.style.fontSize = "20px";
|
|
271
|
+
el.style.border = "1px solid #CBCEE0";
|
|
272
|
+
|
|
273
|
+
const keyboardbindings = {
|
|
274
|
+
// This will overwrite the default binding also named 'tab'
|
|
275
|
+
esc: {
|
|
276
|
+
key: 27,
|
|
277
|
+
handler: function () {
|
|
278
|
+
setIsEditing(false);
|
|
279
|
+
/// onUnSelectKeyFrame();
|
|
280
|
+
},
|
|
281
|
+
},
|
|
282
|
+
enter: {
|
|
283
|
+
key: 13,
|
|
284
|
+
handler: function () {
|
|
285
|
+
setIsEditing(false);
|
|
286
|
+
/// onUnSelectKeyFrame();
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
var quill = new Quill("#note-editor", {
|
|
292
|
+
modules: {
|
|
293
|
+
toolbar: false,
|
|
294
|
+
keyboard: {
|
|
295
|
+
bindings: {
|
|
296
|
+
...keyboardbindings,
|
|
297
|
+
},
|
|
298
|
+
},
|
|
299
|
+
},
|
|
300
|
+
placeholder: "Compose your text here...",
|
|
301
|
+
theme: "snow", // or 'bubble'
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
quill.on("text-change", function () {
|
|
305
|
+
handleTextChange(quill.root.innerText);
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
quill.setText(text);
|
|
309
|
+
quill.focus();
|
|
310
|
+
quill.off("text-change", () => {
|
|
311
|
+
console.log("removed");
|
|
312
|
+
});
|
|
313
|
+
if (!quill.hasFocus()) {
|
|
314
|
+
el.style.display = "none";
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}, [x, y, isEditing]);
|
|
319
|
+
|
|
320
|
+
return (
|
|
321
|
+
<AbstractContainer {...props}>
|
|
322
|
+
<Container ref={parentNode}>
|
|
323
|
+
{/* @ts-ignore */}
|
|
324
|
+
{isEditing && <Container ref={textInputGroupRef}></Container>}
|
|
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>
|
|
350
|
+
</Container>
|
|
351
|
+
</AbstractContainer>
|
|
352
|
+
);
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
export default PixiTextSprite;
|
|
356
|
+
|
|
357
|
+
// @ts-ignore
|
|
358
|
+
// PixiTextSprite.whyDidYouRender = {
|
|
359
|
+
// logOnDifferentValues: true,
|
|
360
|
+
// customName: "PixiTextSprite",
|
|
361
|
+
// };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as PixiTextSprite } from "./PixiTextSprite";
|
|
@@ -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
|
+
};
|