--- url: /api.md description: >- Full API reference for all Elena packages including @elenajs/core, @elenajs/bundler, @elenajs/cli, @elenajs/ssr, and CEM plugins. --- # API Reference ## `@elenajs/core` | Export | Signature | Description | |--------|-----------|-------------| | `Elena` | `Elena(superClass)` | Creates an Elena component base class. Pass in `HTMLElement` to get started. Configure the component using static [component options](#component-options) on the returned class. | ### Template utilities | Export | Signature | Description | |--------|-----------|-------------| | `html` | `` html`...` `` | Write your component’s HTML as a template literal. Values you interpolate are escaped automatically to prevent XSS. Nested `html` fragments are passed through as-is. Return this from `render()`. | | `nothing` | `nothing` | Use this in conditional expressions when you want to render nothing. Safer than `""` or `false`, which can produce unexpected output. | | `unsafeHTML` | `unsafeHTML(str)` | Renders a plain string as raw HTML, skipping automatic escaping. Only use this for content you fully control. | ### Component options | Field | Type | Description | |-------|------|-------------| | `tagName` | `string` | The HTML tag name for this component (e.g. `"elena-button"`). Required for `define()` to register the element. | | `props` | `(string \| { name: string, reflect?: boolean })[]` | The list of props this component accepts. Each prop stays in sync with its matching HTML attribute. Use `{ name, reflect: false }` to keep a prop JS-only without writing it back to the attribute. | | `events` | `string[]` | Events to forward from the inner element up to the host (e.g. `["click", "focus", "blur"]`). | | `element` | `string` | A CSS selector for the inner element that `this.element` points to (e.g. `".inner"`, `"button"`). Defaults to the first child element when omitted. | | `shadow` | `"open" \| "closed"` | Attaches a shadow root to the host element. Elena renders into the shadow root instead of the host. | | `styles` | `CSSStyleSheet \| string \| (CSSStyleSheet \| string)[]` | One or more stylesheets to adopt into the shadow root. Only applies when `shadow` is also set. | | `registry` | `CustomElementRegistry` | A scoped registry to associate with this component’s shadow root. Child custom elements inside the shadow root are resolved from this registry instead of the global one. Only applies when `shadow` is also set. Only supported in Chrome 146+, Edge 146+, and Safari 26+. | ### Host attributes Attributes that Elena adds to the host element automatically. These are not JS properties, they appear in the DOM and can be targeted in CSS. | Attribute | Description | |-----------|-------------| | `hydrated` | Added to the host element after the first render completes. Use `:not([hydrated])` in CSS to style the element before JavaScript runs, and remove those styles once it hydrates. | ### Instance properties | Property | Type | Description | |----------|------|-------------| | `text` | `string` | The text content of the element. Elena reads this from the element’s children before the first render. Setting it later triggers a re-render. When you need to dynamically update this, pass text via a property instead of children. | | `element` | `HTMLElement \| null` | A reference to the inner element, resolved after the first render using the `element` option. | ### Lifecycle methods | Method | Description | |--------|-------------| | `connectedCallback()` | Runs when the element is added to the page. Sets up props, captures text content, renders, and wires up events. | | `willUpdate()` | Runs before every render, including the first. Override to compute derived state before the template evaluates. | | `render()` | Returns the HTML for this component as an `html` template. Called on connect and whenever the component needs re-rendering. Omit this method entirely for components that don’t render their own HTML. | | `firstUpdated()` | Runs once after the first render. `this.element` is available here. Override to run one-time setup that requires the DOM. | | `updated()` | Runs after every render, including the first. `this.element` is available here. Override to react to changes after the DOM is updated. On first connect, `firstUpdated()` runs before `updated()`. | | `requestUpdate()` | Manually schedules a re-render. Use when Elena can’t detect a change automatically, e.g. when mutating an object or array in place. Returns nothing, use `updateComplete` to wait for the render to finish. | | `disconnectedCallback()` | Runs when the element is removed from the page. Cleans up event listeners. | | `adoptedCallback()` | Runs when the element is moved to a new document via `document.adoptNode()`. Override to react to document changes. | | `attributeChangedCallback()` | Runs when an observed attribute changes. Updates the matching JS property and triggers a re-render. | ### Instance promises | Property | Type | Description | |----------|------|-------------| | `updateComplete` | `Promise` | Resolves after the next pending render finishes. Use it to wait for the DOM to settle before reading it. Resolves immediately if no render is pending. | ### Static methods | Method | Description | |--------|-------------| | `ClassName.define(registry?)` | Registers the component using `tagName` option. When called without arguments, registers in the global `customElements` registry. Pass a `CustomElementRegistry` instance to register in a [scoped registry](/components/options#scoped-registration) instead. Does nothing in non-browser environments. | | `ClassName.observedAttributes` | The list of attributes the browser should watch for changes, built from `props` option plus the built-in `text` attribute. | ### Error codes | Error | Explanation | |---------|-------------| | "text" is reserved. | You included `"text"` in `static props`. Elena manages `text` as a built-in reactive property, remove it from the props array to fix the error. | | define() without a tagName. | `ClassName.define()` was called but `static tagName` is not set on the class. Add a `static tagName` before calling `define()`. | | `Element not found.` | The CSS selector in `static element` did not match any element in the rendered output. Check that the selector is correct and that `render()` produces a matching element. | | `Cannot add events.` | `static events` is set but no inner element reference could be resolved. Either add a `render()` that produces an inner element, or check your `static element` selector. | | Prop "\" has no default. | An attribute changed for a prop that has no corresponding instance field default. Add a default value (e.g. `myProp = ""`) to the component class body. | | `Invalid JSON: ` | An `Array` or `Object` prop received an attribute value that could not be parsed as JSON. Check that the attribute value is valid JSON. The prop will be set to `null`. | | `Cannot sync attrs.` | `syncAttribute()` was called with a null element reference. This usually means the inner element was not found before attribute sync ran. Check your `static element` selector. | ## `@elenajs/bundler` ### Commands ```bash elena build elena watch ``` ### CLI flags | Flag | Description | |------|-------------| | `--config ` | Path to a config file. Defaults to `elena.config.mjs` or `elena.config.js` in the project root. | ### `elena.config.mjs` options | Option | Type | Default | Description | |--------|------|---------|-------------| | `input` | `string` | `"src"` | The folder containing your component source files. | | `output.dir` | `string` | `"dist"` | Where to write the compiled output. | | `output.format` | `string` | `"esm"` | JavaScript module format for the output files. | | `output.sourcemap` | `boolean` | `true` | Whether to generate source maps alongside the output. | | `output.filename` | `string` | `"bundle.js"` | Output filename for the single-file bundle. The CSS bundle filename is derived by replacing the `.js` extension with `.css`. | | `bundle` | `string \| false` | `"src/index.js"` | Entry point for a single combined output file. Elena will look for `src/index.ts` automatically if no `.js` file is found. Set to `false` to skip the bundle entirely. | | `plugins` | `Plugin[]` | `[]` | Extra Rollup plugins to include in the build, added after Elena’s built-in ones. | | `analyze` | `object \| false` | `{ plugins: [] }` | CEM analysis options. Set to `false` to skip Custom Elements Manifest generation, TypeScript declarations, and JSX types entirely. | | `analyze.plugins` | `Plugin[]` | `[]` | Extra plugins for the Custom Elements Manifest generation step. | | `target` | `string \| string[] \| false` | `false` | Browserslist target(s) for transpilation. When set, enables syntax transforms (e.g. class fields, optional chaining) via `@babel/preset-env` to widen browser support. Example: `["chrome 71", "firefox 69", "safari 12.1"]`. | | `terser` | `object` | `{ ecma: 2020, module: true }` | Custom Terser minifier options, merged with the defaults. | | `banner` | `string \| false` | `false` | Banner comment prepended to `index.js` and `bundle.js` output files. Use a `@license` JSDoc tag so minifiers preserve it. | | `registration` | `"auto" \| "scoped"` | `"auto"` | Controls how components are registered. `"auto"` preserves `.define()` calls in the output. `"scoped"` strips `.define()` calls and generates a `register.js` with a `defineAll(registry?)` helper for [scoped registry](/components/options#scoped-registration) usage. | ### Error codes | Error | Explanation | |---------|-------------| | Unknown command: \. | You ran `elena ` with an unrecognized command. The CLI only accepts `elena build` or `elena watch`. | | Config file not found: \. | The `--config` flag points to a file that does not exist. Check the path and try again. | | Found "elena.config\" but only .mjs and .js are supported. | Elena found a config file with an unsupported extension (e.g. `.ts`, `.json`, `.cjs`). Rename it to `elena.config.mjs` or `elena.config.js`. | | Unknown config option "\". | Your config file contains an unrecognized option. Check for typos. Valid options are: `input`, `output`, `bundle`, `plugins`, `analyze`, `target`, `terser`, `banner`. | | Invalid config: "\