Facet

screenshot of Facet

Web components made simple and declarative

Overview

Facet is an innovative single-file web library designed to streamline the creation of web components. With its unique approach of utilizing <template> elements equipped with special attributes, Facet eliminates the need for cumbersome JavaScript boilerplate code. This allows developers to focus more on the structure and behavior of their components, making the web development process much smoother and more efficient.

The beauty of Facet lies in its simplicity and effectiveness. By taking advantage of the browser's custom elements API, it seamlessly transforms component definitions found in the HTML of your page into functional web components. Whether you are a seasoned developer or just starting out, Facet empowers you to create stunning components with ease and flexibility.

Features

  • Declarative Component Definitions: Use <template component> elements that are automatically detected, simplifying the creation of web components without any initial JavaScript coding.

  • Shadow DOM Support: By default, Facet components leverage the shadow DOM in closed mode, promoting encapsulation and preventing style leakage. Customize this behavior with shadow attributes like open, closed, or none.

  • Automatic Attribute Observation: Define a list of attributes for your components that, when changed, will trigger the attributeChanged event, facilitating responsive behavior within your components.

  • Inherited Attributes: Easily define attributes that can influence inner elements of your component. Facet supports renaming, filtering, and the automatic updating of inherited attributes, streamlining complex attribute management.

  • Event Handler Attachments: Use <script on> elements inside component definitions to attach event handlers to various parts of your component, allowing for intricate behavior customization.

  • Lifecycle Hooks as Custom Events: Make use of lifecycle hooks like connectedCallback, disconnectedCallback, and adoptedCallback, which are exposed as custom events for enhanced control over component interactions.

  • No JavaScript Boilerplate: By removing the need for complex JavaScript setup, Facet allows you to concentrate on what truly matters—building your components' structure and functionality efficiently.

web-components
Web Components

Web components provide a way to create reusable, encapsulated UI components using standard web technologies such as HTML, CSS, and JavaScript. They allow developers to create complex UI components that can be easily shared across multiple projects and frameworks. Web components are built using four main specifications: Custom Elements, Shadow DOM, HTML Templates, and ES Modules.