Packages
plinth
0.4.6
0.10.2
0.10.1
0.10.0
0.9.3
0.9.2
0.9.1
0.9.0
0.8.2
0.8.1
0.8.0
0.7.2
0.7.1
0.7.0
0.6.1
0.6.0
0.5.9
0.5.8
0.5.7
0.5.6
0.5.5
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
0.4.15
0.4.14
0.4.13
0.4.12
0.4.11
0.4.10
0.4.9
0.4.8
0.4.7
0.4.6
0.4.5
0.4.4
0.4.3
0.4.2
0.4.1
0.4.0
0.3.0
0.2.0
0.1.13
0.1.12
0.1.11
0.1.9
0.1.8
0.1.7
0.1.6
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
Bindings to Node.js and browser platform APIs
Current section
Files
Jump to
Current section
Files
src/window_ffi.mjs
import { Ok, Error } from "./gleam.mjs";
export function self() {
return globalThis;
}
export function alert(message) {
window.alert(message);
}
export function addEventListener(type, listener) {
return window.addEventListener(type, listener);
}
export async function requestWakeLock() {
try {
return new Ok(await window.navigator.wakeLock.request("screen"));
} catch (error) {
return new Error(error.toString());
}
}
export function location() {
return window.location.href;
}
export function locationOf(w) {
try {
return new Ok(w.location.href);
} catch (error) {
return new Error(error.toString());
}
}
export function setLocation(w, url) {
w.location.href = url;
}
export function reload() {
return window.location.reload();
}
export function reloadOf(w) {
return w.location.reload();
}
export function focus(w) {
return w.focus();
}
export function getHash() {
const hash = window.location.hash;
if (hash == "") {
return new Error();
}
return new Ok(decodeURIComponent(hash.slice(1)));
}
export function getSearch() {
const search = window.location.search;
if (search == "") {
return new Error();
}
return new Ok(decodeURIComponent(search.slice(1)));
}
export function innerHeight(w) {
return w.innerHeight;
}
export function innerWidth(w) {
return w.innerWidth;
}
export function outerHeight(w) {
return w.outerHeight;
}
export function outerWidth(w) {
return w.outerWidth;
}
export function open(url, target, features) {
try {
return new Ok(window.open(url, target, features));
} catch (error) {
return new Error(error.toString());
}
}
export function close(w) {
w.close();
}
export function closed(w) {
return w.closed;
}
export function queueMicrotask(callback) {
return window.queueMicrotask(callback);
}
export function requestAnimationFrame(callback) {
return window.requestAnimationFrame(callback);
}
export function cancelAnimationFrame(callback) {
return window.cancelAnimationFrame(callback);
}
export function eval_(string) {
try {
return new Ok(eval(string));
} catch (error) {
return new Error(error.toString());
}
}
export async function import_(string) {
try {
return new Ok(await import(string));
} catch (error) {
return new Error(error.toString());
}
}