mirror of
https://github.com/Rezmason/matrix.git
synced 2026-04-21 15:29:30 -07:00
Massive overhaul: the renderers are now classes that implement Renderer; replaced webpack and rollup with vite; converted bundle-contents to "core" and "full" bundle profiles; renamed "inclusions" to "staticAssets", which are "url" base64-encoded images and "raw" text strings; renamed the Matrix component module to the JSX extension; built out a test scaffold at tools/test/index.html to manually test the various deploy options.
This commit is contained in:
92
js/renderer.js
Normal file
92
js/renderer.js
Normal file
@@ -0,0 +1,92 @@
|
||||
import fetchLibraries from "./fetchLibraries.js";
|
||||
|
||||
export default class Renderer {
|
||||
|
||||
static libraries = fetchLibraries();
|
||||
#type;
|
||||
#canvas;
|
||||
#ready;
|
||||
#width = 300;
|
||||
#height = 150;
|
||||
#fullscreen = false;
|
||||
#cache = new Map();
|
||||
#destroyed = false;
|
||||
|
||||
constructor(type, ready) {
|
||||
this.#type = type;
|
||||
this.#canvas = document.createElement("canvas");
|
||||
this.#ready = Renderer.libraries.then(libraries => {
|
||||
this.#cache = new Map(libraries.staticAssets);
|
||||
}).then(ready);
|
||||
}
|
||||
|
||||
get canvas() {
|
||||
return this.#canvas;
|
||||
}
|
||||
|
||||
get cache() {
|
||||
return this.#cache;
|
||||
}
|
||||
|
||||
get type () {
|
||||
return this.#type;
|
||||
}
|
||||
|
||||
get ready () {
|
||||
return this.#ready;
|
||||
}
|
||||
|
||||
get size() {
|
||||
return [this.#width, this.#height];
|
||||
}
|
||||
|
||||
set size([width, height]) {
|
||||
[width, height] = [Math.ceil(width), Math.ceil(height)];
|
||||
if (width === this.#width && height === this.#height) {
|
||||
return;
|
||||
}
|
||||
[this.#canvas.width, this.#canvas.height] = [this.#width, this.#height] = [width, height];
|
||||
}
|
||||
|
||||
get fullscreen() {
|
||||
return this.#fullscreen;
|
||||
}
|
||||
|
||||
set fullscreen(value) {
|
||||
if (!!value === this.#fullscreen) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!document.fullscreenEnabled && !document.webkitFullscreenEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.#fullscreen = value;
|
||||
if (document.fullscreenElement != null) {
|
||||
document.exitFullscreen();
|
||||
}
|
||||
if (this.#fullscreen) {
|
||||
if (this.#canvas.webkitRequestFullscreen != null) {
|
||||
this.#canvas.webkitRequestFullscreen();
|
||||
} else {
|
||||
this.#canvas.requestFullscreen();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async formulate(config) {
|
||||
await this.ready;
|
||||
if (this.destroyed) {
|
||||
throw new Error("Cannot formulate a destroyed rain instance.");
|
||||
}
|
||||
}
|
||||
|
||||
get destroyed() {
|
||||
return this.#destroyed;
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.#destroyed = true;
|
||||
this.#cache.clear();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user