Perlite
Perlite is a simple and declarative way to create rich client-side widgets designed with server-side apps in mind.
Install / Use
/learn @PaulMaly/PerliteREADME
hyperactiv 🌋 + lit-html ☄️ + extensions 🌊 = perlite 💎.
Perlite is a simple and declarative way to create rich client-side widgets designed with server-side apps in mind. Completely based on native/vanilla Javascript standards and doesn't require additional build steps or compilation. Plays well with server-side rendered apps and micro-frontends. For more details read the description.
🚩 Table of contents
- Description & Features.
- Installation
- Examples
- Basic usage
- Widget declaration
- Widget creation
- Widget multiple instantiation
- Widget container
- Widget state
- Widget template
- Widget lifecycle events
- Widget API
- $widget.target: HTMLElement | Node;
- $widget.state: ProxyConstructor;
- $widget.model: object;
- $widget.effect(fn: () => void, opts?: object): () => void;
- $widget.on(type: string, fn: (e: CustomEvent) => void, opts?: object | boolean): () => void;
- $widget.render(): void;
- $widget.destroy(): void;
- $widget.ctx(fn: (...ctx: any[]) => any): any;
- Widget container API
- $$widgets[index: number]: Widget;
- $$widgets.target: NodeList | Node[];
- $$widgets.state(fn: (state: ProxyConstructor) => void): void;
- $$widgets.effect(fn: (state: ProxyConstructor) => () => void, opts?: object): (() => void)[];
- $$widgets.on(type: string, fn: (e: CustomEvent) => void, opts?: object | boolean): (() => void)[];
- $$widgets.render(): void;
- $$widgets.destroy(): void;
- $$widgets.ctx(fn: (...ctx: any[]) => any): any;
- $$widgets.forEach(fn: (widget: Widget, index: number, widgets: Widget[]) => void): any;
- Advanced usage
- Structuring your project
- Tooling
- Typescript support
- Browsers support
- License
💡 Description & Features
Unlike the other frontend frameworks, eg. React, Vue, Angular or Svelte, which are mostly created for building SPA/RIA applications, Perlite's main goal is to make the life of developers of classical server-side applications a little bit easier and the modern front-end development techniques more accessible. Without extra knowledge of building tools and other dark sides of the frontend ecosystem . 👾
Perlite gives you a combination of the best ideas from the most popular SPA frameworks, like UI is a function of a state (React), reactive state driven development (Vue), observables (Angular) and lack of Virtual DOM (Svelte).
Perlite focuses on building standalone UI widgets placed across different parts of the server-generated page and provides handy tools to manage these widgets and interact between them.
Built on top lit-html - an efficient, expressive, extensible HTML templating library and hyperactiv - a super tiny reactive library. This means that your widgets will have a reactive state with direct object mutations, super-fast DOM updates, and low memory consumption.
The full bundle size of Perlite library is just 8.8Kb (min+gz). In addition, it's optimized for tree-shaking, so you can reduce the final size if not all features are used. At the same time, Perlite is full-featured enough to fulfill its purposes and no additional tools you needed in most of the cases.
📦 Installation
NPM
npm i --save perlite
or
yarn add perlite
and use it
import { html } from 'perlite';
CDN
If you are not using NPM, in modern browsers, you can import bundled ES module from CDN:
import { html } from 'https://unpkg.com/perlite@latest/dist/perlite.min.mjs';
or
just add a regular script-tag to your html for legacy browsers:
<script src="https://unpkg.com/perlite@latest/dist/perlite.min.js"></script>
and use it via global namespace:
const { html } = window.perlite;
Distribution
dist/index.js- UMD outputdist/index.mjs- ESM outputdist/index.min.js- UMD output (minified)dist/index.min.mjs- ESM output (minified)dist/perlite.js- IIFE bundledist/perlite.mjs- ESM bundledist/perlite.min.js- IIFE bundle (minified)dist/perlite.min.mjs- ESM bundle (minified)
🕹 Examples
TodoMVC
- single widget app;
- multiple fragments;
- store with actions for todos list with side-effect to the
sessionStorage; - based on ES dev server and NPM.
Simple Shop
- server-generated page (actually a static file);
- multiple client-side widget
Related Skills
clearshot
Structured screenshot analysis for UI implementation and critique. Analyzes every UI screenshot with a 5×5 spatial grid, full element inventory, and design system extraction — facts and taste together, every time. Escalates to full implementation blueprint when building. Trigger on any digital interface image file (png, jpg, gif, webp — websites, apps, dashboards, mockups, wireframes) or commands like 'analyse this screenshot,' 'rebuild this,' 'match this design,' 'clone this.' Skip for non-UI images (photos, memes, charts) unless the user explicitly wants to build a UI from them. Does NOT trigger on HTML source code, CSS, SVGs, or any code pasted as text.
ui-ux-pro-max-skill
57.9kAn AI SKILL that provide design intelligence for building professional UI/UX multiple platforms
ui-ux-pro-max-skill
57.9kAn AI SKILL that provide design intelligence for building professional UI/UX multiple platforms
onlook
25.0kThe Cursor for Designers • An Open-Source AI-First Design tool • Visually build, style, and edit your React App with AI
