dom-ffi

A minimal FFI layer for DOM operations, designed for use with Respo.mbt

dom
ffi
Download zip
Author
Version
0.2.3
License
Apache-2.0
Last updated
8 months ago
Downloads
4K

#dom-ffi

A minimal FFI layer for DOM operations, designed for use with Respo.mbt

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

#License

Apache License 2.0

BeforeUnloadEvent

#external
pub(all) type BeforeUnloadEvent

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::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> node of the current document. | | MDN Reference

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 of the current document. | | MDN Reference

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

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

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 data being dragged, during a drag and drop operation. | | MDN Reference

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::data_attribute

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

| Gets the value of a custom data attribute (data-*). | | 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_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::js_query_selector

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

| Internal helper for querySelector.

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::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_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::to_js_object

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

cast Element to JsObjectObscure

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.

FocusEvent

#external
pub type FocusEvent

HtmlInputElement

#external
pub(all) type HtmlInputElement

| Provides an interface for the HTML <input> element. | | 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

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

Call method with arguments

JsObjectObscure::delete

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

| Deletes a property from an object.

JsObjectObscure::entries

| Returns an array of a given object's own enumerable string-keyed property [key, value] pairs.

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 an array of a given object's own enumerable property names.

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 an array of a given object's own enumerable property values.

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_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 an 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 live NodeList of child nodes of the given Node. | | MDN Reference

Node::children

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

| Returns a live HTMLCollection containing all of the Element children of the node upon which it was called. | | MDN Reference

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 Document object associated with the node. | | MDN Reference

Node::parent_element

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

| Returns the parent Element of the specified node in the DOM tree. | | MDN Reference

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::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::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")

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 associated with the given parameter name.

Parameters

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

Returns

String - The first value associated with the parameter, or empty string if not found

Example

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

let missing = params.get("email")
inspect(missing, content="")

URLSearchParams::get_all

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

Gets all values associated with the given parameter name.

Parameters

  • self: The URLSearchParams instance
  • name: The name of the parameter to get all values for

Returns

Array[String] - An array of all values associated with the parameter

Example

let params = new_url_search_params("name=john&age=25&name=jane") let names = params.get_all("name") inspect(names, content="[\"john\", \"jane\"]") let ages = params.get_all("age") inspect(ages, content="[\"25\"]")

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")

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::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