zena:web-elements

zena
import {…} from 'zena:web-elements';

Classes

ZenaElement

zena
abstract class ZenaElement
Re-exported from zena:web-elements/core.zena

The base class of an element the host defines from this module.

The lifecycle methods have empty defaults; a subclass overrides the ones it needs. render is called by the host after requestUpdate, once per microtask however many times it was asked.

Properties
zena
var definition: ElementDefinition | null
#

The definition this instance was made from; set by the host's create.

Methods
zena
abstract render(): TemplateResult
#

What the element shows now.

zena
styles(): CSSResult | null
#

The element's styles, from css. The host reads them once per definition, from the instance defineElement constructs, and adopts one stylesheet into every instance's shadow root. Lit's styles is a static field; a static cannot be reached from a definition without a class value, so this is a method, at the same cost.

zena
connected(): void
#

The element was inserted into a document.

zena
disconnected(): void
#

The element was removed from its document.

zena
attributeChanged(name: String, value: String | null): void
#

An observed attribute changed; value is null when it was removed.

zena
updated(first: boolean): void
#

The host rendered the last result; first on the first render.

zena
requestUpdate(): void
#

Ask the host to render before the next frame.

zena
dispatchEvent(type: String, bubbles: boolean = true, composed: boolean = true, cancelable: boolean = false): boolean
#

Dispatch an Event of type from the element, bubbling and composed by default. The event carries no payload: a listener reads what it needs off the element, as it does for change or input, which is also how an element dispatches those standard events. Returns false when a listener canceled a cancelable event.

CSSResult

zena
final class CSSResult
Re-exported from zena:web-elements/core.zena

A stylesheet for an element's styles: the text the host puts in one constructible stylesheet per definition. Only css results and numbers interpolate, as in Lit; unsafeCSS admits text the author vouches for.

Constructors
zena
new()
#
Properties
zena
cssText: String
#

PropertyDef

zena
final class PropertyDef
Re-exported from zena:web-elements/core.zena

One declared property: its name, its attribute, and its accessors over boxed values. The accessors are generic over the field's type where registerProperty makes them, and box so the protocol's typed getter and setter exports can test the box for the kind.

Constructors
zena
new()
#
Properties
zena
name: String
#
zena
attribute: String
#

The observed attribute, or the empty string for none.

zena
read: (element: ZenaElement) => anyref
#
zena
write: (element: ZenaElement, value: anyref) => void
#
zena
var kind: PropertyKind
#

Decided from the probe instance's value on first demand.

zena
var definition: ElementDefinition | null
#

The definition that declares the property; set when it is added.

ElementDefinition

zena
final class ElementDefinition
Re-exported from zena:web-elements/core.zena

A registered element: what defineElement records and the host reads.

Constructors
zena
new()
#
Properties
zena
tag: String
#
zena
create: () => ZenaElement
#
zena
var properties
#
zena
var probe: ZenaElement | null
#

The instance constructed to read the property declarations. Kept, because a property's kind is decided from its value on first demand, and the styles are read from it.

Methods
zena
addProperty(property: PropertyDef): void
#

TemplateResult

zena
final class TemplateResult
Re-exported from zena:web-templates/result.zena

A template and the values for its holes.

strings is the tagged template's TemplateStringsArray, which the compiler makes once per call site; that identity is what tells the host it has seen the template before.

Constructors
zena
new()
#
Properties
zena
strings: TemplateStringsArray
#
zena
values: FixedArray<TemplateValue>
#
zena
kind: i32
#

1 for HTML, 2 for SVG, 3 for MathML.

HostValue

zena
final class HostValue
Re-exported from zena:web-templates/result.zena

A JavaScript value the module holds without looking inside it, so it can sit in a template: a DOM node for .node=${…}, a Date for a child's property. The host hands the value back unchanged.

Constructors
zena
new()
#
Properties
zena
handle: externref
#

Event

zena
extension class Event
Re-exported from zena:web-templates/result.zena

The event a listener receives: the host's event object, with the capability functions as methods, which are all a module can do with an event unless the host grants more.

An extension class rather than a wrapper, so a listener's event costs no allocation and a method's import is linked only when something calls it: a module whose listeners never read their events imports none of these.

Methods
zena
targetValue(): String
#

event.target.value: the text of the input that fired the event.

zena
key(): String
#

event.key of a keyboard event.

zena
preventDefault(): void
#
zena
stopPropagation(): void
#

Mixins

property

zena
mixin property<T> on ZenaElement
Extends ZenaElement
Re-exported from zena:web-elements/core.zena

A property of the element: declared to the host, reflected from its attribute (the lowercased field name), and re-rendering on write.

The #declared initializer runs once per instance; it registers the field with the definition being probed by defineElement and does nothing for every later instance. Registering from an initializer is what field decorators can do today; a per-class registration, run once at module start, is the form this will take once decorators have static members.

Properties
zena
value: T { get; set; }
#
9 inherited members
Properties
zena
var definition: ElementDefinition | null
#

The definition this instance was made from; set by the host's create.

Methods
zena
abstract render(): TemplateResult
#

What the element shows now.

zena
styles(): CSSResult | null
#

The element's styles, from css. The host reads them once per definition, from the instance defineElement constructs, and adopts one stylesheet into every instance's shadow root. Lit's styles is a static field; a static cannot be reached from a definition without a class value, so this is a method, at the same cost.

zena
connected(): void
#

The element was inserted into a document.

zena
disconnected(): void
#

The element was removed from its document.

zena
attributeChanged(name: String, value: String | null): void
#

An observed attribute changed; value is null when it was removed.

zena
updated(first: boolean): void
#

The host rendered the last result; first on the first render.

zena
requestUpdate(): void
#

Ask the host to render before the next frame.

zena
dispatchEvent(type: String, bubbles: boolean = true, composed: boolean = true, cancelable: boolean = false): boolean
#

Dispatch an Event of type from the element, bubbling and composed by default. The event carries no payload: a listener reads what it needs off the element, as it does for change or input, which is also how an element dispatches those standard events. Returns false when a listener canceled a cancelable event.

state

zena
mixin state<T> on ZenaElement
Extends ZenaElement
Re-exported from zena:web-elements/core.zena

Internal reactive state: re-renders on write, like @property, and is declared to the host as a property without an attribute, which is what Lit's @state is.

Properties
zena
value: T { get; set; }
#
9 inherited members
Properties
zena
var definition: ElementDefinition | null
#

The definition this instance was made from; set by the host's create.

Methods
zena
abstract render(): TemplateResult
#

What the element shows now.

zena
styles(): CSSResult | null
#

The element's styles, from css. The host reads them once per definition, from the instance defineElement constructs, and adopts one stylesheet into every instance's shadow root. Lit's styles is a static field; a static cannot be reached from a definition without a class value, so this is a method, at the same cost.

zena
connected(): void
#

The element was inserted into a document.

zena
disconnected(): void
#

The element was removed from its document.

zena
attributeChanged(name: String, value: String | null): void
#

An observed attribute changed; value is null when it was removed.

zena
updated(first: boolean): void
#

The host rendered the last result; first on the first render.

zena
requestUpdate(): void
#

Ask the host to render before the next frame.

zena
dispatchEvent(type: String, bubbles: boolean = true, composed: boolean = true, cancelable: boolean = false): boolean
#

Dispatch an Event of type from the element, bubbling and composed by default. The event carries no payload: a listener reads what it needs off the element, as it does for change or input, which is also how an element dispatches those standard events. Returns false when a listener canceled a cancelable event.

Enums

PropertyKind

zena
enum PropertyKind
Re-exported from zena:web-elements/core.zena

The protocol's property kinds; the values are its value kinds.

Members
zena
Unknown
#
zena
Text
#
zena
Number
#
zena
Boolean
#
zena
Host
#

Type aliases

CSSValue

zena
type CSSValue = CSSResult | Box<i32> | Box<f64>
Re-exported from zena:web-elements/core.zena

TemplateValue

zena
type TemplateValue = String | TemplateResult | Iterable<TemplateValue> | Listener | Box<i32> | Box<f64> | Box<boolean> | HostValue | null
Re-exported from zena:web-templates/result.zena

What a hole may hold. A number or boolean arrives boxed: the union accepts the box, which is what tells the checker to wrap a primitive interpolation in one. null renders nothing, and an iterable renders each of its items in turn.

Listener

zena
type Listener = (event: Event) => void
Re-exported from zena:web-templates/result.zena

An event listener, for an @event=${…} hole.

Functions

css

zena
function css(strings: TemplateStringsArray, values: FixedArray<CSSValue>): CSSResult
Re-exported from zena:web-elements/core.zena

The css tag: a stylesheet, with css results and numbers interpolated.

unsafeCSS

zena
function unsafeCSS(text: String): CSSResult
Re-exported from zena:web-elements/core.zena

A stylesheet from text the author vouches for, as Lit's unsafeCSS.

registerProperty

zena
function registerProperty<T>(name: String, get: (element: ZenaElement) => T, set: (element: ZenaElement, value: T) => void, attribute: boolean): i32
Re-exported from zena:web-elements/core.zena

Declares a property of the element class being probed: its name, its accessors over the host, and whether an attribute reflects into it. Called by @property and @state through the decorator's context. Returns 0, so it can initialize a field.

defineElement

zena
function defineElement(tag: String, create: () => ZenaElement): ElementDefinition
Re-exported from zena:web-elements/core.zena

Registers an element definition. The host defines a custom element named tag whose instances create makes, with the properties its @property and @state fields declare.

create is a closure because a class is not a value in Zena today: there is no constructor reference to pass, so the factory is written out. The design document lists a constructor reference among the language changes this library would use.

One instance is constructed here and kept: constructing it is what runs the decorators' registrations, and its values decide each property's kind.

declareElement

zena
function declareElement(create: () => ZenaElement): ElementDefinition
Re-exported from zena:web-elements/core.zena

Registers an element definition with no tag name. The host builds the custom element class from it and leaves naming and registration to the page (elementDefinitions in @zena-lang/wasm-web-ui/elements), which is how one module serves pages that disagree about tag names.

definitionFor

zena
function definitionFor(tag: String): ElementDefinition | null
Re-exported from zena:web-elements/core.zena

The definition registered under tag, or null.

createElement

zena
function createElement(definition: ElementDefinition): ZenaElement
Re-exported from zena:web-elements/core.zena

A new instance of definition, bound to it.

propertyKind

zena
function propertyKind(property: PropertyDef): PropertyKind
Re-exported from zena:web-elements/core.zena

A property's kind, decided from its definition's probe instance once.

stylesOf

zena
function stylesOf(definition: ElementDefinition): CSSResult | null
Re-exported from zena:web-elements/core.zena

The definition's styles, from its probe instance; null for none.

readProperty

zena
function readProperty(element: ZenaElement, property: PropertyDef): anyref
Re-exported from zena:web-elements/core.zena

The boxed value of property on element, as the field's box.

setTextProperty

zena
function setTextProperty(element: ZenaElement, property: PropertyDef, text: String): void
Re-exported from zena:web-elements/core.zena

Sets a text property from text; nothing for a property of another kind.

setHostProperty

zena
function setHostProperty(element: ZenaElement, property: PropertyDef, value: externref): void
Re-exported from zena:web-elements/core.zena

Sets a host-value property from the host's reference.

setNumberProperty

zena
function setNumberProperty(element: ZenaElement, property: PropertyDef, value: f64): void
Re-exported from zena:web-elements/core.zena

Sets a number or boolean property from a number; nothing for another kind.

applyAttribute

zena
function applyAttribute(element: ZenaElement, property: PropertyDef, text: String): void
Re-exported from zena:web-elements/core.zena

An observed attribute was set. The attribute's text is converted by the property's kind, as Lit's default converters do: a number is parsed, a boolean attribute is true when present, text is taken as it is. A host-value property takes nothing from an attribute.

removeAttribute

zena
function removeAttribute(element: ZenaElement, property: PropertyDef): void
Re-exported from zena:web-elements/core.zena

An observed attribute was removed: a boolean goes false, text goes empty.

propertyForAttribute

zena
function propertyForAttribute(definition: ElementDefinition, name: String): PropertyDef | null
Re-exported from zena:web-elements/core.zena

The property whose attribute is name, or null.

webui_element_count

zena
function webui_element_count(): i32
Re-exported from zena:web-elements/protocol.zena

webui_element_at

zena
function webui_element_at(index: i32): ElementDefinition
Re-exported from zena:web-elements/protocol.zena

webui_definition_tag

zena
function webui_definition_tag(definition: ElementDefinition): externref
Re-exported from zena:web-elements/protocol.zena

webui_definition_styles

zena
function webui_definition_styles(definition: ElementDefinition): externref | null
Re-exported from zena:web-elements/protocol.zena

The definition's stylesheet text, or null for none.

webui_definition_property_count

zena
function webui_definition_property_count(definition: ElementDefinition): i32
Re-exported from zena:web-elements/protocol.zena

webui_definition_property

zena
function webui_definition_property(definition: ElementDefinition, index: i32): PropertyDef
Re-exported from zena:web-elements/protocol.zena

webui_definition_create

zena
function webui_definition_create(definition: ElementDefinition): ZenaElement
Re-exported from zena:web-elements/protocol.zena

The constructor: a new instance of the definition.

webui_property_name

zena
function webui_property_name(property: PropertyDef): externref
Re-exported from zena:web-elements/protocol.zena

webui_property_attribute

zena
function webui_property_attribute(property: PropertyDef): externref
Re-exported from zena:web-elements/protocol.zena

webui_property_kind

zena
function webui_property_kind(property: PropertyDef): i32
Re-exported from zena:web-elements/protocol.zena

webui_element_connected

zena
function webui_element_connected(element: ZenaElement): void
Re-exported from zena:web-elements/protocol.zena

webui_element_disconnected

zena
function webui_element_disconnected(element: ZenaElement): void
Re-exported from zena:web-elements/protocol.zena

webui_element_attribute_changed

zena
function webui_element_attribute_changed(element: ZenaElement, property: PropertyDef, value: externref): void
Re-exported from zena:web-elements/protocol.zena

The property's observed attribute was set; value is the attribute's text.

webui_element_attribute_removed

zena
function webui_element_attribute_removed(element: ZenaElement, property: PropertyDef): void
Re-exported from zena:web-elements/protocol.zena

webui_element_get_extern

zena
function webui_element_get_extern(element: ZenaElement, property: PropertyDef): externref | null
Re-exported from zena:web-elements/protocol.zena

webui_element_get_number

zena
function webui_element_get_number(element: ZenaElement, property: PropertyDef): f64
Re-exported from zena:web-elements/protocol.zena

webui_element_set_extern

zena
function webui_element_set_extern(element: ZenaElement, property: PropertyDef, value: externref): void
Re-exported from zena:web-elements/protocol.zena

webui_element_set_number

zena
function webui_element_set_number(element: ZenaElement, property: PropertyDef, value: f64): void
Re-exported from zena:web-elements/protocol.zena

webui_element_render

zena
function webui_element_render(element: ZenaElement): TemplateResult
Re-exported from zena:web-elements/protocol.zena

webui_element_updated

zena
function webui_element_updated(element: ZenaElement, first: i32): void
Re-exported from zena:web-elements/protocol.zena

renderElement

zena
function renderElement(definition: ElementDefinition, attributes: Map<String, String>, tag: String = ''): String
Re-exported from zena:web-elements/ssr.zena

Renders definition as an element: the tag with attributes, a declarative shadow root with the styles and the template, and the end tag. The attributes are applied to a fresh instance before it renders, as the host applies them on the page, so the markup matches what the page's instance will render from the same attributes. tag names a definition declared without one, or renames a tagged one, as the page does when it registers the class itself.

renderResult

zena
function renderResult(result: TemplateResult): String
Re-exported from zena:web-elements/ssr.zena

Renders a template result with hydration markers.

templateDigest

zena
function templateDigest(strings: TemplateStringsArray): String
Re-exported from zena:web-elements/ssr.zena

Lit's digest of a template's strings, which hydration compares against the digest of the template it is given: two 32-bit DJB hashes over each string's UTF-16 code units, alternating per unit, as 8 bytes in base64.

html

zena
function html(strings: TemplateStringsArray, values: FixedArray<TemplateValue>): TemplateResult
Re-exported from zena:web-templates/result.zena

An HTML template.

svg

zena
function svg(strings: TemplateStringsArray, values: FixedArray<TemplateValue>): TemplateResult
Re-exported from zena:web-templates/result.zena

An SVG template, for use inside an <svg> element.

mathml

zena
function mathml(strings: TemplateStringsArray, values: FixedArray<TemplateValue>): TemplateResult
Re-exported from zena:web-templates/result.zena

A MathML template, for use inside a <math> element.

Variables

definitions

zena
let definitions: GrowableArray<ElementDefinition>
Re-exported from zena:web-elements/core.zena

Every definition the module registered, in registration order.

nothing

zena
let nothing: TemplateValue
Re-exported from zena:web-templates/result.zena

The value that renders nothing.