@oliversalzburg/js-utils 0.7.0 → 0.8.0

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 (178) 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/cli/args.d.ts +9 -0
  8. package/lib/cli/args.js +49 -0
  9. package/lib/cli/args.js.map +1 -0
  10. package/lib/cli/args.test.d.ts +1 -0
  11. package/lib/cli/args.test.js +31 -0
  12. package/lib/cli/args.test.js.map +1 -0
  13. package/lib/core.d.ts +43 -0
  14. package/lib/core.js +2 -0
  15. package/lib/core.js.map +1 -0
  16. package/lib/data/array.d.ts +55 -0
  17. package/lib/data/array.js +90 -0
  18. package/lib/data/array.js.map +1 -0
  19. package/lib/data/nil.d.ts +92 -0
  20. package/lib/data/nil.js +131 -0
  21. package/lib/data/nil.js.map +1 -0
  22. package/lib/data/random.d.ts +111 -0
  23. package/lib/data/random.js +381 -0
  24. package/lib/data/random.js.map +1 -0
  25. package/lib/data/string.d.ts +30 -0
  26. package/lib/data/string.js +53 -0
  27. package/lib/data/string.js.map +1 -0
  28. package/lib/data/tree.d.ts +28 -0
  29. package/lib/data/tree.js +45 -0
  30. package/lib/data/tree.js.map +1 -0
  31. package/lib/device/shake.d.ts +79 -0
  32. package/lib/device/shake.js +135 -0
  33. package/lib/device/shake.js.map +1 -0
  34. package/lib/dom/core.d.ts +21 -0
  35. package/lib/dom/core.js +41 -0
  36. package/lib/dom/core.js.map +1 -0
  37. package/lib/errors/AbstractError.d.ts +29 -0
  38. package/lib/errors/AbstractError.js +59 -0
  39. package/lib/errors/AbstractError.js.map +1 -0
  40. package/lib/errors/InternalError.d.ts +19 -0
  41. package/lib/errors/InternalError.js +38 -0
  42. package/lib/errors/InternalError.js.map +1 -0
  43. package/lib/errors/InvalidArgumentError.d.ts +13 -0
  44. package/lib/errors/InvalidArgumentError.js +22 -0
  45. package/lib/errors/InvalidArgumentError.js.map +1 -0
  46. package/lib/errors/InvalidOperationError.d.ts +13 -0
  47. package/lib/errors/InvalidOperationError.js +22 -0
  48. package/lib/errors/InvalidOperationError.js.map +1 -0
  49. package/lib/errors/NotImplementedError.d.ts +12 -0
  50. package/lib/errors/NotImplementedError.js +21 -0
  51. package/lib/errors/NotImplementedError.js.map +1 -0
  52. package/lib/errors/PermissionViolationError.d.ts +13 -0
  53. package/lib/errors/PermissionViolationError.js +22 -0
  54. package/lib/errors/PermissionViolationError.js.map +1 -0
  55. package/lib/errors/ResourceConflictError.d.ts +12 -0
  56. package/lib/errors/ResourceConflictError.js +21 -0
  57. package/lib/errors/ResourceConflictError.js.map +1 -0
  58. package/lib/errors/UnknownError.d.ts +16 -0
  59. package/lib/errors/UnknownError.js +25 -0
  60. package/lib/errors/UnknownError.js.map +1 -0
  61. package/lib/errors/console.d.ts +7 -0
  62. package/lib/errors/console.js +13 -0
  63. package/lib/errors/console.js.map +1 -0
  64. package/lib/errors/error-serializer.d.ts +45 -0
  65. package/lib/errors/error-serializer.js +74 -0
  66. package/lib/errors/error-serializer.js.map +1 -0
  67. package/lib/errors/error-serializer.test.d.ts +1 -0
  68. package/lib/errors/error-serializer.test.js +109 -0
  69. package/lib/errors/error-serializer.test.js.map +1 -0
  70. package/lib/errors/stream.d.ts +7 -0
  71. package/lib/errors/stream.js +15 -0
  72. package/lib/errors/stream.js.map +1 -0
  73. package/lib/errors/tools.d.ts +10 -0
  74. package/lib/errors/tools.js +13 -0
  75. package/lib/errors/tools.js.map +1 -0
  76. package/lib/events/event.d.ts +9 -0
  77. package/lib/events/event.js +10 -0
  78. package/lib/events/event.js.map +1 -0
  79. package/lib/format/bytes.d.ts +118 -0
  80. package/lib/format/bytes.js +138 -0
  81. package/lib/format/bytes.js.map +1 -0
  82. package/lib/format/bytes.test.d.ts +1 -0
  83. package/lib/format/bytes.test.js +146 -0
  84. package/lib/format/bytes.test.js.map +1 -0
  85. package/lib/format/count.d.ts +14 -0
  86. package/lib/format/count.js +51 -0
  87. package/lib/format/count.js.map +1 -0
  88. package/lib/format/count.test.d.ts +1 -0
  89. package/lib/format/count.test.js +42 -0
  90. package/lib/format/count.test.js.map +1 -0
  91. package/lib/format/milliseconds.d.ts +100 -0
  92. package/lib/format/milliseconds.js +199 -0
  93. package/lib/format/milliseconds.js.map +1 -0
  94. package/lib/format/milliseconds.test.d.ts +1 -0
  95. package/lib/format/milliseconds.test.js +393 -0
  96. package/lib/format/milliseconds.test.js.map +1 -0
  97. package/lib/format/string.d.ts +24 -0
  98. package/lib/format/string.js +32 -0
  99. package/lib/format/string.js.map +1 -0
  100. package/lib/format/string.test.d.ts +1 -0
  101. package/lib/format/string.test.js +17 -0
  102. package/lib/format/string.test.js.map +1 -0
  103. package/lib/graphics/canvas-sandbox-mp.d.ts +258 -0
  104. package/lib/graphics/canvas-sandbox-mp.js +280 -0
  105. package/lib/graphics/canvas-sandbox-mp.js.map +1 -0
  106. package/lib/graphics/canvas-sandbox.d.ts +255 -0
  107. package/lib/graphics/canvas-sandbox.js +358 -0
  108. package/lib/graphics/canvas-sandbox.js.map +1 -0
  109. package/lib/graphics/canvas.d.ts +57 -0
  110. package/lib/graphics/canvas.js +37 -0
  111. package/lib/graphics/canvas.js.map +1 -0
  112. package/lib/graphics/canvas2d-headless.d.ts +85 -0
  113. package/lib/graphics/canvas2d-headless.js +197 -0
  114. package/lib/graphics/canvas2d-headless.js.map +1 -0
  115. package/lib/graphics/canvas2d.d.ts +162 -0
  116. package/lib/graphics/canvas2d.js +332 -0
  117. package/lib/graphics/canvas2d.js.map +1 -0
  118. package/lib/graphics/canvas3d.d.ts +41 -0
  119. package/lib/graphics/canvas3d.js +67 -0
  120. package/lib/graphics/canvas3d.js.map +1 -0
  121. package/lib/graphics/color.d.ts +22 -0
  122. package/lib/graphics/color.js +38 -0
  123. package/lib/graphics/color.js.map +1 -0
  124. package/lib/graphics/core.d.ts +89 -0
  125. package/lib/graphics/core.js +146 -0
  126. package/lib/graphics/core.js.map +1 -0
  127. package/lib/graphics/palette-sampler.d.ts +7 -0
  128. package/lib/graphics/palette-sampler.js +21 -0
  129. package/lib/graphics/palette-sampler.js.map +1 -0
  130. package/lib/graphics/palette.d.ts +120 -0
  131. package/lib/graphics/palette.js +574 -0
  132. package/lib/graphics/palette.js.map +1 -0
  133. package/lib/graphics/palette.test.d.ts +1 -0
  134. package/lib/graphics/palette.test.js +43 -0
  135. package/lib/graphics/palette.test.js.map +1 -0
  136. package/lib/graphics/render-loop.d.ts +76 -0
  137. package/lib/graphics/render-loop.js +114 -0
  138. package/lib/graphics/render-loop.js.map +1 -0
  139. package/lib/graphics/shader.d.ts +56 -0
  140. package/lib/graphics/shader.js +80 -0
  141. package/lib/graphics/shader.js.map +1 -0
  142. package/lib/log/log.d.ts +11 -0
  143. package/lib/log/log.js +2 -0
  144. package/lib/log/log.js.map +1 -0
  145. package/lib/log/report.d.ts +57 -0
  146. package/lib/log/report.js +88 -0
  147. package/lib/log/report.js.map +1 -0
  148. package/lib/math/core.d.ts +85 -0
  149. package/lib/math/core.js +125 -0
  150. package/lib/math/core.js.map +1 -0
  151. package/lib/math/easing.d.ts +204 -0
  152. package/lib/math/easing.js +366 -0
  153. package/lib/math/easing.js.map +1 -0
  154. package/lib/math/euler.d.ts +18 -0
  155. package/lib/math/euler.js +22 -0
  156. package/lib/math/euler.js.map +1 -0
  157. package/lib/math/matrix3.d.ts +227 -0
  158. package/lib/math/matrix3.js +508 -0
  159. package/lib/math/matrix3.js.map +1 -0
  160. package/lib/math/quaternion.d.ts +119 -0
  161. package/lib/math/quaternion.js +270 -0
  162. package/lib/math/quaternion.js.map +1 -0
  163. package/lib/math/transformation.d.ts +26 -0
  164. package/lib/math/transformation.js +31 -0
  165. package/lib/math/transformation.js.map +1 -0
  166. package/lib/math/vector2.d.ts +202 -0
  167. package/lib/math/vector2.js +310 -0
  168. package/lib/math/vector2.js.map +1 -0
  169. package/lib/math/vector3.d.ts +293 -0
  170. package/lib/math/vector3.js +492 -0
  171. package/lib/math/vector3.js.map +1 -0
  172. package/lib/math/vector4.d.ts +182 -0
  173. package/lib/math/vector4.js +302 -0
  174. package/lib/math/vector4.js.map +1 -0
  175. package/lib/measurement/performance.d.ts +13 -0
  176. package/lib/measurement/performance.js +19 -0
  177. package/lib/measurement/performance.js.map +1 -0
  178. package/package.json +5 -7
@@ -0,0 +1,53 @@
1
+ import { mustExist } from "./nil.js";
2
+ /**
3
+ * Indent every line of the passed text.
4
+ * @param subject - The text to indent.
5
+ * @param depth - How often to apply the indenting.
6
+ * @param prefix - The string to use as the indent.
7
+ * @returns The indented text.
8
+ */
9
+ export const indent = (subject, depth = 0, prefix = " ") => subject.replaceAll(/^/gm, prefix.repeat(depth));
10
+ /**
11
+ * A fast and simple 53-bit string hash function with decent collision resistance.
12
+ * Largely inspired by MurmurHash2/3, but with a focus on speed/simplicity.
13
+ * License: Public domain. Attribution appreciated.
14
+ * cyrb53 (c) 2018 bryc (github.com/bryc)
15
+ * @param subject - The string to hash.
16
+ * @param seed - An optional seed value.
17
+ * @returns A hash of the string.
18
+ */
19
+ export const hashCyrb53 = (subject, seed = 0) => {
20
+ let h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed;
21
+ for (let i = 0, ch = 0; i < subject.length; i++) {
22
+ ch = subject.charCodeAt(i);
23
+ h1 = Math.imul(h1 ^ ch, 2654435761);
24
+ h2 = Math.imul(h2 ^ ch, 1597334677);
25
+ }
26
+ h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507);
27
+ h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909);
28
+ h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507);
29
+ h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909);
30
+ return ((h2 >>> 0).toString(16).padStart(8, "0") +
31
+ (h1 >>> 0).toString(16).padStart(8, "0"));
32
+ };
33
+ /**
34
+ * Encodes the provided string in Base64.
35
+ * @param subject - The string to encode.
36
+ * @returns The subject string encoded in Base64.
37
+ */
38
+ export const base64Encode = (subject) => {
39
+ const bytes = new TextEncoder().encode(subject);
40
+ const binString = String.fromCodePoint(...bytes);
41
+ return btoa(binString);
42
+ };
43
+ /**
44
+ * Decodes the provided Base64 encoded string.
45
+ * @param subject - The string to decode.
46
+ * @returns The decoded subject string.
47
+ */
48
+ export const base64Decode = (subject) => {
49
+ const binString = atob(subject);
50
+ const bytes = Uint8Array.from(binString, (m) => mustExist(m.codePointAt(0)));
51
+ return new TextDecoder().decode(bytes);
52
+ };
53
+ //# sourceMappingURL=string.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.js","sourceRoot":"","sources":["../../source/data/string.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,OAAe,EAAE,KAAK,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,EAAU,EAAE,CAC7E,OAAO,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AAEjD;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAAe,EAAE,IAAI,GAAG,CAAC,EAAU,EAAE;IAC/D,IAAI,EAAE,GAAG,UAAU,GAAG,IAAI,EACzB,EAAE,GAAG,UAAU,GAAG,IAAI,CAAC;IACxB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACjD,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAC3B,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,EAAE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,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7E,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACxC,CAAC,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Base class to quickly provide parent-child relationships.
3
+ * @typeParam TNode - Your sub-class.
4
+ */
5
+ export declare abstract class TreeNode<TNode> {
6
+ #private;
7
+ /**
8
+ * The parent.
9
+ * @returns The parent.
10
+ */
11
+ get parent(): TNode | undefined;
12
+ /**
13
+ * The children.
14
+ * @returns The children.
15
+ */
16
+ get children(): Set<TNode>;
17
+ /**
18
+ * Construct tree node.
19
+ * @param parent - The parent.
20
+ */
21
+ constructor(parent?: TNode);
22
+ /**
23
+ * Register a new child on the tree.
24
+ * @param child - A new child.
25
+ * @returns The child.
26
+ */
27
+ child(child: TNode): TNode;
28
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Base class to quickly provide parent-child relationships.
3
+ * @typeParam TNode - Your sub-class.
4
+ */
5
+ export class TreeNode {
6
+ /**
7
+ * The parent.
8
+ */
9
+ #parent;
10
+ /**
11
+ * Our children.
12
+ */
13
+ #children = new Set();
14
+ /**
15
+ * The parent.
16
+ * @returns The parent.
17
+ */
18
+ get parent() {
19
+ return this.#parent;
20
+ }
21
+ /**
22
+ * The children.
23
+ * @returns The children.
24
+ */
25
+ get children() {
26
+ return this.#children;
27
+ }
28
+ /**
29
+ * Construct tree node.
30
+ * @param parent - The parent.
31
+ */
32
+ constructor(parent) {
33
+ this.#parent = parent;
34
+ }
35
+ /**
36
+ * Register a new child on the tree.
37
+ * @param child - A new child.
38
+ * @returns The child.
39
+ */
40
+ child(child) {
41
+ this.children.add(child);
42
+ return child;
43
+ }
44
+ }
45
+ //# sourceMappingURL=tree.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tree.js","sourceRoot":"","sources":["../../source/data/tree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,OAAgB,QAAQ;IAC7B;;OAEG;IACH,OAAO,CAAoB;IAC3B;;OAEG;IACH,SAAS,GAAG,IAAI,GAAG,EAAS,CAAC;IAE7B;;;OAGG;IACH,IAAI,MAAM;QACT,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IAED;;;OAGG;IACH,IAAI,QAAQ;QACX,OAAO,IAAI,CAAC,SAAS,CAAC;IACvB,CAAC;IAED;;;OAGG;IACH,YAAY,MAAc;QACzB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,KAAY;QACjB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACzB,OAAO,KAAK,CAAC;IACd,CAAC;CACD"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * The type of the details of a shake event.
3
+ */
4
+ export type ShakeEventData = DeviceMotionEvent;
5
+ /**
6
+ * The type of the `"shake"` event.
7
+ */
8
+ export type ShakeEvent = CustomEvent<ShakeEventData> & {
9
+ type: "shake";
10
+ };
11
+ /**
12
+ * The type of a handler for the `"shake"` event.
13
+ */
14
+ export type ShakeEventListener = (event: ShakeEvent) => void;
15
+ /**
16
+ * The options for constructing a {@linkcode Shake} handler.
17
+ */
18
+ export interface ShakeOptions {
19
+ /**
20
+ * Minimum acceleration needed to dispatch an event:
21
+ * meters per second squared (m/s²).
22
+ *
23
+ * https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/acceleration
24
+ */
25
+ threshold: number;
26
+ /**
27
+ * After a shake event is dispatched, subsequent events will not be dispatched
28
+ * until after a duration greater than or equal to this value (milliseconds).
29
+ */
30
+ timeout: number;
31
+ }
32
+ /**
33
+ * A device motion handler that dispatches a `"shake"` event as appropriate.
34
+ *
35
+ * Original author: Jesse Jackson - https://github.com/jsejcksn
36
+ * This part of the code is licensed under CC BY-SA 4.0
37
+ */
38
+ export declare class Shake extends EventTarget {
39
+ #private;
40
+ /**
41
+ * Construct a new device shake handler.
42
+ * @param options - The options for the handler.
43
+ */
44
+ constructor(options?: Partial<ShakeOptions>);
45
+ /**
46
+ * Add a new shake event listener.
47
+ * @param type - The type of the event to handle.
48
+ * @param listener - The event handler to call.
49
+ * @param options - The options for this handler.
50
+ */
51
+ addEventListener(type: "shake", listener: ShakeEventListener | null, options?: boolean | AddEventListenerOptions): void;
52
+ /**
53
+ * Dispatch a shake event.
54
+ * @param event - The event to dispatch.
55
+ * @returns true if the event was cancelled, false otherwise.
56
+ */
57
+ dispatchEvent(event: ShakeEvent): boolean;
58
+ /**
59
+ * Removes a previously added event listener.
60
+ * @param type - The type of the event to remove.
61
+ * @param callback - The event handler to remove.
62
+ * @param options - The options the event handler was added with.
63
+ */
64
+ removeEventListener(type: "shake", callback: ShakeEventListener | null, options?: EventListenerOptions | boolean): void;
65
+ /**
66
+ * Requests approval to handle device motion events.
67
+ * @returns true if we got approval, false otherwise.
68
+ */
69
+ approve(): Promise<boolean>;
70
+ /**
71
+ * Start handling device shake.
72
+ * @returns true if we were able to register our handler, false otherwise.
73
+ */
74
+ start(): Promise<boolean>;
75
+ /**
76
+ * Stop handling device shake.
77
+ */
78
+ stop(): void;
79
+ }
@@ -0,0 +1,135 @@
1
+ import { createEvent } from "../events/event.js";
2
+ const getMaxAcceleration = (event) => {
3
+ let max = 0;
4
+ if (event.acceleration) {
5
+ for (const key of ["x", "y", "z"]) {
6
+ const value = Math.abs(event.acceleration[key] ?? 0);
7
+ if (value > max)
8
+ max = value;
9
+ }
10
+ }
11
+ return max;
12
+ };
13
+ /**
14
+ * A device motion handler that dispatches a `"shake"` event as appropriate.
15
+ *
16
+ * Original author: Jesse Jackson - https://github.com/jsejcksn
17
+ * This part of the code is licensed under CC BY-SA 4.0
18
+ */
19
+ export class Shake extends EventTarget {
20
+ /**
21
+ * Have we been granted permissions to use device motion events?
22
+ */
23
+ #approved;
24
+ /**
25
+ * How strong does the motion have to be to trigger the event?
26
+ */
27
+ #threshold;
28
+ /**
29
+ * After the event has been triggered, don't trigger another event for
30
+ * how many milliseconds?
31
+ */
32
+ #timeout;
33
+ /**
34
+ * The last time we triggered an event.
35
+ */
36
+ #timeStamp;
37
+ /**
38
+ * Construct a new device shake handler.
39
+ * @param options - The options for the handler.
40
+ */
41
+ constructor(options) {
42
+ super();
43
+ const { threshold = 15, timeout = 1000 } = options ?? {};
44
+ this.#threshold = threshold;
45
+ this.#timeout = timeout;
46
+ this.#timeStamp = timeout * -1;
47
+ }
48
+ /**
49
+ * Add a new shake event listener.
50
+ * @param type - The type of the event to handle.
51
+ * @param listener - The event handler to call.
52
+ * @param options - The options for this handler.
53
+ */
54
+ // @ts-expect-error
55
+ addEventListener(type, listener, options) {
56
+ super.addEventListener(type, listener, options);
57
+ }
58
+ /**
59
+ * Dispatch a shake event.
60
+ * @param event - The event to dispatch.
61
+ * @returns true if the event was cancelled, false otherwise.
62
+ */
63
+ dispatchEvent(event) {
64
+ return super.dispatchEvent(event);
65
+ }
66
+ /**
67
+ * Removes a previously added event listener.
68
+ * @param type - The type of the event to remove.
69
+ * @param callback - The event handler to remove.
70
+ * @param options - The options the event handler was added with.
71
+ */
72
+ // @ts-expect-error
73
+ removeEventListener(type, callback, options) {
74
+ super.removeEventListener(type, callback, options);
75
+ }
76
+ /**
77
+ * Requests approval to handle device motion events.
78
+ * @returns true if we got approval, false otherwise.
79
+ */
80
+ async approve() {
81
+ if (typeof this.#approved === "undefined") {
82
+ if (!("DeviceMotionEvent" in window)) {
83
+ this.#approved = false;
84
+ return false;
85
+ }
86
+ try {
87
+ if (typeof DeviceMotionEvent.requestPermission === "function") {
88
+ const permissionState = await DeviceMotionEvent.requestPermission();
89
+ this.#approved = permissionState === "granted";
90
+ }
91
+ else {
92
+ this.#approved = true;
93
+ }
94
+ }
95
+ catch {
96
+ this.#approved = false;
97
+ }
98
+ }
99
+ return this.#approved;
100
+ }
101
+ /**
102
+ * Handles a device motion event.
103
+ * @param event - The device motion event.
104
+ */
105
+ #handleDeviceMotion = (event) => {
106
+ const diff = event.timeStamp - this.#timeStamp;
107
+ if (diff < this.#timeout) {
108
+ return;
109
+ }
110
+ const accel = getMaxAcceleration(event);
111
+ if (accel < this.#threshold) {
112
+ return;
113
+ }
114
+ this.#timeStamp = event.timeStamp;
115
+ this.dispatchEvent(createEvent("shake", event));
116
+ };
117
+ /**
118
+ * Start handling device shake.
119
+ * @returns true if we were able to register our handler, false otherwise.
120
+ */
121
+ async start() {
122
+ const approved = await this.approve();
123
+ if (!approved)
124
+ return false;
125
+ window.addEventListener("devicemotion", this.#handleDeviceMotion);
126
+ return true;
127
+ }
128
+ /**
129
+ * Stop handling device shake.
130
+ */
131
+ stop() {
132
+ window.removeEventListener("devicemotion", this.#handleDeviceMotion);
133
+ }
134
+ }
135
+ //# sourceMappingURL=shake.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shake.js","sourceRoot":"","sources":["../../source/device/shake.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,kBAAkB,GAAG,CAAC,KAAwB,EAAU,EAAE;IAC/D,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,IAAI,KAAK,CAAC,YAAY,EAAE,CAAC;QACxB,KAAK,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAU,EAAE,CAAC;YAC5C,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;YACrD,IAAI,KAAK,GAAG,GAAG;gBAAE,GAAG,GAAG,KAAK,CAAC;QAC9B,CAAC;IACF,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC,CAAC;AAoCF;;;;;GAKG;AACH,MAAM,OAAO,KAAM,SA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ructorOf } from "../core.js";
2
+ /**
3
+ * Retrieves an element from the document and returns it if it is
4
+ * non-null and has the expected type. Otherwise an error is thrown.
5
+ * @param document - The document from which to look up the element.
6
+ * @param id - The ID of the element.
7
+ * @param Type - The type you expect the element to have.
8
+ * @returns The requested element, if it has the expected type.
9
+ * @throws {@linkcode InvalidOperationError} When the document element has an unexpected type.
10
+ * @throws {@linkcode UnexpectedNilError} When the the document element is `null`.
11
+ */
12
+ export declare const getDocumentElementTypeByIdStrict: <T extends HTMLElement>(document: Document, id: string, Type: ConstructorOf<T>) => T;
13
+ /**
14
+ * Retrieves an element from the document and returns it if it has the
15
+ * expected type.
16
+ * @param document - The document from which to look up the element.
17
+ * @param id - The ID of the element.
18
+ * @param Type - The type you expect the element to have.
19
+ * @returns The requested element, if it has the expected type; `null` otherwise.
20
+ */
21
+ export declare const getDocumentElementTypeById: <T extends HTMLElement>(document: Document, id: string, Type: ConstructorOf<T>) => T | null;
@@ -0,0 +1,41 @@
1
+ import { UnexpectedNilError } from "../data/nil.js";
2
+ import { InvalidOperationError } from "../errors/InvalidOperationError.js";
3
+ /**
4
+ * Retrieves an element from the document and returns it if it is
5
+ * non-null and has the expected type. Otherwise an error is thrown.
6
+ * @param document - The document from which to look up the element.
7
+ * @param id - The ID of the element.
8
+ * @param Type - The type you expect the element to have.
9
+ * @returns The requested element, if it has the expected type.
10
+ * @throws {@linkcode InvalidOperationError} When the document element has an unexpected type.
11
+ * @throws {@linkcode UnexpectedNilError} When the the document element is `null`.
12
+ */
13
+ export const getDocumentElementTypeByIdStrict = (document, id, Type) => {
14
+ const element = document.getElementById(id);
15
+ if (element === null) {
16
+ throw new UnexpectedNilError(`The document element '${id}' does not exist.`);
17
+ }
18
+ if (!(element instanceof Type)) {
19
+ throw new InvalidOperationError(`The document element '${id}' has an unexpected type.`);
20
+ }
21
+ return element;
22
+ };
23
+ /**
24
+ * Retrieves an element from the document and returns it if it has the
25
+ * expected type.
26
+ * @param document - The document from which to look up the element.
27
+ * @param id - The ID of the element.
28
+ * @param Type - The type you expect the element to have.
29
+ * @returns The requested element, if it has the expected type; `null` otherwise.
30
+ */
31
+ export const getDocumentElementTypeById = (document, id, Type) => {
32
+ const element = document.getElementById(id);
33
+ if (element === null) {
34
+ return null;
35
+ }
36
+ if (!(element instanceof Type)) {
37
+ return null;
38
+ }
39
+ return element;
40
+ };
41
+ //# sourceMappingURL=core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core.js","sourceRoot":"","sources":["../../source/dom/core.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAE3E;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAC/C,QAAkB,EAClB,EAAU,EACV,IAAsB,EAClB,EAAE;IACN,MAAM,OAAO,GAAG,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;IAE5C,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACtB,MAAM,IAAI,kBAAkB,CAC3B,yBAAyB,EAAE,mBAAmB,CAC9C,CAAC;IACH,CAAC;IAED,IAAI,CAAC,CAAC,OAAO,YAAY,IAAI,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,qBAAqB,CAC9B,yBAAyB,EAAE,2BAA2B,CACtD,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC;AAChB,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,CACzC,QAAkB,EAClB,EAAU,EACV,IAAsB,EACX,EAAE;IACb,MAAM,OAAO,GAAG,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;IAE5C,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC;IACb,CAAC;IAED,IAAI,CAAC,CAAC,OAAO,YAAY,IAAI,CAAC,EAAE,CAAC;QAChC,OAAO,IAAI,CAAC;IACb,CAAC;IAED,OAAO,OAAO,CAAC;AAChB,CAAC,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Base class for all errors.
3
+ */
4
+ export declare class AbstractError extends Error {
5
+ /**
6
+ * The HTTP status code to associate with this error.
7
+ */
8
+ status: number;
9
+ /**
10
+ * An application-unique, readable error code.
11
+ */
12
+ code: string;
13
+ /**
14
+ * Constructs a new {@linkcode AbstractError}.
15
+ * @param code - The main identification code for the error.
16
+ * @param message - The main error message.
17
+ * @param status - The HTTP status code to return.
18
+ */
19
+ constructor(code: string, message: string, status: number);
20
+ /**
21
+ * Checks if an object is an instance of {@linkcode AbstractError}, or one of its subclasses.
22
+ * @param error - The object to check.
23
+ * @param allowForeignModule - Only check for similar looking error codes.
24
+ * You're going to want to use this if you're dealing with a setup where
25
+ * multiple versions of js-utils are loaded.
26
+ * @returns `true` if the object is an {@linkcode AbstractError}, `false` otherwise.
27
+ */
28
+ static isAbstractError(error: unknown, allowForeignModule?: boolean): error is AbstractError;
29
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Base class for all errors.
3
+ */
4
+ export class AbstractError extends Error {
5
+ /**
6
+ * The HTTP status code to associate with this error.
7
+ */
8
+ status;
9
+ /**
10
+ * An application-unique, readable error code.
11
+ */
12
+ code;
13
+ /**
14
+ * Constructs a new {@linkcode AbstractError}.
15
+ * @param code - The main identification code for the error.
16
+ * @param message - The main error message.
17
+ * @param status - The HTTP status code to return.
18
+ */
19
+ constructor(code, message, status) {
20
+ super(message);
21
+ this.code = code;
22
+ this.name = "AbstractError";
23
+ this.status = status;
24
+ if (typeof Error.captureStackTrace !== "undefined") {
25
+ // Capture a new stacktrace, otherwise it will include our base-class constructor instead of the code
26
+ // location we're actually interested in.
27
+ Error.captureStackTrace(this, AbstractError);
28
+ }
29
+ }
30
+ /**
31
+ * Checks if an object is an instance of {@linkcode AbstractError}, or one of its subclasses.
32
+ * @param error - The object to check.
33
+ * @param allowForeignModule - Only check for similar looking error codes.
34
+ * You're going to want to use this if you're dealing with a setup where
35
+ * multiple versions of js-utils are loaded.
36
+ * @returns `true` if the object is an {@linkcode AbstractError}, `false` otherwise.
37
+ */
38
+ static isAbstractError(error, allowForeignModule = true) {
39
+ if (error instanceof AbstractError) {
40
+ return true;
41
+ }
42
+ // When multiple versions of js-utils are loaded at runtime, the
43
+ // prototypes of errors don't align. In that case, we just analyze the
44
+ // error code.
45
+ if (allowForeignModule) {
46
+ const errorRecord = error;
47
+ if (Object(error) === error &&
48
+ "code" in errorRecord &&
49
+ typeof errorRecord.code === "string") {
50
+ const codedError = error;
51
+ if (codedError.code.match(/^ERR_OS_/)) {
52
+ return true;
53
+ }
54
+ }
55
+ }
56
+ return false;
57
+ }
58
+ }
59
+ //# sourceMappingURL=AbstractError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AbstractError.js","sourceRoot":"","sources":["../../source/errors/AbstractError.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,KAAK;IACvC;;OAEG;IACH,MAAM,CAAS;IAEf;;OAEG;IACH,IAAI,CAAS;IAEb;;;;;OAKG;IACH,YAAY,IAAY,EAAE,OAAe,EAAE,MAAc;QACxD,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,IAAI,OAAO,KAAK,CAAC,iBAAiB,KAAK,WAAW,EAAE,CAAC;YACpD,qGAAqG;YACrG,yCAAyC;YACzC,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;QAC9C,CAAC;IACF,CAAC;IAED;;;;;;;OAOG;IACH,MAAM,CAAC,eAAe,CACrB,KAAc,EACd,kBAAkB,GAAG,IAAI;QAEzB,IAAI,KAAK,YAAY,aAAa,EAAE,CAAC;YACpC,OAAO,IAAI,CAAC;QACb,CAAC;QAED,gEAAgE;QAChE,sEAAsE;QACtE,cAAc;QACd,IAAI,kBAAkB,EAAE,CAAC;YACxB,MAAM,WAAW,GAAG,KAAgC,CAAC;YACrD,IACC,MAAM,CAAC,KAAK,CAAC,KAAK,KAAK;gBACvB,MAAM,IAAI,WAAW;gBACrB,OAAO,WAAW,CAAC,IAAI,KAAK,QAAQ,EACnC,CAAC;gBACF,MAAM,UAAU,GAAG,KAAyB,CAAC;gBAC7C,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC;oBACvC,OAAO,IAAI,CAAC;gBACb,CAAC;YACF,CAAC;QACF,CAAC;QAED,OAAO,KAAK,CAAC;IACd,CAAC;CACD"}
@@ -0,0 +1,19 @@
1
+ import { AbstractError } from "./AbstractError.js";
2
+ /**
3
+ * Used when an {@linkcode !Error}-like object was caught and converted into an
4
+ * implementation of {@linkcode AbstractError} for further processing.
5
+ */
6
+ export declare class InternalError extends AbstractError {
7
+ /**
8
+ * Constructs a new {@linkcode InternalError}.
9
+ * @param message - The main error message.
10
+ * @param status - The HTTP status code to return.
11
+ */
12
+ constructor(message: string, status?: number);
13
+ /**
14
+ * Converts an error into an {@linkcode InternalError}.
15
+ * @param error - The error to convert.
16
+ * @returns An {@linkcode InternalError} that represents the given error.
17
+ */
18
+ static fromError(error: Error): InternalError;
19
+ }
@@ -0,0 +1,38 @@
1
+ import { AbstractError } from "./AbstractError.js";
2
+ /**
3
+ * Used when an {@linkcode !Error}-like object was caught and converted into an
4
+ * implementation of {@linkcode AbstractError} for further processing.
5
+ */
6
+ export class InternalError extends AbstractError {
7
+ /**
8
+ * Constructs a new {@linkcode InternalError}.
9
+ * @param message - The main error message.
10
+ * @param status - The HTTP status code to return.
11
+ */
12
+ constructor(message, status = 500) {
13
+ super("ERR_OS_INTERNAL", message, status);
14
+ this.name = "InternalError";
15
+ if (typeof Error.captureStackTrace !== "undefined") {
16
+ // Capture a new stacktrace, otherwise it will include our base-class
17
+ // constructor instead of the code location we're actually interested in.
18
+ Error.captureStackTrace(this, InternalError);
19
+ }
20
+ }
21
+ /**
22
+ * Converts an error into an {@linkcode InternalError}.
23
+ * @param error - The error to convert.
24
+ * @returns An {@linkcode InternalError} that represents the given error.
25
+ */
26
+ static fromError(error) {
27
+ // Create a _real_ `InternalError` instance, which we will return later.
28
+ const internalError = new InternalError(error.message);
29
+ // Assign the error to it, to inherit all the fields in the error.
30
+ // Then assign another `InternalError` to replace key fields, like:
31
+ // name, code, status, ...
32
+ Object.assign(internalError, error, new InternalError(error.message));
33
+ // Inherit the original error stack again.
34
+ internalError.stack = error.stack;
35
+ return internalError;
36
+ }
37
+ }
38
+ //# sourceMappingURL=InternalError.js.map
@@ -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;IAC/C;;;;OAIG;IACH,YAAY,OAAe,EAAE,MAAM,GAAG,GAAG;QACxC,KAAK,CAAC,iBAAiB,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QAE1C,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAE5B,IAAI,OAAO,KAAK,CAAC,iBAAiB,KAAK,WAAW,EAAE,CAAC;YACpD,qEAAqE;YACrE,yEAAyE;YACzE,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;QAC9C,CAAC;IACF,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,SAAS,CAAC,KAAY;QAC5B,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,0CAA0C;QAC1C,aAAa,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;QAElC,OAAO,aAAa,CAAC;IACtB,CAAC;CACD"}
@@ -0,0 +1,13 @@
1
+ import { AbstractError } from "./AbstractError.js";
2
+ /**
3
+ * Used when the user supplied an argument that is not valid in the current
4
+ * context.
5
+ */
6
+ export declare class InvalidArgumentError extends AbstractError {
7
+ /**
8
+ * Constructs a new {@linkcode InvalidArgumentError}.
9
+ * @param message - The main error message.
10
+ * @param status - The HTTP status code to return.
11
+ */
12
+ constructor(message: string, status?: number);
13
+ }
@@ -0,0 +1,22 @@
1
+ import { AbstractError } from "./AbstractError.js";
2
+ /**
3
+ * Used when the user supplied an argument that is not valid in the current
4
+ * context.
5
+ */
6
+ export class InvalidArgumentError extends AbstractError {
7
+ /**
8
+ * Constructs a new {@linkcode InvalidArgumentError}.
9
+ * @param message - The main error message.
10
+ * @param status - The HTTP status code to return.
11
+ */
12
+ constructor(message, status = 400) {
13
+ super("ERR_OS_INVALID_ARGUMENT", message, status);
14
+ this.name = "InvalidArgumentError";
15
+ if (typeof Error.captureStackTrace !== "undefined") {
16
+ // Capture a new stacktrace, otherwise it will include our base-class
17
+ // constructor instead of the code location we're actually interested in.
18
+ Error.captureStackTrace(this, InvalidArgumentError);
19
+ }
20
+ }
21
+ }
22
+ //# sourceMappingURL=InvalidArgumentError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InvalidArgumentError.js","sourceRoot":"","sources":["../../source/errors/InvalidArgumentError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;;GAGG;AACH,MAAM,OAAO,oBAAqB,SAAQ,aAAa;IACtD;;;;OAIG;IACH,YAAY,OAAe,EAAE,MAAM,GAAG,GAAG;QACxC,KAAK,CAAC,yBAAyB,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QAElD,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;QAEnC,IAAI,OAAO,KAAK,CAAC,iBAAiB,KAAK,WAAW,EAAE,CAAC;YACpD,qEAAqE;YACrE,yEAAyE;YACzE,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,oBAAoB,CAAC,CAAC;QACrD,CAAC;IACF,CAAC;CACD"}
@@ -0,0 +1,13 @@
1
+ import { AbstractError } from "./AbstractError.js";
2
+ /**
3
+ * Used when an operation was attempted that can not be completed in the current
4
+ * context.
5
+ */
6
+ export declare class InvalidOperationError extends AbstractError {
7
+ /**
8
+ * Constructs a new {@linkcode InvalidOperationError}.
9
+ * @param message - The main error message.
10
+ * @param status - The HTTP status code to return.
11
+ */
12
+ constructor(message: string, status?: number);
13
+ }
@@ -0,0 +1,22 @@
1
+ import { AbstractError } from "./AbstractError.js";
2
+ /**
3
+ * Used when an operation was attempted that can not be completed in the current
4
+ * context.
5
+ */
6
+ export class InvalidOperationError extends AbstractError {
7
+ /**
8
+ * Constructs a new {@linkcode InvalidOperationError}.
9
+ * @param message - The main error message.
10
+ * @param status - The HTTP status code to return.
11
+ */
12
+ constructor(message, status = 400) {
13
+ super("ERR_OS_INVALID_OPERATION", message, status);
14
+ this.name = "InvalidOperationError";
15
+ if (typeof Error.captureStackTrace !== "undefined") {
16
+ // Capture a new stacktrace, otherwise it will include our base-class
17
+ // constructor instead of the code location we're actually interested in.
18
+ Error.captureStackTrace(this, InvalidOperationError);
19
+ }
20
+ }
21
+ }
22
+ //# sourceMappingURL=InvalidOperationError.js.map