Skip to content

API Reference

@elenajs/core Pre-release

ExportSignatureDescription
ElenaElena(superClass)Creates an Elena component base class. Pass in HTMLElement to get started. Configure the component using static component options on the returned class.

Template utilities

ExportSignatureDescription
htmlhtml`...`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().
nothingnothingUse this in conditional expressions when you want to render nothing. Safer than "" or false, which can produce unexpected output.
unsafeHTMLunsafeHTML(str)Renders a plain string as raw HTML, skipping automatic escaping. Only use this for content you fully control.

Component options

FieldTypeDescription
tagNamestringThe 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.
eventsstring[]Events to forward from the inner element up to the host (e.g. ["click", "focus", "blur"]).
elementstringA 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.
stylesCSSStyleSheet | string | (CSSStyleSheet | string)[]One or more stylesheets to adopt into the shadow root. Only applies when shadow is also set.

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.

AttributeDescription
hydratedAdded 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

PropertyTypeDescription
textstringThe 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.
elementHTMLElement | nullA reference to the inner element, resolved after the first render using the element option.

Lifecycle methods

MethodDescription
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

PropertyTypeDescription
updateCompletePromise<void>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

MethodDescription
ClassName.define()Registers the component with the browser using tagName option. Call this once after defining your class. Does nothing in non-browser environments.
ClassName.observedAttributesThe list of attributes the browser should watch for changes, built from props option plus the built-in text attribute.

Error codes

ErrorExplanation
"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 "<name>" 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: <value>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 Pre-release

Commands

bash
elena build
elena watch

CLI flags

FlagDescription
--config <path>Path to a config file. Defaults to elena.config.mjs or elena.config.js in the project root.

elena.config.mjs options

OptionTypeDefaultDescription
inputstring"src"The folder containing your component source files.
output.dirstring"dist"Where to write the compiled output.
output.formatstring"esm"JavaScript module format for the output files.
output.sourcemapbooleantrueWhether to generate source maps alongside the output.
bundlestring | 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.
pluginsPlugin[][]Extra Rollup plugins to include in the build, added after Elena’s built-in ones.
analyzeobject | false{ plugins: [] }CEM analysis options. Set to false to skip Custom Elements Manifest generation, TypeScript declarations, and JSX types entirely.
analyze.pluginsPlugin[][]Extra plugins for the Custom Elements Manifest generation step.
targetstring | string[] | falsefalseBrowserslist 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"].
terserobject{ ecma: 2020, module: true }Custom Terser minifier options, merged with the defaults.
bannerstring | falsefalseBanner comment prepended to index.js and bundle.js output files. Use a @license JSDoc tag so minifiers preserve it.

Error codes

ErrorExplanation
Unknown command: <command>.You ran elena <command> with an unrecognized command. The CLI only accepts elena build or elena watch.
Config file not found: <path>.The --config flag points to a file that does not exist. Check the path and try again.
Found "elena.config<ext>" 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 "<key>".Your config file contains an unrecognized option. Check for typos. Valid options are: input, output, bundle, plugins, analyze, target, terser, banner.
Invalid config: "<option>" must be <type>.A config option has the wrong type. The error message tells you which option and what type it expects. See the config options table for correct types.
Input directory "<dir>" does not exist.The input directory (default "src") was not found. Make sure it exists, or set the input option to the correct path.
Bundle entry "<path>" does not exist.The bundle entry point (default "src/index.js") was not found. Create the file, or set bundle to false to skip bundling.
Build error:Rollup encountered an error during a watch rebuild. The underlying error is logged directly after this message.

@elenajs/cli Pre-release

bash
npx elena-create

Starts an interactive prompt that walks you through creating a new Elena component. No flags needed, it asks you everything it needs:

PromptOptions
Component nameAny valid kebab-case custom element name (e.g. my-button)
Component featuresProps, events, methods, CSS custom properties, encapsulation reset, SSR, and code comments (each optional)
LanguageJavaScript, TypeScript, or single-file HTML
Output directoryWhere to write the generated files

The generated files follow all Elena authoring patterns, including JSDoc annotations and @scope CSS.

@elenajs/ssr Experimental

ExportSignatureDescription
registerregister(...components)Tell the SSR renderer which component classes to expand. Each class must have tagName option set. Call this before ssr().
unregisterunregister(...components)Remove previously registered component classes from the SSR registry.
clearclear()Remove all registered component classes from the SSR registry at once.
ssrssr(html)Takes an HTML string, expands any registered components into full HTML, and returns the result. Full HTML documents (including <!DOCTYPE>) are supported.

@elenajs/plugin-rollup-css Pre-release

ExportSignatureDescription
cssPlugincssPlugin(srcDir)Copies and minifies each .css file from srcDir into the output folder as individual files.
cssBundlePlugincssBundlePlugin(srcDir, fileName)Combines all .css files from srcDir into a single minified file named fileName. CSS files resolved by cssModuleScriptPlugin are automatically excluded.
cssModuleScriptPlugincssModuleScriptPlugin()Handles CSS Module Script imports (with { type: "css" }). Reads and minifies the CSS file, then returns a JS module that constructs and exports a CSSStyleSheet for Shadow DOM adoption.
cssStaticStylesPlugincssStaticStylesPlugin()Finds static styles class fields with template literal values and minifies the CSS inside them.
minifyCssminifyCss(css, filename?)Minifies a CSS string using Lightning CSS.

@elenajs/plugin-cem-define Pre-release

ExportSignatureDescription
elenaDefinePluginelenaDefinePlugin()CEM plugin that reads tagName option from each Elena component class and registers it in the Custom Elements Manifest.

@elenajs/plugin-cem-prop Pre-release

ExportSignatureDescription
elenaPropPluginelenaPropPlugin()CEM plugin that reads @property or @prop JSDoc tags from component class fields and creates corresponding attributes entries in the Custom Elements Manifest.

@elenajs/plugin-cem-tag Pre-release

ExportSignatureDescription
elenaTagPluginelenaTagPlugin(jsdocTag)CEM plugin that copies a custom JSDoc tag from each component’s documentation comment into the Custom Elements Manifest. jsdocTag is the tag name without the @ (e.g. "status" for @status, "displayName" for @displayName). Call it once per tag you want to extract.

@elenajs/plugin-cem-typescript Pre-release

ExportSignatureDescription
elenaTypeScriptPluginelenaTypeScriptPlugin(options?)CEM plugin that generates a .d.ts type file for each component (e.g. button.d.ts alongside button.js), including typed props and event handler fields. Also adds the built-in text prop to every component’s type.

Options

OptionTypeDefaultDescription
outdirstring"dist"Where to write the generated .d.ts TypeScript types.

@elenajs/mcp Experimental

Commands

bash
elena-mcp <project-root>

Resources

Resource URIDescription
elena://componentsA list of all components with their name, description, and status.
elena://components/{tagName}Full details for one component: props, events, CSS custom properties, and slots.
elena://patternsThe Elena component authoring guide.
elena://frameworksFramework integration guide (React, Vue, Angular, Svelte, Next.js, Eleventy, plain HTML).
elena://ssrServer-side rendering guide and @elenajs/ssr API reference.
elena://apiFull API reference for all Elena packages.

Tools

ToolDescription
scaffold-componentGenerates a starter JS class and CSS file for a new component.
lookup-componentLooks up a component’s API from the Custom Elements Manifest.
get-patternsReturns the Elena component authoring guide.
get-api-referenceReturns the full API reference for all Elena packages.
get-frameworks-guideReturns the framework integration guide.
get-ssr-guideReturns the SSR guide and @elenajs/ssr API reference.

Prompts

PromptDescription
create-componentA guided prompt for creating a new Elena component.
review-componentA guided prompt for reviewing a component against Elena best practices.