A lightweight Svelte wrapper around the YouTube embed, loading only a thumbnail until the user presses play.
View on GitHub(YouTube iframe API fallback uses the video's title as iframe title)
<Youtube id="aYtE6XE6b_s" title="Cute cat video" />(the iframe still gets "Cute cat video" as its title attribute for accessibility; showTitle only hides it from the visual overlay)
Video starts at 30s and is muted
Loads only when the video enters the viewport.
<Youtube id="9jLTaiT_cVs" lazy title="Lazy loaded YouTube thumbnail" />Plays as part of the "Official Blender Open Movies" playlist.
<Youtube id="l5OZu-IrXpw" playlistId="PL6B3937A5D230E335" title="Singularity" />id and playlistId are both derived from a single watch URL.
<Youtube
url="https://www.youtube.com/watch?v=l5OZu-IrXpw&list=PL6B3937A5D230E335"
title="Singularity"
/>Video starts at 30s, derived from the `t` query param.
A shorts URL switches the player to a 9 / 16 ratio on its own, so the vertical video fills it instead of being letterboxed. It can be overridden by explicitly setting the `ratio` prop.
A bare Short id looks like any other video id, so pass `ratio` yourself. '16 / 9', '4 / 3', '1 / 1' and '9 / 16' are offered as presets, and any other CSS ratio works too.
Connections to the thumbnail and player hosts are normally opened as they are needed: the thumbnail host while the preview loads, the player host on the first pointer, focus or touch. `eager` opens both as soon as the component renders, which suits a player the visitor is expected to start right away. `none` opens neither.