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

tuijs-element

v0.3.1

Published

A small web component framework for building JavaScript UIs.

Downloads

20

Readme

TUIJS-Element

A small web component framework for building JavaScript UIs.

TUIJS-Element is built on ES Modules.

Last Updated 10/15/2024

Rendering

  • The general idea is to use an attribute counter to prevent the first render from occurring until all of the initial observed custom attributes are accounted for. This will allow the creation of custom elements that have non-standard HTML attributes, which can be used for any desired purpose. So if you have created an element with three custom attributes, the element will only render after the 'attributeChangedCallback' method has been called three times for each initial attribute.
  • The element will re-render for every change after the first render. TUIJS-Element only supports the following default HTML attributes being attached to a custom element.
  • id
  • name
  • class
  • alt
  • title

Programmatic Changes After Render

  • To change the element after the first render, you must do so in a way that will trigger the 'attributeChangedCallback'. This means that you will need to use 'setAttribute' to change the attribute value. This WILL work.
element.setAttribute('custom-attribute', 'value');

This WILL NOT work.

element['custom-attribute'] = 'value';

Event Listeners

  • TUIJS-Element has methods to handle event listeners. In order for the event listeners to be removed automatically with the 'disconnectedCallback' or 'attributeChangedCallback' methods, the 'addTrackedEvent' methods must be used.
  • The 'removeTrackedEvent' and 'removeAllTrackedEvents' methods are also available for manual manipulation if needed.
addTrackedEvent(element, eventType, callback);
removeTrackedEvent(element, eventType, callback);
removeAllTrackedEvents();

Example Project Code

Demo Location: https://github.com/TechTB-OpenSource/tuijs-element The 'parseTemplate' function is a utility functions provided in tuijs-util.

import { parseTemplate } from 'tuijs-util';
import { TuiElement } from 'tuijs-element';

let elm = parseTemplate(`
        <template>
            <color-box id="color-box-2" color-1="red" color-2="green"></color-box>
        <template>
    `);
elm.innerText = 'Color Box 2';
document.body.appendChild(elm);

class ColorBox extends TuiElement {
    constructor() {
        super();
        this.text = this.innerHTML;
    }
    static get observedAttributes() {
        return ['color-1', 'color-2'];
    }
    render() {
        console.log(`RENDER`);
        let elmTemplate = /*HTML*/`
            <template>
                <style>
                    .box {
                        height: 128px;
                        width: 128px;
                        margin: 32px;
                        display: flex;
                        justify-content: center;
                        align-items: center;
                    }
                    .box p {
                        text-align: center;
                        color: black;
                    }
                </style>
                <p>${this.text}</p>
            </template>
        `;
        this.classList.add('box');
        this.style.backgroundColor = `${this.getAttribute('color-1')}`;
        this.innerText = '';
        this.appendChild(parseTemplate(elmTemplate));
        super.addTrackedEvent(this, 'click', () => this.handleButtonClick());
        return;
    }
    handleButtonClick() {
        if (this.style.backgroundColor === this.getAttribute('color-1')) {
            this.style.backgroundColor = this.getAttribute('color-2');
            return;
        }
        this.style.backgroundColor = this.getAttribute('color-1');
        return;
    }
}
customElements.define('color-box', ColorBox);