npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@288-toolkit/video-embed

v4.0.0

Published

A collection of Svelte components and functions to work with Vimeo and Youtube embeds.

Downloads

173

Readme

Video-embed

A collection of Svelte components and functions to work with Vimeo and Youtube embeds.

Components

EmbedGroup.svelte

An embed group that provides a context for video embeds.

Props

  • url (string): The url of the video.

Slot props

Slot props are also available via getVideoEmbedContext().

  • playing (boolean): true if the video embed is currently loaded and playing.
  • play (() => void): Play the video.
  • requestPreconnect (() => void): Request preconnection to the embed domains.
  • preconnect (boolean): true if preconnect has been requested
  • url (string): The URL of the video

EmbedPlayButton.svelte

A button that calls requestPreconnect when hovered and plays the video on click.

Props

  • class (string): The classes to apply to the button element.

EmbedThumbnail.svelte

An img element that renders the default video thumbnail. Make sure to setup the vimeo-thumbnail.jpg endpoint before using (documented below).

Props

  • url (string): The url of the video. Already provided if this component is used inside an EmbedGroup.
  • alt (string): The alt text for the image.
  • class (string): The classes to apply to the img element.

EmbedSelector.svelte

A selector component that automatically determines the provider and renders the appropriate embed. For more control over how the markup is rendered, the component has a slot that provides the embed component.

Props

  • url (string): The url of the video. Already provided if this component is used inside an EmbedGroup.

Slot props

  • provider ('vimeo' | 'youtube'): The embed provider, determined from the url.

  • EmbedComponent (SvelteComponent): The Svelte component of the embed.

YoutubeEmbed.svelte

The Youtube embed component. Automatically rendered by EmbedSelector.

VimeoEmbed.svelte

The Vimeo embed component. Automatically rendered by EmbedSelector.

Example

<script lang="ts">
	import type { AssetInterface } from 'src/craft';
	import { fade } from 'svelte/transition';
	import EmbedGroup from '$com/ui/video-embed/EmbedGroup.svelte';
	import EmbedSelector from '$com/ui/video-embed/EmbedSelector.svelte';
	import EmbedPoster from '$com/ui/video-embed/decoration/EmbedPoster.svelte';
	import EmbedPlayButton from '$com/ui/video-embed/decoration/EmbedPlayButton.svelte';
	import PlayIcon from '$com/ui/PlayIcon.svelte';
	import LazyMedia from '$com/ui/LazyMedia.svelte';

	export let embedUrl: Maybe<string>;
	export let poster: Maybe<AssetInterface>;
</script>

<EmbedGroup url={embedUrl} let:playing>
	<div class="grid-stack grid aspect-[2/1] w-full overflow-hidden rounded">
		<EmbedSelector />
		{#if !playing}
			<div class="h-full w-full" out:fade={{ duration: 200 }}>
				<EmbedPlayButton>
					<div class="grid-stack grid h-full w-full place-items-center">
						{#if poster}
							<Media media={poster} class="h-full w-full object-cover" />
						{:else}
							<EmbedThumbnail />
						{/if}
						<PlayIcon />
					</div>
				</EmbedPlayButton>
			</div>
		{/if}
	</div>
</EmbedGroup>

Functions

isYoutubeUrl()

Check if a URL is a valid YouTube URL

getYoutubeId()

Get the YouTube video ID from a URL

getYoutubeThumbnailUrl()

Get the URL of a YouTube video thumbnail

isVimeoUrl()

Check if a URL is a valid Vimeo URL

getVimeoId()

Get the Vimeo video ID from a URL

getVimeoThumbnailUrl()

Get the URL of a Vimeo video thumbnail. Make sure to setup the vimeo-thumbnail.jpg route in your app (see below).

vimeoThumbnail request handler

To be able to simply generate a vimeo thumbnail from a Vimeo video url (like we can do for Youtube), you must make an API call to Vimeo. To simplify this, you can setup a server route in your Sveltekit app that handles this with the vimeoThumbnailHandler.

Note that getVimeoThumbnailUrl() and EmbedThumbnail.svelte expect the endpoint to be /vimeo-thumbnail.jpg, so for these to work properly, add the following route to your app:

src/routes/vimeo-thumbnail.jpg/+server.ts:

import { vimeoThumbnailHandler } from '@288-toolkit/video-embed';

export const GET = vimeoThumbnailHandler;