@hyperfixi/intent-element
v4.0.1
Published
<lse-intent> custom element — validates LSE protocol JSON and runs it on the page's hyperscript host (@hyperfixi/engine or upstream _hyperscript, via a LokaScriptSemantic render).
Maintainers
Readme
@hyperfixi/intent-element
The <lse-intent> custom element for hyperfixi — a declarative way to run LSE protocol JSON (LokaScript Explicit Syntax) from HTML. The element validates the JSON against the LSE schema, renders it to English hyperscript, and runs that on the page's hyperscript host.
Install
npm install @hyperfixi/intent-elementEvery peer dependency is optional: validation works with none of them. Executing an intent needs a hyperscript host and a renderer:
- the host is
@hyperfixi/engine'shyperfixi-hs.js(window.hyperfixi) or upstream_hyperscript— anything withevaluate(source, context); - the renderer is
@lokascript/semantic'srender(node, 'en'), taken from whicheverLokaScriptSemantic*browser bundle the page loads (browser-en.en.global.jsis the English-only one), or set onLSEIntentElement.render.
The intent is rendered to English (toggle .active on #sidebar) and evaluated with the element as me — the same text path as the lse_to_hyperscript tool. Without a renderer the element validates but does not execute, and reports NO_RENDERER. (@hyperfixi/core 3.x's window.hyperfixi.evalLSENode fallback is gone: hyperfixi.js is the engine's file, which has no such method.)
Usage
The browser build auto-registers <lse-intent>:
<script src="hyperfixi-hs.js"></script>
<script src="browser-en.en.global.js"></script>
<script src="intent-element.iife.global.js"></script>
<!-- Inline LSE JSON -->
<lse-intent trigger="click">
<script type="application/lse+json">
{
"action": "toggle",
"roles": { "patient": { "type": "selector", "value": ".active" } }
}
</script>
<button>Toggle</button>
</lse-intent>
<!-- …or fetch the intent from a URL -->
<lse-intent src="/intents/toggle.json"></lse-intent>The intent is read from a child <script type="application/lse+json"> or fetched via the src attribute. The optional trigger attribute names the DOM event that runs the intent (default: run on connect).
Why a custom element
- Declarative. Behavior travels as data — LSE JSON — not imperative code. It can be authored, stored, and served like any other content.
- Validated. The JSON is checked against the LSE schema (via the zero-dependency
@lokascript/intentpackage) before anything executes; malformed intents fail loudly instead of silently misbehaving. - Sandboxed. Execution runs through a bounded sandbox with a timeout, so a runaway intent can't lock the page.
- Composable. Because the element accepts
src="/intents/foo.json", intents can live in static files or come from an API.
API exports
For programmatic use (e.g. registering the element yourself, or custom schemas):
LSEIntentElement— theHTMLElementsubclass (already defined aslse-intentby the browser build).intentRegistry— the LSE command-schema registry.- Type:
SandboxResult.
The IIFE build exposes these on window.HyperFixiIntentElement.
License
MIT
