UNPKG

@jasonshimmy/custom-elements-runtime

Version:

A powerful, modern, and lightweight runtime for creating reactive web components with TypeScript

123 lines (94 loc) โ€ข 5.6 kB
# ๐Ÿงฉ Custom Elements Runtime [![Patreon](https://img.shields.io/badge/support-patreon-orange?logo=patreon)](https://patreon.com/jshimkoski) > **Ultra-powerful, type-safe runtime for fast, reactive, and maintainable web components.** Build modern components with strict TypeScript, zero dependencies, and a clean functional API. Designed for speed, standards compliance, and productivity. ๐Ÿ•น๏ธ Try it on [Codepen.io](https://codepen.io/jshimkoski/pen/JoYmpxm). ## โœจ Why You'll Love It - โšก **Blazing Fast:** Minimal runtime, instant updates, zero dependencies. - ๐ŸŽจ **JIT CSS:** On-demand, utility-first styling directly in your HTML at runtime. - ๐Ÿ’ช **No Build Necessary:** Instant development feedback, no bundling required. - ๐Ÿง‘โ€๐Ÿ’ป **TypeScript First:** Strict types, intellisense, and safety everywhere. - ๐Ÿงฉ **Functional API:** No classes, no boilerplateโ€”just pure functions. - ๐Ÿ› ๏ธ **SSR & HMR Ready:** Universal rendering and instant hot reloads. - ๐Ÿ”Œ **Extensible:** Directives, event bus, store, and more for advanced use cases. - ๐Ÿ† **Developer Friendly:** Clean docs, examples, and a welcoming community. ## โฑ๏ธ Getting Started 1. **Install:** `npm install @jasonshimmy/custom-elements-runtime` 2. **Create a Component:** ```ts import { component, ref, html, useEmit } from '@jasonshimmy/custom-elements-runtime'; component('my-counter', ({ initialCount = 0 }) => { const count = ref(initialCount); const emit = useEmit(); const handleClick = () => { count.value++; emit('update:initial-count', { count: count.value }); }; return html` <button type="button" class="px-4 py-2 bg-primary-500 text-white rounded" @click.prevent="${handleClick}" > Count: ${count.value} </button> `; }); ``` 3. **Use in HTML:** ```html <my-counter initial-count="5" @update:initial-count="handleCountUpdate" ></my-counter> <script> function handleCountUpdate(event) { console.log('Count updated to:', event.detail.count); } </script> ``` 4. **Enjoy instant reactivity and type safety!** ## ๐Ÿ“– Documentation Index Explore the complete documentation for every runtime feature: ### ๐Ÿš€ **Getting Started** - [**๐ŸŽฏ Functional API**](./docs/functional-api.md) - **Start here!** Complete guide to the modern functional component API ### ๐Ÿ—๏ธ **Core Features** - [๐Ÿงฉ Template](./docs/template.md) - Template syntax and html function - [๐Ÿงญ Directives](./docs/directives.md) - Conditional rendering with `when`, `each`, and `match` - [๐Ÿ› ๏ธ Directive Enhancements](./docs/directive-enhancements.md) - Advanced directive utilities (`unless`, `whenEmpty`, etc.) - [๐Ÿ”— Bindings](./docs/bindings.md) - Data binding with `:prop`, `@event`, `:model`, `:class`, `:style` - [๐Ÿ”” Events Deep Dive](./docs/events-deep-dive.md) - Custom event emission and handling patterns ### ๐ŸŽจ **Styling** - [๐ŸŽจ JIT CSS](./docs/jit-css.md) - On-demand utility-first styling system ### ๐Ÿ”— **Communication & State** - [๐Ÿ“ข Event Bus](./docs/event-bus.md) - Global event system for cross-component communication - [๐Ÿ—„๏ธ Store](./docs/store.md) - Global state management - [๐Ÿšฆ Router](./docs/router.md) - Client-side routing - [๐Ÿค Cross-Component Communication](./docs/cross-component-communication.md) - Patterns for component interaction ### โšก **Advanced Features** - [๐Ÿ”ฎ Virtual DOM](./docs/virtual-dom.md) - VDOM implementation and performance details - [๐ŸŒ SSR](./docs/ssr.md) - Server-side rendering support - [โ™ป๏ธ HMR](./docs/hmr.md) - Hot module replacement - [๐Ÿ›ก๏ธ Infinite Loop Protection](./docs/infinite-loop-protection.md) - Runtime safeguards against infinite loops - [๐Ÿ”’ Secure Expression Evaluator](./docs/secure-expression-evaluator.md) - Safe evaluation of dynamic expressions in templates ### ๐Ÿ”ง **Integration Guides** - [โš›๏ธ React Integration](./docs/react-integration.md) - Using components in React apps - [๐ŸฆŠ Vue Integration](./docs/vue-integration.md) - Using components in Vue apps - [๐Ÿ…ฐ๏ธ Angular Integration](./docs/angular-integration.md) - Using components in Angular apps - [๐Ÿ”ฅ Svelte Integration](./docs/svelte-integration.md) - Using components in Svelte apps ### ๐Ÿ› ๏ธ **Troubleshooting** - [๐Ÿ”ง Troubleshooting](./docs/troubleshooting.md) - Common issues and solutions For examples and implementation details, explore the source code in `src/lib/`. ## ๐Ÿง‘โ€๐Ÿ”ฌ Real-World Examples - [Form Input & Validation](./src/components/examples/FormInputValidation.ts) - [Minimal Example](./src/components/examples/MinimalExample.ts) - [Shopping Cart](./src/components/examples/ShoppingCart.ts) - [Todo App](./src/components/examples/TodoApp.ts) ## ๐ŸŒŸ Showcase & Community - **Showcase your components!** Open a PR to add your project to our gallery. - **Questions or ideas?** [Start a discussion](https://github.com/jasonshimmy/custom-elements-runtime/discussions) or [open an issue](https://github.com/jasonshimmy/custom-elements-runtime/issues). - **Contribute:** We welcome PRs for docs, features, and examples. - โค๏ธ Like what you see? [Support ongoing development on Patreon](https://patreon.com/jshimkoski) ## ๐Ÿ’– Support This Project Custom Elements Runtime is a labor of love built to make modern web development faster and more expressive. If it's helping you build better components, consider [supporting me on Patreon](https://patreon.com/jshimkoski) to help keep the momentum going. Your support helps fund continued development, documentation, and community engagement. Every bit helpsโ€”thank you!