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

react-browser-videos

v1.0.5

Published

Create mp4 videos using React and export it right in the browser (client-side) to avoid server costs

Downloads

1

Readme

render-video

Made with create-react-library

NPM JavaScript Style Guide

Install

npm install --save react-browser-videos

Usage

Setup

If using Next.js remember "use client"

// A page wrapping the canvas

import React, { Component } from 'react'

import { CanvasProvider } from 'react-browser-videos'

export function Page() {
  <CanvasProvider FPS={30} duration={100}>
    * Your other page/component *
  </CanvasProvider>
}

Basic Example

// Page/component for everything else

import React from 'react';
import { HtmlCanvas, DisplayCanvas, PlayPauseButton, TimeSlider, RenderButton, useCurrentFrame } from "react-browser-videos";

function App() {
  const currentFrame = useCurrentFrame();

  return (
    <div className="App">
      <p>Current Frame: {currentFrame}</p>

      <DisplayCanvas width={1000}/>
      <HtmlCanvas width={1000}>
        <div style={{
          width: "100%", 
          height: "100%", 
          display: "grid", 
          placeItems: "center"
        }}>
          <p style={{ fontSize: "60px" }}>Frame {currentFrame}</p>
        </div>
      </HtmlCanvas>

      <div style={{display: "flex"}}>
        <PlayPauseButton/>
        <TimeSlider/>
        <RenderButton/>
      </div>
    </div>
  );
}

export default App;

Components

CanvasProvider

The CanvasProvider is required for the package to work

The page or components that are gonna have anything to do with the video creation needs to be wrapped in this.

| Props | Description | Default | | ------------- | ------------- |- | | FPS | Video Frame Rate | 30 | | Duration | Video Duration | 100 |

import { CanvasProvider } from "react-browser-videos";

<CanvasProvider FPS={30} duration={100}>
  * More code *
</CanvasProvider>

DisplayCanvas

The DisplayCanvas is used to display the canvas version of the HtmlCanvas

| Props | Description | Default | | ------------- | ------------- |- | | Width | Width of the canvas in pixels | 500 |

import { DisplayCanvas } from "react-browser-videos";

<DisplayCanvas width={500}/>

HtmlCanvas

The HtmlCanvas is used to convert your html to a canvas drawing. It only works if there is a DisplayCanvas present

| Props | Description | Default | | ------------- | ------------- |- | | Width | Width of the canvas in pixels | 500 | | Hidden | Hides the display canvas but the render still works fine | false |

import { HtmlCanvas } from "react-browser-videos";

<HtmlCanvas width={500}>
  * Html code *
</HtmlCanvas>

Canvas Components

CanvasImage

Use CanvasImage to display and render images without errors

| Props | Description | | ------------- | ------------- | | src | Source of the image |

import { CanvasImage } from "react-browser-videos";

<CanvasImage src="<image-url>"/>

CanvasVideo

Use CanvasVideo to display and render videos without errors

| Props | Description | | ------------- | ------------- | | src | Source of the video |

import { CanvasVideo } from "react-browser-videos";

<CanvasVideo src="<video-url>"/>

Video Controls

Play Button

A simple button that starts the animation. It can be styled to preference

import { PlayButton } from "react-browser-videos";

<PlayButton/>

Pause Button

A simple button that stops the animation. It can be styled to preference

import { PauseButton } from "react-browser-videos";

<PauseButton/>

Play/Pause Button

This is the play and pause button in 1. It changes state and function based on if the video is currently playing

import { PlayPauseButton } from "react-browser-videos";

<PlayPauseButton/>

Time Slider

A range slider that can be used to controlling the timestamp of the video. It can be styled to preference

import { TimeSlider } from "react-browser-videos";

<TimeSlider/>

Render Button

A button that renders the video and downloads it. It can be styled to preference

| Props | Description | Default | | ------------- | ------------- | - | | fileName | Takes in a string that will be used to download the video | video.mp4 |

import { RenderButton } from "react-browser-videos";

<RenderButton fileName="MyVideo"/>

Functions

useCurrentFrame()

This function is used to get the current frame. It can be used to create dynamic video elements

import { useCurrentFrame } from "react-browser-videos";

const currentFrame = useCurrentFrame()

interpolate()

This function is used to get the current frame. It can be used to create dynamic video elements

| Parameters | Description | | ------------- | ------------- | | frame | The current frame | | startFrame | What frame the interpolation should start at | | endFrame | What frame the interpolation should be finished | | startValue | What the value should go from - Negative numbers are also accepted | | endValue | What the value should end on | | mode | linear, easeIn, easeOut |

import { interpolate } from "react-browser-videos";

const currentFrame = useCurrentFrame()

const opacity = interpolate(frame, 0, 1, 0, 100, "linear")

License

MIT © @esbenischeap