module @sciter
The module contains Sciter specific functions.
Constants and functions from this module can be exported and used individually:
import {on,off,once} from "@sciter";
on("click", event => {...});
or as a namespace:
import * as sctr from "@sciter";
sctr.on("click", event => {...});
Constants
VERSION
String, readonly, current engine version in the form "X.X.X.X";
REVISION
String, readonly, SVN build revision;
QUICKJS_VERSION
String, readonly, QuickJS version
Functions
import()
sctr.import(path:string):object
That is a synchronous equivalent of standard JS import(), so it can be used synchronously as
const module = sctr.import('my-module.js');
That above is essentially a dynamic equivalent of static import statement in JS:
import * as module from 'my-module.js';
For more information, check the samples.sciter/runtime demo.
setModuleUrlResolver()
sctr.setModuleUrlResolver(func):string|false
Set url resolver for names in import ... from "name".
The function is expected to have the following signature:
function resolver(name:string, documentDir:string, srcDir:string) {}
and to return a string with fully qualified absolute url of the module to load. Example:
// NPM style module resolver:
sctr.setModuleUrlResolver((name,documentDir)=>{
return `${documentDir}node_modules/${name}/index.js`;
});
loadLibrary()
sctr.loadLibrary("name"): any
Loads Sciter extension native library (dll,so,dylib).
The "name" is the name of DLL without extension.
The dll shall reside in the same folder as app executable. See /sqlite project that can be used to produce sciter-sqlite extension dll.
parseValue()
sctr.parseValue(string): any
Parses string value by "JSON++ rules", here are valid inputs:
true-> true value;null-> null value;1234-> Numeric value 1234;1234n-> BigInt (64bit) value 1234;0xFF-> Numeric value 255 (hex);0d2021-12-01-> date 2021-12-01 (in ISO format);12px-> value of Length class;1rad-> value of Angle class;{name1:val1, name2:val2,...}-> object value;[val1, val2, ...]-> array;Map and array separators are either
;or standard JSONs,:
{
foo: 1;
bar: 2;
}
- CSS name tokens:
{
foo-bar: zap; // parsed as "foo-bar":"zap";
}
devicePixels()
sctr.devicePixels(length: int | string[,axis])
Converts length to device (screen) pixels:
- length can be integer - number of dips (a.k.a. "CSS pixels")
- or a string like "2in" to get number of screen pixels in 2 inches of a ruler placed on screen.
- axis is either "width" or "height", note axis parameter makes sense only for devices that have different resolution on x/y axis.
on()
sctr.on(eventname: string, [selector: string,] handler: function) : eventTarget
jQuery style event subscription, parameters:
- eventname - string, name of event that
- may start with
^for handling events in capturing phase;
- may contain namespace part:
"click.myns";
- may start with
- selector - string, optional, CSS selector of target element;
- handler - function(evt,target), event handling function that:
- is called with
thisset to element the element this handler is attached to; - is called with two parameters
handler(evt,matchedElement)- event and the element matching the selector if it was given;
- is called with
returns:
- an event handler that allows to chain
oncalls;
off()
sctr.off(eventname): eventTarget
Unsubscribe event handlers either by name "click" or by namespace ".myns".
sctr.off(handler: function): eventTarget
Unsubscribe event handlers by function reference.
once()
sctr.once(eventname: string, [selector: string,] handler: function): eventTarget
Same as sctr.on() but calls sctr.off(handler) after handling the event once.
onGlobalEvent()
sctr.onGlobalEvent(eventname: string, handler: function): eventTarget
event subscription to application wide events (a.k.a. "global events"):
parameters:
- eventname, string, arbitrary event name, may contain namespace part:
"click.myns"; - handler, function,
- the handler is called with
thisset to the element; returns
- the handler is called with
- element itself allowing to chain
onGlobalEventcalls.
The handler gets unsubscribed automatically when the document gets unloaded making offGlobalEvent() call optional.
Global events can be sent or posted by static Window.send(event) and Window.post(event) and are delivered to all subscribers in all windows of the application.
offGlobalEvent()
sctr.offGlobalEvent(eventname: string): eventTarget
Unsubscribe event handler by event name (like "click") or by namespace (like ".myns").
sctr.offGlobalEvent(handler: function): Element
Unsubscribe event handler by its reference.
$()
sctr.$("selector"): Element
Returns first matched DOM element in current document.
$$()
sctr.$$("selector"): array(Element)
Returns list (array) of matched DOM elements.
uuid()
sctr.uuid():String
Returns uuid as a string.
encode()
sctr.encode(text:string, [encoding:string="utf-8"]):arrayBuffer
Encodes text to sequence of bytes (ArrayBuffer). Default encoding is "utf-8".
encoding here is IANA encoding identifier
decode()
sctr.decode(bytes:arrayBuffer, [encoding:string="utf-8"]):String
Decodes sequence of bytes in the buffer to string. Default encoding is "utf-8".
compress()
sctr.compress(in:arrayBuffer,[method]):arrayBuffer
returns compressed in buffer.
method is one of "gz","gzip" or "lzf" (default).
decompress()
sctr.decompress(in:arrayBuffer,[method]):arrayBuffer
Returns decompressed in buffer.
method is one of "gz","gzip" or "lzf" (default).
toBase64()
sctr.toBase64(in:arrayBuffer):string
Returns string - base64 encoded in buffer.
fromBase64()
sctr.fromBase64(in:string):arrayBuffer
Restores array buffer from base64 encoded string.
md5()
sctr.md5(in:arrayBuffer):string
Returns md5 digest (a.k.a. hash) of the in data.
crc32()
sctr.crc32(in:arrayBuffer):integer
Returns crc32 hash of the in data.