@oliversalzburg/js-utils 0.0.3 → 0.0.5

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 (104) 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/mkdocs.yml +52 -0
  31. package/output/core.d.ts +18 -1
  32. package/output/core.js +1 -0
  33. package/output/core.js.map +1 -1
  34. package/output/error-serializer.d.ts +37 -0
  35. package/output/error-serializer.js +63 -0
  36. package/output/error-serializer.js.map +1 -0
  37. package/output/errors/AbstractError.d.ts +42 -0
  38. package/output/errors/AbstractError.js +70 -0
  39. package/output/errors/AbstractError.js.map +1 -0
  40. package/output/errors/InternalError.d.ts +19 -0
  41. package/output/errors/InternalError.js +38 -0
  42. package/output/errors/InternalError.js.map +1 -0
  43. package/output/errors/InvalidArgumentError.d.ts +13 -0
  44. package/output/errors/InvalidArgumentError.js +20 -0
  45. package/output/errors/InvalidArgumentError.js.map +1 -0
  46. package/output/errors/InvalidOperationError.d.ts +13 -0
  47. package/output/errors/InvalidOperationError.js +20 -0
  48. package/output/errors/InvalidOperationError.js.map +1 -0
  49. package/output/errors/NotImplementedError.d.ts +12 -0
  50. package/output/errors/NotImplementedError.js +19 -0
  51. package/output/errors/NotImplementedError.js.map +1 -0
  52. package/output/errors/PermissionViolationError.d.ts +13 -0
  53. package/output/errors/PermissionViolationError.js +20 -0
  54. package/output/errors/PermissionViolationError.js.map +1 -0
  55. package/output/errors/ResourceConflictError.d.ts +12 -0
  56. package/output/errors/ResourceConflictError.js +19 -0
  57. package/output/errors/ResourceConflictError.js.map +1 -0
  58. package/output/errors/UnknownError.d.ts +16 -0
  59. package/output/errors/UnknownError.js +23 -0
  60. package/output/errors/UnknownError.js.map +1 -0
  61. package/output/errors/index.d.ts +8 -0
  62. package/output/errors/index.js +9 -0
  63. package/output/errors/index.js.map +1 -0
  64. package/output/graphics/canvas.d.ts +80 -0
  65. package/output/graphics/canvas.js +164 -0
  66. package/output/graphics/canvas.js.map +1 -0
  67. package/output/graphics/core.d.ts +94 -0
  68. package/output/graphics/core.js +479 -0
  69. package/output/graphics/core.js.map +1 -0
  70. package/output/graphics/index.d.ts +3 -0
  71. package/output/graphics/index.js +4 -0
  72. package/output/graphics/index.js.map +1 -0
  73. package/output/graphics/render-loop.d.ts +20 -0
  74. package/output/graphics/render-loop.js +51 -0
  75. package/output/graphics/render-loop.js.map +1 -0
  76. package/output/index.d.ts +7 -0
  77. package/output/index.js +7 -0
  78. package/output/index.js.map +1 -1
  79. package/output/math/core.d.ts +46 -0
  80. package/output/math/core.js +72 -0
  81. package/output/math/core.js.map +1 -0
  82. package/output/math/index.d.ts +2 -0
  83. package/output/math/index.js +3 -0
  84. package/output/math/index.js.map +1 -0
  85. package/output/math/vector.d.ts +33 -0
  86. package/output/math/vector.js +42 -0
  87. package/output/math/vector.js.map +1 -0
  88. package/output/nil.d.ts +13 -8
  89. package/output/nil.js +16 -11
  90. package/output/nil.js.map +1 -1
  91. package/output/random.d.ts +56 -0
  92. package/output/random.js +184 -0
  93. package/output/random.js.map +1 -0
  94. package/output/string-formatter.d.ts +20 -0
  95. package/output/string-formatter.js +26 -0
  96. package/output/string-formatter.js.map +1 -0
  97. package/output/string-formatter.test.d.ts +1 -0
  98. package/output/string-formatter.test.js +17 -0
  99. package/output/string-formatter.test.js.map +1 -0
  100. package/output/vector.d.ts +10 -0
  101. package/output/vector.js +19 -0
  102. package/output/vector.js.map +1 -0
  103. package/package.json +23 -7
  104. package/typedoc.json +8 -0
@@ -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,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EACL,KAAK,EACL,aAAa,EACb,gBAAgB,EAChB,QAAQ,EACR,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,IAAI,GACL,MAAM,WAAW,CAAC;AAEnB;;;GAGG;AACH,MAAM,OAAO,MAAM;IACR,MAAM,CAAoB;IAC1B,KAAK,CAAS;IACd,MAAM,CAAS;IACf,OAAO,CAA2B;IAClC,MAAM,CAAY;IAClB,MAAM,CAAoB;IAEnC;;;;;OAKG;IACH,YAAY,MAAyB,EAAE,KAAa,EAAE,MAAc;QAClE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,qCAAqC,CAAC,CAAC;QAC9F,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC1D,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;QAE/B,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,iBAAiB,CAAC;IACxC,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAC/C,CAAC;IAED;;;;;O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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;