@reuters-graphics/graphics-components 3.0.12 → 3.0.13

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 (75) hide show
  1. package/dist/components/@types/global.d.ts +45 -0
  2. package/dist/components/Scroller/Scroller.mdx +2 -2
  3. package/dist/components/ScrollerBase/ScrollerBase.mdx +0 -5
  4. package/dist/components/ScrollerVideo/Debug.svelte +207 -0
  5. package/dist/components/ScrollerVideo/Debug.svelte.d.ts +5 -0
  6. package/dist/components/ScrollerVideo/ScrollerVideo.mdx +462 -0
  7. package/dist/components/ScrollerVideo/ScrollerVideo.stories.svelte +190 -0
  8. package/dist/components/ScrollerVideo/ScrollerVideo.stories.svelte.d.ts +19 -0
  9. package/dist/components/ScrollerVideo/ScrollerVideo.svelte +292 -0
  10. package/dist/components/ScrollerVideo/ScrollerVideo.svelte.d.ts +58 -0
  11. package/dist/components/ScrollerVideo/ScrollerVideoForeground.svelte +164 -0
  12. package/dist/components/ScrollerVideo/ScrollerVideoForeground.svelte.d.ts +17 -0
  13. package/dist/components/ScrollerVideo/demo/AdvancedUsecases.svelte +114 -0
  14. package/dist/components/ScrollerVideo/demo/AdvancedUsecases.svelte.d.ts +3 -0
  15. package/dist/components/ScrollerVideo/demo/Embedded.svelte +94 -0
  16. package/dist/components/ScrollerVideo/demo/Embedded.svelte.d.ts +3 -0
  17. package/dist/components/ScrollerVideo/demo/WithAi2svelteForegrounds.svelte +117 -0
  18. package/dist/components/ScrollerVideo/demo/WithAi2svelteForegrounds.svelte.d.ts +3 -0
  19. package/dist/components/ScrollerVideo/demo/WithScrollerBase.svelte +80 -0
  20. package/dist/components/ScrollerVideo/demo/WithScrollerBase.svelte.d.ts +3 -0
  21. package/dist/components/ScrollerVideo/demo/WithTextForegrounds.svelte +72 -0
  22. package/dist/components/ScrollerVideo/demo/WithTextForegrounds.svelte.d.ts +18 -0
  23. package/dist/components/ScrollerVideo/demo/graphic/ai2svelte/ai-chart.svelte +631 -0
  24. package/dist/components/ScrollerVideo/demo/graphic/ai2svelte/ai-chart.svelte.d.ts +3 -0
  25. package/dist/components/ScrollerVideo/demo/graphic/ai2svelte/annotation1.svelte +428 -0
  26. package/dist/components/ScrollerVideo/demo/graphic/ai2svelte/annotation1.svelte.d.ts +26 -0
  27. package/dist/components/ScrollerVideo/demo/graphic/ai2svelte/annotation2.svelte +402 -0
  28. package/dist/components/ScrollerVideo/demo/graphic/ai2svelte/annotation2.svelte.d.ts +26 -0
  29. package/dist/components/ScrollerVideo/demo/graphic/ai2svelte/annotation3.svelte +398 -0
  30. package/dist/components/ScrollerVideo/demo/graphic/ai2svelte/annotation3.svelte.d.ts +26 -0
  31. package/dist/components/ScrollerVideo/demo/graphic/ai2svelte/annotation4.svelte +360 -0
  32. package/dist/components/ScrollerVideo/demo/graphic/ai2svelte/annotation4.svelte.d.ts +26 -0
  33. package/dist/components/ScrollerVideo/demo/graphic/imgs/ai-chart-md.png +0 -0
  34. package/dist/components/ScrollerVideo/demo/graphic/imgs/ai-chart-sm.png +0 -0
  35. package/dist/components/ScrollerVideo/demo/graphic/imgs/ai-chart-xs.png +0 -0
  36. package/dist/components/ScrollerVideo/demo/graphic/imgs/annotation1-lg.png +0 -0
  37. package/dist/components/ScrollerVideo/demo/graphic/imgs/annotation1-md.png +0 -0
  38. package/dist/components/ScrollerVideo/demo/graphic/imgs/annotation1-sm.png +0 -0
  39. package/dist/components/ScrollerVideo/demo/graphic/imgs/annotation1-xl.png +0 -0
  40. package/dist/components/ScrollerVideo/demo/graphic/imgs/annotation1-xs.png +0 -0
  41. package/dist/components/ScrollerVideo/demo/graphic/imgs/annotation2-lg.png +0 -0
  42. package/dist/components/ScrollerVideo/demo/graphic/imgs/annotation2-md.png +0 -0
  43. package/dist/components/ScrollerVideo/demo/graphic/imgs/annotation2-sm.png +0 -0
  44. package/dist/components/ScrollerVideo/demo/graphic/imgs/annotation2-xl.png +0 -0
  45. package/dist/components/ScrollerVideo/demo/graphic/imgs/annotation2-xs.png +0 -0
  46. package/dist/components/ScrollerVideo/demo/graphic/imgs/annotation3-lg.png +0 -0
  47. package/dist/components/ScrollerVideo/demo/graphic/imgs/annotation3-md.png +0 -0
  48. package/dist/components/ScrollerVideo/demo/graphic/imgs/annotation3-sm.png +0 -0
  49. package/dist/components/ScrollerVideo/demo/graphic/imgs/annotation3-xl.png +0 -0
  50. package/dist/components/ScrollerVideo/demo/graphic/imgs/annotation3-xs.png +0 -0
  51. package/dist/components/ScrollerVideo/demo/graphic/imgs/annotation4-lg.png +0 -0
  52. package/dist/components/ScrollerVideo/demo/graphic/imgs/annotation4-md.png +0 -0
  53. package/dist/components/ScrollerVideo/demo/graphic/imgs/annotation4-sm.png +0 -0
  54. package/dist/components/ScrollerVideo/demo/graphic/imgs/annotation4-xl.png +0 -0
  55. package/dist/components/ScrollerVideo/demo/graphic/imgs/annotation4-xs.png +0 -0
  56. package/dist/components/ScrollerVideo/ts/ScrollerVideo.d.ts +248 -0
  57. package/dist/components/ScrollerVideo/ts/ScrollerVideo.js +762 -0
  58. package/dist/components/ScrollerVideo/ts/mp4box.d.ts +137 -0
  59. package/dist/components/ScrollerVideo/ts/state.svelte.d.ts +51 -0
  60. package/dist/components/ScrollerVideo/ts/state.svelte.js +25 -0
  61. package/dist/components/ScrollerVideo/ts/utils.d.ts +70 -0
  62. package/dist/components/ScrollerVideo/ts/utils.js +92 -0
  63. package/dist/components/ScrollerVideo/ts/videoDecoder.d.ts +11 -0
  64. package/dist/components/ScrollerVideo/ts/videoDecoder.js +193 -0
  65. package/dist/components/ScrollerVideo/videos/HPO.mp4 +0 -0
  66. package/dist/components/ScrollerVideo/videos/drone.mp4 +0 -0
  67. package/dist/components/ScrollerVideo/videos/goldengate.mp4 +0 -0
  68. package/dist/components/ScrollerVideo/videos/tennis.mp4 +0 -0
  69. package/dist/components/ScrollerVideo/videos/waves_lg.mp4 +0 -0
  70. package/dist/components/ScrollerVideo/videos/waves_md.mp4 +0 -0
  71. package/dist/components/ScrollerVideo/videos/waves_sm.mp4 +0 -0
  72. package/dist/components/SiteHeadline/SiteHeadline.mdx +4 -1
  73. package/dist/index.d.ts +3 -1
  74. package/dist/index.js +2 -0
  75. package/package.json +3 -1
@@ -0,0 +1,462 @@
1
+ import { Meta } from '@storybook/blocks';
2
+
3
+ import * as ScrollerVideoStories from './ScrollerVideo.stories.svelte';
4
+
5
+ <Meta of={ScrollerVideoStories} />
6
+
7
+ # ScrollerVideo
8
+
9
+ The `ScrollerVideo` component creates interactive video experiences that respond to user scrolling. It is built on top of [ScrollyVideo.js](https://scrollyvideo.js.org/) and is designed to work seamlessly with Svelte.
10
+
11
+ ## Basic demo
12
+
13
+ To use the `ScrollerVideo` component, import it and provide the video source. The scroll height defaults to `200lvh`, but you can adjust this to any valid CSS height value such as `1200px` or `200lvh` with the `height` prop.
14
+
15
+ > 💡TIP: Use `lvh` or `svh` units instead of `vh` unit for the height, as [these units](https://www.w3.org/TR/css-values-4/#large-viewport-size) are more reliable on mobile or other devices where elements such as the address bar toggle between being shown and hidden.
16
+
17
+ [Demo](?path=/story/components-graphics-scrollervideo--demo)
18
+
19
+ ```svelte
20
+ <script lang="ts">
21
+ import { ScrollerVideo } from '@reuters-graphics/graphics-components';
22
+ </script>
23
+
24
+ <!-- Optionally set `height` to adjust scroll height -->
25
+ <ScrollerVideo src="my-video.mp4" height="500lvh" />
26
+ ```
27
+
28
+ ## Optimising videos
29
+
30
+ When using the `ScrollerVideo` component, minimise the video file size and ensure that the video is encoded in a format that is widely supported across browsers. Videos encoded at higher frame rates (FPS) are bound to crash on mobile devices, so 24 FPS is recommended.
31
+
32
+ If at any point your page crashes while using this component (happens often only on phone devices), it is likely due to the video being too large or encoded at a high frame rate. You could also try separate videos for desktop and phone devices to save quality for the desktop viewing experience.
33
+
34
+ > 💡**TIP:** Set the `showDebugInfo` prop to `true` to see video encoding information
35
+
36
+ To optimise your video for the web, you can use `ffmpeg` to convert the video to a suitable format. Here is an example terminal command that converts a video to H.264 format with a resolution of 720p and a frame rate of 24 FPS:
37
+
38
+ ```bash
39
+ npx ffmpeg -y -i <input_video_src>.mp4 -c:v libx264 -movflags +faststart -crf 24 -r 24 -g 72 -vf scale=720:-1 -profile:v high -preset veryslow -pix_fmt yuv420p -color_primaries 1 -color_trc 1 -colorspace 1 -an <output_video>.mp4
40
+ ```
41
+
42
+ Adjust the `-crf` value to control the quality. A lower `-crf` value means higher quality, with 20-24 being a generally good balance. The video framerate can be altered by using `-r` flag. Set keyframe intervals using the `-g` flag. It is advisable to keep it around 3 seconds (3 \* video framerate) for a good output. See [FFmpeg documentation](https://ffmpeg.org/ffmpeg.html) and [Testing Media Capabilities](https://cconcolato.github.io/media-mime-support/mediacapabilities.html) for more.
43
+
44
+ ## Responsive videos
45
+
46
+ To show different videos based on the screen width, use the `ScrollerVideo` component with conditional logic that uses a different video source depending on the [window width](https://svelte.dev/docs/svelte/svelte-window).
47
+
48
+ [Demo](?path=/story/components-graphics-scrollervideo--responsive-videos)
49
+
50
+ ```svelte
51
+ <script lang="ts">
52
+ import { ScrollerVideo } from '@reuters-graphics/graphics-components';
53
+
54
+ let width = $state(0);
55
+ </script>
56
+
57
+ <svelte:window bind:innerWidth={width} />
58
+
59
+ {#if width < 600}
60
+ <!-- Video with aspect ratio 9:16 for window width smaller than 600px -->
61
+ <ScrollerVideo src="my-video-sm.mp4" height="500lvh" />
62
+ {:else if width < 1200}
63
+ <!-- Video with aspect ratio 1:1 for window width between 600px and 1200px -->
64
+ <ScrollerVideo src="my-video-md.mp4" height="500lvh" />
65
+ {:else}
66
+ <!-- Video with aspect ratio 16:9 for window width above 1200px -->
67
+ <ScrollerVideo src="my-video-lg.mp4" height="500lvh" />
68
+ {/if}
69
+ ```
70
+
71
+ ## Embeds
72
+
73
+ Setting `embedded` to `true` will turn `ScrollerVideo` into an embeddable version, where the video autoplays when the user scrolls upon it. Optionally, you can control the embed video behaviour by passing `embeddedProps` to control the autoplay `delay`, `threshold` for triggering autoplay, and the `duration` of the video.
74
+
75
+ > 💡**TIP:** Another way to recreate the ScrollerVideo experience for embeds is to record the desktop screen with [Scroll Capture](https://chromewebstore.google.com/detail/scroll-capture/egmhoeaacclmanaimofoooiamhpkimkk?hl=en) while scrolling through the video and use that video instead as an HTML video component.
76
+
77
+ [Demo](?path=/story/components-graphics-scrollervideo--embed)
78
+
79
+ ```svelte
80
+ <script lang="ts">
81
+ import { ScrollerVideo } from '@reuters-graphics/graphics-components';
82
+
83
+ let embedded = $state(true); // Set to true to enable embedded mode
84
+ </script>
85
+
86
+ <ScrollerVideo
87
+ src="my-video.mp4"
88
+ {embedded}
89
+ embeddedProps={{
90
+ delay: 200, // Optional: Delay before autoplay starts. Defaults to 200ms.
91
+ threshold: 0.5, // Optional: Threshold for triggering the autoplay. Defaults to 0.5.
92
+ duration: 5000, // Optional: Defaults to the duration of the video.
93
+ }}
94
+ />
95
+ ```
96
+
97
+ ## Autoplay
98
+
99
+ The `autoplay` option combines the autoplay and scrollytelling experience. If set to `true`, the video will start playing automatically when the component is mounted, but switch to scrollytelling when the user starts scrolling. The scroll height is calculated based on how much of the video remains, which means that if the user lets the video autoplay to near the end, the user would only have to scroll through a small height to get to the end. If the user lets the video autoplay to the end, there will be no scrolling effect.
100
+
101
+ [Demo](?path=/story/components-graphics-scrollervideo--autoplay)
102
+
103
+ ```svelte
104
+ <script lang="ts">
105
+ import { ScrollerVideo } from '@reuters-graphics/graphics-components';
106
+ </script>
107
+
108
+ <ScrollerVideo src="my-video.mp4" autoplay={true} />
109
+ ```
110
+
111
+ ## Time-based text foregrounds with ArchieML
112
+
113
+ The `ScrollerVideo` component can also be used to display text as foregrounds at specific times in the video. To do so, use the `text` prop in `ScrollerVideoForeground` component.
114
+
115
+ [Demo](?path=/story/components-graphics-scrollervideo--archie-ml-foregrounds)
116
+
117
+ With the graphics kit, you'll likely get your text and prop values from an ArchieML doc...
118
+
119
+ ```yaml
120
+ # ArchieML doc
121
+
122
+ [blocks]
123
+ type: scroller-video
124
+ id: alps-scroller
125
+ src: videos/alps.mp4
126
+ height: 800lvh
127
+
128
+ # Array of foregrounds
129
+ [.foregrounds]
130
+ startTime: 3 # When in the video to start showing the foreground
131
+ endTime: 7 # When to stop showing the foreground
132
+ width: normal # text container width
133
+ position: bottom center # Position of the text. Optional; defaults to 'center center'. Must be a combination of `top/bottom/center center/left/right`
134
+ backgroundColour: rgba(0, 0, 0, 0.8) # Optional; defaults to white
135
+ text: #### The Alps
136
+ The Alps stretch across eight countries: France, Switzerland, Italy, Monaco, Liechtenstein, Austria, Germany, and Slovenia, covering about 1,200 kilometers (750 miles).
137
+ :end
138
+
139
+ startTime: 9
140
+ endTime: 12
141
+ width: normal
142
+ position: bottom center
143
+ backgroundColour: rgba(0, 0, 0, 0.8)
144
+ text: Mont Blanc, standing at 4,809 meters (15,777 feet), is the highest peak in the Alps and Western Europe, though there's ongoing debate between France and Italy about exactly where the summit lies.
145
+ :end
146
+
147
+ startTime: 16
148
+ endTime: 20
149
+ width: normal
150
+ position: bottom center
151
+ backgroundColour: rgba(0, 0, 0, 0.8)
152
+ text: #### History
153
+ The Alps were formed around **65 million years** ago when the African and Eurasian tectonic plates collided, pushing the land upward. Over 14 million people live in the Alpine region, with tourism supporting approximately 120 million visitors annually.
154
+ :end
155
+ []
156
+ []
157
+ ```
158
+
159
+ ... which you'll parse out of a ArchieML block object before passing to the `ScrollerVideo` and `ScrollerVideoForeground` components.
160
+
161
+ ```svelte
162
+ <script lang="ts">
163
+ import {
164
+ ScrollerVideo,
165
+ ScrollerVideoForeground,
166
+ } from '@reuters-graphics/graphics-components';
167
+ import { assets } from '$app/paths'; // 👈 If using in the graphics kit...
168
+ </script>
169
+
170
+ {#each content.blocks as block}
171
+ <!-- Inside the content.blocks for loop... -->
172
+ {#if block.type == 'scroller-video'}
173
+ <ScrollerVideo
174
+ id={block.id}
175
+ src={`${assets}/${block.src}}`}
176
+ height={block.height}
177
+ >
178
+ <!-- Loop through foregrounds to add text blurbs that appear/disappear at specific times -->
179
+ {#each block.foregrounds as foreground}
180
+ <ScrollerVideoForeground
181
+ startTime={parseFloat(foreground.startTime)}
182
+ endTime={parseFloat(foreground.endTime)}
183
+ width={foreground.width}
184
+ position={foreground.position}
185
+ backgroundColour={foreground.backgroundColour}
186
+ text={foreground.text}
187
+ />
188
+ {/each}
189
+ </ScrollerVideo>
190
+ {/if}
191
+ {/each}
192
+ ```
193
+
194
+ ## Time-based component foregrounds with ArchieML
195
+
196
+ The `ScrollerVideo` component can also be used to display components, such as `Headline` or ai2svelte files, as foregrounds at specific times in the video. To do so, use the `Foreground` prop in `ScrollerVideoForeground` component.
197
+
198
+ > **IMPORTANT❗**: When layering ai2svelte files over a video, the aspect ratio of the ai2svelte graphics should match that of the video. If the ai2svelte graphic is responsive and has, for example, small, medium and large versions — which is generally the case — make sure to also render small, medium and large versions of the video at the appropriate screen sizes. See [Responsive videos](#responsive-videos) for more details.
199
+
200
+ [Demo](?path=/story/components-graphics-scrollervideo--component-archie-ml-foregrounds)
201
+
202
+ With the graphics kit, you'll likely get your text and prop values from an ArchieML doc...
203
+
204
+ ```yaml
205
+ # ArchieML doc
206
+
207
+ # Headline
208
+ hed: Wind and waves
209
+ [authors]
210
+ * Jane Doe
211
+ []
212
+ publishTime: 2020-01-01T00:00:00Z
213
+ startTime: 0 # When in the video to start showing the headline
214
+ endTime: 0.3 # When to stop showing the headline
215
+
216
+ [blocks]
217
+ type: scroller-video
218
+ id: my-scroller-video
219
+ height: 800lvh
220
+
221
+ # Adjust prop names as needed
222
+ srcSm: videos/my-video-sm.mp4
223
+ srcMd: videos/my-video-md.mp4
224
+ srcLg: videos/my-video-lg.mp4
225
+
226
+ # Array of foregrounds
227
+ [.foregrounds]
228
+ startTime: 0.3 # When in the video to start showing the foreground
229
+ endTime: 2.2 # When to stop showing the foreground
230
+ width: fluid # foreground container width
231
+ Foreground: Foreground1 # Name of the ai2svelte component to render
232
+
233
+ startTime: 2.2
234
+ endTime: 3.2
235
+ width: fluid
236
+ Foreground: Foreground2
237
+
238
+ startTime: 3.2
239
+ endTime: 4.5
240
+ width: fluid
241
+ Foreground: Foreground3
242
+
243
+ startTime: 6.5
244
+ endTime: 8
245
+ width: fluid
246
+ Foreground: Foreground4
247
+ []
248
+ []
249
+ ```
250
+
251
+ ... which you'll parse out of a ArchieML block object before passing to the `ScrollerVideo` and `ScrollerVideoForeground` components.
252
+
253
+ ```svelte
254
+ <script lang="ts">
255
+ import { assets } from '$app/paths'; // 👈 If using in the graphics kit...
256
+ import {
257
+ Headline,
258
+ GraphicBlock,
259
+ ScrollerVideo,
260
+ Foreground,
261
+ } from '@reuters-graphics/graphics-components';
262
+
263
+ // Foreground ai2svelte components
264
+ import Foreground1 from './ai2svelte/foreground1.svelte';
265
+ import Foreground2 from './ai2svelte/foreground2.svelte';
266
+ import Foreground3 from './ai2svelte/foreground3.svelte';
267
+ import Foreground4 from './ai2svelte/foreground4.svelte';
268
+
269
+ // Add your imported foreground ai2svelte charts to this object
270
+ const aiChartsForeground = {
271
+ Foreground1,
272
+ Foreground2,
273
+ Foreground3,
274
+ Foreground4,
275
+ };
276
+
277
+ // Window width for responsive videos
278
+ let width = $state(1);
279
+ </script>
280
+
281
+ <svelte:window bind:innerWidth={width} />
282
+
283
+ <!-- Loop through content blocks... -->
284
+ {#each content.blocks as block}
285
+ {#if block.type == 'scroller-video'}
286
+ <!-- ScrollVideo snippet to render responsive videos -->
287
+ {#snippet ScrollVideo(height: string, src: string)}
288
+ <ScrollerVideo id={block.id} {height} {src}>
289
+ <!-- Headline component as foreground -->
290
+ <ScrollerVideoForeground
291
+ startTime={parseFloat(content.startTime)}
292
+ endTime={parseFloat(content.endTime)}
293
+ >
294
+ <Headline
295
+ hed={content.hed}
296
+ authors={content.authors}
297
+ publishTime={new Date(content.publishTime).toISOString()}
298
+ />
299
+ </ScrollerVideoForeground>
300
+
301
+ <!-- Loop through block.foregrounds to render each foreground component -->
302
+ {#each block.foregrounds as foreground}
303
+ <ScrollerVideoForeground
304
+ startTime={parseFloat(foreground.startTime)}
305
+ endTime={parseFloat(foreground.endTime)}
306
+ width={foreground.width}
307
+ Foreground={aiChartsForeground[
308
+ foreground.foreground as keyof typeof aiChartsForeground
309
+ ]}
310
+ />
311
+ {/each}
312
+ </ScrollerVideo>
313
+ {/snippet}
314
+
315
+ <!-- Render the ScrollVideo snippet for different screen sizes -->
316
+ {#if width < 600}
317
+ {@render ScrollVideo(block.height, `${assets}/${block.srcSm}`)}
318
+ {:else if width < 1200}
319
+ {@render ScrollVideo(block.height, `${assets}/${block.srcMd}`)}
320
+ {:else}
321
+ {@render ScrollVideo(block.height, `${assets}/${block.srcLg}`)}
322
+ {/if}
323
+ {/if}
324
+ {/each}
325
+ ```
326
+
327
+ ## Using with `ScrollerBase`
328
+
329
+ The `ScrollerVideo` component can be used inside the [ScrollerBase](?path=/story/components-graphics-scrollerbase--docs) component to add foreground content. This allows for a foreground that scrolls up and down over the video, instead of fading in and out at specific times.
330
+
331
+ > **Note**: To use `ScrollerVideo` with `ScrollerBase`, set `trackScroll` to `false` and pass the bindable prop `progress` from `ScrollerBase` as `videoPercentage` to `ScrollerVideo`.
332
+
333
+ [Demo](?path=/story/components-graphics-scrollervideo--scroller-base)
334
+
335
+ ```svelte
336
+ <script lang="ts">
337
+ import {
338
+ ScrollerVideo,
339
+ ScrollerBase,
340
+ } from '@reuters-graphics/graphics-components';
341
+
342
+ // Pass `progress` as `videoPercentage` to ScrollerVideo
343
+ let progress = $state(0);
344
+ </script>
345
+
346
+ <ScrollerBase bind:progress query="div.step-foreground-container">
347
+ {#snippet backgroundSnippet()}
348
+ <!-- Pass bindable prop `progress` as `videoPercentage` and set `trackScroll` to `false` -->
349
+ <ScrollerVideo
350
+ src="my-video.mp4"
351
+ videoPercentage={progress}
352
+ trackScroll={false}
353
+ />
354
+ {/snippet}
355
+ {#snippet foregroundSnippet()}
356
+ <!-- Add custom foreground HTML or component -->
357
+ <div class="step-foreground-container">
358
+ <h3 class="text-center">Step 1</h3>
359
+ </div>
360
+ <div class="step-foreground-container">
361
+ <h3 class="text-center">Step 2</h3>
362
+ </div>
363
+ <div class="step-foreground-container">
364
+ <h3 class="text-center">Step 3</h3>
365
+ </div>
366
+ {/snippet}
367
+ </ScrollerBase>
368
+
369
+ <style lang="scss">
370
+ .step-foreground-container {
371
+ height: 100lvh;
372
+ width: 50%;
373
+ padding: 1em;
374
+ margin: auto;
375
+
376
+ h3 {
377
+ display: flex;
378
+ align-items: center;
379
+ justify-content: center;
380
+ height: 100%;
381
+ color: white;
382
+ }
383
+ }
384
+ </style>
385
+ ```
386
+
387
+ ## Advanced usecases
388
+
389
+ Using the methods attached to the bindable prop `scrollerVideo` allows for advanced customisation of the scroll video behaviour. For example, you can create a looping video that plays a specific section of the video repeatedly, or jump to a specific time in the video when the user scrolls to a certain point.
390
+
391
+ This code below would make the video smoothly jump to the halfway point of the video. Setting `jump` to `true` will make the video jump to the specified percentage abruptly:
392
+
393
+ ```js
394
+ scrollerVideo.setVideoPercentage(
395
+ 0.5, // progress set to 50%
396
+ {
397
+ transitionSpeed: 12, // playback rate for the video
398
+ jump: false, // flag to change transition video abruptly
399
+ easing: (t) => t, // linear easing. Can also pass d3 easing functions - d3.easeLinear
400
+ }
401
+ );
402
+ ```
403
+
404
+ > **Note**: When using these methods, it's recommended to set `trackScroll` to `false` to avoid video playback on scroll and pass functions to the `onReady` prop to ensure that the video is ready before calling any methods on it.
405
+
406
+ Here is a demo that uses `ScrollerVideo` with `ScrollerBase` to make the video jump to the start or the end of the video depending on what step of the scroller the user is on.
407
+
408
+ [Demo](?path=/story/components-graphics-scrollervideo--advanced)
409
+
410
+ ```svelte
411
+ <script lang="ts">
412
+ import {
413
+ ScrollerVideo,
414
+ ScrollerBase,
415
+ type ScrollerVideoInstance,
416
+ } from '@reuters-graphics/graphics-components';
417
+ import { onDestroy } from 'svelte';
418
+
419
+ let scrollerVideo: ScrollerVideoInstance | undefined = $state(undefined);
420
+ let animationFrame = $state(0);
421
+ let index = $state(0); // index for the current step in ScrollerBase
422
+
423
+ // If ScrollerBase is on index 0, jump to the start of the video.
424
+ // Otherwise, jump to 1, or 100% (the end), of the video.
425
+ function jumpVideo() {
426
+ if (index === 0) {
427
+ scrollerVideo?.setVideoPercentage(0, {
428
+ jump: false, // Eases the jump
429
+ });
430
+ } else {
431
+ scrollerVideo?.setVideoPercentage(1, {
432
+ jump: false,
433
+ });
434
+ }
435
+ }
436
+ </script>
437
+
438
+ <ScrollerBase bind:index query="div.step-foreground-container">
439
+ <!-- ScrollerVideo as background -->
440
+ {#snippet backgroundSnippet()}
441
+ <!-- Pass `jumpVideo` to `onReady` and set `trackScroll` to `false` -->
442
+ <ScrollerVideo
443
+ bind:scrollerVideo
444
+ src={Tennis}
445
+ height="100lvh"
446
+ trackScroll={false}
447
+ showDebugInfo
448
+ onReady={jumpVideo}
449
+ />
450
+ {/snippet}
451
+
452
+ <!-- Simple text foregrounds -->
453
+ {#snippet foregroundSnippet()}
454
+ <div class="step-foreground-container">
455
+ <h3 class="text-center">Index {index}</h3>
456
+ </div>
457
+ <div class="step-foreground-container">
458
+ <h3 class="text-center">Index {index}</h3>
459
+ </div>
460
+ {/snippet}
461
+ </ScrollerBase>
462
+ ```
@@ -0,0 +1,190 @@
1
+ <script module lang="ts">
2
+ import { defineMeta } from '@storybook/addon-svelte-csf';
3
+ import ScrollerVideo from './ScrollerVideo.svelte';
4
+ import WithScrollerBase from './demo/WithScrollerBase.svelte';
5
+ import WithAi2svelteForegrounds from './demo/WithAi2svelteForegrounds.svelte';
6
+ import WithTextForegrounds from './demo/WithTextForegrounds.svelte';
7
+ import Embedded from './demo/Embedded.svelte';
8
+
9
+ const { Story } = defineMeta({
10
+ title: 'Components/Graphics/ScrollerVideo',
11
+ component: ScrollerVideo,
12
+ argTypes: {
13
+ autoplay: {
14
+ control: 'boolean',
15
+ table: {
16
+ defaultValue: { summary: 'false' },
17
+ },
18
+ },
19
+ class: {
20
+ control: 'text',
21
+ table: {
22
+ defaultValue: { summary: '' },
23
+ },
24
+ },
25
+ debug: {
26
+ control: 'boolean',
27
+ table: {
28
+ defaultValue: { summary: 'false' },
29
+ },
30
+ },
31
+ frameThreshold: {
32
+ control: 'number',
33
+ table: {
34
+ defaultValue: { summary: '0.1' },
35
+ },
36
+ },
37
+ full: {
38
+ control: 'boolean',
39
+ table: {
40
+ defaultValue: { summary: 'true' },
41
+ },
42
+ },
43
+ lockScroll: {
44
+ control: 'boolean',
45
+ table: {
46
+ defaultValue: { summary: 'true' },
47
+ },
48
+ },
49
+ objectFit: {
50
+ control: 'select',
51
+ options: ['contain', 'cover'],
52
+ table: {
53
+ defaultValue: { summary: 'cover' },
54
+ },
55
+ },
56
+ onChange: {
57
+ table: {
58
+ type: { summary: 'function' },
59
+ defaultValue: { summary: '() => {}' },
60
+ category: 'Bindable states',
61
+ },
62
+ },
63
+ onReady: {
64
+ table: {
65
+ type: { summary: 'function' },
66
+ defaultValue: { summary: '() => {}' },
67
+ category: 'Bindable states',
68
+ },
69
+ },
70
+ scrollerVideo: {
71
+ table: {
72
+ category: 'Bindable states',
73
+ },
74
+ },
75
+ showDebugInfo: {
76
+ control: 'boolean',
77
+ table: {
78
+ defaultValue: { summary: 'false' },
79
+ },
80
+ },
81
+ src: {
82
+ control: 'text',
83
+ table: {
84
+ defaultValue: {
85
+ summary: 'https://scrollyvideo.js.org/goldengate.mp4',
86
+ },
87
+ },
88
+ },
89
+ sticky: {
90
+ control: 'boolean',
91
+ table: {
92
+ defaultValue: { summary: 'true' },
93
+ },
94
+ },
95
+ trackScroll: {
96
+ control: 'boolean',
97
+ table: {
98
+ defaultValue: { summary: 'true' },
99
+ },
100
+ },
101
+ transitionSpeed: {
102
+ control: 'number',
103
+ table: {
104
+ defaultValue: { summary: '8' },
105
+ },
106
+ },
107
+ useWebCodecs: {
108
+ control: 'boolean',
109
+ table: {
110
+ defaultValue: { summary: 'true' },
111
+ },
112
+ },
113
+ videoPercentage: {
114
+ control: 'number',
115
+ table: {
116
+ category: 'Bindable states',
117
+ },
118
+ },
119
+ },
120
+ });
121
+
122
+ let width: number = $state(0);
123
+ </script>
124
+
125
+ <script>
126
+ import Video_SM from './videos/waves_sm.mp4';
127
+ import Video_MD from './videos/waves_md.mp4';
128
+ import Video_LG from './videos/waves_lg.mp4';
129
+ import Goldengate from './videos/goldengate.mp4';
130
+ import AdvancedUsecases from './demo/AdvancedUsecases.svelte';
131
+
132
+ const videoSrc = {
133
+ Video_SM,
134
+ Video_MD,
135
+ Video_LG,
136
+ Goldengate,
137
+ };
138
+
139
+ const args = {
140
+ showDebugInfo: true,
141
+ };
142
+ </script>
143
+
144
+ <svelte:window bind:innerWidth={width} />
145
+
146
+ <Story name="Demo">
147
+ <ScrollerVideo {...args} src={videoSrc.Goldengate} />
148
+ </Story>
149
+
150
+ <Story name="Responsive videos" exportName="ResponsiveVideos">
151
+ {#if width < 600}
152
+ <ScrollerVideo {...args} src={videoSrc.Video_SM} />
153
+ {:else if width < 1200}
154
+ <ScrollerVideo {...args} src={videoSrc.Video_MD} />
155
+ {:else}
156
+ <ScrollerVideo {...args} src={videoSrc.Video_LG} />
157
+ {/if}
158
+ </Story>
159
+
160
+ <Story name="Embed version" exportName="Embed">
161
+ <Embedded />
162
+ </Story>
163
+
164
+ <Story name="Autoplay">
165
+ <ScrollerVideo {...args} src={videoSrc.Goldengate} autoplay={true} />
166
+ </Story>
167
+
168
+ <Story
169
+ name="Time-based foregrounds with ArchieML"
170
+ exportName="ArchieMLForegrounds"
171
+ {args}
172
+ >
173
+ <WithTextForegrounds />
174
+ </Story>
175
+
176
+ <Story
177
+ name="Time-based component foregrounds with ArchieML"
178
+ exportName="ComponentArchieMLForegrounds"
179
+ {args}
180
+ >
181
+ <WithAi2svelteForegrounds />
182
+ </Story>
183
+
184
+ <Story name="Using with ScrollerBase" exportName="ScrollerBase" {args}>
185
+ <WithScrollerBase />
186
+ </Story>
187
+
188
+ <Story name="Advanced usecases" exportName="Advanced" {args}>
189
+ <AdvancedUsecases />
190
+ </Story>
@@ -0,0 +1,19 @@
1
+ import ScrollerVideo from './ScrollerVideo.svelte';
2
+ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
3
+ new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
4
+ $$bindings?: Bindings;
5
+ } & Exports;
6
+ (internal: unknown, props: {
7
+ $$events?: Events;
8
+ $$slots?: Slots;
9
+ }): Exports & {
10
+ $set?: any;
11
+ $on?: any;
12
+ };
13
+ z_$$bindings?: Bindings;
14
+ }
15
+ declare const ScrollerVideo: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
16
+ [evt: string]: CustomEvent<any>;
17
+ }, {}, {}, string>;
18
+ type ScrollerVideo = InstanceType<typeof ScrollerVideo>;
19
+ export default ScrollerVideo;