bobzhang/p5/dom does not have a README file

    AudioNode

    #external
    pub type AudioNode

    A Web Audio AudioNode (or anything with an input node, like p5.sound objects).

    Canvas

    #external
    pub type Canvas

    An HTMLCanvasElement.

    Context2D

    #external
    pub type Context2D

    A CanvasRenderingContext2D.

    Element

    #external
    pub type Element

    A DOM Element.

    File

    #external
    pub type File

    A picked or dropped file.

    ImageData

    #external
    pub type ImageData

    An ImageData.

    ImageElement

    #external
    pub type ImageElement

    An HTMLImageElement (or any CanvasImageSource).

    Path2D

    #external
    pub type Path2D

    A Path2D.

    PointerEvent

    pub(all) struct PointerEvent {
    kind : String
    x : Double
    y : Double
    win_x : Double
    win_y : Double
    moved_x : Double
    moved_y : Double
    button : Int
    buttons : Int
    pointer_id : Int
    pointer_type : String
    is_primary : Bool
    }

    A pointer/mouse event, with coordinates relative to the canvas in CSS pixels (scaled for canvases displayed at a different size).

    add_class

    fn add_class(e : Element, c : String) -> Unit

    add_option

    fn add_option(e : Element, label : String, value : String) -> Unit

    Appends an <option> to a <select>.

    append_child

    fn append_child(e : Element, child : Element) -> Unit

    Appends child to e.

    apply_mask

    fn apply_mask(dst : Canvas, mask : ImageElement) -> Unit

    Masks dst with the alpha channel of mask (scaled to fit).

    audio_context_destination

    fn audio_context_destination() -> AudioNode

    The audio context media elements are routed through (created on first use).

    blit

    fn blit(dst : Canvas, src : ImageElement, w : Double, h : Double) -> Unit

    Draws an image source into a canvas at (0, 0) with the given size (identity transform), replacing its contents.

    canvas_as_image

    fn canvas_as_image(c : Canvas) -> ImageElement

    The canvas as an image source.

    canvas_element

    fn canvas_element(c : Canvas) -> Element

    The canvas as an element.

    canvas_height

    fn canvas_height(c : Canvas) -> Int

    Device-pixel height of a canvas.

    canvas_id

    fn canvas_id(c : Canvas) -> String

    The id of a canvas element.

    canvas_width

    fn canvas_width(c : Canvas) -> Int

    Device-pixel width of a canvas.

    center_element

    fn center_element(e : Element, align : String) -> Unit

    Centers e in its parent ("both", "horizontal" or "vertical"), following p5's center().

    clear_rect

    fn clear_rect(ctx : Context2D, x : Double, y : Double, w : Double, h : Double) -> Unit

    clip_path

    fn clip_path(ctx : Context2D, path : Path2D) -> Unit

    Intersects the clipping region with path.

    console_error

    fn console_error(s : String) -> Unit

    console.error.

    console_log

    fn console_log(s : String) -> Unit

    console_warn

    fn console_warn(s : String) -> Unit

    copy_region

    fn copy_region(dst : Canvas, src : ImageElement, sx : Double, sy : Double, sw : Double, sh : Double, dx : Double, dy : Double, dw : Double, dh : Double) -> Unit

    Copies a region of src into dst (both in device pixels).

    create_canvas

    fn create_canvas(w : Double, h : Double, density : Double, parent : String, visible : Bool) -> Canvas

    Creates a canvas of w×h CSS pixels with the given pixel density and appends it to the element with id parent (or to <main>, created on demand, when parent is empty). Hidden canvases are not attached.

    create_capture

    fn create_capture(video : Bool, audio : Bool, flipped : Bool, parent : String, meta : (Int, Int) -> Unit, failed : (String) -> Unit) -> Element

    Creates a camera/microphone capture <video> (p5's createCapture).

    create_element

    fn create_element(tag : String, html : String, parent : String) -> Element

    Creates an element with the given tag and inner HTML and appends it to the element with id parent (or document.body).

    create_media

    fn create_media(kind : String, sources : FixedArray[String], parent : String, meta : (Int, Int) -> Unit, ready : () -> Unit) -> Element

    Creates a <video> or <audio> element with <source> children, appended to parent (or the body). meta(w, h) runs on loadedmetadata; ready() runs once on canplaythrough.

    create_output

    fn create_output(c : Canvas, kind : String, display : String) -> Unit

    Creates the containers of a text or grid output (_createOutput). kind is "textOutput" or "gridOutput", display "Fallback" or "Label".

    date_part

    fn date_part(which : Int) -> Int

    The current date/time components: year, month (1-12), day, hour, minute, second.

    describe_element_html

    fn describe_element_html(c : Canvas, kind : String, name : String, inner : String) -> Unit

    Writes one row of the canvas element descriptions (_describeElementHTML); name is already stripped for use in ids.

    describe_html

    fn describe_html(c : Canvas, kind : String, text : String) -> Unit

    Writes a canvas description (_describeHTML). kind is "fallback" or "label".

    detach_node

    fn detach_node(e : Element) -> Unit

    Removes an element from its parent, if it has one.

    device_pixel_ratio

    fn device_pixel_ratio() -> Double

    disable_canvas_gestures

    fn disable_canvas_gestures(c : Canvas) -> Unit

    Disables the context menu, page scrolling by wheel and touch gestures on a canvas (what p5's orbitControl does).

    display_height

    fn display_height() -> Double

    display_width

    fn display_width() -> Double

    document_has_focus

    fn document_has_focus() -> Bool

    download_bytes

    fn download_bytes(bytes : FixedArray[Byte], filename : String, mime : String) -> Unit

    Triggers a download of bytes as a file.

    download_text

    fn download_text(text : String, filename : String, mime : String) -> Unit

    Triggers a download of text as a file.

    download_url

    fn download_url(url : String, filename : String) -> Unit

    Triggers a browser download of url named filename.

    draw_image

    fn draw_image(ctx : Context2D, img : ImageElement, sx : Double, sy : Double, sw : Double, sh : Double, dx : Double, dy : Double, dw : Double, dh : Double) -> Unit

    draw_tinted_image

    fn draw_tinted_image(ctx : Context2D, img : ImageElement, iw : Int, ih : Int, r : Double, g : Double, b : Double, a : Double, sx : Double, sy : Double, sw : Double, sh : Double, dx : Double, dy : Double, dw : Double, dh : Double) -> Unit

    Draws img tinted by an RGBA color (components 0-255), using a scratch canvas (same approach as p5's _getTintedImageCanvas).

    element_as_image

    fn element_as_image(e : Element) -> ImageElement

    The element as an image source.

    element_attr_size

    fn element_attr_size(e : Element) -> FixedArray[Double]

    The width/height attributes of an element.

    element_exists

    fn element_exists(e : Element) -> Bool

    element_height

    fn element_height(e : Element) -> Double

    Height of an element in CSS pixels.

    element_width

    fn element_width(e : Element) -> Double

    Width of an element in CSS pixels.

    exit_pointer_lock

    fn exit_pointer_lock() -> Unit

    Exits pointer lock.

    fetch_bytes

    fn fetch_bytes(url : String, done : (FixedArray[Byte]) -> Unit, failed : (String) -> Unit) -> Unit

    Fetches a URL as bytes.

    fetch_text

    fn fetch_text(url : String, done : (String) -> Unit, failed : (String) -> Unit) -> Unit

    Fetches a URL as text; calls done(text) or failed(message).

    file_info

    fn file_info(f : File) -> FixedArray[String]

    [type, subtype, name, size] of a file.

    fill_path

    fn fill_path(ctx : Context2D, path : Path2D, style : String) -> Unit

    Fills path with a CSS color.

    fill_rect

    fn fill_rect(ctx : Context2D, x : Double, y : Double, w : Double, h : Double, style : String) -> Unit

    fill_text

    fn fill_text(ctx : Context2D, text : String, x : Double, y : Double, style : String) -> Unit

    get_attribute

    fn get_attribute(e : Element, name : String) -> String

    get_checked

    fn get_checked(e : Element) -> Bool

    get_class

    fn get_class(e : Element) -> String

    get_context

    fn get_context(c : Canvas) -> Context2D

    The 2D context of a canvas.

    get_context_p3

    fn get_context_p3(c : Canvas) -> Context2D

    The 2D context of a canvas in the Display P3 color space (falls back to sRGB where the browser lacks it).

    get_context_property

    fn get_context_property(c : Canvas, name : String) -> String

    Reads a property of a canvas's 2D context (or of its style).

    get_html

    fn get_html(e : Element) -> String

    get_image_data

    fn get_image_data(ctx : Context2D, x : Int, y : Int, w : Int, h : Int) -> ImageData

    get_style

    fn get_style(e : Element, prop : String) -> String

    get_value

    fn get_value(e : Element) -> String

    has_class

    fn has_class(e : Element, c : String) -> Bool

    has_query_param

    fn has_query_param(name : String) -> Bool

    Whether the page URL has the query parameter name.

    http_request

    fn http_request(url : String, http_method : String, body : String, content_type : String, done : (Int, String) -> Unit, failed : (String) -> Unit) -> Unit

    A general HTTP request; done(status, body_text) or failed(message).

    image_data_copy_from

    fn image_data_copy_from(d : ImageData, src : FixedArray[Byte]) -> Unit

    Copies a MoonBit byte array into image data.

    image_data_copy_to

    fn image_data_copy_to(d : ImageData, dst : FixedArray[Byte]) -> Unit

    Copies image data into a MoonBit byte array.

    image_data_get

    fn image_data_get(d : ImageData, i : Int) -> Int

    image_data_length

    fn image_data_length(d : ImageData) -> Int

    Number of bytes in the image data.

    image_data_set

    fn image_data_set(d : ImageData, i : Int, v : Int) -> Unit

    image_to_data_url

    fn image_to_data_url(img : ImageElement, w : Int, h : Int) -> String

    An image source as a PNG data URL (drawn through a scratch canvas).

    is_fullscreen

    fn is_fullscreen() -> Bool

    listen_device

    fn listen_device(orient : (Double, Double, Double) -> Unit, motion : (Double, Double, Double) -> Unit) -> Unit

    Listens to deviceorientation (orient(alpha, beta, gamma), degrees) and devicemotion (motion(x, y, z), acceleration in m/s²).

    listen_keys

    fn listen_keys(f : (String, String, String, Int) -> Bool) -> Unit

    Listens to keyboard events on the window: f(kind, key, code, key_code) where kind is "down" or "up".

    listen_pointer

    fn listen_pointer(c : Canvas, logical_w : () -> Double, logical_h : () -> Double, f : (PointerEvent) -> Bool) -> Unit

    Listens to pointer events on the canvas. The handler returns false to call preventDefault().

    listen_wheel

    fn listen_wheel(c : Canvas, f : (Double, Double) -> Bool) -> Unit

    Listens to wheel events on the canvas: f(delta_x, delta_y).

    load_font

    fn load_font(url : String, family : String, done : (String) -> Unit, failed : (String) -> Unit) -> Unit

    Loads a font file with the FontFace API and calls done(family) once it is ready (or failed(message)).

    load_font_data

    fn load_font_data(data : FixedArray[Byte], family : String, done : (String) -> Unit, failed : (String) -> Unit) -> Unit

    Registers font file bytes with the FontFace API and calls done(family) once it is ready (or failed(message)).

    load_image

    fn load_image(url : String, done : (ImageElement, Int, Int) -> Unit, failed : (String) -> Unit) -> Unit

    Loads an image; calls done(img, width, height) or failed(message).

    location_href

    fn location_href() -> String

    location.href.

    location_pathname

    fn location_pathname() -> String

    location.pathname.
    fn location_search() -> String

    location.search.

    make_draggable

    fn make_draggable(handle : Element, target : Element) -> Unit

    Makes handle drag target around (p5's draggable()).

    math_random

    fn math_random() -> Double

    Math.random().

    measure_text

    fn measure_text(ctx : Context2D, text : String) -> FixedArray[Double]

    measureText(text) as [width, actualBoundingBoxLeft,actualBoundingBoxRight, actualBoundingBoxAscent, actualBoundingBoxDescent,fontBoundingBoxAscent, fontBoundingBoxDescent, alphabeticBaseline].

    media_connect

    fn media_connect(e : Element, node : AudioNode?) -> Bool

    Connects to node, or only to the output without one.

    media_connect_js

    fn media_connect_js(e : Element, node : AudioNode, has_node : Bool) -> Bool

    Routes a media element through Web Audio (MediaElement.connect): the first call also connects it to the context's destination. Without a node, it connects to the destination only. Returns false when there is no audio context to use.

    media_disconnect

    fn media_disconnect(e : Element) -> Bool

    Disconnects a media element's Web Audio routing; false if it was never connected.

    media_get_number

    fn media_get_number(e : Element, prop : String) -> Double

    media_on_ended

    fn media_on_ended(e : Element, f : () -> Unit) -> Unit

    Sets the ended handler.

    media_on_time_update

    fn media_on_time_update(e : Element, f : (Double) -> Unit) -> Unit

    Calls f(currentTime) on every timeupdate.

    media_pause

    fn media_pause(e : Element) -> Unit

    media_play

    fn media_play(e : Element) -> Unit

    play(), restarting from 0 at the end and loading first if needed.

    media_set_autoplay

    fn media_set_autoplay(e : Element, on : Bool) -> Unit

    media_set_controls

    fn media_set_controls(e : Element, on : Bool) -> Unit

    media_set_loop

    fn media_set_loop(e : Element, on : Bool) -> Unit

    media_set_number

    fn media_set_number(e : Element, prop : String, v : Double) -> Unit

    media_src

    fn media_src(e : Element) -> String

    The source URL of a media element (p5's MediaElement.src getter).

    media_stop

    fn media_stop(e : Element) -> Unit

    media_to_canvas

    fn media_to_canvas(e : Element, c : Canvas, flipped : Bool) -> Unit

    Draws the current frame of a video into c (resizing it to the element's size), mirrored when flipped, like p5's _ensureCanvas.

    now

    fn now() -> Double

    performance.now() in milliseconds.

    number_to_fixed

    fn number_to_fixed(n : Double, digits : Int) -> String

    JavaScript n.toFixed(digits).

    number_to_string

    fn number_to_string(n : Double) -> String

    JavaScript String(n).

    off_event

    fn off_event(e : Element, event : String) -> Unit

    Removes the handler of event.

    on_drop

    fn on_drop(e : Element, f : (File) -> Unit, on_drop : () -> Unit) -> Unit

    Makes e accept dropped files: on_drop first, then f for each file.

    on_event

    fn on_event(e : Element, event : String, f : () -> Unit) -> Unit

    Sets the handler of event (replacing a previous one, like p5's _attachListener); f receives nothing.

    on_files_chosen

    fn on_files_chosen(input : Element, f : (File) -> Unit) -> Unit

    Calls f for each file chosen in a file input.

    on_focus_change

    fn on_focus_change(f : (Bool) -> Unit) -> Unit

    on_ready

    fn on_ready(f : () -> Unit) -> Unit

    Calls f once the document has loaded.

    on_wheel

    fn on_wheel(e : Element, f : (Double) -> Unit) -> Unit

    Sets a wheel handler receiving deltaY.

    on_window_resize

    fn on_window_resize(f : () -> Unit) -> Unit

    path_add_path

    fn path_add_path(target : Path2D, src : Path2D, a : Double, b : Double, c : Double, d : Double, e : Double, f : Double) -> Unit

    target.addPath(src, new DOMMatrix([a, b, c, d, e, f])).

    path_bezier_curve_to

    fn path_bezier_curve_to(p : Path2D, c1x : Double, c1y : Double, c2x : Double, c2y : Double, x : Double, y : Double) -> Unit

    path_close

    fn path_close(p : Path2D) -> Unit

    path_ellipse

    fn path_ellipse(p : Path2D, cx : Double, cy : Double, rx : Double, ry : Double, rotation : Double, start : Double, end : Double) -> Unit

    path_line_to

    fn path_line_to(p : Path2D, x : Double, y : Double) -> Unit

    path_move_to

    fn path_move_to(p : Path2D, x : Double, y : Double) -> Unit

    path_new

    fn path_new() -> Path2D

    path_quadratic_curve_to

    fn path_quadratic_curve_to(p : Path2D, cx : Double, cy : Double, x : Double, y : Double) -> Unit

    path_rect

    fn path_rect(p : Path2D, x : Double, y : Double, w : Double, h : Double) -> Unit

    path_round_rect

    fn path_round_rect(p : Path2D, x : Double, y : Double, w : Double, h : Double, tl : Double, tr : Double, br : Double, bl : Double) -> Unit

    post_text

    fn post_text(url : String, body : String) -> Unit

    POSTs body to url and ignores the answer.

    put_image_data

    fn put_image_data(ctx : Context2D, data : ImageData, x : Int, y : Int) -> Unit

    query_param

    fn query_param(name : String) -> String

    The value of the query parameter name (empty when missing).

    query_selector

    fn query_selector(selector : String) -> Element

    document.querySelector(selector); returns false from found when no element matches.

    query_selector_all

    fn query_selector_all(selector : String, container : String) -> FixedArray[Element]

    container.querySelectorAll(selector) (container empty: document).

    radio_option

    fn radio_option(group : Element, name : String, value : String, label : String) -> Element

    Adds (or updates) an option of a radio group (p5's createRadio option()), returning the input.

    radio_options

    fn radio_options(group : Element) -> FixedArray[Element]

    The radio inputs of a group.

    read_file

    fn read_file(f : File, done : (String, Bool) -> Unit) -> Unit

    Reads a file like p5's File._load: text and JSON as text, video and audio as blob URLs, anything else as a data URL. done(data, is_blob).

    remove_attribute

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

    remove_canvas

    fn remove_canvas(c : Canvas) -> Unit

    Removes a canvas from the document.

    remove_class

    fn remove_class(e : Element, c : String) -> Unit

    remove_element

    fn remove_element(e : Element) -> Unit

    remove_radio_option

    fn remove_radio_option(opt : Element) -> Unit

    Removes the label wrapping a radio input (or the input itself).

    replace_canvas

    fn replace_canvas(old : Canvas, w : Double, h : Double, density : Double) -> Canvas

    Creates a new canvas in place of old (which is hidden and kept for text measurement), like p5 replacing the canvas for a WEBGL context.

    request_animation_frame

    fn request_animation_frame(f : (Double) -> Unit) -> Unit

    Schedules f(timestamp) before the next repaint.

    request_pointer_lock

    fn request_pointer_lock(c : Canvas) -> Bool

    Requests pointer lock on the canvas; returns false when unsupported.

    resize_canvas

    fn resize_canvas(c : Canvas, w : Double, h : Double, density : Double) -> Unit

    Resizes a canvas (contents are cleared).

    restore

    fn restore(ctx : Context2D) -> Unit

    revoke_url

    fn revoke_url(url : String) -> Unit

    Revokes a blob URL.

    save

    fn save(ctx : Context2D) -> Unit

    screen_orientation_type

    fn screen_orientation_type() -> String

    screen.orientation.type (empty when unavailable).

    set_attribute

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

    set_canvas_id

    fn set_canvas_id(c : Canvas, id : String) -> Unit

    Sets the id attribute of a canvas.

    set_checked

    fn set_checked(e : Element, v : Bool) -> Unit

    set_composite

    fn set_composite(ctx : Context2D, op : String) -> Unit

    Sets globalCompositeOperation.

    set_context_property

    fn set_context_property(c : Canvas, name : String, value : String) -> Unit

    Sets a property of a canvas's 2D context, e.g. letterSpacing.

    set_cursor

    fn set_cursor(c : Canvas, cursor : String) -> Unit

    Sets the CSS cursor of the canvas.

    set_description_lang

    fn set_description_lang(c : Canvas, lang : String) -> Unit

    Sets (or, with "", removes) the lang attribute of the canvas and of its descriptions.

    set_element_size

    fn set_element_size(e : Element, w : Double, h : Double) -> Unit

    Sets the width/height of an element (attributes and CSS).

    set_filter

    fn set_filter(ctx : Context2D, f : String) -> Unit

    Sets the canvas filter (CSS filter syntax, "none" to clear).

    set_fullscreen

    fn set_fullscreen(c : Canvas, on : Bool) -> Unit

    Requests or exits fullscreen for the canvas.

    set_global_alpha

    fn set_global_alpha(ctx : Context2D, a : Double) -> Unit

    Sets globalAlpha.

    set_html

    fn set_html(e : Element, html : String) -> Unit

    set_image_smoothing

    fn set_image_smoothing(ctx : Context2D, on : Bool) -> Unit

    Sets imageSmoothingEnabled.

    set_line_dash

    fn set_line_dash(ctx : Context2D, segments : FixedArray[Double]) -> Unit

    Sets a dash pattern (an empty array for solid lines).

    set_media_src

    fn set_media_src(e : Element, src : String) -> Unit

    Replaces the sources of a media element.

    set_output_part

    fn set_output_part(c : Canvas, id : String, part : String, html : String) -> Unit

    Sets the HTML of one part of an output (summary, list, map or shapeDetails) when it changed. id is the output's id without the canvas id prefix, e.g. "textOutput" or "gridOutputLabel".

    set_parent

    fn set_parent(e : Element, parent : String) -> Unit

    Moves e to be the last child of the element with id parent.

    set_position

    fn set_position(e : Element, x : Double, y : Double) -> Unit

    Positions e absolutely at (x, y) (page coordinates).

    set_shadow

    fn set_shadow(ctx : Context2D, blur : Double, dx : Double, dy : Double, color : String) -> Unit

    Applies a shadow (blur = 0 and transparent color to disable).

    set_style

    fn set_style(e : Element, prop : String, value : String) -> Unit

    set_text_style

    fn set_text_style(ctx : Context2D, font : String, align : String, baseline : String, direction : String) -> Unit

    Sets the CSS font, alignment and baseline used for text.

    set_timeout

    fn set_timeout(f : () -> Unit, ms : Double) -> Unit

    Calls f after ms milliseconds.

    set_title

    fn set_title(s : String) -> Unit

    Sets document.title.

    set_transform

    fn set_transform(ctx : Context2D, a : Double, b : Double, c : Double, d : Double, e : Double, f : Double) -> Unit

    set_value

    fn set_value(e : Element, v : String) -> Unit

    storage_clear

    fn storage_clear() -> Unit

    Clears localStorage.

    storage_get

    fn storage_get(key : String) -> String

    Reads a value from localStorage (empty string when missing).

    storage_has

    fn storage_has(key : String) -> Bool

    Whether a localStorage key exists.

    storage_keys

    fn storage_keys() -> FixedArray[String]

    The keys stored in localStorage.

    storage_remove

    fn storage_remove(key : String) -> Unit

    Removes a key from localStorage.

    storage_set

    fn storage_set(key : String, value : String) -> Unit

    Writes a value to localStorage.

    stroke_path

    fn stroke_path(ctx : Context2D, path : Path2D, style : String, width : Double, cap : String, join : String) -> Unit

    Strokes path with a CSS color and line style.

    stroke_text

    fn stroke_text(ctx : Context2D, text : String, x : Double, y : Double, style : String, width : Double, join : String) -> Unit

    to_data_url

    fn to_data_url(c : Canvas, mime : String) -> String

    Encodes the canvas as a data URL (e.g. image/png).

    toggle_class

    fn toggle_class(e : Element, c : String) -> Unit

    upload_canvas_png

    fn upload_canvas_png(c : Canvas, url : String, index : Int, done : () -> Unit, failed : (String) -> Unit) -> Unit

    Encodes the canvas as PNG and POSTs it to url?frame=<index>; calls done() once the server has answered, or failed(message).

    window_height

    fn window_height() -> Double

    window_width

    fn window_width() -> Double