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

@rubenrodriguez/regl-component

v1.2.10

Published

element wrapper to manage multiple regl contexts

Downloads

10

Readme

regl-component

element wrapper to manage multiple regl contexts

This module uses nanocomponent to provide a vanilla DOM wrapper on top of a modified version of multi-regl, which shares a single webgl element among all components.

example

view this demo

var app = require('choo')()
var html = require('choo/html')
var rcom = require('regl-component')(require('regl'))
var anormals = require('angle-normals')

var chart = require('conway-hart')
var demos = [
  fromMesh(rcom.create(), chart('mI')),
  fromMesh(rcom.create(), chart('jT')),
  fromMesh(rcom.create(), chart('djmeD')),
  fromMesh(rcom.create(), chart('pO'))
]

app.route('/', function (state, emit) {
  return html`<body>
    ${rcom.render()}
    ${demos.map(function (demo) {
      return html`<div>
        ${demo.render({ width: 400, height: 150 })}
        <hr>
      </div>`
    })}
  </body>`
})
app.mount('body')

function fromMesh (rc, mesh) {
  var draw = rc.regl({
    frag: `
      precision highp float;
      varying vec3 vnorm;
      void main () {
        gl_FragColor = vec4(vnorm*0.5+0.5,1);
      }
    `,
    vert: `
      precision highp float;
      attribute vec3 position, normal;
      varying vec3 vnorm;
      uniform float aspect;
      void main () {
        vnorm = normal;
        gl_Position = vec4(position.xy*vec2(1,aspect)*0.3,position.z*0.1+0.1,1);
      }
    `,
    uniforms: {
      aspect: function (context) {
        return context.viewportWidth / context.viewportHeight
      }
    },
    attributes: {
      position: mesh.positions,
      normal: anormals(mesh.cells, mesh.positions)
    },
    elements: mesh.cells
  })
  rc.regl.clear({ color: [0,0,0,1], depth: true })
  draw()
  return rc
}

api

var reglComponent = require('regl-component')

var rcom = reglComponent(createRegl, opts)

Create an rcom component given a createRegl constructor function.

Any opts are passed to the regl constructor.

var rootElem = rcom.render()

Generate the root element rootElem that takes care of the full-screen canvas overlay.

var rc = rcom.create()

Create a component wrapper rc.

var elem = rc.render(props)

Return a cached element elem given:

  • props.width - element width
  • props.height - element height

rc.regl

Use this regl instance to control all the draw calls associated with this sub-context.

install

npm install regl-component

license

BSD