package quill

  1. Overview
  2. Docs

Module Brr_ext.ElSource

include module type of struct include Brr.El end
Sourcetype document = Brr.El.document

See Brr.Document.t this is a forward declaration.

Sourcetype window = Brr.El.window

See Brr.Window.t this is a forward declaration.

Sourcetype tag_name = Jstr.t

The type for element tag names.

The type for elements. Technically this is a DOM Node object. But we focus on DOM manipulation via elements, not the various kind of nodes that may exist.

Sourcetype el = t

See t.

Sourceval v : ?d:document -> ?at:Brr.At.t list -> tag_name -> t list -> t

v ?d ?at name cs is an element name with attribute at (defaults to []) and children cs. If at specifies an attribute more than once, the last one takes over with the exception of At.class' and At.style whose occurences accumulate to define the final value. d is the document on which the element is defined it defaults Brr.G.document.

Sourceval txt : ?d:document -> Jstr.t -> t

txt s is the text s. d is the document on which the element is defined it defaults Brr.G.document. WARNING This is not strictly speaking an element most function of this module will error with this value.

Sourceval txt' : ?d:document -> string -> t

txt' s is txt (Jstr.v s).

Sourceval sp : ?d:document -> unit -> t

sp () is El.txt Jstr.sp

Sourceval nbsp : ?d:document -> unit -> t

nbsp () is El.txt' "\u{00A0}".

Sourceval is_txt : t -> bool

is_txt e is true iff e is a text node. Note that in this cases many of the function below fail.

Sourceval is_el : t -> bool

is_el e is true iff e is an element node.

Sourceval tag_name : t -> tag_name

name e is the tag name of element e lowercased. For is_txt nodes this returns "#text".

Sourceval has_tag_name : tag_name -> t -> bool

has_tag_name n e is Jstr.equal n (name e).

Sourceval txt_text : t -> Jstr.t

txt_text e is the text of e if e is a text node and the empty string otherwise.

Sourceval document : t -> document

document e is the document of e.

Sourceval as_target : t -> Brr.Ev.target

as_target d is the document as an event target.

Element lookups

See also document element lookups.

Sourceval find_by_class : ?root:t -> Jstr.t -> t list

els_by_class ~root c are the elements with class c that are descendents of root (defaults to Document.root).

Sourceval find_by_tag_name : ?root:t -> Jstr.t -> t list

find_by_tag_name ~root n are the elements with tag name t that are descendents of root (defaults to Document.root).

Sourceval find_first_by_selector : ?root:t -> Jstr.t -> t option

find_first_by_selector ~root sel is the first element selected by the CSS selector sel that is descendent of root (defaults to Document.root).

Sourceval fold_find_by_selector : ?root:t -> (t -> 'a -> 'a) -> Jstr.t -> 'a -> 'a

fold_find_by_selector ~root f sel acc folds f over the elements selected by the CSS selector sel that are descendent of root (defaults to Document.root).

Parent, children and siblings

Sourceval parent : t -> t option

parent e is the parent element of e (if any).

Sourceval children : ?only_els:bool -> t -> t list

children e are e's children. Warning, unless only_els is true (defaults to false) not all returned elements will satisfy is_el here.

Sourceval set_children : t -> t list -> unit

set_children e l sets the children of e to l.

Sourceval prepend_children : t -> t list -> unit

prepend e l prepends l to e's children.

Sourceval append_children : t -> t list -> unit

append_children e l appends l to e's children.

Sourceval previous_sibling : t -> t option

previous_sibling e is e's previous sibling element (if any).

Sourceval next_sibling : t -> t option

next_sibling e is e's next sibling element (if any).

Sourceval insert_siblings : [ `Before | `After | `Replace ] -> t -> t list -> unit

insert_siblings loc e l inserts l before, after or instead of element e according to loc.

Sourceval remove : t -> unit

remove e removes e from the document.

Attributes and properties

Sourceval at : Brr.At.name -> t -> Jstr.t option

at a e is the attribute a of e (if any).

Sourceval set_at : Brr.At.name -> Jstr.t option -> t -> unit

set_at a v e sets the attribute a of e to v. If v is None the attribute is removed. If a is empty, this has not effect.

Some attributes are reflected as JavaScript properties in elements see here for details. The following gives a quick way of accessing these properties for elements whose interface which, unlike Brr_canvas.Canvas and Brr_io.Media.El, are not necessarily bound by Brr for the time being (or will never be).

Sourcemodule Prop = Brr.El.Prop

Element properties.

Sourceval prop : 'a Prop.t -> t -> 'a

prop p e is the property p of e if defined and false, 0, 0. or Jstr.empty as applicable if undefined.

Sourceval set_prop : 'a Prop.t -> 'a -> t -> unit

set_prop p v o sets property p of e to v.

Classes

Sourceval class' : Jstr.t -> t -> bool

class' c e is the membership of e to class c.

Sourceval set_class : Jstr.t -> bool -> t -> unit

set_class c b e sets the membership of e to class c to b.

Style

Sourcemodule Style = Brr.El.Style

Style property names.

Sourceval computed_style : ?w:window -> Style.prop -> t -> Jstr.t

computed_style ?w p e is the computed style property p of e in window w (defaults to G.window).

Sourceval inline_style : Style.prop -> t -> Jstr.t

inline_style p e is the inline style property p of e.

Sourceval set_inline_style : ?important:bool -> Style.prop -> Jstr.t -> t -> unit

set_inline_style ~important p v e sets the inline style property p of e to v with priority important (defaults to false).

Sourceval remove_inline_style : Style.prop -> t -> unit

remove_inline_style p e removes the inline style property p of e.

Layout

The inner bound of an element includes its content and padding but not its border. We use the client* properties to get it. These only have integral CSS pixel precision.

Sourceval inner_x : t -> float

inner_x e is the horizontal coordinate in the viewport of e's inner bound. Add Window.scroll_x to get the position relative to the document.

Sourceval inner_y : t -> float

inner_y e is the vertical coordinate in the viewport of e's inner bound. Add Window.scroll_y to get the position relative to the document.

Sourceval inner_w : t -> float

inner_w e is e's inner bound width.

Sourceval inner_h : t -> float

inner_h e is e's inner bound height.

The bound of an element includes its content, padding and border. We use getBoundingClientRect to get it. These have CSS subpixel precision.

Sourceval bound_x : t -> float

bound_x e is the horizontal coordinate in the viewport of e's bound. Add Window.scroll_x to get the position relative to the document.

Sourceval bound_y : t -> float

bound_y e is the vertical coordinate in the viewport of e's bound. Add Window.scroll_y to get the position relative to the document.

Sourceval bound_w : t -> float

bound_w e is e's bound width.

Sourceval bound_h : t -> float

bound_h e is e's bound height.

Offset

Sourceval offset_h : t -> int

offset_w e is the height of e in CSS pixels, excluding borders, padding, scrollbars and pseudo-elements, and ignoring transforms.

See the MDN doc and the specification for a precise description.

Sourceval offset_w : t -> int

offset_w e is the width of e in CSS pixels, excluding borders, padding, scrollbars and pseudo-elements, and ignoring transforms.

See the MDN doc and the specification for a precise description.

Sourceval offset_top : t -> int

offset_top e is the number of CSS pixels that the upper left corner of the current element is offset to the left within the parent node. See the MDN doc and the specification for a precise description.

Sourceval offset_left : t -> int

offset_left e is the number of CSS pixels that the upper left corner of the current element is offset to the left within the parent node. See the MDN doc and the specification for a precise description.

Sourceval offset_parent : t -> t option

offset_parent e is the element (if it exists) which is the closest (nearest in the containment hierarchy) positioned ancestor element.

Scrolling

Sourceval scroll_x : t -> float

scroll_x e is the number of pixels scrolled horizontally.

Sourceval scroll_y : t -> float

scroll_y e is the number of pixels scrolled vertically.

Sourceval scroll_w : t -> float

scroll_w e is the minimum width the element would require to display without a vertical scrollbar.

Sourceval scroll_h : t -> float

scroll_h e is the minimum height the element would require to display without a vertical scrollbar.

Sourceval scroll_into_view : ?align_v:[ `Center | `End | `Nearest | `Start ] -> ?behavior:[< `Auto | `Instant | `Smooth ] -> t -> unit

scroll_into_view ~align_v ~behavior e scrolls e into view.

align_v controls the block option:

  • with `Start, (default) the top of the element is align with to to the top of the scrollable area.
  • with `Center, the element vertically at the center of the scrollable container, positioning it in the middle of the visible area.
  • with `End, the bottom of the element is aligned with the bottom of the scrollable area.
  • with `Nearest, the element is to the nearest edge in the vertical direction. If the element is closer to the top edge of the scrollable container, it will align to the top; if it's closer to the bottom edge, it will align to the bottom. This minimizes the scrolling distance.

behavior controls the behavior option:

  • with `Auto (default) scroll behavior is determined by the computed value of scroll-behavior.
  • with `Smooth scrolling should animate smoothly.
  • with `Instant scrolling should happen instantly in a single jump.

Focus

Sourceval has_focus : t -> bool

has_focus e is true if e has focus in the document it belongs to.

Sourceval set_has_focus : bool -> t -> unit

set_has_focus b e sets the focus of e to b in the document it belongs do.

Pointer locking

Sourceval is_locking_pointer : t -> bool

is_locking_pointer e is true if e is the element which locked the pointer.

Sourceval request_pointer_lock : t -> unit Fut.or_error

request_pointer_lock e requests the pointer to be locked to e in the document it belongs to. This listens on the document for the next Ev.pointerlockchange and Ev.pointerlockerror to resolve the future appropriately.

Fullscreen

Sourcemodule Navigation_ui = Brr.El.Navigation_ui

Fullscreen navigation enum.

Sourcetype fullscreen_opts = Brr.El.fullscreen_opts

The type for FullscreenOptions objects.

Sourceval fullscreen_opts : ?navigation_ui:Navigation_ui.t -> unit -> fullscreen_opts

fullscreen_opts () are options for fullscreen with given parameters.

Sourceval request_fullscreen : ?opts:fullscreen_opts -> t -> unit Fut.or_error

request_fullscreen e requests to make the element to be displayed in fullscreen mode.

Click simulation

Sourceval click : t -> unit

click e simulates a click on e.

Sourceval select_text : t -> unit

select_text e selects the textual contents of e. If the DOM element e has no select method this does nothing.

Element interfaces

Some interfaces are in other modules. See for example Brr_io.Media.El for the media element interface, Brr_canvas.Canvas for the canvas element interface and Brr_io.Form for the form element interface.

Element names and constructors

See the MDN HTML element reference.

Convention. Whenever an element name conflicts with an OCaml keyword we prime it, see for example object'.

Sourcemodule Name = Brr.El.Name

Element names

Sourcetype cons = ?d:document -> ?at:Brr.At.t list -> t list -> t

The type for element constructors. This is simply v with a pre-applied element name.

Sourcetype void_cons = ?d:document -> ?at:Brr.At.t list -> unit -> t

The type for void element constructors. This is simply v with a pre-applied element name and without children.

Sourceval a : cons
Sourceval abbr : cons
Sourceval address : cons
Sourceval article : cons
Sourceval aside : cons
Sourceval audio : cons
Sourceval b : cons
Sourceval bdi : cons
Sourceval bdo : cons
Sourceval blockquote : cons
Sourceval body : cons
Sourceval button : cons
Sourceval canvas : cons
Sourceval caption : cons
Sourceval cite : cons
Sourceval code : cons
Sourceval colgroup : cons
Sourceval command : cons
Sourceval datalist : cons
Sourceval dd : cons
Sourceval del : cons
Sourceval details : cons
Sourceval dfn : cons
Sourceval div : cons
Sourceval dl : cons
Sourceval dt : cons
Sourceval em : cons
Sourceval fieldset : cons
Sourceval figcaption : cons
Sourceval figure : cons
Sourceval form : cons
Sourceval h1 : cons
Sourceval h2 : cons
Sourceval h3 : cons
Sourceval h4 : cons
Sourceval h5 : cons
Sourceval h6 : cons
Sourceval head : cons
Sourceval header : cons
Sourceval hgroup : cons
Sourceval html : cons
Sourceval i : cons
Sourceval iframe : cons
Sourceval ins : cons
Sourceval kbd : cons
Sourceval keygen : cons
Sourceval label : cons
Sourceval legend : cons
Sourceval li : cons
Sourceval map : cons
Sourceval mark : cons
Sourceval menu : cons
Sourceval meter : cons
Sourceval nav : cons
Sourceval noscript : cons
Sourceval object' : cons
Sourceval ol : cons
Sourceval optgroup : cons
Sourceval option : cons
Sourceval output : cons
Sourceval p : cons
Sourceval pre : cons
Sourceval progress : cons
Sourceval q : cons
Sourceval rp : cons
Sourceval rt : cons
Sourceval ruby : cons
Sourceval s : cons
Sourceval samp : cons
Sourceval script : cons
Sourceval section : cons
Sourceval select : cons
Sourceval small : cons
Sourceval span : cons
Sourceval strong : cons
Sourceval style : cons
Sourceval sub : cons
Sourceval summary : cons
Sourceval sup : cons
Sourceval table : cons
Sourceval tbody : cons
Sourceval td : cons
Sourceval textarea : cons
Sourceval tfoot : cons
Sourceval th : cons
Sourceval thead : cons
Sourceval time : cons
Sourceval title : cons
Sourceval tr : cons
Sourceval u : cons
Sourceval ul : cons
Sourceval var : cons
Sourceval video : cons
Sourceval inner_text : Brr.El.t -> Jstr.t

inner_text el gets the innerText property of the element el, representing the rendered text content of the node and its descendants.

Sourceval text_content : Brr.El.t -> Jstr.t

text_content el gets the textContent property of the element el, representing the text content of the node and its descendants.