• Stars
    star
    320
  • Rank 131,126 (Top 3 %)
  • Language
    C
  • License
    MIT License
  • Created about 5 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Lightweight GPU accelerated HTML GUI for native JavaScript



azula, a lightweight GPU accelerated HTML GUI for native JavaScript applications

NPM Version

โ€Œโ€Œ

azula is a lightweight alternative to Electron. It is based on Ultralight, which is an embedding friendly Fork of WebKit, with less memory usage and low disk space requirements.

azula can optionally run in OSR mode, which makes it easy to embed azula in existing Projects like Game/VR Engines.

Characteristics

Azula Electron
CPU 1.2% 4.2%
RAM 37Mb 64Mb
DISK 31Mb 118Mb

Platforms

azula comes with pre-built N-API binaries for the following platforms:

OS Status
Windows โ€Œโ€Œ โ€Œโ€Œ โ€Œโ€Œ โ€Œโ€Œ โ€Œโ€Œ โ€Œโ€Œ โ€Œโ€Œ โ€Œโ€Œ โ€Œโ€Œ โ€Œโ€Œ โ€Œโ€Œ โ€Œโ€Œ โ€Œโ€Œ โœ” โ€Œโ€Œ โ€Œโ€Œ โ€Œโ€Œ โ€Œโ€Œ โ€Œโ€Œ โ€Œโ€Œ
Linux โ€Œโ€Œ โ€Œโ€Œ โ€Œโ€Œ โ€Œโ€Œ โ€Œโ€Œ โ€Œโ€Œ In Progress โ€Œโ€Œ โ€Œโ€Œ โ€Œโ€Œ โ€Œโ€Œ โ€Œโ€Œ โ€Œโ€Œ
MacOS โ€Œโ€Œ โ€Œโ€Œ โ€Œโ€Œ โ€Œโ€Œ โ€Œโ€Œ โ€Œโ€Œ In Progress โ€Œโ€Œ โ€Œโ€Œ โ€Œโ€Œ โ€Œโ€Œ โ€Œโ€Œ โ€Œโ€Œ

Getting Started

Install azula using:

npm install azula

You can now import azula into your project:

const azula = require("azula");

Or with ESM:

import azula from "azula";

API

Window

When creating a new Window, the following parameters are available:

Name Type Description
width (Optional) Number The initial width of the window
height (Optional) Number The initial height of the window
title (Optional) String The initial title of the window
useOffscreenRendering (Optional) Boolean When true, creates the window in OSR mode
let window = new azula.Window({
  width: 480,
  height: 320,
  title: "My App",
  useOffscreenRendering: false
});

General

Window.prototype.title

Type Description
String A getter/setter allowing to retrieve or update the title of the window
window.title = "My App";
window.title; // "My App"

Window.prototype.width

Type Description
Number A getter/setter allowing to retrieve or update the width of the window
window.width = 640;
window.width; // 640

Window.prototype.height

Type Description
Number A getter/setter allowing to retrieve or update the height of the window
window.height = 480;
window.height; // 480

Window.prototype.update

This method should be called to poll window events (making the window interactive). In non-OSR mode, this method also does the painting of the window.

window.update();

Window.prototype.flush

This method should only be used in OSR mode. Calling this method executes all remaining render operations and flushes the underlying context.

window.flush();

Window.prototype.shouldClose

Type Description
Boolean A boolean, indicating if the window should be closed
window.shouldClose(); // true/false

Loading

Window.prototype.loadHTML

Name Type Description
html String String representation of the HTML to load
window.loadHTML("<button>Hello World!</button>");

Window.prototype.loadFile

Name Type Description
path String The path from where the content gets read from
window.loadFile("./index.html");

Events

Window.prototype.onresize

Type Description
Function The function to call when the window gets resized

The callback's Event parameter has the following structure:

Name Type Description
width Number The new width of the window
height Number The new height of the window
window.onresize = e => {
  console.log(e.width, e.height);
};

Window.prototype.oncursorchange

Type Description
Function The function to call when the cursor should be changed

The callback's Event parameter has the following structure:

Name Type Description
name String A name representing the cursor type to change to
window.oncursorchange = e => {
  console.log(e.name);
};

Window.prototype.onconsolemessage

Type Description
Function The function to call when a console message got sent

The underlying JavaScript engine of azula is WebKit's JavaScriptCore engine. Now this means, that the JavaScript running in the GUI is separated from the JavaScript in Node. When the JavaScript in the GUI makes a call to the console, e.g. console.log(42);, we have to route this call over to Node.

The callback's Event parameter has the following structure:

Name Type Description
level String The level of the console call. For example "log", "warn" or "error"
callee Function Node's equivalent console function to call
message String The message passed to the console call
source String The file or location where the call was made. Is empty when loadHTML was used
location Object An Object describing the exact code location where the console call was made from

The location Object comes with the following structure:

Name Type Description
line Number The code line where the console call originated from
column Number The code column where the console call originated from
window.onconsolemessage = e => {
  let location = `at ${e.source ? e.source + ":" : ""}${e.location.line}:${e.location.column}`;
  e.callee.apply(console, [e.message, location]);
};

Event Dispatching

The Event Dispatching System should only be used in OSR mode. Event Dispatching allows to manually send events to the GUI, such as mouse gestures or key events.

Window.prototype.dispatchMouseEvent

Name Type Description
type String The type of event
x Number The horizontal position of the mouse
y Number The vertical position of the mouse
button Number The currently pressed mouse button

The following event types are available:

Name Type
onmousedown Simulating a mouse press action
onmouseup Simulating a mouse leave action
onmousemove Simulating a mouse move action
window.dispatchMouseEvent("onmousedown", 16, 32, 1); // press the left mouse button at 16:32
window.dispatchMouseEvent("onmouseup", 16, 32, 1); // leave the left mouse button at 16:32
window.dispatchMouseEvent("onmousemove", 16, 32, 0); // move the mouse to 16:32 without pressing a mouse button

Window.prototype.dispatchKeyEvent

Key Codes are mapped towards GLFW's Key Codes.

Name Type Description
type String The type of event
keyCode Number A key code representing which key to press

The following event types are available:

Name Type
onkeydown Simulating a key press action
onkeyup Simulating a key leave action
window.dispatchKeyEvent("onkeydown", x); // press a key
window.dispatchKeyEvent("onkeyup", x); // leave a key

Window.prototype.dispatchScrollEvent

Name Type Description
type String The type of event
deltaX Number The horizontal amount to scroll
deltaY Number The vertical amount to scroll

The following event types are available:

Name Type
onmousewheel Simulating a mouse wheel action
window.dispatchScrollEvent("onmousewheel", 0, 1); // scroll upwards, vertically by 1
window.dispatchScrollEvent("onmousewheel", -1, 0); // scroll downwards, horizontally by -1

Object Messaging

The underlying JavaScript engine of azula is WebKit's JavaScriptCore engine. The JavaScript engine of Node is different to the one used in azula, so we cannot directly exchange data. The Object Messaging System allows to send Object between both engines.

Note that to be sent Objects should kept small, as behind the scenes, they get serialized.

Window.prototype.dispatchObject

An equivalent method is available in the GUI. See this example as a reference.

Name Type Description
object Object The Object to send to the GUI
window.dispatchObject({ message: "PING" });

Window.prototype.onobjectmessage

An equivalent method is available in the GUI. See this example as a reference.

Type Description
Function The function to call when an object message was sent from the GUI

The callback's Event parameter has the following structure:

Name Type Description
object Object The Object sent from the GUI
window.onobjectmessage = object => {
  console.log(object);
};

Binary Messaging

The underlying JavaScript engine of azula is WebKit's JavaScriptCore engine. The JavaScript engine of Node is different to the one used in azula, so we cannot directly exchange data. The Binary Messaging System allows to efficiently pass ArrayBuffers between both engines. Even though the engines are different, ArrayBuffers can be exchanged without any copying, meaning they don't have any overhead.

Window.prototype.dispatchBinaryBuffer

An equivalent method is available in the GUI. See this example as a reference.

The binarymessage system should only be used when sending large data between Node and azula. The buffer argument is a referenced buffer, which means there is no overhead when sending it between Node and azula as the data is effectively referenced.

The second argument is an Object (and is optional), which can be used to give some additional information about the buffer argument. This Object should be kept small, as it gets serialized behind the scenes, and so comes with some overhead.

Name Type Description
buffer ArrayBuffer The ArrayBuffer to send to the GUI
args (Optional) Object An Used-defined Object providing additional information about the buffer
window.dispatchBinaryBuffer(new ArrayBuffer(16), { kind: "SOME_DATA" });

Window.prototype.onbinarymessage

An equivalent method is available in the GUI. See this example as a reference.

The binarymessage system should only be used when sending large data between Node and azula. The buffer argument is a referenced buffer, which means there is no overhead when sending it between Node and azula as the data is effectively referenced.

The second argument is an Object (and is optional), which can be used to give some additional information about the buffer argument. This Object should be kept small, as it gets serialized behind the scenes, and so comes with some overhead.

Type Description
Function The function to call when a binary message was sent from the GUI

The callback's Event parameter has the following structure:

Name Type Description
buffer ArrayBuffer The ArrayBuffer sent from the GUI
args (Optional) Object An Used-defined Object providing additional information about the sent buffer
window.onbinarymessage = (buffer, args) => {
  console.log(buffer, args);
};

OSR Mode

Window.prototype.getSharedHandleD3D11

Type Description
BigInt A BigInt representing a Windows HANDLE

On Windows, you can use this method to retrieve a shared HANDLE to the underlying D3D11 render texture.

let handle = window.getSharedHandleD3D11();

OSR

See this example as a reference.

azula supports running in OSR (Offscreen rendering) mode. This means, that instead of creating a window, an invisible texture gets used and rendered into. This texture can then be imported into a 3D engine for example. Another common use case would be, to display the texture in a VR environment.

On Windows, you can request a shared HANDLE using the Window's getSharedHandleD3D11 method.

License

Azula is MIT licensed, while Ultralight comes with the following License:

Ultralight is free for non-commercial use, educational use, 
and also free for commercial use by small indie developers making
less than US$100,000 a year. You can find full terms in the SDK. 
Pricing plans for larger commercial projects will be announced later.

For further information regaring the licensing of Ultralight, see this link.

โ€Œโ€Œ

No, you miscalculated! You should have feared me more! - Azula

More Repositories

1

poxi

A flat pixel art editor
JavaScript
2,479
star
2

Iroh

Dynamic code analysis tool - Exploit, record and analyze running JavaScript
JavaScript
921
star
3

nvk

Vulkan API for JavaScript/TypeScript
C++
915
star
4

PokeMMO

๐ŸŽฎ Pokemon MMO engine with realtime editor
JavaScript
728
star
5

POGOserver

Pokemon GO server emulator
JavaScript
460
star
6

dawn-ray-tracing

Hardware Ray tracing extension for Chromium WebGPU
C++
263
star
7

wasm-particles

WASM accelerated particles
JavaScript
253
star
8

mini-c

C to WebAssembly compiler
JavaScript
250
star
9

webgpu

WebGPU for Node [Deprecated, Unmaintained]
C
243
star
10

rokon

3D engine using WebGL2, WebAssembly
JavaScript
233
star
11

glmw

WebAssembly based Matrix and Vector library
C
200
star
12

mini-js

Minimal self-hosted JavaScript compiler in 1k lines of code
JavaScript
158
star
13

WebGPU-Path-Tracer

Toy path tracer using WebGPU RT
JavaScript
135
star
14

tiny-rtx

VK_NV_ray_tracing based Ray tracer
JavaScript
100
star
15

TXT2PNG

๐Ÿ—ป Store ASCII inside PNGs
JavaScript
73
star
16

momo

A Vulkan RTX Path Tracer
JavaScript
69
star
17

hevia-parser

A recursive descent Swift parser written in ES6
JavaScript
63
star
18

nvk-examples

Examples and demos for nvk
JavaScript
58
star
19

chromium-ray-tracing

Chromium build with hardware accelerated ray tracing
57
star
20

pokemon-emerald-rom-hacking

ROM hacking kit for Pokemon Emerald
JavaScript
50
star
21

VK_KHR_ray_tracing

VK_KHR_ray_tracing example
C++
42
star
22

YUE

My personal WebGPU based 3D renderer
TypeScript
38
star
23

html-canvas

Rendering HTML into canvas
JavaScript
26
star
24

canvas-live-stream

Live streaming canvas over websockets
JavaScript
26
star
25

webgpu-examples

Examples for node-webgpu
JavaScript
24
star
26

hevia-compiler

Strongly typed language that compiles to JavaScript
JavaScript
17
star
27

toy-compiler

A tiny self-hosted compiler
JavaScript
16
star
28

emerald-engine

JavaScript
16
star
29

POGO-asset-downloader

๐Ÿš€ Download Pokemon GO 3D models
JavaScript
16
star
30

Lamella

โšช Flow based Visual Programming
JavaScript
12
star
31

tolw

WebGL .obj loader - WebAssembly port of tinyobjloader
JavaScript
11
star
32

src2game

Turn Javascript source code into a Game
JavaScript
10
star
33

nvk-optix-denoiser

Real-time Denoiser for node-vulkan
JavaScript
10
star
34

3d-code-vizard

3D runtime code visualization
JavaScript
9
star
35

object-reflector

Simple & powerful Object reflections
JavaScript
8
star
36

htmlparse

Minimal blazing fast HTML parser
JavaScript
7
star
37

space-shooter

A simple space shooter
JavaScript
7
star
38

banotils

Utilities for the banano cryptocurrency
TypeScript
6
star
39

bitpackr

An efficient low-level packet serializer, down to bit-level
TypeScript
6
star
40

bnsh-decoder

A decoder for Nintendo Switch BNSH shaders
C++
5
star
41

Watcher

Track all changes inside your DOM
JavaScript
5
star
42

webgpu-compute-rasterizer

A simple compute based rasterizer
JavaScript
5
star
43

PokeName

Fiddle with Pokรฉmon names in different languages
JavaScript
4
star
44

Calc

Browserbased Excel
JavaScript
4
star
45

xr-engine

WebXR engine
JavaScript
3
star
46

POGOdecode

Pokemon GO Request<->Response decoder
JavaScript
3
star
47

nvk-essentials

Essential development tools for nvk
GLSL
3
star
48

Interpreter

A small interpreter with asynchronous step based execution support
JavaScript
2
star
49

wast-parser

WebAssembly WAST parser
JavaScript
2
star
50

neural-ocr

Neural network OCR
JavaScript
2
star
51

mc-spawner-upgrade

Lets you upgrade your mob spawners in minecraft
Java
2
star
52

pawtils

Utilities for the paw cryptocurrency
TypeScript
2
star
53

nanpow

TypeScript
1
star
54

Music-Box

Programmable wave music box
JavaScript
1
star
55

Expanding-spiral-animation

Canvas based expanding spiral experiment written in ES6
JavaScript
1
star