@oliversalzburg/js-utils 0.0.4 → 0.0.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.
Files changed (112) hide show
  1. package/coverage/base.css +224 -0
  2. package/coverage/block-navigation.js +87 -0
  3. package/coverage/bundle.js +30 -0
  4. package/coverage/favicon.png +0 -0
  5. package/coverage/index.html +16 -0
  6. package/coverage/prettify.css +1 -0
  7. package/coverage/prettify.js +2 -0
  8. package/coverage/sort-arrow-sprite.png +0 -0
  9. package/coverage/sorter.js +196 -0
  10. package/coverage/spa.css +298 -0
  11. package/coverage/string-formatter.ts.html +187 -0
  12. package/coverage/tmp/coverage-4186-1699218521999-0.json +1 -0
  13. package/coverage/tmp/coverage-4196-1699218521967-0.json +1 -0
  14. package/docs/README.md +3 -0
  15. package/docs/classes/AbstractError.md +271 -0
  16. package/docs/classes/Canvas.md +177 -0
  17. package/docs/classes/InternalError.md +301 -0
  18. package/docs/classes/InvalidArgumentError.md +277 -0
  19. package/docs/classes/InvalidOperationError.md +277 -0
  20. package/docs/classes/NotImplementedError.md +276 -0
  21. package/docs/classes/PermissionViolationError.md +277 -0
  22. package/docs/classes/Random.md +109 -0
  23. package/docs/classes/RenderLoop.md +49 -0
  24. package/docs/classes/ResourceConflictError.md +276 -0
  25. package/docs/classes/UnexpectedNilError.md +169 -0
  26. package/docs/classes/UnknownError.md +280 -0
  27. package/docs/classes/Vector2.md +79 -0
  28. package/docs/classes/Vector3.md +106 -0
  29. package/docs/modules.md +1313 -0
  30. package/lib/core.d.ts +21 -0
  31. package/lib/core.js +3 -0
  32. package/{output → lib}/core.js.map +1 -1
  33. package/{output → lib}/error-serializer.d.ts +1 -1
  34. package/{output → lib}/error-serializer.js +1 -1
  35. package/{output → lib}/errors/AbstractError.d.ts +9 -1
  36. package/{output → lib}/errors/AbstractError.js +10 -2
  37. package/{output → lib}/errors/AbstractError.js.map +1 -1
  38. package/{output → lib}/errors/InternalError.d.ts +6 -1
  39. package/{output → lib}/errors/InternalError.js +6 -1
  40. package/lib/errors/InternalError.js.map +1 -0
  41. package/{output → lib}/errors/InvalidArgumentError.d.ts +1 -1
  42. package/{output → lib}/errors/InvalidArgumentError.js +1 -1
  43. package/{output → lib}/errors/InvalidOperationError.d.ts +1 -1
  44. package/{output → lib}/errors/InvalidOperationError.js +1 -1
  45. package/{output → lib}/errors/NotImplementedError.d.ts +1 -1
  46. package/{output → lib}/errors/NotImplementedError.js +1 -1
  47. package/{output → lib}/errors/PermissionViolationError.d.ts +1 -1
  48. package/{output → lib}/errors/PermissionViolationError.js +1 -1
  49. package/{output → lib}/errors/ResourceConflictError.d.ts +1 -1
  50. package/{output → lib}/errors/ResourceConflictError.js +1 -1
  51. package/{output → lib}/errors/UnknownError.d.ts +2 -2
  52. package/{output → lib}/errors/UnknownError.js +2 -2
  53. package/lib/graphics/canvas.d.ts +80 -0
  54. package/lib/graphics/canvas.js +164 -0
  55. package/lib/graphics/canvas.js.map +1 -0
  56. package/lib/graphics/core.d.ts +94 -0
  57. package/lib/graphics/core.js +479 -0
  58. package/lib/graphics/core.js.map +1 -0
  59. package/lib/graphics/index.d.ts +3 -0
  60. package/lib/graphics/index.js +4 -0
  61. package/lib/graphics/index.js.map +1 -0
  62. package/lib/graphics/render-loop.d.ts +20 -0
  63. package/lib/graphics/render-loop.js +51 -0
  64. package/lib/graphics/render-loop.js.map +1 -0
  65. package/{output → lib}/index.d.ts +4 -0
  66. package/{output → lib}/index.js +4 -0
  67. package/lib/index.js.map +1 -0
  68. package/lib/math/core.d.ts +46 -0
  69. package/lib/math/core.js +72 -0
  70. package/lib/math/core.js.map +1 -0
  71. package/lib/math/index.d.ts +2 -0
  72. package/lib/math/index.js +3 -0
  73. package/lib/math/index.js.map +1 -0
  74. package/lib/math/vector.d.ts +33 -0
  75. package/lib/math/vector.js +42 -0
  76. package/lib/math/vector.js.map +1 -0
  77. package/{output → lib}/nil.d.ts +13 -8
  78. package/{output → lib}/nil.js +16 -11
  79. package/lib/nil.js.map +1 -0
  80. package/lib/random.d.ts +56 -0
  81. package/lib/random.js +184 -0
  82. package/lib/random.js.map +1 -0
  83. package/lib/string-formatter.test.d.ts +1 -0
  84. package/lib/string-formatter.test.js +17 -0
  85. package/lib/string-formatter.test.js.map +1 -0
  86. package/mkdocs.yml +52 -0
  87. package/package.json +25 -13
  88. package/typedoc.json +8 -0
  89. package/output/core.d.ts +0 -4
  90. package/output/core.js +0 -2
  91. package/output/errors/InternalError.js.map +0 -1
  92. package/output/index.js.map +0 -1
  93. package/output/nil.js.map +0 -1
  94. /package/{output → lib}/array.d.ts +0 -0
  95. /package/{output → lib}/array.js +0 -0
  96. /package/{output → lib}/array.js.map +0 -0
  97. /package/{output → lib}/error-serializer.js.map +0 -0
  98. /package/{output → lib}/errors/InvalidArgumentError.js.map +0 -0
  99. /package/{output → lib}/errors/InvalidOperationError.js.map +0 -0
  100. /package/{output → lib}/errors/NotImplementedError.js.map +0 -0
  101. /package/{output → lib}/errors/PermissionViolationError.js.map +0 -0
  102. /package/{output → lib}/errors/ResourceConflictError.js.map +0 -0
  103. /package/{output → lib}/errors/UnknownError.js.map +0 -0
  104. /package/{output → lib}/errors/index.d.ts +0 -0
  105. /package/{output → lib}/errors/index.js +0 -0
  106. /package/{output → lib}/errors/index.js.map +0 -0
  107. /package/{output → lib}/sleep.d.ts +0 -0
  108. /package/{output → lib}/sleep.js +0 -0
  109. /package/{output → lib}/sleep.js.map +0 -0
  110. /package/{output → lib}/string-formatter.d.ts +0 -0
  111. /package/{output → lib}/string-formatter.js +0 -0
  112. /package/{output → lib}/string-formatter.js.map +0 -0
package/lib/core.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Describes a function that is a constructor for T.
3
+ */
4
+ export type ConstructorOf<T = Record<string, unknown>> = new (...args: Array<any>) => T;
5
+ /**
6
+ * Describes literally any function.
7
+ */
8
+ export type AnyFunction = (...args: Array<any>) => any;
9
+ /**
10
+ * Any constructor
11
+ */
12
+ export type AnyConstructor = new (...args: Array<any>) => any;
13
+ /**
14
+ * Describes a function returning an instance of T.
15
+ */
16
+ export type FunctionReturning<T = any> = (...args: Array<any>) => T;
17
+ /**
18
+ * Describes a class "mixin", which is a function that returns a dynamically
19
+ * constructed class, based on the passed parameters.
20
+ */
21
+ export type Mixin<T extends FunctionReturning> = InstanceType<ReturnType<T>>;
package/lib/core.js ADDED
@@ -0,0 +1,3 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ export {};
3
+ //# sourceMappingURL=core.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"core.js","sourceRoot":"","sources":["../source/core.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"core.js","sourceRoot":"","sources":["../source/core.ts"],"names":[],"mappings":"AAAA,uDAAuD"}
@@ -6,7 +6,7 @@ export type SerializedError = Record<string, Record<string, string> | string | u
6
6
  /**
7
7
  * Determine if the given unknown subject is an `Error` instance.
8
8
  * @param subject The object to inspect.
9
- * @returns `true` if the subject is an `Error`, `false´ otherwise.
9
+ * @returns `true` if the subject is an `Error`, `false` otherwise.
10
10
  */
11
11
  export declare const isError: (subject: unknown) => subject is Error;
12
12
  /**
@@ -5,7 +5,7 @@ import { UnknownError } from "./errors/UnknownError.js";
5
5
  /**
6
6
  * Determine if the given unknown subject is an `Error` instance.
7
7
  * @param subject The object to inspect.
8
- * @returns `true` if the subject is an `Error`, `false´ otherwise.
8
+ * @returns `true` if the subject is an `Error`, `false` otherwise.
9
9
  */
10
10
  export const isError = (subject) => {
11
11
  return subject instanceof Error || types.isNativeError(subject);
@@ -24,11 +24,19 @@ export declare class AbstractError extends Error {
24
24
  */
25
25
  code: string;
26
26
  /**
27
- * Constructs a new AbstractError.
27
+ * Constructs a new {@link AbstractError}.
28
28
  * @param code The main identification code for the error.
29
29
  * @param message The main error message.
30
30
  * @param status The HTTP status code to return.
31
31
  */
32
32
  constructor(code: string, message: string, status: number);
33
+ /**
34
+ * Checks if an object is an instance of {@link AbstractError}, or one of its subclasses.
35
+ * @param error The object to check.
36
+ * @param allowForeignModule Only check for similar looking error codes.
37
+ * You're going to want to use this if you're dealing with a setup where
38
+ * multiple versions of js-utils are loaded.
39
+ * @returns `true` if the object is an {@link AbstractError}, `false` otherwise.
40
+ */
33
41
  static isAbstractError(error: unknown, allowForeignModule?: boolean): error is AbstractError;
34
42
  }
@@ -23,7 +23,7 @@ export class AbstractError extends Error {
23
23
  */
24
24
  code;
25
25
  /**
26
- * Constructs a new AbstractError.
26
+ * Constructs a new {@link AbstractError}.
27
27
  * @param code The main identification code for the error.
28
28
  * @param message The main error message.
29
29
  * @param status The HTTP status code to return.
@@ -38,11 +38,19 @@ export class AbstractError extends Error {
38
38
  // location we're actually interested in.
39
39
  Error.captureStackTrace(this, AbstractError);
40
40
  }
41
+ /**
42
+ * Checks if an object is an instance of {@link AbstractError}, or one of its subclasses.
43
+ * @param error The object to check.
44
+ * @param allowForeignModule Only check for similar looking error codes.
45
+ * You're going to want to use this if you're dealing with a setup where
46
+ * multiple versions of js-utils are loaded.
47
+ * @returns `true` if the object is an {@link AbstractError}, `false` otherwise.
48
+ */
41
49
  static isAbstractError(error, allowForeignModule = true) {
42
50
  if (error instanceof AbstractError) {
43
51
  return true;
44
52
  }
45
- // When multiple versions of core-models3 are loaded at runtime, the
53
+ // When multiple versions of js-utils are loaded at runtime, the
46
54
  // prototypes of errors don't align. In that case, we just analyze the
47
55
  // error code.
48
56
  if (allowForeignModule) {
@@ -1 +1 @@
1
- {"version":3,"file":"AbstractError.js","sourceRoot":"","sources":["../../source/errors/AbstractError.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtC;;;;OAIG;IACH,MAAM,CAAS;IAEf;;;OAGG;IACH,KAAK,CAAe;IAEpB;;;OAGG;IACH,IAAI,CAAgB;IAEpB;;OAEG;IACH,IAAI,CAAS;IAEb;;;;;OAKG;IACH,YAAY,IAAY,EAAE,OAAe,EAAE,MAAc;QACvD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AC;QACjB,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAElB,qGAAqG;QACrG,yCAAyC;QACzC,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IAC/C,CAAC;IAED;;;;;;;OAOG;IACH,MAAM,CAAC,eAAe,CAAC,KAAc,EAAE,kBAAkB,GAAG,IAAI;QAC9D,IAAI,KAAK,YAAY,aAAa,EAAE;YAClC,OAAO,IAAI,CAAC;SACb;QAED,gEAAgE;QAChE,sEAAsE;QACtE,cAAc;QACd,IAAI,kBAAkB,EAAE;YACtB,MAAM,WAAW,GAAG,KAAgC,CAAC;YACrD,IACE,MAAM,CAAC,KAAK,CAAC,KAAK,KAAK;gBACvB,MAAM,IAAI,WAAW;gBACrB,OAAO,WAAW,CAAC,IAAI,KAAK,QAAQ,EACpC;gBACA,MAAM,UAAU,GAAG,KAAyB,CAAC;gBAC7C,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE;oBACrC,OAAO,IAAI,CAAC;iBACb;aACF;SACF;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
@@ -5,10 +5,15 @@ import { AbstractError } from "./AbstractError.js";
5
5
  */
6
6
  export declare class InternalError extends AbstractError {
7
7
  /**
8
- * Constructs a new `InternalError`.
8
+ * Constructs a new {@link InternalError}.
9
9
  * @param message The main error message.
10
10
  * @param status The HTTP status code to return.
11
11
  */
12
12
  constructor(message: string, status?: number);
13
+ /**
14
+ * Converts an error into an {@link InternalError}.
15
+ * @param error The error to convert.
16
+ * @returns An {@link InternalError} that represents the given error.
17
+ */
13
18
  static fromError(error: Error): InternalError;
14
19
  }
@@ -5,7 +5,7 @@ import { AbstractError } from "./AbstractError.js";
5
5
  */
6
6
  export class InternalError extends AbstractError {
7
7
  /**
8
- * Constructs a new `InternalError`.
8
+ * Constructs a new {@link InternalError}.
9
9
  * @param message The main error message.
10
10
  * @param status The HTTP status code to return.
11
11
  */
@@ -16,6 +16,11 @@ export class InternalError extends AbstractError {
16
16
  // constructor instead of the code location we're actually interested in.
17
17
  Error.captureStackTrace(this, InternalError);
18
18
  }
19
+ /**
20
+ * Converts an error into an {@link InternalError}.
21
+ * @param error The error to convert.
22
+ * @returns An {@link InternalError} that represents the given error.
23
+ */
19
24
  static fromError(error) {
20
25
  // Create a _real_ `InternalError` instance, which we will return later.
21
26
  const internalError = new InternalError(error.message);
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InternalError.js","sourceRoot":"","sources":["../../source/errors/InternalError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;;GAGG;AACH,MAAM,OAAO,aAAc,SAAQ,aAAa;IAC9C;;;;OAIG;IACH,YAAY,OAAe,EAAE,MAAM,GAAG,GAAG;QACvC,KAAK,CAAC,iBAAiB,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QAE1C,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAE5B,qEAAqE;QACrE,yEAAyE;QACzE,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IAC/C,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,SAAS,CAAC,KAAY;QAC3B,wEAAwE;QACxE,MAAM,aAAa,GAAG,IAAI,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACvD,kEAAkE;QAClE,mEAAmE;QACnE,0BAA0B;QAC1B,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,KAAK,EAAE,IAAI,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QACtE,uBAAuB;QACvB,aAAa,CAAC,KAAK,GAAG,KAAK,CAAC;QAC5B,0CAA0C;QAC1C,aAAa,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;QAElC,OAAO,aAAa,CAAC;IACvB,CAAC;CACF"}
@@ -5,7 +5,7 @@ import { AbstractError } from "./AbstractError.js";
5
5
  */
6
6
  export declare class InvalidArgumentError extends AbstractError {
7
7
  /**
8
- * Constructs a new `InvalidArgumentError`.
8
+ * Constructs a new {@link InvalidArgumentError}.
9
9
  * @param message The main error message.
10
10
  * @param status The HTTP status code to return.
11
11
  */
@@ -5,7 +5,7 @@ import { AbstractError } from "./AbstractError.js";
5
5
  */
6
6
  export class InvalidArgumentError extends AbstractError {
7
7
  /**
8
- * Constructs a new `InvalidArgumentError`.
8
+ * Constructs a new {@link InvalidArgumentError}.
9
9
  * @param message The main error message.
10
10
  * @param status The HTTP status code to return.
11
11
  */
@@ -5,7 +5,7 @@ import { AbstractError } from "./AbstractError.js";
5
5
  */
6
6
  export declare class InvalidOperationError extends AbstractError {
7
7
  /**
8
- * Constructs a new `InvalidOperationError`.
8
+ * Constructs a new {@link InvalidOperationError}.
9
9
  * @param message The main error message.
10
10
  * @param status The HTTP status code to return.
11
11
  */
@@ -5,7 +5,7 @@ import { AbstractError } from "./AbstractError.js";
5
5
  */
6
6
  export class InvalidOperationError extends AbstractError {
7
7
  /**
8
- * Constructs a new `InvalidOperationError`.
8
+ * Constructs a new {@link InvalidOperationError}.
9
9
  * @param message The main error message.
10
10
  * @param status The HTTP status code to return.
11
11
  */
@@ -4,7 +4,7 @@ import { AbstractError } from "./AbstractError.js";
4
4
  */
5
5
  export declare class NotImplementedError extends AbstractError {
6
6
  /**
7
- * Constructs a new `NotImplementedError`.
7
+ * Constructs a new {@link NotImplementedError}.
8
8
  * @param message The main error message.
9
9
  * @param status The HTTP status code to return.
10
10
  */
@@ -4,7 +4,7 @@ import { AbstractError } from "./AbstractError.js";
4
4
  */
5
5
  export class NotImplementedError extends AbstractError {
6
6
  /**
7
- * Constructs a new `NotImplementedError`.
7
+ * Constructs a new {@link NotImplementedError}.
8
8
  * @param message The main error message.
9
9
  * @param status The HTTP status code to return.
10
10
  */
@@ -5,7 +5,7 @@ import { AbstractError } from "./AbstractError.js";
5
5
  */
6
6
  export declare class PermissionViolationError extends AbstractError {
7
7
  /**
8
- * Constructs a new `PermissionViolationError`.
8
+ * Constructs a new {@link PermissionViolationError}.
9
9
  * @param message The main error message.
10
10
  * @param status The HTTP status code to return.
11
11
  */
@@ -5,7 +5,7 @@ import { AbstractError } from "./AbstractError.js";
5
5
  */
6
6
  export class PermissionViolationError extends AbstractError {
7
7
  /**
8
- * Constructs a new `PermissionViolationError`.
8
+ * Constructs a new {@link PermissionViolationError}.
9
9
  * @param message The main error message.
10
10
  * @param status The HTTP status code to return.
11
11
  */
@@ -4,7 +4,7 @@ import { AbstractError } from "./AbstractError.js";
4
4
  */
5
5
  export declare class ResourceConflictError extends AbstractError {
6
6
  /**
7
- * Constructs a new `ResourceConflictError`.
7
+ * Constructs a new {@link ResourceConflictError}.
8
8
  * @param message The main error message.
9
9
  * @param status The HTTP status code to return.
10
10
  */
@@ -4,7 +4,7 @@ import { AbstractError } from "./AbstractError.js";
4
4
  */
5
5
  export class ResourceConflictError extends AbstractError {
6
6
  /**
7
- * Constructs a new `ResourceConflictError`.
7
+ * Constructs a new {@link ResourceConflictError}.
8
8
  * @param message The main error message.
9
9
  * @param status The HTTP status code to return.
10
10
  */
@@ -4,11 +4,11 @@ import { AbstractError } from "./AbstractError.js";
4
4
  * real `Error` instance.
5
5
  * Like when you catch a `throw "boom"`, we will convert the caught `"boom"`
6
6
  * into an `UnknownError`.
7
- * To enrich an `Error`-like object that was caught, use the `InternalError`.
7
+ * To enrich an `Error`-like object that was caught, use the {@link InternalError}.
8
8
  */
9
9
  export declare class UnknownError extends AbstractError {
10
10
  /**
11
- * Constructs a new `UnknownError`.
11
+ * Constructs a new {@link UnknownError}.
12
12
  * @param message The main error message.
13
13
  * @param status The HTTP status code to return.
14
14
  */
@@ -4,11 +4,11 @@ import { AbstractError } from "./AbstractError.js";
4
4
  * real `Error` instance.
5
5
  * Like when you catch a `throw "boom"`, we will convert the caught `"boom"`
6
6
  * into an `UnknownError`.
7
- * To enrich an `Error`-like object that was caught, use the `InternalError`.
7
+ * To enrich an `Error`-like object that was caught, use the {@link InternalError}.
8
8
  */
9
9
  export class UnknownError extends AbstractError {
10
10
  /**
11
- * Constructs a new `UnknownError`.
11
+ * Constructs a new {@link UnknownError}.
12
12
  * @param message The main error message.
13
13
  * @param status The HTTP status code to return.
14
14
  */
@@ -0,0 +1,80 @@
1
+ /// <reference types="@types/web" />
2
+ /**
3
+ * A wrapper around {@linkcode https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement HTMLCanvasElement}
4
+ * to provide some convience for double-buffered drawing.
5
+ */
6
+ export declare class Canvas {
7
+ readonly canvas: HTMLCanvasElement;
8
+ readonly width: number;
9
+ readonly height: number;
10
+ readonly context: CanvasRenderingContext2D;
11
+ readonly pixMap: ImageData;
12
+ readonly buffer: Uint8ClampedArray;
13
+ /**
14
+ * Constructs a new {@link Canvas}.
15
+ * @param canvas The canvas to wrap.
16
+ * @param width The width of the canvas.
17
+ * @param height The height of the canvas.
18
+ */
19
+ constructor(canvas: HTMLCanvasElement, width: number, height: number);
20
+ /**
21
+ * Draws the backbuffer onto the canvas.
22
+ */
23
+ update(): void;
24
+ /**
25
+ * Returns the color of a pixel in the backbuffer.
26
+ * @param x The X coordinate to retrieve.
27
+ * @param y The X coordinate to retrieve.
28
+ * @returns The color of the pixel at the given local.
29
+ */
30
+ getPixel32(x: number, y: number): number;
31
+ /**
32
+ * Colors a pixel in the backbuffer.
33
+ * @param x The X coordinate to color.
34
+ * @param y The Y coordinate to color.
35
+ * @param color The color to place at the coordinate.
36
+ */
37
+ setPixel32(x: number, y: number, color: number): void;
38
+ /**
39
+ * Fills the entire backbuffer with the given color.
40
+ * @param color The color to fill the backbuffer with.
41
+ */
42
+ clearWith(color: number): void;
43
+ }
44
+ /**
45
+ * Linearly blends a new pixel with an existing color value in a {@link Canvas}.
46
+ * @param canvas The {@link Canvas} to interact with.
47
+ * @param x The X coordinate at which to place the pixel.
48
+ * @param y The Y coordinate at which to place the pixel.
49
+ * @param color The color of the pixel.
50
+ * @param alpha The alpha value to use to blend the pixel with existing color at the location.
51
+ */
52
+ export declare const putPixel32: (canvas: Canvas, x: number, y: number, color: number, alpha: number) => void;
53
+ /**
54
+ * Additively blends a new pixel with an existing color value in a {@link Canvas}.
55
+ * @param canvas The {@link Canvas} to interact with.
56
+ * @param x The X coordinate at which to place the pixel.
57
+ * @param y The Y coordinate at which to place the pixel.
58
+ * @param color The color of the pixel.
59
+ * @param alpha The alpha value to use to blend the pixel with existing color at the location.
60
+ */
61
+ export declare const putPixel32Add: (canvas: Canvas, x: number, y: number, color: number, alpha: number) => void;
62
+ /**
63
+ * Subtractively blends a new pixel with an existing color value in a {@link Canvas}.
64
+ * @param canvas The {@link Canvas} to interact with.
65
+ * @param x The X coordinate at which to place the pixel.
66
+ * @param y The Y coordinate at which to place the pixel.
67
+ * @param color The color of the pixel.
68
+ * @param alpha The alpha value to use to blend the pixel with existing color at the location.
69
+ */
70
+ export declare const putPixel32Sub: (canvas: Canvas, x: number, y: number, color: number, alpha: number) => void;
71
+ /**
72
+ * Linearly blends a new pixel with an existing color value in a {@link Canvas}.
73
+ * Compared to {@link putPixel32}, this function supports sub-pixel placement, but is dramatically slower.
74
+ * @param canvas The {@link Canvas} to interact with.
75
+ * @param x The X coordinate at which to place the pixel.
76
+ * @param y The Y coordinate at which to place the pixel.
77
+ * @param color The color of the pixel.
78
+ * @param alpha The alpha value to use to blend the pixel with existing color at the location.
79
+ */
80
+ export declare const putSubPixel32: (canvas: Canvas, x: number, y: number, color: number, alpha: number) => void;
@@ -0,0 +1,164 @@
1
+ import { mustExist } from "../nil.js";
2
+ import { blend, blendAdditive, blendSubtractive, fromRGBA, getA, getB, getG, getR, } from "./core.js";
3
+ /**
4
+ * A wrapper around {@linkcode https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement HTMLCanvasElement}
5
+ * to provide some convience for double-buffered drawing.
6
+ */
7
+ export class Canvas {
8
+ canvas;
9
+ width;
10
+ height;
11
+ context;
12
+ pixMap;
13
+ buffer;
14
+ /**
15
+ * Constructs a new {@link Canvas}.
16
+ * @param canvas The canvas to wrap.
17
+ * @param width The width of the canvas.
18
+ * @param height The height of the canvas.
19
+ */
20
+ constructor(canvas, width, height) {
21
+ this.canvas = canvas;
22
+ this.width = width;
23
+ this.height = height;
24
+ this.context = mustExist(this.canvas.getContext("2d"), "Unable to create rendering context.");
25
+ this.pixMap = this.context.createImageData(width, height);
26
+ this.buffer = this.pixMap.data;
27
+ this.context.font = "12px sans-serif";
28
+ }
29
+ /**
30
+ * Draws the backbuffer onto the canvas.
31
+ */
32
+ update() {
33
+ this.context.putImageData(this.pixMap, 0, 0);
34
+ }
35
+ /**
36
+ * Returns the color of a pixel in the backbuffer.
37
+ * @param x The X coordinate to retrieve.
38
+ * @param y The X coordinate to retrieve.
39
+ * @returns The color of the pixel at the given local.
40
+ */
41
+ getPixel32(x, y) {
42
+ const bufferOffset = Math.trunc((x + y * this.width) * 4);
43
+ return fromRGBA(this.buffer[bufferOffset + 0], this.buffer[bufferOffset + 1], this.buffer[bufferOffset + 2], this.buffer[bufferOffset + 3]);
44
+ }
45
+ /**
46
+ * Colors a pixel in the backbuffer.
47
+ * @param x The X coordinate to color.
48
+ * @param y The Y coordinate to color.
49
+ * @param color The color to place at the coordinate.
50
+ */
51
+ setPixel32(x, y, color) {
52
+ const bufferOffset = Math.trunc((x + y * this.width) * 4);
53
+ this.buffer[bufferOffset + 0] = getR(color);
54
+ this.buffer[bufferOffset + 1] = getG(color);
55
+ this.buffer[bufferOffset + 2] = getB(color);
56
+ this.buffer[bufferOffset + 3] = getA(color);
57
+ }
58
+ /**
59
+ * Fills the entire backbuffer with the given color.
60
+ * @param color The color to fill the backbuffer with.
61
+ */
62
+ clearWith(color) {
63
+ const r = getR(color);
64
+ const g = getG(color);
65
+ const b = getB(color);
66
+ const a = getA(color);
67
+ for (let bufferOffset = 0; bufferOffset < this.width * this.height * 4; bufferOffset += 4) {
68
+ this.buffer[bufferOffset + 0] = r;
69
+ this.buffer[bufferOffset + 1] = g;
70
+ this.buffer[bufferOffset + 2] = b;
71
+ this.buffer[bufferOffset + 3] = a;
72
+ }
73
+ }
74
+ }
75
+ /**
76
+ * Linearly blends a new pixel with an existing color value in a {@link Canvas}.
77
+ * @param canvas The {@link Canvas} to interact with.
78
+ * @param x The X coordinate at which to place the pixel.
79
+ * @param y The Y coordinate at which to place the pixel.
80
+ * @param color The color of the pixel.
81
+ * @param alpha The alpha value to use to blend the pixel with existing color at the location.
82
+ */
83
+ export const putPixel32 = (canvas, x, y, color, alpha) => {
84
+ if (canvas.width < x || x < 0 || canvas.height < y || y < 0) {
85
+ return;
86
+ }
87
+ x = Math.trunc(x);
88
+ y = Math.trunc(y);
89
+ if (alpha > 255) {
90
+ alpha = 255;
91
+ }
92
+ const srcColor = canvas.getPixel32(x, y);
93
+ const newColor = blend(srcColor, color, alpha);
94
+ canvas.setPixel32(x, y, newColor);
95
+ };
96
+ /**
97
+ * Additively blends a new pixel with an existing color value in a {@link Canvas}.
98
+ * @param canvas The {@link Canvas} to interact with.
99
+ * @param x The X coordinate at which to place the pixel.
100
+ * @param y The Y coordinate at which to place the pixel.
101
+ * @param color The color of the pixel.
102
+ * @param alpha The alpha value to use to blend the pixel with existing color at the location.
103
+ */
104
+ export const putPixel32Add = (canvas, x, y, color, alpha) => {
105
+ if (canvas.width < x || x < 0 || canvas.height < y || y < 0) {
106
+ return;
107
+ }
108
+ x = Math.round(x);
109
+ y = Math.round(y);
110
+ if (alpha > 255) {
111
+ alpha = 255;
112
+ }
113
+ const srcColor = canvas.getPixel32(x, y);
114
+ const newColor = blendAdditive(srcColor, color, alpha);
115
+ canvas.setPixel32(x, y, newColor);
116
+ };
117
+ /**
118
+ * Subtractively blends a new pixel with an existing color value in a {@link Canvas}.
119
+ * @param canvas The {@link Canvas} to interact with.
120
+ * @param x The X coordinate at which to place the pixel.
121
+ * @param y The Y coordinate at which to place the pixel.
122
+ * @param color The color of the pixel.
123
+ * @param alpha The alpha value to use to blend the pixel with existing color at the location.
124
+ */
125
+ export const putPixel32Sub = (canvas, x, y, color, alpha) => {
126
+ if (canvas.width < x || x < 0 || canvas.height < y || y < 0) {
127
+ return;
128
+ }
129
+ x = Math.round(x);
130
+ y = Math.round(y);
131
+ if (alpha > 255) {
132
+ alpha = 255;
133
+ }
134
+ const srcColor = canvas.getPixel32(x, y);
135
+ const newColor = blendSubtractive(srcColor, color, alpha);
136
+ canvas.setPixel32(x, y, newColor);
137
+ };
138
+ /**
139
+ * Linearly blends a new pixel with an existing color value in a {@link Canvas}.
140
+ * Compared to {@link putPixel32}, this function supports sub-pixel placement, but is dramatically slower.
141
+ * @param canvas The {@link Canvas} to interact with.
142
+ * @param x The X coordinate at which to place the pixel.
143
+ * @param y The Y coordinate at which to place the pixel.
144
+ * @param color The color of the pixel.
145
+ * @param alpha The alpha value to use to blend the pixel with existing color at the location.
146
+ */
147
+ export const putSubPixel32 = (canvas, x, y, color, alpha) => {
148
+ if (canvas.width < x || x < 0 || canvas.height < y || y < 0) {
149
+ return;
150
+ }
151
+ const xweight = x - Math.trunc(x);
152
+ const yweight = y - Math.trunc(y);
153
+ const xweightn = 1 - xweight;
154
+ const yweightn = 1 - yweight;
155
+ const alpha0 = xweightn * yweightn * alpha;
156
+ const alpha1 = xweight * yweightn * alpha;
157
+ const alpha2 = xweightn * yweight * alpha;
158
+ const alpha3 = xweight * yweight * alpha;
159
+ putPixel32(canvas, x + 0, y + 0, color, alpha0);
160
+ putPixel32(canvas, x + 1, y + 0, color, alpha1);
161
+ putPixel32(canvas, x + 0, y + 1, color, alpha2);
162
+ putPixel32(canvas, x + 1, y + 1, color, alpha3);
163
+ };
164
+ //# sourceMappingURL=canvas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canvas.js","sourceRoot":"","sources":["../../source/graphics/canvas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAA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,EACb,KAAa,EACb,EAAE;IACF,IAAI,MAAM,CAAC,KAAK,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;QAC3D,OAAO;KACR;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"}
@@ -0,0 +1,94 @@
1
+ export declare const PALETTES: number[][];
2
+ /**
3
+ * Constrains a color component value to single-byte range (`0`-`255`).
4
+ * @param c A color component value.
5
+ * @returns The input value constrained into single-byte range.
6
+ */
7
+ export declare const safeRGBComponent: (c: number) => number;
8
+ /**
9
+ * Constructs a 32bit integer value that represents an RGBA color value.
10
+ * @param r The R component.
11
+ * @param g The G component.
12
+ * @param b The B component.
13
+ * @param a The A component.
14
+ * @returns The constructed color value.
15
+ */
16
+ export declare const fromRGBA: (r: number, g: number, b: number, a: number) => number;
17
+ /**
18
+ * Constructs a 32bit integer value that represents an RGBA color value.
19
+ * The A component is fixed to `255`
20
+ * @param r The R component.
21
+ * @param g The G component.
22
+ * @param b The B component.
23
+ * @returns The constructed color value.
24
+ */
25
+ export declare const fromRGB: (r: number, g: number, b: number) => number;
26
+ /**
27
+ * Extracts the R component from a color value.
28
+ * @param color The color value.
29
+ * @returns The R component of the color value.
30
+ */
31
+ export declare const getR: (color: number) => number;
32
+ /**
33
+ * Extracts the G component from a color value.
34
+ * @param color The color value.
35
+ * @returns The G component of the color value.
36
+ */
37
+ export declare const getG: (color: number) => number;
38
+ /**
39
+ * Extracts the B component from a color value.
40
+ * @param color The color value.
41
+ * @returns The B component of the color value.
42
+ */
43
+ export declare const getB: (color: number) => number;
44
+ /**
45
+ * Extracts the A component from a color value.
46
+ * @param color The color value.
47
+ * @returns The A component of the color value.
48
+ */
49
+ export declare const getA: (color: number) => number;
50
+ /**
51
+ * Returns a new color that is a blend between a source and a destination
52
+ * color linerally. The alpha component in these colors is ignored. Instead, the provided
53
+ * `alpha` value is used to blend between the two colors.
54
+ * @param src The source color.
55
+ * @param dst The destination color.
56
+ * @param alpha The alpha value to use for blending.
57
+ * @returns The blended color.
58
+ */
59
+ export declare const blend: (src: number, dst: number, alpha: number) => number;
60
+ /**
61
+ * Returns a new color that is a blend between a source and a destination
62
+ * color additively. The alpha component in these colors is ignored. Instead, the provided
63
+ * `alpha` value is used to blend between the two colors.
64
+ * @param src The source color.
65
+ * @param dst The destination color.
66
+ * @param alpha The alpha value to use for blending.
67
+ * @returns The blended color.
68
+ */
69
+ export declare const blendAdditive: (src: number, dst: number, alpha: number) => number;
70
+ /**
71
+ * Returns a new color that is a blend between a source and a destination
72
+ * color subtractively. The alpha component in these colors is ignored. Instead, the provided
73
+ * `alpha` value is used to blend between the two colors.
74
+ * @param src The source color.
75
+ * @param dst The destination color.
76
+ * @param alpha The alpha value to use for blending.
77
+ * @returns The blended color.
78
+ */
79
+ export declare const blendSubtractive: (src: number, dst: number, alpha: number) => number;
80
+ /**
81
+ * Retrieves a random color from the current global palette.
82
+ * @returns A random color.
83
+ */
84
+ export declare const somecolor: () => number;
85
+ /**
86
+ * Switches the global palette to the next available preset.
87
+ */
88
+ export declare const nextPalette: () => void;
89
+ /**
90
+ * Converts a color value to grayscale.
91
+ * @param color The color to convert.
92
+ * @returns The grayscale value appropriate for the color.
93
+ */
94
+ export declare const toGrayScale: (color: number) => number;