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

breeze-wc

v0.3.0

Published

Breeze is a framework for working with Web Components. It aims to make the process of crafting Web Components easier, faster and more pleasant. It requires no build step, has no dependency, and is quick to get started with.

Downloads

7

Readme

About

Breeze is a framework for working with Web Components. It aims to make the process of crafting Web Components easier, faster and more pleasant. It requires no build step, has no dependency, and is quick to get started with.

Installation

Via NPM:

$ npm i breeze-wc

or git clone this repository.

Usage

The following guide assumes that the reader has a basic understanding of Web Components. If such is not the case, it is recommended to first check out the resources listed in the learn more section below.

Import and setup:

First add a script tag of type "module" pointing to the location/url where your component definition will be found.

<!-- FILE index.html -->
<head>
  ...
  <script type="module" src="./MyComponent.js">
</head>

Then import Component from Breeze and export a custom class definition extending Component.

/* FILE MyComponent.js */
import Component from "breeze-wc"; // In a Node environment (will require a module bundler/build step)

// OR

import Component from "./breeze/index.js"; // Import from index.js in non-Node environments (DOES NOT require a build step)

export class MyComponent extends Component {}

Note that importing from Breeze using a NPM package specifier will require a bundler tool such as Webpack or Rollup to process your files since browsers cannot work with such specifier format. Though if you installed via NPM, you can still avoid the need to use a bundler tool by importing directly from node_modules/breeze-wc/index.js.

Basic component example

import Component from "./breeze/index.js";

export class MyComponent extends Component {
  static tagName = "my-component";

  static template = `
  <div>Hello world!</div>
  <p>Good morning!</p>
  `;

  static styleSheet = `
  div {
    color: blue;
  }

  p {
    font-weight: 700;
  }
  `;

  static init = this.initClass();
}

This will define a custom HTML element that uses the tag <my-component></my-component> in the main HTML document. The template static property defines the contents of the custom element's shadow DOM. The StyleSheet static property will create a <style></style> in the shadow DOM that has the the given string value as it's content. Finally it is very important to call MyComponent.initClass(), since it is this method that initializes the custom element according to the definition that we provide. In the above example, the method is invoked in the declaration static init = this.initClass(). The static property init itself is of no importance, we only use it for convenience reasons.

Advanced component example

import Component from "./breeze/index.js";

export class MyComponent extends Component {
  static tagName = "my-component";

  static template = `
  <div>Hello world!</div>
  <p>Good morning!</p>
  <div class="counter"></div>
  `;

  static styleSheetPaths = "./a-path/to-a-css-file.css"; // A path or an array of paths to a CSS file relative to the HTML document. These files shall contain rulesets that apply to the shadow DOM tree of the custom element.

  static init = this.initClass();

  counterState = this.createState(0); // Creates a local state value and assign it to a public class property.

  // Lifecycle method defined by the "WHATWG HTML Spec".
  connectedCallback() {
    setInterval(() => this.counterState.mutate(this.counterState.value + 1), 1000); // Increments the state value every 1000ms.
  }

  // Special method invoke on every local state mutation.
  render() {
    this.shadowRoot.querySelector(".counter").textContent = this.counterState.value;
  }
}

Note that as observed in the above example, render is special method responsible for updating the custom element, the user interface, and for performing other side effects. It is invoked by multiple triggers, such as when the custom element is connected to the DOM tree, when the custom element is upgraded, when states are mutated, and when observed attributes are changed.

Learn more about Web Components

  • https://html.spec.whatwg.org/multipage/custom-elements.html
  • https://javascript.info/web-components
  • https://developer.mozilla.org/en-US/docs/Web/API/Web_components

Notes

  • This package is fully annotated and supports IntelliSense.
  • Suggestions and contributions are welcome.