@oliversalzburg/js-utils 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/lib/async/async.d.ts +44 -0
  2. package/lib/async/async.js +76 -0
  3. package/lib/async/async.js.map +1 -0
  4. package/lib/async/async.test.d.ts +1 -0
  5. package/lib/async/async.test.js +26 -0
  6. package/lib/async/async.test.js.map +1 -0
  7. package/lib/core.d.ts +43 -0
  8. package/lib/core.js +2 -0
  9. package/lib/core.js.map +1 -0
  10. package/lib/data/array.d.ts +55 -0
  11. package/lib/data/array.js +90 -0
  12. package/lib/data/array.js.map +1 -0
  13. package/lib/data/nil.d.ts +92 -0
  14. package/lib/data/nil.js +131 -0
  15. package/lib/data/nil.js.map +1 -0
  16. package/lib/data/random.d.ts +111 -0
  17. package/lib/data/random.js +381 -0
  18. package/lib/data/random.js.map +1 -0
  19. package/lib/data/string.d.ts +30 -0
  20. package/lib/data/string.js +53 -0
  21. package/lib/data/string.js.map +1 -0
  22. package/lib/data/tree.d.ts +28 -0
  23. package/lib/data/tree.js +45 -0
  24. package/lib/data/tree.js.map +1 -0
  25. package/lib/device/shake.d.ts +79 -0
  26. package/lib/device/shake.js +135 -0
  27. package/lib/device/shake.js.map +1 -0
  28. package/lib/dom/core.d.ts +21 -0
  29. package/lib/dom/core.js +41 -0
  30. package/lib/dom/core.js.map +1 -0
  31. package/lib/errors/AbstractError.d.ts +29 -0
  32. package/lib/errors/AbstractError.js +59 -0
  33. package/lib/errors/AbstractError.js.map +1 -0
  34. package/lib/errors/InternalError.d.ts +19 -0
  35. package/lib/errors/InternalError.js +38 -0
  36. package/lib/errors/InternalError.js.map +1 -0
  37. package/lib/errors/InvalidArgumentError.d.ts +13 -0
  38. package/lib/errors/InvalidArgumentError.js +22 -0
  39. package/lib/errors/InvalidArgumentError.js.map +1 -0
  40. package/lib/errors/InvalidOperationError.d.ts +13 -0
  41. package/lib/errors/InvalidOperationError.js +22 -0
  42. package/lib/errors/InvalidOperationError.js.map +1 -0
  43. package/lib/errors/NotImplementedError.d.ts +12 -0
  44. package/lib/errors/NotImplementedError.js +21 -0
  45. package/lib/errors/NotImplementedError.js.map +1 -0
  46. package/lib/errors/PermissionViolationError.d.ts +13 -0
  47. package/lib/errors/PermissionViolationError.js +22 -0
  48. package/lib/errors/PermissionViolationError.js.map +1 -0
  49. package/lib/errors/ResourceConflictError.d.ts +12 -0
  50. package/lib/errors/ResourceConflictError.js +21 -0
  51. package/lib/errors/ResourceConflictError.js.map +1 -0
  52. package/lib/errors/UnknownError.d.ts +16 -0
  53. package/lib/errors/UnknownError.js +25 -0
  54. package/lib/errors/UnknownError.js.map +1 -0
  55. package/lib/errors/console.d.ts +7 -0
  56. package/lib/errors/console.js +13 -0
  57. package/lib/errors/console.js.map +1 -0
  58. package/lib/errors/error-serializer.d.ts +45 -0
  59. package/lib/errors/error-serializer.js +74 -0
  60. package/lib/errors/error-serializer.js.map +1 -0
  61. package/lib/errors/error-serializer.test.d.ts +1 -0
  62. package/lib/errors/error-serializer.test.js +109 -0
  63. package/lib/errors/error-serializer.test.js.map +1 -0
  64. package/lib/errors/stream.d.ts +7 -0
  65. package/lib/errors/stream.js +15 -0
  66. package/lib/errors/stream.js.map +1 -0
  67. package/lib/errors/tools.d.ts +10 -0
  68. package/lib/errors/tools.js +13 -0
  69. package/lib/errors/tools.js.map +1 -0
  70. package/lib/events/event.d.ts +9 -0
  71. package/lib/events/event.js +10 -0
  72. package/lib/events/event.js.map +1 -0
  73. package/lib/format/bytes.d.ts +118 -0
  74. package/lib/format/bytes.js +138 -0
  75. package/lib/format/bytes.js.map +1 -0
  76. package/lib/format/bytes.test.d.ts +1 -0
  77. package/lib/format/bytes.test.js +146 -0
  78. package/lib/format/bytes.test.js.map +1 -0
  79. package/lib/format/count.d.ts +14 -0
  80. package/lib/format/count.js +51 -0
  81. package/lib/format/count.js.map +1 -0
  82. package/lib/format/count.test.d.ts +1 -0
  83. package/lib/format/count.test.js +42 -0
  84. package/lib/format/count.test.js.map +1 -0
  85. package/lib/format/milliseconds.d.ts +100 -0
  86. package/lib/format/milliseconds.js +199 -0
  87. package/lib/format/milliseconds.js.map +1 -0
  88. package/lib/format/milliseconds.test.d.ts +1 -0
  89. package/lib/format/milliseconds.test.js +393 -0
  90. package/lib/format/milliseconds.test.js.map +1 -0
  91. package/lib/format/string.d.ts +24 -0
  92. package/lib/format/string.js +32 -0
  93. package/lib/format/string.js.map +1 -0
  94. package/lib/format/string.test.d.ts +1 -0
  95. package/lib/format/string.test.js +17 -0
  96. package/lib/format/string.test.js.map +1 -0
  97. package/lib/graphics/canvas-sandbox-mp.d.ts +258 -0
  98. package/lib/graphics/canvas-sandbox-mp.js +280 -0
  99. package/lib/graphics/canvas-sandbox-mp.js.map +1 -0
  100. package/lib/graphics/canvas-sandbox.d.ts +255 -0
  101. package/lib/graphics/canvas-sandbox.js +358 -0
  102. package/lib/graphics/canvas-sandbox.js.map +1 -0
  103. package/lib/graphics/canvas.d.ts +57 -0
  104. package/lib/graphics/canvas.js +37 -0
  105. package/lib/graphics/canvas.js.map +1 -0
  106. package/lib/graphics/canvas2d-headless.d.ts +85 -0
  107. package/lib/graphics/canvas2d-headless.js +197 -0
  108. package/lib/graphics/canvas2d-headless.js.map +1 -0
  109. package/lib/graphics/canvas2d.d.ts +162 -0
  110. package/lib/graphics/canvas2d.js +332 -0
  111. package/lib/graphics/canvas2d.js.map +1 -0
  112. package/lib/graphics/canvas3d.d.ts +41 -0
  113. package/lib/graphics/canvas3d.js +67 -0
  114. package/lib/graphics/canvas3d.js.map +1 -0
  115. package/lib/graphics/color.d.ts +22 -0
  116. package/lib/graphics/color.js +38 -0
  117. package/lib/graphics/color.js.map +1 -0
  118. package/lib/graphics/core.d.ts +89 -0
  119. package/lib/graphics/core.js +146 -0
  120. package/lib/graphics/core.js.map +1 -0
  121. package/lib/graphics/palette-sampler.d.ts +7 -0
  122. package/lib/graphics/palette-sampler.js +21 -0
  123. package/lib/graphics/palette-sampler.js.map +1 -0
  124. package/lib/graphics/palette.d.ts +120 -0
  125. package/lib/graphics/palette.js +574 -0
  126. package/lib/graphics/palette.js.map +1 -0
  127. package/lib/graphics/palette.test.d.ts +1 -0
  128. package/lib/graphics/palette.test.js +43 -0
  129. package/lib/graphics/palette.test.js.map +1 -0
  130. package/lib/graphics/render-loop.d.ts +76 -0
  131. package/lib/graphics/render-loop.js +114 -0
  132. package/lib/graphics/render-loop.js.map +1 -0
  133. package/lib/graphics/shader.d.ts +56 -0
  134. package/lib/graphics/shader.js +80 -0
  135. package/lib/graphics/shader.js.map +1 -0
  136. package/lib/log/log.d.ts +11 -0
  137. package/lib/log/log.js +2 -0
  138. package/lib/log/log.js.map +1 -0
  139. package/lib/log/report.d.ts +57 -0
  140. package/lib/log/report.js +88 -0
  141. package/lib/log/report.js.map +1 -0
  142. package/lib/math/core.d.ts +85 -0
  143. package/lib/math/core.js +125 -0
  144. package/lib/math/core.js.map +1 -0
  145. package/lib/math/easing.d.ts +204 -0
  146. package/lib/math/easing.js +366 -0
  147. package/lib/math/easing.js.map +1 -0
  148. package/lib/math/euler.d.ts +18 -0
  149. package/lib/math/euler.js +22 -0
  150. package/lib/math/euler.js.map +1 -0
  151. package/lib/math/matrix3.d.ts +227 -0
  152. package/lib/math/matrix3.js +508 -0
  153. package/lib/math/matrix3.js.map +1 -0
  154. package/lib/math/quaternion.d.ts +119 -0
  155. package/lib/math/quaternion.js +270 -0
  156. package/lib/math/quaternion.js.map +1 -0
  157. package/lib/math/transformation.d.ts +26 -0
  158. package/lib/math/transformation.js +31 -0
  159. package/lib/math/transformation.js.map +1 -0
  160. package/lib/math/vector2.d.ts +202 -0
  161. package/lib/math/vector2.js +310 -0
  162. package/lib/math/vector2.js.map +1 -0
  163. package/lib/math/vector3.d.ts +293 -0
  164. package/lib/math/vector3.js +492 -0
  165. package/lib/math/vector3.js.map +1 -0
  166. package/lib/math/vector4.d.ts +182 -0
  167. package/lib/math/vector4.js +302 -0
  168. package/lib/math/vector4.js.map +1 -0
  169. package/lib/measurement/performance.d.ts +13 -0
  170. package/lib/measurement/performance.js +19 -0
  171. package/lib/measurement/performance.js.map +1 -0
  172. package/lib/tsconfig.tsbuildinfo +1 -0
  173. package/package.json +3 -5
@@ -0,0 +1,146 @@
1
+ /**
2
+ * The golden ratio.
3
+ * @see {@link https://en.wikipedia.org/wiki/Golden_ratio}
4
+ */
5
+ export const GOLDEN_RATIO = 1.618033988749;
6
+ /**
7
+ * Constrains a color component value to single-byte range (`0`-`255`).
8
+ * @param c - A color component value.
9
+ * @returns The input value constrained into single-byte range.
10
+ */
11
+ export const safeRGBComponent = (c) => {
12
+ if (c < 0) {
13
+ c = 0;
14
+ }
15
+ if (255 < c) {
16
+ c = 255;
17
+ }
18
+ return Math.trunc(c);
19
+ };
20
+ /**
21
+ * Constructs a 32bit integer value that represents an RGBA color value.
22
+ * @param r - The R component.
23
+ * @param g - The G component.
24
+ * @param b - The B component.
25
+ * @param a - The A component.
26
+ * @returns The constructed color value.
27
+ */
28
+ export const fromRGBA = (r, g, b, a) => {
29
+ r = safeRGBComponent(r);
30
+ g = safeRGBComponent(g);
31
+ b = safeRGBComponent(b);
32
+ a = safeRGBComponent(a);
33
+ return (r << 24) | (g << 16) | (b << 8) | a;
34
+ };
35
+ /**
36
+ * Constructs a 32bit integer value that represents an RGBA color value.
37
+ * The A component is fixed to `255`
38
+ * @param r - The R component.
39
+ * @param g - The G component.
40
+ * @param b - The B component.
41
+ * @returns The constructed color value.
42
+ */
43
+ export const fromRGB = (r, g, b) => {
44
+ return fromRGBA(r, g, b, 255);
45
+ };
46
+ /**
47
+ * Extracts the R component from a color value.
48
+ * @param color - The color value.
49
+ * @returns The R component of the color value.
50
+ */
51
+ export const getR = (color) => {
52
+ return (color >> 24) & 0xff;
53
+ };
54
+ /**
55
+ * Extracts the G component from a color value.
56
+ * @param color - The color value.
57
+ * @returns The G component of the color value.
58
+ */
59
+ export const getG = (color) => {
60
+ return (color >> 16) & 0xff;
61
+ };
62
+ /**
63
+ * Extracts the B component from a color value.
64
+ * @param color - The color value.
65
+ * @returns The B component of the color value.
66
+ */
67
+ export const getB = (color) => {
68
+ return (color >> 8) & 0xff;
69
+ };
70
+ /**
71
+ * Extracts the A component from a color value.
72
+ * @param color - The color value.
73
+ * @returns The A component of the color value.
74
+ */
75
+ export const getA = (color) => {
76
+ return color & 0xff;
77
+ };
78
+ /**
79
+ * Returns a new color that is a blend between a source and a destination
80
+ * color linerally. The alpha component in these colors is ignored. Instead, the provided
81
+ * `alpha` value is used to blend between the two colors.
82
+ * @param src - The source color.
83
+ * @param dst - The destination color.
84
+ * @param alpha - The alpha value to use for blending.
85
+ * @returns The blended color.
86
+ */
87
+ export const blend = (src, dst, alpha) => {
88
+ if (alpha >= 255) {
89
+ return dst;
90
+ }
91
+ if (alpha <= 0) {
92
+ return src;
93
+ }
94
+ src |= 0;
95
+ dst |= 0;
96
+ return fromRGB((alpha * getR(dst) + (255 - alpha) * getR(src)) >> 8, (alpha * getG(dst) + (255 - alpha) * getG(src)) >> 8, (alpha * getB(dst) + (255 - alpha) * getB(src)) >> 8);
97
+ };
98
+ /**
99
+ * Returns a new color that is a blend between a source and a destination
100
+ * color additively. The alpha component in these colors is ignored. Instead, the provided
101
+ * `alpha` value is used to blend between the two colors.
102
+ * @param src - The source color.
103
+ * @param dst - The destination color.
104
+ * @param alpha - The alpha value to use for blending.
105
+ * @returns The blended color.
106
+ */
107
+ export const blendAdditive = (src, dst, alpha) => {
108
+ if (alpha >= 255) {
109
+ return dst;
110
+ }
111
+ if (alpha <= 0) {
112
+ return src;
113
+ }
114
+ return fromRGB(((alpha * getR(dst)) >> 8) + getR(src), ((alpha * getG(dst)) >> 8) + getG(src), ((alpha * getB(dst)) >> 8) + getB(src));
115
+ };
116
+ /**
117
+ * Returns a new color that is a blend between a source and a destination
118
+ * color subtractively. The alpha component in these colors is ignored. Instead, the provided
119
+ * `alpha` value is used to blend between the two colors.
120
+ * @param src - The source color.
121
+ * @param dst - The destination color.
122
+ * @param alpha - The alpha value to use for blending.
123
+ * @returns The blended color.
124
+ */
125
+ export const blendSubtractive = (src, dst, alpha) => {
126
+ if (alpha >= 255) {
127
+ return dst;
128
+ }
129
+ if (alpha <= 0) {
130
+ return src;
131
+ }
132
+ const r = getR(src) - ((alpha * getR(dst)) >> 8);
133
+ const g = getG(src) - ((alpha * getG(dst)) >> 8);
134
+ const b = getB(src) - ((alpha * getB(dst)) >> 8);
135
+ return fromRGB(r < 0 ? 0 : r, g < 0 ? 0 : g, b < 0 ? 0 : b);
136
+ };
137
+ /**
138
+ * Converts a color value to grayscale.
139
+ * @param color - The color to convert.
140
+ * @returns The grayscale value appropriate for the color.
141
+ */
142
+ export const toGrayScale = (color) => {
143
+ const gs = getR(color) * 0.3 + getG(color) * 0.59 + getB(color) * 0.11;
144
+ return fromRGBA(gs, gs, gs, getA(color));
145
+ };
146
+ //# sourceMappingURL=core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core.js","sourceRoot":"","sources":["../../source/graphics/core.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,cAAc,CAAC;AAE3C;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAS,EAAE,EAAE;IAC7C,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QACX,CAAC,GAAG,CAAC,CAAC;IACP,CAAC;IACD,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC;QACb,CAAC,GAAG,GAAG,CAAC;IACT,CAAC;IACD,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACtB,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,CAAS,EAAE,CAAS,EAAE,CAAS,EAAE,CAAS,EAAE,EAAE;IACtE,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC;IACxB,C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C,KAAK,CAAC,CAAC,CAAC;AAC1C,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { type Palette } from "./palette.js";
2
+ /**
3
+ * Renders the colors of a palette into a canvas.
4
+ * @param palette - The palette to render.
5
+ * @param canvas - The canvas element to render to.
6
+ */
7
+ export declare const renderPaletteSample: (palette: Palette, canvas: HTMLCanvasElement | OffscreenCanvas) => void;
@@ -0,0 +1,21 @@
1
+ import { mustExist } from "../data/nil.js";
2
+ import { paletteName } from "./palette.js";
3
+ /**
4
+ * Renders the colors of a palette into a canvas.
5
+ * @param palette - The palette to render.
6
+ * @param canvas - The canvas element to render to.
7
+ */
8
+ export const renderPaletteSample = (palette, canvas) => {
9
+ const context = mustExist(canvas.getContext("2d"));
10
+ context.globalAlpha = 255;
11
+ const step = canvas.width / palette.colors.length;
12
+ for (let x = 0; x < palette.colors.length; ++x) {
13
+ const fillColor = (palette.colors[x] << 8) | 0xff;
14
+ context.fillStyle = `#${fillColor.toString(16).padStart(8, "0")}`;
15
+ context.fillRect(x * step, 0, step, canvas.height);
16
+ }
17
+ context.font = "13px monospace";
18
+ context.fillStyle = "#ffffffff";
19
+ context.fillText(paletteName(palette.paletteIndex), 5, canvas.height * 0.8);
20
+ };
21
+ //# sourceMappingURL=palette-sampler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"palette-sampler.js","sourceRoot":"","sources":["../../source/graphics/palette-sampler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAgB,WAAW,EAAE,MAAM,cAAc,CAAC;AAEzD;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAClC,OAAgB,EAChB,MAA2C,EAC1C,EAAE;IACH,MAAM,OAAO,GAAG,SAAS,CACxB,MAAM,CAAC,UAAU,CAAC,IAAI,CAGf,CACP,CAAC;IACF,OAAO,CAAC,WAAW,GAAG,GAAG,CAAC;IAE1B,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC;IAClD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC;QAChD,MAAM,SAAS,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC;QAClD,OAAO,CAAC,SAAS,GAAG,IAAI,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;QAClE,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACpD,CAAC;IAED,OAAO,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAChC,OAAO,CAAC,SAAS,GAAG,WAAW,CAAC;IAChC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC;AAC7E,CAAC,CAAC"}
@@ -0,0 +1,120 @@
1
+ import { type Random } from "../data/random.js";
2
+ /**
3
+ * Color palettes that can be used to quickly colorize a drawing.
4
+ */
5
+ export declare const PALETTES: number[][];
6
+ /**
7
+ * The indices of pre-defined palettes, with friendly names.
8
+ * @see {@linkcode PALETTES}
9
+ */
10
+ export declare const NamedPalettes: {
11
+ /**
12
+ * ![Autumn lake colors](../../docs/media/palette-autumn-lake.png)
13
+ */
14
+ AutumnLake: number;
15
+ /**
16
+ * ![Camouflage colors](../../docs/media/palette-camouflage.png)
17
+ */
18
+ Camouflage: number;
19
+ /**
20
+ * ![Frog pond colors](../../docs/media/palette-frog-pond.png)
21
+ */
22
+ FrogPond: number;
23
+ /**
24
+ * ![Lillypads colors](../../docs/media/palette-lillypads.png)
25
+ */
26
+ Lillypads: number;
27
+ /**
28
+ * ![Midnight colors](../../docs/media/palette-midnight.png)
29
+ */
30
+ Midnight: number;
31
+ /**
32
+ * ![Plight colors](../../docs/media/palette-plight.png)
33
+ */
34
+ Plight: number;
35
+ /**
36
+ * ![Riverside colors](../../docs/media/palette-riverside.png)
37
+ */
38
+ Riverside: number;
39
+ /**
40
+ * ![Seaside colors](../../docs/media/palette-seaside.png)
41
+ */
42
+ Seaside: number;
43
+ /**
44
+ * ![Spring colors](../../docs/media/palette-spring.png)
45
+ */
46
+ Spring: number;
47
+ /**
48
+ * ![Sunflower field colors](../../docs/media/palette-sunflower-field.png)
49
+ */
50
+ SunflowerField: number;
51
+ /**
52
+ * ![Terminator colors](../../docs/media/palette-terminator.png)
53
+ */
54
+ Terminator: number;
55
+ /**
56
+ * ![Terra colors](../../docs/media/palette-terra.png)
57
+ */
58
+ Terra: number;
59
+ /**
60
+ * ![Tundra colors](../../docs/media/palette-tundra.png)
61
+ */
62
+ Tundra: number;
63
+ };
64
+ /**
65
+ * Retrieves a friendly name for a pallete index.
66
+ * @param paletteIndex - The index of the pre-defined palette.
67
+ * @returns The friendly name of the palette, or `"<unknown>"`.
68
+ */
69
+ export declare const paletteName: (paletteIndex: number) => string;
70
+ /**
71
+ * Provides pre-defined color values for drawing operations.
72
+ */
73
+ export declare class Palette {
74
+ #private;
75
+ /**
76
+ * Retrieve the index of the currently selected, pre-defined palette values.
77
+ * @see {@linkcode PALETTES}
78
+ * @returns The index of the currently selected, pre-defined palette values.
79
+ */
80
+ get paletteIndex(): number;
81
+ /**
82
+ * Retrieve the 24bit color values of the currently selected palette.
83
+ * @returns The colors in the palette.
84
+ */
85
+ get colors(): ReadonlyArray<number>;
86
+ /**
87
+ * Constructs a new palette.
88
+ * @param paletteIndex - The index of the pre-defined palette to use.
89
+ */
90
+ constructor(paletteIndex?: number);
91
+ /**
92
+ * Uses the next pre-defined color value set for this palette.
93
+ * @returns This instance.
94
+ */
95
+ nextPalette(): this;
96
+ /**
97
+ * Retrieve a random color from the palette.
98
+ * @param randomInstance - The PRNG to use. Ideally, supply your own.
99
+ * @returns A random color from the palette.
100
+ */
101
+ someColor(randomInstance?: Random): number;
102
+ }
103
+ /**
104
+ * A pre-constructed palette instance, for convenience.
105
+ */
106
+ export declare const palette: Palette;
107
+ /**
108
+ * Retrieves a random color from the current global palette.
109
+ * Uses the global {@linkcode random} object.
110
+ * @returns A random color.
111
+ */
112
+ export declare const someColor: () => number;
113
+ /**
114
+ * Switches the global palette to the next available preset.
115
+ * @returns The new new global palette.
116
+ * @deprecated Use {@linkcode Palette} instead.
117
+ */
118
+ export declare const nextPalette: () => number[];
119
+ export declare const hslPalette: (entries: number, shift?: number, saturation?: number, luminance?: number) => Array<[number, number, number]>;
120
+ export declare const hsvPalette: (entries: number, shift?: number, saturation?: number, value?: number) => Array<[number, number, number]>;