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 🙏

© 2025 – Pkg Stats / Ryan Hefner

js-camera

v1.0.4

Published

This is a custom element V1-based camera component.

Readme

js-camera

This is a custom element V1-based camera component.

Installation

npm install js-camera;

API

API Documentation

Changelog

Changelog

Examples

There are some examples in "./examples" in this package.Here is the first one to get you started.

Usage

Use Camera Controls

You can use play, pause, capture and camera face switch immediately by using "controls" attribute on camera element.

camera-with-controller.jpg

Add "controls" and "autoplay" attributes to the camera element.
If necessary, specify the camera face with the "facing" attribute and the resolution with the "width" and "height" attributes.
The default for the "facing" attribute is "back". If omitted, the rear camera opens.

<js-camera id="camera" controls autoplay facing="back" width="1920" height="1080"></js-camera>

You can receive the photos taken at the event and send them to the server.
Also use the play and pause events if needed.

import 'js-camera';

// Camera element
const camera = document.querySelector('#camera');

// If you use the "autoplay" attribute to automatically open the camera, you can wait for the camera to fully open if necessary.
await camera.waitOpen();

// Camera event listener
camera
  // Called after opening the camera
  .on('opened', () => {})
  // Called after playing the camera from pause/
  .on('played', () => {})
  // Called after pausing the camera
  .on('paused', () => {})
  // Returns the photo taken from the shoot button on the camera controller
  // The captured image can be received from "event.detail.dat" in base64 format.
  .on('tookphoto', evt => {
    console.log(evt.detail.base64.slice(0, 30));// data:image/png;base64,iVB...
  });

Try camera options

If you want to experiment with different camera options, you can use "dat-gui" for the camera element and use the options menu.

camera-with-controller.jpg

The current GUI options can be accessed from the camera element "guiState".
Here is an example using the GUI option.

Add "dat-gui" attribute to the camera element.

<js-camera id="camera" dat-gui></js-camera>

Get camera elements with JS and operate GUI options.


import 'js-camera';

// Camera element
const camera = document.querySelector('#camera');

// Open camera
const [width, height] = camera.guiState.resolution.split(',');
await camera.open(camera.guiState.facing, width, height);

// Close camera
camera.close();

// Take a photo
const options = {format: camera.guiState.format};// Capture options
if (camera.guiState.resize) {
  options.width = camera.guiState.width;
  options.height = camera.guiState.height;
  options.fit = camera.guiState.fit;
}
const base64 = camera.capture(options);
console.log(base64);// data:image/png;base64,iVB...

// Pause
camera.pause();

// Pause
camera.pause();

// Resume from pause
camera.play();

Basic camera usage.

Place the camera open/close, play, pause, and capture buttons in the HTML.

<style>
.actions {
  position: absolute;
  z-index: 1002;
  left: 0;
  bottom: 0;
  padding: 10px;
  width: 100%;
  text-align: center;
}
</style>

<js-camera id="camera"></js-camera>

<div class="actions">
  <button id="btnOpen" type="button">Open</button>
  <button id="btnClose" type="button">Close</button>
  <button id="btnPause" type="button">Pause</button>
  <button id="btnPlay" type="button">Play</button>
  <button id="btnCapture" type="button">Take photo</button>
</div>

Implements camera opening, closing, playing, pausing, and button event capture.
This is the easiest way to use the camera.

import 'js-camera';

// Camera element
const camera = document.querySelector('#camera');

// Open the camera.
// If necessary, you can also specify the resolution like "await camera.open('back', 1920, 1080)".
document.querySelector('#btnOpen').addEventListener('click', async () => {
  await camera.open('back');
});

// Close the camera.
document.querySelector('#btnClose').addEventListener('click', () => {
  if (!camera.opened)
    return;
  camera.close();
});

// Pause
document.querySelector('#btnPause').addEventListener('click', () => {
  if (!camera.opened)
    return;
  camera.pause();
});

// Play camera
document.querySelector('#btnPlay').addEventListener('click', () => {
  if (!camera.opened)
    return;
  camera.play();
});

// Take a photo
document.querySelector('#btnCapture').addEventListener('click', () => {
  if (!camera.opened)
    return;
  // Get the photo data taken
  let base64 = camera.capture();
  console.log(`Capture: ${base64}`);// Capture: data:image/png;base64,iVBORw0K

  // You can specify image/webp, image/png, image/jpeg as the capture format.
  // Default is image/png.
  base64 = camera.capture({format: 'image/webp'});
  console.log(`WebP capture: ${base64}`);// WebP capture: data:image/webp;base64,UklGRrb

  // You can also resize the capture with width, height, and fit options.
  base64 = camera.capture({
    fit: 'cover',
    width: 300,
    height: 200
  });
  console.log(`Resize capture: ${base64}`);// Resize capture: data:image/png;base64,iVBORw0K
});

License

MIT licensed