reacthub-pixitweenjs 0.2.10 → 0.2.12

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 (86) hide show
  1. package/dist/index.es.js +3586 -3583
  2. package/dist/index.umd.js +78 -78
  3. package/package.json +4 -1
  4. package/.storybook/main.ts +0 -31
  5. package/.storybook/preview.tsx +0 -26
  6. package/CHANGELOG.md +0 -100
  7. package/build-storybook.log +0 -94
  8. package/index.html +0 -13
  9. package/public/vite.svg +0 -1
  10. package/src/App.css +0 -42
  11. package/src/App.tsx +0 -29
  12. package/src/assets/font/OpenSans-Light-webfont.eot +0 -0
  13. package/src/assets/font/OpenSans-Light-webfont.svg +0 -252
  14. package/src/assets/font/OpenSans-Light-webfont.ttf +0 -0
  15. package/src/assets/font/OpenSans-Light-webfont.woff +0 -0
  16. package/src/assets/font/OpenSans-Regular-webfont.eot +0 -0
  17. package/src/assets/font/OpenSans-Regular-webfont.svg +0 -252
  18. package/src/assets/font/OpenSans-Regular-webfont.ttf +0 -0
  19. package/src/assets/font/OpenSans-Regular-webfont.woff +0 -0
  20. package/src/assets/icon/percolate.eot +0 -0
  21. package/src/assets/icon/percolate.svg +0 -139
  22. package/src/assets/icon/percolate.ttf +0 -0
  23. package/src/assets/icon/percolate.woff +0 -0
  24. package/src/assets/react.svg +0 -1
  25. package/src/components/PixiAnimatedSprite/PixiAnimatedSprite.tsx +0 -51
  26. package/src/components/PixiAnimatedSprite/index.ts +0 -2
  27. package/src/components/PixiAudioSprite/PixiAudioSprite.stories.tsx +0 -61
  28. package/src/components/PixiAudioSprite/PixiAudioSprite.tsx +0 -202
  29. package/src/components/PixiAudioSprite/index.ts +0 -1
  30. package/src/components/PixiGifSprite/PixiGifSprite.stories.tsx +0 -172
  31. package/src/components/PixiGifSprite/PixiGifSprite.tsx +0 -420
  32. package/src/components/PixiGifSprite/index.ts +0 -2
  33. package/src/components/PixiImageSprite/PixiImageSprite.stories.tsx +0 -220
  34. package/src/components/PixiImageSprite/PixiImageSprite.tsx +0 -60
  35. package/src/components/PixiImageSprite/index.ts +0 -1
  36. package/src/components/PixiSVGSprite/PixiSvgPathSprite.stories.tsx +0 -174
  37. package/src/components/PixiSVGSprite/PixiSvgPathSprite.tsx +0 -158
  38. package/src/components/PixiSVGSprite/index.ts +0 -1
  39. package/src/components/PixiTextSprite/PixiTextSprite.stories.tsx +0 -228
  40. package/src/components/PixiTextSprite/PixiTextSprite.tsx +0 -361
  41. package/src/components/PixiTextSprite/index.ts +0 -1
  42. package/src/components/PixiVideoSprite/PixiVideoSprite.stories.tsx +0 -186
  43. package/src/components/PixiVideoSprite/PixiVideoSprite.tsx +0 -595
  44. package/src/components/PixiVideoSprite/PixiVideoSpriteBackup.txt +0 -755
  45. package/src/components/PixiVideoSprite/index.ts +0 -1
  46. package/src/components/index.ts +0 -7
  47. package/src/declare.module.ts +0 -5
  48. package/src/hocs/AbstractContainer.tsx +0 -199
  49. package/src/hocs/WithFilterContainer.tsx +0 -159
  50. package/src/index.css +0 -457
  51. package/src/index.ts +0 -3
  52. package/src/main.tsx +0 -11
  53. package/src/providers/GsapPixieContextProvider.tsx +0 -245
  54. package/src/providers/index.ts +0 -1
  55. package/src/reacthub-react-bindings.d.ts +0 -27
  56. package/src/stories/Installation.mdx +0 -40
  57. package/src/stories/Introduction.mdx +0 -140
  58. package/src/stories/assets/code-brackets.svg +0 -1
  59. package/src/stories/assets/colors.svg +0 -1
  60. package/src/stories/assets/comments.svg +0 -1
  61. package/src/stories/assets/direction.svg +0 -1
  62. package/src/stories/assets/flow.svg +0 -1
  63. package/src/stories/assets/plugin.svg +0 -1
  64. package/src/stories/assets/repo.svg +0 -1
  65. package/src/stories/assets/stackalt.svg +0 -1
  66. package/src/types/Animations.tsx +0 -41
  67. package/src/types/BaseProps.tsx +0 -56
  68. package/src/types/BlendModes.tsx +0 -19
  69. package/src/types/Effects.tsx +0 -11
  70. package/src/types/transformation.tsx +0 -13
  71. package/src/utils/AppStateProvider.tsx +0 -59
  72. package/src/utils/AppStateStage.tsx +0 -15
  73. package/src/utils/AppWrapper.tsx +0 -47
  74. package/src/utils/ContextBridge.tsx +0 -25
  75. package/src/utils/GsapAnim.tsx +0 -107
  76. package/src/utils/InteractionManager.tsx +0 -36
  77. package/src/utils/PixiStage.tsx +0 -29
  78. package/src/utils/PixiTransformer.tsx +0 -165
  79. package/src/utils/VideoSeekBar.tsx +0 -122
  80. package/src/utils/useDebounce.tsx +0 -15
  81. package/src/utils/useDeepEffect.tsx +0 -23
  82. package/src/vite-env.d.ts +0 -1
  83. package/tsconfig.json +0 -37
  84. package/tsconfig.node.json +0 -10
  85. package/vite.config.ts +0 -39
  86. package/vitest.config.ts +0 -11
@@ -1,755 +0,0 @@
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";
8
- import _ as PIXI from "pixi.js";
9
- import gsap from "gsap";
10
- import PixiTransformer from "../../utils/PixiTransformer";
11
-
12
- // @ts-ignore
13
- import isEmpty from "lodash/isEmpty";
14
- import { getAnimByName } from "../../utils/GsapAnim";
15
- import { TransformationEnd } from "../../types/transformation";
16
-
17
- type PixiVideoSpriteProps = {
18
- uniqueId: string;
19
- src: string;
20
- startAt: number;
21
- endAt: number;
22
- frameStartAt: number;
23
- frameEndAt: number;
24
- mute: boolean;
25
- locked: boolean;
26
- initialAlpha: number;
27
- transformation: {
28
- x: number;
29
- y: number;
30
- width: number;
31
- height: number;
32
- anchor: number;
33
- rotation?: number;
34
- alpha?: number;
35
- scale?: number | [number, number];
36
- tint?: number;
37
- blendMode?: number;
38
- animation?: string;
39
- colorCorrection?: {
40
- enabled?: boolean;
41
- temperature?: number;
42
- hue?: number;
43
- contrast?: number;
44
- saturation?: number;
45
- exposure?: number;
46
- reset?: boolean;
47
- sharpness?: number;
48
- value?: number;
49
- levels?: number;
50
- luminance?: number;
51
- enhance?: number;
52
- blurRadius?: number;
53
- red?: number;
54
- green?: number;
55
- blue?: number;
56
- alpha?: number;
57
- scaleInput?: number;
58
- };
59
- effect?: string;
60
- };
61
- pointerdown?: () => void;
62
- pointerup?: () => void;
63
- mousedown?: () => void;
64
- mouseup?: () => void;
65
- pointerover?: () => void;
66
- mouseover?: () => void;
67
- mouseout?: () => void;
68
- applyTransformer?: boolean;
69
- onAnchorTransformationEnd?: (endData: any) => void;
70
- };
71
-
72
- type EffectFunc = () => void;
73
- type Deps = ReadonlyArray<unknown>;
74
-
75
- interface VideoState {
76
- isPlaying: boolean;
77
- progress: number;
78
- speed: number;
79
- isMuted: boolean;
80
- isWaiting: boolean;
81
- loaded: boolean;
82
- size: { width: number; height: number };
83
- isDragging: boolean;
84
- }
85
-
86
- const Filters = withFilters(Container, {
87
- blur: PIXI.filters.BlurFilter,
88
- adjust: AdjustmentFilter,
89
- matrix: PIXI.filters.ColorMatrixFilter,
90
- });
91
-
92
- /\*_ filter config _/
93
- const config = {
94
- dot: {
95
- scale: 1,
96
- angle: 5,
97
- },
98
- blur: {
99
- blur: 0,
100
- quality: 4,
101
- },
102
- };
103
-
104
- /\*_ CYAN Filters _/
105
- const CYAN = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0];
106
-
107
- const initialState: VideoState = {
108
- isPlaying: false,
109
- progress: 0,
110
- speed: 1,
111
- isMuted: false,
112
- isWaiting: false,
113
- loaded: false,
114
- size: { width: 50, height: 50 },
115
- isDragging: false,
116
- };
117
-
118
- const PixiVideoSprite: React.FC<PixiVideoSpriteProps> = (props) => {
119
- //// State
120
- const [isMounted, setIsMounted] = React.useState(false);
121
- const [vidPlay, setVidPlay] = React.useState(false);
122
- const [isTransformerDragging, setIsTransformerDragging] = useState(false);
123
- const [isMouseOverTransformer, setIsMouseOverTransformer] = useState(false);
124
- const [{ isWaiting, isStalled }, setVideoState] = React.useState({
125
- isWaiting: false,
126
- isStalled: false,
127
- });
128
- const [videoTexture, setVideoTexture] =
129
- React.useState<PIXI.Texture<PIXI.Resource>>();
130
- const [isDragging, setIsDragging] = useState(false);
131
-
132
- console.log("PixiVideoSpriteProps", props);
133
- //// Refs
134
- const imageRef = useRef<PIXI.Sprite>(null);
135
- const containerRef = useRef<PIXI.Container>(null);
136
- const parentNode = useRef<PIXI.Container>(null);
137
- const imgGroupRef = useRef<PIXI.Container>(null);
138
- const transformerRef = useRef<PIXI.Container>(null);
139
- const videoElement = useRef<HTMLVideoElement>(null);
140
- const videoStateRef = useRef<VideoState>(initialState);
141
- const videoTimelineRef = useRef<gsap.core.Timeline | null>(null);
142
-
143
- //// Context
144
- const {
145
- tl,
146
- playerTimeRef,
147
- isDragging: gsapDragging,
148
- play,
149
- } = useContext(GsapPixieContext);
150
-
151
- // console log draggging
152
- console.log("isGsapDragging", gsapDragging);
153
- console.log("play", play);
154
- /// 1001
155
- // console.log("contxt Values", tl);
156
- const {
157
- uniqueId,
158
- mute = false,
159
- locked = false,
160
- src,
161
- startAt,
162
- endAt,
163
- frameStartAt,
164
- frameEndAt,
165
- initialAlpha,
166
- transformation: {
167
- x,
168
- y,
169
- width,
170
- height,
171
- scale,
172
- rotation,
173
- anchor,
174
- animation,
175
- colorCorrection,
176
- effect,
177
- },
178
- pointerdown,
179
- pointerup,
180
- mousedown,
181
- mouseup,
182
- pointerover,
183
- mouseover,
184
- mouseout,
185
- applyTransformer,
186
- onAnchorTransformationEnd,
187
- ...restProps
188
- } = props;
189
-
190
- const videoUrl = src || "";
191
-
192
- // color corrections
193
- const {
194
- enabled = false,
195
- temperature = 1,
196
- hue = 1,
197
- contrast = 1,
198
- saturation = 1,
199
- exposure = 1,
200
- reset,
201
- sharpness = 1,
202
- value = 0,
203
- levels = 1,
204
- luminance = 0,
205
- enhance = 0,
206
- blurRadius = 0,
207
- red = 150,
208
- green = 150,
209
- blue = 150,
210
- alpha = 1,
211
- scaleInput = 1,
212
- } = colorCorrection || {};
213
-
214
- const app = useApp();
215
-
216
- /\*_ adjustment filter _/
217
- const adjustments = {
218
- brightness: exposure,
219
- contrast,
220
- saturation,
221
- alpha,
222
- };
223
-
224
- /\*_ handle on tranformer onchange _/
225
- const handleOnTransformChange = React.useCallback(() => {
226
- setIsDragging(true);
227
- }, []);
228
-
229
- // transformer to handle sprite transformation
230
- const handleOnTransformEnd = React.useCallback(
231
- (endData: TransformationEnd) => {
232
- console.log("changeEnd", endData);
233
- if (onAnchorTransformationEnd) {
234
- console.log("running onAnchorTransformationEnd");
235
- onAnchorTransformationEnd(endData);
236
- }
237
- },
238
- []
239
- );
240
-
241
- /\*_Adding this alternative workaround to work with mov/mk4 video types _/
242
- const videoSrcElement = React.useMemo(() => {
243
- const element = document.createElement("video");
244
- element.src = src;
245
- element.crossOrigin = "Anonymus";
246
- element.autoplay = false;
247
- element.currentTime = 0.0001;
248
- return element;
249
- }, [src]);
250
-
251
- // /\*_ stop video playing when gsapDragging is true _/
252
- React.useEffect(() => {
253
- console.log("current", videoElement.current, gsapDragging);
254
- if (videoElement.current) {
255
- if (gsapDragging) {
256
- videoElement.current.pause();
257
- videoStateRef.current.isPlaying = false;
258
- videoStateRef.current.isDragging = true;
259
- } else {
260
- videoStateRef.current.isDragging = false;
261
- }
262
- }
263
- }, [gsapDragging]);
264
-
265
- /\*_ Gsap Start and Stop Events _/
266
- const gsapOnStart = (startAt: number) => {
267
- if (videoElement.current) {
268
- console.log("video gsapOnStart", playerTimeRef.current, gsapDragging);
269
-
270
- // check the start and end times are between the playerTimeRef.current to start video;
271
- if (
272
- playerTimeRef.current >= startAt &&
273
- playerTimeRef.current <= endAt &&
274
- !gsapDragging
275
- ) {
276
- setVidPlay(true);
277
- videoElement.current.currentTime = playerTimeRef.current;
278
- videoElement.current.play();
279
- videoStateRef.current.isPlaying = true;
280
- } else {
281
- setVidPlay(false);
282
- videoElement.current.pause();
283
- videoStateRef.current.isPlaying = false;
284
- }
285
- }
286
-
287
- };
288
-
289
- const gsapOnPause = (startAt: number) => {
290
- if (videoElement.current) {
291
- setVidPlay(false);
292
-
293
- const vid = videoElement.current;
294
- const isVidPlaying =
295
- vid.currentTime > 0 &&
296
- !vid.paused &&
297
- !vid.ended &&
298
- vid.readyState > vid.HAVE_CURRENT_DATA;
299
- ///if (!isVidPlaying) videoElement.current.play();
300
- if (isVidPlaying) videoElement.current.pause();
301
- videoStateRef.current.isPlaying = false;
302
- }
303
-
304
- };
305
-
306
- const gsapOnComplete = () => {
307
- console.log("onComplete triggered");
308
- if (videoElement.current) {
309
- setVidPlay(false);
310
- const vid = videoElement.current;
311
- const isVidPlaying =
312
- vid.currentTime > 0 &&
313
- !vid.paused &&
314
- !vid.ended &&
315
- vid.readyState > vid.HAVE_CURRENT_DATA;
316
- ///if (!isVidPlaying) videoElement.current.play();
317
- if (isVidPlaying) videoElement.current.pause();
318
- videoStateRef.current.isPlaying = false;
319
- }
320
- };
321
-
322
- const onInterrupt = () => {
323
- // console.log('interrupting', refId);
324
- };
325
-
326
- const onUpdate = (time: number) => {
327
- if (videoElement.current) {
328
- console.log(
329
- "currenttime vs player reftime",
330
- videoElement.current.currentTime,
331
- playerTimeRef.current
332
- );
333
- const absDiff = Math.abs(
334
- videoElement.current.currentTime - playerTimeRef.current
335
- );
336
-
337
- const vid = videoElement.current;
338
- const isVidPlaying =
339
- vid.currentTime > 0 &&
340
- !vid.paused &&
341
- !vid.ended &&
342
- vid.readyState > vid.HAVE_CURRENT_DATA;
343
-
344
- if (videoStateRef.current.isDragging) {
345
- console.log("video updating", playerTimeRef.current);
346
- videoElement.current.currentTime = playerTimeRef.current;
347
- videoElement.current.play();
348
- setTimeout(() => {
349
- setVidPlay(false);
350
- if (videoElement.current) videoElement.current.pause();
351
- }, 55);
352
- videoStateRef.current.isPlaying = false;
353
- } else if (!videoStateRef.current.isPlaying) {
354
- // if (!isVidPlaying) videoElement.current.play();
355
- // videoStateRef.current.isPlaying = true;
356
- // let the video play and update current time
357
- videoElement.current.currentTime = playerTimeRef.current;
358
- if (!isVidPlaying) videoElement.current.play();
359
- videoStateRef.current.isPlaying = true;
360
- videoStateRef.current.isPlaying = true;
361
- } else if (absDiff > 0.3) {
362
- videoElement.current.currentTime = playerTimeRef.current;
363
- if (!isVidPlaying) videoElement.current.play();
364
- videoStateRef.current.isPlaying = true;
365
- }
366
- }
367
-
368
- };
369
-
370
- const handleComplete = () => {
371
- // if (onComplete) {
372
- // onComplete();
373
- // }
374
- videoStateRef.current.isPlaying = false;
375
- };
376
-
377
- useEffect(() => {
378
- let ctx = gsap.context(() => {});
379
- if (containerRef.current && tl.current) {
380
- const data = {
381
- duration: Number(endAt) - Number(startAt),
382
- onStart: gsapOnStart,
383
- onComplete: gsapOnComplete,
384
- onStartParams: [startAt],
385
- onCompleteParams: [],
386
- onInterrupt: onInterrupt,
387
- onUpdate: onUpdate,
388
- onUpdateParams: [],
389
- };
390
-
391
- const ease = getAnimByName(animation || "None");
392
- ctx = gsap.context(() => {
393
- // timeline for video management
394
- videoTimelineRef.current = gsap.timeline({
395
- paused: true,
396
- defaults: { duration: 0 },
397
- });
398
-
399
- if (!isEmpty(ease.from)) {
400
- videoTimelineRef.current
401
- .from(containerRef.current, { ...ease.from }, startAt)
402
- .to(imgGroupRef.current, { alpha: 1, duration: 0.2 }, startAt)
403
- .from(imgGroupRef.current, { ...data }, startAt)
404
- .to(containerRef.current, { alpha: 0, duration: 0.2 }, endAt - 0.2);
405
- } else if (!isEmpty(ease.to)) {
406
- videoTimelineRef.current
407
- .to(
408
- containerRef.current,
409
- { alpha: 1, duration: 0.2, ...ease.to },
410
- startAt
411
- )
412
- .from(imgGroupRef.current, { ...data }, startAt)
413
- .to(containerRef.current, { alpha: 0, duration: 0.2 }, endAt - 0.2);
414
- } else if (!isEmpty(ease.fromTo)) {
415
- videoTimelineRef.current
416
- .fromTo(
417
- containerRef.current,
418
- // @ts-ignore
419
- ease.fromTo?.from,
420
- ease.fromTo?.to,
421
- startAt
422
- )
423
- .from(imgGroupRef.current, { ...data }, startAt)
424
- .to(containerRef.current, { alpha: 0, duration: 0.2 }, endAt - 0.2);
425
- } else {
426
- videoTimelineRef.current
427
- .to(containerRef.current, { alpha: 1, duration: 0.01 }, startAt)
428
- .from(imgGroupRef.current, { ...data }, startAt)
429
- .to(
430
- containerRef.current,
431
- { alpha: 0, duration: 0.1 },
432
- Number(endAt) - Number(0.1)
433
- );
434
- }
435
-
436
- // add the timeline to the tl parent timeline
437
- tl.current.add(videoTimelineRef.current, startAt);
438
- tl.current.fromTo(
439
- containerRef.current,
440
- { xalpha: 0 },
441
- { xalpha: 1, duration: Number(endAt) },
442
- 0
443
- );
444
-
445
- // end of timeline
446
- }); // end of gsap context
447
- }
448
- return () => ctx.revert(); // cleanup!
449
-
450
- }, [animation, startAt, endAt]);
451
-
452
- React.useEffect(() => {
453
- if (containerRef.current) {
454
- setIsMounted(true);
455
- }
456
- }, []);
457
-
458
- React.useEffect(() => {
459
- if (videoElement.current) {
460
- videoElement.current.muted = mute;
461
- }
462
- }, [mute]);
463
-
464
- // stop playing video while isDragging and gsapDragging
465
- React.useEffect(() => {
466
- if (videoElement.current) {
467
- const vid = videoElement.current;
468
- const isVidPlaying =
469
- vid.currentTime > 0 &&
470
- !vid.paused &&
471
- !vid.ended &&
472
- vid.readyState > vid.HAVE_CURRENT_DATA;
473
- if (isVidPlaying && (isDragging || gsapDragging)) {
474
- videoElement.current.pause();
475
- videoStateRef.current.isPlaying = false;
476
- }
477
- }
478
- }, [isDragging, gsapDragging]);
479
-
480
- // play video when vidPlay is true else stop
481
- // React.useEffect(() => {
482
- // let timeout: any;
483
- // if (videoElement.current) {
484
- // const vid = videoElement.current;
485
- // const isVidPlaying =
486
- // vid.currentTime > 0 &&
487
- // !vid.paused &&
488
- // !vid.ended &&
489
- // vid.readyState > vid.HAVE_CURRENT_DATA;
490
- // if (gsapDragging) {
491
- // videoElement.current.play();
492
- // timeout = setTimeout(() => {
493
- // setVidPlay(false);
494
- // if (videoElement.current) videoElement.current.pause();
495
- // }, 55);
496
- // videoStateRef.current.isPlaying = false;
497
- // } else if (vidPlay && !isVidPlaying && !gsapDragging) {
498
- // videoElement.current.play();
499
- // videoStateRef.current.isPlaying = true;
500
- // } else if (!vidPlay && isVidPlaying) {
501
- // videoElement.current.pause();
502
- // videoStateRef.current.isPlaying = false;
503
- // }
504
- // }
505
- // return () => clearTimeout(timeout);
506
- // }, [vidPlay, gsapDragging]);
507
-
508
- React.useEffect(() => {
509
- if (videoElement.current) {
510
- console.log("play updated", play);
511
- videoElement.current.currentTime = playerTimeRef.current;
512
- // play the video if the start and end times are between the playerTimeRef.current
513
- if (
514
- playerTimeRef.current >= startAt &&
515
- playerTimeRef.current <= endAt &&
516
- play
517
- ) {
518
- // set current time of video using playerTimeRef.current
519
- videoElement.current.currentTime = playerTimeRef.current;
520
- const vid = videoElement.current;
521
- const isVidPlaying =
522
- vid.currentTime > 0 &&
523
- !vid.paused &&
524
- !vid.ended &&
525
- vid.readyState > vid.HAVE_CURRENT_DATA;
526
- if (play && !isVidPlaying) videoElement.current.play();
527
- // videoElement.current.play();
528
- setVidPlay(true);
529
- videoStateRef.current.isPlaying = true;
530
- } else {
531
- setVidPlay(false);
532
- videoElement.current.pause();
533
- videoStateRef.current.isPlaying = false;
534
- }
535
-
536
- if (!play) {
537
- videoElement.current.pause();
538
- videoStateRef.current.isPlaying = false;
539
- }
540
- }
541
-
542
- }, [play]);
543
-
544
- // load // load meta // load seek through
545
- React.useEffect(() => {
546
- const minStartAt =
547
- Math.round((Number(frameStartAt) + Number.EPSILON) \* 100) / 100;
548
- const onload = function () {
549
- if (videoElement.current) {
550
- videoElement.current.currentTime = minStartAt;
551
- }
552
- };
553
-
554
- const onEnd = function () {
555
- //dispatchState({ isPlaying: false });
556
- if (videoElement.current) {
557
- const vid = videoElement.current;
558
- const isVidPlaying =
559
- vid.currentTime > 0 &&
560
- !vid.paused &&
561
- !vid.ended &&
562
- vid.readyState > vid.HAVE_CURRENT_DATA;
563
-
564
- if (isVidPlaying) {
565
- videoElement.current.pause();
566
- }
567
- }
568
- setVideoState({ isWaiting: false, isStalled: false });
569
- };
570
-
571
- const onLoadStart = function () {
572
- //dispatchState({ isWaiting: true, isStalled: false });
573
- if (videoElement.current) {
574
- videoElement.current.pause();
575
- }
576
- setVideoState({ isWaiting: true, isStalled: false });
577
- };
578
-
579
- const onCanPlayThrough = function () {
580
- //dispatchState({ isWaiting: false, isStalled: false });
581
- setVideoState({ isWaiting: false, isStalled: false });
582
- };
583
-
584
- const onStalled = function () {
585
- //dispatchState({ isStalled: true });
586
- setVideoState({ isWaiting: false, isStalled: true });
587
- };
588
-
589
- // create a new Sprite using the video texture (yes it's that easy)
590
- const stAt =
591
- Math.round((Number(frameStartAt) + Number.EPSILON) * 100) / 100;
592
- const endAt = Math.round((Number(frameEndAt) + Number.EPSILON) * 100) / 100;
593
- const urlWithTimestamp = `${videoUrl}#t=${stAt},${endAt}`;
594
- const urlWithQuery = `${videoUrl}?t=${stAt},${endAt}`;
595
-
596
- console.log("urlTimestap", urlWithTimestamp);
597
- /// const texture =
598
- PIXI.Texture.fromLoader(videoSrcElement, urlWithTimestamp, uniqueId, {
599
- pixiIdPrefix: uniqueId,
600
- resourceOptions: {
601
- autoPlay: false,
602
- crossorigin: "Anonymus",
603
- updateFPS: 30,
604
- },
605
- }).then((texture) => {
606
- if (!texture) return;
607
- // texture.baseTexture.resource.source.currentSrc = urlWithTimestamp;
608
- setVideoTexture(texture);
609
- // @ts-ignore
610
- console.log(texture.baseTexture.resource.source);
611
- // @ts-ignore
612
- videoElement.current = texture.baseTexture.resource.source;
613
- // @ts-ignore
614
- videoElement.current.id = uniqueId;
615
- // @ts-ignore
616
- videoElement.current.addEventListener("loadedmetadata", onload);
617
- // @ts-ignore
618
- videoElement.current.addEventListener("ended", onEnd);
619
- // @ts-ignore
620
- videoElement.current.addEventListener("loadstart", onLoadStart);
621
- // @ts-ignore
622
- videoElement.current.addEventListener("canplaythrough", onCanPlayThrough);
623
- // @ts-ignore
624
- videoElement.current.addEventListener("stalled", onStalled);
625
- });
626
-
627
- return () => {
628
- // @ts-ignore
629
- videoElement.current.removeEventListener("loadedmetadata", onload);
630
- // @ts-ignore
631
- videoElement.current.removeEventListener("ended", onEnd);
632
- // @ts-ignore
633
- videoElement.current.removeEventListener("loadstart", onLoadStart);
634
- // @ts-ignore
635
- videoElement.current.removeEventListener(
636
- "canplaythrough",
637
- onCanPlayThrough
638
- );
639
- // @ts-ignore
640
- videoElement.current.removeEventListener("stalled", onStalled);
641
- };
642
- // create a new Sprite using the video texture (yes it's that easy)
643
- // const videoSprite = new PIXI.Sprite(texture);
644
-
645
- }, [videoUrl, uniqueId, frameStartAt, frameEndAt, videoSrcElement]);
646
-
647
- return (
648
- // @ts-ignore
649
- <Container ref={parentNode}>
650
- {/_ @ts-ignore _/}
651
- {/_ @ts-ignore _/}
652
- <Container
653
- ref={containerRef}
654
- alpha={initialAlpha}
655
- position={[x, y]}
656
- pivot={[x, y]}
657
- width={width}
658
- height={height} >
659
- {colorCorrection && colorCorrection.enabled ? (
660
- <Filters
661
- scale={1}
662
- blur={{ blur: blurRadius, quality: 4 }}
663
- adjust={adjustments}
664
- apply={({ matrix }: { matrix: any }) => {
665
- if (effect === "BlackAndWhite") {
666
- matrix.desaturate();
667
- } else if (effect === "Sepia") {
668
- matrix.sepia();
669
- } else if (effect === "RetroVintage") {
670
- matrix.negative();
671
- } else if (effect === "NightVision") {
672
- matrix.negative();
673
- } else if (effect === "Normal") {
674
- matrix.reset();
675
- }
676
- }}
677
- matrix={{
678
- enabled: true,
679
- // @ts-ignore
680
- matrix: CYAN,
681
- }} >
682
- {/_ @ts-ignore _/}
683
- <Container ref={imgGroupRef}>
684
- {videoTexture && (
685
- <Sprite
686
- texture={videoTexture}
687
- width={width}
688
- height={height}
689
- anchor={0.5}
690
- x={x}
691
- y={y}
692
- {...(!locked &&
693
- !isDragging && {
694
- interactive: true,
695
- buttonMode: true,
696
- pointerdown: pointerdown,
697
- pointerover: pointerover,
698
- pointerout: mouseout,
699
- mousedown: mousedown,
700
- mouseover: mouseover,
701
- mouseout: mouseout,
702
- })}
703
- ref={imageRef}
704
- scale={scale}
705
- rotation={rotation}
706
- />
707
- )}
708
- </Container>
709
- </Filters>
710
- ) : (
711
- // @ts-ignore
712
- <Container ref={imgGroupRef}>
713
- {videoTexture && (
714
- <Sprite
715
- texture={videoTexture}
716
- width={width}
717
- height={height}
718
- anchor={0.5}
719
- x={x}
720
- y={y}
721
- {...(!locked &&
722
- !isDragging && {
723
- interactive: true,
724
- buttonMode: true,
725
- pointerdown: pointerdown,
726
- pointerover: pointerover,
727
- pointerout: mouseout,
728
- mousedown: mousedown,
729
- mouseover: mouseover,
730
- mouseout: mouseout,
731
- })}
732
- ref={imageRef}
733
- scale={scale}
734
- rotation={rotation}
735
- />
736
- )}
737
- </Container>
738
- )}
739
- </Container>
740
- {applyTransformer && (
741
- <PixiTransformer
742
- pixiTransformerRef={transformerRef}
743
- imageRef={containerRef}
744
- isMounted={isMounted}
745
- transformCommit={handleOnTransformEnd}
746
- transformChange={handleOnTransformChange}
747
- mouseoverEvent={setIsMouseOverTransformer}
748
- uniqueId={uniqueId}
749
- />
750
- )}
751
- </Container>
752
- );
753
- };
754
-
755
- export default PixiVideoSprite;