@oliversalzburg/js-utils 0.0.28-dev.4 → 0.0.28-dev.6
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/graphics/canvas-sandbox.d.ts +1 -1
- package/graphics/canvas-sandbox.js +6 -10
- package/graphics/canvas-sandbox.js.map +1 -1
- package/graphics/canvas.d.ts +4 -4
- package/graphics/canvas.js +6 -6
- package/graphics/canvas.js.map +1 -1
- package/graphics/canvas2d-headless.d.ts +87 -0
- package/graphics/canvas2d-headless.js +194 -0
- package/graphics/canvas2d-headless.js.map +1 -0
- package/graphics/canvas2d.d.ts +13 -12
- package/graphics/canvas2d.js +13 -13
- package/graphics/canvas2d.js.map +1 -1
- package/graphics/canvas3d.js +2 -2
- package/graphics/canvas3d.js.map +1 -1
- package/graphics/index.d.ts +1 -0
- package/graphics/index.js +1 -0
- package/graphics/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -51,13 +51,15 @@ export const CANVAS_SANDBOX_DEFAULT_CSS = /* PURE */ css `
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
#main {
|
|
54
|
-
display:
|
|
54
|
+
display: flex;
|
|
55
55
|
position: absolute;
|
|
56
56
|
margin: auto;
|
|
57
57
|
top: 0;
|
|
58
58
|
left: 0;
|
|
59
59
|
right: 0;
|
|
60
60
|
bottom: 0;
|
|
61
|
+
justify-content: center;
|
|
62
|
+
align-items: center;
|
|
61
63
|
|
|
62
64
|
filter: drop-shadow(10px 10px 4px rgba(0, 0, 0, 0.5));
|
|
63
65
|
transition: all 1s;
|
|
@@ -270,12 +272,8 @@ export class CanvasSandbox {
|
|
|
270
272
|
case 13:
|
|
271
273
|
// Enter
|
|
272
274
|
nextPalette();
|
|
273
|
-
this.#reconfigureApplication(
|
|
274
|
-
|
|
275
|
-
});
|
|
276
|
-
this.application.reconfigure(this.canvas, {
|
|
277
|
-
seed: this.application.random.next().toString(),
|
|
278
|
-
});
|
|
275
|
+
this.#reconfigureApplication();
|
|
276
|
+
this.application.reconfigure(this.canvas);
|
|
279
277
|
this.application.start();
|
|
280
278
|
break;
|
|
281
279
|
case 32:
|
|
@@ -310,9 +308,7 @@ export class CanvasSandbox {
|
|
|
310
308
|
}
|
|
311
309
|
// Run the next variation of the application.
|
|
312
310
|
nextPalette();
|
|
313
|
-
this.#reconfigureApplication(
|
|
314
|
-
seed: this.application.random.next().toString(),
|
|
315
|
-
});
|
|
311
|
+
this.#reconfigureApplication();
|
|
316
312
|
event.preventDefault();
|
|
317
313
|
});
|
|
318
314
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canvas-sandbox.js","sourceRoot":"","sources":["../../source/graphics/canvas-sandbox.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AAG5D,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,KAA2B,EAAU,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAE3E;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,UAAU,CAAC,GAAG,CAAA
|
|
1
|
+
{"version":3,"file":"canvas-sandbox.js","sourceRoot":"","sources":["../../source/graphics/canvas-sandbox.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AAG5D,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C;;;;;;;;;;;;GAY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EG;IACH,UAAU;QACR,IAAI,CAAC,uBAAuB,CAAC;YAC3B,QAAQ,EAAE,IAAI;SACiB,CAAC,CAAC;QACnC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QACxC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,WAAW;QACT,IAAI,CAAC,uBAAuB,CAAC;YAC3B,QAAQ,EAAE,KAAK;SACgB,CAAC,CAAC;QACnC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QACzC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAC7C,CAAC;CACF"}
|
package/graphics/canvas.d.ts
CHANGED
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
*/
|
|
12
12
|
export declare abstract class Canvas {
|
|
13
13
|
/**
|
|
14
|
-
* The
|
|
14
|
+
* The canvas element we're interacting with.
|
|
15
15
|
*/
|
|
16
|
-
readonly
|
|
16
|
+
readonly canvasElement: HTMLCanvasElement | OffscreenCanvas;
|
|
17
17
|
/**
|
|
18
18
|
* Retrieves the width of the canvas.
|
|
19
19
|
* @returns The width of the canvas.
|
|
@@ -26,9 +26,9 @@ export declare abstract class Canvas {
|
|
|
26
26
|
get height(): number;
|
|
27
27
|
/**
|
|
28
28
|
* Constructs a new canvas helper.
|
|
29
|
-
* @param canvas - The canvas node
|
|
29
|
+
* @param canvas - The canvas node to wrap.
|
|
30
30
|
*/
|
|
31
|
-
constructor(canvas: HTMLCanvasElement);
|
|
31
|
+
constructor(canvas: HTMLCanvasElement | OffscreenCanvas);
|
|
32
32
|
/**
|
|
33
33
|
* Rebuild rendering pipeline in reaction to a change in the canvas.
|
|
34
34
|
* Usually, when the canvas was resized.
|
package/graphics/canvas.js
CHANGED
|
@@ -10,29 +10,29 @@
|
|
|
10
10
|
*/
|
|
11
11
|
export class Canvas {
|
|
12
12
|
/**
|
|
13
|
-
* The
|
|
13
|
+
* The canvas element we're interacting with.
|
|
14
14
|
*/
|
|
15
|
-
|
|
15
|
+
canvasElement;
|
|
16
16
|
/**
|
|
17
17
|
* Retrieves the width of the canvas.
|
|
18
18
|
* @returns The width of the canvas.
|
|
19
19
|
*/
|
|
20
20
|
get width() {
|
|
21
|
-
return this.
|
|
21
|
+
return this.canvasElement.width;
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
24
|
* Retrieves the height of the canvas.
|
|
25
25
|
* @returns The height of the canvas.
|
|
26
26
|
*/
|
|
27
27
|
get height() {
|
|
28
|
-
return this.
|
|
28
|
+
return this.canvasElement.height;
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
31
|
* Constructs a new canvas helper.
|
|
32
|
-
* @param canvas - The canvas node
|
|
32
|
+
* @param canvas - The canvas node to wrap.
|
|
33
33
|
*/
|
|
34
34
|
constructor(canvas) {
|
|
35
|
-
this.
|
|
35
|
+
this.canvasElement = canvas;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
//# sourceMappingURL=canvas.js.map
|
package/graphics/canvas.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canvas.js","sourceRoot":"","sources":["../../source/graphics/canvas.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,OAAgB,MAAM;IAC1B;;OAEG;IACM,
|
|
1
|
+
{"version":3,"file":"canvas.js","sourceRoot":"","sources":["../../source/graphics/canvas.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,OAAgB,MAAM;IAC1B;;OAEG;IACM,aAAa,CAAsC;IAE5D;;;OAGG;IACH,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC;IAClC,CAAC;IAED;;;OAGG;IACH,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC;IACnC,CAAC;IAED;;;OAGG;IACH,YAAY,MAA2C;QACrD,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC;IAC9B,CAAC;CAiCF"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/// <reference types="@types/web" />
|
|
2
|
+
import { Canvas } from "./canvas.js";
|
|
3
|
+
import { Canvas2DOptions } from "./canvas2d.js";
|
|
4
|
+
/**
|
|
5
|
+
* An offscreen canvas.
|
|
6
|
+
*
|
|
7
|
+
* This isn't created from a DOM node, but from an existing {@linkcode !OffscreenCanvas}.
|
|
8
|
+
* @group Graphics
|
|
9
|
+
*/
|
|
10
|
+
export declare class Canvas2DHeadless extends Canvas {
|
|
11
|
+
#private;
|
|
12
|
+
/**
|
|
13
|
+
* Retrieves the rendering context of the canvas.
|
|
14
|
+
* @returns The rendering context of the canvas.
|
|
15
|
+
*/
|
|
16
|
+
get context(): OffscreenCanvasRenderingContext2D;
|
|
17
|
+
/**
|
|
18
|
+
* Our back buffer.
|
|
19
|
+
*/
|
|
20
|
+
buffer: Uint8ClampedArray;
|
|
21
|
+
/**
|
|
22
|
+
* The configuration that was used for this canvas.
|
|
23
|
+
*/
|
|
24
|
+
readonly options: Readonly<Partial<Canvas2DOptions>>;
|
|
25
|
+
/**
|
|
26
|
+
* Constructs a new {@linkcode Canvas2DHeadless}.
|
|
27
|
+
* @param canvas - The offscreen canvas we're drawing to.
|
|
28
|
+
* @param context - The rendering context to use for the canvas.
|
|
29
|
+
* @param options - The configuration for this canvas.
|
|
30
|
+
*/
|
|
31
|
+
constructor(canvas: OffscreenCanvas, context: OffscreenCanvasRenderingContext2D, options?: Partial<Canvas2DOptions>);
|
|
32
|
+
/**
|
|
33
|
+
* Recreate internal buffers in reaction to a change in our target {@linkcode !OffscreenCanvas}.
|
|
34
|
+
*/
|
|
35
|
+
refreshCanvasNode(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Draw FPS information onto the canvas.
|
|
38
|
+
* @param frameTimes - Durations of previous frame draws.
|
|
39
|
+
* @param frameTime - The duration of the previous frame draw.
|
|
40
|
+
* @param timeDelta - The time elapsed since the last frame.
|
|
41
|
+
*/
|
|
42
|
+
renderFpsInfo(frameTimes: Array<number>, frameTime: number, timeDelta: number): void;
|
|
43
|
+
/**
|
|
44
|
+
* Draws the back buffer onto the canvas.
|
|
45
|
+
*/
|
|
46
|
+
update(): void;
|
|
47
|
+
/**
|
|
48
|
+
* Draws the offscreen canvas into the DOM canvas.
|
|
49
|
+
*/
|
|
50
|
+
render(): void;
|
|
51
|
+
/**
|
|
52
|
+
* Draws a slightly transparent, black rectangle over the canvas,
|
|
53
|
+
* and then reads the result back into the buffer.
|
|
54
|
+
* @param color - The color to fade the buffer with. The alpha component of
|
|
55
|
+
* the color defines how strong the fade is. `0` is not at all, `255` makes
|
|
56
|
+
* it instantly black.
|
|
57
|
+
*/
|
|
58
|
+
fade(color?: number): void;
|
|
59
|
+
/**
|
|
60
|
+
* Reads the front buffer back into the back buffer.
|
|
61
|
+
*/
|
|
62
|
+
bufferReadBack(): void;
|
|
63
|
+
/**
|
|
64
|
+
* Returns the color of a pixel in the back buffer.
|
|
65
|
+
* @param x - The X coordinate to retrieve.
|
|
66
|
+
* @param y - The X coordinate to retrieve.
|
|
67
|
+
* @returns The color of the pixel at the given local.
|
|
68
|
+
*/
|
|
69
|
+
getPixel32(x: number, y: number): number;
|
|
70
|
+
/**
|
|
71
|
+
* Colors a pixel in the back buffer.
|
|
72
|
+
* @param x - The X coordinate to color.
|
|
73
|
+
* @param y - The Y coordinate to color.
|
|
74
|
+
* @param color - The color to place at the coordinate.
|
|
75
|
+
*/
|
|
76
|
+
setPixel32(x: number, y: number, color: number): void;
|
|
77
|
+
/**
|
|
78
|
+
* Fills the entire back buffer with the given color.
|
|
79
|
+
* @param color - The color to fill the back buffer with.
|
|
80
|
+
*/
|
|
81
|
+
clearWith(color: number): void;
|
|
82
|
+
/**
|
|
83
|
+
* Fills the entire back buffer with the given color.
|
|
84
|
+
* @param color - The color to fill the back buffer with.
|
|
85
|
+
*/
|
|
86
|
+
blendWith(color: number): void;
|
|
87
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { InvalidOperationError } from "../error/InvalidOperationError.js";
|
|
2
|
+
import { mustExist } from "../nil.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
|
+
* @group Graphics
|
|
11
|
+
*/
|
|
12
|
+
export class Canvas2DHeadless extends Canvas {
|
|
13
|
+
/**
|
|
14
|
+
* The 2D rendering context we're using to draw to the canvas.
|
|
15
|
+
*/
|
|
16
|
+
#context;
|
|
17
|
+
/**
|
|
18
|
+
* Retrieves the rendering context of the canvas.
|
|
19
|
+
* @returns The rendering context of the canvas.
|
|
20
|
+
*/
|
|
21
|
+
get context() {
|
|
22
|
+
return this.#context;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The {@linkcode !ImageData} object in our offscreen canvas. We usually interact with its
|
|
26
|
+
* {@linkcode Canvas2D.buffer buffer} directly.
|
|
27
|
+
*/
|
|
28
|
+
#imageData;
|
|
29
|
+
/**
|
|
30
|
+
* Our back buffer.
|
|
31
|
+
*/
|
|
32
|
+
buffer;
|
|
33
|
+
/**
|
|
34
|
+
* The configuration that was used for this canvas.
|
|
35
|
+
*/
|
|
36
|
+
options;
|
|
37
|
+
/**
|
|
38
|
+
* Constructs a new {@linkcode Canvas2DHeadless}.
|
|
39
|
+
* @param canvas - The offscreen canvas we're drawing to.
|
|
40
|
+
* @param context - The rendering context to use for the canvas.
|
|
41
|
+
* @param options - The configuration for this canvas.
|
|
42
|
+
*/
|
|
43
|
+
constructor(canvas, context, options = {}) {
|
|
44
|
+
super(canvas);
|
|
45
|
+
this.options = options;
|
|
46
|
+
this.#context = context;
|
|
47
|
+
this.#imageData = this.#context.createImageData(this.width, this.height);
|
|
48
|
+
this.buffer = this.#imageData.data;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Recreate internal buffers in reaction to a change in our target {@linkcode !OffscreenCanvas}.
|
|
52
|
+
*/
|
|
53
|
+
refreshCanvasNode() {
|
|
54
|
+
this.#context = mustExist(this.canvasElement.getContext("2d", {
|
|
55
|
+
alpha: false,
|
|
56
|
+
desynchronized: true,
|
|
57
|
+
willReadFrequently: this.options.supportReadBack,
|
|
58
|
+
}), "Unable to create rendering context for offscreen canvas.");
|
|
59
|
+
this.#imageData = this.#context.createImageData(this.width, this.height);
|
|
60
|
+
this.buffer = this.#imageData.data;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Draw FPS information onto the canvas.
|
|
64
|
+
* @param frameTimes - Durations of previous frame draws.
|
|
65
|
+
* @param frameTime - The duration of the previous frame draw.
|
|
66
|
+
* @param timeDelta - The time elapsed since the last frame.
|
|
67
|
+
*/
|
|
68
|
+
renderFpsInfo(frameTimes, frameTime, timeDelta) {
|
|
69
|
+
const maxFrameTime = frameTimes.reduce((max, frameTime) => {
|
|
70
|
+
if (max < frameTime) {
|
|
71
|
+
max = frameTime;
|
|
72
|
+
}
|
|
73
|
+
return max;
|
|
74
|
+
}, 0);
|
|
75
|
+
const sumFrameTimes = frameTimes.reduce((sum, frameTime) => sum + frameTime, 0);
|
|
76
|
+
const fpsAll = Math.round(frameTimes.length / (sumFrameTimes / 1000)).toString();
|
|
77
|
+
const fpsFrame = 1000 / frameTime;
|
|
78
|
+
const fpsDelta = 1000 / timeDelta;
|
|
79
|
+
let currentX = this.width;
|
|
80
|
+
for (const frameTime of frameTimes) {
|
|
81
|
+
let fillColor = 0x00ff00ff;
|
|
82
|
+
let width = 1;
|
|
83
|
+
if (MS_PER_FRAME_60FPS < frameTime) {
|
|
84
|
+
const quality = frameTime / maxFrameTime;
|
|
85
|
+
fillColor = 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)}f ${fpsAll}∑ ${Math.round(fpsDelta)}δ`;
|
|
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] = (a * r + (255 - a) * this.buffer[bufferOffset + 0]) >> 8;
|
|
189
|
+
this.buffer[bufferOffset + 1] = (a * g + (255 - a) * this.buffer[bufferOffset + 1]) >> 8;
|
|
190
|
+
this.buffer[bufferOffset + 2] = (a * b + (255 - a) * this.buffer[bufferOffset + 2]) >> 8;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
//# 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,qBAAqB,EAAE,MAA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CAAC;QAC3F,CAAC;IACH,CAAC;CACF"}
|
package/graphics/canvas2d.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="@types/web" />
|
|
2
2
|
import { Canvas } from "./canvas.js";
|
|
3
|
+
import { Canvas2DHeadless } from "./canvas2d-headless.js";
|
|
3
4
|
/**
|
|
4
5
|
* Construction options for a {@linkcode Canvas2D}.
|
|
5
6
|
* @group Graphics
|
|
@@ -96,7 +97,7 @@ export declare class Canvas2D extends Canvas {
|
|
|
96
97
|
blendWith(color: number): void;
|
|
97
98
|
}
|
|
98
99
|
/**
|
|
99
|
-
* Linearly blends a new pixel with an existing color value in a
|
|
100
|
+
* Linearly blends a new pixel with an existing color value in a canvas.
|
|
100
101
|
*
|
|
101
102
|
* As this method is often called many times in render loops, only bounds
|
|
102
103
|
* checking is applied to the given coordinates.
|
|
@@ -107,16 +108,16 @@ export declare class Canvas2D extends Canvas {
|
|
|
107
108
|
*
|
|
108
109
|
* The `alpha` value is expected to be an integer in the range from `0` to `255`.
|
|
109
110
|
* `0` meaning fully transparent, `255` meaning fully opaque.
|
|
110
|
-
* @param canvas - The
|
|
111
|
+
* @param canvas - The canvas to interact with.
|
|
111
112
|
* @param x - The X coordinate at which to place the pixel.
|
|
112
113
|
* @param y - The Y coordinate at which to place the pixel.
|
|
113
114
|
* @param color - The color of the pixel.
|
|
114
115
|
* @param alpha - The alpha value to use to blend the pixel with existing color at the location.
|
|
115
116
|
* @group Graphics
|
|
116
117
|
*/
|
|
117
|
-
export declare const putPixel32: (canvas: Canvas2D, x: number, y: number, color: number, alpha: number) => void;
|
|
118
|
+
export declare const putPixel32: (canvas: Canvas2D | Canvas2DHeadless, x: number, y: number, color: number, alpha: number) => void;
|
|
118
119
|
/**
|
|
119
|
-
* Additively blends a new pixel with an existing color value in a
|
|
120
|
+
* Additively blends a new pixel with an existing color value in a canvas.
|
|
120
121
|
*
|
|
121
122
|
* As this method is often called many times in render loops, only bounds
|
|
122
123
|
* checking is applied to the given coordinates.
|
|
@@ -127,16 +128,16 @@ export declare const putPixel32: (canvas: Canvas2D, x: number, y: number, color:
|
|
|
127
128
|
*
|
|
128
129
|
* The `alpha` value is expected to be an integer in the range from `0` to `255`.
|
|
129
130
|
* `0` meaning fully transparent, `255` meaning fully opaque.
|
|
130
|
-
* @param canvas - The
|
|
131
|
+
* @param canvas - The canvas to interact with.
|
|
131
132
|
* @param x - The X coordinate at which to place the pixel.
|
|
132
133
|
* @param y - The Y coordinate at which to place the pixel.
|
|
133
134
|
* @param color - The color of the pixel.
|
|
134
135
|
* @param alpha - The alpha value to use to blend the pixel with existing color at the location.
|
|
135
136
|
* @group Graphics
|
|
136
137
|
*/
|
|
137
|
-
export declare const putPixel32Add: (canvas: Canvas2D, x: number, y: number, color: number, alpha: number) => void;
|
|
138
|
+
export declare const putPixel32Add: (canvas: Canvas2D | Canvas2DHeadless, x: number, y: number, color: number, alpha: number) => void;
|
|
138
139
|
/**
|
|
139
|
-
* Subtractively blends a new pixel with an existing color value in a
|
|
140
|
+
* Subtractively blends a new pixel with an existing color value in a canvas.
|
|
140
141
|
*
|
|
141
142
|
* As this method is often called many times in render loops, only bounds
|
|
142
143
|
* checking is applied to the given coordinates.
|
|
@@ -147,22 +148,22 @@ export declare const putPixel32Add: (canvas: Canvas2D, x: number, y: number, col
|
|
|
147
148
|
*
|
|
148
149
|
* The `alpha` value is expected to be an integer in the range from `0` to `255`.
|
|
149
150
|
* `0` meaning fully transparent, `255` meaning fully opaque.
|
|
150
|
-
* @param canvas - The
|
|
151
|
+
* @param canvas - The canvas to interact with.
|
|
151
152
|
* @param x - The X coordinate at which to place the pixel.
|
|
152
153
|
* @param y - The Y coordinate at which to place the pixel.
|
|
153
154
|
* @param color - The color of the pixel.
|
|
154
155
|
* @param alpha - The alpha value to use to blend the pixel with existing color at the location.
|
|
155
156
|
* @group Graphics
|
|
156
157
|
*/
|
|
157
|
-
export declare const putPixel32Sub: (canvas: Canvas2D, x: number, y: number, color: number, alpha: number) => void;
|
|
158
|
+
export declare const putPixel32Sub: (canvas: Canvas2D | Canvas2DHeadless, x: number, y: number, color: number, alpha: number) => void;
|
|
158
159
|
/**
|
|
159
|
-
* Linearly blends a new pixel with an existing color value in a
|
|
160
|
+
* Linearly blends a new pixel with an existing color value in a canvas.
|
|
160
161
|
* Compared to {@linkcode putPixel32}, this function supports sub-pixel placement, but is dramatically slower.
|
|
161
|
-
* @param canvas - The
|
|
162
|
+
* @param canvas - The canvas to interact with.
|
|
162
163
|
* @param x - The X coordinate at which to place the pixel.
|
|
163
164
|
* @param y - The Y coordinate at which to place the pixel.
|
|
164
165
|
* @param color - The color of the pixel.
|
|
165
166
|
* @param alpha - The alpha value to use to blend the pixel with existing color at the location.
|
|
166
167
|
* @group Graphics
|
|
167
168
|
*/
|
|
168
|
-
export declare const putSubPixel32: (canvas: Canvas2D, x: number, y: number, color: number, alpha: number) => void;
|
|
169
|
+
export declare const putSubPixel32: (canvas: Canvas2D | Canvas2DHeadless, x: number, y: number, color: number, alpha: number) => void;
|
package/graphics/canvas2d.js
CHANGED
|
@@ -51,7 +51,7 @@ export class Canvas2D extends Canvas {
|
|
|
51
51
|
constructor(canvas, options = {}) {
|
|
52
52
|
super(canvas);
|
|
53
53
|
this.options = options;
|
|
54
|
-
this.#canvasDomContext = mustExist(this.
|
|
54
|
+
this.#canvasDomContext = mustExist(this.canvasElement.getContext("bitmaprenderer", {
|
|
55
55
|
alpha: false,
|
|
56
56
|
}), "Unable to create rendering context for DOM canvas.");
|
|
57
57
|
// Why not .transferControlToOffscreen()?
|
|
@@ -214,7 +214,7 @@ export class Canvas2D extends Canvas {
|
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
/**
|
|
217
|
-
* Linearly blends a new pixel with an existing color value in a
|
|
217
|
+
* Linearly blends a new pixel with an existing color value in a canvas.
|
|
218
218
|
*
|
|
219
219
|
* As this method is often called many times in render loops, only bounds
|
|
220
220
|
* checking is applied to the given coordinates.
|
|
@@ -225,7 +225,7 @@ export class Canvas2D extends Canvas {
|
|
|
225
225
|
*
|
|
226
226
|
* The `alpha` value is expected to be an integer in the range from `0` to `255`.
|
|
227
227
|
* `0` meaning fully transparent, `255` meaning fully opaque.
|
|
228
|
-
* @param canvas - The
|
|
228
|
+
* @param canvas - The canvas to interact with.
|
|
229
229
|
* @param x - The X coordinate at which to place the pixel.
|
|
230
230
|
* @param y - The Y coordinate at which to place the pixel.
|
|
231
231
|
* @param color - The color of the pixel.
|
|
@@ -233,7 +233,7 @@ export class Canvas2D extends Canvas {
|
|
|
233
233
|
* @group Graphics
|
|
234
234
|
*/
|
|
235
235
|
export const putPixel32 = (canvas, x, y, color, alpha) => {
|
|
236
|
-
if (canvas.width
|
|
236
|
+
if (canvas.width <= x || x < 0 || canvas.height <= y || y < 0) {
|
|
237
237
|
return;
|
|
238
238
|
}
|
|
239
239
|
const srcColor = canvas.getPixel32(x, y);
|
|
@@ -241,7 +241,7 @@ export const putPixel32 = (canvas, x, y, color, alpha) => {
|
|
|
241
241
|
canvas.setPixel32(x, y, newColor);
|
|
242
242
|
};
|
|
243
243
|
/**
|
|
244
|
-
* Additively blends a new pixel with an existing color value in a
|
|
244
|
+
* Additively blends a new pixel with an existing color value in a canvas.
|
|
245
245
|
*
|
|
246
246
|
* As this method is often called many times in render loops, only bounds
|
|
247
247
|
* checking is applied to the given coordinates.
|
|
@@ -252,7 +252,7 @@ export const putPixel32 = (canvas, x, y, color, alpha) => {
|
|
|
252
252
|
*
|
|
253
253
|
* The `alpha` value is expected to be an integer in the range from `0` to `255`.
|
|
254
254
|
* `0` meaning fully transparent, `255` meaning fully opaque.
|
|
255
|
-
* @param canvas - The
|
|
255
|
+
* @param canvas - The canvas to interact with.
|
|
256
256
|
* @param x - The X coordinate at which to place the pixel.
|
|
257
257
|
* @param y - The Y coordinate at which to place the pixel.
|
|
258
258
|
* @param color - The color of the pixel.
|
|
@@ -260,7 +260,7 @@ export const putPixel32 = (canvas, x, y, color, alpha) => {
|
|
|
260
260
|
* @group Graphics
|
|
261
261
|
*/
|
|
262
262
|
export const putPixel32Add = (canvas, x, y, color, alpha) => {
|
|
263
|
-
if (canvas.width
|
|
263
|
+
if (canvas.width <= x || x < 0 || canvas.height < y || y < 0) {
|
|
264
264
|
return;
|
|
265
265
|
}
|
|
266
266
|
const srcColor = canvas.getPixel32(x, y);
|
|
@@ -268,7 +268,7 @@ export const putPixel32Add = (canvas, x, y, color, alpha) => {
|
|
|
268
268
|
canvas.setPixel32(x, y, newColor);
|
|
269
269
|
};
|
|
270
270
|
/**
|
|
271
|
-
* Subtractively blends a new pixel with an existing color value in a
|
|
271
|
+
* Subtractively blends a new pixel with an existing color value in a canvas.
|
|
272
272
|
*
|
|
273
273
|
* As this method is often called many times in render loops, only bounds
|
|
274
274
|
* checking is applied to the given coordinates.
|
|
@@ -279,7 +279,7 @@ export const putPixel32Add = (canvas, x, y, color, alpha) => {
|
|
|
279
279
|
*
|
|
280
280
|
* The `alpha` value is expected to be an integer in the range from `0` to `255`.
|
|
281
281
|
* `0` meaning fully transparent, `255` meaning fully opaque.
|
|
282
|
-
* @param canvas - The
|
|
282
|
+
* @param canvas - The canvas to interact with.
|
|
283
283
|
* @param x - The X coordinate at which to place the pixel.
|
|
284
284
|
* @param y - The Y coordinate at which to place the pixel.
|
|
285
285
|
* @param color - The color of the pixel.
|
|
@@ -287,7 +287,7 @@ export const putPixel32Add = (canvas, x, y, color, alpha) => {
|
|
|
287
287
|
* @group Graphics
|
|
288
288
|
*/
|
|
289
289
|
export const putPixel32Sub = (canvas, x, y, color, alpha) => {
|
|
290
|
-
if (canvas.width
|
|
290
|
+
if (canvas.width <= x || x < 0 || canvas.height <= y || y < 0) {
|
|
291
291
|
return;
|
|
292
292
|
}
|
|
293
293
|
const srcColor = canvas.getPixel32(x, y);
|
|
@@ -295,9 +295,9 @@ export const putPixel32Sub = (canvas, x, y, color, alpha) => {
|
|
|
295
295
|
canvas.setPixel32(x, y, newColor);
|
|
296
296
|
};
|
|
297
297
|
/**
|
|
298
|
-
* Linearly blends a new pixel with an existing color value in a
|
|
298
|
+
* Linearly blends a new pixel with an existing color value in a canvas.
|
|
299
299
|
* Compared to {@linkcode putPixel32}, this function supports sub-pixel placement, but is dramatically slower.
|
|
300
|
-
* @param canvas - The
|
|
300
|
+
* @param canvas - The canvas to interact with.
|
|
301
301
|
* @param x - The X coordinate at which to place the pixel.
|
|
302
302
|
* @param y - The Y coordinate at which to place the pixel.
|
|
303
303
|
* @param color - The color of the pixel.
|
|
@@ -305,7 +305,7 @@ export const putPixel32Sub = (canvas, x, y, color, alpha) => {
|
|
|
305
305
|
* @group Graphics
|
|
306
306
|
*/
|
|
307
307
|
export const putSubPixel32 = (canvas, x, y, color, alpha) => {
|
|
308
|
-
if (canvas.width
|
|
308
|
+
if (canvas.width <= x || x < 0 || canvas.height <= y || y < 0) {
|
|
309
309
|
return;
|
|
310
310
|
}
|
|
311
311
|
const xweight = x - Math.trunc(x);
|
package/graphics/canvas2d.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canvas2d.js","sourceRoot":"","sources":["../../source/graphics/canvas2d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"canvas2d.js","sourceRoot":"","sources":["../../source/graphics/canvas2d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EACL,KAAK,EACL,aAAa,EACb,gBAAgB,EAChB,QAAQ,EACR,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,IAAI,GACL,MAAM,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M,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QAC9D,OAAO;IACT,CAAC;IAED,MAAM,OAAO,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAClC,MAAM,OAAO,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAClC,MAAM,QAAQ,GAAG,CAAC,GAAG,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;AAClD,CAAC,CAAC"}
|
package/graphics/canvas3d.js
CHANGED
|
@@ -30,7 +30,7 @@ export class Canvas3D extends Canvas {
|
|
|
30
30
|
constructor(canvas, options = {}) {
|
|
31
31
|
super(canvas);
|
|
32
32
|
this.options = options;
|
|
33
|
-
this.#context = mustExist(this.
|
|
33
|
+
this.#context = mustExist(this.canvasElement.getContext("webgl2", {
|
|
34
34
|
alpha: false,
|
|
35
35
|
}), "Unable to create rendering context for offscreen canvas.");
|
|
36
36
|
}
|
|
@@ -38,7 +38,7 @@ export class Canvas3D extends Canvas {
|
|
|
38
38
|
* Recreate internal buffers in reaction to a change in our target {@linkcode !HTMLCanvasElement}.
|
|
39
39
|
*/
|
|
40
40
|
refreshCanvasNode() {
|
|
41
|
-
this.#context = mustExist(this.
|
|
41
|
+
this.#context = mustExist(this.canvasElement.getContext("webgl2", {
|
|
42
42
|
alpha: false,
|
|
43
43
|
desynchronized: true,
|
|
44
44
|
}), "Unable to create rendering context for offscreen canvas.");
|
package/graphics/canvas3d.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canvas3d.js","sourceRoot":"","sources":["../../source/graphics/canvas3d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAUrC;;;;GAIG;AACH,MAAM,OAAO,QAAS,SAAQ,MAAM;IAClC;;OAEG;IACH,QAAQ,CAAyB;IACjC;;;OAGG;IACH,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED;;OAEG;IACM,OAAO,CAAqC;IAErD;;;;OAIG;IACH,YAAY,MAAyB,EAAE,UAAoC,EAAE;QAC3E,KAAK,CAAC,MAAM,CAAC,CAAC;QAEd,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,IAAI,CAAC,QAAQ,GAAG,SAAS,CACvB,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"canvas3d.js","sourceRoot":"","sources":["../../source/graphics/canvas3d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAUrC;;;;GAIG;AACH,MAAM,OAAO,QAAS,SAAQ,MAAM;IAClC;;OAEG;IACH,QAAQ,CAAyB;IACjC;;;OAGG;IACH,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED;;OAEG;IACM,OAAO,CAAqC;IAErD;;;;OAIG;IACH,YAAY,MAAyB,EAAE,UAAoC,EAAE;QAC3E,KAAK,CAAC,MAAM,CAAC,CAAC;QAEd,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,IAAI,CAAC,QAAQ,GAAG,SAAS,CACvB,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,QAAQ,EAAE;YACtC,KAAK,EAAE,KAAK;SACb,CAAC,EACF,0DAA0D,CAC3D,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,iBAAiB;QACf,IAAI,CAAC,QAAQ,GAAG,SAAS,CACvB,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,QAAQ,EAAE;YACtC,KAAK,EAAE,KAAK;YACZ,cAAc,EAAE,IAAI;SACrB,CAAC,EACF,0DAA0D,CAC3D,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,+BAA+B;IACjC,CAAC;IACD;;OAEG;IACH,MAAM;QACJ,+BAA+B;IACjC,CAAC;IAED;;;OAGG;IACH,SAAS,CAAC,MAAc;QACtB,MAAM,IAAI,mBAAmB,EAAE,CAAC;IAClC,CAAC;IAED;;;;;OAKG;IACH,aAAa,CAAC,WAA0B,EAAE,UAAkB,EAAE,UAAkB;QAC9E,MAAM,IAAI,mBAAmB,EAAE,CAAC;IAClC,CAAC;CACF"}
|
package/graphics/index.d.ts
CHANGED
package/graphics/index.js
CHANGED
package/graphics/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/graphics/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/graphics/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC;AACvC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@oliversalzburg/js-utils",
|
|
4
|
-
"version": "0.0.28-dev.
|
|
4
|
+
"version": "0.0.28-dev.6",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Oliver Salzburg <oliver.salzburg@gmail.com>",
|
|
7
7
|
"repository": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/chai": "4.3.11",
|
|
34
34
|
"@types/chai-as-promised": "7.1.8",
|
|
35
|
-
"@types/eslint": "8.44.
|
|
35
|
+
"@types/eslint": "8.44.9",
|
|
36
36
|
"@types/mocha": "10.0.6",
|
|
37
37
|
"@types/node": "20.10.4",
|
|
38
38
|
"@types/web": "0.0.127",
|