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

brickrouge

v0.4.0

Published

Creates interoperable custom elements

Downloads

22

Readme

Brickrouge.js

Brickrouge.js creates interoperable custom elements—or widgets—from HTML elements. Because the HTML is already there, widgets come to life seamlessly for the user, without bump or refresh.

The special attribute brickrouge-is is used to recognize Brickrouge widgets from classic HTML elements, it defines the name of the widget factory.

Brickrouge.js is framework agnostic.

Usage

The following example demonstrates how to create a widget that creates a copy of itself when its button is pressed.

<div brickrouge-is="copy"><button>copy</button></div>
!function(Brickrouge) {

	// Defining a private constructor
	function Copy(element, options)
	{
		element
		.querySelector('button')
		.addEventListener('click', function() {
			var copy = element.cloneNode(true)
			, parent = element.parentNode

			parent.insertBefore(copy, element)
			parent.insertBefore(element, copy)
		}, false)
	}

	// Registering factory for 'copy' widgets
	Brickrouge.register('copy', (element, options) => {
		return new Copy(element, options)
	})

} (Brickrouge)

Running Brickrouge

Brickrouge.run() is used to run Brickrouge. The DOM is observed for mutations and widgets found in document.body are built.

The best way to invoke the method is as a DOM ready callback:

document.addEventListener('DOMContentLoaded', Brickrouge.run)

The MutationObserver interface—or DOM polling if it's not available—is used to automatically build new widgets.

Events

A widget has been built

The widget event is fired after a widget has been built.

/**
 * @param {Brickrouge.EVENT_WIDGET} ev
 * @listens Brickrouge#widget
 */
Brickrouge.observe(Brickrouge.EVENT_WIDGET, ev => {

    console.log('A widget has been built:', ev.widget)

})

The DOM was updated

The update event is fired after the DOM was updated.

/**
 * @param {Brickrouge.EVENT_UPDATE} ev
 * @listens Brickrouge#update
 */
Brickrouge.observe(Brickrouge.EVENT_UPDATE, ev => {

    console.log('This fragment updated the DOM:', ev.fragment)
    console.log('These elements are new widgets:', ev.elements)
    console.log('These widgets have been built:', ev.widgets)

})

Note: The event is fired a first time after Brickrouge is ran.

Brickrouge is running

The running event is fired after Brickrouge is ran.

/**
 * @param {Brickrouge.EVENT_RUNNING} ev
 * @listens Brickrouge#running
 */
Brickrouge.observe(Brickrouge.EVENT_RUNNING, ev => {

	console.log('Brickrouge is running, we can do stuff')

})

Helpers

  • Brickrouge.isWidget(): Whether the element is a widget.

    var element = document.getElementById('my-element')
      
    if (Brickrouge.isWidget(element)
    {
    	console.log('is an widget')
    }
    else
    {
    	console.log('is not a widget')
    }
  • Brickrouge.isBuilt(): Whether the widget for this element is built.

    var element = document.getElementById('my-element')
      
    if (Brickrouge.isBuilt(element)
    {
    	console.log('widget is built')
    }
    else
    {
    	console.log('widget is not built, also might not be a widget')
    }
  • Brickrouge.uidOf(): Returns the unique identifier associated with an element. If the uniqueNumber property is available it will return it, otherwise it creates a unique identifier of its own.

    var element = document.getElementById('my-element')
    
    console.log('uid:', Brickrouge.uidOf(element))
  • Brickrouge.empty(): Removes the children of an element.

    var element = document.getElementById('my-element')
      
    Brickrouge.empty(element)
  • Brickrouge.clone(): Clone a custom element, taking care of removing sensitive attributes.

    var element = document.getElementById('my-element')
    var clone = Brickrouge.clone(element)
  • Brickrouge.Dataset.from(): Returns the dataset values associated with an element.

    var element = document.getElementById('my-element')
    var dataset = Brickrouge.Dataset.from(element)
  • Brickrouge.Widget.from() or Brickrouge.from(): Returns the widget associated with an element and creates it if needed.

    var element = document.getElementById('my-element')
      
    try
    {
    	var widget = Brickrouge.from(element) 
    }
    catch (e)
    {
    	console.log('probably not a widget')
    }

Build

To build Brickrouge.js you first need to install webpack, then just use the command make. The files dist/brickrouge.js and dist/brickrouge-uncompressed.js should be built.

$ git clone git@github.com:Brickrouge/Brickrouge.js.git
$ cd Brickrouge.js
$ make

License

brickrouge.js is licensed under the New BSD License - See the LICENSE file for details.