@oliversalzburg/js-utils 0.7.0 → 0.7.1
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/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/lib/tsconfig.tsbuildinfo +1 -0
- package/package.json +3 -5
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { mustExist } from "../data/nil.js";
|
|
2
|
+
import { InvalidOperationError } from "../errors/InvalidOperationError.js";
|
|
3
|
+
import { Canvas } from "./canvas.js";
|
|
4
|
+
import { blend, blendAdditive, blendSubtractive, fromRGBA, getA, getB, getG, getR, } from "./core.js";
|
|
5
|
+
import { MS_PER_FRAME_60FPS } from "./render-loop.js";
|
|
6
|
+
/**
|
|
7
|
+
* The {@linkcode Canvas2D} is a double-buffered construct to help with drawing to a
|
|
8
|
+
* {@linkcode !HTMLCanvasElement} with best possible performance.
|
|
9
|
+
* We utilize an {@linkcode !OffscreenCanvas} with a {@linkcode !OffscreenCanvasRenderingContext2D}
|
|
10
|
+
* to draw frames and expect to render them back to the DOM in regular intervals.
|
|
11
|
+
*/
|
|
12
|
+
export class Canvas2D extends Canvas {
|
|
13
|
+
/**
|
|
14
|
+
* The rendering context for the canvas located in the DOM.
|
|
15
|
+
*/
|
|
16
|
+
#canvasDomContext;
|
|
17
|
+
/**
|
|
18
|
+
* The offscreen canvas we use for rendering.
|
|
19
|
+
*/
|
|
20
|
+
#canvasOffscreen;
|
|
21
|
+
/**
|
|
22
|
+
* The 2D rendering context we're using to draw to the canvas.
|
|
23
|
+
*/
|
|
24
|
+
#context;
|
|
25
|
+
/**
|
|
26
|
+
* Retrieves the rendering context of the canvas.
|
|
27
|
+
* @returns The rendering context of the canvas.
|
|
28
|
+
*/
|
|
29
|
+
get context() {
|
|
30
|
+
return this.#context;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The {@linkcode !ImageData} object in our offscreen canvas. We usually interact with its
|
|
34
|
+
* {@linkcode Canvas2D.buffer buffer} directly.
|
|
35
|
+
*/
|
|
36
|
+
#imageData;
|
|
37
|
+
/**
|
|
38
|
+
* Our back buffer.
|
|
39
|
+
*/
|
|
40
|
+
buffer;
|
|
41
|
+
/**
|
|
42
|
+
* The configuration that was used for this canvas.
|
|
43
|
+
*/
|
|
44
|
+
options;
|
|
45
|
+
/**
|
|
46
|
+
* Constructs a new {@linkcode Canvas2D}.
|
|
47
|
+
* @param canvas - The canvas to wrap.
|
|
48
|
+
* @param options - The configuration for this canvas.
|
|
49
|
+
*/
|
|
50
|
+
constructor(canvas, options = {}) {
|
|
51
|
+
super(canvas);
|
|
52
|
+
this.options = options;
|
|
53
|
+
this.#canvasDomContext = mustExist(this.canvasElement.getContext("bitmaprenderer", {
|
|
54
|
+
alpha: false,
|
|
55
|
+
}), "Unable to create rendering context for DOM canvas.");
|
|
56
|
+
// Why not .transferControlToOffscreen()?
|
|
57
|
+
// It prevents the consumer from interactively resizing the DOM canvas.
|
|
58
|
+
// We prefer to just have a discrete offscreen buffer, which we can
|
|
59
|
+
// fully control. In testing, the performance impact seemed insignificant.
|
|
60
|
+
this.#canvasOffscreen = new OffscreenCanvas(this.width, this.height);
|
|
61
|
+
this.#context = mustExist(this.#canvasOffscreen.getContext("2d", {
|
|
62
|
+
alpha: false,
|
|
63
|
+
desynchronized: true,
|
|
64
|
+
willReadFrequently: this.options.supportReadBack,
|
|
65
|
+
}), "Unable to create rendering context for offscreen canvas.");
|
|
66
|
+
this.#imageData = this.#context.createImageData(this.width, this.height);
|
|
67
|
+
this.buffer = this.#imageData.data;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Recreate internal buffers in reaction to a change in our target {@linkcode !HTMLCanvasElement}.
|
|
71
|
+
*/
|
|
72
|
+
refreshCanvasNode() {
|
|
73
|
+
this.#canvasOffscreen = new OffscreenCanvas(this.width, this.height);
|
|
74
|
+
this.#context = mustExist(this.#canvasOffscreen.getContext("2d", {
|
|
75
|
+
alpha: false,
|
|
76
|
+
desynchronized: true,
|
|
77
|
+
willReadFrequently: this.options.supportReadBack,
|
|
78
|
+
}), "Unable to create rendering context for offscreen canvas.");
|
|
79
|
+
this.#imageData = this.#context.createImageData(this.width, this.height);
|
|
80
|
+
this.buffer = this.#imageData.data;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Draw FPS information onto the canvas.
|
|
84
|
+
* @param frameTimes - Durations of previous frame draws.
|
|
85
|
+
* @param frameTime - The duration of the previous frame draw.
|
|
86
|
+
* @param timeDelta - The time elapsed since the last frame.
|
|
87
|
+
*/
|
|
88
|
+
renderFpsInfo(frameTimes, frameTime, timeDelta) {
|
|
89
|
+
const maxFrameTime = frameTimes.reduce((max, frameTime) => {
|
|
90
|
+
if (max < frameTime) {
|
|
91
|
+
max = frameTime;
|
|
92
|
+
}
|
|
93
|
+
return max;
|
|
94
|
+
}, 0);
|
|
95
|
+
const sumFrameTimes = frameTimes.reduce((sum, frameTime) => sum + frameTime, 0);
|
|
96
|
+
const fpsAll = Math.round(frameTimes.length / (sumFrameTimes / 1000)).toString();
|
|
97
|
+
const fpsFrame = 1000 / frameTime;
|
|
98
|
+
const fpsDelta = 1000 / timeDelta;
|
|
99
|
+
let currentX = this.width;
|
|
100
|
+
for (const frameTime of frameTimes) {
|
|
101
|
+
let fillColor = 0x00ff00ff;
|
|
102
|
+
let width = 1;
|
|
103
|
+
if (MS_PER_FRAME_60FPS < frameTime) {
|
|
104
|
+
const quality = frameTime / maxFrameTime;
|
|
105
|
+
fillColor =
|
|
106
|
+
blend(0x00ff00ff, 0xff0000ff, Math.trunc(quality * 255)) >>> 0;
|
|
107
|
+
width = Math.round(frameTime / MS_PER_FRAME_60FPS);
|
|
108
|
+
}
|
|
109
|
+
this.context.fillStyle = `#${fillColor.toString(16).padStart(8, "0")}`;
|
|
110
|
+
this.context.globalAlpha = 255;
|
|
111
|
+
this.context.fillRect(currentX - width, this.height, width, (frameTime / Math.max(100, maxFrameTime)) * -100);
|
|
112
|
+
currentX -= width;
|
|
113
|
+
}
|
|
114
|
+
this.context.beginPath();
|
|
115
|
+
this.context.strokeStyle = "#fff";
|
|
116
|
+
this.context.moveTo(0, this.height - MS_PER_FRAME_60FPS);
|
|
117
|
+
this.context.lineTo(this.width, this.height - MS_PER_FRAME_60FPS);
|
|
118
|
+
this.context.stroke();
|
|
119
|
+
const fpsString = `${Math.round(fpsFrame).toString()}f ${fpsAll}∑ ${Math.round(fpsDelta).toString()}δ`;
|
|
120
|
+
this.context.font = "13px monospace";
|
|
121
|
+
this.context.strokeStyle = "rgba( 255, 255, 255, 1)";
|
|
122
|
+
this.context.textAlign = "right";
|
|
123
|
+
this.context.textRendering = "geometricPrecision";
|
|
124
|
+
this.context.strokeText(fpsString, this.width - 3, this.height - 3);
|
|
125
|
+
this.context.fillStyle = "#000000";
|
|
126
|
+
this.context.fillText(fpsString, this.width - 3, this.height - 3);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Draws the back buffer onto the canvas.
|
|
130
|
+
*/
|
|
131
|
+
update() {
|
|
132
|
+
this.#context.putImageData(this.#imageData, 0, 0);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Draws the offscreen canvas into the DOM canvas.
|
|
136
|
+
*/
|
|
137
|
+
render() {
|
|
138
|
+
const newFrame = this.#canvasOffscreen.transferToImageBitmap();
|
|
139
|
+
this.#canvasDomContext.transferFromImageBitmap(newFrame);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Draws a slightly transparent, black rectangle over the canvas,
|
|
143
|
+
* and then reads the result back into the buffer.
|
|
144
|
+
* @param color - The color to fade the buffer with. The alpha component of
|
|
145
|
+
* the color defines how strong the fade is. `0` is not at all, `255` makes
|
|
146
|
+
* it instantly black.
|
|
147
|
+
*/
|
|
148
|
+
fade(color = fromRGBA(0, 0, 0, 1)) {
|
|
149
|
+
this.blendWith(color);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Reads the front buffer back into the back buffer.
|
|
153
|
+
*/
|
|
154
|
+
bufferReadBack() {
|
|
155
|
+
if (!this.options.supportReadBack) {
|
|
156
|
+
throw new InvalidOperationError("To use `bufferReadBack()`, you must construct the `Canvas` with `options.supportReadBack` set to `true`.");
|
|
157
|
+
}
|
|
158
|
+
this.#imageData = this.#context.getImageData(0, 0, this.width, this.height);
|
|
159
|
+
this.buffer = this.#imageData.data;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Returns the color of a pixel in the back buffer.
|
|
163
|
+
* @param x - The X coordinate to retrieve.
|
|
164
|
+
* @param y - The X coordinate to retrieve.
|
|
165
|
+
* @returns The color of the pixel at the given local.
|
|
166
|
+
*/
|
|
167
|
+
getPixel32(x, y) {
|
|
168
|
+
const bufferOffset = (x + y * this.width) * 4;
|
|
169
|
+
return fromRGBA(this.buffer[bufferOffset + 0], this.buffer[bufferOffset + 1], this.buffer[bufferOffset + 2], this.buffer[bufferOffset + 3]);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Colors a pixel in the back buffer.
|
|
173
|
+
* @param x - The X coordinate to color.
|
|
174
|
+
* @param y - The Y coordinate to color.
|
|
175
|
+
* @param color - The color to place at the coordinate.
|
|
176
|
+
*/
|
|
177
|
+
setPixel32(x, y, color) {
|
|
178
|
+
const bufferOffset = (x + y * this.width) * 4;
|
|
179
|
+
this.buffer[bufferOffset + 0] = getR(color);
|
|
180
|
+
this.buffer[bufferOffset + 1] = getG(color);
|
|
181
|
+
this.buffer[bufferOffset + 2] = getB(color);
|
|
182
|
+
this.buffer[bufferOffset + 3] = getA(color);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Fills the entire back buffer with the given color.
|
|
186
|
+
* @param color - The color to fill the back buffer with.
|
|
187
|
+
*/
|
|
188
|
+
clearWith(color) {
|
|
189
|
+
const r = getR(color);
|
|
190
|
+
const g = getG(color);
|
|
191
|
+
const b = getB(color);
|
|
192
|
+
const a = getA(color);
|
|
193
|
+
for (let bufferOffset = 0; bufferOffset < this.width * this.height * 4; bufferOffset += 4) {
|
|
194
|
+
this.buffer[bufferOffset + 0] = r;
|
|
195
|
+
this.buffer[bufferOffset + 1] = g;
|
|
196
|
+
this.buffer[bufferOffset + 2] = b;
|
|
197
|
+
this.buffer[bufferOffset + 3] = a;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Fills the entire back buffer with the given color.
|
|
202
|
+
* @param color - The color to fill the back buffer with.
|
|
203
|
+
*/
|
|
204
|
+
blendWith(color) {
|
|
205
|
+
const r = getR(color);
|
|
206
|
+
const g = getG(color);
|
|
207
|
+
const b = getB(color);
|
|
208
|
+
const a = getA(color);
|
|
209
|
+
for (let bufferOffset = 0; bufferOffset < this.width * this.height * 4; bufferOffset += 4) {
|
|
210
|
+
this.buffer[bufferOffset + 0] =
|
|
211
|
+
(a * r + (255 - a) * this.buffer[bufferOffset + 0]) >> 8;
|
|
212
|
+
this.buffer[bufferOffset + 1] =
|
|
213
|
+
(a * g + (255 - a) * this.buffer[bufferOffset + 1]) >> 8;
|
|
214
|
+
this.buffer[bufferOffset + 2] =
|
|
215
|
+
(a * b + (255 - a) * this.buffer[bufferOffset + 2]) >> 8;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Linearly blends a new pixel with an existing color value in a canvas.
|
|
221
|
+
*
|
|
222
|
+
* As this method is often called many times in render loops, only bounds
|
|
223
|
+
* checking is applied to the given coordinates.
|
|
224
|
+
*
|
|
225
|
+
* The coordinates are **expected to already be integers**. Supplying numbers with fractions
|
|
226
|
+
* has performance implications. Ensure you're working with integers, or truncate the
|
|
227
|
+
* coordinates before passing them in.
|
|
228
|
+
*
|
|
229
|
+
* The `alpha` value is expected to be an integer in the range from `0` to `255`.
|
|
230
|
+
* `0` meaning fully transparent, `255` meaning fully opaque.
|
|
231
|
+
* @param canvas - The canvas to interact with.
|
|
232
|
+
* @param x - The X coordinate at which to place the pixel.
|
|
233
|
+
* @param y - The Y coordinate at which to place the pixel.
|
|
234
|
+
* @param color - The color of the pixel.
|
|
235
|
+
* @param alpha - The alpha value to use to blend the pixel with existing color at the location.
|
|
236
|
+
*/
|
|
237
|
+
export const putPixel32 = (canvas, x, y, color, alpha) => {
|
|
238
|
+
if (canvas.width <= x || x < 0 || canvas.height <= y || y < 0) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
const srcColor = canvas.getPixel32(x, y);
|
|
242
|
+
if (srcColor === color) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const newColor = blend(srcColor, color, alpha);
|
|
246
|
+
canvas.setPixel32(x, y, newColor);
|
|
247
|
+
};
|
|
248
|
+
/**
|
|
249
|
+
* Additively blends a new pixel with an existing color value in a canvas.
|
|
250
|
+
*
|
|
251
|
+
* As this method is often called many times in render loops, only bounds
|
|
252
|
+
* checking is applied to the given coordinates.
|
|
253
|
+
*
|
|
254
|
+
* The coordinates are **expected to already be integers**. Supplying numbers with fractions
|
|
255
|
+
* has performance implications. Ensure you're working with integers, or truncate the
|
|
256
|
+
* coordinates before passing them in.
|
|
257
|
+
*
|
|
258
|
+
* The `alpha` value is expected to be an integer in the range from `0` to `255`.
|
|
259
|
+
* `0` meaning fully transparent, `255` meaning fully opaque.
|
|
260
|
+
* @param canvas - The canvas to interact with.
|
|
261
|
+
* @param x - The X coordinate at which to place the pixel.
|
|
262
|
+
* @param y - The Y coordinate at which to place the pixel.
|
|
263
|
+
* @param color - The color of the pixel.
|
|
264
|
+
* @param alpha - The alpha value to use to blend the pixel with existing color at the location.
|
|
265
|
+
*/
|
|
266
|
+
export const putPixel32Add = (canvas, x, y, color, alpha) => {
|
|
267
|
+
if (canvas.width <= x || x < 0 || canvas.height < y || y < 0) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
const srcColor = canvas.getPixel32(x, y);
|
|
271
|
+
if (srcColor === 0xffffff || srcColor === color) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
const newColor = blendAdditive(srcColor, color, alpha);
|
|
275
|
+
canvas.setPixel32(x, y, newColor);
|
|
276
|
+
};
|
|
277
|
+
/**
|
|
278
|
+
* Subtractively blends a new pixel with an existing color value in a canvas.
|
|
279
|
+
*
|
|
280
|
+
* As this method is often called many times in render loops, only bounds
|
|
281
|
+
* checking is applied to the given coordinates.
|
|
282
|
+
*
|
|
283
|
+
* The coordinates are **expected to already be integers**. Supplying numbers with fractions
|
|
284
|
+
* has performance implications. Ensure you're working with integers, or truncate the
|
|
285
|
+
* coordinates before passing them in.
|
|
286
|
+
*
|
|
287
|
+
* The `alpha` value is expected to be an integer in the range from `0` to `255`.
|
|
288
|
+
* `0` meaning fully transparent, `255` meaning fully opaque.
|
|
289
|
+
* @param canvas - The canvas to interact with.
|
|
290
|
+
* @param x - The X coordinate at which to place the pixel.
|
|
291
|
+
* @param y - The Y coordinate at which to place the pixel.
|
|
292
|
+
* @param color - The color of the pixel.
|
|
293
|
+
* @param alpha - The alpha value to use to blend the pixel with existing color at the location.
|
|
294
|
+
*/
|
|
295
|
+
export const putPixel32Sub = (canvas, x, y, color, alpha) => {
|
|
296
|
+
if (canvas.width <= x || x < 0 || canvas.height <= y || y < 0) {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
const srcColor = canvas.getPixel32(x, y);
|
|
300
|
+
if (srcColor === 0 || srcColor === color) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
const newColor = blendSubtractive(srcColor, color, alpha);
|
|
304
|
+
canvas.setPixel32(x, y, newColor);
|
|
305
|
+
};
|
|
306
|
+
/**
|
|
307
|
+
* Linearly blends a new pixel with an existing color value in a canvas.
|
|
308
|
+
* Compared to {@linkcode putPixel32}, this function supports sub-pixel placement, but is dramatically slower.
|
|
309
|
+
* @param canvas - The canvas to interact with.
|
|
310
|
+
* @param x - The X coordinate at which to place the pixel.
|
|
311
|
+
* @param y - The Y coordinate at which to place the pixel.
|
|
312
|
+
* @param color - The color of the pixel.
|
|
313
|
+
* @param alpha - The alpha value to use to blend the pixel with existing color at the location.
|
|
314
|
+
*/
|
|
315
|
+
export const putSubPixel32 = (canvas, x, y, color, alpha) => {
|
|
316
|
+
if (canvas.width <= x || x < 0 || canvas.height <= y || y < 0) {
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
const xweight = x - Math.trunc(x);
|
|
320
|
+
const yweight = y - Math.trunc(y);
|
|
321
|
+
const xweightn = 1 - xweight;
|
|
322
|
+
const yweightn = 1 - yweight;
|
|
323
|
+
const alpha0 = xweightn * yweightn * alpha;
|
|
324
|
+
const alpha1 = xweight * yweightn * alpha;
|
|
325
|
+
const alpha2 = xweightn * yweight * alpha;
|
|
326
|
+
const alpha3 = xweight * yweight * alpha;
|
|
327
|
+
putPixel32(canvas, x + 0, y + 0, color, alpha0);
|
|
328
|
+
putPixel32(canvas, x + 1, y + 0, color, alpha1);
|
|
329
|
+
putPixel32(canvas, x + 0, y + 1, color, alpha2);
|
|
330
|
+
putPixel32(canvas, x + 1, y + 1, color, alpha3);
|
|
331
|
+
};
|
|
332
|
+
//# sourceMappingURL=canvas2d.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canvas2d.js","sourceRoot":"","sources":["../../source/graphics/canvas2d.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,OAAO,EACN,KAAK,EACL,aAAa,EACb,gBAAgB,EAChB,QAAQ,EACR,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,IAAI,GACJ,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAatD;;;;;GAKG;AACH,MAAM,OAAO,QAAS,SAAQ,MAAM;IACnC;;OAEG;IACH,iBAAiB,CAA8B;IAE/C;;OAEG;IACH,gBAAgB,CAAkB;IAElC;;OAEG;IACH,QAAQ,CAAoC;IAC5C;;;OAGG;IACH,IAAI,OAAO;QACV,OAAO,IAAI,CAAC,QAAQ,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,UAAU,CAAY;IAEtB;;OAEG;IACH,MAAM,CAAoB;IAE1B;;OAEG;IACM,OAAO,CAAqC;IAErD;;;;OAIG;IACH,YACC,MAAyB,EACzB,OAAO,GAA6B,EAAE;QAEtC,KAAK,CAAC,MAAM,CAAC,CAAC;QAEd,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,IAAI,CAAC,iBAAiB,G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G,OAAO,CAAC;IAC7B,MAAM,QAAQ,GAAG,CAAC,GAAG,OAAO,CAAC;IAE7B,MAAM,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,KAAK,CAAC;IAC3C,MAAM,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,KAAK,CAAC;IAC1C,MAAM,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,KAAK,CAAC;IAC1C,MAAM,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,KAAK,CAAC;IAEzC,UAAU,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;IAChD,UAAU,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;IAChD,UAAU,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;IAChD,UAAU,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AACjD,CAAC,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Canvas } from "./canvas.js";
|
|
2
|
+
/**
|
|
3
|
+
* A canvas to interact with WebGL.
|
|
4
|
+
*/
|
|
5
|
+
export declare class Canvas3D extends Canvas {
|
|
6
|
+
#private;
|
|
7
|
+
/**
|
|
8
|
+
* Retrieves the rendering context of the canvas.
|
|
9
|
+
* @returns The rendering context of the canvas.
|
|
10
|
+
*/
|
|
11
|
+
get context(): WebGL2RenderingContext;
|
|
12
|
+
/**
|
|
13
|
+
* Constructs a new {@linkcode Canvas3D}.
|
|
14
|
+
* @param canvas - The canvas to wrap.
|
|
15
|
+
*/
|
|
16
|
+
constructor(canvas: HTMLCanvasElement);
|
|
17
|
+
/**
|
|
18
|
+
* Recreate internal buffers in reaction to a change in our target {@linkcode !HTMLCanvasElement}.
|
|
19
|
+
*/
|
|
20
|
+
refreshCanvasNode(): void;
|
|
21
|
+
/**
|
|
22
|
+
* Does nothing.
|
|
23
|
+
*/
|
|
24
|
+
update(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Does nothing.
|
|
27
|
+
*/
|
|
28
|
+
render(): void;
|
|
29
|
+
/**
|
|
30
|
+
* Not supported.
|
|
31
|
+
* @param _color - Ignored
|
|
32
|
+
*/
|
|
33
|
+
clearWith(_color: number): void;
|
|
34
|
+
/**
|
|
35
|
+
* Not supported.
|
|
36
|
+
* @param _frameTimes - Ignored.
|
|
37
|
+
* @param _frameTime - Ignored.
|
|
38
|
+
* @param _timeDelta - Ignored.
|
|
39
|
+
*/
|
|
40
|
+
renderFpsInfo(_frameTimes: Array<number>, _frameTime: number, _timeDelta: number): void;
|
|
41
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { mustExist } from "../data/nil.js";
|
|
2
|
+
import { NotImplementedError } from "../errors/NotImplementedError.js";
|
|
3
|
+
import { Canvas } from "./canvas.js";
|
|
4
|
+
/**
|
|
5
|
+
* A canvas to interact with WebGL.
|
|
6
|
+
*/
|
|
7
|
+
export class Canvas3D extends Canvas {
|
|
8
|
+
/**
|
|
9
|
+
* The rendering context of the canvas.
|
|
10
|
+
*/
|
|
11
|
+
#context;
|
|
12
|
+
/**
|
|
13
|
+
* Retrieves the rendering context of the canvas.
|
|
14
|
+
* @returns The rendering context of the canvas.
|
|
15
|
+
*/
|
|
16
|
+
get context() {
|
|
17
|
+
return this.#context;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Constructs a new {@linkcode Canvas3D}.
|
|
21
|
+
* @param canvas - The canvas to wrap.
|
|
22
|
+
*/
|
|
23
|
+
constructor(canvas) {
|
|
24
|
+
super(canvas);
|
|
25
|
+
this.#context = mustExist(this.canvasElement.getContext("webgl2", {
|
|
26
|
+
alpha: false,
|
|
27
|
+
}), "Unable to create rendering context for offscreen canvas.");
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Recreate internal buffers in reaction to a change in our target {@linkcode !HTMLCanvasElement}.
|
|
31
|
+
*/
|
|
32
|
+
refreshCanvasNode() {
|
|
33
|
+
this.#context = mustExist(this.canvasElement.getContext("webgl2", {
|
|
34
|
+
alpha: false,
|
|
35
|
+
desynchronized: true,
|
|
36
|
+
}), "Unable to create rendering context for offscreen canvas.");
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Does nothing.
|
|
40
|
+
*/
|
|
41
|
+
update() {
|
|
42
|
+
// There is nothing to do here.
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Does nothing.
|
|
46
|
+
*/
|
|
47
|
+
render() {
|
|
48
|
+
// There is nothing to do here.
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Not supported.
|
|
52
|
+
* @param _color - Ignored
|
|
53
|
+
*/
|
|
54
|
+
clearWith(_color) {
|
|
55
|
+
throw new NotImplementedError();
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Not supported.
|
|
59
|
+
* @param _frameTimes - Ignored.
|
|
60
|
+
* @param _frameTime - Ignored.
|
|
61
|
+
* @param _timeDelta - Ignored.
|
|
62
|
+
*/
|
|
63
|
+
renderFpsInfo(_frameTimes, _frameTime, _timeDelta) {
|
|
64
|
+
throw new NotImplementedError();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=canvas3d.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canvas3d.js","sourceRoot":"","sources":["../../source/graphics/canvas3d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;GAEG;AACH,MAAM,OAAO,QAAS,SAAQ,MAAM;IACnC;;OAEG;IACH,QAAQ,CAAyB;IACjC;;;OAGG;IACH,IAAI,OAAO;QACV,OAAO,IAAI,CAAC,QAAQ,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,YAAY,MAAyB;QACpC,KAAK,CAAC,MAAM,CAAC,CAAC;QAEd,IAAI,CAAC,QAAQ,GAAG,SAAS,CACxB,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,QAAQ,EAAE;YACvC,KAAK,EAAE,KAAK;SACZ,CAAC,EACF,0DAA0D,CAC1D,CAAC;IACH,CAAC;IAED;;OAEG;IACH,iBAAiB;QAChB,IAAI,CAAC,QAAQ,GAAG,SAAS,CACxB,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,QAAQ,EAAE;YACvC,KAAK,EAAE,KAAK;YACZ,cAAc,EAAE,IAAI;SACpB,CAAC,EACF,0DAA0D,CAC1D,CAAC;IACH,CAAC;IAED;;OAEG;IACH,MAAM;QACL,+BAA+B;IAChC,CAAC;IACD;;OAEG;IACH,MAAM;QACL,+BAA+B;IAChC,CAAC;IAED;;;OAGG;IACH,SAAS,CAAC,MAAc;QACvB,MAAM,IAAI,mBAAmB,EAAE,CAAC;IACjC,CAAC;IAED;;;;;OAKG;IACH,aAAa,CACZ,WAA0B,EAC1B,UAAkB,EAClB,UAAkB;QAElB,MAAM,IAAI,mBAAmB,EAAE,CAAC;IACjC,CAAC;CACD"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* input: h in [0,360] and s,v in [0,1] - output: r,g,b in [0,1]
|
|
3
|
+
* @see https://stackoverflow.com/a/54024653
|
|
4
|
+
*/
|
|
5
|
+
export declare const hsv2rgb: (h: number, s: number, v: number) => number[];
|
|
6
|
+
/**
|
|
7
|
+
* input: h in [0,360] and s,l in [0,1] - output: r,g,b in [0,1]
|
|
8
|
+
* @see https://stackoverflow.com/a/54014428
|
|
9
|
+
*/
|
|
10
|
+
export declare const hsl2rgb: (h: number, s: number, l: number) => number[];
|
|
11
|
+
/**
|
|
12
|
+
* input: r,g,b in [0,1], out: h in [0,360) and s,v in [0,1]
|
|
13
|
+
* @see https://stackoverflow.com/a/54070620
|
|
14
|
+
*/
|
|
15
|
+
export declare const rgb2hsv: (r: number, g: number, b: number) => number[];
|
|
16
|
+
/**
|
|
17
|
+
* in: r,g,b in [0,1], out: h in [0,360) and s,l in [0,1]
|
|
18
|
+
* @see https://stackoverflow.com/a/54071699
|
|
19
|
+
*/
|
|
20
|
+
export declare const rgb2hsl: (r: number, g: number, b: number) => number[];
|
|
21
|
+
export declare const hsl2hsv: (h: number, s: number, l: number, v?: number) => number[];
|
|
22
|
+
export declare const hsv2hsl: (h: number, s: number, v: number, l?: number, m?: number) => number[];
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* input: h in [0,360] and s,v in [0,1] - output: r,g,b in [0,1]
|
|
3
|
+
* @see https://stackoverflow.com/a/54024653
|
|
4
|
+
*/
|
|
5
|
+
export const hsv2rgb = (h, s, v) => {
|
|
6
|
+
const f = (n, k = (n + h / 60) % 6) => v - v * s * Math.max(Math.min(k, 4 - k, 1), 0);
|
|
7
|
+
return [f(5), f(3), f(1)];
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* input: h in [0,360] and s,l in [0,1] - output: r,g,b in [0,1]
|
|
11
|
+
* @see https://stackoverflow.com/a/54014428
|
|
12
|
+
*/
|
|
13
|
+
export const hsl2rgb = (h, s, l) => {
|
|
14
|
+
const a = s * Math.min(l, 1 - l);
|
|
15
|
+
const f = (n, k = (n + h / 30) % 12) => l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
|
|
16
|
+
return [f(0), f(8), f(4)];
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* input: r,g,b in [0,1], out: h in [0,360) and s,v in [0,1]
|
|
20
|
+
* @see https://stackoverflow.com/a/54070620
|
|
21
|
+
*/
|
|
22
|
+
export const rgb2hsv = (r, g, b) => {
|
|
23
|
+
const v = Math.max(r, g, b), c = v - Math.min(r, g, b);
|
|
24
|
+
const h = c && (v === r ? (g - b) / c : v === g ? 2 + (b - r) / c : 4 + (r - g) / c);
|
|
25
|
+
return [60 * (h < 0 ? h + 6 : h), v && c / v, v];
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* in: r,g,b in [0,1], out: h in [0,360) and s,l in [0,1]
|
|
29
|
+
* @see https://stackoverflow.com/a/54071699
|
|
30
|
+
*/
|
|
31
|
+
export const rgb2hsl = (r, g, b) => {
|
|
32
|
+
const v = Math.max(r, g, b), c = v - Math.min(r, g, b), f = 1 - Math.abs(v + v - c - 1);
|
|
33
|
+
const h = c && (v === r ? (g - b) / c : v === g ? 2 + (b - r) / c : 4 + (r - g) / c);
|
|
34
|
+
return [60 * (h < 0 ? h + 6 : h), f ? c / f : 0, (v + v - c) / 2];
|
|
35
|
+
};
|
|
36
|
+
export const hsl2hsv = (h, s, l, v = s * Math.min(l, 1 - l) + l) => [h, v ? 2 - (2 * l) / v : 0, v];
|
|
37
|
+
export const hsv2hsl = (h, s, v, l = v - (v * s) / 2, m = Math.min(l, 1 - l)) => [h, m ? (v - l) / m : 0, l];
|
|
38
|
+
//# sourceMappingURL=color.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color.js","sourceRoot":"","sources":["../../source/graphics/color.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,CAAS,EAAE,CAAS,EAAE,CAAS,EAAE,EAAE;IAC1D,MAAM,CAAC,GAAG,CAAC,CAAS,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,CAC7C,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,E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AC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AACnE,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,OAAO,GAAG,CACtB,CAAS,EACT,CAAS,EACT,CAAS,EACT,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,EAC7B,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAErC,MAAM,CAAC,MAAM,OAAO,GAAG,CACtB,CAAS,EACT,CAAS,EACT,CAAS,EACT,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,EACnB,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,EACrB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The golden ratio.
|
|
3
|
+
* @see {@link https://en.wikipedia.org/wiki/Golden_ratio}
|
|
4
|
+
*/
|
|
5
|
+
export declare const GOLDEN_RATIO = 1.618033988749;
|
|
6
|
+
/**
|
|
7
|
+
* Constrains a color component value to single-byte range (`0`-`255`).
|
|
8
|
+
* @param c - A color component value.
|
|
9
|
+
* @returns The input value constrained into single-byte range.
|
|
10
|
+
*/
|
|
11
|
+
export declare const safeRGBComponent: (c: number) => number;
|
|
12
|
+
/**
|
|
13
|
+
* Constructs a 32bit integer value that represents an RGBA color value.
|
|
14
|
+
* @param r - The R component.
|
|
15
|
+
* @param g - The G component.
|
|
16
|
+
* @param b - The B component.
|
|
17
|
+
* @param a - The A component.
|
|
18
|
+
* @returns The constructed color value.
|
|
19
|
+
*/
|
|
20
|
+
export declare const fromRGBA: (r: number, g: number, b: number, a: number) => number;
|
|
21
|
+
/**
|
|
22
|
+
* Constructs a 32bit integer value that represents an RGBA color value.
|
|
23
|
+
* The A component is fixed to `255`
|
|
24
|
+
* @param r - The R component.
|
|
25
|
+
* @param g - The G component.
|
|
26
|
+
* @param b - The B component.
|
|
27
|
+
* @returns The constructed color value.
|
|
28
|
+
*/
|
|
29
|
+
export declare const fromRGB: (r: number, g: number, b: number) => number;
|
|
30
|
+
/**
|
|
31
|
+
* Extracts the R component from a color value.
|
|
32
|
+
* @param color - The color value.
|
|
33
|
+
* @returns The R component of the color value.
|
|
34
|
+
*/
|
|
35
|
+
export declare const getR: (color: number) => number;
|
|
36
|
+
/**
|
|
37
|
+
* Extracts the G component from a color value.
|
|
38
|
+
* @param color - The color value.
|
|
39
|
+
* @returns The G component of the color value.
|
|
40
|
+
*/
|
|
41
|
+
export declare const getG: (color: number) => number;
|
|
42
|
+
/**
|
|
43
|
+
* Extracts the B component from a color value.
|
|
44
|
+
* @param color - The color value.
|
|
45
|
+
* @returns The B component of the color value.
|
|
46
|
+
*/
|
|
47
|
+
export declare const getB: (color: number) => number;
|
|
48
|
+
/**
|
|
49
|
+
* Extracts the A component from a color value.
|
|
50
|
+
* @param color - The color value.
|
|
51
|
+
* @returns The A component of the color value.
|
|
52
|
+
*/
|
|
53
|
+
export declare const getA: (color: number) => number;
|
|
54
|
+
/**
|
|
55
|
+
* Returns a new color that is a blend between a source and a destination
|
|
56
|
+
* color linerally. The alpha component in these colors is ignored. Instead, the provided
|
|
57
|
+
* `alpha` value is used to blend between the two colors.
|
|
58
|
+
* @param src - The source color.
|
|
59
|
+
* @param dst - The destination color.
|
|
60
|
+
* @param alpha - The alpha value to use for blending.
|
|
61
|
+
* @returns The blended color.
|
|
62
|
+
*/
|
|
63
|
+
export declare const blend: (src: number, dst: number, alpha: number) => number;
|
|
64
|
+
/**
|
|
65
|
+
* Returns a new color that is a blend between a source and a destination
|
|
66
|
+
* color additively. The alpha component in these colors is ignored. Instead, the provided
|
|
67
|
+
* `alpha` value is used to blend between the two colors.
|
|
68
|
+
* @param src - The source color.
|
|
69
|
+
* @param dst - The destination color.
|
|
70
|
+
* @param alpha - The alpha value to use for blending.
|
|
71
|
+
* @returns The blended color.
|
|
72
|
+
*/
|
|
73
|
+
export declare const blendAdditive: (src: number, dst: number, alpha: number) => number;
|
|
74
|
+
/**
|
|
75
|
+
* Returns a new color that is a blend between a source and a destination
|
|
76
|
+
* color subtractively. The alpha component in these colors is ignored. Instead, the provided
|
|
77
|
+
* `alpha` value is used to blend between the two colors.
|
|
78
|
+
* @param src - The source color.
|
|
79
|
+
* @param dst - The destination color.
|
|
80
|
+
* @param alpha - The alpha value to use for blending.
|
|
81
|
+
* @returns The blended color.
|
|
82
|
+
*/
|
|
83
|
+
export declare const blendSubtractive: (src: number, dst: number, alpha: number) => number;
|
|
84
|
+
/**
|
|
85
|
+
* Converts a color value to grayscale.
|
|
86
|
+
* @param color - The color to convert.
|
|
87
|
+
* @returns The grayscale value appropriate for the color.
|
|
88
|
+
*/
|
|
89
|
+
export declare const toGrayScale: (color: number) => number;
|