@oliversalzburg/js-utils 0.0.14 → 0.0.16
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/_site/assets/highlight.css +92 -8
- package/_site/assets/navigation.js +1 -1
- package/_site/assets/search.js +1 -1
- package/_site/classes/AbstractError.html +47 -8
- package/_site/classes/Canvas.html +73 -23
- package/_site/classes/CanvasSandbox.html +91 -0
- package/_site/classes/Euler.html +217 -0
- package/_site/classes/InternalError.html +48 -9
- package/_site/classes/InvalidArgumentError.html +47 -8
- package/_site/classes/InvalidOperationError.html +47 -8
- package/_site/classes/Matrix3.html +167 -0
- package/_site/classes/NotImplementedError.html +47 -8
- package/_site/classes/PermissionViolationError.html +47 -8
- package/_site/classes/Quaternion.html +211 -0
- package/_site/classes/Random.html +56 -15
- package/_site/classes/RenderLoop.html +58 -19
- package/_site/classes/ResourceConflictError.html +47 -8
- package/_site/classes/Transformation.html +52 -0
- package/_site/classes/UnexpectedNilError.html +44 -5
- package/_site/classes/UnknownError.html +47 -8
- package/_site/classes/Vector2.html +77 -38
- package/_site/classes/Vector3.html +201 -15
- package/_site/classes/Vector4.html +156 -0
- package/_site/functions/addVector2.html +43 -4
- package/_site/functions/addVector3.html +44 -0
- package/_site/functions/blend.html +41 -2
- package/_site/functions/blendAdditive.html +41 -2
- package/_site/functions/blendSubtractive.html +41 -2
- package/_site/functions/clamp.html +41 -2
- package/_site/functions/coalesceOnRejection.html +51 -0
- package/_site/functions/cosDeg.html +41 -2
- package/_site/functions/crossVector3.html +44 -0
- package/_site/functions/deg2rad.html +41 -2
- package/_site/functions/difference.html +41 -2
- package/_site/functions/distance.html +41 -2
- package/_site/functions/dotVector3.html +44 -0
- package/_site/functions/errorToJSON.html +41 -2
- package/_site/functions/errorToRecord.html +41 -2
- package/_site/functions/errorToSimpleSerializable.html +41 -2
- package/_site/functions/filterType.html +41 -2
- package/_site/functions/formatString.html +42 -3
- package/_site/functions/formatStringTemplate.html +42 -3
- package/_site/functions/fromRGB.html +41 -2
- package/_site/functions/fromRGBA.html +41 -2
- package/_site/functions/getA.html +41 -2
- package/_site/functions/getB.html +41 -2
- package/_site/functions/getDocumentElementTypeById.html +43 -6
- package/_site/functions/getDocumentElementTypeByIdStrict.html +48 -0
- package/_site/functions/getG.html +41 -2
- package/_site/functions/getR.html +41 -2
- package/_site/functions/intersect.html +41 -2
- package/_site/functions/is.html +41 -2
- package/_site/functions/isError.html +41 -2
- package/_site/functions/isInteger.html +41 -2
- package/_site/functions/isNil.html +41 -2
- package/_site/functions/isqrt.html +41 -2
- package/_site/functions/multiplyVector2.html +43 -4
- package/_site/functions/multiplyVector3.html +44 -0
- package/_site/functions/mustExist.html +41 -2
- package/_site/functions/nextPalette.html +42 -2
- package/_site/functions/prepareAsyncContext.html +46 -0
- package/_site/functions/putPixel32.html +41 -2
- package/_site/functions/putPixel32Add.html +41 -2
- package/_site/functions/putPixel32Sub.html +41 -2
- package/_site/functions/putSubPixel32.html +41 -2
- package/_site/functions/rad2deg.html +41 -2
- package/_site/functions/randomRange.html +41 -2
- package/_site/functions/safeRGBComponent.html +41 -2
- package/_site/functions/seedFromString.html +41 -2
- package/_site/functions/shuffleArray.html +41 -2
- package/_site/functions/sinDeg.html +41 -2
- package/_site/functions/sleep.html +41 -2
- package/_site/functions/somecolor.html +41 -2
- package/_site/functions/subtractVector2.html +43 -4
- package/_site/functions/subtractVector3.html +44 -0
- package/_site/functions/toGrayScale.html +41 -2
- package/_site/functions/unknownToError.html +41 -2
- package/_site/index.html +41 -2
- package/_site/interfaces/CanvasOptions.html +42 -3
- package/_site/interfaces/CanvasSandboxApplication.html +60 -0
- package/_site/interfaces/CanvasSandboxExpectedOptions.html +48 -0
- package/_site/interfaces/CanvasSandboxOptions.html +45 -0
- package/_site/interfaces/RenderLoopOptions.html +43 -4
- package/_site/modules.html +62 -4
- package/_site/types/AnyAsyncFunction.html +41 -0
- package/_site/types/AnyConstructor.html +41 -2
- package/_site/types/AnyFunction.html +41 -2
- package/_site/types/ConstructorOf.html +41 -2
- package/_site/types/FunctionReturning.html +41 -2
- package/_site/types/Maybe.html +41 -2
- package/_site/types/Mixin.html +41 -2
- package/_site/types/Nil.html +41 -2
- package/_site/types/RenderLoopCallback.html +41 -2
- package/_site/types/SerializedError.html +41 -2
- package/_site/variables/CANVAS_SANDBOX_DEFAULT_CSS.html +41 -0
- package/_site/variables/MS_PER_FRAME_60FPS.html +42 -1
- package/_site/variables/PALETTES.html +41 -2
- package/_site/variables/TWO_PI.html +41 -2
- package/_site/variables/random-1.html +41 -2
- package/docs/assets/favicon.ico +0 -0
- package/lib/async.d.ts +27 -0
- package/lib/async.js +43 -0
- package/lib/async.js.map +1 -0
- package/lib/core.d.ts +4 -0
- package/lib/core.js.map +1 -1
- package/lib/dom/core.d.ts +13 -3
- package/lib/dom/core.js +22 -3
- package/lib/dom/core.js.map +1 -1
- package/lib/graphics/canvas-sandbox.d.ts +207 -0
- package/lib/graphics/canvas-sandbox.js +315 -0
- package/lib/graphics/canvas-sandbox.js.map +1 -0
- package/lib/graphics/canvas.d.ts +13 -6
- package/lib/graphics/canvas.js +51 -16
- package/lib/graphics/canvas.js.map +1 -1
- package/lib/graphics/core.d.ts +2 -1
- package/lib/graphics/core.js +2 -0
- package/lib/graphics/core.js.map +1 -1
- package/lib/graphics/index.d.ts +1 -0
- package/lib/graphics/index.js +1 -0
- package/lib/graphics/index.js.map +1 -1
- package/lib/graphics/render-loop.d.ts +2 -1
- package/lib/graphics/render-loop.js +52 -33
- package/lib/graphics/render-loop.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/math/euler.d.ts +19 -0
- package/lib/math/euler.js +23 -0
- package/lib/math/euler.js.map +1 -0
- package/lib/math/index.d.ts +5 -1
- package/lib/math/index.js +5 -1
- package/lib/math/index.js.map +1 -1
- package/lib/math/matrix3.d.ts +218 -0
- package/lib/math/matrix3.js +509 -0
- package/lib/math/matrix3.js.map +1 -0
- package/lib/math/quaternion.d.ts +120 -0
- package/lib/math/quaternion.js +272 -0
- package/lib/math/quaternion.js.map +1 -0
- package/lib/math/transformation.d.ts +27 -0
- package/lib/math/transformation.js +32 -0
- package/lib/math/transformation.js.map +1 -0
- package/lib/math/vector2.d.ts +19 -19
- package/lib/math/vector2.js +12 -12
- package/lib/math/vector2.js.map +1 -1
- package/lib/math/vector3.d.ts +256 -3
- package/lib/math/vector3.js +440 -1
- package/lib/math/vector3.js.map +1 -1
- package/lib/math/vector4.d.ts +183 -0
- package/lib/math/vector4.js +303 -0
- package/lib/math/vector4.js.map +1 -0
- package/lib/random.d.ts +5 -1
- package/lib/random.js +7 -1
- package/lib/random.js.map +1 -1
- package/package.json +5 -4
- package/lib/graphics/canvas copy.d.ts +0 -170
- package/lib/graphics/canvas copy.js +0 -300
- package/lib/graphics/canvas copy.js.map +0 -1
- package/lib/graphics/canvas-worker.d.ts +0 -50
- package/lib/graphics/canvas-worker.js +0 -78
- package/lib/graphics/canvas-worker.js.map +0 -1
- package/lib/math/vector.d.ts +0 -2
- package/lib/math/vector.js +0 -3
- package/lib/math/vector.js.map +0 -1
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { getDocumentElementTypeById } from "../dom/core.js";
|
|
2
|
+
import { Canvas } from "./canvas.js";
|
|
3
|
+
import { nextPalette } from "./core.js";
|
|
4
|
+
import { RenderLoop } from "./render-loop.js";
|
|
5
|
+
/**
|
|
6
|
+
* Provides the input as-is.
|
|
7
|
+
* This method exists only to make use of the `css` template string tag,
|
|
8
|
+
* which allows us to use in-IDE support for CSS through the support for
|
|
9
|
+
* {@link https://lit.dev/docs/components/styles/ Lit styles}.
|
|
10
|
+
* @param input The CSS code.
|
|
11
|
+
* @returns The CSS code as-is.
|
|
12
|
+
*/
|
|
13
|
+
const css = (input) => input.join("");
|
|
14
|
+
/**
|
|
15
|
+
* The CSS we inject into the document, if requested.
|
|
16
|
+
* @group Graphics
|
|
17
|
+
*/
|
|
18
|
+
export const CANVAS_SANDBOX_DEFAULT_CSS = /* PURE */ css `
|
|
19
|
+
html,
|
|
20
|
+
body {
|
|
21
|
+
height: 100%;
|
|
22
|
+
width: 100%;
|
|
23
|
+
padding: 0;
|
|
24
|
+
margin: 0;
|
|
25
|
+
background-color: #808080;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
body {
|
|
29
|
+
transition: background-color 1s ease-in-out;
|
|
30
|
+
}
|
|
31
|
+
body.darkMode {
|
|
32
|
+
background-color: #211f1f;
|
|
33
|
+
}
|
|
34
|
+
body.lightMode {
|
|
35
|
+
background-color: #ebdcdc;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
#main {
|
|
39
|
+
display: block;
|
|
40
|
+
position: absolute;
|
|
41
|
+
margin: auto;
|
|
42
|
+
top: 0;
|
|
43
|
+
left: 0;
|
|
44
|
+
right: 0;
|
|
45
|
+
bottom: 0;
|
|
46
|
+
|
|
47
|
+
filter: drop-shadow(10px 10px 4px rgba(0, 0, 0, 0.5));
|
|
48
|
+
transition: all 1s;
|
|
49
|
+
}
|
|
50
|
+
`;
|
|
51
|
+
/**
|
|
52
|
+
* The {@linkcode CanvasSandbox} provides a scaffold to quickly perform experiments
|
|
53
|
+
* with a {@linkcode !HTMLCanvasElement} in a document. Common functionality for such
|
|
54
|
+
* experiments is implemented in the sandbox already.
|
|
55
|
+
* @example
|
|
56
|
+
* ### `main.ts`
|
|
57
|
+
* ```ts
|
|
58
|
+
* import { Random, seedFromString } from "@oliversalzburg/js-utils/lib/random.js";
|
|
59
|
+
* import { Canvas } from "@oliversalzburg/js-utils/lib/graphics/canvas.js";
|
|
60
|
+
* import { getDocumentElementTypeByIdStrict } from "@oliversalzburg/js-utils/lib/dom/core.js";
|
|
61
|
+
* import { CanvasSandbox } from "@oliversalzburg/js-utils/lib/graphics/canvas-sandbox.js";
|
|
62
|
+
*
|
|
63
|
+
* interface ApplicationOptions {
|
|
64
|
+
* seed: string;
|
|
65
|
+
* somethingElse: number;
|
|
66
|
+
* }
|
|
67
|
+
*
|
|
68
|
+
* class Application {
|
|
69
|
+
* canvas: Canvas;
|
|
70
|
+
* options: ApplicationOptions;
|
|
71
|
+
* random: Random;
|
|
72
|
+
*
|
|
73
|
+
* constructor(canvas:Canvas, options: ApplicationOptions) {
|
|
74
|
+
* this.canvas = canvas;
|
|
75
|
+
* this.options = options;
|
|
76
|
+
* this.random = new Random(seedFromString(options.seed));
|
|
77
|
+
* }
|
|
78
|
+
*
|
|
79
|
+
* reconfigure(canvas:Canvas, options: Partial<ApplicationOptions> = {}) {
|
|
80
|
+
* this.canvas = canvas;
|
|
81
|
+
* this.options = { ...this.options, ...options };
|
|
82
|
+
* this.random = new Random(seedFromString(options.seed));
|
|
83
|
+
* }
|
|
84
|
+
*
|
|
85
|
+
* onDraw(delta:number, timestamp:number) {
|
|
86
|
+
* // draw something on `this.canvas`
|
|
87
|
+
* }
|
|
88
|
+
*
|
|
89
|
+
* start() {}
|
|
90
|
+
* }
|
|
91
|
+
*
|
|
92
|
+
* const canvasNode = getDocumentElementTypeByIdStrict(document, "main", HTMLCanvasElement);
|
|
93
|
+
* const canvasSandbox = new CanvasSandbox(
|
|
94
|
+
* window,
|
|
95
|
+
* canvasNode,
|
|
96
|
+
* Application,
|
|
97
|
+
* {seed: "foo", somethingElse: 12345}
|
|
98
|
+
* );
|
|
99
|
+
*
|
|
100
|
+
* // By running the sandbox, your `start()` and `onDraw()` methods will automatically be invoked
|
|
101
|
+
* // by the sandbox. You shouldn't invoke those methods directly from your own code.
|
|
102
|
+
* canvasSandbox.run();
|
|
103
|
+
* ```
|
|
104
|
+
* ### `index.html`
|
|
105
|
+
* ```html
|
|
106
|
+
* <!doctype html>
|
|
107
|
+
* <html>
|
|
108
|
+
* <head>
|
|
109
|
+
* <meta charset="UTF-8" />
|
|
110
|
+
* </head>
|
|
111
|
+
*
|
|
112
|
+
* <body>
|
|
113
|
+
* <canvas id="main" class="darkMode" width="512" height="512"></canvas>
|
|
114
|
+
* </body>
|
|
115
|
+
* <script src="main.ts" type="module"></script>
|
|
116
|
+
* </html>
|
|
117
|
+
* ```
|
|
118
|
+
* @template {CanvasSandboxExpectedOptions} TApplicationOptions The type of the options
|
|
119
|
+
* the application in the sandbox will be constructed with.
|
|
120
|
+
* @group Graphics
|
|
121
|
+
*/
|
|
122
|
+
export class CanvasSandbox {
|
|
123
|
+
/**
|
|
124
|
+
* The window the sandbox is running in.
|
|
125
|
+
*/
|
|
126
|
+
window;
|
|
127
|
+
/**
|
|
128
|
+
* The document the sandbox is interacting with.
|
|
129
|
+
*/
|
|
130
|
+
document;
|
|
131
|
+
/**
|
|
132
|
+
* The application running inside the sandbox.
|
|
133
|
+
*/
|
|
134
|
+
application;
|
|
135
|
+
/**
|
|
136
|
+
* The canvas node that we're drawing into.
|
|
137
|
+
*/
|
|
138
|
+
canvasNode;
|
|
139
|
+
/**
|
|
140
|
+
* Our convenience canvas wrapper, which we provide to the application
|
|
141
|
+
* to render to.
|
|
142
|
+
*/
|
|
143
|
+
canvas;
|
|
144
|
+
/**
|
|
145
|
+
* The render loop we use to control frame rendering.
|
|
146
|
+
*/
|
|
147
|
+
renderLoop;
|
|
148
|
+
/**
|
|
149
|
+
* The handle that keeps track of debouncing of `resize` events.
|
|
150
|
+
*/
|
|
151
|
+
#resizeDebounce = null;
|
|
152
|
+
/**
|
|
153
|
+
* Construct a new {@linkcode CanvasSandbox}.
|
|
154
|
+
* @param window The window we're running inside.
|
|
155
|
+
* @param canvasNode The canvas node we're drawing to.
|
|
156
|
+
* @param Application The application that is going to run in the sandbox.
|
|
157
|
+
* @param options The options that the application should be constructed with.
|
|
158
|
+
* @param sandboxOptions The options for the sandbox itself.
|
|
159
|
+
*/
|
|
160
|
+
constructor(window, canvasNode, Application, options, sandboxOptions) {
|
|
161
|
+
this.window = window;
|
|
162
|
+
this.document = window.document;
|
|
163
|
+
this.canvasNode = canvasNode;
|
|
164
|
+
this.canvas = new Canvas(canvasNode);
|
|
165
|
+
if (sandboxOptions?.injectDefaultCss ?? true) {
|
|
166
|
+
this.injectDefaultCss();
|
|
167
|
+
}
|
|
168
|
+
this.application = new Application(this.canvas, options);
|
|
169
|
+
const applicationOnDraw = this.application.onDraw.bind(this.application);
|
|
170
|
+
this.renderLoop = new RenderLoop(applicationOnDraw, this.canvas, { drawFps: true });
|
|
171
|
+
this.#hookWindow();
|
|
172
|
+
this.#hookBody();
|
|
173
|
+
this.#hookCanvas();
|
|
174
|
+
const systemPrefersDarkMode = this.window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
175
|
+
if (systemPrefersDarkMode) {
|
|
176
|
+
this.toDarkMode();
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
this.toLightMode();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Injects our default CSS into the document, if it hasn't already been injected.
|
|
184
|
+
* @see {@linkcode CANVAS_SANDBOX_DEFAULT_CSS}
|
|
185
|
+
*/
|
|
186
|
+
injectDefaultCss() {
|
|
187
|
+
const existingStyle = getDocumentElementTypeById(this.document, "canvas-sandbox-styles", HTMLStyleElement);
|
|
188
|
+
if (existingStyle) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
const styleNode = this.document.createElement("style");
|
|
192
|
+
styleNode.textContent = CANVAS_SANDBOX_DEFAULT_CSS;
|
|
193
|
+
this.document.head.appendChild(styleNode);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Run the sandbox.
|
|
197
|
+
*/
|
|
198
|
+
run() {
|
|
199
|
+
this.application.start();
|
|
200
|
+
// In case the application doesn't maintain this state itself.
|
|
201
|
+
this.application.paused = false;
|
|
202
|
+
this.renderLoop.unblock();
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Create event listeners on the document `body`.
|
|
206
|
+
*/
|
|
207
|
+
#hookBody() {
|
|
208
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
209
|
+
this.document.body.addEventListener("click", async (event) => {
|
|
210
|
+
if (event.defaultPrevented) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
if (!this.document.fullscreenEnabled) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
if (!this.document.fullscreenElement) {
|
|
217
|
+
await this.canvasNode.requestFullscreen();
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
this.document.body.addEventListener("keyup", event => {
|
|
221
|
+
switch (event.keyCode) {
|
|
222
|
+
case 13:
|
|
223
|
+
// Enter
|
|
224
|
+
nextPalette();
|
|
225
|
+
this.#reconfigureApplication({
|
|
226
|
+
seed: this.application.random.next().toString(),
|
|
227
|
+
});
|
|
228
|
+
this.application.reconfigure(this.canvas, {
|
|
229
|
+
seed: this.application.random.next().toString(),
|
|
230
|
+
});
|
|
231
|
+
this.application.start();
|
|
232
|
+
break;
|
|
233
|
+
case 32:
|
|
234
|
+
// Space
|
|
235
|
+
this.application.paused = !this.application.paused;
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Reconfigures, and then restarts, the application.
|
|
242
|
+
* @param options The new options for the application.
|
|
243
|
+
*/
|
|
244
|
+
#reconfigureApplication(options = {}) {
|
|
245
|
+
this.application.reconfigure(this.canvas, options);
|
|
246
|
+
this.application.start();
|
|
247
|
+
// In case the application doesn't maintain this state itself.
|
|
248
|
+
this.application.paused = false;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Create event listeners on the canvas node in the document.
|
|
252
|
+
*/
|
|
253
|
+
#hookCanvas() {
|
|
254
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
255
|
+
this.canvasNode.addEventListener("click", async (event) => {
|
|
256
|
+
if (this.document.fullscreenElement) {
|
|
257
|
+
await document.exitFullscreen();
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
nextPalette();
|
|
261
|
+
this.#reconfigureApplication({
|
|
262
|
+
seed: this.application.random.next().toString(),
|
|
263
|
+
});
|
|
264
|
+
event.preventDefault();
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Create event listeners on the window we're running in.
|
|
269
|
+
*/
|
|
270
|
+
#hookWindow() {
|
|
271
|
+
this.window
|
|
272
|
+
.matchMedia("(prefers-color-scheme: dark)")
|
|
273
|
+
.addEventListener("change", ({ matches }) => {
|
|
274
|
+
if (matches) {
|
|
275
|
+
this.toDarkMode();
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
this.toLightMode();
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
this.window.addEventListener("resize", event => {
|
|
282
|
+
if (this.#resizeDebounce !== null) {
|
|
283
|
+
this.window.clearTimeout(this.#resizeDebounce);
|
|
284
|
+
}
|
|
285
|
+
this.#resizeDebounce = this.window.setTimeout(() => {
|
|
286
|
+
this.application.reconfigure(this.canvas);
|
|
287
|
+
this.canvas.refreshCanvasNode();
|
|
288
|
+
this.application.start();
|
|
289
|
+
// In case the application doesn't maintain this state itself.
|
|
290
|
+
this.application.paused = false;
|
|
291
|
+
}, 1000);
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Switch the sandbox to dark mode.
|
|
296
|
+
*/
|
|
297
|
+
toDarkMode() {
|
|
298
|
+
this.#reconfigureApplication({
|
|
299
|
+
darkMode: true,
|
|
300
|
+
});
|
|
301
|
+
document.body.classList.add("darkMode");
|
|
302
|
+
document.body.classList.remove("lightMode");
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Switch the sandbox to light mode.
|
|
306
|
+
*/
|
|
307
|
+
toLightMode() {
|
|
308
|
+
this.#reconfigureApplication({
|
|
309
|
+
darkMode: false,
|
|
310
|
+
});
|
|
311
|
+
document.body.classList.add("lightMode");
|
|
312
|
+
document.body.classList.remove("darkMode");
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
//# sourceMappingURL=canvas-sandbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canvas-sandbox.js","sourceRoot":"","sources":["../../source/graphics/canvas-sandbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AAE5D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C;;;;;;;GAOG;AACH,MAAM,GAAG,GAAG,CAAC,KAA2B,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAE5D;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,UAAU,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgCvD,CAAC;AA8EF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsEG;AACH,MAAM,OAAO,aAAa;IACxB;;OAEG;IACM,MAAM,CAAS;IAExB;;OAEG;IACM,QAAQ,CAAW;IAE5B;;OAEG;IACM,WAAW,CAAgD;IAEpE;;OAEG;IACM,UAAU,CAAoB;IAEvC;;;OAGG;IACM,MAAM,CAAS;IAExB;;OAEG;IACM,UAAU,CAAa;IAEhC;;OAEG;IACH,eAAe,GAAkB,IAAI,CAAC;IAEtC;;;;;;;OAOG;IACH,YACE,MAAc,EACd,UAA6B,EAC7B,WASkD,EAClD,OAA4B,EAC5B,cAAqC;QAErC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAChC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CAAC,UAAU,CAAC,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IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE;gBACjD,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBAC1C,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE,CAAC;gBAChC,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;gBACzB,8DAA8D;gBAC9D,IAAI,CAAC,WAAW,CAAC,MAAM,GAAG,KAAK,CAAC;YAClC,CAAC,EAAE,IAAI,CAAC,CAAC;QACX,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;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/lib/graphics/canvas.d.ts
CHANGED
|
@@ -24,17 +24,20 @@ export declare class Canvas {
|
|
|
24
24
|
*/
|
|
25
25
|
readonly canvasDom: HTMLCanvasElement;
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
27
|
+
* Retrieves the width of the canvas.
|
|
28
|
+
* @returns The width of the canvas.
|
|
28
29
|
*/
|
|
29
|
-
|
|
30
|
+
get width(): number;
|
|
30
31
|
/**
|
|
31
|
-
*
|
|
32
|
+
* Retrieves the height of the canvas.
|
|
33
|
+
* @returns The height of the canvas.
|
|
32
34
|
*/
|
|
33
|
-
|
|
35
|
+
get height(): number;
|
|
34
36
|
/**
|
|
35
|
-
*
|
|
37
|
+
* Retrieves the rendering context of the canvas.
|
|
38
|
+
* @returns The rendering context of the canvas.
|
|
36
39
|
*/
|
|
37
|
-
|
|
40
|
+
get context(): OffscreenCanvasRenderingContext2D;
|
|
38
41
|
/**
|
|
39
42
|
* Our back buffer.
|
|
40
43
|
*/
|
|
@@ -49,6 +52,10 @@ export declare class Canvas {
|
|
|
49
52
|
* @param options The configuration for this canvas.
|
|
50
53
|
*/
|
|
51
54
|
constructor(canvas: HTMLCanvasElement, options?: Partial<CanvasOptions>);
|
|
55
|
+
/**
|
|
56
|
+
* Recreate internal buffers in reaction to a change in our target {@linkcode !HTMLCanvasElement}.
|
|
57
|
+
*/
|
|
58
|
+
refreshCanvasNode(): void;
|
|
52
59
|
/**
|
|
53
60
|
* Draws the back buffer onto the canvas.
|
|
54
61
|
*/
|
package/lib/graphics/canvas.js
CHANGED
|
@@ -24,15 +24,36 @@ export class Canvas {
|
|
|
24
24
|
/**
|
|
25
25
|
* The width of the canvas.
|
|
26
26
|
*/
|
|
27
|
-
width;
|
|
27
|
+
#width;
|
|
28
|
+
/**
|
|
29
|
+
* Retrieves the width of the canvas.
|
|
30
|
+
* @returns The width of the canvas.
|
|
31
|
+
*/
|
|
32
|
+
get width() {
|
|
33
|
+
return this.#width;
|
|
34
|
+
}
|
|
28
35
|
/**
|
|
29
36
|
* The height of the canvas.
|
|
30
37
|
*/
|
|
31
|
-
height;
|
|
38
|
+
#height;
|
|
32
39
|
/**
|
|
33
|
-
*
|
|
40
|
+
* Retrieves the height of the canvas.
|
|
41
|
+
* @returns The height of the canvas.
|
|
34
42
|
*/
|
|
35
|
-
|
|
43
|
+
get height() {
|
|
44
|
+
return this.#height;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The 2D rendering context we're using to draw to the canvas.
|
|
48
|
+
*/
|
|
49
|
+
#context;
|
|
50
|
+
/**
|
|
51
|
+
* Retrieves the rendering context of the canvas.
|
|
52
|
+
* @returns The rendering context of the canvas.
|
|
53
|
+
*/
|
|
54
|
+
get context() {
|
|
55
|
+
return this.#context;
|
|
56
|
+
}
|
|
36
57
|
/**
|
|
37
58
|
* The {@linkcode !ImageData} object in our offscreen canvas. We usually interact with its
|
|
38
59
|
* {@linkcode Canvas.buffer buffer} directly.
|
|
@@ -52,28 +73,42 @@ export class Canvas {
|
|
|
52
73
|
* @param options The configuration for this canvas.
|
|
53
74
|
*/
|
|
54
75
|
constructor(canvas, options = {}) {
|
|
55
|
-
this
|
|
56
|
-
this
|
|
76
|
+
this.#width = canvas.width;
|
|
77
|
+
this.#height = canvas.height;
|
|
57
78
|
this.options = options;
|
|
58
79
|
this.canvasDom = canvas;
|
|
59
80
|
this.#canvasDomContext = mustExist(this.canvasDom.getContext("bitmaprenderer", {
|
|
60
81
|
alpha: false,
|
|
61
82
|
}), "Unable to create rendering context for DOM canvas.");
|
|
62
|
-
this.#canvasOffscreen = new OffscreenCanvas(this
|
|
63
|
-
this
|
|
83
|
+
this.#canvasOffscreen = new OffscreenCanvas(this.#width, this.#height);
|
|
84
|
+
this.#context = mustExist(this.#canvasOffscreen.getContext("2d", {
|
|
85
|
+
alpha: false,
|
|
86
|
+
desynchronized: true,
|
|
87
|
+
willReadFrequently: this.options.supportReadBack,
|
|
88
|
+
}), "Unable to create rendering context for offscreen canvas.");
|
|
89
|
+
this.#imageData = this.#context.createImageData(this.#width, this.#height);
|
|
90
|
+
this.buffer = this.#imageData.data;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Recreate internal buffers in reaction to a change in our target {@linkcode !HTMLCanvasElement}.
|
|
94
|
+
*/
|
|
95
|
+
refreshCanvasNode() {
|
|
96
|
+
this.#width = this.canvasDom.width;
|
|
97
|
+
this.#height = this.canvasDom.height;
|
|
98
|
+
this.#canvasOffscreen = new OffscreenCanvas(this.#width, this.#height);
|
|
99
|
+
this.#context = mustExist(this.#canvasOffscreen.getContext("2d", {
|
|
64
100
|
alpha: false,
|
|
65
101
|
desynchronized: true,
|
|
66
102
|
willReadFrequently: this.options.supportReadBack,
|
|
67
103
|
}), "Unable to create rendering context for offscreen canvas.");
|
|
68
|
-
this.#imageData = this
|
|
104
|
+
this.#imageData = this.#context.createImageData(this.#width, this.#height);
|
|
69
105
|
this.buffer = this.#imageData.data;
|
|
70
|
-
this.context.font = "12px sans-serif";
|
|
71
106
|
}
|
|
72
107
|
/**
|
|
73
108
|
* Draws the back buffer onto the canvas.
|
|
74
109
|
*/
|
|
75
110
|
update() {
|
|
76
|
-
this
|
|
111
|
+
this.#context.putImageData(this.#imageData, 0, 0);
|
|
77
112
|
}
|
|
78
113
|
/**
|
|
79
114
|
* Draws the offscreen canvas into the DOM canvas.
|
|
@@ -99,7 +134,7 @@ export class Canvas {
|
|
|
99
134
|
if (!this.options.supportReadBack) {
|
|
100
135
|
throw new InvalidOperationError("To use `bufferReadBack()`, you must construct the `Canvas` with `options.supportReadBack` set to `true`.");
|
|
101
136
|
}
|
|
102
|
-
this.#imageData = this
|
|
137
|
+
this.#imageData = this.#context.getImageData(0, 0, this.#width, this.#height);
|
|
103
138
|
this.buffer = this.#imageData.data;
|
|
104
139
|
}
|
|
105
140
|
/**
|
|
@@ -109,7 +144,7 @@ export class Canvas {
|
|
|
109
144
|
* @returns The color of the pixel at the given local.
|
|
110
145
|
*/
|
|
111
146
|
getPixel32(x, y) {
|
|
112
|
-
const bufferOffset = (x + y * this
|
|
147
|
+
const bufferOffset = (x + y * this.#width) * 4;
|
|
113
148
|
return fromRGBA(this.buffer[bufferOffset + 0], this.buffer[bufferOffset + 1], this.buffer[bufferOffset + 2], this.buffer[bufferOffset + 3]);
|
|
114
149
|
}
|
|
115
150
|
/**
|
|
@@ -119,7 +154,7 @@ export class Canvas {
|
|
|
119
154
|
* @param color The color to place at the coordinate.
|
|
120
155
|
*/
|
|
121
156
|
setPixel32(x, y, color) {
|
|
122
|
-
const bufferOffset = (x + y * this
|
|
157
|
+
const bufferOffset = (x + y * this.#width) * 4;
|
|
123
158
|
this.buffer[bufferOffset + 0] = getR(color);
|
|
124
159
|
this.buffer[bufferOffset + 1] = getG(color);
|
|
125
160
|
this.buffer[bufferOffset + 2] = getB(color);
|
|
@@ -134,7 +169,7 @@ export class Canvas {
|
|
|
134
169
|
const g = getG(color);
|
|
135
170
|
const b = getB(color);
|
|
136
171
|
const a = getA(color);
|
|
137
|
-
for (let bufferOffset = 0; bufferOffset < this
|
|
172
|
+
for (let bufferOffset = 0; bufferOffset < this.#width * this.#height * 4; bufferOffset += 4) {
|
|
138
173
|
this.buffer[bufferOffset + 0] = r;
|
|
139
174
|
this.buffer[bufferOffset + 1] = g;
|
|
140
175
|
this.buffer[bufferOffset + 2] = b;
|
|
@@ -150,7 +185,7 @@ export class Canvas {
|
|
|
150
185
|
const g = getG(color);
|
|
151
186
|
const b = getB(color);
|
|
152
187
|
const a = getA(color);
|
|
153
|
-
for (let bufferOffset = 0; bufferOffset < this
|
|
188
|
+
for (let bufferOffset = 0; bufferOffset < this.#width * this.#height * 4; bufferOffset += 4) {
|
|
154
189
|
this.buffer[bufferOffset + 0] = (a * r + (255 - a) * this.buffer[bufferOffset + 0]) >> 8;
|
|
155
190
|
this.buffer[bufferOffset + 1] = (a * g + (255 - a) * this.buffer[bufferOffset + 1]) >> 8;
|
|
156
191
|
this.buffer[bufferOffset + 2] = (a * b + (255 - a) * this.buffer[bufferOffset + 2]) >> 8;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canvas.js","sourceRoot":"","sources":["../../source/graphics/canvas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EACL,KAAK,EACL,aAAa,EACb,gBAAgB,EAChB,QAAQ,EACR,IAAI,EACJ,IA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AAC,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/lib/graphics/core.d.ts
CHANGED
|
@@ -100,9 +100,10 @@ export declare const blendSubtractive: (src: number, dst: number, alpha: number)
|
|
|
100
100
|
export declare const somecolor: () => number;
|
|
101
101
|
/**
|
|
102
102
|
* Switches the global palette to the next available preset.
|
|
103
|
+
* @returns The new new global palette.
|
|
103
104
|
* @group Graphics
|
|
104
105
|
*/
|
|
105
|
-
export declare const nextPalette: () =>
|
|
106
|
+
export declare const nextPalette: () => number[];
|
|
106
107
|
/**
|
|
107
108
|
* Converts a color value to grayscale.
|
|
108
109
|
* @param color The color to convert.
|
package/lib/graphics/core.js
CHANGED
|
@@ -476,6 +476,7 @@ export const somecolor = () => {
|
|
|
476
476
|
};
|
|
477
477
|
/**
|
|
478
478
|
* Switches the global palette to the next available preset.
|
|
479
|
+
* @returns The new new global palette.
|
|
479
480
|
* @group Graphics
|
|
480
481
|
*/
|
|
481
482
|
export const nextPalette = () => {
|
|
@@ -483,6 +484,7 @@ export const nextPalette = () => {
|
|
|
483
484
|
if (PALETTES.length <= PALETTE_INDEX) {
|
|
484
485
|
PALETTE_INDEX = 0;
|
|
485
486
|
}
|
|
487
|
+
return PALETTES[PALETTE_INDEX];
|
|
486
488
|
};
|
|
487
489
|
/**
|
|
488
490
|
* Converts a color value to grayscale.
|