Getting Started with SynergyJS
SynergyJS is distributed as a standard ES module with zero external runtime dependencies. You can install it from npm for bundled applications or import it directly in modern browsers using an ES module CDN.
1. Installation
Install the package via npm or pnpm:
npm install synergy
Or import it directly in the browser without a build step:
<script type="module">
import { define } from 'https://unpkg.com/[email protected]/dist/synergy.mjs'
</script>
2. Authoring Your First Component
Every SynergyJS component pairs an HTML <template> with a factory function passed to define(). The factory returns a plain JavaScript object representing the component's initial reactive state and methods.
<template id="greeting-card">
<section class="card">
<h2>Hello, {{ name }}!</h2>
<button onclick="toggleCase">Toggle Case</button>
</section>
</template>
<greeting-card name="Web Components"></greeting-card>
<script type="module">
import { define } from 'synergy'
define('greeting-card', (initialProps) => ({
name: initialProps.name || 'World',
toggleCase() {
this.name = this.name === this.name.toUpperCase()
? 'Web Components'
: this.name.toUpperCase()
}
}))
</script>
3. Light DOM vs. Shadow DOM
By default, SynergyJS renders templates into the element's Light DOM unless a shadowRoot option is supplied. Light DOM rendering allows existing global stylesheets (such as Tailwind CSS or design system tokens) to style custom elements immediately without piercing Shadow DOM boundaries.
If strict style encapsulation is required for third-party embeds or reusable UI widgets, pass { shadowRoot: 'open' } as the third argument to define().
Next step: explore Declarative Templates & Repeated Blocks or jump to the Hello World tutorial.