diff --git a/src/components/ScrollyVideo/Foreground.svelte b/src/components/ScrollyVideo/Foreground.svelte new file mode 100644 index 00000000..e13334a4 --- /dev/null +++ b/src/components/ScrollyVideo/Foreground.svelte @@ -0,0 +1,53 @@ + + + + {#if componentState.generalData.currentTime >= startTime && componentState.generalData.currentTime <= endTime} +
+ {@render children?.()} +
+ {/if} +
+ + diff --git a/src/components/ScrollyVideo/ScrollyVideo.stories.svelte b/src/components/ScrollyVideo/ScrollyVideo.stories.svelte index 478f0528..5daa4714 100644 --- a/src/components/ScrollyVideo/ScrollyVideo.stories.svelte +++ b/src/components/ScrollyVideo/ScrollyVideo.stories.svelte @@ -2,6 +2,7 @@ import { defineMeta } from '@storybook/addon-svelte-csf'; import ScrollyVideo from './ScrollyVideo.svelte'; import WithScrollerBase from './demo/WithScrollerBase.svelte'; + import WithTimeline from './demo/WithTimeline.svelte'; const { Story } = defineMeta({ title: 'Components/Graphics/ScrollyVideo', @@ -123,15 +124,15 @@ @@ -127,13 +140,18 @@ style="height: {heightChange}; width: 100%; min-height: 100svh;" >
- {#if showDebugInfo} + {#if showDebugInfo && scrollyVideo}

- {@html JSON.stringify(flattenObject(scrollyVideoState)) + {@html JSON.stringify(flattenObject(scrollyVideo.componentState)) .replace(/[{}"]/g, '') .split(',') .join('
')}

+ + + {#if children} + {@render children()} + {/if} {/if}
diff --git a/src/components/ScrollyVideo/demo/WithTimeline.svelte b/src/components/ScrollyVideo/demo/WithTimeline.svelte new file mode 100644 index 00000000..e4b734c3 --- /dev/null +++ b/src/components/ScrollyVideo/demo/WithTimeline.svelte @@ -0,0 +1,74 @@ + + + + +{#snippet ScrollForeground()} + + + + + + + + + + + + + + + + + + + + + + + +{/snippet} + +{#snippet ScrollVideo(height: string, VideoSrc: string)} + + {@render ScrollForeground()} + +{/snippet} + +{#if width < 600} + {@render ScrollVideo('800svh', SM)} +{:else if width < 1200} + {@render ScrollVideo('800svh', MD)} +{:else} + {@render ScrollVideo('800svh', LG)} +{/if} + + diff --git a/src/components/ScrollyVideo/demo/graphic/ai2svelte/annotation1.svelte b/src/components/ScrollyVideo/demo/graphic/ai2svelte/annotation1.svelte new file mode 100644 index 00000000..e69acb75 --- /dev/null +++ b/src/components/ScrollyVideo/demo/graphic/ai2svelte/annotation1.svelte @@ -0,0 +1,453 @@ + + +
+ + {#if width && width >= 0 && width < 510} +
+
+
+
+

Solid southwest swell

+
+
+

+ Tahitian local Vahine Fierro drops into a double overhead wave during + a recentcompetition. Timing and position are critical to make the + take-off and maximize scoring +

+

+

 

+
+
+

Shallow water hides

+

a sharp reef

+
+
+ {/if} + + {#if width && width >= 510 && width < 660} +
+
+
+
+

Wave forms from hitting reef, and

+

tube will track the line of the shelf

+
+
+

Solid southwest swell

+
+
+

Tahitian local Vahine Fierro drops into

+

a double overhead wave during a recent

+

competition. Timing and position are critical

+

to make the take-off and maximize scoring

+

+

 

+
+
+

Shallow water hides

+

a sharp reef

+
+
+ {/if} + + {#if width && width >= 660 && width < 930} +
+
+
+
+

Wave forms from hitting reef, and

+

tube will track the line of the shelf

+
+
+

Solid southwest swell

+
+
+

Tahitian local Vahine Fierro drops into

+

a double overhead wave during a recent

+

competition. Timing and position are critical

+

to make the take-off and maximize scoring

+

+

 

+
+
+

Shallow water hides

+

a sharp reef

+
+
+ {/if} + + {#if width && width >= 930 && width < 1200} +
+
+
+
+

Wave forms from hitting reef, and

+

tube will track the line of the shelf

+
+
+

Solid southwest swell

+
+
+

Tahitian local Vahine Fierro drops into

+

a double overhead wave during a recent

+

competition. Timing and position are critical

+

to make the take-off and maximize scoring

+

+

 

+
+
+

Shallow water hides

+

a sharp reef

+
+
+ {/if} + + {#if width && width >= 1200} +
+
+
+
+

Wave forms from hitting reef, and

+

tube will track the line of the shelf

+
+
+

Solid southwest swell

+
+
+

Tahitian local Vahine Fierro drops into

+

a double overhead wave during a recent

+

competition. Timing and position are critical

+

to make the take-off and maximize scoring

+

+

 

+
+
+

Shallow water hides

+

+ a sharp reef +

+
+
+ {/if} +
+ + + + + + diff --git a/src/components/ScrollyVideo/demo/graphic/ai2svelte/annotation2.svelte b/src/components/ScrollyVideo/demo/graphic/ai2svelte/annotation2.svelte new file mode 100644 index 00000000..73625d52 --- /dev/null +++ b/src/components/ScrollyVideo/demo/graphic/ai2svelte/annotation2.svelte @@ -0,0 +1,423 @@ + + +
+ + {#if width && width >= 0 && width < 510} +
+
+
+
+

The wave at Teahupo'o is

+

known to be very heavy

+

with a thick lip that can

+

easily knock a surfer off the

+

wave and onto the reef below

+
+
+

Surfer speed is up

+

to 35 km per hour

+

(20 mph)

+
+
+

One cubic meter

+

of water weighs

+

1,000 kg. (2,200 lb)

+
+
+

+ A surfer will adjust speed to stay in the tube by dragging a hand to + slow, or pumping the board to speed up +

+
+
+ {/if} + + {#if width && width >= 510 && width < 660} +
+
+
+
+ {/if} + + {#if width && width >= 660 && width < 930} +
+
+
+
+

The wave at Teahupo'o is

+

known to be very heavy

+

with a thick lip that can

+

easily knock a surfer off the

+

wave and onto the reef below

+
+
+

Surfer speed is up to

+

35 km per hour (20 mph)

+
+
+

A surfer will adjust speed to stay in

+

the tube by dragging a hand to slow,

+

or pumping the board to speed up

+
+
+

One cubic meter of water

+

weighs 1,000 kg. (2,200 lb)

+
+
+ {/if} + + {#if width && width >= 930 && width < 1200} +
+
+
+
+

The wave at Teahupo'o is

+

known to be very heavy

+

with a thick lip that can

+

easily knock a surfer off the

+

wave and onto the reef below

+
+
+

The wave at Teahupo'o is

+

known to be very heavy

+

with a thick lip that can

+

easily knock a surfer off the

+

wave and onto the reef below

+
+
+

Surfer speed is up to

+

35 km per hour (20 mph)

+
+
+

Surfer speed is up to

+

35 km per hour (20 mph)

+
+
+

A surfer will adjust speed to stay in

+

the tube by dragging a hand to slow,

+

or pumping the board to speed up

+
+
+

A surfer will adjust speed to stay in

+

the tube by dragging a hand to slow,

+

or pumping the board to speed up

+
+
+

One cubic meter of water

+

weighs 1,000 kg. (2,200 lb)

+
+
+

One cubic meter of water

+

weighs 1,000 kg. (2,200 lb)

+
+
+ {/if} + + {#if width && width >= 1200} +
+
+
+
+

The wave at Teahupo'o is

+

known to be very heavy

+

with a thick lip that can

+

easily knock a surfer off the

+

wave and onto the reef below

+
+
+

Surfer speed is up to

+

35 km per hour (20 mph)

+
+
+

A surfer will adjust speed to stay in

+

the tube by dragging a hand to slow,

+

or pumping the board to speed up

+
+
+

One cubic meter of water

+

weighs 1,000 kg. (2,200 lb)

+
+
+ {/if} +
+ + + + + + diff --git a/src/components/ScrollyVideo/demo/graphic/ai2svelte/annotation3.svelte b/src/components/ScrollyVideo/demo/graphic/ai2svelte/annotation3.svelte new file mode 100644 index 00000000..18dee429 --- /dev/null +++ b/src/components/ScrollyVideo/demo/graphic/ai2svelte/annotation3.svelte @@ -0,0 +1,431 @@ + + +
+ + {#if width && width >= 0 && width < 510} +
+
+
+
+

+ Fierro is envelopedin the barrel for over two seconds, which is a long + time in such an unstable environment +

+
+
+

+ In comptitions, more points are scored for being deep inside a barrel + which raises the chance the wave will close out on top of them. +

+
+
+ {/if} + + {#if width && width >= 510 && width < 660} +
+
+
+
+

+ Fierro is envelopedin the barrel for over two seconds, which is a long + time in such an unstable environment +

+
+
+

+ Surfers often say time distorts inside the barrel, slowing down and + that the crashing wave noise falls silent, asthey expereince a sense + of awe +

+
+
+

+ In comptitions, more points are scored for being deep inside a barrel + which raises the chance the wave will close out on top of them. +

+
+
+ {/if} + + {#if width && width >= 660 && width < 930} +
+
+
+
+

+ Fierro is envelopedin the barrel for over two seconds, which is a long + time in such an unstable environment +

+
+
+

+ Surfers often say time distorts inside the barrel, slowing down and + that the crashing wave noise falls silent, as they expereince a sense + of awe +

+
+
+

+ In comptitions, more points are scored for being deep inside a barrel + which raises the chance the wave will close out on top of them. +

+
+
+ {/if} + + {#if width && width >= 930 && width < 1200} +
+
+
+
+

+ Fierro is envelopedin the barrel for over two seconds, which is a long + time in such an unstable environment +

+
+
+

+ Surfers often say time distorts inside the barrel, slowing down and + that the crashing wave noise falls silent, as they expereince a sense + of awe +

+
+
+

+ In comptitions, more points are scored for being deep inside a barrel + which raises the chance the wave will close out on top of them. +

+
+
+ {/if} + + {#if width && width >= 1200} +
+
+
+
+

+ Fierro is envelopedin the barrel for over two seconds, which is a long + time in such an unstable environment +

+
+
+

 

+

Fierro is enveloped

+

 

+

in the barrel for over

+

 

+

2 seconds, which is a

+

 

+

long time in such an

+

 

+

unstable environment

+

 

+

Surfers often say time distorts inside

+

 

+

the barrel, slowing down and that the

+

 

+

crashing wave noise falls silent, as

+

 

+

they expereince a sense of awe

+

 

+

In comptitions, more points are

+

 

+

scored for being deep inside a

+

 

+

barrel which raises the chance

+

 

+

the wave will close out on top of them.

+
+
+

+ Surfers often say time distorts inside the barrel, slowing down and + that the crashing wave noise falls silent, as they expereince a sense + of awe +

+
+
+

+ In comptitions, more points are scored for being deep inside a barrel + which raises the chance the wave will close out on top of them. +

+
+
+ {/if} +
+ + + + + + diff --git a/src/components/ScrollyVideo/demo/graphic/ai2svelte/annotation4.svelte b/src/components/ScrollyVideo/demo/graphic/ai2svelte/annotation4.svelte new file mode 100644 index 00000000..9aba7b48 --- /dev/null +++ b/src/components/ScrollyVideo/demo/graphic/ai2svelte/annotation4.svelte @@ -0,0 +1,392 @@ + + +
+ + {#if width && width >= 0 && width < 510} +
+
+
+
+

The wave path is a short one, only about 100 yards long

+
+
+

+ Fierro exits the barrel with a score of 9.33 out of 10, as she was + deep in the tube, had good speed and went over the foam ball on her + exit +

+
+
+ {/if} + + {#if width && width >= 510 && width < 660} +
+
+
+
+

The wave path is a short one, only about 100 yards long

+
+
+

+ Fierro exits the barrel with a score of 9.33 out of 10, as she was + deep in the tube, had good speed and went over the foam ball on her + exit +

+
+
+

+ The wave heaves so quickly that as it forms, it pulls water off the + reef, creating a ride that is often below sea level - seen as the + surfer exits up and over the wave to higher water +

+
+
+ {/if} + + {#if width && width >= 660 && width < 930} +
+
+
+
+

The wave path is a short one, only about 100 yards long

+
+
+

+ Fierro exits the barrel with a score of 9.33 out of 10, as she was + deep in the tube, had good speed and went over the foam ball on her + exit +

+
+
+

+ The wave heaves so quickly that as it forms, it pulls water off the + reef, creating a ride that is often below sea level - seen as the + surfer exits up and over the wave to higher water +

+
+
+ {/if} + + {#if width && width >= 930 && width < 1200} +
+
+
+
+

The wave path is a short one,

+

only about 100 yards long

+
+
+

+ Fierro exits the barrel with a score of 9.33 out of 10, as she was + deep in the tube, had good speed and went over the foam ball on her + exit +

+
+
+

+ The wave heaves so quickly that as it forms, it pulls water off the + reef, creating a ride that is often below sea level - seen as the + surfer exits up and over the wave to higher water +

+
+
+ {/if} + + {#if width && width >= 1200} +
+
+
+
+

The wave path is a short one,

+

only about 100 yards long

+
+
+

Fierro exits the barrel with a score of

+

9.33 out of 10, as she was deep in the

+

tube, had good speed and went over

+

the foam ball on her exit

+
+
+

The wave heaves so quickly that as it forms,

+

+ it pulls water off the reef, creating a rid e that +

+

is often below sea level - seen as the surfer

+

exits up and over the wave to higher water

+
+
+ {/if} +
+ + + + + + diff --git a/src/components/ScrollyVideo/demo/graphic/imgs/annotation1-lg.png b/src/components/ScrollyVideo/demo/graphic/imgs/annotation1-lg.png new file mode 100644 index 00000000..66a92558 Binary files /dev/null and b/src/components/ScrollyVideo/demo/graphic/imgs/annotation1-lg.png differ diff --git a/src/components/ScrollyVideo/demo/graphic/imgs/annotation1-md.png b/src/components/ScrollyVideo/demo/graphic/imgs/annotation1-md.png new file mode 100644 index 00000000..cf5353ff Binary files /dev/null and b/src/components/ScrollyVideo/demo/graphic/imgs/annotation1-md.png differ diff --git a/src/components/ScrollyVideo/demo/graphic/imgs/annotation1-sm.png b/src/components/ScrollyVideo/demo/graphic/imgs/annotation1-sm.png new file mode 100644 index 00000000..7758da85 Binary files /dev/null and b/src/components/ScrollyVideo/demo/graphic/imgs/annotation1-sm.png differ diff --git a/src/components/ScrollyVideo/demo/graphic/imgs/annotation1-xl.png b/src/components/ScrollyVideo/demo/graphic/imgs/annotation1-xl.png new file mode 100644 index 00000000..35731fc0 Binary files /dev/null and b/src/components/ScrollyVideo/demo/graphic/imgs/annotation1-xl.png differ diff --git a/src/components/ScrollyVideo/demo/graphic/imgs/annotation1-xs.png b/src/components/ScrollyVideo/demo/graphic/imgs/annotation1-xs.png new file mode 100644 index 00000000..9621a6f3 Binary files /dev/null and b/src/components/ScrollyVideo/demo/graphic/imgs/annotation1-xs.png differ diff --git a/src/components/ScrollyVideo/demo/graphic/imgs/annotation2-lg.png b/src/components/ScrollyVideo/demo/graphic/imgs/annotation2-lg.png new file mode 100644 index 00000000..deae2d28 Binary files /dev/null and b/src/components/ScrollyVideo/demo/graphic/imgs/annotation2-lg.png differ diff --git a/src/components/ScrollyVideo/demo/graphic/imgs/annotation2-md.png b/src/components/ScrollyVideo/demo/graphic/imgs/annotation2-md.png new file mode 100644 index 00000000..5e45881a Binary files /dev/null and b/src/components/ScrollyVideo/demo/graphic/imgs/annotation2-md.png differ diff --git a/src/components/ScrollyVideo/demo/graphic/imgs/annotation2-sm.png b/src/components/ScrollyVideo/demo/graphic/imgs/annotation2-sm.png new file mode 100644 index 00000000..16441ea9 Binary files /dev/null and b/src/components/ScrollyVideo/demo/graphic/imgs/annotation2-sm.png differ diff --git a/src/components/ScrollyVideo/demo/graphic/imgs/annotation2-xl.png b/src/components/ScrollyVideo/demo/graphic/imgs/annotation2-xl.png new file mode 100644 index 00000000..dbf15ba9 Binary files /dev/null and b/src/components/ScrollyVideo/demo/graphic/imgs/annotation2-xl.png differ diff --git a/src/components/ScrollyVideo/demo/graphic/imgs/annotation2-xs.png b/src/components/ScrollyVideo/demo/graphic/imgs/annotation2-xs.png new file mode 100644 index 00000000..911411fb Binary files /dev/null and b/src/components/ScrollyVideo/demo/graphic/imgs/annotation2-xs.png differ diff --git a/src/components/ScrollyVideo/demo/graphic/imgs/annotation3-lg.png b/src/components/ScrollyVideo/demo/graphic/imgs/annotation3-lg.png new file mode 100644 index 00000000..6c225533 Binary files /dev/null and b/src/components/ScrollyVideo/demo/graphic/imgs/annotation3-lg.png differ diff --git a/src/components/ScrollyVideo/demo/graphic/imgs/annotation3-md.png b/src/components/ScrollyVideo/demo/graphic/imgs/annotation3-md.png new file mode 100644 index 00000000..e5366243 Binary files /dev/null and b/src/components/ScrollyVideo/demo/graphic/imgs/annotation3-md.png differ diff --git a/src/components/ScrollyVideo/demo/graphic/imgs/annotation3-sm.png b/src/components/ScrollyVideo/demo/graphic/imgs/annotation3-sm.png new file mode 100644 index 00000000..16441ea9 Binary files /dev/null and b/src/components/ScrollyVideo/demo/graphic/imgs/annotation3-sm.png differ diff --git a/src/components/ScrollyVideo/demo/graphic/imgs/annotation3-xl.png b/src/components/ScrollyVideo/demo/graphic/imgs/annotation3-xl.png new file mode 100644 index 00000000..4acb55bf Binary files /dev/null and b/src/components/ScrollyVideo/demo/graphic/imgs/annotation3-xl.png differ diff --git a/src/components/ScrollyVideo/demo/graphic/imgs/annotation3-xs.png b/src/components/ScrollyVideo/demo/graphic/imgs/annotation3-xs.png new file mode 100644 index 00000000..875f6925 Binary files /dev/null and b/src/components/ScrollyVideo/demo/graphic/imgs/annotation3-xs.png differ diff --git a/src/components/ScrollyVideo/demo/graphic/imgs/annotation4-lg.png b/src/components/ScrollyVideo/demo/graphic/imgs/annotation4-lg.png new file mode 100644 index 00000000..dc52b8b1 Binary files /dev/null and b/src/components/ScrollyVideo/demo/graphic/imgs/annotation4-lg.png differ diff --git a/src/components/ScrollyVideo/demo/graphic/imgs/annotation4-md.png b/src/components/ScrollyVideo/demo/graphic/imgs/annotation4-md.png new file mode 100644 index 00000000..7cdf4ba1 Binary files /dev/null and b/src/components/ScrollyVideo/demo/graphic/imgs/annotation4-md.png differ diff --git a/src/components/ScrollyVideo/demo/graphic/imgs/annotation4-sm.png b/src/components/ScrollyVideo/demo/graphic/imgs/annotation4-sm.png new file mode 100644 index 00000000..b220b1a8 Binary files /dev/null and b/src/components/ScrollyVideo/demo/graphic/imgs/annotation4-sm.png differ diff --git a/src/components/ScrollyVideo/demo/graphic/imgs/annotation4-xl.png b/src/components/ScrollyVideo/demo/graphic/imgs/annotation4-xl.png new file mode 100644 index 00000000..b70a6457 Binary files /dev/null and b/src/components/ScrollyVideo/demo/graphic/imgs/annotation4-xl.png differ diff --git a/src/components/ScrollyVideo/demo/graphic/imgs/annotation4-xs.png b/src/components/ScrollyVideo/demo/graphic/imgs/annotation4-xs.png new file mode 100644 index 00000000..fcdde814 Binary files /dev/null and b/src/components/ScrollyVideo/demo/graphic/imgs/annotation4-xs.png differ diff --git a/src/components/ScrollyVideo/js/ScrollyVideo.ts b/src/components/ScrollyVideo/js/ScrollyVideo.ts index 8ee20319..07e6e333 100644 --- a/src/components/ScrollyVideo/js/ScrollyVideo.ts +++ b/src/components/ScrollyVideo/js/ScrollyVideo.ts @@ -1,7 +1,7 @@ import { UAParser } from 'ua-parser-js'; import videoDecoder from './videoDecoder'; import { debounce, isScrollPositionAtTarget, map } from './utils'; -import { scrollyVideoState } from './state.svelte'; +import { createComponentState, type ScrollyVideoState } from './state.svelte'; interface ScrollyVideoArgs { src?: string; @@ -55,6 +55,7 @@ class ScrollyVideo { usingWebCodecs: boolean; // Whether we are using webCodecs totalTime: number; // The total time of the video, used for calculating percentage transitioningRaf: number | null; + componentState: ScrollyVideoState; // Placeholder for component state, if needed updateScrollPercentage: ((jump: boolean) => void) | undefined; resize: (() => void) | undefined; @@ -107,6 +108,7 @@ class ScrollyVideo { this.usingWebCodecs = false; // Whether we are using webCodecs this.totalTime = 0; // The total time of the video, used for calculating percentage this.transitioningRaf = null; + this.componentState = createComponentState(); // Make sure that we have a DOM if (typeof document !== 'object') { @@ -223,12 +225,12 @@ class ScrollyVideo { (containerBoundingClientRect.height - window.innerHeight); // if autplay, trim the playing time to last locked video position - if (scrollyVideoState.autoplayProgress > 0) { + if (this.componentState.autoplayProgress > 0) { scrollPercent = map( scrollPercent, 0, 1, - scrollyVideoState.autoplayProgress, + this.componentState.autoplayProgress, 1 ); } @@ -238,20 +240,20 @@ class ScrollyVideo { } // toggle autoplaying state on manual intervention - if (scrollyVideoState.isAutoPlaying && this.frames) { + if (this.componentState.isAutoPlaying && this.frames) { if (this.debug) console.warn('Stopping autoplay due to manual scroll'); if (this.usingWebCodecs) { - scrollyVideoState.autoplayProgress = parseFloat( + this.componentState.autoplayProgress = parseFloat( (this.currentFrame / this.frames.length).toFixed(4) ); } else { - scrollyVideoState.autoplayProgress = parseFloat( + this.componentState.autoplayProgress = parseFloat( (this.currentTime / this.totalTime).toFixed(4) ); } - scrollyVideoState.isAutoPlaying = false; + this.componentState.isAutoPlaying = false; } this.videoPercentage = scrollPercent; @@ -606,8 +608,9 @@ class ScrollyVideo { this.currentTime >= this.targetTime : this.currentTime <= this.targetTime; - if (scrollyVideoState.isAutoPlaying) { - scrollyVideoState.autoplayProgress = this.currentTime / this.totalTime; + if (this.componentState.isAutoPlaying) { + this.componentState.autoplayProgress = + this.currentTime / this.totalTime; } // If we are already close enough to our target, pause the video and return. @@ -805,26 +808,26 @@ class ScrollyVideo { easing: (i) => i, autoplay: true, }); - scrollyVideoState.isAutoPlaying = true; + this.componentState.isAutoPlaying = true; } updateDebugInfo() { - scrollyVideoState.generalData.src = this.src; - scrollyVideoState.generalData.videoPercentage = parseFloat( + this.componentState.generalData.src = this.src; + this.componentState.generalData.videoPercentage = parseFloat( this.videoPercentage.toFixed(4) ); - scrollyVideoState.generalData.frameRate = parseFloat( + this.componentState.generalData.frameRate = parseFloat( this.frameRate.toFixed(2) ); - scrollyVideoState.generalData.currentTime = parseFloat( + this.componentState.generalData.currentTime = parseFloat( this.currentTime.toFixed(4) ); - scrollyVideoState.generalData.totalTime = parseFloat( + this.componentState.generalData.totalTime = parseFloat( this.totalTime.toFixed(4) ); - scrollyVideoState.usingWebCodecs = this.usingWebCodecs; - scrollyVideoState.framesData.currentFrame = this.currentFrame; - scrollyVideoState.framesData.totalFrames = this.frames?.length || 0; + this.componentState.usingWebCodecs = this.usingWebCodecs; + this.componentState.framesData.currentFrame = this.currentFrame; + this.componentState.framesData.totalFrames = this.frames?.length || 0; } } export default ScrollyVideo; diff --git a/src/components/ScrollyVideo/js/state.svelte.ts b/src/components/ScrollyVideo/js/state.svelte.ts index 1ace7509..b3950bd4 100644 --- a/src/components/ScrollyVideo/js/state.svelte.ts +++ b/src/components/ScrollyVideo/js/state.svelte.ts @@ -20,20 +20,24 @@ export type ScrollyVideoState = { autoplayProgress: number; }; -export const scrollyVideoState = $state({ - generalData: { - src: '', - videoPercentage: 0, - frameRate: 0, - currentTime: 0, - totalTime: 0, - }, - usingWebCodecs: false, - framesData: { - codec: '', - currentFrame: 0, - totalFrames: 0, - }, - isAutoPlaying: false, - autoplayProgress: 0, -}); +export function createComponentState(): ScrollyVideoState { + const scrollyVideoState = $state({ + generalData: { + src: '', + videoPercentage: 0, + frameRate: 0, + currentTime: 0, + totalTime: 0, + }, + usingWebCodecs: false, + framesData: { + codec: '', + currentFrame: 0, + totalFrames: 0, + }, + isAutoPlaying: false, + autoplayProgress: 0, + }); + + return scrollyVideoState; +} diff --git a/src/components/ScrollyVideo/js/videoDecoder.ts b/src/components/ScrollyVideo/js/videoDecoder.ts index a96af7ba..b635e71f 100644 --- a/src/components/ScrollyVideo/js/videoDecoder.ts +++ b/src/components/ScrollyVideo/js/videoDecoder.ts @@ -1,5 +1,4 @@ import * as MP4Box from 'mp4box'; -import { scrollyVideoState } from './state.svelte'; interface MP4BoxBuffer extends ArrayBuffer { fileStart: number; @@ -167,7 +166,7 @@ const decodeVideo = ( if (info && info.videoTracks && info.videoTracks[0]) { [{ codec }] = info.videoTracks; if (debug) console.info('Video with codec:', codec); - scrollyVideoState.framesData.codec = codec; + // scrollyVideoState.framesData.codec = codec; // Define a type for moov to avoid using 'any' interface AvcCBox {