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

shady-components

v0.6.0

Published

Simple method for building WebComponents

Downloads

6

Readme

Shady-Components lets you to create absurdly simple WebComponents.

First let's create a WebComponent in a file called UpperElement.js:

import ShadyElement from "/node_modules/shady-components/shady.js"

export class UpperElement extends ShadyElement {

    get Upper() {
        return this.Data.Text.toUpperCase();
    }
}

ShadyElement.Register(UpperElement);

This registers a WebComponent upper-element with a property that returns the upper-case Data.Text. Now let's define the WebComponent's HTML.

Shady.js automatically requests an HTML file of the same name as the JS file, so in UpperElement.html we write:

<span>${Upper}</span>

This will insert the Upper property declared above when the WebComponent renders. The WebComponent upper-element is now complete!

To import it into a web-page, let's create an index.html page as such:

<html>
    <head>
        <script type="module" src="./UpperElement.js"></script>
    </head>
    <body>
        <div>
            <upper-element data-text="Hello, World!"></upper-element>
        </div>
    </body>
</html>

Parameters are passed into the WebComponent via data-* arguments, which are mapped to Data.* properties within the JS.

When we visit index.html we see:

HELLO, WORLD!

And that's it!

Check the examples for idea's on what this tech can be used for.

FAQ

What does this work on?

Currently this works with no other steps in Chrome. To make it work on other browsers requires a mix of steps involving translating it with Babel.js to a lower JS level and adding polyfills. An example of this can be found in the example Polyfill Demo.

Are there more examples?

Sure, check out more examples here, with their code in the repo here.

How on earth does it know where the HTML is?!

I'm sorry... please don't judge me.

Until various meta properties are exposed I had to do something slightly dirty. Ready yourself..

It uses stacktrace.js to access the current stack-trace and uses file-information from that to locate itself and the relative files.

I cannot morally do that, can I inline the HTML and CSS?

Sure! Check out the Inline Register example to see how. The basic logic is to use a build-step to append the static members .inlineHTML & inlineCSS which shady.js will then use. Any help adding a guide or tool to gulp to do would be a great help!

Warranty

It's hacky, slow and has terrible edge cases so should only really be used for making fun home projects.

Credits

Currently I (Tom Bonner) have written the basic framework with the hope for more contributors.

The excellent people behind the Polymer Framework are owed credit given they were a major source of inspiration and introduced me to Web Components.