dom-ffi

    Typed MoonBit bindings for browser DOM APIs

    dom
    ffi
    Download zip
    Author
    Version
    0.4.0
    License
    Apache-2.0
    Last updated
    17 days ago
    Downloads
    4K

    #dom-ffi

    Typed MoonBit bindings for browser DOM APIs, with runtime conformance tests.

    Docs: https://mooncakes.io/docs/#/tiye/dom-ffi/lib/members

    moon add tiye/dom-ffi

    "import": [{ "path": "tiye/dom-ffi", "alias": "dom_ffi" }]

    Currently it contains:

    • querying elements
    • setting attributes
    • setting styles
    • adding event listeners
    • location
    • search params

    The public surface targets JavaScript and follows the corresponding Web IDL nullability. DOM NodeList and HTMLCollection values are copied into MoonBit arrays; these arrays are snapshots rather than live collections.

    #Quality checks

    moon check --target js moon test --target js moon build --target js --debug corepack yarn@1.22.22 install --frozen-lockfile corepack yarn@1.22.22 test:browser

    The browser suite runs the compiled MoonBit bindings against real Chromium. Run corepack yarn@1.22.22 playwright install chromium once if Chromium is not already installed.

    #License

    Apache License 2.0

    BeforeUnloadEvent

    #external
    pub(all) type BeforeUnloadEvent

    Blob

    #external
    pub type Blob

    | Immutable raw binary data. | | MDN Reference

    Blob::new_from_text

    fn Blob::new_from_text(text : String, type_? : String) -> Blob

    | Creates a text-backed blob with an optional MIME type. | | MDN Reference

    Blob::size

    fn Blob::size(self : Blob) -> Int

    | Returns the number of bytes in this blob. | | MDN Reference

    Blob::type_

    fn Blob::type_(self : Blob) -> String

    | Returns the MIME type, or an empty string when unspecified. | | MDN Reference

    BlurEvent

    #external
    pub type BlurEvent

    CSSStyleDeclaration

    #external
    pub(all) type CSSStyleDeclaration

    CSSStyleDeclaration::remove_property

    fn CSSStyleDeclaration::remove_property(self : CSSStyleDeclaration, name : String) -> Unit

    CSSStyleDeclaration::set_property

    fn CSSStyleDeclaration::set_property(self : CSSStyleDeclaration, name : String, value : String) -> Unit

    DataTransfer

    #external
    pub type DataTransfer

    DataTransfer::clear_data

    fn DataTransfer::clear_data(self : DataTransfer) -> Unit

    DataTransfer::files

    fn DataTransfer::files(self : DataTransfer) -> FileList

    | Returns the files held by a drag data store. | | MDN Reference

    DataTransfer::get_data

    fn DataTransfer::get_data(self : DataTransfer, format : String) -> String

    DataTransfer::set_data

    fn DataTransfer::set_data(self : DataTransfer, format : String, data : String) -> Unit

    DataTransfer::set_drop_effect

    fn DataTransfer::set_drop_effect(self : DataTransfer, effect : String) -> Unit

    DataTransfer::set_effect_allowed

    fn DataTransfer::set_effect_allowed(self : DataTransfer, effect : String) -> Unit

    Document

    #external
    pub(all) type Document

    | The Document interface represents any web page loaded in the browser and serves as an entry point into the web page's content, which is the DOM tree. | | MDN Reference

    Document::body

    fn Document::body(self : Document) -> Element?

    | Returns the <body> or <frameset> element, or None while the | document has no body.

    Document::create_element

    fn Document::create_element(self : Document, name : String) -> Element

    | Creates the HTML element specified by tagName. | | MDN Reference

    Document::get_element_by_id

    fn Document::get_element_by_id(self : Document, id : String) -> Element?

    | Returns a reference to the element by its ID. | Returns None if no element with the specified ID is found. | | MDN Reference

    Document::head

    fn Document::head(self : Document) -> Element?

    | Returns the <head> element, or None when the document has no head.

    Document::query_selector

    fn Document::query_selector(self : Document, selector : String) -> Element?

    | Returns the first Element within the document that matches the specified selector, or group of selectors. | If no matches are found, None is returned. | | MDN Reference

    Document::query_selector_all

    fn Document::query_selector_all(self : Document, selector : String) -> Array[Element]

    | Returns a static (not live) NodeList representing a list of the document's elements that match the specified group of selectors. | | MDN Reference

    Document::reinterpret_as_event_target

    fn Document::reinterpret_as_event_target(self : Document) -> EventTarget

    | Reinterprets a document as an EventTarget without changing the | JavaScript value.

    DomRect

    pub(all) struct DomRect {
    x : Float
    y : Float
    width : Float
    height : Float
    top : Float
    right : Float
    bottom : Float
    left : Float
    }

    | Represents a rectangle describing the size and position of an element. | | MDN Reference

    DomTokenList

    #external
    pub type DomTokenList

    | A set-like collection of CSS class tokens. | | MDN Reference

    DomTokenList::add

    fn DomTokenList::add(self : DomTokenList, token : String) -> Unit

    | Adds a class token when it is not already present. | | MDN Reference

    DomTokenList::contains

    fn DomTokenList::contains(self : DomTokenList, token : String) -> Bool

    | Returns whether this collection contains token. | | MDN Reference

    DomTokenList::remove

    fn DomTokenList::remove(self : DomTokenList, token : String) -> Unit

    | Removes a class token when it is present. | | MDN Reference

    DomTokenList::to_array

    fn DomTokenList::to_array(self : DomTokenList) -> Array[String]

    | Returns a snapshot MoonBit array of the tokens in their current order. | | MDN Reference

    DomTokenList::toggle

    fn DomTokenList::toggle(self : DomTokenList, token : String) -> Bool

    | Toggles a class token and returns whether it is present afterwards. | | MDN Reference

    DragEvent

    #external
    pub type DragEvent

    DragEvent::client_x

    fn DragEvent::client_x(self : DragEvent) -> Float

    | Returns the horizontal coordinate within the viewport at which the event occurred. | | MDN Reference

    DragEvent::client_y

    fn DragEvent::client_y(self : DragEvent) -> Float

    | Returns the vertical coordinate within the viewport at which the event occurred. | | MDN Reference

    DragEvent::data_transfer

    fn DragEvent::data_transfer(self : DragEvent) -> DataTransfer?

    | Returns the drag data store, or None for a synthetic event without | one.

    DragEvent::offset_x

    fn DragEvent::offset_x(self : DragEvent) -> Float

    | Returns the horizontal offset (in pixels) from the left edge of the target element's padding edge. | | MDN Reference

    DragEvent::offset_y

    fn DragEvent::offset_y(self : DragEvent) -> Float

    | Returns the vertical offset (in pixels) from the top edge of the target element's padding edge. | | MDN Reference

    DragEvent::page_x

    fn DragEvent::page_x(self : DragEvent) -> Float

    | Returns the horizontal coordinate (in pixels) relative to the left edge of the entire document. | | MDN Reference

    DragEvent::page_y

    fn DragEvent::page_y(self : DragEvent) -> Float

    | Returns the vertical coordinate (in pixels) relative to the top edge of the entire document. | | MDN Reference

    DragEvent::prevent_default

    fn DragEvent::prevent_default(self : DragEvent) -> Unit

    DragEvent::stop_propagation

    fn DragEvent::stop_propagation(self : DragEvent) -> Unit

    Element

    #external
    pub(all) type Element

    | The most general base class from which all objects in a Document inherit. | | MDN Reference

    Element::append_child

    fn Element::append_child(self : Element, child : Node) -> Unit

    | Adds a node to the end of the list of children of a specified parent node. | | MDN Reference

    Element::class_list

    fn Element::class_list(self : Element) -> DomTokenList

    | Returns the class-token collection for this element. | | MDN Reference

    Element::closest

    fn Element::closest(self : Element, selectors : String) -> Element?

    | Returns the nearest ancestor (including this element) that matches, or | None when no such ancestor exists. | | MDN Reference

    Element::contains

    fn Element::contains(self : Element, other : Node) -> Bool

    | Returns whether this element contains other, including itself. | | MDN Reference

    Element::data_attribute

    fn Element::data_attribute(self : Element, name : String) -> String?

    | Gets a custom dataset value, or None when the key is absent.

    Element::first_element_child

    fn Element::first_element_child(self : Element) -> Element?

    | Returns the first child element, or None when no child element exists. | | MDN Reference

    Element::focus

    fn Element::focus(self : Element) -> Unit

    | Sets focus on the specified element, if it can be focused. | | MDN Reference

    Element::get_attribute

    fn Element::get_attribute(self : Element, name : String) -> String?

    | Returns an attribute value, or None when the attribute is absent. | | MDN Reference

    Element::get_bounding_client_rect

    fn Element::get_bounding_client_rect(self : Element) -> DomRect

    | Returns the size of an element and its position relative to the viewport. | | MDN Reference

    Element::has_attribute

    fn Element::has_attribute(self : Element, name : String) -> Bool

    | Returns whether this element has an attribute with name. | | MDN Reference

    Element::inner_html

    fn Element::inner_html(self : Element) -> String

    | Returns the serialized HTML markup contained by this element. | | MDN Reference

    Element::js_query_selector

    fn Element::js_query_selector(self : Element, selector : String) -> JsObscure

    | Internal helper for querySelector.

    Element::last_element_child

    fn Element::last_element_child(self : Element) -> Element?

    | Returns the last child element, or None when no child element exists. | | MDN Reference

    Element::matches

    fn Element::matches(self : Element, selectors : String) -> Bool

    | Returns whether this element matches a CSS selector. | | MDN Reference

    Element::next_element_sibling

    fn Element::next_element_sibling(self : Element) -> Element?

    | Returns the following element sibling, or None at the end. | | MDN Reference

    Element::previous_element_sibling

    fn Element::previous_element_sibling(self : Element) -> Element?

    | Returns the preceding element sibling, or None at the beginning. | | MDN Reference

    Element::query_selector

    fn Element::query_selector(self : Element, selector : String) -> Element?

    | Returns the first Element within the element that matches the specified selector. | | MDN Reference

    Element::query_selector_all

    fn Element::query_selector_all(self : Element, selectors : String) -> Array[Element]

    | Returns a snapshot MoonBit array of descendants matching selectors. | | MDN Reference

    Element::reinterpret_as_event_target

    fn Element::reinterpret_as_event_target(self : Element) -> EventTarget

    | Reinterprets an element as an EventTarget without changing the | JavaScript value.

    Element::reinterpret_as_html_button_element

    fn Element::reinterpret_as_html_button_element(self : Element) -> HtmlButtonElement

    | Reinterprets an element as a button element without validating its tag. | | MDN Reference

    Element::reinterpret_as_html_form_element

    fn Element::reinterpret_as_html_form_element(self : Element) -> HtmlFormElement

    | Reinterprets an element as a form element without validating its tag. | | MDN Reference

    Element::reinterpret_as_html_input_element

    fn Element::reinterpret_as_html_input_element(self : Element) -> HtmlInputElement

    | Reinterprets an Element as an HtmlInputElement.

    Element::reinterpret_as_html_select_element

    fn Element::reinterpret_as_html_select_element(self : Element) -> HtmlSelectElement

    | Reinterprets an element as a select element without validating its tag. | | MDN Reference

    Element::reinterpret_as_html_textarea_element

    fn Element::reinterpret_as_html_textarea_element(self : Element) -> HtmlTextAreaElement

    | Reinterprets an Element as an HtmlTextAreaElement.

    Element::reinterpret_as_node

    fn Element::reinterpret_as_node(self : Element) -> Node

    | Reinterprets an Element as a Node. This is a type cast and does not change the underlying object.

    Element::remove_attribute

    fn Element::remove_attribute(self : Element, name : String) -> Unit

    | Removes an attribute from the specified element. | | MDN Reference

    Element::remove_data_attribute

    fn Element::remove_data_attribute(self : Element, name : String) -> Unit

    | Removes a custom data attribute (data-*). | | MDN Reference

    Element::set_attribute

    fn Element::set_attribute(self : Element, name : String, value : String) -> Unit

    | Sets the value of an attribute on the specified element. | | MDN Reference

    Element::set_data_attribute

    fn Element::set_data_attribute(self : Element, name : String, value : String) -> Unit

    | Sets a custom data attribute (data-*). | | MDN Reference

    Element::set_html_for

    fn Element::set_html_for(self : Element, html : String) -> Unit

    | Sets the for attribute of a label element. | | MDN Reference

    Element::set_inner_html

    fn Element::set_inner_html(self : Element, html : String) -> Unit

    | Sets the HTML markup contained within the element. | | MDN Reference

    Element::set_inner_text

    fn Element::set_inner_text(self : Element, text : String) -> Unit

    | Sets the text content of a node and its descendants. | | MDN Reference

    Element::set_onclick

    fn Element::set_onclick(self : Element, f : (MouseEvent) -> Unit) -> Unit

    | Sets the onclick event handler for an element. | | MDN Reference

    Element::set_ondblclick

    fn Element::set_ondblclick(self : Element, f : (MouseEvent) -> Unit) -> Unit

    | Sets the ondblclick event handler for an element. | | MDN Reference

    Element::set_ondrag

    fn Element::set_ondrag(self : Element, f : (DragEvent) -> Unit) -> Unit

    | Sets the ondrag event handler for an element. | | MDN Reference

    Element::set_ondragend

    fn Element::set_ondragend(self : Element, f : (DragEvent) -> Unit) -> Unit

    | Sets the ondragend event handler for an element. | | MDN Reference

    Element::set_ondragenter

    fn Element::set_ondragenter(self : Element, f : (DragEvent) -> Unit) -> Unit

    | Sets the ondragenter event handler for an element. | | MDN Reference

    Element::set_ondragleave

    fn Element::set_ondragleave(self : Element, f : (DragEvent) -> Unit) -> Unit

    | Sets the ondragleave event handler for an element. | | MDN Reference

    Element::set_ondragover

    fn Element::set_ondragover(self : Element, f : (DragEvent) -> Unit) -> Unit

    | Sets the ondragover event handler for an element. | | MDN Reference

    Element::set_ondragstart

    fn Element::set_ondragstart(self : Element, f : (DragEvent) -> Unit) -> Unit

    | Sets the ondragstart event handler for an element. | | MDN Reference

    Element::set_ondrop

    fn Element::set_ondrop(self : Element, f : (DragEvent) -> Unit) -> Unit

    | Sets the ondrop event handler for an element. | | MDN Reference

    Element::tag_name

    fn Element::tag_name(self : Element) -> String

    | Returns the tag name of the element in upper case. | | MDN Reference

    Element::text_content

    fn Element::text_content(self : Element) -> String

    | Returns this element's text content. | | MDN Reference

    Element::to_js_object

    fn Element::to_js_object(self : Element) -> JsObjectObscure

    cast Element to JsObjectObscure

    Element::toggle_attribute

    fn Element::toggle_attribute(self : Element, name : String) -> Bool

    | Toggles an attribute and returns whether it is present afterwards. | | MDN Reference

    Element::toggle_attribute_with_force

    fn Element::toggle_attribute_with_force(self : Element, name : String, force : Bool) -> Bool

    | Forces an attribute present or absent and returns its resulting presence. | | MDN Reference

    Element::unset_onclick

    fn Element::unset_onclick(self : Element) -> Unit

    | Removes the onclick event handler from an element.

    Element::unset_ondblclick

    fn Element::unset_ondblclick(self : Element) -> Unit

    | Removes the ondblclick event handler from an element.

    Element::unset_ondrag

    fn Element::unset_ondrag(self : Element) -> Unit

    | Removes the ondrag event handler from an element.

    Element::unset_ondragend

    fn Element::unset_ondragend(self : Element) -> Unit

    | Removes the ondragend event handler from an element.

    Element::unset_ondragenter

    fn Element::unset_ondragenter(self : Element) -> Unit

    | Removes the ondragenter event handler from an element.

    Element::unset_ondragleave

    fn Element::unset_ondragleave(self : Element) -> Unit

    | Removes the ondragleave event handler from an element.

    Element::unset_ondragover

    fn Element::unset_ondragover(self : Element) -> Unit

    | Removes the ondragover event handler from an element.

    Element::unset_ondragstart

    fn Element::unset_ondragstart(self : Element) -> Unit

    | Removes the ondragstart event handler from an element.

    Element::unset_ondrop

    fn Element::unset_ondrop(self : Element) -> Unit

    | Removes the ondrop event handler from an element.

    Event

    #external
    pub type Event

    | A generic browser event. | | MDN Reference

    Event::bubbles

    fn Event::bubbles(self : Event) -> Bool

    | Returns whether this event bubbles.

    Event::cancelable

    fn Event::cancelable(self : Event) -> Bool

    | Returns whether listeners can cancel this event.

    Event::current_target

    fn Event::current_target(self : Event) -> EventTarget?

    | Returns the event target whose listener is currently running, or None | outside listener dispatch.

    Event::default_prevented

    fn Event::default_prevented(self : Event) -> Bool

    | Returns whether prevent_default has canceled this event.

    Event::new

    fn Event::new(type_ : String) -> Event

    | Creates an event with the supplied type.

    Event::new_with_options

    fn Event::new_with_options(type_ : String, bubbles? : Bool, cancelable? : Bool) -> Event

    | Creates an event and explicitly configures whether it bubbles or can be | canceled.

    Event::prevent_default

    fn Event::prevent_default(self : Event) -> Unit

    | Cancels this event when it is cancelable.

    Event::reinterpret_as_submit_event

    fn Event::reinterpret_as_submit_event(self : Event) -> SubmitEvent

    | Reinterprets a generic event as a submission event when the caller knows | it originated from a submit listener. | | MDN Reference

    Event::stop_propagation

    fn Event::stop_propagation(self : Event) -> Unit

    | Prevents the event from continuing to later propagation targets.

    Event::target

    fn Event::target(self : Event) -> EventTarget?

    | Returns the target that originally received the event, or None before | the event is dispatched.

    Event::type_

    fn Event::type_(self : Event) -> String

    | Returns the event type.

    EventListenerOptions

    #external
    pub type EventListenerOptions

    | Options for an event listener registration. | | MDN Reference

    EventListenerOptions::new

    | Creates listener options with browser defaults: bubbling phase, reusable, | and non-passive. | | MDN Reference

    EventListenerOptions::set_capture

    fn EventListenerOptions::set_capture(self : EventListenerOptions, capture : Bool) -> Unit

    | Selects the capture phase for this listener. | | MDN Reference

    EventListenerOptions::set_once

    fn EventListenerOptions::set_once(self : EventListenerOptions, once : Bool) -> Unit

    | Removes this listener automatically after its first invocation. | | MDN Reference

    EventListenerOptions::set_passive

    fn EventListenerOptions::set_passive(self : EventListenerOptions, passive : Bool) -> Unit

    | Declares that this listener will not cancel its event with | prevent_default. | | MDN Reference

    EventTarget

    #external
    pub type EventTarget

    | A browser object that can receive events and manage event listeners. | | MDN Reference

    EventTarget::add_event_listener

    fn EventTarget::add_event_listener(self : EventTarget, type_ : String, listener : (Event) -> Unit) -> Unit

    | Adds a listener for events with type_. | | Keep the same callback value to remove this listener later. | | MDN Reference

    EventTarget::add_event_listener_with_options

    fn EventTarget::add_event_listener_with_options(self : EventTarget, type_ : String, listener : (Event) -> Unit, options : EventListenerOptions) -> Unit

    | Adds a listener with explicit capture, once, and passive options. | | Keep the same callback and capture setting to remove this listener later. | | MDN Reference

    EventTarget::dispatch_event

    fn EventTarget::dispatch_event(self : EventTarget, event : Event) -> Bool

    | Dispatches an event and returns false when a listener cancels a | cancelable event. | | MDN Reference

    EventTarget::new

    | Creates an isolated event target, which is useful for custom event channels | and tests.

    EventTarget::remove_event_listener

    fn EventTarget::remove_event_listener(self : EventTarget, type_ : String, listener : (Event) -> Unit) -> Unit

    | Removes a listener previously added with the same event type and callback. | | MDN Reference

    EventTarget::remove_event_listener_with_options

    fn EventTarget::remove_event_listener_with_options(self : EventTarget, type_ : String, listener : (Event) -> Unit, options : EventListenerOptions) -> Unit

    | Removes a listener added with add_event_listener_with_options. | | Only the capture option participates in listener matching; nevertheless, | passing the same options object makes that requirement explicit. | | MDN Reference

    File

    #external
    pub type File

    | A named file, which is also a Blob. | | MDN Reference

    File::last_modified

    fn File::last_modified(self : File) -> Int

    | Returns the millisecond timestamp at which this file was last modified. | | MDN Reference

    File::name

    fn File::name(self : File) -> String

    | Returns the file name without its path. | | MDN Reference

    File::new_from_text

    fn File::new_from_text(name : String, text : String, type_? : String) -> File

    | Creates a text-backed file with an optional MIME type. | | MDN Reference

    File::size

    fn File::size(self : File) -> Int

    | Returns the number of bytes in this file. | | MDN Reference

    File::type_

    fn File::type_(self : File) -> String

    | Returns the file MIME type, or an empty string when unspecified. | | MDN Reference

    FileList

    #external
    pub type FileList

    | A browser-owned collection of files. | | to_array returns a snapshot, not a live view of the browser collection. | | MDN Reference

    FileList::item

    fn FileList::item(self : FileList, index : Int) -> File?

    | Returns the file at index, or None when the index is out of range. | | MDN Reference

    FileList::length

    fn FileList::length(self : FileList) -> Int

    | Returns the number of files in this list. | | MDN Reference

    FileList::to_array

    fn FileList::to_array(self : FileList) -> Array[File]

    | Returns a snapshot MoonBit array of the files currently in this list. | | MDN Reference

    FocusEvent

    #external
    pub type FocusEvent

    FormData

    #external
    pub type FormData

    | A collection of form fields and files for form submission. | | MDN Reference

    FormData::append_file

    fn FormData::append_file(self : FormData, name : String, value : File) -> Unit

    | Appends a file without removing existing values for the same name. | | MDN Reference

    FormData::append_text

    fn FormData::append_text(self : FormData, name : String, value : String) -> Unit

    | Appends a text value without removing existing values for the same name. | | MDN Reference

    FormData::delete

    fn FormData::delete(self : FormData, name : String) -> Unit

    | Deletes every value for name. | | MDN Reference

    FormData::get

    fn FormData::get(self : FormData, name : String) -> FormDataValue?

    | Returns the first value for name, or None when no value is present. | | MDN Reference

    FormData::get_all

    fn FormData::get_all(self : FormData, name : String) -> Array[FormDataValue]

    | Returns a snapshot MoonBit array of all values for name in insertion | order. | | MDN Reference

    FormData::has

    fn FormData::has(self : FormData, name : String) -> Bool

    | Returns whether at least one value exists for name. | | MDN Reference

    FormData::new

    fn FormData::new() -> FormData

    | Creates empty form data. | | MDN Reference

    FormData::new_from_form

    fn FormData::new_from_form(form : HtmlFormElement) -> FormData

    | Creates FormData from the current successful controls in a form. | | The result is a snapshot; later control changes do not alter it. | | MDN Reference

    FormData::set_file

    fn FormData::set_file(self : FormData, name : String, value : File) -> Unit

    | Replaces all values for name with a file. | | MDN Reference

    FormData::set_text

    fn FormData::set_text(self : FormData, name : String, value : String) -> Unit

    | Replaces all values for name with a text value. | | MDN Reference

    FormDataValue

    pub enum FormDataValue {
    Text(String)
    File(File)
    }

    | A value stored in FormData: either text or a File. | | MDN Reference

    HtmlButtonElement

    #external
    pub type HtmlButtonElement

    | An HTML button element. | | MDN Reference

    HtmlButtonElement::disabled

    fn HtmlButtonElement::disabled(self : HtmlButtonElement) -> Bool

    | Returns whether the button is disabled. | | MDN Reference

    HtmlButtonElement::set_disabled

    fn HtmlButtonElement::set_disabled(self : HtmlButtonElement, disabled : Bool) -> Unit

    | Sets whether the button is disabled. | | MDN Reference

    HtmlButtonElement::set_value

    fn HtmlButtonElement::set_value(self : HtmlButtonElement, value : String) -> Unit

    | Sets the button value submitted with a form. | | MDN Reference

    HtmlButtonElement::value

    fn HtmlButtonElement::value(self : HtmlButtonElement) -> String

    | Returns the button value submitted with a form. | | MDN Reference

    HtmlFormElement

    #external
    pub type HtmlFormElement

    | An HTML form element. | | MDN Reference

    HtmlFormElement::check_validity

    fn HtmlFormElement::check_validity(self : HtmlFormElement) -> Bool

    | Returns whether all form controls pass constraint validation. | | MDN Reference

    HtmlFormElement::request_submit

    fn HtmlFormElement::request_submit(self : HtmlFormElement) -> Unit

    | Requests form submission without an explicit submitter. | | The browser performs constraint validation and dispatches a SubmitEvent. | | MDN Reference

    HtmlFormElement::request_submit_with_submitter

    fn HtmlFormElement::request_submit_with_submitter(self : HtmlFormElement, submitter : Element) -> Unit

    | Requests form submission with the supplied submitter element. | | The element must be a valid form-associated submit control, such as a | submit button or submit input; the browser throws for an invalid element. | | MDN Reference

    HtmlFormElement::reset

    fn HtmlFormElement::reset(self : HtmlFormElement) -> Unit

    | Resets form controls to their default values. | | MDN Reference

    HtmlFormElement::set_submission_method

    fn HtmlFormElement::set_submission_method(self : HtmlFormElement, submission_method : String) -> Unit

    | Sets the form submission method. | | MDN Reference

    HtmlFormElement::submission_method

    fn HtmlFormElement::submission_method(self : HtmlFormElement) -> String

    | Returns the form submission method in normalized lowercase form. | | MDN Reference

    HtmlInputElement

    #external
    pub(all) type HtmlInputElement

    | Provides an interface for the HTML <input> element. | | MDN Reference

    HtmlInputElement::checked

    fn HtmlInputElement::checked(self : HtmlInputElement) -> Bool

    | Returns whether an input is checked. | | MDN Reference

    HtmlInputElement::files

    | Returns the selected files, or None for input types without a file | selection list. | | MDN Reference

    HtmlInputElement::set_checked

    fn HtmlInputElement::set_checked(self : HtmlInputElement, checked : Bool) -> Unit

    | Sets whether an input is checked. | | MDN Reference

    HtmlInputElement::set_onblur

    fn HtmlInputElement::set_onblur(self : HtmlInputElement, f : (BlurEvent) -> Unit?) -> Unit

    | Sets the onblur event handler for an <input> element. | | MDN Reference

    HtmlInputElement::set_onchange

    fn HtmlInputElement::set_onchange(self : HtmlInputElement, f : (InputEvent) -> Unit?) -> Unit

    | Sets the onchange event handler for an <input> element. | | MDN Reference

    HtmlInputElement::set_onfocus

    fn HtmlInputElement::set_onfocus(self : HtmlInputElement, f : (FocusEvent) -> Unit?) -> Unit

    | Sets the onfocus event handler for an <input> element. | | MDN Reference

    HtmlInputElement::set_oninput

    fn HtmlInputElement::set_oninput(self : HtmlInputElement, f : (InputEvent) -> Unit) -> Unit

    | Sets the oninput event handler for an <input> element. | | MDN Reference

    HtmlInputElement::set_onkeydown

    fn HtmlInputElement::set_onkeydown(self : HtmlInputElement, f : (KeyboardEvent) -> Unit?) -> Unit

    | Sets the onkeydown event handler for an <input> element. | | MDN Reference

    HtmlInputElement::set_onkeypress

    fn HtmlInputElement::set_onkeypress(self : HtmlInputElement, f : (KeyboardEvent) -> Unit?) -> Unit

    | Sets the onkeypress event handler for an <input> element. | | MDN Reference

    HtmlInputElement::set_onkeyup

    fn HtmlInputElement::set_onkeyup(self : HtmlInputElement, f : (KeyboardEvent) -> Unit?) -> Unit

    | Sets the onkeyup event handler for an <input> element. | | MDN Reference

    HtmlInputElement::set_value

    fn HtmlInputElement::set_value(self : HtmlInputElement, value : String) -> Unit

    | Sets the value of the input element. | | MDN Reference

    HtmlInputElement::unset_oninput

    fn HtmlInputElement::unset_oninput(self : HtmlInputElement) -> Unit

    | Removes the oninput event handler from an <input> element.

    HtmlInputElement::value

    fn HtmlInputElement::value(self : HtmlInputElement) -> String

    | Gets the current value of the input element. | | MDN Reference

    HtmlSelectElement

    #external
    pub type HtmlSelectElement

    | An HTML select element. | | MDN Reference

    HtmlSelectElement::set_value

    fn HtmlSelectElement::set_value(self : HtmlSelectElement, value : String) -> Unit

    | Selects the option matching value. | | MDN Reference

    HtmlSelectElement::value

    fn HtmlSelectElement::value(self : HtmlSelectElement) -> String

    | Returns the value of the selected option. | | MDN Reference

    HtmlTextAreaElement

    #external
    pub(all) type HtmlTextAreaElement

    | Provides an interface for the HTML <textarea> element. | | MDN Reference

    HtmlTextAreaElement::set_onblur

    fn HtmlTextAreaElement::set_onblur(self : HtmlTextAreaElement, f : (BlurEvent) -> Unit?) -> Unit

    | Sets the onblur event handler for a <textarea> element. | | MDN Reference

    HtmlTextAreaElement::set_onchange

    fn HtmlTextAreaElement::set_onchange(self : HtmlTextAreaElement, f : (InputEvent) -> Unit?) -> Unit

    | Sets the onchange event handler for a <textarea> element. | | MDN Reference

    HtmlTextAreaElement::set_onfocus

    fn HtmlTextAreaElement::set_onfocus(self : HtmlTextAreaElement, f : (FocusEvent) -> Unit?) -> Unit

    | Sets the onfocus event handler for a <textarea> element. | | MDN Reference

    HtmlTextAreaElement::set_oninput

    fn HtmlTextAreaElement::set_oninput(self : HtmlTextAreaElement, f : (InputEvent) -> Unit?) -> Unit

    | Sets the oninput event handler for a <textarea> element. | | MDN Reference

    HtmlTextAreaElement::set_onkeydown

    fn HtmlTextAreaElement::set_onkeydown(self : HtmlTextAreaElement, f : (KeyboardEvent) -> Unit?) -> Unit

    | Sets the onkeydown event handler for a <textarea> element. | | MDN Reference

    HtmlTextAreaElement::set_onkeypress

    fn HtmlTextAreaElement::set_onkeypress(self : HtmlTextAreaElement, f : (KeyboardEvent) -> Unit?) -> Unit

    | Sets the onkeypress event handler for a <textarea> element. | | MDN Reference

    HtmlTextAreaElement::set_onkeyup

    fn HtmlTextAreaElement::set_onkeyup(self : HtmlTextAreaElement, f : (KeyboardEvent) -> Unit?) -> Unit

    | Sets the onkeyup event handler for a <textarea> element. | | MDN Reference

    HtmlTextAreaElement::set_value

    fn HtmlTextAreaElement::set_value(self : HtmlTextAreaElement, value : String) -> Unit

    | Sets the value of the textarea element. | | MDN Reference

    HtmlTextAreaElement::value

    fn HtmlTextAreaElement::value(self : HtmlTextAreaElement) -> String

    | Gets the current value of the textarea element. | | MDN Reference

    InputEvent

    #external
    pub type InputEvent

    InputEvent::target

    fn InputEvent::target(self : InputEvent) -> Element

    | Returns the object to which a dispatched event is targeted. | | MDN Reference

    JsFnObscure

    #external
    pub type JsFnObscure

    JsFnObscure::from

    fn[T] JsFnObscure::from(t : T) -> JsFnObscure

    Perform detection and conversion

    JsFnObscure::to_obscure

    fn JsFnObscure::to_obscure(self : JsFnObscure) -> JsObscure

    JsObjectObscure

    #external
    pub type JsObjectObscure

    | A type representing an obscure JavaScript object.

    JsObjectObscure::call_method_args

    fn JsObjectObscure::call_method_args(self : JsObjectObscure, method_ : String, args : Array[JsObscure]) -> JsObscure

    Calls a named JavaScript method with MoonBit array arguments.

    JsObjectObscure::delete

    fn JsObjectObscure::delete(self : JsObjectObscure, prop : String) -> Bool

    | Deletes a property from an object.

    JsObjectObscure::entries

    | Returns enumerable [key, value] entries as a MoonBit array.

    JsObjectObscure::get

    fn JsObjectObscure::get(self : JsObjectObscure, prop : String) -> JsObscure

    | Gets a property from a JavaScript object.

    JsObjectObscure::has

    fn JsObjectObscure::has(self : JsObjectObscure, prop : String) -> Bool

    | Checks if a property is in an object.

    JsObjectObscure::keys

    | Returns the object's own enumerable property names as a MoonBit array.

    JsObjectObscure::new

    | Creates a new empty JavaScript object.

    JsObjectObscure::set

    fn JsObjectObscure::set(self : JsObjectObscure, prop : String, value : JsObscure) -> Unit

    | Sets a property on a JavaScript object.

    JsObjectObscure::size

    fn JsObjectObscure::size(self : JsObjectObscure) -> Int

    | Returns the number of enumerable properties in an object.

    JsObjectObscure::to_js_obscure

    fn JsObjectObscure::to_js_obscure(self : JsObjectObscure) -> JsObscure

    | Converts JsObjectObscure to JsObscure.

    JsObjectObscure::values

    | Returns the object's own enumerable property values as a MoonBit array.

    JsObscure

    #external
    pub type JsObscure

    | A type representing an obscure JavaScript value. | Its internal structure is unknown and should be inspected before use.

    JsObscure::from_array

    fn JsObscure::from_array(a : Array[JsObscure]) -> JsObscure

    | Converts an Array[JsObscure] to JsObscure.

    JsObscure::from_bool

    fn JsObscure::from_bool(b : Bool) -> JsObscure

    | Converts a Bool to JsObscure.

    JsObscure::from_float

    fn JsObscure::from_float(n : Float) -> JsObscure

    | Converts a Float to JsObscure.

    JsObscure::from_number

    fn JsObscure::from_number(n : Int) -> JsObscure

    | Converts an Int to JsObscure.

    JsObscure::from_string

    fn JsObscure::from_string(s : String) -> JsObscure

    | Converts a String to JsObscure.

    JsObscure::get

    fn JsObscure::get(self : JsObscure, prop : String) -> JsObscure

    | Gets a property from a JavaScript object.

    JsObscure::is_arguments

    fn JsObscure::is_arguments(self : JsObscure) -> Bool

    | Checks if the value is an arguments object.

    JsObscure::is_array

    fn JsObscure::is_array(self : JsObscure) -> Bool

    | Checks if the value is an array.

    JsObscure::is_boolean

    fn JsObscure::is_boolean(self : JsObscure) -> Bool

    | Checks if the value is a boolean.

    JsObscure::is_date

    fn JsObscure::is_date(self : JsObscure) -> Bool

    | Checks if the value is a Date object.

    JsObscure::is_error

    fn JsObscure::is_error(self : JsObscure) -> Bool

    | Checks if the value is an Error object.

    JsObscure::is_function

    fn JsObscure::is_function(self : JsObscure) -> Bool

    | Checks if the value is a function.

    JsObscure::is_map

    fn JsObscure::is_map(self : JsObscure) -> Bool

    | Checks if the value is a Map object.

    JsObscure::is_nil

    fn JsObscure::is_nil(self : JsObscure) -> Bool

    | Checks if the value is null.

    JsObscure::is_nullish

    fn JsObscure::is_nullish(self : JsObscure) -> Bool

    | Checks if the value is either JavaScript null or undefined.

    JsObscure::is_number

    fn JsObscure::is_number(self : JsObscure) -> Bool

    | Checks if the value is a number.

    JsObscure::is_object

    fn JsObscure::is_object(self : JsObscure) -> Bool

    | Checks if the value is a non-null JavaScript object.

    JsObscure::is_regexp

    fn JsObscure::is_regexp(self : JsObscure) -> Bool

    | Checks if the value is a RegExp object.

    JsObscure::is_set

    fn JsObscure::is_set(self : JsObscure) -> Bool

    | Checks if the value is a Set object.

    JsObscure::is_string

    fn JsObscure::is_string(self : JsObscure) -> Bool

    | Checks if the value is a string.

    JsObscure::is_symbol

    fn JsObscure::is_symbol(self : JsObscure) -> Bool

    | Checks if the value is a symbol.

    JsObscure::is_typed_array

    fn JsObscure::is_typed_array(self : JsObscure) -> Bool

    | Checks if the value is a TypedArray.

    JsObscure::is_undefined

    fn JsObscure::is_undefined(self : JsObscure) -> Bool

    | Checks if the value is undefined.

    JsObscure::is_weakmap

    fn JsObscure::is_weakmap(self : JsObscure) -> Bool

    | Checks if the value is a WeakMap object.

    JsObscure::is_weakset

    fn JsObscure::is_weakset(self : JsObscure) -> Bool

    | Checks if the value is a WeakSet object.

    JsObscure::null

    fn JsObscure::null() -> JsObscure

    | Creates a JavaScript null value.

    JsObscure::set

    fn JsObscure::set(self : JsObscure, prop : String, value : JsObscure) -> Unit

    | Sets a property on a JavaScript object.

    JsObscure::undefined

    fn JsObscure::undefined() -> JsObscure

    | Creates a JavaScript undefined value.

    JsPromise

    #external
    pub(all) type JsPromise

    impl Show for JsPromise

    JsPromise::catch_

    fn JsPromise::catch_(self : JsPromise, f : (JsObscure) -> JsObscure) -> JsPromise

    Attaches a callback for the rejection of the Promise.

    Parameters

    • self: The Promise to attach the error handler to
    • f: A function that handles the rejection reason, taking JsObscure and returning JsObscure

    Returns

    JsPromise - A new Promise for the return value of the callback

    Example

    let promise = JsPromise::reject(v_to_js_obscure("error")) let _handled = promise.catch_(fn(_error) { v_to_js_obscure("handled") })

    JsPromise::new

    fn JsPromise::new(f : ((JsObscure) -> Unit, (JsObscure) -> Unit)) -> JsPromise

    Creates a new JavaScript Promise with the given executor function.

    Parameters

    • f: A function that takes two parameters (resolve, reject) both of type (JsObscure) -> Unit

    Returns

    JsPromise - A new Promise object

    Example

    let _promise = JsPromise::new(fn(resolve, reject) {
    // Async operation logic here
    resolve(v_to_js_obscure("success"))
    })

    JsPromise::reject

    fn JsPromise::reject(val : JsObscure) -> JsPromise

    Creates a Promise that is rejected with the given reason.

    Parameters

    • val: The reason for rejection as JsObscure

    Returns

    JsPromise - A Promise that is rejected with the given value

    Example

    let _rejected_promise = JsPromise::reject(v_to_js_obscure("Error occurred")) let _ = _rejected_promise.catch_(fn(_error) { v_to_js_obscure("handled reject") })

    JsPromise::resolve

    fn JsPromise::resolve(val : JsObscure) -> JsPromise

    Creates a Promise that is resolved with the given value.

    Parameters

    • val: The value to resolve the Promise with as JsObscure

    Returns

    JsPromise - A Promise that is resolved with the given value

    Example

    let resolved_promise = JsPromise::resolve(v_to_js_obscure("success")) inspect(resolved_promise, content="[object Promise]")

    JsPromise::then

    fn JsPromise::then(self : JsPromise, f : (JsObscure) -> JsObscure) -> JsPromise

    Attaches a callback for the resolution of the Promise.

    Parameters

    • self: The Promise to attach the callback to
    • f: A function that handles the resolved value, taking JsObscure and returning JsObscure

    Returns

    JsPromise - A new Promise for the return value of the callback

    Example

    let promise = JsPromise::resolve(v_to_js_obscure("initial"))
    let chained = promise.then(fn(value) { v_to_js_obscure("processed") })

    KeyboardEvent

    #external
    pub type KeyboardEvent

    KeyboardEvent::alt_key

    fn KeyboardEvent::alt_key(self : KeyboardEvent) -> Bool

    KeyboardEvent::char_code

    fn KeyboardEvent::char_code(self : KeyboardEvent) -> UInt

    KeyboardEvent::code

    fn KeyboardEvent::code(self : KeyboardEvent) -> String

    KeyboardEvent::ctrl_key

    fn KeyboardEvent::ctrl_key(self : KeyboardEvent) -> Bool

    KeyboardEvent::key

    fn KeyboardEvent::key(self : KeyboardEvent) -> String

    KeyboardEvent::key_code

    fn KeyboardEvent::key_code(self : KeyboardEvent) -> UInt

    KeyboardEvent::location

    fn KeyboardEvent::location(self : KeyboardEvent) -> UInt

    KeyboardEvent::meta_key

    fn KeyboardEvent::meta_key(self : KeyboardEvent) -> Bool

    KeyboardEvent::new_with_init_dict

    fn KeyboardEvent::new_with_init_dict(type_ : String, event_init_dict : KeyboardEventInit) -> KeyboardEvent

    KeyboardEvent::prevent_default

    fn KeyboardEvent::prevent_default(self : KeyboardEvent) -> Unit

    KeyboardEvent::repeat

    fn KeyboardEvent::repeat(self : KeyboardEvent) -> Bool

    KeyboardEvent::set_repeat

    fn KeyboardEvent::set_repeat(self : KeyboardEvent, repeat : Bool) -> Unit

    KeyboardEvent::shift_key

    fn KeyboardEvent::shift_key(self : KeyboardEvent) -> Bool

    KeyboardEvent::stop_propagation

    fn KeyboardEvent::stop_propagation(self : KeyboardEvent) -> Unit

    KeyboardEvent::type_

    fn KeyboardEvent::type_(self : KeyboardEvent) -> String

    KeyboardEvent::view

    fn KeyboardEvent::view(self : KeyboardEvent) -> Window

    KeyboardEventInit

    #external
    pub type KeyboardEventInit

    need to init function first before creating real event

    KeyboardEventInit::new

    KeyboardEventInit::set_char_code

    fn KeyboardEventInit::set_char_code(self : KeyboardEventInit, char_code : UInt) -> Unit

    KeyboardEventInit::set_code

    fn KeyboardEventInit::set_code(self : KeyboardEventInit, code : String) -> Unit

    KeyboardEventInit::set_key

    fn KeyboardEventInit::set_key(self : KeyboardEventInit, key : String) -> Unit

    KeyboardEventInit::set_key_code

    fn KeyboardEventInit::set_key_code(self : KeyboardEventInit, key_code : UInt) -> Unit

    KeyboardEventInit::set_location

    fn KeyboardEventInit::set_location(self : KeyboardEventInit, location : UInt) -> Unit

    KeyboardEventInit::set_view

    fn KeyboardEventInit::set_view(self : KeyboardEventInit, view : Window) -> Unit

    LocalStorage

    #external
    pub(all) type LocalStorage

    LocalStorage::get_item

    fn LocalStorage::get_item(self : LocalStorage, key : String) -> String?

    Retrieves the value associated with the given key from localStorage.

    Parameters

    • self: The LocalStorage instance
    • key: The key to retrieve the value for

    Returns

    String? - Some(value) if the key exists, None if the key doesn't exist or value is null

    Example

    let storage = window().local_storage()
    storage.set_item("username", "alice")
    let result = storage.get_item("username")
    inspect(result, content="Some(\"alice\")")

    let missing = storage.get_item("nonexistent")
    inspect(missing, content="None")

    LocalStorage::remove_item

    fn LocalStorage::remove_item(self : LocalStorage, key : String) -> Unit

    LocalStorage::set_item

    fn LocalStorage::set_item(self : LocalStorage, key : String, value : String) -> Unit

    Location

    #external
    pub(all) type Location

    https://developer.mozilla.org/en-US/docs/Web/API/Location
    impl Show for Location

    Location::assign

    fn Location::assign(self : Location, url : String) -> Unit

    Navigates to the specified URL, adding the current page to the browser history.

    Parameters

    • self: The Location instance
    • url: The URL to navigate to

    Returns

    Unit - No return value

    Example

    let loc = window().location()
    loc.assign("https://example.com/new-page")
    inspect((), content="()")

    Location::hash

    fn Location::hash(self : Location) -> String

    Gets the fragment identifier portion of the URL (including the leading "#").

    Parameters

    • self: The Location instance

    Returns

    String - The hash fragment starting with "#" or empty string if none

    Example

    let loc = window().location()
    let hash = loc.hash()
    inspect(hash, content="#section1")

    Location::host

    fn Location::host(self : Location) -> String

    Gets the host (hostname and port) of the URL.

    Parameters

    • self: The Location instance

    Returns

    String - The host including port if non-standard (e.g., "example.com:8080")

    Example

    let loc = window().location()
    let host = loc.host()
    inspect(host, content="example.com:8080")

    Location::hostname

    fn Location::hostname(self : Location) -> String

    Gets the hostname of the URL (without port).

    Parameters

    • self: The Location instance

    Returns

    String - The hostname only (e.g., "example.com")

    Example

    let loc = window().location()
    let hostname = loc.hostname()
    inspect(hostname, content="example.com")

    Location::href

    fn Location::href(self : Location) -> String

    Gets the complete URL of the current page.

    Parameters

    • self: The Location instance

    Returns

    String - The complete URL including protocol, host, path, and query string

    Example

    let loc = window().location()
    let url = loc.href()
    inspect(url, content="https://example.com/path?query=value#hash")

    Location::origin

    fn Location::origin(self : Location) -> String

    Gets the origin of the URL (protocol + hostname + port).

    Parameters

    • self: The Location instance

    Returns

    String - The origin (e.g., "https://example.com:8080")

    Example

    let loc = window().location()
    let origin = loc.origin()
    inspect(origin, content="https://example.com:8080")

    Location::pathname

    fn Location::pathname(self : Location) -> String

    Gets the path portion of the URL.

    Parameters

    • self: The Location instance

    Returns

    String - The path starting with "/" (e.g., "/path/to/page")

    Example

    let loc = window().location()
    let path = loc.pathname()
    inspect(path, content="/path/to/page")

    Location::port

    fn Location::port(self : Location) -> String

    Gets the port number of the URL.

    Parameters

    • self: The Location instance

    Returns

    String - The port number as a string, or empty string for default ports

    Example

    let loc = window().location()
    let port = loc.port()
    inspect(port, content="8080")

    Location::protocol

    fn Location::protocol(self : Location) -> String

    Gets the protocol scheme of the URL (including the trailing colon).

    Parameters

    • self: The Location instance

    Returns

    String - The protocol (e.g., "https:", "http:", "file:")

    Example

    let loc = window().location()
    let protocol = loc.protocol()
    inspect(protocol, content="https:")

    Location::reload

    fn Location::reload(self : Location) -> Unit

    Location::replace

    fn Location::replace(self : Location, url : String) -> Unit

    Location::search

    fn Location::search(self : Location) -> String

    Gets the query string portion of the URL (including the leading "?").

    Parameters

    • self: The Location instance

    Returns

    String - The query string starting with "?" or empty string if none

    Example

    let loc = window().location()
    let search = loc.search()
    inspect(search, content="?name=john&age=25")

    Location::set_href

    fn Location::set_href(self : Location, href : String) -> Unit

    Sets the complete URL, causing the browser to navigate to the new location.

    Parameters

    • self: The Location instance
    • href: The new URL to navigate to

    Returns

    Unit - No return value

    Example

    let loc = window().location()
    loc.set_href("https://example.com/new-page")

    Location::to_string

    fn Location::to_string(self : Location) -> String

    MouseEvent

    #external
    pub type MouseEvent

    MouseEvent::client_x

    fn MouseEvent::client_x(self : MouseEvent) -> Float

    | Returns the horizontal coordinate within the viewport at which the event occurred. | | MDN Reference

    MouseEvent::client_y

    fn MouseEvent::client_y(self : MouseEvent) -> Float

    | Returns the vertical coordinate within the viewport at which the event occurred. | | MDN Reference

    MouseEvent::offset_x

    fn MouseEvent::offset_x(self : MouseEvent) -> Float

    | Returns the horizontal offset (in pixels) of the pointer from the left edge of the target element's padding edge. | | MDN Reference

    MouseEvent::offset_y

    fn MouseEvent::offset_y(self : MouseEvent) -> Float

    | Returns the vertical offset (in pixels) of the pointer from the top edge of the target element's padding edge. | | MDN Reference

    MouseEvent::page_x

    fn MouseEvent::page_x(self : MouseEvent) -> Float

    | Returns the horizontal coordinate (in pixels) at which the mouse was clicked, relative to the left edge of the entire document. | | MDN Reference

    MouseEvent::page_y

    fn MouseEvent::page_y(self : MouseEvent) -> Float

    | Returns the vertical coordinate (in pixels) at which the mouse was clicked, relative to the top edge of the entire document. | | MDN Reference

    MouseEvent::prevent_default

    fn MouseEvent::prevent_default(self : MouseEvent) -> Unit

    MouseEvent::stop_propagation

    fn MouseEvent::stop_propagation(self : MouseEvent) -> Unit

    #external
    pub(all) type Navigator

    window.navigator object https://developer.mozilla.org/en-US/docs/Web/API/Navigator

    Node

    #external
    pub(all) type Node

    | An interface from which a number of DOM API object types inherit. | | MDN Reference

    Node::append_child

    fn Node::append_child(self : Node, child : Node) -> Unit

    | Adds a node to the end of the list of children of a specified parent node. | | MDN Reference

    Node::child_nodes

    fn Node::child_nodes(self : Node) -> Array[Node]

    | Returns a snapshot MoonBit array of the node's current child nodes.

    Node::children

    fn Node::children(self : Node) -> Array[Element]

    | Returns a snapshot MoonBit array of the node's current element children.

    Node::clone_node

    fn Node::clone_node(self : Node, deep? : Bool) -> Node

    | Returns a duplicate of the node on which this method was called. | | MDN Reference

    Node::dispatch_event

    fn Node::dispatch_event(self : Node, event : KeyboardEvent) -> Bool

    Node::first_child

    fn Node::first_child(self : Node) -> Node?

    | Returns the node's first child in the tree, or None if the node has no children. | | MDN Reference

    Node::insert_before

    fn Node::insert_before(self : Node, new_child : Node, reference_child : Node?) -> Unit

    | Inserts a node before a reference node as a child of a specified parent node. | | MDN Reference

    Node::owner_document

    fn Node::owner_document(self : Node) -> Document?

    | Returns the node's owner document, or None for a document node.

    Node::parent_element

    fn Node::parent_element(self : Node) -> Element?

    | Returns the node's parent element, or None when it has none.

    Node::reinterpret_as_element

    fn Node::reinterpret_as_element(self : Node) -> Element

    | Reinterprets a Node as an Element. This is a type cast and does not change the underlying object.

    Node::reinterpret_as_event_target

    fn Node::reinterpret_as_event_target(self : Node) -> EventTarget

    | Reinterprets a node as an EventTarget without changing the JavaScript | value.

    Node::remove

    fn Node::remove(self : Node) -> Unit

    | Removes the object from the tree it belongs to. | | MDN Reference

    Node::remove_child

    fn Node::remove_child(self : Node, child : Node) -> Unit

    | Removes a child node from the DOM and returns the removed node. | | MDN Reference

    Node::style

    fn Node::style(self : Node) -> CSSStyleDeclaration

    Node::text_content

    fn Node::text_content(self : Node) -> String?

    | Returns node text content, or None for node kinds such as Document | whose DOM textContent is null. | | MDN Reference

    Node::to_js_object

    fn Node::to_js_object(self : Node) -> JsObjectObscure

    cast Node to JsObjectObscure

    Performance

    #external
    pub(all) type Performance

    impl Show for Performance

    Performance::now

    fn Performance::now(self : Performance) -> Float

    Returns a high-resolution timestamp in milliseconds since the time origin.

    Parameters

    • self: The Performance instance

    Returns

    Float - A timestamp in milliseconds with microsecond precision

    Example

    let perf = window().performance()
    let start_time = perf.now()
    // ... some operation ...
    let end_time = perf.now()
    let duration = end_time - start_time
    inspect(start_time, content="1234.567890")

    PointerEvent

    #external
    pub type PointerEvent

    | A pointer input event, covering mouse, pen, and touch input. | | MDN Reference

    PointerEvent::button

    fn PointerEvent::button(self : PointerEvent) -> Int

    | Returns the button whose state changed, or -1 for a move event. | | MDN Reference

    PointerEvent::buttons

    fn PointerEvent::buttons(self : PointerEvent) -> Int

    | Returns the bitmask of currently pressed buttons. | | MDN Reference

    PointerEvent::client_x

    fn PointerEvent::client_x(self : PointerEvent) -> Float

    | Returns the horizontal pointer position within the viewport. | | MDN Reference

    PointerEvent::client_y

    fn PointerEvent::client_y(self : PointerEvent) -> Float

    | Returns the vertical pointer position within the viewport. | | MDN Reference

    PointerEvent::new_with_init_dict

    fn PointerEvent::new_with_init_dict(type_ : String, init : PointerEventInit) -> PointerEvent

    | Creates a pointer event with the supplied initialization dictionary. | | MDN Reference

    PointerEvent::pointer_id

    fn PointerEvent::pointer_id(self : PointerEvent) -> Int

    | Returns the pointer identifier that remains stable for its active input. | | MDN Reference

    PointerEvent::pressure

    fn PointerEvent::pressure(self : PointerEvent) -> Float

    | Returns the normalized pressure, from 0.0 to 1.0. | | MDN Reference

    PointerEvent::reinterpret_as_event

    fn PointerEvent::reinterpret_as_event(self : PointerEvent) -> Event

    | Reinterprets this pointer event as the generic Event used by | EventTarget APIs. | | MDN Reference

    PointerEventInit

    #external
    pub type PointerEventInit

    | Initialization values for a PointerEvent. | | MDN Reference

    PointerEventInit::new

    | Creates an empty pointer-event initialization dictionary. | | MDN Reference

    PointerEventInit::set_button

    fn PointerEventInit::set_button(self : PointerEventInit, button : Int) -> Unit

    | Sets the changed button value. | | MDN Reference

    PointerEventInit::set_buttons

    fn PointerEventInit::set_buttons(self : PointerEventInit, buttons : Int) -> Unit

    | Sets the bitmask of pressed buttons. | | MDN Reference

    PointerEventInit::set_client_x

    fn PointerEventInit::set_client_x(self : PointerEventInit, client_x : Float) -> Unit

    | Sets the horizontal pointer position in viewport coordinates. | | MDN Reference

    PointerEventInit::set_client_y

    fn PointerEventInit::set_client_y(self : PointerEventInit, client_y : Float) -> Unit

    | Sets the vertical pointer position in viewport coordinates. | | MDN Reference

    PointerEventInit::set_pointer_id

    fn PointerEventInit::set_pointer_id(self : PointerEventInit, pointer_id : Int) -> Unit

    | Sets the stable pointer identifier. | | MDN Reference

    PointerEventInit::set_pressure

    fn PointerEventInit::set_pressure(self : PointerEventInit, pressure : Float) -> Unit

    | Sets normalized pointer pressure. | | MDN Reference

    SubmitEvent

    #external
    pub type SubmitEvent

    | A form submission event. | | MDN Reference

    SubmitEvent::new

    fn SubmitEvent::new(type_ : String) -> SubmitEvent

    | Creates a submission event with default initialization values. | | MDN Reference

    SubmitEvent::new_with_init_dict

    fn SubmitEvent::new_with_init_dict(type_ : String, init : SubmitEventInit) -> SubmitEvent

    | Creates a submission event with the supplied initialization dictionary. | | MDN Reference

    SubmitEvent::reinterpret_as_event

    fn SubmitEvent::reinterpret_as_event(self : SubmitEvent) -> Event

    | Reinterprets this submission event as the generic Event used by | EventTarget APIs. | | MDN Reference

    SubmitEvent::submitter

    fn SubmitEvent::submitter(self : SubmitEvent) -> Element?

    | Returns the submitter element that triggered this event, or None when the | event has no submitter. | | MDN Reference

    SubmitEventInit

    #external
    pub type SubmitEventInit

    | Initialization values for a SubmitEvent. | | MDN Reference

    SubmitEventInit::new

    | Creates an empty submit-event initialization dictionary. | | MDN Reference

    SubmitEventInit::set_submitter

    fn SubmitEventInit::set_submitter(self : SubmitEventInit, submitter : Element) -> Unit

    | Sets the element exposed as the event submitter. | | MDN Reference

    URLSearchParams

    type URLSearchParams

    https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams

    URLSearchParams::append

    fn URLSearchParams::append(self : URLSearchParams, name : String, value : String) -> Unit

    Appends a new value to an existing parameter name, or creates it if it doesn't exist.

    Parameters

    • self: The URLSearchParams instance
    • name: The name of the parameter to append to
    • value: The value to append

    Returns

    Unit - No return value

    Example

    let params = new_url_search_params("name=john") params.append("name", "jane") params.append("age", "25") inspect(params.to_string(), content="name=john&name=jane&age=25")

    URLSearchParams::delete

    fn URLSearchParams::delete(self : URLSearchParams, name : String) -> Unit

    Deletes all parameters with the given name.

    Parameters

    • self: The URLSearchParams instance
    • name: The name of the parameter(s) to delete

    Returns

    Unit - No return value

    Example

    let params = new_url_search_params("name=john&age=25&name=jane") params.delete("name") inspect(params.to_string(), content="age=25")

    URLSearchParams::get

    fn URLSearchParams::get(self : URLSearchParams, name : String) -> String?

    Gets the first value for name, or None when it is absent.

    URLSearchParams::get_all

    fn URLSearchParams::get_all(self : URLSearchParams, name : String) -> Array[String]

    Gets all values for name as a MoonBit array.

    URLSearchParams::has

    fn URLSearchParams::has(self : URLSearchParams, name : String) -> Bool

    Checks if a parameter with the given name exists.

    Parameters

    • self: The URLSearchParams instance
    • name: The name of the parameter to check

    Returns

    Bool - true if the parameter exists, false otherwise

    Example

    let params = new_url_search_params("name=john&age=25") let has_name = params.has("name") inspect(has_name, content="true") let has_email = params.has("email") inspect(has_email, content="false")

    URLSearchParams::set

    fn URLSearchParams::set(self : URLSearchParams, name : String, value : String) -> Unit

    Sets the value associated with a parameter name, replacing any existing values.

    Parameters

    • self: The URLSearchParams instance
    • name: The name of the parameter to set
    • value: The value to set for the parameter

    Returns

    Unit - No return value

    Example

    let params = new_url_search_params("name=john&age=25") params.set("name", "alice") params.set("email", "alice@example.com") inspect(params.to_string(), content="name=alice&age=25&email=alice%40example.com")

    URLSearchParams::to_string

    fn URLSearchParams::to_string(self : URLSearchParams) -> String

    Returns a string representation of the URLSearchParams in query string format.

    Parameters

    • self: The URLSearchParams instance

    Returns

    String - A query string representation (without leading '?')

    Example

    let params = new_url_search_params("name=john&age=25") let query_string = params.to_string() inspect(query_string, content="name=john&age=25")

    WheelEvent

    #external
    pub type WheelEvent

    | A wheel event with normalized scroll deltas. | | MDN Reference

    WheelEvent::delta_mode

    fn WheelEvent::delta_mode(self : WheelEvent) -> Int

    | Returns the unit used by delta_x and delta_y: pixel (0), line | (1), or page (2). | | MDN Reference

    WheelEvent::delta_x

    fn WheelEvent::delta_x(self : WheelEvent) -> Float

    | Returns the horizontal scroll amount. | | MDN Reference

    WheelEvent::delta_y

    fn WheelEvent::delta_y(self : WheelEvent) -> Float

    | Returns the vertical scroll amount. | | MDN Reference

    WheelEvent::new_with_init_dict

    fn WheelEvent::new_with_init_dict(type_ : String, init : WheelEventInit) -> WheelEvent

    | Creates a wheel event with the supplied initialization dictionary. | | MDN Reference

    WheelEvent::reinterpret_as_event

    fn WheelEvent::reinterpret_as_event(self : WheelEvent) -> Event

    | Reinterprets this wheel event as the generic Event used by | EventTarget APIs. | | MDN Reference

    WheelEventInit

    #external
    pub type WheelEventInit

    | Initialization values for a WheelEvent. | | MDN Reference

    WheelEventInit::new

    | Creates an empty wheel-event initialization dictionary. | | MDN Reference

    WheelEventInit::set_delta_mode

    fn WheelEventInit::set_delta_mode(self : WheelEventInit, delta_mode : Int) -> Unit

    | Sets the delta unit: pixel (0), line (1), or page (2). | | MDN Reference

    WheelEventInit::set_delta_x

    fn WheelEventInit::set_delta_x(self : WheelEventInit, delta_x : Float) -> Unit

    | Sets the horizontal scroll amount. | | MDN Reference

    WheelEventInit::set_delta_y

    fn WheelEventInit::set_delta_y(self : WheelEventInit, delta_y : Float) -> Unit

    | Sets the vertical scroll amount. | | MDN Reference

    Window

    #external
    pub(all) type Window

    window

    Window::add_event_listener_with_callback

    fn Window::add_event_listener_with_callback(self : Window, type_ : String, f : JsFnObscure) -> Unit

    Window::cancel_animation_frame

    fn Window::cancel_animation_frame(self : Window, id : Int) -> Unit

    | Cancels an animation frame request previously scheduled through a call to request_animation_frame. | | MDN Reference

    Window::clear_interval

    fn Window::clear_interval(self : Window, id : Int) -> Unit

    | Cancels a timed, repeating action previously established by a call to set_interval. | | MDN Reference

    Window::clear_timeout

    fn Window::clear_timeout(self : Window, id : Int) -> Unit

    | Cancels a timeout previously established by calling set_timeout. | | MDN Reference

    Window::document

    fn Window::document(self : Window) -> Document

    | Returns the document object of a window. | | MDN Reference

    Window::keyboard_event_init

    fn Window::keyboard_event_init(self : Window, type_ : String) -> KeyboardEventInit

    Window::local_storage

    fn Window::local_storage(self : Window) -> LocalStorage

    Window::location

    fn Window::location(self : Window) -> Location

    Gets the Location object from the window, representing the current URL.

    Parameters

    • self: The Window instance

    Returns

    Location - The Location object for the current page

    Example

    let _loc = window().location()

    Window::performance

    fn Window::performance(self : Window) -> Performance

    Gets the Performance object from the window, providing access to performance-related information.

    Parameters

    • self: The Window instance

    Returns

    Performance - The Performance object for measuring performance

    Example

    let perf = window().performance()
    inspect(perf, content="[object Performance]")

    Window::reinterpret_as_event_target

    fn Window::reinterpret_as_event_target(self : Window) -> EventTarget

    | Reinterprets a window as an EventTarget without changing the JavaScript | value.

    Window::remove_event_listener_with_callback

    fn Window::remove_event_listener_with_callback(self : Window, type_ : String, f : JsFnObscure) -> Unit

    Window::request_animation_frame

    fn Window::request_animation_frame(self : Window, f : (Float) -> Unit) -> Int

    | Tells the browser that you wish to perform an animation and requests the browser to call a specified function to update an animation before the next repaint. | | MDN Reference

    Window::set_interval

    fn Window::set_interval(self : Window, f : () -> Unit, ms : UInt) -> Int

    | Repeatedly calls a function with a fixed time delay between each call. | | MDN Reference

    Window::set_onbeforeunload

    fn Window::set_onbeforeunload(self : Window, f : (BeforeUnloadEvent) -> Unit) -> Unit

    Window::set_timeout

    fn Window::set_timeout(self : Window, f : () -> Unit, ms : UInt) -> Int

    | Calls a function after a specified delay. | | MDN Reference

    Window::to_js_object

    fn Window::to_js_object(self : Window) -> JsObjectObscure

    Cast Window to JsObjectObscure

    before_unload_event

    fn before_unload_event() -> BeforeUnloadEvent

    cancel_animation_frame

    fn cancel_animation_frame(id : Int) -> Unit

    | Cancels an animation frame request previously scheduled through a call to request_animation_frame. | Convenience function that uses the global window object. | | MDN Reference

    clear_interval

    fn clear_interval(id : Int) -> Unit

    | Cancels a timed, repeating action previously established by a call to set_interval. | Convenience function that uses the global window object. | | MDN Reference

    clear_timeout

    fn clear_timeout(id : Int) -> Unit

    | Cancels a timeout previously established by calling set_timeout. | Convenience function that uses the global window object. | | MDN Reference

    debugger

    fn debugger() -> Unit

    document_get_element_by_id

    fn document_get_element_by_id(id : String) -> Element?

    | Returns a reference to the element by its ID. | Convenience function that uses the global document object. | | MDN Reference

    document_query_selector

    fn document_query_selector(selector : String) -> Element?

    | Returns the first Element within the document that matches the specified selector, or None if no matches are found. | Convenience function that uses the global document object. | | MDN Reference

    document_query_selector_all

    fn document_query_selector_all(selector : String) -> Array[Element]

    | Returns a static (not live) NodeList representing a list of the document's elements that match the specified group of selectors. | Convenience function that uses the global document object. | | MDN Reference

    error_log

    fn error_log(msg : String) -> Unit

    Outputs an error message to the browser console at the error level.

    Parameters

    • msg: The error message string to log

    Returns

    Unit - No return value

    Example

    error_log("An error occurred!") error_log("Failed to load resource")

    eval_js_code

    fn eval_js_code(code : String) -> JsObscure

    | Evaluates JavaScript code and returns the result.

    inject_style

    fn inject_style(id : String, css : String) -> Unit

    | Injects or updates a style element with the given id and CSS content. | If a style element with the given id already exists, its content will be replaced. | | This is useful for dynamically adding CSS for animations, themes, or other runtime styling needs.

    js_obscure_to_v

    fn[T] js_obscure_to_v(v : JsObscure) -> T

    | Converts JsObscure to any Moonbit value. | This is a low-level operation and should be used with caution.

    log

    fn log(msg : String) -> Unit

    Outputs a message to the browser console at the info level.

    Parameters

    • msg: The message string to log

    Returns

    Unit - No return value

    Example

    log("Hello, world!") log("Debug information: value = 42")

    new_url_search_params

    fn new_url_search_params(s : String) -> URLSearchParams

    Creates a new URLSearchParams object from a query string.

    Parameters

    • s: A query string (with or without leading '?')

    Returns

    URLSearchParams - A new URLSearchParams object

    Example

    let params = new_url_search_params("name=john&age=25") inspect(params, content="name=john&age=25") let params2 = new_url_search_params("?foo=bar&baz=qux") inspect(params2, content="foo=bar&baz=qux")

    remove_style

    fn remove_style(id : String) -> Unit

    | Removes a style element with the given id from the document.

    request_animation_frame

    fn request_animation_frame(f : (Float) -> Unit) -> Int

    | Tells the browser that you wish to perform an animation and requests the browser to call a specified function to update an animation before the next repaint. | Convenience function that uses the global window object. | | MDN Reference

    set_interval

    fn set_interval(f : () -> Unit, ms : UInt) -> Int

    | Repeatedly calls a function with a fixed time delay between each call. | Convenience function that uses the global window object. | | MDN Reference

    set_timeout

    fn set_timeout(f : () -> Unit, ms : UInt) -> Int

    | Calls a function after a specified delay. | Convenience function that uses the global window object. | | MDN Reference

    type_of

    fn type_of(v : JsObscure) -> String

    | Returns the lowercased type string of a JavaScript value. | It uses Object.prototype.toString.call internally. | For example, it returns "string", "object", "function".

    v_to_js_obscure

    fn[T] v_to_js_obscure(v : T) -> JsObscure

    | Converts any Moonbit value to JsObscure. | This is a low-level operation and should be used with caution.

    warn_log

    fn warn_log(msg : String) -> Unit

    Outputs a warning message to the browser console at the warning level.

    Parameters

    • msg: The warning message string to log

    Returns

    Unit - No return value

    Example

    warn_log("This is a warning message") warn_log("Deprecated function used")

    window

    fn window() -> Window