@oliversalzburg/js-utils 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/async/async.d.ts +44 -0
- package/lib/async/async.js +76 -0
- package/lib/async/async.js.map +1 -0
- package/lib/async/async.test.d.ts +1 -0
- package/lib/async/async.test.js +26 -0
- package/lib/async/async.test.js.map +1 -0
- package/lib/cli/args.d.ts +9 -0
- package/lib/cli/args.js +49 -0
- package/lib/cli/args.js.map +1 -0
- package/lib/cli/args.test.d.ts +1 -0
- package/lib/cli/args.test.js +31 -0
- package/lib/cli/args.test.js.map +1 -0
- package/lib/core.d.ts +43 -0
- package/lib/core.js +2 -0
- package/lib/core.js.map +1 -0
- package/lib/data/array.d.ts +55 -0
- package/lib/data/array.js +90 -0
- package/lib/data/array.js.map +1 -0
- package/lib/data/nil.d.ts +92 -0
- package/lib/data/nil.js +131 -0
- package/lib/data/nil.js.map +1 -0
- package/lib/data/random.d.ts +111 -0
- package/lib/data/random.js +381 -0
- package/lib/data/random.js.map +1 -0
- package/lib/data/string.d.ts +30 -0
- package/lib/data/string.js +53 -0
- package/lib/data/string.js.map +1 -0
- package/lib/data/tree.d.ts +28 -0
- package/lib/data/tree.js +45 -0
- package/lib/data/tree.js.map +1 -0
- package/lib/device/shake.d.ts +79 -0
- package/lib/device/shake.js +135 -0
- package/lib/device/shake.js.map +1 -0
- package/lib/dom/core.d.ts +21 -0
- package/lib/dom/core.js +41 -0
- package/lib/dom/core.js.map +1 -0
- package/lib/errors/AbstractError.d.ts +29 -0
- package/lib/errors/AbstractError.js +59 -0
- package/lib/errors/AbstractError.js.map +1 -0
- package/lib/errors/InternalError.d.ts +19 -0
- package/lib/errors/InternalError.js +38 -0
- package/lib/errors/InternalError.js.map +1 -0
- package/lib/errors/InvalidArgumentError.d.ts +13 -0
- package/lib/errors/InvalidArgumentError.js +22 -0
- package/lib/errors/InvalidArgumentError.js.map +1 -0
- package/lib/errors/InvalidOperationError.d.ts +13 -0
- package/lib/errors/InvalidOperationError.js +22 -0
- package/lib/errors/InvalidOperationError.js.map +1 -0
- package/lib/errors/NotImplementedError.d.ts +12 -0
- package/lib/errors/NotImplementedError.js +21 -0
- package/lib/errors/NotImplementedError.js.map +1 -0
- package/lib/errors/PermissionViolationError.d.ts +13 -0
- package/lib/errors/PermissionViolationError.js +22 -0
- package/lib/errors/PermissionViolationError.js.map +1 -0
- package/lib/errors/ResourceConflictError.d.ts +12 -0
- package/lib/errors/ResourceConflictError.js +21 -0
- package/lib/errors/ResourceConflictError.js.map +1 -0
- package/lib/errors/UnknownError.d.ts +16 -0
- package/lib/errors/UnknownError.js +25 -0
- package/lib/errors/UnknownError.js.map +1 -0
- package/lib/errors/console.d.ts +7 -0
- package/lib/errors/console.js +13 -0
- package/lib/errors/console.js.map +1 -0
- package/lib/errors/error-serializer.d.ts +45 -0
- package/lib/errors/error-serializer.js +74 -0
- package/lib/errors/error-serializer.js.map +1 -0
- package/lib/errors/error-serializer.test.d.ts +1 -0
- package/lib/errors/error-serializer.test.js +109 -0
- package/lib/errors/error-serializer.test.js.map +1 -0
- package/lib/errors/stream.d.ts +7 -0
- package/lib/errors/stream.js +15 -0
- package/lib/errors/stream.js.map +1 -0
- package/lib/errors/tools.d.ts +10 -0
- package/lib/errors/tools.js +13 -0
- package/lib/errors/tools.js.map +1 -0
- package/lib/events/event.d.ts +9 -0
- package/lib/events/event.js +10 -0
- package/lib/events/event.js.map +1 -0
- package/lib/format/bytes.d.ts +118 -0
- package/lib/format/bytes.js +138 -0
- package/lib/format/bytes.js.map +1 -0
- package/lib/format/bytes.test.d.ts +1 -0
- package/lib/format/bytes.test.js +146 -0
- package/lib/format/bytes.test.js.map +1 -0
- package/lib/format/count.d.ts +14 -0
- package/lib/format/count.js +51 -0
- package/lib/format/count.js.map +1 -0
- package/lib/format/count.test.d.ts +1 -0
- package/lib/format/count.test.js +42 -0
- package/lib/format/count.test.js.map +1 -0
- package/lib/format/milliseconds.d.ts +100 -0
- package/lib/format/milliseconds.js +199 -0
- package/lib/format/milliseconds.js.map +1 -0
- package/lib/format/milliseconds.test.d.ts +1 -0
- package/lib/format/milliseconds.test.js +393 -0
- package/lib/format/milliseconds.test.js.map +1 -0
- package/lib/format/string.d.ts +24 -0
- package/lib/format/string.js +32 -0
- package/lib/format/string.js.map +1 -0
- package/lib/format/string.test.d.ts +1 -0
- package/lib/format/string.test.js +17 -0
- package/lib/format/string.test.js.map +1 -0
- package/lib/graphics/canvas-sandbox-mp.d.ts +258 -0
- package/lib/graphics/canvas-sandbox-mp.js +280 -0
- package/lib/graphics/canvas-sandbox-mp.js.map +1 -0
- package/lib/graphics/canvas-sandbox.d.ts +255 -0
- package/lib/graphics/canvas-sandbox.js +358 -0
- package/lib/graphics/canvas-sandbox.js.map +1 -0
- package/lib/graphics/canvas.d.ts +57 -0
- package/lib/graphics/canvas.js +37 -0
- package/lib/graphics/canvas.js.map +1 -0
- package/lib/graphics/canvas2d-headless.d.ts +85 -0
- package/lib/graphics/canvas2d-headless.js +197 -0
- package/lib/graphics/canvas2d-headless.js.map +1 -0
- package/lib/graphics/canvas2d.d.ts +162 -0
- package/lib/graphics/canvas2d.js +332 -0
- package/lib/graphics/canvas2d.js.map +1 -0
- package/lib/graphics/canvas3d.d.ts +41 -0
- package/lib/graphics/canvas3d.js +67 -0
- package/lib/graphics/canvas3d.js.map +1 -0
- package/lib/graphics/color.d.ts +22 -0
- package/lib/graphics/color.js +38 -0
- package/lib/graphics/color.js.map +1 -0
- package/lib/graphics/core.d.ts +89 -0
- package/lib/graphics/core.js +146 -0
- package/lib/graphics/core.js.map +1 -0
- package/lib/graphics/palette-sampler.d.ts +7 -0
- package/lib/graphics/palette-sampler.js +21 -0
- package/lib/graphics/palette-sampler.js.map +1 -0
- package/lib/graphics/palette.d.ts +120 -0
- package/lib/graphics/palette.js +574 -0
- package/lib/graphics/palette.js.map +1 -0
- package/lib/graphics/palette.test.d.ts +1 -0
- package/lib/graphics/palette.test.js +43 -0
- package/lib/graphics/palette.test.js.map +1 -0
- package/lib/graphics/render-loop.d.ts +76 -0
- package/lib/graphics/render-loop.js +114 -0
- package/lib/graphics/render-loop.js.map +1 -0
- package/lib/graphics/shader.d.ts +56 -0
- package/lib/graphics/shader.js +80 -0
- package/lib/graphics/shader.js.map +1 -0
- package/lib/log/log.d.ts +11 -0
- package/lib/log/log.js +2 -0
- package/lib/log/log.js.map +1 -0
- package/lib/log/report.d.ts +57 -0
- package/lib/log/report.js +88 -0
- package/lib/log/report.js.map +1 -0
- package/lib/math/core.d.ts +85 -0
- package/lib/math/core.js +125 -0
- package/lib/math/core.js.map +1 -0
- package/lib/math/easing.d.ts +204 -0
- package/lib/math/easing.js +366 -0
- package/lib/math/easing.js.map +1 -0
- package/lib/math/euler.d.ts +18 -0
- package/lib/math/euler.js +22 -0
- package/lib/math/euler.js.map +1 -0
- package/lib/math/matrix3.d.ts +227 -0
- package/lib/math/matrix3.js +508 -0
- package/lib/math/matrix3.js.map +1 -0
- package/lib/math/quaternion.d.ts +119 -0
- package/lib/math/quaternion.js +270 -0
- package/lib/math/quaternion.js.map +1 -0
- package/lib/math/transformation.d.ts +26 -0
- package/lib/math/transformation.js +31 -0
- package/lib/math/transformation.js.map +1 -0
- package/lib/math/vector2.d.ts +202 -0
- package/lib/math/vector2.js +310 -0
- package/lib/math/vector2.js.map +1 -0
- package/lib/math/vector3.d.ts +293 -0
- package/lib/math/vector3.js +492 -0
- package/lib/math/vector3.js.map +1 -0
- package/lib/math/vector4.d.ts +182 -0
- package/lib/math/vector4.js +302 -0
- package/lib/math/vector4.js.map +1 -0
- package/lib/measurement/performance.d.ts +13 -0
- package/lib/measurement/performance.js +19 -0
- package/lib/measurement/performance.js.map +1 -0
- package/package.json +5 -7
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The base class for canvas helpers, which also defines a common interface.
|
|
3
|
+
*
|
|
4
|
+
* Derivates of the class might chose to leave implementations of individual methods
|
|
5
|
+
* empty, if it fits their pattern better. For example, one canvas might wrap its
|
|
6
|
+
* context and applications using that canvas will only interact with its interface.
|
|
7
|
+
* Another canvas implementation might expose the context and all give the application
|
|
8
|
+
* full control over the rendering cycle.
|
|
9
|
+
*/
|
|
10
|
+
export class Canvas {
|
|
11
|
+
/**
|
|
12
|
+
* The canvas element we're interacting with.
|
|
13
|
+
*/
|
|
14
|
+
canvasElement;
|
|
15
|
+
/**
|
|
16
|
+
* Retrieves the width of the canvas.
|
|
17
|
+
* @returns The width of the canvas.
|
|
18
|
+
*/
|
|
19
|
+
get width() {
|
|
20
|
+
return this.canvasElement.width;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Retrieves the height of the canvas.
|
|
24
|
+
* @returns The height of the canvas.
|
|
25
|
+
*/
|
|
26
|
+
get height() {
|
|
27
|
+
return this.canvasElement.height;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Constructs a new canvas helper.
|
|
31
|
+
* @param canvas - The canvas node to wrap.
|
|
32
|
+
*/
|
|
33
|
+
constructor(canvas) {
|
|
34
|
+
this.canvasElement = canvas;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=canvas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canvas.js","sourceRoot":"","sources":["../../source/graphics/canvas.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,OAAgB,MAAM;IAC3B;;OAEG;IACM,aAAa,CAAsC;IAE5D;;;OAGG;IACH,IAAI,KAAK;QACR,OAAO,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC;IACjC,CAAC;IAED;;;OAGG;IACH,IAAI,MAAM;QACT,OAAO,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC;IAClC,CAAC;IAED;;;OAGG;IACH,YAAY,MAA2C;QACtD,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC;IAC7B,CAAC;CAqCD"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Canvas } from "./canvas.js";
|
|
2
|
+
import type { Canvas2DOptions } from "./canvas2d.js";
|
|
3
|
+
/**
|
|
4
|
+
* An offscreen canvas.
|
|
5
|
+
*
|
|
6
|
+
* This isn't created from a DOM node, but from an existing {@linkcode !OffscreenCanvas}.
|
|
7
|
+
*/
|
|
8
|
+
export declare class Canvas2DHeadless extends Canvas {
|
|
9
|
+
#private;
|
|
10
|
+
/**
|
|
11
|
+
* Retrieves the rendering context of the canvas.
|
|
12
|
+
* @returns The rendering context of the canvas.
|
|
13
|
+
*/
|
|
14
|
+
get context(): OffscreenCanvasRenderingContext2D;
|
|
15
|
+
/**
|
|
16
|
+
* Our back buffer.
|
|
17
|
+
*/
|
|
18
|
+
buffer: Uint8ClampedArray;
|
|
19
|
+
/**
|
|
20
|
+
* The configuration that was used for this canvas.
|
|
21
|
+
*/
|
|
22
|
+
readonly options: Readonly<Partial<Canvas2DOptions>>;
|
|
23
|
+
/**
|
|
24
|
+
* Constructs a new {@linkcode Canvas2DHeadless}.
|
|
25
|
+
* @param canvas - The offscreen canvas we're drawing to.
|
|
26
|
+
* @param context - The rendering context to use for the canvas.
|
|
27
|
+
* @param options - The configuration for this canvas.
|
|
28
|
+
*/
|
|
29
|
+
constructor(canvas: OffscreenCanvas, context: OffscreenCanvasRenderingContext2D, options?: Partial<Canvas2DOptions>);
|
|
30
|
+
/**
|
|
31
|
+
* Recreate internal buffers in reaction to a change in our target {@linkcode !OffscreenCanvas}.
|
|
32
|
+
*/
|
|
33
|
+
refreshCanvasNode(): void;
|
|
34
|
+
/**
|
|
35
|
+
* Draw FPS information onto the canvas.
|
|
36
|
+
* @param frameTimes - Durations of previous frame draws.
|
|
37
|
+
* @param frameTime - The duration of the previous frame draw.
|
|
38
|
+
* @param timeDelta - The time elapsed since the last frame.
|
|
39
|
+
*/
|
|
40
|
+
renderFpsInfo(frameTimes: Array<number>, frameTime: number, timeDelta: number): void;
|
|
41
|
+
/**
|
|
42
|
+
* Draws the back buffer onto the canvas.
|
|
43
|
+
*/
|
|
44
|
+
update(): void;
|
|
45
|
+
/**
|
|
46
|
+
* Draws the offscreen canvas into the DOM canvas.
|
|
47
|
+
*/
|
|
48
|
+
render(): void;
|
|
49
|
+
/**
|
|
50
|
+
* Draws a slightly transparent, black rectangle over the canvas,
|
|
51
|
+
* and then reads the result back into the buffer.
|
|
52
|
+
* @param color - The color to fade the buffer with. The alpha component of
|
|
53
|
+
* the color defines how strong the fade is. `0` is not at all, `255` makes
|
|
54
|
+
* it instantly black.
|
|
55
|
+
*/
|
|
56
|
+
fade(color?: number): void;
|
|
57
|
+
/**
|
|
58
|
+
* Reads the front buffer back into the back buffer.
|
|
59
|
+
*/
|
|
60
|
+
bufferReadBack(): void;
|
|
61
|
+
/**
|
|
62
|
+
* Returns the color of a pixel in the back buffer.
|
|
63
|
+
* @param x - The X coordinate to retrieve.
|
|
64
|
+
* @param y - The X coordinate to retrieve.
|
|
65
|
+
* @returns The color of the pixel at the given local.
|
|
66
|
+
*/
|
|
67
|
+
getPixel32(x: number, y: number): number;
|
|
68
|
+
/**
|
|
69
|
+
* Colors a pixel in the back buffer.
|
|
70
|
+
* @param x - The X coordinate to color.
|
|
71
|
+
* @param y - The Y coordinate to color.
|
|
72
|
+
* @param color - The color to place at the coordinate.
|
|
73
|
+
*/
|
|
74
|
+
setPixel32(x: number, y: number, color: number): void;
|
|
75
|
+
/**
|
|
76
|
+
* Fills the entire back buffer with the given color.
|
|
77
|
+
* @param color - The color to fill the back buffer with.
|
|
78
|
+
*/
|
|
79
|
+
clearWith(color: number): void;
|
|
80
|
+
/**
|
|
81
|
+
* Fills the entire back buffer with the given color.
|
|
82
|
+
* @param color - The color to fill the back buffer with.
|
|
83
|
+
*/
|
|
84
|
+
blendWith(color: number): void;
|
|
85
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { mustExist } from "../data/nil.js";
|
|
2
|
+
import { InvalidOperationError } from "../errors/InvalidOperationError.js";
|
|
3
|
+
import { Canvas } from "./canvas.js";
|
|
4
|
+
import { blend, fromRGBA, getA, getB, getG, getR } from "./core.js";
|
|
5
|
+
import { MS_PER_FRAME_60FPS } from "./render-loop.js";
|
|
6
|
+
/**
|
|
7
|
+
* An offscreen canvas.
|
|
8
|
+
*
|
|
9
|
+
* This isn't created from a DOM node, but from an existing {@linkcode !OffscreenCanvas}.
|
|
10
|
+
*/
|
|
11
|
+
export class Canvas2DHeadless extends Canvas {
|
|
12
|
+
/**
|
|
13
|
+
* The 2D rendering context we're using to draw to the canvas.
|
|
14
|
+
*/
|
|
15
|
+
#context;
|
|
16
|
+
/**
|
|
17
|
+
* Retrieves the rendering context of the canvas.
|
|
18
|
+
* @returns The rendering context of the canvas.
|
|
19
|
+
*/
|
|
20
|
+
get context() {
|
|
21
|
+
return this.#context;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The {@linkcode !ImageData} object in our offscreen canvas. We usually interact with its
|
|
25
|
+
* {@linkcode Canvas2D.buffer buffer} directly.
|
|
26
|
+
*/
|
|
27
|
+
#imageData;
|
|
28
|
+
/**
|
|
29
|
+
* Our back buffer.
|
|
30
|
+
*/
|
|
31
|
+
buffer;
|
|
32
|
+
/**
|
|
33
|
+
* The configuration that was used for this canvas.
|
|
34
|
+
*/
|
|
35
|
+
options;
|
|
36
|
+
/**
|
|
37
|
+
* Constructs a new {@linkcode Canvas2DHeadless}.
|
|
38
|
+
* @param canvas - The offscreen canvas we're drawing to.
|
|
39
|
+
* @param context - The rendering context to use for the canvas.
|
|
40
|
+
* @param options - The configuration for this canvas.
|
|
41
|
+
*/
|
|
42
|
+
constructor(canvas, context, options = {}) {
|
|
43
|
+
super(canvas);
|
|
44
|
+
this.options = options;
|
|
45
|
+
this.#context = context;
|
|
46
|
+
this.#imageData = this.#context.createImageData(this.width, this.height);
|
|
47
|
+
this.buffer = this.#imageData.data;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Recreate internal buffers in reaction to a change in our target {@linkcode !OffscreenCanvas}.
|
|
51
|
+
*/
|
|
52
|
+
refreshCanvasNode() {
|
|
53
|
+
this.#context = mustExist(this.canvasElement.getContext("2d", {
|
|
54
|
+
alpha: false,
|
|
55
|
+
desynchronized: true,
|
|
56
|
+
willReadFrequently: this.options.supportReadBack,
|
|
57
|
+
}), "Unable to create rendering context for offscreen canvas.");
|
|
58
|
+
this.#imageData = this.#context.createImageData(this.width, this.height);
|
|
59
|
+
this.buffer = this.#imageData.data;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Draw FPS information onto the canvas.
|
|
63
|
+
* @param frameTimes - Durations of previous frame draws.
|
|
64
|
+
* @param frameTime - The duration of the previous frame draw.
|
|
65
|
+
* @param timeDelta - The time elapsed since the last frame.
|
|
66
|
+
*/
|
|
67
|
+
renderFpsInfo(frameTimes, frameTime, timeDelta) {
|
|
68
|
+
const maxFrameTime = frameTimes.reduce((max, frameTime) => {
|
|
69
|
+
if (max < frameTime) {
|
|
70
|
+
max = frameTime;
|
|
71
|
+
}
|
|
72
|
+
return max;
|
|
73
|
+
}, 0);
|
|
74
|
+
const sumFrameTimes = frameTimes.reduce((sum, frameTime) => sum + frameTime, 0);
|
|
75
|
+
const fpsAll = Math.round(frameTimes.length / (sumFrameTimes / 1000)).toString();
|
|
76
|
+
const fpsFrame = 1000 / frameTime;
|
|
77
|
+
const fpsDelta = 1000 / timeDelta;
|
|
78
|
+
let currentX = this.width;
|
|
79
|
+
for (const frameTime of frameTimes) {
|
|
80
|
+
let fillColor = 0x00ff00ff;
|
|
81
|
+
let width = 1;
|
|
82
|
+
if (MS_PER_FRAME_60FPS < frameTime) {
|
|
83
|
+
const quality = frameTime / maxFrameTime;
|
|
84
|
+
fillColor =
|
|
85
|
+
blend(0x00ff00ff, 0xff0000ff, Math.trunc(quality * 255)) >>> 0;
|
|
86
|
+
width = Math.round(frameTime / MS_PER_FRAME_60FPS);
|
|
87
|
+
}
|
|
88
|
+
this.context.fillStyle = `#${fillColor.toString(16).padStart(8, "0")}`;
|
|
89
|
+
this.context.globalAlpha = 255;
|
|
90
|
+
this.context.fillRect(currentX - width, this.height, width, (frameTime / Math.max(100, maxFrameTime)) * -100);
|
|
91
|
+
currentX -= width;
|
|
92
|
+
}
|
|
93
|
+
this.context.beginPath();
|
|
94
|
+
this.context.strokeStyle = "#fff";
|
|
95
|
+
this.context.moveTo(0, this.height - MS_PER_FRAME_60FPS);
|
|
96
|
+
this.context.lineTo(this.width, this.height - MS_PER_FRAME_60FPS);
|
|
97
|
+
this.context.stroke();
|
|
98
|
+
const fpsString = `${Math.round(fpsFrame).toFixed(3)}f ${fpsAll}∑ ${Math.round(fpsDelta).toFixed(3)}δ`;
|
|
99
|
+
this.context.font = "13px monospace";
|
|
100
|
+
this.context.strokeStyle = "rgba( 255, 255, 255, 1)";
|
|
101
|
+
this.context.textAlign = "right";
|
|
102
|
+
this.context.textRendering = "geometricPrecision";
|
|
103
|
+
this.context.strokeText(fpsString, this.width - 3, this.height - 3);
|
|
104
|
+
this.context.fillStyle = "#000000";
|
|
105
|
+
this.context.fillText(fpsString, this.width - 3, this.height - 3);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Draws the back buffer onto the canvas.
|
|
109
|
+
*/
|
|
110
|
+
update() {
|
|
111
|
+
this.#context.putImageData(this.#imageData, 0, 0);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Draws the offscreen canvas into the DOM canvas.
|
|
115
|
+
*/
|
|
116
|
+
render() {
|
|
117
|
+
// Nothing to do here. Everything happens in update().
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Draws a slightly transparent, black rectangle over the canvas,
|
|
121
|
+
* and then reads the result back into the buffer.
|
|
122
|
+
* @param color - The color to fade the buffer with. The alpha component of
|
|
123
|
+
* the color defines how strong the fade is. `0` is not at all, `255` makes
|
|
124
|
+
* it instantly black.
|
|
125
|
+
*/
|
|
126
|
+
fade(color = fromRGBA(0, 0, 0, 1)) {
|
|
127
|
+
this.blendWith(color);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Reads the front buffer back into the back buffer.
|
|
131
|
+
*/
|
|
132
|
+
bufferReadBack() {
|
|
133
|
+
if (!this.options.supportReadBack) {
|
|
134
|
+
throw new InvalidOperationError("To use `bufferReadBack()`, you must construct the `Canvas` with `options.supportReadBack` set to `true`.");
|
|
135
|
+
}
|
|
136
|
+
this.#imageData = this.#context.getImageData(0, 0, this.width, this.height);
|
|
137
|
+
this.buffer = this.#imageData.data;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Returns the color of a pixel in the back buffer.
|
|
141
|
+
* @param x - The X coordinate to retrieve.
|
|
142
|
+
* @param y - The X coordinate to retrieve.
|
|
143
|
+
* @returns The color of the pixel at the given local.
|
|
144
|
+
*/
|
|
145
|
+
getPixel32(x, y) {
|
|
146
|
+
const bufferOffset = (x + y * this.width) * 4;
|
|
147
|
+
return fromRGBA(this.buffer[bufferOffset + 0], this.buffer[bufferOffset + 1], this.buffer[bufferOffset + 2], this.buffer[bufferOffset + 3]);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Colors a pixel in the back buffer.
|
|
151
|
+
* @param x - The X coordinate to color.
|
|
152
|
+
* @param y - The Y coordinate to color.
|
|
153
|
+
* @param color - The color to place at the coordinate.
|
|
154
|
+
*/
|
|
155
|
+
setPixel32(x, y, color) {
|
|
156
|
+
const bufferOffset = (x + y * this.width) * 4;
|
|
157
|
+
this.buffer[bufferOffset + 0] = getR(color);
|
|
158
|
+
this.buffer[bufferOffset + 1] = getG(color);
|
|
159
|
+
this.buffer[bufferOffset + 2] = getB(color);
|
|
160
|
+
this.buffer[bufferOffset + 3] = getA(color);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Fills the entire back buffer with the given color.
|
|
164
|
+
* @param color - The color to fill the back buffer with.
|
|
165
|
+
*/
|
|
166
|
+
clearWith(color) {
|
|
167
|
+
const r = getR(color);
|
|
168
|
+
const g = getG(color);
|
|
169
|
+
const b = getB(color);
|
|
170
|
+
const a = getA(color);
|
|
171
|
+
for (let bufferOffset = 0; bufferOffset < this.width * this.height * 4; bufferOffset += 4) {
|
|
172
|
+
this.buffer[bufferOffset + 0] = r;
|
|
173
|
+
this.buffer[bufferOffset + 1] = g;
|
|
174
|
+
this.buffer[bufferOffset + 2] = b;
|
|
175
|
+
this.buffer[bufferOffset + 3] = a;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Fills the entire back buffer with the given color.
|
|
180
|
+
* @param color - The color to fill the back buffer with.
|
|
181
|
+
*/
|
|
182
|
+
blendWith(color) {
|
|
183
|
+
const r = getR(color);
|
|
184
|
+
const g = getG(color);
|
|
185
|
+
const b = getB(color);
|
|
186
|
+
const a = getA(color);
|
|
187
|
+
for (let bufferOffset = 0; bufferOffset < this.width * this.height * 4; bufferOffset += 4) {
|
|
188
|
+
this.buffer[bufferOffset + 0] =
|
|
189
|
+
(a * r + (255 - a) * this.buffer[bufferOffset + 0]) >> 8;
|
|
190
|
+
this.buffer[bufferOffset + 1] =
|
|
191
|
+
(a * g + (255 - a) * this.buffer[bufferOffset + 1]) >> 8;
|
|
192
|
+
this.buffer[bufferOffset + 2] =
|
|
193
|
+
(a * b + (255 - a) * this.buffer[bufferOffset + 2]) >> 8;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=canvas2d-headless.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canvas2d-headless.js","sourceRoot":"","sources":["../../source/graphics/canvas2d-headless.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,O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
|
|
|
1
|
+
import { Canvas } from "./canvas.js";
|
|
2
|
+
import type { Canvas2DHeadless } from "./canvas2d-headless.js";
|
|
3
|
+
/**
|
|
4
|
+
* Construction options for a {@linkcode Canvas2D}.
|
|
5
|
+
*/
|
|
6
|
+
export interface Canvas2DOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Was this {@linkcode Canvas2D} created with the ability to copy the front buffer back into
|
|
9
|
+
* the back buffer?
|
|
10
|
+
*/
|
|
11
|
+
readonly supportReadBack: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The {@linkcode Canvas2D} is a double-buffered construct to help with drawing to a
|
|
15
|
+
* {@linkcode !HTMLCanvasElement} with best possible performance.
|
|
16
|
+
* We utilize an {@linkcode !OffscreenCanvas} with a {@linkcode !OffscreenCanvasRenderingContext2D}
|
|
17
|
+
* to draw frames and expect to render them back to the DOM in regular intervals.
|
|
18
|
+
*/
|
|
19
|
+
export declare class Canvas2D extends Canvas {
|
|
20
|
+
#private;
|
|
21
|
+
/**
|
|
22
|
+
* Retrieves the rendering context of the canvas.
|
|
23
|
+
* @returns The rendering context of the canvas.
|
|
24
|
+
*/
|
|
25
|
+
get context(): OffscreenCanvasRenderingContext2D;
|
|
26
|
+
/**
|
|
27
|
+
* Our back buffer.
|
|
28
|
+
*/
|
|
29
|
+
buffer: Uint8ClampedArray;
|
|
30
|
+
/**
|
|
31
|
+
* The configuration that was used for this canvas.
|
|
32
|
+
*/
|
|
33
|
+
readonly options: Readonly<Partial<Canvas2DOptions>>;
|
|
34
|
+
/**
|
|
35
|
+
* Constructs a new {@linkcode Canvas2D}.
|
|
36
|
+
* @param canvas - The canvas to wrap.
|
|
37
|
+
* @param options - The configuration for this canvas.
|
|
38
|
+
*/
|
|
39
|
+
constructor(canvas: HTMLCanvasElement, options?: Partial<Canvas2DOptions>);
|
|
40
|
+
/**
|
|
41
|
+
* Recreate internal buffers in reaction to a change in our target {@linkcode !HTMLCanvasElement}.
|
|
42
|
+
*/
|
|
43
|
+
refreshCanvasNode(): void;
|
|
44
|
+
/**
|
|
45
|
+
* Draw FPS information onto the canvas.
|
|
46
|
+
* @param frameTimes - Durations of previous frame draws.
|
|
47
|
+
* @param frameTime - The duration of the previous frame draw.
|
|
48
|
+
* @param timeDelta - The time elapsed since the last frame.
|
|
49
|
+
*/
|
|
50
|
+
renderFpsInfo(frameTimes: Array<number>, frameTime: number, timeDelta: number): void;
|
|
51
|
+
/**
|
|
52
|
+
* Draws the back buffer onto the canvas.
|
|
53
|
+
*/
|
|
54
|
+
update(): void;
|
|
55
|
+
/**
|
|
56
|
+
* Draws the offscreen canvas into the DOM canvas.
|
|
57
|
+
*/
|
|
58
|
+
render(): void;
|
|
59
|
+
/**
|
|
60
|
+
* Draws a slightly transparent, black rectangle over the canvas,
|
|
61
|
+
* and then reads the result back into the buffer.
|
|
62
|
+
* @param color - The color to fade the buffer with. The alpha component of
|
|
63
|
+
* the color defines how strong the fade is. `0` is not at all, `255` makes
|
|
64
|
+
* it instantly black.
|
|
65
|
+
*/
|
|
66
|
+
fade(color?: number): void;
|
|
67
|
+
/**
|
|
68
|
+
* Reads the front buffer back into the back buffer.
|
|
69
|
+
*/
|
|
70
|
+
bufferReadBack(): void;
|
|
71
|
+
/**
|
|
72
|
+
* Returns the color of a pixel in the back buffer.
|
|
73
|
+
* @param x - The X coordinate to retrieve.
|
|
74
|
+
* @param y - The X coordinate to retrieve.
|
|
75
|
+
* @returns The color of the pixel at the given local.
|
|
76
|
+
*/
|
|
77
|
+
getPixel32(x: number, y: number): number;
|
|
78
|
+
/**
|
|
79
|
+
* Colors a pixel in the back buffer.
|
|
80
|
+
* @param x - The X coordinate to color.
|
|
81
|
+
* @param y - The Y coordinate to color.
|
|
82
|
+
* @param color - The color to place at the coordinate.
|
|
83
|
+
*/
|
|
84
|
+
setPixel32(x: number, y: number, color: number): void;
|
|
85
|
+
/**
|
|
86
|
+
* Fills the entire back buffer with the given color.
|
|
87
|
+
* @param color - The color to fill the back buffer with.
|
|
88
|
+
*/
|
|
89
|
+
clearWith(color: number): void;
|
|
90
|
+
/**
|
|
91
|
+
* Fills the entire back buffer with the given color.
|
|
92
|
+
* @param color - The color to fill the back buffer with.
|
|
93
|
+
*/
|
|
94
|
+
blendWith(color: number): void;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Linearly blends a new pixel with an existing color value in a canvas.
|
|
98
|
+
*
|
|
99
|
+
* As this method is often called many times in render loops, only bounds
|
|
100
|
+
* checking is applied to the given coordinates.
|
|
101
|
+
*
|
|
102
|
+
* The coordinates are **expected to already be integers**. Supplying numbers with fractions
|
|
103
|
+
* has performance implications. Ensure you're working with integers, or truncate the
|
|
104
|
+
* coordinates before passing them in.
|
|
105
|
+
*
|
|
106
|
+
* The `alpha` value is expected to be an integer in the range from `0` to `255`.
|
|
107
|
+
* `0` meaning fully transparent, `255` meaning fully opaque.
|
|
108
|
+
* @param canvas - The canvas to interact with.
|
|
109
|
+
* @param x - The X coordinate at which to place the pixel.
|
|
110
|
+
* @param y - The Y coordinate at which to place the pixel.
|
|
111
|
+
* @param color - The color of the pixel.
|
|
112
|
+
* @param alpha - The alpha value to use to blend the pixel with existing color at the location.
|
|
113
|
+
*/
|
|
114
|
+
export declare const putPixel32: (canvas: Canvas2D | Canvas2DHeadless, x: number, y: number, color: number, alpha: number) => void;
|
|
115
|
+
/**
|
|
116
|
+
* Additively blends a new pixel with an existing color value in a canvas.
|
|
117
|
+
*
|
|
118
|
+
* As this method is often called many times in render loops, only bounds
|
|
119
|
+
* checking is applied to the given coordinates.
|
|
120
|
+
*
|
|
121
|
+
* The coordinates are **expected to already be integers**. Supplying numbers with fractions
|
|
122
|
+
* has performance implications. Ensure you're working with integers, or truncate the
|
|
123
|
+
* coordinates before passing them in.
|
|
124
|
+
*
|
|
125
|
+
* The `alpha` value is expected to be an integer in the range from `0` to `255`.
|
|
126
|
+
* `0` meaning fully transparent, `255` meaning fully opaque.
|
|
127
|
+
* @param canvas - The canvas to interact with.
|
|
128
|
+
* @param x - The X coordinate at which to place the pixel.
|
|
129
|
+
* @param y - The Y coordinate at which to place the pixel.
|
|
130
|
+
* @param color - The color of the pixel.
|
|
131
|
+
* @param alpha - The alpha value to use to blend the pixel with existing color at the location.
|
|
132
|
+
*/
|
|
133
|
+
export declare const putPixel32Add: (canvas: Canvas2D | Canvas2DHeadless, x: number, y: number, color: number, alpha: number) => void;
|
|
134
|
+
/**
|
|
135
|
+
* Subtractively blends a new pixel with an existing color value in a canvas.
|
|
136
|
+
*
|
|
137
|
+
* As this method is often called many times in render loops, only bounds
|
|
138
|
+
* checking is applied to the given coordinates.
|
|
139
|
+
*
|
|
140
|
+
* The coordinates are **expected to already be integers**. Supplying numbers with fractions
|
|
141
|
+
* has performance implications. Ensure you're working with integers, or truncate the
|
|
142
|
+
* coordinates before passing them in.
|
|
143
|
+
*
|
|
144
|
+
* The `alpha` value is expected to be an integer in the range from `0` to `255`.
|
|
145
|
+
* `0` meaning fully transparent, `255` meaning fully opaque.
|
|
146
|
+
* @param canvas - The canvas to interact with.
|
|
147
|
+
* @param x - The X coordinate at which to place the pixel.
|
|
148
|
+
* @param y - The Y coordinate at which to place the pixel.
|
|
149
|
+
* @param color - The color of the pixel.
|
|
150
|
+
* @param alpha - The alpha value to use to blend the pixel with existing color at the location.
|
|
151
|
+
*/
|
|
152
|
+
export declare const putPixel32Sub: (canvas: Canvas2D | Canvas2DHeadless, x: number, y: number, color: number, alpha: number) => void;
|
|
153
|
+
/**
|
|
154
|
+
* Linearly blends a new pixel with an existing color value in a canvas.
|
|
155
|
+
* Compared to {@linkcode putPixel32}, this function supports sub-pixel placement, but is dramatically slower.
|
|
156
|
+
* @param canvas - The canvas to interact with.
|
|
157
|
+
* @param x - The X coordinate at which to place the pixel.
|
|
158
|
+
* @param y - The Y coordinate at which to place the pixel.
|
|
159
|
+
* @param color - The color of the pixel.
|
|
160
|
+
* @param alpha - The alpha value to use to blend the pixel with existing color at the location.
|
|
161
|
+
*/
|
|
162
|
+
export declare const putSubPixel32: (canvas: Canvas2D | Canvas2DHeadless, x: number, y: number, color: number, alpha: number) => void;
|