Module ID: shellfish/low
This module provides the low-level Shellfish API for working directly on the HTML DOM and CSS.
When working with Shui or the declarative-level API, you normally do not have to deal directly with this low-level API.
Examples
shRequire("shellfish/low", low =>
{
...
});
require "shellfish/low" as low;
Object {
...
}
Classes
Methods
-
Returns the annotations of the currently active frame handlers.
- See:
Returns:
Type Description Array.<string> The annotations of the frame handlers. -
low.addFrameHandler (handler, annotation)low.FrameHandle static
-
Adds a repeating frame handler and returns a handle for cancelation.
If the system load and the screen refresh rate permit, 60 frames are rendered per second.
For handlers that should only run once, invoke
cancel()
in the handler function itself.Multiple frame handlers may be active at the same time.
Note: The HTML environment decides when to run the frame handlers. Browser windows or tabs may not invoke frame handlers at all while being invisible or without focus.
Name Type Default Description handler
function The handler function.
annotation
string "<no annotation>" optional An optional annotation for identifying the handler for debugging purposes.
Returns:
Type Description low.FrameHandle The handle with a cancel()
method.Examples
const handle = low.addFrameHandler(() => { console.log("next frame"); });
const handle = low.addFrameHandler(() => { handle.cancel(); // run only once console.log("the frame handler was called"); });
-
Creates a DOM element tree from a string of HTML code.
Name Type Description html
string The HTML code.
Returns:
Type Description HTMLElement The root node of the DOM element tree. Example
low.createElementTree("<div><h1>Title</h1><p>This is some text</p></div>");
-
Returns the current value of a CSS property.
Name Type Description target
HTMLElement The target DOM element.
key
string The CSS property key.
Returns:
Type Description string The current value. -
Sets the value of a CSS property.
Name Type Description target
HTMLElement The target DOM element.
key
string The CSS property key.
value
string The new value.
-
low.escapeHtml (text)string Deprecated : Use html.Object#escapeHtml instead. static
-
Escapes a text string for HTML output.
This function replaces certain characters in the text string by entities (for example, "
<
" becomes "<
") so that the string may safely be output in HTML.Name Type Description text
string The text to escape.
Returns:
Type Description string The escaped text. -
low.escapeMarkup (text)string Deprecated : Use html.Object#escapeMarkup instead. static
-
Escapes a text string for literal output.
Name Type Description text
string The text to escape.
Returns:
Type Description string The escaped text. -
Returns a list of all focusable HTML elements in the document. An element is focusable, if it has the data role
sh-focusable
and is visible and not disabled.Returns:
Type Description Array.<HTMLElement> The focusable elements. -
Moves the keyboard focus to the next focusable element.
-
Moves the keyboard focus to the previous focusable element.
-
Enters fullscreen mode with the given target element.
Name Type Description target
HTMLElement The DOM element to show fullscreen.
-
Leaves fullscreen mode.
-
Returns whether fullscreen mode is currently active.
Returns:
Type Description bool Whether fullscreen mode is active. -
Returns if a frame update is currently ongoing, i.e. the program execution is currently in the context of a frame handler.
- See:
-
Converts pixels to rem units according to the current user settings.
A CSS rem unit is the width of the character
m
in the document's global font, font size, and display scale.Name Type Description px
number The pixel value to convert.
- See:
Returns:
Type Description number The amount in rem units. -
Registers a custom topdown-event handler on the given DOM node.
A top-down event trickles down from parent to children, instead of bubbling up from child to parent.
Name Type Description node
object The DOM node.
name
string The name of the event.
cb
function The callback function.
-
Converts rem units to pixels according to the current user settings.
Name Type Description rem
number The rem units to convert.
- See:
Returns:
Type Description number The amount of pixels. -
low.resolveIcons (text)string Deprecated : Resolving icons is handled by html.Label internally. static
-
Resolves icons in a text string.
Icons are encoded by
[icon:<name>]
where<name>
is the name of the icon to show. See the Icon Gallery in the Shellfish UI-Gallery for the icons available.The icons come from a web font and are rendered as font glyphs.
Name Type Description text
string The text to resolve.
Returns:
Type Description string HTML code containing the icons. Example
const output = low.resolveIcons("This is an [icon:bug] icon.");
-
low.resolveMarkup (text)string Deprecated : Resolving markup is handled by html.Label internally. static
-
Resolves inline markup in a text string. Use the character
\
to escape the succeeding character.Supported markups are:
- *italic*
- **bold**
- _underlined_
Name Type Description text
string The text to resolve.
Returns:
Type Description string HTML code containing the formatting. -
Offers the given blob for saving. This function may only be triggered by a user action. Depending on the browser settings, a file dialog may or may not appear for the user to choose a filename, even if you provided a filename.
Name Type Description blob
Blob The blob to save.
filename
string The filename to save to.
-
low.tag (t)low.Tag static
-
Creates a new HTML tag tree node.
Node trees are built by chaining commands.
Name Type Description t
string The tag name.
Returns:
Type Description low.Tag The new node. Example
const tree = low.tag("div").class("item") .style("background-color", "black") .content( low.tag("ol") .content( low.tag("li") .content("First Item") ) .content( low.tag("li") .content("Second Item") ) );
-
Triggers the given custom topdown-event on a DOM node.
Name Type Description node
object The DOM node.
name
string The name of the event.
Type Definitions
-
A handle for controlling a frame handler.
- See:
Properties:
Name Type Description cancel
function Cancels the frame handler.